]> git.pond.sub.org Git - empserver/blob - info/mktop.pl
a9a9eb2e7f7fce2d13f5f85c0cc00e018d713d25
[empserver] / info / mktop.pl
1 #!/usr/bin/perl
2 #
3 #  Empire - A multi-player, client/server Internet based war game.
4 #  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
5 #                           Ken Stevens, Steve McClure
6 #
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.
11 #
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.
16 #
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
20 #
21 #  ---
22 #
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.
26 #
27 #  ---
28 #
29 #  mktop.pl: Create the index of subjects
30 #
31 #  Known contributors to this file:
32 #     Ken Stevens (when it was still info.pl)
33 #     Markus Armbruster, 2006
34 #
35
36 # Usage: mktop.pl OUTFILE SUBJECT-INDEX-FILE...
37 # The SUBJECT-INDEX-FILE... contain all the subject indexes.  Derive
38 # the subjects from the file names, write the index to OUTFILE.  Only
39 # the file names are used, the files aren't accessed.
40
41 my $out = shift @ARGV;
42 my @subject = ();
43 for (@ARGV) {
44     /([^\/]*)\.t$/
45         or die "Strange subject file name";
46     push @subject, $1;
47 }
48 @subject = sort @subject;
49
50 open(TOP, ">$out")
51     or die "Can't open $out: $!";
52 print TOP <<EOF;
53 .\\\" DO NOT EDIT THIS FILE.  It was automatically generated by mktop.pl
54 .TH Info "List of Subjects"
55 .s1
56 Empire info is available on the following subjects:
57 .NF
58 EOF
59
60 # reorder subjects for display in three columns
61 my $k = 0;
62 for my $i (0..2) {
63     for (my $j = $i; $j <= $#subject; $j += 3) {
64         $colsubj[$j] = $subject[$k++];
65     }
66 }
67
68 for my $subj (@colsubj) {
69     push(@subj, $subj);
70     if ($#subj > 1) {
71         flush_subj(@subj);
72         @subj = ();
73     }
74 }
75 flush_subj(@subj);
76 print TOP <<EOF;
77 .FI
78 Type "info <Subject>" where <Subject> is one of the subjects listed above.
79 For a complete list of all info topics, type "info all".
80 EOF
81 close TOP;
82
83 # Print a row of subjects to TOP
84 sub flush_subj {
85     return unless $#_ >= 0;
86     print TOP "  ";
87     for (@_) {
88         printf TOP "%-25s", $_;
89     }
90     print TOP "\n";
91 }