1: # include   <stdio.h>
   2: # include   "constants.h"
   3: # include   "globals.h"
   4: # include   <setjmp.h>
   5: # include   <sccs.h>
   6: 
   7: SCCSID(@(#)main.c	8.1	12/31/84)
   8: 
   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: **	Compilation Flags:
  49: **		xDEBUG -- enables debugging flags -v and -c
  50: **
  51: **	Compilation Instructions:
  52: **		to setup equel do :
  53: **			setup equel; setup libq
  54: */
  55: /*
  56: **  MAIN --  invokes the pre-compiler on all the argument files
  57: **
  58: **	Parameters:
  59: **		argc
  60: **		argv
  61: **
  62: **	Returns:
  63: **		none
  64: */
  65: int     Exit_val = 0;           /* Value to exit with */
  66: jmp_buf     Jmpbuf;             /* nonlocal goto label */
  67: 
  68: main(argc, argv)
  69: int argc;
  70: char    **argv;
  71: {
  72:     extern char **argproc();
  73: 
  74: 
  75:     argv [argc] = 0;
  76: 
  77:     for (argv++; *argv; )
  78:     {
  79:         argv = argproc(argv);
  80:         if (!Arg_error)
  81:             equel(Input_file_name);
  82:     }
  83:     exit(Exit_val);
  84: }
  85: 
  86: /*
  87: **  ARGPROC -- process arguments on the command line
  88: **	Arguments have effect on all the files following them
  89: **	until a "-r" or an argument cancelling the first
  90: **
  91: **	Also performs global initializations.
  92: **
  93: **	Parameters:
  94: **		argv -- a 0 terminated string vector with the
  95: **		        command lines components.
  96: **
  97: **	Returns:
  98: **		a new argv with all the leading arguments taken out
  99: **
 100: **	Side Effects:
 101: **		sets certain variables for certain flags
 102: **		  -d -- Rtdb
 103: **		  -c -- Chardebug
 104: **		  -v -- Lex_debug
 105: **		  -y -- yydebug
 106: **		  -f -- Fillcnt
 107: **		  -r -- resets all variables to default values
 108: **		Sets Arg_error on an argument error that should abort
 109: **		the pre-processing of the file read.
 110: */
 111: 
 112: char **argproc(argv)
 113: char    **argv;
 114: {
 115: 
 116:     /* initializations for a new file */
 117: 
 118:     C_code_flg = Pre_proc_flg = 0;
 119:     yyline = Newline = Lineout = 1;
 120:     Block_level = Indir_level = In_string = Fillmode = 0;
 121:     Charcnt = Lastc = In_quote = 0;
 122:     Arg_error = 0;
 123: 
 124:     /* free C variable trees, and symbol space */
 125:     freecvar(&C_locals);
 126:     freecvar(&F_locals);
 127:     freecvar(&C_globals);
 128:     freecvar(&F_globals);
 129: 
 130:     symspfree();
 131: 
 132:     for ( ; *argv && **argv == '-'; argv++)
 133:     {
 134:         switch (*++*argv)
 135:         {
 136: 
 137: #		  ifdef xDEBUG
 138:           case 'v' :
 139:             Lex_debug = 'v';
 140:             break;
 141: 
 142:           case 'c' :
 143:             Chardebug = 'c';
 144:             break;
 145: #		  endif
 146: 
 147:           case 'y' :
 148:             yydebug = 1;
 149:             break;
 150: 
 151:           case 'd' :
 152:             Rtdb = 1;
 153:             break;
 154: 
 155:           case 'f' :        /* line fill */
 156:             Fillcnt = atoi(++*argv);
 157:             if (!Fillcnt)
 158:                 /* make SURE that C_CODE is put
 159: 				 * on line that it was typed in on
 160: 				 */
 161:                 Fillcnt = 30000;
 162:             break;
 163: 
 164:           case 'r' :        /* reset all flags to
 165: 					 * their default values.
 166: 					 */
 167:             yydebug = Rtdb = 0;
 168:             Fillcnt = FILLCNT;
 169: #			ifdef xDEBUG
 170:             Lex_debug = Chardebug = 0;
 171: #			endif
 172:             break;
 173: 
 174:           default :
 175:             printf("equel: invalid option: '-%c'\n", **argv);
 176:         }
 177:     }
 178:     if (*argv)
 179:         Input_file_name = *argv++;
 180:     else
 181:     {
 182:         printf("equel:  missing file name after arguments\n");
 183:         Arg_error++;
 184:     }
 185:     return (argv);
 186: }
 187: 
 188: 
 189: /*
 190: **  EQUEL -- invokes the precompiler for a non-included file
 191: **
 192: **	Parameters:
 193: **		filename -- the name of the file to pre-compile
 194: **
 195: **	Returns:
 196: **		none
 197: **
 198: **	Side Effects:
 199: **		performs the preprocessing on <filename>
 200: */
 201: 
 202: equel(filename)
 203: char        *filename;
 204: {
 205:     char        o_file [100];
 206:     register    l;
 207: 
 208:     l = length(filename);
 209:     if (l > sizeof o_file - 1)
 210:     {
 211:         printf("equel: filename \"%s\" too long\n",
 212:         filename);
 213:         return;
 214:     }
 215:     if (!sequal(".q", &filename [l - 2]))
 216:     {
 217:         printf("equel: EQUEL source files must end with .q\n");
 218:         return;
 219:     }
 220:     bmove(filename, o_file, l - 2);
 221:     bmove(".c", &o_file[l - 2], 3);
 222:     Input_file_name = filename;
 223:     In_file = Out_file = NULL;
 224: 
 225: 
 226:     if ((In_file = fopen(filename, "r")) == NULL)
 227:         cant("read", filename);
 228:     else if ((Out_file = fopen(o_file, "w")) == NULL)
 229:         cant("write", o_file);
 230:     else if (!setjmp(Jmpbuf))
 231:         yyparse();
 232: 
 233:     /* if a reset(III) is done while processing
 234: 	 * an included file, then this closes all
 235: 	 * files skipped.
 236: 	 */
 237:     while (restoref())
 238:         ;
 239: 
 240:     if (Out_file != NULL)
 241:         fclose(Out_file);
 242:     if (In_file != NULL)
 243:         fclose(In_file);
 244:     In_file = Out_file = NULL;
 245:     if (Block_level != 0)
 246:         yysemerr("unclosed block", 0);
 247:     Input_file_name = 0;
 248: }
 249: 
 250: /*
 251: **  CANT -- print error message on failure to open a file
 252: **
 253: **	Parameters:
 254: **		operation -- "read" or "write", according to what was
 255: **			     attempted
 256: **		filename -- the name of the file on which attempted
 257: **
 258: **	Returns:
 259: **		none
 260: **
 261: **	Side Effects:
 262: **		Prints error message on standard output
 263: */
 264: 
 265: cant(operation, filename)
 266: char        *operation;
 267: char        *filename;
 268: {
 269:     extern  char *sys_errlist[];
 270:     extern  int sys_nerr;
 271:     extern  int errno;
 272:     char    ebuf[BUFSIZ];
 273: 
 274:     if (errno > 0 && errno <= sys_nerr)
 275:         sprintf(ebuf, "Can't %s \"%s\": %s", operation, filename,
 276:             sys_errlist[errno]);
 277:     else
 278:         sprintf(ebuf, "Can't %s \"%s\": unknown error", operation,
 279:             filename);
 280:     yysemerr(ebuf, 0);
 281: }

Defined functions

argproc defined in line 112; used 2 times
cant defined in line 265; used 4 times
equel defined in line 202; used 1 times
  • in line 81
main defined in line 68; never used

Defined variables

Exit_val defined in line 65; used 4 times
Jmpbuf defined in line 66; used 1 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 901
Valid CSS Valid XHTML 1.0 Strict