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
|
%{
/*
*
* IRBOX, an Ivy driver for infra-red remote controls
*
* Copyright 1998-1999
* Centre d'Etudes de la Navigation Aerienne
*
* This is the grammar for reading tables
*
* Authors: Stephane Chatty <chatty@cena.dgac.fr>
*
* $Id$
*
* Please refer to file version.h for the
* copyright notice regarding this software
*/
extern const char* const ResWords;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "irtable.h"
extern int yyparse ();
extern int yylex ();
extern int LineNo;
static char id_buf [1024]; /* Yeech */
static char id_list_buf [4096]; /* Barf */
static const char* filename = 0;
static IrTable* cur_table;
%}
%union {
const char *name;
int integer;
}
%token Y_NAME Y_TYPE Y_BRAND Y_EOL
%token <name> Y_ID Y_STRING
%token <integer> Y_INT
%type <name> id id_list
%%
instr_list:
/* empty */
| instr_list instr
;
id:
Y_ID
{
strcpy (id_buf, $1);
free ((char*) $1); /* was allocated by strdup in lex file */
$$ = id_buf;
}
| Y_INT
{
sprintf (id_buf, "%d", $1);
$$ = id_buf;
}
;
id_list:
id
{
strcpy (id_list_buf, $1);
$$ = $1;
}
| id_list id
{
strcat (id_list_buf, " ");
strcat (id_list_buf, $2);
$$ = id_list_buf;
}
;
instr:
Y_EOL
| Y_NAME Y_ID Y_EOL
{
IrTableName (cur_table, $2);
}
| Y_TYPE ':' Y_ID Y_EOL
{
IrTableType (cur_table, $3);
}
| Y_BRAND ':' id_list Y_EOL
{
IrTableAddBrand (cur_table, $3);
}
| id_list ':' Y_INT Y_INT Y_INT Y_INT Y_INT Y_INT Y_EOL
{
IrTableAddKey (cur_table, $1, $3, $4, $5, $6, $7, $8);
}
;
%%
#include <stdio.h>
int _DoTee = 0;
int
tee (int x)
{
if (_DoTee) {
char *s;
switch (x) {
case ':':
s = ":";
break;
case Y_EOL:
s = "Y_EOL\n";
break;
case Y_STRING:
s = "STRING";
break;
case Y_INT:
s = "INT";
break;
case Y_ID:
s = "ID";
break;
case Y_TYPE:
s = "TYPE";
break;
case Y_BRAND:
s = "BRAND";
break;
/* case Y_:
s = "";
break;
*/
default :
s = "???";
break;
}
printf ("%s ", s);
}
return x;
}
int
yyerror (const char *s)
{
fprintf (stderr, "%s in %s, line %d\n", s, filename, LineNo);
return (0);
}
int
yywrap ()
{
return 1;
}
IrTable*
IrTableReadFile (const char* file)
{
extern void LexInit ();
extern FILE *yyin;
int result;
LexInit ();
filename = file;
if (!(yyin = fopen (file,"r"))) {
char err [1024];
fprintf (stderr, "Cannot open %s\n", file);
return 0;
}
cur_table = IrCreateTable ();
if (yyparse ()) {
result = 0;
}
fclose (yyin);
return cur_table;
}
|