home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XT.ZIP / RN / KFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-21  |  7.3 KB  |  344 lines

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