/[public]/psiconv/trunk/lib/psiconv/parse_layout.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_layout.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 63 Revision 64
29{ 29{
30 int res = 0; 30 int res = 0;
31 int len = 0; 31 int len = 0;
32 32
33 psiconv_progress(lev+1,off,"Going to parse color"); 33 psiconv_progress(lev+1,off,"Going to parse color");
34 *result = malloc(sizeof(**result)); 34 if (!(*result = malloc(sizeof(**result))))
35 goto ERROR1;
35 36
36 (*result)->red = psiconv_read_u8(buf,lev+2,off+len); 37 (*result)->red = psiconv_read_u8(buf,lev+2,off+len,&res);
38 if (res)
39 goto ERROR2;
37 (*result)->green = psiconv_read_u8(buf,lev+2,off+len+1); 40 (*result)->green = psiconv_read_u8(buf,lev+2,off+len+1,&res);
41 if (res)
42 goto ERROR2;
38 (*result)->blue = psiconv_read_u8(buf,lev+2,off+len+2); 43 (*result)->blue = psiconv_read_u8(buf,lev+2,off+len+2,&res);
44 if (res)
45 goto ERROR2;
39 len += 3; 46 len += 3;
40 47
41 psiconv_debug(lev+2,off,"Color: red %02x, green %02x, blue %02x", 48 psiconv_debug(lev+2,off,"Color: red %02x, green %02x, blue %02x",
42 (*result)->red, (*result)->green, (*result)->blue); 49 (*result)->red, (*result)->green, (*result)->blue);
43 if (length) 50 if (length)
44 *length = len; 51 *length = len;
45 52
46 psiconv_progress(lev+1,off+len-1,"End of color (total length: %08x)",len); 53 psiconv_progress(lev+1,off+len-1,"End of color (total length: %08x)",len);
54 return 0;
55
56ERROR2:
57 free(*result);
58ERROR1:
59 psiconv_warn(lev+1,off,"Reading of Color failed");
60 if (length)
61 *length = 0;
62 if (res == 0)
63 return -PSICONV_E_NOMEM;
64 else
47 return res; 65 return res;
48} 66}
49 67
50 68
51 69
52int psiconv_parse_font(const psiconv_buffer buf, int lev, psiconv_u32 off, 70int psiconv_parse_font(const psiconv_buffer buf, int lev, psiconv_u32 off,
56 int strlength,i; 74 int strlength,i;
57 char *str_copy; 75 char *str_copy;
58 int len; 76 int len;
59 77
60 psiconv_progress(lev+1,off,"Going to parse font"); 78 psiconv_progress(lev+1,off,"Going to parse font");
61 *result = malloc(sizeof(**result)); 79 if (!(*result = malloc(sizeof(**result))))
80 goto ERROR1;
62 81
63 strlength = psiconv_read_u8(buf,lev+2,off); 82 strlength = psiconv_read_u8(buf,lev+2,off,&res);
83 if (res)
84 goto ERROR2;
64 (*result)->name = malloc(strlength); 85 if (!((*result)->name = malloc(strlength))) {
86 goto ERROR2;
87 }
65 for (i = 0; i < strlength-1; i++) 88 for (i = 0; (i < strlength-1) && !res; i++)
66 (*result)->name[i] = psiconv_read_u8(buf,lev+2,off + 1 + i); 89 (*result)->name[i] = psiconv_read_u8(buf,lev+2,off + 1 + i,&res);
90 if (res)
91 goto ERROR3;
67 (*result)->name[strlength-1] = 0; 92 (*result)->name[strlength-1] = 0;
68 (*result)->screenfont = psiconv_read_u8(buf,lev+2,off + strlength); 93 (*result)->screenfont = psiconv_read_u8(buf,lev+2,off + strlength,&res);
94 if (res)
95 goto ERROR3;
69 96
70 str_copy = psiconv_make_printable((*result)->name); 97 if (!(str_copy = psiconv_make_printable((*result)->name)))
98 goto ERROR3;
99
71 psiconv_debug(lev+2,off+1,"Found font `%s', displayed with screen font %02x", 100 psiconv_debug(lev+2,off+1,"Found font `%s', displayed with screen font %02x",
72 str_copy,(*result)->screenfont); 101 str_copy,(*result)->screenfont);
73 free(str_copy); 102 free(str_copy);
74 len = strlength + 1; 103 len = strlength + 1;
75 if (length) 104 if (length)
76 *length = len; 105 *length = len;
77 106
78 psiconv_progress(lev+1,off + len - 1,"End of font (total length: %08x)",len); 107 psiconv_progress(lev+1,off + len - 1,"End of font (total length: %08x)",len);
108 return 0;
109
110ERROR3:
111 free ((*result)->name);
112ERROR2:
113 free (*result);
114ERROR1:
115 psiconv_warn(lev+1,off,"Reading of Font failed");
116 if (length)
117 *length = 0;
118 if (!res)
119 return -PSICONV_E_NOMEM;
120 else
79 return res; 121 return res;
80} 122}
81 123
82int psiconv_parse_border(const psiconv_buffer buf,int lev,psiconv_u32 off, 124int psiconv_parse_border(const psiconv_buffer buf,int lev,psiconv_u32 off,
83 int *length, psiconv_border *result) 125 int *length, psiconv_border *result)
84{ 126{
86 int len = 0; 128 int len = 0;
87 psiconv_u32 temp; 129 psiconv_u32 temp;
88 int leng; 130 int leng;
89 131
90 psiconv_progress(lev+1,off,"Going to parse border data"); 132 psiconv_progress(lev+1,off,"Going to parse border data");
91 *result = malloc(sizeof(**result)); 133 if (!(*result = malloc(sizeof(**result)))) {
134 goto ERROR1;
135 }
92 136
93 psiconv_progress(lev+2,off+len,"Going to read border kind"); 137 psiconv_progress(lev+2,off+len,"Going to read border kind");
94 temp = psiconv_read_u8(buf,lev+2,off+len); 138 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
139 if (res)
140 goto ERROR2;
95 if (temp == 0x00) 141 if (temp == 0x00)
96 (*result)->kind = psiconv_border_none; 142 (*result)->kind = psiconv_border_none;
97 else if (temp == 0x01) 143 else if (temp == 0x01)
98 (*result)->kind = psiconv_border_solid; 144 (*result)->kind = psiconv_border_solid;
99 else if (temp == 0x02) 145 else if (temp == 0x02)
107 else if (temp == 0x06) 153 else if (temp == 0x06)
108 (*result)->kind = psiconv_border_dotdotstripe; 154 (*result)->kind = psiconv_border_dotdotstripe;
109 else { 155 else {
110 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')"); 156 psiconv_warn(lev+2,off,"Unknown border kind (defaults to `none')");
111 (*result)->kind = psiconv_border_none; 157 (*result)->kind = psiconv_border_none;
112 res = -1;
113 } 158 }
114 psiconv_debug(lev+2,off+len,"Kind: %02x",temp); 159 psiconv_debug(lev+2,off+len,"Kind: %02x",temp);
115 len ++; 160 len ++;
116 161
117 psiconv_progress(lev+2,off+len,"Going to read border thickness"); 162 psiconv_progress(lev+2,off+len,"Going to read border thickness");
118 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng); 163 (*result)->thickness = psiconv_read_size(buf,lev+2,off+len,&leng,&res);
164 if (res)
165 goto ERROR2;
119 if (((*result)->kind != psiconv_border_solid) && 166 if (((*result)->kind != psiconv_border_solid) &&
120 ((*result)->kind != psiconv_border_double) && 167 ((*result)->kind != psiconv_border_double) &&
121 ((*result)->thickness != 0.0) && 168 ((*result)->thickness != 0.0) &&
122 (fabs((*result)->thickness - 1/20) >= 1/1000)) { 169 (fabs((*result)->thickness - 1/20) >= 1/1000)) {
123 psiconv_warn(lev+2,off, 170 psiconv_warn(lev+2,off,
124 "Border thickness specified for unlikely border type"); 171 "Border thickness specified for unlikely border type");
125 res = -1;
126 } 172 }
127 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness); 173 psiconv_debug(lev+2,off+len,"Thickness: %f",(*result)->thickness);
128 len += leng; 174 len += leng;
129 175
130 psiconv_progress(lev+2,off+len,"Going to read the border color"); 176 psiconv_progress(lev+2,off+len,"Going to read the border color");
131 res |= psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color); 177 if ((psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color)))
178 goto ERROR2;
132 len += leng; 179 len += leng;
133 180
134 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte " 181 psiconv_progress(lev+2,off+len,"Going to read the final unknown byte "
135 "(0x01 expected)"); 182 "(0x01 expected)");
136 temp = psiconv_read_u8(buf,lev+2,off + len); 183 temp = psiconv_read_u8(buf,lev+2,off + len,&res);
184 if (res)
185 goto ERROR3;
137 if (temp != 0x01) { 186 if (temp != 0x01) {
138 psiconv_warn(lev+2,off,"Unknown last byte in border specification"); 187 psiconv_warn(lev+2,off,"Unknown last byte in border specification");
139 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x", 188 psiconv_debug(lev+2,off+len, "Last byte: read %02x, expected %02x",
140 temp,0x01); 189 temp,0x01);
141 res = -1;
142 } 190 }
143 len ++; 191 len ++;
144 192
145 if (length) 193 if (length)
146 *length = len; 194 *length = len;
147 195
148 psiconv_progress(lev+1,off + len - 1, 196 psiconv_progress(lev+1,off + len - 1,
149 "End of border (total length: %08x)",len); 197 "End of border (total length: %08x)",len);
150 198
199 return 0;
200
201ERROR3:
202 psiconv_free_color((*result)->color);
203ERROR2:
204 free (result);
205ERROR1:
206 psiconv_warn(lev+1,off,"Reading of Border failed");
207 if (length)
208 *length = 0;
209 if (!res)
210 return -PSICONV_E_NOMEM;
211 else
151 return res; 212 return res;
152} 213}
153 214
154int psiconv_parse_bullet(const psiconv_buffer buf,int lev,psiconv_u32 off, 215int psiconv_parse_bullet(const psiconv_buffer buf,int lev,psiconv_u32 off,
155 int *length, psiconv_bullet *result) 216 int *length, psiconv_bullet *result)
156{ 217{
157 int res = 0; 218 int res = 0;
158 int len = 0; 219 int len = 0;
159 int leng; 220 int leng;
160 int bullet_length; 221 int bullet_length;
161 222
162 *result = malloc(sizeof(**result)); 223 if (!(*result = malloc(sizeof(**result))))
224 goto ERROR1;
163 (*result)->on = psiconv_bool_true; 225 (*result)->on = psiconv_bool_true;
164 226
165 psiconv_progress(lev+1,off,"Going to parse bullet data"); 227 psiconv_progress(lev+1,off,"Going to parse bullet data");
166 psiconv_progress(lev+2,off+len,"Going to read bullet length"); 228 psiconv_progress(lev+2,off+len,"Going to read bullet length");
167 bullet_length = psiconv_read_u8(buf,lev+2,off+len); 229 bullet_length = psiconv_read_u8(buf,lev+2,off+len,&res);
230 if (res)
231 goto ERROR2;
168 psiconv_debug(lev+2,off+len,"Length: %02x",bullet_length); 232 psiconv_debug(lev+2,off+len,"Length: %02x",bullet_length);
169 len ++; 233 len ++;
170 234
171 psiconv_progress(lev+2,off+len,"Going to read bullet font size"); 235 psiconv_progress(lev+2,off+len,"Going to read bullet font size");
172 (*result)->font_size = psiconv_read_size(buf,lev+2,off+len, &leng); 236 (*result)->font_size = psiconv_read_size(buf,lev+2,off+len, &leng,&res);
237 if (res)
238 goto ERROR2;
173 len +=leng; 239 len +=leng;
174 240
175 psiconv_progress(lev+2,off+len,"Going to read bullet character"); 241 psiconv_progress(lev+2,off+len,"Going to read bullet character");
176 (*result)->character = psiconv_read_u8(buf,lev+2,off+len); 242 (*result)->character = psiconv_read_u8(buf,lev+2,off+len,&res);
243 if (res)
244 goto ERROR2;
177 psiconv_debug(lev+2,off+len,"Character: %02x",(*result)->character); 245 psiconv_debug(lev+2,off+len,"Character: %02x",(*result)->character);
178 len ++; 246 len ++;
179 247
180 psiconv_progress(lev+2,off+len,"Going to read indent on/off"); 248 psiconv_progress(lev+2,off+len,"Going to read indent on/off");
181 res |= psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->indent); 249 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,&(*result)->indent)))
250 goto ERROR2;
182 psiconv_debug(lev+2,off+len,"Indent on: %02x",(*result)->indent); 251 psiconv_debug(lev+2,off+len,"Indent on: %02x",(*result)->indent);
183 len += leng; 252 len += leng;
184 253
185 psiconv_progress(lev+2,off+len,"Going to read bullet color"); 254 psiconv_progress(lev+2,off+len,"Going to read bullet color");
186 res |= psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color); 255 if ((res = psiconv_parse_color(buf,lev+2,off+len,&leng,&(*result)->color)))
256 goto ERROR2;
187 len += leng; 257 len += leng;
188 258
189 psiconv_progress(lev+2,off+len,"Going to read bullet font"); 259 psiconv_progress(lev+2,off+len,"Going to read bullet font");
190 res |= psiconv_parse_font(buf,lev+2,off+len,&leng,&(*result)->font); 260 if ((res = psiconv_parse_font(buf,lev+2,off+len,&leng,&(*result)->font)))
261 goto ERROR3;
191 len += leng; 262 len += leng;
192 263
193 if (len != bullet_length + 1) { 264 if (len != bullet_length + 1) {
194 psiconv_warn(lev+2,off,"Bullet data structure length mismatch"); 265 psiconv_warn(lev+2,off,"Bullet data structure length mismatch");
195 psiconv_debug(lev+2,off,"Length: specified %02x, found %02x", 266 psiconv_debug(lev+2,off,"Length: specified %02x, found %02x",
196 bullet_length,len-1); 267 bullet_length,len-1);
197 res = -1;
198 } 268 }
199 269
200 psiconv_progress(lev+1,off + len - 1, 270 psiconv_progress(lev+1,off + len - 1,
201 "End of bullet data (total length: %08x)",len); 271 "End of bullet data (total length: %08x)",len);
202 272
203 if (length) 273 if (length)
204 *length = len; 274 *length = len;
205 return res; 275 return res;
276
277ERROR3:
278 psiconv_free_color((*result)->color);
279ERROR2:
280 free (result);
281ERROR1:
282 psiconv_warn(lev+1,off,"Reading of Bullet failed");
283 if (length)
284 *length = 0;
285 if (!res)
286 return -PSICONV_E_NOMEM;
287 else
288 return res;
206} 289}
207 290
208int psiconv_parse_tab(const psiconv_buffer buf, int lev, psiconv_u32 off, 291int psiconv_parse_tab(const psiconv_buffer buf, int lev, psiconv_u32 off,
209 int *length, psiconv_tab *result) 292 int *length, psiconv_tab *result)
210{ 293{
212 int len = 0; 295 int len = 0;
213 int leng; 296 int leng;
214 psiconv_u8 temp; 297 psiconv_u8 temp;
215 298
216 psiconv_progress(lev+1,off,"Going to parse tab"); 299 psiconv_progress(lev+1,off,"Going to parse tab");
217 *result = malloc(sizeof(**result)); 300 if (!(*result = malloc(sizeof(**result))))
301 goto ERROR1;
218 302
219 psiconv_progress(lev+2,off,"Going to read tab location"); 303 psiconv_progress(lev+2,off,"Going to read tab location");
220 (*result)->location = psiconv_read_length(buf,lev+2,off+len,&leng); 304 (*result)->location = psiconv_read_length(buf,lev+2,off+len,&leng,&res);
305 if (res)
306 goto ERROR2;
221 len += leng; 307 len += leng;
222 308
223 psiconv_progress(lev+2,off+len,"Going to read the tab kind"); 309 psiconv_progress(lev+2,off+len,"Going to read the tab kind");
224 temp = psiconv_read_u8(buf,lev+2,off+len); 310 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
311 if (res)
312 goto ERROR2;
225 if (temp == 1) 313 if (temp == 1)
226 (*result)->kind = psiconv_tab_left; 314 (*result)->kind = psiconv_tab_left;
227 else if (temp == 2) 315 else if (temp == 2)
228 (*result)->kind = psiconv_tab_centre; 316 (*result)->kind = psiconv_tab_centre;
229 else if (temp == 3) 317 else if (temp == 3)
230 (*result)->kind = psiconv_tab_right; 318 (*result)->kind = psiconv_tab_right;
231 else { 319 else {
232 res = -1;
233 psiconv_warn(lev+2,off+len,"Unknown tab kind argument"); 320 psiconv_warn(lev+2,off+len,"Unknown tab kind argument");
234 psiconv_debug(lev+2,off+len,"Kind found: %02x (defaulted to left tab)", 321 psiconv_debug(lev+2,off+len,"Kind found: %02x (defaulted to left tab)",
235 temp); 322 temp);
236 (*result)->kind = psiconv_tab_left; 323 (*result)->kind = psiconv_tab_left;
237 } 324 }
240 327
241 if (length) 328 if (length)
242 *length = len; 329 *length = len;
243 330
244 psiconv_progress(lev+1,off+len-1,"End of tab (total length: %08x)",len); 331 psiconv_progress(lev+1,off+len-1,"End of tab (total length: %08x)",len);
245 return res; 332 return 0;
246 333
334ERROR2:
335 free (result);
336ERROR1:
337 psiconv_warn(lev+1,off,"Reading of Tab failed");
338 if (length)
339 *length = 0;
340 if (!res)
341 return -PSICONV_E_NOMEM;
342 else
343 return res;
247} 344}
248 345
249int psiconv_parse_paragraph_layout_list(const psiconv_buffer buf, int lev, 346int psiconv_parse_paragraph_layout_list(const psiconv_buffer buf, int lev,
250 psiconv_u32 off, int *length, 347 psiconv_u32 off, int *length,
251 psiconv_paragraph_layout result) 348 psiconv_paragraph_layout result)
253 int res=0; 350 int res=0;
254 int len=0; 351 int len=0;
255 int list_length,leng,nr; 352 int list_length,leng,nr;
256 psiconv_u8 id; 353 psiconv_u8 id;
257 psiconv_u32 temp; 354 psiconv_u32 temp;
258 psiconv_tab tab; 355 psiconv_tab temp_tab;
356 psiconv_color temp_color;
357 psiconv_border temp_border;
358 psiconv_bullet temp_bullet;
259 359
260 psiconv_progress(lev+1,off,"Going to read paragraph layout list"); 360 psiconv_progress(lev+1,off,"Going to read paragraph layout list");
261 361
262 psiconv_progress(lev+2,off,"Going to read the list length"); 362 psiconv_progress(lev+2,off,"Going to read the list length");
263 list_length = psiconv_read_u32(buf,lev+2,off + len); 363 list_length = psiconv_read_u32(buf,lev+2,off + len,&res);
364 if (res)
365 goto ERROR1;
264 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); 366 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length);
265 len += 4; 367 len += 4;
266 368
267 nr = 0; 369 nr = 0;
268 while(len - 4 < list_length) { 370 while(len - 4 < list_length) {
269 psiconv_progress(lev+2,off+len,"Going to read element %d",nr); 371 psiconv_progress(lev+2,off+len,"Going to read element %d",nr);
270 psiconv_progress(lev+3,off+len,"Going to read the element id"); 372 psiconv_progress(lev+3,off+len,"Going to read the element id");
271 id = psiconv_read_u8(buf,lev+2,off+len); 373 id = psiconv_read_u8(buf,lev+2,off+len,&res);
374 if (res)
375 goto ERROR1;
272 psiconv_debug(lev+3,off+len,"Id: %02x",id); 376 psiconv_debug(lev+3,off+len,"Id: %02x",id);
273 len ++; 377 len ++;
274 switch(id) { 378 switch(id) {
275 case 0x01: 379 case 0x01:
276 psiconv_progress(lev+3,off+len,"Going to read background color"); 380 psiconv_progress(lev+3,off+len,"Going to read background color");
381 if ((res = psiconv_parse_color(buf,lev+3,off+len,&leng,&temp_color)))
382 goto ERROR1;
277 psiconv_free_color(result->back_color); 383 psiconv_free_color(result->back_color);
278 res |= psiconv_parse_color(buf,lev+3,off+len,&leng, 384 result->back_color = temp_color;
279 &result->back_color);
280 len += leng; 385 len += leng;
281 break; 386 break;
282 case 0x02: 387 case 0x02:
283 psiconv_progress(lev+3,off+len ,"Going to read indent left"); 388 psiconv_progress(lev+3,off+len ,"Going to read indent left");
284 result->indent_left = psiconv_read_length(buf,lev+3,off+len,&leng); 389 result->indent_left = psiconv_read_length(buf,lev+3,off+len,&leng,&res);
390 if (res)
391 goto ERROR1;
285 len += leng; 392 len += leng;
286 break; 393 break;
287 case 0x03: 394 case 0x03:
288 psiconv_progress(lev+3,off+len,"Going to read indent right"); 395 psiconv_progress(lev+3,off+len,"Going to read indent right");
289 result->indent_right = psiconv_read_length(buf,lev+2,off+len,&leng); 396 result->indent_right = psiconv_read_length(buf,lev+2,off+len,&leng,
397 &res);
398 if (res)
399 goto ERROR1;
290 len += leng; 400 len += leng;
291 break; 401 break;
292 case 0x04: 402 case 0x04:
293 psiconv_progress(lev+3,off+len,"Going to read indent left first line"); 403 psiconv_progress(lev+3,off+len,"Going to read indent left first line");
294 result->indent_first = psiconv_read_length(buf,lev+2,off+len, &leng); 404 result->indent_first = psiconv_read_length(buf,lev+2,off+len, &leng,
405 &res);
406 if (res)
407 goto ERROR1;
295 len += leng; 408 len += leng;
296 break; 409 break;
297 case 0x05: 410 case 0x05:
298 psiconv_progress(lev+3,off+len,"Going to read horizontal justify"); 411 psiconv_progress(lev+3,off+len,"Going to read horizontal justify");
299 temp = psiconv_read_u8(buf,lev+3,off+len); 412 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
413 if (res)
414 goto ERROR1;
300 if (temp == 0x00) 415 if (temp == 0x00)
301 result->justify_hor = psiconv_justify_left; 416 result->justify_hor = psiconv_justify_left;
302 else if (temp == 0x01) 417 else if (temp == 0x01)
303 result->justify_hor = psiconv_justify_centre; 418 result->justify_hor = psiconv_justify_centre;
304 else if (temp == 0x02) 419 else if (temp == 0x02)
305 result->justify_hor = psiconv_justify_right; 420 result->justify_hor = psiconv_justify_right;
306 else if (temp == 0x03) 421 else if (temp == 0x03)
307 result->justify_hor = psiconv_justify_full; 422 result->justify_hor = psiconv_justify_full;
308 else { 423 else {
309 res = -1;
310 psiconv_warn(lev+3,off+len, "Unknown horizontal justify argument " 424 psiconv_warn(lev+3,off+len, "Unknown horizontal justify argument "
311 "in paragraph layout codes list"); 425 "in paragraph layout codes list");
426 result->justify_hor = psiconv_justify_left;
312 } 427 }
313 psiconv_debug(lev+3,off+len,"Justify: %02x",temp); 428 psiconv_debug(lev+3,off+len,"Justify: %02x",temp);
314 len ++; 429 len ++;
315 break; 430 break;
316 case 0x06: 431 case 0x06:
317 psiconv_progress(lev+3,off+len,"Going to read vertical justify"); 432 psiconv_progress(lev+3,off+len,"Going to read vertical justify");
318 temp = psiconv_read_u8(buf,lev+3,off+len); 433 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
434 if (res)
435 goto ERROR1;
319 if (temp == 0x00) 436 if (temp == 0x00)
320 result->justify_ver = psiconv_justify_top; 437 result->justify_ver = psiconv_justify_top;
321 else if (temp == 0x01) 438 else if (temp == 0x01)
322 result->justify_ver = psiconv_justify_middle; 439 result->justify_ver = psiconv_justify_middle;
323 else if (temp == 0x02) 440 else if (temp == 0x02)
324 result->justify_ver = psiconv_justify_bottom; 441 result->justify_ver = psiconv_justify_bottom;
325 else { 442 else {
326 res = -1;
327 psiconv_warn(lev+3,off+len, "Unknown vertical justify argument " 443 psiconv_warn(lev+3,off+len, "Unknown vertical justify argument "
328 "in paragraph layout codes list"); 444 "in paragraph layout codes list");
445 result->justify_ver = psiconv_justify_bottom;
329 } 446 }
330 psiconv_debug(lev+3,off+len,"Justify: %02x",temp); 447 psiconv_debug(lev+3,off+len,"Justify: %02x",temp);
331 len ++; 448 len ++;
332 case 0x07: 449 case 0x07:
333 psiconv_progress(lev+3,off+len,"Going to read interline distance"); 450 psiconv_progress(lev+3,off+len,"Going to read interline distance");
334 result->interline = psiconv_read_size(buf,lev+3,off+len,&leng); 451 result->interline = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
452 if (res)
453 goto ERROR1;
335 len += leng; 454 len += leng;
336 break; 455 break;
337 case 0x08: 456 case 0x08:
338 psiconv_progress(lev+3,off+len,"Going to read interline exact"); 457 psiconv_progress(lev+3,off+len,"Going to read interline exact");
339 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 458 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
340 &result->interline_exact); 459 &result->interline_exact)))
460 goto ERROR1;
341 len += leng; 461 len += leng;
342 break; 462 break;
343 case 0x09: 463 case 0x09:
344 psiconv_progress(lev+3,off+len,"Going to read top space"); 464 psiconv_progress(lev+3,off+len,"Going to read top space");
345 result->top_space = psiconv_read_size(buf,lev+3,off+len,&leng); 465 result->top_space = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
466 if (res)
467 goto ERROR1;
346 len += leng; 468 len += leng;
347 break; 469 break;
348 case 0x0a: 470 case 0x0a:
349 psiconv_progress(lev+3,off+len,"Going to read bottom space"); 471 psiconv_progress(lev+3,off+len,"Going to read bottom space");
350 result->bottom_space = psiconv_read_size(buf,lev+3,off+len,&leng); 472 result->bottom_space = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
473 if (res)
474 goto ERROR1;
351 len += leng; 475 len += leng;
352 break; 476 break;
353 case 0x0b: 477 case 0x0b:
354 psiconv_progress(lev+3,off+len,"Going to read on one page"); 478 psiconv_progress(lev+3,off+len,"Going to read on one page");
355 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 479 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
356 &result->on_one_page); 480 &result->on_one_page)))
481 goto ERROR1;
357 len += leng; 482 len += leng;
358 break; 483 break;
359 case 0x0c: 484 case 0x0c:
360 psiconv_progress(lev+3,off+len,"Going to read together with"); 485 psiconv_progress(lev+3,off+len,"Going to read together with");
361 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 486 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
362 &result->together_with); 487 &result->together_with)))
488 goto ERROR1;
363 len += leng; 489 len += leng;
364 break; 490 break;
365 case 0x0d: 491 case 0x0d:
366 psiconv_progress(lev+3,off+len,"Going to read on next page"); 492 psiconv_progress(lev+3,off+len,"Going to read on next page");
367 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 493 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
368 &result->on_next_page); 494 &result->on_next_page)))
495 goto ERROR1;
369 len += leng; 496 len += leng;
370 break; 497 break;
371 case 0x0e: 498 case 0x0e:
372 psiconv_progress(lev+3,off+len,"Going to read no widow protection"); 499 psiconv_progress(lev+3,off+len,"Going to read no widow protection");
373 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, 500 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
374 &result->no_widow_protection); 501 &result->no_widow_protection)))
502 goto ERROR1;
375 len += leng; 503 len += leng;
376 break; 504 break;
377 case 0x10: 505 case 0x10:
378 psiconv_progress(lev+3,off+len,"Going to read border distance to text"); 506 psiconv_progress(lev+3,off+len,"Going to read border distance to text");
379 result->border_distance = psiconv_read_length(buf,lev+3, 507 result->border_distance = psiconv_read_length(buf,lev+3,
380 off+len,&leng); 508 off+len,&leng,&res);
509 if (res)
510 goto ERROR1;
381 len += leng; 511 len += leng;
382 break; 512 break;
383 case 0x11: 513 case 0x11:
384 psiconv_progress(lev+3,off+len,"Going to read top border"); 514 psiconv_progress(lev+3,off+len,"Going to read top border");
515 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
516 goto ERROR1;
385 psiconv_free_border(result->top_border); 517 psiconv_free_border(result->top_border);
386 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 518 result->top_border = temp_border;
387 &result->top_border);
388 len += leng; 519 len += leng;
389 break; 520 break;
390 case 0x12: 521 case 0x12:
391 psiconv_progress(lev+3,off+len,"Going to read bottom border"); 522 psiconv_progress(lev+3,off+len,"Going to read bottom border");
523 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
524 goto ERROR1;
392 psiconv_free_border(result->bottom_border); 525 psiconv_free_border(result->bottom_border);
393 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 526 result->bottom_border = temp_border;
394 &result->bottom_border);
395 len += leng; 527 len += leng;
396 break; 528 break;
397 case 0x13: 529 case 0x13:
398 psiconv_progress(lev+3,off+len,"Going to read left border"); 530 psiconv_progress(lev+3,off+len,"Going to read left border");
531 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
532 goto ERROR1;
399 psiconv_free_border(result->left_border); 533 psiconv_free_border(result->left_border);
400 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 534 result->left_border = temp_border;
401 &result->left_border);
402 len += leng; 535 len += leng;
403 break; 536 break;
404 case 0x14: 537 case 0x14:
405 psiconv_progress(lev+3,off+len,"Going to read right border"); 538 psiconv_progress(lev+3,off+len,"Going to read right border");
539 if ((res = psiconv_parse_border(buf,lev+3,off+len,&leng,&temp_border)))
540 goto ERROR1;
406 psiconv_free_border(result->right_border); 541 psiconv_free_border(result->right_border);
407 res |= psiconv_parse_border(buf,lev+3,off+len,&leng, 542 result->right_border = temp_border;
408 &result->right_border);
409 len += leng; 543 len += leng;
410 break; 544 break;
411 case 0x15: 545 case 0x15:
412 psiconv_progress(lev+3,off+len,"Going to read bullet"); 546 psiconv_progress(lev+3,off+len,"Going to read bullet");
547 if ((res = psiconv_parse_bullet(buf,lev+3,off+len,&leng,&temp_bullet)));
548 goto ERROR1;
413 psiconv_free_bullet(result->bullet); 549 psiconv_free_bullet(result->bullet);
414 res |= psiconv_parse_bullet(buf,lev+3,off+len,&leng, 550 result->bullet = temp_bullet;
415 &result->bullet);
416 len += leng; 551 len += leng;
417 break; 552 break;
418 case 0x16: 553 case 0x16:
419 psiconv_progress(lev+3,off+len,"Going to read standard tabs"); 554 psiconv_progress(lev+3,off+len,"Going to read standard tabs");
420 result->tabs->normal = psiconv_read_length(buf,lev+3,off+len,&leng); 555 result->tabs->normal = psiconv_read_length(buf,lev+3,off+len,&leng,
556 &res);
557 if (res)
558 goto ERROR1;
421 len += leng; 559 len += leng;
422 break; 560 break;
423 case 0x17: 561 case 0x17:
424 psiconv_progress(lev+3,off+len,"Going to read extra tab"); 562 psiconv_progress(lev+3,off+len,"Going to read extra tab");
425 res |= psiconv_parse_tab(buf,lev+3,off+len,&leng,&tab); 563 if ((res = psiconv_parse_tab(buf,lev+3,off+len,&leng,&temp_tab)))
564 goto ERROR1;
426 psiconv_list_add(result->tabs->extras,tab); 565 if ((res = psiconv_list_add(result->tabs->extras,temp_tab))) {
566 psiconv_free_tab(temp_tab);
567 goto ERROR1;
568 }
427 len += leng; 569 len += leng;
428 break; 570 break;
429 default: 571 default:
430 psiconv_warn(lev+3,off+len, 572 psiconv_warn(lev+3,off+len,
431 "Unknown code in paragraph layout codes list"); 573 "Unknown code in paragraph layout codes list");
432 psiconv_debug(lev+3,off+len,"Code: %02x",id); 574 psiconv_debug(lev+3,off+len,"Code: %02x",id);
433 len ++; 575 len ++;
434 res = -1;
435 break; 576 break;
436 } 577 }
437 nr ++; 578 nr ++;
438 } 579 }
439 580
441 psiconv_warn(lev+2,off+len, 582 psiconv_warn(lev+2,off+len,
442 "Read past end of paragraph layout codes list. I probably lost track" 583 "Read past end of paragraph layout codes list. I probably lost track"
443 "somewhere!"); 584 "somewhere!");
444 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", 585 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d",
445 len-4,list_length); 586 len-4,list_length);
587 res = PSICONV_E_PARSE;
588 goto ERROR1;
446 } 589 }
447 590
448 len = list_length + 4; 591 len = list_length + 4;
449 592
450 psiconv_progress(lev+1,off+len, 593 psiconv_progress(lev+1,off+len,
451 "End of paragraph layout list (total length: %08x)",len); 594 "End of paragraph layout list (total length: %08x)",len);
452 595
453 if (length) 596 if (length)
454 *length = len; 597 *length = len;
598 return 0;
599
600ERROR1:
601 psiconv_warn(lev+1,off,"Reading of paragraph_layout_list failed");
602 if (length)
603 *length = 0;
604 if (!res)
605 return -PSICONV_E_NOMEM;
606 else
455 return res; 607 return res;
456} 608}
457 609
458int psiconv_parse_character_layout_list(const psiconv_buffer buf, int lev, 610int psiconv_parse_character_layout_list(const psiconv_buffer buf, int lev,
459 psiconv_u32 off, int *length, 611 psiconv_u32 off, int *length,
460 psiconv_character_layout result) 612 psiconv_character_layout result)
462 int res=0; 614 int res=0;
463 int len=0; 615 int len=0;
464 int list_length,leng,nr; 616 int list_length,leng,nr;
465 psiconv_u8 id; 617 psiconv_u8 id;
466 psiconv_u32 temp; 618 psiconv_u32 temp;
619 psiconv_color temp_color;
620 psiconv_font temp_font;
467 621
468 psiconv_progress(lev+1,off,"Going to read character layout codes"); 622 psiconv_progress(lev+1,off,"Going to read character layout codes");
469 623
470 psiconv_progress(lev+2,off,"Going to read the list length"); 624 psiconv_progress(lev+2,off,"Going to read the list length");
471 list_length = psiconv_read_u32(buf,lev+2,off + len); 625 list_length = psiconv_read_u32(buf,lev+2,off + len,&res);
626 if (res)
627 goto ERROR1;
472 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); 628 psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length);
473 len += 4; 629 len += 4;
474 630
475 nr = 0; 631 nr = 0;
476 while(len-4 < list_length) { 632 while(len-4 < list_length) {
477 psiconv_progress(lev+2,off+len,"Going to read element %d",nr); 633 psiconv_progress(lev+2,off+len,"Going to read element %d",nr);
478 psiconv_progress(lev+3,off+len,"Going to read the element id"); 634 psiconv_progress(lev+3,off+len,"Going to read the element id");
479 id = psiconv_read_u8(buf,lev+2,off+len); 635 id = psiconv_read_u8(buf,lev+2,off+len,&res);
636 if (res)
637 goto ERROR1;
480 psiconv_debug(lev+3,off+len,"Id: %02x",id); 638 psiconv_debug(lev+3,off+len,"Id: %02x",id);
481 len ++; 639 len ++;
482 switch(id) { 640 switch(id) {
483 case 0x19: 641 case 0x19:
484 psiconv_progress(lev+3,off+len,"Going to read text color"); 642 psiconv_progress(lev+3,off+len,"Going to read text color");
643 if ((res = psiconv_parse_color(buf,lev+3,off+len, &leng,&temp_color)))
644 goto ERROR1;
485 psiconv_free_color(result->color); 645 psiconv_free_color(result->color);
486 res |= psiconv_parse_color(buf,lev+3,off+len, &leng,&result->color); 646 result->color = temp_color;
487 len += leng; 647 len += leng;
488 break; 648 break;
489 case 0x1a: 649 case 0x1a:
490 psiconv_progress(lev+3,off+len,"Going to read background color (?)"); 650 psiconv_progress(lev+3,off+len,"Going to read background color (?)");
651 if ((res = psiconv_parse_color(buf,lev+2,off+len, &leng,&temp_color)))
652 goto ERROR1;
491 psiconv_free_color(result->back_color); 653 psiconv_free_color(result->back_color);
492 res |= psiconv_parse_color(buf,lev+2,off+len, &leng, 654 result->back_color = temp_color;
493 &result->back_color);
494 len += leng; 655 len += leng;
495 break; 656 break;
496 case 0x1c: 657 case 0x1c:
497 psiconv_progress(lev+3,off+len,"Going to read font size"); 658 psiconv_progress(lev+3,off+len,"Going to read font size");
498 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng); 659 result->font_size = psiconv_read_size(buf,lev+3,off+len,&leng,&res);
660 if (res)
661 goto ERROR1;
499 len += leng; 662 len += leng;
500 break; 663 break;
501 case 0x1d: 664 case 0x1d:
502 psiconv_progress(lev+3,off+len,"Going to read italic"); 665 psiconv_progress(lev+3,off+len,"Going to read italic");
503 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->italic); 666 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->italic)))
667 goto ERROR1;
504 len += leng; 668 len += leng;
505 break; 669 break;
506 case 0x1e: 670 case 0x1e:
507 psiconv_progress(lev+3,off+len,"Going to read bold"); 671 psiconv_progress(lev+3,off+len,"Going to read bold");
508 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->bold); 672 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->bold)))
673 goto ERROR1;
509 len += leng; 674 len += leng;
510 break; 675 break;
511 case 0x1f: 676 case 0x1f:
512 psiconv_progress(lev+3,off+len,"Going to read super_sub"); 677 psiconv_progress(lev+3,off+len,"Going to read super_sub");
513 temp = psiconv_read_u8(buf,lev+3,off+len); 678 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
679 if (res)
680 goto ERROR1;
514 if (temp == 0x00) 681 if (temp == 0x00)
515 result->super_sub = psiconv_normalscript; 682 result->super_sub = psiconv_normalscript;
516 else if (temp == 0x01) 683 else if (temp == 0x01)
517 result->super_sub = psiconv_superscript; 684 result->super_sub = psiconv_superscript;
518 else if (temp == 0x02) 685 else if (temp == 0x02)
519 result->super_sub = psiconv_subscript; 686 result->super_sub = psiconv_subscript;
520 else { 687 else {
521 psiconv_warn(lev+3,off+len, 688 psiconv_warn(lev+3,off+len,
522 "Unknown super_sub argument in character layout codes list"); 689 "Unknown super_sub argument in character layout codes list");
523 res = -1;
524 } 690 }
525 psiconv_debug(lev+3,off+len,"Super_sub: %02x",temp); 691 psiconv_debug(lev+3,off+len,"Super_sub: %02x",temp);
526 len ++; 692 len ++;
527 break; 693 break;
528 case 0x20: 694 case 0x20:
529 psiconv_progress(lev+3,off+len,"Going to read underline"); 695 psiconv_progress(lev+3,off+len,"Going to read underline");
530 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->underline); 696 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
697 &result->underline)))
698 goto ERROR1;
531 len += leng; 699 len += leng;
532 break; 700 break;
533 case 0x21: 701 case 0x21:
534 psiconv_progress(lev+3,off+len,"Going to read strike_out"); 702 psiconv_progress(lev+3,off+len,"Going to read strike_out");
535 res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->strike_out); 703 if ((res = psiconv_parse_bool(buf,lev+3,off+len,&leng,
704 &result->strike_out)))
705 goto ERROR1;
536 len += leng; 706 len += leng;
537 break; 707 break;
538 case 0x22: 708 case 0x22:
539 psiconv_progress(lev+3,off+len,"Going to read font"); 709 psiconv_progress(lev+3,off+len,"Going to read font");
710 if ((res = psiconv_parse_font(buf,lev+3,off+len, &leng, &temp_font)))
711 goto ERROR1;
540 psiconv_free_font(result->font); 712 psiconv_free_font(result->font);
541 res |= psiconv_parse_font(buf,lev+3,off+len, &leng, &result->font); 713 result->font = temp_font;
542 len += leng; 714 len += leng;
543 break; 715 break;
544 case 0x24: 716 case 0x24:
545 psiconv_progress(lev+3,off+len, 717 psiconv_progress(lev+3,off+len,
546 "Going to read unknown code 0x24 (%02x expected)", 0); 718 "Going to read unknown code 0x24 (%02x expected)", 0);
547 temp = psiconv_read_u8(buf,lev+3,off+len); 719 temp = psiconv_read_u8(buf,lev+3,off+len,&res);
720 if (res)
721 goto ERROR1;
548 if (temp != 0) { 722 if (temp != 0) {
549 psiconv_warn(lev+3,off+len, 723 psiconv_warn(lev+3,off+len,
550 "Unknown code 0x24 value != 0x0 (0x%02x)", temp); 724 "Unknown code 0x24 value != 0x0 (0x%02x)", temp);
551 } 725 }
552 len ++; 726 len ++;
553 break; 727 break;
554 default: 728 default:
555 psiconv_warn(lev+3,off+len,"Unknown code in character layout list"); 729 psiconv_warn(lev+3,off+len,"Unknown code in character layout list");
556 psiconv_debug(lev+3,off+len,"Code: %02x",id); 730 psiconv_debug(lev+3,off+len,"Code: %02x",id);
557 len ++; 731 len ++;
558 res = -1;
559 break; 732 break;
560 } 733 }
561 nr ++; 734 nr ++;
562 } 735 }
563 736
565 psiconv_warn(lev+2,off+len, 738 psiconv_warn(lev+2,off+len,
566 "Read past end of character layout codes list. I probably lost track" 739 "Read past end of character layout codes list. I probably lost track"
567 "somewhere!"); 740 "somewhere!");
568 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", 741 psiconv_debug(lev+2,off+len,"Read %d characters instead of %d",
569 len-4,list_length); 742 len-4,list_length);
743 res = PSICONV_E_PARSE;
744 goto ERROR1;
570 } 745 }
571 746
572 len = list_length + 4; 747 len = list_length + 4;
573 748
574 psiconv_progress(lev+1,off+len, 749 psiconv_progress(lev+1,off+len,
575 "End of character layout list (total length: %08x)",len); 750 "End of character layout list (total length: %08x)",len);
576 751
577 if (length) 752 if (length)
578 *length = len; 753 *length = len;
579 return res; 754 return res;
755
756ERROR1:
757 psiconv_warn(lev+1,off,"Reading of character_layout_list failed");
758 if (length)
759 *length = 0;
760 if (!res)
761 return -PSICONV_E_NOMEM;
762 else
763 return res;
580} 764}

Legend:
Removed from v.63  
changed lines
  Added in v.64

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26