[1/3,gdb/contrib] Factor out grep_or and sed_or in spellcheck.sh

Message ID 20241006104603.7584-1-tdevries@suse.de
State Committed
Headers
Series [1/3,gdb/contrib] Factor out grep_or and sed_or in spellcheck.sh |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Oct. 6, 2024, 10:46 a.m. UTC
  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.
---
 gdb/contrib/spellcheck.sh | 43 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)


base-commit: 23ca0175c66b1add6fe51efc160628c824f6d32f
  

Comments

Alexandra Hájková Oct. 7, 2024, 6:58 p.m. UTC | #1
>
>  usage ()
>  {
>
> base-commit: 23ca0175c66b1add6fe51efc160628c824f6d32f
> --
> 2.35.3
>
> Looks great, and also works perfectly on aarch64.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
  
Tom de Vries Oct. 8, 2024, 6:24 a.m. UTC | #2
On 10/7/24 20:58, Alexandra Petlanova Hajkova wrote:
> 
> 
> 
> 
>       usage ()
>       {
> 
>     base-commit: 23ca0175c66b1add6fe51efc160628c824f6d32f
>     -- 
>     2.35.3
> 
> Looks great, and also works perfectly on aarch64.
> Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com 

Hi,

thanks for the review, I've pushed the series.

Thanks,
- Tom
  

Patch

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 ()
 {