From 99fd53b19dddeb232e169cc5a3918a2adf7d3da2 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 8 Oct 2024 08:24:13 +0200 Subject: [PATCH] [gdb/contrib] Factor out grep_or and sed_or in spellcheck.sh 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 --- gdb/contrib/spellcheck.sh | 43 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/gdb/contrib/spellcheck.sh b/gdb/contrib/spellcheck.sh index e7db6217d45..343a43f054c 100755 --- a/gdb/contrib/spellcheck.sh +++ b/gdb/contrib/spellcheck.sh @@ -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 () { -- 2.39.5