Files
harbour-core/contrib/hbgt/bitflags.c
Viktor Szakats 5a2a287752 2017-09-08 16:00 UTC Viktor Szakats (vszakats users.noreply.github.com)
* *
    * partial sync with the 3.4 fork codebase. These are the things
      synces for the most part:
      - copyright headers
      - grammar/typos in comments and some readmes
      - comment/whitespace/decorations
      - variable scoping in C files
      - DO CASE/SWITCH and some other alternate syntax usage
      - minimal amount of human readable text in strings
      - minor code updates
      - HB_TRACE() void * casts for pointers and few other changes to
        avoid C compiler warnings
      - various other, minor code cleanups
      - only Harbour/C code/headers were touched in src, utils, contrib,
        include. No 3rd party code, no make files, and with just a few
        exceptions, no 'tests' code was touched.
      - certain components were not touched were 3.4 diverged too much
        already, like f.e. hbmk2, hbssl, hbcurl, hbexpat
      - the goal was that no actual program logic should be altered by
        these changes. Except some possible minor exceptions, any such
        change is probably a bug in this patch.
      It's a massive patch, if you find anything broken after it, please
      open an Issue with the details. Build test was done on macOS.
      The goal is make it easier to see what actual code/logic was changed
      in 3.4 compared to 3.2 and to make patches easier to apply in both
      ways.
2017-09-08 16:25:13 +00:00

135 lines
3.3 KiB
C

/*
* BBS.......: The Dark Knight Returns
* Date......: 1993-03-31
*
* This is an original work by Dave Pearson and is placed in the public
* domain.
* 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.
*
* Modification history:
*
* 2001-08-19 Modifications for Harbour by Brian Hays, also placed in
* the public domain.
*
*/
#include "hbapi.h"
#include "hbapiitm.h"
HB_FUNC( GT_NEWFLAG )
{
unsigned FlagCount = ( unsigned ) hb_parnidef( 1, 1 );
if( FlagCount > 0 )
{
char * FlagString;
unsigned ByteCount = ( unsigned ) ( ( FlagCount / 8 ) + 1 );
unsigned Byte;
if( ! ( FlagCount % 8 ) )
--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 )
{
if( HB_ISCHAR( 1 ) )
{
char * FlagString = hb_itemGetC( hb_param( 1, HB_IT_STRING ) );
unsigned StartBit = hb_parnidef( 2, 1 );
unsigned EndBit = hb_parnidef( 3, 1 );
EndBit = HB_MAX( StartBit, EndBit );
if( StartBit > 0 && EndBit <= ( hb_parclen( 1 ) * 8 ) )
{
unsigned BitCount;
for( BitCount = StartBit; BitCount <= EndBit; BitCount++ )
{
unsigned BitPointer = BitCount % 8;
unsigned BytePointer = ( unsigned ) ( BitCount / 8 );
if( ! BitPointer )
{
BitPointer = 8;
--BytePointer;
}
FlagString[ BytePointer ] |= 1 << ( BitPointer - 1 );
}
}
hb_retclen_buffer( FlagString, hb_parclen( 1 ) );
}
else
hb_retc_null();
}
HB_FUNC( GT_CLRFLAG )
{
if( HB_ISCHAR( 1 ) )
{
char * FlagString = hb_itemGetC( hb_param( 1, HB_IT_STRING ) );
unsigned StartBit = hb_parnidef( 2, 1 );
unsigned EndBit = hb_parnidef( 3, 1 );
EndBit = HB_MAX( StartBit, EndBit );
if( StartBit > 0 && EndBit <= ( hb_parclen( 1 ) * 8 ) )
{
unsigned BitCount;
for( BitCount = StartBit; BitCount <= EndBit; BitCount++ )
{
unsigned BitPointer = BitCount % 8;
unsigned BytePointer = ( unsigned ) ( BitCount / 8 );
if( ! BitPointer )
{
BitPointer = 8;
--BytePointer;
}
FlagString[ BytePointer ] &= 0xff - ( 1 << ( BitPointer - 1 ) );
}
}
hb_retclen_buffer( FlagString, hb_parclen( 1 ) );
}
else
hb_retc_null();
}
HB_FUNC( GT_ISFLAG )
{
HB_BOOL FlagStatus = HB_FALSE;
if( HB_ISCHAR( 1 ) )
{
unsigned Bit = hb_parnidef( 2, 1 );
if( Bit > 0 && Bit <= ( hb_parclen( 1 ) * 8 ) )
{
const char * FlagString = hb_parc( 1 );
unsigned BitPointer = Bit % 8;
unsigned BytePointer = ( unsigned ) ( Bit / 8 );
if( ! BitPointer )
{
BitPointer = 8;
--BytePointer;
}
FlagStatus = FlagString[ BytePointer ] & ( 1 << ( BitPointer - 1 ) );
}
}
hb_retl( FlagStatus );
}