@@ -737,46 +737,63 @@ sub lines { $_[0]->{lines} }
737
737
sub tidy_embed_fnc_entry {
738
738
my ($self , $line_data )= @_ ;
739
739
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 =~ / \| / ;
743
740
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
747
750
my ($flags , $ret , $name , @args )= split /\s *\|\s */, $line ;
751
+
752
+ # Sort and remove duplicate flags
748
753
my %flag_seen ;
749
- $flags = join " " , grep !$flag_seen {$_ }++, sort split //, $flags ;
754
+ $flags = join " " , grep !$flag_seen {$_ }++, sort split //, $flags ;
750
755
if ($flags =~ s / ^#// ) {
751
756
$flags .= " #" ;
752
757
}
753
- if ($flags eq " #" ) {
758
+
759
+ if ($flags eq " #" ) { # Could be an attempt at a conditional
754
760
die " Not allowed to use only '#' for flags"
755
761
. " in 'embed.fnc' at line $line_data ->{start_line_num}" ;
756
762
}
763
+
757
764
if (!$flags ) {
758
765
die " Missing flags in function definition"
759
766
. " in 'embed.fnc' at line $line_data ->{start_line_num}\n "
760
767
. " Did you a forget a line continuation on the previous line?\n " ;
761
768
}
769
+
770
+ # Normalize the return type and arguments
762
771
for ($ret , @args ) {
763
772
s / (\w )\* / $1 */ g ;
764
773
s /\*\s +(\w )/ *$1 / g ;
765
774
s /\* const/ * const/ g ;
766
775
}
776
+
777
+ # Start the output; right justify
767
778
my $head = sprintf " %-8s|%-7s" , $flags , $ret ;
768
779
$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
769
783
if (@args and length ($head ) > 32) {
770
784
$head .= " \\\n " ;
771
785
$head .= " " x 32 ;
772
786
}
787
+
788
+ # Add each argument on a separate line
773
789
foreach my $ix (0 .. $#args ) {
774
790
my $arg = $args [$ix ];
775
791
$head .= " |$arg " ;
776
792
$head .= " \\\n " . (" " x 32 ) if $ix < $#args ;
777
793
}
778
794
$line = $head . " \n " ;
779
795
796
+ # Make all lines in this entry the same length; minimum 72
780
797
if ($line =~ / \\\n / ) {
781
798
my @lines = split /\s *\\\n/, $line ;
782
799
my $len = length ($lines [0]);
@@ -787,7 +804,8 @@ sub tidy_embed_fnc_entry {
787
804
(map { sprintf " %*s" , -$len , $_ } @lines [ 0 .. $#lines - 1 ]),
788
805
$lines [-1]);
789
806
}
790
- ($line )= unexpand($line );
807
+
808
+ ($line )= unexpand($line ); # Back to using tabs
791
809
792
810
$line_data -> {embed }= EmbedLine-> new(
793
811
flags => $flags ,
@@ -796,6 +814,7 @@ sub tidy_embed_fnc_entry {
796
814
args => \@args ,
797
815
start_line_num => $line_data -> {start_line_num },
798
816
);
817
+
799
818
$line =~ s /\s +\z / \n / ;
800
819
$line_data -> {line }= $line ;
801
820
return $line ;
0 commit comments