From 2c6c52830f04df1c140ef94cb919788b9930bd2b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 16 Oct 2007 07:39:29 +0000 Subject: [PATCH] 2007-10-16 09:29 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * include/hbextern.ch * source/rtl/gete.c + Added HB_GETENV(). There you have a 2nd parameter which will be returned in case the requested envvar doesn't exist. This extensions is still present in GETE[NV](), but we'd better remove it. * include/hbextern.ch * source/rtl/isprint.c + Added HB_ISPRINTER() with support for extra parameter printer port name. This parameter also currently has support for Win32 printers. Win32 printer name support was removed from ISPRINTER() to keep compatibility. ISPRINTER() extra parameter is enabled with HB_COMPAT_XPP (which is the default). --- harbour/ChangeLog | 17 +++++++++++ harbour/include/hbextern.ch | 2 ++ harbour/source/rtl/gete.c | 55 ++++++++++++++++++++++++++++++++++++ harbour/source/rtl/isprint.c | 13 +++++++-- 4 files changed, 85 insertions(+), 2 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cdb9dc8139..895b31a7a0 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,23 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-10-16 09:29 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * include/hbextern.ch + * source/rtl/gete.c + + Added HB_GETENV(). There you have a 2nd parameter + which will be returned in case the requested + envvar doesn't exist. This extensions is still present + in GETE[NV](), but we'd better remove it. + + * include/hbextern.ch + * source/rtl/isprint.c + + Added HB_ISPRINTER() with support for extra parameter + printer port name. This parameter also currently has + support for Win32 printers. Win32 printer name support + was removed from ISPRINTER() to keep compatibility. + ISPRINTER() extra parameter is enabled with HB_COMPAT_XPP + (which is the default). + 2007-10-15 18:36 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * source/rtl/tbcolumn.prg ! Strict C5.2e compatible behaviour made the default. diff --git a/harbour/include/hbextern.ch b/harbour/include/hbextern.ch index 7849f85907..5bd5c410ef 100644 --- a/harbour/include/hbextern.ch +++ b/harbour/include/hbextern.ch @@ -409,6 +409,8 @@ EXTERNAL HB_HEXTONUM EXTERNAL HB_NUMTOHEX EXTERNAL HB_HEXTOSTR EXTERNAL HB_STRTOHEX +EXTERNAL HB_ISPRINTER +EXTERNAL HB_GETENV EXTERNAL HB_INISETCOMMENT EXTERNAL HB_INIREAD diff --git a/harbour/source/rtl/gete.c b/harbour/source/rtl/gete.c index cefc5a742a..b3dba80549 100644 --- a/harbour/source/rtl/gete.c +++ b/harbour/source/rtl/gete.c @@ -125,3 +125,58 @@ HB_FUNC( GETE ) { HB_FUNC_EXEC( GETENV ); } + +/* NOTE: Harbour extended version of GETENV(). The 2nd parameter + can be used to specify a default value, returned if the + requested envvar doesn't exist. [vszakats] */ + +HB_FUNC( HB_GETENV ) +{ + PHB_ITEM pName = hb_param( 1, HB_IT_STRING ); + + if( pName ) + { + char * pszName = hb_itemGetC( pName ); + ULONG ulName = strlen( pszName ); + ULONG ulPos; + + /* strip the '=' or else it will clear the variable! */ + + for( ulPos = 0; ulPos < ulName; ulPos++ ) + { + if( pszName[ ulPos ] == '=' ) + { + pszName[ ulPos ] = '\0'; + break; + } + } + + if( pszName[ 0 ] != '\0' ) + { + char * szValue; + + /* NOTE: Convert the envvar name to uppercase. This is required for + DOS and OS/2 systems. [vszakats] */ + + #if defined(HB_OS_DOS) || defined(HB_OS_OS2) + hb_strupr( pszName ); + #endif + + szValue = hb_getenv( pszName ); + if( szValue && szValue[ 0 ] != '\0' ) + hb_retc_buffer( szValue ); + else + { + if( szValue ) + hb_xfree( szValue ); + hb_retc( hb_parc( 2 ) ); + } + } + else + hb_retc( NULL ); + + hb_itemFreeC( pszName ); + } + else + hb_retc( NULL ); +} diff --git a/harbour/source/rtl/isprint.c b/harbour/source/rtl/isprint.c index 38dfa91685..c538388563 100644 --- a/harbour/source/rtl/isprint.c +++ b/harbour/source/rtl/isprint.c @@ -157,11 +157,20 @@ HB_EXPORT BOOL hb_printerIsReady( char * pszPrinterName ) return bIsPrinter; } -/* NOTE: The parameter is an extension over CA-Cl*pper, it's also supported - by Xbase++. [vszakats] */ +/* NOTE: The parameter is an XBase++ extension over CA-Cl*pper. [vszakats] */ HB_FUNC( ISPRINTER ) { +#ifdef HB_COMPAT_XPP + char * pszPrinter = hb_parc( 1 ); + hb_retl( hb_printerIsReady( pszPrinter ? pszPrinter : ( char * ) "LPT1" ) ); +#else + hb_retl( hb_printerIsReady( "LPT1" ) ); +#endif +} + +HB_FUNC( HB_ISPRINTER ) +{ #if defined(HB_WIN_32_PRINTERS) char DefaultPrinter[MAXBUFFERSIZE]; DWORD pdwBufferSize = MAXBUFFERSIZE;