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