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"
31 #include <X11/keysym.h>
32 #include <X11/extensions/XKBgeomcommon.h>
33 #include <X11/Xalloca.h>
38 AppendStmt(ParseCommon * to, ParseCommon * append)
40 ParseCommon *start = to;
44 while ((to != NULL) && (to->next != NULL))
57 ExprCreate(unsigned op, unsigned type)
60 expr = uTypedAlloc(ExprDef);
63 expr->common.stmtType = StmtExpr;
64 expr->common.next = NULL;
70 FATAL("Couldn't allocate expression in parser\n");
77 ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
80 expr = uTypedAlloc(ExprDef);
83 expr->common.stmtType = StmtExpr;
84 expr->common.next = NULL;
87 expr->value.child = child;
91 FATAL("Couldn't allocate expression in parser\n");
98 ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right)
101 expr = uTypedAlloc(ExprDef);
104 expr->common.stmtType = StmtExpr;
105 expr->common.next = NULL;
107 if ((op == OpAssign) || (left->type == TypeUnknown))
108 expr->type = right->type;
109 else if ((left->type == right->type) || (right->type == TypeUnknown))
110 expr->type = left->type;
112 expr->type = TypeUnknown;
113 expr->value.binary.left = left;
114 expr->value.binary.right = right;
118 FATAL("Couldn't allocate expression in parser\n");
125 KeycodeCreate(char *name, ExprDef * value)
129 def = uTypedAlloc(KeycodeDef);
132 def->common.stmtType = StmtKeycodeDef;
133 def->common.next = NULL;
134 strncpy(def->name, name, XkbKeyNameLength);
135 def->name[XkbKeyNameLength] = '\0';
140 FATAL("Couldn't allocate key name definition in parser\n");
147 KeyAliasCreate(char *alias, char *real)
151 def = uTypedAlloc(KeyAliasDef);
154 def->common.stmtType = StmtKeyAliasDef;
155 def->common.next = NULL;
156 strncpy(def->alias, alias, XkbKeyNameLength);
157 def->alias[XkbKeyNameLength] = '\0';
158 strncpy(def->real, real, XkbKeyNameLength);
159 def->real[XkbKeyNameLength] = '\0';
163 FATAL("Couldn't allocate key alias definition in parser\n");
170 VModCreate(Atom name, ExprDef * value)
173 def = uTypedAlloc(VModDef);
176 def->common.stmtType = StmtVModDef;
177 def->common.next = NULL;
183 FATAL("Couldn't allocate variable definition in parser\n");
190 VarCreate(ExprDef * name, ExprDef * value)
193 def = uTypedAlloc(VarDef);
196 def->common.stmtType = StmtVarDef;
197 def->common.next = NULL;
203 FATAL("Couldn't allocate variable definition in parser\n");
210 BoolVarCreate(Atom nameToken, unsigned set)
212 ExprDef *name, *value;
214 name = ExprCreate(ExprIdent, TypeUnknown);
215 name->value.str = nameToken;
216 value = ExprCreate(ExprValue, TypeBoolean);
217 value->value.uval = set;
218 return VarCreate(name, value);
222 InterpCreate(char *sym, ExprDef * match)
226 def = uTypedAlloc(InterpDef);
229 def->common.stmtType = StmtInterpDef;
230 def->common.next = NULL;
231 def->sym = strdup(sym);
236 FATAL("Couldn't allocate interp definition in parser\n");
243 KeyTypeCreate(Atom name, VarDef * body)
247 def = uTypedAlloc(KeyTypeDef);
250 def->common.stmtType = StmtKeyTypeDef;
251 def->common.next = NULL;
252 def->merge = MergeDefault;
258 FATAL("Couldn't allocate key type definition in parser\n");
265 SymbolsCreate(char *keyName, ExprDef * symbols)
269 def = uTypedAlloc(SymbolsDef);
272 def->common.stmtType = StmtSymbolsDef;
273 def->common.next = NULL;
274 def->merge = MergeDefault;
275 bzero(def->keyName, 5);
276 strncpy(def->keyName, keyName, 4);
277 def->symbols = symbols;
281 FATAL("Couldn't allocate symbols definition in parser\n");
288 GroupCompatCreate(int group, ExprDef * val)
292 def = uTypedAlloc(GroupCompatDef);
295 def->common.stmtType = StmtGroupCompatDef;
296 def->common.next = NULL;
297 def->merge = MergeDefault;
303 FATAL("Couldn't allocate group compat definition in parser\n");
310 ModMapCreate(Atom modifier, ExprDef * keys)
314 def = uTypedAlloc(ModMapDef);
317 def->common.stmtType = StmtModMapDef;
318 def->common.next = NULL;
319 def->merge = MergeDefault;
320 def->modifier = modifier;
325 FATAL("Couldn't allocate mod mask definition in parser\n");
332 IndicatorMapCreate(Atom name, VarDef * body)
334 IndicatorMapDef *def;
336 def = uTypedAlloc(IndicatorMapDef);
339 def->common.stmtType = StmtIndicatorMapDef;
340 def->common.next = NULL;
341 def->merge = MergeDefault;
347 FATAL("Couldn't allocate indicator map definition in parser\n");
354 IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
356 IndicatorNameDef *def;
358 def = uTypedAlloc(IndicatorNameDef);
361 def->common.stmtType = StmtIndicatorNameDef;
362 def->common.next = NULL;
363 def->merge = MergeDefault;
366 def->virtual = virtual;
370 FATAL("Couldn't allocate indicator index definition in parser\n");
377 ActionCreate(Atom name, ExprDef * args)
381 act = uTypedAlloc(ExprDef);
384 act->common.stmtType = StmtExpr;
385 act->common.next = NULL;
386 act->op = ExprActionDecl;
387 act->value.action.name = name;
388 act->value.action.args = args;
391 FATAL("Couldn't allocate ActionDef in parser\n");
396 CreateKeysymList(char *sym)
400 def = ExprCreate(ExprKeysymList, TypeSymbols);
403 def->value.list.nSyms = 1;
404 def->value.list.szSyms = 4;
405 def->value.list.syms = uTypedCalloc(4, char *);
406 if (def->value.list.syms != NULL)
408 def->value.list.syms[0] = sym;
412 FATAL("Couldn't allocate expression for keysym list in parser\n");
417 ShapeDeclCreate(Atom name, OutlineDef * outlines)
422 shape = uTypedAlloc(ShapeDef);
425 bzero(shape, sizeof(ShapeDef));
426 shape->common.stmtType = StmtShapeDef;
427 shape->common.next = NULL;
428 shape->merge = MergeDefault;
430 shape->nOutlines = 0;
431 shape->outlines = outlines;
432 for (ol = outlines; ol != NULL; ol = (OutlineDef *) ol->common.next)
442 OutlineCreate(Atom field, ExprDef * points)
447 outline = uTypedAlloc(OutlineDef);
450 bzero(outline, sizeof(OutlineDef));
451 outline->common.stmtType = StmtOutlineDef;
452 outline->common.next = NULL;
453 outline->field = field;
454 outline->nPoints = 0;
455 if (points->op == ExprCoord)
457 for (pt = points; pt != NULL; pt = (ExprDef *) pt->common.next)
462 outline->points = points;
468 KeyDeclCreate(char *name, ExprDef * expr)
472 key = uTypedAlloc(KeyDef);
475 bzero(key, sizeof(KeyDef));
476 key->common.stmtType = StmtKeyDef;
477 key->common.next = NULL;
487 KeyDeclMerge(KeyDef * into, KeyDef * from)
490 (ExprDef *) AppendStmt(&into->expr->common, &from->expr->common);
497 RowDeclCreate(KeyDef * keys)
502 row = uTypedAlloc(RowDef);
505 bzero(row, sizeof(RowDef));
506 row->common.stmtType = StmtRowDef;
507 row->common.next = NULL;
510 for (key = keys; key != NULL; key = (KeyDef *) key->common.next)
512 if (key->common.stmtType == StmtKeyDef)
520 SectionDeclCreate(Atom name, RowDef * rows)
525 section = uTypedAlloc(SectionDef);
528 bzero(section, sizeof(SectionDef));
529 section->common.stmtType = StmtSectionDef;
530 section->common.next = NULL;
531 section->name = name;
533 section->rows = rows;
534 for (row = rows; row != NULL; row = (RowDef *) row->common.next)
536 if (row->common.stmtType == StmtRowDef)
544 OverlayKeyCreate(char *under, char *over)
548 key = uTypedAlloc(OverlayKeyDef);
551 bzero(key, sizeof(OverlayKeyDef));
552 key->common.stmtType = StmtOverlayKeyDef;
553 strncpy(key->over, over, XkbKeyNameLength);
554 strncpy(key->under, under, XkbKeyNameLength);
564 OverlayDeclCreate(Atom name, OverlayKeyDef * keys)
569 ol = uTypedAlloc(OverlayDef);
572 bzero(ol, sizeof(OverlayDef));
573 ol->common.stmtType = StmtOverlayDef;
576 for (key = keys; key != NULL;
577 key = (OverlayKeyDef *) key->common.next)
586 DoodadCreate(unsigned type, Atom name, VarDef * body)
590 doodad = uTypedAlloc(DoodadDef);
593 bzero(doodad, sizeof(DoodadDef));
594 doodad->common.stmtType = StmtDoodadDef;
595 doodad->common.next = NULL;
604 AppendKeysymList(ExprDef * list, char *sym)
606 if (list->value.list.nSyms >= list->value.list.szSyms)
608 list->value.list.szSyms *= 2;
609 list->value.list.syms = uTypedRecalloc(list->value.list.syms,
610 list->value.list.nSyms,
611 list->value.list.szSyms,
613 if (list->value.list.syms == NULL)
615 FATAL("Couldn't resize list of symbols for append\n");
619 list->value.list.syms[list->value.list.nSyms++] = sym;
624 LookupKeysym(char *str, CARD32 * sym_rtrn)
628 if ((!str) || (uStrCaseCmp(str, "any") == 0)
629 || (uStrCaseCmp(str, "nosymbol") == 0))
631 *sym_rtrn = NoSymbol;
634 else if ((uStrCaseCmp(str, "none") == 0)
635 || (uStrCaseCmp(str, "voidsymbol") == 0))
637 *sym_rtrn = XK_VoidSymbol;
640 sym = XkbcStringToKeysym(str);
650 IncludeCreate(char *str, unsigned merge)
652 IncludeStmt *incl, *first;
653 char *file, *map, *stmt, *tmp, *extra_data;
661 stmt = _XkbDupString(str);
662 while ((tmp) && (*tmp))
664 if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
666 if ((file == NULL) && (map == NULL))
673 first = incl = uTypedAlloc(IncludeStmt);
676 incl->next = uTypedAlloc(IncludeStmt);
681 incl->common.stmtType = StmtInclude;
682 incl->common.next = NULL;
687 incl->modifier = extra_data;
693 WSGO("Allocation failure in IncludeCreate\n");
694 ACTION("Using only part of the include\n");
698 merge = MergeAugment;
700 merge = MergeOverride;
713 ERROR("Illegal include statement \"%s\"\n", stmt);
723 uFree(first->modifier);
726 first->file = first->map = first->path = NULL;
737 PrintStmtAddrs(ParseCommon * stmt)
739 fprintf(stderr, "0x%x", stmt);
744 fprintf(stderr, "->0x%x", stmt->next);
749 fprintf(stderr, "\n");
754 CheckDefaultMap(XkbFile * maps)
759 for (tmp = maps, dflt = NULL; tmp != NULL;
760 tmp = (XkbFile *) tmp->common.next)
762 if (tmp->flags & XkbLC_Default)
768 if (warningLevel > 2)
770 WARN("Multiple default components in %s\n",
771 (scanFile ? scanFile : "(unknown)"));
772 ACTION("Using %s, ignoring %s\n",
773 (dflt->name ? dflt->name : "(first)"),
774 (tmp->name ? tmp->name : "(subsequent)"));
776 tmp->flags &= (~XkbLC_Default);
784 XKBParseFile(FILE * file, XkbFile ** pRtrn)
793 CheckDefaultMap(rtrnValue);
805 CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
810 file = uTypedAlloc(XkbFile);
813 XkbcEnsureSafeMapName(name);
814 bzero(file, sizeof(XkbFile));
816 file->topName = _XkbDupString(name);
820 file->compiled = False;
827 StmtSetMerge(ParseCommon * stmt, unsigned merge)
829 if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
831 yyerror("illegal use of 'alternate' merge mode");
832 merge = MergeDefault;