… | |
… | |
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_list(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(const psiconv_buffer buf, int lev, |
|
|
267 | psiconv_u32 off, int *length, |
|
|
268 | psiconv_sheet_formula *result) |
|
|
269 | { |
|
|
270 | int res=0; |
|
|
271 | int len=0; |
|
|
272 | // int leng; |
|
|
273 | |
|
|
274 | psiconv_progress(lev+1,off,"Going to read a sheet formula"); |
|
|
275 | if (!(*result = malloc(sizeof(**result)))) |
|
|
276 | goto ERROR1; |
|
|
277 | |
|
|
278 | psiconv_progress(lev+2,off+len,"COP OUT: DOING NOTHING..."); |
|
|
279 | |
|
|
280 | if (length) |
|
|
281 | *length = len; |
|
|
282 | |
|
|
283 | psiconv_progress(lev,off+len-1, |
|
|
284 | "End of the sheet formula (total length: %08x)", len); |
|
|
285 | return 0; |
|
|
286 | |
|
|
287 | // ERROR2: |
|
|
288 | free(*result); |
|
|
289 | ERROR1: |
|
|
290 | psiconv_warn(lev+1,off,"Reading of Sheet Formula failed"); |
|
|
291 | if (length) |
|
|
292 | *length = 0; |
|
|
293 | if (!res) |
|
|
294 | return -PSICONV_E_NOMEM; |
|
|
295 | else |
|
|
296 | return res; |
|
|
297 | } |
|
|
298 | |
|
|
299 | int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev, |
|
|
300 | psiconv_u32 off, int *length, |
|
|
301 | psiconv_sheet_formula_list *result) |
|
|
302 | { |
|
|
303 | int res=0; |
|
|
304 | int len=0; |
|
|
305 | psiconv_u32 temp; |
|
|
306 | psiconv_sheet_formula formula; |
|
|
307 | psiconv_u32 listlen,i; |
|
|
308 | int leng; |
|
|
309 | |
|
|
310 | psiconv_progress(lev+1,off,"Going to read the sheet formula table"); |
|
|
311 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_formula_s)))) |
|
|
312 | goto ERROR1; |
|
|
313 | |
|
|
314 | psiconv_progress(lev+2,off+len, |
|
|
315 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
316 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
317 | if (res) |
|
|
318 | goto ERROR2; |
|
|
319 | if (temp != 0x02) { |
|
|
320 | psiconv_warn(lev+2,off+len, |
|
|
321 | "Sheet formula table initial byte unknown value (ignored)"); |
|
|
322 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
323 | } |
|
|
324 | len ++; |
|
|
325 | |
|
|
326 | psiconv_progress(lev+2,off+len, |
|
|
327 | "Going to read the number of formulas"); |
|
|
328 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
329 | if (res) |
|
|
330 | goto ERROR2; |
|
|
331 | psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen); |
|
|
332 | len += leng; |
|
|
333 | |
|
|
334 | psiconv_progress(lev+2,off+len,"Going to read all formulas"); |
|
|
335 | for (i = 0; i < listlen; i++) { |
|
|
336 | psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
|
|
337 | if ((res = psiconv_parse_sheet_formula(buf,lev+3,off+len,&leng,&formula))) |
|
|
338 | goto ERROR2; |
|
|
339 | if ((res = psiconv_list_add(*result,formula))) |
|
|
340 | goto ERROR3; |
|
|
341 | len += leng; |
|
|
342 | } |
|
|
343 | |
|
|
344 | if (length) |
|
|
345 | *length = len; |
|
|
346 | |
|
|
347 | psiconv_progress(lev,off+len-1, |
|
|
348 | "End of sheet formula table (total length: %08x)", len); |
|
|
349 | return 0; |
|
|
350 | |
|
|
351 | ERROR3: |
|
|
352 | psiconv_free_sheet_formula(formula); |
|
|
353 | ERROR2: |
|
|
354 | psiconv_list_free(*result); |
|
|
355 | ERROR1: |
|
|
356 | psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed"); |
|
|
357 | if (length) |
|
|
358 | *length = 0; |
|
|
359 | if (!res) |
|
|
360 | return -PSICONV_E_NOMEM; |
|
|
361 | else |
|
|
362 | return res; |
|
|
363 | } |