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 HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest ) { HB_BOOL bRetVal = HB_FALSE; PHB_FILE pSource; PHB_ITEM pError = NULL; HB_TRACE( HB_TR_DEBUG, ( "hb_copyfile(%s, %s)", pszSource, pszDest ) ); do { pSource = hb_fileExtOpen( pszSource, NULL, FO_READ | FO_SHARED | FO_PRIVATE | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( pSource == NULL ) { pError = hb_errRT_FileError( pError, NULL, EG_OPEN, 2012, pszSource ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( pSource == NULL ); if( pError ) { hb_itemRelease( pError ); pError = NULL; } if( pSource != NULL ) { PHB_FILE pDest; do { pDest = hb_fileExtOpen( pszDest, NULL, FO_READWRITE | FO_EXCLUSIVE | FO_PRIVATE | FXO_TRUNCATE | FXO_DEFAULTS | FXO_SHARELOCK, NULL, pError ); if( pDest == NULL ) { pError = hb_errRT_FileError( pError, NULL, EG_CREATE, 2012, pszDest ); if( hb_errLaunch( pError ) != E_RETRY ) break; } } while( pDest == NULL ); if( pError ) { hb_itemRelease( pError ); pError = NULL; } if( pDest != NULL ) { HB_UCHAR * buffer; HB_SIZE nRead; buffer = ( HB_UCHAR * ) hb_xgrab( BUFFER_SIZE ); bRetVal = HB_TRUE; while( ( nRead = hb_fileRead( pSource, buffer, BUFFER_SIZE, -1 ) ) != 0 ) { HB_SIZE nWritten = 0; while( nWritten < nRead ) { nWritten += hb_fileWrite( pDest, buffer + nWritten, nRead - nWritten, -1 ); if( nWritten < nRead ) { pError = hb_errRT_FileError( pError, NULL, EG_WRITE, 2016, pszDest ); if( hb_errLaunch( pError ) != E_RETRY ) { bRetVal = HB_FALSE; break; } } } } if( pError ) hb_itemRelease( pError ); hb_xfree( buffer ); hb_fileClose( pDest ); } hb_fileClose( pSource ); #if defined( HB_OS_UNIX ) if( bRetVal ) { HB_FATTR ulAttr; if( hb_fileAttrGet( pszSource, &ulAttr ) ) hb_fileAttrSet( pszDest, ulAttr ); } #endif } return bRetVal; }
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; }
PHB_DEBUGINFO hb_compGetDebugInfo( HB_COMP_DECL ) { PHB_DEBUGINFO pLineInfo = NULL, pInfo = NULL; HB_SIZE nPos, nSkip, nOffset; HB_ULONG ulLine; const char * pszModuleName = "", * ptr; PFUNCTION pFunc; pFunc = HB_COMP_PARAM->functions.pFirst; while( pFunc ) { if( ( pFunc->funFlags & FUN_FILE_DECL ) == 0 ) { nPos = ulLine = 0; while( nPos < pFunc->nPCodePos ) { nSkip = 0; switch( pFunc->pCode[ nPos ] ) { case HB_P_LINE: ulLine = HB_PCODE_MKUSHORT( &pFunc->pCode[ nPos + 1 ] ); break; case HB_P_MODULENAME: pszModuleName = ( const char * ) &pFunc->pCode[ nPos + 1 ]; pInfo = NULL; break; /* * This enables checking also code block bodies, * if it's not necessary then simply remove the * code below. [druzus] */ case HB_P_PUSHBLOCKLARGE: nSkip = 8 + HB_PCODE_MKUSHORT( &pFunc->pCode[ nPos + 6 ] ) * 2; break; case HB_P_PUSHBLOCK: nSkip = 7 + HB_PCODE_MKUSHORT( &pFunc->pCode[ nPos + 5 ] ) * 2; break; case HB_P_PUSHBLOCKSHORT: nSkip = 2; break; } if( ulLine != 0 ) { if( ! pInfo ) { int i; ptr = strchr( pszModuleName, ':' ); i = ptr ? ( int ) ( ptr - pszModuleName ) : ( int ) strlen( pszModuleName ); pInfo = pLineInfo; while( pInfo != NULL ) { if( strncmp( pszModuleName, pInfo->pszModuleName, i ) == 0 && ( pInfo->pszModuleName[ i ] == '\0' || pInfo->pszModuleName[ i ] == ':' ) ) break; pInfo = pInfo->pNext; } if( ! pInfo ) { pInfo = ( PHB_DEBUGINFO ) hb_xgrab( sizeof( HB_DEBUGINFO ) ); pInfo->pszModuleName = hb_strndup( pszModuleName, i ); pInfo->ulFirstLine = pInfo->ulLastLine = ulLine; /* * allocate memory in 256 bytes chunks (for 2048 lines) * The last 1 byte is reserved for additional 0 byte if * the caller will want to use the returned buffer as * parameter to hb_compGenPushString(). [druzus] */ pInfo->ulAllocated = ( ( ulLine >> 3 ) + 0x100 ) & 0xFFFFFF00L; pInfo->pLineMap = ( HB_BYTE * ) hb_xgrab( pInfo->ulAllocated + 1 ); memset( pInfo->pLineMap, 0, pInfo->ulAllocated + 1 ); pInfo->pNext = pLineInfo; pLineInfo = pInfo; } } nOffset = ulLine >> 3; if( pInfo->ulAllocated <= nOffset ) { HB_ULONG ulNewSize = ( ( ulLine >> 3 ) + 0x100 ) & 0xFFFFFF00L; pInfo->pLineMap = ( HB_BYTE * ) hb_xrealloc( pInfo->pLineMap, ulNewSize + 1 ); memset( pInfo->pLineMap + pInfo->ulAllocated, 0, ulNewSize - pInfo->ulAllocated + 1 ); pInfo->ulAllocated = ulNewSize; } pInfo->pLineMap[ nOffset ] |= 1 << ( ulLine & 0x7 ); /* * It's possible the the line number will be ascending * if some external file is included more then once. [druzus] */ if( pInfo->ulFirstLine > ulLine ) pInfo->ulFirstLine = ulLine; if( pInfo->ulLastLine < ulLine ) pInfo->ulLastLine = ulLine; ulLine = 0; }
/* internal routine to do buffer skips. Passing a positive value performs a downward skip, a negative number does an upward skip. Passing 0 skips to the end of file. Returns a long indicating the number of records skipped */ static long _ft_skip( long iRecs ) { PFT_TEXT ft_text = ( PFT_TEXT ) hb_stackGetTSD( &s_ft_text ); HB_ISIZ iByteCount; HB_ISIZ iBytesRead, iBytesRemaining; char * cPtr; long iSkipped = 0; char * cBuff = ( char * ) hb_xgrab( BUFFSIZE ); HB_FOFFSET fpOffset = ft_text->offset[ ft_text->area ]; ft_text->isBof[ ft_text->area ] = HB_FALSE; ft_text->isEof[ ft_text->area ] = HB_FALSE; ft_text->error[ ft_text->area ] = 0; /* iRecs is zero if they want to find the EOF, start a top of file */ if( iRecs == 0 ) { fpOffset = 0; ft_text->recno[ ft_text->area ] = 1; } if( iRecs >= 0 ) { do { cPtr = cBuff; /* read a chunk */ if( ( iBytesRead = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE, fpOffset ) ) ) == 0 ) { /* buffer is empty thus EOF, set vars and quit */ ft_text->isEof[ ft_text->area ] = HB_TRUE; ft_text->last_rec[ ft_text->area ] = ft_text->recno[ ft_text->area ]; ft_text->last_off[ ft_text->area ] = ft_text->offset[ ft_text->area ]; ft_text->error[ ft_text->area ] = hb_fsError(); break; } iBytesRemaining = iBytesRead; /* parse the buffer while there's still stuff in it */ do { /* get count of chars in this line */ iByteCount = _findeol( cPtr, iBytesRemaining, NULL ); if( iByteCount > 0 && iByteCount != iBytesRemaining ) { /* found an EOL, iByteCount points to first char of next record */ iBytesRemaining -= iByteCount; fpOffset += iByteCount; cPtr += iByteCount; ft_text->offset[ ft_text->area ] = fpOffset; ft_text->recno[ ft_text->area ]++; iSkipped++; if( iRecs && ( iSkipped == iRecs ) ) iBytesRemaining = iBytesRead = 0; } else { /* no more EOLs in this buffer, or EOL is last chars in the buffer */ /* check for EOF */ if( iBytesRead != BUFFSIZE ) { /* buffer was not full, thus EOF, set vars and quit */ iBytesRemaining = 0; ft_text->last_rec[ ft_text->area ] = ft_text->recno[ ft_text->area ]; ft_text->last_off[ ft_text->area ] = ft_text->offset[ ft_text->area ]; if( iRecs ) ft_text->isEof[ ft_text->area ] = HB_TRUE; } else { /* buffer was full, so probably not EOF, but maybe EOL straddled end of buffer, so back up pointer a bit before doing the next read */ fpOffset = hb_fileSeek( ft_text->handles[ ft_text->area ], 0, FS_RELATIVE ) - 1; iBytesRemaining = 0; } } } while( iBytesRemaining > 0 ); } while( iBytesRead == BUFFSIZE ); } else { /* skip backwards */ iRecs = -iRecs; if( ft_text->recno[ ft_text->area ] > iRecs ) { do { /* calc offset to read area of file ahead of current pointer */ fpOffset = HB_MAX( ft_text->offset[ ft_text->area ] - BUFFSIZE, 0 ); /* read a chunk */ if( ( iBytesRead = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], cBuff, BUFFSIZE, fpOffset ) ) ) == 0 ) { /* buffer is empty thus file is zero len, set vars and quit */ ft_text->isBof[ ft_text->area ] = HB_TRUE; ft_text->isEof[ ft_text->area ] = HB_TRUE; ft_text->recno[ ft_text->area ] = 0; ft_text->offset[ ft_text->area ] = 0; ft_text->last_rec[ ft_text->area ] = 0; ft_text->error[ ft_text->area ] = hb_fsError(); break; } /* set pointer within buffer */ iBytesRemaining = ( int ) ( ft_text->offset[ ft_text->area ] - fpOffset ); cPtr = cBuff + iBytesRemaining; /* parse the buffer while there's still stuff in it */ do { /* get count of chars in this line */ iByteCount = _findbol( cPtr, iBytesRemaining ); if( iByteCount > 0 ) { /* found an EOL, iByteCount points to first char of next record */ iBytesRemaining -= iByteCount; ft_text->offset[ ft_text->area ] -= iByteCount; cPtr -= iByteCount; fpOffset = ft_text->offset[ ft_text->area ]; ft_text->recno[ ft_text->area ]--; iSkipped++; if( iSkipped == iRecs ) iBytesRemaining = iBytesRead = 0; } else { /* no more EOLs in this buffer so we're either at BOF or record crosses buffer boundary */ /* check for BOF */ if( iBytesRead != BUFFSIZE ) { /* buffer was not full, thus BOF, set vars and quit */ iBytesRemaining = 0; ft_text->offset[ ft_text->area ] = 0; ft_text->recno[ ft_text->area ] = 1; ft_text->isBof[ ft_text->area ] = HB_TRUE; } else { /* buffer was full, so not BOF */ iBytesRemaining = 0; } } } while( iBytesRemaining > 0 ); } while( fpOffset > 0 && iBytesRead == BUFFSIZE ); } else { ft_text->offset[ ft_text->area ] = 0; ft_text->recno[ ft_text->area ] = 1; ft_text->isBof[ ft_text->area ] = HB_TRUE; } } hb_xfree( cBuff ); return iSkipped; }
void hb_compCodeTraceMarkDead( HB_COMP_DECL, PHB_HFUNC pFunc ) { const PHB_CODETRACE_FUNC * pFuncTable = s_codeTraceFuncTable; HB_CODETRACE_INFO code_info; if( ! HB_COMP_ISSUPPORTED( HB_COMPFLAG_OPTJUMP ) || pFunc->nPCodePos < 2 ) return; assert( HB_P_LAST_PCODE == sizeof( s_codeTraceFuncTable ) / sizeof( PHB_CODETRACE_FUNC ) ); code_info.pnJumps = NULL; code_info.nJumpPos = 0; code_info.nJumpSize = 0; code_info.nJumpCount = 0; code_info.nPCodeSize = pFunc->nPCodePos; code_info.fFinished = HB_FALSE; code_info.pCodeMark = ( HB_BYTE * ) hb_xgrab( code_info.nPCodeSize ); memset( code_info.pCodeMark, 0, code_info.nPCodeSize ); hb_compPCodeTrace( pFunc, ( const PHB_PCODE_FUNC * ) pFuncTable, ( void * ) &code_info ); if( code_info.fFinished ) { HB_SIZE nPos = 0, nCount = 0; HB_BYTE bLastCode = HB_P_LAST_PCODE; do { if( code_info.pCodeMark[ nPos ] == 0 ) ++nCount; else { bLastCode = pFunc->pCode[ nPos ]; if( nCount ) { hb_compNOOPfill( pFunc, nPos - nCount, nCount, HB_FALSE, HB_TRUE ); nCount = 0; } } } while( ++nPos < code_info.nPCodeSize ); /* do not strip the last HB_P_ENDBLOCK / HB_P_ENDPROC marker */ if( nCount > 0 && bLastCode != ( pFunc->szName ? HB_P_ENDPROC : HB_P_ENDBLOCK ) ) { --nPos; --nCount; } if( nCount > 0 ) { /* * We cannot simply decrease size of the generated PCODE here * because jumps or noops tables may point to the this area * and we will have to update also the jump table, [druzus] */ /* pFunc->pCode[ nPos - nCount ] = pFunc->pCode[ nPos - 1 ]; pFunc->nPCodePos = pFunc->nPCodeSize = nPos - nCount + 1; */ hb_compNOOPfill( pFunc, nPos - nCount, nCount, HB_FALSE, HB_TRUE ); } } hb_xfree( code_info.pCodeMark ); if( code_info.pnJumps ) hb_xfree( code_info.pnJumps ); }
/* Creates the codeblock structure * * pBuffer -> the buffer with pcodes (without HB_P_PUSHBLOCK) * wLocals -> number of local variables referenced in a codeblock * pLocalPosTable -> a table with positions on eval stack for referenced variables * pSymbols -> a pointer to the module symbol table * * Note: pLocalPosTable cannot be used if uiLocals is ZERO */ PHB_CODEBLOCK hb_codeblockNew( const HB_BYTE * pBuffer, HB_USHORT uiLocals, const HB_BYTE * pLocalPosTable, PHB_SYMB pSymbols, HB_SIZE nLen ) { HB_STACK_TLS_PRELOAD PHB_CODEBLOCK pCBlock; PHB_ITEM pLocals, pBase; const HB_BYTE * pCode; HB_TRACE( HB_TR_DEBUG, ( "hb_codeblockNew(%p, %hu, %p, %p, %" HB_PFS "u)", pBuffer, uiLocals, pLocalPosTable, pSymbols, nLen ) ); /* Allocate memory for code block body and detach items hb_gcAllocRaw() * to be safe for automatic GC activation in hb_xgrab() without * calling hb_gcLock()/hb_gcUnlock(). [druzus] */ if( nLen ) { /* The codeblock pcode is stored in dynamically allocated memory that * can be deallocated after creation of a codeblock. We have to duplicate * the passed buffer */ pCode = ( const HB_BYTE * ) memcpy( hb_xgrab( nLen ), pBuffer, nLen ); } else { /* The codeblock pcode is stored in static segment. * The only allowed operation on a codeblock is evaluating it then * there is no need to duplicate its pcode - just store the pointer to it */ pCode = pBuffer; } if( uiLocals ) { /* NOTE: if a codeblock will be created by macro compiler then * uiLocal have to be ZERO * uiLocal will be also ZERO if it is a nested codeblock */ HB_USHORT ui = 1; PHB_ITEM pLocal; /* Create a table that will store the values of local variables * accessed in a codeblock * The element 0 is unused * NOTE: This table can be shared by codeblocks created during * evaluation of this codeblock */ pLocals = ( PHB_ITEM ) hb_xgrab( ( uiLocals + 1 ) * sizeof( HB_ITEM ) ); pLocals[ 0 ].type = HB_IT_NIL; do { /* Swap the current value of local variable with the reference to this * value. */ int iLocal = HB_PCODE_MKUSHORT( pLocalPosTable ); pLocal = hb_stackLocalVariable( iLocal ); pLocalPosTable += 2; pLocal = hb_memvarDetachLocal( pLocal ); hb_itemRawCpy( pLocals + ui, pLocal ); /* Increment the reference counter so this value will not be * released if other codeblock will be deleted */ hb_memvarValueIncRef( pLocal->item.asMemvar.value ); } while( ++ui <= uiLocals ); } else { /* Check if this codeblock is created during evaluation of another * codeblock - all inner codeblocks use the local variables table * created during creation of the outermost codeblock */ PHB_ITEM pLocal; pLocal = hb_stackSelfItem(); if( HB_IS_BLOCK( pLocal ) ) { PHB_CODEBLOCK pOwner = pLocal->item.asBlock.value; uiLocals = pOwner->uiLocals; pLocals = pOwner->pLocals; if( pLocals ) hb_xRefInc( pLocals ); } else pLocals = NULL; } pBase = hb_stackBaseItem(); pCBlock = ( PHB_CODEBLOCK ) hb_gcAllocRaw( sizeof( HB_CODEBLOCK ), &s_gcCodeblockFuncs ); pCBlock->pCode = pCode; pCBlock->dynBuffer = nLen != 0; pCBlock->pDefSymb = pBase->item.asSymbol.stackstate->uiClass ? hb_clsMethodSym( pBase ) : pBase->item.asSymbol.value; pCBlock->pSymbols = pSymbols; pCBlock->pStatics = hb_stackGetStaticsBase(); pCBlock->uiLocals = uiLocals; pCBlock->pLocals = pLocals; HB_TRACE( HB_TR_INFO, ( "codeblock created %p", pCBlock ) ); return pCBlock; }
/* * This function pushes passed dynamic symbol that belongs to PRIVATE variable * into the stack. The value will be popped from it if the variable falls * outside the scope (either by using RELEASE, CLEAR ALL, CLEAR MEMORY or by * an exit from the function/procedure) * */ static void hb_memvarAddPrivate( PHB_DYNS pDynSym, PHB_ITEM pValue ) { HB_STACK_TLS_PRELOAD PHB_PRIVATE_STACK pPrivateStack; PHB_ITEM pMemvar; HB_TRACE( HB_TR_DEBUG, ( "hb_memvarAddPrivate(%p,%p)", pDynSym, pValue ) ); pPrivateStack = hb_stackGetPrivateStack(); pMemvar = hb_dynsymGetMemvar( pDynSym ); /* If the variable with the same name exists already * and it's PRIVATE variable declared in this function then * do not push new memvar on PRIVATEs stack */ if( pMemvar ) { HB_SIZE nCount = pPrivateStack->count; while( nCount > pPrivateStack->base ) { if( pDynSym == pPrivateStack->stack[ nCount - 1 ].pDynSym ) break; --nCount; } if( nCount <= pPrivateStack->base ) pMemvar = NULL; } if( ! pMemvar ) { /* Allocate the value from the end of table */ if( pPrivateStack->count == pPrivateStack->size ) { /* No more free values in the table - expand the table */ if( pPrivateStack->size == 0 ) { pPrivateStack->stack = ( PHB_PRIVATE_ITEM ) hb_xgrab( sizeof( HB_PRIVATE_ITEM ) * TABLE_INITHB_VALUE ); pPrivateStack->size = TABLE_INITHB_VALUE; pPrivateStack->count = pPrivateStack->base = 0; } else { pPrivateStack->size += TABLE_EXPANDHB_VALUE; pPrivateStack->stack = ( PHB_PRIVATE_ITEM ) hb_xrealloc( pPrivateStack->stack, sizeof( HB_PRIVATE_ITEM ) * pPrivateStack->size ); } } pPrivateStack->stack[ pPrivateStack->count ].pDynSym = pDynSym; pPrivateStack->stack[ pPrivateStack->count++ ].pPrevMemvar = hb_dynsymGetMemvar( pDynSym ); if( pValue && HB_IS_MEMVAR( pValue ) ) { pMemvar = pValue->item.asMemvar.value; hb_xRefInc( pMemvar ); pValue = NULL; } else pMemvar = hb_memvarValueNew(); hb_dynsymSetMemvar( pDynSym, pMemvar ); } if( pValue ) { hb_itemCopy( pMemvar, pValue ); /* Remove MEMOFLAG if exists (assignment from field). */ pMemvar->type &= ~HB_IT_MEMOFLAG; } }
int main( int argc, char * argv[] ) { char * szFile = NULL, * szRuleFile = NULL, * szWordFile = NULL, * szVerFile = NULL; char * szLogFile = NULL; BOOL fQuiet = FALSE, fWrite = FALSE, fChgLog = FALSE; char * szChangeLogID = NULL, * szLastEntry = NULL; int iResult = 0, i; PHB_PP_STATE pState; pState = hb_pp_new(); if( argc >= 2 ) { szFile = argv[ 1 ]; for( i = 2; szFile && i < argc; i++ ) { if( ! HB_ISOPTSEP( argv[ i ][ 0 ] ) ) szFile = NULL; else { switch( argv[ i ][ 1 ] ) { case 'q': case 'Q': if( argv[ i ][ 2 ] ) szFile = NULL; else fQuiet = TRUE; break; case 'w': case 'W': if( argv[ i ][ 2 ] ) szFile = NULL; else fWrite = TRUE; break; case 'c': case 'C': fChgLog = TRUE; if( argv[ i ][ 2 ] ) szLogFile = argv[ i ] + 2; break; case 'i': case 'I': if( argv[ i ][ 2 ] ) hb_pp_addSearchPath( pState, argv[ i ] + 2, FALSE ); else szFile = NULL; break; case 'o': case 'O': if( argv[ i ][ 2 ] ) szRuleFile = argv[ i ] + 2; else szFile = NULL; break; case 'x': case 'X': if( argv[ i ][ 2 ] ) szWordFile = argv[ i ] + 2; else szWordFile = NULL; break; case 'v': case 'V': if( argv[ i ][ 2 ] ) szVerFile = argv[ i ] + 2; else szFile = NULL; break; default: szFile = NULL; break; } } } } if( szFile ) { hb_pp_init( pState, fQuiet, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); if( hb_pp_inFile( pState, szFile, TRUE, NULL, TRUE ) ) { char * szSVNID = ( char * ) hb_xgrab( 10 ); char * szSVNDateID = ( char * ) hb_xgrab( 10 ); if( fWrite ) { char szFileName[ HB_PATH_MAX ]; PHB_FNAME pFileName; pFileName = hb_fsFNameSplit( szFile ); pFileName->szExtension = ".ppo"; hb_fsFNameMerge( szFileName, pFileName ); hb_xfree( pFileName ); hb_pp_outFile( pState, szFileName, NULL ); } if( fChgLog ) iResult = hb_pp_parseChangelog( pState, szLogFile, fQuiet, szSVNID, szSVNDateID, &szChangeLogID, &szLastEntry ); if( iResult == 0 ) iResult = hb_pp_preprocesfile( pState, szRuleFile, szWordFile ); if( iResult == 0 && szVerFile ) iResult = hb_pp_generateVerInfo( szVerFile, szSVNID, szSVNDateID, szChangeLogID, szLastEntry ); hb_xfree( szSVNID ); hb_xfree( szSVNDateID ); } else iResult = 1; } else { hb_pp_usage( argv[ 0 ] ); iResult = 1; } if( szChangeLogID ) hb_xfree( szChangeLogID ); if( szLastEntry ) hb_xfree( szLastEntry ); hb_pp_free( pState ); return iResult; }
static void s_inetRecvPattern( const char * const * patterns, int * patternsizes, int iPatternsCount, int iParam ) { PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 1 ); PHB_ITEM pResult = hb_param( iParam, HB_IT_BYREF ); PHB_ITEM pMaxSize = hb_param( iParam + 1, HB_IT_NUMERIC ); PHB_ITEM pBufferSize = hb_param( iParam + 2, HB_IT_NUMERIC ); char cChar = '\0'; char * buffer; int iPaternFound = 0; int iTimeElapsed = 0; int iPos = 0; int iLen; int iAllocated, iBufferSize, iMax; int i; if( socket == NULL ) { hb_inetErrRT(); return; } else if( ! hb_inetIsOpen( socket ) ) { if( pResult ) hb_itemPutNI( pResult, -1 ); hb_retc_null(); return; } iBufferSize = pBufferSize ? hb_itemGetNI( pBufferSize ) : 80; iMax = pMaxSize ? hb_itemGetNI( pMaxSize ) : 0; socket->iError = HB_INET_ERR_OK; buffer = ( char * ) hb_xgrab( iBufferSize ); iAllocated = iBufferSize; do { if( iPos == iAllocated - 1 ) { iAllocated += iBufferSize; buffer = ( char * ) hb_xrealloc( buffer, iAllocated ); } iLen = s_inetRecv( socket, &cChar, 1, HB_TRUE, socket->iTimeout ); if( iLen == -1 && s_inetIsTimeout( socket ) ) { iLen = -2; /* this signals timeout */ if( socket->pPeriodicBlock ) { HB_BOOL fResult; iTimeElapsed += socket->iTimeout; hb_execFromArray( socket->pPeriodicBlock ); fResult = hb_parl( -1 ) && hb_vmRequestQuery() == 0; if( fResult && ( socket->iTimeLimit == -1 || iTimeElapsed < socket->iTimeLimit ) ) iLen = 1; } } else if( iLen > 0 ) { buffer[ iPos++ ] = cChar; for( i = 0; i < iPatternsCount; ++i ) { if( patternsizes[ i ] <= iPos && cChar == patterns[ i ][ patternsizes[ i ] - 1 ] ) { if( memcmp( buffer + iPos - patternsizes[ i ], patterns[ i ], patternsizes[ i ] ) == 0 ) { iPaternFound = i + 1; break; } } } } } while( iLen > 0 && iPaternFound == 0 && ( iMax == 0 || iPos < iMax ) ); if( iPaternFound ) { socket->iCount = iPos; if( pResult ) hb_itemPutNI( pResult, iPos ); hb_retclen_buffer( buffer, iPos - patternsizes[ iPaternFound - 1 ] ); } else { if( iLen == 0 ) socket->iError = HB_INET_ERR_CLOSEDCONN; else if( iLen < 0 ) hb_inetGetError( socket ); else { socket->iError = HB_INET_ERR_BUFFOVERRUN; iLen = -1; } if( pResult ) hb_itemPutNI( pResult, iLen ); hb_xfree( buffer ); hb_retc_null(); } }
/* helper function for the justxxx() functions */ static void do_justify (int iSwitch) { int iNoRet; iNoRet = ct_getref() && ISBYREF( 1 ); if (ISCHAR (1)) { char *pcString = hb_parc (1); size_t sStrLen = hb_parclen (1); char cJustChar; char *pc, *pcRet; size_t sJustOffset; if ( sStrLen == 0 ) { if (iNoRet) { hb_ret(); } else { hb_retc( "" ); } return; } if (hb_parclen (2) > 0) cJustChar = *(hb_parc (2)); else if (ISNUM (2)) cJustChar = (char)( hb_parnl (2) % 256 ); else cJustChar = 0x20; pcRet = ( char *)hb_xgrab (sStrLen); switch (iSwitch) { case DO_JUSTIFY_JUSTLEFT: { pc = pcString; sJustOffset = 0; while ((*pc == cJustChar) && (pc < pcString+sStrLen)) { sJustOffset++; pc++; } hb_xmemcpy (pcRet, pcString+sJustOffset, sStrLen-sJustOffset); for (pc = pcRet+sStrLen-sJustOffset; pc < pcRet+sStrLen; pc++) { *pc = cJustChar; } }; break; case DO_JUSTIFY_JUSTRIGHT: { pc = pcString+sStrLen-1; sJustOffset = 0; while ((*pc == cJustChar) && (pc >= pcString)) { sJustOffset++; pc--; } for (pc = pcRet; pc < pcRet+sJustOffset; pc++) { *pc = cJustChar; } hb_xmemcpy (pcRet+sJustOffset, pcString, sStrLen-sJustOffset); }; break; } if (ISBYREF (1)) hb_storclen (pcRet, sStrLen, 1); if (iNoRet) hb_ret(); else hb_retclen (pcRet, sStrLen); hb_xfree (pcRet); } else /* ISCHAR (1) */ { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if (iArgErrorMode != CT_ARGERR_IGNORE) { pSubst = ct_error_subst ((USHORT)iArgErrorMode, EG_ARG, (iSwitch == DO_JUSTIFY_JUSTLEFT ? CT_ERROR_JUSTLEFT : CT_ERROR_JUSTRIGHT), NULL, (iSwitch == DO_JUSTIFY_JUSTLEFT ? "JUSTLEFT" : "JUSTRIGHT"), 0, EF_CANSUBSTITUTE, 2, hb_paramError (1), hb_paramError (2)); } if (pSubst != NULL) { hb_itemRelease( hb_itemReturnForward( pSubst ) ); } else { if (iNoRet) hb_ret(); else hb_retc (""); } } return; }
PHB_ITEM hb_libLoad( PHB_ITEM pLibName, PHB_ITEM pArgs ) { void * hDynLib = NULL; if( hb_itemGetCLen( pLibName ) > 0 ) { int argc = pArgs ? ( int ) hb_arrayLen( pArgs ) : 0, i; const char ** argv = NULL; if( argc > 0 ) { argv = ( const char ** ) hb_xgrab( sizeof( char * ) * argc ); for( i = 0; i < argc; ++i ) argv[ i ] = hb_arrayGetCPtr( pArgs, i + 1 ); } if( hb_vmLockModuleSymbols() ) { /* use stack address as first level marker */ hb_vmBeginSymbolGroup( ( void * ) hb_stackId(), HB_TRUE ); #if defined( HB_OS_WIN ) { void * hFileName; hDynLib = ( void * ) LoadLibraryEx( HB_ITEMGETSTR( pLibName, &hFileName, NULL ), NULL, LOAD_WITH_ALTERED_SEARCH_PATH ); hb_strfree( hFileName ); } #elif defined( HB_OS_OS2 ) { HB_UCHAR LoadError[ 256 ] = ""; /* Area for load failure information */ HMODULE hDynModule; if( DosLoadModule( ( PSZ ) LoadError, sizeof( LoadError ), ( PCSZ ) hb_itemGetCPtr( pLibName ), &hDynModule ) == NO_ERROR ) hDynLib = ( void * ) hDynModule; } #elif defined( HB_HAS_DLFCN ) hDynLib = ( void * ) dlopen( hb_itemGetCPtr( pLibName ), RTLD_LAZY | RTLD_GLOBAL ); if( ! hDynLib ) { HB_TRACE( HB_TR_DEBUG, ( "hb_libLoad(): dlopen(): %s", dlerror() ) ); } #elif defined( HB_CAUSEWAY_DLL ) hDynLib = LoadLibrary( hb_itemGetCPtr( pLibName ) ); #else { int iTODO; } #endif /* set real marker */ hb_vmInitSymbolGroup( hDynLib, argc, argv ); hb_vmUnlockModuleSymbols(); } if( argv ) hb_xfree( ( void * ) argv ); } if( hDynLib ) { void ** pLibPtr = ( void ** ) hb_gcAllocate( sizeof( void * ), &s_gcDynlibFuncs ); *pLibPtr = hDynLib; return hb_itemPutPtrGC( NULL, pLibPtr ); } return NULL; }
static PHRB_BODY hb_hrbLoad( const char * szHrbBody, HB_SIZE nBodySize, HB_USHORT usMode, const char * szFileName ) { PHRB_BODY pHrbBody = NULL; if( szHrbBody ) { HB_SIZE nBodyOffset = 0; HB_SIZE nSize; /* Size of function */ HB_SIZE nPos; HB_ULONG ul; char * buffer, ch; HB_USHORT usBind = ( usMode & HB_HRB_BIND_MODEMASK ); PHB_SYMB pSymRead; /* Symbols read */ PHB_DYNF pDynFunc; /* Functions read */ PHB_DYNS pDynSym; int iVersion = hb_hrbReadHead( szHrbBody, nBodySize, &nBodyOffset ); if( iVersion == 0 ) { hb_errRT_BASE( EG_CORRUPTION, 9995, NULL, HB_ERR_FUNCNAME, 0 ); return NULL; } pHrbBody = ( PHRB_BODY ) hb_xgrab( sizeof( HRB_BODY ) ); pHrbBody->fInit = HB_FALSE; pHrbBody->fExit = HB_FALSE; pHrbBody->lSymStart = -1; pHrbBody->ulFuncs = 0; pHrbBody->pSymRead = NULL; pHrbBody->pDynFunc = NULL; pHrbBody->pModuleSymbols = NULL; if( ! hb_hrbReadValue( szHrbBody, nBodySize, &nBodyOffset, &pHrbBody->ulSymbols ) || pHrbBody->ulSymbols == 0 ) { hb_hrbUnLoad( pHrbBody ); hb_errRT_BASE( EG_CORRUPTION, 9996, NULL, HB_ERR_FUNCNAME, 0 ); return NULL; } /* calculate the size of dynamic symbol table */ nPos = nBodyOffset; nSize = 0; for( ul = 0; ul < pHrbBody->ulSymbols; ul++ ) /* Read symbols in .hrb */ { while( nBodyOffset < nBodySize ) { ++nSize; if( szHrbBody[ nBodyOffset++ ] == 0 ) break; } nBodyOffset += 2; if( nBodyOffset >= nBodySize ) { hb_hrbUnLoad( pHrbBody ); hb_errRT_BASE( EG_CORRUPTION, 9997, NULL, HB_ERR_FUNCNAME, 0 ); return NULL; } } nBodyOffset = nPos; ul = pHrbBody->ulSymbols * sizeof( HB_SYMB ); pSymRead = ( PHB_SYMB ) hb_xgrab( nSize + ul ); buffer = ( ( char * ) pSymRead ) + ul; for( ul = 0; ul < pHrbBody->ulSymbols; ul++ ) /* Read symbols in .hrb */ { pSymRead[ ul ].szName = buffer; do { ch = *buffer++ = szHrbBody[ nBodyOffset++ ]; } while( ch ); pSymRead[ ul ].scope.value = ( HB_BYTE ) szHrbBody[ nBodyOffset++ ]; pSymRead[ ul ].value.pCodeFunc = ( PHB_PCODEFUNC ) ( HB_PTRDIFF ) szHrbBody[ nBodyOffset++ ]; pSymRead[ ul ].pDynSym = NULL; if( pHrbBody->lSymStart == -1 && ( pSymRead[ ul ].scope.value & HB_FS_FIRST ) != 0 && ( pSymRead[ ul ].scope.value & HB_FS_INITEXIT ) == 0 ) { pHrbBody->lSymStart = ul; } } /* Read number of functions */ if( ! hb_hrbReadValue( szHrbBody, nBodySize, &nBodyOffset, &pHrbBody->ulFuncs ) ) { hb_xfree( pSymRead ); hb_hrbUnLoad( pHrbBody ); hb_errRT_BASE( EG_CORRUPTION, 9997, NULL, HB_ERR_FUNCNAME, 0 ); return NULL; } pHrbBody->pSymRead = pSymRead; if( pHrbBody->ulFuncs ) { pDynFunc = ( PHB_DYNF ) hb_xgrab( pHrbBody->ulFuncs * sizeof( HB_DYNF ) ); memset( pDynFunc, 0, pHrbBody->ulFuncs * sizeof( HB_DYNF ) ); pHrbBody->pDynFunc = pDynFunc; for( ul = 0; ul < pHrbBody->ulFuncs; ul++ ) { HB_ULONG ulValue; /* Read name of function */ pDynFunc[ ul ].szName = hb_hrbReadId( szHrbBody, nBodySize, &nBodyOffset ); if( pDynFunc[ ul ].szName == NULL ) break; /* Read size of function */ if( ! hb_hrbReadValue( szHrbBody, nBodySize, &nBodyOffset, &ulValue ) ) break; nSize = ( HB_SIZE ) ulValue; if( nBodyOffset + nSize > nBodySize ) break; /* Copy function body */ pDynFunc[ ul ].pCode = ( HB_BYTE * ) hb_xgrab( nSize ); memcpy( ( char * ) pDynFunc[ ul ].pCode, szHrbBody + nBodyOffset, nSize ); nBodyOffset += nSize; pDynFunc[ ul ].pCodeFunc = ( PHB_PCODEFUNC ) hb_xgrab( sizeof( HB_PCODEFUNC ) ); pDynFunc[ ul ].pCodeFunc->pCode = pDynFunc[ ul ].pCode; pDynFunc[ ul ].pCodeFunc->pSymbols = pSymRead; } if( ul < pHrbBody->ulFuncs ) { hb_xfree( pSymRead ); hb_hrbUnLoad( pHrbBody ); hb_errRT_BASE( EG_CORRUPTION, 9998, NULL, HB_ERR_FUNCNAME, 0 ); return NULL; } } /* End of PCODE loading, now linking */ for( ul = 0; ul < pHrbBody->ulSymbols; ul++ ) { if( pSymRead[ ul ].value.pCodeFunc == ( PHB_PCODEFUNC ) SYM_FUNC ) { nPos = hb_hrbFindSymbol( pSymRead[ ul ].szName, pHrbBody->pDynFunc, pHrbBody->ulFuncs ); if( nPos == SYM_NOT_FOUND ) { pSymRead[ ul ].value.pCodeFunc = ( PHB_PCODEFUNC ) SYM_EXTERN; } else { pSymRead[ ul ].value.pCodeFunc = ( PHB_PCODEFUNC ) pHrbBody->pDynFunc[ nPos ].pCodeFunc; pSymRead[ ul ].scope.value |= HB_FS_PCODEFUNC | HB_FS_LOCAL | ( usBind == HB_HRB_BIND_FORCELOCAL ? HB_FS_STATIC : 0 ); } } else if( pSymRead[ ul ].value.pCodeFunc == ( PHB_PCODEFUNC ) SYM_DEFERRED ) { pSymRead[ ul ].value.pCodeFunc = ( PHB_PCODEFUNC ) SYM_EXTERN; pSymRead[ ul ].scope.value |= HB_FS_DEFERRED; } /* External function */ if( pSymRead[ ul ].value.pCodeFunc == ( PHB_PCODEFUNC ) SYM_EXTERN ) { pSymRead[ ul ].value.pCodeFunc = NULL; pDynSym = hb_dynsymFind( pSymRead[ ul ].szName ); if( pDynSym ) { pSymRead[ ul ].value.pFunPtr = pDynSym->pSymbol->value.pFunPtr; if( pDynSym->pSymbol->scope.value & HB_FS_PCODEFUNC ) { pSymRead[ ul ].scope.value |= HB_FS_PCODEFUNC; } } else if( ( pSymRead[ ul ].scope.value & HB_FS_DEFERRED ) == 0 ) { if( ( usMode & HB_HRB_BIND_LAZY ) != 0 ) pSymRead[ ul ].scope.value |= HB_FS_DEFERRED; else { char szName[ HB_SYMBOL_NAME_LEN + 1 ]; hb_strncpy( szName, pSymRead[ ul ].szName, sizeof( szName ) - 1 ); hb_xfree( pSymRead ); hb_hrbUnLoad( pHrbBody ); hb_errRT_BASE( EG_ARG, 6101, "Unknown or unregistered symbol", szName, 0 ); return NULL; } } } } if( hb_vmLockModuleSymbols() ) { if( usBind == HB_HRB_BIND_LOCAL ) { for( ul = 0; ul < pHrbBody->ulSymbols; ul++ ) { if( ( pSymRead[ ul ].scope.value & ( HB_FS_LOCAL | HB_FS_STATIC ) ) == HB_FS_LOCAL ) { pDynSym = hb_dynsymFind( pSymRead[ ul ].szName ); if( pDynSym ) { /* convert public function to static one */ pSymRead[ ul ].scope.value |= HB_FS_STATIC; } } } } pHrbBody->pModuleSymbols = hb_vmRegisterSymbols( pHrbBody->pSymRead, ( HB_USHORT ) pHrbBody->ulSymbols, szFileName ? szFileName : "pcode.hrb", 0, HB_TRUE, HB_FALSE, usBind == HB_HRB_BIND_OVERLOAD ); if( pHrbBody->pModuleSymbols->pModuleSymbols != pSymRead ) { /* * Old unused symbol table has been recycled - free the one * we allocated and disactivate static initialization [druzus] */ pHrbBody->pSymRead = pHrbBody->pModuleSymbols->pModuleSymbols; hb_xfree( pSymRead ); pHrbBody->fInit = HB_TRUE; } else { /* mark symbol table as dynamically allocated so HVM will free it on exit */ pHrbBody->pModuleSymbols->fAllocated = HB_TRUE; /* initialize static variables */ hb_hrbInitStatic( pHrbBody ); } hb_vmUnlockModuleSymbols(); } else { hb_xfree( pSymRead ); hb_hrbUnLoad( pHrbBody ); pHrbBody = NULL; } } return pHrbBody; }
char * hb_verCompiler( void ) { char * pszCompiler; char * pszName; char szSub[ 32 ]; int iVerMajor; int iVerMinor; int iVerPatch; 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"; 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(__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(_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) iVerPatch = _MSC_FULL_VER - ( _MSC_VER * 10000 ); #else iVerPatch = 0; #endif #elif defined(__BORLANDC__) #if (__BORLANDC__ == 1040) /* Version 3.1 */ iVerMajor = 3; iVerMinor = 1; iVerPatch = 0; #elif (__BORLANDC__ >= 1280) /* 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 #if (__BORLANDC__ >= 1424) /* Version 5.9 */ pszName = "CodeGear C++"; #else pszName = "Borland C++"; #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(__GNUC__) #if defined(__DJGPP__) pszName = "DJ Delorie's DJGPP"; #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 #else pszName = ( char * ) NULL; iVerMajor = iVerMinor = iVerPatch = 0; #endif if( pszName ) { #if defined( __ICL ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %hd.%01d Build %u", pszName, szSub, iVerMajor, iVerMinor, __INTEL_COMPILER_BUILD_DATE ); #else if( iVerPatch != 0 ) #if defined(_MSC_VER) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %hd.%02d.%hd", pszName, szSub, iVerMajor, iVerMinor, iVerPatch ); #else hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %hd.%hd.%hd", pszName, szSub, iVerMajor, iVerMinor, iVerPatch ); #endif else if( iVerMajor != 0 || iVerMinor != 0 ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %hd.%hd", pszName, szSub, iVerMajor, iVerMinor ); else hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s", pszName, szSub ); #endif }
HB_WCHAR * hb_fsNameConvU16( const char * szFileName ) { char * pszBuffer = NULL; HB_WCHAR * lpwFileName; if( s_fFnTrim || s_cDirSep != HB_OS_PATH_DELIM_CHR || s_iFileCase != HB_SET_CASE_MIXED || s_iDirCase != HB_SET_CASE_MIXED ) { PHB_FNAME pFileName; HB_SIZE nLen; szFileName = pszBuffer = hb_strncpy( ( char * ) hb_xgrab( HB_PATH_MAX ), szFileName, HB_PATH_MAX - 1 ); if( s_cDirSep != HB_OS_PATH_DELIM_CHR ) { char * p = ( char * ) szFileName; while( *p ) { if( *p == s_cDirSep ) *p = HB_OS_PATH_DELIM_CHR; p++; } } pFileName = hb_fsFNameSplit( szFileName ); /* strip trailing and leading spaces */ if( s_fFnTrim ) { if( pFileName->szName ) { nLen = strlen( pFileName->szName ); while( nLen && pFileName->szName[ nLen - 1 ] == ' ' ) --nLen; while( nLen && pFileName->szName[ 0 ] == ' ' ) { ++pFileName->szName; --nLen; } ( ( char * ) pFileName->szName )[ nLen ] = '\0'; } if( pFileName->szExtension ) { nLen = strlen( pFileName->szExtension ); while( nLen && pFileName->szExtension[ nLen - 1 ] == ' ' ) --nLen; while( nLen && pFileName->szExtension[ 0 ] == ' ' ) { ++pFileName->szExtension; --nLen; } ( ( char * ) pFileName->szExtension )[ nLen ] = '\0'; } } /* FILECASE */ if( s_iFileCase == HB_SET_CASE_LOWER ) { if( pFileName->szName ) hb_strlow( ( char * ) pFileName->szName ); if( pFileName->szExtension ) hb_strlow( ( char * ) pFileName->szExtension ); } else if( s_iFileCase == HB_SET_CASE_UPPER ) { if( pFileName->szName ) hb_strupr( ( char * ) pFileName->szName ); if( pFileName->szExtension ) hb_strupr( ( char * ) pFileName->szExtension ); } /* DIRCASE */ if( pFileName->szPath ) { if( s_iDirCase == HB_SET_CASE_LOWER ) hb_strlow( ( char * ) pFileName->szPath ); else if( s_iDirCase == HB_SET_CASE_UPPER ) hb_strupr( ( char * ) pFileName->szPath ); } hb_fsFNameMerge( ( char * ) szFileName, pFileName ); hb_xfree( pFileName ); } lpwFileName = hb_mbtowc( szFileName ); if( pszBuffer ) hb_xfree( pszBuffer ); return lpwFileName; }
static void hb_ParseLine( PHB_ITEM pReturn, const char * szText, int iDelimiter, int * iWord ) { if( szText ) { HB_ISIZ nLen = strlen( szText ); if( nLen > 0 ) { PHB_ITEM pTemp = hb_itemNew( NULL ); HB_ISIZ i = 0; int word_count = 0; /* booked enough memory */ char * szResult = ( char * ) hb_xgrab( nLen + 1 ); #if 0 while( nLen ) { if( szText[ nLen - 1 ] && ! HB_ISSPACE( szText[ nLen - 1 ] ) ) break; nLen--; } szText[ nLen ] = 0; nLen = strlen( szText ); #endif while( i < nLen ) { HB_ISIZ ui = 0; hb_xmemset( szResult, ' ', nLen + 1 ); /* an '"' found, loop until the next one is found */ if( szText[ i ] == '"' ) { /* an '"' after '"' ? */ if( szText[ i + 1 ] != '"' ) szResult[ ui ] = szText[ i + 1 ]; else szResult[ ui ] = '\0'; ++i; while( ++i < nLen ) { if( szText[ i - 1 ] == '"' ) { szResult[ ui + 1 ] = '\0'; break; } else { if( szText[ i ] == '"' ) szResult[ ui + 1 ] = '\0'; else szResult[ ++ui ] = szText[ i ]; } } word_count++; hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, szResult ) ); } /* delimiter found */ else if( szText[ i ] == iDelimiter ) { /* first delimiter found but no word yet */ if( word_count == 0 ) { /* add an empty string */ szResult[ ui ] = '\0'; } else { /* we have already have the first word */ /* check next character */ if( szText[ i - 1 ] == iDelimiter ) { /* delimiter after delimiter */ /* just add an empty string */ szResult[ ui ] = '\0'; } else { /* ",,0" */ /* it is not a delimiter */ /* move to next character */ ++i; szResult[ ui ] = szText[ i ]; while( ++i < nLen ) { if( szText[ i ] == iDelimiter ) break; else szResult[ ++ui ] = szText[ i ]; } } } word_count++; szResult[ ui + 1 ] = '\0'; hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, szResult ) ); } else { szResult[ ui ] = szText[ i ]; while( ++i < nLen ) { if( szText[ i ] == iDelimiter ) { szResult[ ui + 1 ] = '\0'; break; } else if( szText[ i ] == '"' ) { szResult[ ui ] = szText[ i + 1 ]; ++i; while( ++i < nLen ) { if( szText[ i - 1 ] == '"' ) { szResult[ ui + 1 ] = '\0'; break; } else { if( szText[ i ] == '"' ) { szResult[ ui + 1 ] = '\0'; break; } else szResult[ ++ui ] = szText[ i ]; } } } else szResult[ ++ui ] = szText[ i ]; } word_count++; szResult[ ui + 1 ] = '\0'; hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, szResult ) ); } i++; } /* last character in passed string is a delimiter */ /* just add an empty string */ if( szText[ nLen - 1 ] == iDelimiter ) { word_count++; hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, NULL ) ); } /* store number of words */ *iWord = word_count; /* clean up */ hb_xfree( szResult ); hb_itemRelease( pTemp ); } } }
/* helper function for the *one functions */ static void do_charonly( int iSwitch ) { /* param check */ if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { const char * pcString = hb_parc( 2 ); HB_SIZE sStrLen = hb_parclen( 2 ); const char * pcOnlySet = hb_parc( 1 ); HB_SIZE sOnlySetLen = hb_parclen( 1 ); char * pcRet; HB_SIZE sRetStrLen = 0; int iShift, iBool; const char * pcSub, * pc; /* check for zero-length strings */ switch( iSwitch ) { case DO_CHARONLY_CHARONLY: case DO_CHARONLY_WORDONLY: if( sStrLen == 0 || sOnlySetLen == 0 ) { hb_retc_null(); return; } break; case DO_CHARONLY_CHARREM: case DO_CHARONLY_WORDREM: if( sStrLen == 0 ) { hb_retc_null(); return; } if( sOnlySetLen == 0 ) { hb_retclen( pcString, sStrLen ); return; } break; } if( iSwitch == DO_CHARONLY_WORDONLY || iSwitch == DO_CHARONLY_WORDREM ) iShift = 2; else iShift = 1; pcRet = ( char * ) hb_xgrab( sStrLen ); for( pcSub = pcString; pcSub < pcString + sStrLen + 1 - iShift; pcSub += iShift ) { pc = ct_at_exact_forward( pcOnlySet, sOnlySetLen, pcSub, iShift, NULL ); iBool = ( ( pc != NULL ) && ( ( ( pc - pcOnlySet ) % iShift ) == 0 ) ); if( iBool ? ( iSwitch == DO_CHARONLY_CHARONLY || iSwitch == DO_CHARONLY_WORDONLY ) : ( iSwitch == DO_CHARONLY_CHARREM || iSwitch == DO_CHARONLY_WORDREM ) ) { for( pc = pcSub; pc < pcSub + iShift; pc++ ) pcRet[ sRetStrLen++ ] = *pc; } } /* copy last character if string len is odd */ if( iShift == 2 && sStrLen % 2 == 1 ) pcRet[ sRetStrLen++ ] = pcString[ sStrLen - 1 ]; hb_retclen( pcRet, sRetStrLen ); hb_xfree( pcRet ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(), iError = 0; if( iArgErrorMode != CT_ARGERR_IGNORE ) { switch( iSwitch ) { case DO_CHARONLY_CHARONLY: iError = CT_ERROR_CHARONLY; break; case DO_CHARONLY_WORDONLY: iError = CT_ERROR_WORDONLY; break; case DO_CHARONLY_CHARREM: iError = CT_ERROR_CHARREM; break; case DO_CHARONLY_WORDREM: iError = CT_ERROR_WORDREM; break; } pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, iError, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); } if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else hb_retc_null(); } }
PHB_ZEBRA hb_zebra_create_msi( const char * szCode, HB_SIZE nLen, int iFlags ) { PHB_ZEBRA pZebra; int i, j, iN, iW, iLen = ( int ) nLen; pZebra = hb_zebra_create(); pZebra->iType = HB_ZEBRA_TYPE_MSI; for( i = 0; i < iLen; i++ ) { if( szCode[ i ] < '0' || szCode[ i ] > '9' ) { pZebra->iError = HB_ZEBRA_ERROR_INVALIDCODE; return pZebra; } } pZebra->szCode = ( char * ) hb_xgrab( iLen + 1 ); hb_xmemcpy( pZebra->szCode, szCode, iLen ); pZebra->szCode[ iLen ] = '\0'; szCode = pZebra->szCode; pZebra->pBits = hb_bitbuffer_create(); if( iFlags & HB_ZEBRA_FLAG_WIDE2_5 ) { iN = 2; iW = 5; } else if( iFlags & HB_ZEBRA_FLAG_WIDE3 ) { iN = 1; iW = 3; } else { iN = 1; iW = 2; } /* start */ hb_bitbuffer_cat_int( pZebra->pBits, 31, iW ); hb_bitbuffer_cat_int( pZebra->pBits, 0, iN ); for( i = 0; i < iLen; i++ ) { char code = szCode[ i ] - '0'; for( j = 0; j < 4; j++ ) { if( code & 8 ) { hb_bitbuffer_cat_int( pZebra->pBits, 31, iW ); hb_bitbuffer_cat_int( pZebra->pBits, 0, iN ); } else { hb_bitbuffer_cat_int( pZebra->pBits, 3, iN ); hb_bitbuffer_cat_int( pZebra->pBits, 0, iW ); } code <<= 1; } } if( iFlags & HB_ZEBRA_FLAG_CHECKSUM ) { char code = _msi_checksum( szCode ); code -= '0'; for( j = 0; j < 4; j++ ) { if( code & 8 ) { hb_bitbuffer_cat_int( pZebra->pBits, 31, iW ); hb_bitbuffer_cat_int( pZebra->pBits, 0, iN ); } else { hb_bitbuffer_cat_int( pZebra->pBits, 3, iN ); hb_bitbuffer_cat_int( pZebra->pBits, 0, iW ); } code <<= 1; } } /* stop */ hb_bitbuffer_cat_int( pZebra->pBits, 3, iN ); hb_bitbuffer_cat_int( pZebra->pBits, 0, iW ); hb_bitbuffer_cat_int( pZebra->pBits, 3, iN ); return pZebra; }
static char * hb_fsReadLine( HB_FHANDLE hFileHandle, HB_ISIZ * plBuffLen, const char ** pTerm, HB_ISIZ * pnTermSizes, HB_ISIZ nTerms, HB_BOOL * pbFound, HB_BOOL * pbEOF ) { HB_ISIZ nPosTerm = 0, nPos, nPosition; int nTries; HB_ISIZ nRead = 0, nOffset, nSize; char * pBuff; HB_TRACE( HB_TR_DEBUG, ( "hb_fsReadLine(%p, %" HB_PFS "d, %p, %p, %" HB_PFS "d, %p, %p)", ( void * ) ( HB_PTRUINT ) hFileHandle, *plBuffLen, pTerm, pnTermSizes, nTerms, pbFound, pbEOF ) ); *pbFound = HB_FALSE; *pbEOF = HB_FALSE; nTries = 0; nOffset = 0; nSize = *plBuffLen; if( *plBuffLen < 10 ) *plBuffLen = READING_BLOCK; pBuff = ( char * ) hb_xgrab( *plBuffLen + 1 ); do { if( nTries > 0 ) { /* pBuff can be enlarged to hold the line as needed.. */ nSize = ( *plBuffLen * ( nTries + 1 ) ) + 1; pBuff = ( char * ) hb_xrealloc( pBuff, nSize ); nOffset += nRead; } /* read from file */ nRead = hb_fsReadLarge( hFileHandle, pBuff + nOffset, nSize - nOffset ); /* scan the read buffer */ if( nRead > 0 ) { for( nPos = 0; nPos < nRead; nPos++ ) { for( nPosTerm = 0; nPosTerm < nTerms; nPosTerm++ ) { /* Compare with the LAST terminator byte */ if( pBuff[ nOffset + nPos ] == pTerm[ nPosTerm ][ pnTermSizes[ nPosTerm ] - 1 ] && ( pnTermSizes[ nPosTerm ] - 1 ) <= ( nPos + nOffset ) ) { *pbFound = HB_TRUE; for( nPosition = 0; nPosition < ( pnTermSizes[ nPosTerm ] - 1 ); nPosition++ ) { if( pTerm[ nPosTerm ][ nPosition ] != pBuff[ nOffset + ( nPos - pnTermSizes[ nPosTerm ] ) + nPosition + 1 ] ) { *pbFound = HB_FALSE; break; } } if( *pbFound ) break; } } if( *pbFound ) break; } if( *pbFound ) { *plBuffLen = nOffset + nPos - pnTermSizes[ nPosTerm ] + 1; pBuff[ *plBuffLen ] = '\0'; /* Set handle pointer in the end of the line */ hb_fsSeekLarge( hFileHandle, ( ( nRead - nPos ) * -1 ) + 1, FS_RELATIVE ); return pBuff; } } else { if( ! *pbFound ) { if( nTries == 0 ) { pBuff[ 0 ] = '\0'; *plBuffLen = 0; } else { pBuff[ nOffset + nRead ] = '\0'; *plBuffLen = nOffset + nRead; } *pbEOF = HB_TRUE; } } nTries++; } while( ! *pbFound && nRead > 0 ); return pBuff; }
static HB_ERRCODE pgsqlOpen( SQLBASEAREAP pArea ) { PGconn * pConn = ( ( SDDCONN * ) pArea->pConnection->pSDDConn )->pConn; SDDDATA * pSDDData; PGresult * pResult; ExecStatusType status; PHB_ITEM pItemEof, pItem; HB_USHORT uiFields, uiCount; HB_BOOL bError; DBFIELDINFO pFieldInfo; pArea->pSDDData = memset( hb_xgrab( sizeof( SDDDATA ) ), 0, sizeof( SDDDATA ) ); pSDDData = ( SDDDATA * ) pArea->pSDDData; pResult = PQexec( pConn, pArea->szQuery ); if( ! pResult ) { hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_LOWMEMORY, "Query failed", NULL, 0 ); /* Low memory, etc */ return HB_FAILURE; } status = PQresultStatus( pResult ); if( status != PGRES_TUPLES_OK && status != PGRES_COMMAND_OK ) { hb_errRT_PostgreSQLDD( EG_OPEN, ESQLDD_INVALIDQUERY, PQresultErrorMessage( pResult ), pArea->szQuery, ( HB_ERRCODE ) status ); PQclear( pResult ); return HB_FAILURE; } pSDDData->pResult = pResult; uiFields = ( HB_USHORT ) PQnfields( pResult ); SELF_SETFIELDEXTENT( ( AREAP ) pArea, uiFields ); pItemEof = hb_itemArrayNew( uiFields ); pItem = hb_itemNew( NULL ); bError = HB_FALSE; for( uiCount = 0; uiCount < uiFields; uiCount++ ) { pFieldInfo.atomName = PQfname( pResult, ( int ) uiCount ); pFieldInfo.uiDec = 0; switch( PQftype( pResult, ( int ) uiCount ) ) { case BPCHAROID: case VARCHAROID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = ( HB_USHORT ) PQfmod( pResult, uiCount ) - 4; break; case TEXTOID: pFieldInfo.uiType = HB_FT_MEMO; pFieldInfo.uiLen = 10; break; case NUMERICOID: pFieldInfo.uiType = HB_FT_DOUBLE; pFieldInfo.uiLen = ( PQfmod( pResult, uiCount ) - 4 ) >> 16; pFieldInfo.uiDec = ( PQfmod( pResult, uiCount ) - 4 ) & 0xFFFF; break; case INT2OID: pFieldInfo.uiType = HB_FT_INTEGER; pFieldInfo.uiLen = 6; break; case INT4OID: pFieldInfo.uiType = HB_FT_INTEGER; pFieldInfo.uiLen = 11; break; case INT8OID: case OIDOID: pFieldInfo.uiType = HB_FT_LONG; pFieldInfo.uiLen = 20; break; case FLOAT4OID: case FLOAT8OID: case CASHOID: /* TODO: ??? */ pFieldInfo.uiType = HB_FT_DOUBLE; pFieldInfo.uiLen = 16; pFieldInfo.uiDec = 2; /* TODO: hb_set.SET_DECIMALS ??? */ break; case BOOLOID: pFieldInfo.uiType = HB_FT_LOGICAL; pFieldInfo.uiLen = 1; break; case DATEOID: pFieldInfo.uiType = HB_FT_DATE; pFieldInfo.uiLen = 8; break; case INETOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 29; break; case CIDROID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 32; break; case MACADDROID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 17; break; case BITOID: case VARBITOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = ( HB_USHORT ) PQfsize( pResult, uiCount ); break; case TIMEOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 12; break; case TIMESTAMPOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 23; break; case TIMETZOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 15; break; case TIMESTAMPTZOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 26; break; case NAMEOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 63; break; case BYTEAOID: pFieldInfo.uiType = HB_FT_STRING; pFieldInfo.uiLen = 0; break; default: pFieldInfo.uiType = 0; pFieldInfo.uiLen = 0; bError = HB_TRUE; break; } /* printf( "field:%s \ttype:%d \tsize:%d \tformat:%d \tmod:%d err=%d\n", pFieldInfo.atomName, PQftype( pResult, ( int ) uiCount ), PQfsize( pResult, uiCount ), PQfformat( pResult, uiCount ) , PQfmod( pResult, uiCount ), bError ); */ if( ! bError ) { switch( pFieldInfo.uiType ) { case HB_FT_STRING: { char * pStr; pStr = ( char * ) hb_xgrab( pFieldInfo.uiLen + 1 ); memset( pStr, ' ', pFieldInfo.uiLen ); pStr[ pFieldInfo.uiLen ] = '\0'; hb_itemPutCL( pItem, pStr, pFieldInfo.uiLen ); hb_xfree( pStr ); break; } case HB_FT_MEMO: hb_itemPutC( pItem, NULL ); hb_itemSetCMemo( pItem ); break; case HB_FT_INTEGER: hb_itemPutNI( pItem, 0 ); break; case HB_FT_LONG: hb_itemPutNL( pItem, 0 ); break; case HB_FT_DOUBLE: hb_itemPutND( pItem, 0.0 ); break; case HB_FT_LOGICAL: hb_itemPutL( pItem, HB_FALSE ); break; case HB_FT_DATE: hb_itemPutDS( pItem, NULL ); break; default: hb_itemClear( pItem ); bError = HB_TRUE; break; } hb_arraySetForward( pItemEof, uiCount + 1, pItem ); /* if( pFieldInfo.uiType == HB_IT_DOUBLE || pFieldInfo.uiType == HB_IT_INTEGER ) pFieldInfo.uiType = HB_IT_LONG; */ if( ! bError ) bError = ( SELF_ADDFIELD( ( AREAP ) pArea, &pFieldInfo ) == HB_FAILURE ); } if( bError ) break; } hb_itemRelease( pItem ); if( bError ) { hb_itemClear( pItemEof ); hb_itemRelease( pItemEof ); hb_errRT_PostgreSQLDD( EG_CORRUPTION, ESQLDD_INVALIDFIELD, "Invalid field type", pArea->szQuery, 0 ); return HB_FAILURE; } pArea->ulRecCount = ( HB_ULONG ) PQntuples( pResult ); pArea->pRow = ( void ** ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( void * ) ); pArea->pRowFlags = ( HB_BYTE * ) hb_xgrab( ( pArea->ulRecCount + 1 ) * sizeof( HB_BYTE ) ); memset( pArea->pRowFlags, 0, ( pArea->ulRecCount + 1 ) * sizeof( HB_BYTE ) ); *pArea->pRow = pItemEof; pArea->pRowFlags[ 0 ] = SQLDD_FLAG_CACHED; pArea->fFetched = HB_TRUE; return HB_SUCCESS; }
/* helper function for the justxxx() functions */ static void do_justify( int iSwitch ) { int iNoRet; iNoRet = ct_getref() && ISBYREF( 1 ); if( ISCHAR( 1 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); char cJustChar; const char * pc; char * pcRet, * pcw; HB_SIZE sJustOffset; if( sStrLen == 0 ) { if( iNoRet ) hb_ret(); else hb_retc_null(); return; } if( hb_parclen( 2 ) > 0 ) cJustChar = *( hb_parc( 2 ) ); else if( ISNUM( 2 ) ) cJustChar = ( char ) ( hb_parnl( 2 ) % 256 ); else cJustChar = 0x20; pcRet = ( char * ) hb_xgrab( sStrLen + 1 ); switch( iSwitch ) { case DO_JUSTIFY_JUSTLEFT: pc = pcString; sJustOffset = 0; while( ( *pc == cJustChar ) && ( pc < pcString + sStrLen ) ) { sJustOffset++; pc++; } hb_xmemcpy( pcRet, pcString + sJustOffset, (size_t) ( sStrLen - sJustOffset ) ); for( pcw = pcRet + sStrLen - sJustOffset; pcw < pcRet + sStrLen; pcw++ ) { *pcw = cJustChar; } break; case DO_JUSTIFY_JUSTRIGHT: pc = pcString + sStrLen - 1; sJustOffset = 0; while( ( *pc == cJustChar ) && ( pc >= pcString ) ) { sJustOffset++; pc--; } for( pcw = pcRet; pcw < pcRet + sJustOffset; pcw++ ) { *pcw = cJustChar; } hb_xmemcpy( pcRet + sJustOffset, pcString, (size_t) ( sStrLen - sJustOffset ) ); break; } if( ISBYREF( 1 ) ) hb_storclen( pcRet, sStrLen, 1 ); if( iNoRet ) { hb_ret(); hb_xfree( pcRet ); } else hb_retclen_buffer( pcRet, sStrLen ); } else /* ISCHAR( 1 ) */ { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) { pSubst = ct_error_subst( ( USHORT ) iArgErrorMode, EG_ARG, iSwitch == DO_JUSTIFY_JUSTLEFT ? CT_ERROR_JUSTLEFT : CT_ERROR_JUSTRIGHT, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); } if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else if( iNoRet ) hb_ret(); else hb_retc_null(); } }
HB_BOOL hb_lppRecv( PHB_LPP pSocket, void ** data, HB_SIZE * len, HB_MAXINT timeout ) { HB_MAXINT nTime = 0; long lRecv; if( ! pSocket->pRecvBuffer ) { pSocket->pRecvBuffer = ( char * ) hb_xgrab( 4 ); pSocket->nRecvLen = 0; pSocket->fRecvHasSize = HB_FALSE; } if( timeout > 0 ) nTime = ( HB_MAXINT ) hb_dateMilliSeconds() + timeout; for( ;; ) { if( ! pSocket->fRecvHasSize ) { lRecv = ( long ) ( 4 - pSocket->nRecvLen ); lRecv = hb_socketRecv( pSocket->sd, pSocket->pRecvBuffer + pSocket->nRecvLen, lRecv, 0, timeout ); if( lRecv == -1 ) { pSocket->iError = hb_socketGetError(); return HB_FALSE; } else if( lRecv == 0 ) { /* peer closed connection */ pSocket->iError = 0; return HB_FALSE; } pSocket->nRecvLen += lRecv; if( pSocket->nRecvLen < 4 ) { pSocket->iError = HB_SOCKET_ERR_TIMEOUT; return HB_FALSE; } pSocket->nRecvSize = HB_GET_UINT32( pSocket->pRecvBuffer ); if( pSocket->nLimit && pSocket->nRecvSize > pSocket->nLimit ) { /* protection against remote memory exhaust attack */ pSocket->iError = HB_LPP_ERR_TOOLARGE; hb_xfree( pSocket->pRecvBuffer ); pSocket->pRecvBuffer = NULL; return HB_FALSE; } pSocket->nRecvLen = 0; pSocket->fRecvHasSize = HB_TRUE; if( pSocket->nRecvSize != 4 ) pSocket->pRecvBuffer = ( char * ) hb_xrealloc( pSocket->pRecvBuffer, pSocket->nRecvSize ); } if( pSocket->nRecvSize - pSocket->nRecvLen < ( HB_SIZE ) LONG_MAX ) lRecv = ( long ) ( pSocket->nRecvSize - pSocket->nRecvLen ); else lRecv = LONG_MAX; lRecv = hb_socketRecv( pSocket->sd, pSocket->pRecvBuffer + pSocket->nRecvLen, lRecv, 0, timeout ); if( lRecv == -1 ) { pSocket->iError = hb_socketGetError(); return HB_FALSE; } else if( lRecv == 0 ) { /* peer closed connection */ pSocket->iError = 0; return HB_FALSE; } pSocket->nRecvLen += lRecv; if( pSocket->nRecvSize == pSocket->nRecvLen ) { * data = pSocket->pRecvBuffer; * len = pSocket->nRecvLen; pSocket->pRecvBuffer = NULL; pSocket->iError = 0; return HB_TRUE; } if( timeout == 0 || ( timeout > 0 && ( timeout = nTime - ( HB_MAXINT ) hb_dateMilliSeconds() ) <= 0 ) ) { pSocket->iError = HB_SOCKET_ERR_TIMEOUT; return HB_FALSE; } } }
/* the contents of the inserted bytes are indeterminate, i.e. you'll have to write to them before they mean anything */ static int _ins_buff( PFT_TEXT ft_text, HB_ISIZ iLen ) { char * ReadBuff = ( char * ) hb_xgrab( BUFFSIZE ); char * WriteBuff = ( char * ) hb_xgrab( BUFFSIZE ); char * SaveBuff; HB_FOFFSET fpRead, fpWrite; HB_ISIZ WriteLen, ReadLen; HB_ISIZ SaveLen; HB_ISIZ iLenRemaining = iLen; /* set target move distance, this allows iLen to be greater than BUFFSIZE */ iLen = HB_MIN( iLenRemaining, BUFFSIZE ); iLenRemaining -= iLen; /* initialize file pointers */ fpRead = ft_text->offset[ ft_text->area ]; fpWrite = ft_text->offset[ ft_text->area ] + iLen; /* do initial load of both buffers */ WriteLen = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], WriteBuff, BUFFSIZE, fpRead ) ); fpRead += WriteLen; ReadLen = hb_fileResult( hb_fileRead( ft_text->handles[ ft_text->area ], ReadBuff, BUFFSIZE, -1 ) ); fpRead += ReadLen; ft_text->error[ ft_text->area ] = 0; while( ! ft_text->error[ ft_text->area ] && iLen > 0 ) { while( WriteLen > 0 ) { /* position to beginning of write area */ if( hb_fileSeek( ft_text->handles[ ft_text->area ], fpWrite, FS_SET ) != fpWrite ) { ft_text->error[ ft_text->area ] = hb_fsError(); break; } if( ( SaveLen = hb_fileResult( hb_fileWrite( ft_text->handles[ ft_text->area ], WriteBuff, WriteLen, -1 ) ) ) == 0 ) { ft_text->error[ ft_text->area ] = hb_fsError(); break; } /* move write pointer */ fpWrite += SaveLen; if( SaveLen != WriteLen ) { /* error, fetch errcode and quit */ ft_text->error[ ft_text->area ] = hb_fsError(); break; } #if 0 WriteLen = SaveLen; #endif /* swap buffers */ SaveBuff = WriteBuff; WriteBuff = ReadBuff; ReadBuff = SaveBuff; WriteLen = ReadLen; /* return to read area and read another buffer */ ReadLen = hb_fileResult( hb_fileReadAt( ft_text->handles[ ft_text->area ], ReadBuff, BUFFSIZE, fpRead ) ); fpRead += ReadLen; } iLen = HB_MIN( iLenRemaining, BUFFSIZE ); iLenRemaining -= iLen; } /* store length in bytes, set legacy EOF marker */ ft_text->lastbyte[ ft_text->area ] = hb_fileSeek( ft_text->handles[ ft_text->area ], fpWrite, FS_SET ); hb_fileWrite( ft_text->handles[ ft_text->area ], WriteBuff, 0, -1 ); /* clear last_rec so next gobot will recount the records */ ft_text->last_rec[ ft_text->area ] = 0; hb_fileSeek( ft_text->handles[ ft_text->area ], ft_text->offset[ ft_text->area ], FS_SET ); hb_xfree( ReadBuff ); hb_xfree( WriteBuff ); return ft_text->error[ ft_text->area ]; }
static HB_BOOL hb_SetDefaultPrinter( LPCTSTR lpPrinterName ) { #if ! defined( HB_OS_WIN_CE ) BOOL bFlag; DWORD dwNeeded = 0; HANDLE hPrinter = NULL; PRINTER_INFO_2 * ppi2 = NULL; LPTSTR pBuffer = NULL; /* If Windows 95 or 98, use SetPrinter. */ if( hb_iswin9x() ) { /* Open this printer so you can get information about it. */ bFlag = OpenPrinter( ( LPTSTR ) lpPrinterName, &hPrinter, NULL ); if( ! bFlag || ! hPrinter ) return HB_FALSE; /* The first GetPrinter() tells you how big our buffer must be to hold ALL of PRINTER_INFO_2. Note that this will typically return FALSE. This only means that the buffer (the 3rd parameter) was not filled in. You do not want it filled in here. */ SetLastError( 0 ); bFlag = GetPrinter( hPrinter, 2, 0, 0, &dwNeeded ); if( ! bFlag ) { if( ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ) || ( dwNeeded == 0 ) ) { ClosePrinter( hPrinter ); return HB_FALSE; } } /* Allocate enough space for PRINTER_INFO_2. */ ppi2 = ( PRINTER_INFO_2 * ) hb_xgrab( dwNeeded ); /* The second GetPrinter() will fill in all the current information so that all you have to do is modify what you are interested in. */ bFlag = GetPrinter( hPrinter, 2, ( LPBYTE ) ppi2, dwNeeded, &dwNeeded ); if( ! bFlag ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); return HB_FALSE; } /* Set default printer attribute for this printer. */ ppi2->Attributes |= PRINTER_ATTRIBUTE_DEFAULT; bFlag = SetPrinter( hPrinter, 2, ( LPBYTE ) ppi2, 0 ); if( ! bFlag ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); return HB_FALSE; } /* Tell all open programs that this change occurred. Allow each program 1 second to handle this message. */ SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0L, ( LPARAM ) ( LPCTSTR ) TEXT( "windows" ), SMTO_NORMAL, 1000, NULL ); } /* If Windows NT, use the SetDefaultPrinter API for Windows 2000, or WriteProfileString for version 4.0 and earlier. */ else if( hb_iswinnt() ) { if( hb_iswin2k() ) /* Windows 2000 or later (use explicit call) */ { HMODULE hWinSpool; typedef BOOL ( WINAPI * DEFPRINTER )( LPCTSTR ); /* stops warnings */ DEFPRINTER fnSetDefaultPrinter; hWinSpool = hbwapi_LoadLibrarySystem( TEXT( "winspool.drv" ) ); if( ! hWinSpool ) return HB_FALSE; fnSetDefaultPrinter = ( DEFPRINTER ) HB_WINAPI_GETPROCADDRESST( hWinSpool, "SetDefaultPrinter" ); if( ! fnSetDefaultPrinter ) { FreeLibrary( hWinSpool ); return HB_FALSE; } bFlag = ( *fnSetDefaultPrinter )( lpPrinterName ); FreeLibrary( hWinSpool ); if( ! bFlag ) return HB_FALSE; } else /* NT4.0 or earlier */ { HB_ISIZ nStrLen; /* Open this printer so you can get information about it. */ bFlag = OpenPrinter( ( LPTSTR ) lpPrinterName, &hPrinter, NULL ); if( ! bFlag || ! hPrinter ) return HB_FALSE; /* The first GetPrinter() tells you how big our buffer must be to hold ALL of PRINTER_INFO_2. Note that this will typically return FALSE. This only means that the buffer (the 3rd parameter) was not filled in. You do not want it filled in here. */ SetLastError( 0 ); bFlag = GetPrinter( hPrinter, 2, 0, 0, &dwNeeded ); if( ! bFlag ) { if( ( GetLastError() != ERROR_INSUFFICIENT_BUFFER ) || ( dwNeeded == 0 ) ) { ClosePrinter( hPrinter ); return HB_FALSE; } } /* Allocate enough space for PRINTER_INFO_2. */ ppi2 = ( PRINTER_INFO_2 * ) hb_xgrab( dwNeeded ); /* The second GetPrinter() fills in all the current information. */ bFlag = GetPrinter( hPrinter, 2, ( LPBYTE ) ppi2, dwNeeded, &dwNeeded ); if( ( ! bFlag ) || ( ! ppi2->pDriverName ) || ( ! ppi2->pPortName ) ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); return HB_FALSE; } nStrLen = hbwapi_tstrlen( lpPrinterName ) + hbwapi_tstrlen( ppi2->pDriverName ) + hbwapi_tstrlen( ppi2->pPortName ) + 2; /* Allocate buffer big enough for concatenated string. String will be in form "printername,drivername,portname". */ pBuffer = ( LPTSTR ) hb_xgrab( ( nStrLen + 1 ) * sizeof( TCHAR ) ); pBuffer[ 0 ] = TEXT( '\0' ); /* Build string in form "printername,drivername,portname". */ hbwapi_tstrncat( pBuffer, lpPrinterName, nStrLen ); hbwapi_tstrncat( pBuffer, TEXT( "," ), nStrLen ); hbwapi_tstrncat( pBuffer, ppi2->pDriverName, nStrLen ); hbwapi_tstrncat( pBuffer, TEXT( "," ), nStrLen ); hbwapi_tstrncat( pBuffer, ppi2->pPortName, nStrLen ); /* Set the default printer in win.ini and registry. */ bFlag = WriteProfileString( TEXT( "windows" ), TEXT( "device" ), pBuffer ); if( ! bFlag ) { ClosePrinter( hPrinter ); hb_xfree( ppi2 ); hb_xfree( pBuffer ); return HB_FALSE; } } /* Tell all open programs that this change occurred. Allow each app 1 second to handle this message. */ SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0L, 0L, SMTO_NORMAL, 1000, NULL ); } /* Clean up. */ if( hPrinter ) ClosePrinter( hPrinter ); if( ppi2 ) hb_xfree( ppi2 ); if( pBuffer ) hb_xfree( pBuffer ); return HB_TRUE; #else HB_SYMBOL_UNUSED( lpPrinterName ); return HB_FALSE; #endif }
HB_ERRCODE hb_dbTransStruct( AREAP lpaSource, AREAP lpaDest, LPDBTRANSINFO lpdbTransInfo, PHB_ITEM * pStruct, PHB_ITEM pFields ) { HB_USHORT uiFields, uiSize, uiCount, uiPosSrc, uiPosDst, uiSizeSrc, uiSizeDst; HB_ERRCODE errCode; const char * szField; HB_BOOL fAll; errCode = SELF_FIELDCOUNT( lpaSource, &uiSizeSrc ); if( errCode != HB_SUCCESS ) return errCode; if( lpaDest ) { errCode = SELF_FIELDCOUNT( lpaDest, &uiSizeDst ); if( errCode != HB_SUCCESS ) return errCode; uiSize = HB_MIN( uiSizeDst, uiSizeSrc ); } else { uiSize = uiSizeDst = uiSizeSrc; } if( ! uiSize ) return HB_FAILURE; if( hb_itemType( pFields ) & HB_IT_ARRAY ) { uiFields = ( HB_USHORT ) hb_arrayLen( pFields ); if( uiFields ) uiSize = uiFields; } else uiFields = 0; fAll = ( uiSizeDst == uiSizeSrc ); lpdbTransInfo->lpaSource = lpaSource; lpdbTransInfo->lpaDest = lpaDest; lpdbTransInfo->lpTransItems = ( LPDBTRANSITEM ) hb_xgrab( uiSize * sizeof( DBTRANSITEM ) ); if( ! lpaDest ) { *pStruct = hb_itemNew( NULL ); hb_arrayNew( *pStruct, 0 ); } if( uiFields == 0 ) { if( lpaDest ) { PHB_ITEM pItem = hb_itemNew( NULL ); uiSize = 0; for( uiCount = 1; uiCount <= uiSizeSrc; ++uiCount ) { if( SELF_FIELDINFO( lpaSource, uiCount, DBS_NAME, pItem ) != HB_SUCCESS ) { uiSize = 0; break; } szField = hb_itemGetCPtr( pItem ); uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); if( uiPosDst != uiCount ) fAll = HB_FALSE; if( uiPosDst ) { HB_USHORT ui; /* check for replicated field names in source area */ for( ui = 0; ui < uiSize; ++ui ) { if( lpdbTransInfo->lpTransItems[ ui ].uiDest == uiPosDst ) break; } if( ui == uiSize ) { lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiCount; lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; } } } hb_itemRelease( pItem ); } else { hb_tblStructure( lpaSource, *pStruct, 0 ); uiSize = ( HB_USHORT ) hb_arrayLen( *pStruct ); for( uiCount = 0; uiCount < uiSize; ++uiCount ) { lpdbTransInfo->lpTransItems[ uiCount ].uiSource = lpdbTransInfo->lpTransItems[ uiCount ].uiDest = uiCount + 1; } } } else { uiSize = 0; for( uiCount = 1; uiCount <= uiFields; ++uiCount ) { szField = hb_dbTransFieldPos( pFields, uiCount ); if( szField ) { uiPosSrc = hb_rddFieldExpIndex( lpaSource, szField ); if( ! uiPosSrc ) continue; if( lpaDest ) uiPosDst = hb_rddFieldExpIndex( lpaDest, szField ); else uiPosDst = uiSize + 1; if( uiPosDst ) { if( uiPosSrc != uiPosDst ) fAll = HB_FALSE; lpdbTransInfo->lpTransItems[ uiSize ].uiSource = uiPosSrc; lpdbTransInfo->lpTransItems[ uiSize++ ].uiDest = uiPosDst; if( ! lpaDest ) { hb_arraySize( *pStruct, uiSize ); hb_fldStructure( lpaSource, uiPosSrc, 0, hb_arrayGetItemPtr( *pStruct, uiSize ) ); } } } } } if( uiSize != uiSizeSrc ) fAll = HB_FALSE; if( fAll && lpaDest ) { PHB_ITEM pSrcItm = hb_itemNew( NULL ), pDstItm = hb_itemNew( NULL ); /* * if fAll is HB_TRUE here then it means that all fields are included * and they are on the same positions in both tables, so now check * if their types and sizes are also equal */ for( uiCount = 1; uiCount <= uiSize; ++uiCount ) { if( SELF_FIELDINFO( lpaSource, uiCount, DBS_TYPE, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_TYPE, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_stricmp( hb_itemGetCPtr( pSrcItm ), hb_itemGetCPtr( pDstItm ) ) != 0 ) { fAll = HB_FALSE; break; } if( SELF_FIELDINFO( lpaSource, uiCount, DBS_LEN, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_LEN, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) { fAll = HB_FALSE; break; } if( SELF_FIELDINFO( lpaSource, uiCount, DBS_DEC, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_DEC, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) { fAll = HB_FALSE; break; } #ifdef DBS_FLAG if( SELF_FIELDINFO( lpaSource, uiCount, DBS_FLAG, pSrcItm ) != HB_SUCCESS || SELF_FIELDINFO( lpaDest, uiCount, DBS_FLAG, pDstItm ) != HB_SUCCESS ) { uiSize = 0; break; } if( hb_itemGetNL( pSrcItm ) != hb_itemGetNL( pDstItm ) ) { fAll = HB_FALSE; break; } #endif } hb_itemRelease( pSrcItm ); hb_itemRelease( pDstItm ); } lpdbTransInfo->uiFlags = fAll ? DBTF_MATCH : 0; lpdbTransInfo->uiItemCount = uiSize; return uiSize ? HB_SUCCESS : HB_FAILURE; }
/* helper function for the charswap and wordswap functions */ static void do_charswap( int iSwitch ) { /* suppress return value ? */ int iNoRet = ct_getref() && HB_ISBYREF( 1 ); /* param check */ if( HB_ISCHAR( 1 ) ) { const char * pcString = hb_parc( 1 ); HB_SIZE sStrLen = hb_parclen( 1 ); char * pcRet; HB_SIZE sRetIndex = 0; int iShift, iMod; const char * pcSub; if( sStrLen == 0 ) { if( iNoRet ) hb_ret(); else hb_retc_null(); return; } if( iSwitch == DO_CHARSWAP_WORDSWAP ) { iShift = 4; if( hb_parl( 2 ) ) iSwitch = DO_CHARSWAP_WORDSWAP_CHARSWAP; } else iShift = 2; pcRet = ( char * ) hb_xgrab( sStrLen ); for( pcSub = pcString; pcSub < pcString + sStrLen + 1 - iShift; pcSub += iShift ) { switch( iSwitch ) { case DO_CHARSWAP_WORDSWAP: pcRet[ sRetIndex++ ] = pcSub[ 2 ]; pcRet[ sRetIndex++ ] = pcSub[ 3 ]; pcRet[ sRetIndex++ ] = pcSub[ 0 ]; pcRet[ sRetIndex++ ] = pcSub[ 1 ]; break; case DO_CHARSWAP_WORDSWAP_CHARSWAP: pcRet[ sRetIndex++ ] = pcSub[ 3 ]; pcRet[ sRetIndex++ ] = pcSub[ 2 ]; /* no 'break' here !! */ case DO_CHARSWAP_CHARSWAP: pcRet[ sRetIndex++ ] = pcSub[ 1 ]; pcRet[ sRetIndex++ ] = pcSub[ 0 ]; } } /* copy rest of string */ if( iSwitch == DO_CHARSWAP_WORDSWAP || iSwitch == DO_CHARSWAP_WORDSWAP_CHARSWAP ) iMod = sStrLen % 4; else iMod = sStrLen % 2; for( pcSub = pcString + sStrLen - iMod; pcSub < pcString + sStrLen; pcSub++ ) pcRet[ sRetIndex++ ] = *pcSub; /* return string */ hb_storclen( pcRet, sRetIndex, 1 ); if( iNoRet ) hb_retl( HB_FALSE ); else hb_retclen( pcRet, sRetIndex ); hb_xfree( pcRet ); } else { PHB_ITEM pSubst = NULL; int iArgErrorMode = ct_getargerrormode(); if( iArgErrorMode != CT_ARGERR_IGNORE ) { if( iSwitch == DO_CHARSWAP_CHARSWAP ) pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_CHARSWAP, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); else pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG, CT_ERROR_WORDSWAP, NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS ); } if( pSubst != NULL ) hb_itemReturnRelease( pSubst ); else if( iNoRet ) hb_retl( HB_FALSE ); else hb_retc_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 = 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; }
static void sk_add( PHB_SETKEY * sk_list_ptr, HB_BOOL bReturn, int iKeyCode, PHB_ITEM pAction, PHB_ITEM pIsActive ) { if( iKeyCode ) { PHB_SETKEY sk_list_tmp, sk_list_end; if( pIsActive && ! HB_IS_EVALITEM( pIsActive ) ) pIsActive = NULL; if( pAction && ! HB_IS_EVALITEM( pAction ) ) pAction = NULL; sk_list_tmp = sk_findkey( iKeyCode, *sk_list_ptr, &sk_list_end ); if( sk_list_tmp == NULL ) { if( pAction ) { sk_list_tmp = ( PHB_SETKEY ) hb_xgrab( sizeof( HB_SETKEY ) ); sk_list_tmp->next = NULL; sk_list_tmp->iKeyCode = iKeyCode; sk_list_tmp->pAction = hb_itemNew( pAction ); sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL; if( sk_list_end == NULL ) *sk_list_ptr = sk_list_tmp; else sk_list_end->next = sk_list_tmp; } } else { /* Return the previous value */ if( bReturn ) hb_itemReturn( sk_list_tmp->pAction ); /* Free the previous values */ hb_itemRelease( sk_list_tmp->pAction ); if( sk_list_tmp->pIsActive ) { hb_itemRelease( sk_list_tmp->pIsActive ); } /* Set the new values or free the entry */ if( pAction ) { sk_list_tmp->pAction = hb_itemNew( pAction ); sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL; } else { /* if this is true, then the key found is the first key in the list */ if( sk_list_end == NULL ) { sk_list_tmp = *sk_list_ptr; *sk_list_ptr = sk_list_tmp->next; hb_xfree( sk_list_tmp ); } else { sk_list_end->next = sk_list_tmp->next; hb_xfree( sk_list_tmp ); } } } } }
static unsigned char * _qr_checksum( PHB_BITBUFFER pData, int iVersion, int iLevel ) { const QRVERSION * pVersion = &s_version[ iVersion - 1 ]; const QRLEVEL * pLevel = &( pVersion->level[ iLevel ] ); HB_BYTE * pDataBuf = hb_bitbuffer_buffer( pData ); int * pPoly, * pExp, * pLog; int i, j, iBits, iMod, iPoly, iECCLen, iIndex; unsigned char * pECC, * pECCPtr, ui, ui2; /* Init Galois field. Parameters: iPoly */ iPoly = 0x11D; j = iPoly; for( iBits = 0; j > 1; iBits++ ) j >>= 1; iMod = ( 1 << iBits ) - 1; pExp = ( int * ) hb_xgrab( sizeof( int ) * iMod ); /* exponent function */ pLog = ( int * ) hb_xgrab( sizeof( int ) * ( iMod + 1 ) ); /* logarithm function */ j = 1; pLog[ 0 ] = iMod; for( i = 0; i < iMod; i++ ) { pExp[ i ] = j; pLog[ j ] = i; j <<= 1; if( j & ( 1 << iBits ) ) j ^= iPoly; } /* Init Reed-Solomonn encode. Parameters: iECCLen, iIndex */ iECCLen = pLevel->block[ 0 ].uiECC; iIndex = 0; /* why this parameter is different from DataMatrix ??? */ pPoly = ( int * ) hb_xgrab( sizeof( int ) * ( iECCLen + 1 ) ); pPoly[ 0 ] = 1; for( i = 1; i <= iECCLen; i++ ) { pPoly[ i ] = 1; for( j = i - 1; j > 0; j-- ) { if( pPoly[ j ] ) pPoly[ j ] = pExp[ ( pLog[ pPoly[ j ] ] + iIndex ) % iMod ]; pPoly[ j ] ^= pPoly[ j - 1 ]; } pPoly[ 0 ] = pExp[ ( pLog[ pPoly[ 0 ] ] + iIndex ) % iMod ]; iIndex++; } #ifdef DEBUG_CODE for( i = 0; i <= iECCLen; i++ ) HB_TRACE( HB_TR_ALWAYS, ( "POLY[%3d %02X]:%3d %02X", i, i, pPoly[ i ], pPoly[ i ] ) ); #endif pECC = ( unsigned char * ) hb_xgrab( pLevel->block[ 0 ].uiECC * ( pLevel->block[ 0 ].uiCount + pLevel->block[ 1 ].uiCount ) ); pECCPtr = pECC; /* Divide data into blocks and do Reed-Solomon encoding for each block */ for( ui = 0; ui < pLevel->block[ 0 ].uiCount; ui++ ) { /* Calculate Reed-Solomon ECC for one block */ _reed_solomon_encode( pDataBuf, pLevel->block[ 0 ].uiData, pECCPtr, iECCLen, pPoly, pExp, pLog, iMod ); pDataBuf += pLevel->block[ 0 ].uiData; for( i = 0; i < iECCLen / 2; i++ ) { ui2 = pECCPtr[ i ]; pECCPtr[ i ] = pECCPtr[ iECCLen - 1 - i ]; pECCPtr[ iECCLen - 1 - i ] = ui2; } pECCPtr += iECCLen; } for( ui = 0; ui < pLevel->block[ 1 ].uiCount; ui++ ) { /* Calculate Reed-Solomon ECC for one block */ _reed_solomon_encode( pDataBuf, pLevel->block[ 1 ].uiData, pECCPtr, iECCLen, pPoly, pExp, pLog, iMod ); pDataBuf += pLevel->block[ 1 ].uiData; for( i = 0; i < iECCLen / 2; i++ ) { ui2 = pECCPtr[ i ]; pECCPtr[ i ] = pECCPtr[ iECCLen - 1 - i ]; pECCPtr[ iECCLen - 1 - i ] = ui2; } pECCPtr += iECCLen; } hb_xfree( pExp ); hb_xfree( pLog ); hb_xfree( pPoly ); #ifdef DEBUG_CODE iECCLen = pLevel->block[ 0 ].uiECC * ( pLevel->block[ 0 ].uiCount + pLevel->block[ 1 ].uiCount ); for( i = 0; i < iECCLen; i++ ) HB_TRACE( HB_TR_ALWAYS, ( "ecc:%3d %02X", ( int ) ( unsigned char ) pECC[ i ], ( int ) ( unsigned char ) pECC[ i ] ) ); #endif return pECC; }
static void * hb_pcre_grab( size_t size ) { return hb_xgrab( size ); }