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 / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-17  |  2.2 KB  |  90 lines

  1. #ifndef lint
  2. static char    *sccsid = "@(#)list.c    1.11    (Berkeley) 5/11/89";
  3. #endif
  4.  
  5. #include "common.h"
  6.  
  7. /*
  8.  * LIST
  9.  *
  10.  * List active newsgroups, newsgroup descriptions, and distributions.
  11.  *
  12.  */
  13.  
  14. list(argc, argv)
  15.     int        argc;
  16.     char        *argv[];
  17. {
  18.     char        line[NNTP_STRLEN];
  19.     char        *grparray[2];
  20.     char        *filename;
  21.     char        *items;
  22.     char        *format;
  23.     register char    *cp;
  24.     register FILE    *list_fp;
  25.     
  26.     if (argc == 1 || (argc == 2 && !strcasecmp(argv[1],"active"))){
  27.                 num_groups = read_groups();
  28.                 if (num_groups == 0){ /* can't get a group list */
  29.                   printf("%d Group update failed. Try later.\r\n",
  30.                          ERR_FAULT);
  31.                   (void) fflush(stdout);
  32. #ifdef LOG
  33.                   syslog(LOG_INFO, "%s group update failed in LIST", hostname);
  34. #endif
  35.                   exit(1);
  36.                 }
  37.         filename = activefile;
  38.         items = "active newsgroups";
  39.         format = "Newsgroups in form \"group high low y/n/m\".";
  40.     } else if (argc == 2 && !strcasecmp(argv[1],"distributions")){
  41.         filename = distributionsfile;
  42.         items = "newsgroup distributions";
  43.         format = "Distributions in form \"area description\".";
  44.     } else if (argc == 2 && !strcasecmp(argv[1],"newsgroups")){
  45.         filename = newsgroupsfile;
  46.         items = "newsgroup descriptions";
  47.         format = "Descriptions in form \"group description\".";
  48.     } else {
  49.         printf("%d Usage: LIST [ACTIVE|NEWSGROUPS|DISTRIBUTIONS]\r\n",
  50.             ERR_CMDSYN);
  51.         (void) fflush(stdout);
  52.         return;
  53.     }
  54.  
  55.     grparray[0] = line;
  56.     grparray[1] = NULL;
  57.  
  58.     list_fp = fopen(filename, "r");
  59.  
  60.     if (list_fp == NULL) {
  61.         printf("%d No list of %s available.\r\n", ERR_FAULT,
  62.             items);
  63.         (void) fflush(stdout);
  64. #ifdef SYSLOG
  65.         syslog(LOG_ERR, "list: fopen %s: %m", filename);
  66. #endif
  67.         return;
  68.     }
  69.  
  70.     printf("%d %s\r\n",OK_GROUPS,format);
  71.  
  72.     while (fgets(line, sizeof(line), list_fp) != NULL) {
  73.         if ((cp = index(line, '\n')) != NULL)
  74.             *cp = '\0';
  75.         if (ngpermcount) {
  76.             if (ngmatch(s1strneql, ALLBUT,
  77.                 ngpermlist, ngpermcount,
  78.                 grparray, 1) == 0)
  79.                 continue;
  80.         }
  81.         else if (ALLBUT==0) break; /* ngpermcnt==0 && ALLBUT == 0 means
  82.                         * don't print the list, right? */
  83.         putline(line);
  84.     }
  85.     (void) fclose(list_fp);
  86.  
  87.     putline(".");
  88.     (void) fflush(stdout);
  89. }
  90.