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

  1. /* $Header: E:\SRC\UUPC\RN\RCS/ADDNG.C 1.1 1992/11/21 06:14:58 ahd Exp $
  2.  *
  3.  * $Log: ADDNG.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:20
  9.  * Initial revision.
  10.  * Revision 4.3.2.4  90/03/17  17:11:36  sob
  11.  * Added support for CNEWS active file flags.
  12.  *
  13.  * Revision 4.3.2.4  89/12/20  00:30:00  tale
  14.  * Added support for C News active file flags.
  15.  *
  16.  * Revision 4.3.2.3  89/11/08  02:33:28  sob
  17.  * Added include for server.h
  18.  *
  19.  * Revision 4.3.2.2  89/11/08  01:23:49  sob
  20.  * Added GROUP check when SERVER defined.
  21.  *
  22.  * Revision 4.3.2.1  89/11/06  00:34:11  sob
  23.  * Added RRN support from NNTP 1.5
  24.  *
  25.  * Revision 4.3.1.2  85/05/29  09:06:24  lwall
  26.  * New newsgroups without spool directories incorrectly classified as "ancient".
  27.  *
  28.  * Revision 4.3.1.1  85/05/10  11:30:50  lwall
  29.  * Branch for patches.
  30.  *
  31.  * Revision 4.3  85/05/01  11:34:41  lwall
  32.  * Baseline for release with 4.3bsd.
  33.  *
  34.  */
  35.  
  36. #include "EXTERN.h"
  37. #include "common.h"
  38. #include "rn.h"
  39. #include "ngdata.h"
  40. #include "last.h"
  41. #include "util.h"
  42. #include "intrp.h"
  43. #include "only.h"
  44. #include "rcstuff.h"
  45.  
  46. #ifdef SERVER
  47. #include "server.h"
  48. #endif
  49.  
  50. #include "INTERN.h"
  51. #include "addng.h"
  52.  
  53. void
  54.   addng_init()
  55. {
  56.    ;
  57. }
  58.  
  59. #ifdef FINDNEWNG
  60. /* generate a list of new newsgroups from active file */
  61.  
  62. bool
  63. newlist(munged, checkinlist)
  64.    bool munged;              /* are we scanning the
  65.                               * whole file? */
  66.    bool checkinlist;
  67. {
  68.    char *tmpname;
  69.    register char *s, *status;
  70.    long birthof();
  71.  
  72.    tmpname = savestr(filexp("/tmp/rnew.%$"));
  73.    tmpfp = fopen(tmpname, "w");
  74.    if (tmpfp == Nullfp)
  75.    {
  76.       printf(cantcreate, tmpname) FLUSH;
  77.       return FALSE;
  78.    }
  79.    while (fgets(buf, LBUFLEN, actfp) != Nullch)
  80.    {
  81.       if (s = index(buf, ' '))
  82.       {
  83.          status = s;
  84.          while (isdigit(*status) || isspace(*status))
  85.             status++;
  86.          *s++ = '\0';
  87.          if (strnEQ(buf, "to.", 3) || *status == 'x' || *status == '=')
  88.             /* since = groups are refiling to another group, just ignore their
  89.              * existence */
  90.             continue;
  91.          if (find_ng(buf) == nextrcline &&
  92.                (checkinlist ?
  93.                 (inlist(buf)) :
  94.                 (birthof(buf, (ART_NUM) atol(s)) > lasttime)
  95.                 )
  96.             )
  97.          {
  98.             /* if not in .newsrc and younger */
  99.             /* than the last time we checked */
  100.             fprintf(tmpfp, "%s\n", buf);
  101.             /* then remember said newsgroup */
  102.          }
  103.  
  104. #ifdef FASTNEW
  105.          else
  106.          {                   /* not really a new
  107.                               * group */
  108.             if (!munged)
  109.             {                /* did we assume not
  110.                               * munged? */
  111.                fclose(tmpfp);/* then go back, knowing
  112.                               * that */
  113.                UNLINK(tmpname);
  114.                free(tmpname);
  115.                return TRUE;  /* active file was
  116.                               * indeed munged */
  117.             }
  118.          }
  119. #endif
  120.       }
  121.  
  122. #ifdef DEBUGGING
  123.       else
  124.          printf("Bad active record: %s\n", buf) FLUSH;
  125. #endif
  126.    }
  127.  
  128.    /* we have successfully generated the list */
  129.  
  130.    fclose(tmpfp);
  131.    tmpfp = fopen(tmpname, "r");
  132.    UNLINK(tmpname);          /* be nice to the world */
  133.    if (tmpfp == Nullfp)
  134.    {
  135.       printf(cantopen, tmpname) FLUSH;
  136.       return FALSE;
  137.    }
  138.    while (fgets(buf, LBUFLEN, tmpfp) != Nullch)
  139.    {
  140.       buf[strlen(buf) - 1] = '\0';
  141.       get_ng(buf, TRUE);     /* add newsgroup, maybe */
  142.    }
  143.    fclose(tmpfp);            /* be nice to ourselves */
  144.    free(tmpname);
  145.    return FALSE;             /* do not call us again */
  146. }
  147.  
  148. /* return creation time of newsgroup */
  149.  
  150. long
  151.   birthof(ngnam, ngsize)
  152.    char *ngnam;
  153.    ART_NUM ngsize;
  154. {
  155.    char tst[128];
  156.    long time();
  157.  
  158. #ifdef SERVER
  159.    int x, tot, min, max;
  160.  
  161.    if (ngsize < 2)
  162.    {
  163.       sprintf(tst, "GROUP %s", ngnam);
  164.       put_server(tst);
  165.       (void) get_server(tst, sizeof (tst));
  166.       if (*tst != CHAR_OK)
  167.          return (0);         /* not a real group */
  168.       (void) sscanf(tst, "%d%d%d%d", &x, &tot, &min, &max);
  169.       if (tot == 1 && min == 1 && max == 1)
  170.          return (time(Null(long *)));
  171.    }
  172.    else
  173.       return (0);
  174. #else                        /* not SERVER */
  175.  
  176.    importng( tst, ngnam, ngsize ? 1 : 0 );
  177.  
  178.    if (stat(tst, &filestat) < 0)
  179.       return (ngsize ? 0L : time(Null(long *)));
  180.    /* not there, assume something good */
  181.    else
  182.       return filestat.st_mtime;
  183. #endif
  184. }
  185.  
  186. bool
  187. scanactive()
  188. {
  189.    NG_NUM oldnext = nextrcline; /* remember # lines in newsrc */
  190.  
  191.    fseek(actfp, 0L, 0);
  192.    newlist(TRUE, TRUE);
  193.    if (nextrcline != oldnext)
  194.    {                         /* did we add any new groups? */
  195.       return TRUE;
  196.    }
  197.    return FALSE;
  198. }
  199.  
  200. #endif
  201.