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
|
%{
/* -*- Mode: C -*-
======================================================================
FILE: icalssyacc.y
CREATOR: eric 08 Aug 2000
DESCRIPTION:
$Id: icalssyacc.y,v 1.1 2000/12/11 22:06:18 federico Exp $
$Locker: $
(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
This program is free software; you can redistribute it and/or modify
it under the terms of either:
The LGPL as published by the Free Software Foundation, version
2.1, available at: http://www.fsf.org/copyleft/lesser.html
Or:
The Mozilla Public License Version 1.0. You may obtain a copy of
the License at http://www.mozilla.org/MPL/
The Original Code is eric. The Initial Developer of the Original
Code is Eric Busboom
======================================================================*/
#include <stdlib.h>
#include <string.h> /* for strdup() */
#include <limits.h> /* for SHRT_MAX*/
#include "ical.h"
#include "pvl.h"
#include "icalgaugeimpl.h"
extern struct icalgauge_impl *icalss_yy_gauge;
void ssyacc_add_where(struct icalgauge_impl* impl, char* str1,
enum icalparameter_xliccomparetype compare , char* str2);
void ssyacc_add_select(struct icalgauge_impl* impl, char* str1);
void ssyacc_add_from(struct icalgauge_impl* impl, char* str1);
void move_where(int w);
void sserror(char *s); /* Don't know why I need this.... */
%}
%union {
char* v_string;
}
%token <v_string> STRING
%token SELECT FROM WHERE COMMA EQUALS NOTEQUALS LESS GREATER LESSEQUALS
%token GREATEREQUALS AND OR EOL END
%%
query_min: SELECT select_list FROM from_list WHERE where_list
| error {
icalparser_clear_flex_input();
yyclearin;
}
;
select_list:
STRING {ssyacc_add_select(icalss_yy_gauge,$1);}
| select_list COMMA STRING {ssyacc_add_select(icalss_yy_gauge,$3);}
;
from_list:
STRING {ssyacc_add_from(icalss_yy_gauge,$1);}
| from_list COMMA STRING {ssyacc_add_from(icalss_yy_gauge,$3);}
;
where_clause:
/* Empty */
| STRING EQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_EQUAL,$3); }
| STRING NOTEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_NOTEQUAL,$3); }
| STRING LESS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_LESS,$3); }
| STRING GREATER STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_GREATER,$3); }
| STRING LESSEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_LESSEQUAL,$3); }
| STRING GREATEREQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICAL_XLICCOMPARETYPE_GREATEREQUAL,$3); }
;
where_list:
where_clause {move_where(1);}
| where_list AND where_clause {move_where(2);}
| where_list OR where_clause {move_where(3);}
;
%%
void ssyacc_add_where(struct icalgauge_impl* impl, char* str1,
enum icalparameter_xliccomparetype compare , char* str2)
{
icalproperty *p;
icalvalue *v;
icalproperty_kind kind;
kind = icalenum_string_to_property_kind(str1);
if(kind == ICAL_NO_PROPERTY){
assert(0);
}
p = icalproperty_new(kind);
v = icalvalue_new_text(str2);
if(v == 0){
assert(0);
}
icalproperty_set_value(p,v);
icalproperty_add_parameter(p,icalparameter_new_xliccomparetype(compare));
icalcomponent_add_property(impl->where,p);
}
void ssyacc_add_select(struct icalgauge_impl* impl, char* str1)
{
icalproperty *p;
icalproperty_kind pkind;
icalcomponent_kind ckind = ICAL_NO_COMPONENT;
char* c;
char* compstr;
char* propstr;
/* Is there a period in str1 ? If so, the string specified both a
component and a property*/
if( (c = strrchr(str1,'.')) != 0){
compstr = str1;
propstr = c+1;
*c = '\0';
} else {
compstr = 0;
propstr = str1;
}
/* Handle the case where a component was specified */
if(compstr != 0){
ckind = icalenum_string_to_component_kind(compstr);
if(ckind == ICAL_NO_COMPONENT){
assert(0);
}
} else {
ckind = ICAL_NO_COMPONENT;
}
/* If the property was '*', then accept all properties */
if(strcmp("*",propstr) == 0) {
pkind = ICAL_ANY_PROPERTY;
} else {
pkind = icalenum_string_to_property_kind(str1);
}
if(pkind == ICAL_NO_PROPERTY){
assert(0);
}
if(ckind == ICAL_NO_COMPONENT){
p = icalproperty_new(pkind);
assert(p!=0);
icalcomponent_add_property(impl->select,p);
} else {
icalcomponent *comp =
icalcomponent_new(ckind);
p = icalproperty_new(pkind);
assert(p!=0);
icalcomponent_add_property(comp,p);
icalcomponent_add_component(impl->select,comp);
}
}
void ssyacc_add_from(struct icalgauge_impl* impl, char* str1)
{
icalcomponent *c;
icalcomponent_kind ckind;
ckind = icalenum_string_to_component_kind(str1);
if(ckind == ICAL_NO_COMPONENT){
assert(0);
}
c = icalcomponent_new(ckind);
icalcomponent_add_component(impl->from,c);
}
void move_where(int w)
{
}
void sserror(char *s){
fprintf(stderr,"Parse error \'%s\'\n", s);
}
|