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