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

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

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

Revision 208 Revision 268
275 int res = 0; 275 int res = 0;
276 int len=0; 276 int len=0;
277 277
278 psiconv_u32 text_len; 278 psiconv_u32 text_len;
279 psiconv_paragraph para; 279 psiconv_paragraph para;
280 psiconv_u8 temp; 280 psiconv_ucs2 temp;
281 psiconv_list line;
281 282
282 int nr; 283 int nr;
283 int i,j,start,leng; 284 int i,leng;
284 char *str_copy; 285 char *str_copy;
285 286
286 psiconv_progress(config,lev+1,off,"Going to parse the text section"); 287 psiconv_progress(config,lev+1,off,"Going to parse the text section");
287 psiconv_progress(config,lev+2,off,"Reading the text length");
288 288
289 if(!(*result = psiconv_list_new(sizeof(*para)))) 289 if(!(*result = psiconv_list_new(sizeof(*para))))
290 goto ERROR1; 290 goto ERROR1;
291 if (!(para = malloc(sizeof(*para)))) 291 if (!(para = malloc(sizeof(*para))))
292 goto ERROR2; 292 goto ERROR2;
293 293
294 psiconv_progress(config,lev+2,off,"Reading the text length");
294 text_len = psiconv_read_X(config,buf,lev+2,off,&leng,&res); 295 text_len = psiconv_read_X(config,buf,lev+2,off,&leng,&res);
295 if (res) 296 if (res)
296 goto ERROR3; 297 goto ERROR3;
297 psiconv_debug(config,lev+2,off,"Length: %08x",text_len); 298 psiconv_debug(config,lev+2,off,"Length: %08x",text_len);
298 len += leng; 299 len += leng;
299 300
300 psiconv_progress(config,lev+2,off+len,"Going to read all paragraph text"); 301 if (!(line = psiconv_list_new(sizeof(psiconv_ucs2))))
302 goto ERROR3;
303
304 i = 0;
301 nr = 0; 305 nr = 0;
302 start = 0; 306 while (i < text_len) {
303 for (i = 0; i < text_len; i++) {
304 temp = psiconv_read_u8(config,buf,lev+2,off+len+i,&res); 307 temp = psiconv_unicode_read_char(config,buf,lev+2,off+len+i,&leng,&res);
305 if (res) 308 if (res)
306 goto ERROR3;
307 if (temp == 0x06) {
308 if (!(para->text = malloc((sizeof((*(para->text))) * (i - start + 1)))))
309 goto ERROR3;
310 for (j = 0; j < i - start; j++) {
311 temp = psiconv_read_u8(config,buf,lev+1,off + len + start + j,&res);
312 if (res)
313 goto ERROR4;
314 para->text[j] = psiconv_unicode_from_char(config,temp);
315 }
316 para->text[j] = 0;
317
318 if ((res = psiconv_list_add(*result,para)))
319 goto ERROR4; 309 goto ERROR4;
310 if (i + leng > text_len) {
311 psiconv_error(config,lev+2,off+len+i,"Malformed text section");
312 res = PSICONV_E_PARSE;
313 goto ERROR4;
314 }
315 if ((temp == 0x06) || (i + leng == text_len)) {
316 if (!(para->text = psiconv_unicode_from_list(line)))
317 goto ERROR4;
320 318
321 if (!(str_copy = psiconv_make_printable(config,para->text))) 319 if (!(str_copy = psiconv_make_printable(config,para->text)))
322 goto ERROR3; 320 goto ERROR5;
323 psiconv_debug(config,lev+2,off+i+len,"Line %d: %d characters",nr, 321 psiconv_debug(config,lev+2,off+i+len,"Line %d: %d characters",nr,
324 strlen(str_copy) +1); 322 strlen(str_copy) +1);
325 psiconv_debug(config,lev+2,off+i+len,"Line %d: `%s'",nr,str_copy); 323 psiconv_debug(config,lev+2,off+i+len,"Line %d: `%s'",nr,str_copy);
326 free(str_copy); 324 free(str_copy);
325 i += leng;
327 326
328 start = i + 1; 327 if (!(para->in_lines = psiconv_list_new(sizeof(
328 struct psiconv_in_line_layout_s))))
329 goto ERROR5;
330 if (!(para->replacements = psiconv_list_new(sizeof(
331 struct psiconv_replacement_s))))
332 goto ERROR6;
333 if (!(para->base_character = psiconv_basic_character_layout()))
334 goto ERROR7;
335 if (!(para->base_paragraph = psiconv_basic_paragraph_layout()))
336 goto ERROR8;
337 para->base_style = 0;
338
339 if ((res = psiconv_list_add(*result,para)))
340 goto ERROR9;
341 psiconv_progress(config,lev+2,off+len+i,"Starting a new line");
342 psiconv_list_empty(line);
329 nr ++; 343 nr ++;
344 } else {
345 if ((res = psiconv_list_add(line,&temp)))
346 goto ERROR4;
347 i += leng;
330 } 348 }
331 } 349 }
332 350
333 if (start != text_len) { 351 psiconv_list_free(line);
334 psiconv_warn(config,lev+2,off+start+len,
335 "Last line does not end on EOL (%d characters left)", len - start);
336 if (!(para->text = malloc(text_len - start + 1)))
337 goto ERROR3;
338 for (j = 0; j < text_len - start; j++) {
339 temp = psiconv_read_u8(config,buf,lev+2,off + start + j + len, &res);
340 if (res)
341 goto ERROR4;
342 para->text[j] = psiconv_unicode_from_char(config,temp);
343 }
344 para->text[text_len - start] = 0;
345 if ((res = psiconv_list_add(*result,para)))
346 goto ERROR4;
347 if (!(str_copy = psiconv_make_printable(config,para->text)))
348 goto ERROR3;
349 psiconv_debug(config,lev+2,off+start+len,"Last line: %d characters",nr,
350 strlen(str_copy)+1);
351 psiconv_debug(config,lev+2,off+start+len,"Last line: `%s'",str_copy);
352 free(str_copy);
353 }
354
355 free(para); 352 free(para);
356 353
357 /* Initialize the remaining parts of each paragraph */
358 for (i = 0; i < psiconv_list_length(*result); i ++) {
359 if (!(para = psiconv_list_get(*result,i))) {
360 psiconv_error(config,lev+2,off+len,"Massive memory corruption");
361 goto ERROR2_0;
362 }
363 if (!(para->in_lines = psiconv_list_new(sizeof(
364 struct psiconv_in_line_layout_s))))
365 goto ERROR2_0;
366 if (!(para->replacements = psiconv_list_new(sizeof(
367 struct psiconv_replacement_s))))
368 goto ERROR2_1;
369 if (!(para->base_character = psiconv_basic_character_layout()))
370 goto ERROR2_2;
371 if (!(para->base_paragraph = psiconv_basic_paragraph_layout()))
372 goto ERROR2_3;
373 para->base_style = 0;
374 }
375
376
377 len += text_len; 354 len += text_len;
378 355
379 if (length) 356 if (length)
380 *length = len; 357 *length = len;
381 358
382 psiconv_progress(config,lev+1,off+len-1,"End of text section (total length: %08x", 359 psiconv_progress(config,lev+1,off+len-1,
383 len); 360 "End of text section (total length: %08x", len);
384 361
385 return res; 362 return res;
386 363
387ERROR2_3: 364ERROR9:
365 psiconv_free_paragraph_layout(para->base_paragraph);
366ERROR8:
388 psiconv_free_character_layout(para->base_character); 367 psiconv_free_character_layout(para->base_character);
389ERROR2_2: 368ERROR7:
390 psiconv_list_free(para->replacements); 369 psiconv_list_free(para->replacements);
391ERROR2_1: 370ERROR6:
392 psiconv_list_free(para->in_lines); 371 psiconv_list_free(para->in_lines);
393ERROR2_0: 372ERROR5:
394 for (j = 0; j < i; j++) { 373 free(para->text);
395 if (!(para = psiconv_list_get(*result,j))) {
396 psiconv_error(config,lev+1,off,"Massive memory corruption...");
397 break;
398 }
399 psiconv_list_free(para->in_lines);
400 psiconv_list_free(para->replacements);
401 psiconv_free_character_layout(para->base_character);
402 psiconv_free_paragraph_layout(para->base_paragraph);
403 }
404 goto ERROR2;
405
406ERROR4: 374ERROR4:
407 free(para->text); 375 psiconv_list_free(line);
408ERROR3: 376ERROR3:
409 free(para); 377 free(para);
410ERROR2: 378ERROR2:
411 for (i = 0; i < psiconv_list_length(*result);i++) { 379 psiconv_free_text_and_layout(*result);
412 if (!(para = psiconv_list_get(*result,i))) {
413 psiconv_error(config,lev+1,off,"Massive memory corruption...");
414 break;
415 }
416 free(para->text);
417 }
418 psiconv_list_free(*result);
419ERROR1: 380ERROR1:
420 psiconv_error(config,lev+1,off,"Reading of Text Section failed"); 381 psiconv_error(config,lev+1,off,"Reading of Text Section failed");
421 if (length) 382 if (length)
422 *length = 0; 383 *length = 0;
423 if (!res) 384 if (!res)
607 goto ERROR4; 568 goto ERROR4;
608 if (temp != 0x00) { 569 if (temp != 0x00) {
609 psiconv_debug(config,lev+4,off+len,"Type: %02x",temp); 570 psiconv_debug(config,lev+4,off+len,"Type: %02x",temp);
610 for (j = 0; j < psiconv_list_length(anon_styles); j++) { 571 for (j = 0; j < psiconv_list_length(anon_styles); j++) {
611 if (!(anon_ptr = psiconv_list_get(anon_styles,j))) { 572 if (!(anon_ptr = psiconv_list_get(anon_styles,j))) {
612 psiconv_error(config,lev+4,off+len,"Massive memory curruption"); 573 psiconv_error(config,lev+4,off+len,"Data structure corruption");
613 goto ERROR4; 574 goto ERROR4;
614 } 575 }
615 if (temp == anon_ptr->nr) 576 if (temp == anon_ptr->nr)
616 break; 577 break;
617 } 578 }
713 psiconv_progress(config,lev+3,off+len, 674 psiconv_progress(config,lev+3,off+len,
714 "Going to read the text layout inline elements"); 675 "Going to read the text layout inline elements");
715 total = 0; 676 total = 0;
716 for (i = 0; i < psiconv_list_length(result); i++) { 677 for (i = 0; i < psiconv_list_length(result); i++) {
717 if (!(para = psiconv_list_get(result,i))) { 678 if (!(para = psiconv_list_get(result,i))) {
718 psiconv_error(config,lev+3,off+len,"Massive memory corruption"); 679 psiconv_error(config,lev+3,off+len,"Data structure corruption");
719 goto ERROR4; 680 goto ERROR4;
720 } 681 }
721 line_length = -1; 682 line_length = -1;
722 for (j = 0; j < inline_count[i]; j++) { 683 for (j = 0; j < inline_count[i]; j++) {
723 psiconv_progress(config,lev+3,off+len,"Element %d: Paragraph %d, element %d", 684 psiconv_progress(config,lev+3,off+len,"Element %d: Paragraph %d, element %d",
818 779
819 free(inline_count); 780 free(inline_count);
820 781
821 for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) { 782 for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) {
822 if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { 783 if (!(anon_ptr = psiconv_list_get(anon_styles,i))) {
823 psiconv_error(config,lev+4,off+len,"Massive memory corruption"); 784 psiconv_error(config,lev+4,off+len,"Data structure corruption");
824 goto ERROR2; 785 goto ERROR2;
825 } 786 }
826 psiconv_free_character_layout(anon_ptr->character); 787 psiconv_free_character_layout(anon_ptr->character);
827 psiconv_free_paragraph_layout(anon_ptr->paragraph); 788 psiconv_free_paragraph_layout(anon_ptr->paragraph);
828 } 789 }
860ERROR4: 821ERROR4:
861 free(inline_count); 822 free(inline_count);
862ERROR3: 823ERROR3:
863 for (i = 0; i < psiconv_list_length(anon_styles); i++) { 824 for (i = 0; i < psiconv_list_length(anon_styles); i++) {
864 if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { 825 if (!(anon_ptr = psiconv_list_get(anon_styles,i))) {
865 psiconv_error(config,lev+1,off,"Massive memory corruption"); 826 psiconv_error(config,lev+1,off,"Data structure corruption");
866 break; 827 break;
867 } 828 }
868 psiconv_free_paragraph_layout(anon_ptr->paragraph); 829 psiconv_free_paragraph_layout(anon_ptr->paragraph);
869 psiconv_free_character_layout(anon_ptr->character); 830 psiconv_free_character_layout(anon_ptr->character);
870 } 831 }
911 goto ERROR3; 872 goto ERROR3;
912 if (!(styles_section->normal->paragraph = 873 if (!(styles_section->normal->paragraph =
913 psiconv_clone_paragraph_layout(base_para))) 874 psiconv_clone_paragraph_layout(base_para)))
914 goto ERROR4; 875 goto ERROR4;
915 styles_section->normal->hotkey = 0; 876 styles_section->normal->hotkey = 0;
916 if (( res = psiconv_unicode_from_chars(config,(psiconv_u8 *) "", 877
917 &styles_section->normal->name))) 878 if (!(styles_section->normal->name = psiconv_unicode_empty_string()))
918 goto ERROR5; 879 goto ERROR5;
919 if (!(styles_section->styles = psiconv_list_new(sizeof( 880 if (!(styles_section->styles = psiconv_list_new(sizeof(
920 struct psiconv_word_style_s)))) 881 struct psiconv_word_style_s))))
921 goto ERROR6; 882 goto ERROR6;
922 883
1263 1224
1264 psiconv_progress(config,lev+2,off+len,"Going to read the icon name"); 1225 psiconv_progress(config,lev+2,off+len,"Going to read the icon name");
1265 (*result)->icon_name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); 1226 (*result)->icon_name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res);
1266 if (res) 1227 if (res)
1267 goto ERROR2; 1228 goto ERROR2;
1268 psiconv_debug(config,lev+2,off+len,"Icon name: %s",(*result)->icon_name);
1269 len += leng; 1229 len += leng;
1270 1230
1271 psiconv_progress(config,lev+2,off+len,"Going to read the icon width"); 1231 psiconv_progress(config,lev+2,off+len,"Going to read the icon width");
1272 (*result)->icon_width = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res); 1232 (*result)->icon_width = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res);
1273 if (res) 1233 if (res)

Legend:
Removed from v.208  
changed lines
  Added in v.268

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