]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/contrib] Factor out grep_or and sed_or in spellcheck.sh
authorTom de Vries <tdevries@suse.de>
Tue, 8 Oct 2024 06:24:13 +0000 (08:24 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 8 Oct 2024 06:24:13 +0000 (08:24 +0200)
While trying to add more separators here:
...
 # Separators: space, slash, tab.
 grep_separator=" |/| "
 sed_separator=" \|/\|\t"
...
I mistakingly used "|" instead of "\|" in sed_separator.

Factor out new variables grep_or and sed_or, and construct the grep_separator
and sed_separator variables by joining the elements of a list using grep_or
and sed_or.

Verified with shellcheck, and tested by rerunning on x86_64-linux.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
gdb/contrib/spellcheck.sh

index e7db6217d4535115e4e6e4a47c28c0da52b53b92..343a43f054c35ae870de2dee0cb1ce2ae72f90c8 100755 (executable)
@@ -27,8 +27,47 @@ cache_file=wikipedia-common-misspellings.txt
 dictionary=$cache_dir/$cache_file
 
 # Separators: space, slash, tab.
-grep_separator=" |/|   "
-sed_separator=" \|/\|\t"
+declare -a grep_separators
+grep_separators=(
+    " "
+    "/"
+    "  "
+)
+declare -a sed_separators
+sed_separators=(
+    " "
+    "/"
+    "\t"
+)
+
+join ()
+{
+    local or
+    or="$1"
+    shift
+
+    local res
+    res=""
+
+    local first
+    first=true
+
+    for item in "$@"; do
+       if $first; then
+           first=false
+           res="$item"
+       else
+           res="$res$or$item"
+       fi
+    done
+
+    echo "$res"
+}
+
+grep_or="|"
+sed_or="\|"
+grep_separator=$(join $grep_or "${grep_separators[@]}")
+sed_separator=$(join $sed_or "${sed_separators[@]}")
 
 usage ()
 {