1995-06-18 05:07:04 +04:00
|
|
|
#! /usr/bin/awk -f
|
2017-06-27 11:09:14 +03:00
|
|
|
# $NetBSD: devlist2h.awk,v 1.3 2017/06/27 08:09:14 wiz Exp $
|
1995-06-18 05:07:04 +04:00
|
|
|
#
|
1996-01-23 00:08:09 +03:00
|
|
|
# Copyright (c) 1995, 1996 Christopher G. Demetriou
|
1995-06-18 05:07:04 +04:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# 3. All advertising materials mentioning features or use of this software
|
|
|
|
# must display the following acknowledgement:
|
|
|
|
# This product includes software developed by Christopher G. Demetriou.
|
|
|
|
# 4. The name of the author may not be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written permission
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
2014-09-21 18:30:22 +04:00
|
|
|
NR == 1 {
|
2003-12-15 10:32:20 +03:00
|
|
|
nproducts = nvendors = blanklines = 0
|
2016-10-26 04:03:23 +03:00
|
|
|
vendormaxlen = productmaxlen = 0
|
2008-11-18 02:33:41 +03:00
|
|
|
nchars = 1
|
2014-09-21 18:30:22 +04:00
|
|
|
dfile= FILENAME "_data.h"
|
|
|
|
hfile= FILENAME ".h"
|
|
|
|
prefix = FILENAME
|
|
|
|
gsub("devs", "", prefix)
|
|
|
|
PREFIX = toupper(prefix)
|
1995-06-18 05:07:04 +04:00
|
|
|
VERSION = $0
|
|
|
|
gsub("\\$", "", VERSION)
|
2005-02-27 18:19:13 +03:00
|
|
|
gsub(/ $/, "", VERSION)
|
1995-06-18 05:07:04 +04:00
|
|
|
|
2003-12-15 10:32:20 +03:00
|
|
|
printf("/*\t$NetBSD" "$\t*/\n\n") > dfile
|
1995-06-18 05:07:04 +04:00
|
|
|
printf("/*\n") > dfile
|
2017-06-27 11:09:14 +03:00
|
|
|
printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
|
1995-06-18 05:07:04 +04:00
|
|
|
> dfile
|
|
|
|
printf(" *\n") > dfile
|
|
|
|
printf(" * generated from:\n") > dfile
|
|
|
|
printf(" *\t%s\n", VERSION) > dfile
|
|
|
|
printf(" */\n") > dfile
|
|
|
|
|
2003-12-15 10:32:20 +03:00
|
|
|
printf("/*\t$NetBSD" "$\t*/\n\n") > hfile
|
1995-06-18 05:07:04 +04:00
|
|
|
printf("/*\n") > hfile
|
2017-06-27 11:09:14 +03:00
|
|
|
printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
|
1995-06-18 05:07:04 +04:00
|
|
|
> hfile
|
|
|
|
printf(" *\n") > hfile
|
|
|
|
printf(" * generated from:\n") > hfile
|
|
|
|
printf(" *\t%s\n", VERSION) > hfile
|
|
|
|
printf(" */\n") > hfile
|
|
|
|
|
1996-01-23 00:08:09 +03:00
|
|
|
next
|
1995-06-18 05:07:04 +04:00
|
|
|
}
|
2003-12-15 10:32:20 +03:00
|
|
|
NF > 0 && $1 == "vendor" {
|
1995-06-18 05:07:04 +04:00
|
|
|
nvendors++
|
|
|
|
|
|
|
|
vendorindex[$2] = nvendors; # record index for this name, for later.
|
|
|
|
vendors[nvendors, 1] = $2; # name
|
|
|
|
vendors[nvendors, 2] = $3; # id
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("#define\t%s_VENDOR_%s\t%s", PREFIX, vendors[nvendors, 1],
|
1995-06-18 05:07:04 +04:00
|
|
|
vendors[nvendors, 2]) > hfile
|
|
|
|
|
|
|
|
i = 3; f = 4;
|
|
|
|
|
|
|
|
# comments
|
|
|
|
ocomment = oparen = 0
|
|
|
|
if (f <= NF) {
|
2005-02-27 18:19:13 +03:00
|
|
|
printf("\t\t/* ") > hfile
|
1995-06-18 05:07:04 +04:00
|
|
|
ocomment = 1;
|
|
|
|
}
|
|
|
|
while (f <= NF) {
|
|
|
|
if ($f == "#") {
|
|
|
|
printf("(") > hfile
|
|
|
|
oparen = 1
|
|
|
|
f++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (oparen) {
|
|
|
|
printf("%s", $f) > hfile
|
|
|
|
if (f < NF)
|
|
|
|
printf(" ") > hfile
|
|
|
|
f++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
vendors[nvendors, i] = $f
|
2008-11-18 02:33:41 +03:00
|
|
|
if (words[$f, 1] == 0) {
|
|
|
|
l = length($f);
|
|
|
|
parts = split($f, junk, "\\");
|
|
|
|
l = l - (parts - 1);
|
|
|
|
nwords++;
|
|
|
|
words[$f, 1] = nwords;
|
|
|
|
words[$f, 2] = l;
|
|
|
|
wordlist[nwords, 1] = $f;
|
|
|
|
wordlist[nwords, 3] = nchars;
|
|
|
|
nchars = nchars + l + 1;
|
|
|
|
}
|
|
|
|
wordlist[words[$f, 1], 2]++;
|
|
|
|
vendors[nvendors, i] = words[$f, 1];
|
|
|
|
printf("%s", $f) > hfile
|
1995-06-18 05:07:04 +04:00
|
|
|
if (f < NF)
|
|
|
|
printf(" ") > hfile
|
|
|
|
i++; f++;
|
|
|
|
}
|
|
|
|
if (oparen)
|
|
|
|
printf(")") > hfile
|
|
|
|
if (ocomment)
|
|
|
|
printf(" */") > hfile
|
|
|
|
printf("\n") > hfile
|
|
|
|
|
2016-10-26 04:03:23 +03:00
|
|
|
if (length($2) > vendormaxlen) {
|
|
|
|
vendormaxlen = length($2)
|
|
|
|
}
|
|
|
|
|
1996-01-23 00:08:09 +03:00
|
|
|
next
|
1995-06-18 05:07:04 +04:00
|
|
|
}
|
2003-12-15 10:32:20 +03:00
|
|
|
NF > 0 && $1 == "product" {
|
1995-06-18 05:07:04 +04:00
|
|
|
nproducts++
|
|
|
|
|
|
|
|
products[nproducts, 1] = $2; # vendor name
|
|
|
|
products[nproducts, 2] = $3; # product id
|
|
|
|
products[nproducts, 3] = $4; # id
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("#define\t%s_PRODUCT_%s_%s\t%s", PREFIX, products[nproducts, 1],
|
1995-06-18 05:07:04 +04:00
|
|
|
products[nproducts, 2], products[nproducts, 3]) > hfile
|
|
|
|
|
|
|
|
i=4; f = 5;
|
|
|
|
|
|
|
|
# comments
|
2016-10-26 04:03:23 +03:00
|
|
|
productlen = ocomment = oparen = 0
|
1995-06-18 05:07:04 +04:00
|
|
|
if (f <= NF) {
|
2005-02-27 18:19:13 +03:00
|
|
|
printf("\t\t/* ") > hfile
|
1995-06-18 05:07:04 +04:00
|
|
|
ocomment = 1;
|
|
|
|
}
|
|
|
|
while (f <= NF) {
|
|
|
|
if ($f == "#") {
|
|
|
|
printf("(") > hfile
|
|
|
|
oparen = 1
|
|
|
|
f++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (oparen) {
|
|
|
|
printf("%s", $f) > hfile
|
|
|
|
if (f < NF)
|
|
|
|
printf(" ") > hfile
|
|
|
|
f++
|
|
|
|
continue
|
|
|
|
}
|
2008-11-18 02:33:41 +03:00
|
|
|
if (words[$f, 1] == 0) {
|
|
|
|
l = length($f);
|
|
|
|
parts = split($f, junk, "\\");
|
|
|
|
l = l - (parts - 1);
|
|
|
|
nwords++;
|
|
|
|
words[$f, 2] = l;
|
|
|
|
words[$f, 1] = nwords;
|
|
|
|
wordlist[nwords, 1] = $f;
|
|
|
|
wordlist[nwords, 3] = nchars;
|
|
|
|
nchars = nchars + l + 1;
|
|
|
|
}
|
2016-10-26 04:03:23 +03:00
|
|
|
productlen += words[$f, 2] + 1;
|
2008-11-18 02:33:41 +03:00
|
|
|
wordlist[words[$f, 1], 2]++;
|
|
|
|
products[nproducts, i] = words[$f, 1];
|
|
|
|
printf("%s", $f) > hfile
|
1995-06-18 05:07:04 +04:00
|
|
|
if (f < NF)
|
|
|
|
printf(" ") > hfile
|
|
|
|
i++; f++;
|
|
|
|
}
|
|
|
|
if (oparen)
|
|
|
|
printf(")") > hfile
|
|
|
|
if (ocomment)
|
|
|
|
printf(" */") > hfile
|
|
|
|
printf("\n") > hfile
|
|
|
|
|
2016-10-26 04:03:23 +03:00
|
|
|
if (productlen > productmaxlen) {
|
|
|
|
productmaxlen = productlen;
|
|
|
|
}
|
|
|
|
|
1996-01-23 00:08:09 +03:00
|
|
|
next
|
1995-06-18 05:07:04 +04:00
|
|
|
}
|
|
|
|
{
|
|
|
|
if ($0 == "")
|
|
|
|
blanklines++
|
|
|
|
print $0 > hfile
|
|
|
|
if (blanklines < 2)
|
|
|
|
print $0 > dfile
|
|
|
|
}
|
|
|
|
END {
|
|
|
|
# print out the match tables
|
|
|
|
|
|
|
|
printf("\n") > dfile
|
|
|
|
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("static const uint16_t %s_vendors[] = {\n", prefix) > dfile
|
2004-08-02 22:43:38 +04:00
|
|
|
for (i = 1; i <= nvendors; i++) {
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("\t %s_VENDOR_%s", PREFIX, vendors[i, 1]) \
|
1995-06-18 05:07:04 +04:00
|
|
|
> dfile
|
|
|
|
|
|
|
|
j = 3;
|
2004-08-02 22:43:38 +04:00
|
|
|
while ((i, j) in vendors) {
|
2008-11-18 02:33:41 +03:00
|
|
|
printf(", %d",
|
|
|
|
wordlist[vendors[i, j], 3]) > dfile
|
|
|
|
# printf(", %d /* %s */",
|
|
|
|
# wordlist[vendors[i, j], 3],
|
|
|
|
# wordlist[vendors[i, j], 1]) > dfile
|
1995-06-18 05:07:04 +04:00
|
|
|
j++
|
|
|
|
}
|
2008-11-18 02:33:41 +03:00
|
|
|
printf(", 0,\n", sep) > dfile
|
1995-06-18 05:07:04 +04:00
|
|
|
}
|
2004-08-02 22:43:38 +04:00
|
|
|
printf("};\n") > dfile
|
|
|
|
|
|
|
|
printf("\n") > dfile
|
|
|
|
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("static const uint16_t %s_products[] = {\n", prefix) > dfile
|
2004-08-02 22:43:38 +04:00
|
|
|
for (i = 1; i <= nproducts; i++) {
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("\t %s_VENDOR_%s, %s_PRODUCT_%s_%s, \n",
|
|
|
|
PREFIX, products[i, 1], PREFIX, products[i, 1],
|
|
|
|
products[i, 2]) > dfile
|
2004-08-02 22:43:38 +04:00
|
|
|
|
2008-11-18 02:33:41 +03:00
|
|
|
printf("\t ") > dfile
|
|
|
|
j = 4
|
|
|
|
sep = ""
|
2004-08-02 22:43:38 +04:00
|
|
|
while ((i, j) in products) {
|
2008-11-18 02:33:41 +03:00
|
|
|
printf("%s%d", sep,
|
|
|
|
wordlist[products[i, j], 3]) > dfile
|
|
|
|
# printf("%s%d /* %s */", sep,
|
|
|
|
# wordlist[products[i, j], 3],
|
|
|
|
# wordlist[products[i, j], 1]) > dfile
|
|
|
|
sep = ", "
|
1995-06-18 05:07:04 +04:00
|
|
|
j++
|
|
|
|
}
|
2008-11-18 02:33:41 +03:00
|
|
|
printf("%s0,\n", sep) > dfile
|
1995-06-18 05:07:04 +04:00
|
|
|
}
|
|
|
|
printf("};\n") > dfile
|
2008-11-18 02:33:41 +03:00
|
|
|
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("static const char %s_words[] = { \".\" \n", prefix) > dfile
|
2008-11-18 02:33:41 +03:00
|
|
|
for (i = 1; i <= nwords; i++) {
|
|
|
|
printf("\t \"%s\\0\" /* %d refs @ %d */\n",
|
|
|
|
wordlist[i, 1], wordlist[i, 2], wordlist[i, 3]) > dfile
|
|
|
|
}
|
|
|
|
printf("};\n") > dfile
|
2014-09-21 18:30:22 +04:00
|
|
|
printf("const int %s_nwords = %d;\n", prefix, nwords) > dfile
|
2008-11-18 02:33:41 +03:00
|
|
|
|
|
|
|
printf("\n") > dfile
|
2004-08-02 22:43:38 +04:00
|
|
|
|
2016-10-26 04:03:23 +03:00
|
|
|
printf("Maximum vendor string length: %d\n", vendormaxlen + 1)
|
|
|
|
printf("Maximum product string length: %d\n", productmaxlen + 1)
|
|
|
|
printf("\nEnsure that device-specific values are sufficiently large");
|
|
|
|
printf("\ncheck Makefile.%s for details).\n", FILENAME);
|
|
|
|
|
2003-12-15 10:32:20 +03:00
|
|
|
close(dfile)
|
|
|
|
close(hfile)
|
1995-06-18 05:07:04 +04:00
|
|
|
}
|