4 # v4+ Adapted for OpenSSH Portable (see cvs Id and history)
5 # v3, I put the program under a proper license
6 # Dan Nelson <dnelson@allantgroup.com> added .An, .Aq and fixed a typo
7 # v2, fixed to work on GNU awk --posix and MacOS X
8 # v1, first attempt, didn't work on MacOS X
10 # Copyright (c) 2003 Peter Stuge <stuge-mdoc2man@cdy.org>
12 # Permission to use, copy, modify, and distribute this software for any
13 # purpose with or without fee is hereby granted, provided that the above
14 # copyright notice and this permission notice appear in all copies.
16 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
17 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
18 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
19 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45 retval=retval words[++w]
72 nwords=split($0,words)
73 for(w=1;w<=nwords;w++) {
75 if(match(words[w],"^Li|Pf$")) {
77 } else if(match(words[w],"^Xo$")) {
80 if(length(line)&&!(match(line," $")||prenl))
82 } else if(match(words[w],"^Xc$")) {
88 } else if(match(words[w],"^Bd$")) {
90 if(match(words[w+1],"-literal")) {
95 } else if(match(words[w],"^Ed$")) {
98 } else if(match(words[w],"^Ns$")) {
103 } else if(match(words[w],"^No$")) {
107 } else if(match(words[w],"^Dq$")) {
111 while(w<nwords&&!match(words[w+1],"^[\\.,]"))
114 if(!nospace&&match(words[w+1],"^[\\.,]"))
116 } else if(match(words[w],"^Sq|Ql$")) {
118 add("`" words[++w] "'")
119 if(!nospace&&match(words[w+1],"^[\\.,]"))
121 } else if(match(words[w],"^Oo$")) {
127 } else if(match(words[w],"^Oc$")) {
133 if(!nospace&&length(line)&&!(match(line," $")||prenl))
138 if(match(words[w],"^Dd$")) {
139 if(match(words[w+1],"^\\$Mdocdate:")) {
141 if(match(words[w+4],"^\\$$")) {
147 } else if(match(words[w],"^Dt$")) {
150 } else if(match(words[w],"^Ux$")) {
153 } else if(match(words[w],"^Ox$")) {
156 } else if(match(words[w],"^Os$")) {
157 add(".TH " id " \"" date "\" \"" wtail() "\"")
158 } else if(match(words[w],"^Sh$")) {
160 synopsis=match(words[w+1],"SYNOPSIS")
161 } else if(match(words[w],"^Xr$")) {
162 add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
163 } else if(match(words[w],"^Rs$")) {
173 } else if(match(words[w],"^Re$")) {
175 for(i=nrefauthors-1;i>0;i--) {
183 add(refauthors[0] ", ")
184 add("\\fI" reftitle "\\fP")
187 if(length(refreport)) {
196 } else if(reference) {
197 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
198 if(match(words[w],"^%T$")) {
200 sub("^\"","",reftitle)
201 sub("\"$","",reftitle)
203 if(match(words[w],"^%N$")) { refissue=wtail() }
204 if(match(words[w],"^%D$")) { refdate=wtail() }
205 if(match(words[w],"^%O$")) { refopt=wtail() }
206 if(match(words[w],"^%R$")) { refreport=wtail() }
207 } else if(match(words[w],"^Nm$")) {
218 if(!nospace&&match(words[w+1],"^[\\.,]"))
220 } else if(match(words[w],"^Nd$")) {
222 } else if(match(words[w],"^Fl$")) {
223 add("\\fB\\-" words[++w] "\\fP")
224 if(!nospace&&match(words[w+1],"^[\\.,]"))
226 } else if(match(words[w],"^Ar$")) {
231 add(words[++w] "\\fP")
232 while(match(words[w+1],"^\\|$"))
233 add(OFS words[++w] " \\fI" words[++w] "\\fP")
235 if(!nospace&&match(words[w+1],"^[\\.,]"))
237 } else if(match(words[w],"^Cm$")) {
238 add("\\fB" words[++w] "\\fP")
239 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
241 } else if(match(words[w],"^Op$")) {
246 } else if(match(words[w],"^Pp$")) {
248 } else if(match(words[w],"^An$")) {
250 } else if(match(words[w],"^Ss$")) {
252 } else if(match(words[w],"^Pa$")&&!option) {
255 if(match(words[w],"^\\."))
258 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
260 } else if(match(words[w],"^Dv$")) {
262 } else if(match(words[w],"^Em|Ev$")) {
264 } else if(match(words[w],"^Pq$")) {
268 } else if(match(words[w],"^Aq$")) {
272 } else if(match(words[w],"^S[xy]$")) {
274 } else if(match(words[w],"^Ic$")) {
279 if(match(words[w],"^Op$")) {
282 words[nwords]=words[nwords] "]"
284 if(match(words[w],"^Ar$")) {
285 add("\\fI" words[++w] "\\fP")
286 } else if(match(words[w],"^[\\.,]")) {
306 } else if(match(words[w],"^Bl$")) {
308 if(match(words[w+1],"-bullet"))
310 else if(match(words[w+1],"-enum")) {
313 } else if(match(words[w+1],"-tag"))
315 else if(match(words[w+1],"-item"))
317 else if(match(words[w+1],"-bullet"))
320 } 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)) {