Extend global variable %Subjects to hold topics. Drop global
variables %subject and %largest.
my @Chapters = qw/Introduction Concept Command Server/;
my @Levels = qw/Basic Expert Obsolete/;
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
my %Subjects;
# $filename{TOPIC} is TOPIC's file name
# current info file
my $filename;
# 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$/) {
while ($#ARGV >= 0 && $ARGV[0] !~ /\.t$/) {
- $Subjects{shift @ARGV} = undef;
+ $Subjects{shift @ARGV} = [];
# Parse an info file
# Set $filename, $long{TOPIC}, $chapter{TOPIC}, $desc{TOPIC},
# $level{TOPIC}.
# Parse an info file
# Set $filename, $long{TOPIC}, $chapter{TOPIC}, $desc{TOPIC},
# $level{TOPIC}.
-# Update %subject, %largest.
sub parse_file {
($filename) = @_;
my $topic = fn2topic($filename);
sub parse_file {
($filename) = @_;
my $topic = fn2topic($filename);
for (split(/, /, $sa)) {
next if exists $filename{$_};
error("Unknown topic $_ in .SA") unless exists $Subjects{$_};
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;
$found = 1;
if ($wanted && $_ eq $wanted) {
$wanted = undef;
error("Chapter $wanted not listed in .SA") if $wanted;
}
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";
# 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 $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";
$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) {
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) {
+ next if $chapter{$topic} ne $chap;
+ $out .= ".s1\n" if $empty;
+ $empty = 0;
my $flags = "";
if ($level{$topic} eq 'Basic') {
$flags .= "*";
my $flags = "";
if ($level{$topic} eq 'Basic') {
$flags .= "*";