Implement SET FILECASE, DIRCASE and DIRSEPARATOR

This commit is contained in:
Gustavo Junior Alves
2002-09-24 01:10:15 +00:00
parent 3f4ea4c459
commit 5c91af924a
7 changed files with 91 additions and 3 deletions

View File

@@ -276,6 +276,7 @@ typedef USHORT ERRCODE;
extern HB_SYMB hb_symEval;
/* Extend API */
extern char HB_EXPORT * hb_filecase ( char * ); /* Convert string to environment case */
extern char HB_EXPORT * hb_parc( int iParam, ... ); /* retrieve a string parameter */
extern ULONG HB_EXPORT hb_parclen( int iParam, ... ); /* retrieve a string parameter length */
extern ULONG HB_EXPORT hb_parcsiz( int iParam, ... ); /* retrieve a by-reference string parameter length, including terminator */

View File

@@ -124,7 +124,10 @@ typedef enum
/* Harbour SET extensions start at 100 */
HB_SET_LANGUAGE = 100,
HB_SET_IDLEREPEAT = 101
HB_SET_IDLEREPEAT = 101,
HB_SET_FILECASE = 102,
HB_SET_DIRCASE = 103,
HB_SET_DIRSEPARATOR = 104
} HB_set_enum;
@@ -182,6 +185,9 @@ typedef struct
BOOL HB_SET_STRICTREAD;
int HB_SET_TYPEAHEAD;
BOOL HB_SET_UNIQUE;
char * HB_SET_FILECASE;
char * HB_SET_DIRCASE;
char * HB_SET_DIRSEPARATOR;
int HB_SET_VIDEOMODE;
BOOL HB_SET_WRAP;
} HB_SET_STRUCT;

View File

@@ -116,6 +116,9 @@
#define _SET_LANGUAGE 100 /* Harbour extension */
#define _SET_IDLEREPEAT 101 /* Harbour extension */
#define _SET_FILECASE 102 /* Harbour extension */
#define _SET_DIRCASE 103 /* Harbour extension */
#define _SET_DIRSEPARATOR 104 /* Harbour extension */
#define HB_SET_BASE 100
#define HB_SET_COUNT 2

View File

@@ -121,6 +121,9 @@ void hb_pp_Table( void )
static DEFINES sD___50 = {"_SET_AUTOSHARE",NULL,-1,"47", &sD___49 };
static DEFINES sD___51 = {"_SET_LANGUAGE",NULL,-1,"100", &sD___50 };
static DEFINES sD___52 = {"_SET_IDLEREPEAT",NULL,-1,"101", &sD___51 };
static DEFINES sD___53 = {"_SET_FILECASE",NULL,-1,"102", &sD___52 };
static DEFINES sD___54 = {"_SET_DIRCASE",NULL,-1,"103", &sD___53 };
static DEFINES sD___55 = {"_SET_DIRSEPARATOR",NULL,-1,"104", &sD___54 };
static COMMANDS sC___1 = {0,"NOTE","\1A30",NULL,NULL };
static COMMANDS sC___2 = {0,"DO","WHILE \1A00","while \1A00",&sC___1 };
@@ -423,8 +426,14 @@ void hb_pp_Table( void )
static COMMANDS sC___242 = {0,"SET","OPTIMIZE (\1A00)","Set( _SET_OPTIMIZE, \1A00 )",&sC___241 };
static COMMANDS sC___243 = {0,"SET","AUTOPEN \1A20 ON,OFF,&>","Set(_SET_AUTOPEN,\1A30 )",&sC___242 };
static COMMANDS sC___244 = {0,"SET","AUTOPEN (\1A00)","Set(_SET_AUTOPEN,\1A00 )",&sC___243 };
static COMMANDS sC___245 = {0,"SET","FILECASE \1A30","Set(_SET_FILECASE, \1A10 )",&sC___244 };
static COMMANDS sC___246 = {0,"SET","FILECASE ( \1A00 )","Set(_SET_FILECASE, \1A00 )",&sC___245 };
static COMMANDS sC___247 = {0,"SET","DIRCASE \1A30","Set(_SET_DIRCASE, \1A10 )",&sC___246 };
static COMMANDS sC___248 = {0,"SET","DIRCASE ( \1A00 )","Set(_SET_DIRCASE, \1A00 )",&sC___247 };
static COMMANDS sC___249 = {0,"SET","DIRSEPARATOR \1A30","Set(_SET_DIRSEPARATOR, \1A10 )",&sC___248 };
static COMMANDS sC___250 = {0,"SET","DIRSEPARATOR ( \1A00 )","Set(_SET_DIRSEPARATOR, \1A00 )",&sC___249 };
hb_pp_topDefine = &sD___52;
hb_pp_topCommand = &sC___244;
hb_pp_topDefine = &sD___55;
hb_pp_topCommand = &sC___250;
hb_pp_topTranslate = NULL;
}

View File

@@ -58,13 +58,17 @@ BOOL hb_fsFile( BYTE * pFilename )
PHB_FFIND ffind;
HB_TRACE(HB_TR_DEBUG, ("hb_fsFile(%s)", (char*) pFilename));
pFilename = hb_filecase(strdup(pFilename));
if( ( ffind = hb_fsFindFirst( ( char * ) pFilename, HB_FA_ALL ) ) != NULL )
{
hb_fsFindClose( ffind );
free(pFilename);
return TRUE;
}
else
free(pFilename);
return FALSE;
}

View File

@@ -96,6 +96,7 @@
#include "hbapi.h"
#include "hbapifs.h"
#include "hbset.h"
#include "hb_io.h"
#if defined(OS_UNIX_COMPATIBLE)
@@ -389,6 +390,38 @@ static void convert_create_flags_ex( USHORT uiAttr, USHORT uiFlags, int * result
#endif
char *hb_filecase(char *str) {
// Convert file and dir case. The allowed SET options are:
// LOWER - Convert all caracters of file to lower
// UPPER - Convert all caracters of file to upper
// MIXED - Leave as is
// The allowed environment options are:
// FILECASE - define the case of file
// DIRCASE - define the case of path
// DIRSEPARATOR - define separator of path (Ex. "/")
int a;
char *filename;
char *dirname=str;
int dirlen;
// Look for filename (Last "\" or DIRSEPARATOR)
if( hb_set.HB_SET_DIRSEPARATOR[0]!='\\') {
for(a=0;a<strlen(str);a++) if(str[a]=='\\') str[a]=hb_set.HB_SET_DIRSEPARATOR[0];
}
if((filename=rindex( str, hb_set.HB_SET_DIRSEPARATOR[0] ))!=NULL) filename++; else filename=str;
dirlen=filename-str;
// FILECASE
if( hb_stricmp( hb_set.HB_SET_FILECASE, "LOWER" ) == 0 ) hb_strLower(filename,strlen(filename));
else if( hb_stricmp( hb_set.HB_SET_FILECASE, "UPPER" ) == 0 ) hb_strUpper(filename,strlen(filename));
// DIRCASE
if( hb_stricmp( hb_set.HB_SET_DIRCASE, "LOWER" ) == 0 ) hb_strLower(dirname,dirlen);
else if( hb_stricmp( hb_set.HB_SET_DIRCASE, "UPPER" ) == 0 ) hb_strUpper(dirname,dirlen);
return str;
}
/*
* FILESYS.API FUNCTIONS --
@@ -459,6 +492,8 @@ FHANDLE hb_fsOpen( BYTE * pFilename, USHORT uiFlags )
HB_TRACE(HB_TR_DEBUG, ("hb_fsOpen(%p, %hu)", pFilename, uiFlags));
pFilename=hb_filecase(strdup(pFilename));
#if defined(X__WIN32__)
{
@@ -551,6 +586,7 @@ FHANDLE hb_fsOpen( BYTE * pFilename, USHORT uiFlags )
#endif
free( pFilename );
return hFileHandle;
}
@@ -562,6 +598,7 @@ FHANDLE hb_fsCreate( BYTE * pFilename, USHORT uiAttr )
HB_TRACE(HB_TR_DEBUG, ("hb_fsCreate(%p, %hu)", pFilename, uiAttr));
pFilename=hb_filecase(strdup(pFilename));
s_uiErrorLast = 0;
#if defined(X__WIN32__)
@@ -610,6 +647,7 @@ FHANDLE hb_fsCreate( BYTE * pFilename, USHORT uiAttr )
#endif
free( pFilename );
return hFileHandle;
}
@@ -627,6 +665,8 @@ FHANDLE hb_fsCreateEx( BYTE * pFilename, USHORT uiAttr, USHORT uiFlags )
HB_TRACE(HB_TR_DEBUG, ("hb_fsCreateEx(%p, %hu, %hu)", pFilename, uiAttr, uiFlags));
pFilename=hb_filecase(strdup(pFilename));
s_uiErrorLast = 0;
#if defined(HB_FS_FILE_IO)
@@ -649,6 +689,7 @@ FHANDLE hb_fsCreateEx( BYTE * pFilename, USHORT uiAttr, USHORT uiFlags )
#endif
free( pFilename );
return hFileHandle;
}

View File

@@ -763,6 +763,21 @@ HB_FUNC( SET )
hb_retl( hb_set.HB_SET_IDLEREPEAT );
if( args > 1 ) hb_set.HB_SET_IDLEREPEAT = set_logical( pArg2 );
break;
case HB_SET_FILECASE :
if( hb_set.HB_SET_FILECASE ) hb_retc( hb_set.HB_SET_FILECASE );
else hb_retc( NULL );
if( args > 1 ) hb_set.HB_SET_FILECASE = set_string( pArg2, hb_set.HB_SET_FILECASE );
break;
case HB_SET_DIRCASE :
if( hb_set.HB_SET_DIRCASE ) hb_retc( hb_set.HB_SET_DIRCASE );
else hb_retc( NULL );
if( args > 1 ) hb_set.HB_SET_DIRCASE = set_string( pArg2, hb_set.HB_SET_DIRCASE );
break;
case HB_SET_DIRSEPARATOR :
if( hb_set.HB_SET_DIRSEPARATOR ) hb_retc( hb_set.HB_SET_DIRSEPARATOR );
else hb_retc( NULL );
if( args > 1 ) hb_set.HB_SET_DIRSEPARATOR = set_string( pArg2, hb_set.HB_SET_DIRSEPARATOR );
break;
default :
/* Return NIL if called with invalid SET specifier */
break;
@@ -843,6 +858,12 @@ void hb_setInitialize( void )
hb_set.HB_SET_STRICTREAD = FALSE;
hb_set.HB_SET_TYPEAHEAD = 50; hb_inkeyReset( TRUE ); /* Allocate keyboard typeahead buffer */
hb_set.HB_SET_UNIQUE = FALSE;
hb_set.HB_SET_FILECASE = ( char * ) hb_xgrab( 6 );
memcpy( hb_set.HB_SET_FILECASE, "MIXED", 6 );
hb_set.HB_SET_DIRCASE = ( char * ) hb_xgrab( 6 );
memcpy( hb_set.HB_SET_DIRCASE, "MIXED", 6 );
hb_set.HB_SET_DIRSEPARATOR = ( char * ) hb_xgrab( 2 );
memcpy( hb_set.HB_SET_DIRSEPARATOR, "\\", 2 );
hb_set.HB_SET_VIDEOMODE = 0;
hb_set.HB_SET_WRAP = FALSE;
@@ -880,6 +901,9 @@ void hb_setRelease( void )
if( hb_set.HB_SET_MFILEEXT ) hb_xfree( hb_set.HB_SET_MFILEEXT );
if( hb_set.HB_SET_PATH ) hb_xfree( hb_set.HB_SET_PATH );
if( hb_set.HB_SET_PRINTFILE ) hb_xfree( hb_set.HB_SET_PRINTFILE );
if( hb_set.HB_SET_FILECASE ) hb_xfree( hb_set.HB_SET_FILECASE );
if( hb_set.HB_SET_DIRCASE ) hb_xfree( hb_set.HB_SET_FILECASE );
if( hb_set.HB_SET_DIRSEPARATOR ) hb_xfree( hb_set.HB_SET_FILECASE );
hb_set.HB_SET_TYPEAHEAD = -1; hb_inkeyReset( TRUE ); /* Free keyboard typeahead buffer */