📄 rcstuff.c
字号:
tmprcnums = rcnums[ngx]; tmpsoftptr = softptr[ngx]; tmpngmax = ngmax[ngx]; tmpabs1st = abs1st[ngx]; for (i=ngx+1; i<nextrcline; i++) { rcline[i-1] = rcline[i]; toread[i-1] = toread[i]; rcchar[i-1] = rcchar[i]; rcnums[i-1] = rcnums[i]; softptr[i-1] = softptr[i]; ngmax[i-1] = ngmax[i]; abs1st[i-1] = abs1st[i]; } rcline[nextrcline-1] = tmprcline; toread[nextrcline-1] = tmptoread; rcchar[nextrcline-1] = tmprcchar; rcnums[nextrcline-1] = tmprcnums; softptr[nextrcline-1] = tmpsoftptr; ngmax[nextrcline-1] = tmpngmax; abs1st[nextrcline-1] = tmpabs1st; } if (current_ng > ngx) current_ng--; if (newng < 0) { reask_reloc: unflush_output(); /* disable any ^O in effect */#ifdef VERBOSE IF(verbose) printf("\nPut newsgroup where? [%s] ", dflt); ELSE#endif#ifdef TERSE printf("\nPut where? [%s] ", dflt);#endif fflush(stdout); reinp_reloc: eat_typeahead(); getcmd(buf); if (errno || *buf == '\f') { /* if return from stop signal */ goto reask_reloc; /* give them a prompt again */ } setdef(buf,dflt);#ifdef VERIFY printcmd();#endif if (*buf == 'h') {#ifdef VERBOSE IF(verbose) { printf("\n\n\Type ^ to put the newsgroup first (position 0).\n\Type $ to put the newsgroup last (position %d).\n", nextrcline-1); printf("\Type . to put it before the current newsgroup (position %d).\n", current_ng); printf("\Type -newsgroup name to put it before that newsgroup.\n\Type +newsgroup name to put it after that newsgroup.\n\Type a number between 0 and %d to put it at that position.\n", nextrcline-1); printf("\Type L for a listing of newsgroups and their positions.\n\Type q to abort the current action.\n") FLUSH; } ELSE#endif#ifdef TERSE { printf("\n\n\^ to put newsgroup first (pos 0).\n\$ to put last (pos %d).\n", nextrcline-1); printf("\. to put before current newsgroup (pos %d).\n", current_ng); printf("\-newsgroup to put before newsgroup.\n\+newsgroup to put after.\n\number in 0-%d to put at that pos.\n", nextrcline-1); printf("\L for list of .newsrc.\n\q to abort\n") FLUSH; }#endif goto reask_reloc; } else if (*buf == 'q') return -1; else if (*buf == 'L') { putchar('\n') FLUSH; list_newsgroups(); goto reask_reloc; } else if (isdigit(*buf)) { if (!finish_command(TRUE)) /* get rest of command */ goto reinp_reloc; newng = atol(buf); if (newng < 0) newng = 0; if (newng >= nextrcline) return nextrcline-1; } else if (*buf == '^') { putchar('\n') FLUSH; newng = 0; } else if (*buf == '$') { newng = nextrcline-1; } else if (*buf == '.') { putchar('\n') FLUSH; newng = current_ng; } else if (*buf == '-' || *buf == '+') { if (!finish_command(TRUE)) /* get rest of command */ goto reinp_reloc; newng = find_ng(buf+1); if (newng == nextrcline) { fputs("Not found.",stdout) FLUSH; goto reask_reloc; } if (*buf == '+') newng++; } else { printf("\n%s",hforhelp) FLUSH; settle_down(); goto reask_reloc; } } if (newng < nextrcline-1) {#ifdef HASHNG if (rc_hash) hashwalk(rc_hash, ins_rc_line, newng);#endif tmprcline = rcline[nextrcline-1]; tmptoread = toread[nextrcline-1]; tmprcchar = rcchar[nextrcline-1]; tmprcnums = rcnums[nextrcline-1]; tmpsoftptr = softptr[nextrcline-1]; tmpngmax = ngmax[nextrcline-1]; tmpabs1st = abs1st[nextrcline-1]; for (i=nextrcline-2; i>=newng; i--) { rcline[i+1] = rcline[i]; toread[i+1] = toread[i]; rcchar[i+1] = rcchar[i]; rcnums[i+1] = rcnums[i]; softptr[i+1] = softptr[i]; ngmax[i+1] = ngmax[i]; abs1st[i+1] = abs1st[i]; } rcline[newng] = tmprcline; toread[newng] = tmptoread; rcchar[newng] = tmprcchar; rcnums[newng] = tmprcnums; softptr[newng] = tmpsoftptr; ngmax[newng] = tmpngmax; abs1st[newng] = tmpabs1st; } if (current_ng >= newng) current_ng++; return newng;}#endif/* List out the newsrc with annotations */voidlist_newsgroups(){ register NG_NUM i; char tmpbuf[2048]; static char *status[] = {"(READ)","(UNSUB)","(BOGUS)","(JUNK)"}; int cmd; page_init(); print_lines("\ # Status Newsgroup\n\",STANDOUT); for (i=0; i<nextrcline && !int_count; i++) { if (toread[i] >= 0) set_toread(i); *(rcline[i] + rcnums[i] - 1) = RCCHAR(rcchar[i]); if (toread[i] > 0) sprintf(tmpbuf,"%3d %6ld ",i,(long)toread[i]); else sprintf(tmpbuf,"%3d %7s ",i,status[-toread[i]]); safecpy(tmpbuf+13,rcline[i],2034); *(rcline[i] + rcnums[i] - 1) = '\0'; if (cmd = print_lines(tmpbuf,NOMARKING)) { if (cmd > 0) pushchar(cmd); break; } } int_count = 0;}/* find a newsgroup in .newsrc */NG_NUMfind_ng(ngnam)char *ngnam;{#ifdef HASHNG HASHDATUM data; assert(rc_hash != 0); data = hashfetch(rc_hash, ngnam, strlen(ngnam)); if (!data.dat_ptr) return nextrcline; /* = notfound */ return data.dat_len;#else /* just do linear search */ register NG_NUM ngnum; for (ngnum = 0; ngnum < nextrcline; ngnum++) { if (strEQ(rcline[ngnum],ngnam)) break; } return ngnum;#endif}voidcleanup_rc(){ register NG_NUM ngx; register NG_NUM bogosity = 0;#ifdef VERBOSE IF(verbose) fputs("Checking out your .newsrc -- hang on a second...\n",stdout) FLUSH; ELSE#endif#ifdef TERSE fputs("Checking .newsrc -- hang on...\n",stdout) FLUSH;#endif for (ngx = 0; ngx < nextrcline; ngx++) { if (toread[ngx] >= TR_UNSUB) { set_toread(ngx); /* this may reset newsgroup */ /* or declare it bogus */ } if (toread[ngx] == TR_BOGUS) bogosity++; } for (ngx = nextrcline-1; ngx >= 0 && toread[ngx] == TR_BOGUS; ngx--) bogosity--; /* discount already moved ones */ if (nextrcline > 5 && bogosity > nextrcline / 2) { fputs("It looks like the active file is messed up. Contact your news administrator,\n\",stdout); fputs("leave the \"bogus\" groups alone, and they may come back to normal. Maybe.\n\",stdout) FLUSH; }#ifdef RELOCATE else if (bogosity) {#ifdef VERBOSE IF(verbose) fputs("Moving bogus newsgroups to the end of your .newsrc.\n", stdout) FLUSH; ELSE#endif#ifdef TERSE fputs("Moving boguses to the end.\n",stdout) FLUSH;#endif for (; ngx >= 0; ngx--) { if (toread[ngx] == TR_BOGUS) relocate_newsgroup(ngx,nextrcline-1); }#ifdef DELBOGUSreask_bogus: in_char("Delete bogus newsgroups? [ny] ", 'D'); setdef(buf,"n");#ifdef VERIFY printcmd();#endif putchar('\n') FLUSH; if (*buf == 'h') {#ifdef VERBOSE IF(verbose) fputs("\Type y to delete bogus newsgroups.\n\Type n or SP to leave them at the end in case they return.\n\",stdout) FLUSH; ELSE#endif#ifdef TERSE fputs("y to delete, n to keep\n",stdout) FLUSH;#endif goto reask_bogus; } else if (*buf == 'n' || *buf == 'q') ; else if (*buf == 'y') { while (toread[nextrcline-1] == TR_BOGUS && nextrcline > 0) --nextrcline; /* real tough, huh? */ } else { fputs(hforhelp,stdout) FLUSH; settle_down(); goto reask_bogus; }#endif }#else#ifdef VERBOSE IF(verbose) fputs("You should edit bogus newsgroups out of your .newsrc.\n", stdout) FLUSH; ELSE#endif#ifdef TERSE fputs("Edit boguses from .newsrc.\n",stdout) FLUSH;#endif#endif paranoid = FALSE;}#ifdef HASHNG/* make an entry in the hash table for the current newsgroup */voidsethash(thisng)NG_NUM thisng;{ HASHDATUM data; data.dat_ptr = nullstr; data.dat_len = thisng; hashstore(rc_hash, rcline[thisng], rcnums[thisng]-1, data);}static intrcline_cmp(key, keylen, data)char *key;int keylen;HASHDATUM data;{ /* We already know that the lengths are equal, just compare the strings */ return bcmp(key, rcline[data.dat_len], keylen);}static voiddel_rc_line(data, ngnum)HASHDATUM *data;int ngnum;{ if (data->dat_len == ngnum) data->dat_len = nextrcline-1; else if (data->dat_len > ngnum) data->dat_len--;}static voidins_rc_line(data, ngnum)HASHDATUM *data;int ngnum;{ if (data->dat_len == nextrcline-1) data->dat_len = ngnum; else if (data->dat_len >= ngnum) data->dat_len++;}#endifvoidnewsrc_check(){ rcfp = fopen(rcname,"r"); /* open it */ if (rcfp == Nullfp) { /* not there? */#ifdef VERBOSE IF(verbose) fputs("\nTrying to set up a .newsrc file -- running newsetup...\n\n\",stdout) FLUSH; ELSE#endif#ifdef TERSE fputs("Setting up .newsrc...\n",stdout) FLUSH;#endif if (doshell(sh,filexp(NEWSETUP)) || (rcfp = fopen(rcname,"r")) == Nullfp) {#ifdef VERBOSE IF(verbose) fputs("\nCan't create a .newsrc -- you must do it yourself.\n\",stdout) FLUSH; ELSE#endif#ifdef TERSE fputs("(Fatal)\n",stdout) FLUSH;#endif finalize(1); } } else { UNLINK(rcbname); /* unlink backup file name */ link(rcname,rcbname); /* and backup current name */ }}/* checkpoint the .newsrc */voidcheckpoint_rc(){#ifdef DEBUG if (debug & DEB_CHECKPOINTING) { fputs("(ckpt)",stdout); fflush(stdout); }#endif if (doing_ng) bits_to_rc(); /* do not restore M articles */ if (rc_changed) write_rc();#ifdef DEBUG if (debug & DEB_CHECKPOINTING) { fputs("(done)",stdout); fflush(stdout); }#endif}/* write out the (presumably) revised .newsrc */voidwrite_rc(){ register NG_NUM tmpng; register char *delim; rcfp = fopen(rctname, "w"); /* open .newnewsrc */ if (rcfp == Nullfp) { printf(cantrecreate,".newsrc") FLUSH; finalize(1); } if (stat(rcname,&filestat)>=0) { /* preserve permissions */ chmod(rctname,filestat.st_mode&0666); chown(rctname,filestat.st_uid,filestat.st_gid); /* if possible */ } /* write out each line*/ for (tmpng = 0; tmpng < nextrcline; tmpng++) { if (rcnums[tmpng]) { delim = rcline[tmpng] + rcnums[tmpng] - 1; *delim = RCCHAR(rcchar[tmpng]); if (rcchar[tmpng] == '0' && delim[2] == '1') delim[2] = '0'; } else delim = Nullch;#ifdef DEBUG if (debug & DEB_NEWSRC_LINE) printf("%s\n",rcline[tmpng]) FLUSH;#endif if (fprintf(rcfp,"%s\n",rcline[tmpng]) < 0) { write_error: printf(cantrecreate,".newsrc") FLUSH; fclose(rcfp); /* close .newnewsrc */ UNLINK(rctname); finalize(1); } if (delim) { *delim = '\0'; /* might still need this line */ if (rcchar[tmpng] == '0' && delim[2] == '0') delim[2] = '1'; } } fflush(rcfp); if (ferror(rcfp)) goto write_error; fclose(rcfp); /* close .newnewsrc */ UNLINK(rcname);#ifdef HAS_RENAME rename(rctname,rcname);#else link(rctname,rcname); UNLINK(rctname);#endif if (writesoft) { tmpfp = fopen(filexp(softname), "w"); /* open .rnsoft */ if (tmpfp == Nullfp) { printf(cantcreate,filexp(softname)) FLUSH; return; } for (tmpng = 0; tmpng < nextrcline; tmpng++) { fprintf(tmpfp,"%ld\n",(long)softptr[tmpng]); } fclose(tmpfp); }}voidget_old_rc(){ UNLINK(rctname);#ifdef HAS_RENAME rename(rcname,rctname); rename(rcbname,rcname);#else link(rcname,rctname); UNLINK(rcname); link(rcbname,rcname); UNLINK(rcbname);#endif}static voidgrow_rc_arrays(newsize)int newsize;{ abs1st = (ART_NUM*)saferealloc((char*)abs1st, (MEM_SIZE)newsize * sizeof (ART_NUM)); ngmax = (ART_NUM*)saferealloc((char*)ngmax, (MEM_SIZE)newsize * sizeof (ART_NUM)); rcline = (char**)saferealloc((char*)rcline, (MEM_SIZE)newsize * sizeof (char*)); toread = (ART_UNREAD*)saferealloc((char*)toread, (MEM_SIZE)newsize * sizeof(ART_UNREAD)); rcchar = (char *) saferealloc(rcchar, (MEM_SIZE)newsize * sizeof (char)); rcnums = (char*)saferealloc(rcnums, (MEM_SIZE)newsize * sizeof (char)); softptr = (ACT_POS*)saferealloc((char*)softptr, (MEM_SIZE)newsize * sizeof (ACT_POS)); bzero((char*)(abs1st+maxrcline), (newsize-maxrcline) * sizeof (ART_NUM)); bzero((char*)(ngmax+maxrcline), (newsize-maxrcline) * sizeof (ART_NUM)); maxrcline = newsize; return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -