1 /************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
31 #include <X11/XKBlib.h>
34 #define DEBUG_VAR scanDebug
36 #include "parseutils.h"
38 unsigned int scanDebug;
42 static char scanFileBuf[1024] = {0};
43 char *scanFile = scanFileBuf;
49 static int scanStrLine = 0;
52 static char readBuf[BUFSIZE];
53 static int readBufPos = 0;
54 static int readBufLen = 0;
57 extern int debugFlags;
67 snprintf(buf, sizeof(buf), "END_OF_FILE");
70 snprintf(buf, sizeof(buf), "ERROR");
74 snprintf(buf, sizeof(buf), "XKB_KEYMAP");
77 snprintf(buf, sizeof(buf), "XKB_KEYCODES");
80 snprintf(buf, sizeof(buf), "XKB_TYPES");
83 snprintf(buf, sizeof(buf), "XKB_SYMBOLS");
86 snprintf(buf, sizeof(buf), "XKB_COMPATMAP");
89 snprintf(buf, sizeof(buf), "XKB_GEOMETRY");
92 snprintf(buf, sizeof(buf), "XKB_SEMANTICS");
95 snprintf(buf, sizeof(buf), "XKB_LAYOUT");
99 snprintf(buf, sizeof(buf), "INCLUDE");
102 snprintf(buf, sizeof(buf), "OVERRIDE");
105 snprintf(buf, sizeof(buf), "AUGMENT");
108 snprintf(buf, sizeof(buf), "REPLACE");
111 snprintf(buf, sizeof(buf), "ALTERNATE");
115 snprintf(buf, sizeof(buf), "VIRTUAL_MODS");
118 snprintf(buf, sizeof(buf), "TYPE");
121 snprintf(buf, sizeof(buf), "INTERPRET");
124 snprintf(buf, sizeof(buf), "ACTION");
127 snprintf(buf, sizeof(buf), "KEY");
130 snprintf(buf, sizeof(buf), "ALIAS");
133 snprintf(buf, sizeof(buf), "GROUP");
136 snprintf(buf, sizeof(buf), "MODIFIER_MAP");
139 snprintf(buf, sizeof(buf), "INDICATOR");
142 snprintf(buf, sizeof(buf), "SHAPE");
145 snprintf(buf, sizeof(buf), "KEYS");
148 snprintf(buf, sizeof(buf), "ROW");
151 snprintf(buf, sizeof(buf), "SECTION");
154 snprintf(buf, sizeof(buf), "OVERLAY");
157 snprintf(buf, sizeof(buf), "TEXT");
160 snprintf(buf, sizeof(buf), "OUTLINE");
163 snprintf(buf, sizeof(buf), "SOLID");
166 snprintf(buf, sizeof(buf), "LOGO");
169 snprintf(buf, sizeof(buf), "VIRTUAL");
173 snprintf(buf, sizeof(buf), "EQUALS");
176 snprintf(buf, sizeof(buf), "PLUS");
179 snprintf(buf, sizeof(buf), "MINUS");
182 snprintf(buf, sizeof(buf), "DIVIDE");
185 snprintf(buf, sizeof(buf), "TIMES");
188 snprintf(buf, sizeof(buf), "OBRACE");
191 snprintf(buf, sizeof(buf), "CBRACE");
194 snprintf(buf, sizeof(buf), "OPAREN");
197 snprintf(buf, sizeof(buf), "CPAREN");
200 snprintf(buf, sizeof(buf), "OBRACKET");
203 snprintf(buf, sizeof(buf), "CBRACKET");
206 snprintf(buf, sizeof(buf), "DOT");
209 snprintf(buf, sizeof(buf), "COMMA");
212 snprintf(buf, sizeof(buf), "SEMI");
215 snprintf(buf, sizeof(buf), "EXCLAM");
218 snprintf(buf, sizeof(buf), "INVERT");
222 snprintf(buf, sizeof(buf), "STRING (%s)", scanBuf);
225 snprintf(buf, sizeof(buf), "INTEGER (0x%x)", scanInt);
228 snprintf(buf, sizeof(buf), "FLOAT (%d.%d)",
229 scanInt / XkbGeomPtsPerMM, scanInt % XkbGeomPtsPerMM);
232 snprintf(buf, sizeof(buf), "IDENT (%s)", scanBuf);
235 snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanBuf);
239 snprintf(buf, sizeof(buf), "PARTIAL");
242 snprintf(buf, sizeof(buf), "DEFAULT");
245 snprintf(buf, sizeof(buf), "HIDDEN");
248 case ALPHANUMERIC_KEYS:
249 snprintf(buf, sizeof(buf), "ALPHANUMERIC_KEYS");
252 snprintf(buf, sizeof(buf), "MODIFIER_KEYS");
255 snprintf(buf, sizeof(buf), "KEYPAD_KEYS");
258 snprintf(buf, sizeof(buf), "FUNCTION_KEYS");
260 case ALTERNATE_GROUP:
261 snprintf(buf, sizeof(buf), "ALTERNATE_GROUP");
265 snprintf(buf, sizeof(buf), "UNKNOWN");
275 if (readBufPos >= readBufLen) {
276 readBufLen = fread(readBuf, 1, BUFSIZE, yyin);
281 readBuf[readBufLen] = EOF;
284 return readBuf[readBufPos++];
290 if (readBuf[--readBufPos] != c) {
291 fprintf(stderr, "UNGETCHAR FAILED! Put back %c, was expecting %c at "
292 "position %d, buf is '%s'\n", c, readBuf[readBufPos],
293 readBufPos, readBuf);
299 setScanState(char *file, int line)
302 strncpy(scanFile, file, 1024);
314 while (((ch = scanchar()) != EOF) && (ch != '"'))
318 if ((ch = scanchar()) != EOF)
338 if (((tmp = scanchar()) != EOF) && (isdigit(tmp))
339 && (tmp != '8') && (tmp != '9'))
341 ch = (ch * 8) + (tmp - '0');
350 if (((tmp = scanchar()) != EOF)
351 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
353 ch = (ch * 8) + (tmp - '0');
363 if (((tmp = scanchar()) != EOF)
364 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
366 ch = (ch * 8) + (tmp - '0');
379 if (i < sizeof(scanBuf) - 1)
385 scanStrLine = lineNum;
397 while (((ch = scanchar()) != EOF) && (ch != '>'))
401 if ((ch = scanchar()) != EOF)
421 if (((tmp = scanchar()) != EOF) && (isdigit(tmp))
422 && (tmp != '8') && (tmp != '9'))
424 ch = (ch * 8) + (tmp - '0');
431 if ((!stop) && ((tmp = scanchar()) != EOF)
432 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
434 ch = (ch * 8) + (tmp - '0');
441 if ((!stop) && ((tmp = scanchar()) != EOF)
442 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
444 ch = (ch * 8) + (tmp - '0');
457 if (i < sizeof(scanBuf) - 1)
460 if ((ch == '>') && (i < 5))
463 scanStrLine = lineNum;
469 static struct _Keyword
476 "xkb_keymap", XKB_KEYMAP},
478 "xkb_keycodes", XKB_KEYCODES},
480 "xkb_types", XKB_TYPES},
482 "xkb_symbols", XKB_SYMBOLS},
484 "xkb_compat", XKB_COMPATMAP},
486 "xkb_compat_map", XKB_COMPATMAP},
488 "xkb_compatibility", XKB_COMPATMAP},
490 "xkb_compatibility_map", XKB_COMPATMAP},
492 "xkb_geometry", XKB_GEOMETRY},
494 "xkb_semantics", XKB_SEMANTICS},
496 "xkb_layout", XKB_LAYOUT},
500 "override", OVERRIDE},
506 "alternate", ALTERNATE},
514 "virtual_modifiers", VIRTUAL_MODS},
518 "interpret", INTERPRET},
520 "action", ACTION_TOK},
528 "modmap", MODIFIER_MAP},
530 "mod_map", MODIFIER_MAP},
532 "modifier_map", MODIFIER_MAP},
534 "indicator", INDICATOR},
556 "alphanumeric_keys", ALPHANUMERIC_KEYS},
558 "modifier_keys", MODIFIER_KEYS},
560 "keypad_keys", KEYPAD_KEYS},
562 "function_keys", FUNCTION_KEYS},
564 "alternate_group", ALTERNATE_GROUP}
566 static int numKeywords = sizeof(keywords) / sizeof(struct _Keyword);
569 yyGetIdent(int first)
576 while (((ch = scanchar()) != EOF) && (isalnum(ch) || (ch == '_')))
578 if (j < sizeof(scanBuf) - 1)
584 for (i = 0; (!found) && (i < numKeywords); i++)
586 if (uStrCaseCmp(scanBuf, keywords[i].keyword) == 0)
588 rtrn = keywords[i].token;
594 scanStrLine = lineNum;
598 if ((ch != EOF) && (!isspace(ch)))
609 const int nMaxBuffSize = 1024;
611 char buf[nMaxBuffSize];
616 while (((ch = scanchar()) != EOF)
617 && (isxdigit(ch) || ((nInBuf == 1) && (ch == 'x')))
618 && nInBuf < (nMaxBuffSize - 1))
622 if ((ch == '.') && (nInBuf < (nMaxBuffSize - 1)))
626 while (((ch = scanchar()) != EOF) && (isxdigit(ch))
627 && nInBuf < (nMaxBuffSize - 1))
632 buf[nInBuf++] = '\0';
633 if ((ch != EOF) && (!isspace(ch)))
639 if (sscanf(buf, "%g", &tmp) == 1)
641 scanInt = tmp * XkbGeomPtsPerMM;
645 else if (sscanf(buf, "%i", &scanInt) == 1)
647 fprintf(stderr, "Malformed number %s\n", buf);
665 { /* handle shell style '#' comments */
670 while ((ch != '\n') && (ch != EOF));
674 { /* handle C++ style double-/ comments */
675 int newch = scanchar();
682 while ((ch != '\n') && (ch != EOF));
685 else if (newch != EOF)
691 while ((ch != EOF) && (isspace(ch)));
725 rtrn = yyGetString();
727 rtrn = yyGetKeyName();
728 else if (isalpha(ch) || (ch == '_'))
729 rtrn = yyGetIdent(ch);
730 else if (isdigit(ch))
731 rtrn = yyGetNumber(ch);
739 "Unexpected character %c (%d) in input stream\n", ch, ch);
744 if (debugFlags & 0x2)
745 fprintf(stderr, "scan: %s\n", tokText(rtrn));