1# $NetBSD: MAKEDEV2manpage.awk,v 1.3 2002/04/19 01:34:41 dillo 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/etc.${ARCH}/MAKEDEV and 41# src/share/man/man8/MAKEDEV.8.template to 42# src/share/man/man8/man8.${ARCH}/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 50BEGIN { 51 MAKEDEV = "../../../etc/etc." ARCH "/MAKEDEV"; 52 print ".\\\" *** ------------------------------------------------------------------"; 53 print ".\\\" *** This file was generated automatically"; 54 print ".\\\" *** from src/etc/etc." ARCH "/MAKEDEV 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 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 { 148 page=target; 149 sub(/[^a-zA-Z]+/, "", page); 150 } 151 152 if (system("test -f ../man4/" page ".4 -o -f ../man4/man4." ARCH "/" page ".4") == 0) { 153 sub(/[ \t]*$/, "", line); 154 if (line ~ /see/) { 155 # already a manpage there, e.g. scsictl(8) 156 line = line ", "; 157 } 158 else 159 line = line ", see "; 160 line = line page "(4)"; 161 } 162 # Add .Xr \&foo 4 - ampersand to work around manpages that are 163 # *roff commands at the same time 164 while (line ~ /[a-zA-Z0-9]+\([0-9]\)/) { 165 line=gensub(/[ \t]*([a-zA-Z0-9]+)\(([0-9])\)(.*)/, "\n.Xr \\\\\\&\\1 \\2 \\3", "g", line); 166 } 167 gsub(/[ \t]+$/, "", line); 168 gsub(/[ \t]+/, " ", line); 169 170 print ". It Ar " target; 171 print toupper(substr(line, 1, 1)) substr(line, 2); 172 } 173 print MANPAGE ". El"; 174 } while (r1l ~ /^# /); 175 176 print ".El"; 177 next; 178} 179/@@@ARCH@@@/ { 180 gsub(/@@@ARCH@@@/, ARCH); 181} 182# date is substituted in the shell script 183#/@@@DATE@@@/ { 184# # date 185#} 186/\$NetBSD/ { 187 sub(/\$NetBSD.*\$/, "$""NetBSD$"); 188} 189{ print } 190