4 # v3, I put the program under a proper license
5 # Dan Nelson <dnelson@allantgroup.com> added .An, .Aq and fixed a typo
6 # v2, fixed to work on GNU awk --posix and MacOS X
7 # v1, first attempt, didn't work on MacOS X
9 # Copyright (c) 2003 Peter Stuge <stuge-mdoc2man@cdy.org>
11 # Permission to use, copy, modify, and distribute this software for any
12 # purpose with or without fee is hereby granted, provided that the above
13 # copyright notice and this permission notice appear in all copies.
15 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
44 retval=retval words
[++w
]
71 nwords=split($0,words)
72 for(w=1;w<=nwords;w++) {
74 if(match(words[w],"^Li
|Pf$
")) {
76 } else if(match(words[w],"^Xo$
")) {
79 if(length(line)&&!(match(line," $
")||prenl))
81 } else if(match(words[w],"^Xc$
")) {
87 } else if(match(words[w],"^Bd$
")) {
89 if(match(words[w+1],"-literal
")) {
94 } else if(match(words[w],"^Ed$
")) {
97 } else if(match(words[w],"^Ns$
")) {
102 } else if(match(words[w],"^No$
")) {
106 } else if(match(words[w],"^Dq$
")) {
110 while(w<nwords&&!match(words[w+1],"^
[\\.
,]"))
113 if(!nospace&&match(words[w+1],"^
[\\.
,]"))
115 } else if(match(words[w],"^Sq
|Ql$
")) {
117 add("`
" words[++w] "'")
118 if(!nospace&&match(words[w+1],"^[\\.,]"))
120 } else if(match(words[w],"^Oo$")) {
126 } else if(match(words[w],"^Oc$")) {
132 if(!nospace&&length(line)&&!(match(line," $")||prenl))
137 if(match(words[w],"^Dd$")) {
140 } else if(match(words[w],"^Dt$")) {
143 } else if(match(words[w],"^Os$")) {
144 add(".TH " id " \"" date "\" \"" wtail() "\"")
145 } else if(match(words[w],"^Sh$")) {
147 synopsis=match(words[w+1],"SYNOPSIS")
148 } else if(match(words[w],"^Xr$")) {
149 add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
150 } else if(match(words[w],"^Rs$")) {
159 } else if(match(words[w],"^Re$")) {
161 for(i=nrefauthors-1;i>0;i--) {
168 add(refauthors[0] ", \\fI" reftitle "\\fP")
177 } else if(reference) {
178 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
179 if(match(words[w],"^%T$")) {
181 sub("^\"","",reftitle)
182 sub("\"$","",reftitle)
184 if(match(words[w],"^%N$")) { refissue=wtail() }
185 if(match(words[w],"^%D$")) { refdate=wtail() }
186 if(match(words[w],"^%O$")) { refopt=wtail() }
187 } else if(match(words[w],"^Nm$")) {
198 if(!nospace&&match(words[w+1],"^[\\.,]"))
200 } else if(match(words[w],"^Nd$")) {
202 } else if(match(words[w],"^Fl$")) {
203 add("\\fB\\-" words[++w] "\\fP")
204 if(!nospace&&match(words[w+1],"^[\\.,]"))
206 } else if(match(words[w],"^Ar$")) {
211 add(words[++w] "\\fP")
212 while(match(words[w+1],"^\\|$"))
213 add(OFS words[++w] " \\fI" words[++w] "\\fP")
215 if(!nospace&&match(words[w+1],"^[\\.,]"))
217 } else if(match(words[w],"^Cm$")) {
218 add("\\fB" words[++w] "\\fP")
219 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
221 } else if(match(words[w],"^Op$")) {
226 } else if(match(words[w],"^Pp$")) {
228 } else if(match(words[w],"^An$")) {
230 } else if(match(words[w],"^Ss$")) {
232 } else if(match(words[w],"^Pa$")&&!option) {
235 if(match(words[w],"^\\."))
238 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
240 } else if(match(words[w],"^Dv$")) {
242 } else if(match(words[w],"^Em|Ev$")) {
244 } else if(match(words[w],"^Pq$")) {
248 } else if(match(words[w],"^Aq$")) {
252 } else if(match(words[w],"^S[xy]$")) {
254 } else if(match(words[w],"^Ic$")) {
259 if(match(words[w],"^Op$")) {
262 words[nwords]=words[nwords] "]"
264 if(match(words[w],"^Ar$")) {
265 add("\\fI" words[++w] "\\fP")
266 } else if(match(words[w],"^[\\.,]")) {
286 } else if(match(words[w],"^Bl$")) {
288 if(match(words[w+1],"-bullet"))
290 else if(match(words[w+1],"-enum")) {
293 } else if(match(words[w+1],"-tag"))
295 else if(match(words[w+1],"-item"))
297 else if(match(words[w+1],"-bullet"))
300 } else if(match(words[w],"^El$")) {
302 } else if(match(words[w],"^Bk$")) {
303 if(match(words[w+1],"-words")) {
307 } else if(match(words[w],"^Ek$")) {
309 } else if(match(words[w],"^It$")&&optlist) {
313 add(".IP " ++enum ".")
314 else if(optlist==3) {
317 if(match(words[w+1],"^Pa$|^Ev$")) {
321 } else if(optlist==4)
323 } else if(match(words[w],"^Sm$")) {
324 if(match(words[w+1],"off"))
326 else if(match(words[w+1],"on"))
333 if(match(line,"^\\.[^a-zA-Z]"))
341 if(ext&&!extopt&&!match(line," $"))
343 if(!ext&&!extopt&&length(line)) {