xkbscan.c revision 34345a63
1f46a6179Smrg/************************************************************
2f46a6179Smrg Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3f46a6179Smrg
4f46a6179Smrg Permission to use, copy, modify, and distribute this
5f46a6179Smrg software and its documentation for any purpose and without
6f46a6179Smrg fee is hereby granted, provided that the above copyright
7f46a6179Smrg notice appear in all copies and that both that copyright
8f46a6179Smrg notice and this permission notice appear in supporting
9f46a6179Smrg documentation, and that the name of Silicon Graphics not be
10f46a6179Smrg used in advertising or publicity pertaining to distribution
11f46a6179Smrg of the software without specific prior written permission.
12f46a6179Smrg Silicon Graphics makes no representation about the suitability
13f46a6179Smrg of this software for any purpose. It is provided "as is"
14f46a6179Smrg without any express or implied warranty.
15f46a6179Smrg
16f46a6179Smrg SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17f46a6179Smrg SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18f46a6179Smrg AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19f46a6179Smrg GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20f46a6179Smrg DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21f46a6179Smrg DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22f46a6179Smrg OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
23f46a6179Smrg THE USE OR PERFORMANCE OF THIS SOFTWARE.
24f46a6179Smrg
25f46a6179Smrg ********************************************************/
26f46a6179Smrg
27f46a6179Smrg#include <stdio.h>
28f46a6179Smrg#include <ctype.h>
29f46a6179Smrg#include <X11/Xos.h>
30f46a6179Smrg#include <X11/Xlib.h>
31f46a6179Smrg#include <X11/XKBlib.h>
32f46a6179Smrg
33f46a6179Smrg#include "tokens.h"
34f46a6179Smrg#define	DEBUG_VAR	scanDebug
35f46a6179Smrg#include "utils.h"
36f46a6179Smrg#include "parseutils.h"
37f46a6179Smrg
3834345a63Smrgunsigned int scanDebug;
39f46a6179Smrg
4034345a63SmrgFILE *yyin = NULL;
41f46a6179Smrg
4234345a63Smrgstatic char scanFileBuf[1024] = {0};
4334345a63Smrgchar *scanFile = scanFileBuf;
4434345a63Smrgint lineNum = 0;
45f46a6179Smrg
4634345a63Smrgint scanInt;
4734345a63Smrg
4834345a63Smrgchar *scanStr = NULL;
4934345a63Smrgstatic int scanStrLine = 0;
50f46a6179Smrg
51f46a6179Smrg#define	BUFSIZE	512
5234345a63Smrgstatic int nInBuf = 0;
5334345a63Smrgstatic char buf[BUFSIZE];
54f46a6179Smrg
55f46a6179Smrg#ifdef DEBUG
56f46a6179Smrgstatic char *
57f46a6179SmrgtokText(int tok)
58f46a6179Smrg{
5934345a63Smrg    static char buf[32];
6034345a63Smrg
6134345a63Smrg    switch (tok)
6234345a63Smrg    {
6334345a63Smrg    case END_OF_FILE:
6434345a63Smrg        snprintf(buf, sizeof(buf), "END_OF_FILE");
6534345a63Smrg        break;
6634345a63Smrg    case ERROR_TOK:
6734345a63Smrg        snprintf(buf, sizeof(buf), "ERROR");
6834345a63Smrg        break;
6934345a63Smrg
7034345a63Smrg    case XKB_KEYMAP:
7134345a63Smrg        snprintf(buf, sizeof(buf), "XKB_KEYMAP");
7234345a63Smrg        break;
7334345a63Smrg    case XKB_KEYCODES:
7434345a63Smrg        snprintf(buf, sizeof(buf), "XKB_KEYCODES");
7534345a63Smrg        break;
7634345a63Smrg    case XKB_TYPES:
7734345a63Smrg        snprintf(buf, sizeof(buf), "XKB_TYPES");
7834345a63Smrg        break;
7934345a63Smrg    case XKB_SYMBOLS:
8034345a63Smrg        snprintf(buf, sizeof(buf), "XKB_SYMBOLS");
8134345a63Smrg        break;
8234345a63Smrg    case XKB_COMPATMAP:
8334345a63Smrg        snprintf(buf, sizeof(buf), "XKB_COMPATMAP");
8434345a63Smrg        break;
8534345a63Smrg    case XKB_GEOMETRY:
8634345a63Smrg        snprintf(buf, sizeof(buf), "XKB_GEOMETRY");
8734345a63Smrg        break;
8834345a63Smrg    case XKB_SEMANTICS:
8934345a63Smrg        snprintf(buf, sizeof(buf), "XKB_SEMANTICS");
9034345a63Smrg        break;
9134345a63Smrg    case XKB_LAYOUT:
9234345a63Smrg        snprintf(buf, sizeof(buf), "XKB_LAYOUT");
9334345a63Smrg        break;
9434345a63Smrg
9534345a63Smrg    case INCLUDE:
9634345a63Smrg        snprintf(buf, sizeof(buf), "INCLUDE");
9734345a63Smrg        break;
9834345a63Smrg    case OVERRIDE:
9934345a63Smrg        snprintf(buf, sizeof(buf), "OVERRIDE");
10034345a63Smrg        break;
10134345a63Smrg    case AUGMENT:
10234345a63Smrg        snprintf(buf, sizeof(buf), "AUGMENT");
10334345a63Smrg        break;
10434345a63Smrg    case REPLACE:
10534345a63Smrg        snprintf(buf, sizeof(buf), "REPLACE");
10634345a63Smrg        break;
10734345a63Smrg    case ALTERNATE:
10834345a63Smrg        snprintf(buf, sizeof(buf), "ALTERNATE");
10934345a63Smrg        break;
11034345a63Smrg
11134345a63Smrg    case VIRTUAL_MODS:
11234345a63Smrg        snprintf(buf, sizeof(buf), "VIRTUAL_MODS");
11334345a63Smrg        break;
11434345a63Smrg    case TYPE:
11534345a63Smrg        snprintf(buf, sizeof(buf), "TYPE");
11634345a63Smrg        break;
11734345a63Smrg    case INTERPRET:
11834345a63Smrg        snprintf(buf, sizeof(buf), "INTERPRET");
11934345a63Smrg        break;
12034345a63Smrg    case ACTION_TOK:
12134345a63Smrg        snprintf(buf, sizeof(buf), "ACTION");
12234345a63Smrg        break;
12334345a63Smrg    case KEY:
12434345a63Smrg        snprintf(buf, sizeof(buf), "KEY");
12534345a63Smrg        break;
12634345a63Smrg    case ALIAS:
12734345a63Smrg        snprintf(buf, sizeof(buf), "ALIAS");
12834345a63Smrg        break;
12934345a63Smrg    case GROUP:
13034345a63Smrg        snprintf(buf, sizeof(buf), "GROUP");
13134345a63Smrg        break;
13234345a63Smrg    case MODIFIER_MAP:
13334345a63Smrg        snprintf(buf, sizeof(buf), "MODIFIER_MAP");
13434345a63Smrg        break;
13534345a63Smrg    case INDICATOR:
13634345a63Smrg        snprintf(buf, sizeof(buf), "INDICATOR");
13734345a63Smrg        break;
13834345a63Smrg    case SHAPE:
13934345a63Smrg        snprintf(buf, sizeof(buf), "SHAPE");
14034345a63Smrg        break;
14134345a63Smrg    case KEYS:
14234345a63Smrg        snprintf(buf, sizeof(buf), "KEYS");
14334345a63Smrg        break;
14434345a63Smrg    case ROW:
14534345a63Smrg        snprintf(buf, sizeof(buf), "ROW");
14634345a63Smrg        break;
14734345a63Smrg    case SECTION:
14834345a63Smrg        snprintf(buf, sizeof(buf), "SECTION");
14934345a63Smrg        break;
15034345a63Smrg    case OVERLAY:
15134345a63Smrg        snprintf(buf, sizeof(buf), "OVERLAY");
15234345a63Smrg        break;
15334345a63Smrg    case TEXT:
15434345a63Smrg        snprintf(buf, sizeof(buf), "TEXT");
15534345a63Smrg        break;
15634345a63Smrg    case OUTLINE:
15734345a63Smrg        snprintf(buf, sizeof(buf), "OUTLINE");
15834345a63Smrg        break;
15934345a63Smrg    case SOLID:
16034345a63Smrg        snprintf(buf, sizeof(buf), "SOLID");
16134345a63Smrg        break;
16234345a63Smrg    case LOGO:
16334345a63Smrg        snprintf(buf, sizeof(buf), "LOGO");
16434345a63Smrg        break;
16534345a63Smrg    case VIRTUAL:
16634345a63Smrg        snprintf(buf, sizeof(buf), "VIRTUAL");
16734345a63Smrg        break;
16834345a63Smrg
16934345a63Smrg    case EQUALS:
17034345a63Smrg        snprintf(buf, sizeof(buf), "EQUALS");
17134345a63Smrg        break;
17234345a63Smrg    case PLUS:
17334345a63Smrg        snprintf(buf, sizeof(buf), "PLUS");
17434345a63Smrg        break;
17534345a63Smrg    case MINUS:
17634345a63Smrg        snprintf(buf, sizeof(buf), "MINUS");
17734345a63Smrg        break;
17834345a63Smrg    case DIVIDE:
17934345a63Smrg        snprintf(buf, sizeof(buf), "DIVIDE");
18034345a63Smrg        break;
18134345a63Smrg    case TIMES:
18234345a63Smrg        snprintf(buf, sizeof(buf), "TIMES");
18334345a63Smrg        break;
18434345a63Smrg    case OBRACE:
18534345a63Smrg        snprintf(buf, sizeof(buf), "OBRACE");
18634345a63Smrg        break;
18734345a63Smrg    case CBRACE:
18834345a63Smrg        snprintf(buf, sizeof(buf), "CBRACE");
18934345a63Smrg        break;
19034345a63Smrg    case OPAREN:
19134345a63Smrg        snprintf(buf, sizeof(buf), "OPAREN");
19234345a63Smrg        break;
19334345a63Smrg    case CPAREN:
19434345a63Smrg        snprintf(buf, sizeof(buf), "CPAREN");
19534345a63Smrg        break;
19634345a63Smrg    case OBRACKET:
19734345a63Smrg        snprintf(buf, sizeof(buf), "OBRACKET");
19834345a63Smrg        break;
19934345a63Smrg    case CBRACKET:
20034345a63Smrg        snprintf(buf, sizeof(buf), "CBRACKET");
20134345a63Smrg        break;
20234345a63Smrg    case DOT:
20334345a63Smrg        snprintf(buf, sizeof(buf), "DOT");
20434345a63Smrg        break;
20534345a63Smrg    case COMMA:
20634345a63Smrg        snprintf(buf, sizeof(buf), "COMMA");
20734345a63Smrg        break;
20834345a63Smrg    case SEMI:
20934345a63Smrg        snprintf(buf, sizeof(buf), "SEMI");
21034345a63Smrg        break;
21134345a63Smrg    case EXCLAM:
21234345a63Smrg        snprintf(buf, sizeof(buf), "EXCLAM");
21334345a63Smrg        break;
21434345a63Smrg    case INVERT:
21534345a63Smrg        snprintf(buf, sizeof(buf), "INVERT");
21634345a63Smrg        break;
21734345a63Smrg
21834345a63Smrg    case STRING:
21934345a63Smrg        snprintf(buf, sizeof(buf), "STRING (%s)", scanStr);
22034345a63Smrg        break;
22134345a63Smrg    case INTEGER:
22234345a63Smrg        snprintf(buf, sizeof(buf), "INTEGER (0x%x)", scanInt);
22334345a63Smrg        break;
22434345a63Smrg    case FLOAT:
22534345a63Smrg        snprintf(buf, sizeof(buf), "FLOAT (%d.%d)",
22634345a63Smrg                scanInt / XkbGeomPtsPerMM, scanInt % XkbGeomPtsPerMM);
22734345a63Smrg        break;
22834345a63Smrg    case IDENT:
22934345a63Smrg        snprintf(buf, sizeof(buf), "IDENT (%s)", scanStr);
23034345a63Smrg        break;
23134345a63Smrg    case KEYNAME:
23234345a63Smrg        snprintf(buf, sizeof(buf), "KEYNAME (%s)", scanStr);
23334345a63Smrg        break;
23434345a63Smrg
23534345a63Smrg    case PARTIAL:
23634345a63Smrg        snprintf(buf, sizeof(buf), "PARTIAL");
23734345a63Smrg        break;
23834345a63Smrg    case DEFAULT:
23934345a63Smrg        snprintf(buf, sizeof(buf), "DEFAULT");
24034345a63Smrg        break;
24134345a63Smrg    case HIDDEN:
24234345a63Smrg        snprintf(buf, sizeof(buf), "HIDDEN");
24334345a63Smrg        break;
24434345a63Smrg
24534345a63Smrg    case ALPHANUMERIC_KEYS:
24634345a63Smrg        snprintf(buf, sizeof(buf), "ALPHANUMERIC_KEYS");
24734345a63Smrg        break;
24834345a63Smrg    case MODIFIER_KEYS:
24934345a63Smrg        snprintf(buf, sizeof(buf), "MODIFIER_KEYS");
25034345a63Smrg        break;
25134345a63Smrg    case KEYPAD_KEYS:
25234345a63Smrg        snprintf(buf, sizeof(buf), "KEYPAD_KEYS");
25334345a63Smrg        break;
25434345a63Smrg    case FUNCTION_KEYS:
25534345a63Smrg        snprintf(buf, sizeof(buf), "FUNCTION_KEYS");
25634345a63Smrg        break;
25734345a63Smrg    case ALTERNATE_GROUP:
25834345a63Smrg        snprintf(buf, sizeof(buf), "ALTERNATE_GROUP");
25934345a63Smrg        break;
26034345a63Smrg
26134345a63Smrg    default:
26234345a63Smrg        snprintf(buf, sizeof(buf), "UNKNOWN");
26334345a63Smrg        break;
264f46a6179Smrg    }
265f46a6179Smrg    return buf;
266f46a6179Smrg}
267f46a6179Smrg#endif
268f46a6179Smrg
269f46a6179Smrgint
27034345a63SmrgsetScanState(char *file, int line)
271f46a6179Smrg{
27234345a63Smrg    if (file != NULL)
27334345a63Smrg        strncpy(scanFile, file, 1024);
27434345a63Smrg    if (line >= 0)
27534345a63Smrg        lineNum = line;
276f46a6179Smrg    return 1;
277f46a6179Smrg}
278f46a6179Smrg
279f46a6179Smrgstatic int
280f46a6179SmrgyyGetString(void)
281f46a6179Smrg{
28234345a63Smrg    int ch;
283f46a6179Smrg
284f46a6179Smrg    nInBuf = 0;
28534345a63Smrg    while (((ch = getc(yyin)) != EOF) && (ch != '"'))
28634345a63Smrg    {
28734345a63Smrg        if (ch == '\\')
28834345a63Smrg        {
28934345a63Smrg            if ((ch = getc(yyin)) != EOF)
29034345a63Smrg            {
29134345a63Smrg                if (ch == 'n')
29234345a63Smrg                    ch = '\n';
29334345a63Smrg                else if (ch == 't')
29434345a63Smrg                    ch = '\t';
29534345a63Smrg                else if (ch == 'v')
29634345a63Smrg                    ch = '\v';
29734345a63Smrg                else if (ch == 'b')
29834345a63Smrg                    ch = '\b';
29934345a63Smrg                else if (ch == 'r')
30034345a63Smrg                    ch = '\r';
30134345a63Smrg                else if (ch == 'f')
30234345a63Smrg                    ch = '\f';
30334345a63Smrg                else if (ch == 'e')
30434345a63Smrg                    ch = '\033';
30534345a63Smrg                else if (ch == '0')
30634345a63Smrg                {
30734345a63Smrg                    int tmp, stop;
30834345a63Smrg                    ch = stop = 0;
30934345a63Smrg                    if (((tmp = getc(yyin)) != EOF) && (isdigit(tmp))
31034345a63Smrg                        && (tmp != '8') && (tmp != '9'))
31134345a63Smrg                    {
31234345a63Smrg                        ch = (ch * 8) + (tmp - '0');
31334345a63Smrg                    }
31434345a63Smrg                    else
31534345a63Smrg                    {
31634345a63Smrg                        stop = 1;
31734345a63Smrg                        ungetc(tmp, yyin);
31834345a63Smrg                    }
31934345a63Smrg                    if (!stop)
32034345a63Smrg                    {
32134345a63Smrg                        if (((tmp = getc(yyin)) != EOF)
32234345a63Smrg                            && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
32334345a63Smrg                        {
32434345a63Smrg                            ch = (ch * 8) + (tmp - '0');
32534345a63Smrg                        }
32634345a63Smrg                        else
32734345a63Smrg                        {
32834345a63Smrg                            stop = 1;
32934345a63Smrg                            ungetc(tmp, yyin);
33034345a63Smrg                        }
33134345a63Smrg                    }
33234345a63Smrg                    if (!stop)
33334345a63Smrg                    {
33434345a63Smrg                        if (((tmp = getc(yyin)) != EOF)
33534345a63Smrg                            && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
33634345a63Smrg                        {
33734345a63Smrg                            ch = (ch * 8) + (tmp - '0');
33834345a63Smrg                        }
33934345a63Smrg                        else
34034345a63Smrg                        {
34134345a63Smrg                            stop = 1;
34234345a63Smrg                            ungetc(tmp, yyin);
34334345a63Smrg                        }
34434345a63Smrg                    }
34534345a63Smrg                }
34634345a63Smrg            }
34734345a63Smrg            else
34834345a63Smrg                return ERROR_TOK;
34934345a63Smrg        }
35034345a63Smrg        if (nInBuf < BUFSIZE - 1)
35134345a63Smrg            buf[nInBuf++] = ch;
352f46a6179Smrg    }
35334345a63Smrg    if (ch == '"')
35434345a63Smrg    {
35534345a63Smrg        buf[nInBuf++] = '\0';
35634345a63Smrg        if (scanStr)
35734345a63Smrg            uFree(scanStr);
35834345a63Smrg        scanStr = (char *) uStringDup(buf);
35934345a63Smrg        scanStrLine = lineNum;
36034345a63Smrg        return STRING;
361f46a6179Smrg    }
362f46a6179Smrg    return ERROR_TOK;
363f46a6179Smrg}
364f46a6179Smrg
365f46a6179Smrgstatic int
366f46a6179SmrgyyGetKeyName(void)
367f46a6179Smrg{
36834345a63Smrg    int ch;
369f46a6179Smrg
370f46a6179Smrg    nInBuf = 0;
37134345a63Smrg    while (((ch = getc(yyin)) != EOF) && (ch != '>'))
37234345a63Smrg    {
37334345a63Smrg        if (ch == '\\')
37434345a63Smrg        {
37534345a63Smrg            if ((ch = getc(yyin)) != EOF)
37634345a63Smrg            {
37734345a63Smrg                if (ch == 'n')
37834345a63Smrg                    ch = '\n';
37934345a63Smrg                else if (ch == 't')
38034345a63Smrg                    ch = '\t';
38134345a63Smrg                else if (ch == 'v')
38234345a63Smrg                    ch = '\v';
38334345a63Smrg                else if (ch == 'b')
38434345a63Smrg                    ch = '\b';
38534345a63Smrg                else if (ch == 'r')
38634345a63Smrg                    ch = '\r';
38734345a63Smrg                else if (ch == 'f')
38834345a63Smrg                    ch = '\f';
38934345a63Smrg                else if (ch == 'e')
39034345a63Smrg                    ch = '\033';
39134345a63Smrg                else if (ch == '0')
39234345a63Smrg                {
39334345a63Smrg                    int tmp, stop;
39434345a63Smrg                    ch = stop = 0;
39534345a63Smrg                    if (((tmp = getc(yyin)) != EOF) && (isdigit(tmp))
39634345a63Smrg                        && (tmp != '8') && (tmp != '9'))
39734345a63Smrg                    {
39834345a63Smrg                        ch = (ch * 8) + (tmp - '0');
39934345a63Smrg                    }
40034345a63Smrg                    else
40134345a63Smrg                    {
40234345a63Smrg                        stop = 1;
40334345a63Smrg                        ungetc(tmp, yyin);
40434345a63Smrg                    }
40534345a63Smrg                    if ((!stop) && ((tmp = getc(yyin)) != EOF)
40634345a63Smrg                        && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
40734345a63Smrg                    {
40834345a63Smrg                        ch = (ch * 8) + (tmp - '0');
40934345a63Smrg                    }
41034345a63Smrg                    else
41134345a63Smrg                    {
41234345a63Smrg                        stop = 1;
41334345a63Smrg                        ungetc(tmp, yyin);
41434345a63Smrg                    }
41534345a63Smrg                    if ((!stop) && ((tmp = getc(yyin)) != EOF)
41634345a63Smrg                        && (isdigit(tmp)) && (tmp != '8') && (tmp != '9'))
41734345a63Smrg                    {
41834345a63Smrg                        ch = (ch * 8) + (tmp - '0');
41934345a63Smrg                    }
42034345a63Smrg                    else
42134345a63Smrg                    {
42234345a63Smrg                        stop = 1;
42334345a63Smrg                        ungetc(tmp, yyin);
42434345a63Smrg                    }
42534345a63Smrg                }
42634345a63Smrg            }
42734345a63Smrg            else
42834345a63Smrg                return ERROR_TOK;
42934345a63Smrg        }
43034345a63Smrg
43134345a63Smrg        if (nInBuf < BUFSIZE - 1)
43234345a63Smrg            buf[nInBuf++] = ch;
433f46a6179Smrg    }
43434345a63Smrg    if ((ch == '>') && (nInBuf < 5))
43534345a63Smrg    {
43634345a63Smrg        buf[nInBuf++] = '\0';
43734345a63Smrg        if (scanStr)
43834345a63Smrg            uFree(scanStr);
43934345a63Smrg        scanStr = (char *) uStringDup(buf);
44034345a63Smrg        scanStrLine = lineNum;
44134345a63Smrg        return KEYNAME;
442f46a6179Smrg    }
443f46a6179Smrg    return ERROR_TOK;
444f46a6179Smrg}
445f46a6179Smrg
44634345a63Smrgstatic struct _Keyword
44734345a63Smrg{
44834345a63Smrg    const char *keyword;
44934345a63Smrg    int token;
45034345a63Smrg} keywords[] =
45134345a63Smrg{
45234345a63Smrg    {
45334345a63Smrg    "xkb_keymap", XKB_KEYMAP},
45434345a63Smrg    {
45534345a63Smrg    "xkb_keycodes", XKB_KEYCODES},
45634345a63Smrg    {
45734345a63Smrg    "xkb_types", XKB_TYPES},
45834345a63Smrg    {
45934345a63Smrg    "xkb_symbols", XKB_SYMBOLS},
46034345a63Smrg    {
46134345a63Smrg    "xkb_compat", XKB_COMPATMAP},
46234345a63Smrg    {
46334345a63Smrg    "xkb_compat_map", XKB_COMPATMAP},
46434345a63Smrg    {
46534345a63Smrg    "xkb_compatibility", XKB_COMPATMAP},
46634345a63Smrg    {
46734345a63Smrg    "xkb_compatibility_map", XKB_COMPATMAP},
46834345a63Smrg    {
46934345a63Smrg    "xkb_geometry", XKB_GEOMETRY},
47034345a63Smrg    {
47134345a63Smrg    "xkb_semantics", XKB_SEMANTICS},
47234345a63Smrg    {
47334345a63Smrg    "xkb_layout", XKB_LAYOUT},
47434345a63Smrg    {
47534345a63Smrg    "include", INCLUDE},
47634345a63Smrg    {
47734345a63Smrg    "override", OVERRIDE},
47834345a63Smrg    {
47934345a63Smrg    "augment", AUGMENT},
48034345a63Smrg    {
48134345a63Smrg    "replace", REPLACE},
48234345a63Smrg    {
48334345a63Smrg    "alternate", ALTERNATE},
48434345a63Smrg    {
48534345a63Smrg    "partial", PARTIAL},
48634345a63Smrg    {
48734345a63Smrg    "default", DEFAULT},
48834345a63Smrg    {
48934345a63Smrg    "hidden", HIDDEN},
49034345a63Smrg    {
49134345a63Smrg    "virtual_modifiers", VIRTUAL_MODS},
49234345a63Smrg    {
49334345a63Smrg    "type", TYPE},
49434345a63Smrg    {
49534345a63Smrg    "interpret", INTERPRET},
49634345a63Smrg    {
49734345a63Smrg    "action", ACTION_TOK},
49834345a63Smrg    {
49934345a63Smrg    "key", KEY},
50034345a63Smrg    {
50134345a63Smrg    "alias", ALIAS},
50234345a63Smrg    {
50334345a63Smrg    "group", GROUP},
50434345a63Smrg    {
50534345a63Smrg    "modmap", MODIFIER_MAP},
50634345a63Smrg    {
50734345a63Smrg    "mod_map", MODIFIER_MAP},
50834345a63Smrg    {
50934345a63Smrg    "modifier_map", MODIFIER_MAP},
51034345a63Smrg    {
51134345a63Smrg    "indicator", INDICATOR},
51234345a63Smrg    {
51334345a63Smrg    "shape", SHAPE},
51434345a63Smrg    {
51534345a63Smrg    "row", ROW},
51634345a63Smrg    {
51734345a63Smrg    "keys", KEYS},
51834345a63Smrg    {
51934345a63Smrg    "section", SECTION},
52034345a63Smrg    {
52134345a63Smrg    "overlay", OVERLAY},
52234345a63Smrg    {
52334345a63Smrg    "text", TEXT},
52434345a63Smrg    {
52534345a63Smrg    "outline", OUTLINE},
52634345a63Smrg    {
52734345a63Smrg    "solid", SOLID},
52834345a63Smrg    {
52934345a63Smrg    "logo", LOGO},
53034345a63Smrg    {
53134345a63Smrg    "virtual", VIRTUAL},
53234345a63Smrg    {
53334345a63Smrg    "alphanumeric_keys", ALPHANUMERIC_KEYS},
53434345a63Smrg    {
53534345a63Smrg    "modifier_keys", MODIFIER_KEYS},
53634345a63Smrg    {
53734345a63Smrg    "keypad_keys", KEYPAD_KEYS},
53834345a63Smrg    {
53934345a63Smrg    "function_keys", FUNCTION_KEYS},
54034345a63Smrg    {
54134345a63Smrg    "alternate_group", ALTERNATE_GROUP}
542f46a6179Smrg};
54334345a63Smrgstatic int numKeywords = sizeof(keywords) / sizeof(struct _Keyword);
544f46a6179Smrg
545f46a6179Smrgstatic int
546f46a6179SmrgyyGetIdent(int first)
547f46a6179Smrg{
54834345a63Smrg    int ch, i, found;
54934345a63Smrg    int rtrn = IDENT;
55034345a63Smrg
55134345a63Smrg    buf[0] = first;
55234345a63Smrg    nInBuf = 1;
55334345a63Smrg    while (((ch = getc(yyin)) != EOF) && (isalnum(ch) || (ch == '_')))
55434345a63Smrg    {
55534345a63Smrg        if (nInBuf < BUFSIZE - 1)
55634345a63Smrg            buf[nInBuf++] = ch;
557f46a6179Smrg    }
558f46a6179Smrg    buf[nInBuf++] = '\0';
55934345a63Smrg    found = 0;
56034345a63Smrg
56134345a63Smrg    for (i = 0; (!found) && (i < numKeywords); i++)
56234345a63Smrg    {
56334345a63Smrg        if (uStrCaseCmp(buf, keywords[i].keyword) == 0)
56434345a63Smrg        {
56534345a63Smrg            rtrn = keywords[i].token;
56634345a63Smrg            found = 1;
56734345a63Smrg        }
568f46a6179Smrg    }
56934345a63Smrg    if (!found)
57034345a63Smrg    {
57134345a63Smrg        if (scanStr)
57234345a63Smrg            uFree(scanStr);
57334345a63Smrg        scanStr = (char *) uStringDup(buf);
57434345a63Smrg        scanStrLine = lineNum;
57534345a63Smrg        rtrn = IDENT;
576f46a6179Smrg    }
577f46a6179Smrg
57834345a63Smrg    if ((ch != EOF) && (!isspace(ch)))
57934345a63Smrg        ungetc(ch, yyin);
58034345a63Smrg    else if (ch == '\n')
58134345a63Smrg        lineNum++;
582f46a6179Smrg
583f46a6179Smrg    return rtrn;
584f46a6179Smrg}
585f46a6179Smrg
586f46a6179Smrgstatic int
587f46a6179SmrgyyGetNumber(int ch)
588f46a6179Smrg{
58934345a63Smrg    int isFloat = 0;
59034345a63Smrg
59134345a63Smrg    buf[0] = ch;
59234345a63Smrg    nInBuf = 1;
59334345a63Smrg    while (((ch = getc(yyin)) != EOF)
59434345a63Smrg           && (isxdigit(ch) || ((nInBuf == 1) && (ch == 'x'))))
59534345a63Smrg    {
59634345a63Smrg        buf[nInBuf++] = ch;
597f46a6179Smrg    }
59834345a63Smrg    if (ch == '.')
59934345a63Smrg    {
60034345a63Smrg        isFloat = 1;
60134345a63Smrg        buf[nInBuf++] = ch;
60234345a63Smrg        while (((ch = getc(yyin)) != EOF) && (isxdigit(ch)))
60334345a63Smrg        {
60434345a63Smrg            buf[nInBuf++] = ch;
60534345a63Smrg        }
606f46a6179Smrg    }
60734345a63Smrg    buf[nInBuf++] = '\0';
60834345a63Smrg    if ((ch != EOF) && (!isspace(ch)))
60934345a63Smrg        ungetc(ch, yyin);
61034345a63Smrg
61134345a63Smrg    if (isFloat)
61234345a63Smrg    {
61334345a63Smrg        float tmp;
61434345a63Smrg        if (sscanf(buf, "%g", &tmp) == 1)
61534345a63Smrg        {
61634345a63Smrg            scanInt = tmp * XkbGeomPtsPerMM;
61734345a63Smrg            return FLOAT;
61834345a63Smrg        }
619f46a6179Smrg    }
62034345a63Smrg    else if (sscanf(buf, "%i", &scanInt) == 1)
62134345a63Smrg        return INTEGER;
62234345a63Smrg    fprintf(stderr, "Malformed number %s\n", buf);
623f46a6179Smrg    return ERROR_TOK;
624f46a6179Smrg}
625f46a6179Smrg
626f46a6179Smrgint
627f46a6179Smrgyylex(void)
628f46a6179Smrg{
62934345a63Smrg    int ch;
63034345a63Smrg    int rtrn;
63134345a63Smrg
63234345a63Smrg    do
63334345a63Smrg    {
63434345a63Smrg        ch = getc(yyin);
63534345a63Smrg        if (ch == '\n')
63634345a63Smrg        {
63734345a63Smrg            lineNum++;
63834345a63Smrg        }
63934345a63Smrg        else if (ch == '#')
64034345a63Smrg        {                       /* handle shell style '#' comments */
64134345a63Smrg            do
64234345a63Smrg            {
64334345a63Smrg                ch = getc(yyin);
64434345a63Smrg            }
64534345a63Smrg            while ((ch != '\n') && (ch != EOF));
64634345a63Smrg            lineNum++;
64734345a63Smrg        }
64834345a63Smrg        else if (ch == '/')
64934345a63Smrg        {                       /* handle C++ style double-/ comments */
65034345a63Smrg            int newch = getc(yyin);
65134345a63Smrg            if (newch == '/')
65234345a63Smrg            {
65334345a63Smrg                do
65434345a63Smrg                {
65534345a63Smrg                    ch = getc(yyin);
65634345a63Smrg                }
65734345a63Smrg                while ((ch != '\n') && (ch != EOF));
65834345a63Smrg                lineNum++;
65934345a63Smrg            }
66034345a63Smrg            else if (newch != EOF)
66134345a63Smrg            {
66234345a63Smrg                ungetc(newch, yyin);
66334345a63Smrg            }
66434345a63Smrg        }
66534345a63Smrg    }
66634345a63Smrg    while ((ch != EOF) && (isspace(ch)));
66734345a63Smrg    if (ch == '=')
66834345a63Smrg        rtrn = EQUALS;
66934345a63Smrg    else if (ch == '+')
67034345a63Smrg        rtrn = PLUS;
67134345a63Smrg    else if (ch == '-')
67234345a63Smrg        rtrn = MINUS;
67334345a63Smrg    else if (ch == '/')
67434345a63Smrg        rtrn = DIVIDE;
67534345a63Smrg    else if (ch == '*')
67634345a63Smrg        rtrn = TIMES;
67734345a63Smrg    else if (ch == '{')
67834345a63Smrg        rtrn = OBRACE;
67934345a63Smrg    else if (ch == '}')
68034345a63Smrg        rtrn = CBRACE;
68134345a63Smrg    else if (ch == '(')
68234345a63Smrg        rtrn = OPAREN;
68334345a63Smrg    else if (ch == ')')
68434345a63Smrg        rtrn = CPAREN;
68534345a63Smrg    else if (ch == '[')
68634345a63Smrg        rtrn = OBRACKET;
68734345a63Smrg    else if (ch == ']')
68834345a63Smrg        rtrn = CBRACKET;
68934345a63Smrg    else if (ch == '.')
69034345a63Smrg        rtrn = DOT;
69134345a63Smrg    else if (ch == ',')
69234345a63Smrg        rtrn = COMMA;
69334345a63Smrg    else if (ch == ';')
69434345a63Smrg        rtrn = SEMI;
69534345a63Smrg    else if (ch == '!')
69634345a63Smrg        rtrn = EXCLAM;
69734345a63Smrg    else if (ch == '~')
69834345a63Smrg        rtrn = INVERT;
69934345a63Smrg    else if (ch == '"')
70034345a63Smrg        rtrn = yyGetString();
70134345a63Smrg    else if (ch == '<')
70234345a63Smrg        rtrn = yyGetKeyName();
70334345a63Smrg    else if (isalpha(ch) || (ch == '_'))
70434345a63Smrg        rtrn = yyGetIdent(ch);
70534345a63Smrg    else if (isdigit(ch))
70634345a63Smrg        rtrn = yyGetNumber(ch);
70734345a63Smrg    else if (ch == EOF)
70834345a63Smrg        rtrn = END_OF_FILE;
70934345a63Smrg    else
71034345a63Smrg    {
711f46a6179Smrg#ifdef DEBUG
71234345a63Smrg        if (debugFlags)
71334345a63Smrg            fprintf(stderr,
71434345a63Smrg                    "Unexpected character %c (%d) in input stream\n", ch, ch);
715f46a6179Smrg#endif
71634345a63Smrg        rtrn = ERROR_TOK;
717f46a6179Smrg    }
718f46a6179Smrg#ifdef DEBUG
71934345a63Smrg    if (debugFlags & 0x2)
72034345a63Smrg        fprintf(stderr, "scan: %s\n", tokText(rtrn));
721f46a6179Smrg#endif
722f46a6179Smrg    return rtrn;
723f46a6179Smrg}
724