summaryrefslogtreecommitdiff
path: root/library/backend
authorzecke <zecke>2002-10-15 21:42:20 (UTC)
committer zecke <zecke>2002-10-15 21:42:20 (UTC)
commit676be5604cbdb3213c00775e0ff66f4e766f8dcb (patch) (unidiff)
tree63c29adab530a60371f78880ff75e2689398e239 /library/backend
parentb774e015816e51ac65e5d1c685306f8404a3a19e (diff)
downloadopie-676be5604cbdb3213c00775e0ff66f4e766f8dcb.zip
opie-676be5604cbdb3213c00775e0ff66f4e766f8dcb.tar.gz
opie-676be5604cbdb3213c00775e0ff66f4e766f8dcb.tar.bz2
Actually most of them are -+ cause I opened them in xemacs..
The main goal is to replace some header names to let them be overwritten by external once so "qpeapplication.h" is now <qpe/qpeapplication.h> I'll check if it's building on non Qt2/X11 systems...
Diffstat (limited to 'library/backend') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/vcc.y2
-rw-r--r--library/backend/vcc_yacc.cpp2
-rw-r--r--library/backend/vobject.cpp116
3 files changed, 60 insertions, 60 deletions
diff --git a/library/backend/vcc.y b/library/backend/vcc.y
index 5bcf0cb..6781312 100644
--- a/library/backend/vcc.y
+++ b/library/backend/vcc.y
@@ -1,1208 +1,1208 @@
1%{ 1%{
2 2
3/*************************************************************************** 3/***************************************************************************
4(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International 4(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
5Business Machines Corporation and Siemens Rolm Communications Inc. 5Business Machines Corporation and Siemens Rolm Communications Inc.
6 6
7For purposes of this license notice, the term Licensors shall mean, 7For purposes of this license notice, the term Licensors shall mean,
8collectively, Apple Computer, Inc., AT&T Corp., International 8collectively, Apple Computer, Inc., AT&T Corp., International
9Business Machines Corporation and Siemens Rolm Communications Inc. 9Business Machines Corporation and Siemens Rolm Communications Inc.
10The term Licensor shall mean any of the Licensors. 10The term Licensor shall mean any of the Licensors.
11 11
12Subject to acceptance of the following conditions, permission is hereby 12Subject to acceptance of the following conditions, permission is hereby
13granted by Licensors without the need for written agreement and without 13granted by Licensors without the need for written agreement and without
14license or royalty fees, to use, copy, modify and distribute this 14license or royalty fees, to use, copy, modify and distribute this
15software for any purpose. 15software for any purpose.
16 16
17The above copyright notice and the following four paragraphs must be 17The above copyright notice and the following four paragraphs must be
18reproduced in all copies of this software and any software including 18reproduced in all copies of this software and any software including
19this software. 19this software.
20 20
21THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE 21THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
22ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR 22ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
23MODIFICATIONS. 23MODIFICATIONS.
24 24
25IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, 25IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
26INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 26INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
27OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 27OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28DAMAGE. 28DAMAGE.
29 29
30EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, 30EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
31INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE 31INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
32IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 32IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33PURPOSE. 33PURPOSE.
34 34
35The software is provided with RESTRICTED RIGHTS. Use, duplication, or 35The software is provided with RESTRICTED RIGHTS. Use, duplication, or
36disclosure by the government are subject to restrictions set forth in 36disclosure by the government are subject to restrictions set forth in
37DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. 37DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.
38 38
39***************************************************************************/ 39***************************************************************************/
40 40
41/* 41/*
42 * src: vcc.c 42 * src: vcc.c
43 * doc: Parser for vCard and vCalendar. Note that this code is 43 * doc: Parser for vCard and vCalendar. Note that this code is
44 * generated by a yacc parser generator. Generally it should not 44 * generated by a yacc parser generator. Generally it should not
45 * be edited by hand. The real source is vcc.y. The #line directives 45 * be edited by hand. The real source is vcc.y. The #line directives
46 * can be commented out here to make it easier to trace through 46 * can be commented out here to make it easier to trace through
47 * in a debugger. However, if a bug is found it should 47 * in a debugger. However, if a bug is found it should
48 * be fixed in vcc.y and this file regenerated. 48 * be fixed in vcc.y and this file regenerated.
49 */ 49 */
50 50
51 51
52/* debugging utilities */ 52/* debugging utilities */
53#if __DEBUG 53#if __DEBUG
54#define DBG_(x) printf x 54#define DBG_(x) printf x
55#else 55#else
56#define DBG_(x) 56#define DBG_(x)
57#endif 57#endif
58 58
59/**** External Functions ****/ 59/**** External Functions ****/
60 60
61/* assign local name to parser variables and functions so that 61/* assign local name to parser variables and functions so that
62 we can use more than one yacc based parser. 62 we can use more than one yacc based parser.
63*/ 63*/
64 64
65#if 0 65#if 0
66#define yyparse mime_parse 66#define yyparse mime_parse
67#define yylex mime_lex 67#define yylex mime_lex
68#define yyerror mime_error 68#define yyerror mime_error
69#define yychar mime_char 69#define yychar mime_char
70/* #define p_yyval p_mime_val */ 70/* #define p_yyval p_mime_val */
71#undef yyval 71#undef yyval
72#define yyval mime_yyval 72#define yyval mime_yyval
73/* #define p_yylval p_mime_lval */ 73/* #define p_yylval p_mime_lval */
74#undef yylval 74#undef yylval
75#define yylval mime_yylval 75#define yylval mime_yylval
76#define yydebug mime_debug 76#define yydebug mime_debug
77#define yynerrs mime_nerrs 77#define yynerrs mime_nerrs
78#define yyerrflag mime_errflag 78#define yyerrflag mime_errflag
79#define yyss mime_ss 79#define yyss mime_ss
80#define yyssp mime_ssp 80#define yyssp mime_ssp
81#define yyvs mime_vs 81#define yyvs mime_vs
82#define yyvsp mime_vsp 82#define yyvsp mime_vsp
83#define yylhs mime_lhs 83#define yylhs mime_lhs
84#define yylen mime_len 84#define yylen mime_len
85#define yydefred mime_defred 85#define yydefred mime_defred
86#define yydgoto mime_dgoto 86#define yydgoto mime_dgoto
87#define yysindex mime_sindex 87#define yysindex mime_sindex
88#define yyrindex mime_rindex 88#define yyrindex mime_rindex
89#define yygindex mime_gindex 89#define yygindex mime_gindex
90#define yytable mime_table 90#define yytable mime_table
91#define yycheck mime_check 91#define yycheck mime_check
92#define yyname mime_name 92#define yyname mime_name
93#define yyrule mime_rule 93#define yyrule mime_rule
94#ifdef YYPREFIX 94#ifdef YYPREFIX
95#undef YYPREFIX 95#undef YYPREFIX
96#endif 96#endif
97#define YYPREFIX "mime_" 97#define YYPREFIX "mime_"
98#endif 98#endif
99 99
100 100
101#ifndef _NO_LINE_FOLDING 101#ifndef _NO_LINE_FOLDING
102#define _SUPPORT_LINE_FOLDING 1 102#define _SUPPORT_LINE_FOLDING 1
103#endif 103#endif
104 104
105/* undef below if compile with MFC */ 105/* undef below if compile with MFC */
106/* #define INCLUDEMFC 1 */ 106/* #define INCLUDEMFC 1 */
107 107
108#if defined(WIN32) || defined(_WIN32) 108#if defined(WIN32) || defined(_WIN32)
109#ifdef INCLUDEMFC 109#ifdef INCLUDEMFC
110#include <afx.h> 110#include <afx.h>
111#endif 111#endif
112#endif 112#endif
113 113
114#include <string.h> 114#include <string.h>
115#ifndef __MWERKS__ 115#ifndef __MWERKS__
116#include <stdlib.h> 116#include <stdlib.h>
117#endif 117#endif
118#include <stdio.h> 118#include <stdio.h>
119#include <stdlib.h> 119#include <stdlib.h>
120#include <ctype.h> 120#include <ctype.h>
121 121
122//#ifdef PALMTOPCENTER 122//#ifdef PALMTOPCENTER
123//#include <qpe/vobject_p.h> 123//#include <qpe/vobject_p.h>
124//#else 124//#else
125#include "vobject_p.h" 125#include <qtopia/private/vobject_p.h>
126//#endif 126//#endif
127 127
128/**** Types, Constants ****/ 128/**** Types, Constants ****/
129 129
130 #define YYDEBUG 0/* 1 to compile in some debugging code */ 130 #define YYDEBUG 0/* 1 to compile in some debugging code */
131 #define MAXTOKEN 256/* maximum token (line) length */ 131 #define MAXTOKEN 256/* maximum token (line) length */
132 #define YYSTACKSIZE 100// ~unref ? 132 #define YYSTACKSIZE 100// ~unref ?
133 #define MAXLEVEL 10/* max # of nested objects parseable */ 133 #define MAXLEVEL 10/* max # of nested objects parseable */
134 /* (includes outermost) */ 134 /* (includes outermost) */
135 135
136 136
137/**** Global Variables ****/ 137/**** Global Variables ****/
138int mime_lineNum, mime_numErrors; /* yyerror() can use these */ 138int mime_lineNum, mime_numErrors; /* yyerror() can use these */
139static VObject* vObjList; 139static VObject* vObjList;
140static VObject *curProp; 140static VObject *curProp;
141static VObject *curObj; 141static VObject *curObj;
142static VObject* ObjStack[MAXLEVEL]; 142static VObject* ObjStack[MAXLEVEL];
143static int ObjStackTop; 143static int ObjStackTop;
144 144
145 145
146/* A helpful utility for the rest of the app. */ 146/* A helpful utility for the rest of the app. */
147#if __CPLUSPLUS__ 147#if __CPLUSPLUS__
148extern "C" { 148extern "C" {
149#endif 149#endif
150 150
151 extern void yyerror(char *s); 151 extern void yyerror(char *s);
152 152
153#if __CPLUSPLUS__ 153#if __CPLUSPLUS__
154 }; 154 };
155#endif 155#endif
156 156
157int yyparse(); 157int yyparse();
158 158
159enum LexMode { 159enum LexMode {
160 L_NORMAL, 160 L_NORMAL,
161 L_VCARD, 161 L_VCARD,
162 L_VCAL, 162 L_VCAL,
163 L_VEVENT, 163 L_VEVENT,
164 L_VTODO, 164 L_VTODO,
165 L_VALUES, 165 L_VALUES,
166 L_BASE64, 166 L_BASE64,
167 L_QUOTED_PRINTABLE 167 L_QUOTED_PRINTABLE
168 }; 168 };
169 169
170/**** Private Forward Declarations ****/ 170/**** Private Forward Declarations ****/
171static int pushVObject(const char *prop); 171static int pushVObject(const char *prop);
172static VObject* popVObject(); 172static VObject* popVObject();
173static void lexPopMode(int top); 173static void lexPopMode(int top);
174static int lexWithinMode(enum LexMode mode); 174static int lexWithinMode(enum LexMode mode);
175static void lexPushMode(enum LexMode mode); 175static void lexPushMode(enum LexMode mode);
176static void enterProps(const char *s); 176static void enterProps(const char *s);
177static void enterAttr(const char *s1, const char *s2); 177static void enterAttr(const char *s1, const char *s2);
178static void enterValues(const char *value); 178static void enterValues(const char *value);
179#define mime_error yyerror 179#define mime_error yyerror
180void mime_error(char *s); 180void mime_error(char *s);
181void mime_error_(char *s); 181void mime_error_(char *s);
182 182
183%} 183%}
184 184
185/***************************************************************************/ 185/***************************************************************************/
186/*** The grammar ****/ 186/*** The grammar ****/
187/***************************************************************************/ 187/***************************************************************************/
188 188
189%union { 189%union {
190 char *str; 190 char *str;
191 VObject *vobj; 191 VObject *vobj;
192 } 192 }
193 193
194%token 194%token
195 EQ COLON DOT SEMICOLON SPACE HTAB LINESEP NEWLINE 195 EQ COLON DOT SEMICOLON SPACE HTAB LINESEP NEWLINE
196 BEGIN_VCARD END_VCARD BEGIN_VCAL END_VCAL 196 BEGIN_VCARD END_VCARD BEGIN_VCAL END_VCAL
197 BEGIN_VEVENT END_VEVENT BEGIN_VTODO END_VTODO 197 BEGIN_VEVENT END_VEVENT BEGIN_VTODO END_VTODO
198 ID 198 ID
199 199
200/* 200/*
201 * NEWLINE is the token that would occur outside a vCard, 201 * NEWLINE is the token that would occur outside a vCard,
202 * while LINESEP is the token that would occur inside a vCard. 202 * while LINESEP is the token that would occur inside a vCard.
203 */ 203 */
204 204
205%token <str> 205%token <str>
206 STRING ID 206 STRING ID
207 207
208%type <str> name value 208%type <str> name value
209 209
210%type <vobj> vcard vcal vobject 210%type <vobj> vcard vcal vobject
211 211
212%start mime 212%start mime
213 213
214%% 214%%
215 215
216 216
217mime: vobjects 217mime: vobjects
218 ; 218 ;
219 219
220vobjects: vobjects vobject 220vobjects: vobjects vobject
221 { addList(&vObjList, $2); curObj = 0; } 221 { addList(&vObjList, $2); curObj = 0; }
222 | vobject 222 | vobject
223 { addList(&vObjList, $1); curObj = 0; } 223 { addList(&vObjList, $1); curObj = 0; }
224 ; 224 ;
225 225
226vobject: vcard 226vobject: vcard
227 | vcal 227 | vcal
228 ; 228 ;
229 229
230vcard: 230vcard:
231 BEGIN_VCARD 231 BEGIN_VCARD
232 { 232 {
233 lexPushMode(L_VCARD); 233 lexPushMode(L_VCARD);
234 if (!pushVObject(VCCardProp)) YYERROR; 234 if (!pushVObject(VCCardProp)) YYERROR;
235 } 235 }
236 items END_VCARD 236 items END_VCARD
237 { 237 {
238 lexPopMode(0); 238 lexPopMode(0);
239 $$ = popVObject(); 239 $$ = popVObject();
240 } 240 }
241 | BEGIN_VCARD 241 | BEGIN_VCARD
242 { 242 {
243 lexPushMode(L_VCARD); 243 lexPushMode(L_VCARD);
244 if (!pushVObject(VCCardProp)) YYERROR; 244 if (!pushVObject(VCCardProp)) YYERROR;
245 } 245 }
246 END_VCARD 246 END_VCARD
247 { 247 {
248 lexPopMode(0); 248 lexPopMode(0);
249 $$ = popVObject(); 249 $$ = popVObject();
250 } 250 }
251 ; 251 ;
252 252
253items: items item 253items: items item
254 | item 254 | item
255 ; 255 ;
256 256
257item: prop COLON 257item: prop COLON
258 { 258 {
259 lexPushMode(L_VALUES); 259 lexPushMode(L_VALUES);
260 } 260 }
261 values LINESEP 261 values LINESEP
262 { 262 {
263 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE)) 263 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE))
264 lexPopMode(0); 264 lexPopMode(0);
265 lexPopMode(0); 265 lexPopMode(0);
266 } 266 }
267 | error 267 | error
268 ; 268 ;
269 269
270prop: name 270prop: name
271 { 271 {
272 enterProps($1); 272 enterProps($1);
273 } 273 }
274 attr_params 274 attr_params
275 | name 275 | name
276 { 276 {
277 enterProps($1); 277 enterProps($1);
278 } 278 }
279 ; 279 ;
280 280
281attr_params: attr_params attr_param 281attr_params: attr_params attr_param
282 | attr_param 282 | attr_param
283 ; 283 ;
284 284
285attr_param: SEMICOLON attr 285attr_param: SEMICOLON attr
286 ; 286 ;
287 287
288attr: name 288attr: name
289 { 289 {
290 enterAttr($1,0); 290 enterAttr($1,0);
291 } 291 }
292 | name EQ name 292 | name EQ name
293 { 293 {
294 enterAttr($1,$3); 294 enterAttr($1,$3);
295 295
296 } 296 }
297 ; 297 ;
298 298
299name: ID 299name: ID
300 ; 300 ;
301 301
302values: value SEMICOLON { enterValues($1); } values 302values: value SEMICOLON { enterValues($1); } values
303 | value 303 | value
304 { enterValues($1); } 304 { enterValues($1); }
305 ; 305 ;
306 306
307value: STRING 307value: STRING
308 | 308 |
309 { $$ = 0; } 309 { $$ = 0; }
310 ; 310 ;
311 311
312vcal: 312vcal:
313 BEGIN_VCAL 313 BEGIN_VCAL
314 { if (!pushVObject(VCCalProp)) YYERROR; } 314 { if (!pushVObject(VCCalProp)) YYERROR; }
315 calitems 315 calitems
316 END_VCAL 316 END_VCAL
317 { $$ = popVObject(); } 317 { $$ = popVObject(); }
318 | BEGIN_VCAL 318 | BEGIN_VCAL
319 { if (!pushVObject(VCCalProp)) YYERROR; } 319 { if (!pushVObject(VCCalProp)) YYERROR; }
320 END_VCAL 320 END_VCAL
321 { $$ = popVObject(); } 321 { $$ = popVObject(); }
322 ; 322 ;
323 323
324calitems: calitems calitem 324calitems: calitems calitem
325 | calitem 325 | calitem
326 ; 326 ;
327 327
328calitem: 328calitem:
329 eventitem 329 eventitem
330 | todoitem 330 | todoitem
331 | items 331 | items
332 ; 332 ;
333 333
334eventitem: 334eventitem:
335 BEGIN_VEVENT 335 BEGIN_VEVENT
336 { 336 {
337 lexPushMode(L_VEVENT); 337 lexPushMode(L_VEVENT);
338 if (!pushVObject(VCEventProp)) YYERROR; 338 if (!pushVObject(VCEventProp)) YYERROR;
339 } 339 }
340 items 340 items
341 END_VEVENT 341 END_VEVENT
342 { 342 {
343 lexPopMode(0); 343 lexPopMode(0);
344 popVObject(); 344 popVObject();
345 } 345 }
346 | BEGIN_VEVENT 346 | BEGIN_VEVENT
347 { 347 {
348 lexPushMode(L_VEVENT); 348 lexPushMode(L_VEVENT);
349 if (!pushVObject(VCEventProp)) YYERROR; 349 if (!pushVObject(VCEventProp)) YYERROR;
350 } 350 }
351 END_VEVENT 351 END_VEVENT
352 { 352 {
353 lexPopMode(0); 353 lexPopMode(0);
354 popVObject(); 354 popVObject();
355 } 355 }
356 ; 356 ;
357 357
358todoitem: 358todoitem:
359 BEGIN_VTODO 359 BEGIN_VTODO
360 { 360 {
361 lexPushMode(L_VTODO); 361 lexPushMode(L_VTODO);
362 if (!pushVObject(VCTodoProp)) YYERROR; 362 if (!pushVObject(VCTodoProp)) YYERROR;
363 } 363 }
364 items 364 items
365 END_VTODO 365 END_VTODO
366 { 366 {
367 lexPopMode(0); 367 lexPopMode(0);
368 popVObject(); 368 popVObject();
369 } 369 }
370 | BEGIN_VTODO 370 | BEGIN_VTODO
371 { 371 {
372 lexPushMode(L_VTODO); 372 lexPushMode(L_VTODO);
373 if (!pushVObject(VCTodoProp)) YYERROR; 373 if (!pushVObject(VCTodoProp)) YYERROR;
374 } 374 }
375 END_VTODO 375 END_VTODO
376 { 376 {
377 lexPopMode(0); 377 lexPopMode(0);
378 popVObject(); 378 popVObject();
379 } 379 }
380 ; 380 ;
381 381
382%% 382%%
383/*------------------------------------*/ 383/*------------------------------------*/
384static int pushVObject(const char *prop) 384static int pushVObject(const char *prop)
385 { 385 {
386 VObject *newObj; 386 VObject *newObj;
387 if (ObjStackTop == MAXLEVEL) 387 if (ObjStackTop == MAXLEVEL)
388 return FALSE; 388 return FALSE;
389 389
390 ObjStack[++ObjStackTop] = curObj; 390 ObjStack[++ObjStackTop] = curObj;
391 391
392 if (curObj) { 392 if (curObj) {
393 newObj = addProp(curObj,prop); 393 newObj = addProp(curObj,prop);
394 curObj = newObj; 394 curObj = newObj;
395 } 395 }
396 else 396 else
397 curObj = newVObject(prop); 397 curObj = newVObject(prop);
398 398
399 return TRUE; 399 return TRUE;
400 } 400 }
401 401
402 402
403/*---------------------------------------*/ 403/*---------------------------------------*/
404/* This pops the recently built vCard off the stack and returns it. */ 404/* This pops the recently built vCard off the stack and returns it. */
405static VObject* popVObject() 405static VObject* popVObject()
406 { 406 {
407 VObject *oldObj; 407 VObject *oldObj;
408 if (ObjStackTop < 0) { 408 if (ObjStackTop < 0) {
409 yyerror("pop on empty Object Stack\n"); 409 yyerror("pop on empty Object Stack\n");
410 return 0; 410 return 0;
411 } 411 }
412 oldObj = curObj; 412 oldObj = curObj;
413 curObj = ObjStack[ObjStackTop--]; 413 curObj = ObjStack[ObjStackTop--];
414 414
415 return oldObj; 415 return oldObj;
416 } 416 }
417 417
418 418
419static void enterValues(const char *value) 419static void enterValues(const char *value)
420 { 420 {
421 if (fieldedProp && *fieldedProp) { 421 if (fieldedProp && *fieldedProp) {
422 if (value) { 422 if (value) {
423 addPropValue(curProp,*fieldedProp,value); 423 addPropValue(curProp,*fieldedProp,value);
424 } 424 }
425 /* else this field is empty, advance to next field */ 425 /* else this field is empty, advance to next field */
426 fieldedProp++; 426 fieldedProp++;
427 } 427 }
428 else { 428 else {
429 if (value) { 429 if (value) {
430 setVObjectStringZValue_(curProp,strdup( value )); 430 setVObjectStringZValue_(curProp,strdup( value ));
431 } 431 }
432 } 432 }
433 deleteStr(value); 433 deleteStr(value);
434 } 434 }
435 435
436static void enterProps(const char *s) 436static void enterProps(const char *s)
437 { 437 {
438 curProp = addGroup(curObj,s); 438 curProp = addGroup(curObj,s);
439 deleteStr(s); 439 deleteStr(s);
440 } 440 }
441 441
442static void enterAttr(const char *s1, const char *s2) 442static void enterAttr(const char *s1, const char *s2)
443 { 443 {
444 const char *p1, *p2; 444 const char *p1, *p2;
445 p1 = lookupProp_(s1); 445 p1 = lookupProp_(s1);
446 if (s2) { 446 if (s2) {
447 VObject *a; 447 VObject *a;
448 p2 = lookupProp_(s2); 448 p2 = lookupProp_(s2);
449 a = addProp(curProp,p1); 449 a = addProp(curProp,p1);
450 setVObjectStringZValue(a,p2); 450 setVObjectStringZValue(a,p2);
451 } 451 }
452 else 452 else
453 addProp(curProp,p1); 453 addProp(curProp,p1);
454 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0)) 454 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0))
455 lexPushMode(L_BASE64); 455 lexPushMode(L_BASE64);
456 else if (qstricmp(p1,VCQuotedPrintableProp) == 0 456 else if (qstricmp(p1,VCQuotedPrintableProp) == 0
457 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0)) 457 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0))
458 lexPushMode(L_QUOTED_PRINTABLE); 458 lexPushMode(L_QUOTED_PRINTABLE);
459 deleteStr(s1); deleteStr(s2); 459 deleteStr(s1); deleteStr(s2);
460 } 460 }
461 461
462 462
463#define MAX_LEX_LOOKAHEAD_0 32 463#define MAX_LEX_LOOKAHEAD_0 32
464#define MAX_LEX_LOOKAHEAD 64 464#define MAX_LEX_LOOKAHEAD 64
465#define MAX_LEX_MODE_STACK_SIZE 10 465#define MAX_LEX_MODE_STACK_SIZE 10
466#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop]) 466#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop])
467 467
468struct LexBuf { 468struct LexBuf {
469 /* input */ 469 /* input */
470#ifdef INCLUDEMFC 470#ifdef INCLUDEMFC
471 CFile *inputFile; 471 CFile *inputFile;
472#else 472#else
473 FILE *inputFile; 473 FILE *inputFile;
474#endif 474#endif
475 char *inputString; 475 char *inputString;
476 unsigned long curPos; 476 unsigned long curPos;
477 unsigned long inputLen; 477 unsigned long inputLen;
478 /* lookahead buffer */ 478 /* lookahead buffer */
479 /* -- lookahead buffer is short instead of char so that EOF 479 /* -- lookahead buffer is short instead of char so that EOF
480 / can be represented correctly. 480 / can be represented correctly.
481 */ 481 */
482 unsigned long len; 482 unsigned long len;
483 short buf[MAX_LEX_LOOKAHEAD]; 483 short buf[MAX_LEX_LOOKAHEAD];
484 unsigned long getPtr; 484 unsigned long getPtr;
485 /* context stack */ 485 /* context stack */
486 unsigned long lexModeStackTop; 486 unsigned long lexModeStackTop;
487 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE]; 487 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE];
488 /* token buffer */ 488 /* token buffer */
489 unsigned long maxToken; 489 unsigned long maxToken;
490 char *strs; 490 char *strs;
491 unsigned long strsLen; 491 unsigned long strsLen;
492 } lexBuf; 492 } lexBuf;
493 493
494static void lexPushMode(enum LexMode mode) 494static void lexPushMode(enum LexMode mode)
495 { 495 {
496 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1)) 496 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1))
497 yyerror("lexical context stack overflow"); 497 yyerror("lexical context stack overflow");
498 else { 498 else {
499 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode; 499 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode;
500 } 500 }
501 } 501 }
502 502
503static void lexPopMode(int top) 503static void lexPopMode(int top)
504 { 504 {
505 /* special case of pop for ease of error recovery -- this 505 /* special case of pop for ease of error recovery -- this
506 version will never underflow */ 506 version will never underflow */
507 if (top) 507 if (top)
508 lexBuf.lexModeStackTop = 0; 508 lexBuf.lexModeStackTop = 0;
509 else 509 else
510 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--; 510 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--;
511 } 511 }
512 512
513static int lexWithinMode(enum LexMode mode) { 513static int lexWithinMode(enum LexMode mode) {
514 unsigned long i; 514 unsigned long i;
515 for (i=0;i<lexBuf.lexModeStackTop;i++) 515 for (i=0;i<lexBuf.lexModeStackTop;i++)
516 if (mode == lexBuf.lexModeStack[i]) return 1; 516 if (mode == lexBuf.lexModeStack[i]) return 1;
517 return 0; 517 return 0;
518 } 518 }
519 519
520static int lexGetc_() 520static int lexGetc_()
521 { 521 {
522 /* get next char from input, no buffering. */ 522 /* get next char from input, no buffering. */
523 if (lexBuf.curPos == lexBuf.inputLen) 523 if (lexBuf.curPos == lexBuf.inputLen)
524 return EOF; 524 return EOF;
525 else if (lexBuf.inputString) 525 else if (lexBuf.inputString)
526 return *(lexBuf.inputString + lexBuf.curPos++); 526 return *(lexBuf.inputString + lexBuf.curPos++);
527 else { 527 else {
528#ifdef INCLUDEMFC 528#ifdef INCLUDEMFC
529 char result; 529 char result;
530 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF; 530 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF;
531#else 531#else
532 return fgetc(lexBuf.inputFile); 532 return fgetc(lexBuf.inputFile);
533#endif 533#endif
534 } 534 }
535 } 535 }
536 536
537static int lexGeta() 537static int lexGeta()
538 { 538 {
539 ++lexBuf.len; 539 ++lexBuf.len;
540 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_()); 540 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_());
541 } 541 }
542 542
543static int lexGeta_(int i) 543static int lexGeta_(int i)
544 { 544 {
545 ++lexBuf.len; 545 ++lexBuf.len;
546 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_()); 546 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_());
547 } 547 }
548 548
549static void lexSkipLookahead() { 549static void lexSkipLookahead() {
550 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 550 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
551 /* don't skip EOF. */ 551 /* don't skip EOF. */
552 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 552 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
553 lexBuf.len--; 553 lexBuf.len--;
554 } 554 }
555 } 555 }
556 556
557static int lexLookahead() { 557static int lexLookahead() {
558 int c = (lexBuf.len)? 558 int c = (lexBuf.len)?
559 lexBuf.buf[lexBuf.getPtr]: 559 lexBuf.buf[lexBuf.getPtr]:
560 lexGeta(); 560 lexGeta();
561 /* do the \r\n -> \n or \r -> \n translation here */ 561 /* do the \r\n -> \n or \r -> \n translation here */
562 if (c == '\r') { 562 if (c == '\r') {
563 int a = (lexBuf.len>1)? 563 int a = (lexBuf.len>1)?
564 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]: 564 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]:
565 lexGeta_(1); 565 lexGeta_(1);
566 if (a == '\n') { 566 if (a == '\n') {
567 lexSkipLookahead(); 567 lexSkipLookahead();
568 } 568 }
569 lexBuf.buf[lexBuf.getPtr] = c = '\n'; 569 lexBuf.buf[lexBuf.getPtr] = c = '\n';
570 } 570 }
571 else if (c == '\n') { 571 else if (c == '\n') {
572 int a = (lexBuf.len>1)? 572 int a = (lexBuf.len>1)?
573 lexBuf.buf[lexBuf.getPtr+1]: 573 lexBuf.buf[lexBuf.getPtr+1]:
574 lexGeta_(1); 574 lexGeta_(1);
575 if (a == '\r') { 575 if (a == '\r') {
576 lexSkipLookahead(); 576 lexSkipLookahead();
577 } 577 }
578 lexBuf.buf[lexBuf.getPtr] = '\n'; 578 lexBuf.buf[lexBuf.getPtr] = '\n';
579 } 579 }
580 return c; 580 return c;
581 } 581 }
582 582
583static int lexGetc() { 583static int lexGetc() {
584 int c = lexLookahead(); 584 int c = lexLookahead();
585 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 585 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
586 /* EOF will remain in lookahead buffer */ 586 /* EOF will remain in lookahead buffer */
587 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 587 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
588 lexBuf.len--; 588 lexBuf.len--;
589 } 589 }
590 return c; 590 return c;
591 } 591 }
592 592
593static void lexSkipLookaheadWord() { 593static void lexSkipLookaheadWord() {
594 if (lexBuf.strsLen <= lexBuf.len) { 594 if (lexBuf.strsLen <= lexBuf.len) {
595 lexBuf.len -= lexBuf.strsLen; 595 lexBuf.len -= lexBuf.strsLen;
596 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; 596 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD;
597 } 597 }
598 } 598 }
599 599
600static void lexClearToken() 600static void lexClearToken()
601 { 601 {
602 lexBuf.strsLen = 0; 602 lexBuf.strsLen = 0;
603 } 603 }
604 604
605static void lexAppendc(int c) 605static void lexAppendc(int c)
606 { 606 {
607 lexBuf.strs[lexBuf.strsLen] = c; 607 lexBuf.strs[lexBuf.strsLen] = c;
608 /* append up to zero termination */ 608 /* append up to zero termination */
609 if (c == 0) return; 609 if (c == 0) return;
610 lexBuf.strsLen++; 610 lexBuf.strsLen++;
611 if (lexBuf.strsLen > lexBuf.maxToken) { 611 if (lexBuf.strsLen > lexBuf.maxToken) {
612 /* double the token string size */ 612 /* double the token string size */
613 lexBuf.maxToken <<= 1; 613 lexBuf.maxToken <<= 1;
614 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken); 614 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken);
615 } 615 }
616 } 616 }
617 617
618static char* lexStr() { 618static char* lexStr() {
619 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); 619 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1);
620 } 620 }
621 621
622static void lexSkipWhite() { 622static void lexSkipWhite() {
623 int c = lexLookahead(); 623 int c = lexLookahead();
624 while (c == ' ' || c == '\t') { 624 while (c == ' ' || c == '\t') {
625 lexSkipLookahead(); 625 lexSkipLookahead();
626 c = lexLookahead(); 626 c = lexLookahead();
627 } 627 }
628 } 628 }
629 629
630static char* lexGetWord() { 630static char* lexGetWord() {
631 int c; 631 int c;
632 lexSkipWhite(); 632 lexSkipWhite();
633 lexClearToken(); 633 lexClearToken();
634 c = lexLookahead(); 634 c = lexLookahead();
635 while (c != EOF && !strchr("\t\n ;:=",c)) { 635 while (c != EOF && !strchr("\t\n ;:=",c)) {
636 lexAppendc(c); 636 lexAppendc(c);
637 lexSkipLookahead(); 637 lexSkipLookahead();
638 c = lexLookahead(); 638 c = lexLookahead();
639 } 639 }
640 lexAppendc(0); 640 lexAppendc(0);
641 return lexStr(); 641 return lexStr();
642 } 642 }
643 643
644static void lexPushLookaheadc(int c) { 644static void lexPushLookaheadc(int c) {
645 int putptr; 645 int putptr;
646 /* can't putback EOF, because it never leaves lookahead buffer */ 646 /* can't putback EOF, because it never leaves lookahead buffer */
647 if (c == EOF) return; 647 if (c == EOF) return;
648 putptr = (int)lexBuf.getPtr - 1; 648 putptr = (int)lexBuf.getPtr - 1;
649 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; 649 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD;
650 lexBuf.getPtr = putptr; 650 lexBuf.getPtr = putptr;
651 lexBuf.buf[putptr] = c; 651 lexBuf.buf[putptr] = c;
652 lexBuf.len += 1; 652 lexBuf.len += 1;
653 } 653 }
654 654
655static char* lexLookaheadWord() { 655static char* lexLookaheadWord() {
656 /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 656 /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0
657 / and thing bigger than that will stop the lookahead and return 0; 657 / and thing bigger than that will stop the lookahead and return 0;
658 / leading white spaces are not recoverable. 658 / leading white spaces are not recoverable.
659 */ 659 */
660 int c; 660 int c;
661 int len = 0; 661 int len = 0;
662 int curgetptr = 0; 662 int curgetptr = 0;
663 lexSkipWhite(); 663 lexSkipWhite();
664 lexClearToken(); 664 lexClearToken();
665 curgetptr = (int)lexBuf.getPtr;// remember! 665 curgetptr = (int)lexBuf.getPtr;// remember!
666 while (len < (MAX_LEX_LOOKAHEAD_0)) { 666 while (len < (MAX_LEX_LOOKAHEAD_0)) {
667 c = lexGetc(); 667 c = lexGetc();
668 len++; 668 len++;
669 if (c == EOF || strchr("\t\n ;:=", c)) { 669 if (c == EOF || strchr("\t\n ;:=", c)) {
670 lexAppendc(0); 670 lexAppendc(0);
671 /* restore lookahead buf. */ 671 /* restore lookahead buf. */
672 lexBuf.len += len; 672 lexBuf.len += len;
673 lexBuf.getPtr = curgetptr; 673 lexBuf.getPtr = curgetptr;
674 return lexStr(); 674 return lexStr();
675 } 675 }
676 else 676 else
677 lexAppendc(c); 677 lexAppendc(c);
678 } 678 }
679 lexBuf.len += len;/* char that has been moved to lookahead buffer */ 679 lexBuf.len += len;/* char that has been moved to lookahead buffer */
680 lexBuf.getPtr = curgetptr; 680 lexBuf.getPtr = curgetptr;
681 return 0; 681 return 0;
682 } 682 }
683 683
684#ifdef _SUPPORT_LINE_FOLDING 684#ifdef _SUPPORT_LINE_FOLDING
685static void handleMoreRFC822LineBreak(int c) { 685static void handleMoreRFC822LineBreak(int c) {
686 /* suport RFC 822 line break in cases like 686 /* suport RFC 822 line break in cases like
687 *ADR: foo; 687 *ADR: foo;
688 * morefoo; 688 * morefoo;
689 * more foo; 689 * more foo;
690 */ 690 */
691 if (c == ';') { 691 if (c == ';') {
692 int a; 692 int a;
693 lexSkipLookahead(); 693 lexSkipLookahead();
694 /* skip white spaces */ 694 /* skip white spaces */
695 a = lexLookahead(); 695 a = lexLookahead();
696 while (a == ' ' || a == '\t') { 696 while (a == ' ' || a == '\t') {
697 lexSkipLookahead(); 697 lexSkipLookahead();
698 a = lexLookahead(); 698 a = lexLookahead();
699 } 699 }
700 if (a == '\n') { 700 if (a == '\n') {
701 lexSkipLookahead(); 701 lexSkipLookahead();
702 a = lexLookahead(); 702 a = lexLookahead();
703 if (a == ' ' || a == '\t') { 703 if (a == ' ' || a == '\t') {
704 /* continuation, throw away all the \n and spaces read so 704 /* continuation, throw away all the \n and spaces read so
705 * far 705 * far
706 */ 706 */
707 lexSkipWhite(); 707 lexSkipWhite();
708 lexPushLookaheadc(';'); 708 lexPushLookaheadc(';');
709 } 709 }
710 else { 710 else {
711 lexPushLookaheadc('\n'); 711 lexPushLookaheadc('\n');
712 lexPushLookaheadc(';'); 712 lexPushLookaheadc(';');
713 } 713 }
714 } 714 }
715 else { 715 else {
716 lexPushLookaheadc(';'); 716 lexPushLookaheadc(';');
717 } 717 }
718 } 718 }
719 } 719 }
720 720
721static char* lexGet1Value() { 721static char* lexGet1Value() {
722 int c; 722 int c;
723 lexSkipWhite(); 723 lexSkipWhite();
724 c = lexLookahead(); 724 c = lexLookahead();
725 lexClearToken(); 725 lexClearToken();
726 while (c != EOF && c != ';') { 726 while (c != EOF && c != ';') {
727 if (c == '\\' ) { 727 if (c == '\\' ) {
728 int a; 728 int a;
729 lexSkipLookahead(); 729 lexSkipLookahead();
730 a = lexLookahead(); 730 a = lexLookahead();
731 if ( a != ';' ) { 731 if ( a != ';' ) {
732 lexAppendc('\\'); 732 lexAppendc('\\');
733 } else { 733 } else {
734 lexAppendc( ';' ); 734 lexAppendc( ';' );
735 lexSkipLookahead(); 735 lexSkipLookahead();
736 } 736 }
737 } else if (c == '\n') { 737 } else if (c == '\n') {
738 int a; 738 int a;
739 lexSkipLookahead(); 739 lexSkipLookahead();
740 a = lexLookahead(); 740 a = lexLookahead();
741 if (a == ' ' || a == '\t') { 741 if (a == ' ' || a == '\t') {
742 lexAppendc(' '); 742 lexAppendc(' ');
743 lexSkipLookahead(); 743 lexSkipLookahead();
744 } 744 }
745 else { 745 else {
746 lexPushLookaheadc('\n'); 746 lexPushLookaheadc('\n');
747 break; 747 break;
748 } 748 }
749 } 749 }
750 else { 750 else {
751 lexAppendc(c); 751 lexAppendc(c);
752 lexSkipLookahead(); 752 lexSkipLookahead();
753 } 753 }
754 c = lexLookahead(); 754 c = lexLookahead();
755 } 755 }
756 lexAppendc(0); 756 lexAppendc(0);
757 handleMoreRFC822LineBreak(c); 757 handleMoreRFC822LineBreak(c);
758 return c==EOF?0:lexStr(); 758 return c==EOF?0:lexStr();
759 } 759 }
760#endif 760#endif
761 761
762static int match_begin_name(int end) { 762static int match_begin_name(int end) {
763 char *n = lexLookaheadWord(); 763 char *n = lexLookaheadWord();
764 int token = ID; 764 int token = ID;
765 if (n) { 765 if (n) {
766 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD; 766 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD;
767 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL; 767 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL;
768 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT; 768 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT;
769 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO; 769 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO;
770 deleteStr(n); 770 deleteStr(n);
771 return token; 771 return token;
772 } 772 }
773 return 0; 773 return 0;
774 } 774 }
775 775
776 776
777#ifdef INCLUDEMFC 777#ifdef INCLUDEMFC
778void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile) 778void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile)
779#else 779#else
780void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) 780void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile)
781#endif 781#endif
782 { 782 {
783 // initialize lex mode stack 783 // initialize lex mode stack
784 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL; 784 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL;
785 785
786 // iniatialize lex buffer. 786 // iniatialize lex buffer.
787 lexBuf.inputString = (char*) inputstring; 787 lexBuf.inputString = (char*) inputstring;
788 lexBuf.inputLen = inputlen; 788 lexBuf.inputLen = inputlen;
789 lexBuf.curPos = 0; 789 lexBuf.curPos = 0;
790 lexBuf.inputFile = inputfile; 790 lexBuf.inputFile = inputfile;
791 791
792 lexBuf.len = 0; 792 lexBuf.len = 0;
793 lexBuf.getPtr = 0; 793 lexBuf.getPtr = 0;
794 794
795 lexBuf.maxToken = MAXTOKEN; 795 lexBuf.maxToken = MAXTOKEN;
796 lexBuf.strs = (char*)malloc(MAXTOKEN); 796 lexBuf.strs = (char*)malloc(MAXTOKEN);
797 lexBuf.strsLen = 0; 797 lexBuf.strsLen = 0;
798 798
799 } 799 }
800 800
801static void finiLex() { 801static void finiLex() {
802 free(lexBuf.strs); 802 free(lexBuf.strs);
803 } 803 }
804 804
805 805
806/*-----------------------------------*/ 806/*-----------------------------------*/
807/* This parses and converts the base64 format for binary encoding into 807/* This parses and converts the base64 format for binary encoding into
808 * a decoded buffer (allocated with new). See RFC 1521. 808 * a decoded buffer (allocated with new). See RFC 1521.
809 */ 809 */
810static char * lexGetDataFromBase64() 810static char * lexGetDataFromBase64()
811 { 811 {
812 unsigned long bytesLen = 0, bytesMax = 0; 812 unsigned long bytesLen = 0, bytesMax = 0;
813 int quadIx = 0, pad = 0; 813 int quadIx = 0, pad = 0;
814 unsigned long trip = 0; 814 unsigned long trip = 0;
815 unsigned char b; 815 unsigned char b;
816 int c; 816 int c;
817 unsigned char *bytes = NULL; 817 unsigned char *bytes = NULL;
818 unsigned char *oldBytes = NULL; 818 unsigned char *oldBytes = NULL;
819 819
820 DBG_(("db: lexGetDataFromBase64\n")); 820 DBG_(("db: lexGetDataFromBase64\n"));
821 while (1) { 821 while (1) {
822 c = lexGetc(); 822 c = lexGetc();
823 if (c == '\n') { 823 if (c == '\n') {
824 ++mime_lineNum; 824 ++mime_lineNum;
825 if (lexLookahead() == '\n') { 825 if (lexLookahead() == '\n') {
826 /* a '\n' character by itself means end of data */ 826 /* a '\n' character by itself means end of data */
827 break; 827 break;
828 } 828 }
829 else continue; /* ignore '\n' */ 829 else continue; /* ignore '\n' */
830 } 830 }
831 else { 831 else {
832 if ((c >= 'A') && (c <= 'Z')) 832 if ((c >= 'A') && (c <= 'Z'))
833 b = (unsigned char)(c - 'A'); 833 b = (unsigned char)(c - 'A');
834 else if ((c >= 'a') && (c <= 'z')) 834 else if ((c >= 'a') && (c <= 'z'))
835 b = (unsigned char)(c - 'a') + 26; 835 b = (unsigned char)(c - 'a') + 26;
836 else if ((c >= '0') && (c <= '9')) 836 else if ((c >= '0') && (c <= '9'))
837 b = (unsigned char)(c - '0') + 52; 837 b = (unsigned char)(c - '0') + 52;
838 else if (c == '+') 838 else if (c == '+')
839 b = 62; 839 b = 62;
840 else if (c == '/') 840 else if (c == '/')
841 b = 63; 841 b = 63;
842 else if (c == '=') { 842 else if (c == '=') {
843 b = 0; 843 b = 0;
844 pad++; 844 pad++;
845 } else if ((c == ' ') || (c == '\t')) { 845 } else if ((c == ' ') || (c == '\t')) {
846 continue; 846 continue;
847 } else { /* error condition */ 847 } else { /* error condition */
848 if (bytes) free(bytes); 848 if (bytes) free(bytes);
849 else if (oldBytes) free(oldBytes); 849 else if (oldBytes) free(oldBytes);
850 // error recovery: skip until 2 adjacent newlines. 850 // error recovery: skip until 2 adjacent newlines.
851 DBG_(("db: invalid character 0x%x '%c'\n", c,c)); 851 DBG_(("db: invalid character 0x%x '%c'\n", c,c));
852 if (c != EOF) { 852 if (c != EOF) {
853 c = lexGetc(); 853 c = lexGetc();
854 while (c != EOF) { 854 while (c != EOF) {
855 if (c == '\n' && lexLookahead() == '\n') { 855 if (c == '\n' && lexLookahead() == '\n') {
856 ++mime_lineNum; 856 ++mime_lineNum;
857 break; 857 break;
858 } 858 }
859 c = lexGetc(); 859 c = lexGetc();
860 } 860 }
861 } 861 }
862 return NULL; 862 return NULL;
863 } 863 }
864 trip = (trip << 6) | b; 864 trip = (trip << 6) | b;
865 if (++quadIx == 4) { 865 if (++quadIx == 4) {
866 unsigned char outBytes[3]; 866 unsigned char outBytes[3];
867 int numOut; 867 int numOut;
868 int i; 868 int i;
869 for (i = 0; i < 3; i++) { 869 for (i = 0; i < 3; i++) {
870 outBytes[2-i] = (unsigned char)(trip & 0xFF); 870 outBytes[2-i] = (unsigned char)(trip & 0xFF);
871 trip >>= 8; 871 trip >>= 8;
872 } 872 }
873 numOut = 3 - pad; 873 numOut = 3 - pad;
874 if (bytesLen + numOut > bytesMax) { 874 if (bytesLen + numOut > bytesMax) {
875 if (!bytes) { 875 if (!bytes) {
876 bytesMax = 1024; 876 bytesMax = 1024;
877 bytes = (unsigned char*)malloc((size_t)bytesMax); 877 bytes = (unsigned char*)malloc((size_t)bytesMax);
878 } 878 }
879 else { 879 else {
880 bytesMax <<= 2; 880 bytesMax <<= 2;
881 oldBytes = bytes; 881 oldBytes = bytes;
882 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax); 882 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax);
883 } 883 }
884 if (bytes == 0) { 884 if (bytes == 0) {
885 mime_error("out of memory while processing BASE64 data\n"); 885 mime_error("out of memory while processing BASE64 data\n");
886 } 886 }
887 } 887 }
888 if (bytes) { 888 if (bytes) {
889 memcpy(bytes + bytesLen, outBytes, numOut); 889 memcpy(bytes + bytesLen, outBytes, numOut);
890 bytesLen += numOut; 890 bytesLen += numOut;
891 } 891 }
892 trip = 0; 892 trip = 0;
893 quadIx = 0; 893 quadIx = 0;
894 } 894 }
895 } 895 }
896 } /* while */ 896 } /* while */
897 DBG_(("db: bytesLen = %d\n", bytesLen)); 897 DBG_(("db: bytesLen = %d\n", bytesLen));
898 /* kludge: all this won't be necessary if we have tree form 898 /* kludge: all this won't be necessary if we have tree form
899 representation */ 899 representation */
900 if (bytes) { 900 if (bytes) {
901 setValueWithSize(curProp,bytes,(unsigned int)bytesLen); 901 setValueWithSize(curProp,bytes,(unsigned int)bytesLen);
902 free(bytes); 902 free(bytes);
903 } 903 }
904 else if (oldBytes) { 904 else if (oldBytes) {
905 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); 905 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen);
906 free(oldBytes); 906 free(oldBytes);
907 } 907 }
908 return 0; 908 return 0;
909 } 909 }
910 910
911static int match_begin_end_name(int end) { 911static int match_begin_end_name(int end) {
912 int token; 912 int token;
913 lexSkipWhite(); 913 lexSkipWhite();
914 if (lexLookahead() != ':') return ID; 914 if (lexLookahead() != ':') return ID;
915 lexSkipLookahead(); 915 lexSkipLookahead();
916 lexSkipWhite(); 916 lexSkipWhite();
917 token = match_begin_name(end); 917 token = match_begin_name(end);
918 if (token == ID) { 918 if (token == ID) {
919 lexPushLookaheadc(':'); 919 lexPushLookaheadc(':');
920 DBG_(("db: ID '%s'\n", yylval.str)); 920 DBG_(("db: ID '%s'\n", yylval.str));
921 return ID; 921 return ID;
922 } 922 }
923 else if (token != 0) { 923 else if (token != 0) {
924 lexSkipLookaheadWord(); 924 lexSkipLookaheadWord();
925 deleteStr(yylval.str); 925 deleteStr(yylval.str);
926 DBG_(("db: begin/end %d\n", token)); 926 DBG_(("db: begin/end %d\n", token));
927 return token; 927 return token;
928 } 928 }
929 return 0; 929 return 0;
930 } 930 }
931 931
932static char* lexGetQuotedPrintable() 932static char* lexGetQuotedPrintable()
933{ 933{
934 int c; 934 int c;
935 lexSkipWhite(); 935 lexSkipWhite();
936 c = lexLookahead(); 936 c = lexLookahead();
937 lexClearToken(); 937 lexClearToken();
938 938
939 while (c != EOF && c != ';') { 939 while (c != EOF && c != ';') {
940 if (c == '\n') { 940 if (c == '\n') {
941 // break, leave '\n' on remaining chars. 941 // break, leave '\n' on remaining chars.
942 break; 942 break;
943 } else if (c == '=') { 943 } else if (c == '=') {
944 int cur = 0; 944 int cur = 0;
945 int next; 945 int next;
946 946
947 lexSkipLookahead(); // skip '=' 947 lexSkipLookahead(); // skip '='
948 next = lexLookahead(); 948 next = lexLookahead();
949 949
950 if (next == '\n') { 950 if (next == '\n') {
951 // skip and only skip the \n 951 // skip and only skip the \n
952 lexSkipLookahead(); 952 lexSkipLookahead();
953 c = lexLookahead(); 953 c = lexLookahead();
954 ++mime_lineNum; // aid in error reporting 954 ++mime_lineNum; // aid in error reporting
955 continue; 955 continue;
956 } else if (next >= '0' && next <= '9') { 956 } else if (next >= '0' && next <= '9') {
957 cur = next - '0'; 957 cur = next - '0';
958 } else if (next >= 'A' && next <= 'F') { 958 } else if (next >= 'A' && next <= 'F') {
959 cur = next - 'A' + 10; 959 cur = next - 'A' + 10;
960 } else { 960 } else {
961 // we have been sent buggy stuff. doesn't matter 961 // we have been sent buggy stuff. doesn't matter
962 // what we do so long as we keep going. 962 // what we do so long as we keep going.
963 // should probably spit an error here 963 // should probably spit an error here
964 c = lexLookahead(); 964 c = lexLookahead();
965 continue; 965 continue;
966 } 966 }
967 967
968 lexSkipLookahead(); // skip A-Z0-9 968 lexSkipLookahead(); // skip A-Z0-9
969 next = lexLookahead(); 969 next = lexLookahead();
970 970
971 cur = cur * 16; 971 cur = cur * 16;
972 // this time really just expecting 0-9A-F 972 // this time really just expecting 0-9A-F
973 if (next >= '0' && next <= '9') { 973 if (next >= '0' && next <= '9') {
974 cur += next - '0'; 974 cur += next - '0';
975 } else if (next >= 'A' && next <= 'F') { 975 } else if (next >= 'A' && next <= 'F') {
976 cur += next - 'A' + 10; 976 cur += next - 'A' + 10;
977 } else { 977 } else {
978 // we have been sent buggy stuff. doesn't matter 978 // we have been sent buggy stuff. doesn't matter
979 // what we do so long as we keep going. 979 // what we do so long as we keep going.
980 // should probably spit an error here 980 // should probably spit an error here
981 c = lexLookahead(); 981 c = lexLookahead();
982 continue; 982 continue;
983 } 983 }
984 984
985 // got a valid escaped =. append it. 985 // got a valid escaped =. append it.
986 lexSkipLookahead(); // skip second 0-9A-F 986 lexSkipLookahead(); // skip second 0-9A-F
987 lexAppendc(cur); 987 lexAppendc(cur);
988 } else { 988 } else {
989 lexSkipLookahead(); // skip whatever we just read. 989 lexSkipLookahead(); // skip whatever we just read.
990 lexAppendc(c); // and append it. 990 lexAppendc(c); // and append it.
991 } 991 }
992 c = lexLookahead(); 992 c = lexLookahead();
993 } 993 }
994 lexAppendc(0); 994 lexAppendc(0);
995 return c==EOF?0:lexStr(); 995 return c==EOF?0:lexStr();
996} 996}
997 997
998static int yylex() { 998static int yylex() {
999 999
1000 int lexmode = LEXMODE(); 1000 int lexmode = LEXMODE();
1001 if (lexmode == L_VALUES) { 1001 if (lexmode == L_VALUES) {
1002 int c = lexGetc(); 1002 int c = lexGetc();
1003 if (c == ';') { 1003 if (c == ';') {
1004 DBG_(("db: SEMICOLON\n")); 1004 DBG_(("db: SEMICOLON\n"));
1005 lexPushLookaheadc(c); 1005 lexPushLookaheadc(c);
1006 handleMoreRFC822LineBreak(c); 1006 handleMoreRFC822LineBreak(c);
1007 lexSkipLookahead(); 1007 lexSkipLookahead();
1008 return SEMICOLON; 1008 return SEMICOLON;
1009 } 1009 }
1010 else if (strchr("\n",c)) { 1010 else if (strchr("\n",c)) {
1011 ++mime_lineNum; 1011 ++mime_lineNum;
1012 /* consume all line separator(s) adjacent to each other */ 1012 /* consume all line separator(s) adjacent to each other */
1013 c = lexLookahead(); 1013 c = lexLookahead();
1014 while (strchr("\n",c)) { 1014 while (strchr("\n",c)) {
1015 lexSkipLookahead(); 1015 lexSkipLookahead();
1016 c = lexLookahead(); 1016 c = lexLookahead();
1017 ++mime_lineNum; 1017 ++mime_lineNum;
1018 } 1018 }
1019 DBG_(("db: LINESEP\n")); 1019 DBG_(("db: LINESEP\n"));
1020 return LINESEP; 1020 return LINESEP;
1021 } 1021 }
1022 else { 1022 else {
1023 char *p = 0; 1023 char *p = 0;
1024 lexPushLookaheadc(c); 1024 lexPushLookaheadc(c);
1025 if (lexWithinMode(L_BASE64)) { 1025 if (lexWithinMode(L_BASE64)) {
1026 /* get each char and convert to bin on the fly... */ 1026 /* get each char and convert to bin on the fly... */
1027 p = lexGetDataFromBase64(); 1027 p = lexGetDataFromBase64();
1028 yylval.str = p; 1028 yylval.str = p;
1029 return STRING; 1029 return STRING;
1030 } 1030 }
1031 else if (lexWithinMode(L_QUOTED_PRINTABLE)) { 1031 else if (lexWithinMode(L_QUOTED_PRINTABLE)) {
1032 p = lexGetQuotedPrintable(); 1032 p = lexGetQuotedPrintable();
1033 } 1033 }
1034 else { 1034 else {
1035#ifdef _SUPPORT_LINE_FOLDING 1035#ifdef _SUPPORT_LINE_FOLDING
1036 p = lexGet1Value(); 1036 p = lexGet1Value();
1037#else 1037#else
1038 p = lexGetStrUntil(";\n"); 1038 p = lexGetStrUntil(";\n");
1039#endif 1039#endif
1040 } 1040 }
1041 if (p) { 1041 if (p) {
1042 DBG_(("db: STRING: '%s'\n", p)); 1042 DBG_(("db: STRING: '%s'\n", p));
1043 yylval.str = p; 1043 yylval.str = p;
1044 return STRING; 1044 return STRING;
1045 } 1045 }
1046 else return 0; 1046 else return 0;
1047 } 1047 }
1048 } 1048 }
1049 else { 1049 else {
1050 /* normal mode */ 1050 /* normal mode */
1051 while (1) { 1051 while (1) {
1052 int c = lexGetc(); 1052 int c = lexGetc();
1053 switch(c) { 1053 switch(c) {
1054 case ':': { 1054 case ':': {
1055 /* consume all line separator(s) adjacent to each other */ 1055 /* consume all line separator(s) adjacent to each other */
1056 /* ignoring linesep immediately after colon. */ 1056 /* ignoring linesep immediately after colon. */
1057 c = lexLookahead(); 1057 c = lexLookahead();
1058 while (strchr("\n",c)) { 1058 while (strchr("\n",c)) {
1059 lexSkipLookahead(); 1059 lexSkipLookahead();
1060 c = lexLookahead(); 1060 c = lexLookahead();
1061 ++mime_lineNum; 1061 ++mime_lineNum;
1062 } 1062 }
1063 DBG_(("db: COLON\n")); 1063 DBG_(("db: COLON\n"));
1064 return COLON; 1064 return COLON;
1065 } 1065 }
1066 case ';': 1066 case ';':
1067 DBG_(("db: SEMICOLON\n")); 1067 DBG_(("db: SEMICOLON\n"));
1068 return SEMICOLON; 1068 return SEMICOLON;
1069 case '=': 1069 case '=':
1070 DBG_(("db: EQ\n")); 1070 DBG_(("db: EQ\n"));
1071 return EQ; 1071 return EQ;
1072 /* ignore whitespace in this mode */ 1072 /* ignore whitespace in this mode */
1073 case '\t': 1073 case '\t':
1074 case ' ': continue; 1074 case ' ': continue;
1075 case '\n': { 1075 case '\n': {
1076 ++mime_lineNum; 1076 ++mime_lineNum;
1077 continue; 1077 continue;
1078 } 1078 }
1079 case EOF: return 0; 1079 case EOF: return 0;
1080 break; 1080 break;
1081 default: { 1081 default: {
1082 lexPushLookaheadc(c); 1082 lexPushLookaheadc(c);
1083 if (isalnum(c)) { 1083 if (isalnum(c)) {
1084 char *t = lexGetWord(); 1084 char *t = lexGetWord();
1085 yylval.str = t; 1085 yylval.str = t;
1086 if (!qstricmp(t, "begin")) { 1086 if (!qstricmp(t, "begin")) {
1087 return match_begin_end_name(0); 1087 return match_begin_end_name(0);
1088 } 1088 }
1089 else if (!qstricmp(t,"end")) { 1089 else if (!qstricmp(t,"end")) {
1090 return match_begin_end_name(1); 1090 return match_begin_end_name(1);
1091 } 1091 }
1092 else { 1092 else {
1093 DBG_(("db: ID '%s'\n", t)); 1093 DBG_(("db: ID '%s'\n", t));
1094 return ID; 1094 return ID;
1095 } 1095 }
1096 } 1096 }
1097 else { 1097 else {
1098 /* unknow token */ 1098 /* unknow token */
1099 return 0; 1099 return 0;
1100 } 1100 }
1101 break; 1101 break;
1102 } 1102 }
1103 } 1103 }
1104 } 1104 }
1105 } 1105 }
1106 return 0; 1106 return 0;
1107 } 1107 }
1108 1108
1109 1109
1110/***************************************************************************/ 1110/***************************************************************************/
1111 /*** Public Functions ****/ 1111 /*** Public Functions ****/
1112/***************************************************************************/ 1112/***************************************************************************/
1113 1113
1114static VObject* Parse_MIMEHelper() 1114static VObject* Parse_MIMEHelper()
1115 { 1115 {
1116 ObjStackTop = -1; 1116 ObjStackTop = -1;
1117 mime_numErrors = 0; 1117 mime_numErrors = 0;
1118 mime_lineNum = 1; 1118 mime_lineNum = 1;
1119 vObjList = 0; 1119 vObjList = 0;
1120 curObj = 0; 1120 curObj = 0;
1121 1121
1122 if (yyparse() != 0) 1122 if (yyparse() != 0)
1123 return 0; 1123 return 0;
1124 1124
1125 finiLex(); 1125 finiLex();
1126 return vObjList; 1126 return vObjList;
1127 } 1127 }
1128 1128
1129/*--------------------------------------------*/ 1129/*--------------------------------------------*/
1130DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len) 1130DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len)
1131 { 1131 {
1132 initLex(input, len, 0); 1132 initLex(input, len, 0);
1133 return Parse_MIMEHelper(); 1133 return Parse_MIMEHelper();
1134 } 1134 }
1135 1135
1136 1136
1137#if INCLUDEMFC 1137#if INCLUDEMFC
1138 1138
1139DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file) 1139DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file)
1140 { 1140 {
1141 unsigned long startPos; 1141 unsigned long startPos;
1142 VObject *result; 1142 VObject *result;
1143 1143
1144 initLex(0,-1,file); 1144 initLex(0,-1,file);
1145 startPos = file->GetPosition(); 1145 startPos = file->GetPosition();
1146 if (!(result = Parse_MIMEHelper())) 1146 if (!(result = Parse_MIMEHelper()))
1147 file->Seek(startPos, CFile::begin); 1147 file->Seek(startPos, CFile::begin);
1148 return result; 1148 return result;
1149 } 1149 }
1150 1150
1151#else 1151#else
1152 1152
1153VObject* Parse_MIME_FromFile(FILE *file) 1153VObject* Parse_MIME_FromFile(FILE *file)
1154 { 1154 {
1155 VObject *result; 1155 VObject *result;
1156 long startPos; 1156 long startPos;
1157 1157
1158 initLex(0,(unsigned long)-1,file); 1158 initLex(0,(unsigned long)-1,file);
1159 startPos = ftell(file); 1159 startPos = ftell(file);
1160 if (!(result = Parse_MIMEHelper())) { 1160 if (!(result = Parse_MIMEHelper())) {
1161 fseek(file,startPos,SEEK_SET); 1161 fseek(file,startPos,SEEK_SET);
1162 } 1162 }
1163 return result; 1163 return result;
1164 } 1164 }
1165 1165
1166DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname) 1166DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname)
1167 { 1167 {
1168 FILE *fp = fopen(fname,"r"); 1168 FILE *fp = fopen(fname,"r");
1169 if (fp) { 1169 if (fp) {
1170 VObject* o = Parse_MIME_FromFile(fp); 1170 VObject* o = Parse_MIME_FromFile(fp);
1171 fclose(fp); 1171 fclose(fp);
1172 return o; 1172 return o;
1173 } 1173 }
1174 else { 1174 else {
1175 char msg[80]; 1175 char msg[80];
1176 sprintf(msg, "can't open file '%s' for reading\n", fname); 1176 sprintf(msg, "can't open file '%s' for reading\n", fname);
1177 mime_error_(msg); 1177 mime_error_(msg);
1178 return 0; 1178 return 0;
1179 } 1179 }
1180 } 1180 }
1181 1181
1182#endif 1182#endif
1183 1183
1184/*-------------------------------------*/ 1184/*-------------------------------------*/
1185 1185
1186static MimeErrorHandler mimeErrorHandler; 1186static MimeErrorHandler mimeErrorHandler;
1187 1187
1188DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me) 1188DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me)
1189 { 1189 {
1190 mimeErrorHandler = me; 1190 mimeErrorHandler = me;
1191 } 1191 }
1192 1192
1193void mime_error(char *s) 1193void mime_error(char *s)
1194 { 1194 {
1195 char msg[256]; 1195 char msg[256];
1196 if (mimeErrorHandler) { 1196 if (mimeErrorHandler) {
1197 sprintf(msg,"%s at line %d", s, mime_lineNum); 1197 sprintf(msg,"%s at line %d", s, mime_lineNum);
1198 mimeErrorHandler(msg); 1198 mimeErrorHandler(msg);
1199 } 1199 }
1200 } 1200 }
1201 1201
1202void mime_error_(char *s) 1202void mime_error_(char *s)
1203 { 1203 {
1204 if (mimeErrorHandler) { 1204 if (mimeErrorHandler) {
1205 mimeErrorHandler(s); 1205 mimeErrorHandler(s);
1206 } 1206 }
1207 } 1207 }
1208 1208
diff --git a/library/backend/vcc_yacc.cpp b/library/backend/vcc_yacc.cpp
index 19a108f..b2b0c14 100644
--- a/library/backend/vcc_yacc.cpp
+++ b/library/backend/vcc_yacc.cpp
@@ -1,1576 +1,1576 @@
1#ifndef lint 1#ifndef lint
2 /*static char yysccsid[] = "from: @(#)yaccpar1.9 (Berkeley) 02/21/93";*/ 2 /*static char yysccsid[] = "from: @(#)yaccpar1.9 (Berkeley) 02/21/93";*/
3static char yyrcsid[] = "$Id$"; 3static char yyrcsid[] = "$Id$";
4#endif 4#endif
5#define YYBYACC 1 5#define YYBYACC 1
6#define YYMAJOR 1 6#define YYMAJOR 1
7#define YYMINOR 9 7#define YYMINOR 9
8#define yyclearin (yychar=(-1)) 8#define yyclearin (yychar=(-1))
9#define yyerrok (yyerrflag=0) 9#define yyerrok (yyerrflag=0)
10#define YYRECOVERING (yyerrflag!=0) 10#define YYRECOVERING (yyerrflag!=0)
11#define yyparse vccparse 11#define yyparse vccparse
12#define yylex vcclex 12#define yylex vcclex
13#define yyerror vccerror 13#define yyerror vccerror
14#define yychar vccchar 14#define yychar vccchar
15#define yyval vccval 15#define yyval vccval
16#define yylval vcclval 16#define yylval vcclval
17#define yydebug vccdebug 17#define yydebug vccdebug
18#define yynerrs vccnerrs 18#define yynerrs vccnerrs
19#define yyerrflag vccerrflag 19#define yyerrflag vccerrflag
20#define yyss vccss 20#define yyss vccss
21#define yyssp vccssp 21#define yyssp vccssp
22#define yyvs vccvs 22#define yyvs vccvs
23#define yyvsp vccvsp 23#define yyvsp vccvsp
24#define yylhs vcclhs 24#define yylhs vcclhs
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
41Business Machines Corporation and Siemens Rolm Communications Inc. 41Business Machines Corporation and Siemens Rolm Communications Inc.
42 42
43For purposes of this license notice, the term Licensors shall mean, 43For purposes of this license notice, the term Licensors shall mean,
44collectively, Apple Computer, Inc., AT&T Corp., International 44collectively, Apple Computer, Inc., AT&T Corp., International
45Business Machines Corporation and Siemens Rolm Communications Inc. 45Business Machines Corporation and Siemens Rolm Communications Inc.
46The term Licensor shall mean any of the Licensors. 46The term Licensor shall mean any of the Licensors.
47 47
48Subject to acceptance of the following conditions, permission is hereby 48Subject to acceptance of the following conditions, permission is hereby
49granted by Licensors without the need for written agreement and without 49granted by Licensors without the need for written agreement and without
50license or royalty fees, to use, copy, modify and distribute this 50license or royalty fees, to use, copy, modify and distribute this
51software for any purpose. 51software for any purpose.
52 52
53The above copyright notice and the following four paragraphs must be 53The above copyright notice and the following four paragraphs must be
54reproduced in all copies of this software and any software including 54reproduced in all copies of this software and any software including
55this software. 55this software.
56 56
57THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE 57THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
58ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR 58ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
59MODIFICATIONS. 59MODIFICATIONS.
60 60
61IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, 61IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
62INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 62INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
63OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 63OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
64DAMAGE. 64DAMAGE.
65 65
66EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, 66EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
67INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE 67INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
68IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 68IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69PURPOSE. 69PURPOSE.
70 70
71The software is provided with RESTRICTED RIGHTS. Use, duplication, or 71The software is provided with RESTRICTED RIGHTS. Use, duplication, or
72disclosure by the government are subject to restrictions set forth in 72disclosure by the government are subject to restrictions set forth in
73DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. 73DFARS 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/*#include <qpe/vobject_p.h> */
160/*#else */ 160/*#else */
161#include "vobject_p.h" 161#include <qtopia/private/vobject_p.h>
162/*#endif */ 162/*#endif */
163 163
164/**** Types, Constants ****/ 164/**** Types, Constants ****/
165 165
166 #define YYDEBUG 0/* 1 to compile in some debugging code */ 166 #define YYDEBUG 0/* 1 to compile in some debugging code */
167 #define MAXTOKEN 256/* maximum token (line) length */ 167 #define MAXTOKEN 256/* maximum token (line) length */
168 #define YYSTACKSIZE 100/* ~unref ? */ 168 #define YYSTACKSIZE 100/* ~unref ? */
169 #define MAXLEVEL 10/* max # of nested objects parseable */ 169 #define MAXLEVEL 10/* max # of nested objects parseable */
170 /* (includes outermost) */ 170 /* (includes outermost) */
171 171
172 172
173/**** Global Variables ****/ 173/**** Global Variables ****/
174int mime_lineNum, mime_numErrors; /* yyerror() can use these */ 174int mime_lineNum, mime_numErrors; /* yyerror() can use these */
175static VObject* vObjList; 175static VObject* vObjList;
176static VObject *curProp; 176static VObject *curProp;
177static VObject *curObj; 177static VObject *curObj;
178static VObject* ObjStack[MAXLEVEL]; 178static VObject* ObjStack[MAXLEVEL];
179static int ObjStackTop; 179static int ObjStackTop;
180 180
181 181
182/* A helpful utility for the rest of the app. */ 182/* A helpful utility for the rest of the app. */
183#if __CPLUSPLUS__ 183#if __CPLUSPLUS__
184extern "C" { 184extern "C" {
185#endif 185#endif
186 186
187 extern void yyerror(char *s); 187 extern void yyerror(char *s);
188 188
189#if __CPLUSPLUS__ 189#if __CPLUSPLUS__
190 }; 190 };
191#endif 191#endif
192 192
193int yyparse(); 193int yyparse();
194 194
195enum LexMode { 195enum LexMode {
196 L_NORMAL, 196 L_NORMAL,
197 L_VCARD, 197 L_VCARD,
198 L_VCAL, 198 L_VCAL,
199 L_VEVENT, 199 L_VEVENT,
200 L_VTODO, 200 L_VTODO,
201 L_VALUES, 201 L_VALUES,
202 L_BASE64, 202 L_BASE64,
203 L_QUOTED_PRINTABLE 203 L_QUOTED_PRINTABLE
204 }; 204 };
205 205
206/**** Private Forward Declarations ****/ 206/**** Private Forward Declarations ****/
207static int pushVObject(const char *prop); 207static int pushVObject(const char *prop);
208static VObject* popVObject(); 208static VObject* popVObject();
209static void lexPopMode(int top); 209static void lexPopMode(int top);
210static int lexWithinMode(enum LexMode mode); 210static int lexWithinMode(enum LexMode mode);
211static void lexPushMode(enum LexMode mode); 211static void lexPushMode(enum LexMode mode);
212static void enterProps(const char *s); 212static void enterProps(const char *s);
213static void enterAttr(const char *s1, const char *s2); 213static void enterAttr(const char *s1, const char *s2);
214static void enterValues(const char *value); 214static void enterValues(const char *value);
215#define mime_error yyerror 215#define mime_error yyerror
216void mime_error(char *s); 216void mime_error(char *s);
217void mime_error_(char *s); 217void mime_error_(char *s);
218 218
219#line 189 "backend/vcc.y" 219#line 189 "backend/vcc.y"
220typedef union { 220typedef union {
221 char *str; 221 char *str;
222 VObject *vobj; 222 VObject *vobj;
223 } YYSTYPE; 223 } YYSTYPE;
224#line 225 "y.tab.c" 224#line 225 "y.tab.c"
225#define EQ 257 225#define EQ 257
226#define COLON 258 226#define COLON 258
227#define DOT 259 227#define DOT 259
228#define SEMICOLON 260 228#define SEMICOLON 260
229#define SPACE 261 229#define SPACE 261
230#define HTAB 262 230#define HTAB 262
231#define LINESEP 263 231#define LINESEP 263
232#define NEWLINE 264 232#define NEWLINE 264
233#define BEGIN_VCARD 265 233#define BEGIN_VCARD 265
234#define END_VCARD 266 234#define END_VCARD 266
235#define BEGIN_VCAL 267 235#define BEGIN_VCAL 267
236#define END_VCAL 268 236#define END_VCAL 268
237#define BEGIN_VEVENT 269 237#define BEGIN_VEVENT 269
238#define END_VEVENT 270 238#define END_VEVENT 270
239#define BEGIN_VTODO 271 239#define BEGIN_VTODO 271
240#define END_VTODO 272 240#define END_VTODO 272
241#define ID 273 241#define ID 273
242#define STRING 274 242#define STRING 274
243#define YYERRCODE 256 243#define YYERRCODE 256
244short vcclhs[] = { -1, 244short vcclhs[] = { -1,
245 0, 6, 6, 5, 5, 8, 3, 9, 3, 7, 245 0, 6, 6, 5, 5, 8, 3, 9, 3, 7,
246 7, 13, 10, 10, 15, 11, 11, 14, 14, 16, 246 7, 13, 10, 10, 15, 11, 11, 14, 14, 16,
247 17, 17, 1, 18, 12, 12, 2, 2, 20, 4, 247 17, 17, 1, 18, 12, 12, 2, 2, 20, 4,
248 21, 4, 19, 19, 22, 22, 22, 25, 23, 26, 248 21, 4, 19, 19, 22, 22, 22, 25, 23, 26,
249 23, 27, 24, 28, 24, 249 23, 27, 24, 28, 24,
250}; 250};
251short vcclen[] = { 2, 251short vcclen[] = { 2,
252 1, 2, 1, 1, 1, 0, 4, 0, 3, 2, 252 1, 2, 1, 1, 1, 0, 4, 0, 3, 2,
253 1, 0, 5, 1, 0, 3, 1, 2, 1, 2, 253 1, 0, 5, 1, 0, 3, 1, 2, 1, 2,
254 1, 3, 1, 0, 4, 1, 1, 0, 0, 4, 254 1, 3, 1, 0, 4, 1, 1, 0, 0, 4,
255 0, 3, 2, 1, 1, 1, 1, 0, 4, 0, 255 0, 3, 2, 1, 1, 1, 1, 0, 4, 0,
256 3, 0, 4, 0, 3, 256 3, 0, 4, 0, 3,
257}; 257};
258short vccdefred[] = { 0, 258short vccdefred[] = { 0,
259 0, 0, 0, 4, 5, 3, 0, 0, 0, 0, 259 0, 0, 0, 4, 5, 3, 0, 0, 0, 0,
260 0, 2, 14, 23, 0, 0, 11, 0, 9, 0, 260 0, 2, 14, 23, 0, 0, 11, 0, 9, 0,
261 0, 0, 0, 34, 35, 36, 32, 0, 7, 10, 261 0, 0, 0, 34, 35, 36, 32, 0, 7, 10,
262 12, 0, 0, 0, 0, 30, 33, 0, 0, 19, 262 12, 0, 0, 0, 0, 30, 33, 0, 0, 19,
263 0, 0, 41, 0, 45, 0, 20, 18, 27, 0, 263 0, 0, 41, 0, 45, 0, 20, 18, 27, 0,
264 0, 39, 43, 0, 24, 13, 22, 0, 25, 264 0, 39, 43, 0, 24, 13, 22, 0, 25,
265}; 265};
266short vccdgoto[] = { 3, 266short vccdgoto[] = { 3,
267 15, 50, 4, 5, 6, 7, 22, 8, 9, 17, 267 15, 50, 4, 5, 6, 7, 22, 8, 9, 17,
268 18, 51, 41, 39, 28, 40, 47, 58, 23, 10, 268 18, 51, 41, 39, 28, 40, 47, 58, 23, 10,
269 11, 24, 25, 26, 32, 33, 34, 35, 269 11, 24, 25, 26, 32, 33, 34, 35,
270}; 270};
271short vccsindex[] = { -262, 271short vccsindex[] = { -262,
272 0, 0, 0, 0, 0, 0, -262, -252, -219, -249, 272 0, 0, 0, 0, 0, 0, -262, -252, -219, -249,
273 -256, 0, 0, 0, 0, -227, 0, -242, 0, 0, 273 -256, 0, 0, 0, 0, -227, 0, -242, 0, 0,
274 0, -252, -254, 0, 0, 0, 0, -208, 0, 0, 274 0, -252, -254, 0, 0, 0, 0, -208, 0, 0,
275 0, -252, -228, -252, -213, 0, 0, -212, -208, 0, 275 0, -252, -228, -252, -213, 0, 0, -212, -208, 0,
276 -214, -233, 0, -224, 0, -195, 0, 0, 0, -197, 276 -214, -233, 0, -224, 0, -195, 0, 0, 0, -197,
277 -199, 0, 0, -212, 0, 0, 0, -214, 0, 277 -199, 0, 0, -212, 0, 0, 0, -214, 0,
278}; 278};
279short vccrindex[] = { 0, 279short vccrindex[] = { 0,
280 -222, -238, 0, 0, 0, 0, 65, 0, 0, 0, 280 -222, -238, 0, 0, 0, 0, 65, 0, 0, 0,
281 0, 0, 0, 0, -215, 0, 0, 0, 0, -220, 281 0, 0, 0, 0, -215, 0, 0, 0, 0, -220,
282 -218, -260, 0, 0, 0, 0, 0, 0, 0, 0, 282 -218, -260, 0, 0, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0, -192, 0, 283 0, 0, 0, 0, 0, 0, 0, 0, -192, 0,
284 -250, 0, 0, 0, 0, -202, 0, 0, 0, -196, 284 -250, 0, 0, 0, 0, -202, 0, 0, 0, -196,
285 0, 0, 0, 0, 0, 0, 0, -250, 0, 285 0, 0, 0, 0, 0, 0, 0, -250, 0,
286}; 286};
287short vccgindex[] = { 0, 287short vccgindex[] = { 0,
288 3, 0, 0, 0, 61, 0, -7, 0, 0, -16, 288 3, 0, 0, 0, 61, 0, -7, 0, 0, -16,
289 0, 11, 0, 0, 0, 31, 0, 0, 0, 0, 289 0, 11, 0, 0, 0, 31, 0, 0, 0, 0,
290 0, 48, 0, 0, 0, 0, 0, 0, 290 0, 48, 0, 0, 0, 0, 0, 0,
291}; 291};
292#define YYTABLESIZE 71 292#define YYTABLESIZE 71
293short vcctable[] = { 30, 293short vcctable[] = { 30,
294 16, 13, 1, 13, 2, 30, 13, 37, 37, 28, 294 16, 13, 1, 13, 2, 30, 13, 37, 37, 28,
295 37, 27, 28, 36, 20, 31, 21, 29, 14, 20, 295 37, 27, 28, 36, 20, 31, 21, 29, 14, 20,
296 14, 21, 13, 14, 42, 30, 44, 30, 13, 31, 296 14, 21, 13, 14, 42, 30, 44, 30, 13, 31,
297 29, 13, 29, 6, 29, 38, 52, 42, 29, 14, 297 29, 13, 29, 6, 29, 38, 52, 42, 29, 14,
298 46, 43, 17, 8, 15, 14, 19, 53, 14, 40, 298 46, 43, 17, 8, 15, 14, 19, 53, 14, 40,
299 6, 38, 38, 44, 42, 21, 57, 21, 45, 49, 299 6, 38, 38, 44, 42, 21, 57, 21, 45, 49,
300 14, 54, 55, 56, 1, 16, 26, 12, 59, 48, 300 14, 54, 55, 56, 1, 16, 26, 12, 59, 48,
301 37, 301 37,
302}; 302};
303short vcccheck[] = { 16, 303short vcccheck[] = { 16,
304 8, 256, 265, 256, 267, 22, 256, 268, 269, 260, 304 8, 256, 265, 256, 267, 22, 256, 268, 269, 260,
305 271, 268, 263, 268, 269, 258, 271, 256, 273, 269, 305 271, 268, 263, 268, 269, 258, 271, 256, 273, 269,
306 273, 271, 256, 273, 32, 42, 34, 44, 256, 268, 306 273, 271, 256, 273, 32, 42, 34, 44, 256, 268,
307 269, 256, 271, 256, 273, 256, 270, 256, 266, 273, 307 269, 256, 271, 256, 273, 256, 270, 256, 266, 273,
308 38, 270, 258, 266, 260, 273, 266, 272, 273, 270, 308 38, 270, 258, 266, 260, 273, 266, 272, 273, 270,
309 273, 260, 273, 272, 273, 258, 54, 260, 272, 274, 309 273, 260, 273, 272, 273, 258, 54, 260, 272, 274,
310 273, 257, 260, 263, 0, 258, 263, 7, 58, 39, 310 273, 257, 260, 263, 0, 258, 263, 7, 58, 39,
311 23, 311 23,
312}; 312};
313#define YYFINAL 3 313#define YYFINAL 3
314#ifndef YYDEBUG 314#ifndef YYDEBUG
315#define YYDEBUG 0 315#define YYDEBUG 0
316#endif 316#endif
317#define YYMAXTOKEN 274 317#define YYMAXTOKEN 274
318#if YYDEBUG 318#if YYDEBUG
319char *vccname[] = { 319char *vccname[] = {
320"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 320"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3210,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3210,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3220,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3220,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3230,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3230,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3250,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3250,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3260,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"EQ","COLON","DOT","SEMICOLON", 3260,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"EQ","COLON","DOT","SEMICOLON",
327"SPACE","HTAB","LINESEP","NEWLINE","BEGIN_VCARD","END_VCARD","BEGIN_VCAL", 327"SPACE","HTAB","LINESEP","NEWLINE","BEGIN_VCARD","END_VCARD","BEGIN_VCAL",
328"END_VCAL","BEGIN_VEVENT","END_VEVENT","BEGIN_VTODO","END_VTODO","ID","STRING", 328"END_VCAL","BEGIN_VEVENT","END_VEVENT","BEGIN_VTODO","END_VTODO","ID","STRING",
329}; 329};
330char *vccrule[] = { 330char *vccrule[] = {
331"$accept : mime", 331"$accept : mime",
332"mime : vobjects", 332"mime : vobjects",
333"vobjects : vobjects vobject", 333"vobjects : vobjects vobject",
334"vobjects : vobject", 334"vobjects : vobject",
335"vobject : vcard", 335"vobject : vcard",
336"vobject : vcal", 336"vobject : vcal",
337"$$1 :", 337"$$1 :",
338"vcard : BEGIN_VCARD $$1 items END_VCARD", 338"vcard : BEGIN_VCARD $$1 items END_VCARD",
339"$$2 :", 339"$$2 :",
340"vcard : BEGIN_VCARD $$2 END_VCARD", 340"vcard : BEGIN_VCARD $$2 END_VCARD",
341"items : items item", 341"items : items item",
342"items : item", 342"items : item",
343"$$3 :", 343"$$3 :",
344"item : prop COLON $$3 values LINESEP", 344"item : prop COLON $$3 values LINESEP",
345"item : error", 345"item : error",
346"$$4 :", 346"$$4 :",
347"prop : name $$4 attr_params", 347"prop : name $$4 attr_params",
348"prop : name", 348"prop : name",
349"attr_params : attr_params attr_param", 349"attr_params : attr_params attr_param",
350"attr_params : attr_param", 350"attr_params : attr_param",
351"attr_param : SEMICOLON attr", 351"attr_param : SEMICOLON attr",
352"attr : name", 352"attr : name",
353"attr : name EQ name", 353"attr : name EQ name",
354"name : ID", 354"name : ID",
355"$$5 :", 355"$$5 :",
356"values : value SEMICOLON $$5 values", 356"values : value SEMICOLON $$5 values",
357"values : value", 357"values : value",
358"value : STRING", 358"value : STRING",
359"value :", 359"value :",
360"$$6 :", 360"$$6 :",
361"vcal : BEGIN_VCAL $$6 calitems END_VCAL", 361"vcal : BEGIN_VCAL $$6 calitems END_VCAL",
362"$$7 :", 362"$$7 :",
363"vcal : BEGIN_VCAL $$7 END_VCAL", 363"vcal : BEGIN_VCAL $$7 END_VCAL",
364"calitems : calitems calitem", 364"calitems : calitems calitem",
365"calitems : calitem", 365"calitems : calitem",
366"calitem : eventitem", 366"calitem : eventitem",
367"calitem : todoitem", 367"calitem : todoitem",
368"calitem : items", 368"calitem : items",
369"$$8 :", 369"$$8 :",
370"eventitem : BEGIN_VEVENT $$8 items END_VEVENT", 370"eventitem : BEGIN_VEVENT $$8 items END_VEVENT",
371"$$9 :", 371"$$9 :",
372"eventitem : BEGIN_VEVENT $$9 END_VEVENT", 372"eventitem : BEGIN_VEVENT $$9 END_VEVENT",
373"$$10 :", 373"$$10 :",
374"todoitem : BEGIN_VTODO $$10 items END_VTODO", 374"todoitem : BEGIN_VTODO $$10 items END_VTODO",
375"$$11 :", 375"$$11 :",
376"todoitem : BEGIN_VTODO $$11 END_VTODO", 376"todoitem : BEGIN_VTODO $$11 END_VTODO",
377}; 377};
378#endif 378#endif
379#ifdef YYSTACKSIZE 379#ifdef YYSTACKSIZE
380#undef YYMAXDEPTH 380#undef YYMAXDEPTH
381#define YYMAXDEPTH YYSTACKSIZE 381#define YYMAXDEPTH YYSTACKSIZE
382#else 382#else
383#ifdef YYMAXDEPTH 383#ifdef YYMAXDEPTH
384#define YYSTACKSIZE YYMAXDEPTH 384#define YYSTACKSIZE YYMAXDEPTH
385#else 385#else
386#define YYSTACKSIZE 500 386#define YYSTACKSIZE 500
387#define YYMAXDEPTH 500 387#define YYMAXDEPTH 500
388#endif 388#endif
389#endif 389#endif
390int yydebug; 390int yydebug;
391int yynerrs; 391int yynerrs;
392int yyerrflag; 392int yyerrflag;
393int yychar; 393int yychar;
394short *yyssp; 394short *yyssp;
395YYSTYPE *yyvsp; 395YYSTYPE *yyvsp;
396YYSTYPE yyval; 396YYSTYPE yyval;
397YYSTYPE yylval; 397YYSTYPE yylval;
398short yyss[YYSTACKSIZE]; 398short yyss[YYSTACKSIZE];
399YYSTYPE yyvs[YYSTACKSIZE]; 399YYSTYPE yyvs[YYSTACKSIZE];
400#define yystacksize YYSTACKSIZE 400#define yystacksize YYSTACKSIZE
401#line 382 "backend/vcc.y" 401#line 382 "backend/vcc.y"
402 402
403/*------------------------------------*/ 403/*------------------------------------*/
404static int pushVObject(const char *prop) 404static int pushVObject(const char *prop)
405 { 405 {
406 VObject *newObj; 406 VObject *newObj;
407 if (ObjStackTop == MAXLEVEL) 407 if (ObjStackTop == MAXLEVEL)
408 return FALSE; 408 return FALSE;
409 409
410 ObjStack[++ObjStackTop] = curObj; 410 ObjStack[++ObjStackTop] = curObj;
411 411
412 if (curObj) { 412 if (curObj) {
413 newObj = addProp(curObj,prop); 413 newObj = addProp(curObj,prop);
414 curObj = newObj; 414 curObj = newObj;
415 } 415 }
416 else 416 else
417 curObj = newVObject(prop); 417 curObj = newVObject(prop);
418 418
419 return TRUE; 419 return TRUE;
420 } 420 }
421 421
422 422
423/*---------------------------------------*/ 423/*---------------------------------------*/
424/* This pops the recently built vCard off the stack and returns it. */ 424/* This pops the recently built vCard off the stack and returns it. */
425static VObject* popVObject() 425static VObject* popVObject()
426 { 426 {
427 VObject *oldObj; 427 VObject *oldObj;
428 if (ObjStackTop < 0) { 428 if (ObjStackTop < 0) {
429 yyerror("pop on empty Object Stack\n"); 429 yyerror("pop on empty Object Stack\n");
430 return 0; 430 return 0;
431 } 431 }
432 oldObj = curObj; 432 oldObj = curObj;
433 curObj = ObjStack[ObjStackTop--]; 433 curObj = ObjStack[ObjStackTop--];
434 434
435 return oldObj; 435 return oldObj;
436 } 436 }
437 437
438 438
439static void enterValues(const char *value) 439static void enterValues(const char *value)
440 { 440 {
441 if (fieldedProp && *fieldedProp) { 441 if (fieldedProp && *fieldedProp) {
442 if (value) { 442 if (value) {
443 addPropValue(curProp,*fieldedProp,value); 443 addPropValue(curProp,*fieldedProp,value);
444 } 444 }
445 /* else this field is empty, advance to next field */ 445 /* else this field is empty, advance to next field */
446 fieldedProp++; 446 fieldedProp++;
447 } 447 }
448 else { 448 else {
449 if (value) { 449 if (value) {
450 setVObjectStringZValue_(curProp,strdup( value )); 450 setVObjectStringZValue_(curProp,strdup( value ));
451 } 451 }
452 } 452 }
453 deleteStr(value); 453 deleteStr(value);
454 } 454 }
455 455
456static void enterProps(const char *s) 456static void enterProps(const char *s)
457 { 457 {
458 curProp = addGroup(curObj,s); 458 curProp = addGroup(curObj,s);
459 deleteStr(s); 459 deleteStr(s);
460 } 460 }
461 461
462static void enterAttr(const char *s1, const char *s2) 462static void enterAttr(const char *s1, const char *s2)
463 { 463 {
464 const char *p1, *p2; 464 const char *p1, *p2;
465 p1 = lookupProp_(s1); 465 p1 = lookupProp_(s1);
466 if (s2) { 466 if (s2) {
467 VObject *a; 467 VObject *a;
468 p2 = lookupProp_(s2); 468 p2 = lookupProp_(s2);
469 a = addProp(curProp,p1); 469 a = addProp(curProp,p1);
470 setVObjectStringZValue(a,p2); 470 setVObjectStringZValue(a,p2);
471 } 471 }
472 else 472 else
473 addProp(curProp,p1); 473 addProp(curProp,p1);
474 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0)) 474 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0))
475 lexPushMode(L_BASE64); 475 lexPushMode(L_BASE64);
476 else if (qstricmp(p1,VCQuotedPrintableProp) == 0 476 else if (qstricmp(p1,VCQuotedPrintableProp) == 0
477 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0)) 477 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0))
478 lexPushMode(L_QUOTED_PRINTABLE); 478 lexPushMode(L_QUOTED_PRINTABLE);
479 deleteStr(s1); deleteStr(s2); 479 deleteStr(s1); deleteStr(s2);
480 } 480 }
481 481
482 482
483#define MAX_LEX_LOOKAHEAD_0 32 483#define MAX_LEX_LOOKAHEAD_0 32
484#define MAX_LEX_LOOKAHEAD 64 484#define MAX_LEX_LOOKAHEAD 64
485#define MAX_LEX_MODE_STACK_SIZE 10 485#define MAX_LEX_MODE_STACK_SIZE 10
486#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop]) 486#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop])
487 487
488struct LexBuf { 488struct LexBuf {
489 /* input */ 489 /* input */
490#ifdef INCLUDEMFC 490#ifdef INCLUDEMFC
491 CFile *inputFile; 491 CFile *inputFile;
492#else 492#else
493 FILE *inputFile; 493 FILE *inputFile;
494#endif 494#endif
495 char *inputString; 495 char *inputString;
496 unsigned long curPos; 496 unsigned long curPos;
497 unsigned long inputLen; 497 unsigned long inputLen;
498 /* lookahead buffer */ 498 /* lookahead buffer */
499 /* -- lookahead buffer is short instead of char so that EOF 499 /* -- lookahead buffer is short instead of char so that EOF
500 / can be represented correctly. 500 / can be represented correctly.
501 */ 501 */
502 unsigned long len; 502 unsigned long len;
503 short buf[MAX_LEX_LOOKAHEAD]; 503 short buf[MAX_LEX_LOOKAHEAD];
504 unsigned long getPtr; 504 unsigned long getPtr;
505 /* context stack */ 505 /* context stack */
506 unsigned long lexModeStackTop; 506 unsigned long lexModeStackTop;
507 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE]; 507 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE];
508 /* token buffer */ 508 /* token buffer */
509 unsigned long maxToken; 509 unsigned long maxToken;
510 char *strs; 510 char *strs;
511 unsigned long strsLen; 511 unsigned long strsLen;
512 } lexBuf; 512 } lexBuf;
513 513
514static void lexPushMode(enum LexMode mode) 514static void lexPushMode(enum LexMode mode)
515 { 515 {
516 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1)) 516 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1))
517 yyerror("lexical context stack overflow"); 517 yyerror("lexical context stack overflow");
518 else { 518 else {
519 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode; 519 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode;
520 } 520 }
521 } 521 }
522 522
523static void lexPopMode(int top) 523static void lexPopMode(int top)
524 { 524 {
525 /* special case of pop for ease of error recovery -- this 525 /* special case of pop for ease of error recovery -- this
526 version will never underflow */ 526 version will never underflow */
527 if (top) 527 if (top)
528 lexBuf.lexModeStackTop = 0; 528 lexBuf.lexModeStackTop = 0;
529 else 529 else
530 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--; 530 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--;
531 } 531 }
532 532
533static int lexWithinMode(enum LexMode mode) { 533static int lexWithinMode(enum LexMode mode) {
534 unsigned long i; 534 unsigned long i;
535 for (i=0;i<lexBuf.lexModeStackTop;i++) 535 for (i=0;i<lexBuf.lexModeStackTop;i++)
536 if (mode == lexBuf.lexModeStack[i]) return 1; 536 if (mode == lexBuf.lexModeStack[i]) return 1;
537 return 0; 537 return 0;
538 } 538 }
539 539
540static int lexGetc_() 540static int lexGetc_()
541 { 541 {
542 /* get next char from input, no buffering. */ 542 /* get next char from input, no buffering. */
543 if (lexBuf.curPos == lexBuf.inputLen) 543 if (lexBuf.curPos == lexBuf.inputLen)
544 return EOF; 544 return EOF;
545 else if (lexBuf.inputString) 545 else if (lexBuf.inputString)
546 return *(lexBuf.inputString + lexBuf.curPos++); 546 return *(lexBuf.inputString + lexBuf.curPos++);
547 else { 547 else {
548#ifdef INCLUDEMFC 548#ifdef INCLUDEMFC
549 char result; 549 char result;
550 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF; 550 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF;
551#else 551#else
552 return fgetc(lexBuf.inputFile); 552 return fgetc(lexBuf.inputFile);
553#endif 553#endif
554 } 554 }
555 } 555 }
556 556
557static int lexGeta() 557static int lexGeta()
558 { 558 {
559 ++lexBuf.len; 559 ++lexBuf.len;
560 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_()); 560 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_());
561 } 561 }
562 562
563static int lexGeta_(int i) 563static int lexGeta_(int i)
564 { 564 {
565 ++lexBuf.len; 565 ++lexBuf.len;
566 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_()); 566 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_());
567 } 567 }
568 568
569static void lexSkipLookahead() { 569static void lexSkipLookahead() {
570 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 570 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
571 /* don't skip EOF. */ 571 /* don't skip EOF. */
572 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 572 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
573 lexBuf.len--; 573 lexBuf.len--;
574 } 574 }
575 } 575 }
576 576
577static int lexLookahead() { 577static int lexLookahead() {
578 int c = (lexBuf.len)? 578 int c = (lexBuf.len)?
579 lexBuf.buf[lexBuf.getPtr]: 579 lexBuf.buf[lexBuf.getPtr]:
580 lexGeta(); 580 lexGeta();
581 /* do the \r\n -> \n or \r -> \n translation here */ 581 /* do the \r\n -> \n or \r -> \n translation here */
582 if (c == '\r') { 582 if (c == '\r') {
583 int a = (lexBuf.len>1)? 583 int a = (lexBuf.len>1)?
584 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]: 584 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]:
585 lexGeta_(1); 585 lexGeta_(1);
586 if (a == '\n') { 586 if (a == '\n') {
587 lexSkipLookahead(); 587 lexSkipLookahead();
588 } 588 }
589 lexBuf.buf[lexBuf.getPtr] = c = '\n'; 589 lexBuf.buf[lexBuf.getPtr] = c = '\n';
590 } 590 }
591 else if (c == '\n') { 591 else if (c == '\n') {
592 int a = (lexBuf.len>1)? 592 int a = (lexBuf.len>1)?
593 lexBuf.buf[lexBuf.getPtr+1]: 593 lexBuf.buf[lexBuf.getPtr+1]:
594 lexGeta_(1); 594 lexGeta_(1);
595 if (a == '\r') { 595 if (a == '\r') {
596 lexSkipLookahead(); 596 lexSkipLookahead();
597 } 597 }
598 lexBuf.buf[lexBuf.getPtr] = '\n'; 598 lexBuf.buf[lexBuf.getPtr] = '\n';
599 } 599 }
600 return c; 600 return c;
601 } 601 }
602 602
603static int lexGetc() { 603static int lexGetc() {
604 int c = lexLookahead(); 604 int c = lexLookahead();
605 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 605 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
606 /* EOF will remain in lookahead buffer */ 606 /* EOF will remain in lookahead buffer */
607 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 607 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
608 lexBuf.len--; 608 lexBuf.len--;
609 } 609 }
610 return c; 610 return c;
611 } 611 }
612 612
613static void lexSkipLookaheadWord() { 613static void lexSkipLookaheadWord() {
614 if (lexBuf.strsLen <= lexBuf.len) { 614 if (lexBuf.strsLen <= lexBuf.len) {
615 lexBuf.len -= lexBuf.strsLen; 615 lexBuf.len -= lexBuf.strsLen;
616 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; 616 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD;
617 } 617 }
618 } 618 }
619 619
620static void lexClearToken() 620static void lexClearToken()
621 { 621 {
622 lexBuf.strsLen = 0; 622 lexBuf.strsLen = 0;
623 } 623 }
624 624
625static void lexAppendc(int c) 625static void lexAppendc(int c)
626 { 626 {
627 lexBuf.strs[lexBuf.strsLen] = c; 627 lexBuf.strs[lexBuf.strsLen] = c;
628 /* append up to zero termination */ 628 /* append up to zero termination */
629 if (c == 0) return; 629 if (c == 0) return;
630 lexBuf.strsLen++; 630 lexBuf.strsLen++;
631 if (lexBuf.strsLen > lexBuf.maxToken) { 631 if (lexBuf.strsLen > lexBuf.maxToken) {
632 /* double the token string size */ 632 /* double the token string size */
633 lexBuf.maxToken <<= 1; 633 lexBuf.maxToken <<= 1;
634 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken); 634 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken);
635 } 635 }
636 } 636 }
637 637
638static char* lexStr() { 638static char* lexStr() {
639 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); 639 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1);
640 } 640 }
641 641
642static void lexSkipWhite() { 642static void lexSkipWhite() {
643 int c = lexLookahead(); 643 int c = lexLookahead();
644 while (c == ' ' || c == '\t') { 644 while (c == ' ' || c == '\t') {
645 lexSkipLookahead(); 645 lexSkipLookahead();
646 c = lexLookahead(); 646 c = lexLookahead();
647 } 647 }
648 } 648 }
649 649
650static char* lexGetWord() { 650static char* lexGetWord() {
651 int c; 651 int c;
652 lexSkipWhite(); 652 lexSkipWhite();
653 lexClearToken(); 653 lexClearToken();
654 c = lexLookahead(); 654 c = lexLookahead();
655 while (c != EOF && !strchr("\t\n ;:=",c)) { 655 while (c != EOF && !strchr("\t\n ;:=",c)) {
656 lexAppendc(c); 656 lexAppendc(c);
657 lexSkipLookahead(); 657 lexSkipLookahead();
658 c = lexLookahead(); 658 c = lexLookahead();
659 } 659 }
660 lexAppendc(0); 660 lexAppendc(0);
661 return lexStr(); 661 return lexStr();
662 } 662 }
663 663
664static void lexPushLookaheadc(int c) { 664static void lexPushLookaheadc(int c) {
665 int putptr; 665 int putptr;
666 /* can't putback EOF, because it never leaves lookahead buffer */ 666 /* can't putback EOF, because it never leaves lookahead buffer */
667 if (c == EOF) return; 667 if (c == EOF) return;
668 putptr = (int)lexBuf.getPtr - 1; 668 putptr = (int)lexBuf.getPtr - 1;
669 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; 669 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD;
670 lexBuf.getPtr = putptr; 670 lexBuf.getPtr = putptr;
671 lexBuf.buf[putptr] = c; 671 lexBuf.buf[putptr] = c;
672 lexBuf.len += 1; 672 lexBuf.len += 1;
673 } 673 }
674 674
675static char* lexLookaheadWord() { 675static char* lexLookaheadWord() {
676 /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 676 /* 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; 677 / and thing bigger than that will stop the lookahead and return 0;
678 / leading white spaces are not recoverable. 678 / leading white spaces are not recoverable.
679 */ 679 */
680 int c; 680 int c;
681 int len = 0; 681 int len = 0;
682 int curgetptr = 0; 682 int curgetptr = 0;
683 lexSkipWhite(); 683 lexSkipWhite();
684 lexClearToken(); 684 lexClearToken();
685 curgetptr = (int)lexBuf.getPtr;// remember! 685 curgetptr = (int)lexBuf.getPtr;// remember!
686 while (len < (MAX_LEX_LOOKAHEAD_0)) { 686 while (len < (MAX_LEX_LOOKAHEAD_0)) {
687 c = lexGetc(); 687 c = lexGetc();
688 len++; 688 len++;
689 if (c == EOF || strchr("\t\n ;:=", c)) { 689 if (c == EOF || strchr("\t\n ;:=", c)) {
690 lexAppendc(0); 690 lexAppendc(0);
691 /* restore lookahead buf. */ 691 /* restore lookahead buf. */
692 lexBuf.len += len; 692 lexBuf.len += len;
693 lexBuf.getPtr = curgetptr; 693 lexBuf.getPtr = curgetptr;
694 return lexStr(); 694 return lexStr();
695 } 695 }
696 else 696 else
697 lexAppendc(c); 697 lexAppendc(c);
698 } 698 }
699 lexBuf.len += len;/* char that has been moved to lookahead buffer */ 699 lexBuf.len += len;/* char that has been moved to lookahead buffer */
700 lexBuf.getPtr = curgetptr; 700 lexBuf.getPtr = curgetptr;
701 return 0; 701 return 0;
702 } 702 }
703 703
704#ifdef _SUPPORT_LINE_FOLDING 704#ifdef _SUPPORT_LINE_FOLDING
705static void handleMoreRFC822LineBreak(int c) { 705static void handleMoreRFC822LineBreak(int c) {
706 /* suport RFC 822 line break in cases like 706 /* suport RFC 822 line break in cases like
707 *ADR: foo; 707 *ADR: foo;
708 * morefoo; 708 * morefoo;
709 * more foo; 709 * more foo;
710 */ 710 */
711 if (c == ';') { 711 if (c == ';') {
712 int a; 712 int a;
713 lexSkipLookahead(); 713 lexSkipLookahead();
714 /* skip white spaces */ 714 /* skip white spaces */
715 a = lexLookahead(); 715 a = lexLookahead();
716 while (a == ' ' || a == '\t') { 716 while (a == ' ' || a == '\t') {
717 lexSkipLookahead(); 717 lexSkipLookahead();
718 a = lexLookahead(); 718 a = lexLookahead();
719 } 719 }
720 if (a == '\n') { 720 if (a == '\n') {
721 lexSkipLookahead(); 721 lexSkipLookahead();
722 a = lexLookahead(); 722 a = lexLookahead();
723 if (a == ' ' || a == '\t') { 723 if (a == ' ' || a == '\t') {
724 /* continuation, throw away all the \n and spaces read so 724 /* continuation, throw away all the \n and spaces read so
725 * far 725 * far
726 */ 726 */
727 lexSkipWhite(); 727 lexSkipWhite();
728 lexPushLookaheadc(';'); 728 lexPushLookaheadc(';');
729 } 729 }
730 else { 730 else {
731 lexPushLookaheadc('\n'); 731 lexPushLookaheadc('\n');
732 lexPushLookaheadc(';'); 732 lexPushLookaheadc(';');
733 } 733 }
734 } 734 }
735 else { 735 else {
736 lexPushLookaheadc(';'); 736 lexPushLookaheadc(';');
737 } 737 }
738 } 738 }
739 } 739 }
740 740
741static char* lexGet1Value() { 741static char* lexGet1Value() {
742 int c; 742 int c;
743 lexSkipWhite(); 743 lexSkipWhite();
744 c = lexLookahead(); 744 c = lexLookahead();
745 lexClearToken(); 745 lexClearToken();
746 while (c != EOF && c != ';') { 746 while (c != EOF && c != ';') {
747 if (c == '\\' ) { 747 if (c == '\\' ) {
748 int a; 748 int a;
749 lexSkipLookahead(); 749 lexSkipLookahead();
750 a = lexLookahead(); 750 a = lexLookahead();
751 if ( a != ';' ) { 751 if ( a != ';' ) {
752 lexAppendc('\\'); 752 lexAppendc('\\');
753 } else { 753 } else {
754 lexAppendc( ';' ); 754 lexAppendc( ';' );
755 lexSkipLookahead(); 755 lexSkipLookahead();
756 } 756 }
757 } else if (c == '\n') { 757 } else if (c == '\n') {
758 int a; 758 int a;
759 lexSkipLookahead(); 759 lexSkipLookahead();
760 a = lexLookahead(); 760 a = lexLookahead();
761 if (a == ' ' || a == '\t') { 761 if (a == ' ' || a == '\t') {
762 lexAppendc(' '); 762 lexAppendc(' ');
763 lexSkipLookahead(); 763 lexSkipLookahead();
764 } 764 }
765 else { 765 else {
766 lexPushLookaheadc('\n'); 766 lexPushLookaheadc('\n');
767 break; 767 break;
768 } 768 }
769 } 769 }
770 else { 770 else {
771 lexAppendc(c); 771 lexAppendc(c);
772 lexSkipLookahead(); 772 lexSkipLookahead();
773 } 773 }
774 c = lexLookahead(); 774 c = lexLookahead();
775 } 775 }
776 lexAppendc(0); 776 lexAppendc(0);
777 handleMoreRFC822LineBreak(c); 777 handleMoreRFC822LineBreak(c);
778 return c==EOF?0:lexStr(); 778 return c==EOF?0:lexStr();
779 } 779 }
780#endif 780#endif
781 781
782static int match_begin_name(int end) { 782static int match_begin_name(int end) {
783 char *n = lexLookaheadWord(); 783 char *n = lexLookaheadWord();
784 int token = ID; 784 int token = ID;
785 if (n) { 785 if (n) {
786 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD; 786 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD;
787 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL; 787 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL;
788 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT; 788 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT;
789 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO; 789 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO;
790 deleteStr(n); 790 deleteStr(n);
791 return token; 791 return token;
792 } 792 }
793 return 0; 793 return 0;
794 } 794 }
795 795
796 796
797#ifdef INCLUDEMFC 797#ifdef INCLUDEMFC
798void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile) 798void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile)
799#else 799#else
800void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) 800void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile)
801#endif 801#endif
802 { 802 {
803 // initialize lex mode stack 803 // initialize lex mode stack
804 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL; 804 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL;
805 805
806 // iniatialize lex buffer. 806 // iniatialize lex buffer.
807 lexBuf.inputString = (char*) inputstring; 807 lexBuf.inputString = (char*) inputstring;
808 lexBuf.inputLen = inputlen; 808 lexBuf.inputLen = inputlen;
809 lexBuf.curPos = 0; 809 lexBuf.curPos = 0;
810 lexBuf.inputFile = inputfile; 810 lexBuf.inputFile = inputfile;
811 811
812 lexBuf.len = 0; 812 lexBuf.len = 0;
813 lexBuf.getPtr = 0; 813 lexBuf.getPtr = 0;
814 814
815 lexBuf.maxToken = MAXTOKEN; 815 lexBuf.maxToken = MAXTOKEN;
816 lexBuf.strs = (char*)malloc(MAXTOKEN); 816 lexBuf.strs = (char*)malloc(MAXTOKEN);
817 lexBuf.strsLen = 0; 817 lexBuf.strsLen = 0;
818 818
819 } 819 }
820 820
821static void finiLex() { 821static void finiLex() {
822 free(lexBuf.strs); 822 free(lexBuf.strs);
823 } 823 }
824 824
825 825
826/*-----------------------------------*/ 826/*-----------------------------------*/
827/* This parses and converts the base64 format for binary encoding into 827/* This parses and converts the base64 format for binary encoding into
828 * a decoded buffer (allocated with new). See RFC 1521. 828 * a decoded buffer (allocated with new). See RFC 1521.
829 */ 829 */
830static char * lexGetDataFromBase64() 830static char * lexGetDataFromBase64()
831 { 831 {
832 unsigned long bytesLen = 0, bytesMax = 0; 832 unsigned long bytesLen = 0, bytesMax = 0;
833 int quadIx = 0, pad = 0; 833 int quadIx = 0, pad = 0;
834 unsigned long trip = 0; 834 unsigned long trip = 0;
835 unsigned char b; 835 unsigned char b;
836 int c; 836 int c;
837 unsigned char *bytes = NULL; 837 unsigned char *bytes = NULL;
838 unsigned char *oldBytes = NULL; 838 unsigned char *oldBytes = NULL;
839 839
840 DBG_(("db: lexGetDataFromBase64\n")); 840 DBG_(("db: lexGetDataFromBase64\n"));
841 while (1) { 841 while (1) {
842 c = lexGetc(); 842 c = lexGetc();
843 if (c == '\n') { 843 if (c == '\n') {
844 ++mime_lineNum; 844 ++mime_lineNum;
845 if (lexLookahead() == '\n') { 845 if (lexLookahead() == '\n') {
846 /* a '\n' character by itself means end of data */ 846 /* a '\n' character by itself means end of data */
847 break; 847 break;
848 } 848 }
849 else continue; /* ignore '\n' */ 849 else continue; /* ignore '\n' */
850 } 850 }
851 else { 851 else {
852 if ((c >= 'A') && (c <= 'Z')) 852 if ((c >= 'A') && (c <= 'Z'))
853 b = (unsigned char)(c - 'A'); 853 b = (unsigned char)(c - 'A');
854 else if ((c >= 'a') && (c <= 'z')) 854 else if ((c >= 'a') && (c <= 'z'))
855 b = (unsigned char)(c - 'a') + 26; 855 b = (unsigned char)(c - 'a') + 26;
856 else if ((c >= '0') && (c <= '9')) 856 else if ((c >= '0') && (c <= '9'))
857 b = (unsigned char)(c - '0') + 52; 857 b = (unsigned char)(c - '0') + 52;
858 else if (c == '+') 858 else if (c == '+')
859 b = 62; 859 b = 62;
860 else if (c == '/') 860 else if (c == '/')
861 b = 63; 861 b = 63;
862 else if (c == '=') { 862 else if (c == '=') {
863 b = 0; 863 b = 0;
864 pad++; 864 pad++;
865 } else if ((c == ' ') || (c == '\t')) { 865 } else if ((c == ' ') || (c == '\t')) {
866 continue; 866 continue;
867 } else { /* error condition */ 867 } else { /* error condition */
868 if (bytes) free(bytes); 868 if (bytes) free(bytes);
869 else if (oldBytes) free(oldBytes); 869 else if (oldBytes) free(oldBytes);
870 // error recovery: skip until 2 adjacent newlines. 870 // error recovery: skip until 2 adjacent newlines.
871 DBG_(("db: invalid character 0x%x '%c'\n", c,c)); 871 DBG_(("db: invalid character 0x%x '%c'\n", c,c));
872 if (c != EOF) { 872 if (c != EOF) {
873 c = lexGetc(); 873 c = lexGetc();
874 while (c != EOF) { 874 while (c != EOF) {
875 if (c == '\n' && lexLookahead() == '\n') { 875 if (c == '\n' && lexLookahead() == '\n') {
876 ++mime_lineNum; 876 ++mime_lineNum;
877 break; 877 break;
878 } 878 }
879 c = lexGetc(); 879 c = lexGetc();
880 } 880 }
881 } 881 }
882 return NULL; 882 return NULL;
883 } 883 }
884 trip = (trip << 6) | b; 884 trip = (trip << 6) | b;
885 if (++quadIx == 4) { 885 if (++quadIx == 4) {
886 unsigned char outBytes[3]; 886 unsigned char outBytes[3];
887 int numOut; 887 int numOut;
888 int i; 888 int i;
889 for (i = 0; i < 3; i++) { 889 for (i = 0; i < 3; i++) {
890 outBytes[2-i] = (unsigned char)(trip & 0xFF); 890 outBytes[2-i] = (unsigned char)(trip & 0xFF);
891 trip >>= 8; 891 trip >>= 8;
892 } 892 }
893 numOut = 3 - pad; 893 numOut = 3 - pad;
894 if (bytesLen + numOut > bytesMax) { 894 if (bytesLen + numOut > bytesMax) {
895 if (!bytes) { 895 if (!bytes) {
896 bytesMax = 1024; 896 bytesMax = 1024;
897 bytes = (unsigned char*)malloc((size_t)bytesMax); 897 bytes = (unsigned char*)malloc((size_t)bytesMax);
898 } 898 }
899 else { 899 else {
900 bytesMax <<= 2; 900 bytesMax <<= 2;
901 oldBytes = bytes; 901 oldBytes = bytes;
902 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax); 902 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax);
903 } 903 }
904 if (bytes == 0) { 904 if (bytes == 0) {
905 mime_error("out of memory while processing BASE64 data\n"); 905 mime_error("out of memory while processing BASE64 data\n");
906 } 906 }
907 } 907 }
908 if (bytes) { 908 if (bytes) {
909 memcpy(bytes + bytesLen, outBytes, numOut); 909 memcpy(bytes + bytesLen, outBytes, numOut);
910 bytesLen += numOut; 910 bytesLen += numOut;
911 } 911 }
912 trip = 0; 912 trip = 0;
913 quadIx = 0; 913 quadIx = 0;
914 } 914 }
915 } 915 }
916 } /* while */ 916 } /* while */
917 DBG_(("db: bytesLen = %d\n", bytesLen)); 917 DBG_(("db: bytesLen = %d\n", bytesLen));
918 /* kludge: all this won't be necessary if we have tree form 918 /* kludge: all this won't be necessary if we have tree form
919 representation */ 919 representation */
920 if (bytes) { 920 if (bytes) {
921 setValueWithSize(curProp,bytes,(unsigned int)bytesLen); 921 setValueWithSize(curProp,bytes,(unsigned int)bytesLen);
922 free(bytes); 922 free(bytes);
923 } 923 }
924 else if (oldBytes) { 924 else if (oldBytes) {
925 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); 925 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen);
926 free(oldBytes); 926 free(oldBytes);
927 } 927 }
928 return 0; 928 return 0;
929 } 929 }
930 930
931static int match_begin_end_name(int end) { 931static int match_begin_end_name(int end) {
932 int token; 932 int token;
933 lexSkipWhite(); 933 lexSkipWhite();
934 if (lexLookahead() != ':') return ID; 934 if (lexLookahead() != ':') return ID;
935 lexSkipLookahead(); 935 lexSkipLookahead();
936 lexSkipWhite(); 936 lexSkipWhite();
937 token = match_begin_name(end); 937 token = match_begin_name(end);
938 if (token == ID) { 938 if (token == ID) {
939 lexPushLookaheadc(':'); 939 lexPushLookaheadc(':');
940 DBG_(("db: ID '%s'\n", yylval.str)); 940 DBG_(("db: ID '%s'\n", yylval.str));
941 return ID; 941 return ID;
942 } 942 }
943 else if (token != 0) { 943 else if (token != 0) {
944 lexSkipLookaheadWord(); 944 lexSkipLookaheadWord();
945 deleteStr(yylval.str); 945 deleteStr(yylval.str);
946 DBG_(("db: begin/end %d\n", token)); 946 DBG_(("db: begin/end %d\n", token));
947 return token; 947 return token;
948 } 948 }
949 return 0; 949 return 0;
950 } 950 }
951 951
952static char* lexGetQuotedPrintable() 952static char* lexGetQuotedPrintable()
953 { 953 {
954 int cur; 954 int cur;
955 955
956 lexClearToken(); 956 lexClearToken();
957 do { 957 do {
958 cur = lexGetc(); 958 cur = lexGetc();
959 switch (cur) { 959 switch (cur) {
960 case '=': { 960 case '=': {
961 int c = 0; 961 int c = 0;
962 int next[2]; 962 int next[2];
963 int i; 963 int i;
964 for (i = 0; i < 2; i++) { 964 for (i = 0; i < 2; i++) {
965 next[i] = lexGetc(); 965 next[i] = lexGetc();
966 if (next[i] >= '0' && next[i] <= '9') 966 if (next[i] >= '0' && next[i] <= '9')
967 c = c * 16 + next[i] - '0'; 967 c = c * 16 + next[i] - '0';
968 else if (next[i] >= 'A' && next[i] <= 'F') 968 else if (next[i] >= 'A' && next[i] <= 'F')
969 c = c * 16 + next[i] - 'A' + 10; 969 c = c * 16 + next[i] - 'A' + 10;
970 else 970 else
971 break; 971 break;
972 } 972 }
973 if (i == 0) { 973 if (i == 0) {
974 /* single '=' follow by LINESEP is continuation sign? */ 974 /* single '=' follow by LINESEP is continuation sign? */
975 if (next[0] == '\n') { 975 if (next[0] == '\n') {
976 ++mime_lineNum; 976 ++mime_lineNum;
977 } 977 }
978 else { 978 else {
979 lexPushLookaheadc('='); 979 lexPushLookaheadc('=');
980 goto EndString; 980 goto EndString;
981 } 981 }
982 } 982 }
983 else if (i == 1) { 983 else if (i == 1) {
984 lexPushLookaheadc(next[1]); 984 lexPushLookaheadc(next[1]);
985 lexPushLookaheadc(next[0]); 985 lexPushLookaheadc(next[0]);
986 lexAppendc('='); 986 lexAppendc('=');
987 } else { 987 } else {
988 lexAppendc(c); 988 lexAppendc(c);
989 } 989 }
990 break; 990 break;
991 } /* '=' */ 991 } /* '=' */
992 case '\n': { 992 case '\n': {
993 lexPushLookaheadc('\n'); 993 lexPushLookaheadc('\n');
994 goto EndString; 994 goto EndString;
995 } 995 }
996 case (int)EOF: 996 case (int)EOF:
997 break; 997 break;
998 default: 998 default:
999 lexAppendc(cur); 999 lexAppendc(cur);
1000 break; 1000 break;
1001 } /* switch */ 1001 } /* switch */
1002 } while (cur != (int)EOF); 1002 } while (cur != (int)EOF);
1003 1003
1004EndString: 1004EndString:
1005 lexAppendc(0); 1005 lexAppendc(0);
1006 return lexStr(); 1006 return lexStr();
1007 } /* LexQuotedPrintable */ 1007 } /* LexQuotedPrintable */
1008 1008
1009static int yylex() { 1009static int yylex() {
1010 1010
1011 int lexmode = LEXMODE(); 1011 int lexmode = LEXMODE();
1012 if (lexmode == L_VALUES) { 1012 if (lexmode == L_VALUES) {
1013 int c = lexGetc(); 1013 int c = lexGetc();
1014 if (c == ';') { 1014 if (c == ';') {
1015 DBG_(("db: SEMICOLON\n")); 1015 DBG_(("db: SEMICOLON\n"));
1016 lexPushLookaheadc(c); 1016 lexPushLookaheadc(c);
1017 handleMoreRFC822LineBreak(c); 1017 handleMoreRFC822LineBreak(c);
1018 lexSkipLookahead(); 1018 lexSkipLookahead();
1019 return SEMICOLON; 1019 return SEMICOLON;
1020 } 1020 }
1021 else if (strchr("\n",c)) { 1021 else if (strchr("\n",c)) {
1022 ++mime_lineNum; 1022 ++mime_lineNum;
1023 /* consume all line separator(s) adjacent to each other */ 1023 /* consume all line separator(s) adjacent to each other */
1024 c = lexLookahead(); 1024 c = lexLookahead();
1025 while (strchr("\n",c)) { 1025 while (strchr("\n",c)) {
1026 lexSkipLookahead(); 1026 lexSkipLookahead();
1027 c = lexLookahead(); 1027 c = lexLookahead();
1028 ++mime_lineNum; 1028 ++mime_lineNum;
1029 } 1029 }
1030 DBG_(("db: LINESEP\n")); 1030 DBG_(("db: LINESEP\n"));
1031 return LINESEP; 1031 return LINESEP;
1032 } 1032 }
1033 else { 1033 else {
1034 char *p = 0; 1034 char *p = 0;
1035 lexPushLookaheadc(c); 1035 lexPushLookaheadc(c);
1036 if (lexWithinMode(L_BASE64)) { 1036 if (lexWithinMode(L_BASE64)) {
1037 /* get each char and convert to bin on the fly... */ 1037 /* get each char and convert to bin on the fly... */
1038 p = lexGetDataFromBase64(); 1038 p = lexGetDataFromBase64();
1039 yylval.str = p; 1039 yylval.str = p;
1040 return STRING; 1040 return STRING;
1041 } 1041 }
1042 else if (lexWithinMode(L_QUOTED_PRINTABLE)) { 1042 else if (lexWithinMode(L_QUOTED_PRINTABLE)) {
1043 p = lexGetQuotedPrintable(); 1043 p = lexGetQuotedPrintable();
1044 } 1044 }
1045 else { 1045 else {
1046#ifdef _SUPPORT_LINE_FOLDING 1046#ifdef _SUPPORT_LINE_FOLDING
1047 p = lexGet1Value(); 1047 p = lexGet1Value();
1048#else 1048#else
1049 p = lexGetStrUntil(";\n"); 1049 p = lexGetStrUntil(";\n");
1050#endif 1050#endif
1051 } 1051 }
1052 if (p) { 1052 if (p) {
1053 DBG_(("db: STRING: '%s'\n", p)); 1053 DBG_(("db: STRING: '%s'\n", p));
1054 yylval.str = p; 1054 yylval.str = p;
1055 return STRING; 1055 return STRING;
1056 } 1056 }
1057 else return 0; 1057 else return 0;
1058 } 1058 }
1059 } 1059 }
1060 else { 1060 else {
1061 /* normal mode */ 1061 /* normal mode */
1062 while (1) { 1062 while (1) {
1063 int c = lexGetc(); 1063 int c = lexGetc();
1064 switch(c) { 1064 switch(c) {
1065 case ':': { 1065 case ':': {
1066 /* consume all line separator(s) adjacent to each other */ 1066 /* consume all line separator(s) adjacent to each other */
1067 /* ignoring linesep immediately after colon. */ 1067 /* ignoring linesep immediately after colon. */
1068 c = lexLookahead(); 1068 c = lexLookahead();
1069 while (strchr("\n",c)) { 1069 while (strchr("\n",c)) {
1070 lexSkipLookahead(); 1070 lexSkipLookahead();
1071 c = lexLookahead(); 1071 c = lexLookahead();
1072 ++mime_lineNum; 1072 ++mime_lineNum;
1073 } 1073 }
1074 DBG_(("db: COLON\n")); 1074 DBG_(("db: COLON\n"));
1075 return COLON; 1075 return COLON;
1076 } 1076 }
1077 case ';': 1077 case ';':
1078 DBG_(("db: SEMICOLON\n")); 1078 DBG_(("db: SEMICOLON\n"));
1079 return SEMICOLON; 1079 return SEMICOLON;
1080 case '=': 1080 case '=':
1081 DBG_(("db: EQ\n")); 1081 DBG_(("db: EQ\n"));
1082 return EQ; 1082 return EQ;
1083 /* ignore whitespace in this mode */ 1083 /* ignore whitespace in this mode */
1084 case '\t': 1084 case '\t':
1085 case ' ': continue; 1085 case ' ': continue;
1086 case '\n': { 1086 case '\n': {
1087 ++mime_lineNum; 1087 ++mime_lineNum;
1088 continue; 1088 continue;
1089 } 1089 }
1090 case EOF: return 0; 1090 case EOF: return 0;
1091 break; 1091 break;
1092 default: { 1092 default: {
1093 lexPushLookaheadc(c); 1093 lexPushLookaheadc(c);
1094 if (isalnum(c)) { 1094 if (isalnum(c)) {
1095 char *t = lexGetWord(); 1095 char *t = lexGetWord();
1096 yylval.str = t; 1096 yylval.str = t;
1097 if (!qstricmp(t, "begin")) { 1097 if (!qstricmp(t, "begin")) {
1098 return match_begin_end_name(0); 1098 return match_begin_end_name(0);
1099 } 1099 }
1100 else if (!qstricmp(t,"end")) { 1100 else if (!qstricmp(t,"end")) {
1101 return match_begin_end_name(1); 1101 return match_begin_end_name(1);
1102 } 1102 }
1103 else { 1103 else {
1104 DBG_(("db: ID '%s'\n", t)); 1104 DBG_(("db: ID '%s'\n", t));
1105 return ID; 1105 return ID;
1106 } 1106 }
1107 } 1107 }
1108 else { 1108 else {
1109 /* unknow token */ 1109 /* unknow token */
1110 return 0; 1110 return 0;
1111 } 1111 }
1112 break; 1112 break;
1113 } 1113 }
1114 } 1114 }
1115 } 1115 }
1116 } 1116 }
1117 return 0; 1117 return 0;
1118 } 1118 }
1119 1119
1120 1120
1121/***************************************************************************/ 1121/***************************************************************************/
1122 /*** Public Functions ****/ 1122 /*** Public Functions ****/
1123/***************************************************************************/ 1123/***************************************************************************/
1124 1124
1125static VObject* Parse_MIMEHelper() 1125static VObject* Parse_MIMEHelper()
1126 { 1126 {
1127 ObjStackTop = -1; 1127 ObjStackTop = -1;
1128 mime_numErrors = 0; 1128 mime_numErrors = 0;
1129 mime_lineNum = 1; 1129 mime_lineNum = 1;
1130 vObjList = 0; 1130 vObjList = 0;
1131 curObj = 0; 1131 curObj = 0;
1132 1132
1133 if (yyparse() != 0) 1133 if (yyparse() != 0)
1134 return 0; 1134 return 0;
1135 1135
1136 finiLex(); 1136 finiLex();
1137 return vObjList; 1137 return vObjList;
1138 } 1138 }
1139 1139
1140/*--------------------------------------------*/ 1140/*--------------------------------------------*/
1141DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len) 1141DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len)
1142 { 1142 {
1143 initLex(input, len, 0); 1143 initLex(input, len, 0);
1144 return Parse_MIMEHelper(); 1144 return Parse_MIMEHelper();
1145 } 1145 }
1146 1146
1147 1147
1148#if INCLUDEMFC 1148#if INCLUDEMFC
1149 1149
1150DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file) 1150DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file)
1151 { 1151 {
1152 unsigned long startPos; 1152 unsigned long startPos;
1153 VObject *result; 1153 VObject *result;
1154 1154
1155 initLex(0,-1,file); 1155 initLex(0,-1,file);
1156 startPos = file->GetPosition(); 1156 startPos = file->GetPosition();
1157 if (!(result = Parse_MIMEHelper())) 1157 if (!(result = Parse_MIMEHelper()))
1158 file->Seek(startPos, CFile::begin); 1158 file->Seek(startPos, CFile::begin);
1159 return result; 1159 return result;
1160 } 1160 }
1161 1161
1162#else 1162#else
1163 1163
1164VObject* Parse_MIME_FromFile(FILE *file) 1164VObject* Parse_MIME_FromFile(FILE *file)
1165 { 1165 {
1166 VObject *result; 1166 VObject *result;
1167 long startPos; 1167 long startPos;
1168 1168
1169 initLex(0,(unsigned long)-1,file); 1169 initLex(0,(unsigned long)-1,file);
1170 startPos = ftell(file); 1170 startPos = ftell(file);
1171 if (!(result = Parse_MIMEHelper())) { 1171 if (!(result = Parse_MIMEHelper())) {
1172 fseek(file,startPos,SEEK_SET); 1172 fseek(file,startPos,SEEK_SET);
1173 } 1173 }
1174 return result; 1174 return result;
1175 } 1175 }
1176 1176
1177DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname) 1177DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname)
1178 { 1178 {
1179 FILE *fp = fopen(fname,"r"); 1179 FILE *fp = fopen(fname,"r");
1180 if (fp) { 1180 if (fp) {
1181 VObject* o = Parse_MIME_FromFile(fp); 1181 VObject* o = Parse_MIME_FromFile(fp);
1182 fclose(fp); 1182 fclose(fp);
1183 return o; 1183 return o;
1184 } 1184 }
1185 else { 1185 else {
1186 char msg[80]; 1186 char msg[80];
1187 sprintf(msg, "can't open file '%s' for reading\n", fname); 1187 sprintf(msg, "can't open file '%s' for reading\n", fname);
1188 mime_error_(msg); 1188 mime_error_(msg);
1189 return 0; 1189 return 0;
1190 } 1190 }
1191 } 1191 }
1192 1192
1193#endif 1193#endif
1194 1194
1195/*-------------------------------------*/ 1195/*-------------------------------------*/
1196 1196
1197static MimeErrorHandler mimeErrorHandler; 1197static MimeErrorHandler mimeErrorHandler;
1198 1198
1199DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me) 1199DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me)
1200 { 1200 {
1201 mimeErrorHandler = me; 1201 mimeErrorHandler = me;
1202 } 1202 }
1203 1203
1204void mime_error(char *s) 1204void mime_error(char *s)
1205 { 1205 {
1206 char msg[256]; 1206 char msg[256];
1207 if (mimeErrorHandler) { 1207 if (mimeErrorHandler) {
1208 sprintf(msg,"%s at line %d", s, mime_lineNum); 1208 sprintf(msg,"%s at line %d", s, mime_lineNum);
1209 mimeErrorHandler(msg); 1209 mimeErrorHandler(msg);
1210 } 1210 }
1211 } 1211 }
1212 1212
1213void mime_error_(char *s) 1213void mime_error_(char *s)
1214 { 1214 {
1215 if (mimeErrorHandler) { 1215 if (mimeErrorHandler) {
1216 mimeErrorHandler(s); 1216 mimeErrorHandler(s);
1217 } 1217 }
1218 } 1218 }
1219 1219
1220#line 1221 "y.tab.c" 1220#line 1221 "y.tab.c"
1221#define YYABORT goto yyabort 1221#define YYABORT goto yyabort
1222#define YYREJECT goto yyabort 1222#define YYREJECT goto yyabort
1223#define YYACCEPT goto yyaccept 1223#define YYACCEPT goto yyaccept
1224#define YYERROR goto yyerrlab 1224#define YYERROR goto yyerrlab
1225int 1225int
1226#if defined(__STDC__) 1226#if defined(__STDC__)
1227yyparse(void) 1227yyparse(void)
1228#else 1228#else
1229yyparse() 1229yyparse()
1230#endif 1230#endif
1231{ 1231{
1232 register int yym, yyn, yystate; 1232 register int yym, yyn, yystate;
1233#if YYDEBUG 1233#if YYDEBUG
1234 register char *yys; 1234 register char *yys;
1235 extern char *getenv(); 1235 extern char *getenv();
1236 1236
1237 if (yys = getenv("YYDEBUG")) 1237 if (yys = getenv("YYDEBUG"))
1238 { 1238 {
1239 yyn = *yys; 1239 yyn = *yys;
1240 if (yyn >= '0' && yyn <= '9') 1240 if (yyn >= '0' && yyn <= '9')
1241 yydebug = yyn - '0'; 1241 yydebug = yyn - '0';
1242 } 1242 }
1243#endif 1243#endif
1244 1244
1245 yynerrs = 0; 1245 yynerrs = 0;
1246 yyerrflag = 0; 1246 yyerrflag = 0;
1247 yychar = (-1); 1247 yychar = (-1);
1248 1248
1249 yyssp = yyss; 1249 yyssp = yyss;
1250 yyvsp = yyvs; 1250 yyvsp = yyvs;
1251 *yyssp = yystate = 0; 1251 *yyssp = yystate = 0;
1252 1252
1253yyloop: 1253yyloop:
1254 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 1254 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1255 if (yychar < 0) 1255 if (yychar < 0)
1256 { 1256 {
1257 if ((yychar = yylex()) < 0) yychar = 0; 1257 if ((yychar = yylex()) < 0) yychar = 0;
1258#if YYDEBUG 1258#if YYDEBUG
1259 if (yydebug) 1259 if (yydebug)
1260 { 1260 {
1261 yys = 0; 1261 yys = 0;
1262 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1262 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1263 if (!yys) yys = "illegal-symbol"; 1263 if (!yys) yys = "illegal-symbol";
1264 printf("%sdebug: state %d, reading %d (%s)\n", 1264 printf("%sdebug: state %d, reading %d (%s)\n",
1265 YYPREFIX, yystate, yychar, yys); 1265 YYPREFIX, yystate, yychar, yys);
1266 } 1266 }
1267#endif 1267#endif
1268 } 1268 }
1269 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && 1269 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1270 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1270 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1271 { 1271 {
1272#if YYDEBUG 1272#if YYDEBUG
1273 if (yydebug) 1273 if (yydebug)
1274 printf("%sdebug: state %d, shifting to state %d\n", 1274 printf("%sdebug: state %d, shifting to state %d\n",
1275 YYPREFIX, yystate, yytable[yyn]); 1275 YYPREFIX, yystate, yytable[yyn]);
1276#endif 1276#endif
1277 if (yyssp >= yyss + yystacksize - 1) 1277 if (yyssp >= yyss + yystacksize - 1)
1278 { 1278 {
1279 goto yyoverflow; 1279 goto yyoverflow;
1280 } 1280 }
1281 *++yyssp = yystate = yytable[yyn]; 1281 *++yyssp = yystate = yytable[yyn];
1282 *++yyvsp = yylval; 1282 *++yyvsp = yylval;
1283 yychar = (-1); 1283 yychar = (-1);
1284 if (yyerrflag > 0) --yyerrflag; 1284 if (yyerrflag > 0) --yyerrflag;
1285 goto yyloop; 1285 goto yyloop;
1286 } 1286 }
1287 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && 1287 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1288 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1288 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1289 { 1289 {
1290 yyn = yytable[yyn]; 1290 yyn = yytable[yyn];
1291 goto yyreduce; 1291 goto yyreduce;
1292 } 1292 }
1293 if (yyerrflag) goto yyinrecovery; 1293 if (yyerrflag) goto yyinrecovery;
1294 yyerror("syntax error"); 1294 yyerror("syntax error");
1295#ifdef lint 1295#ifdef lint
1296 goto yyerrlab; 1296 goto yyerrlab;
1297#endif 1297#endif
1298yyerrlab: 1298yyerrlab:
1299 ++yynerrs; 1299 ++yynerrs;
1300yyinrecovery: 1300yyinrecovery:
1301 if (yyerrflag < 3) 1301 if (yyerrflag < 3)
1302 { 1302 {
1303 yyerrflag = 3; 1303 yyerrflag = 3;
1304 for (;;) 1304 for (;;)
1305 { 1305 {
1306 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && 1306 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1307 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) 1307 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1308 { 1308 {
1309#if YYDEBUG 1309#if YYDEBUG
1310 if (yydebug) 1310 if (yydebug)
1311 printf("%sdebug: state %d, error recovery shifting\ 1311 printf("%sdebug: state %d, error recovery shifting\
1312 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); 1312 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1313#endif 1313#endif
1314 if (yyssp >= yyss + yystacksize - 1) 1314 if (yyssp >= yyss + yystacksize - 1)
1315 { 1315 {
1316 goto yyoverflow; 1316 goto yyoverflow;
1317 } 1317 }
1318 *++yyssp = yystate = yytable[yyn]; 1318 *++yyssp = yystate = yytable[yyn];
1319 *++yyvsp = yylval; 1319 *++yyvsp = yylval;
1320 goto yyloop; 1320 goto yyloop;
1321 } 1321 }
1322 else 1322 else
1323 { 1323 {
1324#if YYDEBUG 1324#if YYDEBUG
1325 if (yydebug) 1325 if (yydebug)
1326 printf("%sdebug: error recovery discarding state %d\n", 1326 printf("%sdebug: error recovery discarding state %d\n",
1327 YYPREFIX, *yyssp); 1327 YYPREFIX, *yyssp);
1328#endif 1328#endif
1329 if (yyssp <= yyss) goto yyabort; 1329 if (yyssp <= yyss) goto yyabort;
1330 --yyssp; 1330 --yyssp;
1331 --yyvsp; 1331 --yyvsp;
1332 } 1332 }
1333 } 1333 }
1334 } 1334 }
1335 else 1335 else
1336 { 1336 {
1337 if (yychar == 0) goto yyabort; 1337 if (yychar == 0) goto yyabort;
1338#if YYDEBUG 1338#if YYDEBUG
1339 if (yydebug) 1339 if (yydebug)
1340 { 1340 {
1341 yys = 0; 1341 yys = 0;
1342 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1342 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1343 if (!yys) yys = "illegal-symbol"; 1343 if (!yys) yys = "illegal-symbol";
1344 printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 1344 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1345 YYPREFIX, yystate, yychar, yys); 1345 YYPREFIX, yystate, yychar, yys);
1346 } 1346 }
1347#endif 1347#endif
1348 yychar = (-1); 1348 yychar = (-1);
1349 goto yyloop; 1349 goto yyloop;
1350 } 1350 }
1351yyreduce: 1351yyreduce:
1352#if YYDEBUG 1352#if YYDEBUG
1353 if (yydebug) 1353 if (yydebug)
1354 printf("%sdebug: state %d, reducing by rule %d (%s)\n", 1354 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1355 YYPREFIX, yystate, yyn, yyrule[yyn]); 1355 YYPREFIX, yystate, yyn, yyrule[yyn]);
1356#endif 1356#endif
1357 yym = yylen[yyn]; 1357 yym = yylen[yyn];
1358 yyval = yyvsp[1-yym]; 1358 yyval = yyvsp[1-yym];
1359 switch (yyn) 1359 switch (yyn)
1360 { 1360 {
1361case 2: 1361case 2:
1362#line 221 "backend/vcc.y" 1362#line 221 "backend/vcc.y"
1363{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; } 1363{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; }
1364break; 1364break;
1365case 3: 1365case 3:
1366#line 223 "backend/vcc.y" 1366#line 223 "backend/vcc.y"
1367{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; } 1367{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; }
1368break; 1368break;
1369case 6: 1369case 6:
1370#line 232 "backend/vcc.y" 1370#line 232 "backend/vcc.y"
1371{ 1371{
1372 lexPushMode(L_VCARD); 1372 lexPushMode(L_VCARD);
1373 if (!pushVObject(VCCardProp)) YYERROR; 1373 if (!pushVObject(VCCardProp)) YYERROR;
1374 } 1374 }
1375break; 1375break;
1376case 7: 1376case 7:
1377#line 237 "backend/vcc.y" 1377#line 237 "backend/vcc.y"
1378{ 1378{
1379 lexPopMode(0); 1379 lexPopMode(0);
1380 yyval.vobj = popVObject(); 1380 yyval.vobj = popVObject();
1381 } 1381 }
1382break; 1382break;
1383case 8: 1383case 8:
1384#line 242 "backend/vcc.y" 1384#line 242 "backend/vcc.y"
1385{ 1385{
1386 lexPushMode(L_VCARD); 1386 lexPushMode(L_VCARD);
1387 if (!pushVObject(VCCardProp)) YYERROR; 1387 if (!pushVObject(VCCardProp)) YYERROR;
1388 } 1388 }
1389break; 1389break;
1390case 9: 1390case 9:
1391#line 247 "backend/vcc.y" 1391#line 247 "backend/vcc.y"
1392{ 1392{
1393 lexPopMode(0); 1393 lexPopMode(0);
1394 yyval.vobj = popVObject(); 1394 yyval.vobj = popVObject();
1395 } 1395 }
1396break; 1396break;
1397case 12: 1397case 12:
1398#line 258 "backend/vcc.y" 1398#line 258 "backend/vcc.y"
1399{ 1399{
1400 lexPushMode(L_VALUES); 1400 lexPushMode(L_VALUES);
1401 } 1401 }
1402break; 1402break;
1403case 13: 1403case 13:
1404#line 262 "backend/vcc.y" 1404#line 262 "backend/vcc.y"
1405{ 1405{
1406 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE)) 1406 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE))
1407 lexPopMode(0); 1407 lexPopMode(0);
1408 lexPopMode(0); 1408 lexPopMode(0);
1409 } 1409 }
1410break; 1410break;
1411case 15: 1411case 15:
1412#line 271 "backend/vcc.y" 1412#line 271 "backend/vcc.y"
1413{ 1413{
1414 enterProps(yyvsp[0].str); 1414 enterProps(yyvsp[0].str);
1415 } 1415 }
1416break; 1416break;
1417case 17: 1417case 17:
1418#line 276 "backend/vcc.y" 1418#line 276 "backend/vcc.y"
1419{ 1419{
1420 enterProps(yyvsp[0].str); 1420 enterProps(yyvsp[0].str);
1421 } 1421 }
1422break; 1422break;
1423case 21: 1423case 21:
1424#line 289 "backend/vcc.y" 1424#line 289 "backend/vcc.y"
1425{ 1425{
1426 enterAttr(yyvsp[0].str,0); 1426 enterAttr(yyvsp[0].str,0);
1427 } 1427 }
1428break; 1428break;
1429case 22: 1429case 22:
1430#line 293 "backend/vcc.y" 1430#line 293 "backend/vcc.y"
1431{ 1431{
1432 enterAttr(yyvsp[-2].str,yyvsp[0].str); 1432 enterAttr(yyvsp[-2].str,yyvsp[0].str);
1433 1433
1434 } 1434 }
1435break; 1435break;
1436case 24: 1436case 24:
1437#line 302 "backend/vcc.y" 1437#line 302 "backend/vcc.y"
1438{ enterValues(yyvsp[-1].str); } 1438{ enterValues(yyvsp[-1].str); }
1439break; 1439break;
1440case 26: 1440case 26:
1441#line 304 "backend/vcc.y" 1441#line 304 "backend/vcc.y"
1442{ enterValues(yyvsp[0].str); } 1442{ enterValues(yyvsp[0].str); }
1443break; 1443break;
1444case 28: 1444case 28:
1445#line 309 "backend/vcc.y" 1445#line 309 "backend/vcc.y"
1446{ yyval.str = 0; } 1446{ yyval.str = 0; }
1447break; 1447break;
1448case 29: 1448case 29:
1449#line 314 "backend/vcc.y" 1449#line 314 "backend/vcc.y"
1450{ if (!pushVObject(VCCalProp)) YYERROR; } 1450{ if (!pushVObject(VCCalProp)) YYERROR; }
1451break; 1451break;
1452case 30: 1452case 30:
1453#line 317 "backend/vcc.y" 1453#line 317 "backend/vcc.y"
1454{ yyval.vobj = popVObject(); } 1454{ yyval.vobj = popVObject(); }
1455break; 1455break;
1456case 31: 1456case 31:
1457#line 319 "backend/vcc.y" 1457#line 319 "backend/vcc.y"
1458{ if (!pushVObject(VCCalProp)) YYERROR; } 1458{ if (!pushVObject(VCCalProp)) YYERROR; }
1459break; 1459break;
1460case 32: 1460case 32:
1461#line 321 "backend/vcc.y" 1461#line 321 "backend/vcc.y"
1462{ yyval.vobj = popVObject(); } 1462{ yyval.vobj = popVObject(); }
1463break; 1463break;
1464case 38: 1464case 38:
1465#line 336 "backend/vcc.y" 1465#line 336 "backend/vcc.y"
1466{ 1466{
1467 lexPushMode(L_VEVENT); 1467 lexPushMode(L_VEVENT);
1468 if (!pushVObject(VCEventProp)) YYERROR; 1468 if (!pushVObject(VCEventProp)) YYERROR;
1469 } 1469 }
1470break; 1470break;
1471case 39: 1471case 39:
1472#line 342 "backend/vcc.y" 1472#line 342 "backend/vcc.y"
1473{ 1473{
1474 lexPopMode(0); 1474 lexPopMode(0);
1475 popVObject(); 1475 popVObject();
1476 } 1476 }
1477break; 1477break;
1478case 40: 1478case 40:
1479#line 347 "backend/vcc.y" 1479#line 347 "backend/vcc.y"
1480{ 1480{
1481 lexPushMode(L_VEVENT); 1481 lexPushMode(L_VEVENT);
1482 if (!pushVObject(VCEventProp)) YYERROR; 1482 if (!pushVObject(VCEventProp)) YYERROR;
1483 } 1483 }
1484break; 1484break;
1485case 41: 1485case 41:
1486#line 352 "backend/vcc.y" 1486#line 352 "backend/vcc.y"
1487{ 1487{
1488 lexPopMode(0); 1488 lexPopMode(0);
1489 popVObject(); 1489 popVObject();
1490 } 1490 }
1491break; 1491break;
1492case 42: 1492case 42:
1493#line 360 "backend/vcc.y" 1493#line 360 "backend/vcc.y"
1494{ 1494{
1495 lexPushMode(L_VTODO); 1495 lexPushMode(L_VTODO);
1496 if (!pushVObject(VCTodoProp)) YYERROR; 1496 if (!pushVObject(VCTodoProp)) YYERROR;
1497 } 1497 }
1498break; 1498break;
1499case 43: 1499case 43:
1500#line 366 "backend/vcc.y" 1500#line 366 "backend/vcc.y"
1501{ 1501{
1502 lexPopMode(0); 1502 lexPopMode(0);
1503 popVObject(); 1503 popVObject();
1504 } 1504 }
1505break; 1505break;
1506case 44: 1506case 44:
1507#line 371 "backend/vcc.y" 1507#line 371 "backend/vcc.y"
1508{ 1508{
1509 lexPushMode(L_VTODO); 1509 lexPushMode(L_VTODO);
1510 if (!pushVObject(VCTodoProp)) YYERROR; 1510 if (!pushVObject(VCTodoProp)) YYERROR;
1511 } 1511 }
1512break; 1512break;
1513case 45: 1513case 45:
1514#line 376 "backend/vcc.y" 1514#line 376 "backend/vcc.y"
1515{ 1515{
1516 lexPopMode(0); 1516 lexPopMode(0);
1517 popVObject(); 1517 popVObject();
1518 } 1518 }
1519break; 1519break;
1520#line 1521 "y.tab.c" 1520#line 1521 "y.tab.c"
1521 } 1521 }
1522 yyssp -= yym; 1522 yyssp -= yym;
1523 yystate = *yyssp; 1523 yystate = *yyssp;
1524 yyvsp -= yym; 1524 yyvsp -= yym;
1525 yym = yylhs[yyn]; 1525 yym = yylhs[yyn];
1526 if (yystate == 0 && yym == 0) 1526 if (yystate == 0 && yym == 0)
1527 { 1527 {
1528#if YYDEBUG 1528#if YYDEBUG
1529 if (yydebug) 1529 if (yydebug)
1530 printf("%sdebug: after reduction, shifting from state 0 to\ 1530 printf("%sdebug: after reduction, shifting from state 0 to\
1531 state %d\n", YYPREFIX, YYFINAL); 1531 state %d\n", YYPREFIX, YYFINAL);
1532#endif 1532#endif
1533 yystate = YYFINAL; 1533 yystate = YYFINAL;
1534 *++yyssp = YYFINAL; 1534 *++yyssp = YYFINAL;
1535 *++yyvsp = yyval; 1535 *++yyvsp = yyval;
1536 if (yychar < 0) 1536 if (yychar < 0)
1537 { 1537 {
1538 if ((yychar = yylex()) < 0) yychar = 0; 1538 if ((yychar = yylex()) < 0) yychar = 0;
1539#if YYDEBUG 1539#if YYDEBUG
1540 if (yydebug) 1540 if (yydebug)
1541 { 1541 {
1542 yys = 0; 1542 yys = 0;
1543 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1543 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1544 if (!yys) yys = "illegal-symbol"; 1544 if (!yys) yys = "illegal-symbol";
1545 printf("%sdebug: state %d, reading %d (%s)\n", 1545 printf("%sdebug: state %d, reading %d (%s)\n",
1546 YYPREFIX, YYFINAL, yychar, yys); 1546 YYPREFIX, YYFINAL, yychar, yys);
1547 } 1547 }
1548#endif 1548#endif
1549 } 1549 }
1550 if (yychar == 0) goto yyaccept; 1550 if (yychar == 0) goto yyaccept;
1551 goto yyloop; 1551 goto yyloop;
1552 } 1552 }
1553 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && 1553 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1554 yyn <= YYTABLESIZE && yycheck[yyn] == yystate) 1554 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1555 yystate = yytable[yyn]; 1555 yystate = yytable[yyn];
1556 else 1556 else
1557 yystate = yydgoto[yym]; 1557 yystate = yydgoto[yym];
1558#if YYDEBUG 1558#if YYDEBUG
1559 if (yydebug) 1559 if (yydebug)
1560 printf("%sdebug: after reduction, shifting from state %d \ 1560 printf("%sdebug: after reduction, shifting from state %d \
1561to state %d\n", YYPREFIX, *yyssp, yystate); 1561to state %d\n", YYPREFIX, *yyssp, yystate);
1562#endif 1562#endif
1563 if (yyssp >= yyss + yystacksize - 1) 1563 if (yyssp >= yyss + yystacksize - 1)
1564 { 1564 {
1565 goto yyoverflow; 1565 goto yyoverflow;
1566 } 1566 }
1567 *++yyssp = yystate; 1567 *++yyssp = yystate;
1568 *++yyvsp = yyval; 1568 *++yyvsp = yyval;
1569 goto yyloop; 1569 goto yyloop;
1570yyoverflow: 1570yyoverflow:
1571 yyerror("yacc stack overflow"); 1571 yyerror("yacc stack overflow");
1572yyabort: 1572yyabort:
1573 return (1); 1573 return (1);
1574yyaccept: 1574yyaccept:
1575 return (0); 1575 return (0);
1576} 1576}
diff --git a/library/backend/vobject.cpp b/library/backend/vobject.cpp
index e6f6b78..dab128e 100644
--- a/library/backend/vobject.cpp
+++ b/library/backend/vobject.cpp
@@ -1,1315 +1,1315 @@
1/*************************************************************************** 1/***************************************************************************
2(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International 2(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
3Business Machines Corporation and Siemens Rolm Communications Inc. 3Business Machines Corporation and Siemens Rolm Communications Inc.
4 4
5For purposes of this license notice, the term Licensors shall mean, 5For purposes of this license notice, the term Licensors shall mean,
6collectively, Apple Computer, Inc., AT&T Corp., International 6collectively, Apple Computer, Inc., AT&T Corp., International
7Business Machines Corporation and Siemens Rolm Communications Inc. 7Business Machines Corporation and Siemens Rolm Communications Inc.
8The term Licensor shall mean any of the Licensors. 8The term Licensor shall mean any of the Licensors.
9 9
10Subject to acceptance of the following conditions, permission is hereby 10Subject to acceptance of the following conditions, permission is hereby
11granted by Licensors without the need for written agreement and without 11granted by Licensors without the need for written agreement and without
12license or royalty fees, to use, copy, modify and distribute this 12license or royalty fees, to use, copy, modify and distribute this
13software for any purpose. 13software for any purpose.
14 14
15The above copyright notice and the following four paragraphs must be 15The above copyright notice and the following four paragraphs must be
16reproduced in all copies of this software and any software including 16reproduced in all copies of this software and any software including
17this software. 17this software.
18 18
19THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE 19THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
20ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR 20ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
21MODIFICATIONS. 21MODIFICATIONS.
22 22
23IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, 23IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
24INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 24INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
25OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26DAMAGE. 26DAMAGE.
27 27
28EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, 28EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
29INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE 29INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31PURPOSE. 31PURPOSE.
32 32
33The software is provided with RESTRICTED RIGHTS. Use, duplication, or 33The software is provided with RESTRICTED RIGHTS. Use, duplication, or
34disclosure by the government are subject to restrictions set forth in 34disclosure by the government are subject to restrictions set forth in
35DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. 35DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.
36 36
37***************************************************************************/ 37***************************************************************************/
38 38
39/* 39/*
40 * src: vobject.c 40 * src: vobject.c
41 * doc: vobject and APIs to construct vobject, APIs pretty print 41 * doc: vobject and APIs to construct vobject, APIs pretty print
42 * vobject, and convert a vobject into its textual representation. 42 * vobject, and convert a vobject into its textual representation.
43 */ 43 */
44 44
45 #ifndef MWERKS 45 #ifndef MWERKS
46#include <malloc.h> 46#include <malloc.h>
47#endif 47#endif
48 48
49#include "vobject_p.h" 49#include <qtopia/private/vobject_p.h>
50#include "qfiledirect_p.h" 50#include <qtopia/private/qfiledirect_p.h>
51#include <string.h> 51#include <string.h>
52#include <stdio.h> 52#include <stdio.h>
53#include <fcntl.h> 53#include <fcntl.h>
54//#include <io.h> 54//#include <io.h>
55 55
56 56
57 #define NAME_OF(o) o->id 57 #define NAME_OF(o) o->id
58 #define VALUE_TYPE(o) o->valType 58 #define VALUE_TYPE(o) o->valType
59 #define STRINGZ_VALUE_OF(o) o->val.strs 59 #define STRINGZ_VALUE_OF(o) o->val.strs
60 #define INTEGER_VALUE_OF(o) o->val.i 60 #define INTEGER_VALUE_OF(o) o->val.i
61 #define LONG_VALUE_OF(o) o->val.l 61 #define LONG_VALUE_OF(o) o->val.l
62 #define ANY_VALUE_OF(o) o->val.any 62 #define ANY_VALUE_OF(o) o->val.any
63 #define VOBJECT_VALUE_OF(o) o->val.vobj 63 #define VOBJECT_VALUE_OF(o) o->val.vobj
64 64
65typedef union ValueItem { 65typedef union ValueItem {
66 const char *strs; 66 const char *strs;
67 unsigned int i; 67 unsigned int i;
68 unsigned long l; 68 unsigned long l;
69 void *any; 69 void *any;
70 VObject *vobj; 70 VObject *vobj;
71 } ValueItem; 71 } ValueItem;
72 72
73struct VObject { 73struct VObject {
74 VObject *next; 74 VObject *next;
75 const char *id; 75 const char *id;
76 VObject *prop; 76 VObject *prop;
77 unsigned short valType; 77 unsigned short valType;
78 ValueItem val; 78 ValueItem val;
79 }; 79 };
80 80
81typedef struct StrItem StrItem; 81typedef struct StrItem StrItem;
82 82
83struct StrItem { 83struct StrItem {
84 StrItem *next; 84 StrItem *next;
85 const char *s; 85 const char *s;
86 unsigned int refCnt; 86 unsigned int refCnt;
87 }; 87 };
88 88
89const char** fieldedProp; 89const char** fieldedProp;
90 90
91 91
92 92
93/*---------------------------------------------------------------------- 93/*----------------------------------------------------------------------
94 The following functions involve with memory allocation: 94 The following functions involve with memory allocation:
95 newVObject 95 newVObject
96 deleteVObject 96 deleteVObject
97 dupStr 97 dupStr
98 deleteStr 98 deleteStr
99 newStrItem 99 newStrItem
100 deleteStrItem 100 deleteStrItem
101 ----------------------------------------------------------------------*/ 101 ----------------------------------------------------------------------*/
102 102
103DLLEXPORT(VObject*) newVObject_(const char *id) 103DLLEXPORT(VObject*) newVObject_(const char *id)
104{ 104{
105 VObject *p = (VObject*)malloc(sizeof(VObject)); 105 VObject *p = (VObject*)malloc(sizeof(VObject));
106 p->next = 0; 106 p->next = 0;
107 p->id = id; 107 p->id = id;
108 p->prop = 0; 108 p->prop = 0;
109 VALUE_TYPE(p) = 0; 109 VALUE_TYPE(p) = 0;
110 ANY_VALUE_OF(p) = 0; 110 ANY_VALUE_OF(p) = 0;
111 return p; 111 return p;
112} 112}
113 113
114DLLEXPORT(VObject*) newVObject(const char *id) 114DLLEXPORT(VObject*) newVObject(const char *id)
115{ 115{
116 return newVObject_(lookupStr(id)); 116 return newVObject_(lookupStr(id));
117} 117}
118 118
119DLLEXPORT(void) deleteVObject(VObject *p) 119DLLEXPORT(void) deleteVObject(VObject *p)
120{ 120{
121 unUseStr(p->id); 121 unUseStr(p->id);
122 free(p); 122 free(p);
123} 123}
124 124
125DLLEXPORT(char*) dupStr(const char *s, unsigned int size) 125DLLEXPORT(char*) dupStr(const char *s, unsigned int size)
126{ 126{
127 char *t; 127 char *t;
128 if (size == 0) { 128 if (size == 0) {
129 size = strlen(s); 129 size = strlen(s);
130 } 130 }
131 t = (char*)malloc(size+1); 131 t = (char*)malloc(size+1);
132 if (t) { 132 if (t) {
133 memcpy(t,s,size); 133 memcpy(t,s,size);
134 t[size] = 0; 134 t[size] = 0;
135 return t; 135 return t;
136 } 136 }
137 else { 137 else {
138 return (char*)0; 138 return (char*)0;
139 } 139 }
140} 140}
141 141
142DLLEXPORT(void) deleteStr(const char *p) 142DLLEXPORT(void) deleteStr(const char *p)
143{ 143{
144 if (p) free((void*)p); 144 if (p) free((void*)p);
145} 145}
146 146
147 147
148static StrItem* newStrItem(const char *s, StrItem *next) 148static StrItem* newStrItem(const char *s, StrItem *next)
149{ 149{
150 StrItem *p = (StrItem*)malloc(sizeof(StrItem)); 150 StrItem *p = (StrItem*)malloc(sizeof(StrItem));
151 p->next = next; 151 p->next = next;
152 p->s = s; 152 p->s = s;
153 p->refCnt = 1; 153 p->refCnt = 1;
154 return p; 154 return p;
155} 155}
156 156
157static void deleteStrItem(StrItem *p) 157static void deleteStrItem(StrItem *p)
158{ 158{
159 free((void*)p); 159 free((void*)p);
160} 160}
161 161
162 162
163/*---------------------------------------------------------------------- 163/*----------------------------------------------------------------------
164 The following function provide accesses to VObject's value. 164 The following function provide accesses to VObject's value.
165 ----------------------------------------------------------------------*/ 165 ----------------------------------------------------------------------*/
166 166
167DLLEXPORT(const char*) vObjectName(VObject *o) 167DLLEXPORT(const char*) vObjectName(VObject *o)
168{ 168{
169 return NAME_OF(o); 169 return NAME_OF(o);
170} 170}
171 171
172DLLEXPORT(void) setVObjectName(VObject *o, const char* id) 172DLLEXPORT(void) setVObjectName(VObject *o, const char* id)
173{ 173{
174 NAME_OF(o) = id; 174 NAME_OF(o) = id;
175} 175}
176 176
177DLLEXPORT(const char*) vObjectStringZValue(VObject *o) 177DLLEXPORT(const char*) vObjectStringZValue(VObject *o)
178{ 178{
179 return STRINGZ_VALUE_OF(o); 179 return STRINGZ_VALUE_OF(o);
180} 180}
181 181
182DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s) 182DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s)
183{ 183{
184 STRINGZ_VALUE_OF(o) = dupStr(s,0); 184 STRINGZ_VALUE_OF(o) = dupStr(s,0);
185 VALUE_TYPE(o) = VCVT_STRINGZ; 185 VALUE_TYPE(o) = VCVT_STRINGZ;
186} 186}
187 187
188DLLEXPORT(void) setVObjectStringZValue_(VObject *o, const char *s) 188DLLEXPORT(void) setVObjectStringZValue_(VObject *o, const char *s)
189{ 189{
190 STRINGZ_VALUE_OF(o) = s; 190 STRINGZ_VALUE_OF(o) = s;
191 VALUE_TYPE(o) = VCVT_STRINGZ; 191 VALUE_TYPE(o) = VCVT_STRINGZ;
192} 192}
193 193
194DLLEXPORT(unsigned int) vObjectIntegerValue(VObject *o) 194DLLEXPORT(unsigned int) vObjectIntegerValue(VObject *o)
195{ 195{
196 return INTEGER_VALUE_OF(o); 196 return INTEGER_VALUE_OF(o);
197} 197}
198 198
199DLLEXPORT(void) setVObjectIntegerValue(VObject *o, unsigned int i) 199DLLEXPORT(void) setVObjectIntegerValue(VObject *o, unsigned int i)
200{ 200{
201 INTEGER_VALUE_OF(o) = i; 201 INTEGER_VALUE_OF(o) = i;
202 VALUE_TYPE(o) = VCVT_UINT; 202 VALUE_TYPE(o) = VCVT_UINT;
203} 203}
204 204
205DLLEXPORT(unsigned long) vObjectLongValue(VObject *o) 205DLLEXPORT(unsigned long) vObjectLongValue(VObject *o)
206{ 206{
207 return LONG_VALUE_OF(o); 207 return LONG_VALUE_OF(o);
208} 208}
209 209
210DLLEXPORT(void) setVObjectLongValue(VObject *o, unsigned long l) 210DLLEXPORT(void) setVObjectLongValue(VObject *o, unsigned long l)
211{ 211{
212 LONG_VALUE_OF(o) = l; 212 LONG_VALUE_OF(o) = l;
213 VALUE_TYPE(o) = VCVT_ULONG; 213 VALUE_TYPE(o) = VCVT_ULONG;
214} 214}
215 215
216DLLEXPORT(void*) vObjectAnyValue(VObject *o) 216DLLEXPORT(void*) vObjectAnyValue(VObject *o)
217{ 217{
218 return ANY_VALUE_OF(o); 218 return ANY_VALUE_OF(o);
219} 219}
220 220
221DLLEXPORT(void) setVObjectAnyValue(VObject *o, void *t) 221DLLEXPORT(void) setVObjectAnyValue(VObject *o, void *t)
222{ 222{
223 ANY_VALUE_OF(o) = t; 223 ANY_VALUE_OF(o) = t;
224 VALUE_TYPE(o) = VCVT_RAW; 224 VALUE_TYPE(o) = VCVT_RAW;
225} 225}
226 226
227DLLEXPORT(VObject*) vObjectVObjectValue(VObject *o) 227DLLEXPORT(VObject*) vObjectVObjectValue(VObject *o)
228{ 228{
229 return VOBJECT_VALUE_OF(o); 229 return VOBJECT_VALUE_OF(o);
230} 230}
231 231
232DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p) 232DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p)
233{ 233{
234 VOBJECT_VALUE_OF(o) = p; 234 VOBJECT_VALUE_OF(o) = p;
235 VALUE_TYPE(o) = VCVT_VOBJECT; 235 VALUE_TYPE(o) = VCVT_VOBJECT;
236} 236}
237 237
238DLLEXPORT(int) vObjectValueType(VObject *o) 238DLLEXPORT(int) vObjectValueType(VObject *o)
239{ 239{
240 return VALUE_TYPE(o); 240 return VALUE_TYPE(o);
241} 241}
242 242
243 243
244/*---------------------------------------------------------------------- 244/*----------------------------------------------------------------------
245 The following functions can be used to build VObject. 245 The following functions can be used to build VObject.
246 ----------------------------------------------------------------------*/ 246 ----------------------------------------------------------------------*/
247 247
248DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p) 248DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p)
249{ 249{
250 /* circular link list pointed to tail */ 250 /* circular link list pointed to tail */
251 /* 251 /*
252 o {next,id,prop,val} 252 o {next,id,prop,val}
253 V 253 V
254 pn {next,id,prop,val} 254 pn {next,id,prop,val}
255 V 255 V
256 ... 256 ...
257 p1 {next,id,prop,val} 257 p1 {next,id,prop,val}
258 V 258 V
259 pn 259 pn
260 --> 260 -->
261 o {next,id,prop,val} 261 o {next,id,prop,val}
262 V 262 V
263 pn {next,id,prop,val} 263 pn {next,id,prop,val}
264 V 264 V
265 p {next,id,prop,val} 265 p {next,id,prop,val}
266 ... 266 ...
267 p1 {next,id,prop,val} 267 p1 {next,id,prop,val}
268 V 268 V
269 pn 269 pn
270 */ 270 */
271 271
272 VObject *tail = o->prop; 272 VObject *tail = o->prop;
273 if (tail) { 273 if (tail) {
274 p->next = tail->next; 274 p->next = tail->next;
275 o->prop = tail->next = p; 275 o->prop = tail->next = p;
276 } 276 }
277 else { 277 else {
278 o->prop = p->next = p; 278 o->prop = p->next = p;
279 } 279 }
280 return p; 280 return p;
281} 281}
282 282
283DLLEXPORT(VObject*) addProp(VObject *o, const char *id) 283DLLEXPORT(VObject*) addProp(VObject *o, const char *id)
284{ 284{
285 return addVObjectProp(o,newVObject(id)); 285 return addVObjectProp(o,newVObject(id));
286} 286}
287 287
288DLLEXPORT(VObject*) addProp_(VObject *o, const char *id) 288DLLEXPORT(VObject*) addProp_(VObject *o, const char *id)
289{ 289{
290 return addVObjectProp(o,newVObject_(id)); 290 return addVObjectProp(o,newVObject_(id));
291} 291}
292 292
293DLLEXPORT(void) addList(VObject **o, VObject *p) 293DLLEXPORT(void) addList(VObject **o, VObject *p)
294{ 294{
295 p->next = 0; 295 p->next = 0;
296 if (*o == 0) { 296 if (*o == 0) {
297 *o = p; 297 *o = p;
298 } 298 }
299 else { 299 else {
300 VObject *t = *o; 300 VObject *t = *o;
301 while (t->next) { 301 while (t->next) {
302 t = t->next; 302 t = t->next;
303 } 303 }
304 t->next = p; 304 t->next = p;
305 } 305 }
306} 306}
307 307
308DLLEXPORT(VObject*) nextVObjectInList(VObject *o) 308DLLEXPORT(VObject*) nextVObjectInList(VObject *o)
309{ 309{
310 return o->next; 310 return o->next;
311} 311}
312 312
313DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size) 313DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size)
314{ 314{
315 VObject *sizeProp; 315 VObject *sizeProp;
316 setVObjectAnyValue(prop, val); 316 setVObjectAnyValue(prop, val);
317 sizeProp = addProp(prop,VCDataSizeProp); 317 sizeProp = addProp(prop,VCDataSizeProp);
318 setVObjectLongValue(sizeProp, size); 318 setVObjectLongValue(sizeProp, size);
319 return prop; 319 return prop;
320} 320}
321 321
322DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size) 322DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size)
323{ 323{
324 void *p = dupStr((const char *)val,size); 324 void *p = dupStr((const char *)val,size);
325 return setValueWithSize_(prop,p,p?size:0); 325 return setValueWithSize_(prop,p,p?size:0);
326} 326}
327 327
328DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o) 328DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o)
329{ 329{
330 i->start = o->prop; 330 i->start = o->prop;
331 i->next = 0; 331 i->next = 0;
332} 332}
333 333
334DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o) 334DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o)
335{ 335{
336 i->start = o->next; 336 i->start = o->next;
337 i->next = 0; 337 i->next = 0;
338} 338}
339 339
340DLLEXPORT(int) moreIteration(VObjectIterator *i) 340DLLEXPORT(int) moreIteration(VObjectIterator *i)
341{ 341{
342 return (i->start && (i->next==0 || i->next!=i->start)); 342 return (i->start && (i->next==0 || i->next!=i->start));
343} 343}
344 344
345DLLEXPORT(VObject*) nextVObject(VObjectIterator *i) 345DLLEXPORT(VObject*) nextVObject(VObjectIterator *i)
346{ 346{
347 if (i->start && i->next != i->start) { 347 if (i->start && i->next != i->start) {
348 if (i->next == 0) { 348 if (i->next == 0) {
349 i->next = i->start->next; 349 i->next = i->start->next;
350 return i->next; 350 return i->next;
351 } 351 }
352 else { 352 else {
353 i->next = i->next->next; 353 i->next = i->next->next;
354 return i->next; 354 return i->next;
355 } 355 }
356 } 356 }
357 else return (VObject*)0; 357 else return (VObject*)0;
358} 358}
359 359
360DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id) 360DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id)
361{ 361{
362 VObjectIterator i; 362 VObjectIterator i;
363 initPropIterator(&i,o); 363 initPropIterator(&i,o);
364 while (moreIteration(&i)) { 364 while (moreIteration(&i)) {
365 VObject *each = nextVObject(&i); 365 VObject *each = nextVObject(&i);
366 if (!qstricmp(id,each->id)) 366 if (!qstricmp(id,each->id))
367 return each; 367 return each;
368 } 368 }
369 return (VObject*)0; 369 return (VObject*)0;
370} 370}
371 371
372DLLEXPORT(VObject*) addGroup(VObject *o, const char *g) 372DLLEXPORT(VObject*) addGroup(VObject *o, const char *g)
373{ 373{
374 /* 374 /*
375 a.b.c 375 a.b.c
376 --> 376 -->
377 prop(c) 377 prop(c)
378 prop(VCGrouping=b) 378 prop(VCGrouping=b)
379 prop(VCGrouping=a) 379 prop(VCGrouping=a)
380 */ 380 */
381 char *dot = strrchr(g,'.'); 381 char *dot = strrchr(g,'.');
382 if (dot) { 382 if (dot) {
383 VObject *p, *t; 383 VObject *p, *t;
384 char *gs, *n = dot+1; 384 char *gs, *n = dot+1;
385 gs = dupStr(g,0);/* so we can write to it. */ 385 gs = dupStr(g,0);/* so we can write to it. */
386 /* used to be 386 /* used to be
387 * t = p = addProp_(o,lookupProp_(n)); 387 * t = p = addProp_(o,lookupProp_(n));
388 */ 388 */
389 t = p = addProp_(o,lookupProp(n)); 389 t = p = addProp_(o,lookupProp(n));
390 dot = strrchr(gs,'.'); 390 dot = strrchr(gs,'.');
391 *dot = 0; 391 *dot = 0;
392 do { 392 do {
393 dot = strrchr(gs,'.'); 393 dot = strrchr(gs,'.');
394 if (dot) { 394 if (dot) {
395 n = dot+1; 395 n = dot+1;
396 *dot=0; 396 *dot=0;
397 } 397 }
398 else 398 else
399 n = gs; 399 n = gs;
400 /* property(VCGroupingProp=n); 400 /* property(VCGroupingProp=n);
401 *and the value may have VCGrouping property 401 *and the value may have VCGrouping property
402 */ 402 */
403 t = addProp(t,VCGroupingProp); 403 t = addProp(t,VCGroupingProp);
404 setVObjectStringZValue(t,lookupProp_(n)); 404 setVObjectStringZValue(t,lookupProp_(n));
405 } while (n != gs); 405 } while (n != gs);
406 deleteStr(gs); 406 deleteStr(gs);
407 return p; 407 return p;
408 } 408 }
409 else 409 else
410 return addProp_(o,lookupProp(g)); 410 return addProp_(o,lookupProp(g));
411} 411}
412 412
413DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v) 413DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v)
414{ 414{
415 VObject *prop; 415 VObject *prop;
416 prop = addProp(o,p); 416 prop = addProp(o,p);
417 setVObjectStringZValue_(prop, strdup( v ) ); 417 setVObjectStringZValue_(prop, strdup( v ) );
418 return prop; 418 return prop;
419} 419}
420 420
421DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v, 421DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v,
422 unsigned int size) 422 unsigned int size)
423{ 423{
424 VObject *prop; 424 VObject *prop;
425 prop = addProp(o,p); 425 prop = addProp(o,p);
426 setValueWithSize_(prop, (void*)v, size); 426 setValueWithSize_(prop, (void*)v, size);
427 return prop; 427 return prop;
428} 428}
429 429
430DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v, 430DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v,
431 unsigned int size) 431 unsigned int size)
432{ 432{
433 return addPropSizedValue_(o,p,dupStr(v,size),size); 433 return addPropSizedValue_(o,p,dupStr(v,size),size);
434} 434}
435 435
436 436
437DLLEXPORT(void) cleanVObject(VObject *o) 437DLLEXPORT(void) cleanVObject(VObject *o)
438{ 438{
439 if (o == 0) return; 439 if (o == 0) return;
440 if (o->prop) { 440 if (o->prop) {
441 /* destroy time: cannot use the iterator here. 441 /* destroy time: cannot use the iterator here.
442 Have to break the cycle in the circular link 442 Have to break the cycle in the circular link
443 list and turns it into regular NULL-terminated 443 list and turns it into regular NULL-terminated
444 list -- since at some point of destruction, 444 list -- since at some point of destruction,
445 the reference entry for the iterator to work 445 the reference entry for the iterator to work
446 will not longer be valid. 446 will not longer be valid.
447 */ 447 */
448 VObject *p; 448 VObject *p;
449 p = o->prop->next; 449 p = o->prop->next;
450 o->prop->next = 0; 450 o->prop->next = 0;
451 do { 451 do {
452 VObject *t = p->next; 452 VObject *t = p->next;
453 cleanVObject(p); 453 cleanVObject(p);
454 p = t; 454 p = t;
455 } while (p); 455 } while (p);
456 } 456 }
457 switch (VALUE_TYPE(o)) { 457 switch (VALUE_TYPE(o)) {
458 case VCVT_STRINGZ: 458 case VCVT_STRINGZ:
459 case VCVT_RAW: 459 case VCVT_RAW:
460 // assume they are all allocated by malloc. 460 // assume they are all allocated by malloc.
461 free((char*)STRINGZ_VALUE_OF(o)); 461 free((char*)STRINGZ_VALUE_OF(o));
462 break; 462 break;
463 case VCVT_VOBJECT: 463 case VCVT_VOBJECT:
464 cleanVObject(VOBJECT_VALUE_OF(o)); 464 cleanVObject(VOBJECT_VALUE_OF(o));
465 break; 465 break;
466 } 466 }
467 deleteVObject(o); 467 deleteVObject(o);
468} 468}
469 469
470DLLEXPORT(void) cleanVObjects(VObject *list) 470DLLEXPORT(void) cleanVObjects(VObject *list)
471{ 471{
472 while (list) { 472 while (list) {
473 VObject *t = list; 473 VObject *t = list;
474 list = nextVObjectInList(list); 474 list = nextVObjectInList(list);
475 cleanVObject(t); 475 cleanVObject(t);
476 } 476 }
477} 477}
478 478
479/*---------------------------------------------------------------------- 479/*----------------------------------------------------------------------
480 The following is a String Table Facilities. 480 The following is a String Table Facilities.
481 ----------------------------------------------------------------------*/ 481 ----------------------------------------------------------------------*/
482 482
483#define STRTBLSIZE 255 483#define STRTBLSIZE 255
484 484
485static StrItem *strTbl[STRTBLSIZE]; 485static StrItem *strTbl[STRTBLSIZE];
486 486
487static unsigned int hashStr(const char *s) 487static unsigned int hashStr(const char *s)
488{ 488{
489 unsigned int h = 0; 489 unsigned int h = 0;
490 int i; 490 int i;
491 for (i=0;s[i];i++) { 491 for (i=0;s[i];i++) {
492 h += s[i]*i; 492 h += s[i]*i;
493 } 493 }
494 return h % STRTBLSIZE; 494 return h % STRTBLSIZE;
495} 495}
496 496
497DLLEXPORT(const char*) lookupStr(const char *s) 497DLLEXPORT(const char*) lookupStr(const char *s)
498{ 498{
499 StrItem *t; 499 StrItem *t;
500 unsigned int h = hashStr(s); 500 unsigned int h = hashStr(s);
501 if ((t = strTbl[h]) != 0) { 501 if ((t = strTbl[h]) != 0) {
502 do { 502 do {
503 if (qstricmp(t->s,s) == 0) { 503 if (qstricmp(t->s,s) == 0) {
504 t->refCnt++; 504 t->refCnt++;
505 return t->s; 505 return t->s;
506 } 506 }
507 t = t->next; 507 t = t->next;
508 } while (t); 508 } while (t);
509 } 509 }
510 s = dupStr(s,0); 510 s = dupStr(s,0);
511 strTbl[h] = newStrItem(s,strTbl[h]); 511 strTbl[h] = newStrItem(s,strTbl[h]);
512 return s; 512 return s;
513} 513}
514 514
515DLLEXPORT(void) unUseStr(const char *s) 515DLLEXPORT(void) unUseStr(const char *s)
516{ 516{
517 StrItem *t, *p; 517 StrItem *t, *p;
518 unsigned int h = hashStr(s); 518 unsigned int h = hashStr(s);
519 if ((t = strTbl[h]) != 0) { 519 if ((t = strTbl[h]) != 0) {
520 p = t; 520 p = t;
521 do { 521 do {
522 if (qstricmp(t->s,s) == 0) { 522 if (qstricmp(t->s,s) == 0) {
523 t->refCnt--; 523 t->refCnt--;
524 if (t->refCnt == 0) { 524 if (t->refCnt == 0) {
525 if (p == strTbl[h]) { 525 if (p == strTbl[h]) {
526 strTbl[h] = t->next; 526 strTbl[h] = t->next;
527 } 527 }
528 else { 528 else {
529 p->next = t->next; 529 p->next = t->next;
530 } 530 }
531 deleteStr(t->s); 531 deleteStr(t->s);
532 deleteStrItem(t); 532 deleteStrItem(t);
533 return; 533 return;
534 } 534 }
535 } 535 }
536 p = t; 536 p = t;
537 t = t->next; 537 t = t->next;
538 } while (t); 538 } while (t);
539 } 539 }
540} 540}
541 541
542DLLEXPORT(void) cleanStrTbl() 542DLLEXPORT(void) cleanStrTbl()
543{ 543{
544 int i; 544 int i;
545 for (i=0; i<STRTBLSIZE;i++) { 545 for (i=0; i<STRTBLSIZE;i++) {
546 StrItem *t = strTbl[i]; 546 StrItem *t = strTbl[i];
547 while (t) { 547 while (t) {
548 StrItem *p; 548 StrItem *p;
549 deleteStr(t->s); 549 deleteStr(t->s);
550 p = t; 550 p = t;
551 t = t->next; 551 t = t->next;
552 deleteStrItem(p); 552 deleteStrItem(p);
553 } while (t); 553 } while (t);
554 strTbl[i] = 0; 554 strTbl[i] = 0;
555 } 555 }
556} 556}
557 557
558 558
559struct PreDefProp { 559struct PreDefProp {
560 const char *name; 560 const char *name;
561 const char *alias; 561 const char *alias;
562 const char** fields; 562 const char** fields;
563 unsigned int flags; 563 unsigned int flags;
564 }; 564 };
565 565
566/* flags in PreDefProp */ 566/* flags in PreDefProp */
567 #define PD_BEGIN0x1 567 #define PD_BEGIN0x1
568 #define PD_INTERNAL0x2 568 #define PD_INTERNAL0x2
569 569
570static const char *adrFields[] = { 570static const char *adrFields[] = {
571 VCPostalBoxProp, 571 VCPostalBoxProp,
572 VCExtAddressProp, 572 VCExtAddressProp,
573 VCStreetAddressProp, 573 VCStreetAddressProp,
574 VCCityProp, 574 VCCityProp,
575 VCRegionProp, 575 VCRegionProp,
576 VCPostalCodeProp, 576 VCPostalCodeProp,
577 VCCountryNameProp, 577 VCCountryNameProp,
578 0 578 0
579}; 579};
580 580
581static const char *nameFields[] = { 581static const char *nameFields[] = {
582 VCFamilyNameProp, 582 VCFamilyNameProp,
583 VCGivenNameProp, 583 VCGivenNameProp,
584 VCAdditionalNamesProp, 584 VCAdditionalNamesProp,
585 VCNamePrefixesProp, 585 VCNamePrefixesProp,
586 VCNameSuffixesProp, 586 VCNameSuffixesProp,
587 NULL 587 NULL
588 }; 588 };
589 589
590static const char *orgFields[] = { 590static const char *orgFields[] = {
591 VCOrgNameProp, 591 VCOrgNameProp,
592 VCOrgUnitProp, 592 VCOrgUnitProp,
593 VCOrgUnit2Prop, 593 VCOrgUnit2Prop,
594 VCOrgUnit3Prop, 594 VCOrgUnit3Prop,
595 VCOrgUnit4Prop, 595 VCOrgUnit4Prop,
596 NULL 596 NULL
597 }; 597 };
598 598
599static const char *AAlarmFields[] = { 599static const char *AAlarmFields[] = {
600 VCRunTimeProp, 600 VCRunTimeProp,
601 VCSnoozeTimeProp, 601 VCSnoozeTimeProp,
602 VCRepeatCountProp, 602 VCRepeatCountProp,
603 VCAudioContentProp, 603 VCAudioContentProp,
604 0 604 0
605 }; 605 };
606 606
607/* ExDate -- has unamed fields */ 607/* ExDate -- has unamed fields */
608/* RDate -- has unamed fields */ 608/* RDate -- has unamed fields */
609 609
610static const char *DAlarmFields[] = { 610static const char *DAlarmFields[] = {
611 VCRunTimeProp, 611 VCRunTimeProp,
612 VCSnoozeTimeProp, 612 VCSnoozeTimeProp,
613 VCRepeatCountProp, 613 VCRepeatCountProp,
614 VCDisplayStringProp, 614 VCDisplayStringProp,
615 0 615 0
616 }; 616 };
617 617
618static const char *MAlarmFields[] = { 618static const char *MAlarmFields[] = {
619 VCRunTimeProp, 619 VCRunTimeProp,
620 VCSnoozeTimeProp, 620 VCSnoozeTimeProp,
621 VCRepeatCountProp, 621 VCRepeatCountProp,
622 VCEmailAddressProp, 622 VCEmailAddressProp,
623 VCNoteProp, 623 VCNoteProp,
624 0 624 0
625 }; 625 };
626 626
627static const char *PAlarmFields[] = { 627static const char *PAlarmFields[] = {
628 VCRunTimeProp, 628 VCRunTimeProp,
629 VCSnoozeTimeProp, 629 VCSnoozeTimeProp,
630 VCRepeatCountProp, 630 VCRepeatCountProp,
631 VCProcedureNameProp, 631 VCProcedureNameProp,
632 0 632 0
633 }; 633 };
634 634
635static struct PreDefProp propNames[] = { 635static struct PreDefProp propNames[] = {
636 { VC7bitProp, 0, 0, 0 }, 636 { VC7bitProp, 0, 0, 0 },
637 { VC8bitProp, 0, 0, 0 }, 637 { VC8bitProp, 0, 0, 0 },
638 { VCAAlarmProp, 0, AAlarmFields, 0 }, 638 { VCAAlarmProp, 0, AAlarmFields, 0 },
639 { VCAdditionalNamesProp, 0, 0, 0 }, 639 { VCAdditionalNamesProp, 0, 0, 0 },
640 { VCAdrProp, 0, adrFields, 0 }, 640 { VCAdrProp, 0, adrFields, 0 },
641 { VCAgentProp, 0, 0, 0 }, 641 { VCAgentProp, 0, 0, 0 },
642 { VCAIFFProp, 0, 0, 0 }, 642 { VCAIFFProp, 0, 0, 0 },
643 { VCAOLProp, 0, 0, 0 }, 643 { VCAOLProp, 0, 0, 0 },
644 { VCAppleLinkProp, 0, 0, 0 }, 644 { VCAppleLinkProp, 0, 0, 0 },
645 { VCAttachProp, 0, 0, 0 }, 645 { VCAttachProp, 0, 0, 0 },
646 { VCAttendeeProp, 0, 0, 0 }, 646 { VCAttendeeProp, 0, 0, 0 },
647 { VCATTMailProp, 0, 0, 0 }, 647 { VCATTMailProp, 0, 0, 0 },
648 { VCAudioContentProp, 0, 0, 0 }, 648 { VCAudioContentProp, 0, 0, 0 },
649 { VCAVIProp, 0, 0, 0 }, 649 { VCAVIProp, 0, 0, 0 },
650 { VCBase64Prop, 0, 0, 0 }, 650 { VCBase64Prop, 0, 0, 0 },
651 { VCBBSProp, 0, 0, 0 }, 651 { VCBBSProp, 0, 0, 0 },
652 { VCBirthDateProp, 0, 0, 0 }, 652 { VCBirthDateProp, 0, 0, 0 },
653 { VCBMPProp, 0, 0, 0 }, 653 { VCBMPProp, 0, 0, 0 },
654 { VCBodyProp, 0, 0, 0 }, 654 { VCBodyProp, 0, 0, 0 },
655 { VCBusinessRoleProp, 0, 0, 0 }, 655 { VCBusinessRoleProp, 0, 0, 0 },
656 { VCCalProp, 0, 0, PD_BEGIN }, 656 { VCCalProp, 0, 0, PD_BEGIN },
657 { VCCaptionProp, 0, 0, 0 }, 657 { VCCaptionProp, 0, 0, 0 },
658 { VCCardProp, 0, 0, PD_BEGIN }, 658 { VCCardProp, 0, 0, PD_BEGIN },
659 { VCCarProp, 0, 0, 0 }, 659 { VCCarProp, 0, 0, 0 },
660 { VCCategoriesProp, 0, 0, 0 }, 660 { VCCategoriesProp, 0, 0, 0 },
661 { VCCellularProp, 0, 0, 0 }, 661 { VCCellularProp, 0, 0, 0 },
662 { VCCGMProp, 0, 0, 0 }, 662 { VCCGMProp, 0, 0, 0 },
663 { VCCharSetProp, 0, 0, 0 }, 663 { VCCharSetProp, 0, 0, 0 },
664 { VCCIDProp, VCContentIDProp, 0, 0 }, 664 { VCCIDProp, VCContentIDProp, 0, 0 },
665 { VCCISProp, 0, 0, 0 }, 665 { VCCISProp, 0, 0, 0 },
666 { VCCityProp, 0, 0, 0 }, 666 { VCCityProp, 0, 0, 0 },
667 { VCClassProp, 0, 0, 0 }, 667 { VCClassProp, 0, 0, 0 },
668 { VCCommentProp, 0, 0, 0 }, 668 { VCCommentProp, 0, 0, 0 },
669 { VCCompletedProp, 0, 0, 0 }, 669 { VCCompletedProp, 0, 0, 0 },
670 { VCContentIDProp, 0, 0, 0 }, 670 { VCContentIDProp, 0, 0, 0 },
671 { VCCountryNameProp, 0, 0, 0 }, 671 { VCCountryNameProp, 0, 0, 0 },
672 { VCDAlarmProp, 0, DAlarmFields, 0 }, 672 { VCDAlarmProp, 0, DAlarmFields, 0 },
673 { VCDataSizeProp, 0, 0, PD_INTERNAL }, 673 { VCDataSizeProp, 0, 0, PD_INTERNAL },
674 { VCDayLightProp, 0, 0, 0 }, 674 { VCDayLightProp, 0, 0, 0 },
675 { VCDCreatedProp, 0, 0, 0 }, 675 { VCDCreatedProp, 0, 0, 0 },
676 { VCDeliveryLabelProp, 0, 0, 0 }, 676 { VCDeliveryLabelProp, 0, 0, 0 },
677 { VCDescriptionProp, 0, 0, 0 }, 677 { VCDescriptionProp, 0, 0, 0 },
678 { VCDIBProp, 0, 0, 0 }, 678 { VCDIBProp, 0, 0, 0 },
679 { VCDisplayStringProp, 0, 0, 0 }, 679 { VCDisplayStringProp, 0, 0, 0 },
680 { VCDomesticProp, 0, 0, 0 }, 680 { VCDomesticProp, 0, 0, 0 },
681 { VCDTendProp, 0, 0, 0 }, 681 { VCDTendProp, 0, 0, 0 },
682 { VCDTstartProp, 0, 0, 0 }, 682 { VCDTstartProp, 0, 0, 0 },
683 { VCDueProp, 0, 0, 0 }, 683 { VCDueProp, 0, 0, 0 },
684 { VCEmailAddressProp, 0, 0, 0 }, 684 { VCEmailAddressProp, 0, 0, 0 },
685 { VCEncodingProp, 0, 0, 0 }, 685 { VCEncodingProp, 0, 0, 0 },
686 { VCEndProp, 0, 0, 0 }, 686 { VCEndProp, 0, 0, 0 },
687 { VCEventProp, 0, 0, PD_BEGIN }, 687 { VCEventProp, 0, 0, PD_BEGIN },
688 { VCEWorldProp, 0, 0, 0 }, 688 { VCEWorldProp, 0, 0, 0 },
689 { VCExNumProp, 0, 0, 0 }, 689 { VCExNumProp, 0, 0, 0 },
690 { VCExpDateProp, 0, 0, 0 }, 690 { VCExpDateProp, 0, 0, 0 },
691 { VCExpectProp, 0, 0, 0 }, 691 { VCExpectProp, 0, 0, 0 },
692 { VCExtAddressProp, 0, 0, 0 }, 692 { VCExtAddressProp, 0, 0, 0 },
693 { VCFamilyNameProp, 0, 0, 0 }, 693 { VCFamilyNameProp, 0, 0, 0 },
694 { VCFaxProp, 0, 0, 0 }, 694 { VCFaxProp, 0, 0, 0 },
695 { VCFullNameProp, 0, 0, 0 }, 695 { VCFullNameProp, 0, 0, 0 },
696 { VCGeoLocationProp, 0, 0, 0 }, 696 { VCGeoLocationProp, 0, 0, 0 },
697 { VCGeoProp, 0, 0, 0 }, 697 { VCGeoProp, 0, 0, 0 },
698 { VCGIFProp, 0, 0, 0 }, 698 { VCGIFProp, 0, 0, 0 },
699 { VCGivenNameProp, 0, 0, 0 }, 699 { VCGivenNameProp, 0, 0, 0 },
700 { VCGroupingProp, 0, 0, 0 }, 700 { VCGroupingProp, 0, 0, 0 },
701 { VCHomeProp, 0, 0, 0 }, 701 { VCHomeProp, 0, 0, 0 },
702 { VCIBMMailProp, 0, 0, 0 }, 702 { VCIBMMailProp, 0, 0, 0 },
703 { VCInlineProp, 0, 0, 0 }, 703 { VCInlineProp, 0, 0, 0 },
704 { VCInternationalProp, 0, 0, 0 }, 704 { VCInternationalProp, 0, 0, 0 },
705 { VCInternetProp, 0, 0, 0 }, 705 { VCInternetProp, 0, 0, 0 },
706 { VCISDNProp, 0, 0, 0 }, 706 { VCISDNProp, 0, 0, 0 },
707 { VCJPEGProp, 0, 0, 0 }, 707 { VCJPEGProp, 0, 0, 0 },
708 { VCLanguageProp, 0, 0, 0 }, 708 { VCLanguageProp, 0, 0, 0 },
709 { VCLastModifiedProp, 0, 0, 0 }, 709 { VCLastModifiedProp, 0, 0, 0 },
710 { VCLastRevisedProp, 0, 0, 0 }, 710 { VCLastRevisedProp, 0, 0, 0 },
711 { VCLocationProp, 0, 0, 0 }, 711 { VCLocationProp, 0, 0, 0 },
712 { VCLogoProp, 0, 0, 0 }, 712 { VCLogoProp, 0, 0, 0 },
713 { VCMailerProp, 0, 0, 0 }, 713 { VCMailerProp, 0, 0, 0 },
714 { VCMAlarmProp, 0, MAlarmFields, 0 }, 714 { VCMAlarmProp, 0, MAlarmFields, 0 },
715 { VCMCIMailProp, 0, 0, 0 }, 715 { VCMCIMailProp, 0, 0, 0 },
716 { VCMessageProp, 0, 0, 0 }, 716 { VCMessageProp, 0, 0, 0 },
717 { VCMETProp, 0, 0, 0 }, 717 { VCMETProp, 0, 0, 0 },
718 { VCModemProp, 0, 0, 0 }, 718 { VCModemProp, 0, 0, 0 },
719 { VCMPEG2Prop, 0, 0, 0 }, 719 { VCMPEG2Prop, 0, 0, 0 },
720 { VCMPEGProp, 0, 0, 0 }, 720 { VCMPEGProp, 0, 0, 0 },
721 { VCMSNProp, 0, 0, 0 }, 721 { VCMSNProp, 0, 0, 0 },
722 { VCNamePrefixesProp, 0, 0, 0 }, 722 { VCNamePrefixesProp, 0, 0, 0 },
723 { VCNameProp, 0, nameFields, 0 }, 723 { VCNameProp, 0, nameFields, 0 },
724 { VCNameSuffixesProp, 0, 0, 0 }, 724 { VCNameSuffixesProp, 0, 0, 0 },
725 { VCNoteProp, 0, 0, 0 }, 725 { VCNoteProp, 0, 0, 0 },
726 { VCOrgNameProp, 0, 0, 0 }, 726 { VCOrgNameProp, 0, 0, 0 },
727 { VCOrgProp, 0, orgFields, 0 }, 727 { VCOrgProp, 0, orgFields, 0 },
728 { VCOrgUnit2Prop, 0, 0, 0 }, 728 { VCOrgUnit2Prop, 0, 0, 0 },
729 { VCOrgUnit3Prop, 0, 0, 0 }, 729 { VCOrgUnit3Prop, 0, 0, 0 },
730 { VCOrgUnit4Prop, 0, 0, 0 }, 730 { VCOrgUnit4Prop, 0, 0, 0 },
731 { VCOrgUnitProp, 0, 0, 0 }, 731 { VCOrgUnitProp, 0, 0, 0 },
732 { VCPagerProp, 0, 0, 0 }, 732 { VCPagerProp, 0, 0, 0 },
733 { VCPAlarmProp, 0, PAlarmFields, 0 }, 733 { VCPAlarmProp, 0, PAlarmFields, 0 },
734 { VCParcelProp, 0, 0, 0 }, 734 { VCParcelProp, 0, 0, 0 },
735 { VCPartProp, 0, 0, 0 }, 735 { VCPartProp, 0, 0, 0 },
736 { VCPCMProp, 0, 0, 0 }, 736 { VCPCMProp, 0, 0, 0 },
737 { VCPDFProp, 0, 0, 0 }, 737 { VCPDFProp, 0, 0, 0 },
738 { VCPGPProp, 0, 0, 0 }, 738 { VCPGPProp, 0, 0, 0 },
739 { VCPhotoProp, 0, 0, 0 }, 739 { VCPhotoProp, 0, 0, 0 },
740 { VCPICTProp, 0, 0, 0 }, 740 { VCPICTProp, 0, 0, 0 },
741 { VCPMBProp, 0, 0, 0 }, 741 { VCPMBProp, 0, 0, 0 },
742 { VCPostalBoxProp, 0, 0, 0 }, 742 { VCPostalBoxProp, 0, 0, 0 },
743 { VCPostalCodeProp, 0, 0, 0 }, 743 { VCPostalCodeProp, 0, 0, 0 },
744 { VCPostalProp, 0, 0, 0 }, 744 { VCPostalProp, 0, 0, 0 },
745 { VCPowerShareProp, 0, 0, 0 }, 745 { VCPowerShareProp, 0, 0, 0 },
746 { VCPreferredProp, 0, 0, 0 }, 746 { VCPreferredProp, 0, 0, 0 },
747 { VCPriorityProp, 0, 0, 0 }, 747 { VCPriorityProp, 0, 0, 0 },
748 { VCProcedureNameProp, 0, 0, 0 }, 748 { VCProcedureNameProp, 0, 0, 0 },
749 { VCProdIdProp, 0, 0, 0 }, 749 { VCProdIdProp, 0, 0, 0 },
750 { VCProdigyProp, 0, 0, 0 }, 750 { VCProdigyProp, 0, 0, 0 },
751 { VCPronunciationProp, 0, 0, 0 }, 751 { VCPronunciationProp, 0, 0, 0 },
752 { VCPSProp, 0, 0, 0 }, 752 { VCPSProp, 0, 0, 0 },
753 { VCPublicKeyProp, 0, 0, 0 }, 753 { VCPublicKeyProp, 0, 0, 0 },
754 { VCQPProp, VCQuotedPrintableProp, 0, 0 }, 754 { VCQPProp, VCQuotedPrintableProp, 0, 0 },
755 { VCQuickTimeProp, 0, 0, 0 }, 755 { VCQuickTimeProp, 0, 0, 0 },
756 { VCQuotedPrintableProp, 0, 0, 0 }, 756 { VCQuotedPrintableProp, 0, 0, 0 },
757 { VCRDateProp, 0, 0, 0 }, 757 { VCRDateProp, 0, 0, 0 },
758 { VCRegionProp, 0, 0, 0 }, 758 { VCRegionProp, 0, 0, 0 },
759 { VCRelatedToProp, 0, 0, 0 }, 759 { VCRelatedToProp, 0, 0, 0 },
760 { VCRepeatCountProp, 0, 0, 0 }, 760 { VCRepeatCountProp, 0, 0, 0 },
761 { VCResourcesProp, 0, 0, 0 }, 761 { VCResourcesProp, 0, 0, 0 },
762 { VCRNumProp, 0, 0, 0 }, 762 { VCRNumProp, 0, 0, 0 },
763 { VCRoleProp, 0, 0, 0 }, 763 { VCRoleProp, 0, 0, 0 },
764 { VCRRuleProp, 0, 0, 0 }, 764 { VCRRuleProp, 0, 0, 0 },
765 { VCRSVPProp, 0, 0, 0 }, 765 { VCRSVPProp, 0, 0, 0 },
766 { VCRunTimeProp, 0, 0, 0 }, 766 { VCRunTimeProp, 0, 0, 0 },
767 { VCSequenceProp, 0, 0, 0 }, 767 { VCSequenceProp, 0, 0, 0 },
768 { VCSnoozeTimeProp, 0, 0, 0 }, 768 { VCSnoozeTimeProp, 0, 0, 0 },
769 { VCStartProp, 0, 0, 0 }, 769 { VCStartProp, 0, 0, 0 },
770 { VCStatusProp, 0, 0, 0 }, 770 { VCStatusProp, 0, 0, 0 },
771 { VCStreetAddressProp, 0, 0, 0 }, 771 { VCStreetAddressProp, 0, 0, 0 },
772 { VCSubTypeProp, 0, 0, 0 }, 772 { VCSubTypeProp, 0, 0, 0 },
773 { VCSummaryProp, 0, 0, 0 }, 773 { VCSummaryProp, 0, 0, 0 },
774 { VCTelephoneProp, 0, 0, 0 }, 774 { VCTelephoneProp, 0, 0, 0 },
775 { VCTIFFProp, 0, 0, 0 }, 775 { VCTIFFProp, 0, 0, 0 },
776 { VCTimeZoneProp, 0, 0, 0 }, 776 { VCTimeZoneProp, 0, 0, 0 },
777 { VCTitleProp, 0, 0, 0 }, 777 { VCTitleProp, 0, 0, 0 },
778 { VCTLXProp, 0, 0, 0 }, 778 { VCTLXProp, 0, 0, 0 },
779 { VCTodoProp, 0, 0, PD_BEGIN }, 779 { VCTodoProp, 0, 0, PD_BEGIN },
780 { VCTranspProp, 0, 0, 0 }, 780 { VCTranspProp, 0, 0, 0 },
781 { VCUniqueStringProp, 0, 0, 0 }, 781 { VCUniqueStringProp, 0, 0, 0 },
782 { VCURLProp, 0, 0, 0 }, 782 { VCURLProp, 0, 0, 0 },
783 { VCURLValueProp, 0, 0, 0 }, 783 { VCURLValueProp, 0, 0, 0 },
784 { VCValueProp, 0, 0, 0 }, 784 { VCValueProp, 0, 0, 0 },
785 { VCVersionProp, 0, 0, 0 }, 785 { VCVersionProp, 0, 0, 0 },
786 { VCVideoProp, 0, 0, 0 }, 786 { VCVideoProp, 0, 0, 0 },
787 { VCVoiceProp, 0, 0, 0 }, 787 { VCVoiceProp, 0, 0, 0 },
788 { VCWAVEProp, 0, 0, 0 }, 788 { VCWAVEProp, 0, 0, 0 },
789 { VCWMFProp, 0, 0, 0 }, 789 { VCWMFProp, 0, 0, 0 },
790 { VCWorkProp, 0, 0, 0 }, 790 { VCWorkProp, 0, 0, 0 },
791 { VCX400Prop, 0, 0, 0 }, 791 { VCX400Prop, 0, 0, 0 },
792 { VCX509Prop, 0, 0, 0 }, 792 { VCX509Prop, 0, 0, 0 },
793 { VCXRuleProp, 0, 0, 0 }, 793 { VCXRuleProp, 0, 0, 0 },
794 { 0,0,0,0 } 794 { 0,0,0,0 }
795 }; 795 };
796 796
797 797
798static struct PreDefProp* lookupPropInfo(const char* str) 798static struct PreDefProp* lookupPropInfo(const char* str)
799{ 799{
800 /* brute force for now, could use a hash table here. */ 800 /* brute force for now, could use a hash table here. */
801 int i; 801 int i;
802 802
803 for (i = 0; propNames[i].name; i++) 803 for (i = 0; propNames[i].name; i++)
804 if (qstricmp(str, propNames[i].name) == 0) { 804 if (qstricmp(str, propNames[i].name) == 0) {
805 return &propNames[i]; 805 return &propNames[i];
806 } 806 }
807 807
808 return 0; 808 return 0;
809} 809}
810 810
811 811
812DLLEXPORT(const char*) lookupProp_(const char* str) 812DLLEXPORT(const char*) lookupProp_(const char* str)
813{ 813{
814 int i; 814 int i;
815 815
816 for (i = 0; propNames[i].name; i++) 816 for (i = 0; propNames[i].name; i++)
817 if (qstricmp(str, propNames[i].name) == 0) { 817 if (qstricmp(str, propNames[i].name) == 0) {
818 const char* s; 818 const char* s;
819 s = propNames[i].alias?propNames[i].alias:propNames[i].name; 819 s = propNames[i].alias?propNames[i].alias:propNames[i].name;
820 return lookupStr(s); 820 return lookupStr(s);
821 } 821 }
822 return lookupStr(str); 822 return lookupStr(str);
823} 823}
824 824
825 825
826DLLEXPORT(const char*) lookupProp(const char* str) 826DLLEXPORT(const char*) lookupProp(const char* str)
827{ 827{
828 int i; 828 int i;
829 829
830 for (i = 0; propNames[i].name; i++) 830 for (i = 0; propNames[i].name; i++)
831 if (qstricmp(str, propNames[i].name) == 0) { 831 if (qstricmp(str, propNames[i].name) == 0) {
832 const char *s; 832 const char *s;
833 fieldedProp = propNames[i].fields; 833 fieldedProp = propNames[i].fields;
834 s = propNames[i].alias?propNames[i].alias:propNames[i].name; 834 s = propNames[i].alias?propNames[i].alias:propNames[i].name;
835 return lookupStr(s); 835 return lookupStr(s);
836 } 836 }
837 fieldedProp = 0; 837 fieldedProp = 0;
838 return lookupStr(str); 838 return lookupStr(str);
839} 839}
840 840
841 841
842/*---------------------------------------------------------------------- 842/*----------------------------------------------------------------------
843 APIs to Output text form. 843 APIs to Output text form.
844 ----------------------------------------------------------------------*/ 844 ----------------------------------------------------------------------*/
845#define OFILE_REALLOC_SIZE 256 845#define OFILE_REALLOC_SIZE 256
846typedef struct OFile { 846typedef struct OFile {
847 FILE *fp; 847 FILE *fp;
848 char *s; 848 char *s;
849 int len; 849 int len;
850 int limit; 850 int limit;
851 int alloc:1; 851 int alloc:1;
852 int fail:1; 852 int fail:1;
853 } OFile; 853 } OFile;
854 854
855#if 0 855#if 0
856static void appendsOFile(OFile *fp, const char *s) 856static void appendsOFile(OFile *fp, const char *s)
857{ 857{
858 int slen; 858 int slen;
859 if (fp->fail) return; 859 if (fp->fail) return;
860 slen = strlen(s); 860 slen = strlen(s);
861 if (fp->fp) { 861 if (fp->fp) {
862 fwrite(s,1,slen,fp->fp); 862 fwrite(s,1,slen,fp->fp);
863 } 863 }
864 else { 864 else {
865stuff: 865stuff:
866 if (fp->len + slen < fp->limit) { 866 if (fp->len + slen < fp->limit) {
867 memcpy(fp->s+fp->len,s,slen); 867 memcpy(fp->s+fp->len,s,slen);
868 fp->len += slen; 868 fp->len += slen;
869 return; 869 return;
870 } 870 }
871 else if (fp->alloc) { 871 else if (fp->alloc) {
872 fp->limit = fp->limit + OFILE_REALLOC_SIZE; 872 fp->limit = fp->limit + OFILE_REALLOC_SIZE;
873 if (OFILE_REALLOC_SIZE <= slen) fp->limit += slen; 873 if (OFILE_REALLOC_SIZE <= slen) fp->limit += slen;
874 fp->s = (char *) realloc(fp->s,fp->limit); 874 fp->s = (char *) realloc(fp->s,fp->limit);
875 if (fp->s) goto stuff; 875 if (fp->s) goto stuff;
876 } 876 }
877 if (fp->alloc) 877 if (fp->alloc)
878 free(fp->s); 878 free(fp->s);
879 fp->s = 0; 879 fp->s = 0;
880 fp->fail = 1; 880 fp->fail = 1;
881 } 881 }
882} 882}
883 883
884static void appendcOFile(OFile *fp, char c) 884static void appendcOFile(OFile *fp, char c)
885{ 885{
886 if (fp->fail) return; 886 if (fp->fail) return;
887 if (fp->fp) { 887 if (fp->fp) {
888 fputc(c,fp->fp); 888 fputc(c,fp->fp);
889 } 889 }
890 else { 890 else {
891stuff: 891stuff:
892 if (fp->len+1 < fp->limit) { 892 if (fp->len+1 < fp->limit) {
893 fp->s[fp->len] = c; 893 fp->s[fp->len] = c;
894 fp->len++; 894 fp->len++;
895 return; 895 return;
896 } 896 }
897 else if (fp->alloc) { 897 else if (fp->alloc) {
898 fp->limit = fp->limit + OFILE_REALLOC_SIZE; 898 fp->limit = fp->limit + OFILE_REALLOC_SIZE;
899 fp->s = (char *) realloc(fp->s,fp->limit); 899 fp->s = (char *) realloc(fp->s,fp->limit);
900 if (fp->s) goto stuff; 900 if (fp->s) goto stuff;
901 } 901 }
902 if (fp->alloc) 902 if (fp->alloc)
903 free(fp->s); 903 free(fp->s);
904 fp->s = 0; 904 fp->s = 0;
905 fp->fail = 1; 905 fp->fail = 1;
906 } 906 }
907} 907}
908#else 908#else
909static void appendcOFile_(OFile *fp, char c) 909static void appendcOFile_(OFile *fp, char c)
910{ 910{
911 if (fp->fail) return; 911 if (fp->fail) return;
912 if (fp->fp) { 912 if (fp->fp) {
913 fputc(c,fp->fp); 913 fputc(c,fp->fp);
914 } 914 }
915 else { 915 else {
916stuff: 916stuff:
917 if (fp->len+1 < fp->limit) { 917 if (fp->len+1 < fp->limit) {
918 fp->s[fp->len] = c; 918 fp->s[fp->len] = c;
919 fp->len++; 919 fp->len++;
920 return; 920 return;
921 } 921 }
922 else if (fp->alloc) { 922 else if (fp->alloc) {
923 fp->limit = fp->limit + OFILE_REALLOC_SIZE; 923 fp->limit = fp->limit + OFILE_REALLOC_SIZE;
924 fp->s = (char *)realloc(fp->s,fp->limit); 924 fp->s = (char *)realloc(fp->s,fp->limit);
925 if (fp->s) goto stuff; 925 if (fp->s) goto stuff;
926 } 926 }
927 if (fp->alloc) 927 if (fp->alloc)
928 free(fp->s); 928 free(fp->s);
929 fp->s = 0; 929 fp->s = 0;
930 fp->fail = 1; 930 fp->fail = 1;
931 } 931 }
932} 932}
933 933
934static void appendcOFile(OFile *fp, char c) 934static void appendcOFile(OFile *fp, char c)
935{ 935{
936 if (c == '\n') { 936 if (c == '\n') {
937 /* write out as <CR><LF> */ 937 /* write out as <CR><LF> */
938 appendcOFile_(fp,0xd); 938 appendcOFile_(fp,0xd);
939 appendcOFile_(fp,0xa); 939 appendcOFile_(fp,0xa);
940 } 940 }
941 else 941 else
942 appendcOFile_(fp,c); 942 appendcOFile_(fp,c);
943} 943}
944 944
945static void appendsOFile(OFile *fp, const char *s) 945static void appendsOFile(OFile *fp, const char *s)
946{ 946{
947 int i, slen; 947 int i, slen;
948 slen = strlen(s); 948 slen = strlen(s);
949 for (i=0; i<slen; i++) { 949 for (i=0; i<slen; i++) {
950 appendcOFile(fp,s[i]); 950 appendcOFile(fp,s[i]);
951 } 951 }
952} 952}
953 953
954#endif 954#endif
955 955
956static void initOFile(OFile *fp, FILE *ofp) 956static void initOFile(OFile *fp, FILE *ofp)
957{ 957{
958 fp->fp = ofp; 958 fp->fp = ofp;
959 fp->s = 0; 959 fp->s = 0;
960 fp->len = 0; 960 fp->len = 0;
961 fp->limit = 0; 961 fp->limit = 0;
962 fp->alloc = 0; 962 fp->alloc = 0;
963 fp->fail = 0; 963 fp->fail = 0;
964} 964}
965 965
966static int writeBase64(OFile *fp, unsigned char *s, long len) 966static int writeBase64(OFile *fp, unsigned char *s, long len)
967{ 967{
968 long cur = 0; 968 long cur = 0;
969 int i, numQuads = 0; 969 int i, numQuads = 0;
970 unsigned long trip; 970 unsigned long trip;
971 unsigned char b; 971 unsigned char b;
972 char quad[5]; 972 char quad[5];
973#define MAXQUADS 16 973#define MAXQUADS 16
974 974
975 quad[4] = 0; 975 quad[4] = 0;
976 976
977 while (cur < len) { 977 while (cur < len) {
978 // collect the triplet of bytes into 'trip' 978 // collect the triplet of bytes into 'trip'
979 trip = 0; 979 trip = 0;
980 for (i = 0; i < 3; i++) { 980 for (i = 0; i < 3; i++) {
981 b = (cur < len) ? *(s + cur) : 0; 981 b = (cur < len) ? *(s + cur) : 0;
982 cur++; 982 cur++;
983 trip = trip << 8 | b; 983 trip = trip << 8 | b;
984 } 984 }
985 // fill in 'quad' with the appropriate four characters 985 // fill in 'quad' with the appropriate four characters
986 for (i = 3; i >= 0; i--) { 986 for (i = 3; i >= 0; i--) {
987 b = (unsigned char)(trip & 0x3F); 987 b = (unsigned char)(trip & 0x3F);
988 trip = trip >> 6; 988 trip = trip >> 6;
989 if ((3 - i) < (cur - len)) 989 if ((3 - i) < (cur - len))
990 quad[i] = '='; // pad char 990 quad[i] = '='; // pad char
991 else if (b < 26) quad[i] = (char)b + 'A'; 991 else if (b < 26) quad[i] = (char)b + 'A';
992 else if (b < 52) quad[i] = (char)(b - 26) + 'a'; 992 else if (b < 52) quad[i] = (char)(b - 26) + 'a';
993 else if (b < 62) quad[i] = (char)(b - 52) + '0'; 993 else if (b < 62) quad[i] = (char)(b - 52) + '0';
994 else if (b == 62) quad[i] = '+'; 994 else if (b == 62) quad[i] = '+';
995 else quad[i] = '/'; 995 else quad[i] = '/';
996 } 996 }
997 // now output 'quad' with appropriate whitespace and line ending 997 // now output 'quad' with appropriate whitespace and line ending
998 appendsOFile(fp, (numQuads == 0 ? " " : "")); 998 appendsOFile(fp, (numQuads == 0 ? " " : ""));
999 appendsOFile(fp, quad); 999 appendsOFile(fp, quad);
1000 appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : ""))); 1000 appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : "")));
1001 numQuads = (numQuads + 1) % MAXQUADS; 1001 numQuads = (numQuads + 1) % MAXQUADS;
1002 } 1002 }
1003 appendcOFile(fp,'\n'); 1003 appendcOFile(fp,'\n');
1004 1004
1005 return 1; 1005 return 1;
1006} 1006}
1007 1007
1008static const char *replaceChar(unsigned char c) 1008static const char *replaceChar(unsigned char c)
1009{ 1009{
1010 if (c == '\n') { 1010 if (c == '\n') {
1011 return "=0A=\n"; 1011 return "=0A=\n";
1012 } else if ( 1012 } else if (
1013 (c >= 'A' && c <= 'Z') 1013 (c >= 'A' && c <= 'Z')
1014 || 1014 ||
1015 (c >= 'a' && c <= 'z') 1015 (c >= 'a' && c <= 'z')
1016 || 1016 ||
1017 (c >= '0' && c <= '9') 1017 (c >= '0' && c <= '9')
1018 || 1018 ||
1019 (c >= '\'' && c <= ')') 1019 (c >= '\'' && c <= ')')
1020 || 1020 ||
1021 (c >= '+' && c <= '-') 1021 (c >= '+' && c <= '-')
1022 || 1022 ||
1023 (c == '/') 1023 (c == '/')
1024 || 1024 ||
1025 (c == '?') 1025 (c == '?')
1026 || 1026 ||
1027 (c == ' ')) 1027 (c == ' '))
1028 { 1028 {
1029 return 0; 1029 return 0;
1030 } 1030 }
1031 1031
1032 static char trans[4]; 1032 static char trans[4];
1033 trans[0] = '='; 1033 trans[0] = '=';
1034 trans[3] = '\0'; 1034 trans[3] = '\0';
1035 int rem = c % 16; 1035 int rem = c % 16;
1036 int div = c / 16; 1036 int div = c / 16;
1037 1037
1038 if (div < 10) 1038 if (div < 10)
1039 trans[1] = '0' + div; 1039 trans[1] = '0' + div;
1040 else 1040 else
1041 trans[1] = 'A' + (div - 10); 1041 trans[1] = 'A' + (div - 10);
1042 1042
1043 if (rem < 10) 1043 if (rem < 10)
1044 trans[2] = '0' + rem; 1044 trans[2] = '0' + rem;
1045 else 1045 else
1046 trans[2] = 'A' + (rem - 10); 1046 trans[2] = 'A' + (rem - 10);
1047 1047
1048 return trans; 1048 return trans;
1049} 1049}
1050 1050
1051static void writeQPString(OFile *fp, const char *s) 1051static void writeQPString(OFile *fp, const char *s)
1052{ 1052{
1053 /* 1053 /*
1054 only A-Z, 0-9 and 1054 only A-Z, 0-9 and
1055 "'" (ASCII code 39) 1055 "'" (ASCII code 39)
1056 "(" (ASCII code 40) 1056 "(" (ASCII code 40)
1057 ")" (ASCII code 41) 1057 ")" (ASCII code 41)
1058 "+" (ASCII code 43) 1058 "+" (ASCII code 43)
1059 "," (ASCII code 44) 1059 "," (ASCII code 44)
1060 "-" (ASCII code 45) 1060 "-" (ASCII code 45)
1061 "/" (ASCII code 47) 1061 "/" (ASCII code 47)
1062 "?" (ASCII code 63) 1062 "?" (ASCII code 63)
1063 1063
1064 should remain un-encoded. 1064 should remain un-encoded.
1065 '=' needs to be encoded as it is the escape character. 1065 '=' needs to be encoded as it is the escape character.
1066 ';' needs to be as it is a field separator. 1066 ';' needs to be as it is a field separator.
1067 1067
1068 */ 1068 */
1069 const char *p = s; 1069 const char *p = s;
1070 while (*p) { 1070 while (*p) {
1071 const char *rep = replaceChar(*p); 1071 const char *rep = replaceChar(*p);
1072 if (rep) 1072 if (rep)
1073 appendsOFile(fp, rep); 1073 appendsOFile(fp, rep);
1074 else 1074 else
1075 appendcOFile(fp, *p); 1075 appendcOFile(fp, *p);
1076 p++; 1076 p++;
1077 } 1077 }
1078} 1078}
1079 1079
1080static bool includesUnprintable(VObject *o) 1080static bool includesUnprintable(VObject *o)
1081{ 1081{
1082 if (o) { 1082 if (o) {
1083 if (VALUE_TYPE(o) == VCVT_STRINGZ) { 1083 if (VALUE_TYPE(o) == VCVT_STRINGZ) {
1084 const char *p = STRINGZ_VALUE_OF(o); 1084 const char *p = STRINGZ_VALUE_OF(o);
1085 if (p) { 1085 if (p) {
1086 while (*p) { 1086 while (*p) {
1087 if (replaceChar(*p)) 1087 if (replaceChar(*p))
1088 return TRUE; 1088 return TRUE;
1089 p++; 1089 p++;
1090 } 1090 }
1091 } 1091 }
1092 } 1092 }
1093 } 1093 }
1094 return FALSE; 1094 return FALSE;
1095} 1095}
1096 1096
1097static void writeVObject_(OFile *fp, VObject *o); 1097static void writeVObject_(OFile *fp, VObject *o);
1098 1098
1099static void writeValue(OFile *fp, VObject *o, unsigned long size) 1099static void writeValue(OFile *fp, VObject *o, unsigned long size)
1100{ 1100{
1101 if (o == 0) return; 1101 if (o == 0) return;
1102 switch (VALUE_TYPE(o)) { 1102 switch (VALUE_TYPE(o)) {
1103 case VCVT_STRINGZ: { 1103 case VCVT_STRINGZ: {
1104 writeQPString(fp, STRINGZ_VALUE_OF(o)); 1104 writeQPString(fp, STRINGZ_VALUE_OF(o));
1105 break; 1105 break;
1106 } 1106 }
1107 case VCVT_UINT: { 1107 case VCVT_UINT: {
1108 char buf[16]; 1108 char buf[16];
1109 sprintf(buf,"%u", INTEGER_VALUE_OF(o)); 1109 sprintf(buf,"%u", INTEGER_VALUE_OF(o));
1110 appendsOFile(fp,buf); 1110 appendsOFile(fp,buf);
1111 break; 1111 break;
1112 } 1112 }
1113 case VCVT_ULONG: { 1113 case VCVT_ULONG: {
1114 char buf[16]; 1114 char buf[16];
1115 sprintf(buf,"%lu", LONG_VALUE_OF(o)); 1115 sprintf(buf,"%lu", LONG_VALUE_OF(o));
1116 appendsOFile(fp,buf); 1116 appendsOFile(fp,buf);
1117 break; 1117 break;
1118 } 1118 }
1119 case VCVT_RAW: { 1119 case VCVT_RAW: {
1120 appendcOFile(fp,'\n'); 1120 appendcOFile(fp,'\n');
1121 writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size); 1121 writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size);
1122 break; 1122 break;
1123 } 1123 }
1124 case VCVT_VOBJECT: 1124 case VCVT_VOBJECT:
1125 appendcOFile(fp,'\n'); 1125 appendcOFile(fp,'\n');
1126 writeVObject_(fp,VOBJECT_VALUE_OF(o)); 1126 writeVObject_(fp,VOBJECT_VALUE_OF(o));
1127 break; 1127 break;
1128 } 1128 }
1129} 1129}
1130 1130
1131static void writeAttrValue(OFile *fp, VObject *o) 1131static void writeAttrValue(OFile *fp, VObject *o)
1132{ 1132{
1133 if (NAME_OF(o)) { 1133 if (NAME_OF(o)) {
1134 struct PreDefProp *pi; 1134 struct PreDefProp *pi;
1135 pi = lookupPropInfo(NAME_OF(o)); 1135 pi = lookupPropInfo(NAME_OF(o));
1136 if (pi && ((pi->flags & PD_INTERNAL) != 0)) return; 1136 if (pi && ((pi->flags & PD_INTERNAL) != 0)) return;
1137 if ( includesUnprintable(o) ) { 1137 if ( includesUnprintable(o) ) {
1138 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); 1138 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
1139 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); 1139 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
1140 } 1140 }
1141 appendcOFile(fp,';'); 1141 appendcOFile(fp,';');
1142 appendsOFile(fp,NAME_OF(o)); 1142 appendsOFile(fp,NAME_OF(o));
1143 } 1143 }
1144 else 1144 else
1145 appendcOFile(fp,';'); 1145 appendcOFile(fp,';');
1146 if (VALUE_TYPE(o)) { 1146 if (VALUE_TYPE(o)) {
1147 appendcOFile(fp,'='); 1147 appendcOFile(fp,'=');
1148 writeValue(fp,o,0); 1148 writeValue(fp,o,0);
1149 } 1149 }
1150} 1150}
1151 1151
1152static void writeGroup(OFile *fp, VObject *o) 1152static void writeGroup(OFile *fp, VObject *o)
1153{ 1153{
1154 char buf1[256]; 1154 char buf1[256];
1155 char buf2[256]; 1155 char buf2[256];
1156 strcpy(buf1,NAME_OF(o)); 1156 strcpy(buf1,NAME_OF(o));
1157 while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { 1157 while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) {
1158 strcpy(buf2,STRINGZ_VALUE_OF(o)); 1158 strcpy(buf2,STRINGZ_VALUE_OF(o));
1159 strcat(buf2,"."); 1159 strcat(buf2,".");
1160 strcat(buf2,buf1); 1160 strcat(buf2,buf1);
1161 strcpy(buf1,buf2); 1161 strcpy(buf1,buf2);
1162 } 1162 }
1163 appendsOFile(fp,buf1); 1163 appendsOFile(fp,buf1);
1164} 1164}
1165 1165
1166static int inList(const char **list, const char *s) 1166static int inList(const char **list, const char *s)
1167{ 1167{
1168 if (list == 0) return 0; 1168 if (list == 0) return 0;
1169 while (*list) { 1169 while (*list) {
1170 if (qstricmp(*list,s) == 0) return 1; 1170 if (qstricmp(*list,s) == 0) return 1;
1171 list++; 1171 list++;
1172 } 1172 }
1173 return 0; 1173 return 0;
1174} 1174}
1175 1175
1176static void writeProp(OFile *fp, VObject *o) 1176static void writeProp(OFile *fp, VObject *o)
1177{ 1177{
1178 if (NAME_OF(o)) { 1178 if (NAME_OF(o)) {
1179 struct PreDefProp *pi; 1179 struct PreDefProp *pi;
1180 VObjectIterator t; 1180 VObjectIterator t;
1181 const char **fields_ = 0; 1181 const char **fields_ = 0;
1182 pi = lookupPropInfo(NAME_OF(o)); 1182 pi = lookupPropInfo(NAME_OF(o));
1183 if (pi && ((pi->flags & PD_BEGIN) != 0)) { 1183 if (pi && ((pi->flags & PD_BEGIN) != 0)) {
1184 writeVObject_(fp,o); 1184 writeVObject_(fp,o);
1185 return; 1185 return;
1186 } 1186 }
1187 if (isAPropertyOf(o,VCGroupingProp)) 1187 if (isAPropertyOf(o,VCGroupingProp))
1188 writeGroup(fp,o); 1188 writeGroup(fp,o);
1189 else 1189 else
1190 appendsOFile(fp,NAME_OF(o)); 1190 appendsOFile(fp,NAME_OF(o));
1191 if (pi) fields_ = pi->fields; 1191 if (pi) fields_ = pi->fields;
1192 initPropIterator(&t,o); 1192 initPropIterator(&t,o);
1193 while (moreIteration(&t)) { 1193 while (moreIteration(&t)) {
1194 const char *s; 1194 const char *s;
1195 VObject *eachProp = nextVObject(&t); 1195 VObject *eachProp = nextVObject(&t);
1196 s = NAME_OF(eachProp); 1196 s = NAME_OF(eachProp);
1197 if (qstricmp(VCGroupingProp,s) && !inList(fields_,s)) 1197 if (qstricmp(VCGroupingProp,s) && !inList(fields_,s))
1198 writeAttrValue(fp,eachProp); 1198 writeAttrValue(fp,eachProp);
1199 } 1199 }
1200 if (fields_) { 1200 if (fields_) {
1201 int i = 0, n = 0; 1201 int i = 0, n = 0;
1202 const char** fields = fields_; 1202 const char** fields = fields_;
1203 /* output prop as fields */ 1203 /* output prop as fields */
1204 bool printable = TRUE; 1204 bool printable = TRUE;
1205 while (*fields && printable) { 1205 while (*fields && printable) {
1206 VObject *t = isAPropertyOf(o,*fields); 1206 VObject *t = isAPropertyOf(o,*fields);
1207 if (includesUnprintable(t)) 1207 if (includesUnprintable(t))
1208 printable = FALSE; 1208 printable = FALSE;
1209 fields++; 1209 fields++;
1210 } 1210 }
1211 fields = fields_; 1211 fields = fields_;
1212 if (!printable) { 1212 if (!printable) {
1213 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); 1213 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
1214 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); 1214 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
1215 } 1215 }
1216 appendcOFile(fp,':'); 1216 appendcOFile(fp,':');
1217 while (*fields) { 1217 while (*fields) {
1218 VObject *t = isAPropertyOf(o,*fields); 1218 VObject *t = isAPropertyOf(o,*fields);
1219 i++; 1219 i++;
1220 if (t) n = i; 1220 if (t) n = i;
1221 fields++; 1221 fields++;
1222 } 1222 }
1223 fields = fields_; 1223 fields = fields_;
1224 for (i=0;i<n;i++) { 1224 for (i=0;i<n;i++) {
1225 writeValue(fp,isAPropertyOf(o,*fields),0); 1225 writeValue(fp,isAPropertyOf(o,*fields),0);
1226 fields++; 1226 fields++;
1227 if (i<(n-1)) appendcOFile(fp,';'); 1227 if (i<(n-1)) appendcOFile(fp,';');
1228 } 1228 }
1229 } 1229 }
1230 } 1230 }
1231 1231
1232 1232
1233 if (VALUE_TYPE(o)) { 1233 if (VALUE_TYPE(o)) {
1234 if ( includesUnprintable(o) ) { 1234 if ( includesUnprintable(o) ) {
1235 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); 1235 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
1236 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); 1236 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
1237 } 1237 }
1238 unsigned long size = 0; 1238 unsigned long size = 0;
1239 VObject *p = isAPropertyOf(o,VCDataSizeProp); 1239 VObject *p = isAPropertyOf(o,VCDataSizeProp);
1240 if (p) size = LONG_VALUE_OF(p); 1240 if (p) size = LONG_VALUE_OF(p);
1241 appendcOFile(fp,':'); 1241 appendcOFile(fp,':');
1242 writeValue(fp,o,size); 1242 writeValue(fp,o,size);
1243 } 1243 }
1244 1244
1245 appendcOFile(fp,'\n'); 1245 appendcOFile(fp,'\n');
1246} 1246}
1247 1247
1248static void writeVObject_(OFile *fp, VObject *o) 1248static void writeVObject_(OFile *fp, VObject *o)
1249{ 1249{
1250 if (NAME_OF(o)) { 1250 if (NAME_OF(o)) {
1251 struct PreDefProp *pi; 1251 struct PreDefProp *pi;
1252 pi = lookupPropInfo(NAME_OF(o)); 1252 pi = lookupPropInfo(NAME_OF(o));
1253 1253
1254 if (pi && ((pi->flags & PD_BEGIN) != 0)) { 1254 if (pi && ((pi->flags & PD_BEGIN) != 0)) {
1255 VObjectIterator t; 1255 VObjectIterator t;
1256 const char *begin = NAME_OF(o); 1256 const char *begin = NAME_OF(o);
1257 appendsOFile(fp,"BEGIN:"); 1257 appendsOFile(fp,"BEGIN:");
1258 appendsOFile(fp,begin); 1258 appendsOFile(fp,begin);
1259 appendcOFile(fp,'\n'); 1259 appendcOFile(fp,'\n');
1260 initPropIterator(&t,o); 1260 initPropIterator(&t,o);
1261 while (moreIteration(&t)) { 1261 while (moreIteration(&t)) {
1262 VObject *eachProp = nextVObject(&t); 1262 VObject *eachProp = nextVObject(&t);
1263 writeProp(fp, eachProp); 1263 writeProp(fp, eachProp);
1264 } 1264 }
1265 appendsOFile(fp,"END:"); 1265 appendsOFile(fp,"END:");
1266 appendsOFile(fp,begin); 1266 appendsOFile(fp,begin);
1267 appendsOFile(fp,"\n\n"); 1267 appendsOFile(fp,"\n\n");
1268 } 1268 }
1269 } 1269 }
1270} 1270}
1271 1271
1272void writeVObject(FILE *fp, VObject *o) 1272void writeVObject(FILE *fp, VObject *o)
1273{ 1273{
1274 OFile ofp; 1274 OFile ofp;
1275 // ##### 1275 // #####
1276 //_setmode(_fileno(fp), _O_BINARY); 1276 //_setmode(_fileno(fp), _O_BINARY);
1277 initOFile(&ofp,fp); 1277 initOFile(&ofp,fp);
1278 writeVObject_(&ofp,o); 1278 writeVObject_(&ofp,o);
1279} 1279}
1280 1280
1281DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o) 1281DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o)
1282{ 1282{
1283 QFileDirect f( fname); 1283 QFileDirect f( fname);
1284 if ( !f.open( IO_WriteOnly ) ) { 1284 if ( !f.open( IO_WriteOnly ) ) {
1285 qWarning("Unable to open vobject write %s", fname); 1285 qWarning("Unable to open vobject write %s", fname);
1286 return; 1286 return;
1287 } 1287 }
1288 1288
1289 writeVObject( f.directHandle(),o ); 1289 writeVObject( f.directHandle(),o );
1290} 1290}
1291 1291
1292DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list) 1292DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list)
1293{ 1293{
1294 QFileDirect f( fname); 1294 QFileDirect f( fname);
1295 if ( !f.open( IO_WriteOnly ) ) { 1295 if ( !f.open( IO_WriteOnly ) ) {
1296 qWarning("Unable to open vobject write %s", fname); 1296 qWarning("Unable to open vobject write %s", fname);
1297 return; 1297 return;
1298 } 1298 }
1299 1299
1300 while (list) { 1300 while (list) {
1301 writeVObject(f.directHandle(),list); 1301 writeVObject(f.directHandle(),list);
1302 list = nextVObjectInList(list); 1302 list = nextVObjectInList(list);
1303 } 1303 }
1304} 1304}
1305 1305
1306DLLEXPORT(const char *) vObjectTypeInfo(VObject *o) 1306DLLEXPORT(const char *) vObjectTypeInfo(VObject *o)
1307{ 1307{
1308 const char *type = vObjectName( o ); 1308 const char *type = vObjectName( o );
1309 if ( strcmp( type, "TYPE" ) == 0 ) 1309 if ( strcmp( type, "TYPE" ) == 0 )
1310 type = vObjectStringZValue( o ); 1310 type = vObjectStringZValue( o );
1311 return type; 1311 return type;
1312} 1312}
1313 1313
1314 1314
1315// end of source file vobject.c 1315// end of source file vobject.c