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