diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 65 |
1 files changed, 46 insertions, 19 deletions
@@ -58,7 +58,7 @@ static void init_args(int argc0, int argc, const char *argv0, char **argv); static void init_vars(void); static NODE *load_environ(void); static NODE *load_procinfo(void); -static RETSIGTYPE catchsig(int sig); +static void catchsig(int sig); #ifdef HAVE_LIBSIGSEGV static int catchsegv(void *fault_address, int serious); static void catchstackoverflow(int emergency, stackoverflow_context_t scp); @@ -147,7 +147,7 @@ static void set_locale_stuff(void); static bool stopped_early = false; int do_flags = false; -bool do_optimize = false; /* apply default optimizations */ +bool do_optimize = true; /* apply default optimizations */ static int do_nostalgia = false; /* provide a blast from the past */ static int do_binary = false; /* hands off my data! */ static int do_version = false; /* print version info */ @@ -193,6 +193,7 @@ static const struct option optab[] = { { "locale", required_argument, NULL, 'Z' }, #endif { "non-decimal-data", no_argument, NULL, 'n' }, + { "no-optimize", no_argument, NULL, 's' }, { "nostalgia", no_argument, & do_nostalgia, 1 }, { "optimize", no_argument, NULL, 'O' }, #if defined(YYDEBUG) || defined(GAWKDEBUG) @@ -294,22 +295,10 @@ main(int argc, char **argv) * this value once makes a speed difference. */ gawk_mb_cur_max = MB_CUR_MAX; -#ifdef LIBC_IS_BORKED -{ - const char *env_lc; - - env_lc = getenv("LC_ALL"); - if (env_lc == NULL) - env_lc = getenv("LANG"); - if (env_lc != NULL && env_lc[1] == '\0' && tolower(env_lc[0]) == 'c') - gawk_mb_cur_max = 1; -} -#endif /* init the cache for checking bytes if they're characters */ init_btowc_cache(); - if (do_nostalgia) nostalgia(); @@ -498,9 +487,8 @@ main(int argc, char **argv) if (do_debug) debug_prog(code_block); - else if (do_pretty_print && ! do_debug && getenv("GAWK_NO_PP_RUN") != NULL) - /* hack to run pretty printer only. need a better solution */ - ; + else if (do_pretty_print && ! do_profile) + ; /* run pretty printer only. */ else interpret(code_block); @@ -596,6 +584,7 @@ usage(int exitval, FILE *fp) fputs(_("\t-p[file]\t\t--profile[=file]\n"), fp); fputs(_("\t-P\t\t\t--posix\n"), fp); fputs(_("\t-r\t\t\t--re-interval\n"), fp); + fputs(_("\t-s\t\t\t--no-optimize\n"), fp); fputs(_("\t-S\t\t\t--sandbox\n"), fp); fputs(_("\t-t\t\t\t--lint-old\n"), fp); fputs(_("\t-V\t\t\t--version\n"), fp); @@ -898,9 +887,40 @@ load_environ() */ path_environ("AWKPATH", defpath); path_environ("AWKLIBPATH", deflibpath); + + /* set up array functions */ + init_env_array(ENVIRON_node); + return ENVIRON_node; } +static void +load_procinfo_argv() +{ + NODE *tmp; + NODE **aptr; + NODE *argv_array; + int i; + + tmp = make_string("argv", 4); + aptr = assoc_lookup(PROCINFO_node, tmp); + unref(tmp); + unref(*aptr); + getnode(argv_array); + memset(argv_array, '\0', sizeof(NODE)); /* valgrind wants this */ + null_array(argv_array); + *aptr = argv_array; + argv_array->parent_array = PROCINFO_node; + argv_array->vname = estrdup("argv", 4); + for (i = 0; d_argv[i] != NULL; i++) { + tmp = make_number(i); + aptr = assoc_lookup(argv_array, tmp); + unref(tmp); + unref(*aptr); + *aptr = make_string(d_argv[i], strlen(d_argv[i])); + } +} + /* load_procinfo --- populate the PROCINFO array */ static NODE * @@ -1000,6 +1020,7 @@ load_procinfo() groupset = NULL; } #endif + load_procinfo_argv(); return PROCINFO_node; } @@ -1170,7 +1191,7 @@ arg_assign(char *arg, bool initing) /* catchsig --- catch signals */ -static RETSIGTYPE +static void catchsig(int sig) { if (sig == SIGFPE) { @@ -1411,7 +1432,7 @@ parse_args(int argc, char **argv) /* * The + on the front tells GNU getopt not to rearrange argv. */ - const char *optlist = "+F:f:v:W;bcCd::D::e:E:ghi:l:L:nNo::Op::MPrStVYZ:"; + const char *optlist = "+F:f:v:W;bcCd::D::e:E:ghi:l:L:nNo::Op::MPrSstVYZ:"; int old_optind; int c; char *scan; @@ -1571,6 +1592,10 @@ parse_args(int argc, char **argv) do_flags |= DO_INTERVALS; break; + case 's': + do_optimize = false; + break; + case 'S': do_flags |= DO_SANDBOX; break; @@ -1645,6 +1670,8 @@ parse_args(int argc, char **argv) break; } out: + do_optimize = (do_optimize && ! do_pretty_print); + return; } |