//*********************
// helper functions
// By Emil Halim
//*********************
#include 'smm32.zir';
procedure H_memcpy(Dword dst,src,len)
{
uses Esi Edi Ecx;
Edi = dst;
Esi = src;
Ecx = len;
rep movsb
}
function H_strlen(char* str)
{
Eax = nil;
Ebx = str;
while(char[Ebx] != 0)
{
Ebx++;
Eax++;
}
}
function H_strcpy(Dword dst,src)
{
Eax = dst;
Edx = src;
push Eax;
BL = [Edx];
while ( BL != 0)
{
[Eax] = BL;
Eax++; Edx++;
BL = [Edx];
}
[Eax] = 0;
pop Eax;
}
function H_strcat(Dword dst,src)
{
Eax = dst;
Edx = src;
push Eax;
while (byte [Eax] != 0) { Eax++; }
while (byte [Edx] != 0)
{
BL = [Edx];
[Eax] = BL;
Edx++; Eax++;
}
[Eax] = 0;
pop Eax;
}
function H_GetNextLine(char* strbuf; pointer dest)
{
global int32 incr;
uses esi edi;
eax = xor;
ecx = incr;
esi = strbuf;
add esi, ecx
edi = dest;
while(char[esi] != 0)
{
if (word[esi] == "\r\n")
{
eax += 2;
break;
}
bl = char[Esi];
char[edi] = bl;
eax++;
esi++;
edi++;
}
char[edi] = 0;
add ecx, eax
incr = ecx;
}
function H_GetTmpStr(DWord sizeInByte)
{
uses Ebx Ecx;
global int32 StrCnt;
global char* StrFunc[2048];
Eax = StrCnt;
Eax++;
and Eax,2047
StrCnt = Eax;
Ebx = @StrFunc;
lea Ebx,[Ebx+Eax]
Eax=DWord[Ebx];
if( Eax> 0)
{
freemem( Eax);
}
[Ebx]= malloc(sizeInByte);
}
function H_Trim(char* str;int32* len)
{
uses Ebx Ecx;
Ebx = str;
al = char[Ebx];
@Rept:
if(al==32 or al==9 or al==10 or al==11 or al==13)
{
Ebx++;
al = char[Ebx];
goto @Rept;
}
Ecx = Ebx;
while(char[Ecx] != 0)
{
Ecx++;
}
al = char[Ecx-1];
@Rept1:
if(al==32 or al==9 or al==10 or al==11 or al==13)
{
Ecx--;
al = char[Ecx-1];
goto @Rept1;
}
sub Ecx,Ebx
if(len != nil )
{
//*len = Ecx;
Eax = len;
Dword[Eax] = Ecx;
}
Eax = H_GetTmpStr(Ecx);
char[Eax+Ecx]=0;
H_memcpy(Eax,Ebx,Ecx);
}
function H_LTrim (char* str)
{
uses Ebx Ecx;
Ebx = str;
al = char[Ebx];
@Rept:
if(al==32 or al==9 or al==10 or al==11 or al==13)
{
Ebx++;
al = char[Ebx];
goto @Rept;
}
Ecx = Ebx;
while(char[Ecx] != 0)
{
Ecx++;
}
sub Ecx,Ebx
Eax = H_GetTmpStr(Ecx);
push Eax
strlcpy(Eax,Ebx,Ecx);
pop Eax
}
function H_Left(char* str; int32 length)
{
uses Esi Edi Ecx;
Esi = str;
Ecx = Esi;
while(char[Ecx] != 0)
{
Ecx++;
}
sub Ecx,Esi
if(length < Ecx)
{
Ecx = length;
}
Edi = H_GetTmpStr(Ecx);
char[Edi+Ecx]=0;
push Edi
rep movsb
pop Eax
}