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