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