|
|
1.1 ! root 1: # include <stdio.h> ! 2: # include "constants.h" ! 3: # include "globals.h" ! 4: # include <sccs.h> ! 5: ! 6: SCCSID(@(#)main.c 7.4 5/31/83) ! 7: ! 8: ! 9: /* ! 10: ** MAIN.C -- Start up routines ! 11: ** ! 12: ** Usage: ! 13: ** equel {-d | -v | -c | -y | -f | -f<integer> | <name>.q} ! 14: ** ! 15: ** Files: ! 16: ** standard output -- for diagnostics ! 17: ** <name>.q -- read ! 18: ** <name>.c -- created and written ! 19: ** any file appearing in a "#include" with a name ! 20: ** <name>.q.h -- read ! 21: ** <name>.c.h -- created and written ! 22: ** ! 23: ** Flags: ! 24: ** possible arguments are: ! 25: ** -d -- enables run-time errors to have the file name ! 26: ** and line number where they occurred reported ! 27: ** Defaults to off. ! 28: ** -f -- specify the number of characters to fill ! 29: ** an output line on quel commands ! 30: ** as being very high (to get C code on the ! 31: ** right line invariably). ! 32: ** -f<integer> -- fill output lines to integer chars ! 33: ** (0 is like -f alone) ! 34: ** Defaults to FILLCNT. ! 35: ** -y -- have the parser print debugging info ! 36: ** Defaults to off. ! 37: ** -v -- (verbose) have the lexical analizer ! 38: ** print the kind of token it sees. ! 39: ** (only available if xDEBUG is defined) ! 40: ** Defaults to off. ! 41: ** -c -- have every character read or backed up ! 42: ** echoed (only if xDEBUG is defined) ! 43: ** Defaults to off. ! 44: ** -r -- reset all previous flags to default ! 45: ** <name>.q -- name of a file to be equel'ed ! 46: ** ! 47: ** Compilation Flags: ! 48: ** xDEBUG -- enables debugging flags -v and -c ! 49: ** ! 50: ** Compilation Instructions: ! 51: ** to setup equel do : ! 52: ** setup equel; setup libq ! 53: */ ! 54: /* ! 55: ** MAIN -- invokes the pre-compiler on all the argument files ! 56: ** ! 57: ** Parameters: ! 58: ** argc ! 59: ** argv ! 60: ** ! 61: ** Returns: ! 62: ** none ! 63: */ ! 64: int Exit_val = 0; /* Value to exit with */ ! 65: ! 66: main(argc, argv) ! 67: int argc; ! 68: char **argv; ! 69: { ! 70: extern char **argproc(); ! 71: ! 72: ! 73: argv [argc] = 0; ! 74: ! 75: for (argv++; *argv; ) ! 76: { ! 77: argv = argproc(argv); ! 78: if (!Arg_error) ! 79: equel(Input_file_name); ! 80: } ! 81: exit(Exit_val); ! 82: } ! 83: ! 84: /* ! 85: ** ARGPROC -- process arguments on the command line ! 86: ** Arguments have effect on all the files following them ! 87: ** until a "-r" or an argument cancelling the first ! 88: ** ! 89: ** Also performs global initializations. ! 90: ** ! 91: ** Parameters: ! 92: ** argv -- a 0 terminated string vector with the ! 93: ** command lines components. ! 94: ** ! 95: ** Returns: ! 96: ** a new argv with all the leading arguments taken out ! 97: ** ! 98: ** Side Effects: ! 99: ** sets certain variables for certain flags ! 100: ** -d -- Rtdb ! 101: ** -c -- Chardebug ! 102: ** -v -- Lex_debug ! 103: ** -y -- yydebug ! 104: ** -f -- Fillcnt ! 105: ** -r -- resets all variables to default values ! 106: ** Sets Arg_error on an argument error that should abort ! 107: ** the pre-processing of the file read. ! 108: */ ! 109: ! 110: char **argproc(argv) ! 111: char **argv; ! 112: { ! 113: ! 114: /* initializations for a new file */ ! 115: ! 116: C_code_flg = Pre_proc_flg = 0; ! 117: yyline = Newline = Lineout = 1; ! 118: Block_level = Indir_level = In_string = Fillmode = 0; ! 119: Charcnt = Lastc = In_quote = 0; ! 120: Arg_error = 0; ! 121: ! 122: /* free C variable trees, and symbol space */ ! 123: freecvar(&C_locals); ! 124: freecvar(&F_locals); ! 125: freecvar(&C_globals); ! 126: freecvar(&F_globals); ! 127: ! 128: symspfree(); ! 129: ! 130: for ( ; *argv && **argv == '-'; argv++) ! 131: { ! 132: switch (*++*argv) ! 133: { ! 134: ! 135: # ifdef xDEBUG ! 136: case 'v' : ! 137: Lex_debug = 'v'; ! 138: break; ! 139: ! 140: case 'c' : ! 141: Chardebug = 'c'; ! 142: break; ! 143: # endif ! 144: ! 145: case 'y' : ! 146: yydebug = 1; ! 147: break; ! 148: ! 149: case 'd' : ! 150: Rtdb = 1; ! 151: break; ! 152: ! 153: case 'f' : /* line fill */ ! 154: Fillcnt = atoi(++*argv); ! 155: if (!Fillcnt) ! 156: /* make SURE that C_CODE is put ! 157: * on line that it was typed in on ! 158: */ ! 159: Fillcnt = 30000; ! 160: break; ! 161: ! 162: case 'r' : /* reset all flags to ! 163: * their default values. ! 164: */ ! 165: yydebug = Rtdb = 0; ! 166: Fillcnt = FILLCNT; ! 167: # ifdef xDEBUG ! 168: Lex_debug = Chardebug = 0; ! 169: # endif ! 170: break; ! 171: ! 172: default : ! 173: printf("equel: invalid option: '-%c'\n", **argv); ! 174: } ! 175: } ! 176: if (*argv) ! 177: Input_file_name = *argv++; ! 178: else ! 179: { ! 180: printf("equel: missing file name after arguments\n"); ! 181: Arg_error++; ! 182: } ! 183: return (argv); ! 184: } ! 185: ! 186: ! 187: /* ! 188: ** EQUEL -- invokes the precompiler for a non-included file ! 189: ** ! 190: ** Parameters: ! 191: ** filename -- the name of the file to pre-compile ! 192: ** ! 193: ** Returns: ! 194: ** none ! 195: ** ! 196: ** Side Effects: ! 197: ** performs the preprocessing on <filename> ! 198: */ ! 199: ! 200: equel(filename) ! 201: char *filename; ! 202: { ! 203: char o_file [100]; ! 204: register l; ! 205: ! 206: l = length(filename); ! 207: if (l > sizeof o_file - 1) ! 208: { ! 209: printf("equel: filename \"%s\" too long\n", ! 210: filename); ! 211: return; ! 212: } ! 213: if (!sequal(".q", &filename [l - 2])) ! 214: { ! 215: printf("equel: EQUEL source files must end with .q\n"); ! 216: return; ! 217: } ! 218: bmove(filename, o_file, l - 2); ! 219: bmove(".c", &o_file[l - 2], 3); ! 220: Input_file_name = filename; ! 221: In_file = Out_file = NULL; ! 222: ! 223: ! 224: if ((In_file = fopen(filename, "r")) == NULL) ! 225: cant("read", filename); ! 226: else if ((Out_file = fopen(o_file, "w")) == NULL) ! 227: cant("write", o_file); ! 228: else if (!setexit()) ! 229: yyparse(); ! 230: ! 231: /* if a reset(III) is done while processing ! 232: * an included file, then this closes all ! 233: * files skipped. ! 234: */ ! 235: while (restoref()) ! 236: ; ! 237: ! 238: if (Out_file != NULL) ! 239: fclose(Out_file); ! 240: if (In_file != NULL) ! 241: fclose(In_file); ! 242: In_file = Out_file = NULL; ! 243: if (Block_level != 0) ! 244: yysemerr("unclosed block", 0); ! 245: Input_file_name = 0; ! 246: } ! 247: ! 248: /* ! 249: ** CANT -- print error message on failure to open a file ! 250: ** ! 251: ** Parameters: ! 252: ** operation -- "read" or "write", according to what was ! 253: ** attempted ! 254: ** filename -- the name of the file on which attempted ! 255: ** ! 256: ** Returns: ! 257: ** none ! 258: ** ! 259: ** Side Effects: ! 260: ** Prints error message on standard output ! 261: */ ! 262: ! 263: cant(operation, filename) ! 264: char *operation; ! 265: char *filename; ! 266: { ! 267: extern char *sys_errlist[]; ! 268: extern int sys_nerr; ! 269: extern int errno; ! 270: char ebuf[BUFSIZ]; ! 271: ! 272: if (errno > 0 && errno <= sys_nerr) ! 273: sprintf(ebuf, "Can't %s \"%s\": %s", operation, filename, ! 274: sys_errlist[errno]); ! 275: else ! 276: sprintf(ebuf, "Can't %s \"%s\": unknown error", operation, ! 277: filename); ! 278: yysemerr(ebuf, 0); ! 279: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.