Annotation of 3BSD/cmd/getNAME.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: 
        !             3: int tocrc;
        !             4: 
        !             5: main(argc, argv)
        !             6:        int argc;
        !             7:        char *argv[];
        !             8: {
        !             9: 
        !            10:        argc--, argv++;
        !            11:        if (!strcmp(argv[0], "-t"))
        !            12:                argc--, argv++, tocrc++;
        !            13:        while (argc > 0)
        !            14:                getfrom(*argv++), argc--;
        !            15:        exit(0);
        !            16: }
        !            17: 
        !            18: getfrom(name)
        !            19:        char *name;
        !            20: {
        !            21:        char headbuf[BUFSIZ];
        !            22:        char linbuf[BUFSIZ];
        !            23:        register char *cp;
        !            24:        int i = 0;
        !            25: 
        !            26:        if (freopen(name, "r", stdin) == 0) {
        !            27:                perror(name);
        !            28:                exit(1);
        !            29:        }
        !            30:        for (;;) {
        !            31:                if (fgets(headbuf, sizeof headbuf, stdin) == NULL)
        !            32:                        return;
        !            33:                if (headbuf[0] != '.')
        !            34:                        continue;
        !            35:                if (headbuf[1] == 'T' && headbuf[2] == 'H')
        !            36:                        break;
        !            37:                if (headbuf[1] == 't' && headbuf[2] == 'h')
        !            38:                        break;
        !            39:        }
        !            40:        for (;;) {
        !            41:                if (fgets(linbuf, sizeof linbuf, stdin) == NULL)
        !            42:                        return;
        !            43:                if (linbuf[0] != '.')
        !            44:                        continue;
        !            45:                if (linbuf[1] == 'S' && linbuf[2] == 'H')
        !            46:                        break;
        !            47:                if (linbuf[1] == 's' && linbuf[2] == 'h')
        !            48:                        break;
        !            49:        }
        !            50:        trimln(headbuf);
        !            51:        if (tocrc) {
        !            52:                register char *dp = name, *ep;
        !            53: 
        !            54: again:
        !            55:                while (*dp && *dp != '.')
        !            56:                        putchar(*dp++);
        !            57:                if (*dp)
        !            58:                        for (ep = dp+1; *ep; ep++)
        !            59:                                if (*ep == '.') {
        !            60:                                        putchar(*dp++);
        !            61:                                        goto again;
        !            62:                                }
        !            63:                putchar('(');
        !            64:                if (*dp)
        !            65:                        dp++;
        !            66:                while (*dp)
        !            67:                        putchar (*dp++);
        !            68:                putchar(')');
        !            69:                putchar(' ');
        !            70:        }
        !            71:        printf("%s\t", headbuf);
        !            72:        for (;;) {
        !            73:                if (fgets(linbuf, sizeof linbuf, stdin) == NULL)
        !            74:                        break;
        !            75:                if (linbuf[0] == '.') {
        !            76:                        if (linbuf[1] == 'S' && linbuf[2] == 'H')
        !            77:                                break;
        !            78:                        if (linbuf[1] == 's' && linbuf[2] == 'h')
        !            79:                                break;
        !            80:                }
        !            81:                trimln(linbuf);
        !            82:                if (i != 0)
        !            83:                        printf(" ");
        !            84:                i++;
        !            85:                printf("%s", linbuf);
        !            86:        }
        !            87:        printf("\n");
        !            88: }
        !            89: 
        !            90: trimln(cp)
        !            91:        register char *cp;
        !            92: {
        !            93: 
        !            94:        while (*cp)
        !            95:                cp++;
        !            96:        if (*--cp == '\n')
        !            97:                *cp = 0;
        !            98: }

unix.superglobalmegacorp.com

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