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

New function. (stf_parse_options_add_line_terminator,

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

	* src/stf-parse.c (compile_terminators): New function.
	(stf_parse_options_add_line_terminator,
	stf_parse_options_remove_line_terminator,
	stf_parse_options_clear_line_terminator): Call
	compile_terminators, fix memory ownership.
	(stf_parse_options_new): Set terminators using
	stf_parse_options_add_line_terminator.
	(compare_terminator): Speed up using compiled terminators.

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

	* gnumeric-optionmenu.c (gnumeric_option_menu_destroy): Leak fix.

	* widget-charmap-selector.c (cs_build_menu): Leak fix.

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

	* dialog-stf-preview.c (render_get_value): Change tabs into spaces
	here.
	(stf_preview_set_lines): Clear the table here too.
	(stf_preview_render): Merge into stf_preview_set_lines, then
	remove.

	* dialog-stf.h (DruidPageData_t): Add parseoptions here.  Remove
	from all page structs.

	* dialog-stf-fixed-page.c (fixed_page_update_preview): Turn off
	trimming here.
parent b470418e
2003-06-12 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (compile_terminators): New function.
(stf_parse_options_add_line_terminator,
stf_parse_options_remove_line_terminator,
stf_parse_options_clear_line_terminator): Call
compile_terminators, fix memory ownership.
(stf_parse_options_new): Set terminators using
stf_parse_options_add_line_terminator.
(compare_terminator): Speed up using compiled terminators.
2003-06-12 Andreas J. Guelzow <aguelzow@taliesin.ca>
* configure.in: added en_CA
......
2003-06-12 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (compile_terminators): New function.
(stf_parse_options_add_line_terminator,
stf_parse_options_remove_line_terminator,
stf_parse_options_clear_line_terminator): Call
compile_terminators, fix memory ownership.
(stf_parse_options_new): Set terminators using
stf_parse_options_add_line_terminator.
(compare_terminator): Speed up using compiled terminators.
2003-06-12 Andreas J. Guelzow <aguelzow@taliesin.ca>
* configure.in: added en_CA
......
2003-06-12 Morten Welinder <terra@gnome.org>
* src/stf-parse.c (compile_terminators): New function.
(stf_parse_options_add_line_terminator,
stf_parse_options_remove_line_terminator,
stf_parse_options_clear_line_terminator): Call
compile_terminators, fix memory ownership.
(stf_parse_options_new): Set terminators using
stf_parse_options_add_line_terminator.
(compare_terminator): Speed up using compiled terminators.
2003-06-12 Andreas J. Guelzow <aguelzow@taliesin.ca>
* configure.in: added en_CA
......
2003-06-12 Morten Welinder <terra@gnome.org>
* dialog-stf-preview.c (render_get_value): Change tabs into spaces
here.
(stf_preview_set_lines): Clear the table here too.
(stf_preview_render): Merge into stf_preview_set_lines, then
remove.
* dialog-stf.h (DruidPageData_t): Add parseoptions here. Remove
from all page structs.
* dialog-stf-fixed-page.c (fixed_page_update_preview): Turn off
trimming here.
2003-06-12 Andreas J. Guelzow <aguelzow@taliesin.ca>
* dialog-analysis-tools.c (regression_tool_ok_clicked_cb):
......
......@@ -40,16 +40,18 @@
**/
static void
csv_page_global_change (G_GNUC_UNUSED GtkWidget *widget,
DruidPageData_t *data)
DruidPageData_t *pagedata)
{
StfParseOptions_t *parseoptions = data->csv.parseoptions;
RenderData_t *renderdata = data->csv.renderdata;
StfParseOptions_t *parseoptions = pagedata->parseoptions;
RenderData_t *renderdata = pagedata->csv.renderdata;
GSList *sepstr;
GString *sepc = g_string_new (NULL);
GPtrArray *lines;
StfTrimType_t trim;
sepstr = NULL;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_custom))) {
char *csvcustomtext = gtk_editable_get_chars (GTK_EDITABLE (data->csv.csv_customseparator), 0, -1);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_custom))) {
char *csvcustomtext = gtk_editable_get_chars (GTK_EDITABLE (pagedata->csv.csv_customseparator), 0, -1);
if (strcmp (csvcustomtext, "") != 0)
sepstr = g_slist_append (sepstr, csvcustomtext);
......@@ -57,44 +59,42 @@ csv_page_global_change (G_GNUC_UNUSED GtkWidget *widget,
g_free (csvcustomtext);
}
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_tab)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_tab)))
g_string_append_c (sepc, '\t');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_colon)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_colon)))
g_string_append_c (sepc, ':');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_comma)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_comma)))
g_string_append_c (sepc, ',');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_space)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_space)))
g_string_append_c (sepc, ' ');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_semicolon)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_semicolon)))
g_string_append_c (sepc, ';');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_pipe)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_pipe)))
g_string_append_c (sepc, '|');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_slash)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_slash)))
g_string_append_c (sepc, '/');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_hyphen)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_hyphen)))
g_string_append_c (sepc, '-');
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_bang)))
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_bang)))
g_string_append_c (sepc, '!');
stf_parse_options_csv_set_separators (parseoptions,
strcmp (sepc->str, "") == 0 ? NULL : sepc->str,
sepstr);
g_string_free (sepc, TRUE);
if (sepstr) {
GSList *l;
for (l = sepstr; l != NULL; l = l->next)
g_free ((char *) l->data);
g_slist_free (sepstr);
}
g_slist_free_custom (sepstr, g_free);
stf_parse_options_csv_set_duplicates (parseoptions,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->csv.csv_duplicates)));
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_duplicates)));
/* Don't trim on this page. */
trim = parseoptions->trim_spaces;
stf_parse_options_set_trim_spaces (parseoptions, TRIM_TYPE_NEVER);
lines = stf_parse_general (parseoptions,
pagedata->cur, pagedata->cur_end);
stf_parse_options_set_trim_spaces (parseoptions, trim);
stf_preview_set_lines (renderdata,
stf_parse_general (parseoptions,
data->cur,
data->cur_end));
stf_preview_render (renderdata);
stf_preview_set_lines (renderdata, lines);
}
/**
......@@ -139,17 +139,13 @@ csv_page_prepare (G_GNUC_UNUSED GnomeDruidPage *page,
G_GNUC_UNUSED GnomeDruid *druid,
DruidPageData_t *pagedata)
{
stf_parse_options_set_trim_spaces (pagedata->csv.parseoptions, pagedata->trim);
stf_parse_options_set_trim_spaces (pagedata->parseoptions, pagedata->trim);
if (format_get_arg_sep () == ',')
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_comma), TRUE);
else
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_semicolon), TRUE);
#if 0
stf_preview_set_startrow (pagedata->csv.renderdata, GTK_RANGE (pagedata->csv.csv_scroll)->adjustment->value);
#endif
/* Calling this routine will also automatically call global change which updates the preview too */
csv_page_custom_toggled (pagedata->csv.csv_custom, pagedata);
}
......@@ -169,11 +165,6 @@ csv_page_prepare (G_GNUC_UNUSED GnomeDruidPage *page,
void
stf_dialog_csv_page_cleanup (DruidPageData_t *pagedata)
{
if (pagedata->csv.parseoptions) {
stf_parse_options_free (pagedata->csv.parseoptions);
pagedata->csv.parseoptions = NULL;
}
stf_preview_free (pagedata->csv.renderdata);
pagedata->csv.renderdata = NULL;
}
......@@ -214,9 +205,6 @@ stf_dialog_csv_page_init (GladeXML *gui, DruidPageData_t *pagedata)
pagedata->csv.renderdata =
stf_preview_new (pagedata->csv.csv_data_container,
NULL);
pagedata->csv.parseoptions = stf_parse_options_new ();
stf_parse_options_set_type (pagedata->csv.parseoptions, PARSE_TYPE_CSV);
/* Connect signals */
g_signal_connect (G_OBJECT (pagedata->csv.csv_tab),
......
......@@ -44,13 +44,13 @@ fixed_page_autodiscover (DruidPageData_t *pagedata)
guint i = 1;
char *tset[2];
stf_parse_options_fixed_autodiscover (pagedata->fixed.parseoptions,
stf_parse_options_fixed_autodiscover (pagedata->parseoptions,
pagedata->cur, pagedata->cur_end);
gtk_clist_clear (pagedata->fixed.fixed_collist);
while (i < pagedata->fixed.parseoptions->splitpositions->len) {
while (i < pagedata->parseoptions->splitpositions->len) {
tset[0] = g_strdup_printf ("%d", i - 1);
tset[1] = g_strdup_printf ("%d", g_array_index (pagedata->fixed.parseoptions->splitpositions,
tset[1] = g_strdup_printf ("%d", g_array_index (pagedata->parseoptions->splitpositions,
int,
i));
gtk_clist_append (pagedata->fixed.fixed_collist, tset);
......@@ -74,7 +74,7 @@ fixed_page_autodiscover (DruidPageData_t *pagedata)
* no columns where found
*/
if (pagedata->fixed.parseoptions->splitpositions->len < 1) {
if (pagedata->parseoptions->splitpositions->len < 1) {
GtkWidget *dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
......@@ -191,23 +191,28 @@ cb_col_event (GtkWidget *button,
static void
fixed_page_update_preview (DruidPageData_t *pagedata)
{
StfParseOptions_t *parseoptions = pagedata->fixed.parseoptions;
StfParseOptions_t *parseoptions = pagedata->parseoptions;
RenderData_t *renderdata = pagedata->fixed.renderdata;
char *t[2];
int i, temp;
int i;
GPtrArray *lines;
StfTrimType_t trim;
stf_parse_options_fixed_splitpositions_clear (parseoptions);
for (i = 0; i < GTK_CLIST (pagedata->fixed.fixed_collist)->rows; i++) {
char *t[2];
gtk_clist_get_text (pagedata->fixed.fixed_collist, i, 1, t);
temp = atoi (t[0]);
stf_parse_options_fixed_splitpositions_add (parseoptions, temp);
stf_parse_options_fixed_splitpositions_add (parseoptions, atoi (t[0]));
}
stf_preview_set_lines (renderdata,
stf_parse_general (parseoptions,
pagedata->cur,
pagedata->cur_end));
stf_preview_render (renderdata);
/* Don't trim on this page. */
trim = parseoptions->trim_spaces;
stf_parse_options_set_trim_spaces (parseoptions, TRIM_TYPE_NEVER);
lines = stf_parse_general (parseoptions,
pagedata->cur, pagedata->cur_end);
stf_parse_options_set_trim_spaces (parseoptions, trim);
stf_preview_set_lines (renderdata, lines);
for (i = 0; i < renderdata->colcount; i++) {
GtkTreeViewColumn *column =
......@@ -422,14 +427,14 @@ 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_trim_spaces (pagedata->parseoptions, TRIM_TYPE_NEVER);
#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,
spinadjust->upper = stf_parse_get_longest_row_width (pagedata->parseoptions,
pagedata->cur,
pagedata->cur_end);
gtk_spin_button_set_adjustment (pagedata->fixed.fixed_colend, spinadjust);
......@@ -453,11 +458,6 @@ void
stf_dialog_fixed_page_cleanup (DruidPageData_t *pagedata)
{
stf_preview_free (pagedata->fixed.renderdata);
if (pagedata->fixed.parseoptions) {
stf_parse_options_free (pagedata->fixed.parseoptions);
pagedata->fixed.parseoptions = NULL;
}
}
/**
......@@ -491,14 +491,11 @@ stf_dialog_fixed_page_init (GladeXML *gui, DruidPageData_t *pagedata)
pagedata->fixed.renderdata =
stf_preview_new (pagedata->fixed.fixed_data_container,
NULL);
pagedata->fixed.parseoptions = stf_parse_options_new ();
pagedata->fixed.manual = FALSE;
pagedata->fixed.index = -1;
pagedata->fixed.mousedown = FALSE;
pagedata->fixed.xorigin = 0;
stf_parse_options_set_type (pagedata->fixed.parseoptions, PARSE_TYPE_FIXED);
gtk_clist_column_titles_passive (pagedata->fixed.fixed_collist);
t[0] = g_strdup ("0");
......
......@@ -92,10 +92,9 @@ format_page_update_preview (DruidPageData_t *pagedata)
}
stf_preview_set_lines (renderdata,
stf_parse_general (pagedata->format.parseoptions,
stf_parse_general (pagedata->parseoptions,
pagedata->cur,
pagedata->cur_end));
stf_preview_render (renderdata);
for (i = 0; i < renderdata->colcount; i++) {
GtkTreeViewColumn *column =
......@@ -368,7 +367,6 @@ stf_dialog_format_page_init (GladeXML *gui, DruidPageData_t *pagedata)
pagedata->format.index = -1;
pagedata->format.manual_change = FALSE;
pagedata->format.sublist_select = TRUE;
pagedata->format.parseoptions = NULL; /* stf_parse_options_new (); */
gtk_clist_column_titles_passive (pagedata->format.format_sublist);
......
......@@ -70,12 +70,11 @@ main_page_set_encoding (DruidPageData_t *pagedata, const char *enc)
static void
main_page_update_preview (DruidPageData_t *pagedata)
{
StfParseOptions_t *parseoptions = pagedata->main.parseoptions;
RenderData_t *renderdata = pagedata->main.renderdata;
stf_preview_set_lines (renderdata,
stf_parse_lines (parseoptions, pagedata->utf8_data, TRUE));
stf_preview_render (renderdata);
stf_parse_lines (pagedata->parseoptions,
pagedata->utf8_data, TRUE));
}
......@@ -110,7 +109,6 @@ static void
main_page_import_range_changed (DruidPageData_t *data)
{
RenderData_t *renderdata = data->main.renderdata;
StfParseOptions_t *parseoptions = data->main.parseoptions;
int startrow, stoprow;
char *linescaption;
......@@ -130,8 +128,8 @@ main_page_import_range_changed (DruidPageData_t *data)
main_page_set_spin_button_adjustment (data->main.main_startrow, 1, stoprow);
main_page_set_spin_button_adjustment (data->main.main_stoprow, startrow, renderdata->lines->len);
data->cur = stf_parse_find_line (parseoptions, data->utf8_data, startrow - 1);
data->cur_end = stf_parse_find_line (parseoptions, data->utf8_data, stoprow);
data->cur = stf_parse_find_line (data->parseoptions, data->utf8_data, startrow - 1);
data->cur_end = stf_parse_find_line (data->parseoptions, data->utf8_data, stoprow);
data->importlines = (stoprow - startrow) + 1;
linescaption = g_strdup_printf (_("%d of %d lines to import"),
......@@ -200,19 +198,17 @@ 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;
textfieldtext = gtk_editable_get_chars (GTK_EDITABLE (data->main.main_textfield), 0, -1);
str_ind = g_utf8_get_char (textfieldtext);
if (str_ind != '\0')
stf_parse_options_csv_set_stringindicator (parseoptions,
stf_parse_options_csv_set_stringindicator (data->parseoptions,
str_ind);
g_free (textfieldtext);
stf_parse_options_csv_set_indicator_2x_is_single (parseoptions,
stf_parse_options_csv_set_indicator_2x_is_single (data->parseoptions,
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->main.main_2x_indicator)));
}
......@@ -226,6 +222,9 @@ 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);
stf_parse_options_set_type (data->parseoptions,
active ? PARSE_TYPE_CSV : PARSE_TYPE_FIXED);
}
/**
......@@ -244,6 +243,7 @@ main_page_prepare (G_GNUC_UNUSED GnomeDruidPage *page,
G_GNUC_UNUSED GnomeDruid *druid,
DruidPageData_t *pagedata)
{
main_page_source_format_toggled (NULL, pagedata);
main_page_update_preview (pagedata);
}
......@@ -256,11 +256,6 @@ void
stf_dialog_main_page_cleanup (DruidPageData_t *pagedata)
{
stf_preview_free (pagedata->main.renderdata);
if (pagedata->main.parseoptions) {
stf_parse_options_free (pagedata->main.parseoptions);
pagedata->main.parseoptions = NULL;
}
}
/**
......@@ -307,7 +302,6 @@ stf_dialog_main_page_init (GladeXML *gui, DruidPageData_t *pagedata)
renderdata = pagedata->main.renderdata = stf_preview_new
(pagedata->main.main_data_container,
NULL);
pagedata->main.parseoptions = stf_parse_options_new ();
renderdata->ignore_formats = TRUE;
main_page_update_preview (pagedata);
......@@ -365,5 +359,6 @@ stf_dialog_main_page_init (GladeXML *gui, DruidPageData_t *pagedata)
"charmap_changed",
G_CALLBACK (encodings_changed_cb), pagedata);
main_page_source_format_toggled (NULL, pagedata);
main_page_import_range_changed (pagedata);
}
......@@ -91,74 +91,23 @@ render_get_value (gint row, gint column, gpointer _rd, GValue *value)
g_value_init (value, ll->column_headers[column]);
if (text) {
char *copy = NULL;
char *tab = strchr (text, '\t');
if (tab) {
copy = g_strdup (text);
tab = copy + (tab - text);
do {
*tab = ' ';
tab = strchr (tab + 1, '\t');
} while (tab);
text = copy;
}
g_value_set_string (value, text);
g_free (copy);
}
}
/**
* stf_preview_render
* @renderdata : a renderdata struct
*
* This will render a preview.
*
* returns : nothing
**/
void
stf_preview_render (RenderData_t *renderdata)
{
GPtrArray *lines;
int colcount = 0;
unsigned int i;
g_return_if_fail (renderdata != NULL);
/* Empty the table. */
gnumeric_lazy_list_set_rows (renderdata->ll, 0);
g_return_if_fail (renderdata->lines != NULL);
lines = renderdata->lines;
for (i = 0; i < lines->len; i++) {
GPtrArray *line = g_ptr_array_index (lines, i);
colcount = MAX (colcount, (int)line->len);
}
/*
* Don't display more then the maximum amount of columns
* in a sheet
*/
if (colcount > SHEET_MAX_COLS)
colcount = SHEET_MAX_COLS;
else if (colcount <= 0)
colcount = 1;
/* Fix number of columns. */
while (renderdata->colcount > colcount)
gtk_tree_view_remove_column
(renderdata->tree_view,
gtk_tree_view_get_column (renderdata->tree_view,
--(renderdata->colcount)));
while (renderdata->colcount < colcount) {
char *text = g_strdup_printf (_(COLUMN_CAPTION),
renderdata->colcount + 1);
GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
GtkTreeViewColumn *column =
gtk_tree_view_column_new_with_attributes
(text, cell,
"text", renderdata->colcount,
NULL);
gtk_tree_view_append_column (renderdata->tree_view, column);
g_free (text);
renderdata->colcount++;
}
/* Fill the table. */
gnumeric_lazy_list_set_rows (renderdata->ll,
MIN (lines->len, LINE_DISPLAY_LIMIT));
}
/******************************************************************************************************************
* STRUCTURE MANIPULATION FUNCTIONS
******************************************************************************************************************/
......@@ -229,14 +178,61 @@ stf_preview_free (RenderData_t *renderdata)
void
stf_preview_set_lines (RenderData_t *renderdata, GPtrArray *lines)
{
unsigned int i;
int colcount = 0;
g_return_if_fail (renderdata != NULL);
if (renderdata->lines == lines)
return;
/* Empty the table. */
gnumeric_lazy_list_set_rows (renderdata->ll, 0);
if (renderdata->lines)
stf_parse_general_free (renderdata->lines);
renderdata->lines = lines;
if (lines == NULL)
return;
for (i = 0; i < lines->len; i++) {
GPtrArray *line = g_ptr_array_index (lines, i);
colcount = MAX (colcount, (int)line->len);
}
/*
* Don't display more then the maximum amount of columns
* in a sheet
*/
if (colcount > SHEET_MAX_COLS)
colcount = SHEET_MAX_COLS;
else if (colcount <= 0)
colcount = 1;
/* Fix number of columns. */
while (renderdata->colcount > colcount)
gtk_tree_view_remove_column
(renderdata->tree_view,
gtk_tree_view_get_column (renderdata->tree_view,
--(renderdata->colcount)));
while (renderdata->colcount < colcount) {
char *text = g_strdup_printf (_(COLUMN_CAPTION),
renderdata->colcount + 1);
GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
GtkTreeViewColumn *column =
gtk_tree_view_column_new_with_attributes
(text, cell,
"text", renderdata->colcount,
NULL);
gtk_tree_view_append_column (renderdata->tree_view, column);
g_free (text);
renderdata->colcount++;
}
/* Fill the table. */
gnumeric_lazy_list_set_rows (renderdata->ll,
MIN (lines->len, LINE_DISPLAY_LIMIT));
}
/**
......
......@@ -43,9 +43,6 @@ typedef struct {
GnmDateConventions const *date_conv;
} RenderData_t;
/* This will actually draw the stuff on screen */
void stf_preview_render (RenderData_t *renderdata);
/* These are for creation/deletion */
RenderData_t* stf_preview_new (GtkWidget *data_container,
GnmDateConventions const *date_conv);
......
......@@ -136,30 +136,19 @@ stf_dialog_druid_page_next (G_GNUC_UNUSED GnomeDruidPage *page,
stf_preview_set_lines (data->main.renderdata, NULL);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->main.main_separated))) {
newpos = DPG_CSV;
data->parsetype = PARSE_TYPE_CSV;
} else {
newpos = DPG_FIXED;
data->parsetype = PARSE_TYPE_FIXED;
}
break;
case DPG_CSV:
stf_preview_set_lines (data->csv.renderdata, NULL);
newpos = DPG_FORMAT;
data->format.parseoptions = data->csv.parseoptions;
break;
case DPG_FIXED:
stf_preview_set_lines (data->fixed.renderdata, NULL);
newpos = DPG_FORMAT;
/*
* Set trim type here, we never want trimming on
* the fixed width page of the druid because of
* columns getting mangled
*/
stf_parse_options_set_trim_spaces (data->fixed.parseoptions, data->trim);
data->format.parseoptions = data->fixed.parseoptions;
break;
default:
......@@ -205,7 +194,7 @@ stf_dialog_druid_page_previous (G_GNUC_UNUSED GnomeDruidPage *page,
switch (data->position) {
case DPG_FORMAT:
stf_preview_set_lines (data->format.renderdata, NULL);
if (data->parsetype == PARSE_TYPE_CSV)
if (data->parseoptions->parsetype == PARSE_TYPE_CSV)
newpos = DPG_CSV;
else
newpos = DPG_FIXED;
......@@ -474,6 +463,7 @@ stf_dialog (WorkbookControlGUI *wbcg,
pagedata.fixed_page = GNOME_DRUID_PAGE (glade_xml_get_widget (gui, "fixed_page"));
pagedata.format_page = GNOME_DRUID_PAGE (glade_xml_get_widget (gui, "format_page"));
pagedata.position = DPG_MAIN;
pagedata.parseoptions = stf_parse_options_new ();
stf_dialog_main_page_init (gui, &pagedata);
stf_dialog_csv_page_init (gui, &pagedata);
......@@ -509,23 +499,13 @@ stf_dialog (WorkbookControlGUI *wbcg,
dialogresult->lines = pagedata.importlines;
dialogresult->rowcount = pagedata.format.renderdata->lines->len;
if (pagedata.parsetype == PARSE_TYPE_CSV) {
dialogresult->parseoptions = pagedata.csv.parseoptions;
pagedata.csv.parseoptions = NULL;
} else {
dialogresult->parseoptions = pagedata.fixed.parseoptions;
pagedata.fixed.parseoptions = NULL;
}
dialogresult->parseoptions = pagedata.parseoptions;
pagedata.parseoptions = NULL;
dialogresult->formats = pagedata.format.formats;
pagedata.format.formats = NULL;
}
/* Quick Note, if the parseoptions members of either the csv page or
* fixed page have been set to NULL when calling the cleanup function
* they will not attempt to free it, this will be done in stf_dialog_result_free
* instead
*/
stf_dialog_main_page_cleanup (&pagedata);
stf_dialog_csv_page_cleanup (&pagedata);
stf_dialog_fixed_page_cleanup (&pagedata);
......@@ -536,6 +516,8 @@ stf_dialog (WorkbookControlGUI *wbcg,
g_object_unref (G_OBJECT (gui));
g_free (pagedata.encoding);
g_free (pagedata.utf8_data);
if (pagedata.parseoptions)
stf_parse_options_free (pagedata.parseoptions);
return dialogresult;
}
......
......@@ -23,7 +23,6 @@ typedef struct {
/* Page members that are created at run-time */
CharmapSelector *charmap_selector;
RenderData_t *renderdata;
StfParseOptions_t *parseoptions;
} MainInfo_t;
/* for the csv_page */
......@@ -38,7 +37,6 @@ typedef struct {
/* Page members that are created at run-time */
RenderData_t *renderdata;
StfParseOptions_t *parseoptions;
int scrollpos;
} CsvInfo_t;
......@@ -51,7 +49,6 @@ typedef struct {
/* Page members that are created at run-time */
RenderData_t *renderdata;
StfParseOptions_t *parseoptions;
int index;
gboolean manual;
gboolean mousedown;
......@@ -69,7 +66,6 @@ typedef struct {
/* Page members that are created at run-time */
RenderData_t *renderdata;
StfParseOptions_t *parseoptions; /* Note : refers to either FixedInfo_t or CsvInfo_t parseoptions */
GPtrArray *formats; /* Contains StyleFormat* */
int index;
gboolean manual_change;
......@@ -111,7 +107,7 @@ typedef struct {
FormatInfo_t format;
gboolean canceled; /* Indicates whether the user pressed cancel button */
StfParseType_t parsetype; /* Indicates the parse type the user choose */
StfParseOptions_t *parseoptions;
StfTrimType_t trim; /* Do we want to trim and if so -> how? */
} DruidPageData_t;
......
......@@ -91,20 +91,33 @@ comp_term (gchar const *s, gchar const *term)
return TRUE;
}
static inline int
static int
compare_terminator (char const *s, StfParseOptions_t *parseoptions)
{
GSList *term;
for (term = parseoptions->terminator; term; term = term->next) {
int len = strlen (term->data);
if (strncmp (term->data, s, len) == 0)
return len;
}
return 0;
}
const guchar *us = (const guchar *)s;
GSList *l;
if (*us > parseoptions->compiled_terminator.max ||
*us < parseoptions->compiled_terminator.min)
return 0;
for (l = parseoptions->terminator; l; l = l->next) {
const char *term = l->data;
<