xref: /freebsd/usr.sbin/kbdcontrol/lex.l (revision 9a14aa017b21c292740c00ee098195cd46642730)
1 /*-
2  * Copyright (c) 1994-1995 Søren Schmidt
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 %{
32 
33 #include "lex.h"
34 #define YY_NO_UNPUT
35 #define YY_NO_INPUT
36 
37 %}
38 
39 D	[0-9]
40 X	[0-9a-fA-F]
41 A	.
42 L	[OCNB]
43 
44 %%
45 
46 nop		{ return TNOP; }
47 lshift 		{ return TLSH; }
48 rshift 		{ return TRSH; }
49 clock 		{ return TCLK; }
50 nlock		{ return TNLK; }
51 slock 		{ return TSLK; }
52 lalt|alt 	{ return TLALT; }
53 btab		{ return TBTAB; }
54 lctrl|ctrl 	{ return TLCTR; }
55 nscr 		{ return TNEXT; }
56 pscr 		{ return TPREV; }
57 rctrl 		{ return TRCTR; }
58 ralt 		{ return TRALT; }
59 alock 		{ return TALK; }
60 ashift 		{ return TASH; }
61 meta 		{ return TMETA; }
62 boot 		{ return TRBT; }
63 debug 		{ return TDBG; }
64 susp		{ return TSUSP; }
65 saver		{ return TSPSC; }
66 panic		{ return TPANIC; }
67 lshifta|shifta	{ return TLSHA; }
68 rshifta		{ return TRSHA; }
69 lctrla|ctrla	{ return TLCTRA; }
70 rctrla		{ return TRCTRA; }
71 lalta|alta	{ return TLALTA; }
72 ralta		{ return TRALTA; }
73 halt		{ return THALT; }
74 pdwn		{ return TPDWN; }
75 paste		{ return TPASTE; }
76 
77 NUL|nul		{ number = 0; return TNUM; }
78 SOH|soh		{ number = 1; return TNUM; }
79 STX|stx		{ number = 2; return TNUM; }
80 ETX|etx		{ number = 3; return TNUM; }
81 EOT|eot		{ number = 4; return TNUM; }
82 ENQ|enq		{ number = 5; return TNUM; }
83 ACK|ack		{ number = 6; return TNUM; }
84 BEL|bel		{ number = 7; return TNUM; }
85 BS|bs		{ number = 8; return TNUM; }
86 HT|ht		{ number = 9; return TNUM; }
87 LF|lf|NL|nl	{ number = 10; return TNUM; }
88 VT|vt		{ number = 11; return TNUM; }
89 FF|ff|NP|np	{ number = 12; return TNUM; }
90 CR|cr		{ number = 13; return TNUM; }
91 SO|so		{ number = 14; return TNUM; }
92 SI|si		{ number = 15; return TNUM; }
93 DLE|dle		{ number = 16; return TNUM; }
94 DC1|dc1		{ number = 17; return TNUM; }
95 DC2|dc2		{ number = 18; return TNUM; }
96 DC3|dc3		{ number = 19; return TNUM; }
97 DC4|dc4		{ number = 20; return TNUM; }
98 NAK|nak		{ number = 21; return TNUM; }
99 SYN|syn		{ number = 22; return TNUM; }
100 ETB|etb		{ number = 23; return TNUM; }
101 CAN|can		{ number = 24; return TNUM; }
102 EM|em		{ number = 25; return TNUM; }
103 SUB|sub		{ number = 26; return TNUM; }
104 ESC|esc		{ number = 27; return TNUM; }
105 FS|fs		{ number = 28; return TNUM; }
106 GS|gs		{ number = 29; return TNUM; }
107 RS|rs		{ number = 30; return TNUM; }
108 NS|ns		{ number = 31; return TNUM; }
109 US|us		{ number = 31; return TNUM; }
110 SP|sp		{ number = 32; return TNUM; }
111 DEL|del		{ number = 127; return TNUM; }
112 
113 dgra|DGRA	{ number =  0; return TACC; }
114 dacu|DACU	{ number =  1; return TACC; }
115 dcir|DCIR	{ number =  2; return TACC; }
116 dtil|DTIL	{ number =  3; return TACC; }
117 dmac|DMAC	{ number =  4; return TACC; }
118 dbre|DBRE	{ number =  5; return TACC; }
119 ddot|DDOT	{ number =  6; return TACC; }
120 duml|DUML	{ number =  7; return TACC; }
121 ddia|DDIA	{ number =  7; return TACC; }
122 dsla|DSLA	{ number =  8; return TACC; }
123 drin|DRIN	{ number =  9; return TACC; }
124 dced|DCED	{ number =  10; return TACC; }
125 dapo|DAPO	{ number =  11; return TACC; }
126 ddac|DDAC	{ number =  12; return TACC; }
127 dogo|DOGO	{ number =  13; return TACC; }
128 dcar|DCAR	{ number =  14; return TACC; }
129 
130 fkey{D}({D}*)		{
131 				sscanf(yytext+4, "%d", &number);
132 				return TFUNC;
133 			}
134 scr{D}({D}*)		{
135 				sscanf(yytext+3, "%d", &number);
136 				return TSCRN;
137 			}
138 '{A}'			{ letter = *(yytext+1); return TLET; }
139 #({A}*)			{ /* ignore */ }
140 0x{X}({X}*)  		{ sscanf(yytext, "%x", &number); return TNUM; }
141 {D}({D}*)  		{ sscanf(yytext, "%d", &number); return TNUM; }
142 {L}			{
143 				if (*yytext == 'O') number = 0;
144 				if (*yytext == 'C') number = 1;
145 				if (*yytext == 'N') number = 2;
146 				if (*yytext == 'B') number = 3;
147 				return TFLAG;
148 			}
149 [ \t\n]		{ /* ignore */ }
150 .		{ return *yytext; }
151