/[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 94 Revision 98
180 return -PSICONV_E_NOMEM; 180 return -PSICONV_E_NOMEM;
181 else 181 else
182 return res; 182 return res;
183} 183}
184 184
185int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev,
186 psiconv_u32 off, int *length,
187 psiconv_sheet_workbook_section *result)
188{
189 int res=0;
190 psiconv_u32 temp,formulas_off;
191 int len=0;
192
193 psiconv_progress(lev+1,off,"Going to read the sheet workbook section");
194 if (!(*result = malloc(sizeof(**result))))
195 goto ERROR1;
196
197 psiconv_progress(lev+2,off+len,
198 "Going to read the initial byte (%02x expected)",0x04);
199 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
200 if (res)
201 goto ERROR2;
202 if (temp != 0x04) {
203 psiconv_warn(lev+2,off+len,
204 "Sheet workbook section initial byte unknown value (ignored)");
205 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
206 }
207 len ++;
208
209 psiconv_progress(lev+2,off+len,
210 "Going to read the offset of the 1st ??? Section");
211 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
212 if (res)
213 goto ERROR2;
214 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
215 len += 4;
216
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,
226 "Going to read the offset of the 3rd ??? Section");
227 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
228 if (res)
229 goto ERROR2;
230 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
231 len += 4;
232
233 psiconv_progress(lev+2,off+len,
234 "Going to read the offset of the 4th ??? Section");
235 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
236 if (res)
237 goto ERROR2;
238 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
239 len += 4;
240
241 psiconv_progress(lev+2,off+len,"Going to read the formulas list");
242 if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL,
243 &(*result)->formulas)))
244 goto ERROR2;
245
246
247 if (length)
248 *length = len;
249
250 psiconv_progress(lev,off+len-1,
251 "End of sheet workbook section (total length: %08x)", len);
252 return 0;
253
254ERROR2:
255 free (*result);
256ERROR1:
257 psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed");
258 if (length)
259 *length = 0;
260 if (!res)
261 return -PSICONV_E_NOMEM;
262 else
263 return res;
264}
265
266int 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
318ERROR3:
319 psiconv_free_formula(formula);
320ERROR2:
321 psiconv_list_free(*result);
322ERROR1:
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}

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

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