From 3069cd38a2d82859accd9bea74cef7c45254533d Mon Sep 17 00:00:00 2001 From: Aleksander Czajczynski Date: Wed, 14 Apr 2021 22:25:13 +0200 Subject: [PATCH] 2021-04-14 22:25 UTC+0200 Aleksander Czajczynski (hb fki.pl) + src/rtl/vfilehi.prg * src/rtl/Makefile * src/harbour.def * include/harbour.hbx + added FILE API counterparts to hb_DirBuild() and hb_FNameExists() hb_vfDirBuild( ) -> hb_vfDirUnbuild( ) -> hb_vfNameExists( ) -> ; their implementations are imported from 3.4 https://github.com/vszakats/hb/blob/master/src/rtl/hbfilehi.prg but were renamed to fit in the hb_vf* namespace * src/rtl/hbfilehi.prg * use hb_LeftEq() instead of Left() == ; partial merge of 3.4 2015-07-27 14:26 UTC+0200 Viktor Szakats ! fix several sloppy checks where Empty() were used on strings while in fact a zero length check would have been correct. ; Empty() is a "weasel-word" when used on strings, should be used carefully and sparingly. * ChangeLog.txt % avoid spaces before EOLs --- ChangeLog.txt | 30 +++++++++- include/harbour.hbx | 3 + src/harbour.def | 3 + src/rtl/Makefile | 1 + src/rtl/hbfilehi.prg | 31 +++++----- src/rtl/vfilehi.prg | 131 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 180 insertions(+), 19 deletions(-) create mode 100644 src/rtl/vfilehi.prg diff --git a/ChangeLog.txt b/ChangeLog.txt index e9061c078d..4d1c971198 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,32 @@ Entries may not always be in chronological/commit order. See license at the end of file. */ +2021-04-14 22:25 UTC+0200 Aleksander Czajczynski (hb fki.pl) + + src/rtl/vfilehi.prg + * src/rtl/Makefile + * src/harbour.def + * include/harbour.hbx + + added FILE API counterparts to hb_DirBuild() and hb_FNameExists() + hb_vfDirBuild( ) -> + hb_vfDirUnbuild( ) -> + hb_vfNameExists( ) -> + ; their implementations are imported from 3.4 + https://github.com/vszakats/hb/blob/master/src/rtl/hbfilehi.prg + but were renamed to fit in the hb_vf* namespace + + * src/rtl/hbfilehi.prg + * use hb_LeftEq() instead of Left() == + ; partial merge of 3.4 + 2015-07-27 14:26 UTC+0200 Viktor Szakats + ! fix several sloppy checks where Empty() were + used on strings while in fact a zero length + check would have been correct. + ; Empty() is a "weasel-word" when used on strings, + should be used carefully and sparingly. + + * ChangeLog.txt + % avoid spaces before EOLs + 2021-04-12 21:18 UTC+0200 Aleksander Czajczynski (hb fki.pl) * src/rtl/hbfilehi.prg * hb_DirBuild() will now honor UNC "\\server\share\dir\tree" parameter @@ -16,7 +42,7 @@ folder was created on current drive, as if the UNC specifier was omitted. It was more or less consistent with other platforms but not expected for this platform. Spotted by Maurizio la Cecilia (#233) - [INCOMPATIBLE] + [INCOMPATIBLE] * contrib/hbdoc/hbdoc.prg * contrib/hbformat/utils/hbformat.prg @@ -27,7 +53,7 @@ * utils/hbi18n/hbi18n.prg * utils/hbtest/hbtest.prg * bumped copyright year to 2021 - + 2021-04-10 23:32 UTC+0200 Aleksander Czajczynski (hb fki.pl) * contrib/hbfbird/firebird.c + added optional as 7-th parameter of FBCREATEDB( , diff --git a/include/harbour.hbx b/include/harbour.hbx index 6ab691c188..dbcd1ab2ff 100644 --- a/include/harbour.hbx +++ b/include/harbour.hbx @@ -941,10 +941,12 @@ DYNAMIC hb_vfCommit DYNAMIC hb_vfConfig DYNAMIC hb_vfCopyFile DYNAMIC hb_vfDirectory +DYNAMIC hb_vfDirBuild DYNAMIC hb_vfDirExists DYNAMIC hb_vfDirMake DYNAMIC hb_vfDirRemove DYNAMIC hb_vfDirSpace +DYNAMIC hb_vfDirUnbuild DYNAMIC hb_vfEof DYNAMIC hb_vfErase DYNAMIC hb_vfExists @@ -957,6 +959,7 @@ DYNAMIC hb_vfLoad DYNAMIC hb_vfLock DYNAMIC hb_vfLockTest DYNAMIC hb_vfMoveFile +DYNAMIC hb_vfNameExists DYNAMIC hb_vfOpen DYNAMIC hb_vfRead DYNAMIC hb_vfReadAt diff --git a/src/harbour.def b/src/harbour.def index 647f996c27..97e2eb5378 100644 --- a/src/harbour.def +++ b/src/harbour.def @@ -1132,11 +1132,13 @@ HB_FUN_HB_VFCLOSE HB_FUN_HB_VFCOMMIT HB_FUN_HB_VFCONFIG HB_FUN_HB_VFCOPYFILE +HB_FUN_HB_VFDIRBUILD HB_FUN_HB_VFDIRECTORY HB_FUN_HB_VFDIREXISTS HB_FUN_HB_VFDIRMAKE HB_FUN_HB_VFDIRREMOVE HB_FUN_HB_VFDIRSPACE +HB_FUN_HB_VFDIRUNBUILD HB_FUN_HB_VFEOF HB_FUN_HB_VFERASE HB_FUN_HB_VFEXISTS @@ -1149,6 +1151,7 @@ HB_FUN_HB_VFLOAD HB_FUN_HB_VFLOCK HB_FUN_HB_VFLOCKTEST HB_FUN_HB_VFMOVEFILE +HB_FUN_HB_VFNAMEEXISTS HB_FUN_HB_VFOPEN HB_FUN_HB_VFREAD HB_FUN_HB_VFREADAT diff --git a/src/rtl/Makefile b/src/rtl/Makefile index 6472d624df..36daf25768 100644 --- a/src/rtl/Makefile +++ b/src/rtl/Makefile @@ -289,6 +289,7 @@ PRG_SOURCES := \ ttopbar.prg \ typefile.prg \ valtoexp.prg \ + vfilehi.prg \ wait.prg \ LIBNAME := hbrtl diff --git a/src/rtl/hbfilehi.prg b/src/rtl/hbfilehi.prg index 14d055fe6d..e25be36eea 100644 --- a/src/rtl/hbfilehi.prg +++ b/src/rtl/hbfilehi.prg @@ -1,7 +1,7 @@ /* * High-level portable file functions. * - * Copyright 2009-2011 Viktor Szakats (vszakats.net/harbour) + * Copyright 2009-2017 Viktor Szakats (vsz.me/hb) * * 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 @@ -280,16 +280,16 @@ FUNCTION hb_DirBuild( cDir ) cDir := hb_DirSepAdd( cDir ) - IF ! Empty( hb_osDriveSeparator() ) .AND. ; + IF ! hb_osDriveSeparator() == "" .AND. ; ( tmp := At( hb_osDriveSeparator(), cDir ) ) > 0 cDirTemp := Left( cDir, tmp ) cDir := SubStr( cDir, tmp + 1 ) #ifdef __PLATFORM__WINDOWS - ELSEIF Left( cDir, 2 ) == "\\" /* UNC Path, network share */ + ELSEIF hb_LeftEq( cDir, "\\" ) /* UNC Path, network share */ cDirTemp := Left( cDir, hb_At( "\", cDir, 3 ) ) cDir := SubStr( cDir, Len( cDirTemp ) + 1 ) #endif - ELSEIF Left( cDir, 1 ) == hb_ps() + ELSEIF hb_LeftEq( cDir, hb_ps() ) cDirTemp := Left( cDir, 1 ) cDir := SubStr( cDir, 2 ) ELSE @@ -297,10 +297,10 @@ FUNCTION hb_DirBuild( cDir ) ENDIF FOR EACH cDirItem IN hb_ATokens( cDir, hb_ps() ) - IF !( Right( cDirTemp, 1 ) == hb_ps() ) .AND. ! Empty( cDirTemp ) + IF ! Right( cDirTemp, 1 ) == hb_ps() .AND. ! cDirTemp == "" cDirTemp += hb_ps() ENDIF - IF ! Empty( cDirItem ) /* Skip root path, if any */ + IF ! cDirItem == "" /* Skip root path, if any */ cDirTemp += cDirItem IF hb_FileExists( cDirTemp ) RETURN .F. @@ -317,7 +317,6 @@ FUNCTION hb_DirBuild( cDir ) FUNCTION hb_DirUnbuild( cDir ) - LOCAL cDirTemp LOCAL tmp IF ! HB_ISSTRING( cDir ) @@ -328,19 +327,17 @@ FUNCTION hb_DirUnbuild( cDir ) cDir := hb_DirSepDel( cDir ) - cDirTemp := cDir - DO WHILE ! Empty( cDirTemp ) - IF hb_DirExists( cDirTemp ) - IF hb_DirDelete( cDirTemp ) != 0 - RETURN .F. - ENDIF + DO WHILE ! Empty( cDir ) + IF hb_DirExists( cDir ) .AND. ; + hb_DirDelete( cDir ) != 0 + RETURN .F. ENDIF - IF ( tmp := RAt( hb_ps(), cDirTemp ) ) == 0 + IF ( tmp := RAt( hb_ps(), cDir ) ) == 0 /* FIXME: use hb_URAt() function */ EXIT ENDIF - cDirTemp := Left( cDirTemp, tmp - 1 ) - IF ! Empty( hb_osDriveSeparator() ) .AND. ; - Right( cDirTemp, Len( hb_osDriveSeparator() ) ) == hb_osDriveSeparator() + cDir := Left( cDir, tmp - 1 ) + IF ! hb_osDriveSeparator() == "" .AND. ; + Right( cDir, Len( hb_osDriveSeparator() ) ) == hb_osDriveSeparator() EXIT ENDIF ENDDO diff --git a/src/rtl/vfilehi.prg b/src/rtl/vfilehi.prg new file mode 100644 index 0000000000..1e86c2b657 --- /dev/null +++ b/src/rtl/vfilehi.prg @@ -0,0 +1,131 @@ +/* + * High-level VF FILE API based functions. + * + * Copyright 2009-2017 Viktor Szakats (vsz.me/hb) + * + * 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 program; see the file LICENSE.txt. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA (or visit https://www.gnu.org/licenses/). + * + * 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. + * + */ + +FUNCTION hb_vfDirBuild( cDir ) + + LOCAL cDirTemp + LOCAL cDirItem + LOCAL tmp + + IF ! HB_ISSTRING( cDir ) + RETURN .F. + ENDIF + + cDir := hb_PathNormalize( cDir ) + + IF ! hb_vfDirExists( cDir ) + + cDir := hb_DirSepAdd( cDir ) + + IF ! hb_osDriveSeparator() == "" .AND. ; + ( tmp := At( hb_osDriveSeparator(), cDir ) ) > 0 + cDirTemp := Left( cDir, tmp ) + cDir := SubStr( cDir, tmp + 1 ) +#ifdef __PLATFORM__WINDOWS + ELSEIF hb_LeftEq( cDir, "\\" ) /* UNC Path, network share */ + cDirTemp := Left( cDir, hb_At( "\", cDir, 3 ) ) + cDir := SubStr( cDir, Len( cDirTemp ) + 1 ) +#endif + ELSEIF hb_LeftEq( cDir, 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. ! cDirTemp == "" + cDirTemp += hb_ps() + ENDIF + IF ! cDirItem == "" /* Skip root path, if any */ + cDirTemp += cDirItem + IF hb_vfExists( cDirTemp ) + RETURN .F. + ELSEIF ! hb_vfDirExists( cDirTemp ) + IF hb_vfDirMake( cDirTemp ) != 0 + RETURN .F. + ENDIF + ENDIF + ENDIF + NEXT + ENDIF + + RETURN .T. + +FUNCTION hb_vfDirUnbuild( cDir ) + + LOCAL tmp + + IF ! HB_ISSTRING( cDir ) + RETURN .F. + ENDIF + + IF hb_vfDirExists( cDir ) + + cDir := hb_DirSepDel( cDir ) + + DO WHILE ! cDir == "" + IF hb_vfDirExists( cDir ) .AND. ; + hb_vfDirRemove( cDir ) != 0 + RETURN .F. + ENDIF + IF ( tmp := RAt( hb_ps(), cDir ) ) == 0 /* FIXME: use hb_URAt() function */ + EXIT + ENDIF + cDir := Left( cDir, tmp - 1 ) + IF ! hb_osDriveSeparator() == "" .AND. ; + Right( cDir, Len( hb_osDriveSeparator() ) ) == hb_osDriveSeparator() + EXIT + ENDIF + ENDDO + ENDIF + + RETURN .T. + +FUNCTION hb_vfNameExists( cName ) + RETURN ; + hb_vfExists( cName ) .OR. ; + hb_vfDirExists( cName )