MAKEDEV2manpage.awk revision 1.8 1 # $NetBSD: MAKEDEV2manpage.awk,v 1.8 2003/10/24 23:42:25 jdolecek Exp $
2 #
3 # Copyright (c) 2002
4 # Dieter Baron <dillo (at] NetBSD.org>. All rights reserved.
5 # Copyright (c) 1999
6 # Hubert Feyrer <hubertf (at] NetBSD.org>. All rights reserved.
7 # [converted from Hubert's Perl version]
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. All advertising materials mentioning features or use of this software
18 # must display the following acknowledgement:
19 # This product includes software developed by Hubert Feyrer for
20 # the NetBSD Project.
21 # 4. Neither the name of the University nor the names of its contributors
22 # may be used to endorse or promote products derived from this software
23 # without specific prior written permission.
24 #
25 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 # SUCH DAMAGE.
36 #
37 #
38 ###########################################################################
39 #
40 # Convert src/etc/MAKEDEV.tmpl and
41 # src/share/man/man8/MAKEDEV.8.template to
42 # src/share/man/man8/MAKEDEV.8, replacing
43 # - @@@SPECIAL@@@ with all targets in the first section (all, std, ...)
44 # - @@@DEVICES@@@ with the remaining targets
45 # - @@@ARCH@@@ with the architecture name
46 #
47
48 # XXX: uses non-standard AWK functions toupper() and gensub()
49
50 BEGIN {
51 MAKEDEV = "../../../etc/MAKEDEV.tmpl";
52 print ".\\\" *** ------------------------------------------------------------------";
53 print ".\\\" *** This file was generated automatically";
54 print ".\\\" *** from src/etc/MAKEDEV.tmpl and";
55 print ".\\\" *** src/share/man/man8/MAKEDEV.8.template";
56 print ".\\\" ***";
57 print ".\\\" *** DO NOT EDIT - any changes will be lost!!!";
58 print ".\\\" *** ------------------------------------------------------------------";
59 print ".\\\"";
60 }
61
62 function read1line() {
63 if (r1kept)
64 r1l = r1last;
65 else
66 getline r1l < MAKEDEV;
67
68 while (r1l ~ /^#[ \t]*$/)
69 getline r1l < MAKEDEV;
70
71 if (r1l ~ /^#[ \t]/) {
72 if (r1l ~ /^# /) {
73 # Not a device/other target
74 r1kept = 0;
75 }
76 else {
77 # Continuation line (?)
78 getline r1ll < MAKEDEV;
79 while (r1ll ~ /^#\t[ \t]/) {
80 sub(/^#\t[ \t]/, " ", r1ll);
81 r1l = r1l r1ll;
82 getline r1ll < MAKEDEV;
83 }
84 r1last = r1ll;
85 r1kept = 1;
86 }
87 }
88 else
89 r1kept = 0;
90
91 return 1;
92 }
93
94 /^@@@SPECIAL@@@$/ {
95 print ".\\\" " $0;
96 print ".Bl -tag -width 01234567 -compact";
97
98 while (getline l < MAKEDEV > 0 && l !~ /^#.*Device.*Valid.*argument/)
99 ;
100 while (read1line() && r1l ~ /^#\t/) {
101 sub(/#[ \t]*/, "", r1l);
102 target=r1l;
103 sub(/[ \t].*/, "", target);
104 line=r1l;
105 sub(/[^ \t]*[ \t]/, "", line);
106 line=gensub(/\"([^\"]*)"/, "``\\1''", "g", line);
107 line=gensub(/[ \t]*(MAKEDEV(.local)?)[ \t]*/, "\n.Pa \\1\n", "g", line);
108 gsub(/[ \t]+/, " ", line);
109 print ".It Ar " target;
110 print toupper(substr(line, 1, 1)) substr(line, 2);
111
112 }
113 r1last = r1l;
114 r1kept = 1;
115 print ".El";
116 next;
117 }
118 /^@@@DEVICES@@@$/ {
119 print ".\\\" " $0;
120 print ".Bl -tag -width 01";
121
122 read1line();
123 do {
124 sub(/^#[ \t]+/, "", r1l);
125 if (r1l ~ /[^ \t]:$/)
126 sub(/:$/, " :", r1l);
127 print ".It " r1l; # print section heading
128
129 print ". Bl -tag -width 0123456789 -compact";
130 while(read1line() && r1l ~ /^#\t/) {
131 gsub(/#[ \t]+/, "", r1l);
132 target=r1l;
133 sub(/[ \t].*/, "", target);
134 line=r1l;
135 sub(/[^ \t]*[ \t]+/, "", line);
136 sub(/\*/, "#", target);
137 line=gensub(/\"([^\"]*)"/, "``\\1''", "g", line);
138 line=gensub(/[ \t]*(MAKEDEV(.local)?)[ \t]*/, "\n.Pa \\1\n", "g", line);
139 sub(/\(XXX[^)]*\)/, "", line);
140 sub(/[ \t]*$/, "", line);
141
142 # add manpage, if available
143 if (target == "fd#")
144 page = "fdc"
145 else if (target == "pms#")
146 page = "omps"
147 else if (target == "ed#")
148 page = "edc"
149 else if (target == "ttye#")
150 page = "ite"
151 else if (target == "ttyU#")
152 page = "ucom"
153 else if (target == "fd")
154 page = "-----" # force no .Xr
155 else if (target == "sysmon")
156 page = "envsys"
157 else if (target == "veriexec")
158 page = "verifiedexec"
159 else if (target == "ttyZ#")
160 page = "zstty"
161 else if (target == "ttyCZ?")
162 page = "cz"
163 else if (target == "ttyCY?")
164 page = "cy"
165 else if (target == "ttyB?")
166 page = "scc"
167 else {
168 page=target;
169 sub(/[^a-zA-Z]+/, "", page);
170 }
171
172 str = "ls ../man4/" page ".4 ../man4/man4.*/" page ".4 2>/dev/null"
173 while(str | getline) {
174 if (system("test -f " $0) != 0)
175 continue
176
177 # get the manpage including opt. arch name
178 sub(/^\.\.\/man4\//, "")
179 sub(/^man4\./, "")
180 sub(/\.4$/, "")
181
182 sub(/[ \t]*$/, "", line);
183 if (line ~ /see/) {
184 # already a manpage there, e.g. scsictl(8)
185 line = line ", ";
186 }
187 else
188 line = line ", see ";
189 line = line $0 "(4)";
190 }
191 close(str)
192 # Add .Xr \&foo 4 - ampersand to work around manpages that are
193 # *roff commands at the same time
194 while (line ~ /[a-zA-Z0-9]+\([0-9]\)/) {
195 line=gensub(/[ \t]*([a-zA-Z0-9\/]+)\(([0-9])\)(.*)/, "\n.Xr \\\\\\&\\1 \\2 \\3", "g", line);
196 }
197 gsub(/[ \t]+$/, "", line);
198 gsub(/[ \t]+/, " ", line);
199
200 print ". It Ar " target;
201 line2=toupper(substr(line, 1, 1)) substr(line, 2);
202 sub(/Wscons/, "wscons", line2);
203 sub(/Pccons/, "pccons", line2);
204 print line2;
205 }
206 print MANPAGE ". El";
207 } while (r1l ~ /^# /);
208
209 print ".El";
210 next;
211 }
212 /@@@ARCH@@@/ {
213 gsub(/@@@ARCH@@@/, ARCH);
214 }
215 # date is substituted in the shell script
216 #/@@@DATE@@@/ {
217 # # date
218 #}
219 /\$NetBSD/ {
220 sub(/\$NetBSD.*\$/, "$""NetBSD$");
221 }
222 { print }
223