home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume23 / trn / part13 / addng.c next >
Encoding:
C/C++ Source or Header  |  1991-08-22  |  4.6 KB  |  196 lines

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