summaryrefslogtreecommitdiffabout
path: root/libical/src/libicalss/icalssyacc.y
Unidiff
Diffstat (limited to 'libical/src/libicalss/icalssyacc.y') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libicalss/icalssyacc.y245
1 files changed, 245 insertions, 0 deletions
diff --git a/libical/src/libicalss/icalssyacc.y b/libical/src/libicalss/icalssyacc.y
new file mode 100644
index 0000000..6482b58
--- a/dev/null
+++ b/libical/src/libicalss/icalssyacc.y
@@ -0,0 +1,245 @@
1%{
2/* -*- Mode: C -*-
3 ======================================================================
4 FILE: icalssyacc.y
5 CREATOR: eric 08 Aug 2000
6
7 DESCRIPTION:
8
9 $Id$
10 $Locker$
11
12(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of either:
16
17 The LGPL as published by the Free Software Foundation, version
18 2.1, available at: http://www.fsf.org/copyleft/lesser.html
19
20 Or:
21
22 The Mozilla Public License Version 1.0. You may obtain a copy of
23 the License at http://www.mozilla.org/MPL/
24
25 The Original Code is eric. The Initial Developer of the Original
26 Code is Eric Busboom
27
28 ======================================================================*/
29
30#include <stdlib.h>
31#include <string.h> /* for strdup() */
32#include <limits.h> /* for SHRT_MAX*/
33#include "ical.h"
34#include "pvl.h"
35#include "icalgauge.h"
36#include "icalgaugeimpl.h"
37
38
39extern struct icalgauge_impl *icalss_yy_gauge;
40
41void ssyacc_add_where(struct icalgauge_impl* impl, char* prop,
42 icalgaugecompare compare , char* value);
43void ssyacc_add_select(struct icalgauge_impl* impl, char* str1);
44void ssyacc_add_from(struct icalgauge_impl* impl, char* str1);
45void set_logic(struct icalgauge_impl* impl,icalgaugelogic l);
46void sserror(char *s); /* Don't know why I need this.... */
47
48
49
50%}
51
52%union {
53 char* v_string;
54}
55
56
57%token <v_string> STRING
58%token SELECT FROM WHERE COMMA QUOTE EQUALS NOTEQUALS LESS GREATER LESSEQUALS
59%token GREATEREQUALS AND OR EOL END
60
61%%
62
63query_min: SELECT select_list FROM from_list WHERE where_list
64 | error {
65 icalparser_clear_flex_input();
66 yyclearin;
67 }
68 ;
69
70select_list:
71 STRING {ssyacc_add_select(icalss_yy_gauge,$1);}
72 | select_list COMMA STRING {ssyacc_add_select(icalss_yy_gauge,$3);}
73 ;
74
75
76from_list:
77 STRING {ssyacc_add_from(icalss_yy_gauge,$1);}
78 | from_list COMMA STRING {ssyacc_add_from(icalss_yy_gauge,$3);}
79 ;
80
81where_clause:
82 /* Empty */
83 | STRING EQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_EQUAL,$3); }
84
85 | STRING NOTEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_NOTEQUAL,$3); }
86 | STRING LESS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_LESS,$3); }
87 | STRING GREATER STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_GREATER,$3); }
88 | STRING LESSEQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_LESSEQUAL,$3); }
89 | STRING GREATEREQUALS STRING {ssyacc_add_where(icalss_yy_gauge,$1,ICALGAUGECOMPARE_GREATEREQUAL,$3); }
90 ;
91
92where_list:
93 where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_NONE);}
94 | where_list AND where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_AND);}
95 | where_list OR where_clause {set_logic(icalss_yy_gauge,ICALGAUGELOGIC_OR);}
96 ;
97
98
99%%
100
101void ssyacc_add_where(struct icalgauge_impl* impl, char* str1,
102 icalgaugecompare compare , char* value_str)
103{
104
105 struct icalgauge_where *where;
106 char *compstr, *propstr, *c, *s,*l;
107
108 if ( (where = malloc(sizeof(struct icalgauge_where))) ==0){
109 icalerror_set_errno(ICAL_NEWFAILED_ERROR);
110 return;
111 }
112
113 memset(where,0,sizeof(struct icalgauge_where));
114 where->logic = ICALGAUGELOGIC_NONE;
115 where->compare = ICALGAUGECOMPARE_NONE;
116 where->comp = ICAL_NO_COMPONENT;
117 where->prop = ICAL_NO_PROPERTY;
118
119 /* remove enclosing quotes */
120 s = value_str;
121 if(*s == '\''){
122 s++;
123 }
124 l = s+strlen(s)-1;
125 if(*l == '\''){
126 *l=0;
127 }
128
129 where->value = strdup(s);
130
131 /* Is there a period in str1 ? If so, the string specified both a
132 component and a property*/
133 if( (c = strrchr(str1,'.')) != 0){
134 compstr = str1;
135 propstr = c+1;
136 *c = '\0';
137 } else {
138 compstr = 0;
139 propstr = str1;
140 }
141
142
143 /* Handle the case where a component was specified */
144 if(compstr != 0){
145 where->comp = icalenum_string_to_component_kind(compstr);
146 } else {
147 where->comp = ICAL_NO_COMPONENT;
148 }
149
150 where->prop = icalenum_string_to_property_kind(propstr);
151
152 where->compare = compare;
153
154 if(where->value == 0){
155 icalerror_set_errno(ICAL_NEWFAILED_ERROR);
156 free(where->value);
157 return;
158 }
159
160 pvl_push(impl->where,where);
161}
162
163void set_logic(struct icalgauge_impl* impl,icalgaugelogic l)
164{
165 pvl_elem e = pvl_tail(impl->where);
166 struct icalgauge_where *where = pvl_data(e);
167
168 where->logic = l;
169
170}
171
172
173
174void ssyacc_add_select(struct icalgauge_impl* impl, char* str1)
175{
176 char *c, *compstr, *propstr;
177 struct icalgauge_where *where;
178
179 /* Uses only the prop and comp fields of the where structure */
180 if ( (where = malloc(sizeof(struct icalgauge_where))) ==0){
181 icalerror_set_errno(ICAL_NEWFAILED_ERROR);
182 return;
183 }
184
185 memset(where,0,sizeof(struct icalgauge_where));
186 where->logic = ICALGAUGELOGIC_NONE;
187 where->compare = ICALGAUGECOMPARE_NONE;
188 where->comp = ICAL_NO_COMPONENT;
189 where->prop = ICAL_NO_PROPERTY;
190
191 /* Is there a period in str1 ? If so, the string specified both a
192 component and a property*/
193 if( (c = strrchr(str1,'.')) != 0){
194 compstr = str1;
195 propstr = c+1;
196 *c = '\0';
197 } else {
198 compstr = 0;
199 propstr = str1;
200 }
201
202
203 /* Handle the case where a component was specified */
204 if(compstr != 0){
205 where->comp = icalenum_string_to_component_kind(compstr);
206 } else {
207 where->comp = ICAL_NO_COMPONENT;
208 }
209
210
211 /* If the property was '*', then accept all properties */
212 if(strcmp("*",propstr) == 0) {
213 where->prop = ICAL_ANY_PROPERTY;
214 } else {
215 where->prop = icalenum_string_to_property_kind(propstr);
216 }
217
218
219 if(where->prop == ICAL_NO_PROPERTY){
220 icalgauge_free(where);
221 icalerror_set_errno(ICAL_BADARG_ERROR);
222 return;
223 }
224
225 pvl_push(impl->select,where);
226}
227
228void ssyacc_add_from(struct icalgauge_impl* impl, char* str1)
229{
230 icalcomponent_kind ckind;
231
232 ckind = icalenum_string_to_component_kind(str1);
233
234 if(ckind == ICAL_NO_COMPONENT){
235 assert(0);
236 }
237
238 pvl_push(impl->from,(void*)ckind);
239
240}
241
242
243void sserror(char *s){
244 fprintf(stderr,"Parse error \'%s\'\n", s);
245}