/[public]/psiconv/trunk/lib/psiconv/parse_sheet.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_sheet.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 97 Revision 98
237 goto ERROR2; 237 goto ERROR2;
238 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 238 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
239 len += 4; 239 len += 4;
240 240
241 psiconv_progress(lev+2,off+len,"Going to read the formulas list"); 241 psiconv_progress(lev+2,off+len,"Going to read the formulas list");
242 if ((res = psiconv_parse_sheet_formula_list(buf,lev+2,formulas_off,NULL, 242 if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL,
243 &(*result)->formulas))) 243 &(*result)->formulas)))
244 goto ERROR2; 244 goto ERROR2;
245 245
246 246
247 if (length) 247 if (length)
248 *length = len; 248 *length = len;
261 return -PSICONV_E_NOMEM; 261 return -PSICONV_E_NOMEM;
262 else 262 else
263 return res; 263 return res;
264} 264}
265 265
266int psiconv_parse_sheet_formula(const psiconv_buffer buf, int lev, 266int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev,
267 psiconv_u32 off, int *length, 267 psiconv_u32 off, int *length,
268 psiconv_sheet_formula *result) 268 psiconv_formula_list *result)
269{ 269{
270 int res=0; 270 int res=0;
271 int len=0; 271 int len=0;
272 psiconv_u32 temp;
273 psiconv_formula formula;
274 psiconv_u32 listlen,i;
272 // int leng; 275 int leng;
273 276
274 psiconv_progress(lev+1,off,"Going to read a sheet formula"); 277 psiconv_progress(lev+1,off,"Going to read the sheet formula table");
275 if (!(*result = malloc(sizeof(**result)))) 278 if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s))))
276 goto ERROR1; 279 goto ERROR1;
277 280
278 psiconv_progress(lev+2,off+len,"COP OUT: DOING NOTHING..."); 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 }
279 310
280 if (length) 311 if (length)
281 *length = len; 312 *length = len;
282 313
283 psiconv_progress(lev,off+len-1, 314 psiconv_progress(lev,off+len-1,
284 "End of the sheet formula (total length: %08x)", len); 315 "End of sheet formula table (total length: %08x)", len);
285 return 0; 316 return 0;
286 317
318ERROR3:
319 psiconv_free_formula(formula);
287// ERROR2: 320ERROR2:
288 free(*result); 321 psiconv_list_free(*result);
289ERROR1: 322ERROR1:
290 psiconv_warn(lev+1,off,"Reading of Sheet Formula failed"); 323 psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed");
291 if (length) 324 if (length)
292 *length = 0; 325 *length = 0;
293 if (!res) 326 if (!res)
294 return -PSICONV_E_NOMEM; 327 return -PSICONV_E_NOMEM;
295 else 328 else
296 return res; 329 return res;
297} 330}
298
299int 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
351ERROR3:
352 psiconv_free_sheet_formula(formula);
353ERROR2:
354 psiconv_list_free(*result);
355ERROR1:
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}

Legend:
Removed from v.97  
changed lines
  Added in v.98

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26