Subversion Repositories Kolibri OS

Rev

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

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