diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a9a73ff3f9..74e3a08d8f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,20 @@ +19990903-08:00 GMT+1 Victor Szel + * include/hbdefs.h + include/extend.h + ! IT_OBJECT() checked for IT_ARRAY type, correct to IT_OBJECT, which + is equal to IT_ARRAY, so there was no bug, but it's not a good practice + to take shortcuts like this. + * Type checking macros moved to extend.h from hbdefs.h + * source/vm/hvm.c + % Variable optimed out in HB_PCOUNT(). + * source/compiler/harbour.y + source/hbpp/stdalone/hbpp.c + source/rtl/filesys.c + ! hb_fsFNameSplit() now leaves the szName pointer to NULL if there was + no name specified. + ! hb_fsFNameMerge() now handles when szName is NULL. + * Some variable names made consistent in the functions above. + 19990902-21:15 EDT David G. Holm * source/rtl/filesys.c ! Added missing semi-colon for line 1842. diff --git a/harbour/include/extend.h b/harbour/include/extend.h index b849c20556..51f80b5168 100644 --- a/harbour/include/extend.h +++ b/harbour/include/extend.h @@ -37,7 +37,7 @@ #include "fm.api" #endif -/* items types */ +/* items types and type checking macros */ #define IT_NIL ( ( WORD ) 0x0000 ) #define IT_INTEGER ( ( WORD ) 0x0002 ) #define IT_LONG ( ( WORD ) 0x0008 ) @@ -57,6 +57,34 @@ #define IT_NUMERIC ( IT_INTEGER | IT_LONG | IT_DOUBLE ) #define IT_ANY ( ( WORD ) 0xFFFF ) +#define IS_BYREF( p ) ( ( p )->type & IT_BYREF ) +#define IS_OF_TYPE( p, t ) ( ( ( p )->type & ~IT_BYREF ) == t ) +#define IS_ARRAY( p ) IS_OF_TYPE( p, IT_ARRAY ) +#define IS_NIL( p ) IS_OF_TYPE( p, IT_NIL ) +#define IS_BLOCK( p ) IS_OF_TYPE( p, IT_BLOCK ) +#define IS_DATE( p ) IS_OF_TYPE( p, IT_DATE ) +#define IS_DOUBLE( p ) IS_OF_TYPE( p, IT_DOUBLE ) +#define IS_INTEGER( p ) IS_OF_TYPE( p, IT_INTEGER ) +#define IS_LOGICAL( p ) IS_OF_TYPE( p, IT_LOGICAL ) +#define IS_LONG( p ) IS_OF_TYPE( p, IT_LONG ) +#define IS_NUMERIC( p ) ( ( p )->type & IT_NUMERIC ) +#define IS_OBJECT( p ) IS_OF_TYPE( p, IT_OBJECT ) +#define IS_STRING( p ) IS_OF_TYPE( p, IT_STRING ) +#define IS_SYMBOL( p ) IS_OF_TYPE( p, IT_SYMBOL ) +#define IS_MEMVAR( p ) IS_OF_TYPE( p, IT_MEMVAR ) + +#define ISNIL( n ) ( hb_param( n, IT_NIL ) != NULL ) +#define ISCHAR( n ) ( hb_param( n, IT_STRING ) != NULL ) +#define ISNUM( n ) ( hb_param( n, IT_NUMERIC ) != NULL ) +#define ISLOG( n ) ( hb_param( n, IT_LOGICAL ) != NULL ) +#define ISDATE( n ) ( hb_param( n, IT_DATE ) != NULL ) +#define ISMEMO( n ) ( hb_param( n, IT_MEMO ) != NULL ) +#define ISBYREF( n ) ( hb_parinfo( n ) & IT_BYREF ) /* NOTE: Intentionally using a different method */ +#define ISARRAY( n ) ( hb_param( n, IT_ARRAY ) != NULL ) + +#define PCOUNT hb_pcount() +#define ALENGTH( n ) hb_parinfa( n, 0 ) + /* forward declarations */ struct _HB_CODEBLOCK; struct _HB_BASEARRAY; diff --git a/harbour/include/hbdefs.h b/harbour/include/hbdefs.h index cead380f20..53f3c9b13e 100644 --- a/harbour/include/hbdefs.h +++ b/harbour/include/hbdefs.h @@ -114,32 +114,4 @@ typedef char SYMBOLSCOPE; /* stores symbol's scope */ #define HB_SYMBOL_UNUSED( symbol ) ( void ) symbol -#define IS_BYREF( p ) ( ( p )->type & IT_BYREF ) -#define IS_OF_TYPE( p, t ) ( ( ( p )->type & ~IT_BYREF ) == t ) -#define IS_ARRAY( p ) IS_OF_TYPE( p, IT_ARRAY ) -#define IS_NIL( p ) IS_OF_TYPE( p, IT_NIL ) -#define IS_BLOCK( p ) IS_OF_TYPE( p, IT_BLOCK ) -#define IS_DATE( p ) IS_OF_TYPE( p, IT_DATE ) -#define IS_DOUBLE( p ) IS_OF_TYPE( p, IT_DOUBLE ) -#define IS_INTEGER( p ) IS_OF_TYPE( p, IT_INTEGER ) -#define IS_LOGICAL( p ) IS_OF_TYPE( p, IT_LOGICAL ) -#define IS_LONG( p ) IS_OF_TYPE( p, IT_LONG ) -#define IS_NUMERIC( p ) ( ( p )->type & IT_NUMERIC ) -#define IS_OBJECT( p ) IS_OF_TYPE( p, IT_ARRAY ) -#define IS_STRING( p ) IS_OF_TYPE( p, IT_STRING ) -#define IS_SYMBOL( p ) IS_OF_TYPE( p, IT_SYMBOL ) -#define IS_MEMVAR( p ) IS_OF_TYPE( p, IT_MEMVAR ) - -#define ISNIL( n ) ( hb_param( n, IT_NIL ) != NULL ) -#define ISCHAR( n ) ( hb_param( n, IT_STRING ) != NULL ) -#define ISNUM( n ) ( hb_param( n, IT_NUMERIC ) != NULL ) -#define ISLOG( n ) ( hb_param( n, IT_LOGICAL ) != NULL ) -#define ISDATE( n ) ( hb_param( n, IT_DATE ) != NULL ) -#define ISMEMO( n ) ( hb_param( n, IT_MEMO ) != NULL ) -#define ISBYREF( n ) ( hb_parinfo( n ) & IT_BYREF ) /* Intentionally using a different method */ -#define ISARRAY( n ) ( hb_param( n, IT_ARRAY ) != NULL ) - -#define PCOUNT hb_pcount() -#define ALENGTH( n ) hb_parinfa( n, 0 ) - #endif /* HB_DEFS_H_ */ diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index c7645449f1..fd630379a5 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -5348,57 +5348,57 @@ static void LoopEnd( void ) #define IS_PATH_SEP( c ) ( strchr( OS_PATH_DELIMITER_LIST, ( c ) ) != NULL ) /* Split given filename into path, name and extension */ -PHB_FNAME hb_fsFNameSplit( char * szFilename ) +PHB_FNAME hb_fsFNameSplit( char * szFileName ) { - PHB_FNAME pName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); + PHB_FNAME pFileName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); - int iLen = strlen( szFilename ); + int iLen = strlen( szFileName ); int iSlashPos; int iDotPos; int iPos; - pName->szPath = - pName->szName = - pName->szExtension = NULL; + pFileName->szPath = + pFileName->szName = + pFileName->szExtension = NULL; iSlashPos = iLen - 1; iPos = 0; - while( iSlashPos >= 0 && !IS_PATH_SEP( szFilename[ iSlashPos ] ) ) + while( iSlashPos >= 0 && !IS_PATH_SEP( szFileName[ iSlashPos ] ) ) --iSlashPos; if( iSlashPos == 0 ) { /* root path -> \filename */ - pName->szBuffer[ 0 ] = OS_PATH_DELIMITER; - pName->szBuffer[ 1 ] = '\0'; - pName->szPath = pName->szBuffer; + pFileName->szBuffer[ 0 ] = OS_PATH_DELIMITER; + pFileName->szBuffer[ 1 ] = '\0'; + pFileName->szPath = pFileName->szBuffer; iPos = 2; /* first free position after the slash */ } else if( iSlashPos > 0 ) { /* If we are after a drive letter let's keep the following backslash */ if( IS_PATH_SEP( ':' ) && - ( szFilename[ iSlashPos ] == ':' || szFilename[ iSlashPos - 1 ] == ':' ) ) + ( szFileName[ iSlashPos ] == ':' || szFileName[ iSlashPos - 1 ] == ':' ) ) { /* path with separator -> d:\path\filename or d:path\filename */ - memcpy( pName->szBuffer, szFilename, iSlashPos + 1 ); - pName->szBuffer[ iSlashPos + 1 ] = '\0'; + memcpy( pFileName->szBuffer, szFileName, iSlashPos + 1 ); + pFileName->szBuffer[ iSlashPos + 1 ] = '\0'; iPos = iSlashPos + 2; /* first free position after the slash */ } else { /* path with separator -> path\filename */ - memcpy( pName->szBuffer, szFilename, iSlashPos ); - pName->szBuffer[ iSlashPos ] = '\0'; + memcpy( pFileName->szBuffer, szFileName, iSlashPos ); + pFileName->szBuffer[ iSlashPos ] = '\0'; iPos = iSlashPos + 1; /* first free position after the slash */ } - pName->szPath = pName->szBuffer; + pFileName->szPath = pFileName->szBuffer; } iDotPos = iLen - 1; - while( iDotPos > iSlashPos && szFilename[ iDotPos ] != '.' ) + while( iDotPos > iSlashPos && szFileName[ iDotPos ] != '.' ) --iDotPos; if( ( iDotPos - iSlashPos ) > 1 ) @@ -5409,15 +5409,15 @@ PHB_FNAME hb_fsFNameSplit( char * szFilename ) 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'; + pFileName->szExtension = pFileName->szBuffer + iPos; + pFileName->szBuffer[ iPos++ ] = '.'; + pFileName->szBuffer[ iPos++ ] = '\0'; } else { - pName->szExtension = pName->szBuffer + iPos; + pFileName->szExtension = pFileName->szBuffer + iPos; /* copy rest of the string with terminating ZERO character */ - memcpy( pName->szExtension, szFilename + iDotPos + 1, iLen - iDotPos ); + memcpy( pFileName->szExtension, szFileName + iDotPos + 1, iLen - iDotPos ); iPos += iLen - iDotPos; } } @@ -5425,18 +5425,21 @@ PHB_FNAME hb_fsFNameSplit( char * szFilename ) /* 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'; + if( ( iDotPos - iSlashPos - 1 ) > 0 ) + { + pFileName->szName = pFileName->szBuffer + iPos; + memcpy( pFileName->szName, szFileName + iSlashPos + 1, iDotPos - iSlashPos - 1 ); + pFileName->szName[ iDotPos - iSlashPos - 1 ] = '\0'; + } /* DEBUG - printf( "\nFilename: %s\n", szFilename ); - printf( "\n szPath: %s\n", pName->szPath ); - printf( "\n szName: %s\n", pName->szName ); - printf( "\n szExt: %s\n", pName->szExtension ); + printf( "\nFilename: %s\n", szFileName ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); */ - return pName; + return pFileName; } /* This function joins path, name and extension into a string with a filename */ @@ -5462,16 +5465,20 @@ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) szFileName[ iLen ] = '\0'; } } - strcpy( szFileName + iLen, pFileName->szName ); + if( pFileName->szName ) + strcpy( szFileName + iLen, pFileName->szName ); } else - strcpy( szFileName, pFileName->szName ); + { + if( pFileName->szName ) + strcpy( szFileName, pFileName->szName ); + } if( pFileName->szExtension ) { int iLen = strlen( szFileName ); - if( !( pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen-1 ] == '.') ) + if( !( pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen - 1 ] == '.') ) { /* add extension separator only when extansion doesn't contain it */ szFileName[ iLen++ ] = '.'; @@ -5480,6 +5487,14 @@ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) strcpy( szFileName + iLen, pFileName->szExtension ); } +/* DEBUG + printf( "\nMERGE:\n" ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); + printf( "\nFilename result: %s\n", szFileName ); +*/ + return szFileName; } diff --git a/harbour/source/hbpp/stdalone/hbpp.c b/harbour/source/hbpp/stdalone/hbpp.c index 1998706d0d..e634a586af 100644 --- a/harbour/source/hbpp/stdalone/hbpp.c +++ b/harbour/source/hbpp/stdalone/hbpp.c @@ -430,57 +430,57 @@ void GenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarni #define IS_PATH_SEP( c ) ( strchr( OS_PATH_DELIMITER_LIST, ( c ) ) != NULL ) /* Split given filename into path, name and extension */ -PHB_FNAME hb_fsFNameSplit( char * szFilename ) +PHB_FNAME hb_fsFNameSplit( char * szFileName ) { - PHB_FNAME pName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); + PHB_FNAME pFileName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); - int iLen = strlen( szFilename ); + int iLen = strlen( szFileName ); int iSlashPos; int iDotPos; int iPos; - pName->szPath = - pName->szName = - pName->szExtension = NULL; + pFileName->szPath = + pFileName->szName = + pFileName->szExtension = NULL; iSlashPos = iLen - 1; iPos = 0; - while( iSlashPos >= 0 && !IS_PATH_SEP( szFilename[ iSlashPos ] ) ) + while( iSlashPos >= 0 && !IS_PATH_SEP( szFileName[ iSlashPos ] ) ) --iSlashPos; if( iSlashPos == 0 ) { /* root path -> \filename */ - pName->szBuffer[ 0 ] = OS_PATH_DELIMITER; - pName->szBuffer[ 1 ] = '\0'; - pName->szPath = pName->szBuffer; + pFileName->szBuffer[ 0 ] = OS_PATH_DELIMITER; + pFileName->szBuffer[ 1 ] = '\0'; + pFileName->szPath = pFileName->szBuffer; iPos = 2; /* first free position after the slash */ } else if( iSlashPos > 0 ) { /* If we are after a drive letter let's keep the following backslash */ if( IS_PATH_SEP( ':' ) && - ( szFilename[ iSlashPos ] == ':' || szFilename[ iSlashPos - 1 ] == ':' ) ) + ( szFileName[ iSlashPos ] == ':' || szFileName[ iSlashPos - 1 ] == ':' ) ) { /* path with separator -> d:\path\filename or d:path\filename */ - memcpy( pName->szBuffer, szFilename, iSlashPos + 1 ); - pName->szBuffer[ iSlashPos + 1 ] = '\0'; + memcpy( pFileName->szBuffer, szFileName, iSlashPos + 1 ); + pFileName->szBuffer[ iSlashPos + 1 ] = '\0'; iPos = iSlashPos + 2; /* first free position after the slash */ } else { /* path with separator -> path\filename */ - memcpy( pName->szBuffer, szFilename, iSlashPos ); - pName->szBuffer[ iSlashPos ] = '\0'; + memcpy( pFileName->szBuffer, szFileName, iSlashPos ); + pFileName->szBuffer[ iSlashPos ] = '\0'; iPos = iSlashPos + 1; /* first free position after the slash */ } - pName->szPath = pName->szBuffer; + pFileName->szPath = pFileName->szBuffer; } iDotPos = iLen - 1; - while( iDotPos > iSlashPos && szFilename[ iDotPos ] != '.' ) + while( iDotPos > iSlashPos && szFileName[ iDotPos ] != '.' ) --iDotPos; if( ( iDotPos - iSlashPos ) > 1 ) @@ -491,15 +491,15 @@ PHB_FNAME hb_fsFNameSplit( char * szFilename ) 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'; + pFileName->szExtension = pFileName->szBuffer + iPos; + pFileName->szBuffer[ iPos++ ] = '.'; + pFileName->szBuffer[ iPos++ ] = '\0'; } else { - pName->szExtension = pName->szBuffer + iPos; + pFileName->szExtension = pFileName->szBuffer + iPos; /* copy rest of the string with terminating ZERO character */ - memcpy( pName->szExtension, szFilename + iDotPos + 1, iLen - iDotPos ); + memcpy( pFileName->szExtension, szFileName + iDotPos + 1, iLen - iDotPos ); iPos += iLen - iDotPos; } } @@ -507,11 +507,21 @@ PHB_FNAME hb_fsFNameSplit( char * szFilename ) /* 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'; + if( ( iDotPos - iSlashPos - 1 ) > 0 ) + { + pFileName->szName = pFileName->szBuffer + iPos; + memcpy( pFileName->szName, szFileName + iSlashPos + 1, iDotPos - iSlashPos - 1 ); + pFileName->szName[ iDotPos - iSlashPos - 1 ] = '\0'; + } - return pName; +/* DEBUG + printf( "\nFilename: %s\n", szFileName ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); +*/ + + return pFileName; } /* This function joins path, name and extension into a string with a filename */ @@ -537,16 +547,20 @@ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) szFileName[ iLen ] = '\0'; } } - strcpy( szFileName + iLen, pFileName->szName ); + if( pFileName->szName ) + strcpy( szFileName + iLen, pFileName->szName ); } else - strcpy( szFileName, pFileName->szName ); + { + if( pFileName->szName ) + strcpy( szFileName, pFileName->szName ); + } if( pFileName->szExtension ) { int iLen = strlen( szFileName ); - if( !( pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen-1 ] == '.') ) + if( !( pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen - 1 ] == '.') ) { /* add extension separator only when extansion doesn't contain it */ szFileName[ iLen++ ] = '.'; @@ -555,6 +569,14 @@ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) strcpy( szFileName + iLen, pFileName->szExtension ); } +/* DEBUG + printf( "\nMERGE:\n" ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); + printf( "\nFilename result: %s\n", szFileName ); +*/ + return szFileName; } diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 6faeceb250..46d4671793 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -1288,57 +1288,57 @@ HARBOUR HB_W2BIN( void ) #define IS_PATH_SEP( c ) ( strchr( OS_PATH_DELIMITER_LIST, ( c ) ) != NULL ) /* Split given filename into path, name and extension */ -PHB_FNAME hb_fsFNameSplit( char * szFilename ) +PHB_FNAME hb_fsFNameSplit( char * szFileName ) { - PHB_FNAME pName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); + PHB_FNAME pFileName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) ); - int iLen = strlen( szFilename ); + int iLen = strlen( szFileName ); int iSlashPos; int iDotPos; int iPos; - pName->szPath = - pName->szName = - pName->szExtension = NULL; + pFileName->szPath = + pFileName->szName = + pFileName->szExtension = NULL; iSlashPos = iLen - 1; iPos = 0; - while( iSlashPos >= 0 && !IS_PATH_SEP( szFilename[ iSlashPos ] ) ) + while( iSlashPos >= 0 && !IS_PATH_SEP( szFileName[ iSlashPos ] ) ) --iSlashPos; if( iSlashPos == 0 ) { /* root path -> \filename */ - pName->szBuffer[ 0 ] = OS_PATH_DELIMITER; - pName->szBuffer[ 1 ] = '\0'; - pName->szPath = pName->szBuffer; + pFileName->szBuffer[ 0 ] = OS_PATH_DELIMITER; + pFileName->szBuffer[ 1 ] = '\0'; + pFileName->szPath = pFileName->szBuffer; iPos = 2; /* first free position after the slash */ } else if( iSlashPos > 0 ) { /* If we are after a drive letter let's keep the following backslash */ if( IS_PATH_SEP( ':' ) && - ( szFilename[ iSlashPos ] == ':' || szFilename[ iSlashPos - 1 ] == ':' ) ) + ( szFileName[ iSlashPos ] == ':' || szFileName[ iSlashPos - 1 ] == ':' ) ) { /* path with separator -> d:\path\filename or d:path\filename */ - memcpy( pName->szBuffer, szFilename, iSlashPos + 1 ); - pName->szBuffer[ iSlashPos + 1 ] = '\0'; + memcpy( pFileName->szBuffer, szFileName, iSlashPos + 1 ); + pFileName->szBuffer[ iSlashPos + 1 ] = '\0'; iPos = iSlashPos + 2; /* first free position after the slash */ } else { /* path with separator -> path\filename */ - memcpy( pName->szBuffer, szFilename, iSlashPos ); - pName->szBuffer[ iSlashPos ] = '\0'; + memcpy( pFileName->szBuffer, szFileName, iSlashPos ); + pFileName->szBuffer[ iSlashPos ] = '\0'; iPos = iSlashPos + 1; /* first free position after the slash */ } - pName->szPath = pName->szBuffer; + pFileName->szPath = pFileName->szBuffer; } iDotPos = iLen - 1; - while( iDotPos > iSlashPos && szFilename[ iDotPos ] != '.' ) + while( iDotPos > iSlashPos && szFileName[ iDotPos ] != '.' ) --iDotPos; if( ( iDotPos - iSlashPos ) > 1 ) @@ -1349,15 +1349,15 @@ PHB_FNAME hb_fsFNameSplit( char * szFilename ) 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'; + pFileName->szExtension = pFileName->szBuffer + iPos; + pFileName->szBuffer[ iPos++ ] = '.'; + pFileName->szBuffer[ iPos++ ] = '\0'; } else { - pName->szExtension = pName->szBuffer + iPos; + pFileName->szExtension = pFileName->szBuffer + iPos; /* copy rest of the string with terminating ZERO character */ - memcpy( pName->szExtension, szFilename + iDotPos + 1, iLen - iDotPos ); + memcpy( pFileName->szExtension, szFileName + iDotPos + 1, iLen - iDotPos ); iPos += iLen - iDotPos; } } @@ -1365,15 +1365,23 @@ PHB_FNAME hb_fsFNameSplit( char * szFilename ) /* 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'; + if( ( iDotPos - iSlashPos - 1 ) > 0 ) + { + pFileName->szName = pFileName->szBuffer + iPos; + memcpy( pFileName->szName, szFileName + iSlashPos + 1, iDotPos - iSlashPos - 1 ); + pFileName->szName[ iDotPos - iSlashPos - 1 ] = '\0'; + } - return pName; +/* DEBUG + printf( "\nFilename: %s\n", szFileName ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); +*/ + + return pFileName; } -/* TOFIX: Check not to overrun the _POSIX_PATH_MAX buffer size. */ - /* This function joins path, name and extension into a string with a filename */ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) { @@ -1397,10 +1405,14 @@ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) szFileName[ iLen ] = '\0'; } } - strcpy( szFileName + iLen, pFileName->szName ); + if( pFileName->szName ) + strcpy( szFileName + iLen, pFileName->szName ); } else - strcpy( szFileName, pFileName->szName ); + { + if( pFileName->szName ) + strcpy( szFileName, pFileName->szName ); + } if( pFileName->szExtension ) { @@ -1415,6 +1427,13 @@ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName ) strcpy( szFileName + iLen, pFileName->szExtension ); } +/* DEBUG + printf( "\nMERGE:\n" ); + printf( "\n szPath: %s\n", pFileName->szPath ); + printf( "\n szName: %s\n", pFileName->szName ); + printf( "\n szExt: %s\n", pFileName->szExtension ); + printf( "\nFilename result: %s\n", szFileName ); +*/ + return szFileName; } - diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 54e7a898e6..8af18c9967 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -488,7 +488,7 @@ void hb_vmExecute( BYTE * pCode, PHB_SYMB pSymbols ) * +1 +2 -> size of codeblock * +3 +4 -> number of expected parameters * +5 +6 -> number of referenced local variables - * +7 -> start of table with referenced local variables + * +7 -> start of table with referenced local variables */ hb_vmPushBlock( pCode + w, pSymbols ); w += ( pCode[ w + 1 ] + ( pCode[ w + 2 ] * 256 ) ); @@ -2295,7 +2295,7 @@ void hb_vmPushString( char * szText, ULONG length ) stack.pPos->type = IT_STRING; stack.pPos->item.asString.length = length; - stack.pPos->item.asString.value = szTemp; + stack.pPos->item.asString.value = szTemp; hb_stackPush(); HB_DEBUG( "hb_vmPushString\n" ); @@ -2319,12 +2319,12 @@ void hb_vmPush( PHB_ITEM pItem ) HB_DEBUG( "hb_vmPush\n" ); } -/* +0 -> HB_P_PUSHBLOCK -* +1 +2 -> size of codeblock -* +3 +4 -> number of expected parameters -* +5 +6 -> number of referenced local variables -* +7 -> start of table with referenced local variables -*/ +/* +0 -> HB_P_PUSHBLOCK + * +1 +2 -> size of codeblock + * +3 +4 -> number of expected parameters + * +5 +6 -> number of referenced local variables + * +7 -> start of table with referenced local variables + */ void hb_vmPushBlock( BYTE * pCode, PHB_SYMB pSymbols ) { WORD wLocals; @@ -2333,9 +2333,9 @@ void hb_vmPushBlock( BYTE * pCode, PHB_SYMB pSymbols ) wLocals = pCode[ 5 ] + ( pCode[ 6 ] * 256 ); stack.pPos->item.asBlock.value = - hb_codeblockNew( pCode + 7 + wLocals*2, /* pcode buffer */ - wLocals, /* number of referenced local variables */ - ( WORD * )( pCode + 7 ), /* table with referenced local variables */ + hb_codeblockNew( pCode + 7 + wLocals * 2, /* pcode buffer */ + wLocals, /* number of referenced local variables */ + ( WORD * ) ( pCode + 7 ), /* table with referenced local variables */ pSymbols ); /* store the statics base of function where the codeblock was defined @@ -2954,7 +2954,6 @@ HARBOUR HB_WORD( void ) } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "WORD" ); - } HARBOUR HB_PROCNAME( void ) @@ -3026,10 +3025,10 @@ HARBOUR HB_PCOUNT( void ) { if( hb_pcount() == 0 ) { + /* Skip current function */ PHB_ITEM pBase = stack.pItems + stack.pBase->item.asSymbol.stackbase; - WORD wRet = pBase->item.asSymbol.paramcnt; /* Skip current function */ - hb_retni( wRet ); + hb_retni( pBase->item.asSymbol.paramcnt ); } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "PCOUNT" ); /* NOTE: Clipper catches this at compile time! */