Commit 10adef43 authored by Andreas Voegele's avatar Andreas Voegele Committed by Arturo Espinosa

Use the locale to figure out the correct separator

1999-07-19  Andreas Voegele <andreas.voegele@gmx.de>

	* src/parser.y (gnumeric_unsafe_expr_parser): Use the locale to
	figure out the correct separator

	* src/file.c (workbook_read): According to the GNU libc
	documentaiton retrieving the current locale should be done by
	passing NULL to setlocale as the locale argument.
parent e09fa640
1999-07-19 Andreas Voegele <andreas.voegele@gmx.de>
* src/parser.y (gnumeric_unsafe_expr_parser): Use the locale to
figure out the correct separator
* src/file.c (workbook_read): According to the GNU libc
documentaiton retrieving the current locale should be done by
passing NULL to setlocale as the locale argument.
1999-07-17 Michael Meeks <michael@edenproject.org>
* src/workbook.c (workbook_setup_edit_area): Enabled function
......
1999-07-19 Andreas Voegele <andreas.voegele@gmx.de>
* src/parser.y (gnumeric_unsafe_expr_parser): Use the locale to
figure out the correct separator
* src/file.c (workbook_read): According to the GNU libc
documentaiton retrieving the current locale should be done by
passing NULL to setlocale as the locale argument.
1999-07-17 Michael Meeks <michael@edenproject.org>
* src/workbook.c (workbook_setup_edit_area): Enabled function
......
......@@ -500,6 +500,15 @@ value_cellrange_get_as_string (const Value *value, gboolean use_relative_syntax)
char *
value_get_as_string (const Value *value)
{
struct lconv *locinfo;
separator = ",";
locinfo = localeconv ();
if (locinfo->decimal_point &&
locinfo->decimal_point [0] == ',' &&
locinfo->decimal_point [1] == 0)
separator = ";";
switch (value->type){
case VALUE_STRING:
return g_strdup (value->v.str->str);
......@@ -524,7 +533,7 @@ value_get_as_string (const Value *value)
v->type == VALUE_INTEGER,
"Duff Array contents");
if (lpx)
g_string_sprintfa (str, ",");
g_string_sprintfa (str, separator);
if (v->type == VALUE_STRING)
g_string_sprintfa (str, "\"%s\"",
v->v.str->str);
......@@ -532,7 +541,7 @@ value_get_as_string (const Value *value)
g_string_sprintfa (str, "%g",
value_get_as_float (v));
}
if (lpy<value->v.array.y-1)
if (lpy < value->v.array.y-1)
g_string_sprintfa (str, ";");
}
g_string_sprintfa (str, "}");
......
......@@ -147,7 +147,8 @@ workbook_read (const char *filename)
g_return_val_if_fail (filename != NULL, NULL);
/* Files are expected to be in standard C format. */
oldlocale = g_strdup (setlocale (LC_NUMERIC, "C"));
oldlocale = g_strdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, "C");
for (l = gnumeric_file_openers; l; l = l->next){
const FileOpener *fo = l->data;
......@@ -230,7 +231,8 @@ workbook_import (Workbook *parent, const char *filename)
int sel_row = GPOINTER_TO_INT (clist->selection->data);
/* Files are expected to be in standard C format. */
oldlocale = g_strdup (setlocale (LC_NUMERIC, "C"));
oldlocale = g_strdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, NULL);
fo = gtk_clist_get_row_data (clist, sel_row);
w = fo->open (filename);
......@@ -422,8 +424,9 @@ workbook_save_as (Workbook *wb)
workbook_set_filename (wb, name);
/* Files are expected to be in standard C format. */
oldlocale = g_strdup (setlocale (LC_NUMERIC, "C"));
oldlocale = g_strdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, "C");
current_saver->save (wb, wb->filename);
setlocale (LC_NUMERIC, oldlocale);
......
......@@ -69,7 +69,8 @@ static const char **parser_desired_format;
/* Locale info. */
static char parser_decimal_point;
static char parser_separator;
static ExprTree **parser_result;
#define p_new(type) ((type *) alloc_buffer ((unsigned) sizeof (type)))
......@@ -111,6 +112,7 @@ build_array_formula (ExprTree * func,
%type <list> arg_list
%token <tree> NUMBER STRING FUNCALL CONSTANT CELLREF GTE LTE NE
%token <sheetref> SHEETREF
%token SEPARATOR
%type <tree> cellref
%left '&'
......@@ -124,7 +126,7 @@ build_array_formula (ExprTree * func,
%%
line: exp { *parser_result = $1; }
| '{' exp '}' '(' NUMBER ',' NUMBER ')' '[' NUMBER ']' '[' NUMBER ']' {
| '{' exp '}' '(' NUMBER SEPARATOR NUMBER ')' '[' NUMBER ']' '[' NUMBER ']' {
*parser_result = build_array_formula ($2, $5, $7, $10, $13) ;
}
......@@ -194,7 +196,7 @@ arg_list: exp {
$$ = g_list_prepend (NULL, $1);
alloc_glist ($$);
}
| exp ',' arg_list {
| exp SEPARATOR arg_list {
forget_glist ($3);
$$ = g_list_prepend ($3, $1);
alloc_glist ($$);
......@@ -417,9 +419,12 @@ int yylex (void)
parser_expr++;
c = *parser_expr++;
if (c == '(' || c == ',' || c == ')')
if (c == '(' || c == ')')
return c;
if (c == parser_separator)
return SEPARATOR;
/* Translate locale's decimal marker into a dot. */
if (c == parser_decimal_point)
c = '.';
......@@ -437,7 +442,7 @@ int yylex (void)
digits = 1;
while (isdigit ((unsigned char)*tmp) ||
(!is_float && *tmp=='.' && ++is_float)) {
(!is_float && *tmp == parser_decimal_point && ++is_float)){
tmp++;
digits++;
}
......@@ -716,6 +721,11 @@ gnumeric_unsafe_expr_parser (const char *expr, Sheet *sheet, guint eval_col, gui
else
parser_decimal_point = '.';
if (parser_decimal_point == ',')
parser_separator = ';';
else
parser_separator = ',';
yyparse ();
if (parser_error == PARSE_OK)
......
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