Home | History | Annotate | Line # | Download | only in gio
devlist2h.awk revision 1.5.64.1
      1       1.1  sekiya #! /usr/bin/awk -f
      2  1.5.64.1   skrll #	$NetBSD: devlist2h.awk,v 1.5.64.1 2017/08/28 17:51:51 skrll Exp $
      3       1.1  sekiya #
      4       1.1  sekiya # Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1  sekiya # All rights reserved.
      6       1.1  sekiya #
      7       1.1  sekiya # This code is derived from software contributed to The NetBSD Foundation
      8       1.1  sekiya # by Christos Zoulas.
      9       1.1  sekiya #
     10       1.1  sekiya # Redistribution and use in source and binary forms, with or without
     11       1.1  sekiya # modification, are permitted provided that the following conditions
     12       1.1  sekiya # are met:
     13       1.1  sekiya # 1. Redistributions of source code must retain the above copyright
     14       1.1  sekiya #    notice, this list of conditions and the following disclaimer.
     15       1.1  sekiya # 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  sekiya #    notice, this list of conditions and the following disclaimer in the
     17       1.1  sekiya #    documentation and/or other materials provided with the distribution.
     18       1.1  sekiya #
     19       1.1  sekiya # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1  sekiya # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1  sekiya # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1  sekiya # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1  sekiya # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1  sekiya # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1  sekiya # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1  sekiya # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1  sekiya # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1  sekiya # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1  sekiya # POSSIBILITY OF SUCH DAMAGE.
     30       1.1  sekiya #
     31       1.1  sekiya # Copyright (c) 1995, 1996 Christopher G. Demetriou
     32       1.1  sekiya # All rights reserved.
     33       1.1  sekiya #
     34       1.1  sekiya # Redistribution and use in source and binary forms, with or without
     35       1.1  sekiya # modification, are permitted provided that the following conditions
     36       1.1  sekiya # are met:
     37       1.1  sekiya # 1. Redistributions of source code must retain the above copyright
     38       1.1  sekiya #    notice, this list of conditions and the following disclaimer.
     39       1.1  sekiya # 2. Redistributions in binary form must reproduce the above copyright
     40       1.1  sekiya #    notice, this list of conditions and the following disclaimer in the
     41       1.1  sekiya #    documentation and/or other materials provided with the distribution.
     42       1.1  sekiya # 3. All advertising materials mentioning features or use of this software
     43       1.1  sekiya #    must display the following acknowledgement:
     44       1.1  sekiya #      This product includes software developed by Christopher G. Demetriou.
     45       1.1  sekiya # 4. The name of the author(s) may not be used to endorse or promote products
     46       1.1  sekiya #    derived from this software without specific prior written permission
     47       1.1  sekiya #
     48       1.1  sekiya # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     49       1.1  sekiya # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     50       1.1  sekiya # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     51       1.1  sekiya # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     52       1.1  sekiya # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     53       1.1  sekiya # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     54       1.1  sekiya # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     55       1.1  sekiya # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     56       1.1  sekiya # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     57       1.1  sekiya # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     58       1.1  sekiya #
     59       1.1  sekiya function collectline(_f, _line) {
     60       1.1  sekiya 	_oparen = 0
     61       1.1  sekiya 	_line = ""
     62       1.1  sekiya 	while (_f <= NF) {
     63       1.1  sekiya 		if ($_f == "#") {
     64       1.1  sekiya 			_line = _line "("
     65       1.1  sekiya 			_oparen = 1
     66       1.1  sekiya 			_f++
     67       1.1  sekiya 			continue
     68       1.1  sekiya 		}
     69       1.1  sekiya 		if (_oparen) {
     70       1.1  sekiya 			_line = _line $_f
     71       1.1  sekiya 			if (_f < NF)
     72       1.1  sekiya 				_line = _line " "
     73       1.1  sekiya 			_f++
     74       1.1  sekiya 			continue
     75       1.1  sekiya 		}
     76       1.1  sekiya 		_line = _line $_f
     77       1.1  sekiya 		if (_f < NF)
     78       1.1  sekiya 			_line = _line " "
     79       1.1  sekiya 		_f++
     80       1.1  sekiya 	}
     81       1.1  sekiya 	if (_oparen)
     82       1.1  sekiya 		_line = _line ")"
     83       1.1  sekiya 	return _line
     84       1.1  sekiya }
     85       1.1  sekiya BEGIN {
     86       1.1  sekiya 	nproducts = nvendors = blanklines = 0
     87       1.2  sekiya 	dfile="giodevs_data.h"
     88       1.2  sekiya 	hfile="giodevs.h"
     89       1.1  sekiya 	line=""
     90       1.1  sekiya }
     91       1.1  sekiya NR == 1 {
     92       1.1  sekiya 	VERSION = $0
     93       1.1  sekiya 	gsub("\\$", "", VERSION)
     94       1.1  sekiya 
     95       1.2  sekiya 	printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
     96       1.2  sekiya 	printf("/*\n") > hfile
     97       1.2  sekiya 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
     98       1.2  sekiya 	    > hfile
     99       1.2  sekiya 	printf(" */\n") > hfile
    100       1.2  sekiya 
    101       1.1  sekiya 	printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
    102       1.1  sekiya 	printf("/*\n") > dfile
    103       1.1  sekiya 	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
    104       1.1  sekiya 	    > dfile
    105       1.1  sekiya 	printf(" */\n") > dfile
    106       1.1  sekiya 
    107       1.1  sekiya 	next
    108       1.1  sekiya }
    109       1.1  sekiya NF > 0 && $1 == "product" {
    110       1.1  sekiya 	nproducts++
    111       1.1  sekiya 
    112       1.1  sekiya 	products[nproducts, 1] = $2;
    113       1.2  sekiya 	products[nproducts, 2] = $3
    114       1.2  sekiya 	products[nproducts, 3] = collectline(4, line)
    115       1.1  sekiya 
    116       1.1  sekiya 	next
    117       1.1  sekiya }
    118       1.1  sekiya {
    119       1.1  sekiya 	if ($0 == "")
    120       1.1  sekiya 		blanklines++
    121       1.1  sekiya 	if (blanklines < 2)
    122       1.1  sekiya 		print $0 > dfile
    123       1.1  sekiya }
    124       1.1  sekiya END {
    125       1.1  sekiya 	# print out the match tables
    126       1.1  sekiya 
    127       1.1  sekiya 	printf("\n") > dfile
    128       1.1  sekiya 
    129       1.1  sekiya 	printf("struct gio_knowndev {\n") > dfile
    130       1.1  sekiya 	printf("\tint productid;\n") > dfile
    131       1.3  martin 	printf("\tconst char *product;\n") > dfile
    132       1.1  sekiya 	printf("};\n") > dfile
    133       1.1  sekiya 	printf("\nstruct gio_knowndev gio_knowndevs[] = {\n") > dfile
    134       1.2  sekiya 
    135       1.2  sekiya 	printf("\n") > hfile
    136       1.1  sekiya 	for (i = 1; i <= nproducts; i++) {
    137       1.2  sekiya 		printf("#define %s\t%s\t/* %s */\n", products[i, 1], products[i,2], products[i, 3]) > hfile
    138       1.2  sekiya 
    139       1.1  sekiya 		printf("\t{ %s, \"%s\" },\n",
    140       1.2  sekiya 		    products[i, 2], products[i, 3]) > dfile
    141       1.1  sekiya 	}
    142       1.1  sekiya 	printf("\t{ 0, NULL }\n") > dfile
    143       1.1  sekiya 	printf("};\n") > dfile
    144       1.1  sekiya 	close(dfile)
    145       1.2  sekiya 	close(hfile)
    146       1.1  sekiya }
    147