Subversion Repositories Kolibri OS

Rev

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