… | |
… | |
22 | |
22 | |
23 | #include <stdlib.h> |
23 | #include <stdlib.h> |
24 | |
24 | |
25 | #include "parse_routines.h" |
25 | #include "parse_routines.h" |
26 | #include "error.h" |
26 | #include "error.h" |
|
|
27 | |
|
|
28 | #ifdef DMALLOC |
|
|
29 | #include <dmalloc.h> |
|
|
30 | #endif |
27 | |
31 | |
28 | static psiconv_sheet_cell_layout psiconv_basic_cell_layout(void) |
32 | static psiconv_sheet_cell_layout psiconv_basic_cell_layout(void) |
29 | { |
33 | { |
30 | psiconv_sheet_cell_layout result; |
34 | psiconv_sheet_cell_layout result; |
31 | if (!(result = malloc(sizeof(*result)))) |
35 | if (!(result = malloc(sizeof(*result)))) |
… | |
… | |
75 | ERROR1: |
79 | ERROR1: |
76 | return NULL; |
80 | return NULL; |
77 | } |
81 | } |
78 | |
82 | |
79 | static psiconv_sheet_cell_reference_t |
83 | static psiconv_sheet_cell_reference_t |
80 | psiconv_read_var_cellref (const psiconv_buffer buf, int lev, |
84 | psiconv_read_var_cellref (const psiconv_config config, |
|
|
85 | const psiconv_buffer buf, int lev, |
81 | psiconv_u32 off, int *length, |
86 | psiconv_u32 off, int *length, |
82 | int *status) |
87 | int *status) |
83 | { |
88 | { |
84 | int len=0; |
89 | int len=0; |
85 | int res; |
90 | int res; |
86 | psiconv_sheet_cell_reference_t result; |
91 | psiconv_sheet_cell_reference_t result; |
87 | psiconv_u32 temp; |
92 | psiconv_u32 temp; |
88 | |
93 | |
89 | psiconv_progress(lev+1,off+len,"Going to read a sheet cell reference"); |
94 | psiconv_progress(config,lev+1,off+len,"Going to read a sheet cell reference"); |
90 | psiconv_progress(lev+2,off+len, |
95 | psiconv_progress(config,lev+2,off+len, |
91 | "Going to read the initial byte (%02x expected)",0x00); |
96 | "Going to read the initial byte (%02x expected)",0x00); |
92 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
97 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
93 | if (res) |
98 | if (res) |
94 | goto ERROR1; |
99 | goto ERROR1; |
95 | if (temp != 0x00) { |
100 | if (temp != 0x00) { |
96 | psiconv_warn(lev+2,off+len, |
101 | psiconv_warn(config,lev+2,off+len, |
97 | "Sheet cell reference initial byte unknown value (ignored)"); |
102 | "Sheet cell reference initial byte unknown value (ignored)"); |
98 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
103 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
99 | } |
104 | } |
100 | len ++; |
105 | len ++; |
101 | |
106 | |
102 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
107 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
103 | if (res) |
108 | if (res) |
104 | goto ERROR1; |
109 | goto ERROR1; |
105 | if (temp & 0xffff0000) { |
110 | if (temp & 0xffff0000) { |
106 | psiconv_warn(lev+2,off+len, |
111 | psiconv_warn(config,lev+2,off+len, |
107 | "Sheet cell row reference to unknown row (reset)"); |
112 | "Sheet cell row reference to unknown row (reset)"); |
108 | } |
113 | } |
109 | result.row.offset = temp; |
114 | result.row.offset = temp; |
110 | result.row.absolute = psiconv_bool_true; |
115 | result.row.absolute = psiconv_bool_true; |
111 | len += 4; |
116 | len += 4; |
112 | |
117 | |
113 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
118 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
114 | if (res) |
119 | if (res) |
115 | goto ERROR1; |
120 | goto ERROR1; |
116 | if (temp & 0xffff0000) { |
121 | if (temp & 0xffff0000) { |
117 | psiconv_warn(lev+2,off+len, |
122 | psiconv_warn(config,lev+2,off+len, |
118 | "Sheet cell column reference to unknown row (reset)"); |
123 | "Sheet cell column reference to unknown row (reset)"); |
119 | } |
124 | } |
120 | result.column.offset = temp; |
125 | result.column.offset = temp; |
121 | result.column.absolute = psiconv_bool_true; |
126 | result.column.absolute = psiconv_bool_true; |
122 | len += 4; |
127 | len += 4; |
123 | |
128 | |
124 | if (length) |
129 | if (length) |
125 | *length = len; |
130 | *length = len; |
126 | |
131 | |
127 | psiconv_progress(lev,off+len-1, |
132 | psiconv_progress(config,lev,off+len-1, |
128 | "End of sheet column reference (total length: %08x)", len); |
133 | "End of sheet column reference (total length: %08x)", len); |
129 | return result; |
134 | return result; |
130 | ERROR1: |
135 | ERROR1: |
131 | psiconv_warn(lev+1,off,"Reading of Sheet Column Reference failed"); |
136 | psiconv_warn(config,lev+1,off,"Reading of Sheet Column Reference failed"); |
132 | if (length) |
137 | if (length) |
133 | *length = 0; |
138 | *length = 0; |
134 | if (status) |
139 | if (status) |
135 | *status = res?res:-PSICONV_E_NOMEM; |
140 | *status = res?res:-PSICONV_E_NOMEM; |
136 | return result; |
141 | return result; |
137 | } |
142 | } |
138 | |
143 | |
139 | static psiconv_sheet_cell_block_t |
144 | static psiconv_sheet_cell_block_t |
140 | psiconv_read_var_cellblock (const psiconv_buffer buf, int lev, |
145 | psiconv_read_var_cellblock (const psiconv_config config, |
|
|
146 | const psiconv_buffer buf, int lev, |
141 | psiconv_u32 off, int *length, |
147 | psiconv_u32 off, int *length, |
142 | int *status) |
148 | int *status) |
143 | { |
149 | { |
144 | int len=0; |
150 | int len=0; |
145 | int res; |
151 | int res; |
146 | psiconv_sheet_cell_block_t result; |
152 | psiconv_sheet_cell_block_t result; |
147 | psiconv_u32 temp; |
153 | psiconv_u32 temp; |
148 | |
154 | |
149 | psiconv_progress(lev+1,off+len,"Going to read a sheet cell block reference"); |
155 | psiconv_progress(config,lev+1,off+len,"Going to read a sheet cell block reference"); |
150 | psiconv_progress(lev+2,off+len, |
156 | psiconv_progress(config,lev+2,off+len, |
151 | "Going to read the initial byte (%02x expected)",0x00); |
157 | "Going to read the initial byte (%02x expected)",0x00); |
152 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
158 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
153 | if (res) |
159 | if (res) |
154 | goto ERROR1; |
160 | goto ERROR1; |
155 | if (temp != 0x00) { |
161 | if (temp != 0x00) { |
156 | psiconv_warn(lev+2,off+len, |
162 | psiconv_warn(config,lev+2,off+len, |
157 | "Sheet cell reference initial byte unknown value (ignored)"); |
163 | "Sheet cell reference initial byte unknown value (ignored)"); |
158 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
164 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
159 | } |
165 | } |
160 | len ++; |
166 | len ++; |
161 | |
167 | |
162 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
168 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
163 | if (res) |
169 | if (res) |
164 | goto ERROR1; |
170 | goto ERROR1; |
165 | if (temp & 0xffff0000) { |
171 | if (temp & 0xffff0000) { |
166 | psiconv_warn(lev+2,off+len, |
172 | psiconv_warn(config,lev+2,off+len, |
167 | "Sheet block initial row reference to unknown row (reset)"); |
173 | "Sheet block initial row reference to unknown row (reset)"); |
168 | } |
174 | } |
169 | result.first.row.offset = temp; |
175 | result.first.row.offset = temp; |
170 | result.first.row.absolute = psiconv_bool_true; |
176 | result.first.row.absolute = psiconv_bool_true; |
171 | len += 4; |
177 | len += 4; |
172 | |
178 | |
173 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
179 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
174 | if (res) |
180 | if (res) |
175 | goto ERROR1; |
181 | goto ERROR1; |
176 | if (temp & 0xffff0000) { |
182 | if (temp & 0xffff0000) { |
177 | psiconv_warn(lev+2,off+len, |
183 | psiconv_warn(config,lev+2,off+len, |
178 | "Sheet block initial column reference to unknown row (reset)"); |
184 | "Sheet block initial column reference to unknown row (reset)"); |
179 | } |
185 | } |
180 | result.first.column.offset = temp; |
186 | result.first.column.offset = temp; |
181 | result.first.column.absolute = psiconv_bool_true; |
187 | result.first.column.absolute = psiconv_bool_true; |
182 | len += 4; |
188 | len += 4; |
183 | |
189 | |
184 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
190 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
185 | if (res) |
191 | if (res) |
186 | goto ERROR1; |
192 | goto ERROR1; |
187 | if (temp & 0xffff0000) { |
193 | if (temp & 0xffff0000) { |
188 | psiconv_warn(lev+2,off+len, |
194 | psiconv_warn(config,lev+2,off+len, |
189 | "Sheet block final row reference to unknown row (reset)"); |
195 | "Sheet block final row reference to unknown row (reset)"); |
190 | } |
196 | } |
191 | result.last.row.offset = temp; |
197 | result.last.row.offset = temp; |
192 | result.last.row.absolute = psiconv_bool_true; |
198 | result.last.row.absolute = psiconv_bool_true; |
193 | len += 4; |
199 | len += 4; |
194 | |
200 | |
195 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
201 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
196 | if (res) |
202 | if (res) |
197 | goto ERROR1; |
203 | goto ERROR1; |
198 | if (temp & 0xffff0000) { |
204 | if (temp & 0xffff0000) { |
199 | psiconv_warn(lev+2,off+len, |
205 | psiconv_warn(config,lev+2,off+len, |
200 | "Sheet block final column reference to unknown row (reset)"); |
206 | "Sheet block final column reference to unknown row (reset)"); |
201 | } |
207 | } |
202 | result.last.column.offset = temp; |
208 | result.last.column.offset = temp; |
203 | result.last.column.absolute = psiconv_bool_true; |
209 | result.last.column.absolute = psiconv_bool_true; |
204 | len += 4; |
210 | len += 4; |
205 | |
211 | |
206 | if (length) |
212 | if (length) |
207 | *length = len; |
213 | *length = len; |
208 | |
214 | |
209 | psiconv_progress(lev,off+len-1, |
215 | psiconv_progress(config,lev,off+len-1, |
210 | "End of sheet cell block reference (total length: %08x)", |
216 | "End of sheet cell block reference (total length: %08x)", |
211 | len); |
217 | len); |
212 | return result; |
218 | return result; |
213 | ERROR1: |
219 | ERROR1: |
214 | psiconv_warn(lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
220 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
215 | if (length) |
221 | if (length) |
216 | *length = 0; |
222 | *length = 0; |
217 | if (status) |
223 | if (status) |
218 | *status = res?res:-PSICONV_E_NOMEM; |
224 | *status = res?res:-PSICONV_E_NOMEM; |
219 | return result; |
225 | return result; |
220 | } |
226 | } |
221 | |
227 | |
222 | int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, |
228 | int psiconv_parse_sheet_numberformat(const psiconv_config config, |
|
|
229 | const psiconv_buffer buf, int lev, |
223 | psiconv_u32 off, int *length, |
230 | psiconv_u32 off, int *length, |
224 | psiconv_sheet_numberformat result) |
231 | psiconv_sheet_numberformat result) |
225 | { |
232 | { |
226 | int res=0; |
233 | int res=0; |
227 | int len=0; |
234 | int len=0; |
228 | psiconv_u8 temp; |
235 | psiconv_u8 temp; |
229 | |
236 | |
230 | psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); |
237 | psiconv_progress(config,lev+1,off,"Going to read a sheet numberformat"); |
231 | |
238 | |
232 | psiconv_progress(lev+2,off+len, |
239 | psiconv_progress(config,lev+2,off+len, |
233 | "Going to read the initial byte (%02x expected)",0x02); |
240 | "Going to read the initial byte (%02x expected)",0x02); |
234 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
241 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
235 | if (res) |
242 | if (res) |
236 | goto ERROR1; |
243 | goto ERROR1; |
237 | if (temp != 0x02) { |
244 | if (temp != 0x02) { |
238 | psiconv_warn(lev+2,off+len, |
245 | psiconv_warn(config,lev+2,off+len, |
239 | "Sheet numberformat initial byte unknown value (ignored)"); |
246 | "Sheet numberformat initial byte unknown value (ignored)"); |
240 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
247 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
241 | } |
248 | } |
242 | len ++; |
249 | len ++; |
243 | |
250 | |
244 | psiconv_progress(lev+2,off+len, "Going to read the code byte"); |
251 | psiconv_progress(config,lev+2,off+len, "Going to read the code byte"); |
245 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
252 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
246 | if (res) |
253 | if (res) |
247 | goto ERROR1; |
254 | goto ERROR1; |
248 | psiconv_debug(lev+2,off+len,"Code: %02x",temp); |
255 | psiconv_debug(config,lev+2,off+len,"Code: %02x",temp); |
249 | if (temp == 0x00) |
256 | if (temp == 0x00) |
250 | result->code = psiconv_numberformat_general; |
257 | result->code = psiconv_numberformat_general; |
251 | else if (temp == 0x02) |
258 | else if (temp == 0x02) |
252 | result->code = psiconv_numberformat_fixeddecimal; |
259 | result->code = psiconv_numberformat_fixeddecimal; |
253 | else if (temp == 0x04) |
260 | else if (temp == 0x04) |
… | |
… | |
307 | else if (temp == 0x3A) |
314 | else if (temp == 0x3A) |
308 | result->code = psiconv_numberformat_time_HHii; |
315 | result->code = psiconv_numberformat_time_HHii; |
309 | else if (temp == 0x3C) |
316 | else if (temp == 0x3C) |
310 | result->code = psiconv_numberformat_time_HHiiss; |
317 | result->code = psiconv_numberformat_time_HHiiss; |
311 | else { |
318 | else { |
312 | psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); |
319 | psiconv_warn(config,lev+2,off+len,"Unknown number format (assumed general)"); |
313 | result->code = psiconv_numberformat_general; |
320 | result->code = psiconv_numberformat_general; |
314 | } |
321 | } |
315 | len ++; |
322 | len ++; |
316 | |
323 | |
317 | psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); |
324 | psiconv_progress(config,lev+2,off+len, "Going to read the number of decimals"); |
318 | result->decimal = psiconv_read_u8(buf,lev+2,off+len,&res) >> 1; |
325 | result->decimal = psiconv_read_u8(config,buf,lev+2,off+len,&res) >> 1; |
319 | if (res) |
326 | if (res) |
320 | goto ERROR1; |
327 | goto ERROR1; |
321 | psiconv_debug(lev+2,off+len,"Decimals: %d",result->decimal); |
328 | psiconv_debug(config,lev+2,off+len,"Decimals: %d",result->decimal); |
322 | len ++; |
329 | len ++; |
323 | |
330 | |
324 | if (length) |
331 | if (length) |
325 | *length = len; |
332 | *length = len; |
326 | |
333 | |
327 | psiconv_progress(lev,off+len-1, |
334 | psiconv_progress(config,lev,off+len-1, |
328 | "End of sheet number format (total length: %08x)", len); |
335 | "End of sheet number format (total length: %08x)", len); |
329 | return 0; |
336 | return 0; |
330 | |
337 | |
331 | ERROR1: |
338 | ERROR1: |
332 | psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); |
339 | psiconv_warn(config,lev+1,off,"Reading of Sheet Number Format failed"); |
333 | if (length) |
340 | if (length) |
334 | *length = 0; |
341 | *length = 0; |
335 | if (!res) |
342 | if (!res) |
336 | return -PSICONV_E_NOMEM; |
343 | return -PSICONV_E_NOMEM; |
337 | else |
344 | else |
338 | return res; |
345 | return res; |
339 | } |
346 | } |
340 | |
347 | |
341 | int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, |
348 | int psiconv_parse_sheet_status_section(const psiconv_config config, |
|
|
349 | const psiconv_buffer buf, int lev, |
342 | psiconv_u32 off, int *length, |
350 | psiconv_u32 off, int *length, |
343 | psiconv_sheet_status_section *result) |
351 | psiconv_sheet_status_section *result) |
344 | { |
352 | { |
345 | int res=0; |
353 | int res=0; |
346 | int len=0; |
354 | int len=0; |
347 | psiconv_u32 temp; |
355 | psiconv_u32 temp; |
348 | int leng; |
356 | int leng; |
349 | |
357 | |
350 | psiconv_progress(lev+1,off,"Going to read the sheet status section"); |
358 | psiconv_progress(config,lev+1,off,"Going to read the sheet status section"); |
351 | if (!(*result = malloc(sizeof(**result)))) |
359 | if (!(*result = malloc(sizeof(**result)))) |
352 | goto ERROR1; |
360 | goto ERROR1; |
353 | |
361 | |
354 | psiconv_progress(lev+2,off+len, |
362 | psiconv_progress(config,lev+2,off+len, |
355 | "Going to read the initial byte (%02x expected)",0x02); |
363 | "Going to read the initial byte (%02x expected)",0x02); |
356 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
364 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
357 | if (res) |
365 | if (res) |
358 | goto ERROR2; |
366 | goto ERROR2; |
359 | if (temp != 0x02) { |
367 | if (temp != 0x02) { |
360 | psiconv_warn(lev+2,off+len, |
368 | psiconv_warn(config,lev+2,off+len, |
361 | "Sheet status section initial byte unknown value (ignored)"); |
369 | "Sheet status section initial byte unknown value (ignored)"); |
362 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
370 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
363 | } |
371 | } |
364 | len ++; |
372 | len ++; |
365 | |
373 | |
366 | psiconv_progress(lev+2,off+len, |
374 | psiconv_progress(config,lev+2,off+len, |
367 | "Going to read the cursor row"); |
375 | "Going to read the cursor row"); |
368 | (*result)->cursor_row = psiconv_read_u32(buf,lev+2,off + len,&res); |
376 | (*result)->cursor_row = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
369 | if (res) |
377 | if (res) |
370 | goto ERROR2; |
378 | goto ERROR2; |
371 | psiconv_debug(lev+2,off+len,"Cursor row: %08x", |
379 | psiconv_debug(config,lev+2,off+len,"Cursor row: %08x", |
372 | (*result)->cursor_row); |
380 | (*result)->cursor_row); |
373 | len += 0x04; |
381 | len += 0x04; |
374 | |
382 | |
375 | psiconv_progress(lev+2,off+len, |
383 | psiconv_progress(config,lev+2,off+len, |
376 | "Going to read the cursor column"); |
384 | "Going to read the cursor column"); |
377 | (*result)->cursor_column = psiconv_read_u32(buf,lev+2,off + len,&res); |
385 | (*result)->cursor_column = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
378 | if (res) |
386 | if (res) |
379 | goto ERROR2; |
387 | goto ERROR2; |
380 | psiconv_debug(lev+2,off+len,"Cursor column: %08x", |
388 | psiconv_debug(config,lev+2,off+len,"Cursor column: %08x", |
381 | (*result)->cursor_column); |
389 | (*result)->cursor_column); |
382 | len += 0x04; |
390 | len += 0x04; |
383 | |
391 | |
384 | psiconv_progress(lev+2,off+len,"Going to read initially display graph"); |
392 | psiconv_progress(config,lev+2,off+len,"Going to read initially display graph"); |
385 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
393 | if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng, |
386 | &(*result)->show_graph))) |
394 | &(*result)->show_graph))) |
387 | goto ERROR2; |
395 | goto ERROR2; |
388 | len += leng; |
396 | len += leng; |
389 | |
397 | |
390 | psiconv_progress(lev+2,off+len, |
398 | psiconv_progress(config,lev+2,off+len, |
391 | "Going to read the toolbar status byte"); |
399 | "Going to read the toolbar status byte"); |
392 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
400 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
393 | if (res) |
401 | if (res) |
394 | goto ERROR2; |
402 | goto ERROR2; |
395 | |
403 | |
396 | (*result)->show_side_sheet_toolbar = temp&0x01 ? psiconv_bool_true : |
404 | (*result)->show_side_sheet_toolbar = temp&0x01 ? psiconv_bool_true : |
397 | psiconv_bool_false; |
405 | psiconv_bool_false; |
398 | psiconv_debug(lev+2,off+len,"Show side sheet toolbar: %02x", |
406 | psiconv_debug(config,lev+2,off+len,"Show side sheet toolbar: %02x", |
399 | (*result)->show_side_sheet_toolbar); |
407 | (*result)->show_side_sheet_toolbar); |
400 | (*result)->show_top_sheet_toolbar = temp&0x02 ? psiconv_bool_true : |
408 | (*result)->show_top_sheet_toolbar = temp&0x02 ? psiconv_bool_true : |
401 | psiconv_bool_false; |
409 | psiconv_bool_false; |
402 | psiconv_debug(lev+2,off+len,"Show top sheet toolbar: %02x", |
410 | psiconv_debug(config,lev+2,off+len,"Show top sheet toolbar: %02x", |
403 | (*result)->show_top_sheet_toolbar); |
411 | (*result)->show_top_sheet_toolbar); |
404 | (*result)->show_side_graph_toolbar = temp&0x04 ? psiconv_bool_true : |
412 | (*result)->show_side_graph_toolbar = temp&0x04 ? psiconv_bool_true : |
405 | psiconv_bool_false; |
413 | psiconv_bool_false; |
406 | psiconv_debug(lev+2,off+len,"Show side graph toolbar: %02x", |
414 | psiconv_debug(config,lev+2,off+len,"Show side graph toolbar: %02x", |
407 | (*result)->show_side_graph_toolbar); |
415 | (*result)->show_side_graph_toolbar); |
408 | (*result)->show_top_graph_toolbar = temp&0x08 ? psiconv_bool_true : |
416 | (*result)->show_top_graph_toolbar = temp&0x08 ? psiconv_bool_true : |
409 | psiconv_bool_false; |
417 | psiconv_bool_false; |
410 | psiconv_debug(lev+2,off+len,"Show top graph toolbar: %02x", |
418 | psiconv_debug(config,lev+2,off+len,"Show top graph toolbar: %02x", |
411 | (*result)->show_top_graph_toolbar); |
419 | (*result)->show_top_graph_toolbar); |
412 | if (temp & 0xf0) { |
420 | if (temp & 0xf0) { |
413 | psiconv_warn(lev+2,off+len,"Sheet status section toolbar byte " |
421 | psiconv_warn(config,lev+2,off+len,"Sheet status section toolbar byte " |
414 | "flags contains unknown flags (ignored)"); |
422 | "flags contains unknown flags (ignored)"); |
415 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
423 | psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
416 | } |
424 | } |
417 | len ++; |
425 | len ++; |
418 | |
426 | |
419 | psiconv_progress(lev+2,off+len, |
427 | psiconv_progress(config,lev+2,off+len, |
420 | "Going to read the scrollbar status byte"); |
428 | "Going to read the scrollbar status byte"); |
421 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
429 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
422 | if (res) |
430 | if (res) |
423 | goto ERROR2; |
431 | goto ERROR2; |
424 | if ((temp & 0x03) == 0x03) { |
432 | if ((temp & 0x03) == 0x03) { |
425 | psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
433 | psiconv_warn(config,lev+2,off+len,"Sheet status section scrollbar byte " |
426 | "flags contains unknown flags (ignored)"); |
434 | "flags contains unknown flags (ignored)"); |
427 | psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x03); |
435 | psiconv_debug(config,lev+2,off+len,"Unknown flag: %02x",temp & 0x03); |
428 | } |
436 | } |
429 | (*result)->show_horizontal_scrollbar = (temp&0x03) == 1? psiconv_triple_off : |
437 | (*result)->show_horizontal_scrollbar = (temp&0x03) == 1? psiconv_triple_off : |
430 | (temp&0x03) == 2? psiconv_triple_auto: |
438 | (temp&0x03) == 2? psiconv_triple_auto: |
431 | psiconv_triple_on; |
439 | psiconv_triple_on; |
432 | psiconv_debug(lev+2,off+len,"Show horizontal scrollbar: %02x", |
440 | psiconv_debug(config,lev+2,off+len,"Show horizontal scrollbar: %02x", |
433 | (*result)->show_horizontal_scrollbar); |
441 | (*result)->show_horizontal_scrollbar); |
434 | if ((temp & 0x0c) == 0x0c) { |
442 | if ((temp & 0x0c) == 0x0c) { |
435 | psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
443 | psiconv_warn(config,lev+2,off+len,"Sheet status section scrollbar byte " |
436 | "flags contains unknown flags (ignored)"); |
444 | "flags contains unknown flags (ignored)"); |
437 | psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x0c); |
445 | psiconv_debug(config,lev+2,off+len,"Unknown flag: %02x",temp & 0x0c); |
438 | } |
446 | } |
439 | (*result)->show_vertical_scrollbar = (temp&0x0c) ==0x04? psiconv_triple_off: |
447 | (*result)->show_vertical_scrollbar = (temp&0x0c) ==0x04? psiconv_triple_off: |
440 | (temp&0x0c) ==0x08? psiconv_triple_auto: |
448 | (temp&0x0c) ==0x08? psiconv_triple_auto: |
441 | psiconv_triple_on; |
449 | psiconv_triple_on; |
442 | psiconv_debug(lev+2,off+len,"Show vertical scrollbar: %02x", |
450 | psiconv_debug(config,lev+2,off+len,"Show vertical scrollbar: %02x", |
443 | (*result)->show_vertical_scrollbar); |
451 | (*result)->show_vertical_scrollbar); |
444 | if (temp & 0xf0) { |
452 | if (temp & 0xf0) { |
445 | psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
453 | psiconv_warn(config,lev+2,off+len,"Sheet status section scrollbar byte " |
446 | "flags contains unknown flags (ignored)"); |
454 | "flags contains unknown flags (ignored)"); |
447 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
455 | psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
448 | } |
456 | } |
449 | len ++; |
457 | len ++; |
450 | |
458 | |
451 | psiconv_progress(lev+2,off+len, |
459 | psiconv_progress(config,lev+2,off+len, |
452 | "Going to read an unknown byte (%02x expected)",0x00); |
460 | "Going to read an unknown byte (%02x expected)",0x00); |
453 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
461 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
454 | if (res) |
462 | if (res) |
455 | goto ERROR2; |
463 | goto ERROR2; |
456 | if (temp != 0x00) { |
464 | if (temp != 0x00) { |
457 | psiconv_warn(lev+2,off+len, |
465 | psiconv_warn(config,lev+2,off+len, |
458 | "Sheet status section unknown byte unknown value (ignored)"); |
466 | "Sheet status section unknown byte unknown value (ignored)"); |
459 | psiconv_debug(lev+2,off+len,"Unknown byte: %02x",temp); |
467 | psiconv_debug(config,lev+2,off+len,"Unknown byte: %02x",temp); |
460 | } |
468 | } |
461 | len ++; |
469 | len ++; |
462 | |
470 | |
463 | psiconv_progress(lev+2,off+len,"Going to read sheet display size"); |
471 | psiconv_progress(config,lev+2,off+len,"Going to read sheet display size"); |
464 | (*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
472 | (*result)->sheet_display_size = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
465 | if (res) |
473 | if (res) |
466 | goto ERROR2; |
474 | goto ERROR2; |
467 | psiconv_debug(lev+2,off+len,"Sheet display size: %08x", |
475 | psiconv_debug(config,lev+2,off+len,"Sheet display size: %08x", |
468 | (*result)->sheet_display_size); |
476 | (*result)->sheet_display_size); |
469 | len += 0x04; |
477 | len += 0x04; |
470 | |
478 | |
471 | psiconv_progress(lev+2,off+len,"Going to read graph display size"); |
479 | psiconv_progress(config,lev+2,off+len,"Going to read graph display size"); |
472 | (*result)->graph_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
480 | (*result)->graph_display_size = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
473 | if (res) |
481 | if (res) |
474 | goto ERROR2; |
482 | goto ERROR2; |
475 | psiconv_debug(lev+2,off+len,"Graph display size: %08x", |
483 | psiconv_debug(config,lev+2,off+len,"Graph display size: %08x", |
476 | (*result)->graph_display_size); |
484 | (*result)->graph_display_size); |
477 | len += 0x04; |
485 | len += 0x04; |
478 | |
486 | |
479 | if (length) |
487 | if (length) |
480 | *length = len; |
488 | *length = len; |
481 | |
489 | |
482 | psiconv_progress(lev,off+len-1, |
490 | psiconv_progress(config,lev,off+len-1, |
483 | "End of sheet status section (total length: %08x)", len); |
491 | "End of sheet status section (total length: %08x)", len); |
484 | return 0; |
492 | return 0; |
485 | |
493 | |
486 | ERROR2: |
494 | ERROR2: |
487 | free (*result); |
495 | free (*result); |
488 | ERROR1: |
496 | ERROR1: |
489 | psiconv_warn(lev+1,off,"Reading of Sheet Status Section failed"); |
497 | psiconv_warn(config,lev+1,off,"Reading of Sheet Status Section failed"); |
490 | if (length) |
498 | if (length) |
491 | *length = 0; |
499 | *length = 0; |
492 | if (!res) |
500 | if (!res) |
493 | return -PSICONV_E_NOMEM; |
501 | return -PSICONV_E_NOMEM; |
494 | else |
502 | else |
495 | return res; |
503 | return res; |
496 | } |
504 | } |
497 | |
505 | |
498 | int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
506 | int psiconv_parse_sheet_workbook_section(const psiconv_config config, |
|
|
507 | const psiconv_buffer buf, int lev, |
499 | psiconv_u32 off, int *length, |
508 | psiconv_u32 off, int *length, |
500 | psiconv_sheet_workbook_section *result) |
509 | psiconv_sheet_workbook_section *result) |
501 | { |
510 | { |
502 | int res=0,with_name; |
511 | int res=0,with_name; |
503 | psiconv_u32 temp,formulas_off,worksheets_off,info_off,var_off,name_off=0; |
512 | psiconv_u32 temp,formulas_off,worksheets_off,info_off,var_off,name_off=0; |
504 | int len=0; |
513 | int len=0; |
505 | |
514 | |
506 | psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
515 | psiconv_progress(config,lev+1,off,"Going to read the sheet workbook section"); |
507 | if (!(*result = malloc(sizeof(**result)))) |
516 | if (!(*result = malloc(sizeof(**result)))) |
508 | goto ERROR1; |
517 | goto ERROR1; |
509 | |
518 | |
510 | psiconv_progress(lev+2,off+len, |
519 | psiconv_progress(config,lev+2,off+len, |
511 | "Going to read the initial byte (%02x or %02x expected)", |
520 | "Going to read the initial byte (%02x or %02x expected)", |
512 | 0x02,0x04); |
521 | 0x02,0x04); |
513 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
522 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
514 | if (res) |
523 | if (res) |
515 | goto ERROR2; |
524 | goto ERROR2; |
516 | if ((temp != 0x04) && temp !=0x02) { |
525 | if ((temp != 0x04) && temp !=0x02) { |
517 | psiconv_warn(lev+2,off+len, |
526 | psiconv_warn(config,lev+2,off+len, |
518 | "Sheet workbook section initial byte unknown value (ignored)"); |
527 | "Sheet workbook section initial byte unknown value (ignored)"); |
519 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
528 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
520 | } |
529 | } |
521 | with_name = temp ==0x04; |
530 | with_name = temp ==0x04; |
522 | len ++; |
531 | len ++; |
523 | |
532 | |
524 | psiconv_progress(lev+2,off+len, |
533 | psiconv_progress(config,lev+2,off+len, |
525 | "Going to read the offset of the sheet info Section"); |
534 | "Going to read the offset of the sheet info Section"); |
526 | info_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
535 | info_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
527 | if (res) |
536 | if (res) |
528 | goto ERROR2; |
537 | goto ERROR2; |
529 | psiconv_debug(lev+2,off+len,"Offset: %04x",info_off); |
538 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",info_off); |
530 | len += 4; |
539 | len += 4; |
531 | |
540 | |
532 | psiconv_progress(lev+2,off+len, |
541 | psiconv_progress(config,lev+2,off+len, |
533 | "Going to read the offset of the Formulas List"); |
542 | "Going to read the offset of the Formulas List"); |
534 | formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
543 | formulas_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
535 | if (res) |
544 | if (res) |
536 | goto ERROR2; |
545 | goto ERROR2; |
537 | psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); |
546 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",formulas_off); |
538 | len += 4; |
547 | len += 4; |
539 | |
548 | |
540 | psiconv_progress(lev+2,off+len, |
549 | psiconv_progress(config,lev+2,off+len, |
541 | "Going to read the offset of the Worksheet List"); |
550 | "Going to read the offset of the Worksheet List"); |
542 | worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
551 | worksheets_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
543 | if (res) |
552 | if (res) |
544 | goto ERROR2; |
553 | goto ERROR2; |
545 | psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); |
554 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",worksheets_off); |
546 | len += 4; |
555 | len += 4; |
547 | |
556 | |
548 | psiconv_progress(lev+2,off+len, |
557 | psiconv_progress(config,lev+2,off+len, |
549 | "Going to read the offset of the Variable List"); |
558 | "Going to read the offset of the Variable List"); |
550 | var_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
559 | var_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
551 | if (res) |
560 | if (res) |
552 | goto ERROR2; |
561 | goto ERROR2; |
553 | psiconv_debug(lev+2,off+len,"Offset: %04x",var_off); |
562 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",var_off); |
554 | len += 4; |
563 | len += 4; |
555 | |
564 | |
556 | if (with_name) { |
565 | if (with_name) { |
557 | psiconv_progress(lev+2,off+len, |
566 | psiconv_progress(config,lev+2,off+len, |
558 | "Going to read the offset of the Name Section"); |
567 | "Going to read the offset of the Name Section"); |
559 | name_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
568 | name_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
560 | if (res) |
569 | if (res) |
561 | goto ERROR2; |
570 | goto ERROR2; |
562 | psiconv_debug(lev+2,off+len,"Offset: %04x",name_off); |
571 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",name_off); |
563 | len += 4; |
572 | len += 4; |
564 | } |
573 | } |
565 | |
574 | |
566 | |
575 | |
567 | psiconv_progress(lev+2,off+len,"Going to read the info section"); |
576 | psiconv_progress(config,lev+2,off+len,"Going to read the info section"); |
568 | if ((res = psiconv_parse_sheet_info_section(buf,lev+2,info_off,NULL, |
577 | if ((res = psiconv_parse_sheet_info_section(config,buf,lev+2,info_off,NULL, |
569 | &(*result)->info))) |
578 | &(*result)->info))) |
570 | goto ERROR2; |
579 | goto ERROR2; |
571 | |
580 | |
572 | psiconv_progress(lev+2,off+len,"Going to read the variables list"); |
581 | psiconv_progress(config,lev+2,off+len,"Going to read the variables list"); |
573 | if ((res = psiconv_parse_sheet_variable_list(buf,lev+2,var_off,NULL, |
582 | if ((res = psiconv_parse_sheet_variable_list(config,buf,lev+2,var_off,NULL, |
574 | &(*result)->variables))) |
583 | &(*result)->variables))) |
575 | goto ERROR3; |
584 | goto ERROR3; |
576 | |
585 | |
577 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
586 | psiconv_progress(config,lev+2,off+len,"Going to read the formulas list"); |
578 | if ((res = psiconv_parse_sheet_formula_list(buf,lev+2,formulas_off,NULL, |
587 | if ((res = psiconv_parse_sheet_formula_list(config,buf,lev+2,formulas_off,NULL, |
579 | &(*result)->formulas))) |
588 | &(*result)->formulas))) |
580 | goto ERROR4; |
589 | goto ERROR4; |
581 | |
590 | |
582 | psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); |
591 | psiconv_progress(config,lev+2,off+len,"Going to read the worksheet list"); |
583 | if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, |
592 | if ((res = psiconv_parse_sheet_worksheet_list(config,buf,lev+2,worksheets_off, |
584 | NULL,&(*result)->worksheets))) |
593 | NULL,&(*result)->worksheets))) |
585 | goto ERROR5; |
594 | goto ERROR5; |
586 | |
595 | |
587 | if (with_name) { |
596 | if (with_name) { |
588 | psiconv_progress(lev+2,off+len,"Going to read the name section"); |
597 | psiconv_progress(config,lev+2,off+len,"Going to read the name section"); |
589 | if ((res = psiconv_parse_sheet_name_section(buf,lev+2,name_off,NULL, |
598 | if ((res = psiconv_parse_sheet_name_section(config,buf,lev+2,name_off,NULL, |
590 | &(*result)->name))) |
599 | &(*result)->name))) |
591 | goto ERROR6; |
600 | goto ERROR6; |
592 | } else |
601 | } else |
593 | (*result)->name = NULL; |
602 | (*result)->name = NULL; |
594 | |
603 | |
595 | if (length) |
604 | if (length) |
596 | *length = len; |
605 | *length = len; |
597 | |
606 | |
598 | psiconv_progress(lev,off+len-1, |
607 | psiconv_progress(config,lev,off+len-1, |
599 | "End of sheet workbook section (total length: %08x)", len); |
608 | "End of sheet workbook section (total length: %08x)", len); |
600 | return 0; |
609 | return 0; |
601 | |
610 | |
602 | ERROR6: |
611 | ERROR6: |
603 | psiconv_free_sheet_worksheet_list((*result)->worksheets); |
612 | psiconv_free_sheet_worksheet_list((*result)->worksheets); |
… | |
… | |
608 | ERROR3: |
617 | ERROR3: |
609 | psiconv_free_sheet_info_section((*result)->info); |
618 | psiconv_free_sheet_info_section((*result)->info); |
610 | ERROR2: |
619 | ERROR2: |
611 | free (*result); |
620 | free (*result); |
612 | ERROR1: |
621 | ERROR1: |
613 | psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); |
622 | psiconv_warn(config,lev+1,off,"Reading of Sheet Workbook Section failed"); |
614 | if (length) |
623 | if (length) |
615 | *length = 0; |
624 | *length = 0; |
616 | if (!res) |
625 | if (!res) |
617 | return -PSICONV_E_NOMEM; |
626 | return -PSICONV_E_NOMEM; |
618 | else |
627 | else |
619 | return res; |
628 | return res; |
620 | } |
629 | } |
621 | |
630 | |
622 | int psiconv_parse_sheet_name_section(const psiconv_buffer buf, int lev, |
631 | int psiconv_parse_sheet_name_section(const psiconv_config config, |
|
|
632 | const psiconv_buffer buf, int lev, |
623 | psiconv_u32 off, int *length, |
633 | psiconv_u32 off, int *length, |
624 | psiconv_sheet_name_section *result) |
634 | psiconv_sheet_name_section *result) |
625 | { |
635 | { |
626 | int res=0; |
636 | int res=0; |
627 | psiconv_u32 temp; |
637 | psiconv_u32 temp; |
628 | int len=0,leng; |
638 | int len=0,leng; |
629 | |
639 | |
630 | psiconv_progress(lev+1,off,"Going to read the sheet name section"); |
640 | psiconv_progress(config,lev+1,off,"Going to read the sheet name section"); |
631 | if (!(*result = malloc(sizeof(**result)))) |
641 | if (!(*result = malloc(sizeof(**result)))) |
632 | goto ERROR1; |
642 | goto ERROR1; |
633 | |
643 | |
634 | psiconv_progress(lev+2,off+len, |
644 | psiconv_progress(config,lev+2,off+len, |
635 | "Going to read the initial byte (%02x expected)",0x02); |
645 | "Going to read the initial byte (%02x expected)",0x02); |
636 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
646 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
637 | if (res) |
647 | if (res) |
638 | goto ERROR2; |
648 | goto ERROR2; |
639 | if (temp != 0x02) { |
649 | if (temp != 0x02) { |
640 | psiconv_warn(lev+2,off+len, |
650 | psiconv_warn(config,lev+2,off+len, |
641 | "Sheet name section initial byte unknown value (ignored)"); |
651 | "Sheet name section initial byte unknown value (ignored)"); |
642 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
652 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
643 | } |
653 | } |
644 | len ++; |
654 | len ++; |
645 | |
655 | |
646 | psiconv_progress(lev+2,off+len, "Going to read the sheet name"); |
656 | psiconv_progress(config,lev+2,off+len, "Going to read the sheet name"); |
647 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
657 | (*result)->name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
648 | if (res) |
658 | if (res) |
649 | goto ERROR2; |
659 | goto ERROR2; |
650 | len += leng; |
660 | len += leng; |
651 | |
661 | |
652 | if (length) |
662 | if (length) |
653 | *length = len; |
663 | *length = len; |
654 | |
664 | |
655 | psiconv_progress(lev,off+len-1, |
665 | psiconv_progress(config,lev,off+len-1, |
656 | "End of sheet name section (total length: %08x)", len); |
666 | "End of sheet name section (total length: %08x)", len); |
657 | return 0; |
667 | return 0; |
658 | |
668 | |
659 | ERROR2: |
669 | ERROR2: |
660 | free(*result); |
670 | free(*result); |
661 | ERROR1: |
671 | ERROR1: |
662 | psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
672 | psiconv_warn(config,lev+1,off,"Reading of Sheet Name Section failed"); |
663 | if (length) |
673 | if (length) |
664 | *length = 0; |
674 | *length = 0; |
665 | if (!res) |
675 | if (!res) |
666 | return -PSICONV_E_NOMEM; |
676 | return -PSICONV_E_NOMEM; |
667 | else |
677 | else |
668 | return res; |
678 | return res; |
669 | } |
679 | } |
670 | |
680 | |
671 | int psiconv_parse_sheet_info_section(const psiconv_buffer buf, int lev, |
681 | int psiconv_parse_sheet_info_section(const psiconv_config config, |
|
|
682 | const psiconv_buffer buf, int lev, |
672 | psiconv_u32 off, int *length, |
683 | psiconv_u32 off, int *length, |
673 | psiconv_sheet_info_section *result) |
684 | psiconv_sheet_info_section *result) |
674 | { |
685 | { |
675 | int res=0; |
686 | int res=0; |
676 | psiconv_u32 temp; |
687 | psiconv_u32 temp; |
677 | int len=0,leng; |
688 | int len=0,leng; |
678 | |
689 | |
679 | psiconv_progress(lev+1,off,"Going to read the sheet info section"); |
690 | psiconv_progress(config,lev+1,off,"Going to read the sheet info section"); |
680 | if (!(*result = malloc(sizeof(**result)))) |
691 | if (!(*result = malloc(sizeof(**result)))) |
681 | goto ERROR1; |
692 | goto ERROR1; |
682 | |
693 | |
683 | psiconv_progress(lev+2,off+len, |
694 | psiconv_progress(config,lev+2,off+len, |
684 | "Going to read the initial byte (%02x expected)",0x02); |
695 | "Going to read the initial byte (%02x expected)",0x02); |
685 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
696 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
686 | if (res) |
697 | if (res) |
687 | goto ERROR2; |
698 | goto ERROR2; |
688 | if (temp != 0x02) { |
699 | if (temp != 0x02) { |
689 | psiconv_warn(lev+2,off+len, |
700 | psiconv_warn(config,lev+2,off+len, |
690 | "Sheet info section initial byte unknown value (ignored)"); |
701 | "Sheet info section initial byte unknown value (ignored)"); |
691 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
702 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
692 | } |
703 | } |
693 | len ++; |
704 | len ++; |
694 | |
705 | |
695 | psiconv_progress(lev+2,off+len, "Going to read an unknown Xint"); |
706 | psiconv_progress(config,lev+2,off+len, "Going to read an unknown Xint"); |
696 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
707 | temp = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
697 | if (res) |
708 | if (res) |
698 | goto ERROR2; |
709 | goto ERROR2; |
699 | psiconv_debug(lev+2,off+len,"Value: %d\n",temp); |
710 | psiconv_debug(config,lev+2,off+len,"Value: %d\n",temp); |
700 | len += leng; |
711 | len += leng; |
701 | |
712 | |
702 | psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
713 | psiconv_progress(config,lev+2,off+len, "Going to read the flags byte"); |
703 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
714 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
704 | if (res) |
715 | if (res) |
705 | goto ERROR2; |
716 | goto ERROR2; |
706 | (*result)->auto_recalc = temp & 0x01 ? psiconv_bool_true:psiconv_bool_false; |
717 | (*result)->auto_recalc = temp & 0x01 ? psiconv_bool_true:psiconv_bool_false; |
707 | psiconv_debug(lev+2,off+len,"Auto recalculation: %02x", |
718 | psiconv_debug(config,lev+2,off+len,"Auto recalculation: %02x", |
708 | (*result)->auto_recalc); |
719 | (*result)->auto_recalc); |
709 | if ((temp & 0xfe) != 0x02) { |
720 | if ((temp & 0xfe) != 0x02) { |
710 | psiconv_warn(lev+2,off+len,"Sheet Info Section flags byte " |
721 | psiconv_warn(config,lev+2,off+len,"Sheet Info Section flags byte " |
711 | "contains unknown flags (ignored)"); |
722 | "contains unknown flags (ignored)"); |
712 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp &0xfe); |
723 | psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp &0xfe); |
713 | } |
724 | } |
714 | |
725 | |
715 | len ++; |
726 | len ++; |
716 | |
727 | |
717 | |
728 | |
718 | if (length) |
729 | if (length) |
719 | *length = len; |
730 | *length = len; |
720 | |
731 | |
721 | psiconv_progress(lev,off+len-1, |
732 | psiconv_progress(config,lev,off+len-1, |
722 | "End of sheet info section (total length: %08x)", len); |
733 | "End of sheet info section (total length: %08x)", len); |
723 | return 0; |
734 | return 0; |
724 | |
735 | |
725 | ERROR2: |
736 | ERROR2: |
726 | free(*result); |
737 | free(*result); |
727 | ERROR1: |
738 | ERROR1: |
728 | psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
739 | psiconv_warn(config,lev+1,off,"Reading of Sheet Name Section failed"); |
729 | if (length) |
740 | if (length) |
730 | *length = 0; |
741 | *length = 0; |
731 | if (!res) |
742 | if (!res) |
732 | return -PSICONV_E_NOMEM; |
743 | return -PSICONV_E_NOMEM; |
733 | else |
744 | else |
734 | return res; |
745 | return res; |
735 | } |
746 | } |
736 | |
747 | |
737 | int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev, |
748 | int psiconv_parse_sheet_formula_list(const psiconv_config config, |
|
|
749 | const psiconv_buffer buf, int lev, |
738 | psiconv_u32 off, int *length, |
750 | psiconv_u32 off, int *length, |
739 | psiconv_formula_list *result) |
751 | psiconv_formula_list *result) |
740 | { |
752 | { |
741 | int res=0; |
753 | int res=0; |
742 | int len=0; |
754 | int len=0; |
743 | psiconv_u32 temp; |
755 | psiconv_u32 temp; |
744 | psiconv_formula formula; |
756 | psiconv_formula formula; |
745 | psiconv_u32 listlen,i; |
757 | psiconv_u32 listlen,i; |
746 | int leng; |
758 | int leng; |
747 | |
759 | |
748 | psiconv_progress(lev+1,off,"Going to read the sheet formula list"); |
760 | psiconv_progress(config,lev+1,off,"Going to read the sheet formula list"); |
749 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
761 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
750 | goto ERROR1; |
762 | goto ERROR1; |
751 | |
763 | |
752 | psiconv_progress(lev+2,off+len, |
764 | psiconv_progress(config,lev+2,off+len, |
753 | "Going to read the initial byte (%02x expected)",0x02); |
765 | "Going to read the initial byte (%02x expected)",0x02); |
754 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
766 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
755 | if (res) |
767 | if (res) |
756 | goto ERROR2; |
768 | goto ERROR2; |
757 | if (temp != 0x02) { |
769 | if (temp != 0x02) { |
758 | psiconv_warn(lev+2,off+len, |
770 | psiconv_warn(config,lev+2,off+len, |
759 | "Sheet formula list initial byte unknown value (ignored)"); |
771 | "Sheet formula list initial byte unknown value (ignored)"); |
760 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
772 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
761 | } |
773 | } |
762 | len ++; |
774 | len ++; |
763 | |
775 | |
764 | psiconv_progress(lev+2,off+len, |
776 | psiconv_progress(config,lev+2,off+len, |
765 | "Going to read the number of formulas"); |
777 | "Going to read the number of formulas"); |
766 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
778 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
767 | if (res) |
779 | if (res) |
768 | goto ERROR2; |
780 | goto ERROR2; |
769 | psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen); |
781 | psiconv_debug(config,lev+2,off+len,"Number of formulas: %d",listlen); |
770 | len += leng; |
782 | len += leng; |
771 | |
783 | |
772 | psiconv_progress(lev+2,off+len,"Going to read all formulas"); |
784 | psiconv_progress(config,lev+2,off+len,"Going to read all formulas"); |
773 | for (i = 0; i < listlen; i++) { |
785 | for (i = 0; i < listlen; i++) { |
774 | psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
786 | psiconv_progress(config,lev+3,off+len,"Going to read formula %d",i); |
775 | if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) |
787 | if ((res = psiconv_parse_formula(config,buf,lev+3,off+len,&leng,&formula))) |
776 | goto ERROR2; |
788 | goto ERROR2; |
777 | if ((res = psiconv_list_add(*result,formula))) |
789 | if ((res = psiconv_list_add(*result,formula))) |
778 | goto ERROR3; |
790 | goto ERROR3; |
779 | free(formula); |
791 | free(formula); |
780 | len += leng; |
792 | len += leng; |
781 | } |
793 | } |
782 | |
794 | |
783 | if (length) |
795 | if (length) |
784 | *length = len; |
796 | *length = len; |
785 | |
797 | |
786 | psiconv_progress(lev,off+len-1, |
798 | psiconv_progress(config,lev,off+len-1, |
787 | "End of sheet formula list (total length: %08x)", len); |
799 | "End of sheet formula list (total length: %08x)", len); |
788 | return 0; |
800 | return 0; |
789 | |
801 | |
790 | ERROR3: |
802 | ERROR3: |
791 | psiconv_free_formula(formula); |
803 | psiconv_free_formula(formula); |
792 | ERROR2: |
804 | ERROR2: |
793 | psiconv_list_free(*result); |
805 | psiconv_list_free(*result); |
794 | ERROR1: |
806 | ERROR1: |
795 | psiconv_warn(lev+1,off,"Reading of Sheet Formula list failed"); |
807 | psiconv_warn(config,lev+1,off,"Reading of Sheet Formula list failed"); |
796 | if (length) |
808 | if (length) |
797 | *length = 0; |
809 | *length = 0; |
798 | if (!res) |
810 | if (!res) |
799 | return -PSICONV_E_NOMEM; |
811 | return -PSICONV_E_NOMEM; |
800 | else |
812 | else |
801 | return res; |
813 | return res; |
802 | } |
814 | } |
803 | |
815 | |
804 | int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, |
816 | int psiconv_parse_sheet_cell(const psiconv_config config, |
|
|
817 | const psiconv_buffer buf, int lev, |
805 | psiconv_u32 off, int *length, |
818 | psiconv_u32 off, int *length, |
806 | psiconv_sheet_cell *result, |
819 | psiconv_sheet_cell *result, |
807 | const psiconv_sheet_cell_layout default_layout, |
820 | const psiconv_sheet_cell_layout default_layout, |
808 | const psiconv_sheet_line_list row_default_layouts, |
821 | const psiconv_sheet_line_list row_default_layouts, |
809 | const psiconv_sheet_line_list col_default_layouts) |
822 | const psiconv_sheet_line_list col_default_layouts) |
… | |
… | |
812 | int len=0; |
825 | int len=0; |
813 | psiconv_u32 temp; |
826 | psiconv_u32 temp; |
814 | psiconv_bool_t has_layout; |
827 | psiconv_bool_t has_layout; |
815 | int leng; |
828 | int leng; |
816 | |
829 | |
817 | psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); |
830 | psiconv_progress(config,lev+1,off,"Going to read a sheet cell structure"); |
818 | if (!(*result = malloc(sizeof(**result)))) |
831 | if (!(*result = malloc(sizeof(**result)))) |
819 | goto ERROR1; |
832 | goto ERROR1; |
820 | |
833 | |
821 | (*result)->layout = NULL; |
834 | (*result)->layout = NULL; |
822 | (*result)->type = psiconv_cell_blank; |
835 | (*result)->type = psiconv_cell_blank; |
823 | |
836 | |
824 | psiconv_progress(lev+2,off+len,"Going to read the cell position"); |
837 | psiconv_progress(config,lev+2,off+len,"Going to read the cell position"); |
825 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
838 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
826 | if (res) |
839 | if (res) |
827 | goto ERROR2; |
840 | goto ERROR2; |
828 | len ++; |
841 | len ++; |
829 | temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 8; |
842 | temp += psiconv_read_u8(config,buf,lev+2,off+len,&res) << 8; |
830 | if (res) |
843 | if (res) |
831 | goto ERROR2; |
844 | goto ERROR2; |
832 | len ++; |
845 | len ++; |
833 | temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 16; |
846 | temp += psiconv_read_u8(config,buf,lev+2,off+len,&res) << 16; |
834 | if (res) |
847 | if (res) |
835 | goto ERROR2; |
848 | goto ERROR2; |
836 | len ++; |
849 | len ++; |
837 | (*result)->column = (temp >> 2) & 0xFF; |
850 | (*result)->column = (temp >> 2) & 0xFF; |
838 | (*result)->row = (temp >> 10) & 0x3FFF; |
851 | (*result)->row = (temp >> 10) & 0x3FFF; |
839 | psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", |
852 | psiconv_debug(config,lev+2,off+len,"Cell position is col:%02x row:%04x", |
840 | (*result)->column,(*result)->row); |
853 | (*result)->column,(*result)->row); |
841 | if (temp & 0x03) { |
854 | if (temp & 0x03) { |
842 | psiconv_warn(lev+2,off+len,"Unknown flags in cell position (ignored)"); |
855 | psiconv_warn(config,lev+2,off+len,"Unknown flags in cell position (ignored)"); |
843 | psiconv_debug(lev+2,off+len,"Flags: %02x",temp & 0x03); |
856 | psiconv_debug(config,lev+2,off+len,"Flags: %02x",temp & 0x03); |
844 | } |
857 | } |
845 | |
858 | |
846 | psiconv_progress(lev+2,off+len,"Going to read the cell type"); |
859 | psiconv_progress(config,lev+2,off+len,"Going to read the cell type"); |
847 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
860 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
848 | if (res) |
861 | if (res) |
849 | goto ERROR2; |
862 | goto ERROR2; |
850 | len ++; |
863 | len ++; |
851 | (*result)->type = (temp >> 5) & 0x07; |
864 | (*result)->type = (temp >> 5) & 0x07; |
852 | (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false; |
865 | (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false; |
853 | has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false; |
866 | has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false; |
854 | |
867 | |
855 | psiconv_progress(lev+2,off+len,"Going to read the cell value"); |
868 | psiconv_progress(config,lev+2,off+len,"Going to read the cell value"); |
856 | if ((*result)->type == psiconv_cell_blank) { |
869 | if ((*result)->type == psiconv_cell_blank) { |
857 | psiconv_debug(lev+2,off+len,"Cell type is blank: no value given."); |
870 | psiconv_debug(config,lev+2,off+len,"Cell type is blank: no value given."); |
858 | } else if ((*result)->type == psiconv_cell_int) { |
871 | } else if ((*result)->type == psiconv_cell_int) { |
859 | psiconv_progress(lev+2,off+len,"Going to read an integer"); |
872 | psiconv_progress(config,lev+2,off+len,"Going to read an integer"); |
860 | (*result)->data.dat_int = psiconv_read_u32(buf,lev+2,off+len,&res); |
873 | (*result)->data.dat_int = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
861 | if (res) |
874 | if (res) |
862 | goto ERROR2; |
875 | goto ERROR2; |
863 | len += 4; |
876 | len += 4; |
864 | psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
877 | psiconv_debug(config,lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
865 | |
878 | |
866 | } else if ((*result)->type == psiconv_cell_bool) { |
879 | } else if ((*result)->type == psiconv_cell_bool) { |
867 | psiconv_progress(lev+2,off+len,"Going to read a boolean"); |
880 | psiconv_progress(config,lev+2,off+len,"Going to read a boolean"); |
868 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
881 | if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng, |
869 | &(*result)->data.dat_bool))) |
882 | &(*result)->data.dat_bool))) |
870 | goto ERROR2; |
883 | goto ERROR2; |
871 | psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); |
884 | psiconv_debug(config,lev+2,off+len,"Cell contents: %01x",temp); |
872 | (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
885 | (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
873 | len += leng; |
886 | len += leng; |
874 | } else if ((*result)->type == psiconv_cell_error) { |
887 | } else if ((*result)->type == psiconv_cell_error) { |
875 | psiconv_progress(lev+2,off+len,"Going to read the error code"); |
888 | psiconv_progress(config,lev+2,off+len,"Going to read the error code"); |
876 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
889 | temp = psiconv_read_u16(config,buf,lev+2,off+len,&res); |
877 | if (res) |
890 | if (res) |
878 | goto ERROR2; |
891 | goto ERROR2; |
879 | if (temp == 0) |
892 | if (temp == 0) |
880 | (*result)->data.dat_error = psiconv_sheet_error_none; |
893 | (*result)->data.dat_error = psiconv_sheet_error_none; |
881 | else if (temp == 1) |
894 | else if (temp == 1) |
… | |
… | |
891 | else if (temp == 6) |
904 | else if (temp == 6) |
892 | (*result)->data.dat_error = psiconv_sheet_error_number; |
905 | (*result)->data.dat_error = psiconv_sheet_error_number; |
893 | else if (temp == 7) |
906 | else if (temp == 7) |
894 | (*result)->data.dat_error = psiconv_sheet_error_notavail; |
907 | (*result)->data.dat_error = psiconv_sheet_error_notavail; |
895 | else { |
908 | else { |
896 | psiconv_warn(lev+2,off+len,"Unknown error code (default assumed)"); |
909 | psiconv_warn(config,lev+2,off+len,"Unknown error code (default assumed)"); |
897 | psiconv_debug(lev+2,off+len,"Error code: %04x",temp); |
910 | psiconv_debug(config,lev+2,off+len,"Error code: %04x",temp); |
898 | (*result)->data.dat_error = psiconv_sheet_error_none; |
911 | (*result)->data.dat_error = psiconv_sheet_error_none; |
899 | } |
912 | } |
900 | psiconv_debug(lev+2,off+len,"Cell contents: %04x", |
913 | psiconv_debug(config,lev+2,off+len,"Cell contents: %04x", |
901 | (*result)->data.dat_error); |
914 | (*result)->data.dat_error); |
902 | len += 2; |
915 | len += 2; |
903 | } else if ((*result)->type == psiconv_cell_float) { |
916 | } else if ((*result)->type == psiconv_cell_float) { |
904 | psiconv_progress(lev+2,off+len,"Going to read a float"); |
917 | psiconv_progress(config,lev+2,off+len,"Going to read a float"); |
905 | (*result)->data.dat_float = |
918 | (*result)->data.dat_float = |
906 | psiconv_read_float(buf,lev+2,off+len,&leng,&res); |
919 | psiconv_read_float(config,buf,lev+2,off+len,&leng,&res); |
907 | if (res) |
920 | if (res) |
908 | goto ERROR2; |
921 | goto ERROR2; |
909 | psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
922 | psiconv_debug(config,lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
910 | len += leng; |
923 | len += leng; |
911 | } else if ((*result)->type == psiconv_cell_string) { |
924 | } else if ((*result)->type == psiconv_cell_string) { |
912 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
925 | psiconv_progress(config,lev+2,off+len,"Going to read a string"); |
913 | (*result)->data.dat_string = |
926 | (*result)->data.dat_string = |
914 | psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
927 | psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
915 | if (res) |
928 | if (res) |
916 | goto ERROR2; |
929 | goto ERROR2; |
917 | psiconv_debug(lev+2,off+len,"Cell contents: `%s'", |
930 | psiconv_debug(config,lev+2,off+len,"Cell contents: `%s'", |
918 | (*result)->data.dat_string); |
931 | (*result)->data.dat_string); |
919 | len += leng; |
932 | len += leng; |
920 | } else { |
933 | } else { |
921 | psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
934 | psiconv_warn(config,lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
922 | res = PSICONV_E_PARSE; |
935 | res = PSICONV_E_PARSE; |
923 | goto ERROR2; |
936 | goto ERROR2; |
924 | } |
937 | } |
925 | |
938 | |
926 | if (!((*result)->layout = psiconv_clone_cell_layout( |
939 | if (!((*result)->layout = psiconv_clone_cell_layout( |
… | |
… | |
929 | default_layout, |
942 | default_layout, |
930 | (*result)->row, |
943 | (*result)->row, |
931 | (*result)->column)))) |
944 | (*result)->column)))) |
932 | goto ERROR2; |
945 | goto ERROR2; |
933 | if (has_layout) { |
946 | if (has_layout) { |
934 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
947 | if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len, |
935 | &leng,(*result)->layout))) |
948 | &leng,(*result)->layout))) |
936 | goto ERROR2; |
949 | goto ERROR2; |
937 | len += leng; |
950 | len += leng; |
938 | } |
951 | } |
939 | |
952 | |
940 | if ((*result)->calculated) { |
953 | if ((*result)->calculated) { |
941 | psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); |
954 | psiconv_progress(config,lev+2,off+len,"Going to read the cell formula reference"); |
942 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
955 | temp = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
943 | if (res) |
956 | if (res) |
944 | goto ERROR2; |
957 | goto ERROR2; |
945 | psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); |
958 | psiconv_debug(config,lev+2,off+len,"Cell formula reference: %d",temp); |
946 | len += leng; |
959 | len += leng; |
947 | (*result)->ref_formula = temp; |
960 | (*result)->ref_formula = temp; |
948 | } |
961 | } |
949 | |
962 | |
950 | if (length) |
963 | if (length) |
951 | *length = len; |
964 | *length = len; |
952 | |
965 | |
953 | psiconv_progress(lev,off+len-1, |
966 | psiconv_progress(config,lev,off+len-1, |
954 | "End of sheet cell structure (total length: %08x)", len); |
967 | "End of sheet cell structure (total length: %08x)", len); |
955 | return 0; |
968 | return 0; |
956 | |
969 | |
957 | ERROR2: |
970 | ERROR2: |
958 | psiconv_free_sheet_cell(*result); |
971 | psiconv_free_sheet_cell(*result); |
959 | ERROR1: |
972 | ERROR1: |
960 | psiconv_warn(lev+1,off,"Reading of Sheet Cell Structure failed"); |
973 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cell Structure failed"); |
961 | if (length) |
974 | if (length) |
962 | *length = 0; |
975 | *length = 0; |
963 | if (!res) |
976 | if (!res) |
964 | return -PSICONV_E_NOMEM; |
977 | return -PSICONV_E_NOMEM; |
965 | else |
978 | else |
966 | return res; |
979 | return res; |
967 | } |
980 | } |
968 | |
981 | |
969 | int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, |
982 | int psiconv_parse_sheet_cell_list(const psiconv_config config, |
|
|
983 | const psiconv_buffer buf, int lev, |
970 | psiconv_u32 off, int *length, |
984 | psiconv_u32 off, int *length, |
971 | psiconv_sheet_cell_list *result, |
985 | psiconv_sheet_cell_list *result, |
972 | const psiconv_sheet_cell_layout default_layout, |
986 | const psiconv_sheet_cell_layout default_layout, |
973 | const psiconv_sheet_line_list row_default_layouts, |
987 | const psiconv_sheet_line_list row_default_layouts, |
974 | const psiconv_sheet_line_list col_default_layouts) |
988 | const psiconv_sheet_line_list col_default_layouts) |
… | |
… | |
978 | psiconv_u32 temp; |
992 | psiconv_u32 temp; |
979 | psiconv_sheet_cell cell; |
993 | psiconv_sheet_cell cell; |
980 | psiconv_u32 listlen,i; |
994 | psiconv_u32 listlen,i; |
981 | int leng; |
995 | int leng; |
982 | |
996 | |
983 | psiconv_progress(lev+1,off,"Going to read the sheet cell list"); |
997 | psiconv_progress(config,lev+1,off,"Going to read the sheet cell list"); |
984 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
998 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
985 | goto ERROR1; |
999 | goto ERROR1; |
986 | |
1000 | |
987 | psiconv_progress(lev+2,off+len, |
1001 | psiconv_progress(config,lev+2,off+len, |
988 | "Going to read the initial byte (%02x expected)",0x02); |
1002 | "Going to read the initial byte (%02x expected)",0x02); |
989 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1003 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
990 | if (res) |
1004 | if (res) |
991 | goto ERROR2; |
1005 | goto ERROR2; |
992 | if (temp != 0x02) { |
1006 | if (temp != 0x02) { |
993 | psiconv_warn(lev+2,off+len, |
1007 | psiconv_warn(config,lev+2,off+len, |
994 | "Sheet cell list initial byte unknown value (ignored)"); |
1008 | "Sheet cell list initial byte unknown value (ignored)"); |
995 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1009 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
996 | } |
1010 | } |
997 | len ++; |
1011 | len ++; |
998 | |
1012 | |
999 | psiconv_progress(lev+2,off+len, |
1013 | psiconv_progress(config,lev+2,off+len, |
1000 | "Going to read the initial byte (%02x expected)",0x00); |
1014 | "Going to read the initial byte (%02x expected)",0x00); |
1001 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1015 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1002 | if (res) |
1016 | if (res) |
1003 | goto ERROR2; |
1017 | goto ERROR2; |
1004 | if (temp != 0x00) { |
1018 | if (temp != 0x00) { |
1005 | psiconv_warn(lev+2,off+len, |
1019 | psiconv_warn(config,lev+2,off+len, |
1006 | "Sheet cell list initial byte unknown value (ignored)"); |
1020 | "Sheet cell list initial byte unknown value (ignored)"); |
1007 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1021 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
1008 | } |
1022 | } |
1009 | len ++; |
1023 | len ++; |
1010 | |
1024 | |
1011 | psiconv_progress(lev+2,off+len, |
1025 | psiconv_progress(config,lev+2,off+len, |
1012 | "Going to read the number of defined cells"); |
1026 | "Going to read the number of defined cells"); |
1013 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1027 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
1014 | if (res) |
1028 | if (res) |
1015 | goto ERROR2; |
1029 | goto ERROR2; |
1016 | psiconv_debug(lev+2,off+len,"Number of defined cells: %d",listlen); |
1030 | psiconv_debug(config,lev+2,off+len,"Number of defined cells: %d",listlen); |
1017 | len += leng; |
1031 | len += leng; |
1018 | |
1032 | |
1019 | psiconv_progress(lev+2,off+len,"Going to read all cells"); |
1033 | psiconv_progress(config,lev+2,off+len,"Going to read all cells"); |
1020 | for (i = 0; i < listlen; i++) { |
1034 | for (i = 0; i < listlen; i++) { |
1021 | psiconv_progress(lev+3,off+len,"Going to read cell %d",i); |
1035 | psiconv_progress(config,lev+3,off+len,"Going to read cell %d",i); |
1022 | if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell, |
1036 | if ((res = psiconv_parse_sheet_cell(config,buf,lev+3,off+len,&leng,&cell, |
1023 | default_layout,row_default_layouts, |
1037 | default_layout,row_default_layouts, |
1024 | col_default_layouts))) |
1038 | col_default_layouts))) |
1025 | goto ERROR2; |
1039 | goto ERROR2; |
1026 | if ((res = psiconv_list_add(*result,cell))) |
1040 | if ((res = psiconv_list_add(*result,cell))) |
1027 | goto ERROR3; |
1041 | goto ERROR3; |
… | |
… | |
1030 | } |
1044 | } |
1031 | |
1045 | |
1032 | if (length) |
1046 | if (length) |
1033 | *length = len; |
1047 | *length = len; |
1034 | |
1048 | |
1035 | psiconv_progress(lev,off+len-1, |
1049 | psiconv_progress(config,lev,off+len-1, |
1036 | "End of sheet cell list (total length: %08x)", len); |
1050 | "End of sheet cell list (total length: %08x)", len); |
1037 | return 0; |
1051 | return 0; |
1038 | |
1052 | |
1039 | ERROR3: |
1053 | ERROR3: |
1040 | psiconv_free_sheet_cell(cell); |
1054 | psiconv_free_sheet_cell(cell); |
1041 | ERROR2: |
1055 | ERROR2: |
1042 | psiconv_free_sheet_cell_list(*result); |
1056 | psiconv_free_sheet_cell_list(*result); |
1043 | ERROR1: |
1057 | ERROR1: |
1044 | psiconv_warn(lev+1,off,"Reading of Sheet Cells List failed"); |
1058 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cells List failed"); |
1045 | if (length) |
1059 | if (length) |
1046 | *length = 0; |
1060 | *length = 0; |
1047 | if (!res) |
1061 | if (!res) |
1048 | return -PSICONV_E_NOMEM; |
1062 | return -PSICONV_E_NOMEM; |
1049 | else |
1063 | else |
1050 | return res; |
1064 | return res; |
1051 | } |
1065 | } |
1052 | |
1066 | |
1053 | |
1067 | |
1054 | int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev, |
1068 | int psiconv_parse_sheet_worksheet_list(const psiconv_config config, |
|
|
1069 | const psiconv_buffer buf, int lev, |
1055 | psiconv_u32 off, int *length, |
1070 | psiconv_u32 off, int *length, |
1056 | psiconv_sheet_worksheet_list *result) |
1071 | psiconv_sheet_worksheet_list *result) |
1057 | { |
1072 | { |
1058 | psiconv_sheet_worksheet worksheet; |
1073 | psiconv_sheet_worksheet worksheet; |
1059 | int res=0; |
1074 | int res=0; |
1060 | int len=0; |
1075 | int len=0; |
1061 | psiconv_u8 temp; |
1076 | psiconv_u8 temp; |
1062 | psiconv_u32 offset; |
1077 | psiconv_u32 offset; |
1063 | int leng,i,nr; |
1078 | int leng,i,nr; |
1064 | |
1079 | |
1065 | psiconv_progress(lev+1,off,"Going to read the worksheet list"); |
1080 | psiconv_progress(config,lev+1,off,"Going to read the worksheet list"); |
1066 | if (!(*result = psiconv_list_new(sizeof(*worksheet)))) |
1081 | if (!(*result = psiconv_list_new(sizeof(*worksheet)))) |
1067 | goto ERROR1; |
1082 | goto ERROR1; |
1068 | |
1083 | |
1069 | psiconv_progress(lev+2,off+len, |
1084 | psiconv_progress(config,lev+2,off+len, |
1070 | "Going to read the initial bytes (%02x expected)",0x02); |
1085 | "Going to read the initial bytes (%02x expected)",0x02); |
1071 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1086 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1072 | if (res) |
1087 | if (res) |
1073 | goto ERROR2; |
1088 | goto ERROR2; |
1074 | if (temp != 0x02) { |
1089 | if (temp != 0x02) { |
1075 | psiconv_warn(lev+2,off+len, |
1090 | psiconv_warn(config,lev+2,off+len, |
1076 | "Sheet worksheet list initial byte unknown value (ignored)"); |
1091 | "Sheet worksheet list initial byte unknown value (ignored)"); |
1077 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1092 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
1078 | } |
1093 | } |
1079 | len ++; |
1094 | len ++; |
1080 | |
1095 | |
1081 | psiconv_progress(lev+2,off+len,"Going to read the list length"); |
1096 | psiconv_progress(config,lev+2,off+len,"Going to read the list length"); |
1082 | nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1097 | nr = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
1083 | if (res) |
1098 | if (res) |
1084 | goto ERROR2; |
1099 | goto ERROR2; |
1085 | psiconv_debug(lev+2,off+len,"Length: %02x",nr); |
1100 | psiconv_debug(config,lev+2,off+len,"Length: %02x",nr); |
1086 | len += leng; |
1101 | len += leng; |
1087 | |
1102 | |
1088 | psiconv_progress(lev+2,off+len,"Going to read the list"); |
1103 | psiconv_progress(config,lev+2,off+len,"Going to read the list"); |
1089 | for (i=0 ; i < nr; i++) { |
1104 | for (i=0 ; i < nr; i++) { |
1090 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
1105 | psiconv_progress(config,lev+3,off+len,"Going to read element %d",i); |
1091 | psiconv_progress(lev+4,off+len, |
1106 | psiconv_progress(config,lev+4,off+len, |
1092 | "Going to read the initial byte (%02x expected)",0x00); |
1107 | "Going to read the initial byte (%02x expected)",0x00); |
1093 | temp = psiconv_read_u8(buf,lev+4,off+len,&res); |
1108 | temp = psiconv_read_u8(config,buf,lev+4,off+len,&res); |
1094 | if (res) |
1109 | if (res) |
1095 | goto ERROR2; |
1110 | goto ERROR2; |
1096 | if (temp != 0x00) { |
1111 | if (temp != 0x00) { |
1097 | psiconv_warn(lev+4,off+len, |
1112 | psiconv_warn(config,lev+4,off+len, |
1098 | "Sheet worksheet element initial byte unknown value (ignored)"); |
1113 | "Sheet worksheet element initial byte unknown value (ignored)"); |
1099 | psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp); |
1114 | psiconv_debug(config,lev+4,off+len,"Initial byte: %02x",temp); |
1100 | } |
1115 | } |
1101 | len ++; |
1116 | len ++; |
1102 | |
1117 | |
1103 | psiconv_progress(lev+4,off+len,"Going to read the worksheet offset"); |
1118 | psiconv_progress(config,lev+4,off+len,"Going to read the worksheet offset"); |
1104 | offset = psiconv_read_u32(buf,lev+2,off+len,&res); |
1119 | offset = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1105 | if (res) |
1120 | if (res) |
1106 | goto ERROR2; |
1121 | goto ERROR2; |
1107 | psiconv_debug(lev+4,off+len,"Offset: %08x",offset); |
1122 | psiconv_debug(config,lev+4,off+len,"Offset: %08x",offset); |
1108 | len += 4; |
1123 | len += 4; |
1109 | |
1124 | |
1110 | if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL, |
1125 | if ((res = psiconv_parse_sheet_worksheet(config,buf,lev+4,offset,NULL, |
1111 | &worksheet))) |
1126 | &worksheet))) |
1112 | goto ERROR2; |
1127 | goto ERROR2; |
1113 | if ((res = psiconv_list_add(*result,worksheet))) |
1128 | if ((res = psiconv_list_add(*result,worksheet))) |
1114 | goto ERROR3; |
1129 | goto ERROR3; |
1115 | free(worksheet); |
1130 | free(worksheet); |
1116 | } |
1131 | } |
1117 | |
1132 | |
1118 | if (length) |
1133 | if (length) |
1119 | *length = len; |
1134 | *length = len; |
1120 | |
1135 | |
1121 | psiconv_progress(lev,off+len-1, |
1136 | psiconv_progress(config,lev,off+len-1, |
1122 | "End of worksheet list (total length: %08x)", len); |
1137 | "End of worksheet list (total length: %08x)", len); |
1123 | |
1138 | |
1124 | return 0; |
1139 | return 0; |
1125 | |
1140 | |
1126 | ERROR3: |
1141 | ERROR3: |
1127 | psiconv_free_sheet_worksheet(worksheet); |
1142 | psiconv_free_sheet_worksheet(worksheet); |
1128 | ERROR2: |
1143 | ERROR2: |
1129 | psiconv_free_sheet_worksheet_list(*result); |
1144 | psiconv_free_sheet_worksheet_list(*result); |
1130 | ERROR1: |
1145 | ERROR1: |
1131 | psiconv_warn(lev+1,off,"Reading of worksheet list failed"); |
1146 | psiconv_warn(config,lev+1,off,"Reading of worksheet list failed"); |
1132 | if (length) |
1147 | if (length) |
1133 | *length = 0; |
1148 | *length = 0; |
1134 | if (!res) |
1149 | if (!res) |
1135 | return -PSICONV_E_NOMEM; |
1150 | return -PSICONV_E_NOMEM; |
1136 | else |
1151 | else |
1137 | return res; |
1152 | return res; |
1138 | } |
1153 | } |
1139 | |
1154 | |
1140 | int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, |
1155 | int psiconv_parse_sheet_cell_layout(const psiconv_config config, |
|
|
1156 | const psiconv_buffer buf, int lev, |
1141 | psiconv_u32 off, int *length, |
1157 | psiconv_u32 off, int *length, |
1142 | psiconv_sheet_cell_layout result) |
1158 | psiconv_sheet_cell_layout result) |
1143 | |
1159 | |
1144 | { |
1160 | { |
1145 | int res=0; |
1161 | int res=0; |
1146 | int len=0; |
1162 | int len=0; |
1147 | int leng; |
1163 | int leng; |
1148 | psiconv_u8 temp; |
1164 | psiconv_u8 temp; |
1149 | |
1165 | |
1150 | psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); |
1166 | psiconv_progress(config,lev+1,off,"Going to read a sheet cell layout"); |
1151 | |
1167 | |
1152 | psiconv_progress(lev+2,off+len, |
1168 | psiconv_progress(config,lev+2,off+len, |
1153 | "Going to read the first byte (%02x expected)",0x02); |
1169 | "Going to read the first byte (%02x expected)",0x02); |
1154 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1170 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1155 | if (res) |
1171 | if (res) |
1156 | goto ERROR1; |
1172 | goto ERROR1; |
1157 | if (temp != 0x02) { |
1173 | if (temp != 0x02) { |
1158 | psiconv_warn(lev+2,off+len, |
1174 | psiconv_warn(config,lev+2,off+len, |
1159 | "Worksheet section initial byte unknown value (ignored)"); |
1175 | "Worksheet section initial byte unknown value (ignored)"); |
1160 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1176 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
1161 | } |
1177 | } |
1162 | len ++; |
1178 | len ++; |
1163 | |
1179 | |
1164 | psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); |
1180 | psiconv_progress(config,lev+2,off+len,"Going to read the default formats flag"); |
1165 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1181 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1166 | if (res) |
1182 | if (res) |
1167 | goto ERROR1; |
1183 | goto ERROR1; |
1168 | len ++; |
1184 | len ++; |
1169 | |
1185 | |
1170 | if (temp & 0x01) { |
1186 | if (temp & 0x01) { |
1171 | psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes"); |
1187 | psiconv_progress(config,lev+3,off+len,"Going to read the default paragraph codes"); |
1172 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
1188 | if ((res = psiconv_parse_paragraph_layout_list(config,buf,lev+3,off+len,&leng, |
1173 | result->paragraph))) |
1189 | result->paragraph))) |
1174 | goto ERROR1; |
1190 | goto ERROR1; |
1175 | len += leng; |
1191 | len += leng; |
1176 | } |
1192 | } |
1177 | |
1193 | |
1178 | if (temp & 0x02) { |
1194 | if (temp & 0x02) { |
1179 | psiconv_progress(lev+3,off+len,"Going to read the default character codes"); |
1195 | psiconv_progress(config,lev+3,off+len,"Going to read the default character codes"); |
1180 | if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
1196 | if ((res = psiconv_parse_character_layout_list(config,buf,lev+3,off+len,&leng, |
1181 | result->character))) |
1197 | result->character))) |
1182 | goto ERROR1; |
1198 | goto ERROR1; |
1183 | len += leng; |
1199 | len += leng; |
1184 | } |
1200 | } |
1185 | |
1201 | |
1186 | if (temp & 0x04) { |
1202 | if (temp & 0x04) { |
1187 | psiconv_progress(lev+3,off+len, "Going to read the default number format"); |
1203 | psiconv_progress(config,lev+3,off+len, "Going to read the default number format"); |
1188 | psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, |
1204 | psiconv_parse_sheet_numberformat(config,buf,lev+3,off+len,&leng, |
1189 | result->numberformat); |
1205 | result->numberformat); |
1190 | len += leng; |
1206 | len += leng; |
1191 | } |
1207 | } |
1192 | |
1208 | |
1193 | if (length) |
1209 | if (length) |
1194 | *length = len; |
1210 | *length = len; |
1195 | |
1211 | |
1196 | psiconv_progress(lev,off+len-1, |
1212 | psiconv_progress(config,lev,off+len-1, |
1197 | "End of sheet cell layout (total length: %08x)", len); |
1213 | "End of sheet cell layout (total length: %08x)", len); |
1198 | |
1214 | |
1199 | return 0; |
1215 | return 0; |
1200 | |
1216 | |
1201 | ERROR1: |
1217 | ERROR1: |
1202 | psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); |
1218 | psiconv_warn(config,lev+1,off,"Reading of sheet cell layout failed"); |
1203 | if (length) |
1219 | if (length) |
1204 | *length = 0; |
1220 | *length = 0; |
1205 | if (!res) |
1221 | if (!res) |
1206 | return -PSICONV_E_NOMEM; |
1222 | return -PSICONV_E_NOMEM; |
1207 | else |
1223 | else |
1208 | return res; |
1224 | return res; |
1209 | } |
1225 | } |
1210 | |
1226 | |
1211 | |
1227 | |
1212 | int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, |
1228 | int psiconv_parse_sheet_worksheet(const psiconv_config config, |
|
|
1229 | const psiconv_buffer buf, int lev, |
1213 | psiconv_u32 off, int *length, |
1230 | psiconv_u32 off, int *length, |
1214 | psiconv_sheet_worksheet *result) |
1231 | psiconv_sheet_worksheet *result) |
1215 | { |
1232 | { |
1216 | int res=0; |
1233 | int res=0; |
1217 | psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off,unknown_off; |
1234 | psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off,unknown_off; |
1218 | int len=0; |
1235 | int len=0; |
1219 | int leng; |
1236 | int leng; |
1220 | |
1237 | |
1221 | psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
1238 | psiconv_progress(config,lev+1,off,"Going to read the sheet worksheet section"); |
1222 | if (!(*result = malloc(sizeof(**result)))) |
1239 | if (!(*result = malloc(sizeof(**result)))) |
1223 | goto ERROR1; |
1240 | goto ERROR1; |
1224 | |
1241 | |
1225 | psiconv_progress(lev+2,off+len, |
1242 | psiconv_progress(config,lev+2,off+len, |
1226 | "Going to read the initial bytes (%02x expected)",0x04); |
1243 | "Going to read the initial bytes (%02x expected)",0x04); |
1227 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1244 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1228 | if (res) |
1245 | if (res) |
1229 | goto ERROR2; |
1246 | goto ERROR2; |
1230 | if (temp != 0x04) { |
1247 | if (temp != 0x04) { |
1231 | psiconv_warn(lev+2,off+len, |
1248 | psiconv_warn(config,lev+2,off+len, |
1232 | "Worksheet section initial byte unknown value (ignored)"); |
1249 | "Worksheet section initial byte unknown value (ignored)"); |
1233 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1250 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
1234 | } |
1251 | } |
1235 | len ++; |
1252 | len ++; |
1236 | |
1253 | |
1237 | psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
1254 | psiconv_progress(config,lev+2,off+len, "Going to read the flags byte"); |
1238 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1255 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1239 | if (res) |
1256 | if (res) |
1240 | goto ERROR2; |
1257 | goto ERROR2; |
1241 | psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp); |
1258 | psiconv_debug(config,lev+2,off+len,"Flags byte: %02x",temp); |
1242 | (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; |
1259 | (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; |
1243 | if (temp & 0xfe) { |
1260 | if (temp & 0xfe) { |
1244 | psiconv_warn(lev+2,off+len, |
1261 | psiconv_warn(config,lev+2,off+len, |
1245 | "Worksheet section flags byte unknown bits (ignored)"); |
1262 | "Worksheet section flags byte unknown bits (ignored)"); |
1246 | } |
1263 | } |
1247 | len ++; |
1264 | len ++; |
1248 | |
1265 | |
1249 | psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); |
1266 | psiconv_progress(config,lev+2,off+len,"Going to read the default cell layout"); |
1250 | if (!((*result)->default_layout = psiconv_basic_cell_layout())) |
1267 | if (!((*result)->default_layout = psiconv_basic_cell_layout())) |
1251 | goto ERROR2; |
1268 | goto ERROR2; |
1252 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, |
1269 | if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len,&leng, |
1253 | (*result)->default_layout))) |
1270 | (*result)->default_layout))) |
1254 | goto ERROR3; |
1271 | goto ERROR3; |
1255 | len += leng; |
1272 | len += leng; |
1256 | |
1273 | |
1257 | psiconv_progress(lev+2,off+len, |
1274 | psiconv_progress(config,lev+2,off+len, |
1258 | "Going to read the offset of the row defaults Section"); |
1275 | "Going to read the offset of the row defaults Section"); |
1259 | rows_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1276 | rows_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1260 | if (res) |
1277 | if (res) |
1261 | goto ERROR3; |
1278 | goto ERROR3; |
1262 | psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off); |
1279 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",rows_off); |
1263 | len += 4; |
1280 | len += 4; |
1264 | |
1281 | |
1265 | psiconv_progress(lev+2,off+len, |
1282 | psiconv_progress(config,lev+2,off+len, |
1266 | "Going to read the offset of the column defaults Section"); |
1283 | "Going to read the offset of the column defaults Section"); |
1267 | cols_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1284 | cols_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1268 | if (res) |
1285 | if (res) |
1269 | goto ERROR3; |
1286 | goto ERROR3; |
1270 | psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off); |
1287 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",cols_off); |
1271 | len += 4; |
1288 | len += 4; |
1272 | |
1289 | |
1273 | psiconv_progress(lev+2,off+len, |
1290 | psiconv_progress(config,lev+2,off+len, |
1274 | "Going to read the offset of the Cells List"); |
1291 | "Going to read the offset of the Cells List"); |
1275 | cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1292 | cells_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1276 | if (res) |
1293 | if (res) |
1277 | goto ERROR3; |
1294 | goto ERROR3; |
1278 | psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off); |
1295 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",cells_off); |
1279 | len += 4; |
1296 | len += 4; |
1280 | |
1297 | |
1281 | psiconv_progress(lev+2,off+len, |
1298 | psiconv_progress(config,lev+2,off+len, |
1282 | "Going to read the offset of the Grid Section"); |
1299 | "Going to read the offset of the Grid Section"); |
1283 | grid_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1300 | grid_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1284 | if (res) |
1301 | if (res) |
1285 | goto ERROR3; |
1302 | goto ERROR3; |
1286 | psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
1303 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",grid_off); |
1287 | len += 4; |
1304 | len += 4; |
1288 | |
1305 | |
1289 | psiconv_progress(lev+2,off+len, |
1306 | psiconv_progress(config,lev+2,off+len, |
1290 | "Going to read the offset of the 3rd ??? Section"); |
1307 | "Going to read the offset of the 3rd ??? Section"); |
1291 | unknown_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1308 | unknown_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1292 | if (res) |
1309 | if (res) |
1293 | goto ERROR3; |
1310 | goto ERROR3; |
1294 | psiconv_debug(lev+2,off+len,"Offset: %04x",unknown_off); |
1311 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",unknown_off); |
1295 | len += 4; |
1312 | len += 4; |
1296 | |
1313 | |
1297 | psiconv_progress(lev+2,off+len, |
1314 | psiconv_progress(config,lev+2,off+len, |
1298 | "Going to read a long of the 3rd ??? Section " |
1315 | "Going to read a long of the 3rd ??? Section " |
1299 | "(%08x expected)",0x00); |
1316 | "(%08x expected)",0x00); |
1300 | temp = psiconv_read_u32(buf,lev+2,unknown_off,&res); |
1317 | temp = psiconv_read_u32(config,buf,lev+2,unknown_off,&res); |
1301 | if (res) |
1318 | if (res) |
1302 | goto ERROR3; |
1319 | goto ERROR3; |
1303 | if (temp != 0x00) { |
1320 | if (temp != 0x00) { |
1304 | psiconv_warn(lev+2,unknown_off, |
1321 | psiconv_warn(config,lev+2,unknown_off, |
1305 | "Unknown worksheet subsection has unknown contents (ignored)"); |
1322 | "Unknown worksheet subsection has unknown contents (ignored)"); |
1306 | psiconv_debug(lev+2,unknown_off,"Offset: %04x",temp); |
1323 | psiconv_debug(config,lev+2,unknown_off,"Offset: %04x",temp); |
1307 | } |
1324 | } |
1308 | len += 4; |
1325 | len += 4; |
1309 | |
1326 | |
1310 | psiconv_progress(lev+2,off+len,"Going to read the row defaults"); |
1327 | psiconv_progress(config,lev+2,off+len,"Going to read the row defaults"); |
1311 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL, |
1328 | if ((res = psiconv_parse_sheet_line_list(config,buf,lev+2,rows_off,NULL, |
1312 | &(*result)->row_default_layouts, |
1329 | &(*result)->row_default_layouts, |
1313 | (*result)->default_layout))) |
1330 | (*result)->default_layout))) |
1314 | goto ERROR3; |
1331 | goto ERROR3; |
1315 | |
1332 | |
1316 | psiconv_progress(lev+2,off+len,"Going to read the column defaults"); |
1333 | psiconv_progress(config,lev+2,off+len,"Going to read the column defaults"); |
1317 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,cols_off,NULL, |
1334 | if ((res = psiconv_parse_sheet_line_list(config,buf,lev+2,cols_off,NULL, |
1318 | &(*result)->col_default_layouts, |
1335 | &(*result)->col_default_layouts, |
1319 | (*result)->default_layout))) |
1336 | (*result)->default_layout))) |
1320 | goto ERROR4; |
1337 | goto ERROR4; |
1321 | |
1338 | |
1322 | psiconv_progress(lev+2,off+len,"Going to read the cells list"); |
1339 | psiconv_progress(config,lev+2,off+len,"Going to read the cells list"); |
1323 | if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, |
1340 | if ((res = psiconv_parse_sheet_cell_list(config,buf,lev+2,cells_off,NULL, |
1324 | &(*result)->cells, |
1341 | &(*result)->cells, |
1325 | (*result)->default_layout, |
1342 | (*result)->default_layout, |
1326 | (*result)->row_default_layouts, |
1343 | (*result)->row_default_layouts, |
1327 | (*result)->col_default_layouts))) |
1344 | (*result)->col_default_layouts))) |
1328 | goto ERROR5; |
1345 | goto ERROR5; |
1329 | |
1346 | |
1330 | |
1347 | |
1331 | psiconv_progress(lev+2,off+len,"Going to read the grid section"); |
1348 | psiconv_progress(config,lev+2,off+len,"Going to read the grid section"); |
1332 | if ((res = psiconv_parse_sheet_grid_section(buf,lev+2,grid_off,NULL, |
1349 | if ((res = psiconv_parse_sheet_grid_section(config,buf,lev+2,grid_off,NULL, |
1333 | &(*result)->grid))) |
1350 | &(*result)->grid))) |
1334 | goto ERROR6; |
1351 | goto ERROR6; |
1335 | |
1352 | |
1336 | |
1353 | |
1337 | |
1354 | |
1338 | if (length) |
1355 | if (length) |
1339 | *length = len; |
1356 | *length = len; |
1340 | |
1357 | |
1341 | psiconv_progress(lev,off+len-1, |
1358 | psiconv_progress(config,lev,off+len-1, |
1342 | "End of sheet worksheet section (total length: %08x)", len); |
1359 | "End of sheet worksheet section (total length: %08x)", len); |
1343 | return 0; |
1360 | return 0; |
1344 | |
1361 | |
1345 | ERROR6: |
1362 | ERROR6: |
1346 | psiconv_free_sheet_cell_list((*result)->cells); |
1363 | psiconv_free_sheet_cell_list((*result)->cells); |
… | |
… | |
1351 | ERROR3: |
1368 | ERROR3: |
1352 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
1369 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
1353 | ERROR2: |
1370 | ERROR2: |
1354 | free (*result); |
1371 | free (*result); |
1355 | ERROR1: |
1372 | ERROR1: |
1356 | psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); |
1373 | psiconv_warn(config,lev+1,off,"Reading of Sheet Worksheet Section failed"); |
1357 | if (length) |
1374 | if (length) |
1358 | *length = 0; |
1375 | *length = 0; |
1359 | if (!res) |
1376 | if (!res) |
1360 | return -PSICONV_E_NOMEM; |
1377 | return -PSICONV_E_NOMEM; |
1361 | else |
1378 | else |
1362 | return res; |
1379 | return res; |
1363 | } |
1380 | } |
1364 | |
1381 | |
1365 | int psiconv_parse_sheet_line(const psiconv_buffer buf, int lev, |
1382 | int psiconv_parse_sheet_line(const psiconv_config config, |
|
|
1383 | const psiconv_buffer buf, int lev, |
1366 | psiconv_u32 off, int *length, |
1384 | psiconv_u32 off, int *length, |
1367 | psiconv_sheet_line *result, |
1385 | psiconv_sheet_line *result, |
1368 | const psiconv_sheet_cell_layout default_layout) |
1386 | const psiconv_sheet_cell_layout default_layout) |
1369 | { |
1387 | { |
1370 | int res=0; |
1388 | int res=0; |
1371 | int len=0; |
1389 | int len=0; |
1372 | int leng; |
1390 | int leng; |
1373 | |
1391 | |
1374 | |
1392 | |
1375 | psiconv_progress(lev+1,off,"Going to read a sheet line"); |
1393 | psiconv_progress(config,lev+1,off,"Going to read a sheet line"); |
1376 | if (!(*result = malloc(sizeof(**result)))) |
1394 | if (!(*result = malloc(sizeof(**result)))) |
1377 | goto ERROR1; |
1395 | goto ERROR1; |
1378 | |
1396 | |
1379 | psiconv_progress(lev+2,off+len,"Going to read the line number"); |
1397 | psiconv_progress(config,lev+2,off+len,"Going to read the line number"); |
1380 | (*result)->position = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1398 | (*result)->position = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
1381 | if (res) |
1399 | if (res) |
1382 | goto ERROR2; |
1400 | goto ERROR2; |
1383 | psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->position); |
1401 | psiconv_debug(config,lev+2,off+len,"Line number: %d\n",(*result)->position); |
1384 | len += leng; |
1402 | len += leng; |
1385 | |
1403 | |
1386 | if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) |
1404 | if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) |
1387 | goto ERROR2; |
1405 | goto ERROR2; |
1388 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
1406 | if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len, |
1389 | &leng,(*result)->layout))) |
1407 | &leng,(*result)->layout))) |
1390 | goto ERROR3; |
1408 | goto ERROR3; |
1391 | len += leng; |
1409 | len += leng; |
1392 | |
1410 | |
1393 | if (length) |
1411 | if (length) |
1394 | *length = len; |
1412 | *length = len; |
1395 | |
1413 | |
1396 | psiconv_progress(lev,off+len-1, |
1414 | psiconv_progress(config,lev,off+len-1, |
1397 | "End of the sheet line (total length: %08x)", len); |
1415 | "End of the sheet line (total length: %08x)", len); |
1398 | return 0; |
1416 | return 0; |
1399 | |
1417 | |
1400 | ERROR3: |
1418 | ERROR3: |
1401 | psiconv_free_sheet_cell_layout((*result)->layout); |
1419 | psiconv_free_sheet_cell_layout((*result)->layout); |
1402 | ERROR2: |
1420 | ERROR2: |
1403 | free (*result); |
1421 | free (*result); |
1404 | ERROR1: |
1422 | ERROR1: |
1405 | psiconv_warn(lev+1,off,"Reading of the sheet line failed"); |
1423 | psiconv_warn(config,lev+1,off,"Reading of the sheet line failed"); |
1406 | if (length) |
1424 | if (length) |
1407 | *length = 0; |
1425 | *length = 0; |
1408 | if (!res) |
1426 | if (!res) |
1409 | return -PSICONV_E_NOMEM; |
1427 | return -PSICONV_E_NOMEM; |
1410 | else |
1428 | else |
1411 | return res; |
1429 | return res; |
1412 | } |
1430 | } |
1413 | |
1431 | |
1414 | |
1432 | |
1415 | int psiconv_parse_sheet_line_list(const psiconv_buffer buf, int lev, |
1433 | int psiconv_parse_sheet_line_list(const psiconv_config config, |
|
|
1434 | const psiconv_buffer buf, int lev, |
1416 | psiconv_u32 off, int *length, |
1435 | psiconv_u32 off, int *length, |
1417 | psiconv_sheet_line_list *result, |
1436 | psiconv_sheet_line_list *result, |
1418 | const psiconv_sheet_cell_layout default_layout) |
1437 | const psiconv_sheet_cell_layout default_layout) |
1419 | { |
1438 | { |
1420 | int res=0; |
1439 | int res=0; |
… | |
… | |
1422 | psiconv_u32 temp; |
1441 | psiconv_u32 temp; |
1423 | psiconv_sheet_line line; |
1442 | psiconv_sheet_line line; |
1424 | psiconv_u32 listlen,i; |
1443 | psiconv_u32 listlen,i; |
1425 | int leng; |
1444 | int leng; |
1426 | |
1445 | |
1427 | psiconv_progress(lev+1,off,"Going to read the sheet line list"); |
1446 | psiconv_progress(config,lev+1,off,"Going to read the sheet line list"); |
1428 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s)))) |
1447 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s)))) |
1429 | goto ERROR1; |
1448 | goto ERROR1; |
1430 | |
1449 | |
1431 | psiconv_progress(lev+2,off+len, |
1450 | psiconv_progress(config,lev+2,off+len, |
1432 | "Going to read the initial byte (%02x expected)",0x02); |
1451 | "Going to read the initial byte (%02x expected)",0x02); |
1433 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1452 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1434 | if (res) |
1453 | if (res) |
1435 | goto ERROR2; |
1454 | goto ERROR2; |
1436 | if (temp != 0x02) { |
1455 | if (temp != 0x02) { |
1437 | psiconv_warn(lev+2,off+len, |
1456 | psiconv_warn(config,lev+2,off+len, |
1438 | "Sheet line list initial byte unknown value (ignored)"); |
1457 | "Sheet line list initial byte unknown value (ignored)"); |
1439 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1458 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
1440 | } |
1459 | } |
1441 | len ++; |
1460 | len ++; |
1442 | |
1461 | |
1443 | psiconv_progress(lev+2,off+len, |
1462 | psiconv_progress(config,lev+2,off+len, |
1444 | "Going to read the number of defined lines"); |
1463 | "Going to read the number of defined lines"); |
1445 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1464 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
1446 | if (res) |
1465 | if (res) |
1447 | goto ERROR2; |
1466 | goto ERROR2; |
1448 | psiconv_debug(lev+2,off+len,"Number of defined lines: %d",listlen); |
1467 | psiconv_debug(config,lev+2,off+len,"Number of defined lines: %d",listlen); |
1449 | len += leng; |
1468 | len += leng; |
1450 | |
1469 | |
1451 | psiconv_progress(lev+2,off+len,"Going to read all lines"); |
1470 | psiconv_progress(config,lev+2,off+len,"Going to read all lines"); |
1452 | for (i = 0; i < listlen; i++) { |
1471 | for (i = 0; i < listlen; i++) { |
1453 | psiconv_progress(lev+3,off+len,"Going to read line %d",i); |
1472 | psiconv_progress(config,lev+3,off+len,"Going to read line %d",i); |
1454 | if ((res = psiconv_parse_sheet_line(buf,lev+3,off+len,&leng,&line, |
1473 | if ((res = psiconv_parse_sheet_line(config,buf,lev+3,off+len,&leng,&line, |
1455 | default_layout))) |
1474 | default_layout))) |
1456 | goto ERROR2; |
1475 | goto ERROR2; |
1457 | if ((res = psiconv_list_add(*result,line))) |
1476 | if ((res = psiconv_list_add(*result,line))) |
1458 | goto ERROR3; |
1477 | goto ERROR3; |
1459 | free(line); |
1478 | free(line); |
… | |
… | |
1461 | } |
1480 | } |
1462 | |
1481 | |
1463 | if (length) |
1482 | if (length) |
1464 | *length = len; |
1483 | *length = len; |
1465 | |
1484 | |
1466 | psiconv_progress(lev,off+len-1, |
1485 | psiconv_progress(config,lev,off+len-1, |
1467 | "End of sheet line list (total length: %08x)", len); |
1486 | "End of sheet line list (total length: %08x)", len); |
1468 | return 0; |
1487 | return 0; |
1469 | |
1488 | |
1470 | ERROR3: |
1489 | ERROR3: |
1471 | psiconv_free_sheet_line(line); |
1490 | psiconv_free_sheet_line(line); |
1472 | ERROR2: |
1491 | ERROR2: |
1473 | psiconv_free_sheet_line_list(*result); |
1492 | psiconv_free_sheet_line_list(*result); |
1474 | ERROR1: |
1493 | ERROR1: |
1475 | psiconv_warn(lev+1,off,"Reading of Sheet Line List failed"); |
1494 | psiconv_warn(config,lev+1,off,"Reading of Sheet Line List failed"); |
1476 | if (length) |
1495 | if (length) |
1477 | *length = 0; |
1496 | *length = 0; |
1478 | if (!res) |
1497 | if (!res) |
1479 | return -PSICONV_E_NOMEM; |
1498 | return -PSICONV_E_NOMEM; |
1480 | else |
1499 | else |
1481 | return res; |
1500 | return res; |
1482 | } |
1501 | } |
1483 | |
1502 | |
1484 | int psiconv_parse_sheet_variable(const psiconv_buffer buf, int lev, |
1503 | int psiconv_parse_sheet_variable(const psiconv_config config, |
|
|
1504 | const psiconv_buffer buf, int lev, |
1485 | psiconv_u32 off, int *length, |
1505 | psiconv_u32 off, int *length, |
1486 | psiconv_sheet_variable *result) |
1506 | psiconv_sheet_variable *result) |
1487 | { |
1507 | { |
1488 | int res=0; |
1508 | int res=0; |
1489 | int len=0; |
1509 | int len=0; |
1490 | psiconv_u32 marker; |
1510 | psiconv_u32 marker; |
1491 | int leng; |
1511 | int leng; |
1492 | |
1512 | |
1493 | psiconv_progress(lev+1,off,"Going to read a sheet variable"); |
1513 | psiconv_progress(config,lev+1,off,"Going to read a sheet variable"); |
1494 | if (!(*result = malloc(sizeof(**result)))) |
1514 | if (!(*result = malloc(sizeof(**result)))) |
1495 | goto ERROR1; |
1515 | goto ERROR1; |
1496 | |
1516 | |
1497 | psiconv_progress(lev+2,off+len, "Going to read the variable name"); |
1517 | psiconv_progress(config,lev+2,off+len, "Going to read the variable name"); |
1498 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
1518 | (*result)->name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
1499 | if (res) |
1519 | if (res) |
1500 | goto ERROR2; |
1520 | goto ERROR2; |
1501 | len += leng; |
1521 | len += leng; |
1502 | |
1522 | |
1503 | psiconv_progress(lev+2,off+len,"Going to read the type marker"); |
1523 | psiconv_progress(config,lev+2,off+len,"Going to read the type marker"); |
1504 | marker = psiconv_read_u8(buf,lev+2,off+len,&res); |
1524 | marker = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1505 | if (res) |
1525 | if (res) |
1506 | goto ERROR3; |
1526 | goto ERROR3; |
1507 | psiconv_debug(lev+2,off+len,"Marker: %02x",marker); |
1527 | psiconv_debug(config,lev+2,off+len,"Marker: %02x",marker); |
1508 | len ++; |
1528 | len ++; |
1509 | |
1529 | |
1510 | if (marker == 0x00) { |
1530 | if (marker == 0x00) { |
1511 | (*result)->type = psiconv_var_int; |
1531 | (*result)->type = psiconv_var_int; |
1512 | psiconv_progress(lev+2,off+len,"Going to read a signed integer"); |
1532 | psiconv_progress(config,lev+2,off+len,"Going to read a signed integer"); |
1513 | (*result)->data.dat_int = psiconv_read_sint(buf,lev+2,off+len,&leng,&res); |
1533 | (*result)->data.dat_int = psiconv_read_sint(config,buf,lev+2,off+len,&leng,&res); |
1514 | if (res) |
1534 | if (res) |
1515 | goto ERROR3; |
1535 | goto ERROR3; |
1516 | psiconv_debug(lev+2,off+len,"Value: %d",(*result)->data.dat_int); |
1536 | psiconv_debug(config,lev+2,off+len,"Value: %d",(*result)->data.dat_int); |
1517 | len += leng; |
1537 | len += leng; |
1518 | } else if (marker == 0x01) { |
1538 | } else if (marker == 0x01) { |
1519 | (*result)->type = psiconv_var_float; |
1539 | (*result)->type = psiconv_var_float; |
1520 | psiconv_progress(lev+2,off+len,"Going to read a floating point number"); |
1540 | psiconv_progress(config,lev+2,off+len,"Going to read a floating point number"); |
1521 | (*result)->data.dat_float = psiconv_read_float(buf,lev+2,off+len,&leng, |
1541 | (*result)->data.dat_float = psiconv_read_float(config,buf,lev+2,off+len,&leng, |
1522 | &res); |
1542 | &res); |
1523 | if (res) |
1543 | if (res) |
1524 | goto ERROR3; |
1544 | goto ERROR3; |
1525 | psiconv_debug(lev+2,off+len,"Value: %f",(*result)->data.dat_float); |
1545 | psiconv_debug(config,lev+2,off+len,"Value: %f",(*result)->data.dat_float); |
1526 | len += leng; |
1546 | len += leng; |
1527 | } else if (marker == 0x02) { |
1547 | } else if (marker == 0x02) { |
1528 | (*result)->type = psiconv_var_string; |
1548 | (*result)->type = psiconv_var_string; |
1529 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
1549 | psiconv_progress(config,lev+2,off+len,"Going to read a string"); |
1530 | (*result)->data.dat_string = psiconv_read_string(buf,lev+2,off+len,&leng, |
1550 | (*result)->data.dat_string = psiconv_read_string(config,buf,lev+2,off+len,&leng, |
1531 | &res); |
1551 | &res); |
1532 | if (res) |
1552 | if (res) |
1533 | goto ERROR3; |
1553 | goto ERROR3; |
1534 | len += leng; |
1554 | len += leng; |
1535 | } else if (marker == 0x03) { |
1555 | } else if (marker == 0x03) { |
1536 | (*result)->type = psiconv_var_cellref; |
1556 | (*result)->type = psiconv_var_cellref; |
1537 | psiconv_progress(lev+2,off+len,"Going to read a cell reference"); |
1557 | psiconv_progress(config,lev+2,off+len,"Going to read a cell reference"); |
1538 | (*result)->data.dat_cellref = psiconv_read_var_cellref(buf,lev+2,off+len, |
1558 | (*result)->data.dat_cellref = psiconv_read_var_cellref(config,buf,lev+2,off+len, |
1539 | &leng, &res); |
1559 | &leng, &res); |
1540 | if (res) |
1560 | if (res) |
1541 | goto ERROR3; |
1561 | goto ERROR3; |
1542 | len += leng; |
1562 | len += leng; |
1543 | } else if (marker == 0x04) { |
1563 | } else if (marker == 0x04) { |
1544 | (*result)->type = psiconv_var_cellblock; |
1564 | (*result)->type = psiconv_var_cellblock; |
1545 | psiconv_progress(lev+2,off+len,"Going to read a cell block reference"); |
1565 | psiconv_progress(config,lev+2,off+len,"Going to read a cell block reference"); |
1546 | (*result)->data.dat_cellblock = psiconv_read_var_cellblock(buf,lev+2, |
1566 | (*result)->data.dat_cellblock = psiconv_read_var_cellblock(config,buf,lev+2, |
1547 | off+len, |
1567 | off+len, |
1548 | &leng, &res); |
1568 | &leng, &res); |
1549 | if (res) |
1569 | if (res) |
1550 | goto ERROR3; |
1570 | goto ERROR3; |
1551 | len += leng; |
1571 | len += leng; |
1552 | } else { |
1572 | } else { |
1553 | psiconv_warn(lev+2,off+len,"Sheet variable unknown type marker"); |
1573 | psiconv_warn(config,lev+2,off+len,"Sheet variable unknown type marker"); |
1554 | res = -PSICONV_E_PARSE; |
1574 | res = -PSICONV_E_PARSE; |
1555 | goto ERROR3; |
1575 | goto ERROR3; |
1556 | } |
1576 | } |
1557 | |
1577 | |
1558 | psiconv_progress(lev+2,off+len,"Going to read the variable number"); |
1578 | psiconv_progress(config,lev+2,off+len,"Going to read the variable number"); |
1559 | (*result)->number = psiconv_read_u32(buf,lev+2,off+len,&res); |
1579 | (*result)->number = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1560 | if (res) |
1580 | if (res) |
1561 | goto ERROR4; |
1581 | goto ERROR4; |
1562 | psiconv_debug(lev+2,off+len,"Number: %08x",(*result)->number); |
1582 | psiconv_debug(config,lev+2,off+len,"Number: %08x",(*result)->number); |
1563 | len += 4; |
1583 | len += 4; |
1564 | |
1584 | |
1565 | if (length) |
1585 | if (length) |
1566 | *length = len; |
1586 | *length = len; |
1567 | |
1587 | |
1568 | psiconv_progress(lev,off+len-1, |
1588 | psiconv_progress(config,lev,off+len-1, |
1569 | "End of sheet variable (total length: %08x)", len); |
1589 | "End of sheet variable (total length: %08x)", len); |
1570 | return 0; |
1590 | return 0; |
1571 | |
1591 | |
1572 | ERROR4: |
1592 | ERROR4: |
1573 | if ((*result)->type == psiconv_var_string) |
1593 | if ((*result)->type == psiconv_var_string) |
… | |
… | |
1575 | ERROR3: |
1595 | ERROR3: |
1576 | free((*result)->name); |
1596 | free((*result)->name); |
1577 | ERROR2: |
1597 | ERROR2: |
1578 | free (*result); |
1598 | free (*result); |
1579 | ERROR1: |
1599 | ERROR1: |
1580 | psiconv_warn(lev+1,off,"Reading of Sheet Variable failed"); |
1600 | psiconv_warn(config,lev+1,off,"Reading of Sheet Variable failed"); |
1581 | if (length) |
1601 | if (length) |
1582 | *length = 0; |
1602 | *length = 0; |
1583 | if (!res) |
1603 | if (!res) |
1584 | return -PSICONV_E_NOMEM; |
1604 | return -PSICONV_E_NOMEM; |
1585 | else |
1605 | else |
1586 | return res; |
1606 | return res; |
1587 | } |
1607 | } |
1588 | |
1608 | |
1589 | |
1609 | |
1590 | int psiconv_parse_sheet_variable_list(const psiconv_buffer buf, int lev, |
1610 | int psiconv_parse_sheet_variable_list(const psiconv_config config, |
|
|
1611 | const psiconv_buffer buf, int lev, |
1591 | psiconv_u32 off, int *length, |
1612 | psiconv_u32 off, int *length, |
1592 | psiconv_sheet_variable_list *result) |
1613 | psiconv_sheet_variable_list *result) |
1593 | { |
1614 | { |
1594 | int res=0; |
1615 | int res=0; |
1595 | int len=0; |
1616 | int len=0; |
1596 | psiconv_u32 temp; |
1617 | psiconv_u32 temp; |
1597 | psiconv_sheet_variable variable; |
1618 | psiconv_sheet_variable variable; |
1598 | psiconv_u32 listlen,i; |
1619 | psiconv_u32 listlen,i; |
1599 | int leng; |
1620 | int leng; |
1600 | |
1621 | |
1601 | psiconv_progress(lev+1,off,"Going to read the sheet variable list"); |
1622 | psiconv_progress(config,lev+1,off,"Going to read the sheet variable list"); |
1602 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s)))) |
1623 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s)))) |
1603 | goto ERROR1; |
1624 | goto ERROR1; |
1604 | |
1625 | |
1605 | psiconv_progress(lev+2,off+len, |
1626 | psiconv_progress(config,lev+2,off+len, |
1606 | "Going to read the initial byte (%02x expected)",0x02); |
1627 | "Going to read the initial byte (%02x expected)",0x02); |
1607 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1628 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1608 | if (res) |
1629 | if (res) |
1609 | goto ERROR2; |
1630 | goto ERROR2; |
1610 | if (temp != 0x02) { |
1631 | if (temp != 0x02) { |
1611 | psiconv_warn(lev+2,off+len, |
1632 | psiconv_warn(config,lev+2,off+len, |
1612 | "Sheet variable list initial byte unknown value (ignored)"); |
1633 | "Sheet variable list initial byte unknown value (ignored)"); |
1613 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1634 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
1614 | } |
1635 | } |
1615 | len ++; |
1636 | len ++; |
1616 | |
1637 | |
1617 | psiconv_progress(lev+2,off+len, |
1638 | psiconv_progress(config,lev+2,off+len, |
1618 | "Going to read the number of variables"); |
1639 | "Going to read the number of variables"); |
1619 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1640 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
1620 | if (res) |
1641 | if (res) |
1621 | goto ERROR2; |
1642 | goto ERROR2; |
1622 | psiconv_debug(lev+2,off+len,"Number of variables: %d",listlen); |
1643 | psiconv_debug(config,lev+2,off+len,"Number of variables: %d",listlen); |
1623 | len += leng; |
1644 | len += leng; |
1624 | |
1645 | |
1625 | psiconv_progress(lev+2,off+len,"Going to read all variables"); |
1646 | psiconv_progress(config,lev+2,off+len,"Going to read all variables"); |
1626 | for (i = 0; i < listlen; i++) { |
1647 | for (i = 0; i < listlen; i++) { |
1627 | psiconv_progress(lev+3,off+len,"Going to read variable %d",i); |
1648 | psiconv_progress(config,lev+3,off+len,"Going to read variable %d",i); |
1628 | if ((res = psiconv_parse_sheet_variable(buf,lev+3,off+len,&leng,&variable))) |
1649 | if ((res = psiconv_parse_sheet_variable(config,buf,lev+3,off+len,&leng,&variable))) |
1629 | goto ERROR2; |
1650 | goto ERROR2; |
1630 | if ((res = psiconv_list_add(*result,variable))) |
1651 | if ((res = psiconv_list_add(*result,variable))) |
1631 | goto ERROR3; |
1652 | goto ERROR3; |
1632 | len += leng; |
1653 | len += leng; |
1633 | } |
1654 | } |
1634 | |
1655 | |
1635 | if (length) |
1656 | if (length) |
1636 | *length = len; |
1657 | *length = len; |
1637 | |
1658 | |
1638 | psiconv_progress(lev,off+len-1, |
1659 | psiconv_progress(config,lev,off+len-1, |
1639 | "End of sheet variabels list (total length: %08x)", len); |
1660 | "End of sheet variabels list (total length: %08x)", len); |
1640 | return 0; |
1661 | return 0; |
1641 | |
1662 | |
1642 | ERROR3: |
1663 | ERROR3: |
1643 | psiconv_free_sheet_variable(variable); |
1664 | psiconv_free_sheet_variable(variable); |
1644 | ERROR2: |
1665 | ERROR2: |
1645 | psiconv_list_free(*result); |
1666 | psiconv_list_free(*result); |
1646 | ERROR1: |
1667 | ERROR1: |
1647 | psiconv_warn(lev+1,off,"Reading of Sheet Variable list failed"); |
1668 | psiconv_warn(config,lev+1,off,"Reading of Sheet Variable list failed"); |
1648 | if (length) |
1669 | if (length) |
1649 | *length = 0; |
1670 | *length = 0; |
1650 | if (!res) |
1671 | if (!res) |
1651 | return -PSICONV_E_NOMEM; |
1672 | return -PSICONV_E_NOMEM; |
1652 | else |
1673 | else |
1653 | return res; |
1674 | return res; |
1654 | } |
1675 | } |
1655 | |
1676 | |
1656 | int psiconv_parse_sheet_grid_section(const psiconv_buffer buf, int lev, |
1677 | int psiconv_parse_sheet_grid_section(const psiconv_config config, |
|
|
1678 | const psiconv_buffer buf, int lev, |
1657 | psiconv_u32 off, int *length, |
1679 | psiconv_u32 off, int *length, |
1658 | psiconv_sheet_grid_section *result) |
1680 | psiconv_sheet_grid_section *result) |
1659 | { |
1681 | { |
1660 | int res=0,i; |
1682 | int res=0,i; |
1661 | int len=0,leng; |
1683 | int len=0,leng; |
1662 | psiconv_u32 temp; |
1684 | psiconv_u32 temp; |
1663 | |
1685 | |
1664 | psiconv_progress(lev+1,off,"Going to read the sheet grid section"); |
1686 | psiconv_progress(config,lev+1,off,"Going to read the sheet grid section"); |
1665 | if (!(*result = malloc(sizeof(**result)))) |
1687 | if (!(*result = malloc(sizeof(**result)))) |
1666 | goto ERROR1; |
1688 | goto ERROR1; |
1667 | |
1689 | |
1668 | psiconv_progress(lev+2,off+len, "Going to read the first flags byte"); |
1690 | psiconv_progress(config,lev+2,off+len, "Going to read the first flags byte"); |
1669 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1691 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1670 | if (res) |
1692 | if (res) |
1671 | goto ERROR2; |
1693 | goto ERROR2; |
1672 | (*result)->show_column_titles = temp&0x01?psiconv_bool_true: |
1694 | (*result)->show_column_titles = temp&0x01?psiconv_bool_true: |
1673 | psiconv_bool_false; |
1695 | psiconv_bool_false; |
1674 | psiconv_debug(lev+2,off+len, |
1696 | psiconv_debug(config,lev+2,off+len, |
1675 | "Show column titles: %s", |
1697 | "Show column titles: %s", |
1676 | (*result)->show_column_titles?"true":"false"); |
1698 | (*result)->show_column_titles?"true":"false"); |
1677 | (*result)->show_row_titles = temp&0x02?psiconv_bool_true:psiconv_bool_false; |
1699 | (*result)->show_row_titles = temp&0x02?psiconv_bool_true:psiconv_bool_false; |
1678 | psiconv_debug(lev+2,off+len, |
1700 | psiconv_debug(config,lev+2,off+len, |
1679 | "Show row titles: %s", |
1701 | "Show row titles: %s", |
1680 | (*result)->show_row_titles?"true":"false"); |
1702 | (*result)->show_row_titles?"true":"false"); |
1681 | (*result)->show_vertical_grid = temp&0x04?psiconv_bool_true: |
1703 | (*result)->show_vertical_grid = temp&0x04?psiconv_bool_true: |
1682 | psiconv_bool_false; |
1704 | psiconv_bool_false; |
1683 | psiconv_debug(lev+2,off+len, |
1705 | psiconv_debug(config,lev+2,off+len, |
1684 | "Show vertical grid: %s", |
1706 | "Show vertical grid: %s", |
1685 | (*result)->show_vertical_grid?"true":"false"); |
1707 | (*result)->show_vertical_grid?"true":"false"); |
1686 | (*result)->show_horizontal_grid = temp&0x07?psiconv_bool_true: |
1708 | (*result)->show_horizontal_grid = temp&0x07?psiconv_bool_true: |
1687 | psiconv_bool_false; |
1709 | psiconv_bool_false; |
1688 | psiconv_debug(lev+2,off+len, |
1710 | psiconv_debug(config,lev+2,off+len, |
1689 | "Show horizontal grid: %s", |
1711 | "Show horizontal grid: %s", |
1690 | (*result)->show_horizontal_grid?"true":"false"); |
1712 | (*result)->show_horizontal_grid?"true":"false"); |
1691 | (*result)->freeze_rows = temp&0x80?psiconv_bool_true:psiconv_bool_false; |
1713 | (*result)->freeze_rows = temp&0x80?psiconv_bool_true:psiconv_bool_false; |
1692 | psiconv_debug(lev+2,off+len, |
1714 | psiconv_debug(config,lev+2,off+len, |
1693 | "Freeze rows: %s", |
1715 | "Freeze rows: %s", |
1694 | (*result)->freeze_rows?"true":"false"); |
1716 | (*result)->freeze_rows?"true":"false"); |
1695 | if ((temp & 0x70) != 0x30) { |
1717 | if ((temp & 0x70) != 0x30) { |
1696 | psiconv_warn(lev+2,off+len, |
1718 | psiconv_warn(config,lev+2,off+len, |
1697 | "Grid section first flag byte has unknown bits (ignored)"); |
1719 | "Grid section first flag byte has unknown bits (ignored)"); |
1698 | psiconv_debug(lev+2,off+len,"Bits: %02x (%02x expected)",temp&0x70,0x30); |
1720 | psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0x70,0x30); |
1699 | } |
1721 | } |
1700 | len ++; |
1722 | len ++; |
1701 | |
1723 | |
1702 | psiconv_progress(lev+2,off+len, "Going to read the second flags byte"); |
1724 | psiconv_progress(config,lev+2,off+len, "Going to read the second flags byte"); |
1703 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1725 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1704 | if (res) |
1726 | if (res) |
1705 | goto ERROR2; |
1727 | goto ERROR2; |
1706 | (*result)->freeze_columns = temp&0x01?psiconv_bool_true:psiconv_bool_false; |
1728 | (*result)->freeze_columns = temp&0x01?psiconv_bool_true:psiconv_bool_false; |
1707 | psiconv_debug(lev+2,off+len, |
1729 | psiconv_debug(config,lev+2,off+len, |
1708 | "Freeze columns: %s", (*result)->freeze_columns?"true":"false"); |
1730 | "Freeze columns: %s", (*result)->freeze_columns?"true":"false"); |
1709 | if ((temp & 0xfe) != 0x80) { |
1731 | if ((temp & 0xfe) != 0x80) { |
1710 | psiconv_warn(lev+2,off+len, |
1732 | psiconv_warn(config,lev+2,off+len, |
1711 | "Grid section second flag byte has unknown bits (ignored)"); |
1733 | "Grid section second flag byte has unknown bits (ignored)"); |
1712 | psiconv_debug(lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfe,0x80); |
1734 | psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfe,0x80); |
1713 | } |
1735 | } |
1714 | len ++; |
1736 | len ++; |
1715 | |
1737 | |
1716 | psiconv_progress(lev+2,off+len, |
1738 | psiconv_progress(config,lev+2,off+len, |
1717 | "Going to an unknown byte (%02x expected)",0x90); |
1739 | "Going to an unknown byte (%02x expected)",0x90); |
1718 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1740 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1719 | if (res) |
1741 | if (res) |
1720 | goto ERROR2; |
1742 | goto ERROR2; |
1721 | if (temp != 0x90) { |
1743 | if (temp != 0x90) { |
1722 | psiconv_warn(lev+2,off+len, |
1744 | psiconv_warn(config,lev+2,off+len, |
1723 | "Grid section third byte unknown value (ignored)"); |
1745 | "Grid section third byte unknown value (ignored)"); |
1724 | psiconv_debug(lev+2,off+len,"Value: %02x",temp); |
1746 | psiconv_debug(config,lev+2,off+len,"Value: %02x",temp); |
1725 | } |
1747 | } |
1726 | len ++; |
1748 | len ++; |
1727 | |
1749 | |
1728 | psiconv_progress(lev+2,off+len, "Going to read the fourth flags byte"); |
1750 | psiconv_progress(config,lev+2,off+len, "Going to read the fourth flags byte"); |
1729 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1751 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1730 | if (res) |
1752 | if (res) |
1731 | goto ERROR2; |
1753 | goto ERROR2; |
1732 | (*result)->show_page_breaks = temp&0x04?psiconv_bool_true:psiconv_bool_false; |
1754 | (*result)->show_page_breaks = temp&0x04?psiconv_bool_true:psiconv_bool_false; |
1733 | psiconv_debug(lev+2,off+len, |
1755 | psiconv_debug(config,lev+2,off+len, |
1734 | "Show page breaks: %s", |
1756 | "Show page breaks: %s", |
1735 | (*result)->show_page_breaks?"true":"false"); |
1757 | (*result)->show_page_breaks?"true":"false"); |
1736 | if ((temp & 0xfc) != 0x00) { |
1758 | if ((temp & 0xfc) != 0x00) { |
1737 | psiconv_warn(lev+2,off+len, |
1759 | psiconv_warn(config,lev+2,off+len, |
1738 | "Grid section fourth flag byte has unknown bits (ignored)"); |
1760 | "Grid section fourth flag byte has unknown bits (ignored)"); |
1739 | psiconv_debug(lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfc,0x00); |
1761 | psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfc,0x00); |
1740 | } |
1762 | } |
1741 | len ++; |
1763 | len ++; |
1742 | |
1764 | |
1743 | psiconv_progress(lev+2,off+len,"Going to read the first visible row"); |
1765 | psiconv_progress(config,lev+2,off+len,"Going to read the first visible row"); |
1744 | (*result)->first_row = psiconv_read_u32(buf,lev+2,off+len,&res); |
1766 | (*result)->first_row = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1745 | if (res) |
1767 | if (res) |
1746 | goto ERROR2; |
1768 | goto ERROR2; |
1747 | psiconv_debug(lev+2,off+len,"First row: %d",(*result)->first_row); |
1769 | psiconv_debug(config,lev+2,off+len,"First row: %d",(*result)->first_row); |
1748 | len += 4; |
1770 | len += 4; |
1749 | |
1771 | |
1750 | psiconv_progress(lev+2,off+len,"Going to read the first visible column"); |
1772 | psiconv_progress(config,lev+2,off+len,"Going to read the first visible column"); |
1751 | (*result)->first_column = psiconv_read_u32(buf,lev+2,off+len,&res); |
1773 | (*result)->first_column = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1752 | if (res) |
1774 | if (res) |
1753 | goto ERROR2; |
1775 | goto ERROR2; |
1754 | psiconv_debug(lev+2,off+len,"First column: %d",(*result)->first_column); |
1776 | psiconv_debug(config,lev+2,off+len,"First column: %d",(*result)->first_column); |
1755 | len += 4; |
1777 | len += 4; |
1756 | |
1778 | |
1757 | psiconv_progress(lev+2,off+len,"Going to read the last visible row"); |
1779 | psiconv_progress(config,lev+2,off+len,"Going to read the last visible row"); |
1758 | (*result)->last_row = psiconv_read_u32(buf,lev+2,off+len,&res); |
1780 | (*result)->last_row = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1759 | if (res) |
1781 | if (res) |
1760 | goto ERROR2; |
1782 | goto ERROR2; |
1761 | psiconv_debug(lev+2,off+len,"Last row: %d",(*result)->last_row); |
1783 | psiconv_debug(config,lev+2,off+len,"Last row: %d",(*result)->last_row); |
1762 | len += 4; |
1784 | len += 4; |
1763 | |
1785 | |
1764 | psiconv_progress(lev+2,off+len,"Going to read the last visible column"); |
1786 | psiconv_progress(config,lev+2,off+len,"Going to read the last visible column"); |
1765 | (*result)->last_column = psiconv_read_u32(buf,lev+2,off+len,&res); |
1787 | (*result)->last_column = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1766 | if (res) |
1788 | if (res) |
1767 | goto ERROR2; |
1789 | goto ERROR2; |
1768 | psiconv_debug(lev+2,off+len,"Last column: %d",(*result)->last_column); |
1790 | psiconv_debug(config,lev+2,off+len,"Last column: %d",(*result)->last_column); |
1769 | len += 4; |
1791 | len += 4; |
1770 | |
1792 | |
1771 | psiconv_progress(lev+2,off+len,"Going to read the default row height"); |
1793 | psiconv_progress(config,lev+2,off+len,"Going to read the default row height"); |
1772 | (*result)->default_row_height = psiconv_read_length(buf,lev+2,off+len, |
1794 | (*result)->default_row_height = psiconv_read_length(config,buf,lev+2,off+len, |
1773 | &leng,&res); |
1795 | &leng,&res); |
1774 | if (res) |
1796 | if (res) |
1775 | goto ERROR2; |
1797 | goto ERROR2; |
1776 | psiconv_debug(lev+2,off+len,"Default row height: %f", |
1798 | psiconv_debug(config,lev+2,off+len,"Default row height: %f", |
1777 | (*result)->default_row_height); |
1799 | (*result)->default_row_height); |
1778 | len += leng; |
1800 | len += leng; |
1779 | |
1801 | |
1780 | psiconv_progress(lev+2,off+len,"Going to read the row heights list"); |
1802 | psiconv_progress(config,lev+2,off+len,"Going to read the row heights list"); |
1781 | if ((res = psiconv_parse_sheet_grid_size_list(buf,lev+2,off+len,&leng, |
1803 | if ((res = psiconv_parse_sheet_grid_size_list(config,buf,lev+2,off+len,&leng, |
1782 | &(*result)->row_heights))) |
1804 | &(*result)->row_heights))) |
1783 | goto ERROR2; |
1805 | goto ERROR2; |
1784 | len += leng; |
1806 | len += leng; |
1785 | |
1807 | |
1786 | psiconv_progress(lev+2,off+len,"Going to read the default column height"); |
1808 | psiconv_progress(config,lev+2,off+len,"Going to read the default column height"); |
1787 | (*result)->default_column_width = psiconv_read_length(buf,lev+2,off+len, |
1809 | (*result)->default_column_width = psiconv_read_length(config,buf,lev+2,off+len, |
1788 | &leng,&res); |
1810 | &leng,&res); |
1789 | if (res) |
1811 | if (res) |
1790 | goto ERROR3; |
1812 | goto ERROR3; |
1791 | psiconv_debug(lev+2,off+len,"Default column width: %f", |
1813 | psiconv_debug(config,lev+2,off+len,"Default column width: %f", |
1792 | (*result)->default_column_width); |
1814 | (*result)->default_column_width); |
1793 | len += leng; |
1815 | len += leng; |
1794 | |
1816 | |
1795 | psiconv_progress(lev+2,off+len,"Going to read the column heights list"); |
1817 | psiconv_progress(config,lev+2,off+len,"Going to read the column heights list"); |
1796 | if ((res = psiconv_parse_sheet_grid_size_list(buf,lev+2,off+len,&leng, |
1818 | if ((res = psiconv_parse_sheet_grid_size_list(config,buf,lev+2,off+len,&leng, |
1797 | &(*result)->column_heights))) |
1819 | &(*result)->column_heights))) |
1798 | goto ERROR3; |
1820 | goto ERROR3; |
1799 | len += leng; |
1821 | len += leng; |
1800 | |
1822 | |
1801 | psiconv_progress(lev+2,off+len, |
1823 | psiconv_progress(config,lev+2,off+len, |
1802 | "Going to read an unknown word (%04x expected)",0x00); |
1824 | "Going to read an unknown word (%04x expected)",0x00); |
1803 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
1825 | temp = psiconv_read_u16(config,buf,lev+2,off+len,&res); |
1804 | if (res) |
1826 | if (res) |
1805 | goto ERROR4; |
1827 | goto ERROR4; |
1806 | if (temp != 0x00) { |
1828 | if (temp != 0x00) { |
1807 | psiconv_warn(lev+2,off+len, |
1829 | psiconv_warn(config,lev+2,off+len, |
1808 | "Grid section unknown word has unknown value (ignored)"); |
1830 | "Grid section unknown word has unknown value (ignored)"); |
1809 | psiconv_debug(lev+2,off+len,"Value: %04x",temp); |
1831 | psiconv_debug(config,lev+2,off+len,"Value: %04x",temp); |
1810 | } |
1832 | } |
1811 | len += 2; |
1833 | len += 2; |
1812 | |
1834 | |
1813 | psiconv_progress(lev+2,off+len,"Going to read the row breaks list"); |
1835 | psiconv_progress(config,lev+2,off+len,"Going to read the row breaks list"); |
1814 | if ((res = psiconv_parse_sheet_grid_break_list(buf,lev+2,off+len,&leng, |
1836 | if ((res = psiconv_parse_sheet_grid_break_list(config,buf,lev+2,off+len,&leng, |
1815 | &(*result)->row_page_breaks))) |
1837 | &(*result)->row_page_breaks))) |
1816 | goto ERROR4; |
1838 | goto ERROR4; |
1817 | len += leng; |
1839 | len += leng; |
1818 | |
1840 | |
1819 | psiconv_progress(lev+2,off+len,"Going to read the column breaks list"); |
1841 | psiconv_progress(config,lev+2,off+len,"Going to read the column breaks list"); |
1820 | if ((res = psiconv_parse_sheet_grid_break_list(buf,lev+2,off+len,&leng, |
1842 | if ((res = psiconv_parse_sheet_grid_break_list(config,buf,lev+2,off+len,&leng, |
1821 | &(*result)->column_page_breaks))) |
1843 | &(*result)->column_page_breaks))) |
1822 | goto ERROR5; |
1844 | goto ERROR5; |
1823 | len += leng; |
1845 | len += leng; |
1824 | |
1846 | |
1825 | |
1847 | |
1826 | psiconv_progress(lev+2,off+len, |
1848 | psiconv_progress(config,lev+2,off+len, |
1827 | "Going to read 22 unknown bytes (%02x expected)",0x00); |
1849 | "Going to read 22 unknown bytes (%02x expected)",0x00); |
1828 | for (i = 0; i < 22 ; i++) { |
1850 | for (i = 0; i < 22 ; i++) { |
1829 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1851 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1830 | if (res) |
1852 | if (res) |
1831 | goto ERROR6; |
1853 | goto ERROR6; |
1832 | if (temp != 0x00) { |
1854 | if (temp != 0x00) { |
1833 | psiconv_warn(lev+2,off+len, |
1855 | psiconv_warn(config,lev+2,off+len, |
1834 | "Grid section unknown byte %d has unknown value (ignored)", |
1856 | "Grid section unknown byte %d has unknown value (ignored)", |
1835 | i); |
1857 | i); |
1836 | psiconv_debug(lev+2,off+len,"Value: %02x",temp); |
1858 | psiconv_debug(config,lev+2,off+len,"Value: %02x",temp); |
1837 | } |
1859 | } |
1838 | len += 1; |
1860 | len += 1; |
1839 | } |
1861 | } |
1840 | |
1862 | |
1841 | if ((*result)->freeze_rows || (*result)->freeze_columns) { |
1863 | if ((*result)->freeze_rows || (*result)->freeze_columns) { |
1842 | |
1864 | |
1843 | psiconv_progress(lev+2,off+len,"Going to read number of frozen rows"); |
1865 | psiconv_progress(config,lev+2,off+len,"Going to read number of frozen rows"); |
1844 | (*result)->frozen_rows = psiconv_read_u32(buf,lev+2,off+len, &res); |
1866 | (*result)->frozen_rows = psiconv_read_u32(config,buf,lev+2,off+len, &res); |
1845 | if (res) |
1867 | if (res) |
1846 | goto ERROR6; |
1868 | goto ERROR6; |
1847 | psiconv_debug(lev+2,off+len,"Number of frozen rows: %d", |
1869 | psiconv_debug(config,lev+2,off+len,"Number of frozen rows: %d", |
1848 | (*result)->frozen_rows); |
1870 | (*result)->frozen_rows); |
1849 | len += leng; |
1871 | len += leng; |
1850 | |
1872 | |
1851 | psiconv_progress(lev+2,off+len,"Going to read number of frozen columns"); |
1873 | psiconv_progress(config,lev+2,off+len,"Going to read number of frozen columns"); |
1852 | (*result)->frozen_columns = psiconv_read_u32(buf,lev+2,off+len, &res); |
1874 | (*result)->frozen_columns = psiconv_read_u32(config,buf,lev+2,off+len, &res); |
1853 | if (res) |
1875 | if (res) |
1854 | goto ERROR6; |
1876 | goto ERROR6; |
1855 | psiconv_debug(lev+2,off+len,"Number of frozen columns: %d", |
1877 | psiconv_debug(config,lev+2,off+len,"Number of frozen columns: %d", |
1856 | (*result)->frozen_columns); |
1878 | (*result)->frozen_columns); |
1857 | len += leng; |
1879 | len += leng; |
1858 | |
1880 | |
1859 | psiconv_progress(lev+2,off+len,"Going to read first unfrozen row"); |
1881 | psiconv_progress(config,lev+2,off+len,"Going to read first unfrozen row"); |
1860 | (*result)->first_unfrozen_row_displayed = psiconv_read_u32(buf,lev+2, |
1882 | (*result)->first_unfrozen_row_displayed = psiconv_read_u32(config,buf,lev+2, |
1861 | off+len, &res); |
1883 | off+len, &res); |
1862 | if (res) |
1884 | if (res) |
1863 | goto ERROR6; |
1885 | goto ERROR6; |
1864 | psiconv_debug(lev+2,off+len,"First row: %d", |
1886 | psiconv_debug(config,lev+2,off+len,"First row: %d", |
1865 | (*result)->first_unfrozen_row_displayed); |
1887 | (*result)->first_unfrozen_row_displayed); |
1866 | len += leng; |
1888 | len += leng; |
1867 | |
1889 | |
1868 | psiconv_progress(lev+2,off+len,"Going to read first unfrozen column"); |
1890 | psiconv_progress(config,lev+2,off+len,"Going to read first unfrozen column"); |
1869 | (*result)->first_unfrozen_column_displayed = psiconv_read_u32(buf,lev+2, |
1891 | (*result)->first_unfrozen_column_displayed = psiconv_read_u32(config,buf,lev+2, |
1870 | off+len,&res); |
1892 | off+len,&res); |
1871 | if (res) |
1893 | if (res) |
1872 | goto ERROR6; |
1894 | goto ERROR6; |
1873 | psiconv_debug(lev+2,off+len,"First column: %d", |
1895 | psiconv_debug(config,lev+2,off+len,"First column: %d", |
1874 | (*result)->first_unfrozen_column_displayed); |
1896 | (*result)->first_unfrozen_column_displayed); |
1875 | len += leng; |
1897 | len += leng; |
1876 | } else |
1898 | } else |
1877 | (*result)->frozen_rows = (*result)->frozen_columns = |
1899 | (*result)->frozen_rows = (*result)->frozen_columns = |
1878 | (*result)->first_unfrozen_row_displayed = |
1900 | (*result)->first_unfrozen_row_displayed = |
1879 | (*result)->first_unfrozen_column_displayed = 0; |
1901 | (*result)->first_unfrozen_column_displayed = 0; |
1880 | |
1902 | |
1881 | psiconv_progress(lev+2,off+len, |
1903 | psiconv_progress(config,lev+2,off+len, |
1882 | "Going to read 3 unknown bytes (%02x expected)",0xff); |
1904 | "Going to read 3 unknown bytes (%02x expected)",0xff); |
1883 | for (i = 0; i < 3 ; i++) { |
1905 | for (i = 0; i < 3 ; i++) { |
1884 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1906 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
1885 | if (res) |
1907 | if (res) |
1886 | goto ERROR6; |
1908 | goto ERROR6; |
1887 | if (temp != 0xff) { |
1909 | if (temp != 0xff) { |
1888 | psiconv_warn(lev+2,off+len, |
1910 | psiconv_warn(config,lev+2,off+len, |
1889 | "Grid section unknown byte %d has unknown value (ignored)", |
1911 | "Grid section unknown byte %d has unknown value (ignored)", |
1890 | i); |
1912 | i); |
1891 | psiconv_debug(lev+2,off+len,"Value: %02x",temp); |
1913 | psiconv_debug(config,lev+2,off+len,"Value: %02x",temp); |
1892 | } |
1914 | } |
1893 | len ++; |
1915 | len ++; |
1894 | } |
1916 | } |
1895 | |
1917 | |
1896 | if (length) |
1918 | if (length) |
1897 | *length = len; |
1919 | *length = len; |
1898 | |
1920 | |
1899 | psiconv_progress(lev,off+len-1, |
1921 | psiconv_progress(config,lev,off+len-1, |
1900 | "End of sheet grid section (total length: %08x)", len); |
1922 | "End of sheet grid section (total length: %08x)", len); |
1901 | return 0; |
1923 | return 0; |
1902 | |
1924 | |
1903 | ERROR6: |
1925 | ERROR6: |
1904 | psiconv_free_sheet_grid_break_list((*result)->column_page_breaks); |
1926 | psiconv_free_sheet_grid_break_list((*result)->column_page_breaks); |
… | |
… | |
1909 | ERROR3: |
1931 | ERROR3: |
1910 | psiconv_free_sheet_grid_size_list((*result)->row_heights); |
1932 | psiconv_free_sheet_grid_size_list((*result)->row_heights); |
1911 | ERROR2: |
1933 | ERROR2: |
1912 | free(*result); |
1934 | free(*result); |
1913 | ERROR1: |
1935 | ERROR1: |
1914 | psiconv_warn(lev+1,off,"Reading of Sheet Grid Section failed"); |
1936 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Section failed"); |
1915 | if (length) |
1937 | if (length) |
1916 | *length = 0; |
1938 | *length = 0; |
1917 | if (!res) |
1939 | if (!res) |
1918 | return -PSICONV_E_NOMEM; |
1940 | return -PSICONV_E_NOMEM; |
1919 | else |
1941 | else |
1920 | return res; |
1942 | return res; |
1921 | } |
1943 | } |
1922 | |
1944 | |
1923 | |
1945 | |
1924 | int psiconv_parse_sheet_grid_size_list(const psiconv_buffer buf, int lev, |
1946 | int psiconv_parse_sheet_grid_size_list(const psiconv_config config, |
|
|
1947 | const psiconv_buffer buf, int lev, |
1925 | psiconv_u32 off, int *length, |
1948 | psiconv_u32 off, int *length, |
1926 | psiconv_sheet_grid_size_list *result) |
1949 | psiconv_sheet_grid_size_list *result) |
1927 | { |
1950 | { |
1928 | int res=0; |
1951 | int res=0; |
1929 | int len=0,i; |
1952 | int len=0,i; |
1930 | int leng,listlen; |
1953 | int leng,listlen; |
1931 | psiconv_sheet_grid_size size; |
1954 | psiconv_sheet_grid_size size; |
1932 | |
1955 | |
1933 | psiconv_progress(lev+1,off,"Going to read a sheet grid size list"); |
1956 | psiconv_progress(config,lev+1,off,"Going to read a sheet grid size list"); |
1934 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_grid_size_s)))) |
1957 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_grid_size_s)))) |
1935 | goto ERROR1; |
1958 | goto ERROR1; |
1936 | |
1959 | |
1937 | psiconv_progress(lev+2,off+len, |
1960 | psiconv_progress(config,lev+2,off+len, |
1938 | "Going to read the number of elements"); |
1961 | "Going to read the number of elements"); |
1939 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1962 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
1940 | if (res) |
1963 | if (res) |
1941 | goto ERROR2; |
1964 | goto ERROR2; |
1942 | psiconv_debug(lev+2,off+len,"Number of elements: %d",listlen); |
1965 | psiconv_debug(config,lev+2,off+len,"Number of elements: %d",listlen); |
1943 | len += leng; |
1966 | len += leng; |
1944 | |
1967 | |
1945 | psiconv_progress(lev+2,off+len,"Going to read all elements"); |
1968 | psiconv_progress(config,lev+2,off+len,"Going to read all elements"); |
1946 | for (i = 0; i < listlen; i++) { |
1969 | for (i = 0; i < listlen; i++) { |
1947 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
1970 | psiconv_progress(config,lev+3,off+len,"Going to read element %d",i); |
1948 | if ((res = psiconv_parse_sheet_grid_size(buf,lev+3,off+len,&leng,&size))) |
1971 | if ((res = psiconv_parse_sheet_grid_size(config,buf,lev+3,off+len,&leng,&size))) |
1949 | goto ERROR2; |
1972 | goto ERROR2; |
1950 | if ((res = psiconv_list_add(*result,size))) |
1973 | if ((res = psiconv_list_add(*result,size))) |
1951 | goto ERROR3; |
1974 | goto ERROR3; |
1952 | free(size); |
1975 | free(size); |
1953 | len += leng; |
1976 | len += leng; |
1954 | } |
1977 | } |
1955 | |
1978 | |
1956 | if (length) |
1979 | if (length) |
1957 | *length = len; |
1980 | *length = len; |
1958 | |
1981 | |
1959 | psiconv_progress(lev,off+len-1, |
1982 | psiconv_progress(config,lev,off+len-1, |
1960 | "End of sheet grid size list (total length: %08x)", len); |
1983 | "End of sheet grid size list (total length: %08x)", len); |
1961 | return 0; |
1984 | return 0; |
1962 | |
1985 | |
1963 | ERROR3: |
1986 | ERROR3: |
1964 | psiconv_free_sheet_grid_size(size); |
1987 | psiconv_free_sheet_grid_size(size); |
1965 | ERROR2: |
1988 | ERROR2: |
1966 | psiconv_list_free(*result); |
1989 | psiconv_list_free(*result); |
1967 | ERROR1: |
1990 | ERROR1: |
1968 | psiconv_warn(lev+1,off,"Reading of Sheet Grid Size List failed"); |
1991 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size List failed"); |
1969 | if (length) |
1992 | if (length) |
1970 | *length = 0; |
1993 | *length = 0; |
1971 | if (!res) |
1994 | if (!res) |
1972 | return -PSICONV_E_NOMEM; |
1995 | return -PSICONV_E_NOMEM; |
1973 | else |
1996 | else |
1974 | return res; |
1997 | return res; |
1975 | } |
1998 | } |
1976 | |
1999 | |
1977 | int psiconv_parse_sheet_grid_size(const psiconv_buffer buf, int lev, |
2000 | int psiconv_parse_sheet_grid_size(const psiconv_config config, |
|
|
2001 | const psiconv_buffer buf, int lev, |
1978 | psiconv_u32 off, int *length, |
2002 | psiconv_u32 off, int *length, |
1979 | psiconv_sheet_grid_size *result) |
2003 | psiconv_sheet_grid_size *result) |
1980 | { |
2004 | { |
1981 | int res=0; |
2005 | int res=0; |
1982 | int len=0; |
2006 | int len=0; |
1983 | int leng; |
2007 | int leng; |
1984 | |
2008 | |
1985 | psiconv_progress(lev+1,off,"Going to read a sheet grid size"); |
2009 | psiconv_progress(config,lev+1,off,"Going to read a sheet grid size"); |
1986 | |
2010 | |
1987 | if (!(*result = malloc(sizeof(**result)))) |
2011 | if (!(*result = malloc(sizeof(**result)))) |
1988 | goto ERROR1; |
2012 | goto ERROR1; |
1989 | |
2013 | |
1990 | psiconv_progress(lev+2,off+len, "Going to read the row or column number"); |
2014 | psiconv_progress(config,lev+2,off+len, "Going to read the row or column number"); |
1991 | (*result)->line_number = psiconv_read_u32(buf,lev+2,off+len,&res); |
2015 | (*result)->line_number = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
1992 | if (res) |
2016 | if (res) |
1993 | goto ERROR2; |
2017 | goto ERROR2; |
1994 | psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->line_number); |
2018 | psiconv_debug(config,lev+2,off+len,"Line number: %d\n",(*result)->line_number); |
1995 | len += 4; |
2019 | len += 4; |
1996 | |
2020 | |
1997 | psiconv_progress(lev+2,off+len, "Going to read the row or column height"); |
2021 | psiconv_progress(config,lev+2,off+len, "Going to read the row or column height"); |
1998 | (*result)->size = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
2022 | (*result)->size = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res); |
1999 | if (res) |
2023 | if (res) |
2000 | goto ERROR2; |
2024 | goto ERROR2; |
2001 | psiconv_debug(lev+2,off+len,"Size: %f\n",(*result)->size); |
2025 | psiconv_debug(config,lev+2,off+len,"Size: %f\n",(*result)->size); |
2002 | len += leng; |
2026 | len += leng; |
2003 | |
2027 | |
2004 | if (length) |
2028 | if (length) |
2005 | *length = len; |
2029 | *length = len; |
2006 | |
2030 | |
2007 | psiconv_progress(lev,off+len-1, |
2031 | psiconv_progress(config,lev,off+len-1, |
2008 | "End of sheet grid size(total length: %08x)", len); |
2032 | "End of sheet grid size(total length: %08x)", len); |
2009 | return 0; |
2033 | return 0; |
2010 | |
2034 | |
2011 | ERROR2: |
2035 | ERROR2: |
2012 | free (*result); |
2036 | free (*result); |
2013 | ERROR1: |
2037 | ERROR1: |
2014 | psiconv_warn(lev+1,off,"Reading of Sheet Grid Size failed"); |
2038 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size failed"); |
2015 | if (length) |
2039 | if (length) |
2016 | *length = 0; |
2040 | *length = 0; |
2017 | if (!res) |
2041 | if (!res) |
2018 | return -PSICONV_E_NOMEM; |
2042 | return -PSICONV_E_NOMEM; |
2019 | else |
2043 | else |
2020 | return res; |
2044 | return res; |
2021 | } |
2045 | } |
2022 | |
2046 | |
2023 | |
2047 | |
2024 | int psiconv_parse_sheet_grid_break_list(const psiconv_buffer buf, int lev, |
2048 | int psiconv_parse_sheet_grid_break_list(const psiconv_config config, |
|
|
2049 | const psiconv_buffer buf, int lev, |
2025 | psiconv_u32 off, int *length, |
2050 | psiconv_u32 off, int *length, |
2026 | psiconv_sheet_grid_break_list *result) |
2051 | psiconv_sheet_grid_break_list *result) |
2027 | { |
2052 | { |
2028 | int res=0; |
2053 | int res=0; |
2029 | int len=0,i; |
2054 | int len=0,i; |
2030 | int leng,listlen; |
2055 | int leng,listlen; |
2031 | psiconv_u32 nr; |
2056 | psiconv_u32 nr; |
2032 | |
2057 | |
2033 | psiconv_progress(lev+1,off,"Going to read a sheet grid break list"); |
2058 | psiconv_progress(config,lev+1,off,"Going to read a sheet grid break list"); |
2034 | if (!(*result = psiconv_list_new(sizeof(psiconv_u32)))) |
2059 | if (!(*result = psiconv_list_new(sizeof(psiconv_u32)))) |
2035 | goto ERROR1; |
2060 | goto ERROR1; |
2036 | |
2061 | |
2037 | psiconv_progress(lev+2,off+len, |
2062 | psiconv_progress(config,lev+2,off+len, |
2038 | "Going to read the number of elements"); |
2063 | "Going to read the number of elements"); |
2039 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
2064 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
2040 | if (res) |
2065 | if (res) |
2041 | goto ERROR2; |
2066 | goto ERROR2; |
2042 | psiconv_debug(lev+2,off+len,"Number of elements: %d",listlen); |
2067 | psiconv_debug(config,lev+2,off+len,"Number of elements: %d",listlen); |
2043 | len += leng; |
2068 | len += leng; |
2044 | |
2069 | |
2045 | psiconv_progress(lev+2,off+len,"Going to read all elements"); |
2070 | psiconv_progress(config,lev+2,off+len,"Going to read all elements"); |
2046 | for (i = 0; i < listlen; i++) { |
2071 | for (i = 0; i < listlen; i++) { |
2047 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
2072 | psiconv_progress(config,lev+3,off+len,"Going to read element %d",i); |
2048 | nr = psiconv_read_u32(buf,lev+3,off+len,&res); |
2073 | nr = psiconv_read_u32(config,buf,lev+3,off+len,&res); |
2049 | if (res) |
2074 | if (res) |
2050 | goto ERROR2; |
2075 | goto ERROR2; |
2051 | if ((res = psiconv_list_add(*result,&nr))) |
2076 | if ((res = psiconv_list_add(*result,&nr))) |
2052 | goto ERROR2; |
2077 | goto ERROR2; |
2053 | len += leng; |
2078 | len += leng; |
2054 | } |
2079 | } |
2055 | |
2080 | |
2056 | if (length) |
2081 | if (length) |
2057 | *length = len; |
2082 | *length = len; |
2058 | |
2083 | |
2059 | psiconv_progress(lev,off+len-1, |
2084 | psiconv_progress(config,lev,off+len-1, |
2060 | "End of sheet grid break list (total length: %08x)", len); |
2085 | "End of sheet grid break list (total length: %08x)", len); |
2061 | return 0; |
2086 | return 0; |
2062 | |
2087 | |
2063 | ERROR2: |
2088 | ERROR2: |
2064 | psiconv_list_free(*result); |
2089 | psiconv_list_free(*result); |
2065 | ERROR1: |
2090 | ERROR1: |
2066 | psiconv_warn(lev+1,off,"Reading of Sheet Grid break List failed"); |
2091 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid break List failed"); |
2067 | if (length) |
2092 | if (length) |
2068 | *length = 0; |
2093 | *length = 0; |
2069 | if (!res) |
2094 | if (!res) |
2070 | return -PSICONV_E_NOMEM; |
2095 | return -PSICONV_E_NOMEM; |
2071 | else |
2096 | else |