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.
43 retval=retval words[++w]
70 nwords=split($0,words)
71 for(w=1;w<=nwords;w++) {
73 if(match(words[w],"^Li|Pf$")) {
75 } else if(match(words[w],"^Xo$")) {
78 if(length(line)&&!(match(line," $")||prenl))
80 } else if(match(words[w],"^Xc$")) {
86 } else if(match(words[w],"^Bd$")) {
88 if(match(words[w+1],"-literal")) {
93 } else if(match(words[w],"^Ed$")) {
96 } else if(match(words[w],"^Ns$")) {
101 } else if(match(words[w],"^No$")) {
105 } else if(match(words[w],"^Dq$")) {
109 while(w<nwords&&!match(words[w+1],"^[\\.,]"))
112 if(!nospace&&match(words[w+1],"^[\\.,]"))
114 } else if(match(words[w],"^Sq|Ql$")) {
116 add("`" words[++w] "'")
117 if(!nospace&&match(words[w+1],"^[\\.,]"))
119 } else if(match(words[w],"^Oo$")) {
125 } else if(match(words[w],"^Oc$")) {
131 if(!nospace&&length(line)&&!(match(line," $")||prenl))
136 if(match(words[w],"^Dd$")) {
139 } else if(match(words[w],"^Dt$")) {
142 } else if(match(words[w],"^Os$")) {
143 add(".TH " id " \"" date "\" \"" wtail() "\"")
144 } else if(match(words[w],"^Sh$")) {
146 synopsis=match(words[w+1],"SYNOPSIS")
147 } else if(match(words[w],"^Xr$")) {
148 add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
149 } else if(match(words[w],"^Rs$")) {
158 } else if(match(words[w],"^Re$")) {
160 for(i=nrefauthors-1;i>0;i--) {
167 add(refauthors[0] ", \\fI" reftitle "\\fP")
176 } else if(reference) {
177 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
178 if(match(words[w],"^%T$")) {
180 sub("^\"","",reftitle)
181 sub("\"$","",reftitle)
183 if(match(words[w],"^%N$")) { refissue=wtail() }
184 if(match(words[w],"^%D$")) { refdate=wtail() }
185 if(match(words[w],"^%O$")) { refopt=wtail() }
186 } else if(match(words[w],"^Nm$")) {
197 if(!nospace&&match(words[w+1],"^[\\.,]"))
199 } else if(match(words[w],"^Nd$")) {
201 } else if(match(words[w],"^Fl$")) {
202 add("\\fB\\-" words[++w] "\\fP")
203 if(!nospace&&match(words[w+1],"^[\\.,]"))
205 } else if(match(words[w],"^Ar$")) {
210 add(words[++w] "\\fP")
211 while(match(words[w+1],"^\\|$"))
212 add(OFS words[++w] " \\fI" words[++w] "\\fP")
214 if(!nospace&&match(words[w+1],"^[\\.,]"))
216 } else if(match(words[w],"^Cm$")) {
217 add("\\fB" words[++w] "\\fP")
218 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
220 } else if(match(words[w],"^Op$")) {
225 } else if(match(words[w],"^Pp$")) {
227 } else if(match(words[w],"^An$")) {
229 } else if(match(words[w],"^Ss$")) {
231 } else if(match(words[w],"^Pa$")&&!option) {
234 if(match(words[w],"^\\."))
237 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
239 } else if(match(words[w],"^Dv$")) {
241 } else if(match(words[w],"^Em|Ev$")) {
243 } else if(match(words[w],"^Pq$")) {
247 } else if(match(words[w],"^Aq$")) {
251 } else if(match(words[w],"^S[xy]$")) {
253 } else if(match(words[w],"^Ic$")) {
258 if(match(words[w],"^Op$")) {
261 words[nwords]=words[nwords] "]"
263 if(match(words[w],"^Ar$")) {
264 add("\\fI" words[++w] "\\fP")
265 } else if(match(words[w],"^[\\.,]")) {
285 } else if(match(words[w],"^Bl$")) {
287 if(match(words[w+1],"-bullet"))
289 else if(match(words[w+1],"-enum")) {
292 } else if(match(words[w+1],"-tag"))
294 else if(match(words[w+1],"-item"))
296 else if(match(words[w+1],"-bullet"))
299 } else if(match(words[w],"^El$")) {
301 } else if(match(words[w],"^It$")&&optlist) {
305 add(".IP " ++enum ".")
306 else if(optlist==3) {
309 if(match(words[w+1],"^Pa|Ev$")) {
313 } else if(optlist==4)
315 } else if(match(words[w],"^Sm$")) {
316 if(match(words[w+1],"off"))
318 else if(match(words[w+1],"on"))
325 if(match(line,"^\\.[^a-zA-Z]"))
333 if(ext&&!extopt&&!match(line," $"))
335 if(!ext&&!extopt&&length(line)) {