Diffstat (limited to 'library/backend/vcc_yacc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | library/backend/vcc_yacc.cpp | 2153 |
1 files changed, 1079 insertions, 1074 deletions
diff --git a/library/backend/vcc_yacc.cpp b/library/backend/vcc_yacc.cpp index 4006bc2..bc05f87 100644 --- a/library/backend/vcc_yacc.cpp +++ b/library/backend/vcc_yacc.cpp | |||
@@ -25,210 +25,215 @@ static char yyrcsid[] = "$Id$"; | |||
25 | #define yylen vcclen | 25 | #define yylen vcclen |
26 | #define yydefred vccdefred | 26 | #define yydefred vccdefred |
27 | #define yydgoto vccdgoto | 27 | #define yydgoto vccdgoto |
28 | #define yysindex vccsindex | 28 | #define yysindex vccsindex |
29 | #define yyrindex vccrindex | 29 | #define yyrindex vccrindex |
30 | #define yygindex vccgindex | 30 | #define yygindex vccgindex |
31 | #define yytable vcctable | 31 | #define yytable vcctable |
32 | #define yycheck vcccheck | 32 | #define yycheck vcccheck |
33 | #define yyname vccname | 33 | #define yyname vccname |
34 | #define yyrule vccrule | 34 | #define yyrule vccrule |
35 | #define YYPREFIX "vcc" | 35 | #define YYPREFIX "vcc" |
36 | #line 1 "backend/vcc.y" | 36 | #line 1 "backend/vcc.y" |
37 | 37 | ||
38 | 38 | ||
39 | /*************************************************************************** | 39 | /*************************************************************************** |
40 | (C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International | 40 | (C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International |
41 | Business Machines Corporation and Siemens Rolm Communications Inc. | 41 | Business Machines Corporation and Siemens Rolm Communications Inc. |
42 | 42 | ||
43 | For purposes of this license notice, the term Licensors shall mean, | 43 | For purposes of this license notice, the term Licensors shall mean, |
44 | collectively, Apple Computer, Inc., AT&T Corp., International | 44 | collectively, Apple Computer, Inc., AT&T Corp., International |
45 | Business Machines Corporation and Siemens Rolm Communications Inc. | 45 | Business Machines Corporation and Siemens Rolm Communications Inc. |
46 | The term Licensor shall mean any of the Licensors. | 46 | The term Licensor shall mean any of the Licensors. |
47 | 47 | ||
48 | Subject to acceptance of the following conditions, permission is hereby | 48 | Subject to acceptance of the following conditions, permission is hereby |
49 | granted by Licensors without the need for written agreement and without | 49 | granted by Licensors without the need for written agreement and without |
50 | license or royalty fees, to use, copy, modify and distribute this | 50 | license or royalty fees, to use, copy, modify and distribute this |
51 | software for any purpose. | 51 | software for any purpose. |
52 | 52 | ||
53 | The above copyright notice and the following four paragraphs must be | 53 | The above copyright notice and the following four paragraphs must be |
54 | reproduced in all copies of this software and any software including | 54 | reproduced in all copies of this software and any software including |
55 | this software. | 55 | this software. |
56 | 56 | ||
57 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE | 57 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE |
58 | ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR | 58 | ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR |
59 | MODIFICATIONS. | 59 | MODIFICATIONS. |
60 | 60 | ||
61 | IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, | 61 | IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, |
62 | INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT | 62 | INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT |
63 | OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 63 | OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
64 | DAMAGE. | 64 | DAMAGE. |
65 | 65 | ||
66 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, | 66 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, |
67 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE | 67 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE |
68 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 68 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
69 | PURPOSE. | 69 | PURPOSE. |
70 | 70 | ||
71 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or | 71 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or |
72 | disclosure by the government are subject to restrictions set forth in | 72 | disclosure by the government are subject to restrictions set forth in |
73 | DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. | 73 | DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. |
74 | 74 | ||
75 | ***************************************************************************/ | 75 | ***************************************************************************/ |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * src: vcc.c | 78 | * src: vcc.c |
79 | * doc: Parser for vCard and vCalendar. Note that this code is | 79 | * doc: Parser for vCard and vCalendar. Note that this code is |
80 | * generated by a yacc parser generator. Generally it should not | 80 | * generated by a yacc parser generator. Generally it should not |
81 | * be edited by hand. The real source is vcc.y. The #line directives | 81 | * be edited by hand. The real source is vcc.y. The #line directives |
82 | * can be commented out here to make it easier to trace through | 82 | * can be commented out here to make it easier to trace through |
83 | * in a debugger. However, if a bug is found it should | 83 | * in a debugger. However, if a bug is found it should |
84 | * be fixed in vcc.y and this file regenerated. | 84 | * be fixed in vcc.y and this file regenerated. |
85 | */ | 85 | */ |
86 | 86 | ||
87 | 87 | ||
88 | /* debugging utilities */ | 88 | /* debugging utilities */ |
89 | #if __DEBUG | 89 | #if __DEBUG |
90 | #define DBG_(x) printf x | 90 | #define DBG_(x) printf x |
91 | #else | 91 | #else |
92 | #define DBG_(x) | 92 | #define DBG_(x) |
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | /**** External Functions ****/ | 95 | /**** External Functions ****/ |
96 | 96 | ||
97 | /* assign local name to parser variables and functions so that | 97 | /* assign local name to parser variables and functions so that |
98 | we can use more than one yacc based parser. | 98 | we can use more than one yacc based parser. |
99 | */ | 99 | */ |
100 | 100 | ||
101 | #if 0 | 101 | #if 0 |
102 | #define yyparse mime_parse | 102 | #define yyparse mime_parse |
103 | #define yylex mime_lex | 103 | #define yylex mime_lex |
104 | #define yyerror mime_error | 104 | #define yyerror mime_error |
105 | #define yychar mime_char | 105 | #define yychar mime_char |
106 | /* #define p_yyval p_mime_val */ | 106 | /* #define p_yyval p_mime_val */ |
107 | #undef yyval | 107 | #undef yyval |
108 | #define yyval mime_yyval | 108 | #define yyval mime_yyval |
109 | /* #define p_yylval p_mime_lval */ | 109 | /* #define p_yylval p_mime_lval */ |
110 | #undef yylval | 110 | #undef yylval |
111 | #define yylval mime_yylval | 111 | #define yylval mime_yylval |
112 | #define yydebug mime_debug | 112 | #define yydebug mime_debug |
113 | #define yynerrs mime_nerrs | 113 | #define yynerrs mime_nerrs |
114 | #define yyerrflag mime_errflag | 114 | #define yyerrflag mime_errflag |
115 | #define yyss mime_ss | 115 | #define yyss mime_ss |
116 | #define yyssp mime_ssp | 116 | #define yyssp mime_ssp |
117 | #define yyvs mime_vs | 117 | #define yyvs mime_vs |
118 | #define yyvsp mime_vsp | 118 | #define yyvsp mime_vsp |
119 | #define yylhs mime_lhs | 119 | #define yylhs mime_lhs |
120 | #define yylen mime_len | 120 | #define yylen mime_len |
121 | #define yydefred mime_defred | 121 | #define yydefred mime_defred |
122 | #define yydgoto mime_dgoto | 122 | #define yydgoto mime_dgoto |
123 | #define yysindex mime_sindex | 123 | #define yysindex mime_sindex |
124 | #define yyrindex mime_rindex | 124 | #define yyrindex mime_rindex |
125 | #define yygindex mime_gindex | 125 | #define yygindex mime_gindex |
126 | #define yytable mime_table | 126 | #define yytable mime_table |
127 | #define yycheck mime_check | 127 | #define yycheck mime_check |
128 | #define yyname mime_name | 128 | #define yyname mime_name |
129 | #define yyrule mime_rule | 129 | #define yyrule mime_rule |
130 | #ifdef YYPREFIX | 130 | #ifdef YYPREFIX |
131 | #undef YYPREFIX | 131 | #undef YYPREFIX |
132 | #endif | 132 | #endif |
133 | #define YYPREFIX "mime_" | 133 | #define YYPREFIX "mime_" |
134 | #endif | 134 | #endif |
135 | 135 | ||
136 | 136 | ||
137 | #ifndef _NO_LINE_FOLDING | 137 | #ifndef _NO_LINE_FOLDING |
138 | #define _SUPPORT_LINE_FOLDING 1 | 138 | #define _SUPPORT_LINE_FOLDING 1 |
139 | #endif | 139 | #endif |
140 | 140 | ||
141 | /* undef below if compile with MFC */ | 141 | /* undef below if compile with MFC */ |
142 | /* #define INCLUDEMFC 1 */ | 142 | /* #define INCLUDEMFC 1 */ |
143 | 143 | ||
144 | #if defined(WIN32) || defined(_WIN32) | 144 | #if defined(WIN32) || defined(_WIN32) |
145 | #ifdef INCLUDEMFC | 145 | #ifdef INCLUDEMFC |
146 | #include <afx.h> | 146 | #include <afx.h> |
147 | #endif | 147 | #endif |
148 | #endif | 148 | #endif |
149 | 149 | ||
150 | #include <string.h> | 150 | #include <string.h> |
151 | #ifndef __MWERKS__ | 151 | #ifndef __MWERKS__ |
152 | #include <stdlib.h> | 152 | #include <stdlib.h> |
153 | #endif | 153 | #endif |
154 | #include <stdio.h> | 154 | #include <stdio.h> |
155 | #include <stdlib.h> | 155 | #include <stdlib.h> |
156 | #include <ctype.h> | 156 | #include <ctype.h> |
157 | 157 | ||
158 | /*#ifdef PALMTOPCENTER */ | 158 | /*#ifdef PALMTOPCENTER |
159 | /*#include <qpe/vobject_p.h> */ | 159 | */ |
160 | /*#else */ | 160 | /*#include <qpe/vobject_p.h> |
161 | #include "vobject_p.h" | 161 | */ |
162 | /*#endif */ | 162 | /*#else |
163 | 163 | */ | |
164 | /**** Types, Constants ****/ | 164 | #include "vobject_p.h" |
165 | 165 | /*#endif | |
166 | #define YYDEBUG 0/* 1 to compile in some debugging code */ | 166 | */ |
167 | #define MAXTOKEN 256/* maximum token (line) length */ | 167 | |
168 | #define YYSTACKSIZE 100/* ~unref ? */ | 168 | /**** Types, Constants ****/ |
169 | #define MAXLEVEL 10/* max # of nested objects parseable */ | 169 | |
170 | /* (includes outermost) */ | 170 | #define YYDEBUG 0/* 1 to compile in some debugging code */ |
171 | 171 | #define MAXTOKEN 256/* maximum token (line) length */ | |
172 | 172 | #define YYSTACKSIZE 100/* ~unref ? | |
173 | /**** Global Variables ****/ | 173 | */ |
174 | int mime_lineNum, mime_numErrors; /* yyerror() can use these */ | 174 | #define MAXLEVEL 10/* max # of nested objects parseable */ |
175 | static VObject* vObjList; | 175 | /* (includes outermost) */ |
176 | static VObject *curProp; | 176 | |
177 | static VObject *curObj; | 177 | |
178 | static VObject* ObjStack[MAXLEVEL]; | 178 | /**** Global Variables ****/ |
179 | static int ObjStackTop; | 179 | int mime_lineNum, mime_numErrors; /* yyerror() can use these */ |
180 | 180 | static VObject* vObjList; | |
181 | 181 | static VObject *curProp; | |
182 | /* A helpful utility for the rest of the app. */ | 182 | static VObject *curObj; |
183 | #if __CPLUSPLUS__ | 183 | static VObject* ObjStack[MAXLEVEL]; |
184 | extern "C" { | 184 | static int ObjStackTop; |
185 | #endif | 185 | |
186 | 186 | ||
187 | extern void yyerror(char *s); | 187 | /* A helpful utility for the rest of the app. */ |
188 | 188 | #if __CPLUSPLUS__ | |
189 | #if __CPLUSPLUS__ | 189 | extern "C" { |
190 | }; | 190 | #endif |
191 | #endif | 191 | |
192 | 192 | extern void yyerror(char *s); | |
193 | int yyparse(); | 193 | |
194 | 194 | #if __CPLUSPLUS__ | |
195 | enum LexMode { | 195 | }; |
196 | L_NORMAL, | 196 | #endif |
197 | L_VCARD, | 197 | |
198 | L_VCAL, | 198 | int yyparse(); |
199 | L_VEVENT, | 199 | |
200 | L_VTODO, | 200 | enum LexMode { |
201 | L_VALUES, | 201 | L_NORMAL, |
202 | L_BASE64, | 202 | L_VCARD, |
203 | L_QUOTED_PRINTABLE | 203 | L_VCAL, |
204 | }; | 204 | L_VEVENT, |
205 | 205 | L_VTODO, | |
206 | /**** Private Forward Declarations ****/ | 206 | L_VALUES, |
207 | static int pushVObject(const char *prop); | 207 | L_BASE64, |
208 | static VObject* popVObject(); | 208 | L_QUOTED_PRINTABLE |
209 | static void lexPopMode(int top); | 209 | }; |
210 | static int lexWithinMode(enum LexMode mode); | 210 | |
211 | static void lexPushMode(enum LexMode mode); | 211 | /**** Private Forward Declarations ****/ |
212 | static void enterProps(const char *s); | 212 | static int pushVObject(const char *prop); |
213 | static void enterAttr(const char *s1, const char *s2); | 213 | static VObject* popVObject(); |
214 | static void enterValues(const char *value); | 214 | static void lexPopMode(int top); |
215 | #define mime_error yyerror | 215 | static int lexWithinMode(enum LexMode mode); |
216 | void mime_error(char *s); | 216 | static void lexPushMode(enum LexMode mode); |
217 | void mime_error_(char *s); | 217 | static void enterProps(const char *s); |
218 | 218 | static void enterAttr(const char *s1, const char *s2); | |
219 | static void enterValues(const char *value); | ||
220 | #define mime_error yyerror | ||
221 | void mime_error(char *s); | ||
222 | void mime_error_(char *s); | ||
223 | |||
219 | #line 189 "backend/vcc.y" | 224 | #line 189 "backend/vcc.y" |
220 | typedef union { | 225 | typedef union { |
221 | char *str; | 226 | char *str; |
222 | VObject *vobj; | 227 | VObject *vobj; |
223 | } YYSTYPE; | 228 | } YYSTYPE; |
224 | #line 225 "y.tab.c" | 229 | #line 225 "y.tab.c" |
225 | #define EQ 257 | 230 | #define EQ 257 |
226 | #define COLON 258 | 231 | #define COLON 258 |
227 | #define DOT 259 | 232 | #define DOT 259 |
228 | #define SEMICOLON 260 | 233 | #define SEMICOLON 260 |
229 | #define SPACE 261 | 234 | #define SPACE 261 |
230 | #define HTAB 262 | 235 | #define HTAB 262 |
231 | #define LINESEP 263 | 236 | #define LINESEP 263 |
232 | #define NEWLINE 264 | 237 | #define NEWLINE 264 |
233 | #define BEGIN_VCARD 265 | 238 | #define BEGIN_VCARD 265 |
234 | #define END_VCARD 266 | 239 | #define END_VCARD 266 |
@@ -390,862 +395,862 @@ char *vccrule[] = { | |||
390 | int yydebug; | 395 | int yydebug; |
391 | int yynerrs; | 396 | int yynerrs; |
392 | int yyerrflag; | 397 | int yyerrflag; |
393 | int yychar; | 398 | int yychar; |
394 | short *yyssp; | 399 | short *yyssp; |
395 | YYSTYPE *yyvsp; | 400 | YYSTYPE *yyvsp; |
396 | YYSTYPE yyval; | 401 | YYSTYPE yyval; |
397 | YYSTYPE yylval; | 402 | YYSTYPE yylval; |
398 | short yyss[YYSTACKSIZE]; | 403 | short yyss[YYSTACKSIZE]; |
399 | YYSTYPE yyvs[YYSTACKSIZE]; | 404 | YYSTYPE yyvs[YYSTACKSIZE]; |
400 | #define yystacksize YYSTACKSIZE | 405 | #define yystacksize YYSTACKSIZE |
401 | #line 382 "backend/vcc.y" | 406 | #line 382 "backend/vcc.y" |
402 | 407 | ||
403 | /*------------------------------------*/ | 408 | /*------------------------------------*/ |
404 | static int pushVObject(const char *prop) | 409 | static int pushVObject(const char *prop) |
405 | { | 410 | { |
406 | VObject *newObj; | 411 | VObject *newObj; |
407 | if (ObjStackTop == MAXLEVEL) | 412 | if (ObjStackTop == MAXLEVEL) |
408 | return FALSE; | 413 | return FALSE; |
409 | 414 | ||
410 | ObjStack[++ObjStackTop] = curObj; | 415 | ObjStack[++ObjStackTop] = curObj; |
411 | 416 | ||
412 | if (curObj) { | 417 | if (curObj) { |
413 | newObj = addProp(curObj,prop); | 418 | newObj = addProp(curObj,prop); |
414 | curObj = newObj; | 419 | curObj = newObj; |
415 | } | 420 | } |
416 | else | 421 | else |
417 | curObj = newVObject(prop); | 422 | curObj = newVObject(prop); |
418 | 423 | ||
419 | return TRUE; | 424 | return TRUE; |
420 | } | 425 | } |
421 | 426 | ||
422 | 427 | ||
423 | /*---------------------------------------*/ | 428 | /*---------------------------------------*/ |
424 | /* This pops the recently built vCard off the stack and returns it. */ | 429 | /* This pops the recently built vCard off the stack and returns it. */ |
425 | static VObject* popVObject() | 430 | static VObject* popVObject() |
426 | { | 431 | { |
427 | VObject *oldObj; | 432 | VObject *oldObj; |
428 | if (ObjStackTop < 0) { | 433 | if (ObjStackTop < 0) { |
429 | yyerror("pop on empty Object Stack\n"); | 434 | yyerror("pop on empty Object Stack\n"); |
430 | return 0; | 435 | return 0; |
431 | } | 436 | } |
432 | oldObj = curObj; | 437 | oldObj = curObj; |
433 | curObj = ObjStack[ObjStackTop--]; | 438 | curObj = ObjStack[ObjStackTop--]; |
434 | 439 | ||
435 | return oldObj; | 440 | return oldObj; |
436 | } | 441 | } |
437 | 442 | ||
438 | 443 | ||
439 | static void enterValues(const char *value) | 444 | static void enterValues(const char *value) |
440 | { | 445 | { |
441 | if (fieldedProp && *fieldedProp) { | 446 | if (fieldedProp && *fieldedProp) { |
442 | if (value) { | 447 | if (value) { |
443 | addPropValue(curProp,*fieldedProp,value); | 448 | addPropValue(curProp,*fieldedProp,value); |
444 | } | 449 | } |
445 | /* else this field is empty, advance to next field */ | 450 | /* else this field is empty, advance to next field */ |
446 | fieldedProp++; | 451 | fieldedProp++; |
447 | } | 452 | } |
448 | else { | 453 | else { |
449 | if (value) { | 454 | if (value) { |
450 | setVObjectStringZValue_(curProp,strdup( value )); | 455 | setVObjectStringZValue_(curProp,strdup( value )); |
451 | } | 456 | } |
452 | } | 457 | } |
453 | deleteStr(value); | 458 | deleteStr(value); |
454 | } | 459 | } |
455 | 460 | ||
456 | static void enterProps(const char *s) | 461 | static void enterProps(const char *s) |
457 | { | 462 | { |
458 | curProp = addGroup(curObj,s); | 463 | curProp = addGroup(curObj,s); |
459 | deleteStr(s); | 464 | deleteStr(s); |
460 | } | 465 | } |
461 | 466 | ||
462 | static void enterAttr(const char *s1, const char *s2) | 467 | static void enterAttr(const char *s1, const char *s2) |
463 | { | 468 | { |
464 | const char *p1, *p2=0; | 469 | const char *p1, *p2=0; |
465 | p1 = lookupProp_(s1); | 470 | p1 = lookupProp_(s1); |
466 | if (s2) { | 471 | if (s2) { |
467 | VObject *a; | 472 | VObject *a; |
468 | p2 = lookupProp_(s2); | 473 | p2 = lookupProp_(s2); |
469 | a = addProp(curProp,p1); | 474 | a = addProp(curProp,p1); |
470 | setVObjectStringZValue(a,p2); | 475 | setVObjectStringZValue(a,p2); |
471 | } | 476 | } |
472 | else | 477 | else |
473 | addProp(curProp,p1); | 478 | addProp(curProp,p1); |
474 | if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0)) | 479 | if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0)) |
475 | lexPushMode(L_BASE64); | 480 | lexPushMode(L_BASE64); |
476 | else if (qstricmp(p1,VCQuotedPrintableProp) == 0 | 481 | else if (qstricmp(p1,VCQuotedPrintableProp) == 0 |
477 | || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0)) | 482 | || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0)) |
478 | lexPushMode(L_QUOTED_PRINTABLE); | 483 | lexPushMode(L_QUOTED_PRINTABLE); |
479 | deleteStr(s1); deleteStr(s2); | 484 | deleteStr(s1); deleteStr(s2); |
480 | } | 485 | } |
481 | 486 | ||
482 | 487 | ||
483 | #define MAX_LEX_LOOKAHEAD_0 32 | 488 | #define MAX_LEX_LOOKAHEAD_0 32 |
484 | #define MAX_LEX_LOOKAHEAD 64 | 489 | #define MAX_LEX_LOOKAHEAD 64 |
485 | #define MAX_LEX_MODE_STACK_SIZE 10 | 490 | #define MAX_LEX_MODE_STACK_SIZE 10 |
486 | #define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop]) | 491 | #define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop]) |
487 | 492 | ||
488 | struct LexBuf { | 493 | struct LexBuf { |
489 | /* input */ | 494 | /* input */ |
490 | #ifdef INCLUDEMFC | 495 | #ifdef INCLUDEMFC |
491 | CFile *inputFile; | 496 | CFile *inputFile; |
492 | #else | 497 | #else |
493 | FILE *inputFile; | 498 | FILE *inputFile; |
494 | #endif | 499 | #endif |
495 | char *inputString; | 500 | char *inputString; |
496 | unsigned long curPos; | 501 | unsigned long curPos; |
497 | unsigned long inputLen; | 502 | unsigned long inputLen; |
498 | /* lookahead buffer */ | 503 | /* lookahead buffer */ |
499 | /* -- lookahead buffer is short instead of char so that EOF | 504 | /* -- lookahead buffer is short instead of char so that EOF |
500 | / can be represented correctly. | 505 | / can be represented correctly. |
501 | */ | 506 | */ |
502 | unsigned long len; | 507 | unsigned long len; |
503 | short buf[MAX_LEX_LOOKAHEAD]; | 508 | short buf[MAX_LEX_LOOKAHEAD]; |
504 | unsigned long getPtr; | 509 | unsigned long getPtr; |
505 | /* context stack */ | 510 | /* context stack */ |
506 | unsigned long lexModeStackTop; | 511 | unsigned long lexModeStackTop; |
507 | enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE]; | 512 | enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE]; |
508 | /* token buffer */ | 513 | /* token buffer */ |
509 | unsigned long maxToken; | 514 | unsigned long maxToken; |
510 | char *strs; | 515 | char *strs; |
511 | unsigned long strsLen; | 516 | unsigned long strsLen; |
512 | } lexBuf; | 517 | } lexBuf; |
513 | 518 | ||
514 | static void lexPushMode(enum LexMode mode) | 519 | static void lexPushMode(enum LexMode mode) |
515 | { | 520 | { |
516 | if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1)) | 521 | if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1)) |
517 | yyerror("lexical context stack overflow"); | 522 | yyerror("lexical context stack overflow"); |
518 | else { | 523 | else { |
519 | lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode; | 524 | lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode; |
520 | } | 525 | } |
521 | } | 526 | } |
522 | 527 | ||
523 | static void lexPopMode(int top) | 528 | static void lexPopMode(int top) |
524 | { | 529 | { |
525 | /* special case of pop for ease of error recovery -- this | 530 | /* special case of pop for ease of error recovery -- this |
526 | version will never underflow */ | 531 | version will never underflow */ |
527 | if (top) | 532 | if (top) |
528 | lexBuf.lexModeStackTop = 0; | 533 | lexBuf.lexModeStackTop = 0; |
529 | else | 534 | else |
530 | if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--; | 535 | if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--; |
531 | } | 536 | } |
532 | 537 | ||
533 | static int lexWithinMode(enum LexMode mode) { | 538 | static int lexWithinMode(enum LexMode mode) { |
534 | unsigned long i; | 539 | unsigned long i; |
535 | for (i=0;i<lexBuf.lexModeStackTop;i++) | 540 | for (i=0;i<lexBuf.lexModeStackTop;i++) |
536 | if (mode == lexBuf.lexModeStack[i]) return 1; | 541 | if (mode == lexBuf.lexModeStack[i]) return 1; |
537 | return 0; | 542 | return 0; |
538 | } | 543 | } |
539 | 544 | ||
540 | static int lexGetc_() | 545 | static int lexGetc_() |
541 | { | 546 | { |
542 | /* get next char from input, no buffering. */ | 547 | /* get next char from input, no buffering. */ |
543 | if (lexBuf.curPos == lexBuf.inputLen) | 548 | if (lexBuf.curPos == lexBuf.inputLen) |
544 | return EOF; | 549 | return EOF; |
545 | else if (lexBuf.inputString) | 550 | else if (lexBuf.inputString) |
546 | return *(lexBuf.inputString + lexBuf.curPos++); | 551 | return *(lexBuf.inputString + lexBuf.curPos++); |
547 | else { | 552 | else { |
548 | #ifdef INCLUDEMFC | 553 | #ifdef INCLUDEMFC |
549 | char result; | 554 | char result; |
550 | return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF; | 555 | return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF; |
551 | #else | 556 | #else |
552 | return fgetc(lexBuf.inputFile); | 557 | return fgetc(lexBuf.inputFile); |
553 | #endif | 558 | #endif |
554 | } | 559 | } |
555 | } | 560 | } |
556 | 561 | ||
557 | static int lexGeta() | 562 | static int lexGeta() |
558 | { | 563 | { |
559 | ++lexBuf.len; | 564 | ++lexBuf.len; |
560 | return (lexBuf.buf[lexBuf.getPtr] = lexGetc_()); | 565 | return (lexBuf.buf[lexBuf.getPtr] = lexGetc_()); |
561 | } | 566 | } |
562 | 567 | ||
563 | static int lexGeta_(int i) | 568 | static int lexGeta_(int i) |
564 | { | 569 | { |
565 | ++lexBuf.len; | 570 | ++lexBuf.len; |
566 | return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_()); | 571 | return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_()); |
567 | } | 572 | } |
568 | 573 | ||
569 | static void lexSkipLookahead() { | 574 | static void lexSkipLookahead() { |
570 | if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { | 575 | if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { |
571 | /* don't skip EOF. */ | 576 | /* don't skip EOF. */ |
572 | lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; | 577 | lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; |
573 | lexBuf.len--; | 578 | lexBuf.len--; |
574 | } | 579 | } |
575 | } | 580 | } |
576 | 581 | ||
577 | static int lexLookahead() { | 582 | static int lexLookahead() { |
578 | int c = (lexBuf.len)? | 583 | int c = (lexBuf.len)? |
579 | lexBuf.buf[lexBuf.getPtr]: | 584 | lexBuf.buf[lexBuf.getPtr]: |
580 | lexGeta(); | 585 | lexGeta(); |
581 | /* do the \r\n -> \n or \r -> \n translation here */ | 586 | /* do the \r\n -> \n or \r -> \n translation here */ |
582 | if (c == '\r') { | 587 | if (c == '\r') { |
583 | int a = (lexBuf.len>1)? | 588 | int a = (lexBuf.len>1)? |
584 | lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]: | 589 | lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]: |
585 | lexGeta_(1); | 590 | lexGeta_(1); |
586 | if (a == '\n') { | 591 | if (a == '\n') { |
587 | lexSkipLookahead(); | 592 | lexSkipLookahead(); |
588 | } | 593 | } |
589 | lexBuf.buf[lexBuf.getPtr] = c = '\n'; | 594 | lexBuf.buf[lexBuf.getPtr] = c = '\n'; |
590 | } | 595 | } |
591 | else if (c == '\n') { | 596 | else if (c == '\n') { |
592 | int a = (lexBuf.len>1)? | 597 | int a = (lexBuf.len>1)? |
593 | lexBuf.buf[lexBuf.getPtr+1]: | 598 | lexBuf.buf[lexBuf.getPtr+1]: |
594 | lexGeta_(1); | 599 | lexGeta_(1); |
595 | if (a == '\r') { | 600 | if (a == '\r') { |
596 | lexSkipLookahead(); | 601 | lexSkipLookahead(); |
597 | } | 602 | } |
598 | lexBuf.buf[lexBuf.getPtr] = '\n'; | 603 | lexBuf.buf[lexBuf.getPtr] = '\n'; |
599 | } | 604 | } |
600 | return c; | 605 | return c; |
601 | } | 606 | } |
602 | 607 | ||
603 | static int lexGetc() { | 608 | static int lexGetc() { |
604 | int c = lexLookahead(); | 609 | int c = lexLookahead(); |
605 | if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { | 610 | if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { |
606 | /* EOF will remain in lookahead buffer */ | 611 | /* EOF will remain in lookahead buffer */ |
607 | lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; | 612 | lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; |
608 | lexBuf.len--; | 613 | lexBuf.len--; |
609 | } | 614 | } |
610 | return c; | 615 | return c; |
611 | } | 616 | } |
612 | 617 | ||
613 | static void lexSkipLookaheadWord() { | 618 | static void lexSkipLookaheadWord() { |
614 | if (lexBuf.strsLen <= lexBuf.len) { | 619 | if (lexBuf.strsLen <= lexBuf.len) { |
615 | lexBuf.len -= lexBuf.strsLen; | 620 | lexBuf.len -= lexBuf.strsLen; |
616 | lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; | 621 | lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; |
617 | } | 622 | } |
618 | } | 623 | } |
619 | 624 | ||
620 | static void lexClearToken() | 625 | static void lexClearToken() |
621 | { | 626 | { |
622 | lexBuf.strsLen = 0; | 627 | lexBuf.strsLen = 0; |
623 | } | 628 | } |
624 | 629 | ||
625 | static void lexAppendc(int c) | 630 | static void lexAppendc(int c) |
626 | { | 631 | { |
627 | lexBuf.strs[lexBuf.strsLen] = c; | 632 | lexBuf.strs[lexBuf.strsLen] = c; |
628 | /* append up to zero termination */ | 633 | /* append up to zero termination */ |
629 | if (c == 0) return; | 634 | if (c == 0) return; |
630 | lexBuf.strsLen++; | 635 | lexBuf.strsLen++; |
631 | if (lexBuf.strsLen > lexBuf.maxToken) { | 636 | if (lexBuf.strsLen > lexBuf.maxToken) { |
632 | /* double the token string size */ | 637 | /* double the token string size */ |
633 | lexBuf.maxToken <<= 1; | 638 | lexBuf.maxToken <<= 1; |
634 | lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken); | 639 | lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken); |
635 | } | 640 | } |
636 | } | 641 | } |
637 | 642 | ||
638 | static char* lexStr() { | 643 | static char* lexStr() { |
639 | return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); | 644 | return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); |
640 | } | 645 | } |
641 | 646 | ||
642 | static void lexSkipWhite() { | 647 | static void lexSkipWhite() { |
643 | int c = lexLookahead(); | 648 | int c = lexLookahead(); |
644 | while (c == ' ' || c == '\t') { | 649 | while (c == ' ' || c == '\t') { |
645 | lexSkipLookahead(); | 650 | lexSkipLookahead(); |
646 | c = lexLookahead(); | 651 | c = lexLookahead(); |
647 | } | 652 | } |
648 | } | 653 | } |
649 | 654 | ||
650 | static char* lexGetWord() { | 655 | static char* lexGetWord() { |
651 | int c; | 656 | int c; |
652 | lexSkipWhite(); | 657 | lexSkipWhite(); |
653 | lexClearToken(); | 658 | lexClearToken(); |
654 | c = lexLookahead(); | 659 | c = lexLookahead(); |
655 | while (c != EOF && !strchr("\t\n ;:=",c)) { | 660 | while (c != EOF && !strchr("\t\n ;:=",c)) { |
656 | lexAppendc(c); | 661 | lexAppendc(c); |
657 | lexSkipLookahead(); | 662 | lexSkipLookahead(); |
658 | c = lexLookahead(); | 663 | c = lexLookahead(); |
659 | } | 664 | } |
660 | lexAppendc(0); | 665 | lexAppendc(0); |
661 | return lexStr(); | 666 | return lexStr(); |
662 | } | 667 | } |
663 | 668 | ||
664 | static void lexPushLookaheadc(int c) { | 669 | static void lexPushLookaheadc(int c) { |
665 | int putptr; | 670 | int putptr; |
666 | /* can't putback EOF, because it never leaves lookahead buffer */ | 671 | /* can't putback EOF, because it never leaves lookahead buffer */ |
667 | if (c == EOF) return; | 672 | if (c == EOF) return; |
668 | putptr = (int)lexBuf.getPtr - 1; | 673 | putptr = (int)lexBuf.getPtr - 1; |
669 | if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; | 674 | if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; |
670 | lexBuf.getPtr = putptr; | 675 | lexBuf.getPtr = putptr; |
671 | lexBuf.buf[putptr] = c; | 676 | lexBuf.buf[putptr] = c; |
672 | lexBuf.len += 1; | 677 | lexBuf.len += 1; |
673 | } | 678 | } |
674 | 679 | ||
675 | static char* lexLookaheadWord() { | 680 | static char* lexLookaheadWord() { |
676 | /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 | 681 | /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 |
677 | / and thing bigger than that will stop the lookahead and return 0; | 682 | / and thing bigger than that will stop the lookahead and return 0; |
678 | / leading white spaces are not recoverable. | 683 | / leading white spaces are not recoverable. |
679 | */ | 684 | */ |
680 | int c; | 685 | int c; |
681 | int len = 0; | 686 | int len = 0; |
682 | int curgetptr = 0; | 687 | int curgetptr = 0; |
683 | lexSkipWhite(); | 688 | lexSkipWhite(); |
684 | lexClearToken(); | 689 | lexClearToken(); |
685 | curgetptr = (int)lexBuf.getPtr;// remember! | 690 | curgetptr = (int)lexBuf.getPtr;// remember! |
686 | while (len < (MAX_LEX_LOOKAHEAD_0)) { | 691 | while (len < (MAX_LEX_LOOKAHEAD_0)) { |
687 | c = lexGetc(); | 692 | c = lexGetc(); |
688 | len++; | 693 | len++; |
689 | if (c == EOF || strchr("\t\n ;:=", c)) { | 694 | if (c == EOF || strchr("\t\n ;:=", c)) { |
690 | lexAppendc(0); | 695 | lexAppendc(0); |
691 | /* restore lookahead buf. */ | 696 | /* restore lookahead buf. */ |
692 | lexBuf.len += len; | 697 | lexBuf.len += len; |
693 | lexBuf.getPtr = curgetptr; | 698 | lexBuf.getPtr = curgetptr; |
694 | return lexStr(); | 699 | return lexStr(); |
695 | } | 700 | } |
696 | else | 701 | else |
697 | lexAppendc(c); | 702 | lexAppendc(c); |
698 | } | 703 | } |
699 | lexBuf.len += len;/* char that has been moved to lookahead buffer */ | 704 | lexBuf.len += len;/* char that has been moved to lookahead buffer */ |
700 | lexBuf.getPtr = curgetptr; | 705 | lexBuf.getPtr = curgetptr; |
701 | return 0; | 706 | return 0; |
702 | } | 707 | } |
703 | 708 | ||
704 | #ifdef _SUPPORT_LINE_FOLDING | 709 | #ifdef _SUPPORT_LINE_FOLDING |
705 | static void handleMoreRFC822LineBreak(int c) { | 710 | static void handleMoreRFC822LineBreak(int c) { |
706 | /* suport RFC 822 line break in cases like | 711 | /* suport RFC 822 line break in cases like |
707 | *ADR: foo; | 712 | *ADR: foo; |
708 | * morefoo; | 713 | * morefoo; |
709 | * more foo; | 714 | * more foo; |
710 | */ | 715 | */ |
711 | if (c == ';') { | 716 | if (c == ';') { |
712 | int a; | 717 | int a; |
713 | lexSkipLookahead(); | 718 | lexSkipLookahead(); |
714 | /* skip white spaces */ | 719 | /* skip white spaces */ |
715 | a = lexLookahead(); | 720 | a = lexLookahead(); |
716 | while (a == ' ' || a == '\t') { | 721 | while (a == ' ' || a == '\t') { |
717 | lexSkipLookahead(); | 722 | lexSkipLookahead(); |
718 | a = lexLookahead(); | 723 | a = lexLookahead(); |
719 | } | 724 | } |
720 | if (a == '\n') { | 725 | if (a == '\n') { |
721 | lexSkipLookahead(); | 726 | lexSkipLookahead(); |
722 | a = lexLookahead(); | 727 | a = lexLookahead(); |
723 | if (a == ' ' || a == '\t') { | 728 | if (a == ' ' || a == '\t') { |
724 | /* continuation, throw away all the \n and spaces read so | 729 | /* continuation, throw away all the \n and spaces read so |
725 | * far | 730 | * far |
726 | */ | 731 | */ |
727 | lexSkipWhite(); | 732 | lexSkipWhite(); |
728 | lexPushLookaheadc(';'); | 733 | lexPushLookaheadc(';'); |
729 | } | 734 | } |
730 | else { | 735 | else { |
731 | lexPushLookaheadc('\n'); | 736 | lexPushLookaheadc('\n'); |
732 | lexPushLookaheadc(';'); | 737 | lexPushLookaheadc(';'); |
733 | } | 738 | } |
734 | } | 739 | } |
735 | else { | 740 | else { |
736 | lexPushLookaheadc(';'); | 741 | lexPushLookaheadc(';'); |
737 | } | 742 | } |
738 | } | 743 | } |
739 | } | 744 | } |
740 | 745 | ||
741 | static char* lexGet1Value() { | 746 | static char* lexGet1Value() { |
742 | int c; | 747 | int c; |
743 | lexSkipWhite(); | 748 | lexSkipWhite(); |
744 | c = lexLookahead(); | 749 | c = lexLookahead(); |
745 | lexClearToken(); | 750 | lexClearToken(); |
746 | while (c != EOF && (c != ';' || !fieldedProp)) { | 751 | while (c != EOF && (c != ';' || !fieldedProp)) { |
747 | if (c == '\\' ) { | 752 | if (c == '\\' ) { |
748 | int a; | 753 | int a; |
749 | lexSkipLookahead(); | 754 | lexSkipLookahead(); |
750 | a = lexLookahead(); | 755 | a = lexLookahead(); |
751 | if ( a == ';' ) { | 756 | if ( a == ';' ) { |
752 | lexAppendc( ';' ); | 757 | lexAppendc( ';' ); |
753 | lexSkipLookahead(); | 758 | lexSkipLookahead(); |
754 | } else if ( a == '\n' ) { | 759 | } else if ( a == '\n' ) { |
755 | lexAppendc( '\n' ); | 760 | lexAppendc( '\n' ); |
756 | lexSkipLookahead(); | 761 | lexSkipLookahead(); |
757 | } else if ( a == '\\' ) { | 762 | } else if ( a == '\\' ) { |
758 | lexAppendc( '\\' ); | 763 | lexAppendc( '\\' ); |
759 | lexSkipLookahead(); | 764 | lexSkipLookahead(); |
760 | } else { | 765 | } else { |
761 | lexAppendc('\\'); | 766 | lexAppendc('\\'); |
762 | } | 767 | } |
763 | } else if (c == '\n') { | 768 | } else if (c == '\n') { |
764 | int a; | 769 | int a; |
765 | lexSkipLookahead(); | 770 | lexSkipLookahead(); |
766 | a = lexLookahead(); | 771 | a = lexLookahead(); |
767 | if (a == ' ' || a == '\t') { | 772 | if (a == ' ' || a == '\t') { |
768 | lexAppendc(' '); | 773 | lexAppendc(' '); |
769 | lexSkipLookahead(); | 774 | lexSkipLookahead(); |
770 | } | 775 | } |
771 | else { | 776 | else { |
772 | lexPushLookaheadc('\n'); | 777 | lexPushLookaheadc('\n'); |
773 | break; | 778 | break; |
774 | } | 779 | } |
775 | } | 780 | } |
776 | else { | 781 | else { |
777 | lexAppendc(c); | 782 | lexAppendc(c); |
778 | lexSkipLookahead(); | 783 | lexSkipLookahead(); |
779 | } | 784 | } |
780 | c = lexLookahead(); | 785 | c = lexLookahead(); |
781 | } | 786 | } |
782 | lexAppendc(0); | 787 | lexAppendc(0); |
783 | handleMoreRFC822LineBreak(c); | 788 | handleMoreRFC822LineBreak(c); |
784 | return c==EOF?0:lexStr(); | 789 | return c==EOF?0:lexStr(); |
785 | } | 790 | } |
786 | #endif | 791 | #endif |
787 | 792 | ||
788 | static int match_begin_name(int end) { | 793 | static int match_begin_name(int end) { |
789 | char *n = lexLookaheadWord(); | 794 | char *n = lexLookaheadWord(); |
790 | int token = ID; | 795 | int token = ID; |
791 | if (n) { | 796 | if (n) { |
792 | if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD; | 797 | if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD; |
793 | else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL; | 798 | else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL; |
794 | else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT; | 799 | else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT; |
795 | else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO; | 800 | else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO; |
796 | deleteStr(n); | 801 | deleteStr(n); |
797 | return token; | 802 | return token; |
798 | } | 803 | } |
799 | return 0; | 804 | return 0; |
800 | } | 805 | } |
801 | 806 | ||
802 | 807 | ||
803 | #ifdef INCLUDEMFC | 808 | #ifdef INCLUDEMFC |
804 | void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile) | 809 | void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile) |
805 | #else | 810 | #else |
806 | void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) | 811 | void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) |
807 | #endif | 812 | #endif |
808 | { | 813 | { |
809 | // initialize lex mode stack | 814 | // initialize lex mode stack |
810 | lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL; | 815 | lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL; |
811 | 816 | ||
812 | // iniatialize lex buffer. | 817 | // iniatialize lex buffer. |
813 | lexBuf.inputString = (char*) inputstring; | 818 | lexBuf.inputString = (char*) inputstring; |
814 | lexBuf.inputLen = inputlen; | 819 | lexBuf.inputLen = inputlen; |
815 | lexBuf.curPos = 0; | 820 | lexBuf.curPos = 0; |
816 | lexBuf.inputFile = inputfile; | 821 | lexBuf.inputFile = inputfile; |
817 | 822 | ||
818 | lexBuf.len = 0; | 823 | lexBuf.len = 0; |
819 | lexBuf.getPtr = 0; | 824 | lexBuf.getPtr = 0; |
820 | 825 | ||
821 | lexBuf.maxToken = MAXTOKEN; | 826 | lexBuf.maxToken = MAXTOKEN; |
822 | lexBuf.strs = (char*)malloc(MAXTOKEN); | 827 | lexBuf.strs = (char*)malloc(MAXTOKEN); |
823 | lexBuf.strsLen = 0; | 828 | lexBuf.strsLen = 0; |
824 | 829 | ||
825 | } | 830 | } |
826 | 831 | ||
827 | static void finiLex() { | 832 | static void finiLex() { |
828 | free(lexBuf.strs); | 833 | free(lexBuf.strs); |
829 | } | 834 | } |
830 | 835 | ||
831 | 836 | ||
832 | /*-----------------------------------*/ | 837 | /*-----------------------------------*/ |
833 | /* This parses and converts the base64 format for binary encoding into | 838 | /* This parses and converts the base64 format for binary encoding into |
834 | * a decoded buffer (allocated with new). See RFC 1521. | 839 | * a decoded buffer (allocated with new). See RFC 1521. |
835 | */ | 840 | */ |
836 | static int lexGetDataFromBase64() | 841 | static int lexGetDataFromBase64() |
837 | { | 842 | { |
838 | unsigned long bytesLen = 0, bytesMax = 0; | 843 | unsigned long bytesLen = 0, bytesMax = 0; |
839 | int quadIx = 0, pad = 0; | 844 | int quadIx = 0, pad = 0; |
840 | unsigned long trip = 0; | 845 | unsigned long trip = 0; |
841 | unsigned char b; | 846 | unsigned char b; |
842 | int c; | 847 | int c; |
843 | unsigned char *bytes = NULL; | 848 | unsigned char *bytes = NULL; |
844 | unsigned char *oldBytes = NULL; | 849 | unsigned char *oldBytes = NULL; |
845 | 850 | ||
846 | DBG_(("db: lexGetDataFromBase64\n")); | 851 | DBG_(("db: lexGetDataFromBase64\n")); |
847 | while (1) { | 852 | while (1) { |
848 | c = lexGetc(); | 853 | c = lexGetc(); |
849 | lexSkipWhite(); | 854 | lexSkipWhite(); |
850 | if (c == '\n') { | 855 | if (c == '\n') { |
851 | ++mime_lineNum; | 856 | ++mime_lineNum; |
852 | if (lexLookahead() == '\n') { | 857 | if (lexLookahead() == '\n') { |
853 | /* a '\n' character by itself means end of data */ | 858 | /* a '\n' character by itself means end of data */ |
854 | break; | 859 | break; |
855 | } | 860 | } |
856 | else continue; /* ignore '\n' */ | 861 | else continue; /* ignore '\n' */ |
857 | } | 862 | } |
858 | else { | 863 | else { |
859 | if ((c >= 'A') && (c <= 'Z')) | 864 | if ((c >= 'A') && (c <= 'Z')) |
860 | b = (unsigned char)(c - 'A'); | 865 | b = (unsigned char)(c - 'A'); |
861 | else if ((c >= 'a') && (c <= 'z')) | 866 | else if ((c >= 'a') && (c <= 'z')) |
862 | b = (unsigned char)(c - 'a') + 26; | 867 | b = (unsigned char)(c - 'a') + 26; |
863 | else if ((c >= '0') && (c <= '9')) | 868 | else if ((c >= '0') && (c <= '9')) |
864 | b = (unsigned char)(c - '0') + 52; | 869 | b = (unsigned char)(c - '0') + 52; |
865 | else if (c == '+') | 870 | else if (c == '+') |
866 | b = 62; | 871 | b = 62; |
867 | else if (c == '/') | 872 | else if (c == '/') |
868 | b = 63; | 873 | b = 63; |
869 | else if (c == '=') { | 874 | else if (c == '=') { |
870 | b = 0; | 875 | b = 0; |
871 | pad++; | 876 | pad++; |
872 | } else { /* error condition */ | 877 | } else { /* error condition */ |
873 | if (bytes) free(bytes); | 878 | if (bytes) free(bytes); |
874 | else if (oldBytes) free(oldBytes); | 879 | else if (oldBytes) free(oldBytes); |
875 | // error recovery: skip until 2 adjacent newlines. | 880 | // error recovery: skip until 2 adjacent newlines. |
876 | DBG_(("db: invalid character 0x%x '%c'\n", c,c)); | 881 | DBG_(("db: invalid character 0x%x '%c'\n", c,c)); |
877 | if (c != EOF) { | 882 | if (c != EOF) { |
878 | c = lexGetc(); | 883 | c = lexGetc(); |
879 | while (c != EOF) { | 884 | while (c != EOF) { |
880 | if (c == '\n') { | 885 | if (c == '\n') { |
881 | lexSkipWhite(); | 886 | lexSkipWhite(); |
882 | if(lexLookahead() == '\n') { | 887 | if(lexLookahead() == '\n') { |
883 | ++mime_lineNum; | 888 | ++mime_lineNum; |
884 | break; | 889 | break; |
885 | } | 890 | } |
886 | } | 891 | } |
887 | c = lexGetc(); | 892 | c = lexGetc(); |
888 | } | 893 | } |
889 | } | 894 | } |
890 | return c != EOF; | 895 | return c != EOF; |
891 | } | 896 | } |
892 | trip = (trip << 6) | b; | 897 | trip = (trip << 6) | b; |
893 | if (++quadIx == 4) { | 898 | if (++quadIx == 4) { |
894 | unsigned char outBytes[3]; | 899 | unsigned char outBytes[3]; |
895 | int numOut; | 900 | int numOut; |
896 | int i; | 901 | int i; |
897 | for (i = 0; i < 3; i++) { | 902 | for (i = 0; i < 3; i++) { |
898 | outBytes[2-i] = (unsigned char)(trip & 0xFF); | 903 | outBytes[2-i] = (unsigned char)(trip & 0xFF); |
899 | trip >>= 8; | 904 | trip >>= 8; |
900 | } | 905 | } |
901 | numOut = 3 - pad; | 906 | numOut = 3 - pad; |
902 | if (bytesLen + numOut > bytesMax) { | 907 | if (bytesLen + numOut > bytesMax) { |
903 | if (!bytes) { | 908 | if (!bytes) { |
904 | bytesMax = 1024; | 909 | bytesMax = 1024; |
905 | bytes = (unsigned char*)malloc((size_t)bytesMax); | 910 | bytes = (unsigned char*)malloc((size_t)bytesMax); |
906 | } | 911 | } |
907 | else { | 912 | else { |
908 | bytesMax <<= 2; | 913 | bytesMax <<= 2; |
909 | oldBytes = bytes; | 914 | oldBytes = bytes; |
910 | bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax); | 915 | bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax); |
911 | } | 916 | } |
912 | if (bytes == 0) { | 917 | if (bytes == 0) { |
913 | mime_error("out of memory while processing BASE64 data\n"); | 918 | mime_error("out of memory while processing BASE64 data\n"); |
914 | } | 919 | } |
915 | } | 920 | } |
916 | if (bytes) { | 921 | if (bytes) { |
917 | memcpy(bytes + bytesLen, outBytes, numOut); | 922 | memcpy(bytes + bytesLen, outBytes, numOut); |
918 | bytesLen += numOut; | 923 | bytesLen += numOut; |
919 | } | 924 | } |
920 | trip = 0; | 925 | trip = 0; |
921 | quadIx = 0; | 926 | quadIx = 0; |
922 | } | 927 | } |
923 | } | 928 | } |
924 | } /* while */ | 929 | } /* while */ |
925 | DBG_(("db: bytesLen = %d\n", bytesLen)); | 930 | DBG_(("db: bytesLen = %d\n", bytesLen)); |
926 | /* kludge: all this won't be necessary if we have tree form | 931 | /* kludge: all this won't be necessary if we have tree form |
927 | representation */ | 932 | representation */ |
928 | if (bytes) { | 933 | if (bytes) { |
929 | setValueWithSize(curProp,bytes,(unsigned int)bytesLen); | 934 | setValueWithSize(curProp,bytes,(unsigned int)bytesLen); |
930 | free(bytes); | 935 | free(bytes); |
931 | } | 936 | } |
932 | else if (oldBytes) { | 937 | else if (oldBytes) { |
933 | setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); | 938 | setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); |
934 | free(oldBytes); | 939 | free(oldBytes); |
935 | } | 940 | } |
936 | return bytesLen; | 941 | return bytesLen; |
937 | } | 942 | } |
938 | 943 | ||
939 | static int match_begin_end_name(int end) { | 944 | static int match_begin_end_name(int end) { |
940 | int token; | 945 | int token; |
941 | lexSkipWhite(); | 946 | lexSkipWhite(); |
942 | if (lexLookahead() != ':') return ID; | 947 | if (lexLookahead() != ':') return ID; |
943 | lexSkipLookahead(); | 948 | lexSkipLookahead(); |
944 | lexSkipWhite(); | 949 | lexSkipWhite(); |
945 | token = match_begin_name(end); | 950 | token = match_begin_name(end); |
946 | if (token == ID) { | 951 | if (token == ID) { |
947 | lexPushLookaheadc(':'); | 952 | lexPushLookaheadc(':'); |
948 | DBG_(("db: ID '%s'\n", yylval.str)); | 953 | DBG_(("db: ID '%s'\n", yylval.str)); |
949 | return ID; | 954 | return ID; |
950 | } | 955 | } |
951 | else if (token != 0) { | 956 | else if (token != 0) { |
952 | lexSkipLookaheadWord(); | 957 | lexSkipLookaheadWord(); |
953 | deleteStr(yylval.str); | 958 | deleteStr(yylval.str); |
954 | DBG_(("db: begin/end %d\n", token)); | 959 | DBG_(("db: begin/end %d\n", token)); |
955 | return token; | 960 | return token; |
956 | } | 961 | } |
957 | return 0; | 962 | return 0; |
958 | } | 963 | } |
959 | 964 | ||
960 | static char* lexGetQuotedPrintable() | 965 | static char* lexGetQuotedPrintable() |
961 | { | 966 | { |
962 | int c; | 967 | int c; |
963 | lexSkipWhite(); | 968 | lexSkipWhite(); |
964 | c = lexLookahead(); | 969 | c = lexLookahead(); |
965 | lexClearToken(); | 970 | lexClearToken(); |
966 | 971 | ||
967 | while (c != EOF && (c != ';' || !fieldedProp)) { | 972 | while (c != EOF && (c != ';' || !fieldedProp)) { |
968 | if (c == '\n') { | 973 | if (c == '\n') { |
969 | // break, leave '\n' on remaining chars. | 974 | // break, leave '\n' on remaining chars. |
970 | break; | 975 | break; |
971 | } else if (c == '=') { | 976 | } else if (c == '=') { |
972 | int cur = 0; | 977 | int cur = 0; |
973 | int next; | 978 | int next; |
974 | 979 | ||
975 | lexSkipLookahead(); // skip '=' | 980 | lexSkipLookahead(); // skip '=' |
976 | next = lexLookahead(); | 981 | next = lexLookahead(); |
977 | 982 | ||
978 | if (next == '\n') { | 983 | if (next == '\n') { |
979 | // skip and only skip the \n | 984 | // skip and only skip the \n |
980 | lexSkipLookahead(); | 985 | lexSkipLookahead(); |
981 | c = lexLookahead(); | 986 | c = lexLookahead(); |
982 | ++mime_lineNum; // aid in error reporting | 987 | ++mime_lineNum; // aid in error reporting |
983 | continue; | 988 | continue; |
984 | } else if (next >= '0' && next <= '9') { | 989 | } else if (next >= '0' && next <= '9') { |
985 | cur = next - '0'; | 990 | cur = next - '0'; |
986 | } else if (next >= 'A' && next <= 'F') { | 991 | } else if (next >= 'A' && next <= 'F') { |
987 | cur = next - 'A' + 10; | 992 | cur = next - 'A' + 10; |
988 | } else { | 993 | } else { |
989 | // we have been sent buggy stuff. doesn't matter | 994 | // we have been sent buggy stuff. doesn't matter |
990 | // what we do so long as we keep going. | 995 | // what we do so long as we keep going. |
991 | // should probably spit an error here | 996 | // should probably spit an error here |
992 | lexSkipLookahead(); | 997 | lexSkipLookahead(); |
993 | c = lexLookahead(); | 998 | c = lexLookahead(); |
994 | continue; | 999 | continue; |
995 | } | 1000 | } |
996 | 1001 | ||
997 | lexSkipLookahead(); // skip A-Z0-9 | 1002 | lexSkipLookahead(); // skip A-Z0-9 |
998 | next = lexLookahead(); | 1003 | next = lexLookahead(); |
999 | 1004 | ||
1000 | cur = cur * 16; | 1005 | cur = cur * 16; |
1001 | // this time really just expecting 0-9A-F | 1006 | // this time really just expecting 0-9A-F |
1002 | if (next >= '0' && next <= '9') { | 1007 | if (next >= '0' && next <= '9') { |
1003 | cur += next - '0'; | 1008 | cur += next - '0'; |
1004 | } else if (next >= 'A' && next <= 'F') { | 1009 | } else if (next >= 'A' && next <= 'F') { |
1005 | cur += next - 'A' + 10; | 1010 | cur += next - 'A' + 10; |
1006 | } else { | 1011 | } else { |
1007 | // we have been sent buggy stuff. doesn't matter | 1012 | // we have been sent buggy stuff. doesn't matter |
1008 | // what we do so long as we keep going. | 1013 | // what we do so long as we keep going. |
1009 | // should probably spit an error here | 1014 | // should probably spit an error here |
1010 | lexSkipLookahead(); | 1015 | lexSkipLookahead(); |
1011 | c = lexLookahead(); | 1016 | c = lexLookahead(); |
1012 | continue; | 1017 | continue; |
1013 | } | 1018 | } |
1014 | 1019 | ||
1015 | // got a valid escaped =. append it. | 1020 | // got a valid escaped =. append it. |
1016 | lexSkipLookahead(); // skip second 0-9A-F | 1021 | lexSkipLookahead(); // skip second 0-9A-F |
1017 | lexAppendc(cur); | 1022 | lexAppendc(cur); |
1018 | } else { | 1023 | } else { |
1019 | lexSkipLookahead(); // skip whatever we just read. | 1024 | lexSkipLookahead(); // skip whatever we just read. |
1020 | lexAppendc(c); // and append it. | 1025 | lexAppendc(c); // and append it. |
1021 | } | 1026 | } |
1022 | c = lexLookahead(); | 1027 | c = lexLookahead(); |
1023 | } | 1028 | } |
1024 | lexAppendc(0); | 1029 | lexAppendc(0); |
1025 | return c==EOF?0:lexStr(); | 1030 | return c==EOF?0:lexStr(); |
1026 | } | 1031 | } |
1027 | 1032 | ||
1028 | static int yylex() { | 1033 | static int yylex() { |
1029 | 1034 | ||
1030 | int lexmode = LEXMODE(); | 1035 | int lexmode = LEXMODE(); |
1031 | if (lexmode == L_VALUES) { | 1036 | if (lexmode == L_VALUES) { |
1032 | int c = lexGetc(); | 1037 | int c = lexGetc(); |
1033 | if (c == ';' && fieldedProp) { | 1038 | if (c == ';' && fieldedProp) { |
1034 | DBG_(("db: SEMICOLON\n")); | 1039 | DBG_(("db: SEMICOLON\n")); |
1035 | lexPushLookaheadc(c); | 1040 | lexPushLookaheadc(c); |
1036 | handleMoreRFC822LineBreak(c); | 1041 | handleMoreRFC822LineBreak(c); |
1037 | lexSkipLookahead(); | 1042 | lexSkipLookahead(); |
1038 | return SEMICOLON; | 1043 | return SEMICOLON; |
1039 | } | 1044 | } |
1040 | else if (strchr("\n",c)) { | 1045 | else if (strchr("\n",c)) { |
1041 | ++mime_lineNum; | 1046 | ++mime_lineNum; |
1042 | /* consume all line separator(s) adjacent to each other */ | 1047 | /* consume all line separator(s) adjacent to each other */ |
1043 | c = lexLookahead(); | 1048 | c = lexLookahead(); |
1044 | while (strchr("\n",c)) { | 1049 | while (strchr("\n",c)) { |
1045 | lexSkipLookahead(); | 1050 | lexSkipLookahead(); |
1046 | c = lexLookahead(); | 1051 | c = lexLookahead(); |
1047 | ++mime_lineNum; | 1052 | ++mime_lineNum; |
1048 | } | 1053 | } |
1049 | DBG_(("db: LINESEP\n")); | 1054 | DBG_(("db: LINESEP\n")); |
1050 | return LINESEP; | 1055 | return LINESEP; |
1051 | } | 1056 | } |
1052 | else { | 1057 | else { |
1053 | char *p = 0; | 1058 | char *p = 0; |
1054 | lexPushLookaheadc(c); | 1059 | lexPushLookaheadc(c); |
1055 | if (lexWithinMode(L_BASE64)) { | 1060 | if (lexWithinMode(L_BASE64)) { |
1056 | /* get each char and convert to bin on the fly... */ | 1061 | /* get each char and convert to bin on the fly... */ |
1057 | yylval.str = NULL; | 1062 | yylval.str = NULL; |
1058 | return lexGetDataFromBase64() ? STRING : 0; | 1063 | return lexGetDataFromBase64() ? STRING : 0; |
1059 | } | 1064 | } |
1060 | else if (lexWithinMode(L_QUOTED_PRINTABLE)) { | 1065 | else if (lexWithinMode(L_QUOTED_PRINTABLE)) { |
1061 | p = lexGetQuotedPrintable(); | 1066 | p = lexGetQuotedPrintable(); |
1062 | } | 1067 | } |
1063 | else { | 1068 | else { |
1064 | #ifdef _SUPPORT_LINE_FOLDING | 1069 | #ifdef _SUPPORT_LINE_FOLDING |
1065 | p = lexGet1Value(); | 1070 | p = lexGet1Value(); |
1066 | #else | 1071 | #else |
1067 | p = lexGetStrUntil(";\n"); | 1072 | p = lexGetStrUntil(";\n"); |
1068 | #endif | 1073 | #endif |
1069 | } | 1074 | } |
1070 | if (p) { | 1075 | if (p) { |
1071 | DBG_(("db: STRING: '%s'\n", p)); | 1076 | DBG_(("db: STRING: '%s'\n", p)); |
1072 | yylval.str = p; | 1077 | yylval.str = p; |
1073 | return STRING; | 1078 | return STRING; |
1074 | } | 1079 | } |
1075 | else return 0; | 1080 | else return 0; |
1076 | } | 1081 | } |
1077 | } | 1082 | } |
1078 | else { | 1083 | else { |
1079 | /* normal mode */ | 1084 | /* normal mode */ |
1080 | while (1) { | 1085 | while (1) { |
1081 | int c = lexGetc(); | 1086 | int c = lexGetc(); |
1082 | switch(c) { | 1087 | switch(c) { |
1083 | case ':': { | 1088 | case ':': { |
1084 | /* consume all line separator(s) adjacent to each other */ | 1089 | /* consume all line separator(s) adjacent to each other */ |
1085 | /* ignoring linesep immediately after colon. */ | 1090 | /* ignoring linesep immediately after colon. */ |
1086 | /* I don't see this in the spec, and it breaks null values -- WA | 1091 | /* I don't see this in the spec, and it breaks null values -- WA |
1087 | c = lexLookahead(); | 1092 | c = lexLookahead(); |
1088 | while (strchr("\n",c)) { | 1093 | while (strchr("\n",c)) { |
1089 | lexSkipLookahead(); | 1094 | lexSkipLookahead(); |
1090 | c = lexLookahead(); | 1095 | c = lexLookahead(); |
1091 | ++mime_lineNum; | 1096 | ++mime_lineNum; |
1092 | } | 1097 | } |
1093 | */ | 1098 | */ |
1094 | DBG_(("db: COLON\n")); | 1099 | DBG_(("db: COLON\n")); |
1095 | return COLON; | 1100 | return COLON; |
1096 | } | 1101 | } |
1097 | case ';': | 1102 | case ';': |
1098 | DBG_(("db: SEMICOLON\n")); | 1103 | DBG_(("db: SEMICOLON\n")); |
1099 | return SEMICOLON; | 1104 | return SEMICOLON; |
1100 | case '=': | 1105 | case '=': |
1101 | DBG_(("db: EQ\n")); | 1106 | DBG_(("db: EQ\n")); |
1102 | return EQ; | 1107 | return EQ; |
1103 | /* ignore whitespace in this mode */ | 1108 | /* ignore whitespace in this mode */ |
1104 | case '\t': | 1109 | case '\t': |
1105 | case ' ': continue; | 1110 | case ' ': continue; |
1106 | case '\n': { | 1111 | case '\n': { |
1107 | ++mime_lineNum; | 1112 | ++mime_lineNum; |
1108 | continue; | 1113 | continue; |
1109 | } | 1114 | } |
1110 | case EOF: return 0; | 1115 | case EOF: return 0; |
1111 | break; | 1116 | break; |
1112 | default: { | 1117 | default: { |
1113 | lexPushLookaheadc(c); | 1118 | lexPushLookaheadc(c); |
1114 | if (isalnum(c)) { | 1119 | if (isalnum(c)) { |
1115 | char *t = lexGetWord(); | 1120 | char *t = lexGetWord(); |
1116 | yylval.str = t; | 1121 | yylval.str = t; |
1117 | if (!qstricmp(t, "begin")) { | 1122 | if (!qstricmp(t, "begin")) { |
1118 | return match_begin_end_name(0); | 1123 | return match_begin_end_name(0); |
1119 | } | 1124 | } |
1120 | else if (!qstricmp(t,"end")) { | 1125 | else if (!qstricmp(t,"end")) { |
1121 | return match_begin_end_name(1); | 1126 | return match_begin_end_name(1); |
1122 | } | 1127 | } |
1123 | else { | 1128 | else { |
1124 | DBG_(("db: ID '%s'\n", t)); | 1129 | DBG_(("db: ID '%s'\n", t)); |
1125 | return ID; | 1130 | return ID; |
1126 | } | 1131 | } |
1127 | } | 1132 | } |
1128 | else { | 1133 | else { |
1129 | /* unknow token */ | 1134 | /* unknow token */ |
1130 | return 0; | 1135 | return 0; |
1131 | } | 1136 | } |
1132 | break; | 1137 | break; |
1133 | } | 1138 | } |
1134 | } | 1139 | } |
1135 | } | 1140 | } |
1136 | } | 1141 | } |
1137 | return 0; | 1142 | return 0; |
1138 | } | 1143 | } |
1139 | 1144 | ||
1140 | 1145 | ||
1141 | /***************************************************************************/ | 1146 | /***************************************************************************/ |
1142 | /*** Public Functions ****/ | 1147 | /*** Public Functions ****/ |
1143 | /***************************************************************************/ | 1148 | /***************************************************************************/ |
1144 | 1149 | ||
1145 | static VObject* Parse_MIMEHelper() | 1150 | static VObject* Parse_MIMEHelper() |
1146 | { | 1151 | { |
1147 | ObjStackTop = -1; | 1152 | ObjStackTop = -1; |
1148 | mime_numErrors = 0; | 1153 | mime_numErrors = 0; |
1149 | mime_lineNum = 1; | 1154 | mime_lineNum = 1; |
1150 | vObjList = 0; | 1155 | vObjList = 0; |
1151 | curObj = 0; | 1156 | curObj = 0; |
1152 | 1157 | ||
1153 | if (yyparse() != 0) | 1158 | if (yyparse() != 0) |
1154 | return 0; | 1159 | return 0; |
1155 | 1160 | ||
1156 | finiLex(); | 1161 | finiLex(); |
1157 | return vObjList; | 1162 | return vObjList; |
1158 | } | 1163 | } |
1159 | 1164 | ||
1160 | /*--------------------------------------------*/ | 1165 | /*--------------------------------------------*/ |
1161 | DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len) | 1166 | DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len) |
1162 | { | 1167 | { |
1163 | initLex(input, len, 0); | 1168 | initLex(input, len, 0); |
1164 | return Parse_MIMEHelper(); | 1169 | return Parse_MIMEHelper(); |
1165 | } | 1170 | } |
1166 | 1171 | ||
1167 | 1172 | ||
1168 | #if INCLUDEMFC | 1173 | #if INCLUDEMFC |
1169 | 1174 | ||
1170 | DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file) | 1175 | DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file) |
1171 | { | 1176 | { |
1172 | unsigned long startPos; | 1177 | unsigned long startPos; |
1173 | VObject *result; | 1178 | VObject *result; |
1174 | 1179 | ||
1175 | initLex(0,-1,file); | 1180 | initLex(0,-1,file); |
1176 | startPos = file->GetPosition(); | 1181 | startPos = file->GetPosition(); |
1177 | if (!(result = Parse_MIMEHelper())) | 1182 | if (!(result = Parse_MIMEHelper())) |
1178 | file->Seek(startPos, CFile::begin); | 1183 | file->Seek(startPos, CFile::begin); |
1179 | return result; | 1184 | return result; |
1180 | } | 1185 | } |
1181 | 1186 | ||
1182 | #else | 1187 | #else |
1183 | 1188 | ||
1184 | VObject* Parse_MIME_FromFile(FILE *file) | 1189 | VObject* Parse_MIME_FromFile(FILE *file) |
1185 | { | 1190 | { |
1186 | VObject *result; | 1191 | VObject *result; |
1187 | long startPos; | 1192 | long startPos; |
1188 | 1193 | ||
1189 | initLex(0,(unsigned long)-1,file); | 1194 | initLex(0,(unsigned long)-1,file); |
1190 | startPos = ftell(file); | 1195 | startPos = ftell(file); |
1191 | if (!(result = Parse_MIMEHelper())) { | 1196 | if (!(result = Parse_MIMEHelper())) { |
1192 | fseek(file,startPos,SEEK_SET); | 1197 | fseek(file,startPos,SEEK_SET); |
1193 | } | 1198 | } |
1194 | return result; | 1199 | return result; |
1195 | } | 1200 | } |
1196 | 1201 | ||
1197 | DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname) | 1202 | DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname) |
1198 | { | 1203 | { |
1199 | FILE *fp = fopen(fname,"r"); | 1204 | FILE *fp = fopen(fname,"r"); |
1200 | if (fp) { | 1205 | if (fp) { |
1201 | VObject* o = Parse_MIME_FromFile(fp); | 1206 | VObject* o = Parse_MIME_FromFile(fp); |
1202 | fclose(fp); | 1207 | fclose(fp); |
1203 | return o; | 1208 | return o; |
1204 | } | 1209 | } |
1205 | else { | 1210 | else { |
1206 | char msg[80]; | 1211 | char msg[80]; |
1207 | sprintf(msg, "can't open file '%s' for reading\n", fname); | 1212 | sprintf(msg, "can't open file '%s' for reading\n", fname); |
1208 | mime_error_(msg); | 1213 | mime_error_(msg); |
1209 | return 0; | 1214 | return 0; |
1210 | } | 1215 | } |
1211 | } | 1216 | } |
1212 | 1217 | ||
1213 | #endif | 1218 | #endif |
1214 | 1219 | ||
1215 | /*-------------------------------------*/ | 1220 | /*-------------------------------------*/ |
1216 | 1221 | ||
1217 | static MimeErrorHandler mimeErrorHandler; | 1222 | static MimeErrorHandler mimeErrorHandler; |
1218 | 1223 | ||
1219 | DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me) | 1224 | DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me) |
1220 | { | 1225 | { |
1221 | mimeErrorHandler = me; | 1226 | mimeErrorHandler = me; |
1222 | } | 1227 | } |
1223 | 1228 | ||
1224 | void mime_error(char *s) | 1229 | void mime_error(char *s) |
1225 | { | 1230 | { |
1226 | char msg[256]; | 1231 | char msg[256]; |
1227 | if (mimeErrorHandler) { | 1232 | if (mimeErrorHandler) { |
1228 | sprintf(msg,"%s at line %d", s, mime_lineNum); | 1233 | sprintf(msg,"%s at line %d", s, mime_lineNum); |
1229 | mimeErrorHandler(msg); | 1234 | mimeErrorHandler(msg); |
1230 | } | 1235 | } |
1231 | } | 1236 | } |
1232 | 1237 | ||
1233 | void mime_error_(char *s) | 1238 | void mime_error_(char *s) |
1234 | { | 1239 | { |
1235 | if (mimeErrorHandler) { | 1240 | if (mimeErrorHandler) { |
1236 | mimeErrorHandler(s); | 1241 | mimeErrorHandler(s); |
1237 | } | 1242 | } |
1238 | } | 1243 | } |
1239 | 1244 | ||
1240 | #line 1241 "y.tab.c" | 1245 | #line 1241 "y.tab.c" |
1241 | #define YYABORT goto yyabort | 1246 | #define YYABORT goto yyabort |
1242 | #define YYREJECT goto yyabort | 1247 | #define YYREJECT goto yyabort |
1243 | #define YYACCEPT goto yyaccept | 1248 | #define YYACCEPT goto yyaccept |
1244 | #define YYERROR goto yyerrlab | 1249 | #define YYERROR goto yyerrlab |
1245 | int | 1250 | int |
1246 | #if defined(__STDC__) | 1251 | #if defined(__STDC__) |
1247 | yyparse(void) | 1252 | yyparse(void) |
1248 | #else | 1253 | #else |
1249 | yyparse() | 1254 | yyparse() |
1250 | #endif | 1255 | #endif |
1251 | { | 1256 | { |
@@ -1379,87 +1384,87 @@ yyreduce: | |||
1379 | switch (yyn) | 1384 | switch (yyn) |
1380 | { | 1385 | { |
1381 | case 2: | 1386 | case 2: |
1382 | #line 221 "backend/vcc.y" | 1387 | #line 221 "backend/vcc.y" |
1383 | { addList(&vObjList, yyvsp[0].vobj); curObj = 0; } | 1388 | { addList(&vObjList, yyvsp[0].vobj); curObj = 0; } |
1384 | break; | 1389 | break; |
1385 | case 3: | 1390 | case 3: |
1386 | #line 223 "backend/vcc.y" | 1391 | #line 223 "backend/vcc.y" |
1387 | { addList(&vObjList, yyvsp[0].vobj); curObj = 0; } | 1392 | { addList(&vObjList, yyvsp[0].vobj); curObj = 0; } |
1388 | break; | 1393 | break; |
1389 | case 6: | 1394 | case 6: |
1390 | #line 232 "backend/vcc.y" | 1395 | #line 232 "backend/vcc.y" |
1391 | { | 1396 | { |
1392 | lexPushMode(L_VCARD); | 1397 | lexPushMode(L_VCARD); |
1393 | if (!pushVObject(VCCardProp)) YYERROR; | 1398 | if (!pushVObject(VCCardProp)) YYERROR; |
1394 | } | 1399 | } |
1395 | break; | 1400 | break; |
1396 | case 7: | 1401 | case 7: |
1397 | #line 237 "backend/vcc.y" | 1402 | #line 237 "backend/vcc.y" |
1398 | { | 1403 | { |
1399 | lexPopMode(0); | 1404 | lexPopMode(0); |
1400 | yyval.vobj = popVObject(); | 1405 | yyval.vobj = popVObject(); |
1401 | } | 1406 | } |
1402 | break; | 1407 | break; |
1403 | case 8: | 1408 | case 8: |
1404 | #line 242 "backend/vcc.y" | 1409 | #line 242 "backend/vcc.y" |
1405 | { | 1410 | { |
1406 | lexPushMode(L_VCARD); | 1411 | lexPushMode(L_VCARD); |
1407 | if (!pushVObject(VCCardProp)) YYERROR; | 1412 | if (!pushVObject(VCCardProp)) YYERROR; |
1408 | } | 1413 | } |
1409 | break; | 1414 | break; |
1410 | case 9: | 1415 | case 9: |
1411 | #line 247 "backend/vcc.y" | 1416 | #line 247 "backend/vcc.y" |
1412 | { | 1417 | { |
1413 | lexPopMode(0); | 1418 | lexPopMode(0); |
1414 | yyval.vobj = popVObject(); | 1419 | yyval.vobj = popVObject(); |
1415 | } | 1420 | } |
1416 | break; | 1421 | break; |
1417 | case 12: | 1422 | case 12: |
1418 | #line 258 "backend/vcc.y" | 1423 | #line 258 "backend/vcc.y" |
1419 | { | 1424 | { |
1420 | lexPushMode(L_VALUES); | 1425 | lexPushMode(L_VALUES); |
1421 | } | 1426 | } |
1422 | break; | 1427 | break; |
1423 | case 13: | 1428 | case 13: |
1424 | #line 262 "backend/vcc.y" | 1429 | #line 262 "backend/vcc.y" |
1425 | { | 1430 | { |
1426 | if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE)) | 1431 | if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE)) |
1427 | lexPopMode(0); | 1432 | lexPopMode(0); |
1428 | lexPopMode(0); | 1433 | lexPopMode(0); |
1429 | } | 1434 | } |
1430 | break; | 1435 | break; |
1431 | case 15: | 1436 | case 15: |
1432 | #line 271 "backend/vcc.y" | 1437 | #line 271 "backend/vcc.y" |
1433 | { | 1438 | { |
1434 | enterProps(yyvsp[0].str); | 1439 | enterProps(yyvsp[0].str); |
1435 | } | 1440 | } |
1436 | break; | 1441 | break; |
1437 | case 17: | 1442 | case 17: |
1438 | #line 276 "backend/vcc.y" | 1443 | #line 276 "backend/vcc.y" |
1439 | { | 1444 | { |
1440 | enterProps(yyvsp[0].str); | 1445 | enterProps(yyvsp[0].str); |
1441 | } | 1446 | } |
1442 | break; | 1447 | break; |
1443 | case 21: | 1448 | case 21: |
1444 | #line 289 "backend/vcc.y" | 1449 | #line 289 "backend/vcc.y" |
1445 | { | 1450 | { |
1446 | enterAttr(yyvsp[0].str,0); | 1451 | enterAttr(yyvsp[0].str,0); |
1447 | } | 1452 | } |
1448 | break; | 1453 | break; |
1449 | case 22: | 1454 | case 22: |
1450 | #line 293 "backend/vcc.y" | 1455 | #line 293 "backend/vcc.y" |
1451 | { | 1456 | { |
1452 | enterAttr(yyvsp[-2].str,yyvsp[0].str); | 1457 | enterAttr(yyvsp[-2].str,yyvsp[0].str); |
1453 | 1458 | ||
1454 | } | 1459 | } |
1455 | break; | 1460 | break; |
1456 | case 24: | 1461 | case 24: |
1457 | #line 302 "backend/vcc.y" | 1462 | #line 302 "backend/vcc.y" |
1458 | { enterValues(yyvsp[-1].str); } | 1463 | { enterValues(yyvsp[-1].str); } |
1459 | break; | 1464 | break; |
1460 | case 26: | 1465 | case 26: |
1461 | #line 304 "backend/vcc.y" | 1466 | #line 304 "backend/vcc.y" |
1462 | { enterValues(yyvsp[0].str); } | 1467 | { enterValues(yyvsp[0].str); } |
1463 | break; | 1468 | break; |
1464 | case 28: | 1469 | case 28: |
1465 | #line 309 "backend/vcc.y" | 1470 | #line 309 "backend/vcc.y" |
@@ -1474,76 +1479,76 @@ case 30: | |||
1474 | { yyval.vobj = popVObject(); } | 1479 | { yyval.vobj = popVObject(); } |
1475 | break; | 1480 | break; |
1476 | case 31: | 1481 | case 31: |
1477 | #line 319 "backend/vcc.y" | 1482 | #line 319 "backend/vcc.y" |
1478 | { if (!pushVObject(VCCalProp)) YYERROR; } | 1483 | { if (!pushVObject(VCCalProp)) YYERROR; } |
1479 | break; | 1484 | break; |
1480 | case 32: | 1485 | case 32: |
1481 | #line 321 "backend/vcc.y" | 1486 | #line 321 "backend/vcc.y" |
1482 | { yyval.vobj = popVObject(); } | 1487 | { yyval.vobj = popVObject(); } |
1483 | break; | 1488 | break; |
1484 | case 38: | 1489 | case 38: |
1485 | #line 336 "backend/vcc.y" | 1490 | #line 336 "backend/vcc.y" |
1486 | { | 1491 | { |
1487 | lexPushMode(L_VEVENT); | 1492 | lexPushMode(L_VEVENT); |
1488 | if (!pushVObject(VCEventProp)) YYERROR; | 1493 | if (!pushVObject(VCEventProp)) YYERROR; |
1489 | } | 1494 | } |
1490 | break; | 1495 | break; |
1491 | case 39: | 1496 | case 39: |
1492 | #line 342 "backend/vcc.y" | 1497 | #line 342 "backend/vcc.y" |
1493 | { | 1498 | { |
1494 | lexPopMode(0); | 1499 | lexPopMode(0); |
1495 | popVObject(); | 1500 | popVObject(); |
1496 | } | 1501 | } |
1497 | break; | 1502 | break; |
1498 | case 40: | 1503 | case 40: |
1499 | #line 347 "backend/vcc.y" | 1504 | #line 347 "backend/vcc.y" |
1500 | { | 1505 | { |
1501 | lexPushMode(L_VEVENT); | 1506 | lexPushMode(L_VEVENT); |
1502 | if (!pushVObject(VCEventProp)) YYERROR; | 1507 | if (!pushVObject(VCEventProp)) YYERROR; |
1503 | } | 1508 | } |
1504 | break; | 1509 | break; |
1505 | case 41: | 1510 | case 41: |
1506 | #line 352 "backend/vcc.y" | 1511 | #line 352 "backend/vcc.y" |
1507 | { | 1512 | { |
1508 | lexPopMode(0); | 1513 | lexPopMode(0); |
1509 | popVObject(); | 1514 | popVObject(); |
1510 | } | 1515 | } |
1511 | break; | 1516 | break; |
1512 | case 42: | 1517 | case 42: |
1513 | #line 360 "backend/vcc.y" | 1518 | #line 360 "backend/vcc.y" |
1514 | { | 1519 | { |
1515 | lexPushMode(L_VTODO); | 1520 | lexPushMode(L_VTODO); |
1516 | if (!pushVObject(VCTodoProp)) YYERROR; | 1521 | if (!pushVObject(VCTodoProp)) YYERROR; |
1517 | } | 1522 | } |
1518 | break; | 1523 | break; |
1519 | case 43: | 1524 | case 43: |
1520 | #line 366 "backend/vcc.y" | 1525 | #line 366 "backend/vcc.y" |
1521 | { | 1526 | { |
1522 | lexPopMode(0); | 1527 | lexPopMode(0); |
1523 | popVObject(); | 1528 | popVObject(); |
1524 | } | 1529 | } |
1525 | break; | 1530 | break; |
1526 | case 44: | 1531 | case 44: |
1527 | #line 371 "backend/vcc.y" | 1532 | #line 371 "backend/vcc.y" |
1528 | { | 1533 | { |
1529 | lexPushMode(L_VTODO); | 1534 | lexPushMode(L_VTODO); |
1530 | if (!pushVObject(VCTodoProp)) YYERROR; | 1535 | if (!pushVObject(VCTodoProp)) YYERROR; |
1531 | } | 1536 | } |
1532 | break; | 1537 | break; |
1533 | case 45: | 1538 | case 45: |
1534 | #line 376 "backend/vcc.y" | 1539 | #line 376 "backend/vcc.y" |
1535 | { | 1540 | { |
1536 | lexPopMode(0); | 1541 | lexPopMode(0); |
1537 | popVObject(); | 1542 | popVObject(); |
1538 | } | 1543 | } |
1539 | break; | 1544 | break; |
1540 | #line 1541 "y.tab.c" | 1545 | #line 1541 "y.tab.c" |
1541 | } | 1546 | } |
1542 | yyssp -= yym; | 1547 | yyssp -= yym; |
1543 | yystate = *yyssp; | 1548 | yystate = *yyssp; |
1544 | yyvsp -= yym; | 1549 | yyvsp -= yym; |
1545 | yym = yylhs[yyn]; | 1550 | yym = yylhs[yyn]; |
1546 | if (yystate == 0 && yym == 0) | 1551 | if (yystate == 0 && yym == 0) |
1547 | { | 1552 | { |
1548 | #if YYDEBUG | 1553 | #if YYDEBUG |
1549 | if (yydebug) | 1554 | if (yydebug) |