Commit ebcefbeb authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Remove parselines member.

2003-06-11  Morten Welinder  <terra@gnome.org>

	* src/stf-parse.h (StfParseOptions_t): Remove parselines member.

	* src/stf-parse.c (stf_parse_get_longest_row_width): Take a
	data_end pointer too.  Callers changed.
	(stf_parse_general): Ditto.
	(stf_parse_sheet): Ditto, but optional.
	(stf_parse_region): Ditto, but optional.
	(stf_parse_options_fixed_autodiscover): Ditto.  Remove data_lines arg.
	(stf_parse_options_set_lines_to_parse): Delete.

2003-06-11  Morten Welinder  <terra@gnome.org>

	* dialog-stf.c (stf_dialog): Nul-terminate result.
	* dialog-stf.h (DruidPageData_t): Add cur_end member.
parent 08c87614
......@@ -185,7 +185,7 @@ Pending Patches
2.15) Put big "best guess" button on from page.
2.16) Fix character set mess on paste (DONE)
2.17) Tabs: either map to spaces or handle expansion.
2.18) Kill use of "importlines" and properly find the end.
2.18) Kill use of "importlines" and properly find the end. (DONE)
3) hlinks
3.1) Finish the edit dialog to load and store results (DONE)
......
2003-06-11 Morten Welinder <terra@gnome.org>
* src/stf-parse.h (StfParseOptions_t): Remove parselines member.
* src/stf-parse.c (stf_parse_get_longest_row_width): Take a
data_end pointer too. Callers changed.
(stf_parse_general): Ditto.
(stf_parse_sheet): Ditto, but optional.
(stf_parse_region): Ditto, but optional.
(stf_parse_options_fixed_autodiscover): Ditto. Remove data_lines arg.
(stf_parse_options_set_lines_to_parse): Delete.
2003-06-11 Jody Goldberg <jody@gnome.org>
* schemas/gnumeric-general.schemas.in : Make the default number of
......
2003-06-11 Morten Welinder <terra@gnome.org>
* src/stf-parse.h (StfParseOptions_t): Remove parselines member.
* src/stf-parse.c (stf_parse_get_longest_row_width): Take a
data_end pointer too. Callers changed.
(stf_parse_general): Ditto.
(stf_parse_sheet): Ditto, but optional.
(stf_parse_region): Ditto, but optional.
(stf_parse_options_fixed_autodiscover): Ditto. Remove data_lines arg.
(stf_parse_options_set_lines_to_parse): Delete.
2003-06-11 Jody Goldberg <jody@gnome.org>
* schemas/gnumeric-general.schemas.in : Make the default number of
......
2003-06-11 Morten Welinder <terra@gnome.org>
* src/stf-parse.h (StfParseOptions_t): Remove parselines member.
* src/stf-parse.c (stf_parse_get_longest_row_width): Take a
data_end pointer too. Callers changed.
(stf_parse_general): Ditto.
(stf_parse_sheet): Ditto, but optional.
(stf_parse_region): Ditto, but optional.
(stf_parse_options_fixed_autodiscover): Ditto. Remove data_lines arg.
(stf_parse_options_set_lines_to_parse): Delete.
2003-06-11 Jody Goldberg <jody@gnome.org>
* schemas/gnumeric-general.schemas.in : Make the default number of
......
2003-06-11 Morten Welinder <terra@gnome.org>
* dialog-stf.c (stf_dialog): Nul-terminate result.
* dialog-stf.h (DruidPageData_t): Add cur_end member.
* dialog-stf.h (MainInfo_t): Add parse options member.
* dialog-stf-main-page.c (main_page_startrow_changed): Treat line
......
......@@ -91,7 +91,9 @@ csv_page_global_change (G_GNUC_UNUSED GtkWidget *widget,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_duplicates)));
stf_preview_set_lines (renderdata,
stf_parse_general (parseoptions, data->cur));
stf_parse_general (parseoptions,
data->cur,
data->cur_end));
stf_preview_render (renderdata);
}
......@@ -138,7 +140,6 @@ csv_page_prepare (G_GNUC_UNUSED GnomeDruidPage *page,
DruidPageData_t *pagedata)
{
stf_parse_options_set_trim_spaces (pagedata->csv.parseoptions, pagedata->trim);
stf_parse_options_set_lines_to_parse (pagedata->csv.parseoptions, pagedata->importlines);
if (format_get_arg_sep () == ',')
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_comma), TRUE);
......
......@@ -44,7 +44,8 @@ fixed_page_autodiscover (DruidPageData_t *pagedata)
guint i = 1;
char *tset[2];
stf_parse_options_fixed_autodiscover (pagedata->fixed.parseoptions, pagedata->importlines, (char *) pagedata->cur);
stf_parse_options_fixed_autodiscover (pagedata->fixed.parseoptions,
pagedata->cur, pagedata->cur_end);
gtk_clist_clear (pagedata->fixed.fixed_collist);
while (i < pagedata->fixed.parseoptions->splitpositions->len) {
......@@ -203,7 +204,9 @@ fixed_page_update_preview (DruidPageData_t *pagedata)
}
stf_preview_set_lines (renderdata,
stf_parse_general (parseoptions, pagedata->cur));
stf_parse_general (parseoptions,
pagedata->cur,
pagedata->cur_end));
stf_preview_render (renderdata);
for (i = 0; i < renderdata->colcount; i++) {
......@@ -420,14 +423,15 @@ fixed_page_prepare (G_GNUC_UNUSED GnomeDruidPage *page,
GtkAdjustment *spinadjust;
stf_parse_options_set_trim_spaces (pagedata->fixed.parseoptions, TRIM_TYPE_NEVER);
stf_parse_options_set_lines_to_parse (pagedata->fixed.parseoptions, pagedata->importlines);
#if 0
stf_preview_set_startrow (pagedata->fixed.renderdata, GTK_RANGE (pagedata->fixed.fixed_scroll)->adjustment->value);
#endif
spinadjust = gtk_spin_button_get_adjustment (pagedata->fixed.fixed_colend);
spinadjust->lower = 1;
spinadjust->upper = stf_parse_get_longest_row_width (pagedata->fixed.parseoptions, pagedata->cur);
spinadjust->upper = stf_parse_get_longest_row_width (pagedata->fixed.parseoptions,
pagedata->cur,
pagedata->cur_end);
gtk_spin_button_set_adjustment (pagedata->fixed.fixed_colend, spinadjust);
fixed_page_update_preview (pagedata);
......
......@@ -93,7 +93,8 @@ format_page_update_preview (DruidPageData_t *pagedata)
stf_preview_set_lines (renderdata,
stf_parse_general (pagedata->format.parseoptions,
pagedata->cur));
pagedata->cur,
pagedata->cur_end));
stf_preview_render (renderdata);
for (i = 0; i < renderdata->colcount; i++) {
......
......@@ -173,44 +173,28 @@ encodings_changed_cb (CharmapSelector *cs, char const *new_charmap,
static void
main_page_startrow_changed (GtkSpinButton* button, DruidPageData_t *data)
{
const char *cur = data->utf8_data;
int startrow = gtk_spin_button_get_value_as_int (button) - 1;
#warning "FIXME: this should match stf_parse_lines."
while (startrow > 0) {
switch (*cur) {
case 0:
startrow = 0;
break;
case '\n':
startrow--;
cur++;
break;
case '\r':
startrow--;
cur++;
if (*cur == '\n') cur++;
break;
default:
cur++;
}
}
data->cur = cur;
StfParseOptions_t *parseoptions = data->main.parseoptions;
int line = gtk_spin_button_get_value_as_int (button) - 1;
data->cur = stf_parse_find_line (parseoptions, data->utf8_data, line);
main_page_import_range_changed (data);
}
/**
* main_page_startrow_changed
* main_page_stoprow_changed
* @button : the spinbutton the event handler is attached to
* @data : mother struct
*
* returns : nothing
**/
static void
main_page_stoprow_changed (G_GNUC_UNUSED GtkSpinButton* button,
main_page_stoprow_changed (GtkSpinButton* button,
DruidPageData_t *data)
{
StfParseOptions_t *parseoptions = data->main.parseoptions;
int line = gtk_spin_button_get_value_as_int (button) - 1;
data->cur_end = stf_parse_find_line (parseoptions, data->utf8_data, line + 1);
main_page_import_range_changed (data);
}
......@@ -218,6 +202,7 @@ static void
main_page_stringindicator_change (G_GNUC_UNUSED GtkWidget *widget,
DruidPageData_t *data)
{
#warning "FIXME: csv?"
StfParseOptions_t *parseoptions = data->csv.parseoptions;
char *textfieldtext;
gunichar str_ind;
......@@ -245,8 +230,6 @@ main_page_source_format_toggled (G_GNUC_UNUSED GtkWidget *widget,
gtk_widget_set_sensitive (GTK_WIDGET (data->main.main_2x_indicator), active);
gtk_widget_set_sensitive (GTK_WIDGET (data->main.main_textindicator), active);
gtk_widget_set_sensitive (GTK_WIDGET (data->main.main_textfield), active);
main_page_stoprow_changed (NULL, data);
}
/**
......@@ -387,6 +370,7 @@ stf_dialog_main_page_init (GladeXML *gui, DruidPageData_t *pagedata)
g_signal_connect (G_OBJECT (pagedata->main.charmap_selector),
"charmap_changed",
G_CALLBACK (encodings_changed_cb), pagedata);
main_page_startrow_changed (pagedata->main.main_startrow, pagedata);
main_page_stoprow_changed (pagedata->main.main_stoprow, pagedata);
}
......@@ -499,6 +499,7 @@ stf_dialog (WorkbookControlGUI *wbcg,
dialogresult = g_new (DialogStfResult_t, 1);
dialogresult->text = pagedata.utf8_data;
*((char *)pagedata.cur_end) = 0;
strcpy (dialogresult->text, pagedata.cur);
pagedata.cur = pagedata.utf8_data = NULL;
......
......@@ -100,6 +100,7 @@ typedef struct {
const char *raw_data; /* Raw bytes, not UTF-8. */
char *utf8_data; /* raw_data converted into UTF-8. */
const char *cur; /* Pointer pointing to position in utf8_data to start parsing */
const char *cur_end; /* Pointer pointing to position in utf8_data to stop parsing */
const char *filename; /* File we are reading from */
int importlines; /* Number of lines to import */
......
......@@ -104,8 +104,7 @@ text_to_cell_region (WorkbookControlGUI *wbcg,
if (dialogresult != NULL) {
int col;
stf_parse_options_set_lines_to_parse (dialogresult->parseoptions, dialogresult->lines);
cr = stf_parse_region (dialogresult->parseoptions, dialogresult->text);
cr = stf_parse_region (dialogresult->parseoptions, dialogresult->text, NULL);
if (cr == NULL) {
g_free (data);
......
......@@ -126,7 +126,6 @@ stf_parse_options_new (void)
parseoptions->terminator = g_create_slist (g_strdup("\r\n"), g_strdup("\n"), g_strdup("\r"), NULL);
parseoptions->parselines = -1;
parseoptions->trim_spaces = (TRIM_TYPE_RIGHT | TRIM_TYPE_LEFT);
parseoptions->splitpositions = g_array_new (FALSE, FALSE, sizeof (int));
......@@ -244,25 +243,6 @@ stf_parse_options_clear_line_terminator (StfParseOptions_t *parseoptions)
parseoptions->terminator = NULL;
}
/**
* stf_parse_options_set_lines_to_parse:
*
* This forces the parser to stop after parsing @lines lines, if you set @lines
* to -1, which is the default, the parser will parse until it encounters a '\0'
**/
void
stf_parse_options_set_lines_to_parse (StfParseOptions_t *parseoptions, int const lines)
{
g_return_if_fail (parseoptions != NULL);
if (lines != -1)
parseoptions->parselines = lines;
else
parseoptions->parselines = -1;
}
/**
* stf_parse_options_set_trim_spaces:
*
......@@ -710,7 +690,8 @@ stf_parse_general_free (GPtrArray *lines)
* stf_parse_general_free.
**/
GPtrArray *
stf_parse_general (StfParseOptions_t *parseoptions, char const *data)
stf_parse_general (StfParseOptions_t *parseoptions,
char const *data, char const *data_end)
{
GPtrArray *lines;
Source_t src;
......@@ -718,6 +699,7 @@ stf_parse_general (StfParseOptions_t *parseoptions, char const *data)
g_return_val_if_fail (parseoptions != NULL, NULL);
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (data_end != NULL, NULL);
g_return_val_if_fail (stf_parse_options_valid (parseoptions), NULL);
g_return_val_if_fail (g_utf8_validate (data, -1, NULL), NULL);
......@@ -725,7 +707,7 @@ stf_parse_general (StfParseOptions_t *parseoptions, char const *data)
row = 0;
lines = g_ptr_array_new ();
while (*src.position != '\0') {
while (*src.position != '\0' && src.position < data_end) {
GPtrArray *line;
if (++row >= SHEET_MAX_ROWS) {
......@@ -733,10 +715,6 @@ stf_parse_general (StfParseOptions_t *parseoptions, char const *data)
break;
}
if (parseoptions->parselines != -1)
if (row > parseoptions->parselines)
break;
line = parseoptions->parsetype == PARSE_TYPE_CSV
? stf_parse_csv_line (&src, parseoptions)
: stf_parse_fixed_line (&src, parseoptions);
......@@ -779,38 +757,54 @@ stf_parse_lines (StfParseOptions_t *parseoptions, const char *data, gboolean wit
return lines;
}
const char *
stf_parse_find_line (StfParseOptions_t *parseoptions,
const char *data,
int line)
{
while (line > 0) {
int termlen = compare_terminator (data, parseoptions);
if (termlen > 0) {
data += termlen;
line--;
} else if (*data == 0) {
return data;
} else {
data = g_utf8_next_char (data);
}
}
return data;
}
/**
* stf_parse_get_longest_row_width:
*
* Returns the largest number of characters found in a line/row
**/
int
stf_parse_get_longest_row_width (StfParseOptions_t *parseoptions, char const *data)
stf_parse_get_longest_row_width (StfParseOptions_t *parseoptions,
char const *data, char const *data_end)
{
char const *s;
int len = 0;
int longest = 0;
int row = 0;
g_return_val_if_fail (parseoptions != NULL, 0);
g_return_val_if_fail (data != NULL, 0);
g_return_val_if_fail (data_end != NULL, 0);
for (s = data; *s; ) {
for (s = data; *s && s < data_end; ) {
int termlen = compare_terminator (s, parseoptions);
if (termlen > 0 || s[1] == '\0') {
if (len > longest)
longest = len;
len = 0;
row++;
s += termlen;
} else {
len++;
s = g_utf8_next_char (s);
}
if (parseoptions->parselines != -1)
if (row > parseoptions->parselines)
break;
}
return longest;
......@@ -830,7 +824,8 @@ stf_parse_get_longest_row_width (StfParseOptions_t *parseoptions, char const *da
* Think hard of a better more flexible solution...
**/
void
stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const data_lines, char const *data)
stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions,
char const *data, char const *data_end)
{
char const *iterator = data;
GSList *list = NULL;
......@@ -847,7 +842,7 @@ stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const
/*
* First take a look at all possible white space combinations
*/
while (*iterator) {
while (*iterator && iterator < data_end) {
gboolean begin_recorded = FALSE;
AutoDiscovery_t *disc = NULL;
int position = 0;
......@@ -891,9 +886,6 @@ stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const
effective_lines++;
lines++;
if (lines >= data_lines)
break;
}
list = g_slist_reverse (list);
......@@ -954,7 +946,7 @@ stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const
iterator = data;
lines = 0;
while (*iterator) {
while (*iterator && iterator < data_end) {
gboolean trigger = FALSE;
gboolean space_trigger = FALSE;
int pos = 0;
......@@ -995,9 +987,6 @@ stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const
iterator++;
lines++;
if (lines >= data_lines)
break;
}
/*
......@@ -1027,7 +1016,7 @@ stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const
iterator = data;
lines = 0;
while (*iterator) {
while (*iterator && iterator < data_end) {
gboolean trigger = FALSE;
int pos = 0;
......@@ -1050,9 +1039,6 @@ stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const
iterator++;
lines++;
if (lines >= data_lines)
break;
}
/*
......@@ -1083,8 +1069,9 @@ stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int const
*******************************************************************************************************/
gboolean
stf_parse_sheet (StfParseOptions_t *parseoptions, char const *data, Sheet *sheet,
int start_col, int start_row)
stf_parse_sheet (StfParseOptions_t *parseoptions,
char const *data, char const *data_end,
Sheet *sheet, int start_col, int start_row)
{
int row;
unsigned int lrow;
......@@ -1097,7 +1084,9 @@ stf_parse_sheet (StfParseOptions_t *parseoptions, char const *data, Sheet *sheet
date_conv = workbook_date_conv (sheet->workbook);
lines = stf_parse_general (parseoptions, data);
if (!data_end)
data_end = data + strlen (data);
lines = stf_parse_general (parseoptions, data, data_end);
for (row = start_row, lrow = 0; lrow < lines->len ; row++, lrow++) {
unsigned int lcol;
GPtrArray *line = g_ptr_array_index (lines, lrow);
......@@ -1125,7 +1114,7 @@ stf_parse_sheet (StfParseOptions_t *parseoptions, char const *data, Sheet *sheet
}
CellRegion *
stf_parse_region (StfParseOptions_t *parseoptions, char const *data)
stf_parse_region (StfParseOptions_t *parseoptions, char const *data, char const *data_end)
{
CellRegion *cr;
CellCopyList *content = NULL;
......@@ -1135,7 +1124,9 @@ stf_parse_region (StfParseOptions_t *parseoptions, char const *data)
g_return_val_if_fail (parseoptions != NULL, NULL);
g_return_val_if_fail (data != NULL, NULL);
lines = stf_parse_general (parseoptions, data);
if (!data_end)
data_end = data + strlen (data);
lines = stf_parse_general (parseoptions, data, data_end);
for (row = 0; row < lines->len; row++) {
GPtrArray *line = g_ptr_array_index (lines, row);
unsigned int col;
......
......@@ -32,7 +32,6 @@ typedef enum {
typedef struct {
StfParseType_t parsetype; /* The type of import to do */
GSList * terminator; /* Line terminators */
int parselines; /* Number of lines to parse */
StfTrimType_t trim_spaces; /* Trim spaces in fields ? */
/* CSV related */
......@@ -65,8 +64,6 @@ void stf_parse_options_add_line_terminator (StfParseOptions_t *parse
char const *terminator);
void stf_parse_options_remove_line_terminator (StfParseOptions_t *parseoptions,
char const *terminator);
void stf_parse_options_set_lines_to_parse (StfParseOptions_t *parseoptions,
int const lines);
void stf_parse_options_set_trim_spaces (StfParseOptions_t *parseoptions,
StfTrimType_t const trim_spaces);
void stf_parse_options_csv_set_separators (StfParseOptions_t *parseoptions,
......@@ -84,17 +81,24 @@ void stf_parse_options_fixed_splitpositions_add (StfParseOptions_t *parse
/* USING the stf structs to actually do some parsing, these are the lower-level functions and utility functions */
GPtrArray *stf_parse_general (StfParseOptions_t *parseoptions,
char const *data);
char const *data,
char const *data_end);
void stf_parse_general_free (GPtrArray *lines);
GPtrArray *stf_parse_lines (StfParseOptions_t *parseoptions,
const char *data,
gboolean with_lineno);
int stf_parse_get_longest_row_width (StfParseOptions_t *parseoptions,
const char *data);
const char *data,
char const *data_end);
void stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions,
int const data_lines, char const *data);
char const *data,
char const *data_end);
const char *stf_parse_find_line (StfParseOptions_t *parseoptions,
const char *data,
int line);
char const *stf_parse_next_token (char const *data,
StfParseOptions_t *parseoptions,
......@@ -102,9 +106,10 @@ char const *stf_parse_next_token (char cons
/* Higher level functions, can be used for directly parsing into an application specific data container */
gboolean stf_parse_sheet (StfParseOptions_t *parseoptions,
char const *data, Sheet *sheet,
char const *data, char const *data_end,
Sheet *sheet,
int start_col, int start_row);
CellRegion *stf_parse_region (StfParseOptions_t *parseoptions,
char const *data);
char const *data, char const *data_end);
#endif
......@@ -121,8 +121,6 @@ stf_store_results (DialogStfResult_t *dialogresult,
{
unsigned int ui;
stf_parse_options_set_lines_to_parse (dialogresult->parseoptions, dialogresult->lines);
for (ui = 0; ui < dialogresult->formats->len; ui++) {
StyleFormat *sf = g_ptr_array_index (dialogresult->formats, ui);
Range range;
......@@ -139,7 +137,7 @@ stf_store_results (DialogStfResult_t *dialogresult,
}
return stf_parse_sheet (dialogresult->parseoptions,
dialogresult->text, sheet,
dialogresult->text, NULL, sheet,
start_col, start_row);
}
......@@ -340,7 +338,6 @@ stf_read_workbook_auto_csvtab (GnmFileOpener const *fo, gchar const *enc,
stf_parse_options_set_type (po, PARSE_TYPE_CSV);
stf_parse_options_set_trim_spaces (po, TRIM_TYPE_LEFT | TRIM_TYPE_RIGHT);
stf_parse_options_set_lines_to_parse (po, -1);
stf_parse_options_csv_set_stringindicator (po, '"');
stf_parse_options_csv_set_indicator_2x_is_single (po, TRUE);
stf_parse_options_csv_set_duplicates (po, FALSE);
......@@ -373,7 +370,7 @@ stf_read_workbook_auto_csvtab (GnmFileOpener const *fo, gchar const *enc,
if (tab > lines || tab >= sep)
stf_parse_options_csv_set_separators (po, "\t", NULL);
if (!stf_parse_sheet (po, data, sheet, 0, 0)) {
if (!stf_parse_sheet (po, data, NULL, sheet, 0, 0)) {
workbook_sheet_detach (book, sheet);
g_free (data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment