3 # $Id: mdoc2man.awk,v 1.3 2003/09/05 16:33:51 dnelson Exp $
6 # v3, I put the program under a proper license
7 # Dan Nelson <dnelson@allantgroup.com> added .An, .Aq and fixed a typo
8 # v2, fixed to work on GNU awk --posix and MacOS X
9 # v1, first attempt, didn't work on MacOS X
11 # Copyright (c) 2003 Peter Stuge <stuge-mdoc2man@cdy.org>
13 # Permission to use, copy, modify, and distribute this software for any
14 # purpose with or without fee is hereby granted, provided that the above
15 # copyright notice and this permission notice appear in all copies.
17 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
18 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
19 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
20 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
23 # 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$")) {
141 } else if(match(words[w],"^Dt$")) {
144 } else if(match(words[w],"^Os$")) {
145 add(".TH " id " \"" date "\" \"" wtail() "\"")
146 } else if(match(words[w],"^Sh$")) {
148 synopsis=match(words[w+1],"SYNOPSIS")
149 } else if(match(words[w],"^Xr$")) {
150 add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w])
151 } else if(match(words[w],"^Rs$")) {
160 } else if(match(words[w],"^Re$")) {
162 for(i=nrefauthors-1;i>0;i--) {
169 add(refauthors[0] ", \\fI" reftitle "\\fP")
178 } else if(reference) {
179 if(match(words[w],"^%A$")) { refauthors[nrefauthors++]=wtail() }
180 if(match(words[w],"^%T$")) {
182 sub("^\"","",reftitle)
183 sub("\"$","",reftitle)
185 if(match(words[w],"^%N$")) { refissue=wtail() }
186 if(match(words[w],"^%D$")) { refdate=wtail() }
187 if(match(words[w],"^%O$")) { refopt=wtail() }
188 } else if(match(words[w],"^Nm$")) {
199 if(!nospace&&match(words[w+1],"^[\\.,]"))
201 } else if(match(words[w],"^Nd$")) {
203 } else if(match(words[w],"^Fl$")) {
204 add("\\fB\\-" words[++w] "\\fP")
205 if(!nospace&&match(words[w+1],"^[\\.,]"))
207 } else if(match(words[w],"^Ar$")) {
212 add(words[++w] "\\fP")
213 while(match(words[w+1],"^\\|$"))
214 add(OFS words[++w] " \\fI" words[++w] "\\fP")
216 if(!nospace&&match(words[w+1],"^[\\.,]"))
218 } else if(match(words[w],"^Cm$")) {
219 add("\\fB" words[++w] "\\fP")
220 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
222 } else if(match(words[w],"^Op$")) {
227 } else if(match(words[w],"^Pp$")) {
229 } else if(match(words[w],"^An$")) {
231 } else if(match(words[w],"^Ss$")) {
233 } else if(match(words[w],"^Pa$")&&!option) {
236 if(match(words[w],"^\\."))
239 while(w<nwords&&match(words[w+1],"^[\\.,:;)]"))
241 } else if(match(words[w],"^Dv$")) {
243 } else if(match(words[w],"^Em|Ev$")) {
245 } else if(match(words[w],"^Pq$")) {
249 } else if(match(words[w],"^Aq$")) {
253 } else if(match(words[w],"^S[xy]$")) {
255 } else if(match(words[w],"^Ic$")) {
260 if(match(words[w],"^Op$")) {
263 words[nwords]=words[nwords] "]"
265 if(match(words[w],"^Ar$")) {
266 add("\\fI" words[++w] "\\fP")
267 } else if(match(words[w],"^[\\.,]")) {
287 } else if(match(words[w],"^Bl$")) {
289 if(match(words[w+1],"-bullet"))
291 else if(match(words[w+1],"-enum")) {
294 } else if(match(words[w+1],"-tag"))
296 else if(match(words[w+1],"-item"))
298 else if(match(words[w+1],"-bullet"))
301 } else if(match(words[w],"^El$")) {
303 } else if(match(words[w],"^It$")&&optlist) {
307 add(".IP " ++enum ".")
308 else if(optlist==3) {
311 if(match(words[w+1],"^Pa|Ev$")) {
315 } else if(optlist==4)
317 } else if(match(words[w],"^Sm$")) {
318 if(match(words[w+1],"off"))
320 else if(match(words[w+1],"on"))
327 if(match(line,"^\\.[^a-zA-Z]"))
335 if(ext&&!extopt&&!match(line," $"))
337 if(!ext&&!extopt&&length(line)) {