Annotation of 43BSD/contrib/news/misc/article.c, revision 1.1

1.1     ! root        1: /* down!honey 4/84 */
        !             2: 
        !             3: #define HISTORY "/usr/new/lib/news/history"
        !             4: #define NEWSDIR "/usr/spool/news"
        !             5: 
        !             6: char   *formats[] = {          /* add as appropriate */
        !             7:        "<%s.uucp>",
        !             8:        "<%s>",
        !             9:        "<%s.arpa>",
        !            10:        "<%s.oz>",
        !            11:        0
        !            12: };
        !            13: 
        !            14: #include <stdio.h>
        !            15: #include <sysexits.h>
        !            16: #include <ctype.h>
        !            17: 
        !            18: typedef struct {
        !            19:        char    *dptr;
        !            20:        int     dsize;
        !            21: } datum;
        !            22: 
        !            23: long   lseek();
        !            24: char   *index();
        !            25: datum  fetch(), dofetch();
        !            26: 
        !            27: main(argc, argv)
        !            28: char **argv;
        !            29: {
        !            30:        int     fd;
        !            31:        char    buf[BUFSIZ], *ptr1, *ptr2;
        !            32:        datum   content;
        !            33:        long    offset;
        !            34: 
        !            35:        if ((fd = open(HISTORY, 0)) < 0) {
        !            36:                perror(HISTORY);
        !            37:                exit(EX_UNAVAILABLE);
        !            38:        }
        !            39:        if (dbminit(HISTORY) < 0) {
        !            40:                fprintf(stderr, "dbm error\n");
        !            41:                exit(EX_UNAVAILABLE);
        !            42:        }
        !            43:        for (--argc, argv++; argc; --argc, argv++) {
        !            44:                content = dofetch(*argv);
        !            45:                if (content.dptr == 0) {
        !            46:                        printf("%s: No such key\n", *argv);
        !            47:                        continue;
        !            48:                }
        !            49:                /* ensure alignment */
        !            50:                bcopy(content.dptr, (char *)&offset, sizeof offset);
        !            51:                if (lseek(fd, offset, 0) < 0)
        !            52:                        continue;
        !            53:                if (read(fd, buf, sizeof buf) <= 0)
        !            54:                        continue;
        !            55:                if ((ptr2 = index(buf, '\n')) == 0)
        !            56:                        continue;
        !            57:                *ptr2 = '\0';
        !            58:                if ((ptr1 = index(buf, '\t')) == 0)
        !            59:                        continue;
        !            60:                ptr1++;
        !            61:                if ((ptr1 = index(ptr1, '\t')) == 0)
        !            62:                        continue;
        !            63:                ptr1++;
        !            64:                for (ptr2 = ptr1; ptr2 = index(ptr2, '.'); *ptr2 = '/')
        !            65:                        ;
        !            66:                if ((ptr2 = index(ptr1, ' ')) != NULL)
        !            67:                        *ptr2 = '\0';
        !            68:                if (*ptr1 == '\0')
        !            69:                        printf("expired\n");
        !            70:                else
        !            71:                        printf("%s/%s\n", NEWSDIR, ptr1);
        !            72:        }
        !            73:        exit(EX_OK);
        !            74: }
        !            75: 
        !            76: datum
        !            77: dofetch(str)
        !            78: char   *str;
        !            79: {
        !            80:        datum   key, content;
        !            81:        char    buf[BUFSIZ], **fmt;
        !            82:        register char *rcp;
        !            83: 
        !            84:        for (fmt = formats; *fmt; fmt++) {
        !            85:                sprintf(buf, *fmt, str);
        !            86:                rcp = buf - 1;
        !            87:                while (*++rcp)
        !            88:                        if (isupper(*rcp))
        !            89:                                *rcp = tolower(*rcp);
        !            90:                key.dptr = buf;
        !            91:                key.dsize = strlen(buf) + 1;
        !            92:                content = fetch(key);
        !            93:                if (content.dptr)
        !            94:                        break;
        !            95:        }
        !            96:        return(content);
        !            97: }

unix.superglobalmegacorp.com

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