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"
30 #include <X11/keysym.h>
31 #include <X11/Xalloca.h>
36 AppendStmt(ParseCommon * to, ParseCommon * append)
38 ParseCommon *start = to;
42 while ((to != NULL) && (to->next != NULL))
55 ExprCreate(unsigned op, unsigned type)
58 expr = uTypedAlloc(ExprDef);
61 expr->common.stmtType = StmtExpr;
62 expr->common.next = NULL;
68 FATAL("Couldn't allocate expression in parser\n");
75 ExprCreateUnary(unsigned op, unsigned type, ExprDef * child)
78 expr = uTypedAlloc(ExprDef);
81 expr->common.stmtType = StmtExpr;
82 expr->common.next = NULL;
85 expr->value.child = child;
89 FATAL("Couldn't allocate expression in parser\n");
96 ExprCreateBinary(unsigned op, ExprDef * left, ExprDef * right)
99 expr = uTypedAlloc(ExprDef);
102 expr->common.stmtType = StmtExpr;
103 expr->common.next = NULL;
105 if ((op == OpAssign) || (left->type == TypeUnknown))
106 expr->type = right->type;
107 else if ((left->type == right->type) || (right->type == TypeUnknown))
108 expr->type = left->type;
110 expr->type = TypeUnknown;
111 expr->value.binary.left = left;
112 expr->value.binary.right = right;
116 FATAL("Couldn't allocate expression in parser\n");
123 KeycodeCreate(char *name, ExprDef * value)
127 def = uTypedAlloc(KeycodeDef);
130 def->common.stmtType = StmtKeycodeDef;
131 def->common.next = NULL;
132 strncpy(def->name, name, XkbKeyNameLength);
133 def->name[XkbKeyNameLength] = '\0';
138 FATAL("Couldn't allocate key name definition in parser\n");
145 KeyAliasCreate(char *alias, char *real)
149 def = uTypedAlloc(KeyAliasDef);
152 def->common.stmtType = StmtKeyAliasDef;
153 def->common.next = NULL;
154 strncpy(def->alias, alias, XkbKeyNameLength);
155 def->alias[XkbKeyNameLength] = '\0';
156 strncpy(def->real, real, XkbKeyNameLength);
157 def->real[XkbKeyNameLength] = '\0';
161 FATAL("Couldn't allocate key alias definition in parser\n");
168 VModCreate(uint32_t name, ExprDef * value)
171 def = uTypedAlloc(VModDef);
174 def->common.stmtType = StmtVModDef;
175 def->common.next = NULL;
181 FATAL("Couldn't allocate variable definition in parser\n");
188 VarCreate(ExprDef * name, ExprDef * value)
191 def = uTypedAlloc(VarDef);
194 def->common.stmtType = StmtVarDef;
195 def->common.next = NULL;
201 FATAL("Couldn't allocate variable definition in parser\n");
208 BoolVarCreate(uint32_t nameToken, unsigned set)
210 ExprDef *name, *value;
212 name = ExprCreate(ExprIdent, TypeUnknown);
213 name->value.str = nameToken;
214 value = ExprCreate(ExprValue, TypeBoolean);
215 value->value.uval = set;
216 return VarCreate(name, value);
220 InterpCreate(char *sym, ExprDef * match)
224 def = uTypedAlloc(InterpDef);
227 def->common.stmtType = StmtInterpDef;
228 def->common.next = NULL;
229 def->sym = strdup(sym);
234 FATAL("Couldn't allocate interp definition in parser\n");
241 KeyTypeCreate(uint32_t name, VarDef * body)
245 def = uTypedAlloc(KeyTypeDef);
248 def->common.stmtType = StmtKeyTypeDef;
249 def->common.next = NULL;
250 def->merge = MergeDefault;
256 FATAL("Couldn't allocate key type definition in parser\n");
263 SymbolsCreate(char *keyName, ExprDef * symbols)
267 def = uTypedAlloc(SymbolsDef);
270 def->common.stmtType = StmtSymbolsDef;
271 def->common.next = NULL;
272 def->merge = MergeDefault;
273 bzero(def->keyName, 5);
274 strncpy(def->keyName, keyName, 4);
275 def->symbols = symbols;
279 FATAL("Couldn't allocate symbols definition in parser\n");
286 GroupCompatCreate(int group, ExprDef * val)
290 def = uTypedAlloc(GroupCompatDef);
293 def->common.stmtType = StmtGroupCompatDef;
294 def->common.next = NULL;
295 def->merge = MergeDefault;
301 FATAL("Couldn't allocate group compat definition in parser\n");
308 ModMapCreate(uint32_t modifier, ExprDef * keys)
312 def = uTypedAlloc(ModMapDef);
315 def->common.stmtType = StmtModMapDef;
316 def->common.next = NULL;
317 def->merge = MergeDefault;
318 def->modifier = modifier;
323 FATAL("Couldn't allocate mod mask definition in parser\n");
330 IndicatorMapCreate(uint32_t name, VarDef * body)
332 IndicatorMapDef *def;
334 def = uTypedAlloc(IndicatorMapDef);
337 def->common.stmtType = StmtIndicatorMapDef;
338 def->common.next = NULL;
339 def->merge = MergeDefault;
345 FATAL("Couldn't allocate indicator map definition in parser\n");
352 IndicatorNameCreate(int ndx, ExprDef * name, Bool virtual)
354 IndicatorNameDef *def;
356 def = uTypedAlloc(IndicatorNameDef);
359 def->common.stmtType = StmtIndicatorNameDef;
360 def->common.next = NULL;
361 def->merge = MergeDefault;
364 def->virtual = virtual;
368 FATAL("Couldn't allocate indicator index definition in parser\n");
375 ActionCreate(uint32_t name, ExprDef * args)
379 act = uTypedAlloc(ExprDef);
382 act->common.stmtType = StmtExpr;
383 act->common.next = NULL;
384 act->op = ExprActionDecl;
385 act->value.action.name = name;
386 act->value.action.args = args;
389 FATAL("Couldn't allocate ActionDef in parser\n");
394 CreateKeysymList(char *sym)
398 def = ExprCreate(ExprKeysymList, TypeSymbols);
401 def->value.list.nSyms = 1;
402 def->value.list.szSyms = 4;
403 def->value.list.syms = uTypedCalloc(4, char *);
404 if (def->value.list.syms != NULL)
406 def->value.list.syms[0] = sym;
410 FATAL("Couldn't allocate expression for keysym list in parser\n");
415 ShapeDeclCreate(uint32_t name, OutlineDef * outlines)
420 shape = uTypedAlloc(ShapeDef);
423 bzero(shape, sizeof(ShapeDef));
424 shape->common.stmtType = StmtShapeDef;
425 shape->common.next = NULL;
426 shape->merge = MergeDefault;
428 shape->nOutlines = 0;
429 shape->outlines = outlines;
430 for (ol = outlines; ol != NULL; ol = (OutlineDef *) ol->common.next)
440 OutlineCreate(uint32_t field, ExprDef * points)
445 outline = uTypedAlloc(OutlineDef);
448 bzero(outline, sizeof(OutlineDef));
449 outline->common.stmtType = StmtOutlineDef;
450 outline->common.next = NULL;
451 outline->field = field;
452 outline->nPoints = 0;
453 if (points->op == ExprCoord)
455 for (pt = points; pt != NULL; pt = (ExprDef *) pt->common.next)
460 outline->points = points;
466 KeyDeclCreate(char *name, ExprDef * expr)
470 key = uTypedAlloc(KeyDef);
473 bzero(key, sizeof(KeyDef));
474 key->common.stmtType = StmtKeyDef;
475 key->common.next = NULL;
485 RowDeclCreate(KeyDef * keys)
490 row = uTypedAlloc(RowDef);
493 bzero(row, sizeof(RowDef));
494 row->common.stmtType = StmtRowDef;
495 row->common.next = NULL;
498 for (key = keys; key != NULL; key = (KeyDef *) key->common.next)
500 if (key->common.stmtType == StmtKeyDef)
508 SectionDeclCreate(uint32_t name, RowDef * rows)
513 section = uTypedAlloc(SectionDef);
516 bzero(section, sizeof(SectionDef));
517 section->common.stmtType = StmtSectionDef;
518 section->common.next = NULL;
519 section->name = name;
521 section->rows = rows;
522 for (row = rows; row != NULL; row = (RowDef *) row->common.next)
524 if (row->common.stmtType == StmtRowDef)
532 OverlayKeyCreate(char *under, char *over)
536 key = uTypedAlloc(OverlayKeyDef);
539 bzero(key, sizeof(OverlayKeyDef));
540 key->common.stmtType = StmtOverlayKeyDef;
541 strncpy(key->over, over, XkbKeyNameLength);
542 strncpy(key->under, under, XkbKeyNameLength);
552 OverlayDeclCreate(uint32_t name, OverlayKeyDef * keys)
557 ol = uTypedAlloc(OverlayDef);
560 bzero(ol, sizeof(OverlayDef));
561 ol->common.stmtType = StmtOverlayDef;
564 for (key = keys; key != NULL;
565 key = (OverlayKeyDef *) key->common.next)
574 DoodadCreate(unsigned type, uint32_t name, VarDef * body)
578 doodad = uTypedAlloc(DoodadDef);
581 bzero(doodad, sizeof(DoodadDef));
582 doodad->common.stmtType = StmtDoodadDef;
583 doodad->common.next = NULL;
592 AppendKeysymList(ExprDef * list, char *sym)
594 if (list->value.list.nSyms >= list->value.list.szSyms)
596 list->value.list.szSyms *= 2;
597 list->value.list.syms = uTypedRecalloc(list->value.list.syms,
598 list->value.list.nSyms,
599 list->value.list.szSyms,
601 if (list->value.list.syms == NULL)
603 FATAL("Couldn't resize list of symbols for append\n");
607 list->value.list.syms[list->value.list.nSyms++] = sym;
612 LookupKeysym(char *str, uint32_t * sym_rtrn)
616 if ((!str) || (uStrCaseCmp(str, "any") == 0)
617 || (uStrCaseCmp(str, "nosymbol") == 0))
619 *sym_rtrn = NoSymbol;
622 else if ((uStrCaseCmp(str, "none") == 0)
623 || (uStrCaseCmp(str, "voidsymbol") == 0))
625 *sym_rtrn = XK_VoidSymbol;
628 sym = xkb_string_to_keysym(str);
638 IncludeCreate(char *str, unsigned merge)
640 IncludeStmt *incl, *first;
641 char *file, *map, *stmt, *tmp, *extra_data;
649 stmt = _XkbDupString(str);
650 while ((tmp) && (*tmp))
652 if (XkbParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
654 if ((file == NULL) && (map == NULL))
661 first = incl = uTypedAlloc(IncludeStmt);
664 incl->next = uTypedAlloc(IncludeStmt);
669 incl->common.stmtType = StmtInclude;
670 incl->common.next = NULL;
675 incl->modifier = extra_data;
681 WSGO("Allocation failure in IncludeCreate\n");
682 ACTION("Using only part of the include\n");
686 merge = MergeAugment;
688 merge = MergeOverride;
701 ERROR("Illegal include statement \"%s\"\n", stmt);
711 free(first->modifier);
714 first->file = first->map = first->path = NULL;
725 PrintStmtAddrs(ParseCommon * stmt)
727 fprintf(stderr, "0x%x", stmt);
732 fprintf(stderr, "->0x%x", stmt->next);
737 fprintf(stderr, "\n");
742 CheckDefaultMap(XkbFile * maps)
747 for (tmp = maps, dflt = NULL; tmp != NULL;
748 tmp = (XkbFile *) tmp->common.next)
750 if (tmp->flags & XkbLC_Default)
756 if (warningLevel > 2)
758 WARN("Multiple default components in %s\n",
759 (scanFile ? scanFile : "(unknown)"));
760 ACTION("Using %s, ignoring %s\n",
761 (dflt->name ? dflt->name : "(first)"),
762 (tmp->name ? tmp->name : "(subsequent)"));
764 tmp->flags &= (~XkbLC_Default);
772 CreateXKBFile(int type, char *name, ParseCommon * defs, unsigned flags)
777 file = uTypedAlloc(XkbFile);
780 XkbcEnsureSafeMapName(name);
781 bzero(file, sizeof(XkbFile));
783 file->topName = _XkbDupString(name);
787 file->compiled = False;
794 StmtSetMerge(ParseCommon * stmt, unsigned merge)
796 if ((merge == MergeAltForm) && (stmt->stmtType != StmtKeycodeDef))
798 yyerror("illegal use of 'alternate' merge mode");
799 merge = MergeDefault;