From 48c7f008ce86cb42a4ba9b9c713717382fe4001f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 30 Oct 2009 16:19:18 +0000 Subject: [PATCH] 2009-10-30 17:08 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * INSTALL * Minor fix to UPX supported platforms. * contrib/hbmisc/Makefile + contrib/hbmisc/ffind.c + Added direct file find API from my own function collection: FILEFINDFIRST( , @[, ] ) -> FILEFINDNEXT( ) -> FILEFINDNAME( ) -> (without drive/dir) FILEFINDATTR( ) -> FILEFINDSIZE( ) -> FILEFINDDATE( ) -> FILEFINDTIME( ) -> (as "HH:MM:SS") It's an alternative to DIRECTORY()/FILE() functions. ; NOTE: To release the file find handle on some platforms (like Windows), and allow deletion of the dir we've been scanning, should go out of scope or be explicitly release by freeing variable. To make this easy, some may want to add: #xtranslate FILEFINDCLOSE( ) => \( := NIL \) #xtranslate FILEFINDCLOSE( @ ) => \( := NIL \) ; NOTE: Could be extended to return new timestamp format. * contrib/rddads/adsfunc.c + Added lAlive := AdsIsConnectionAlive( hConnection ) function. Borrowed from Augusto Infante / xhb. Three small fixes applied. --- harbour/ChangeLog | 29 +++++++ harbour/INSTALL | 2 +- harbour/contrib/hbmisc/Makefile | 1 + harbour/contrib/hbmisc/ffind.c | 143 +++++++++++++++++++++++++++++++ harbour/contrib/rddads/adsfunc.c | 9 ++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 harbour/contrib/hbmisc/ffind.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9ca3910232..7ea88039a8 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,35 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-10-30 17:08 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * INSTALL + * Minor fix to UPX supported platforms. + + * contrib/hbmisc/Makefile + + contrib/hbmisc/ffind.c + + Added direct file find API from my own function collection: + FILEFINDFIRST( , @[, ] ) -> + FILEFINDNEXT( ) -> + FILEFINDNAME( ) -> (without drive/dir) + FILEFINDATTR( ) -> + FILEFINDSIZE( ) -> + FILEFINDDATE( ) -> + FILEFINDTIME( ) -> (as "HH:MM:SS") + It's an alternative to DIRECTORY()/FILE() functions. + ; NOTE: To release the file find handle on some platforms + (like Windows), and allow deletion of the dir we've + been scanning, should go out of scope or + be explicitly release by freeing variable. + To make this easy, some may want to add: + #xtranslate FILEFINDCLOSE( ) => \( := NIL \) + #xtranslate FILEFINDCLOSE( @ ) => \( := NIL \) + ; NOTE: Could be extended to return new timestamp format. + + * contrib/rddads/adsfunc.c + + Added lAlive := AdsIsConnectionAlive( hConnection ) function. + Borrowed from Augusto Infante / xhb. + Three small fixes applied. + 2009-10-30 07:33 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/compiler/hbgenerr.c * Minor formatting. diff --git a/harbour/INSTALL b/harbour/INSTALL index 6f25b53a8f..1767ba7b0c 100644 --- a/harbour/INSTALL +++ b/harbour/INSTALL @@ -1255,7 +1255,7 @@ HARBOUR GNU Sed (stream editor) [multiplatform, free, open-source] Windows binary: http://gnuwin32.sourceforge.net/packages/sed.htm - UPX (executable compressor) [win, dos, linux, free, open-source] + UPX (executable compressor) [win, dos, *nix, free, open-source] http://upx.sourceforge.net/ Nullsoft Installer [win, free, open-source] http://nsis.sourceforge.net/ diff --git a/harbour/contrib/hbmisc/Makefile b/harbour/contrib/hbmisc/Makefile index 2f25280e73..884ba401e6 100644 --- a/harbour/contrib/hbmisc/Makefile +++ b/harbour/contrib/hbmisc/Makefile @@ -8,6 +8,7 @@ LIBNAME := hbmisc C_SOURCES := \ dates2.c \ + ffind.c \ hb_f.c \ spd.c \ strfmt.c \ diff --git a/harbour/contrib/hbmisc/ffind.c b/harbour/contrib/hbmisc/ffind.c new file mode 100644 index 0000000000..c305b7826f --- /dev/null +++ b/harbour/contrib/hbmisc/ffind.c @@ -0,0 +1,143 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * File find API + * + * Copyright 1991-2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.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 "hbapifs.h" + +static HB_GARBAGE_FUNC( PHB_FFIND_release ) +{ + void ** ph = ( void ** ) Cargo; + + /* Check if pointer is not NULL to avoid multiple freeing */ + if( ph && * ph ) + { + /* Destroy the object */ + hb_fsFindClose( ( PHB_FFIND ) * ph ); + + /* set pointer to NULL just in case */ + * ph = NULL; + } +} + +static const HB_GC_FUNCS s_gcPHB_FFIND_funcs = +{ + PHB_FFIND_release, + hb_gcDummyMark +}; + +static PHB_FFIND PHB_FFIND_par( int iParam ) +{ + void ** ph = ( void ** ) hb_parptrGC( &s_gcPHB_FFIND_funcs, iParam ); + + return ph ? ( PHB_FFIND ) * ph : NULL; +} + +HB_FUNC( FILEFINDFIRST ) +{ + const char * pszFileName = hb_parc( 1 ); + + if( pszFileName && HB_ISBYREF( 2 ) ) + { + void ** ph = ( void ** ) hb_gcAllocate( sizeof( PHB_FFIND ), &s_gcPHB_FFIND_funcs ); + + PHB_FFIND ffind = hb_fsFindFirst( pszFileName, HB_ISNUM( 3 ) ? hb_parnl( 3 ) : HB_FA_ALL ); + + * ph = ( void * ) ffind; + + hb_storptrGC( ph, 2 ); + + hb_retl( ffind != NULL ); + } + else + hb_retl( FALSE ); +} + +HB_FUNC( FILEFINDNEXT ) +{ + PHB_FFIND ffind = PHB_FFIND_par( 1 ); + + hb_retl( ffind && hb_fsFindNext( ffind ) ); +} + +HB_FUNC( FILEFINDNAME ) +{ + PHB_FFIND ffind = PHB_FFIND_par( 1 ); + + hb_retc( ffind ? ffind->szName : NULL ); +} + +HB_FUNC( FILEFINDATTR ) +{ + PHB_FFIND ffind = PHB_FFIND_par( 1 ); + + hb_retnl( ffind ? ffind->attr : 0 ); +} + +HB_FUNC( FILEFINDSIZE ) +{ + PHB_FFIND ffind = PHB_FFIND_par( 1 ); + + hb_retnint( ffind ? ffind->size : 0 ); +} + +HB_FUNC( FILEFINDDATE ) +{ + PHB_FFIND ffind = PHB_FFIND_par( 1 ); + + hb_retds( ffind ? ffind->szDate : NULL ); +} + +HB_FUNC( FILEFINDTIME ) +{ + PHB_FFIND ffind = PHB_FFIND_par( 1 ); + + hb_retc( ffind ? ffind->szTime : NULL ); +} diff --git a/harbour/contrib/rddads/adsfunc.c b/harbour/contrib/rddads/adsfunc.c index 05a0aadfa0..8315aa7380 100644 --- a/harbour/contrib/rddads/adsfunc.c +++ b/harbour/contrib/rddads/adsfunc.c @@ -1434,6 +1434,15 @@ HB_FUNC( ADSCONNECTION ) /* Get/Set func to switch between connec hb_ads_hConnect = HB_ADS_PARCONNECTION( 1 ); } +HB_FUNC( ADSISCONNECTIONALIVE ) /* Determine if passed or default connection is still valid */ +{ + UNSIGNED16 bConnectionIsAlive = 0; + + AdsIsConnectionAlive( HB_ADS_PARCONNECTION( 1 ), &bConnectionIsAlive ); + + hb_retl( bConnectionIsAlive != 0 ); +} + HB_FUNC( ADSGETHANDLETYPE ) /* DD, admin, table */ { UNSIGNED16 usType = AE_INVALID_HANDLE;