Skip to content

Commit

Permalink
- Added: Support for "&..." octal numbers in VAL/VALINT/... (like "&O…
Browse files Browse the repository at this point in the history
…..." octal numbers, but without the "O")

  No compile-time support for &... in number literals though, at least for the moment.

- Some work on test case, including adding new "&..." cases.

r5252
  • Loading branch information
countingpine committed Jun 11, 2009
1 parent d3de993 commit 9b388d8
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 25 deletions.
1 change: 1 addition & 0 deletions FreeBASIC/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Version 0.21.0 Beta:
- PRINT USING now supports "&" for intelligent number formatting (counting_pine)
- PRINT USING: normal expressions allowed before USING (counting_pine)
- PRINT USING: support for SPC/TAB (counting_pine)
- VAL/VALINT/... now support "&..." for octal numbers, e.g. "&123" (counting_pine)

[fixed]
- WIDTH was crashing when optional parameter was not specified (DrV)
Expand Down
9 changes: 8 additions & 1 deletion FreeBASIC/src/rtlib/libfb_str_convfrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ FBCALL double fb_hStr2Double( char *src, int len )
char *p, *q, c;
int radix;
int i;
int skip;
double ret;

/* skip white spc */
Expand All @@ -56,6 +57,7 @@ FBCALL double fb_hStr2Double( char *src, int len )

else if( (len >= 2) && (p[0] == '&') )
{
skip = 2;
radix = 0;
switch( p[1] )
{
Expand All @@ -71,10 +73,15 @@ FBCALL double fb_hStr2Double( char *src, int len )
case 'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
skip = 1;
break;
}

if( radix != 0 )
return (double)fb_hStrRadix2Longint( &p[2], len-2, radix );
return (double)fb_hStrRadix2Longint( &p[skip], len - skip, radix );
}

/* Workaround: strtod() does not allow 'd' as an exponent specifier on
Expand Down
9 changes: 8 additions & 1 deletion FreeBASIC/src/rtlib/libfb_str_convfrom_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FBCALL int fb_hStr2Int( char *src, int len )
{
char *p;
int radix;
int skip;

/* skip white spc */
p = fb_hStrSkipChar( src, len, 32 );
Expand All @@ -55,6 +56,7 @@ FBCALL int fb_hStr2Int( char *src, int len )
else if( (len >= 2) && (p[0] == '&') )
{
radix = 0;
skip = 2;
switch( p[1] )
{
case 'h':
Expand All @@ -69,10 +71,15 @@ FBCALL int fb_hStr2Int( char *src, int len )
case 'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
skip = 1;
break;
}

if( radix != 0 )
return fb_hStrRadix2Int( &p[2], len-2, radix );
return fb_hStrRadix2Int( &p[skip], len - skip, radix );
}

/* atoi() saturates values outside [-2^31, 2^31)
Expand Down
11 changes: 9 additions & 2 deletions FreeBASIC/src/rtlib/libfb_str_convfrom_lng.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FBCALL long long fb_hStr2Longint( char *src, int len )
{
char *p;
int radix;
int skip;

/* skip white spc */
p = fb_hStrSkipChar( src, len, 32 );
Expand All @@ -55,6 +56,7 @@ FBCALL long long fb_hStr2Longint( char *src, int len )
radix = 10;
if( (len >= 2) && (p[0] == '&') )
{
skip = 2;
switch( p[1] )
{
case 'h':
Expand All @@ -69,13 +71,18 @@ FBCALL long long fb_hStr2Longint( char *src, int len )
case 'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
skip = 1;
break;
}

if( radix != 10 )
{
p += 2;
p += skip;
#ifdef TARGET_WIN32
return fb_hStrRadix2Longint( p, len-2, radix );
return fb_hStrRadix2Longint( p, len - skip, radix );
#endif
}
}
Expand Down
9 changes: 8 additions & 1 deletion FreeBASIC/src/rtlib/libfb_str_convfrom_uint.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FBCALL unsigned int fb_hStr2UInt( char *src, int len )
{
char *p;
int radix;
int skip;

/* skip white spc */
p = fb_hStrSkipChar( src, len, 32 );
Expand All @@ -55,6 +56,7 @@ FBCALL unsigned int fb_hStr2UInt( char *src, int len )
radix = 10;
if( (len >= 2) && (p[0] == '&') )
{
skip = 2;
switch( p[1] )
{
case 'h':
Expand All @@ -69,10 +71,15 @@ FBCALL unsigned int fb_hStr2UInt( char *src, int len )
case 'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
skip = 1;
break;
}

if( radix != 10 )
p += 2;
p += skip;
}

return strtoul( p, NULL, radix );
Expand Down
13 changes: 9 additions & 4 deletions FreeBASIC/src/rtlib/libfb_str_convfrom_ulng.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FBCALL unsigned long long fb_hStr2ULongint( char *src, int len )
{
char *p;
int radix;
int skip;

/* skip white spc */
p = fb_hStrSkipChar( src, len, 32 );
Expand All @@ -55,6 +56,7 @@ FBCALL unsigned long long fb_hStr2ULongint( char *src, int len )
radix = 10;
if( (len >= 2) && (p[0] == '&') )
{
skip = 2;
switch( p[1] )
{
case 'h':
Expand All @@ -69,13 +71,18 @@ FBCALL unsigned long long fb_hStr2ULongint( char *src, int len )
case 'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
skip = 1;
break;
}

if( radix != 10 )
{
p += 2;
p += skip;
#ifdef TARGET_WIN32
return fb_hStrRadix2Longint( p, len-2, radix );
return fb_hStrRadix2Longint( p, len - skip, radix );
#endif
}
}
Expand All @@ -101,5 +108,3 @@ FBCALL unsigned long long fb_VALULNG ( FBSTRING *str )

return val;
}


5 changes: 5 additions & 0 deletions FreeBASIC/src/rtlib/libfb_strw_convfrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ FBCALL double fb_WstrToDouble( const FB_WCHAR *src, int len )
case L'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
r--;
break;
}

if( radix != 0 )
Expand Down
5 changes: 5 additions & 0 deletions FreeBASIC/src/rtlib/libfb_strw_convfrom_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ FBCALL int fb_WstrToInt( const FB_WCHAR *src, int len )
case L'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
r--;
break;
}

if( radix != 10 )
Expand Down
6 changes: 5 additions & 1 deletion FreeBASIC/src/rtlib/libfb_strw_convfrom_lng.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ FBCALL long long fb_WstrToLongint( const FB_WCHAR *src, int len )
case L'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
r--;
break;
}

if( radix != 10 )
Expand Down Expand Up @@ -103,4 +108,3 @@ FBCALL long long fb_WstrValLng ( const FB_WCHAR *str )

return val;
}

5 changes: 5 additions & 0 deletions FreeBASIC/src/rtlib/libfb_strw_convfrom_uint.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ FBCALL unsigned int fb_WstrToUInt( const FB_WCHAR *src, int len )
case L'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
r--;
break;
}

if( radix != 10 )
Expand Down
7 changes: 5 additions & 2 deletions FreeBASIC/src/rtlib/libfb_strw_convfrom_ulng.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ FBCALL unsigned long long fb_WstrToULongint( const FB_WCHAR *src, int len )
case L'B':
radix = 2;
break;

default: /* assume octal */
radix = 8;
r--;
break;
}

if( radix != 10 )
Expand Down Expand Up @@ -101,5 +106,3 @@ FBCALL unsigned long long fb_WstrValULng ( const FB_WCHAR *str )

return val;
}


0 comments on commit 9b388d8

Please sign in to comment.