]> git.pond.sub.org Git - empserver/commitdiff
Simplify how mksubj.pl keeps track of the subjects' topics
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 28 Apr 2013 15:45:05 +0000 (17:45 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 8 May 2013 04:57:57 +0000 (06:57 +0200)
Extend global variable %Subjects to hold topics.  Drop global
variables %subject and %largest.

info/mksubj.pl

index 60b5cfdb256c4153a70eaea38586e4441eb08c74..cc4bfbcbcc7969509db1c7b80f60e59c89f8ac2a 100644 (file)
@@ -43,6 +43,9 @@ use File::stat;
 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
@@ -59,15 +62,8 @@ my %level;
 # 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} = [];
 }
 
 for (@ARGV) {
 }
 
 for (@ARGV) {
@@ -91,7 +87,7 @@ sub fn2topic {
 # 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.
+# Update %Subjects.
 sub parse_file {
     ($filename) = @_;
     my $topic = fn2topic($filename);
 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{$_};
     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;
@@ -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
 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) {
            $any_topic = 1;
            $any_topic = 1;
+           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 .= "*";