SVF player fix for

[ 2112823 ] Conversion with strtod and similar influenced by locale


git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1363 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Arnim Läuger 16 years ago
parent d6923f9ddc
commit 28c1dd6149

@ -1,3 +1,8 @@
2008-09-15 Arnim Laeuger <arniml@users.sourceforge.net>
* src/svf/svf.h, src/svf/svf_flex.l: SVF player fix for
[ 2112823 ] Conversion with strtod and similar influenced by locale
2008-09-14 Kolja Waschk <kawk>
Version 0.9 released.

@ -105,6 +105,7 @@ typedef struct parser_priv parser_priv_t;
struct scanner_extra {
int num_lines;
int print_progress;
char decimal_point;
};
typedef struct scanner_extra scanner_extra_t;

@ -35,6 +35,11 @@
#include <ctype.h>
#include <sysdep.h>
#ifdef ENABLE_NLS
#include <locale.h>
#endif
#include "svf.h"
#include "svf_bison.h"
@ -89,8 +94,26 @@ COMMENT (!.*)|("//".*)[^\n]
{DIGIT}+(\.{DIGIT}+)?([eE][-+]?{DIGIT}+)? {
/* token is a real number */
yylval->dvalue = strtod(yytext, (char **) NULL);
fix_yylloc(yylloc, yytext);
char *real_string = strdup(yytext);
/* Note: We need to compensate the current locale's representation
of the decimal point since strtod() functionality depends
on the locale settings. */
if (real_string) {
char *point_pos = index(real_string, '.');
YY_EXTRA_TYPE extra = yyget_extra(yyscanner);
if (point_pos)
/* convert decimal point into current locale's representation */
*point_pos = extra->decimal_point;
yylval->dvalue = strtod(real_string, (char **) NULL);
fix_yylloc(yylloc, yytext);
free(real_string);
} else
yylval->dvalue = 0.0;
return(NUMBER);
} /* end of real number */
@ -338,6 +361,15 @@ void *svf_flex_init(FILE *f, int num_lines, int print_progress)
extra->num_lines = num_lines;
extra->print_progress = print_progress;
#ifdef ENABLE_NLS
{
struct lconv *lc = localeconv();
extra->decimal_point = lc->decimal_point[0];
}
#else
extra->decimal_point = '.';
#endif
yyset_extra(extra, scanner);
return scanner;

Loading…
Cancel
Save