cfgparse.y revision 76910425
1/* $Xorg: cfgparse.y,v 1.3 2000/08/17 19:54:49 cpqbld Exp $ */ 2/************************************************************ 3 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc. 4 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. 16 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. 25 26 ********************************************************/ 27/* $XFree86: xc/programs/xkbevd/cfgparse.y,v 1.4tsi Exp $ */ 28 29%token 30 END_OF_FILE 0 31 ERROR 255 32 BELL 1 33 ACCESSX 2 34 MESSAGE 3 35 36 NONE 20 37 IGNORE 21 38 ECHO 22 39 PRINT_EV 23 40 SHELL 24 41 SOUND 25 42 43 EQUALS 40 44 PLUS 41 45 MINUS 42 46 DIVIDE 43 47 TIMES 44 48 OBRACE 45 49 CBRACE 46 50 OPAREN 47 51 CPAREN 48 52 OBRACKET 49 53 CBRACKET 50 54 DOT 51 55 COMMA 52 56 SEMI 53 57 EXCLAM 54 58 INVERT 55 59 STRING 60 60 INTEGER 61 61 FLOAT 62 62 IDENT 63 63 KEYNAME 64 64%{ 65#ifdef DEBUG 66#define YYDEBUG 1 67#endif 68#define DEBUG_VAR parseDebug 69#include "xkbevd.h" 70%} 71%right EQUALS 72%left PLUS MINUS 73%left TIMES DIVIDE 74%left EXCLAM INVERT 75%left OPAREN 76%start CfgFile 77%union { 78 char * str; 79 int ival; 80 CfgEntryPtr entry; 81 ActDefPtr act; 82} 83%type <str> Ident String OptString NameSpec OptNameSpec 84%type <ival> ActionType EventType 85%type <act> ActionDef 86%type <entry> CfgFile CfgEntryList CfgEntry EventDef VarDef 87%% 88CfgFile : CfgEntryList 89 { InterpretConfigs($1); } 90 ; 91 92CfgEntryList : CfgEntryList CfgEntry 93 { 94 CfgEntryPtr tmp; 95 if ($1!=NULL) { 96 for (tmp=$1;tmp->next!=NULL;tmp=tmp->next) { 97 /* conditional does the work */ 98 } 99 tmp->next= $2; 100 $$= $1; 101 } 102 else $$= $2; 103 } 104 | CfgEntry { $$= $1; } 105 ; 106 107CfgEntry : EventDef ActionDef 108 { 109 if (($1)&&($2)) 110 $1->action= *($2); 111 if ($2) 112 uFree($2); 113 $$= $1; 114 } 115 | VarDef { $$= $1; } 116 ; 117 118VarDef : Ident EQUALS NameSpec 119 { 120 CfgEntryPtr cfg; 121 cfg= uTypedCalloc(1,CfgEntryRec); 122 if (cfg) { 123 cfg->entry_type= VariableDef; 124 cfg->event_type= 0; 125 cfg->name.str= $1; 126 cfg->action.type= UnknownAction; 127 cfg->action.text= $3; 128 cfg->action.priv= 0; 129 cfg->next= NULL; 130 } 131 $$= cfg; 132 } 133 ; 134 135EventDef : EventType OPAREN OptNameSpec CPAREN 136 { 137 CfgEntryPtr cfg; 138 cfg= uTypedCalloc(1,CfgEntryRec); 139 if (cfg) { 140 cfg->entry_type= EventDef; 141 cfg->event_type= $1; 142 cfg->name.str= $3; 143 cfg->action.type= UnknownAction; 144 cfg->action.text= NULL; 145 cfg->action.priv= 0; 146 cfg->next= NULL; 147 } 148 $$= cfg; 149 } 150 ; 151 152EventType : BELL { $$= XkbBellNotify; } 153 | ACCESSX { $$= XkbAccessXNotify; } 154 | MESSAGE { $$= XkbActionMessage; } 155 ; 156 157ActionDef : ActionType OptString 158 { 159 ActDefPtr act; 160 act= uTypedCalloc(1,ActDefRec); 161 if (act) { 162 act->type= $1; 163 act->text= $2; 164 } 165 $$= act; 166 } 167 ; 168 169ActionType : NONE { $$ = NoAction; } 170 | IGNORE { $$ = NoAction; } 171 | ECHO { $$ = EchoAction; } 172 | PRINT_EV { $$ = PrintEvAction; } 173 | SHELL { $$ = ShellAction; } 174 | SOUND { $$ = SoundAction; } 175 | { $$ = UnknownAction; } 176 ; 177 178OptNameSpec : NameSpec { $$= $1; } 179 | { $$= NULL; } 180 ; 181 182NameSpec : Ident { $$= $1; } 183 | String { $$= $1; } 184 ; 185 186Ident : IDENT { $$= scanStr; scanStr= NULL; } 187 ; 188 189OptString : String { $$= $1; } 190 | { $$= NULL; } 191 ; 192 193String : STRING { $$= scanStr; scanStr= NULL; } 194 ; 195%% 196int 197yyerror(char *s) 198{ 199 (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum, 200 (scanFile?scanFile:"(unknown)")); 201 if (scanStr) 202 (void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr); 203 return 1; 204} 205 206 207int 208yywrap(void) 209{ 210 return 1; 211} 212 213int 214CFGParseFile(FILE *file) 215{ 216 if (file) { 217 yyin= file; 218 if (yyparse()==0) { 219 return 1; 220 } 221 return 0; 222 } 223 return 1; 224} 225