* contrib/gtwvg/gtwvg.c
* contrib/gtwvg/wincallb.c
* contrib/gtwvg/wvgcore.c
* contrib/gtwvg/wvgcuig.c
* contrib/gtwvg/wvgutils.c
* contrib/gtwvg/wvgwin.c
* contrib/hbbmcdx/bmdbfcdx.c
* contrib/hbbtree/hb_btree.c
* contrib/hbclipsm/environ.c
* contrib/hbclipsm/gauge.c
* contrib/hbclipsm/num.c
* contrib/hbclipsm/status.c
* contrib/hbct/addascii.c
* contrib/hbct/asciisum.c
* contrib/hbct/ascpos.c
* contrib/hbct/atadjust.c
* contrib/hbct/atnum.c
* contrib/hbct/atrepl.c
* contrib/hbct/bitnum.c
* contrib/hbct/charevod.c
* contrib/hbct/charlist.c
* contrib/hbct/charmirr.c
* contrib/hbct/charmix.c
* contrib/hbct/charone.c
* contrib/hbct/charonly.c
* contrib/hbct/charop.c
* contrib/hbct/charrepl.c
* contrib/hbct/charsort.c
* contrib/hbct/charsprd.c
* contrib/hbct/charswap.c
* contrib/hbct/color.c
* contrib/hbct/count.c
* contrib/hbct/ctc.c
* contrib/hbct/ctmath2.c
* contrib/hbct/ctnet.c
* contrib/hbct/ctpad.c
* contrib/hbct/ctstr.c
* contrib/hbct/ctstrfil.c
* contrib/hbct/ctwfunc.c
* contrib/hbct/datetime.c
* contrib/hbct/dattime2.c
* contrib/hbct/disk.c
* contrib/hbct/expand.c
* contrib/hbct/files.c
* contrib/hbct/finan.c
* contrib/hbct/justify.c
* contrib/hbct/keyset.c
* contrib/hbct/lton.c
* contrib/hbct/maxline.c
* contrib/hbct/misc1.c
* contrib/hbct/num1.c
* contrib/hbct/numat.c
* contrib/hbct/numcount.c
* contrib/hbct/numline.c
* contrib/hbct/pos1.c
* contrib/hbct/pos2.c
* contrib/hbct/posdiff.c
* contrib/hbct/print.c
* contrib/hbct/range.c
* contrib/hbct/relation.c
* contrib/hbct/remove.c
* contrib/hbct/replace.c
* contrib/hbct/screen1.c
* contrib/hbct/screen2.c
* contrib/hbct/setrc.c
* contrib/hbct/strdiff.c
* contrib/hbct/strswap.c
* contrib/hbct/tab.c
* contrib/hbct/token1.c
* contrib/hbct/token2.c
* contrib/hbct/trig.c
* contrib/hbct/video.c
* contrib/hbct/wordrepl.c
* contrib/hbct/wordtoch.c
* contrib/hbcurl/hbcurl.c
* contrib/hbcurl/hbcurlm.c
* contrib/hbfbird/firebird.c
* contrib/hbfimage/fi_wrp.c
* contrib/hbgd/gdwrp.c
* contrib/hbgt/ascposgt.c
* contrib/hbgt/atdiff.c
* contrib/hbgt/bitflags.c
* contrib/hbgt/charmixg.c
* contrib/hbgt/chrcount.c
* contrib/hbgt/chrfirst.c
* contrib/hbgt/chrtotal.c
* contrib/hbgt/strcount.c
* contrib/hbgt/strcspn.c
* contrib/hbgt/strdiffg.c
* contrib/hbgt/strleft.c
* contrib/hbgt/strpbrk.c
* contrib/hbgt/strright.c
* contrib/hbmisc/dates2.c
* contrib/hbmisc/hb_f.c
* contrib/hbmisc/stringsx.c
* contrib/hbmysql/mysql.c
* contrib/hbmzip/hbmzip.c
* contrib/hbnf/caplock.c
* contrib/hbnf/chdir.c
* contrib/hbnf/color2n.c
* contrib/hbnf/ftattr.c
* contrib/hbnf/fttext.c
* contrib/hbnf/getenvrn.c
* contrib/hbnf/mkdir.c
* contrib/hbnf/n2color.c
* contrib/hbnf/numlock.c
* contrib/hbnf/peek.c
* contrib/hbnf/poke.c
* contrib/hbnf/prtscr.c
* contrib/hbnf/putkey.c
* contrib/hbnf/rmdir.c
* contrib/hbodbc/odbc.c
* contrib/hbqt/hbqt_qradiobutton.cpp
* contrib/hbqt/qth/QRadioButton.qth
* contrib/hbsqlit3/hbsqlit3.c
* contrib/hbssl/ssl.c
* contrib/hbssl/sslciph.c
* contrib/hbtip/utils.c
* contrib/hbwin/legacyc.c
* contrib/hbwin/olecore.c
* contrib/hbwin/wapi_commctrl.c
* contrib/hbwin/wapi_winbase.c
* contrib/hbwin/wapi_winuser.c
* contrib/hbwin/win_dll.c
* contrib/hbwin/win_misc.c
* contrib/hbwin/win_prn1.c
* contrib/hbwin/win_prn2.c
* contrib/hbwin/win_prt.c
* contrib/rddads/ads1.c
* contrib/rddads/adsfunc.c
* contrib/rddads/adsmgmnt.c
* contrib/xhb/datesxhb.c
* contrib/xhb/fparse.c
* contrib/xhb/freadlin.c
* contrib/xhb/hbcomprs.c
* contrib/xhb/hboutdbg.c
* contrib/xhb/txtline.c
* contrib/xhb/xhbarr.c
* contrib/xhb/xhbcopyf.c
* contrib/xhb/xhbfunc.c
* contrib/xhb/xhbsave.c
* contrib/xhb/xhbtrim.c
* contrib/xhb/xstrdel.c
* IS*() -> HB_IS*() macro rename.
(pass 3 - final)
181 lines
5.1 KiB
C
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 )
|
|
{
|
|
|
|
BOOL FlagStatus = 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);
|
|
}
|