Simplify how mksubj.pl parses argument of .SA

Call parse_see_also() immediately.  Permits eliminating global
variables %see_also and %sanr.
This commit is contained in:
Markus Armbruster 2013-04-28 17:05:10 +02:00
parent 156930c515
commit c8bd8202ce

View file

@ -55,10 +55,6 @@ my %chapter;
my %desc; my %desc;
# $level{TOPIC} is TOPIC's difficulty level (arg to .LV) # $level{TOPIC} is TOPIC's difficulty level (arg to .LV)
my %level; my %level;
# $see_also{TOPIC} is TOPIC's list of SEE ALSO items (.SA argument)
my %see_also;
# $sanr{TOPIC} is the line number of TOPIC's .SA request
my %sanr;
# current info file # current info file
my $filename; my $filename;
@ -75,27 +71,31 @@ while ($#ARGV >= 0 && $ARGV[0] !~ /\.t$/) {
} }
for (@ARGV) { for (@ARGV) {
parse_file($_); $filename{fn2topic($_)} = $_;
} }
for my $t (sort keys %desc) { for (@ARGV) {
parse_see_also($t); parse_file($_);
} }
for (keys %Subjects) { for (keys %Subjects) {
update_subj($_); update_subj($_);
} }
sub fn2topic {
my ($fn) = @_;
$fn =~ s,.*/([^/]*)\.t$,$1,;
return $fn;
}
# Parse an info file # Parse an info file
# Set $filename, $filename{TOPIC}, $long{TOPIC}, $chapter{TOPIC}, # Set $filename, $long{TOPIC}, $chapter{TOPIC}, $desc{TOPIC},
# $desc{TOPIC}, $level{TOPIC}, $see_also{TOPIC}, $sanr{TOPIC} # $level{TOPIC}.
# Update %subject, %largest.
sub parse_file { sub parse_file {
($filename) = @_; ($filename) = @_;
my ($topic, $st); my $topic = fn2topic($filename);
my $st;
$topic = $filename;
$topic =~ s,.*/([^/]*)\.t$,$1,;
$filename{$topic} = $filename;
$st = stat $filename $st = stat $filename
or die "Can't stat $filename: $!"; or die "Can't stat $filename: $!";
@ -143,8 +143,7 @@ sub parse_file {
if ($_) { if ($_) {
if (/^\.SA "([^\"]*)"/) { if (/^\.SA "([^\"]*)"/) {
$see_also{$topic} = $1; parse_see_also($topic, $1);
$sanr{$topic} = $.;
} else { } else {
error("Incorrect .SA Syntax. Syntax should be '.SA \"item1, item2\"'"); error("Incorrect .SA Syntax. Syntax should be '.SA \"item1, item2\"'");
} }
@ -159,23 +158,18 @@ sub parse_file {
close F; close F;
} }
# Create %subject and %largest from %see_also
sub parse_see_also { sub parse_see_also {
my ($topic) = @_; my ($topic, $sa) = @_;
my @see_also = split(/, /, $see_also{$topic});
my $wanted = $chapter{$topic}; my $wanted = $chapter{$topic};
my $found; # found a subject? my $found; # found a subject?
$wanted = undef if $wanted eq 'Concept' or $wanted eq 'Command'; $wanted = undef if $wanted eq 'Concept' or $wanted eq 'Command';
$filename = $filename{$topic};
$. = $sanr{$topic};
for (@see_also) { for (split(/, /, $sa)) {
if (!exists $desc{$_}) { # is this entry a subject? next if exists $filename{$_};
error("Unknown topic $_ in .SA") unless exists $Subjects{$_}; error("Unknown topic $_ in .SA") unless exists $Subjects{$_};
set_subject($_, $topic); set_subject($_, $topic);
$found = 1; $found = 1;
}
if ($wanted && $_ eq $wanted) { if ($wanted && $_ eq $wanted) {
$wanted = undef; $wanted = undef;
} }