Annotation of coherent/b/bin/as/fixdoc.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Turn the warning and error comments into nroff
        !             3:  * in the form suggested by Fred Buntzen.
        !             4:  *
        !             5:  * Input lines are formatted as
        !             6:  *     sort field
        !             7:  *     message
        !             8:  *     message type
        !             9:  *     zero or more comment lines
        !            10:  *
        !            11:  * Output lines are formatted as
        !            12:  * .IP "\fB message \fR" (message type)
        !            13:  * comment
        !            14:  * comment ...
        !            15:  */
        !            16: #include <stdio.h>
        !            17: 
        !            18: enum state { start, startMsg, inMsg, pct, mType, At, bsl, inComm };
        !            19: 
        !            20: main(argc, argv)
        !            21: char *argv[];
        !            22: {
        !            23:        register enum state state;
        !            24:        register c;
        !            25:        char *p, delim;
        !            26: 
        !            27:        delim = (NULL == argv[1]) ? '@' : argv[1][0];
        !            28: 
        !            29:        for (state = start; EOF != (c = getchar()); ) {
        !            30:                switch (state) {
        !            31:                case start:     /* discard sort field */
        !            32:                        if (c != delim)
        !            33:                                continue;
        !            34:                        printf(".IP \"\\fR");
        !            35:                        state = startMsg;
        !            36:                        continue;
        !            37: 
        !            38:                case startMsg:  /* first char of message */
        !            39:                        if ('.' == c) {
        !            40:                                putchar('\\');
        !            41:                                putchar('&');
        !            42:                        }
        !            43:                        state = inMsg;
        !            44: 
        !            45:                case inMsg:
        !            46:                        if (delim == c) {
        !            47:                                state = mType;
        !            48:                                printf("\\fR (");
        !            49:                                continue;
        !            50:                        }
        !            51:                        switch (c) {
        !            52:                        case '\\':
        !            53:                                state = bsl;
        !            54:                                continue;
        !            55:                        case '%':
        !            56:                                state = pct;
        !            57:                                continue;
        !            58: 
        !            59:                        case '\n':
        !            60:                                state = start;
        !            61:                                printf("\\fR\"\n");
        !            62:                                continue;
        !            63: 
        !            64:                        case '\'':
        !            65:                                putchar('\\');
        !            66:                        }
        !            67:                        break;
        !            68: 
        !            69:                case mType:
        !            70:                        if (delim == c) {
        !            71:                                state = At;
        !            72:                                printf(")\"\n");
        !            73:                                continue;
        !            74:                        }
        !            75:                        else if ('\n' == c) {
        !            76:                                putchar('"');
        !            77:                                state = start;
        !            78:                        }
        !            79:                        break;
        !            80: 
        !            81:                case bsl:
        !            82:                        state = inMsg;
        !            83:                        switch (c) {
        !            84:                        case '\\':
        !            85:                                printf("\\e");
        !            86:                                continue;
        !            87:                        default:        /* to be expanded */
        !            88:                                putchar('\\');
        !            89:                        }
        !            90:                        break;
        !            91: 
        !            92:                case pct:
        !            93:                        switch (c) {
        !            94:                        case 'c':
        !            95:                                p = "c";
        !            96:                                break;
        !            97:                        case 'd':
        !            98:                                p = "n";
        !            99:                                break;
        !           100:                        case 'x':
        !           101:                                p = "0xn";
        !           102:                                break;
        !           103:                        case 's':
        !           104:                                p = "string";
        !           105:                                break;
        !           106:                        default:
        !           107:                                continue;
        !           108:                        }
        !           109:                        printf("\\fI%s\\fR", p);
        !           110:                        state = inMsg;
        !           111:                        continue;
        !           112: 
        !           113:                case At:
        !           114:                        switch (c) {
        !           115:                        case ' ':       /* discard first space */
        !           116:                                state = inComm;
        !           117:                                continue;
        !           118:                        case '\n':      /* back to start */
        !           119:                                state = start;
        !           120:                                continue;
        !           121:                        default:        /* normal output */
        !           122:                                if (delim == c)
        !           123:                                        continue;
        !           124:                                state = inComm;
        !           125:                        }
        !           126:                        break;
        !           127: 
        !           128:                case inComm:                    
        !           129:                        if (delim == c) {
        !           130:                                c = '\n';
        !           131:                                state = At;
        !           132:                        }
        !           133:                        else if ('\n' == c)
        !           134:                                state = start;
        !           135:                }
        !           136:                putchar (c);
        !           137:        }
        !           138:        exit(0);
        !           139: }

unix.superglobalmegacorp.com

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