summaryrefslogtreecommitdiff
path: root/mdoc2man.pl
diff options
context:
space:
mode:
authorTim Rice <tim@multitalents.net>2001-04-29 18:01:51 -0700
committerTim Rice <tim@multitalents.net>2001-04-29 18:01:51 -0700
commit4534492aec2d7c383d6f29685195597375344673 (patch)
tree98a0e7bd59619f2917f0cc56d8a5b98f3e286610 /mdoc2man.pl
parentf343674d5e297f16aafe24f68620b22656a27ba1 (diff)
- (tim) New version of mdoc2man.pl from Mark D. Roth <roth+openssh@feep.net>
Diffstat (limited to 'mdoc2man.pl')
-rw-r--r--mdoc2man.pl376
1 files changed, 301 insertions, 75 deletions
diff --git a/mdoc2man.pl b/mdoc2man.pl
index f2d794539..fddb2e09d 100644
--- a/mdoc2man.pl
+++ b/mdoc2man.pl
@@ -40,18 +40,28 @@ use strict;
40 40
41my ($name, $date, $id); 41my ($name, $date, $id);
42my ($line); 42my ($line);
43my ($optlist, $nospace, $enum, $synopsis); 43my ($optlist, $oldoptlist, $nospace, $enum, $synopsis);
44my ($reference, $block, $ext, $extopt, $literal);
45my (@refauthors, $reftitle, $refissue, $refdate, $refopt);
44 46
45 47
46$optlist = 0; ### 1 = bullet, 2 = enum, 3 = tag 48$optlist = 0; ### 1 = bullet, 2 = enum, 3 = tag, 4 = item
49$oldoptlist = 0;
47$nospace = 0; 50$nospace = 0;
48$synopsis = 0; 51$synopsis = 0;
52$reference = 0;
53$block = 0;
54$ext = 0;
55$extopt = 0;
56$literal = 0;
49 57
50while ($line = <STDIN>) 58while ($line = <STDIN>)
51{ 59{
52 if ($line !~ /^\./) 60 if ($line !~ /^\./)
53 { 61 {
54 print $line; 62 print $line;
63 print ".br\n"
64 if ($literal);
55 next; 65 next;
56 } 66 }
57 67
@@ -70,13 +80,12 @@ while ($line = <STDIN>)
70sub ParseMacro # ($line) 80sub ParseMacro # ($line)
71{ 81{
72 my ($line) = @_; 82 my ($line) = @_;
73 my (@words, $retval, $option, $parens, $arg); 83 my (@words, $retval, $option, $parens);
74 84
75 @words = split(/\s+/, $line); 85 @words = split(/\s+/, $line);
76 $retval = ''; 86 $retval = '';
77 $option = 0; 87 $option = 0;
78 $parens = 0; 88 $parens = 0;
79 $arg = 0;
80 89
81# print('@words = ', scalar(@words), ': ', join(' ', @words), "\n"); 90# print('@words = ', scalar(@words), ': ', join(' ', @words), "\n");
82 91
@@ -85,9 +94,39 @@ sub ParseMacro # ($line)
85# print "WORD: $_\n"; 94# print "WORD: $_\n";
86 95
87 next 96 next
88 if (/^(Li|Pf|X[oc])$/); 97 if (/^(Li|Pf)$/);
89 98
90 if (/^Ns/) 99 if (/^Xo$/)
100 {
101 $ext = 1;
102 $retval .= ' '
103 if ($retval ne '' && $retval !~ m/[\n ]$/);
104 next;
105 }
106
107 if (/^Xc$/)
108 {
109 $ext = 0;
110 $retval .= "\n"
111 if (! $extopt);
112 last;
113 }
114
115 if (/^Bd$/)
116 {
117 $literal = 1
118 if ($words[0] eq '-literal');
119 $retval .= "\n";
120 last;
121 }
122
123 if (/^Ed$/)
124 {
125 $literal = 0;
126 last;
127 }
128
129 if (/^Ns$/)
91 { 130 {
92 $nospace = 1 131 $nospace = 1
93 if (! $nospace); 132 if (! $nospace);
@@ -95,43 +134,78 @@ sub ParseMacro # ($line)
95 next; 134 next;
96 } 135 }
97 136
98 if (/^No/) 137 if (/^No$/)
99 { 138 {
100 $retval =~ s/ $//; 139 $retval =~ s/ $//;
101 $retval .= shift @words; 140 $retval .= shift @words;
102 next; 141 next;
103 } 142 }
104 143
105 if (/^Dq$/) { 144 if (/^Dq$/)
106 $retval .= '``' . (shift @words) . '\'\''; 145 {
146 $retval .= '``';
147 do
148 {
149 $retval .= (shift @words) . ' ';
150 }
151 while (@words > 0 && $words[0] !~ m/^[\.,]/);
152 $retval =~ s/ $//;
153 $retval .= '\'\'';
107 $nospace = 1 154 $nospace = 1
108 if (! $nospace && $words[0] =~ m/^[\.,]/); 155 if (! $nospace && $words[0] =~ m/^[\.,]/);
109 next; 156 next;
110 } 157 }
111 158
112 if (/^(Sq|Ql)$/) { 159 if (/^(Sq|Ql)$/)
160 {
113 $retval .= '`' . (shift @words) . '\''; 161 $retval .= '`' . (shift @words) . '\'';
114 $nospace = 1 162 $nospace = 1
115 if (! $nospace && $words[0] =~ m/^[\.,]/); 163 if (! $nospace && $words[0] =~ m/^[\.,]/);
116 next; 164 next;
117 } 165 }
118 166
167# if (/^Ic$/)
168# {
169# $retval .= '\\fB' . shift(@words) . '\\fP';
170# next;
171# }
172
173 if (/^Oo$/)
174 {
175# $retval .= "[\\c\n";
176 $extopt = 1;
177 $nospace = 1
178 if (! $nospace);
179 $retval .= '[';
180 next;
181 }
182
183 if (/^Oc$/)
184 {
185 $extopt = 0;
186 $retval .= ']';
187 next;
188 }
189
119 $retval .= ' ' 190 $retval .= ' '
120 if (! $nospace && $retval ne '' && $retval !~ m/[\n ]$/); 191 if (! $nospace && $retval ne '' && $retval !~ m/[\n ]$/);
121 $nospace = 0 192 $nospace = 0
122 if ($nospace == 1); 193 if ($nospace == 1);
123 194
124 if (/^Dd$/) { 195 if (/^Dd$/)
196 {
125 $date = join(' ', @words); 197 $date = join(' ', @words);
126 return undef; 198 return undef;
127 } 199 }
128 200
129 if (/^Dt$/) { 201 if (/^Dt$/)
202 {
130 $id = join(' ', @words); 203 $id = join(' ', @words);
131 return undef; 204 return undef;
132 } 205 }
133 206
134 if (/^Os$/) { 207 if (/^Os$/)
208 {
135 $retval .= '.TH ' 209 $retval .= '.TH '
136 . $id 210 . $id
137 . " \"$date\" \"" 211 . " \"$date\" \""
@@ -140,7 +214,8 @@ sub ParseMacro # ($line)
140 last; 214 last;
141 } 215 }
142 216
143 if (/^Sh$/) { 217 if (/^Sh$/)
218 {
144 $retval .= '.SH'; 219 $retval .= '.SH';
145 if ($words[0] eq 'SYNOPSIS') 220 if ($words[0] eq 'SYNOPSIS')
146 { 221 {
@@ -153,113 +228,213 @@ sub ParseMacro # ($line)
153 next; 228 next;
154 } 229 }
155 230
156 if (/^Xr$/) { 231 if (/^Xr$/)
232 {
157 $retval .= '\\fB' . (shift @words) . 233 $retval .= '\\fB' . (shift @words) .
158 '\\fR(' . (shift @words) . ')' 234 '\\fP(' . (shift @words) . ')'
159 . (shift @words); 235 . (shift @words);
160 last; 236 last;
161 } 237 }
162 238
163 if (/^Nm$/) { 239 if (/^Rs/)
240 {
241 @refauthors = ();
242 $reftitle = '';
243 $refissue = '';
244 $refdate = '';
245 $refopt = '';
246 $reference = 1;
247 last;
248 }
249
250 if (/^Re/)
251 {
252 $retval .= "\n";
253
254 # authors
255 while (scalar(@refauthors) > 1)
256 {
257 $retval .= shift(@refauthors) . ', ';
258 }
259 $retval .= 'and '
260 if ($retval ne '');
261 $retval .= shift(@refauthors);
262
263 # title
264 $retval .= ', \\fI' . $reftitle . '\\fP';
265
266 # issue
267 $retval .= ', ' . $refissue
268 if ($refissue ne '');
269
270 # date
271 $retval .= ', ' . $refdate
272 if ($refdate ne '');
273
274 # optional info
275 $retval .= ', ' . $refopt
276 if ($refopt ne '');
277
278 $retval .= ".\n";
279
280 $reference = 0;
281 last;
282 }
283
284 if ($reference)
285 {
286 if (/^%A$/)
287 {
288 unshift(@refauthors, join(' ', @words));
289 last;
290 }
291
292 if (/^%T$/)
293 {
294 $reftitle = join(' ', @words);
295 $reftitle =~ s/^"//;
296 $reftitle =~ s/"$//;
297 last;
298 }
299
300 if (/^%N$/)
301 {
302 $refissue = join(' ', @words);
303 last;
304 }
305
306 if (/^%D$/)
307 {
308 $refdate = join(' ', @words);
309 last;
310 }
311
312 if (/^%O$/)
313 {
314 $refopt = join(' ', @words);
315 last;
316 }
317 }
318
319 if (/^Nm$/)
320 {
164 $name = shift @words 321 $name = shift @words
165 if (@words > 0); 322 if (@words > 0);
166 $retval .= ".br\n" 323 $retval .= ".br\n"
167 if ($synopsis); 324 if ($synopsis);
168 $retval .= "\\fB$name\\fR"; 325 $retval .= "\\fB$name\\fP";
169 $nospace = 1 326 $nospace = 1
170 if (! $nospace && $words[0] =~ m/^[\.,]/); 327 if (! $nospace && $words[0] =~ m/^[\.,]/);
171 next; 328 next;
172 } 329 }
173 330
174 if (/^Nd$/) { 331 if (/^Nd$/)
332 {
175 $retval .= '\\-'; 333 $retval .= '\\-';
176 next; 334 next;
177 } 335 }
178 336
179 if (/^Fl$/) { 337 if (/^Fl$/)
180 $retval .= '\\fB\\-' . (shift @words) . '\\fR'; 338 {
339 $retval .= '\\fB\\-' . (shift @words) . '\\fP';
181 $nospace = 1 340 $nospace = 1
182 if (! $nospace && $words[0] =~ m/^[\.,]/); 341 if (! $nospace && $words[0] =~ m/^[\.,]/);
183 next; 342 next;
184 } 343 }
185 344
186 if (/^Ar$/) { 345 if (/^Ar$/)
346 {
187 $retval .= '\\fI'; 347 $retval .= '\\fI';
188 if (! defined $words[0]) 348 if (! defined $words[0])
189 { 349 {
190 $retval .= 'file ...\\fR'; 350 $retval .= 'file ...\\fP';
351 }
352 else
353 {
354 $retval .= shift(@words) . '\\fP';
355 while ($words[0] eq '|')
356 {
357 $retval .= ' ' . shift(@words);
358 $retval .= ' \\fI' . shift(@words);
359 $retval .= '\\fP';
360 }
191 } 361 }
192 $arg = 1;
193 $nospace = 1 362 $nospace = 1
194 if (! $nospace); 363 if (! $nospace && $words[0] =~ m/^[\.,]/);
195 next; 364 next;
196 } 365 }
197 366
198 if (/^Cm$/) { 367 if (/^Cm$/)
199 $retval .= '\\fB' . (shift @words) . '\\fR'; 368 {
369 $retval .= '\\fB' . (shift @words) . '\\fP';
370 while ($words[0] =~ m/^[\.,:)]$/)
371 {
372 $retval .= shift(@words);
373 }
200 next; 374 next;
201 } 375 }
202 376
203 if (/^Op$/) { 377 if (/^Op$/)
378 {
204 $option = 1; 379 $option = 1;
205 $nospace = 1 380 $nospace = 1
206 if (! $nospace); 381 if (! $nospace);
207 $retval .= '['; 382 $retval .= '[';
383# my $tmp = pop(@words);
384# $tmp .= ']';
385# push(@words, $tmp);
208 next; 386 next;
209 } 387 }
210 388
211 if (/^Oo$/) { 389 if (/^Pp$/)
212 $retval .= "[\\c\n"; 390 {
213 next; 391 $retval .= "\n";
214 }
215
216 if (/^Oc$/) {
217 $retval .= ']';
218 next;
219 }
220
221 if (/^Pp$/) {
222 if ($optlist) {
223 $retval .= "\n";
224 } else {
225 $retval .= '.LP';
226 }
227 next; 392 next;
228 } 393 }
229 394
230 if (/^Ss$/) { 395 if (/^Ss$/)
396 {
231 $retval .= '.SS'; 397 $retval .= '.SS';
232 next; 398 next;
233 } 399 }
234 400
235 if (/^Pa$/ && ! $option) { 401 if (/^Pa$/ && ! $option)
402 {
236 $retval .= '\\fI'; 403 $retval .= '\\fI';
237 $retval .= '\\&' 404 $retval .= '\\&'
238 if ($words[0] =~ m/^\./); 405 if ($words[0] =~ m/^\./);
239 $retval .= (shift @words) . '\\fR'; 406 $retval .= (shift @words) . '\\fP';
240 $nospace = 1 407 while ($words[0] =~ m/^[\.,:;)]$/)
241 if (! $nospace && $words[0] =~ m/^[\.,]/); 408 {
409 $retval .= shift(@words);
410 }
411# $nospace = 1
412# if (! $nospace && $words[0] =~ m/^[\.,:)]/);
242 next; 413 next;
243 } 414 }
244 415
245 if (/^Dv$/) { 416 if (/^Dv$/)
417 {
246 $retval .= '.BR'; 418 $retval .= '.BR';
247 next; 419 next;
248 } 420 }
249 421
250 if (/^(Em|Ev)$/) { 422 if (/^(Em|Ev)$/)
423 {
251 $retval .= '.IR'; 424 $retval .= '.IR';
252 next; 425 next;
253 } 426 }
254 427
255 if (/^Pq$/) { 428 if (/^Pq$/)
429 {
256 $retval .= '('; 430 $retval .= '(';
257 $nospace = 1; 431 $nospace = 1;
258 $parens = 1; 432 $parens = 1;
259 next; 433 next;
260 } 434 }
261 435
262 if (/^(S[xy])$/) { 436 if (/^(S[xy])$/)
437 {
263 $retval .= '.B ' . join(' ', @words); 438 $retval .= '.B ' . join(' ', @words);
264 last; 439 last;
265 } 440 }
@@ -270,48 +445,83 @@ sub ParseMacro # ($line)
270 while (defined $words[0] 445 while (defined $words[0]
271 && $words[0] !~ m/^[\.,]/) 446 && $words[0] !~ m/^[\.,]/)
272 { 447 {
273 $retval .= shift @words; 448 if ($words[0] eq 'Op')
449 {
450 shift(@words);
451 $retval .= '[';
452 my $tmp = pop(@words);
453 $tmp .= ']';
454 push(@words, $tmp);
455 next;
456 }
457 if ($words[0] eq 'Ar')
458 {
459 shift @words;
460 $retval .= '\\fI';
461 $retval .= shift @words;
462 $retval .= '\\fP';
463 }
464 else
465 {
466 $retval .= shift @words;
467 }
274 $retval .= ' ' 468 $retval .= ' '
275 if (! $nospace); 469 if (! $nospace);
276 } 470 }
277 $retval =~ s/ $//; 471 $retval =~ s/ $//;
278 $retval .= '\\fR'; 472 $retval .= '\\fP';
279 $retval .= shift @words 473 $retval .= shift @words
280 if (defined $words[0]); 474 if (defined $words[0]);
281 last; 475 last;
282 } 476 }
283 477
284 if (/^Bl$/) { 478 if (/^Bl$/)
285 if ($words[0] eq '-bullet') { 479 {
480 $oldoptlist = $optlist;
481 if ($words[0] eq '-bullet')
482 {
286 $optlist = 1; 483 $optlist = 1;
287 } elsif ($words[0] eq '-enum') { 484 }
485 elsif ($words[0] eq '-enum')
486 {
288 $optlist = 2; 487 $optlist = 2;
289 $enum = 0; 488 $enum = 0;
290 } elsif ($words[0] eq '-tag') { 489 }
490 elsif ($words[0] eq '-tag')
491 {
291 $optlist = 3; 492 $optlist = 3;
292 } 493 }
494 elsif ($words[0] eq '-item')
495 {
496 $optlist = 4;
497 }
293 last; 498 last;
294 } 499 }
295 500
296 if (/^El$/) { 501 if (/^El$/)
297 $optlist = 0; 502 {
503 $optlist = $oldoptlist;
298 next; 504 next;
299 } 505 }
300 506
301 if ($optlist && /^It$/) { 507 if ($optlist && /^It$/)
302 if ($optlist == 1) { 508 {
509 if ($optlist == 1)
510 {
303 # bullets 511 # bullets
304 $retval .= '.IP \\(bu'; 512 $retval .= '.IP \\(bu';
305 next; 513 next;
306 } 514 }
307 515
308 if ($optlist == 2) { 516 if ($optlist == 2)
517 {
309 # enum 518 # enum
310 $retval .= '.IP ' . (++$enum) . '.'; 519 $retval .= '.IP ' . (++$enum) . '.';
311 next; 520 next;
312 } 521 }
313 522
314 if ($optlist == 3) { 523 if ($optlist == 3)
524 {
315 # tags 525 # tags
316 $retval .= ".TP\n"; 526 $retval .= ".TP\n";
317 if ($words[0] =~ m/^(Pa|Ev)$/) 527 if ($words[0] =~ m/^(Pa|Ev)$/)
@@ -322,14 +532,25 @@ sub ParseMacro # ($line)
322 next; 532 next;
323 } 533 }
324 534
535 if ($optlist == 4)
536 {
537 # item
538 $retval .= ".IP\n";
539 next;
540 }
541
325 next; 542 next;
326 } 543 }
327 544
328 if (/^Sm$/) { 545 if (/^Sm$/)
329 if ($words[0] eq 'off') { 546 {
547 if ($words[0] eq 'off')
548 {
330 $nospace = 2; 549 $nospace = 2;
331 } elsif ($words[0] eq 'on') { 550 }
332 $retval .= "\n"; 551 elsif ($words[0] eq 'on')
552 {
553# $retval .= "\n";
333 $nospace = 0; 554 $nospace = 0;
334 } 555 }
335 shift @words; 556 shift @words;
@@ -343,7 +564,7 @@ sub ParseMacro # ($line)
343 if ($retval eq '.'); 564 if ($retval eq '.');
344 565
345 $retval =~ s/^\.([^a-zA-Z])/$1/; 566 $retval =~ s/^\.([^a-zA-Z])/$1/;
346 $retval =~ s/ $//; 567# $retval =~ s/ $//;
347 568
348 $retval .= ')' 569 $retval .= ')'
349 if ($parens == 1); 570 if ($parens == 1);
@@ -351,14 +572,19 @@ sub ParseMacro # ($line)
351 $retval .= ']' 572 $retval .= ']'
352 if ($option == 1); 573 if ($option == 1);
353 574
354 $retval .= '\\fR' 575# $retval .= ' '
355 if ($arg); 576# if ($nospace && $retval ne '' && $retval !~ m/\n$/);
577
578# $retval .= ' '
579# if ($extended && $retval !~ m/ $/);
356 580
357 $retval .= '\\c' 581 $retval .= ' '
358 if ($nospace && $retval ne '' && $retval !~ m/\n$/); 582 if ($ext && ! $extopt && $retval !~ m/ $/);
359 583
360 $retval .= "\n" 584 $retval .= "\n"
361 if ($retval ne '' && $retval !~ m/\n$/); 585 if (! $ext && ! $extopt && $retval ne '' && $retval !~ m/\n$/);
362 586
363 return $retval; 587 return $retval;
364} 588}
589
590