3 * This file is part of kbd project.
4 * Copyright (C) 1993 Risto Kankkunen.
5 * Copyright (C) 1993 Eugene G. Crosser.
6 * Copyright (C) 1994-2007 Andries E. Brouwer.
7 * Copyright (C) 2007-2013 Alexey Gladkov <gladkov.alexey@gmail.com>
9 * This file is covered by the GNU General Public License,
10 * which should be included with kbd as the file COPYING.
13 #define YY_HEADER_EXPORT_START_CONDITIONS 1
20 #include "modifiers.h"
29 #ifndef STRDATA_STRUCT
30 #define STRDATA_STRUCT
31 #define MAX_PARSER_STRING 512
34 unsigned char data[MAX_PARSER_STRING];
47 %lex-param { yyscan_t scanner }
50 %parse-param { void *scanner }
51 %parse-param { struct lk_ctx *ctx }
53 %token EOL NUMBER LITERAL CHARSET KEYMAPS KEYCODE EQUALS
54 %token PLAIN SHIFT CONTROL ALT ALTGR SHIFTL SHIFTR CTRLL CTRLR CAPSSHIFT
55 %token COMMA DASH STRING STRLITERAL COMPOSE TO CCHAR ERROR PLUS
56 %token UNUMBER ALT_IS_META STRINGS AS USUAL ON FOR
63 %type <str> STRLITERAL
73 yyerror(yyscan_t scanner __attribute__ ((unused)),
74 struct lk_ctx *ctx, const char *s)
81 strings_as_usual(struct lk_ctx *ctx)
84 * 26 strings, mostly inspired by the VT100 family
86 char *stringvalues[30] = {
88 "\033[[A", "\033[[B", "\033[[C", "\033[[D", "\033[[E",
89 "\033[17~", "\033[18~", "\033[19~", "\033[20~", "\033[21~",
90 "\033[23~", "\033[24~", "\033[25~", "\033[26~",
91 "\033[28~", "\033[29~",
92 "\033[31~", "\033[32~", "\033[33~", "\033[34~",
93 /* Find, Insert, Remove, Select, Prior */
94 "\033[1~", "\033[2~", "\033[3~", "\033[4~", "\033[5~",
95 /* Next, Macro, Help, Do, Pause */
100 for (i = 0; i < 30; i++) {
101 if (stringvalues[i]) {
104 strncpy((char *)ke.kb_string, stringvalues[i],
105 sizeof(ke.kb_string));
106 ke.kb_string[sizeof(ke.kb_string) - 1] = 0;
108 if (lk_add_func(ctx, ke) == -1)
116 compose_as_usual(struct lk_ctx *ctx, char *charset)
118 if (charset && strcmp(charset, "iso-8859-1")) {
119 ERR(ctx, _("loadkeys: don't know how to compose for %s"), charset);
124 unsigned char c1, c2, c3;
125 } def_latin1_composes[68] = {
126 { '`', 'A', 0300 }, { '`', 'a', 0340 },
127 { '\'', 'A', 0301 }, { '\'', 'a', 0341 },
128 { '^', 'A', 0302 }, { '^', 'a', 0342 },
129 { '~', 'A', 0303 }, { '~', 'a', 0343 },
130 { '"', 'A', 0304 }, { '"', 'a', 0344 },
131 { 'O', 'A', 0305 }, { 'o', 'a', 0345 },
132 { '0', 'A', 0305 }, { '0', 'a', 0345 },
133 { 'A', 'A', 0305 }, { 'a', 'a', 0345 },
134 { 'A', 'E', 0306 }, { 'a', 'e', 0346 },
135 { ',', 'C', 0307 }, { ',', 'c', 0347 },
136 { '`', 'E', 0310 }, { '`', 'e', 0350 },
137 { '\'', 'E', 0311 }, { '\'', 'e', 0351 },
138 { '^', 'E', 0312 }, { '^', 'e', 0352 },
139 { '"', 'E', 0313 }, { '"', 'e', 0353 },
140 { '`', 'I', 0314 }, { '`', 'i', 0354 },
141 { '\'', 'I', 0315 }, { '\'', 'i', 0355 },
142 { '^', 'I', 0316 }, { '^', 'i', 0356 },
143 { '"', 'I', 0317 }, { '"', 'i', 0357 },
144 { '-', 'D', 0320 }, { '-', 'd', 0360 },
145 { '~', 'N', 0321 }, { '~', 'n', 0361 },
146 { '`', 'O', 0322 }, { '`', 'o', 0362 },
147 { '\'', 'O', 0323 }, { '\'', 'o', 0363 },
148 { '^', 'O', 0324 }, { '^', 'o', 0364 },
149 { '~', 'O', 0325 }, { '~', 'o', 0365 },
150 { '"', 'O', 0326 }, { '"', 'o', 0366 },
151 { '/', 'O', 0330 }, { '/', 'o', 0370 },
152 { '`', 'U', 0331 }, { '`', 'u', 0371 },
153 { '\'', 'U', 0332 }, { '\'', 'u', 0372 },
154 { '^', 'U', 0333 }, { '^', 'u', 0373 },
155 { '"', 'U', 0334 }, { '"', 'u', 0374 },
156 { '\'', 'Y', 0335 }, { '\'', 'y', 0375 },
157 { 'T', 'H', 0336 }, { 't', 'h', 0376 },
158 { 's', 's', 0337 }, { '"', 'y', 0377 },
159 { 's', 'z', 0337 }, { 'i', 'j', 0377 }
162 for (i = 0; i < 68; i++) {
163 struct ccc ptr = def_latin1_composes[i];
164 if (lk_add_compose(ctx, ptr.c1, ptr.c2, ptr.c3) == -1)
188 charsetline : CHARSET STRLITERAL EOL
190 if (lk_set_charset(ctx, (char *) $2.data)) {
192 _("unknown charset %s - ignoring charset request\n"),
196 ctx->keywords |= LK_KEYWORD_CHARSET;
198 /* Unicode: The first 256 code points were made
199 identical to the content of ISO 8859-1 */
200 if (ctx->flags & LK_FLAG_PREFER_UNICODE &&
201 !strcasecmp((char *) $2.data, "iso-8859-1"))
202 ctx->flags ^= LK_FLAG_PREFER_UNICODE;
205 altismetaline : ALT_IS_META EOL
207 ctx->keywords |= LK_KEYWORD_ALTISMETA;
210 usualstringsline: STRINGS AS USUAL EOL
212 if (strings_as_usual(ctx) == -1)
214 ctx->keywords |= LK_KEYWORD_STRASUSUAL;
217 usualcomposeline: COMPOSE AS USUAL FOR STRLITERAL EOL
219 if (compose_as_usual(ctx, (char *) $5.data) == -1)
222 | COMPOSE AS USUAL EOL
224 if (compose_as_usual(ctx, 0) == -1)
228 keymapline : KEYMAPS range EOL
230 ctx->keywords |= LK_KEYWORD_KEYMAPS;
233 range : range COMMA range0
236 range0 : NUMBER DASH NUMBER
239 for (i = $1; i <= $3; i++) {
240 if (lk_add_map(ctx, i) == -1)
246 if (lk_add_map(ctx, $1) == -1)
250 strline : STRING LITERAL EQUALS STRLITERAL EOL
254 if (KTYP($2) != KT_FN) {
255 ERR(ctx, _("'%s' is not a function key symbol"),
256 syms[KTYP($2)].table[KVAL($2)]);
260 ke.kb_func = KVAL($2);
261 strncpy((char *) ke.kb_string,
263 sizeof(ke.kb_string));
264 ke.kb_string[sizeof(ke.kb_string) - 1] = 0;
266 if (lk_add_func(ctx, ke) == -1)
270 compline : COMPOSE compsym compsym TO compsym EOL
272 if (lk_add_compose(ctx, $2, $3, $5) == -1)
275 | COMPOSE compsym compsym TO rvalue EOL
277 if (lk_add_compose(ctx, $2, $3, $5) == -1)
281 compsym : CCHAR { $$ = $1; }
282 | UNUMBER { $$ = $1 ^ 0xf000; }
287 modifiers KEYCODE NUMBER EQUALS rvalue EOL
289 if (lk_add_key(ctx, ctx->mod, $4, $6) < 0)
292 | PLAIN KEYCODE NUMBER EQUALS rvalue EOL
294 if (lk_add_key(ctx, 0, $3, $5) < 0)
298 modifiers : modifiers modifier
301 modifier : SHIFT { ctx->mod |= M_SHIFT; }
302 | CONTROL { ctx->mod |= M_CTRL; }
303 | ALT { ctx->mod |= M_ALT; }
304 | ALTGR { ctx->mod |= M_ALTGR; }
305 | SHIFTL { ctx->mod |= M_SHIFTL; }
306 | SHIFTR { ctx->mod |= M_SHIFTR; }
307 | CTRLL { ctx->mod |= M_CTRLL; }
308 | CTRLR { ctx->mod |= M_CTRLR; }
309 | CAPSSHIFT { ctx->mod |= M_CAPSSHIFT; }
311 fullline : KEYCODE NUMBER EQUALS rvalue0 EOL
313 unsigned int j, i, keycode;
316 if (ctx->key_line->count == 1) {
318 /* Some files do not have a keymaps line, and
319 * we have to wait until all input has been read
320 * before we know which maps to fill. */
321 lk_array_set(ctx->key_constant, $2, &one);
323 /* On the other hand, we now have include files,
324 * and it should be possible to override lines
325 * from an include file. So, kill old defs. */
326 for (j = 0; j < ctx->keymap->total; j++) {
327 if (!lk_map_exists(ctx, j))
330 if (lk_del_key(ctx, j, $2) < 0)
335 if (ctx->keywords & LK_KEYWORD_KEYMAPS) {
338 for (j = 0; j < ctx->keymap->total; j++) {
339 if (!lk_map_exists(ctx, j))
342 if (ctx->key_line->count != 1 || i == 0) {
345 if (i < ctx->key_line->count) {
346 val = lk_array_get(ctx->key_line, i);
350 if (lk_add_key(ctx, j, $2, keycode) < 0)
356 if (i < ctx->key_line->count) {
357 ERR(ctx, _("too many (%d) entries on one line"),
358 ctx->key_line->count);
362 for (i = 0; i < ctx->key_line->count; i++) {
363 val = lk_array_get(ctx->key_line, i);
365 if (lk_add_key(ctx, i, $2, *val) < 0)
378 lk_array_append(ctx->key_line, &val);
381 rvalue : NUMBER { $$ = convert_code(ctx, $1, TO_AUTO); }
382 | PLUS NUMBER { $$ = add_capslock(ctx, $2); }
383 | UNUMBER { $$ = convert_code(ctx, $1^0xf000, TO_AUTO); }
384 | PLUS UNUMBER { $$ = add_capslock(ctx, $2^0xf000); }
385 | LITERAL { $$ = $1; }
386 | PLUS LITERAL { $$ = add_capslock(ctx, $2); }
391 lk_parse_keymap(struct lk_ctx *ctx, lkfile_t *f)
396 yylex_init(&scanner);
397 yylex_init_extra(ctx, &scanner);
399 INFO(ctx, _("Loading %s"), f->pathname);
401 if (stack_push(ctx, f, scanner) == -1)
404 if (yyparse(scanner, ctx))
409 stack_pop(ctx, scanner);
411 fail: yylex_destroy(scanner);