devlist2h.awk revision 1.1
1# $OpenBSD: devlist2h.awk,v 1.1 2006/03/04 16:27:03 grange 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: devlist2h.awk,v 1.1 2006/03/04 16:27:03 grange Exp $\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	printf("/*\t$OpenBSD: devlist2h.awk,v 1.1 2006/03/04 16:27:03 grange Exp $\t*/\n\n" \
32	       "/*\n * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n" \
33	       " *\n * Generated from:\n *\t%s\n */\n\n", VERSION) > dfile
34	printf("static const struct onewire_family " \
35	       "onewire_familytab[] = {\n") > dfile
36}
37
38$1 == "family" {
39	printf("#define ONEWIRE_FAMILY_%s\t%s\n", toupper($2), $3) > hfile
40	printf("\t{ ONEWIRE_FAMILY_%s, \"", toupper($2)) > dfile
41
42	f = 4
43	while (f <= NF) {
44		if (f > 4)
45			printf(" ") > dfile
46		printf("%s", $f) > dfile
47		f++
48	}
49	printf("\" },\n") > dfile
50	next
51}
52
53END {
54	printf("\t{ 0, NULL }\n};\n") > dfile
55}
56