"Fossies" - the Fresh Open Source Software Archive 
Member "xzgv-0.9.2/doc/makeman.awk" (3 Sep 2017, 9506 Bytes) of package /linux/misc/old/xzgv-0.9.2.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) (G)AWK source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/usr/bin/gawk -f
2 #
3 # makeman - make xzgv man page from texinfo file.
4 # Public domain by Russell Marks.
5 #
6 # Requires gawk (it uses `gensub' (gawk only?) and `[:blank:]' (POSIX)).
7 #
8 # Note that this *IS NOT* a general texinfo to man page converter.
9 # It only supports the bare minimum required by xzgv.texi.
10 # It could probably be generalised to cope with most stuff though.
11
12 # BTW, I'm serious about that "bare minimum" bit - if I use more stuff
13 # in xzgv.texi, this is likely to need fixing to cope with it. :-)
14
15
16 BEGIN \
17 {
18 last_was_blank=1
19 exit_val=0
20
21 print ".\\\" *** Auto-generated by makeman, *edits will be lost*! ***"
22 print ".\\\""
23 print ".\\\""
24 }
25
26
27 function do_header()
28 {
29 # man page header
30
31 print ".TH XZGV 1 \"" var_value["UPDATED"] "\" " \
32 "\"Version " var_value["VERSION"] "\" \"Graphics Software\""
33 print ".SH NAME"
34 print "xzgv \\- picture viewer for X, with thumbnail-based file selector"
35 print ".\\\""
36
37 print ".SH SYNOPSIS"
38 print "xzgv [\\fIoptions\\fR] [\\fIdir\\fR | \\fIfile\\fR ...]"
39 }
40
41 END \
42 {
43 print ".SH AUTHOR"
44 print "Russell Marks <rus@svgalib.org> and others;"
45 print "see the section \\fBACKNOWLEDGEMENTS\\fR for details."
46 print ".PP"
47 print ".SH \"SEE ALSO\""
48 print ".BR zgv \"(1),\""
49 print ".BR xv \"(1),\""
50 print ".BR cjpeg \"(1), \" djpeg \"(1),\""
51 print ".BR pbm \"(5), \" pgm \"(5), \" ppm \"(5),\""
52 print ".BR mrf \"(5)\""
53
54 # should be last thing
55 exit exit_val
56 }
57
58
59
60 function add_line_to_para(line)
61 {
62 if(para=="")
63 { para=line }
64 else
65 { para=para "\n" line }
66 }
67
68
69 # output para, splitting at LFs as we go in order to escape dots.
70 function output_para( lhs)
71 {
72 while(para ~ /\n/)
73 {
74 lhs=gensub(/^([^\n]*)\n.*/, "\\1", "g", para)
75 para=gensub(/^[^\n]*\n(.*)/, "\\1", "g", para)
76
77 # if it begins with .[^A-Z], escape the dot so troff ignores it.
78 # The assumption is that this catches things like ".xvpics",
79 # while leaving things like ".PP" alone.
80 # The \f. bit is so it catches them after a font-change too
81 # (curiously, dot-commands seem to count even after that!).
82 # We have to allow .br though, which complicates it. :-/
83 #
84 # We assume no lines start with ' (which isn't handled here).
85 #
86 if(lhs ~ /^(\\f.)?\.[^A-Z]/ && lhs !~ /^\.br/)
87 {
88 # it's such fun escaping a dot in troff :-(((
89 # @-cmds have been dealt with by now, so /^@/ should be unlikely.
90 print ".cc @\n" lhs "\n@cc ."
91 }
92 else
93 print lhs
94 }
95
96 # XXX ugly duplication here, should restructure so I don't need this
97 #
98 lhs=para
99 if(lhs!="")
100 {
101 if(lhs ~ /^(\\f.)?\.[^A-Z]/ && lhs !~ /^\.br/)
102 {
103 print ".cc @\n" lhs "\n@cc ."
104 }
105 else
106 print lhs
107 }
108 }
109
110
111
112 # first, keep copy of previous line available.
113
114 { prevline=curline_orig; curline_orig=$0 }
115
116
117 /@c(omment)?\>/ \
118 {
119 sub(/@c.*/,"")
120 if($0=="")
121 {
122 # that's right, this *is* a revolting kludge... :-)
123 # (it's a special-case hack to avoid gaps in @item/@itemx pairs where
124 # there's a comment in-between the two)
125 if(prevline ~ /^@item[^x]/) { last_was_blank=1 }
126 next
127 }
128 }
129
130 /^\\input texinfo\>/ { next }
131
132 /^@ifinfo\>/,/^@end ifinfo\>/ \
133 { next }
134
135 /^@ignore\>/,/^@end ignore\>/ \
136 { next }
137
138 /^@menu\>/,/^@end menu\>/ \
139 { next }
140
141 /^@author\>/ { next }
142 /^@bye\>/ { next }
143
144
145 /^@example\>/ { in_example++; next }
146 /^@end example\>/ \
147 {
148 in_example--
149 last_was_blank=1
150 add_line_to_para(".PP")
151 next
152 }
153
154
155 # section headings
156 # we ignore the `unnumbered' ones, assuming they are indexes.
157 /^@(chapter|section|subsection|subsubsection)\>/ \
158 {
159 sec_name=gensub(/^@[a-z]*[[:blank:]]*([^[:blank:]]+)/, "\\1", "g")
160 # fix some headings to make them man-page-like
161 sub(/^Overview/,"DESCRIPTION",sec_name)
162 sub(/^Invoking xzgv/,"OPTIONS",sec_name)
163
164 # chapter/section headings are in caps and are main headings (SH),
165 # subsection/subsubsection aren't, and are subheadings (SS).
166
167 if(/^@(chapter|section)/)
168 { print ".SH \"" toupper(sec_name) "\"" }
169 else
170 { print ".SS \"" sec_name "\"" }
171
172 if(sec_name=="DESCRIPTION")
173 {
174 print "(NB: This man page is automagically generated from xzgv's"
175 print "texinfo file, and so may look a bit odd."
176 print "We apologise for the inconvenience. :-))"
177 print ".PP"
178 }
179 next
180 }
181
182 # various tables
183 /^@v?table\>/ \
184 {
185 table_lvl++; table_type[table_lvl]=$2
186 first_item[table_lvl]=1
187 is_itemize[table_lvl]=0; next
188 }
189
190 /^@itemize\>/ \
191 {
192 table_lvl++; table_type[table_lvl]=$2
193 first_item[table_lvl]=1
194 is_itemize[table_lvl]=1; next
195 }
196
197 /^@end (v?table||itemize)\>/ \
198 {
199 table_lvl--
200 add_line_to_para(".RE")
201 was_tableend=1
202 next
203 }
204
205 /^@itemx?\>/ \
206 {
207 itemx=/^@itemx\>/
208
209 if(!table_lvl)
210 {
211 print "makeman:" NR ": @item outside of @table" >"/dev/stderr"
212 exit_val=1
213 next
214 }
215
216 if(is_itemize[table_lvl])
217 { $0=table_type[table_lvl] "{}" }
218 else
219 {
220 $0=gensub(/^@itemx?[[:blank:]]+(.*)/, \
221 (first_item[table_lvl]?"":".RE\n") \
222 table_type[table_lvl] "{\\1}\n.RS", 1)
223 }
224
225 first_item[table_lvl]=0
226
227 # cope with there not being any blank lines between last item's text
228 # and next @item. The regexp checks the last line wasn't an @item.
229 #
230 if(!last_was_blank && prevline !~ /^@itemx?\>/) { was_item=1 }
231 }
232
233
234 /^@set\>/ \
235 {
236 valname=$2
237 var_value[valname]=$3
238
239 i=4
240 while($(i)!="")
241 {
242 var_value[valname]=var_value[valname] " " $(i)
243 i++
244 }
245
246 next
247 }
248
249
250 /^@titlepage\>/ \
251 {
252 # given the way xzgv.texi is laid out, we know VERSION and
253 # UPDATED must be set now.
254 do_header()
255 }
256
257 # ...but ignore the titlepage stuff apart from that.
258 /^@titlepage\>/,/^@end titlepage\>/ \
259 { next }
260
261 # these ones are ignored
262 /^@[ckfv]index\>/ { last_was_blank=1;next }
263 /^@contents\>/ { next }
264 /^@dircategory\>/ { next }
265 /^@direntry\>/ { next }
266 /^@end\>/ { next }
267 /^@node\>/ { next }
268 /^@page\>/ { next }
269 /^@printindex\>/ { next }
270 /^@setchapternewpage\>/ { next }
271 /^@setfilename\>/ { next }
272 /^@settitle\>/ { next }
273 /^@subtitle\>/ { next }
274 /^@title\>/ { next }
275 /^@top\>/ { next }
276 /^@unnumbered\>/ { next }
277 /^@vskip\>/ { next }
278
279 (/^$/ && !last_was_blank) || was_item || was_tableend \
280 {
281 # before printing the paragraph, fix attribute-ish stuff (e.g. @samp{foo}).
282
283 # XXX nasty special-case hack to handle @-cmd within @-cmd :-(
284 # @var{dir|file} -> italic dir|file
285 para=gensub(/@var\{(dir|file)\}/, "\\\\fI\\1\\\\fR", "g", para)
286
287 # the one footnote used at the time of writing isn't very
288 # important (it's in the File Format Depths node), and I generally
289 # try to avoid footnotes as they're not handled that well in Info,
290 # so we just drop any footnotes.
291 para=gensub(/@footnote\{.*\}/, "", "g", para)
292
293 # @value
294 while(/@value\{/)
295 {
296 valname=gensub(/.*@value\{([^}]+)\}.*/, "\\1", 1, para)
297 para=gensub(/@value\{([^}]+)\}/, var_value[valname], 1, para)
298 }
299
300 # @{samp,file,var,cite,emph,indicateurl} -> italic
301 para=gensub(/@(samp|file|var|cite|emph|indicateurl)\{([^}]+)\}/,
302 "\\\\fI\\2\\\\fR", "g", para)
303
304 # @email{foo@@bar} -> <foo@bar>
305 # (this assumes there's an @@ in it!)
306 para=gensub(/@email\{(.*)@@([^}]+)\}/, "<\\1@\\2>", "g", para)
307
308 # @strong -> bold
309 para=gensub(/@strong\{([^}]+)\}/, "\\\\fB\\1\\\\fR", "g", para)
310
311 # @{code,kbd} -> bold in quotes
312 para=gensub(/@(code|kbd)\{([^}]+)\}/, "`\\\\fB\\2\\\\fR'", "g", para)
313
314 # @bullet -> bold `o'
315 # XXX this is crap :-)
316 para=gensub(/@bullet\{([^}]*)\}/, "\\\\fBo\\\\fR \\1", "g", para)
317
318 # @minus -> bold `-'
319 # XXX also crap...
320 para=gensub(/@minus\{([^}]*)\}/, "\\\\fB\\-\\\\fR \\1", "g", para)
321
322 # @asis -> normal
323 para=gensub(/@asis\{([^}]*)\}/, "\\1", "g", para)
324
325 # @dots{} -> ...
326 para=gensub(/@dots\{\}/, "...", "g", para)
327
328
329 # hairy hack to support five-arg form of @pxref
330 para=gensub(/@pxref\{([^,]+),([^,]*),([^,]*),([^,]+),([^,]*)\}/, \
331 "see \\\\fB\\1\\\\fR in the \\\\fI\\4\\\\fR info file", "g", para)
332
333 # XXX none of @pxref/@xref/@ref uppercase their args yet :-/
334
335 # @pxref{foo} -> see FOO (with FOO in bold)
336 para=gensub(/@pxref\{([^}]+)\}/, \
337 "see \\\\fB\\1\\\\fR", "g", para)
338
339 # @xref{foo} -> See FOO (with FOO in bold)
340 para=gensub(/@xref\{([^}]+)\}/, \
341 "See \\\\fB\\1\\\\fR", "g", para)
342
343 # @ref{foo} -> FOO (with FOO in bold)
344 para=gensub(/@ref\{([^}]+)\}/, \
345 "\\\\fB\\1\\\\fR", "g", para)
346
347
348 # finally, a bit of a kludge - replace "\fBInvoking xzgv\fR" with
349 # "\fBOptions\fR", assuming it's in a @pxref/@xref/@ref.
350 para=gensub(/\\fBInvoking xzgv\\fR/, "\\\\fBOptions\\\\fR", "g", para)
351
352 # if it still contains { or }, we probably missed something - say so.
353 if(para ~ /[\{\}]/)
354 {
355 print "makeman:" NR ": warning: output paragraph contains a brace" \
356 >"/dev/stderr"
357 exit_val=1
358 }
359
360 output_para()
361 para=""
362
363 print ".PP"
364 last_was_blank=1
365 if(was_item) { add_line_to_para($0) }
366 was_item=0
367 was_tableend=0
368 next
369 }
370
371 /^[^@]/ || /^@(file|samp|code|var|cite|emph|strong)/ { last_was_blank=0 }
372
373 # otherwise...
374 !/^$/ \
375 {
376 # if there's one we haven't handled, complain (but keep going).
377 # This only checks for start-of-line ones; the {/} check in the
378 # paragraph-output routine should catch any others.
379
380 if(/^@[a-z]+\>[^\{]/)
381 {
382 print "makeman:" NR ": unhandled texinfo command in this paragraph!" \
383 >"/dev/stderr"
384 exit_val=1
385 }
386
387 add_line_to_para($0)
388 if(in_example)
389 {
390 add_line_to_para(".br")
391 }
392 }