From 0ca093dab6e11e380d6bfae7795c7d251d68d455 Mon Sep 17 00:00:00 2001 From: Ray Gardner Date: Wed, 27 Mar 2024 08:37:49 -0600 Subject: [PATCH] Replace rx_compile(rx, pat) with xregcomp(rx, pat, REG_EXTENDED) --- toys/pending/awk.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/toys/pending/awk.c b/toys/pending/awk.c index 1b42513d..34c535f1 100644 --- a/toys/pending/awk.c +++ b/toys/pending/awk.c @@ -304,7 +304,6 @@ ssize_t getdelim(char ** restrict lineptr, size_t * restrict n, int delimiter, F // Forward ref declarations static struct zvalue *val_to_str(struct zvalue *v); -static void rx_compile(regex_t *rx, char *pat); //////////////////// @@ -1102,7 +1101,7 @@ static int make_literal_regex_val(char *s) { regex_t *rx; rx = xmalloc(sizeof(*rx)); - rx_compile(rx, s); + xregcomp(rx, s, REG_EXTENDED); struct zvalue v = ZVINIT(ZF_RX, 0, 0); v.rx = rx; // Flag empty rx to make it easy to identify for split() special case @@ -1385,7 +1384,6 @@ static void map_name(void) gen2cd(tkvar, slotnum); } - static void check_builtin_arg_counts(int tk, int num_args, char *fname) { static char builtin_1_arg[] = { tkcos, tksin, tkexp, tklog, tksqrt, tkint, @@ -2517,11 +2515,6 @@ static char *rx_escape_str(char *s) return s0; } -static void rx_compile(regex_t *rx, char *pat) -{ - xregcomp(rx, pat, REG_EXTENDED); -} - static void rx_zvalue_compile(regex_t **rx, struct zvalue *pat) { if (IS_RX(pat)) *rx = pat->rx; @@ -2529,7 +2522,7 @@ static void rx_zvalue_compile(regex_t **rx, struct zvalue *pat) val_to_str(pat); zvalue_dup_zstring(pat); rx_escape_str(pat->vst->str); - rx_compile(*rx, pat->vst->str); + xregcomp(*rx, pat->vst->str, REG_EXTENDED); } } @@ -2620,7 +2613,7 @@ static regex_t *rx_fs_prep(char *fs) if (strlen(fs) >= FS_MAX) FATAL("FS too long"); strcpy(TT.fs_last, fs); regfree(&TT.rx_last); - rx_compile(&TT.rx_last, fmt_one_char_fs(fs)); + xregcomp(&TT.rx_last, fmt_one_char_fs(fs), REG_EXTENDED); return &TT.rx_last; } @@ -4478,9 +4471,9 @@ static void run(int optind, int argc, char **argv, char *sepstring, char *printf_fmt_rx = "%[-+ #0']*([*]|[0-9]*)([.]([*]|[0-9]*))?[aAdiouxXfFeEgGcs%]"; 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]+"); - rx_compile(&TT.rx_printf_fmt, printf_fmt_rx); + xregcomp(&TT.rx_default, "[ \t\n]+", REG_EXTENDED); + xregcomp(&TT.rx_last, "[ \t\n]+", REG_EXTENDED); + xregcomp(&TT.rx_printf_fmt, printf_fmt_rx, REG_EXTENDED); new_file("-", stdin, 'r', 'f')->is_std_file = 1; new_file("/dev/stdin", stdin, 'r', 'f')->is_std_file = 1; new_file("/dev/stdout", stdout, 'w', 'f')->is_std_file = 1; @@ -4506,7 +4499,6 @@ static void run(int optind, int argc, char **argv, char *sepstring, static void progfiles_init(char *progstring, struct arg_list *prog_args) { - TT.scs->p = progstring ? progstring : " " + 2; TT.scs->progstring = progstring; TT.scs->prog_args = prog_args; -- 2.39.2