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-2014 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. |
… | |
… | |
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+len, 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; |
161 | |
238 | |
162 | *result = malloc(sizeof(**result)); |
239 | if (!(*result = malloc(sizeof(**result)))) |
|
|
240 | goto ERROR1; |
163 | (*result)->on = psiconv_bool_true; |
241 | (*result)->on = psiconv_bool_true; |
164 | |
242 | |
165 | psiconv_progress(lev+1,off,"Going to parse bullet data"); |
243 | psiconv_progress(config,lev+1,off,"Going to parse bullet data"); |
166 | psiconv_progress(lev+2,off+len,"Going to read bullet length"); |
244 | psiconv_progress(config,lev+2,off+len,"Going to read bullet length"); |
167 | bullet_length = psiconv_read_u8(buf,lev+2,off+len); |
245 | bullet_length = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
246 | if (res) |
|
|
247 | goto ERROR2; |
168 | psiconv_debug(lev+2,off+len,"Length: %02x",bullet_length); |
248 | psiconv_debug(config,lev+2,off+len,"Length: %02x",bullet_length); |
169 | len ++; |
249 | len ++; |
170 | |
250 | |
171 | psiconv_progress(lev+2,off+len,"Going to read bullet font size"); |
251 | 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); |
252 | (*result)->font_size = psiconv_read_size(config,buf,lev+2,off+len, &leng,&res); |
|
|
253 | if (res) |
|
|
254 | goto ERROR2; |
173 | len +=leng; |
255 | len +=leng; |
174 | |
256 | |
175 | psiconv_progress(lev+2,off+len,"Going to read bullet character"); |
257 | psiconv_progress(config,lev+2,off+len,"Going to read bullet character"); |
176 | (*result)->character = psiconv_read_u8(buf,lev+2,off+len); |
258 | (*result)->character = psiconv_unicode_read_char(config,buf,lev+2, |
|
|
259 | off+len,&leng,&res); |
|
|
260 | if (res) |
|
|
261 | goto ERROR2; |
177 | psiconv_debug(lev+2,off+len,"Character: %02x",(*result)->character); |
262 | psiconv_debug(config,lev+2,off+len,"Character: %02x",(*result)->character); |
178 | len ++; |
263 | len += leng; |
179 | |
264 | |
180 | psiconv_progress(lev+2,off+len,"Going to read indent on/off"); |
265 | 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); |
266 | if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,&(*result)->indent))) |
|
|
267 | goto ERROR2; |
182 | psiconv_debug(lev+2,off+len,"Indent on: %02x",(*result)->indent); |
268 | psiconv_debug(config,lev+2,off+len,"Indent on: %02x",(*result)->indent); |
183 | len += leng; |
269 | len += leng; |
184 | |
270 | |
185 | psiconv_progress(lev+2,off+len,"Going to read bullet color"); |
271 | 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); |
272 | if ((res = psiconv_parse_color(config,buf,lev+2,off+len,&leng,&(*result)->color))) |
|
|
273 | goto ERROR2; |
187 | len += leng; |
274 | len += leng; |
188 | |
275 | |
189 | psiconv_progress(lev+2,off+len,"Going to read bullet font"); |
276 | 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); |
277 | if ((res = psiconv_parse_font(config,buf,lev+2,off+len,&leng,&(*result)->font))) |
|
|
278 | goto ERROR3; |
191 | len += leng; |
279 | len += leng; |
192 | |
280 | |
193 | if (len != bullet_length + 1) { |
281 | if (len != bullet_length + 1) { |
194 | psiconv_warn(lev+2,off,"Bullet data structure length mismatch"); |
282 | psiconv_warn(config,lev+2,off,"Bullet data structure length mismatch"); |
195 | psiconv_debug(lev+2,off,"Length: specified %02x, found %02x", |
283 | psiconv_debug(config,lev+2,off,"Length: specified %02x, found %02x", |
196 | bullet_length,len-1); |
284 | bullet_length,len-1); |
197 | res = -1; |
|
|
198 | } |
285 | } |
199 | |
286 | |
200 | psiconv_progress(lev+1,off + len - 1, |
287 | psiconv_progress(config,lev+1,off + len - 1, |
201 | "End of bullet data (total length: %08x)",len); |
288 | "End of bullet data (total length: %08x)",len); |
202 | |
289 | |
203 | if (length) |
290 | if (length) |
204 | *length = len; |
291 | *length = len; |
|
|
292 | return 0; |
|
|
293 | |
|
|
294 | ERROR3: |
|
|
295 | psiconv_free_color((*result)->color); |
|
|
296 | ERROR2: |
|
|
297 | free (result); |
|
|
298 | ERROR1: |
|
|
299 | psiconv_error(config,lev+1,off,"Reading of Bullet failed"); |
|
|
300 | if (length) |
|
|
301 | *length = 0; |
|
|
302 | if (!res) |
|
|
303 | return -PSICONV_E_NOMEM; |
|
|
304 | else |
205 | return res; |
305 | return res; |
206 | } |
306 | } |
207 | |
307 | |
208 | int psiconv_parse_tab(const psiconv_buffer buf, int lev, psiconv_u32 off, |
308 | int psiconv_parse_tab(const psiconv_config config, |
|
|
309 | const psiconv_buffer buf, int lev, psiconv_u32 off, |
209 | int *length, psiconv_tab *result) |
310 | int *length, psiconv_tab *result) |
210 | { |
311 | { |
211 | int res = 0; |
312 | int res = 0; |
212 | int len = 0; |
313 | int len = 0; |
213 | int leng; |
314 | int leng; |
214 | psiconv_u8 temp; |
315 | psiconv_u8 temp; |
215 | |
316 | |
216 | psiconv_progress(lev+1,off,"Going to parse tab"); |
317 | psiconv_progress(config,lev+1,off,"Going to parse tab"); |
217 | *result = malloc(sizeof(**result)); |
318 | if (!(*result = malloc(sizeof(**result)))) |
|
|
319 | goto ERROR1; |
218 | |
320 | |
219 | psiconv_progress(lev+2,off,"Going to read tab location"); |
321 | psiconv_progress(config,lev+2,off,"Going to read tab location"); |
220 | (*result)->location = psiconv_read_length(buf,lev+2,off+len,&leng); |
322 | (*result)->location = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res); |
|
|
323 | if (res) |
|
|
324 | goto ERROR2; |
221 | len += leng; |
325 | len += leng; |
222 | |
326 | |
223 | psiconv_progress(lev+2,off+len,"Going to read the tab kind"); |
327 | psiconv_progress(config,lev+2,off+len,"Going to read the tab kind"); |
224 | temp = psiconv_read_u8(buf,lev+2,off+len); |
328 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
329 | if (res) |
|
|
330 | goto ERROR2; |
225 | if (temp == 1) |
331 | if (temp == 1) |
226 | (*result)->kind = psiconv_tab_left; |
332 | (*result)->kind = psiconv_tab_left; |
227 | else if (temp == 2) |
333 | else if (temp == 2) |
228 | (*result)->kind = psiconv_tab_centre; |
334 | (*result)->kind = psiconv_tab_centre; |
229 | else if (temp == 3) |
335 | else if (temp == 3) |
230 | (*result)->kind = psiconv_tab_right; |
336 | (*result)->kind = psiconv_tab_right; |
231 | else { |
337 | else { |
232 | res = -1; |
|
|
233 | psiconv_warn(lev+2,off+len,"Unknown tab kind argument"); |
338 | 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)", |
339 | psiconv_debug(config,lev+2,off+len,"Kind found: %02x (defaulted to left tab)", |
235 | temp); |
340 | temp); |
236 | (*result)->kind = psiconv_tab_left; |
341 | (*result)->kind = psiconv_tab_left; |
237 | } |
342 | } |
238 | psiconv_debug(lev+2,off+len,"Kind: %02x",temp); |
343 | psiconv_debug(config,lev+2,off+len,"Kind: %02x",temp); |
239 | len ++; |
344 | len ++; |
240 | |
345 | |
241 | if (length) |
346 | if (length) |
242 | *length = len; |
347 | *length = len; |
243 | |
348 | |
244 | psiconv_progress(lev+1,off+len-1,"End of tab (total length: %08x)",len); |
349 | psiconv_progress(config,lev+1,off+len-1,"End of tab (total length: %08x)",len); |
245 | return res; |
350 | return 0; |
246 | |
351 | |
|
|
352 | ERROR2: |
|
|
353 | free (result); |
|
|
354 | ERROR1: |
|
|
355 | psiconv_error(config,lev+1,off,"Reading of Tab failed"); |
|
|
356 | if (length) |
|
|
357 | *length = 0; |
|
|
358 | if (!res) |
|
|
359 | return -PSICONV_E_NOMEM; |
|
|
360 | else |
|
|
361 | return res; |
247 | } |
362 | } |
248 | |
363 | |
249 | int psiconv_parse_paragraph_layout_list(const psiconv_buffer buf, int lev, |
364 | int psiconv_parse_paragraph_layout_list(const psiconv_config config, |
|
|
365 | const psiconv_buffer buf, int lev, |
250 | psiconv_u32 off, int *length, |
366 | psiconv_u32 off, int *length, |
251 | psiconv_paragraph_layout result) |
367 | psiconv_paragraph_layout result) |
252 | { |
368 | { |
253 | int res=0; |
369 | int res=0; |
254 | int len=0; |
370 | int len=0; |
255 | int list_length,leng,nr; |
371 | int list_length,leng,nr; |
256 | psiconv_u8 id; |
372 | psiconv_u8 id; |
257 | psiconv_u32 temp; |
373 | psiconv_u32 temp; |
258 | psiconv_tab tab; |
374 | psiconv_tab temp_tab; |
|
|
375 | psiconv_color temp_color; |
|
|
376 | psiconv_border temp_border; |
|
|
377 | psiconv_bullet temp_bullet; |
259 | |
378 | |
260 | psiconv_progress(lev+1,off,"Going to read paragraph layout list"); |
379 | psiconv_progress(config,lev+1,off,"Going to read paragraph layout list"); |
261 | |
380 | |
262 | psiconv_progress(lev+2,off,"Going to read the list length"); |
381 | psiconv_progress(config,lev+2,off,"Going to read the list length"); |
263 | list_length = psiconv_read_u32(buf,lev+2,off + len); |
382 | list_length = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
|
|
383 | if (res) |
|
|
384 | goto ERROR1; |
264 | psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); |
385 | psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length); |
265 | len += 4; |
386 | len += 4; |
266 | |
387 | |
267 | nr = 0; |
388 | nr = 0; |
268 | while(len - 4 < list_length) { |
389 | while(len - 4 < list_length) { |
269 | psiconv_progress(lev+2,off+len,"Going to read element %d",nr); |
390 | 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"); |
391 | psiconv_progress(config,lev+3,off+len,"Going to read the element id"); |
271 | id = psiconv_read_u8(buf,lev+2,off+len); |
392 | id = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
393 | if (res) |
|
|
394 | goto ERROR1; |
272 | psiconv_debug(lev+3,off+len,"Id: %02x",id); |
395 | psiconv_debug(config,lev+3,off+len,"Id: %02x",id); |
273 | len ++; |
396 | len ++; |
274 | switch(id) { |
397 | switch(id) { |
275 | case 0x01: |
398 | case 0x01: |
276 | psiconv_progress(lev+3,off+len,"Going to read background color"); |
399 | psiconv_progress(config,lev+3,off+len,"Going to read background color"); |
|
|
400 | if ((res = psiconv_parse_color(config,buf,lev+3,off+len,&leng,&temp_color))) |
|
|
401 | goto ERROR1; |
277 | psiconv_free_color(result->back_color); |
402 | psiconv_free_color(result->back_color); |
278 | res |= psiconv_parse_color(buf,lev+3,off+len,&leng, |
403 | result->back_color = temp_color; |
279 | &result->back_color); |
|
|
280 | len += leng; |
404 | len += leng; |
281 | break; |
405 | break; |
282 | case 0x02: |
406 | case 0x02: |
283 | psiconv_progress(lev+3,off+len ,"Going to read indent left"); |
407 | 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); |
408 | result->indent_left = psiconv_read_length(config,buf,lev+3,off+len,&leng,&res); |
|
|
409 | if (res) |
|
|
410 | goto ERROR1; |
285 | len += leng; |
411 | len += leng; |
286 | break; |
412 | break; |
287 | case 0x03: |
413 | case 0x03: |
288 | psiconv_progress(lev+3,off+len,"Going to read indent right"); |
414 | 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); |
415 | result->indent_right = psiconv_read_length(config,buf,lev+2,off+len,&leng, |
|
|
416 | &res); |
|
|
417 | if (res) |
|
|
418 | goto ERROR1; |
290 | len += leng; |
419 | len += leng; |
291 | break; |
420 | break; |
292 | case 0x04: |
421 | case 0x04: |
293 | psiconv_progress(lev+3,off+len,"Going to read indent left first line"); |
422 | 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); |
423 | result->indent_first = psiconv_read_length(config,buf,lev+2,off+len, &leng, |
|
|
424 | &res); |
|
|
425 | if (res) |
|
|
426 | goto ERROR1; |
295 | len += leng; |
427 | len += leng; |
296 | break; |
428 | break; |
297 | case 0x05: |
429 | case 0x05: |
298 | psiconv_progress(lev+3,off+len,"Going to read horizontal justify"); |
430 | psiconv_progress(config,lev+3,off+len,"Going to read horizontal justify"); |
299 | temp = psiconv_read_u8(buf,lev+3,off+len); |
431 | temp = psiconv_read_u8(config,buf,lev+3,off+len,&res); |
|
|
432 | if (res) |
|
|
433 | goto ERROR1; |
300 | if (temp == 0x00) |
434 | if (temp == 0x00) |
301 | result->justify_hor = psiconv_justify_left; |
435 | result->justify_hor = psiconv_justify_left; |
302 | else if (temp == 0x01) |
436 | else if (temp == 0x01) |
303 | result->justify_hor = psiconv_justify_centre; |
437 | result->justify_hor = psiconv_justify_centre; |
304 | else if (temp == 0x02) |
438 | else if (temp == 0x02) |
305 | result->justify_hor = psiconv_justify_right; |
439 | result->justify_hor = psiconv_justify_right; |
306 | else if (temp == 0x03) |
440 | else if (temp == 0x03) |
307 | result->justify_hor = psiconv_justify_full; |
441 | result->justify_hor = psiconv_justify_full; |
308 | else { |
442 | else { |
309 | res = -1; |
|
|
310 | psiconv_warn(lev+3,off+len, "Unknown horizontal justify argument " |
443 | psiconv_warn(config,lev+3,off+len, "Unknown horizontal justify argument " |
311 | "in paragraph layout codes list"); |
444 | "in paragraph layout codes list"); |
|
|
445 | result->justify_hor = psiconv_justify_left; |
312 | } |
446 | } |
313 | psiconv_debug(lev+3,off+len,"Justify: %02x",temp); |
447 | psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp); |
314 | len ++; |
448 | len ++; |
315 | break; |
449 | break; |
316 | case 0x06: |
450 | case 0x06: |
317 | psiconv_progress(lev+3,off+len,"Going to read vertical justify"); |
451 | psiconv_progress(config,lev+3,off+len,"Going to read vertical justify"); |
318 | temp = psiconv_read_u8(buf,lev+3,off+len); |
452 | temp = psiconv_read_u8(config,buf,lev+3,off+len,&res); |
|
|
453 | if (res) |
|
|
454 | goto ERROR1; |
319 | if (temp == 0x00) |
455 | if (temp == 0x00) |
320 | result->justify_ver = psiconv_justify_top; |
456 | result->justify_ver = psiconv_justify_top; |
321 | else if (temp == 0x01) |
457 | else if (temp == 0x01) |
322 | result->justify_ver = psiconv_justify_middle; |
458 | result->justify_ver = psiconv_justify_middle; |
323 | else if (temp == 0x02) |
459 | else if (temp == 0x02) |
324 | result->justify_ver = psiconv_justify_bottom; |
460 | result->justify_ver = psiconv_justify_bottom; |
325 | else { |
461 | else { |
326 | res = -1; |
|
|
327 | psiconv_warn(lev+3,off+len, "Unknown vertical justify argument " |
462 | psiconv_warn(config,lev+3,off+len, "Unknown vertical justify argument " |
328 | "in paragraph layout codes list"); |
463 | "in paragraph layout codes list"); |
|
|
464 | result->justify_ver = psiconv_justify_bottom; |
329 | } |
465 | } |
330 | psiconv_debug(lev+3,off+len,"Justify: %02x",temp); |
466 | psiconv_debug(config,lev+3,off+len,"Justify: %02x",temp); |
331 | len ++; |
467 | len ++; |
|
|
468 | break; |
332 | case 0x07: |
469 | case 0x07: |
333 | psiconv_progress(lev+3,off+len,"Going to read interline distance"); |
470 | psiconv_progress(config,lev+3,off+len,"Going to read linespacing distance"); |
334 | result->interline = psiconv_read_size(buf,lev+3,off+len,&leng); |
471 | result->linespacing = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res); |
|
|
472 | if (res) |
|
|
473 | goto ERROR1; |
335 | len += leng; |
474 | len += leng; |
336 | break; |
475 | break; |
337 | case 0x08: |
476 | case 0x08: |
338 | psiconv_progress(lev+3,off+len,"Going to read interline exact"); |
477 | psiconv_progress(config,lev+3,off+len,"Going to read linespacing exact"); |
339 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, |
478 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
340 | &result->interline_exact); |
479 | &result->linespacing_exact))) |
|
|
480 | goto ERROR1; |
341 | len += leng; |
481 | len += leng; |
342 | break; |
482 | break; |
343 | case 0x09: |
483 | case 0x09: |
344 | psiconv_progress(lev+3,off+len,"Going to read top space"); |
484 | 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); |
485 | result->space_above = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res); |
|
|
486 | if (res) |
|
|
487 | goto ERROR1; |
346 | len += leng; |
488 | len += leng; |
347 | break; |
489 | break; |
348 | case 0x0a: |
490 | case 0x0a: |
349 | psiconv_progress(lev+3,off+len,"Going to read bottom space"); |
491 | 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); |
492 | result->space_below = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res); |
|
|
493 | if (res) |
|
|
494 | goto ERROR1; |
351 | len += leng; |
495 | len += leng; |
352 | break; |
496 | break; |
353 | case 0x0b: |
497 | case 0x0b: |
354 | psiconv_progress(lev+3,off+len,"Going to read on one page"); |
498 | psiconv_progress(config,lev+3,off+len,"Going to read on one page"); |
355 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, |
499 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
356 | &result->on_one_page); |
500 | &result->keep_together))) |
|
|
501 | goto ERROR1; |
357 | len += leng; |
502 | len += leng; |
358 | break; |
503 | break; |
359 | case 0x0c: |
504 | case 0x0c: |
360 | psiconv_progress(lev+3,off+len,"Going to read together with"); |
505 | psiconv_progress(config,lev+3,off+len,"Going to read together with"); |
361 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, |
506 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
362 | &result->together_with); |
507 | &result->keep_with_next))) |
|
|
508 | goto ERROR1; |
363 | len += leng; |
509 | len += leng; |
364 | break; |
510 | break; |
365 | case 0x0d: |
511 | case 0x0d: |
366 | psiconv_progress(lev+3,off+len,"Going to read on next page"); |
512 | psiconv_progress(config,lev+3,off+len,"Going to read on next page"); |
367 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, |
513 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
368 | &result->on_next_page); |
514 | &result->on_next_page))) |
|
|
515 | goto ERROR1; |
369 | len += leng; |
516 | len += leng; |
370 | break; |
517 | break; |
371 | case 0x0e: |
518 | case 0x0e: |
372 | psiconv_progress(lev+3,off+len,"Going to read no widow protection"); |
519 | psiconv_progress(config,lev+3,off+len,"Going to read no widow protection"); |
373 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng, |
520 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
374 | &result->no_widow_protection); |
521 | &result->no_widow_protection))) |
|
|
522 | goto ERROR1; |
|
|
523 | len += leng; |
|
|
524 | break; |
|
|
525 | case 0x0f: |
|
|
526 | psiconv_progress(config,lev+3,off+len,"Going to read wrap to fit cell limits"); |
|
|
527 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
|
|
528 | &result->wrap_to_fit_cell))) |
|
|
529 | goto ERROR1; |
375 | len += leng; |
530 | len += leng; |
376 | break; |
531 | break; |
377 | case 0x10: |
532 | case 0x10: |
378 | psiconv_progress(lev+3,off+len,"Going to read border distance to text"); |
533 | psiconv_progress(config,lev+3,off+len,"Going to read border distance to text"); |
379 | result->border_distance = psiconv_read_length(buf,lev+3, |
534 | result->border_distance = psiconv_read_length(config,buf,lev+3, |
380 | off+len,&leng); |
535 | off+len,&leng,&res); |
|
|
536 | if (res) |
|
|
537 | goto ERROR1; |
381 | len += leng; |
538 | len += leng; |
382 | break; |
539 | break; |
383 | case 0x11: |
540 | case 0x11: |
384 | psiconv_progress(lev+3,off+len,"Going to read top border"); |
541 | psiconv_progress(config,lev+3,off+len,"Going to read top border"); |
|
|
542 | if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border))) |
|
|
543 | goto ERROR1; |
385 | psiconv_free_border(result->top_border); |
544 | psiconv_free_border(result->top_border); |
386 | res |= psiconv_parse_border(buf,lev+3,off+len,&leng, |
545 | result->top_border = temp_border; |
387 | &result->top_border); |
|
|
388 | len += leng; |
546 | len += leng; |
389 | break; |
547 | break; |
390 | case 0x12: |
548 | case 0x12: |
391 | psiconv_progress(lev+3,off+len,"Going to read bottom border"); |
549 | psiconv_progress(config,lev+3,off+len,"Going to read bottom border"); |
|
|
550 | if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border))) |
|
|
551 | goto ERROR1; |
392 | psiconv_free_border(result->bottom_border); |
552 | psiconv_free_border(result->bottom_border); |
393 | res |= psiconv_parse_border(buf,lev+3,off+len,&leng, |
553 | result->bottom_border = temp_border; |
394 | &result->bottom_border); |
|
|
395 | len += leng; |
554 | len += leng; |
396 | break; |
555 | break; |
397 | case 0x13: |
556 | case 0x13: |
398 | psiconv_progress(lev+3,off+len,"Going to read left border"); |
557 | psiconv_progress(config,lev+3,off+len,"Going to read left border"); |
|
|
558 | if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border))) |
|
|
559 | goto ERROR1; |
399 | psiconv_free_border(result->left_border); |
560 | psiconv_free_border(result->left_border); |
400 | res |= psiconv_parse_border(buf,lev+3,off+len,&leng, |
561 | result->left_border = temp_border; |
401 | &result->left_border); |
|
|
402 | len += leng; |
562 | len += leng; |
403 | break; |
563 | break; |
404 | case 0x14: |
564 | case 0x14: |
405 | psiconv_progress(lev+3,off+len,"Going to read right border"); |
565 | psiconv_progress(config,lev+3,off+len,"Going to read right border"); |
|
|
566 | if ((res = psiconv_parse_border(config,buf,lev+3,off+len,&leng,&temp_border))) |
|
|
567 | goto ERROR1; |
406 | psiconv_free_border(result->right_border); |
568 | psiconv_free_border(result->right_border); |
407 | res |= psiconv_parse_border(buf,lev+3,off+len,&leng, |
569 | result->right_border = temp_border; |
408 | &result->right_border); |
|
|
409 | len += leng; |
570 | len += leng; |
410 | break; |
571 | break; |
411 | case 0x15: |
572 | case 0x15: |
412 | psiconv_progress(lev+3,off+len,"Going to read bullet"); |
573 | psiconv_progress(config,lev+3,off+len,"Going to read bullet"); |
|
|
574 | if ((res = psiconv_parse_bullet(config,buf,lev+3,off+len,&leng,&temp_bullet))) |
|
|
575 | goto ERROR1; |
413 | psiconv_free_bullet(result->bullet); |
576 | psiconv_free_bullet(result->bullet); |
414 | res |= psiconv_parse_bullet(buf,lev+3,off+len,&leng, |
577 | result->bullet = temp_bullet; |
415 | &result->bullet); |
|
|
416 | len += leng; |
578 | len += leng; |
417 | break; |
579 | break; |
418 | case 0x16: |
580 | case 0x16: |
419 | psiconv_progress(lev+3,off+len,"Going to read standard tabs"); |
581 | 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); |
582 | result->tabs->normal = psiconv_read_length(config,buf,lev+3,off+len,&leng, |
|
|
583 | &res); |
|
|
584 | if (res) |
|
|
585 | goto ERROR1; |
421 | len += leng; |
586 | len += leng; |
422 | break; |
587 | break; |
423 | case 0x17: |
588 | case 0x17: |
424 | psiconv_progress(lev+3,off+len,"Going to read extra tab"); |
589 | psiconv_progress(config,lev+3,off+len,"Going to read extra tab"); |
425 | res |= psiconv_parse_tab(buf,lev+3,off+len,&leng,&tab); |
590 | if ((res = psiconv_parse_tab(config,buf,lev+3,off+len,&leng,&temp_tab))) |
|
|
591 | goto ERROR1; |
426 | psiconv_list_add(result->tabs->extras,tab); |
592 | if ((res = psiconv_list_add(result->tabs->extras,temp_tab))) { |
|
|
593 | psiconv_free_tab(temp_tab); |
|
|
594 | goto ERROR1; |
|
|
595 | } |
|
|
596 | psiconv_free_tab(temp_tab); |
427 | len += leng; |
597 | len += leng; |
428 | break; |
598 | break; |
429 | default: |
599 | default: |
430 | psiconv_warn(lev+3,off+len, |
600 | psiconv_warn(config,lev+3,off+len, |
431 | "Unknown code in paragraph layout codes list"); |
601 | "Unknown code in paragraph layout codes list"); |
432 | psiconv_debug(lev+3,off+len,"Code: %02x",id); |
602 | psiconv_debug(config,lev+3,off+len,"Code: %02x",id); |
433 | len ++; |
603 | len ++; |
434 | res = -1; |
|
|
435 | break; |
604 | break; |
436 | } |
605 | } |
437 | nr ++; |
606 | nr ++; |
438 | } |
607 | } |
439 | |
608 | |
440 | if (len - 4 != list_length) { |
609 | if (len - 4 != list_length) { |
441 | psiconv_warn(lev+2,off+len, |
610 | psiconv_error(config,lev+2,off+len, |
442 | "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 " |
443 | "somewhere!"); |
612 | "somewhere!"); |
444 | psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", |
613 | psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d", |
445 | len-4,list_length); |
614 | len-4,list_length); |
|
|
615 | res = PSICONV_E_PARSE; |
|
|
616 | goto ERROR1; |
446 | } |
617 | } |
447 | |
618 | |
448 | len = list_length + 4; |
619 | len = list_length + 4; |
449 | |
620 | |
450 | psiconv_progress(lev+1,off+len, |
621 | psiconv_progress(config,lev+1,off+len, |
451 | "End of paragraph layout list (total length: %08x)",len); |
622 | "End of paragraph layout list (total length: %08x)",len); |
452 | |
623 | |
453 | if (length) |
624 | if (length) |
454 | *length = len; |
625 | *length = len; |
|
|
626 | return 0; |
|
|
627 | |
|
|
628 | ERROR1: |
|
|
629 | psiconv_error(config,lev+1,off,"Reading of paragraph_layout_list failed"); |
|
|
630 | if (length) |
|
|
631 | *length = 0; |
|
|
632 | if (!res) |
|
|
633 | return -PSICONV_E_NOMEM; |
|
|
634 | else |
455 | return res; |
635 | return res; |
456 | } |
636 | } |
457 | |
637 | |
458 | int psiconv_parse_character_layout_list(const psiconv_buffer buf, int lev, |
638 | int psiconv_parse_character_layout_list(const psiconv_config config, |
|
|
639 | const psiconv_buffer buf, int lev, |
459 | psiconv_u32 off, int *length, |
640 | psiconv_u32 off, int *length, |
460 | psiconv_character_layout result) |
641 | psiconv_character_layout result) |
461 | { |
642 | { |
462 | int res=0; |
643 | int res=0; |
463 | int len=0; |
644 | int len=0; |
464 | int list_length,leng,nr; |
645 | int list_length,leng,nr; |
465 | psiconv_u8 id; |
646 | psiconv_u8 id; |
466 | psiconv_u32 temp; |
647 | psiconv_u32 temp; |
|
|
648 | psiconv_color temp_color; |
|
|
649 | psiconv_font temp_font; |
467 | |
650 | |
468 | psiconv_progress(lev+1,off,"Going to read character layout codes"); |
651 | psiconv_progress(config,lev+1,off,"Going to read character layout codes"); |
469 | |
652 | |
470 | psiconv_progress(lev+2,off,"Going to read the list length"); |
653 | psiconv_progress(config,lev+2,off,"Going to read the list length"); |
471 | list_length = psiconv_read_u32(buf,lev+2,off + len); |
654 | list_length = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
|
|
655 | if (res) |
|
|
656 | goto ERROR1; |
472 | psiconv_debug(lev+2,off,"Length in bytes: %08x",list_length); |
657 | psiconv_debug(config,lev+2,off,"Length in bytes: %08x",list_length); |
473 | len += 4; |
658 | len += 4; |
474 | |
659 | |
475 | nr = 0; |
660 | nr = 0; |
476 | while(len-4 < list_length) { |
661 | while(len-4 < list_length) { |
477 | psiconv_progress(lev+2,off+len,"Going to read element %d",nr); |
662 | 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"); |
663 | psiconv_progress(config,lev+3,off+len,"Going to read the element id"); |
479 | id = psiconv_read_u8(buf,lev+2,off+len); |
664 | id = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
665 | if (res) |
|
|
666 | goto ERROR1; |
480 | psiconv_debug(lev+3,off+len,"Id: %02x",id); |
667 | psiconv_debug(config,lev+3,off+len,"Id: %02x",id); |
481 | len ++; |
668 | len ++; |
482 | switch(id) { |
669 | switch(id) { |
|
|
670 | case 0x18: |
|
|
671 | psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting"); |
|
|
672 | len ++; |
|
|
673 | break; |
483 | case 0x19: |
674 | case 0x19: |
484 | psiconv_progress(lev+3,off+len,"Going to read text color"); |
675 | psiconv_progress(config,lev+3,off+len,"Going to read text color"); |
|
|
676 | if ((res = psiconv_parse_color(config,buf,lev+3,off+len, &leng,&temp_color))) |
|
|
677 | goto ERROR1; |
485 | psiconv_free_color(result->color); |
678 | psiconv_free_color(result->color); |
486 | res |= psiconv_parse_color(buf,lev+3,off+len, &leng,&result->color); |
679 | result->color = temp_color; |
487 | len += leng; |
680 | len += leng; |
488 | break; |
681 | break; |
489 | case 0x1a: |
682 | case 0x1a: |
490 | psiconv_progress(lev+3,off+len,"Going to read background color (?)"); |
683 | psiconv_progress(config,lev+3,off+len,"Going to read background color (?)"); |
|
|
684 | if ((res = psiconv_parse_color(config,buf,lev+2,off+len, &leng,&temp_color))) |
|
|
685 | goto ERROR1; |
491 | psiconv_free_color(result->back_color); |
686 | psiconv_free_color(result->back_color); |
492 | res |= psiconv_parse_color(buf,lev+2,off+len, &leng, |
687 | result->back_color = temp_color; |
493 | &result->back_color); |
688 | len += leng; |
|
|
689 | break; |
|
|
690 | case 0x1b: |
|
|
691 | psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting"); |
494 | len += leng; |
692 | len ++; |
495 | break; |
693 | break; |
496 | case 0x1c: |
694 | case 0x1c: |
497 | psiconv_progress(lev+3,off+len,"Going to read font size"); |
695 | 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); |
696 | result->font_size = psiconv_read_size(config,buf,lev+3,off+len,&leng,&res); |
|
|
697 | if (res) |
|
|
698 | goto ERROR1; |
499 | len += leng; |
699 | len += leng; |
500 | break; |
700 | break; |
501 | case 0x1d: |
701 | case 0x1d: |
502 | psiconv_progress(lev+3,off+len,"Going to read italic"); |
702 | psiconv_progress(config,lev+3,off+len,"Going to read italic"); |
503 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->italic); |
703 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,&result->italic))) |
|
|
704 | goto ERROR1; |
504 | len += leng; |
705 | len += leng; |
505 | break; |
706 | break; |
506 | case 0x1e: |
707 | case 0x1e: |
507 | psiconv_progress(lev+3,off+len,"Going to read bold"); |
708 | psiconv_progress(config,lev+3,off+len,"Going to read bold"); |
508 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->bold); |
709 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng,&result->bold))) |
|
|
710 | goto ERROR1; |
509 | len += leng; |
711 | len += leng; |
510 | break; |
712 | break; |
511 | case 0x1f: |
713 | case 0x1f: |
512 | psiconv_progress(lev+3,off+len,"Going to read super_sub"); |
714 | psiconv_progress(config,lev+3,off+len,"Going to read super_sub"); |
513 | temp = psiconv_read_u8(buf,lev+3,off+len); |
715 | temp = psiconv_read_u8(config,buf,lev+3,off+len,&res); |
|
|
716 | if (res) |
|
|
717 | goto ERROR1; |
514 | if (temp == 0x00) |
718 | if (temp == 0x00) |
515 | result->super_sub = psiconv_normalscript; |
719 | result->super_sub = psiconv_normalscript; |
516 | else if (temp == 0x01) |
720 | else if (temp == 0x01) |
517 | result->super_sub = psiconv_superscript; |
721 | result->super_sub = psiconv_superscript; |
518 | else if (temp == 0x02) |
722 | else if (temp == 0x02) |
519 | result->super_sub = psiconv_subscript; |
723 | result->super_sub = psiconv_subscript; |
520 | else { |
724 | else { |
521 | psiconv_warn(lev+3,off+len, |
725 | psiconv_warn(config,lev+3,off+len, |
522 | "Unknown super_sub argument in character layout codes list"); |
726 | "Unknown super_sub argument in character layout codes list"); |
523 | res = -1; |
|
|
524 | } |
727 | } |
525 | psiconv_debug(lev+3,off+len,"Super_sub: %02x",temp); |
728 | psiconv_debug(config,lev+3,off+len,"Super_sub: %02x",temp); |
526 | len ++; |
729 | len ++; |
527 | break; |
730 | break; |
528 | case 0x20: |
731 | case 0x20: |
529 | psiconv_progress(lev+3,off+len,"Going to read underline"); |
732 | psiconv_progress(config,lev+3,off+len,"Going to read underline"); |
530 | res |= psiconv_parse_bool(buf,lev+3,off+len,&leng,&result->underline); |
733 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
|
|
734 | &result->underline))) |
|
|
735 | goto ERROR1; |
531 | len += leng; |
736 | len += leng; |
532 | break; |
737 | break; |
533 | case 0x21: |
738 | case 0x21: |
534 | psiconv_progress(lev+3,off+len,"Going to read strike_out"); |
739 | 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); |
740 | if ((res = psiconv_parse_bool(config,buf,lev+3,off+len,&leng, |
|
|
741 | &result->strikethrough))) |
|
|
742 | goto ERROR1; |
536 | len += leng; |
743 | len += leng; |
537 | break; |
744 | break; |
538 | case 0x22: |
745 | case 0x22: |
539 | psiconv_progress(lev+3,off+len,"Going to read font"); |
746 | psiconv_progress(config,lev+3,off+len,"Going to read font"); |
|
|
747 | if ((res = psiconv_parse_font(config,buf,lev+3,off+len, &leng, &temp_font))) |
|
|
748 | goto ERROR1; |
540 | psiconv_free_font(result->font); |
749 | psiconv_free_font(result->font); |
541 | res |= psiconv_parse_font(buf,lev+3,off+len, &leng, &result->font); |
750 | result->font = temp_font; |
|
|
751 | len += leng; |
|
|
752 | break; |
|
|
753 | case 0x23: |
|
|
754 | psiconv_progress(config,lev+3,off+len,"Going to skip an unknown setting"); |
542 | len += leng; |
755 | len ++; |
|
|
756 | break; |
|
|
757 | case 0x24: |
|
|
758 | psiconv_progress(config,lev+3,off+len, |
|
|
759 | "Going to read unknown code 0x24 (%02x expected)", 0); |
|
|
760 | temp = psiconv_read_u8(config,buf,lev+3,off+len,&res); |
|
|
761 | if (res) |
|
|
762 | goto ERROR1; |
|
|
763 | if (temp != 0) { |
|
|
764 | psiconv_warn(config,lev+3,off+len, |
|
|
765 | "Unknown code 0x24 value != 0x0 (0x%02x)", temp); |
|
|
766 | } |
|
|
767 | len ++; |
543 | break; |
768 | break; |
544 | default: |
769 | default: |
545 | psiconv_warn(lev+3,off+len,"Unknown code in character layout list"); |
770 | psiconv_warn(config,lev+3,off+len,"Unknown code in character layout list"); |
546 | psiconv_debug(lev+3,off+len,"Code: %02x",id); |
771 | psiconv_debug(config,lev+3,off+len,"Code: %02x",id); |
547 | len ++; |
772 | len ++; |
548 | res = -1; |
|
|
549 | break; |
773 | break; |
550 | } |
774 | } |
551 | nr ++; |
775 | nr ++; |
552 | } |
776 | } |
553 | |
777 | |
554 | if (len - 4 != list_length) { |
778 | if (len - 4 != list_length) { |
555 | psiconv_warn(lev+2,off+len, |
779 | psiconv_error(config,lev+2,off+len, |
556 | "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 " |
557 | "somewhere!"); |
781 | "somewhere!"); |
558 | psiconv_debug(lev+2,off+len,"Read %d characters instead of %d", |
782 | psiconv_debug(config,lev+2,off+len,"Read %d characters instead of %d", |
559 | len-4,list_length); |
783 | len-4,list_length); |
|
|
784 | res = PSICONV_E_PARSE; |
|
|
785 | goto ERROR1; |
560 | } |
786 | } |
561 | |
787 | |
562 | len = list_length + 4; |
788 | len = list_length + 4; |
563 | |
789 | |
564 | psiconv_progress(lev+1,off+len, |
790 | psiconv_progress(config,lev+1,off+len, |
565 | "End of character layout list (total length: %08x)",len); |
791 | "End of character layout list (total length: %08x)",len); |
566 | |
792 | |
567 | if (length) |
793 | if (length) |
568 | *length = len; |
794 | *length = len; |
569 | return res; |
795 | return res; |
|
|
796 | |
|
|
797 | ERROR1: |
|
|
798 | psiconv_error(config,lev+1,off,"Reading of character_layout_list failed"); |
|
|
799 | if (length) |
|
|
800 | *length = 0; |
|
|
801 | if (!res) |
|
|
802 | return -PSICONV_E_NOMEM; |
|
|
803 | else |
|
|
804 | return res; |
570 | } |
805 | } |