Subversion Repositories Kolibri OS

Rev

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

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