diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4f4a4100e0..f02e6dc98a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,44 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-08-22 19:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbpp.h + * harbour/include/hbcomp.h + * harbour/include/hbcompdf.h + * harbour/source/pp/ppcore.c + * harbour/source/rtl/gttrm/gttrm.c + * harbour/source/main/harbour.c + * harbour/source/compiler/hbmain.c + * harbour/source/compiler/cmdcheck.c + * harbour/source/compiler/hbcomp.c + * harbour/source/compiler/hbcmplib.c + * harbour/source/compiler/ppcomp.c + * added 'const' to some 'char *' declarations + + added hb_pp_inBuffer() + + extended hb_compMain() to accept source code passed as ASCIIZ + string + + .prg function HB_COMPILEFROMBUF() + + added support for -q2 compiler switch - it disables _ALL_ stdout/stderr + messages + + * harbour/utils/Makefile + + harbour/utils/hbdot + + harbour/utils/hbdot/hbdot.prg + + harbour/utils/hbdot/Makefile + + added hbdot utility program. + It's a "DOt Prompt" Console for the Harbour Language + Syntax: hbdot [ []] + It should look and work in similar way to pp/xBaseScript + by Ron Pinkas but unlike xBaseScript is does not have preprocessor + or simulated runtime environment but simply uses Harbour pp and + compiler libraries to preprocess and compile commands. It means + that it supports all language constructions also statements, f.e.: + "for i:=1 to 10; ? i; next" + Additionally it can also compile and execute .prg files given as + first parameter just like hbrun. + Please test it. If it will work as expected then we can remove + 'pp' (contrib/dot) from standard packages + 2007-08-21 16:00 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/vm/memvars.c + added __MVSETBASE() function diff --git a/harbour/include/hbcomp.h b/harbour/include/hbcomp.h index 9b05ef5c04..c24efde9e4 100644 --- a/harbour/include/hbcomp.h +++ b/harbour/include/hbcomp.h @@ -169,7 +169,7 @@ extern void hb_compGenBreak( HB_COMP_DECL ); /* generate code for BREAK stateme extern void hb_compExternGen( HB_COMP_DECL ); /* generates the symbols for the EXTERN names */ extern void hb_compExternAdd( HB_COMP_DECL, char * szExternName, HB_SYMBOLSCOPE cScope ); /* defines a new extern name */ -extern void hb_compAutoOpenAdd( HB_COMP_DECL, char * szName ); +extern void hb_compAutoOpenAdd( HB_COMP_DECL, const char * szName ); extern void hb_compSwitchKill( HB_COMP_DECL ); extern void hb_compLoopKill( HB_COMP_DECL ); @@ -266,7 +266,7 @@ extern BOOL hb_compCheckUnclosedStru( HB_COMP_DECL ); #define HB_GEN_FUNC3( func, p1,p2,p3 ) hb_compGen##func( p1, p2, p3, HB_COMP_PARAM ) #define HB_GEN_FUNC4( func, p1,p2,p3,p4 ) hb_compGen##func( p1, p2, p3, p4, HB_COMP_PARAM ) -extern int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ); +extern int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize, const char * szSource ); extern void hb_compOutStd( HB_COMP_DECL, const char * szMessage ); extern void hb_compOutErr( HB_COMP_DECL, const char * szMessage ); @@ -352,9 +352,6 @@ extern const char * hb_comp_szWarnings[]; /* table with PCODEs' length */ extern const BYTE hb_comp_pcode_len[]; -/* file handle for error messages */ -extern FILE * hb_comp_errFile; - /* identifier types for hb_compIdentifierNew() */ #define HB_IDENT_STATIC 0 #define HB_IDENT_FREE 1 diff --git a/harbour/include/hbcompdf.h b/harbour/include/hbcompdf.h index 93b3113f47..970296aba7 100644 --- a/harbour/include/hbcompdf.h +++ b/harbour/include/hbcompdf.h @@ -608,6 +608,10 @@ typedef struct _HB_COMP PHB_FNAME pOutPath; PHB_FNAME pPpoPath; + void ( * outStdFunc ) ( void *, const char* ); + void ( * outErrFunc ) ( void *, const char* ); + void * cargo; + ULONG ulOutBufSize; /* memory output buffer size */ BYTE * pOutBuf; /* memory output buffer address */ @@ -642,6 +646,7 @@ typedef struct _HB_COMP int ilastLineErr; /* line numer with last syntax error */ BOOL fQuiet; /* be quiet during compilation (-q) */ + BOOL fFullQuiet; /* be quiet during compilation disable all messages */ BOOL fExit; /* force breaking compilation process */ BOOL fPPO; /* flag indicating, is ppo output needed */ BOOL fPPT; /* flag indicating, is ppt output needed */ diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index 6c8d065283..f2f1597f22 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -83,7 +83,7 @@ HB_EXTERN_BEGIN #define HB_PP_INLINE_QUOTE2 6 /* function to open included files */ -#define HB_PP_OPEN_FUNC_( func ) FILE * func( void *, char *, BOOL, char * ) +#define HB_PP_OPEN_FUNC_( func ) FILE * func( void *, const char *, BOOL, char * ) typedef HB_PP_OPEN_FUNC_( HB_PP_OPEN_FUNC ); typedef HB_PP_OPEN_FUNC * PHB_PP_OPEN_FUNC; @@ -107,7 +107,7 @@ typedef HB_PP_DISP_FUNC * PHB_PP_DISP_FUNC; typedef HB_PP_DUMP_FUNC_( HB_PP_DUMP_FUNC ); typedef HB_PP_DUMP_FUNC * PHB_PP_DUMP_FUNC; -/* function for catching #pragma dump data */ +/* function for catching HB_INLINE(...){...} data */ #define HB_PP_INLINE_FUNC_( func ) void func( void *, char *, char *, ULONG, int ) typedef HB_PP_INLINE_FUNC_( HB_PP_INLINE_FUNC ); typedef HB_PP_INLINE_FUNC * PHB_PP_INLINE_FUNC; @@ -542,7 +542,7 @@ typedef struct _HB_PP_FILE BOOL fGenLineInfo; /* #line information should be generated */ BOOL fEof; /* the end of file reached */ - char * pLineBuf; /* buffer for parsing external lines */ + const char * pLineBuf; /* buffer for parsing external lines */ ULONG ulLineBufLen; /* size of external line buffer */ struct _HB_PP_FILE * pPrev; /* previous file, the one which included this file */ @@ -646,14 +646,15 @@ extern void hb_pp_init( PHB_PP_STATE pState, BOOL fQuiet, PHB_PP_DUMP_FUNC pDumpFunc, PHB_PP_INLINE_FUNC pInLineFunc, PHB_PP_SWITCH_FUNC pSwitchFunc ); extern void hb_pp_initDynDefines( PHB_PP_STATE pState ); -extern void hb_pp_readRules( PHB_PP_STATE pState, char * szRulesFile ); +extern void hb_pp_readRules( PHB_PP_STATE pState, const char * szRulesFile ); extern void hb_pp_setStdRules( PHB_PP_STATE pState ); extern void hb_pp_setStdBase( PHB_PP_STATE pState ); extern void hb_pp_setStream( PHB_PP_STATE pState, int iMode ); extern void hb_pp_addSearchPath( PHB_PP_STATE pState, const char * szPath, BOOL fReplace ); -extern BOOL hb_pp_inFile( PHB_PP_STATE pState, char * szFileName, BOOL fSearchPath, FILE * file_in, BOOL fError ); -extern BOOL hb_pp_outFile( PHB_PP_STATE pState, char * szOutFileName, FILE * file_out ); -extern BOOL hb_pp_traceFile( PHB_PP_STATE pState, char * szTraceFileName, FILE * file_trace ); +extern BOOL hb_pp_inBuffer( PHB_PP_STATE pState, const char * pBuffer, ULONG ulLen ); +extern BOOL hb_pp_inFile( PHB_PP_STATE pState, const char * szFileName, BOOL fSearchPath, FILE * file_in, BOOL fError ); +extern BOOL hb_pp_outFile( PHB_PP_STATE pState, const char * szOutFileName, FILE * file_out ); +extern BOOL hb_pp_traceFile( PHB_PP_STATE pState, const char * szTraceFileName, FILE * file_trace ); extern char * hb_pp_fileName( PHB_PP_STATE pState ); extern int hb_pp_line( PHB_PP_STATE pState ); extern BOOL hb_pp_eof( PHB_PP_STATE pState ); @@ -661,16 +662,16 @@ extern int hb_pp_lineTot( PHB_PP_STATE pState ); extern char * hb_pp_outFileName( PHB_PP_STATE pState ); extern char * hb_pp_traceFileName( PHB_PP_STATE pState ); extern char * hb_pp_nextLine( PHB_PP_STATE pState, ULONG * pulLen ); -extern char * hb_pp_parseLine( PHB_PP_STATE pState, char * pLine, ULONG * pulLen ); -extern void hb_pp_addDefine( PHB_PP_STATE pState, char * szDefName, char * szDefValue ); -extern void hb_pp_delDefine( PHB_PP_STATE pState, char * szDefName ); +extern char * hb_pp_parseLine( PHB_PP_STATE pState, const char * pLine, ULONG * pulLen ); +extern void hb_pp_addDefine( PHB_PP_STATE pState, const char * szDefName, const char * szDefValue ); +extern void hb_pp_delDefine( PHB_PP_STATE pState, const char * szDefName ); extern BOOL hb_pp_lasterror( PHB_PP_STATE pState ); extern BOOL hb_pp_eof( PHB_PP_STATE pState ); extern void hb_pp_tokenUpper( PHB_PP_TOKEN pToken ); extern void hb_pp_tokenToString( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ); extern char * hb_pp_tokenBlockString( PHB_PP_STATE pState, PHB_PP_TOKEN pToken, int * piType, int * piLen ); -extern PHB_PP_STATE hb_pp_lexNew( char * pString, ULONG ulLen ); +extern PHB_PP_STATE hb_pp_lexNew( const char * pString, ULONG ulLen ); extern PHB_PP_TOKEN hb_pp_lexGet( PHB_PP_STATE pState ); extern PHB_PP_TOKEN hb_pp_tokenGet( PHB_PP_STATE pState ); extern BOOL hb_pp_tokenNextExp( PHB_PP_TOKEN * pTokenPtr ); diff --git a/harbour/source/compiler/cmdcheck.c b/harbour/source/compiler/cmdcheck.c index 8e16c62cd7..04dc7410d0 100644 --- a/harbour/source/compiler/cmdcheck.c +++ b/harbour/source/compiler/cmdcheck.c @@ -449,10 +449,15 @@ static void hb_compChkEnvironVar( HB_COMP_DECL, char *szSwitch ) case 'q': case 'Q': - if( *( s + 1 ) == '0' ) - HB_COMP_PARAM->fLogo = FALSE; - - HB_COMP_PARAM->fQuiet = TRUE; + switch( *( s + 1 ) ) + { + case '2': + HB_COMP_PARAM->fFullQuiet = TRUE; + case '0': + HB_COMP_PARAM->fLogo = FALSE; + default: + HB_COMP_PARAM->fQuiet = TRUE; + } break; case 'r': diff --git a/harbour/source/compiler/hbcmplib.c b/harbour/source/compiler/hbcmplib.c index 63d14746c0..35e4984a2d 100644 --- a/harbour/source/compiler/hbcmplib.c +++ b/harbour/source/compiler/hbcmplib.c @@ -117,7 +117,7 @@ HB_FUNC( HB_COMPILE ) hb_compGenArgList( 1, hb_pcount(), &argc, &argv ); - hb_retni( hb_compMain( argc, argv, NULL, NULL ) ); + hb_retni( hb_compMain( argc, argv, NULL, NULL, NULL ) ); hb_xfree( argv ); } @@ -129,8 +129,26 @@ HB_FUNC( HB_COMPILEBUF ) ULONG ulLen; hb_compGenArgList( 1, hb_pcount(), &argc, &argv ); - iResult = hb_compMain( argc, argv, &pBuffer, &ulLen ); + iResult = hb_compMain( argc, argv, &pBuffer, &ulLen, NULL ); hb_xfree( argv ); if( iResult == EXIT_SUCCESS && pBuffer ) hb_retclen_buffer( ( char * ) pBuffer, ulLen ); } + +HB_FUNC( HB_COMPILEFROMBUF ) +{ + int iResult, argc; + char ** argv, * szSource; + BYTE * pBuffer; + ULONG ulLen; + + szSource = hb_parc( 1 ); + if( szSource ) + { + hb_compGenArgList( 2, hb_pcount(), &argc, &argv ); + iResult = hb_compMain( argc, argv, &pBuffer, &ulLen, szSource ); + hb_xfree( argv ); + if( iResult == EXIT_SUCCESS && pBuffer ) + hb_retclen_buffer( ( char * ) pBuffer, ulLen ); + } +} diff --git a/harbour/source/compiler/hbcomp.c b/harbour/source/compiler/hbcomp.c index a811844f1b..2673ddcb34 100644 --- a/harbour/source/compiler/hbcomp.c +++ b/harbour/source/compiler/hbcomp.c @@ -292,16 +292,30 @@ void hb_comp_free( HB_COMP_PTR pComp ) void hb_compOutStd( HB_COMP_DECL, const char * szMessage ) { - HB_SYMBOL_UNUSED( HB_COMP_PARAM ); - - fprintf( stderr, "%s", szMessage ); - fflush( stdout ); + if( ! HB_COMP_PARAM->fFullQuiet ) + { + if( HB_COMP_PARAM->outStdFunc ) + HB_COMP_PARAM->outStdFunc( HB_COMP_PARAM->cargo, szMessage ); + else + { + fprintf( stderr, "%s", szMessage ); fflush( stdout ); + } + } } void hb_compOutErr( HB_COMP_DECL, const char * szMessage ) { - HB_SYMBOL_UNUSED( HB_COMP_PARAM ); - - fprintf( hb_comp_errFile, "%s", szMessage ); - fflush( hb_comp_errFile ); + if( ! HB_COMP_PARAM->fFullQuiet ) + { + if( HB_COMP_PARAM->outErrFunc ) + HB_COMP_PARAM->outErrFunc( HB_COMP_PARAM->cargo, szMessage ); + else + { +#if defined( HOST_OS_UNIX_COMPATIBLE ) + fprintf( stderr, "%s", szMessage ); fflush( stderr ); +#else + fprintf( stdout, "%s", szMessage ); fflush( stdout ); +#endif + } + } } diff --git a/harbour/source/compiler/hbmain.c b/harbour/source/compiler/hbmain.c index 58e364e60d..086c1fb8b0 100644 --- a/harbour/source/compiler/hbmain.c +++ b/harbour/source/compiler/hbmain.c @@ -67,30 +67,27 @@ extern unsigned _stklen = UINT_MAX; #endif -static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ); +#define HB_COMP_SINGLEFILE 1 +#define HB_COMP_AUTOADDFILE 2 +#define HB_COMP_MEMBUFFER 3 + +static int hb_compCompile( HB_COMP_DECL, const char * szPrg, int iFileType ); static int hb_compProcessRSPFile( HB_COMP_DECL, char * ); /* process response file */ -static int hb_compAutoOpen( HB_COMP_DECL, char * szPrg, BOOL * bSkipGen, BOOL bSingleFile ); +static int hb_compAutoOpen( HB_COMP_DECL, const char * szPrg, BOOL * bSkipGen, int iFileType ); static void hb_compDeclaredInit( HB_COMP_DECL ); -/* global variables */ -FILE * hb_comp_errFile = NULL; /* ************************************************************************* */ -int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) +int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize, + const char * szSource ) { HB_COMP_DECL; int iStatus = EXIT_SUCCESS; BOOL bAnyFiles = FALSE; int i; -#if defined( HOST_OS_UNIX_COMPATIBLE ) - hb_comp_errFile = stderr; -#else - hb_comp_errFile = stdout; -#endif - HB_TRACE(HB_TR_DEBUG, ("hb_compMain()")); HB_COMP_PARAM = hb_comp_new(); @@ -142,21 +139,27 @@ int hb_compMain( int argc, char * argv[], BYTE ** pBufPtr, ULONG * pulSize ) hb_compDeclaredInit( HB_COMP_PARAM ); } - /* Process all files passed via the command line. */ - for( i = 1; i < argc && !HB_COMP_PARAM->fExit; i++ ) + if( szSource ) { - HB_TRACE(HB_TR_DEBUG, ("main LOOP(%i,%s)", i, argv[i])); - if( ! HB_ISOPTSEP( argv[ i ][ 0 ] ) ) + bAnyFiles = TRUE; + iStatus = hb_compCompile( HB_COMP_PARAM, szSource, HB_COMP_MEMBUFFER ); + } + else + { + /* Process all files passed via the command line. */ + for( i = 1; i < argc && !HB_COMP_PARAM->fExit; i++ ) { - bAnyFiles = TRUE; - - if( argv[ i ][ 0 ] == '@' ) - iStatus = hb_compProcessRSPFile( HB_COMP_PARAM, argv[ i ] + 1 ); - else - iStatus = hb_compCompile( HB_COMP_PARAM, argv[ i ], TRUE ); - - if( iStatus != EXIT_SUCCESS ) - break; + HB_TRACE(HB_TR_DEBUG, ("main LOOP(%i,%s)", i, argv[i])); + if( ! HB_ISOPTSEP( argv[ i ][ 0 ] ) ) + { + bAnyFiles = TRUE; + if( argv[ i ][ 0 ] == '@' ) + iStatus = hb_compProcessRSPFile( HB_COMP_PARAM, argv[ i ] + 1 ); + else + iStatus = hb_compCompile( HB_COMP_PARAM, argv[ i ], HB_COMP_SINGLEFILE ); + if( iStatus != EXIT_SUCCESS ) + break; + } } } @@ -265,7 +268,7 @@ static int hb_compProcessRSPFile( HB_COMP_DECL, char * szRspName ) HB_COMP_PARAM->fAutoOpen = bAutoOpen; hb_fsFNameMerge( szFile, pFileName ); - hb_compCompile( HB_COMP_PARAM, szFile, FALSE ); + hb_compCompile( HB_COMP_PARAM, szFile, HB_COMP_AUTOADDFILE ); } hb_xfree( pFileName ); @@ -4229,11 +4232,18 @@ void hb_compCompileEnd( HB_COMP_DECL ) } } -static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) +static int hb_compCompile( HB_COMP_DECL, const char * szPrg, int iFileType ) { + const char * szBuffer = NULL; int iStatus = EXIT_SUCCESS; - HB_TRACE(HB_TR_DEBUG, ("hb_compCompile(%s,%d)", szPrg, bSingleFile)); + HB_TRACE(HB_TR_DEBUG, ("hb_compCompile(%s,%d)", szPrg, iFileType)); + + if( iFileType == HB_COMP_MEMBUFFER ) + { + szBuffer = szPrg; + szPrg = "{SOURCE}"; + } HB_COMP_PARAM->pMainFileName = hb_fsFNameSplit( szPrg ); HB_COMP_PARAM->pFileName = HB_COMP_PARAM->pMainFileName; @@ -4257,14 +4267,22 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) HB_COMP_PARAM->pFileName->szExtension = ".prg"; hb_fsFNameMerge( szFileName, HB_COMP_PARAM->pFileName ); - if( !hb_pp_inFile( HB_COMP_PARAM->pLex->pPP, szFileName, FALSE, NULL, FALSE ) ) + if( iFileType == HB_COMP_MEMBUFFER ) + { + if( !hb_pp_inBuffer( HB_COMP_PARAM->pLex->pPP, szBuffer, strlen( szBuffer ) ) ) + { + hb_compOutErr( HB_COMP_PARAM, "Cannot create preprocessor buffer." ); + iStatus = EXIT_FAILURE; + } + } + else if( !hb_pp_inFile( HB_COMP_PARAM->pLex->pPP, szFileName, FALSE, NULL, FALSE ) ) { snprintf( buffer, sizeof( buffer ), "Cannot open input file: %s\n", szFileName ); hb_compOutErr( HB_COMP_PARAM, buffer ); iStatus = EXIT_FAILURE; } - else if( bSingleFile ) + else if( iFileType == HB_COMP_SINGLEFILE ) { if( HB_COMP_PARAM->fPPT ) { @@ -4289,7 +4307,13 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) hb_compIdentifierNew( HB_COMP_PARAM, szFileName, HB_IDENT_COPY ); HB_COMP_PARAM->currLine = 1; - if( bSingleFile ) + if( iFileType == HB_COMP_MEMBUFFER ) + { + hb_compFunctionAdd( HB_COMP_PARAM, "", 0, FUN_PROCEDURE ); + hb_compparse( HB_COMP_PARAM ); + hb_compCheckUnclosedStru( HB_COMP_PARAM ); + } + else if( iFileType == HB_COMP_SINGLEFILE ) { if( ! HB_COMP_PARAM->fQuiet ) { @@ -4336,7 +4360,7 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) PAUTOOPEN pAutoOpen = HB_COMP_PARAM->autoopen; if( ! hb_compFunctionFind( HB_COMP_PARAM, pAutoOpen->szName ) ) - hb_compAutoOpen( HB_COMP_PARAM, pAutoOpen->szName, &bSkipGen, bSingleFile ); + hb_compAutoOpen( HB_COMP_PARAM, pAutoOpen->szName, &bSkipGen, iFileType ); HB_COMP_PARAM->autoopen = HB_COMP_PARAM->autoopen->pNext; hb_xfree( pAutoOpen ); @@ -4504,7 +4528,7 @@ static int hb_compCompile( HB_COMP_DECL, char * szPrg, BOOL bSingleFile ) return HB_COMP_PARAM->fExit ? EXIT_FAILURE : iStatus; } -static BOOL hb_compAutoOpenFind( HB_COMP_DECL, char * szName ) +static BOOL hb_compAutoOpenFind( HB_COMP_DECL, const char * szName ) { PAUTOOPEN pLast = HB_COMP_PARAM->autoopen; @@ -4528,7 +4552,7 @@ static BOOL hb_compAutoOpenFind( HB_COMP_DECL, char * szName ) return FALSE; } -void hb_compAutoOpenAdd( HB_COMP_DECL, char * szName ) +void hb_compAutoOpenAdd( HB_COMP_DECL, const char * szName ) { HB_TRACE(HB_TR_DEBUG, ("hb_compAutoOpenAdd(%p,%s)", HB_COMP_PARAM, szName)); @@ -4536,7 +4560,7 @@ void hb_compAutoOpenAdd( HB_COMP_DECL, char * szName ) { PAUTOOPEN pAutoOpen = ( PAUTOOPEN ) hb_xgrab( sizeof( AUTOOPEN ) ), pLast; - pAutoOpen->szName = szName; + pAutoOpen->szName = ( char * ) szName; pAutoOpen->pNext = NULL; if( HB_COMP_PARAM->autoopen == NULL ) @@ -4552,7 +4576,7 @@ void hb_compAutoOpenAdd( HB_COMP_DECL, char * szName ) } } -static int hb_compAutoOpen( HB_COMP_DECL, char * szPrg, BOOL * pbSkipGen, BOOL bSingleFile ) +static int hb_compAutoOpen( HB_COMP_DECL, const char * szPrg, BOOL * pbSkipGen, int iFileType ) { int iStatus = EXIT_SUCCESS; PHB_FNAME pMainFileName = HB_COMP_PARAM->pFileName; @@ -4616,7 +4640,7 @@ static int hb_compAutoOpen( HB_COMP_DECL, char * szPrg, BOOL * pbSkipGen, BOOL b /* Generate the starting procedure frame */ if( HB_COMP_PARAM->fStartProc ) hb_compFunctionAdd( HB_COMP_PARAM, hb_compIdentifierNew( HB_COMP_PARAM, hb_strupr( hb_strdup( HB_COMP_PARAM->pFileName->szName ) ), HB_IDENT_FREE ), HB_FS_PUBLIC, FUN_PROCEDURE ); - else if( ! bSingleFile ) + else if( iFileType != HB_COMP_SINGLEFILE ) hb_compFunctionAdd( HB_COMP_PARAM, "", 0, FUN_PROCEDURE ); if( !HB_COMP_PARAM->fExit ) diff --git a/harbour/source/compiler/ppcomp.c b/harbour/source/compiler/ppcomp.c index 5a26d23381..eae1fd922a 100644 --- a/harbour/source/compiler/ppcomp.c +++ b/harbour/source/compiler/ppcomp.c @@ -73,6 +73,13 @@ static void hb_pp_ErrorGen( void * cargo, HB_COMP_PARAM->currModule = currModule; } +static void hb_pp_Disp( void * cargo, const char * szMessage ) +{ + HB_COMP_DECL = ( HB_COMP_PTR ) cargo; + + hb_compOutStd( HB_COMP_PARAM, szMessage ); +} + static void hb_pp_PragmaDump( void * cargo, char * pBuffer, ULONG ulSize, int iLine ) { @@ -210,7 +217,7 @@ void hb_compInitPP( HB_COMP_DECL, int argc, char * argv[] ) hb_pp_init( HB_COMP_PARAM->pLex->pPP, HB_COMP_PARAM->fQuiet, HB_COMP_PARAM->iMaxTransCycles, HB_COMP_PARAM, NULL, NULL, - hb_pp_ErrorGen, NULL, hb_pp_PragmaDump, + hb_pp_ErrorGen, hb_pp_Disp, hb_pp_PragmaDump, HB_COMP_ISSUPPORTED( HB_COMPFLAG_HB_INLINE ) ? hb_pp_hb_inLine : NULL, hb_pp_CompilerSwitch ); diff --git a/harbour/source/main/harbour.c b/harbour/source/main/harbour.c index 6fb767f859..9b0dff2d82 100644 --- a/harbour/source/main/harbour.c +++ b/harbour/source/main/harbour.c @@ -57,7 +57,7 @@ int main( int argc, char * argv[] ) { int iResult; - iResult = hb_compMain( argc, argv, NULL, NULL ); + iResult = hb_compMain( argc, argv, NULL, NULL, NULL ); hb_xexit(); return iResult; @@ -353,15 +353,7 @@ void hb_conOutErr( const char * pStr, ULONG ulLen ) if( ulLen == 0 ) ulLen = strlen( pStr ); - fprintf( hb_comp_errFile, "%.*s", ( int ) ulLen, pStr ); -} - -void hb_conOutStd( const char * pStr, ULONG ulLen ) -{ - if( ulLen == 0 ) - ulLen = strlen( pStr ); - - printf( "%.*s", ( int ) ulLen, pStr ); + fprintf( stderr, "%.*s", ( int ) ulLen, pStr ); } char * hb_conNewLine( void ) diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index 0d815cef42..7baecda3ef 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -1831,7 +1831,7 @@ static PHB_PP_FILE hb_pp_FileNew( PHB_PP_STATE pState, char * szFileName, return pFile; } -static PHB_PP_FILE hb_pp_FileBufNew( char * pLineBuf, ULONG ulLineBufLen ) +static PHB_PP_FILE hb_pp_FileBufNew( const char * pLineBuf, ULONG ulLineBufLen ) { PHB_PP_FILE pFile; @@ -5113,7 +5113,7 @@ void hb_pp_initDynDefines( PHB_PP_STATE pState ) /* * read preprocess rules from file */ -void hb_pp_readRules( PHB_PP_STATE pState, char * szRulesFile ) +void hb_pp_readRules( PHB_PP_STATE pState, const char * szRulesFile ) { char szFileName[ _POSIX_PATH_MAX + 1 ]; PHB_PP_FILE pFile = pState->pFile; @@ -5154,17 +5154,31 @@ void hb_pp_readRules( PHB_PP_STATE pState, char * szRulesFile ) } /* - * close all open input files and set the given one as new + * close all open input files and set the given buffer as input stream */ -BOOL hb_pp_inFile( PHB_PP_STATE pState, char * szFileName, BOOL fSearchPath, - FILE * file_in, BOOL fError ) +BOOL hb_pp_inBuffer( PHB_PP_STATE pState, const char * pBuffer, ULONG ulLen ) { hb_pp_InFileFree( pState ); pState->fError = FALSE; - pState->pFile = hb_pp_FileNew( pState, szFileName, FALSE, file_in, - fSearchPath, NULL ); + pState->pFile = hb_pp_FileBufNew( pBuffer, ulLen ); + pState->iFiles++; + return TRUE; +} + +/* + * close all open input files and set the given one as new + */ +BOOL hb_pp_inFile( PHB_PP_STATE pState, const char * szFileName, + BOOL fSearchPath, FILE * file_in, BOOL fError ) +{ + hb_pp_InFileFree( pState ); + + pState->fError = FALSE; + + pState->pFile = hb_pp_FileNew( pState, ( char * ) szFileName, FALSE, + file_in, fSearchPath, NULL ); if( pState->pFile ) { pState->iFiles++; @@ -5178,7 +5192,8 @@ BOOL hb_pp_inFile( PHB_PP_STATE pState, char * szFileName, BOOL fSearchPath, /* * set output (.ppo) file */ -BOOL hb_pp_outFile( PHB_PP_STATE pState, char * szOutFileName, FILE * file_out ) +BOOL hb_pp_outFile( PHB_PP_STATE pState, const char * szOutFileName, + FILE * file_out ) { pState->fError = FALSE; hb_pp_OutFileFree( pState ); @@ -5207,7 +5222,7 @@ BOOL hb_pp_outFile( PHB_PP_STATE pState, char * szOutFileName, FILE * file_out ) /* * set trace (.ppt) file */ -BOOL hb_pp_traceFile( PHB_PP_STATE pState, char * szTraceFileName, FILE * file_trace ) +BOOL hb_pp_traceFile( PHB_PP_STATE pState, const char * szTraceFileName, FILE * file_trace ) { pState->fError = FALSE; hb_pp_TraceFileFree( pState ); @@ -5295,7 +5310,8 @@ BOOL hb_pp_eof( PHB_PP_STATE pState ) /* * add new define value */ -void hb_pp_addDefine( PHB_PP_STATE pState, char * szDefName, char * szDefValue ) +void hb_pp_addDefine( PHB_PP_STATE pState, const char * szDefName, + const char * szDefValue ) { PHB_PP_TOKEN pMatch, pResult, pToken; PHB_PP_FILE pFile; @@ -5342,7 +5358,7 @@ void hb_pp_addDefine( PHB_PP_STATE pState, char * szDefName, char * szDefValue ) /* * delete define value */ -void hb_pp_delDefine( PHB_PP_STATE pState, char * szDefName ) +void hb_pp_delDefine( PHB_PP_STATE pState, const char * szDefName ) { PHB_PP_TOKEN pToken; @@ -5430,7 +5446,7 @@ char * hb_pp_nextLine( PHB_PP_STATE pState, ULONG * pulLen ) /* * preprocess given buffer */ -char * hb_pp_parseLine( PHB_PP_STATE pState, char * pLine, ULONG * pulLen ) +char * hb_pp_parseLine( PHB_PP_STATE pState, const char * pLine, ULONG * pulLen ) { PHB_PP_TOKEN pToken; PHB_PP_FILE pFile; @@ -5486,7 +5502,7 @@ char * hb_pp_parseLine( PHB_PP_STATE pState, char * pLine, ULONG * pulLen ) /* * create new PP context for macro compiler */ -PHB_PP_STATE hb_pp_lexNew( char * pMacroString, ULONG ulLen ) +PHB_PP_STATE hb_pp_lexNew( const char * pMacroString, ULONG ulLen ) { PHB_PP_STATE pState = hb_pp_new(); diff --git a/harbour/source/rtl/gttrm/gttrm.c b/harbour/source/rtl/gttrm/gttrm.c index 4b0be0b985..d1bc721a4b 100644 --- a/harbour/source/rtl/gttrm/gttrm.c +++ b/harbour/source/rtl/gttrm/gttrm.c @@ -379,6 +379,10 @@ typedef struct static HB_TERM_STATE s_termState; +/* save old hilit tracking & enable mouse tracking */ +static const char * s_szMouseOn = "\033[?1001s\033[?1002h"; +/* disable mouse tracking & restore old hilit tracking */ +static const char * s_szMouseOff = "\033[?1002l\033[?1001r"; static const BYTE s_szBell[] = { HB_CHAR_BEL, 0 }; static BYTE * s_szCrLf; static ULONG s_ulCrLf; @@ -1076,9 +1080,7 @@ static void mouse_init( void ) if( s_termState.terminal_type == TERM_XTERM || s_termState.terminal_type == TERM_LINUX ) { - /* save old hilit tracking & enable mouse tracking */ - static const char * szMouseOn = "\033[?1001s\033[?1002h"; - hb_gt_trm_termOut( ( BYTE * ) szMouseOn, strlen( szMouseOn ) ); + hb_gt_trm_termOut( ( BYTE * ) s_szMouseOn, strlen( s_szMouseOn ) ); hb_gt_trm_termFlush(); memset( ( void * ) &s_termState.mLastEvt, 0, sizeof( s_termState.mLastEvt ) ); s_termState.mouse_type |= MOUSE_XTERM; @@ -1125,9 +1127,7 @@ static void mouse_exit( void ) { if( s_termState.mouse_type & MOUSE_XTERM ) { - /* disable mouse tracking & restore old hilit tracking */ - static const char * szMouseOff = "\033[?1002l\033[?1001r"; - hb_gt_trm_termOut( ( BYTE * ) szMouseOff, strlen( szMouseOff ) ); + hb_gt_trm_termOut( ( BYTE * ) s_szMouseOff, strlen( s_szMouseOff ) ); hb_gt_trm_termFlush(); } #ifdef HAVE_GPM_H @@ -3044,6 +3044,10 @@ static BOOL hb_gt_trm_Resume( void ) tcsetattr( s_termState.hFilenoStdin, TCSANOW, &s_termState.curr_TIO ); } #endif + + if( s_termState.mouse_type & MOUSE_XTERM ) + hb_gt_trm_termOut( ( BYTE * ) s_szMouseOn, strlen( s_szMouseOn ) ); + s_termState.Init(); hb_gt_GetSize( &iHeight, &iWidth ); diff --git a/harbour/utils/Makefile b/harbour/utils/Makefile index a5dddaf017..0109291f0e 100644 --- a/harbour/utils/Makefile +++ b/harbour/utils/Makefile @@ -9,6 +9,7 @@ DIRS=\ hbpptest \ hbver \ hbrun \ + hbdot \ hbdoc \ hbtest \ hbmake \ diff --git a/harbour/utils/hbdot/Makefile b/harbour/utils/hbdot/Makefile new file mode 100644 index 0000000000..800e5131e9 --- /dev/null +++ b/harbour/utils/hbdot/Makefile @@ -0,0 +1,35 @@ +# +# $Id$ +# + +ifeq ($(HB_MAIN),) +HB_MAIN = std +endif + +ROOT = ../../ + +PRG_SOURCES=\ + hbdot.prg \ + +PRG_MAIN=hbdot.prg + +LIBS=\ + debug \ + vm \ + rtl \ + lang \ + rdd \ + rtl \ + vm \ + macro \ + pp \ + compiler \ + common \ + +ifeq ($(findstring -DHB_PCRE_REGEX, $(C_USR)),) +ifeq ($(findstring -DHB_POSIX_REGEX, $(C_USR)),) +LIBS += hbpcre +endif +endif + +include $(TOP)$(ROOT)config/bin.cf diff --git a/harbour/utils/hbdot/hbdot.prg b/harbour/utils/hbdot/hbdot.prg new file mode 100644 index 0000000000..0d6e7271f1 --- /dev/null +++ b/harbour/utils/hbdot/hbdot.prg @@ -0,0 +1,321 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * "DOt Prompt" Console for the Harbour Language + * + * Copyright 2007 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "inkey.ch" +#include "setcurs.ch" +#include "hbextern.ch" + +#include "hbclass.ch" + +#define HB_HISTORY_LEN 32 +#define HB_LINE_LEN 256 +#define HB_PROMPT "." + +STATIC s_nRow := 2, s_nCol := 0 +STATIC s_aIncDir := {} + +/* ********************************************************************** */ + +PROCEDURE _APPMAIN( cFile, ... ) + LOCAL GetList, cLine, cCommand, cPath + LOCAL aHistory, nHistIndex + LOCAL bKeyUP, bKeyDown, bKeyIns + +#ifdef _DEFAULT_INC_DIR + AADD( s_aIncDir, "-I" + _DEFAULT_INC_DIR ) +#endif + cPath := getenv( "HB_INC_INSTALL" ) + IF !EMPTY( cPath ) + AADD( s_aIncDir, "-I" + cPath ) + ENDIF +#ifdef __PLATFORM__UNIX + AADD( s_aIncDir, "-I/usr/include/harbour" ) + AADD( s_aIncDir, "-I/usr/local/include/harbour" ) +#endif + + CLEAR SCREEN + + IF PCount() > 0 + SWITCH cFile + CASE "-?" + CASE "-h" + CASE "--help" + CASE "/?" + CASE "/h" + HB_DotUsage() + EXIT + OTHERWISE + cFile := HB_COMPILEBUF( HB_ARGV( 0 ), "-n", "-w", "-es2", "-q0", ; + s_aIncDir, cFile ) + IF cFile == NIL + ERRORLEVEL( 1 ) + ELSE + __hrbRun( cFile, ... ) + ENDIF + END + ELSE + + SET SCOREBOARD OFF + GetList := {} + cCommand := "" + aHistory := { padr( "quit", HB_LINE_LEN ) } + nHistIndex := 2 + + DO WHILE .T. + + IF cLine == NIL + cLine := Space( HB_LINE_LEN ) + ENDIF + + HB_DotInfo( cCommand ) + + @ MaxRow(), 00 SAY HB_PROMPT + @ Row(), Col() GET cLine PICTURE "@KS79" + + SetCursor( IIF( ReadInsert(), SC_INSERT, SC_NORMAL ) ) + + bKeyIns := SetKey( K_INS, ; + {|| SetCursor( IIF( ReadInsert( !ReadInsert() ), ; + SC_NORMAL, SC_INSERT ) ) } ) + bKeyUp := SetKey( K_UP, ; + {|| IIF( nHistIndex > 1, ; + cLine := aHistory[ --nHistIndex ], ) } ) + bKeyDown := SetKey( K_DOWN, ; + {|| cLine := IIF( nHistIndex < LEN( aHistory ), ; + aHistory[ ++nHistIndex ], ; + ( nHistIndex := LEN( aHistory ) + 1, Space( HB_LINE_LEN ) ) ) } ) + + READ + + SetKey( K_DOWN, bKeyDown ) + SetKey( K_UP, bKeyUp ) + SetKey( K_INS, bKeyIns ) + + IF LastKey() == K_ESC .OR. EMPTY( cLine ) + cLine := NIL + LOOP + ENDIF + + IF EMPTY( aHistory ) .OR. ! ATAIL( aHistory ) == cLine + IF LEN( aHistory ) < HB_HISTORY_LEN + AADD( aHistory, cLine ) + ELSE + ADEL( aHistory, 1 ) + aHistory[ 1 ] := cLine + ENDIF + ENDIF + nHistIndex := LEN( aHistory ) + 1 + + cCommand := AllTrim( cLine, " " ) + cLine := NIL + @ MaxRow(), 0 CLEAR + HB_DotInfo( cCommand ) + + HB_DotExec( cCommand ) + + IF s_nRow >= MaxRow() + Scroll( 2, 0, MaxRow(), MaxCol(), 1 ) + s_nRow = MaxRow() - 1 + ENDIF + + ENDDO + ENDIF + +RETURN + +/* ********************************************************************** */ + +STATIC PROCEDURE HB_DotUsage() + + OutStd( 'Harbour "DOt Prompt" Console' + HB_OSNewLine() +; + 'Copyright 1999-2007, Przemyslaw Czerpak' + HB_OSNewLine() + ; + 'http://www.harbour-project.org' + HB_OSNewLine() +; + HB_OSNewLine() +; + 'Syntax: hbdot [ []]' + HB_OSNewLine() + ; + HB_OSNewLine() +; + "Note: Linked with " + Version() + HB_OSNewLine() ) + +RETURN + +/* ********************************************************************** */ + +STATIC PROCEDURE HB_DotInfo( cCommand ) + + LOCAL r := Row(), c := Col() + + IF cCommand != NIL + DispOutAt( 0, 0, "PP: " ) + DispOutAt( 0, 4, PadR( cCommand, MaxCol() - 3 ), "N/R" ) + ENDIF + IF Used() + DispOutAt( 1, 0, ; + PadR( "RDD: " + PadR( RddName(), 6 ) + ; + " | Area:" + Str( Select(), 3 ) + ; + " | Dbf: " + PadR( Alias(), 10 ) + ; + " | Index: " + PadR( OrdName( IndexOrd() ), 8 ) + ; + " | # " + Str( RecNo(), 7 ) + "/" + Str( RecCount(), 7 ), ; + MaxCol() + 1 ), "N/BG" ) + ELSE + DispOutAt( 1, 0, ; + PadR( "RDD: " + Space( 6 ) + ; + " | Area:" + Space( 3 ) + ; + " | Dbf: " + Space( 10 ) + ; + " | Index: " + Space( 8 ) + ; + " | # " + Space( 7 ) + "/" + Space( 7 ), ; + MaxCol() + 1 ), "N/BG" ) + ENDIF + SetPos( r, c ) + +RETURN + +/* ********************************************************************** */ + +STATIC PROCEDURE HB_DotErr( oErr, cCommand ) + + LOCAL xArg, cMessage + + cMessage := "Sorry, could not execute:;;" + cCommand + ";;" + IF oErr:ClassName == "ERROR" + cMessage += oErr:Description + IF ValType( oErr:Args ) == 'A' .AND. Len( oErr:Args ) > 0 + cMessage += ";Arguments:" + FOR EACH xArg IN oErr:Args + cMessage += ";" + HB_CStr( xArg ) + NEXT + ENDIF + ELSEIF ValType( oErr ) == 'C' + cMessage += oErr + ENDIF + cMessage += ";;" + ProcName( 2 ) + '(' + LTrim( Str( ProcLine( 2 ) ) ) + ')' + + Alert( cMessage ) + + BREAK( oErr ) + +/* ********************************************************************** */ + +STATIC PROCEDURE HB_DotExec( cCommand ) + LOCAL oHRB, cHRB, cFunc, bBlock, cEol + + cEol := hb_osNewLine() + cFunc := "STATIC FUNC __HBDOT()" + cEol + ; + "RETURN {||" + cEol + ; + " " + cCommand + cEol + ; + " RETURN __MVSETBASE()" + cEol + ; + "}" + cEol + + BEGIN SEQUENCE WITH {|oErr| HB_DotErr( oErr, cCommand ) } + + cHRB := HB_COMPILEFROMBUF( cFunc, HB_ARGV( 0 ), "-n", "-q2", s_aIncDir ) + IF cHRB == NIL + EVAL( ErrorBlock(), "Syntax error." ) + ELSE + oHRB := hrbHolder():New( cHRB ) + bBlock := oHRB:do() + + DevPos( s_nRow, s_nCol ) + Eval( bBlock ) + s_nRow := Row() + s_nCol := Col() + IF s_nRow < 2 + s_nRow := 2 + ENDIF + + ENDIF + + END SEQUENCE + + oHRB := NIL + + __MVSETBASE() + +RETURN + +/* ********************************************************************** */ + +CREATE CLASS hrbHolder STATIC + VAR pHRB + METHOD init( cHRB ) + METHOD do() + DESTRUCTOR hrbDestruct +ENDCLASS + +METHOD init( cHRB ) + ::pHRB := __hrbLoad( cHRB ) +RETURN Self + +METHOD do() + IF ::pHRB != NIL + RETURN __hrbDo( ::pHRB ) + ENDIF +RETURN NIL + +METHOD PROCEDURE hrbDestruct + IF ::pHRB != NIL + __hrbUnLoad( ::pHRB ) + ENDIF +RETURN + +/* ********************************************************************** */ + +/* request about full screen GT driver */ +#if defined( __PLATFORM__UNIX ) +REQUEST HB_GT_TRM_DEFAULT +#elif defined( __PLATFORM__Windows ) +REQUEST HB_GT_WIN_DEFAULT +#elif defined( __PLATFORM__DOS ) +REQUEST HB_GT_DOS_DEFAULT +#elif defined( __PLATFORM__OS2 ) +REQUEST HB_GT_OS2_DEFAULT +#endif + +/* ********************************************************************** */