Home | History | Annotate | Line # | Download | only in wsconsctl
map_parse.y revision 1.5
      1  1.5  christos /*	$NetBSD: map_parse.y,v 1.5 2005/06/26 22:45:50 christos 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.3     itohy  * keycode 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.3     itohy  *				Missing symbols are generated automatically
     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.4   xtraeme static int ksym_lookup(keysym_t);
     70  1.1   hannken 
     71  1.1   hannken static int
     72  1.4   xtraeme ksym_lookup(keysym_t ksym)
     73  1.1   hannken {
     74  1.1   hannken 	int i;
     75  1.1   hannken 	struct wscons_keymap *mp;
     76  1.1   hannken 
     77  1.1   hannken 	for (i = 0; i < kbmap.maplen; i++) {
     78  1.1   hannken 		mp = kbmap.map + i;
     79  1.1   hannken 		if (mp->command == ksym ||
     80  1.1   hannken 		    mp->group1[0] == ksym || mp->group1[1] == ksym ||
     81  1.1   hannken 		    mp->group2[0] == ksym || mp->group2[1] == ksym)
     82  1.1   hannken 			return(i);
     83  1.1   hannken 	}
     84  1.1   hannken 
     85  1.1   hannken 	errx(1, "keysym %s not found", ksym2name(ksym));
     86  1.1   hannken }
     87  1.1   hannken 
     88  1.1   hannken %}
     89  1.1   hannken 
     90  1.1   hannken %union {
     91  1.1   hannken 		keysym_t kval;
     92  1.1   hannken 		int ival;
     93  1.1   hannken 	}
     94  1.1   hannken 
     95  1.1   hannken %token T_KEYSYM T_KEYCODE
     96  1.1   hannken %token <kval> T_KEYSYM_VAR T_KEYSYM_CMD_VAR
     97  1.1   hannken %token <ival> T_NUMBER
     98  1.1   hannken 
     99  1.2   hannken %type <kval> keysym_var
    100  1.2   hannken 
    101  1.1   hannken %%
    102  1.1   hannken 
    103  1.1   hannken program		: = {
    104  1.1   hannken 			int i;
    105  1.1   hannken 			struct wscons_keymap *mp;
    106  1.1   hannken 
    107  1.1   hannken 			for (i = 0; i < KS_NUMKEYCODES; i++) {
    108  1.1   hannken 				mp = mapdata + i;
    109  1.1   hannken 				mp->command = KS_voidSymbol;
    110  1.1   hannken 				mp->group1[0] = KS_voidSymbol;
    111  1.1   hannken 				mp->group1[1] = KS_voidSymbol;
    112  1.1   hannken 				mp->group2[0] = KS_voidSymbol;
    113  1.1   hannken 				mp->group2[1] = KS_voidSymbol;
    114  1.1   hannken 			}
    115  1.1   hannken 
    116  1.1   hannken 			newkbmap.maplen = 0;
    117  1.1   hannken 			newkbmap.map = mapdata;
    118  1.1   hannken 		} expr_list
    119  1.1   hannken 		;
    120  1.1   hannken 
    121  1.1   hannken expr_list	: expr
    122  1.1   hannken 		| expr_list expr
    123  1.1   hannken 		;
    124  1.1   hannken 
    125  1.1   hannken expr		: keysym_expr
    126  1.1   hannken 		| keycode_expr
    127  1.1   hannken 		;
    128  1.1   hannken 
    129  1.2   hannken keysym_expr	: T_KEYSYM keysym_var "=" keysym_var = {
    130  1.1   hannken 			int src, dst;
    131  1.1   hannken 
    132  1.1   hannken 			dst = ksym_lookup($2);
    133  1.1   hannken 			src = ksym_lookup($4);
    134  1.1   hannken 			newkbmap.map[dst] = kbmap.map[src];
    135  1.1   hannken 			if (dst >= newkbmap.maplen)
    136  1.1   hannken 				newkbmap.maplen = dst + 1;
    137  1.1   hannken 		}
    138  1.1   hannken 		;
    139  1.1   hannken 
    140  1.1   hannken keycode_expr	: T_KEYCODE T_NUMBER "=" = {
    141  1.1   hannken 			if ($2 >= KS_NUMKEYCODES)
    142  1.1   hannken 				errx(1, "%d: keycode too large", $2);
    143  1.1   hannken 			if ($2 >= newkbmap.maplen)
    144  1.1   hannken 				newkbmap.maplen = $2 + 1;
    145  1.1   hannken 			cur_mp = mapdata + $2;
    146  1.1   hannken 		} keysym_cmd keysym_list
    147  1.1   hannken 		;
    148  1.1   hannken 
    149  1.1   hannken keysym_cmd	: /* empty */
    150  1.1   hannken 		| T_KEYSYM_CMD_VAR = {
    151  1.1   hannken 			cur_mp->command = $1;
    152  1.1   hannken 		}
    153  1.1   hannken 		;
    154  1.1   hannken 
    155  1.2   hannken keysym_list	: keysym_var = {
    156  1.1   hannken 			cur_mp->group1[0] = $1;
    157  1.1   hannken 			cur_mp->group1[1] = ksym_upcase(cur_mp->group1[0]);
    158  1.1   hannken 			cur_mp->group2[0] = cur_mp->group1[0];
    159  1.1   hannken 			cur_mp->group2[1] = cur_mp->group1[1];
    160  1.1   hannken 		}
    161  1.2   hannken 		| keysym_var keysym_var = {
    162  1.1   hannken 			cur_mp->group1[0] = $1;
    163  1.1   hannken 			cur_mp->group1[1] = $2;
    164  1.1   hannken 			cur_mp->group2[0] = cur_mp->group1[0];
    165  1.1   hannken 			cur_mp->group2[1] = cur_mp->group1[1];
    166  1.1   hannken 		}
    167  1.2   hannken 		| keysym_var keysym_var keysym_var = {
    168  1.1   hannken 			cur_mp->group1[0] = $1;
    169  1.1   hannken 			cur_mp->group1[1] = $2;
    170  1.1   hannken 			cur_mp->group2[0] = $3;
    171  1.1   hannken 			cur_mp->group2[1] = ksym_upcase(cur_mp->group2[0]);
    172  1.1   hannken 		}
    173  1.2   hannken 		| keysym_var keysym_var keysym_var keysym_var = {
    174  1.1   hannken 			cur_mp->group1[0] = $1;
    175  1.1   hannken 			cur_mp->group1[1] = $2;
    176  1.1   hannken 			cur_mp->group2[0] = $3;
    177  1.1   hannken 			cur_mp->group2[1] = $4;
    178  1.1   hannken 		}
    179  1.1   hannken 		;
    180  1.2   hannken 
    181  1.2   hannken keysym_var	: T_KEYSYM_VAR = {
    182  1.2   hannken 			$$ = $1;
    183  1.2   hannken 		}
    184  1.2   hannken 		| T_NUMBER = {
    185  1.2   hannken 			char name[2];
    186  1.2   hannken 			int res;
    187  1.2   hannken 
    188  1.2   hannken 			if ($1 < 0 || $1 > 9)
    189  1.2   hannken 				yyerror("keysym expected");
    190  1.2   hannken 			name[0] = $1 + '0';
    191  1.2   hannken 			name[1] = '\0';
    192  1.2   hannken 			res = name2ksym(name);
    193  1.2   hannken 			if (res < 0)
    194  1.2   hannken 				yyerror("keysym expected");
    195  1.2   hannken 			$$ = res;
    196  1.2   hannken 		};
    197  1.1   hannken %%
    198  1.1   hannken 
    199  1.1   hannken void
    200  1.5  christos yyerror(const char *msg)
    201  1.1   hannken {
    202  1.1   hannken 	errx(1, "parse: %s", msg);
    203  1.1   hannken }
    204