* bin/check.hb
* tests/fixcase.hb
+ some exceptions for casing
* deleted one file exception (a readme)
* contrib/gtwvg/gtwvgd.c
* contrib/gtwvg/wvgcore.c
* contrib/gtwvg/wvgcuig.c
* contrib/gtwvg/wvgwin.c
* contrib/gtwvg/wvgwing.c
* contrib/hbamf/amfenc.c
* contrib/hbbz2/core.c
* contrib/hbct/ctcom1.c
* contrib/hbct/ctcom2.c
* contrib/hbct/ctnet.c
* contrib/hbct/ctstr.c
* contrib/hbct/ctwfunc.c
* contrib/hbct/ctwin.c
* contrib/hbct/disk.c
* contrib/hbct/finan.c
* contrib/hbct/screen2.c
* contrib/hbct/token1.c
* contrib/hbct/token2.c
* contrib/hbct/trig.c
* contrib/hbgd/gdwrp.c
* contrib/hbhpdf/image.c
* contrib/hbmisc/irm.c
* contrib/hbnetio/netiocli.c
* contrib/hbnetio/netiosrv.c
* contrib/hbnetio/readme.txt
* contrib/hbnf/dispc.c
* contrib/hbnf/ftattr.c
* contrib/hbnf/origin.c
* contrib/hbssl/ssl.c
* contrib/hbwin/wapi_commctrl.c
* contrib/hbwin/wapi_winuser.c
* contrib/hbwin/win_dlg.c
* contrib/hbwin/win_prn2.c
* contrib/hbwin/win_shell.c
* contrib/rddads/ads1.c
* contrib/rddads/adsfunc.c
* contrib/xhb/fparse.c
* contrib/xhb/hbcrypt.c
* contrib/xhb/hbserv.c
* contrib/xhb/hbxml.c
* contrib/xhb/txtline.c
* contrib/xhb/xhbarr.c
* contrib/xhb/xhbarrex.c
* extras/gfspell/spellc.c
* extras/gtwvw/gtwvwd.c
* extras/gtwvw/hbgtwvw.h
* extras/gtwvw/wvwcheck.c
* extras/gtwvw/wvwdraw.c
* extras/gtwvw/wvwedit.c
* extras/gtwvw/wvwfuncs.c
* extras/gtwvw/wvwmenu.c
* extras/gtwvw/wvwpush.c
* extras/gtwvw/wvwstbar.c
* extras/gtwvw/wvwtbar.c
* include/hbapi.h
* include/hbapirdd.h
* include/hbdefs.h
* include/hbexpra.c
* include/hbexprb.c
* include/hbpcode.h
* include/hbpp.h
* include/hbrddcdx.h
* include/hbrddnsx.h
* src/codepage/cp_utf8.c
* src/common/expropt1.c
* src/common/expropt2.c
* src/compiler/cmdcheck.c
* src/compiler/genc.c
* src/compiler/gencc.c
* src/compiler/hbfunchk.c
* src/compiler/hbopt.c
* src/pp/pplib.c
* src/rdd/dbcmd.c
* src/rdd/dbf1.c
* src/rdd/dbfcdx/dbfcdx1.c
* src/rdd/hbsix/sxcompr.c
* src/rdd/hbsix/sxord.c
* src/rdd/hsx/hsx.c
* src/rtl/chruni.c
* src/rtl/cputime.c
* src/rtl/dateshb.c
* src/rtl/filehb.c
* src/rtl/filesys.c
* src/rtl/gtsln/gtsln.c
* src/rtl/gtwvt/gtwvt.c
* src/rtl/gtxwc/gtxwc.c
* src/rtl/hbgtcore.c
* src/rtl/hbinet.c
* src/rtl/hblpphb.c
* src/rtl/hbmd5.c
* src/rtl/hbproces.c
* src/rtl/hbsocket.c
* src/rtl/hbsockhb.c
* src/rtl/hbtoken.c
* src/rtl/hbzlib.c
* src/rtl/hbzlibgz.c
* src/rtl/langapi.c
* src/rtl/mlcfunc.c
* src/rtl/philes.c
* src/rtl/soundex.c
* src/rtl/strzero.c
* src/rtl/transfrm.c
* src/vm/arrayshb.c
* src/vm/classes.c
* src/vm/dynsym.c
* src/vm/eval.c
* src/vm/garbage.c
* src/vm/hvm.c
* src/vm/macro.c
* src/vm/memvars.c
* src/vm/runner.c
* src/vm/set.c
* src/vm/thread.c
* run tests/fixcase.hb now that it's able to fixup casing
inside all comments
252 lines
6.4 KiB
Plaintext
252 lines
6.4 KiB
Plaintext
/*
|
|
* Function naming casing fixer
|
|
*
|
|
* The script takes proper casing from .hbx files
|
|
* and applies it to whole source tree. (except
|
|
* C sources and some certain files)
|
|
*
|
|
* BEWARE: ugly code
|
|
*
|
|
* Copyright 2012 Viktor Szakats (harbour syenar.net)
|
|
* www - http://harbour-project.org
|
|
*
|
|
*/
|
|
|
|
#pragma -w3
|
|
#pragma -km+
|
|
#pragma -ko+
|
|
|
|
#include "directry.ch"
|
|
#include "simpleio.ch"
|
|
|
|
PROCEDURE Main( cFile )
|
|
|
|
LOCAL aFile
|
|
LOCAL cExt
|
|
|
|
LOCAL hAll := { => }
|
|
|
|
LOCAL hExtExceptions := { ;
|
|
hb_libExt() =>, ;
|
|
".zip" =>, ;
|
|
".7z" =>, ;
|
|
".exe" =>, ;
|
|
".o" =>, ;
|
|
".obj" =>, ;
|
|
".js" =>, ;
|
|
".dif" =>, ;
|
|
".exe" =>, ;
|
|
".y" =>, ;
|
|
".yyc" =>, ;
|
|
".yyh" =>, ;
|
|
".a" =>, ;
|
|
".afm" =>, ;
|
|
".bmp" =>, ;
|
|
".dat" =>, ;
|
|
".dbf" =>, ;
|
|
".exe" =>, ;
|
|
".frm" =>, ;
|
|
".gif" =>, ;
|
|
".icns" =>, ;
|
|
".ico" =>, ;
|
|
".jpg" =>, ;
|
|
".lbl" =>, ;
|
|
".lib" =>, ;
|
|
".mdb" =>, ;
|
|
".ng" =>, ;
|
|
".odt" =>, ;
|
|
".pdf" =>, ;
|
|
".pfb" =>, ;
|
|
".png" =>, ;
|
|
".sq3" =>, ;
|
|
".tif" => }
|
|
|
|
LOCAL hPartial := { ;
|
|
".c" =>, ;
|
|
".h" =>, ;
|
|
".api" => }
|
|
|
|
LOCAL hFileExceptions := { ;
|
|
"ChangeLog.txt" =>, ;
|
|
"std.ch" =>, ;
|
|
"wcecon.prg" =>, ;
|
|
"uc16_gen.prg" =>, ;
|
|
"clsscope.prg" =>, ;
|
|
"speedstr.prg" =>, ;
|
|
"cpinfo.prg" =>, ;
|
|
"clsccast.prg" =>, ;
|
|
"clsicast.prg" =>, ;
|
|
"clsscast.prg" =>, ;
|
|
"big5_gen.prg" =>, ;
|
|
"foreach2.prg" =>, ;
|
|
"speedtst.prg" =>, ;
|
|
"keywords.prg" =>, ;
|
|
"xhb-diff.txt" =>, ;
|
|
"pp.txt" =>, ;
|
|
"locks.txt" =>, ;
|
|
"oldnews.txt" =>, ;
|
|
"news.html" =>, ;
|
|
"news1.html" =>, ;
|
|
"c_std.txt" =>, ;
|
|
"tracing.txt" =>, ;
|
|
"pcode.txt" => }
|
|
|
|
LOCAL aMaskExceptions := { ;
|
|
"src/3rd/*" , ;
|
|
"contrib/3rd/*" , ;
|
|
"contrib/*/3rd/*" , ;
|
|
"contrib/xhb/thtm.prg" , ;
|
|
"contrib/hbnetio/tests/*" , ;
|
|
"extras/httpsrv/home/*" , ;
|
|
"tests/hbpptest/*" , ;
|
|
"tests/mt/*" , ;
|
|
"tests/multifnc/*" , ;
|
|
"tests/rddtest/*" }
|
|
|
|
hb_cdpSelect( "EN" )
|
|
|
|
hb_HCaseMatch( hAll, .F. )
|
|
|
|
__hbformat_BuildListOfFunctions( hAll )
|
|
|
|
IF HB_ISSTRING( cFile )
|
|
ProcFile( hAll, cFile )
|
|
ELSE
|
|
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 )
|
|
ENDIF
|
|
NEXT
|
|
ENDIF
|
|
|
|
RETURN
|
|
|
|
STATIC PROCEDURE ProcFile( hAll, cFileName, lPartial )
|
|
|
|
LOCAL cFile := MemoRead( cFileName )
|
|
LOCAL cFileStripped
|
|
|
|
LOCAL a
|
|
LOCAL cProper
|
|
|
|
LOCAL nChanged := 0
|
|
|
|
hb_default( @lPartial, .F. )
|
|
|
|
IF lPartial
|
|
cFileStripped := GetCComments( cFile )
|
|
ELSE
|
|
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. ;
|
|
!( 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 ] + "|"
|
|
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 ] + "|"
|
|
nChanged++
|
|
ENDIF
|
|
NEXT
|
|
ENDIF
|
|
|
|
IF nChanged > 0
|
|
? cFileName, "changed: ", nChanged
|
|
hb_MemoWrit( cFileName, cFile )
|
|
ENDIF
|
|
|
|
RETURN
|
|
|
|
STATIC FUNCTION ProperCase( hAll, cName )
|
|
|
|
IF cName $ hAll
|
|
RETURN hb_HKeyAt( hAll, hb_HPos( hAll, cName ) )
|
|
ENDIF
|
|
|
|
RETURN cName
|
|
|
|
STATIC PROCEDURE __hbformat_BuildListOfFunctions( hFunctions )
|
|
|
|
WalkDir( hb_DirBase() + ".." + hb_ps() + "include", hFunctions )
|
|
WalkDir( hb_DirBase() + ".." + hb_ps() + "contrib", hFunctions )
|
|
WalkDir( hb_DirBase() + ".." + hb_ps() + "extras", hFunctions )
|
|
|
|
RETURN
|
|
|
|
STATIC PROCEDURE WalkDir( cDir, hFunctions )
|
|
|
|
LOCAL aFile
|
|
|
|
cDir := hb_DirSepAdd( cDir )
|
|
|
|
FOR EACH aFile IN hb_DirScan( cDir, "*.hbx" )
|
|
HBXToFuncList( hFunctions, hb_MemoRead( cDir + aFile[ F_NAME ] ) )
|
|
NEXT
|
|
|
|
RETURN
|
|
|
|
STATIC PROCEDURE HBXToFuncList( hFunctions, cHBX )
|
|
LOCAL cLine
|
|
|
|
FOR EACH cLine IN hb_ATokens( StrTran( cHBX, Chr( 13 ) ), Chr( 10 ) )
|
|
IF Left( cLine, Len( "DYNAMIC " ) ) == "DYNAMIC "
|
|
hFunctions[ SubStr( cLine, Len( "DYNAMIC " ) + 1 ) ] := NIL
|
|
ENDIF
|
|
NEXT
|
|
|
|
RETURN
|
|
|
|
/* retains positions in file */
|
|
STATIC FUNCTION GetCComments( cFile )
|
|
|
|
LOCAL nPos := 1
|
|
LOCAL aHits := {}
|
|
LOCAL tmp
|
|
LOCAL tmp1
|
|
LOCAL lStart := .T.
|
|
|
|
LOCAL cComments
|
|
|
|
/* bare bones */
|
|
DO WHILE ( tmp := hb_BAt( iif( lStart, "/*", "*/" ), cFile, nPos ) ) > 0
|
|
AAdd( aHits, tmp + iif( lStart, 0, 2 ) )
|
|
nPos := tmp
|
|
lStart := ! lStart
|
|
ENDDO
|
|
|
|
/* unbalanced */
|
|
IF Len( aHits ) % 2 != 0
|
|
AAdd( aHits, hb_BLen( cFile ) )
|
|
ENDIF
|
|
|
|
cComments := Space( hb_BLen( cFile ) )
|
|
|
|
FOR tmp := 1 TO Len( aHits ) STEP 2
|
|
FOR tmp1 := aHits[ tmp ] TO aHits[ tmp + 1 ]
|
|
IF ! hb_BSubStr( cFile, tmp1, 1 ) $ Chr( 13 ) + Chr( 10 )
|
|
hb_BPoke( @cComments, tmp1, hb_BPeek( cFile, tmp1 ) )
|
|
ENDIF
|
|
NEXT
|
|
NEXT
|
|
|
|
RETURN cComments
|