diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b919de85a8..c77102e275 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,34 @@ The license applies to all entries newer than 2009-04-28. */ +2012-11-16 09:39 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * harbour/include/hbapi.h + * harbour/src/vm/cmdarg.c + ! fixed to compile without UNICODE macro + + added new C functions: hb_cmdargBaseProgName(), hb_cmdargPushArgs() + * marked places which needs TCHAR conversions in MS-Windows builds + + * harbour/src/vm/hvm.c + * use hb_cmdargPushArgs() + + * harbour/src/rtl/hbproces.c + ! fixed to compile without UNICODE macro + + * harbour/src/rtl/gtxwc/gtxwc.c + * modified code to set window title to always operate on UTF8 values + * use hb_cmdargBaseProgName() + + * harbour/src/rtl/gtwvt/gtwvt.c + * harbour/contrib/gtwvg/gtwgud.c + * harbour/contrib/gtwvg/gtwvgd.c + * harbour/contrib/gtalleg/gtalleg.c + * harbour/extras/gtwvw/gtwvwd.c + * use hb_cmdargBaseProgName() + + * harbour/contrib/hbodbc/odbc.c + ! keep references to parent handles in sub-handles pointer structures + ; please make real life tests if it works correctly + 2012-11-16 04:10 UTC+0100 Viktor Szakats (harbour syenar.net) * ChangeLog ! restored/fixed file that got corrupted in diff --git a/harbour/contrib/gtalleg/gtalleg.c b/harbour/contrib/gtalleg/gtalleg.c index 1dd1e967cc..1527cd939b 100644 --- a/harbour/contrib/gtalleg/gtalleg.c +++ b/harbour/contrib/gtalleg/gtalleg.c @@ -330,7 +330,6 @@ static void hb_gt_alleg_ScreenUpdate( PHB_GT pGT ) static HB_BOOL hb_gt_alleg_InitializeScreen( PHB_GT pGT, int iRows, int iCols, HB_BOOL lClearInit ) { - PHB_FNAME pFileName; int iRet = 1, iWidth, iHeight; /* Don't remove iRet, ixFP and iyFP initializers! */ short ixFP = 0, iyFP = 0; HB_BOOL lMode = HB_FALSE, lPrev = s_fInit; @@ -432,9 +431,13 @@ static HB_BOOL hb_gt_alleg_InitializeScreen( PHB_GT pGT, int iRows, int iCols, H else lMode = HB_TRUE; - pFileName = hb_fsFNameSplit( hb_cmdargARGV()[ 0 ] ); - al_set_window_title( ( char * ) pFileName->szName ); - hb_xfree( pFileName ); + { + char * pszBaseName = hb_cmdargBaseProgName(); + + al_set_window_title( pszBaseName ); + if( pszBaseName ) + hb_xfree( pszBaseName ); + } if( ! lPrev ) { diff --git a/harbour/contrib/gtwvg/gtwgud.c b/harbour/contrib/gtwvg/gtwgud.c index 135705bc77..bde88e61d7 100644 --- a/harbour/contrib/gtwvg/gtwgud.c +++ b/harbour/contrib/gtwvg/gtwgud.c @@ -274,13 +274,10 @@ static PHB_GTWVT hb_gt_wvt_New( PHB_GT pGT, HINSTANCE hInstance, int iCmdShow ) pWVT->bClosable = HB_TRUE; { - PHB_FNAME pFileName = hb_fsFNameSplit( hb_cmdargARGVN( 0 ) ); - PHB_ITEM pItem = hb_itemPutC( NULL, pFileName->szName ); + PHB_ITEM pItem = hb_itemPutCPtr( NULL, hb_cmdargBaseProgName() ); pWVT->lpWindowTitle = HB_ITEMGETSTR( pItem, &pWVT->hWindowTitle, NULL ); - hb_itemRelease( pItem ); - hb_xfree( pFileName ); } pWVT->pPP = ( HB_GT_PARAMS * ) hb_xgrab( sizeof( HB_GT_PARAMS ) ); diff --git a/harbour/contrib/gtwvg/gtwvgd.c b/harbour/contrib/gtwvg/gtwvgd.c index 3cb31596c4..1eff4157e7 100644 --- a/harbour/contrib/gtwvg/gtwvgd.c +++ b/harbour/contrib/gtwvg/gtwvgd.c @@ -432,13 +432,10 @@ static PHB_GTWVT hb_gt_wvt_New( PHB_GT pGT, HINSTANCE hInstance, int iCmdShow ) pWVT->bClosable = HB_TRUE; { - PHB_FNAME pFileName = hb_fsFNameSplit( hb_cmdargARGVN( 0 ) ); - PHB_ITEM pItem = hb_itemPutC( NULL, pFileName->szName ); + PHB_ITEM pItem = hb_itemPutCPtr( NULL, hb_cmdargBaseProgName() ); pWVT->lpWindowTitle = HB_ITEMGETSTR( pItem, &pWVT->hWindowTitle, NULL ); - hb_itemRelease( pItem ); - hb_xfree( pFileName ); } pWVT->ResizeMode = HB_GTI_RESIZEMODE_FONT; diff --git a/harbour/contrib/hbodbc/odbc.c b/harbour/contrib/hbodbc/odbc.c index 9d8bf7bafd..a2b7de8c2d 100644 --- a/harbour/contrib/hbodbc/odbc.c +++ b/harbour/contrib/hbodbc/odbc.c @@ -75,6 +75,7 @@ */ #include "hbapi.h" +#include "hbapiitm.h" #include "hbapierr.h" #include "hbapistr.h" #include "hbset.h" @@ -193,102 +194,155 @@ static void hb_SQLHENV_stor( SQLHENV hEnv, int iParam ) /* GC - SQLHDBC */ +typedef struct +{ + SQLHDBC hDbc; + PHB_ITEM pHEnvItm; +} +HB_SQLHDBC, * PHB_SQLHDBC; + static HB_GARBAGE_FUNC( hb_SQLHDBC_Destructor ) { /* Retrieve image pointer holder */ - SQLHDBC * ptr = ( SQLHDBC * ) Cargo; + PHB_SQLHDBC pHDbc = ( PHB_SQLHDBC ) Cargo; /* Check if pointer is not NULL to avoid multiple freeing */ - if( *ptr ) + if( pHDbc->hDbc ) { #if defined( _HBODBC_AUTO_MM_ ) #if ODBCVER >= 0x0300 - SQLFreeHandle( SQL_HANDLE_DBC, ( SQLHANDLE ) *ptr ); + SQLFreeHandle( SQL_HANDLE_DBC, ( SQLHANDLE ) pHDbc->hDbc ); #else - SQLFreeConnect( *ptr ); + SQLFreeConnect( pHDbc->hDbc ); #endif #endif /* set pointer to NULL to avoid multiple freeing */ - *ptr = NULL; + pHDbc->hDbc = NULL; + } + if( pHDbc->pHEnvItm ) + { + /* release reference to parent handler */ + hb_itemRelease( pHDbc->pHEnvItm ); + /* set pointer to NULL to avoid multiple freeing */ + pHDbc->pHEnvItm = NULL; + } +} + +static HB_GARBAGE_FUNC( hb_SQLHDBC_Mark ) +{ + /* Retrieve image pointer holder */ + PHB_SQLHDBC pHDbc = ( PHB_SQLHDBC ) Cargo; + + if( pHDbc->pHEnvItm ) + { + /* mark parent item handler as used */ + hb_gcMark( pHDbc->pHEnvItm ); } } static const HB_GC_FUNCS s_gcSQLHDBCFuncs = { hb_SQLHDBC_Destructor, - hb_gcDummyMark + hb_SQLHDBC_Mark }; static SQLHDBC hb_SQLHDBC_par( int iParam ) { - SQLHDBC * ptr = ( SQLHDBC * ) hb_parptrGC( &s_gcSQLHDBCFuncs, iParam ); + PHB_SQLHDBC pHDbc = ( PHB_SQLHDBC ) hb_parptrGC( &s_gcSQLHDBCFuncs, iParam ); - return ptr ? *ptr : NULL; + return pHDbc ? pHDbc->hDbc : NULL; } -static SQLHDBC hb_SQLHDBC_is( int iParam ) +static HB_BOOL hb_SQLHDBC_is( int iParam ) { - return hb_parptrGC( &s_gcSQLHDBCFuncs, iParam ); + return hb_SQLHDBC_par( iParam ) != NULL; } -static void hb_SQLHDBC_stor( SQLHDBC hDbc, int iParam ) +static void hb_SQLHDBC_stor( PHB_ITEM pHEnvItm, SQLHDBC hDbc, int iParam ) { - SQLHDBC * ptr = ( SQLHDBC * ) hb_gcAllocate( sizeof( SQLHDBC ), &s_gcSQLHDBCFuncs ); + PHB_SQLHDBC pHDbc = ( PHB_SQLHDBC ) hb_gcAllocate( sizeof( HB_SQLHDBC ), &s_gcSQLHDBCFuncs ); - *ptr = hDbc; + pHDbc->hDbc = hDbc; + pHDbc->pHEnvItm = pHEnvItm ? hb_itemNew( pHEnvItm ) : NULL; - hb_storptrGC( ( void * ) ptr, iParam ); + hb_storptrGC( ( void * ) pHDbc, iParam ); } /* GC - SQLHSTMT */ +typedef struct +{ + SQLHSTMT hStmt; + PHB_ITEM pHDbcItm; +} +HB_SQLHSTMT, * PHB_SQLHSTMT; + static HB_GARBAGE_FUNC( hb_SQLHSTMT_Destructor ) { /* Retrieve image pointer holder */ - SQLHSTMT * ptr = ( SQLHSTMT * ) Cargo; + PHB_SQLHSTMT pHStmt = ( PHB_SQLHSTMT ) Cargo; /* Check if pointer is not NULL to avoid multiple freeing */ - if( *ptr ) + if( pHStmt->hStmt ) { #if defined( _HBODBC_AUTO_MM_ ) #if ODBCVER >= 0x0300 - SQLFreeHandle( SQL_HANDLE_STMT, ( SQLHANDLE ) *ptr ); + SQLFreeHandle( SQL_HANDLE_STMT, ( SQLHANDLE ) pHStmt->hStmt ); #else - SQLFreeStmt( *ptr, SQL_DROP ); + SQLFreeStmt( pHStmt->hStmt, SQL_DROP ); #endif #endif /* set pointer to NULL to avoid multiple freeing */ - *ptr = NULL; + pHStmt->hStmt = NULL; + } + if( pHStmt->pHDbcItm ) + { + /* release reference to parent handler */ + hb_itemRelease( pHStmt->pHDbcItm ); + /* set pointer to NULL to avoid multiple freeing */ + pHStmt->pHDbcItm = NULL; } } +static HB_GARBAGE_FUNC( hb_SQLHSTMT_Mark ) +{ + /* Retrieve image pointer holder */ + PHB_SQLHSTMT pHStmt = ( PHB_SQLHSTMT ) Cargo; + + if( pHStmt->pHDbcItm ) + { + /* mark parent item handler as used */ + hb_gcMark( pHStmt->pHDbcItm ); + } +} static const HB_GC_FUNCS s_gcSQLHSTMTFuncs = { hb_SQLHSTMT_Destructor, - hb_gcDummyMark + hb_SQLHSTMT_Mark }; static SQLHSTMT hb_SQLHSTMT_par( int iParam ) { - SQLHSTMT * ptr = ( SQLHSTMT * ) hb_parptrGC( &s_gcSQLHSTMTFuncs, iParam ); + PHB_SQLHSTMT pHStmt = ( PHB_SQLHSTMT ) hb_parptrGC( &s_gcSQLHSTMTFuncs, iParam ); - return ptr ? *ptr : NULL; + return pHStmt ? pHStmt->hStmt : NULL; } -static SQLHSTMT hb_SQLHSTMT_is( int iParam ) +static HB_BOOL hb_SQLHSTMT_is( int iParam ) { - return hb_parptrGC( &s_gcSQLHSTMTFuncs, iParam ); + return hb_SQLHSTMT_par( iParam ) != NULL; } -static void hb_SQLHSTMT_stor( SQLHSTMT hStmt, int iParam ) +static void hb_SQLHSTMT_stor( PHB_ITEM pHDbcItm, SQLHSTMT hStmt, int iParam ) { - SQLHSTMT * ptr = ( SQLHSTMT * ) hb_gcAllocate( sizeof( SQLHSTMT ), &s_gcSQLHSTMTFuncs ); + PHB_SQLHSTMT pHStmt = ( PHB_SQLHSTMT ) hb_gcAllocate( sizeof( HB_SQLHSTMT ), &s_gcSQLHSTMTFuncs ); - *ptr = hStmt; + pHStmt->hStmt = hStmt; + pHStmt->pHDbcItm = pHDbcItm ? hb_itemNew( pHDbcItm ) : NULL; - hb_storptrGC( ( void * ) ptr, iParam ); + hb_storptrGC( ( void * ) pHStmt, iParam ); } HB_FUNC( SQLALLOCENV ) /* @hEnv --> nRetCode */ @@ -317,7 +371,7 @@ HB_FUNC( SQLALLOCCONNECT ) /* hEnv, @hDbc --> nRetCode */ hb_retni( SQLAllocConnect( hEnv, &hDbc ) ); #endif - hb_SQLHDBC_stor( hDbc, 2 ); + hb_SQLHDBC_stor( hb_param( 1, HB_IT_ANY ), hDbc, 2 ); } else hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); @@ -428,7 +482,7 @@ HB_FUNC( SQLALLOCSTMT ) /* hDbc, @hStmt --> nRetCode */ hb_retni( SQLAllocStmt( hDbc, &hStmt ) ); #endif - hb_SQLHSTMT_stor( hStmt, 2 ); + hb_SQLHSTMT_stor( hb_param( 1, HB_IT_ANY ), hStmt, 2 ); } else hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); diff --git a/harbour/extras/gtwvw/gtwvwd.c b/harbour/extras/gtwvw/gtwvwd.c index 04b271657f..66ca421ac0 100644 --- a/harbour/extras/gtwvw/gtwvwd.c +++ b/harbour/extras/gtwvw/gtwvwd.c @@ -468,15 +468,12 @@ static void hb_gt_wvw_Init( PHB_GT pGT, HB_FHANDLE hFilenoStdin, HB_FHANDLE hFil hb_errRT_TERM( EG_CREATE, 10001, "WINAPI CreateWindow() failed", "hb_gt_Init()", 0, 0 ); { - PHB_FNAME pFileName = hb_fsFNameSplit( hb_cmdargARGVN( 0 ) ); - PHB_ITEM pItem = hb_itemPutC( NULL, pFileName->szName ); - void * hWindowTitle; + PHB_ITEM pItem = hb_itemPutCPtr( NULL, hb_cmdargBaseProgName() ); + void * hWindowTitle; hb_gt_wvwSetWindowTitle( 0, HB_ITEMGETSTR( pItem, &hWindowTitle, NULL ) ); - hb_strfree( hWindowTitle ); hb_itemRelease( pItem ); - hb_xfree( pFileName ); } hb_gt_wvwCreateObjects( 0 ); @@ -7097,11 +7094,9 @@ HB_FUNC( WVW_NOPENWINDOW ) } else { - pFileName = hb_fsFNameSplit( hb_cmdargARGV()[ 0 ] ); - PHB_ITEM pItem = hb_itemPutC( NULL, pFileName->szName ); + PHB_ITEM pItem = hb_itemPutCPtr( NULL, hb_cmdargBaseProgName() ); lpszWinName = HB_ITEMGETSTR( pItem, &hWinName, NULL ); - hb_itemRelease( pItem ); } diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index f90cc68f74..c7c0b0693f 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -1041,6 +1041,8 @@ extern HB_EXPORT char ** hb_cmdargARGV( void ); /* retrieve command line a extern HB_EXPORT const char * hb_cmdargARGVN( int argc ); /* retrieve given command line argument */ extern HB_EXPORT HB_BOOL hb_cmdargIsInternal( const char * szArg, int * piLen ); /* determine if a string is an internal setting */ extern HB_EXPORT char * hb_cmdargProgName( void ); /* return application name with path or NULL if not set, caller must free returned value with hb_xfree() if not NULL */ +extern HB_EXPORT char * hb_cmdargBaseProgName( void ); /* return application name without path or NULL if not set, caller must free returned value with hb_xfree() if not NULL */ +extern int hb_cmdargPushArgs( void ); /* places application parameters on the HVM stack */ extern void hb_cmdargUpdate( void ); /* update arguments after HVM initialization */ extern HB_BOOL hb_cmdargCheck( const char * pszName ); /* Check if a given internal switch (like //INFO) was set */ extern char * hb_cmdargString( const char * pszName ); /* Returns the string value of an internal switch (like //TEMPPATH:"C:\") */ diff --git a/harbour/src/rtl/gtwvt/gtwvt.c b/harbour/src/rtl/gtwvt/gtwvt.c index 8a30246052..9f9f59bcb2 100644 --- a/harbour/src/rtl/gtwvt/gtwvt.c +++ b/harbour/src/rtl/gtwvt/gtwvt.c @@ -372,13 +372,10 @@ static PHB_GTWVT hb_gt_wvt_New( PHB_GT pGT, HINSTANCE hInstance, int iCmdShow ) pWVT->bSelectCopy = HB_TRUE; { - PHB_FNAME pFileName = hb_fsFNameSplit( hb_cmdargARGVN( 0 ) ); - PHB_ITEM pItem = hb_itemPutC( NULL, pFileName->szName ); + PHB_ITEM pItem = hb_itemPutCPtr( NULL, hb_cmdargBaseProgName() ); pWVT->lpWindowTitle = HB_ITEMGETSTR( pItem, &pWVT->hWindowTitle, NULL ); - hb_itemRelease( pItem ); - hb_xfree( pFileName ); } pWVT->bResizable = HB_TRUE; diff --git a/harbour/src/rtl/gtxwc/gtxwc.c b/harbour/src/rtl/gtxwc/gtxwc.c index 95cbb51b32..4b119ef7d5 100644 --- a/harbour/src/rtl/gtxwc/gtxwc.c +++ b/harbour/src/rtl/gtxwc/gtxwc.c @@ -3984,6 +3984,27 @@ static HB_ULONG hb_gt_xwc_CurrentTime( void ) /* *********************************************************************** */ +static void hb_gt_xwc_SetTitle( PXWND_DEF wnd, const char * szTitle ) +{ + if( szTitle && * szTitle ) + { + XTextProperty text; + char * pBuffer; + + pBuffer = hb_cdpDup( szTitle, HB_GTSELF_HOSTCP( wnd->pGT ), wnd->utf8CDP ); + text.value = ( unsigned char * ) pBuffer; + text.encoding = s_atomUTF8String; + text.format = 8; + text.nitems = strlen( pBuffer ); + XSetWMName( wnd->dpy, wnd->window, &text ); + hb_xfree( pBuffer ); + } + else + XStoreName( wnd->dpy, wnd->window, "" ); +} + +/* *********************************************************************** */ + static void hb_gt_xwc_ProcessMessages( PXWND_DEF wnd, HB_BOOL fSync ) { if( wnd->cursorType != SC_NONE ) @@ -4011,21 +4032,7 @@ static void hb_gt_xwc_ProcessMessages( PXWND_DEF wnd, HB_BOOL fSync ) if( wnd->fDspTitle ) { wnd->fDspTitle = HB_FALSE; - if( wnd->szTitle ) - { - XTextProperty text; - char * pBuffer; - - pBuffer = hb_cdpDup( wnd->szTitle, HB_GTSELF_HOSTCP( wnd->pGT ), wnd->utf8CDP ); - text.value = ( unsigned char * ) pBuffer; - text.encoding = s_atomUTF8String; - text.format = 8; - text.nitems = strlen( pBuffer ); - XSetWMName( wnd->dpy, wnd->window, &text ); - hb_xfree( pBuffer ); - } - else - XStoreName( wnd->dpy, wnd->window, "" ); + hb_gt_xwc_SetTitle( wnd, wnd->szTitle ); } #if 1 @@ -4327,7 +4334,6 @@ static HB_BOOL hb_gt_xwc_isUTF8( void ) static PXWND_DEF hb_gt_xwc_CreateWndDef( PHB_GT pGT ) { - PHB_FNAME pFileName; PXWND_DEF wnd = ( PXWND_DEF ) hb_xgrab( sizeof( XWND_DEF ) ); int i; @@ -4351,10 +4357,8 @@ static PXWND_DEF hb_gt_xwc_CreateWndDef( PHB_GT pGT ) wnd->cursorType = SC_NORMAL; /* Window Title */ - pFileName = hb_fsFNameSplit( hb_cmdargARGVN( 0 ) ); - wnd->szTitle = pFileName->szName ? hb_strdup( pFileName->szName ) : NULL; + wnd->szTitle = hb_cmdargBaseProgName(); wnd->fDspTitle = HB_TRUE; - hb_xfree( pFileName ); /* Font parameters */ wnd->fontHeight = XWC_DEFAULT_FONT_HEIGHT; @@ -4594,7 +4598,7 @@ static void hb_gt_xwc_CreateWindow( PXWND_DEF wnd ) /* Line width 2 */ XSetLineAttributes( wnd->dpy, wnd->gc, 1, LineSolid, CapRound, JoinBevel ); - XStoreName( wnd->dpy, wnd->window, wnd->szTitle ? wnd->szTitle : "" ); + hb_gt_xwc_SetTitle( wnd, wnd->szTitle ); } XSetFont( wnd->dpy, wnd->gc, wnd->xfs->fid ); @@ -5107,16 +5111,21 @@ static HB_BOOL hb_gt_xwc_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) } case HB_GTI_WINTITLE: - pInfo->pResult = hb_itemPutC( pInfo->pResult, wnd->szTitle ); + pInfo->pResult = hb_itemPutStrLenUTF8( pInfo->pResult, wnd->szTitle, + strlen( wnd->szTitle ) ); if( hb_itemType( pInfo->pNewVal ) & HB_IT_STRING ) { + void * hString; + HB_SIZE nLen; + const char * pszTitle = hb_itemGetStrUTF8( pInfo->pNewVal, &hString, &nLen ); + if( wnd->szTitle ) hb_xfree( wnd->szTitle ); - - if( hb_itemGetCLen( pInfo->pNewVal ) > 0 ) - wnd->szTitle = hb_strdup( hb_itemGetCPtr( pInfo->pNewVal ) ); + if( nLen > 0 ) + wnd->szTitle = hb_strdup( pszTitle ); else wnd->szTitle = NULL; + hb_strfree( hString ); wnd->fDspTitle = HB_TRUE; } diff --git a/harbour/src/rtl/hbproces.c b/harbour/src/rtl/hbproces.c index 515be1e6f2..42433bf707 100644 --- a/harbour/src/rtl/hbproces.c +++ b/harbour/src/rtl/hbproces.c @@ -427,7 +427,7 @@ HB_FHANDLE hb_fsProcessOpen( const char * pszFilename, PROCESS_INFORMATION pi; STARTUPINFO si; DWORD dwFlags = 0; - LPWSTR lpCommand = HB_CHARDUP( pszFilename ); + LPTSTR lpCommand = HB_CHARDUP( pszFilename ); memset( &pi, 0, sizeof( pi ) ); memset( &si, 0, sizeof( si ) ); diff --git a/harbour/src/vm/cmdarg.c b/harbour/src/vm/cmdarg.c index b1ce5f16cd..a8eef3a233 100644 --- a/harbour/src/vm/cmdarg.c +++ b/harbour/src/vm/cmdarg.c @@ -79,10 +79,12 @@ static char s_szAppName[ HB_PATH_MAX ]; #else +#include "hbwinuni.h" #include -static char s_szAppName[ MAX_PATH ]; +/* static LPTSTR* s_lpArgV = NULL; */ static TCHAR s_lpAppName[ MAX_PATH ]; +static char s_szAppName[ MAX_PATH ]; static int s_fSkipAppName = HB_FALSE; static HANDLE s_hInstance = 0; @@ -147,6 +149,7 @@ const char * hb_cmdargARGVN( int argc ) static char * hb_cmdargDup( int argc ) { + /* TODO: TCHAR conv */ return argc >= 0 && argc < s_argc ? hb_osStrDecode( s_argv[ argc ] ) : NULL; } @@ -157,6 +160,7 @@ void hb_cmdargUpdate( void ) if( s_argc > 0 ) { #if defined( HB_OS_WIN ) + /* TODO: TCHAR conv */ /* NOTE: Manually setup the executable name in Windows, because in console apps the name may be truncated @@ -261,6 +265,27 @@ void hb_cmdargUpdate( void ) } } +/* places application parameters on the HVM stack */ + +int hb_cmdargPushArgs( void ) +{ + int argc = hb_cmdargARGC(); + char ** argv = hb_cmdargARGV(); + int iArgCount = 0, i; + + for( i = 1; i < argc; i++ ) + { + /* Filter out any parameters beginning with //, like //INFO */ + if( ! hb_cmdargIsInternal( argv[ i ], NULL ) ) + { + hb_vmPushString( argv[ i ], strlen( argv[ i ] ) ); + iArgCount++; + } + } + + return iArgCount; +} + HB_BOOL hb_cmdargIsInternal( const char * szArg, int * piLen ) { HB_TRACE( HB_TR_DEBUG, ( "hb_cmdargIsInternal(%s, %p)", szArg, piLen ) ); @@ -307,6 +332,7 @@ static char * hb_cmdargGet( const char * pszName, HB_BOOL bRetValue ) { if( bRetValue ) { + /* TODO: TCHAR conv */ char * pszPos = s_argv[ i ] + iPrefixLen + strlen( pszName ); if( *pszPos == ':' ) @@ -426,6 +452,7 @@ int hb_cmdargNum( const char * pszName ) char * hb_cmdargProgName( void ) { #if defined( HB_OS_WIN ) + /* TODO: TCHAR conv */ if( ! s_fSkipAppName ) { if( s_lpAppName[ 0 ] == 0 ) @@ -437,12 +464,28 @@ char * hb_cmdargProgName( void ) s_lpAppName[ 0 ] = 0; } if( s_lpAppName[ 0 ] != 0 ) - return hb_osStrU16Decode( s_lpAppName ); + return HB_OSSTRDUP( s_lpAppName ); } #endif return hb_cmdargDup( 0 ); } +/* NOTE: Pointer must be freed with hb_xfree() if not NULL */ + +char * hb_cmdargBaseProgName( void ) +{ + char * pszProgName, * pszBaseProgName; + PHB_FNAME pFileName; + + pszProgName = hb_cmdargProgName(); + pFileName = hb_fsFNameSplit( pszProgName ); + pszBaseProgName = hb_strdup( pFileName->szName ); + hb_xfree( pFileName ); + hb_xfree( pszProgName ); + + return pszBaseProgName; +} + /* Check if an internal switch has been set */ HB_FUNC( HB_ARGCHECK ) @@ -502,6 +545,7 @@ HB_FUNC( HB_ARGSHIFT ) { if( ! hb_cmdargIsInternal( s_argv[ iArg ], NULL ) ) { + /* TODO: TCHAR conv */ s_argv[ 0 ] = s_argv[ iArg ]; #if defined( HB_OS_WIN ) s_fSkipAppName = HB_TRUE; @@ -516,6 +560,7 @@ HB_FUNC( HB_ARGSHIFT ) --s_argc; while( iArg < s_argc ) { + /* TODO: TCHAR conv */ s_argv[ iArg ] = s_argv[ iArg + 1 ]; ++iArg; } @@ -530,6 +575,8 @@ HB_FUNC( HB_CMDLINE ) HB_SIZE nLen; int iArg; + /* TODO: TCHAR conv */ + nLen = 0; for( iArg = 1; iArg < argc; iArg++ ) nLen += strlen( argv[ iArg ] ) + 1; diff --git a/harbour/src/vm/hvm.c b/harbour/src/vm/hvm.c index 4c2bfc26bf..968a33b9ad 100644 --- a/harbour/src/vm/hvm.c +++ b/harbour/src/vm/hvm.c @@ -1125,25 +1125,9 @@ void hb_vmInit( HB_BOOL bStartMainProc ) if( bStartMainProc && s_pSymStart ) { - int argc = hb_cmdargARGC(); - char ** argv = hb_cmdargARGV(); - int iArgCount = 0; - int i; - hb_vmPushSymbol( s_pSymStart ); /* pushes first HB_FS_PUBLIC defined symbol to the stack */ hb_vmPushNil(); /* places NIL at self */ - - for( i = 1; i < argc; i++ ) /* places application parameters on the stack */ - { - /* Filter out any parameters beginning with //, like //INFO */ - if( ! hb_cmdargIsInternal( argv[ i ], NULL ) ) - { - hb_vmPushString( argv[ i ], strlen( argv[ i ] ) ); - iArgCount++; - } - } - - hb_vmProc( ( HB_USHORT ) iArgCount ); /* invoke it with number of supplied parameters */ + hb_vmProc( ( HB_USHORT ) hb_cmdargPushArgs() ); /* invoke it with number of supplied parameters */ } } @@ -8142,26 +8126,9 @@ static void hb_vmDoInitFunctions( HB_BOOL fClipInit ) ( strcmp( ( pLastSymbols->pModuleSymbols + ui )->szName, "CLIPINIT$" ) == 0 ? fClipInit : !fClipInit ) ) { - int argc = hb_cmdargARGC(); - char ** argv = hb_cmdargARGV(); - int iArgCount; - int i; - hb_vmPushSymbol( pLastSymbols->pModuleSymbols + ui ); hb_vmPushNil(); - - iArgCount = 0; - for( i = 1; i < argc; i++ ) /* places application parameters on the stack */ - { - /* Filter out any parameters beginning with //, like //INFO */ - if( ! hb_cmdargIsInternal( argv[ i ], NULL ) ) - { - hb_vmPushString( argv[ i ], strlen( argv[ i ] ) ); - iArgCount++; - } - } - - hb_vmProc( ( HB_USHORT ) iArgCount ); + hb_vmProc( ( HB_USHORT ) hb_cmdargPushArgs() ); if( hb_vmRequestQuery() != 0 ) break; }