SDL: wikiheaders: Fixes to manpage output for datatypes vs functions.

From 6ccdfffe2653467c42b60fc5eb8ea5548c295333 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 11 Apr 2024 01:03:07 -0400
Subject: [PATCH] wikiheaders: Fixes to manpage output for datatypes vs
 functions.

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

diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index 47a923e9c0dc2..594f0701e3338 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -1674,8 +1674,8 @@ sub print_undocumented_section {
 } elsif ($copy_direction == -2) { # --copy-to-manpages
     # This only takes from the wiki data, since it has sections we omit from the headers, like code examples.
 
-    $manpath .= "/man3";
-    File::Path::make_path($manpath);
+    File::Path::make_path("$manpath/man3");
+    File::Path::make_path("$manpath/man3type");
 
     $dewikify_mode = 'manpage';
     $wordwrap_mode = 'manpage';
@@ -1731,6 +1731,18 @@ sub print_undocumented_section {
         $headerfile =~ s/\%fname\%/$headersymslocation{$sym}/g;
         $headerfile .= "\n";
 
+        my $mansection;
+        my $mansectionname;
+        if (($symtype == 1) || ($symtype == 2)) {  # functions or macros
+            $mansection = '3';
+            $mansectionname = 'FUNCTIONS';
+        } elsif (($symtype >= 3) && ($symtype <= 5)) {  # struct/union/enum/typedef
+            $mansection = '3type';
+            $mansectionname = 'DATATYPES';
+        } else {
+            die("Unexpected symtype $symtype");
+        }
+
         my $brief = $sectionsref->{'[Brief]'};
         my $decl = $headerdecls{$sym};
         my $str = '';
@@ -1769,7 +1781,7 @@ sub print_undocumented_section {
         $str .= "..\n";
         $str .= '.if \n[.g] .mso www.tmac' . "\n";
 
-        $str .= ".TH $sym 3 \"$projectshortname $fullversion\" \"$projectfullname\" \"$projectshortname$majorver FUNCTIONS\"\n";
+        $str .= ".TH $sym $mansection \"$projectshortname $fullversion\" \"$projectfullname\" \"$projectshortname$majorver $mansectionname\"\n";
         $str .= ".SH NAME\n";
 
         $str .= "$sym";
@@ -1927,16 +1939,7 @@ sub print_undocumented_section {
         $str .= ".UE\n";
         }
 
-        my $mansection;
-        if (($symtype == 1) || ($symtype == 2)) {  # functions or macros
-            $mansection = '3';
-        } elsif (($symtype >= 3) && ($symtype <= 5)) {  # struct/union/enum/typedef
-            $mansection = '3type';
-        } else {
-            die("Unexpected symtype $symtype");
-        }
-
-        my $path = "$manpath/$_.$mansection";
+        my $path = "$manpath/man$mansection/$_.$mansection";
         my $tmppath = "$path.tmp";
         open(FH, '>', $tmppath) or die("Can't open '$tmppath': $!\n");
         print FH $str;