PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/claws-mail-extra-plugins-3.8.1/vcalendar-2.0.13/libical/libical/icalyacc.y

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