Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  Implementation of ltoa().
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include "widechar.h"
  34. #include <stdlib.h>
  35.  
  36. extern const char __based(__segname("_CONST")) __Alphabet[];
  37.  
  38. unsigned long __uldiv( unsigned long, unsigned _WCNEAR * );
  39. #if defined(__386__)
  40.     #pragma aux __uldiv = \
  41.         "xor edx,edx" \
  42.         "div dword ptr [ebx]" \
  43.         "mov [ebx],edx" \
  44.         parm caller [eax] [ebx] \
  45.         modify exact [eax edx] \
  46.         value [eax];
  47. #elif defined(M_I86) && defined(__BIG_DATA__)
  48.     #pragma aux __uldiv = \
  49.         "xor cx,cx" \
  50.         "cmp dx,ss:[bx]" \
  51.         "jb short SMALL_ENOUGH" \
  52.         "xchg ax,dx" \
  53.         "xchg cx,dx" \
  54.         "div word ptr ss:[bx]" \
  55.         "xchg ax,cx" \
  56.         "SMALL_ENOUGH:" \
  57.         "div word ptr ss:[bx]" \
  58.         "mov ss:[bx],dx" \
  59.         "mov dx,cx" \
  60.         parm caller [ax dx] [bx] \
  61.         modify exact [ax cx dx] \
  62.         value [ax dx];
  63. #elif defined(M_I86) && defined(__SMALL_DATA__)
  64.     #pragma aux __uldiv = \
  65.         "xor cx,cx" \
  66.         "cmp dx,[bx]" \
  67.         "jb short SMALL_ENOUGH" \
  68.         "xchg ax,dx" \
  69.         "xchg cx,dx" \
  70.         "div word ptr [bx]" \
  71.         "xchg ax,cx" \
  72.         "SMALL_ENOUGH:" \
  73.         "div word ptr [bx]" \
  74.         "mov [bx],dx" \
  75.         "mov dx,cx" \
  76.         parm caller [ax dx] [bx] \
  77.         modify exact [ax cx dx] \
  78.         value [ax dx];
  79. #endif
  80.  
  81.  
  82. _WCRTLINK CHAR_TYPE *__F_NAME(ultoa,_ultow)( unsigned long value, CHAR_TYPE *buffer, int radix )
  83. {
  84.     CHAR_TYPE   *p = buffer;
  85.     char        *q;
  86.     unsigned    rem;
  87.     char        buf[34];        // only holds ASCII so 'char' is OK
  88.  
  89.     buf[0] = '\0';
  90.     q = &buf[1];
  91.     do {
  92. #if defined(_M_IX86) && defined(__WATCOMC__)
  93.         rem = radix;
  94.         value = __uldiv( value, (unsigned _WCNEAR *) &rem );
  95. #else
  96.         rem = value % radix;
  97.         value = value / radix;
  98. #endif
  99.         *q = __Alphabet[rem];
  100.         ++q;
  101.     } while( value != 0 );
  102.     while( (*p++ = (CHAR_TYPE)*--q) )
  103.         ;
  104.     return( buffer );
  105. }
  106.  
  107.  
  108. _WCRTLINK CHAR_TYPE *__F_NAME(ltoa,_ltow)( long value, CHAR_TYPE *buffer, int radix )
  109. {
  110.     CHAR_TYPE   *p = buffer;
  111.  
  112.     if( radix == 10 ) {
  113.         if( value < 0 ) {
  114.             *p++ = '-';
  115.             value = - value;
  116.         }
  117.     }
  118.     __F_NAME(ultoa,_ultow)( value, p, radix );
  119.     return( buffer );
  120. }
  121.