projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tab: Merge struct tab_table into struct table.
[pspp]
/
src
/
data
/
ods-reader.c
diff --git
a/src/data/ods-reader.c
b/src/data/ods-reader.c
index ce9310a230b23385891eaed984f8ce929bdc7819..7d91135b99e82cf2d249a6dae2b95039a1e65a6a 100644
(file)
--- a/
src/data/ods-reader.c
+++ b/
src/data/ods-reader.c
@@
-85,6
+85,7
@@
enum reader_state
struct state_data
{
xmlTextReaderPtr xtr;
struct state_data
{
xmlTextReaderPtr xtr;
+ struct zip_member *zm;
int node_type;
enum reader_state state;
int row;
int node_type;
enum reader_state state;
int row;
@@
-103,6
+104,9
@@
state_data_destroy (struct state_data *sd)
xmlFreeTextReader (sd->xtr);
sd->xtr = NULL;
xmlFreeTextReader (sd->xtr);
sd->xtr = NULL;
+
+ zip_member_finish (sd->zm);
+ sd->zm = NULL;
}
struct ods_reader
}
struct ods_reader
@@
-153,7
+157,7
@@
ods_unref (struct spreadsheet *s)
xmlFree (r->sheets[i].name);
}
xmlFree (r->sheets[i].name);
}
- dict_
destroy
(r->dict);
+ dict_
unref
(r->dict);
zip_reader_destroy (r->zreader);
free (r->sheets);
zip_reader_destroy (r->zreader);
free (r->sheets);
@@
-507,6
+511,12
@@
convert_xml_to_value (struct ccase *c, const struct variable *var,
}
}
}
}
+static int
+xml_reader_for_zip_member (void *zm_, char *buffer, int len)
+{
+ struct zip_member *zm = zm_;
+ return zip_member_read (zm, buffer, len);
+}
/* Try to find out how many sheets there are in the "workbook" */
static int
/* Try to find out how many sheets there are in the "workbook" */
static int
@@
-519,9
+529,7
@@
get_sheet_count (struct zip_reader *zreader)
if ( meta == NULL)
return -1;
if ( meta == NULL)
return -1;
- mxtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
- (xmlInputCloseCallback) NULL,
- meta, NULL, NULL, 0);
+ mxtr = xmlReaderForIO (xml_reader_for_zip_member, NULL, meta, NULL, NULL, 0);
while (1 == xmlTextReaderRead (mxtr))
{
while (1 == xmlTextReaderRead (mxtr))
{
@@
-534,6
+542,7
@@
get_sheet_count (struct zip_reader *zreader)
{
int s = _xmlchar_to_int (attr);
xmlFreeTextReader (mxtr);
{
int s = _xmlchar_to_int (attr);
xmlFreeTextReader (mxtr);
+ zip_member_finish (meta);
xmlFree (name);
xmlFree (attr);
return s;
xmlFree (name);
xmlFree (attr);
return s;
@@
-544,12
+553,14
@@
get_sheet_count (struct zip_reader *zreader)
}
xmlFreeTextReader (mxtr);
}
xmlFreeTextReader (mxtr);
+ zip_member_finish (meta);
return -1;
}
static void
ods_error_handler (void *ctx, const char *mesg,
return -1;
}
static void
ods_error_handler (void *ctx, const char *mesg,
- UNUSED xmlParserSeverities sev, xmlTextReaderLocatorPtr loc)
+ xmlParserSeverities sev UNUSED,
+ xmlTextReaderLocatorPtr loc)
{
struct ods_reader *r = ctx;
{
struct ods_reader *r = ctx;
@@
-561,8
+572,9
@@
ods_error_handler (void *ctx, const char *mesg,
}
}
-static xmlTextReaderPtr
-init_reader (struct ods_reader *r, bool report_errors)
+static bool
+init_reader (struct ods_reader *r, bool report_errors,
+ struct state_data *state)
{
struct zip_member *content = zip_member_open (r->zreader, "content.xml");
xmlTextReaderPtr xtr;
{
struct zip_member *content = zip_member_open (r->zreader, "content.xml");
xmlTextReaderPtr xtr;
@@
-570,21
+582,22
@@
init_reader (struct ods_reader *r, bool report_errors)
if ( content == NULL)
return NULL;
if ( content == NULL)
return NULL;
- xtr = xmlReaderForIO ((xmlInputReadCallback) zip_member_read,
- (xmlInputCloseCallback) NULL,
- content, NULL, NULL,
+ xtr = xmlReaderForIO (xml_reader_for_zip_member, NULL, content, NULL, NULL,
report_errors ? 0 : (XML_PARSE_NOERROR | XML_PARSE_NOWARNING) );
if ( xtr == NULL)
report_errors ? 0 : (XML_PARSE_NOERROR | XML_PARSE_NOWARNING) );
if ( xtr == NULL)
- return false;
+
return false;
+ *state = (struct state_data) { .xtr = xtr,
+ .zm = content,
+ .state = STATE_INIT };
r->spreadsheet.type = SPREADSHEET_ODS;
if (report_errors)
xmlTextReaderSetErrorHandler (xtr, ods_error_handler, r);
r->spreadsheet.type = SPREADSHEET_ODS;
if (report_errors)
xmlTextReaderSetErrorHandler (xtr, ods_error_handler, r);
- return
xtr
;
+ return
true
;
}
}
@@
-594,7
+607,6
@@
ods_probe (const char *filename, bool report_errors)
{
int sheet_count;
struct ods_reader *r = xzalloc (sizeof *r);
{
int sheet_count;
struct ods_reader *r = xzalloc (sizeof *r);
- xmlTextReaderPtr xtr;
struct zip_reader *zr;
ds_init_empty (&r->zip_errs);
struct zip_reader *zr;
ds_init_empty (&r->zip_errs);
@@
-618,17
+630,8
@@
ods_probe (const char *filename, bool report_errors)
r->zreader = zr;
r->spreadsheet.ref_cnt = 1;
r->zreader = zr;
r->spreadsheet.ref_cnt = 1;
- xtr = init_reader (r, report_errors);
- if (xtr == NULL)
- {
- goto error;
- }
- r->msd.xtr = xtr;
- r->msd.row = 0;
- r->msd.col = 0;
- r->msd.current_sheet = 0;
- r->msd.state = STATE_INIT;
-
+ if (!init_reader (r, report_errors, &r->msd))
+ goto error;
r->spreadsheet.n_sheets = sheet_count;
r->n_allocated_sheets = 0;
r->spreadsheet.n_sheets = sheet_count;
r->n_allocated_sheets = 0;
@@
-655,7
+658,6
@@
ods_make_reader (struct spreadsheet *spreadsheet,
int i;
struct var_spec *var_spec = NULL;
int n_var_specs = 0;
int i;
struct var_spec *var_spec = NULL;
int n_var_specs = 0;
- xmlTextReaderPtr xtr;
struct ods_reader *r = (struct ods_reader *) spreadsheet;
xmlChar *val_string = NULL;
struct ods_reader *r = (struct ods_reader *) spreadsheet;
xmlChar *val_string = NULL;
@@
-665,16
+667,9
@@
ods_make_reader (struct spreadsheet *spreadsheet,
ds_init_empty (&r->ods_errs);
++r->spreadsheet.ref_cnt;
ds_init_empty (&r->ods_errs);
++r->spreadsheet.ref_cnt;
- xtr = init_reader (r, true);
- if ( xtr == NULL)
+ if (!init_reader (r, true, &r->rsd))
goto error;
goto error;
- r->rsd.xtr = xtr;
- r->rsd.row = 0;
- r->rsd.col = 0;
- r->rsd.current_sheet = 0;
- r->rsd.state = STATE_INIT;
-
r->used_first_case = false;
r->first_case = NULL;
r->used_first_case = false;
r->first_case = NULL;