xkbevd should not try to build into a pure wayland platform.
[platform/upstream/xkbevd.git] / 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 #include <stdlib.h>
69 %}
70 %right  EQUALS
71 %left   PLUS MINUS
72 %left   TIMES DIVIDE
73 %left   EXCLAM INVERT
74 %left   OPAREN
75 %start  CfgFile
76 %union  {
77         char *          str;
78         int             ival;
79         CfgEntryPtr     entry;
80         ActDefPtr       act;
81 }
82 %type <str>     Ident String OptString NameSpec OptNameSpec
83 %type <ival>    ActionType EventType
84 %type <act>     ActionDef
85 %type <entry>   CfgFile CfgEntryList CfgEntry EventDef VarDef
86 %%
87 CfgFile         :       CfgEntryList
88                         { InterpretConfigs($1); }
89                 ;
90
91 CfgEntryList    :       CfgEntryList CfgEntry
92                         {
93                             CfgEntryPtr tmp;
94                             if ($1!=NULL) {
95                                 for (tmp=$1;tmp->next!=NULL;tmp=tmp->next) {
96                                     /* conditional does the work */
97                                 }
98                                 tmp->next= $2;
99                                 $$= $1;
100                             }
101                             else $$= $2;
102                         }
103                 |       CfgEntry { $$= $1; }
104                 ;
105
106 CfgEntry        :       EventDef ActionDef
107                         {
108                             if (($1)&&($2))
109                                 $1->action= *($2);
110                             if ($2)
111                                 free($2);
112                             $$= $1;
113                         }
114                 |       VarDef          { $$= $1; }
115                 ;
116
117 VarDef          :       Ident EQUALS NameSpec
118                         {
119                             CfgEntryPtr cfg;
120                             cfg= calloc(1,sizeof(CfgEntryRec));
121                             if (cfg) {
122                                 cfg->entry_type= VariableDef;
123                                 cfg->event_type= 0;
124                                 cfg->name.str= $1;
125                                 cfg->action.type= UnknownAction;
126                                 cfg->action.text= $3;
127                                 cfg->action.priv= 0;
128                                 cfg->next= NULL;
129                             }
130                             $$= cfg;
131                         }
132                 ;
133
134 EventDef        :       EventType OPAREN OptNameSpec CPAREN
135                         {
136                             CfgEntryPtr cfg;
137                             cfg= calloc(1,sizeof(CfgEntryRec));
138                             if (cfg) {
139                                 cfg->entry_type= EventDef;
140                                 cfg->event_type= $1;
141                                 cfg->name.str= $3;
142                                 cfg->action.type= UnknownAction;
143                                 cfg->action.text= NULL;
144                                 cfg->action.priv= 0;
145                                 cfg->next= NULL;
146                             }
147                             $$= cfg;
148                         }
149                 ;
150
151 EventType       :       BELL            { $$= XkbBellNotify; }
152                 |       ACCESSX         { $$= XkbAccessXNotify; }
153                 |       MESSAGE         { $$= XkbActionMessage; }
154                 ;
155
156 ActionDef       :       ActionType OptString
157                         {
158                             ActDefPtr act;
159                             act= calloc(1,sizeof(ActDefRec));
160                             if (act) {
161                                 act->type= $1;
162                                 act->text= $2;
163                             }
164                             $$= act;
165                         }
166                 ;
167
168 ActionType      :       NONE     { $$ = NoAction; }
169                 |       IGNORE   { $$ = NoAction; }
170                 |       ECHO     { $$ = EchoAction; }
171                 |       PRINT_EV { $$ = PrintEvAction; }
172                 |       SHELL    { $$ = ShellAction; }
173                 |       SOUND    { $$ = SoundAction; }
174                 |                { $$ = UnknownAction; }
175                 ;
176
177 OptNameSpec     :       NameSpec { $$= $1; }
178                 |                { $$= NULL; }
179                 ;
180
181 NameSpec        :       Ident   { $$= $1; }
182                 |       String  { $$= $1; }
183                 ;
184
185 Ident           :       IDENT   { $$= scanStr; scanStr= NULL; }
186                 ;
187
188 OptString       :       String  { $$= $1; }
189                 |               { $$= NULL; }
190                 ;
191
192 String          :       STRING  { $$= scanStr; scanStr= NULL; }
193                 ;
194 %%
195 int
196 yyerror(char *s)
197 {
198     (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
199                                         (scanFile?scanFile:"(unknown)"));
200     if (scanStr)
201         (void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr);
202     return 1;
203 }
204
205
206 int
207 yywrap(void)
208 {
209    return 1;
210 }
211
212 int
213 CFGParseFile(FILE *file)
214 {
215     if (file) {
216         yyin= file;
217         if (yyparse()==0) {
218             return 1;
219         }
220         return 0;
221     }
222     return 1;
223 }