#include "gl/xalloc.h"
static void ods_file_casereader_destroy (struct casereader *, void *);
-
static struct ccase *ods_file_casereader_read (struct casereader *, void *);
+
static const struct casereader_class ods_file_casereader_class =
{
ods_file_casereader_read,
struct spreadsheet spreadsheet;
struct zip_reader *zreader;
xmlTextReaderPtr xtr;
+ int ref_cnt;
enum reader_state state;
int row;
int current_sheet;
xmlChar *current_sheet_name;
- const xmlChar *target_sheet_name;
+ xmlChar *target_sheet_name;
int target_sheet_index;
struct string ods_errs;
};
+void
+ods_destroy (struct spreadsheet *s)
+{
+ struct ods_reader *r = (struct ods_reader *) s;
+
+ if (--r->ref_cnt == 0)
+ {
+ int i;
+
+ for (i = 0; i < r->n_allocated_sheets; ++i)
+ {
+ xmlFree (r->sheets[i].name);
+ }
+
+ zip_reader_destroy (r->zreader);
+ free (r->sheets);
+ free (r);
+ }
+}
+
+
static bool
reading_target_sheet (const struct ods_reader *r)
caseproto_unref (r->proto);
- // free (r);
+ xmlFree (r->current_sheet_name);
+ xmlFree (r->target_sheet_name);
+
+ ods_destroy (&r->spreadsheet);
}
+
+
+
+
static void
process_node (struct ods_reader *r)
{
if (! xmlTextReaderIsEmptyElement (r->xtr))
r->state = STATE_ROW;
+
+ xmlFree (value);
}
else if (0 == xmlStrcasecmp (name, _xml("table:table")) &&
(XML_READER_TYPE_END_ELEMENT == r->node_type))
return -1;
mxtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
- (xmlInputCloseCallback) zip_member_finish,
+ (xmlInputCloseCallback) NULL,
meta, NULL, NULL, 0);
while (1 == xmlTextReaderRead (mxtr))
if ( content == NULL)
return false;
- zip_member_ref (content);
-
+ if (r->xtr)
+ xmlFreeTextReader (r->xtr);
+ zip_member_ref (content);
xtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
(xmlInputCloseCallback) zip_member_finish,
content, NULL, NULL,
r = xzalloc (sizeof *r);
r->zreader = zr;
+ r->ref_cnt = 1;
if (! init_reader (r, report_errors))
{
assert (r);
r->read_names = opts->read_names;
ds_init_empty (&r->ods_errs);
-
+ ++r->ref_cnt;
if ( !init_reader (r, true))
goto error;
- if ( opts->cell_range )
+ if (opts->cell_range)
{
if ( ! convert_cell_ref (opts->cell_range,
&r->start_col, &r->start_row,
}
r->state = STATE_INIT;
- r->target_sheet_name = BAD_CAST opts->sheet_name;
+ r->target_sheet_name = xmlStrdup (BAD_CAST opts->sheet_name);
r->target_sheet_index = opts->sheet_index;
r->row = r->col = 0;
-#if 0
- printf ("%s:%d %d,%d %d,%d\n", __FILE__, __LINE__,
- r->start_col,
- r->start_row,
- r->stop_col,
- r->stop_row);
-#endif
-
-
/* Advance to the start of the cells for the target sheet */
while ( ! reading_target_sheet (r)
|| r->state != STATE_ROW || r->row <= r->start_row )
if ( r->state == STATE_CELL_CONTENT &&
XML_READER_TYPE_TEXT == r->node_type)
{
-#if 0
- printf ("%s:%d Idx %d n_var_specs %d\n", __FILE__, __LINE__,
- idx, n_var_specs);
-
- printf ("%s:%d Idx %d r_col %d\n", __FILE__, __LINE__,
- idx, r->col);
-#endif
-
if (idx >= n_var_specs)
{
var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1));
break;
}
- // zip_reader_destroy (zreader);
for ( i = 0 ; i < n_var_specs ; ++i )
{
error:
- //zip_reader_destroy (zreader);
-
for ( i = 0 ; i < n_var_specs ; ++i )
{
free (var_spec[i].firstval.type);
r->spreadsheet.dict = NULL;
ods_file_casereader_destroy (NULL, r);
-
return NULL;
}
continue;
if (r->stop_col != -1 && idx > r->stop_col - r->start_col )
break;
+ if (idx >= dict_get_var_cnt (r->dict))
+ break;
var = dict_get_var (r->dict, idx);
convert_xml_to_value (c, var, xmv);