Skip to content

Commit

Permalink
wikiheaders: Generate wiki pages for defines under a typedef.
Browse files Browse the repository at this point in the history
These are just there to handle cases where a user stumbles upon a symbol
and punches it into the wiki, so they don't get a 404 for it, but rather
a pointer to where that symbol is relevant.

These pages are generated in the wiki if they don't exist, and are never
overwritten, in case text has been added to them. They are also not bridged
back to the headers or added to the set of manpages.
  • Loading branch information
icculus committed May 1, 2024
1 parent a24d30e commit 12b6c17
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion build-scripts/wikiheaders.pl
Expand Up @@ -541,6 +541,8 @@ sub usage {
my %wikisyms = (); # contains references to hash of strings, each string being the full contents of a section of a wiki page, like $wikisyms{"SDL_OpenAudio"}{"Remarks"}.
my %wikisectionorder = (); # contains references to array, each array item being a key to a wikipage section in the correct order, like $wikisectionorder{"SDL_OpenAudio"}[2] == 'Remarks'

my %referenceonly = (); # $referenceonly{"Y"} -> symbol name that this symbol is bound to. This makes wiki pages that say "See X" where "X" is a typedef and "Y" is a define attached to it. These pages are generated in the wiki only and do not bridge to the headers or manpages.

sub print_undocumented_section {
my $fh = shift;
my $typestr = shift;
Expand Down Expand Up @@ -870,7 +872,11 @@ sub print_undocumented_section {

if (/\A\s*\Z/) {
$blank_lines++;
} elsif (/\A\s*\#(define|if|else|elif|endif)(\s+|\Z)/) {
} elsif (/\A\s*\#\s*(define|if|else|elif|endif)(\s+|\Z)/) {
if (/\A\s*\#\s*define\s+([a-zA-Z0-9_]*)/) {
$referenceonly{$1} = $sym;
}
# update strings now that we know everything pending is to be applied to this declaration. Add pending blank lines and the new text.
if ($blank_lines > 0) {
while ($blank_lines > 0) {
$additional_decl .= "\n";
Expand Down Expand Up @@ -1726,6 +1732,26 @@ sub print_undocumented_section {
rename($path, "$wikipath/$_.${wikitype}") or die("Can't rename '$path' to '$wikipath/$_.${wikitype}': $!\n");
}

# Write out simple redirector pages if they don't already exist.
foreach (keys %referenceonly) {
my $sym = $_;
my $refersto = $referenceonly{$sym};
my $path = "$wikipath/$sym.md"; # we only do Markdown for these.
next if (-f $path); # don't overwrite if it already exists. Delete the file if you need a rebuild!
open(FH, '>', $path) or die("Can't open '$path': $!\n");

if (defined $wikipreamble) {
my $wikified_preamble = wikify('md', $wikipreamble);
print FH "###### $wikified_preamble\n";
}

print FH "# $sym\n\nPlease refer to [$refersto]($refersto) for details.\n\n";
#print FH "----\n";
#print FH "[CategoryAPI](CategoryAPI)\n\n";

close(FH);
}

if (defined $readmepath) {
if ( -d $readmepath ) {
mkdir($wikireadmepath); # just in case
Expand Down

0 comments on commit 12b6c17

Please sign in to comment.