From e41b82be36562b5e40b97371666251850fadad7b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 7 Apr 2013 11:03:48 +0200 Subject: [PATCH] 2013-04-07 10:59 UTC+0200 Viktor Szakats (harbour syenar.net) * contrib/Makefile ! do not ignore failures in contribs in GNU Make build process (this will ensure a 'build failed' status in Travis) * bin/check.hb * tests/fixcase.hb ! fixed to the way search hits are replaced. Now it replaces only what it found and where it found it, instead of previous brute-force method of replacing each similar hit in the file, causing the errors experienced in 2013-04-05 16:24 UTC+0200. (plus also few similar cases in the past) * tests/fixcase.hb ! fixed to do comment only fix on .c files even when run in single file mode --- ChangeLog.txt | 17 +++++++++++++ bin/check.hb | 28 ++++++++++++--------- contrib/Makefile | 2 +- tests/fixcase.hb | 64 ++++++++++++++++++++++++++++-------------------- 4 files changed, 71 insertions(+), 40 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 486e56ce8b..c4d8336a66 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,23 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2013-04-07 10:59 UTC+0200 Viktor Szakats (harbour syenar.net) + * contrib/Makefile + ! do not ignore failures in contribs in GNU Make build process + (this will ensure a 'build failed' status in Travis) + + * bin/check.hb + * tests/fixcase.hb + ! fixed to the way search hits are replaced. Now it replaces + only what it found and where it found it, instead of previous + brute-force method of replacing each similar hit in the file, + causing the errors experienced in 2013-04-05 16:24 UTC+0200. + (plus also few similar cases in the past) + + * tests/fixcase.hb + ! fixed to do comment only fix on .c files even when run in + single file mode + 2013-04-07 03:48 UTC+0200 Viktor Szakats (harbour syenar.net) * package/mpkg_win_nightly.bat ! delete source zip before download diff --git a/bin/check.hb b/bin/check.hb index 018a4b9ee2..304b5cf086 100644 --- a/bin/check.hb +++ b/bin/check.hb @@ -770,7 +770,7 @@ STATIC FUNCTION FixFuncCase( cFileName ) LOCAL cFile LOCAL cFileStripped - LOCAL a + LOCAL match LOCAL cProper LOCAL cOldCP @@ -797,27 +797,31 @@ STATIC FUNCTION FixFuncCase( cFileName ) cOldCP := hb_cdpSelect( "EN" ) - FOR EACH a IN hb_regexAll( "([A-Za-z] |[^A-Za-z_:]|^)([A-Za-z_][A-Za-z0-9_]+\()", cFileStripped,,,,, .T. ) - IF Len( a[ 2 ] ) != 2 .OR. !( Left( a[ 2 ], 1 ) $ "D" /* "METHOD" */ ) - cProper := ProperCase( hAll, hb_StrShrink( a[ 3 ] ) ) + "(" - IF !( cProper == a[ 3 ] ) .AND. ; + #define _MATCH_cStr 1 + #define _MATCH_nStart 2 + #define _MATCH_nEnd 3 + + FOR EACH match IN hb_regexAll( "([A-Za-z] |[^A-Za-z_:]|^)([A-Za-z_][A-Za-z0-9_]+\()", cFileStripped,,,,, .F. ) + IF Len( match[ 2 ][ _MATCH_cStr ] ) != 2 .OR. !( Left( match[ 2 ][ _MATCH_cStr ], 1 ) $ "D" /* "METHOD" */ ) + cProper := ProperCase( hAll, hb_StrShrink( match[ 3 ][ _MATCH_cStr ] ) ) + "(" + IF !( cProper == match[ 3 ][ _MATCH_cStr ] ) .AND. ; !( Upper( cProper ) == Upper( "FILE(" ) ) .AND. ; /* interacts with "file(s)" text */ !( Upper( cProper ) == Upper( "TOKEN(" ) ) .AND. ; /* interacts with "token(s)" text */ !( Upper( cProper ) == Upper( "INT(" ) ) .AND. ; /* interacts with SQL statements */ ( ! lPartial .OR. !( "|" + Lower( cProper ) + "|" $ Lower( "|Max(|Min(|FOpen(|Abs(|Log10(|GetEnv(|Sqrt(|Rand(|IsDigit(|IsAlpha(|" ) ) ) - cFile := StrTran( cFile, a[ 1 ], StrTran( a[ 1 ], a[ 3 ], cProper ) ) - ? cFileName, a[ 3 ], cProper, "|" + a[ 1 ] + "|" + cFile := Left( cFile, match[ 3 ][ _MATCH_nStart ] - 1 ) + cProper + SubStr( cFile, match[ 3 ][ _MATCH_nEnd ] + 1 ) + ? cFileName, match[ 3 ][ _MATCH_cStr ], cProper, "|" + match[ 1 ][ _MATCH_cStr ] + "|" nChanged++ ENDIF ENDIF NEXT IF !( "hbclass.ch" $ cFileName ) .AND. ! lPartial - FOR EACH a IN hb_regexAll( "(?:REQUEST|EXTERNAL|EXTERNA|EXTERN)[ \t]+([A-Za-z_][A-Za-z0-9_]+)", cFile,,,,, .T. ) - cProper := ProperCase( hAll, a[ 2 ] ) - IF !( cProper == a[ 2 ] ) - cFile := StrTran( cFile, a[ 1 ], StrTran( a[ 1 ], a[ 2 ], cProper ) ) - OutStd( cFileName, a[ 2 ], cProper, "|" + a[ 1 ] + "|" + hb_eol() ) + FOR EACH match IN hb_regexAll( "(?:REQUEST|EXTERNAL|EXTERNA|EXTERN)[ \t]+([A-Za-z_][A-Za-z0-9_]+)", cFile,,,,, .T. ) + cProper := ProperCase( hAll, match[ 2 ] ) + IF !( cProper == match[ 2 ] ) + cFile := StrTran( cFile, match[ 1 ], StrTran( match[ 1 ], match[ 2 ], cProper ) ) + OutStd( cFileName, match[ 2 ], cProper, "|" + match[ 1 ] + "|" + hb_eol() ) nChanged++ ENDIF NEXT diff --git a/contrib/Makefile b/contrib/Makefile index 28500347d9..1761703a2d 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -6,6 +6,6 @@ include $(ROOT)config/global.mk ifneq ($(HB_NO_HBSCRIPT),yes) first clean install:: - $(if $(wildcard $(HB_HOST_BIN_DIR)/hbmk2$(HB_HOST_BIN_EXT)),-$(HB_HOST_BIN_DIR)/hbmk2$(HB_HOST_BIN_EXT) $(TOP)$(ROOT)contrib/make.hb $@,@$(ECHO) $(ECHOQUOTE)! Warning: hbmk2 not found, contrib/make.hb skipped.$(ECHOQUOTE)) + $(if $(wildcard $(HB_HOST_BIN_DIR)/hbmk2$(HB_HOST_BIN_EXT)),$(HB_HOST_BIN_DIR)/hbmk2$(HB_HOST_BIN_EXT) $(TOP)$(ROOT)contrib/make.hb $@,@$(ECHO) $(ECHOQUOTE)! Warning: hbmk2 not found, contrib/make.hb skipped.$(ECHOQUOTE)) endif diff --git a/tests/fixcase.hb b/tests/fixcase.hb index 9da64aceb3..5f9a1dd62a 100644 --- a/tests/fixcase.hb +++ b/tests/fixcase.hb @@ -26,8 +26,12 @@ PROCEDURE Main( cFile ) LOCAL hAll := { => } - LOCAL hExtExceptions := { ; - hb_libExt() =>, ; + STATIC sc_hExtExceptions := { ; + ".dll" =>, ; + ".dxe" =>, ; + ".dylib" =>, ; + ".so" =>, ; + ".sl" =>, ; ".zip" =>, ; ".7z" =>, ; ".exe" =>, ; @@ -61,12 +65,7 @@ PROCEDURE Main( cFile ) ".sq3" =>, ; ".tif" => } - LOCAL hPartial := { ; - ".c" =>, ; - ".h" =>, ; - ".api" => } - - LOCAL hFileExceptions := { ; + STATIC sc_hFileExceptions := { ; "ChangeLog.txt" =>, ; "std.ch" =>, ; "wcecon.prg" =>, ; @@ -91,7 +90,7 @@ PROCEDURE Main( cFile ) "tracing.txt" =>, ; "pcode.txt" => } - LOCAL aMaskExceptions := { ; + STATIC sc_aMaskExceptions := { ; "src/3rd/*" , ; "contrib/3rd/*" , ; "contrib/*/3rd/*" , ; @@ -115,27 +114,34 @@ PROCEDURE Main( cFile ) FOR EACH aFile IN hb_DirScan( "", hb_osFileMask() ) cExt := hb_FNameExt( aFile[ F_NAME ] ) IF ! Empty( cExt ) .AND. ; - !( cExt $ hExtExceptions ) .AND. ; - !( hb_FNameNameExt( aFile[ F_NAME ] ) $ hFileExceptions ) .AND. ; - AScan( aMaskExceptions, {| tmp | hb_FileMatch( StrTran( aFile[ F_NAME ], "\", "/" ), tmp ) } ) == 0 - ProcFile( hAll, aFile[ F_NAME ], cExt $ hPartial ) + !( cExt $ sc_hExtExceptions ) .AND. ; + !( hb_FNameNameExt( aFile[ F_NAME ] ) $ sc_hFileExceptions ) .AND. ; + AScan( sc_aMaskExceptions, {| tmp | hb_FileMatch( StrTran( aFile[ F_NAME ], "\", "/" ), tmp ) } ) == 0 + ProcFile( hAll, aFile[ F_NAME ] ) ENDIF NEXT ENDIF RETURN -STATIC PROCEDURE ProcFile( hAll, cFileName, lPartial ) +STATIC PROCEDURE ProcFile( hAll, cFileName ) + + STATIC sc_hPartial := { ; + ".c" =>, ; + ".cpp" =>, ; + ".h" =>, ; + ".api" => } LOCAL cFile := MemoRead( cFileName ) LOCAL cFileStripped - LOCAL a + LOCAL match LOCAL cProper + LOCAL lPartial LOCAL nChanged := 0 - hb_default( @lPartial, .F. ) + lPartial := hb_FNameExt( cFileName ) $ sc_hPartial IF lPartial cFileStripped := GetCComments( cFile ) @@ -143,27 +149,31 @@ STATIC PROCEDURE ProcFile( hAll, cFileName, lPartial ) cFileStripped := cFile ENDIF - FOR EACH a IN hb_regexAll( "([A-Za-z] |[^A-Za-z_:]|^)([A-Za-z_][A-Za-z0-9_]+\()", cFileStripped,,,,, .T. ) - IF Len( a[ 2 ] ) != 2 .OR. !( Left( a[ 2 ], 1 ) $ "D" /* "METHOD" */ ) - cProper := ProperCase( hAll, hb_StrShrink( a[ 3 ] ) ) + "(" - IF !( cProper == a[ 3 ] ) .AND. ; + #define _MATCH_cStr 1 + #define _MATCH_nStart 2 + #define _MATCH_nEnd 3 + + FOR EACH match IN hb_regexAll( "([A-Za-z] |[^A-Za-z_:]|^)([A-Za-z_][A-Za-z0-9_]+\()", cFileStripped,,,,, .F. ) + IF Len( match[ 2 ][ _MATCH_cStr ] ) != 2 .OR. !( Left( match[ 2 ][ _MATCH_cStr ], 1 ) $ "D" /* "METHOD" */ ) + cProper := ProperCase( hAll, hb_StrShrink( match[ 3 ][ _MATCH_cStr ] ) ) + "(" + IF !( cProper == match[ 3 ][ _MATCH_cStr ] ) .AND. ; !( Upper( cProper ) == Upper( "FILE(" ) ) .AND. ; /* interacts with "file(s)" text */ !( Upper( cProper ) == Upper( "TOKEN(" ) ) .AND. ; /* interacts with "token(s)" text */ !( Upper( cProper ) == Upper( "INT(" ) ) .AND. ; /* interacts with SQL statements */ ( ! lPartial .OR. !( "|" + Lower( cProper ) + "|" $ Lower( "|Max(|Min(|FOpen(|Abs(|Log10(|GetEnv(|Sqrt(|Rand(|IsDigit(|IsAlpha(|" ) ) ) - cFile := StrTran( cFile, a[ 1 ], StrTran( a[ 1 ], a[ 3 ], cProper ) ) - ? cFileName, a[ 3 ], cProper, "|" + a[ 1 ] + "|" + cFile := Left( cFile, match[ 3 ][ _MATCH_nStart ] - 1 ) + cProper + SubStr( cFile, match[ 3 ][ _MATCH_nEnd ] + 1 ) + ? cFileName, match[ 3 ][ _MATCH_cStr ], cProper, "|" + match[ 1 ][ _MATCH_cStr ] + "|" nChanged++ ENDIF ENDIF NEXT IF !( "hbclass.ch" $ cFileName ) .AND. ! lPartial - FOR EACH a IN hb_regexAll( "(?:REQUEST|EXTERNAL|EXTERNA|EXTERN)[ \t]+([A-Za-z_][A-Za-z0-9_]+)", cFile,,,,, .T. ) - cProper := ProperCase( hAll, a[ 2 ] ) - IF !( cProper == a[ 2 ] ) - cFile := StrTran( cFile, a[ 1 ], StrTran( a[ 1 ], a[ 2 ], cProper ) ) - ? cFileName, a[ 2 ], cProper, "|" + a[ 1 ] + "|" + FOR EACH match IN hb_regexAll( "(?:REQUEST|EXTERNAL|EXTERNA|EXTERN)[ \t]+([A-Za-z_][A-Za-z0-9_]+)", cFile,,,,, .T. ) + cProper := ProperCase( hAll, match[ 2 ] ) + IF !( cProper == match[ 2 ] ) + cFile := StrTran( cFile, match[ 1 ], StrTran( match[ 1 ], match[ 2 ], cProper ) ) + ? cFileName, match[ 2 ], cProper, "|" + match[ 1 ] + "|" nChanged++ ENDIF NEXT