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 / addng.c next >
Text File  |  1990-08-25  |  4KB  |  171 lines

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