Subversion Repositories Kolibri OS

Rev

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