-rw-r--r-- | library/backend/vcc.y | 2 | ||||
-rw-r--r-- | library/backend/vcc_yacc.cpp | 2 | ||||
-rw-r--r-- | library/backend/vobject.cpp | 116 |
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 | |||
@@ -29,193 +29,193 @@ DAMAGE. | |||
29 | 29 | ||
30 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, | 30 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, |
31 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE | 31 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE |
32 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 32 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
33 | PURPOSE. | 33 | PURPOSE. |
34 | 34 | ||
35 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or | 35 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or |
36 | disclosure by the government are subject to restrictions set forth in | 36 | disclosure by the government are subject to restrictions set forth in |
37 | DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. | 37 | DFARS 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 ****/ |
138 | int mime_lineNum, mime_numErrors; /* yyerror() can use these */ | 138 | int mime_lineNum, mime_numErrors; /* yyerror() can use these */ |
139 | static VObject* vObjList; | 139 | static VObject* vObjList; |
140 | static VObject *curProp; | 140 | static VObject *curProp; |
141 | static VObject *curObj; | 141 | static VObject *curObj; |
142 | static VObject* ObjStack[MAXLEVEL]; | 142 | static VObject* ObjStack[MAXLEVEL]; |
143 | static int ObjStackTop; | 143 | static 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__ |
148 | extern "C" { | 148 | extern "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 | ||
157 | int yyparse(); | 157 | int yyparse(); |
158 | 158 | ||
159 | enum LexMode { | 159 | enum 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 ****/ |
171 | static int pushVObject(const char *prop); | 171 | static int pushVObject(const char *prop); |
172 | static VObject* popVObject(); | 172 | static VObject* popVObject(); |
173 | static void lexPopMode(int top); | 173 | static void lexPopMode(int top); |
174 | static int lexWithinMode(enum LexMode mode); | 174 | static int lexWithinMode(enum LexMode mode); |
175 | static void lexPushMode(enum LexMode mode); | 175 | static void lexPushMode(enum LexMode mode); |
176 | static void enterProps(const char *s); | 176 | static void enterProps(const char *s); |
177 | static void enterAttr(const char *s1, const char *s2); | 177 | static void enterAttr(const char *s1, const char *s2); |
178 | static void enterValues(const char *value); | 178 | static void enterValues(const char *value); |
179 | #define mime_error yyerror | 179 | #define mime_error yyerror |
180 | void mime_error(char *s); | 180 | void mime_error(char *s); |
181 | void mime_error_(char *s); | 181 | void 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 | ||
217 | mime: vobjects | 217 | mime: vobjects |
218 | ; | 218 | ; |
219 | 219 | ||
220 | vobjects: vobjects vobject | 220 | vobjects: vobjects vobject |
221 | { addList(&vObjList, $2); curObj = 0; } | 221 | { addList(&vObjList, $2); curObj = 0; } |
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 | |||
@@ -65,193 +65,193 @@ DAMAGE. | |||
65 | 65 | ||
66 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, | 66 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, |
67 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE | 67 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE |
68 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 68 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
69 | PURPOSE. | 69 | PURPOSE. |
70 | 70 | ||
71 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or | 71 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or |
72 | disclosure by the government are subject to restrictions set forth in | 72 | disclosure by the government are subject to restrictions set forth in |
73 | DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. | 73 | DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. |
74 | 74 | ||
75 | ***************************************************************************/ | 75 | ***************************************************************************/ |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * src: vcc.c | 78 | * src: vcc.c |
79 | * doc: Parser for vCard and vCalendar. Note that this code is | 79 | * doc: Parser for vCard and vCalendar. Note that this code is |
80 | * generated by a yacc parser generator. Generally it should not | 80 | * generated by a yacc parser generator. Generally it should not |
81 | * be edited by hand. The real source is vcc.y. The #line directives | 81 | * be edited by hand. The real source is vcc.y. The #line directives |
82 | * can be commented out here to make it easier to trace through | 82 | * can be commented out here to make it easier to trace through |
83 | * in a debugger. However, if a bug is found it should | 83 | * in a debugger. However, if a bug is found it should |
84 | * be fixed in vcc.y and this file regenerated. | 84 | * be fixed in vcc.y and this file regenerated. |
85 | */ | 85 | */ |
86 | 86 | ||
87 | 87 | ||
88 | /* debugging utilities */ | 88 | /* debugging utilities */ |
89 | #if __DEBUG | 89 | #if __DEBUG |
90 | #define DBG_(x) printf x | 90 | #define DBG_(x) printf x |
91 | #else | 91 | #else |
92 | #define DBG_(x) | 92 | #define DBG_(x) |
93 | #endif | 93 | #endif |
94 | 94 | ||
95 | /**** External Functions ****/ | 95 | /**** External Functions ****/ |
96 | 96 | ||
97 | /* assign local name to parser variables and functions so that | 97 | /* assign local name to parser variables and functions so that |
98 | we can use more than one yacc based parser. | 98 | we can use more than one yacc based parser. |
99 | */ | 99 | */ |
100 | 100 | ||
101 | #if 0 | 101 | #if 0 |
102 | #define yyparse mime_parse | 102 | #define yyparse mime_parse |
103 | #define yylex mime_lex | 103 | #define yylex mime_lex |
104 | #define yyerror mime_error | 104 | #define yyerror mime_error |
105 | #define yychar mime_char | 105 | #define yychar mime_char |
106 | /* #define p_yyval p_mime_val */ | 106 | /* #define p_yyval p_mime_val */ |
107 | #undef yyval | 107 | #undef yyval |
108 | #define yyval mime_yyval | 108 | #define yyval mime_yyval |
109 | /* #define p_yylval p_mime_lval */ | 109 | /* #define p_yylval p_mime_lval */ |
110 | #undef yylval | 110 | #undef yylval |
111 | #define yylval mime_yylval | 111 | #define yylval mime_yylval |
112 | #define yydebug mime_debug | 112 | #define yydebug mime_debug |
113 | #define yynerrs mime_nerrs | 113 | #define yynerrs mime_nerrs |
114 | #define yyerrflag mime_errflag | 114 | #define yyerrflag mime_errflag |
115 | #define yyss mime_ss | 115 | #define yyss mime_ss |
116 | #define yyssp mime_ssp | 116 | #define yyssp mime_ssp |
117 | #define yyvs mime_vs | 117 | #define yyvs mime_vs |
118 | #define yyvsp mime_vsp | 118 | #define yyvsp mime_vsp |
119 | #define yylhs mime_lhs | 119 | #define yylhs mime_lhs |
120 | #define yylen mime_len | 120 | #define yylen mime_len |
121 | #define yydefred mime_defred | 121 | #define yydefred mime_defred |
122 | #define yydgoto mime_dgoto | 122 | #define yydgoto mime_dgoto |
123 | #define yysindex mime_sindex | 123 | #define yysindex mime_sindex |
124 | #define yyrindex mime_rindex | 124 | #define yyrindex mime_rindex |
125 | #define yygindex mime_gindex | 125 | #define yygindex mime_gindex |
126 | #define yytable mime_table | 126 | #define yytable mime_table |
127 | #define yycheck mime_check | 127 | #define yycheck mime_check |
128 | #define yyname mime_name | 128 | #define yyname mime_name |
129 | #define yyrule mime_rule | 129 | #define yyrule mime_rule |
130 | #ifdef YYPREFIX | 130 | #ifdef YYPREFIX |
131 | #undef YYPREFIX | 131 | #undef YYPREFIX |
132 | #endif | 132 | #endif |
133 | #define YYPREFIX "mime_" | 133 | #define YYPREFIX "mime_" |
134 | #endif | 134 | #endif |
135 | 135 | ||
136 | 136 | ||
137 | #ifndef _NO_LINE_FOLDING | 137 | #ifndef _NO_LINE_FOLDING |
138 | #define _SUPPORT_LINE_FOLDING 1 | 138 | #define _SUPPORT_LINE_FOLDING 1 |
139 | #endif | 139 | #endif |
140 | 140 | ||
141 | /* undef below if compile with MFC */ | 141 | /* undef below if compile with MFC */ |
142 | /* #define INCLUDEMFC 1 */ | 142 | /* #define INCLUDEMFC 1 */ |
143 | 143 | ||
144 | #if defined(WIN32) || defined(_WIN32) | 144 | #if defined(WIN32) || defined(_WIN32) |
145 | #ifdef INCLUDEMFC | 145 | #ifdef INCLUDEMFC |
146 | #include <afx.h> | 146 | #include <afx.h> |
147 | #endif | 147 | #endif |
148 | #endif | 148 | #endif |
149 | 149 | ||
150 | #include <string.h> | 150 | #include <string.h> |
151 | #ifndef __MWERKS__ | 151 | #ifndef __MWERKS__ |
152 | #include <stdlib.h> | 152 | #include <stdlib.h> |
153 | #endif | 153 | #endif |
154 | #include <stdio.h> | 154 | #include <stdio.h> |
155 | #include <stdlib.h> | 155 | #include <stdlib.h> |
156 | #include <ctype.h> | 156 | #include <ctype.h> |
157 | 157 | ||
158 | /*#ifdef PALMTOPCENTER */ | 158 | /*#ifdef PALMTOPCENTER */ |
159 | /*#include <qpe/vobject_p.h> */ | 159 | /*#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 ****/ |
174 | int mime_lineNum, mime_numErrors; /* yyerror() can use these */ | 174 | int mime_lineNum, mime_numErrors; /* yyerror() can use these */ |
175 | static VObject* vObjList; | 175 | static VObject* vObjList; |
176 | static VObject *curProp; | 176 | static VObject *curProp; |
177 | static VObject *curObj; | 177 | static VObject *curObj; |
178 | static VObject* ObjStack[MAXLEVEL]; | 178 | static VObject* ObjStack[MAXLEVEL]; |
179 | static int ObjStackTop; | 179 | static 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__ |
184 | extern "C" { | 184 | extern "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 | ||
193 | int yyparse(); | 193 | int yyparse(); |
194 | 194 | ||
195 | enum LexMode { | 195 | enum 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 ****/ |
207 | static int pushVObject(const char *prop); | 207 | static int pushVObject(const char *prop); |
208 | static VObject* popVObject(); | 208 | static VObject* popVObject(); |
209 | static void lexPopMode(int top); | 209 | static void lexPopMode(int top); |
210 | static int lexWithinMode(enum LexMode mode); | 210 | static int lexWithinMode(enum LexMode mode); |
211 | static void lexPushMode(enum LexMode mode); | 211 | static void lexPushMode(enum LexMode mode); |
212 | static void enterProps(const char *s); | 212 | static void enterProps(const char *s); |
213 | static void enterAttr(const char *s1, const char *s2); | 213 | static void enterAttr(const char *s1, const char *s2); |
214 | static void enterValues(const char *value); | 214 | static void enterValues(const char *value); |
215 | #define mime_error yyerror | 215 | #define mime_error yyerror |
216 | void mime_error(char *s); | 216 | void mime_error(char *s); |
217 | void mime_error_(char *s); | 217 | void mime_error_(char *s); |
218 | 218 | ||
219 | #line 189 "backend/vcc.y" | 219 | #line 189 "backend/vcc.y" |
220 | typedef union { | 220 | typedef 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 |
244 | short vcclhs[] = { -1, | 244 | short 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 | }; |
251 | short vcclen[] = { 2, | 251 | short 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 | }; |
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,146 +1,146 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | (C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International | 2 | (C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International |
3 | Business Machines Corporation and Siemens Rolm Communications Inc. | 3 | Business Machines Corporation and Siemens Rolm Communications Inc. |
4 | 4 | ||
5 | For purposes of this license notice, the term Licensors shall mean, | 5 | For purposes of this license notice, the term Licensors shall mean, |
6 | collectively, Apple Computer, Inc., AT&T Corp., International | 6 | collectively, Apple Computer, Inc., AT&T Corp., International |
7 | Business Machines Corporation and Siemens Rolm Communications Inc. | 7 | Business Machines Corporation and Siemens Rolm Communications Inc. |
8 | The term Licensor shall mean any of the Licensors. | 8 | The term Licensor shall mean any of the Licensors. |
9 | 9 | ||
10 | Subject to acceptance of the following conditions, permission is hereby | 10 | Subject to acceptance of the following conditions, permission is hereby |
11 | granted by Licensors without the need for written agreement and without | 11 | granted by Licensors without the need for written agreement and without |
12 | license or royalty fees, to use, copy, modify and distribute this | 12 | license or royalty fees, to use, copy, modify and distribute this |
13 | software for any purpose. | 13 | software for any purpose. |
14 | 14 | ||
15 | The above copyright notice and the following four paragraphs must be | 15 | The above copyright notice and the following four paragraphs must be |
16 | reproduced in all copies of this software and any software including | 16 | reproduced in all copies of this software and any software including |
17 | this software. | 17 | this software. |
18 | 18 | ||
19 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE | 19 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE |
20 | ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR | 20 | ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR |
21 | MODIFICATIONS. | 21 | MODIFICATIONS. |
22 | 22 | ||
23 | IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, | 23 | IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, |
24 | INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT | 24 | INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT |
25 | OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | 25 | OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
26 | DAMAGE. | 26 | DAMAGE. |
27 | 27 | ||
28 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, | 28 | EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, |
29 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE | 29 | INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE |
30 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 30 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
31 | PURPOSE. | 31 | PURPOSE. |
32 | 32 | ||
33 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or | 33 | The software is provided with RESTRICTED RIGHTS. Use, duplication, or |
34 | disclosure by the government are subject to restrictions set forth in | 34 | disclosure by the government are subject to restrictions set forth in |
35 | DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. | 35 | DFARS 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 | ||
65 | typedef union ValueItem { | 65 | typedef 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 | ||
73 | struct VObject { | 73 | struct 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 | ||
81 | typedef struct StrItem StrItem; | 81 | typedef struct StrItem StrItem; |
82 | 82 | ||
83 | struct StrItem { | 83 | struct 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 | ||
89 | const char** fieldedProp; | 89 | const 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 | ||
103 | DLLEXPORT(VObject*) newVObject_(const char *id) | 103 | DLLEXPORT(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 | ||
114 | DLLEXPORT(VObject*) newVObject(const char *id) | 114 | DLLEXPORT(VObject*) newVObject(const char *id) |
115 | { | 115 | { |
116 | return newVObject_(lookupStr(id)); | 116 | return newVObject_(lookupStr(id)); |
117 | } | 117 | } |
118 | 118 | ||
119 | DLLEXPORT(void) deleteVObject(VObject *p) | 119 | DLLEXPORT(void) deleteVObject(VObject *p) |
120 | { | 120 | { |
121 | unUseStr(p->id); | 121 | unUseStr(p->id); |
122 | free(p); | 122 | free(p); |
123 | } | 123 | } |
124 | 124 | ||
125 | DLLEXPORT(char*) dupStr(const char *s, unsigned int size) | 125 | DLLEXPORT(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 | ||
142 | DLLEXPORT(void) deleteStr(const char *p) | 142 | DLLEXPORT(void) deleteStr(const char *p) |
143 | { | 143 | { |
144 | if (p) free((void*)p); | 144 | if (p) free((void*)p); |
145 | } | 145 | } |
146 | 146 | ||
@@ -234,269 +234,269 @@ DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p) | |||
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 | ||
238 | DLLEXPORT(int) vObjectValueType(VObject *o) | 238 | DLLEXPORT(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 | ||
248 | DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p) | 248 | DLLEXPORT(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 | ||
283 | DLLEXPORT(VObject*) addProp(VObject *o, const char *id) | 283 | DLLEXPORT(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 | ||
288 | DLLEXPORT(VObject*) addProp_(VObject *o, const char *id) | 288 | DLLEXPORT(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 | ||
293 | DLLEXPORT(void) addList(VObject **o, VObject *p) | 293 | DLLEXPORT(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 | ||
308 | DLLEXPORT(VObject*) nextVObjectInList(VObject *o) | 308 | DLLEXPORT(VObject*) nextVObjectInList(VObject *o) |
309 | { | 309 | { |
310 | return o->next; | 310 | return o->next; |
311 | } | 311 | } |
312 | 312 | ||
313 | DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size) | 313 | DLLEXPORT(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 | ||
322 | DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size) | 322 | DLLEXPORT(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 | ||
328 | DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o) | 328 | DLLEXPORT(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 | ||
334 | DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o) | 334 | DLLEXPORT(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 | ||
340 | DLLEXPORT(int) moreIteration(VObjectIterator *i) | 340 | DLLEXPORT(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 | ||
345 | DLLEXPORT(VObject*) nextVObject(VObjectIterator *i) | 345 | DLLEXPORT(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 | ||
360 | DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id) | 360 | DLLEXPORT(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 | ||
372 | DLLEXPORT(VObject*) addGroup(VObject *o, const char *g) | 372 | DLLEXPORT(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 | ||
413 | DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v) | 413 | DLLEXPORT(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 | ||
421 | DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v, | 421 | DLLEXPORT(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 | ||
430 | DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v, | 430 | DLLEXPORT(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 | ||
437 | DLLEXPORT(void) cleanVObject(VObject *o) | 437 | DLLEXPORT(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 | ||
470 | DLLEXPORT(void) cleanVObjects(VObject *list) | 470 | DLLEXPORT(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 | ||
485 | static StrItem *strTbl[STRTBLSIZE]; | 485 | static StrItem *strTbl[STRTBLSIZE]; |
486 | 486 | ||
487 | static unsigned int hashStr(const char *s) | 487 | static 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 | ||
497 | DLLEXPORT(const char*) lookupStr(const char *s) | 497 | DLLEXPORT(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 { |
@@ -706,610 +706,610 @@ static struct PreDefProp propNames[] = { | |||
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 | ||
798 | static struct PreDefProp* lookupPropInfo(const char* str) | 798 | static 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 | ||
812 | DLLEXPORT(const char*) lookupProp_(const char* str) | 812 | DLLEXPORT(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 | ||
826 | DLLEXPORT(const char*) lookupProp(const char* str) | 826 | DLLEXPORT(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 |
846 | typedef struct OFile { | 846 | typedef 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 |
856 | static void appendsOFile(OFile *fp, const char *s) | 856 | static 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 { |
865 | stuff: | 865 | stuff: |
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 | ||
884 | static void appendcOFile(OFile *fp, char c) | 884 | static 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 { |
891 | stuff: | 891 | stuff: |
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 |
909 | static void appendcOFile_(OFile *fp, char c) | 909 | static 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 { |
916 | stuff: | 916 | stuff: |
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 | ||
934 | static void appendcOFile(OFile *fp, char c) | 934 | static 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 | ||
945 | static void appendsOFile(OFile *fp, const char *s) | 945 | static 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 | ||
956 | static void initOFile(OFile *fp, FILE *ofp) | 956 | static 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 | ||
966 | static int writeBase64(OFile *fp, unsigned char *s, long len) | 966 | static 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 | ||
1008 | static const char *replaceChar(unsigned char c) | 1008 | static 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 | ||
1051 | static void writeQPString(OFile *fp, const char *s) | 1051 | static 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 | ||
1080 | static bool includesUnprintable(VObject *o) | 1080 | static 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 | ||
1097 | static void writeVObject_(OFile *fp, VObject *o); | 1097 | static void writeVObject_(OFile *fp, VObject *o); |
1098 | 1098 | ||
1099 | static void writeValue(OFile *fp, VObject *o, unsigned long size) | 1099 | static 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 | ||
1131 | static void writeAttrValue(OFile *fp, VObject *o) | 1131 | static 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 | ||
1152 | static void writeGroup(OFile *fp, VObject *o) | 1152 | static 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 | ||
1166 | static int inList(const char **list, const char *s) | 1166 | static 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 | ||
1176 | static void writeProp(OFile *fp, VObject *o) | 1176 | static 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 | ||
1248 | static void writeVObject_(OFile *fp, VObject *o) | 1248 | static 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 | ||
1272 | void writeVObject(FILE *fp, VObject *o) | 1272 | void 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 | ||
1281 | DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o) | 1281 | DLLEXPORT(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 | ||
1292 | DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list) | 1292 | DLLEXPORT(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 | ||
1306 | DLLEXPORT(const char *) vObjectTypeInfo(VObject *o) | 1306 | DLLEXPORT(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 |