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