SDL: wikiheaders.pl: pull in full sections from headers, fix more whitespace.

From 8ec9fbdd0c3f2ae6d91acc0351e6241314509f23 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 14 Jul 2021 11:58:57 -0400
Subject: [PATCH] wikiheaders.pl: pull in full sections from headers, fix more
 whitespace.

---
 build-scripts/wikiheaders.pl | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index 59b093542..f33216138 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -118,7 +118,7 @@ sub wordwrap {
     }
 
     $retval .= wordwrap_paragraphs($str);  # wrap what's left.
-    $retval =~ s/\n+$//;
+    $retval =~ s/\n+\Z//ms;
 
     #print("\n\nWORDWRAP DONE:\n\n$retval\n\n\n");
     return $retval;
@@ -738,11 +738,16 @@ sub usage {
                     my $subline = $doxygenlines[0];
                     $subline =~ s/\A\s*//;
                     last if $subline =~ /\A\\/;  # some sort of doxygen command, assume we're past this thing.
-                    last if $subline eq '';  # empty line, this param is done.
                     shift @doxygenlines;  # dump this line from the array; we're using it.
-                    $desc .= " $subline";
+                    if ($subline eq '') {  # empty line, make sure it keeps the newline char.
+                        $desc .= "\n";
+                    } else {
+                        $desc .= " $subline";
+                    }
                 }
 
+                $desc =~ s/[\s\n]+\Z//ms;
+
                 # We need to know the length of the longest string to make Markdown tables, so we just store these off until everything is parsed.
                 push @params, $arg;
                 push @params, $desc;
@@ -753,22 +758,30 @@ sub usage {
                     my $subline = $doxygenlines[0];
                     $subline =~ s/\A\s*//;
                     last if $subline =~ /\A\\/;  # some sort of doxygen command, assume we're past this thing.
-                    last if $subline eq '';  # empty line, this param is done.
                     shift @doxygenlines;  # dump this line from the array; we're using it.
-                    $desc .= wikify($wikitype, " $subline");
+                    if ($subline eq '') {  # empty line, make sure it keeps the newline char.
+                        $desc .= "\n";
+                    } else {
+                        $desc .= " $subline";
+                    }
                 }
-                $sections{'Return Value'} = wordwrap("$retstr $desc") . "\n";
+                $desc =~ s/[\s\n]+\Z//ms;
+                $sections{'Return Value'} = wordwrap("$retstr " . wikify($wikitype, $desc)) . "\n";
             } elsif ($l =~ /\A\\since\s+(.*)\Z/) {
                 my $desc = $1;
                 while (@doxygenlines) {
                     my $subline = $doxygenlines[0];
                     $subline =~ s/\A\s*//;
                     last if $subline =~ /\A\\/;  # some sort of doxygen command, assume we're past this thing.
-                    last if $subline eq '';  # empty line, this param is done.
                     shift @doxygenlines;  # dump this line from the array; we're using it.
-                    $desc .= wikify($wikitype, " $subline");
+                    if ($subline eq '') {  # empty line, make sure it keeps the newline char.
+                        $desc .= "\n";
+                    } else {
+                        $desc .= " $subline";
+                    }
                 }
-                $sections{'Version'} = wordwrap($desc) . "\n";
+                $desc =~ s/[\s\n]+\Z//ms;
+                $sections{'Version'} = wordwrap(wikify($wikitype, $desc)) . "\n";
             } elsif ($l =~ /\A\\sa\s+(.*)\Z/) {
                 my $sa = $1;
                 $sa =~ s/\(\)\Z//;  # Convert "SDL_Func()" to "SDL_Func"