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 strchr() and wcsrchr().
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include "widechar.h"
  34. #include <stddef.h>
  35. #include <string.h>
  36. #include "riscstr.h"
  37.  
  38. #if defined(M_I86) && !defined(__WIDECHAR__)
  39.  
  40. extern  char *_fast_strrchr( const char _WCFAR *, char );
  41.  
  42. #if defined(__SMALL_DATA__)
  43. #pragma aux    _fast_strrchr = \
  44.         0xb9 0xff 0xff  /* mov cx,ffffh */ \
  45.         0x30 0xc0       /* xor al,al */ \
  46.         0xf2 0xae       /* repne scasb */ \
  47.         0xf7 0xd1       /* not cx */ \
  48.         0x4f            /* dec di */ \
  49.         0x88 0xd0       /* mov al,dl */ \
  50.         0xfd            /* std */ \
  51.         0xf2 0xae       /* repne scasb */ \
  52.         0xfc            /* cld */ \
  53.         0x75 0x03       /* jne L1 */ \
  54.         0x89 0xf9       /* mov cx,di */ \
  55.         0x41            /* inc cx */ \
  56.                         /* L1: */ \
  57.         parm caller [es di] [dl] \
  58.         value [cx] \
  59.         modify exact [cx ax di];
  60. #else
  61. #pragma aux    _fast_strrchr = \
  62.         0xb9 0xff 0xff  /* mov cx,ffffh */ \
  63.         0x30 0xc0       /* xor al,al */ \
  64.         0xf2 0xae       /* repne scasb */ \
  65.         0xf7 0xd1       /* not cx */ \
  66.         0x4f            /* dec di */ \
  67.         0x88 0xd8       /* mov al,bl */ \
  68.         0xfd            /* std */ \
  69.         0xf2 0xae       /* repne scasb */ \
  70.         0xfc            /* cld */ \
  71.         0x75 0x04       /* jne L1 */ \
  72.         0x89 0xf9       /* mov cx,di */ \
  73.         0x41            /* inc cx */ \
  74.         0xa9            /* hide 2 bytes */ \
  75.         0x8e 0xc1       /* L1: mov es,cx */ \
  76.         parm caller [es di] [bl] \
  77.         value [es cx] \
  78.         modify exact [es cx ax di];
  79. #endif
  80. #endif
  81.  
  82. /* Locate the last occurrence of c in the string pointed to by s.
  83.    The terminating null character is considered to be part of the string.
  84.    If the character c is not found, NULL is returned.
  85. */
  86.  
  87.  
  88. #if defined(__RISCSTR__) && defined(__WIDECHAR__)
  89.  _WCRTLINK CHAR_TYPE *__simple_wcsrchr( const CHAR_TYPE *s, INTCHAR_TYPE c )
  90. #else
  91.  _WCRTLINK CHAR_TYPE *__F_NAME(strrchr,wcsrchr)( const CHAR_TYPE *s, INTCHAR_TYPE c )
  92. #endif
  93.     {
  94. #if defined(M_I86) && !defined(__WIDECHAR__)
  95.         return( _fast_strrchr( s, c ) );
  96. #else
  97.         CHAR_TYPE *p;
  98.         CHAR_TYPE cc = c;
  99.  
  100.         p = NULL;       /* assume c will not be found */
  101.         do {
  102.             if( *s == cc ) p = (CHAR_TYPE *)s;
  103.         } while( *s++ != NULLCHAR );
  104.         return( p );
  105. #endif
  106.     }
  107.