Annotation of coherent/b/bin/c/cpp/cpp.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * cpp/cpp.c
        !             3:  * Run cc0 (from LIBPATH under GEMDOS) for old cpp functionality.
        !             4:  * Default to stdin and stdout.
        !             5:  * See usage() for details.
        !             6:  * v0   -- dag 870722
        !             7:  * v1   -- steve 870730        COHERENT and MSDOS conditionalization
        !             8:  * v2   -- steve 920716        -C and -P options
        !             9:  * v4.0 -- steve 930128        -VCPLUS option
        !            10:  */
        !            11: 
        !            12: #include <stdio.h>
        !            13: #include <path.h>
        !            14: #include "var.h"
        !            15: #include "varmch.h"
        !            16: 
        !            17: #define        NEWCPP  1       /* must be 0 to compile using old cpp */
        !            18:                        /* because it does not understand "string1" "string2" */
        !            19: 
        !            20: #define        VERSION "4.0"
        !            21: 
        !            22: #if    COHERENT
        !            23: #define        CC0NAME "cc0"
        !            24: extern char **environ;
        !            25: extern char *getenv();
        !            26: #endif
        !            27: 
        !            28: #if    GEMDOS
        !            29: #define        CC0NAME "cc0.prg"
        !            30: extern char **environ;
        !            31: extern char *getenv();
        !            32: #endif
        !            33: 
        !            34: #if    MSDOS
        !            35: #define        CC0NAME "cc0"
        !            36: extern char *malloc();
        !            37: extern char *strcat();
        !            38: #endif
        !            39: 
        !            40: /* Forward. */
        !            41: void   usage();
        !            42: void   cpperror();
        !            43: 
        !            44: /* Globals. */
        !            45: int    cppargc;
        !            46: char   *cppargs[128];
        !            47: VARIANT        variant;
        !            48: int    verbose = 0;
        !            49: char   vstr[2*VMAXIM/VGRANU + 1];
        !            50: 
        !            51: main(argc, argv) int argc; char *argv[];
        !            52: {
        !            53:        register char *ap;
        !            54:        register int i, s;
        !            55: #if    GEMDOS || COHERENT
        !            56:        char *libptr;
        !            57: #endif
        !            58: #if    MSDOS
        !            59:        register int len;
        !            60:        register char *tail;
        !            61: #endif
        !            62: 
        !            63: #if    COHERENT
        !            64:        _addargs("CPP", &argc, &argv);
        !            65: #endif
        !            66: 
        !            67:        cppargc = 4;
        !            68:        setvariant(VCPP);
        !            69:        argc--;
        !            70:        while (argc-- > 0) {
        !            71:                ap = *++argv;
        !            72: #if    DEBUG
        !            73:                printf("%d: %s\n", argc, ap);
        !            74: #endif
        !            75:                if (*ap == '-') {
        !            76:                        switch (ap[1]) {
        !            77:                        case 'I':
        !            78:                                cppargs[cppargc++] = ap;
        !            79:                                if (ap[2] == 0) {
        !            80:                                        if ((cppargs[cppargc++] = *++argv)
        !            81:                                                                        == NULL)
        !            82:                                                usage();
        !            83:                                        --argc;
        !            84:                                }
        !            85:                                break;
        !            86: 
        !            87:                        case 'D':
        !            88:                        case 'U':
        !            89:                                cppargs[cppargc++] = ap;
        !            90:                                break;
        !            91: 
        !            92:                        case 'o':
        !            93:                                if ((cppargs[3] = *++argv) == NULL)
        !            94:                                        usage();
        !            95:                                --argc;
        !            96:                                break;
        !            97: 
        !            98:                        case 'C':
        !            99:                                setvariant(VCPPC);
        !           100:                                break;
        !           101: 
        !           102:                        case 'E':
        !           103:                        case 'P':
        !           104:                                setvariant(VCPPE);
        !           105:                                break;
        !           106: 
        !           107:                        case 'Q':
        !           108:                                verbose = 0;
        !           109:                                setvariant(VQUIET);
        !           110:                                break;
        !           111: 
        !           112:                        case '3':
        !           113:                                setvariant(V3GRAPH);
        !           114:                                break;
        !           115: 
        !           116:                        case 'V':
        !           117:                                if (strcmp(&ap[2], "CPLUS") == 0) {
        !           118:                                        setvariant(VCPLUS);
        !           119:                                        break;
        !           120:                                }
        !           121:                                fprintf(stderr, "cpp: V%s\n", VERSION);
        !           122:                                verbose++;
        !           123:                                break;
        !           124: 
        !           125:                        case '?':
        !           126:                        default:
        !           127:                                usage();
        !           128:                        }
        !           129:                } else if (cppargs[2] != NULL) {
        !           130:                        usage();
        !           131:                } else
        !           132:                        cppargs[2] = ap;
        !           133:        }
        !           134: 
        !           135:        if (cppargs[2] == NULL)
        !           136:                cppargs[2] = "-";
        !           137:        if (cppargs[3] == NULL)
        !           138:                cppargs[3] = "-";
        !           139: 
        !           140: #if    GEMDOS || COHERENT
        !           141:        if ((libptr = getenv("LIBPATH")) == NULL)
        !           142:                libptr = DEFLIBPATH;
        !           143:        if ((ap = path(libptr, CC0NAME, AEXEC)) == NULL)
        !           144:                cpperror("cannot find cc0");
        !           145:        cppargs[0] = ap;
        !           146: #endif
        !           147: #if    MSDOS
        !           148:        cppargs[0] = CC0NAME;
        !           149: #endif
        !           150:        makvariant(vstr);
        !           151:        cppargs[1] = vstr;
        !           152:        if (verbose) {
        !           153:                for (i = 0; i<cppargc; i++)
        !           154:                        printf("%s ", cppargs[i]);
        !           155:                printf("\n");
        !           156:        }
        !           157: #if    GEMDOS || COHERENT
        !           158:        if (s = execve(cppargs[0], cppargs, environ))
        !           159:                if (s < 0)
        !           160:                        perror(cppargs[0]);
        !           161: #endif
        !           162: #if    MSDOS
        !           163:        for (len=0, i=1; i<cppargc; i++)
        !           164:                len += strlen(cppargs[i]) + 1;
        !           165:        if ((tail = malloc(len)) == NULL)
        !           166:                cpperror("cannot allocate tail");
        !           167:        for (tail[0]='\0', i=1; i<cppargc; i++) {
        !           168:                strcat(tail, cppargs[i]);
        !           169:                if (i < cppargc-1)
        !           170:                        strcat(tail, " ");
        !           171:        }
        !           172:        if ((s = execall(cppargs[0], tail)) == 0177)
        !           173:                cpperror("cannot execute cc0");
        !           174: #endif
        !           175:        exit(s);
        !           176: }
        !           177: 
        !           178: void
        !           179: usage()
        !           180: {
        !           181:        fprintf(stderr, "Usage:\t/lib/cpp [ option... ] [ file ]\n");
        !           182: #if    NEWCPP
        !           183:        fprintf(stderr,
        !           184:                "Options:\n"
        !           185: #if    VCNEST
        !           186:                /* UNDOCUMENTED: -3 */
        !           187: #endif
        !           188:                "\t-C\t\t\tdo not suppress comments\n"
        !           189:                "\t-Dvariable[=val]\tdefine variable with val [default=1]\n"
        !           190:                "\t-E\t\t\tstrip file line number information\n"
        !           191:                "\t-Idirectory\t\tadd directory to #include file search list\n"
        !           192:                "\t-o outfile\t\twrite output to outfile [default=stdout]\n"
        !           193:                "\t-P\t\t\tstrip file line number information (same as -E)\n"
        !           194:                "\t-Q\t\t\tsuppress all messages\n"
        !           195:                "\t-Uvariable\t\tundefine variable\n"
        !           196:                "\t-V\t\t\tprint verbose information\n"
        !           197:                "\t-VCPLUS\t\t\tsuppress C++ - style online comments\n"
        !           198:                );
        !           199: #endif
        !           200:        exit(1);
        !           201: }
        !           202: 
        !           203: void
        !           204: cpperror(s) char *s;
        !           205: {
        !           206:        fprintf(stderr, "cpp: %s\n", s);
        !           207:        exit(1);
        !           208: }
        !           209: 
        !           210: /* end of cpp/cpp.c */

unix.superglobalmegacorp.com

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