xref: /netbsd-src/sys/dev/hil/devlist2h.awk (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1#! /usr/bin/awk -f
2#	$NetBSD: devlist2h.awk,v 1.1 2011/02/06 18:26:54 tsutsui Exp $
3#	$OpenBSD: devlist2h.awk,v 1.4 2006/08/10 23:44:16 miod Exp $
4#
5# Copyright (c) 2003, Miodrag Vallat.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28BEGIN {
29	header = 0
30}
31NR == 1 {
32	VERSION = $0
33	gsub("\\$", "", VERSION)
34
35	printf("/*\t\$NetBSD\$\t*/\n\n")
36	printf("/*\n")
37	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n")
38	printf(" *\n")
39	printf(" * generated from:\n")
40	printf(" *\t%s\n", VERSION)
41	printf(" */\n")
42
43	next
44}
45$1 == "keyboard" || $1 == "mouse" || $1 == "idmodule" || $1 == "buttonbox" {
46
47	if (header == 0) {
48		printf("const struct hildevice hildevs[] = {\n")
49		header = 1
50	}
51
52	printf("\t{ 0x%s, 0x%s, HIL_DEVICE_%s, \"",
53	    $2, $3, toupper($1))
54
55	# description, with optional ``#''-prefixed comments
56	comment = 0
57	i = 4
58	f = i
59	while (f <= NF) {
60		if ($f == "#") {
61			comment = 1
62			printf ("\" },\t/*")
63		} else {
64			if (f > i)
65				printf(" ")
66			printf("%s", $f)
67		}
68		f++
69	}
70	if (comment)
71		printf(" */\n");
72	else
73		printf("\" },\n")
74
75	next
76}
77{
78	if ($0 == "")
79		blanklines++
80	if (blanklines < 2)
81		print $0
82}
83END {
84	printf("\t{ -1, -1, -1, NULL }\n")
85	printf("};\n")
86}
87