1
/* $Id: strsep_P.c,v 1.1.2.1 2008/03/20 21:42:30 joerg_wunsch Exp $ */
9
# define PRINTFLN(line, fmt, ...) \
10
printf("\nLine %d: " fmt "\n", line, ##__VA_ARGS__)
11
# define EXIT(code) exit ((code) < 255 ? (code) : 255)
12
# define memcmp_P memcmp
13
# define strsep_P strsep
15
# if defined(__AVR_ATmega128__)
16
/* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
17
# define PRINTFLN(line, fmt, ...) \
18
sprintf ((char *)0x2000, "\nLine %d: " fmt "\n", line, ##__VA_ARGS__)
21
# define PRINTFLN(args...)
26
void Check (int line, const char *s1, const char *s2, int clr, int pnt)
32
if (strlen_P(s1) > sizeof(t1) - 1)
36
rp = strsep_P (&sp, s2);
39
PRINTFLN (line, "false return value");
43
if (strcmp_P (t1, s1)) {
44
PRINTFLN (line, "string is changed");
48
if (strlen (t1) != (size_t)clr) {
49
PRINTFLN (line, "strlen: expect= %d result= %d",
53
if (memcmp_P (t1, s1, clr)
55
|| strcmp_P (t1 + clr + 1, s1 + clr + 1))
57
PRINTFLN (line, "string mismatch");
63
PRINTFLN (line, "sp is not a NULL");
68
PRINTFLN (line, "sp: expect= %d result= %d",
77
delim - delimeter list
78
clr - if (clr >= 0) s[cln] must be cleared
79
pnt - if (pnt >= 0) s[pnt] must be pointed, else NULL
81
#define CHECK(s, delim, clr, pnt) do { \
82
Check (__LINE__, PSTR(s), PSTR(delim), clr, pnt); \
89
/* NULL at first call */
91
if (strsep_P (&p, "") || p) exit (__LINE__);
92
if (strsep_P (&p, "abc") || p) exit (__LINE__);
95
CHECK ("", "", -1, -1);
96
CHECK ("", "abc", -1, -1);
98
/* Empty delimeter list */
99
CHECK ("a", "", -1, -1);
100
CHECK ("12345678", "", -1, -1);
102
/* No delimeter symbols are founded */
103
CHECK ("\tabc", " ", -1, -1);
104
CHECK ("THE QUICK BROWN FOX", "thequickbrownfox", -1, -1);
106
/* delim is 1 byte long */
107
CHECK (".", ".", 0, 1);
108
CHECK ("abc", "a", 0, 1);
109
CHECK ("abc", "b", 1, 2);
110
CHECK ("abc", "c", 2, 3);
112
/* delim is 2 bytes long */
113
CHECK ("0", "01", 0, 1);
114
CHECK ("1", "01", 0, 1);
115
CHECK ("A.", "AB", 0, 1);
116
CHECK ("B.", "AB", 0, 1);
117
CHECK ("CAD", "AB", 1, 2);
118
CHECK ("CDB", "AB", 2, 3);
120
/* delim length > 2 bytes */
121
CHECK ("the quick", "0123456789 ", 3, 4);
123
/* Very long string */
124
CHECK ("................................................................"
125
"................................................................"
126
"................................................................"
127
"...............................................................*",
129
CHECK ("................................................................"
130
"................................................................"
131
"................................................................"
132
"................................................................"
135
/* Non ASCII bytes */
136
CHECK ("\001\002\377", "\001", 0, 1);
137
CHECK ("\001\002\377", "\377", 2, 3);