~ubuntu-branches/debian/sid/ntp/sid

« back to all changes in this revision

Viewing changes to scripts/html2man.in

  • Committer: Package Import Robot
  • Author(s): Peter Eisentraut
  • Date: 2012-02-27 13:55:56 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20120227135556-dkx4mkod5trl5bgt
Tags: 1:4.2.6.p5+dfsg-1
* New upstream release (closes: #644673)
* Updated instructions on generating autotools.patch
* Updated standards version

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#   name of man page, man section, 'see also' section
21
21
%manfiles = (
22
22
             'ntpd' => ['ntpd', 8, 'ntp.conf(5), ntpq(8), ntpdc(8)'],
23
 
             'ntpq' => ['ntpq', 8, 'ntpd(8), ntpdc(8)'],
 
23
             'ntpq' => ['ntpq', 8, 'ntp_decode(5), ntpd(8), ntpdc(8)'],
24
24
             'ntpdate' => ['ntpdate', 8, 'ntpd(8)'],
25
25
             'ntpdc' => ['ntpdc', 8, 'ntpd(8)'],
26
 
             'ntptime' => ['ntpdtime', 8, 'ntpd(8), ntpdate(8)'],
 
26
             'ntptime' => ['ntptime', 8, 'ntpd(8), ntpdate(8)'],
27
27
             'ntptrace' => ['ntptrace', 8, 'ntpd(8)'],
 
28
             'ntp-wait' => ['ntp-wait', 8, 'ntpd(8)'],
28
29
             'keygen' => ['ntp-keygen', 8, 'ntpd(8), ntp_auth(5)'],
29
 
             'confopt' => ['ntp.conf', 5, 'ntpd(8)'],
 
30
             'tickadj' => ['tickadj', 8, 'ntpd(8)'],
 
31
             'confopt' => ['ntp.conf', 5, 'ntpd(8), ntp_auth(5), ntp_mon(5), ntp_acc(5), ntp_clock(5), ntp_misc(5)'],
30
32
             'authopt' => ['ntp_auth', 5, 'ntp.conf(5), ntpd(8)'],
31
 
             'monopt' => ['ntp_mon', 5, 'ntp.conf(5)'],
 
33
             'monopt' => ['ntp_mon', 5, 'ntp.conf(5), ntp_decode(5)'],
32
34
             'accopt' => ['ntp_acc', 5, 'ntp.conf(5)'],
33
35
             'clockopt' => ['ntp_clock', 5, 'ntp.conf(5)'],
 
36
             'decode' => ['ntp_decode', 5, 'ntpq(8), ntp_mon(5)'],
34
37
             'miscopt' => ['ntp_misc', 5, 'ntp.conf(5)']);
35
38
 
 
39
%table_headers = (
 
40
    'ntpd' => 'l l l l.',
 
41
    'ntpq' => 'l l.',
 
42
    'monopt' => 'l l l.',
 
43
    'decode' => 'l l l l.',
 
44
    'authopt' => 'c c c c c c.'
 
45
);
 
46
 
36
47
# Disclaimer to go in SEE ALSO section of the man page
37
 
$seealso_disclaimer = 'These man pages are automatically hacked from the main NTP ' .
38
 
    'documentation pages, which are maintained in HTML format.  These files are ' .
39
 
    'included in the NTP source distribution.  If you installed NTP from a binary ' .
40
 
    'package, or it came pre-installed on your system, chances are the documentation ' .
41
 
    'was also included in the usual place for your system.  The HTML files are more ' .
42
 
    'correct and complete than these man pages, which are provided for your reference ' .
43
 
    'only.';
44
 
 
45
 
# Disclaimer to go right at the top
46
 
$top_disclaimer = 'This file was automatically generated from HTML source, and may be ' .
47
 
    'incorrect.  See the SEE ALSO section at the end of this file for more info';
 
48
$seealso_disclaimer = "The official HTML documentation.\n\n" .
 
49
    "This file was automatically generated from HTML source.\n";
48
50
 
49
51
mkdir $MANDIR, 0777;
50
52
mkdir "$MANDIR/man8", 0777;
64
66
    $fileinfo = $manfiles{$filename};
65
67
 
66
68
    $p = HTML::TokeParser->new("$filename.html") || die "Can't open $filename.html: $!";
67
 
    open(MANOUT, ">$MANDIR/man$fileinfo->[1]/$fileinfo->[0].$fileinfo->[1]")
 
69
    $fileout = "$MANDIR/man$fileinfo->[1]/$fileinfo->[0].$fileinfo->[1]";
 
70
    open(MANOUT, ">$fileout")
68
71
        || die "Can't open: $!";
69
72
 
70
73
    $p->get_tag("title");
73
76
 
74
77
    # Setup man header
75
78
    print MANOUT ".TH " . $fileinfo->[0] . " " . $fileinfo->[1] .  "\n";
76
 
    print MANOUT ".UC 4\n";
77
79
    print MANOUT ".SH NAME\n";
78
80
    $pat = $fileinfo->[0];
79
81
    if ($name =~ /$pat/) {
81
83
        # Add the manpage name, if not in the HTML title already
82
84
        print MANOUT "$fileinfo->[0] - ";
83
85
    }
84
 
    print MANOUT "$name\n\n";
85
 
 
86
 
    print MANOUT "$top_disclaimer\n";
87
 
 
 
86
    print MANOUT "$name\n.SH \\ \n\n";
 
87
 
 
88
    @fontstack = ();
 
89
    $deflevel = 0;
 
90
    $pre = 0;
 
91
    $ignore = 0;
 
92
    $first_td = 1;
88
93
    # Now start scanning.  We basically print everything after translating some tags.
89
94
    # $token->[0] has "T", "S", "E" for Text, Start, End
90
95
    # $token->[1] has the tag name, or text (for "T" case)
92
97
    while (my $token = $p->get_token) {
93
98
        if($token->[0] eq "T") {
94
99
            my $text = $token->[1];
95
 
            if($tag) {
96
 
                $text =~ s/^[\n ]*//;
97
 
                $text =~ s/[\n ]*$/ /;
 
100
            if (!$pre) {
 
101
                if($tag) {
 
102
                    $text =~ s/^[\n\t ]*//;
 
103
                }
 
104
                $text =~ s/^[\n\t ][\n\t ]+$//;
 
105
                $text =~ s/[\n\t ]+/ /g;
 
106
                $text =~ s/&nbsp\;/ /g;
 
107
                $text =~ s/&gt\;/>/g;
 
108
                $text =~ s/&lt\;/</g;
 
109
                $text =~ s/&quot\;/"/g;
 
110
                $text =~ s/&amp\;/&/g;
 
111
                $text =~ s/^\./\\[char46]/;
98
112
            }
99
 
            $text =~ s/&nbsp\;/ /g;
100
 
            $text =~ s/^\./\\./;
101
113
            print MANOUT "$text";
102
114
            $tag = 0;
103
115
        }
104
116
        if($token->[0] eq "S") {
105
117
            if($token->[1] eq "h4") {
106
118
                my $text = uc($p->get_trimmed_text("/h4"));
107
 
                print MANOUT ".SH $text\n";
 
119
                # ignore these sections in ntpd.html
 
120
                if ($filename eq "ntpd" &&
 
121
                    ($text eq "CONFIGURATION OPTIONS")) {
 
122
                        $ignore = 1;
 
123
                        close(MANOUT);
 
124
                        open(MANOUT, ">/dev/null");
 
125
                } elsif ($ignore) {
 
126
                    $ignore = 0;
 
127
                    close(MANOUT);
 
128
                    open(MANOUT, ">>$fileout");
 
129
                }
 
130
                print MANOUT "\n\n.SH $text\n";
108
131
            }
109
132
            if($token->[1] eq "tt") {
110
133
                push @fontstack, "tt";
118
141
                my $text = $p->get_trimmed_text("/address");
119
142
                print MANOUT "\n.SH AUTHOR\n$text\n";
120
143
            }
121
 
            if($token->[1] eq "dt") {
122
 
                $tmp = $deflevel-4;
123
 
                print MANOUT "\n.RS $tmp\n";
 
144
            if($token->[1] eq "dt" || $token->[1] eq "br" && $deflevel > 0) {
 
145
                print MANOUT "\n.TP 8\n";
124
146
                $tag = 1;
125
147
            }
126
148
            if($token->[1] eq "dd") {
127
 
                print MANOUT "\n.RS $deflevel\n";
 
149
                print MANOUT "\n";
128
150
                $tag = 1;
129
151
            }
130
152
            if($token->[1] eq "dl") {
131
 
                $deflevel+=4;
 
153
                $deflevel+=1;
 
154
                if ($deflevel > 0) {
 
155
                    print MANOUT "\n.RS ", $deflevel > 1 ? 8 : 0;
 
156
                }
 
157
            }
 
158
            if($token->[1] eq "p") {
 
159
                print MANOUT "\n";
 
160
            }
 
161
            if($token->[1] eq "pre") {
 
162
                print MANOUT "\n.nf";
 
163
                $pre = 1;
 
164
            }
 
165
            if($token->[1] eq "table") {
 
166
                print MANOUT "\n.TS\n";
 
167
                print MANOUT "expand allbox tab(%);\n";
 
168
                print MANOUT $table_headers{$filename};
 
169
                print MANOUT "\n";
 
170
            }
 
171
            if($token->[1] eq "td") {
 
172
                if ($first_td == 0) {
 
173
                    print MANOUT " % ";
 
174
                }
 
175
                $first_td = 0;
132
176
            }
133
177
        }
134
178
        elsif($token->[0] eq "E") {
135
 
            if($token->[1] eq "dd") {
136
 
                print MANOUT "\n.RE\n";
 
179
            if($token->[1] eq "h4") {
137
180
                $tag = 1;
138
181
            }
139
182
            if($token->[1] eq "tt") {
157
200
                print MANOUT "$fontswitch";
158
201
            }
159
202
            if($token->[1] eq "dl") {
160
 
                $deflevel-=4;
 
203
                if ($deflevel > 0) {
 
204
                    print MANOUT "\n.RE";
 
205
                }
 
206
                print MANOUT "\n";
 
207
                $deflevel-=1;
161
208
            }
162
 
            if($token->[1] eq "dt") {
163
 
                print MANOUT "\n.RE";
 
209
            if($token->[1] eq "p") {
 
210
                print MANOUT "\n";
164
211
                $tag = 1;
165
212
            }
 
213
            if($token->[1] eq "pre") {
 
214
                print MANOUT "\n.fi";
 
215
                $pre = 0;
 
216
            }
 
217
            if($token->[1] eq "table") {
 
218
                print MANOUT ".TE\n";
 
219
            }
 
220
            if($token->[1] eq "tr") {
 
221
                print MANOUT "\n";
 
222
                $first_td = 1;
 
223
            }
166
224
        }
167
225
    }
168
 
    print MANOUT ".SH SEE ALSO\n\n";
 
226
    if ($ignore) {
 
227
        close(MANOUT);
 
228
        open(MANOUT, ">>$fileout");
 
229
    }
 
230
    print MANOUT "\n.SH SEE ALSO\n\n";
169
231
    print MANOUT "$fileinfo->[2]\n\n";
170
232
    print MANOUT "$seealso_disclaimer\n";
171
233
    close(MANOUT);