From bbfa409c72646f602ddf5cf616e9608673489214 Mon Sep 17 00:00:00 2001 From: Antonio Linares Date: Fri, 30 May 2003 07:32:08 +0000 Subject: [PATCH] hb_strVal() used instead of atof() --- harbour/source/compiler/harbour.l | 57 +++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 1393f10ab9..b2e8f2bace 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -775,7 +775,7 @@ Separator {SpaceTab} hb_comp_iState = IDENTIFIER; return IDENTIFIER; } - + if( hb_comp_iLineINLINE ) { hb_compGenError( hb_comp_szErrors, 'F', HB_COMP_ERR_TOOMANY_INLINE, "on the same line", NULL ); @@ -1593,11 +1593,64 @@ int yy_lex_input( char *buffer, int iBufferSize ) return hb_pp_Internal( hb_comp_bPPO ? hb_comp_yyppo : NULL, buffer ); } +static double hb_strVal( const char * szText, ULONG ulLen ) +{ + long double ldValue = 0.0; + ULONG ulPos; + ULONG ulDecPos = 0; + BOOL bNegative = FALSE; + long double ldScale = 0.1L; + + /* Look for sign */ + + for( ulPos = 0; ulPos < ulLen; ulPos++ ) + { + if( szText[ ulPos ] == '-' ) + { + bNegative = TRUE; + ulPos++; + break; + } + else if( szText[ ulPos ] == '+' ) + { + ulPos++; + break; + } + else if( ! HB_ISSPACE( szText[ ulPos ] ) ) + break; + } + + /* Build the number */ + + for(; ulPos < ulLen; ulPos++ ) + { + if( szText[ ulPos ] == '.' && ulDecPos == 0 ) + { + ulDecPos++; + ldScale = 0.1L; + } + else if( szText[ ulPos ] >= '0' && szText[ ulPos ] <= '9' ) + { + if( ulDecPos ) + { + ldValue += ldScale * ( long double )( szText[ ulPos ] - '0' ); + ldScale *= 0.1L; + } + else + ldValue = ( ldValue * 10.0L ) + ( long double )( szText[ ulPos ] - '0' ); + } + else + break; + } + + return ( double )( bNegative && ldValue != 0.0L ? -ldValue : ldValue ); +} + static int yy_ConvertNumber( char * szBuffer ) { char * ptr; - yylval.valDouble.dNumber = atof( szBuffer ); + yylval.valDouble.dNumber = hb_strVal( szBuffer, strlen( szBuffer ) ); /* atof( szBuffer ); */ ptr = strchr( szBuffer, '.' ); if( ptr ) {