Subversion Repositories Kolibri OS

Rev

Rev 6887 | Rev 7286 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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