From bc71137a02223f4f6da1d4e4d9ada2dc6b61ee0e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 4 Jun 2009 12:00:42 +0000 Subject: [PATCH] 2009-06-04 14:00 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/xhb/Makefile + contrib/xhb/xhbsave.c + contrib/xhb/xhbtrim.c + Added "extended" versions of some core functions, supporting some extra parameters formerly available in Harbour when compiled with (now removed) HB_EXTENSION option: XHB_TRIM(), XHB_RTRIM(), XHB_ALLTRIM(), XHB_SAVESCREEN(), XHB_RESTSCREEN(). --- harbour/ChangeLog | 11 +++ harbour/contrib/xhb/Makefile | 2 + harbour/contrib/xhb/xhbsave.c | 125 ++++++++++++++++++++++++++++++++++ harbour/contrib/xhb/xhbtrim.c | 122 +++++++++++++++++++++++++++++++++ 4 files changed, 260 insertions(+) create mode 100644 harbour/contrib/xhb/xhbsave.c create mode 100644 harbour/contrib/xhb/xhbtrim.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 87c5727af1..c67065071a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,17 @@ past entries belonging to these authors: Viktor Szakats. */ +2009-06-04 14:00 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/xhb/Makefile + + contrib/xhb/xhbsave.c + + contrib/xhb/xhbtrim.c + + Added "extended" versions of some core functions, + supporting some extra parameters formerly available + in Harbour when compiled with (now removed) HB_EXTENSION + option: + XHB_TRIM(), XHB_RTRIM(), XHB_ALLTRIM(), + XHB_SAVESCREEN(), XHB_RESTSCREEN(). + 2009-06-04 13:53 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/xhb/hbcompat.ch + Added INET and HASH function name conversion from diff --git a/harbour/contrib/xhb/Makefile b/harbour/contrib/xhb/Makefile index 0f5f080ecd..fa3831253b 100644 --- a/harbour/contrib/xhb/Makefile +++ b/harbour/contrib/xhb/Makefile @@ -30,7 +30,9 @@ C_SOURCES=\ xhbis.c \ xhbmsgs.c \ xhbqself.c \ + xhbsave.c \ xhbscr.c \ + xhbtrim.c \ xhbwith.c \ xstrdel.c \ diff --git a/harbour/contrib/xhb/xhbsave.c b/harbour/contrib/xhb/xhbsave.c new file mode 100644 index 0000000000..0878d0e87f --- /dev/null +++ b/harbour/contrib/xhb/xhbsave.c @@ -0,0 +1,125 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * XHB_SAVESCREEN(), XHB_RESTSCREEN() functions + * + * Copyright 1999 Antonio Linares + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapigt.h" + +static void hb_getScreenRange( USHORT * pusMin, USHORT * pusMax, + BOOL fNoCheck, BOOL fVertical ) +{ + int iFrom, iTo, iMax; + + if( fVertical ) + { + iMax = hb_gtMaxRow(); + iFrom = hb_parni( 1 ); + iTo = ISNUM( 3 ) ? hb_parni( 3 ) : iMax; + } + else + { + iMax = hb_gtMaxCol(); + iFrom = hb_parni( 2 ); + iTo = ISNUM( 4 ) ? hb_parni( 4 ) : iMax; + } + + if( iFrom < 0 ) + iFrom = 0; + else if( iFrom > iMax && !fNoCheck ) + iFrom = iMax; + + if( iTo < 0 ) + iTo = 0; + else if( iTo > iMax && !fNoCheck ) + iTo = iMax; + + if( iFrom > iTo ) + { + *pusMin = ( USHORT ) iTo; + *pusMax = ( USHORT ) iFrom; + } + else + { + *pusMin = ( USHORT ) iFrom; + *pusMax = ( USHORT ) iTo; + } +} + +HB_FUNC( XHB_SAVESCREEN ) +{ + USHORT uiTop, uiLeft, uiBottom, uiRight; + ULONG ulSize; + void * pBuffer; + BOOL fNoCheck = hb_parl( 5 ); + + hb_getScreenRange( &uiTop, &uiBottom, fNoCheck, TRUE ); + hb_getScreenRange( &uiLeft, &uiRight, fNoCheck, FALSE ); + + hb_gtRectSize( uiTop, uiLeft, uiBottom, uiRight, &ulSize ); + pBuffer = hb_xgrab( ulSize + 1 ); + + hb_gtSave( uiTop, uiLeft, uiBottom, uiRight, pBuffer ); + hb_retclen_buffer( ( char * ) pBuffer, ulSize ); +} + +HB_FUNC( XHB_RESTSCREEN ) +{ + if( ISCHAR( 5 ) ) + { + USHORT uiTop, uiLeft, uiBottom, uiRight; + BOOL fNoCheck = hb_parl( 6 ); + + hb_getScreenRange( &uiTop, &uiBottom, fNoCheck, TRUE ); + hb_getScreenRange( &uiLeft, &uiRight, fNoCheck, FALSE ); + + hb_gtRest( uiTop, uiLeft, uiBottom, uiRight, ( void * ) hb_parc( 5 ) ); + } +} diff --git a/harbour/contrib/xhb/xhbtrim.c b/harbour/contrib/xhb/xhbtrim.c new file mode 100644 index 0000000000..2503842a12 --- /dev/null +++ b/harbour/contrib/xhb/xhbtrim.c @@ -0,0 +1,122 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * *TRIM() functions + * + * Copyright 1999 Antonio Linares + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbapiitm.h" +#include "hbapierr.h" + +/* trims trailing spaces from a string */ + +/* NOTE: The second parameter is a Harbour extension. */ + +HB_FUNC( XHB_RTRIM ) +{ + PHB_ITEM pText = hb_param( 1, HB_IT_STRING ); + + if( pText ) + { + ULONG ulLen, ulSrc; + char * szText = hb_itemGetCPtr( pText ); + + ulSrc = hb_itemGetCLen( pText ); + ulLen = hb_strRTrimLen( szText, ulSrc, ISLOG( 2 ) && hb_parl( 2 ) ); + + if( ulLen == ulSrc ) + hb_itemReturn( pText ); + else + hb_retclen( szText, ulLen ); + } + else + /* NOTE: "TRIM" is right here [vszakats] */ + hb_errRT_BASE_SubstR( EG_ARG, 1100, NULL, "TRIM", HB_ERR_ARGS_BASEPARAMS ); +} + +/* synonymn for XHB_RTRIM */ +HB_FUNC( XHB_TRIM ) +{ + HB_FUNC_EXEC( XHB_RTRIM ); +} + +/* trims leading and trailing spaces from a string */ + +/* NOTE: The second parameter is a Harbour extension. */ + +HB_FUNC( XHB_ALLTRIM ) +{ + PHB_ITEM pText = hb_param( 1, HB_IT_STRING ); + + if( pText ) + { + ULONG ulLen, ulSrc; + char * szText = hb_itemGetCPtr( pText ); + + ulSrc = hb_itemGetCLen( pText ); + ulLen = hb_strRTrimLen( szText, ulSrc, ISLOG( 2 ) && hb_parl( 2 ) ); + szText = hb_strLTrim( szText, &ulLen ); + + if( ulLen == ulSrc ) + hb_itemReturn( pText ); + else + hb_retclen( szText, ulLen ); + } + else +#ifdef HB_COMPAT_C53 + /* NOTE: This runtime error appeared in CA-Cl*pper 5.3 [vszakats] */ +#ifdef HB_C52_STRICT + hb_errRT_BASE_SubstR( EG_ARG, 2022, NULL, "ALLTRIM", 0 ); +#else + hb_errRT_BASE_SubstR( EG_ARG, 2022, NULL, "ALLTRIM", HB_ERR_ARGS_BASEPARAMS ); +#endif +#else + hb_retc( NULL ); +#endif +}