… | |
… | |
185 | int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
185 | int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
186 | psiconv_u32 off, int *length, |
186 | psiconv_u32 off, int *length, |
187 | psiconv_sheet_workbook_section *result) |
187 | psiconv_sheet_workbook_section *result) |
188 | { |
188 | { |
189 | int res=0; |
189 | int res=0; |
190 | psiconv_u32 temp; |
190 | psiconv_u32 temp,formulas_off; |
191 | int len=0; |
191 | int len=0; |
192 | |
192 | |
193 | psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
193 | psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
194 | if (!(*result = malloc(sizeof(**result)))) |
194 | if (!(*result = malloc(sizeof(**result)))) |
195 | goto ERROR1; |
195 | goto ERROR1; |
… | |
… | |
213 | goto ERROR2; |
213 | goto ERROR2; |
214 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
214 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
215 | len += 4; |
215 | len += 4; |
216 | |
216 | |
217 | psiconv_progress(lev+2,off+len, |
217 | psiconv_progress(lev+2,off+len, |
|
|
218 | "Going to read the offset of the Formulas List"); |
|
|
219 | formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
220 | if (res) |
|
|
221 | goto ERROR2; |
|
|
222 | psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); |
|
|
223 | len += 4; |
|
|
224 | |
|
|
225 | psiconv_progress(lev+2,off+len, |
218 | "Going to read the offset of the 2nd ??? Section"); |
226 | "Going to read the offset of the 3rd ??? Section"); |
219 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
227 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
220 | if (res) |
228 | if (res) |
221 | goto ERROR2; |
229 | goto ERROR2; |
222 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
230 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
223 | len += 4; |
231 | len += 4; |
224 | |
232 | |
225 | psiconv_progress(lev+2,off+len, |
233 | psiconv_progress(lev+2,off+len, |
226 | "Going to read the offset of the 3rd ??? Section"); |
234 | "Going to read the offset of the 4th ??? Section"); |
227 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
235 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
228 | if (res) |
236 | if (res) |
229 | goto ERROR2; |
237 | goto ERROR2; |
230 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
238 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
231 | len += 4; |
239 | len += 4; |
232 | |
240 | |
233 | psiconv_progress(lev+2,off+len, |
241 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
234 | "Going to read the offset of the 4th ??? Section"); |
242 | if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL, |
235 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
243 | &(*result)->formulas))) |
236 | if (res) |
|
|
237 | goto ERROR2; |
244 | goto ERROR2; |
238 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
245 | |
239 | len += 4; |
|
|
240 | |
246 | |
241 | if (length) |
247 | if (length) |
242 | *length = len; |
248 | *length = len; |
243 | |
249 | |
244 | psiconv_progress(lev,off+len-1, |
250 | psiconv_progress(lev,off+len-1, |
… | |
… | |
254 | if (!res) |
260 | if (!res) |
255 | return -PSICONV_E_NOMEM; |
261 | return -PSICONV_E_NOMEM; |
256 | else |
262 | else |
257 | return res; |
263 | return res; |
258 | } |
264 | } |
|
|
265 | |
|
|
266 | int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev, |
|
|
267 | psiconv_u32 off, int *length, |
|
|
268 | psiconv_formula_list *result) |
|
|
269 | { |
|
|
270 | int res=0; |
|
|
271 | int len=0; |
|
|
272 | psiconv_u32 temp; |
|
|
273 | psiconv_formula formula; |
|
|
274 | psiconv_u32 listlen,i; |
|
|
275 | int leng; |
|
|
276 | |
|
|
277 | psiconv_progress(lev+1,off,"Going to read the sheet formula table"); |
|
|
278 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
|
|
279 | goto ERROR1; |
|
|
280 | |
|
|
281 | psiconv_progress(lev+2,off+len, |
|
|
282 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
283 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
284 | if (res) |
|
|
285 | goto ERROR2; |
|
|
286 | if (temp != 0x02) { |
|
|
287 | psiconv_warn(lev+2,off+len, |
|
|
288 | "Sheet formula table initial byte unknown value (ignored)"); |
|
|
289 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
290 | } |
|
|
291 | len ++; |
|
|
292 | |
|
|
293 | psiconv_progress(lev+2,off+len, |
|
|
294 | "Going to read the number of formulas"); |
|
|
295 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
296 | if (res) |
|
|
297 | goto ERROR2; |
|
|
298 | psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen); |
|
|
299 | len += leng; |
|
|
300 | |
|
|
301 | psiconv_progress(lev+2,off+len,"Going to read all formulas"); |
|
|
302 | for (i = 0; i < listlen; i++) { |
|
|
303 | psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
|
|
304 | if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) |
|
|
305 | goto ERROR2; |
|
|
306 | if ((res = psiconv_list_add(*result,formula))) |
|
|
307 | goto ERROR3; |
|
|
308 | len += leng; |
|
|
309 | } |
|
|
310 | |
|
|
311 | if (length) |
|
|
312 | *length = len; |
|
|
313 | |
|
|
314 | psiconv_progress(lev,off+len-1, |
|
|
315 | "End of sheet formula table (total length: %08x)", len); |
|
|
316 | return 0; |
|
|
317 | |
|
|
318 | ERROR3: |
|
|
319 | psiconv_free_formula(formula); |
|
|
320 | ERROR2: |
|
|
321 | psiconv_list_free(*result); |
|
|
322 | ERROR1: |
|
|
323 | psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed"); |
|
|
324 | if (length) |
|
|
325 | *length = 0; |
|
|
326 | if (!res) |
|
|
327 | return -PSICONV_E_NOMEM; |
|
|
328 | else |
|
|
329 | return res; |
|
|
330 | } |