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