From d34ee4d3f1dcbdc62f51c748daa2f35f55cd2980 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 7 Nov 2012 11:03:53 +0000 Subject: [PATCH] 2012-11-07 11:59 UTC+0100 Viktor Szakats (harbour syenar.net) * src/rtl/dirscan.prg + HB_DIRSCAN(): more strict check on parameters to avoid RTEs % HB_DIRSCAN(): minor optimizations * bin/find.hb % Use HB_DIRSCAN() * include/harbour.hbx * src/rtl/hbfilehi.prg + added HB_DIRSEPTOOS( ) -> * bin/find.hb * config/postinst.hb * contrib/make.hb * Use HB_DIRSEPTOOS() instead of locally rolled copy --- harbour/ChangeLog | 20 +++++++++++++++++++ harbour/bin/find.hb | 16 ++++------------ harbour/config/postinst.hb | 37 +++++++++++++++++------------------- harbour/contrib/make.hb | 19 ++++++++---------- harbour/include/harbour.hbx | 1 + harbour/src/rtl/dirscan.prg | 17 ++++------------- harbour/src/rtl/hbfilehi.prg | 3 +++ 7 files changed, 57 insertions(+), 56 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c541ff83bb..d9947444c1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,23 @@ The license applies to all entries newer than 2009-04-28. */ +2012-11-07 11:59 UTC+0100 Viktor Szakats (harbour syenar.net) + * src/rtl/dirscan.prg + + HB_DIRSCAN(): more strict check on parameters to avoid RTEs + % HB_DIRSCAN(): minor optimizations + + * bin/find.hb + % Use HB_DIRSCAN() + + * include/harbour.hbx + * src/rtl/hbfilehi.prg + + added HB_DIRSEPTOOS( ) -> + + * bin/find.hb + * config/postinst.hb + * contrib/make.hb + * Use HB_DIRSEPTOOS() instead of locally rolled copy + 2012-11-07 11:12 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbblink/hbblink.hbx * found original sources and formatted Blinker @@ -41,6 +58,9 @@ * extras/rddado/adordd.prg * formatted ! some commented code converted to #if 0/#endif block + % changed to use hbnf lib instead of keeping multiple + copies of hbnf functions locally + * minor cleanup in hbmk2 lib parameters 2012-11-07 03:28 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbnf/hbnf.hbx diff --git a/harbour/bin/find.hb b/harbour/bin/find.hb index 1372e725ab..b6250c7f83 100644 --- a/harbour/bin/find.hb +++ b/harbour/bin/find.hb @@ -42,22 +42,14 @@ STATIC PROCEDURE WalkDir( cDir, aContains ) LOCAL aFile - cDir := hb_DirSepAdd( PathSepToSelf( cDir ) ) + cDir := hb_DirSepAdd( hb_DirSepToOS( cDir ) ) - FOR EACH aFile IN Directory( cDir + hb_osFileMask(), "D" ) - IF aFile[ F_NAME ] == "." .OR. aFile[ F_NAME ] == ".." - ELSEIF "D" $ aFile[ F_ATTR ] - WalkDir( cDir + aFile[ F_NAME ] + hb_ps(), aContains ) - ELSEIF hb_FNameExt( aFile[ F_NAME ] ) == ".hbx" - ProcessFile( cDir + aFile[ F_NAME ], aContains ) - ENDIF + FOR EACH aFile IN hb_DirScan( cDir, "*.hbx" ) + ProcessFile( cDir + aFile[ F_NAME ], aContains ) NEXT RETURN -STATIC FUNCTION PathSepToSelf( cFileName ) - RETURN StrTran( cFileName, iif( hb_ps() == "\", "/", "\" ), hb_ps() ) - STATIC PROCEDURE ProcessFile( cFileName, aContains ) LOCAL cDynamic @@ -67,7 +59,7 @@ STATIC PROCEDURE ProcessFile( cFileName, aContains ) IF Empty( aContains ) .OR. AScan( aContains, {| tmp | Upper( tmp ) $ Upper( cDynamic ) } ) > 0 IF lFirst lFirst := .F. - OutStd( PathSepToSelf( cFileName ) + hb_eol() ) + OutStd( hb_DirSepToOS( cFileName ) + hb_eol() ) ENDIF OutStd( " " + cDynamic + "()" + hb_eol() ) ENDIF diff --git a/harbour/config/postinst.hb b/harbour/config/postinst.hb index 3d48d2656a..cf46297cef 100644 --- a/harbour/config/postinst.hb +++ b/harbour/config/postinst.hb @@ -63,7 +63,7 @@ PROCEDURE Main( ... ) OutStd( "! Copying root documents..." + hb_eol() ) - IF hb_DirBuild( PathSepToSelf( tmp ) ) + IF hb_DirBuild( hb_DirSepToOS( tmp ) ) FOR EACH aFile IN Directory( "Change*" ) mk_hb_FCopy( aFile[ F_NAME ], tmp + hb_ps() + iif( GetEnvC( "HB_PLATFORM" ) == "dos", "CHANGES", "" ) ) NEXT @@ -96,7 +96,7 @@ PROCEDURE Main( ... ) OutStd( "! Copying *nix config files..." + hb_eol() ) - IF hb_DirBuild( PathSepToSelf( GetEnvC( "HB_INSTALL_ETC" ) ) ) + IF hb_DirBuild( hb_DirSepToOS( GetEnvC( "HB_INSTALL_ETC" ) ) ) mk_hb_FCopy( "src/rtl/gtcrs/hb-charmap.def", GetEnvC( "HB_INSTALL_ETC" ) + hb_ps(), .T. ) ELSE OutStd( hb_StrFormat( "! Error: Cannot create directory '%1$s'", GetEnvC( "HB_INSTALL_ETC" ) ) + hb_eol() ) @@ -108,7 +108,7 @@ PROCEDURE Main( ... ) OutStd( "! Creating Linux ld config file..." + hb_eol() ) tmp := GetEnvC( "HB_INSTALL_ETC" ) + hb_ps() + ".." + hb_ps() + "ld.so.conf.d" - IF hb_DirBuild( PathSepToSelf( tmp ) ) + IF hb_DirBuild( hb_DirSepToOS( tmp ) ) tmp1 := GetEnvC( "HB_INSTALL_DYN" ) IF Left( tmp1, Len( GetEnvC( "HB_INSTALL_PKG_ROOT" ) ) ) == GetEnvC( "HB_INSTALL_PKG_ROOT" ) tmp1 := SubStr( tmp1, Len( GetEnvC( "HB_INSTALL_PKG_ROOT" ) ) + 1 ) @@ -124,7 +124,7 @@ PROCEDURE Main( ... ) OutStd( "! Copying *nix man files..." + hb_eol() ) - IF hb_DirBuild( PathSepToSelf( GetEnvC( "HB_INSTALL_MAN" ) ) + hb_ps() + "man1" ) + IF hb_DirBuild( hb_DirSepToOS( GetEnvC( "HB_INSTALL_MAN" ) ) + hb_ps() + "man1" ) FOR EACH tmp IN { ; "src/main/harbour.1", ; "src/pp/hbpp.1", ; @@ -140,7 +140,7 @@ PROCEDURE Main( ... ) IF !( GetEnvC( "HB_PLATFORM" ) $ "win|wce|os2|dos|cygwin" ) .AND. ; ! Empty( GetEnvC( "HB_INSTALL_DYN" ) ) .AND. ; - hb_FileExists( PathSepToSelf( GetEnvC( "HB_DYNLIB_DIR" ) ) + hb_ps() + GetEnvC( "HB_DYNLIB_PREF" ) + GetEnvC( "HB_DYNLIB_BASE" ) + GetEnvC( "HB_DYNLIB_POST" ) + GetEnvC( "HB_DYNLIB_EXT" ) + GetEnvC( "HB_DYNLIB_PEXT" ) ) + hb_FileExists( hb_DirSepToOS( GetEnvC( "HB_DYNLIB_DIR" ) ) + hb_ps() + GetEnvC( "HB_DYNLIB_PREF" ) + GetEnvC( "HB_DYNLIB_BASE" ) + GetEnvC( "HB_DYNLIB_POST" ) + GetEnvC( "HB_DYNLIB_EXT" ) + GetEnvC( "HB_DYNLIB_PEXT" ) ) OutStd( "! Creating dynamic lib symlinks..." + hb_eol() ) @@ -148,8 +148,8 @@ PROCEDURE Main( ... ) cDynVersionComp := GetEnvC( "HB_DYNLIB_PREF" ) + GetEnvC( "HB_DYNLIB_BASE" ) + GetEnvC( "HB_DYNLIB_POSC" ) + GetEnvC( "HB_DYNLIB_EXT" ) + GetEnvC( "HB_DYNLIB_PEXC" ) cDynVersionless := GetEnvC( "HB_DYNLIB_PREF" ) + GetEnvC( "HB_DYNLIB_BASE" ) + GetEnvC( "HB_DYNLIB_EXT" ) - mk_hb_FLinkSym( cDynVersionFull, PathSepToSelf( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + cDynVersionComp ) - mk_hb_FLinkSym( cDynVersionFull, PathSepToSelf( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + cDynVersionless ) + mk_hb_FLinkSym( cDynVersionFull, hb_DirSepToOS( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + cDynVersionComp ) + mk_hb_FLinkSym( cDynVersionFull, hb_DirSepToOS( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + cDynVersionless ) DO CASE CASE EndsWith( GetEnvC( "HB_INSTALL_DYN" ), "/usr/lib/harbour" ) .OR. ; @@ -157,9 +157,9 @@ PROCEDURE Main( ... ) EndsWith( GetEnvC( "HB_INSTALL_DYN" ), "/usr/local/lib/harbour" ) .OR. ; EndsWith( GetEnvC( "HB_INSTALL_DYN" ), "/usr/local/lib64/harbour" ) - mk_hb_FLinkSym( "harbour" + hb_ps() + cDynVersionFull, PathSepToSelf( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + ".." + hb_ps() + cDynVersionless ) - mk_hb_FLinkSym( "harbour" + hb_ps() + cDynVersionFull, PathSepToSelf( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + ".." + hb_ps() + cDynVersionComp ) - mk_hb_FLinkSym( "harbour" + hb_ps() + cDynVersionFull, PathSepToSelf( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + ".." + hb_ps() + cDynVersionFull ) + mk_hb_FLinkSym( "harbour" + hb_ps() + cDynVersionFull, hb_DirSepToOS( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + ".." + hb_ps() + cDynVersionless ) + mk_hb_FLinkSym( "harbour" + hb_ps() + cDynVersionFull, hb_DirSepToOS( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + ".." + hb_ps() + cDynVersionComp ) + mk_hb_FLinkSym( "harbour" + hb_ps() + cDynVersionFull, hb_DirSepToOS( GetEnvC( "HB_INSTALL_DYN" ) ) + hb_ps() + ".." + hb_ps() + cDynVersionFull ) CASE GetEnvC( "HB_INSTALL_DYN" ) == "/usr/local/harbour/lib" /* TOFIX: Rewrite this in .prg: @@ -185,7 +185,7 @@ PROCEDURE Main( ... ) IF "D" $ tmp[ F_ATTR ] .AND. !( tmp[ F_NAME ] == "." ) .AND. !( tmp[ F_NAME ] == ".." ) FOR EACH aFile IN Directory( "utils" + hb_ps() + tmp[ F_NAME ] + hb_ps() + "*.po" ) mk_hbl( "utils" + hb_ps() + tmp[ F_NAME ] + hb_ps() + aFile[ F_NAME ], ; - PathSepToSelf( GetEnvC( "HB_INSTALL_BIN" ) ) + hb_ps() + hb_FNameExtSet( aFile[ F_NAME ], ".hbl" ) ) + hb_DirSepToOS( GetEnvC( "HB_INSTALL_BIN" ) ) + hb_ps() + hb_FNameExtSet( aFile[ F_NAME ], ".hbl" ) ) NEXT ENDIF NEXT @@ -230,7 +230,7 @@ PROCEDURE Main( ... ) cOldDir := hb_cwd( GetEnvC( "HB_INSTALL_PKG_ROOT" ) ) - mk_hb_processRun( PathSepToSelf( GetEnvC( "HB_DIR_ZIP" ) ) + "zip" + ; + mk_hb_processRun( hb_DirSepToOS( GetEnvC( "HB_DIR_ZIP" ) ) + "zip" + ; " -q -9 -X -r -o" + ; " " + FNameEscape( tmp ) + ; " . -i " + FNameEscape( GetEnvC( "HB_PKGNAME" ) + hb_ps() + "*" ) + ; @@ -244,7 +244,7 @@ PROCEDURE Main( ... ) OutStd( "! Making Harbour .exe install package: '" + tmp + "'" + hb_eol() ) - mk_hb_processRun( PathSepToSelf( GetEnvC( "HB_DIR_NSIS" ) ) + "makensis.exe" + ; + mk_hb_processRun( hb_DirSepToOS( GetEnvC( "HB_DIR_NSIS" ) ) + "makensis.exe" + ; " -V2" + ; " " + FNameEscape( StrTran( "package/mpkg_win.nsi", "/", hb_ps() ) ) ) ENDIF @@ -379,7 +379,7 @@ STATIC FUNCTION mk_hbd_core( cDirSource, cDirDest ) NEXT IF ! Empty( aEntry ) - cName := hb_DirSepAdd( PathSepToSelf( cDirDest ) ) + cName + ".hbd" + cName := hb_DirSepAdd( hb_DirSepToOS( cDirDest ) ) + cName + ".hbd" IF __hbdoc_SaveHBD( cName, aEntry ) OutStd( "! Created " + cName + " <= " + cDirSource + hb_eol() ) RETURN .T. @@ -399,9 +399,6 @@ STATIC FUNCTION mk_hb_processRun( cCommand, ... ) STATIC FUNCTION FNameEscape( cFN ) RETURN Chr( 34 ) + cFN + Chr( 34 ) -STATIC FUNCTION PathSepToSelf( cFileName ) - RETURN StrTran( cFileName, iif( hb_ps() == "\", "/", "\" ), hb_ps() ) - /* Like hb_FCopy(), but accepts dir as target and can set attributes */ STATIC PROCEDURE mk_hb_FCopy( cSrc, cDst, l644 ) @@ -411,8 +408,8 @@ STATIC PROCEDURE mk_hb_FCopy( cSrc, cDst, l644 ) l644 := .F. ENDIF - cSrc := PathSepToSelf( cSrc ) - cDst := PathSepToSelf( cDst ) + cSrc := hb_DirSepToOS( cSrc ) + cDst := hb_DirSepToOS( cDst ) hb_FNameSplit( cDst, @cDir, @cName, @cExt ) IF Empty( cName ) .AND. Empty( cExt ) @@ -496,7 +493,7 @@ STATIC FUNCTION mk_extern_core() ! Empty( GetEnvC( "HB_DYNLIB_BASE" ) ) /* TOFIX: Use list of libs instead of dynamic lib */ - IF ( aExtern := __hb_extern_get_list( PathSepToSelf( GetEnvC( "HB_DYNLIB_DIR" ) ) + hb_ps() + GetEnvC( "HB_DYNLIB_PREF" ) + GetEnvC( "HB_DYNLIB_BASE" ) + GetEnvC( "HB_DYNLIB_POST" ) + GetEnvC( "HB_DYNLIB_EXT" ) + GetEnvC( "HB_DYNLIB_PEXT" ) ) ) != NIL + IF ( aExtern := __hb_extern_get_list( hb_DirSepToOS( GetEnvC( "HB_DYNLIB_DIR" ) ) + hb_ps() + GetEnvC( "HB_DYNLIB_PREF" ) + GetEnvC( "HB_DYNLIB_BASE" ) + GetEnvC( "HB_DYNLIB_POST" ) + GetEnvC( "HB_DYNLIB_EXT" ) + GetEnvC( "HB_DYNLIB_PEXT" ) ) ) != NIL OutStd( "! Generating core extern headers..." + hb_eol() ) diff --git a/harbour/contrib/make.hb b/harbour/contrib/make.hb index 982ff720ee..8412e3a631 100755 --- a/harbour/contrib/make.hb +++ b/harbour/contrib/make.hb @@ -173,7 +173,7 @@ PROCEDURE Standalone( aParams, hProjectList ) IF ! lCustom /* Find out which projects are in current dir, these will be our primary targets */ FOR EACH tmp IN hProjectList - tmp1 := hb_ps() + hb_FNameDir( PathSepToSelf( tmp:__enumKey() ) ) + tmp1 := hb_ps() + hb_FNameDir( hb_DirSepToOS( tmp:__enumKey() ) ) IF tmp1 == Right( hb_cwd(), Len( tmp1 ) ) /* Not ultimate solution */ hProjectReqList[ tmp:__enumKey() ] := tmp:__enumKey() s_cReBase := SubStr( tmp1, 2 ) @@ -306,8 +306,8 @@ PROCEDURE GNUMake( aParams, hProjectList ) ENDIF FOR EACH cProject IN aFilter FOR EACH tmp IN hProjectList - IF hb_FileMatch( PathSepToSelf( cProject ), PathSepToSelf( tmp:__enumKey() ) ) .OR. ; - hb_FileMatch( PathSepToSelf( cProject ), hb_DirSepDel( hb_FNameDir( PathSepToSelf( tmp:__enumKey() ) ) ) ) + IF hb_FileMatch( hb_DirSepToOS( cProject ), hb_DirSepToOS( tmp:__enumKey() ) ) .OR. ; + hb_FileMatch( hb_DirSepToOS( cProject ), hb_DirSepDel( hb_FNameDir( hb_DirSepToOS( tmp:__enumKey() ) ) ) ) IF lFilterNegative IF tmp:__enumKey() $ hProjectReqList hb_HDel( hProjectReqList, tmp:__enumKey() ) @@ -467,7 +467,7 @@ STATIC PROCEDURE build_projects( nAction, hProjectList, hProjectReqList, cOption /* Compile documentation */ IF lInstall - mk_hbd( hb_FNameDir( PathSepToSelf( cProjectPath ) ) ) + mk_hbd( hb_FNameDir( hb_DirSepToOS( cProjectPath ) ) ) ENDIF ENDIF ELSE @@ -517,7 +517,7 @@ STATIC FUNCTION call_hbmk2_hbinfo( cProjectPath, hProject ) ENDIF #endif AAdd( hProject[ "aDept" ], { "nDepth" => Len( tmp ) - Len( LTrim( tmp ) ), ; - "cFileName_HBP" => StrTran( hb_PathNormalize( hb_PathJoin( s_cRebase, hb_FNameExtSet( PathSepToSelf( LTrim( tmp ) ), ".hbp" ) ) ), "\", "/" ) } ) + "cFileName_HBP" => StrTran( hb_PathNormalize( hb_PathJoin( s_cRebase, hb_FNameExtSet( hb_DirSepToOS( LTrim( tmp ) ), ".hbp" ) ) ), "\", "/" ) } ) ENDIF NEXT ENDIF @@ -552,7 +552,7 @@ STATIC FUNCTION call_hbmk2( cProjectPath, cOptionsPre, cDynSuffix, cStdErr, cStd hb_SetEnv( "_HB_BUILD_LIBDYN" ) ENDIF - hb_SetEnv( "_HB_CONTRIB_SUBDIR", hb_FNameDir( PathSepToSelf( cProjectPath ) ) ) + hb_SetEnv( "_HB_CONTRIB_SUBDIR", hb_FNameDir( hb_DirSepToOS( cProjectPath ) ) ) cCommand := s_cBinDir + "hbmk2" + ; " -quiet -width=0 -autohbm-" + ; @@ -625,7 +625,7 @@ STATIC FUNCTION mk_hbd( cDir ) NEXT IF ! Empty( aEntry ) - cName := PathSepToSelf( cDocDir ) + hb_ps() + cName + ".hbd" + cName := hb_DirSepToOS( cDocDir ) + hb_ps() + cName + ".hbd" IF __hbdoc_SaveHBD( cName, aEntry ) OutStd( "! Compiled documentation: " + cName + " <= " + cDir + hb_eol() ) RETURN .T. @@ -654,9 +654,6 @@ STATIC FUNCTION DirGetName( cDir ) RETURN cName -STATIC FUNCTION PathSepToSelf( cFileName ) - RETURN StrTran( cFileName, iif( hb_ps() == "\", "/", "\" ), hb_ps() ) - /* Convert indented list of line to tree / list of parent-child pairs */ STATIC PROCEDURE DeptLinesToDeptPairList( aPairList, cParent, aFlatTree ) @@ -748,7 +745,7 @@ PROCEDURE AddProject( hProjectList, cFileName ) IF ! Empty( cFileName ) - cFileName := PathSepToSelf( AllTrim( cFileName ) ) + cFileName := hb_DirSepToOS( AllTrim( cFileName ) ) hb_FNameSplit( cFileName, @cDir, @cName, @cExt ) diff --git a/harbour/include/harbour.hbx b/harbour/include/harbour.hbx index e3aeb4e74d..22f50e5d36 100644 --- a/harbour/include/harbour.hbx +++ b/harbour/include/harbour.hbx @@ -406,6 +406,7 @@ DYNAMIC hb_DirExists DYNAMIC hb_DirScan DYNAMIC hb_DirSepAdd DYNAMIC hb_DirSepDel +DYNAMIC hb_DirSepToOS DYNAMIC hb_DirTemp DYNAMIC hb_DirUnbuild DYNAMIC hb_DisableWaitLocks diff --git a/harbour/src/rtl/dirscan.prg b/harbour/src/rtl/dirscan.prg index 46592489c7..a3362779ea 100644 --- a/harbour/src/rtl/dirscan.prg +++ b/harbour/src/rtl/dirscan.prg @@ -4,7 +4,7 @@ /* * Harbour Project source code: - * HB_DirScan() + * hb_DirScan() * * Copyright 2008 Przemyslaw Czerpak * www - http://harbour-project.org @@ -78,18 +78,9 @@ STATIC FUNCTION hb_doScan( cPath, cMask, cAttr, cPathSep ) FUNCTION hb_DirScan( cPath, cFileMask, cAttr ) - LOCAL cFilePath + hb_default( @cPath, "" ) - IF Empty( cPath ) - cFilePath := "" - ELSE - cFilePath := cPath - IF ! Right( cPath, 1 ) $ hb_osPathDelimiters() - cFilePath += hb_ps() - ENDIF - ENDIF - - RETURN HB_DoScan( cFilePath, ; - iif( Empty( cFileMask ), hb_osFileMask(), cFileMask ), ; + RETURN HB_DoScan( hb_DirSepAdd( cPath ), ; + iif( HB_ISSTRING( cFileMask ), cFileMask, hb_osFileMask() ), ; iif( HB_ISSTRING( cAttr ), cAttr, "" ), ; hb_ps() ) diff --git a/harbour/src/rtl/hbfilehi.prg b/harbour/src/rtl/hbfilehi.prg index 4a9df77fd0..057a52e356 100644 --- a/harbour/src/rtl/hbfilehi.prg +++ b/harbour/src/rtl/hbfilehi.prg @@ -267,6 +267,9 @@ FUNCTION hb_DirSepDel( cDir ) RETURN cDir +FUNCTION hb_DirSepToOS( cFileName ) + RETURN StrTran( cFileName, iif( hb_ps() == "\", "/", "\" ), hb_ps() ) + FUNCTION hb_DirBuild( cDir ) LOCAL cDirTemp