Annotation of researchv8dc/cmd/awk/main.c, revision 1.1.1.1

1.1       root        1: #define DEBUG
                      2: #include <stdio.h>
                      3: #include <ctype.h>
                      4: #include <signal.h>
                      5: #include "awk.h"
                      6: #include "y.tab.h"
                      7: 
                      8: int    dbg     = 0;
                      9: int    svargc;
                     10: char   **svargv;
                     11: char   *cmdname;       /* gets argv[0] for error messages */
                     12: extern FILE *yyin;     /* lex input file */
                     13: char   *lexprog;       /* points to program argument if it exists */
                     14: extern int errorflag;  /* non-zero if any syntax errors; set by yyerror */
                     15: int    compile_time = 1;       /* 0 when machine starts.  for error printing */
                     16: 
                     17: main(argc, argv)
                     18:        int argc;
                     19:        char *argv[];
                     20: {
                     21:        char *progfile = NULL, *progarg = NULL, *fs = NULL, *freezename = NULL;
                     22:        extern int fpecatch();
                     23: 
                     24:        cmdname = argv[0];
                     25:        if (argc == 1)
                     26:                error(FATAL, "Usage: %s [-f source | 'cmds'] [files]", cmdname);
                     27:        yyin = NULL;
                     28:        while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {
                     29:                switch (argv[1][1]) {
                     30:                case 'f':       /* next argument is program filename */
                     31:                        argc--;
                     32:                        argv++;
                     33:                        if ((yyin = fopen(argv[1], "r")) == NULL)
                     34:                                error(FATAL, "can't open file %s", argv[1]);
                     35:                        progfile = argv[1];
                     36:                        break;
                     37:                case 'F':       /* set field separator */
                     38:                        if (argv[1][2] != 0) {  /* arg is -Fsomething */
                     39:                                if (argv[1][2] == 't' && argv[1][3] == 0)       /* special case for tab */
                     40:                                        fs = "\t";
                     41:                                else
                     42:                                        fs = &argv[1][2];
                     43:                        } else {        /* it's -F (space) something */
                     44:                                argc--;
                     45:                                argv++;
                     46:                                if (argv[1][0] == 't' && argv[1][1] == 0)
                     47:                                        fs = "\t";
                     48:                                else
                     49:                                        fs = &argv[1][0];
                     50:                        }
                     51:                        break;
                     52:                case 'd':
                     53:                        dbg = 1;
                     54:                        break;
                     55:                }
                     56:                argc--;
                     57:                argv++;
                     58:        }
                     59:        if (yyin == NULL) {     /* no -f; first argument is program */
                     60:                dprintf("program = |%s|\n", argv[1]);
                     61:                progarg = lexprog = argv[1];
                     62:                argc--;
                     63:                argv++;
                     64:        }
                     65:        if (argc == 1) {        /* no filenames; use stdin */
                     66:                argv[0] = tostring("-");
                     67:                argc++;
                     68:                argv--;
                     69:        }
                     70:        argv[0] = cmdname;      /* put prog name at front of arglist */
                     71:        svargc = argc;
                     72:        svargv = argv;
                     73:        dprintf("svargc=%d, svargv[0]=%s\n", svargc, svargv[0]);
                     74:        syminit(svargc, svargv);
                     75:        if (fs)
                     76:                *FS = tostring(fs);
                     77:        *FILENAME = svargv[1];  /* initial file name */
                     78:        signal(SIGFPE, fpecatch);
                     79:        yyparse();
                     80:        dprintf("errorflag=%d\n", errorflag, NULL, NULL);
                     81:        if (errorflag == 0) {
                     82:                compile_time = 0;
                     83:                run(winner);
                     84:        } else
                     85:                bracecheck();
                     86:        exit(errorflag);
                     87: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.