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 ********************************************************/
27 #define DEBUG_VAR parseDebug
28 #include "parseutils.h"
30 #include <X11/keysym.h>
31 #include <X11/extensions/XKBgeom.h>
32 #include <X11/Xalloca.h>
39 AppendStmt(ParseCommon * to, ParseCommon * append)
41 ParseCommon *start = to;
45 while ((to != NULL) && (to->next != NULL))
58 ExprCreate(unsigned op, unsigned type)
61 expr = uTypedAlloc(ExprDef);
64 expr->common.stmtType = StmtExpr;
65 expr->common.next = NULL;
71 FATAL("Couldn't allocate expression in parser\n");
78 ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
81 expr = uTypedAlloc(ExprDef);
84 expr->common.stmtType = StmtExpr;
85 expr->common.next = NULL;
88 expr->value.child = child;
92 FATAL("Couldn't allocate expression in parser\n");
99 ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right)
102 expr = uTypedAlloc(ExprDef);
105 expr->common.stmtType = StmtExpr;
106 expr->common.next = NULL;
108 if ((op == OpAssign) || (left->type == TypeUnknown))
109 expr->type = right->type;
110 else if ((left->type == right->type) || (right->type == TypeUnknown))
111 expr->type = left->type;
113 expr->type = TypeUnknown;
114 expr->value.binary.left = left;
115 expr->value.binary.right = right;
119 FATAL("Couldn't allocate expression in parser\n");
126 KeycodeCreate(char *name, ExprDef * value)
130 def = uTypedAlloc(KeycodeDef);
133 def->common.stmtType = StmtKeycodeDef;
134 def->common.next = NULL;
135 strncpy(def->name, name, XkbKeyNameLength);
136 def->name[XkbKeyNameLength] = '\0';
141 FATAL("Couldn't allocate key name definition in parser\n");
148 KeyAliasCreate(char *alias, char *real)
152 def = uTypedAlloc(KeyAliasDef);
155 def->common.stmtType = StmtKeyAliasDef;
156 def->common.next = NULL;
157 strncpy(def->alias, alias, XkbKeyNameLength);
158 def->alias[XkbKeyNameLength] = '\0';
159 strncpy(def->real, real, XkbKeyNameLength);
160 def->real[XkbKeyNameLength] = '\0';
164 FATAL("Couldn't allocate key alias definition in parser\n");
171 VModCreate(Atom name, ExprDef * value)
174 def = uTypedAlloc(VModDef);
177 def->common.stmtType = StmtVModDef;
178 def->common.next = NULL;
184 FATAL("Couldn't allocate variable definition in parser\n");
191 VarCreate(ExprDef * name, ExprDef * value)
194 def = uTypedAlloc(VarDef);
197 def->common.stmtType = StmtVarDef;
198 def->common.next = NULL;
204 FATAL("Couldn't allocate variable definition in parser\n");
211 BoolVarCreate(Atom nameToken, unsigned set)
213 ExprDef *name, *value;
215 name = ExprCreate(ExprIdent, TypeUnknown);
216 name->value.str = nameToken;
217 value = ExprCreate(ExprValue, TypeBoolean);
218 value->value.uval = set;
219 return VarCreate(name, value);
223 InterpCreate(KeySym sym, ExprDef * match)
227 def = uTypedAlloc(InterpDef);
230 def->common.stmtType = StmtInterpDef;
231 def->common.next = NULL;
237 FATAL("Couldn't allocate interp definition in parser\n");
244 KeyTypeCreate(Atom name, VarDef * body)
248 def = uTypedAlloc(KeyTypeDef);
251 def->common.stmtType = StmtKeyTypeDef;
252 def->common.next = NULL;
253 def->merge = MergeDefault;
259 FATAL("Couldn't allocate key type definition in parser\n");
266 SymbolsCreate(char *keyName, ExprDef * symbols)
270 def = uTypedAlloc(SymbolsDef);
273 def->common.stmtType = StmtSymbolsDef;
274 def->common.next = NULL;
275 def->merge = MergeDefault;
276 bzero(def->keyName, 5);
277 strncpy(def->keyName, keyName, 4);
278 def->symbols = symbols;
282 FATAL("Couldn't allocate symbols definition in parser\n");
289 GroupCompatCreate(int group, ExprDef * val)
293 def = uTypedAlloc(GroupCompatDef);
296 def->common.stmtType = StmtGroupCompatDef;
297 def->common.next = NULL;
298 def->merge = MergeDefault;
304 FATAL("Couldn't allocate group compat definition in parser\n");
311 ModMapCreate(Atom modifier, ExprDef * keys)
315 def = uTypedAlloc(ModMapDef);
318 def->common.stmtType = StmtModMapDef;
319 def->common.next = NULL;
320 def->merge = MergeDefault;
321 def->modifier = modifier;
326 FATAL("Couldn't allocate mod mask definition in parser\n");
333 IndicatorMapCreate(Atom name, VarDef * body)
335 IndicatorMapDef *def;
337 def = uTypedAlloc(IndicatorMapDef);
340 def->common.stmtType = StmtIndicatorMapDef;
341 def->common.next = NULL;
342 def->merge = MergeDefault;
348 FATAL("Couldn't allocate indicator map definition in parser\n");
355 IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
357 IndicatorNameDef *def;
359 def = uTypedAlloc(IndicatorNameDef);
362 def->common.stmtType = StmtIndicatorNameDef;
363 def->common.next = NULL;
364 def->merge = MergeDefault;
367 def->virtual = virtual;
371 FATAL("Couldn't allocate indicator index definition in parser\n");
378 ActionCreate(Atom name, ExprDef * args)
382 act = uTypedAlloc(ExprDef);
385 act->common.stmtType = StmtExpr;
386 act->common.next = NULL;
387 act->op = ExprActionDecl;
388 act->value.action.name = name;
389 act->value.action.args = args;
392 FATAL("Couldn't allocate ActionDef in parser\n");
397 CreateKeysymList(char *sym)
401 def = ExprCreate(ExprKeysymList, TypeSymbols);
404 def->value.list.nSyms = 1;
405 def->value.list.szSyms = 4;
406 def->value.list.syms = uTypedCalloc(4, char *);
407 if (def->value.list.syms != NULL)
409 def->value.list.syms[0] = sym;
413 FATAL("Couldn't allocate expression for keysym list in parser\n");
418 ShapeDeclCreate(Atom name, OutlineDef * outlines)
423 shape = uTypedAlloc(ShapeDef);
426 bzero(shape, sizeof(ShapeDef));
427 shape->common.stmtType = StmtShapeDef;
428 shape->common.next = NULL;
429 shape->merge = MergeDefault;
431 shape->nOutlines = 0;
432 shape->outlines = outlines;
433 for (ol = outlines; ol != NULL; ol = (OutlineDef *) ol->common.next)
443 OutlineCreate(Atom field, ExprDef * points)
448 outline = uTypedAlloc(OutlineDef);
451 bzero(outline, sizeof(OutlineDef));
452 outline->common.stmtType = StmtOutlineDef;
453 outline->common.next = NULL;
454 outline->field = field;
455 outline->nPoints = 0;
456 if (points->op == ExprCoord)
458 for (pt = points; pt != NULL; pt = (ExprDef *) pt->common.next)
463 outline->points = points;
469 KeyDeclCreate(char *name, ExprDef * expr)
473 key = uTypedAlloc(KeyDef);
476 bzero(key, sizeof(KeyDef));
477 key->common.stmtType = StmtKeyDef;
478 key->common.next = NULL;
488 KeyDeclMerge(KeyDef * into, KeyDef * from)
491 (ExprDef *) AppendStmt(&into->expr->common, &from->expr->common);
498 RowDeclCreate(KeyDef * keys)
503 row = uTypedAlloc(RowDef);
506 bzero(row, sizeof(RowDef));
507 row->common.stmtType = StmtRowDef;
508 row->common.next = NULL;
511 for (key = keys; key != NULL; key = (KeyDef *) key->common.next)
513 if (key->common.stmtType == StmtKeyDef)
521 SectionDeclCreate(Atom name, RowDef * rows)
526 section = uTypedAlloc(SectionDef);
529 bzero(section, sizeof(SectionDef));
530 section->common.stmtType = StmtSectionDef;
531 section->common.next = NULL;
532 section->name = name;
534 section->rows = rows;
535 for (row = rows; row != NULL; row = (RowDef *) row->common.next)
537 if (row->common.stmtType == StmtRowDef)
545 OverlayKeyCreate(char *under, char *over)
549 key = uTypedAlloc(OverlayKeyDef);
552 bzero(key, sizeof(OverlayKeyDef));
553 key->common.stmtType = StmtOverlayKeyDef;
554 strncpy(key->over, over, XkbKeyNameLength);
555 strncpy(key->under, under, XkbKeyNameLength);
565 OverlayDeclCreate(Atom name, OverlayKeyDef * keys)
570 ol = uTypedAlloc(OverlayDef);
573 bzero(ol, sizeof(OverlayDef));
574 ol->common.stmtType = StmtOverlayDef;
577 for (key = keys; key != NULL;
578 key = (OverlayKeyDef *) key->common.next)
587 DoodadCreate(unsigned type, Atom name, VarDef * body)
591 doodad = uTypedAlloc(DoodadDef);
594 bzero(doodad, sizeof(DoodadDef));
595 doodad->common.stmtType = StmtDoodadDef;
596 doodad->common.next = NULL;
605 AppendKeysymList(ExprDef * list, char *sym)
607 if (list->value.list.nSyms >= list->value.list.szSyms)
609 list->value.list.szSyms *= 2;
610 list->value.list.syms = uTypedRecalloc(list->value.list.syms,
611 list->value.list.nSyms,
612 list->value.list.szSyms,
614 if (list->value.list.syms == NULL)
616 FATAL("Couldn't resize list of symbols for append\n");
620 list->value.list.syms[list->value.list.nSyms++] = sym;
625 LookupKeysym(char *str, KeySym * sym_rtrn)
630 if ((!str) || (uStrCaseCmp(str, "any") == 0)
631 || (uStrCaseCmp(str, "nosymbol") == 0))
633 *sym_rtrn = NoSymbol;
636 else if ((uStrCaseCmp(str, "none") == 0)
637 || (uStrCaseCmp(str, "voidsymbol") == 0))
639 *sym_rtrn = XK_VoidSymbol;
642 sym = XStringToKeysym(str);
648 if (strlen(str) > 2 && str[0] == '0' && str[1] == 'x') {
649 sym = strtoul(str, &tmp, 16);
650 if (sym != ULONG_MAX && (!tmp || *tmp == '\0')) {
659 IncludeCreate(char *str, unsigned merge)
661 IncludeStmt *incl, *first;
662 char *file, *map, *stmt, *tmp, *extra_data;
670 stmt = uStringDup(str);
671 while ((tmp) && (*tmp))
673 if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
675 if ((file == NULL) && (map == NULL))
682 first = incl = uTypedAlloc(IncludeStmt);
685 incl->next = uTypedAlloc(IncludeStmt);
690 incl->common.stmtType = StmtInclude;
691 incl->common.next = NULL;
696 incl->modifier = extra_data;
702 WSGO("Allocation failure in IncludeCreate\n");
703 ACTION("Using only part of the include\n");
707 merge = MergeAugment;
709 merge = MergeOverride;
722 ERROR1("Illegal include statement \"%s\"\n", stmt);
732 uFree(first->modifier);
735 first->file = first->map = first->path = NULL;
746 PrintStmtAddrs(ParseCommon * stmt)
748 fprintf(stderr, "0x%x", stmt);
753 fprintf(stderr, "->0x%x", stmt->next);
758 fprintf(stderr, "\n");
763 CheckDefaultMap(XkbFile * maps)
768 for (tmp = maps, dflt = NULL; tmp != NULL;
769 tmp = (XkbFile *) tmp->common.next)
771 if (tmp->flags & XkbLC_Default)
777 if (warningLevel > 2)
779 WARN1("Multiple default components in %s\n",
780 (scanFile ? scanFile : "(unknown)"));
781 ACTION2("Using %s, ignoring %s\n",
782 (dflt->name ? dflt->name : "(first)"),
783 (tmp->name ? tmp->name : "(subsequent)"));
785 tmp->flags &= (~XkbLC_Default);
793 XKBParseFile(FILE * file, XkbFile ** pRtrn)
802 CheckDefaultMap(rtrnValue);
814 CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
819 file = uTypedAlloc(XkbFile);
822 XkbEnsureSafeMapName(name);
823 bzero(file, sizeof(XkbFile));
825 file->topName = uStringDup(name);
829 file->compiled = False;
836 StmtSetMerge(ParseCommon * stmt, unsigned merge)
838 if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
840 yyerror("illegal use of 'alternate' merge mode");
841 merge = MergeDefault;