OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [compat/] [strstr.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
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.1.1.1 2002-01-16 10:25:23 markom Exp $
13
 */
14
 
15
/*
16
 *----------------------------------------------------------------------
17
 *
18
 * strstr --
19
 *
20
 *      Locate the first instance of a substring in a string.
21
 *
22
 * Results:
23
 *      If string contains substring, the return value is the
24
 *      location of the first matching instance of substring
25
 *      in string.  If string doesn't contain substring, the
26
 *      return value is 0.  Matching is done on an exact
27
 *      character-for-character basis with no wildcards or special
28
 *      characters.
29
 *
30
 * Side effects:
31
 *      None.
32
 *
33
 *----------------------------------------------------------------------
34
 */
35
 
36
char *
37
strstr(string, substring)
38
    register char *string;      /* String to search. */
39
    char *substring;            /* Substring to try to find in string. */
40
{
41
    register char *a, *b;
42
 
43
    /* First scan quickly through the two strings looking for a
44
     * single-character match.  When it's found, then compare the
45
     * rest of the substring.
46
     */
47
 
48
    b = substring;
49
    if (*b == 0) {
50
        return string;
51
    }
52
    for ( ; *string != 0; string += 1) {
53
        if (*string != *b) {
54
            continue;
55
        }
56
        a = string;
57
        while (1) {
58
            if (*b == 0) {
59
                return string;
60
            }
61
            if (*a++ != *b++) {
62
                break;
63
            }
64
        }
65
        b = substring;
66
    }
67
    return (char *) 0;
68
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.