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:
parent
c8bd8202ce
commit
cd4cd8d0f7
1 changed files with 20 additions and 24 deletions
|
@ -43,6 +43,9 @@ use File::stat;
|
||||||
my @Chapters = qw/Introduction Concept Command Server/;
|
my @Chapters = qw/Introduction Concept Command Server/;
|
||||||
|
|
||||||
my @Levels = qw/Basic Expert Obsolete/;
|
my @Levels = qw/Basic Expert Obsolete/;
|
||||||
|
|
||||||
|
# $Subjects{SUBJECT} is a reference to an an anonymous array
|
||||||
|
# containing SUBJECT's topics
|
||||||
my %Subjects;
|
my %Subjects;
|
||||||
|
|
||||||
# $filename{TOPIC} is TOPIC's file name
|
# $filename{TOPIC} is TOPIC's file name
|
||||||
|
@ -59,15 +62,8 @@ my %level;
|
||||||
# current info file
|
# current info file
|
||||||
my $filename;
|
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} = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (@ARGV) {
|
for (@ARGV) {
|
||||||
|
@ -91,7 +87,7 @@ sub fn2topic {
|
||||||
# Parse an info file
|
# Parse an info file
|
||||||
# Set $filename, $long{TOPIC}, $chapter{TOPIC}, $desc{TOPIC},
|
# Set $filename, $long{TOPIC}, $chapter{TOPIC}, $desc{TOPIC},
|
||||||
# $level{TOPIC}.
|
# $level{TOPIC}.
|
||||||
# Update %subject, %largest.
|
# Update %Subjects.
|
||||||
sub parse_file {
|
sub parse_file {
|
||||||
($filename) = @_;
|
($filename) = @_;
|
||||||
my $topic = fn2topic($filename);
|
my $topic = fn2topic($filename);
|
||||||
|
@ -168,7 +164,7 @@ sub parse_see_also {
|
||||||
for (split(/, /, $sa)) {
|
for (split(/, /, $sa)) {
|
||||||
next if exists $filename{$_};
|
next if exists $filename{$_};
|
||||||
error("Unknown topic $_ in .SA") unless exists $Subjects{$_};
|
error("Unknown topic $_ in .SA") unless exists $Subjects{$_};
|
||||||
set_subject($_, $topic);
|
push @{$Subjects{$_}}, $topic;
|
||||||
$found = 1;
|
$found = 1;
|
||||||
if ($wanted && $_ eq $wanted) {
|
if ($wanted && $_ eq $wanted) {
|
||||||
$wanted = undef;
|
$wanted = undef;
|
||||||
|
@ -179,31 +175,31 @@ sub parse_see_also {
|
||||||
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
|
# Update a Subject.t file
|
||||||
sub update_subj {
|
sub update_subj {
|
||||||
my ($subj) = @_;
|
my ($subj) = @_;
|
||||||
my $fname = "info/$subj.t";
|
my $fname = "info/$subj.t";
|
||||||
|
my @topics = @{$Subjects{$subj}};
|
||||||
my $out = "";
|
my $out = "";
|
||||||
my ($any_topic, $any_basic, $any_obsolete, $any_long);
|
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 .= '.\" DO NOT EDIT THIS FILE. It was automatically generated by mksubj.pl'."\n";
|
||||||
$out .= ".TH Subject \U$subj\n";
|
$out .= ".TH Subject \U$subj\n";
|
||||||
$largest{$subj} =~ s/-/M/g;
|
$largest =~ s/-/M/g;
|
||||||
$out .= ".in \\w'$largest{$subj}XX\\0\\0\\0\\0'u\n";
|
$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};
|
my $empty = 1;
|
||||||
$out .= ".s1\n";
|
for my $topic (@topics) {
|
||||||
for my $topic (split(/\n/, $subject{$subj}{$chap})) {
|
|
||||||
$any_topic = 1;
|
$any_topic = 1;
|
||||||
|
next if $chapter{$topic} ne $chap;
|
||||||
|
$out .= ".s1\n" if $empty;
|
||||||
|
$empty = 0;
|
||||||
my $flags = "";
|
my $flags = "";
|
||||||
if ($level{$topic} eq 'Basic') {
|
if ($level{$topic} eq 'Basic') {
|
||||||
$flags .= "*";
|
$flags .= "*";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue