1: /* $Header: kfile.c,v 4.3.1.3 85/05/29 09:11:52 lwall Exp $
   2:  *
   3:  * $Log:	kfile.c,v $
   4:  * Revision 4.3.1.3  85/05/29  09:11:52  lwall
   5:  * Suppressed some killing messages on -t.
   6:  *
   7:  * Revision 4.3.1.2  85/05/10  14:21:29  lwall
   8:  * Prevented THRU from setting art < absfirst.
   9:  *
  10:  * Revision 4.3.1.1  85/05/10  11:34:33  lwall
  11:  * Branch for patches.
  12:  *
  13:  * Revision 4.3  85/05/01  11:41:53  lwall
  14:  * Baseline for release with 4.3bsd.
  15:  *
  16:  */
  17: 
  18: #include "EXTERN.h"
  19: #include "common.h"
  20: #include "term.h"
  21: #include "util.h"
  22: #include "artsrch.h"
  23: #include "ng.h"
  24: #include "bits.h"
  25: #include "intrp.h"
  26: #include "ngstuff.h"
  27: #include "rcstuff.h"
  28: #include "rn.h"
  29: #include "INTERN.h"
  30: #include "kfile.h"
  31: 
  32: static bool exitcmds = FALSE;
  33: 
  34: void
  35: kfile_init()
  36: {
  37:     ;
  38: }
  39: 
  40: #ifndef KILLFILES
  41: int
  42: edit_kfile()
  43: {
  44:     notincl("^K");
  45:     return -1;
  46: }
  47: 
  48: #else KILLFILES
  49: 
  50: char killglobal[] = KILLGLOBAL;
  51: char killlocal[] = KILLLOCAL;
  52: 
  53: void
  54: mention(str)
  55: char *str;
  56: {
  57: #ifdef VERBOSE
  58:     IF(verbose) {
  59: #ifdef NOFIREWORKS
  60:     no_sofire();
  61: #endif
  62:     standout();
  63:     fputs(str,stdout);
  64:     un_standout();
  65:     putchar('\n');
  66:     }
  67:     ELSE
  68: #endif
  69: #ifdef TERSE
  70:     putchar('.');
  71: #endif
  72:     fflush(stdout);
  73: }
  74: 
  75: int
  76: do_kfile(kfp,entering)
  77: FILE *kfp;
  78: int entering;
  79: {
  80:     art = lastart+1;
  81:     fseek(kfp,0L,0);            /* rewind file */
  82:     while (fgets(buf,LBUFLEN,kfp) != Nullch) {
  83:     buf[strlen(buf)-1] = '\0';
  84:     if (strnEQ(buf,"THRU",4)) {
  85:         ART_NUM tmpart;
  86: 
  87:         tmpart = atol(buf+4)+1;
  88:         if (tmpart < absfirst)
  89:         tmpart = absfirst;
  90:         check_first(tmpart);
  91:         firstart = tmpart;
  92:         continue;
  93:     }
  94:     if (*buf == 'X') {      /* exit command? */
  95:         if (entering) {
  96:         exitcmds = TRUE;
  97:         continue;
  98:         }
  99:         strcpy(buf,buf+1);
 100:     }
 101:     else {
 102:         if (!entering)
 103:         continue;
 104:     }
 105:     if (*buf == '&') {
 106:         mention(buf);
 107:         switcheroo();
 108:     }
 109:     else if (*buf == '/' && firstart <= lastart) {
 110:         mention(buf);
 111:         switch (art_search(buf, (sizeof buf), FALSE)) {
 112:         case SRCH_ABORT:
 113:         continue;
 114:         case SRCH_INTR:
 115: #ifdef VERBOSE
 116:         IF(verbose)
 117:             printf("\n(Interrupted at article %ld)\n",(long)art)
 118:               FLUSH;
 119:         ELSE
 120: #endif
 121: #ifdef TERSE
 122:             printf("\n(Intr at %ld)\n",(long)art) FLUSH;
 123: #endif
 124:         return -1;
 125:         case SRCH_DONE:
 126:         break;
 127:         case SRCH_SUBJDONE:
 128:         fputs("\tsubject not found (???)\n",stdout) FLUSH;
 129:         break;
 130:         case SRCH_NOTFOUND:
 131:         fputs("\tnot found\n",stdout) FLUSH;
 132:         break;
 133:         case SRCH_FOUND:
 134:         fputs("\tfound\n",stdout) FLUSH;
 135:         }
 136:     }
 137:     }
 138:     return 0;
 139: }
 140: 
 141: void
 142: kill_unwanted(starting,message,entering)
 143: ART_NUM starting;
 144: char *message;
 145: int entering;
 146: {
 147:     bool intr = FALSE;          /* did we get an interrupt? */
 148:     ART_NUM oldfirst;
 149:     bool anytokill = (toread[ng] > 0);
 150: 
 151:     if (localkfp || globkfp) {
 152:     if (!entering && !exitcmds)
 153:         return;
 154:     exitcmds = FALSE;
 155:     oldfirst = firstart;
 156:     firstart = starting;
 157:     clear();
 158: #ifdef VERBOSE
 159:     IF(verbose)
 160:         if (message)
 161:         fputs(message,stdout) FLUSH;
 162: #endif
 163:     if (localkfp)
 164:         intr = do_kfile(localkfp,entering);
 165:     if (globkfp && !intr)
 166:         intr = do_kfile(globkfp,entering);
 167:     if (entering && localkfp && !intr)
 168:         setthru(lastart);
 169:     putchar('\n') FLUSH;
 170: #ifdef VERBOSE
 171:     IF(verbose)
 172:         if (entering)
 173:         get_anything();
 174: #endif
 175:     if (anytokill)          /* if there was anything to kill */
 176:         forcelast = FALSE;      /* allow for having killed it all */
 177:     firstart = oldfirst;
 178:     }
 179: }
 180: 
 181: void
 182: setthru(thru)
 183: ART_NUM thru;
 184: {
 185:     FILE *newkfp;
 186: 
 187:     fseek(localkfp,0L,0);       /* rewind current file */
 188:     strcpy(buf,filexp(getval("KILLLOCAL",killlocal)));
 189:     UNLINK(buf);            /* to prevent file reuse */
 190:     if (newkfp = fopen(buf,"w")) {
 191:     fprintf(newkfp,"THRU %ld\n",(long)thru);
 192:     while (fgets(buf,LBUFLEN,localkfp) != Nullch) {
 193:         if (strnEQ(buf,"THRU",4))
 194:         continue;
 195:         fputs(buf,newkfp);
 196:     }
 197:     fclose(newkfp);
 198:     open_kfile(KF_LOCAL);       /* and reopen local file */
 199:     }
 200:     else
 201:     printf(cantcreate,buf) FLUSH;
 202: }
 203: 
 204: /* edit KILL file for newsgroup */
 205: 
 206: int
 207: edit_kfile()
 208: {
 209:     int r = -1;
 210: 
 211:     if (in_ng)
 212:     strcpy(buf,filexp(getval("KILLLOCAL",killlocal)));
 213:     else
 214:     strcpy(buf,filexp(getval("KILLGLOBAL",killglobal)));
 215:     if ((r = makedir(buf,MD_FILE)) >= 0) {
 216:     sprintf(cmd_buf,"%s %s",
 217:         filexp(getval("VISUAL",getval("EDITOR",defeditor))),buf);
 218:     printf("\nEditing %s KILL file:\n%s\n",
 219:         (in_ng?"local":"global"),cmd_buf) FLUSH;
 220:     resetty();          /* make sure tty is friendly */
 221:     r = doshell(sh,cmd_buf);/* invoke the shell */
 222:     noecho();           /* and make terminal */
 223:     crmode();           /*   unfriendly again */
 224:     open_kfile(in_ng);
 225:     }
 226:     else
 227:     printf("Can't make %s\n",buf) FLUSH;
 228:     return r;
 229: }
 230: 
 231: void
 232: open_kfile(local)
 233: int local;
 234: {
 235:     char *kname = filexp(local ?
 236:     getval("KILLLOCAL",killlocal) :
 237:     getval("KILLGLOBAL",killglobal)
 238:     );
 239: 
 240:     stat(kname,&filestat);
 241:     if (!filestat.st_size)      /* nothing in the file? */
 242:     UNLINK(kname);          /* delete the file */
 243:     if (local) {
 244:     if (localkfp)
 245:         fclose(localkfp);
 246:     localkfp = fopen(kname,"r");
 247:     }
 248:     else {
 249:     if (globkfp)
 250:         fclose(globkfp);
 251:     globkfp = fopen(kname,"r");
 252:     }
 253: }
 254: 
 255: void
 256: kf_append(cmd)
 257: char *cmd;
 258: {
 259:     strcpy(cmd_buf,filexp(getval("KILLLOCAL",killlocal)));
 260:     if (makedir(cmd_buf,MD_FILE) >= 0) {
 261: #ifdef VERBOSE
 262:     IF(verbose)
 263:         printf("\nDepositing command in %s...",cmd_buf);
 264:     ELSE
 265: #endif
 266: #ifdef TERSE
 267:         printf("\n--> %s...",cmd_buf);
 268: #endif
 269:     fflush(stdout);
 270:     sleep(2);
 271:     if ((tmpfp = fopen(cmd_buf,"a")) != Nullfp) {
 272:         fseek(tmpfp,0L,2);      /* get to EOF for sure */
 273:         fprintf(tmpfp,"%s\n",cmd);
 274:         fclose(tmpfp);
 275:         fputs("done\n",stdout) FLUSH;
 276:     }
 277:     else
 278:         printf(cantopen,cmd_buf) FLUSH;
 279:     }
 280: }
 281: #endif KILLFILES

Defined functions

do_kfile defined in line 75; used 3 times
kf_append defined in line 255; used 2 times
kfile_init defined in line 34; used 2 times
mention defined in line 53; used 2 times
open_kfile defined in line 231; used 5 times
setthru defined in line 181; used 2 times

Defined variables

killglobal defined in line 50; used 2 times
killlocal defined in line 51; used 4 times
Last modified: 1986-03-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1728
Valid CSS Valid XHTML 1.0 Strict