From 8cfbc435f7f141f200daedf5790eebd8265c1c5b Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Mon, 2 Jul 2007 15:16:58 +0000 Subject: [PATCH] 2007-07-02 17:16 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/common.mak * harbour/source/rtl/Makefile + harbour/source/rtl/hbhex.c * added HB_HEXTONUM() and HB_NUMTOHEX() * harbour/include/hbcompat.ch * added trnaslation rules for expresions in parentheses which use new xHarbour operators: HAS, IN, LIKE, &, |, ^^, >>, << Please note that only code which uses above operators in parentheses will be translated, f.e. this code will not be translated: if cVal1 IN cVal2 nVal := nVal1 | nVal2 | nVal3 | nVal4 endif will not be translated but this one will: if ( cVal1 IN cVal2 ) nVal := ( nVal1 | nVal2 | nVal3 | nVal4 ) endif * harbour/contrib/tip/thtml.prg * harbour/contrib/tip/thtml.ch + added $\Id * harbour/source/rtl/hbbit.c + added $\Id ! fixed typo in HB_BITSHIFT() --- harbour/ChangeLog | 26 +++++++ harbour/common.mak | 1 + harbour/contrib/tip/thtml.ch | 4 ++ harbour/contrib/tip/thtml.prg | 11 ++- harbour/include/hbcompat.ch | 27 ++++++- harbour/source/rtl/Makefile | 1 + harbour/source/rtl/hbbit.c | 2 +- harbour/source/rtl/hbhex.c | 128 ++++++++++++++++++++++++++++++++++ 8 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 harbour/source/rtl/hbhex.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index fb24a0b133..3e5517a713 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,32 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-07-02 17:16 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/common.mak + * harbour/source/rtl/Makefile + + harbour/source/rtl/hbhex.c + * added HB_HEXTONUM() and HB_NUMTOHEX() + + * harbour/include/hbcompat.ch + * added trnaslation rules for expresions in parentheses which use + new xHarbour operators: HAS, IN, LIKE, &, |, ^^, >>, << + Please note that only code which uses above operators in parentheses + will be translated, f.e. this code will not be translated: + if cVal1 IN cVal2 + nVal := nVal1 | nVal2 | nVal3 | nVal4 + endif + will not be translated but this one will: + if ( cVal1 IN cVal2 ) + nVal := ( nVal1 | nVal2 | nVal3 | nVal4 ) + endif + + * harbour/contrib/tip/thtml.prg + * harbour/contrib/tip/thtml.ch + + added $\Id + * harbour/source/rtl/hbbit.c + + added $\Id + ! fixed typo in HB_BITSHIFT() + 2007-07-02 14:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbcompat.ch + added hb_CStr() <=> CStr() translations diff --git a/harbour/common.mak b/harbour/common.mak index 2cbd68aaff..a2253288e9 100644 --- a/harbour/common.mak +++ b/harbour/common.mak @@ -414,6 +414,7 @@ RTL_LIB_OBJS = \ $(OBJ_DIR)\hbadler$(OBJEXT) \ $(OBJ_DIR)\hbbit$(OBJEXT) \ $(OBJ_DIR)\hbcrc$(OBJEXT) \ + $(OBJ_DIR)\hbhex$(OBJEXT) \ $(OBJ_DIR)\hbmd5$(OBJEXT) \ $(OBJ_DIR)\hbffind$(OBJEXT) \ $(OBJ_DIR)\hbgtcore$(OBJEXT) \ diff --git a/harbour/contrib/tip/thtml.ch b/harbour/contrib/tip/thtml.ch index 77182654cc..5f3c460691 100644 --- a/harbour/contrib/tip/thtml.ch +++ b/harbour/contrib/tip/thtml.ch @@ -1,3 +1,7 @@ +/* + * $Id$ + */ + /* * Harbour Project source code: * Directives for HTML Classes diff --git a/harbour/contrib/tip/thtml.prg b/harbour/contrib/tip/thtml.prg index ba0e5441e7..eff7d3fee6 100644 --- a/harbour/contrib/tip/thtml.prg +++ b/harbour/contrib/tip/thtml.prg @@ -1,3 +1,7 @@ +/* + * $Id$ + */ + /* * Harbour Project source code: * HTML Classes @@ -51,13 +55,6 @@ #include "hbclass.ch" #include "thtml.ch" -#xtranslate ( HAS ) => HB_REGEXHAS( , ) -#xtranslate ( LIKE ) => HB_REGEXLIKE( , ) -#xtranslate ( | [ | ] ) => HB_BITOR( , [, ] ) -#xtranslate ( & [ & ] ) => HB_BITAND( , [, ] ) -#xtranslate HB_BITOR( [,] | ) => HB_BITOR( [,] , ) -#xtranslate HB_BITAND( [,] & ) => HB_BITAND( [,] , ) - // A Html document can have more than 16 nesting levels. // The current implementation of FOR EACH is not suitable for the HTML classes diff --git a/harbour/include/hbcompat.ch b/harbour/include/hbcompat.ch index f019a89657..e7254ca6a9 100644 --- a/harbour/include/hbcompat.ch +++ b/harbour/include/hbcompat.ch @@ -123,8 +123,8 @@ #xtranslate HALLOCATE([]) => HB_HALLOCATE() #xtranslate HDEFAULT([]) => HB_HDEFAULT() - #xtranslate NUMTOHEX() => NTOC(, 16) - #xtranslate HEXTONUM() => CTON(, 16) + #xtranslate HEXTONUM([]) => HB_HEXTONUM() + #xtranslate NUMTOHEX([]) => HB_NUMTOHEX() #xcommand TEXT INTO => #pragma __text|+=%s+HB_OSNEWLINE();:="" @@ -140,6 +140,29 @@ #xtranslate \<|[]| => {|| #xcommand > [<*x*>] => } + /* xHarbour operators: IN, HAS, LIKE, >>, <<, |, &, ^^ */ + #translate ( IN => ( $ + #translate ( HAS => ( HB_REGEXHAS( , ) + #translate ( LIKE => ( HB_REGEXLIKE( , ) + #translate ( \<\< => ( HB_BITSHIFT( , ) + #translate ( >> => ( HB_BITSHIFT( , - ) + #translate ( | => ( HB_BITOR( , ) + #translate ( & => ( HB_BITAND( , ) + #translate ( ^^ => ( HB_BITXOR( , ) + + #translate , IN => , $ + #translate , HAS => , HB_REGEXHAS( , ) + #translate , LIKE => , HB_REGEXLIKE( , ) + #translate , \<\< => , HB_BITSHIFT( , ) + #translate , >> => , HB_BITSHIFT( , - ) + #translate , | => , HB_BITOR( , ) + #translate , & => , HB_BITAND( , ) + #translate , ^^ => , HB_BITXOR( , ) + + #xtranslate HB_BITOR( [,] | ) => HB_BITOR( [,] , ) + #xtranslate HB_BITAND( [,] & ) => HB_BITAND( [,] , ) + #xtranslate HB_BITXOR( [,] ^^ ) => HB_BITXOR( [,] , ) + #endif #endif /* __HARBOUR__ */ diff --git a/harbour/source/rtl/Makefile b/harbour/source/rtl/Makefile index 432cbf845b..e2a142c4ef 100644 --- a/harbour/source/rtl/Makefile +++ b/harbour/source/rtl/Makefile @@ -52,6 +52,7 @@ C_SOURCES=\ hbadler.c \ hbbit.c \ hbcrc.c \ + hbhex.c \ hbmd5.c \ hbffind.c \ hbgtcore.c \ diff --git a/harbour/source/rtl/hbbit.c b/harbour/source/rtl/hbbit.c index 96542101f0..013330ee91 100644 --- a/harbour/source/rtl/hbbit.c +++ b/harbour/source/rtl/hbbit.c @@ -153,7 +153,7 @@ HB_FUNC( HB_BITSHIFT ) if( hb_numParam( 1, &lValue ) && hb_numParam( 2, &lBits ) ) { if( lBits < 0 ) - hb_retnint( lValue >> lBits ); + hb_retnint( lValue >> -lBits ); else hb_retnint( lValue << lBits ); } diff --git a/harbour/source/rtl/hbhex.c b/harbour/source/rtl/hbhex.c new file mode 100644 index 0000000000..10f6276a6b --- /dev/null +++ b/harbour/source/rtl/hbhex.c @@ -0,0 +1,128 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * HB_NUMTOHEX() + * HB_HEXTONUM() + * + * Copyright 2007 Przemyslaw Czerpak + * 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 "hbapierr.h" + +HB_FUNC( HB_HEXTONUM ) +{ + char * szHex = hb_parc( 1 ); + + if( szHex ) + { + HB_ULONG ulNum = 0; + + while( *szHex == ' ' ) szHex++; + while( *szHex ) + { + int iDigit; + char c = *szHex++; + if ( c >= '0' && c <= '9' ) + iDigit = c - '0'; + else if ( c >= 'A' && c <= 'F' ) + iDigit = c - 'A' + 10; + else if ( c >= 'a' && c <= 'f' ) + iDigit = c - 'a' + 10; + else + { + ulNum = 0; + break; + } + ulNum = ( ulNum << 4 ) + iDigit; + } + hb_retnint( ulNum ); + } + else + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, &hb_errFuncName, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( HB_NUMTOHEX ) +{ + HB_ULONG ulNum; + int iLen; + BOOL fDefaultLen; + char ret[ 33 ]; + + if( ISNUM( 2 ) ) + { + iLen = hb_parni( 2 ); + iLen = ( iLen < 1 ) ? 1 : ( ( iLen > 32 ) ? 32 : iLen ); + fDefaultLen = 0; + } + else + { + iLen = 32; + fDefaultLen = 1; + } + + if( ISNUM( 1 ) ) + ulNum = hb_parnint( 1 ); + else if( ISPOINTER( 1 ) ) + ulNum = (HB_PTRDIFF) hb_parptr( 1 ); + else + { + hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, &hb_errFuncName, HB_ERR_ARGS_BASEPARAMS ); + return; + } + + ret[ iLen ] = '\0'; + do + { + int iDigit = ( int ) ( ulNum & 0x0F ); + ret[ --iLen ] = iDigit + ( iDigit < 10 ? '0' : 'A' - 10 ); + ulNum >>= 4; + } + while( fDefaultLen ? ulNum : iLen ); + + hb_retc( &ret[ iLen ] ); +}