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