From f06af57f7e23488c3018c330ccf2ca83a0d255d5 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 29 Sep 2008 15:42:21 +0000 Subject: [PATCH] 2008-09-29 17:41 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbset.h * harbour/source/vm/set.c + divided __SETCENTURY() PRG function into two functions: __SETCENTURY() and public C function hb_setSetCentury() to manipulate century setting from C code. Modyfication by Francesco Saverio Giudice --- harbour/ChangeLog | 8 +++++ harbour/include/hbset.h | 1 + harbour/source/vm/set.c | 73 +++++++++++++++++++---------------------- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 449d0f6977..e5ea4bdb2f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,14 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-09-29 17:41 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbset.h + * harbour/source/vm/set.c + + divided __SETCENTURY() PRG function into two functions: + __SETCENTURY() and public C function hb_setSetCentury() + to manipulate century setting from C code. + Modyfication by Francesco Saverio Giudice + 2008-09-29 15:59 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * ChangeLog * mpkg_tgz.sh diff --git a/harbour/include/hbset.h b/harbour/include/hbset.h index a581270ad0..c937a82dae 100644 --- a/harbour/include/hbset.h +++ b/harbour/include/hbset.h @@ -254,6 +254,7 @@ extern HB_EXPORT HB_PATHNAMES * hb_setGetFirstSetPath( void ); extern HB_EXPORT HB_FHANDLE hb_setGetAltHan( void ); extern HB_EXPORT BOOL hb_setGetCentury( void ); +extern HB_EXPORT BOOL hb_setSetCentury( BOOL ); extern HB_EXPORT HB_FHANDLE hb_setGetExtraHan( void ); extern HB_EXPORT HB_FHANDLE hb_setGetPrintHan( void ); extern HB_EXPORT BOOL hb_setGetAlternate( void ); diff --git a/harbour/source/vm/set.c b/harbour/source/vm/set.c index c8055733eb..aec289467d 100644 --- a/harbour/source/vm/set.c +++ b/harbour/source/vm/set.c @@ -95,6 +95,10 @@ static char set_char( PHB_ITEM pItem, char oldChar ) return newChar; } +/* + * Change the setting if the parameter is a logical value, or is + * either "ON" or "OFF" (regardless of case) + */ static BOOL set_logical( PHB_ITEM pItem, BOOL bDefault ) { BOOL bLogical = bDefault; @@ -200,7 +204,7 @@ static HB_FHANDLE open_handle( PHB_SET_STRUCT pSet, const char * file_name, BOOL if( pFilename->szName ) { int iLen = ( int ) strlen( pFilename->szName ); - if( ( iLen == 3 && + if( ( iLen == 3 && ( hb_stricmp( pFilename->szName, "PRN" ) == 0 || hb_stricmp( pFilename->szName, "CON" ) == 0 ) ) || ( iLen == 4 && @@ -295,44 +299,17 @@ static HB_FHANDLE open_handle( PHB_SET_STRUCT pSet, const char * file_name, BOOL return handle; } -HB_FUNC( SETCANCEL ) -{ - hb_retl( hb_setGetCancel() ); - hb_setSetItem( HB_SET_CANCEL, hb_param( 1, HB_IT_LOGICAL ) ); -} - -HB_FUNC( __SETCENTURY ) +HB_EXPORT BOOL hb_setSetCentury( BOOL new_century_setting ) { PHB_SET_STRUCT pSet = hb_stackSetStruct(); BOOL old_century_setting = pSet->hb_set_century; + pSet->hb_set_century = new_century_setting; /* - * Change the setting if the parameter is a logical value, or is - * either "ON" or "OFF" (regardless of case) - */ - if( ISLOG( 1 ) ) - pSet->hb_set_century = hb_parl( 1 ); - else if( ISCHAR( 1 ) ) - { - char * szString = hb_parc( 1 ); - ULONG ulLen = hb_parclen( 1 ); - - if( ulLen >= 2 - && toupper( ( UCHAR ) szString[ 0 ] ) == 'O' - && toupper( ( UCHAR ) szString[ 1 ] ) == 'N' ) - pSet->hb_set_century = TRUE; - else if( ulLen >= 3 - && toupper( ( UCHAR ) szString[ 0 ] ) == 'O' - && toupper( ( UCHAR ) szString[ 1 ] ) == 'F' - && toupper( ( UCHAR ) szString[ 2 ] ) == 'F' ) - pSet->hb_set_century = FALSE; - } - - /* - * Finally, if the setting changed, adjust the current date format to use + * if the setting changed, adjust the current date format to use * the correct number of year digits. */ - if( old_century_setting != pSet->hb_set_century ) + if( old_century_setting != new_century_setting ) { int count, digit, size, y_size, y_start, y_stop; char * szDateFormat, * szNewFormat; @@ -364,7 +341,7 @@ HB_FUNC( __SETCENTURY ) y_size = y_stop - y_start; /* Calculate size of new format */ size -= y_size; - if( pSet->hb_set_century ) + if( new_century_setting ) size += 4; else size += 2; @@ -376,7 +353,7 @@ HB_FUNC( __SETCENTURY ) if( y_start > 0 ) memcpy( szNewFormat, szDateFormat, y_start ); szNewFormat[ y_start ] = '\0'; hb_strncat( szNewFormat, "YY", size ); - if( pSet->hb_set_century ) + if( new_century_setting ) hb_strncat( szNewFormat, "YY", size ); format_len = strlen( szDateFormat ); if( y_stop < format_len ) @@ -391,9 +368,27 @@ HB_FUNC( __SETCENTURY ) } /* Return the previous setting */ + return old_century_setting; +} + +HB_FUNC( __SETCENTURY ) +{ + BOOL old_century_setting = hb_setGetCentury(); + PHB_ITEM pNewVal = hb_param( 1, HB_IT_ANY ); + + if( pNewVal ) + hb_setSetCentury( set_logical( pNewVal, old_century_setting ) ); + hb_retl( old_century_setting ); } +HB_FUNC( SETCANCEL ) +{ + hb_retl( hb_setGetCancel() ); + /* SETCANCEL() accepts only logical parameters */ + hb_setSetItem( HB_SET_CANCEL, hb_param( 1, HB_IT_LOGICAL ) ); +} + HB_FUNC( SET ) { PHB_SET_STRUCT pSet = hb_stackSetStruct(); @@ -958,7 +953,7 @@ HB_FUNC( SET ) /* Return NIL if called with invalid SET specifier */ break; -#if 0 +#if 0 /* * intentionally removed default: clause to enable C compiler warning * when not all HB_SET_* cases are implemented. [druzus] @@ -1516,7 +1511,7 @@ HB_EXPORT BOOL hb_setSetItem( HB_set_enum set_specifier, PHB_ITEM pItem ) case HB_SET_HBOUTLOGINFO: case HB_SET_INVALID_: break; -#if 0 +#if 0 /* * intentionally removed default: clause to enable C compiler warning * when not all HB_SET_* cases are implemented. [druzus] @@ -1634,7 +1629,7 @@ HB_EXPORT BOOL hb_setGetL( HB_set_enum set_specifier ) case HB_SET_HBOUTLOGINFO: case HB_SET_INVALID_: break; -#if 0 +#if 0 /* * intentionally removed default: clause to enable C compiler warning * when not all HB_SET_* cases are implemented. [druzus] @@ -1733,7 +1728,7 @@ HB_EXPORT char * hb_setGetCPtr( HB_set_enum set_specifier ) case HB_SET_TRIMFILENAME: case HB_SET_INVALID_: break; -#if 0 +#if 0 /* * intentionally removed default: clause to enable C compiler warning * when not all HB_SET_* cases are implemented. [druzus] @@ -1832,7 +1827,7 @@ HB_EXPORT int hb_setGetNI( HB_set_enum set_specifier ) case HB_SET_HBOUTLOGINFO: case HB_SET_INVALID_: break; -#if 0 +#if 0 /* * intentionally removed default: clause to enable C compiler warning * when not all HB_SET_* cases are implemented. [druzus]