| 1 |
#! /usr/bin/perl -w |
| 2 |
|
| 3 |
sub die_arg() { |
| 4 |
print STDERR "usage: uogo2man PACKAGE PROGRAM SECTION FORMAT [opt SEC]...\n"; |
| 5 |
exit(2); |
| 6 |
|
| 7 |
} |
| 8 |
my $package=$ARGV[0] || die_arg; |
| 9 |
my $prog=$ARGV[1] || die_arg; |
| 10 |
my $secnum=$ARGV[2] || die_arg; |
| 11 |
my $format=$ARGV[3] || die_arg; |
| 12 |
|
| 13 |
my $html=1 if ($format eq "html"); |
| 14 |
$html=0 if ($format eq "man"); |
| 15 |
die "format must be html or man" unless (defined($html)); |
| 16 |
|
| 17 |
my $i; |
| 18 |
for ($i=0;$i<4;$i++) { |
| 19 |
shift(@ARGV); |
| 20 |
} |
| 21 |
|
| 22 |
my $cprog=$prog; |
| 23 |
$cprog =~ s%^.*/%%; |
| 24 |
|
| •25 |
my $datum="2005-04-28"; |
| 26 |
chomp($datum); |
| 27 |
|
| 28 |
sub die_no_help() { |
| 29 |
die "failed to get help from $prog: $!"; |
| 30 |
} |
| 31 |
|
| 32 |
my $secname; |
| 33 |
if (!$html) { |
| 34 |
if ($secnum == 1) { $secname="User Commands"; } |
| 35 |
elsif ($secnum == 2) { $secname="System Calls"; } |
| 36 |
elsif ($secnum == 3) { $secname="Library Functions"; } |
| 37 |
elsif ($secnum == 4) { $secname="Special Files"; } |
| 38 |
elsif ($secnum == 5) { $secname="File Formats"; } |
| 39 |
elsif ($secnum == 6) { $secname="Games"; } |
| 40 |
elsif ($secnum == 7) { $secname="Miscellaneous"; } |
| 41 |
elsif ($secnum == 8) { $secname="Administration Commands"; } |
| 42 |
elsif ($secnum == 9) { $secname="Kernel Internals"; } |
| 43 |
else { $secname="???"; } |
| 44 |
} |
| 45 |
|
| 46 |
if (open(I,"<doc.highlights")) { |
| 47 |
while (<I>) { |
| 48 |
chop; |
| 49 |
next if (/^#/); |
| 50 |
next if (/^$/); |
| 51 |
if (/^(\S*)\s+(.*)/) { |
| 52 |
$hl{$1}=$2; |
| 53 |
} elsif (/^(\S*)/) { |
| 54 |
$hl{$1}=""; |
| 55 |
} |
| 56 |
} |
| 57 |
close(I); |
| 58 |
} |
| 59 |
sub do_hl($) |
| 60 |
{ |
| 61 |
my $x=shift; |
| 62 |
my $k; |
| 63 |
foreach $k (keys %hl) { |
| 64 |
if ($html) { |
| 65 |
if ($x !~ m%http://% && $x !~ m%$k(-\S+)*\@(\S+)%) { |
| 66 |
$x =~ s%(\b$k\b)%<b>$k</b>%g; |
| 67 |
} |
| 68 |
} else { |
| 69 |
$x =~ s/(\b$k\b)/\\fB$k\\fR/g; |
| 70 |
} |
| 71 |
} |
| 72 |
if ($html) { |
| 73 |
$x =~ s%<(\S+\@\S+)>%<a href="mailto:$1">$1</a>%g; |
| 74 |
$x =~ s%(http://\S+)%<a href="$1">$1</a>%g; |
| 75 |
} |
| 76 |
return $x; |
| 77 |
} |
| 78 |
sub copy_option_output($$$) |
| 79 |
{ |
| 80 |
my $opt=shift; |
| 81 |
my $x=shift; |
| 82 |
my $dohl=shift; |
| 83 |
open(I,"$prog $opt|") || die_no_help; |
| 84 |
my $flag=0; |
| 85 |
my $inex=0; |
| 86 |
my $flag_dl=0; |
| 87 |
my $kill_usage=0; |
| 88 |
$kill_usage=1 if ($x eq "SYNOPSIS"); |
| 89 |
|
| 90 |
while (<I>) { |
| 91 |
$_=~ s%\\%\\\\%g; |
| 92 |
if ($kill_usage && /^usage:\s*(.*)/i) { |
| 93 |
$_=$1."\n"; |
| 94 |
} |
| 95 |
if (!$flag) { |
| 96 |
if ($html) { |
| 97 |
$n=$x; |
| 98 |
$n=~ s/\s/-/g; |
| 99 |
print "<h3><a name=\"$n\"></a>$x</h3><br>\n"; |
| 100 |
} else { |
| 101 |
print ".SH \"$x\"\n" unless ($flag); |
| 102 |
} |
| 103 |
} |
| 104 |
$flag=1; |
| 105 |
if ($inex && !/^ /) { |
| 106 |
$inex=0; |
| 107 |
if ($html) { |
| 108 |
print "</pre>\n"; |
| 109 |
} else { |
| 110 |
print ".fi\n"; |
| 111 |
} |
| 112 |
} |
| 113 |
if (/^ *\n$/) { |
| 114 |
if ($html) { |
| 115 |
print "<p>\n"; |
| 116 |
} else { |
| 117 |
print ".P\n"; |
| 118 |
} |
| 119 |
next; |
| 120 |
} |
| 121 |
if (/^ / && !$inex) { |
| 122 |
$inex=1; |
| 123 |
if ($html) { |
| 124 |
print "<pre>\n"; |
| 125 |
} else { |
| 126 |
print ".nf\n"; |
| 127 |
} |
| 128 |
} |
| 129 |
$_=do_hl($_) if ($dohl); |
| 130 |
print "\\" if (/^'/ && !$html); |
| 131 |
print $_; |
| 132 |
} |
| 133 |
if ($inex) { |
| 134 |
if ($html) { |
| 135 |
print "</pre>\n"; |
| 136 |
} else { |
| 137 |
print ".fi\n"; |
| 138 |
} |
| 139 |
} |
| 140 |
if ($flag_dl) { |
| 141 |
print "</dl>\n"; |
| 142 |
} |
| 143 |
close(I); |
| 144 |
} |
| 145 |
sub copy_manhelp_options_output($$$) |
| 146 |
{ |
| 147 |
my $opt=shift; |
| 148 |
my $x=shift; |
| 149 |
my $dohl=shift; |
| 150 |
open(I,"$prog $opt|") || die_no_help; |
| 151 |
my $flag=0; |
| 152 |
my $flag_dl=0; |
| 153 |
my $in_indent=0; |
| 154 |
my $markword=""; |
| 155 |
|
| 156 |
while (<I>) { |
| 157 |
$_=~ s%\\%\\\\%g; |
| 158 |
if (!$flag) { |
| 159 |
if ($html) { |
| 160 |
$n=$x; |
| 161 |
$n=~ s/\s/-/g; |
| 162 |
print "<h3><a name=\"$n\"></a>$x</h3><br>\n"; |
| 163 |
} else { |
| 164 |
print ".SH \"$x\"\n" unless ($flag); |
| 165 |
} |
| 166 |
$flag=1; |
| 167 |
} |
| 168 |
if ($in_indent && !/^ /) { |
| 169 |
$in_indent=0; |
| 170 |
if ($html) { |
| 171 |
print "</pre>\n"; |
| 172 |
} else { |
| 173 |
print ".fi\n"; |
| 174 |
} |
| 175 |
} |
| 176 |
if (/^ / && !$in_indent) { |
| 177 |
$in_indent=1; |
| 178 |
if ($html) { |
| 179 |
print "<pre>\n"; |
| 180 |
} else { |
| 181 |
print ".nf\n"; |
| 182 |
} |
| 183 |
} |
| 184 |
if (/^$/) { |
| 185 |
if ($html) { |
| 186 |
print "<p>\n"; |
| 187 |
} else { |
| 188 |
print ".br\n"; |
| 189 |
} |
| 190 |
next; |
| 191 |
} |
| 192 |
if (/^-/) { |
| 193 |
$markword=""; |
| 194 |
$markword=$1 if (/=(.*)\n/); |
| 195 |
if (!$flag_dl && $html) { |
| 196 |
print "<dl>\n"; |
| 197 |
$flag_dl=1; |
| 198 |
} |
| 199 |
if ($html) { |
| 200 |
print "<dt>\n"; |
| 201 |
} else { |
| 202 |
print ".TP\n"; |
| 203 |
} |
| 204 |
print $_; |
| 205 |
if ($html) { |
| 206 |
print "<dd>\n"; |
| 207 |
# } else { |
| 208 |
# print ".br\n"; |
| 209 |
} |
| 210 |
next; |
| 211 |
} |
| 212 |
$_=do_hl($_) if ($dohl); |
| 213 |
if ($markword) { |
| 214 |
if ($html) { |
| 215 |
s%(\b$markword\b)%<i>$markword</i>%g; |
| 216 |
} else { |
| 217 |
s/(\b$markword\b)/\\fI$markword\\fR/g; |
| 218 |
} |
| 219 |
} |
| 220 |
if (!/^ /) { |
| 221 |
if ($html) { |
| 222 |
print "<h3>$_</h3>\n"; |
| 223 |
} else { |
| 224 |
print ".SS $_\n"; |
| 225 |
} |
| 226 |
next |
| 227 |
} |
| 228 |
s/^ //; |
| 229 |
print "\\" if (/^'/ && !$html); |
| 230 |
print $_; |
| 231 |
if (!$html) { |
| 232 |
print ".br\n"; |
| 233 |
} |
| 234 |
} |
| 235 |
if ($flag_dl) { |
| 236 |
print "</dl>\n"; |
| 237 |
} |
| 238 |
if ($in_indent) { |
| 239 |
if ($html) { |
| 240 |
print "</pre>\n"; |
| 241 |
} else { |
| 242 |
print ".fi\n"; |
| 243 |
} |
| 244 |
} |
| 245 |
close(I); |
| 246 |
} |
| 247 |
|
| 248 |
if ($html) { |
| 249 |
if (open(I,"<doc-header.html")) { |
| 250 |
while(<I>) { |
| 251 |
s/xxPACKAGExx/$package/g; |
| 252 |
s/xxPROGRAMxx/$cprog/g; |
| 253 |
print $_; |
| 254 |
} |
| 255 |
} |
| 256 |
} else { |
| 257 |
print ".TH $cprog $secnum $datum \"\" \"$secname\"\n"; |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
open(I,"$prog --manhelp-short-desc|") || die_no_help; |
| 262 |
my $description; |
| 263 |
while (<I>) { |
| 264 |
$description=$_; |
| 265 |
last; |
| 266 |
} |
| 267 |
close(I); |
| 268 |
die "no description" unless ($description); |
| 269 |
|
| 270 |
if ($html) { |
| 271 |
print "$cprog - $description\n"; |
| 272 |
print "<p>"; |
| 273 |
} else { |
| 274 |
print ".SH NAME\n"; |
| 275 |
print "$cprog \\- $description\n"; |
| 276 |
} |
| 277 |
|
| 278 |
copy_option_output("--manhelp-synopsis","SYNOPSIS",1); |
| 279 |
copy_option_output("--manhelp-long-desc","DESCRIPTION",1); |
| 280 |
copy_manhelp_options_output("--manhelp-options","OPTIONS",1); |
| 281 |
copy_option_output("--examples","EXAMPLES",1); |
| 282 |
while ($ARGV[0]) { |
| 283 |
die "bad number of arguments" unless ($ARGV[1]); |
| 284 |
|
| 285 |
copy_option_output($ARGV[0],$ARGV[1],1); |
| 286 |
shift(@ARGV); |
| 287 |
shift(@ARGV); |
| 288 |
} |
| 289 |
copy_option_output("--copyright","COPYRIGHT",1); |
| 290 |
copy_option_output("--author","AUTHOR",1); |
| 291 |
copy_option_output("--manhelp-tail","MORE INFORMATION",1); |
| 292 |
copy_option_output("--see-also","SEE ALSO",1); |