Diffstat (limited to 'libical/src/libical/icalyacc.y') (more/less context) (show whitespace changes)
-rw-r--r-- | libical/src/libical/icalyacc.y | 404 |
1 files changed, 404 insertions, 0 deletions
diff --git a/libical/src/libical/icalyacc.y b/libical/src/libical/icalyacc.y new file mode 100644 index 0000000..4f53d84 --- a/dev/null +++ b/libical/src/libical/icalyacc.y | |||
@@ -0,0 +1,404 @@ | |||
1 | %{ | ||
2 | /* -*- Mode: C -*- | ||
3 | ====================================================================== | ||
4 | FILE: icalitip.y | ||
5 | CREATOR: eric 10 June 1999 | ||
6 | |||
7 | DESCRIPTION: | ||
8 | |||
9 | $Id$ | ||
10 | $Locker$ | ||
11 | |||
12 | (C) COPYRIGHT 1999 Eric Busboom | ||
13 | http://www.softwarestudio.org | ||
14 | |||
15 | The contents of this file are subject to the Mozilla Public License | ||
16 | Version 1.0 (the "License"); you may not use this file except in | ||
17 | compliance with the License. You may obtain a copy of the License at | ||
18 | http://www.mozilla.org/MPL/ | ||
19 | |||
20 | Software distributed under the License is distributed on an "AS IS" | ||
21 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
22 | the License for the specific language governing rights and | ||
23 | limitations under the License. | ||
24 | |||
25 | The original author is Eric Busboom | ||
26 | The original code is icalitip.y | ||
27 | |||
28 | |||
29 | |||
30 | =======================================================================*/ | ||
31 | |||
32 | #include <stdlib.h> | ||
33 | #include <string.h> /* for strdup() */ | ||
34 | #include "icalparser.h" | ||
35 | #include "pvl.h" | ||
36 | |||
37 | icalvalue *icalparser_yy_value; /* Current Value */ | ||
38 | |||
39 | void ical_yyerror(char* s); | ||
40 | void icalparser_clear_flex_input(); | ||
41 | int ical_yy_lex(void); | ||
42 | |||
43 | /* Globals for UTCOFFSET values */ | ||
44 | int utc; | ||
45 | int utc_b; | ||
46 | int utcsign; | ||
47 | |||
48 | /* Globals for DURATION values */ | ||
49 | struct icaldurationtype duration; | ||
50 | |||
51 | /* Globals for TRIGGER values */ | ||
52 | struct icaltriggertype trigger; | ||
53 | |||
54 | void copy_list(short* array, size_t size); | ||
55 | void add_prop(icalproperty_kind); | ||
56 | void icalparser_fill_date(struct tm* t, char* dstr); | ||
57 | void icalparser_fill_time(struct tm* t, char* tstr); | ||
58 | void set_value_type(icalvalue_kind kind); | ||
59 | void set_parser_value_state(); | ||
60 | struct icaltimetype fill_datetime(char* d, char* t); | ||
61 | void ical_yy_error(char *s); /* Don't know why I need this.... */ | ||
62 | int yylex(void); /* Or this. */ | ||
63 | |||
64 | |||
65 | |||
66 | /* Set the state of the lexer so it will interpret values ( iCAL | ||
67 | VALUEs, that is, ) correctly. */ | ||
68 | |||
69 | %} | ||
70 | |||
71 | %union { | ||
72 | float v_float; | ||
73 | int v_int; | ||
74 | char* v_string; | ||
75 | } | ||
76 | |||
77 | |||
78 | /* Renaming hack */ | ||
79 | |||
80 | /* | ||
81 | #define yymaxdepth ical_yy_maxdepth | ||
82 | #define yyparse ical_yy_parse | ||
83 | #define yyerror ical_yy_error | ||
84 | #define yylval ical_yy_lval | ||
85 | #define yychar ical_yy_char | ||
86 | #define yydebug ical_yy_debug | ||
87 | #define yypact ical_yy_pact | ||
88 | #define yyr1 ical_yy_r1 | ||
89 | #define yyr2 ical_yy_r2 | ||
90 | #define yydef ical_yy_def | ||
91 | #define yychk ical_yy_chk | ||
92 | #define yypgo ical_yy_pgo | ||
93 | #define yyact ical_yy_act | ||
94 | #define yyexca ical_yy_exca | ||
95 | #define yyerrflag ical_yy_errflag | ||
96 | #define yynerrs ical_yy_nerrs | ||
97 | #define yyps ical_yy_ps | ||
98 | #define yypv ical_yy_pv | ||
99 | #define yys ical_yy_s | ||
100 | #define yy_yys ical_yy_yys | ||
101 | #define yystate ical_yy_state | ||
102 | #define yytmp ical_yy_tmp | ||
103 | #define yyv ical_yy_v | ||
104 | #define yy_yyv ical_yy_yyv | ||
105 | #define yyval ical_yy_val | ||
106 | #define yylloc ical_yy_lloc | ||
107 | #define yyreds ical_yy_reds | ||
108 | #define yytoks ical_yy_toks | ||
109 | #define yylhs ical_yy_yylhs | ||
110 | #define yylen ical_yy_yylen | ||
111 | #define yydefred ical_yy_yydefred | ||
112 | #define yydgoto ical_yy_yydgoto | ||
113 | #define yydefred ical_yy_yydefred | ||
114 | #define yydgoto ical_yy_yydgoto | ||
115 | #define yysindex ical_yy_yysindex | ||
116 | #define yyrindex ical_yy_yyrindex | ||
117 | #define yygindex ical_yy_yygindex | ||
118 | #define yytable ical_yy_yytable | ||
119 | #define yycheck ical_yy_yycheck | ||
120 | #define yyname ical_yy_yyname | ||
121 | #define yyrule ical_yy_yyrule | ||
122 | #define yy_scan_bytes ical_yy_scan_bytes | ||
123 | #define yy_scan_string ical_yy_scan_string | ||
124 | #define yy_scan_buffer ical_yy_scan_buffer | ||
125 | */ | ||
126 | |||
127 | /* These are redefined with the -P option to flex */ | ||
128 | /* | ||
129 | #define yy_create_buffer ical_yy_create_buffer | ||
130 | #define yy_delete_buffer ical_yy_delete_buffer | ||
131 | #define yy_flex_debug ical_yy_flex_debug | ||
132 | #define yy_init_buffer ical_yy_init_buffer | ||
133 | #define yy_flush_buffer ical_yy_flush_buffer | ||
134 | #define yy_load_buffer_state ical_yy_load_buffer_state | ||
135 | #define yy_switch_to_buffer ical_yy_switch_to_buffer | ||
136 | #define yyin ical_yyin | ||
137 | #define yyleng ical_yyleng | ||
138 | #define yylex ical_yylex | ||
139 | #define yylineno ical_yylineno | ||
140 | #define yyout ical_yyout | ||
141 | #define yyrestart ical_yyrestart | ||
142 | #define yytext ical_yytext | ||
143 | #define yywrap ical_yywrap | ||
144 | */ | ||
145 | |||
146 | |||
147 | %token <v_string> DIGITS | ||
148 | %token <v_int> INTNUMBER | ||
149 | %token <v_float> FLOATNUMBER | ||
150 | %token <v_string> STRING | ||
151 | %token EOL EQUALS CHARACTER COLON COMMA SEMICOLON MINUS TIMESEPERATOR | ||
152 | |||
153 | %token TRUE FALSE | ||
154 | |||
155 | %token FREQ BYDAY BYHOUR BYMINUTE BYMONTH BYMONTHDAY BYSECOND BYSETPOS BYWEEKNO | ||
156 | %token BYYEARDAY DAILY MINUTELY MONTHLY SECONDLY WEEKLY HOURLY YEARLY | ||
157 | %token INTERVAL COUNT UNTIL WKST MO SA SU TU WE TH FR | ||
158 | |||
159 | %token BIT8 ACCEPTED ADD AUDIO BASE64 BINARY BOOLEAN BUSY BUSYTENTATIVE | ||
160 | %token BUSYUNAVAILABLE CALADDRESS CANCEL CANCELLED CHAIR CHILD COMPLETED | ||
161 | %token CONFIDENTIAL CONFIRMED COUNTER DATE DATETIME DECLINECOUNTER DECLINED | ||
162 | %token DELEGATED DISPLAY DRAFT DURATION EMAIL END FINAL FLOAT FREE GREGORIAN | ||
163 | %token GROUP INDIVIDUAL INPROCESS INTEGER NEEDSACTION NONPARTICIPANT | ||
164 | %token OPAQUE OPTPARTICIPANT PARENT PERIOD PRIVATE PROCEDURE PUBLIC PUBLISH | ||
165 | %token RECUR REFRESH REPLY REQPARTICIPANT REQUEST RESOURCE ROOM SIBLING | ||
166 | %token START TENTATIVE TEXT THISANDFUTURE THISANDPRIOR TIME TRANSPAENT | ||
167 | %token UNKNOWN UTCOFFSET XNAME | ||
168 | |||
169 | %token ALTREP CN CUTYPE DAYLIGHT DIR ENCODING EVENT FBTYPE FMTTYPE LANGUAGE | ||
170 | %token MEMBER PARTSTAT RANGE RELATED RELTYPE ROLE RSVP SENTBY STANDARD URI | ||
171 | |||
172 | %token TIME_CHAR UTC_CHAR | ||
173 | |||
174 | |||
175 | %% | ||
176 | |||
177 | value: | ||
178 | date_value | ||
179 | | datetime_value | ||
180 | | duration_value | ||
181 | | period_value | ||
182 | | utcoffset_value | ||
183 | | error { | ||
184 | icalparser_yy_value = 0; | ||
185 | icalparser_clear_flex_input(); | ||
186 | yyclearin; | ||
187 | } | ||
188 | |||
189 | |||
190 | date_value: DIGITS | ||
191 | { | ||
192 | struct icaltimetype stm; | ||
193 | |||
194 | stm = fill_datetime($1,0); | ||
195 | |||
196 | stm.hour = -1; | ||
197 | stm.minute = -1; | ||
198 | stm.second = -1; | ||
199 | stm.is_utc = 0; | ||
200 | stm.is_date = 1; | ||
201 | |||
202 | icalparser_yy_value = icalvalue_new_date(stm); | ||
203 | } | ||
204 | |||
205 | utc_char: | ||
206 | /*empty*/ {utc = 0;} | ||
207 | | UTC_CHAR {utc = 1;} | ||
208 | |||
209 | /* This is used in the period_value, where there may be two utc characters per rule. */ | ||
210 | utc_char_b: | ||
211 | /*empty*/ {utc_b = 0;} | ||
212 | | UTC_CHAR {utc_b = 1;} | ||
213 | |||
214 | datetime_value: | ||
215 | DIGITS TIME_CHAR DIGITS utc_char | ||
216 | { | ||
217 | struct icaltimetype stm; | ||
218 | stm = fill_datetime($1, $3); | ||
219 | stm.is_utc = utc; | ||
220 | stm.is_date = 0; | ||
221 | |||
222 | icalparser_yy_value = | ||
223 | icalvalue_new_datetime(stm); | ||
224 | } | ||
225 | |||
226 | |||
227 | /* Duration */ | ||
228 | |||
229 | |||
230 | dur_date: dur_day | ||
231 | | dur_day dur_time | ||
232 | |||
233 | dur_week: DIGITS 'W' | ||
234 | { | ||
235 | duration.weeks = atoi($1); | ||
236 | } | ||
237 | |||
238 | dur_time: TIME_CHAR dur_hour | ||
239 | { | ||
240 | } | ||
241 | | TIME_CHAR dur_minute | ||
242 | { | ||
243 | } | ||
244 | | TIME_CHAR dur_second | ||
245 | { | ||
246 | } | ||
247 | |||
248 | dur_hour: DIGITS 'H' | ||
249 | { | ||
250 | duration.hours = atoi($1); | ||
251 | } | ||
252 | | DIGITS 'H' dur_minute | ||
253 | { | ||
254 | duration.hours = atoi($1); | ||
255 | } | ||
256 | |||
257 | dur_minute: DIGITS 'M' | ||
258 | { | ||
259 | duration.minutes = atoi($1); | ||
260 | } | ||
261 | | DIGITS 'M' dur_second | ||
262 | { | ||
263 | duration.minutes = atoi($1); | ||
264 | } | ||
265 | |||
266 | dur_second: DIGITS 'S' | ||
267 | { | ||
268 | duration.seconds = atoi($1); | ||
269 | } | ||
270 | |||
271 | dur_day: DIGITS 'D' | ||
272 | { | ||
273 | duration.days = atoi($1); | ||
274 | } | ||
275 | |||
276 | dur_prefix: /* empty */ | ||
277 | { | ||
278 | duration.is_neg = 0; | ||
279 | } | ||
280 | | '+' | ||
281 | { | ||
282 | duration.is_neg = 0; | ||
283 | } | ||
284 | | '-' | ||
285 | { | ||
286 | duration.is_neg = 1; | ||
287 | } | ||
288 | |||
289 | duration_value: dur_prefix 'P' dur_date | ||
290 | { | ||
291 | icalparser_yy_value = icalvalue_new_duration(duration); | ||
292 | memset(&duration,0, sizeof(duration)); | ||
293 | } | ||
294 | | dur_prefix 'P' dur_time | ||
295 | { | ||
296 | icalparser_yy_value = icalvalue_new_duration(duration); | ||
297 | memset(&duration,0, sizeof(duration)); | ||
298 | } | ||
299 | | dur_prefix 'P' dur_week | ||
300 | { | ||
301 | icalparser_yy_value = icalvalue_new_duration(duration); | ||
302 | memset(&duration,0, sizeof(duration)); | ||
303 | } | ||
304 | |||
305 | |||
306 | /* Period */ | ||
307 | |||
308 | period_value: DIGITS TIME_CHAR DIGITS utc_char '/' DIGITS TIME_CHAR DIGITS utc_char_b | ||
309 | { | ||
310 | struct icalperiodtype p; | ||
311 | |||
312 | p.start = fill_datetime($1,$3); | ||
313 | p.start.is_utc = utc; | ||
314 | p.start.is_date = 0; | ||
315 | |||
316 | |||
317 | p.end = fill_datetime($6,$8); | ||
318 | p.end.is_utc = utc_b; | ||
319 | p.end.is_date = 0; | ||
320 | |||
321 | p.duration.days = -1; | ||
322 | p.duration.weeks = -1; | ||
323 | p.duration.hours = -1; | ||
324 | p.duration.minutes = -1; | ||
325 | p.duration.seconds = -1; | ||
326 | |||
327 | icalparser_yy_value = icalvalue_new_period(p); | ||
328 | } | ||
329 | | DIGITS TIME_CHAR DIGITS utc_char '/' duration_value | ||
330 | { | ||
331 | struct icalperiodtype p; | ||
332 | |||
333 | p.start = fill_datetime($1,$3); | ||
334 | p.start.is_utc = utc; | ||
335 | p.start.is_date = 0; | ||
336 | |||
337 | p.end.year = -1; | ||
338 | p.end.month = -1; | ||
339 | p.end.day = -1; | ||
340 | p.end.hour = -1; | ||
341 | p.end.minute = -1; | ||
342 | p.end.second = -1; | ||
343 | |||
344 | /* The duration_value rule setes the global 'duration' | ||
345 | variable, but it also creates a new value in | ||
346 | icalparser_yy_value. So, free that, then copy | ||
347 | 'duration' into the icalperiodtype struct. */ | ||
348 | |||
349 | p.duration = icalvalue_get_duration(icalparser_yy_value); | ||
350 | icalvalue_free(icalparser_yy_value); | ||
351 | icalparser_yy_value = 0; | ||
352 | |||
353 | icalparser_yy_value = icalvalue_new_period(p); | ||
354 | |||
355 | } | ||
356 | |||
357 | |||
358 | trigger: | ||
359 | |||
360 | |||
361 | |||
362 | /* UTC Offset */ | ||
363 | |||
364 | plusminus: '+' { utcsign = 1; } | ||
365 | | '-' { utcsign = -1; } | ||
366 | |||
367 | utcoffset_value: | ||
368 | plusminus INTNUMBER INTNUMBER | ||
369 | { | ||
370 | icalparser_yy_value = icalvalue_new_utcoffset( utcsign * ($2*3600) + ($3*60) ); | ||
371 | } | ||
372 | |||
373 | | plusminus INTNUMBER INTNUMBER INTNUMBER | ||
374 | { | ||
375 | icalparser_yy_value = icalvalue_new_utcoffset(utcsign * ($2*3600) + ($3*60) +($4)); | ||
376 | } | ||
377 | |||
378 | %% | ||
379 | |||
380 | struct icaltimetype fill_datetime(char* datestr, char* timestr) | ||
381 | { | ||
382 | struct icaltimetype stm; | ||
383 | |||
384 | memset(&stm,0,sizeof(stm)); | ||
385 | |||
386 | if (datestr != 0){ | ||
387 | sscanf(datestr,"%4d%2d%2d",&(stm.year), &(stm.month), | ||
388 | &(stm.day)); | ||
389 | } | ||
390 | |||
391 | if (timestr != 0){ | ||
392 | sscanf(timestr,"%2d%2d%2d", &(stm.hour), &(stm.minute), | ||
393 | &(stm.second)); | ||
394 | } | ||
395 | |||
396 | return stm; | ||
397 | |||
398 | } | ||
399 | |||
400 | void ical_yyerror(char* s) | ||
401 | { | ||
402 | /*fprintf(stderr,"Parse error \'%s\'\n", s);*/ | ||
403 | } | ||
404 | |||