1
/* $Xorg: parseutils.c,v 1.3 2000/08/17 19:54:33 cpqbld Exp $ */
2
/************************************************************
3
Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
5
Permission to use, copy, modify, and distribute this
6
software and its documentation for any purpose and without
7
fee is hereby granted, provided that the above copyright
8
notice appear in all copies and that both that copyright
9
notice and this permission notice appear in supporting
10
documentation, and that the name of Silicon Graphics not be
11
used in advertising or publicity pertaining to distribution
12
of the software without specific prior written permission.
13
Silicon Graphics makes no representation about the suitability
14
of this software for any purpose. It is provided "as is"
15
without any express or implied warranty.
17
SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
18
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
20
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
21
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
23
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
24
THE USE OR PERFORMANCE OF THIS SOFTWARE.
26
********************************************************/
27
/* $XFree86: xc/programs/xkbcomp/parseutils.c,v 1.5 2002/07/01 02:26:01 tsi Exp $ */
29
#define DEBUG_VAR_NOT_LOCAL
30
#define DEBUG_VAR parseDebug
31
#include "parseutils.h"
33
#include <X11/keysym.h>
34
#include <X11/extensions/XKBgeom.h>
35
#include <X11/Xalloca.h>
40
AppendStmt(ParseCommon *to,ParseCommon *append)
42
ParseCommon *start= to;
46
while ((to!=NULL) && (to->next!=NULL)) {
57
ExprCreate(unsigned op,unsigned type)
60
expr= uTypedAlloc(ExprDef);
62
expr->common.stmtType= StmtExpr;
63
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);
80
expr->common.stmtType= StmtExpr;
81
expr->common.next= NULL;
84
expr->value.child= child;
87
FATAL("Couldn't allocate expression in parser\n");
94
ExprCreateBinary(unsigned op,ExprDef *left,ExprDef *right)
97
expr= uTypedAlloc(ExprDef);
99
expr->common.stmtType= StmtExpr;
100
expr->common.next= NULL;
102
if ((op==OpAssign)||(left->type==TypeUnknown))
103
expr->type= right->type;
104
else if ((left->type==right->type)||(right->type==TypeUnknown))
105
expr->type= left->type;
106
else expr->type= TypeUnknown;
107
expr->value.binary.left= left;
108
expr->value.binary.right= right;
111
FATAL("Couldn't allocate expression in parser\n");
118
KeycodeCreate(char *name,ExprDef *value)
122
def= uTypedAlloc(KeycodeDef);
124
def->common.stmtType= StmtKeycodeDef;
125
def->common.next= NULL;
126
strncpy(def->name,name,XkbKeyNameLength);
127
def->name[XkbKeyNameLength]= '\0';
131
FATAL("Couldn't allocate key name definition in parser\n");
138
KeyAliasCreate(char *alias,char *real)
142
def= uTypedAlloc(KeyAliasDef);
144
def->common.stmtType= StmtKeyAliasDef;
145
def->common.next= NULL;
146
strncpy(def->alias,alias,XkbKeyNameLength);
147
def->alias[XkbKeyNameLength]= '\0';
148
strncpy(def->real,real,XkbKeyNameLength);
149
def->real[XkbKeyNameLength]= '\0';
152
FATAL("Couldn't allocate key alias definition in parser\n");
159
VModCreate(Atom name,ExprDef *value)
162
def= uTypedAlloc(VModDef);
164
def->common.stmtType= StmtVModDef;
165
def->common.next= NULL;
170
FATAL("Couldn't allocate variable definition in parser\n");
177
VarCreate(ExprDef *name,ExprDef *value)
180
def= uTypedAlloc(VarDef);
182
def->common.stmtType= StmtVarDef;
183
def->common.next= NULL;
188
FATAL("Couldn't allocate variable definition in parser\n");
195
BoolVarCreate(Atom nameToken,unsigned set)
197
ExprDef *name,*value;
199
name= ExprCreate(ExprIdent,TypeUnknown);
200
name->value.str= nameToken;
201
value= ExprCreate(ExprValue,TypeBoolean);
202
value->value.uval= set;
203
return VarCreate(name,value);
207
InterpCreate(KeySym sym,ExprDef *match)
211
def= uTypedAlloc(InterpDef);
213
def->common.stmtType= StmtInterpDef;
214
def->common.next= NULL;
219
FATAL("Couldn't allocate interp definition in parser\n");
226
KeyTypeCreate(Atom name,VarDef *body)
230
def= uTypedAlloc(KeyTypeDef);
232
def->common.stmtType= StmtKeyTypeDef;
233
def->common.next= NULL;
234
def->merge= MergeDefault;
239
FATAL("Couldn't allocate key type definition in parser\n");
246
SymbolsCreate(char *keyName,ExprDef *symbols)
250
def= uTypedAlloc(SymbolsDef);
252
def->common.stmtType= StmtSymbolsDef;
253
def->common.next= NULL;
254
def->merge= MergeDefault;
255
bzero(def->keyName,5);
256
strncpy(def->keyName,keyName,4);
257
def->symbols= symbols;
260
FATAL("Couldn't allocate symbols definition in parser\n");
267
GroupCompatCreate(int group,ExprDef *val)
271
def= uTypedAlloc(GroupCompatDef);
273
def->common.stmtType= StmtGroupCompatDef;
274
def->common.next= NULL;
275
def->merge= MergeDefault;
280
FATAL("Couldn't allocate group compat definition in parser\n");
287
ModMapCreate(Atom modifier,ExprDef *keys)
291
def= uTypedAlloc(ModMapDef);
293
def->common.stmtType= StmtModMapDef;
294
def->common.next= NULL;
295
def->merge= MergeDefault;
296
def->modifier= modifier;
300
FATAL("Couldn't allocate mod mask definition in parser\n");
307
IndicatorMapCreate(Atom name,VarDef *body)
309
IndicatorMapDef *def;
311
def= uTypedAlloc(IndicatorMapDef);
313
def->common.stmtType= StmtIndicatorMapDef;
314
def->common.next= NULL;
315
def->merge= MergeDefault;
320
FATAL("Couldn't allocate indicator map definition in parser\n");
327
IndicatorNameCreate(int ndx,ExprDef *name,Bool virtual)
329
IndicatorNameDef *def;
331
def= uTypedAlloc(IndicatorNameDef);
333
def->common.stmtType= StmtIndicatorNameDef;
334
def->common.next= NULL;
335
def->merge= MergeDefault;
338
def->virtual= virtual;
341
FATAL("Couldn't allocate indicator index definition in parser\n");
348
ActionCreate(Atom name,ExprDef *args)
352
act= uTypedAlloc(ExprDef);
354
act->common.stmtType= StmtExpr;
355
act->common.next= NULL;
356
act->op= ExprActionDecl;
357
act->value.action.name= name;
358
act->value.action.args= args;
361
FATAL("Couldn't allocate ActionDef in parser\n");
366
CreateKeysymList(KeySym sym)
370
def= ExprCreate(ExprKeysymList,TypeSymbols);
372
def->value.list.nSyms= 1;
373
def->value.list.szSyms= 2;
374
def->value.list.syms= uTypedCalloc(2,KeySym);
375
if (def->value.list.syms!=NULL) {
376
def->value.list.syms[0]= sym;
380
FATAL("Couldn't allocate expression for keysym list in parser\n");
385
ShapeDeclCreate(Atom name,OutlineDef *outlines)
390
shape= uTypedAlloc(ShapeDef);
392
bzero(shape,sizeof(ShapeDef));
393
shape->common.stmtType= StmtShapeDef;
394
shape->common.next= NULL;
395
shape->merge= MergeDefault;
398
shape->outlines= outlines;
399
for (ol=outlines;ol!=NULL;ol= (OutlineDef *)ol->common.next) {
408
OutlineCreate(Atom field,ExprDef *points)
410
OutlineDef * outline;
413
outline= uTypedAlloc(OutlineDef);
415
bzero(outline,sizeof(OutlineDef));
416
outline->common.stmtType= StmtOutlineDef;
417
outline->common.next= NULL;
418
outline->field= field;
420
if (points->op==ExprCoord) {
421
for (pt=points;pt!=NULL;pt= (ExprDef *)pt->common.next) {
425
outline->points= points;
431
KeyDeclCreate(char *name,ExprDef *expr)
435
key= uTypedAlloc(KeyDef);
437
bzero(key,sizeof(KeyDef));
438
key->common.stmtType= StmtKeyDef;
439
key->common.next= NULL;
440
if (name) key->name= name;
441
else key->expr= expr;
447
KeyDeclMerge(KeyDef *into,KeyDef *from)
449
into->expr= (ExprDef *)AppendStmt(&into->expr->common,&from->expr->common);
456
RowDeclCreate(KeyDef * keys)
461
row= uTypedAlloc(RowDef);
463
bzero(row,sizeof(RowDef));
464
row->common.stmtType= StmtRowDef;
465
row->common.next= NULL;
468
for (key=keys;key!=NULL;key=(KeyDef *)key->common.next) {
469
if (key->common.stmtType==StmtKeyDef)
477
SectionDeclCreate(Atom name,RowDef *rows)
479
SectionDef * section;
482
section= uTypedAlloc(SectionDef);
484
bzero(section,sizeof(SectionDef));
485
section->common.stmtType= StmtSectionDef;
486
section->common.next= NULL;
490
for (row=rows;row!=NULL;row=(RowDef *)row->common.next) {
491
if (row->common.stmtType==StmtRowDef)
499
OverlayKeyCreate(char * under,char *over)
503
key= uTypedAlloc(OverlayKeyDef);
505
bzero(key,sizeof(OverlayKeyDef));
506
key->common.stmtType= StmtOverlayKeyDef;
507
strncpy(key->over,over,XkbKeyNameLength);
508
strncpy(key->under,under,XkbKeyNameLength);
509
if (over) uFree(over);
510
if (under) uFree(under);
516
OverlayDeclCreate(Atom name,OverlayKeyDef *keys)
521
ol= uTypedAlloc(OverlayDef);
523
bzero(ol,sizeof(OverlayDef));
524
ol->common.stmtType= StmtOverlayDef;
527
for (key=keys;key!=NULL;key=(OverlayKeyDef *)key->common.next) {
535
DoodadCreate(unsigned type,Atom name,VarDef *body)
539
doodad= uTypedAlloc(DoodadDef);
541
bzero(doodad,sizeof(DoodadDef));
542
doodad->common.stmtType= StmtDoodadDef;
543
doodad->common.next= NULL;
552
AppendKeysymList(ExprDef *list,KeySym sym)
554
if (list->value.list.nSyms>=list->value.list.szSyms) {
555
list->value.list.szSyms*=2;
556
list->value.list.syms= uTypedRecalloc(list->value.list.syms,
557
list->value.list.nSyms,
558
list->value.list.szSyms,
560
if (list->value.list.syms==NULL) {
561
FATAL("Couldn't resize list of symbols for append\n");
565
list->value.list.syms[list->value.list.nSyms++]= sym;
570
LookupKeysym(char *str,KeySym *sym_rtrn)
574
if ((!str)||(uStrCaseCmp(str,"any")==0)||(uStrCaseCmp(str,"nosymbol")==0)) {
578
else if ((uStrCaseCmp(str,"none")==0)||(uStrCaseCmp(str,"voidsymbol")==0)) {
579
*sym_rtrn= XK_VoidSymbol;
582
sym= XStringToKeysym(str);
591
IncludeCreate(char *str,unsigned merge)
593
IncludeStmt * incl,*first;
594
char * file,*map,*stmt,*tmp, *extra_data;
602
stmt= uStringDup(str);
603
while ((tmp)&&(*tmp)) {
604
if (XkbParseIncludeMap(&tmp,&file,&map,&nextop,&extra_data)) {
605
if ((file==NULL)&&(map==NULL)) {
611
first= incl= uTypedAlloc(IncludeStmt);
613
incl->next= uTypedAlloc(IncludeStmt);
617
incl->common.stmtType= StmtInclude;
618
incl->common.next= NULL;
623
incl->modifier= extra_data;
628
WSGO("Allocation failure in IncludeCreate\n");
629
ACTION("Using only part of the include\n");
632
if (nextop=='|') merge= MergeAugment;
633
else merge= MergeOverride;
639
if (first) first->stmt= stmt;
640
else if (stmt) uFree(stmt);
643
ERROR1("Illegal include statement \"%s\"\n",stmt);
647
if (first->file) uFree(first->file);
648
if (first->map) uFree(first->map);
649
if (first->modifier) uFree(first->modifier);
650
if (first->path) uFree(first->path);
651
first->file= first->map= first->path= NULL;
662
PrintStmtAddrs(ParseCommon *stmt)
664
fprintf(stderr,"0x%x",stmt);
667
fprintf(stderr,"->0x%x",stmt->next);
671
fprintf(stderr,"\n");
676
CheckDefaultMap(XkbFile *maps)
681
for (tmp=maps,dflt=NULL;tmp!=NULL;tmp=(XkbFile *)tmp->common.next) {
682
if (tmp->flags&XkbLC_Default) {
686
if (warningLevel>2) {
687
WARN1("Multiple default components in %s\n",
688
(scanFile?scanFile:"(unknown)"));
689
ACTION2("Using %s, ignoring %s\n",
690
(dflt->name?dflt->name:"(first)"),
691
(tmp->name?tmp->name:"(subsequent)"));
693
tmp->flags&= (~XkbLC_Default);
701
XKBParseFile(FILE *file,XkbFile **pRtrn)
708
CheckDefaultMap(rtrnValue);
720
CreateXKBFile(int type,char *name,ParseCommon *defs,unsigned flags)
725
file= uTypedAlloc(XkbFile);
727
XkbEnsureSafeMapName(name);
728
bzero(file,sizeof(XkbFile));
730
file->topName= uStringDup(name);
734
file->compiled= False;
741
StmtSetMerge(ParseCommon *stmt,unsigned merge)
743
if ((merge==MergeAltForm) && (stmt->stmtType!=StmtKeycodeDef)) {
744
yyerror("illegal use of 'alternate' merge mode");