3 # $Id: mdoc2man.awk,v 1.9 2009/10/24 00:52:42 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],"^Ux$")) {
155 } else if(match(words[w],"^Ox$")) {
158 } else if(match(words[w],"^Os$")) {
159 add(".TH " id " \"" date "\" \"" wtail() "\"")
160 } else if(match(words[w],"^Sh$")) {
162 synopsis=match(words[w+1],"SYNOPSIS")
163 } else if(match(words[w],"^Xr$")) {
164 add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
165 } else if(match(words[w],"^Rs$")) {
175 } else if(match(words[w],"^Re$")) {
177 for(i=nrefauthors-1;i>0;i--) {
185 add(refauthors[0] ", ")
186 add("\\fI" reftitle "\\fP")
189 if(length(refreport)) {
198 } else if(reference) {
199 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
200 if(match(words[w],"^%T$")) {
202 sub("^\"","",reftitle)
203 sub("\"$","",reftitle)
205 if(match(words[w],"^%N$")) { refissue=wtail() }
206 if(match(words[w],"^%D$")) { refdate=wtail() }
207 if(match(words[w],"^%O$")) { refopt=wtail() }
208 if(match(words[w],"^%R$")) { refreport=wtail() }
209 } else if(match(words[w],"^Nm$")) {
220 if(!nospace&&match(words[w+1],"^[\\.,]"))
222 } else if(match(words[w],"^Nd$")) {
224 } else if(match(words[w],"^Fl$")) {
225 add("\\fB\\-" words[++w] "\\fP")
226 if(!nospace&&match(words[w+1],"^[\\.,]"))
228 } else if(match(words[w],"^Ar$")) {
233 add(words[++w] "\\fP")
234 while(match(words[w+1],"^\\|$"))
235 add(OFS words[++w] " \\fI" words[++w] "\\fP")
237 if(!nospace&&match(words[w+1],"^[\\.,]"))
239 } else if(match(words[w],"^Cm$")) {
240 add("\\fB" words[++w] "\\fP")
241 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
243 } else if(match(words[w],"^Op$")) {
248 } else if(match(words[w],"^Pp$")) {
250 } else if(match(words[w],"^An$")) {
252 } else if(match(words[w],"^Ss$")) {
254 } else if(match(words[w],"^Pa$")&&!option) {
257 if(match(words[w],"^\\."))
260 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
262 } else if(match(words[w],"^Dv$")) {
264 } else if(match(words[w],"^Em|Ev$")) {
266 } else if(match(words[w],"^Pq$")) {
270 } else if(match(words[w],"^Aq$")) {
274 } else if(match(words[w],"^S[xy]$")) {
276 } else if(match(words[w],"^Ic$")) {
281 if(match(words[w],"^Op$")) {
284 words[nwords]=words[nwords] "]"
286 if(match(words[w],"^Ar$")) {
287 add("\\fI" words[++w] "\\fP")
288 } else if(match(words[w],"^[\\.,]")) {
308 } else if(match(words[w],"^Bl$")) {
310 if(match(words[w+1],"-bullet"))
312 else if(match(words[w+1],"-enum")) {
315 } else if(match(words[w+1],"-tag"))
317 else if(match(words[w+1],"-item"))
319 else if(match(words[w+1],"-bullet"))
322 } else if(match(words[w],"^El$")) {
324 } else if(match(words[w],"^Bk$")) {
325 if(match(words[w+1],"-words")) {
329 } else if(match(words[w],"^Ek$")) {
331 } else if(match(words[w],"^It$")&&optlist) {
335 add(".IP " ++enum ".")
336 else if(optlist==3) {
339 if(match(words[w+1],"^Pa$|^Ev$")) {
343 } else if(optlist==4)
345 } else if(match(words[w],"^Sm$")) {
346 if(match(words[w+1],"off"))
348 else if(match(words[w+1],"on"))
355 if(match(line,"^\\.[^a-zA-Z]"))
363 if(ext&&!extopt&&!match(line," $"))
365 if(!ext&&!extopt&&length(line)) {