2001-12-18 01:03 UTC+0100 Viktor Szakats <viktor.szakats@syenar.hu>

This commit is contained in:
Viktor Szakats
2001-12-18 00:03:25 +00:00
parent 38c54411c4
commit 6a248ab0ac
7 changed files with 80 additions and 651 deletions

View File

@@ -8,6 +8,24 @@
2002-12-01 23:12 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
2001-12-18 01:03 UTC+0100 Viktor Szakats <viktor.szakats@syenar.hu>
* source/common/hbffind.c
* include/hbapifs.h
! Some fixes (MSVC, Win32, misc).
* source/rtl/Makefile
! Fixed indentation in Makefile.
* source/compiler/gencobj.c
! Fix provided by Jose Lalin
bDelTemp was initialized to TRUE by default and this was
causing that MAKE utilities rebuilds all the files in a
project since the intermediate C file was deleted.
* source/rtl/gt_tpl/gt_tpl.c
! Minor change.
2001-12-17 17:02 UTC+0100 Viktor Szakats <viktor.szakats@syenar.hu>
* source/rtl/tbrowse.prg

View File

@@ -178,14 +178,14 @@ typedef struct
} HB_FFIND, * PHB_FFIND;
/* File Find API functions */
extern PHB_FFIND hb_fsFindFirst( char * pszFileName, USHORT uiAttr );
extern PHB_FFIND hb_fsFindFirst( const char * pszFileName, USHORT uiAttr );
extern BOOL hb_fsFindNext( PHB_FFIND ffind );
extern void hb_fsFindClose( PHB_FFIND ffind );
/* Misc helper functions */
extern USHORT hb_fsAttrFromRaw( ULONG raw_attr );
extern ULONG hb_fsAttrToRaw( USHORT uiAttr );
extern USHORT hb_fsAttrEncode( char * szAttr );
extern USHORT hb_fsAttrEncode( const char * szAttr );
extern char * hb_fsAttrDecode( USHORT uiAttr, char * szAttr );
#if defined(HB_EXTERN_C)

View File

@@ -66,6 +66,8 @@
/* ------------------------------------------------------------- */
#include <ctype.h>
#if defined(HB_OS_DOS)
#if defined(__DJGPP__) || defined(__RSX32__)
@@ -241,9 +243,9 @@ ULONG hb_fsAttrToRaw( USHORT uiAttr )
/* Converts a CA-Cl*pper compatible file attribute string
to the internal reprensentation. */
USHORT hb_fsAttrEncode( char * szAttr )
USHORT hb_fsAttrEncode( const char * szAttr )
{
char * pos = szAttr;
const char * pos = szAttr;
char ch;
USHORT uiAttr = 0;
@@ -281,6 +283,8 @@ USHORT hb_fsAttrEncode( char * szAttr )
/* Converts a file attribute (ffind->attr) to the CA-Cl*pper
compatible file attribute string format. */
/* NOTE: szAttr buffer must be at least 16 chars long */
char * hb_fsAttrDecode( USHORT uiAttr, char * szAttr )
{
char * ptr = szAttr;
@@ -313,7 +317,7 @@ char * hb_fsAttrDecode( USHORT uiAttr, char * szAttr )
static void hb_fsFindFill( PHB_FFIND ffind )
{
PHB_FFIND_INFO info = ffind->info;
PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info;
USHORT nYear;
USHORT nMonth;
@@ -396,7 +400,8 @@ static void hb_fsFindFill( PHB_FFIND ffind )
{
strncpy( ffind->szName, info->pFindFileData.cFileName, _POSIX_PATH_MAX );
/* TOFIX: nFileSizeHigh is not yet used. */
/* TOFIX: Use the complete value, to get around the 4GB limit */
/* ffind->size = ( info->pFindFileData.nFileSizeHigh * MAXDWORD ) + info->pFindFileData.nFileSizeLow; */
ffind->size = info->pFindFileData.nFileSizeLow;
raw_attr = ( USHORT ) info->pFindFileData.dwFileAttributes;
@@ -483,7 +488,6 @@ static void hb_fsFindFill( PHB_FFIND ffind )
/* Do the conversions common for all platforms */
ffind->szName[ _POSIX_PATH_MAX ] = '\0';
ffind->szName[ 8 + 1 + 3 ] = '\0';
ffind->attr = hb_fsAttrFromRaw( raw_attr );
@@ -493,7 +497,7 @@ static void hb_fsFindFill( PHB_FFIND ffind )
sprintf( ffind->szTime, "%02d:%02d:%02d", nHour, nMin, nSec );
}
PHB_FFIND hb_fsFindFirst( char * pszFileName, USHORT uiAttr )
PHB_FFIND hb_fsFindFirst( const char * pszFileName, USHORT uiAttr )
{
PHB_FFIND ffind = ( PHB_FFIND ) hb_xgrab( sizeof( HB_FFIND ) );
BOOL bFound;
@@ -507,7 +511,7 @@ PHB_FFIND hb_fsFindFirst( char * pszFileName, USHORT uiAttr )
#if defined(HB_OS_DOS)
{
PHB_FFIND_INFO info = ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
bFound = ( findfirst( pszFileName, &info->entry, ( USHORT ) hb_fsAttrToRaw( uiAttr ) ) == 0 );
}
@@ -515,7 +519,7 @@ PHB_FFIND hb_fsFindFirst( char * pszFileName, USHORT uiAttr )
#elif defined(HB_OS_OS2)
{
PHB_FFIND_INFO info = ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
info->hFindFile = HDIR_CREATE;
@@ -531,7 +535,7 @@ PHB_FFIND hb_fsFindFirst( char * pszFileName, USHORT uiAttr )
#elif defined(HB_OS_WIN_32)
{
PHB_FFIND_INFO info = ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
info->hFindFile = FindFirstFile( pszFileName, &info->pFindFileData );
info->dwAttr = ( DWORD ) hb_fsAttrToRaw( uiAttr );
@@ -563,7 +567,7 @@ PHB_FFIND hb_fsFindFirst( char * pszFileName, USHORT uiAttr )
#elif defined(HB_OS_UNIX)
{
PHB_FFIND_INFO info = ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info = ( void * ) hb_xgrab( sizeof( HB_FFIND_INFO ) );
info->dir = opendir( pszFileName );
@@ -613,7 +617,7 @@ PHB_FFIND hb_fsFindFirst( char * pszFileName, USHORT uiAttr )
BOOL hb_fsFindNext( PHB_FFIND ffind )
{
PHB_FFIND_INFO info = ffind->info;
PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info;
BOOL bFound;
/* Do platform dependant search */
@@ -686,7 +690,7 @@ void hb_fsFindClose( PHB_FFIND ffind )
if( ffind->info != NULL )
{
PHB_FFIND_INFO info = ffind->info;
PHB_FFIND_INFO info = ( PHB_FFIND_INFO ) ffind->info;
#if defined(HB_OS_DOS)

View File

@@ -55,7 +55,7 @@ void hb_compGenCObj( PHB_FNAME pFileName )
char * pszCfg;
char * pszEnv;
BOOL bVerbose = FALSE; /* Don't show C compiler messages (default). */
BOOL bDelTmp = TRUE; /* Delete intermediate C file (default). */
BOOL bDelTmp = FALSE; /* Delete intermediate C file (default). */
int iSuccess;
/* First pass: build the C output */

View File

@@ -133,7 +133,7 @@ PRG_SOURCES=\
getlist.prg \
getsys.prg \
input.prg \
listbox.prg \
listbox.prg \
memoedit.prg \
memvarbl.prg \
menuto.prg \
@@ -146,7 +146,7 @@ PRG_SOURCES=\
radiogrp.prg \
readkey.prg \
readvar.prg \
scrollbr.prg \
scrollbr.prg \
setfunc.prg \
setta.prg \
tclass.prg \

View File

@@ -50,10 +50,6 @@
*
*/
/* TOFIX: Filename/path splitting and merging should be rewritten to use
hb_FName*() functions, instead of repeating the functionality
in the current partially buggy way. [vszakats] */
/*
* Notes from the fringe... <ptucker@sympatico.ca>
*
@@ -93,664 +89,75 @@
* TODO: - Volume label support
* - check that path support vis stat works on all platforms
* - UNC Support? ie: dir \\myserver\root
* - Use hb_fsFNameSplit()/Merge() for filename composing/decomposing.
*
*/
/* NOTE: For OS/2. Must be ahead of any and all #include statements */
#define INCL_DOSFILEMGR
#define INCL_DOSERRORS
#define HB_OS_WIN_32_USED
#include <ctype.h>
#include "hbapi.h"
#include "hbapifs.h"
#include "hbapiitm.h"
#include "hb_io.h"
#include "directry.ch"
#if defined(__GNUC__) && !defined(__MINGW32__)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <time.h>
#if !defined(HAVE_POSIX_IO)
#define HAVE_POSIX_IO
#endif
#if defined( HB_OS_UNIX )
#define HB_DIR_ALL_FILES_MASK "*"
#else
#define HB_DIR_ALL_FILES_MASK "*.*"
#endif
#if defined(__WATCOMC__) || defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >= 1000 )
#include <sys/stat.h>
#include <share.h>
#include <fcntl.h>
#include <errno.h>
#include <direct.h>
#include <time.h>
#if !defined(HAVE_POSIX_IO)
#define HAVE_POSIX_IO
#endif
#elif defined(_MSC_VER)
#include <sys/stat.h>
#include <share.h>
#include <fcntl.h>
#include <errno.h>
#include <direct.h>
#include <time.h>
#include <dos.h>
#if !defined(HAVE_POSIX_IO)
#define HAVE_POSIX_IO
#endif
#endif
#if defined(HB_OS_OS2)
#include <sys/stat.h>
#include <time.h>
#if !defined(HAVE_POSIX_IO)
#define HAVE_POSIX_IO
#endif
#endif
#if defined(__BORLANDC__)
#include <sys\stat.h>
#include <fcntl.h>
#include <share.h>
#include <dirent.h>
#include <dir.h>
#include <dos.h>
#include <time.h>
#include <errno.h>
#if !defined(HAVE_POSIX_IO)
#define HAVE_POSIX_IO
#ifndef S_IEXEC
#define S_IEXEC 0x0040 /* owner may execute <directory search> */
#endif
#ifndef S_IRWXU
#define S_IRWXU 0x01c0 /* RWE permissions mask for owner */
#endif
#ifndef S_IRUSR
#define S_IRUSR 0x0100 /* owner may read */
#endif
#ifndef S_IWUSR
#define S_IWUSR 0x0080 /* owner may write */
#endif
#ifndef S_IXUSR
#define S_IXUSR 0x0040 /* owner may execute <directory search> */
#endif
#endif
#endif
#if !defined(FA_RDONLY)
#define FA_RDONLY 1 /* R */
#define FA_HIDDEN 2 /* H */
#define FA_SYSTEM 4 /* S */
#define FA_LABEL 8 /* V */
#define FA_DIREC 16 /* D */
#define FA_ARCH 32 /* A */
#endif
/* these work under NT but are otherwise used as placeholders for
non MS o/s support */
#if !defined(FA_DEVICE)
#define FA_DEVICE 64 /* I */
/* #define FA_NORMAL 128 */ /* N */ /* ignored */ /* Exists in BORLANDC */
#define FA_TEMPORARY 256 /* T */
#define FA_SPARSE 512 /* P */
#define FA_REPARSE 1024 /* L */
#define FA_COMPRESSED 2048 /* C */
#define FA_OFFLINE 4096 /* O */
#define FA_NOTINDEXED 8192 /* X */
#define FA_ENCRYPTED 16384 /* E */
#define FA_VOLCOMP 32768 /* M */
#endif
/* Conversion functions *** commented out functions not finished-not needed */
static USHORT osToHarbourMask( USHORT usMask )
{
USHORT usRetMask;
HB_TRACE(HB_TR_DEBUG, ("osToHarbourMask(%hu)", usMask));
usRetMask = usMask;
/* probably access denied when requesting mode */
if( usMask == (USHORT) -1 )
return 0;
#if defined(OS_UNIX_COMPATIBLE)
/* The use of any particular FA_ define here is meaningless */
/* they are essentially placeholders */
usRetMask = 0;
if( S_ISREG( usMask ) )
usRetMask |= FA_ARCH; /* A */
if( S_ISDIR( usMask ) )
usRetMask |= FA_DIREC; /* D */
if( S_ISLNK( usMask ) )
usRetMask |= FA_REPARSE; /* L */
if( S_ISCHR( usMask ) )
usRetMask |= FA_COMPRESSED; /* C */
if( S_ISBLK( usMask ) )
usRetMask |= FA_DEVICE; /* B (I) */
if( S_ISFIFO( usMask ) )
usRetMask |= FA_TEMPORARY; /* F (T) */
if( S_ISSOCK( usMask ) )
usRetMask |= FA_SPARSE; /* K (P) */
#elif defined(HB_OS_OS2)
usRetMask = 0;
if( usMask & FILE_ARCHIVED )
usRetMask |= FA_ARCH;
if( usMask & FILE_DIRECTORY )
usRetMask |= FA_DIREC;
if( usMask & FILE_HIDDEN )
usRetMask |= FA_HIDDEN;
if( usMask & FILE_READONLY )
usRetMask |= FA_RDONLY;
if( usMask & FILE_SYSTEM )
usRetMask |= FA_SYSTEM;
#endif
return usRetMask;
}
static USHORT HarbourAttributesToMask( BYTE * byAttrib )
{
BYTE * pos = byAttrib;
BYTE c;
USHORT usMask = 0;
HB_TRACE(HB_TR_DEBUG, ("HarbourAttributesToMask(%p)", byAttrib));
while( ( c = toupper( *pos ) ) != '\0' )
{
switch( c )
{
case 'A': usMask |= FA_ARCH; break;
case 'D': usMask |= FA_DIREC; break;
case 'H': usMask |= FA_HIDDEN; break;
case 'R': usMask |= FA_RDONLY; break;
case 'S': usMask |= FA_SYSTEM; break;
case 'V': usMask |= FA_LABEL; break;
/* extensions */
/* case 'N': usMask |= FA_NORMAL; break; */
case 'O': usMask |= FA_OFFLINE; break;
case 'T': usMask |= FA_TEMPORARY; break;
case 'I': usMask |= FA_DEVICE; break;
case 'M': usMask |= FA_VOLCOMP; break;
case 'E': usMask |= FA_ENCRYPTED; break;
case 'X': usMask |= FA_NOTINDEXED; break;
case 'C': usMask |= FA_COMPRESSED; break;
case 'L': usMask |= FA_REPARSE; break;
case 'P': usMask |= FA_SPARSE; break;
}
pos++;
}
return usMask;
}
static BYTE * HarbourMaskToAttributes( USHORT usMask, BYTE * byAttrib )
{
char * cAttrib = ( char * ) byAttrib;
HB_TRACE(HB_TR_DEBUG, ("HarbourMaskToAttributes(%hu, %p)", usMask, byAttrib));
*cAttrib = '\0';
if( usMask & FA_RDONLY )
strcat( cAttrib, "R" );
if( usMask & FA_HIDDEN )
strcat( cAttrib, "H" );
if( usMask & FA_SYSTEM )
strcat( cAttrib, "S" );
if( usMask & FA_DIREC )
strcat( cAttrib, "D" );
if( usMask & FA_ARCH )
strcat( cAttrib, "A" );
if( usMask & FA_LABEL )
{
strcat( cAttrib, "V" );
if( usMask & FA_VOLCOMP )
strcat( cAttrib, "M" ); /* volume supports compression. */
}
/* thse can be returned under NT with NTFS - I picked the letters to use.*/
/* needs testing on a Novell drive */
/* PLEASE! If these cause you trouble let me know! <ptucker@sympatico.ca> */
if( usMask & FA_DEVICE )
strcat( cAttrib, "I" );
/* if( usMask & FA_NORMAL ) */
/* strcat( cAttrib, "N" ); */
if( usMask & FA_TEMPORARY )
strcat( cAttrib, "T" );
if( usMask & FA_SPARSE )
strcat( cAttrib, "P" );
if( usMask & FA_REPARSE )
strcat( cAttrib, "L" );
if( usMask & FA_COMPRESSED )
strcat( cAttrib, "C" );
if( usMask & FA_OFFLINE )
strcat( cAttrib, "O" );
if( usMask & FA_NOTINDEXED )
strcat( cAttrib, "X" );
if( usMask & FA_ENCRYPTED )
strcat( cAttrib, "E" );
return byAttrib;
}
/* NOTE: The third (lEightDotThree) parameter is a Harbour extension. */
HB_FUNC( DIRECTORY )
{
#if defined(HAVE_POSIX_IO)
PHB_ITEM pDirSpec = hb_param( 1, HB_IT_STRING );
PHB_ITEM pAttributes = hb_param( 2, HB_IT_STRING );
PHB_ITEM pDirSpec = hb_param( 1, HB_IT_STRING );
PHB_ITEM pAttributes = hb_param( 2, HB_IT_STRING );
USHORT uiMask;
#if defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >= 1000 )
PHB_ITEM pEightDotThree = hb_param( 3, HB_IT_LOGICAL );
BOOL bEightDotThree;
#elif defined(__WATCOMC__)
int iDirnameLen;
#endif
PHB_ITEM pDir = hb_itemArrayNew( 0 );
char fullfile[ _POSIX_PATH_MAX + 1 ];
char filename[ _POSIX_PATH_MAX + 1 ];
char pattern[ _POSIX_PATH_MAX + 1 ];
char dirname[ _POSIX_PATH_MAX + 1 ];
char string[ _POSIX_PATH_MAX + 1 ];
char pfname[ _POSIX_PATH_MAX + 1 ];
char pfext[ _POSIX_PATH_MAX + 1 ];
char fname[ _POSIX_PATH_MAX + 1 ];
char fext[ _POSIX_PATH_MAX + 1 ];
char ddate[ 9 ];
char ttime[ 9 ];
char aatrib[ 17 ];
int attrib;
long fsize = 0;
time_t ftime;
char * pos;
USHORT ushbMask = FA_ARCH;
PHB_ITEM pDir;
struct stat statbuf;
struct tm * ft;
#if defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >= 1000 )
struct _finddata_t entry;
long hFile;
#elif defined(_MSC_VER)
struct _find_t entry;
long hFile;
#elif defined(HB_OS_OS2)
FILEFINDBUF3 entry;
HDIR hFind = HDIR_CREATE;
ULONG fileTypes = FILE_ARCHIVED | FILE_DIRECTORY | FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY;
ULONG findSize = sizeof( entry );
ULONG findCount = 1;
#elif defined (__BORLANDC__)
struct ffblk entry;
#else
struct dirent * entry;
DIR * dir;
#endif
dirname[ 0 ] = '\0';
pattern[ 0 ] = '\0';
PHB_FFIND ffind;
/* Get the passed attributes and convert them to Harbour Flags */
if( pAttributes && hb_itemGetCLen( pAttributes ) >= 1 )
ushbMask |= HarbourAttributesToMask( ( BYTE * ) hb_itemGetCPtr( pAttributes ) );
#if defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >= 1000 )
/* Do we want 8.3 support? */
bEightDotThree = ( pEightDotThree ? hb_itemGetL( pEightDotThree ) : FALSE );
#endif
uiMask = HB_FA_ARCHIVE;
if( pAttributes && hb_itemGetCLen( pAttributes ) > 0 )
uiMask |= hb_fsAttrEncode( hb_itemGetCPtr( pAttributes ) );
pattern[ 0 ] = '\0';
/* Get the file list */
/* TODO: add supporting code */
/* if you request the volume label, that's all you get */
if( ushbMask & FA_LABEL )
if( ( ffind = hb_fsFindFirst( pDirSpec ? hb_itemGetCPtr( pDirSpec ) : HB_DIR_ALL_FILES_MASK, uiMask ) ) != NULL )
{
/* get rid of anything else */
ushbMask = FA_LABEL;
PHB_ITEM pFilename = hb_itemNew( NULL );
PHB_ITEM pSize = hb_itemNew( NULL );
PHB_ITEM pDate = hb_itemNew( NULL );
PHB_ITEM pTime = hb_itemNew( NULL );
PHB_ITEM pAttr = hb_itemNew( NULL );
if( pDirSpec )
{
strcpy( string, hb_itemGetCPtr( pDirSpec ) );
pos = strrchr( string, ':' );
if( pos )
*( ++pos ) = '\0';
else
string[ 0 ] = '\0';
strcpy( pattern, string );
}
}
else
{
if( pDirSpec )
{
strcpy( string, hb_itemGetCPtr( pDirSpec ) );
pos = strrchr( string, OS_PATH_DELIMITER );
if( pos )
{
strcpy( pattern, pos + 1 );
*( pos + 1 ) = '\0';
strcpy( dirname, string );
}
else
{
strcpy( pattern, string );
strcpy( dirname, ".X" );
dirname[ 1 ] = OS_PATH_DELIMITER;
}
}
if( !*pattern )
strcpy( pattern, "*.*" );
}
#if defined(__WATCOMC__)
iDirnameLen = strlen( dirname );
if( iDirnameLen < 1 )
{
strcpy( dirname, ".X" );
dirname[ 1 ] = OS_PATH_DELIMITER;
iDirnameLen = 2;
}
#endif
if( strlen( pattern ) > 0 )
{
strcpy( string, pattern );
pos = strrchr( string, '.' );
if( pos )
{
strcpy( pfext, pos + 1 );
*pos = '\0';
strcpy( pfname, string );
}
else
{
strcpy( pfname, string );
pfext[ 0 ] = '\0';
}
}
if( strlen( pfname ) < 1 )
strcpy( pfname, "*" );
HB_TRACE(HB_TR_INFO, ("dirname: |%s|, pattern: |%s|\n", dirname, pattern));
HB_TRACE(HB_TR_INFO, ("pfname: |%s|, pfext: |%s|\n", pfname, pfext));
/* should have drive, directory in dirname and filespec in pattern */
tzset();
pDir = hb_itemArrayNew( 0 );
#if defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >=1000 )
strcpy( string, dirname );
strcat( string, pattern );
if( ( hFile = _findfirst( string, &entry ) ) != -1L )
{
do
{
strcpy( string, dirname );
strcat( string, entry.name );
PHB_ITEM pSubarray = hb_itemArrayNew( F_LEN );
char buffer[ 32 ];
/* this needs the full path to the file */
if( bEightDotThree )
GetShortPathName( string, string, _POSIX_PATH_MAX );
hb_arraySet( pSubarray, F_NAME, hb_itemPutC( pFilename, ffind->szName ) );
hb_arraySet( pSubarray, F_SIZE, hb_itemPutNL( pSize, ffind->size ) );
hb_arraySet( pSubarray, F_DATE, hb_itemPutDS( pDate, ffind->szDate ) );
hb_arraySet( pSubarray, F_TIME, hb_itemPutC( pTime, ffind->szTime ) );
hb_arraySet( pSubarray, F_ATTR, hb_itemPutC( pAttr, hb_fsAttrDecode( ffind->attr, buffer ) ) );
#elif defined(_MSC_VER)
/* Don't exit when array limit is reached */
hb_arrayAdd( pDir, pSubarray );
strcpy( string, dirname );
strcat( string, pattern );
hb_itemRelease( pSubarray );
}
while( hb_fsFindNext( ffind ) );
if( _dos_findfirst( string, ushbMask, &entry ) == 0 )
{
do
{
strcpy( string, entry.name );
#elif defined(HB_OS_OS2)
hb_itemRelease( pFilename );
hb_itemRelease( pSize );
hb_itemRelease( pDate );
hb_itemRelease( pTime );
hb_itemRelease( pAttr );
strcpy( string, dirname );
strcat( string, pattern );
if( DosFindFirst( string, &hFind, fileTypes, &entry, findSize, &findCount, FIL_STANDARD ) == NO_ERROR && findCount > 0 )
{
do
{
strcpy( string, entry.achName );
#elif defined(__BORLANDC__)
strcpy( string, dirname );
strcat( string, pattern );
if( findfirst( string, &entry, ushbMask ) == 0 )
{
do
{
strcpy( string, entry.ff_name );
#else
#if defined(__WATCOMC__)
/* opendir in Watcom doesn't like the path delimiter at the end of a string */
dirname[ iDirnameLen ] = '.';
dirname[ iDirnameLen + 1 ] = '\0';
#endif
dir = opendir( dirname );
#if defined(__WATCOMC__)
dirname[ iDirnameLen ] = '\0';
#endif
if( NULL == dir )
{
HB_TRACE(HB_TR_INFO, ("invalid dirname |%s|\n", dirname));
hb_itemRelease( hb_itemReturn( pDir ) );
return;
hb_fsFindClose( ffind );
}
/* now put everything into an array */
while( ( entry = readdir( dir ) ) != NULL )
{
strcpy( string, entry->d_name );
#endif
pos = strrchr( string, OS_PATH_DELIMITER );
pos = strrchr( pos ? ( pos + 1 ) : string, '.' );
if( pos && ! ( pos == &string[ 0 ] ) )
{
strcpy( fext, pos + 1 );
*pos = '\0';
}
else
fext[ 0 ] = '\0';
pos = strrchr( string, OS_PATH_DELIMITER );
strcpy( fname, pos ? ( pos + 1 ) : string );
if( !*fname )
strcpy( fname, "*" );
HB_TRACE(HB_TR_INFO, ("fname: |%s|, fext: |%s|\n", fname, fext));
if( hb_strMatchRegExp( fname, pfname ) && hb_strMatchRegExp( fext, pfext ) )
{
attrib = 0;
#if defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >= 1000 )
/* due to short-name support: reconstruct the filename */
if( bEightDotThree )
{
pos = strrchr( string, OS_PATH_DELIMITER );
if( pos )
{
++pos;
if( ! *pos || ( *pos == '.' && ! pos[ 1 ] ) )
strcat( string, "." );
}
strcpy( filename, string ); /* entry.name ); */
if( *fext )
{
strcat( filename, "." );
strcat( filename, fext );
}
*fullfile = '\0';
}
else
{
strcpy( fullfile, dirname );
strcpy( filename, entry.name );
}
#elif defined(_MSC_VER)
strcpy( filename, entry.name );
strcpy( fullfile, dirname );
#elif defined(HB_OS_OS2)
strcpy( filename, entry.achName );
strcpy( fullfile, dirname );
#elif defined (__BORLANDC__)
strcpy( filename, entry.ff_name );
strcpy( fullfile, dirname );
#else
strcpy( filename, entry->d_name );
strcpy( fullfile, dirname );
#endif
strcat( fullfile, filename );
if( stat( fullfile, &statbuf ) != -1 )
{
#if defined(__BORLANDC__)
fsize = entry.ff_fsize;
#else
fsize = statbuf.st_size;
ftime = statbuf.st_mtime;
#endif
#if defined(OS_UNIX_COMPATIBLE)
/* GNU C on Linux or on other UNIX */
attrib = statbuf.st_mode;
#elif defined(HB_OS_OS2)
attrib = entry.attrFile;
#elif defined(__MINGW32__) || defined(_MSC_VER)
attrib = entry.attrib;
#if defined(__MINGW32__) || ( defined(_MSC_VER) && _MSC_VER >= 1000 )
if( bEightDotThree )
{
/* need to strip off the path */
pos = strrchr( filename, OS_PATH_DELIMITER );
if( pos )
strcpy( filename, ++pos );
}
#endif
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 1280)
/* NOTE: _chmod( f, 0 ) => Get attribs
_chmod( f, 1, n ) => Set attribs
chmod() though, _will_ change the attributes */
attrib = ( USHORT ) entry.ff_attrib;
#elif defined(__BORLANDC__)
attrib = ( USHORT ) entry.ff_attrib;
#elif defined(__DJGPP__)
attrib = ( USHORT ) _chmod( fullfile, 0 );
#else
attrib = 0;
#endif
attrib = osToHarbourMask( attrib );
if( attrib & FA_DIREC )
{
/* MS says size for a Directory is undefined.
Novell uses these bits for other purposes
*/
fsize = 0;
}
#if defined(__BORLANDC__)
sprintf(ddate , "%04d%02d%02d",(long) (entry.ff_fdate >> 9) +1980 ,(long) ((entry.ff_fdate & ~0xFE00) >> 5) ,(long)entry.ff_fdate & ~0xFFE0);
sprintf(ttime,"%2.2u:%2.2u",(entry.ff_ftime >> 11) & 0x1f,(entry.ff_ftime>> 5) & 0x3f);
#else
ft = localtime( &ftime );
sprintf( ddate, "%04d%02d%02d",
ft->tm_year + 1900, ft->tm_mon + 1, ft->tm_mday );
sprintf( ttime, "%02d:%02d:%02d",
ft->tm_hour, ft->tm_min, ft->tm_sec );
#endif
HB_TRACE(HB_TR_INFO, ("name: |%s|, date: |%s|, time: |%s|\n", filename, ddate, ttime));
}
else
HB_TRACE(HB_TR_INFO, ("invalid file |%s|\n", fullfile));
if( !( ( ( ushbMask & FA_HIDDEN ) == 0 && ( attrib & FA_HIDDEN ) > 0 ) ||
( ( ushbMask & FA_SYSTEM ) == 0 && ( attrib & FA_SYSTEM ) > 0 ) ||
( ( ushbMask & FA_DIREC ) == 0 && ( attrib & FA_DIREC ) > 0 ) ) )
{
PHB_ITEM pSubarray = hb_itemArrayNew( F_LEN );
PHB_ITEM pFilename = hb_itemPutC( NULL, filename );
PHB_ITEM pSize = hb_itemPutNL( NULL, fsize );
PHB_ITEM pDate = hb_itemPutDS( NULL, ddate );
PHB_ITEM pTime = hb_itemPutC( NULL, ttime );
PHB_ITEM pAttr = hb_itemPutC( NULL, ( char * ) HarbourMaskToAttributes( attrib, ( BYTE * ) aatrib ) );
hb_itemArrayPut( pSubarray, F_NAME, pFilename );
hb_itemArrayPut( pSubarray, F_SIZE, pSize );
hb_itemArrayPut( pSubarray, F_DATE, pDate );
hb_itemArrayPut( pSubarray, F_TIME, pTime );
hb_itemArrayPut( pSubarray, F_ATTR, pAttr );
/* NOTE: Simply ignores the situation where the array length
limit is reached. */
hb_arrayAdd( pDir, pSubarray );
hb_itemRelease( pFilename );
hb_itemRelease( pSize );
hb_itemRelease( pDate );
hb_itemRelease( pTime );
hb_itemRelease( pAttr );
hb_itemRelease( pSubarray );
}
}
}
#if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER >= 1000 )
while( _findnext( hFile, &entry ) == 0 );
_findclose( hFile );
#elif defined(_MSC_VER )
while( _dos_findnext( &entry ) == 0 );
#elif defined(HB_OS_OS2)
while( DosFindNext( hFind, &entry, findSize, &findCount ) == NO_ERROR && findCount > 0 );
DosFindClose( hFind );
#elif defined(__BORLANDC__)
while( findnext( &entry ) == 0 );
findclose( &entry );
#else
closedir( dir );
#endif
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(HB_OS_OS2) || defined(__BORLANDC__)
}
#endif
HB_TRACE(HB_TR_INFO, ("normal return\n"));
hb_itemRelease( hb_itemReturn( pDir ) ); /* DIRECTORY() returns an array */
#endif /* HAVE_POSIX_IO */
hb_itemRelease( hb_itemReturn( pDir ) );
}

View File

@@ -4,7 +4,7 @@
/*
* Harbour Project source code:
* Video subsystem template
* {Video subsystem template}
*
* Copyright 1999 {list of individual authors and e-mail addresses}
* www - http://www.harbour-project.org