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/XKBgeomcommon.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, ExprDef * 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(Atom 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(Atom 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(KeySym 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(Atom 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 bzero(def->keyName, 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(Atom 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(Atom 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(Atom 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(KeySym sym)
399 def = ExprCreate(ExprKeysymList, TypeSymbols);
402 def->value.list.nSyms = 1;
403 def->value.list.szSyms = 2;
404 def->value.list.syms = uTypedCalloc(2, KeySym);
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 ShapeDeclCreate(Atom name, OutlineDef * outlines)
421 shape = uTypedAlloc(ShapeDef);
424 bzero(shape, sizeof(ShapeDef));
425 shape->common.stmtType = StmtShapeDef;
426 shape->common.next = NULL;
427 shape->merge = MergeDefault;
429 shape->nOutlines = 0;
430 shape->outlines = outlines;
431 for (ol = outlines; ol != NULL; ol = (OutlineDef *) ol->common.next)
441 OutlineCreate(Atom field, ExprDef * points)
446 outline = uTypedAlloc(OutlineDef);
449 bzero(outline, sizeof(OutlineDef));
450 outline->common.stmtType = StmtOutlineDef;
451 outline->common.next = NULL;
452 outline->field = field;
453 outline->nPoints = 0;
454 if (points->op == ExprCoord)
456 for (pt = points; pt != NULL; pt = (ExprDef *) pt->common.next)
461 outline->points = points;
467 KeyDeclCreate(char *name, ExprDef * expr)
471 key = uTypedAlloc(KeyDef);
474 bzero(key, sizeof(KeyDef));
475 key->common.stmtType = StmtKeyDef;
476 key->common.next = NULL;
486 KeyDeclMerge(KeyDef * into, KeyDef * from)
489 (ExprDef *) AppendStmt(&into->expr->common, &from->expr->common);
496 RowDeclCreate(KeyDef * keys)
501 row = uTypedAlloc(RowDef);
504 bzero(row, sizeof(RowDef));
505 row->common.stmtType = StmtRowDef;
506 row->common.next = NULL;
509 for (key = keys; key != NULL; key = (KeyDef *) key->common.next)
511 if (key->common.stmtType == StmtKeyDef)
519 SectionDeclCreate(Atom name, RowDef * rows)
524 section = uTypedAlloc(SectionDef);
527 bzero(section, sizeof(SectionDef));
528 section->common.stmtType = StmtSectionDef;
529 section->common.next = NULL;
530 section->name = name;
532 section->rows = rows;
533 for (row = rows; row != NULL; row = (RowDef *) row->common.next)
535 if (row->common.stmtType == StmtRowDef)
543 OverlayKeyCreate(char *under, char *over)
547 key = uTypedAlloc(OverlayKeyDef);
550 bzero(key, sizeof(OverlayKeyDef));
551 key->common.stmtType = StmtOverlayKeyDef;
552 strncpy(key->over, over, XkbKeyNameLength);
553 strncpy(key->under, under, XkbKeyNameLength);
563 OverlayDeclCreate(Atom name, OverlayKeyDef * keys)
568 ol = uTypedAlloc(OverlayDef);
571 bzero(ol, sizeof(OverlayDef));
572 ol->common.stmtType = StmtOverlayDef;
575 for (key = keys; key != NULL;
576 key = (OverlayKeyDef *) key->common.next)
585 DoodadCreate(unsigned type, Atom name, VarDef * body)
589 doodad = uTypedAlloc(DoodadDef);
592 bzero(doodad, sizeof(DoodadDef));
593 doodad->common.stmtType = StmtDoodadDef;
594 doodad->common.next = NULL;
603 AppendKeysymList(ExprDef * list, KeySym sym)
605 if (list->value.list.nSyms >= list->value.list.szSyms)
607 list->value.list.szSyms *= 2;
608 list->value.list.syms = uTypedRecalloc(list->value.list.syms,
609 list->value.list.nSyms,
610 list->value.list.szSyms,
612 if (list->value.list.syms == NULL)
614 FATAL("Couldn't resize list of symbols for append\n");
618 list->value.list.syms[list->value.list.nSyms++] = sym;
623 LookupKeysym(char *str, KeySym * sym_rtrn)
627 if ((!str) || (uStrCaseCmp(str, "any") == 0)
628 || (uStrCaseCmp(str, "nosymbol") == 0))
630 *sym_rtrn = NoSymbol;
633 else if ((uStrCaseCmp(str, "none") == 0)
634 || (uStrCaseCmp(str, "voidsymbol") == 0))
636 *sym_rtrn = XK_VoidSymbol;
639 sym = XkbcStringToKeysym(str);
649 IncludeCreate(char *str, unsigned merge)
651 IncludeStmt *incl, *first;
652 char *file, *map, *stmt, *tmp, *extra_data;
660 stmt = uStringDup(str);
661 while ((tmp) && (*tmp))
663 if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
665 if ((file == NULL) && (map == NULL))
672 first = incl = uTypedAlloc(IncludeStmt);
675 incl->next = uTypedAlloc(IncludeStmt);
680 incl->common.stmtType = StmtInclude;
681 incl->common.next = NULL;
686 incl->modifier = extra_data;
692 WSGO("Allocation failure in IncludeCreate\n");
693 ACTION("Using only part of the include\n");
697 merge = MergeAugment;
699 merge = MergeOverride;
712 ERROR("Illegal include statement \"%s\"\n", stmt);
722 uFree(first->modifier);
725 first->file = first->map = first->path = NULL;
736 PrintStmtAddrs(ParseCommon * stmt)
738 fprintf(stderr, "0x%x", stmt);
743 fprintf(stderr, "->0x%x", stmt->next);
748 fprintf(stderr, "\n");
753 CheckDefaultMap(XkbFile * maps)
758 for (tmp = maps, dflt = NULL; tmp != NULL;
759 tmp = (XkbFile *) tmp->common.next)
761 if (tmp->flags & XkbLC_Default)
767 if (warningLevel > 2)
769 WARN("Multiple default components in %s\n",
770 (scanFile ? scanFile : "(unknown)"));
771 ACTION("Using %s, ignoring %s\n",
772 (dflt->name ? dflt->name : "(first)"),
773 (tmp->name ? tmp->name : "(subsequent)"));
775 tmp->flags &= (~XkbLC_Default);
783 XKBParseFile(FILE * file, XkbFile ** pRtrn)
792 CheckDefaultMap(rtrnValue);
804 CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
809 file = uTypedAlloc(XkbFile);
812 XkbcEnsureSafeMapName(name);
813 bzero(file, sizeof(XkbFile));
815 file->topName = uStringDup(name);
819 file->compiled = False;
826 StmtSetMerge(ParseCommon * stmt, unsigned merge)
828 if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
830 yyerror("illegal use of 'alternate' merge mode");
831 merge = MergeDefault;