]> git.sur5r.net Git - cc65/blob - testcode/lib/strqtok-test.c
Added a quoted-token parsing function.
[cc65] / testcode / lib / strqtok-test.c
1 /* strqtok-test.c
2 **
3 ** 2014-05-20, Greg King
4 **
5 ** This program tests that strqtok() correctly will parse strings
6 ** with quotation marks in them.  It should show this list of tokens
7 ** from the test strings:
8 **
9 ** >This<
10 ** >  is only    <
11 ** >a<
12 ** >short<
13 ** >quoting<
14 ** >test ,  honoring  blanks, commas<
15 ** >and<
16 ** >(4)<
17 ** >empty<
18 ** ><
19 ** ><
20 ** ><
21 ** ><
22 ** >strings,   EOT  <
23 **
24 ** It shouldn"t show
25 **
26 ** >Bogus token<
27 */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 void main(void)
33 {
34     /* b[] and s[] are declared as automatic, not static, variables
35     ** because strqtok() will change them.
36     ** They must be defined together; and, b[] must be defined first
37     ** (because they're copied onto the top-down stack).
38     */
39     char b[] = "Bogus token ";
40     char s[] = "  This ,  \"  is only    \"a   short   "
41         "quoting\"test ,  honoring  blanks"
42         ", commas\", and (4) empty \"\"\"\"\"\"\"\" \"strings,   EOT  ";
43     char *t = strqtok(s, " ,");
44
45     while (t != NULL) {
46         printf(">%s<\n", t);
47         t = strqtok(NULL, " ,");
48     }
49 }