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