From a0ed8b9a0c7ed5c847ea8d4050bcdf9549a8a4b5 Mon Sep 17 00:00:00 2001 From: Ray Gardner Date: Sat, 3 Feb 2024 13:46:03 -0700 Subject: [PATCH] Allow comma flag in printf; fix ENVIRON init code Allow "'" in printf format for comma thousands separators; make ENVIRON init not modify program environment --- toys/pending/awk.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/toys/pending/awk.c b/toys/pending/awk.c index db2dec37..20ee5e8b 100644 --- a/toys/pending/awk.c +++ b/toys/pending/awk.c @@ -4363,12 +4363,11 @@ static void init_globals(int optind, int argc, char **argv, char *sepstring, for (char **pkey = envp; *pkey; pkey++) { char *pval = strchr(*pkey, '='); if (!pval) continue; - *pval++ = 0; - struct zvalue zkey = ZVINIT(ZF_STR, 0, new_zstring(*pkey, strlen(*pkey))); + struct zvalue zkey = ZVINIT(ZF_STR, 0, new_zstring(*pkey, pval - *pkey)); struct zvalue *v = get_map_val(&m, &zkey); zstring_release(&zkey.vst); if (v->vst) FFATAL("env var dup? (%s)", pkey); - *v = new_str_val(pval); // FIXME refcnt + *v = new_str_val(++pval); // FIXME refcnt check_numeric_string(v); } @@ -4459,7 +4458,7 @@ static void free_literal_regex(void) static void run(int optind, int argc, char **argv, char *sepstring, struct arg_list *assign_args, char **envp) { - char *printf_fmt_rx = "%[-+ #0]*([*]|[0-9]*)([.]([*]|[0-9]*))?[aAdiouxXfFeEgGcs%]"; + char *printf_fmt_rx = "%['-+ #0]*([*]|[0-9]*)([.]([*]|[0-9]*))?[aAdiouxXfFeEgGcs%]"; init_globals(optind, argc, argv, sepstring, assign_args, envp); TT.cfile = xzalloc(sizeof(struct zfile)); rx_compile_or_die(&TT.rx_default, "[ \t\n]+"); -- 2.39.2