SDL: wikiheaders: Fixed LaTeX chapter list and symbol sorting.

From 353001e0777e0d8051a6969090cbf00caa134197 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sun, 5 May 2024 02:44:45 -0400
Subject: [PATCH] wikiheaders: Fixed LaTeX chapter list and symbol sorting.

---
 build-scripts/wikiheaders.pl | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index 700f4ef35f6cc..f25f41841aa12 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -2354,14 +2354,20 @@ sub print_undocumented_section {
 
     # Sort symbols by symbol type, then alphabetically.
     my @headersymskeys = sort {
-        my $rc = $headersymstype{$a} <=> $headersymstype{$b};
+        my $symtypea = $headersymstype{$a};
+        my $symtypeb = $headersymstype{$b};
+        $symtypea = 3 if ($symtypea > 3);
+        $symtypeb = 3 if ($symtypeb > 3);
+        my $rc = $symtypea <=> $symtypeb;
         if ($rc == 0) {
-            $rc = $a cmp $b;
+            $rc = lc($a) cmp lc($b);
         }
         return $rc;
     } keys %headersyms;
 
     my $current_symtype = 0;
+    my $current_chapter = '';
+
     foreach (@headersymskeys) {
         my $sym = $_;
         next if not defined $wikisyms{$sym};  # don't have a page for that function, skip it.
@@ -2393,7 +2399,11 @@ sub print_undocumented_section {
             } else {
                 $newchapter = 'Datatypes';
             }
-            $str .= "\n\n\\chapter{$projectshortname $newchapter}\n\n\\clearpage\n\n";
+
+            if ($current_chapter ne $newchapter) {
+                $str .= "\n\n\\chapter{$projectshortname $newchapter}\n\n\\clearpage\n\n";
+                $current_chapter = $newchapter;
+            }
             $current_symtype = $symtype;
         }