3 # Empire - A multi-player, client/server Internet based war game.
4 # Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
5 # Ken Stevens, Steve McClure
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # See files README, COPYING and CREDITS in the root of the source
24 # tree for related information and legal notices. It is expected
25 # that future projects/authors will amend these files as needed.
29 # mksubj.pl: Create the index for a subject
31 # Known contributors to this file:
32 # Ken Stevens (when it was still info.pl)
33 # Markus Armbruster, 2006
36 # Usage: mksubj.pl OUTFILE INFILE...
37 # The INFILE... contain all the topics belonging to a subject. Read
38 # and check the information required for the index from them, write
39 # the index to OUTFILE.
44 # The chapters, in order
45 our @Chapters = qw/Introduction Concept Command Server/;
48 my (%subject, %level, %desc);
51 my $out = shift @ARGV;
52 $out =~ /([^\/]*)\.t$/
53 or die "Strange subject file name $out";
57 my ($topic, $chap, $lvl, $desc) = parse_file($_);
58 $largest = $topic if length $topic > length $largest;
59 $subject{$chap} .= "$topic\n";
60 $level{$topic} = $lvl;
61 $desc{$topic} = $desc;
65 or die "Can't open $out for writing: $!";
67 print SUBJ '.\" DO NOT EDIT THIS FILE. It was automatically generated by mksubj.pl'."\n";
68 print SUBJ ".TH Subject \U$subj\n";
70 print SUBJ ".in \\w'$largest", "XX\\0\\0\\0\\0'u\n";
72 for my $chap (@Chapters) {
73 next unless exists $subject{$chap};
75 for (split(/\n/, $subject{$chap})) {
76 print SUBJ ".L \"$_ ";
77 if ($level{$_} eq 'Basic') {
82 print SUBJ "$desc{$_}\n";
89 For info on a particular subject, type "info <subject>" where <subject> is
90 one of the subjects listed above. Subjects marked by * are the most
91 important and should be read by new players.
96 # Check .TH, .NA, .LV and .SA.
97 # Parse .NA into %desc and .SA into %see_also
100 my ($topic, $chap, $lvl, $desc);
103 $topic =~ s,.*/([^/]*)\.t$,$1,;
105 open(F, "<$filename")
106 or die "Can't open $filename: $!";
109 if (/^\.TH (\S+) (\S.+\S)$/) {
110 if (!grep(/^$1$/, @Chapters)) {
111 error("First argument to .TH was '$1', which is not a known chapter");
114 if ($1 eq "Command" && $2 ne "\U$topic") {
115 error("Second argument to .TH was '$2' but it should be '\U$topic'");
118 error("The first line in the file must be a .TH request");
122 if (/^\.NA (\S+) "(\S.+\S)"$/) {
124 error("First argument to .NA was '$1' but it should be '$topic'");
128 error("The second line in the file must be a .NA request");
132 if (/^\.LV (\S+)$/) {
133 if ($1 ne 'Basic' && $1 ne 'Expert') {
134 error("The argument to .LV was '$1' but it must be either 'Basic' or 'Expert'");
138 error("The third line in the file must be a .LV request");
143 return ($topic, $chap, $lvl, $desc);
146 # Print an integrity error message and exit with code 1
150 print STDERR "mksubj.pl:$filename:$.: $error\n";