-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtexi2man
executable file
·189 lines (170 loc) · 4.94 KB
/
texi2man
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/perl
# Written by Adrian Mariano, additional features by Eric Backus,
# yet more features by Tim Mann.
# Script to translate a texinfo file into an nroff manual page.
$version="1.01.tpm1";
$html=0;
$ignore=0;
$tex=0;
$doman=0;
$title=0;
$diditem=0;
$justdidlp=1;
$noman=0;
$info=0;
$manprefix="";
$args=($#ARGV < 0) ? "stdin" : "@ARGV";
$itemxcomma=0;
printf(".\\\"Do not edit this file. It was created from %s\n", $args);
printf(".\\\"using texi2man version %s on %s", $version, `date`);
printf(".\\\"If you want a typeset version, you will get better\n");
printf(".\\\"results with the original file.\n.\\\"\n");
sub parse
{
if (s/\@c man //) { print; next; }
if (/\@c noman/) { $noman=1; next; }
if (/\@c end noman/) { $noman=0; next; }
if ($noman) { next; }
if (/\@c ifman\s*(.*)/) { $doman=1; $manprefix = $1; next; }
if (/\@c end ifman/) { $doman=0; $manprefix = ""; next; }
if (/^\\input/) { next; }
if (/^\*/) { next; }
if (/^INFO-DIR-SECTION/) { next; }
if (/^START-INFO-DIR-ENTRY/) { next; }
if (/^END-INFO-DIR-ENTRY/) { next; }
if (/\@titlepage/) { $title=1; next; }
if (/\@end titlepage/) { $title=0; next; }
if (/\@tex/) { $tex=1; next; }
if (/\@end tex/) { $tex=0; next; }
if (/\@ignore/) { $ignore=1; next; }
if (/\@end ignore/) { $ignore=0; next; }
if (/\@ifinfo/) { $info=1; next; }
if (/\@end ifinfo/) { $info=0; next; }
if (/\@ifhtml/) { $html=1; next; }
if (/\@end ifhtml/) { $html=0; next; }
if (/\@ifnothtml/) { next; }
if (/\@end ifhtml/) { next; }
if (/\@iftex/) { $tex=1; next; }
if (/\@end iftex/) { $tex=0; next; }
if (/\@ifnottex/) { next; }
if (/\@end iftex/) { next; }
if (!$doman && ($ignore || $html || $title || $tex || $info)) { next; }
s/\\/\\\\/g;
s/\@-/\\-/g;
s/\@cite\{([^}]*)}/\`$1\'/g;
s/\@code\{([^}]*)}/\`$1\'/g;
s/\@email\{([^}]*)}/\`$1\'/g;
s/\@file\{([^}]*)}/\`$1\'/g;
s/\@kbd\{([^}]*)}/\`$1\'/g;
s/\@samp\{([^}]*)}/\`$1\'/g;
s/\@url\{([^}]*)}/\`$1\'/g;
s/\@dfn\{([^}]*)}/\"$1\"/g;
s/\@key\{([^}]*)}/<$1>/g;
s/\@emph\{([^}]*)}/\\fI$1\\fR/g;
s/\@strong\{([^}]*)}/\\fB$1\\fR/g;
s/\@var\{([^}]*)}/\U$1\E/g;
s/\@sc\{([^}]*)}/\U$1\E/g;
s/\@w\{([^}]*)}/$1/g;
s/\@pxref\{([^}]*)}/See \\fI$1\\fR/g;
s/\@xref\{([^}]*)}/See \\fI$1\\fR/g;
s/\@ref\{([^}]*)}/\\fI$1\\fR/g;
s/\@footnote\{([^}]*)}/[$1]/g;
s/\@minus\{}/-/g;
s/\@copyright\{}/(C)/g;
s/\@noindent//;
s/\@\{/{/g;
s/\@}/}/g;
s/\@\@/@/g;
s/\\'\\'/\"/g;
s/\\`\\`/\"/g;
s/---/ -- /g;
s/\@value\{([^\s]+)}/$value{$1}/eg;
if (/\@set\s+([^\s]+)\s+(.*)$/) { $value{$1} = $2; next; }
if (/\@clear\s+([^\s]+)\s+(.*)$/) { delete $value{$1}; next; }
if ($itemxcomma) {
# If multiple items have the same description, put the items
# on one line, separated by commas
if (/\@itemx (.*)/) { printf(", $1"); $diditem=1; next; }
elsif ($diditem) { printf("\n"); $diditem=0; }
if (/\@item (.*)/) {
printf("%s.TP\n%s.B $1", $manprefix, $manprefix);
$diditem=1;
next;
}
} else {
# If multiple items have the same description, put the items
# on separate lines
if (/\@item (.*)/) {
printf("%s.TP\n%s.B $1\n", $manprefix, $manprefix);
next;
}
if (/\@itemx (.*)/) {
printf("%s.PD 0\n%s.TP\n%s.B $1\n%s.PD\n",
$manprefix, $manprefix, $manprefix, $manprefix);
next;
}
}
if (s/\@chapter (.*)/.SH \U$1\E/)
{
printf("%s%s", $manprefix, $_);
$justdidlp=1;
next;
}
if (s/\@unnumbered (.*)/.SH \U$1\E/)
{
printf("%s%s", $manprefix, $_);
$justdidlp=1;
next;
}
if (s/\@section (.*)/$1/)
{
printf("%s.SS %s", $manprefix, $_);
$justdidlp=1;
next;
}
if (/\@example/) {
printf("%s.nf\n", $manprefix);
$manprefix = $manprefix . " ";
$example=1;
next;
}
if (/\@end example/) {
$manprefix = substr($manprefix, 0, -4);
printf("%s.fi\n", $manprefix);
$example=0;
next;
}
if (/\@display/) { printf("%s.nf\n", $manprefix); $example=1; next; }
if (/\@end display/) { printf("%s.fi\n", $manprefix); $example=0; next; }
if (/\@format/) { printf("%s.nf\n", $manprefix); $example=1; next; }
if (/\@end format/) { printf("%s.fi\n", $manprefix); $example=0; next; }
if (/\@smallexample/) { printf("%s.nf\n", $manprefix); $example=1; next; }
if (/\@end smallexample/) { printf("%s.fi\n", $manprefix); $example=0; next; }
if (!$example && /^\s*$/ && !$doman)
{
if ($justdidlp) { next; }
# printf(".PP\n");
printf("\n");
$justdidlp=1;
next;
}
if (/\@end table/) {
printf("%s.PP\n", $manprefix);
$justdidlp=1;
}
if (/\@include (.*)/) {
my $INCL;
open($INCL, $1) or open($INCL, "../$1") or die "$1: $!";
while (<$INCL>) {
parse();
}
next;
}
if (/^\@/) { next; }
printf("%s%s", $manprefix, $_);
if (!$doman) { $justdidlp=0; }
}
while(<>)
{
parse();
}