1# $NetBSD: MAKEDEV2manpage.awk,v 1.13 2010/03/23 19:19:03 jakllsch Exp $ 2# 3# Copyright (c) 2002 4# Dieter Baron <dillo@NetBSD.org>. All rights reserved. 5# Copyright (c) 1999 6# Hubert Feyrer <hubertf@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 function toupper() 49 50BEGIN { 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 62function 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 # replace "foo" with ``foo'' 107 gsub(/\"[^\"]*\"/, "``&''", line) 108 gsub(/\"/, "", line) 109 gsub(/[ \t]+/, " ", line); 110 print ".It Ar " target; 111 print toupper(substr(line, 1, 1)) substr(line, 2); 112 113 } 114 r1last = r1l; 115 r1kept = 1; 116 print ".El"; 117 next; 118} 119/^@@@DEVICES@@@$/ { 120 print ".\\\" " $0; 121 print ".Bl -tag -width 01"; 122 123 read1line(); 124 do { 125 sub(/^#[ \t]+/, "", r1l); 126 if (r1l ~ /[^ \t]:$/) 127 sub(/:$/, " :", r1l); 128 print ".It " r1l; # print section heading 129 130 print ". Bl -tag -width 0123456789 -compact"; 131 while(read1line() && r1l ~ /^#\t/) { 132 gsub(/#[ \t]+/, "", r1l); 133 target=r1l; 134 sub(/[ \t].*/, "", target); 135 line=r1l; 136 sub(/[^ \t]*[ \t]+/, "", line); 137 sub(/\*/, "#", target); 138 # replace "foo" with ``foo'' 139 gsub(/\"[^\"]*\"/, "``&''", line) 140 gsub(/\"/, "", line) 141 # fix collateral damage of previous 142 sub(/5 1\/4''/, "5 1/4\"", line) 143 sub(/3 1\/2``/, "3 1/2\"", line) 144 # gc whitespace 145 sub(/\(XXX[^)]*\)/, "", line); 146 sub(/[ \t]*$/, "", line); 147 148 # add manpage, if available 149 if (target == "fd#") 150 page = "fdc" 151 else if (target == "pms#") 152 page = "opms" 153 else if (target == "ed#") 154 page = "edc" 155 else if (target == "ttye#") 156 page = "ite" 157 else if (target == "ttyh#") 158 page = "sab" 159 else if (target == "ttyU#") 160 page = "ucom" 161 else if (target == "fd") 162 page = "-----" # force no .Xr 163 else if (target == "sysmon") 164 page = "envsys" 165 else if (target == "ttyZ#") 166 page = "zstty" 167 else if (target == "ttyCZ?") 168 page = "cz" 169 else if (target == "ttyCY?") 170 page = "cy" 171 else if (target == "ttyB?") 172 page = "scc" 173 else if (target == "random") 174 page = "rnd" 175 else if (target == "scsibus#") 176 page = "scsi" 177 else { 178 page=target; 179 sub(/[^a-zA-Z]+/, "", page); 180 } 181 182 str = "ls ../man4/" page ".4 ../man4/man4.*/" page ".4 2>/dev/null" 183 while(str | getline) { 184 if (system("test -f " $0) != 0) 185 continue 186 187 # get the manpage including opt. arch name 188 sub(/^\.\.\/man4\//, "") 189 sub(/^man4\./, "") 190 sub(/\.4$/, "") 191 192 sub(/[ \t]*$/, "", line); 193 if (line ~ /see/) { 194 # already a manpage there, e.g. scsictl(8) 195 line = line " ,"; 196 } 197 else 198 line = line ", see"; 199 # Add .Xr \&foo 4 - ampersand to work around 200 # manpages that are *roff commands at the same 201 # time 202 line = line "\n.Xr \\&" $0 " 4"; 203 } 204 close(str) 205 206 gsub(/[ \t]+$/, "", line); 207 gsub(/[ \t]+/, " ", line); 208 209 print ". It Ar " target; 210 line2=toupper(substr(line, 1, 1)) substr(line, 2); 211 sub(/Wscons/, "wscons", line2); 212 sub(/Pccons/, "pccons", line2); 213 print line2; 214 } 215 print MANPAGE ". El"; 216 } while (r1l ~ /^# /); 217 218 print ".El"; 219 next; 220} 221/@@@ARCH@@@/ { 222 gsub(/@@@ARCH@@@/, ARCH); 223} 224# date is substituted in the shell script 225#/@@@DATE@@@/ { 226# # date 227#} 228/\$NetBSD/ { 229 sub(/\$NetBSD.*\$/, "$""NetBSD$"); 230} 231{ print } 232