3 # $Id: mdoc2man.awk,v 1.8 2007/06/05 10:01:16 dtucker Exp $
6 # v4+ Adapted for OpenSSH Portable (see cvs Id and history)
7 # v3, I put the program under a proper license
8 # Dan Nelson <dnelson@allantgroup.com> added .An, .Aq and fixed a typo
9 # v2, fixed to work on GNU awk --posix and MacOS X
10 # v1, first attempt, didn't work on MacOS X
12 # Copyright (c) 2003 Peter Stuge <stuge-mdoc2man@cdy.org>
14 # Permission to use, copy, modify, and distribute this software for any
15 # purpose with or without fee is hereby granted, provided that the above
16 # copyright notice and this permission notice appear in all copies.
18 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
19 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
20 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
21 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
23 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
24 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
47 retval=retval words
[++w
]
74 nwords=split($0,words)
75 for(w=1;w<=nwords;w++) {
77 if(match(words[w],"^Li
|Pf$
")) {
79 } else if(match(words[w],"^Xo$
")) {
82 if(length(line)&&!(match(line," $
")||prenl))
84 } else if(match(words[w],"^Xc$
")) {
90 } else if(match(words[w],"^Bd$
")) {
92 if(match(words[w+1],"-literal
")) {
97 } else if(match(words[w],"^Ed$
")) {
100 } else if(match(words[w],"^Ns$
")) {
105 } else if(match(words[w],"^No$
")) {
109 } else if(match(words[w],"^Dq$
")) {
113 while(w<nwords&&!match(words[w+1],"^
[\\.
,]"))
116 if(!nospace&&match(words[w+1],"^
[\\.
,]"))
118 } else if(match(words[w],"^Sq
|Ql$
")) {
120 add("`
" words[++w] "'")
121 if(!nospace&&match(words[w+1],"^[\\.,]"))
123 } else if(match(words[w],"^Oo$")) {
129 } else if(match(words[w],"^Oc$")) {
135 if(!nospace&&length(line)&&!(match(line," $")||prenl))
140 if(match(words[w],"^Dd$")) {
141 if(match(words[w+1],"^\\$Mdocdate:")) {
143 if(match(words[w+4],"^\\$$")) {
149 } else if(match(words[w],"^Dt$")) {
152 } else if(match(words[w],"^Ox$")) {
155 } else if(match(words[w],"^Os$")) {
156 add(".TH " id " \"" date "\" \"" wtail() "\"")
157 } else if(match(words[w],"^Sh$")) {
159 synopsis=match(words[w+1],"SYNOPSIS")
160 } else if(match(words[w],"^Xr$")) {
161 add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
162 } else if(match(words[w],"^Rs$")) {
172 } else if(match(words[w],"^Re$")) {
174 for(i=nrefauthors-1;i>0;i--) {
182 add(refauthors[0] ", ")
183 add("\\fI" reftitle "\\fP")
186 if(length(refreport)) {
195 } else if(reference) {
196 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
197 if(match(words[w],"^%T$")) {
199 sub("^\"","",reftitle)
200 sub("\"$","",reftitle)
202 if(match(words[w],"^%N$")) { refissue=wtail() }
203 if(match(words[w],"^%D$")) { refdate=wtail() }
204 if(match(words[w],"^%O$")) { refopt=wtail() }
205 if(match(words[w],"^%R$")) { refreport=wtail() }
206 } else if(match(words[w],"^Nm$")) {
217 if(!nospace&&match(words[w+1],"^[\\.,]"))
219 } else if(match(words[w],"^Nd$")) {
221 } else if(match(words[w],"^Fl$")) {
222 add("\\fB\\-" words[++w] "\\fP")
223 if(!nospace&&match(words[w+1],"^[\\.,]"))
225 } else if(match(words[w],"^Ar$")) {
230 add(words[++w] "\\fP")
231 while(match(words[w+1],"^\\|$"))
232 add(OFS words[++w] " \\fI" words[++w] "\\fP")
234 if(!nospace&&match(words[w+1],"^[\\.,]"))
236 } else if(match(words[w],"^Cm$")) {
237 add("\\fB" words[++w] "\\fP")
238 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
240 } else if(match(words[w],"^Op$")) {
245 } else if(match(words[w],"^Pp$")) {
247 } else if(match(words[w],"^An$")) {
249 } else if(match(words[w],"^Ss$")) {
251 } else if(match(words[w],"^Pa$")&&!option) {
254 if(match(words[w],"^\\."))
257 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
259 } else if(match(words[w],"^Dv$")) {
261 } else if(match(words[w],"^Em|Ev$")) {
263 } else if(match(words[w],"^Pq$")) {
267 } else if(match(words[w],"^Aq$")) {
271 } else if(match(words[w],"^S[xy]$")) {
273 } else if(match(words[w],"^Ic$")) {
278 if(match(words[w],"^Op$")) {
281 words[nwords]=words[nwords] "]"
283 if(match(words[w],"^Ar$")) {
284 add("\\fI" words[++w] "\\fP")
285 } else if(match(words[w],"^[\\.,]")) {
305 } else if(match(words[w],"^Bl$")) {
307 if(match(words[w+1],"-bullet"))
309 else if(match(words[w+1],"-enum")) {
312 } else if(match(words[w+1],"-tag"))
314 else if(match(words[w+1],"-item"))
316 else if(match(words[w+1],"-bullet"))
319 } else if(match(words[w],"^El$")) {
321 } else if(match(words[w],"^Bk$")) {
322 if(match(words[w+1],"-words")) {
326 } else if(match(words[w],"^Ek$")) {
328 } else if(match(words[w],"^It$")&&optlist) {
332 add(".IP " ++enum ".")
333 else if(optlist==3) {
336 if(match(words[w+1],"^Pa$|^Ev$")) {
340 } else if(optlist==4)
342 } else if(match(words[w],"^Sm$")) {
343 if(match(words[w+1],"off"))
345 else if(match(words[w+1],"on"))
352 if(match(line,"^\\.[^a-zA-Z]"))
360 if(ext&&!extopt&&!match(line," $"))
362 if(!ext&&!extopt&&length(line)) {