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(const char *sym_str, ExprDef * match)
227 def = uTypedAlloc(InterpDef);
230 def->common.stmtType = StmtInterpDef;
231 def->common.next = NULL;
232 if (LookupKeysym(sym_str, &def->sym) == 0)
240 FATAL("Couldn't allocate interp definition in parser\n");
247 KeyTypeCreate(Atom name, VarDef * body)
251 def = uTypedAlloc(KeyTypeDef);
254 def->common.stmtType = StmtKeyTypeDef;
255 def->common.next = NULL;
256 def->merge = MergeDefault;
262 FATAL("Couldn't allocate key type definition in parser\n");
269 SymbolsCreate(char *keyName, ExprDef * symbols)
273 def = uTypedAlloc(SymbolsDef);
276 def->common.stmtType = StmtSymbolsDef;
277 def->common.next = NULL;
278 def->merge = MergeDefault;
279 bzero(def->keyName, 5);
280 strncpy(def->keyName, keyName, 4);
281 def->symbols = symbols;
285 FATAL("Couldn't allocate symbols definition in parser\n");
292 GroupCompatCreate(int group, ExprDef * val)
296 def = uTypedAlloc(GroupCompatDef);
299 def->common.stmtType = StmtGroupCompatDef;
300 def->common.next = NULL;
301 def->merge = MergeDefault;
307 FATAL("Couldn't allocate group compat definition in parser\n");
314 ModMapCreate(Atom modifier, ExprDef * keys)
318 def = uTypedAlloc(ModMapDef);
321 def->common.stmtType = StmtModMapDef;
322 def->common.next = NULL;
323 def->merge = MergeDefault;
324 def->modifier = modifier;
329 FATAL("Couldn't allocate mod mask definition in parser\n");
336 IndicatorMapCreate(Atom name, VarDef * body)
338 IndicatorMapDef *def;
340 def = uTypedAlloc(IndicatorMapDef);
343 def->common.stmtType = StmtIndicatorMapDef;
344 def->common.next = NULL;
345 def->merge = MergeDefault;
351 FATAL("Couldn't allocate indicator map definition in parser\n");
358 IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
360 IndicatorNameDef *def;
362 def = uTypedAlloc(IndicatorNameDef);
365 def->common.stmtType = StmtIndicatorNameDef;
366 def->common.next = NULL;
367 def->merge = MergeDefault;
370 def->virtual = virtual;
374 FATAL("Couldn't allocate indicator index definition in parser\n");
381 ActionCreate(Atom name, ExprDef * args)
385 act = uTypedAlloc(ExprDef);
388 act->common.stmtType = StmtExpr;
389 act->common.next = NULL;
390 act->op = ExprActionDecl;
391 act->value.action.name = name;
392 act->value.action.args = args;
395 FATAL("Couldn't allocate ActionDef in parser\n");
400 CreateKeysymList(char *sym)
404 def = ExprCreate(ExprKeysymList, TypeSymbols);
407 def->value.list.nSyms = 1;
408 def->value.list.szSyms = 4;
409 def->value.list.syms = uTypedCalloc(4, char *);
410 if (def->value.list.syms != NULL)
412 def->value.list.syms[0] = sym;
416 FATAL("Couldn't allocate expression for keysym list in parser\n");
421 ShapeDeclCreate(Atom name, OutlineDef * outlines)
426 shape = uTypedAlloc(ShapeDef);
429 bzero(shape, sizeof(ShapeDef));
430 shape->common.stmtType = StmtShapeDef;
431 shape->common.next = NULL;
432 shape->merge = MergeDefault;
434 shape->nOutlines = 0;
435 shape->outlines = outlines;
436 for (ol = outlines; ol != NULL; ol = (OutlineDef *) ol->common.next)
446 OutlineCreate(Atom field, ExprDef * points)
451 outline = uTypedAlloc(OutlineDef);
454 bzero(outline, sizeof(OutlineDef));
455 outline->common.stmtType = StmtOutlineDef;
456 outline->common.next = NULL;
457 outline->field = field;
458 outline->nPoints = 0;
459 if (points->op == ExprCoord)
461 for (pt = points; pt != NULL; pt = (ExprDef *) pt->common.next)
466 outline->points = points;
472 KeyDeclCreate(char *name, ExprDef * expr)
476 key = uTypedAlloc(KeyDef);
479 bzero(key, sizeof(KeyDef));
480 key->common.stmtType = StmtKeyDef;
481 key->common.next = NULL;
491 KeyDeclMerge(KeyDef * into, KeyDef * from)
494 (ExprDef *) AppendStmt(&into->expr->common, &from->expr->common);
501 RowDeclCreate(KeyDef * keys)
506 row = uTypedAlloc(RowDef);
509 bzero(row, sizeof(RowDef));
510 row->common.stmtType = StmtRowDef;
511 row->common.next = NULL;
514 for (key = keys; key != NULL; key = (KeyDef *) key->common.next)
516 if (key->common.stmtType == StmtKeyDef)
524 SectionDeclCreate(Atom name, RowDef * rows)
529 section = uTypedAlloc(SectionDef);
532 bzero(section, sizeof(SectionDef));
533 section->common.stmtType = StmtSectionDef;
534 section->common.next = NULL;
535 section->name = name;
537 section->rows = rows;
538 for (row = rows; row != NULL; row = (RowDef *) row->common.next)
540 if (row->common.stmtType == StmtRowDef)
548 OverlayKeyCreate(char *under, char *over)
552 key = uTypedAlloc(OverlayKeyDef);
555 bzero(key, sizeof(OverlayKeyDef));
556 key->common.stmtType = StmtOverlayKeyDef;
557 strncpy(key->over, over, XkbKeyNameLength);
558 strncpy(key->under, under, XkbKeyNameLength);
568 OverlayDeclCreate(Atom name, OverlayKeyDef * keys)
573 ol = uTypedAlloc(OverlayDef);
576 bzero(ol, sizeof(OverlayDef));
577 ol->common.stmtType = StmtOverlayDef;
580 for (key = keys; key != NULL;
581 key = (OverlayKeyDef *) key->common.next)
590 DoodadCreate(unsigned type, Atom name, VarDef * body)
594 doodad = uTypedAlloc(DoodadDef);
597 bzero(doodad, sizeof(DoodadDef));
598 doodad->common.stmtType = StmtDoodadDef;
599 doodad->common.next = NULL;
608 AppendKeysymList(ExprDef * list, char *sym)
610 if (list->value.list.nSyms >= list->value.list.szSyms)
612 list->value.list.szSyms *= 2;
613 list->value.list.syms = uTypedRecalloc(list->value.list.syms,
614 list->value.list.nSyms,
615 list->value.list.szSyms,
617 if (list->value.list.syms == NULL)
619 FATAL("Couldn't resize list of symbols for append\n");
623 list->value.list.syms[list->value.list.nSyms++] = sym;
628 LookupKeysym(const char *str, KeySym * sym_rtrn)
633 if ((!str) || (uStrCaseCmp(str, "any") == 0)
634 || (uStrCaseCmp(str, "nosymbol") == 0))
636 *sym_rtrn = NoSymbol;
639 else if ((uStrCaseCmp(str, "none") == 0)
640 || (uStrCaseCmp(str, "voidsymbol") == 0))
642 *sym_rtrn = XK_VoidSymbol;
645 sym = XStringToKeysym(str);
651 if (strlen(str) > 2 && str[0] == '0' && str[1] == 'x') {
652 sym = strtoul(str, &tmp, 16);
653 if (sym != ULONG_MAX && (!tmp || *tmp == '\0')) {
662 IncludeCreate(char *str, unsigned merge)
664 IncludeStmt *incl, *first;
665 char *file, *map, *stmt, *tmp, *extra_data;
673 stmt = uStringDup(str);
674 while ((tmp) && (*tmp))
676 if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
678 if ((file == NULL) && (map == NULL))
685 first = incl = uTypedAlloc(IncludeStmt);
688 incl->next = uTypedAlloc(IncludeStmt);
693 incl->common.stmtType = StmtInclude;
694 incl->common.next = NULL;
699 incl->modifier = extra_data;
705 WSGO("Allocation failure in IncludeCreate\n");
706 ACTION("Using only part of the include\n");
710 merge = MergeAugment;
712 merge = MergeOverride;
725 ERROR1("Illegal include statement \"%s\"\n", stmt);
735 uFree(first->modifier);
738 first->file = first->map = first->path = NULL;
749 PrintStmtAddrs(ParseCommon * stmt)
751 fprintf(stderr, "%p", stmt);
756 fprintf(stderr, "->%p", stmt->next);
761 fprintf(stderr, "\n");
766 CheckDefaultMap(XkbFile * maps)
771 for (tmp = maps, dflt = NULL; tmp != NULL;
772 tmp = (XkbFile *) tmp->common.next)
774 if (tmp->flags & XkbLC_Default)
780 if (warningLevel > 2)
782 WARN1("Multiple default components in %s\n",
783 (scanFile ? scanFile : "(unknown)"));
784 ACTION2("Using %s, ignoring %s\n",
785 (dflt->name ? dflt->name : "(first)"),
786 (tmp->name ? tmp->name : "(subsequent)"));
788 tmp->flags &= (~XkbLC_Default);
796 XKBParseFile(FILE * file, XkbFile ** pRtrn)
805 CheckDefaultMap(rtrnValue);
817 CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
822 file = uTypedAlloc(XkbFile);
825 XkbEnsureSafeMapName(name);
826 bzero(file, sizeof(XkbFile));
828 file->topName = uStringDup(name);
832 file->compiled = False;
839 StmtSetMerge(ParseCommon * stmt, unsigned merge)
841 if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
843 yyerror("illegal use of 'alternate' merge mode");
844 merge = MergeDefault;