1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
/* XKB scanner.
Copyright (C) 2002, 03 Marco Gerards
Written by Marco Gerards <marco@student.han.nl>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */
#include "xkb.h"
#include "parser.tab.h"
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <error.h>
int close_include (void);
int lineno = 1;
char *filename = "foo";
%option nodebug
%option UNPUT
KEYCODE "<"[A-Z][-+A-Z0-9]*">"
DIGIT [0-9]
NUM {DIGIT}{DIGIT}*
FLOAT {DIGIT}{DIGIT}*\.{DIGIT}{DIGIT}*
HEX 0x[A-Za-z0-9]*
IDENTIFIER [a-zA-Z][a-zA-Z0-9_]*
CPPCOMMENT "//".*"\n"
%%
/* When the end of a file is reached, close the
current one and pop the next file to process
of the stack. */
/* Filter out comment. */
{CPPCOMMENT} { lineno++; }
"/*" {
int c;
while((c = input()) != 0)
{
if(c == '\n')
lineno++;
else if(c == '*')
{
if((c = input()) == '/')
break;
else
unput(c);
}
}
}
\n { lineno++; }
/* Beginning of sections. */
xkb_keymap { return XKBKEYMAP; }
xkb_symbols { return XKBSYMBOLS; }
xkb_keycodes { return XKBKEYCODES; }
xkb_types { return XKBTYPES; }
xkb_compatibility { return XKBCOMPAT; }
xkb_geometry { return XKBGEOMETRY; }
/* Real modifiers. */
shift { return SHIFT; }
lock { return LOCK; }
control { return CONTROL; }
ctrl { return CONTROL; }
mod1 { return MOD1; }
mod2 { return MOD2; }
mod3 { return MOD3; }
mod4 { return MOD4; }
mod5 { return MOD5; }
/* Levels. */
anylevel { yylval.val = 0; return LEVEL; }
levelone { yylval.val = 1; return LEVEL; }
level1 { yylval.val = 1; return LEVEL; }
level2 { yylval.val = 2; return LEVEL; }
level3 { yylval.val = 3; return LEVEL; }
level4 { yylval.val = 4; return LEVEL; }
level[1-9][0-9]* { yylval.val = atoi(yytext + 5); return LEVEL; }
/* Groups. */
group1 { yylval.val = 1; return GROUPNUM; }
group2 { yylval.val = 2; return GROUPNUM; }
group3 { yylval.val = 3; return GROUPNUM; }
group4 { yylval.val = 4; return GROUPNUM; }
/* Booleans */
true { yylval.val = 1; return BOOLEAN; }
false { yylval.val = 0; return BOOLEAN; }
/* Interpretation */
interpret { return INTERPRET; }
usemodmap { return USEMODMAP; }
usemodmapmods { return USEMODMAP; }
modmapmods { return USEMODMAP; }
repeat { return REPEAT; }
locking { return LOCKING; }
locks { return LOCKING; }
virtualmodifier { return VIRTUALMODIFIER; }
virtualmod { return VIRTUALMODIFIER; }
/* Interpretation match. */
noneof { yylval.val = 0; return INTERPMATCH ;}
anyofornone { yylval.val = 1; return INTERPMATCH ;}
anyof { yylval.val = 2; return INTERPMATCH ;}
allof { yylval.val = 3; return INTERPMATCH ;}
exactly { yylval.val = 4; return INTERPMATCH ;}
/* SetMods action. */
clearlocks { return CLEARLOCKS; }
mods { return MODS; }
unlock { return UNLOCK; }
both { return BOTH; }
neither { return NEITHER; }
/* Actions. */
setmods { return SETMODS; }
latchmods { return LATCHMODS; }
lockmods { return LOCKMODS; }
setgroup { return SETGROUP; }
latchgroup { return LATCHGROUP; }
lockgroup { return LOCKGROUP; }
setptrdflt { return PTRDFLT; }
setpointerdefault { return PTRDFLT; }
lockptrbtn { return LOCKPTRBTN; }
lockpointerbutton { return LOCKPTRBTN; }
lockptrbutton { return LOCKPTRBTN; }
lockpointerbtn { return LOCKPTRBTN; }
setcontrols { return SETCONTROLS; }
lockcontrols { return LOCKCONTROLS; }
terminateserver { return TERMINATE; }
terminate { return TERMINATE; }
switchscreen { return SWITCHSCREEN; }
consscroll { return CONSSCROLL; }
consolescroll { return CONSSCROLL; }
moveptr { return MOVEPTR; }
private { return PRIVATE; }
/* Action parameters. */
latchtolock { return LATCHTOLOCK; }
group { return GROUP; }
groups { return GROUPS; }
accel { return ACCEL; }
accelerate { return ACCEL; }
default { return DEFAULT; }
count { return COUNT; }
controls { return CONTROLS; }
same { return SAMESERVER; }
sameserver { return SAMESERVER; }
screen { return SCREEN; }
line { return LINE; }
percentage { return PERCENT; }
ptrbtn { return PTRBTN ; }
pointerbutton { return PTRBTN ; }
action { return ACTION; }
actions { return ACTIONS; }
whichmodstate { return WHICHMODSTATE; }
whichmodifierstate { return WHICHMODSTATE; }
whichgroupstate { return WHICHGROUPSTATE; }
/* Match state for indicator. */
base { yylval.val = 0; return WHICHSTATE; }
latched { yylval.val = 1; return WHICHSTATE; }
locked { yylval.val = 4; return WHICHSTATE; }
effective { yylval.val = 8; return WHICHSTATE; }
/* Bits for binary controls. */
repeatkeys { yylval.val = 0; return CONTROLFLAG; }
autorepeat { yylval.val = 0; return CONTROLFLAG; }
accessxkeys { yylval.val = 0; return CONTROLFLAG; }
slowkeys { yylval.val = 0; return CONTROLFLAG; }
bouncekeys { yylval.val = 0; return CONTROLFLAG; }
stickykeys { yylval.val = 0; return CONTROLFLAG; }
accessxtimeout { yylval.val = 0; return CONTROLFLAG; }
accessxfeedback { yylval.val = 0; return CONTROLFLAG; }
mousekeys { yylval.val = 0; return CONTROLFLAG; }
mousekeysaccel { yylval.val = 0; return CONTROLFLAG; }
audiblebell { yylval.val = 0; return CONTROLFLAG; }
ignoregrouplock { yylval.val = 0; return CONTROLFLAG; }
index { return INDEX; }
name { return NAME; }
symbols { return SYMBOLS; }
key { return KEY; }
/* Mouse buttons. */
button1 { yylval.val = 1; return BUTTONNUM; }
button2 { yylval.val = 2; return BUTTONNUM; }
button3 { yylval.val = 3; return BUTTONNUM; }
button4 { yylval.val = 4; return BUTTONNUM; }
button5 { yylval.val = 5; return BUTTONNUM; }
button { return BUTTON; }
/* Fuzzyness. */
any { return ANY; }
all { return ALL; }
none { return NONE; }
defaultbutton { return DEFAULTBTN; }
affect { return AFFECT; }
allowexplicit { return ALLOWEXPLICIT; }
/* Feedback to the keyboard. */
driveskeyboard { return DRIVESKBD; }
driveskbd { return DRIVESKBD; }
ledsdrivekbd { return DRIVESKBD; }
ledsdrivekeyboard { return DRIVESKBD; }
indicatordriveskbd { return DRIVESKBD; }
indicatordriveskeyboard { return DRIVESKBD; }
modifier_map { return MODMAP; }
minimum { return MINIMUM; }
maximum { return MAXIMUM; }
virtual { return VIRTUAL; }
alias { return ALIAS; }
indicator { return INDICATOR; }
virtual_modifiers { return VMODS; }
virtualmods { return VMODS; }
vmods { return VMODS; }
type { return TYPE; }
data { return DATA; }
modifiers { return MODS; }
map { return MAP; }
level_name { return LEVEL_NAME; }
preserve { return PRESERVE; }
/* Section flags. */
partial { yylval.val = 1; return FLAGS; }
complete { yylval.val = 2; return FLAGS; }
fc { yylval.val = 4; return FLAGS; }
fd { yylval.val = 8; return FLAGS; }
cp { return XKBCOMPAT; }
/* Section merge modes. */
include { yylval.mergemode = defaultmm; return INCLUDE; }
augment { yylval.mergemode = augment; return AUGMENT; }
replace { yylval.mergemode = replace; return REPLACE; }
override { yylval.mergemode = override; return OVERRIDE; }
isolock { return ISOLOCK; }
pointers { return POINTERS;}
ptr { return POINTERS;}
noaction { return NOACTION;}
groupswrap { return GROUPSWRAP; }
wrapgroups { return GROUPSWRAP; }
clampgroups { return GROUPSCLAMP; }
groupsredirect { return GROUPSREDIRECT; }
overlay1 { yylval.val = 1; return OVERLAY; }
overlay2 { yylval.val = 2; return OVERLAY; }
/* String. */
\"([^"]|\\\")*\" {
yytext[strlen (yytext) - 1] = '\0';
yylval.str = strdup (yytext + 1);
return STR;
}
/* Ignore whitespace. */
[ \t]*
/* A keycode. */
{KEYCODE} { yylval.str = strdup (yytext) + 1; yylval.str[strlen (yylval.str) - 1] = 0; return KEYCODE; }
/* A float vlaue. */
{FLOAT} { yylval.dbl = atof (yytext); return FLOAT; }
/* An integer. */
{NUM} { yylval.val = atoi (yytext); return NUM; }
/* A hexadecimal value. */
{HEX} { sscanf (yytext, "0x%X", &yylval.val); return HEX; }
/* An identifier. */
{IDENTIFIER} { yylval.str = strdup (yytext); return IDENTIFIER; }
/* All unrecognized characters. */
. { return yytext[0]; }
%%
/* Stupid hack, the current version of flex is fucked. */
#define yytext_ptr yytext
void
scanner_unput (int c)
{
unput (c);
}
int
yywrap (void)
{
if (close_include () == 0)
return 0;
else
return 1;
}
#define MAX_INCLUDE_DEPTH 50
/* An include file on the stack. */
struct include_stack
{
YY_BUFFER_STATE buffer;
mergemode merge_mode;
int currline;
char *filename;
} include_stack[MAX_INCLUDE_DEPTH];
int include_stack_ptr = 0;
/* Add an file to the stack. */
void
include_file (FILE *file, mergemode new_mm, char *fname)
{
YY_BUFFER_STATE buffer;
debug_printf ("including file %s\n.", fname);
if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
{
fprintf (stderr, "Includes nested too deeply\n");
exit (EXIT_FAILURE);
}
include_stack[include_stack_ptr].filename = filename;
include_stack[include_stack_ptr].currline = lineno;
include_stack[include_stack_ptr].merge_mode = merge_mode;
include_stack[include_stack_ptr++].buffer = YY_CURRENT_BUFFER;
filename = fname;
lineno = 1;
merge_mode = new_mm;
buffer = yy_create_buffer (file, YY_BUF_SIZE);
yy_switch_to_buffer (buffer);
}
/* Close an includefile. returns 0 on success */
int
close_include (void)
{
if ( --include_stack_ptr < 0 )
{
fprintf (stderr, "Unexpected end of file at %s:%d.\n", filename, lineno);
return (1);
}
else
{
fclose (yyin);
yy_delete_buffer (YY_CURRENT_BUFFER);
merge_mode = include_stack[include_stack_ptr].merge_mode;
lineno = include_stack[include_stack_ptr].currline;
filename = include_stack[include_stack_ptr].filename;
yy_switch_to_buffer (include_stack[include_stack_ptr].buffer);
debug_printf ("closing file. going back to %s.\n", filename);
return (0);
}
}
void
yyerror (char *s)
{
fprintf (stderr, "%s:%d: %s\n", filename, lineno, s);
// error_at_line (0, 1, filename, lineno, "foo %d\n", 2);
}
int
scanner_get_current_location()
{
return lineno;
}
const char*
scanner_get_current_file()
{
return filename;
}
|