Commit 8aad5f3a authored by Almer S. Tigelaar's avatar Almer S. Tigelaar Committed by Almer S. Tigelaar

return invalid character or NULL if the data is valid.

2000-09-23  Almer S. Tigelaar  <almer1@dds.nl>

	* src/stf-parse.c, src/stf-parse.h:
	(stf_parse_is_valid_data): return invalid character
	or NULL if the data is valid.

	* src/clipboard.c:
	(stf_read_workbook): Adjust to cope with the new
	stf_parse_is_valid_data.

	* src/stf.c:
	(x_selection_to_cell_region): Idem.
parent ce350f49
2000-09-23 Almer S. Tigelaar <almer1@dds.nl>
* src/stf-parse.c, src/stf-parse.h:
(stf_parse_is_valid_data): return invalid character
or NULL if the data is valid.
* src/clipboard.c:
(stf_read_workbook): Adjust to cope with the new
stf_parse_is_valid_data.
* src/stf.c:
(x_selection_to_cell_region): Idem.
2000-09-23 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use stock icons.
......
2000-09-23 Almer S. Tigelaar <almer1@dds.nl>
* src/stf-parse.c, src/stf-parse.h:
(stf_parse_is_valid_data): return invalid character
or NULL if the data is valid.
* src/clipboard.c:
(stf_read_workbook): Adjust to cope with the new
stf_parse_is_valid_data.
* src/stf.c:
(x_selection_to_cell_region): Idem.
2000-09-23 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use stock icons.
......
2000-09-23 Almer S. Tigelaar <almer1@dds.nl>
* src/stf-parse.c, src/stf-parse.h:
(stf_parse_is_valid_data): return invalid character
or NULL if the data is valid.
* src/clipboard.c:
(stf_read_workbook): Adjust to cope with the new
stf_parse_is_valid_data.
* src/stf.c:
(x_selection_to_cell_region): Idem.
2000-09-23 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use stock icons.
......
2000-09-23 Almer S. Tigelaar <almer1@dds.nl>
* src/stf-parse.c, src/stf-parse.h:
(stf_parse_is_valid_data): return invalid character
or NULL if the data is valid.
* src/clipboard.c:
(stf_read_workbook): Adjust to cope with the new
stf_parse_is_valid_data.
* src/stf.c:
(x_selection_to_cell_region): Idem.
2000-09-23 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use stock icons.
......
2000-09-23 Almer S. Tigelaar <almer1@dds.nl>
* src/stf-parse.c, src/stf-parse.h:
(stf_parse_is_valid_data): return invalid character
or NULL if the data is valid.
* src/clipboard.c:
(stf_read_workbook): Adjust to cope with the new
stf_parse_is_valid_data.
* src/stf.c:
(x_selection_to_cell_region): Idem.
2000-09-23 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use stock icons.
......
2000-09-23 Almer S. Tigelaar <almer1@dds.nl>
* src/stf-parse.c, src/stf-parse.h:
(stf_parse_is_valid_data): return invalid character
or NULL if the data is valid.
* src/clipboard.c:
(stf_read_workbook): Adjust to cope with the new
stf_parse_is_valid_data.
* src/stf.c:
(x_selection_to_cell_region): Idem.
2000-09-23 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use stock icons.
......
2000-09-23 Almer S. Tigelaar <almer1@dds.nl>
* src/stf-parse.c, src/stf-parse.h:
(stf_parse_is_valid_data): return invalid character
or NULL if the data is valid.
* src/clipboard.c:
(stf_read_workbook): Adjust to cope with the new
stf_parse_is_valid_data.
* src/stf.c:
(x_selection_to_cell_region): Idem.
2000-09-23 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use stock icons.
......
......@@ -586,6 +586,7 @@ x_selection_to_cell_region (CommandContext *context, const char *src,
CellRegion *cr = NULL;
CellRegion *crerr;
char *data;
char *c;
data = g_new (char, len + 1);
memcpy (data, src, len);
......@@ -603,9 +604,16 @@ x_selection_to_cell_region (CommandContext *context, const char *src,
return crerr;
}
if (!stf_parse_is_valid_data (data)) {
if ((c = stf_parse_is_valid_data (data)) != NULL) {
char *message;
message = g_strdup_printf (_("The data on the clipboard does not seem to be valid text.\nThe character '%s' (ASCII decimal %d) was encountered"),
*c, (int) *c);
g_warning (message);
g_free (message);
g_free (data);
g_warning (_("This data on the clipboard does not seem to be valid text"));
return crerr;
}
......
......@@ -1381,15 +1381,13 @@ stf_parse_convert_to_unix (char *data)
* returns weather the input data is valid to import.
* (meaning it checks weather it is text only)
*
* returns : true if valid, false otherwise
* returns : NULL if valid, a pointer to the invalid character otherwise
**/
gboolean
stf_parse_is_valid_data (const char *data)
char *
stf_parse_is_valid_data (char *data)
{
gboolean valid;
const char *iterator = data;
char *iterator = data;
valid = TRUE;
while (*iterator) {
if (!isprint ((unsigned char)*iterator) &&
......@@ -1398,13 +1396,13 @@ stf_parse_is_valid_data (const char *data)
*iterator != '\t' &&
*iterator != '\f') {
valid = FALSE;
break;
return iterator;
}
iterator++;
}
return valid;
return NULL;
}
/**
......
......@@ -121,7 +121,7 @@ int stf_parse_get_longest_row_width (StfParseO
int stf_parse_get_colwidth (StfParseOptions_t *parseoptions, const char *data, int index);
gboolean stf_parse_convert_to_unix (char *data);
gboolean stf_parse_is_valid_data (const char *data);
char *stf_parse_is_valid_data (char *data);
void stf_parse_options_fixed_autodiscover (StfParseOptions_t *parseoptions, int data_lines, const char *data);
......
......@@ -113,6 +113,7 @@ stf_read_workbook (CommandContext *context, Workbook *book, char const *filename
DialogStfResult_t *dialogresult;
char *name;
char *data;
char *c;
Sheet *sheet;
data = stf_open_and_read (filename);
......@@ -133,14 +134,19 @@ stf_read_workbook (CommandContext *context, Workbook *book, char const *filename
return -1;
}
if (!stf_parse_is_valid_data (data)) {
if ((c = stf_parse_is_valid_data (data)) != NULL) {
char *message;
/*
* Note this buffer was allocated with malloc, not g_malloc
*/
message = g_strdup_printf (_("This file does not seem to be a valid text file.\nThe character '%c' (ASCII decimal %d) was encountered"),
*c, (int) *c);
gnumeric_error_read (context, message);
g_free (message);
free (data);
gnumeric_error_read (context,
_("This file does not seem to be a valid text file"));
return -1;
}
......
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