From 8e57711e1d59518a27990b7ed5e68541fece0ab5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 19 Feb 2013 01:02:32 +0000 Subject: [PATCH] 2013-02-19 02:01 UTC+0100 Viktor Szakats (harbour syenar.net) * utils/hbmk2/hbmk2.prg ! fixed -find to continue search for substrings after a full match (f.e. hbmk2 -find str) + documented shell script API calls + new help section format for above + ensure -n2 build and enable warning settings to help building into an .hrb (quite fun to run hbmk2/hbrun as a hbrun script!) ! FuncNameEncode() "fixed" to be in sync with how Harbour compiler (incorrectly) encodes function names. This fixes: 'hbmk2 1.prg' ; TOFIX: ? hb_compGenCFunc() in src/compiler to encode the first character of a function if it's a digit. * doc/pragma.txt * src/pp/ppcore.c ! fixed '#pragma nostartproc'. Only 'off' worked, 'on' was silently ignored since who-knows-when (pointer to int type received HB_BOOL value). Now it will accept a numeric value in sync with '-n' option. [INCOMPATIBLE] ; TOFIX: It still doesn't work. Not does existing '#pragma -n2' Pbly it's too late to set this while compiling, or it needs deeper modifications. Or delete if unfixable. --- test_n2.prg #pragma tracepragmas=on #pragma -n2 #pragma -w3 STATIC stat := "stat" PROCEDURE Main() ? stat /* ISSUE: warning appears without cmdline -n2 option */ RETURN --- $ harbour test_n2 $ harbour test_n2 -n2 * README.txt * minor sync with hbmk2 help --- harbour/ChangeLog.txt | 49 ++++++++++++-- harbour/README.txt | 3 +- harbour/doc/pragma.txt | 24 +++---- harbour/src/pp/ppcore.c | 4 +- harbour/utils/hbmk2/hbmk2.prg | 120 ++++++++++++++++++++++++---------- 5 files changed, 146 insertions(+), 54 deletions(-) diff --git a/harbour/ChangeLog.txt b/harbour/ChangeLog.txt index 3b4d384182..4330e605dd 100644 --- a/harbour/ChangeLog.txt +++ b/harbour/ChangeLog.txt @@ -10,6 +10,47 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2013-02-19 02:01 UTC+0100 Viktor Szakats (harbour syenar.net) + * utils/hbmk2/hbmk2.prg + ! fixed -find to continue search for substrings + after a full match (f.e. hbmk2 -find str) + + documented shell script API calls + + new help section format for above + + ensure -n2 build and enable warning settings to + help building into an .hrb + (quite fun to run hbmk2/hbrun as a hbrun script!) + ! FuncNameEncode() "fixed" to be in sync with how + Harbour compiler (incorrectly) encodes function names. + This fixes: 'hbmk2 1.prg' + ; TOFIX: ? hb_compGenCFunc() in src/compiler to encode + the first character of a function if it's a digit. + + * doc/pragma.txt + * src/pp/ppcore.c + ! fixed '#pragma nostartproc'. Only 'off' worked, 'on' + was silently ignored since who-knows-when (pointer to + int type received HB_BOOL value). Now it will accept + a numeric value in sync with '-n' option. [INCOMPATIBLE] + ; TOFIX: It still doesn't work. Not does existing '#pragma -n2' + Pbly it's too late to set this while compiling, + or it needs deeper modifications. + Or delete if unfixable. + --- test_n2.prg + #pragma tracepragmas=on + #pragma -n2 + + #pragma -w3 + STATIC stat := "stat" + PROCEDURE Main() + ? stat /* ISSUE: warning appears without cmdline -n2 option */ + RETURN + --- + $ harbour test_n2 + $ harbour test_n2 -n2 + + * README.txt + * minor sync with hbmk2 help + 2013-02-19 01:48 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * harbour/src/codepage/l_sr_cyr.h ! restored original Serbian collation by Srdjan Dragojlovic - thanks. @@ -24,7 +65,7 @@ 2013-12-18 15:40 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/gtwvg/gtwgud.c * contrib/gtwvg/gtwvgd.c - + Allied: Rolf supplied patch but with changes. Now GTWVG is + + Allied: Rolf supplied patch but with changes. Now GTWVG is equal to GTWVT in many respects. 2013-02-18 17:32 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) @@ -76,7 +117,7 @@ value (it was so far only mentioned next to HBMK_HAS_ envvar) + documented exit codes in help text - * minor tweaks to some help lines + * minor tweaks on some help lines * cleanup for Markdown formatting internals * plugin callback variable "nErrorLevel" renamed to "nExitCode" [INCOMPATIBLE] @@ -160,7 +201,7 @@ * utils/hbmk2/hbmk2.prg ! avoided one ASCII code dependent comparison - ! added missing value value validation for -incpath= option + ! missing value validation for -incpath= option * minor internal cleanups 2013-02-16 15:09 UTC+0100 Viktor Szakats (harbour syenar.net) @@ -169,7 +210,7 @@ 2013-02-15 19:21 UTC+0100 Viktor Szakats (harbour syenar.net) * utils/hbmk2/hbmk2.prg - + reminaing STRTRAN() to HB_STRXCHG() update. + + remaining STRTRAN() to HB_STRXCHG() update * converted few NOTEs to TODOs to eliminate few cases of recursive macros (which exploited side-effect of repeated STRTRAN() calls) diff --git a/harbour/README.txt b/harbour/README.txt index 5bb107faf4..1627f8016f 100644 --- a/harbour/README.txt +++ b/harbour/README.txt @@ -1432,7 +1432,8 @@ TABLE OF CONTENT - To run a Harbour script: 'hbmk2 script.hb []' - Examples to build and run Harbour portable binary (aka precompiled script): + Examples to build and run Harbour portable binary + (aka precompiled Harbour script): - To build: 'hbmk2 -gh script.hb' diff --git a/harbour/doc/pragma.txt b/harbour/doc/pragma.txt index 5d524c0c69..b548923a09 100644 --- a/harbour/doc/pragma.txt +++ b/harbour/doc/pragma.txt @@ -43,19 +43,19 @@ This is the list of the supported commands and switches: * Command Switch ----------------------------------------------- - * AUTOMEMVAR = /A<+/-> - * DEBUGINFO = /B<+/-> - * DYNAMICMEMVAR = /V<+/-> - * ENABLEWARNINGS = /W<+/-> + * AUTOMEMVAR = -a<+/-> + * DEBUGINFO = -b<+/-> + * DYNAMICMEMVAR = -v<+/-> + * ENABLEWARNINGS = -w<+/-> * ESCAPEDSTRINGS = - * EXITSEVERITY = /E - * LINENUMBER = /L<+/-> - * NOSTARTPROC = /N<+/-> - * PREPROCESSING = /P<+/-> - * SHORTCUT = /Z<+/-> + * EXITSEVERITY = -es + * LINENUMBER = -l<+/-> + * NOSTARTPROC = -n + * PREPROCESSING = -p<+/-> + * SHORTCUT = -z<+/-> * TEXTHIDDEN = - * TRACE = /P+ - * WARNINGLEVEL = /W + * TRACE = -p+ + * WARNINGLEVEL = -w The switches have the same behavior as the corresponding compiler ones and the commands are synonyms for the switches. @@ -76,7 +76,7 @@ preprocessor. EXAMPLES ======== -#pragma NoStartProc=Off +#pragma NoStartProc=0 /* #pragma /N- */ FUNCTION Test() diff --git a/harbour/src/pp/ppcore.c b/harbour/src/pp/ppcore.c index 525e884c13..9355f366da 100644 --- a/harbour/src/pp/ppcore.c +++ b/harbour/src/pp/ppcore.c @@ -2720,9 +2720,9 @@ static void hb_pp_pragmaNew( PHB_PP_STATE pState, PHB_PP_TOKEN pToken ) } else if( hb_pp_tokenValueCmp( pToken, "NOSTARTPROC", HB_PP_CMP_DBASE ) ) { - pValue = hb_pp_pragmaGetLogical( pToken->pNext, &fValue ); + pValue = hb_pp_pragmaGetInt( pToken->pNext, &iValue ); if( pValue ) - fError = hb_pp_setCompilerSwitch( pState, "n", fValue ); + fError = hb_pp_setCompilerSwitch( pState, "n", iValue ); else fError = HB_TRUE; } diff --git a/harbour/utils/hbmk2/hbmk2.prg b/harbour/utils/hbmk2/hbmk2.prg index 5ba7773363..cfaa439960 100644 --- a/harbour/utils/hbmk2/hbmk2.prg +++ b/harbour/utils/hbmk2/hbmk2.prg @@ -58,6 +58,14 @@ * */ +#if __pragma( n ) == 2 + /* Keeping it tidy */ + #pragma -w3 + #pragma -es2 +#else + #error Missing required Harbour option: -n2 +#endif + /* Optimizations */ #pragma -km+ #pragma -ko+ @@ -11399,7 +11407,8 @@ STATIC FUNCTION FuncNameEncode( cName ) cResult := "" FOR nPos := 1 TO hb_BLen( cName ) c := hb_BSubStr( cName, nPos, 1 ) - IF c == "_" .OR. hb_asciiIsAlpha( c ) .OR. ( ! cResult == "" .AND. hb_asciiIsDigit( c ) ) + IF c == "_" .OR. hb_asciiIsAlpha( c ) .OR. ; + hb_asciiIsDigit( c ) /* synced to how Harbour compiler works (see hb_compGenCFunc()). In theory should be: ( ! cResult == "" .AND. hb_asciiIsDigit( c ) ) */ cResult += c ELSE cResult += "x" + Lower( hb_NumToHex( Asc( c ), 2 ) ) @@ -12835,6 +12844,7 @@ STATIC PROCEDURE ShowFunctionProviders( hbmk, aFunction, lGenericFind ) LOCAL hAll := GetListOfFunctionsKnown( hbmk, lGenericFind ) LOCAL cFunction + LOCAL lFound LOCAL aLib LOCAL tmp, tmp1 @@ -12853,16 +12863,20 @@ STATIC PROCEDURE ShowFunctionProviders( hbmk, aFunction, lGenericFind ) } FOR EACH cFunction IN aFunction DESCEND + lFound := .F. IF ( tmp := hb_HPos( hAll, cFunction ) ) > 0 - /* Get the function name in original .hbx casing */ - Eval( bAdd, hb_HKeyAt( hAll, tmp ) ) - hb_ADel( aFunction, cFunction:__enumIndex(), .T. ) - ELSEIF lGenericFind + Eval( bAdd, hb_HKeyAt( hAll, tmp ) /* Get the function name in original .hbx casing */ ) + lFound := .T. + ENDIF + IF lGenericFind FOR EACH tmp1 IN hAll IF hb_WildMatchI( "*" + cFunction + "*", tmp1:__enumKey() ) Eval( bAdd, tmp1:__enumKey() ) + lFound := .T. ENDIF NEXT + ENDIF + IF lFound hb_ADel( aFunction, cFunction:__enumIndex(), .T. ) ENDIF NEXT @@ -14165,30 +14179,30 @@ STATIC FUNCTION __hbshell_CanLoadDyn() because dynlibs are built against harbour.dll. */ RETURN hb_Version( HB_VERSION_UNIX_COMPAT ) .OR. hb_Version( HB_VERSION_SHARED ) -STATIC PROCEDURE __hbshell_Err( oErr, cCommand ) +STATIC PROCEDURE __hbshell_Err( oError, cCommand ) LOCAL xArg, cMessage cMessage := I_( "Could not execute:" ) + ";;" + cCommand + ";;" - IF oErr:ClassName() == "ERROR" - cMessage += oErr:Description - IF ! Empty( oErr:Operation ) - cMessage += " " + oErr:Operation + IF oError:ClassName() == "ERROR" + cMessage += oError:Description + IF ! Empty( oError:Operation ) + cMessage += " " + oError:Operation ENDIF - IF HB_ISARRAY( oErr:Args ) .AND. Len( oErr:Args ) > 0 + IF HB_ISARRAY( oError:Args ) .AND. Len( oError:Args ) > 0 cMessage += ";" + I_( "Arguments:" ) - FOR EACH xArg IN oErr:Args + FOR EACH xArg IN oError:Args cMessage += ";" + hb_CStr( xArg ) NEXT ENDIF - ELSEIF HB_ISSTRING( oErr ) - cMessage += oErr + ELSEIF HB_ISSTRING( oError ) + cMessage += oError ENDIF cMessage += ";;" + ProcName( 2 ) + "(" + hb_ntos( ProcLine( 2 ) ) + ")" Alert( cMessage ) - Break( oErr ) + Break( oError ) STATIC PROCEDURE __hbshell_Exec( cCommand ) @@ -14215,7 +14229,7 @@ STATIC PROCEDURE __hbshell_Exec( cCommand ) DevPos( s_nRow, s_nCol ) - BEGIN SEQUENCE WITH {| oErr | __hbshell_Err( oErr, cCommand ) } + BEGIN SEQUENCE WITH {| oError | __hbshell_Err( oError, cCommand ) } /* We can use this function as this is a GPL licenced application */ cHRB := hb_compileFromBuf( cFunc, hbmk_CoreHeaderFiles(), hb_ProgName(), "-n2", "-q2", hb_ArrayToParams( aOPTPRG ) ) @@ -14453,7 +14467,7 @@ STATIC FUNCTION __hbshell_TryHeader( cName ) LOCAL lRetVal := .F. - BEGIN SEQUENCE WITH {| oErr | Break( oErr ) } + BEGIN SEQUENCE WITH {| oError | Break( oError ) } IF ! Empty( hb_compileFromBuf( "", hbmk_CoreHeaderFiles(), hb_ProgName(), "-q2", ; "-i" + s_hbmk[ _HBMK_cHB_INSTALL_INC ], ; @@ -15390,7 +15404,7 @@ STATIC PROCEDURE ShowHelp( hbmk, lFull, lLong ) { "*.hbm" , I_( "collection of options. Can be used to collect common ones into a file and include that into project files. Lines beginning with '#' character are ignored, otherwise newline is optional, same rules apply as for the command-line." ) }, ; { "*.hbc" , I_( "collection of options that accompany components (aka 'libs', aka packages). Use different syntax than command-line and .hbp/.hbm files. Lines beginning with '#' character are ignored, each directive must be placed in separate lines." ) }, ; { "*.hb" , I_( "Harbour script" ) }, ; - { "*.hrb" , I_( "Harbour portable binary (aka precompiled script)" ) }, ; + { "*.hrb" , I_( "Harbour portable binary (aka precompiled Harbour script)" ) }, ; { "*.ch" , I_( "if passed directly as a source file, it will be used as additional standard header" ) }, ; { _HBMK_AUTOHBC_NAME , hb_StrFormat( I_( "standard .hbc file that gets automatically processed, if present. Possible location(s) (in order of precedence) [*]: %1$s" ), ArrayToList( AutoConfPathList( .F., hbmk[ _HBMK_lMarkdown ] ), ", " ) ) }, ; { _HBMK_AUTOHBM_NAME , I_( "optional .hbm file residing in current working directory, which gets automatically processed before other options" ) }, ; @@ -15578,6 +15592,23 @@ STATIC PROCEDURE ShowHelp( hbmk, lFull, lLong ) { hb_StrFormat( _HBMK_DIR_TPL, I_( "" ) ) , I_( "return the header directory where was detected, or empty if it wasn't." ) }, ; { hb_StrFormat( _HBMK_HAS_TPL_LOCAL, I_( "" ) ) , I_( "when dependency was detected in a location configured by -depincpathlocal= option" ) } } +#ifndef _HBMK_EMBEDDED_ + LOCAL aHdr_APIShell := { ; + "", ; + I_( "Shell API available in Harbour scripts:" ) } + + LOCAL aLst_APIShell := { ; + NIL, ; + { "hbshell_gtSelect( [] ) -> NIL" , hb_StrFormat( I_( "Switch GT. Default [*]: '%1$s'" ), Lower( __hbshell_gtDefault() ) ) }, ; + { "hbshell_include( ) -> " , I_( "Load Harbour header." ) }, ; + { "hbshell_uninclude( ) -> " , I_( "Unload Harbour header." ) }, ; + { "hbshell_ext_load( ) -> " , I_( "Load package. Similar to #request PP directive." ) }, ; + { "hbshell_ext_unload( ) -> ", I_( "Unload package." ) }, ; + { "hbshell_ext_get_list() -> " , I_( "List of loaded packages." ) }, ; + { "hbshell_DirBase() -> " , I_( "DirBase() not mapped to script." ) }, ; + { "hbshell_ProgName() -> " , I_( "ProgName() not mapped to script." ) } } +#endif + LOCAL aHdr_Notes := { ; "", ; I_( "Notes:" ) } @@ -15639,6 +15670,10 @@ STATIC PROCEDURE ShowHelp( hbmk, lFull, lLong ) AEval( aLst_EnvVar, {| tmp | OutOpt( hbmk, tmp ) } ) AEval( aHdr_HBC, {| tmp | OutHdr( hbmk, tmp + _OUT_EOL ) } ) AEval( aLst_HBC, {| tmp | OutOpt( hbmk, tmp ) } ) +#ifndef _HBMK_EMBEDDED_ + AEval( aHdr_APIShell, {| tmp | OutHdr( hbmk, tmp + _OUT_EOL ) } ) + AEval( aLst_APIShell, {| tmp | OutOpt( hbmk, tmp, -1 ) } ) +#endif /* TODO: Move to separate section from notes: - description - filter and macro syntax, %{}, subprojects @@ -15666,11 +15701,7 @@ STATIC PROCEDURE ShowHelp( hbmk, lFull, lLong ) STATIC PROCEDURE OutHdr( hbmk, cText ) - IF hbmk[ _HBMK_lMarkdown ] - cText := ToMarkdown( cText ) - ENDIF - - OutStd( cText ) + OutStd( iif( hbmk[ _HBMK_lMarkdown ], ToMarkdown( cText ), cText ) ) RETURN @@ -15679,28 +15710,47 @@ STATIC PROCEDURE OutOpt( hbmk, aOpt, nWidth ) LOCAL nLine LOCAL nLines + hb_default( @nWidth, 23 ) + IF Empty( aOpt ) IF hbmk[ _HBMK_lMarkdown ] OutStd( _OUT_EOL ) + OutStd( _OUT_EOL ) + ELSE + IF nWidth >= 0 + OutStd( _OUT_EOL ) + ENDIF ENDIF - OutStd( _OUT_EOL ) ELSE IF Len( aOpt ) > 1 - hb_default( @nWidth, 23 ) IF hbmk[ _HBMK_lMarkdown ] - IF nWidth > 0 - OutStd( " - " + ToMarkdown( aOpt[ 1 ], iif( Empty( aOpt[ 2 ] ), NIL, "strong" ) ) + " " + ToMarkdown( aOpt[ 2 ] ) + _OUT_EOL ) - ELSE + IF nWidth == 0 OutStd( ToMarkdown( aOpt[ 2 ] ) + _OUT_EOL ) + ELSE + OutStd( ; + " - " + ; + ToMarkdown( aOpt[ 1 ], iif( Empty( aOpt[ 2 ] ), NIL, "strong" ) ) + ; + iif( nWidth < 0, ToMarkdown( e"\n" ), " " ) + ; + ToMarkdown( aOpt[ 2 ] ) + _OUT_EOL ) ENDIF ELSE - aOpt[ 2 ] := StrTran( aOpt[ 2 ], e"\n", hb_eol() ) - nLines := Max( MLCount( aOpt[ 2 ], hbmk[ _HBMK_nMaxCol ] - nWidth ), ; - MLCount( aOpt[ 1 ], nWidth ) ) - FOR nLine := 1 TO nLines - OutStd( PadR( Space( 2 ) + MemoLine( aOpt[ 1 ], nWidth, nLine ), nWidth ) ) - OutStd( RTrim( MemoLine( aOpt[ 2 ], hbmk[ _HBMK_nMaxCol ] - nWidth, nLine ) ) + _OUT_EOL ) - NEXT + IF nWidth >= 0 + aOpt[ 2 ] := StrTran( aOpt[ 2 ], e"\n", hb_eol() ) + nLines := Max( MLCount( aOpt[ 2 ], hbmk[ _HBMK_nMaxCol ] - nWidth ), ; + MLCount( aOpt[ 1 ], nWidth ) ) + FOR nLine := 1 TO nLines + OutStd( PadR( Space( 2 ) + MemoLine( aOpt[ 1 ], nWidth, nLine ), nWidth ) ) + OutStd( RTrim( MemoLine( aOpt[ 2 ], hbmk[ _HBMK_nMaxCol ] - nWidth, nLine ) ) + _OUT_EOL ) + NEXT + ELSE + nWidth := 8 + OutStd( _OUT_EOL + Space( 2 ) + aOpt[ 1 ] + _OUT_EOL ) + aOpt[ 2 ] := StrTran( aOpt[ 2 ], e"\n", hb_eol() ) + nLines := MLCount( aOpt[ 2 ], hbmk[ _HBMK_nMaxCol ] - nWidth ) + FOR nLine := 1 TO nLines + OutStd( Space( nWidth ) + RTrim( MemoLine( aOpt[ 2 ], hbmk[ _HBMK_nMaxCol ] - nWidth, nLine ) ) + _OUT_EOL ) + NEXT + ENDIF ENDIF ELSE IF hbmk[ _HBMK_lMarkdown ]