From 7ec3746550d4247d81744098876c5e749c3970eb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 24 Nov 2012 15:51:28 +0000 Subject: [PATCH] 2012-11-24 16:48 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbgt/hbgt.hbp * contrib/hbgt/hbgt.hbx * contrib/hbgt/asciisgt.c * contrib/hbgt/ascposgt.c * contrib/hbgt/atdiff.c * contrib/hbgt/bitflags.c * contrib/hbgt/chareven.c * contrib/hbgt/charmixg.c * contrib/hbgt/charodd.c * contrib/hbgt/chrcount.c * contrib/hbgt/chrfirst.c * contrib/hbgt/chrtotal.c * contrib/hbgt/strasint.c * contrib/hbgt/strcount.c * contrib/hbgt/strcspn.c * contrib/hbgt/strdiffg.c * contrib/hbgt/strexpan.c * contrib/hbgt/strleft.c * contrib/hbgt/strpbrk.c * contrib/hbgt/strright.c * contrib/hbgt/doc/en/hbgt.txt * code cleanup and optimizations + fixed flag functions (they wrote to read-only buffer) + enabled flag functions --- harbour/ChangeLog | 26 +++++++ harbour/contrib/hbgt/asciisgt.c | 1 - harbour/contrib/hbgt/ascposgt.c | 11 +-- harbour/contrib/hbgt/atdiff.c | 13 +--- harbour/contrib/hbgt/bitflags.c | 106 +++++++++------------------ harbour/contrib/hbgt/chareven.c | 13 +--- harbour/contrib/hbgt/charmixg.c | 21 ++---- harbour/contrib/hbgt/charodd.c | 18 ++--- harbour/contrib/hbgt/chrcount.c | 15 ++-- harbour/contrib/hbgt/chrfirst.c | 21 ++---- harbour/contrib/hbgt/chrtotal.c | 17 ++--- harbour/contrib/hbgt/doc/en/hbgt.txt | 64 ++++++++-------- harbour/contrib/hbgt/hbgt.hbp | 1 + harbour/contrib/hbgt/hbgt.hbx | 4 + harbour/contrib/hbgt/strasint.c | 1 + harbour/contrib/hbgt/strcount.c | 17 ++--- harbour/contrib/hbgt/strcspn.c | 17 ++--- harbour/contrib/hbgt/strdiffg.c | 13 +--- harbour/contrib/hbgt/strexpan.c | 26 ++----- harbour/contrib/hbgt/strleft.c | 18 ++--- harbour/contrib/hbgt/strpbrk.c | 21 ++---- harbour/contrib/hbgt/strright.c | 18 ++--- 22 files changed, 180 insertions(+), 282 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f511d89914..435306413d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -10,6 +10,32 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2012-11-24 16:48 UTC+0100 Viktor Szakats (harbour syenar.net) + * contrib/hbgt/hbgt.hbp + * contrib/hbgt/hbgt.hbx + * contrib/hbgt/asciisgt.c + * contrib/hbgt/ascposgt.c + * contrib/hbgt/atdiff.c + * contrib/hbgt/bitflags.c + * contrib/hbgt/chareven.c + * contrib/hbgt/charmixg.c + * contrib/hbgt/charodd.c + * contrib/hbgt/chrcount.c + * contrib/hbgt/chrfirst.c + * contrib/hbgt/chrtotal.c + * contrib/hbgt/strasint.c + * contrib/hbgt/strcount.c + * contrib/hbgt/strcspn.c + * contrib/hbgt/strdiffg.c + * contrib/hbgt/strexpan.c + * contrib/hbgt/strleft.c + * contrib/hbgt/strpbrk.c + * contrib/hbgt/strright.c + * contrib/hbgt/doc/en/hbgt.txt + * code cleanup and optimizations + + fixed flag functions (they wrote to read-only buffer) + + enabled flag functions + 2012-11-24 15:20 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbct/addascii.c * contrib/hbct/asciisum.c diff --git a/harbour/contrib/hbgt/asciisgt.c b/harbour/contrib/hbgt/asciisgt.c index e5ced7cbe4..0c8c4a1ec0 100644 --- a/harbour/contrib/hbgt/asciisgt.c +++ b/harbour/contrib/hbgt/asciisgt.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: asciisum.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 diff --git a/harbour/contrib/hbgt/ascposgt.c b/harbour/contrib/hbgt/ascposgt.c index 41047017ba..3791917a62 100644 --- a/harbour/contrib/hbgt/ascposgt.c +++ b/harbour/contrib/hbgt/ascposgt.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: ascpos.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,13 +20,11 @@ HB_FUNC( GT_ASCPOS ) { - const char * s; - HB_SIZE p; - if( HB_ISCHAR( 1 ) && HB_ISNUM( 2 ) ) { - s = hb_parc( 1 ); - p = hb_parns( 2 ); + const char * s = hb_parc( 1 ); + HB_SIZE p = hb_parns( 2 ); + p--; /* decrement p to adjust for c strings */ /* starting at position 0 */ @@ -38,7 +35,5 @@ HB_FUNC( GT_ASCPOS ) /* character in string */ } else - { hb_retni( -1 ); /* parameter mismatch - error -1 */ - } } diff --git a/harbour/contrib/hbgt/atdiff.c b/harbour/contrib/hbgt/atdiff.c index 46ea3af2f8..bb717c736f 100644 --- a/harbour/contrib/hbgt/atdiff.c +++ b/harbour/contrib/hbgt/atdiff.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: atdiff.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,14 +20,12 @@ HB_FUNC( GT_ATDIFF ) { - const char * s1, * s2; - HB_ISIZ pos, len; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - s1 = hb_parc( 1 ); - s2 = hb_parc( 2 ); - len = hb_parclen( 2 ); + const char * s1 = hb_parc( 1 ); + const char * s2 = hb_parc( 2 ); + HB_ISIZ len = hb_parclen( 2 ); + HB_ISIZ pos; /* loop through comparing both strings @@ -46,7 +43,5 @@ HB_FUNC( GT_ATDIFF ) hb_retns( pos ); } else - { hb_retns( -1 ); /* parameter mismatch - error -1 */ - } } diff --git a/harbour/contrib/hbgt/bitflags.c b/harbour/contrib/hbgt/bitflags.c index 5f14433d4b..513cb2b603 100644 --- a/harbour/contrib/hbgt/bitflags.c +++ b/harbour/contrib/hbgt/bitflags.c @@ -3,7 +3,6 @@ */ /* - * File......: BITFLAGS.C * Author....: Dave Pearson * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -25,64 +24,44 @@ * */ - #include "hbapi.h" - -#define _GT_MAX( x, y ) ( x > y ? x : y ) +#include "hbapiitm.h" HB_FUNC( GT_NEWFLAG ) { - char * FlagString; - unsigned ByteCount; - unsigned FlagCount = 1; - unsigned Byte; + unsigned FlagCount = ( unsigned ) hb_parnidef( 1, 1 ); - if( ISNUM( 1 ) ) - { - FlagCount = ( unsigned ) hb_parni( 1 ); - } if( FlagCount > 0 ) { - ByteCount = ( unsigned ) ( ( FlagCount / 8 ) + 1 ); + char * FlagString; + unsigned ByteCount = ( unsigned ) ( ( FlagCount / 8 ) + 1 ); + unsigned Byte; + if( ! ( FlagCount % 8 ) ) - { --ByteCount; - } - FlagString = hb_xgrab( ByteCount ); + FlagString = ( char * ) hb_xgrab( ByteCount ); for( Byte = 0; Byte < ByteCount; Byte++ ) - { FlagString[ Byte ] = 0; - } hb_retclen( FlagString, ByteCount ); hb_xfree( FlagString ); } else - { hb_retc_null(); - } } HB_FUNC( GT_SETFLAG ) { - char * FlagString; - unsigned StartBit = 1; - unsigned EndBit = 1; - unsigned BitCount; - unsigned BitPointer; - unsigned BytePointer; - if( HB_ISCHAR( 1 ) ) { - FlagString = hb_parc( 1 ); - if( HB_ISNUM( 2 ) ) - { - StartBit = hb_parni( 2 ); - } - if( HB_ISNUM( 3 ) ) - { - EndBit = hb_parni( 3 ); - } - EndBit = _GT_MAX( StartBit, EndBit ); + char * FlagString = hb_itemGetC( hb_param( 1, HB_IT_STRING ) ); + unsigned StartBit = hb_parnidef( 2, 1 ); + unsigned EndBit = hb_parnidef( 3, 1 ); + unsigned BitCount; + unsigned BitPointer; + unsigned BytePointer; + + EndBit = HB_MAX( StartBit, EndBit ); + if( StartBit > 0 && EndBit <= ( hb_parclen( 1 ) * 8 ) ) { for( BitCount = StartBit; BitCount <= EndBit; BitCount++ ) @@ -97,35 +76,25 @@ HB_FUNC( GT_SETFLAG ) FlagString[ BytePointer ] |= 1 << ( BitPointer - 1 ); } } - hb_retclen( FlagString, hb_parclen( 1 ) ); + hb_retclen_buffer( FlagString, hb_parclen( 1 ) ); } else - { hb_retc_null(); - } } HB_FUNC( GT_CLRFLAG ) { - char * FlagString; - unsigned StartBit = 1; - unsigned EndBit = 1; - unsigned BitCount; - unsigned BitPointer; - unsigned BytePointer; - if( HB_ISCHAR( 1 ) ) { - FlagString = hb_parc( 1 ); - if( HB_ISNUM( 2 ) ) - { - StartBit = hb_parni( 2 ); - } - if( HB_ISNUM( 3 ) ) - { - EndBit = hb_parni( 3 ); - } - EndBit = _GT_MAX( StartBit, EndBit ); + char * FlagString = hb_itemGetC( hb_param( 1, HB_IT_STRING ) ); + unsigned StartBit = hb_parnidef( 2, 1 ); + unsigned EndBit = hb_parnidef( 3, 1 ); + unsigned BitCount; + unsigned BitPointer; + unsigned BytePointer; + + EndBit = HB_MAX( StartBit, EndBit ); + if( StartBit > 0 && EndBit <= ( hb_parclen( 1 ) * 8 ) ) { for( BitCount = StartBit; BitCount <= EndBit; BitCount++ ) @@ -140,30 +109,23 @@ HB_FUNC( GT_CLRFLAG ) FlagString[ BytePointer ] &= 0xff - ( 1 << ( BitPointer - 1 ) ); } } - hb_retclen( FlagString, hb_parclen( 1 ) ); + hb_retclen_buffer( FlagString, hb_parclen( 1 ) ); } else - { hb_retc_null(); - } } -HB_FUNC( GT_ISFLAG ) +HB_FUNC( GT_ISFLAG ) { - - HB_BOOL FlagStatus = HB_FALSE; - unsigned Bit = 1; - unsigned BitPointer; - unsigned BytePointer; - char * FlagString; + HB_BOOL FlagStatus = HB_FALSE; if( HB_ISCHAR( 1 ) ) { - FlagString = hb_parc( 1 ); - if( HB_ISNUM( 2 ) ) - { - Bit = hb_parni( 2 ); - } + unsigned Bit = hb_parnidef( 2, 1 ); + unsigned BitPointer; + unsigned BytePointer; + const char * FlagString = hb_parc( 1 ); + if( Bit > 0 && Bit <= ( hb_parclen( 1 ) * 8 ) ) { BitPointer = Bit % 8; diff --git a/harbour/contrib/hbgt/chareven.c b/harbour/contrib/hbgt/chareven.c index 6641b29f8f..38802f2991 100644 --- a/harbour/contrib/hbgt/chareven.c +++ b/harbour/contrib/hbgt/chareven.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: chareven.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,14 +20,12 @@ HB_FUNC( GT_CHAREVEN ) { - const char * s1; - char * s2; - HB_ISIZ len, i; - if( HB_ISCHAR( 1 ) ) { - s1 = hb_parc( 1 ); - len = hb_parclen( 1 ); + const char * s1 = hb_parc( 1 ); + char * s2; + HB_ISIZ len = hb_parclen( 1 ); + HB_ISIZ i; s2 = ( char * ) hb_xgrab( len / 2 + 1 ); /* grab us some mem to work with */ @@ -38,7 +35,5 @@ HB_FUNC( GT_CHAREVEN ) hb_retclen_buffer( s2, len / 2 ); } else - { hb_retc_null(); /* parameter mismatch - error NullStr */ - } } diff --git a/harbour/contrib/hbgt/charmixg.c b/harbour/contrib/hbgt/charmixg.c index 70ad274604..82a775ba2c 100644 --- a/harbour/contrib/hbgt/charmixg.c +++ b/harbour/contrib/hbgt/charmixg.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: charmix.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,17 +20,14 @@ HB_FUNC( GT_CHARMIX ) { - const char * s1, * s2; - char * s3; - HB_ISIZ l1, l2, i, pos3; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - s1 = hb_parc( 1 ); - s2 = hb_parc( 2 ); - l1 = hb_parclen( 1 ); - l2 = hb_parclen( 2 ); - pos3 = 0; + const char * s1 = hb_parc( 1 ); + const char * s2 = hb_parc( 2 ); + HB_ISIZ l1 = hb_parclen( 1 ); + HB_ISIZ l2 = hb_parclen( 2 ); + char * s3; + HB_ISIZ i, pos3 = 0; s3 = ( char * ) hb_xgrab( l1 + l2 + 1 ); /* grab us some mem to work with */ @@ -48,11 +44,8 @@ HB_FUNC( GT_CHARMIX ) s3[ pos3++ ] = s2[ i ]; s3[ pos3 ] = '\0'; - hb_retclen( s3, l1 + l2 ); - hb_xfree( s3 ); /* free alloc'ed mem */ + hb_retclen_buffer( s3, l1 + l2 ); } else - { hb_retc_null(); /* parameter mismatch - error NullStr */ - } } diff --git a/harbour/contrib/hbgt/charodd.c b/harbour/contrib/hbgt/charodd.c index 8217e64191..c1c9ccc735 100644 --- a/harbour/contrib/hbgt/charodd.c +++ b/harbour/contrib/hbgt/charodd.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: charodd.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,25 +20,20 @@ HB_FUNC( GT_CHARODD ) { - const char * s1; - char * s2; - HB_ISIZ len, i; - if( HB_ISCHAR( 1 ) ) { - s1 = hb_parc( 1 ); - len = hb_parclen( 1 ); + const char * s1 = hb_parc( 1 ); + char * s2; + HB_ISIZ len = hb_parclen( 1 ); + HB_ISIZ i; - s2 = ( char * ) hb_xgrab( len / 2 ); /* grab us some mem to work with */ + s2 = ( char * ) hb_xgrab( len / 2 + 1 ); /* grab us some mem to work with */ for( i = 0; i <= len; i += 2 ) s2[ i / 2 ] = s1[ i ] & 0x7f; - hb_retclen( s2, len ); - hb_xfree( s2 ); /* free alloc'ed mem */ + hb_retclen_buffer( s2, len / 2 ); } else - { hb_retc_null(); /* parameter mismatch - error NullStr */ - } } diff --git a/harbour/contrib/hbgt/chrcount.c b/harbour/contrib/hbgt/chrcount.c index c71a8bca9a..7d8f0c1504 100644 --- a/harbour/contrib/hbgt/chrcount.c +++ b/harbour/contrib/hbgt/chrcount.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: chrcount.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,14 +20,12 @@ HB_FUNC( GT_CHRCOUNT ) { - const char * s1, * s2; - HB_ISIZ count, pos2, len; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - s1 = hb_parc( 1 ); - s2 = hb_parc( 2 ); - len = hb_parclen( 2 ); + const char * s1 = hb_parc( 1 ); + const char * s2 = hb_parc( 2 ); + HB_ISIZ len = hb_parclen( 2 ); + HB_ISIZ count, pos2; /* loop through s2 matching passed character (s1) with each character of s1 */ @@ -40,7 +37,5 @@ HB_FUNC( GT_CHRCOUNT ) hb_retns( count ); /* return result */ } else - { - hb_retns( -1 ); /* parameter mismatch - error -1 */ - } + hb_retns( -1 ); /* parameter mismatch - error -1 */ } diff --git a/harbour/contrib/hbgt/chrfirst.c b/harbour/contrib/hbgt/chrfirst.c index dd5bc81aa3..ce2e0246cc 100644 --- a/harbour/contrib/hbgt/chrfirst.c +++ b/harbour/contrib/hbgt/chrfirst.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: chrfirst.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,18 +20,15 @@ HB_FUNC( GT_CHRFIRST ) { - const char * string; - const char * cset; - HB_ISIZ l1, l2; - HB_ISIZ p1, p2; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - string = hb_parc( 2 ); - cset = hb_parc( 1 ); - l1 = hb_parclen( 2 ); - l2 = hb_parclen( 1 ); - p1 = p2 = 0; + const char * string = hb_parc( 2 ); + const char * cset = hb_parc( 1 ); + HB_ISIZ l1 = hb_parclen( 2 ); + HB_ISIZ l2 = hb_parclen( 1 ); + HB_ISIZ p1, p2; + + p1 = p2 = 0; do { @@ -48,10 +44,7 @@ HB_FUNC( GT_CHRFIRST ) if( p2 >= l2 ) hb_retni( 0 ); - } else - { hb_retni( -1 ); /* parameter mismatch - error NullStr */ - } } diff --git a/harbour/contrib/hbgt/chrtotal.c b/harbour/contrib/hbgt/chrtotal.c index 868b8987e1..329fba06fc 100644 --- a/harbour/contrib/hbgt/chrtotal.c +++ b/harbour/contrib/hbgt/chrtotal.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: chrtotal.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,15 +20,13 @@ HB_FUNC( GT_CHRTOTAL ) { - const char * s1, * s2; - HB_ISIZ count, p1, p2, l2, l1; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - s1 = hb_parc( 1 ); - s2 = hb_parc( 2 ); - l2 = hb_parclen( 2 ); - l1 = hb_parclen( 1 ); + const char * s1 = hb_parc( 1 ); + const char * s2 = hb_parc( 2 ); + HB_ISIZ l1 = hb_parclen( 1 ); + HB_ISIZ l2 = hb_parclen( 2 ); + HB_ISIZ count, p1, p2; for( count = 0, p2 = 0; p2 < l2; p2++ ) for( p1 = 0; p1 < l1; p1++ ) @@ -40,7 +37,5 @@ HB_FUNC( GT_CHRTOTAL ) hb_retns( count ); /* return result */ } else - { - hb_retns( -1 ); /* parameter mismatch - error -1 */ - } + hb_retns( -1 ); /* parameter mismatch - error -1 */ } diff --git a/harbour/contrib/hbgt/doc/en/hbgt.txt b/harbour/contrib/hbgt/doc/en/hbgt.txt index 7c746bcdba..e17898778f 100644 --- a/harbour/contrib/hbgt/doc/en/hbgt.txt +++ b/harbour/contrib/hbgt/doc/en/hbgt.txt @@ -556,44 +556,44 @@ /* $DOC$ $NAME$ - GT_NEWFLAG() + gt_NewFlag() $CATEGORY$ General $ONELINER$ Create a new bit flag string. $SYNTAX$ - GT_NewFlag() --> cFlagString + gt_NewFlag() --> cFlagString $ARGUMENTS$ is the number of flags you wish to store. $RETURNS$ A string to hold the bit flags. All flags are set to FALSE. $DESCRIPTION$ - GT_NewFlag() is used to construct a bit flag string. The bit flag + gt_NewFlag() is used to construct a bit flag string. The bit flag functions can be used for storing a large number of logical values in a small space. - To create a bit flag string you need to pass GT_NewFlag() a value + To create a bit flag string you need to pass gt_NewFlag() a value that is equal to or greater than the number of flags required (you may want to allow for future expansion). Each character in the - string returned from GT_NewFlag() will hold 8 logical values. + string returned from gt_NewFlag() will hold 8 logical values. $EXAMPLES$ - cFlags := GT_NewFlag( 20 ) // Create a bit flag string for 20 logical values. + cFlags := gt_NewFlag( 20 ) // Create a bit flag string for 20 logical values. $SEEALSO$ - GT_SETFLAG() GT_CLRFLAG() GT_ISFLAG() + gt_SetFlag() gt_ClrFlag() gt_IsFlag() $END$ */ /* $DOC$ $NAME$ - GT_SETFLAG() + gt_SetFlag() $CATEGORY$ General $ONELINER$ Set a number of flags to TRUE in a bit flag string. $SYNTAX$ - GT_SetFlag(,[],[]) --> cFlagString + gt_SetFlag(,[],[]) --> cFlagString $ARGUMENTS$ - is a bit flag string created with GT_NewFlag() + is a bit flag string created with gt_NewFlag() is the starting flag. This is an optional numeric value. If not supplied it defaults to 1. @@ -603,38 +603,38 @@ $RETURNS$ The bit map string with the new flag settings. $DESCRIPTION$ - GT_SetFlag() is used to turn flags within the flag string on. + gt_SetFlag() is used to turn flags within the flag string on. $EXAMPLES$ - cFlags := GT_NewFlag( 20 ) // Create a bit flag string for 20 + cFlags := gt_NewFlag( 20 ) // Create a bit flag string for 20 // logical values. // Now set flags 10 to 15 to true. - cFlags := GT_SetFlag( cFlags, 10, 15 ) + cFlags := gt_SetFlag( cFlags, 10, 15 ) // And set flag 18 to true. - cFlags := GT_SetFlag( cFlags, 18 ) + cFlags := gt_SetFlag( cFlags, 18 ) // And set flag 1 to true. - cFlags := GT_SetFlag( cFlags ) + cFlags := gt_SetFlag( cFlags ) $SEEALSO$ - GT_NEWFLAG() GT_CLRFLAG() GT_ISFLAG() + gt_NewFlag() gt_ClrFlag() gt_IsFlag() $END$ */ /* $DOC$ $NAME$ - GT_CLRFLAG() + gt_ClrFlag() $CATEGORY$ General $ONELINER$ Set a number of flags to FALSE in a bit flag string. $SYNTAX$ - GT_ClrFlag(,[],[]) --> cFlagString + gt_ClrFlag(,[],[]) --> cFlagString $ARGUMENTS$ - is a bit flag string created with GT_NewFlag() + is a bit flag string created with gt_NewFlag() is the starting flag. This is an optional numeric value. If not supplied it defaults to 1. @@ -644,56 +644,56 @@ $RETURNS$ The bit map string with the new flag settings. $DESCRIPTION$ - GT_ClrFlag() is used to turn flags within the flag string off. + gt_ClrFlag() is used to turn flags within the flag string off. $EXAMPLES$ - cFlags := GT_NewFlag( 20 ) // Create a bit flag string for 20 + cFlags := gt_NewFlag( 20 ) // Create a bit flag string for 20 // logical values. // Now, turn them all on. - cFlags := GT_SetFlag( cFlags, 1, 20 ) + cFlags := gt_SetFlag( cFlags, 1, 20 ) // Now set flags 10 to 15 to false. - cFlags := GT_ClrFlag( cFlags, 10, 15 ) + cFlags := gt_ClrFlag( cFlags, 10, 15 ) // And set flag 18 to false. - cFlags := GT_ClrFlag( cFlags, 18 ) + cFlags := gt_ClrFlag( cFlags, 18 ) // And set flag 1 to false. - cFlags := GT_ClrFlag( cFlags ) + cFlags := gt_ClrFlag( cFlags ) $SEEALSO$ - GT_NEWFLAG() GT_SETFLAG() GT_ISFLAG() + gt_NewFlag() gt_SetFlag() gt_IsFlag() $END$ */ /* $DOC$ $NAME$ - GT_ISFLAG() + gt_IsFlag() $CATEGORY$ General $ONELINER$ Test the setting of a flag in a bit flag string. $SYNTAX$ - GT_IsFlag(,[]) --> lSetting + gt_IsFlag(,[]) --> lSetting $ARGUMENTS$ - is a bit flag string created with GT_NewFlag() + is a bit flag string created with gt_NewFlag() is the flag to be tested. $RETURNS$ A boolean value, TRUE if the flag is on, FALSE if it's off. $DESCRIPTION$ - GT_IsFlag() is used to test the state of a flag with a bit flag + gt_IsFlag() is used to test the state of a flag with a bit flag string. $EXAMPLES$ // Print the setting of the flags in a flag string called ``cDave'' FOR nFlag := 1 to ( Len( cDave ) * 8 ) - ? "Flag number ", nFlag, " == ", GT_IsFlag( cDave, nFlag ) + ? "Flag number ", nFlag, " == ", gt_IsFlag( cDave, nFlag ) NEXT $SEEALSO$ - GT_NEWFLAG() GT_SETFLAG() GT_CLRFLAG() + gt_NewFlag() gt_SetFlag() gt_ClrFlag() $END$ */ diff --git a/harbour/contrib/hbgt/hbgt.hbp b/harbour/contrib/hbgt/hbgt.hbp index 4893f3943f..27b564fe40 100644 --- a/harbour/contrib/hbgt/hbgt.hbp +++ b/harbour/contrib/hbgt/hbgt.hbp @@ -14,6 +14,7 @@ hbgt.hbx asciisgt.c ascposgt.c atdiff.c +bitflags.c chareven.c charmixg.c charodd.c diff --git a/harbour/contrib/hbgt/hbgt.hbx b/harbour/contrib/hbgt/hbgt.hbx index ef99c3fa3b..8472331d4a 100644 --- a/harbour/contrib/hbgt/hbgt.hbx +++ b/harbour/contrib/hbgt/hbgt.hbx @@ -30,6 +30,10 @@ DYNAMIC gt_CharOdd DYNAMIC gt_ChrCount DYNAMIC gt_ChrFirst DYNAMIC gt_ChrTotal +DYNAMIC gt_ClrFlag +DYNAMIC gt_IsFlag +DYNAMIC gt_NewFlag +DYNAMIC gt_SetFlag DYNAMIC gt_StrCount DYNAMIC gt_StrCSPN DYNAMIC gt_StrDiff diff --git a/harbour/contrib/hbgt/strasint.c b/harbour/contrib/hbgt/strasint.c index 9cdc7449e1..47d8fc12ae 100644 --- a/harbour/contrib/hbgt/strasint.c +++ b/harbour/contrib/hbgt/strasint.c @@ -27,5 +27,6 @@ int _GT_Internal_StringAsInt( char * String, HB_ISIZ Start, HB_ISIZ End ) Decimal *= 0xA; } } + return Value; } diff --git a/harbour/contrib/hbgt/strcount.c b/harbour/contrib/hbgt/strcount.c index 25810d851b..78e33886bf 100644 --- a/harbour/contrib/hbgt/strcount.c +++ b/harbour/contrib/hbgt/strcount.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: strcount.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,16 +20,14 @@ HB_FUNC( GT_STRCOUNT ) { - const char * s1, * s2; - HB_ISIZ count, p1, p2, l1, l2; - int match; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - s1 = hb_parc( 1 ); - s2 = hb_parc( 2 ); - l1 = hb_parclen( 1 ); - l2 = hb_parclen( 2 ); + const char * s1 = hb_parc( 1 ); + const char * s2 = hb_parc( 2 ); + HB_ISIZ l1 = hb_parclen( 1 ); + HB_ISIZ l2 = hb_parclen( 2 ); + HB_ISIZ count, p1, p2; + int match; /* loop through s2 matching passed character (s1) with each character of s1 */ @@ -52,7 +49,5 @@ HB_FUNC( GT_STRCOUNT ) hb_retns( count ); /* return result */ } else - { hb_retns( -1 ); /* parameter mismatch - error -1 */ - } } diff --git a/harbour/contrib/hbgt/strcspn.c b/harbour/contrib/hbgt/strcspn.c index abc1d36445..e73a26d5b8 100644 --- a/harbour/contrib/hbgt/strcspn.c +++ b/harbour/contrib/hbgt/strcspn.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: strcspn.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,17 +20,13 @@ HB_FUNC( GT_STRCSPN ) { - const char * string; - const char * cset; - HB_ISIZ l1, l2; - HB_ISIZ p1, p2; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - string = hb_parc( 1 ); - cset = hb_parc( 2 ); - l1 = hb_parclen( 1 ); - l2 = hb_parclen( 2 ); + const char * string = hb_parc( 1 ); + const char * cset = hb_parc( 2 ); + HB_ISIZ l1 = hb_parclen( 1 ); + HB_ISIZ l2 = hb_parclen( 2 ); + HB_ISIZ p1, p2; for( p1 = 0; p1 < l1; ++p1 ) { @@ -44,7 +39,5 @@ HB_FUNC( GT_STRCSPN ) hb_retns( p1 ); } else - { hb_retns( -1 ); /* parameter mismatch - error -1 */ - } } diff --git a/harbour/contrib/hbgt/strdiffg.c b/harbour/contrib/hbgt/strdiffg.c index 3cfd511656..150844b3df 100644 --- a/harbour/contrib/hbgt/strdiffg.c +++ b/harbour/contrib/hbgt/strdiffg.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: strdiff.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,14 +20,12 @@ HB_FUNC( GT_STRDIFF ) { - const char * s1, * s2; - HB_ISIZ pos, len; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - s1 = hb_parc( 1 ); - s2 = hb_parc( 2 ); - len = hb_parclen( 2 ); + const char * s1 = hb_parc( 1 ); + const char * s2 = hb_parc( 2 ); + HB_ISIZ pos; + HB_ISIZ len = hb_parclen( 2 ); /* loop through comparing both strings @@ -46,7 +43,5 @@ HB_FUNC( GT_STRDIFF ) hb_retc( s2 ); } else - { hb_ret(); /* parameter mismatch - error return NIL */ - } } diff --git a/harbour/contrib/hbgt/strexpan.c b/harbour/contrib/hbgt/strexpan.c index 90c84a9d3e..833fb33c61 100644 --- a/harbour/contrib/hbgt/strexpan.c +++ b/harbour/contrib/hbgt/strexpan.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: strexpan.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,21 +20,15 @@ HB_FUNC( GT_STREXPAND ) { - const char * in; - char * out; - int nIns = 1; - const char * insert = " "; - HB_ISIZ len; - HB_ISIZ i, p; - int j; - if( HB_ISCHAR( 1 ) && ( HB_ISNUM( 2 ) || hb_pcount() < 2 ) && ( HB_ISCHAR( 3 ) || hb_pcount() < 3 ) ) { - in = hb_parc( 1 ); - len = hb_parclen( 1 ); - - if( HB_ISNUM( 2 ) ) - nIns = hb_parni( 2 ); + const char * in = hb_parc( 1 ); + char * out; + int nIns = hb_parnidef( 2, 1 ); + const char * insert = " "; + HB_ISIZ len = hb_parclen( 1 ); + HB_ISIZ i, p; + int j; if( HB_ISCHAR( 3 ) ) insert = hb_parc( 3 ); @@ -54,11 +47,8 @@ HB_FUNC( GT_STREXPAND ) } out[ p ] = '\0'; /* Add terminating NUL */ - hb_retc( out ); - hb_xfree( out ); /* free alloc'ed mem */ + hb_retc_buffer( out ); } else - { hb_retc_null(); /* parameter mismatch - error NullStr */ - } } diff --git a/harbour/contrib/hbgt/strleft.c b/harbour/contrib/hbgt/strleft.c index d1aa9d3f5d..f77ae59e98 100644 --- a/harbour/contrib/hbgt/strleft.c +++ b/harbour/contrib/hbgt/strleft.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: strleft.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,17 +20,13 @@ HB_FUNC( GT_STRLEFT ) { - const char * string; - const char * cset; - HB_ISIZ l1, l2; - HB_ISIZ p1, p2; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - string = hb_parc( 1 ); - cset = hb_parc( 2 ); - l1 = hb_parclen( 1 ); - l2 = hb_parclen( 2 ); + const char * string = hb_parc( 1 ); + const char * cset = hb_parc( 2 ); + HB_ISIZ l1 = hb_parclen( 1 ); + HB_ISIZ l2 = hb_parclen( 2 ); + HB_ISIZ p1, p2; for( p1 = 0; p1 < l1; p1++ ) { @@ -42,10 +37,7 @@ HB_FUNC( GT_STRLEFT ) break; } hb_retns( p1 ); - } else - { hb_retns( -1 ); /* parameter mismatch - error NullStr */ - } } diff --git a/harbour/contrib/hbgt/strpbrk.c b/harbour/contrib/hbgt/strpbrk.c index 032188482a..26e919e10d 100644 --- a/harbour/contrib/hbgt/strpbrk.c +++ b/harbour/contrib/hbgt/strpbrk.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: strpbrk.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,18 +20,15 @@ HB_FUNC( GT_STRPBRK ) { - const char * string; - const char * cset; - HB_ISIZ l1, l2; - HB_ISIZ p1, p2; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - string = hb_parc( 1 ); - cset = hb_parc( 2 ); - l1 = hb_parclen( 1 ); - l2 = hb_parclen( 2 ); - p1 = p2 = 0; + const char * string = hb_parc( 1 ); + const char * cset = hb_parc( 2 ); + HB_ISIZ l1 = hb_parclen( 1 ); + HB_ISIZ l2 = hb_parclen( 2 ); + HB_ISIZ p1, p2; + + p1 = p2 = 0; do { @@ -48,10 +44,7 @@ HB_FUNC( GT_STRPBRK ) if( p2 >= l2 ) hb_retc_null(); - } else - { hb_retc_null(); /* parameter mismatch - error NullStr */ - } } diff --git a/harbour/contrib/hbgt/strright.c b/harbour/contrib/hbgt/strright.c index d2d1202e16..6add857a93 100644 --- a/harbour/contrib/hbgt/strright.c +++ b/harbour/contrib/hbgt/strright.c @@ -5,7 +5,6 @@ /* * GT CLIPPER STANDARD HEADER * - * File......: strright.c * Author....: Andy M Leighton * BBS.......: The Dark Knight Returns * Net/Node..: 050/069 @@ -21,17 +20,13 @@ HB_FUNC( GT_STRRIGHT ) { - const char * string; - const char * cset; - HB_ISIZ l1, l2; - HB_ISIZ p1, p2; - if( HB_ISCHAR( 1 ) && HB_ISCHAR( 2 ) ) { - string = hb_parc( 1 ); - cset = hb_parc( 2 ); - l1 = hb_parclen( 1 ); - l2 = hb_parclen( 2 ); + const char * string = hb_parc( 1 ); + const char * cset = hb_parc( 2 ); + HB_ISIZ l1 = hb_parclen( 1 ); + HB_ISIZ l2 = hb_parclen( 2 ); + HB_ISIZ p1, p2; for( p1 = l1 - 1; p1 >= 0; p1-- ) { @@ -42,10 +37,7 @@ HB_FUNC( GT_STRRIGHT ) break; } hb_retns( l1 - p1 - 1 ); - } else - { hb_retns( -1 ); /* parameter mismatch - error NullStr */ - } }