home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NNTP-1.000 / NNTP-1 / nntp.1.5.11t / server / newgroups.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-17  |  2.6 KB  |  128 lines

  1. #ifndef lint
  2. static char    *sccsid = "@(#)newgroups.c    1.13    (Berkeley) 2/6/88";
  3. #endif
  4.  
  5. #include "common.h"
  6. #include "time.h"
  7.  
  8. /*
  9.  * NEWGROUPS date time ["GMT"] [<distributions>]
  10.  *
  11.  * Display new newsgroups since a given date and time, but only
  12.  * for those in <distributions>.
  13.  */
  14.  
  15. newgroups(argc, argv)
  16.     int        argc;
  17.     char        *argv[];
  18. {
  19.     char        line[NNTP_STRLEN];
  20.     register char    *cp, *temp;
  21.     static char    **dist_list = (char **) NULL;
  22.     int        distcount = 0;
  23.     int        i;
  24.     long        date;
  25.     register FILE    *date_fp;
  26.  
  27.     if (argc < 3) {
  28. printf("%d Usage: NEWGROUPS yymmdd hhmmss [\"GMT\"] [<distributions>].\r\n",
  29.             ERR_CMDSYN);
  30.         (void) fflush(stdout);
  31.         return;
  32.     }
  33.  
  34.     date_fp = fopen(ngdatefile, "r");
  35.     if (date_fp == NULL) {
  36. #ifdef SYSLOG
  37.         syslog(LOG_ERR, "newgroups: fopen %s: %m", ngdatefile);
  38. #endif
  39.         printf("%d Cannot open newsgroup date file.\r\n", ERR_FAULT);
  40.         (void) fflush(stdout);
  41.         return;
  42.     }
  43.  
  44.     /*        YYMMDD            HHMMSS    */
  45.     if (strlen(argv[1]) != 6 || strlen(argv[2]) != 6) {
  46.         printf("%d Date/time must be in form YYMMDD HHMMSS.\r\n",
  47.             ERR_CMDSYN);
  48.         (void) fflush(stdout);
  49.         (void) fclose(date_fp);
  50.         return;
  51.     }
  52.  
  53.     (void) strcpy(line, argv[1]);            /* yymmdd */
  54.     (void) strcat(line, argv[2]);            /* hhmmss */
  55.  
  56.     date = dtol(line);
  57.     if (date < 0) {
  58.         printf("%d Invalid date specification.\r\n", ERR_CMDSYN);
  59.         (void) fflush(stdout);
  60.         (void) fclose(date_fp);
  61.         return;
  62.     }
  63.  
  64.     argc -= 3;
  65.     argv += 3;
  66.  
  67.     if (argc > 0 && !strcasecmp(*argv, "GMT")) { /* We store stuff in GMT */
  68.             ++argv;            /* anyway, so this is */
  69.             --argc;            /* a "noop" */
  70.     } else                     /* But that means not GMT */
  71.         date = local_to_gmt(date);    /* is a definite "op" */
  72.  
  73.     if (argc > 0) {
  74.         distcount = get_distlist(&dist_list, *argv);
  75.         if (distcount < 0) {
  76.             printf("%d Bad distribution list %s:\r\n", *argv);
  77.             (void) fflush(stdout);
  78.             (void) fclose(date_fp);
  79.             return;
  80.         }
  81.     }
  82.  
  83.     printf("%d New newsgroups since %s follow.\r\n", OK_NEWGROUPS, line);
  84.  
  85.     while (fgets(line, sizeof(line), date_fp) != NULL) {
  86.         if ((cp = index(line, '\n')) != NULL)
  87.             *cp = '\0';
  88.         if ((cp = index(line, ' ')) != NULL)
  89.             *cp = '\0';
  90. #ifdef ACTIVE_TIMES_FILE
  91.         if (atoi(cp + 1) < date)
  92.             continue;
  93. #else
  94.         if (atoi(line) < date)
  95.             break;
  96. #endif
  97.  
  98.         if (distcount == 0) {
  99. #ifdef ACTIVE_TIMES_FILE
  100.             putline(line);
  101. #else
  102.             putline(cp + 1);
  103. #endif
  104.         } else {
  105. #ifdef ACTIVE_TIMES_FILE
  106.             temp = line;
  107. #else
  108.             temp = cp + 1;
  109. #endif
  110.             cp = index(temp, '.');
  111.             if (cp == NULL)
  112.                 continue;
  113.             *cp = '\0';
  114.             for (i = 0; i < distcount; ++i)
  115.                 if (strcmp(temp, dist_list[i]) == 0) {
  116.                     *cp = '.';
  117.                     putline(temp);
  118.                     break;
  119.                 }
  120.         }
  121.     }
  122.     putchar('.');
  123.     putchar('\r');
  124.     putchar('\n');
  125.     (void) fflush(stdout);
  126.     (void) fclose(date_fp);
  127. }
  128.