From b26689f9506556e3236c103c1dca48971430ca66 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 3 Oct 2022 05:08:33 -0500 Subject: [PATCH] Fix bucket sort with -F --- tests/grep.test | 1 + toys/posix/grep.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/grep.test b/tests/grep.test index 67cfecaa..f7efabab 100755 --- a/tests/grep.test +++ b/tests/grep.test @@ -191,6 +191,7 @@ testcmd "-Fx" "-Fx h input" "h\n" \ "missing\nH\nthis is hello\nthis is world\nh\nmissing" "" testcmd "-Fix" "-Fix h input" "H\nh\n" \ "missing\nH\nthis is HELLO\nthis is WORLD\nh\nmissing" "" +testcmd "-F bucket sort" "-F '\.zip'" '\\.zip\n' '' '\\.zip\n' testcmd "-f /dev/null" "-f /dev/null" "" "" "hello\n" testcmd "-z with \n in pattern" "-f input" "hi\nthere\n" "i\nt" "hi\nthere" diff --git a/toys/posix/grep.c b/toys/posix/grep.c index efaabe82..1f347046 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -445,9 +445,12 @@ static void parse_regex(void) // Sort fast path patterns into buckets by first character for (al = TT.e; al; al = new) { new = al->next; - key = '^'==*al->arg; - if ('\\'==al->arg[key]) key++; - else if ('$'==al->arg[key] && !al->arg[key+1]) key++; + if (FLAG(F)) key = 0; + else { + key = '^'==*al->arg; + if ('\\'==al->arg[key]) key++; + else if ('$'==al->arg[key] && !al->arg[key+1]) key++; + } key = al->arg[key]; if (FLAG(i)) key = toupper(key); al->next = TT.fixed[key]; -- 2.39.2