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