3737my $versionmajorregex = ' \A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z' ;
3838my $versionminorregex = ' \A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z' ;
3939my $versionmicroregex = ' \A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z' ;
40+ my $wikidocsectionsym = ' SDL_WIKI_DOCUMENTATION_SECTION' ;
41+ my $forceinlinesym = ' SDL_FORCE_INLINE' ;
42+ my $deprecatedsym = ' SDL_DEPRECATED' ;
43+ my $declspecsym = ' (?:SDLMAIN_|SDL_)?DECLSPEC' ;
44+ my $callconvsym = ' SDLCALL' ;
4045my $mainincludefname = ' SDL.h' ;
4146my $selectheaderregex = ' \ASDL.*?\.h\Z' ;
4247my $projecturl = ' https://libsdl.org/' ;
147152 $envvardesc = $val , next if $key eq ' envvardesc' ;
148153 $envvarsymregex = $val , next if $key eq ' envvarsymregex' ;
149154 $envvarsymreplace = $val , next if $key eq ' envvarsymreplace' ;
155+ $wikidocsectionsym = $val , next if $key eq ' wikidocsectionsym' ;
156+ $forceinlinesym = $val , next if $key eq ' forceinlinesym' ;
157+ $deprecatedsym = $val , next if $key eq ' deprecatedsym' ;
158+ $declspecsym = $val , next if $key eq ' declspecsym' ;
159+ $callconvsym = $val , next if $key eq ' callconvsym' ;
160+
150161 }
151162 }
152163 close (OPTIONS);
@@ -750,6 +761,7 @@ sub print_undocumented_section {
750761 }
751762}
752763
764+ # !!! FIXME: generalize this for other libraries to use.
753765sub strip_fn_declaration_metadata {
754766 my $decl = shift ;
755767 $decl =~ s / SDL_(PRINTF|SCANF)_FORMAT_STRING\s *// ; # don't want this metadata as part of the documentation.
@@ -1153,7 +1165,7 @@ sub generate_envvar_wiki_page {
11531165 } elsif ($ignoring_lines ) {
11541166 push @contents , $_ ;
11551167 next ;
1156- } elsif (/ \A\s *\#\s *ifndef\s +SDL_WIKI_DOCUMENTATION_SECTION \s *\Z / ) {
1168+ } elsif (/ \A\s *\#\s *ifndef\s +$wikidocsectionsym \s *\Z / ) {
11571169 $ignoring_lines = 1;
11581170 push @contents , $_ ;
11591171 next ;
@@ -1162,13 +1174,13 @@ sub generate_envvar_wiki_page {
11621174 # print("CATEGORY FOR '$dent' CHANGED TO " . (defined($current_wiki_category) ? "'$current_wiki_category'" : '(undef)') . "\n");
11631175 push @contents , $_ ;
11641176 next ;
1165- } elsif (/ \A\s *extern\s +(SDL_DEPRECATED \s +|)(SDLMAIN_|SDL_)?DECLSPEC / ) { # a function declaration without a doxygen comment?
1177+ } elsif (/ \A\s *extern\s +(?: $deprecatedsym \s +|)$declspecsym / ) { # a function declaration without a doxygen comment?
11661178 $symtype = 1; # function declaration
11671179 @templines = ();
11681180 $decl = $_ ;
11691181 $str = ' ' ;
11701182 $has_doxygen = 0;
1171- } elsif (/ \A\s *SDL_FORCE_INLINE / ) { # a (forced-inline) function declaration without a doxygen comment?
1183+ } elsif (/ \A\s *$forceinlinesym / ) { # a (forced-inline) function declaration without a doxygen comment?
11721184 $symtype = 1; # function declaration
11731185 @templines = ();
11741186 $decl = $_ ;
@@ -1235,9 +1247,9 @@ sub generate_envvar_wiki_page {
12351247 $lineno ++ if defined $decl ;
12361248 $decl = ' ' if not defined $decl ;
12371249 chomp ($decl );
1238- if ($decl =~ / \A\s *extern\s +(SDL_DEPRECATED \s +|)(SDLMAIN_|SDL_)?DECLSPEC / ) {
1250+ if ($decl =~ / \A\s *extern\s +(?: $deprecatedsym \s +|)$declspecsym / ) {
12391251 $symtype = 1; # function declaration
1240- } elsif ($decl =~ / \A\s *SDL_FORCE_INLINE / ) {
1252+ } elsif ($decl =~ / \A\s *$forceinlinesym / ) {
12411253 $symtype = 1; # (forced-inline) function declaration
12421254 } elsif ($decl =~ / \A\s *\#\s *define\s +/ ) {
12431255 $symtype = 2; # macro
@@ -1274,7 +1286,7 @@ sub generate_envvar_wiki_page {
12741286 }
12751287 $headercategorydocs {$current_wiki_category } = $sym ;
12761288 } elsif ($symtype == 1) { # a function
1277- my $is_forced_inline = ($decl =~ / \A\s *SDL_FORCE_INLINE / );
1289+ my $is_forced_inline = ($decl =~ / \A\s *$forceinlinesym / );
12781290
12791291 if ($is_forced_inline ) {
12801292 if (not $decl =~ / \)\s *(\{ .*|)\s *\Z / ) {
@@ -1311,14 +1323,14 @@ sub generate_envvar_wiki_page {
13111323
13121324 my $paramsstr = undef ;
13131325
1314- if (!$is_forced_inline && $decl =~ / \A\s *extern\s +(SDL_DEPRECATED\s +|)(SDLMAIN_|SDL_)?DECLSPEC\w *\s +(const\s +|)(unsigned\s +|)(.*?)([\*\s ]+)(\* ?)\s *SDLCALL\s +(.*?)\s *\( (.*?)\) ;/ ) {
1315- $sym = $8 ;
1316- $rettype = " $3$4$5$6 " ;
1317- $paramsstr = $9 ;
1318- } elsif ($is_forced_inline && $decl =~ / \A\s *SDL_FORCE_INLINE\s +(SDL_DEPRECATED\s +|)(const\s +|)(unsigned\s +|)(.*?)([\*\s ]+)(.*?)\s *\( (.*?)\) ;/ ) {
1326+ if (!$is_forced_inline && $decl =~ / \A\s *extern\s +(?:$deprecatedsym \s +|)$declspecsym \w *\s +(const\s +|)(unsigned\s +|)(.*?)([\*\s ]+)(\* ?)\s *$callconvsym \s +(.*?)\s *\( (.*?)\) ;/ ) {
13191327 $sym = $6 ;
1320- $rettype = " $2$3$4$5 " ;
1328+ $rettype = " $1$ 2$3$4$5 " ;
13211329 $paramsstr = $7 ;
1330+ } elsif ($is_forced_inline && $decl =~ / \A\s *$forceinlinesym \s +(?:$deprecatedsym \s +|)(const\s +|)(unsigned\s +|)(.*?)([\*\s ]+)(.*?)\s *\( (.*?)\) ;/ ) {
1331+ $sym = $5 ;
1332+ $rettype = " $1$2$3$4 " ;
1333+ $paramsstr = $6 ;
13221334 } else {
13231335 # print "Found doxygen but no function sig:\n$str\n\n";
13241336 foreach (@templines ) {
@@ -1384,7 +1396,7 @@ sub generate_envvar_wiki_page {
13841396
13851397 $decl = $_ ;
13861398 $temp = $decl ;
1387- $temp =~ s /\A extern\s +(SDL_DEPRECATED \s +|)(SDLMAIN_|SDL_)?DECLSPEC \w *\s +(.*?)\s +(\* ?)SDLCALL \s +/ $3$4 / ;
1399+ $temp =~ s /\A extern\s +(?:$deprecatedsym \s +|)$declspecsym \w *\s +(.*?)\s +(\* ?)$callconvsym \s +/ $1$2 / ;
13881400 $shrink_length = length ($decl ) - length ($temp );
13891401 $decl = $temp ;
13901402 } else {
@@ -2259,10 +2271,10 @@ sub generate_envvar_wiki_page {
22592271
22602272 $desc =~ s / [\s\n ]+\Z // ms ;
22612273
2262- if (0) { # !!! FIXME: disabled because it's not currently suitable for general use, but for manually inspecting the output, it can be useful.
2263- if (($desc =~ / \A [A-Z ]/ ) && (not $desc =~ / \A SDL_ / )) {
2264- print STDERR " WARNING: $sym \' s '\\ param $arg ' text starts with a capital letter: '$desc '. Fixing.\n " ;
2265- $desc = lcfirst ($desc );
2274+ if (0) {
2275+ if (($desc =~ / \A [a-z ]/ ) && (not $desc =~ / $apiprefixregex / )) {
2276+ print STDERR " WARNING: $sym \' s '\\ param $arg ' text starts with a lowercase letter: '$desc '. Fixing.\n " ;
2277+ $desc = ucfirst ($desc );
22662278 }
22672279 }
22682280
@@ -2306,8 +2318,8 @@ sub generate_envvar_wiki_page {
23062318 }
23072319 $desc =~ s / [\s\n ]+\Z // ms ;
23082320
2309- if (0) { # !!! FIXME: disabled because it's not currently suitable for general use, but for manually inspecting the output, it can be useful.
2310- if (($desc =~ / \A [A-Z]/ ) && (not $desc =~ / \A SDL_ / )) {
2321+ if (0) {
2322+ if (($desc =~ / \A [A-Z]/ ) && (not $desc =~ / $apiprefixregex / )) {
23112323 print STDERR " WARNING: $sym \' s '\\ returns' text starts with a capital letter: '$desc '. Fixing.\n " ;
23122324 $desc = lcfirst ($desc );
23132325 }
@@ -2451,7 +2463,7 @@ sub generate_envvar_wiki_page {
24512463 } else {
24522464 die (" Unexpected symbol type $symtype !" );
24532465 }
2454- my $str = " This $symtypename is available since SDL 3.0.0." ;
2466+ my $str = " This $symtypename is available since $projectshortname 3.0.0." ;
24552467 $sections {' Version' } = wordwrap(wikify($wikitype , $str )) . " \n " ;
24562468 }
24572469 }
@@ -2916,7 +2928,7 @@ sub generate_envvar_wiki_page {
29162928 $str .= " .\\\" Please report issues in this manpage's content at:\n " ;
29172929 $str .= " .\\\" $bugreporturl \n " ;
29182930 $str .= " .\\\" Please report issues in the generation of this manpage from the wiki at:\n " ;
2919- $str .= " .\\\" https://github.com/libsdl-org/SDL/issues/new?title=Misgenerated%20manpage%20for%20$sym \n " ;
2931+ $str .= " .\\\" https://github.com/libsdl-org/SDL/issues/new?title=Misgenerated%20manpage%20for%20$sym \n " ; # !!! FIXME: if this becomes a problem for other projects, we'll generalize this.
29202932 $str .= " .\\\" $projectshortname can be found at $projecturl \n " ;
29212933
29222934 # Define a .URL macro. The "www.tmac" thing decides if we're using GNU roff (which has a .URL macro already), and if so, overrides the macro we just created.
0 commit comments