jcs's openbsd hax
openbsd
1# $OpenBSD: devlist2h.awk,v 1.4 2007/02/28 22:31:32 deraadt Exp $
2
3#
4# Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
5#
6# Permission to use, copy, modify, and distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17#
18
19BEGIN {
20 hfile = "onewiredevs.h"
21 dfile = "onewiredevs_data.h"
22}
23
24NR == 1 {
25 VERSION = $0
26 gsub("\\$", "", VERSION)
27
28 printf("/*\t\$OpenBSD\$\t*/\n\n" \
29 "/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
30 " *\n * Generated from:\n *\t%s\n */\n\n", VERSION) > hfile
31
32 printf("/*\t\$OpenBSD\$\t*/\n\n" \
33 "/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
34 " *\n * Generated from:\n *\t%s\n */\n\n", VERSION) > dfile
35
36 printf("struct onewire_family {\n") > dfile
37 printf("\tint\t\tof_type;\n") > dfile
38 printf("\tconst char\t*of_name;\n") > dfile
39 printf("};\n\n") > dfile
40
41 printf("static const struct onewire_family " \
42 "onewire_famtab[] = {\n") > dfile
43}
44
45$1 == "family" {
46 printf("#define ONEWIRE_FAMILY_%s\t%s\n", toupper($2), $3) > hfile
47 printf("\t{ ONEWIRE_FAMILY_%s, \"", toupper($2)) > dfile
48
49 f = 4
50 while (f <= NF) {
51 if (f > 4)
52 printf(" ") > dfile
53 printf("%s", $f) > dfile
54 f++
55 }
56 printf("\" },\n") > dfile
57 next
58}
59
60END {
61 printf("\t{ 0, NULL }\n};\n") > dfile
62}