From 28c1dd61498fe65e70543b58fe102b61af15a205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnim=20L=C3=A4uger?= Date: Mon, 15 Sep 2008 21:49:25 +0000 Subject: [PATCH] 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 --- jtag/ChangeLog | 5 +++++ jtag/src/svf/svf.h | 1 + jtag/src/svf/svf_flex.l | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 662063a0..808d5935 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,8 @@ +2008-09-15 Arnim Laeuger + + * 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 Version 0.9 released. diff --git a/jtag/src/svf/svf.h b/jtag/src/svf/svf.h index 8d8970eb..28aab582 100644 --- a/jtag/src/svf/svf.h +++ b/jtag/src/svf/svf.h @@ -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; diff --git a/jtag/src/svf/svf_flex.l b/jtag/src/svf/svf_flex.l index 35c08477..4b9a90c6 100644 --- a/jtag/src/svf/svf_flex.l +++ b/jtag/src/svf/svf_flex.l @@ -35,6 +35,11 @@ #include #include + +#ifdef ENABLE_NLS +#include +#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;