diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 98e43d7349..0c5a027952 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,82 @@ +19990824-18:05 GMT+1 Victor Szel + + * source/rtl/extend.c + include/extend.h + % Variable declarations moved to inner blocks. + ! Parameter number zero is considered a bad case, instead of undefined. + % Optimalization and cleanup. Returns from inner blocks optimed out. + % Array index parameter is only evaluated when actual parameter is an + array, so that it should be faster now. + % The type checkings reordered, so that the first is the most probable one. + Array type is checked last, since this is the most rarely occuring case. + This will speed up things a bit. + ! Casting to (long) fixed in hb_parni() when return an array element. + ! Variable parameters are treated consistently as longs, we are not + Clipper compatible here, but in Harbour an array index can be ULONG, just + as like the string lengths were already ULONGs instead of ints. + ! WORD wArrayIndex changed to ULONG ulArrayIndex. + ! hb_storclen() WORD parameter changed to ULONG. + + Some casts added to hb_parni(), hb_parnd() + ! hb_parl() is returning valid values for INTEGER, LONG and DOUBLE type of + parameters. (Clipper does the same except for DOUBLE) + ! hb_parnl() is returning the date value as a long is the paramater is DATE + type. (just like in Clipper). + ; Reformatted to Harbour standard. + + * source/arrays.c + ! hb_arrayGetDouble() is now returning a value even for the DATE type, + to be consistent with hb_parn*(); + ! hb_arrayGetBool() is now returning a value even for INTEGER, LONG and + DOUBLE types, to be consistent with hb_parl(). + * Reindented using Harbour standard. + % Removed hb_ret() calls, they are not needed, since the default return + value is always NIL. + ! AEVAL() GPF fixed when the second parameter was not a codeblock. + - Removed (unsigned) casts from hb_arrayLen(). + ; Reformatted to Harbour standard. + + * source/rdd/dbcmd.c + ! HB_DBSKIP() it will work even when a DOUBLE type of numeric was passed, + (like Clipper). The low level HB_ITEM access changes to use the + extend API. + + * makefile.b32 + ! Fixes by Luiz Rafael Culik implemented. + + * source/rtl/strings.c + + Added a new runtime error for ALLTRIM(), this error has been + introduced in Clipper 5.3. + (Put between HB_COMPATIBILITY_CLIPPER_53 guard) + % Some PHB_ITEM accesses changed to type checking macros, only where + the PHB_ITEM was only used to check the type. + * Some reformatting (putting spaces between ()[] chars) + ; Reformatted to Harbour standard. + + * source/rtl/math.c + % PHB_ITEM access changed to Extend API calls and/or type checking macros. + + * source/rtl/console.c + % PHB_ITEM access changed to Extend API calls and/or type checking macros. + ! SETPRC() was checking the first parameter type two times, but not at all + the second. + + * source/rtl/descend.c + ! One (double) cast moved to the right place. + + * source/rtl/classes.c + % One hb_ret() removed. + * Some reformatting. + + * tests/working/rtl_test.prg + + CA-Clipper bugs documented somewhat better. + + * source/rtl/dates.c + source/rtl/dir.c + source/rtl/inkey.c + source/vm/hvm.c + * Some minor formatting change: defined( x ) -> defined(x). + + Two (double) casts added to hb_vmPopDouble() + 19990824-17:57 GMT+1 Antonio Linares * source/debug/debugger.prg + Added support for Next Window (K_TAB) and Prev Window (K_SH_TAB) diff --git a/harbour/include/extend.h b/harbour/include/extend.h index 5f495538db..cf8a895c9b 100644 --- a/harbour/include/extend.h +++ b/harbour/include/extend.h @@ -230,7 +230,7 @@ extern void hb_retnd( double dNumber ); /* returns a double */ extern void hb_reta( ULONG ulLen ); /* returns an array with a specific length */ extern void hb_storc( char * szText, int iParam, ... ); /* stores a szString on a variable by reference */ -extern void hb_storclen( char * fixText, WORD wLength, int iParam, ... ); /* stores a fixed length string on a variable by reference */ +extern void hb_storclen( char * fixText, ULONG ulLength, int iParam, ... ); /* stores a fixed length string on a variable by reference */ extern void hb_stords( char * szDate, int iParam, ... ); /* szDate must have yyyymmdd format */ extern void hb_storl( int iLogical, int iParam, ... ); /* stores a logical integer on a variable by reference */ extern void hb_storni( int iValue, int iParam, ... ); /* stores an integer on a variable by reference */ diff --git a/harbour/makefile.b32 b/harbour/makefile.b32 index a156f7523d..94a87c7ba2 100644 --- a/harbour/makefile.b32 +++ b/harbour/makefile.b32 @@ -20,7 +20,7 @@ harbour.lib : achoice.obj adir.obj alert.obj arrays.obj asort.obj \ errorapi.obj errorsys.obj extend.obj fileread.obj filesys.obj fm.obj \ hardcr.obj hb_f.obj hvm.obj initsymb.obj inkey.obj itemapi.obj \ langapi.obj math.obj mathx.obj memvars.obj menuto.obj mtran.obj msges.obj \ - objfunc.obj \ + objfunc.obj readvar.obj xsavescr.obj\ set.obj setcolor.obj setkey.obj strings.obj symbols.obj stringp.obj \ stringsx.obj tbcolumn.obj tbrowse.obj tbrwtext.obj tclass.obj tget.obj tgetlist.obj tone.obj transfrm.obj @@ -82,6 +82,8 @@ tget.obj : tget.c extend.h hbdefs.h tgetlist.obj : tgetlist.c extend.h hbdefs.h tone.obj : tone.c extend.h init.h inkey.h transfrm.obj : transfrm.c extend.h hbdefs.h +readvar.obj : readvar.c extend.h hbdefs.h +xsavescr.obj : xsavescr.c extend.h hbdefs.h achoice.c : achoice.prg harbour.exe adir.c : adir.prg harbour.exe @@ -102,7 +104,8 @@ tbrowse.c : tbrowse.prg harbour.exe tclass.c : tclass.prg harbour.exe tget.c : tget.prg harbour.exe tgetlist.c : tgetlist.prg harbour.exe - +readvar.c : readvar.prg harbour.exe +xsavescr.c : xsavescr.prg harbour.exe .asm.obj: tasm32 $<, $@ tlib .\libs\b32\harbour.lib -+$@,, diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index 7161964660..49a248e0eb 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -1078,19 +1078,13 @@ HARBOUR HB_DBSETDRIVER( void ) HARBOUR HB_DBSKIP( void ) { - PHB_ITEM pItem; LONG lToSkip = 1; if( pCurrArea ) { - pItem = hb_param( 1, IT_NUMERIC ); - if( pItem ) - { - if( pItem->type == IT_INTEGER ) - lToSkip = pItem->item.asInteger.value; - else if( pItem->type == IT_LONG ) - lToSkip = pItem->item.asLong.value; - } + if( ISNUM( 1 ) ) + lToSkip = hb_parnl( 1 ); + SELF_SKIP( ( AREAP ) pCurrArea->pArea, lToSkip ); } else diff --git a/harbour/source/rtl/arrays.c b/harbour/source/rtl/arrays.c index 9074260725..9b03fa35df 100644 --- a/harbour/source/rtl/arrays.c +++ b/harbour/source/rtl/arrays.c @@ -33,96 +33,103 @@ * Internal */ - char * hb_arrayGetDate( PHB_ITEM pArray, ULONG ulIndex, char * szDate ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned )hb_arrayLen( pArray ) ) - { - PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + { + PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; - if( IS_DATE( pItem ) && pItem->item.asDate.value > 0 ) - { - long lDay, lMonth, lYear; + if( IS_DATE( pItem ) && pItem->item.asDate.value > 0 ) + { + long lDay, lMonth, lYear; - hb_dateDecode( pItem->item.asDate.value, &lDay, &lMonth, &lYear ); - hb_dateStrPut( szDate, lDay, lMonth, lYear ); - } - else - { - memset( szDate, ' ', 8 ); - } - } + hb_dateDecode( pItem->item.asDate.value, &lDay, &lMonth, &lYear ); + hb_dateStrPut( szDate, lDay, lMonth, lYear ); + } + else + { + memset( szDate, ' ', 8 ); + } + } else - { - hb_errRT_BASE(EG_BOUND, 1132, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } + { + hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } - return szDate; + return szDate; } - - BOOL hb_arrayGetBool( PHB_ITEM pArray, ULONG ulIndex ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned )hb_arrayLen( pArray ) ) - { - PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; - if( IS_LOGICAL( pItem ) ) + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + { + PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; + + if( IS_LOGICAL( pItem ) ) return pItem->item.asLogical.value; - else - return FALSE; - } + + else if( IS_INTEGER( pItem ) ) + return pItem->item.asInteger.value != 0; + + else if( IS_LONG( pItem ) ) + return pItem->item.asLong.value != 0; + + else if( IS_DOUBLE( pItem ) ) + return pItem->item.asDouble.value != 0.0; + } else - { - hb_errRT_BASE(EG_BOUND, 1132, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - return FALSE; + { + hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + + return FALSE; } double hb_arrayGetDouble( PHB_ITEM pArray, ULONG ulIndex ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned )hb_arrayLen( pArray ) ) - { - PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + { + PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; - if( IS_INTEGER( pItem ) ) + if( IS_INTEGER( pItem ) ) return pItem->item.asInteger.value; - else if( IS_LONG( pItem ) ) + else if( IS_LONG( pItem ) ) return pItem->item.asLong.value; - else if( IS_DOUBLE( pItem ) ) + else if( IS_DOUBLE( pItem ) ) return pItem->item.asDouble.value; - else - return 0; - } + else if( IS_DATE( pItem ) ) + return pItem->item.asDate.value; + } else - { - hb_errRT_BASE(EG_BOUND, 1132, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - return 0; + { + hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + + return 0; } @@ -135,10 +142,10 @@ void hb_arrayNew( PHB_ITEM pItem, ULONG ulLen ) /* creates a new array */ pItem->type = IT_ARRAY; - if( ulLen ) - pBaseArray->pItems = ( PHB_ITEM ) hb_xgrab( sizeof( HB_ITEM ) * ulLen ); + if( ulLen > 0 ) + pBaseArray->pItems = ( PHB_ITEM ) hb_xgrab( sizeof( HB_ITEM ) * ulLen ); else - pBaseArray->pItems = 0; + pBaseArray->pItems = 0; pBaseArray->ulLen = ulLen; pBaseArray->wHolders = 1; @@ -146,7 +153,7 @@ void hb_arrayNew( PHB_ITEM pItem, ULONG ulLen ) /* creates a new array */ pBaseArray->bSuperCast = FALSE; for( ul = 0; ul < ulLen; ul++ ) - ( pBaseArray->pItems + ul )->type = IT_NIL; + ( pBaseArray->pItems + ul )->type = IT_NIL; pItem->item.asArray.value = pBaseArray; } @@ -161,362 +168,364 @@ void hb_arrayAdd( PHB_ITEM pArray, PHB_ITEM pValue ) void hb_arrayGet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned )hb_arrayLen( pArray ) ) - hb_itemCopy( pItem, pArray->item.asArray.value->pItems + ( ulIndex - 1 ) ); + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + hb_itemCopy( pItem, pArray->item.asArray.value->pItems + ( ulIndex - 1 ) ); else - { - hb_errRT_BASE(EG_BOUND, 1132, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } + { + hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } } -char *hb_arrayGetString( PHB_ITEM pArray, ULONG ulIndex ) +char * hb_arrayGetString( PHB_ITEM pArray, ULONG ulIndex ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned )hb_arrayLen( pArray ) ) - { - PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + { + PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; - if( IS_STRING( pItem ) ) + if( IS_STRING( pItem ) ) return pItem->item.asString.value; - else - return ""; - } + } else - { - hb_errRT_BASE(EG_BOUND, 1132, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - return ""; + { + hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + + return ""; } ULONG hb_arrayGetStringLen( PHB_ITEM pArray, ULONG ulIndex ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned )hb_arrayLen( pArray ) ) - { - PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + { + PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; - if( IS_STRING( pItem ) ) + if( IS_STRING( pItem ) ) return pItem->item.asString.length; - else - return 0; - } + } else - { - hb_errRT_BASE(EG_BOUND, 1132, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - return 0; + { + hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + + return 0; } int hb_arrayGetType( PHB_ITEM pArray, ULONG ulIndex ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned ) hb_arrayLen( pArray ) ) - { - PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; - return pItem->type; - } + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + { + PHB_ITEM pItem = pArray->item.asArray.value->pItems + ulIndex - 1; + return pItem->type; + } else - { - hb_errRT_BASE(EG_BOUND, 1132, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - return 0; + { + hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + + return 0; } void hb_arrayLast( PHB_ITEM pArray, PHB_ITEM pResult ) { - if ( pArray->item.asArray.value->ulLen ) - hb_itemCopy( pResult, pArray->item.asArray.value->pItems + + if( pArray->item.asArray.value->ulLen ) + hb_itemCopy( pResult, pArray->item.asArray.value->pItems + ( pArray->item.asArray.value->ulLen - 1 ) ); - else - hb_itemClear( pResult ); + else + hb_itemClear( pResult ); } ULONG hb_arrayLen( PHB_ITEM pArray ) { - if( IS_ARRAY( pArray ) ) - return pArray->item.asArray.value->ulLen; - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_ARRACCESS)); - } - return 0; + if( IS_ARRAY( pArray ) ) + return pArray->item.asArray.value->ulLen; + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_ARRACCESS ) ); + } + + return 0; } void hb_arraySet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ) { - if( IS_ARRAY( pArray ) ) - { - if( ulIndex <= ( unsigned )hb_arrayLen( pArray ) ) - hb_itemCopy( pArray->item.asArray.value->pItems + ( ulIndex - 1 ), pItem ); + if( IS_ARRAY( pArray ) ) + { + if( ulIndex <= hb_arrayLen( pArray ) ) + hb_itemCopy( pArray->item.asArray.value->pItems + ( ulIndex - 1 ), pItem ); else - { - hb_errRT_BASE(EG_BOUND, 1133, NULL, hb_langDGetErrorDesc(EG_ARRASSIGN)); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1069, NULL, hb_langDGetErrorDesc(EG_ARRASSIGN)); - } + { + hb_errRT_BASE( EG_BOUND, 1133, NULL, hb_langDGetErrorDesc( EG_ARRASSIGN ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1069, NULL, hb_langDGetErrorDesc( EG_ARRASSIGN ) ); + } } void hb_arraySize( PHB_ITEM pArray, ULONG ulLen ) { - if ( IS_ARRAY( pArray ) ) - { + if( IS_ARRAY( pArray ) ) + { PBASEARRAY pBaseArray = pArray->item.asArray.value; ULONG ul; if( ! pBaseArray->ulLen ) - { - pBaseArray->pItems = ( PHB_ITEM ) hb_xgrab( ulLen * sizeof( HB_ITEM ) ); - for ( ul = 0; ul < ulLen; ul ++ ) + { + pBaseArray->pItems = ( PHB_ITEM ) hb_xgrab( ulLen * sizeof( HB_ITEM ) ); + for( ul = 0; ul < ulLen; ul ++ ) ( pBaseArray->pItems + ul )->type = IT_NIL; - } + } else - { - if( pBaseArray->ulLen < ulLen ) - { - pBaseArray->pItems = ( PHB_ITEM )hb_xrealloc( pBaseArray->pItems, sizeof( HB_ITEM ) * ulLen ); + { + if( pBaseArray->ulLen < ulLen ) + { + pBaseArray->pItems = ( PHB_ITEM ) hb_xrealloc( pBaseArray->pItems, sizeof( HB_ITEM ) * ulLen ); - /* set value for new items */ - for( ul = pBaseArray->ulLen; ul < ulLen; ul++ ) - ( pBaseArray->pItems + ul )->type = IT_NIL; - } - else if( pBaseArray->ulLen > ulLen ) - { - /* release old items */ - for( ul = ulLen; ul < pBaseArray->ulLen; ul++ ) - hb_itemClear( pBaseArray->pItems + ul ); + /* set value for new items */ + for( ul = pBaseArray->ulLen; ul < ulLen; ul++ ) + ( pBaseArray->pItems + ul )->type = IT_NIL; + } + else if( pBaseArray->ulLen > ulLen ) + { + /* release old items */ + for( ul = ulLen; ul < pBaseArray->ulLen; ul++ ) + hb_itemClear( pBaseArray->pItems + ul ); - pBaseArray->pItems = ( PHB_ITEM )hb_xrealloc( pBaseArray->pItems, sizeof( HB_ITEM ) * ulLen ); - } - } + pBaseArray->pItems = ( PHB_ITEM ) hb_xrealloc( pBaseArray->pItems, sizeof( HB_ITEM ) * ulLen ); + } + } pBaseArray->ulLen = ulLen; - } + } } void hb_arrayFill( PHB_ITEM pArray, PHB_ITEM pValue, ULONG ulStart, ULONG ulCount ) { - if ( IS_ARRAY( pArray ) ) - { + if( IS_ARRAY( pArray ) ) + { PBASEARRAY pBaseArray; ULONG ulLen = hb_arrayLen( pArray ); - if ( ulStart == 0 ) /* if parameter is missing */ - ulStart = 1; + if( ulStart == 0 ) /* if parameter is missing */ + ulStart = 1; - if ( ulCount == 0 ) /* if parameter is missing */ - ulCount = ulLen - ulStart + 1; + if( ulCount == 0 ) /* if parameter is missing */ + ulCount = ulLen - ulStart + 1; - if ( ulStart + ulCount > ulLen ) /* check range */ - ulCount = ulLen - ulStart + 1; + if( ulStart + ulCount > ulLen ) /* check range */ + ulCount = ulLen - ulStart + 1; pBaseArray = pArray->item.asArray.value; - for ( ; ulCount > 0; ulCount --, ulStart ++ ) /* set value items */ - hb_itemCopy( pBaseArray->pItems + ( ulStart - 1 ), pValue ); - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_NOTARRAY)); - } + for( ; ulCount > 0; ulCount --, ulStart ++ ) /* set value items */ + hb_itemCopy( pBaseArray->pItems + ( ulStart - 1 ), pValue ); + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + } } void hb_arrayDel( PHB_ITEM pArray, ULONG ulIndex ) { - if ( IS_ARRAY( pArray ) ) - { + if( IS_ARRAY( pArray ) ) + { ULONG ulLen = hb_arrayLen( pArray ); - if ( ulIndex > 0 && ulIndex <= ulLen ) - { - PBASEARRAY pBaseArray = pArray->item.asArray.value; + if( ulIndex > 0 && ulIndex <= ulLen ) + { + PBASEARRAY pBaseArray = pArray->item.asArray.value; - hb_itemClear( pBaseArray->pItems + ( ulIndex - 1 ) ); + hb_itemClear( pBaseArray->pItems + ( ulIndex - 1 ) ); - for ( ulIndex --; ulIndex < ulLen; ulIndex ++ ) /* move items */ + for( ulIndex --; ulIndex < ulLen; ulIndex ++ ) /* move items */ hb_itemCopy( pBaseArray->pItems + ulIndex, pBaseArray->pItems + ( ulIndex + 1 ) ); - hb_itemClear( pBaseArray->pItems + ( ulLen - 1 ) ); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_NOTARRAY)); - } + hb_itemClear( pBaseArray->pItems + ( ulLen - 1 ) ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + } } void hb_arrayIns( PHB_ITEM pArray, ULONG ulIndex ) { - if ( IS_ARRAY( pArray ) ) - { + if( IS_ARRAY( pArray ) ) + { ULONG ulLen = hb_arrayLen( pArray ); - if ( ulIndex > 0 && ulIndex <= ulLen ) - { - PBASEARRAY pBaseArray = pArray->item.asArray.value; + if( ulIndex > 0 && ulIndex <= ulLen ) + { + PBASEARRAY pBaseArray = pArray->item.asArray.value; - hb_itemClear( pBaseArray->pItems + ( ulLen - 1 ) ); + hb_itemClear( pBaseArray->pItems + ( ulLen - 1 ) ); - for ( ulLen --; ulLen >= ulIndex; ulLen -- ) /* move items */ + for( ulLen --; ulLen >= ulIndex; ulLen -- ) /* move items */ hb_itemCopy( pBaseArray->pItems + ulLen, pBaseArray->pItems + ( ulLen - 1 ) ); - hb_itemClear( pBaseArray->pItems + ulLen ); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_NOTARRAY)); - } + hb_itemClear( pBaseArray->pItems + ulLen ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + } } int hb_arrayScan( PHB_ITEM pArray, PHB_ITEM pValue, ULONG ulStart, ULONG ulCount ) { - if ( IS_ARRAY( pArray ) && pValue->type != IT_NIL ) - { + if( IS_ARRAY( pArray ) && pValue->type != IT_NIL ) + { BOOL bFound = FALSE; PBASEARRAY pBaseArray; ULONG ulLen = hb_arrayLen( pArray ); - if ( ulStart == 0 ) /* if parameter is missing */ - ulStart = 1; + if( ulStart == 0 ) /* if parameter is missing */ + ulStart = 1; - if ( ulCount == 0 ) /* if parameter is missing */ - ulCount = ulLen - ulStart + 1; + if( ulCount == 0 ) /* if parameter is missing */ + ulCount = ulLen - ulStart + 1; - if ( ulStart + ulCount > ulLen ) /* check range */ - ulCount = ulLen - ulStart + 1; + if( ulStart + ulCount > ulLen ) /* check range */ + ulCount = ulLen - ulStart + 1; pBaseArray = pArray->item.asArray.value; - for ( ulStart --; ulCount > 0; ulCount --, ulStart ++ ) - { - PHB_ITEM pItem = pBaseArray->pItems + ulStart; + for( ulStart --; ulCount > 0; ulCount --, ulStart ++ ) + { + PHB_ITEM pItem = pBaseArray->pItems + ulStart; - if ( pValue->type == IT_BLOCK ) + if( pValue->type == IT_BLOCK ) + { + hb_vmPushSymbol( &symEval ); + hb_vmPush( pValue ); + hb_vmPush( pItem ); + hb_vmDo( 1 ); + + if( IS_LOGICAL( &stack.Return ) && + stack.Return.item.asLogical.value ) + bFound = TRUE; + } + else + { + if( pValue->type == pItem->type ) { - hb_vmPushSymbol( &symEval ); - hb_vmPush( pValue ); - hb_vmPush( pItem ); - hb_vmDo( 1 ); + switch( pItem->type ) + { + case IT_INTEGER : + bFound = ( pValue->item.asInteger.value == pItem->item.asInteger.value ); + break; - if ( IS_LOGICAL( &stack.Return ) && - stack.Return.item.asLogical.value ) - bFound = TRUE; + case IT_LONG : + bFound = ( pValue->item.asLong.value == pItem->item.asLong.value ); + break; + + case IT_DOUBLE : + bFound = ( pValue->item.asDouble.value == pItem->item.asDouble.value ); + break; + + case IT_DATE : + bFound = ( pValue->item.asDate.value == pItem->item.asDouble.value ); + break; + + case IT_LOGICAL : + bFound = ( pValue->item.asLogical.value == pItem->item.asLogical.value ); + break; + + case IT_STRING : + bFound = ( hb_itemStrCmp( pValue, pItem, FALSE ) == 0 ); + break; + } } - else - { - if ( pValue->type == pItem->type ) - { - switch( pItem->type ) - { - case IT_INTEGER : - bFound = ( pValue->item.asInteger.value == pItem->item.asInteger.value); - break; + } - case IT_LONG : - bFound = ( pValue->item.asLong.value == pItem->item.asLong.value ); - break; - - case IT_DOUBLE : - bFound = ( pValue->item.asDouble.value == pItem->item.asDouble.value ); - break; - - case IT_DATE : - bFound = ( pValue->item.asDate.value == pItem->item.asDouble.value ); - break; - - case IT_LOGICAL : - bFound = ( pValue->item.asLogical.value == pItem->item.asLogical.value ); - break; - - case IT_STRING : - bFound = ( hb_itemStrCmp( pValue, pItem, FALSE ) == 0 ); - break; - } - } - } - if ( bFound ) + if( bFound ) return ulStart + 1; /* arrays start from 1 */ - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_NOTARRAY)); - } - return 0; + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + } + + return 0; } void hb_arrayEval( PHB_ITEM pArray, PHB_ITEM bBlock, ULONG ulStart, ULONG ulCount ) { - if ( IS_ARRAY( pArray ) && IS_BLOCK( bBlock ) ) - { + if( IS_ARRAY( pArray ) && IS_BLOCK( bBlock ) ) + { PBASEARRAY pBaseArray; ULONG ulLen = hb_arrayLen( pArray ); - if ( ulStart == 0 ) /* if parameter is missing */ - ulStart = 1; + if( ulStart == 0 ) /* if parameter is missing */ + ulStart = 1; - if ( ulCount == 0 ) /* if parameter is missing */ - ulCount = ulLen - ulStart + 1; + if( ulCount == 0 ) /* if parameter is missing */ + ulCount = ulLen - ulStart + 1; - if ( ulStart + ulCount > ulLen ) /* check range */ - ulCount = ulLen - ulStart + 1; + if( ulStart + ulCount > ulLen ) /* check range */ + ulCount = ulLen - ulStart + 1; pBaseArray = pArray->item.asArray.value; - for ( ulStart --; ulCount > 0; ulCount --, ulStart ++ ) - { - PHB_ITEM pItem = pBaseArray->pItems + ulStart; + for( ulStart --; ulCount > 0; ulCount --, ulStart ++ ) + { + PHB_ITEM pItem = pBaseArray->pItems + ulStart; - hb_vmPushSymbol( &symEval ); - hb_vmPush( bBlock ); - hb_vmPush( pItem ); - hb_vmPushNumber( (double)(ulStart + 1), 0 ); - hb_vmDo( 2 ); - } - } - else - { - hb_errRT_BASE(EG_ARG, 2017, NULL, "AEVAL"); - } + hb_vmPushSymbol( &symEval ); + hb_vmPush( bBlock ); + hb_vmPush( pItem ); + hb_vmPushNumber( ( double ) ( ulStart + 1 ), 0 ); + hb_vmDo( 2 ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 2017, NULL, "AEVAL" ); + } } void hb_arrayRelease( PHB_ITEM pArray ) { - if ( IS_ARRAY( pArray ) ) - { + if( IS_ARRAY( pArray ) ) + { ULONG ul, ulLen = hb_arrayLen( pArray ); PBASEARRAY pBaseArray = pArray->item.asArray.value; if( !pBaseArray->bSuperCast ) { - for ( ul = 0; ul < ulLen; ul ++ ) + for( ul = 0; ul < ulLen; ul ++ ) hb_itemClear( pBaseArray->pItems + ul ); if( pBaseArray->pItems ) @@ -526,56 +535,56 @@ void hb_arrayRelease( PHB_ITEM pArray ) pArray->type = IT_NIL; pArray->item.asArray.value = NULL; - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_NOTARRAY)); - } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + } } void hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG ulStart, - ULONG ulCount, ULONG ulTarget ) + ULONG ulCount, ULONG ulTarget ) { - if ( IS_ARRAY( pSrcArray ) && IS_ARRAY( pDstArray ) ) - { + if( IS_ARRAY( pSrcArray ) && IS_ARRAY( pDstArray ) ) + { PBASEARRAY pSrcBaseArray, pDstBaseArray; ULONG ulSrcLen = hb_arrayLen( pSrcArray ); ULONG ulDstLen = hb_arrayLen( pDstArray ); - if ( ulStart == 0 ) /* if parameter is missing */ - ulStart = 1; + if( ulStart == 0 ) /* if parameter is missing */ + ulStart = 1; - if ( ulTarget == 0 ) /* if parameter is missing */ - ulTarget = 1; + if( ulTarget == 0 ) /* if parameter is missing */ + ulTarget = 1; - if ( ulCount == 0 ) /* if parameter is missing */ - ulCount = ulSrcLen - ulStart + 1; + if( ulCount == 0 ) /* if parameter is missing */ + ulCount = ulSrcLen - ulStart + 1; - if ( ulStart + ulCount > ulSrcLen ) /* check range */ - ulCount = ulSrcLen - ulStart + 1; + if( ulStart + ulCount > ulSrcLen ) /* check range */ + ulCount = ulSrcLen - ulStart + 1; - if ( ulCount > ulDstLen ) - ulCount = ulDstLen; + if( ulCount > ulDstLen ) + ulCount = ulDstLen; pSrcBaseArray = pSrcArray->item.asArray.value; pDstBaseArray = pDstArray->item.asArray.value; - for ( ulTarget --, ulStart --; ulCount > 0; ulCount --, ulStart ++ ) - { - hb_itemCopy( pDstBaseArray->pItems + ( ulTarget + ulStart ), pSrcBaseArray->pItems + ulStart ); - } - } - else - { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_NOTARRAY)); - } + for( ulTarget --, ulStart --; ulCount > 0; ulCount --, ulStart ++ ) + { + hb_itemCopy( pDstBaseArray->pItems + ( ulTarget + ulStart ), pSrcBaseArray->pItems + ulStart ); + } + } + else + { + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + } } PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray ) { PHB_ITEM pDstArray = hb_itemNew( 0 ); - if ( IS_ARRAY( pSrcArray ) ) + if( IS_ARRAY( pSrcArray ) ) { PBASEARRAY pSrcBaseArray, pDstBaseArray; ULONG ulCount, ulSrcLen = hb_arrayLen( pSrcArray ); @@ -586,11 +595,11 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray ) pDstBaseArray = pDstArray->item.asArray.value; pDstBaseArray->wClass = pSrcBaseArray->wClass; - for ( ulCount = 0; ulCount < ulSrcLen; ulCount ++ ) + for( ulCount = 0; ulCount < ulSrcLen; ulCount ++ ) { PHB_ITEM pSrcItem = pSrcBaseArray->pItems + ulCount; - if ( pSrcItem->type == IT_ARRAY ) + if( pSrcItem->type == IT_ARRAY ) { PHB_ITEM pClone = hb_arrayClone( pSrcItem ); @@ -604,8 +613,9 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray ) } else { - hb_errRT_BASE(EG_ARG, 1068, NULL, hb_langDGetErrorDesc(EG_NOTARRAY)); + hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); } + return pDstArray; } @@ -617,184 +627,167 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray ) HARBOUR HB_ARRAY( void ) { - int iParCount = hb_pcount(); + int iParCount = hb_pcount(); - if ( iParCount > 0 ) - { - int tmp; - BOOL bError = FALSE; + if( iParCount > 0 ) + { + int tmp; + BOOL bError = FALSE; - for ( tmp = 1; tmp <= iParCount; tmp++ ) - { - if ( !ISNUM( tmp ) ) + for( tmp = 1; tmp <= iParCount; tmp++ ) { - bError = TRUE; - break; + if( ! ISNUM( tmp ) ) + { + bError = TRUE; + break; + } + + if( hb_parnl( tmp ) < 0 ) + { + hb_errRT_BASE( EG_BOUND, 1131, NULL, hb_langDGetErrorDesc( EG_ARRDIMENSION ) ); + } } - if ( hb_parnl( tmp ) < 0 ) - { - hb_errRT_BASE( EG_BOUND, 1131, NULL, hb_langDGetErrorDesc( EG_ARRDIMENSION ) ); - } - } - - if ( bError ) - hb_ret(); - else - hb_arrayNew( &stack.Return, hb_parnl( 1 ) ); - } - else - hb_ret(); + if( ! bError ) + hb_arrayNew( &stack.Return, hb_parnl( 1 ) ); + } } HARBOUR HB_AADD( void ) { - if ( hb_pcount() == 2 ) - { - if ( ISARRAY( 1 ) ) - { + if( hb_pcount() == 2 ) + { PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - PHB_ITEM pValue = hb_param( 2, IT_ANY ); - hb_arrayAdd( pArray, pValue ); + if( pArray ) + { + PHB_ITEM pValue = hb_param( 2, IT_ANY ); - hb_itemCopy( &stack.Return, pValue ); - } - else - hb_errRT_BASE( EG_ARG, 1123, NULL, "AADD" ); - } - else - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "AADD" ); + hb_arrayAdd( pArray, pValue ); + + hb_itemCopy( &stack.Return, pValue ); + } + else + hb_errRT_BASE( EG_ARG, 1123, NULL, "AADD" ); + } + else + /* NOTE: Clipper catches this at compile time! */ + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "AADD" ); } HARBOUR HB_ASIZE( void ) { - PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - if ( pArray && ISNUM( 2 ) ) - { - LONG lSize = hb_parnl( 2 ); + if( pArray && ISNUM( 2 ) ) + { + LONG lSize = hb_parnl( 2 ); - hb_arraySize( pArray, MAX( lSize, 0 ) ); + hb_arraySize( pArray, MAX( lSize, 0 ) ); - hb_itemCopy( &stack.Return, pArray ); /* ASize() returns the array itself */ - } - else - hb_ret(); + hb_itemCopy( &stack.Return, pArray ); /* ASize() returns the array itself */ + } } HARBOUR HB_ATAIL( void ) { - PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - if ( pArray ) - hb_arrayLast( pArray, &stack.Return ); - else - hb_ret(); + if( pArray ) + hb_arrayLast( pArray, &stack.Return ); } HARBOUR HB_AINS( void ) { - PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - if ( pArray ) - { - if ( ISNUM( 2 ) ) - hb_arrayIns( pArray, hb_parnl( 2 ) ); + if( pArray ) + { + if( ISNUM( 2 ) ) + hb_arrayIns( pArray, hb_parnl( 2 ) ); - hb_itemCopy( &stack.Return, pArray ); /* AIns() returns the array itself */ - } - else - hb_ret(); + hb_itemCopy( &stack.Return, pArray ); /* AIns() returns the array itself */ + } } HARBOUR HB_ADEL( void ) { - PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - if ( pArray ) - { - if ( ISNUM( 2 ) ) - hb_arrayDel( pArray, hb_parnl( 2 ) ); + if( pArray ) + { + if( ISNUM( 2 ) ) + hb_arrayDel( pArray, hb_parnl( 2 ) ); - hb_itemCopy( &stack.Return, pArray ); /* ADel() returns the array itself */ - } - else - hb_ret(); + hb_itemCopy( &stack.Return, pArray ); /* ADel() returns the array itself */ + } } /* TOFIX: nCount parameter == zero is incompatible. */ HARBOUR HB_AFILL( void ) { - PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - if ( pArray ) - { + if( pArray ) + { hb_arrayFill( pArray, hb_param( 2, IT_ANY ), hb_parnl( 3 ), hb_parnl( 4 ) ); hb_itemCopy( &stack.Return, pArray ); /* AFill() returns the array itself */ - } - else - hb_ret(); + } } /* TOFIX: nCount parameter == zero is incompatible. */ HARBOUR HB_ASCAN( void ) { - PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - if ( pArray ) - hb_retnl( hb_arrayScan( pArray, hb_param( 2, IT_ANY ), hb_parnl( 3 ), hb_parnl( 4 ) ) ); - else - hb_retnl( 0 ); + if( pArray ) + hb_retnl( hb_arrayScan( pArray, hb_param( 2, IT_ANY ), hb_parnl( 3 ), hb_parnl( 4 ) ) ); + else + hb_retnl( 0 ); } /* TOFIX: nCount parameter == zero is incompatible. */ HARBOUR HB_AEVAL( void ) { - PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); - PHB_ITEM bBlock = hb_param( 2, IT_BLOCK ); + PHB_ITEM pArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pBlock = hb_param( 2, IT_BLOCK ); - if ( pArray ) - { - hb_arrayEval( pArray, bBlock, hb_parnl( 3 ), hb_parnl( 4 ) ); + if( pArray && pBlock ) + { + hb_arrayEval( pArray, pBlock, hb_parnl( 3 ), hb_parnl( 4 ) ); hb_itemCopy( &stack.Return, pArray ); /* AEval() returns the array itself */ - } - else - hb_ret(); + } + else + hb_errRT_BASE( EG_ARG, 2017, NULL, "AEVAL" ); } /* TOFIX: nCount parameter == zero is incompatible. */ HARBOUR HB_ACOPY( void ) { - PHB_ITEM pSrcArray = hb_param( 1, IT_ARRAY ); - PHB_ITEM pDstArray = hb_param( 2, IT_ARRAY ); + PHB_ITEM pSrcArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pDstArray = hb_param( 2, IT_ARRAY ); - if ( pSrcArray && pDstArray ) - { + if( pSrcArray && pDstArray ) + { hb_arrayCopy( pSrcArray, pDstArray, hb_parnl( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ); hb_itemCopy( &stack.Return, pDstArray ); /* ACopy() returns the target array */ - } - else - hb_ret(); + } } HARBOUR HB_ACLONE( void ) { - PHB_ITEM pSrcArray = hb_param( 1, IT_ARRAY ); + PHB_ITEM pSrcArray = hb_param( 1, IT_ARRAY ); - if ( pSrcArray ) - { + if( pSrcArray ) + { PHB_ITEM pDstArray = hb_arrayClone( pSrcArray ); hb_itemCopy( &stack.Return, pDstArray ); /* AClone() returns the new array */ hb_itemClear( pDstArray ); hb_xfree( pDstArray ); - } - else - hb_ret(); + } } diff --git a/harbour/source/rtl/classes.c b/harbour/source/rtl/classes.c index a9e9a1ec3e..89365f80b6 100644 --- a/harbour/source/rtl/classes.c +++ b/harbour/source/rtl/classes.c @@ -70,7 +70,7 @@ typedef struct #define BASE_METHODS 200 #define BUCKET 4 -#define HASH_KEY (BASE_METHODS / BUCKET) +#define HASH_KEY ( BASE_METHODS / BUCKET ) static PCLASS pClasses = 0; static WORD wClasses = 0; @@ -133,7 +133,7 @@ extern HARBOUR HB___OBJMODMETHOD( void ); * see MET_* * Optional initializer for DATA */ -HARBOUR HB___CLSADDMSG(void) +HARBOUR HB___CLSADDMSG( void ) { WORD wClass = hb_parnl( 1 ); @@ -148,7 +148,7 @@ HARBOUR HB___CLSADDMSG(void) if ( wType == MET_INLINE && hb_param( 3, IT_BLOCK ) == NULL ) { - hb_errRT_BASE(EG_ARG, 3000, NULL, "__CLSADDMSG"); + hb_errRT_BASE( EG_ARG, 3000, NULL, "__CLSADDMSG" ); } if( pClass->wMethods > ( pClass->wHashKey * BUCKET * 2/3 ) ) @@ -237,7 +237,7 @@ HARBOUR HB___CLSADDMSG(void) * Number of DATAs in the class * Optional handle of superclass */ -HARBOUR HB___CLSNEW(void) +HARBOUR HB___CLSNEW( void ) { WORD wSuper = hb_parni( 3 ); /* Super class present */ PCLASS pNewCls; @@ -258,7 +258,7 @@ HARBOUR HB___CLSNEW(void) WORD wSize; pNewCls->wDataFirst = pSprCls->wDatas; - pNewCls->wDatas = pSprCls->wDatas + hb_parni(2); + pNewCls->wDatas = pSprCls->wDatas + hb_parni( 2 ); pNewCls->wMethods = pSprCls->wMethods; pNewCls->pClassDatas = hb_arrayClone( pSprCls->pClassDatas ); @@ -295,7 +295,7 @@ HARBOUR HB___CLSNEW(void) * Object * Message */ -HARBOUR HB___CLSDELMSG(void) +HARBOUR HB___CLSDELMSG( void ) { WORD wClass = hb_parni( 1 ); PHB_ITEM pString = hb_param( 2, IT_STRING ); @@ -314,7 +314,7 @@ HARBOUR HB___CLSDELMSG(void) ( pClass->pMethods[ wAt ].pMessage != pMsg ) ) ) { wAt++; - if( wAt == wMask) + if( wAt == wMask ) wAt = 0; } @@ -334,7 +334,7 @@ HARBOUR HB___CLSDELMSG(void) pClass->pMethods + ( ( wAt == wMask ) ? 0 : wAt + 1 ), sizeof( METHOD ) ); wAt++; - if( wAt == wMask) + if( wAt == wMask ) wAt = 0; } @@ -362,7 +362,7 @@ static HARBOUR hb___msgClsH( void ) * * Create a new object from class definition */ -HARBOUR HB___CLSINST(void) +HARBOUR HB___CLSINST( void ) { WORD wClass = hb_parni( 1 ); @@ -380,8 +380,6 @@ HARBOUR HB___CLSINST(void) if( pMeth->pInitValue ) hb_itemArrayPut( &stack.Return, pMeth->wData, pMeth->pInitValue ); } - else - hb_ret(); } /* @@ -389,7 +387,7 @@ HARBOUR HB___CLSINST(void) * * Modify message (only for INLINE and METHOD) */ -HARBOUR HB___CLSMODMSG(void) +HARBOUR HB___CLSMODMSG( void ) { WORD wClass = hb_parni( 1 ); PHB_ITEM pString = hb_param( 2, IT_STRING ); @@ -408,7 +406,7 @@ HARBOUR HB___CLSMODMSG(void) ( pClass->pMethods[ wAt ].pMessage != pMsg ) ) ) { wAt++; - if( wAt == wMask) + if( wAt == wMask ) wAt = 0; } @@ -421,13 +419,13 @@ HARBOUR HB___CLSMODMSG(void) PHB_ITEM pBlock = hb_param( 3, IT_BLOCK ); if ( pBlock == NULL ) - hb_errRT_BASE(EG_ARG, 3000, NULL, "__CLSMODMSG"); + hb_errRT_BASE( EG_ARG, 3000, NULL, "__CLSMODMSG" ); else hb_arraySet( pClass->pInlines, pClass->pMethods[ wAt ].wData, pBlock ); } else if( ( pFunc == hb___msgSetData ) || ( pFunc == hb___msgGetData ) ) { /* Not allowed for DATA */ - hb_errRT_BASE(EG_ARG, 3004, "Cannot modify a DATA item", "__CLSMODMSG"); + hb_errRT_BASE( EG_ARG, 3004, "Cannot modify a DATA item", "__CLSMODMSG" ); } else /* Modify METHOD */ pClass->pMethods[ wAt ].pFunction = ( PHB_FUNC ) hb_parnl( 3 ); @@ -459,7 +457,7 @@ static HARBOUR hb___msgClsName( void ) * * Returns class name of */ -HARBOUR HB___OBJGETCLSNAME(void) +HARBOUR HB___OBJGETCLSNAME( void ) { PHB_ITEM pObject = hb_param( 0, IT_OBJECT ); @@ -484,7 +482,7 @@ HARBOUR HB___OBJGETCLSNAME(void) * * Returns all the messages in */ -static HARBOUR hb___msgClsSel(void) +static HARBOUR hb___msgClsSel( void ) { WORD wClass = IS_ARRAY( stack.pBase + 1 ) ? ( stack.pBase + 1 )->item.asArray.value->wClass : 0; @@ -697,7 +695,7 @@ PHB_FUNC hb_objGetMethod( PHB_ITEM pObject, PHB_SYMB pMessage ) return pMethod->pFunction; } wAt++; - if( wAt == wMask) + if( wAt == wMask ) wAt = 0; } } @@ -728,7 +726,7 @@ PHB_FUNC hb_objGetMethod( PHB_ITEM pObject, PHB_SYMB pMessage ) ULONG hb_objHasMsg( PHB_ITEM pObject, char *szString ) { PHB_SYMB pMessage = hb_dynsymGet( szString )->pSymbol; - return( (ULONG) hb_objGetMethod( pObject, pMessage ) ); + return( ( ULONG ) hb_objGetMethod( pObject, pMessage ) ); } /* Get funcptr of message */ @@ -737,7 +735,7 @@ ULONG hb_objHasMsg( PHB_ITEM pObject, char *szString ) * * Is a valid message for the */ -HARBOUR HB___OBJHASMSG(void) +HARBOUR HB___OBJHASMSG( void ) { PHB_ITEM pObject = hb_param( 1, IT_OBJECT ); PHB_ITEM pString = hb_param( 2, IT_STRING ); @@ -746,7 +744,7 @@ HARBOUR HB___OBJHASMSG(void) hb_retl( hb_objHasMsg( pObject, pString->item.asString.value ) != 0 ); else { - hb_errRT_BASE(EG_ARG, 3000, NULL, "__OBJHASMSG"); + hb_errRT_BASE( EG_ARG, 3000, NULL, "__OBJHASMSG" ); } } @@ -769,7 +767,7 @@ HARBOUR HB___OBJCLONE( void ) } else { - hb_errRT_BASE(EG_ARG, 3001, NULL, "__OBJCLONE"); + hb_errRT_BASE( EG_ARG, 3001, NULL, "__OBJCLONE" ); } } @@ -779,7 +777,7 @@ HARBOUR HB___OBJCLONE( void ) * * Send a message to an object */ -HARBOUR HB___OBJSENDMSG(void) +HARBOUR HB___OBJSENDMSG( void ) { PHB_ITEM pObject = hb_param( 1, IT_OBJECT ); PHB_ITEM pMessage = hb_param( 2, IT_STRING ); @@ -797,7 +795,7 @@ HARBOUR HB___OBJSENDMSG(void) } else { - hb_errRT_BASE(EG_ARG, 3000, NULL, "__OBJSENDMSG"); + hb_errRT_BASE( EG_ARG, 3000, NULL, "__OBJSENDMSG" ); } } @@ -850,8 +848,8 @@ void hb_clsReleaseAll( void ) static HARBOUR hb___msgSuper( void ) { PHB_ITEM pObject = stack.pBase + 1; - PHB_ITEM pSuper = (PHB_ITEM) hb_xgrab( sizeof( HB_ITEM ) ); - PBASEARRAY pNewBase = (PBASEARRAY) hb_xgrab( sizeof( BASEARRAY ) ); + PHB_ITEM pSuper = ( PHB_ITEM ) hb_xgrab( sizeof( HB_ITEM ) ); + PBASEARRAY pNewBase = ( PBASEARRAY ) hb_xgrab( sizeof( BASEARRAY ) ); WORD wSuperCls = pMethod->wData; /* Get handle of superclass */ memcpy( pSuper, pObject, sizeof( HB_ITEM ) ); @@ -938,7 +936,7 @@ HARBOUR HB___CLSINSTSUPER( void ) if( !IS_OBJECT( &stack.Return ) ) { - hb_errRT_BASE(EG_ARG, 3002, "Super class does not return an object", "__CLSINSTSUPER"); + hb_errRT_BASE( EG_ARG, 3002, "Super class does not return an object", "__CLSINSTSUPER" ); } for( w = 0; !bFound && w < wClasses; w++ ) @@ -952,7 +950,7 @@ HARBOUR HB___CLSINSTSUPER( void ) } else { - hb_errRT_BASE(EG_ARG, 3003, "Cannot find super class", "__CLSINSTSUPER"); + hb_errRT_BASE( EG_ARG, 3003, "Cannot find super class", "__CLSINSTSUPER" ); } } if( !bFound ) @@ -965,7 +963,7 @@ HARBOUR HB___CLSINSTSUPER( void ) * * Return number of class datas */ -HARBOUR HB___CLS_CNTCLSDATA(void) +HARBOUR HB___CLS_CNTCLSDATA( void ) { WORD wClass = hb_parnl( 1 ); @@ -981,7 +979,7 @@ HARBOUR HB___CLS_CNTCLSDATA(void) * * Return number of datas */ -HARBOUR HB___CLS_CNTDATA(void) +HARBOUR HB___CLS_CNTDATA( void ) { WORD wClass = hb_parnl( 1 ); @@ -996,7 +994,7 @@ HARBOUR HB___CLS_CNTDATA(void) * * Return number of datas and decrease */ -HARBOUR HB___CLS_DECDATA(void) +HARBOUR HB___CLS_DECDATA( void ) { WORD wClass = hb_parnl( 1 ); @@ -1012,7 +1010,7 @@ HARBOUR HB___CLS_DECDATA(void) * * Return number of datas and decrease */ -HARBOUR HB___CLS_INCDATA(void) +HARBOUR HB___CLS_INCDATA( void ) { WORD wClass = hb_parnl( 1 ); diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index 46b9eac83c..9504de5f4f 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -176,7 +176,7 @@ static void hb_out( WORD wParam, hb_out_func_typedef * hb_out_func ) { char * szText; PHB_ITEM pItem = hb_param( wParam, IT_ANY ); - char szBuffer [11]; + char szBuffer [ 11 ]; switch( hb_parinfo( wParam ) ) { @@ -524,12 +524,9 @@ HARBOUR HB_QOUT( void ) HARBOUR HB_SETPOS( void ) /* Sets the screen position */ { - PHB_ITEM pRow, pCol; if( hb_pcount() > 1 ) { - pRow = hb_param( 1, IT_NUMERIC ); - pCol = hb_param( 2, IT_NUMERIC ); - if( pRow && pCol ) + if( ISNUM( 1 ) && ISNUM( 2 ) ) { int i_row = hb_parni( 1 ); int i_col = hb_parni( 2 ); @@ -551,12 +548,9 @@ HARBOUR HB_SETPOS( void ) /* Sets the screen position */ HARBOUR HB_DEVPOS( void ) /* Sets the screen and/or printer position */ { - PHB_ITEM pRow, pCol; if( hb_pcount() > 1 ) { - pRow = hb_param( 1, IT_NUMERIC ); - pCol = hb_param( 2, IT_NUMERIC ); - if( pRow && pCol ) + if( ISNUM( 1 ) && ISNUM( 2 ) ) { long l_row = hb_parnl( 1 ); long l_col = hb_parnl( 2 ); @@ -582,7 +576,7 @@ HARBOUR HB_DEVOUT( void ) /* writes a single value to the current device (screen { #ifdef HARBOUR_USE_GTAPI char fpOldColor[ CLR_STRLEN ]; - if( ISCHAR(2) ) + if( ISCHAR( 2 ) ) { hb_gtGetColorStr( fpOldColor ); hb_gtSetColorStr( hb_parc(2) ); @@ -592,7 +586,7 @@ HARBOUR HB_DEVOUT( void ) /* writes a single value to the current device (screen hb_out( 1, hb_devout ); #ifdef HARBOUR_USE_GTAPI - if( ISCHAR(2) ) + if( ISCHAR( 2 ) ) { hb_gtSetColorStr( fpOldColor ); } @@ -607,7 +601,7 @@ HARBOUR HB_DISPOUT( void ) /* writes a single value to the current device (scree #ifdef HARBOUR_USE_GTAPI char fpOldColor[ CLR_STRLEN ]; - if( ISCHAR(2) ) + if( ISCHAR( 2 ) ) { hb_gtGetColorStr( fpOldColor ); hb_gtSetColorStr( hb_parc(2) ); @@ -617,7 +611,7 @@ HARBOUR HB_DISPOUT( void ) /* writes a single value to the current device (scree hb_out( 1, hb_dispout ); #ifdef HARBOUR_USE_GTAPI - if( ISCHAR(2) ) + if( ISCHAR( 2 ) ) { hb_gtSetColorStr( fpOldColor ); } @@ -648,9 +642,7 @@ HARBOUR HB_SETPRC( void ) /* Sets the current printer row and column positions * { if( hb_pcount() > 1 ) { - PHB_ITEM pRow = hb_param( 1, IT_NUMERIC ); - PHB_ITEM pCol = hb_param( 1, IT_NUMERIC ); - if( pRow && pCol ) + if( ISNUM( 1 ) && ISNUM( 2 ) ) { long l_row = hb_parnl( 1 ); long l_col = hb_parnl( 2 ); @@ -672,17 +664,17 @@ HARBOUR HB_SCROLL( void ) /* Scrolls a screen region (requires the GT API) */ v_scroll = 0, h_scroll = 0; WORD top, left, bottom, right; - if( hb_pcount() > 0 && hb_param( 1, IT_NUMERIC ) ) + if( hb_pcount() > 0 && ISNUM( 1 ) ) i_top = hb_parni( 1 ); - if( hb_pcount() > 1 && hb_param( 2, IT_NUMERIC ) ) + if( hb_pcount() > 1 && ISNUM( 2 ) ) i_left = hb_parni( 2 ); - if( hb_pcount() > 2 && hb_param( 3, IT_NUMERIC ) ) + if( hb_pcount() > 2 && ISNUM( 3 ) ) i_bottom = hb_parni( 3 ); - if( hb_pcount() > 3 && hb_param( 4, IT_NUMERIC ) ) + if( hb_pcount() > 3 && ISNUM( 4 ) ) i_right = hb_parni( 4 ); - if( hb_pcount() > 4 && hb_param( 5, IT_NUMERIC ) ) + if( hb_pcount() > 4 && ISNUM( 5 ) ) v_scroll = hb_parni( 5 ); - if( hb_pcount() > 5 && hb_param( 6, IT_NUMERIC ) ) + if( hb_pcount() > 5 && ISNUM( 6 ) ) h_scroll = hb_parni( 6 ); /* Enforce limits of (0,0) to (MAXROW(),MAXCOL()) */ @@ -743,21 +735,21 @@ HARBOUR HB_COL( void ) /* Return the current screen column position (zero origin HARBOUR HB_DISPBOX (void) { #ifdef HARBOUR_USE_GTAPI - if (ISNUM(1) && ISNUM(2) && ISNUM(3) && ISNUM(4)) + if( ISNUM( 1 ) && ISNUM( 2 ) && ISNUM( 3 ) && ISNUM( 4 ) ) { char szOldColor [CLR_STRLEN]; - if (ISCHAR(6)) + if( ISCHAR( 6 ) ) { hb_gtGetColorStr(szOldColor); hb_gtSetColorStr(hb_parc(6)); } - if (ISCHAR(5)) + if( ISCHAR( 5 ) ) { hb_gtBox(hb_parni(1), hb_parni(2), hb_parni(3), hb_parni(4), hb_parc(5)); } - else if (ISNUM(5) && hb_parni(5) == 2) + else if( ISNUM( 5 ) && hb_parni( 5 ) == 2 ) { hb_gtBoxD(hb_parni(1), hb_parni(2), hb_parni(3), hb_parni(4)); } @@ -766,13 +758,13 @@ HARBOUR HB_DISPBOX (void) hb_gtBoxS(hb_parni(1), hb_parni(2), hb_parni(3), hb_parni(4)); } - if (ISCHAR(6)) + if( ISCHAR( 6 ) ) { hb_gtSetColorStr(szOldColor); } } #else - if (ISNUM(1) && ISNUM(2) && ISNUM(3) && ISNUM(4)) + if( ISNUM( 1 ) && ISNUM( 2 ) && ISNUM( 3 ) && ISNUM( 4 ) ) { char * szBorderStyle = B_SINGLE; int i_top = hb_parni( 1 ), i_left = hb_parni( 2 ); @@ -920,7 +912,7 @@ HARBOUR HB_ISCOLOR (void) HARBOUR HB_NOSNOW (void) { #ifdef HARBOUR_USE_GTAPI - if ( ISLOG( 1 ) ) + if( ISLOG( 1 ) ) { hb_gtSetSnowFlag(hb_parl(1)); } @@ -1013,7 +1005,7 @@ HARBOUR HB_SETBLINK( void ) BOOL bPreviousBlink; hb_gtGetBlink( &bPreviousBlink ); - if ( ISLOG( 1 ) ) + if( ISLOG( 1 ) ) hb_gtSetBlink( hb_parl( 1 ) ); hb_retl( bPreviousBlink ); @@ -1040,7 +1032,7 @@ HARBOUR HB___ACCEPT( void ) /* Internal Clipper function used in ACCEPT command /* Read the data using fgets(), because hb_inkeyPoll() doesn't support Unix compatible operating systems yet. */ szResult[0] = '\x0'; /* start with something defined */ - if (fgets( szResult, ACCEPT_BUFFER_LEN, stdin )) + if( fgets( szResult, ACCEPT_BUFFER_LEN, stdin ) ) { strtok(szResult, "\n"); /* strip off the trailing newline if it exists */ @@ -1123,40 +1115,40 @@ HARBOUR HB___ACCEPT( void ) /* Internal Clipper function used in ACCEPT command HARBOUR HB___COLORINDEX( void ) { - if ( ISCHAR( 1 ) && ISNUM( 2 ) ) + if( ISCHAR( 1 ) && ISNUM( 2 ) ) { char * szColor = hb_parc( 1 ); ULONG ulColorPos; ULONG ulColorLen; - USHORT uiColorIndex = (USHORT) hb_parni( 2 ); + USHORT uiColorIndex = ( USHORT ) hb_parni( 2 ); /* Skip the given number of commas */ - for ( ulColorPos = 0 ; szColor[ ulColorPos ] != '\0' && uiColorIndex > 0 ; ulColorPos++ ) + for( ulColorPos = 0 ; szColor[ ulColorPos ] != '\0' && uiColorIndex > 0 ; ulColorPos++ ) { - if ( szColor[ ulColorPos ] == ',' ) + if( szColor[ ulColorPos ] == ',' ) uiColorIndex--; } /* if found, continue */ - if ( uiColorIndex == 0 ) + if( uiColorIndex == 0 ) { /* Skip the spaces after the comma */ - while ( szColor[ ulColorPos ] == ' ' ) ulColorPos++; + while( szColor[ ulColorPos ] == ' ' ) ulColorPos++; /* Search for next comma or end of string */ ulColorLen = 0; - while ( szColor[ ulColorPos + ulColorLen ] != '\0' && - szColor[ ulColorPos + ulColorLen ] != ',' ) ulColorLen++; + while( szColor[ ulColorPos + ulColorLen ] != '\0' && + szColor[ ulColorPos + ulColorLen ] != ',' ) ulColorLen++; /* Skip the trailing spaces */ - while ( ulColorLen > 0 && - szColor[ ulColorPos + ulColorLen - 1 ] == ' ' ) ulColorLen--; + while( ulColorLen > 0 && + szColor[ ulColorPos + ulColorLen - 1 ] == ' ' ) ulColorLen--; /* Return the string */ diff --git a/harbour/source/rtl/dates.c b/harbour/source/rtl/dates.c index c64979207d..efe84881d8 100644 --- a/harbour/source/rtl/dates.c +++ b/harbour/source/rtl/dates.c @@ -46,7 +46,7 @@ #if defined(__TURBOC__) || defined(__BORLANDC__) || defined(__DJGPP__) #include #endif -#if defined( _MSC_VER ) +#if defined(_MSC_VER) #include #endif #ifndef HARBOUR_STRICT_CLIPPER_COMPATIBILITY diff --git a/harbour/source/rtl/descend.c b/harbour/source/rtl/descend.c index e73cc3cd8b..6279451bff 100644 --- a/harbour/source/rtl/descend.c +++ b/harbour/source/rtl/descend.c @@ -67,7 +67,7 @@ char * hb_strDescend( char * szText, ULONG ulLen ) { - if (!(ulLen == 1 && szText[0] == '\0')) + if( ! ( ulLen == 1 && szText[ 0 ] == '\0' ) ) { char *s; @@ -82,7 +82,7 @@ HARBOUR HB_DESCEND( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pItem = hb_param(1, IT_ANY ); + PHB_ITEM pItem = hb_param( 1, IT_ANY ); if( pItem ) { @@ -95,12 +95,12 @@ HARBOUR HB_DESCEND( void ) PHB_ITEM pReturn; double dValue; - if ( IS_DOUBLE( pItem ) ) - dValue = (double)pItem->item.asDouble.value; + if( IS_DOUBLE( pItem ) ) + dValue = pItem->item.asDouble.value; else if( IS_INTEGER( pItem ) ) - dValue = (double)pItem->item.asInteger.value; + dValue = ( double ) pItem->item.asInteger.value; else if( IS_LONG( pItem ) ) - dValue = pItem->item.asLong.value; + dValue = ( double ) pItem->item.asLong.value; pReturn = hb_itemPutND( NULL, -1 * dValue ); hb_itemReturn( pReturn ); @@ -111,7 +111,7 @@ HARBOUR HB_DESCEND( void ) */ } else if( IS_LOGICAL( pItem ) ) - hb_retl( !pItem->item.asLogical.value ); + hb_retl( ! pItem->item.asLogical.value ); } } } diff --git a/harbour/source/rtl/dir.c b/harbour/source/rtl/dir.c index 12544f7ed1..8a08f12b26 100644 --- a/harbour/source/rtl/dir.c +++ b/harbour/source/rtl/dir.c @@ -47,7 +47,7 @@ #include #endif -#if defined(__WATCOMC__) || defined( _MSC_VER ) +#if defined(__WATCOMC__) || defined(_MSC_VER) #include #include #include @@ -262,13 +262,13 @@ HARBOUR HB_DIRECTORY( void ) { strcpy(string,entry.achName); #else - #if defined( __WATCOMC__ ) + #if defined(__WATCOMC__) /* opendir in Watcom doesn't like the path delimiter at the end of a string */ dirname[ iDirnameLen ] ='.'; dirname[ iDirnameLen+1 ] ='\x0'; #endif dir = opendir( dirname ); - #if defined( __WATCOMC__ ) + #if defined(__WATCOMC__) dirname[ iDirnameLen ] ='\x0'; #endif if (NULL == dir) diff --git a/harbour/source/rtl/extend.c b/harbour/source/rtl/extend.c index f6dfe7a5cc..95ff1fb6d4 100644 --- a/harbour/source/rtl/extend.c +++ b/harbour/source/rtl/extend.c @@ -29,15 +29,13 @@ PHB_ITEM hb_param( int iParam, WORD wMask ) { - WORD wType; - PHB_ITEM pLocal; - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pLocal; + WORD wType; + if( iParam == -1 ) wType = stack.Return.type; - else if( iParam < -1 ) - return NULL; else wType = ( stack.pBase + 1 + iParam )->type; @@ -45,8 +43,6 @@ PHB_ITEM hb_param( int iParam, WORD wMask ) { if( iParam == -1 ) pLocal = &stack.Return; - else if( iParam < -1 ) - return NULL; else pLocal = stack.pBase + 1 + iParam; @@ -55,85 +51,75 @@ PHB_ITEM hb_param( int iParam, WORD wMask ) else return pLocal; } - else - return NULL; } + return NULL; } char * hb_parc( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return ""; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) - { - if( wArrayIndex ) - return hb_arrayGetString( pItem, wArrayIndex ); - else - return ""; - } - else if( IS_STRING( pItem ) ) + if( IS_STRING( pItem ) ) return pItem->item.asString.value; - else - return ""; + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + return hb_arrayGetString( pItem, ulArrayIndex ); + } } + return ""; } ULONG hb_parclen( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return 0; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) - { - if( wArrayIndex ) - return hb_arrayGetStringLen( pItem, wArrayIndex ); - else - return 0; - } - else if( IS_STRING( pItem ) ) + if( IS_STRING( pItem ) ) return pItem->item.asString.length; + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; - else - return 0; + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + return hb_arrayGetStringLen( pItem, ulArrayIndex ); + } } + return 0; } @@ -142,279 +128,265 @@ ULONG hb_parclen( int iParam, ... ) ULONG hb_parcsiz( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return 0; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) - { - if( wArrayIndex ) - return hb_arrayGetStringLen( pItem, wArrayIndex ) + 1; - else - return 0; - } - else if( IS_STRING( pItem ) ) + if( IS_STRING( pItem ) ) return pItem->item.asString.length + 1; + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; - else - return 0; + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + return hb_arrayGetStringLen( pItem, ulArrayIndex ) + 1; + } } + return 0; } char * hb_pards( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return " "; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) + if( IS_DATE( pItem ) ) { - if( wArrayIndex ) + if ( pItem->item.asDate.value > 0 ) { - hb_arrayGetDate( pItem, wArrayIndex, stack.szDate ); + long lDay, lMonth, lYear; + + hb_dateDecode( pItem->item.asDate.value, &lDay, &lMonth, &lYear ); + hb_dateStrPut( stack.szDate, lDay, lMonth, lYear ); stack.szDate[ 8 ] = '\0'; - return stack.szDate; + return stack.szDate; /* this guaranties good behavior when multithreading */ } - else - return " "; } - else if( IS_DATE( pItem ) && pItem->item.asDate.value > 0 ) + else if( IS_ARRAY( pItem ) ) { - long lDay, lMonth, lYear; + va_list va; + ULONG ulArrayIndex; - hb_dateDecode( pItem->item.asDate.value, &lDay, &lMonth, &lYear ); - hb_dateStrPut( stack.szDate, lDay, lMonth, lYear ); - stack.szDate[ 8 ] = '\0'; + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); - return stack.szDate; /* this guaranties good behavior when multithreading */ + if ( ulArrayIndex != 0 ) + { + hb_arrayGetDate( pItem, ulArrayIndex, stack.szDate ); + stack.szDate[ 8 ] = '\0'; + + return stack.szDate; /* this guaranties good behavior when multithreading */ + } } - else - return " "; } + return " "; } int hb_parl( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return 0; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) - { - if( wArrayIndex ) - return hb_arrayGetBool( pItem, wArrayIndex ) ? 1 : 0; - else - return 0; - } - - else if( IS_LOGICAL( pItem ) ) + if( IS_LOGICAL( pItem ) ) return pItem->item.asLogical.value ? 1 : 0; - else - return 0; + else if( IS_INTEGER( pItem ) ) + return pItem->item.asInteger.value != 0 ? 1 : 0; + + else if( IS_LONG( pItem ) ) + return pItem->item.asLong.value != 0 ? 1 : 0; + + else if( IS_DOUBLE( pItem ) ) + return pItem->item.asDouble.value != 0.0 ? 1 : 0; + + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + return hb_arrayGetBool( pItem, ulArrayIndex ) ? 1 : 0; + } } + return 0; } double hb_parnd( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return 0; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) - { - if( wArrayIndex ) - return hb_arrayGetDouble( pItem, wArrayIndex ); - else - return 0; - } - else if( IS_INTEGER( pItem ) ) - return pItem->item.asInteger.value; - - else if( IS_LONG( pItem ) ) - return pItem->item.asLong.value; - - else if( IS_DOUBLE( pItem ) ) + if( IS_DOUBLE( pItem ) ) return pItem->item.asDouble.value; - else - return 0; + else if( IS_INTEGER( pItem ) ) + return ( double ) pItem->item.asInteger.value; + + else if( IS_LONG( pItem ) ) + return ( double ) pItem->item.asLong.value; + + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + return hb_arrayGetDouble( pItem, ulArrayIndex ); + } } + return 0; } int hb_parni( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return 0; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) - { - if( wArrayIndex ) - return (long) hb_arrayGetDouble( pItem, wArrayIndex ); - else - return 0; - } - - else if( IS_INTEGER( pItem ) ) + if( IS_INTEGER( pItem ) ) return pItem->item.asInteger.value; else if( IS_LONG( pItem ) ) - return pItem->item.asLong.value; + return ( int ) pItem->item.asLong.value; else if( IS_DOUBLE( pItem ) ) - return pItem->item.asDouble.value; + return ( int ) pItem->item.asDouble.value; - else - return 0; + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + return ( int ) hb_arrayGetDouble( pItem, ulArrayIndex ); + } } + return 0; } long hb_parnl( int iParam, ... ) { - PHB_ITEM pItem; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem; + if( iParam == -1 ) pItem = &stack.Return; - else if( iParam < -1 ) - return 0; else pItem = stack.pBase + 1 + iParam; if( IS_BYREF( pItem ) ) pItem = hb_itemUnRef( pItem ); - if( IS_ARRAY( pItem ) ) - { - if( wArrayIndex ) - return (long) hb_arrayGetDouble( pItem, wArrayIndex ); - else - return 0; - } - - else if( IS_INTEGER( pItem ) ) - return (long) pItem->item.asInteger.value; - - else if( IS_LONG( pItem ) ) + if( IS_LONG( pItem ) ) return pItem->item.asLong.value; - else if( IS_DOUBLE( pItem ) ) - return (long) pItem->item.asDouble.value; + else if( IS_INTEGER( pItem ) ) + return ( long ) pItem->item.asInteger.value; - else - return 0; + else if( IS_DOUBLE( pItem ) ) + return ( long ) pItem->item.asDouble.value; + + else if( IS_DATE( pItem ) ) + return pItem->item.asDate.value; + + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + return ( long ) hb_arrayGetDouble( pItem, ulArrayIndex ); + } } + return 0; } - ULONG hb_parinfa( int iParamNum, ULONG uiArrayIndex ) { PHB_ITEM pArray = hb_param( iParamNum, IT_ARRAY ); if( pArray ) { - if( ! uiArrayIndex ) + if( uiArrayIndex == 0 ) return hb_arrayLen( pArray ); else - return (long) hb_arrayGetType( pArray, uiArrayIndex ); + return ( long ) hb_arrayGetType( pArray, uiArrayIndex ); } else - return 0; /* QUESTION: should we raise an error here ? */ + return 0; } WORD hb_parinfo( int iParam ) @@ -423,12 +395,10 @@ WORD hb_parinfo( int iParam ) return stack.pBase->item.asSymbol.paramcnt; else { - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { if( iParam == -1 ) return stack.Return.type; - else if( iParam < -1 ) - return 0; else return ( stack.pBase + 1 + iParam )->type; } @@ -437,8 +407,6 @@ WORD hb_parinfo( int iParam ) } } - - WORD hb_pcount( void ) { return stack.pBase->item.asSymbol.paramcnt; @@ -459,7 +427,7 @@ void hb_retc( char * szText ) ULONG ulLen = strlen( szText ); hb_itemClear( &stack.Return ); - stack.Return.type = IT_STRING; + stack.Return.type = IT_STRING; stack.Return.item.asString.length = ulLen; stack.Return.item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); strcpy( stack.Return.item.asString.value, szText ); @@ -468,7 +436,7 @@ void hb_retc( char * szText ) void hb_retclen( char * szText, ULONG ulLen ) { hb_itemClear( &stack.Return ); - stack.Return.type = IT_STRING; + stack.Return.type = IT_STRING; stack.Return.item.asString.length = ulLen; stack.Return.item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); memcpy( stack.Return.item.asString.value, szText, ulLen ); @@ -483,7 +451,7 @@ void hb_retds( char * szDate ) /* szDate must have yyyymmdd format */ hb_itemClear( &stack.Return ); - stack.Return.type = IT_DATE; + stack.Return.type = IT_DATE; /* QUESTION: Is this ok ? we are going to use a long to store the date */ /* QUESTION: What happens if we use sizeof( LONG ) instead ? */ /* QUESTION: Would it break Clipper language code ? */ @@ -493,7 +461,7 @@ void hb_retds( char * szDate ) /* szDate must have yyyymmdd format */ void hb_retnd( double dNumber ) { hb_itemClear( &stack.Return ); - stack.Return.type = IT_DOUBLE; + stack.Return.type = IT_DOUBLE; if( dNumber > 10000000000.0 ) stack.Return.item.asDouble.length = 20; else @@ -527,17 +495,11 @@ void hb_retnl( long lNumber ) void hb_storc( char * szText, int iParam, ... ) { - PHB_ITEM pItem, pItemRef; - va_list va; - WORD wArrayIndex; - ULONG ulLen; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, long ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem, pItemRef; + ULONG ulLen; + if( iParam == -1 ) { pItem = &stack.Return; @@ -548,23 +510,10 @@ void hb_storc( char * szText, int iParam, ... ) pItem->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); strcpy( pItem->item.asString.value, szText ); } - else if( iParam < -1 ) - return; else pItem = stack.pBase + 1 + iParam; - if( IS_ARRAY( pItem ) && wArrayIndex ) - { - ulLen = strlen( szText ); - pItemRef = hb_itemNew( NULL ); - pItemRef->type = IT_STRING; - pItemRef->item.asString.length = ulLen; - pItemRef->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); - strcpy( pItemRef->item.asString.value, szText ); - hb_arraySet( pItem, wArrayIndex, pItemRef ); - hb_itemRelease( pItemRef ); - } - else if( IS_BYREF( pItem ) ) + if( IS_BYREF( pItem ) ) { ulLen = strlen( szText ); pItemRef = hb_itemUnRef( pItem ); @@ -574,70 +523,86 @@ void hb_storc( char * szText, int iParam, ... ) pItemRef->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); strcpy( pItemRef->item.asString.value, szText ); } + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + { + ulLen = strlen( szText ); + pItemRef = hb_itemNew( NULL ); + pItemRef->type = IT_STRING; + pItemRef->item.asString.length = ulLen; + pItemRef->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); + strcpy( pItemRef->item.asString.value, szText ); + hb_arraySet( pItem, ulArrayIndex, pItemRef ); + hb_itemRelease( pItemRef ); + } + } } } -void hb_storclen( char * fixText, WORD wLength, int iParam, ... ) +void hb_storclen( char * fixText, ULONG ulLen, int iParam, ... ) { - PHB_ITEM pItem, pItemRef; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, long ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem, pItemRef; + if( iParam == -1 ) { pItem = &stack.Return; hb_itemClear( pItem ); pItem->type = IT_STRING; - pItem->item.asString.length = wLength; - pItem->item.asString.value = ( char * ) hb_xgrab( wLength + 1 ); - memcpy( pItem->item.asString.value, fixText, wLength ); - pItem->item.asString.value[ wLength ] = '\0'; + pItem->item.asString.length = ulLen; + pItem->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); + memcpy( pItem->item.asString.value, fixText, ulLen ); + pItem->item.asString.value[ ulLen ] = '\0'; } - else if( iParam < -1 ) - return; else pItem = stack.pBase + 1 + iParam; - if( IS_ARRAY( pItem ) && wArrayIndex ) - { - pItemRef = hb_itemNew( NULL ); - pItemRef->type = IT_STRING; - pItemRef->item.asString.length = wLength; - pItemRef->item.asString.value = ( char * ) hb_xgrab( wLength + 1 ); - memcpy( pItemRef->item.asString.value, fixText, wLength ); - pItemRef->item.asString.value[ wLength ] = '\0'; - hb_arraySet( pItem, wArrayIndex, pItemRef ); - hb_itemRelease( pItemRef ); - } - else if( IS_BYREF( pItem ) ) + if( IS_BYREF( pItem ) ) { pItemRef = hb_itemUnRef( pItem ); hb_itemClear( pItemRef ); pItemRef->type = IT_STRING; - pItemRef->item.asString.length = wLength; - pItemRef->item.asString.value = ( char * ) hb_xgrab( wLength + 1 ); - memcpy( pItemRef->item.asString.value, fixText, wLength ); - pItemRef->item.asString.value[ wLength ] = '\0'; + pItemRef->item.asString.length = ulLen; + pItemRef->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); + memcpy( pItemRef->item.asString.value, fixText, ulLen ); + pItemRef->item.asString.value[ ulLen ] = '\0'; + } + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + { + pItemRef = hb_itemNew( NULL ); + pItemRef->type = IT_STRING; + pItemRef->item.asString.length = ulLen; + pItemRef->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); + memcpy( pItemRef->item.asString.value, fixText, ulLen ); + pItemRef->item.asString.value[ ulLen ] = '\0'; + hb_arraySet( pItem, ulArrayIndex, pItemRef ); + hb_itemRelease( pItemRef ); + } } } } void hb_stords( char * szDate, int iParam, ... ) /* szDate must have yyyymmdd format */ { - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { PHB_ITEM pItem, pItemRef; long lDay, lMonth, lYear; @@ -651,41 +616,43 @@ void hb_stords( char * szDate, int iParam, ... ) /* szDate must have yyyymmdd fo pItem->type = IT_DATE; pItem->item.asDate.value = hb_dateEncode( lDay, lMonth, lYear ); } - else if( iParam < -1 ) - return; else pItem = stack.pBase + 1 + iParam; - if( IS_ARRAY( pItem ) && wArrayIndex ) - { - pItemRef = hb_itemNew( NULL ); - pItemRef->type = IT_DATE; - pItemRef->item.asDate.value = hb_dateEncode( lDay, lMonth, lYear ); - hb_arraySet( pItem, wArrayIndex, pItemRef ); - hb_itemRelease( pItemRef ); - } - else if( IS_BYREF( pItem ) ) + if( IS_BYREF( pItem ) ) { pItemRef = hb_itemUnRef( pItem ); hb_itemClear( pItemRef ); pItemRef->type = IT_DATE; pItemRef->item.asDate.value = hb_dateEncode( lDay, lMonth, lYear ); } + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + { + pItemRef = hb_itemNew( NULL ); + pItemRef->type = IT_DATE; + pItemRef->item.asDate.value = hb_dateEncode( lDay, lMonth, lYear ); + hb_arraySet( pItem, ulArrayIndex, pItemRef ); + hb_itemRelease( pItemRef ); + } + } } } void hb_storl( int iLogical, int iParam, ... ) { - PHB_ITEM pItem, pItemRef; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem, pItemRef; + if( iParam == -1 ) { pItem = &stack.Return; @@ -693,41 +660,43 @@ void hb_storl( int iLogical, int iParam, ... ) pItem->type = IT_LOGICAL; pItem->item.asLogical.value = iLogical ? TRUE : FALSE; } - else if( iParam < -1 ) - return; else pItem = stack.pBase + 1 + iParam; - if( IS_ARRAY( pItem ) && wArrayIndex ) - { - pItemRef = hb_itemNew( NULL ); - pItemRef->type = IT_LOGICAL; - pItemRef->item.asLogical.value = iLogical ? TRUE : FALSE; - hb_arraySet( pItem, wArrayIndex, pItemRef ); - hb_itemRelease( pItemRef ); - } - else if( IS_BYREF( pItem ) ) + if( IS_BYREF( pItem ) ) { pItemRef = hb_itemUnRef( pItem ); hb_itemClear( pItemRef ); pItemRef->type = IT_LOGICAL; pItemRef->item.asLogical.value = iLogical ? TRUE : FALSE; } + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + { + pItemRef = hb_itemNew( NULL ); + pItemRef->type = IT_LOGICAL; + pItemRef->item.asLogical.value = iLogical ? TRUE : FALSE; + hb_arraySet( pItem, ulArrayIndex, pItemRef ); + hb_itemRelease( pItemRef ); + } + } } } void hb_storni( int iValue, int iParam, ... ) { - PHB_ITEM pItem, pItemRef; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, int ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem, pItemRef; + if( iParam == -1 ) { pItem = &stack.Return; @@ -736,21 +705,10 @@ void hb_storni( int iValue, int iParam, ... ) pItem->item.asInteger.length = 10; pItem->item.asInteger.value = iValue; } - else if( iParam < -1 ) - return; else pItem = stack.pBase + 1 + iParam; - if( IS_ARRAY( pItem ) && wArrayIndex ) - { - pItemRef = hb_itemNew( NULL ); - pItemRef->type = IT_INTEGER; - pItemRef->item.asInteger.length = 10; - pItemRef->item.asInteger.value = iValue; - hb_arraySet( pItem, wArrayIndex, pItemRef ); - hb_itemRelease( pItemRef ); - } - else if( IS_BYREF( pItem ) ) + if( IS_BYREF( pItem ) ) { pItemRef = hb_itemUnRef( pItem ); hb_itemClear( pItemRef ); @@ -758,21 +716,34 @@ void hb_storni( int iValue, int iParam, ... ) pItemRef->item.asInteger.length = 10; pItemRef->item.asInteger.value = iValue; } + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + { + pItemRef = hb_itemNew( NULL ); + pItemRef->type = IT_INTEGER; + pItemRef->item.asInteger.length = 10; + pItemRef->item.asInteger.value = iValue; + hb_arraySet( pItem, ulArrayIndex, pItemRef ); + hb_itemRelease( pItemRef ); + } + } } } void hb_stornl( long lValue, int iParam, ... ) { - PHB_ITEM pItem, pItemRef; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, long ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem, pItemRef; + if( iParam == -1 ) { pItem = &stack.Return; @@ -781,21 +752,10 @@ void hb_stornl( long lValue, int iParam, ... ) pItem->item.asLong.length = 10; pItem->item.asLong.value = lValue; } - else if( iParam < -1 ) - return; else pItem = stack.pBase + 1 + iParam; - if( IS_ARRAY( pItem ) && wArrayIndex ) - { - pItemRef = hb_itemNew( NULL ); - pItemRef->type = IT_LONG; - pItemRef->item.asLong.length = 10; - pItemRef->item.asLong.value = lValue; - hb_arraySet( pItem, wArrayIndex, pItemRef ); - hb_itemRelease( pItemRef ); - } - else if( IS_BYREF( pItem ) ) + if( IS_BYREF( pItem ) ) { pItemRef = hb_itemUnRef( pItem ); hb_itemClear( pItemRef ); @@ -803,21 +763,34 @@ void hb_stornl( long lValue, int iParam, ... ) pItemRef->item.asLong.length = 10; pItemRef->item.asLong.value = lValue; } + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + { + pItemRef = hb_itemNew( NULL ); + pItemRef->type = IT_LONG; + pItemRef->item.asLong.length = 10; + pItemRef->item.asLong.value = lValue; + hb_arraySet( pItem, ulArrayIndex, pItemRef ); + hb_itemRelease( pItemRef ); + } + } } } void hb_stornd( double dValue, int iParam, ... ) { - PHB_ITEM pItem, pItemRef; - va_list va; - WORD wArrayIndex; - - va_start( va, iParam ); - wArrayIndex = va_arg( va, long ); - va_end( va ); - - if( ( iParam <= hb_pcount() ) || ( iParam == -1 ) ) + if( ( iParam > 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) { + PHB_ITEM pItem, pItemRef; + if( iParam == -1 ) { pItem = &stack.Return; @@ -830,25 +803,10 @@ void hb_stornd( double dValue, int iParam, ... ) pItem->item.asDouble.decimal = hb_set.HB_SET_DECIMALS; pItem->item.asDouble.value = dValue; } - else if( iParam < -1 ) - return; else pItem = stack.pBase + 1 + iParam; - if( IS_ARRAY( pItem ) && wArrayIndex ) - { - pItemRef = hb_itemNew( NULL ); - pItemRef->type = IT_DOUBLE; - if( dValue > 10000000000.0 ) - pItemRef->item.asDouble.length = 20; - else - pItemRef->item.asDouble.length = 10; - pItemRef->item.asDouble.decimal = hb_set.HB_SET_DECIMALS; - pItemRef->item.asDouble.value = dValue; - hb_arraySet( pItem, wArrayIndex, pItemRef ); - hb_itemRelease( pItemRef ); - } - else if( IS_BYREF( pItem ) ) + if( IS_BYREF( pItem ) ) { pItemRef = hb_itemUnRef( pItem ); hb_itemClear( pItemRef ); @@ -860,6 +818,29 @@ void hb_stornd( double dValue, int iParam, ... ) pItemRef->item.asDouble.decimal = hb_set.HB_SET_DECIMALS; pItemRef->item.asDouble.value = dValue; } + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, long ); + va_end( va ); + + if ( ulArrayIndex != 0 ) + { + pItemRef = hb_itemNew( NULL ); + pItemRef->type = IT_DOUBLE; + if( dValue > 10000000000.0 ) + pItemRef->item.asDouble.length = 20; + else + pItemRef->item.asDouble.length = 10; + pItemRef->item.asDouble.decimal = hb_set.HB_SET_DECIMALS; + pItemRef->item.asDouble.value = dValue; + hb_arraySet( pItem, ulArrayIndex, pItemRef ); + hb_itemRelease( pItemRef ); + } + } } } diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 73d8e102cf..8739fd1c27 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -8,53 +8,53 @@ #include "errorapi.h" #if defined(__CYGWIN__) - #include + #include #endif #if defined(__GNUC__) - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include - #if !defined(HAVE_POSIX_IO) - #define HAVE_POSIX_IO - #endif + #if !defined(HAVE_POSIX_IO) + #define HAVE_POSIX_IO + #endif #endif #if defined(__WATCOMC__) - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include - #if !defined(HAVE_POSIX_IO) - #define HAVE_POSIX_IO - #endif + #if !defined(HAVE_POSIX_IO) + #define HAVE_POSIX_IO + #endif #endif #if defined(__BORLANDC__) || defined(__IBMCPP__) || defined(_MSC_VER) - #include - #include - #include - #include - #if defined(__IBMCPP__) || defined(_MSC_VER) - #include - #else - #include - #endif + #include + #include + #include + #include + #if defined(__IBMCPP__) || defined(_MSC_VER) + #include + #else + #include + #endif - #if defined(_MSC_VER) - #include - #else - #if !defined(HAVE_POSIX_IO) - #define HAVE_POSIX_IO - #endif - #endif - #include + #if defined(_MSC_VER) + #include + #else + #if !defined(HAVE_POSIX_IO) + #define HAVE_POSIX_IO + #endif + #endif + #include #endif #ifdef __MPW__ @@ -62,57 +62,54 @@ #endif #ifndef O_BINARY - #define O_BINARY 0 /* O_BINARY not defined on Linux */ + #define O_BINARY 0 /* O_BINARY not defined on Linux */ #endif #ifndef S_IEXEC -#define S_IEXEC 0x0040 /* owner may execute */ + #define S_IEXEC 0x0040 /* owner may execute */ #endif #ifndef S_IRWXU -#define S_IRWXU 0x01c0 /* RWE permissions mask for owner */ + #define S_IRWXU 0x01C0 /* RWE permissions mask for owner */ #endif #ifndef S_IRUSR -#define S_IRUSR 0x0100 /* owner may read */ + #define S_IRUSR 0x0100 /* owner may read */ #endif #ifndef S_IWUSR -#define S_IWUSR 0x0080 /* owner may write */ + #define S_IWUSR 0x0080 /* owner may write */ #endif #ifndef S_IXUSR -#define S_IXUSR 0x0040 /* owner may execute */ + #define S_IXUSR 0x0040 /* owner may execute */ #endif #ifndef SH_COMPAT -#define SH_COMPAT 0x00 /* Compatibility */ + #define SH_COMPAT 0x00 /* Compatibility */ #endif #ifndef SH_DENYRW -#define SH_DENYRW 0x10 /* Deny read/write */ + #define SH_DENYRW 0x10 /* Deny read/write */ #endif #ifndef SH_DENYWR -#define SH_DENYWR 0x20 /* Deny write */ + #define SH_DENYWR 0x20 /* Deny write */ #endif #ifndef SH_DENYRD -#define SH_DENYRD 0x30 /* Deny read */ + #define SH_DENYRD 0x30 /* Deny read */ #endif #ifndef SH_DENYNO -#define SH_DENYNO 0x40 /* Deny nothing */ + #define SH_DENYNO 0x40 /* Deny nothing */ #endif - -#define IT_NUMBER (IT_INTEGER|IT_LONG|IT_DOUBLE) - -static USHORT last_error = 0; +static USHORT s_uiErrorLast = 0; #if !defined(PATH_MAX) /* if PATH_MAX isn't defined, 256 bytes is a good number :) */ -#define PATH_MAX 256 + #define PATH_MAX 256 #endif #define MKLONG(_1,_2,_3,_4) (((long)_4)<<24)|(((long)_3)<<16)|(((long)_2)<<8)|_1 @@ -124,73 +121,73 @@ extern int rename( const char *, const char * ); #if defined(HAVE_POSIX_IO) || defined(_MSC_VER) -static int convert_open_flags( int flags ) +static int convert_open_flags( USHORT uiFlags ) { - /* by default FO_READ+FO_COMPAT is set */ - int result_flags = 0; + /* by default FO_READ + FO_COMPAT is set */ + int result_flags = 0; - result_flags |= O_BINARY; + result_flags |= O_BINARY; - if( flags == 0 ) - result_flags |= O_RDONLY|SH_COMPAT; + if( uiFlags == 0 ) + result_flags |= O_RDONLY | SH_COMPAT; - /* read & write flags */ - if( flags & FO_WRITE ) - result_flags |= O_WRONLY; + /* read & write flags */ + if( uiFlags & FO_WRITE ) + result_flags |= O_WRONLY; - if( flags & FO_READWRITE ) - result_flags |= O_RDWR; + if( uiFlags & FO_READWRITE ) + result_flags |= O_RDWR; - /* shared flags */ - if( flags & FO_EXCLUSIVE ) - result_flags |= SH_DENYRW; + /* shared flags */ + if( uiFlags & FO_EXCLUSIVE ) + result_flags |= SH_DENYRW; - if( flags & FO_DENYWRITE ) - result_flags |= SH_DENYWR; + if( uiFlags & FO_DENYWRITE ) + result_flags |= SH_DENYWR; - if( flags & FO_DENYREAD ) - result_flags |= SH_DENYRD; + if( uiFlags & FO_DENYREAD ) + result_flags |= SH_DENYRD; - if( flags & FO_DENYNONE ) - result_flags |= SH_DENYNO; + if( uiFlags & FO_DENYNONE ) + result_flags |= SH_DENYNO; - if( flags & FO_SHARED ) - result_flags |= SH_DENYNO; + if( uiFlags & FO_SHARED ) + result_flags |= SH_DENYNO; - return result_flags; + return result_flags; } -static int convert_seek_flags( int flags ) +static int convert_seek_flags( USHORT uiFlags ) { - /* by default FS_SET is set */ - int result_flags=0; + /* by default FS_SET is set */ + int result_flags = 0; - result_flags = SEEK_SET; + result_flags = SEEK_SET; - if( flags & FS_RELATIVE ) - result_flags = SEEK_CUR; + if( uiFlags & FS_RELATIVE ) + result_flags = SEEK_CUR; - if( flags & FS_END ) - result_flags = SEEK_END; + if( uiFlags & FS_END ) + result_flags = SEEK_END; - return result_flags; + return result_flags; } -static void convert_create_flags( int flags, int *result_flags, unsigned *result_pmode ) +static void convert_create_flags( USHORT uiFlags, int * result_flags, unsigned * result_pmode ) { - /* by default FC_NORMAL is set */ + /* by default FC_NORMAL is set */ - *result_flags = O_BINARY | O_CREAT | O_TRUNC | O_RDWR; - *result_pmode = S_IRUSR | S_IWUSR; + *result_flags = O_BINARY | O_CREAT | O_TRUNC | O_RDWR; + *result_pmode = S_IRUSR | S_IWUSR; - if( flags & FC_READONLY ) - *result_pmode = S_IRUSR; + if( uiFlags & FC_READONLY ) + *result_pmode = S_IRUSR; - if( flags & FC_HIDDEN ) - *result_flags |= 0; + if( uiFlags & FC_HIDDEN ) + *result_flags |= 0; - if( flags & FC_SYSTEM ) - *result_flags |= 0; + if( uiFlags & FC_SYSTEM ) + *result_flags |= 0; } #endif @@ -200,338 +197,489 @@ static void convert_create_flags( int flags, int *result_flags, unsigned *result * FILESYS.API FUNCTIONS -- */ -FHANDLE hb_fsOpen ( BYTE * name, USHORT flags ) +FHANDLE hb_fsOpen ( BYTE * pFilename, USHORT uiFlags ) { - FHANDLE handle; -#if defined(HAVE_POSIX_IO) - errno = 0; - handle = open((char *)name,convert_open_flags(flags)); - last_error = errno; -#else - #if defined( _MSC_VER ) - errno = 0; - handle = _open( ( char * ) name, convert_open_flags( flags ) ); - last_error = errno; - #else - handle = FS_ERROR; - last_error = FS_ERROR; - #endif -#endif - return handle; -} - -FHANDLE hb_fsCreate ( BYTE * name, USHORT flags ) -{ - FHANDLE handle; - int oflag; - unsigned pmode; + FHANDLE hFileHandle; #if defined(HAVE_POSIX_IO) - errno = 0; - convert_create_flags( flags, &oflag, &pmode ); - handle = open((char *)name,oflag,pmode); - if( handle == FS_ERROR) - { - /* This if block is required, because errno will be set - if the file did not exist and had to be created, even - when the create is successful! */ - last_error = errno; - } + + errno = 0; + hFileHandle = open( ( char * ) pFilename, convert_open_flags( uiFlags ) ); + s_uiErrorLast = errno; + #else - #if defined( _MSC_VER ) - errno = 0; - convert_create_flags( flags, &oflag, &pmode ); - handle = _open( ( char * ) name, oflag, pmode ); - if( handle == FS_ERROR ) - { - /* This if block is required, because errno will be set - if the file did not exist and had to be created, even - when the create is successful! */ - last_error = errno; - } - #else - handle = FS_ERROR; - last_error = FS_ERROR; - #endif + + #if defined(_MSC_VER) + + errno = 0; + hFileHandle = _open( ( char * ) pFilename, convert_open_flags( uiFlags ) ); + s_uiErrorLast = errno; + + #else + + hFileHandle = FS_ERROR; + s_uiErrorLast = FS_ERROR; + + #endif + #endif - return handle; + + return hFileHandle; } -void hb_fsClose ( FHANDLE handle ) +FHANDLE hb_fsCreate ( BYTE * pFilename, USHORT uiFlags ) { -#if defined( HAVE_POSIX_IO ) - close( handle ); - return; -#else - #if defined( _MSC_VER ) - _close( handle ); - return; - #endif -#endif -} + FHANDLE hFileHandle; + int oflag; + unsigned pmode; -USHORT hb_fsRead ( FHANDLE handle, BYTE * buff, USHORT count ) -{ - USHORT bytes; -#if defined( HAVE_POSIX_IO ) - errno = 0; - bytes = read( handle, buff, count ); - last_error = errno; - if( bytes == 65535U ) bytes = 0; -#else - #if defined( _MSC_VER ) - errno = 0; - bytes = _read( handle, buff, count ); - last_error = errno; - if( bytes == 65535U ) bytes = 0; - #else - bytes = 0; - last_error = FS_ERROR; - #endif -#endif - return bytes; -} + s_uiErrorLast = 0; -USHORT hb_fsWrite ( FHANDLE handle, BYTE * buff, USHORT count ) -{ - USHORT bytes; -#if defined( HAVE_POSIX_IO ) - errno = 0; - bytes = write( handle, buff, count ); - last_error = errno; -#else - #if defined( _MSC_VER ) - errno = 0; - bytes = _write( handle, buff, count ); - last_error = errno; - #else - bytes = 0; - last_error = FS_ERROR; - #endif -#endif - return bytes; -} - -ULONG hb_fsSeek ( FHANDLE handle, LONG offset, USHORT flags ) -{ - ULONG position; #if defined(HAVE_POSIX_IO) - errno = 0; - position = lseek( handle, offset, convert_seek_flags( flags ) ); - last_error = errno; + + errno = 0; + convert_create_flags( uiFlags, &oflag, &pmode ); + hFileHandle = open( ( char * ) pFilename, oflag, pmode ); + if( hFileHandle == -1 ) + { + /* This if block is required, because errno will be set + if the file did not exist and had to be created, even + when the create is successful! */ + s_uiErrorLast = errno; + } + #else - #if defined( _MSC_VER ) - errno = 0; - position = _lseek( handle, offset, convert_seek_flags( flags ) ); - last_error = errno; - #else - position = 0; - last_error = FS_ERROR; - #endif + + #if defined(_MSC_VER) + + errno = 0; + convert_create_flags( uiFlags, &oflag, &pmode ); + hFileHandle = _open( ( char * ) pFilename, oflag, pmode ); + if( hFileHandle == -1 ) + { + /* This if block is required, because errno will be set + if the file did not exist and had to be created, even + when the create is successful! */ + s_uiErrorLast = errno; + } + + #else + + hFileHandle = FS_ERROR; + s_uiErrorLast = FS_ERROR; + + #endif + #endif - return position; + + return hFileHandle; +} + +void hb_fsClose ( FHANDLE hFileHandle ) +{ +#if defined(HAVE_POSIX_IO) + + errno = 0; + close( hFileHandle ); + s_uiErrorLast = errno; + +#else + + #if defined(_MSC_VER) + + errno = 0; + _close( hFileHandle ); + s_uiErrorLast = errno; + + #else + + s_uiErrorLast = FS_ERROR; + + #endif + +#endif + +} + +USHORT hb_fsRead ( FHANDLE hFileHandle, BYTE * pBuff, USHORT uiCount ) +{ + USHORT uiRead; + +#if defined(HAVE_POSIX_IO) + + errno = 0; + uiRead = read( hFileHandle, pBuff, uiCount ); + s_uiErrorLast = errno; + if( uiRead == ( USHORT )-1 ) + uiRead = 0; + +#else + + #if defined(_MSC_VER) + + errno = 0; + uiRead = _read( hFileHandle, pBuff, uiCount ); + s_uiErrorLast = errno; + if( uiRead == ( USHORT )-1 ) + uiRead = 0; + + #else + + uiRead = 0; + s_uiErrorLast = FS_ERROR; + + #endif + +#endif + + return uiRead; +} + +USHORT hb_fsWrite ( FHANDLE hFileHandle, BYTE * pBuff, USHORT uiCount ) +{ + USHORT uiWritten; + +#if defined(HAVE_POSIX_IO) + + errno = 0; + uiWritten = write( hFileHandle, pBuff, uiCount ); + s_uiErrorLast = errno; + if( uiWritten == (USHORT)-1 ) + uiWritten = 0; + +#else + + #if defined(_MSC_VER) + + errno = 0; + uiWritten = _write( hFileHandle, pBuff, uiCount ); + s_uiErrorLast = errno; + if( uiWritten == (USHORT)-1 ) + uiWritten = 0; + + #else + + uiWritten = 0; + s_uiErrorLast = FS_ERROR; + + #endif + +#endif + + return uiWritten; +} + +ULONG hb_fsSeek ( FHANDLE hFileHandle, LONG lOffset, USHORT uiFlags ) +{ + ULONG ulPos; + +#if defined(HAVE_POSIX_IO) + + errno = 0; + ulPos = lseek( hFileHandle, lOffset, convert_seek_flags( uiFlags ) ); + s_uiErrorLast = errno; + +#else + + #if defined(_MSC_VER) + + errno = 0; + ulPos = _lseek( hFileHandle, lOffset, convert_seek_flags( uiFlags ) ); + s_uiErrorLast = errno; + + #else + + ulPos = 0; + s_uiErrorLast = FS_ERROR; + + #endif + +#endif + + return ulPos; } USHORT hb_fsError ( void ) { - return last_error; + return s_uiErrorLast; } -void hb_fsDelete ( BYTE * name ) +void hb_fsDelete ( BYTE * pFilename ) { #if defined(HAVE_POSIX_IO) - errno = 0; - unlink( ( char * ) name ); - last_error = errno; - return; + + errno = 0; + unlink( ( char * ) pFilename ); + s_uiErrorLast = errno; + #else - #if defined( _MSC_VER ) - errno = 0; - remove( ( char *) name ); - last_error = errno; - return; - #endif + + #if defined(_MSC_VER) + + errno = 0; + remove( ( char *) pFilename ); + s_uiErrorLast = errno; + + #else + + s_uiErrorLast = FS_ERROR; + + #endif + #endif } -void hb_fsRename ( BYTE * older, BYTE * newer ) +void hb_fsRename ( BYTE * pOldName, BYTE * pNewName ) { -#if defined(HAVE_POSIX_IO) || defined( _MSC_VER ) - errno = 0; - rename( ( char * ) older, ( char * ) newer ); - last_error = errno; - return; +#if defined(HAVE_POSIX_IO) || defined(_MSC_VER) + + errno = 0; + rename( ( char * ) pOldName, ( char * ) pNewName ); + s_uiErrorLast = errno; + +#else + + s_uiErrorLast = FS_ERROR; + #endif } -BOOL hb_fsLock ( FHANDLE handle, ULONG start, - ULONG length, USHORT mode ) +BOOL hb_fsLock ( FHANDLE hFileHandle, ULONG ulStart, + ULONG ulLength, USHORT uiMode ) { - int result=0; + int iResult = 0; #if defined(_MSC_VER) - ULONG position; + ULONG ulPos; #endif #if defined(HAVE_POSIX_IO) && !defined(__GNUC__) && !defined(__IBMCPP__) - errno = 0; - switch( mode ) - { - case FL_LOCK: - result = lock(handle, start, length); - break; - case FL_UNLOCK: - result = unlock(handle, start, length); - } - last_error = errno; + errno = 0; + switch( uiMode ) + { + case FL_LOCK: + iResult = lock( hFileHandle, ulStart, ulLength ); + break; + + case FL_UNLOCK: + iResult = unlock( hFileHandle, ulStart, ulLength ); + } + s_uiErrorLast = errno; + #else + #if defined(_MSC_VER) - position = hb_fsSeek( handle, start, 0 ); - result = locking( handle, mode?_LK_UNLCK:_LK_LOCK,length ); - hb_fsSeek( handle, position, 0 ); + + ulPos = hb_fsSeek( hFileHandle, ulStart, FS_SET ); + + switch( uiMode ) + { + case FL_LOCK: + iResult = locking( hFileHandle, _LK_LOCK, ulLength ); + break; + + case FL_UNLOCK: + iResult = locking( hFileHandle, _LK_UNLCK, ulLength ); + } + + hb_fsSeek( hFileHandle, ulPos, FS_SET ); + #else - result = 1; - last_error = FS_ERROR; + + iResult = 1; + s_uiErrorLast = FS_ERROR; + #endif + #endif - return (result ? FALSE : TRUE ); + + return ( iResult ? FALSE : TRUE ); } -void hb_fsCommit ( FHANDLE handle ) +void hb_fsCommit ( FHANDLE hFileHandle ) { #if defined(HAVE_POSIX_IO) - int dup_handle; - errno = 0; - dup_handle = dup(handle); - last_error = errno; - if (dup_handle != -1) - { - close(dup_handle); - last_error = errno; - } + int dup_handle; + + errno = 0; + dup_handle = dup( hFileHandle ); + s_uiErrorLast = errno; + + if( dup_handle != -1 ) + { + close( dup_handle ); + s_uiErrorLast = errno; + } + +#else + + s_uiErrorLast = FS_ERROR; #endif - return; } -BOOL hb_fsMkDir ( BYTE * name ) +BOOL hb_fsMkDir ( BYTE * pDirname ) { - int result; + int iResult; + #if defined(HAVE_POSIX_IO) - errno = 0; - #if !defined(__WATCOMC__) && !defined(__BORLANDC__) && !defined(__IBMCPP__) - result = mkdir( (char *)name, S_IWUSR|S_IRUSR); - #else - result = mkdir( (char *)name ); - #endif - last_error = errno; + + errno = 0; + + #if !defined(__WATCOMC__) && !defined(__BORLANDC__) && !defined(__IBMCPP__) + iResult = mkdir( ( char * ) pDirname, S_IWUSR | S_IRUSR ); + #else + iResult = mkdir( ( char * ) pDirname ); + #endif + + s_uiErrorLast = errno; + #else - result = 1; - last_error = FS_ERROR; + + iResult = 1; + s_uiErrorLast = FS_ERROR; + #endif - return (result ? FALSE : TRUE ); + + return ( iResult ? FALSE : TRUE ); } -BOOL hb_fsChDir ( BYTE * name ) +BOOL hb_fsChDir ( BYTE * pDirname ) { - int result; + int iResult; + #if defined(HAVE_POSIX_IO) - errno = 0; - result = chdir( (char *)name ); - last_error = errno; + + errno = 0; + iResult = chdir( ( char * ) pDirname ); + s_uiErrorLast = errno; + #else - result = 1; - last_error = FS_ERROR; + + iResult = 1; + s_uiErrorLast = FS_ERROR; + #endif - return (result ? FALSE : TRUE ); + + return ( iResult ? FALSE : TRUE ); } -BOOL hb_fsRmDir ( BYTE * name ) +BOOL hb_fsRmDir ( BYTE * pDirname ) { - int result; + int iResult; + #if defined(HAVE_POSIX_IO) - errno = 0; - result = rmdir( (char *)name ); - last_error = errno; + + errno = 0; + iResult = rmdir( ( char * ) pDirname ); + s_uiErrorLast = errno; + #else - result = 1; - last_error = FS_ERROR; + + iResult = 1; + s_uiErrorLast = FS_ERROR; + #endif - return (result ? FALSE : TRUE ); + + return ( iResult ? FALSE : TRUE ); } /* TODO: Make it thread safe */ BYTE * hb_fsCurDir ( USHORT uiDrive ) { - static char cwd_buff[PATH_MAX+1]; + static char cwd_buff[ PATH_MAX + 1 ]; + #if defined(HAVE_POSIX_IO) - errno = 0; - getcwd(cwd_buff,PATH_MAX); - last_error = errno; + + errno = 0; + getcwd( cwd_buff, PATH_MAX ); + s_uiErrorLast = errno; + #else - cwd_buff[0] = 0; - last_error = FS_ERROR; + + cwd_buff[ 0 ] = '\0'; + s_uiErrorLast = FS_ERROR; + #endif -#if defined(_MSC_VER) - BYTE * dmm = ( BYTE * )cwd_buff; -#endif - return ( BYTE * )cwd_buff; + + return ( BYTE * ) cwd_buff; } /* TODO: Implement nDrive */ USHORT hb_fsChDrv ( BYTE * nDrive ) { - USHORT result; + USHORT iResult; + #if defined(HAVE_POSIX_IO) - errno = 0; - result = 0; - last_error = errno; - last_error = FS_ERROR; /* TODO: Remove when function implemented */ + + errno = 0; + iResult = 0; + s_uiErrorLast = errno; + s_uiErrorLast = FS_ERROR; /* TODO: Remove when function implemented */ + #else - result = 0; - last_error = FS_ERROR; + + iResult = 0; + s_uiErrorLast = FS_ERROR; + #endif - return result; + + return iResult; } BYTE hb_fsCurDrv ( void ) { - USHORT result; + USHORT iResult; + #if defined(HAVE_POSIX_IO) - errno = 0; - result = 0; - last_error = errno; - last_error = FS_ERROR; /* TODO: Remove when function implemented */ + + errno = 0; + iResult = 0; + s_uiErrorLast = errno; + s_uiErrorLast = FS_ERROR; /* TODO: Remove when function implemented */ + #else - result = 0; - last_error = FS_ERROR; + + iResult = 0; + s_uiErrorLast = FS_ERROR; + #endif - return result; + + return iResult; } USHORT hb_fsIsDrv ( BYTE nDrive ) { - USHORT result; + USHORT iResult; + #if defined(HAVE_POSIX_IO) - errno = 0; - result = 0; - last_error = errno; - last_error = FS_ERROR; /* TODO: Remove when function implemented */ + + errno = 0; + iResult = 0; + s_uiErrorLast = errno; + s_uiErrorLast = FS_ERROR; /* TODO: Remove when function implemented */ + #else - result = 0; - last_error = FS_ERROR; + + iResult = 0; + s_uiErrorLast = FS_ERROR; + #endif - return result; + + return iResult; } /* TODO: Implement hb_fsExtOpen */ -FHANDLE hb_fsExtOpen( BYTE * fpFilename, BYTE * fpDefExt, - USHORT uiFlags, BYTE * fpPaths, PHB_ITEM pError ) +FHANDLE hb_fsExtOpen( BYTE * pFilename, BYTE * pDefExt, + USHORT uiFlags, BYTE * pPaths, PHB_ITEM pError ) { + + s_uiErrorLast = FS_ERROR; + return FS_ERROR; } @@ -541,216 +689,183 @@ FHANDLE hb_fsExtOpen( BYTE * fpFilename, BYTE * fpDefExt, HARBOUR HB_FOPEN( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_STRING); - PHB_ITEM arg2_it = hb_param(2,IT_NUMBER); - - int open_flags; - int file_handle = -1; - - if( arg1_it ) - { - if( arg2_it ) - open_flags = hb_parni(2); - else - open_flags = 0; - - file_handle = hb_fsOpen( ( BYTE * )hb_parc(1), open_flags ); - } - else - { - hb_errRT_BASE(EG_ARG, 3006, NULL, "FOPEN"); - } - - hb_retni(file_handle); - return; + if( ISCHAR( 1 ) ) + { + hb_retni( hb_fsOpen( ( BYTE * ) hb_parc( 1 ), + ISNUM( 2 ) ? hb_parni( 2 ) : FO_READ ) ); + } + else + { + /* NOTE: Undocumented but existing Clipper Run-time error */ + hb_errRT_BASE( EG_ARG, 2021, NULL, "FOPEN" ); + } } HARBOUR HB_FCREATE( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_STRING); - PHB_ITEM arg2_it = hb_param(2,IT_NUMBER); + FHANDLE hFileHandle; - int create_flags; - int file_handle = -1; + if( ISCHAR( 1 ) ) + hFileHandle = hb_fsCreate( ( BYTE * ) hb_parc( 1 ), + ISNUM( 2 ) ? hb_parni( 2 ) : FC_NORMAL ); + else + hFileHandle = FS_ERROR; - if( arg1_it ) - { - if( arg2_it ) - create_flags = hb_parni(2); - else - create_flags = 0; - - file_handle = hb_fsCreate( ( BYTE * )hb_parc(1), create_flags ); - } - - hb_retni(file_handle); - return; + hb_retni( hFileHandle ); } HARBOUR HB_FREAD( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_NUMBER); - PHB_ITEM arg2_it = hb_param(2,IT_STRING+IT_BYREF); - PHB_ITEM arg3_it = hb_param(3,IT_NUMBER); + ULONG ulRead = 0; - long bytes=0; + if( ISNUM( 1 ) && hb_param( 2, IT_STRING | IT_BYREF ) != NULL && ISNUM( 3 ) ) + { + ULONG ulToRead = hb_parnl( 3 ); - if( arg1_it && arg2_it && arg3_it ) - { - bytes = hb_fsRead(hb_parni(1), ( BYTE * )hb_parc(2), hb_parnl(3) ); - } + if( ulToRead <= hb_parclen( 2 ) ) + { + /* NOTE: Warning, the read buffer will be directly modified ! */ - hb_retnl(bytes); - return; + ulRead = hb_fsRead( hb_parni( 1 ), + hb_parc( 2 ), + ulToRead ); + } + else ulRead = (ULONG) -1; + } + else ulRead = (ULONG) -1; + + hb_retnl( ulRead ); } HARBOUR HB_FWRITE( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_NUMBER); - PHB_ITEM arg2_it = hb_param(2,IT_STRING); - PHB_ITEM arg3_it = hb_param(3,IT_NUMBER); + ULONG ulWritten; - long bytes=0; + if( ISNUM( 1 ) && ISCHAR( 2 ) ) + ulWritten = hb_fsWrite( hb_parni( 1 ), + ( BYTE * ) hb_parc( 2 ), + ISNUM( 3 ) ? hb_parnl( 3 ) : hb_parclen( 2 ) ); + else + ulWritten = 0; - if( arg1_it && arg2_it ) - { - bytes = (arg3_it ? hb_parnl(3) : hb_parclen( 2 ) ); - bytes = hb_fsWrite( hb_parni(1), ( BYTE * )hb_parc(2), bytes); - } - - hb_retnl(bytes); - return; + hb_retnl( ulWritten ); } HARBOUR HB_FERROR( void ) { - hb_retni(hb_fsError()); - return; + hb_retni( hb_fsError() ); } HARBOUR HB_FCLOSE( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_NUMBER); + s_uiErrorLast = 0; - last_error = 0; - if( arg1_it ) - { - hb_fsClose(hb_parni(1)); - } - hb_retl( last_error == 0 ); - return; + if( ISNUM( 1 ) ) + { + hb_fsClose( hb_parni( 1 ) ); + hb_retl( s_uiErrorLast == 0 ); + } + else + hb_retl( FALSE ); } HARBOUR HB_FERASE( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_STRING); + if( ISCHAR( 1 ) ) + { + hb_fsDelete( ( BYTE * ) hb_parc( 1 ) ); + } - if( arg1_it ) - { - hb_fsDelete( ( BYTE * )hb_parc(1) ); - } - - hb_retni(last_error=0); - return; + hb_retni( s_uiErrorLast ); } HARBOUR HB_FRENAME( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_STRING); - PHB_ITEM arg2_it = hb_param(2,IT_STRING); + if( ISCHAR( 1 ) && ISCHAR( 2 ) ) + { + hb_fsRename( ( BYTE * ) hb_parc( 1 ), + ( BYTE * ) hb_parc( 2 ) ); + } - if( arg1_it && arg2_it ) - { - hb_fsRename( ( BYTE * )hb_parc(1), ( BYTE * )hb_parc(2) ); - } - - hb_retni(last_error); - return; + hb_retni( s_uiErrorLast ); } HARBOUR HB_FSEEK( void ) { - PHB_ITEM arg1_it = hb_param(1,IT_NUMBER); - PHB_ITEM arg2_it = hb_param(2,IT_NUMBER); - PHB_ITEM arg3_it = hb_param(3,IT_NUMBER); + ULONG ulPos; - long bytes=0; - int pos; + if( ISNUM( 1 ) && ISNUM( 2 ) ) + ulPos = hb_fsSeek( hb_parni( 1 ), + hb_parnl( 2 ), + ISNUM( 3 ) ? hb_parni( 3 ) : FS_SET ); + else + ulPos = 0; - if( arg1_it && arg2_it ) - { - pos = (arg3_it ? hb_parni(3) : FS_SET); - bytes = hb_fsSeek(hb_parni(1),hb_parnl(2),pos); - } - - hb_retnl(bytes); - return; + hb_retnl( ulPos ); } HARBOUR HB_FILE( void ) { - PHB_ITEM arg1_it = hb_param( 1, IT_STRING ); + if( ISCHAR( 1 ) ) + { - if( arg1_it ) - { /*TODO: Check if F_OK is defined in all compilers */ #ifdef OS_UNIX_COMPATIBLE - hb_retl( access(hb_parc(1), F_OK) == 0 ); -#else - #ifdef __MPW__ - int hFileHandle; - if( (hFileHandle = open( hb_parc( 1 ), O_RDONLY )) >= 0 ) - { - close( hFileHandle ); - hb_retl( 1 ); - } - else hb_retl(0); - #else - hb_retl( access(hb_parc(1), 0) == 0 ); - #endif + hb_retl( access( hb_parc( 1 ), F_OK ) == 0 ); + +#else + + #ifdef __MPW__ + + int hFileHandle; + + if( ( hFileHandle = open( hb_parc( 1 ), O_RDONLY ) ) >= 0 ) + { + close( hFileHandle ); + hb_retl( TRUE ); + } + else + hb_retl( FALSE ); + + #else + + hb_retl( access( hb_parc( 1 ), 0 ) == 0 ); + + #endif + #endif - } - else hb_retl(0); - return; + + } + else + hb_retl( FALSE ); } HARBOUR HB_FREADSTR( void ) { - PHB_ITEM arg1_it = hb_param( 1, IT_NUMBER ); - PHB_ITEM arg2_it = hb_param( 2, IT_NUMBER ); + if( ISNUM( 1 ) && ISNUM( 2 ) ) + { + ULONG ulToRead = hb_parnl( 2 ); - int handle; - long bytes; - long nRead; - long readed; - char * buffer; - char ch[1]; + if( ulToRead > 0 ) + { + BYTE * buffer = ( BYTE * ) hb_xgrab( ulToRead + 1 ); + ULONG ulRead; - if( arg1_it ) - { - handle = hb_parni(1); - bytes = (arg2_it ? hb_parnl(2) : 0); - buffer = ( char * ) hb_xgrab(bytes + 1); + ulRead = hb_fsRead( ( FHANDLE ) hb_parni( 1 ), buffer, ulToRead ); - readed=0; ch[0]=1; - while( readed < bytes ) - { - nRead = read(handle,ch,1); - if( nRead < 1 ) - break; - buffer[readed]=ch[0]; - readed++; - } + buffer[ ulRead ] = '\0'; - buffer[readed]=0; - hb_retc(buffer); - hb_xfree(buffer); - } - else - hb_retc(""); + /* NOTE: This is valid, Clipper will not return Chr(0) from FREADSTR() */ + hb_retc( buffer ); - return; + hb_xfree( buffer ); + } + else + hb_retc( "" ); + } + else + hb_retc( "" ); } /* NOTE: This function should not return the leading and trailing */ @@ -758,209 +873,232 @@ HARBOUR HB_FREADSTR( void ) HARBOUR HB_CURDIR( void ) { - hb_retc( (char *)hb_fsCurDir( ( ISCHAR( 1 ) && hb_parclen( 1 ) ) ? (USHORT)( toupper( *hb_parc( 1 ) ) - 'A' + 1 ) : 0 ) ); + hb_retc( ( char * ) hb_fsCurDir( ( ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) ? + ( USHORT )( toupper( *hb_parc( 1 ) ) - 'A' + 1 ) : 0 ) ); } HARBOUR HB_BIN2I( void ) { - PHB_ITEM arg1_it = hb_param( 1, IT_STRING ); - char * s; - int result=0; + int iResult = 0; - if( arg1_it ) - { - s = hb_parc(1); - if( hb_parclen(1) >= 2 ) - result = MKINT(s[0],s[1]); - else - result = 0; - } + if( ISCHAR( 1 ) ) + { + char * szString = hb_parc( 1 ); - hb_retni(result); - return; + if( hb_parclen( 1 ) >= 2 ) + iResult = MKINT( szString[ 0 ], szString[ 1 ] ); + } + + hb_retni( iResult ); } HARBOUR HB_BIN2L( void ) { - PHB_ITEM arg1_it = hb_param( 1, IT_STRING ); - char * s; - long result=0; + long lResult = 0; - if( arg1_it ) - { - s = hb_parc(1); - if( hb_parclen(1) >= 4 ) - result = MKLONG(s[0],s[1],s[2],s[3]); - else - result = 0; - } + if( ISCHAR( 1 ) ) + { + char * szString = hb_parc( 1 ); - hb_retni(result); - return; + if( hb_parclen( 1 ) >= 4 ) + lResult = MKLONG( szString[ 0 ], szString[ 1 ], szString[ 2 ], szString[ 3 ] ); + } + + hb_retnl( lResult ); } HARBOUR HB_BIN2W( void ) { - HB_BIN2I(); + HB_BIN2I(); } HARBOUR HB_I2BIN( void ) { - PHB_ITEM arg1_it = hb_param( 1, IT_INTEGER ); - int n; - char s[3]; + char szString[ 2 ]; - if( arg1_it ) - { - n = hb_parni(1); - s[0] = n & 0xFF; - s[1] = (n & 0xFF00)>>8; - s[2] = 0; - hb_retclen(s,3); - } - else - hb_retclen("\0\0",2); + if( ISNUM( 1 ) ) + { + int iValue = hb_parni( 1 ); - return; + szString[ 0 ] = iValue & 0x00FF; + szString[ 1 ] = ( iValue & 0xFF00 ) >> 8; + } + else + { + szString[ 0 ] = + szString[ 1 ] = '\0'; + } + + hb_retclen( szString, 2 ); } HARBOUR HB_L2BIN( void ) { - PHB_ITEM arg1_it = hb_param( 1, IT_LONG ); - long n; - char s[5]; + char szString[ 4 ]; - if( arg1_it ) - { - n = hb_parnl(1); - s[0] = n & 0x000000FF; - s[1] = (n & 0x0000FF00)>>8; - s[2] = (n & 0x00FF0000)>>16; - s[3] = (n & 0xFF000000)>>24; - s[4] = 0; - hb_retclen(s,5); - } - else - hb_retclen("\0\0\0\0",4); + if( ISNUM( 1 ) ) + { + long lValue = hb_parnl( 1 ); - return; + szString[ 0 ] = lValue & 0x000000FF; + szString[ 1 ] = ( lValue & 0x0000FF00 ) >> 8; + szString[ 2 ] = ( lValue & 0x00FF0000 ) >> 16; + szString[ 3 ] = ( lValue & 0xFF000000 ) >> 24; + } + else + { + szString[ 0 ] = + szString[ 1 ] = + szString[ 2 ] = + szString[ 3 ] = '\0'; + } + + hb_retclen( szString, 4 ); } HARBOUR HB_W2BIN( void ) { - HB_I2BIN(); + HB_I2BIN(); } -#define IS_PATH_SEP( c ) (c == OS_PATH_DELIMITER) +#define IS_PATH_SEP( c ) ( c == OS_PATH_DELIMITER ) /* Split given filename into path, name and extension */ PHB_FNAME hb_fsFNameSplit( char *szFilename ) { - PHB_FNAME pName = (PHB_FNAME) hb_xgrab( sizeof(HB_FNAME) ); - int iLen = strlen(szFilename); - int iSlashPos; - int iDotPos; - int iPos; + PHB_FNAME pName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); - pName->szPath = pName->szName = pName->szExtension = NULL; + int iLen = strlen( szFilename ); + int iSlashPos; + int iDotPos; + int iPos; - iSlashPos = iLen-1; - iPos = 0; + pName->szPath = + pName->szName = + pName->szExtension = NULL; - while( iSlashPos >= 0 && !IS_PATH_SEP(szFilename[ iSlashPos ]) ) - --iSlashPos; + iSlashPos = iLen - 1; + iPos = 0; - if( iSlashPos == 0 ) - { - /* root path -> \filename */ - pName->szBuffer[ 0 ] = OS_PATH_DELIMITER; - pName->szBuffer[ 1 ] = '\x0'; - pName->szPath = pName->szBuffer; - iPos = 2; /* first free position after the slash */ - } - else if( iSlashPos > 0 ) - { - /* path with separator -> path\filename */ - memcpy( pName->szBuffer, szFilename, iSlashPos ); - pName->szBuffer[ iSlashPos ] = '\x0'; - pName->szPath = pName->szBuffer; - iPos = iSlashPos + 1; /* first free position after the slash */ - } + while( iSlashPos >= 0 && !IS_PATH_SEP( szFilename[ iSlashPos ] ) ) + --iSlashPos; - iDotPos = iLen-1; - while( iDotPos > iSlashPos && szFilename[ iDotPos ] != '.' ) - --iDotPos; - if( (iDotPos-iSlashPos) > 1 ) - { - /* the dot was found - * and there is at least one character between a slash and a dot - */ - if( iDotPos == iLen-1 ) - { - /* the dot is the last character -use it as extension name */ - pName->szExtension = pName->szBuffer+iPos; - pName->szBuffer[ iPos++ ] = '.'; - pName->szBuffer[ iPos++ ] = '\x0'; - } - else - { - pName->szExtension = pName->szBuffer+iPos; - /* copy rest of the string with terminating ZERO character */ - memcpy( pName->szExtension, szFilename+iDotPos+1, iLen-iDotPos ); - iPos += iLen-iDotPos; - } - } - else - /* there is no dot in the filename or it is '.filename' */ - iDotPos = iLen; + if( iSlashPos == 0 ) + { + /* root path -> \filename */ + pName->szBuffer[ 0 ] = OS_PATH_DELIMITER; + pName->szBuffer[ 1 ] = '\0'; + pName->szPath = pName->szBuffer; + iPos = 2; /* first free position after the slash */ + } + else if( iSlashPos > 0 ) + { + /* path with separator -> path\filename */ + memcpy( pName->szBuffer, szFilename, iSlashPos ); + pName->szBuffer[ iSlashPos ] = '\0'; + pName->szPath = pName->szBuffer; + iPos = iSlashPos + 1; /* first free position after the slash */ + } - pName->szName = pName->szBuffer + iPos; - memcpy( pName->szName, szFilename + iSlashPos + 1, iDotPos - iSlashPos - 1 ); - pName->szName[ iDotPos - iSlashPos - 1 ] = '\x0'; + iDotPos = iLen - 1; + while( iDotPos > iSlashPos && szFilename[ iDotPos ] != '.' ) + --iDotPos; - return pName; + if( ( iDotPos - iSlashPos ) > 1 ) + { + /* the dot was found + * and there is at least one character between a slash and a dot + */ + if( iDotPos == iLen - 1 ) + { + /* the dot is the last character -use it as extension name */ + pName->szExtension = pName->szBuffer + iPos; + pName->szBuffer[ iPos++ ] = '.'; + pName->szBuffer[ iPos++ ] = '\0'; + } + else + { + pName->szExtension = pName->szBuffer + iPos; + /* copy rest of the string with terminating ZERO character */ + memcpy( pName->szExtension, szFilename + iDotPos + 1, iLen - iDotPos ); + iPos += iLen - iDotPos; + } + } + else + /* there is no dot in the filename or it is '.filename' */ + iDotPos = iLen; + + pName->szName = pName->szBuffer + iPos; + memcpy( pName->szName, szFilename + iSlashPos + 1, iDotPos - iSlashPos - 1 ); + pName->szName[ iDotPos - iSlashPos - 1 ] = '\0'; + + return pName; } /* This function joins path, name and extension into a string with a filename */ char * hb_fsFNameMerge( char *szFileName, PHB_FNAME pFileName ) { - if( pFileName->szPath && pFileName->szPath[ 0 ] ) - { - /* we have not empty path specified */ - int iLen = strlen(pFileName->szPath); + if( pFileName->szPath && pFileName->szPath[ 0 ] ) + { + /* we have not empty path specified */ + int iLen = strlen( pFileName->szPath ); - strcpy( szFileName, pFileName->szPath ); + strcpy( szFileName, pFileName->szPath ); - /* if the path is a root directory then we don't need to add path separator */ - if( !(IS_PATH_SEP(pFileName->szPath[ 0 ]) && pFileName->szPath[ 0 ] == '\x0') ) - { - /* add the path separator only in cases: - * when a name doesn't start with it - * when the path doesn't end with it - */ - if( !( IS_PATH_SEP(pFileName->szName[ 0 ]) || IS_PATH_SEP(pFileName->szPath[ iLen-1 ]) ) ) + /* if the path is a root directory then we don't need to add path separator */ + if( !( IS_PATH_SEP( pFileName->szPath[ 0 ] ) && pFileName->szPath[ 0 ] == '\0' ) ) { - szFileName[ iLen++ ] = OS_PATH_DELIMITER; - szFileName[ iLen ] = '\x0'; + /* add the path separator only in cases: + * when a name doesn't start with it + * when the path doesn't end with it + */ + if( !( IS_PATH_SEP( pFileName->szName[ 0 ] ) || IS_PATH_SEP( pFileName->szPath[ iLen-1 ] ) ) ) + { + szFileName[ iLen++ ] = OS_PATH_DELIMITER; + szFileName[ iLen ] = '\0'; + } } - } - strcpy( szFileName+iLen, pFileName->szName ); - } - else - strcpy( szFileName, pFileName->szName ); + strcpy( szFileName + iLen, pFileName->szName ); + } + else + strcpy( szFileName, pFileName->szName ); - if( pFileName->szExtension ) - { - int iLen = strlen(szFileName); + if( pFileName->szExtension ) + { + int iLen = strlen( szFileName ); - if( !(pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen-1 ] == '.') ) - { - /* add extension separator only when extansion doesn't contain it */ - szFileName[ iLen++ ] = '.'; - szFileName[ iLen ] = '\x0'; - } - strcpy( szFileName+iLen, pFileName->szExtension ); - } + if( !( pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen-1 ] == '.') ) + { + /* add extension separator only when extansion doesn't contain it */ + szFileName[ iLen++ ] = '.'; + szFileName[ iLen ] = '\0'; + } + strcpy( szFileName + iLen, pFileName->szExtension ); + } - return szFileName; + return szFileName; } + +/* +If you call pFileName = hb_fsFNameSplit( "C:FILE.EXT" ) the result is: + pFileName->szPath => (null) must be 'C:' + pFileName->szName => 'C:FILE' must be 'FILE' + pFileName->szExtension => '.EXT' Ok! + +If you call pFileName = hb_fsFNameSplit( "C:\FILE.EXT" ) the result is: + pFileName->szPath => 'C:' must be 'C:\' + pFileName->szName => 'FILE' Ok! + pFileName->szExtension => '.EXT' Ok! + +If you call pFileName = hb_fsFNameSplit( "\FILE.EXT" ) the result is: + pFileName->szPath => '\' Ok! + pFileName->szName => 'FILE' Ok! + pFileName->szExtension => '.EXT' Ok! + +If you call pFileName = hb_fsFNameSplit( "C:\DIR\FILE.EXT" ) the result +is: + pFileName->szPath => 'C:\DIR' Ok! + pFileName->szName => 'FILE' Ok! + pFileName->szExtension => '.EXT' Ok! + +*/ diff --git a/harbour/source/rtl/inkey.c b/harbour/source/rtl/inkey.c index a132cdb73e..924219a982 100644 --- a/harbour/source/rtl/inkey.c +++ b/harbour/source/rtl/inkey.c @@ -79,7 +79,7 @@ #include "inkey.h" #include "init.h" -#if defined( OS_UNIX_COMPATIBLE ) +#if defined(OS_UNIX_COMPATIBLE) #include #include diff --git a/harbour/source/rtl/math.c b/harbour/source/rtl/math.c index 6dccd71be1..da0ea112c9 100644 --- a/harbour/source/rtl/math.c +++ b/harbour/source/rtl/math.c @@ -60,9 +60,7 @@ HARBOUR HB_EXP( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pNumber = hb_param(1, IT_NUMERIC); - - if( pNumber ) + if( ISNUM( 1 ) ) { hb_retnd( exp( hb_parnd( 1 ) ) ); /* Always set default number of decimals after EXP() */ @@ -102,9 +100,7 @@ HARBOUR HB_LOG( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pNumber = hb_param(1, IT_NUMERIC); - - if( pNumber ) + if( ISNUM( 1 ) ) { double dNumber = hb_parnd( 1 ); hb_retnd( log( dNumber ) ); @@ -209,9 +205,8 @@ FUNCTION MOD(cl_num, cl_base) IF(cl_result * cl_base < 0, cl_result + cl_base, cl_result) ) */ PHB_ITEM pNumber = hb_param(1, IT_NUMERIC); - PHB_ITEM pBase = hb_param(2, IT_NUMERIC); - if( pNumber && pBase ) + if( pNumber && ISNUM( 2 ) ) { double dNumber = hb_parnd(1); double dBase = hb_parnd(2); /* dBase! Cool! */ @@ -232,12 +227,12 @@ FUNCTION MOD(cl_num, cl_base) { hb_retnd(dNumber); /* Set the correct number of decimals */ - stack.Return.item.asDouble.decimal = (pNumber->item.asDouble.decimal); + stack.Return.item.asDouble.decimal = pNumber->item.asDouble.decimal; } } else { - hb_errRT_BASE(EG_ARG, 1085, NULL, "%"); + hb_errRT_BASE( EG_ARG, 1085, NULL, "%" ); } } @@ -306,9 +301,7 @@ HARBOUR HB_SQRT( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pNumber = hb_param(1, IT_NUMERIC); - - if( pNumber ) + if( ISNUM( 1 ) ) { double dNumber = hb_parnd(1); diff --git a/harbour/source/rtl/strings.c b/harbour/source/rtl/strings.c index 002569ed42..d641ae4487 100644 --- a/harbour/source/rtl/strings.c +++ b/harbour/source/rtl/strings.c @@ -40,7 +40,7 @@ #include "errorapi.h" #include "set.h" -#define HB_ISSPACE(c) ((c) == 9 || (c) == 10 || (c) == 13 || (c) == 32) +#define HB_ISSPACE( c ) ( ( c ) == 9 || ( c ) == 10 || ( c ) == 13 || ( c ) == 32 ) /* DJGPP can sprintf a float that is almost 320 digits long */ #define HB_MAX_DOUBLE_LENGTH 320 @@ -66,7 +66,7 @@ BOOL hb_strEmpty( char * szText, ULONG ulLen ) while( ulLen-- ) { - char c = szText[ulLen]; + char c = szText[ ulLen ]; if( !HB_ISSPACE( c ) ) { @@ -109,45 +109,47 @@ int hb_stricmp( const char *s1, const char *s2 ) return rc; } -static BOOL hb_strMatchDOS (char *pszString, char *pszMask) +static BOOL hb_strMatchDOS( char *pszString, char *pszMask ) { - while (*pszMask && *pszString) + while( *pszMask && *pszString ) { - if (*pszMask == '*') + if( *pszMask == '*' ) { - while (*pszMask == '*') + while( *pszMask == '*' ) pszMask++; - if (!(*pszMask)) - return (TRUE); + + if( ! ( *pszMask ) ) + return TRUE; else - if (*pszMask == '?') + if( *pszMask == '?' ) pszString++; else { - while (toupper(*pszString) != toupper(*pszMask)) + while( toupper( *pszString ) != toupper( *pszMask ) ) { - if (!(*(++pszString))) - return (FALSE); + if( ! ( *( ++pszString ) ) ) + return FALSE; } - while (toupper(*pszString) == toupper(*pszMask)) + while( toupper( *pszString ) == toupper( *pszMask ) ) { - if (!(*(++pszString))) + if( ! ( *( ++pszString ) ) ) break; } pszMask++; } } else - if (toupper(*pszMask) != toupper(*pszString) && *pszMask != '?') - return (FALSE); + if( toupper( *pszMask ) != toupper( *pszString ) && *pszMask != '?' ) + return FALSE; else { pszMask++; pszString++; } } - return !((!(*pszString) && *pszMask && *pszMask != '*') || - (!(*pszMask) && *pszString)); + + return ! ( ( ! ( *pszString ) && *pszMask && *pszMask != '*') || + ( ! ( *pszMask ) && *pszString ) ); } /* TODO: Replace it with a code that supports real regular expressions @@ -164,7 +166,7 @@ BOOL hb_strMatchRegExp( char *szString, char *szMask ) /* TEST: QOUT( "isalpha( '12345' ) = ", isalpha( '12345' ) ) */ HARBOUR HB_ISALPHA( void ) { - hb_retl(isalpha(*hb_parc(1))); + hb_retl( isalpha( *hb_parc( 1 ) ) ); } /* determines if first char of string is digit */ @@ -172,7 +174,7 @@ HARBOUR HB_ISALPHA( void ) /* TEST: QOUT( "isdigit( 'abcde' ) = ", isdigit( 'abcde' ) ) */ HARBOUR HB_ISDIGIT( void ) { - hb_retl(isdigit(*hb_parc(1))); + hb_retl( isdigit( *hb_parc( 1 ) ) ); } /* determines if first char of string is upper-case */ @@ -180,7 +182,7 @@ HARBOUR HB_ISDIGIT( void ) /* TEST: QOUT( "isupper( 'abcde' ) = ", isupper( 'abcde' ) ) */ HARBOUR HB_ISUPPER( void ) { - hb_retl(isupper(*hb_parc(1))); + hb_retl( isupper( *hb_parc( 1 ) ) ); } /* determines if first char of string is lower-case */ @@ -188,18 +190,19 @@ HARBOUR HB_ISUPPER( void ) /* TEST: QOUT( "islower( 'Abcde' ) = ", islower( 'Abcde' ) ) */ HARBOUR HB_ISLOWER( void ) { - hb_retl(islower(*hb_parc(1))); + hb_retl( islower( *hb_parc( 1 ) ) ); } /* trims from the left, and returns a new pointer to szText */ /* also returns the new length in lLen */ char *hb_strLTrim( char *szText, ULONG *lLen ) { - while( *lLen && HB_ISSPACE(*szText) ) + while( *lLen && HB_ISSPACE( *szText ) ) { szText++; - (*lLen)--; + ( *lLen )--; } + return szText; } @@ -209,24 +212,24 @@ HARBOUR HB_LTRIM( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { ULONG lLen = pText->item.asString.length; - char *szText = hb_strLTrim(pText->item.asString.value, &lLen); + char *szText = hb_strLTrim( pText->item.asString.value, &lLen ); - hb_retclen(szText, lLen); + hb_retclen( szText, lLen ); } else { - hb_errRT_BASE(EG_ARG, 1101, NULL, "LTRIM"); + hb_errRT_BASE( EG_ARG, 1101, NULL, "LTRIM" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "LTRIM"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "LTRIM" ); } } @@ -235,14 +238,15 @@ ULONG hb_strRTrimLen( char *szText, ULONG lLen, BOOL bAnySpace ) { if( bAnySpace ) { - while( lLen && HB_ISSPACE(szText[lLen - 1]) ) + while( lLen && HB_ISSPACE( szText[ lLen - 1 ] ) ) lLen--; } else { - while( lLen && szText[lLen - 1] == ' ' ) + while( lLen && szText[ lLen - 1 ] == ' ' ) lLen--; } + return lLen; } @@ -253,26 +257,26 @@ HARBOUR HB_RTRIM( void ) { if( hb_pcount() > 0 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { - BOOL bAnySpace = (hb_pcount() > 1 ? hb_parl(2) : FALSE); - hb_retclen(pText->item.asString.value, hb_strRTrimLen(pText->item.asString.value, pText->item.asString.length, bAnySpace)); + BOOL bAnySpace = ( hb_pcount() > 1 ? hb_parl( 2 ) : FALSE ); + hb_retclen( pText->item.asString.value, hb_strRTrimLen( pText->item.asString.value, pText->item.asString.length, bAnySpace ) ); } else { #ifdef HARBOUR_STRICT_CLIPPER_COMPATIBILITY /* Clipper doesn't error, but only in RTRIM. TRIM() throws an error, though */ - hb_retc(""); + hb_retc( "" ); #else - hb_errRT_BASE(EG_ARG, 1100, NULL, "RTRIM"); + hb_errRT_BASE( EG_ARG, 1100, NULL, "RTRIM" ); #endif } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "RTRIM"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "RTRIM" ); } } @@ -281,21 +285,21 @@ HARBOUR HB_TRIM( void ) { if( hb_pcount() > 0 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { - BOOL bAnySpace = (hb_pcount() > 1 ? hb_parl(2) : FALSE); - hb_retclen(pText->item.asString.value, hb_strRTrimLen(pText->item.asString.value, pText->item.asString.length, bAnySpace)); + BOOL bAnySpace = ( hb_pcount() > 1 ? hb_parl( 2 ) : FALSE ); + hb_retclen( pText->item.asString.value, hb_strRTrimLen( pText->item.asString.value, pText->item.asString.length, bAnySpace ) ); } else { - hb_errRT_BASE(EG_ARG, 1100, NULL, "TRIM"); + hb_errRT_BASE( EG_ARG, 1100, NULL, "TRIM" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "TRIM"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "TRIM" ); } } @@ -305,19 +309,22 @@ HARBOUR HB_ALLTRIM( void ) { if( hb_pcount() > 0 ) { - char *szText = hb_parc(1); - BOOL bAnySpace = (hb_pcount() > 1 ? hb_parl(2) : FALSE); + char *szText = hb_parc( 1 ); + BOOL bAnySpace = ( hb_pcount() > 1 ? hb_parl( 2 ) : FALSE ); ULONG lLen; - lLen = hb_strRTrimLen(szText, hb_parclen(1), bAnySpace); + lLen = hb_strRTrimLen( szText, hb_parclen( 1 ), bAnySpace ); - szText = hb_strLTrim(szText, &lLen); + szText = hb_strLTrim( szText, &lLen ); - hb_retclen(szText, lLen); + hb_retclen( szText, lLen ); } else - /* Clipper doesn't error */ - hb_retc(""); +#ifdef HB_COMPATIBILITY_CLIPPER_53 + hb_errRT_BASE( EG_ARG, 2022, NULL, "ALLTRIM" ); +#else + hb_retc( "" ); +#endif } /* This function is used by all of the PAD functions to prepare the argument @@ -333,16 +340,19 @@ static char * hb_itemPadConv( PHB_ITEM pItem, char * buffer, ULONG * pulSize ) szText = hb_dtoc( hb_pards( 1 ), buffer, hb_set.HB_SET_DATEFORMAT ); *pulSize = strlen( szText ); break; + case IT_INTEGER: sprintf( buffer, "%d", hb_parni( 1 ) ); szText = buffer; *pulSize = strlen( szText ); break; + case IT_LONG: sprintf( buffer, "%ld", hb_parnl( 1 ) ); szText = buffer; *pulSize = strlen( szText ); break; + case IT_DOUBLE: if( pItem->item.asDouble.decimal ) sprintf( buffer, "%.*f", pItem->item.asDouble.decimal, hb_parnd( 1 ) ); @@ -351,11 +361,13 @@ static char * hb_itemPadConv( PHB_ITEM pItem, char * buffer, ULONG * pulSize ) szText = buffer; *pulSize = strlen( szText ); break; + case IT_STRING: szText = hb_parc( 1 ); *pulSize = hb_parclen( 1 ); break; } + return szText; } @@ -369,34 +381,34 @@ HARBOUR HB_PADR( void ) if( szText && hb_pcount() > 1 ) { - LONG lLen = hb_parnl(2); + LONG lLen = hb_parnl( 2 ); - if( lLen > (LONG)ulSize ) + if( lLen > ( LONG ) ulSize ) { - char *szResult = (char *)hb_xgrab(lLen + 1); + char *szResult = ( char * ) hb_xgrab( lLen + 1 ); LONG lPos; char cPad; - memcpy(szResult, szText, (LONG)ulSize); + memcpy( szResult, szText, ( LONG ) ulSize ); - cPad = ( hb_pcount() > 2? *(hb_parc(3)): ' ' ); + cPad = ( hb_pcount() > 2 ? *( hb_parc( 3 ) ) : ' ' ); - for( lPos = (LONG)ulSize; lPos < lLen; lPos++ ) - szResult[lPos] = cPad; + for( lPos = ( LONG ) ulSize; lPos < lLen; lPos++ ) + szResult[ lPos ] = cPad; - hb_retclen(szResult, lLen); - hb_xfree(szResult); + hb_retclen( szResult , lLen); + hb_xfree( szResult ); } else { if( lLen < 0 ) lLen = 0; - hb_retclen(szText, lLen); + hb_retclen( szText, lLen ); } } else - hb_retc(""); + hb_retc( "" ); } /* synonymn for PADR */ @@ -411,40 +423,40 @@ HARBOUR HB_PADL( void ) { ULONG ulSize; char buffer[ 128 ]; - char *szText = hb_itemPadConv( hb_param( 1, IT_ANY ), buffer, &ulSize ); + char * szText = hb_itemPadConv( hb_param( 1, IT_ANY ), buffer, &ulSize ); if( szText && hb_pcount() > 1 ) { - LONG lLen = hb_parnl(2); + LONG lLen = hb_parnl( 2 ); - if( lLen > (LONG)ulSize ) + if( lLen > ( LONG ) ulSize ) { - char *szResult = (char *)hb_xgrab(lLen + 1); - LONG lPos = lLen - (LONG)ulSize; + char *szResult = ( char * ) hb_xgrab( lLen + 1 ); + LONG lPos = lLen - ( LONG ) ulSize; char cPad; - memcpy(szResult + lPos, szText, (LONG)ulSize); + memcpy( szResult + lPos, szText, ( LONG ) ulSize ); - cPad = (hb_pcount() > 2? *(hb_parc(3)): ' '); + cPad = ( hb_pcount() > 2 ? *( hb_parc( 3 ) ) : ' '); for(; lPos > 0; lPos--) { - szResult[lPos - 1] = cPad; + szResult[ lPos - 1 ] = cPad; } - hb_retclen(szResult, lLen); - hb_xfree(szResult); + hb_retclen( szResult, lLen ); + hb_xfree( szResult ); } else { if( lLen < 0 ) lLen = 0; - hb_retclen(szText, lLen); + hb_retclen( szText, lLen ); } } else - hb_retc(""); + hb_retc( "" ); } /* centre-pads a date, number, or string with spaces or supplied character */ @@ -457,42 +469,42 @@ HARBOUR HB_PADC( void ) if( szText && hb_pcount() > 1 ) { - LONG lLen = hb_parnl(2); + LONG lLen = hb_parnl( 2 ); - if( lLen > (LONG)ulSize ) + if( lLen > ( LONG ) ulSize ) { - char *szResult = (char *)hb_xgrab(lLen + 1); + char *szResult = ( char * ) hb_xgrab( lLen + 1 ); char cPad; - LONG w, lPos = (lLen - (LONG)ulSize) / 2; + LONG w, lPos = ( lLen - ( LONG ) ulSize ) / 2; - memcpy(szResult + lPos, szText, (LONG)ulSize + 1); + memcpy( szResult + lPos, szText, ( LONG ) ulSize + 1 ); - cPad = ( hb_pcount() > 2? *hb_parc(3): ' ' ); + cPad = ( hb_pcount() > 2 ? *hb_parc( 3 ) : ' ' ); for( w = 0; w < lPos; w++ ) - szResult[w] = cPad; + szResult[ w ] = cPad; - for( w = (LONG)ulSize + lPos; w < lLen; w++ ) - szResult[w] = cPad; + for( w = ( LONG ) ulSize + lPos; w < lLen; w++ ) + szResult[ w ] = cPad; - szResult[lLen] = '\0'; + szResult[ lLen ] = '\0'; - hb_retclen(szResult, lLen); - hb_xfree(szResult); + hb_retclen( szResult, lLen ); + hb_xfree( szResult ); } else { if( lLen < 0 ) lLen = 0; - hb_retclen(szText, lLen); + hb_retclen( szText, lLen ); } } else - hb_retc(""); + hb_retc( "" ); } -ULONG hb_strAt(char *szSub, ULONG ulSubLen, char *szText, ULONG ulLen) +ULONG hb_strAt( char *szSub, ULONG ulSubLen, char *szText, ULONG ulLen ) { if( ulSubLen ) { @@ -502,7 +514,7 @@ ULONG hb_strAt(char *szSub, ULONG ulSubLen, char *szText, ULONG ulLen) while( ulPos < ulLen && ulSubPos < ulSubLen ) { - if( *(szText + ulPos) == *(szSub + ulSubPos) ) + if( *( szText + ulPos ) == *( szSub + ulSubPos ) ) { ulSubPos++; ulPos++; @@ -512,7 +524,7 @@ ULONG hb_strAt(char *szSub, ULONG ulSubLen, char *szText, ULONG ulLen) else ulPos++; } - return (ulSubPos < ulSubLen ? 0: ulPos - ulSubLen + 1); + return ( ulSubPos < ulSubLen ) ? 0 : ( ulPos - ulSubLen + 1 ); } else return 0; @@ -525,24 +537,24 @@ ULONG hb_strAt(char *szSub, ULONG ulSubLen, char *szText, ULONG ulLen) /* TEST: QOUT( "at( 'cde', 'abcdefgfedcba' ) = '" + at( 'cde', 'abcsefgfedcba' ) + "'" ) */ HARBOUR HB_AT( void ) { - PHB_ITEM pSub = hb_param(1, IT_ANY); - PHB_ITEM pText = hb_param(2, IT_ANY); + PHB_ITEM pSub = hb_param( 1, IT_ANY ); + PHB_ITEM pText = hb_param( 2, IT_ANY ); if( pText && pSub ) { if( IS_STRING( pText ) && IS_STRING( pSub ) ) { - hb_retnl( hb_strAt(pSub->item.asString.value, pSub->item.asString.length, pText->item.asString.value, pText->item.asString.length) ); + hb_retnl( hb_strAt( pSub->item.asString.value, pSub->item.asString.length, pText->item.asString.value, pText->item.asString.length ) ); } else { - hb_errRT_BASE(EG_ARG, 1108, NULL, "AT"); + hb_errRT_BASE( EG_ARG, 1108, NULL, "AT" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "AT"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "AT" ); } } @@ -550,31 +562,31 @@ HARBOUR HB_AT( void ) /* TEST: QOUT( "rat( 'cde', 'abcdefgfedcba' ) = '" + rat( 'cde', 'abcdefgfedcba' ) + "'" ) */ HARBOUR HB_RAT( void ) { - ULONG ulSubLen = hb_parclen(1); + ULONG ulSubLen = hb_parclen( 1 ); if( ulSubLen ) { - long lPos = hb_parclen(2) - ulSubLen; + long lPos = hb_parclen( 2 ) - ulSubLen; if( lPos < 0 ) - hb_retni(0); + hb_retni( 0 ); else { - char *szSub = hb_parc(1); - char *szText = hb_parc(2); + char *szSub = hb_parc( 1 ); + char *szText = hb_parc( 2 ); BOOL bFound = FALSE; while( lPos >= 0 && !bFound ) { - if( *(szText + lPos) == *szSub ) - bFound = ( memcmp(szSub, szText + lPos, ulSubLen) == 0 ); + if( *( szText + lPos ) == *szSub ) + bFound = ( memcmp( szSub, szText + lPos, ulSubLen ) == 0 ); lPos--; } - hb_retnl( bFound ? lPos + 2: 0 ); + hb_retnl( bFound ? lPos + 2 : 0 ); } } else /* This function never seems to raise an error */ - hb_retni(0); + hb_retni( 0 ); } /* converts an ASCII code to a character value */ @@ -582,52 +594,50 @@ HARBOUR HB_CHR( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pAsc = hb_param(1, IT_NUMERIC); - - if( pAsc ) + if( ISNUM( 1 ) ) { - char chr[2]; + char chr[ 2 ]; /* Believe it or not, clipper does this! */ - chr[0] = hb_parnl(1) % 256; - chr[1] = '\0'; - hb_retclen(chr, 1); + chr[ 0 ] = hb_parnl( 1 ) % 256; + chr[ 1 ] = '\0'; + hb_retclen( chr, 1 ); } else { - hb_errRT_BASE(EG_ARG, 1104, NULL, "CHR"); + hb_errRT_BASE( EG_ARG, 1104, NULL, "CHR" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "CHR"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "CHR" ); } } /* converts a character value to an ASCII code */ -HARBOUR HB_ASC(void) +HARBOUR HB_ASC( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { if( pText->item.asString.length > 0 ) - hb_retni((BYTE)*(pText->item.asString.value)); + hb_retni( ( BYTE ) * ( pText->item.asString.value ) ); else - hb_retni(0); + hb_retni( 0 ); } else { - hb_errRT_BASE(EG_ARG, 1107, NULL, "ASC"); + hb_errRT_BASE( EG_ARG, 1107, NULL, "ASC" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "ASC"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "ASC" ); } } @@ -636,38 +646,36 @@ HARBOUR HB_LEFT( void ) { if( hb_pcount() == 2 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { - PHB_ITEM pLen = hb_param(2, IT_NUMERIC); - - if( pLen ) + if( ISNUM( 2 ) ) { - LONG lLen = hb_parnl(2); + LONG lLen = hb_parnl( 2 ); - if( lLen > (LONG)pText->item.asString.length ) - lLen = (LONG)pText->item.asString.length; + if( lLen > ( LONG ) pText->item.asString.length ) + lLen = ( LONG ) pText->item.asString.length; else if( lLen < 0 ) lLen = 0; - hb_retclen(pText->item.asString.value, lLen); + hb_retclen( pText->item.asString.value, lLen ); } else { - hb_errRT_BASE(EG_ARG, 3009, NULL, "LEFT"); + hb_errRT_BASE( EG_ARG, 3009, NULL, "LEFT" ); } } else { - hb_errRT_BASE(EG_ARG, 1124, NULL, "LEFT"); + hb_errRT_BASE( EG_ARG, 1124, NULL, "LEFT" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "LEFT"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "LEFT" ); } } @@ -676,41 +684,39 @@ HARBOUR HB_RIGHT( void ) { if( hb_pcount() == 2 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { - PHB_ITEM pLen = hb_param(2, IT_NUMERIC); - - if( pLen ) + if( ISNUM( 2 ) ) { - LONG lLen = hb_parnl(2); + LONG lLen = hb_parnl( 2 ); - if( lLen > (LONG)pText->item.asString.length ) - lLen = (LONG)pText->item.asString.length; + if( lLen > ( LONG ) pText->item.asString.length ) + lLen = ( LONG ) pText->item.asString.length; else if( lLen < 0 ) lLen = 0; - hb_retclen(pText->item.asString.value + pText->item.asString.length - lLen, lLen); + hb_retclen( pText->item.asString.value + pText->item.asString.length - lLen, lLen ); } else { /* Clipper doesn't error */ - hb_retc(""); + hb_retc( "" ); } } else { /* Clipper doesn't error */ - hb_retc(""); + hb_retc( "" ); } } else { /* NOTE: Clipper catches this at compile time! */ /* Clipper doesn't error */ - hb_retc(""); + hb_retc( "" ); } } @@ -719,16 +725,15 @@ HARBOUR HB_SUBSTR( void ) { if( hb_pcount() > 1 && hb_pcount() < 4 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); - PHB_ITEM pPos = hb_param(2, IT_NUMERIC); + PHB_ITEM pText = hb_param( 1, IT_STRING ); - if( pText && pPos ) + if( pText && ISNUM( 2 ) ) { - LONG lPos = hb_parnl(2); + LONG lPos = hb_parnl( 2 ); if( lPos < 0 ) { - lPos += (LONG)pText->item.asString.length; + lPos += ( LONG ) pText->item.asString.length; if( lPos < 0 ) lPos = 0; } @@ -737,47 +742,48 @@ HARBOUR HB_SUBSTR( void ) lPos--; } - if( lPos < (LONG)pText->item.asString.length ) + if( lPos < ( LONG ) pText->item.asString.length ) { - PHB_ITEM pLen = hb_param(3, IT_NUMERIC); LONG lLen; - if( pLen ) + if( ISNUM( 3 ) ) { - lLen = hb_parnl(3); + lLen = hb_parnl( 3 ); - if( lLen > (LONG)pText->item.asString.length - lPos ) - lLen = (LONG)pText->item.asString.length - lPos; + if( lLen > ( LONG ) pText->item.asString.length - lPos ) + lLen = ( LONG ) pText->item.asString.length - lPos; } else - lLen = (LONG)pText->item.asString.length - lPos; + lLen = ( LONG ) pText->item.asString.length - lPos; if( lLen > 0 ) - hb_retclen(pText->item.asString.value + lPos, lLen); + hb_retclen( pText->item.asString.value + lPos, lLen ); else - hb_retc(""); + hb_retc( "" ); } else - hb_retc(""); + hb_retc( "" ); } else { - hb_errRT_BASE(EG_ARG, 1110, NULL, "SUBSTR"); + hb_errRT_BASE( EG_ARG, 1110, NULL, "SUBSTR" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "SUBSTR"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "SUBSTR" ); } } /* converts szText to lower case. Does not create a new string! */ -char *hb_strLower(char *szText, ULONG ulLen) +char *hb_strLower( char *szText, ULONG ulLen ) { ULONG i; + for( i = 0; i < ulLen; i++ ) - szText[i] = tolower(szText[i]); + szText[ i ] = tolower( szText[ i ] ); + return szText; } @@ -786,23 +792,23 @@ HARBOUR HB_LOWER( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { ULONG ulLen = pText->item.asString.length; - hb_retclen(hb_strLower(pText->item.asString.value, ulLen), ulLen); + hb_retclen( hb_strLower( pText->item.asString.value, ulLen ), ulLen ); } else { - hb_errRT_BASE(EG_ARG, 1103, NULL, "LOWER"); + hb_errRT_BASE( EG_ARG, 1103, NULL, "LOWER" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "LOWER"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "LOWER" ); } } @@ -815,11 +821,13 @@ void hb_strupr( char * szText ) } /* converts szText to upper case. Does not create a new string! */ -char *hb_strUpper(char *szText, ULONG ulLen) +char *hb_strUpper( char *szText, ULONG ulLen ) { ULONG i; + for( i = 0; i < ulLen; i++ ) - szText[i] = toupper(szText[i]); + szText[ i ] = toupper( szText[ i ] ); + return szText; } @@ -828,23 +836,23 @@ HARBOUR HB_UPPER( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { ULONG ulLen = pText->item.asString.length; - hb_retclen(hb_strUpper(pText->item.asString.value, ulLen), ulLen); + hb_retclen( hb_strUpper( pText->item.asString.value, ulLen ), ulLen ); } else { - hb_errRT_BASE(EG_ARG, 1102, NULL, "UPPER"); + hb_errRT_BASE( EG_ARG, 1102, NULL, "UPPER" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "UPPER"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "UPPER" ); } } @@ -854,45 +862,45 @@ HARBOUR HB_REPLICATE( void ) { if( hb_pcount() == 2 ) { - if( ISCHAR(1) && ISNUM(2) ) + if( ISCHAR( 1 ) && ISNUM( 2 ) ) { - LONG lTimes = hb_parnl(2); + LONG lTimes = hb_parnl( 2 ); if( lTimes > 0 ) { - ULONG ulLen = hb_parclen(1); + ULONG ulLen = hb_parclen( 1 ); - if ( (double)((double)ulLen * (double)lTimes) < (double)ULONG_MAX ) + if( ( double ) ( ( double ) ulLen * ( double ) lTimes ) < ( double ) ULONG_MAX ) { - char *szText = hb_parc(1); - char *szResult = (char *)hb_xgrab((ulLen * lTimes) + 1); + char *szText = hb_parc( 1 ); + char *szResult = ( char * ) hb_xgrab( ( ulLen * lTimes ) + 1 ); char *szPtr = szResult; LONG i; for( i = 0; i < lTimes; i++ ) { - memcpy(szPtr, szText, ulLen); + memcpy( szPtr, szText, ulLen ); szPtr += ulLen; } - hb_retclen(szResult, ulLen * lTimes); - hb_xfree(szResult); + hb_retclen( szResult, ulLen * lTimes ); + hb_xfree( szResult ); } else - hb_errRT_BASE(EG_STROVERFLOW, 1234, NULL, "REPLICATE"); + hb_errRT_BASE( EG_STROVERFLOW, 1234, NULL, "REPLICATE" ); } else - hb_retc(""); + hb_retc( "" ); } else { - hb_errRT_BASE(EG_ARG, 1106, NULL, "REPLICATE"); + hb_errRT_BASE( EG_ARG, 1106, NULL, "REPLICATE" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "REPLICATE"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "REPLICATE" ); } } @@ -902,54 +910,52 @@ HARBOUR HB_SPACE( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pLen = hb_param(1, IT_NUMERIC); - - if( pLen ) + if( ISNUM( 1 ) ) { - LONG lLen = hb_parnl(1); + LONG lLen = hb_parnl( 1 ); if( lLen > 0 ) { - char *szResult = (char *)hb_xgrab(lLen + 1); + char *szResult = ( char * ) hb_xgrab( lLen + 1 ); /* NOTE: String overflow could never occure since a string can */ /* be as large as ULONG_MAX, and the maximum length that */ /* can be specified is LONG_MAX here. */ - /* hb_errRT_BASE(EG_STROVERFLOW, 1233, NULL, "SPACE"); */ + /* hb_errRT_BASE( EG_STROVERFLOW, 1233, NULL, "SPACE" ); */ - memset(szResult, ' ', lLen); - hb_retclen(szResult, lLen); - hb_xfree(szResult); + memset( szResult, ' ', lLen ); + hb_retclen( szResult, lLen ); + hb_xfree( szResult ); } else - hb_retc(""); + hb_retc( "" ); } else { - hb_errRT_BASE(EG_ARG, 1105, NULL, "SPACE"); + hb_errRT_BASE( EG_ARG, 1105, NULL, "SPACE" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "SPACE"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "SPACE" ); } } /* replaces characters in a string */ HARBOUR HB_STUFF( void ) { - if ( ISCHAR(1) && ISNUM(2) && ISNUM(3) && ISCHAR(4) ) + if( ISCHAR( 1 ) && ISNUM( 2 ) && ISNUM( 3 ) && ISCHAR( 4 ) ) { - char *szText = hb_parc(1); - ULONG ulText = hb_parclen(1); - ULONG ulPos = hb_parnl(2); - ULONG ulDel = hb_parnl(3); - ULONG ulInsert = hb_parclen(4); + char *szText = hb_parc( 1 ); + ULONG ulText = hb_parclen( 1 ); + ULONG ulPos = hb_parnl( 2 ); + ULONG ulDel = hb_parnl( 3 ); + ULONG ulInsert = hb_parclen( 4 ); ULONG ulTotalLen; - if( ulPos > 0) + if( ulPos > 0 ) ulPos--; if( ulPos > ulText ) @@ -958,53 +964,54 @@ HARBOUR HB_STUFF( void ) if( ulDel > ulText - ulPos ) ulDel = ulText - ulPos; - if( (ulTotalLen = ulText + ulInsert - ulDel) > 0 ) + if( ( ulTotalLen = ulText + ulInsert - ulDel ) > 0 ) { - char *szResult = (char *)hb_xgrab(ulTotalLen + 1); + char * szResult = ( char * ) hb_xgrab( ulTotalLen + 1 ); - memcpy(szResult, szText, ulPos); - memcpy(szResult + ulPos, hb_parc(4), ulInsert); - memcpy(szResult + ulPos + ulInsert, szText + ulPos + ulDel, ulText - (ulPos + ulDel)); + memcpy( szResult, szText, ulPos ); + memcpy( szResult + ulPos, hb_parc( 4 ), ulInsert ); + memcpy( szResult + ulPos + ulInsert, szText + ulPos + ulDel, ulText - ( ulPos + ulDel ) ); - szResult[ulTotalLen] = '\0'; - hb_retclen(szResult, ulTotalLen); - hb_xfree(szResult); + szResult[ ulTotalLen ] = '\0'; + hb_retclen( szResult, ulTotalLen ); + hb_xfree( szResult ); } else - hb_retc(""); + hb_retc( "" ); } else - hb_retc(""); + hb_retc( "" ); } /* replaces lots of characters in a string */ HARBOUR HB_STRTRAN( void ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { - PHB_ITEM pSeek = hb_param(2, IT_STRING); + PHB_ITEM pSeek = hb_param( 2, IT_STRING ); + if( pSeek ) { char *szText = pText->item.asString.value; + if( pSeek->item.asString.length && pSeek->item.asString.length <= pText->item.asString.length ) { char *szSeek = pSeek->item.asString.value; - PHB_ITEM pStart = hb_param(4, IT_NUMERIC); char *szReplace; ULONG ulStart; - ulStart = (pStart? hb_parnl(4): 1); + ulStart = ( ISNUM( 4 ) ? hb_parnl( 4 ) : 1 ); + if( !ulStart ) { /* Clipper seems to work this way */ - hb_retc(""); + hb_retc( "" ); } else if( ulStart > 0 ) { - PHB_ITEM pReplace = hb_param(3, IT_STRING); - PHB_ITEM pCount = hb_param(5, IT_NUMERIC); + PHB_ITEM pReplace = hb_param( 3, IT_STRING ); ULONG ulReplace; ULONG ulCount; BOOL bAll; @@ -1020,9 +1027,9 @@ HARBOUR HB_STRTRAN( void ) ulReplace = 0; } - if( pCount ) + if( ISNUM( 5 ) ) { - ulCount = hb_itemGetNL( pCount ); + ulCount = hb_parnl( 5 ); bAll = FALSE; } else @@ -1040,7 +1047,7 @@ HARBOUR HB_STRTRAN( void ) while( i < pText->item.asString.length ) { - if( (bAll || lReplaced < (LONG)ulCount) && !memcmp(szText + i, szSeek, pSeek->item.asString.length) ) + if( ( bAll || lReplaced < ( LONG ) ulCount ) && ! memcmp( szText + i, szSeek, pSeek->item.asString.length ) ) { ulFound++; if( ulFound >= ulStart ) @@ -1058,63 +1065,63 @@ HARBOUR HB_STRTRAN( void ) if( ulFound ) { - char *szResult = (char *)hb_xgrab(ulLength + 1); + char *szResult = ( char * ) hb_xgrab( ulLength + 1 ); char *szPtr = szResult; ulFound = 0; i = 0; while( i < pText->item.asString.length ) { - if( lReplaced && !memcmp(szText + i, szSeek, pSeek->item.asString.length) ) + if( lReplaced && ! memcmp( szText + i, szSeek, pSeek->item.asString.length ) ) { ulFound++; if( ulFound >= ulStart ) { lReplaced--; - memcpy(szPtr, szReplace, ulReplace); + memcpy( szPtr, szReplace, ulReplace ); szPtr += ulReplace; i += pSeek->item.asString.length; } else { - *szPtr = szText[i]; + *szPtr = szText[ i ]; szPtr++; i++; } } else { - *szPtr = szText[i]; + *szPtr = szText[ i ]; szPtr++; i++; } } - hb_retclen(szResult, ulLength); - hb_xfree(szResult); + hb_retclen( szResult, ulLength ); + hb_xfree( szResult ); } else - hb_retclen(szText, pText->item.asString.length); + hb_retclen( szText, pText->item.asString.length ); } else - hb_retclen(szText, pText->item.asString.length); + hb_retclen( szText, pText->item.asString.length ); } else - hb_retclen(szText, pText->item.asString.length); + hb_retclen( szText, pText->item.asString.length ); } else - hb_retclen(szText, pText->item.asString.length); + hb_retclen( szText, pText->item.asString.length ); } else - hb_errRT_BASE(EG_ARG, 3010, NULL, "STRTRAN"); + hb_errRT_BASE( EG_ARG, 3010, NULL, "STRTRAN" ); } else - hb_errRT_BASE(EG_ARG, 1126, NULL, "STRTRAN"); + hb_errRT_BASE( EG_ARG, 1126, NULL, "STRTRAN" ); } /* returns the numeric value of a character string representation of a number */ double hb_strVal( char *szText ) { - return atof(szText); + return atof( szText ); } /* returns the numeric value of a character string representation of a number */ @@ -1122,31 +1129,34 @@ HARBOUR HB_VAL( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pText = hb_param(1, IT_STRING); + PHB_ITEM pText = hb_param( 1, IT_STRING ); if( pText ) { int nWidth, nDec = 0; char * ptr = strchr( pText->item.asString.value, '.' ); + if( ptr ) { nWidth = ptr - pText->item.asString.value; nDec = strlen( ptr + 1 ); } - else nWidth = strlen( pText->item.asString.value ); - hb_retnd(hb_strVal(pText->item.asString.value)); + else + nWidth = strlen( pText->item.asString.value ); + + hb_retnd( hb_strVal( pText->item.asString.value ) ); stack.Return.item.asDouble.length = nWidth; - stack.Return.item.asDouble.decimal = nDec; + stack.Return.item.asDouble.decimal = nDec; } else { - hb_errRT_BASE(EG_ARG, 1098, NULL, "VAL"); + hb_errRT_BASE( EG_ARG, 1098, NULL, "VAL" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "VAL"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "VAL" ); } } @@ -1169,17 +1179,17 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) int iWidth; int iDec; - if ( IS_DOUBLE( pNumber ) ) + if( IS_DOUBLE( pNumber ) ) { iWidth = pNumber->item.asDouble.length; iDec = pNumber->item.asDouble.decimal; } - else if ( IS_INTEGER( pNumber ) ) + else if( IS_INTEGER( pNumber ) ) { iWidth = pNumber->item.asInteger.length; iDec = 0; } - else if ( IS_LONG( pNumber ) ) + else if( IS_LONG( pNumber ) ) { iWidth = pNumber->item.asLong.length; iDec = 0; @@ -1201,7 +1211,7 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) { /* If the width parameter is specified, override the default value and set the number of decimals to zero */ - iWidth =(int) hb_itemGetNL( pWidth ); + iWidth = ( int ) hb_itemGetNL( pWidth ); if( iWidth < 1 ) iWidth = 10; /* If 0 or negative, use default */ @@ -1213,22 +1223,22 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) /* This function does not include the decimal places in the width, so the width must be adjusted downwards, if the decimal places parameter is greater than 0 */ - iDec =(int) hb_itemGetNL( pDec ); + iDec = ( int ) hb_itemGetNL( pDec ); if( iDec < 0 ) iDec = 0; else if( iDec > 0 ) - iWidth -= (iDec + 1); + iWidth -= ( iDec + 1 ); } if( iWidth ) { /* We at least have a width value */ int iBytes; - int iSize = (iDec ? iWidth + 1 + iDec : iWidth); + int iSize = ( iDec ? iWidth + 1 + iDec : iWidth ); /* Be paranoid and use a large amount of padding */ - szResult = (char *)hb_xgrab( HB_MAX_DOUBLE_LENGTH ); + szResult = ( char * ) hb_xgrab( HB_MAX_DOUBLE_LENGTH ); if( IS_DOUBLE( pNumber ) || iDec != 0 ) { @@ -1247,7 +1257,7 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) if( iDec > 0 ) iBytes = sprintf( szResult, "%*.*f", iSize, iDec, dNumber ); else - iBytes = sprintf( szResult, "%*ld", iWidth, (LONG)dNumber ); + iBytes = sprintf( szResult, "%*ld", iWidth, ( LONG ) dNumber ); } } else switch( pNumber->type & ~IT_BYREF ) @@ -1310,9 +1320,9 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) * --------------------------------------------------------------- * $DESCRIPTION$ * STR() is a numeric conversion function that converts numeric values - * to character strings. It is commonly used to concatenate numeric values - * to character strings. STR() has applications displaying numbers, - * creating codes such as part numbers from numeric values, and creating + * to character strings. It is commonly used to concatenate numeric values + * to character strings. STR() has applications displaying numbers, + * creating codes such as part numbers from numeric values, and creating * index keys that combine numeric and character data. * * STR() is like TRANSFORM(), which formats numeric values as character @@ -1361,7 +1371,7 @@ HARBOUR HB_STR( void ) if( hb_pcount() > 1 ) { pWidth = hb_param( 2, IT_NUMERIC ); - if( !pWidth) + if( !pWidth ) bValid = FALSE; } if( hb_pcount() > 2 ) @@ -1385,13 +1395,13 @@ HARBOUR HB_STR( void ) } else { - hb_errRT_BASE(EG_ARG, 1099, NULL, "STR"); + hb_errRT_BASE( EG_ARG, 1099, NULL, "STR" ); } } else { /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "STR"); + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "STR" ); } } @@ -1432,9 +1442,9 @@ HARBOUR HB_STR( void ) * --------------------------------------------------------------- * $DESCRIPTION$ * STRZERO() is a numeric conversion function that converts numeric values - * to character strings. It is commonly used to concatenate numeric values - * to character strings. STRZERO() has applications displaying numbers, - * creating codes such as part numbers from numeric values, and creating + * to character strings. It is commonly used to concatenate numeric values + * to character strings. STRZERO() has applications displaying numbers, + * creating codes such as part numbers from numeric values, and creating * index keys that combine numeric and character data. * * STRZERO() is like TRANSFORM(), which formats numeric values as character @@ -1506,7 +1516,7 @@ HARBOUR HB_STRZERO( void ) ulPos++; } - if ( szResult[ ulPos ] == '-' ) + if( szResult[ ulPos ] == '-' ) { /* Negative sign found, put the negative sign to the first */ /* position */ @@ -1540,7 +1550,7 @@ HARBOUR HB_STRZERO( void ) } else { - hb_errRT_BASE(EG_ARG, 9999, NULL, "STRZERO"); + hb_errRT_BASE( EG_ARG, 9999, NULL, "STRZERO" ); } } } @@ -1549,20 +1559,18 @@ HARBOUR HB_STRZERO( void ) int hb_strgreater( char * sz1, char * sz2 ) { - while( *( sz1 ) && *( sz2 ) && *( sz1 ) == *( sz2 ) ) { sz1++; sz2++; } - if ( ( *( sz1 ) == 0 && *( sz2 ) != 0 ) || - ( *( sz2 ) > *( sz1 ) ) ) + if( ( *( sz1 ) == 0 && *( sz2 ) != 0 ) || + ( *( sz2 ) > *( sz1 ) ) ) return HB_STRGREATER_RIGHT; - if ( ( *( sz1 ) != 0 && *( sz2 ) == 0 ) || - ( *( sz1 ) > *( sz2 ) ) ) + if( ( *( sz1 ) != 0 && *( sz2 ) == 0 ) || + ( *( sz1 ) > *( sz2 ) ) ) return HB_STRGREATER_LEFT; return HB_STRGREATER_EQUAL; } - diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index f5ab0ffcc9..fa0634a74d 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -101,7 +101,7 @@ static PHB_SYMB pSymStart; /* start symbol of the application. MAIN() is static PSYMBOLS pSymbols = 0; /* to hold a linked list of all different modules symbol tables */ static BYTE byErrorLevel = 0; /* application exit errorlevel */ -/* Stores the position on the stack of current SEQUENCE envelope or 0 if no +/* Stores the position on the stack of current SEQUENCE envelope or 0 if no * SEQUENCE is active */ static LONG RecoverBase = 0; @@ -119,7 +119,7 @@ static WORD wActionRequest = 0; /* uncomment it to trace the virtual machine activity */ /* #define bHB_DEBUG */ -#if defined( bHB_DEBUG ) +#if defined(bHB_DEBUG) #define HB_DEBUG( x ) printf( x ) #define HB_DEBUG2( x, y ) printf( x, y ) #else @@ -1734,23 +1734,24 @@ static void hb_vmPopAliasedField( PHB_SYMB pSym ) double hb_vmPopDouble( WORD *pwDec ) { - double d; + double dNumber; hb_stackDec(); + switch( stack.pPos->type & ~IT_BYREF ) { case IT_INTEGER: - d = stack.pPos->item.asInteger.value; + dNumber = ( double ) stack.pPos->item.asInteger.value; *pwDec =0; break; case IT_LONG: - d = stack.pPos->item.asLong.value; + dNumber = ( double ) stack.pPos->item.asLong.value; *pwDec =0; break; case IT_DOUBLE: - d = stack.pPos->item.asDouble.value; + dNumber = stack.pPos->item.asDouble.value; *pwDec =stack.pPos->item.asDouble.decimal; break; @@ -1758,9 +1759,12 @@ double hb_vmPopDouble( WORD *pwDec ) hb_errInternal( 9999, "Incorrect item type trying to Pop a double", NULL, NULL ); break; } + stack.pPos->type = IT_NIL; + HB_DEBUG( "hb_vmPopDouble\n" ); - return d; + + return dNumber; } static void hb_vmPopField( PHB_SYMB pSym ) @@ -1842,11 +1846,14 @@ double hb_vmPopNumber( void ) break; default: - hb_stackShow(); hb_errInternal( 9999, "Incorrect item on the stack trying to pop a number", NULL, NULL ); break; } + stack.pPos->type = IT_NIL; + + HB_DEBUG( "hb_vmPopNumber\n" ); + return dNumber; } diff --git a/harbour/tests/working/rtl_test.prg b/harbour/tests/working/rtl_test.prg index 4113a31afd..3713c238ec 100644 --- a/harbour/tests/working/rtl_test.prg +++ b/harbour/tests/working/rtl_test.prg @@ -443,7 +443,7 @@ FUNCTION Main( cPar1 ) TEST_LINE( Transform( SToD("19101112") , "9#-9#/##" ) , "1910.11.12" ) TEST_LINE( Transform( SToD("19920101") , "" ) , "1992.01.01" ) TEST_LINE( Transform( SToD("19920101") , "DO THIS " ) , "1992.01.01" ) - TEST_LINE( Transform( SToD("19920102") , "@E" ) , "02/01/1992" ) /* BUG in Clipper */ + TEST_LINE( Transform( SToD("19920102") , "@E" ) , "02/01/1992" ) /* Bug in CA-Cl*pper, it returns: "2.91901.02" */ TEST_LINE( Transform( 1234 , "@D 9999" ) , "1234.00.0 " ) TEST_LINE( Transform( 1234 , "@BD 9999" ) , "1234.00.0 " ) @@ -461,7 +461,7 @@ FUNCTION Main( cPar1 ) TEST_LINE( Transform( SToD("19101112") , "9#-9#/##" ) , "10.11.12" ) TEST_LINE( Transform( SToD("19920101") , "" ) , "92.01.01" ) TEST_LINE( Transform( SToD("19920101") , "DO THIS " ) , "92.01.01" ) - TEST_LINE( Transform( SToD("19920102") , "@E" ) , "02/01/92" ) /* BUG in Clipper */ + TEST_LINE( Transform( SToD("19920102") , "@E" ) , "02/01/92" ) /* Bug in CA-Cl*pper, it returns: "01.92.02" */ TEST_LINE( Transform( 1234 , "@D 9999" ) , "**.**.* " ) TEST_LINE( Transform( 1234 , "@BD 9999" ) , "**.**.* " ) @@ -502,7 +502,7 @@ FUNCTION Main( cPar1 ) TEST_LINE( Transform( -7 , "9X9^" ) , "-X7^" ) TEST_LINE( Transform( 1 , "@R 9HI!" ) , "1HI!" ) TEST_LINE( Transform( 1 , "9HI!" ) , "1HI!" ) - TEST_LINE( Transform( -12 , "@( 99" ) , "(*)" ) /* BUG Fix */ + TEST_LINE( Transform( -12 , "@( 99" ) , "(*)" ) /* Bug in CA-Cl*pper, it returns: "(2)" */ TEST_LINE( Transform( 12 , "@( 99" ) , "12" ) TEST_LINE( Transform( 1 , "" ) , " 1" ) TEST_LINE( Transform( 32768 , "" ) , " 32768" ) @@ -510,9 +510,9 @@ FUNCTION Main( cPar1 ) TEST_LINE( Transform( 1048576 , "" ) , " 1048576" ) TEST_LINE( Transform( 21.65 , "" ) , " 21.65" ) TEST_LINE( Transform( -3.33 , "" ) , " -3.33" ) - TEST_LINE( Transform( -1234 , "@( 9999" ) , "(***)" ) /* BUG Fix */ + TEST_LINE( Transform( -1234 , "@( 9999" ) , "(***)" ) /* Bug in CA-Cl*pper, it returns: "(234)" */ TEST_LINE( Transform( -1234 , "@B 9999" ) , "****" ) - TEST_LINE( Transform( -1234 , "@B( 9999" ) , "(***)" ) /* BUG Fix */ + TEST_LINE( Transform( -1234 , "@B( 9999" ) , "(***)" ) /* Bug in CA-Cl*pper, it returns: "(234)" */ TEST_LINE( Transform( 1234 , "@E 9,999.99" ) , "1.234,00" ) TEST_LINE( Transform( 12.2 , "@E 9,999.99" ) , " 12,20" ) TEST_LINE( Transform( -1234 , "@X 9999" ) , "1234 DB" )