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