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