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

Defined functions

argproc defined in line 139; used 2 times
equel defined in line 240; used 1 times
  • in line 97
main defined in line 82; never used

Defined variables

Env defined in line 8; used 1 times
Last modified: 1995-02-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3587
Valid CSS Valid XHTML 1.0 Strict