Rev 8484 | Rev 9439 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8484 | Rev 8868 | ||
---|---|---|---|
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 bool streq(ESI, EDI) |
209 | inline fastcall bool 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 | } |
223 | } |
224 | 224 | ||
225 | inline fastcall bool streqrp(ESI, EDI) //streq right part |
225 | inline fastcall bool streqrp(ESI, EDI) //streq right part |
226 | { |
226 | { |
227 | if(DSBYTE[ESI]==0) || (DSBYTE[EDI]==0) return false; |
227 | if(DSBYTE[ESI]==0) || (DSBYTE[EDI]==0) return false; |
228 | loop() |
228 | loop() |
229 | { |
229 | { |
230 | if(DSBYTE[EDI]==0) return true; |
230 | if(DSBYTE[EDI]==0) return true; |
231 | if(DSBYTE[ESI]!=DSBYTE[EDI]) return false; |
231 | if(DSBYTE[ESI]!=DSBYTE[EDI]) return false; |
232 | ESI++; |
232 | ESI++; |
233 | EDI++; |
233 | EDI++; |
234 | } |
234 | } |
235 | } |
235 | } |
236 | 236 | ||
237 | inline fastcall void strcpy( EDI, ESI) |
237 | inline fastcall void strcpy( EDI, ESI) |
238 | { |
238 | { |
239 | $cld |
239 | $cld |
240 | L2: |
240 | L2: |
241 | $lodsb |
241 | $lodsb |
242 | $stosb |
242 | $stosb |
243 | $test al,al |
243 | $test al,al |
244 | $jnz L2 |
244 | $jnz L2 |
245 | } |
245 | } |
246 | 246 | ||
247 | inline fastcall int strlcpy(dword ESI, EDI, EBX) |
247 | inline fastcall int strlcpy(dword ESI, EDI, EBX) |
248 | { |
248 | { |
249 | if (EBX<0) return -1; |
249 | if (EBX<0) return -1; |
250 | EDX=0; |
250 | EDX=0; |
251 | do { |
251 | do { |
252 | DSBYTE[ESI]=DSBYTE[EDI]; |
252 | DSBYTE[ESI]=DSBYTE[EDI]; |
253 | ESI++; |
253 | ESI++; |
254 | EDI++; |
254 | EDI++; |
255 | EDX++; |
255 | EDX++; |
256 | if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;} |
256 | if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;} |
257 | } while(DSBYTE[EDI-1]!='\0'); |
257 | } while(DSBYTE[EDI-1]!='\0'); |
258 | return 0; |
258 | return 0; |
259 | } |
259 | } |
260 | 260 | ||
261 | :void strncpy(dword dst, src, len) |
261 | :void strncpy(dword dst, src, len) |
262 | { |
262 | { |
263 | while (len) && (ESBYTE[src]) |
263 | while (len) && (ESBYTE[src]) |
264 | { |
264 | { |
265 | ESBYTE[dst] = ESBYTE[src]; |
265 | ESBYTE[dst] = ESBYTE[src]; |
266 | dst++; |
266 | dst++; |
267 | src++; |
267 | src++; |
268 | len--; |
268 | len--; |
269 | } |
269 | } |
270 | ESBYTE[dst]=0; |
270 | ESBYTE[dst]=0; |
271 | } |
271 | } |
272 | 272 | ||
273 | /* |
273 | /* |
274 | inline fastcall void strtrim( ESI) |
274 | inline fastcall void strtrim( ESI) |
275 | { |
275 | { |
276 | EDI = ESI; |
276 | EDI = ESI; |
277 | do{ |
277 | do{ |
278 | AL=DSBYTE[EDI]; |
278 | AL=DSBYTE[EDI]; |
279 | if (AL != '\32') && (AL != '\13') && (AL != '\10') |
279 | if (AL != '\32') && (AL != '\13') && (AL != '\10') |
280 | { |
280 | { |
281 | DSBYTE[ESI]=AL; |
281 | DSBYTE[ESI]=AL; |
282 | $inc ESI |
282 | $inc ESI |
283 | } |
283 | } |
284 | $inc EDI |
284 | $inc EDI |
285 | }while(AL!=0); |
285 | }while(AL!=0); |
286 | DSBYTE[ESI] = '\0'; |
286 | DSBYTE[ESI] = '\0'; |
287 | } |
287 | } |
288 | */ |
288 | */ |
289 | 289 | ||
290 | inline byte __isWhite(int s){ if (s==13)||(s==32)||(s==10)||(s==9) return true; return false; } |
290 | inline byte __isWhite(int s){ if (s==13)||(s==32)||(s==10)||(s==9) return true; return false; } |
291 | inline void strltrim(dword text){ |
291 | inline void strltrim(dword text){ |
292 | int s; |
292 | int s; |
293 | dword back_text; |
293 | dword back_text; |
294 | back_text = text; |
294 | back_text = text; |
295 | s = ESBYTE[text]; |
295 | s = ESBYTE[text]; |
296 | while(__isWhite(s)) |
296 | while(__isWhite(s)) |
297 | { |
297 | { |
298 | $inc text |
298 | $inc text |
299 | s = ESBYTE[text]; |
299 | s = ESBYTE[text]; |
300 | } |
300 | } |
301 | loop() |
301 | loop() |
302 | { |
302 | { |
303 | ESBYTE[back_text] = s; |
303 | ESBYTE[back_text] = s; |
304 | $inc back_text |
304 | $inc back_text |
305 | if(!s) break; |
305 | if(!s) break; |
306 | $inc text |
306 | $inc text |
307 | s = ESBYTE[text]; |
307 | s = ESBYTE[text]; |
308 | }; |
308 | }; |
309 | } |
309 | } |
310 | 310 | ||
311 | inline void strrtrim(dword text) |
311 | inline void strrtrim(dword text) |
312 | { |
312 | { |
313 | int s; |
313 | int s; |
314 | dword p; |
314 | dword p; |
315 | do { |
315 | do { |
316 | s = ESBYTE[text]; |
316 | s = ESBYTE[text]; |
317 | if(__isWhite(s)) |
317 | if(__isWhite(s)) |
318 | { |
318 | { |
319 | p = text; |
319 | p = text; |
320 | while(__isWhite(s)) |
320 | while(__isWhite(s)) |
321 | { |
321 | { |
322 | $inc text; |
322 | $inc text; |
323 | s = ESBYTE[text]; |
323 | s = ESBYTE[text]; |
324 | } |
324 | } |
325 | } |
325 | } |
326 | else $inc text |
326 | else $inc text |
327 | } while(s); |
327 | } while(s); |
328 | $dec text |
328 | $dec text |
329 | s = ESBYTE[text]; |
329 | s = ESBYTE[text]; |
330 | if(__isWhite(s)) ESBYTE[p] = 0; |
330 | if(__isWhite(s)) ESBYTE[p] = 0; |
331 | } |
331 | } |
332 | 332 | ||
333 | inline void strtrim(dword text){ |
333 | inline void strtrim(dword text){ |
334 | int s; |
334 | int s; |
335 | dword p,back_text; |
335 | dword p,back_text; |
336 | back_text = text; |
336 | back_text = text; |
337 | s = ESBYTE[text]; |
337 | s = ESBYTE[text]; |
338 | while(__isWhite(s)) |
338 | while(__isWhite(s)) |
339 | { |
339 | { |
340 | $inc text |
340 | $inc text |
341 | s = ESBYTE[text]; |
341 | s = ESBYTE[text]; |
342 | } |
342 | } |
343 | do { |
343 | do { |
344 | s = ESBYTE[text]; |
344 | s = ESBYTE[text]; |
345 | if(__isWhite(s)) |
345 | if(__isWhite(s)) |
346 | { |
346 | { |
347 | p = back_text; |
347 | p = back_text; |
348 | while(__isWhite(s)) |
348 | while(__isWhite(s)) |
349 | { |
349 | { |
350 | ESBYTE[back_text] = s; |
350 | ESBYTE[back_text] = s; |
351 | $inc back_text |
351 | $inc back_text |
352 | $inc text; |
352 | $inc text; |
353 | s = ESBYTE[text]; |
353 | s = ESBYTE[text]; |
354 | } |
354 | } |
355 | } |
355 | } |
356 | else { |
356 | else { |
357 | ESBYTE[back_text] = s; |
357 | ESBYTE[back_text] = s; |
358 | $inc back_text |
358 | $inc back_text |
359 | $inc text |
359 | $inc text |
360 | } |
360 | } |
361 | } while(s); |
361 | } while(s); |
362 | $dec text |
362 | $dec text |
363 | s = ESBYTE[text]; |
363 | s = ESBYTE[text]; |
364 | if(__isWhite(s)) ESBYTE[p] = 0; |
364 | if(__isWhite(s)) ESBYTE[p] = 0; |
365 | } |
365 | } |
366 | 366 | ||
367 | inline fastcall void strcat( EDI, ESI) |
367 | inline fastcall void strcat( EDI, ESI) |
368 | { |
368 | { |
369 | asm { |
369 | asm { |
370 | mov ebx, edi |
370 | mov ebx, edi |
371 | xor ecx, ecx |
371 | xor ecx, ecx |
372 | xor eax, eax |
372 | xor eax, eax |
373 | dec ecx |
373 | dec ecx |
374 | repne scasb |
374 | repne scasb |
375 | dec edi |
375 | dec edi |
376 | mov edx, edi |
376 | mov edx, edi |
377 | mov edi, esi |
377 | mov edi, esi |
378 | xor ecx, ecx |
378 | xor ecx, ecx |
379 | xor eax, eax |
379 | xor eax, eax |
380 | dec ecx |
380 | dec ecx |
381 | repne scasb |
381 | repne scasb |
382 | xor ecx, 0ffffffffh |
382 | xor ecx, 0ffffffffh |
383 | mov edi, edx |
383 | mov edi, edx |
384 | mov edx, ecx |
384 | mov edx, ecx |
385 | mov eax, edi |
385 | mov eax, edi |
386 | shr ecx, 2 |
386 | shr ecx, 2 |
387 | rep movsd |
387 | rep movsd |
388 | mov ecx, edx |
388 | mov ecx, edx |
389 | and ecx, 3 |
389 | and ecx, 3 |
390 | rep movsb |
390 | rep movsb |
391 | mov eax, ebx |
391 | mov eax, ebx |
392 | } |
392 | } |
393 | } |
393 | } |
394 | 394 | ||
395 | :void strncat(dword dst, src, len) |
395 | :void strncat(dword dst, src, len) |
396 | { |
396 | { |
397 | while (ESBYTE[dst]) && (len) { |
397 | while (ESBYTE[dst]) && (len) { |
398 | dst++; |
398 | dst++; |
399 | len--; |
399 | len--; |
400 | } |
400 | } |
401 | while (ESBYTE[src]) && (len>1) { |
401 | while (ESBYTE[src]) && (len>1) { |
402 | ESBYTE[dst] = ESBYTE[src]; |
402 | ESBYTE[dst] = ESBYTE[src]; |
403 | dst++; |
403 | dst++; |
404 | src++; |
404 | src++; |
405 | len--; |
405 | len--; |
406 | } |
406 | } |
407 | ESBYTE[dst] = 0; |
407 | ESBYTE[dst] = 0; |
408 | } |
408 | } |
409 | 409 | ||
410 | inline fastcall void chrcat(ESI, DI) |
410 | inline fastcall void chrcat(ESI, DI) |
411 | { |
411 | { |
412 | while (ESBYTE[ESI]) ESI++; |
412 | while (ESBYTE[ESI]) ESI++; |
413 | ESBYTE[ESI] = DI; |
413 | ESBYTE[ESI] = DI; |
414 | ESI++; |
414 | ESI++; |
415 | ESBYTE[ESI] = 0; |
415 | ESBYTE[ESI] = 0; |
416 | } |
416 | } |
417 | 417 | ||
418 | inline fastcall void chrncat(EDI, AL, EDX) |
418 | inline fastcall void chrncat(EDI, AL, EDX) |
419 | { |
419 | { |
420 | while (ESBYTE[EDI]) && (EDX) { |
420 | while (ESBYTE[EDI]) && (EDX) { |
421 | EDI++; |
421 | EDI++; |
422 | EDX--; |
422 | EDX--; |
423 | } |
423 | } |
424 | ESBYTE[EDI] = AL; |
424 | ESBYTE[EDI] = AL; |
425 | EDI++; |
425 | EDI++; |
426 | ESBYTE[EDI] = 0; |
426 | ESBYTE[EDI] = 0; |
427 | } |
427 | } |
428 | 428 | ||
429 | /* |
429 | /* |
430 | inline dword strchr(ESI, BL) |
430 | inline dword strchr(ESI, BL) |
431 | { |
431 | { |
432 | loop() |
432 | loop() |
433 | { |
433 | { |
434 | AL = DSBYTE[ESI]; |
434 | AL = DSBYTE[ESI]; |
435 | if(!AL)return 0; |
435 | if(!AL)return 0; |
436 | if(AL==BL)return ESI; |
436 | if(AL==BL)return ESI; |
437 | ESI++; |
437 | ESI++; |
438 | } |
438 | } |
439 | } |
439 | } |
440 | */ |
440 | */ |
441 | 441 | ||
442 | /* |
442 | /* |
443 | :void chrncat(dword dst, unsigned char s, dword len) |
443 | :void chrncat(dword dst, unsigned char s, dword len) |
444 | { |
444 | { |
445 | while (ESBYTE[dst]) && (len) { |
445 | while (ESBYTE[dst]) && (len) { |
446 | dst++; |
446 | dst++; |
447 | len--; |
447 | len--; |
448 | } |
448 | } |
449 | if (len>1) { |
449 | if (len>1) { |
450 | ESBYTE[dst] = s; |
450 | ESBYTE[dst] = s; |
451 | ESBYTE[dst+1] = 0; |
451 | ESBYTE[dst+1] = 0; |
452 | } |
452 | } |
453 | } |
453 | } |
454 | */ |
454 | */ |
455 | 455 | ||
456 | inline dword strchr(dword shb;char s) |
456 | inline dword strchr(dword shb;char s) |
457 | { |
457 | { |
458 | char ss; |
458 | char ss; |
459 | loop() |
459 | loop() |
460 | { |
460 | { |
461 | ss = DSBYTE[shb]; |
461 | ss = DSBYTE[shb]; |
462 | if(!ss)return 0; |
462 | if(!ss)return 0; |
463 | if(ss==s)return shb; |
463 | if(ss==s)return shb; |
464 | shb++; |
464 | shb++; |
465 | } |
465 | } |
466 | } |
466 | } |
467 | 467 | ||
468 | inline dword strchrw(dword str, len) |
468 | inline dword strchrw(dword str, len) |
469 | { |
469 | { |
470 | len += str; |
470 | len += str; |
471 | loop() |
471 | loop() |
472 | { |
472 | { |
473 | if(!DSBYTE[str])return 0; |
473 | if(!DSBYTE[str])return 0; |
474 | if (__isWhite(DSBYTE[str])) return str; |
474 | if (__isWhite(DSBYTE[str])) return str; |
475 | str++; |
475 | str++; |
476 | if (str >= len) return 0; |
476 | if (str >= len) return 0; |
477 | } |
477 | } |
478 | } |
478 | } |
479 | 479 | ||
480 | inline fastcall signed int strrchr( ESI,BL) |
480 | inline fastcall signed int strrchr( ESI,BL) |
481 | { |
481 | { |
482 | int jj=0, last=0; |
482 | int jj=0, last=0; |
483 | do{ |
483 | do{ |
484 | jj++; |
484 | jj++; |
485 | $lodsb |
485 | $lodsb |
486 | IF(AL==BL) last=jj; |
486 | IF(AL==BL) last=jj; |
487 | } while(AL!=0); |
487 | } while(AL!=0); |
488 | return last; |
488 | return last; |
489 | } |
489 | } |
490 | 490 | ||
491 | 491 | ||
492 | inline fastcall unsigned int chrnum( ESI, BL) |
492 | inline fastcall unsigned int chrnum( ESI, BL) |
493 | { |
493 | { |
494 | int num = 0; |
494 | int num = 0; |
495 | while(DSBYTE[ESI]) |
495 | while(DSBYTE[ESI]) |
496 | { |
496 | { |
497 | if (DSBYTE[ESI] == BL) num++; |
497 | if (DSBYTE[ESI] == BL) num++; |
498 | ESI++; |
498 | ESI++; |
499 | } |
499 | } |
500 | return num; |
500 | return num; |
501 | } |
501 | } |
502 | 502 | ||
503 | inline fastcall unsigned int chrlnum( ESI, BL, EDI) |
503 | inline fastcall unsigned int chrlnum( ESI, BL, EDI) |
504 | { |
504 | { |
505 | int num = 0; |
505 | int num = 0; |
506 | while(DSBYTE[ESI]) && (EDI) |
506 | while(DSBYTE[ESI]) && (EDI) |
507 | { |
507 | { |
508 | if (DSBYTE[ESI] == BL) num++; |
508 | if (DSBYTE[ESI] == BL) num++; |
509 | ESI++; |
509 | ESI++; |
510 | EDI--; |
510 | EDI--; |
511 | } |
511 | } |
512 | return num; |
512 | return num; |
513 | } |
513 | } |
514 | 514 | ||
515 | inline fastcall signed int strstr( EBX, EDX) |
515 | inline fastcall signed int strstr( EBX, EDX) |
516 | { |
516 | { |
517 | asm { |
517 | asm { |
518 | MOV EDI, EDX |
518 | MOV EDI, EDX |
519 | XOR ECX, ECX |
519 | XOR ECX, ECX |
520 | XOR EAX, EAX |
520 | XOR EAX, EAX |
521 | DEC ECX |
521 | DEC ECX |
522 | REPNE SCASB |
522 | REPNE SCASB |
523 | NOT ECX |
523 | NOT ECX |
524 | DEC ECX |
524 | DEC ECX |
525 | JE LS2 |
525 | JE LS2 |
526 | MOV ESI, ECX |
526 | MOV ESI, ECX |
527 | XOR ECX, ECX |
527 | XOR ECX, ECX |
528 | MOV EDI, EBX |
528 | MOV EDI, EBX |
529 | DEC ECX |
529 | DEC ECX |
530 | REPNE SCASB |
530 | REPNE SCASB |
531 | NOT ECX |
531 | NOT ECX |
532 | SUB ECX, ESI |
532 | SUB ECX, ESI |
533 | JBE LS2 |
533 | JBE LS2 |
534 | MOV EDI, EBX |
534 | MOV EDI, EBX |
535 | LEA EBX, DSDWORD[ ESI-1] |
535 | LEA EBX, DSDWORD[ ESI-1] |
536 | LS1: MOV ESI, EDX |
536 | LS1: MOV ESI, EDX |
537 | LODSB |
537 | LODSB |
538 | REPNE SCASB |
538 | REPNE SCASB |
539 | JNE LS2 |
539 | JNE LS2 |
540 | MOV EAX, ECX |
540 | MOV EAX, ECX |
541 | PUSH EDI |
541 | PUSH EDI |
542 | MOV ECX, EBX |
542 | MOV ECX, EBX |
543 | REPE CMPSB |
543 | REPE CMPSB |
544 | POP EDI |
544 | POP EDI |
545 | MOV ECX, EAX |
545 | MOV ECX, EAX |
546 | JNE LS1 |
546 | JNE LS1 |
547 | LEA EAX, DSDWORD[ EDI-1] |
547 | LEA EAX, DSDWORD[ EDI-1] |
548 | JMP SHORT LS3 |
548 | JMP SHORT LS3 |
549 | LS2: XOR EAX, EAX |
549 | LS2: XOR EAX, EAX |
550 | LS3: |
550 | LS3: |
551 | } |
551 | } |
552 | } |
552 | } |
553 | 553 | ||
554 | inline int strnum(dword haystack, needle) |
554 | inline int strnum(dword haystack, needle) |
555 | { |
555 | { |
556 | int count = 0; |
556 | int count = 0; |
557 | int needle_len = strlen(needle); |
557 | int needle_len = strlen(needle); |
558 | loop() { |
558 | loop() { |
559 | if (! haystack = strstr(haystack, needle)) break; |
559 | if (! haystack = strstr(haystack, needle)) break; |
560 | haystack+=needle_len; |
560 | haystack+=needle_len; |
561 | count++; |
561 | count++; |
562 | } |
562 | } |
563 | return count; |
563 | return count; |
564 | } |
564 | } |
565 | 565 | ||
566 | inline int strinum(dword haystack, needle) |
566 | inline int strinum(dword haystack, needle) |
567 | { |
567 | { |
568 | int count = 0; |
568 | int count = 0; |
569 | int needle_len = strlen(needle); |
569 | int needle_len = strlen(needle); |
570 | loop() { |
570 | loop() { |
571 | if (! haystack = strstri(haystack, needle)) break; |
571 | if (! haystack = strstri(haystack, needle)) break; |
572 | haystack+=needle_len; |
572 | haystack+=needle_len; |
573 | count++; |
573 | count++; |
574 | } |
574 | } |
575 | return count; |
575 | return count; |
576 | } |
576 | } |
577 | 577 | ||
578 | inline signed int strcmpi(dword cmp1, cmp2) |
578 | inline signed int strcmpi(dword cmp1, cmp2) |
579 | { |
579 | { |
580 | char si, ue; |
580 | char si, ue; |
581 | 581 | ||
582 | loop() |
582 | loop() |
583 | { |
583 | { |
584 | si = DSBYTE[cmp1]; |
584 | si = DSBYTE[cmp1]; |
585 | ue = DSBYTE[cmp2]; |
585 | ue = DSBYTE[cmp2]; |
586 | if (si>='A') && (si<='Z') si +=32; |
586 | if (si>='A') && (si<='Z') si +=32; |
587 | if (ue>='A') && (ue<='Z') ue +=32; |
587 | if (ue>='A') && (ue<='Z') ue +=32; |
588 | if (si != ue) return si-ue; |
588 | if (si != ue) return si-ue; |
589 | cmp1++; |
589 | cmp1++; |
590 | cmp2++; |
590 | cmp2++; |
591 | if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0; |
591 | if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0; |
592 | if (DSBYTE[cmp1]=='\0') return -1; |
592 | if (DSBYTE[cmp1]=='\0') return -1; |
593 | if (DSBYTE[cmp2]=='\0') return 1; |
593 | if (DSBYTE[cmp2]=='\0') return 1; |
594 | } |
594 | } |
595 | } |
595 | } |
596 | 596 | ||
597 | inline dword strstri(dword searchin, usestr_s) |
597 | inline dword strstri(dword searchin, usestr_s) |
598 | { |
598 | { |
599 | dword usestr_e = usestr_s; |
599 | dword usestr_e = usestr_s; |
600 | char si, ue; |
600 | char si, ue; |
601 | 601 | ||
602 | while(DSBYTE[searchin]) |
602 | while(DSBYTE[searchin]) |
603 | { |
603 | { |
604 | si = DSBYTE[searchin]; |
604 | si = DSBYTE[searchin]; |
605 | ue = DSBYTE[usestr_e]; |
605 | ue = DSBYTE[usestr_e]; |
606 | if (si>='A') && (si<='Z') si +=32; |
606 | if (si>='A') && (si<='Z') si +=32; |
607 | if (ue>='A') && (ue<='Z') ue +=32; |
607 | if (ue>='A') && (ue<='Z') ue +=32; |
608 | if (si == ue) usestr_e++; else usestr_e = usestr_s; |
608 | if (si == ue) usestr_e++; else usestr_e = usestr_s; |
609 | searchin++; |
609 | searchin++; |
610 | if (DSBYTE[usestr_e]=='\0') return searchin; |
610 | if (DSBYTE[usestr_e]=='\0') return searchin; |
611 | } |
611 | } |
612 | return 0; |
612 | return 0; |
613 | } |
613 | } |
614 | 614 | ||
615 | 615 | ||
616 | inline unsigned int strcpyb(dword search_in, copyin, startstr, endstr) |
616 | inline unsigned int strcpyb(dword search_in, copyin, startstr, endstr) |
617 | { |
617 | { |
618 | dword startp, endp; |
618 | dword startp, endp; |
619 | dword copyin_start_off = copyin; |
619 | dword copyin_start_off = copyin; |
620 | if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr); |
620 | if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr); |
621 | if (! endp = strstri(startp, endstr)) endp = startp+strlen(search_in); |
621 | if (! endp = strstri(startp, endstr)) endp = startp+strlen(search_in); |
622 | //if (startp==endp) return 0; |
622 | //if (startp==endp) return 0; |
623 | do |
623 | do |
624 | { |
624 | { |
625 | DSBYTE[copyin] = DSBYTE[startp]; |
625 | DSBYTE[copyin] = DSBYTE[startp]; |
626 | copyin++; |
626 | copyin++; |
627 | startp++; |
627 | startp++; |
628 | } |
628 | } |
629 | while (startp |
629 | while (startp |
630 | DSBYTE[copyin] = '\0'; |
630 | DSBYTE[copyin] = '\0'; |
631 | return copyin_start_off; |
631 | return copyin_start_off; |
632 | } |
632 | } |
633 | 633 | ||
634 | 634 | ||
635 | /*void strcat(char *to, char *from) |
635 | /*void strcat(char *to, char *from) |
636 | { |
636 | { |
637 | while(*to) to++; |
637 | while(*to) to++; |
638 | while(*from) |
638 | while(*from) |
639 | { |
639 | { |
640 | *to = *from; |
640 | *to = *from; |
641 | to++; |
641 | to++; |
642 | from++; |
642 | from++; |
643 | } |
643 | } |
644 | *to = '\0'; |
644 | *to = '\0'; |
645 | }*/ |
645 | }*/ |
646 | 646 | ||
647 | 647 | ||
648 | inline fastcall dword atoi( EDI) |
648 | inline fastcall dword atoi( EDI) |
649 | { |
649 | { |
650 | $push ebx |
650 | $push ebx |
651 | $push esi |
651 | $push esi |
652 | ESI=EDI; |
652 | ESI=EDI; |
653 | while (DSBYTE[ESI]==' ') ESI++; |
653 | while (DSBYTE[ESI]==' ') ESI++; |
654 | if (DSBYTE[ESI]=='-') ESI++; |
654 | if (DSBYTE[ESI]=='-') ESI++; |
655 | EAX=0; |
655 | EAX=0; |
656 | while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9') |
656 | while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9') |
657 | { |
657 | { |
658 | $xor ebx, ebx |
658 | $xor ebx, ebx |
659 | EBX = DSBYTE[ESI]-'0'; |
659 | EBX = DSBYTE[ESI]-'0'; |
660 | EAX *= 10; |
660 | EAX *= 10; |
661 | EAX += EBX; |
661 | EAX += EBX; |
662 | ESI++; |
662 | ESI++; |
663 | } |
663 | } |
664 | IF (DSBYTE[EDI]=='-') -EAX; |
664 | IF (DSBYTE[EDI]=='-') -EAX; |
665 | $pop esi |
665 | $pop esi |
666 | $pop ebx |
666 | $pop ebx |
667 | } |
667 | } |
668 | 668 | ||
669 | 669 | ||
670 | 670 | ||
671 | inline fastcall strupr( ESI) |
671 | inline fastcall strupr( ESI) |
672 | { |
672 | { |
673 | do{ |
673 | do{ |
674 | AL=DSBYTE[ESI]; |
674 | AL=DSBYTE[ESI]; |
675 | IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f; |
675 | IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f; |
676 | IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32; //à-ï |
676 | IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32; //à-ï |
677 | IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80; //à-ï |
677 | IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80; //à-ï |
678 | ESI++; |
678 | ESI++; |
679 | }while(AL!=0); |
679 | }while(AL!=0); |
680 | } |
680 | } |
681 | 681 | ||
682 | inline fastcall strlwr( ESI) |
682 | inline fastcall strlwr( ESI) |
683 | { |
683 | { |
684 | do{ |
684 | do{ |
685 | $LODSB |
685 | $LODSB |
686 | IF(AL>='A')&&(AL<='Z'){ |
686 | IF(AL>='A')&&(AL<='Z'){ |
687 | AL+=0x20; |
687 | AL+=0x20; |
688 | DSBYTE[ESI-1]=AL; |
688 | DSBYTE[ESI-1]=AL; |
689 | CONTINUE; |
689 | CONTINUE; |
690 | } |
690 | } |
691 | }while(AL!=0); |
691 | }while(AL!=0); |
692 | } |
692 | } |
693 | 693 | ||
694 | inline fastcall strttl( EDX) |
694 | inline fastcall strttl( EDX) |
695 | { |
695 | { |
696 | AL=DSBYTE[EDX]; |
696 | AL=DSBYTE[EDX]; |
697 | IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f; |
697 | IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f; |
698 | IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32; //à-ï |
698 | IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32; //à-ï |
699 | IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80; //à-ï |
699 | IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80; //à-ï |
700 | do{ |
700 | do{ |
701 | EDX++; |
701 | EDX++; |
702 | AL=DSBYTE[EDX]; |
702 | AL=DSBYTE[EDX]; |
703 | IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;} |
703 | IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;} |
704 | IF(AL>='')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯ |
704 | IF(AL>='')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯ |
705 | IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80; //à-ï |
705 | IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80; //à-ï |
706 | }while(AL!=0); |
706 | }while(AL!=0); |
707 | } |
707 | } |
708 | 708 | ||
709 | /* |
709 | /* |
710 | dword itoa( ESI) |
710 | dword itoa( ESI) |
711 | { |
711 | { |
712 | unsigned char buffer[11]; |
712 | unsigned char buffer[11]; |
713 | $pusha |
713 | $pusha |
714 | EDI = #buffer; |
714 | EDI = #buffer; |
715 | ECX = 10; |
715 | ECX = 10; |
716 | if (ESI < 0) |
716 | if (ESI < 0) |
717 | { |
717 | { |
718 | $mov al, '-' |
718 | $mov al, '-' |
719 | $stosb |
719 | $stosb |
720 | $neg esi |
720 | $neg esi |
721 | } |
721 | } |
722 | 722 | ||
723 | $mov eax, esi |
723 | $mov eax, esi |
724 | $push -'0' |
724 | $push -'0' |
725 | F2: |
725 | F2: |
726 | $xor edx, edx |
726 | $xor edx, edx |
727 | $div ecx |
727 | $div ecx |
728 | $push edx |
728 | $push edx |
729 | $test eax, eax |
729 | $test eax, eax |
730 | $jnz F2 |
730 | $jnz F2 |
731 | F3: |
731 | F3: |
732 | $pop eax |
732 | $pop eax |
733 | $add al, '0' |
733 | $add al, '0' |
734 | $stosb |
734 | $stosb |
735 | $jnz F3 |
735 | $jnz F3 |
736 | 736 | ||
737 | $mov al, '\0' |
737 | $mov al, '\0' |
738 | $stosb |
738 | $stosb |
739 | 739 | ||
740 | $popa |
740 | $popa |
741 | return #buffer; |
741 | return #buffer; |
742 | } |
742 | } |
743 | */ |
743 | */ |
744 | :unsigned char BUF_ITOA[11]; |
744 | :unsigned char BUF_ITOA[11]; |
745 | inline dword itoa(signed long number) |
745 | inline dword itoa(signed long number) |
746 | { |
746 | { |
747 | dword ret,p; |
747 | dword ret,p; |
748 | byte cmd; |
748 | byte cmd; |
749 | long mask,tmp; |
749 | long mask,tmp; |
750 | mask = 1000000000; |
750 | mask = 1000000000; |
751 | cmd = true; |
751 | cmd = true; |
752 | p = #BUF_ITOA; |
752 | p = #BUF_ITOA; |
753 | if(!number){ |
753 | if(!number){ |
754 | ESBYTE[p] = '0'; |
754 | ESBYTE[p] = '0'; |
755 | ESBYTE[p+1] = 0; |
755 | ESBYTE[p+1] = 0; |
756 | return p; |
756 | return p; |
757 | } |
757 | } |
758 | ret = p; |
758 | ret = p; |
759 | if(number<0) |
759 | if(number<0) |
760 | { |
760 | { |
761 | $neg number |
761 | $neg number |
762 | ESBYTE[p] = '-'; |
762 | ESBYTE[p] = '-'; |
763 | $inc p |
763 | $inc p |
764 | } |
764 | } |
765 | while(mask) |
765 | while(mask) |
766 | { |
766 | { |
767 | tmp = number / mask; |
767 | tmp = number / mask; |
768 | tmp = tmp%10; |
768 | tmp = tmp%10; |
769 | 769 | ||
770 | if(cmd){ |
770 | if(cmd){ |
771 | if(tmp){ |
771 | if(tmp){ |
772 | ESBYTE[p] = tmp + '0'; |
772 | ESBYTE[p] = tmp + '0'; |
773 | $inc p |
773 | $inc p |
774 | cmd = false; |
774 | cmd = false; |
775 | } |
775 | } |
776 | } |
776 | } |
777 | else { |
777 | else { |
778 | ESBYTE[p] = tmp + '0'; |
778 | ESBYTE[p] = tmp + '0'; |
779 | $inc p |
779 | $inc p |
780 | } |
780 | } |
781 | mask /= 10; |
781 | mask /= 10; |
782 | } |
782 | } |
783 | ESBYTE[p] = 0; |
783 | ESBYTE[p] = 0; |
784 | return ret; |
784 | return ret; |
785 | } |
785 | } |
786 | 786 | ||
787 | inline fastcall itoa_(signed int EDI, ESI) |
787 | inline fastcall itoa_(signed int EDI, ESI) |
788 | { |
788 | { |
789 | $pusha |
789 | $pusha |
790 | EBX = EDI; |
790 | EBX = EDI; |
791 | ECX = 10; |
791 | ECX = 10; |
792 | if (ESI > 90073741824) |
792 | if (ESI > 90073741824) |
793 | { |
793 | { |
794 | $mov al, '-' |
794 | $mov al, '-' |
795 | $stosb |
795 | $stosb |
796 | $neg esi |
796 | $neg esi |
797 | } |
797 | } |
798 | 798 | ||
799 | $mov eax, esi |
799 | $mov eax, esi |
800 | $push -'0' |
800 | $push -'0' |
801 | F2: |
801 | F2: |
802 | $xor edx, edx |
802 | $xor edx, edx |
803 | $div ecx |
803 | $div ecx |
804 | $push edx |
804 | $push edx |
805 | $test eax, eax |
805 | $test eax, eax |
806 | $jnz F2 |
806 | $jnz F2 |
807 | F3: |
807 | F3: |
808 | $pop eax |
808 | $pop eax |
809 | $add al, '0' |
809 | $add al, '0' |
810 | $stosb |
810 | $stosb |
811 | $jnz F3 |
811 | $jnz F3 |
812 | 812 | ||
813 | $mov al, '\0' |
813 | $mov al, '\0' |
814 | $stosb |
814 | $stosb |
815 | 815 | ||
816 | $popa |
816 | $popa |
817 | return EBX; |
817 | return EBX; |
818 | } |
818 | } |
819 | 819 | ||
820 | inline dword memchr(dword s,int c,signed len) |
820 | inline dword memchr(dword s,int c,signed len) |
821 | { |
821 | { |
822 | if(!len) return NULL; |
822 | if(!len) return NULL; |
823 | do { |
823 | do { |
824 | if(DSBYTE[s] == c) return s; |
824 | if(DSBYTE[s] == c) return s; |
825 | $inc s |
825 | $inc s |
826 | $dec len |
826 | $dec len |
827 | } while(len); |
827 | } while(len); |
828 | return NULL; |
828 | return NULL; |
829 | } |
829 | } |
830 | 830 | ||
831 | inline dword strdup(dword text) |
831 | inline dword strdup(dword text) |
832 | { |
832 | { |
833 | dword l = strlen(text); |
833 | dword l = strlen(text); |
834 | dword ret = malloc(l+1); |
834 | dword ret = malloc(l+1); |
835 | if(!ret) return NULL; |
835 | if(!ret) return NULL; |
836 | strlcpy(ret,text,l); |
836 | strlcpy(ret,text,l); |
837 | return ret; |
837 | return ret; |
838 | } |
838 | } |
839 | 839 | ||
840 | inline dword strndup(dword str, signed maxlen) |
840 | inline dword strndup(dword str, signed maxlen) |
841 | { |
841 | { |
842 | dword copy,len; |
842 | dword copy,len; |
843 | 843 | ||
844 | len = strnlen(str, maxlen); |
844 | len = strnlen(str, maxlen); |
845 | copy = malloc(len + 1); |
845 | copy = malloc(len + 1); |
846 | if (copy != NULL) |
846 | if (copy != NULL) |
847 | { |
847 | { |
848 | strlcpy(copy, str, len); |
848 | strlcpy(copy, str, len); |
849 | DSBYTE[len+copy] = '\0'; |
849 | DSBYTE[len+copy] = '\0'; |
850 | } |
850 | } |
851 | return copy; |
851 | return copy; |
852 | } |
852 | } |
853 | 853 | ||
854 | inline dword hexdec(dword text) |
854 | inline dword hexdec(dword text) |
855 | { |
855 | { |
856 | char s; |
856 | char s; |
857 | dword ret,l; |
857 | dword ret,l; |
858 | ret = 0; |
858 | ret = 0; |
859 | s = DSBYTE[text]; |
859 | s = DSBYTE[text]; |
860 | while(s) |
860 | while(s) |
861 | { |
861 | { |
862 | ret <<= 4; |
862 | ret <<= 4; |
863 | if(s>='A')&&(s<='F')ret |= s-'A'+10; |
863 | if(s>='A')&&(s<='F')ret |= s-'A'+10; |
864 | else if(s>='a')&&(s<='f')ret |= s-'a'+10; |
864 | else if(s>='a')&&(s<='f')ret |= s-'a'+10; |
865 | else if(s>='0')&&(s<='9')ret |= s-'0'; |
865 | else if(s>='0')&&(s<='9')ret |= s-'0'; |
866 | text++; |
866 | text++; |
867 | s = DSBYTE[text]; |
867 | s = DSBYTE[text]; |
868 | } |
868 | } |
869 | return ret; |
869 | return ret; |
870 | } |
870 | } |
871 | 871 | ||
872 | inline signed csshexdec(dword text) |
872 | inline signed csshexdec(dword text) |
873 | { |
873 | { |
874 | char s; |
874 | char s; |
875 | dword ret,l; |
875 | dword ret,l; |
876 | byte tmp; |
876 | byte tmp; |
877 | l = strlen(text); |
877 | l = strlen(text); |
878 | ret = 0; |
878 | ret = 0; |
879 | s = DSBYTE[text]; |
879 | s = DSBYTE[text]; |
880 | tmp = 0; |
880 | tmp = 0; |
881 | if(l==6) while(s) |
881 | if(l==6) while(s) |
882 | { |
882 | { |
883 | ret <<= 4; |
883 | ret <<= 4; |
884 | if(s>='A')&&(s<='F')ret |= s-'A'+10; |
884 | if(s>='A')&&(s<='F')ret |= s-'A'+10; |
885 | else if(s>='a')&&(s<='f')ret |= s-'a'+10; |
885 | else if(s>='a')&&(s<='f')ret |= s-'a'+10; |
886 | else if(s>='0')&&(s<='9')ret |= s-'0'; |
886 | else if(s>='0')&&(s<='9')ret |= s-'0'; |
887 | text++; |
887 | text++; |
888 | s = DSBYTE[text]; |
888 | s = DSBYTE[text]; |
889 | } |
889 | } |
890 | else if(l==3) while(s) |
890 | else if(l==3) while(s) |
891 | { |
891 | { |
892 | ret |= tmp; |
892 | ret |= tmp; |
893 | ret <<= 4; |
893 | ret <<= 4; |
894 | ret |= tmp; |
894 | ret |= tmp; |
895 | ret <<= 4; |
895 | ret <<= 4; |
896 | if(s>='A')&&(s<='F')tmp = s-'A'+10; |
896 | if(s>='A')&&(s<='F')tmp = s-'A'+10; |
897 | else if(s>='a')&&(s<='f')tmp = s-'a'+10; |
897 | else if(s>='a')&&(s<='f')tmp = s-'a'+10; |
898 | else if(s>='0')&&(s<='9')tmp = s-'0'; |
898 | else if(s>='0')&&(s<='9')tmp = s-'0'; |
899 | text++; |
899 | text++; |
900 | s = DSBYTE[text]; |
900 | s = DSBYTE[text]; |
901 | } |
901 | } |
902 | return ret; |
902 | return ret; |
903 | } |
903 | } |
904 | 904 | ||
905 | void miniprintf(dword dst, format, insert_line) |
905 | :void miniprintf(dword dst, format, insert_line) |
906 | { |
906 | { |
907 | dword in_pos = strchr(format, '%'); |
907 | dword in_pos = strchr(format, '%'); |
908 | if (ESBYTE[in_pos+1] == 's') { |
908 | if (ESBYTE[in_pos+1] == 's') { |
909 | strlcpy(dst, format, in_pos - format); |
909 | strlcpy(dst, format, in_pos - format); |
910 | strcat(dst, insert_line); |
910 | strcat(dst, insert_line); |
911 | strcat(dst, in_pos+2); |
911 | strcat(dst, in_pos+2); |
912 | } |
912 | } |
913 | } |
913 | } |
914 | 914 | ||
915 | inline cdecl int sprintf(dword buf, format,...) |
915 | inline cdecl int sprintf(dword buf, format,...) |
916 | { |
916 | { |
917 | #define END_ARGS 0xFF00FF //ARGS FUNCTION |
917 | #define END_ARGS 0xFF00FF //ARGS FUNCTION |
918 | byte s; |
918 | byte s; |
919 | char X[10]; |
- | |
920 | dword ret, tmp, l; |
919 | dword ret, tmp, l; |
921 | dword arg = #format; |
920 | dword arg = #format; |
922 | ret = buf; |
921 | ret = buf; |
923 | s = DSBYTE[format]; |
922 | s = DSBYTE[format]; |
924 | while(s){ |
923 | while(s){ |
925 | if(s=='%'){ |
924 | if(s=='%'){ |
926 | arg+=4; |
925 | arg+=4; |
927 | tmp = DSDWORD[arg]; |
926 | tmp = DSDWORD[arg]; |
928 | if(tmp==END_ARGS)goto END_FUNC_SPRINTF; |
927 | if(tmp==END_ARGS)goto END_FUNC_SPRINTF; |
929 | $inc format |
928 | $inc format |
930 | s = DSBYTE[format]; |
929 | s = DSBYTE[format]; |
931 | if(!s)goto END_FUNC_SPRINTF; |
930 | if(!s)goto END_FUNC_SPRINTF; |
932 | switch(s) |
931 | switch(s) |
933 | { |
932 | { |
934 | case 's': |
933 | case 's': |
935 | l = tmp; |
934 | l = tmp; |
936 | s = DSBYTE[tmp]; |
935 | s = DSBYTE[tmp]; |
937 | while(s) |
936 | while(s) |
938 | { |
937 | { |
939 | DSBYTE[buf] = s; |
938 | DSBYTE[buf] = s; |
940 | $inc tmp |
939 | $inc tmp |
941 | $inc buf |
940 | $inc buf |
942 | s = DSBYTE[tmp]; |
941 | s = DSBYTE[tmp]; |
943 | } |
942 | } |
944 | break; |
943 | break; |
945 | case 'c': |
944 | case 'c': |
946 | DSBYTE[buf] = tmp; |
945 | DSBYTE[buf] = tmp; |
947 | $inc buf |
946 | $inc buf |
948 | break; |
947 | break; |
949 | case 'u': //if(tmp<0)return ret; |
948 | case 'u': //if(tmp<0)return ret; |
950 | case 'd': |
949 | case 'd': |
951 | case 'i': |
950 | case 'i': |
952 | tmp = itoa(tmp); |
951 | tmp = itoa(tmp); |
953 | if(!DSBYTE[tmp])goto END_FUNC_SPRINTF; |
952 | if(!DSBYTE[tmp])goto END_FUNC_SPRINTF; |
954 | l = strlen(tmp); |
953 | l = strlen(tmp); |
955 | strlcpy(buf,tmp,l); |
954 | strlcpy(buf,tmp,l); |
956 | buf += l; |
955 | buf += l; |
957 | break; |
956 | break; |
958 | case 'a': |
957 | case 'a': |
959 | case 'A': |
958 | case 'A': |
960 | strlcpy(buf,"0x00000000",10); |
959 | strlcpy(buf,"0x00000000",10); |
961 | buf+=10; |
960 | buf+=10; |
962 | l=buf; |
961 | l=buf; |
963 | while(tmp) |
962 | while(tmp) |
964 | { |
963 | { |
965 | $dec buf |
964 | $dec buf |
966 | s=tmp&0xF; |
965 | s=tmp&0xF; |
967 | if(s>9)DSBYTE[buf]='A'+s-10; |
966 | if(s>9)DSBYTE[buf]='A'+s-10; |
968 | else DSBYTE[buf]='0'+s; |
967 | else DSBYTE[buf]='0'+s; |
969 | tmp>>=4; |
968 | tmp>>=4; |
970 | } |
969 | } |
971 | buf=l; |
970 | buf=l; |
972 | break; |
971 | break; |
973 | case 'p': |
972 | case 'p': |
974 | tmp = itoa(#tmp); |
973 | tmp = itoa(#tmp); |
975 | if(!DSBYTE[tmp])goto END_FUNC_SPRINTF; |
974 | if(!DSBYTE[tmp])goto END_FUNC_SPRINTF; |
976 | l = strlen(tmp); |
975 | l = strlen(tmp); |
977 | strlcpy(buf,tmp,l); |
976 | strlcpy(buf,tmp,l); |
978 | buf += l; |
977 | buf += l; |
979 | break; |
978 | break; |
980 | case '%': |
979 | case '%': |
981 | DSBYTE[buf] = '%'; |
980 | DSBYTE[buf] = '%'; |
982 | $inc buf |
981 | $inc buf |
983 | break; |
982 | break; |
984 | default: |
983 | default: |
985 | goto END_FUNC_SPRINTF; |
984 | goto END_FUNC_SPRINTF; |
986 | } |
985 | } |
987 | } |
986 | } |
988 | else { |
987 | else { |
989 | DSBYTE[buf] = s; |
988 | DSBYTE[buf] = s; |
990 | $inc buf |
989 | $inc buf |
991 | } |
990 | } |
992 | $inc format |
991 | $inc format |
993 | s = DSBYTE[format]; |
992 | s = DSBYTE[format]; |
994 | } |
993 | } |
995 | END_FUNC_SPRINTF: |
994 | END_FUNC_SPRINTF: |
996 | DSBYTE[buf] = 0; |
995 | DSBYTE[buf] = 0; |
997 | return ret; |
996 | return ret; |
998 | } |
997 | } |
999 | 998 | ||
1000 | inline signed strcoll(dword text1,text2) |
999 | inline signed strcoll(dword text1,text2) |
1001 | { |
1000 | { |
1002 | char s,ss; |
1001 | char s,ss; |
1003 | loop() |
1002 | loop() |
1004 | { |
1003 | { |
1005 | s = DSBYTE[text2]; |
1004 | s = DSBYTE[text2]; |
1006 | ss=strchr(text1,s); |
1005 | ss=strchr(text1,s); |
1007 | if(ss)return ss; |
1006 | if(ss)return ss; |
1008 | text2++; |
1007 | text2++; |
1009 | } |
1008 | } |
1010 | return 0; |
1009 | return 0; |
1011 | } |
1010 | } |
1012 | 1011 | ||
1013 | // void * memset( ptr, value, num ); |
1012 | // void * memset( ptr, value, num ); |
1014 | // fills the memory with a dword |
1013 | // fills the memory with a dword |
1015 | // example: memset(str,'-', sizeof(str)); |
1014 | // example: memset(str,'-', sizeof(str)); |
1016 | inline void MEMSETD(EDI,ECX,EAX) |
1015 | inline void MEMSETD(EDI,ECX,EAX) |
1017 | { |
1016 | { |
1018 | $REP |
1017 | $REP |
1019 | $STOSD |
1018 | $STOSD |
1020 | } |
1019 | } |
1021 | 1020 | ||
1022 | :replace_char(dword in_str, char from_char, to_char, int length) { |
1021 | :replace_char(dword in_str, char from_char, to_char, int length) { |
1023 | dword max = in_str + length; |
1022 | dword max = in_str + length; |
1024 | while (in_str < max) { |
1023 | while (in_str < max) { |
1025 | if (ESBYTE[in_str] == from_char) ESBYTE[in_str] = to_char; |
1024 | if (ESBYTE[in_str] == from_char) ESBYTE[in_str] = to_char; |
1026 | in_str++; |
1025 | in_str++; |
1027 | } |
1026 | } |
1028 | } |
1027 | } |
1029 | 1028 | ||
1030 | #endif>0)return>='9')tmp>='f')tmp>='F')tmp>=><=>=><=>='9')ret>='f')ret>='F')ret>=><=>='9')ret>='f')ret>='F')ret>=><=>0) |
1029 | #endif>0)return>='9')tmp>='f')tmp>='F')tmp>=><=>=><=>='9')ret>='f')ret>='F')ret>=><=>='9')ret>='f')ret>='F')ret>=><=>0) |
1031 | >>=159)>='')DSBYTE[EDX]=AL|0x20;>='Z'){DSBYTE[EDX]=AL|0x20;>=239)>=175)>='z')DSBYTE[EDX]=AL&0x5f; |
1030 | >>=159)>='')DSBYTE[EDX]=AL|0x20;>='Z'){DSBYTE[EDX]=AL|0x20;>=239)>=175)>='z')DSBYTE[EDX]=AL&0x5f; |
1032 | >='Z'){ |
1031 | >='Z'){ |
1033 | >=239)>=175)>='z')DSBYTE[ESI]=AL&0x5f; |
1032 | >=239)>=175)>='z')DSBYTE[ESI]=AL&0x5f; |
1034 | >='9') |
1033 | >='9') |
1035 | > |
1034 | > |
1036 | >='Z')>='Z')>='Z')>='Z')>0)> |
1035 | >='Z')>='Z')>='Z')>='Z')>0)> |