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