From 2428951d68528198af393faaeab2f1f8cc84770e Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 5 Sep 2007 14:50:23 +0000 Subject: [PATCH] 2007-09-05 16:50 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/hbgtmk.sh * replaced CVS checkout commands by SVN checkout # This script checks you have all tools to build Harbour binaries # installed then takes current Harbour sources from SourceForge SVN # repository and build binary RPMs at your local host If possible I think it will be good to put this script on Harbour home page so Linux users using RPM based distributions can simply download it and execute. It should greatly help them and it will reduce some repeated questions. * harbour/include/hbapifs.h * harbour/source/rtl/filesys.c + added hb_fsNameConv() function, hb_fileNameConv() kept only for backward compatibility - it should not be used * use hb_fsNameConv() instead of hb_fileNameConv() * updated conversion code to use hb_fsFNameSplit()/hb_fsFNameMerge() and respect some other DOS like conditions * harbour/include/hbdate.h * harbour/source/common/hbdate.c * harbour/source/rtl/seconds.c * use MT safe localtime_r() instead of localtime() in Linux + hb_dateTimeStamp(), hb_timeStampStr(), hb_timeStampDecode(), hb_dateTimeStampStr(), hb_dateTimeStampStrGet() * harbour/contrib/libct/files.c * harbour/contrib/libct/disk.c * harbour/contrib/hbzlib/hbcomprs.c * harbour/source/rtl/diskspac.c * harbour/source/rtl/fstemp.c * harbour/source/rtl/disksphb.c * harbour/source/rtl/file.c * use hb_fsNameConv() instead of hb_fileNameConv() * harbour/source/debug/dbgentry.c + added modifications by Phil Krylow borowed from xHarbour for supporting :: in command line expressions * harbour/source/rdd/dbfntx/dbfntx1.c * harbour/source/rdd/dbfdbt/dbfdbt1.c * harbour/source/rdd/dbfcdx/dbfcdx1.c * harbour/source/rdd/delim1.c * harbour/source/rdd/dbf1.c * harbour/source/rdd/dbffpt/dbffpt1.c * harbour/source/rdd/sdf1.c * minor clenup: use hb_parptr(n) instead of hb_itemGetPtr(hb_param(n,HB_IT_POINTER)) --- harbour/ChangeLog | 50 ++++++++ harbour/contrib/hbzlib/hbcomprs.c | 3 +- harbour/contrib/libct/disk.c | 5 +- harbour/contrib/libct/files.c | 14 +- harbour/hbgtmk.sh | 29 +---- harbour/include/hbapifs.h | 1 + harbour/include/hbdate.h | 5 + harbour/source/common/hbdate.c | 133 +++++++++++++++++++ harbour/source/debug/dbgentry.c | 70 ++++++---- harbour/source/rdd/dbf1.c | 6 +- harbour/source/rdd/dbfcdx/dbfcdx1.c | 12 +- harbour/source/rdd/dbfdbt/dbfdbt1.c | 6 +- harbour/source/rdd/dbffpt/dbffpt1.c | 6 +- harbour/source/rdd/dbfntx/dbfntx1.c | 4 +- harbour/source/rdd/delim1.c | 11 +- harbour/source/rdd/sdf1.c | 11 +- harbour/source/rtl/diskspac.c | 47 ++++--- harbour/source/rtl/disksphb.c | 8 +- harbour/source/rtl/file.c | 29 ++++- harbour/source/rtl/filesys.c | 191 ++++++++++++++++++---------- harbour/source/rtl/fstemp.c | 2 +- harbour/source/rtl/seconds.c | 110 +++++++++++++--- 22 files changed, 545 insertions(+), 208 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2c4e3d2d22..c76fc85528 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,56 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-09-05 16:50 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/hbgtmk.sh + * replaced CVS checkout commands by SVN checkout + # This script checks you have all tools to build Harbour binaries + # installed then takes current Harbour sources from SourceForge SVN + # repository and build binary RPMs at your local host + + If possible I think it will be good to put this script on + Harbour home page so Linux users using RPM based distributions + can simply download it and execute. It should greatly help them + and it will reduce some repeated questions. + + * harbour/include/hbapifs.h + * harbour/source/rtl/filesys.c + + added hb_fsNameConv() function, hb_fileNameConv() kept only for + backward compatibility - it should not be used + * use hb_fsNameConv() instead of hb_fileNameConv() + * updated conversion code to use hb_fsFNameSplit()/hb_fsFNameMerge() + and respect some other DOS like conditions + + * harbour/include/hbdate.h + * harbour/source/common/hbdate.c + * harbour/source/rtl/seconds.c + * use MT safe localtime_r() instead of localtime() in Linux + + hb_dateTimeStamp(), hb_timeStampStr(), hb_timeStampDecode(), + hb_dateTimeStampStr(), hb_dateTimeStampStrGet() + + * harbour/contrib/libct/files.c + * harbour/contrib/libct/disk.c + * harbour/contrib/hbzlib/hbcomprs.c + * harbour/source/rtl/diskspac.c + * harbour/source/rtl/fstemp.c + * harbour/source/rtl/disksphb.c + * harbour/source/rtl/file.c + * use hb_fsNameConv() instead of hb_fileNameConv() + + * harbour/source/debug/dbgentry.c + + added modifications by Phil Krylow borowed from xHarbour for + supporting :: in command line expressions + + * harbour/source/rdd/dbfntx/dbfntx1.c + * harbour/source/rdd/dbfdbt/dbfdbt1.c + * harbour/source/rdd/dbfcdx/dbfcdx1.c + * harbour/source/rdd/delim1.c + * harbour/source/rdd/dbf1.c + * harbour/source/rdd/dbffpt/dbffpt1.c + * harbour/source/rdd/sdf1.c + * minor clenup: + use hb_parptr(n) instead of hb_itemGetPtr(hb_param(n,HB_IT_POINTER)) + 2007-09-03 01:23 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) - harbour/contrib/apollo/makefile + harbour/contrib/apollo/Makefile diff --git a/harbour/contrib/hbzlib/hbcomprs.c b/harbour/contrib/hbzlib/hbcomprs.c index d11df7d354..0095c0cc7d 100644 --- a/harbour/contrib/hbzlib/hbcomprs.c +++ b/harbour/contrib/hbzlib/hbcomprs.c @@ -4223,8 +4223,7 @@ void HB_EXPORT hb_fsDirectory( PHB_ITEM pDir, char* szSkleton, char* szAttribute if ( szSkleton && strlen( szSkleton ) > 0 ) { - szDirSpec = (BYTE *) hb_fileNameConv( hb_strdup( szSkleton ) ); - bAlloc = TRUE; + szDirSpec = hb_fsNameConv( szSkleton, &bAlloc ); } else { diff --git a/harbour/contrib/libct/disk.c b/harbour/contrib/libct/disk.c index 4418ed3543..ea9fc8997b 100644 --- a/harbour/contrib/libct/disk.c +++ b/harbour/contrib/libct/disk.c @@ -212,10 +212,11 @@ HB_FUNC( VOLUME ) char *sRoot = NULL; char *sVolName = NULL; char sRootBuf[3], sVolNameBuf[12]; + BOOL fFree; if( ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) { - sDiskName = hb_fileNameConv( hb_strdup( hb_parcx( 1 ) ) ); + sDiskName = hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); if( ( fname = hb_fsFNameSplit( ( char * ) sDiskName ) ) != NULL ) { @@ -237,6 +238,8 @@ HB_FUNC( VOLUME ) strncpy( sVolNameBuf, ( char * ) sDiskName, 11 ); sVolName = sVolNameBuf; } + if( fFree ) + hb_xfree( sDiskName ); } #if defined(HB_OS_WIN_32) bReturn = SetVolumeLabel( sRoot, sVolName ); diff --git a/harbour/contrib/libct/files.c b/harbour/contrib/libct/files.c index ee2539eedf..924638626c 100644 --- a/harbour/contrib/libct/files.c +++ b/harbour/contrib/libct/files.c @@ -103,6 +103,7 @@ static PHB_FFIND _hb_fileStart( BOOL fNext ) { char * szFile = hb_parc( 1 ); USHORT uiAttr = HB_FA_ALL; + BOOL fFree; if( s_ffind ) { @@ -117,11 +118,12 @@ static PHB_FFIND _hb_fileStart( BOOL fNext ) hb_vmAtExit( _hb_fileClose, NULL ); s_fInit = TRUE; } - szFile = ( char * ) hb_fileNameConv( hb_strdup( szFile ) ); + szFile = ( char * ) hb_fsNameConv( ( BYTE * ) szFile, &fFree ); if( ISNUM( 2 ) ) uiAttr = hb_parni( 2 ); s_ffind = hb_fsFindFirst( szFile, uiAttr ); - hb_xfree( szFile ); + if( fFree ) + hb_xfree( szFile ); } } else if( fNext && s_ffind ) @@ -320,12 +322,13 @@ HB_FUNC( FILEDELETE ) BYTE * pDirSpec; PHB_FFIND ffind; USHORT uiAttr = HB_FA_ALL; + BOOL fFree; - pDirSpec = hb_fileNameConv( hb_strdup( hb_parc( 1 ) ) ); + pDirSpec = hb_fsNameConv( ( BYTE * ) hb_parc( 1 ), &fFree ); if( ISNUM( 2 ) ) uiAttr = hb_parni( 2 ); - if( ( ffind = hb_fsFindFirst( ( const char * ) pDirSpec, uiAttr ) ) != NULL ) + if( ( ffind = hb_fsFindFirst( ( char * ) pDirSpec, uiAttr ) ) != NULL ) { PHB_FNAME pFilepath; @@ -346,7 +349,8 @@ HB_FUNC( FILEDELETE ) hb_fsFindClose( ffind ); } - hb_xfree( pDirSpec ); + if( fFree ) + hb_xfree( pDirSpec ); } hb_retl( bReturn ); diff --git a/harbour/hbgtmk.sh b/harbour/hbgtmk.sh index 9dccc1c1ab..027c9a373f 100755 --- a/harbour/hbgtmk.sh +++ b/harbour/hbgtmk.sh @@ -6,15 +6,13 @@ # --------------------------------------------------------------- # Copyright 2003 Przemyslaw Czerpak # This script checks you have all tools to build Harbour binaries -# installed then takes current Harbour sources from SourceForge CVS -# and build binary RPMs at your local host +# installed then takes current Harbour sources from SourceForge SVN +# repository and build binary RPMs at your local host # # See doc/license.txt for licensing terms. # --------------------------------------------------------------- -# ssh is not necessary for anonymous access on SourceForge -# export CVS_RSH=ssh -export CVSROOT=":pserver:anonymous@harbour-project.cvs.sourceforge.net:/cvsroot/harbour-project" +export SVNURL="https://harbour-project.svn.sourceforge.net/svnroot/harbour-project/trunk/harbour" export PROJECT=harbour test_reqrpm() @@ -23,30 +21,17 @@ test_reqrpm() } TOINST_LST="" -for i in cvs make gcc binutils bash ncurses ncurses-devel +for i in subversion make gcc binutils bash ncurses ncurses-devel do test_reqrpm "$i" || TOINST_LST="${TOINST_LST} $i" done -_cvs_RSH="${CVS_RSH}" -[ -n "${_cvs_RSH}" ] || _cvs_RSH="rsh" - -if ! which ${_cvs_RSH} &>/dev/null -then - if [ "${_cvs_RSH}" = "ssh" ] - then - TOINST_LST="${TOINST_LST} [open]ssh-clients" - else - TOINST_LST="${TOINST_LST} ${_cvs_RSH}" - fi -fi - if [ -z "${TOINST_LST}" ] || [ "$1" = "--force" ] then cd - mkdir -p CVS - cd CVS - if cvs -z3 co "${PROJECT}"; then + mkdir -p SVN + cd SVN + if svn co "${SVNURL}"; then cd "${PROJECT}" ./make_rpm.sh "$*" fi diff --git a/harbour/include/hbapifs.h b/harbour/include/hbapifs.h index dda3d57ca5..67198e51b3 100644 --- a/harbour/include/hbapifs.h +++ b/harbour/include/hbapifs.h @@ -225,6 +225,7 @@ extern USHORT hb_fsAttrFromRaw( ULONG raw_attr ); extern ULONG hb_fsAttrToRaw( USHORT uiAttr ); extern USHORT hb_fsAttrEncode( const char * szAttr ); extern char * hb_fsAttrDecode( USHORT uiAttr, char * szAttr ); +extern HB_EXPORT BYTE * hb_fsNameConv( BYTE * szFileName, BOOL * pfFree ); extern HB_EXPORT BYTE * hb_fileNameConv( char *str ); HB_EXTERN_END diff --git a/harbour/include/hbdate.h b/harbour/include/hbdate.h index c6e0aa68c4..2881dde015 100644 --- a/harbour/include/hbdate.h +++ b/harbour/include/hbdate.h @@ -59,6 +59,11 @@ HB_EXTERN_BEGIN extern HB_EXPORT double hb_dateSeconds( void ); extern HB_EXPORT double hb_secondsCPU( int n ); +extern HB_EXPORT void hb_dateTimeStamp( LONG * plJulian, LONG * plMilliSec ); +extern HB_EXPORT char * hb_timeStampStr( char * szTime, LONG lMillisec ); +extern HB_EXPORT void hb_timeStampDecode( LONG lMillisec, int * piHour, int * piMinutes, int * piSeconds, int * piMSec ); +extern HB_EXPORT char * hb_dateTimeStampStr( char * szDateTime, LONG lJulian, LONG lMillisec ); +extern HB_EXPORT void hb_dateTimeStampStrGet( const char * szDateTime, LONG * plJulian, LONG * plMillisec ); extern HB_EXPORT void hb_dateToday( int * piYear, int * piMonth, int * piDay ); extern HB_EXPORT void hb_dateTimeStr( char * pszTime ); extern HB_EXPORT char * hb_dateCMonth( int iMonth ); diff --git a/harbour/source/common/hbdate.c b/harbour/source/common/hbdate.c index b258aa8052..933285de6a 100644 --- a/harbour/source/common/hbdate.c +++ b/harbour/source/common/hbdate.c @@ -268,6 +268,18 @@ HB_EXPORT void hb_dateToday( int * piYear, int * piMonth, int * piDay ) *piMonth = st.wMonth; *piDay = st.wDay; +#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) + + time_t t; + struct tm st; + + time( &t ); + localtime_r( &t, &st ); + + *piYear = st.tm_year + 1900; + *piMonth = st.tm_mon + 1; + *piDay = st.tm_mday; + #else time_t t; @@ -293,6 +305,16 @@ HB_EXPORT void hb_dateTimeStr( char * pszTime ) GetLocalTime( &st ); snprintf( pszTime, 9, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond ); } +#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) + { + time_t t; + struct tm st; + + time( &t ); + localtime_r( &t, &st ); + + snprintf( pszTime, 9, "%02d:%02d:%02d", st.tm_hour, st.tm_min, st.tm_sec ); + } #else { time_t t; @@ -304,3 +326,114 @@ HB_EXPORT void hb_dateTimeStr( char * pszTime ) } #endif } + +HB_EXPORT void hb_timeStampDecode( LONG lMillisec, int * piHour, int * piMinutes, + int * piSeconds, int * piMSec ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_timeStampDecode(%ld, %p, %p, %p, %p)", lMillisec, piHour, piMinutes, piSeconds, piMSec)); + + if( lMillisec <= 0 ) + { + *piHour = *piMinutes = *piSeconds = *piMSec = 0; + } + else + { + *piMSec = lMillisec % 1000; + lMillisec /= 1000; + *piSeconds = lMillisec % 60; + lMillisec /= 60; + *piMinutes = lMillisec % 60; + lMillisec /= 60; + if( lMillisec >= 24 ) + *piHour = *piMinutes = *piSeconds = *piMSec = 0; + else + *piHour = ( int ) lMillisec; + } +} + +/* This function always closes the time with a zero byte, so it needs a + 13 character long buffer. */ + +HB_EXPORT char * hb_timeStampStr( char * szTime, LONG lMillisec ) +{ + int iHour, iMinutes, iSeconds, iMSec; + + HB_TRACE(HB_TR_DEBUG, ("hb_timeStampStr(%p, %ld)", szTime, lMillisec)); + + hb_timeStampDecode( lMillisec, &iHour, &iMinutes, &iSeconds, &iMSec ); + snprintf( szTime, 13, "%02d:%02d:%02d.%03d", + iHour, iMinutes, iSeconds, iMSec ); + szTime[ 12 ] = '\0'; + + return szTime; +} + +/* This function always closes the time with a zero byte, so it needs a + 24 character long buffer. */ + +HB_EXPORT char * hb_dateTimeStampStr( char * szDateTime, LONG lJulian, LONG lMillisec ) +{ + int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateTimeStampStr(%p, %ld, %ld)", szDateTime, lJulian, lMillisec)); + + hb_dateDecode( lJulian, &iYear, &iMonth, &iDay ); + hb_timeStampDecode( lMillisec, &iHour, &iMinutes, &iSeconds, &iMSec ); + snprintf( szDateTime, 24, "%04d-%02d-%02d %02d:%02d:%02d.%03d", + iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec ); + szDateTime[ 23 ] = '\0'; + + return szDateTime; +} + +HB_EXPORT void hb_dateTimeStampStrGet( const char * szDateTime, LONG * plJulian, LONG * plMillisec ) +{ + int iLen; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateTimeStampStr(%s, %p, %p)", szDateTime, plJulian, plMillisec)); + + *plJulian = *plMillisec = 0; + iLen = szDateTime ? hb_strnlen( szDateTime, 23 ) : 0; + if( iLen >= 10 ) + { + int iYear, iMonth, iDay; + + iYear = ( ( ( int ) ( szDateTime[ 0 ] - '0' ) * 10 + + ( int ) ( szDateTime[ 1 ] - '0' ) ) * 10 + + ( int ) ( szDateTime[ 2 ] - '0' ) ) * 10 + + ( int ) ( szDateTime[ 3 ] - '0' ); + iMonth = ( szDateTime[ 5 ] - '0' ) * 10 + ( szDateTime[ 6 ] - '0' ); + iDay = ( szDateTime[ 8 ] - '0' ) * 10 + ( szDateTime[ 9 ] - '0' ); + + *plJulian = hb_dateEncode( iYear, iMonth, iDay ); + if( iLen >= 16 ) + { + int iHour, iMinutes, iSeconds = 0, iMSec = 0; + + iHour = ( szDateTime[ 11 ] - '0' ) * 10 + + ( szDateTime[ 12 ] - '0' ); + iMinutes = ( szDateTime[ 14 ] - '0' ) * 10 + + ( szDateTime[ 15 ] - '0' ); + if( iHour >= 0 && iHour < 24 && iMinutes >= 0 && iMinutes < 60 ) + { + if( iLen >= 19 ) + { + iSeconds = ( szDateTime[ 17 ] - '0' ) * 10 + + ( szDateTime[ 18 ] - '0' ); + if( iSeconds < 0 || iSeconds >= 60 ) + iSeconds = 0; + else if( iLen >= 23 ) + { + iMSec = ( ( szDateTime[ 20 ] - '0' ) * 10 + + ( szDateTime[ 21 ] - '0' ) ) * 10 + + ( szDateTime[ 22 ] - '0' ); + if( iMSec < 0 || iMSec >= 1000 ) + iMSec = 0; + } + } + *plMillisec = ( ( ( iHour * 60 ) + iMinutes ) * 60 + iSeconds ) * + 1000 + iMSec; + } + } + } +} diff --git a/harbour/source/debug/dbgentry.c b/harbour/source/debug/dbgentry.c index a7931ee0c5..bf5e7a51f5 100644 --- a/harbour/source/debug/dbgentry.c +++ b/harbour/source/debug/dbgentry.c @@ -1034,6 +1034,41 @@ hb_dbgEvalMacro( char *szExpr, PHB_ITEM pItem ) #define IS_IDENT_START( c ) ( isalpha( (UCHAR) (c) ) || (c) == '_' ) #define IS_IDENT_CHAR( c ) ( IS_IDENT_START( (c) ) || isdigit( (UCHAR) (c) ) ) +static int +hb_dbgEvalSubstituteVar( HB_WATCHPOINT *watch, char *szWord, int nStart, int nLen ) +{ + int j; + char *t; + + for ( j = 0; j < watch->nVars; j++ ) + { + if ( !strcmp( szWord, watch->aVars[ j ] ) ) + { + break; + } + } + if ( j == watch->nVars ) + { + *ARRAY_ADD( char *, watch->aVars, watch->nVars ) = szWord; + } + else + { + FREE( szWord ); + } + + t = (char *) ALLOC( strlen( watch->szExpr ) - nLen + 9 + 1 ); + memmove( t, watch->szExpr, nStart ); + memmove( t + nStart, "__dbg[", 6 ); + t[ nStart + 6 ] = '0' + ( ( j + 1 ) / 10 ); + t[ nStart + 7 ] = '0' + ( ( j + 1 ) % 10 ); + t[ nStart + 8 ] = ']'; + strcpy( t + nStart + 9, watch->szExpr + nStart + nLen ); + FREE( watch->szExpr ); + watch->szExpr = t; + return nStart + 9; +} + + static PHB_ITEM hb_dbgEvalMakeBlock( HB_WATCHPOINT *watch ) { @@ -1084,34 +1119,7 @@ hb_dbgEvalMakeBlock( HB_WATCHPOINT *watch ) } } hb_strupr( szWord ); - for ( j = 0; j < watch->nVars; j++ ) - { - if ( !strcmp( szWord, watch->aVars[ j ] ) ) - { - break; - } - } - if ( j == watch->nVars ) - { - *ARRAY_ADD( char *, watch->aVars, watch->nVars ) = szWord; - } - else - { - FREE( szWord ); - } - { - char *t = (char *) ALLOC( strlen( watch->szExpr ) - nLen + 9 + 1 ); - - memmove( t, watch->szExpr, nStart ); - memmove( t + nStart, "__dbg[", 6 ); - t[ nStart + 6 ] = '0' + ( ( j + 1 ) / 10 ); - t[ nStart + 7 ] = '0' + ( ( j + 1 ) % 10 ); - t[ nStart + 8 ] = ']'; - strcpy( t + nStart + 9, watch->szExpr + nStart + nLen ); - FREE( watch->szExpr ); - watch->szExpr = t; - i = nStart + 9; - } + i = hb_dbgEvalSubstituteVar( watch, szWord, nStart, nLen ); bAfterId = TRUE; continue; } @@ -1143,6 +1151,12 @@ hb_dbgEvalMakeBlock( HB_WATCHPOINT *watch ) || ( c == '-' && watch->szExpr[ i + 1 ] == '>' && IS_IDENT_START( watch->szExpr[ i + 2 ] ) ) ) { + if ( c == ':' && watch->szExpr[ i + 1 ] == ':' ) + { + i = hb_dbgEvalSubstituteVar( watch, hb_strdup( "SELF" ), i, 1 ); + bAfterId = TRUE; + continue; + } if ( c == '-' ) { i++; diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index f07fce526c..e13476eb03 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -4615,11 +4615,11 @@ HB_FUNC( DBF_GETFUNCTABLE ) RDDFUNCS * pTable; USHORT * uiCount, uiRddId; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); uiRddId = hb_parni( 4 ); - HB_TRACE(HB_TR_DEBUG, ("DBF_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + HB_TRACE(HB_TR_DEBUG, ("DBF_GETFUNCTABLE(%p, %p)", uiCount, pTable)); if( pTable ) { diff --git a/harbour/source/rdd/dbfcdx/dbfcdx1.c b/harbour/source/rdd/dbfcdx/dbfcdx1.c index 81a714ccd7..c1575983c3 100644 --- a/harbour/source/rdd/dbfcdx/dbfcdx1.c +++ b/harbour/source/rdd/dbfcdx/dbfcdx1.c @@ -9437,11 +9437,11 @@ HB_FUNC( SIXCDX_GETFUNCTABLE ) RDDFUNCS * pTable; USHORT * uiCount, uiRddId; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); uiRddId = hb_parni( 4 ); - HB_TRACE(HB_TR_DEBUG, ("SIXCDX_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + HB_TRACE(HB_TR_DEBUG, ("SIXCDX_GETFUNCTABLE(%p, %p)", uiCount, pTable)); if ( pTable ) { @@ -9501,11 +9501,11 @@ HB_FUNC( DBFCDX_GETFUNCTABLE ) RDDFUNCS * pTable; USHORT * uiCount, uiRddId; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); uiRddId = hb_parni( 4 ); - HB_TRACE(HB_TR_DEBUG, ("DBFCDX_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + HB_TRACE(HB_TR_DEBUG, ("DBFCDX_GETFUNCTABLE(%p, %p)", uiCount, pTable)); if ( pTable ) { diff --git a/harbour/source/rdd/dbfdbt/dbfdbt1.c b/harbour/source/rdd/dbfdbt/dbfdbt1.c index abb59cc7ee..eb6cc44431 100644 --- a/harbour/source/rdd/dbfdbt/dbfdbt1.c +++ b/harbour/source/rdd/dbfdbt/dbfdbt1.c @@ -796,10 +796,10 @@ HB_FUNC( DBFDBT_GETFUNCTABLE ) RDDFUNCS * pTable; USHORT * uiCount; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); - HB_TRACE(HB_TR_DEBUG, ("DBFDBT_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + HB_TRACE(HB_TR_DEBUG, ("DBFDBT_GETFUNCTABLE(%p, %p)", uiCount, pTable)); if( pTable ) { diff --git a/harbour/source/rdd/dbffpt/dbffpt1.c b/harbour/source/rdd/dbffpt/dbffpt1.c index 0430d8358a..77efae84db 100644 --- a/harbour/source/rdd/dbffpt/dbffpt1.c +++ b/harbour/source/rdd/dbffpt/dbffpt1.c @@ -4676,11 +4676,11 @@ static void hb_dbffptRegisterRDD( USHORT * pusRddId ) RDDFUNCS * pTable; USHORT * uiCount, uiRddId; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); uiRddId = hb_parni( 4 ); - HB_TRACE(HB_TR_DEBUG, ("DBFFPT_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + HB_TRACE(HB_TR_DEBUG, ("DBFFPT_GETFUNCTABLE(%p, %p)", uiCount, pTable)); if( pTable ) { diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index 4acbdb82bb..8a40115e8b 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -7627,8 +7627,8 @@ HB_FUNC( DBFNTX_GETFUNCTABLE ) RDDFUNCS * pTable; USHORT * uiCount, uiRddId; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); uiRddId = hb_parni( 4 ); if( pTable ) diff --git a/harbour/source/rdd/delim1.c b/harbour/source/rdd/delim1.c index ea70896663..3b7368e099 100644 --- a/harbour/source/rdd/delim1.c +++ b/harbour/source/rdd/delim1.c @@ -1511,14 +1511,17 @@ HB_FUNC( DELIM_GETFUNCTABLE ) RDDFUNCS * pTable; USHORT * uiCount; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - * uiCount = RDDFUNCSCOUNT; - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); - HB_TRACE(HB_TR_DEBUG, ("DELIM_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + HB_TRACE(HB_TR_DEBUG, ("DELIM_GETFUNCTABLE(%p, %p)", uiCount, pTable)); if( pTable ) + { + if( uiCount ) + * uiCount = RDDFUNCSCOUNT; hb_retni( hb_rddInherit( pTable, &delimTable, &delimSuper, NULL ) ); + } else hb_retni( FAILURE ); } diff --git a/harbour/source/rdd/sdf1.c b/harbour/source/rdd/sdf1.c index 48812a415c..ec99480cf5 100644 --- a/harbour/source/rdd/sdf1.c +++ b/harbour/source/rdd/sdf1.c @@ -1237,14 +1237,17 @@ HB_FUNC( SDF_GETFUNCTABLE ) RDDFUNCS * pTable; USHORT * uiCount; - uiCount = ( USHORT * ) hb_itemGetPtr( hb_param( 1, HB_IT_POINTER ) ); - * uiCount = RDDFUNCSCOUNT; - pTable = ( RDDFUNCS * ) hb_itemGetPtr( hb_param( 2, HB_IT_POINTER ) ); + uiCount = ( USHORT * ) hb_parptr( 1 ); + pTable = ( RDDFUNCS * ) hb_parptr( 2 ); - HB_TRACE(HB_TR_DEBUG, ("SDF_GETFUNCTABLE(%i, %p)", uiCount, pTable)); + HB_TRACE(HB_TR_DEBUG, ("SDF_GETFUNCTABLE(%p, %p)", uiCount, pTable)); if( pTable ) + { + if( uiCount ) + * uiCount = RDDFUNCSCOUNT; hb_retni( hb_rddInherit( pTable, &sdfTable, &sdfSuper, NULL ) ); + } else hb_retni( FAILURE ); } diff --git a/harbour/source/rtl/diskspac.c b/harbour/source/rtl/diskspac.c index 901e523784..1962fbc74e 100644 --- a/harbour/source/rtl/diskspac.c +++ b/harbour/source/rtl/diskspac.c @@ -194,40 +194,37 @@ HB_FUNC( DISKSPACE ) } #elif defined(HB_OS_UNIX) { -#if defined(__WATCOMC__) - struct stat st; char *szName = hb_parc( 1 ); + BOOL fFree = FALSE; if( !szName ) szName = ( char * ) "/"; - szName = hb_fileNameConv( hb_strdup( szName ) ); - - if( stat( szName, &st) == 0 ) - dSpace = ( double ) st.st_blocks * ( double ) st.st_blksize; else - bError = TRUE; + szName = ( char * ) hb_fsNameConv( ( BYTE * ) szName, &fFree ); - hb_xfree( szName ); -#else - struct statvfs st; - char *szName = hb_parc( 1 ); - - if( !szName ) - szName = ( char * ) "/"; - szName = ( char * ) hb_fileNameConv( hb_strdup( szName ) ); - - if( statvfs( szName, &st ) == 0 ) { - if( getuid() == 0 ) - dSpace = ( double ) st.f_bfree * ( double ) st.f_bsize; +#if defined(__WATCOMC__) + struct stat st; + if( stat( szName, &st) == 0 ) + dSpace = ( double ) st.st_blocks * ( double ) st.st_blksize; else - dSpace = ( double ) st.f_bavail * ( double ) st.f_bsize; - } - else - bError = TRUE; - - hb_xfree( szName ); + bError = TRUE; +#else + struct statvfs st; + if( statvfs( szName, &st ) == 0 ) + { + if( getuid() == 0 ) + dSpace = ( double ) st.f_bfree * ( double ) st.f_bsize; + else + dSpace = ( double ) st.f_bavail * ( double ) st.f_bsize; + } + else + bError = TRUE; #endif + } + + if( fFree ) + hb_xfree( szName ); } #endif diff --git a/harbour/source/rtl/disksphb.c b/harbour/source/rtl/disksphb.c index 2594a8fb6c..af08999686 100644 --- a/harbour/source/rtl/disksphb.c +++ b/harbour/source/rtl/disksphb.c @@ -330,8 +330,10 @@ HB_FUNC( HB_DISKSPACE ) #elif defined(HB_OS_UNIX) && !defined(__WATCOMC__) { struct statvfs sf; + BOOL fFree = FALSE; + + szPath = ( char * ) hb_fsNameConv( ( BYTE * ) szPath, &fFree ); - szPath = ( char * ) hb_fileNameConv( hb_strdup( szPath ) ); if( statvfs( szPath, &sf ) == 0 ) { switch( uiType ) @@ -357,7 +359,9 @@ HB_FUNC( HB_DISKSPACE ) } else hb_fsSetIOError( FALSE, 0 ); - hb_xfree( szPath ); + + if( fFree ) + hb_xfree( szPath ); } #else { diff --git a/harbour/source/rtl/file.c b/harbour/source/rtl/file.c index c268bed7a2..708ddef3cc 100644 --- a/harbour/source/rtl/file.c +++ b/harbour/source/rtl/file.c @@ -56,10 +56,11 @@ HB_EXPORT BOOL hb_fsFile( BYTE * pFilename ) { PHB_FFIND ffind; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsFile(%s)", ( char * ) pFilename)); - pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename ) ); + pFilename = hb_fsNameConv( pFilename, &fFree ); if( ( ffind = hb_fsFindFirst( ( char * ) pFilename, HB_FA_ALL ) ) != NULL ) { @@ -68,22 +69,36 @@ HB_EXPORT BOOL hb_fsFile( BYTE * pFilename ) return TRUE; } - hb_xfree( pFilename ); + if( fFree ) + hb_xfree( pFilename ); + return FALSE; } HB_EXPORT BOOL hb_fsIsDirectory( BYTE * pFilename ) { - BOOL bResult = FALSE; + BOOL bResult = FALSE, fFree; PHB_FFIND ffind; int iLen; HB_TRACE(HB_TR_DEBUG, ("hb_fsIsDirectory(%s)", ( char * ) pFilename)); - pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename ) ); + pFilename = hb_fsNameConv( pFilename, &fFree ); + iLen = strlen( ( char * ) pFilename ); while( iLen && strchr( OS_PATH_DELIMITER_LIST, pFilename[ iLen - 1 ] ) ) - pFilename[ --iLen ] = '\0'; + --iLen; + + if( pFilename[ iLen ] ) + { + if( fFree ) + pFilename[ iLen ] = '\0'; + else + { + pFilename = ( BYTE * ) hb_strndup( ( char * ) pFilename, iLen ); + fFree = TRUE; + } + } if( iLen && iLen <= _POSIX_PATH_MAX ) { @@ -95,6 +110,8 @@ HB_EXPORT BOOL hb_fsIsDirectory( BYTE * pFilename ) } } - hb_xfree( pFilename ); + if( fFree ) + hb_xfree( pFilename ); + return bResult; } diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 94d85193e7..379a78c31d 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -638,10 +638,11 @@ HB_EXPORT FHANDLE hb_fsPOpen( BYTE * pFilename, BYTE * pMode ) HB_EXPORT FHANDLE hb_fsOpen( BYTE * pFilename, USHORT uiFlags ) { FHANDLE hFileHandle; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsOpen(%p, %hu)", pFilename, uiFlags)); - pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename) ); + pFilename = hb_fsNameConv( pFilename, &fFree ); #if defined(HB_WIN32_IO) { @@ -685,7 +686,8 @@ HB_EXPORT FHANDLE hb_fsOpen( BYTE * pFilename, USHORT uiFlags ) #endif - hb_xfree( pFilename ); + if( fFree ) + hb_xfree( pFilename ); return hFileHandle; } @@ -693,10 +695,11 @@ HB_EXPORT FHANDLE hb_fsOpen( BYTE * pFilename, USHORT uiFlags ) HB_EXPORT FHANDLE hb_fsCreate( BYTE * pFilename, USHORT uiAttr ) { FHANDLE hFileHandle; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsCreate(%p, %hu)", pFilename, uiAttr)); - pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename ) ); + pFilename = hb_fsNameConv( pFilename, &fFree ); #if defined(HB_WIN32_IO) { @@ -734,7 +737,8 @@ HB_EXPORT FHANDLE hb_fsCreate( BYTE * pFilename, USHORT uiAttr ) #endif - hb_xfree( pFilename ); + if( fFree ) + hb_xfree( pFilename ); return hFileHandle; } @@ -748,10 +752,11 @@ HB_EXPORT FHANDLE hb_fsCreate( BYTE * pFilename, USHORT uiAttr ) HB_EXPORT FHANDLE hb_fsCreateEx( BYTE * pFilename, USHORT uiAttr, USHORT uiFlags ) { FHANDLE hFileHandle; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsCreateEx(%p, %hu, %hu)", pFilename, uiAttr, uiFlags)); - pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename ) ); + pFilename = hb_fsNameConv( pFilename, &fFree ); #if defined( HB_WIN32_IO ) { @@ -787,7 +792,8 @@ HB_EXPORT FHANDLE hb_fsCreateEx( BYTE * pFilename, USHORT uiAttr, USHORT uiFlags #endif - hb_xfree( pFilename ); + if( fFree ) + hb_xfree( pFilename ); return hFileHandle; } @@ -1712,10 +1718,11 @@ HB_EXPORT ULONG hb_fsTell( FHANDLE hFileHandle ) HB_EXPORT BOOL hb_fsDelete( BYTE * pFilename ) { BOOL bResult; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsDelete(%s)", (char*) pFilename)); - pFilename = hb_fileNameConv( hb_strdup( ( char * ) pFilename ) ); + pFilename = hb_fsNameConv( pFilename, &fFree ); #if defined(HB_OS_WIN_32) @@ -1739,7 +1746,8 @@ HB_EXPORT BOOL hb_fsDelete( BYTE * pFilename ) #endif - hb_xfree( pFilename ) ; + if( fFree ) + hb_xfree( pFilename ); return bResult; } @@ -1747,11 +1755,12 @@ HB_EXPORT BOOL hb_fsDelete( BYTE * pFilename ) HB_EXPORT BOOL hb_fsRename( BYTE * pOldName, BYTE * pNewName ) { BOOL bResult; + BOOL fFreeOld, fFreeNew; HB_TRACE(HB_TR_DEBUG, ("hb_fsRename(%s, %s)", (char*) pOldName, (char*) pNewName)); - pOldName = hb_fileNameConv( hb_strdup( ( char * ) pOldName ) ); - pNewName = hb_fileNameConv( hb_strdup( ( char * ) pNewName ) ); + pOldName = hb_fsNameConv( pOldName, &fFreeOld ); + pNewName = hb_fsNameConv( pNewName, &fFreeNew ); #if defined(HB_OS_WIN_32) @@ -1770,8 +1779,10 @@ HB_EXPORT BOOL hb_fsRename( BYTE * pOldName, BYTE * pNewName ) #endif - hb_xfree( pOldName ) ; - hb_xfree( pNewName ) ; + if( fFreeOld ) + hb_xfree( pOldName ); + if( fFreeNew ) + hb_xfree( pNewName ); return bResult; } @@ -1779,10 +1790,11 @@ HB_EXPORT BOOL hb_fsRename( BYTE * pOldName, BYTE * pNewName ) HB_EXPORT BOOL hb_fsMkDir( BYTE * pDirname ) { BOOL bResult; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsMkDir(%s)", (char*) pDirname)); - pDirname = hb_fileNameConv( hb_strdup( ( char * ) pDirname ) ); + pDirname = hb_fsNameConv( pDirname, &fFree ); HB_TRACE(HB_TR_DEBUG, ("hb_fsMkDir(%s)", (char*) pDirname)); @@ -1809,7 +1821,8 @@ HB_EXPORT BOOL hb_fsMkDir( BYTE * pDirname ) #endif - hb_xfree(pDirname) ; + if( fFree ) + hb_xfree( pDirname ); return bResult; } @@ -1817,10 +1830,11 @@ HB_EXPORT BOOL hb_fsMkDir( BYTE * pDirname ) HB_EXPORT BOOL hb_fsChDir( BYTE * pDirname ) { BOOL bResult; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsChDir(%s)", (char*) pDirname)); - pDirname = hb_fileNameConv( hb_strdup( ( char * ) pDirname ) ); + pDirname = hb_fsNameConv( pDirname, &fFree ); #if defined(HB_OS_WIN_32) @@ -1839,7 +1853,8 @@ HB_EXPORT BOOL hb_fsChDir( BYTE * pDirname ) #endif - hb_xfree( pDirname ); + if( fFree ) + hb_xfree( pDirname ); return bResult; } @@ -1847,10 +1862,11 @@ HB_EXPORT BOOL hb_fsChDir( BYTE * pDirname ) HB_EXPORT BOOL hb_fsRmDir( BYTE * pDirname ) { BOOL bResult; + BOOL fFree; HB_TRACE(HB_TR_DEBUG, ("hb_fsRmDir(%s)", (char*) pDirname)); - pDirname = hb_fileNameConv( hb_strdup( ( char * ) pDirname ) ); + pDirname = hb_fsNameConv( pDirname, &fFree ); #if defined(HB_OS_WIN_32) @@ -1869,7 +1885,8 @@ HB_EXPORT BOOL hb_fsRmDir( BYTE * pDirname ) #endif - hb_xfree( pDirname ); + if( fFree ) + hb_xfree( pDirname ); return bResult; } @@ -1903,7 +1920,7 @@ HB_EXPORT USHORT hb_fsCurDirBuff( USHORT uiDrive, BYTE * pbyBuffer, ULONG ulLen /* * do not cover this code by OS_HAS_DRIVE_LETTER macro * It will allow us to add drive emulation in hb_fsCurDrv()/hb_fsChDrv() - * and hb_fileNameConv() + * and hb_fsNameConv() */ #if !defined(HB_OS_OS2) && !defined(__MINGW32__) if( uiDrive ) @@ -2326,79 +2343,113 @@ HB_EXPORT BOOL hb_fsEof( FHANDLE hFileHandle ) #endif } -HB_EXPORT BYTE * hb_fileNameConv( char *str ) { +HB_EXPORT BYTE * hb_fsNameConv( BYTE * szFileName, BOOL * pfFree ) +{ /* Convert file and dir case. The allowed SET options are: - LOWER - Convert all caracters of file to lower - UPPER - Convert all caracters of file to upper - MIXED - Leave as is + LOWER - Convert all caracters of file to lower + UPPER - Convert all caracters of file to upper + MIXED - Leave as is The allowed environment options are: - FILECASE - define the case of file - DIRCASE - define the case of path - DIRSEPARATOR - define separator of path (Ex. "/") + FILECASE - define the case of file + DIRCASE - define the case of path + DIRSEPARATOR - define separator of path (Ex. "/") + TRIMFILENAME - strip trailing and leading spaces (also from extension) */ - char *filename; - ULONG ulDirLen, ulFileLen; - /* strip trailing and leading spaces */ - if( hb_set.HB_SET_TRIMFILENAME ) + if( hb_set.HB_SET_TRIMFILENAME || + hb_set.HB_SET_DIRSEPARATOR != '\\' || + hb_set.HB_SET_FILECASE != HB_SET_CASE_MIXED || + hb_set.HB_SET_DIRCASE != HB_SET_CASE_MIXED ) { - char *szFileTrim; + PHB_FNAME pFileName; ULONG ulLen; - ulLen = hb_strRTrimLen( str, strlen( str ), FALSE ); - szFileTrim = hb_strLTrim( str, &ulLen ); - if ( str != szFileTrim ) + if( pfFree ) { - memmove( str, szFileTrim, ulLen ); + szFileName = ( BYTE * ) hb_strdup( ( char * ) szFileName ); + *pfFree = TRUE; } - str[ulLen] = '\0'; - } - if( hb_set.HB_SET_DIRSEPARATOR != '\\' ) - { - char *p = str; - while( *p ) + if( hb_set.HB_SET_DIRSEPARATOR != '\\' ) { - if( *p == '\\' ) + BYTE *p = szFileName; + while( *p ) { - *p = hb_set.HB_SET_DIRSEPARATOR; + if( *p == '\\' ) + *p = hb_set.HB_SET_DIRSEPARATOR; + p++; } - p++; } - } - /* Look for filename (Last "\" or DIRSEPARATOR) */ - if( ( filename = strrchr( str, hb_set.HB_SET_DIRSEPARATOR ) ) != NULL ) - { - filename++; - } - else - { - filename = str; - } - ulFileLen = strlen( filename ); - ulDirLen = filename - str; + pFileName = hb_fsFNameSplit( ( char * ) szFileName ); - /* FILECASE */ - if( ulFileLen > 0 ) - { + /* strip trailing and leading spaces */ + if( hb_set.HB_SET_TRIMFILENAME ) + { + if( pFileName->szName ) + { + ulLen = strlen( pFileName->szName ); + ulLen = hb_strRTrimLen( pFileName->szName, ulLen, FALSE ); + pFileName->szName = hb_strLTrim( pFileName->szName, &ulLen ); + pFileName->szName[ulLen] = '\0'; + } + if( pFileName->szExtension ) + { + ulLen = strlen( pFileName->szExtension ); + ulLen = hb_strRTrimLen( pFileName->szExtension, ulLen, FALSE ); + pFileName->szExtension = hb_strLTrim( pFileName->szExtension, &ulLen ); + pFileName->szExtension[ulLen] = '\0'; + } + } + + /* FILECASE */ if( hb_set.HB_SET_FILECASE == HB_SET_CASE_LOWER ) - hb_strLower( filename, strlen(filename) ); + { + if( pFileName->szName ) + hb_strLower( pFileName->szName, strlen( pFileName->szName ) ); + if( pFileName->szExtension ) + hb_strLower( pFileName->szExtension, strlen( pFileName->szExtension ) ); + } else if( hb_set.HB_SET_FILECASE == HB_SET_CASE_UPPER ) - hb_strUpper( filename, strlen(filename) ); + { + if( pFileName->szName ) + hb_strUpper( pFileName->szName, strlen( pFileName->szName ) ); + if( pFileName->szExtension ) + hb_strUpper( pFileName->szExtension, strlen( pFileName->szExtension ) ); + } + + /* DIRCASE */ + if( pFileName->szPath ) + { + if( hb_set.HB_SET_DIRCASE == HB_SET_CASE_LOWER ) + hb_strLower( pFileName->szPath, strlen( pFileName->szPath ) ); + else if( hb_set.HB_SET_DIRCASE == HB_SET_CASE_UPPER ) + hb_strUpper( pFileName->szPath, strlen( pFileName->szPath ) ); + } + + hb_fsFNameMerge( ( char * ) szFileName, pFileName ); + } + else if( pfFree ) + *pfFree = FALSE; + + return szFileName; +} + +HB_EXPORT BYTE * hb_fileNameConv( char * szFileName ) +{ + BOOL fFree; + BYTE * szNew; + + szNew = hb_fsNameConv( ( BYTE * ) szFileName, &fFree ); + if( fFree ) + { + hb_strncpy( szFileName, ( char * ) szNew, strlen( szFileName ) ); + hb_xfree( szNew ); } - /* DIRCASE */ - if( ulDirLen > 0 ) - { - if( hb_set.HB_SET_DIRCASE == HB_SET_CASE_LOWER ) - hb_strLower( str, ulDirLen ); - else if( hb_set.HB_SET_DIRCASE == HB_SET_CASE_UPPER ) - hb_strUpper( str, ulDirLen ); - } - return ( BYTE * ) str; + return ( BYTE * ) szFileName; } HB_EXPORT BOOL hb_fsDisableWaitLocks( int iSet ) diff --git a/harbour/source/rtl/fstemp.c b/harbour/source/rtl/fstemp.c index 9e4eb7631a..12bf37678b 100644 --- a/harbour/source/rtl/fstemp.c +++ b/harbour/source/rtl/fstemp.c @@ -229,7 +229,7 @@ HB_EXPORT FHANDLE hb_fsCreateTemp( const BYTE * pszDir, const BYTE * pszPrefix, d = modf( d, &x ); pszName[ iLen++ ] = n + ( n > 9 ? 'a' - 10 : '0' ); } - hb_fileNameConv( ( char * ) pszName ); + hb_fsNameConv( pszName, NULL ); fd = hb_fsCreateEx( pszName, uiAttr, FO_EXCLUSIVE | FO_EXCL ); } diff --git a/harbour/source/rtl/seconds.c b/harbour/source/rtl/seconds.c index d47434dce0..fbb41ebe4c 100644 --- a/harbour/source/rtl/seconds.c +++ b/harbour/source/rtl/seconds.c @@ -55,7 +55,7 @@ #include -#if defined( HB_OS_BSD) +#if ( defined( HB_OS_BSD ) || defined( HB_OS_LINUX ) ) && !defined( __WATCOMC__ ) #include #else #include @@ -66,8 +66,66 @@ #endif #if defined( HB_OS_WIN_32 ) #include +#elif defined(_MSC_VER) + #define timeb _timeb + #define ftime _ftime #endif +HB_EXPORT void hb_dateTimeStamp( LONG * plJulian, LONG * plMilliSec ) +{ +#if defined(HB_OS_WIN_32) + SYSTEMTIME st; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateTimeStamp(%p,%p)", plJulian, plMilliSec)); + + GetLocalTime( &st ); + + *plJulian = hb_dateEncode( st.wYear, st.wMonth, st.wDay ); + *plMilliSec = ( ( st.wHour * 60 + st.wMinute ) * 60 + st.wSecond ) * 1000 + + st.wMilliseconds; +#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) + struct timeval tv; + struct tm st; + time_t seconds; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateTimeStamp(%p,%p)", plJulian, plMilliSec)); + + gettimeofday( &tv, NULL ); + seconds = tv.tv_sec; + localtime_r( &seconds, &st ); + *plJulian = hb_dateEncode( st.tm_year + 1900, st.tm_mon + 1, st.tm_mday ); + *plMilliSec = ( ( st.tm_hour * 60 + st.tm_min ) * 60 + st.tm_sec ) * 1000 + + tv.tv_usec / 1000; +#elif defined( HB_OS_BSD ) + struct timeval tv; + struct tm * st; + time_t seconds; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateTimeStamp(%p,%p)", plJulian, plMilliSec)); + + gettimeofday( &tv, NULL ); + seconds = tv.tv_sec; + st = localtime( &seconds ); + *plJulian = hb_dateEncode( st->tm_year + 1900, st->tm_mon + 1, st->tm_mday ); + *plMilliSec = ( ( st->tm_hour * 60 + st->tm_min ) * 60 + st->tm_sec ) * 1000 + + tv->tv_usec / 1000.0; +#else + struct timeb tb; + struct tm * st; + time_t seconds; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateTimeStamp(%p,%p)", plJulian, plMilliSec)); + + ftime( &tb ); + seconds = tb.time; + st = localtime( &seconds ); + + *plJulian = hb_dateEncode( st->tm_year + 1900, st->tm_mon + 1, st->tm_mday ); + *plMilliSec = ( ( st->tm_hour * 60 + st->tm_min ) * 60 + st->tm_sec ) * 1000 + + tb.millitm; +#endif +} + HB_EXPORT double hb_dateSeconds( void ) { #if defined(HB_OS_WIN_32) @@ -81,39 +139,49 @@ HB_EXPORT double hb_dateSeconds( void ) ( SystemTime.wMinute * 60 ) + SystemTime.wSecond + ( ( double ) SystemTime.wMilliseconds / 1000.0 ); -#else -#if defined(_MSC_VER) - #define timeb _timeb - #define ftime _ftime -#endif -#if defined(HB_OS_BSD) +#elif defined( HB_OS_LINUX ) && !defined( __WATCOMC__ ) struct timeval tv; - struct timezone tz; -#else - struct timeb tb; -#endif + struct tm oTime; time_t seconds; - time_t fraction; - struct tm * oTime; HB_TRACE(HB_TR_DEBUG, ("hb_dateSeconds()")); -#if defined(HB_OS_BSD) - gettimeofday( &tv, &tz ); - seconds = tv.tv_sec - tz.tz_minuteswest * 60; - fraction = tv.tv_usec / 1000U; + gettimeofday( &tv, NULL ); + seconds = tv.tv_sec; + localtime_r( &seconds, &oTime ); + return ( oTime.tm_hour * 3600 ) + + ( oTime.tm_min * 60 ) + + oTime.tm_sec + + ( ( double ) tv.tv_usec / 1000000.0 ); +#elif defined( HB_OS_BSD ) + struct timeval tv; + struct tm * oTime; + time_t seconds; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateSeconds()")); + + gettimeofday( &tv, NULL ); + seconds = tv.tv_sec; + oTime = localtime( &seconds ); + return ( oTime->tm_hour * 3600 ) + + ( oTime->tm_min * 60 ) + + oTime->tm_sec + + ( ( double ) tv.tv_usec / 1000000.0 ); #else + struct timeb tb; + struct tm * oTime; + time_t seconds; + + HB_TRACE(HB_TR_DEBUG, ("hb_dateSeconds()")); + ftime( &tb ); seconds = tb.time; - fraction = tb.millitm; -#endif - oTime = localtime( &seconds ); return ( oTime->tm_hour * 3600 ) + ( oTime->tm_min * 60 ) + oTime->tm_sec + - ( ( double ) fraction / 1000.0 ); + ( ( double ) tb.millitm / 1000.0 ); #endif }