/* load built-in functions in symbol table */ void bi_funct_init(void) { register BI_REC *p; register SYMTAB *stp; /* length is special (posix bozo) */ stp = insert(bi_funct->name); stp->type = ST_LENGTH; stp->stval.bip = bi_funct; for (p = bi_funct + 1; p->name; p++) { stp = insert(p->name); stp->type = ST_BUILTIN; stp->stval.bip = p; } /* seed rand() off the clock */ { CELL c; c.type = 0; bi_srand(&c); } }
/* load built-in functions in symbol table */ void bi_funct_init(void) { register BI_REC *p; register SYMTAB *stp; /* length is special (posix bozo) */ stp = insert(bi_funct->name); stp->type = ST_LENGTH; stp->stval.bip = bi_funct; for (p = bi_funct + 1; p->name; p++) { stp = insert(p->name); stp->type = ST_BUILTIN; stp->stval.bip = p; } #ifndef NO_INIT_SRAND /* seed rand() off the clock */ { CELL c[2]; memset(c, 0, sizeof(c)); c[1].type = C_NOINIT; bi_srand(c + 1); } #endif }
static void process_cmdline(int argc, char **argv) { int i, j, nextarg; char *optArg; char *optNext; PFILE dummy; /* starts linked list of filenames */ PFILE *tail = &dummy; size_t length; if (argc <= 1) usage(); for (i = 1; i < argc && argv[i][0] == '-'; i = nextarg) { if (argv[i][1] == 0) /* - alone */ { if (!pfile_name) no_program(); break; /* the for loop */ } /* safe to look at argv[i][2] */ /* * Check for "long" options and decide how to handle them. */ if (strlen(argv[i]) > 2 && !strncmp(argv[i], "--", (size_t) 2)) { if (!allow_long_options(argv[i])) { nextarg = i + 1; continue; } } if (argv[i][2] == 0) { if (i == argc - 1 && argv[i][1] != '-') { if (strchr("WFvf", argv[i][1])) { errmsg(0, "option %s lacks argument", argv[i]); mawk_exit(2); } bad_option(argv[i]); } optArg = argv[i + 1]; nextarg = i + 2; } else { /* argument glued to option */ optArg = &argv[i][2]; nextarg = i + 1; } switch (argv[i][1]) { case 'W': for (j = 0; j < (int) strlen(optArg); j = (int) (optNext - optArg)) { switch (parse_w_opt(optArg + j, &optNext)) { case W_VERSION: print_version(); break; #if USE_BINMODE case W_BINMODE: if (haveValue(optNext)) { set_binmode(atoi(optNext + 1)); optNext = skipValue(optNext); } else { errmsg(0, "missing value for -W binmode"); mawk_exit(2); } break; #endif case W_DUMP: dump_code_flag = 1; break; case W_EXEC: if (pfile_name) { errmsg(0, "-W exec is incompatible with -f"); mawk_exit(2); } else if (nextarg == argc) { no_program(); } if (haveValue(optNext)) { pfile_name = optNext + 1; i = nextarg; } else { pfile_name = argv[nextarg]; i = nextarg + 1; } goto no_more_opts; case W_INTERACTIVE: interactive_flag = 1; setbuf(stdout, (char *) 0); break; case W_POSIX_SPACE: posix_space_flag = 1; break; case W_RANDOM: if (haveValue(optNext)) { int x = atoi(optNext + 1); CELL c[2]; memset(c, 0, sizeof(c)); c[1].type = C_DOUBLE; c[1].dval = (double) x; /* c[1] is input, c[0] is output */ bi_srand(c + 1); optNext = skipValue(optNext); } else { errmsg(0, "missing value for -W random"); mawk_exit(2); } break; case W_SPRINTF: if (haveValue(optNext)) { int x = atoi(optNext + 1); if (x > (int) sizeof(string_buff)) { if (sprintf_buff != string_buff && sprintf_buff != 0) { zfree(sprintf_buff, (size_t) (sprintf_limit - sprintf_buff)); } sprintf_buff = (char *) zmalloc((size_t) x); sprintf_limit = sprintf_buff + x; } optNext = skipValue(optNext); } else { errmsg(0, "missing value for -W sprintf"); mawk_exit(2); } break; case W_HELP: /* FALLTHRU */ case W_USAGE: usage(); /* NOTREACHED */ break; case W_UNKNOWN: errmsg(0, "vacuous option: -W %s", optArg + j); break; } while (*optNext == '=') { errmsg(0, "unexpected option value %s", optArg + j); optNext = skipValue(optNext); } } break; case 'v': if (!is_cmdline_assign(optArg)) { errmsg(0, "improper assignment: -v %s", optArg); mawk_exit(2); } break; case 'F': rm_escape(optArg, &length); /* recognize escape sequences */ cell_destroy(FS); FS->type = C_STRING; FS->ptr = (PTR) new_STRING1(optArg, length); cast_for_split(cellcpy(&fs_shadow, FS)); break; case '-': if (argv[i][2] != 0) { bad_option(argv[i]); } i++; goto no_more_opts; case 'f': /* first file goes in pfile_name ; any more go on a list */ if (!pfile_name) pfile_name = optArg; else { tail = tail->link = ZMALLOC(PFILE); tail->fname = optArg; } break; default: bad_option(argv[i]); } } no_more_opts: tail->link = (PFILE *) 0; pfile_list = dummy.link; if (pfile_name) { set_ARGV(argc, argv, i); scan_init((char *) 0); } else { /* program on command line */ if (i == argc) no_program(); set_ARGV(argc, argv, i + 1); #if defined(MSDOS) && ! HAVE_REARGV /* reversed quotes */ { char *p; for (p = argv[i]; *p; p++) if (*p == '\'') *p = '\"'; } #endif scan_init(argv[i]); /* #endif */ } }