syscons - Fix NULL pointer access in 0d7c8a4d1cafae68239
[dragonfly.git] / sys / tools / acpi_quirks2h.awk
blob096c8ee7111ed9facf45cf984c4e9e792f95c227
1 #!/usr/bin/awk -f
3 # $FreeBSD: head/sys/tools/acpi_quirks2h.awk 167814 2007-03-22 18:16:43Z jkim $
5 #-
6 # Copyright (c) 2004 Mark Santcroos <marks@ripe.net>
7 # All rights reserved.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # SUCH DAMAGE.
31 BEGIN {
32 OUTPUT="acpi_quirks.h"
35 # Print header and id
36 NR == 1 {
37 VERSION = $0;
38 gsub("\^# ", "", VERSION)
39 gsub("\\$", "", VERSION)
41 printf("/*\n") > OUTPUT;
42 printf(" * THIS FILE IS AUTOMAGICALLY GENERATED. DO NOT EDIT.\n") \
43 > OUTPUT;
44 printf(" *\n") > OUTPUT;
45 printf(" * Generated from:\n") > OUTPUT;
46 printf(" * %s\n", VERSION) > OUTPUT;
47 printf(" */\n\n") > OUTPUT;
50 # Ignore comments and empty lines
51 /^#/, NF == 0 {
55 # NAME field: this is the first line of every entry
57 $1 == "name:" {
58 ENTRY_NAME = $2;
59 printf("const struct acpi_q_rule %s[] = {\n", ENTRY_NAME) > OUTPUT;
63 # OEM field
65 $1 == "oem:" {
66 LENGTH = length();
68 # Parse table type to match
69 TABLE = $2;
71 # Parse OEM ID
72 M = match ($0, /\"[^\"]*\"/);
73 OEM_ID = substr($0, M, RLENGTH);
75 # Parse OEM Table ID
76 ANCHOR = LENGTH - (M + RLENGTH - 1);
77 REMAINDER = substr($0, M + RLENGTH, ANCHOR);
78 M = match (REMAINDER, /\"[^\"]*\"/);
79 OEM_TABLE_ID = substr(REMAINDER, M, RLENGTH);
81 printf("\t{ \"%s\", OEM, {%s}, {%s} },\n",
82 TABLE, OEM_ID, OEM_TABLE_ID) > OUTPUT;
86 # CREATOR field
88 $1 == "creator:" {
89 # Parse table type to match
90 TABLE = $2;
92 M = match ($0, /\"[^\"]*\"/);
93 CREATOR = substr($0, M, RLENGTH);
95 printf("\t{ \"%s\", CREATOR, {%s} },\n",
96 TABLE, CREATOR) > OUTPUT;
100 # OEM REVISION field
102 $1 == "oem_rev:" {
103 TABLE = $2;
104 SIGN = $3;
105 VALUE = $4;
107 # Parse operand
108 OPERAND = trans_sign(SIGN);
110 printf("\t{ \"%s\", OEM_REV, {.op = %s}, {.rev = %s} },\n",
111 TABLE, OPERAND, VALUE) > OUTPUT;
115 # CREATOR REVISION field
117 $1 == "creator_rev:" {
118 TABLE = $2;
119 SIGN = $3;
120 VALUE = $4;
122 # Parse operand
123 OPERAND = trans_sign(SIGN);
125 printf("\t{ \"%s\", CREATOR_REV, {.op = %s}, {.rev = %s} },\n",
126 TABLE, OPERAND, VALUE) > OUTPUT;
130 # QUIRKS field: This is the last line of every entry
132 $1 == "quirks:" {
133 printf("\t{ \"\" }\n};\n\n") > OUTPUT;
135 QUIRKS = $0;
136 sub(/^quirks:[ ]*/ , "", QUIRKS);
138 QUIRK_COUNT++;
139 QUIRK_LIST[QUIRK_COUNT] = QUIRKS;
140 QUIRK_NAME[QUIRK_COUNT] = ENTRY_NAME;
144 # All information is gathered, now create acpi_quirks_table
146 END {
147 # Header
148 printf("const struct acpi_q_entry acpi_quirks_table[] = {\n") \
149 > OUTPUT;
151 # Array of all quirks
152 for (i = 1; i <= QUIRK_COUNT; i++) {
153 printf("\t{ %s, %s },\n", QUIRK_NAME[i], QUIRK_LIST[i]) \
154 > OUTPUT;
157 # Footer
158 printf("\t{ NULL, 0 }\n") > OUTPUT;
159 printf("};\n") > OUTPUT;
161 exit(0);
165 # Translate math SIGN into verbal OPERAND
167 function trans_sign(TMP_SIGN)
169 if (TMP_SIGN == "=")
170 TMP_OPERAND = "OP_EQL";
171 else if (TMP_SIGN == "!=")
172 TMP_OPERAND = "OP_NEQ";
173 else if (TMP_SIGN == "<=")
174 TMP_OPERAND = "OP_LEQ";
175 else if (TMP_SIGN == ">=")
176 TMP_OPERAND = "OP_GEQ";
177 else if (TMP_SIGN == ">")
178 TMP_OPERAND = "OP_GTR";
179 else if (TMP_SIGN == "<")
180 TMP_OPERAND = "OP_LES";
181 else {
182 printf("error: unknown sign: " TMP_SIGN "\n");
183 exit(1);
186 return (TMP_OPERAND);