map_parse.y revision 1.1 1 1.1 hannken /* $NetBSD: map_parse.y,v 1.1 1998/12/28 14:01:17 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.1 hannken %%
101 1.1 hannken
102 1.1 hannken program : = {
103 1.1 hannken int i;
104 1.1 hannken struct wscons_keymap *mp;
105 1.1 hannken
106 1.1 hannken for (i = 0; i < KS_NUMKEYCODES; i++) {
107 1.1 hannken mp = mapdata + i;
108 1.1 hannken mp->command = KS_voidSymbol;
109 1.1 hannken mp->group1[0] = KS_voidSymbol;
110 1.1 hannken mp->group1[1] = KS_voidSymbol;
111 1.1 hannken mp->group2[0] = KS_voidSymbol;
112 1.1 hannken mp->group2[1] = KS_voidSymbol;
113 1.1 hannken }
114 1.1 hannken
115 1.1 hannken newkbmap.maplen = 0;
116 1.1 hannken newkbmap.map = mapdata;
117 1.1 hannken } expr_list
118 1.1 hannken ;
119 1.1 hannken
120 1.1 hannken expr_list : expr
121 1.1 hannken | expr_list expr
122 1.1 hannken ;
123 1.1 hannken
124 1.1 hannken expr : keysym_expr
125 1.1 hannken | keycode_expr
126 1.1 hannken ;
127 1.1 hannken
128 1.1 hannken keysym_expr : T_KEYSYM T_KEYSYM_VAR "=" T_KEYSYM_VAR = {
129 1.1 hannken int src, dst;
130 1.1 hannken
131 1.1 hannken dst = ksym_lookup($2);
132 1.1 hannken src = ksym_lookup($4);
133 1.1 hannken newkbmap.map[dst] = kbmap.map[src];
134 1.1 hannken if (dst >= newkbmap.maplen)
135 1.1 hannken newkbmap.maplen = dst + 1;
136 1.1 hannken }
137 1.1 hannken ;
138 1.1 hannken
139 1.1 hannken keycode_expr : T_KEYCODE T_NUMBER "=" = {
140 1.1 hannken if ($2 >= KS_NUMKEYCODES)
141 1.1 hannken errx(1, "%d: keycode too large", $2);
142 1.1 hannken if ($2 >= newkbmap.maplen)
143 1.1 hannken newkbmap.maplen = $2 + 1;
144 1.1 hannken cur_mp = mapdata + $2;
145 1.1 hannken } keysym_cmd keysym_list
146 1.1 hannken ;
147 1.1 hannken
148 1.1 hannken keysym_cmd : /* empty */
149 1.1 hannken | T_KEYSYM_CMD_VAR = {
150 1.1 hannken cur_mp->command = $1;
151 1.1 hannken }
152 1.1 hannken ;
153 1.1 hannken
154 1.1 hannken keysym_list : T_KEYSYM_VAR = {
155 1.1 hannken cur_mp->group1[0] = $1;
156 1.1 hannken cur_mp->group1[1] = ksym_upcase(cur_mp->group1[0]);
157 1.1 hannken cur_mp->group2[0] = cur_mp->group1[0];
158 1.1 hannken cur_mp->group2[1] = cur_mp->group1[1];
159 1.1 hannken }
160 1.1 hannken | T_KEYSYM_VAR T_KEYSYM_VAR = {
161 1.1 hannken cur_mp->group1[0] = $1;
162 1.1 hannken cur_mp->group1[1] = $2;
163 1.1 hannken cur_mp->group2[0] = cur_mp->group1[0];
164 1.1 hannken cur_mp->group2[1] = cur_mp->group1[1];
165 1.1 hannken }
166 1.1 hannken | T_KEYSYM_VAR T_KEYSYM_VAR T_KEYSYM_VAR = {
167 1.1 hannken cur_mp->group1[0] = $1;
168 1.1 hannken cur_mp->group1[1] = $2;
169 1.1 hannken cur_mp->group2[0] = $3;
170 1.1 hannken cur_mp->group2[1] = ksym_upcase(cur_mp->group2[0]);
171 1.1 hannken }
172 1.1 hannken | T_KEYSYM_VAR T_KEYSYM_VAR T_KEYSYM_VAR T_KEYSYM_VAR = {
173 1.1 hannken cur_mp->group1[0] = $1;
174 1.1 hannken cur_mp->group1[1] = $2;
175 1.1 hannken cur_mp->group2[0] = $3;
176 1.1 hannken cur_mp->group2[1] = $4;
177 1.1 hannken }
178 1.1 hannken ;
179 1.1 hannken %%
180 1.1 hannken
181 1.1 hannken void
182 1.1 hannken yyerror(msg)
183 1.1 hannken char *msg;
184 1.1 hannken {
185 1.1 hannken errx(1, "parse: %s", msg);
186 1.1 hannken }
187