1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
#!/usr/bin/perl
#
# See COPYRIGHT
#
# Script to generate a pod file from an html source (the same one as for text files too)
# and later this pod file it passed through pod2man
#
# Use:
# html2man [ <man-dir> [<version-dir>] ] <file.html
#
# <Man-dir> is the directory where the man pages will be created
# (current directory by default). If a file name is given instead of
# directory then the directory of that file is used.
# <Version-dir> is the directory containing the ttf2pt1 files version.h
# and CHANGES.html which are used to generate the release name and date
# for the man page (by default looks in current directory and then in up to
# 5 ancestor directories).
# If the version files can not be found then the release defaults to
# "current" and the date defaults to today.
#
# Special formatting in the html file is:
# All controls are hidden within HTML comments that must occupy a whole separate line
# Such a line looks like:
# <!-- =<html2man_directive> <arguments> -->
# <!-- ==<pod_directive> <arguments> -->
# Any sort of directive must be followed by a space. The pod directives are
# automatically surrounded by empty lines in the output file.
# The html2man directives are:
#
# <!-- =defdoc <docid> <file> <section> -->
# Define a man page. Multiple man pages can be defined in the same HTML
# file. <Docid> is a short name by which this man page will be referred in the
# other directives. <File> is the name of the man page, and <section> is the
# section of the manual (do not confuse with sections within a man page).
#
# <!-- =section <docid> <page_section_name> -->
# All the text following this directive is copied (with translation)
# into the specified section of the specified man page. The sections
# may appear in arbitrary order, they will be rearranged to the standard
# order before output. Only standard section names are permitted (see @stdsect
# below). The pod directives which occur outside of man sections are ignored,
# just like the common text. The translation of HTML tags is:
#
# <br> - to paragraph break
# <b> - to B<>
# <i> - to I<>
# <tt> - to C<>
# <a href> - to F<>
# <ul>, <li>, </ul> - to =over 2, =item *, =back
# , &, <, > - to their symbols, appropriately encoded
#
# The rest of HTML tags is removed
#
# If the same section is started more than once, the text from the
# second appearance will be added to the first, etc.
#
# <!-- =stop -->
# Stop copying text to the man page.
#
# <!-- =cont -->
# Continue copying text to the man page, same section as before.
#
# <!-- =text <text> -->
# Insert this <text> into the man page (works only when copying is enabled).
# Characters <, >, & are converted as usual.
@mons = qw(January February March April May June July August September October November December);
$dir = $ARGV[0];
$maindir = $ARGV[1];
if($dir eq "") {
$dir = ".";
} elsif( ! -d $dir ) {
if( ! ($dir =~ s|\/[^/]*$||) ) {
$dir = ".";
}
}
if($maindir eq "") {
$maindir = ".";
for($i=0; $i<5; $i++) {
if(-f "$maindir/version.h") {
last;
}
$maindir = "../$maindir";
}
}
if( open(VERFILE, "<$maindir/version.h") ) {
while(<VERFILE>) {
if( /^\s*\#define\s+TTF2PT1_VERSION\s+\"(.*)\"/ ) {
$release = "version $1";
}
}
close(VERFILE);
if( $release =~ /SNAP-([0-9][0-9])([0-9][0-9])([0-9][0-9])/ ) {
$date = sprintf("%s %d, 20%02d", $mons[$2-1], $3, $1);
} elsif( open(CFILE, "<$maindir/CHANGES.html") ) {
while(<CFILE>) {
if( /\<H4\>/) {
last;
}
}
$_ = <CFILE>;
chomp;
if( $_ =~ s/^.*?-- // ) {
$date = $_;
}
close(CFILE);
}
}
if($release eq "") {
if( open(VERFILE, "<../Makefile") ) {
while(<VERFILE>) {
if( /^VERSION\s+=\s+(.*)/ ) {
$release = "version $1";
}
}
close(VERFILE);
}
}
if($release eq "") {
$release = "current";
}
if($date eq "") {
@lt = localtime(time);
$date = sprintf("%s %d, %d", $mons[$lt[4]], $lt[3], 1900+$lt[5]);
}
#printf(STDERR "date=%s release=%s\n", $date, $release);
$writemode = 0;
while(<STDIN>) {
if( s/^\<\!\-\- \=(\S+)\s+//) {
$cmd = $1;
s/\s*\-\-\>\s*$//;
#printf(STDERR "cmd=%s args=%s\n", $cmd, $_);
if($cmd =~ /^=/) {
if($writemode) {
$text{$tosect} .= "\n\n$cmd $_\n\n";
}
} elsif($cmd eq "defdoc") {
@sl = split;
push(@allids, $sl[0]);
$file{$sl[0]} = $sl[1];
$mansect{$sl[0]} = $sl[2];
} elsif($cmd eq "section") {
# tosect includes the file id
$tosect = $_;
$text{$tosect} .= "\n\n";
$writemode = 1;
} elsif($cmd eq "stop") {
$writemode = 0;
$text{$tosect} .= "\n";
} elsif($cmd eq "cont") {
$writemode = 1;
} elsif($cmd eq "text") {
if($writemode) {
s/\<\;/</gi;
s/\>\;/>/gi;
s/\&\;/\&/gi;
$text{$tosect} .= "$_\n";
}
}
} elsif($writemode) {
# s/^\s+//;
s/\{/\&lbr;/g;
s/\}/\&rbr;/g;
s/\<br\>/\n\n/gi;
#s/\<blockquote\>/\n\n=over 4\n\n/gi;
#s/\<\/blockquote\>/\n\n=back\n\n/gi;
s/\<ul\>/\n\n=over 4\n\n/gi;
s/\<\/ul\>/\n\n=back\n\n/gi;
s/\<li\>\s*/\n\n=item \*\n\n/gi;
s/\<dl\>/\n\n=over 4\n\n/gi;
s/\<\/dl\>/\n\n=back\n\n/gi;
s/\<dt\>\s*/\n\n=item \*\n\n/gi;
s/\<dd\>\s*/\n\n/gi;
s/\<i\>(.*?)\<\/i\>/I\{\1\}/gi;
s/\<em\>(.*?)\<\/em\>/I\{\1\}/gi;
s/\<b\>(.*?)\<\/b\>/B\{\1\}/gi;
s/\<tt\>(.*?)\<\/tt\>/C\{\1\}/gi;
s/\<a href\=\.*?\>(.*?)\<\/a\>/F\{\1\}/gi;
s/\<h2\>summary\<\/h2\>//gi;
s/\<h2\>description\<\/h2\>//gi;
s/\<h2\>examples\<\/h2\>//gi;
s/\<h2\>options\<\/h2\>//gi;
s/\<h2\>(.*?)\<\/h2\>/B\{\1\}/gi;
s/\<.*?\>//g;
s/\{/\</g;
s/\}/\>/g;
s/\ \;/S< >/gi;
s/\&\;/\&/gi;
# s/\<\;/E<lt>/gi;
# s/\>\;/E<gt>/gi;
s/\<\;/\</gi;
s/\>\;/\>/gi;
#s/\|/E<verbar>/g;
#s/\//E<sol>/g;
s/\&lbr\;/\{/g;
s/\&rbr\;/\}/g;
#printf(STDERR "section=%s add=%s", $tosect, $_);
$text{$tosect} .= $_;
}
}
@stdsect = (
"NAME",
"SYNOPSIS",
"OPTIONS",
"DESCRIPTION",
"RETURN VALUE",
"ERRORS",
"EXAMPLES",
"ENVIRONMENT",
"FILES",
"SEE ALSO",
"NOTES",
"CAVEATS",
"DIAGNOSTICS",
"BUGS",
"RESTRICTIONS",
"AUTHOR",
"HISTORY" );
#printf(STDERR "allids= @allids\n");
for $id (@allids) {
print(STDERR "creating man page $id $file{$id} $mansect{$id}\n\n");
die "Unable to create pod file $dir/$file{$id}.pod"
unless open(PODF, ">./pod/$file{$id}.pod");
print(PODF "=pod\n\n");
for $sect (@stdsect) {
$sid = "$id $sect";
#printf(STDERR "trying %s\n", $sid);
if(defined $text{$sid}) {
#printf(STDERR " section %s\n", $sid);
print(PODF "=head1 $sect\n\n$text{$sid}\n\n");
}
}
print(PODF "=cut\n");
close(PODF);
die "Unable to generate the man page $dir/$file{$id}.1"
if system("pod2man --section=\"$mansect{$id}\" --release=\"$release\" "
. "--center=\"SAORD Documentation\" --date=\"$date\" "
. "--name=\"$file{$id}\" "
. "./pod/$file{$id}.pod > $dir/man$mansect{$id}/$file{$id}.$mansect{$id}");
unlink("$dir/$file{$id}.pod");
}
|