os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strstr.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* 
     2  * strstr.c --
     3  *
     4  *	Source code for the "strstr" library routine.
     5  *
     6  * Copyright (c) 1988-1993 The Regents of the University of California.
     7  * Copyright (c) 1994 Sun Microsystems, Inc.
     8  *
     9  * See the file "license.terms" for information on usage and redistribution
    10  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    11  *
    12  * RCS: @(#) $Id: strstr.c,v 1.3.2.1 2005/04/12 18:28:56 kennykb Exp $
    13  */
    14 
    15 #include "tcl.h"
    16 #ifndef NULL
    17 #define NULL 0
    18 #endif
    19 
    20 /*
    21  *----------------------------------------------------------------------
    22  *
    23  * strstr --
    24  *
    25  *	Locate the first instance of a substring in a string.
    26  *
    27  * Results:
    28  *	If string contains substring, the return value is the
    29  *	location of the first matching instance of substring
    30  *	in string.  If string doesn't contain substring, the
    31  *	return value is 0.  Matching is done on an exact
    32  *	character-for-character basis with no wildcards or special
    33  *	characters.
    34  *
    35  * Side effects:
    36  *	None.
    37  *
    38  *----------------------------------------------------------------------
    39  */
    40 
    41 char *
    42 strstr(string, substring)
    43     register char *string;	/* String to search. */
    44     char *substring;		/* Substring to try to find in string. */
    45 {
    46     register char *a, *b;
    47 
    48     /* First scan quickly through the two strings looking for a
    49      * single-character match.  When it's found, then compare the
    50      * rest of the substring.
    51      */
    52 
    53     b = substring;
    54     if (*b == 0) {
    55 	return string;
    56     }
    57     for ( ; *string != 0; string += 1) {
    58 	if (*string != *b) {
    59 	    continue;
    60 	}
    61 	a = string;
    62 	while (1) {
    63 	    if (*b == 0) {
    64 		return string;
    65 	    }
    66 	    if (*a++ != *b++) {
    67 		break;
    68 	    }
    69 	}
    70 	b = substring;
    71     }
    72     return NULL;
    73 }