wikiheaders: Allow blank lines in post-typedef #define blocks.

Reference Issue #9557.
This commit is contained in:
Ryan C. Gordon 2024-04-25 14:26:49 -04:00
parent ac5a61cd60
commit d29b861a76
No known key found for this signature in database
GPG key ID: FA148B892AB48044
4 changed files with 28 additions and 7 deletions

View file

@ -859,20 +859,33 @@ while (my $d = readdir(DH)) {
next;
}
# We assume any `#define`s directly after the typedef are related to it: probably bitflags for an integer typedef. Even a blank line will signify an end!
# We assume any `#define`s directly after the typedef are related to it: probably bitflags for an integer typedef.
# Blank lines are allowed, anything else, even comments, are not.
my $blank_lines = 0;
my $lastpos = tell(FH);
my $additional_decl = '';
while (<FH>) {
chomp;
if (not /\A\s*\#define\s+/) {
seek(FH, $lastpos, 0); # re-read this line again next time.
if (/\A\s*\Z/) {
$blank_lines++;
} elsif (/\A\s*\#define\s+/) {
if ($blank_lines > 0) {
while ($blank_lines > 0) {
$additional_decl .= "\n";
push @decllines, '';
$blank_lines--;
}
}
$additional_decl .= "\n$_";
push @decllines, $_;
$lastpos = tell(FH);
} else {
seek(FH, $lastpos, 0); # re-read eaten lines again next time.
last;
}
$additional_decl .= "$_\n";
push @decllines, $_;
$lastpos = tell(FH);
}
$decl .= "\n$additional_decl" if ($additional_decl ne '');
$decl .= $additional_decl;
} else {
die("Unexpected symtype $symtype");
}