Mark long info pages with `!' in subject pages

This commit is contained in:
Markus Armbruster 2011-04-13 19:50:31 +02:00
parent 7c8eef0525
commit 4c0b4c0416

View file

@ -39,25 +39,29 @@
use strict; use strict;
use warnings; use warnings;
use File::stat;
# The chapters, in order # The chapters, in order
our @Chapters = qw/Introduction Concept Command Server/; our @Chapters = qw/Introduction Concept Command Server/;
our $filename; our $filename;
my (%subject, %level, %desc); my (%subject, %level, %desc, %long);
my $largest = ""; my $largest = "";
my $out = shift @ARGV; my $out = shift @ARGV;
$out =~ /([^\/]*)\.t$/ $out =~ /([^\/]*)\.t$/
or die "Strange subject file name $out"; or die "Strange subject file name $out";
my $subj = $1; my $subj = $1;
my $any_long = 0;
for (@ARGV) { for (@ARGV) {
my ($topic, $chap, $lvl, $desc) = parse_file($_); my ($topic, $chap, $lvl, $desc, $long) = parse_file($_);
$largest = $topic if length $topic > length $largest; $largest = $topic if length $topic > length $largest;
$subject{$chap} .= "$topic\n"; $subject{$chap} .= "$topic\n";
$level{$topic} = $lvl; $level{$topic} = $lvl;
$desc{$topic} = $desc; $desc{$topic} = $desc;
$long{$topic} = $long;
$any_long = 1 if $long;
} }
open(SUBJ, ">$out") open(SUBJ, ">$out")
@ -72,12 +76,11 @@ for my $chap (@Chapters) {
next unless exists $subject{$chap}; next unless exists $subject{$chap};
print SUBJ ".s1\n"; print SUBJ ".s1\n";
for (split(/\n/, $subject{$chap})) { for (split(/\n/, $subject{$chap})) {
print SUBJ ".L \"$_ "; my $flags = "";
if ($level{$_} eq 'Basic') { $flags .= "*" if $level{$_} eq 'Basic';
print SUBJ "* \"\n"; $flags .= "!" if $long{$_};
} else { $flags = sprintf("%-2s", $flags);
print SUBJ " \"\n"; print SUBJ ".L \"$_ $flags\"\n";
}
print SUBJ "$desc{$_}\n"; print SUBJ "$desc{$_}\n";
} }
} }
@ -89,16 +92,23 @@ For info on a particular subject, type "info <subject>" where <subject> is
one of the subjects listed above. Subjects marked by * are the most one of the subjects listed above. Subjects marked by * are the most
important and should be read by new players. important and should be read by new players.
EOF EOF
print SUBJ <<EOF if $any_long;
Unusually long subjects are marked with a !.
EOF
close SUBJ; close SUBJ;
sub parse_file { sub parse_file {
($filename) = @_; ($filename) = @_;
my ($topic, $chap, $lvl, $desc); my ($topic, $chap, $lvl, $desc, $long, $st);
$topic = $filename; $topic = $filename;
$topic =~ s,.*/([^/]*)\.t$,$1,; $topic =~ s,.*/([^/]*)\.t$,$1,;
$st = stat $filename
or die "Can't stat $filename: $!";
$long = $st->size > 9999;
open(F, "<$filename") open(F, "<$filename")
or die "Can't open $filename: $!"; or die "Can't open $filename: $!";
@ -137,7 +147,7 @@ sub parse_file {
close F; close F;
return ($topic, $chap, $lvl, $desc); return ($topic, $chap, $lvl, $desc, $long);
} }
# Print an integrity error message and exit with code 1 # Print an integrity error message and exit with code 1