|
|
1.1 ! root 1: #include "ideal.h" ! 2: #include "y.tab.h" ! 3: ! 4: boolean dbg = FALSE; ! 5: int when_bug = 0; ! 6: char *filename; ! 7: int lineno = 0; ! 8: char libstr[100]; ! 9: boolean radflag = FALSE; ! 10: #ifdef DUMPVARS ! 11: boolean dumpvars = FALSE; ! 12: #endif ! 13: ! 14: BOXPTR boxlist = NULL; ! 15: ! 16: main(argc, argv) ! 17: int argc; ! 18: char *argv[]; ! 19: { ! 20: bug_off; ! 21: while (argc > 1 && argv[1][0] == '-') { ! 22: switch (argv[1][1]) { ! 23: case 'd': ! 24: when_bug = argv[1][2]?atoi(&argv[1][2]):~0; ! 25: break; ! 26: case 'l': ! 27: idinclude (&argv[1][2], LIBFIL); ! 28: while (yyparse()); ! 29: break; ! 30: case 'r': ! 31: radflag = TRUE; ! 32: break; ! 33: case 'p': ! 34: case '4': ! 35: case 'n': ! 36: break; ! 37: #ifdef DUMPVARS ! 38: case 'v': ! 39: dumpvars = TRUE; ! 40: break; ! 41: #endif ! 42: default: ! 43: fprintf(stderr, "ideal: unknown flag %c\n", argv[1][1]); ! 44: break; ! 45: } ! 46: argc--; ! 47: argv++; ! 48: } ! 49: if (argc < 2) { ! 50: filename = "-"; ! 51: lineno = 0; ! 52: filepush (stdin); ! 53: while (yyparse ()); ! 54: } else ! 55: while (argc-- > 1) { ! 56: filename = *argv; ! 57: lineno = 0; ! 58: idinclude (*++argv, CHATTY); ! 59: while (yyparse ()); ! 60: } ! 61: exit(0); ! 62: } ! 63: ! 64: interpret() ! 65: { ! 66: PUTNODE dummyroot; ! 67: if (when_bug & 01) bug_on; ! 68: else bug_off; ! 69: dummyroot.name = lookup("main"); ! 70: dummyroot.parm = boxgen (lookup("main"), (STMTPTR) NULL); ! 71: /* if boxlist includes main, execute it */ ! 72: if (boxlist && findbox(lookup("main"),TRUE)->stmtlist) { ! 73: NOADPTR noadtree; ! 74: bug_off; ! 75: /* make room for all variables */ ! 76: noadtree = buildnoadtree (&dummyroot); ! 77: /* solve all equations */ ! 78: eqneval (noadtree); ! 79: nl_eval (); ! 80: depvarkill (); ! 81: #ifdef DUMPVARS ! 82: if (dumpvars) ! 83: dumpnoad (noadtree); ! 84: #endif ! 85: /* make a list of segments in the picture */ ! 86: noadtree->linelist = build (noadtree, noadtree->linelist); ! 87: /* draw the thing */ ! 88: act (noadtree->linelist); ! 89: /* free the thing, but save definitions */ ! 90: noadfree (noadtree); ! 91: fflush (stdout); ! 92: forget (lookup ("main")); ! 93: } ! 94: } ! 95: ! 96: idinclude (filnam, mode) ! 97: char *filnam; ! 98: int mode; ! 99: { ! 100: FILE *nufile; ! 101: char *lib, *getenv(); ! 102: dprintf "opening file %s\n", filnam); ! 103: printf (".lf 1 %s\n", filnam); ! 104: if (mode == CHATTY) ! 105: nufile = fopen (filnam, "r"); ! 106: else if (mode == LIBFIL) { ! 107: if (!(lib = getenv("LIBDIR"))) ! 108: lib = "/usr/lib/ideal/lib/"; ! 109: strcpy (libstr, lib); ! 110: strcat (&libstr[0],filnam); ! 111: filnam = libstr; ! 112: nufile = fopen (filnam, "r"); ! 113: } ! 114: filename = filnam; ! 115: if (!nufile) { ! 116: fprintf (stderr, "ideal: can't open file %s\n", filnam); ! 117: exit (1); ! 118: } else { ! 119: filepush (nufile); ! 120: } ! 121: } ! 122: ! 123: act (the_picture) ! 124: LINEPTR the_picture; ! 125: { ! 126: LINEPTR lineseg; ! 127: double bounds[4]; ! 128: #define maxx bounds[MAXX] ! 129: #define maxy bounds[MAXY] ! 130: #define minx bounds[MINX] ! 131: #define miny bounds[MINY] ! 132: maxx = -10000.0; ! 133: maxy = -10000.0; ! 134: minx = 10000.0; ! 135: miny = 10000.0; ! 136: for (lineseg = the_picture; lineseg; lineseg = lineseg->next) { ! 137: switch (lineseg->kind) { ! 138: case LINE: ! 139: bbline (lineseg, bounds); ! 140: break; ! 141: case CIRCLE: ! 142: bbcirc ((CIRCPTR) lineseg, bounds); ! 143: break; ! 144: case ARC: ! 145: bbarc ((ARCPTR) lineseg, bounds); ! 146: break; ! 147: case STRING: ! 148: bbstring ((TEXTPTR) lineseg, bounds); ! 149: break; ! 150: case SPLINE: ! 151: break; ! 152: default: ! 153: fprintf (stderr, "ideal: act: can't happen\n"); ! 154: break; ! 155: } ! 156: } ! 157: if (the_picture) { ! 158: boundscall (bounds); ! 159: } ! 160: for (lineseg = the_picture; lineseg; lineseg = lineseg->next) { ! 161: switch (lineseg->kind) { ! 162: case LINE: ! 163: linecall (lineseg); ! 164: break; ! 165: case CIRCLE: ! 166: circcall ((CIRCPTR) lineseg); ! 167: break; ! 168: case ARC: ! 169: arccall ((ARCPTR) lineseg); ! 170: break; ! 171: case STRING: ! 172: textcall ((TEXTPTR) lineseg); ! 173: break; ! 174: case SPLINE: ! 175: splcall (((SPLPTR) lineseg)->knotlist); ! 176: break; ! 177: default: ! 178: fprintf (stderr, "ideal: act: can't happen\n"); ! 179: break; ! 180: } ! 181: } ! 182: } ! 183: ! 184: #ifdef DUMPVARS ! 185: ! 186: /* print the variable values in the first level blocks of n */ ! 187: dumpnoad(n) ! 188: NOADPTR n; ! 189: { ! 190: VARPTR vp, vpi; ! 191: NOADPTR np; ! 192: char *bname; ! 193: fprintf(stderr,"DUMP\n"); ! 194: for (np=n->son; np; np=np->brother) { ! 195: bname=idprint(np->defnode->name); ! 196: for (vp=np->boxvarlist ; vp ; ) { ! 197: if(vp->re_name) { ! 198: fprintf(stderr,"%s.%s ", bname, ! 199: idprint(THENAME(vp))); ! 200: depprint(vp->deplist); ! 201: fprintf(stderr," "); ! 202: /* next should be imag part */ ! 203: vpi=vp->next; ! 204: if(!vpi || THENAME(vpi)!=THENAME(vp)) ! 205: exit(1); ! 206: depprint(vpi->deplist); ! 207: fprintf(stderr,"\n"); ! 208: vp=vpi; ! 209: } ! 210: vp = vp->next; ! 211: } ! 212: } ! 213: } ! 214: ! 215: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.