early-access version 2281
This commit is contained in:
239
externals/SDL/build-scripts/wikiheaders.pl
vendored
239
externals/SDL/build-scripts/wikiheaders.pl
vendored
@@ -136,14 +136,21 @@ sub wikify_chunk {
|
||||
#print("\n\nWIKIFY CHUNK:\n\n$str\n\n\n");
|
||||
|
||||
if ($wikitype eq 'mediawiki') {
|
||||
# convert `code` things first, so they aren't mistaken for other markdown items.
|
||||
my $codedstr = '';
|
||||
while ($str =~ s/\A(.*?)\`(.*?)\`//ms) {
|
||||
my $codeblock = $2;
|
||||
$codedstr .= wikify_chunk($wikitype, $1, undef, undef);
|
||||
# Convert obvious SDL things to wikilinks, even inside `code` blocks.
|
||||
$codeblock =~ s/\b(SDL_[a-zA-Z0-9_]+)/[[$1]]/gms;
|
||||
$codedstr .= "<code>$codeblock</code>";
|
||||
}
|
||||
|
||||
# Convert obvious SDL things to wikilinks.
|
||||
$str =~ s/\b(SDL_[a-zA-Z0-9_]+)/[[$1]]/gms;
|
||||
|
||||
# Make some Markdown things into MediaWiki...
|
||||
|
||||
# <code></code> is also popular. :/
|
||||
$str =~ s/\`(.*?)\`/<code>$1<\/code>/gms;
|
||||
|
||||
# bold+italic
|
||||
$str =~ s/\*\*\*(.*?)\*\*\*/'''''$1'''''/gms;
|
||||
|
||||
@@ -156,6 +163,8 @@ sub wikify_chunk {
|
||||
# bullets
|
||||
$str =~ s/^\- /* /gm;
|
||||
|
||||
$str = $codedstr . $str;
|
||||
|
||||
if (defined $code) {
|
||||
$str .= "<syntaxhighlight lang='$codelang'>$code<\/syntaxhighlight>";
|
||||
}
|
||||
@@ -261,6 +270,7 @@ usage() if not defined $wikipath;
|
||||
my @standard_wiki_sections = (
|
||||
'Draft',
|
||||
'[Brief]',
|
||||
'Deprecated',
|
||||
'Syntax',
|
||||
'Function Parameters',
|
||||
'Return Value',
|
||||
@@ -283,6 +293,7 @@ my %headerfuncs = (); # $headerfuncs{"SDL_OpenAudio"} -> string of header docu
|
||||
my %headerdecls = ();
|
||||
my %headerfuncslocation = (); # $headerfuncslocation{"SDL_OpenAudio"} -> name of header holding SDL_OpenAudio define ("SDL_audio.h" in this case).
|
||||
my %headerfuncschunk = (); # $headerfuncschunk{"SDL_OpenAudio"} -> offset in array in %headers that should be replaced for this function.
|
||||
my %headerfuncshasdoxygen = (); # $headerfuncschunk{"SDL_OpenAudio"} -> 1 if there was no existing doxygen for this function.
|
||||
|
||||
my $incpath = "$srcpath/include";
|
||||
opendir(DH, $incpath) or die("Can't opendir '$incpath': $!\n");
|
||||
@@ -295,46 +306,54 @@ while (readdir(DH)) {
|
||||
|
||||
while (<FH>) {
|
||||
chomp;
|
||||
if (not /\A\/\*\*\s*\Z/) { # not doxygen comment start?
|
||||
my $decl;
|
||||
my @templines;
|
||||
my $str;
|
||||
my $has_doxygen = 1;
|
||||
if (/\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC/) { # a function declaration without a doxygen comment?
|
||||
@templines = ();
|
||||
$decl = $_;
|
||||
$str = '';
|
||||
$has_doxygen = 0;
|
||||
} elsif (not /\A\/\*\*\s*\Z/) { # not doxygen comment start?
|
||||
push @contents, $_;
|
||||
next;
|
||||
}
|
||||
|
||||
my @templines = ();
|
||||
push @templines, $_;
|
||||
my $str = '';
|
||||
while (<FH>) {
|
||||
chomp;
|
||||
push @templines, $_;
|
||||
last if /\A\s*\*\/\Z/;
|
||||
if (s/\A\s*\*\s*\`\`\`/```/) { # this is a hack, but a lot of other code relies on the whitespace being trimmed, but we can't trim it in code blocks...
|
||||
$str .= "$_\n";
|
||||
while (<FH>) {
|
||||
chomp;
|
||||
push @templines, $_;
|
||||
s/\A\s*\*\s?//;
|
||||
if (s/\A\s*\`\`\`/```/) {
|
||||
$str .= "$_\n";
|
||||
last;
|
||||
} else {
|
||||
$str .= "$_\n";
|
||||
} else { # Start of a doxygen comment, parse it out.
|
||||
@templines = ( $_ );
|
||||
while (<FH>) {
|
||||
chomp;
|
||||
push @templines, $_;
|
||||
last if /\A\s*\*\/\Z/;
|
||||
if (s/\A\s*\*\s*\`\`\`/```/) { # this is a hack, but a lot of other code relies on the whitespace being trimmed, but we can't trim it in code blocks...
|
||||
$str .= "$_\n";
|
||||
while (<FH>) {
|
||||
chomp;
|
||||
push @templines, $_;
|
||||
s/\A\s*\*\s?//;
|
||||
if (s/\A\s*\`\`\`/```/) {
|
||||
$str .= "$_\n";
|
||||
last;
|
||||
} else {
|
||||
$str .= "$_\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
s/\A\s*\*\s*//;
|
||||
$str .= "$_\n";
|
||||
}
|
||||
} else {
|
||||
s/\A\s*\*\s*//;
|
||||
$str .= "$_\n";
|
||||
}
|
||||
}
|
||||
|
||||
my $decl = <FH>;
|
||||
chomp($decl);
|
||||
if (not $decl =~ /\A\s*extern\s+DECLSPEC/) {
|
||||
#print "Found doxygen but no function sig:\n$str\n\n";
|
||||
foreach (@templines) {
|
||||
push @contents, $_;
|
||||
$decl = <FH>;
|
||||
$decl = '' if not defined $decl;
|
||||
chomp($decl);
|
||||
if (not $decl =~ /\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC/) {
|
||||
#print "Found doxygen but no function sig:\n$str\n\n";
|
||||
foreach (@templines) {
|
||||
push @contents, $_;
|
||||
}
|
||||
push @contents, $decl;
|
||||
next;
|
||||
}
|
||||
push @contents, $decl;
|
||||
next;
|
||||
}
|
||||
|
||||
my @decllines = ( $decl );
|
||||
@@ -355,8 +374,8 @@ while (readdir(DH)) {
|
||||
#print("DECL: [$decl]\n");
|
||||
|
||||
my $fn = '';
|
||||
if ($decl =~ /\A\s*extern\s+DECLSPEC\s+(const\s+|)(unsigned\s+|)(.*?)\s*(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
|
||||
$fn = $5;
|
||||
if ($decl =~ /\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC\s+(const\s+|)(unsigned\s+|)(.*?)\s*(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
|
||||
$fn = $6;
|
||||
#$decl =~ s/\A\s*extern\s+DECLSPEC\s+(.*?)\s+SDLCALL/$1/;
|
||||
} else {
|
||||
#print "Found doxygen but no function sig:\n$str\n\n";
|
||||
@@ -373,9 +392,10 @@ while (readdir(DH)) {
|
||||
foreach (@decllines) {
|
||||
if ($decl eq '') {
|
||||
$decl = $_;
|
||||
$decl =~ s/\Aextern\s+DECLSPEC\s+(.*?)\s+(\*?)SDLCALL\s+/$1$2 /;
|
||||
$decl =~ s/\Aextern\s+(SDL_DEPRECATED\s+|)DECLSPEC\s+(.*?)\s+(\*?)SDLCALL\s+/$2$3 /;
|
||||
} else {
|
||||
my $trimmed = $_;
|
||||
# !!! FIXME: trim space for SDL_DEPRECATED if it was used, too.
|
||||
$trimmed =~ s/\A\s{24}//; # 24 for shrinking to match the removed "extern DECLSPEC SDLCALL "
|
||||
$decl .= $trimmed;
|
||||
}
|
||||
@@ -384,13 +404,33 @@ while (readdir(DH)) {
|
||||
|
||||
#print("$fn:\n$str\n\n");
|
||||
|
||||
$headerfuncs{$fn} = $str;
|
||||
$headerdecls{$fn} = $decl;
|
||||
$headerfuncslocation{$fn} = $dent;
|
||||
$headerfuncschunk{$fn} = scalar(@contents);
|
||||
# There might be multiple declarations of a function due to #ifdefs,
|
||||
# and only one of them will have documentation. If we hit an
|
||||
# undocumented one before, delete the placeholder line we left for
|
||||
# it so it doesn't accumulate a new blank line on each run.
|
||||
my $skipfn = 0;
|
||||
if (defined $headerfuncshasdoxygen{$fn}) {
|
||||
if ($headerfuncshasdoxygen{$fn} == 0) { # An undocumented declaration already exists, nuke its placeholder line.
|
||||
delete $contents[$headerfuncschunk{$fn}]; # delete DOES NOT RENUMBER existing elements!
|
||||
} else { # documented function already existed?
|
||||
$skipfn = 1; # don't add this copy to the list of functions.
|
||||
if ($has_doxygen) {
|
||||
print STDERR "WARNING: Function '$fn' appears to be documented in multiple locations. Only keeping the first one we saw!\n";
|
||||
}
|
||||
push @contents, join("\n", @decllines); # just put the existing declation in as-is.
|
||||
}
|
||||
}
|
||||
|
||||
if (!$skipfn) {
|
||||
$headerfuncs{$fn} = $str;
|
||||
$headerdecls{$fn} = $decl;
|
||||
$headerfuncslocation{$fn} = $dent;
|
||||
$headerfuncschunk{$fn} = scalar(@contents);
|
||||
$headerfuncshasdoxygen{$fn} = $has_doxygen;
|
||||
push @contents, join("\n", @templines);
|
||||
push @contents, join("\n", @decllines);
|
||||
}
|
||||
|
||||
push @contents, join("\n", @templines);
|
||||
push @contents, join("\n", @decllines);
|
||||
}
|
||||
close(FH);
|
||||
|
||||
@@ -513,7 +553,6 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
|
||||
$wordwrap_mode = 'md'; # the headers use Markdown format.
|
||||
|
||||
# if it's not in the headers already, we don't add it, so iterate what we know is already there for changes.
|
||||
foreach (keys %headerfuncs) {
|
||||
my $fn = $_;
|
||||
next if not defined $wikifuncs{$fn}; # don't have a page for that function, skip it.
|
||||
@@ -524,10 +563,13 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
my $returns = %$sectionsref{'Return Value'};
|
||||
my $version = %$sectionsref{'Version'};
|
||||
my $related = %$sectionsref{'Related Functions'};
|
||||
my $deprecated = %$sectionsref{'Deprecated'};
|
||||
my $brief = %$sectionsref{'[Brief]'};
|
||||
my $addblank = 0;
|
||||
my $str = '';
|
||||
|
||||
$headerfuncshasdoxygen{$fn} = 1; # Added/changed doxygen for this header.
|
||||
|
||||
$brief = dewikify($wikitype, $brief);
|
||||
$brief =~ s/\A(.*?\.) /$1\n/; # \brief should only be one sentence, delimited by a period+space. Split if necessary.
|
||||
my @briefsplit = split /\n/, $brief;
|
||||
@@ -547,6 +589,21 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
$str .= wordwrap($remarks) . "\n";
|
||||
}
|
||||
|
||||
if (defined $deprecated) {
|
||||
# !!! FIXME: lots of code duplication in all of these.
|
||||
$str .= "\n" if $addblank; $addblank = 1;
|
||||
my $v = dewikify($wikitype, $deprecated);
|
||||
my $whitespacelen = length("\\deprecated") + 1;
|
||||
my $whitespace = ' ' x $whitespacelen;
|
||||
$v = wordwrap($v, -$whitespacelen);
|
||||
my @desclines = split /\n/, $v;
|
||||
my $firstline = shift @desclines;
|
||||
$str .= "\\deprecated $firstline\n";
|
||||
foreach (@desclines) {
|
||||
$str .= "${whitespace}$_\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $params) {
|
||||
$str .= "\n" if $addblank; $addblank = (defined $returns) ? 0 : 1;
|
||||
my @lines = split /\n/, dewikify($wikitype, $params);
|
||||
@@ -623,8 +680,15 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
}
|
||||
}
|
||||
|
||||
my $header = $headerfuncslocation{$fn};
|
||||
my $contentsref = $headers{$header};
|
||||
my $chunk = $headerfuncschunk{$fn};
|
||||
|
||||
my @lines = split /\n/, $str;
|
||||
my $output = "/**\n";
|
||||
|
||||
my $addnewline = (($chunk > 0) && ($$contentsref[$chunk-1] ne '')) ? "\n" : '';
|
||||
|
||||
my $output = "$addnewline/**\n";
|
||||
foreach (@lines) {
|
||||
chomp;
|
||||
s/\s*\Z//;
|
||||
@@ -638,9 +702,6 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
|
||||
#print("$fn:\n$output\n\n");
|
||||
|
||||
my $header = $headerfuncslocation{$fn};
|
||||
my $chunk = $headerfuncschunk{$fn};
|
||||
my $contentsref = $headers{$header};
|
||||
$$contentsref[$chunk] = $output;
|
||||
#$$contentsref[$chunk+1] = $headerdecls{$fn};
|
||||
|
||||
@@ -648,19 +709,36 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
}
|
||||
|
||||
foreach (keys %changed_headers) {
|
||||
my $contentsref = $headers{$_};
|
||||
my $path = "$incpath/$_.tmp";
|
||||
my $header = $_;
|
||||
|
||||
# this is kinda inefficient, but oh well.
|
||||
my @removelines = ();
|
||||
foreach (keys %headerfuncslocation) {
|
||||
my $fn = $_;
|
||||
next if $headerfuncshasdoxygen{$fn};
|
||||
next if $headerfuncslocation{$fn} ne $header;
|
||||
# the index of the blank line we put before the function declaration in case we needed to replace it with new content from the wiki.
|
||||
push @removelines, $headerfuncschunk{$fn};
|
||||
}
|
||||
|
||||
my $contentsref = $headers{$header};
|
||||
foreach (@removelines) {
|
||||
delete $$contentsref[$_]; # delete DOES NOT RENUMBER existing elements!
|
||||
}
|
||||
|
||||
my $path = "$incpath/$header.tmp";
|
||||
open(FH, '>', $path) or die("Can't open '$path': $!\n");
|
||||
foreach (@$contentsref) {
|
||||
print FH "$_\n";
|
||||
print FH "$_\n" if defined $_;
|
||||
}
|
||||
close(FH);
|
||||
rename($path, "$incpath/$_") or die("Can't rename '$path' to '$incpath/$_': $!\n");
|
||||
rename($path, "$incpath/$header") or die("Can't rename '$path' to '$incpath/$header': $!\n");
|
||||
}
|
||||
|
||||
} elsif ($copy_direction == -1) { # --copy-to-wiki
|
||||
foreach (keys %headerfuncs) {
|
||||
my $fn = $_;
|
||||
next if not $headerfuncshasdoxygen{$fn};
|
||||
my $wikitype = defined $wikitypes{$fn} ? $wikitypes{$fn} : 'mediawiki'; # default to MediaWiki for new stuff FOR NOW.
|
||||
die("Unexpected wikitype '$wikitype'\n") if (($wikitype ne 'mediawiki') and ($wikitype ne 'md'));
|
||||
|
||||
@@ -669,6 +747,7 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
$wordwrap_mode = $wikitype;
|
||||
|
||||
my $raw = $headerfuncs{$fn}; # raw doxygen text with comment characters stripped from start/end and start of each line.
|
||||
next if not defined $raw;
|
||||
$raw =~ s/\A\s*\\brief\s+//; # Technically we don't need \brief (please turn on JAVADOC_AUTOBRIEF if you use Doxygen), so just in case one is present, strip it.
|
||||
|
||||
my @doxygenlines = split /\n/, $raw;
|
||||
@@ -714,7 +793,7 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
|
||||
my $decl = $headerdecls{$fn};
|
||||
#$decl =~ s/\*\s+SDLCALL/ *SDLCALL/; # Try to make "void * Function" become "void *Function"
|
||||
#$decl =~ s/\A\s*extern\s+DECLSPEC\s+(.*?)\s+(\*?)SDLCALL/$1$2/;
|
||||
#$decl =~ s/\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC\s+(.*?)\s+(\*?)SDLCALL/$2$3/;
|
||||
|
||||
my $syntax = '';
|
||||
if ($wikitype eq 'mediawiki') {
|
||||
@@ -768,6 +847,21 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
}
|
||||
$desc =~ s/[\s\n]+\Z//ms;
|
||||
$sections{'Return Value'} = wordwrap("$retstr " . wikify($wikitype, $desc)) . "\n";
|
||||
} elsif ($l =~ /\A\\deprecated\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.
|
||||
shift @doxygenlines; # dump this line from the array; we're using it.
|
||||
if ($subline eq '') { # empty line, make sure it keeps the newline char.
|
||||
$desc .= "\n";
|
||||
} else {
|
||||
$desc .= " $subline";
|
||||
}
|
||||
}
|
||||
$desc =~ s/[\s\n]+\Z//ms;
|
||||
$sections{'Deprecated'} = wordwrap(wikify($wikitype, $desc)) . "\n";
|
||||
} elsif ($l =~ /\A\\since\s+(.*)\Z/) {
|
||||
my $desc = $1;
|
||||
while (@doxygenlines) {
|
||||
@@ -854,30 +948,57 @@ if ($copy_direction == 1) { # --copy-to-headers
|
||||
}
|
||||
|
||||
my $wikisectionorderref = $wikisectionorder{$fn};
|
||||
my @ordered_sections = (@standard_wiki_sections, defined $wikisectionorderref ? @$wikisectionorderref : ()); # this copies the arrays into one.
|
||||
|
||||
# Make sure there's a footer in the wiki that puts this function in CategoryAPI...
|
||||
if (not $$sectionsref{'[footer]'}) {
|
||||
$$sectionsref{'[footer]'} = '';
|
||||
push @$wikisectionorderref, '[footer]';
|
||||
}
|
||||
|
||||
# !!! FIXME: This won't be CategoryAPI if we eventually handle things other than functions.
|
||||
my $footer = $$sectionsref{'[footer]'};
|
||||
if ($wikitype eq 'mediawiki') {
|
||||
$footer =~ s/\[\[CategoryAPI\]\],?\s*//g;
|
||||
$footer = '[[CategoryAPI]]' . (($footer eq '') ? "\n" : ", $footer");
|
||||
} elsif ($wikitype eq 'md') {
|
||||
$footer =~ s/\[CategoryAPI\]\(CategoryAPI\),?\s*//g;
|
||||
$footer = '[CategoryAPI](CategoryAPI)' . (($footer eq '') ? '' : ', ') . $footer;
|
||||
} else { die("Unexpected wikitype '$wikitype'\n"); }
|
||||
$$sectionsref{'[footer]'} = $footer;
|
||||
|
||||
my $prevsectstr = '';
|
||||
my @ordered_sections = (@standard_wiki_sections, defined $wikisectionorderref ? @$wikisectionorderref : ()); # this copies the arrays into one.
|
||||
foreach (@ordered_sections) {
|
||||
my $sect = $_;
|
||||
next if $sect eq '[start]';
|
||||
next if (not defined $sections{$sect} and not defined $$sectionsref{$sect});
|
||||
my $section = defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
|
||||
if ($sect eq '[footer]') {
|
||||
# Make sure previous section ends with two newlines.
|
||||
if (substr($prevsectstr, -1) ne "\n") {
|
||||
print FH "\n\n";
|
||||
} elsif (substr($prevsectstr, -2) ne "\n\n") {
|
||||
print FH "\n";
|
||||
}
|
||||
print FH "----\n"; # It's the same in Markdown and MediaWiki.
|
||||
} elsif ($sect eq '[Brief]') {
|
||||
if ($wikitype eq 'mediawiki') {
|
||||
print FH "= $fn =\n\n";
|
||||
} elsif ($wikitype eq 'md') {
|
||||
print FH "# $fn\n\n";
|
||||
} else { die("Expected wikitype '$wikitype'\n"); }
|
||||
} else { die("Unexpected wikitype '$wikitype'\n"); }
|
||||
} else {
|
||||
if ($wikitype eq 'mediawiki') {
|
||||
print FH "\n== $sect ==\n\n";
|
||||
} elsif ($wikitype eq 'md') {
|
||||
print FH "\n## $sect\n\n";
|
||||
} else { die("Expected wikitype '$wikitype'\n"); }
|
||||
} else { die("Unexpected wikitype '$wikitype'\n"); }
|
||||
}
|
||||
|
||||
print FH defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
|
||||
my $sectstr = defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
|
||||
print FH $sectstr;
|
||||
|
||||
$prevsectstr = $sectstr;
|
||||
|
||||
# make sure these don't show up twice.
|
||||
delete($sections{$sect});
|
||||
|
Reference in New Issue
Block a user