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 ********************************************************/
32 #define DEBUG_VAR scanDebug
34 #include "parseutils.h"
36 unsigned int scanDebug;
40 static char scanFileBuf[1024] = {0};
41 char *scanFile = scanFileBuf;
47 static int scanStrLine = 0;
50 static int nInBuf = 0;
51 static char readBuf[BUFSIZE];
52 static int readBufPos = 0;
53 static int readBufLen = 0;
56 extern int debugFlags;
66 snprintf(buf, sizeof(buf), "END_OF_FILE");
69 snprintf(buf, sizeof(buf), "ERROR");
73 snprintf(buf, sizeof(buf), "XKB_KEYMAP");
76 snprintf(buf, sizeof(buf), "XKB_KEYCODES");
79 snprintf(buf, sizeof(buf), "XKB_TYPES");
82 snprintf(buf, sizeof(buf), "XKB_SYMBOLS");
85 snprintf(buf, sizeof(buf), "XKB_COMPATMAP");
88 snprintf(buf, sizeof(buf), "XKB_GEOMETRY");
91 snprintf(buf, sizeof(buf), "XKB_SEMANTICS");
94 snprintf(buf, sizeof(buf), "XKB_LAYOUT");
98 snprintf(buf, sizeof(buf), "INCLUDE");
101 snprintf(buf, sizeof(buf), "OVERRIDE");
104 snprintf(buf, sizeof(buf), "AUGMENT");
107 snprintf(buf, sizeof(buf), "REPLACE");
110 snprintf(buf, sizeof(buf), "ALTERNATE");
114 snprintf(buf, sizeof(buf), "VIRTUAL_MODS");
117 snprintf(buf, sizeof(buf), "TYPE");
120 snprintf(buf, sizeof(buf), "INTERPRET");
123 snprintf(buf, sizeof(buf), "ACTION");
126 snprintf(buf, sizeof(buf), "KEY");
129 snprintf(buf, sizeof(buf), "ALIAS");
132 snprintf(buf, sizeof(buf), "GROUP");
135 snprintf(buf, sizeof(buf), "MODIFIER_MAP");
138 snprintf(buf, sizeof(buf), "INDICATOR");
141 snprintf(buf, sizeof(buf), "SHAPE");
144 snprintf(buf, sizeof(buf), "KEYS");
147 snprintf(buf, sizeof(buf), "ROW");
150 snprintf(buf, sizeof(buf), "SECTION");
153 snprintf(buf, sizeof(buf), "OVERLAY");
156 snprintf(buf, sizeof(buf), "TEXT");
159 snprintf(buf, sizeof(buf), "OUTLINE");
162 snprintf(buf, sizeof(buf), "SOLID");
165 snprintf(buf, sizeof(buf), "LOGO");
168 snprintf(buf, sizeof(buf), "VIRTUAL");
172 snprintf(buf, sizeof(buf), "EQUALS");
175 snprintf(buf, sizeof(buf), "PLUS");
178 snprintf(buf, sizeof(buf), "MINUS");
181 snprintf(buf, sizeof(buf), "DIVIDE");
184 snprintf(buf, sizeof(buf), "TIMES");
187 snprintf(buf, sizeof(buf), "OBRACE");
190 snprintf(buf, sizeof(buf), "CBRACE");
193 snprintf(buf, sizeof(buf), "OPAREN");
196 snprintf(buf, sizeof(buf), "CPAREN");
199 snprintf(buf, sizeof(buf), "OBRACKET");
202 snprintf(buf, sizeof(buf), "CBRACKET");
205 snprintf(buf, sizeof(buf), "DOT");
208 snprintf(buf, sizeof(buf), "COMMA");
211 snprintf(buf, sizeof(buf), "SEMI");
214 snprintf(buf, sizeof(buf), "EXCLAM");
217 snprintf(buf, sizeof(buf), "INVERT");
221 snprintf(buf, sizeof(buf), "STRING (%s)", scanStr);
224 snprintf(buf, sizeof(buf), "INTEGER (0x%x)", scanInt);
227 snprintf(buf, sizeof(buf), "FLOAT (%d.%d)",
228 scanInt / XkbGeomPtsPerMM, scanInt % XkbGeomPtsPerMM);
231 snprintf(buf, sizeof(buf), "IDENT (%s)", scanStr);
234 snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanStr);
238 snprintf(buf, sizeof(buf), "PARTIAL");
241 snprintf(buf, sizeof(buf), "DEFAULT");
244 snprintf(buf, sizeof(buf), "HIDDEN");
247 case ALPHANUMERIC_KEYS:
248 snprintf(buf, sizeof(buf), "ALPHANUMERIC_KEYS");
251 snprintf(buf, sizeof(buf), "MODIFIER_KEYS");
254 snprintf(buf, sizeof(buf), "KEYPAD_KEYS");
257 snprintf(buf, sizeof(buf), "FUNCTION_KEYS");
259 case ALTERNATE_GROUP:
260 snprintf(buf, sizeof(buf), "ALTERNATE_GROUP");
264 snprintf(buf, sizeof(buf), "UNKNOWN");
274 if (readBufPos >= readBufLen) {
275 readBufLen = fread(readBuf, 1, BUFSIZE, yyin);
280 readBuf[readBufLen] = EOF;
283 return readBuf[readBufPos++];
289 if (readBuf[--readBufPos] != c) {
290 fprintf(stderr, "UNGETCHAR FAILED! Put back %c, was expecting %c at "
291 "position %d, buf is '%s'\n", c, readBuf[readBufPos],
292 readBufPos, readBuf);
298 setScanState(char *file, int line)
301 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(buf) - 1)
387 scanStr = strdup(buf);
388 scanStrLine = lineNum;
401 while (((ch = scanchar()) != EOF) && (ch != '>'))
405 if ((ch = scanchar()) != EOF)
425 if (((tmp = scanchar()) != EOF) && (isdigit(tmp))
426 && (tmp != '8') && (tmp != '9'))
428 ch = (ch * 8) + (tmp - '0');
435 if ((!stop) && ((tmp = scanchar()) != EOF)
436 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
438 ch = (ch * 8) + (tmp - '0');
445 if ((!stop) && ((tmp = scanchar()) != EOF)
446 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
448 ch = (ch * 8) + (tmp - '0');
461 if (i < sizeof(buf) - 1)
464 if ((ch == '>') && (i < 5))
469 scanStr = strdup(buf);
470 scanStrLine = lineNum;
476 static struct _Keyword
483 "xkb_keymap", XKB_KEYMAP},
485 "xkb_keycodes", XKB_KEYCODES},
487 "xkb_types", XKB_TYPES},
489 "xkb_symbols", XKB_SYMBOLS},
491 "xkb_compat", XKB_COMPATMAP},
493 "xkb_compat_map", XKB_COMPATMAP},
495 "xkb_compatibility", XKB_COMPATMAP},
497 "xkb_compatibility_map", XKB_COMPATMAP},
499 "xkb_geometry", XKB_GEOMETRY},
501 "xkb_semantics", XKB_SEMANTICS},
503 "xkb_layout", XKB_LAYOUT},
507 "override", OVERRIDE},
513 "alternate", ALTERNATE},
521 "virtual_modifiers", VIRTUAL_MODS},
525 "interpret", INTERPRET},
527 "action", ACTION_TOK},
535 "modmap", MODIFIER_MAP},
537 "mod_map", MODIFIER_MAP},
539 "modifier_map", MODIFIER_MAP},
541 "indicator", INDICATOR},
563 "alphanumeric_keys", ALPHANUMERIC_KEYS},
565 "modifier_keys", MODIFIER_KEYS},
567 "keypad_keys", KEYPAD_KEYS},
569 "function_keys", FUNCTION_KEYS},
571 "alternate_group", ALTERNATE_GROUP}
573 static int numKeywords = sizeof(keywords) / sizeof(struct _Keyword);
576 yyGetIdent(int first)
584 while (((ch = scanchar()) != EOF) && (isalnum(ch) || (ch == '_')))
586 if (j < sizeof(buf) - 1)
592 for (i = 0; (!found) && (i < numKeywords); i++)
594 if (uStrCaseCmp(buf, keywords[i].keyword) == 0)
596 rtrn = keywords[i].token;
604 scanStr = strdup(buf);
605 scanStrLine = lineNum;
609 if ((ch != EOF) && (!isspace(ch)))
625 while (((ch = scanchar()) != EOF)
626 && (isxdigit(ch) || ((nInBuf == 1) && (ch == 'x'))))
634 while (((ch = scanchar()) != EOF) && (isxdigit(ch)))
639 buf[nInBuf++] = '\0';
640 if ((ch != EOF) && (!isspace(ch)))
646 if (sscanf(buf, "%g", &tmp) == 1)
648 scanInt = tmp * XkbGeomPtsPerMM;
652 else if (sscanf(buf, "%i", &scanInt) == 1)
654 fprintf(stderr, "Malformed number %s\n", buf);
672 { /* handle shell style '#' comments */
677 while ((ch != '\n') && (ch != EOF));
681 { /* handle C++ style double-/ comments */
682 int newch = scanchar();
689 while ((ch != '\n') && (ch != EOF));
692 else if (newch != EOF)
698 while ((ch != EOF) && (isspace(ch)));
732 rtrn = yyGetString();
734 rtrn = yyGetKeyName();
735 else if (isalpha(ch) || (ch == '_'))
736 rtrn = yyGetIdent(ch);
737 else if (isdigit(ch))
738 rtrn = yyGetNumber(ch);
746 "Unexpected character %c (%d) in input stream\n", ch, ch);
751 if (debugFlags & 0x2)
752 fprintf(stderr, "scan: %s\n", tokText(rtrn));