home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / rn_4_3_blars.lzh / kfile.c < prev    next >
Text File  |  1990-08-22  |  6KB  |  299 lines

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