1
/* $Id: strstr.c,v 1.1 2007/03/01 13:10:55 dmix Exp $ */
10
void Check (int line, const char *s1, const char *s2, int expect)
16
if ( strlen_P(s1) > sizeof(t1) - 1
17
|| strlen_P(s2) > sizeof(t2) - 1)
22
if ((!p && expect == -1) || (p == t1 + expect))
25
printf ("\nLine %d: expect: %d, result: %d\n",
26
line, expect, (p ? p - t1 : -1));
27
if (line > 255) line = 255;
29
exit (p ? p - t1 : -1);
34
#define CHECK(s1, s2, expect) do { \
35
Check (__LINE__, PSTR(s1), PSTR(s2), expect); \
42
CHECK ("12345", "", 0);
45
CHECK ("ababac", "abac", 2);
47
/* 'needle' of 1 byte long */
51
CHECK ("abcbef", "a", 0);
53
CHECK (".a.", "a", 1);
54
CHECK ("ABCDEFGH", "H", 7);
56
/* 'needle' of 2 bytes long */
58
CHECK ("13", "12", -1);
59
CHECK ("32", "12", -1);
60
CHECK ("12", "12", 0);
61
CHECK ("123", "12", 0);
62
CHECK ("012", "12", 1);
63
CHECK ("01200", "12", 1);
65
/* partially mathing */
66
CHECK ("a_ab_abc_abcd_abcde", "abcdef", -1);
67
CHECK ("a_ab_abc_abcd_abcde_abcdef", "abcdef", 20);
68
CHECK ("aababcabcdabcde", "abcdef", -1);
69
CHECK ("aababcabcdabcdeabcdef", "abcdef", 15);
72
CHECK ("abaabaaabaaaab", "aaaaab", -1);
73
CHECK ("abaabaaabaaaabaaaaab", "aaaaab", 14);
75
/* A first match is returned. */
76
CHECK ("_foo_foo", "foo", 1);
78
/* Case is importent. */