Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5572 → Rev 5573

/programs/cmm/lib/strings.h
2,22 → 2,28
// strcmp( ESI, EDI)
// strlen( EDI)
// strcpy( EDI, ESI) --- 0 if ==
// strncpy(dword text1,text2,signed length)
// strcat( EDI, ESI)
// strncat(dword text1,text2,signed length) --- pasting the text of a certain length
// strchr( ESI,BL) --- find first BL
// strrchr( ESI,BL) --- find last BL
// strstr( EBX, EDX)
// itoa( ESI)
// atoi( EAX)
// itoa(signed long number) --- convert the number as a string
// atoi(dword text) --- convert a string as a number
// strupr( ESI)
// strlwr( ESI) --- kyrillic symbols may not work
// strttl( EDX)
// strtok( ESI)
// strtrim( ESI) --- removes "blank" characters (\r, \n and space)
// strltrim(dword text) --- removes "blank" characters on the left (\r, \n and space)
// strrtrim(dword text) --- removes "blank" characters on the right (\r, \n and space)
// strtrim(dword text) --- delete "empty" characters (\ r \ n and space) on both sides
// chrnum(dword searchin, char symbol)
// strcpyb(dword searchin, copyin, startstr, endstr) --- copy string between strings
// strnumb(dword searchin, startstr, endstr) --- get number between strings
// strdup(dword text) --- allocation under the text
//------------------------------------------------------------------------------
 
/*
inline fastcall signed int strcmp( ESI, EDI)
{
loop()
29,6 → 35,7
EDI++;
}
}
*/
 
 
inline fastcall signed int strncmp( ESI, EDI, ECX)
62,6 → 69,31
}
 
 
signed int strcmp(dword text1, text2)
{
char s1,s2;
dword p1,p2;
p1 = text1;
p2 = text2;
loop()
{
s1 = DSBYTE[text1];
s2 = DSBYTE[text2];
if(s1==s2)
{
if(s1==0) return 0;
}
else {
return -1;
}
$inc text1
$inc text2
}
return 0;
}
 
 
inline fastcall void strcpy( EDI, ESI)
{
$cld
72,6 → 104,24
$jnz L2
}
 
void strncpy(dword text1, text2, signed len)
signed o1,o2;
{
o1 = len/4;
o2 = len-4*o1;
while(o1){
ESDWORD[text1] = ESDWORD[text2];
text1 += 4;
text2 += 4;
$dec o1
}
while(o2){
ESBYTE[text1] = ESBYTE[text2];
$inc text1
$inc text2
$dec o2
}
}
 
inline fastcall int strlcpy(dword ESI, EDI, EBX)
{
87,7 → 137,8
return 0;
}
 
inline fastcall strtrim( ESI)
/*
inline fastcall void strtrim( ESI)
{
EDI = ESI;
do{
95,14 → 146,91
if (AL != '\32') && (AL != '\13') && (AL != '\10')
{
DSBYTE[ESI]=AL;
ESI++;
$inc ESI
}
EDI++;
$inc EDI
}while(AL!=0);
DSBYTE[ESI] = '\0';
}
*/
 
byte __isWhite(int s){ if (s==13)||(s==32)||(s==10)||(s==9) return true; return false; }
void strltrim(dword text){
int s;
dword back_text;
back_text = text;
s = ESBYTE[text];
while(__isWhite(s))
{
$inc text
s = ESBYTE[text];
}
loop()
{
ESBYTE[back_text] = s;
$inc back_text
if(!s) break;
$inc text
s = ESBYTE[text];
};
}
 
void strrtrim(dword text)
{
int s;
dword p;
do {
s = ESBYTE[text];
if(__isWhite(s))
{
p = text;
while(__isWhite(s))
{
$inc text;
s = ESBYTE[text];
}
}
else $inc text
} while(s);
$dec text
s = ESBYTE[text];
if(__isWhite(s)) ESBYTE[p] = 0;
}
 
void strtrim(dword text){
int s;
dword p,back_text;
back_text = text;
s = ESBYTE[text];
while(__isWhite(s))
{
$inc text
s = ESBYTE[text];
}
do {
s = ESBYTE[text];
if(__isWhite(s))
{
p = back_text;
while(__isWhite(s))
{
ESBYTE[back_text] = s;
$inc back_text
$inc text;
s = ESBYTE[text];
}
}
else {
ESBYTE[back_text] = s;
$inc back_text
$inc text
}
} while(s);
$dec text
s = ESBYTE[text];
if(__isWhite(s)) ESBYTE[p] = 0;
}
 
inline fastcall void strcat( EDI, ESI)
{
asm {
131,6 → 259,31
}
}
 
void strncat(dword text1, text2, signed len)
signed o1,o2;
char s;
{
s = ESBYTE[text1];
while(s){
$inc text1
s = ESBYTE[text1];
}
o1 = len/4;
o2 = len-4*o1;
while(o1){
ESDWORD[text1] = ESDWORD[text2];
text1 += 4;
text2 += 4;
$dec o1
}
while(o2){
ESBYTE[text1] = ESBYTE[text2];
$inc text1
$inc text2
$dec o2
}
}
 
inline fastcall void chrcat(ESI, BL)
{
EDI = strlen(ESI);
346,7 → 499,7
}while(AL!=0);
}
 
 
/*
dword itoa( ESI)
{
unsigned char buffer[11];
380,7 → 533,50
$popa
return #buffer;
}
*/
 
dword itoa(signed long number)
{
unsigned char buf[11];
dword ret;
byte cmd;
long mask,tmp;
mask = 1000000000;
cmd = true;
if(!number){
ESBYTE[buf] = '0';
ESBYTE[buf+1] = 0;
return buf;
}
ret = buf;
if(number<0)
{
$neg number
ESBYTE[buf] = '-';
$inc buf
}
while(mask)
{
tmp = number / mask;
tmp = tmp%10;
if(cmd){
if(tmp){
ESBYTE[buf] = tmp + '0';
$inc buf
cmd = false;
}
}
else {
ESBYTE[buf] = tmp + '0';
$inc buf
}
mask /= 10;
}
ESBYTE[buf] = 0;
return ret;
}
inline fastcall itoa_(signed int EDI, ESI)
{
$pusha
414,6 → 610,14
return EBX;
}
 
dword strdup(dword text)
{
dword l = strlen(text);
dword ret = malloc(l+1);
strncpy(ret,text,l);
return ret;
}
 
void debugi(dword d_int)
{
char tmpch[12];
422,7 → 626,7
}
 
 
#define strncpy strcpyn
//#define strncpy strcpyn
#define strnmov strmovn
#define stricmp strcmpi
#define strcmpn strncmp