From 4acc58ca6a4edc3b88c9673de3ffba7a1940eb48 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 13 Nov 2012 18:00:52 +0000 Subject: [PATCH] 2012-11-13 19:00 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbfimage/fi_wrp.c * contrib/hbfimage/tests/fitest.prg ! FI_SETOUTPUTMESSAGE(): fixed/implemented error callback. In previous version it was not working. Now the function accepts both function pointer and codeblock. * adapted/fixed error callback setting in test + added test for error callback * contrib/xhb/hbcompat.ch * formatting --- harbour/ChangeLog | 12 ++ harbour/contrib/hbfimage/fi_wrp.c | 74 +++++++--- harbour/contrib/hbfimage/tests/fitest.prg | 17 ++- harbour/contrib/xhb/hbcompat.ch | 170 +++++++++++----------- 4 files changed, 156 insertions(+), 117 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5253d65c15..85ba36bc7b 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,18 @@ The license applies to all entries newer than 2009-04-28. */ +2012-11-13 19:00 UTC+0100 Viktor Szakats (harbour syenar.net) + * contrib/hbfimage/fi_wrp.c + * contrib/hbfimage/tests/fitest.prg + ! FI_SETOUTPUTMESSAGE(): fixed/implemented error callback. + In previous version it was not working. Now the function + accepts both function pointer and codeblock. + * adapted/fixed error callback setting in test + + added test for error callback + + * contrib/xhb/hbcompat.ch + * formatting + 2012-11-13 17:59 UTC+0100 Viktor Szakats (harbour syenar.net) * INSTALL * minor tweak in hbmk2 examples to better emphasis .hbc files diff --git a/harbour/contrib/hbfimage/fi_wrp.c b/harbour/contrib/hbfimage/fi_wrp.c index b92f9edcb8..981d3f5c6e 100644 --- a/harbour/contrib/hbfimage/fi_wrp.c +++ b/harbour/contrib/hbfimage/fi_wrp.c @@ -7,6 +7,7 @@ * FreeImage graphic library low level (client api) interface code. * * Copyright 2005 Francesco Saverio Giudice + * Copyright 2012 Viktor Szakats (harbour syenar.net) * www - http://www.xharbour.org http://harbour-project.org * * This program is free software; you can redistribute it and/or modify @@ -55,6 +56,7 @@ #include "hbapi.h" #include "hbapiitm.h" #include "hbapierr.h" +#include "hbstack.h" #include "hbvm.h" #if defined( HB_OS_WIN ) @@ -69,6 +71,33 @@ #define hb_fi_retl( x ) hb_retl( x ? HB_TRUE : HB_FALSE ) #define hb_fi_parl( x ) ( hb_parl( x ) ? TRUE : FALSE ) +/* Error callback */ + +typedef struct +{ + PHB_ITEM pErrorCallback; +} HB_FI_ERROR; + +static void hb_fi_error_init( void * cargo ) +{ + HB_FI_ERROR * pError = ( HB_FI_ERROR * ) cargo; + + pError->pErrorCallback = NULL; +} + +static void hb_fi_error_release( void * cargo ) +{ + HB_FI_ERROR * pError = ( HB_FI_ERROR * ) cargo; + + if( pError->pErrorCallback ) + hb_itemRelease( pError->pErrorCallback ); +} + +static HB_TSD_NEW( s_fi_error, + sizeof( HB_FI_ERROR ), + hb_fi_error_init, + hb_fi_error_release ); + /* HB_FIBITMAP API */ typedef struct @@ -189,9 +218,6 @@ static void hb_FIMULTIBITMAP_ret( FIMULTIBITMAP * bitmap ) /* ************************* WRAPPED FUNCTIONS ****************************** */ -/* static for error handler (see below FI_SETOUTPUTMESSAGE ) */ -static void * s_pErrorHandler = NULL; - /* Init / Error routines */ /* --------------------- */ @@ -224,45 +250,45 @@ HB_FUNC( FI_GETCOPYRIGHTMESSAGE ) /* DLL_API void DLL_CALLCONV FreeImage_OutputMessageProc(int fif, const char *fmt, ...); */ /* typedef void (*FreeImage_OutputMessageFunction)(FREE_IMAGE_FORMAT fif, const char *msg); */ -/* DLL_API void DLL_CALLCONV FreeImage_SetOutputMessage(FreeImage_OutputMessageFunction omf); */ -/* implementation: void FreeImage_SetOutputMessage( pFunctionPointer ) */ - -/** - @param fif Format / Plugin responsible for the error - @param message Error message - */ static void FreeImageErrorHandler( FREE_IMAGE_FORMAT fif, const char * message ) { - if( s_pErrorHandler ) + HB_FI_ERROR * pError = ( HB_FI_ERROR * ) hb_stackGetTSD( &s_fi_error ); + + if( pError ) { - if( hb_vmRequestReenter() ) + PHB_ITEM pErrorCallback = pError->pErrorCallback; + + if( pErrorCallback && hb_vmRequestReenter() ) { const char * format = FreeImage_GetFormatFromFIF( fif ); - /* launch error function at prg level */ - hb_vmPushSymbol( ( PHB_SYMB ) s_pErrorHandler ); - hb_vmPushNil(); + hb_vmPushEvalSym(); + hb_vmPush( pErrorCallback ); hb_vmPushString( format, strlen( format ) ); hb_vmPushString( message, strlen( message ) ); - hb_vmDo( 2 ); + hb_vmSend( 2 ); hb_vmRequestRestore(); } - else - hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, "FreeImageErrorHandler", HB_ERR_ARGS_BASEPARAMS ); } } +/* DLL_API void DLL_CALLCONV FreeImage_SetOutputMessage(FreeImage_OutputMessageFunction omf); */ +/* implementation: void FreeImage_SetOutputMessage( pFunctionPointer ) */ HB_FUNC( FI_SETOUTPUTMESSAGE ) { - s_pErrorHandler = NULL; - FreeImage_SetOutputMessage( FreeImageErrorHandler ); + if( HB_ISBLOCK( 1 ) || HB_ISSYMBOL( 1 ) ) + { + HB_FI_ERROR * pError = ( HB_FI_ERROR * ) hb_stackGetTSD( &s_fi_error ); - if( HB_ISPOINTER( 1 ) ) - /* Set the pointer */ - s_pErrorHandler = hb_parptr( 1 ); - else if( ! HB_ISNIL( 1 ) ) + if( pError->pErrorCallback ) + hb_itemRelease( pError->pErrorCallback ); + pError->pErrorCallback = hb_itemNew( hb_param( 1, HB_IT_BLOCK | HB_IT_SYMBOL ) ); + + FreeImage_SetOutputMessage( FreeImageErrorHandler ); + } + else hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } diff --git a/harbour/contrib/hbfimage/tests/fitest.prg b/harbour/contrib/hbfimage/tests/fitest.prg index 6d0a030fda..006e8a5baf 100644 --- a/harbour/contrib/hbfimage/tests/fitest.prg +++ b/harbour/contrib/hbfimage/tests/fitest.prg @@ -13,6 +13,7 @@ #include "freeimag.ch" #include "fileio.ch" +#include "simpleio.ch" #define IMAGES_IN "" #define IMAGES_OUT "imgs_out" + hb_ps() @@ -47,15 +48,15 @@ PROCEDURE Main() // - ? "Set Error Message:", fi_SetOutputMessage( fi_Error() ) -#if 0 - ? "Set Error Message:", fi_SetOutputMessage( NIL ) -#endif - ? "Version :", fi_GetVersion() ? "Copyright :", fi_GetCopyrightMessage() ? "File type :", fi_GetFileType( IMAGES_IN + "sample1.jpg" ) + ? "Set Error Message (symbol):", fi_SetOutputMessage( @fi_Error() ) + im := fi_Load( FIF_JPEG, IMAGES_IN + "nothere.jpg", JPEG_DEFAULT ) + ? "Set Error Message (block):", fi_SetOutputMessage( {| cFormat, cMessage | fi_Error( cFormat, cMessage ) } ) + im := fi_Load( FIF_JPEG, IMAGES_IN + "nothere.jpg", JPEG_DEFAULT ) + ? "Load JPEG directly from file" im := fi_Load( FIF_JPEG, IMAGES_IN + "sample1.jpg", JPEG_DEFAULT ) @@ -208,9 +209,9 @@ PROCEDURE Main() PROCEDURE fi_Error( cFormat, cMessage ) - ? "ERROR!..." - ? "Format : ", cFormat - ? "Message : ", cMessage + ? "ERROR!.." + ? "Format : ", cFormat + ? "Message: ", cMessage RETURN diff --git a/harbour/contrib/xhb/hbcompat.ch b/harbour/contrib/xhb/hbcompat.ch index fae51ab54a..892201f13b 100644 --- a/harbour/contrib/xhb/hbcompat.ch +++ b/harbour/contrib/xhb/hbcompat.ch @@ -64,81 +64,81 @@ #define __PLATFORM__LINUX #endif - #xtranslate hb_ScrMaxRow() => gtInfo( HB_GTI_SCREENHEIGHT ) - #xtranslate hb_ScrMaxCol() => gtInfo( HB_GTI_SCREENWIDTH ) - #xtranslate MaxRow( .T. ) => gtInfo( HB_GTI_SCREENHEIGHT ) - #xtranslate MaxCol( .T. ) => gtInfo( HB_GTI_SCREENWIDTH ) - #xtranslate hb_keyNext( [] ) => NextKey( ) + #xtranslate hb_gtInfo( HB_GTI_INKEYREAD [, ] ) => SetInkeyBeforeBlock( [] ) <-x-> + #xtranslate hb_gtInfo( HB_GTI_INKEYFILTER [, ] ) => SetInkeyAfterBlock( [] ) <-x-> - #xtranslate hb_osNewLine() => hb_eol() - #xtranslate hb_osPathSeparator() => hb_ps() + #xtranslate hb_ScrMaxRow() => gtInfo( HB_GTI_SCREENHEIGHT ) + #xtranslate hb_ScrMaxCol() => gtInfo( HB_GTI_SCREENWIDTH ) + #xtranslate MaxRow( .T. ) => gtInfo( HB_GTI_SCREENHEIGHT ) + #xtranslate MaxCol( .T. ) => gtInfo( HB_GTI_SCREENWIDTH ) + #xtranslate hb_keyNext( [] ) => NextKey( ) - #xtranslate hb_dbPack() => __dbPack() - #xtranslate hb_dbZap() => __dbZap() - #xtranslate hb_dbDrop( [] ) => dbDrop( ) - #xtranslate hb_dbExists( [] ) => dbExists( ) - #xtranslate hb_FieldLen( [] ) => FieldLen( ) - #xtranslate hb_FieldDec( [] ) => FieldDec( ) - #xtranslate hb_FieldType( [] ) => FieldType( ) + #xtranslate hb_osNewLine() => hb_eol() + #xtranslate hb_osPathSeparator() => hb_ps() - #xtranslate hb_gtInfo( HB_GTI_INKEYREAD [, ] ) => SetInkeyBeforeBlock( [] ) <-x-> - #xtranslate hb_gtInfo( HB_GTI_INKEYFILTER [, ] ) => SetInkeyAfterBlock( [] ) <-x-> + #xtranslate hb_dbPack() => __dbPack() + #xtranslate hb_dbZap() => __dbZap() + #xtranslate hb_dbDrop( [] ) => dbDrop( ) + #xtranslate hb_dbExists( [] ) => dbExists( ) + #xtranslate hb_FieldLen( [] ) => FieldLen( ) + #xtranslate hb_FieldDec( [] ) => FieldDec( ) + #xtranslate hb_FieldType( [] ) => FieldType( ) - #xtranslate hb_processOpen( [] ) => hb_OpenProcess( ) - #xtranslate hb_processClose( [] ) => hb_CloseProcess( ) + #xtranslate hb_processOpen( [] ) => hb_OpenProcess( ) + #xtranslate hb_processClose( [] ) => hb_CloseProcess( ) - #xtranslate hb_IsRegex( [] ) => hb_IsRegexString( ) - #xtranslate hb_MethodName( [] ) => MethodName( ) - #xtranslate hb_libLoad( [] ) => LibLoad( ) - #xtranslate hb_libFree( [] ) => LibFree( ) - #xtranslate hb_Adler32( [] ) => hb_Checksum( ) - #xtranslate hb_keySetLast( [] ) => hb_SetLastKey( ) - #xtranslate hb_CStr( [] ) => CStr( ) - #xtranslate hb_ValToExp( [] ) => ValToPrgExp( ) - #xtranslate hb_rddInfo( [] ) => rddInfo( ) - #xtranslate hb_idleSleep( [] ) => SecondsSleep( ) - #xtranslate hb_UserName() => NetName( 1 ) - #xtranslate hb_FSize( ) => FileSize( ) - #xtranslate hb_WildMatch( [] ) => WildMatch( ) - #xtranslate hb_bitTest( [] ) => hb_bitIsSet( ) - #xtranslate hb_Deserialize( ) => hb_DeserialNext( ) + #xtranslate hb_IsRegex( [] ) => hb_IsRegexString( ) + #xtranslate hb_MethodName( [] ) => MethodName( ) + #xtranslate hb_libLoad( [] ) => LibLoad( ) + #xtranslate hb_libFree( [] ) => LibFree( ) + #xtranslate hb_Adler32( [] ) => hb_Checksum( ) + #xtranslate hb_keySetLast( [] ) => hb_SetLastKey( ) + #xtranslate hb_CStr( [] ) => CStr( ) + #xtranslate hb_ValToExp( [] ) => ValToPrgExp( ) + #xtranslate hb_rddInfo( [] ) => rddInfo( ) + #xtranslate hb_idleSleep( [] ) => SecondsSleep( ) + #xtranslate hb_UserName() => NetName( 1 ) + #xtranslate hb_FSize( ) => FileSize( ) + #xtranslate hb_WildMatch( [] ) => WildMatch( ) + #xtranslate hb_bitTest( [] ) => hb_bitIsSet( ) + #xtranslate hb_Deserialize( ) => hb_DeserialNext( ) - #xtranslate hb_HexToNum( [] ) => HexToNum( ) - #xtranslate hb_NumToHex( [] ) => NumToHex( ) - #xtranslate hb_HexToStr( [] ) => HexToStr( ) - #xtranslate hb_StrToHex( [] ) => StrToHex( ) + #xtranslate hb_HexToNum( [] ) => HexToNum( ) + #xtranslate hb_NumToHex( [] ) => NumToHex( ) + #xtranslate hb_HexToStr( [] ) => HexToStr( ) + #xtranslate hb_StrToHex( [] ) => StrToHex( ) - #xtranslate hb_AScan( [] ) => AScan( ) - #xtranslate hb_RAScan( [] ) => RAScan( ) - #xtranslate hb_AIns( [] ) => AIns( ) - #xtranslate hb_ADel( [] ) => ADel( ) - #xtranslate hb_At( [] ) => At( ) + #xtranslate hb_AScan( [] ) => AScan( ) + #xtranslate hb_RAScan( [] ) => RAScan( ) + #xtranslate hb_AIns( [] ) => AIns( ) + #xtranslate hb_ADel( [] ) => ADel( ) + #xtranslate hb_At( [] ) => At( ) - #xtranslate hb_DateTime( [] ) => DateTime( ) - #xtranslate hb_Hour( [] ) => Hour( ) - #xtranslate hb_Minute( [] ) => Minute( ) - #xtranslate hb_TToS( [] ) => TToS( ) - #xtranslate hb_SToT( [] ) => SToT( ) - #xtranslate hb_TToC( [] ) => TToC( ) - #xtranslate hb_CToT( [] ) => CToT( ) + #xtranslate hb_DateTime( [] ) => DateTime( ) + #xtranslate hb_Hour( [] ) => Hour( ) + #xtranslate hb_Minute( [] ) => Minute( ) + #xtranslate hb_TToS( [] ) => TToS( ) + #xtranslate hb_SToT( [] ) => SToT( ) + #xtranslate hb_TToC( [] ) => TToC( ) + #xtranslate hb_CToT( [] ) => CToT( ) - #xtranslate hb_GetEnv( [] ) => GetEnv( ) - #xtranslate hb_SetKey( [] ) => SetKey( ) + #xtranslate hb_GetEnv( [] ) => GetEnv( ) + #xtranslate hb_SetKey( [] ) => SetKey( ) - #xtranslate hb_i18n_gettext( ) => i18n( ) + #xtranslate hb_i18n_gettext( ) => i18n( ) - #xtranslate hb_cdpSelect( [] ) => hb_SetCodepage( ) + #xtranslate hb_cdpSelect( [] ) => hb_SetCodepage( ) - #xtranslate hb_argv( [] ) => hb_CmdArgArgV( ) + #xtranslate hb_argv( [] ) => hb_CmdArgArgV( ) - #xtranslate hb_iniSetComment( [] ) => hb_SetIniComment( ) - #xtranslate hb_iniRead( [] ) => hb_ReadIni( ) - #xtranslate hb_iniWrite( [] ) => hb_WriteIni( ) + #xtranslate hb_iniSetComment( [] ) => hb_SetIniComment( ) + #xtranslate hb_iniRead( [] ) => hb_ReadIni( ) + #xtranslate hb_iniWrite( [] ) => hb_WriteIni( ) - #xtranslate hb_DisableWaitLocks( [] ) => DisableWaitLocks( ) + #xtranslate hb_DisableWaitLocks( [] ) => DisableWaitLocks( ) - #xtranslate hb_gtLock() => hbConsoleLock() - #xtranslate hb_gtUnLock() => hbConsoleUnLock() + #xtranslate hb_gtLock() => hbConsoleLock() + #xtranslate hb_gtUnLock() => hbConsoleUnLock() /* MT functions */ #xtranslate hb_mtvm() => hb_MultiThread() @@ -171,31 +171,31 @@ hb_MutexTimeOutLock( , ) ) ) /* Hash item functions */ - #xtranslate hb_Hash( [] ) => Hash( ) - #xtranslate hb_HHasKey( [] ) => HHasKey( ) - #xtranslate hb_HPos( [] ) => HGetPos( ) - #xtranslate hb_HGet( [] ) => HGet( ) - #xtranslate hb_HSet( [] ) => HSet( ) - #xtranslate hb_HDel( [] ) => HDel( ) - #xtranslate hb_HKeyAt( [] ) => HGetKeyAt( ) - #xtranslate hb_HValueAt( [] ) => HGetValueAt( ) - #xtranslate hb_HValueAt( [] ) => HSetValueAt( ) - #xtranslate hb_HPairAt( [] ) => HGetPairAt( ) - #xtranslate hb_HDelAt( [] ) => HDelAt( ) - #xtranslate hb_HKeys( [] ) => HGetKeys( ) - #xtranslate hb_HValues( [] ) => HGetValues( ) - #xtranslate hb_HFill( [] ) => HFill( ) - #xtranslate hb_HClone( [] ) => HClone( ) - #xtranslate hb_HCopy( [] ) => HCopy( ) - #xtranslate hb_HMerge( [] ) => HMerge( ) - #xtranslate hb_HEval( [] ) => HEval( ) - #xtranslate hb_HScan( [] ) => HScan( ) - #xtranslate hb_HSetCaseMatch( [] ) => HSetCaseMatch( ) - #xtranslate hb_HCaseMatch( [] ) => HGetCaseMatch( ) - #xtranslate hb_HSetAutoAdd( [] ) => HSetAutoAdd( ) - #xtranslate hb_HAutoAdd( [] ) => HGetAutoAdd( ) - #xtranslate hb_HAllocate( [] ) => HAllocate( ) - #xtranslate hb_HDefault( [] ) => HDefault( ) + #xtranslate hb_Hash( [] ) => Hash( ) + #xtranslate hb_HHasKey( [] ) => HHasKey( ) + #xtranslate hb_HPos( [] ) => HGetPos( ) + #xtranslate hb_HGet( [] ) => HGet( ) + #xtranslate hb_HSet( [] ) => HSet( ) + #xtranslate hb_HDel( [] ) => HDel( ) + #xtranslate hb_HKeyAt( [] ) => HGetKeyAt( ) + #xtranslate hb_HValueAt( [] ) => HGetValueAt( ) + #xtranslate hb_HValueAt( [] ) => HSetValueAt( ) + #xtranslate hb_HPairAt( [] ) => HGetPairAt( ) + #xtranslate hb_HDelAt( [] ) => HDelAt( ) + #xtranslate hb_HKeys( [] ) => HGetKeys( ) + #xtranslate hb_HValues( [] ) => HGetValues( ) + #xtranslate hb_HFill( [] ) => HFill( ) + #xtranslate hb_HClone( [] ) => HClone( ) + #xtranslate hb_HCopy( [] ) => HCopy( ) + #xtranslate hb_HMerge( [] ) => HMerge( ) + #xtranslate hb_HEval( [] ) => HEval( ) + #xtranslate hb_HScan( [] ) => HScan( ) + #xtranslate hb_HSetCaseMatch( [] ) => HSetCaseMatch( ) + #xtranslate hb_HCaseMatch( [] ) => HGetCaseMatch( ) + #xtranslate hb_HSetAutoAdd( [] ) => HSetAutoAdd( ) + #xtranslate hb_HAutoAdd( [] ) => HGetAutoAdd( ) + #xtranslate hb_HAllocate( [] ) => HAllocate( ) + #xtranslate hb_HDefault( [] ) => HDefault( ) /* Inet functions */ #xtranslate hb_inetInit( [] ) => inetInit( )