2007-11-04 02:34 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/include/hbapi.h
  * harbour/source/common/hbstr.c
    + added hb_strlow()

  * harbour/source/rtl/fstemp.c
  * harbour/source/rtl/filesys.c
    ! fixed _SET_DIRSEPARATOR behavior - now it's always set to default
      OS directory separator what means no translations. If you want to
      enable some translations then it should be set to other value, f.e.
      in *nixes:
         set( _SET_DIRSEPARATOR, "\" )
      enables translations of "\" in paths to "/"

  * harbour/source/main/harbour.c
    + added support for new compiler switches:
         - Filename casing:
               -fn:l       (lower)
               -fn:u       (upper)
               -fn-        (disable - default)
               -fn         (disable - default)
         - Directory casing
               -fd:l       (lower)
               -fd:u       (upper)
               -fd-        (disable - default)
               -fd         (disable - default)
         - Path separator:
               -fp:<char>
               -fp         (default: OS defined)
         - Filename space trimming:
               -fs         (enable)
               -fs-        (disable - default)
      These switches works only in standalone compiler.
      When compiler is linked with HVM and RTL then corresponding
      _SET_* switches are used instead.
This commit is contained in:
Przemyslaw Czerpak
2007-11-04 01:34:59 +00:00
parent 523a7a2705
commit 7bad05f1b6
6 changed files with 264 additions and 17 deletions

View File

@@ -8,6 +8,42 @@
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
2007-11-04 02:34 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbapi.h
* harbour/source/common/hbstr.c
+ added hb_strlow()
* harbour/source/rtl/fstemp.c
* harbour/source/rtl/filesys.c
! fixed _SET_DIRSEPARATOR behavior - now it's always set to default
OS directory separator what means no translations. If you want to
enable some translations then it should be set to other value, f.e.
in *nixes:
set( _SET_DIRSEPARATOR, "\" )
enables translations of "\" in paths to "/"
* harbour/source/main/harbour.c
+ added support for new compiler switches:
- Filename casing:
-fn:l (lower)
-fn:u (upper)
-fn- (disable - default)
-fn (disable - default)
- Directory casing
-fd:l (lower)
-fd:u (upper)
-fd- (disable - default)
-fd (disable - default)
- Path separator:
-fp:<char>
-fp (default: OS defined)
- Filename space trimming:
-fs (enable)
-fs- (disable - default)
These switches works only in standalone compiler.
When compiler is linked with HVM and RTL then corresponding
_SET_* switches are used instead.
2007-11-03 11:12 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/rtl/cdpapi.c
* indenting

View File

@@ -812,6 +812,7 @@ extern const char * hb_szAscii[256]; /* array of 1 character length strings
extern HB_EXPORT int hb_stricmp( const char * s1, const char * s2 ); /* compare two strings without regards to case */
extern HB_EXPORT int hb_strnicmp( const char * s1, const char * s2, ULONG ulLen ); /* compare two string without regards to case, limited by length */
extern HB_EXPORT char * hb_strupr( char * pszText ); /* convert a string in-place to upper-case */
extern HB_EXPORT char * hb_strlow( char * pszText ); /* convert a string in-place to lower-case */
extern HB_EXPORT char * hb_strdup( const char * pszText ); /* returns a pointer to a newly allocated copy of the source string */
extern HB_EXPORT char * hb_strndup( const char * pszText, ULONG ulLen ); /* returns a pointer to a newly allocated copy of the source string not longer then ulLen */
extern HB_EXPORT ULONG hb_strnlen( const char * pszText, ULONG ulLen ); /* like strlen() but result is limited to ulLen */

View File

@@ -129,6 +129,18 @@ HB_EXPORT char * hb_strupr( char * pszText )
return pszText;
}
HB_EXPORT char * hb_strlow( char * pszText )
{
char * pszPos;
HB_TRACE(HB_TR_DEBUG, ("hb_strlow(%s)", pszText));
for( pszPos = pszText; *pszPos; pszPos++ )
*pszPos = tolower( ( UCHAR ) *pszPos );
return pszText;
}
HB_EXPORT char * hb_strdup( const char * pszText )
{
char * pszDup;

View File

@@ -53,16 +53,7 @@
#include "hbcomp.h"
#include "hbapifs.h"
#include "hbmemory.ch"
int main( int argc, char * argv[] )
{
int iResult;
iResult = hb_compMain( argc, argv, NULL, NULL, NULL );
hb_xexit();
return iResult;
}
#include "hbset.h"
/* ------------------------------------------------------------------------- */
/* FM statistic module */
@@ -362,10 +353,217 @@ char * hb_conNewLine( void )
return "\n";
}
static int s_iFileCase = HB_SET_CASE_MIXED;
static int s_iDirCase = HB_SET_CASE_MIXED;
static BOOL s_fFnTrim = FALSE;
static char s_cDirSep = OS_PATH_DELIMITER;
HB_EXPORT BYTE * hb_fsNameConv( BYTE * szFileName, BOOL * pfFree )
{
if( pfFree )
* pfFree = FALSE;
if( s_fFnTrim || s_cDirSep != OS_PATH_DELIMITER ||
s_iFileCase != HB_SET_CASE_MIXED || s_iDirCase != HB_SET_CASE_MIXED )
{
PHB_FNAME pFileName;
ULONG ulLen;
if( pfFree )
{
BYTE * szNew = ( BYTE * ) hb_xgrab( _POSIX_PATH_MAX + 1 );
hb_strncpy( ( char * ) szNew, ( char * ) szFileName, _POSIX_PATH_MAX );
szFileName = szNew;
*pfFree = TRUE;
}
if( s_cDirSep != OS_PATH_DELIMITER )
{
BYTE *p = szFileName;
while( *p )
{
if( *p == s_cDirSep )
*p = OS_PATH_DELIMITER;
p++;
}
}
pFileName = hb_fsFNameSplit( ( char * ) szFileName );
/* strip trailing and leading spaces */
if( s_fFnTrim )
{
if( pFileName->szName )
{
ulLen = strlen( pFileName->szName );
while( ulLen && pFileName->szName[ulLen - 1] == ' ' )
--ulLen;
while( ulLen && pFileName->szName[0] == ' ' )
{
++pFileName->szName;
--ulLen;
}
pFileName->szName[ulLen] = '\0';
}
if( pFileName->szExtension )
{
ulLen = strlen( pFileName->szExtension );
while( ulLen && pFileName->szExtension[ulLen - 1] == ' ' )
--ulLen;
while( ulLen && pFileName->szExtension[0] == ' ' )
{
++pFileName->szExtension;
--ulLen;
}
pFileName->szExtension[ulLen] = '\0';
}
}
/* FILECASE */
if( s_iFileCase == HB_SET_CASE_LOWER )
{
if( pFileName->szName )
hb_strlow( pFileName->szName );
if( pFileName->szExtension )
hb_strlow( pFileName->szExtension );
}
else if( s_iFileCase == HB_SET_CASE_UPPER )
{
if( pFileName->szName )
hb_strupr( pFileName->szName );
if( pFileName->szExtension )
hb_strupr( pFileName->szExtension );
}
/* DIRCASE */
if( pFileName->szPath )
{
if( s_iDirCase == HB_SET_CASE_LOWER )
hb_strlow( pFileName->szPath );
else if( s_iDirCase == HB_SET_CASE_UPPER )
hb_strupr( pFileName->szPath );
}
hb_fsFNameMerge( ( char * ) szFileName, pFileName );
hb_xfree( pFileName );
}
else if( pfFree )
*pfFree = FALSE;
return szFileName;
}
static void hb_compChkFileSwitches( int argc, char * argv[] )
{
int i, n;
for( i = 1; i < argc; ++i )
{
if( HB_ISOPTSEP( argv[i][0] ) && argv[i][1] == 'f' )
{
n = 0;
switch( argv[i][2] )
{
case 'n':
if( !argv[i][3] )
{
s_iFileCase = HB_SET_CASE_MIXED;
n = 3;
}
else if( argv[i][3] == ':' )
{
if( argv[i][4] == 'u' )
{
s_iFileCase = HB_SET_CASE_UPPER;
n = 5;
}
else if( argv[i][4] == 'l' )
{
s_iFileCase = HB_SET_CASE_LOWER;
n = 5;
}
}
else if( argv[i][3] == '-' )
{
s_iFileCase = HB_SET_CASE_MIXED;
n = 4;
}
break;
case 'd':
if( !argv[i][3] )
{
s_iDirCase = HB_SET_CASE_MIXED;
n = 3;
}
else if( argv[i][3] == ':' )
{
if( argv[i][4] == 'u' )
{
s_iDirCase = HB_SET_CASE_UPPER;
n = 5;
}
else if( argv[i][4] == 'l' )
{
s_iDirCase = HB_SET_CASE_LOWER;
n = 5;
}
}
else if( argv[i][3] == '-' )
{
s_iDirCase = HB_SET_CASE_MIXED;
n = 4;
}
break;
case 'p':
if( !argv[i][3] )
{
s_cDirSep = OS_PATH_DELIMITER;
n = 3;
}
else if( argv[i][3] == '-' )
{
s_cDirSep = OS_PATH_DELIMITER;
n = 4;
}
else if( argv[i][3] == ':' && argv[i][4] )
{
s_cDirSep = argv[i][4];
n = 5;
}
break;
case 's':
if( !argv[i][3] )
{
s_fFnTrim = TRUE;
n = 3;
}
else if( argv[i][3] == '-' )
{
s_fFnTrim = FALSE;
n = 4;
}
break;
}
if( n )
{
argv[i] += n;
if( argv[i][0] )
--i;
else
argv[i] = "-";
}
}
}
}
int main( int argc, char * argv[] )
{
int iResult;
hb_compChkFileSwitches( argc, argv );
iResult = hb_compMain( argc, argv, NULL, NULL, NULL );
hb_xexit();
return iResult;
}

View File

@@ -2363,7 +2363,7 @@ HB_EXPORT BYTE * hb_fsNameConv( BYTE * szFileName, BOOL * pfFree )
*/
if( hb_set.HB_SET_TRIMFILENAME ||
hb_set.HB_SET_DIRSEPARATOR != '\\' ||
hb_set.HB_SET_DIRSEPARATOR != OS_PATH_DELIMITER ||
hb_set.HB_SET_FILECASE != HB_SET_CASE_MIXED ||
hb_set.HB_SET_DIRCASE != HB_SET_CASE_MIXED )
{
@@ -2378,13 +2378,13 @@ HB_EXPORT BYTE * hb_fsNameConv( BYTE * szFileName, BOOL * pfFree )
*pfFree = TRUE;
}
if( hb_set.HB_SET_DIRSEPARATOR != '\\' )
if( hb_set.HB_SET_DIRSEPARATOR != OS_PATH_DELIMITER )
{
BYTE *p = szFileName;
while( *p )
{
if( *p == '\\' )
*p = hb_set.HB_SET_DIRSEPARATOR;
if( *p == hb_set.HB_SET_DIRSEPARATOR )
*p = OS_PATH_DELIMITER;
p++;
}
}

View File

@@ -206,7 +206,7 @@ HB_EXPORT FHANDLE hb_fsCreateTemp( const BYTE * pszDir, const BYTE * pszPrefix,
{
int len;
len = strlen( ( char * ) pszName );
pszName[ len ] = ( BYTE ) hb_set.HB_SET_DIRSEPARATOR;
pszName[ len ] = ( BYTE ) OS_PATH_DELIMITER;
pszName[ len + 1 ] = '\0';
}