map_parse.y revision 1.1 1 /* $NetBSD: map_parse.y,v 1.1 1998/12/28 14:01:17 hannken Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /* Parse a keyboard map. Statements are one of
40 *
41 * keysym sym1 = sym2 Assign the key containing `sym2' to
42 * the key containing `sym1'. This is a copy
43 * from the old to the new map. Therefore it
44 * is possible to exchange keys.
45 *
46 * kecode pos = sym ... assign the symbols to key `pos'.
47 * The first symbol may be a command.
48 * The following symbols are assigned
49 * to the normal and altgr groups.
50 * Missing symbols are generated automacically
51 * as either the upper case variant or the
52 * normal group.
53 */
54
55 %{
56
57 #include <sys/time.h>
58 #include <dev/wscons/wsksymdef.h>
59 #include <dev/wscons/wsconsio.h>
60 #include <err.h>
61 #include "wsconsctl.h"
62
63 extern struct wskbd_map_data kbmap; /* from keyboard.c */
64
65 static struct wscons_keymap mapdata[KS_NUMKEYCODES];
66 struct wskbd_map_data newkbmap; /* used in util.c */
67 static struct wscons_keymap *cur_mp;
68
69 static int ksym_lookup __P((keysym_t));
70
71 static int
72 ksym_lookup(ksym)
73 keysym_t ksym;
74 {
75 int i;
76 struct wscons_keymap *mp;
77
78 for (i = 0; i < kbmap.maplen; i++) {
79 mp = kbmap.map + i;
80 if (mp->command == ksym ||
81 mp->group1[0] == ksym || mp->group1[1] == ksym ||
82 mp->group2[0] == ksym || mp->group2[1] == ksym)
83 return(i);
84 }
85
86 errx(1, "keysym %s not found", ksym2name(ksym));
87 }
88
89 %}
90
91 %union {
92 keysym_t kval;
93 int ival;
94 }
95
96 %token T_KEYSYM T_KEYCODE
97 %token <kval> T_KEYSYM_VAR T_KEYSYM_CMD_VAR
98 %token <ival> T_NUMBER
99
100 %%
101
102 program : = {
103 int i;
104 struct wscons_keymap *mp;
105
106 for (i = 0; i < KS_NUMKEYCODES; i++) {
107 mp = mapdata + i;
108 mp->command = KS_voidSymbol;
109 mp->group1[0] = KS_voidSymbol;
110 mp->group1[1] = KS_voidSymbol;
111 mp->group2[0] = KS_voidSymbol;
112 mp->group2[1] = KS_voidSymbol;
113 }
114
115 newkbmap.maplen = 0;
116 newkbmap.map = mapdata;
117 } expr_list
118 ;
119
120 expr_list : expr
121 | expr_list expr
122 ;
123
124 expr : keysym_expr
125 | keycode_expr
126 ;
127
128 keysym_expr : T_KEYSYM T_KEYSYM_VAR "=" T_KEYSYM_VAR = {
129 int src, dst;
130
131 dst = ksym_lookup($2);
132 src = ksym_lookup($4);
133 newkbmap.map[dst] = kbmap.map[src];
134 if (dst >= newkbmap.maplen)
135 newkbmap.maplen = dst + 1;
136 }
137 ;
138
139 keycode_expr : T_KEYCODE T_NUMBER "=" = {
140 if ($2 >= KS_NUMKEYCODES)
141 errx(1, "%d: keycode too large", $2);
142 if ($2 >= newkbmap.maplen)
143 newkbmap.maplen = $2 + 1;
144 cur_mp = mapdata + $2;
145 } keysym_cmd keysym_list
146 ;
147
148 keysym_cmd : /* empty */
149 | T_KEYSYM_CMD_VAR = {
150 cur_mp->command = $1;
151 }
152 ;
153
154 keysym_list : T_KEYSYM_VAR = {
155 cur_mp->group1[0] = $1;
156 cur_mp->group1[1] = ksym_upcase(cur_mp->group1[0]);
157 cur_mp->group2[0] = cur_mp->group1[0];
158 cur_mp->group2[1] = cur_mp->group1[1];
159 }
160 | T_KEYSYM_VAR T_KEYSYM_VAR = {
161 cur_mp->group1[0] = $1;
162 cur_mp->group1[1] = $2;
163 cur_mp->group2[0] = cur_mp->group1[0];
164 cur_mp->group2[1] = cur_mp->group1[1];
165 }
166 | T_KEYSYM_VAR T_KEYSYM_VAR T_KEYSYM_VAR = {
167 cur_mp->group1[0] = $1;
168 cur_mp->group1[1] = $2;
169 cur_mp->group2[0] = $3;
170 cur_mp->group2[1] = ksym_upcase(cur_mp->group2[0]);
171 }
172 | T_KEYSYM_VAR T_KEYSYM_VAR T_KEYSYM_VAR T_KEYSYM_VAR = {
173 cur_mp->group1[0] = $1;
174 cur_mp->group1[1] = $2;
175 cur_mp->group2[0] = $3;
176 cur_mp->group2[1] = $4;
177 }
178 ;
179 %%
180
181 void
182 yyerror(msg)
183 char *msg;
184 {
185 errx(1, "parse: %s", msg);
186 }
187