Annotation of coherent/d/bin/cc/c/cpp/cpp.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * 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:  */
                      9: #include <stdio.h>
                     10: #include <path.h>
                     11: #include "var.h"
                     12: #include "varmch.h"
                     13: 
                     14: #define        VERBOSITY       0       /* must be 0 to compile using old cpp */
                     15: 
                     16: VARIANT variant;
                     17: char vstr[2*VMAXIM/VGRANU + 1];
                     18: char *cppargs[128];
                     19: int  cppargc;
                     20: int  verbose = 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: main(argc, argv)
                     41: register int argc;
                     42: register char **argv;
                     43: {
                     44:        register char *ap;
                     45:        register int i, s;
                     46: #if    GEMDOS || COHERENT
                     47:        char *libptr;
                     48: #endif
                     49: #if    MSDOS
                     50:        register int len;
                     51:        register char *tail;
                     52: #endif
                     53: 
                     54:        cppargc = 4;
                     55:        setvariant(VCPP);
                     56:        if (argc-- < 2)
                     57:                usage();
                     58:        while (argc-- > 0) {
                     59:                ap = *++argv;
                     60: #if    DEBUG
                     61:                printf("%d: %s\n", argc, ap);
                     62: #endif
                     63:                if (*ap == '-') {
                     64:                        switch (ap[1]) {
                     65:                        case 'I':
                     66:                                cppargs[cppargc++] = ap;
                     67:                                if (ap[2] == 0) {
                     68:                                        if ((cppargs[cppargc++] = *++argv)
                     69:                                                                        == NULL)
                     70:                                                usage();
                     71:                                        --argc;
                     72:                                }
                     73:                                break;
                     74: 
                     75:                        case 'D':
                     76:                        case 'U':
                     77:                                cppargs[cppargc++] = ap;
                     78:                                break;
                     79: 
                     80:                        case 'o':
                     81:                                if ((cppargs[3] = *++argv) == NULL)
                     82:                                        usage();
                     83:                                --argc;
                     84:                                break;
                     85: 
                     86:                        case 'C':
                     87: #if    VCNEST
                     88:                                setvariant(VCNEST);
                     89: #endif
                     90:                                break;
                     91: 
                     92:                        case 'E':
                     93:                                setvariant(VCPPE);
                     94:                                break;
                     95: 
                     96:                        case 'Q':
                     97:                                verbose = 0;
                     98:                                setvariant(VQUIET);
                     99:                                break;
                    100:                        case '3':
                    101:                                setvariant(V3GRAPH);
                    102:                                break;
                    103:                        case 'V':
                    104:                                verbose++;
                    105:                                break;
                    106:                        default:
                    107:                                usage();
                    108:                        }
                    109:                } else if (cppargs[2] != NULL) {
                    110:                        usage();
                    111:                } else
                    112:                        cppargs[2] = ap;
                    113:        }
                    114: 
                    115:        if (cppargs[2] == NULL)
                    116:                cppargs[2] = "-";
                    117:        if (cppargs[3] == NULL)
                    118:                cppargs[3] = "-";
                    119: 
                    120: #if    GEMDOS || COHERENT
                    121:        if ((libptr = getenv("LIBPATH")) == NULL)
                    122:                libptr = DEFLIBPATH;
                    123:        if ((ap = path(libptr, CC0NAME, AEXEC)) == NULL)
                    124:                cerr("cannot find cc0");
                    125:        cppargs[0] = ap;
                    126: #endif
                    127: #if    MSDOS
                    128:        cppargs[0] = CC0NAME;
                    129: #endif
                    130:        makvariant(vstr);
                    131:        cppargs[1] = vstr;
                    132:        if (verbose) {
                    133:                for (i = 0; i<cppargc; i++)
                    134:                        printf("%s ", cppargs[i]);
                    135:                printf("\n");
                    136:        }
                    137: #if    GEMDOS || COHERENT
                    138:        if (s = execve(cppargs[0], cppargs, environ))
                    139:                if (s < 0)
                    140:                        perror(cppargs[0]);
                    141: #endif
                    142: #if    MSDOS
                    143:        for (len=0, i=1; i<cppargc; i++)
                    144:                len += strlen(cppargs[i]) + 1;
                    145:        if ((tail = malloc(len)) == NULL)
                    146:                cerr("cannot allocate tail");
                    147:        for (tail[0]='\0', i=1; i<cppargc; i++) {
                    148:                strcat(tail, cppargs[i]);
                    149:                if (i < cppargc-1)
                    150:                        strcat(tail, " ");
                    151:        }
                    152:        if ((s = execall(cppargs[0], tail)) == 0177)
                    153:                cerr("cannot execute cc0");
                    154: #endif
                    155:        exit(s);
                    156: }
                    157: 
                    158: usage() {
                    159:        fprintf(stderr, "Usage:\tcpp [ option... ] [ file ]\n");
                    160: #if    VERBOSITY
                    161:        fprintf(stderr,
                    162:                "Options:\n"
                    163:                /* UNDOCUMENTED: -3 */
                    164: #if    VCNEST
                    165:                "   -C\t\t\tallow nested comments\n"
                    166: #endif
                    167:                "   -Dvariable[=val]\tdefine variable with val [default=1]\n"
                    168:                "   -E\t\t\tstrip all comments and line numbers\n"
                    169:                "   -Idirectory\t\tadd directory to #include file search list\n"
                    170:                "   -o outfile\t\twrite output to outfile [default=stdout]\n"
                    171:                "   -Q\t\t\tsupress all messages\n"
                    172:                "   -Uvariable\t\tundefine variable\n"
                    173:                "   -V\t\t\tprint verbose information\n"
                    174:                );
                    175: #endif
                    176:        exit(1);
                    177: }
                    178: 
                    179: cerr(s)
                    180: char *s;
                    181: {
                    182:        fprintf(stderr, "cpp: %s\n", s);
                    183:        exit(1);
                    184: }
                    185: 
                    186: /* end of cpp.c */

unix.superglobalmegacorp.com

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