int row;
int col;
int node_type;
- int sheet_index;
+ int current_sheet;
const xmlChar *target_sheet;
int target_sheet_index;
+#if 1
int start_row;
int start_col;
int stop_row;
int stop_col;
+#endif
+
+ int col_span;
struct sheet_detail *sheets;
int n_allocated_sheets;
if (0 == xmlStrcasecmp (name, _xml("office:spreadsheet")) &&
XML_READER_TYPE_ELEMENT == r->node_type)
{
- printf ("%s:%d Start of Workbook %d: Rows %d\n", __FILE__, __LINE__,
- r->sheet_index, r->row);
-
r->state = STATE_SPREADSHEET;
- r->sheet_index = -1;
+ r->current_sheet = -1;
}
break;
case STATE_SPREADSHEET:
{
xmlChar *value = xmlTextReaderGetAttribute (r->xtr, _xml ("table:name"));
+ ++r->current_sheet;
- ++r->sheet_index;
-
- printf ("%s:%d Start of SHEET %d: Allocated Sheets %d\n", __FILE__, __LINE__,
- r->sheet_index, r->n_allocated_sheets);
-
- if (r->sheet_index >= r->n_allocated_sheets)
+ if (r->current_sheet >= r->n_allocated_sheets)
{
r->sheets = xrealloc (r->sheets, sizeof (*r->sheets) * ++r->n_allocated_sheets);
r->sheets[r->n_allocated_sheets - 1].start_col = -1;
r->sheets[r->n_allocated_sheets - 1].name = value;
}
-
-
r->col = 0;
r->row = 0;
-
if ( r->target_sheet != NULL)
{
if ( 0 == xmlStrcmp (value, r->target_sheet))
r->sheet_found = true;
}
}
- else if (r->target_sheet_index == r->sheet_index)
+ else if (r->target_sheet_index == r->current_sheet)
{
r->sheet_found = true;
}
{
r->state = STATE_INIT;
printf ("%s:%d End of Workbook %d: Rows %d Cols %d\n", __FILE__, __LINE__,
- r->sheet_index, r->row, r->col);
+ r->current_sheet, r->row, r->col);
}
break;
case STATE_TABLE:
int row_span = value ? _xmlchar_to_int (value) : 1;
- printf ("%s:%d Start of Row %d Span %d\n", __FILE__, __LINE__, r->row, row_span);
r->row += row_span;
r->col = 0;
else if (0 == xmlStrcasecmp (name, _xml("table:table")) &&
(XML_READER_TYPE_END_ELEMENT == r->node_type))
{
- printf ("%s:%d End of SHEET %d %d,%d\n", __FILE__, __LINE__, r->sheet_index, r->row, r->col);
r->state = STATE_SPREADSHEET;
-
}
break;
case STATE_ROW:
xmlTextReaderGetAttribute (r->xtr,
_xml ("table:number-columns-repeated"));
- int col_span = value ? _xmlchar_to_int (value) : 1;
-
- r->col += col_span;
+ r->col_span = value ? _xmlchar_to_int (value) : 1;
+ r->col += r->col_span;
- printf ("%s:%d (span %d) Start of Cell %d, %d\n", __FILE__, __LINE__,
- col_span,
- r->row, r->col);
if (! xmlTextReaderIsEmptyElement (r->xtr))
r->state = STATE_CELL;
}
&&
(XML_READER_TYPE_END_ELEMENT == r->node_type))
{
- /* Set the span back to the default */
- printf ("%s:%d End of Cell: %d, %d\n", __FILE__, __LINE__, r->row, r->col);
r->state = STATE_TABLE;
}
break;
&&
( XML_READER_TYPE_ELEMENT == r->node_type))
{
- printf ("%s:%d Start of Cell Contents %d\n", __FILE__, __LINE__, r->row);
if (! xmlTextReaderIsEmptyElement (r->xtr))
r->state = STATE_CELL_CONTENT;
}
(XML_READER_TYPE_END_ELEMENT == r->node_type)
)
{
- printf ("%s:%d End of Cell contents: Rows %d\n", __FILE__, __LINE__, r->row);
r->state = STATE_ROW;
}
break;
case STATE_CELL_CONTENT:
- assert (r->sheet_index >= 0);
- assert (r->sheet_index < r->n_allocated_sheets);
+ assert (r->current_sheet >= 0);
+ assert (r->current_sheet < r->n_allocated_sheets);
- if (r->sheets[r->sheet_index].start_row == -1)
- r->sheets[r->sheet_index].start_row = r->row - 1;
+ if (r->sheets[r->current_sheet].start_row == -1)
+ r->sheets[r->current_sheet].start_row = r->row - 1;
if (
- (r->sheets[r->sheet_index].start_col == -1)
+ (r->sheets[r->current_sheet].start_col == -1)
||
- (r->sheets[r->sheet_index].start_col >= r->col - 1)
+ (r->sheets[r->current_sheet].start_col >= r->col - 1)
)
- r->sheets[r->sheet_index].start_col = r->col - 1;
+ r->sheets[r->current_sheet].start_col = r->col - 1;
- r->sheets[r->sheet_index].stop_row = r->row - 1;
- printf ("Stop Row for %d is %d\n", r->sheet_index, r->sheets[r->sheet_index].stop_row);
+ r->sheets[r->current_sheet].stop_row = r->row - 1;
- if ( r->sheets[r->sheet_index].stop_col < r->col - 1)
- r->sheets[r->sheet_index].stop_col = r->col - 1;
+ if ( r->sheets[r->current_sheet].stop_col < r->col - 1)
+ r->sheets[r->current_sheet].stop_col = r->col - 1;
if (XML_READER_TYPE_END_ELEMENT == r->node_type)
r->state = STATE_CELL;
r = xzalloc (sizeof *r);
r->zreader = zr;
- if (! init_reader (r, false))
+ if (! init_reader (r, report_errors))
{
goto error;
}
r->spreadsheet.n_sheets = sheet_count;
r->n_allocated_sheets = 0;
- r->sheet_index = -1;
r->sheets = NULL;
ds_destroy (&errs);
- printf ("%s:%d\n", __FILE__, __LINE__);
-
r->spreadsheet.file_name = filename;
return &r->spreadsheet;
ds_init_empty (&r->ods_errs);
- printf ("%s:%d\n", __FILE__, __LINE__);
-
if ( !init_reader (r, true))
goto error;
- printf ("%s:%d\n", __FILE__, __LINE__);
-
+#if 1
if ( opts->cell_range )
{
if ( ! convert_cell_ref (opts->cell_range,
r->stop_col = -1;
r->stop_row = -1;
}
+#endif
r->state = STATE_INIT;
r->target_sheet = BAD_CAST opts->sheet_name;
r->target_sheet_index = opts->sheet_index;
r->row = r->col = 0;
- r->sheet_index = 0;
-
- printf ("%s:%d\n", __FILE__, __LINE__);
-
/* If CELLRANGE was given, then we know how many variables should be read */
if ( r->stop_col != -1 )
memset (var_spec, '\0', sizeof (*var_spec) * n_var_specs);
}
- printf ("%s:%d Number of var specs %d\n", __FILE__, __LINE__, n_var_specs);
- printf ("%s:%d Target Sjheet %d\n", __FILE__, __LINE__, r->target_sheet_index);
-
-
/* Advance to the start of the cells for the target sheet */
- while ( r->sheet_index < r->target_sheet_index - 1 ||
+ while ( r->current_sheet < r->target_sheet_index - 1 ||
r->state != STATE_TABLE
)
{
process_node (r);
}
- printf ("%s:%d\n", __FILE__, __LINE__);
if (ret < 1)
{
goto error;
}
- printf ("%s:%d\n", __FILE__, __LINE__);
-
if ( opts->read_names)
{
while (1 == (ret = xmlTextReaderRead (r->xtr)))
/* If the row is finished then stop for now */
if (r->state == STATE_TABLE && r->row > r->start_row)
break;
-
+
idx = r->col - r->start_col - 1;
if (r->state == STATE_CELL_CONTENT
}
}
- printf ("%s:%d N varspecs %d\n", __FILE__, __LINE__, n_var_specs);
-
/* Read in the first row of data */
while (1 == xmlTextReaderRead (r->xtr))
{
process_node (r);
/* If the row is finished then stop for now */
- if (r->state == STATE_TABLE && r->row > r->start_row + 1)
+ if (r->state == STATE_TABLE && r->row > r->start_row + (opts->read_names ? 1 : 0))
break;
idx = r->col - r->start_col - 1;
if ( r->state == STATE_CELL_CONTENT &&
XML_READER_TYPE_TEXT == r->node_type)
{
-
if ( idx >= n_var_specs)
{
var_spec = xrealloc (var_spec, sizeof (*var_spec) * (idx + 1));
}
}
- printf ("%s:%d N varspecs %d\n", __FILE__, __LINE__, n_var_specs);
-
/* Create the dictionary and populate it */
r->spreadsheet.dict = r->dict = dict_create (
CHAR_CAST (const char *, xmlTextReaderConstEncoding (r->xtr)));
r->first_case = case_create (r->proto);
case_set_missing (r->first_case);
- printf ("%s:%d Hello %d\n", __FILE__, __LINE__, n_var_specs);
-
- for ( i = 0 ; i < n_var_specs ; ++i )
+ for (i = 0 ; i < n_var_specs; ++i)
{
const struct variable *var = dict_get_var (r->dict, i);
convert_xml_to_value (r->first_case, var, &var_spec[i].firstval);
}
- printf ("%s:%d Hello %d\n", __FILE__, __LINE__, n_var_specs);
+ /* Read in the first row of data */
+ while (1 == xmlTextReaderRead (r->xtr))
+ {
+ process_node (r);
+
+ if (r->state == STATE_ROW)
+ break;
+ }
// zip_reader_destroy (zreader);
free (var_spec);
#endif
- printf ("%s:%d Creating reader\n", __FILE__, __LINE__);
return casereader_create_sequential
(NULL,
r->proto,
struct ods_reader *r = r_;
int current_row = r->row;
- printf ("%s:%d Reading CASE\n", __FILE__, __LINE__);
-
if ( !r->used_first_case )
{
r->used_first_case = true;
return r->first_case;
}
- printf ("%s:%d Reading CASE\n", __FILE__, __LINE__);
-
if ( r->state > STATE_INIT)
{
c = case_create (r->proto);
case_set_missing (c);
}
- if (r->state == STATE_SPREADSHEET)
+ if (r->state == STATE_SPREADSHEET
+ &&
+ r->current_sheet == r->target_sheet_index - 1
+ )
{
- printf ("%s:%d CASES ARE ENDED\n", __FILE__, __LINE__);
return NULL;
}
while (1 == xmlTextReaderRead (r->xtr))
{
process_node (r);
- if ( r->row > current_row)
- {
- break;
- }
- if ( r->col < r->start_col || (r->stop_col != -1 && r->col > r->stop_col))
- {
- continue;
- }
- if ( r->col - r->start_col >= caseproto_get_n_widths (r->proto))
- {
- continue;
- }
- if ( r->stop_row != -1 && r->row > r->stop_row)
- {
- continue;
- }
+
+ if (r->row > current_row && r->state == STATE_ROW)
+ break;
+
if ( r->state == STATE_CELL &&
r->node_type == XML_READER_TYPE_ELEMENT )
{
val_string = xmlTextReaderGetAttribute (r->xtr, _xml ("office:value"));
}
- if ( r->state == STATE_CELL_CONTENT && r->node_type == XML_READER_TYPE_TEXT )
+ if ( r->state == STATE_CELL_CONTENT &&
+ r->node_type == XML_READER_TYPE_TEXT )
{
int col;
struct xml_value *xmv = xzalloc (sizeof *xmv);
xmv->value = val_string;
val_string = NULL;
- /*
- for (col = 0; col < r->span ; ++col)
+ for (col = 0; col < r->col_span; ++col)
{
- const int idx = r->col + col - r->start_col;
-
+ const int idx = r->col + col - r->start_col - 1;
const struct variable *var = dict_get_var (r->dict, idx);
-
convert_xml_to_value (c, var, xmv);
}
- */
+
free (xmv->text);
free (xmv->value);
free (xmv);
break;
}
- if (NULL == c || (r->stop_row != -1 && r->row > r->stop_row + 1))
+ if (NULL == c)
{
case_unref (c);
return NULL;