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