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);
325 $retval .= "\\fB$name\\fP";
327 if (! $nospace && $words[0] =~ m/^[\.,]/);
339 $retval .= '\\fB\\-' . (shift @words) . '\\fP';
341 if (! $nospace && $words[0] =~ m/^[\.,]/);
348 if (! defined $words[0])
350 $retval .= 'file ...\\fP';
354 $retval .= shift(@words) . '\\fP';
355 while ($words[0] eq '|')
357 $retval .= ' ' . shift(@words);
358 $retval .= ' \\fI' . shift(@words);
363 if (! $nospace && $words[0] =~ m/^[\.,]/);
369 $retval .= '\\fB' . (shift @words) . '\\fP';
370 while ($words[0] =~ m/^[\.,:)]$/)
372 $retval .= shift(@words);
383 # my $tmp = pop(@words);
385 # push(@words, $tmp);
401 if (/^Pa$/ && ! $option)
405 if ($words[0] =~ m/^\./);
406 $retval .= (shift @words) . '\\fP';
407 while ($words[0] =~ m/^[\.,:;)]$/)
409 $retval .= shift(@words);
412 # if (! $nospace && $words[0] =~ m/^[\.,:)]/);
438 $retval .= '.B ' . join(' ', @words);
445 while (defined $words[0]
446 && $words[0] !~ m/^[\.,]/)
448 if ($words[0] eq 'Op')
452 my $tmp = pop(@words);
457 if ($words[0] eq 'Ar')
461 $retval .= shift @words;
466 $retval .= shift @words;
473 $retval .= shift @words
474 if (defined $words[0]);
480 $oldoptlist = $optlist;
481 if ($words[0] eq '-bullet')
485 elsif ($words[0] eq '-enum')
490 elsif ($words[0] eq '-tag')
494 elsif ($words[0] eq '-item')
503 $optlist = $oldoptlist;
507 if ($optlist && /^It$/)
512 $retval .= '.IP \\(bu';
519 $retval .= '.IP ' . (++$enum) . '.';
527 if ($words[0] =~ m/^(Pa|Ev)$/)
547 if ($words[0] eq 'off')
551 elsif ($words[0] eq 'on')
566 $retval =~ s/^\.([^a-zA-Z])/$1/;
576 # if ($nospace && $retval ne '' && $retval !~ m/\n$/);
579 # if ($extended && $retval !~ m/ $/);
582 if ($ext && ! $extopt && $retval !~ m/ $/);
585 if (! $ext && ! $extopt && $retval ne '' && $retval !~ m/\n$/);