diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0f2e86f2b8..4aa20e0d4b 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,7 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ -2010-06-20 18:57 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) +2010-06-21 20:46 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbct/Makefile + * contrib/hbct/hbct.hbp + * contrib/hbct/ct.h + * contrib/hbct/charlist.c + + contrib/hbct/charlish.c + ! Moved non-CT3 (Harbour extension functions to separate + source file) + % Optimized code. + * Cleaned code and type usage. + + * Changelog + ! Fixed date in my today's commits. + +2010-06-21 18:57 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/rtl/filesys.c ! Fixed typo in last commit affecting Windows builds. @@ -42,7 +56,7 @@ * harbour/contrib/xhb/fparse.c * pacified CLANG warnings -2010-06-20 15:24 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) +2010-06-21 15:24 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/vm/thread.c * Added casts to pacify msvc64 warnings. Of some the ones related to pMutex->events I'm unsure of, @@ -54,7 +68,7 @@ * src/vm/classes.c * Added casts to pacify msvc64 warnings. -2010-06-20 15:10 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) +2010-06-21 15:10 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/vm/extend.c ! Fixed typo in hb_retns(). diff --git a/harbour/contrib/hbct/Makefile b/harbour/contrib/hbct/Makefile index dafeef80eb..bae0c43a43 100644 --- a/harbour/contrib/hbct/Makefile +++ b/harbour/contrib/hbct/Makefile @@ -16,6 +16,7 @@ C_SOURCES := \ bitnum.c \ blank.c \ charevod.c \ + charlish.c \ charlist.c \ charmirr.c \ charmix.c \ diff --git a/harbour/contrib/hbct/charlish.c b/harbour/contrib/hbct/charlish.c new file mode 100644 index 0000000000..6b8988fc3d --- /dev/null +++ b/harbour/contrib/hbct/charlish.c @@ -0,0 +1,145 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * CT3 string functions + * - CHARSLIST() (Harbour extension) + * - CHARHIST() (Harbour extension) + * + * Copyright 2001 IntTec GmbH, Neunlindenstr 32, 79106 Freiburg, Germany + * Author: Martin Vogel + * + * www - http://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" + +/* $DOC$ + * $FUNCNAME$ + * CHARSLIST() + * $CATEGORY$ + * CT3 string functions + * $ONELINER$ + * Generates a sorted list of all characters in a string + * $SYNTAX$ + * CHARSLIST ([]) -> cSortedCharacterList + * $ARGUMENTS$ + * [] is the string for whom the function generates a + * sorted list of all characters + * Default: "" (empty string) + * $RETURNS$ + * a sorted list of the characters in + * $DESCRIPTION$ + * The CHARLIST() function generates a sorted list of those characters that + * are contained in . This list can contain each character + * only once, so that its maximum length is 256. The function + * gives the same result as CHARSORT(CHARLIST()) + * $EXAMPLES$ + * ? charslist ("Hello World !") --> " !HWdelor" + * $TESTS$ + * charslist ("Hello World !") == " !HWdelor" + * charslist ("Hello World !") == charsort (charlist ("Hello World !")) + * charslist (nil) == "" + * $STATUS$ + * Ready + * $COMPLIANCE$ + * CHARSLIST() is only available in Harbour's CT3 library. + * $PLATFORMS$ + * All + * $FILES$ + * Source is charlist.c, library is libct. + * $SEEALSO$ + * CHARNOLIST(),CHARLIST(),CHARHIST() + * $END$ + */ + +HB_FUNC( CHARSLIST ) +{ + ct_charlist( CT_CHARLIST_CHARSLIST ); +} + +/* $DOC$ + * $FUNCNAME$ + * CHARHIST() + * $CATEGORY$ + * CT3 string functions + * $ONELINER$ + * Generates a character histogram of a string + * $SYNTAX$ + * CHARHIST ([]) -> aCharacterCount + * $ARGUMENTS$ + * [] is the string for whom the function generates a + * character histogram + * Default: "" (empty string) + * $RETURNS$ + * an array with 256 elements where the nth element + * contains the count of character #(n-1) in cString + * $DESCRIPTION$ + * The CHARHIST() function generates a character histogram of those + * characters that are contained in . This histogram is stored + * in an 256-element array where the nth element contains the count + * of ASCII character #(n-1) in . + * $EXAMPLES$ + * ? charhist ("Hello World !")[109] --> 3 // chr(108)=="l" + * $TESTS$ + * charhist ("Hello World !")[109] == 3 + * eval ({||aeval (charhist ("Hello World !"),{|x|nTotal+=x}),nTotal==len("Hello World !")} + * $STATUS$ + * Ready + * $COMPLIANCE$ + * CHARHIST() is only available in Harbour's CT3 library. + * $PLATFORMS$ + * All + * $FILES$ + * Source is charlist.c, library is libct. + * $SEEALSO$ + * CHARLIST(),CHARNOLIST(),CHARSLIST() + * $END$ + */ + +HB_FUNC( CHARHIST ) +{ + ct_charlist( CT_CHARLIST_CHARHIST ); +} diff --git a/harbour/contrib/hbct/charlist.c b/harbour/contrib/hbct/charlist.c index 076f1cdd02..6722093697 100644 --- a/harbour/contrib/hbct/charlist.c +++ b/harbour/contrib/hbct/charlist.c @@ -6,9 +6,7 @@ * Harbour Project source code: * CT3 string functions * - CHARLIST() - * - CHARSLIST() (NEW) * - CHARNOLIST() - * - CHARHIST() (NEW) * * Copyright 2001 IntTec GmbH, Neunlindenstr 32, 79106 Freiburg, Germany * Author: Martin Vogel @@ -58,109 +56,77 @@ #include "ct.h" -/* defines */ -#define DO_LIST_CHARLIST 0 -#define DO_LIST_CHARNOLIST 1 -#define DO_LIST_CHARHIST 2 -#define DO_LIST_CHARSLIST 3 - /* helper function for the list function */ -static void do_list( int iSwitch ) +void ct_charlist( int iMode ) { - const char *pcString; - HB_SIZE sStrLen; + const char * pcString = hb_parcx( 1 ); + HB_SIZE sStrLen = hb_parclen( 1 ); - HB_SIZE asCharCnt[256]; + HB_SIZE asCharCnt[ 256 ]; HB_SIZE sCnt; /* init asCharCnt */ - for( sCnt = 0; sCnt < 256; sCnt++ ) - { - asCharCnt[sCnt] = 0; - } - - /* init params */ - if( HB_ISCHAR( 1 ) ) - { - pcString = hb_parc( 1 ); - sStrLen = hb_parclen( 1 ); - } - else - { - pcString = ""; - sStrLen = 0; - } + for( sCnt = 0; sCnt < HB_SIZEOFARRAY( asCharCnt ); ++sCnt ) + asCharCnt[ sCnt ] = 0; /* count characters */ - if( iSwitch == DO_LIST_CHARLIST ) + if( iMode == CT_CHARLIST_CHARLIST ) { - char pcRet[256]; + char pcRet[ 256 ]; HB_SIZE sRetStrLen = 0; - for( sCnt = 0; sCnt < sStrLen; sCnt++ ) + for( sCnt = 0; sCnt < sStrLen; ++sCnt ) { - if( asCharCnt[( HB_SIZE ) ( pcString[sCnt] )] == 0 ) + if( asCharCnt[ ( HB_UCHAR ) pcString[ sCnt ] ] == 0 ) { - pcRet[sRetStrLen++] = pcString[sCnt]; - asCharCnt[( HB_SIZE ) ( pcString[sCnt] )] = 1; + pcRet[ sRetStrLen++ ] = pcString[ sCnt ]; + asCharCnt[ ( HB_UCHAR ) pcString[ sCnt ] ] = 1; } } hb_retclen( pcRet, sRetStrLen ); } else { - for( sCnt = 0; sCnt < sStrLen; sCnt++ ) - { - HB_SIZE sIndex = ( HB_SIZE ) ( unsigned char ) ( *( pcString + sCnt ) ); - asCharCnt[sIndex] = asCharCnt[sIndex] + 1; - } + for( sCnt = 0; sCnt < sStrLen; ++sCnt ) + asCharCnt[ ( HB_UCHAR ) pcString[ sCnt ] ]++; - switch ( iSwitch ) + switch( iMode ) { - case DO_LIST_CHARSLIST: + case CT_CHARLIST_CHARSLIST: { - char *pcRet; + char * pcRet = ( char * ) hb_xgrab( HB_SIZEOFARRAY( asCharCnt ) ); HB_SIZE sRetStrLen = 0; - pcRet = ( char * ) hb_xgrab( 256 ); - - for( sCnt = 0; sCnt < 256; sCnt++ ) + for( sCnt = 0; sCnt < HB_SIZEOFARRAY( asCharCnt ); ++sCnt ) { - if( asCharCnt[sCnt] != 0 ) - pcRet[ sRetStrLen++ ] = ( unsigned char ) sCnt; + if( asCharCnt[ sCnt ] != 0 ) + pcRet[ sRetStrLen++ ] = ( HB_UCHAR ) sCnt; } - hb_retclen( pcRet, sRetStrLen ); - hb_xfree( pcRet ); + hb_retclen_buffer( pcRet, sRetStrLen ); break; } - - case DO_LIST_CHARNOLIST: + case CT_CHARLIST_CHARNOLIST: { - char *pcRet; + char * pcRet = ( char * ) hb_xgrab( HB_SIZEOFARRAY( asCharCnt ) ); HB_SIZE sRetStrLen = 0; - pcRet = ( char * ) hb_xgrab( 256 ); - - for( sCnt = 0; sCnt < 256; sCnt++ ) + for( sCnt = 0; sCnt < HB_SIZEOFARRAY( asCharCnt ); ++sCnt ) { - if( asCharCnt[sCnt] == 0 ) - { - *( pcRet + sRetStrLen ) = ( unsigned char ) sCnt; - sRetStrLen++; - } + if( asCharCnt[ sCnt ] == 0 ) + pcRet[ sRetStrLen++ ] = ( HB_UCHAR ) sCnt; } - hb_retclen( pcRet, sRetStrLen ); - hb_xfree( pcRet ); + hb_retclen_buffer( pcRet, sRetStrLen ); break; } - case DO_LIST_CHARHIST: + case CT_CHARLIST_CHARHIST: { - PHB_ITEM pArray = hb_itemArrayNew( 256 ); + PHB_ITEM pArray = hb_itemArrayNew( HB_SIZEOFARRAY( asCharCnt ) ); + + for( sCnt = 0; sCnt < HB_SIZEOFARRAY( asCharCnt ); ++sCnt ) + hb_arraySetNS( pArray, sCnt + 1, asCharCnt[ sCnt ] ); - for( sCnt = 0; sCnt < 256; sCnt++ ) - hb_arraySetNS( pArray, sCnt + 1, asCharCnt[sCnt] ); hb_itemReturnRelease( pArray ); break; } @@ -209,52 +175,7 @@ static void do_list( int iSwitch ) HB_FUNC( CHARLIST ) { - do_list( DO_LIST_CHARLIST ); -} - - -/* $DOC$ - * $FUNCNAME$ - * CHARSLIST() - * $CATEGORY$ - * CT3 string functions - * $ONELINER$ - * Generates a sorted list of all characters in a string - * $SYNTAX$ - * CHARSLIST ([]) -> cSortedCharacterList - * $ARGUMENTS$ - * [] is the string for whom the function generates a - * sorted list of all characters - * Default: "" (empty string) - * $RETURNS$ - * a sorted list of the characters in - * $DESCRIPTION$ - * The CHARLIST() function generates a sorted list of those characters that - * are contained in . This list can contain each character - * only once, so that its maximum length is 256. The function - * gives the same result as CHARSORT(CHARLIST()) - * $EXAMPLES$ - * ? charslist ("Hello World !") --> " !HWdelor" - * $TESTS$ - * charslist ("Hello World !") == " !HWdelor" - * charslist ("Hello World !") == charsort (charlist ("Hello World !")) - * charslist (nil) == "" - * $STATUS$ - * Ready - * $COMPLIANCE$ - * CHARSLIST() is only available in Harbour's CT3 library. - * $PLATFORMS$ - * All - * $FILES$ - * Source is charlist.c, library is libct. - * $SEEALSO$ - * CHARNOLIST(),CHARLIST(),CHARHIST() - * $END$ - */ - -HB_FUNC( CHARSLIST ) -{ - do_list( DO_LIST_CHARSLIST ); + ct_charlist( CT_CHARLIST_CHARLIST ); } @@ -298,50 +219,5 @@ HB_FUNC( CHARSLIST ) HB_FUNC( CHARNOLIST ) { - do_list( DO_LIST_CHARNOLIST ); -} - - -/* $DOC$ - * $FUNCNAME$ - * CHARHIST() - * $CATEGORY$ - * CT3 string functions - * $ONELINER$ - * Generates a character histogram of a string - * $SYNTAX$ - * CHARHIST ([]) -> aCharacterCount - * $ARGUMENTS$ - * [] is the string for whom the function generates a - * character histogram - * Default: "" (empty string) - * $RETURNS$ - * an array with 256 elements where the nth element - * contains the count of character #(n-1) in cString - * $DESCRIPTION$ - * The CHARHIST() function generates a character histogram of those - * characters that are contained in . This histogram is stored - * in an 256-element array where the nth element contains the count - * of ASCII character #(n-1) in . - * $EXAMPLES$ - * ? charhist ("Hello World !")[109] --> 3 // chr(108)=="l" - * $TESTS$ - * charhist ("Hello World !")[109] == 3 - * eval ({||aeval (charhist ("Hello World !"),{|x|nTotal+=x}),nTotal==len("Hello World !")} - * $STATUS$ - * Ready - * $COMPLIANCE$ - * CHARHIST() is only available in Harbour's CT3 library. - * $PLATFORMS$ - * All - * $FILES$ - * Source is charlist.c, library is libct. - * $SEEALSO$ - * CHARLIST(),CHARNOLIST(),CHARSLIST() - * $END$ - */ - -HB_FUNC( CHARHIST ) -{ - do_list( DO_LIST_CHARHIST ); + ct_charlist( CT_CHARLIST_CHARNOLIST ); } diff --git a/harbour/contrib/hbct/ct.h b/harbour/contrib/hbct/ct.h index edff9a0321..fe2802cbd3 100644 --- a/harbour/contrib/hbct/ct.h +++ b/harbour/contrib/hbct/ct.h @@ -77,6 +77,14 @@ HB_EXTERN_BEGIN +/* ct_charlist() modes */ +#define CT_CHARLIST_CHARLIST 0 +#define CT_CHARLIST_CHARNOLIST 1 +#define CT_CHARLIST_CHARHIST 2 +#define CT_CHARLIST_CHARSLIST 3 + +extern void ct_charlist( int iMode ); + /* CT subsystem error throwing functions */ extern HB_USHORT ct_error( HB_USHORT uiSeverity, HB_ERRCODE ulGenCode, HB_ERRCODE ulSubCode, const char *szDescription, const char *szOperation, HB_ERRCODE uiOsCode, HB_USHORT uiFlags, HB_ULONG uiArgCount, ... ); diff --git a/harbour/contrib/hbct/hbct.hbp b/harbour/contrib/hbct/hbct.hbp index 345f75fdb8..674c70f299 100644 --- a/harbour/contrib/hbct/hbct.hbp +++ b/harbour/contrib/hbct/hbct.hbp @@ -19,6 +19,7 @@ atrepl.c bitnum.c blank.c charevod.c +charlish.c charlist.c charmirr.c charmix.c