Skip to content

Commit 3970a88

Browse files
committed
wikiheaders.pl: Migrate in docs that exist only in the wiki.
This is going to expose some docs that needs cleaning up once the bridge imports those docs, though.
1 parent 194657a commit 3970a88

File tree

1 file changed

+75
-42
lines changed

1 file changed

+75
-42
lines changed

build-scripts/wikiheaders.pl

Lines changed: 75 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ sub usage {
292292
my %headerdecls = ();
293293
my %headerfuncslocation = (); # $headerfuncslocation{"SDL_OpenAudio"} -> name of header holding SDL_OpenAudio define ("SDL_audio.h" in this case).
294294
my %headerfuncschunk = (); # $headerfuncschunk{"SDL_OpenAudio"} -> offset in array in %headers that should be replaced for this function.
295+
my %headerfuncshasdoxygen = (); # $headerfuncschunk{"SDL_OpenAudio"} -> 1 if there was no existing doxygen for this function.
295296

296297
my $incpath = "$srcpath/include";
297298
opendir(DH, $incpath) or die("Can't opendir '$incpath': $!\n");
@@ -304,46 +305,54 @@ sub usage {
304305

305306
while (<FH>) {
306307
chomp;
307-
if (not /\A\/\*\*\s*\Z/) { # not doxygen comment start?
308+
my $decl;
309+
my @templines;
310+
my $str;
311+
my $has_doxygen = 1;
312+
if (/\A\s*extern\s+DECLSPEC/) { # a function declaration without a doxygen comment?
313+
@templines = ();
314+
$decl = $_;
315+
$str = '';
316+
$has_doxygen = 0;
317+
} elsif (not /\A\/\*\*\s*\Z/) { # not doxygen comment start?
308318
push @contents, $_;
309319
next;
310-
}
311-
312-
my @templines = ();
313-
push @templines, $_;
314-
my $str = '';
315-
while (<FH>) {
316-
chomp;
317-
push @templines, $_;
318-
last if /\A\s*\*\/\Z/;
319-
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...
320-
$str .= "$_\n";
321-
while (<FH>) {
322-
chomp;
323-
push @templines, $_;
324-
s/\A\s*\*\s?//;
325-
if (s/\A\s*\`\`\`/```/) {
326-
$str .= "$_\n";
327-
last;
328-
} else {
329-
$str .= "$_\n";
320+
} else { # Start of a doxygen comment, parse it out.
321+
@templines = ( $_ );
322+
while (<FH>) {
323+
chomp;
324+
push @templines, $_;
325+
last if /\A\s*\*\/\Z/;
326+
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...
327+
$str .= "$_\n";
328+
while (<FH>) {
329+
chomp;
330+
push @templines, $_;
331+
s/\A\s*\*\s?//;
332+
if (s/\A\s*\`\`\`/```/) {
333+
$str .= "$_\n";
334+
last;
335+
} else {
336+
$str .= "$_\n";
337+
}
330338
}
339+
} else {
340+
s/\A\s*\*\s*//;
341+
$str .= "$_\n";
331342
}
332-
} else {
333-
s/\A\s*\*\s*//;
334-
$str .= "$_\n";
335343
}
336-
}
337344

338-
my $decl = <FH>;
339-
chomp($decl);
340-
if (not $decl =~ /\A\s*extern\s+DECLSPEC/) {
341-
#print "Found doxygen but no function sig:\n$str\n\n";
342-
foreach (@templines) {
343-
push @contents, $_;
345+
$decl = <FH>;
346+
$decl = '' if not defined $decl;
347+
chomp($decl);
348+
if (not $decl =~ /\A\s*extern\s+DECLSPEC/) {
349+
#print "Found doxygen but no function sig:\n$str\n\n";
350+
foreach (@templines) {
351+
push @contents, $_;
352+
}
353+
push @contents, $decl;
354+
next;
344355
}
345-
push @contents, $decl;
346-
next;
347356
}
348357

349358
my @decllines = ( $decl );
@@ -397,6 +406,7 @@ sub usage {
397406
$headerdecls{$fn} = $decl;
398407
$headerfuncslocation{$fn} = $dent;
399408
$headerfuncschunk{$fn} = scalar(@contents);
409+
$headerfuncshasdoxygen{$fn} = $has_doxygen;
400410

401411
push @contents, join("\n", @templines);
402412
push @contents, join("\n", @decllines);
@@ -522,7 +532,6 @@ sub usage {
522532

523533
$wordwrap_mode = 'md'; # the headers use Markdown format.
524534

525-
# if it's not in the headers already, we don't add it, so iterate what we know is already there for changes.
526535
foreach (keys %headerfuncs) {
527536
my $fn = $_;
528537
next if not defined $wikifuncs{$fn}; # don't have a page for that function, skip it.
@@ -537,6 +546,8 @@ sub usage {
537546
my $addblank = 0;
538547
my $str = '';
539548

549+
$headerfuncshasdoxygen{$fn} = 1; # Added/changed doxygen for this header.
550+
540551
$brief = dewikify($wikitype, $brief);
541552
$brief =~ s/\A(.*?\.) /$1\n/; # \brief should only be one sentence, delimited by a period+space. Split if necessary.
542553
my @briefsplit = split /\n/, $brief;
@@ -632,8 +643,15 @@ sub usage {
632643
}
633644
}
634645

646+
my $header = $headerfuncslocation{$fn};
647+
my $contentsref = $headers{$header};
648+
my $chunk = $headerfuncschunk{$fn};
649+
635650
my @lines = split /\n/, $str;
636-
my $output = "/**\n";
651+
652+
my $addnewline = (($chunk > 0) && ($$contentsref[$chunk-1] ne '')) ? "\n" : '';
653+
654+
my $output = "$addnewline/**\n";
637655
foreach (@lines) {
638656
chomp;
639657
s/\s*\Z//;
@@ -647,29 +665,43 @@ sub usage {
647665

648666
#print("$fn:\n$output\n\n");
649667

650-
my $header = $headerfuncslocation{$fn};
651-
my $chunk = $headerfuncschunk{$fn};
652-
my $contentsref = $headers{$header};
653668
$$contentsref[$chunk] = $output;
654669
#$$contentsref[$chunk+1] = $headerdecls{$fn};
655670

656671
$changed_headers{$header} = 1;
657672
}
658673

659674
foreach (keys %changed_headers) {
660-
my $contentsref = $headers{$_};
661-
my $path = "$incpath/$_.tmp";
675+
my $header = $_;
676+
677+
# this is kinda inefficient, but oh well.
678+
my @removelines = ();
679+
foreach (keys %headerfuncslocation) {
680+
my $fn = $_;
681+
next if $headerfuncshasdoxygen{$fn};
682+
next if $headerfuncslocation{$fn} ne $header;
683+
# 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.
684+
push @removelines, $headerfuncschunk{$fn};
685+
}
686+
687+
my $contentsref = $headers{$header};
688+
foreach (@removelines) {
689+
delete $$contentsref[$_]; # delete DOES NOT RENUMBER existing elements!
690+
}
691+
692+
my $path = "$incpath/$header.tmp";
662693
open(FH, '>', $path) or die("Can't open '$path': $!\n");
663694
foreach (@$contentsref) {
664-
print FH "$_\n";
695+
print FH "$_\n" if defined $_;
665696
}
666697
close(FH);
667-
rename($path, "$incpath/$_") or die("Can't rename '$path' to '$incpath/$_': $!\n");
698+
rename($path, "$incpath/$header") or die("Can't rename '$path' to '$incpath/$header': $!\n");
668699
}
669700

670701
} elsif ($copy_direction == -1) { # --copy-to-wiki
671702
foreach (keys %headerfuncs) {
672703
my $fn = $_;
704+
next if not $headerfuncshasdoxygen{$fn};
673705
my $wikitype = defined $wikitypes{$fn} ? $wikitypes{$fn} : 'mediawiki'; # default to MediaWiki for new stuff FOR NOW.
674706
die("Unexpected wikitype '$wikitype'\n") if (($wikitype ne 'mediawiki') and ($wikitype ne 'md'));
675707

@@ -678,6 +710,7 @@ sub usage {
678710
$wordwrap_mode = $wikitype;
679711

680712
my $raw = $headerfuncs{$fn}; # raw doxygen text with comment characters stripped from start/end and start of each line.
713+
next if not defined $raw;
681714
$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.
682715

683716
my @doxygenlines = split /\n/, $raw;

0 commit comments

Comments
 (0)