3 # Written by Adrian Mariano, additional features by Eric Backus,
4 # yet more features by Tim Mann.
6 # Script to translate a texinfo file into an nroff manual page.
20 $args=($#ARGV < 0) ? "stdin" : "@ARGV";
23 printf(".\\\"Do not edit this file. It was created from %s\n", $args);
24 printf(".\\\"using texi2man version %s on %s", $version, `date`);
25 printf(".\\\"If you want a typeset version, you will get better\n");
26 printf(".\\\"results with the original file.\n.\\\"\n");
30 if (s/\@c man //) { print; next; }
31 if (/\@c noman/) { $noman=1; next; }
32 if (/\@c end noman/) { $noman=0; next; }
35 if (/\@c ifman\s*(.*)/) { $doman=1; $manprefix = $1; next; }
36 if (/\@c end ifman/) { $doman=0; $manprefix = ""; next; }
38 if (/^\\input/) { next; }
40 if (/^INFO-DIR-SECTION/) { next; }
41 if (/^START-INFO-DIR-ENTRY/) { next; }
42 if (/^END-INFO-DIR-ENTRY/) { next; }
44 if (/\@titlepage/) { $title=1; next; }
45 if (/\@end titlepage/) { $title=0; next; }
46 if (/\@tex/) { $tex=1; next; }
47 if (/\@end tex/) { $tex=0; next; }
48 if (/\@ignore/) { $ignore=1; next; }
49 if (/\@end ignore/) { $ignore=0; next; }
50 if (/\@ifinfo/) { $info=1; next; }
51 if (/\@end ifinfo/) { $info=0; next; }
52 if (/\@ifhtml/) { $html=1; next; }
53 if (/\@end ifhtml/) { $html=0; next; }
54 if (/\@ifnothtml/) { next; }
55 if (/\@end ifhtml/) { next; }
56 if (/\@iftex/) { $tex=1; next; }
57 if (/\@end iftex/) { $tex=0; next; }
58 if (/\@ifnottex/) { next; }
59 if (/\@end iftex/) { next; }
60 if (!$doman && ($ignore || $html || $title || $tex || $info)) { next; }
64 s/\@cite\{([^}]*)}/\`$1\'/g;
65 s/\@code\{([^}]*)}/\`$1\'/g;
66 s/\@email\{([^}]*)}/\`$1\'/g;
67 s/\@file\{([^}]*)}/\`$1\'/g;
68 s/\@kbd\{([^}]*)}/\`$1\'/g;
69 s/\@samp\{([^}]*)}/\`$1\'/g;
70 s/\@url\{([^}]*)}/\`$1\'/g;
71 s/\@dfn\{([^}]*)}/\"$1\"/g;
72 s/\@key\{([^}]*)}/<$1>/g;
73 s/\@emph\{([^}]*)}/\\fI$1\\fR/g;
74 s/\@strong\{([^}]*)}/\\fB$1\\fR/g;
75 s/\@var\{([^}]*)}/\U$1\E/g;
76 s/\@sc\{([^}]*)}/\U$1\E/g;
78 s/\@pxref\{([^}]*)}/See \\fI$1\\fR/g;
79 s/\@xref\{([^}]*)}/See \\fI$1\\fR/g;
80 s/\@ref\{([^}]*)}/\\fI$1\\fR/g;
81 s/\@footnote\{([^}]*)}/[$1]/g;
83 s/\@copyright\{}/(C)/g;
92 s/\@value\{([^\s]+)}/$value{$1}/eg;
93 if (/\@set\s+([^\s]+)\s+(.*)$/) { $value{$1} = $2; next; }
94 if (/\@clear\s+([^\s]+)\s+(.*)$/) { delete $value{$1}; next; }
97 # If multiple items have the same description, put the items
98 # on one line, separated by commas
99 if (/\@itemx (.*)/) { printf(", $1"); $diditem=1; next; }
100 elsif ($diditem) { printf("\n"); $diditem=0; }
102 printf("%s.TP\n%s.B $1", $manprefix, $manprefix);
107 # If multiple items have the same description, put the items
110 printf("%s.TP\n%s.B $1\n", $manprefix, $manprefix);
113 if (/\@itemx (.*)/) {
114 printf("%s.PD 0\n%s.TP\n%s.B $1\n%s.PD\n",
115 $manprefix, $manprefix, $manprefix, $manprefix);
120 if (s/\@chapter (.*)/.SH \U$1\E/)
122 printf("%s%s", $manprefix, $_);
126 if (s/\@unnumbered (.*)/.SH \U$1\E/)
128 printf("%s%s", $manprefix, $_);
132 if (s/\@section (.*)/$1/)
134 printf("%s.SS %s", $manprefix, $_);
140 printf("%s.nf\n", $manprefix);
141 $manprefix = $manprefix . " ";
145 if (/\@end example/) {
146 $manprefix = substr($manprefix, 0, -4);
147 printf("%s.fi\n", $manprefix);
152 if (/\@display/) { printf("%s.nf\n", $manprefix); $example=1; next; }
153 if (/\@end display/) { printf("%s.fi\n", $manprefix); $example=0; next; }
154 if (/\@format/) { printf("%s.nf\n", $manprefix); $example=1; next; }
155 if (/\@end format/) { printf("%s.fi\n", $manprefix); $example=0; next; }
156 if (/\@smallexample/) { printf("%s.nf\n", $manprefix); $example=1; next; }
157 if (/\@end smallexample/) { printf("%s.fi\n", $manprefix); $example=0; next; }
158 if (!$example && /^\s*$/ && !$doman)
160 if ($justdidlp) { next; }
167 printf("%s.PP\n", $manprefix);
171 if (/\@include (.*)/) {
173 open($INCL, $1) or open($INCL, "../$1") or die "$1: $!";
182 printf("%s%s", $manprefix, $_);
184 if (!$doman) { $justdidlp=0; }