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-2004 Frodo Looijaard <frodol@dds.nl> |
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 | |
64 | ERROR2: |
64 | ERROR2: |
65 | free(*result); |
65 | free(*result); |
66 | ERROR1: |
66 | ERROR1: |
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 |
… | |
… | |
80 | int *length, psiconv_font *result) |
80 | int *length, psiconv_font *result) |
81 | { |
81 | { |
82 | int res = 0; |
82 | int res = 0; |
83 | char *str_copy; |
83 | char *str_copy; |
84 | int len=0; |
84 | int len=0; |
85 | int leng; |
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 | fontlen = psiconv_read_u8(config,buf,lev+2,off,&res); |
|
|
92 | if (res) |
|
|
93 | goto ERROR2; |
|
|
94 | len = 1; |
|
|
95 | |
91 | (*result)->name = psiconv_read_short_string(config,buf,lev+2,off+len, |
96 | (*result)->name = psiconv_read_charlist(config,buf,lev+2,off, fontlen-1,&res); |
92 | &leng,&res); |
|
|
93 | if (res) |
97 | if (res) |
94 | goto ERROR2; |
98 | goto ERROR2; |
95 | len += leng; |
99 | len += fontlen - 1; |
96 | |
100 | |
97 | (*result)->screenfont = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
101 | (*result)->screenfont = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
98 | if (res) |
102 | if (res) |
99 | goto ERROR3; |
103 | goto ERROR3; |
100 | |
104 | |
101 | if (!(str_copy = psiconv_make_printable((*result)->name))) |
105 | if (!(str_copy = psiconv_make_printable(config,(*result)->name))) |
102 | goto ERROR3; |
106 | goto ERROR3; |
103 | |
107 | |
104 | psiconv_debug(config,lev+2,off+len, |
108 | psiconv_debug(config,lev+2,off+len, |
105 | "Found font `%s', displayed with screen font %02x", |
109 | "Found font `%s', displayed with screen font %02x", |
106 | str_copy,(*result)->screenfont); |
110 | str_copy,(*result)->screenfont); |
… | |
… | |
117 | ERROR3: |
121 | ERROR3: |
118 | free ((*result)->name); |
122 | free ((*result)->name); |
119 | ERROR2: |
123 | ERROR2: |
120 | free (*result); |
124 | free (*result); |
121 | ERROR1: |
125 | ERROR1: |
122 | psiconv_warn(config,lev+1,off,"Reading of Font failed"); |
126 | psiconv_error(config,lev+1,off,"Reading of Font failed"); |
123 | if (length) |
127 | if (length) |
124 | *length = 0; |
128 | *length = 0; |
125 | if (!res) |
129 | if (!res) |
126 | return -PSICONV_E_NOMEM; |
130 | return -PSICONV_E_NOMEM; |
127 | else |
131 | else |
… | |
… | |
212 | ERROR3: |
216 | ERROR3: |
213 | psiconv_free_color((*result)->color); |
217 | psiconv_free_color((*result)->color); |
214 | ERROR2: |
218 | ERROR2: |
215 | free (result); |
219 | free (result); |
216 | ERROR1: |
220 | ERROR1: |
217 | psiconv_warn(config,lev+1,off,"Reading of Border failed"); |
221 | psiconv_error(config,lev+1,off,"Reading of Border failed"); |
218 | if (length) |
222 | if (length) |
219 | *length = 0; |
223 | *length = 0; |
220 | if (!res) |
224 | if (!res) |
221 | return -PSICONV_E_NOMEM; |
225 | return -PSICONV_E_NOMEM; |
222 | else |
226 | else |
… | |
… | |
249 | if (res) |
253 | if (res) |
250 | goto ERROR2; |
254 | goto ERROR2; |
251 | len +=leng; |
255 | len +=leng; |
252 | |
256 | |
253 | 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"); |
254 | (*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); |
255 | if (res) |
260 | if (res) |
256 | goto ERROR2; |
261 | goto ERROR2; |
257 | psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character); |
262 | psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character); |
258 | len ++; |
263 | len += leng; |
259 | |
264 | |
260 | 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"); |
261 | 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))) |
262 | goto ERROR2; |
267 | goto ERROR2; |
263 | 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); |
… | |
… | |
289 | ERROR3: |
294 | ERROR3: |
290 | psiconv_free_color((*result)->color); |
295 | psiconv_free_color((*result)->color); |
291 | ERROR2: |
296 | ERROR2: |
292 | free (result); |
297 | free (result); |
293 | ERROR1: |
298 | ERROR1: |
294 | psiconv_warn(config,lev+1,off,"Reading of Bullet failed"); |
299 | psiconv_error(config,lev+1,off,"Reading of Bullet failed"); |
295 | if (length) |
300 | if (length) |
296 | *length = 0; |
301 | *length = 0; |
297 | if (!res) |
302 | if (!res) |
298 | return -PSICONV_E_NOMEM; |
303 | return -PSICONV_E_NOMEM; |
299 | else |
304 | else |
… | |
… | |
345 | return 0; |
350 | return 0; |
346 | |
351 | |
347 | ERROR2: |
352 | ERROR2: |
348 | free (result); |
353 | free (result); |
349 | ERROR1: |
354 | ERROR1: |
350 | psiconv_warn(config,lev+1,off,"Reading of Tab failed"); |
355 | psiconv_error(config,lev+1,off,"Reading of Tab failed"); |
351 | if (length) |
356 | if (length) |
352 | *length = 0; |
357 | *length = 0; |
353 | if (!res) |
358 | if (!res) |
354 | return -PSICONV_E_NOMEM; |
359 | return -PSICONV_E_NOMEM; |
355 | else |
360 | else |
… | |
… | |
600 | } |
605 | } |
601 | nr ++; |
606 | nr ++; |
602 | } |
607 | } |
603 | |
608 | |
604 | if (len - 4 != list_length) { |
609 | if (len - 4 != list_length) { |
605 | psiconv_warn(config,lev+2,off+len, |
610 | psiconv_error(config,lev+2,off+len, |
606 | "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 " |
607 | "somewhere!"); |
612 | "somewhere!"); |
608 | 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", |
609 | len-4,list_length); |
614 | len-4,list_length); |
610 | res = PSICONV_E_PARSE; |
615 | res = PSICONV_E_PARSE; |
611 | goto ERROR1; |
616 | goto ERROR1; |
… | |
… | |
619 | if (length) |
624 | if (length) |
620 | *length = len; |
625 | *length = len; |
621 | return 0; |
626 | return 0; |
622 | |
627 | |
623 | ERROR1: |
628 | ERROR1: |
624 | 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"); |
625 | if (length) |
630 | if (length) |
626 | *length = 0; |
631 | *length = 0; |
627 | if (!res) |
632 | if (!res) |
628 | return -PSICONV_E_NOMEM; |
633 | return -PSICONV_E_NOMEM; |
629 | else |
634 | else |
… | |
… | |
769 | } |
774 | } |
770 | nr ++; |
775 | nr ++; |
771 | } |
776 | } |
772 | |
777 | |
773 | if (len - 4 != list_length) { |
778 | if (len - 4 != list_length) { |
774 | psiconv_warn(config,lev+2,off+len, |
779 | psiconv_error(config,lev+2,off+len, |
775 | "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 " |
776 | "somewhere!"); |
781 | "somewhere!"); |
777 | 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", |
778 | len-4,list_length); |
783 | len-4,list_length); |
779 | res = PSICONV_E_PARSE; |
784 | res = PSICONV_E_PARSE; |
780 | goto ERROR1; |
785 | goto ERROR1; |
… | |
… | |
788 | if (length) |
793 | if (length) |
789 | *length = len; |
794 | *length = len; |
790 | return res; |
795 | return res; |
791 | |
796 | |
792 | ERROR1: |
797 | ERROR1: |
793 | 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"); |
794 | if (length) |
799 | if (length) |
795 | *length = 0; |
800 | *length = 0; |
796 | if (!res) |
801 | if (!res) |
797 | return -PSICONV_E_NOMEM; |
802 | return -PSICONV_E_NOMEM; |
798 | else |
803 | else |