Annotation of researchv10no/cmd/grap/non-ansi/main.c, revision 1.1.1.1

1.1       root        1: #include       <stdio.h>
                      2: #include       <signal.h>
                      3: #include       <math.h>
                      4: #include       "grap.h"
                      5: #include       "y.tab.h"
                      6: 
                      7: int    dbg     = 0;
                      8: 
                      9: #ifndef GRAPDEFINES
                     10: #define GRAPDEFINES "/usr/lib/grap.defines"
                     11: #endif
                     12: char   *lib_defines    = GRAPDEFINES;
                     13: 
                     14: int    lib     = 1;            /* 1 to include lib_defines */
                     15: FILE   *tfd    = NULL;
                     16: char   *tempfile = NULL;
                     17: 
                     18: int    synerr  = 0;
                     19: int    codegen = 0;            /* 1=>output for this picture; 0=>no output */
                     20: char   *cmdname;
                     21: 
                     22: Obj    *objlist = NULL;        /* all names stored here */
                     23: 
                     24: #define        BIG     1e30
                     25: Point  ptmin   = { NULL, -BIG, -BIG };
                     26: Point  ptmax   = { NULL, BIG, BIG };
                     27: 
                     28: char   *version = "version February 5, 1990";
                     29: 
                     30: main(argc, argv)
                     31:        char **argv;
                     32: {
                     33:        extern int onintr(), fpecatch();
                     34:        char *getenv();
                     35: 
                     36:        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
                     37:                signal(SIGINT, onintr);
                     38:        signal(SIGFPE, fpecatch);
                     39:        tempfile = "/tmp/grap.XXXXXX";
                     40:        cmdname = argv[0];
                     41:        while (argc > 1 && *argv[1] == '-') {
                     42:                switch (argv[1][1]) {
                     43:                case 'd':
                     44:                        dbg = 1;
                     45:                        tfd = stdout;
                     46:                        tempfile = "grap.temp";
                     47:                        unlink(tempfile);
                     48:                        fprintf(stderr, "%s\n", version);
                     49:                        break;
                     50:                case 'l':       /* turn off /usr/lib inclusion */
                     51:                        lib = 0;
                     52:                        break;
                     53:                }
                     54:                argc--;
                     55:                argv++;
                     56:        }
                     57:        setdefaults();
                     58:        if (!dbg)
                     59:                mktemp(tempfile);
                     60:        curfile = infile;
                     61:        if (argc <= 1) {
                     62:                curfile->fin = stdin;
                     63:                curfile->fname = tostring("-");
                     64:                pushsrc(File, curfile->fname);
                     65:                getdata();
                     66:        } else
                     67:                while (argc-- > 1) {
                     68:                        if ((curfile->fin = fopen(*++argv, "r")) == NULL) {
                     69:                                fprintf(stderr, "grap: can't open %s\n", *argv);
                     70:                                onintr();
                     71:                        }
                     72:                        curfile->fname = tostring(*argv);
                     73:                        pushsrc(File, curfile->fname);
                     74:                        getdata();
                     75:                        fclose(curfile->fin);
                     76:                        free(curfile->fname);
                     77:                }
                     78:        if (!dbg)
                     79:                unlink(tempfile);
                     80:        exit(0);
                     81: }
                     82: 
                     83: onintr()
                     84: {
                     85:        if (!dbg)
                     86:                unlink(tempfile);
                     87:        exit(1);
                     88: }
                     89: 
                     90: fpecatch()
                     91: {
                     92:        ERROR "floating point exception" WARNING;
                     93:        onintr();
                     94: }
                     95: 
                     96: char *grow(ptr, name, num, size)       /* make array bigger */
                     97:        char *ptr, *name;
                     98:        int num, size;
                     99: {
                    100:        char *p;
                    101: 
                    102:        if (ptr == NULL)
                    103:                p = malloc(num * size);
                    104:        else
                    105:                p = realloc(ptr, num * size);
                    106:        if (p == NULL)
                    107:                ERROR "can't grow %s to %d", name, num * size FATAL;
                    108:        return p;
                    109: }
                    110: 
                    111: static struct {
                    112:        char    *name;
                    113:        double  val;
                    114: } defaults[] ={
                    115:        "frameht", FRAMEHT,
                    116:        "framewid", FRAMEWID,
                    117:        "ticklen", TICKLEN,
                    118:        "slop", SLOP,
                    119:        NULL, 0
                    120: };
                    121: 
                    122: setdefaults()  /* set default sizes for variables */
                    123: {
                    124:        int i;
                    125:        Obj *p;
                    126: 
                    127:        for (i = 0; defaults[i].name != NULL; i++) {
                    128:                p = lookup(defaults[i].name, 1);
                    129:                setvar(p, defaults[i].val);
                    130:        }
                    131: }
                    132: 
                    133: getdata()              /* read input */
                    134: {
                    135:        register FILE *fin;
                    136:        char buf[1000], buf1[100];
                    137:        int ln;
                    138: 
                    139:        fin = curfile->fin;
                    140:        curfile->lineno = 0;
                    141:        printf(".lf 1 %s\n", curfile->fname);
                    142:        while (fgets(buf, sizeof buf, fin) != NULL) {
                    143:                curfile->lineno++;
                    144:                if (*buf == '.' && *(buf+1) == 'G' && *(buf+2) == '1') {
                    145:                        setup();
                    146:                        fprintf(stdout, ".PS%s", &buf[3]);      /* maps .G1 [w] to .PS w */
                    147:                        printf(".lf %d\n", curfile->lineno+1);
                    148:                        yyparse();
                    149:                        fprintf(stdout, ".PE\n");
                    150:                        printf(".lf %d\n", curfile->lineno+1);
                    151:                        fflush(stdout);
                    152:                } else if (buf[0] == '.' && buf[1] == 'l' && buf[2] == 'f') {
                    153:                        if (sscanf(buf+3, "%d %s", &ln, buf1) == 2) {
                    154:                                free(curfile->fname);
                    155:                                printf(".lf %d %s\n", curfile->lineno = ln, curfile->fname = tostring(buf1));
                    156:                        } else
                    157:                                printf(".lf %d\n", curfile->lineno = ln);
                    158:                } else
                    159:                        fputs(buf, stdout);
                    160:        }
                    161: }

unix.superglobalmegacorp.com

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