Subversion Repositories Kolibri OS

Rev

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