Skip to content

Commit d57bf9d

Browse files
committed
regen/HeaderParser.pm: Add comments; white-space
1 parent a281942 commit d57bf9d

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

regen/HeaderParser.pm

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -737,46 +737,63 @@ sub lines { $_[0]->{lines} }
737737
sub tidy_embed_fnc_entry {
738738
my ($self, $line_data)= @_;
739739
my $line= $line_data->{line};
740-
return $line if $line =~ /^\s*:/;
741-
return $line unless $line_data->{type} eq "content";
742-
return $line unless $line =~ /\|/;
743740

744-
$line =~ s/\s*\\\n/ /g;
745-
$line =~ s/\s+\z//;
746-
($line)= expand($line);
741+
return $line if $line =~ /^\s*:/; # Don't tidy comments
742+
return $line unless $line_data->{type} eq "content"; # Nor #if-like
743+
return $line unless $line =~ /\|/; # Nor non-entries
744+
745+
$line =~ s/\s*\\\n/ /g; # Embedded \n to blank
746+
$line =~ s/\s+\z//; # No trailing white space
747+
($line)= expand($line); # No tabs
748+
749+
# Split into fields
747750
my ($flags, $ret, $name, @args)= split /\s*\|\s*/, $line;
751+
752+
# Sort and remove duplicate flags
748753
my %flag_seen;
749-
$flags= join "", grep !$flag_seen{$_}++, sort split //, $flags;
754+
$flags = join "", grep !$flag_seen{$_}++, sort split //, $flags;
750755
if ($flags =~ s/^#//) {
751756
$flags .= "#";
752757
}
753-
if ($flags eq "#") {
758+
759+
if ($flags eq "#") { # Could be an attempt at a conditional
754760
die "Not allowed to use only '#' for flags"
755761
. "in 'embed.fnc' at line $line_data->{start_line_num}";
756762
}
763+
757764
if (!$flags) {
758765
die "Missing flags in function definition"
759766
. " in 'embed.fnc' at line $line_data->{start_line_num}\n"
760767
. "Did you a forget a line continuation on the previous line?\n";
761768
}
769+
770+
# Normalize the return type and arguments
762771
for ($ret, @args) {
763772
s/(\w)\*/$1 */g;
764773
s/\*\s+(\w)/*$1/g;
765774
s/\*const/* const/g;
766775
}
776+
777+
# Start the output; right justify
767778
my $head= sprintf "%-8s|%-7s", $flags, $ret;
768779
$head .= sprintf "|%*s", -(31 - length($head)), $name;
780+
781+
# Start first argument on next line if $head already extends too far to
782+
# the right
769783
if (@args and length($head) > 32) {
770784
$head .= "\\\n";
771785
$head .= " " x 32;
772786
}
787+
788+
# Add each argument on a separate line
773789
foreach my $ix (0 .. $#args) {
774790
my $arg= $args[$ix];
775791
$head .= "|$arg";
776792
$head .= "\\\n" . (" " x 32) if $ix < $#args;
777793
}
778794
$line= $head . "\n";
779795

796+
# Make all lines in this entry the same length; minimum 72
780797
if ($line =~ /\\\n/) {
781798
my @lines= split /\s*\\\n/, $line;
782799
my $len= length($lines[0]);
@@ -787,7 +804,8 @@ sub tidy_embed_fnc_entry {
787804
(map { sprintf "%*s", -$len, $_ } @lines[ 0 .. $#lines - 1 ]),
788805
$lines[-1]);
789806
}
790-
($line)= unexpand($line);
807+
808+
($line)= unexpand($line); # Back to using tabs
791809

792810
$line_data->{embed}= EmbedLine->new(
793811
flags => $flags,
@@ -796,6 +814,7 @@ sub tidy_embed_fnc_entry {
796814
args => \@args,
797815
start_line_num => $line_data->{start_line_num},
798816
);
817+
799818
$line =~ s/\s+\z/\n/;
800819
$line_data->{line}= $line;
801820
return $line;

0 commit comments

Comments
 (0)