static void hb_compChkIgnoredInfo( HB_COMP_DECL, const char * szSwitch ) { char buffer[ 64 ]; hb_snprintf( buffer, sizeof( buffer ), "Ignored unsupported command line option: %s\n", szSwitch ); hb_compOutStd( HB_COMP_PARAM, buffer ); }
/* NOTE: Use as minimal calls from here, as possible. Don't allocate memory from this function. [vszakats] */ void hb_errInternal( HB_ERRCODE errCode, const char * szText, const char * szPar1, const char * szPar2 ) { char buffer[ 1024 ]; HB_TRACE( HB_TR_DEBUG, ( "hb_errInternal(%d, %s, %s, %s)", errCode, szText, szPar1, szPar2 ) ); hb_conOutErr( hb_conNewLine(), 0 ); hb_snprintf( buffer, sizeof( buffer ), "Unrecoverable error %d: ", errCode ); hb_conOutErr( buffer, 0 ); if( szText ) { hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); hb_conOutErr( buffer, 0 ); } hb_conOutErr( hb_conNewLine(), 0 ); exit( EXIT_FAILURE ); }
static void hb_notSupportedInfo( HB_COMP_DECL, const char * szSwitch ) { char buffer[ 512 ]; hb_snprintf( buffer, sizeof( buffer ), "Not yet supported command line option: %s\n", szSwitch ); hb_compOutStd( HB_COMP_PARAM, buffer ); }
void hb_dateTimeStr( char * pszTime ) { int iYear, iMonth, iDay, iHour, iMinute, iSeconds, iMillisec; HB_TRACE( HB_TR_DEBUG, ( "hb_dateTimeStr(%p)", pszTime ) ); hb_timeStampGetLocal( &iYear, &iMonth, &iDay, &iHour, &iMinute, &iSeconds, &iMillisec ); hb_snprintf( pszTime, 9, "%02d:%02d:%02d", iHour, iMinute, iSeconds ); }
char * hb_verBuildDate( void ) { char * pszDate; HB_TRACE( HB_TR_DEBUG, ( "hb_verBuildDate()" ) ); pszDate = ( char * ) hb_xgrab( 64 ); hb_snprintf( pszDate, 64, "%s %s", __DATE__, __TIME__ ); return pszDate; }
/* This function always closes the time with a zero byte, so it needs a * 13 character long buffer to store time in format "hh:mm:ss.fff" */ char * hb_timeStr( char * szTime, long lMilliSec ) { int iHour, iMinutes, iSeconds, iMSec; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStr(%p, %ld)", szTime, lMilliSec ) ); hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec ); hb_snprintf( szTime, 13, "%02d:%02d:%02d.%03d", iHour, iMinutes, iSeconds, iMSec ); return szTime; }
static void hb_compOutMsg( void * cargo, int iErrorFmt, int iLine, const char * szModule, char cPrefix, int iValue, const char * szText, const char * szPar1, const char * szPar2 ) { char buffer[ 512 ]; if( szModule ) { if( iErrorFmt == HB_ERRORFMT_CLIPPER ) hb_snprintf( buffer, sizeof( buffer ), "\r%s(%i) ", szModule, iLine ); else if( iLine ) hb_snprintf( buffer, sizeof( buffer ), "\n%s:%i: ", szModule, iLine ); else hb_snprintf( buffer, sizeof( buffer ), "\n%s:%s ", szModule, szPar2 ); hb_compOutErr( ( PHB_COMP ) cargo, buffer ); } if( iErrorFmt == HB_ERRORFMT_CLIPPER ) hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ", cPrefix == 'W' ? "Warning" : "Error", cPrefix, iValue ); else hb_snprintf( buffer, sizeof( buffer ), "%s %c%04i ", cPrefix == 'W' ? "warning" : "error", cPrefix, iValue ); hb_compOutErr( ( PHB_COMP ) cargo, buffer ); hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); hb_compOutErr( ( PHB_COMP ) cargo, buffer ); hb_compOutErr( ( PHB_COMP ) cargo, "\n" ); }
char * hb_verHarbour( void ) { char * pszVersion; HB_TRACE( HB_TR_DEBUG, ( "hb_verHarbour()" ) ); pszVersion = ( char * ) hb_xgrab( 80 ); hb_snprintf( pszVersion, 80, "Harbour %d.%d.%d%s (Rev. %d)", HB_VER_MAJOR, HB_VER_MINOR, HB_VER_RELEASE, HB_VER_STATUS, hb_verRevision() ); return pszVersion; }
static void hb_signalExceptionHandler( int sig, siginfo_t * si, void * ucp ) { char buffer[ 32 ]; const char * signame; const char * sigaddr; HB_SYMBOL_UNUSED( ucp ); switch( sig ) { case SIGSEGV: signame = "SIGSEGV"; hb_snprintf( buffer, sizeof( buffer ), "%p", si->si_addr ); sigaddr = buffer; break; case SIGILL: signame = "SIGILL"; hb_snprintf( buffer, sizeof( buffer ), "%p", si->si_addr ); sigaddr = buffer; break; case SIGFPE: signame = "SIGFPE"; hb_snprintf( buffer, sizeof( buffer ), "%p", si->si_addr ); sigaddr = buffer; break; case SIGBUS: signame = "SIGBUS"; hb_snprintf( buffer, sizeof( buffer ), "%p", si->si_addr ); sigaddr = buffer; break; default: hb_snprintf( buffer, sizeof( buffer ), "sig:%d", sig ); signame = buffer; sigaddr = "UNKNOWN"; break; } hb_errInternal( 6005, "Exception %s at address %s", signame, sigaddr ); }
HB_ERRCODE hb_rddGetTempAlias( char * szAliasTmp ) { int i, iArea; for( i = 1; i < 1000; i++ ) { hb_snprintf( szAliasTmp, 11, "__HBTMP%03i", i ); if( hb_rddGetAliasNumber( szAliasTmp, &iArea ) != HB_SUCCESS ) return HB_SUCCESS; } szAliasTmp[ 0 ] = '\0'; return HB_FAILURE; }
/* This function always closes the time with a zero byte, so it needs a * 18 character long buffer to store time in format "YYYYMMDDhhmmssfff" * with trailing 0 byte. */ char * hb_timeStampStrRawPut( char * szDateTime, long lJulian, long lMilliSec ) { int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampStrRawPut(%p, %ld, %ld)", szDateTime, lJulian, lMilliSec ) ); hb_dateDecode( lJulian, &iYear, &iMonth, &iDay ); hb_dateStrPut( szDateTime, iYear, iMonth, iDay ); hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec ); hb_snprintf( szDateTime + 8, 10, "%02d%02d%02d%03d", iHour, iMinutes, iSeconds, iMSec ); return szDateTime; }
/* This function always closes the time with a zero byte. * It needs a 24 character long buffer for full datetime representation * "YYYY-MM-DD hh:mm:ss.fff" */ char * hb_timeStampStr( char * szDateTime, long lJulian, long lMilliSec ) { int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec; HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampStr(%p, %ld, %ld)", szDateTime, lJulian, lMilliSec ) ); hb_dateDecode( lJulian, &iYear, &iMonth, &iDay ); hb_timeDecode( lMilliSec, &iHour, &iMinutes, &iSeconds, &iMSec ); hb_snprintf( szDateTime, 24, "%04d-%02d-%02d %02d:%02d:%02d.%03d", iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec ); szDateTime[ 23 ] = '\0'; return szDateTime; }
char * hb_langName( void ) { char * pszName = ( char * ) hb_xgrab( 128 ); if( s_lang ) hb_snprintf( pszName, 128, "Harbour Language: %s %s (%s)", ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_ID ), ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_NAME ), ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_NAMENAT ) ); else hb_xstrcpy( pszName, "Harbour Language: (not installed)", 0 ); return pszName; }
char * hb_langName( const char * pszID ) { char * pszName; PHB_LANG lang; lang = pszID ? hb_langFind( pszID ) : hb_vmLang(); if( lang ) { pszName = ( char * ) hb_xgrab( 128 ); hb_snprintf( pszName, 128, "Harbour Language: %s %s (%s)", hb_langGetItem( pszID, HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_ID ), hb_langGetItem( pszID, HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_NAME ), hb_langGetItem( pszID, HB_LANG_ITEM_BASE_ID + HB_LANG_ITEM_ID_NAMENAT ) ); } else pszName = hb_strdup( "Harbour Language: (not installed)" ); return pszName; }
/* * Add <pItem> to array <pReturn> at pos <uiPos> * AddToArray( <pItem>, <pReturn>, <uiPos> ) */ static void AddToArray( PHB_ITEM pItem, PHB_ITEM pReturn, HB_SIZE nPos ) { HB_TRACE( HB_TR_DEBUG, ( "AddToArray(%p, %p, %" HB_PFS "u)", pItem, pReturn, nPos ) ); if( HB_IS_SYMBOL( pItem ) ) /* Symbol is pushed as text */ { PHB_ITEM pArrayItem = hb_arrayGetItemPtr( pReturn, nPos ); if( pArrayItem ) { HB_SIZE nLen = strlen( pItem->item.asSymbol.value->szName ) + 2; char * szBuff = ( char * ) hb_xgrab( nLen + 1 ); hb_snprintf( szBuff, nLen + 1, "[%s]", pItem->item.asSymbol.value->szName ); hb_itemPutCLPtr( pArrayItem, szBuff, nLen ); } } else /* Normal types */ hb_itemArrayPut( pReturn, nPos, pItem ); }
static void hb_gaugeUpdate( PHB_ITEM pArray, float fPercent ) { int iCenter = ( ( hb_arrayGetNL( pArray, B_RIGHT ) - hb_arrayGetNL( pArray, B_LEFT ) ) / 2 ) + 1; int iRatio = hb_arrayGetNL( pArray, B_RIGHT ) - hb_arrayGetNL( pArray, B_LEFT ) - 1; int iRow; int iCols; int iMax; char szOldColor[ CLR_STRLEN ]; char * szStr = " "; char szPct[ 5 ]; hb_gtGetColorStr( szOldColor ); hb_gtSetColorStr( hb_arrayGetCPtr( pArray, B_BARCOLOR ) ); fPercent = ( fPercent < 0 ? 0 : ( fPercent > 1 ? 1 : fPercent ) ); iCols = (int) (fPercent * iRatio); if( hb_arrayGetL( pArray, B_DISPLAYNUM ) ) { // hb_snprintf( szPct, sizeof( szPct ), "%3.0f\%", fPercent * 100 ); hb_snprintf( szPct, sizeof( szPct ), "%3.0f%%", fPercent * 100 ); hb_gtWriteAt( (USHORT) hb_arrayGetNL( pArray, B_TOP ), (USHORT) iCenter + 2, (BYTE *) szPct, 4 ); } hb_gtBox( (SHORT) hb_arrayGetNL( pArray, B_TOP ) + 1, (SHORT) hb_arrayGetNL( pArray, B_LEFT ) + 1, (SHORT) hb_arrayGetNL( pArray, B_BOTTOM ) - 1, (SHORT) hb_arrayGetNL( pArray, B_RIGHT ) - 1, ( BYTE * ) szStr ); iMax = hb_arrayGetNL( pArray, B_BOTTOM ) - hb_arrayGetNL( pArray, B_TOP ) - 1; for( iRow = 1; iRow <= iMax; iRow++ ) { hb_gtRepChar( ( USHORT ) (iRow + hb_arrayGetNL( pArray, B_TOP )), ( USHORT ) (hb_arrayGetNL( pArray, B_LEFT ) + 1), ( BYTE ) * hb_arrayGetCPtr( pArray, B_BARCHAR ), ( USHORT ) iCols ); } hb_gtSetColorStr( szOldColor ); }
void hb_compGenPortObj( HB_COMP_DECL, PHB_FNAME pFileName ) { char szFileName[ HB_PATH_MAX ]; HB_SIZE nSize; HB_BYTE * pHrbBody; FILE * yyc; if( ! pFileName->szExtension ) pFileName->szExtension = ".hrb"; hb_fsFNameMerge( szFileName, pFileName ); yyc = hb_fopen( szFileName, "wb" ); if( ! yyc ) { hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_CREATE_OUTPUT, szFileName, NULL ); return; } if( ! HB_COMP_PARAM->fQuiet ) { char buffer[ 80 + HB_PATH_MAX - 1 ]; hb_snprintf( buffer, sizeof( buffer ), "Generating Harbour Portable Object output to \'%s\'... ", szFileName ); hb_compOutStd( HB_COMP_PARAM, buffer ); } hb_compGenBufPortObj( HB_COMP_PARAM, &pHrbBody, &nSize ); if( fwrite( pHrbBody, nSize, 1, yyc ) != 1 ) hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'E', HB_COMP_ERR_FILE_WRITE, szFileName, NULL ); hb_xfree( pHrbBody ); fclose( yyc ); if( ! HB_COMP_PARAM->fQuiet ) hb_compOutStd( HB_COMP_PARAM, "Done.\n" ); }
/* $Doc$ * $FuncName$ AddToArray( <pItem>, <pReturn>, <uiPos> ) * $Description$ Add <pItem> to array <pReturn> at pos <uiPos> * $End$ */ static void AddToArray( PHB_ITEM pItem, PHB_ITEM pReturn, ULONG ulPos ) { HB_ITEM_NEW( Temp ); HB_TRACE(HB_TR_DEBUG, ("AddToArray(%p, %p, %lu)", pItem, pReturn, ulPos)); if( pItem->type == HB_IT_SYMBOL ) { int iLen = strlen( pItem->item.asSymbol.value->szName ) + 2; char *sTemp = (char *) hb_xgrab( iLen + 1 ); hb_snprintf( sTemp, iLen + 1, "[%s]", pItem->item.asSymbol.value->szName ); hb_itemPutCPtr( &Temp, sTemp, iLen ); hb_arraySetForward( pReturn, ulPos, &Temp ); // hb_itemRelease( pTemp ); /* Get rid of temporary str.*/ } else /* Normal types */ { hb_arraySet( pReturn, ulPos, pItem ); } }
HB_EXTERN_BEGIN static void hb_pp_ErrorMessage( void * cargo, const char * const szMsgTable[], char cPrefix, int iCode, const char * szParam1, const char * szParam2 ) { HB_TRACE( HB_TR_DEBUG, ( "hb_pp_ErrorGen(%p, %p, %c, %d, %s, %s)", cargo, szMsgTable, cPrefix, iCode, szParam1, szParam2 ) ); HB_SYMBOL_UNUSED( cargo ); /* ignore all warning messages and errors when break or quit request */ if( cPrefix != 'W' && hb_vmRequestQuery() == 0 ) { char szMsgBuf[ 1024 ]; PHB_ITEM pError; hb_snprintf( szMsgBuf, sizeof( szMsgBuf ), szMsgTable[ iCode - 1 ], szParam1, szParam2 ); pError = hb_errRT_New( ES_ERROR, "PP", 1001, ( HB_ERRCODE ) iCode, szMsgBuf, NULL, 0, EF_NONE | EF_CANDEFAULT ); hb_errLaunch( pError ); hb_errRelease( pError ); } }
char * hb_verCompiler( void ) { char * pszCompiler; const char * pszName; char szSub[ 64 ]; int iVerMajor; int iVerMinor; int iVerPatch; int iVerMicro = 0; int iElements = 0; HB_TRACE( HB_TR_DEBUG, ( "hb_verCompiler()" ) ); pszCompiler = ( char * ) hb_xgrab( COMPILER_BUF_SIZE ); szSub[ 0 ] = '\0'; #if defined( __IBMC__ ) || defined( __IBMCPP__ ) #if defined( __IBMC__ ) iVerMajor = __IBMC__; #else iVerMajor = __IBMCPP__; #endif if( iVerMajor >= 300 ) pszName = "IBM Visual Age C++"; else pszName = "IBM C++"; iVerMajor /= 100; iVerMinor = iVerMajor % 100; iVerPatch = 0; #elif defined( __POCC__ ) pszName = "Pelles ISO C Compiler"; iVerMajor = __POCC__ / 100; iVerMinor = __POCC__ % 100; iVerPatch = 0; #elif defined( __XCC__ ) pszName = "Pelles ISO C Compiler (XCC)"; iVerMajor = __XCC__ / 100; iVerMinor = __XCC__ % 100; iVerPatch = 0; #elif defined( __LCC__ ) pszName = "Logiciels/Informatique lcc-win32"; iVerMajor = 0 /* __LCC__ / 100 */; iVerMinor = 0 /* __LCC__ % 100 */; iVerPatch = 0; #elif defined( __DMC__ ) pszName = __DMC_VERSION_STRING__; iVerMajor = 0; iVerMinor = 0; iVerPatch = 0; #elif defined( __INTEL_COMPILER ) pszName = "Intel(R) C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __INTEL_COMPILER / 100; iVerMinor = ( __INTEL_COMPILER % 100 ) / 10; iVerPatch = 0; #elif defined( __ICL ) pszName = "Intel(R) C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __ICL / 100; iVerMinor = __ICL % 100; iVerPatch = 0; #elif defined( __ICC ) pszName = "Intel(R) (ICC) C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __ICC / 100; iVerMinor = __ICC % 100; iVerPatch = 0; #elif defined( __OPENCC__ ) pszName = "Open64 C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __OPENCC__; iVerMinor = __OPENCC_MINOR__; #if __OPENCC_PATCHLEVEL__ - 0 <= 0 #undef __OPENCC_PATCHLEVEL__ #define __OPENCC_PATCHLEVEL__ 0 #endif iVerPatch = __OPENCC_PATCHLEVEL__; #elif defined( __clang__ ) && defined( __clang_major__ ) /* NOTE: keep clang detection before msvc detection. */ pszName = "LLVM/Clang C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __clang_major__; iVerMinor = __clang_minor__; iVerPatch = __clang_patchlevel__; #elif defined( __clang__ ) pszName = "LLVM/Clang C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif hb_strncat( szSub, " 1.x", sizeof( szSub ) - 1 ); iVerMajor = iVerMinor = iVerPatch = 0; #elif defined( __llvm__ ) && defined( __GNUC__ ) pszName = "LLVM/GNU C"; #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __GNUC__; iVerMinor = __GNUC_MINOR__; #if defined( __GNUC_PATCHLEVEL__ ) iVerPatch = __GNUC_PATCHLEVEL__; #else iVerPatch = 0; #endif #elif defined( _MSC_VER ) #if _MSC_VER >= 800 pszName = "Microsoft Visual C"; #else pszName = "Microsoft C"; #endif #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = _MSC_VER / 100; iVerMinor = _MSC_VER % 100; #if defined( _MSC_FULL_VER ) #if _MSC_VER >= 1400 iVerPatch = _MSC_FULL_VER - ( _MSC_VER * 100000 ); #else iVerPatch = _MSC_FULL_VER - ( _MSC_VER * 10000 ); #endif #else iVerPatch = 0; #endif #elif defined( __BORLANDC__ ) #if __BORLANDC__ >= 0x0590 /* Version 5.9 */ #if __BORLANDC__ >= 0x0620 /* Version 6.2 */ pszName = "Borland/Embarcadero C++"; #else pszName = "Borland/CodeGear C++"; #endif #else pszName = "Borland C++"; #endif #if __BORLANDC__ == 0x0400 /* Version 3.0 */ iVerMajor = 3; iVerMinor = 0; iVerPatch = 0; #elif __BORLANDC__ == 0x0410 /* Version 3.1 */ iVerMajor = 3; iVerMinor = 1; iVerPatch = 0; #elif __BORLANDC__ == 0x0452 /* Version 4.0 */ iVerMajor = 4; iVerMinor = 0; iVerPatch = 0; #elif __BORLANDC__ == 0x0460 /* Version 4.5 */ iVerMajor = 4; iVerMinor = 5; iVerPatch = 0; #elif __BORLANDC__ >= 0x0500 /* Version 5.x */ iVerMajor = __BORLANDC__ >> 8; iVerMinor = ( __BORLANDC__ & 0xFF ) >> 4; iVerPatch = __BORLANDC__ & 0xF; #else /* Version 4.x */ iVerMajor = __BORLANDC__ >> 8; iVerMinor = ( __BORLANDC__ - 1 & 0xFF ) >> 4; iVerPatch = 0; #endif #elif defined( __TURBOC__ ) pszName = "Borland Turbo C"; iVerMajor = __TURBOC__ >> 8; iVerMinor = __TURBOC__ & 0xFF; iVerPatch = 0; #elif defined( __MPW__ ) pszName = "MPW C"; iVerMajor = __MPW__ / 100; iVerMinor = __MPW__ % 100; iVerPatch = 0; #elif defined( __WATCOMC__ ) #if __WATCOMC__ < 1200 pszName = "Watcom C"; #else pszName = "Open Watcom C"; #endif #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __WATCOMC__ / 100; iVerMinor = __WATCOMC__ % 100; #if defined( __WATCOM_REVISION__ ) iVerPatch = __WATCOM_REVISION__; #else iVerPatch = 0; #endif #elif defined( __DCC__ ) pszName = "Wind River Compiler (diab)"; iVerMajor = ( __VERSION_NUMBER__ / 1000 ) % 10; iVerMinor = ( __VERSION_NUMBER__ / 100 ) % 10; iVerPatch = ( __VERSION_NUMBER__ / 10 ) % 10; iVerMicro = __VERSION_NUMBER__ % 10; iElements = 4; #elif defined( __TINYC__ ) pszName = "Tiny C Compiler"; iVerMajor = __TINYC__ / 100; iVerMinor = ( __TINYC__ % 100 ) / 10; iVerPatch = ( __TINYC__ % 100 ) % 10; #elif defined( __PCC__ ) pszName = "Portable C Compiler"; iVerMajor = __PCC__; iVerMinor = __PCC_MINOR__; iVerPatch = __PCC_MINORMINOR__; #if defined( __GNUC__ ) hb_snprintf( szSub, sizeof( szSub ), " (GCC %d.%d.%d emul.)", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ ); #endif #elif defined( __GNUC__ ) #if defined( __DJGPP__ ) pszName = "Delorie GNU C"; #elif defined( __CYGWIN__ ) pszName = "Cygwin GNU C"; #elif defined( __MINGW32__ ) pszName = "MinGW GNU C"; #elif defined( __RSX32__ ) pszName = "EMX/RSXNT/DOS GNU C"; #elif defined( __RSXNT__ ) pszName = "EMX/RSXNT/Win32 GNU C"; #elif defined( __EMX__ ) pszName = "EMX GNU C"; #else pszName = "GNU C"; #endif #if defined( __cplusplus ) hb_strncpy( szSub, "++", sizeof( szSub ) - 1 ); #endif iVerMajor = __GNUC__; iVerMinor = __GNUC_MINOR__; #if defined( __GNUC_PATCHLEVEL__ ) iVerPatch = __GNUC_PATCHLEVEL__; #else iVerPatch = 0; #endif #elif defined( __SUNPRO_C ) pszName = "Sun C"; #if __SUNPRO_C < 0x1000 iVerMajor = __SUNPRO_C / 0x100; iVerMinor = ( __SUNPRO_C & 0xff ) / 0x10; iVerPatch = __SUNPRO_C & 0xf; #else iVerMajor = __SUNPRO_C / 0x1000; iVerMinor = __SUNPRO_C / 0x10 & 0xff; iVerMinor = iVerMinor / 0x10 * 0xa + iVerMinor % 0x10; iVerPatch = __SUNPRO_C & 0xf; #endif #elif defined( __SUNPRO_CC ) pszName = "Sun C++"; #if __SUNPRO_CC < 0x1000 iVerMajor = __SUNPRO_CC / 0x100; iVerMinor = ( __SUNPRO_CC & 0xff ) / 0x10; iVerPatch = __SUNPRO_CC & 0xf; #else iVerMajor = __SUNPRO_CC / 0x1000; iVerMinor = __SUNPRO_CC / 0x10 & 0xff; iVerMinor = iVerMinor / 0x10 * 0xa + iVerMinor % 0x10; iVerPatch = __SUNPRO_CC & 0xf; #endif #else pszName = NULL; iVerMajor = iVerMinor = iVerPatch = 0; #endif if( pszName ) { if( iElements == 4 ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %d.%d.%d.%d", pszName, szSub, iVerMajor, iVerMinor, iVerPatch, iVerMicro ); else if( iVerPatch != 0 ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %d.%d.%d", pszName, szSub, iVerMajor, iVerMinor, iVerPatch ); else if( iVerMajor != 0 || iVerMinor != 0 ) hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s %d.%d", pszName, szSub, iVerMajor, iVerMinor ); else hb_snprintf( pszCompiler, COMPILER_BUF_SIZE, "%s%s", pszName, szSub ); } else hb_strncpy( pszCompiler, "(unrecognized)", COMPILER_BUF_SIZE - 1 ); #if defined( __clang_version__ ) if( strstr( __clang_version__, "(" ) ) /* "2.0 (trunk 103176)" -> "(trunk 103176)" */ hb_snprintf( szSub, sizeof( szSub ), " %s", strstr( __clang_version__, "(" ) ); else hb_snprintf( szSub, sizeof( szSub ), " (%s)", __clang_version__ ); hb_strncat( pszCompiler, szSub, COMPILER_BUF_SIZE - 1 ); #endif #if defined( __DJGPP__ ) hb_snprintf( szSub, sizeof( szSub ), " (DJGPP %i.%02i)", ( int ) __DJGPP__, ( int ) __DJGPP_MINOR__ ); hb_strncat( pszCompiler, szSub, COMPILER_BUF_SIZE - 1 ); #endif #if defined( HB_ARCH_16BIT ) hb_strncat( pszCompiler, " (16-bit)", COMPILER_BUF_SIZE - 1 ); #elif defined( HB_ARCH_32BIT ) hb_strncat( pszCompiler, " (32-bit)", COMPILER_BUF_SIZE - 1 ); #elif defined( HB_ARCH_64BIT ) hb_strncat( pszCompiler, " (64-bit)", COMPILER_BUF_SIZE - 1 ); #endif return pszCompiler; }
char * hb_verPlatform( void ) { char * pszPlatform; HB_TRACE( HB_TR_DEBUG, ( "hb_verPlatform()" ) ); pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 ); #if defined( HB_OS_DOS ) { union REGS regs; regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah ); /* Host OS detection: Windows 2.x, 3.x, 95/98 */ { regs.HB_XREGS.ax = 0x1600; HB_DOS_INT86( 0x2F, ®s, ®s ); if( regs.h.al != 0x00 && regs.h.al != 0x80 ) { char szHost[ 128 ]; if( regs.h.al == 0x01 || regs.h.al == 0xFF ) hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" ); else hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } /* Host OS detection: Windows NT family */ { regs.HB_XREGS.ax = 0x3306; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.HB_XREGS.bx == 0x3205 ) hb_strncat( pszPlatform, " (Windows NT)", PLATFORM_BUF_SIZE ); } /* Host OS detection: OS/2 */ { regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); if( regs.h.al >= 10 ) { char szHost[ 128 ]; if( regs.h.al == 20 && regs.h.ah > 20 ) hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 ); else hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah ); hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE ); } } } #elif defined( HB_OS_OS2 ) { unsigned long aulQSV[ QSV_MAX ] = { 0 }; APIRET rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX ); if( rc == 0 ) { /* is this OS/2 2.x ? */ if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 ) hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld", aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10, aulQSV[ QSV_VERSION_MINOR - 1 ] ); else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f", ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 ); } else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" ); } #elif defined( HB_OS_WIN ) { const char * pszName = ""; OSVERSIONINFO osvi; memset( &osvi, 0, sizeof( osvi ) ); #if defined( HB_OS_WIN_CE ) pszName = " CE"; osvi.dwOSVersionInfoSize = sizeof( osvi ); GetVersionEx( &osvi ); #else /* Detection of legacy Windows versions */ switch( hb_iswin9x() ) { case 5: osvi.dwMajorVersion = 4; osvi.dwMinorVersion = 0; pszName = " 95"; break; case 8: osvi.dwMajorVersion = 4; osvi.dwMinorVersion = 10; pszName = " 98"; break; case 9: osvi.dwMajorVersion = 4; osvi.dwMinorVersion = 90; pszName = " ME"; break; } #endif if( pszName[ 0 ] == '\0' ) { #if defined( HB_OS_WIN_CE ) pszName = " CE"; #else if( hb_iswinver( 11, 0, 0, HB_TRUE ) ) { osvi.dwMajorVersion = 11; osvi.dwMinorVersion = 0; pszName = " 11 or newer"; } else if( hb_iswin10() ) { osvi.dwMajorVersion = 10; osvi.dwMinorVersion = 0; if( hb_iswinver( 10, 0, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 10"; else pszName = " Server 2016"; } else if( hb_iswin81() ) { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 3; if( hb_iswinver( 6, 3, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 8.1"; else pszName = " Server 2012 R2"; } else if( hb_iswinvista() ) { if( hb_iswin8() ) { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 2; if( hb_iswinver( 6, 2, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 8"; else pszName = " Server 2012"; } else if( hb_iswinver( 6, 1, 0, HB_FALSE ) ) { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 1; if( hb_iswinver( 6, 1, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " 7"; else pszName = " Server 2008 R2"; } else { osvi.dwMajorVersion = 6; osvi.dwMinorVersion = 0; if( hb_iswinver( 6, 0, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " Vista"; else pszName = " Server 2008"; } } else if( hb_iswinver( 5, 2, 0, HB_FALSE ) ) { osvi.dwMajorVersion = 5; osvi.dwMinorVersion = 2; if( hb_iswinver( 5, 2, VER_NT_WORKSTATION, HB_FALSE ) ) pszName = " XP x64"; else if( GetSystemMetrics( SM_SERVERR2 ) != 0 ) pszName = " Server 2003 R2"; else pszName = " Server 2003"; } else if( hb_iswinver( 5, 1, 0, HB_FALSE ) ) { osvi.dwMajorVersion = 5; osvi.dwMinorVersion = 1; pszName = " XP"; } else if( hb_iswin2k() ) { osvi.dwMajorVersion = 5; osvi.dwMinorVersion = 0; pszName = " 2000"; } else pszName = " NT"; #endif } hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows%s%s %lu.%lu", pszName, s_iWine ? " (Wine)" : "", osvi.dwMajorVersion, osvi.dwMinorVersion ); /* Add service pack/other info */ if( hb_iswin2k() ) { int tmp; for( tmp = 5; tmp > 0; --tmp ) { if( hb_iswinsp( tmp, HB_TRUE ) ) { char szServicePack[ 8 ]; hb_snprintf( szServicePack, sizeof( szServicePack ), " SP%u", tmp ); hb_strncat( pszPlatform, szServicePack, PLATFORM_BUF_SIZE ); break; } } } #if defined( HB_OS_WIN_CE ) else { /* Also for Win9x and NT, but GetVersionEx() is deprecated so we avoid it. */ if( osvi.szCSDVersion[ 0 ] != TEXT( '\0' ) ) { char * pszCSDVersion = HB_OSSTRDUP( osvi.szCSDVersion ); int i; /* Skip the leading spaces (Win95B, Win98) */ for( i = 0; pszCSDVersion[ i ] != '\0' && HB_ISSPACE( ( int ) pszCSDVersion[ i ] ); i++ ) ; if( pszCSDVersion[ i ] != '\0' ) { hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE ); hb_strncat( pszPlatform, pszCSDVersion + i, PLATFORM_BUF_SIZE ); } hb_xfree( pszCSDVersion ); } } #endif } #elif defined( __CEGCC__ ) { hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" ); } #elif defined( HB_OS_UNIX ) { struct utsname un; uname( &un ); #if defined( HB_OS_MINIX ) hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s Release %s Version %s %s", un.sysname, un.release, un.version, un.machine ); #else hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine ); #endif } #else { hb_strncpy( pszPlatform, "(unrecognized)", PLATFORM_BUF_SIZE ); } #endif return pszPlatform; }
void hb_errInternalRaw( HB_ERRCODE errCode, const char * szText, const char * szPar1, const char * szPar2 ) { char buffer[ 8192 ]; char file[ HB_PATH_MAX ]; const char * szFile, * szInfo; HB_BOOL fStack, fLang; HB_USHORT uiLine; int iLevel; FILE * hLog; HB_TRACE( HB_TR_DEBUG, ( "hb_errInternal(%d, %s, %s, %s)", errCode, szText, szPar1, szPar2 ) ); if( szPar1 == NULL ) szPar1 = ""; if( szPar2 == NULL ) szPar2 = ""; fStack = hb_stackId() != NULL; fLang = fStack && hb_langID() != NULL; szFile = fStack ? hb_setGetCPtr( HB_SET_HBOUTLOG ) : NULL; if( ! szFile ) szFile = "hb_out.log"; hLog = hb_fopen( szFile, "a+" ); if( hLog ) { char szTime[ 9 ]; int iYear, iMonth, iDay; hb_dateToday( &iYear, &iMonth, &iDay ); hb_dateTimeStr( szTime ); fprintf( hLog, "Application Internal Error - %s\n", hb_cmdargARGVN( 0 ) ); fprintf( hLog, "Terminated at: %04d-%02d-%02d %s\n", iYear, iMonth, iDay, szTime ); szInfo = fStack ? hb_setGetCPtr( HB_SET_HBOUTLOGINFO ) : NULL; if( szInfo && *szInfo ) fprintf( hLog, "Info: %s\n", szInfo ); } hb_conOutErr( hb_conNewLine(), 0 ); if( fLang ) hb_snprintf( buffer, sizeof( buffer ), hb_langDGetItem( HB_LANG_ITEM_BASE_ERRINTR ), errCode ); else hb_snprintf( buffer, sizeof( buffer ), "Unrecoverable error %d: ", errCode ); hb_conOutErr( buffer, 0 ); if( hLog ) fprintf( hLog, "%s", buffer ); if( ! szText && fLang ) szText = hb_langDGetItem( HB_LANG_ITEM_BASE_ERRINTR + errCode - 9000 ); if( szText ) hb_snprintf( buffer, sizeof( buffer ), szText, szPar1, szPar2 ); else buffer[ 0 ] = '\0'; hb_conOutErr( buffer, 0 ); hb_conOutErr( hb_conNewLine(), 0 ); if( hLog ) fprintf( hLog, "%s\n", buffer ); if( fStack && hb_stackTotalItems() ) { iLevel = 0; while( hb_procinfo( iLevel++, buffer, &uiLine, file ) ) { char msg[ HB_SYMBOL_NAME_LEN + HB_SYMBOL_NAME_LEN + 32 ]; hb_snprintf( msg, sizeof( msg ), "Called from %s(%hu)%s%s\n", buffer, uiLine, *file ? " in " : "", file ); hb_conOutErr( msg, 0 ); if( hLog ) fprintf( hLog, "%s", msg ); } } if( hLog ) { fprintf( hLog, "------------------------------------------------------------------------\n" ); fclose( hLog ); } }
static int hb_pp_writeRules( FILE * fout, PHB_PP_RULE pFirst, char * szName ) { char szMatch[ 16 ], szResult[ 16 ]; ULONG ulRepeatBits, ulBit; PHB_PP_RULE pRule; int iRule; USHORT u; iRule = 0; pRule = pFirst; while( pRule ) { ++iRule; if( pRule->pMatch ) { if( strlen( pRule->pMatch->value ) > 1 ) hb_pp_CollectReservedName( pRule->pMatch->value ); hb_snprintf( szMatch, sizeof( szMatch ), "s_%cm%03d", szName[ 0 ], iRule ); hb_pp_writeTokenList( fout, pRule->pMatch, szMatch ); } if( pRule->pResult ) { hb_snprintf( szResult, sizeof( szResult ), "s_%cr%03d", szName[ 0 ], iRule ); hb_pp_writeTokenList( fout, pRule->pResult, szResult ); } pRule = pRule->pPrev; } fprintf( fout, "static const HB_PP_DEFRULE s_%s[ %d ] = {\n", szName, iRule ); iRule = 0; pRule = pFirst; while( pRule ) { ++iRule; if( pRule->pMatch ) hb_snprintf( szMatch, sizeof( szMatch ), "s_%cm%03d", szName[ 0 ], iRule ); else hb_strncpy( szMatch, "NULL ", sizeof( szResult ) - 1 ); if( pRule->pResult ) hb_snprintf( szResult, sizeof( szResult ), "s_%cr%03d", szName[ 0 ], iRule ); else hb_strncpy( szResult, "NULL ", sizeof( szResult ) - 1 ); ulRepeatBits = 0; for( u = 0, ulBit = 1; u < pRule->markers; ++u, ulBit <<= 1 ) { if( pRule->pMarkers[ u ].canrepeat ) ulRepeatBits |= ulBit; } fprintf( fout, " { %s, %s, %d,%2d, 0x%04lx }%s\n", szMatch, szResult, HB_PP_CMP_MODE( pRule->mode ), pRule->markers, ulRepeatBits, pRule->pPrev ? "," : "" ); pRule = pRule->pPrev; } fprintf( fout, "};\n\n" ); return iRule; }
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 }
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; }
int hb_pp_Internal( FILE * handl_o, char * sOut ) { PFILE pFile; char * ptr, * ptrOut, * tmpPtr; int lContinue; int lens, rdlen; int lLine = 0; int State = 0; HB_TRACE(HB_TR_DEBUG, ("hb_pp_Internal(%p, %s)", handl_o, sOut)); while( TRUE ) { pFile = hb_comp_files.pLast; lens = lContinue = 0; ptrOut = sOut; while( ( rdlen = hb_pp_RdStr( pFile->handle, s_szLine + lens, HB_PP_STR_SIZE - 1 - lens, lContinue, ( char * ) pFile->pBuffer, &( pFile->lenBuffer ), &( pFile->iBuffer ), State ) ) >= 0 ) { lens += rdlen; hb_comp_iLine ++; // printf( "Line: %i Len: %i <%s>\n", hb_comp_iLine, lens, s_szLine ); if( lens >= HB_PP_STR_SIZE ) { hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_BUFFER_OVERFLOW, NULL, NULL ); } if( hb_pp_bInline ) { break; } if( s_szLine[ lens - 1 ] == ';' ) { lContinue = 1; lens--; lens--; while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' ) { lens--; } s_szLine[ ++lens ] = ' '; s_szLine[ ++lens ] = '\0'; State = STATE_NORMAL; } else { lContinue = 0; lens = 0; State = 0; } if( ! lContinue ) { if( *s_szLine != '\0' ) { ptr = s_szLine; HB_SKIPTABSPACES( ptr ); if( *ptr == '#' ) { hb_pp_ParseDirective( ptr + 1 ); if( pFile != hb_comp_files.pLast ) { pFile = ( PFILE ) ( ( PFILE ) hb_comp_files.pLast )->pPrev; if( lLine ) { hb_snprintf( s_szLine, sizeof( s_szLine ), "#line %d \"%s\"\n", pFile->iLine, pFile->szFileName ); } else { *s_szLine = '\0'; } lLine = 0; hb_snprintf( s_szLine + strlen( s_szLine ), sizeof( s_szLine ) - strlen( s_szLine ), "#line 1 \"%s\"", hb_comp_files.pLast->szFileName ); } else { *s_szLine = '\0'; } } else { if( *ptr == '\0' ) { if( hb_comp_files.iFiles == 1 ) { *s_szLine = '\0'; } else { continue; } } else { if( hb_pp_nCondCompile == 0 || hb_pp_aCondCompile[ hb_pp_nCondCompile - 1 ] > 0 ) { //printf( "Parse: >%s<\n", ptr ); hb_pp_ParseExpression( ptr, s_szOutLine ); //printf( "1-Parsed: >%s<\n", s_szLine ); //printf( "2-Parsed: >%s<\n", s_szOutLine ); } else { *s_szLine = '\0'; } } } } break; } } if( hb_pp_bInComment ) { hb_compGenError( hb_pp_szErrors, 'F', HB_PP_ERR_UNTERMINATED_COMMENTS, NULL, NULL ); } if( rdlen < 0 ) { if( hb_comp_files.iFiles == 1 ) { return 0; /* we have reached the main EOF */ } else { CloseInclude(); lLine = 1; } /* Ron Pinkas added 2000-06-22 */ s_szLine[0] = '\0'; break; /* Ron Pinkas end 2000-06-22 */ } if( *s_szLine ) { break; } else { if( handl_o && s_szOutLine[0] == '#' ) { hb_pp_WrStr( handl_o, s_szOutLine ); s_szOutLine[0] = '\0'; } } } if( lLine ) { if( hb_comp_files.iFiles == 1 ) { hb_pp_LastOutLine = hb_comp_iLine; } sprintf( ptrOut, "#line %d \"%s\"", ( hb_comp_files.pLast->iLine ) , hb_comp_files.pLast->szFileName ); while( *ptrOut ) { ptrOut++; } /* Ron Pinkas added 2000-06-14 */ tmpPtr = s_szLine; HB_SKIPTABSPACES( tmpPtr ); /* Last Opened file ended without CR - adding CR to the #line directive. */ if( *tmpPtr != '\0' ) { *ptrOut++ = '\n'; *ptrOut = '\0'; } /* Ron Pinkas end 2000-06-14 */ } lens = hb_pp_strocpy( ptrOut, s_szLine ) + ( ptrOut - sOut ); if( hb_comp_iLineINLINE && hb_pp_bInline == 0 ) { hb_comp_iLine = hb_comp_iLinePRG + ( hb_comp_iLine - hb_comp_iLineINLINE ); hb_comp_iLineINLINE = 0; } if( handl_o ) { char *pTmp = sOut; HB_SKIPTABSPACES( pTmp ); //printf( "1>%s<\n", sOut ); //printf( "2>%s<\n", s_szOutLine ); if( s_szOutLine[0] && ( strstr( s_szOutLine, pTmp ) ) ) { if( pTmp > sOut ) { hb_pp_Stuff( sOut, s_szOutLine, pTmp - sOut, 0, strlen( s_szOutLine ) ); } hb_pp_WrStr( handl_o, s_szOutLine ); } else if( s_szOutLine[0] == '#' && strstr( pTmp, s_szOutLine ) == NULL ) { strcpy( sOut + lens, s_szOutLine ); hb_pp_WrStr( handl_o, sOut ); } else { hb_pp_WrStr( handl_o, sOut ); } s_szOutLine[0] = '\0'; } *( sOut + lens++ ) = '\n'; *( sOut + lens ) = '\0'; #if 0 printf( "%d : %s\n", hb_comp_iLine, sOut ); #endif return lens; }
static LONG WINAPI hb_winExceptionHandler( struct _EXCEPTION_POINTERS * pExceptionInfo ) { char errmsg[ 8192 ]; int errmsglen = sizeof( errmsg ) - 1; errmsg[ 0 ] = '\0'; #if defined( HB_OS_WIN_64 ) && defined( HB_CPU_X86_64 ) { char buf[ 32 ]; PCONTEXT pCtx = pExceptionInfo->ContextRecord; const char * szCode; /* two most common codes */ switch( pExceptionInfo->ExceptionRecord->ExceptionCode ) { case EXCEPTION_ACCESS_VIOLATION: szCode = " " "ACCESS_VIOLATION"; break; case EXCEPTION_IN_PAGE_ERROR: szCode = " " "IN_PAGE_ERROR"; break; default: szCode = ""; } hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X%s\n" " Exception Address:%016" PFLL "X\n" " RAX:%016" PFLL "X RBX:%016" PFLL "X RCX:%016" PFLL "X RDX:%016" PFLL "X\n" " RSI:%016" PFLL "X RDI:%016" PFLL "X RBP:%016" PFLL "X\n" " R8 :%016" PFLL "X R9 :%016" PFLL "X R10:%016" PFLL "X R11:%016" PFLL "X\n" " R12:%016" PFLL "X R13:%016" PFLL "X R14:%016" PFLL "X R15:%016" PFLL "X\n" " CS:RIP:%04X:%016" PFLL "X SS:RSP:%04X:%016" PFLL "X\n" " DS:%04X ES:%04X FS:%04X GS:%04X\n" " Flags:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, szCode, ( HB_PTRDIFF ) pExceptionInfo->ExceptionRecord->ExceptionAddress, pCtx->Rax, pCtx->Rbx, pCtx->Rcx, pCtx->Rdx, pCtx->Rsi, pCtx->Rdi, pCtx->Rbp, pCtx->R8 , pCtx->R9 , pCtx->R10, pCtx->R11, pCtx->R12, pCtx->R13, pCtx->R14, pCtx->R15, ( HB_U32 ) pCtx->SegCs, pCtx->Rip, ( HB_U32 ) pCtx->SegSs, pCtx->Rsp, ( HB_U32 ) pCtx->SegDs, ( HB_U32 ) pCtx->SegEs, ( HB_U32 ) pCtx->SegFs, ( HB_U32 ) pCtx->SegGs, ( HB_U32 ) pCtx->EFlags ); if( pExceptionInfo->ExceptionRecord->NumberParameters && pExceptionInfo->ExceptionRecord->NumberParameters < ( DWORD ) EXCEPTION_MAXIMUM_PARAMETERS ) { DWORD arg; hb_strncat( errmsg, " Exception Parameters:", errmsglen ); for( arg = 0; arg < pExceptionInfo->ExceptionRecord->NumberParameters; ++arg ) { hb_snprintf( buf, sizeof( buf ), " %016" PFLL "X", ( HB_U64 ) pExceptionInfo->ExceptionRecord->ExceptionInformation[ arg ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n", errmsglen ); } /* TODO: 64-bit stack trace. See: - StackWalk64() - https://www.codeproject.com/KB/threads/StackWalker.aspx?fid=202364 */ } #elif defined( HB_OS_WIN_64 ) && defined( HB_CPU_IA_64 ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%016" PFLL "X\n" " IS0 :%016" PFLL "X IS1 :%016" PFLL "X IS2 :%016" PFLL "X IS3 :%016" PFLL "X\n" " IT0 :%016" PFLL "X IT1 :%016" PFLL "X IT2 :%016" PFLL "X IT3 :%016" PFLL "X\n" " IT4 :%016" PFLL "X IT5 :%016" PFLL "X IT6 :%016" PFLL "X IT7 :%016" PFLL "X\n" " IT8 :%016" PFLL "X IT9 :%016" PFLL "X IT10:%016" PFLL "X IT11:%016" PFLL "X\n" " IT12:%016" PFLL "X IT13:%016" PFLL "X IT14:%016" PFLL "X IT15:%016" PFLL "X\n" " IT16:%016" PFLL "X IT17:%016" PFLL "X IT18:%016" PFLL "X IT19:%016" PFLL "X\n" " IT20:%016" PFLL "X IT21:%016" PFLL "X IT22:%016" PFLL "X\n" " IGp :%016" PFLL "X IV0 :%016" PFLL "X ISp :%016" PFLL "X ITeb:%016" PFLL "X\n" " INat:%016" PFLL "X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, pExceptionInfo->ExceptionRecord->ExceptionAddress, pCtx->IntS0 , pCtx->IntS1 , pCtx->IntS2 , pCtx->IntS3 , pCtx->IntT0 , pCtx->IntT1 , pCtx->IntT2 , pCtx->IntT3 , pCtx->IntT4 , pCtx->IntT5 , pCtx->IntT6 , pCtx->IntT7 , pCtx->IntT8 , pCtx->IntT9 , pCtx->IntT10, pCtx->IntT11, pCtx->IntT12, pCtx->IntT13, pCtx->IntT14, pCtx->IntT15, pCtx->IntT16, pCtx->IntT17, pCtx->IntT18, pCtx->IntT19, pCtx->IntT20, pCtx->IntT21, pCtx->IntT22, pCtx->IntGp , pCtx->IntV0 , pCtx->IntSp , pCtx->IntTeb, pCtx->IntNats ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_ARM ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%08X\n" " R0 :%08X R1 :%08X R2 :%08X R3 :%08X\n" " R4 :%08X R5 :%08X R6 :%08X R7 :%08X\n" " R8 :%08X R9 :%08X R10:%08X R11:%08X\n" " R12:%08X\n" " SP :%08X LR :%08X PC :%08X\n" " Flags:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->R0 , ( HB_U32 ) pCtx->R1 , ( HB_U32 ) pCtx->R2 , ( HB_U32 ) pCtx->R3 , ( HB_U32 ) pCtx->R4 , ( HB_U32 ) pCtx->R5 , ( HB_U32 ) pCtx->R6 , ( HB_U32 ) pCtx->R7 , ( HB_U32 ) pCtx->R8 , ( HB_U32 ) pCtx->R9 , ( HB_U32 ) pCtx->R10, ( HB_U32 ) pCtx->R11, ( HB_U32 ) pCtx->R12, ( HB_U32 ) pCtx->Sp , ( HB_U32 ) pCtx->Lr , ( HB_U32 ) pCtx->Pc, ( HB_U32 ) pCtx->Psr ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_MIPS ) && defined( HB_ARCH_32BIT ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%08X\n" " IZe:%08X IAt:%08X ILo:%08X IHi:%08X\n" " IA0:%08X IA1:%08X IA2:%08X IA3:%08X\n" " IT0:%08X IT1:%08X IT2:%08X IT3:%08X\n" " IT4:%08X IT5:%08X IT6:%08X IT7:%08X\n" " IT8:%08X IT9:%08X IV0:%08X IV1:%08X\n" " IS0:%08X IS1:%08X IS2:%08X IS3:%08X\n" " IS4:%08X IS5:%08X IS6:%08X IS7:%08X\n" " IS8:%08X IK0:%08X IK1:%08X\n" " IGp:%08X ISp:%08X IRa:%08X\n" " Fsr:%08X Fir:%08X Psr:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->IntZero, ( HB_U32 ) pCtx->IntAt, ( HB_U32 ) pCtx->IntLo, ( HB_U32 ) pCtx->IntHi, ( HB_U32 ) pCtx->IntA0, ( HB_U32 ) pCtx->IntA1, ( HB_U32 ) pCtx->IntA2, ( HB_U32 ) pCtx->IntA3, ( HB_U32 ) pCtx->IntT0, ( HB_U32 ) pCtx->IntT1, ( HB_U32 ) pCtx->IntT2, ( HB_U32 ) pCtx->IntT3, ( HB_U32 ) pCtx->IntT4, ( HB_U32 ) pCtx->IntT5, ( HB_U32 ) pCtx->IntT6, ( HB_U32 ) pCtx->IntT7, ( HB_U32 ) pCtx->IntT8, ( HB_U32 ) pCtx->IntT9, ( HB_U32 ) pCtx->IntV0, ( HB_U32 ) pCtx->IntV1, ( HB_U32 ) pCtx->IntS0, ( HB_U32 ) pCtx->IntS1, ( HB_U32 ) pCtx->IntS2, ( HB_U32 ) pCtx->IntS3, ( HB_U32 ) pCtx->IntS4, ( HB_U32 ) pCtx->IntS5, ( HB_U32 ) pCtx->IntS6, ( HB_U32 ) pCtx->IntS7, ( HB_U32 ) pCtx->IntS8, ( HB_U32 ) pCtx->IntK0, ( HB_U32 ) pCtx->IntK1, ( HB_U32 ) pCtx->IntGp, ( HB_U32 ) pCtx->IntSp, ( HB_U32 ) pCtx->IntRa, ( HB_U32 ) pCtx->Fsr , ( HB_U32 ) pCtx->Fir , ( HB_U32 ) pCtx->Psr ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_MIPS ) && defined( HB_ARCH_64BIT ) /* Such platform doesn't currently exist [2010]. */ { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%016" PFLL "X\n" " IZe:%016" PFLL "X IAt:%016" PFLL "X ILo:%016" PFLL "X IHi:%016" PFLL "X\n" " IA0:%016" PFLL "X IA1:%016" PFLL "X IA2:%016" PFLL "X IA3:%016" PFLL "X\n" " IT0:%016" PFLL "X IT1:%016" PFLL "X IT2:%016" PFLL "X IT3:%016" PFLL "X\n" " IT4:%016" PFLL "X IT5:%016" PFLL "X IT6:%016" PFLL "X IT7:%016" PFLL "X\n" " IT8:%016" PFLL "X IT9:%016" PFLL "X IV0:%016" PFLL "X IV1:%016" PFLL "X\n" " IS0:%016" PFLL "X IS1:%016" PFLL "X IS2:%016" PFLL "X IS3:%016" PFLL "X\n" " IS4:%016" PFLL "X IS5:%016" PFLL "X IS6:%016" PFLL "X IS7:%016" PFLL "X\n" " IS8:%016" PFLL "X IK0:%016" PFLL "X IK1:%016" PFLL "X\n" " IGp:%016" PFLL "X ISp:%016" PFLL "X IRa:%016" PFLL "X\n" " Fsr:%016" PFLL "X Fir:%016" PFLL "X Psr:%016" PFLL "X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, pExceptionInfo->ExceptionRecord->ExceptionAddress, pCtx->IntZero, pCtx->IntAt, pCtx->IntLo, pCtx->IntHi, pCtx->IntA0, pCtx->IntA1, pCtx->IntA2, pCtx->IntA3, pCtx->IntT0, pCtx->IntT1, pCtx->IntT2, pCtx->IntT3, pCtx->IntT4, pCtx->IntT5, pCtx->IntT6, pCtx->IntT7, pCtx->IntT8, pCtx->IntT9, pCtx->IntV0, pCtx->IntV1, pCtx->IntS0, pCtx->IntS1, pCtx->IntS2, pCtx->IntS3, pCtx->IntS4, pCtx->IntS5, pCtx->IntS6, pCtx->IntS7, pCtx->IntS8, pCtx->IntK0, pCtx->IntK1, pCtx->IntGp, pCtx->IntSp, pCtx->IntRa, pCtx->Fsr , pCtx->Fir , pCtx->Psr ); } #elif defined( HB_OS_WIN_CE ) && defined( HB_CPU_SH ) { PCONTEXT pCtx = pExceptionInfo->ContextRecord; hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X\n" " Exception Address:%08X\n" " R0 :%08X R1 :%08X R2 :%08X R3 :%08X\n" " R4 :%08X R5 :%08X R6 :%08X R7 :%08X\n" " R8 :%08X R9 :%08X R10:%08X R11:%08X\n" " R12:%08X R13:%08X R14:%08X R15:%08X\n" " PR :%08X MACH:%08X MACL:%08X GBR:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->R0 , ( HB_U32 ) pCtx->R1 , ( HB_U32 ) pCtx->R2 , ( HB_U32 ) pCtx->R3 , ( HB_U32 ) pCtx->R4 , ( HB_U32 ) pCtx->R5 , ( HB_U32 ) pCtx->R6 , ( HB_U32 ) pCtx->R7 , ( HB_U32 ) pCtx->R8 , ( HB_U32 ) pCtx->R9 , ( HB_U32 ) pCtx->R10, ( HB_U32 ) pCtx->R11, ( HB_U32 ) pCtx->R12, ( HB_U32 ) pCtx->R13, ( HB_U32 ) pCtx->R14, ( HB_U32 ) pCtx->R15, ( HB_U32 ) pCtx->PR, ( HB_U32 ) pCtx->MACH, ( HB_U32 ) pCtx->MACL, ( HB_U32 ) pCtx->GBR ); } #elif defined( HB_CPU_X86 ) { char buf[ 64 + MAX_PATH ]; PCONTEXT pCtx = pExceptionInfo->ContextRecord; const char * szCode; /* two most common codes */ switch( pExceptionInfo->ExceptionRecord->ExceptionCode ) { case EXCEPTION_ACCESS_VIOLATION: szCode = " " "ACCESS_VIOLATION"; break; case EXCEPTION_IN_PAGE_ERROR: szCode = " " "IN_PAGE_ERROR"; break; default: szCode = ""; } hb_snprintf( errmsg, errmsglen, "\n\n" " Exception Code:%08X%s\n" " Exception Address:%08X\n" " EAX:%08X EBX:%08X ECX:%08X EDX:%08X\n" " ESI:%08X EDI:%08X EBP:%08X\n" " CS:EIP:%04X:%08X SS:ESP:%04X:%08X\n" " DS:%04X ES:%04X FS:%04X GS:%04X\n" " Flags:%08X\n", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionCode, szCode, ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionAddress, ( HB_U32 ) pCtx->Eax, ( HB_U32 ) pCtx->Ebx, ( HB_U32 ) pCtx->Ecx, ( HB_U32 ) pCtx->Edx, ( HB_U32 ) pCtx->Esi, ( HB_U32 ) pCtx->Edi, ( HB_U32 ) pCtx->Ebp, ( HB_U32 ) pCtx->SegCs, ( HB_U32 ) pCtx->Eip, ( HB_U32 ) pCtx->SegSs, ( HB_U32 ) pCtx->Esp, ( HB_U32 ) pCtx->SegDs, ( HB_U32 ) pCtx->SegEs, ( HB_U32 ) pCtx->SegFs, ( HB_U32 ) pCtx->SegGs, ( HB_U32 ) pCtx->EFlags ); if( pExceptionInfo->ExceptionRecord->NumberParameters && pExceptionInfo->ExceptionRecord->NumberParameters < ( DWORD ) EXCEPTION_MAXIMUM_PARAMETERS ) { DWORD arg; hb_strncat( errmsg, " Exception Parameters:", errmsglen ); for( arg = 0; arg < pExceptionInfo->ExceptionRecord->NumberParameters; ++arg ) { hb_snprintf( buf, sizeof( buf ), " %08X", ( HB_U32 ) pExceptionInfo->ExceptionRecord->ExceptionInformation[ arg ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n", errmsglen ); } { unsigned char * pc; unsigned int * sc; unsigned int * ebp; unsigned int eip; unsigned int j; int i; hb_strncat( errmsg, " CS:EIP:", errmsglen ); pc = ( unsigned char * ) pCtx->Eip; for( i = 0; i < 16; i++ ) { /* TOFIX: Unsafe funcion. */ if( IsBadReadPtr( pc, 1 ) ) break; hb_snprintf( buf, sizeof( buf ), " %02X", ( int ) pc[ i ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n SS:ESP:", errmsglen ); sc = ( unsigned int * ) pCtx->Esp; for( i = 0; i < 16; i++ ) { /* TOFIX: Unsafe funcion. */ if( IsBadReadPtr( sc, 4 ) ) break; hb_snprintf( buf, sizeof( buf ), " %08X", sc[ i ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n\n", errmsglen ); hb_strncat( errmsg, " C stack:\n", errmsglen ); hb_strncat( errmsg, " EIP: EBP: Frame: OldEBP, RetAddr, Params...\n", errmsglen ); eip = pCtx->Eip; ebp = ( unsigned int * ) pCtx->Ebp; /* TOFIX: Unsafe funcion. */ if( ! IsBadWritePtr( ebp, 8 ) ) { for( i = 0; i < 20; i++ ) { /* TOFIX: Unsafe funcion. */ if( ( unsigned int ) ebp % 4 != 0 || IsBadWritePtr( ebp, 40 ) || ( unsigned int ) ebp >= ebp[ 0 ] ) break; hb_snprintf( buf, sizeof( buf ), " %08X %08X ", ( int ) eip, ( int ) ebp ); hb_strncat( errmsg, buf, errmsglen ); for( j = 0; j < 10 && ( unsigned int ) ( ebp + j ) < ebp[ 0 ]; j++ ) { hb_snprintf( buf, sizeof( buf ), " %08X", ebp[ j ] ); hb_strncat( errmsg, buf, errmsglen ); } hb_strncat( errmsg, "\n", errmsglen ); eip = ebp[ 1 ]; ebp = ( unsigned int * ) ebp[ 0 ]; } hb_strncat( errmsg, "\n", errmsglen ); } } } #endif { #if defined( HB_OS_WIN_CE ) HMODULE hToolhelp = GetModuleHandle( TEXT( "toolhelp.dll" ) ); #else /* NOTE: Several non-MS sources say that Win9x has these functions in tlhelp32.dll. Testing shows though, that in Win95, Win95b and Win98 they are in kernel32.dll, and tlhelp32.dll doesn't exist. [vszakats] */ HMODULE hToolhelp = GetModuleHandle( TEXT( "kernel32.dll" ) ); #endif if( hToolhelp ) { /* NOTE: Hack to force the ASCII versions of these types. [vszakats] */ #if ! defined( HB_OS_WIN_CE ) && defined( UNICODE ) #undef MODULEENTRY32 #undef LPMODULEENTRY32 #endif typedef HANDLE ( WINAPI * P_CTH32SSH )( DWORD, DWORD ); /* CreateToolhelp32Snapshot() */ typedef BOOL ( WINAPI * P_M32F )( HANDLE, LPMODULEENTRY32 ); /* Module32First() */ typedef BOOL ( WINAPI * P_M32N )( HANDLE, LPMODULEENTRY32 ); /* Module32Next() */ P_CTH32SSH pCreateToolhelp32Snapshot = ( P_CTH32SSH ) HB_WINAPI_GETPROCADDRESS( hToolhelp, "CreateToolhelp32Snapshot" ); P_M32F pModule32First = ( P_M32F ) HB_WINAPI_GETPROCADDRESS( hToolhelp, "Module32First" ); P_M32N pModule32Next = ( P_M32N ) HB_WINAPI_GETPROCADDRESS( hToolhelp, "Module32Next" ); if( pCreateToolhelp32Snapshot && pModule32First && pModule32Next ) { /* Take a snapshot of all modules in the specified process. */ HANDLE hModuleSnap = pCreateToolhelp32Snapshot( TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, GetCurrentProcessId() ); if( hModuleSnap != INVALID_HANDLE_VALUE ) { MODULEENTRY32 me32; /* Set the size of the structure before using it. */ me32.dwSize = sizeof( MODULEENTRY32 ); /* Retrieve information about the first module, and exit if unsuccessful */ if( pModule32First( hModuleSnap, &me32 ) ) { hb_strncat( errmsg, "\nModules:\n", errmsglen ); /* Now walk the module list of the process, and display information about each module */ do { char buf[ 256 ]; #if defined( HB_OS_WIN_64 ) /* TOFIX: me32.szExePath seemed trashed in some (standalone) tests. */ hb_snprintf( buf, sizeof( buf ), "%016" PFLL "X %016" PFLL "X %s\n", ( HB_PTRDIFF ) me32.modBaseAddr, ( HB_PTRDIFF ) me32.modBaseSize, me32.szExePath ); #else char szBuffer[ MAX_PATH ]; #if defined( HB_OS_WIN_CE ) hb_wcntombcpy( szBuffer, me32.szExePath, HB_SIZEOFARRAY( szBuffer ) - 1 ); #else hb_strncpy( szBuffer, me32.szExePath, HB_SIZEOFARRAY( szBuffer ) - 1 ); #endif hb_snprintf( buf, sizeof( buf ), "%08lX %08lX %s\n", ( HB_PTRDIFF ) me32.modBaseAddr, ( HB_PTRDIFF ) me32.modBaseSize, szBuffer ); #endif hb_strncat( errmsg, buf, errmsglen ); } while( pModule32Next( hModuleSnap, &me32 ) ); } /* Do not forget to clean up the snapshot object. */ CloseHandle( hModuleSnap ); } } } } hb_errInternalRaw( 6005, "Exception error:%s", errmsg, NULL ); return hb_cmdargCheck( "BATCH" ) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; }
/* * Retrieve information about the current table/driver. */ static HB_ERRCODE hb_delimInfo( DELIMAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem ) { HB_TRACE( HB_TR_DEBUG, ( "hb_delimInfo(%p,%hu,%p)", pArea, uiIndex, pItem ) ); switch( uiIndex ) { case DBI_CANPUTREC: hb_itemPutL( pItem, pArea->fTransRec ); break; case DBI_GETRECSIZE: hb_itemPutNL( pItem, pArea->uiRecordLen ); break; case DBI_GETDELIMITER: { char szDelim[ 2 ]; szDelim[ 0 ] = pArea->cDelim; szDelim[ 1 ] = '\0'; hb_itemPutC( pItem, szDelim ); break; } case DBI_SETDELIMITER: if( hb_itemType( pItem ) & HB_IT_STRING ) { const char * szDelim = hb_itemGetCPtr( pItem ); if( hb_stricmp( szDelim, "BLANK" ) == 0 ) { pArea->cDelim = '\0'; pArea->cSeparator = ' '; } #ifndef HB_CLP_STRICT else if( hb_stricmp( szDelim, "PIPE" ) == 0 ) { pArea->cDelim = '\0'; pArea->cSeparator = '|'; } else if( hb_stricmp( szDelim, "TAB" ) == 0 ) { pArea->cDelim = '\0'; pArea->cSeparator = '\t'; } else #else else if( *szDelim ) #endif { pArea->cDelim = *szDelim; } } /* * a small trick which allow to set character field delimiter and * field separator in COPY TO ... and APPEND FROM ... commands as * array. F.e.: * COPY TO test DELIMITED WITH ({"","|"}) */ #ifndef HB_CLP_STRICT else if( hb_itemType( pItem ) & HB_IT_ARRAY ) { char cSeparator; if( hb_arrayGetType( pItem, 1 ) & HB_IT_STRING ) pArea->cDelim = *hb_arrayGetCPtr( pItem, 1 ); cSeparator = *hb_arrayGetCPtr( pItem, 2 ); if( cSeparator ) pArea->cSeparator = cSeparator; } #endif break; case DBI_SEPARATOR: { char szSeparator[ 2 ]; const char * szNew = hb_itemGetCPtr( pItem ); szSeparator[ 0 ] = pArea->cSeparator; szSeparator[ 1 ] = '\0'; if( *szNew ) pArea->cSeparator = *szNew; hb_itemPutC( pItem, szSeparator ); break; } case DBI_FULLPATH: hb_itemPutC( pItem, pArea->szFileName); break; case DBI_FILEHANDLE: hb_itemPutNInt( pItem, ( HB_NHANDLE ) hb_fileHandle( pArea->pFile ) ); break; case DBI_SHARED: hb_itemPutL( pItem, pArea->fShared ); break; case DBI_ISREADONLY: hb_itemPutL( pItem, pArea->fReadonly ); break; case DBI_POSITIONED: hb_itemPutL( pItem, pArea->fPositioned ); break; case DBI_DB_VERSION: case DBI_RDD_VERSION: { char szBuf[ 64 ]; int iSub = hb_itemGetNI( pItem ); if( iSub == 1 ) hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d (%s)", 0, 1, "DELIM" ); else if( iSub == 2 ) hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d (%s:%d)", 0, 1, "DELIM", pArea->area.rddID ); else hb_snprintf( szBuf, sizeof( szBuf ), "%d.%d", 0, 1 ); hb_itemPutC( pItem, szBuf ); break; } default: return SUPER_INFO( &pArea->area, uiIndex, pItem ); }
static HB_BOOL hb_fsFindNextLow( PHB_FFIND ffind ) { HB_BOOL bFound; int iYear = 0; int iMonth = 0; int iDay = 0; int iHour = 0; int iMin = 0; int iSec = 0; int iMSec = 0; HB_FATTR raw_attr = 0, nAttr = 0; /* Set the default values in case some platforms don't support some of these, or they may fail on them. */ ffind->szName[ 0 ] = '\0'; ffind->size = 0; /* Do platform dependant first/next search */ hb_vmUnlock(); #if defined( HB_OS_DOS ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; /* Handling HB_FA_LABEL doesn't need any special tricks under the MS-DOS platform. */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; /* tzset(); */ #if defined( __WATCOMC__ ) bFound = ( _dos_findfirst( ffind->pszFileMask, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ), &info->entry ) == 0 ); #else bFound = ( findfirst( ffind->pszFileMask, &info->entry, ( HB_USHORT ) hb_fsAttrToRaw( ffind->attrmask ) ) == 0 ); #endif } else { #if defined( __WATCOMC__ ) bFound = ( _dos_findnext( &info->entry ) == 0 ); #else bFound = ( findnext( &info->entry ) == 0 ); #endif } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( ffind->szName, info->entry.ff_name, sizeof( ffind->szName ) - 1 ); ffind->size = info->entry.ff_fsize; raw_attr = info->entry.ff_attrib; { time_t ftime; struct tm * ft; struct stat sStat; stat( info->entry.ff_name, &sStat ); ftime = sStat.st_mtime; ft = localtime( &ftime ); iYear = ft->tm_year + 1900; iMonth = ft->tm_mon + 1; iDay = ft->tm_mday; iHour = ft->tm_hour; iMin = ft->tm_min; iSec = ft->tm_sec; } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_OS2 ) { #define HB_OS2_DIRCNT 16 PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; APIRET ret = NO_ERROR; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { ffind->bFirst = HB_FALSE; info->isWSeB = hb_isWSeB(); info->findSize = sizeof( FILEFINDBUF3L ); if( info->findSize & 0x07 ) info->findSize += 0x08 - ( info->findSize & 0x07 ); info->findSize *= HB_OS2_DIRCNT; if( info->findSize > 0xF000 ) info->findSize = 0xF000; info->findInitCnt = ! info->isWSeB ? info->findSize / 32 : HB_OS2_DIRCNT; info->hFindFile = HDIR_CREATE; info->findCount = info->findInitCnt; ret = DosAllocMem( &info->entry, info->findSize, OBJ_TILE | PAG_COMMIT | PAG_WRITE ); if( ret == NO_ERROR ) { ret = DosFindFirst( ( PCSZ ) ffind->pszFileMask, &info->hFindFile, ( ULONG ) hb_fsAttrToRaw( ffind->attrmask ), info->entry, info->findSize, &info->findCount, FIL_STANDARDL ); bFound = ret == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } else { info->entry = NULL; bFound = HB_FALSE; } } else if( info->findCount == 0 ) { info->findCount = info->findInitCnt; ret = DosFindNext( info->hFindFile, info->entry, info->findSize, &info->findCount ); bFound = ret == NO_ERROR && info->findCount > 0; if( bFound ) info->next = info->entry; } else bFound = HB_TRUE; if( bFound ) { ULONG oNextEntryOffset; if( info->isWSeB ) { PFILEFINDBUF3L pFFB = ( PFILEFINDBUF3L ) info->next; hb_strncpy( ffind->szName, pFFB->achName, sizeof( ffind->szName ) - 1 ); ffind->size = ( HB_FOFFSET ) pFFB->cbFile; raw_attr = pFFB->attrFile; iYear = pFFB->fdateLastWrite.year + 1980; iMonth = pFFB->fdateLastWrite.month; iDay = pFFB->fdateLastWrite.day; iHour = pFFB->ftimeLastWrite.hours; iMin = pFFB->ftimeLastWrite.minutes; iSec = pFFB->ftimeLastWrite.twosecs * 2; oNextEntryOffset = pFFB->oNextEntryOffset; } else { PFILEFINDBUF3 pFFB = ( PFILEFINDBUF3 ) info->next; hb_strncpy( ffind->szName, pFFB->achName, sizeof( ffind->szName ) - 1 ); ffind->size = ( HB_FOFFSET ) pFFB->cbFile; raw_attr = pFFB->attrFile; iYear = pFFB->fdateLastWrite.year + 1980; iMonth = pFFB->fdateLastWrite.month; iDay = pFFB->fdateLastWrite.day; iHour = pFFB->ftimeLastWrite.hours; iMin = pFFB->ftimeLastWrite.minutes; iSec = pFFB->ftimeLastWrite.twosecs * 2; oNextEntryOffset = pFFB->oNextEntryOffset; } if( oNextEntryOffset > 0 ) { info->next = ( char * ) info->next + oNextEntryOffset; info->findCount--; } else info->findCount = 0; } hb_fsSetError( ( HB_ERRCODE ) ret ); } #elif defined( HB_OS_WIN ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; bFound = HB_FALSE; #if ! defined( HB_OS_WIN_CE ) if( ( ffind->attrmask & HB_FA_LABEL ) != 0 && ! info->fLabelDone ) { TCHAR lpVolName[ HB_PATH_MAX ]; LPTSTR lpFileMask = NULL; char * mask = NULL; info->fLabelDone = HB_TRUE; if( ffind->pszFileMask && *ffind->pszFileMask ) { PHB_FNAME pFileName = hb_fsFNameSplit( ffind->pszFileMask ); if( pFileName->szName && pFileName->szName[ 0 ] ) mask = hb_strdup( pFileName->szName ); if( pFileName->szPath && pFileName->szPath[ 0 ] && ( pFileName->szPath[ 1 ] || pFileName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR ) ) lpFileMask = HB_CHARDUP( pFileName->szPath ); hb_xfree( pFileName ); } bFound = GetVolumeInformation( lpFileMask, lpVolName, HB_SIZEOFARRAY( lpVolName ), NULL, NULL, NULL, NULL, 0 ) != 0; if( bFound ) { HB_OSSTRDUP2( lpVolName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( mask && *mask && ! hb_strMatchFile( ffind->szName, mask ) ) { ffind->szName[ 0 ] = '\0'; bFound = HB_FALSE; } } if( lpFileMask ) hb_xfree( lpFileMask ); if( mask ) hb_xfree( mask ); } #endif if( ! bFound && ( ffind->attrmask & ( HB_FA_LABEL | HB_FA_HIDDEN | HB_FA_SYSTEM | HB_FA_DIRECTORY ) ) != HB_FA_LABEL ) { if( ffind->bFirst ) { LPTSTR lpFileMask = HB_CHARDUP( ffind->pszFileMask ); ffind->bFirst = HB_FALSE; info->dwAttr = ( DWORD ) hb_fsAttrToRaw( ffind->attrmask ); info->hFindFile = FindFirstFile( lpFileMask, &info->pFindFileData ); hb_xfree( lpFileMask ); if( ( info->hFindFile != INVALID_HANDLE_VALUE ) && _HB_WIN_MATCH() ) bFound = HB_TRUE; } if( ! bFound && info->hFindFile != INVALID_HANDLE_VALUE ) { while( FindNextFile( info->hFindFile, &info->pFindFileData ) ) { if( _HB_WIN_MATCH() ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { HB_OSSTRDUP2( info->pFindFileData.cFileName, ffind->szName, sizeof( ffind->szName ) - 1 ); if( info->pFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ffind->size = 0; else { #if defined( __XCC__ ) || ( defined( __POCC__ ) && __POCC__ >= 500 ) /* NOTE: PellesC 5.00.1 will go into an infinite loop if we don't split this into two operations. [vszakats] */ ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow; ffind->size += ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32; #else ffind->size = ( HB_FOFFSET ) info->pFindFileData.nFileSizeLow + ( ( HB_FOFFSET ) info->pFindFileData.nFileSizeHigh << 32 ); #endif } raw_attr = ( HB_FATTR ) info->pFindFileData.dwFileAttributes; /* NOTE: One of these may fail when searching on an UNC path, I don't know yet what's the reason. [vszakats] */ { FILETIME ft; SYSTEMTIME time; if( FileTimeToLocalFileTime( &info->pFindFileData.ftLastWriteTime, &ft ) && FileTimeToSystemTime( &ft, &time ) ) { iYear = time.wYear; iMonth = time.wMonth; iDay = time.wDay; iHour = time.wHour; iMin = time.wMinute; iSec = time.wSecond; iMSec = time.wMilliseconds; } } } } hb_fsSetIOError( bFound, 0 ); } #elif defined( HB_OS_UNIX ) { PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info; char dirname[ HB_PATH_MAX ]; bFound = HB_FALSE; /* TODO: HB_FA_LABEL handling */ if( ffind->bFirst ) { char * pos; ffind->bFirst = HB_FALSE; hb_strncpy( dirname, ffind->pszFileMask, sizeof( dirname ) - 1 ); pos = strrchr( dirname, HB_OS_PATH_DELIM_CHR ); if( pos ) { hb_strncpy( info->pattern, pos + 1, sizeof( info->pattern ) - 1 ); *( pos + 1 ) = '\0'; } else { hb_strncpy( info->pattern, dirname, sizeof( info->pattern ) - 1 ); dirname[ 0 ] = '.'; dirname[ 1 ] = HB_OS_PATH_DELIM_CHR; dirname[ 2 ] = '\0'; } /* tzset(); */ info->dir = opendir( dirname ); hb_strncpy( info->path, dirname, sizeof( info->path ) - 1 ); } if( info->dir && info->pattern[ 0 ] != '\0' ) { while( ( info->entry = readdir( info->dir ) ) != NULL ) { if( hb_strMatchFile( info->entry->d_name, info->pattern ) ) { bFound = HB_TRUE; break; } } } /* Fill Harbour found file info */ if( bFound ) { hb_strncpy( dirname, info->path, sizeof( dirname ) - 1 ); hb_strncat( dirname, info->entry->d_name, sizeof( dirname ) - 1 ); { time_t ftime; struct tm lt; #if defined( HB_USE_LARGEFILE64 ) struct stat64 sStat, sStatL; if( lstat64( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) && ( ffind->attrmask & HB_FA_LINK ) == 0 ) { if( stat64( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #else struct stat sStat, sStatL; if( lstat( dirname, &sStat ) == 0 ) { if( S_ISLNK( sStat.st_mode ) && ( ffind->attrmask & HB_FA_LINK ) == 0 ) { if( stat( dirname, &sStatL ) == 0 ) memcpy( &sStat, &sStatL, sizeof( sStat ) ); nAttr |= HB_FA_LINK; } #endif hb_strncpy( ffind->szName, info->entry->d_name, sizeof( ffind->szName ) - 1 ); ffind->size = sStat.st_size; raw_attr = sStat.st_mode; ftime = sStat.st_mtime; # if defined( HB_HAS_LOCALTIME_R ) localtime_r( &ftime, < ); # else lt = *localtime( &ftime ); # endif iYear = lt.tm_year + 1900; iMonth = lt.tm_mon + 1; iDay = lt.tm_mday; iHour = lt.tm_hour; iMin = lt.tm_min; iSec = lt.tm_sec; # if defined( HB_OS_LINUX ) && \ defined( __GLIBC__ ) && defined( __GLIBC_MINOR__ ) && \ ( __GLIBC__ > 2 || ( __GLIBC__ == 2 && __GLIBC_MINOR__ >= 6 ) ) # if defined( _BSD_SOURCE ) || defined( _SVID_SOURCE ) || \ ( __GLIBC_MINOR__ >= 12 && \ ( ( defined( _POSIX_C_SOURCE ) || _POSIX_C_SOURCE >= 200809L ) || \ ( defined( _XOPEN_SOURCE ) || _XOPEN_SOURCE >= 700 ) ) ) iMSec = sStat.st_mtim.tv_nsec / 1000000; # else iMSec = sStat.st_mtimensec / 1000000; # endif # endif } else bFound = HB_FALSE; } } hb_fsSetIOError( bFound, 0 ); } #else { int iTODO; /* TODO: for given platform */ /* HB_SYMBOL_UNUSED( ffind ); */ HB_SYMBOL_UNUSED( iYear ); HB_SYMBOL_UNUSED( iMonth ); HB_SYMBOL_UNUSED( iDay ); HB_SYMBOL_UNUSED( iHour ); HB_SYMBOL_UNUSED( iMin ); HB_SYMBOL_UNUSED( iSec ); HB_SYMBOL_UNUSED( iMSec ); HB_SYMBOL_UNUSED( raw_attr ); bFound = HB_FALSE; hb_fsSetIOError( bFound, 0 ); } #endif /* Fill common Harbour found file info */ if( bFound ) { /* Do the conversions common for all platforms */ ffind->szName[ sizeof( ffind->szName ) - 1 ] = '\0'; #if ! defined( HB_OS_WIN ) /* Convert from OS codepage */ { char * pszFree = NULL; HB_SIZE nSize = sizeof( ffind->szName ); const char * pszResult = hb_osDecodeCP( ffind->szName, &pszFree, &nSize ); if( pszFree ) { hb_strncpy( ffind->szName, pszResult, sizeof( ffind->szName ) - 1 ); hb_xfree( pszFree ); } } #endif ffind->attr = hb_fsAttrFromRaw( raw_attr ) | nAttr; ffind->lDate = hb_dateEncode( iYear, iMonth, iDay ); ffind->lTime = hb_timeEncode( iHour, iMin, iSec, iMSec ); hb_dateStrPut( ffind->szDate, iYear, iMonth, iDay ); ffind->szDate[ 8 ] = '\0'; hb_snprintf( ffind->szTime, sizeof( ffind->szTime ), "%02d:%02d:%02d", iHour, iMin, iSec ); } hb_vmLock(); return bFound; } PHB_FFIND hb_fsFindFirst( const char * pszFileMask, HB_FATTR attrmask ) { PHB_FFIND ffind = ( PHB_FFIND ) hb_xgrabz( sizeof( HB_FFIND ) ); /* Allocate platform dependent file find info storage */ ffind->info = ( void * ) hb_xgrabz( sizeof( HB_FFIND_INFO ) ); /* Store search parameters */ #if defined( HB_OS_WIN ) ffind->pszFileMask = pszFileMask; #else /* Convert to OS codepage */ ffind->pszFileMask = hb_fsNameConv( pszFileMask, &ffind->pszFree ); #endif ffind->attrmask = attrmask; ffind->bFirst = HB_TRUE; /* Find first/next matching file */ if( hb_fsFindNext( ffind ) ) return ffind; /* If no file found at all, free stuff allocated so far and return NULL. */ hb_fsFindClose( ffind ); return NULL; }
static void _hb_jsonEncode( PHB_ITEM pValue, PHB_JSON_ENCODE_CTX pCtx, HB_SIZE nLevel, HB_BOOL fEOL ) { /* Protection against recursive structures */ if( ( HB_IS_ARRAY( pValue ) || HB_IS_HASH( pValue ) ) && hb_itemSize( pValue ) > 0 ) { void * id = HB_IS_HASH( pValue ) ? hb_hashId( pValue ) : hb_arrayId( pValue ); HB_SIZE nIndex; for( nIndex = 0; nIndex < nLevel; nIndex++ ) { if( pCtx->pId[ nIndex ] == id ) { if( ! fEOL && pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "null", 4 ); return; } } if( nLevel >= pCtx->nAllocId ) { pCtx->nAllocId += 8; pCtx->pId = ( void ** ) hb_xrealloc( pCtx->pId, sizeof( void * ) * pCtx->nAllocId ); } pCtx->pId[ nLevel ] = id; } if( fEOL ) { --pCtx->pHead; _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); } if( HB_IS_STRING( pValue ) ) { const char * szString = hb_itemGetCPtr( pValue ); HB_SIZE nPos, nPos2, nLen = hb_itemGetCLen( pValue ); _hb_jsonCtxAdd( pCtx, "\"", 1 ); nPos = 0; while( nPos < nLen ) { nPos2 = nPos; while( *( ( const unsigned char * ) szString + nPos2 ) >= ' ' && szString[ nPos2 ] != '\\' && szString[ nPos2 ] != '\"' ) nPos2++; if( nPos2 > nPos ) { _hb_jsonCtxAdd( pCtx, szString + nPos, nPos2 - nPos ); nPos = nPos2; continue; } switch( szString[ nPos ] ) { case '\\': _hb_jsonCtxAdd( pCtx, "\\\\", 2 ); break; case '\"': _hb_jsonCtxAdd( pCtx, "\\\"", 2 ); break; case '\b': _hb_jsonCtxAdd( pCtx, "\\b", 2 ); break; case '\f': _hb_jsonCtxAdd( pCtx, "\\f", 2 ); break; case '\n': _hb_jsonCtxAdd( pCtx, "\\n", 2 ); break; case '\r': _hb_jsonCtxAdd( pCtx, "\\r", 2 ); break; case '\t': _hb_jsonCtxAdd( pCtx, "\\t", 2 ); break; default: { char buf[ 8 ]; hb_snprintf( buf, sizeof( buf ), "\\u00%02X", ( unsigned char ) szString[ nPos ] ); _hb_jsonCtxAdd( pCtx, buf, 6 ); break; } } nPos++; } _hb_jsonCtxAdd( pCtx, "\"", 1 ); } else if( HB_IS_NUMINT( pValue ) ) { char buf[ 32 ]; hb_snprintf( buf, sizeof( buf ), "%" PFHL "d", hb_itemGetNInt( pValue ) ); _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) ); } else if( HB_IS_NUMERIC( pValue ) ) { char buf[ 64 ]; int iDec; double dblValue = hb_itemGetNDDec( pValue, &iDec ); hb_snprintf( buf, sizeof( buf ), "%.*f", iDec, dblValue ); _hb_jsonCtxAdd( pCtx, buf, strlen( buf ) ); } else if( HB_IS_NIL( pValue ) ) { _hb_jsonCtxAdd( pCtx, "null", 4 ); } else if( HB_IS_LOGICAL( pValue ) ) { if( hb_itemGetL( pValue ) ) _hb_jsonCtxAdd( pCtx, "true", 4 ); else _hb_jsonCtxAdd( pCtx, "false", 5 ); } else if( HB_IS_DATE( pValue ) ) { char szBuffer[ 10 ]; hb_itemGetDS( pValue, szBuffer + 1 ); szBuffer[ 0 ] = '\"'; szBuffer[ 9 ] = '\"'; _hb_jsonCtxAdd( pCtx, szBuffer, 10 ); } else if( HB_IS_TIMESTAMP( pValue ) ) { char szBuffer[ 19 ]; hb_itemGetTS( pValue, szBuffer + 1 ); szBuffer[ 0 ] = '\"'; szBuffer[ 18 ] = '\"'; _hb_jsonCtxAdd( pCtx, szBuffer, 19 ); } else if( HB_IS_ARRAY( pValue ) ) { HB_SIZE nLen = hb_itemSize( pValue ); if( nLen ) { HB_SIZE nIndex; if( pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "[", 1 ); for( nIndex = 1; nIndex <= nLen; nIndex++ ) { PHB_ITEM pItem = hb_arrayGetItemPtr( pValue, nIndex ); if( nIndex > 1 ) _hb_jsonCtxAdd( pCtx, ",", 1 ); if( pCtx->fHuman ) _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); if( pCtx->fHuman && ! ( ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0 ) ) _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE ); _hb_jsonEncode( pItem, pCtx, nLevel + 1, HB_FALSE ); } if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); } _hb_jsonCtxAdd( pCtx, "]", 1 ); } else _hb_jsonCtxAdd( pCtx, "[]", 2 ); } else if( HB_IS_HASH( pValue ) ) { HB_SIZE nLen = hb_hashLen( pValue ); if( nLen ) { HB_SIZE nIndex; if( pCtx->fHuman ) _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); _hb_jsonCtxAdd( pCtx, "{", 1 ); for( nIndex = 1; nIndex <= nLen; nIndex++ ) { PHB_ITEM pKey = hb_hashGetKeyAt( pValue, nIndex ); if( HB_IS_STRING( pKey ) ) { PHB_ITEM pItem = hb_hashGetValueAt( pValue, nIndex ); HB_BOOL fEOL = HB_FALSE; if( nIndex > 1 ) _hb_jsonCtxAdd( pCtx, ",", 1 ); if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, ( nLevel + 1 ) * INDENT_SIZE ); } _hb_jsonEncode( pKey, pCtx, nLevel + 1, HB_FALSE ); if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, ": ", 2 ); fEOL = ( HB_IS_ARRAY( pItem ) || HB_IS_HASH( pItem ) ) && hb_itemSize( pItem ) > 0; } else _hb_jsonCtxAdd( pCtx, ":", 1 ); _hb_jsonEncode( pItem, pCtx, nLevel + 1, fEOL ); } } if( pCtx->fHuman ) { _hb_jsonCtxAdd( pCtx, pCtx->szEol, pCtx->iEolLen ); _hb_jsonCtxAddIndent( pCtx, nLevel * INDENT_SIZE ); } _hb_jsonCtxAdd( pCtx, "}", 1 ); } else _hb_jsonCtxAdd( pCtx, "{}", 2 ); } else { /* All unsupported types are replacd by null */ _hb_jsonCtxAdd( pCtx, "null", 4 ); } }