struct state_data
{
xmlTextReaderPtr xtr;
+ struct zip_member *zm;
int node_type;
enum reader_state state;
int row;
xmlFreeTextReader (sd->xtr);
sd->xtr = NULL;
+
+ zip_member_finish (sd->zm);
+ sd->zm = NULL;
}
struct ods_reader
{
if (r->target_sheet_name != NULL)
{
- if ( 0 == xmlStrcmp (r->target_sheet_name, msd->current_sheet_name))
+ if (0 == xmlStrcmp (r->target_sheet_name, msd->current_sheet_name))
return true;
}
while (
(r->n_allocated_sheets <= n)
|| or->state != STATE_SPREADSHEET
- )
+ )
{
int ret = xmlTextReaderRead (or->xtr);
- if ( ret != 1)
+ if (ret != 1)
break;
process_node (r, or);
(r->n_allocated_sheets <= n)
|| (r->sheets[n].stop_row == -1)
|| or->state != STATE_SPREADSHEET
- )
+ )
{
int ret = xmlTextReaderRead (or->xtr);
- if ( ret != 1)
+ if (ret != 1)
break;
process_node (r, or);
ods_file_casereader_destroy (struct casereader *reader UNUSED, void *r_)
{
struct ods_reader *r = r_;
- if ( r == NULL)
+ if (r == NULL)
return ;
state_data_destroy (&r->rsd);
- if ( ! ds_is_empty (&r->ods_errs))
+ if (! ds_is_empty (&r->ods_errs))
msg (ME, "%s", ds_cstr (&r->ods_errs));
ds_destroy (&r->ods_errs);
- if ( r->first_case && ! r->used_first_case )
+ if (r->first_case && ! r->used_first_case)
case_unref (r->first_case);
}
break;
case STATE_ROW:
- if ( (0 == xmlStrcasecmp (name, _xml ("table:table-cell")))
+ if ((0 == xmlStrcasecmp (name, _xml ("table:table-cell")))
&&
(XML_READER_TYPE_ELEMENT == r->node_type))
{
xmlFree (value);
}
- else if ( (0 == xmlStrcasecmp (name, _xml ("table:table-row")))
+ else if ((0 == xmlStrcasecmp (name, _xml ("table:table-row")))
&&
(XML_READER_TYPE_END_ELEMENT == r->node_type))
{
}
break;
case STATE_CELL:
- if ( (0 == xmlStrcasecmp (name, _xml("text:p")))
+ if ((0 == xmlStrcasecmp (name, _xml("text:p")))
&&
- ( XML_READER_TYPE_ELEMENT == r->node_type))
+ (XML_READER_TYPE_ELEMENT == r->node_type))
{
if (! xmlTextReaderIsEmptyElement (r->xtr))
r->state = STATE_CELL_CONTENT;
}
else if
- ( (0 == xmlStrcasecmp (name, _xml("table:table-cell")))
+ ((0 == xmlStrcasecmp (name, _xml("table:table-cell")))
&&
(XML_READER_TYPE_END_ELEMENT == r->node_type)
- )
+ )
{
r->state = STATE_ROW;
}
(or->sheets[r->current_sheet].start_col == -1)
||
(or->sheets[r->current_sheet].start_col >= r->col - 1)
- )
+ )
or->sheets[r->current_sheet].start_col = r->col - 1;
or->sheets[r->current_sheet].stop_row = r->row - 1;
- if ( or->sheets[r->current_sheet].stop_col < r->col - 1)
+ if (or->sheets[r->current_sheet].stop_col < r->col - 1)
or->sheets[r->current_sheet].stop_col = r->col - 1;
if (XML_READER_TYPE_END_ELEMENT == r->node_type)
if (xmv->type != NULL && 0 != xmlStrcmp (xmv->type, _xml("string")))
return 0;
- if ( fallback != -1)
+ if (fallback != -1)
return fallback;
- if ( xmv->value )
+ if (xmv->value)
width = ROUND_UP (xmlStrlen (xmv->value),
SPREADSHEET_DEFAULT_WIDTH);
- else if ( xmv->text)
+ else if (xmv->text)
width = ROUND_UP (xmlStrlen (xmv->text),
SPREADSHEET_DEFAULT_WIDTH);
if (xmv->value == NULL && xmv->text == NULL)
value_set_missing (v, var_get_width (var));
- else if ( var_is_alpha (var))
+ else if (var_is_alpha (var))
/* Use the text field, because it seems that there is no
value field for strings */
value_copy_str_rpad (v, var_get_width (var), xmv->text, ' ');
const struct fmt_spec *fmt = var_get_write_format (var);
enum fmt_category fc = fmt_get_category (fmt->type);
- assert ( fc != FMT_CAT_STRING);
+ assert (fc != FMT_CAT_STRING);
- if ( 0 == xmlStrcmp (xmv->type, _xml("float")))
+ if (0 == xmlStrcmp (xmv->type, _xml("float")))
{
v->f = c_strtod (CHAR_CAST (const char *, xmv->value), NULL);
}
struct zip_member *meta = NULL;
meta = zip_member_open (zreader, "meta.xml");
- if ( meta == NULL)
+ if (meta == NULL)
return -1;
mxtr = xmlReaderForIO (xml_reader_for_zip_member, NULL, meta, NULL, NULL, 0);
while (1 == xmlTextReaderRead (mxtr))
{
xmlChar *name = xmlTextReaderName (mxtr);
- if ( 0 == xmlStrcmp (name, _xml("meta:document-statistic")))
+ if (0 == xmlStrcmp (name, _xml("meta:document-statistic")))
{
xmlChar *attr = xmlTextReaderGetAttribute (mxtr, _xml ("meta:table-count"));
- if ( attr != NULL)
+ if (attr != NULL)
{
int s = _xmlchar_to_int (attr);
xmlFreeTextReader (mxtr);
+ zip_member_finish (meta);
xmlFree (name);
xmlFree (attr);
return s;
}
xmlFreeTextReader (mxtr);
+ zip_member_finish (meta);
return -1;
}
}
-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;
- if ( content == NULL)
+ if (content == NULL)
return NULL;
xtr = xmlReaderForIO (xml_reader_for_zip_member, NULL, content, NULL, NULL,
- report_errors ? 0 : (XML_PARSE_NOERROR | XML_PARSE_NOWARNING) );
+ report_errors ? 0 : (XML_PARSE_NOERROR | XML_PARSE_NOWARNING));
- if ( xtr == NULL)
- return false;
+ if (xtr == NULL)
+ 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);
- return xtr;
+ return true;
}
{
int sheet_count;
struct ods_reader *r = xzalloc (sizeof *r);
- xmlTextReaderPtr xtr;
struct zip_reader *zr;
ds_init_empty (&r->zip_errs);
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;
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;
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;
- 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;
if (opts->cell_range)
{
- if ( ! convert_cell_ref (opts->cell_range,
+ if (! convert_cell_ref (opts->cell_range,
&r->start_col, &r->start_row,
&r->stop_col, &r->stop_row))
{
r->target_sheet_index = opts->sheet_index;
/* Advance to the start of the cells for the target sheet */
- while ( ! reading_target_sheet (r, &r->rsd)
- || r->rsd.state != STATE_ROW || r->rsd.row <= r->start_row )
+ while (! reading_target_sheet (r, &r->rsd)
+ || r->rsd.state != STATE_ROW || r->rsd.row <= r->start_row)
{
if (1 != (ret = xmlTextReaderRead (r->rsd.xtr)))
break;
goto error;
}
- if ( opts->read_names)
+ if (opts->read_names)
{
while (1 == xmlTextReaderRead (r->rsd.xtr))
{
int idx;
process_node (r, &r->rsd);
- if ( ! reading_target_sheet (r, &r->rsd) )
+ if (! reading_target_sheet (r, &r->rsd))
break;
/* If the row is finished then stop for now */
if (r->stop_col != -1 && idx > r->stop_col - r->start_col)
continue;
- if ( r->rsd.state == STATE_CELL &&
+ if (r->rsd.state == STATE_CELL &&
XML_READER_TYPE_ELEMENT == r->rsd.node_type)
{
type = xmlTextReaderGetAttribute (r->rsd.xtr, _xml ("office:value-type"));
val_string = xmlTextReaderGetAttribute (r->rsd.xtr, _xml ("office:value"));
}
- if ( r->rsd.state == STATE_CELL_CONTENT &&
+ if (r->rsd.state == STATE_CELL_CONTENT &&
XML_READER_TYPE_TEXT == r->rsd.node_type)
{
if (idx >= n_var_specs)
r->spreadsheet.dict = r->dict = dict_create (
CHAR_CAST (const char *, xmlTextReaderConstEncoding (r->rsd.xtr)));
- for (i = 0; i < n_var_specs ; ++i )
+ for (i = 0; i < n_var_specs ; ++i)
{
struct fmt_spec fmt;
struct variable *var = NULL;
var = dict_get_var (r->dict, i);
- if ( 0 == xmlStrcmp (var_spec[i].firstval.type, _xml("date")))
+ if (0 == xmlStrcmp (var_spec[i].firstval.type, _xml("date")))
{
fmt.type = FMT_DATE;
fmt.d = 0;
var_set_both_formats (var, &fmt);
}
- if ( n_var_specs == 0 )
+ if (n_var_specs == 0)
{
msg (MW, _("Selected sheet or range of spreadsheet `%s' is empty."),
spreadsheet->file_name);
}
- for ( i = 0 ; i < n_var_specs ; ++i )
+ for (i = 0 ; i < n_var_specs ; ++i)
{
free (var_spec[i].firstval.type);
free (var_spec[i].firstval.value);
error:
- for ( i = 0 ; i < n_var_specs ; ++i )
+ for (i = 0 ; i < n_var_specs ; ++i)
{
free (var_spec[i].firstval.type);
free (var_spec[i].firstval.value);
/* Advance to the start of a row. (If there is one) */
while (r->rsd.state != STATE_ROW
&& 1 == xmlTextReaderRead (r->rsd.xtr)
- )
+ )
{
process_node (r, &r->rsd);
}
- if ( ! reading_target_sheet (r, &r->rsd)
+ if (! reading_target_sheet (r, &r->rsd)
|| r->rsd.state < STATE_TABLE
|| (r->stop_row != -1 && r->rsd.row > r->stop_row + 1)
- )
+)
{
return NULL;
}
{
process_node (r, &r->rsd);
- if ( r->stop_row != -1 && r->rsd.row > r->stop_row + 1)
+ if (r->stop_row != -1 && r->rsd.row > r->stop_row + 1)
break;
if (r->rsd.state == STATE_CELL &&
const int idx = r->rsd.col - col - r->start_col - 1;
if (idx < 0)
continue;
- if (r->stop_col != -1 && idx > r->stop_col - r->start_col )
+ if (r->stop_col != -1 && idx > r->stop_col - r->start_col)
break;
if (idx >= dict_get_var_cnt (r->dict))
break;
xmlFree (xmv->type);
free (xmv);
}
- if ( r->rsd.state <= STATE_TABLE)
+ if (r->rsd.state <= STATE_TABLE)
break;
}