/[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 168 Revision 270
1/* 1/*
2 parse_layout.c - Part of psiconv, a PSION 5 file formats converter 2 parse_layout.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999-2005 Frodo Looijaard <frodo@frodo.looijaard.name>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
62 return 0; 62 return 0;
63 63
64ERROR2: 64ERROR2:
65 free(*result); 65 free(*result);
66ERROR1: 66ERROR1:
67 psiconv_warn(config,lev+1,off,"Reading of Color failed"); 67 psiconv_error(config,lev+1,off,"Reading of Color failed");
68 if (length) 68 if (length)
69 *length = 0; 69 *length = 0;
70 if (res == 0) 70 if (res == 0)
71 return -PSICONV_E_NOMEM; 71 return -PSICONV_E_NOMEM;
72 else 72 else
78int psiconv_parse_font(const psiconv_config config, 78int psiconv_parse_font(const psiconv_config config,
79 const psiconv_buffer buf, int lev, psiconv_u32 off, 79 const psiconv_buffer buf, int lev, psiconv_u32 off,
80 int *length, psiconv_font *result) 80 int *length, psiconv_font *result)
81{ 81{
82 int res = 0; 82 int res = 0;
83 int strlength,i;
84 char *str_copy; 83 char *str_copy;
85 int len; 84 int len=0;
85 int fontlen;
86 86
87 psiconv_progress(config,lev+1,off,"Going to parse font"); 87 psiconv_progress(config,lev+1,off,"Going to parse font");
88 if (!(*result = malloc(sizeof(**result)))) 88 if (!(*result = malloc(sizeof(**result))))
89 goto ERROR1; 89 goto ERROR1;
90 90
91 strlength = psiconv_read_u8(config,buf,lev+2,off,&res); 91 fontlen = psiconv_read_u8(config,buf,lev+2,off,&res);
92 if (res) 92 if (res)
93 goto ERROR2; 93 goto ERROR2;
94 if (!((*result)->name = malloc(strlength))) { 94 len = 1;
95
96 (*result)->name = psiconv_read_charlist(config,buf,lev+2,off+len, fontlen-1,&res);
97 if (res)
95 goto ERROR2; 98 goto ERROR2;
96 } 99 len += fontlen - 1;
97 for (i = 0; (i < strlength-1) && !res; i++) 100
98 (*result)->name[i] = psiconv_read_u8(config,buf,lev+2,off + 1 + i,&res); 101 (*result)->screenfont = psiconv_read_u8(config,buf,lev+2,off+len,&res);
99 if (res) 102 if (res)
100 goto ERROR3; 103 goto ERROR3;
101 (*result)->name[strlength-1] = 0; 104
102 (*result)->screenfont = psiconv_read_u8(config,buf,lev+2,off + strlength,&res); 105 if (!(str_copy = psiconv_make_printable(config,(*result)->name)))
103 if (res)
104 goto ERROR3; 106 goto ERROR3;
105 107
106 if (!(str_copy = psiconv_make_printable((*result)->name))) 108 psiconv_debug(config,lev+2,off+len,
107 goto ERROR3; 109 "Found font `%s', displayed with screen font %02x",
108
109 psiconv_debug(config,lev+2,off+1,"Found font `%s', displayed with screen font %02x",
110 str_copy,(*result)->screenfont); 110 str_copy,(*result)->screenfont);
111 free(str_copy); 111 free(str_copy);
112 len = strlength + 1; 112 len ++;
113
113 if (length) 114 if (length)
114 *length = len; 115 *length = len;
115 116
116 psiconv_progress(config,lev+1,off + len - 1,"End of font (total length: %08x)",len); 117 psiconv_progress(config,lev+1,off + len - 1,
118 "End of font (total length: %08x)",len);
117 return 0; 119 return 0;
118 120
119ERROR3: 121ERROR3:
120 free ((*result)->name); 122 free ((*result)->name);
121ERROR2: 123ERROR2:
122 free (*result); 124 free (*result);
123ERROR1: 125ERROR1:
124 psiconv_warn(config,lev+1,off,"Reading of Font failed"); 126 psiconv_error(config,lev+1,off,"Reading of Font failed");
125 if (length) 127 if (length)
126 *length = 0; 128 *length = 0;
127 if (!res) 129 if (!res)
128 return -PSICONV_E_NOMEM; 130 return -PSICONV_E_NOMEM;
129 else 131 else
214ERROR3: 216ERROR3:
215 psiconv_free_color((*result)->color); 217 psiconv_free_color((*result)->color);
216ERROR2: 218ERROR2:
217 free (result); 219 free (result);
218ERROR1: 220ERROR1:
219 psiconv_warn(config,lev+1,off,"Reading of Border failed"); 221 psiconv_error(config,lev+1,off,"Reading of Border failed");
220 if (length) 222 if (length)
221 *length = 0; 223 *length = 0;
222 if (!res) 224 if (!res)
223 return -PSICONV_E_NOMEM; 225 return -PSICONV_E_NOMEM;
224 else 226 else
251 if (res) 253 if (res)
252 goto ERROR2; 254 goto ERROR2;
253 len +=leng; 255 len +=leng;
254 256
255 psiconv_progress(config,lev+2,off+len,"Going to read bullet character"); 257 psiconv_progress(config,lev+2,off+len,"Going to read bullet character");
256 (*result)->character = psiconv_read_u8(config,buf,lev+2,off+len,&res); 258 (*result)->character = psiconv_unicode_read_char(config,buf,lev+2,
259 off+len,&leng,&res);
257 if (res) 260 if (res)
258 goto ERROR2; 261 goto ERROR2;
259 psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character); 262 psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character);
260 len ++; 263 len += leng;
261 264
262 psiconv_progress(config,lev+2,off+len,"Going to read indent on/off"); 265 psiconv_progress(config,lev+2,off+len,"Going to read indent on/off");
263 if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,&(*result)->indent))) 266 if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,&(*result)->indent)))
264 goto ERROR2; 267 goto ERROR2;
265 psiconv_debug(config,lev+2,off+len,"Indent on: %02x",(*result)->indent); 268 psiconv_debug(config,lev+2,off+len,"Indent on: %02x",(*result)->indent);
291ERROR3: 294ERROR3:
292 psiconv_free_color((*result)->color); 295 psiconv_free_color((*result)->color);
293ERROR2: 296ERROR2:
294 free (result); 297 free (result);
295ERROR1: 298ERROR1:
296 psiconv_warn(config,lev+1,off,"Reading of Bullet failed"); 299 psiconv_error(config,lev+1,off,"Reading of Bullet failed");
297 if (length) 300 if (length)
298 *length = 0; 301 *length = 0;
299 if (!res) 302 if (!res)
300 return -PSICONV_E_NOMEM; 303 return -PSICONV_E_NOMEM;
301 else 304 else
347 return 0; 350 return 0;
348 351
349ERROR2: 352ERROR2:
350 free (result); 353 free (result);
351ERROR1: 354ERROR1:
352 psiconv_warn(config,lev+1,off,"Reading of Tab failed"); 355 psiconv_error(config,lev+1,off,"Reading of Tab failed");
353 if (length) 356 if (length)
354 *length = 0; 357 *length = 0;
355 if (!res) 358 if (!res)
356 return -PSICONV_E_NOMEM; 359 return -PSICONV_E_NOMEM;
357 else 360 else
602 } 605 }
603 nr ++; 606 nr ++;
604 } 607 }
605 608
606 if (len - 4 != list_length) { 609 if (len - 4 != list_length) {
607 psiconv_warn(config,lev+2,off+len, 610 psiconv_error(config,lev+2,off+len,
608 "Read past end of paragraph layout codes list. I probably lost track" 611 "Read past end of paragraph layout codes list. I probably lost track "
609 "somewhere!"); 612 "somewhere!");
610 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d", 613 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
611 len-4,list_length); 614 len-4,list_length);
612 res = PSICONV_E_PARSE; 615 res = PSICONV_E_PARSE;
613 goto ERROR1; 616 goto ERROR1;
621 if (length) 624 if (length)
622 *length = len; 625 *length = len;
623 return 0; 626 return 0;
624 627
625ERROR1: 628ERROR1:
626 psiconv_warn(config,lev+1,off,"Reading of paragraph_layout_list failed"); 629 psiconv_error(config,lev+1,off,"Reading of paragraph_layout_list failed");
627 if (length) 630 if (length)
628 *length = 0; 631 *length = 0;
629 if (!res) 632 if (!res)
630 return -PSICONV_E_NOMEM; 633 return -PSICONV_E_NOMEM;
631 else 634 else
771 } 774 }
772 nr ++; 775 nr ++;
773 } 776 }
774 777
775 if (len - 4 != list_length) { 778 if (len - 4 != list_length) {
776 psiconv_warn(config,lev+2,off+len, 779 psiconv_error(config,lev+2,off+len,
777 "Read past end of character layout codes list. I probably lost track" 780 "Read past end of character layout codes list. I probably lost track "
778 "somewhere!"); 781 "somewhere!");
779 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d", 782 psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d",
780 len-4,list_length); 783 len-4,list_length);
781 res = PSICONV_E_PARSE; 784 res = PSICONV_E_PARSE;
782 goto ERROR1; 785 goto ERROR1;
790 if (length) 793 if (length)
791 *length = len; 794 *length = len;
792 return res; 795 return res;
793 796
794ERROR1: 797ERROR1:
795 psiconv_warn(config,lev+1,off,"Reading of character_layout_list failed"); 798 psiconv_error(config,lev+1,off,"Reading of character_layout_list failed");
796 if (length) 799 if (length)
797 *length = 0; 800 *length = 0;
798 if (!res) 801 if (!res)
799 return -PSICONV_E_NOMEM; 802 return -PSICONV_E_NOMEM;
800 else 803 else

Legend:
Removed from v.168  
changed lines
  Added in v.270

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