Simplify how mksubj.pl keeps track of the subjects' topics

Extend global variable %Subjects to hold topics.  Drop global
variables %subject and %largest.
This commit is contained in:
Markus Armbruster 2013-04-28 17:45:05 +02:00
parent c8bd8202ce
commit cd4cd8d0f7

View file

@ -43,6 +43,9 @@ use File::stat;
my @Chapters = qw/Introduction Concept Command Server/;
my @Levels = qw/Basic Expert Obsolete/;
# $Subjects{SUBJECT} is a reference to an an anonymous array
# containing SUBJECT's topics
my %Subjects;
# $filename{TOPIC} is TOPIC's file name
@ -59,15 +62,8 @@ my %level;
# current info file
my $filename;
# $subject{$subj}{$chap} = "item1\nitem2\n..."
# Topics in that subject organized by chapter.
my %subject;
# $largest{$sub} The largest topic name in that subject (used for
# column formatting)
my %largest;
while ($#ARGV >= 0 && $ARGV[0] !~ /\.t$/) {
$Subjects{shift @ARGV} = undef;
$Subjects{shift @ARGV} = [];
}
for (@ARGV) {
@ -91,7 +87,7 @@ sub fn2topic {
# Parse an info file
# Set $filename, $long{TOPIC}, $chapter{TOPIC}, $desc{TOPIC},
# $level{TOPIC}.
# Update %subject, %largest.
# Update %Subjects.
sub parse_file {
($filename) = @_;
my $topic = fn2topic($filename);
@ -168,7 +164,7 @@ sub parse_see_also {
for (split(/, /, $sa)) {
next if exists $filename{$_};
error("Unknown topic $_ in .SA") unless exists $Subjects{$_};
set_subject($_, $topic);
push @{$Subjects{$_}}, $topic;
$found = 1;
if ($wanted && $_ eq $wanted) {
$wanted = undef;
@ -179,31 +175,31 @@ sub parse_see_also {
error("Chapter $wanted not listed in .SA") if $wanted;
}
# Add a new entry to %subject and possibly to %largest
sub set_subject {
my ($sub, $topic) = @_;
my $chap = $chapter{$topic};
$subject{$sub}{$chap} .= "$topic\n";
$largest{$sub} = "" unless defined $largest{$_};
$largest{$sub} = $topic if length $topic > length $largest{$sub};
}
# Update a Subject.t file
sub update_subj {
my ($subj) = @_;
my $fname = "info/$subj.t";
my @topics = @{$Subjects{$subj}};
my $out = "";
my ($any_topic, $any_basic, $any_obsolete, $any_long);
my $largest = "";
for my $topic (@topics) {
$largest = $topic if length $topic > length $largest;
}
$out .= '.\" DO NOT EDIT THIS FILE. It was automatically generated by mksubj.pl'."\n";
$out .= ".TH Subject \U$subj\n";
$largest{$subj} =~ s/-/M/g;
$out .= ".in \\w'$largest{$subj}XX\\0\\0\\0\\0'u\n";
$largest =~ s/-/M/g;
$out .= ".in \\w'$largest" . "XX\\0\\0\\0\\0'u\n";
for my $chap (@Chapters) {
next unless exists $subject{$subj}{$chap};
$out .= ".s1\n";
for my $topic (split(/\n/, $subject{$subj}{$chap})) {
my $empty = 1;
for my $topic (@topics) {
$any_topic = 1;
next if $chapter{$topic} ne $chap;
$out .= ".s1\n" if $empty;
$empty = 0;
my $flags = "";
if ($level{$topic} eq 'Basic') {
$flags .= "*";