static void s_hb_winVerInit( void ) { union REGS regs; /* TODO */ s_fWinVista = HB_FALSE; s_fWin2K3 = s_fWinVista; s_fWin2K = HB_FALSE; /* Host OS detection: Windows NT family */ { regs.HB_XREGS.ax = 0x3306; HB_DOS_INT86( 0x21, ®s, ®s ); s_fWinNT = ( regs.HB_XREGS.bx == 0x3205 ); } /* Host OS detection: 95/98 */ if( ! s_fWinNT ) { regs.HB_XREGS.ax = 0x1600; HB_DOS_INT86( 0x2F, ®s, ®s ); s_fWin9x = ( regs.h.al != 0x80 && regs.h.al != 0xFF && regs.h.al >= 4 ); } else s_fWin9x = HB_FALSE; s_fWinVerInit = HB_TRUE; }
static void hb_taskFreeze( HB_MAXINT wakeup ) { #if defined( HB_OS_DOS ) while( wakeup > hb_taskTimeStop( 0 ) ) { union REGS regs; regs.h.ah = 2; regs.HB_XREGS.ax = 0x1680; HB_DOS_INT86( 0x2F, ®s, ®s ); } #else wakeup -= hb_taskTimeStop( 0 ); if( wakeup > 0 ) { # if defined( __DJGPP__ ) usleep( wakeup * 1000 ); # elif defined( HB_OS_WIN ) Sleep( wakeup ); # elif defined( HB_OS_OS2 ) DosSleep( wakeup ); /* Duration is in milliseconds */ # elif defined( HB_OS_UNIX ) struct timeval tv; tv.tv_sec = wakeup / 1000; tv.tv_usec = ( wakeup % 1000 ) * 1000; select( 0, NULL, NULL, NULL, &tv ); # endif } #endif }
static int _ft_nwsemfunc( int nMode, HB_ULONG nHandle, HB_UINT nTimeOut ) { #if defined( HB_OS_DOS ) { union REGS regs; regs.h.ah = 0xC5; regs.h.al = ( HB_BYTE ) nMode; regs.HB_XREGS.cx = HB_LOWORD( ( HB_U32 ) nHandle ); regs.HB_XREGS.dx = HB_HIWORD( ( HB_U32 ) nHandle ); #if defined( __DJGPP__ ) regs.HB_XREGS.bp = ( HB_U16 ) nTimeOut; #else HB_SYMBOL_UNUSED( nTimeOut ); #endif HB_DOS_INT86( 0x21, ®s, ®s ); return ( HB_BYTE ) regs.h.al; } #else /* TODO */ HB_SYMBOL_UNUSED( nMode ); HB_SYMBOL_UNUSED( nHandle ); HB_SYMBOL_UNUSED( nTimeOut ); return 1; #endif }
static int kbhit( void ) { union REGS regs; regs.h.ah = 0x0B; HB_DOS_INT86( 0x21, ®s, ®s ); return regs.HB_XREGS.ax; }
static void hb_gt_dos_SetCursorSize( unsigned char start, unsigned char end ) { union REGS regs; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_dos_SetCursorSize(%d, %d)", ( int ) start, ( int ) end ) ); regs.h.ah = 0x01; regs.h.ch = start; regs.h.cl = end; HB_DOS_INT86( 0x10, ®s, ®s ); }
static void hb_gt_dos_GetCursorSize( unsigned char * start, unsigned char * end ) { union REGS regs; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_dos_GetCursorSize(%p, %p)", start, end ) ); regs.h.ah = 0x03; regs.h.bh = 0; HB_DOS_INT86( 0x10, ®s, ®s ); *start = regs.h.ch; *end = regs.h.cl; }
static void hb_gt_dos_GetCursorPosition( int * piRow, int * piCol ) { union REGS regs; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_dos_GetCursorPosition(%p, %p)", piRow, piCol ) ); regs.h.ah = 0x03; regs.h.bh = 0; HB_DOS_INT86( 0x10, ®s, ®s ); *piRow = regs.h.dh; *piCol = regs.h.dl; }
static void hb_gt_dos_mouse_Hide( PHB_GT pGT ) { HB_SYMBOL_UNUSED( pGT ); if( s_fMousePresent ) { union REGS regs; regs.HB_XREGS.ax = 2; HB_DOS_INT86( 0x33, ®s, ®s ); s_fMouseVisible = HB_FALSE; } }
static void hb_gt_dos_mouse_GetPos( PHB_GT pGT, int * piRow, int * piCol ) { HB_SYMBOL_UNUSED( pGT ); if( s_fMousePresent ) { union REGS regs; regs.HB_XREGS.ax = 3; HB_DOS_INT86( 0x33, ®s, ®s ); *piRow = regs.HB_XREGS.dx >> 3; *piCol = regs.HB_XREGS.cx >> 3; } else
static void hb_gt_dos_SetCursorPosition( int iRow, int iCol ) { union REGS regs; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_dos_SetCursorPosition(%d, %d)", iRow, iCol ) ); if( s_iCurRow != iRow || s_iCurCol != iCol ) { regs.h.ah = 0x02; regs.h.bh = 0; regs.h.dh = ( HB_BYTE ) iRow; regs.h.dl = ( HB_BYTE ) iCol; HB_DOS_INT86( 0x10, ®s, ®s ); s_iCurRow = iRow; s_iCurCol = iCol; } }
static void hb_gt_dos_mouse_Init( PHB_GT pGT ) { union REGS regs; regs.HB_XREGS.ax = 0; HB_DOS_INT86( 0x33, ®s, ®s ); s_fMousePresent = regs.HB_XREGS.ax; if( s_fMousePresent ) { s_iMouseButtons = regs.HB_XREGS.bx; if( s_iMouseButtons == 0 ) s_iMouseButtons = 3; if( s_iMouseButtons == 0xffff ) s_iMouseButtons = 2; s_iMouseInitCol = HB_GTSELF_MOUSECOL( pGT ); s_iMouseInitRow = HB_GTSELF_MOUSEROW( pGT ); } }
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; }
double hb_fsDiskSpace( const char * pszPath, HB_USHORT uiType ) { char szPathBuf[ 2 ]; double dSpace = 0.0; if( uiType > HB_DISK_TOTAL ) uiType = HB_DISK_AVAIL; if( ! pszPath ) { szPathBuf[ 0 ] = HB_OS_PATH_DELIM_CHR; szPathBuf[ 1 ] = '\0'; pszPath = szPathBuf; } #if defined( HB_OS_WIN ) { LPCTSTR lpPath; LPTSTR lpFree; lpPath = HB_FSNAMECONV( pszPath, &lpFree ); { UINT uiErrMode = SetErrorMode( SEM_FAILCRITICALERRORS ); HB_BOOL fResult; #if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 ) /* NOTE: We need to call this function dynamically to maintain support Win95 first edition. It was introduced in Win95B (aka OSR2) [vszakats] */ typedef BOOL ( WINAPI * P_GDFSE )( LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER ); static P_GDFSE s_pGetDiskFreeSpaceEx = NULL; static HB_BOOL s_fInit = HB_FALSE; if( ! s_fInit ) { HMODULE hModule = GetModuleHandle( HB_WINAPI_KERNEL32_DLL() ); if( hModule ) s_pGetDiskFreeSpaceEx = ( P_GDFSE ) HB_WINAPI_GETPROCADDRESST( hModule, "GetDiskFreeSpaceEx" ); s_fInit = HB_TRUE; } if( ! s_pGetDiskFreeSpaceEx ) { DWORD dwSectorsPerCluster; DWORD dwBytesPerSector; DWORD dwNumberOfFreeClusters; DWORD dwTotalNumberOfClusters; fResult = GetDiskFreeSpace( lpPath, &dwSectorsPerCluster, &dwBytesPerSector, &dwNumberOfFreeClusters, &dwTotalNumberOfClusters ) ? HB_TRUE : HB_FALSE; hb_fsSetIOError( fResult, 0 ); if( fResult ) { switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) dwTotalNumberOfClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; if( uiType == HB_DISK_USED ) dSpace -= ( double ) dwNumberOfFreeClusters * ( double ) dwSectorsPerCluster * ( double ) dwBytesPerSector; break; } } } else #endif { #if defined( _MSC_VER ) || defined( __LCC__ ) || \ ( defined( __GNUC__ ) && ! defined( __RSXNT__ ) ) # define HB_GET_LARGE_UINT( v ) ( ( double ) (v).LowPart + \ ( double ) (v).HighPart * \ ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) #else /* NOTE: Borland doesn't seem to deal with the un-named struct that is part of ULARGE_INTEGER [pt] */ # define HB_GET_LARGE_UINT( v ) ( ( double ) (v).u.LowPart + \ ( double ) (v).u.HighPart * \ ( ( ( double ) 0xFFFFFFFF ) + 1 ) ) #endif ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes; #if ! defined( HB_OS_WIN_CE ) && ! defined( HB_OS_WIN_64 ) fResult = s_pGetDiskFreeSpaceEx( lpPath, ( PULARGE_INTEGER ) &i64FreeBytesToCaller, ( PULARGE_INTEGER ) &i64TotalBytes, ( PULARGE_INTEGER ) &i64FreeBytes ); #else fResult = GetDiskFreeSpaceEx( lpPath, ( PULARGE_INTEGER ) &i64FreeBytesToCaller, ( PULARGE_INTEGER ) &i64TotalBytes, ( PULARGE_INTEGER ) &i64FreeBytes ); #endif hb_fsSetIOError( fResult, 0 ); if( fResult ) { switch( uiType ) { case HB_DISK_AVAIL: dSpace = HB_GET_LARGE_UINT( i64FreeBytesToCaller ); break; case HB_DISK_FREE: dSpace = HB_GET_LARGE_UINT( i64FreeBytes ); break; case HB_DISK_TOTAL: dSpace = HB_GET_LARGE_UINT( i64TotalBytes ); break; case HB_DISK_USED: dSpace = HB_GET_LARGE_UINT( i64TotalBytes ) - HB_GET_LARGE_UINT( i64FreeBytes ); break; } } } SetErrorMode( uiErrMode ); } if( lpFree ) hb_xfree( lpFree ); } #elif defined( HB_OS_DOS ) || defined( HB_OS_OS2 ) { HB_USHORT uiDrive; uiDrive = pszPath == NULL || pszPath[ 0 ] == 0 || pszPath[ 1 ] != HB_OS_DRIVE_DELIM_CHR ? 0 : ( pszPath[ 0 ] >= 'A' && pszPath[ 0 ] <= 'Z' ? pszPath[ 0 ] - 'A' + 1 : ( pszPath[ 0 ] >= 'a' && pszPath[ 0 ] <= 'z' ? pszPath[ 0 ] - 'a' + 1 : 0 ) ); #if defined( HB_OS_DOS ) for( ;; ) { union REGS regs; regs.HB_XREGS.dx = uiDrive; regs.h.ah = 0x36; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.HB_XREGS.ax != 0xFFFF ) { HB_USHORT uiClusterTotal = regs.HB_XREGS.dx; HB_USHORT uiClusterFree = regs.HB_XREGS.bx; HB_USHORT uiSecPerCluster = regs.HB_XREGS.ax; HB_USHORT uiSectorSize = regs.HB_XREGS.cx; switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) uiClusterFree * ( double ) uiSecPerCluster * ( double ) uiSectorSize; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) uiClusterTotal * ( double ) uiSecPerCluster * ( double ) uiSectorSize; if( uiType == HB_DISK_USED ) dSpace -= ( double ) uiClusterFree * ( double ) uiSecPerCluster * ( double ) uiSectorSize; break; } } else { if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) == E_RETRY ) continue; } break; } #else /* HB_OS_OS2 */ { struct _FSALLOCATE fsa; APIRET rc; /* Query level 1 info from filesystem */ while( ( rc = DosQueryFSInfo( uiDrive, 1, &fsa, sizeof( fsa ) ) ) != NO_ERROR ) { if( hb_errRT_BASE_Ext1( EG_OPEN, 2018, NULL, NULL, 0, ( EF_CANDEFAULT | EF_CANRETRY ), HB_ERR_ARGS_BASEPARAMS ) != E_RETRY ) break; } hb_fsSetError( ( HB_ERRCODE ) rc ); if( rc == NO_ERROR ) { switch( uiType ) { case HB_DISK_AVAIL: case HB_DISK_FREE: dSpace = ( double ) fsa.cUnitAvail * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; break; case HB_DISK_USED: case HB_DISK_TOTAL: dSpace = ( double ) fsa.cUnit * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; if( uiType == HB_DISK_USED ) dSpace -= ( double ) fsa.cUnitAvail * ( double ) fsa.cSectorUnit * ( double ) fsa.cbSector; break; } } } #endif } #elif defined( HB_OS_UNIX ) && \ !( defined( __WATCOMC__ ) || defined( __CEGCC__ ) || defined( HB_OS_SYMBIAN ) ) { #if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \ defined( HB_OS_VXWORKS ) struct statfs sf; #else struct statvfs sf; #endif char * pszFree; pszPath = hb_fsNameConv( pszPath, &pszFree ); #if defined( HB_OS_DARWIN ) || defined( HB_OS_ANDROID ) || \ defined( HB_OS_VXWORKS ) if( statfs( pszPath, &sf ) == 0 ) #else if( statvfs( pszPath, &sf ) == 0 ) #endif { switch( uiType ) { case HB_DISK_AVAIL: dSpace = ( double ) sf.f_bavail * ( double ) sf.f_bsize; break; case HB_DISK_FREE: dSpace = ( double ) sf.f_bfree * ( double ) sf.f_bsize; break; case HB_DISK_USED: dSpace = ( double ) ( sf.f_blocks - sf.f_bfree ) * ( double ) sf.f_bsize; break; case HB_DISK_TOTAL: dSpace = ( double ) sf.f_blocks * ( double ) sf.f_bsize; break; } hb_fsSetIOError( HB_TRUE, 0 ); } else hb_fsSetIOError( HB_FALSE, 0 ); if( pszFree ) hb_xfree( pszFree ); } #else { int iTODO; HB_SYMBOL_UNUSED( uiType ); } #endif return dSpace; }
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; }
HB_BOOL hb_printerIsReady( const char * pszPrinterName ) { HB_BOOL bIsPrinter; #if defined( HB_OS_DOS ) /* NOTE: MS-DOS specific solution, using BIOS interrupt */ { int iPort; if( pszPrinterName == NULL ) pszPrinterName = "LPT1"; if( hb_strnicmp( pszPrinterName, "PRN", 3 ) == 0 ) { union REGS regs; regs.h.ah = 2; regs.HB_XREGS.dx = 0; /* LPT1 */ HB_DOS_INT86( 0x17, ®s, ®s ); bIsPrinter = ( regs.h.ah == 0x90 ); } else if( strlen( pszPrinterName ) >= 4 && hb_strnicmp( pszPrinterName, "LPT", 3 ) == 0 && ( iPort = atoi( pszPrinterName + 3 ) ) > 0 ) { union REGS regs; regs.h.ah = 2; regs.HB_XREGS.dx = iPort - 1; HB_DOS_INT86( 0x17, ®s, ®s ); bIsPrinter = ( regs.h.ah == 0x90 ); } else bIsPrinter = HB_FALSE; } #else /* NOTE: Platform independent method, at least it will compile and run on any platform, but the result may not be the expected one, since Unix/Linux doesn't support LPT/COM by nature, other OSs may not reflect the actual physical presence of the printer when trying to open it, since we are talking to the spooler. [vszakats] */ { HB_FHANDLE fhnd; if( pszPrinterName == NULL ) #if defined( HB_OS_UNIX ) pszPrinterName = "/dev/lp0"; #else pszPrinterName = "LPT1"; #endif fhnd = hb_fsOpen( pszPrinterName, FO_WRITE | FO_SHARED | FO_PRIVATE ); bIsPrinter = ( fhnd != FS_ERROR ); hb_fsClose( fhnd ); } #endif return bIsPrinter; }
void hb_idle_releaseCPU( USHORT uiIdleSleepMsec, BOOL bIdleWaitNoCpu ) { #if defined( HB_THREAD_SUPPORT ) hb_threadSleep( uiIdleSleepMsec, bIdleWaitNoCpu ); #else #if defined( HB_OS_OS2 ) || defined( HB_OS_DOS ) || defined( HB_OS_DARWIN ) || defined( HB_OS_UNIX ) HB_SYMBOL_UNUSED( bIdleWaitNoCpu ); #endif #if defined( HB_OS_WIN ) || defined( __CYGWIN__ ) /* Forfeit the remainder of the current time slice. */ if( bIdleWaitNoCpu ) WaitMessage(); else Sleep( uiIdleSleepMsec ); #elif defined( HB_OS_OS2 ) /* 23/nov/2000 - [email protected] Minimum time slice under OS/2 is 32 milliseconds, passed 1 will be rounded to 32 and will give a chance to threads of lower priority to get executed. Passing 0 causes current thread to give up its time slice only if there are threads of equal priority waiting to be dispatched. Note: certain versions of OS/2 kernel have a bug which causes DosSleep(0) not to work as expected. */ DosSleep( uiIdleSleepMsec ); /* Duration is in milliseconds */ #elif defined( HB_OS_DOS ) /* NOTE: there is a bug under NT 4 and 2000 - if the app is running in protected mode, time slices will _not_ be released - you must switch to real mode first, execute the following, and switch back. It just occurred to me that this is actually by design. Since MS doesn't want you to do this from a console app, their solution was to not allow the call to work in protected mode - screw the rest of the planet <g>. returns zero on failure. (means not supported) */ { union REGS regs; regs.h.ah = 2; regs.HB_XREGS.ax = 0x1680; HB_DOS_INT86( 0x2F, ®s, ®s ); } #elif defined( HB_OS_DARWIN ) usleep( uiIdleSleepMsec ); #elif defined( HB_OS_UNIX ) { /* struct timeval tv; * tv.tv_sec = 0; * tv.tv_usec = 1000; * select( 0, NULL, NULL, NULL, &tv ); */ struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 20000; select( 0, NULL, NULL, NULL, &tv ); } #else /* Do nothing */ #endif #endif }
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; }