Skip to content

Commit 55f6084

Browse files
committed
wikiheaders.pl: Try to handle functions with multiple declarations better.
1 parent 3970a88 commit 55f6084

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

build-scripts/wikiheaders.pl

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,33 @@ sub usage {
402402

403403
#print("$fn:\n$str\n\n");
404404

405-
$headerfuncs{$fn} = $str;
406-
$headerdecls{$fn} = $decl;
407-
$headerfuncslocation{$fn} = $dent;
408-
$headerfuncschunk{$fn} = scalar(@contents);
409-
$headerfuncshasdoxygen{$fn} = $has_doxygen;
410-
411-
push @contents, join("\n", @templines);
412-
push @contents, join("\n", @decllines);
405+
# There might be multiple declarations of a function due to #ifdefs,
406+
# and only one of them will have documentation. If we hit an
407+
# undocumented one before, delete the placeholder line we left for
408+
# it so it doesn't accumulate a new blank line on each run.
409+
my $skipfn = 0;
410+
if (defined $headerfuncshasdoxygen{$fn}) {
411+
if ($headerfuncshasdoxygen{$fn} == 0) { # An undocumented declaration already exists, nuke its placeholder line.
412+
delete $contents[$headerfuncschunk{$fn}]; # delete DOES NOT RENUMBER existing elements!
413+
} else { # documented function already existed?
414+
$skipfn = 1; # don't add this copy to the list of functions.
415+
if ($has_doxygen) {
416+
print STDERR "WARNING: Function '$fn' appears to be documented in multiple locations. Only keeping the first one we saw!\n";
417+
}
418+
push @contents, join("\n", @decllines); # just put the existing declation in as-is.
419+
}
420+
}
421+
422+
if (!$skipfn) {
423+
$headerfuncs{$fn} = $str;
424+
$headerdecls{$fn} = $decl;
425+
$headerfuncslocation{$fn} = $dent;
426+
$headerfuncschunk{$fn} = scalar(@contents);
427+
$headerfuncshasdoxygen{$fn} = $has_doxygen;
428+
push @contents, join("\n", @templines);
429+
push @contents, join("\n", @decllines);
430+
}
431+
413432
}
414433
close(FH);
415434

0 commit comments

Comments
 (0)