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],"^Ox$")) {
146 } else if(match(words[w],"^Os$")) {
147 add(".TH " id " \"" date "\" \"" wtail() "\"")
148 } else if(match(words[w],"^Sh$")) {
150 synopsis=match(words[w+1],"SYNOPSIS")
151 } else if(match(words[w],"^Xr$")) {
152 add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
153 } else if(match(words[w],"^Rs$")) {
162 } else if(match(words[w],"^Re$")) {
164 for(i=nrefauthors-1;i>0;i--) {
171 add(refauthors[0] ", \\fI" reftitle "\\fP")
180 } else if(reference) {
181 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
182 if(match(words[w],"^%T$")) {
184 sub("^\"","",reftitle)
185 sub("\"$","",reftitle)
187 if(match(words[w],"^%N$")) { refissue=wtail() }
188 if(match(words[w],"^%D$")) { refdate=wtail() }
189 if(match(words[w],"^%O$")) { refopt=wtail() }
190 } else if(match(words[w],"^Nm$")) {
201 if(!nospace&&match(words[w+1],"^[\\.,]"))
203 } else if(match(words[w],"^Nd$")) {
205 } else if(match(words[w],"^Fl$")) {
206 add("\\fB\\-" words[++w] "\\fP")
207 if(!nospace&&match(words[w+1],"^[\\.,]"))
209 } else if(match(words[w],"^Ar$")) {
214 add(words[++w] "\\fP")
215 while(match(words[w+1],"^\\|$"))
216 add(OFS words[++w] " \\fI" words[++w] "\\fP")
218 if(!nospace&&match(words[w+1],"^[\\.,]"))
220 } else if(match(words[w],"^Cm$")) {
221 add("\\fB" words[++w] "\\fP")
222 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
224 } else if(match(words[w],"^Op$")) {
229 } else if(match(words[w],"^Pp$")) {
231 } else if(match(words[w],"^An$")) {
233 } else if(match(words[w],"^Ss$")) {
235 } else if(match(words[w],"^Pa$")&&!option) {
238 if(match(words[w],"^\\."))
241 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
243 } else if(match(words[w],"^Dv$")) {
245 } else if(match(words[w],"^Em|Ev$")) {
247 } else if(match(words[w],"^Pq$")) {
251 } else if(match(words[w],"^Aq$")) {
255 } else if(match(words[w],"^S[xy]$")) {
257 } else if(match(words[w],"^Ic$")) {
262 if(match(words[w],"^Op$")) {
265 words[nwords]=words[nwords] "]"
267 if(match(words[w],"^Ar$")) {
268 add("\\fI" words[++w] "\\fP")
269 } else if(match(words[w],"^[\\.,]")) {
289 } else if(match(words[w],"^Bl$")) {
291 if(match(words[w+1],"-bullet"))
293 else if(match(words[w+1],"-enum")) {
296 } else if(match(words[w+1],"-tag"))
298 else if(match(words[w+1],"-item"))
300 else if(match(words[w+1],"-bullet"))
303 } else if(match(words[w],"^El$")) {
305 } else if(match(words[w],"^Bk$")) {
306 if(match(words[w+1],"-words")) {
310 } else if(match(words[w],"^Ek$")) {
312 } else if(match(words[w],"^It$")&&optlist) {
316 add(".IP " ++enum ".")
317 else if(optlist==3) {
320 if(match(words[w+1],"^Pa$|^Ev$")) {
324 } else if(optlist==4)
326 } else if(match(words[w],"^Sm$")) {
327 if(match(words[w+1],"off"))
329 else if(match(words[w+1],"on"))
336 if(match(line,"^\\.[^a-zA-Z]"))
344 if(ext&&!extopt&&!match(line," $"))
346 if(!ext&&!extopt&&length(line)) {