Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need a simple FLL
Message
 
To
19/09/2006 11:51:03
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
01154766
Message ID:
01155803
Views:
12
Hi Mark,

I make my variant of the function of Christian Ehlscheid just for your amusement.
The nom of the function of Christian Ehlscheid is STR2HEXEX,
the nom of my version is STR2HEXEX2 .
If the length of string is more than 250 characters the variant of Christian Ehlscheid is faster ~ 25 %, if the length of string is less than 250 characters the variant of Igor Nikiforov is faster ~ 10 %
You can download the FLL file with test program from
ftp://ftp-developpez.com/nikiforov/UDFs/Ehlscheid.zip

Regards,
Igor.
// include FoxPro LCK header file
#include <pro_ext.h>

void _fastcall  StringToHexEx2(ParamBlk *parm)  {
   unsigned char *bString,  *pString,  *eString;
   if (!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length * 3)) // compute length of resulting hex string
   	     _Error(182); // "Insufficient memory"
   	/*  Since this routine does not call any functions which cause memory reorganization, 
	it is not necessary to _HLock the handles prior to	dereferencing them (_HandToPtr).*/
    bString = (unsigned char *)_HandToPtr(parm->p[0].val.ev_handle) - 1 ;
    pString = bString +parm->p[0].val.ev_length;
	parm->p[0].val.ev_length *= 3;
    eString = bString + parm->p[0].val.ev_length;
    while (eString > bString) {  	// transform the string to hexadecimal
        register unsigned  char i = 0;
		do {   // i == 0 - lower 4 bits (modulo of 16) 
          register unsigned  char cHexChar = '0';
		  cHexChar += (i ? *pString-- >> 4 : *pString % 16 ); // i == 1 - upper 4 bits (divide by 16)
		  if (cHexChar > '9')
		  	cHexChar += 0x7;	 
		   *eString-- =  cHexChar ;  
           i ^= 1;
		}  while (i) ;
 	  *eString-- = '%';
	}
	_RetVal(&parm->p[0].val);
}

void _fastcall StringToHexEx(ParamBlk *parm)
{
	unsigned char *pString, *pHexString;
	unsigned char cHexChar;
	unsigned int xj;
	Value vHexString;
        vHexString.ev_type = 'C';

	// compute length of resulting hex string
	vHexString.ev_length = parm->p[0].val.ev_length * 3;

	// if len is equal to 0, return an empty string
	if (vHexString.ev_length == 0)
	{
		_RetVal(&vHexString);
		return;
	}

	// allocate a memory buffer for the hex string
	vHexString.ev_handle = _AllocHand(vHexString.ev_length);
	 // raise Error "Insufficient memory" if allocation failed
	if (!vHexString.ev_handle)
		_Error(182);

	// lock memory handles and get real pointers
	_HLock(vHexString.ev_handle);
	pHexString = (unsigned char*)_HandToPtr(vHexString.ev_handle);
	_HLock(parm->p[0].val.ev_handle);
	pString = (unsigned char*)_HandToPtr(parm->p[0].val.ev_handle);

	// transform the string to hexadecimal
	for ( xj = 1; xj <= parm->p[0].val.ev_length; xj++)
	{
		*pHexString++ = '%';
		// upper 4 bits (divide by 16)
		cHexChar = *pString / 16 + '0';
		if (cHexChar > '9')
			cHexChar += 0x7;
                *pHexString++ = cHexChar;

		// lower 4 bits (modulo of 16)
		cHexChar = *pString % 16 + '0';
		if (cHexChar > '9')
			cHexChar += 0x7;
               *pHexString++ = cHexChar;

		pString++;
	}

	// unlock memory handles and return the hex string
	_HUnLock(parm->p[0].val.ev_handle);
	_HUnLock(vHexString.ev_handle);
	_RetVal(&vHexString);
}


FoxInfo myFoxInfo[] =  {
 {"STR2HEXEX2", (FPFI) StringToHexEx2, 1, "C"},
 {"STR2HEXEX", (FPFI) StringToHexEx, 1, "C"}
};

FoxTable _FoxTable = {
(FoxTable *)0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
Previous
Reply
Map
View

Click here to load this message in the networking platform