InfoUtils.pm: Make menu building more robust. Handle depth 5. Minor changes for clarity.

* Simplify menu info gathering and make it more robust.
* Handle depth 5. I still do not like how the result look.
* Send debugging info to STDERR.
* New 'orig' field.
* Minor changes for clarity.
parent 4f5940fa
...@@ -113,7 +113,6 @@ sub info_parse_raw_file { ...@@ -113,7 +113,6 @@ sub info_parse_raw_file {
'menu' => []} 'menu' => []}
); );
my %menu = ();
my %levellast = (0 => "Top"); my %levellast = (0 => "Top");
my %labels = (); my %labels = ();
my %docdata = # Some misc data for the document my %docdata = # Some misc data for the document
...@@ -132,20 +131,15 @@ sub info_parse_raw_file { ...@@ -132,20 +131,15 @@ sub info_parse_raw_file {
while (<$INPUT>){ while (<$INPUT>){
chomp; chomp;
if ( s/^\@SUB\s+// ){ if ( s/^\@SUB\s+// ){
my $updepth = $depth; my $updepth = $depth;
my $uppernode = $levellast{$updepth};
$depth++; $depth++;
$sort++; $sort++;
my @levelmenu = (); my @levelmenu = ();
if ( $lastdepth > $depth ){ if ( defined $nodedata{$uppernode}->{'menu'} ){
$nodedata{$levellast{$depth}}->{'menu'} = $menu{$depth}; @levelmenu = @{ $nodedata{$uppernode}->{'menu'} };
delete $menu{$depth};
@levelmenu = ();
}
if ( defined $menu{$updepth} ){
@levelmenu = @{ $menu{$updepth} };
} }
my $nodetext = info_normalize_node_text($_); my $nodetext = info_normalize_node_text($_);
...@@ -155,16 +149,17 @@ sub info_parse_raw_file { ...@@ -155,16 +149,17 @@ sub info_parse_raw_file {
$nodedata{'Top'}->{'next'} = $nodename if ( $lastdepth eq 0); $nodedata{'Top'}->{'next'} = $nodename if ( $lastdepth eq 0);
# Fill info for current node (and 'next' for last one in level) # Fill info for current node (and 'next' for last one in level)
$nodedata{$nodename}->{'orig'} = $_;
$nodedata{$nodename}->{'text'} = $nodetext; $nodedata{$nodename}->{'text'} = $nodetext;
$nodedata{$nodename}->{'depth'} = $depth; $nodedata{$nodename}->{'depth'} = $depth;
$nodedata{$nodename}->{'previous'} = $nodedata{$nodename}->{'previous'} =
defined $levellast{$depth} ? $levellast{$depth} : ""; defined $levellast{$depth} ? $levellast{$depth} : "";
$nodedata{$levellast{$depth}}->{'next'} = $nodename $nodedata{$levellast{$depth}}->{'next'} = $nodename
if defined $levellast{$depth}; if defined $levellast{$depth};
$nodedata{$nodename}->{'up'} = $levellast{$updepth}; $nodedata{$nodename}->{'up'} = $uppernode;
$nodedata{$nodename}->{'sort'} = $sort; $nodedata{$nodename}->{'sort'} = $sort;
$nodedata{$nodename}->{'debug'} = $nodedata{$nodename}->{'debug'} =
"updepth: $updepth, lastdepth: $lastdepth, up: $levellast{$updepth}"; "updepth: $updepth, lastdepth: $lastdepth, up: $uppernode";
# Keep this defined in case tbere is no next node in the same level. # Keep this defined in case tbere is no next node in the same level.
$nodedata{$nodename}->{'next'} = ""; $nodedata{$nodename}->{'next'} = "";
...@@ -175,7 +170,7 @@ sub info_parse_raw_file { ...@@ -175,7 +170,7 @@ sub info_parse_raw_file {
# Prepare things for next @SUB entry found # Prepare things for next @SUB entry found
$levellast{$depth} = $lastnode = $nodename; $levellast{$depth} = $lastnode = $nodename;
$lastdepth = $depth; $lastdepth = $depth;
$menu{$updepth} = \@levelmenu; $nodedata{$uppernode}->{'menu'} = \@levelmenu;
} elsif ( s/^\@ENDSUB// ){ } elsif ( s/^\@ENDSUB// ){
$depth--; $depth--;
...@@ -195,11 +190,6 @@ sub info_parse_raw_file { ...@@ -195,11 +190,6 @@ sub info_parse_raw_file {
} }
close $INPUT; close $INPUT;
# Flush pending menus
foreach (0..5){
$nodedata{$levellast{$_}}->{'menu'} = $menu{$_} if defined $menu{$_};
}
$docdata{'nodedata'} = \%nodedata; $docdata{'nodedata'} = \%nodedata;
$docdata{'labels'} = \%labels; $docdata{'labels'} = \%labels;
$docdata{'inputtext'} = \@inputtext; $docdata{'inputtext'} = \@inputtext;
...@@ -226,7 +216,7 @@ sub info_write_preprocessed_file { ...@@ -226,7 +216,7 @@ sub info_write_preprocessed_file {
my $OUTFILE; my $OUTFILE;
# check_parsed_data($nodedata); # info_check_parsed_data($nodedata);
my %sections = ( 1 => "\@chapter", my %sections = ( 1 => "\@chapter",
2 => "\@section", 2 => "\@section",
...@@ -266,8 +256,10 @@ sub info_write_preprocessed_file { ...@@ -266,8 +256,10 @@ sub info_write_preprocessed_file {
$texinfo .= $txt; $texinfo .= $txt;
$lastdepth = $depth; $lastdepth = $depth;
$lastnode = $key; $lastnode = $key;
} elsif ( $depth eq 5 ){
$texinfo .= "** $key\n";
} else { } else {
die "info-postASP:$key has wrong depth $depth\n"; die "info-postASP: Entry \"$key\" has wrong depth $depth\n";
} }
} elsif (s/^\@REF\s+//){ } elsif (s/^\@REF\s+//){
if ( defined $labels->{$_} ){ if ( defined $labels->{$_} ){
...@@ -305,15 +297,16 @@ sub info_check_parsed_data { ...@@ -305,15 +297,16 @@ sub info_check_parsed_data {
foreach ( @sections ){ foreach ( @sections ){
my $ref = $tmpnodedata->{$_}; my $ref = $tmpnodedata->{$_};
print "$_\n"; print STDERR "Node: $_\n";
print " text: $ref->{'text'}\n"; print STDERR " orig: $ref->{'orig'}\n";
print " debug: $ref->{'debug'}\n"; print STDERR " text: $ref->{'text'}\n";
print " up: $ref->{'up'}\n"; print STDERR " debug: $ref->{'debug'}\n";
print " depth: $ref->{'depth'}\n"; print STDERR " up: $ref->{'up'}\n";
print " previous: $ref->{'previous'}\n"; print STDERR " depth: $ref->{'depth'}\n";
print " next: $ref->{'next'}\n"; print STDERR " previous: $ref->{'previous'}\n";
print " sort: $ref->{'sort'}\n"; print STDERR " next: $ref->{'next'}\n";
print " menu:\n * " . join("\n * ",@{$ref->{'menu'}}) . "\n" if defined $ref->{'menu'}; print STDERR " sort: $ref->{'sort'}\n";
print STDERR " menu:\n * " . join("\n * ",@{$ref->{'menu'}}) . "\n" if defined $ref->{'menu'};
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment