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 buf[BUFSIZE];
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)", scanStr);
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)", scanStr);
230 snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanStr);
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");
268 setScanState(char *file, int line)
271 strncpy(scanFile, file, 1024);
283 while (((ch = getc(yyin)) != EOF) && (ch != '"'))
287 if ((ch = getc(yyin)) != EOF)
307 if (((tmp = getc(yyin)) != EOF) && (isdigit(tmp))
308 && (tmp != '8') && (tmp != '9'))
310 ch = (ch * 8) + (tmp - '0');
319 if (((tmp = getc(yyin)) != EOF)
320 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
322 ch = (ch * 8) + (tmp - '0');
332 if (((tmp = getc(yyin)) != EOF)
333 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
335 ch = (ch * 8) + (tmp - '0');
348 if (nInBuf < BUFSIZE - 1)
353 buf[nInBuf++] = '\0';
356 scanStr = (char *) uStringDup(buf);
357 scanStrLine = lineNum;
369 while (((ch = getc(yyin)) != EOF) && (ch != '>'))
373 if ((ch = getc(yyin)) != EOF)
393 if (((tmp = getc(yyin)) != EOF) && (isdigit(tmp))
394 && (tmp != '8') && (tmp != '9'))
396 ch = (ch * 8) + (tmp - '0');
403 if ((!stop) && ((tmp = getc(yyin)) != EOF)
404 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
406 ch = (ch * 8) + (tmp - '0');
413 if ((!stop) && ((tmp = getc(yyin)) != EOF)
414 && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
416 ch = (ch * 8) + (tmp - '0');
429 if (nInBuf < BUFSIZE - 1)
432 if ((ch == '>') && (nInBuf < 5))
434 buf[nInBuf++] = '\0';
437 scanStr = (char *) uStringDup(buf);
438 scanStrLine = lineNum;
444 static struct _Keyword
451 "xkb_keymap", XKB_KEYMAP},
453 "xkb_keycodes", XKB_KEYCODES},
455 "xkb_types", XKB_TYPES},
457 "xkb_symbols", XKB_SYMBOLS},
459 "xkb_compat", XKB_COMPATMAP},
461 "xkb_compat_map", XKB_COMPATMAP},
463 "xkb_compatibility", XKB_COMPATMAP},
465 "xkb_compatibility_map", XKB_COMPATMAP},
467 "xkb_geometry", XKB_GEOMETRY},
469 "xkb_semantics", XKB_SEMANTICS},
471 "xkb_layout", XKB_LAYOUT},
475 "override", OVERRIDE},
481 "alternate", ALTERNATE},
489 "virtual_modifiers", VIRTUAL_MODS},
493 "interpret", INTERPRET},
495 "action", ACTION_TOK},
503 "modmap", MODIFIER_MAP},
505 "mod_map", MODIFIER_MAP},
507 "modifier_map", MODIFIER_MAP},
509 "indicator", INDICATOR},
531 "alphanumeric_keys", ALPHANUMERIC_KEYS},
533 "modifier_keys", MODIFIER_KEYS},
535 "keypad_keys", KEYPAD_KEYS},
537 "function_keys", FUNCTION_KEYS},
539 "alternate_group", ALTERNATE_GROUP}
541 static int numKeywords = sizeof(keywords) / sizeof(struct _Keyword);
544 yyGetIdent(int first)
551 while (((ch = getc(yyin)) != EOF) && (isalnum(ch) || (ch == '_')))
553 if (nInBuf < BUFSIZE - 1)
556 buf[nInBuf++] = '\0';
559 for (i = 0; (!found) && (i < numKeywords); i++)
561 if (uStrCaseCmp(buf, keywords[i].keyword) == 0)
563 rtrn = keywords[i].token;
571 scanStr = (char *) uStringDup(buf);
572 scanStrLine = lineNum;
576 if ((ch != EOF) && (!isspace(ch)))
591 while (((ch = getc(yyin)) != EOF)
592 && (isxdigit(ch) || ((nInBuf == 1) && (ch == 'x'))))
600 while (((ch = getc(yyin)) != EOF) && (isxdigit(ch)))
605 buf[nInBuf++] = '\0';
606 if ((ch != EOF) && (!isspace(ch)))
612 if (sscanf(buf, "%g", &tmp) == 1)
614 scanInt = tmp * XkbGeomPtsPerMM;
618 else if (sscanf(buf, "%i", &scanInt) == 1)
620 fprintf(stderr, "Malformed number %s\n", buf);
638 { /* handle shell style '#' comments */
643 while ((ch != '\n') && (ch != EOF));
647 { /* handle C++ style double-/ comments */
648 int newch = getc(yyin);
655 while ((ch != '\n') && (ch != EOF));
658 else if (newch != EOF)
664 while ((ch != EOF) && (isspace(ch)));
698 rtrn = yyGetString();
700 rtrn = yyGetKeyName();
701 else if (isalpha(ch) || (ch == '_'))
702 rtrn = yyGetIdent(ch);
703 else if (isdigit(ch))
704 rtrn = yyGetNumber(ch);
712 "Unexpected character %c (%d) in input stream\n", ch, ch);
717 if (debugFlags & 0x2)
718 fprintf(stderr, "scan: %s\n", tokText(rtrn));