From 6b668123d65508b9fcc6363d9b4ea6750ff5966f Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Fri, 19 Dec 2008 18:44:35 +0000 Subject: [PATCH] 2008-12-19 19:46 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/filesys.c * do not respect _SET_PATH when hb_{file|fs}ExtOpen() is called with create file attributes - Clipper compatibility. * harbour/source/vm/set.c * recognize files starting with "/dev/" as devices in *nixes * check if given file name is a name of existing device (character, block, fifo, socket) in *nix builds * ignore _SET_DEFAULT and default extension in _SET_PRINTFILE, _SET_ALTFILE and _SET_EXTRAFILE when given file name is device name. In DOS/Windows/OS2 builds devices are recognized by name: "PRN", "CON", "LPT[1-3]", "COM[1-9]" --- harbour/ChangeLog | 14 ++++++++ harbour/source/rtl/filesys.c | 4 ++- harbour/source/vm/set.c | 63 ++++++++++++++++++++++++------------ 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0a9cf6d99e..7976f87676 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,20 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-12-19 19:46 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/source/rtl/filesys.c + * do not respect _SET_PATH when hb_{file|fs}ExtOpen() is called + with create file attributes - Clipper compatibility. + + * harbour/source/vm/set.c + * recognize files starting with "/dev/" as devices in *nixes + * check if given file name is a name of existing device (character, + block, fifo, socket) in *nix builds + * ignore _SET_DEFAULT and default extension in _SET_PRINTFILE, + _SET_ALTFILE and _SET_EXTRAFILE when given file name is device name. + In DOS/Windows/OS2 builds devices are recognized by name: + "PRN", "CON", "LPT[1-3]", "COM[1-9]" + 2008-12-19 18:25 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/compiler/hbopt.c * pacified GCC warning diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 2e63ba2360..f1fe715129 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -2876,7 +2876,9 @@ BYTE * hb_fsExtName( BYTE * pFilename, BYTE * pDefExt, hb_fsFNameMerge( ( char * ) szPath, pFilepath ); fIsFile = hb_fsFile( szPath ); } - if( !fIsFile && hb_setGetPath() ) + if( !fIsFile && + ( uiExFlags & ( FXO_TRUNCATE | FXO_APPEND | FXO_UNIQUE ) ) == 0 && + hb_setGetPath() ) { pNextPath = hb_setGetFirstSetPath(); while( !fIsFile && pNextPath ) diff --git a/harbour/source/vm/set.c b/harbour/source/vm/set.c index b4bc48a732..3a7ab5569b 100644 --- a/harbour/source/vm/set.c +++ b/harbour/source/vm/set.c @@ -178,6 +178,40 @@ static void close_text( PHB_SET_STRUCT pSet, HB_FHANDLE handle ) } } +static BOOL is_devicename( const char * szFileName ) +{ + if( szFileName && *szFileName ) + { +#if defined(HB_OS_OS2) || defined(HB_OS_W32) || defined(HB_OS_DOS) + int iLen = ( int ) strlen( szFileName ); + if( ( iLen == 3 && + ( hb_stricmp( szFileName, "PRN" ) == 0 || + hb_stricmp( szFileName, "CON" ) == 0 ) ) || + ( iLen == 4 && + ( ( hb_strnicmp( szFileName, "LPT", 3 ) == 0 && + szFileName[3] >= '1' && szFileName[3] <= '3' ) || + ( hb_strnicmp( szFileName, "COM", 3 ) == 0 && + szFileName[3] >= '1' && szFileName[3] <= '9' ) ) ) ) + { + return TRUE; + } +#elif defined(HB_OS_UNIX) + if( strncmp( szFileName, "/dev/", 5 ) == 0 ) + return TRUE; + else + { + ULONG ulAttr = 0; + if( hb_fsGetAttr( ( BYTE * ) szFileName, &ulAttr ) ) + { + if( ulAttr & ( HB_FA_CHRDEVICE | HB_FA_BLKDEVICE | HB_FA_FIFO | HB_FA_SOCKET ) ) + return TRUE; + } + } +#endif + } + return FALSE; +} + static HB_FHANDLE open_handle( PHB_SET_STRUCT pSet, const char * file_name, BOOL bAppend, const char * def_ext, HB_set_enum set_specifier ) { PHB_ITEM pError = NULL; @@ -199,31 +233,20 @@ static HB_FHANDLE open_handle( PHB_SET_STRUCT pSet, const char * file_name, BOOL { PHB_FNAME pFilename = hb_fsFNameSplit( file_name ); - if( pSet->HB_SET_DEFEXTENSIONS && pFilename->szExtension == NULL && def_ext ) + if( is_devicename( file_name ) ) { #if defined(HB_OS_OS2) || defined(HB_OS_W32) || defined(HB_OS_DOS) - if( pFilename->szName ) - { - int iLen = ( int ) strlen( pFilename->szName ); - if( ( iLen == 3 && - ( hb_stricmp( pFilename->szName, "PRN" ) == 0 || - hb_stricmp( pFilename->szName, "CON" ) == 0 ) ) || - ( iLen == 4 && - ( ( hb_strnicmp( pFilename->szName, "LPT", 3 ) == 0 && - pFilename->szName[3] >= '1' && pFilename->szName[3] <= '3' ) || - ( hb_strnicmp( pFilename->szName, "COM", 3 ) == 0 && - pFilename->szName[3] >= '1' && pFilename->szName[3] <= '9' ) ) ) ) - { - hb_strupr( ( char * ) pFilename->szName ); - def_ext = NULL; - } - } + hb_strupr( ( char * ) pFilename->szName ); #endif - pFilename->szExtension = def_ext; } - if( pFilename->szPath == NULL && pSet->HB_SET_DEFAULT ) - pFilename->szPath = pSet->HB_SET_DEFAULT; + else + { + if( pFilename->szExtension == NULL && def_ext && pSet->HB_SET_DEFEXTENSIONS ) + pFilename->szExtension = def_ext; + if( pFilename->szPath == NULL && pSet->HB_SET_DEFAULT ) + pFilename->szPath = pSet->HB_SET_DEFAULT; + } hb_fsFNameMerge( path, pFilename ); hb_xfree( pFilename ); }