3 ### Quick usage: mdoc2man.pl < mdoc_manpage.8 > man_manpage.8
6 ### Copyright (c) 2001 University of Illinois Board of Trustees
7 ### Copyright (c) 2001 Mark D. Roth
8 ### All rights reserved.
10 ### Redistribution and use in source and binary forms, with or without
11 ### modification, are permitted provided that the following conditions
13 ### 1. Redistributions of source code must retain the above copyright
14 ### notice, this list of conditions and the following disclaimer.
15 ### 2. Redistributions in binary form must reproduce the above copyright
16 ### notice, this list of conditions and the following disclaimer in the
17 ### documentation and/or other materials provided with the distribution.
18 ### 3. All advertising materials mentioning features or use of this software
19 ### must display the following acknowledgement:
20 ### This product includes software developed by the University of
21 ### Illinois at Urbana, and their contributors.
22 ### 4. The University nor the names of their
23 ### contributors may be used to endorse or promote products derived from
24 ### this software without specific prior written permission.
26 ### THIS SOFTWARE IS PROVIDED BY THE TRUSTEES AND CONTRIBUTORS ``AS IS'' AND
27 ### ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 ### IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 ### ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR CONTRIBUTORS BE LIABLE
30 ### FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 ### DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 ### OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 ### HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 ### LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 ### OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 my ($name, $date, $id);
43 my ($optlist, $oldoptlist, $nospace, $enum, $synopsis);
44 my ($reference, $block, $ext, $extopt, $literal);
45 my (@refauthors, $reftitle, $refissue, $refdate, $refopt);
48 $optlist = 0; ### 1 = bullet, 2 = enum, 3 = tag, 4 = item
58 while ($line = <STDIN>)
73 $line = ParseMacro($line);
80 sub ParseMacro # ($line)
83 my (@words, $retval, $option, $parens);
85 @words = split(/\s+/, $line);
90 # print('@words = ', scalar(@words), ': ', join(' ', @words), "\n");
92 while ($_ = shift @words)
103 if ($retval ne '' && $retval !~ m/[\n ]$/);
118 if ($words[0] eq '-literal');
140 $retval .= shift @words;
149 $retval .= (shift @words) . ' ';
151 while (@words > 0 && $words[0] !~ m/^[\.,]/);
155 if (! $nospace && $words[0] =~ m/^[\.,]/);
161 $retval .= '`' . (shift @words) . '\'';
163 if (! $nospace && $words[0] =~ m/^[\.,]/);
169 # $retval .= '\\fB' . shift(@words) . '\\fP';
175 # $retval .= "[\\c\n";
191 if (! $nospace && $retval ne '' && $retval !~ m/[\n ]$/);
197 $date = join(' ', @words);
203 $id = join(' ', @words);
220 if ($words[0] eq 'SYNOPSIS')
233 $retval .= '\\fB' . (shift @words) .
234 '\\fP(' . (shift @words) . ')'
255 while (scalar(@refauthors) > 1)
257 $retval .= shift(@refauthors) . ', ';
261 $retval .= shift(@refauthors);
264 $retval .= ', \\fI' . $reftitle . '\\fP';
267 $retval .= ', ' . $refissue
268 if ($refissue ne '');
271 $retval .= ', ' . $refdate
275 $retval .= ', ' . $refopt
288 unshift(@refauthors, join(' ', @words));
294 $reftitle = join(' ', @words);
302 $refissue = join(' ', @words);
308 $refdate = join(' ', @words);
314 $refopt = join(' ', @words);
324 $name = $n unless $name;
327 $retval .= "\\fB$n\\fP";
329 if (! $nospace && $words[0] =~ m/^[\.,]/);
341 $retval .= '\\fB\\-' . (shift @words) . '\\fP';
343 if (! $nospace && $words[0] =~ m/^[\.,]/);
350 if (! defined $words[0])
352 $retval .= 'file ...\\fP';
356 $retval .= shift(@words) . '\\fP';
357 while ($words[0] eq '|')
359 $retval .= ' ' . shift(@words);
360 $retval .= ' \\fI' . shift(@words);
365 if (! $nospace && $words[0] =~ m/^[\.,]/);
371 $retval .= '\\fB' . (shift @words) . '\\fP';
372 while ($words[0] =~ m/^[\.,:)]$/)
374 $retval .= shift(@words);
385 # my $tmp = pop(@words);
387 # push(@words, $tmp);
403 if (/^Pa$/ && ! $option)
407 if ($words[0] =~ m/^\./);
408 $retval .= (shift @words) . '\\fP';
409 while ($words[0] =~ m/^[\.,:;)]$/)
411 $retval .= shift(@words);
414 # if (! $nospace && $words[0] =~ m/^[\.,:)]/);
440 $retval .= '.B ' . join(' ', @words);
447 while (defined $words[0]
448 && $words[0] !~ m/^[\.,]/)
450 if ($words[0] eq 'Op')
454 my $tmp = pop(@words);
459 if ($words[0] eq 'Ar')
463 $retval .= shift @words;
468 $retval .= shift @words;
475 $retval .= shift @words
476 if (defined $words[0]);
482 $oldoptlist = $optlist;
483 if ($words[0] eq '-bullet')
487 elsif ($words[0] eq '-enum')
492 elsif ($words[0] eq '-tag')
496 elsif ($words[0] eq '-item')
505 $optlist = $oldoptlist;
509 if ($optlist && /^It$/)
514 $retval .= '.IP \\(bu';
521 $retval .= '.IP ' . (++$enum) . '.';
529 if ($words[0] =~ m/^(Pa|Ev)$/)
549 if ($words[0] eq 'off')
553 elsif ($words[0] eq 'on')
568 $retval =~ s/^\.([^a-zA-Z])/$1/;
578 # if ($nospace && $retval ne '' && $retval !~ m/\n$/);
581 # if ($extended && $retval !~ m/ $/);
584 if ($ext && ! $extopt && $retval !~ m/ $/);
587 if (! $ext && ! $extopt && $retval ne '' && $retval !~ m/\n$/);