diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ae7355a276..a82043f303 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,16 @@ +2001-11-19 17:20 GMT+1 Martin Vogel + + + contrib/libct/bit2.c + + number and bit manipulation functions CLEARBIT, SETBIT, ISBIT + + all provided by Walter Negro - FOEESITRA + + * contrib/libct/Makefile + * contrib/libct/makefile.bc + * contrib/libct/makefile.vc + * contrib/libct/ctflist.txt + * changes according to the above + 2001-11-19 xx:xx GMT+0700 Andi Jahja * source/compiler/harbour.y ! add type casts for MsVC diff --git a/harbour/contrib/libct/Makefile b/harbour/contrib/libct/Makefile index ee6c446504..b9e55c818d 100644 --- a/harbour/contrib/libct/Makefile +++ b/harbour/contrib/libct/Makefile @@ -11,6 +11,7 @@ C_SOURCES = \ atadjust.c \ atnum.c \ atrepl.c \ + bit2.c \ charevod.c \ charlist.c \ charmirr.c \ diff --git a/harbour/contrib/libct/bit2.c b/harbour/contrib/libct/bit2.c new file mode 100644 index 0000000000..9444178f00 --- /dev/null +++ b/harbour/contrib/libct/bit2.c @@ -0,0 +1,283 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * CT3 Number and bit manipulation functions: - CLEARBIT() + * - SETBIT() + * - ISBIT() + * + * Copyright 2001 Walter Negro - FOEESITRA" + * 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 "ct.h" + + +long int static __hex2long( char *cNum1, int iLenHex ); +long int static __getparam( int iParam ); + + +/* $DOC$ + * $FUNCNAME$ + * CLEARBIT() + * $CATEGORY$ + * CT3 number and bit manipulation functions + * $ONELINER$ + * $SYNTAX$ + * CLEARBIT( , [,...] ) -> + * $ARGUMENTS$ + * $RETURNS$ + * $DESCRIPTION$ + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is bit2.c, library is libct. + * $SEEALSO$ + * SETBIT(), ISBIT() + * $END$ + */ + +HB_FUNC( CLEARBIT ) +{ + long int lNumClearBit = -1; + long int lNum1; + int iNum2; + int iPCount, iFor; + + iPCount = hb_pcount(); + + lNum1 = __getparam( 1 ); /* Obtain the parameter and converting from HEXA + if necessary */ + + if ( ISNUM(1) || ISCHAR(1) ) + + for ( iFor=2; iFor <= iPCount; iFor++) + { + if ( ISNUM( iFor ) ) + { + iNum2 = hb_parni( iFor ); + + if ( (iNum2 >= 1) && (iNum2 <= 32) ) + /* if bit to clear this between 1 and 32 */ + + lNumClearBit = lNum1 & ~( 1L << (iNum2 - 1) ); + + else + { + lNumClearBit = -1L; + break; + } + } + else + { + lNumClearBit = -1L; + break; + } + } + else + lNumClearBit = -1L; + + hb_retnl( lNumClearBit ); + +} + + +/* $DOC$ + * $FUNCNAME$ + * SETBIT() + * $CATEGORY$ + * CT3 number and bit manipulation functions + * $ONELINER$ + * $SYNTAX$ + * SETBIT( , [,...] ) -> + * $ARGUMENTS$ + * $RETURNS$ + * $DESCRIPTION$ + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is bit2.c, library is libct. + * $SEEALSO$ + * CLEARBIT(), ISBIT() + * $END$ + */ + +HB_FUNC( SETBIT ) +{ + long int lNumSetBit = -1L; + long int lNum1; + int iNum2; + int iPCount, iFor; + + iPCount = hb_pcount(); + + lNum1 = __getparam( 1 ); /* Obtain the parameter and converting from HEXA + if necessary */ + + if ( ISNUM(1) || ISCHAR(1) ) + + for ( iFor=2; iFor <= iPCount; iFor++) + { + if ( ISNUM( iFor ) ) + { + iNum2 = hb_parni( iFor ); + + if ( (iNum2 >= 1) && (iNum2 <= 32) ) + /* if bit to clear this between 1 and 32 */ + + lNumSetBit = lNum1 | ( 1L << (iNum2 - 1) ); + + else + { + lNumSetBit = -1L; + break; + } + } + else + { + lNumSetBit = -1L; + break; + } + } + else + lNumSetBit = -1L; + + hb_retnl( lNumSetBit ); + +} + +/* $DOC$ + * $FUNCNAME$ + * ISBIT() + * $CATEGORY$ + * CT3 number and bit manipulation functions + * $ONELINER$ + * $SYNTAX$ + * ISBIT( , ) -> + * $ARGUMENTS$ + * $RETURNS$ + * $DESCRIPTION$ + * TODO: add documentation + * $EXAMPLES$ + * $TESTS$ + * $STATUS$ + * Started + * $COMPLIANCE$ + * $PLATFORMS$ + * All + * $FILES$ + * Source is bit2.c, library is libct. + * $SEEALSO$ + * CLEARBIT(), SETBIT() + * $END$ + */ + +HB_FUNC ( ISBIT ) +{ + long int lNum1; + int iTestBit; + + if (( ISNUM( 1 ) || ISCHAR( 1 ) ) && ( ISNUM( 2 ) ) ) + { + lNum1 = __getparam( 1 ); + iTestBit = hb_parni( 2 ); + + hb_retl( lNum1 & ( 1L << (iTestBit - 1) ) ); + } + else + hb_retl( FALSE ); + +} + + +long int static __hex2long( char *cNum1, int iLenHex ) +{ + register int i; + register int iNum; + long int iHexNum = 0; + + + i = ( iLenHex - 1 ); + while (( i >= 0 ) && ( iLenHex-i <= 4 )) + { + iNum = ((int) cNum1[i]) - 0x30; + + if (iNum > 9) + iNum -= 7; + + if ((iNum < 0) || (iNum > 0x0F)) + break; + + iHexNum += (long int) iNum * (1 << (4 * ( iLenHex - i - 1 ))); + i--; + } + return iHexNum; +} + + +long int static __getparam( int iParam ) +{ + + if ( ISCHAR( iParam ) ) + return __hex2long( hb_parc( iParam ), hb_parclen( iParam ) ); + else + return hb_parnl( iParam ); + +} + + diff --git a/harbour/contrib/libct/ctflist.txt b/harbour/contrib/libct/ctflist.txt index 0d697ebd7b..372f11bd86 100644 --- a/harbour/contrib/libct/ctflist.txt +++ b/harbour/contrib/libct/ctflist.txt @@ -272,7 +272,7 @@ WORDTOCHAR ;S; ; BITTOC ;N; CELSIUS ;R; -CLEARBIT ;N; +CLEARBIT ;S; CTOBIT ;N; CTOF ;N; CTON ;S; @@ -282,7 +282,7 @@ FTOC ;N; INFINITY ;R; INTNEG ;N; INTPOS ;N; -ISBIT ;N; +ISBIT ;S; LTON ;N; MANTISSA ;N; NTOC ;S; @@ -297,7 +297,7 @@ NUMROL ;N; NUMXOR ;N; RAND ;N; RANDOM ;N; -SETBIT ;N; +SETBIT ;S; ; ; ;2.2 video functions diff --git a/harbour/contrib/libct/makefile.bc b/harbour/contrib/libct/makefile.bc index 19c67de180..d50e028901 100644 --- a/harbour/contrib/libct/makefile.bc +++ b/harbour/contrib/libct/makefile.bc @@ -96,6 +96,7 @@ TOOLS_LIB_OBJS = \ $(OBJ_DIR)\atadjust.obj \ $(OBJ_DIR)\atnum.obj \ $(OBJ_DIR)\atrepl.obj \ + $(OBJ_DIR)\bit2.obj \ $(OBJ_DIR)\charevod.obj \ $(OBJ_DIR)\charlist.obj \ $(OBJ_DIR)\charmirr.obj \ @@ -183,6 +184,10 @@ $(OBJ_DIR)\atrepl.obj : $(TOOLS_DIR)\atrepl.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,, +$(OBJ_DIR)\bit2.obj : $(TOOLS_DIR)\bit2.c + $(CC) $(CLIBFLAGS) -o$@ $** + tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,, + $(OBJ_DIR)\charevod.obj : $(TOOLS_DIR)\charevod.c $(CC) $(CLIBFLAGS) -o$@ $** tlib $(TOOLS_LIB) $(ARFLAGS) -+$@,, diff --git a/harbour/contrib/libct/makefile.vc b/harbour/contrib/libct/makefile.vc index 2819b9538f..7c3a5a4419 100644 --- a/harbour/contrib/libct/makefile.vc +++ b/harbour/contrib/libct/makefile.vc @@ -116,6 +116,7 @@ TOOLS_LIB_OBJS = \ $(OBJ_DIR)\atadjust.obj \ $(OBJ_DIR)\atnum.obj \ $(OBJ_DIR)\atrepl.obj \ + $(OBJ_DIR)\bit2.obj \ $(OBJ_DIR)\charevod.obj \ $(OBJ_DIR)\charlist.obj \ $(OBJ_DIR)\charmirr.obj \ @@ -176,6 +177,7 @@ CLEAN: -@if exist $(OBJ_DIR)\atadjust.* del $(OBJ_DIR)\atadjust.* -@if exist $(OBJ_DIR)\atnum.* del $(OBJ_DIR)\atnum.* -@if exist $(OBJ_DIR)\atrepl.* del $(OBJ_DIR)\atrepl.* + -@if exist $(OBJ_DIR)\bit2.* del $(OBJ_DIR)\bit2.* -@if exist $(OBJ_DIR)\charevod.* del $(OBJ_DIR)\charevod.* -@if exist $(OBJ_DIR)\charlist.* del $(OBJ_DIR)\charlist.* -@if exist $(OBJ_DIR)\charmirr.* del $(OBJ_DIR)\charmirr.*