summaryrefslogtreecommitdiff
path: root/cfgparse.y
blob: 033b752a645eff0489b65a58d848b04d120ee143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/************************************************************
 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be
 used in advertising or publicity pertaining to distribution
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.

 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
 THE USE OR PERFORMANCE OF THIS SOFTWARE.

 ********************************************************/

%token
	END_OF_FILE	0
	ERROR		255
	BELL		1
	ACCESSX		2
	MESSAGE		3

	NONE		20
	IGNORE		21
	ECHO		22
	PRINT_EV	23
	SHELL		24
	SOUND		25

	EQUALS		40
	PLUS		41
	MINUS		42
	DIVIDE		43
	TIMES		44
	OBRACE		45
	CBRACE		46
	OPAREN		47
	CPAREN		48
	OBRACKET	49
	CBRACKET	50
	DOT		51
	COMMA		52
	SEMI		53
	EXCLAM		54
	INVERT		55
	STRING		60
	INTEGER		61
	FLOAT		62
	IDENT		63
	KEYNAME		64
%{
#ifdef DEBUG
#define	YYDEBUG 1
#endif
#define	DEBUG_VAR parseDebug
#include "xkbevd.h"
#include <stdlib.h>
%}
%right	EQUALS
%left	PLUS MINUS
%left	TIMES DIVIDE
%left	EXCLAM INVERT
%left	OPAREN
%start	CfgFile
%union	{
	char *		str;
	int		ival;
	CfgEntryPtr	entry;
	ActDefPtr	act;
}
%type <str>	Ident String OptString NameSpec OptNameSpec
%type <ival>	ActionType EventType
%type <act>	ActionDef
%type <entry>	CfgFile CfgEntryList CfgEntry EventDef VarDef
%%
CfgFile		:	CfgEntryList
			{ InterpretConfigs($1); }
		;

CfgEntryList	:	CfgEntryList CfgEntry
			{
			    CfgEntryPtr tmp;
			    if ($1!=NULL) {
				for (tmp=$1;tmp->next!=NULL;tmp=tmp->next) {
				    /* conditional does the work */
				}
				tmp->next= $2;
				$$= $1;
			    }
			    else $$= $2;
			}
		|	CfgEntry { $$= $1; }
		;

CfgEntry	:	EventDef ActionDef
			{
			    if (($1)&&($2))
				$1->action= *($2);
			    if ($2)
				free($2);
			    $$= $1;
			}
		|	VarDef 		{ $$= $1; }
		;

VarDef		:	Ident EQUALS NameSpec
			{
			    CfgEntryPtr cfg;
			    cfg= calloc(1,sizeof(CfgEntryRec));
			    if (cfg) {
				cfg->entry_type= VariableDef;
				cfg->event_type= 0;
				cfg->name.str= $1;
				cfg->action.type= UnknownAction;
				cfg->action.text= $3;
				cfg->action.priv= 0;
				cfg->next= NULL;
			    }
			    $$= cfg;
			}
		;

EventDef	:	EventType OPAREN OptNameSpec CPAREN
			{
			    CfgEntryPtr cfg;
			    cfg= calloc(1,sizeof(CfgEntryRec));
			    if (cfg) {
				cfg->entry_type= EventDef;
				cfg->event_type= $1;
				cfg->name.str= $3;
				cfg->action.type= UnknownAction;
				cfg->action.text= NULL;
				cfg->action.priv= 0;
				cfg->next= NULL;
			    }
			    $$= cfg;
			}
		;

EventType	:	BELL		{ $$= XkbBellNotify; }
		|	ACCESSX		{ $$= XkbAccessXNotify; }
		|	MESSAGE		{ $$= XkbActionMessage; }
		;

ActionDef	:	ActionType OptString
			{
			    ActDefPtr act;
			    act= calloc(1,sizeof(ActDefRec));
			    if (act) {
				act->type= $1;
				act->text= $2;
			    }
			    $$= act;
			}
		;

ActionType	:	NONE	 { $$ = NoAction; }
		|	IGNORE	 { $$ = NoAction; }
		|	ECHO	 { $$ = EchoAction; }
		|	PRINT_EV { $$ = PrintEvAction; }
		|	SHELL	 { $$ = ShellAction; }
		|	SOUND	 { $$ = SoundAction; }
		|		 { $$ = UnknownAction; }
		;

OptNameSpec	:	NameSpec { $$= $1; }
		|		 { $$= NULL; }
		;

NameSpec	:	Ident	{ $$= $1; }
		|	String	{ $$= $1; }
		;

Ident		:	IDENT	{ $$= scanStr; scanStr= NULL; }
		;

OptString	:	String	{ $$= $1; }
		|		{ $$= NULL; }
		;

String		:	STRING	{ $$= scanStr; scanStr= NULL; }
		;
%%
int
yyerror(char *s)
{
    (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
					(scanFile?scanFile:"(unknown)"));
    if (scanStr)
	(void)fprintf(stderr,"last scanned symbol is: %s\n",scanStr);
    return 1;
}


int
yywrap(void)
{
   return 1;
}

int
CFGParseFile(FILE *file)
{
    if (file) {
	yyin= file;
	if (yyparse()==0) {
	    return 1;
	}
	return 0;
    }
    return 1;
}