Subversion Repositories Kolibri OS

Rev

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