From 38c62e1718e8c6648a31f7d2852de55c7a63b7b0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 20 Oct 2026 00:41:06 -0500 Subject: [PATCH] Add comments and tighten up fast path. --- toys/pending/sh.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/toys/pending/sh.c b/toys/pending/sh.c index b9103c54..576939c1 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -2112,8 +2112,18 @@ static int expand_arg_nobrace(struct sh_arg *arg, char *str, unsigned flags, struct arg_list **delete, struct sh_arg *ant, long *measure) { char cc, qq = flags&NO_QUOTE, sep[6], *new = str, *s, *ss, *ifs, *slice; - int ii = 0, oo = 0, xx, yy, dd, jj, kk, ll, mm; + int ii = 0, oo = 0, xx, yy, dd, jj, kk, ll, mm, nosplit; struct sh_arg deck = {0}; + struct sh_arg aa; + + // theory: loop copying str[ii++] to new[oo++] then arg_add(arg, new); + + // umodified new = str, passed-in string gets added to arg if no changes made. + // All mallocs added to delete for later garbage collection. + // useis wildcard_add_files(deck) instead of arg_add for ? * glob expansion. + // ifs = expanded $VAR content: when unquoted checked against $IFS as cached + // in TT.ff->ifs used to split words and arg_add extras. + // aa = things like "$@" expand to multiple ifs, array to hold them // TODO: ! history expansion @@ -2145,9 +2155,6 @@ static int expand_arg_nobrace(struct sh_arg *arg, char *str, unsigned flags, // parameter/variable expansion and dequoting if (!ant) ant = &deck; for (; (cc = str[ii++]); str!=new && (new[oo] = 0)) { - struct sh_arg aa = {0}; - int nosplit = 0; - if (measure && cc==*measure) break; // skip literal chars @@ -2158,12 +2165,15 @@ static int expand_arg_nobrace(struct sh_arg *arg, char *str, unsigned flags, continue; } + ifs = slice = 0; + nosplit = 0; + memset(&aa, 0, sizeof(aa)); + // allocate snapshot if we just started modifying if (str == new) { new = xstrdup(new); new[oo] = 0; } - ifs = slice = 0; // handle escapes and quoting if (cc == '"') qq++; -- 2.39.5