From b83ec8bb2933482da6babe1f912dd24a7d486bdf Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 2 Jul 2010 13:04:35 +0000 Subject: [PATCH] 2010-07-02 15:04 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/pp/ppcore.c * include/hbpp.h + Added #pragma __binarystreaminclude. Works the same as other stream include pragmas, but here it the size limit is ~16MB and it accepts binary files for input. ; TODO: The encoding now contains high ascii chars which is unsafe as it can be converted by editors thus corrupting the embedded binary. * contrib/hbqt/hbmk2_plugin_qt.prg % Optimized .qrc to .prg converter to not split the lines. Harbour is able to compile very long source lines, pbly todays patch from Przemek was needed for that. Nice! --- harbour/ChangeLog | 15 ++++++++ harbour/contrib/hbqt/hbmk2_plugin_qt.prg | 19 +++------- harbour/include/hbpp.h | 1 + harbour/src/pp/ppcore.c | 45 +++++++++++++++++------- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 81cacdbbc7..9f3c1958ca 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ +2010-07-02 15:04 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * src/pp/ppcore.c + * include/hbpp.h + + Added #pragma __binarystreaminclude. Works the same as + other stream include pragmas, but here it the size limit + is ~16MB and it accepts binary files for input. + ; TODO: The encoding now contains high ascii chars which + is unsafe as it can be converted by editors thus + corrupting the embedded binary. + + * contrib/hbqt/hbmk2_plugin_qt.prg + % Optimized .qrc to .prg converter to not split the lines. + Harbour is able to compile very long source lines, pbly + todays patch from Przemek was needed for that. Nice! + 2010-07-02 14:33 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbqt/hbmk2_plugin_qt.prg + Activated new resource binary generator code, which diff --git a/harbour/contrib/hbqt/hbmk2_plugin_qt.prg b/harbour/contrib/hbqt/hbmk2_plugin_qt.prg index dd44c591b2..22bff44c3d 100644 --- a/harbour/contrib/hbqt/hbmk2_plugin_qt.prg +++ b/harbour/contrib/hbqt/hbmk2_plugin_qt.prg @@ -336,6 +336,8 @@ PROCEDURE Main( cSrc, cDst ) LOCAL cName + OutStd( "Test mode", hb_osNewLine() ) + IF cSrc != NIL .AND. ; cDst != NIL @@ -391,7 +393,6 @@ STATIC FUNCTION qrc_bin_to_src( hbmk2, cFileNameSrc, cFileNameDst, cName ) LOCAL cFile LOCAL cChar LOCAL cOutput - LOCAL cLine LOCAL cExt IF hb_FileExists( cFileNameSrc ) @@ -416,14 +417,11 @@ STATIC FUNCTION qrc_bin_to_src( hbmk2, cFileNameSrc, cFileNameDst, cName ) cOutput += "{" + hb_osNewLine() cOutput += Chr( 9 ) + "static const char s_res_data[] =" + hb_osNewLine() cOutput += Chr( 9 ) + "{" + hb_osNewLine() - cOutput += Chr( 9 ) + Chr( 9 ) FOR EACH cChar IN cFile cOutput += "0x" + hb_NumToHex( Asc( cChar ) ) + "," NEXT - cOutput += hb_osNewLine() - cOutput += Chr( 9 ) + "};" + hb_osNewLine() cOutput += hb_osNewLine() cOutput += Chr( 9 ) + "hb_retclen_const( s_res_data, sizeof( s_res_data ) );" + hb_osNewLine() @@ -436,18 +434,11 @@ STATIC FUNCTION qrc_bin_to_src( hbmk2, cFileNameSrc, cFileNameDst, cName ) cOutput += "#pragma -km+" + hb_osNewLine() cOutput += hb_osNewLine() cOutput += "FUNCTION " + cName + "()" + hb_osNewLine() - cOutput += Chr( 9 ) + "RETURN ;" + hb_osNewLine() - - cLine := Chr( 9 ) + Chr( 9 ) + "e" + Chr( 34 ) + cOutput += Chr( 9 ) + "RETURN e" + Chr( 34 ) FOR EACH cChar IN cFile - cLine += "\x" + hb_NumToHex( Asc( cChar ), 2 ) - IF Len( cLine ) >= 1024 - cOutput += cLine + Chr( 34 ) + " +;" + hb_osNewLine() - cLine := Chr( 9 ) + Chr( 9 ) + "e" + Chr( 34 ) - ENDIF + cOutput += "\x" + hb_NumToHex( Asc( cChar ), 2 ) NEXT - - cOutput += cLine + Chr( 34 ) + hb_osNewLine() + cOutput += Chr( 34 ) + hb_osNewLine() EXIT diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index d9e7171bf9..951ef97878 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -72,6 +72,7 @@ HB_EXTERN_BEGIN #define HB_PP_STREAM_PRG 4 /* TEXT/ENDTEXT lines joined with LF */ #define HB_PP_STREAM_C 5 /* TEXT/ENDTEXT lines joined and ESC seq processed */ #define HB_PP_STREAM_INLINE_C 6 /* hb_inLIne() {...} data, should not be preprocessed */ +#define HB_PP_STREAM_BINARY 7 /* __binarystreaminclude */ /* hb_inLine() states */ #define HB_PP_INLINE_OFF 0 diff --git a/harbour/src/pp/ppcore.c b/harbour/src/pp/ppcore.c index 1c68bead8f..da07f36648 100644 --- a/harbour/src/pp/ppcore.c +++ b/harbour/src/pp/ppcore.c @@ -1873,7 +1873,7 @@ static void hb_pp_defineDel( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) static PHB_PP_FILE hb_pp_FileNew( PHB_PP_STATE pState, const char * szFileName, HB_BOOL fSysFile, HB_BOOL * pfNested, FILE * file_in, - HB_BOOL fSearchPath, PHB_PP_OPEN_FUNC pOpenFunc ) + HB_BOOL fSearchPath, PHB_PP_OPEN_FUNC pOpenFunc, HB_BOOL fBinary ) { char szFileNameBuf[ HB_PATH_MAX ]; PHB_PP_FILE pFile; @@ -1915,7 +1915,7 @@ static PHB_PP_FILE hb_pp_FileNew( PHB_PP_STATE pState, const char * szFileName, } } - file_in = hb_fopen( szFileName, "r" ); + file_in = hb_fopen( szFileName, fBinary ? "rb" : "r" ); fNested = file_in == NULL && hb_fsMaxFilesError(); } @@ -1934,7 +1934,7 @@ static PHB_PP_FILE hb_pp_FileNew( PHB_PP_STATE pState, const char * szFileName, { pFileName->szPath = pPath->szPath; hb_fsFNameMerge( szFileNameBuf, pFileName ); - file_in = hb_fopen( szFileNameBuf, "r" ); + file_in = hb_fopen( szFileNameBuf, fBinary ? "rb" : "r" ); pPath = pPath->pNext; } } @@ -2135,22 +2135,26 @@ static HB_BOOL hb_pp_pragmaStream( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) } #define MAX_STREAM_SIZE 0xFFF0 +#define MAX_STREAM_SIZE_BIN 0xFFFF00 -static void hb_pp_pragmaStreamFile( PHB_PP_STATE pState, const char * szFileName ) +static void hb_pp_pragmaStreamFile( PHB_PP_STATE pState, const char * szFileName, HB_BOOL fBinary ) { PHB_PP_FILE pFile = hb_pp_FileNew( pState, szFileName, HB_FALSE, NULL, NULL, - HB_TRUE, pState->pOpenFunc ); + HB_TRUE, pState->pOpenFunc, fBinary ); if( pFile ) { - char * pBuffer = ( char * ) hb_xgrab( MAX_STREAM_SIZE + 1 ); + char * pBuffer; HB_SIZE nSize; + HB_SIZE nMaxSize = pState->iStreamDump == HB_PP_STREAM_BINARY ? MAX_STREAM_SIZE_BIN : MAX_STREAM_SIZE; + + pBuffer = ( char * ) hb_xgrab( nMaxSize + 1 ); if( ! pState->pStreamBuffer ) pState->pStreamBuffer = hb_membufNew(); - nSize = ( HB_SIZE ) fread( pBuffer, sizeof( char ), MAX_STREAM_SIZE + 1, pFile->file_in ); + nSize = ( HB_SIZE ) fread( pBuffer, sizeof( char ), nMaxSize + 1, pFile->file_in ); hb_pp_FileFree( pState, pFile, pState->pCloseFunc ); - if( nSize <= MAX_STREAM_SIZE ) + if( nSize <= nMaxSize ) { if( pState->iStreamDump == HB_PP_STREAM_C ) hb_strRemEscSeq( pBuffer, &nSize ); @@ -2468,7 +2472,7 @@ static void hb_pp_pragmaNew( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) if( !fError ) { pState->iStreamDump = HB_PP_STREAM_PRG; - hb_pp_pragmaStreamFile( pState, pToken->pNext->value ); + hb_pp_pragmaStreamFile( pState, pToken->pNext->value, HB_FALSE ); pState->iStreamDump = HB_PP_STREAM_OFF; } } @@ -2483,7 +2487,22 @@ static void hb_pp_pragmaNew( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) if( !fError ) { pState->iStreamDump = HB_PP_STREAM_C; - hb_pp_pragmaStreamFile( pState, pToken->pNext->value ); + hb_pp_pragmaStreamFile( pState, pToken->pNext->value, HB_FALSE ); + pState->iStreamDump = HB_PP_STREAM_OFF; + } + } + else + fError = HB_TRUE; + } + else if( hb_pp_tokenValueCmp( pToken, "__binarystreaminclude", HB_PP_CMP_DBASE ) ) + { + if( pToken->pNext && HB_PP_TOKEN_TYPE( pToken->pNext->type ) == HB_PP_TOKEN_STRING ) + { + fError = hb_pp_pragmaStream( pState, pToken->pNext->pNext ); + if( !fError ) + { + pState->iStreamDump = HB_PP_STREAM_BINARY; + hb_pp_pragmaStreamFile( pState, pToken->pNext->value, HB_TRUE ); pState->iStreamDump = HB_PP_STREAM_OFF; } } @@ -4934,7 +4953,7 @@ static void hb_pp_includeFile( PHB_PP_STATE pState, const char * szFileName, HB_ { HB_BOOL fNested = HB_FALSE; PHB_PP_FILE pFile = hb_pp_FileNew( pState, szFileName, fSysFile, &fNested, - NULL, HB_TRUE, pState->pOpenFunc ); + NULL, HB_TRUE, pState->pOpenFunc, HB_FALSE ); if( pFile ) { #if defined( HB_PP_STRICT_LINEINFO_TOKEN ) @@ -5550,7 +5569,7 @@ void hb_pp_readRules( PHB_PP_STATE pState, const char * szRulesFile ) hb_xfree( pFileName ); pState->pFile = hb_pp_FileNew( pState, szFileName, HB_FALSE, NULL, NULL, - HB_TRUE, pState->pOpenFunc ); + HB_TRUE, pState->pOpenFunc, HB_FALSE ); if( !pState->pFile ) { pState->pFile = pFile; @@ -5601,7 +5620,7 @@ HB_BOOL hb_pp_inFile( PHB_PP_STATE pState, const char * szFileName, pState->fError = HB_FALSE; pState->pFile = hb_pp_FileNew( pState, ( char * ) szFileName, HB_FALSE, NULL, - file_in, fSearchPath, NULL ); + file_in, fSearchPath, NULL, HB_FALSE ); if( pState->pFile ) { pState->iFiles++;