Files
harbour-core/harbour/contrib/hbgt/bitflags.c
Viktor Szakats ec13203192 2010-06-19 12:23 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* src/vm/itemapi.c
    - hb_itemGetNL() no longer works for date types.
      INCOMPATIBLE. If you used it to retrieve date/time,
      use hb_itemGetDL() instead.
    ! Fixed typo in prev addition.

  * include/hbapi.h
  * src/vm/arrays.c
    + Added hb_arrayGetNSize(), hb_arraySetNSize().
    ! Fixed old typo in TRACE() call of hb_arrayGetNInt().

  * src/vm/extend.c
    ! Fixed typo in prev addition.

  * src/rtl/filesys.c
    ! Applied fixed from Przemek to hb_fsReadAt()/hb_fsWriteAt()
      code to be MT safe plus fix other problems.
    ; QUESTION: Shouls the same applied to hb_fsWriteLarge()/hb_fsReadLarge() 
                loops? (BTW inactive in 32-bit Harbour builds)

  * contrib/hbct/screen2.c
    ! Type cleanup.

  * contrib/hbct/pack.c
  * contrib/xhb/hbxml.c
  * contrib/xhb/hbxml.h
  * contrib/hbgt/charmixg.c
  * contrib/hbgt/charodd.c
  * contrib/hbgt/strexpan.c
  * contrib/hbgt/asciisgt.c
  * contrib/hbgt/strright.c
  * contrib/hbgt/strasint.c
  * contrib/hbgt/strdiffg.c
  * contrib/hbgt/chrtotal.c
  * contrib/hbgt/strcount.c
  * contrib/hbgt/strleft.c
  * contrib/hbgt/chrfirst.c
  * contrib/hbgt/chrcount.c
  * contrib/hbgt/strpbrk.c
  * contrib/hbgt/chareven.c
  * contrib/hbgt/bitflags.c
  * contrib/hbgt/strcspn.c
  * contrib/hbgt/atdiff.c
  * contrib/hbnf/proper.c
  * contrib/hbnf/getenvrn.c
    ! Fixed to use Harbour size types.

  * contrib/hbnf/dispc.c
    ! Started using Harbour type, but this is code is
      deadly and needs further work. I still wonder how
      to create code which mixes properly HB_FOFFSET and
      HB_SIZE.

  * contrib/xhb/cstructc.c
    * Formatting.
2010-06-19 10:26:02 +00:00

181 lines
5.1 KiB
C

/*
* $Id$
*/
/*
* File......: BITFLAGS.C
* Author....: Dave Pearson
* BBS.......: The Dark Knight Returns
* Net/Node..: 050/069
* User Name.: Dave Pearson
* Date......: 31/03/93
* Revision..: 1.0
*
* 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:
* ---------------------
*
* 8/19/2001 Modifications for Harbour by Brian Hays, also placed in
* the public domain.
*
*/
#include "hbapi.h"
#define _GT_MAX(x,y) (x > y ? x : y)
HB_FUNC( GT_NEWFLAG )
{
char *FlagString;
unsigned ByteCount;
unsigned FlagCount = 1;
unsigned Byte;
if (ISNUM(1))
{
FlagCount = (unsigned) hb_parni(1);
}
if (FlagCount > 0)
{
ByteCount = (unsigned)((FlagCount / 8) + 1);
if (!(FlagCount % 8))
{
--ByteCount;
}
FlagString = 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);
if (StartBit > 0 && EndBit <= (hb_parclen(1) * 8))
{
for (BitCount = StartBit; BitCount <= EndBit; BitCount++)
{
BitPointer = BitCount % 8;
BytePointer = (unsigned) (BitCount / 8);
if (!BitPointer)
{
BitPointer = 8;
--BytePointer;
}
FlagString[BytePointer] |= 1 << (BitPointer - 1);
}
}
hb_retclen(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);
if (StartBit > 0 && EndBit <= (hb_parclen(1) * 8))
{
for (BitCount = StartBit; BitCount <= EndBit; BitCount++)
{
BitPointer = BitCount % 8;
BytePointer = (unsigned) (BitCount / 8);
if (!BitPointer)
{
BitPointer = 8;
--BytePointer;
}
FlagString[BytePointer] &= 0xff - (1 << (BitPointer - 1));
}
}
hb_retclen(FlagString, hb_parclen(1));
}
else
{
hb_retc_null();
}
}
HB_FUNC( GT_ISFLAG )
{
HB_BOOL FlagStatus = HB_FALSE;
unsigned Bit = 1;
unsigned BitPointer;
unsigned BytePointer;
char *FlagString;
if ( HB_ISCHAR(1) )
{
FlagString = hb_parc(1);
if ( HB_ISNUM(2) )
{
Bit = hb_parni(2);
}
if (Bit > 0 && Bit <= (hb_parclen(1) * 8))
{
BitPointer = Bit % 8;
BytePointer = (unsigned) (Bit / 8);
if (!BitPointer)
{
BitPointer = 8;
--BytePointer;
}
FlagStatus = FlagString[BytePointer] & (1 << (BitPointer - 1));
}
}
hb_retl(FlagStatus);
}