[gdb/contrib] Handle capitalized words in spellcheck.sh

The dictionary contains a few entries with capital letters:
...
$ grep -E '[A-Z]' .git/wikipedia-common-misspellings.txt | wc -l
143
...
but they don't look too interesting in the gdb context (for instance,
Habsbourg->Habsburg), so filter them out.

That leaves us with entries looking only like "foobat->foobar", so add
handling of capitalized words, such that we also rewrite "Foobat" to "Foobar".

Tested on aarch64-linux.  Verified with shellcheck.

Approved-by: Kevin Buettner <kevinb@redhat.com>
diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index 742fc81..c3b7a19 100644
--- a/gdb/amd64-linux-nat.c
+++ b/gdb/amd64-linux-nat.c
@@ -90,7 +90,7 @@ static int amd64_linux_gregset32_reg_offset[] =
 };
 
 
-/* Transfering the general-purpose registers between GDB, inferiors
+/* Transferring the general-purpose registers between GDB, inferiors
    and core files.  */
 
 /* See amd64_collect_native_gregset.  This linux specific version handles
@@ -178,7 +178,7 @@ fill_gregset (const struct regcache *regcache,
   amd64_linux_collect_native_gregset (regcache, gregsetp, regnum);
 }
 
-/* Transfering floating-point registers between GDB, inferiors and cores.  */
+/* Transferring floating-point registers between GDB, inferiors and cores.  */
 
 /* Fill GDB's register cache with the floating-point and SSE register
    values in *FPREGSETP.  */
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index c17b5f7..ba6532f 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -1227,7 +1227,7 @@ amd64_get_unused_input_int_reg (const struct amd64_insn *details)
 
   /* Avoid RAX.  */
   used_regs_mask |= 1 << EAX_REG_NUM;
-  /* Similarily avoid RDX, implicit operand in divides.  */
+  /* Similarly avoid RDX, implicit operand in divides.  */
   used_regs_mask |= 1 << EDX_REG_NUM;
   /* Avoid RSP.  */
   used_regs_mask |= 1 << ESP_REG_NUM;
diff --git a/gdb/contrib/spellcheck.sh b/gdb/contrib/spellcheck.sh
index a95b325..0223885 100755
--- a/gdb/contrib/spellcheck.sh
+++ b/gdb/contrib/spellcheck.sh
@@ -218,8 +218,10 @@
 
 output_dictionaries ()
 {
-    output_local_dictionary
-    cat "$dictionary"
+    (
+	output_local_dictionary
+	cat "$dictionary"
+    ) | grep -E -v "[A-Z]"
 }
 
 parse_dictionary ()
@@ -247,7 +249,14 @@
     else
 	rm -f "$cache_dir/$cache_file2".*
 
-	pat=$(grep_join "${words[@]}")
+	declare -a re_words
+	mapfile -t re_words \
+		< <(for f in "${words[@]}"; do
+			echo "$f"
+		    done \
+			| sed "s/^\(.\)/[\u\1\1]/")
+
+	pat=$(grep_join "${re_words[@]}")
 
 	local before after
 	before=$(grep_join \
@@ -283,6 +292,8 @@
 		"${grep_separators[@]}" \
 		"${grep_post[@]}")
 
+    pat="(${pat@u}|$pat)"
+
     pat="$before$pat$after"
 
     grep -E \
@@ -310,11 +321,13 @@
 		"${sed_separators[@]}" \
 		"${sed_post[@]}")
 
-    local repl
-    repl="s%$before$word$after%\1$replacement\2%g"
+    local repl1
+    local repl2
+    repl1="s%$before$word$after%\1$replacement\2%g"
+    repl2="s%$before${word@u}$after%\1${replacement@u}\2%g"
 
     sed -i \
-	"$repl" \
+	"$repl1;$repl2" \
 	"$file"
 }
 
diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
index 41c1113..d2cbe51 100644
--- a/gdb/i386-linux-nat.c
+++ b/gdb/i386-linux-nat.c
@@ -137,7 +137,7 @@ store_register (const struct regcache *regcache, int regno)
 }
 
 
-/* Transfering the general-purpose registers between GDB, inferiors
+/* Transferring the general-purpose registers between GDB, inferiors
    and core files.  */
 
 /* Fill GDB's register array with the general-purpose register values
@@ -234,7 +234,7 @@ static void store_regs (const struct regcache *regcache, int tid, int regno) {}
 #endif
 
 
-/* Transfering floating-point registers between GDB, inferiors and cores.  */
+/* Transferring floating-point registers between GDB, inferiors and cores.  */
 
 /* Fill GDB's register array with the floating-point register values in
    *FPREGSETP.  */
@@ -304,7 +304,7 @@ store_fpregs (const struct regcache *regcache, int tid, int regno)
 #endif
 
 
-/* Transfering floating-point and SSE registers to and from GDB.  */
+/* Transferring floating-point and SSE registers to and from GDB.  */
 
 /* Fetch all registers covered by the PTRACE_GETREGSET request from
    process/thread TID and store their values in GDB's register array.
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 65ec221..d345205 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -2104,7 +2104,7 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
   if (!note_data)
     return NULL;
 
-  /* Auxillary vector.  */
+  /* Auxiliary vector.  */
   std::optional<gdb::byte_vector> auxv =
     target_read_alloc (current_inferior ()->top_target (),
 		       TARGET_OBJECT_AUXV, NULL);
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 2887ad2..0201f84 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -961,7 +961,7 @@
 
        case LOC_LABEL:
        case LOC_UNRESOLVED:
-	  error (_("internal:  Unforseen case in m2lex()"));
+	  error (_("internal:  Unforeseen case in m2lex()"));
 
        default:
 	  error (_("unhandled token in m2lex()"));
diff --git a/gdb/m32r-linux-nat.c b/gdb/m32r-linux-nat.c
index 08a4db1..bb86675 100644
--- a/gdb/m32r-linux-nat.c
+++ b/gdb/m32r-linux-nat.c
@@ -66,7 +66,7 @@ static int regmap[] = {
 
 
 
-/* Transfering the general-purpose registers between GDB, inferiors
+/* Transferring the general-purpose registers between GDB, inferiors
    and core files.  */
 
 /* Fill GDB's register array with the general-purpose register values
@@ -176,7 +176,7 @@ store_regs (const struct regcache *regcache, int tid, int regno)
 
 
 
-/* Transfering floating-point registers between GDB, inferiors and cores.  
+/* Transferring floating-point registers between GDB, inferiors and cores.
    Since M32R has no floating-point registers, these functions do nothing.  */
 
 void
diff --git a/gdb/m68k-linux-nat.c b/gdb/m68k-linux-nat.c
index 49cd491..7ea5847 100644
--- a/gdb/m68k-linux-nat.c
+++ b/gdb/m68k-linux-nat.c
@@ -300,7 +300,7 @@ static void store_regs (const struct regcache *regcache, int tid, int regno)
 #endif
 
 
-/* Transfering floating-point registers between GDB, inferiors and cores.  */
+/* Transferring floating-point registers between GDB, inferiors and cores.  */
 
 /* What is the address of fpN within the floating-point register set F?  */
 #define FPREG_ADDR(f, n) (&(f)->fpregs[(n) * 3])
diff --git a/gdb/or1k-linux-nat.c b/gdb/or1k-linux-nat.c
index 2139224..e6cc9c7 100644
--- a/gdb/or1k-linux-nat.c
+++ b/gdb/or1k-linux-nat.c
@@ -106,7 +106,7 @@ fill_gregset (const struct regcache *regcache, prgregset_t *gregs, int regnum)
     regcache->raw_collect (OR1K_NPC_REGNUM, regp + 32);
 }
 
-/* Transfering floating-point registers between GDB, inferiors and cores.
+/* Transferring floating-point registers between GDB, inferiors and cores.
    Since OpenRISC floating-point registers are the same as GPRs these do
    nothing.  */
 
diff --git a/gdb/target.h b/gdb/target.h
index 6da58c7..d872991 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1651,7 +1651,7 @@ struct memory_write_request
     : begin (begin_), end (end_), data (data_), baton (baton_)
   {}
 
-  /* Begining address that must be written.  */
+  /* Beginning address that must be written.  */
   ULONGEST begin;
   /* Past-the-end address.  */
   ULONGEST end;
diff --git a/gdb/testsuite/gdb.arch/arc-decode-insn.S b/gdb/testsuite/gdb.arch/arc-decode-insn.S
index ea37455..6b37d54 100644
--- a/gdb/testsuite/gdb.arch/arc-decode-insn.S
+++ b/gdb/testsuite/gdb.arch/arc-decode-insn.S
@@ -394,7 +394,7 @@
 
 #ifdef TEST_B
 .Lb_target:
-    ; Artifical nop, so that first b will not branch to itself.
+    ; Artificial nop, so that first b will not branch to itself.
     nop_s
     ; b s25
     .set b_s25_target, @.Lb_target
diff --git a/gdb/testsuite/gdb.cp/static-print-quit.exp b/gdb/testsuite/gdb.cp/static-print-quit.exp
index 109bf8d..7236439 100644
--- a/gdb/testsuite/gdb.cp/static-print-quit.exp
+++ b/gdb/testsuite/gdb.cp/static-print-quit.exp
@@ -55,7 +55,7 @@
 
 gdb_test "q" ".*"
 
-# Now the obstack is uninitialized.  Excercise it.
+# Now the obstack is uninitialized.  Exercise it.
 
 gdb_test_no_output "set pagination off"
 gdb_test "print c" ".*" "first print"
diff --git a/gdb/tilegx-linux-nat.c b/gdb/tilegx-linux-nat.c
index 440a5cc..5755e70 100644
--- a/gdb/tilegx-linux-nat.c
+++ b/gdb/tilegx-linux-nat.c
@@ -72,7 +72,7 @@ static const int regmap[] =
   56, 58
 };
 
-/* Transfering the general-purpose registers between GDB, inferiors
+/* Transferring the general-purpose registers between GDB, inferiors
    and core files.  */
 
 /* Fill GDB's register array with the general-purpose register values
@@ -105,7 +105,7 @@ fill_gregset (const struct regcache* regcache,
       regcache->raw_collect (i, regp + regmap[i]);
 }
 
-/* Transfering floating-point registers between GDB, inferiors and cores.  */
+/* Transferring floating-point registers between GDB, inferiors and cores.  */
 
 /* Fill GDB's register array with the floating-point register values in
    *FPREGSETP.  */