2013-04-07 22:41 UTC+0200 Viktor Szakats (harbour syenar.net)

* bin/commit.hb
    + do not add new empty entry template if one already
      exist, replace existing one instead
    + put last changelog entry to clipboard on pre-commit

  * bin/check.hb
    * refined and sorted exceptions for case checking

  * bin/check.hb
  - tests/fixcase.hb
    - deleted stdalong case fixer, now part of bin/check.hb
      (call it it --fixup-case option for same functionality)

  * doc/oldnews.txt
  * doc/pp.txt
    * casing fixes
This commit is contained in:
Viktor Szakats
2013-04-07 22:45:23 +02:00
parent fb930b3083
commit f4ebdfd48b
6 changed files with 377 additions and 498 deletions

View File

@@ -45,7 +45,7 @@ FUNCTION CheckFileList( xName )
LOCAL lApplyFixes := "--fixup" $ hb_CmdLine()
IF HB_ISSTRING( xName )
xName := { xName }
xName := iif( Left( xName, 2 ) == "--", NIL, { xName } )
ENDIF
IF Empty( xName ) .OR. HB_ISARRAY( xName )
@@ -55,14 +55,22 @@ FUNCTION CheckFileList( xName )
hb_cwd( s )
lApplyFixes := .F. /* do not allow to mass fix all files */
ENDIF
FOR EACH file IN xName
IF ! CheckFile( file, @aErr, lApplyFixes )
lPassed := .F.
FOR EACH s IN aErr
OutStd( file + ": " + s + hb_eol() )
NEXT
ENDIF
NEXT
IF "--fixup-case" $ hb_CmdLine()
FOR EACH file IN xName
IF "|" + hb_FNameExt( file ) + "|" $ "|.c|.cpp|.h|.api|.ch|.hb|.po|.prg|.md|.txt|"
FixFuncCase( file, .T. )
ENDIF
NEXT
ELSE
FOR EACH file IN xName
IF ! CheckFile( file, @aErr, lApplyFixes )
lPassed := .F.
FOR EACH s IN aErr
OutStd( file + ": " + s + hb_eol() )
NEXT
ENDIF
NEXT
ENDIF
ENDIF
RETURN lPassed
@@ -100,14 +108,14 @@ STATIC FUNCTION CheckFile( cName, /* @ */ aErr, lApplyFixes )
"*/hb-charmap.def", ; /* TOFIX: Use 8.3 name */
"debian/*", ;
"package/*", ;
"*/3rd/*", ;
"lib/3rd/*", ;
"contrib/hbwin/*", ;
"contrib/rddads/unixutils.h", ;
"extras/httpsrv/*" }
LOCAL aCanHaveNoExtension := { ;
"Makefile", ;
".*", ;
"Makefile", ;
"debian/*" }
LOCAL aCanHaveTab := { ;
@@ -116,6 +124,7 @@ STATIC FUNCTION CheckFile( cName, /* @ */ aErr, lApplyFixes )
"*.mk", ;
"*.yyc", ;
"*.dif", ;
"*.html", ;
"*.xml", ;
"*.css" }
@@ -685,9 +694,9 @@ STATIC FUNCTION my_DirScanWorker( cMask, aList )
/* ---- */
STATIC FUNCTION FixFuncCase( cFileName )
STATIC FUNCTION FixFuncCase( cFileName, lVerbose )
STATIC sc_hPartial := { ;
STATIC sc_hInCommentOnly := { ;
".c" =>, ;
".cpp" =>, ;
".h" =>, ;
@@ -696,32 +705,30 @@ STATIC FUNCTION FixFuncCase( cFileName )
STATIC sc_hFileExceptions := { ;
"ChangeLog.txt" =>, ;
"std.ch" =>, ;
"wcecon.prg" =>, ;
"uc16_gen.prg" =>, ;
"clsscope.prg" =>, ;
"speedstr.prg" =>, ;
"cpinfo.prg" =>, ;
"big5_gen.prg" =>, ;
"clsccast.prg" =>, ;
"clsicast.prg" =>, ;
"clsscast.prg" =>, ;
"big5_gen.prg" =>, ;
"clsscope.prg" =>, ;
"cpinfo.prg" =>, ;
"foreach2.prg" =>, ;
"speedtst.prg" =>, ;
"keywords.prg" =>, ;
"xhb-diff.txt" =>, ;
"pp.txt" =>, ;
"locks.txt" =>, ;
"oldnews.txt" =>, ;
"speedstr.prg" =>, ;
"speedtst.prg" =>, ;
"uc16_gen.prg" =>, ;
"wcecon.prg" =>, ;
"c_std.txt" =>, ;
"locks.txt" =>, ;
"pcode.txt" =>, ;
"tracing.txt" =>, ;
"pcode.txt" => }
"xhb-diff.txt" => }
STATIC sc_aMaskExceptions := { ;
"src/3rd/*" , ;
"contrib/3rd/*" , ;
"contrib/*/3rd/*" , ;
"contrib/hbnetio/tests/*" , ;
"extras/httpsrv/home/*" , ;
"contrib/xhb/thtm.prg" , ;
"tests/hbpptest/*" , ;
"tests/mt/*" , ;
"tests/multifnc/*" , ;
@@ -735,20 +742,22 @@ STATIC FUNCTION FixFuncCase( cFileName )
LOCAL cProper
LOCAL cOldCP
LOCAL lPartial
LOCAL lInCommentOnly
LOCAL nChanged := 0
hb_default( @lVerbose, .F. )
IF Empty( hb_FNameExt( cFileName ) ) .OR. ;
hb_FNameNameExt( cFileName ) $ sc_hFileExceptions .OR. ;
AScan( sc_aMaskExceptions, {| tmp | hb_FileMatch( StrTran( cFileName, "\", "/" ), tmp ) } ) == 0
AScan( sc_aMaskExceptions, {| tmp | hb_FileMatch( StrTran( cFileName, "\", "/" ), tmp ) } ) != 0
RETURN .F.
ENDIF
hAll := __hbformat_BuildListOfFunctions()
cFile := MemoRead( _HBROOT_ + cFileName )
lPartial := hb_FNameExt( cFileName ) $ sc_hPartial
cFileStripped := iif( lPartial, GetCComments( cFile ), cFile )
lInCommentOnly := hb_FNameExt( cFileName ) $ sc_hInCommentOnly
cFileStripped := iif( lInCommentOnly, GetCComments( cFile ), cFile )
cOldCP := hb_cdpSelect( "EN" )
@@ -763,15 +772,17 @@ STATIC FUNCTION FixFuncCase( cFileName )
!( 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(|" ) ) )
( ! lInCommentOnly .OR. !( "|" + Lower( cProper ) + "|" $ Lower( "|Max(|Min(|FOpen(|Abs(|Log10(|GetEnv(|Sqrt(|Rand(|IsDigit(|IsAlpha(|" ) ) )
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 ] + "|"
IF lVerbose
OutStd( cFileName, match[ 3 ][ _MATCH_cStr ], cProper, "|" + match[ 1 ][ _MATCH_cStr ] + "|" + hb_eol() )
ENDIF
nChanged++
ENDIF
ENDIF
NEXT
IF !( "hbclass.ch" $ cFileName ) .AND. ! lPartial
IF !( "hbclass.ch" $ cFileName ) .AND. ! lInCommentOnly
FOR EACH match IN hb_regexAll( "(?:REQUEST|EXTERNAL|EXTERNA|EXTERN)[ \t]+([A-Za-z_][A-Za-z0-9_]+)", cFile,,,,, .F. )
cProper := ProperCase( hAll, match[ 2 ][ _MATCH_cStr ] )
IF !( cProper == match[ 2 ][ _MATCH_cStr ] )

View File

@@ -30,6 +30,8 @@
#pragma -km+
#pragma -ko+
#include "hbgtinfo.ch"
PROCEDURE Main()
LOCAL cVCS := VCSDetect()
@@ -37,14 +39,10 @@ PROCEDURE Main()
LOCAL aFiles := {}
LOCAL aChanges := DoctorChanges( cVCS, Changes( cVCS ), aFiles )
LOCAL cLog
LOCAL cLogNew
LOCAL cLine
LOCAL nOffset
LOCAL cHit
LOCAL nPos
LOCAL nStart, nEnd
LOCAL cMyName
LOCAL cOldLang
LOCAL cLogName
LOCAL lWasChangeLog
IF Empty( aChanges )
OutStd( hb_ProgName() + ": " + "no changes" + hb_eol() )
@@ -67,6 +65,12 @@ PROCEDURE Main()
OutStd( hb_ProgName() + ": " + hb_StrFormat( "%1$s not updated. Run 'hbrun bin/commit' and retry.", cLogName ) + hb_eol() )
ErrorLevel( 3 )
RETURN
ELSE
cLog := GetLastEntry( MemoRead( cLogName ), @nStart, @nEnd )
IF ! Empty( cLog )
hbshell_gtSelect()
hb_gtInfo( HB_GTI_CLIPBOARDDATA, cLog )
ENDIF
ENDIF
ELSE
IF cVCS == "git"
@@ -81,34 +85,28 @@ PROCEDURE Main()
ENDIF
ENDIF
nOffset := hb_UTCOffset()
cLogNew := hb_StrFormat( "%1$s UTC%2$s%3$02d%4$02d %5$s", ;
hb_TToC( hb_DateTime(), "YYYY-MM-DD", "HH:MM" ), ;
iif( nOffset < 0, "-", "+" ), ;
Int( nOffset / 3600 ), ;
Int( ( ( nOffset / 3600 ) - Int( nOffset / 3600 ) ) * 60 ), ;
cMyName ) + hb_eol()
FOR EACH cLine IN aChanges
cLogNew += cLine + hb_eol()
NEXT
// ;
cLog := MemoRead( cLogName )
cOldLang := hb_cdpSelect( "EN" )
cHit := hb_AtX( "\n[1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9] UTC[\-+][0-1][0-9][0-5][0-9] ", cLog )
IF Empty( cHit )
cHit := ""
ENDIF
hb_cdpSelect( cOldLang )
nPos := At( AllTrim( cHit ), cLog )
IF nPos > 0
cLog := Left( cLog, nPos - 1 ) + cLogNew + hb_eol() + SubStr( cLog, nPos )
GetLastEntry( cLog, @nStart, @nEnd )
IF nStart > 0
/* Strip last entry if it's empty to avoid adding double entries */
IF IsLastEntryEmpty( SubStr( cLog, nStart, nEnd - nStart ), cLogName, @lWasChangeLog )
OutStd( hb_ProgName() + ": " + hb_StrFormat( "Updating last empty %1$s entry", cLogName ) + hb_eol() )
cLog := Left( cLog, nStart - 1 ) + SubStr( cLog, nEnd )
ELSE
lWasChangelog := .T.
ENDIF
cLog := ;
Left( cLog, nStart - 1 ) + ;
MakeEntry( aChanges, cMyName, cLogName, lWasChangeLog ) + hb_eol() + ;
SubStr( cLog, nStart )
ELSE
cLog += hb_eol() + cLogNew
cLog += hb_eol() + MakeEntry( aChanges, cMyName, cLogName, .T. )
ENDIF
hb_MemoWrit( cLogName, cLog )
@@ -125,6 +123,85 @@ PROCEDURE Main()
RETURN
STATIC FUNCTION GetLastEntry( cLog, /* @ */ nStart, /* @ */ nEnd )
LOCAL cLogHeaderExp := "\n[1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9] UTC[\-+][0-1][0-9][0-5][0-9] [\S ]*" + hb_eol()
LOCAL cOldLang := hb_cdpSelect( "EN" )
LOCAL cHit
nEnd := 0
cHit := hb_AtX( cLogHeaderExp, cLog )
IF Empty( cHit )
cHit := ""
ENDIF
nStart := At( AllTrim( cHit ), cLog )
IF nStart > 0
cHit := hb_AtX( cLogHeaderExp, cLog,, nStart + Len( cHit ) )
IF Empty( cHit )
cHit := ""
ENDIF
nEnd := At( AllTrim( cHit ), cLog )
IF nEnd == 0
nEnd := Len( cLog )
ENDIF
cLog := hb_StrShrink( SubStr( cLog, nStart, nEnd - nStart ), Len( hb_eol() ) )
ELSE
cLog := ""
ENDIF
hb_cdpSelect( cOldLang )
RETURN cLog
STATIC FUNCTION MakeEntry( aChanges, cMyName, cLogName, lAllowChangeLog )
LOCAL nOffset := hb_UTCOffset()
LOCAL cLog := hb_StrFormat( "%1$s UTC%2$s%3$02d%4$02d %5$s", ;
hb_TToC( hb_DateTime(), "YYYY-MM-DD", "HH:MM" ), ;
iif( nOffset < 0, "-", "+" ), ;
Int( nOffset / 3600 ), ;
Int( ( ( nOffset / 3600 ) - Int( nOffset / 3600 ) ) * 60 ), ;
cMyName ) + hb_eol()
LOCAL cLine
FOR EACH cLine IN aChanges
IF lAllowChangeLog .OR. !( SubStr( cLine, 5 ) == cLogName )
cLog += cLine + hb_eol()
ENDIF
NEXT
RETURN cLog
STATIC FUNCTION IsLastEntryEmpty( cLog, cLogName, /* @ */ lChangeLog )
LOCAL cLine
lChangeLog := .F.
FOR EACH cLine IN hb_ATokens( StrTran( cLog, Chr( 13 ) ), Chr( 10 ) )
IF cLine:__enumIndex() != 1
IF Empty( Left( cLine, 2 ) ) .AND. ! Empty( SubStr( cLine, 3, 1 ) )
IF SubStr( cLine, 5 ) == cLogName
lChangeLog := .T.
ENDIF
ELSE
IF ! Empty( cLine )
RETURN .F.
ENDIF
ENDIF
ENDIF
NEXT
RETURN .T.
STATIC FUNCTION VCSDetect()
DO CASE