From f81fb1c8ad311730312b2dcd08ca53d50c373f62 Mon Sep 17 00:00:00 2001 From: Ray Gardner Date: Tue, 26 Mar 2024 20:28:05 -0600 Subject: [PATCH] Remove debug code; replace envp with environ --- toys/pending/awk.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/toys/pending/awk.c b/toys/pending/awk.c index 62518914..329247f0 100644 --- a/toys/pending/awk.c +++ b/toys/pending/awk.c @@ -3482,7 +3482,6 @@ static void gsub(int opcode, int nargs, int parmbase) val_to_str(repl); val_to_str(v); -#define MKINT(x) ((int)(x)) // coerce to integer #define SLEN(zvalp) ((zvalp)->vst->size) char *p, *rp0 = repl->vst->str, *rp = rp0, *s = v->vst->str; int namps = 0, nhits = 0, is_sub = (opcode == tksub), eflags = 0; @@ -4371,7 +4370,7 @@ static void insert_argv_map(struct zvalue *map, int key, char *value) } static void init_globals(int optind, int argc, char **argv, char *sepstring, - struct arg_list *assign_args, char **envp) + struct arg_list *assign_args) { // Global variables reside at the bottom of the TT.stack. Start with the awk // "special variables": ARGC, ARGV, CONVFMT, ENVIRON, FILENAME, FNR, FS, NF, @@ -4382,7 +4381,7 @@ static void init_globals(int optind, int argc, char **argv, char *sepstring, struct zvalue m = ZVINIT(ZF_MAP, 0, 0); zvalue_map_init(&m); STACK[ENVIRON] = m; - for (char **pkey = envp; *pkey; pkey++) { + for (char **pkey = environ; *pkey; pkey++) { char *pval = strchr(*pkey, '='); if (!pval) continue; struct zvalue zkey = ZVINIT(ZF_STR, 0, new_zstring(*pkey, pval - *pkey)); @@ -4478,10 +4477,10 @@ static void free_literal_regex(void) } static void run(int optind, int argc, char **argv, char *sepstring, - struct arg_list *assign_args, char **envp) + struct arg_list *assign_args) { char *printf_fmt_rx = "%[-+ #0']*([*]|[0-9]*)([.]([*]|[0-9]*))?[aAdiouxXfFeEgGcs%]"; - init_globals(optind, argc, argv, sepstring, assign_args, envp); + init_globals(optind, argc, argv, sepstring, assign_args); TT.cfile = xzalloc(sizeof(struct zfile)); rx_compile(&TT.rx_default, "[ \t\n]+"); rx_compile(&TT.rx_last, "[ \t\n]+"); @@ -4535,9 +4534,8 @@ static void progfiles_init(char *progstring, struct arg_list *prog_args) static int awk(char *sepstring, char *progstring, struct arg_list *prog_args, struct arg_list *assign_args, int optind, int argc, char **argv, - int opt_run_prog, char **envp, int opt_test_scanner, int opt_dump_symbols) + int opt_run_prog) { -(void)opt_test_scanner, (void)opt_dump_symbols; struct scanner_state ss = {0}; TT.scs = &ss; @@ -4548,7 +4546,7 @@ static int awk(char *sepstring, char *progstring, struct arg_list *prog_args, error_exit("%d syntax error(s)", TT.cgl.compile_error_count); else { if (opt_run_prog) - run(optind, argc, argv, sepstring, assign_args, envp); + run(optind, argc, argv, sepstring, assign_args); } return TT.cgl.compile_error_count; @@ -4561,12 +4559,12 @@ void awk_main(void) char *progstring = NULL; TT.pbuf = toybuf; - toys.exitval = 73; + toys.exitval = 2; if (!TT.f) { if (*toys.optargs) progstring = toys.optargs[optind++]; else error_exit("No program string\n"); } TT.progname = toys.which->name; toys.exitval = awk(sepstring, progstring, TT.f, TT.v, - optind, toys.optc, toys.optargs, !FLAG(c), environ, 0, 0); + optind, toys.optc, toys.optargs, !FLAG(c)); } -- 2.39.2