Annotation of 43BSD/contrib/nntp/server/newgroups.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char    *sccsid = "@(#)newgroups.c      1.4     (Berkeley) 3/20/86";
        !             3: #endif
        !             4: 
        !             5: #include "common.h"
        !             6: 
        !             7: long   local_to_gmt();
        !             8: 
        !             9: /*
        !            10:  * NEWGROUPS date time ["GMT"] [<distributions>]
        !            11:  *
        !            12:  * Display new newsgroups since a given date and time, but only
        !            13:  * for those in <distributions>.
        !            14:  */
        !            15: 
        !            16: newgroups(argc, argv)
        !            17: int    argc;
        !            18: char   *argv[];
        !            19: {
        !            20:        char            line[MAX_STRLEN];
        !            21:        register char   *cp, *temp;
        !            22:        static char     **dist_list = (char **) NULL;
        !            23:        int             distcount = 0;
        !            24:        int             i;
        !            25:        long            date;
        !            26:        register FILE   *date_fp;
        !            27:        long            dtol();
        !            28: 
        !            29:        if (argc < 3) {
        !            30:                printf("%d NEWGROUPS requires at least two arguments.\r\n",
        !            31:                        ERR_CMDSYN);
        !            32:                (void) fflush(stdout);
        !            33:                return;
        !            34:        }
        !            35: 
        !            36:        date_fp = fopen(NGDATE_FILE, "r");
        !            37:        if (date_fp == NULL) {
        !            38:                syslog(LOG_ERR, "newgroups: fopen %s: %m", NGDATE_FILE);
        !            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 && streql(*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:                if (atoi(line) < date)
        !            91:                        break;
        !            92: 
        !            93:                if (distcount == 0)
        !            94:                        printf("%s\r\n", cp + 1);
        !            95:                else {
        !            96:                        temp = cp + 1;
        !            97:                        cp = index(temp, '.');
        !            98:                        if (cp == NULL)
        !            99:                                continue;
        !           100:                        *cp = '\0';
        !           101:                        for (i = 0; i < distcount; ++i)
        !           102:                                if (strcmp(temp, dist_list[i]) == 0) {
        !           103:                                        *cp = '.';
        !           104:                                        printf("%s\r\n", temp);
        !           105:                                        break;
        !           106:                                }
        !           107:                }
        !           108:        }
        !           109:        printf(".\r\n");
        !           110:        (void) fflush(stdout);
        !           111:        (void) fclose(date_fp);
        !           112: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.