Subversion Repositories Kolibri OS

Rev

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:  _fstrstr() implementation.
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include <stddef.h>
  34. #include <string.h>
  35.  
  36. #ifdef M_I86
  37. #if defined(__QNX__)
  38. #include <i86.h>
  39. #else
  40. #include <dos.h>
  41. #endif
  42.  
  43. extern  int     i86_memeq( const char _WCFAR *, const char _WCFAR *, int );
  44.  
  45. #define _ZFLAG          (INTR_ZF<<8)
  46.  
  47. #pragma aux     i86_memeq = \
  48.         0x1e            /* push ds */\
  49.         0x96            /* xchg si,ax */\
  50.         0x8e 0xd8       /* mov ds,ax  */\
  51.         0xf3 0xa6       /* rep cmpsb */\
  52.         0x9f            /* lahf */\
  53.         0x1f            /* pop ds */\
  54.         parm caller     [si ax] [es di] [cx]\
  55.         value           [ax] \
  56.         modify exact    [si di cx ax];
  57.  
  58. #define memeq( p1, p2, len )    ( i86_memeq((p1),(p2),(len)) & _ZFLAG )
  59.  
  60. #else
  61.  
  62. #define memeq( p1, p2, len )    ( _fmemcmp((p1),(p2),(len)) == 0 )
  63.  
  64. #endif
  65.  
  66. /* Locate the first occurrence of the string pointed to by s2 in the
  67.    string pointed to by s1.
  68.    The strstr function returns a pointer to the located string, or a
  69.    null pointer if the string is not found.
  70. */
  71.  
  72. _WCRTLINK char _WCFAR *_fstrstr( const char _WCFAR *s1, const char _WCFAR *s2 )
  73.     {
  74.         char _WCFAR *end_of_s1;
  75.         size_t s1len, s2len;
  76.  
  77.         if( s2[0] == '\0' ) {
  78.             return( (char _WCFAR *)s1 );
  79.         } else if( s2[1] == '\0' ) {
  80.             return( _fstrchr( s1, s2[0] ) );
  81.         }
  82.         end_of_s1 = _fmemchr( s1, '\0', ~0u );
  83.         s2len = _fstrlen( s2 );
  84.         for(;;) {
  85.             s1len = end_of_s1 - s1;
  86.             if( s1len < s2len ) break;
  87.             s1 = _fmemchr( s1, *s2, s1len ); /* find start of possible match */
  88.             if( s1 == NULL ) break;
  89.             if( memeq( s1, s2, s2len ) ) return( (char _WCFAR *)s1 );
  90.             ++s1;
  91.         }
  92.         return( NULL );
  93.     }
  94.