|
|
1.1 ! root 1: /* ! 2: * Main program that controls the translation of Icon programs. ! 3: */ ! 4: ! 5: #include "itran.h" ! 6: #include "sym.h" ! 7: #include "tree.h" ! 8: #include "../h/version.h" ! 9: #include "token.h" ! 10: #include "tstats.h" ! 11: ! 12: #ifdef TranStats ! 13: /* int TokCount[TokSize]; */ ! 14: #endif TranStats ! 15: ! 16: ! 17: ! 18: #define MaxFiles 64 /* maximum number of file names */ ! 19: #define MaxName 40 /* maximum length of file name */ ! 20: ! 21: int fatalerrs = 0; /* total number of fatal errors */ ! 22: int warnings = 0; /* total number of warnings */ ! 23: int nocode = 0; /* non-zero to suppress code generation */ ! 24: int inline = 1; /* current input line number */ ! 25: int incol = 0; /* current input column number */ ! 26: int peekc = 0; /* one-character look ahead */ ! 27: int implicit = LOCAL; /* implicit scope for undeclared identifiers */ ! 28: int silence = 0; /* don't be silent (default) */ ! 29: int trace = 0; /* initial setting of &trace */ ! 30: ! 31: FILE *infile; /* current input file */ ! 32: FILE *codefile; /* current ucode output file */ ! 33: FILE *globfile; /* current global table output file */ ! 34: char codename[MaxName]; /* name of ucode output file */ ! 35: char globname[MaxName]; /* name of global table output file */ ! 36: ! 37: char *filelist[MaxFiles]; /* list of input file names */ ! 38: char **filep; /* pointer to current input file name */ ! 39: ! 40: main(argc,argv) ! 41: int argc; ! 42: char **argv; ! 43: { ! 44: int aval; ! 45: int mflag = 0; /* m4 preprocessed */ ! 46: char *progname; ! 47: static char mname[80]; /* m4 command string */ ! 48: register char **fp; /* indexes filelist while scanning args */ ! 49: char *maknam(); ! 50: #ifndef MSDOS ! 51: extern FILE *popen(); ! 52: #endif MSDOS ! 53: ! 54: progname = "itran"; ! 55: filep = fp = filelist; ! 56: while (--argc) { ! 57: if (**++argv == '-') { /* argument starts with a '-' */ ! 58: switch ((*argv)[1]) { ! 59: case '\0': /* read standard input */ ! 60: *fp++ = *argv; ! 61: continue; ! 62: case 'm': /* process with m4 */ ! 63: mflag++; ! 64: continue; ! 65: case 'u': /* tell ilink to note undeclared identifiers*/ ! 66: implicit = 0; ! 67: continue; ! 68: case 't': /* tell ilink to turn on tracing */ ! 69: trace++; ! 70: continue; ! 71: case 's': /* don't produce informative messages */ ! 72: silence++; ! 73: continue; ! 74: case 'D': /* debug flag for ilink, ignored by itran */ ! 75: continue; ! 76: #ifdef VMS ! 77: case 'r': ! 78: #endif VMS ! 79: case 'S': ! 80: if ((*argv)[3] == 'h') { /* change hash table size */ ! 81: aval = atoi(&(*argv)[4]); ! 82: if (aval <= 0) ! 83: goto badarg; ! 84: switch ((*argv)[2]) { ! 85: case 'i': ihsize = aval; continue; ! 86: case 'g': ghsize = aval; continue; ! 87: case 'c': chsize = aval; continue; ! 88: case 'l': lhsize = aval; continue; ! 89: case 'f': continue; ! 90: } ! 91: } ! 92: else { /* change symbol table size */ ! 93: aval = atoi(&(*argv)[3]); ! 94: if (aval <= 0) ! 95: goto badarg; ! 96: switch ((*argv)[2]) { ! 97: case 'c': csize = aval; continue; ! 98: case 'i': isize = aval; continue; ! 99: case 'g': gsize = aval; continue; ! 100: case 'l': lsize = aval; continue; ! 101: case 's': ssize = aval; continue; ! 102: case 't': tsize = aval; continue; ! 103: case 'f': continue; ! 104: case 'r': continue; ! 105: case 'L': continue; ! 106: case 'C': continue; ! 107: } ! 108: } ! 109: default: ! 110: badarg: ! 111: fprintf(stderr, "bad argument: %s\n", *argv); ! 112: continue; ! 113: } ! 114: } ! 115: else /* argument doesn't start with a '-', assume it's a file */ ! 116: *fp++ = *argv; ! 117: } ! 118: *fp++ = 0; /* terminate list of files with a NULL */ ! 119: /* ! 120: * Process each input file in turn. If m4 processing is to be done (mflag ! 121: * is set), a pipe is opened to m4 with the current file name, otherwise, ! 122: * the input file is opened. infile is the file pointer for the current ! 123: * input file and filep is the name of the file. ! 124: */ ! 125: for ( ; *filep; filep++) { ! 126: inline = 1; ! 127: if (!mflag) { ! 128: if (*filep[0] == '-') ! 129: infile = stdin; ! 130: else ! 131: #ifndef VMS ! 132: #ifndef MSDOS ! 133: infile = fopen(*filep, "r"); ! 134: #else MSDOS ! 135: /* ! 136: * Under MSDOS, if no extension provided then append ".icn". ! 137: */ ! 138: { ! 139: char *cp, lastch = 0; ! 140: ! 141: cp = *filep; ! 142: while( *cp ) ! 143: { ! 144: if ( *cp == '.' || ! 145: *cp == '\\' || ! 146: *cp == '/' || ! 147: *cp == ':' ) ! 148: lastch = *cp; ! 149: cp++; ! 150: } ! 151: if ( lastch != '.' ) ! 152: { ! 153: strcpy( mname, *filep ); ! 154: strcat( mname, ".icn" ); ! 155: *filep = mname; ! 156: } ! 157: infile = fopen( *filep, "r" ); ! 158: } ! 159: #endif MSDOS ! 160: #else VMS ! 161: /* ! 162: * Under VMS, if no extension provided then append ".icn". ! 163: */ ! 164: { ! 165: char *cp, lastch = 0; ! 166: ! 167: cp = *filep; ! 168: while( *cp ) ! 169: { ! 170: if ( *cp == '.' || *cp == ']' || *cp == ':' ) ! 171: lastch = *cp; ! 172: cp++; ! 173: } ! 174: if ( lastch != '.' ) ! 175: { ! 176: strcpy( mname, *filep ); ! 177: strcat( mname, ".icn" ); ! 178: *filep = mname; ! 179: } ! 180: infile = fopen( *filep, "r" ); ! 181: } ! 182: #endif VMS ! 183: } ! 184: else { ! 185: #ifndef VMS ! 186: #ifndef MSDOS ! 187: strcpy(mname, "m4 "); ! 188: strcat(mname, *filep); ! 189: infile = popen(mname, "r"); ! 190: #else MSDOS ! 191: fprintf(stderr, "-m option not supported\n"); ! 192: exit(ErrorExit); ! 193: #endif MSDOS ! 194: #else VMS ! 195: fprintf(stderr, "-m option not supported\n"); ! 196: exit(ErrorExit); ! 197: #endif VMS ! 198: } ! 199: if (*filep[0] == '-') ! 200: *filep = "stdin"; ! 201: if (infile == NULL) { ! 202: fprintf(stderr, "%s: cannot open %s\n", progname, *filep); ! 203: fatalerrs++; ! 204: continue; ! 205: } ! 206: ! 207: if (!silence) ! 208: fprintf(stderr, "%s:\n", *filep); ! 209: ! 210: /* ! 211: * Form names for the .u1 and .u2 files and open them. ! 212: */ ! 213: maknam(codename, *filep, ".u1"); ! 214: maknam(globname, *filep, ".u2"); ! 215: codefile = fopen(codename, "w"); ! 216: if (codefile == NULL) { ! 217: fprintf(stderr, "%s: cannot create %s\n", progname, codename); ! 218: fatalerrs++; ! 219: continue; ! 220: } ! 221: globfile = fopen(globname, "w"); ! 222: if (globfile == NULL) { ! 223: fprintf(stderr, "%s: cannot create %s\n", progname, globname); ! 224: fatalerrs++; ! 225: continue; ! 226: } ! 227: ! 228: fprintf(globfile,"version\t%s\n",UVersion); /* ucode serial number */ ! 229: meminit(); /* Initialize data structures */ ! 230: ! 231: yyparse(); /* Parse the input */ ! 232: ! 233: /* ! 234: * Close the input file and the .u1 and .u2 files. ! 235: */ ! 236: if (!mflag) ! 237: fclose(infile); ! 238: #ifndef VMS ! 239: #ifndef MSDOS ! 240: else { ! 241: if (pclose(infile) != 0) { ! 242: fprintf(stderr, "%s: m4 terminated abnormally\n", progname); ! 243: fatalerrs++; ! 244: } ! 245: } ! 246: #endif MSDOS ! 247: #endif VMS ! 248: fclose(codefile); ! 249: fclose(globfile); ! 250: } ! 251: ! 252: /* ! 253: * Produce information about errors and warnings and be correct about it. ! 254: */ ! 255: if (fatalerrs == 1) ! 256: fprintf(stderr, "1 error; "); ! 257: else if (fatalerrs > 1) ! 258: fprintf(stderr, "%d errors; ", fatalerrs); ! 259: else if (!silence) ! 260: fprintf(stderr, "No errors; "); ! 261: if (warnings == 1) ! 262: fprintf(stderr, "1 warning\n"); ! 263: else if (warnings > 1) ! 264: fprintf(stderr, "%d warnings\n", warnings); ! 265: else if (!silence) ! 266: fprintf(stderr, "no warnings\n"); ! 267: else if (fatalerrs > 0) ! 268: fprintf(stderr, "\n"); ! 269: if (fatalerrs > 0) ! 270: exit(ErrorExit); ! 271: #ifdef TranStats ! 272: tokdump(); ! 273: #endif TranStats ! 274: exit(NormalExit); ! 275: } ! 276: ! 277: /* ! 278: * maknam - makes a file name from prefix and suffix. ! 279: * ! 280: * Uses only the last file specification if name is a path, ! 281: * replaces suffix of name with suffix argument. ! 282: */ ! 283: ! 284: char *maknam(dest, name, suffix) ! 285: char *dest, *name, *suffix; ! 286: { ! 287: register char *d, *pre, *suf; ! 288: char *mark; ! 289: ! 290: d = dest; ! 291: pre = name; ! 292: suf = suffix; ! 293: mark = pre; ! 294: while (*pre) /* find last delimiter */ ! 295: #ifndef VMS ! 296: #ifndef MSDOS ! 297: if (*pre++ == '/') ! 298: mark = pre; ! 299: #else MSDOS ! 300: if (*pre == ':' || *pre == '/' || *pre == '\\') ! 301: mark = ++pre; ! 302: else ! 303: ++pre; ! 304: #endif MSDOS ! 305: #else VMS ! 306: if (*pre == ']' || *pre == ':' ) ! 307: mark = ++pre; ! 308: else ! 309: ++pre; ! 310: #endif VMS ! 311: pre = mark; ! 312: mark = 0; ! 313: while (*d = *pre++) /* copy from last slash into dest */ ! 314: if (*d++ == '.') /* look for last dot, too */ ! 315: mark = d - 1; ! 316: if (mark) /* if no dot, just append suffix */ ! 317: d = mark; ! 318: while (*d++ = *suf++) ; /* copy suffix into dest */ ! 319: return dest; ! 320: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.