3 ### Quick usage: mdoc2man.pl < mdoc_manpage.8 > doc_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, $nospace, $enum, $synopsis);
46 $optlist = 0; ### 1 = bullet, 2 = enum, 3 = tag
50 while ($line = <STDIN>)
63 $line = ParseMacro($line);
70 sub ParseMacro # ($line)
73 my (@words, $retval, $option, $parens, $arg);
75 @words = split(/\s+/, $line);
81 # print('@words = ', scalar(@words), ': ', join(' ', @words), "\n");
83 while ($_ = shift @words)
88 if (/^(Li|Pf|X[oc])$/);
101 $retval .= shift @words;
106 $retval .= '``' . (shift @words) . '\'\'';
108 if (! $nospace && $words[0] =~ m/^[\.,]/);
113 $retval .= '`' . (shift @words) . '\'';
115 if (! $nospace && $words[0] =~ m/^[\.,]/);
120 if (! $nospace && $retval ne '' && $retval !~ m/[\n ]$/);
125 $date = join(' ', @words);
130 $id = join(' ', @words);
145 if ($words[0] eq 'SYNOPSIS')
157 $retval .= '\\fB' . (shift @words) .
158 '\\fR(' . (shift @words) . ')'
168 $retval .= "\\fB$name\\fR";
170 if (! $nospace && $words[0] =~ m/^[\.,]/);
180 $retval .= '\\fB\\-' . (shift @words) . '\\fR';
182 if (! $nospace && $words[0] =~ m/^[\.,]/);
188 if (! defined $words[0])
190 $retval .= 'file ...\\fR';
199 $retval .= '\\fB' . (shift @words) . '\\fR';
235 if (/^Pa$/ && ! $option) {
238 if ($words[0] =~ m/^\./);
239 $retval .= (shift @words) . '\\fR';
241 if (! $nospace && $words[0] =~ m/^[\.,]/);
263 $retval .= '.B ' . join(' ', @words);
270 while (defined $words[0]
271 && $words[0] !~ m/^[\.,]/)
273 $retval .= shift @words;
279 $retval .= shift @words
280 if (defined $words[0]);
285 if ($words[0] eq '-bullet') {
287 } elsif ($words[0] eq '-enum') {
290 } elsif ($words[0] eq '-tag') {
301 if ($optlist && /^It$/) {
304 $retval .= '.IP \\(bu';
310 $retval .= '.IP ' . (++$enum) . '.';
317 if ($words[0] =~ m/^(Pa|Ev)$/)
329 if ($words[0] eq 'off') {
331 } elsif ($words[0] eq 'on') {
345 $retval =~ s/^\.([^a-zA-Z])/$1/;
358 if ($nospace && $retval ne '' && $retval !~ m/\n$/);
361 if ($retval ne '' && $retval !~ m/\n$/);