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