1: #ifndef lint
   2: static char sccsid[] = "@(#)main.c	4.4 (Berkeley) 12/8/84";
   3: #endif
   4: 
   5: #include "stdio.h"
   6: #include "ctype.h"
   7: #include "awk.def"
   8: #include "awk.h"
   9: #define TOLOWER(c)  (isupper(c) ? tolower(c) : c) /* ugh!!! */
  10: 
  11: int dbg = 0;
  12: int ldbg    = 0;
  13: int svflg   = 0;
  14: int rstflg  = 0;
  15: int svargc;
  16: char    **svargv, **xargv;
  17: extern FILE *yyin;  /* lex input file */
  18: char    *lexprog;   /* points to program argument if it exists */
  19: extern  errorflag;  /* non-zero if any syntax errors; set by yyerror */
  20: 
  21: int filefd, symnum, ansfd;
  22: char *filelist;
  23: extern int maxsym, errno;
  24: main(argc, argv) int argc; char *argv[]; {
  25:     if (argc == 1)
  26:         error(FATAL, "Usage: awk [-f source | 'cmds'] [files]");
  27:     syminit();
  28:     while (argc > 1) {
  29:         argc--;
  30:         argv++;
  31:         /* this nonsense is because gcos argument handling */
  32:         /* folds -F into -f.  accordingly, one checks the next
  33: 		/* character after f to see if it's -f file or -Fx.
  34: 		*/
  35:         if (argv[0][0] == '-' && TOLOWER(argv[0][1]) == 'f' && argv[0][2] == '\0') {
  36:             yyin = fopen(argv[1], "r");
  37:             if (yyin == NULL)
  38:                 error(FATAL, "can't open %s", argv[1]);
  39:             argc--;
  40:             argv++;
  41:             break;
  42:         } else if (argv[0][0] == '-' && TOLOWER(argv[0][1]) == 'f') {   /* set field sep */
  43:             if (argv[0][2] == 't')  /* special case for tab */
  44:                 **FS = '\t';
  45:             else
  46:                 **FS = argv[0][2];
  47:             continue;
  48:         } else if (argv[0][0] != '-') {
  49:             dprintf("cmds=|%s|\n", argv[0], NULL, NULL);
  50:             yyin = NULL;
  51:             lexprog = argv[0];
  52:             argv[0] = argv[-1]; /* need this space */
  53:             break;
  54:         } else if (strcmp("-d", argv[0])==0) {
  55:             dbg = 1;
  56:         }
  57:         else if (strcmp("-l", argv[0])==0) {
  58:             ldbg = 1;
  59:         }
  60:         else if(strcmp("-S", argv[0]) == 0) {
  61:             svflg = 1;
  62:         }
  63:         else if(strncmp("-R", argv[0], 2) == 0) {
  64:             if(thaw(argv[0] + 2) == 0)
  65:                 rstflg = 1;
  66:             else {
  67:                 fprintf(stderr, "not restored\n");
  68:                 exit(1);
  69:             }
  70:         }
  71:     }
  72:     if (argc <= 1) {
  73:         argv[0][0] = '-';
  74:         argv[0][1] = '\0';
  75:         argc++;
  76:         argv--;
  77:     }
  78:     svargc = --argc;
  79:     svargv = ++argv;
  80:     dprintf("svargc=%d svargv[0]=%s\n", svargc, svargv[0], NULL);
  81:     *FILENAME = *svargv;    /* initial file name */
  82:     if(rstflg == 0)
  83:         yyparse();
  84:     dprintf("errorflag=%d\n", errorflag, NULL, NULL);
  85:     if (errorflag)
  86:         exit(errorflag);
  87:     if(svflg) {
  88:         svflg = 0;
  89:         if(freeze("awk.out") != 0)
  90:             fprintf(stderr, "not saved\n");
  91:         exit(0);
  92:     }
  93:     run();
  94:     exit(errorflag);
  95: }
  96: 
  97: yywrap()
  98: {
  99:     return(1);
 100: }

Defined functions

main defined in line 24; never used
yywrap defined in line 97; never used

Defined variables

ansfd defined in line 21; never used
dbg defined in line 11; used 4 times
filefd defined in line 21; never used
filelist defined in line 22; never used
ldbg defined in line 12; used 1 times
  • in line 58
lexprog defined in line 18; used 1 times
  • in line 51
rstflg defined in line 14; used 2 times
sccsid defined in line 2; never used
svargc defined in line 15; used 2 times
svargv defined in line 16; used 3 times
svflg defined in line 13; used 3 times
symnum defined in line 21; never used
xargv defined in line 16; never used

Defined macros

TOLOWER defined in line 9; used 2 times
Last modified: 1987-02-08
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1289
Valid CSS Valid XHTML 1.0 Strict