os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strstr.c
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strstr.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,73 @@
1.4 +/*
1.5 + * strstr.c --
1.6 + *
1.7 + * Source code for the "strstr" library routine.
1.8 + *
1.9 + * Copyright (c) 1988-1993 The Regents of the University of California.
1.10 + * Copyright (c) 1994 Sun Microsystems, Inc.
1.11 + *
1.12 + * See the file "license.terms" for information on usage and redistribution
1.13 + * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.14 + *
1.15 + * RCS: @(#) $Id: strstr.c,v 1.3.2.1 2005/04/12 18:28:56 kennykb Exp $
1.16 + */
1.17 +
1.18 +#include "tcl.h"
1.19 +#ifndef NULL
1.20 +#define NULL 0
1.21 +#endif
1.22 +
1.23 +/*
1.24 + *----------------------------------------------------------------------
1.25 + *
1.26 + * strstr --
1.27 + *
1.28 + * Locate the first instance of a substring in a string.
1.29 + *
1.30 + * Results:
1.31 + * If string contains substring, the return value is the
1.32 + * location of the first matching instance of substring
1.33 + * in string. If string doesn't contain substring, the
1.34 + * return value is 0. Matching is done on an exact
1.35 + * character-for-character basis with no wildcards or special
1.36 + * characters.
1.37 + *
1.38 + * Side effects:
1.39 + * None.
1.40 + *
1.41 + *----------------------------------------------------------------------
1.42 + */
1.43 +
1.44 +char *
1.45 +strstr(string, substring)
1.46 + register char *string; /* String to search. */
1.47 + char *substring; /* Substring to try to find in string. */
1.48 +{
1.49 + register char *a, *b;
1.50 +
1.51 + /* First scan quickly through the two strings looking for a
1.52 + * single-character match. When it's found, then compare the
1.53 + * rest of the substring.
1.54 + */
1.55 +
1.56 + b = substring;
1.57 + if (*b == 0) {
1.58 + return string;
1.59 + }
1.60 + for ( ; *string != 0; string += 1) {
1.61 + if (*string != *b) {
1.62 + continue;
1.63 + }
1.64 + a = string;
1.65 + while (1) {
1.66 + if (*b == 0) {
1.67 + return string;
1.68 + }
1.69 + if (*a++ != *b++) {
1.70 + break;
1.71 + }
1.72 + }
1.73 + b = substring;
1.74 + }
1.75 + return NULL;
1.76 +}