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 ********************************************************/
33 #include "parseutils.h"
37 static char scanFileBuf[1024] = {0};
38 char *scanFile = scanFileBuf;
44 static int scanStrLine = 0;
47 static char readBuf[BUFSIZE];
48 static int readBufPos = 0;
49 static int readBufLen = 0;
52 extern int debugFlags;
62 snprintf(buf, sizeof(buf), "END_OF_FILE");
65 snprintf(buf, sizeof(buf), "ERROR");
69 snprintf(buf, sizeof(buf), "XKB_KEYMAP");
72 snprintf(buf, sizeof(buf), "XKB_KEYCODES");
75 snprintf(buf, sizeof(buf), "XKB_TYPES");
78 snprintf(buf, sizeof(buf), "XKB_SYMBOLS");
81 snprintf(buf, sizeof(buf), "XKB_COMPATMAP");
84 snprintf(buf, sizeof(buf), "XKB_GEOMETRY");
87 snprintf(buf, sizeof(buf), "XKB_SEMANTICS");
90 snprintf(buf, sizeof(buf), "XKB_LAYOUT");
94 snprintf(buf, sizeof(buf), "INCLUDE");
97 snprintf(buf, sizeof(buf), "OVERRIDE");
100 snprintf(buf, sizeof(buf), "AUGMENT");
103 snprintf(buf, sizeof(buf), "REPLACE");
106 snprintf(buf, sizeof(buf), "ALTERNATE");
110 snprintf(buf, sizeof(buf), "VIRTUAL_MODS");
113 snprintf(buf, sizeof(buf), "TYPE");
116 snprintf(buf, sizeof(buf), "INTERPRET");
119 snprintf(buf, sizeof(buf), "ACTION");
122 snprintf(buf, sizeof(buf), "KEY");
125 snprintf(buf, sizeof(buf), "ALIAS");
128 snprintf(buf, sizeof(buf), "GROUP");
131 snprintf(buf, sizeof(buf), "MODIFIER_MAP");
134 snprintf(buf, sizeof(buf), "INDICATOR");
137 snprintf(buf, sizeof(buf), "SHAPE");
140 snprintf(buf, sizeof(buf), "KEYS");
143 snprintf(buf, sizeof(buf), "ROW");
146 snprintf(buf, sizeof(buf), "SECTION");
149 snprintf(buf, sizeof(buf), "OVERLAY");
152 snprintf(buf, sizeof(buf), "TEXT");
155 snprintf(buf, sizeof(buf), "OUTLINE");
158 snprintf(buf, sizeof(buf), "SOLID");
161 snprintf(buf, sizeof(buf), "LOGO");
164 snprintf(buf, sizeof(buf), "VIRTUAL");
168 snprintf(buf, sizeof(buf), "EQUALS");
171 snprintf(buf, sizeof(buf), "PLUS");
174 snprintf(buf, sizeof(buf), "MINUS");
177 snprintf(buf, sizeof(buf), "DIVIDE");
180 snprintf(buf, sizeof(buf), "TIMES");
183 snprintf(buf, sizeof(buf), "OBRACE");
186 snprintf(buf, sizeof(buf), "CBRACE");
189 snprintf(buf, sizeof(buf), "OPAREN");
192 snprintf(buf, sizeof(buf), "CPAREN");
195 snprintf(buf, sizeof(buf), "OBRACKET");
198 snprintf(buf, sizeof(buf), "CBRACKET");
201 snprintf(buf, sizeof(buf), "DOT");
204 snprintf(buf, sizeof(buf), "COMMA");
207 snprintf(buf, sizeof(buf), "SEMI");
210 snprintf(buf, sizeof(buf), "EXCLAM");
213 snprintf(buf, sizeof(buf), "INVERT");
217 snprintf(buf, sizeof(buf), "STRING (%s)", scanBuf);
220 snprintf(buf, sizeof(buf), "INTEGER (0x%x)", scanInt);
223 snprintf(buf, sizeof(buf), "FLOAT (%d.%d)",
224 scanInt / XkbGeomPtsPerMM, scanInt % XkbGeomPtsPerMM);
227 snprintf(buf, sizeof(buf), "IDENT (%s)", scanBuf);
230 snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanBuf);
234 snprintf(buf, sizeof(buf), "PARTIAL");
237 snprintf(buf, sizeof(buf), "DEFAULT");
240 snprintf(buf, sizeof(buf), "HIDDEN");
243 case ALPHANUMERIC_KEYS:
244 snprintf(buf, sizeof(buf), "ALPHANUMERIC_KEYS");
247 snprintf(buf, sizeof(buf), "MODIFIER_KEYS");
250 snprintf(buf, sizeof(buf), "KEYPAD_KEYS");
253 snprintf(buf, sizeof(buf), "FUNCTION_KEYS");
255 case ALTERNATE_GROUP:
256 snprintf(buf, sizeof(buf), "ALTERNATE_GROUP");
260 snprintf(buf, sizeof(buf), "UNKNOWN");
270 if (readBufPos >= readBufLen) {
271 readBufLen = fread(readBuf, 1, BUFSIZE, yyin);
276 readBuf[readBufLen] = EOF;
279 return readBuf[readBufPos++];
285 if (readBuf[--readBufPos] != c) {
286 fprintf(stderr, "UNGETCHAR FAILED! Put back %c, was expecting %c at "
287 "position %d, buf is '%s'\n", c, readBuf[readBufPos],
288 readBufPos, readBuf);
294 setScanState(char *file, int line)
297 strncpy(scanFile, file, 1024);
309 while (((ch = scanchar()) != EOF) && (ch != '"'))
313 if ((ch = scanchar()) != EOF)
333 if (((tmp = scanchar()) != EOF) && (isdigit(tmp))
334 && (tmp != '8') && (tmp != '9'))
336 ch = (ch * 8) + (tmp - '0');
345 if (((tmp = scanchar()) != EOF)
346 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
348 ch = (ch * 8) + (tmp - '0');
358 if (((tmp = scanchar()) != EOF)
359 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
361 ch = (ch * 8) + (tmp - '0');
374 if (i < sizeof(scanBuf) - 1)
380 scanStrLine = lineNum;
392 while (((ch = scanchar()) != EOF) && (ch != '>'))
396 if ((ch = scanchar()) != EOF)
416 if (((tmp = scanchar()) != EOF) && (isdigit(tmp))
417 && (tmp != '8') && (tmp != '9'))
419 ch = (ch * 8) + (tmp - '0');
426 if ((!stop) && ((tmp = scanchar()) != EOF)
427 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
429 ch = (ch * 8) + (tmp - '0');
436 if ((!stop) && ((tmp = scanchar()) != EOF)
437 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
439 ch = (ch * 8) + (tmp - '0');
452 if (i < sizeof(scanBuf) - 1)
455 if ((ch == '>') && (i < 5))
458 scanStrLine = lineNum;
464 static struct _Keyword
471 "xkb_keymap", XKB_KEYMAP},
473 "xkb_keycodes", XKB_KEYCODES},
475 "xkb_types", XKB_TYPES},
477 "xkb_symbols", XKB_SYMBOLS},
479 "xkb_compat", XKB_COMPATMAP},
481 "xkb_compat_map", XKB_COMPATMAP},
483 "xkb_compatibility", XKB_COMPATMAP},
485 "xkb_compatibility_map", XKB_COMPATMAP},
487 "xkb_geometry", XKB_GEOMETRY},
489 "xkb_semantics", XKB_SEMANTICS},
491 "xkb_layout", XKB_LAYOUT},
495 "override", OVERRIDE},
501 "alternate", ALTERNATE},
509 "virtual_modifiers", VIRTUAL_MODS},
513 "interpret", INTERPRET},
515 "action", ACTION_TOK},
523 "modmap", MODIFIER_MAP},
525 "mod_map", MODIFIER_MAP},
527 "modifier_map", MODIFIER_MAP},
529 "indicator", INDICATOR},
551 "alphanumeric_keys", ALPHANUMERIC_KEYS},
553 "modifier_keys", MODIFIER_KEYS},
555 "keypad_keys", KEYPAD_KEYS},
557 "function_keys", FUNCTION_KEYS},
559 "alternate_group", ALTERNATE_GROUP}
561 static int numKeywords = sizeof(keywords) / sizeof(struct _Keyword);
564 yyGetIdent(int first)
571 while (((ch = scanchar()) != EOF) && (isalnum(ch) || (ch == '_')))
573 if (j < sizeof(scanBuf) - 1)
579 for (i = 0; (!found) && (i < numKeywords); i++)
581 if (uStrCaseCmp(scanBuf, keywords[i].keyword) == 0)
583 rtrn = keywords[i].token;
589 scanStrLine = lineNum;
593 if ((ch != EOF) && (!isspace(ch)))
610 while (((ch = scanchar()) != EOF)
611 && (isxdigit(ch) || ((nInBuf == 1) && (ch == 'x'))))
619 while (((ch = scanchar()) != EOF) && (isxdigit(ch)))
624 buf[nInBuf++] = '\0';
625 if ((ch != EOF) && (!isspace(ch)))
631 if (sscanf(buf, "%g", &tmp) == 1)
633 scanInt = tmp * XkbGeomPtsPerMM;
637 else if (sscanf(buf, "%i", &scanInt) == 1)
639 fprintf(stderr, "Malformed number %s\n", buf);
657 { /* handle shell style '#' comments */
662 while ((ch != '\n') && (ch != EOF));
666 { /* handle C++ style double-/ comments */
667 int newch = scanchar();
674 while ((ch != '\n') && (ch != EOF));
677 else if (newch != EOF)
683 while ((ch != EOF) && (isspace(ch)));
717 rtrn = yyGetString();
719 rtrn = yyGetKeyName();
720 else if (isalpha(ch) || (ch == '_'))
721 rtrn = yyGetIdent(ch);
722 else if (isdigit(ch))
723 rtrn = yyGetNumber(ch);
731 "Unexpected character %c (%d) in input stream\n", ch, ch);
736 if (debugFlags & 0x2)
737 fprintf(stderr, "scan: %s\n", tokText(rtrn));