devlist2h.awk revision 1.1.6.2 1 1.1.6.2 yamt # $NetBSD: devlist2h.awk,v 1.1.6.2 2014/05/22 11:39:50 yamt Exp $
2 1.1.6.2 yamt
3 1.1.6.2 yamt # $OpenBSD: devlist2h.awk,v 1.6 2004/04/07 18:24:19 mickey Exp $
4 1.1.6.2 yamt
5 1.1.6.2 yamt #
6 1.1.6.2 yamt # Copyright (c) 1998-2003 Michael Shalayeff
7 1.1.6.2 yamt # All rights reserved.
8 1.1.6.2 yamt #
9 1.1.6.2 yamt # Redistribution and use in source and binary forms, with or without
10 1.1.6.2 yamt # modification, are permitted provided that the following conditions
11 1.1.6.2 yamt # are met:
12 1.1.6.2 yamt # 1. Redistributions of source code must retain the above copyright
13 1.1.6.2 yamt # notice, this list of conditions and the following disclaimer.
14 1.1.6.2 yamt # 2. Redistributions in binary form must reproduce the above copyright
15 1.1.6.2 yamt # notice, this list of conditions and the following disclaimer in the
16 1.1.6.2 yamt # documentation and/or other materials provided with the distribution.
17 1.1.6.2 yamt #
18 1.1.6.2 yamt # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1.6.2 yamt # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1.6.2 yamt # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1.6.2 yamt # IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 1.1.6.2 yamt # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 1.1.6.2 yamt # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 1.1.6.2 yamt # SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.1.6.2 yamt # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 1.1.6.2 yamt # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 1.1.6.2 yamt # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 1.1.6.2 yamt # THE POSSIBILITY OF SUCH DAMAGE.
29 1.1.6.2 yamt #
30 1.1.6.2 yamt
31 1.1.6.2 yamt BEGIN {
32 1.1.6.2 yamt ncpu = busted = 0;
33 1.1.6.2 yamt cpuh="cpudevs.h";
34 1.1.6.2 yamt cpud="cpudevs_data.h";
35 1.1.6.2 yamt SUBSEP = "_";
36 1.1.6.2 yamt }
37 1.1.6.2 yamt
38 1.1.6.2 yamt /^[ \t]*$/ {next}
39 1.1.6.2 yamt
40 1.1.6.2 yamt /^[ \t]*\/\*/ {busted++}
41 1.1.6.2 yamt
42 1.1.6.2 yamt /^[ \t]*#/ {next}
43 1.1.6.2 yamt
44 1.1.6.2 yamt busted {
45 1.1.6.2 yamt cp = match($0, /\*\//);
46 1.1.6.2 yamt if(!cp) {
47 1.1.6.2 yamt next;
48 1.1.6.2 yamt } else if (cp + 1 == length($0)) {
49 1.1.6.2 yamt busted = 0;
50 1.1.6.2 yamt next;
51 1.1.6.2 yamt } else {
52 1.1.6.2 yamt sub(/.*\*\//, "");
53 1.1.6.2 yamt busted = 0;
54 1.1.6.2 yamt }
55 1.1.6.2 yamt }
56 1.1.6.2 yamt
57 1.1.6.2 yamt # first line is rcsid, beware
58 1.1.6.2 yamt NR == 1 {
59 1.1.6.2 yamt VERSION = $0;
60 1.1.6.2 yamt gsub("\\$", "", VERSION);
61 1.1.6.2 yamt
62 1.1.6.2 yamt printf("/*\t$NetBSD" "$\t*/\n\n") > cpud;
63 1.1.6.2 yamt printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
64 1.1.6.2 yamt " * generated from:\n *\t%s\n */\n\n", VERSION) > cpud;
65 1.1.6.2 yamt printf("/*\t$NetBSD" "$\t*/\n\n") > cpuh;
66 1.1.6.2 yamt printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
67 1.1.6.2 yamt " * generated from:\n *\t%s\n */\n\n", VERSION) > cpuh;
68 1.1.6.2 yamt }
69 1.1.6.2 yamt
70 1.1.6.2 yamt /^\$/ {
71 1.1.6.2 yamt next;
72 1.1.6.2 yamt }
73 1.1.6.2 yamt
74 1.1.6.2 yamt NF > 0 && $1 == "type" {
75 1.1.6.2 yamt printf("#define\tHPPA_TYPE_%s\t%s\n", toupper($2), $3) > cpuh;
76 1.1.6.2 yamt types[tolower($2)] = toupper($2);
77 1.1.6.2 yamt next;
78 1.1.6.2 yamt }
79 1.1.6.2 yamt
80 1.1.6.2 yamt NR > 1 {
81 1.1.6.2 yamt if (tolower($1) in types) {
82 1.1.6.2 yamt printf("#define\tHPPA_%s_%s\t%s\n", toupper($1),
83 1.1.6.2 yamt toupper($2), $3) > cpuh;
84 1.1.6.2 yamt printf("{HPPA_TYPE_%s,\tHPPA_%s_%s,\t\"", toupper($1),
85 1.1.6.2 yamt toupper($1), toupper($2), $3) > cpud;
86 1.1.6.2 yamt f = 4;
87 1.1.6.2 yamt while (f <= NF) {
88 1.1.6.2 yamt sub(/[ \t]*/, "", $f);
89 1.1.6.2 yamt ep = match($f, /\*\//);
90 1.1.6.2 yamt if (busted && !ep) {
91 1.1.6.2 yamt f++;
92 1.1.6.2 yamt continue;
93 1.1.6.2 yamt }
94 1.1.6.2 yamt if (match($f, /\/\*/)) {
95 1.1.6.2 yamt if (ep) {
96 1.1.6.2 yamt sub(/\/\*/, "", $f);
97 1.1.6.2 yamt } else {
98 1.1.6.2 yamt sub(/\/\*.*$/, "", $f);
99 1.1.6.2 yamt busted++;
100 1.1.6.2 yamt }
101 1.1.6.2 yamt }
102 1.1.6.2 yamt if (ep) {
103 1.1.6.2 yamt gsub(/^.*\*\//, "", $f);
104 1.1.6.2 yamt busted = 0;
105 1.1.6.2 yamt }
106 1.1.6.2 yamt if (length($f)) {
107 1.1.6.2 yamt if (f > 4)
108 1.1.6.2 yamt printf (" ") > cpud;
109 1.1.6.2 yamt printf ("%s", $f) > cpud;
110 1.1.6.2 yamt }
111 1.1.6.2 yamt f++;
112 1.1.6.2 yamt }
113 1.1.6.2 yamt printf("\" },\n") > cpud;
114 1.1.6.2 yamt } else {
115 1.1.6.2 yamt printf("WHA at line %d\n", NR);
116 1.1.6.2 yamt exit(1);
117 1.1.6.2 yamt }
118 1.1.6.2 yamt }
119 1.1.6.2 yamt
120 1.1.6.2 yamt END {
121 1.1.6.2 yamt if (busted) {
122 1.1.6.2 yamt print("unterminated comment at the EOF\n");
123 1.1.6.2 yamt exit(1);
124 1.1.6.2 yamt }
125 1.1.6.2 yamt close(cpud)
126 1.1.6.2 yamt close(cpuh)
127 1.1.6.2 yamt }
128