diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e9cfa1860e..103b812524 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,61 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-31 15:48 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * src/rtl/dirdrive.c + + Added HB_DIRCREATE(), which is same as MAKEDIR() C5.3 function, + but it's always available, not just when HB_COMPAT_C53 is enabled. + + Added HB_DIRDELETE(), which is same as DIRREMOVE() C5.3 function, + but it's always available, not just when HB_COMPAT_C53 is enabled. + + * contrib/hbnetio/tests/netiotst.prg + * contrib/hbnetio/tests/netiot03.prg + * contrib/hbfimage/tests/fitest.prg + * contrib/hbide/idesaveload.prg + * utils/hbmk2/hbmk2.prg + * utils/hbrun/hbrun.prg + * tests/wcecon.prg + * tests/flink.prg + * bin/hb3rdpat.hbs + * examples/hbdoc2/gentpl.prg + * Replaced MakeDir() with universally available hb_DirCreate(). + ; TODO: same in config/postinst.hbs (delayed to avoid a million + false bug reports) + + * src/rtl/Makefile + + src/rtl/hbfilehi.prg + + Added generic file/dir/path handling functions. + They are taken from hbmk2 code, added parameter checking, + did two minor change to DirBuild() to be generic, + renamed to have HB_ prefix. + Please note the parameter list and any details are + subject to change yet, IOW these APIs are not yet finalized: + + hb_cwd() -> + hb_PathNormalize( ) -> + hb_PathMakeAbsolute( , ) -> + hb_PathMakeRelative( , , ) -> + hb_DirAddPathSep( ) -> + hb_DirDelPathSep( ) -> + hb_DirBuild( ) -> + hb_DirUnbuild( ) -> + hb_FNameDirGet( ) -> + hb_FNameNameGet( ) -> + hb_FNameNameExtGet( ) -> + hb_FNameExtGet( ) -> + hb_FNameExtDef( , ) -> + hb_FNameExtSet( , ) -> + hb_FNameDirExtSet( , , ) -> + + ; TODO: Review, clean interface. + ; TODO: Use these functions in .hbs files, utils, hbide. + + * include/harbour.hbx + * Updated. + + * utils/hbmk2/hbmk2.prg + * One internal function renamed. + 2011-01-31 13:38 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbide/idemisc.prg ! Applied FN_FromArray() fix to the copy in HBIDE. diff --git a/harbour/bin/hb3rdpat.hbs b/harbour/bin/hb3rdpat.hbs index ac7e2670de..0b2a9b1a87 100755 --- a/harbour/bin/hb3rdpat.hbs +++ b/harbour/bin/hb3rdpat.hbs @@ -399,13 +399,13 @@ PROCEDURE Main( ... ) FClose( hb_FTempCreateEx( @s_cTempDir, cRoot, FNameNameGet( hb_ProgName() ) + "_" ) ) FErase( s_cTempDir ) - MakeDir( s_cTempDir ) + hb_DirCreate( s_cTempDir ) cThisComponent := FNameNameGet( cCWD ) - MakeDir( CombinePath( s_cTempDir, cThisComponent ) ) - MakeDir( CombinePath( s_cTempDir, cThisComponent + ".orig" ) ) - MakeDir( CombinePath( s_cTempDir, "root" ) ) + hb_DirCreate( CombinePath( s_cTempDir, cThisComponent ) ) + hb_DirCreate( CombinePath( s_cTempDir, cThisComponent + ".orig" ) ) + hb_DirCreate( CombinePath( s_cTempDir, "root" ) ) IF lRediff .AND. cDiffFile == NIL OutStd( "Requested rediff mode with no existing local diff, attempting to create one." + hb_eol() ) diff --git a/harbour/contrib/hbfimage/tests/fitest.prg b/harbour/contrib/hbfimage/tests/fitest.prg index 56aaf3b9e1..af76eda7ac 100644 --- a/harbour/contrib/hbfimage/tests/fitest.prg +++ b/harbour/contrib/hbfimage/tests/fitest.prg @@ -34,7 +34,7 @@ PROCEDURE Main() // Check output directory IF !hb_DirExists( IMAGES_OUT ) #ifdef HB_COMPAT_C53 - MakeDir( IMAGES_OUT ) + hb_DirCreate( IMAGES_OUT ) #endif ENDIF diff --git a/harbour/contrib/hbide/idesaveload.prg b/harbour/contrib/hbide/idesaveload.prg index 83efdaf910..79023928ad 100644 --- a/harbour/contrib/hbide/idesaveload.prg +++ b/harbour/contrib/hbide/idesaveload.prg @@ -774,7 +774,7 @@ FUNCTION hbide_getIniPath( cHbideIni ) cPath := hbide_DirAddPathSep( GetEnv( "HOME" ) ) + ".hbide/" #endif IF ! hb_dirExists( cPath ) - MakeDir( cPath ) + hb_DirCreate( cPath ) ENDIF cIni := cPath + "hbide.ini" ENDIF diff --git a/harbour/contrib/hbnetio/tests/netiot03.prg b/harbour/contrib/hbnetio/tests/netiot03.prg index 80c3409e88..65ef086f54 100644 --- a/harbour/contrib/hbnetio/tests/netiot03.prg +++ b/harbour/contrib/hbnetio/tests/netiot03.prg @@ -26,7 +26,7 @@ request DBFCDX request HB_DIREXISTS -request MAKEDIR +request HB_DIRCREATE request HB_DATETIME proc main() @@ -84,7 +84,7 @@ proc main() ? "Directory './data'", iif( !lExists, "not exists", "exists" ) if !lExists ? "Creating directory './data' ->", ; - iif( netio_funcexec( "MakeDir", "./data" ) == -1, "error", "OK" ) + iif( netio_funcexec( "hb_DirCreate", "./data" ) == -1, "error", "OK" ) endif createdb( DBNAME ) diff --git a/harbour/contrib/hbnetio/tests/netiotst.prg b/harbour/contrib/hbnetio/tests/netiotst.prg index 35d6969a3c..c728e544ed 100644 --- a/harbour/contrib/hbnetio/tests/netiotst.prg +++ b/harbour/contrib/hbnetio/tests/netiotst.prg @@ -26,7 +26,7 @@ request DBFCDX request HB_DIREXISTS -request MAKEDIR +request HB_DIRCREATE proc main() local pSockSrv, lExists @@ -53,7 +53,7 @@ proc main() ? "Directory './data'", iif( !lExists, "not exists", "exists" ) if !lExists ? "Creating directory './data' ->", ; - iif( netio_funcexec( "MakeDir", "./data" ) == -1, "error", "OK" ) + iif( netio_funcexec( "hb_DirCreate", "./data" ) == -1, "error", "OK" ) endif ? "'" + DBNAME + "'" diff --git a/harbour/examples/hbdoc2/gentpl.prg b/harbour/examples/hbdoc2/gentpl.prg index 9f20a54db9..4d56062ff6 100644 --- a/harbour/examples/hbdoc2/gentpl.prg +++ b/harbour/examples/hbdoc2/gentpl.prg @@ -105,9 +105,9 @@ METHOD New( cFolder, cFilename, cTitle, cExtension, nType ) CLASS TPLGenerate ::cExtension := cExtension ::nType := nType - IF EMPTY( DIRECTORY( ::cFolder, "D" ) ) + IF hb_DirExists( ::cFolder ) ? "Creating folder " + ::cFolder - MAKEDIR( ::cFolder ) + hb_DirCreate( ::cFolder ) ENDIF ::nHandle := FCreate( ::cFolder + hb_ps() + ::cFilename + ::cExtension ) diff --git a/harbour/include/harbour.hbx b/harbour/include/harbour.hbx index 6287047f5f..a10d686f86 100644 --- a/harbour/include/harbour.hbx +++ b/harbour/include/harbour.hbx @@ -370,6 +370,7 @@ DYNAMIC HB_CSTR DYNAMIC HB_CTOD DYNAMIC HB_CTOT DYNAMIC HB_CURDRIVE +DYNAMIC HB_CWD DYNAMIC HB_DATE DYNAMIC HB_DATETIME DYNAMIC HB_DBCREATETEMP @@ -381,10 +382,16 @@ DYNAMIC HB_DBRENAME DYNAMIC HB_DBREQUEST DYNAMIC HB_DBZAP DYNAMIC HB_DESERIALIZE +DYNAMIC HB_DIRADDPATHSEP DYNAMIC HB_DIRBASE +DYNAMIC HB_DIRBUILD +DYNAMIC HB_DIRCREATE +DYNAMIC HB_DIRDELETE +DYNAMIC HB_DIRDELPATHSEP DYNAMIC HB_DIREXISTS DYNAMIC HB_DIRSCAN DYNAMIC HB_DIRTEMP +DYNAMIC HB_DIRUNBUILD DYNAMIC HB_DISABLEWAITLOCKS DYNAMIC HB_DISKSPACE DYNAMIC HB_DISPBOX @@ -413,8 +420,15 @@ DYNAMIC HB_FLINK DYNAMIC HB_FLINKREAD DYNAMIC HB_FLINKSYM DYNAMIC HB_FLOCK +DYNAMIC HB_FNAMEDIREXTSET +DYNAMIC HB_FNAMEDIRGET DYNAMIC HB_FNAMEEXISTS +DYNAMIC HB_FNAMEEXTDEF +DYNAMIC HB_FNAMEEXTGET +DYNAMIC HB_FNAMEEXTSET DYNAMIC HB_FNAMEMERGE +DYNAMIC HB_FNAMENAMEEXTGET +DYNAMIC HB_FNAMENAMEGET DYNAMIC HB_FNAMESPLIT DYNAMIC HB_FORNEXT DYNAMIC HB_FSETATTR @@ -659,6 +673,9 @@ DYNAMIC HB_OSNEWLINE DYNAMIC HB_OSPATHDELIMITERS DYNAMIC HB_OSPATHLISTSEPARATOR DYNAMIC HB_OSPATHSEPARATOR +DYNAMIC HB_PATHMAKEABSOLUTE +DYNAMIC HB_PATHMAKERELATIVE +DYNAMIC HB_PATHNORMALIZE DYNAMIC HB_PCODEVER DYNAMIC HB_PROCESSCLOSE DYNAMIC HB_PROCESSOPEN diff --git a/harbour/src/rtl/Makefile b/harbour/src/rtl/Makefile index d7f3580768..17e51f9c41 100644 --- a/harbour/src/rtl/Makefile +++ b/harbour/src/rtl/Makefile @@ -228,6 +228,7 @@ PRG_SOURCES := \ getsyshb.prg \ gui.prg \ hbdoc.prg \ + hbfilehi.prg \ hbi18n2.prg \ hbini.prg \ input.prg \ diff --git a/harbour/src/rtl/dirdrive.c b/harbour/src/rtl/dirdrive.c index b3ecf91fa2..40e173bc0c 100644 --- a/harbour/src/rtl/dirdrive.c +++ b/harbour/src/rtl/dirdrive.c @@ -50,11 +50,27 @@ * */ -/* NOTE: Clipper 5.3 functions */ - #include "hbapi.h" #include "hbapifs.h" +HB_FUNC( HB_DIRCREATE ) +{ + if( HB_ISCHAR( 1 ) ) + hb_retni( hb_fsMkDir( hb_parc( 1 ) ) ? 0 : hb_fsError() ); + else + hb_retni( F_ERROR ); +} + +HB_FUNC( HB_DIRDELETE ) +{ + if( HB_ISCHAR( 1 ) ) + hb_retni( hb_fsRmDir( hb_parc( 1 ) ) ? 0 : hb_fsError() ); + else + hb_retni( F_ERROR ); +} + +/* NOTE: Clipper 5.3 functions */ + #ifdef HB_COMPAT_C53 HB_FUNC( DIRCHANGE ) @@ -70,18 +86,12 @@ HB_FUNC( DIRCHANGE ) HB_FUNC( MAKEDIR ) { - if( HB_ISCHAR( 1 ) ) - hb_retni( hb_fsMkDir( hb_parc( 1 ) ) ? 0 : hb_fsError() ); - else - hb_retni( F_ERROR ); + HB_FUNC_EXEC( HB_DIRCREATE ); } HB_FUNC( DIRREMOVE ) { - if( HB_ISCHAR( 1 ) ) - hb_retni( hb_fsRmDir( hb_parc( 1 ) ) ? 0 : hb_fsError() ); - else - hb_retni( F_ERROR ); + HB_FUNC_EXEC( HB_DIRDELETE ); } /* NOTE: Clipper 5.3 undocumented */ diff --git a/harbour/src/rtl/hbfilehi.prg b/harbour/src/rtl/hbfilehi.prg new file mode 100644 index 0000000000..943a9ab89e --- /dev/null +++ b/harbour/src/rtl/hbfilehi.prg @@ -0,0 +1,399 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * High-level portable file functions. + * + * Copyright 2009-2011 Viktor Szakats (harbour.01 syenar.hu) + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "common.ch" + +FUNCTION hb_cwd() + RETURN hb_DirAddPathSep( 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. */ +FUNCTION hb_PathNormalize( cPath ) + LOCAL aDir + LOCAL cDir + + IF ! hb_isString( cPath ) + RETURN "" + ENDIF + + IF ! Empty( cPath ) + + aDir := hb_ATokens( cPath, hb_ps() ) + + FOR EACH cDir IN aDir DESCEND + IF cDir == "." + hb_ADel( aDir, cDir:__enumIndex(), .T. ) + ELSEIF !( cDir == ".." ) .AND. ; + ! Empty( cDir ) .AND. ; + ! _ISDRIVESPEC( cDir ) + IF cDir:__enumIndex() < Len( cDir:__enumBase() ) .AND. ; + aDir[ cDir:__enumIndex() + 1 ] == ".." + hb_ADel( aDir, cDir:__enumIndex() + 1, .T. ) + hb_ADel( aDir, cDir:__enumIndex(), .T. ) + ENDIF + ENDIF + NEXT + + cPath := "" + FOR EACH cDir IN aDir + cPath += cDir + IF cDir:__enumIndex() < Len( cDir:__enumBase() ) + cPath += hb_ps() + ENDIF + NEXT + + IF Empty( cPath ) + cPath := "." + hb_ps() + ENDIF + ENDIF + + RETURN cPath + +/* QUESTION: Swap the two parameters? */ +FUNCTION hb_PathMakeAbsolute( cPathR, cPathA ) + LOCAL cDirA + LOCAL cDirR, cDriveR, cNameR, cExtR + + IF ! hb_isString( cPathR ) + RETURN "" + ENDIF + + IF ! hb_isString( cPathA ) .OR. Empty( cPathA ) + RETURN cPathR + ENDIF + + hb_FNameSplit( cPathR, @cDirR, @cNameR, @cExtR, @cDriveR ) + + IF ! Empty( cDriveR ) .OR. ( ! Empty( cDirR ) .AND. Left( cDirR, 1 ) $ hb_osPathDelimiters() ) + RETURN cPathR + ENDIF + + hb_FNameSplit( cPathA, @cDirA ) + + IF Empty( cDirA ) + RETURN cPathR + ENDIF + + RETURN hb_FNameMerge( cDirA + cDirR, cNameR, cExtR ) + +FUNCTION hb_PathMakeRelative( cPathBase, cPathTarget, lForceRelative ) + LOCAL tmp + + LOCAL aPathBase + LOCAL aPathTarget + + LOCAL cTestBase + LOCAL cTestTarget + + LOCAL cTargetFileName + + IF ! hb_isString( cPathBase ) .OR. ! hb_isString( cPathTarget ) + RETURN "" + ENDIF + + IF ! hb_isLogical( lForceRelative ) + lForceRelative := .F. + ENDIF + + cPathBase := hb_PathMakeAbsolute( hb_DirAddPathSep( cPathBase ), hb_dirBase() ) + cPathTarget := hb_PathMakeAbsolute( cPathTarget, hb_dirBase() ) + + /* TODO: Optimize to operate on strings instead of arrays */ + + aPathBase := s_FN_ToArray( cPathBase ) + aPathTarget := s_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 s_FN_FromArray( aPathTarget, tmp, NIL, cTargetFileName ) + ENDIF + + /* Different drive spec. There is no 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 s_FN_FromArray( aPathTarget, tmp, NIL, cTargetFileName, Replicate( ".." + hb_ps(), Len( aPathBase ) - tmp ) ) + ENDIF + + RETURN cPathTarget + +STATIC FUNCTION s_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 s_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( hb_DirDelPathSep( hb_DirAddPathSep( cDirPrefix ) + cDir ), cFileName ) + +FUNCTION hb_DirAddPathSep( cDir ) + + IF ! hb_isString( cDir ) + RETURN "" + ENDIF + + IF ! Empty( cDir ) .AND. !( Right( cDir, 1 ) == hb_ps() ) + cDir += hb_ps() + ENDIF + + RETURN cDir + +FUNCTION hb_DirDelPathSep( cDir ) + + IF ! hb_isString( cDir ) + RETURN "" + ENDIF + + IF Empty( hb_osDriveSeparator() ) + DO WHILE Len( cDir ) > 1 .AND. Right( cDir, 1 ) == hb_ps() + cDir := hb_StrShrink( cDir, 1 ) + ENDDO + ELSE + DO WHILE Len( cDir ) > 1 .AND. Right( cDir, 1 ) == hb_ps() .AND. ; + !( Right( cDir, 2 ) == hb_osDriveSeparator() + hb_ps() ) + cDir := hb_StrShrink( cDir, 1 ) + ENDDO + ENDIF + + RETURN cDir + +FUNCTION hb_DirBuild( cDir ) + LOCAL cDirTemp + LOCAL cDirItem + LOCAL tmp + + IF ! hb_isString( cDir ) + RETURN .F. + ENDIF + + cDir := hb_PathNormalize( cDir ) + + IF ! hb_DirExists( cDir ) + + cDir := hb_DirAddPathSep( cDir ) + + IF ! Empty( hb_osDriveSeparator() ) .AND. ; + ( tmp := At( hb_osDriveSeparator(), cDir ) ) > 0 + cDirTemp := Left( cDir, tmp ) + cDir := SubStr( cDir, tmp + 1 ) + ELSEIF Left( cDir, 1 ) == hb_ps() + cDirTemp := Left( cDir, 1 ) + cDir := SubStr( cDir, 2 ) + ELSE + cDirTemp := "" + ENDIF + + FOR EACH cDirItem IN hb_ATokens( cDir, hb_ps() ) + IF !( Right( cDirTemp, 1 ) == hb_ps() ) .AND. ! Empty( cDirTemp ) + cDirTemp += hb_ps() + ENDIF + IF ! Empty( cDirItem ) /* Skip root path, if any */ + cDirTemp += cDirItem + IF hb_FileExists( cDirTemp ) + RETURN .F. + ELSEIF ! hb_DirExists( cDirTemp ) + IF hb_DirCreate( cDirTemp ) != 0 + RETURN .F. + ENDIF + ENDIF + ENDIF + NEXT + ENDIF + + RETURN .T. + +FUNCTION hb_DirUnbuild( cDir ) + LOCAL cDirTemp + LOCAL tmp + + IF ! hb_isString( cDir ) + RETURN .F. + ENDIF + + IF hb_DirExists( cDir ) + + cDir := hb_DirDelPathSep( cDir ) + + cDirTemp := cDir + DO WHILE ! Empty( cDirTemp ) + IF hb_DirExists( cDirTemp ) + IF hb_DirDelete( cDirTemp ) != 0 + RETURN .F. + ENDIF + ENDIF + IF ( tmp := RAt( hb_ps(), cDirTemp ) ) == 0 + EXIT + ENDIF + cDirTemp := Left( cDirTemp, tmp - 1 ) + IF ! Empty( hb_osDriveSeparator() ) .AND. ; + Right( cDirTemp, 1 ) == hb_osDriveSeparator() + EXIT + ENDIF + ENDDO + ENDIF + + RETURN .T. + +FUNCTION hb_FNameDirGet( cFileName ) + LOCAL cDir + + hb_FNameSplit( cFileName, @cDir ) + + RETURN cDir + +FUNCTION hb_FNameNameGet( cFileName ) + LOCAL cName + + hb_FNameSplit( cFileName,, @cName ) + + RETURN cName + +FUNCTION hb_FNameNameExtGet( cFileName ) + LOCAL cName, cExt + + hb_FNameSplit( cFileName,, @cName, @cExt ) + + RETURN hb_FNameMerge( NIL, cName, cExt ) + +FUNCTION hb_FNameExtGet( cFileName ) + LOCAL cExt + + hb_FNameSplit( cFileName,,, @cExt ) + + RETURN cExt + +FUNCTION hb_FNameExtDef( cFileName, cDefExt ) + LOCAL cDir, cName, cExt + + hb_FNameSplit( cFileName, @cDir, @cName, @cExt ) + + IF Empty( cExt ) + cExt := cDefExt + ENDIF + + RETURN hb_FNameMerge( cDir, cName, cExt ) + +FUNCTION hb_FNameExtSet( cFileName, cExt ) + LOCAL cDir, cName + + hb_FNameSplit( cFileName, @cDir, @cName ) + + RETURN hb_FNameMerge( cDir, cName, cExt ) + +FUNCTION hb_FNameDirExtSet( cFileName, cDirNew, cExtNew ) + LOCAL cDir, cName, cExt + + hb_FNameSplit( cFileName, @cDir, @cName, @cExt ) + + IF cDirNew != NIL + cDir := cDirNew + ENDIF + IF cExtNew != NIL + cExt := cExtNew + ENDIF + + RETURN hb_FNameMerge( cDir, cName, cExt ) diff --git a/harbour/tests/flink.prg b/harbour/tests/flink.prg index ef50a5f3c0..e1d082c71e 100644 --- a/harbour/tests/flink.prg +++ b/harbour/tests/flink.prg @@ -42,7 +42,7 @@ PROCEDURE Main() ? HB_FLINKREAD( "_hb_slnk.tmp" ) ? FERROR() - MakeDir( "_hb_d" ) + hb_DirCreate( "_hb_d" ) ? HB_FLINKSYM( "_hb_d.tmp", "_hb_dlnk.tmp" ) ? FERROR() diff --git a/harbour/tests/wcecon.prg b/harbour/tests/wcecon.prg index 05a430b0ca..897451665b 100644 --- a/harbour/tests/wcecon.prg +++ b/harbour/tests/wcecon.prg @@ -59,7 +59,7 @@ proc main() rddSetDefault("DBFCDX") if !hb_dirExists( cPath ) - MakeDir( cPath ) + hb_dirCreate( cPath ) endif dbCreate( cPath + "mydata", { { "F1", "C", 10, 0 }, ; { "F2", "=", 8, 0 }, ; diff --git a/harbour/utils/hbmk2/hbmk2.prg b/harbour/utils/hbmk2/hbmk2.prg index af90c72623..647bb27309 100644 --- a/harbour/utils/hbmk2/hbmk2.prg +++ b/harbour/utils/hbmk2/hbmk2.prg @@ -495,9 +495,6 @@ REQUEST hbmk_KEYW #define HBMK_ISPLAT( list ) HBMK_IS_IN( hbmk[ _HBMK_cPLAT ], list ) #define HBMK_ISCOMP( list ) HBMK_IS_IN( hbmk[ _HBMK_cCOMP ], list ) -#define hb_DirCreate( d ) MakeDir( d ) -#define hb_DirDelete( d ) DirRemove( d ) - /* Request some functions for plugins */ REQUEST HB_REGEX REQUEST HBCLASS @@ -5633,11 +5630,11 @@ FUNCTION hbmk2( aArgs, nArgTarget, /* @ */ lPause, nLevel ) cOpt_CompC := StrTran( cOpt_CompC, "{OW}" , FNameEscape( hbmk[ _HBMK_cWorkDir ], nOpt_Esc, nOpt_FNF ) ) IF lCHD_Comp - tmp2 := DirAddPathSep( PathMakeRelative( PathNormalize( PathMakeAbsolute( hbmk[ _HBMK_cWorkDir ], hb_pwd() ) ), hb_pwd(), .T. ) ) + tmp2 := DirAddPathSep( PathMakeRelative( PathNormalize( PathMakeAbsolute( hbmk[ _HBMK_cWorkDir ], hb_cwd() ) ), hb_cwd(), .T. ) ) IF hbmk[ _HBMK_lDONTEXEC ] cCHD_DirOld := NIL ELSE - cCHD_DirOld := hb_pwd() + cCHD_DirOld := hb_cwd() IF hbmk[ _HBMK_lTRACE ] .AND. hbmk[ _HBMK_lInfo ] hbmk_OutStd( hbmk, hb_StrFormat( I_( "'cd' to: %1$s" ), hbmk[ _HBMK_cWorkDir ] ) ) ENDIF @@ -6296,7 +6293,7 @@ STATIC PROCEDURE convert_incpaths_to_options( hbmk, cOptIncMask, lCHD_Comp ) LOCAL cINCPATH IF lCHD_Comp - cBaseDir := DirAddPathSep( PathMakeRelative( PathNormalize( PathMakeAbsolute( hbmk[ _HBMK_cWorkDir ], hb_pwd() ) ), hb_pwd(), .T. ) ) + cBaseDir := DirAddPathSep( PathMakeRelative( PathNormalize( PathMakeAbsolute( hbmk[ _HBMK_cWorkDir ], hb_cwd() ) ), hb_cwd(), .T. ) ) ENDIF FOR EACH cINCPATH IN hbmk[ _HBMK_aINCPATH ] @@ -7814,7 +7811,7 @@ STATIC PROCEDURE PlugIn_Load( hbmk, cFileName ) /* Public functions accessible for plugins */ -FUNCTION hbmk2_CWD() ; RETURN hb_pwd() +FUNCTION hbmk2_CWD() ; RETURN hb_cwd() FUNCTION hbmk2_FindInPath( ... ) ; RETURN FindInPath( ... ) FUNCTION hbmk2_PathNormalize( ... ) ; RETURN PathNormalize( ... ) FUNCTION hbmk2_PathMakeAbsolute( ... ) ; RETURN PathMakeAbsolute( ... ) @@ -7868,7 +7865,7 @@ STATIC FUNCTION ctx_to_hbmk( ctx ) FUNCTION hbmk2_PathFromWorkdirToCWD( ctx ) LOCAL hbmk := ctx_to_hbmk( ctx ) IF hbmk != NIL - RETURN DirAddPathSep( PathMakeRelative( PathNormalize( PathMakeAbsolute( hbmk[ _HBMK_cWorkDir ], hb_pwd() ) ), hb_pwd(), .T. ) ) + RETURN DirAddPathSep( PathMakeRelative( PathNormalize( PathMakeAbsolute( hbmk[ _HBMK_cWorkDir ], hb_cwd() ) ), hb_cwd(), .T. ) ) ENDIF RETURN "" @@ -9637,7 +9634,7 @@ STATIC FUNCTION ArchCompFilter( hbmk, cItem ) RETURN cItem -STATIC FUNCTION hb_pwd() +STATIC FUNCTION hb_cwd() RETURN DirAddPathSep( hb_CurDrive() + hb_osDriveSeparator() + hb_ps() + CurDir() ) STATIC FUNCTION MacroProc( hbmk, cString, cFileName, cMacroPrefix ) @@ -9683,7 +9680,7 @@ STATIC FUNCTION MacroGet( hbmk, cMacro, cFileName ) CASE "HB_SELF" cMacro := PathSepToSelf( cFileName ) ; EXIT CASE "HB_CURDIR" - cMacro := hb_pwd() ; EXIT + cMacro := hb_cwd() ; EXIT CASE "HB_TEMPDIR" cMacro := hb_DirTemp() ; EXIT CASE "HB_TARGETNAME" diff --git a/harbour/utils/hbrun/hbrun.prg b/harbour/utils/hbrun/hbrun.prg index 1cf58b48b8..dd29f742a9 100644 --- a/harbour/utils/hbrun/hbrun.prg +++ b/harbour/utils/hbrun/hbrun.prg @@ -587,7 +587,7 @@ STATIC FUNCTION hbrun_HistoryFileName() ENDIF IF ! hb_dirExists( cDir ) - MakeDir( cDir ) + hb_dirCreate( cDir ) ENDIF RETURN cDir + hb_ps() + cFileName