2 # Written by Adrian Mariano, additional features by Eric Backus,
3 # yet more features by Tim Mann.
5 # Script to translate a texinfo file into an nroff manual page.
19 $args=($#ARGV < 0) ? "stdin" : "@ARGV";
22 printf(".\\\"Do not edit this file. It was created from %s\n", $args);
23 printf(".\\\"using texi2man version %s on %s", $version, `date`);
24 printf(".\\\"If you want a typeset version, you will get better\n");
25 printf(".\\\"results with the original file.\n.\\\"\n");
29 if (s/\@c man //) { print; next; }
30 if (/\@c noman/) { $noman=1; next; }
31 if (/\@c end noman/) { $noman=0; next; }
34 if (/\@c ifman\s*(.*)/) { $doman=1; $manprefix = $1; next; }
35 if (/\@c end ifman/) { $doman=0; $manprefix = ""; next; }
37 if (/^\\input/) { next; }
39 if (/^INFO-DIR-SECTION/) { next; }
40 if (/^START-INFO-DIR-ENTRY/) { next; }
41 if (/^END-INFO-DIR-ENTRY/) { next; }
43 if (/\@titlepage/) { $title=1; next; }
44 if (/\@end titlepage/) { $title=0; next; }
45 if (/\@tex/) { $tex=1; next; }
46 if (/\@end tex/) { $tex=0; next; }
47 if (/\@ignore/) { $ignore=1; next; }
48 if (/\@end ignore/) { $ignore=0; next; }
49 if (/\@ifinfo/) { $info=1; next; }
50 if (/\@end ifinfo/) { $info=0; next; }
51 if (/\@ifhtml/) { $html=1; next; }
52 if (/\@end ifhtml/) { $html=0; next; }
53 if (/\@ifnothtml/) { next; }
54 if (/\@end ifhtml/) { next; }
55 if (/\@iftex/) { $tex=1; next; }
56 if (/\@end iftex/) { $tex=0; next; }
57 if (/\@ifnottex/) { next; }
58 if (/\@end iftex/) { next; }
59 if (!$doman && ($ignore || $html || $title || $tex || $info)) { next; }
63 s/\@cite\{([^}]*)}/\`$1\'/g;
64 s/\@code\{([^}]*)}/\`$1\'/g;
65 s/\@email\{([^}]*)}/\`$1\'/g;
66 s/\@file\{([^}]*)}/\`$1\'/g;
67 s/\@kbd\{([^}]*)}/\`$1\'/g;
68 s/\@samp\{([^}]*)}/\`$1\'/g;
69 s/\@url\{([^}]*)}/\`$1\'/g;
70 s/\@dfn\{([^}]*)}/\"$1\"/g;
71 s/\@key\{([^}]*)}/<$1>/g;
72 s/\@emph\{([^}]*)}/\\fI$1\\fR/g;
73 s/\@strong\{([^}]*)}/\\fB$1\\fR/g;
74 s/\@var\{([^}]*)}/\U$1\E/g;
75 s/\@sc\{([^}]*)}/\U$1\E/g;
77 s/\@pxref\{([^}]*)}/See \\fI$1\\fR/g;
78 s/\@xref\{([^}]*)}/See \\fI$1\\fR/g;
79 s/\@ref\{([^}]*)}/\\fI$1\\fR/g;
80 s/\@footnote\{([^}]*)}/[$1]/g;
82 s/\@copyright\{}/(C)/g;
91 s/\@value\{([^\s]+)}/$value{$1}/eg;
92 if (/\@set\s+([^\s]+)\s+(.*)$/) { $value{$1} = $2; next; }
93 if (/\@clear\s+([^\s]+)\s+(.*)$/) { delete $value{$1}; next; }
96 # If multiple items have the same description, put the items
97 # on one line, separated by commas
98 if (/\@itemx (.*)/) { printf(", $1"); $diditem=1; next; }
99 elsif ($diditem) { printf("\n"); $diditem=0; }
101 printf("%s.TP\n%s.B $1", $manprefix, $manprefix);
106 # If multiple items have the same description, put the items
109 printf("%s.TP\n%s.B $1\n", $manprefix, $manprefix);
112 if (/\@itemx (.*)/) {
113 printf("%s.PD 0\n%s.TP\n%s.B $1\n%s.PD\n",
114 $manprefix, $manprefix, $manprefix, $manprefix);
119 if (s/\@chapter (.*)/.SH \U$1\E/)
121 printf("%s%s", $manprefix, $_);
125 if (s/\@unnumbered (.*)/.SH \U$1\E/)
127 printf("%s%s", $manprefix, $_);
131 if (s/\@section (.*)/$1/)
133 printf("%s.SS %s", $manprefix, $_);
139 printf("%s.nf\n", $manprefix);
140 $manprefix = $manprefix . " ";
144 if (/\@end example/) {
145 $manprefix = substr($manprefix, 0, -4);
146 printf("%s.fi\n", $manprefix);
151 if (/\@display/) { printf("%s.nf\n", $manprefix); $example=1; next; }
152 if (/\@end display/) { printf("%s.fi\n", $manprefix); $example=0; next; }
153 if (/\@format/) { printf("%s.nf\n", $manprefix); $example=1; next; }
154 if (/\@end format/) { printf("%s.fi\n", $manprefix); $example=0; next; }
155 if (/\@smallexample/) { printf("%s.nf\n", $manprefix); $example=1; next; }
156 if (/\@end smallexample/) { printf("%s.fi\n", $manprefix); $example=0; next; }
157 if (!$example && /^\s*$/ && !$doman)
159 if ($justdidlp) { next; }
166 printf("%s.PP\n", $manprefix);
170 if (/\@include (.*)/) {
172 open($INCL, $1) or open($INCL, "../$1") or die "$1: $!";
181 printf("%s%s", $manprefix, $_);
183 if (!$doman) { $justdidlp=0; }