2009-04-03 02:49 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/hvm.c
* harbour/source/vm/fm.c
* harbour/source/vm/cmdarg.c
! fixed GPF when hb_vmInit() is called without initializing
application startup parameters by hb_cmdargInit().
Thanks to Enrico's friends for information about the problem.
* some code cleanup
This commit is contained in:
@@ -8,6 +8,15 @@
|
||||
2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
|
||||
*/
|
||||
|
||||
2009-04-03 02:49 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
|
||||
* harbour/source/vm/hvm.c
|
||||
* harbour/source/vm/fm.c
|
||||
* harbour/source/vm/cmdarg.c
|
||||
! fixed GPF when hb_vmInit() is called without initializing
|
||||
application startup parameters by hb_cmdargInit().
|
||||
Thanks to Enrico's friends for information about the problem.
|
||||
* some code cleanup
|
||||
|
||||
2009-04-03 01:20 UTC+0200 Francesco Saverio Giudice (info/at/fsgiudice.com)
|
||||
* harbour/contrib/examples/uhttpd/uhttpd.prg
|
||||
+ added Application Root folder
|
||||
|
||||
@@ -102,8 +102,16 @@ void hb_cmdargInit( int argc, char * argv[] )
|
||||
{
|
||||
HB_TRACE(HB_TR_DEBUG, ("hb_cmdargInit(%d, %p)", argc, argv));
|
||||
|
||||
s_argc = argc;
|
||||
s_argv = argv;
|
||||
if( argc == 0 || argv == NULL )
|
||||
{
|
||||
s_argc = 0;
|
||||
s_argv = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_argc = argc;
|
||||
s_argv = argv;
|
||||
}
|
||||
}
|
||||
|
||||
int hb_cmdargARGC( void )
|
||||
@@ -125,93 +133,96 @@ void hb_cmdargUpdate( void )
|
||||
{
|
||||
HB_TRACE(HB_TR_DEBUG, ("hb_cmdargUpdate()"));
|
||||
|
||||
if( s_argc > 0 )
|
||||
{
|
||||
#if defined( HB_OS_WIN )
|
||||
|
||||
/* NOTE: Manually setup the executable name in Windows,
|
||||
because in console apps the name may be truncated
|
||||
in some cases, and in GUI apps it's not filled
|
||||
at all. [vszakats] */
|
||||
if( GetModuleFileName( NULL, s_lpAppName, MAX_PATH ) != 0 )
|
||||
{
|
||||
HB_TCHAR_GETFROM( s_szAppName, s_lpAppName, MAX_PATH );
|
||||
s_argv[ 0 ] = s_szAppName;
|
||||
}
|
||||
#else
|
||||
/* NOTE: try to create absolute path from s_argv[ 0 ] if necessary */
|
||||
{
|
||||
PHB_FNAME pFName = hb_fsFNameSplit( s_argv[ 0 ] );
|
||||
BOOL fInPath = FALSE;
|
||||
|
||||
if( !pFName->szPath )
|
||||
/* NOTE: Manually setup the executable name in Windows,
|
||||
because in console apps the name may be truncated
|
||||
in some cases, and in GUI apps it's not filled
|
||||
at all. [vszakats] */
|
||||
if( GetModuleFileName( NULL, s_lpAppName, MAX_PATH ) != 0 )
|
||||
{
|
||||
char * pszPATH = hb_getenv( "PATH" );
|
||||
HB_TCHAR_GETFROM( s_szAppName, s_lpAppName, MAX_PATH );
|
||||
s_argv[ 0 ] = s_szAppName;
|
||||
}
|
||||
#else
|
||||
/* NOTE: try to create absolute path from s_argv[ 0 ] if necessary */
|
||||
{
|
||||
PHB_FNAME pFName = hb_fsFNameSplit( s_argv[ 0 ] );
|
||||
BOOL fInPath = FALSE;
|
||||
|
||||
if( pszPATH && *pszPATH )
|
||||
if( !pFName->szPath )
|
||||
{
|
||||
HB_PATHNAMES * pSearchPath = NULL, * pNextPath;
|
||||
hb_fsAddSearchPath( pszPATH, &pSearchPath );
|
||||
pNextPath = pSearchPath;
|
||||
char * pszPATH = hb_getenv( "PATH" );
|
||||
|
||||
#ifdef HB_OS_OS2
|
||||
if( !pFName->szExtension )
|
||||
pFName->szExtension = ".exe";
|
||||
#endif
|
||||
|
||||
while( pNextPath )
|
||||
if( pszPATH && *pszPATH )
|
||||
{
|
||||
pFName->szPath = pNextPath->szPath;
|
||||
hb_fsFNameMerge( s_szAppName, pFName );
|
||||
if( hb_fsFileExists( s_szAppName ) )
|
||||
HB_PATHNAMES * pSearchPath = NULL, * pNextPath;
|
||||
hb_fsAddSearchPath( pszPATH, &pSearchPath );
|
||||
pNextPath = pSearchPath;
|
||||
|
||||
# ifdef HB_OS_OS2
|
||||
if( !pFName->szExtension )
|
||||
pFName->szExtension = ".exe";
|
||||
# endif
|
||||
|
||||
while( pNextPath )
|
||||
{
|
||||
/* even if the file is located using PATH then it does
|
||||
* not mean we will have absolute path here. It's not
|
||||
* good idea but PATH envvar can also contain relative
|
||||
* directories, f.e. "." or "bin" so we should add
|
||||
* current directory if necessary in code below.
|
||||
*/
|
||||
hb_xfree( pFName );
|
||||
pFName = hb_fsFNameSplit( s_szAppName );
|
||||
fInPath = TRUE;
|
||||
break;
|
||||
pFName->szPath = pNextPath->szPath;
|
||||
hb_fsFNameMerge( s_szAppName, pFName );
|
||||
if( hb_fsFileExists( s_szAppName ) )
|
||||
{
|
||||
/* even if the file is located using PATH then it does
|
||||
* not mean we will have absolute path here. It's not
|
||||
* good idea but PATH envvar can also contain relative
|
||||
* directories, f.e. "." or "bin" so we should add
|
||||
* current directory if necessary in code below.
|
||||
*/
|
||||
hb_xfree( pFName );
|
||||
pFName = hb_fsFNameSplit( s_szAppName );
|
||||
fInPath = TRUE;
|
||||
break;
|
||||
}
|
||||
pNextPath = pNextPath->pNext;
|
||||
}
|
||||
pNextPath = pNextPath->pNext;
|
||||
hb_fsFreeSearchPath( pSearchPath );
|
||||
if( !fInPath )
|
||||
pFName->szPath = NULL;
|
||||
}
|
||||
hb_fsFreeSearchPath( pSearchPath );
|
||||
if( !fInPath )
|
||||
pFName->szPath = NULL;
|
||||
if( pszPATH )
|
||||
hb_xfree( pszPATH );
|
||||
}
|
||||
if( pszPATH )
|
||||
hb_xfree( pszPATH );
|
||||
}
|
||||
if( pFName->szPath )
|
||||
{
|
||||
#if defined(HB_OS_HAS_DRIVE_LETTER)
|
||||
if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR && !pFName->szDrive )
|
||||
#else
|
||||
if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR )
|
||||
#endif
|
||||
if( pFName->szPath )
|
||||
{
|
||||
if( pFName->szPath[ 0 ] == '.' &&
|
||||
pFName->szPath[ 1 ] == HB_OS_PATH_DELIM_CHR )
|
||||
pFName->szPath += 2;
|
||||
s_szAppName[ 0 ] = HB_OS_PATH_DELIM_CHR;
|
||||
hb_fsCurDirBuff( 0, ( BYTE * ) ( s_szAppName + 1 ), HB_PATH_MAX - 1 );
|
||||
if( s_szAppName[ 1 ] != 0 )
|
||||
# if defined( HB_OS_HAS_DRIVE_LETTER )
|
||||
if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR && !pFName->szDrive )
|
||||
# else
|
||||
if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR )
|
||||
# endif
|
||||
{
|
||||
hb_strncat( s_szAppName, HB_OS_PATH_DELIM_CHR_STRING, HB_PATH_MAX - 1 );
|
||||
hb_strncat( s_szAppName, pFName->szPath, HB_PATH_MAX - 1 );
|
||||
pFName->szPath = hb_strdup( s_szAppName );
|
||||
hb_fsFNameMerge( s_szAppName, pFName );
|
||||
hb_xfree( ( void * ) pFName->szPath );
|
||||
s_argv[ 0 ] = s_szAppName;
|
||||
if( pFName->szPath[ 0 ] == '.' &&
|
||||
pFName->szPath[ 1 ] == HB_OS_PATH_DELIM_CHR )
|
||||
pFName->szPath += 2;
|
||||
s_szAppName[ 0 ] = HB_OS_PATH_DELIM_CHR;
|
||||
hb_fsCurDirBuff( 0, ( BYTE * ) ( s_szAppName + 1 ), HB_PATH_MAX - 1 );
|
||||
if( s_szAppName[ 1 ] != 0 )
|
||||
{
|
||||
hb_strncat( s_szAppName, HB_OS_PATH_DELIM_CHR_STRING, HB_PATH_MAX - 1 );
|
||||
hb_strncat( s_szAppName, pFName->szPath, HB_PATH_MAX - 1 );
|
||||
pFName->szPath = hb_strdup( s_szAppName );
|
||||
hb_fsFNameMerge( s_szAppName, pFName );
|
||||
hb_xfree( ( void * ) pFName->szPath );
|
||||
s_argv[ 0 ] = s_szAppName;
|
||||
}
|
||||
}
|
||||
else if( fInPath )
|
||||
s_argv[ 0 ] = s_szAppName;
|
||||
}
|
||||
else if( fInPath )
|
||||
s_argv[ 0 ] = s_szAppName;
|
||||
hb_xfree( pFName );
|
||||
}
|
||||
hb_xfree( pFName );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
BOOL hb_cmdargIsInternal( const char * szArg, int * piLen )
|
||||
@@ -432,39 +443,35 @@ HB_FUNC( HB_ARGV )
|
||||
HB_FUNC( HB_CMDLINE )
|
||||
{
|
||||
char * pszBuffer;
|
||||
|
||||
BOOL fFree;
|
||||
int nLen;
|
||||
int nPos;
|
||||
|
||||
int argc = hb_cmdargARGC();
|
||||
char** argv = hb_cmdargARGV();
|
||||
|
||||
nLen = 1;
|
||||
for( nPos = 1; nPos < argc; nPos++ )
|
||||
nLen += ( int ) strlen( argv[ nPos ] ) + 1;
|
||||
|
||||
pszBuffer = ( char * ) hb_xgrab( nLen + 1 );
|
||||
|
||||
pszBuffer[ 0 ] = '\0';
|
||||
for( nPos = 1; nPos < argc; nPos++ )
|
||||
if( argc )
|
||||
{
|
||||
hb_strncat( pszBuffer, argv[ nPos ], nLen );
|
||||
hb_strncat( pszBuffer, " ", nLen );
|
||||
}
|
||||
nLen = 1;
|
||||
for( nPos = 1; nPos < argc; nPos++ )
|
||||
nLen += ( int ) strlen( argv[ nPos ] ) + 1;
|
||||
|
||||
{
|
||||
/* Convert from OS codepage */
|
||||
BOOL fFree;
|
||||
char * pbyResult = ( char * ) hb_osDecode( ( BYTE * ) pszBuffer, &fFree );
|
||||
pszBuffer = ( char * ) hb_xgrab( nLen + 1 );
|
||||
|
||||
if( fFree )
|
||||
pszBuffer[ 0 ] = '\0';
|
||||
for( nPos = 1; nPos < argc; nPos++ )
|
||||
{
|
||||
hb_retc_buffer( pbyResult );
|
||||
hb_xfree( pszBuffer );
|
||||
hb_strncat( pszBuffer, argv[ nPos ], nLen );
|
||||
hb_strncat( pszBuffer, " ", nLen );
|
||||
}
|
||||
else
|
||||
hb_retc_buffer( pszBuffer );
|
||||
|
||||
/* Convert from OS codepage */
|
||||
hb_retc_buffer( ( char * ) hb_osDecode( ( BYTE * ) pszBuffer, &fFree ) );
|
||||
if( fFree )
|
||||
hb_xfree( pszBuffer );
|
||||
}
|
||||
else
|
||||
hb_retc_null();
|
||||
}
|
||||
|
||||
/* Check for command line internal arguments */
|
||||
|
||||
@@ -1000,7 +1000,7 @@ void hb_xexit( void ) /* Deinitialize fixed memory subsystem */
|
||||
hb_dateToday( &iYear, &iMonth, &iDay );
|
||||
hb_dateTimeStr( szTime );
|
||||
|
||||
fprintf( hLog, HB_I_("Application Memory Allocation Report - %s\n"), hb_cmdargARGV()[0] );
|
||||
fprintf( hLog, HB_I_("Application Memory Allocation Report - %s\n"), hb_cmdargARGVN( 0 ) );
|
||||
fprintf( hLog, HB_I_("Terminated at: %04d.%02d.%02d %s\n"), iYear, iMonth, iDay, szTime );
|
||||
if( s_szInfo[ 0 ] )
|
||||
fprintf( hLog, HB_I_("Info: %s\n"), s_szInfo );
|
||||
|
||||
@@ -1011,17 +1011,16 @@ void hb_vmInit( BOOL bStartMainProc )
|
||||
|
||||
if( bStartMainProc && s_pSymStart )
|
||||
{
|
||||
int argc = hb_cmdargARGC();
|
||||
char ** argv = hb_cmdargARGV();
|
||||
int iArgCount = 0;
|
||||
int i;
|
||||
int iArgCount;
|
||||
|
||||
hb_vmPushSymbol( s_pSymStart ); /* pushes first HB_FS_PUBLIC defined symbol to the stack */
|
||||
hb_vmPushNil(); /* places NIL at self */
|
||||
|
||||
iArgCount = 0;
|
||||
for( i = 1; i < hb_cmdargARGC(); i++ ) /* places application parameters on the stack */
|
||||
for( i = 1; i < argc; i++ ) /* places application parameters on the stack */
|
||||
{
|
||||
char ** argv = hb_cmdargARGV();
|
||||
|
||||
/* Filter out any parameters beginning with //, like //INFO */
|
||||
if( ! hb_cmdargIsInternal( argv[ i ], NULL ) )
|
||||
{
|
||||
@@ -7804,9 +7803,8 @@ static void hb_vmDoInitFunctions( void )
|
||||
{
|
||||
int argc = hb_cmdargARGC();
|
||||
char ** argv = hb_cmdargARGV();
|
||||
|
||||
int i;
|
||||
int iArgCount;
|
||||
int i;
|
||||
|
||||
hb_vmPushSymbol( pLastSymbols->pModuleSymbols + ui );
|
||||
hb_vmPushNil();
|
||||
|
||||
Reference in New Issue
Block a user