{
struct spreadsheet spreadsheet;
struct zip_reader *zreader;
- int ref_cnt;
+
int target_sheet_index;
xmlChar *target_sheet_name;
bool read_names;
struct string ods_errs;
+
+ struct string zip_errs;
};
void
-ods_destroy (struct spreadsheet *s)
+ods_unref (struct spreadsheet *s)
{
struct ods_reader *r = (struct ods_reader *) s;
- if (--r->ref_cnt == 0)
+ if (--s->ref_cnt == 0)
{
int i;
zip_reader_destroy (r->zreader);
free (r->sheets);
-
+ free (s->file_name);
free (r);
}
}
r->target_sheet_name = NULL;
- ods_destroy (&r->spreadsheet);
+ ods_unref (&r->spreadsheet);
}
}
+
struct spreadsheet *
ods_probe (const char *filename, bool report_errors)
{
- struct ods_reader *r;
- struct string errs = DS_EMPTY_INITIALIZER;
int sheet_count;
- struct zip_reader *zr = zip_reader_create (filename, &errs);
- xmlTextReaderPtr xtr;
+ struct ods_reader *r = xzalloc (sizeof *r);
+ xmlTextReaderPtr xtr;
+ struct zip_reader *zr;
+
+ ds_init_empty (&r->zip_errs);
+
+ zr = zip_reader_create (filename, &r->zip_errs);
if (zr == NULL)
{
if (report_errors)
{
msg (ME, _("Cannot open %s as a OpenDocument file: %s"),
- filename, ds_cstr (&errs));
+ filename, ds_cstr (&r->zip_errs));
}
+ ds_destroy (&r->zip_errs);
+ free (r);
return NULL;
}
sheet_count = get_sheet_count (zr);
- r = xzalloc (sizeof *r);
r->zreader = zr;
- r->ref_cnt = 1;
+ r->spreadsheet.ref_cnt = 1;
xtr = init_reader (r, report_errors);
if (xtr == NULL)
r->n_allocated_sheets = 0;
r->sheets = NULL;
- ds_destroy (&errs);
-
- r->spreadsheet.file_name = filename;
+ r->spreadsheet.file_name = strdup (filename);
return &r->spreadsheet;
error:
+ ds_destroy (&r->zip_errs);
zip_reader_destroy (r->zreader);
- ds_destroy (&errs);
free (r);
return NULL;
}
assert (r);
r->read_names = opts->read_names;
ds_init_empty (&r->ods_errs);
- ++r->ref_cnt;
+ ++r->spreadsheet.ref_cnt;
xtr = init_reader (r, true);
if ( xtr == NULL)
struct xml_value *xmv = xzalloc (sizeof *xmv);
xmv->text = xmlTextReaderValue (r->rsd.xtr);
xmv->value = val_string;
- xmv->type = type;
val_string = NULL;
+ xmv->type = type;
+ type = NULL;
for (col = 0; col < r->rsd.col_span; ++col)
{
break;
}
+ xmlFree (type);
+ xmlFree (val_string);
+
return c;
}
#endif