~ubuntu-branches/ubuntu/quantal/kdepimlibs/quantal-proposed

« back to all changes in this revision

Viewing changes to kcal/libical/src/libicalss/icalssyacc.y

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-09-06 22:45:39 UTC
  • Revision ID: james.westby@ubuntu.com-20060906224539-fiq8t03qdbqu7z3i
Tags: upstream-3.80.1
ImportĀ upstreamĀ versionĀ 3.80.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%pure_parser
 
2
 
 
3
%{
 
4
/* -*- Mode: C -*-
 
5
  ======================================================================
 
6
  FILE: icalssyacc.y
 
7
  CREATOR: eric 08 Aug 2000
 
8
  
 
9
  DESCRIPTION:
 
10
  
 
11
  $Id: icalssyacc.y 539060 2006-05-09 15:58:38Z winterz $
 
12
  $Locker:  $
 
13
 
 
14
(C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
 
15
 
 
16
 This program is free software; you can redistribute it and/or modify
 
17
 it under the terms of either: 
 
18
 
 
19
    The LGPL as published by the Free Software Foundation, version
 
20
    2.1, available at: http://www.fsf.org/copyleft/lesser.html
 
21
 
 
22
  Or:
 
23
 
 
24
    The Mozilla Public License Version 1.0. You may obtain a copy of
 
25
    the License at http://www.mozilla.org/MPL/
 
26
 
 
27
 The Original Code is eric. The Initial Developer of the Original
 
28
 Code is Eric Busboom
 
29
 
 
30
  ======================================================================*/
 
31
/*#define YYDEBUG 1*/
 
32
#include <stdlib.h>
 
33
#include <string.h> /* for strdup() */
 
34
#include <limits.h> /* for SHRT_MAX*/
 
35
#include "ical.h"
 
36
#include "icalgauge.h"
 
37
#include "icalgaugeimpl.h"
 
38
 
 
39
 
 
40
#define YYPARSE_PARAM yy_globals
 
41
#define YYLEX_PARAM yy_globals
 
42
#define YY_EXTRA_TYPE  icalgauge_impl*
 
43
  /* ick...*/
 
44
#define yyextra ((struct icalgauge_impl*)ssget_extra(yy_globals))
 
45
 
 
46
 
 
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.... */
 
53
int ssget_extra();
 
54
int sslex();
 
55
 
 
56
%}
 
57
 
 
58
%union {
 
59
        char* v_string;
 
60
}
 
61
 
 
62
 
 
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
 
66
 
 
67
%%
 
68
 
 
69
query_min: SELECT select_list FROM from_list WHERE where_list
 
70
           | SELECT select_list FROM from_list
 
71
           | error { 
 
72
                 yyclearin;
 
73
                 YYABORT;
 
74
           }    
 
75
           ;    
 
76
 
 
77
select_list:
 
78
        STRING {ssyacc_add_select(yyextra,$1);}
 
79
        | select_list COMMA STRING {ssyacc_add_select(yyextra,$3);}
 
80
        ;
 
81
 
 
82
 
 
83
from_list:
 
84
        STRING {ssyacc_add_from(yyextra,$1);}
 
85
        | from_list COMMA STRING {ssyacc_add_from(yyextra,$3);}
 
86
        ;
 
87
 
 
88
where_clause:
 
89
        /* Empty */
 
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); }
 
98
        ;
 
99
 
 
100
where_list:
 
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);}
 
104
        ;
 
105
 
 
106
 
 
107
%%
 
108
 
 
109
static void ssyacc_add_where(struct icalgauge_impl* impl, char* str1, 
 
110
        icalgaugecompare compare , char* value_str)
 
111
{
 
112
 
 
113
    struct icalgauge_where *where;
 
114
    char *compstr, *propstr, *c, *s,*l;
 
115
    
 
116
    if ( (where = malloc(sizeof(struct icalgauge_where))) ==0){
 
117
        icalerror_set_errno(ICAL_NEWFAILED_ERROR);
 
118
        return;
 
119
    }
 
120
 
 
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;
 
126
 
 
127
    /* remove enclosing quotes */
 
128
    s = value_str;
 
129
    if(*s == '\''){
 
130
        s++;
 
131
    }
 
132
    l = s+strlen(s)-1;
 
133
    if(*l == '\''){
 
134
        *l=0;
 
135
    }
 
136
        
 
137
    where->value = strdup(s);
 
138
 
 
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){
 
142
        compstr = str1;
 
143
        propstr = c+1;
 
144
        *c = '\0';
 
145
    } else {
 
146
        compstr = 0;
 
147
        propstr = str1;
 
148
    }
 
149
 
 
150
 
 
151
    /* Handle the case where a component was specified */
 
152
    if(compstr != 0){
 
153
        where->comp = icalenum_string_to_component_kind(compstr);
 
154
    } else {
 
155
        where->comp = ICAL_NO_COMPONENT;
 
156
    }
 
157
 
 
158
    where->prop = icalenum_string_to_property_kind(propstr);    
 
159
 
 
160
    where->compare = compare;
 
161
 
 
162
    if(where->value == 0){
 
163
        icalerror_set_errno(ICAL_NEWFAILED_ERROR);
 
164
        free(where->value);
 
165
        return;
 
166
    }
 
167
 
 
168
    pvl_push(impl->where,where);
 
169
}
 
170
 
 
171
static void set_logic(struct icalgauge_impl* impl,icalgaugelogic l)
 
172
{
 
173
    pvl_elem e = pvl_tail(impl->where);
 
174
    struct icalgauge_where *where = pvl_data(e);
 
175
 
 
176
    where->logic = l;
 
177
   
 
178
}
 
179
 
 
180
 
 
181
 
 
182
static void ssyacc_add_select(struct icalgauge_impl* impl, char* str1)
 
183
{
 
184
    char *c, *compstr, *propstr;
 
185
    struct icalgauge_where *where;
 
186
    
 
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);
 
190
        return;
 
191
    }
 
192
 
 
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;
 
198
 
 
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){
 
202
        compstr = str1;
 
203
        propstr = c+1;
 
204
        *c = '\0';
 
205
    } else {
 
206
        compstr = 0;
 
207
        propstr = str1;
 
208
    }
 
209
 
 
210
 
 
211
    /* Handle the case where a component was specified */
 
212
    if(compstr != 0){
 
213
        where->comp = icalenum_string_to_component_kind(compstr);
 
214
    } else {
 
215
        where->comp = ICAL_NO_COMPONENT;
 
216
    }
 
217
 
 
218
 
 
219
    /* If the property was '*', then accept all properties */
 
220
    if(strcmp("*",propstr) == 0) {
 
221
        where->prop = ICAL_ANY_PROPERTY;            
 
222
    } else {
 
223
        where->prop = icalenum_string_to_property_kind(propstr);    
 
224
    }
 
225
    
 
226
 
 
227
    if(where->prop == ICAL_NO_PROPERTY){
 
228
      free(where);
 
229
      icalerror_set_errno(ICAL_BADARG_ERROR);
 
230
      return;
 
231
    }
 
232
 
 
233
    pvl_push(impl->select,where);
 
234
}
 
235
 
 
236
static void ssyacc_add_from(struct icalgauge_impl* impl, char* str1)
 
237
{
 
238
    icalcomponent_kind ckind;
 
239
 
 
240
    ckind = icalenum_string_to_component_kind(str1);
 
241
 
 
242
    if(ckind == ICAL_NO_COMPONENT){
 
243
        assert(0);
 
244
    }
 
245
 
 
246
    pvl_push(impl->from,(void*)ckind);
 
247
 
 
248
}
 
249
 
 
250
 
 
251
void sserror(const char *s){
 
252
  fprintf(stderr,"Parse error \'%s\'\n", s);
 
253
  icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
 
254
}