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