Subversion Repositories Kolibri OS

Rev

Rev 7764 | Rev 7783 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7764 Rev 7768
1
#ifndef INCLUDE_STRING_H
1
#ifndef INCLUDE_STRING_H
2
#define INCLUDE_STRING_H
2
#define INCLUDE_STRING_H
3
 
3
 
4
#ifndef INCLUDE_MEM_H
4
#ifndef INCLUDE_MEM_H
5
#include "../lib/mem.h"
5
#include "../lib/mem.h"
6
#endif
6
#endif
7
 
7
 
8
//------------------------------------------------------------------------------
8
//------------------------------------------------------------------------------
9
// strspn(dword text1,text2) --- example: strspn("12 year","1234567890") -> return 2
9
// strspn(dword text1,text2) --- example: strspn("12 year","1234567890") -> return 2
10
// strpbrk(dword text1,text2) --- example: strpbrk("this test", " ckfi") -> return "is test"
10
// strpbrk(dword text1,text2) --- example: strpbrk("this test", " ckfi") -> return "is test"
11
// strcmp( ESI, EDI)
11
// strcmp( ESI, EDI)
12
// strlen( EDI)
12
// strlen( EDI)
13
// utf8_strlen( ESI)
13
// utf8_strlen( ESI)
14
// strcpy( EDI, ESI) --- 0 if ==
14
// strcpy( EDI, ESI) --- 0 if ==
15
// strlcpy(dword text1,text2,signed length)
15
// strlcpy(dword text1,text2,signed length)
16
// strcat( EDI, ESI)
16
// strcat( EDI, ESI)
17
// chrcat(ESI, BL)
17
// chrcat(ESI, BL)
18
// strncat(dword text1,text2,signed length) --- pasting the text of a certain length
18
// strncat(dword text1,text2,signed length) --- pasting the text of a certain length
19
// strchr( ESI,BL) --- find first BL
19
// strchr( ESI,BL) --- find first BL
20
// strrchr( ESI,BL) --- find last BL
20
// strrchr( ESI,BL) --- find last BL
21
// strstr( EBX, EDX)
21
// strstr( EBX, EDX)
22
// itoa(signed long number) --- convert the number as a string
22
// itoa(signed long number) --- convert the number as a string
23
// atoi(dword text) --- convert a string as a number
23
// atoi(dword text) --- convert a string as a number
24
// strupr( ESI)
24
// strupr( ESI)
25
// strlwr( ESI) --- Cyrillic symbols may not work
25
// strlwr( ESI) --- Cyrillic symbols may not work
26
// strttl( EDX)
26
// strttl( EDX)
27
// strtok( ESI)
27
// strtok( ESI)
28
// strltrim(dword text) --- removes "blank" characters on the left (\r, \n and space)
28
// strltrim(dword text) --- removes "blank" characters on the left (\r, \n and space)
29
// strrtrim(dword text) --- removes "blank" characters on the right (\r, \n and space)
29
// strrtrim(dword text) --- removes "blank" characters on the right (\r, \n and space)
30
// strtrim(dword text) --- delete "empty" characters (\ r \ n and space) on both sides
30
// strtrim(dword text) --- delete "empty" characters (\ r \ n and space) on both sides
31
// chrnum(dword searchin, char symbol)
31
// chrnum(dword searchin, char symbol)
32
// strcpyb(dword searchin, copyin, startstr, endstr) --- copy string between strings
32
// strcpyb(dword searchin, copyin, startstr, endstr) --- copy string between strings
33
// strnumb(dword searchin, startstr, endstr) --- get number between strings
33
// strnumb(dword searchin, startstr, endstr) --- get number between strings
34
// strdup(dword text) --- allocation under the text
34
// strdup(dword text) --- allocation under the text
35
//------------------------------------------------------------------------------
35
//------------------------------------------------------------------------------
36
 
36
 
37
/*
37
/*
38
inline fastcall signed int strcmp( ESI, EDI)
38
inline fastcall signed int strcmp( ESI, EDI)
39
{
39
{
40
    loop()
40
    loop()
41
    {
41
    {
42
        IF (DSBYTE[ESI]
42
        IF (DSBYTE[ESI]
43
        IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
43
        IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
44
        IF (DSBYTE[ESI]=='\0') RETURN 0;
44
        IF (DSBYTE[ESI]=='\0') RETURN 0;
45
        ESI++;
45
        ESI++;
46
        EDI++;
46
        EDI++;
47
    }
47
    }
48
}
48
}
49
*/
49
*/
50
 
50
 
51
 
51
 
52
 
52
 
53
inline int strspn(dword text1,text2)
53
inline int strspn(dword text1,text2)
54
{
54
{
55
	dword beg;
55
	dword beg;
56
	char s1,s2;
56
	char s1,s2;
57
	int ret;
57
	int ret;
58
	ret = 0;
58
	ret = 0;
59
	beg = text2;
59
	beg = text2;
60
	do {
60
	do {
61
		s1 = ESBYTE[text1];
61
		s1 = ESBYTE[text1];
62
		text2 = beg;
62
		text2 = beg;
63
		do {
63
		do {
64
			s2 = ESBYTE[text2];
64
			s2 = ESBYTE[text2];
65
			if(s1==s2)
65
			if(s1==s2)
66
			{
66
			{
67
				if(!s2)break;
67
				if(!s2)break;
68
				$inc ret
68
				$inc ret
69
				break;
69
				break;
70
			}
70
			}
71
			else $inc text2
71
			else $inc text2
72
		} while(s2);
72
		} while(s2);
73
		$inc text1
73
		$inc text1
74
	} while(s1);
74
	} while(s1);
75
	return ret;
75
	return ret;
76
}
76
}
77
 
77
 
78
inline dword strpbrk(dword text1,text2)
78
inline dword strpbrk(dword text1,text2)
79
{
79
{
80
	char s,ss;
80
	char s,ss;
81
	dword beg;
81
	dword beg;
82
	beg = text2;
82
	beg = text2;
83
	do {
83
	do {
84
		s = ESBYTE[text1];
84
		s = ESBYTE[text1];
85
		text2 = beg;
85
		text2 = beg;
86
		do {
86
		do {
87
			ss = ESBYTE[text2];
87
			ss = ESBYTE[text2];
88
			if(ss==s) return text1;
88
			if(ss==s) return text1;
89
			$inc text2
89
			$inc text2
90
		} while(ss);
90
		} while(ss);
91
		$inc text1
91
		$inc text1
92
	} while(s);
92
	} while(s);
93
	return text1;
93
	return text1;
94
}
94
}
95
 
95
 
96
inline fastcall signed int strncmp( ESI, EDI, ECX)
96
inline fastcall signed int strncmp( ESI, EDI, ECX)
97
{
97
{
98
  asm {
98
  asm {
99
    MOV EBX, EDI
99
    MOV EBX, EDI
100
    XOR EAX, EAX
100
    XOR EAX, EAX
101
    MOV EDX, ECX
101
    MOV EDX, ECX
102
    OR ECX, ECX
102
    OR ECX, ECX
103
    JE L1
103
    JE L1
104
    REPNE SCASB
104
    REPNE SCASB
105
    SUB EDX, ECX
105
    SUB EDX, ECX
106
    MOV ECX, EDX
106
    MOV ECX, EDX
107
    MOV EDI, EBX
107
    MOV EDI, EBX
108
    XOR EBX, EBX
108
    XOR EBX, EBX
109
    REPE CMPSB
109
    REPE CMPSB
110
    MOV AL, DSBYTE[ ESI-1]
110
    MOV AL, DSBYTE[ ESI-1]
111
    MOV BL, DSBYTE[ EDI-1]
111
    MOV BL, DSBYTE[ EDI-1]
112
    SUB EAX, EBX
112
    SUB EAX, EBX
113
L1:
113
L1:
114
  }
114
  }
115
}
115
}
116
 
116
 
117
/*
117
/*
118
signed int strncmp(dword s1, s2, signed n)
118
signed int strncmp(dword s1, s2, signed n)
119
unsigned char _s1,_s2;
119
unsigned char _s1,_s2;
120
{
120
{
121
	if (n == 0)
121
	if (n == 0)
122
		return 0;
122
		return 0;
123
	do {
123
	do {
124
		_s1 = DSBYTE[s1];
124
		_s1 = DSBYTE[s1];
125
		_s2 = DSBYTE[s2];
125
		_s2 = DSBYTE[s2];
126
		if (_s1 != _s2)
126
		if (_s1 != _s2)
127
		{
127
		{
128
			$dec s2
128
			$dec s2
129
			return _s1 - _s2;
129
			return _s1 - _s2;
130
		}
130
		}
131
		$inc s2
131
		$inc s2
132
		if (_s1 == 0)
132
		if (_s1 == 0)
133
			break;
133
			break;
134
		$inc s1
134
		$inc s1
135
		$dec n
135
		$dec n
136
	} while (n);
136
	} while (n);
137
	return 0;
137
	return 0;
138
}
138
}
139
*/
139
*/
140
 
140
 
141
/*
141
/*
142
inline signed int strncmp(dword text1,text2,len)
142
inline signed int strncmp(dword text1,text2,len)
143
{
143
{
144
	
144
	
145
	loop()
145
	loop()
146
	{
146
	{
147
		if(DSBYTE[text1]!=DSBYTE[text2])return text1-text2;
147
		if(DSBYTE[text1]!=DSBYTE[text2])return text1-text2;
148
		$dec len 
148
		$dec len 
149
		if(!len)return 0;
149
		if(!len)return 0;
150
	}
150
	}
151
}
151
}
152
*/
152
*/
153
inline fastcall unsigned int strlen( EDI)
153
inline fastcall unsigned int strlen( EDI)
154
{
154
{
155
	$xor eax, eax
155
	$xor eax, eax
156
	$mov ecx, -1
156
	$mov ecx, -1
157
	$REPNE $SCASB
157
	$REPNE $SCASB
158
	EAX-=2+ECX;
158
	EAX-=2+ECX;
159
}
159
}
160
 
160
 
161
inline dword strnlen(dword str, dword maxlen)
161
inline dword strnlen(dword str, dword maxlen)
162
{
162
{
163
	dword cp;
163
	dword cp;
164
	for (cp = str; (maxlen != 0) && (DSBYTE[cp] != '\0'); cp++, maxlen--);
164
	for (cp = str; (maxlen != 0) && (DSBYTE[cp] != '\0'); cp++, maxlen--);
165
	return cp - str;
165
	return cp - str;
166
}
166
}
167
 
167
 
168
inline fastcall unsigned int utf8_strlen( ESI)
168
inline fastcall unsigned int utf8_strlen( ESI)
169
{
169
{
170
 $xor  ecx, ecx
170
 $xor  ecx, ecx
171
  _loop: 
171
  _loop: 
172
 $lodsb
172
 $lodsb
173
 $test  al, al
173
 $test  al, al
174
 $jz  _done
174
 $jz  _done
175
 $and al, 0xc0
175
 $and al, 0xc0
176
 $cmp al, 0x80
176
 $cmp al, 0x80
177
 $jz  _loop 
177
 $jz  _loop 
178
 $inc ecx
178
 $inc ecx
179
 $jmp _loop
179
 $jmp _loop
180
 
180
 
181
  _done:
181
  _done:
182
 return ECX;
182
 return ECX;
183
}
183
}
184
 
184
 
185
inline signed int strcmp(dword text1, text2)
185
inline signed int strcmp(dword text1, text2)
186
{
186
{
187
	char s1,s2;
187
	char s1,s2;
188
	dword p1,p2;
188
	dword p1,p2;
189
	p1 = text1;
189
	p1 = text1;
190
	p2 = text2;
190
	p2 = text2;
191
	loop()
191
	loop()
192
	{
192
	{
193
		s1 = DSBYTE[text1];
193
		s1 = DSBYTE[text1];
194
		s2 = DSBYTE[text2];
194
		s2 = DSBYTE[text2];
195
		if(s1==s2)
195
		if(s1==s2)
196
		{
196
		{
197
			if(s1==0) return 0;
197
			if(s1==0) return 0;
198
		}
198
		}
199
		else {
199
		else {
200
			return s1-s2;
200
			return s1-s2;
201
		}
201
		}
202
		$inc text1 
202
		$inc text1 
203
		$inc text2
203
		$inc text2
204
	}
204
	}
205
	return 0;
205
	return 0;
206
}
206
}
207
 
207
 
208
 
208
 
209
inline fastcall streq(ESI, EDI)
209
inline fastcall streq(ESI, EDI)
210
{
210
{
211
	loop()
211
	loop()
212
	{
212
	{
213
		if(DSBYTE[ESI]==DSBYTE[EDI])
213
		if(DSBYTE[ESI]==DSBYTE[EDI])
214
		{
214
		{
215
			if(DSBYTE[ESI]==0) return true;
215
			if(DSBYTE[ESI]==0) return true;
216
		}
216
		}
217
		else {
217
		else {
218
			return false;
218
			return false;
219
		}
219
		}
220
		ESI++;
220
		ESI++;
221
		EDI++;
221
		EDI++;
222
	}
222
	}
223
	return true;
223
	return true;
224
}
224
}
225
 
225
 
226
inline fastcall void strcpy( EDI, ESI)
226
inline fastcall void strcpy( EDI, ESI)
227
{
227
{
228
    $cld
228
    $cld
229
L2:
229
L2:
230
    $lodsb
230
    $lodsb
231
    $stosb
231
    $stosb
232
    $test al,al
232
    $test al,al
233
    $jnz L2
233
    $jnz L2
234
}
234
}
235
 
235
 
236
inline fastcall int strlcpy(dword ESI, EDI, EBX)
236
inline fastcall int strlcpy(dword ESI, EDI, EBX)
237
{
237
{
238
    if (EBX<0) return -1;
238
    if (EBX<0) return -1;
239
    EDX=0;
239
    EDX=0;
240
    do {
240
    do {
241
        DSBYTE[ESI]=DSBYTE[EDI];
241
        DSBYTE[ESI]=DSBYTE[EDI];
242
        ESI++;
242
        ESI++;
243
        EDI++;
243
        EDI++;
244
        EDX++;
244
        EDX++;
245
        if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;}
245
        if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;}
246
    } while(DSBYTE[EDI-1]!='\0');
246
    } while(DSBYTE[EDI-1]!='\0');
247
    return 0;
247
    return 0;
248
}
248
}
249
 
249
 
250
:void strncpy(dword dst, src, len)
250
:void strncpy(dword dst, src, len)
251
{
251
{
252
	while (len) && (ESBYTE[src])
252
	while (len) && (ESBYTE[src])
253
	{
253
	{
254
		ESBYTE[dst] = ESBYTE[src];
254
		ESBYTE[dst] = ESBYTE[src];
255
		dst++;
255
		dst++;
256
		src++;
256
		src++;
257
		len--;
257
		len--;
258
	}
258
	}
259
	ESBYTE[dst]=0;
259
	ESBYTE[dst]=0;
260
}
260
}
261
 
261
 
262
/*
262
/*
263
inline fastcall void strtrim( ESI)
263
inline fastcall void strtrim( ESI)
264
{
264
{
265
    EDI = ESI;
265
    EDI = ESI;
266
    do{
266
    do{
267
        AL=DSBYTE[EDI];
267
        AL=DSBYTE[EDI];
268
        if (AL != '\32') && (AL != '\13') && (AL != '\10')
268
        if (AL != '\32') && (AL != '\13') && (AL != '\10')
269
        {
269
        {
270
            DSBYTE[ESI]=AL;
270
            DSBYTE[ESI]=AL;
271
            $inc ESI
271
            $inc ESI
272
        }
272
        }
273
         $inc EDI
273
         $inc EDI
274
    }while(AL!=0);
274
    }while(AL!=0);
275
    DSBYTE[ESI] = '\0';
275
    DSBYTE[ESI] = '\0';
276
}
276
}
277
*/
277
*/
278
 
278
 
279
inline byte __isWhite(int s){ if (s==13)||(s==32)||(s==10)||(s==9) return true; return false; }
279
inline byte __isWhite(int s){ if (s==13)||(s==32)||(s==10)||(s==9) return true; return false; }
280
inline void strltrim(dword text){
280
inline void strltrim(dword text){
281
	int s;
281
	int s;
282
	dword back_text;
282
	dword back_text;
283
	back_text = text;
283
	back_text = text;
284
	s = ESBYTE[text];
284
	s = ESBYTE[text];
285
	while(__isWhite(s))
285
	while(__isWhite(s))
286
	{
286
	{
287
		$inc text
287
		$inc text
288
		s = ESBYTE[text];
288
		s = ESBYTE[text];
289
	}
289
	}
290
	loop()
290
	loop()
291
	{
291
	{
292
		ESBYTE[back_text] = s;
292
		ESBYTE[back_text] = s;
293
		$inc back_text
293
		$inc back_text
294
		if(!s) break;
294
		if(!s) break;
295
		$inc text
295
		$inc text
296
		s = ESBYTE[text];
296
		s = ESBYTE[text];
297
	};
297
	};
298
}
298
}
299
 
299
 
300
inline void strrtrim(dword text)
300
inline void strrtrim(dword text)
301
{
301
{
302
	int s;
302
	int s;
303
	dword p;
303
	dword p;
304
	do {
304
	do {
305
		s = ESBYTE[text];
305
		s = ESBYTE[text];
306
		if(__isWhite(s))
306
		if(__isWhite(s))
307
		{
307
		{
308
			p = text;
308
			p = text;
309
			while(__isWhite(s))
309
			while(__isWhite(s))
310
			{
310
			{
311
				$inc text;
311
				$inc text;
312
				s = ESBYTE[text];
312
				s = ESBYTE[text];
313
			}
313
			}
314
		}
314
		}
315
		else $inc text
315
		else $inc text
316
	} while(s);
316
	} while(s);
317
	$dec text
317
	$dec text
318
	s = ESBYTE[text];
318
	s = ESBYTE[text];
319
	if(__isWhite(s)) ESBYTE[p] = 0;
319
	if(__isWhite(s)) ESBYTE[p] = 0;
320
}
320
}
321
 
321
 
322
inline void strtrim(dword text){
322
inline void strtrim(dword text){
323
	int s;
323
	int s;
324
	dword p,back_text;
324
	dword p,back_text;
325
	back_text = text;
325
	back_text = text;
326
	s = ESBYTE[text];
326
	s = ESBYTE[text];
327
	while(__isWhite(s))
327
	while(__isWhite(s))
328
	{
328
	{
329
		$inc text
329
		$inc text
330
		s = ESBYTE[text];
330
		s = ESBYTE[text];
331
	} 
331
	} 
332
	do {
332
	do {
333
		s = ESBYTE[text];
333
		s = ESBYTE[text];
334
		if(__isWhite(s))
334
		if(__isWhite(s))
335
		{
335
		{
336
			p = back_text;
336
			p = back_text;
337
			while(__isWhite(s))
337
			while(__isWhite(s))
338
			{
338
			{
339
				ESBYTE[back_text] = s;
339
				ESBYTE[back_text] = s;
340
				$inc back_text
340
				$inc back_text
341
				$inc text;
341
				$inc text;
342
				s = ESBYTE[text];
342
				s = ESBYTE[text];
343
			}
343
			}
344
		}
344
		}
345
		else {
345
		else {
346
			ESBYTE[back_text] = s;
346
			ESBYTE[back_text] = s;
347
			$inc back_text
347
			$inc back_text
348
			$inc text
348
			$inc text
349
		}
349
		}
350
	} while(s);
350
	} while(s);
351
	$dec text
351
	$dec text
352
	s = ESBYTE[text];
352
	s = ESBYTE[text];
353
	if(__isWhite(s)) ESBYTE[p] = 0;
353
	if(__isWhite(s)) ESBYTE[p] = 0;
354
}
354
}
355
 
355
 
356
inline fastcall void strcat( EDI, ESI)
356
inline fastcall void strcat( EDI, ESI)
357
{
357
{
358
  asm {
358
  asm {
359
    mov ebx, edi
359
    mov ebx, edi
360
    xor ecx, ecx
360
    xor ecx, ecx
361
    xor eax, eax
361
    xor eax, eax
362
    dec ecx
362
    dec ecx
363
    repne scasb
363
    repne scasb
364
    dec edi
364
    dec edi
365
    mov edx, edi
365
    mov edx, edi
366
    mov edi, esi
366
    mov edi, esi
367
    xor ecx, ecx
367
    xor ecx, ecx
368
    xor eax, eax
368
    xor eax, eax
369
    dec ecx
369
    dec ecx
370
    repne scasb
370
    repne scasb
371
    xor ecx, 0ffffffffh
371
    xor ecx, 0ffffffffh
372
    mov edi, edx
372
    mov edi, edx
373
    mov edx, ecx
373
    mov edx, ecx
374
    mov eax, edi
374
    mov eax, edi
375
    shr ecx, 2
375
    shr ecx, 2
376
    rep movsd
376
    rep movsd
377
    mov ecx, edx
377
    mov ecx, edx
378
    and ecx, 3
378
    and ecx, 3
379
    rep movsb
379
    rep movsb
380
    mov eax, ebx
380
    mov eax, ebx
381
    }
381
    }
382
}
382
}
383
 
383
 
384
:void strncat(dword dst, src, len)
384
:void strncat(dword dst, src, len)
385
{
385
{
386
	while (ESBYTE[dst]) && (len) {
386
	while (ESBYTE[dst]) && (len) {
387
		dst++;
387
		dst++;
388
		len--;
388
		len--;
389
	}
389
	}
390
	while (ESBYTE[src]) && (len>1) {
390
	while (ESBYTE[src]) && (len>1) {
391
		ESBYTE[dst] = ESBYTE[src];
391
		ESBYTE[dst] = ESBYTE[src];
392
		dst++;
392
		dst++;
393
		src++;
393
		src++;
394
		len--;
394
		len--;
395
	}
395
	}
396
	ESBYTE[dst] = 0;
396
	ESBYTE[dst] = 0;
397
}
397
}
398
 
398
 
399
:void chrncat(dword dst, unsigned char s, dword len)
399
:void chrncat(dword dst, unsigned char s, dword len)
400
{
400
{
401
	while (ESBYTE[dst]) && (len) {
401
	while (ESBYTE[dst]) && (len) {
402
		dst++;
402
		dst++;
403
		len--;
403
		len--;
404
	}
404
	}
405
	if (len>1) {
405
	if (len>1) {
406
		ESBYTE[dst] = s;
406
		ESBYTE[dst] = s;
407
		ESBYTE[dst+1] = 0;
407
		ESBYTE[dst+1] = 0;
408
	}
408
	}
409
}
409
}
410
 
410
 
411
inline fastcall void chrcat(ESI, DI)
411
inline fastcall void chrcat(ESI, DI)
412
{
412
{
413
    while (ESBYTE[ESI]) ESI++;
413
    while (ESBYTE[ESI]) ESI++;
414
    ESBYTE[ESI] = DI;
414
    ESBYTE[ESI] = DI;
415
    ESI++;
415
    ESI++;
416
    ESBYTE[ESI] = 0;
416
    ESBYTE[ESI] = 0;
417
}
417
}
418
 
418
 
419
inline dword strchr(dword shb;char s)
419
inline dword strchr(dword shb;char s)
420
{
420
{
421
	char ss;
421
	char ss;
422
	loop()
422
	loop()
423
	{
423
	{
424
		ss = DSBYTE[shb];
424
		ss = DSBYTE[shb];
425
		if(!ss)return 0;
425
		if(!ss)return 0;
426
		if(ss==s)return shb;
426
		if(ss==s)return shb;
427
		shb++;
427
		shb++;
428
	}
428
	}
429
}
429
}
430
 
430
 
431
inline fastcall signed int strrchr( ESI,BL)
431
inline fastcall signed int strrchr( ESI,BL)
432
{
432
{
433
    int jj=0, last=0;
433
    int jj=0, last=0;
434
    do{
434
    do{
435
        jj++;
435
        jj++;
436
        $lodsb
436
        $lodsb
437
        IF(AL==BL) last=jj;
437
        IF(AL==BL) last=jj;
438
    } while(AL!=0);
438
    } while(AL!=0);
439
    return last;
439
    return last;
440
}
440
}
441
 
441
 
442
 
442
 
443
inline fastcall unsigned int chrnum( ESI, BL)
443
inline fastcall unsigned int chrnum( ESI, BL)
444
{
444
{
445
    int num = 0;
445
    int num = 0;
446
    while(DSBYTE[ESI])
446
    while(DSBYTE[ESI])
447
    { 
447
    { 
448
        if (DSBYTE[ESI] == BL) num++;
448
        if (DSBYTE[ESI] == BL) num++;
449
        ESI++;
449
        ESI++;
450
    }
450
    }
451
    return num;
451
    return num;
452
}
452
}
453
 
453
 
454
 
454
 
455
inline fastcall signed int strstr( EBX, EDX)
455
inline fastcall signed int strstr( EBX, EDX)
456
{
456
{
457
  asm {
457
  asm {
458
    MOV EDI, EDX
458
    MOV EDI, EDX
459
    XOR ECX, ECX
459
    XOR ECX, ECX
460
    XOR EAX, EAX
460
    XOR EAX, EAX
461
    DEC ECX
461
    DEC ECX
462
    REPNE SCASB
462
    REPNE SCASB
463
    NOT ECX
463
    NOT ECX
464
    DEC ECX
464
    DEC ECX
465
    JE LS2
465
    JE LS2
466
    MOV ESI, ECX
466
    MOV ESI, ECX
467
    XOR ECX, ECX
467
    XOR ECX, ECX
468
    MOV EDI, EBX
468
    MOV EDI, EBX
469
    DEC ECX
469
    DEC ECX
470
    REPNE SCASB
470
    REPNE SCASB
471
    NOT ECX
471
    NOT ECX
472
    SUB ECX, ESI
472
    SUB ECX, ESI
473
    JBE LS2
473
    JBE LS2
474
    MOV EDI, EBX
474
    MOV EDI, EBX
475
    LEA EBX, DSDWORD[ ESI-1]
475
    LEA EBX, DSDWORD[ ESI-1]
476
LS1: MOV ESI, EDX
476
LS1: MOV ESI, EDX
477
    LODSB
477
    LODSB
478
    REPNE SCASB
478
    REPNE SCASB
479
    JNE LS2
479
    JNE LS2
480
    MOV EAX, ECX
480
    MOV EAX, ECX
481
    PUSH EDI
481
    PUSH EDI
482
    MOV ECX, EBX
482
    MOV ECX, EBX
483
    REPE CMPSB
483
    REPE CMPSB
484
    POP EDI
484
    POP EDI
485
    MOV ECX, EAX
485
    MOV ECX, EAX
486
    JNE LS1
486
    JNE LS1
487
    LEA EAX, DSDWORD[ EDI-1]
487
    LEA EAX, DSDWORD[ EDI-1]
488
    JMP SHORT LS3
488
    JMP SHORT LS3
489
LS2: XOR EAX, EAX
489
LS2: XOR EAX, EAX
490
LS3:
490
LS3:
491
  }
491
  }
492
}
492
}
493
 
493
 
494
inline dword strcmpi(dword cmp1, cmp2)
494
inline dword strcmpi(dword cmp1, cmp2)
495
{
495
{
496
    char si, ue;
496
    char si, ue;
497
 
497
 
498
    loop()
498
    loop()
499
    { 
499
    { 
500
        si = DSBYTE[cmp1];
500
        si = DSBYTE[cmp1];
501
        ue = DSBYTE[cmp2];
501
        ue = DSBYTE[cmp2];
502
        if (si>='A') && (si<='Z') si +=32;
502
        if (si>='A') && (si<='Z') si +=32;
503
        if (ue>='A') && (ue<='Z') ue +=32;
503
        if (ue>='A') && (ue<='Z') ue +=32;
504
        if (si != ue) return -1;
504
        if (si != ue) return -1;
505
        cmp1++;
505
        cmp1++;
506
        cmp2++;
506
        cmp2++;
507
        if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0;
507
        if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0;
508
        if (DSBYTE[cmp1]=='\0') return -1;
508
        if (DSBYTE[cmp1]=='\0') return -1;
509
        if (DSBYTE[cmp2]=='\0') return 1;
509
        if (DSBYTE[cmp2]=='\0') return 1;
510
    }
510
    }
511
}
511
}
512
 
512
 
513
inline dword strstri(dword searchin, usestr_s)
513
inline dword strstri(dword searchin, usestr_s)
514
{
514
{
515
    dword usestr_e = usestr_s;
515
    dword usestr_e = usestr_s;
516
    char si, ue;
516
    char si, ue;
517
 
517
 
518
    while(DSBYTE[searchin])
518
    while(DSBYTE[searchin])
519
    { 
519
    { 
520
        si = DSBYTE[searchin];
520
        si = DSBYTE[searchin];
521
        ue = DSBYTE[usestr_e];
521
        ue = DSBYTE[usestr_e];
522
        if (si>='A') && (si<='Z') si +=32;
522
        if (si>='A') && (si<='Z') si +=32;
523
        if (ue>='A') && (ue<='Z') ue +=32;
523
        if (ue>='A') && (ue<='Z') ue +=32;
524
        if (si == ue) usestr_e++; else usestr_e = usestr_s;
524
        if (si == ue) usestr_e++; else usestr_e = usestr_s;
525
        searchin++;
525
        searchin++;
526
        if (DSBYTE[usestr_e]=='\0') return searchin;
526
        if (DSBYTE[usestr_e]=='\0') return searchin;
527
    }
527
    }
528
    return -1;
528
    return -1;
529
}
529
}
530
 
530
 
531
 
531
 
532
inline unsigned int strcpyb(dword search_in, copyin, startstr, endstr)
532
inline unsigned int strcpyb(dword search_in, copyin, startstr, endstr)
533
{
533
{
534
    dword startp, endp;
534
    dword startp, endp;
535
    dword copyin_start_off = copyin;
535
    dword copyin_start_off = copyin;
536
    if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr);
536
    if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr);
537
    endp = strstri(startp, endstr);
537
    endp = strstri(startp, endstr);
538
    if (endp==0) endp = startp+strlen(search_in);
538
    if (endp==0) endp = startp+strlen(search_in);
539
    //if (startp==endp) return 0;
539
    //if (startp==endp) return 0;
540
    do
540
    do
541
    { 
541
    { 
542
        DSBYTE[copyin] = DSBYTE[startp];
542
        DSBYTE[copyin] = DSBYTE[startp];
543
        copyin++;
543
        copyin++;
544
        startp++;
544
        startp++;
545
    }
545
    }
546
    while (startp
546
    while (startp
547
    DSBYTE[copyin] = '\0';
547
    DSBYTE[copyin] = '\0';
548
    return copyin_start_off;
548
    return copyin_start_off;
549
}
549
}
550
 
550
 
551
 
551
 
552
/*void strcat(char *to, char *from) 
552
/*void strcat(char *to, char *from) 
553
{
553
{
554
    while(*to) to++;
554
    while(*to) to++;
555
    while(*from)
555
    while(*from)
556
    {
556
    {
557
        *to = *from;
557
        *to = *from;
558
        to++;
558
        to++;
559
        from++;
559
        from++;
560
    }
560
    }
561
    *to = '\0';
561
    *to = '\0';
562
}*/
562
}*/
563
 
563
 
564
 
564
 
565
inline fastcall dword atoi( EDI)
565
inline fastcall dword atoi( EDI)
566
{
566
{
567
    $push ebx
567
    $push ebx
568
    $push esi
568
    $push esi
569
    ESI=EDI;
569
    ESI=EDI;
570
    while (DSBYTE[ESI]==' ') ESI++;
570
    while (DSBYTE[ESI]==' ') ESI++;
571
    if (DSBYTE[ESI]=='-') ESI++;
571
    if (DSBYTE[ESI]=='-') ESI++;
572
    EAX=0;
572
    EAX=0;
573
    while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9')
573
    while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9')
574
    {
574
    {
575
        $xor ebx, ebx
575
        $xor ebx, ebx
576
        EBX = DSBYTE[ESI]-'0';
576
        EBX = DSBYTE[ESI]-'0';
577
        EAX *= 10;
577
        EAX *= 10;
578
        EAX += EBX;
578
        EAX += EBX;
579
        ESI++;
579
        ESI++;
580
    } 
580
    } 
581
    IF (DSBYTE[EDI]=='-') -EAX;
581
    IF (DSBYTE[EDI]=='-') -EAX;
582
    $pop esi
582
    $pop esi
583
    $pop ebx
583
    $pop ebx
584
}
584
}
585
 
585
 
586
 
586
 
587
 
587
 
588
inline fastcall strupr( ESI)
588
inline fastcall strupr( ESI)
589
{
589
{
590
    do{
590
    do{
591
        AL=DSBYTE[ESI];
591
        AL=DSBYTE[ESI];
592
        IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f;
592
        IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f;
593
        IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32;    //à-ï
593
        IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32;    //à-ï
594
        IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80;    //à-ï
594
        IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80;    //à-ï
595
         ESI++;
595
         ESI++;
596
    }while(AL!=0);
596
    }while(AL!=0);
597
}
597
}
598
 
598
 
599
inline fastcall strlwr( ESI)
599
inline fastcall strlwr( ESI)
600
{
600
{
601
    do{
601
    do{
602
        $LODSB
602
        $LODSB
603
        IF(AL>='A')&&(AL<='Z'){
603
        IF(AL>='A')&&(AL<='Z'){
604
            AL+=0x20;
604
            AL+=0x20;
605
            DSBYTE[ESI-1]=AL;
605
            DSBYTE[ESI-1]=AL;
606
            CONTINUE;
606
            CONTINUE;
607
        }
607
        }
608
    }while(AL!=0);
608
    }while(AL!=0);
609
}
609
}
610
 
610
 
611
inline fastcall strttl( EDX)
611
inline fastcall strttl( EDX)
612
{
612
{
613
    AL=DSBYTE[EDX];
613
    AL=DSBYTE[EDX];
614
    IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
614
    IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
615
    IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;    //à-ï
615
    IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;    //à-ï
616
    IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;    //à-ï
616
    IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;    //à-ï
617
    do{
617
    do{
618
        EDX++;
618
        EDX++;
619
        AL=DSBYTE[EDX];
619
        AL=DSBYTE[EDX];
620
        IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
620
        IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
621
        IF(AL>='€')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯
621
        IF(AL>='€')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯
622
        IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;    //à-ï
622
        IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;    //à-ï
623
    }while(AL!=0);
623
    }while(AL!=0);
624
}
624
}
625
 
625
 
626
/*
626
/*
627
dword itoa( ESI)
627
dword itoa( ESI)
628
{
628
{
629
    unsigned char buffer[11];
629
    unsigned char buffer[11];
630
    $pusha
630
    $pusha
631
    EDI = #buffer;
631
    EDI = #buffer;
632
    ECX = 10;
632
    ECX = 10;
633
    if (ESI < 0)
633
    if (ESI < 0)
634
    {
634
    {
635
         $mov     al, '-'
635
         $mov     al, '-'
636
         $stosb
636
         $stosb
637
         $neg     esi
637
         $neg     esi
638
    }
638
    }
639
 
639
 
640
    $mov     eax, esi
640
    $mov     eax, esi
641
    $push    -'0'
641
    $push    -'0'
642
F2:
642
F2:
643
    $xor     edx, edx
643
    $xor     edx, edx
644
    $div     ecx
644
    $div     ecx
645
    $push    edx
645
    $push    edx
646
    $test    eax, eax
646
    $test    eax, eax
647
    $jnz     F2
647
    $jnz     F2
648
F3:
648
F3:
649
    $pop     eax
649
    $pop     eax
650
    $add     al, '0'
650
    $add     al, '0'
651
    $stosb
651
    $stosb
652
    $jnz     F3
652
    $jnz     F3
653
    
653
    
654
    $mov     al, '\0'
654
    $mov     al, '\0'
655
    $stosb
655
    $stosb
656
 
656
 
657
    $popa
657
    $popa
658
    return #buffer;
658
    return #buffer;
659
}
659
}
660
*/
660
*/
661
:unsigned char BUF_ITOA[11];
661
:unsigned char BUF_ITOA[11];
662
inline dword itoa(signed long number)
662
inline dword itoa(signed long number)
663
{
663
{
664
	dword ret,p;
664
	dword ret,p;
665
	byte cmd;
665
	byte cmd;
666
	long mask,tmp;
666
	long mask,tmp;
667
	mask = 1000000000;
667
	mask = 1000000000;
668
	cmd = true;
668
	cmd = true;
669
	p = #BUF_ITOA;
669
	p = #BUF_ITOA;
670
	if(!number){
670
	if(!number){
671
		ESBYTE[p] = '0';
671
		ESBYTE[p] = '0';
672
		ESBYTE[p+1] = 0;
672
		ESBYTE[p+1] = 0;
673
		return p;
673
		return p;
674
	}
674
	}
675
	ret = p;
675
	ret = p;
676
	if(number<0)
676
	if(number<0)
677
	{
677
	{
678
		$neg number
678
		$neg number
679
		ESBYTE[p] = '-';
679
		ESBYTE[p] = '-';
680
		$inc p
680
		$inc p
681
	}
681
	}
682
	while(mask)
682
	while(mask)
683
	{
683
	{
684
		tmp = number / mask;
684
		tmp = number / mask;
685
		tmp = tmp%10;
685
		tmp = tmp%10;
686
		
686
		
687
		if(cmd){
687
		if(cmd){
688
			if(tmp){
688
			if(tmp){
689
				ESBYTE[p] = tmp + '0';
689
				ESBYTE[p] = tmp + '0';
690
				$inc p
690
				$inc p
691
				cmd = false;
691
				cmd = false;
692
			}
692
			}
693
		}
693
		}
694
		else {
694
		else {
695
			ESBYTE[p] = tmp + '0';
695
			ESBYTE[p] = tmp + '0';
696
			$inc p
696
			$inc p
697
		}
697
		}
698
		mask /= 10;
698
		mask /= 10;
699
	}
699
	}
700
	ESBYTE[p] = 0;
700
	ESBYTE[p] = 0;
701
	return ret;
701
	return ret;
702
}
702
}
703
 
703
 
704
inline fastcall itoa_(signed int EDI, ESI)
704
inline fastcall itoa_(signed int EDI, ESI)
705
{
705
{
706
    $pusha
706
    $pusha
707
    EBX = EDI;
707
    EBX = EDI;
708
    ECX = 10;
708
    ECX = 10;
709
    if (ESI > 90073741824)
709
    if (ESI > 90073741824)
710
    {
710
    {
711
         $mov     al, '-'
711
         $mov     al, '-'
712
         $stosb
712
         $stosb
713
         $neg     esi
713
         $neg     esi
714
    }
714
    }
715
 
715
 
716
    $mov     eax, esi
716
    $mov     eax, esi
717
    $push    -'0'
717
    $push    -'0'
718
F2:
718
F2:
719
    $xor     edx, edx
719
    $xor     edx, edx
720
    $div     ecx
720
    $div     ecx
721
    $push    edx
721
    $push    edx
722
    $test    eax, eax
722
    $test    eax, eax
723
    $jnz     F2
723
    $jnz     F2
724
F3:
724
F3:
725
    $pop     eax
725
    $pop     eax
726
    $add     al, '0'
726
    $add     al, '0'
727
    $stosb
727
    $stosb
728
    $jnz     F3
728
    $jnz     F3
729
    
729
    
730
    $mov     al, '\0'
730
    $mov     al, '\0'
731
    $stosb
731
    $stosb
732
 
732
 
733
    $popa
733
    $popa
734
    return EBX;
734
    return EBX;
735
} 
735
} 
736
 
736
 
737
inline dword memchr(dword s,int c,signed len)
737
inline dword memchr(dword s,int c,signed len)
738
{
738
{
739
	if(!len) return NULL;
739
	if(!len) return NULL;
740
	do {
740
	do {
741
		if(DSBYTE[s] == c) return s;
741
		if(DSBYTE[s] == c) return s;
742
		$inc s
742
		$inc s
743
		$dec len
743
		$dec len
744
	} while(len);
744
	} while(len);
745
	return NULL;
745
	return NULL;
746
}
746
}
747
 
747
 
748
inline dword strdup(dword text)
748
inline dword strdup(dword text)
749
{
749
{
750
    dword l = strlen(text);
750
    dword l = strlen(text);
751
    dword ret = malloc(l+1);
751
    dword ret = malloc(l+1);
752
	if(!ret) return NULL;
752
	if(!ret) return NULL;
753
    strlcpy(ret,text,l);
753
    strlcpy(ret,text,l);
754
    return ret;
754
    return ret;
755
}
755
}
756
 
756
 
757
inline dword strndup(dword str, signed maxlen)
757
inline dword strndup(dword str, signed maxlen)
758
{
758
{
759
	dword copy,len;
759
	dword copy,len;
760
 
760
 
761
	len = strnlen(str, maxlen);
761
	len = strnlen(str, maxlen);
762
	copy = malloc(len + 1);
762
	copy = malloc(len + 1);
763
	if (copy != NULL)
763
	if (copy != NULL)
764
	{
764
	{
765
		strlcpy(copy, str, len);
765
		strlcpy(copy, str, len);
766
		DSBYTE[len+copy] = '\0';
766
		DSBYTE[len+copy] = '\0';
767
	}
767
	}
768
	return copy;
768
	return copy;
769
}
769
}
770
 
770
 
771
inline dword hexdec(dword text)
771
inline dword hexdec(dword text)
772
{
772
{
773
	char s;
773
	char s;
774
	dword ret,l;
774
	dword ret,l;
775
	ret = 0;
775
	ret = 0;
776
	s = DSBYTE[text];
776
	s = DSBYTE[text];
777
	while(s)
777
	while(s)
778
	{	
778
	{	
779
		ret <<= 4;
779
		ret <<= 4;
780
		if(s>='A')&&(s<='F')ret |= s-'A'+10;
780
		if(s>='A')&&(s<='F')ret |= s-'A'+10;
781
		else if(s>='a')&&(s<='f')ret |= s-'a'+10;
781
		else if(s>='a')&&(s<='f')ret |= s-'a'+10;
782
		else if(s>='0')&&(s<='9')ret |= s-'0';
782
		else if(s>='0')&&(s<='9')ret |= s-'0';
783
		text++;
783
		text++;
784
		s = DSBYTE[text];
784
		s = DSBYTE[text];
785
	}
785
	}
786
	return ret;
786
	return ret;
787
}
787
}
788
 
788
 
789
inline signed csshexdec(dword text)
789
inline signed csshexdec(dword text)
790
{
790
{
791
	char s;
791
	char s;
792
	dword ret,l;
792
	dword ret,l;
793
	byte tmp;
793
	byte tmp;
794
	l = strlen(text);
794
	l = strlen(text);
795
	ret = 0;
795
	ret = 0;
796
	s = DSBYTE[text];
796
	s = DSBYTE[text];
797
	tmp = 0;
797
	tmp = 0;
798
	if(l==6) while(s)
798
	if(l==6) while(s)
799
	{	
799
	{	
800
		ret <<= 4;
800
		ret <<= 4;
801
		if(s>='A')&&(s<='F')ret |= s-'A'+10;
801
		if(s>='A')&&(s<='F')ret |= s-'A'+10;
802
		else if(s>='a')&&(s<='f')ret |= s-'a'+10;
802
		else if(s>='a')&&(s<='f')ret |= s-'a'+10;
803
		else if(s>='0')&&(s<='9')ret |= s-'0';
803
		else if(s>='0')&&(s<='9')ret |= s-'0';
804
		text++;
804
		text++;
805
		s = DSBYTE[text];
805
		s = DSBYTE[text];
806
	}
806
	}
807
	else if(l==3) while(s)
807
	else if(l==3) while(s)
808
	{	
808
	{	
809
		ret |= tmp;
809
		ret |= tmp;
810
		ret <<= 4;
810
		ret <<= 4;
811
		ret |= tmp;
811
		ret |= tmp;
812
		ret <<= 4;
812
		ret <<= 4;
813
		if(s>='A')&&(s<='F')tmp = s-'A'+10;
813
		if(s>='A')&&(s<='F')tmp = s-'A'+10;
814
		else if(s>='a')&&(s<='f')tmp = s-'a'+10;
814
		else if(s>='a')&&(s<='f')tmp = s-'a'+10;
815
		else if(s>='0')&&(s<='9')tmp = s-'0';
815
		else if(s>='0')&&(s<='9')tmp = s-'0';
816
		text++;
816
		text++;
817
		s = DSBYTE[text];
817
		s = DSBYTE[text];
818
	}
818
	}
819
	return ret;
819
	return ret;
820
}
820
}
821
 
821
 
822
inline cdecl int sprintf(dword buf, format,...)
822
inline cdecl int sprintf(dword buf, format,...)
823
{
823
{
824
	#define END_ARGS 0xFF00FF //ARGS FUNCTION
824
	#define END_ARGS 0xFF00FF //ARGS FUNCTION
825
	byte s;
825
	byte s;
826
	char X[10];
826
	char X[10];
827
	dword ret, tmp, l;
827
	dword ret, tmp, l;
828
	dword arg = #format;
828
	dword arg = #format;
829
	ret = buf;
829
	ret = buf;
830
	s = DSBYTE[format];
830
	s = DSBYTE[format];
831
	while(s){
831
	while(s){
832
		if(s=='%'){
832
		if(s=='%'){
833
			arg+=4;
833
			arg+=4;
834
			tmp = DSDWORD[arg];
834
			tmp = DSDWORD[arg];
835
			if(tmp==END_ARGS)goto END_FUNC_SPRINTF;
835
			if(tmp==END_ARGS)goto END_FUNC_SPRINTF;
836
			$inc format
836
			$inc format
837
			s = DSBYTE[format];
837
			s = DSBYTE[format];
838
			if(!s)goto END_FUNC_SPRINTF;
838
			if(!s)goto END_FUNC_SPRINTF;
839
			switch(s)
839
			switch(s)
840
			{
840
			{
841
				case 's':
841
				case 's':
842
					l = tmp;
842
					l = tmp;
843
					s = DSBYTE[tmp];
843
					s = DSBYTE[tmp];
844
					while(s)
844
					while(s)
845
					{
845
					{
846
						DSBYTE[buf] = s;
846
						DSBYTE[buf] = s;
847
						$inc tmp
847
						$inc tmp
848
						$inc buf
848
						$inc buf
849
						s = DSBYTE[tmp];
849
						s = DSBYTE[tmp];
850
					}
850
					}
851
				break;
851
				break;
852
				case 'c':
852
				case 'c':
853
					DSBYTE[buf] = tmp;
853
					DSBYTE[buf] = tmp;
854
					$inc buf
854
					$inc buf
855
				break;
855
				break;
856
				case 'u': //if(tmp<0)return ret;
856
				case 'u': //if(tmp<0)return ret;
857
				case 'd':
857
				case 'd':
858
				case 'i':
858
				case 'i':
859
					tmp = itoa(tmp);
859
					tmp = itoa(tmp);
860
					if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
860
					if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
861
					l = strlen(tmp);
861
					l = strlen(tmp);
862
					strlcpy(buf,tmp,l);
862
					strlcpy(buf,tmp,l);
863
					buf += l;
863
					buf += l;
864
				break;
864
				break;
865
				case 'a':
865
				case 'a':
866
				case 'A':
866
				case 'A':
867
					strlcpy(buf,"0x00000000",10);
867
					strlcpy(buf,"0x00000000",10);
868
					buf+=10;
868
					buf+=10;
869
					l=buf;
869
					l=buf;
-
 
870
					debugval("tmp", tmp);
870
					while(tmp)
871
					while(tmp)
871
					{
872
					{
872
						$dec buf
873
						$dec buf
873
						s=tmp&0xF;
874
						s=tmp&0xF;
874
						if(s>9)DSBYTE[buf]='A'+s-10;
875
						if(s>9)DSBYTE[buf]='A'+s-10;
875
						else DSBYTE[buf]='0'+s;
876
						else DSBYTE[buf]='0'+s;
876
						tmp>>=4;
877
						tmp>>=4;
877
					}
878
					}
878
					buf=l;
879
					buf=l;
879
				break;
880
				break;
880
				case 'p':
881
				case 'p':
881
					tmp = itoa(#tmp);
882
					tmp = itoa(#tmp);
882
					if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
883
					if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
883
					l = strlen(tmp);
884
					l = strlen(tmp);
884
					strlcpy(buf,tmp,l);
885
					strlcpy(buf,tmp,l);
885
					buf += l;
886
					buf += l;
886
				break;
887
				break;
887
				case '%':
888
				case '%':
888
					DSBYTE[buf] = '%';
889
					DSBYTE[buf] = '%';
889
					$inc buf
890
					$inc buf
890
				break;
891
				break;
891
				default:
892
				default:
892
				goto END_FUNC_SPRINTF;
893
				goto END_FUNC_SPRINTF;
893
			}
894
			}
894
		}
895
		}
895
		else {
896
		else {
896
			DSBYTE[buf] = s;
897
			DSBYTE[buf] = s;
897
			$inc buf
898
			$inc buf
898
		}
899
		}
899
		$inc format
900
		$inc format
900
		s = DSBYTE[format];
901
		s = DSBYTE[format];
901
	}
902
	}
902
	END_FUNC_SPRINTF:
903
	END_FUNC_SPRINTF:
903
	DSBYTE[buf] = 0;
904
	DSBYTE[buf] = 0;
904
	return ret;
905
	return ret;
905
}
906
}
906
 
907
 
907
inline signed strcoll(dword text1,text2)
908
inline signed strcoll(dword text1,text2)
908
{
909
{
909
	char s,ss;
910
	char s,ss;
910
	loop()
911
	loop()
911
	{
912
	{
912
		s = DSBYTE[text2];
913
		s = DSBYTE[text2];
913
		ss=strchr(text1,s);
914
		ss=strchr(text1,s);
914
		if(ss)return ss;
915
		if(ss)return ss;
915
		text2++;
916
		text2++;
916
	}
917
	}
917
	return 0;
918
	return 0;
918
}
919
}
919
 
920
 
920
// void * memset( ptr, value, num );
921
// void * memset( ptr, value, num );
921
// fills the memory with a dword
922
// fills the memory with a dword
922
// example: memset(str,'-', sizeof(str));
923
// example: memset(str,'-', sizeof(str));
923
inline void MEMSETD(EDI,ECX,EAX)
924
inline void MEMSETD(EDI,ECX,EAX)
924
{
925
{
925
	$REP 
926
	$REP 
926
	$STOSD
927
	$STOSD
927
}
928
}
928
 
929
 
929
:replace_char(dword in_str, char from_char, to_char, int length) {
930
:replace_char(dword in_str, char from_char, to_char, int length) {
930
	int i;
931
	int i;
931
	for (i=0; i
932
	for (i=0; i
932
		if (ESBYTE[in_str+i] == from_char) ESBYTE[in_str+i] = to_char;
933
		if (ESBYTE[in_str+i] == from_char) ESBYTE[in_str+i] = to_char;
933
	}
934
	}
934
	ESBYTE[in_str+length]=0;
935
	ESBYTE[in_str+length]=0;
935
}
936
}
936
 
937
 
937
#endif
938
#endif
938
>
939
>
939
>
940
>
940
>
941
>
941
>
942
>
942
>
943
>
943
>
944
>