5
======================================================================
7
CREATOR: eric 08 Aug 2000
11
$Id: icalssyacc.y 539060 2006-05-09 15:58:38Z winterz $
14
(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
16
This program is free software; you can redistribute it and/or modify
17
it under the terms of either:
19
The LGPL as published by the Free Software Foundation, version
20
2.1, available at: http://www.fsf.org/copyleft/lesser.html
24
The Mozilla Public License Version 1.0. You may obtain a copy of
25
the License at http://www.mozilla.org/MPL/
27
The Original Code is eric. The Initial Developer of the Original
30
======================================================================*/
33
#include <string.h> /* for strdup() */
34
#include <limits.h> /* for SHRT_MAX*/
36
#include "icalgauge.h"
37
#include "icalgaugeimpl.h"
40
#define YYPARSE_PARAM yy_globals
41
#define YYLEX_PARAM yy_globals
42
#define YY_EXTRA_TYPE icalgauge_impl*
44
#define yyextra ((struct icalgauge_impl*)ssget_extra(yy_globals))
47
static void ssyacc_add_where(struct icalgauge_impl* impl, char* prop,
48
icalgaugecompare compare , char* value);
49
static void ssyacc_add_select(struct icalgauge_impl* impl, char* str1);
50
static void ssyacc_add_from(struct icalgauge_impl* impl, char* str1);
51
static void set_logic(struct icalgauge_impl* impl,icalgaugelogic l);
52
void sserror(const char *s); /* Don't know why I need this.... */
63
%token <v_string> STRING
64
%token SELECT FROM WHERE COMMA QUOTE EQUALS NOTEQUALS LESS GREATER LESSEQUALS
65
%token GREATEREQUALS AND OR EOL END IS NOT SQLNULL
69
query_min: SELECT select_list FROM from_list WHERE where_list
70
| SELECT select_list FROM from_list
78
STRING {ssyacc_add_select(yyextra,$1);}
79
| select_list COMMA STRING {ssyacc_add_select(yyextra,$3);}
84
STRING {ssyacc_add_from(yyextra,$1);}
85
| from_list COMMA STRING {ssyacc_add_from(yyextra,$3);}
90
| STRING EQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_EQUAL,$3); }
91
| STRING IS SQLNULL {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_ISNULL,""); }
92
| STRING IS NOT SQLNULL {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_ISNOTNULL,""); }
93
| STRING NOTEQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_NOTEQUAL,$3); }
94
| STRING LESS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_LESS,$3); }
95
| STRING GREATER STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_GREATER,$3); }
96
| STRING LESSEQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_LESSEQUAL,$3); }
97
| STRING GREATEREQUALS STRING {ssyacc_add_where(yyextra,$1,ICALGAUGECOMPARE_GREATEREQUAL,$3); }
101
where_clause {set_logic(yyextra,ICALGAUGELOGIC_NONE);}
102
| where_list AND where_clause {set_logic(yyextra,ICALGAUGELOGIC_AND);}
103
| where_list OR where_clause {set_logic(yyextra,ICALGAUGELOGIC_OR);}
109
static void ssyacc_add_where(struct icalgauge_impl* impl, char* str1,
110
icalgaugecompare compare , char* value_str)
113
struct icalgauge_where *where;
114
char *compstr, *propstr, *c, *s,*l;
116
if ( (where = malloc(sizeof(struct icalgauge_where))) ==0){
117
icalerror_set_errno(ICAL_NEWFAILED_ERROR);
121
memset(where,0,sizeof(struct icalgauge_where));
122
where->logic = ICALGAUGELOGIC_NONE;
123
where->compare = ICALGAUGECOMPARE_NONE;
124
where->comp = ICAL_NO_COMPONENT;
125
where->prop = ICAL_NO_PROPERTY;
127
/* remove enclosing quotes */
137
where->value = strdup(s);
139
/* Is there a period in str1 ? If so, the string specified both a
140
component and a property*/
141
if( (c = strrchr(str1,'.')) != 0){
151
/* Handle the case where a component was specified */
153
where->comp = icalenum_string_to_component_kind(compstr);
155
where->comp = ICAL_NO_COMPONENT;
158
where->prop = icalenum_string_to_property_kind(propstr);
160
where->compare = compare;
162
if(where->value == 0){
163
icalerror_set_errno(ICAL_NEWFAILED_ERROR);
168
pvl_push(impl->where,where);
171
static void set_logic(struct icalgauge_impl* impl,icalgaugelogic l)
173
pvl_elem e = pvl_tail(impl->where);
174
struct icalgauge_where *where = pvl_data(e);
182
static void ssyacc_add_select(struct icalgauge_impl* impl, char* str1)
184
char *c, *compstr, *propstr;
185
struct icalgauge_where *where;
187
/* Uses only the prop and comp fields of the where structure */
188
if ( (where = malloc(sizeof(struct icalgauge_where))) ==0){
189
icalerror_set_errno(ICAL_NEWFAILED_ERROR);
193
memset(where,0,sizeof(struct icalgauge_where));
194
where->logic = ICALGAUGELOGIC_NONE;
195
where->compare = ICALGAUGECOMPARE_NONE;
196
where->comp = ICAL_NO_COMPONENT;
197
where->prop = ICAL_NO_PROPERTY;
199
/* Is there a period in str1 ? If so, the string specified both a
200
component and a property*/
201
if( (c = strrchr(str1,'.')) != 0){
211
/* Handle the case where a component was specified */
213
where->comp = icalenum_string_to_component_kind(compstr);
215
where->comp = ICAL_NO_COMPONENT;
219
/* If the property was '*', then accept all properties */
220
if(strcmp("*",propstr) == 0) {
221
where->prop = ICAL_ANY_PROPERTY;
223
where->prop = icalenum_string_to_property_kind(propstr);
227
if(where->prop == ICAL_NO_PROPERTY){
229
icalerror_set_errno(ICAL_BADARG_ERROR);
233
pvl_push(impl->select,where);
236
static void ssyacc_add_from(struct icalgauge_impl* impl, char* str1)
238
icalcomponent_kind ckind;
240
ckind = icalenum_string_to_component_kind(str1);
242
if(ckind == ICAL_NO_COMPONENT){
246
pvl_push(impl->from,(void*)ckind);
251
void sserror(const char *s){
252
fprintf(stderr,"Parse error \'%s\'\n", s);
253
icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);