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 #include "parseutils.h"
31 #include <X11/keysym.h>
32 #include <X11/Xalloca.h>
37 AppendStmt(ParseCommon * to, ParseCommon * append)
39 ParseCommon *start = to;
43 while ((to != NULL) && (to->next != NULL))
56 ExprCreate(unsigned op, unsigned type)
59 expr = uTypedAlloc(ExprDef);
62 expr->common.stmtType = StmtExpr;
63 expr->common.next = NULL;
69 FATAL("Couldn't allocate expression in parser\n");
76 ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
79 expr = uTypedAlloc(ExprDef);
82 expr->common.stmtType = StmtExpr;
83 expr->common.next = NULL;
86 expr->value.child = child;
90 FATAL("Couldn't allocate expression in parser\n");
97 ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right)
100 expr = uTypedAlloc(ExprDef);
103 expr->common.stmtType = StmtExpr;
104 expr->common.next = NULL;
106 if ((op == OpAssign) || (left->type == TypeUnknown))
107 expr->type = right->type;
108 else if ((left->type == right->type) || (right->type == TypeUnknown))
109 expr->type = left->type;
111 expr->type = TypeUnknown;
112 expr->value.binary.left = left;
113 expr->value.binary.right = right;
117 FATAL("Couldn't allocate expression in parser\n");
124 KeycodeCreate(char *name, unsigned long value)
128 def = uTypedAlloc(KeycodeDef);
131 def->common.stmtType = StmtKeycodeDef;
132 def->common.next = NULL;
133 strncpy(def->name, name, XkbKeyNameLength);
134 def->name[XkbKeyNameLength] = '\0';
139 FATAL("Couldn't allocate key name definition in parser\n");
146 KeyAliasCreate(char *alias, char *real)
150 def = uTypedAlloc(KeyAliasDef);
153 def->common.stmtType = StmtKeyAliasDef;
154 def->common.next = NULL;
155 strncpy(def->alias, alias, XkbKeyNameLength);
156 def->alias[XkbKeyNameLength] = '\0';
157 strncpy(def->real, real, XkbKeyNameLength);
158 def->real[XkbKeyNameLength] = '\0';
162 FATAL("Couldn't allocate key alias definition in parser\n");
169 VModCreate(xkb_atom_t name, ExprDef * value)
172 def = uTypedAlloc(VModDef);
175 def->common.stmtType = StmtVModDef;
176 def->common.next = NULL;
182 FATAL("Couldn't allocate variable definition in parser\n");
189 VarCreate(ExprDef * name, ExprDef * value)
192 def = uTypedAlloc(VarDef);
195 def->common.stmtType = StmtVarDef;
196 def->common.next = NULL;
202 FATAL("Couldn't allocate variable definition in parser\n");
209 BoolVarCreate(xkb_atom_t nameToken, unsigned set)
211 ExprDef *name, *value;
213 name = ExprCreate(ExprIdent, TypeUnknown);
214 name->value.str = nameToken;
215 value = ExprCreate(ExprValue, TypeBoolean);
216 value->value.uval = set;
217 return VarCreate(name, value);
221 InterpCreate(char *sym, ExprDef * match)
225 def = uTypedAlloc(InterpDef);
228 def->common.stmtType = StmtInterpDef;
229 def->common.next = NULL;
235 FATAL("Couldn't allocate interp definition in parser\n");
242 KeyTypeCreate(xkb_atom_t name, VarDef * body)
246 def = uTypedAlloc(KeyTypeDef);
249 def->common.stmtType = StmtKeyTypeDef;
250 def->common.next = NULL;
251 def->merge = MergeDefault;
257 FATAL("Couldn't allocate key type definition in parser\n");
264 SymbolsCreate(char *keyName, ExprDef * symbols)
268 def = uTypedAlloc(SymbolsDef);
271 def->common.stmtType = StmtSymbolsDef;
272 def->common.next = NULL;
273 def->merge = MergeDefault;
274 memset(def->keyName, 0, 5);
275 strncpy(def->keyName, keyName, 4);
276 def->symbols = symbols;
280 FATAL("Couldn't allocate symbols definition in parser\n");
287 GroupCompatCreate(int group, ExprDef * val)
291 def = uTypedAlloc(GroupCompatDef);
294 def->common.stmtType = StmtGroupCompatDef;
295 def->common.next = NULL;
296 def->merge = MergeDefault;
302 FATAL("Couldn't allocate group compat definition in parser\n");
309 ModMapCreate(uint32_t modifier, ExprDef * keys)
313 def = uTypedAlloc(ModMapDef);
316 def->common.stmtType = StmtModMapDef;
317 def->common.next = NULL;
318 def->merge = MergeDefault;
319 def->modifier = modifier;
324 FATAL("Couldn't allocate mod mask definition in parser\n");
331 IndicatorMapCreate(xkb_atom_t name, VarDef * body)
333 IndicatorMapDef *def;
335 def = uTypedAlloc(IndicatorMapDef);
338 def->common.stmtType = StmtIndicatorMapDef;
339 def->common.next = NULL;
340 def->merge = MergeDefault;
346 FATAL("Couldn't allocate indicator map definition in parser\n");
353 IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
355 IndicatorNameDef *def;
357 def = uTypedAlloc(IndicatorNameDef);
360 def->common.stmtType = StmtIndicatorNameDef;
361 def->common.next = NULL;
362 def->merge = MergeDefault;
365 def->virtual = virtual;
369 FATAL("Couldn't allocate indicator index definition in parser\n");
376 ActionCreate(xkb_atom_t name, ExprDef * args)
380 act = uTypedAlloc(ExprDef);
383 act->common.stmtType = StmtExpr;
384 act->common.next = NULL;
385 act->op = ExprActionDecl;
386 act->value.action.name = name;
387 act->value.action.args = args;
390 FATAL("Couldn't allocate ActionDef in parser\n");
395 CreateKeysymList(char *sym)
399 def = ExprCreate(ExprKeysymList, TypeSymbols);
402 def->value.list.nSyms = 1;
403 def->value.list.szSyms = 4;
404 def->value.list.syms = uTypedCalloc(4, char *);
405 if (def->value.list.syms != NULL)
407 def->value.list.syms[0] = sym;
411 FATAL("Couldn't allocate expression for keysym list in parser\n");
416 AppendKeysymList(ExprDef * list, char *sym)
418 if (list->value.list.nSyms >= list->value.list.szSyms)
420 list->value.list.szSyms *= 2;
421 list->value.list.syms = uTypedRecalloc(list->value.list.syms,
422 list->value.list.nSyms,
423 list->value.list.szSyms,
425 if (list->value.list.syms == NULL)
427 FATAL("Couldn't resize list of symbols for append\n");
431 list->value.list.syms[list->value.list.nSyms++] = sym;
436 LookupKeysym(char *str, xkb_keysym_t * sym_rtrn)
440 if ((!str) || (strcasecmp(str, "any") == 0) ||
441 (strcasecmp(str, "nosymbol") == 0))
443 *sym_rtrn = NoSymbol;
446 else if ((strcasecmp(str, "none") == 0) ||
447 (strcasecmp(str, "voidsymbol") == 0))
449 *sym_rtrn = XK_VoidSymbol;
452 sym = xkb_string_to_keysym(str);
462 FreeInclude(IncludeStmt *incl);
465 IncludeCreate(char *str, unsigned merge)
467 IncludeStmt *incl, *first;
468 char *file, *map, *stmt, *tmp, *extra_data;
476 stmt = uDupString(str);
477 while ((tmp) && (*tmp))
479 if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
481 if ((file == NULL) && (map == NULL))
488 first = incl = uTypedAlloc(IncludeStmt);
491 incl->next = uTypedAlloc(IncludeStmt);
496 incl->common.stmtType = StmtInclude;
497 incl->common.next = NULL;
502 incl->modifier = extra_data;
508 WSGO("Allocation failure in IncludeCreate\n");
509 ACTION("Using only part of the include\n");
513 merge = MergeAugment;
515 merge = MergeOverride;
529 ERROR("Illegal include statement \"%s\"\n", stmt);
538 PrintStmtAddrs(ParseCommon * stmt)
540 fprintf(stderr, "0x%x", stmt);
545 fprintf(stderr, "->0x%x", stmt->next);
550 fprintf(stderr, "\n");
555 CheckDefaultMap(XkbFile * maps)
560 for (tmp = maps, dflt = NULL; tmp != NULL;
561 tmp = (XkbFile *) tmp->common.next)
563 if (tmp->flags & XkbLC_Default)
569 if (warningLevel > 2)
571 WARN("Multiple default components in %s\n",
572 (scanFile ? scanFile : "(unknown)"));
573 ACTION("Using %s, ignoring %s\n",
574 (dflt->name ? dflt->name : "(first)"),
575 (tmp->name ? tmp->name : "(subsequent)"));
577 tmp->flags &= (~XkbLC_Default);
584 CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
589 file = uTypedAlloc(XkbFile);
592 XkbcEnsureSafeMapName(name);
593 memset(file, 0, sizeof(XkbFile));
595 file->topName = uDupString(name);
599 file->compiled = False;
606 StmtSetMerge(ParseCommon * stmt, unsigned merge)
608 if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
610 yyerror("illegal use of 'alternate' merge mode");
611 merge = MergeDefault;
617 FreeExpr(ExprDef *expr)
631 FreeStmt(&expr->value.child->common);
638 FreeStmt(&expr->value.binary.left->common);
639 FreeStmt(&expr->value.binary.right->common);
642 FreeStmt(&expr->value.action.args->common);
645 FreeStmt(&expr->value.array.entry->common);
648 for (i = 0; i < expr->value.list.nSyms; i++)
649 free(expr->value.list.syms[i]);
650 free(expr->value.list.syms);
658 FreeInclude(IncludeStmt *incl)
668 free(incl->modifier);
678 FreeStmt(ParseCommon *stmt)
688 switch (stmt->stmtType)
691 FreeInclude((IncludeStmt *)stmt);
692 /* stmt is already free'd here. */
699 FreeStmt(&u.var->name->common);
700 FreeStmt(&u.var->value->common);
703 FreeStmt(&u.keyType->body->common);
707 FreeStmt(&u.interp->match->common);
708 FreeStmt(&u.interp->def->common);
711 FreeStmt(&u.vmod->value->common);
714 FreeStmt(&u.syms->symbols->common);
717 FreeStmt(&u.modMask->keys->common);
719 case StmtGroupCompatDef:
720 FreeStmt(&u.groupCompat->def->common);
722 case StmtIndicatorMapDef:
723 FreeStmt(&u.ledMap->body->common);
725 case StmtIndicatorNameDef:
726 FreeStmt(&u.ledName->name->common);
738 FreeXKBFile(XkbFile *file)
744 next = (XkbFile *)file->common.next;
749 case XkmSemanticsFile:
751 FreeXKBFile((XkbFile *)file->defs);
754 case XkmCompatMapIndex:
755 case XkmSymbolsIndex:
756 case XkmKeyNamesIndex:
757 case XkmGeometryIndex:
758 case XkmGeometryFile:
759 FreeStmt(file->defs);