From 530f92449eefddbc64260ef835ebecf9af56a445 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 3 Feb 2011 12:58:47 +0000 Subject: [PATCH] 2011-02-03 13:55 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * include/harbour.hbx * src/rtl/hbfilehi.prg * HB_PATHMAKEABSOLUTE() swapped two input parameters. Now: ( , ) * HB_PATHMAKEABSOLUTE() renamed to HB_PATHJOIN() * HB_PATHMAKERELATIVE() 3rd () parameter default changed to .T. * HB_PATHMAKERELATIVE() renamed to HB_PATHRELATIVIZE() * HB_DIRADDPATHSEP() renamed to HB_DIRSEPADD() * HB_DIRDELPATHSEP() renamed to HB_DIRSEPDEL() ; HB_PATHNORMALIZE() name finalized * contrib/hbide/idemisc.prg - Deleted unused hbmk2_PathMakeRelative() --- harbour/ChangeLog | 14 ++++ harbour/contrib/hbide/idemisc.prg | 104 ------------------------------ harbour/include/harbour.hbx | 8 +-- harbour/src/rtl/hbfilehi.prg | 24 ++++--- 4 files changed, 29 insertions(+), 121 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c044df211b..88e765f241 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,20 @@ The license applies to all entries newer than 2009-04-28. */ +2011-02-03 13:55 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * include/harbour.hbx + * src/rtl/hbfilehi.prg + * HB_PATHMAKEABSOLUTE() swapped two input parameters. Now: ( , ) + * HB_PATHMAKEABSOLUTE() renamed to HB_PATHJOIN() + * HB_PATHMAKERELATIVE() 3rd () parameter default changed to .T. + * HB_PATHMAKERELATIVE() renamed to HB_PATHRELATIVIZE() + * HB_DIRADDPATHSEP() renamed to HB_DIRSEPADD() + * HB_DIRDELPATHSEP() renamed to HB_DIRSEPDEL() + ; HB_PATHNORMALIZE() name finalized + + * contrib/hbide/idemisc.prg + - Deleted unused hbmk2_PathMakeRelative() + 2011-02-03 13:32 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/hbsocket.c * added workaround to pacify warning in some winsock header files diff --git a/harbour/contrib/hbide/idemisc.prg b/harbour/contrib/hbide/idemisc.prg index 950e2e53ae..e1cec4a04e 100644 --- a/harbour/contrib/hbide/idemisc.prg +++ b/harbour/contrib/hbide/idemisc.prg @@ -1519,109 +1519,6 @@ FUNCTION hbide_outputLine( cLine, nOccur ) /*----------------------------------------------------------------------*/ -/* NOTE: Not used by hbmk2 code, but could be useful for - apps creating hbmk2 script/config files. [vszakats] */ -FUNCTION hbmk2_PathMakeRelative( cPathBase, cPathTarget, lForceRelative ) - LOCAL tmp - - LOCAL aPathBase - LOCAL aPathTarget - - LOCAL cTestBase - LOCAL cTestTarget - - LOCAL cTargetFileName - - DEFAULT lForceRelative TO .F. - - cPathBase := hbide_PathMakeAbsolute( hbide_DirAddPathSep( cPathBase ), hb_dirBase() ) - cPathTarget := hbide_PathMakeAbsolute( cPathTarget, hb_dirBase() ) - - /* TODO: Optimize to operate on strings instead of arrays */ - - aPathBase := FN_ToArray( cPathBase ) - aPathTarget := FN_ToArray( cPathTarget, @cTargetFileName ) - - tmp := 1 - cTestBase := "" - cTestTarget := "" - DO WHILE tmp <= Len( aPathTarget ) .AND. tmp <= Len( aPathBase ) - cTestBase += aPathBase[ tmp ] - cTestTarget += aPathTarget[ tmp ] - IF ! hb_FileMatch( cTestBase, cTestTarget ) - EXIT - ENDIF - ++tmp - ENDDO - - IF tmp > Len( aPathTarget ) .AND. tmp > Len( aPathBase ) - tmp-- - ENDIF - - IF tmp == Len( aPathBase ) - RETURN FN_FromArray( aPathTarget, tmp, NIL, cTargetFileName ) - ENDIF - - /* Different drive spec. There is way to solve that using relative dirs. */ - IF ! Empty( hb_osDriveSeparator() ) .AND. ; - tmp == 1 .AND. ; - ( Right( aPathBase[ 1 ] , 1 ) == hb_osDriveSeparator() .OR. ; - Right( aPathTarget[ 1 ], 1 ) == hb_osDriveSeparator() ) - RETURN cPathTarget - ENDIF - - /* Force to return relative paths even when base is different. */ - IF lForceRelative - RETURN FN_FromArray( aPathTarget, tmp, NIL, cTargetFileName, Replicate( ".." + hb_ps(), Len( aPathBase ) - tmp ) ) - ENDIF - - RETURN cPathTarget - - -STATIC FUNCTION FN_ToArray( cPath, /* @ */ cFileName ) - LOCAL cDir, cName, cExt - - hb_FNameSplit( cPath, @cDir, @cName, @cExt ) - - IF ! Empty( cName ) .OR. ! Empty( cExt ) - cFileName := cName + cExt - ENDIF - - RETURN hb_ATokens( cDir, hb_ps() ) - - -STATIC FUNCTION FN_FromArray( aPath, nFrom, nTo, cFileName, cDirPrefix ) - LOCAL cDir - LOCAL tmp - - DEFAULT nFrom TO 1 - DEFAULT nTo TO Len( aPath ) - - IF nFrom > Len( aPath ) .OR. nTo < 1 - RETURN "" - ENDIF - - DEFAULT cDirPrefix TO "" - - IF nFrom < 1 - nFrom := 1 - ENDIF - - IF nTo > Len( aPath ) - nTo := Len( aPath ) - ENDIF - - cDir := "" - FOR tmp := nFrom TO nTo - cDir += aPath[ tmp ] - IF nFrom < nTo - cDir += hb_ps() - ENDIF - NEXT - - RETURN hb_FNameMerge( DirDelPathSep( hbide_DirAddPathSep( cDirPrefix ) + cDir ), cFileName ) - - FUNCTION hbide_DirAddPathSep( cDir ) IF ! Empty( cDir ) .AND. !( Right( cDir, 1 ) == hb_ps() ) @@ -1630,7 +1527,6 @@ FUNCTION hbide_DirAddPathSep( cDir ) RETURN cDir - STATIC FUNCTION DirDelPathSep( cDir ) IF Empty( hb_osDriveSeparator() ) diff --git a/harbour/include/harbour.hbx b/harbour/include/harbour.hbx index 80e19f898a..ba49cd9d4c 100644 --- a/harbour/include/harbour.hbx +++ b/harbour/include/harbour.hbx @@ -382,12 +382,12 @@ DYNAMIC HB_DBRENAME DYNAMIC HB_DBREQUEST DYNAMIC HB_DBZAP DYNAMIC HB_DESERIALIZE -DYNAMIC HB_DIRADDPATHSEP +DYNAMIC HB_DIRSEPADD +DYNAMIC HB_DIRSEPDEL DYNAMIC HB_DIRBASE DYNAMIC HB_DIRBUILD DYNAMIC HB_DIRCREATE DYNAMIC HB_DIRDELETE -DYNAMIC HB_DIRDELPATHSEP DYNAMIC HB_DIREXISTS DYNAMIC HB_DIRSCAN DYNAMIC HB_DIRTEMP @@ -672,8 +672,8 @@ DYNAMIC HB_OSNEWLINE DYNAMIC HB_OSPATHDELIMITERS DYNAMIC HB_OSPATHLISTSEPARATOR DYNAMIC HB_OSPATHSEPARATOR -DYNAMIC HB_PATHMAKEABSOLUTE -DYNAMIC HB_PATHMAKERELATIVE +DYNAMIC HB_PATHJOIN +DYNAMIC HB_PATHRELATIVIZE DYNAMIC HB_PATHNORMALIZE DYNAMIC HB_PCODEVER DYNAMIC HB_PROCESSCLOSE diff --git a/harbour/src/rtl/hbfilehi.prg b/harbour/src/rtl/hbfilehi.prg index 29c8aa9d3b..8e4d4f663f 100644 --- a/harbour/src/rtl/hbfilehi.prg +++ b/harbour/src/rtl/hbfilehi.prg @@ -55,12 +55,11 @@ FUNCTION hb_cwd( cNewDir ) IF hb_isString( cNewDir ) /* TODO */ ENDIF - RETURN hb_DirAddPathSep( hb_CurDrive() + hb_osDriveSeparator() + hb_ps() + CurDir() ) + RETURN hb_DirSepAdd( hb_CurDrive() + hb_osDriveSeparator() + hb_ps() + CurDir() ) #define _ISDRIVESPEC( cDir ) ( ! Empty( hb_osDriveSeparator() ) .AND. Right( cDir, Len( hb_osDriveSeparator() ) ) == hb_osDriveSeparator() ) /* NOTE: Can hurt if there are symlinks on the way. */ -/* QUESTION: Rename to hb_PathOptimize() ? */ FUNCTION hb_PathNormalize( cPath ) LOCAL aDir LOCAL cDir @@ -105,8 +104,7 @@ FUNCTION hb_PathNormalize( cPath ) RETURN cPath -/* QUESTION: Swap the two parameters? */ -FUNCTION hb_PathMakeAbsolute( cPathR, cPathA ) +FUNCTION hb_PathJoin( cPathA, cPathR ) LOCAL cDirA LOCAL cDirR, cDriveR, cNameR, cExtR @@ -132,7 +130,7 @@ FUNCTION hb_PathMakeAbsolute( cPathR, cPathA ) RETURN hb_FNameMerge( cDirA + cDirR, cNameR, cExtR ) -FUNCTION hb_PathMakeRelative( cPathBase, cPathTarget, lForceRelative ) +FUNCTION hb_PathRelativize( cPathBase, cPathTarget, lForceRelative ) LOCAL tmp LOCAL aPathBase @@ -148,11 +146,11 @@ FUNCTION hb_PathMakeRelative( cPathBase, cPathTarget, lForceRelative ) ENDIF IF ! hb_isLogical( lForceRelative ) - lForceRelative := .F. + lForceRelative := .T. ENDIF - cPathBase := hb_PathMakeAbsolute( hb_DirAddPathSep( cPathBase ), hb_dirBase() ) - cPathTarget := hb_PathMakeAbsolute( cPathTarget, hb_dirBase() ) + cPathBase := hb_PathJoin( hb_dirBase(), hb_DirSepAdd( cPathBase ) ) + cPathTarget := hb_PathJoin( hb_dirBase(), cPathTarget ) /* TODO: Optimize to operate on strings instead of arrays */ @@ -226,9 +224,9 @@ STATIC FUNCTION s_FN_FromArray( aPath, nFrom, cFileName, cDirPrefix ) ENDIF NEXT - RETURN hb_FNameMerge( hb_DirDelPathSep( hb_DirAddPathSep( cDirPrefix ) + cDir ), cFileName ) + RETURN hb_FNameMerge( hb_DirSepDel( hb_DirSepAdd( cDirPrefix ) + cDir ), cFileName ) -FUNCTION hb_DirAddPathSep( cDir ) +FUNCTION hb_DirSepAdd( cDir ) IF ! hb_isString( cDir ) RETURN "" @@ -243,7 +241,7 @@ FUNCTION hb_DirAddPathSep( cDir ) RETURN cDir -FUNCTION hb_DirDelPathSep( cDir ) +FUNCTION hb_DirSepDel( cDir ) IF ! hb_isString( cDir ) RETURN "" @@ -277,7 +275,7 @@ FUNCTION hb_DirBuild( cDir ) IF ! hb_DirExists( cDir ) - cDir := hb_DirAddPathSep( cDir ) + cDir := hb_DirSepAdd( cDir ) IF ! Empty( hb_osDriveSeparator() ) .AND. ; ( tmp := At( hb_osDriveSeparator(), cDir ) ) > 0 @@ -319,7 +317,7 @@ FUNCTION hb_DirUnbuild( cDir ) IF hb_DirExists( cDir ) - cDir := hb_DirDelPathSep( cDir ) + cDir := hb_DirSepDel( cDir ) cDirTemp := cDir DO WHILE ! Empty( cDirTemp )