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