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$")) {
171 } else if(match(words[w],"^Re$")) {
173 for(i=nrefauthors-1;i>0;i--) {
180 add(refauthors[0] ", \\fI" reftitle "\\fP")
189 } else if(reference) {
190 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
191 if(match(words[w],"^%T$")) {
193 sub("^\"","",reftitle)
194 sub("\"$","",reftitle)
196 if(match(words[w],"^%N$")) { refissue=wtail() }
197 if(match(words[w],"^%D$")) { refdate=wtail() }
198 if(match(words[w],"^%O$")) { refopt=wtail() }
199 } else if(match(words[w],"^Nm$")) {
210 if(!nospace&&match(words[w+1],"^[\\.,]"))
212 } else if(match(words[w],"^Nd$")) {
214 } else if(match(words[w],"^Fl$")) {
215 add("\\fB\\-" words[++w] "\\fP")
216 if(!nospace&&match(words[w+1],"^[\\.,]"))
218 } else if(match(words[w],"^Ar$")) {
223 add(words[++w] "\\fP")
224 while(match(words[w+1],"^\\|$"))
225 add(OFS words[++w] " \\fI" words[++w] "\\fP")
227 if(!nospace&&match(words[w+1],"^[\\.,]"))
229 } else if(match(words[w],"^Cm$")) {
230 add("\\fB" words[++w] "\\fP")
231 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
233 } else if(match(words[w],"^Op$")) {
238 } else if(match(words[w],"^Pp$")) {
240 } else if(match(words[w],"^An$")) {
242 } else if(match(words[w],"^Ss$")) {
244 } else if(match(words[w],"^Pa$")&&!option) {
247 if(match(words[w],"^\\."))
250 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
252 } else if(match(words[w],"^Dv$")) {
254 } else if(match(words[w],"^Em|Ev$")) {
256 } else if(match(words[w],"^Pq$")) {
260 } else if(match(words[w],"^Aq$")) {
264 } else if(match(words[w],"^S[xy]$")) {
266 } else if(match(words[w],"^Ic$")) {
271 if(match(words[w],"^Op$")) {
274 words[nwords]=words[nwords] "]"
276 if(match(words[w],"^Ar$")) {
277 add("\\fI" words[++w] "\\fP")
278 } else if(match(words[w],"^[\\.,]")) {
298 } else if(match(words[w],"^Bl$")) {
300 if(match(words[w+1],"-bullet"))
302 else if(match(words[w+1],"-enum")) {
305 } else if(match(words[w+1],"-tag"))
307 else if(match(words[w+1],"-item"))
309 else if(match(words[w+1],"-bullet"))
312 } else if(match(words[w],"^El$")) {
314 } else if(match(words[w],"^Bk$")) {
315 if(match(words[w+1],"-words")) {
319 } else if(match(words[w],"^Ek$")) {
321 } else if(match(words[w],"^It$")&&optlist) {
325 add(".IP " ++enum ".")
326 else if(optlist==3) {
329 if(match(words[w+1],"^Pa$|^Ev$")) {
333 } else if(optlist==4)
335 } else if(match(words[w],"^Sm$")) {
336 if(match(words[w+1],"off"))
338 else if(match(words[w+1],"on"))
345 if(match(line,"^\\.[^a-zA-Z]"))
353 if(ext&&!extopt&&!match(line," $"))
355 if(!ext&&!extopt&&length(line)) {