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:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
  28. *               DESCRIBE IT HERE!
  29. *
  30. ****************************************************************************/
  31.  
  32.  
  33. #include "variety.h"
  34. #include "widechar.h"
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include "riscstr.h"
  38.  
  39. #if defined(M_I86) && !defined(__WIDECHAR__)
  40.  
  41. extern int _fast_strncmp( const char *, const char _WCFAR *, size_t );
  42.  
  43. #if defined(__SMALL_DATA__)
  44. #pragma aux    _fast_strncmp = \
  45.         0x89 0xfa       /* mov dx,di */ \
  46.         0x30 0xc0       /* xor al,al */ \
  47.         0xf2 0xae       /* repne scasb */ \
  48.         0x89 0xf9       /* mov cx,di */ \
  49.         0x89 0xd7       /* mov di,dx */ \
  50.         0x29 0xf9       /* sub cx,di */ \
  51.         0xf3 0xa6       /* repe cmpsb */ \
  52.         0x74 0x05       /* je L1 */ \
  53.         0x19 0xc9       /* sbb cx,cx */ \
  54.         0x83 0xd9 0xff  /* sbb cx,ffffh */ \
  55.                         /* L1: */ \
  56.         parm caller [si] [es di] [cx] \
  57.         value [cx] \
  58.         modify exact [dx ax di cx si];
  59. #else
  60. #pragma aux    _fast_strncmp = \
  61.         0x1e            /* push ds */ \
  62.         0x8e 0xda       /* mov ds,dx */ \
  63.         0x89 0xfa       /* mov dx,di */ \
  64.         0x30 0xc0       /* xor al,al */ \
  65.         0xf2 0xae       /* repne scasb */ \
  66.         0x89 0xf9       /* mov cx,di */ \
  67.         0x89 0xd7       /* mov di,dx */ \
  68.         0x29 0xf9       /* sub cx,di */ \
  69.         0xf3 0xa6       /* repe cmpsb */ \
  70.         0x74 0x05       /* je L1 */ \
  71.         0x19 0xc9       /* sbb cx,cx */ \
  72.         0x83 0xd9 0xff  /* sbb cx,ffffh */ \
  73.                         /* L1: */ \
  74.         0x1f            /* pop ds */ \
  75.         parm caller [dx si] [es di] [cx] \
  76.         value [cx] \
  77.         modify exact [dx ax di cx si];
  78. #endif
  79. #endif
  80.  
  81. /* return <0 if s<t, 0 if s==t, >0 if s>t */
  82.  
  83. #if defined(__RISCSTR__) && defined(__WIDECHAR__)
  84.  _WCRTLINK int __simple_wcsncmp( const CHAR_TYPE *s, const CHAR_TYPE *t, size_t n )
  85. #else
  86.  _WCRTLINK int __F_NAME(strncmp,wcsncmp)( const CHAR_TYPE *s, const CHAR_TYPE *t, size_t n )
  87. #endif
  88.     {
  89. #if defined(M_I86) && !defined(__WIDECHAR__)
  90.         if( n ) {
  91.             return( _fast_strncmp( s, t, n ) );
  92.         }
  93.         return( 0 );
  94. #else
  95.         for(;;) {
  96.             if( n == 0 )     return( 0 );       /* equal */
  97.             if( *s != *t )   return( *s - *t ); /* less than or greater than */
  98.             if( *s == NULLCHAR ) return( 0 );       /* equal */
  99.             ++s;
  100.             ++t;
  101.             --n;
  102.         }
  103. #endif
  104.     }
  105.