int hb_gt_chrmapinit( int * piTransTbl, const char * pszTerm, HB_BOOL fSetACSC ) { char * pszFree = NULL; int nRet = -1; chrmap_init( piTransTbl ); if( pszTerm == NULL || *pszTerm == '\0' ) pszTerm = pszFree = hb_getenv( "HB_TERM" ); if( pszTerm == NULL || *pszTerm == '\0' ) { if( pszFree ) hb_xfree( pszFree ); pszTerm = pszFree = hb_getenv( "TERM" ); } if( pszTerm != NULL && *pszTerm != '\0' ) { char * pszFile = hb_getenv( "HB_CHARMAP" ); if( pszFile != NULL && *pszFile != '\0' ) nRet = hb_gt_chrmapread( pszFile, pszTerm, piTransTbl ); if( nRet == -1 ) { char szFile[ HB_PATH_MAX ]; if( pszFile ) hb_xfree( pszFile ); pszFile = hb_getenv( "HB_ROOT" ); if( pszFile != NULL && sizeof( szFile ) > strlen( pszFile ) + strlen( s_szCharMapFileDefault ) ) { hb_strncpy( szFile, pszFile, sizeof( szFile ) - 1 ); hb_strncat( szFile, s_szCharMapFileDefault, sizeof( szFile ) - 1 ); nRet = hb_gt_chrmapread( szFile, pszTerm, piTransTbl ); } } if( pszFile ) hb_xfree( pszFile ); if( nRet == -1 ) nRet = hb_gt_chrmapread( s_szCharMapFileDefault, pszTerm, piTransTbl ); } if( pszFree ) hb_xfree( pszFree ); if( nRet == -1 ) { chrmap_dotctrl( piTransTbl ); if( fSetACSC ) chrmap_acscbox( piTransTbl ); else chrmap_ascictrl( piTransTbl ); } return nRet; }
static BOOL hb_gt_std_SetKeyCP( PHB_GT pGT, const char *pszTermCDP, const char *pszHostCDP ) { HB_TRACE( HB_TR_DEBUG, ( "hb_gt_std_SetKeyCP(%p,%s,%s)", pGT, pszTermCDP, pszHostCDP ) ); HB_GTSUPER_SETKEYCP( pGT, pszTermCDP, pszHostCDP ); #ifndef HB_CDP_SUPPORT_OFF if( !pszHostCDP ) pszHostCDP = hb_cdpID(); if( !pszTermCDP ) pszTermCDP = pszHostCDP; if( pszTermCDP && pszHostCDP ) { PHB_CODEPAGE cdpTerm = hb_cdpFind( pszTermCDP ), cdpHost = hb_cdpFind( pszHostCDP ); if( cdpTerm && cdpHost && cdpTerm != cdpHost && cdpTerm->nChars && cdpTerm->nChars == cdpHost->nChars ) { char *pszHostLetters = ( char * ) hb_xgrab( cdpHost->nChars * 2 + 1 ); char *pszTermLetters = ( char * ) hb_xgrab( cdpTerm->nChars * 2 + 1 ); hb_strncpy( pszHostLetters, cdpHost->CharsUpper, cdpHost->nChars * 2 ); hb_strncat( pszHostLetters, cdpHost->CharsLower, cdpHost->nChars * 2 ); hb_strncpy( pszTermLetters, cdpTerm->CharsUpper, cdpTerm->nChars * 2 ); hb_strncat( pszTermLetters, cdpTerm->CharsLower, cdpTerm->nChars * 2 ); hb_gt_std_setKeyTrans( HB_GTSTD_GET( pGT ), pszTermLetters, pszHostLetters ); hb_xfree( pszHostLetters ); hb_xfree( pszTermLetters ); } else hb_gt_std_setKeyTrans( HB_GTSTD_GET( pGT ), NULL, NULL ); return TRUE; } #endif return FALSE; }
char * hb_verCompiler( void ) { char * pszCompiler; const char * pszName; char szSub[ 64 ]; int iVerMajor; int iVerMinor; int iVerPatch; int iVerMicro = 0; int iElements = 0; HB_TRACE( HB_TR_DEBUG, ( "hb_verCompiler()" ) ); pszCompiler = ( char * ) hb_xgrab( COMPILER_BUF_SIZE ); szSub[ 0 ] = '\0'; #if defined( __IBMC__ ) || defined( __IBMCPP__ ) #if defined( __IBMC__ ) iVerMajor = __IBMC__; #else iVerMajor = __IBMCPP__; #endif if( iVerMajor >= 300 ) pszName = "IBM Visual Age C++"; else pszName = "IBM C++"; iVerMajor /= 100; iVerMinor = iVerMajor % 100; iVerPatch = 0; #elif defined( __POCC__ ) pszName = "Pelles ISO C Compiler"; iVerMajor = __POCC__ / 100; iVerMinor = __POCC__ % 100; iVerPatch = 0; #elif defined( __XCC__ ) pszName = "Pelles ISO C Compiler (XCC)"; iVerMajor = __XCC__ / 100; iVerMinor = __XCC__ % 100; iVerPatch = 0; #elif defined( __LCC__ ) pszName = "Logiciels/Informatique lcc-win32"; iVerMajor = 0 /* __LCC__ / 100 */; iVerMinor = 0 /* __LCC__ % 100 */; iVerPatch = 0; #elif defined( __DMC__ ) pszName = __DMC_VERSION_STRING__; iVerMajor = 0; iVerMinor = 0; iVerPatch = 0; #elif defined( __INTEL_COMPILER ) pszName = "Intel(R) C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __INTEL_COMPILER / 100; iVerMinor = ( __INTEL_COMPILER % 100 ) / 10; iVerPatch = 0; #elif defined( __ICL ) pszName = "Intel(R) C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __ICL / 100; iVerMinor = __ICL % 100; iVerPatch = 0; #elif defined( __ICC ) pszName = "Intel(R) (ICC) C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __ICC / 100; iVerMinor = __ICC % 100; iVerPatch = 0; #elif defined( __OPENCC__ ) pszName = "Open64 C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __OPENCC__; iVerMinor = __OPENCC_MINOR__; #if __OPENCC_PATCHLEVEL__ - 0 <= 0 #undef __OPENCC_PATCHLEVEL__ #define __OPENCC_PATCHLEVEL__ 0 #endif iVerPatch = __OPENCC_PATCHLEVEL__; #elif defined( __clang__ ) && defined( __clang_major__ ) /* NOTE: keep clang detection before msvc detection. */ pszName = "LLVM/Clang C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __clang_major__; iVerMinor = __clang_minor__; iVerPatch = __clang_patchlevel__; #elif defined( __clang__ ) pszName = "LLVM/Clang C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif hb_strncat( szSub, " 1.x", sizeof( szSub ) - 1 ); iVerMajor = iVerMinor = iVerPatch = 0; #elif defined( __llvm__ ) && defined( __GNUC__ ) pszName = "LLVM/GNU C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __GNUC__; iVerMinor = __GNUC_MINOR__; #if defined( __GNUC_PATCHLEVEL__ ) iVerPatch = __GNUC_PATCHLEVEL__; #else iVerPatch = 0; #endif #elif defined( _MSC_VER ) #if _MSC_VER >= 800 pszName = "Microsoft Visual C"; #else pszName = "Microsoft C"; #endif #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = _MSC_VER / 100; iVerMinor = _MSC_VER % 100; #if defined( _MSC_FULL_VER ) #if _MSC_VER >= 1400 iVerPatch = _MSC_FULL_VER - ( _MSC_VER * 100000 ); #else iVerPatch = _MSC_FULL_VER - ( _MSC_VER * 10000 ); #endif #else iVerPatch = 0; #endif #elif defined( __BORLANDC__ ) #if __BORLANDC__ >= 0x0590 /* Version 5.9 */ #if __BORLANDC__ >= 0x0620 /* Version 6.2 */ pszName = "Borland/Embarcadero C++"; #else pszName = "Borland/CodeGear C++"; #endif #else pszName = "Borland C++"; #endif #if __BORLANDC__ == 0x0400 /* Version 3.0 */ iVerMajor = 3; iVerMinor = 0; iVerPatch = 0; #elif __BORLANDC__ == 0x0410 /* Version 3.1 */ iVerMajor = 3; iVerMinor = 1; iVerPatch = 0; #elif __BORLANDC__ == 0x0452 /* Version 4.0 */ iVerMajor = 4; iVerMinor = 0; iVerPatch = 0; #elif __BORLANDC__ == 0x0460 /* Version 4.5 */ iVerMajor = 4; iVerMinor = 5; iVerPatch = 0; #elif __BORLANDC__ >= 0x0500 /* Version 5.x */ iVerMajor = __BORLANDC__ >> 8; iVerMinor = ( __BORLANDC__ & 0xFF ) >> 4; iVerPatch = __BORLANDC__ & 0xF; #else /* Version 4.x */ iVerMajor = __BORLANDC__ >> 8; iVerMinor = ( __BORLANDC__ - 1 & 0xFF ) >> 4; iVerPatch = 0; #endif #elif defined( __TURBOC__ ) pszName = "Borland Turbo C"; iVerMajor = __TURBOC__ >> 8; iVerMinor = __TURBOC__ & 0xFF; iVerPatch = 0; #elif defined( __MPW__ ) pszName = "MPW C"; iVerMajor = __MPW__ / 100; iVerMinor = __MPW__ % 100; iVerPatch = 0; #elif defined( __WATCOMC__ ) #if __WATCOMC__ < 1200 pszName = "Watcom C"; #else pszName = "Open Watcom C"; #endif #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __WATCOMC__ / 100; iVerMinor = __WATCOMC__ % 100; #if defined( __WATCOM_REVISION__ ) iVerPatch = __WATCOM_REVISION__; #else iVerPatch = 0; #endif #elif defined( __DCC__ ) pszName = "Wind River Compiler (diab)"; iVerMajor = ( __VERSION_NUMBER__ / 1000 ) % 10; iVerMinor = ( __VERSION_NUMBER__ / 100 ) % 10; iVerPatch = ( __VERSION_NUMBER__ / 10 ) % 10; iVerMicro = __VERSION_NUMBER__ % 10; iElements = 4; #elif defined( __TINYC__ ) pszName = "Tiny C Compiler"; iVerMajor = __TINYC__ / 100; iVerMinor = ( __TINYC__ % 100 ) / 10; iVerPatch = ( __TINYC__ % 100 ) % 10; #elif defined( __PCC__ ) pszName = "Portable C Compiler"; iVerMajor = __PCC__; iVerMinor = __PCC_MINOR__; iVerPatch = __PCC_MINORMINOR__; #if defined( __GNUC__ ) hb_snprintf( szSub, sizeof( szSub ), " (GCC %d.%d.%d emul.)", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ ); #endif #elif defined( __GNUC__ ) #if defined( __DJGPP__ ) pszName = "Delorie GNU C"; #elif defined( __CYGWIN__ ) pszName = "Cygwin GNU C"; #elif defined( __MINGW32__ ) pszName = "MinGW GNU C"; #elif defined( __RSX32__ ) pszName = "EMX/RSXNT/DOS GNU C"; #elif defined( __RSXNT__ ) pszName = "EMX/RSXNT/Win32 GNU C"; #elif defined( __EMX__ ) pszName = "EMX GNU C"; #else pszName = "GNU C"; #endif #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __GNUC__; iVerMinor = __GNUC_MINOR__; #if defined( __GNUC_PATCHLEVEL__ ) iVerPatch = __GNUC_PATCHLEVEL__; #else iVerPatch = 0; #endif #elif defined( __SUNPRO_C ) pszName = "Sun C"; #if __SUNPRO_C < 0x1000 iVerMajor = __SUNPRO_C / 0x100; iVerMinor = ( __SUNPRO_C & 0xff ) / 0x10; iVerPatch = __SUNPRO_C & 0xf; #else iVerMajor = __SUNPRO_C / 0x1000; iVerMinor = __SUNPRO_C / 0x10 & 0xff; iVerMinor = iVerMinor / 0x10 * 0xa + iVerMinor % 0x10; iVerPatch = __SUNPRO_C & 0xf; #endif #elif defined( __SUNPRO_CC ) pszName = "Sun C++"; #if __SUNPRO_CC < 0x1000 iVerMajor = __SUNPRO_CC / 0x100; iVerMinor = ( __SUNPRO_CC & 0xff ) / 0x10; iVerPatch = __SUNPRO_CC & 0xf; #else iVerMajor = __SUNPRO_CC / 0x1000; iVerMinor = __SUNPRO_CC / 0x10 & 0xff; iVerMinor = iVerMinor / 0x10 * 0xa + iVerMinor % 0x10; iVerPatch = __SUNPRO_CC & 0xf; #endif #else pszName = NULL; iVerMajor = iVerMinor = iVerPatch = 0; #endif if( pszName ) { if( iElements == 4 ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %d.%d.%d.%d", pszName, szSub, iVerMajor, iVerMinor, iVerPatch, iVerMicro ); else if( iVerPatch != 0 ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %d.%d.%d", pszName, szSub, iVerMajor, iVerMinor, iVerPatch ); else if( iVerMajor != 0 || iVerMinor != 0 ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %d.%d", pszName, szSub, iVerMajor, iVerMinor ); else hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s", pszName, szSub ); } else hb_strncpy( pszCompiler, "(unrecognized)", COMPILER_BUF_SIZE - 1 ); #if defined( __clang_version__ ) if( strstr( __clang_version__, "(" ) ) /* "2.0 (trunk 103176)" -> "(trunk 103176)" */ hb_snprintf( szSub, sizeof( szSub ), " %s", strstr( __clang_version__, "(" ) ); else hb_snprintf( szSub, sizeof( szSub ), " (%s)", __clang_version__ ); hb_strncat( pszCompiler, szSub, COMPILER_BUF_SIZE - 1 ); #endif #if defined( __DJGPP__ ) hb_snprintf( szSub, sizeof( szSub ), " (DJGPP %i.%02i)", ( int ) __DJGPP__, ( int ) __DJGPP_MINOR__ ); hb_strncat( pszCompiler, szSub, COMPILER_BUF_SIZE - 1 ); #endif #if defined( HB_ARCH_16BIT ) hb_strncat( pszCompiler, " (16-bit)", COMPILER_BUF_SIZE - 1 ); #elif defined( HB_ARCH_32BIT ) hb_strncat( pszCompiler, " (32-bit)", COMPILER_BUF_SIZE - 1 ); #elif defined( HB_ARCH_64BIT ) hb_strncat( pszCompiler, " (64-bit)", COMPILER_BUF_SIZE - 1 ); #endif return pszCompiler; }
char * hb_verPlatform( void ) { char * pszPlatform; HB_TRACE( HB_TR_DEBUG, ( "hb_verPlatform()" ) ); pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 ); #if defined( HB_OS_DOS ) { union REGS regs; regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah ); /* Host OS detection: Windows 2.x, 3.x, 95/98 */ { regs.HB_XREGS.ax = 0x1600; HB_DOS_INT86( 0x2F, ®s, ®s ); if( regs.h.al != 0x00 && regs.h.al != 0x80 ) { char szHost[ 128 ]; if( regs.h.al == 0x01 || regs.h.al == 0xFF ) hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" ); else hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } /* Host OS detection: Windows NT family */ { regs.HB_XREGS.ax = 0x3306; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.HB_XREGS.bx == 0x3205 ) hb_strncat( pszPlatform, " (Windows NT)", PLATFORM_BUF_SIZE ); } /* Host OS detection: OS/2 */ { regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.h.al >= 10 ) { char szHost[ 128 ]; if( regs.h.al == 20 && regs.h.ah > 20 ) hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 ); else hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } } #elif defined( HB_OS_OS2 ) { unsigned long aulQSV[ QSV_MAX ] = { 0 }; APIRET rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX ); if( rc == 0 ) { /* is this OS/2 2.x ? */ if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 ) hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld", aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10, aulQSV[ QSV_VERSION_MINOR - 1 ] ); else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f", ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 ); } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" ); } #elif defined( HB_OS_WIN ) { const char * pszName = ""; OSVERSIONINFO osvi; memset( &osvi, 0, sizeof( osvi ) ); #if defined( HB_OS_WIN_CE ) pszName = " CE"; osvi.dwOSVersionInfoSize = sizeof( osvi ); GetVersionEx( &osvi ); #else /* Detection of legacy Windows versions */ switch( hb_iswin9x() ) { case 5: osvi.dwMajorVersion = 4; osvi.dwMinorVersion = 0; pszName = " 95"; break; case 8: osvi.dwMajorVersion = 4; osvi.dwMinorVersion = 10; pszName = " 98"; break; case 9: osvi.dwMajorVersion = 4; osvi.dwMinorVersion = 90; pszName = " ME"; break; } #endif if( pszName[ 0 ] == '\0' ) { #if defined( HB_OS_WIN_CE ) pszName = " CE"; #else if( hb_iswinver( 11, 0, 0, HB_TRUE ) ) { osvi.dwMajorVersion = 11; osvi.dwMinorVersion = 0; pszName = " 11 or newer"; } else if( hb_iswin10() ) { osvi.dwMajorVersion = 10; osvi.dwMinorVersion = 0; if( hb_iswinver( 10, 0, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 10"; else pszName = " Server 2016"; } else if( hb_iswin81() ) { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 3; if( hb_iswinver( 6, 3, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 8.1"; else pszName = " Server 2012 R2"; } else if( hb_iswinvista() ) { if( hb_iswin8() ) { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 2; if( hb_iswinver( 6, 2, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 8"; else pszName = " Server 2012"; } else if( hb_iswinver( 6, 1, 0, HB_FALSE ) ) { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 1; if( hb_iswinver( 6, 1, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 7"; else pszName = " Server 2008 R2"; } else { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 0; if( hb_iswinver( 6, 0, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " Vista"; else pszName = " Server 2008"; } } else if( hb_iswinver( 5, 2, 0, HB_FALSE ) ) { osvi.dwMajorVersion = 5; osvi.dwMinorVersion = 2; if( hb_iswinver( 5, 2, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " XP x64"; else if( GetSystemMetrics( SM_SERVERR2 ) != 0 ) pszName = " Server 2003 R2"; else pszName = " Server 2003"; } else if( hb_iswinver( 5, 1, 0, HB_FALSE ) ) { osvi.dwMajorVersion = 5; osvi.dwMinorVersion = 1; pszName = " XP"; } else if( hb_iswin2k() ) { osvi.dwMajorVersion = 5; osvi.dwMinorVersion = 0; pszName = " 2000"; } else pszName = " NT"; #endif } hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows%s%s %lu.%lu", pszName, s_iWine ? " (Wine)" : "", osvi.dwMajorVersion, osvi.dwMinorVersion ); /* Add service pack/other info */ if( hb_iswin2k() ) { int tmp; for( tmp = 5; tmp > 0; --tmp ) { if( hb_iswinsp( tmp, HB_TRUE ) ) { char szServicePack[ 8 ]; hb_snprintf( szServicePack, sizeof( szServicePack ), " SP%u", tmp ); hb_strncat( pszPlatform, szServicePack, PLATFORM_BUF_SIZE ); break; } } } #if defined( HB_OS_WIN_CE ) else { /* Also for Win9x and NT, but GetVersionEx() is deprecated so we avoid it. */ if( osvi.szCSDVersion[ 0 ] != TEXT( '\0' ) ) { char * pszCSDVersion = HB_OSSTRDUP( osvi.szCSDVersion ); int i; /* Skip the leading spaces (Win95B, Win98) */ for( i = 0; pszCSDVersion[ i ] != '\0' && HB_ISSPACE( ( int ) pszCSDVersion[ i ] ); i++ ) ; if( pszCSDVersion[ i ] != '\0' ) { hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE ); hb_strncat( pszPlatform, pszCSDVersion + i, PLATFORM_BUF_SIZE ); } hb_xfree( pszCSDVersion ); } } #endif } #elif defined( __CEGCC__ ) { hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" ); } #elif defined( HB_OS_UNIX ) { struct utsname un; uname( &un ); #if defined( HB_OS_MINIX ) hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s Release %s Version %s %s", un.sysname, un.release, un.version, un.machine ); #else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine ); #endif } #else { hb_strncpy( pszPlatform, "(unrecognized)", PLATFORM_BUF_SIZE ); } #endif return pszPlatform; }
char * hb_verPlatform( void ) { char * pszPlatform; HB_TRACE(HB_TR_DEBUG, ("hb_verPlatform()")); pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 ); #if defined(HB_OS_DOS) { union REGS regs; regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah ); /* Host OS detection: Windows 2.x, 3.x, 95/98 */ { regs.HB_XREGS.ax = 0x1600; HB_DOS_INT86( 0x2F, ®s, ®s ); if( regs.h.al != 0x00 && regs.h.al != 0x80 ) { char szHost[ 128 ]; if( regs.h.al == 0x01 || regs.h.al == 0xFF ) hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" ); else hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } /* Host OS detection: Windows NT/2000 */ { regs.HB_XREGS.ax = 0x3306; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.HB_XREGS.bx == 0x3205 ) hb_strncat( pszPlatform, " (Windows NT/2000)", PLATFORM_BUF_SIZE ); } /* Host OS detection: OS/2 */ { regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.h.al >= 10 ) { char szHost[ 128 ]; if( regs.h.al == 20 && regs.h.ah > 20 ) hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 ); else hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } } #elif defined(HB_OS_OS2) { unsigned long aulQSV[ QSV_MAX ] = { 0 }; APIRET rc; rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX ); if( rc == 0 ) { /* is this OS/2 2.x ? */ if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 ) { hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld", aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10, aulQSV[ QSV_VERSION_MINOR - 1 ] ); } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f", ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 ); } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" ); } #elif defined(HB_OS_WIN_32) { OSVERSIONINFOA osVer; osVer.dwOSVersionInfoSize = sizeof( osVer ); if( GetVersionExA( &osVer ) ) { const char *szName = NULL; const char *szProduct = NULL; switch( osVer.dwPlatformId ) { case VER_PLATFORM_WIN32_WINDOWS: if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion < 10 ) { szName = " 95"; } else if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion == 10 ) { szName = " 98"; } else { szName = " ME"; } break; case VER_PLATFORM_WIN32_NT: if( osVer.dwMajorVersion == 6 ) { szName = " Windows Vista"; } else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion == 2 ) { szName = " Server 2003"; } else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion == 1 ) { szName = " XP"; } else if( osVer.dwMajorVersion == 5 ) { szName = " 2000"; } else { szName = " NT"; } /* test for specific product on Windows NT 4.0 SP6 and later */ { HBOSVERSIONINFOEX osVerEx; /* NOTE */ osVerEx.dwOSVersionInfoSize = sizeof( osVerEx ); /* Windows decl error? */ if( GetVersionEx( ( LPOSVERSIONINFOA ) &osVerEx ) ) { /* workstation type */ if( osVerEx.wProductType == VER_NT_WORKSTATION ) { if( osVerEx.dwMajorVersion == 4 ) { szProduct = " Workstation 4.0"; } else if( osVerEx.wSuiteMask & VER_SUITE_PERSONAL ) { szProduct = " Home Edition"; } else { szProduct = " Professional"; } } /* server type */ else if( osVerEx.wProductType == VER_NT_SERVER ) { if( osVerEx.dwMajorVersion == 5 && osVerEx.dwMinorVersion == 2 ) { if( osVerEx.wSuiteMask & VER_SUITE_DATACENTER ) { szProduct = " Datacenter Edition"; } else if( osVerEx.wSuiteMask & VER_SUITE_ENTERPRISE ) { szProduct = " Enterprise Edition"; } else if( osVerEx.wSuiteMask == VER_SUITE_BLADE ) { szProduct = " Web Edition"; } else { szProduct = " Standard Edition"; } } else if( osVerEx.dwMajorVersion == 5 && osVerEx.dwMinorVersion == 0 ) { if( osVerEx.wSuiteMask & VER_SUITE_DATACENTER ) { szProduct = " Datacenter Server"; } else if( osVerEx.wSuiteMask & VER_SUITE_ENTERPRISE ) { szProduct = " Advanced Server"; } else { szProduct = " Server"; } } else { if( osVerEx.wSuiteMask & VER_SUITE_ENTERPRISE ) { szProduct = " Server 4.0, Enterprise Edition"; } else { szProduct = " Server 4.0"; } } } } } break; case VER_PLATFORM_WIN32s: szName = " 32s"; break; case VER_PLATFORM_WIN32_CE: szName = " CE"; break; } hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows %s%s %lu.%02lu.%04d", szName ? szName : NULL, szProduct ? szProduct : "", ( ULONG ) osVer.dwMajorVersion, ( ULONG ) osVer.dwMinorVersion, ( USHORT ) LOWORD( osVer.dwBuildNumber ) ); /* Add service pack/other info */ if( osVer.szCSDVersion ) { int i; /* Skip the leading spaces (Win95B, Win98) */ for( i = 0; osVer.szCSDVersion[ i ] != '\0' && isspace( ( int ) osVer.szCSDVersion[ i ] ); i++ ) {}; if( osVer.szCSDVersion[ i ] != '\0' ) { hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE ); hb_strncat( pszPlatform, osVer.szCSDVersion + i, PLATFORM_BUF_SIZE ); } } } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows" ); } #elif defined(__CEGCC__) { hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" ); } #elif defined(HB_OS_UNIX) { struct utsname un; uname( &un ); hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine ); } #elif defined(HB_OS_MAC) { hb_strncpy( pszPlatform, "MacOS compatible", PLATFORM_BUF_SIZE ); } #else { hb_strncpy( pszPlatform, "(unknown)", PLATFORM_BUF_SIZE ); } #endif return pszPlatform; }
static LONG WINAPI hb_winExceptionHandler( struct _EXCEPTION_POINTERS * pExceptionInfo ) { char errmsg[ 8192 ]; int errmsglen = sizeof( errmsg ) - 1; errmsg[ 0 ] = '\0'; #if defined( HB_OS_WIN_64 ) && defined( HB_CPU_X86_64 ) { char buf[ 32 ]; PCONTEXT pCtx = pExceptionInfo->ContextRecord; const char * szCode; /* two most common codes */ switch( pExceptionInfo->ExceptionRecord->ExceptionCode ) { case EXCEPTION_ACCESS_VIOLATION: szCode = " " "ACCESS_VIOLATION"; break; case EXCEPTION_IN_PAGE_ERROR: szCode = " " "IN_PAGE_ERROR"; break; default: szCode = ""; } hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X%s\n" " Exception Address:%016" PFLL "X\n" " RAX:%016" PFLL "X RBX:%016" PFLL "X RCX:%016" PFLL "X RDX:%016" PFLL "X\n" " RSI:%016" PFLL "X RDI:%016" PFLL "X RBP:%016" PFLL "X\n" " R8 :%016" PFLL "X R9 :%016" PFLL "X R10:%016" PFLL "X R11:%016" PFLL "X\n" " R12:%016" PFLL "X R13:%016" PFLL "X R14:%016" PFLL "X R15:%016" PFLL "X\n" " CS:RIP:%04X:%016" PFLL "X SS:RSP:%04X:%016" PFLL "X\n" " DS:%04X ES:%04X FS:%04X GS:%04X\n" " Flags:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, szCode, ( HB_PTRDIFF ) pExceptionInfo->ExceptionRecord->ExceptionAddress, pCtx->Rax, pCtx->Rbx, pCtx->Rcx, pCtx->Rdx, pCtx->Rsi, pCtx->Rdi, pCtx->Rbp, pCtx->R8 , pCtx->R9 , pCtx->R10, pCtx->R11, pCtx->R12, pCtx->R13, pCtx->R14, pCtx->R15, ( HB_U32 ) pCtx->SegCs, pCtx->Rip, ( HB_U32 ) pCtx->SegSs, pCtx->Rsp, ( HB_U32 ) pCtx->SegDs, ( HB_U32 ) pCtx->SegEs, ( HB_U32 ) pCtx->SegFs, ( HB_U32 ) pCtx->SegGs, ( HB_U32 ) pCtx->EFlags ); if( pExceptionInfo->ExceptionRecord->NumberParameters && pExceptionInfo->ExceptionRecord->NumberParameters < ( DWORD ) EXCEPTION_MAXIMUM_PARAMETERS ) { DWORD arg; hb_strncat( errmsg, " Exception Parameters:", errmsglen ); for( arg = 0; arg < pExceptionInfo->ExceptionRecord->NumberParameters; ++arg ) { hb_snprintf( buf, sizeof( buf ), " %016" PFLL "X", ( HB_U64 ) pExceptionInfo->ExceptionRecord->ExceptionInformation[ arg ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n", errmsglen ); } /* TODO: 64-bit stack trace. See: - StackWalk64() - https://www.codeproject.com/KB/threads/StackWalker.aspx?fid=202364 */ } #elif defined( HB_OS_WIN_64 ) && defined( HB_CPU_IA_64 ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%016" PFLL "X\n" " IS0 :%016" PFLL "X IS1 :%016" PFLL "X IS2 :%016" PFLL "X IS3 :%016" PFLL "X\n" " IT0 :%016" PFLL "X IT1 :%016" PFLL "X IT2 :%016" PFLL "X IT3 :%016" PFLL "X\n" " IT4 :%016" PFLL "X IT5 :%016" PFLL "X IT6 :%016" PFLL "X IT7 :%016" PFLL "X\n" " IT8 :%016" PFLL "X IT9 :%016" PFLL "X IT10:%016" PFLL "X IT11:%016" PFLL "X\n" " IT12:%016" PFLL "X IT13:%016" PFLL "X IT14:%016" PFLL "X IT15:%016" PFLL "X\n" " IT16:%016" PFLL "X IT17:%016" PFLL "X IT18:%016" PFLL "X IT19:%016" PFLL "X\n" " IT20:%016" PFLL "X IT21:%016" PFLL "X IT22:%016" PFLL "X\n" " IGp :%016" PFLL "X IV0 :%016" PFLL "X ISp :%016" PFLL "X ITeb:%016" PFLL "X\n" " INat:%016" PFLL "X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, pExceptionInfo->ExceptionRecord->ExceptionAddress, pCtx->IntS0 , pCtx->IntS1 , pCtx->IntS2 , pCtx->IntS3 , pCtx->IntT0 , pCtx->IntT1 , pCtx->IntT2 , pCtx->IntT3 , pCtx->IntT4 , pCtx->IntT5 , pCtx->IntT6 , pCtx->IntT7 , pCtx->IntT8 , pCtx->IntT9 , pCtx->IntT10, pCtx->IntT11, pCtx->IntT12, pCtx->IntT13, pCtx->IntT14, pCtx->IntT15, pCtx->IntT16, pCtx->IntT17, pCtx->IntT18, pCtx->IntT19, pCtx->IntT20, pCtx->IntT21, pCtx->IntT22, pCtx->IntGp , pCtx->IntV0 , pCtx->IntSp , pCtx->IntTeb, pCtx->IntNats ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_ARM ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%08X\n" " R0 :%08X R1 :%08X R2 :%08X R3 :%08X\n" " R4 :%08X R5 :%08X R6 :%08X R7 :%08X\n" " R8 :%08X R9 :%08X R10:%08X R11:%08X\n" " R12:%08X\n" " SP :%08X LR :%08X PC :%08X\n" " Flags:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->R0 , ( HB_U32 ) pCtx->R1 , ( HB_U32 ) pCtx->R2 , ( HB_U32 ) pCtx->R3 , ( HB_U32 ) pCtx->R4 , ( HB_U32 ) pCtx->R5 , ( HB_U32 ) pCtx->R6 , ( HB_U32 ) pCtx->R7 , ( HB_U32 ) pCtx->R8 , ( HB_U32 ) pCtx->R9 , ( HB_U32 ) pCtx->R10, ( HB_U32 ) pCtx->R11, ( HB_U32 ) pCtx->R12, ( HB_U32 ) pCtx->Sp , ( HB_U32 ) pCtx->Lr , ( HB_U32 ) pCtx->Pc, ( HB_U32 ) pCtx->Psr ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_MIPS ) && defined( HB_ARCH_32BIT ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%08X\n" " IZe:%08X IAt:%08X ILo:%08X IHi:%08X\n" " IA0:%08X IA1:%08X IA2:%08X IA3:%08X\n" " IT0:%08X IT1:%08X IT2:%08X IT3:%08X\n" " IT4:%08X IT5:%08X IT6:%08X IT7:%08X\n" " IT8:%08X IT9:%08X IV0:%08X IV1:%08X\n" " IS0:%08X IS1:%08X IS2:%08X IS3:%08X\n" " IS4:%08X IS5:%08X IS6:%08X IS7:%08X\n" " IS8:%08X IK0:%08X IK1:%08X\n" " IGp:%08X ISp:%08X IRa:%08X\n" " Fsr:%08X Fir:%08X Psr:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->IntZero, ( HB_U32 ) pCtx->IntAt, ( HB_U32 ) pCtx->IntLo, ( HB_U32 ) pCtx->IntHi, ( HB_U32 ) pCtx->IntA0, ( HB_U32 ) pCtx->IntA1, ( HB_U32 ) pCtx->IntA2, ( HB_U32 ) pCtx->IntA3, ( HB_U32 ) pCtx->IntT0, ( HB_U32 ) pCtx->IntT1, ( HB_U32 ) pCtx->IntT2, ( HB_U32 ) pCtx->IntT3, ( HB_U32 ) pCtx->IntT4, ( HB_U32 ) pCtx->IntT5, ( HB_U32 ) pCtx->IntT6, ( HB_U32 ) pCtx->IntT7, ( HB_U32 ) pCtx->IntT8, ( HB_U32 ) pCtx->IntT9, ( HB_U32 ) pCtx->IntV0, ( HB_U32 ) pCtx->IntV1, ( HB_U32 ) pCtx->IntS0, ( HB_U32 ) pCtx->IntS1, ( HB_U32 ) pCtx->IntS2, ( HB_U32 ) pCtx->IntS3, ( HB_U32 ) pCtx->IntS4, ( HB_U32 ) pCtx->IntS5, ( HB_U32 ) pCtx->IntS6, ( HB_U32 ) pCtx->IntS7, ( HB_U32 ) pCtx->IntS8, ( HB_U32 ) pCtx->IntK0, ( HB_U32 ) pCtx->IntK1, ( HB_U32 ) pCtx->IntGp, ( HB_U32 ) pCtx->IntSp, ( HB_U32 ) pCtx->IntRa, ( HB_U32 ) pCtx->Fsr , ( HB_U32 ) pCtx->Fir , ( HB_U32 ) pCtx->Psr ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_MIPS ) && defined( HB_ARCH_64BIT ) /* Such platform doesn't currently exist [2010]. */ { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%016" PFLL "X\n" " IZe:%016" PFLL "X IAt:%016" PFLL "X ILo:%016" PFLL "X IHi:%016" PFLL "X\n" " IA0:%016" PFLL "X IA1:%016" PFLL "X IA2:%016" PFLL "X IA3:%016" PFLL "X\n" " IT0:%016" PFLL "X IT1:%016" PFLL "X IT2:%016" PFLL "X IT3:%016" PFLL "X\n" " IT4:%016" PFLL "X IT5:%016" PFLL "X IT6:%016" PFLL "X IT7:%016" PFLL "X\n" " IT8:%016" PFLL "X IT9:%016" PFLL "X IV0:%016" PFLL "X IV1:%016" PFLL "X\n" " IS0:%016" PFLL "X IS1:%016" PFLL "X IS2:%016" PFLL "X IS3:%016" PFLL "X\n" " IS4:%016" PFLL "X IS5:%016" PFLL "X IS6:%016" PFLL "X IS7:%016" PFLL "X\n" " IS8:%016" PFLL "X IK0:%016" PFLL "X IK1:%016" PFLL "X\n" " IGp:%016" PFLL "X ISp:%016" PFLL "X IRa:%016" PFLL "X\n" " Fsr:%016" PFLL "X Fir:%016" PFLL "X Psr:%016" PFLL "X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, pExceptionInfo->ExceptionRecord->ExceptionAddress, pCtx->IntZero, pCtx->IntAt, pCtx->IntLo, pCtx->IntHi, pCtx->IntA0, pCtx->IntA1, pCtx->IntA2, pCtx->IntA3, pCtx->IntT0, pCtx->IntT1, pCtx->IntT2, pCtx->IntT3, pCtx->IntT4, pCtx->IntT5, pCtx->IntT6, pCtx->IntT7, pCtx->IntT8, pCtx->IntT9, pCtx->IntV0, pCtx->IntV1, pCtx->IntS0, pCtx->IntS1, pCtx->IntS2, pCtx->IntS3, pCtx->IntS4, pCtx->IntS5, pCtx->IntS6, pCtx->IntS7, pCtx->IntS8, pCtx->IntK0, pCtx->IntK1, pCtx->IntGp, pCtx->IntSp, pCtx->IntRa, pCtx->Fsr , pCtx->Fir , pCtx->Psr ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_SH ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%08X\n" " R0 :%08X R1 :%08X R2 :%08X R3 :%08X\n" " R4 :%08X R5 :%08X R6 :%08X R7 :%08X\n" " R8 :%08X R9 :%08X R10:%08X R11:%08X\n" " R12:%08X R13:%08X R14:%08X R15:%08X\n" " PR :%08X MACH:%08X MACL:%08X GBR:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->R0 , ( HB_U32 ) pCtx->R1 , ( HB_U32 ) pCtx->R2 , ( HB_U32 ) pCtx->R3 , ( HB_U32 ) pCtx->R4 , ( HB_U32 ) pCtx->R5 , ( HB_U32 ) pCtx->R6 , ( HB_U32 ) pCtx->R7 , ( HB_U32 ) pCtx->R8 , ( HB_U32 ) pCtx->R9 , ( HB_U32 ) pCtx->R10, ( HB_U32 ) pCtx->R11, ( HB_U32 ) pCtx->R12, ( HB_U32 ) pCtx->R13, ( HB_U32 ) pCtx->R14, ( HB_U32 ) pCtx->R15, ( HB_U32 ) pCtx->PR, ( HB_U32 ) pCtx->MACH, ( HB_U32 ) pCtx->MACL, ( HB_U32 ) pCtx->GBR ); } #elif defined( HB_CPU_X86 ) { char buf[ 64 + MAX_PATH ]; PCONTEXT pCtx = pExceptionInfo->ContextRecord; const char * szCode; /* two most common codes */ switch( pExceptionInfo->ExceptionRecord->ExceptionCode ) { case EXCEPTION_ACCESS_VIOLATION: szCode = " " "ACCESS_VIOLATION"; break; case EXCEPTION_IN_PAGE_ERROR: szCode = " " "IN_PAGE_ERROR"; break; default: szCode = ""; } hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X%s\n" " Exception Address:%08X\n" " EAX:%08X EBX:%08X ECX:%08X EDX:%08X\n" " ESI:%08X EDI:%08X EBP:%08X\n" " CS:EIP:%04X:%08X SS:ESP:%04X:%08X\n" " DS:%04X ES:%04X FS:%04X GS:%04X\n" " Flags:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, szCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->Eax, ( HB_U32 ) pCtx->Ebx, ( HB_U32 ) pCtx->Ecx, ( HB_U32 ) pCtx->Edx, ( HB_U32 ) pCtx->Esi, ( HB_U32 ) pCtx->Edi, ( HB_U32 ) pCtx->Ebp, ( HB_U32 ) pCtx->SegCs, ( HB_U32 ) pCtx->Eip, ( HB_U32 ) pCtx->SegSs, ( HB_U32 ) pCtx->Esp, ( HB_U32 ) pCtx->SegDs, ( HB_U32 ) pCtx->SegEs, ( HB_U32 ) pCtx->SegFs, ( HB_U32 ) pCtx->SegGs, ( HB_U32 ) pCtx->EFlags ); if( pExceptionInfo->ExceptionRecord->NumberParameters && pExceptionInfo->ExceptionRecord->NumberParameters < ( DWORD ) EXCEPTION_MAXIMUM_PARAMETERS ) { DWORD arg; hb_strncat( errmsg, " Exception Parameters:", errmsglen ); for( arg = 0; arg < pExceptionInfo->ExceptionRecord->NumberParameters; ++arg ) { hb_snprintf( buf, sizeof( buf ), " %08X", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionInformation[ arg ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n", errmsglen ); } { unsigned char * pc; unsigned int * sc; unsigned int * ebp; unsigned int eip; unsigned int j; int i; hb_strncat( errmsg, " CS:EIP:", errmsglen ); pc = ( unsigned char * ) pCtx->Eip; for( i = 0; i < 16; i++ ) { /* TOFIX: Unsafe funcion. */ if( IsBadReadPtr( pc, 1 ) ) break; hb_snprintf( buf, sizeof( buf ), " %02X", ( int ) pc[ i ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n SS:ESP:", errmsglen ); sc = ( unsigned int * ) pCtx->Esp; for( i = 0; i < 16; i++ ) { /* TOFIX: Unsafe funcion. */ if( IsBadReadPtr( sc, 4 ) ) break; hb_snprintf( buf, sizeof( buf ), " %08X", sc[ i ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n\n", errmsglen ); hb_strncat( errmsg, " C stack:\n", errmsglen ); hb_strncat( errmsg, " EIP: EBP: Frame: OldEBP, RetAddr, Params...\n", errmsglen ); eip = pCtx->Eip; ebp = ( unsigned int * ) pCtx->Ebp; /* TOFIX: Unsafe funcion. */ if( ! IsBadWritePtr( ebp, 8 ) ) { for( i = 0; i < 20; i++ ) { /* TOFIX: Unsafe funcion. */ if( ( unsigned int ) ebp % 4 != 0 || IsBadWritePtr( ebp, 40 ) || ( unsigned int ) ebp >= ebp[ 0 ] ) break; hb_snprintf( buf, sizeof( buf ), " %08X %08X ", ( int ) eip, ( int ) ebp ); hb_strncat( errmsg, buf, errmsglen ); for( j = 0; j < 10 && ( unsigned int ) ( ebp + j ) < ebp[ 0 ]; j++ ) { hb_snprintf( buf, sizeof( buf ), " %08X", ebp[ j ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n", errmsglen ); eip = ebp[ 1 ]; ebp = ( unsigned int * ) ebp[ 0 ]; } hb_strncat( errmsg, "\n", errmsglen ); } } } #endif { #if defined( HB_OS_WIN_CE ) HMODULE hToolhelp = GetModuleHandle( TEXT( "toolhelp.dll" ) ); #else /* NOTE: Several non-MS sources say that Win9x has these functions in tlhelp32.dll. Testing shows though, that in Win95, Win95b and Win98 they are in kernel32.dll, and tlhelp32.dll doesn't exist. [vszakats] */ HMODULE hToolhelp = GetModuleHandle( TEXT( "kernel32.dll" ) ); #endif if( hToolhelp ) { /* NOTE: Hack to force the ASCII versions of these types. [vszakats] */ #if ! defined( HB_OS_WIN_CE ) && defined( UNICODE ) #undef MODULEENTRY32 #undef LPMODULEENTRY32 #endif typedef HANDLE ( WINAPI * P_CTH32SSH )( DWORD, DWORD ); /* CreateToolhelp32Snapshot() */ typedef BOOL ( WINAPI * P_M32F )( HANDLE, LPMODULEENTRY32 ); /* Module32First() */ typedef BOOL ( WINAPI * P_M32N )( HANDLE, LPMODULEENTRY32 ); /* Module32Next() */ P_CTH32SSH pCreateToolhelp32Snapshot = ( P_CTH32SSH ) HB_WINAPI_GETPROCADDRESS( hToolhelp, "CreateToolhelp32Snapshot" ); P_M32F pModule32First = ( P_M32F ) HB_WINAPI_GETPROCADDRESS( hToolhelp, "Module32First" ); P_M32N pModule32Next = ( P_M32N ) HB_WINAPI_GETPROCADDRESS( hToolhelp, "Module32Next" ); if( pCreateToolhelp32Snapshot && pModule32First && pModule32Next ) { /* Take a snapshot of all modules in the specified process. */ HANDLE hModuleSnap = pCreateToolhelp32Snapshot( TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, GetCurrentProcessId() ); if( hModuleSnap != INVALID_HANDLE_VALUE ) { MODULEENTRY32 me32; /* Set the size of the structure before using it. */ me32.dwSize = sizeof( MODULEENTRY32 ); /* Retrieve information about the first module, and exit if unsuccessful */ if( pModule32First( hModuleSnap, &me32 ) ) { hb_strncat( errmsg, "\nModules:\n", errmsglen ); /* Now walk the module list of the process, and display information about each module */ do { char buf[ 256 ]; #if defined( HB_OS_WIN_64 ) /* TOFIX: me32.szExePath seemed trashed in some (standalone) tests. */ hb_snprintf( buf, sizeof( buf ), "%016" PFLL "X %016" PFLL "X %s\n", ( HB_PTRDIFF ) me32.modBaseAddr, ( HB_PTRDIFF ) me32.modBaseSize, me32.szExePath ); #else char szBuffer[ MAX_PATH ]; #if defined( HB_OS_WIN_CE ) hb_wcntombcpy( szBuffer, me32.szExePath, HB_SIZEOFARRAY( szBuffer ) - 1 ); #else hb_strncpy( szBuffer, me32.szExePath, HB_SIZEOFARRAY( szBuffer ) - 1 ); #endif hb_snprintf( buf, sizeof( buf ), "%08lX %08lX %s\n", ( HB_PTRDIFF ) me32.modBaseAddr, ( HB_PTRDIFF ) me32.modBaseSize, szBuffer ); #endif hb_strncat( errmsg, buf, errmsglen ); } while( pModule32Next( hModuleSnap, &me32 ) ); } /* Do not forget to clean up the snapshot object. */ CloseHandle( hModuleSnap ); } } } } hb_errInternalRaw( 6005, "Exception error:%s", errmsg, NULL ); return hb_cmdargCheck( "BATCH" ) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; }
HB_FHANDLE hb_fsCreateTempEx( char * pszName, const char * pszDir, const char * pszPrefix, const char * pszExt, HB_FATTR ulAttr ) { /* less attemps */ int iAttemptLeft = 99, iLen; HB_FHANDLE fd; do { pszName[ 0 ] = '\0'; if( pszDir && pszDir[ 0 ] != '\0' ) { hb_strncpy( pszName, pszDir, HB_PATH_MAX - 1 ); iLen = ( int ) strlen( pszName ); if( pszName[ iLen - 1 ] != HB_OS_PATH_DELIM_CHR && iLen < HB_PATH_MAX - 1 ) { pszName[ iLen ] = HB_OS_PATH_DELIM_CHR; pszName[ iLen + 1 ] = '\0'; } } else hb_fsTempDir( pszName ); if( pszPrefix ) hb_strncat( pszName, pszPrefix, HB_PATH_MAX - 1 ); iLen = ( int ) strlen( pszName ); if( iLen > ( HB_PATH_MAX - 1 ) - 6 - ( pszExt ? ( int ) strlen( pszExt ) : 0 ) ) { fd = FS_ERROR; break; } #if defined( HB_HAS_MKSTEMP ) if( hb_setGetFileCase() != HB_SET_CASE_LOWER && hb_setGetFileCase() != HB_SET_CASE_UPPER && hb_setGetDirCase() != HB_SET_CASE_LOWER && hb_setGetDirCase() != HB_SET_CASE_UPPER #if ! defined( HB_HAS_MKSTEMPS ) && ( pszExt == NULL || *pszExt == 0 ) #endif ) { hb_vmUnlock(); hb_strncat( pszName, "XXXXXX", HB_PATH_MAX - 1 ); #if defined( HB_HAS_MKSTEMPS ) if( pszExt && *pszExt ) { hb_strncat( pszName, pszExt, HB_PATH_MAX - 1 ); #if defined( HB_USE_LARGEFILE64 ) fd = ( HB_FHANDLE ) mkstemps64( pszName, ( int ) strlen( pszExt ) ); #else fd = ( HB_FHANDLE ) mkstemps( pszName, ( int ) strlen( pszExt ) ); #endif } else #endif #if defined( HB_USE_LARGEFILE64 ) fd = ( HB_FHANDLE ) mkstemp64( pszName ); #else fd = ( HB_FHANDLE ) mkstemp( pszName ); #endif hb_fsSetIOError( fd != ( HB_FHANDLE ) -1, 0 ); hb_vmLock(); } else #endif /* HB_HAS_MKSTEMP */ { int i, n; double d = hb_random_num(), x; for( i = 0; i < 6; i++ ) { d = d * 36; n = ( int ) d; d = modf( d, &x ); pszName[ iLen++ ] = ( char ) ( n + ( n > 9 ? 'a' - 10 : '0' ) ); } pszName[ iLen ] = '\0'; if( pszExt ) hb_strncat( pszName, pszExt, HB_PATH_MAX - 1 ); fd = hb_fsCreateEx( pszName, ulAttr, FO_EXCLUSIVE | FO_EXCL ); } if( fd != ( HB_FHANDLE ) FS_ERROR ) break; } while( --iAttemptLeft ); return fd; }
/* This function joins path, name and extension into a string with a filename */ char * hb_fsFNameMerge( char * pszFileName, PHB_FNAME pFileName ) { HB_TRACE( HB_TR_DEBUG, ( "hb_fsFNameMerge(%p, %p)", pszFileName, pFileName ) ); if( pszFileName && pFileName ) { const char * pszName; char cDirSep; /* dir separator set by user */ cDirSep = ( char ) hb_setGetDirSeparator(); /* Set the result to an empty string */ pszFileName[ 0 ] = '\0'; /* Strip preceding path separators from the filename */ pszName = pFileName->szName; if( pszName && pszName[ 0 ] != '\0' && ( pszName[ 0 ] == cDirSep || strchr( HB_OS_PATH_DELIM_CHR_LIST, pszName[ 0 ] ) != NULL ) ) pszName++; /* Add path if specified */ if( pFileName->szPath ) hb_strncat( pszFileName, pFileName->szPath, HB_PATH_MAX - 1 - 1 ); /* If we have a path, append a path separator to the path if there was none. */ if( pszFileName[ 0 ] != '\0' && ( pszName || pFileName->szExtension ) ) { int iLen = ( int ) strlen( pszFileName ) - 1; if( iLen < HB_PATH_MAX - 1 - 2 && pszFileName[ iLen ] != cDirSep && strchr( HB_OS_PATH_DELIM_CHR_LIST, pszFileName[ iLen ] ) == NULL ) { pszFileName[ iLen + 1 ] = HB_OS_PATH_DELIM_CHR; pszFileName[ iLen + 2 ] = '\0'; } } /* Add filename (without extension) if specified */ if( pszName ) hb_strncat( pszFileName, pszName, HB_PATH_MAX - 1 - 1 ); /* Add extension if specified */ if( pFileName->szExtension ) { /* Add a dot if the extension doesn't have it */ if( pFileName->szExtension[ 0 ] != '\0' && pFileName->szExtension[ 0 ] != '.' ) hb_strncat( pszFileName, ".", HB_PATH_MAX - 1 - 1 ); hb_strncat( pszFileName, pFileName->szExtension, HB_PATH_MAX - 1 - 1 ); } HB_TRACE( HB_TR_INFO, ( "hb_fsFNameMerge: szPath: |%s|", pFileName->szPath ) ); HB_TRACE( HB_TR_INFO, ( "hb_fsFNameMerge: szName: |%s|", pFileName->szName ) ); HB_TRACE( HB_TR_INFO, ( "hb_fsFNameMerge: szExt: |%s|", pFileName->szExtension ) ); HB_TRACE( HB_TR_INFO, ( "hb_fsFNameMerge: Filename: |%s|", pszFileName ) ); } return pszFileName; }
static HB_BOOL hb_fsFindNextLow( PHB_FFIND ffind ) { HB_BOOL bFound; int iYear = 0; int iMonth = 0; int iDay = 0; int iHour = 0; int iMin = 0; int iSec = 0; int iMSec = 0; HB_FATTR raw_attr = 0, nAttr = 0; /* Set the default values in case some platforms don't support some of these, or they may fail on them. */ ffind->szName[ 0 ] = '\0'; ffind->size = 0; /* Do platform dependant first/next search */ hb_vmUnlock(); #if defined( HB_OS_DOS ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; /* Handling HB_FA_LABEL doesn't need any special tricks under the MS-DOS platform. */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; /* tzset(); */ #if defined( __WATCOMC__ ) bFound = ( _dos_findfirst( ffind->pszFileMask, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ), &info->entry ) == 0 ); #else bFound = ( findfirst( ffind->pszFileMask, &info->entry, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ) ) == 0 ); #endif } else { #if defined( __WATCOMC__ ) bFound = ( _dos_findnext( &info->entry ) == 0 ); #else bFound = ( findnext( &info->entry ) == 0 ); #endif } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( ffind->szName, info->entry.ff_name, sizeof( ffind->szName ) - 1 ); ffind->size = info->entry.ff_fsize; raw_attr = info->entry.ff_attrib; { time_t ftime; struct tm * ft; struct stat sStat; stat( info->entry.ff_name, &sStat ); ftime = sStat.st_mtime; ft = localtime( &ftime ); iYear = ft->tm_year + 1900; iMonth = ft->tm_mon + 1; iDay = ft->tm_mday; iHour = ft->tm_hour; iMin = ft->tm_min; iSec = ft->tm_sec; } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_OS2 ) { #define HB_OS2_DIRCNT 16 PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; APIRET ret = NO_ERROR; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; info->isWSeB = hb_isWSeB(); info->findSize = sizeof( FILEFINDBUF3L ); if( info->findSize & 0x07 ) info->findSize += 0x08 - ( info->findSize & 0x07 ); info->findSize *= HB_OS2_DIRCNT; if( info->findSize > 0xF000 ) info->findSize = 0xF000; info->findInitCnt = ! info->isWSeB ? info->findSize / 32 : HB_OS2_DIRCNT; info->hFindFile = HDIR_CREATE; info->findCount = info->findInitCnt; ret = DosAllocMem( &info->entry, info->findSize, OBJ_TILE | PAG_COMMIT | PAG_WRITE ); if( ret == NO_ERROR ) { ret = DosFindFirst( ( PCSZ ) ffind->pszFileMask, &info->hFindFile, ( ULONG ) hb_fsAttrToRaw( ffind->attrmask ), info->entry, info->findSize, &info->findCount, FIL_STANDARDL ); bFound = ret == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } else { info->entry = NULL; bFound = HB_FALSE; } } else if( info->findCount == 0 ) { info->findCount = info->findInitCnt; ret = DosFindNext( info->hFindFile, info->entry, info->findSize, &info->findCount ); bFound = ret == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } else bFound = HB_TRUE; if( bFound ) { ULONG oNextEntryOffset; if( info->isWSeB ) { PFILEFINDBUF3L pFFB = ( PFILEFINDBUF3L ) info->next; hb_strncpy( ffind->szName, pFFB->achName, sizeof( ffind->szName ) - 1 ); ffind->size = ( HB_FOFFSET ) pFFB->cbFile; raw_attr = pFFB->attrFile; iYear = pFFB->fdateLastWrite.year + 1980; iMonth = pFFB->fdateLastWrite.month; iDay = pFFB->fdateLastWrite.day; iHour = pFFB->ftimeLastWrite.hours; iMin = pFFB->ftimeLastWrite.minutes; iSec = pFFB->ftimeLastWrite.twosecs * 2; oNextEntryOffset = pFFB->oNextEntryOffset; } else { PFILEFINDBUF3 pFFB = ( PFILEFINDBUF3 ) info->next; hb_strncpy( ffind->szName, pFFB->achName, sizeof( ffind->szName ) - 1 ); ffind->size = ( HB_FOFFSET ) pFFB->cbFile; raw_attr = pFFB->attrFile; iYear = pFFB->fdateLastWrite.year + 1980; iMonth = pFFB->fdateLastWrite.month; iDay = pFFB->fdateLastWrite.day; iHour = pFFB->ftimeLastWrite.hours; iMin = pFFB->ftimeLastWrite.minutes; iSec = pFFB->ftimeLastWrite.twosecs * 2; oNextEntryOffset = pFFB->oNextEntryOffset; } if( oNextEntryOffset > 0 ) { info->next = ( char * ) info->next + oNextEntryOffset; info->findCount--; } else info->findCount = 0; } hb_fsSetError( ( HB_ERRCODE ) ret ); } #elif defined( HB_OS_WIN ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; bFound = HB_FALSE; #if ! defined( HB_OS_WIN_CE ) if( ( ffind->attrmask & HB_FA_LABEL ) != 0 && ! info->fLabelDone ) { TCHAR lpVolName[ HB_PATH_MAX ]; LPTSTR lpFileMask = NULL; char * mask = NULL; info->fLabelDone = HB_TRUE; if( ffind->pszFileMask && *ffind->pszFileMask ) { PHB_FNAME pFileName = hb_fsFNameSplit( ffind->pszFileMask ); if( pFileName->szName && pFileName->szName[ 0 ] ) mask = hb_strdup( pFileName->szName ); if( pFileName->szPath && pFileName->szPath[ 0 ] && ( pFileName->szPath[ 1 ] || pFileName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR ) ) lpFileMask = HB_CHARDUP( pFileName->szPath ); hb_xfree( pFileName ); } bFound = GetVolumeInformation( lpFileMask, lpVolName, HB_SIZEOFARRAY( lpVolName ), NULL, NULL, NULL, NULL, 0 ) != 0; if( bFound ) { HB_OSSTRDUP2( lpVolName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( mask && *mask && ! hb_strMatchFile( ffind->szName, mask ) ) { ffind->szName[ 0 ] = '\0'; bFound = HB_FALSE; } } if( lpFileMask ) hb_xfree( lpFileMask ); if( mask ) hb_xfree( mask ); } #endif if( ! bFound && ( ffind->attrmask & ( HB_FA_LABEL | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY ) ) != HB_FA_LABEL ) { if( ffind->bFirst ) { LPTSTR lpFileMask = HB_CHARDUP( ffind->pszFileMask ); ffind->bFirst = HB_FALSE; info->dwAttr = ( DWORD ) hb_fsAttrToRaw( ffind->attrmask ); info->hFindFile = FindFirstFile( lpFileMask, &info->pFindFileData ); hb_xfree( lpFileMask ); if( ( info->hFindFile != INVALID_HANDLE_VALUE ) && _HB_WIN_MATCH() ) bFound = HB_TRUE; } if( ! bFound && info->hFindFile != INVALID_HANDLE_VALUE ) { while( FindNextFile( info->hFindFile, &info->pFindFileData ) ) { if( _HB_WIN_MATCH() ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { HB_OSSTRDUP2( info->pFindFileData.cFileName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( info->pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ffind->size = 0; else { #if defined( __XCC__ ) || ( defined( __POCC__ ) && __POCC__ >= 500 ) /* NOTE: PellesC 5.00.1 will go into an infinite loop if we don't split this into two operations. [vszakats] */ ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow; ffind->size += ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32; #else ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow + ( ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32 ); #endif } raw_attr = ( HB_FATTR ) info->pFindFileData.dwFileAttributes; /* NOTE: One of these may fail when searching on an UNC path, I don't know yet what's the reason. [vszakats] */ { FILETIME ft; SYSTEMTIME time; if( FileTimeToLocalFileTime( &info->pFindFileData.ftLastWriteTime, &ft ) && FileTimeToSystemTime( &ft, &time ) ) { iYear = time.wYear; iMonth = time.wMonth; iDay = time.wDay; iHour = time.wHour; iMin = time.wMinute; iSec = time.wSecond; iMSec = time.wMilliseconds; } } } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_UNIX ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; char dirname[ HB_PATH_MAX ]; bFound = HB_FALSE; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { char * pos; ffind->bFirst = HB_FALSE; hb_strncpy( dirname, ffind->pszFileMask, sizeof( dirname ) - 1 ); pos = strrchr( dirname, HB_OS_PATH_DELIM_CHR ); if( pos ) { hb_strncpy( info->pattern, pos + 1, sizeof( info->pattern ) - 1 ); *( pos + 1 ) = '\0'; } else { hb_strncpy( info->pattern, dirname, sizeof( info->pattern ) - 1 ); dirname[ 0 ] = '.'; dirname[ 1 ] = HB_OS_PATH_DELIM_CHR; dirname[ 2 ] = '\0'; } /* tzset(); */ info->dir = opendir( dirname ); hb_strncpy( info->path, dirname, sizeof( info->path ) - 1 ); } if( info->dir && info->pattern[ 0 ] != '\0' ) { while( ( info->entry = readdir( info->dir ) ) != NULL ) { if( hb_strMatchFile( info->entry->d_name, info->pattern ) ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( dirname, info->path, sizeof( dirname ) - 1 ); hb_strncat( dirname, info->entry->d_name, sizeof( dirname ) - 1 ); { time_t ftime; struct tm lt; #if defined( HB_USE_LARGEFILE64 ) struct stat64 sStat, sStatL; if( lstat64( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) && ( ffind->attrmask & HB_FA_LINK ) == 0 ) { if( stat64( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #else struct stat sStat, sStatL; if( lstat( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) && ( ffind->attrmask & HB_FA_LINK ) == 0 ) { if( stat( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #endif hb_strncpy( ffind->szName, info->entry->d_name, sizeof( ffind->szName ) - 1 ); ffind->size = sStat.st_size; raw_attr = sStat.st_mode; ftime = sStat.st_mtime; # if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, < ); # else lt = *localtime( &ftime ); # endif iYear = lt.tm_year + 1900; iMonth = lt.tm_mon + 1; iDay = lt.tm_mday; iHour = lt.tm_hour; iMin = lt.tm_min; iSec = lt.tm_sec; # if defined( HB_OS_LINUX ) && \ defined( __GLIBC__ ) && defined( __GLIBC_MINOR__ ) && \ ( __GLIBC__ > 2 || ( __GLIBC__ == 2 && __GLIBC_MINOR__ >= 6 ) ) # if defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) || \ ( __GLIBC_MINOR__ >= 12 && \ ( ( defined( _POSIX_C_SOURCE ) || _POSIX_C_SOURCE >= 200809L ) || \ ( defined( _XOPEN_SOURCE ) || _XOPEN_SOURCE >= 700 ) ) ) iMSec = sStat.st_mtim.tv_nsec / 1000000; # else iMSec = sStat.st_mtimensec / 1000000; # endif # endif } else bFound = HB_FALSE; } } hb_fsSetIOError( bFound, 0 ); } #else { int iTODO; /* TODO: for given platform */ /* HB_SYMBOL_UNUSED( ffind ); */ HB_SYMBOL_UNUSED( iYear ); HB_SYMBOL_UNUSED( iMonth ); HB_SYMBOL_UNUSED( iDay ); HB_SYMBOL_UNUSED( iHour ); HB_SYMBOL_UNUSED( iMin ); HB_SYMBOL_UNUSED( iSec ); HB_SYMBOL_UNUSED( iMSec ); HB_SYMBOL_UNUSED( raw_attr ); bFound = HB_FALSE; hb_fsSetIOError( bFound, 0 ); } #endif /* Fill common Harbour found file info */ if( bFound ) { /* Do the conversions common for all platforms */ ffind->szName[ sizeof( ffind->szName ) - 1 ] = '\0'; #if ! defined( HB_OS_WIN ) /* Convert from OS codepage */ { char * pszFree = NULL; HB_SIZE nSize = sizeof( ffind->szName ); const char * pszResult = hb_osDecodeCP( ffind->szName, &pszFree, &nSize ); if( pszFree ) { hb_strncpy( ffind->szName, pszResult, sizeof( ffind->szName ) - 1 ); hb_xfree( pszFree ); } } #endif ffind->attr = hb_fsAttrFromRaw( raw_attr ) | nAttr; ffind->lDate = hb_dateEncode( iYear, iMonth, iDay ); ffind->lTime = hb_timeEncode( iHour, iMin, iSec, iMSec ); hb_dateStrPut( ffind->szDate, iYear, iMonth, iDay ); ffind->szDate[ 8 ] = '\0'; hb_snprintf( ffind->szTime, sizeof( ffind->szTime ), "%02d:%02d:%02d", iHour, iMin, iSec ); } hb_vmLock(); return bFound; } PHB_FFIND hb_fsFindFirst( const char * pszFileMask, HB_FATTR attrmask ) { PHB_FFIND ffind = ( PHB_FFIND ) hb_xgrabz( sizeof( HB_FFIND ) ); /* Allocate platform dependent file find info storage */ ffind->info = ( void * ) hb_xgrabz( sizeof( HB_FFIND_INFO ) ); /* Store search parameters */ #if defined( HB_OS_WIN ) ffind->pszFileMask = pszFileMask; #else /* Convert to OS codepage */ ffind->pszFileMask = hb_fsNameConv( pszFileMask, &ffind->pszFree ); #endif ffind->attrmask = attrmask; ffind->bFirst = HB_TRUE; /* Find first/next matching file */ if( hb_fsFindNext( ffind ) ) return ffind; /* If no file found at all, free stuff allocated so far and return NULL. */ hb_fsFindClose( ffind ); return NULL; }
char * hb_verPlatform( void ) { char * pszPlatform; HB_TRACE( HB_TR_DEBUG, ( "hb_verPlatform()" ) ); pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 ); #if defined( HB_OS_DOS ) { union REGS regs; regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah ); /* Host OS detection: Windows 2.x, 3.x, 95/98 */ { regs.HB_XREGS.ax = 0x1600; HB_DOS_INT86( 0x2F, ®s, ®s ); if( regs.h.al != 0x00 && regs.h.al != 0x80 ) { char szHost[ 128 ]; if( regs.h.al == 0x01 || regs.h.al == 0xFF ) hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" ); else hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } /* Host OS detection: Windows NT family */ { regs.HB_XREGS.ax = 0x3306; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.HB_XREGS.bx == 0x3205 ) hb_strncat( pszPlatform, " (Windows NT)", PLATFORM_BUF_SIZE ); } /* Host OS detection: OS/2 */ { regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.h.al >= 10 ) { char szHost[ 128 ]; if( regs.h.al == 20 && regs.h.ah > 20 ) hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 ); else hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } } #elif defined( HB_OS_OS2 ) { unsigned long aulQSV[ QSV_MAX ] = { 0 }; APIRET rc; rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX ); if( rc == 0 ) { /* is this OS/2 2.x ? */ if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 ) { hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld", aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10, aulQSV[ QSV_VERSION_MINOR - 1 ] ); } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f", ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 ); } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" ); } #elif defined( HB_OS_WIN ) { OSVERSIONINFO osVer; osVer.dwOSVersionInfoSize = sizeof( osVer ); if( GetVersionEx( &osVer ) ) { /* NOTE: Unofficial Wine detection. http://www.mail-archive.com/[email protected]/msg48659.html */ HMODULE hntdll = GetModuleHandle( TEXT( "ntdll.dll" ) ); const char * pszWine = ""; const char * pszName = ""; if( hntdll && GetProcAddress( hntdll, "wine_get_version" ) ) pszWine = " (Wine)"; switch( osVer.dwPlatformId ) { case VER_PLATFORM_WIN32_WINDOWS: if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion < 10 ) pszName = " 95"; else if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion == 10 ) pszName = " 98"; else pszName = " ME"; break; case VER_PLATFORM_WIN32_NT: #ifndef VER_NT_WORKSTATION #define VER_NT_WORKSTATION 0x0000001 #endif if( osVer.dwMajorVersion == 6 ) { #if !defined( HB_OS_WIN_CE ) && !defined( __DMC__ ) && \ ( !defined( _MSC_VER ) || _MSC_VER >= 1400 ) OSVERSIONINFOEX osVerEx; osVerEx.dwOSVersionInfoSize = sizeof( osVerEx ); if( GetVersionEx( ( OSVERSIONINFO * ) &osVerEx ) ) { if( osVer.dwMinorVersion == 2 ) { if( osVerEx.wProductType == VER_NT_WORKSTATION ) pszName = " 8"; else pszName = " Server 2012"; } else if( osVer.dwMinorVersion == 1 ) { if( osVerEx.wProductType == VER_NT_WORKSTATION ) pszName = " 7"; else pszName = " Server 2008 R2"; } else if( osVer.dwMinorVersion == 0 ) { if( osVerEx.wProductType == VER_NT_WORKSTATION ) pszName = " Vista"; else pszName = " Server 2008"; } else pszName = ""; } else #endif pszName = ""; } else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion >= 2 ) { #if !defined( HB_OS_WIN_CE ) && !defined( __DMC__ ) && \ ( !defined( _MSC_VER ) || _MSC_VER >= 1400 ) OSVERSIONINFOEX osVerEx; osVerEx.dwOSVersionInfoSize = sizeof( osVerEx ); if( GetVersionEx( ( OSVERSIONINFO * ) &osVerEx ) ) { if( osVerEx.wProductType == VER_NT_WORKSTATION ) pszName = " XP x64"; else { #ifndef SM_SERVERR2 #define SM_SERVERR2 89 #endif if( GetSystemMetrics( SM_SERVERR2 ) != 0 ) pszName = " Server 2003 R2"; else pszName = " Server 2003"; } } else pszName = ""; #else pszName = " Server 2003 / XP x64"; #endif } else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion == 1 ) pszName = " XP"; else if( osVer.dwMajorVersion == 5 ) pszName = " 2000"; else pszName = " NT"; break; case VER_PLATFORM_WIN32s: pszName = " 32s"; break; case VER_PLATFORM_WIN32_CE: pszName = " CE"; break; } hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows%s%s %lu.%lu.%04u", pszName, pszWine, osVer.dwMajorVersion, osVer.dwMinorVersion, LOWORD( osVer.dwBuildNumber ) ); /* Add service pack/other info */ if( osVer.szCSDVersion ) { char * pszCSDVersion = HB_OSSTRDUP( osVer.szCSDVersion ); int i; /* Skip the leading spaces (Win95B, Win98) */ for( i = 0; pszCSDVersion[ i ] != '\0' && HB_ISSPACE( ( int ) pszCSDVersion[ i ] ); i++ ) ; if( pszCSDVersion[ i ] != '\0' ) { hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE ); hb_strncat( pszPlatform, pszCSDVersion + i, PLATFORM_BUF_SIZE ); } hb_xfree( pszCSDVersion ); } } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows" ); } #elif defined( __CEGCC__ ) { hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" ); } #elif defined( HB_OS_UNIX ) { struct utsname un; uname( &un ); #if defined( HB_OS_MINIX ) hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s Release %s Version %s %s", un.sysname, un.release, un.version, un.machine ); #else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine ); #endif } #else { hb_strncpy( pszPlatform, "(unknown)", PLATFORM_BUF_SIZE ); } #endif return pszPlatform; }
void hb_cmdargUpdate( void ) { HB_TRACE( HB_TR_DEBUG, ( "hb_cmdargUpdate()" ) ); #if ! defined( HB_OS_WIN ) if( s_argc > 0 ) { #if defined( HB_OS_OS2 ) { PPIB ppib = NULL; APIRET ulrc; ulrc = DosGetInfoBlocks( NULL, &ppib ); if( ulrc == NO_ERROR ) { ulrc = DosQueryModuleName( ppib->pib_hmte, HB_SIZEOFARRAY( s_szAppName ), s_szAppName ); if( ulrc == NO_ERROR ) 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 ] ); HB_BOOL fInPath = HB_FALSE; if( ! pFName->szPath ) { char * pszPATH = hb_getenv( "PATH" ); if( pszPATH && *pszPATH ) { HB_PATHNAMES * pSearchPath = NULL, * pNextPath; hb_fsAddSearchPath( pszPATH, &pSearchPath ); pNextPath = pSearchPath; while( pNextPath ) { 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 = HB_TRUE; break; } pNextPath = pNextPath->pNext; } hb_fsFreeSearchPath( pSearchPath ); if( ! fInPath ) pFName->szPath = NULL; } 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[ 0 ] == '.' && pFName->szPath[ 1 ] == HB_OS_PATH_DELIM_CHR ) pFName->szPath += 2; s_szAppName[ 0 ] = HB_OS_PATH_DELIM_CHR; hb_fsCurDirBuff( 0, 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; } hb_xfree( pFName ); } #endif } #endif }