1178476Sjb/*
2178476Sjb * CDDL HEADER START
3178476Sjb *
4178476Sjb * The contents of this file are subject to the terms of the
5178476Sjb * Common Development and Distribution License (the "License").
6178476Sjb * You may not use this file except in compliance with the License.
7178476Sjb *
8178476Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9178476Sjb * or http://www.opensolaris.org/os/licensing.
10178476Sjb * See the License for the specific language governing permissions
11178476Sjb * and limitations under the License.
12178476Sjb *
13178476Sjb * When distributing Covered Code, include this CDDL HEADER in each
14178476Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15178476Sjb * If applicable, add the following below this CDDL HEADER, with the
16178476Sjb * fields enclosed by brackets "[]" replaced with your own identifying
17178476Sjb * information: Portions Copyright [yyyy] [name of copyright owner]
18178476Sjb *
19178476Sjb * CDDL HEADER END
20178476Sjb */
21178476Sjb
22178476Sjb/*
23178476Sjb * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24178476Sjb * Use is subject to license terms.
25178476Sjb */
26178476Sjb
27178476Sjb#pragma ident	"%Z%%M%	%I%	%E% SMI"
28178476Sjb
29178476Sjb#pragma D option quiet
30178476Sjb
31178476SjbBEGIN
32178476Sjb{
33178476Sjb	this->str = ",,,Carrots,,Barley,Oatmeal,,,Beans,";
34178476Sjb}
35178476Sjb
36178476SjbBEGIN
37178476Sjb/(this->field = strtok(this->str, ",")) == NULL/
38178476Sjb{
39178476Sjb	exit(1);
40178476Sjb}
41178476Sjb
42178476SjbBEGIN
43178476Sjb{
44178476Sjb	printf("%s\n", this->field);
45178476Sjb}
46178476Sjb
47178476SjbBEGIN
48178476Sjb/(this->field = strtok(NULL, ",")) == NULL/
49178476Sjb{
50178476Sjb	exit(2);
51178476Sjb}
52178476Sjb
53178476SjbBEGIN
54178476Sjb{
55178476Sjb	printf("%s\n", this->field);
56178476Sjb}
57178476Sjb
58178476SjbBEGIN
59178476Sjb/(this->field = strtok(NULL, ",")) == NULL/
60178476Sjb{
61178476Sjb	exit(3);
62178476Sjb}
63178476Sjb
64178476SjbBEGIN
65178476Sjb{
66178476Sjb	printf("%s\n", this->field);
67178476Sjb}
68178476Sjb
69178476SjbBEGIN
70178476Sjb/(this->field = strtok(NULL, ",")) == NULL/
71178476Sjb{
72178476Sjb	exit(4);
73178476Sjb}
74178476Sjb
75178476SjbBEGIN
76178476Sjb{
77178476Sjb	printf("%s\n", this->field);
78178476Sjb}
79178476Sjb
80178476SjbBEGIN
81178476Sjb/(self->a = strtok(NULL, ",")) != NULL/
82178476Sjb{
83178476Sjb	printf("unexpected field: %s\n", this->field);
84178476Sjb	exit(5);
85178476Sjb}
86178476Sjb
87178476Sjbstruct {
88178476Sjb	string s1;
89178476Sjb	string s2;
90178476Sjb	string result;
91178476Sjb} command[int];
92178476Sjb
93178476Sjbint i;
94178476Sjb
95178476SjbBEGIN
96178476Sjb{
97178476Sjb	command[i].s1 = "";
98178476Sjb	command[i].s2 = "";
99178476Sjb	command[i].result = "";
100178476Sjb	i++;
101178476Sjb
102178476Sjb	command[i].s1 = "foo";
103178476Sjb	command[i].s2 = "";
104178476Sjb	command[i].result = command[i].s1;
105178476Sjb	i++;
106178476Sjb
107178476Sjb	command[i].s1 = "foobar";
108178476Sjb	command[i].s2 = "o";
109178476Sjb	command[i].result = "f";
110178476Sjb	i++;
111178476Sjb
112178476Sjb	command[i].s1 = "oobar";
113178476Sjb	command[i].s2 = "o";
114178476Sjb	command[i].result = "bar";
115178476Sjb	i++;
116178476Sjb
117178476Sjb	command[i].s1 = "foo";
118178476Sjb	command[i].s2 = "bar";
119178476Sjb	command[i].result = command[i].s1;
120178476Sjb	i++;
121178476Sjb
122178476Sjb	command[i].s1 = "";
123178476Sjb	command[i].s2 = "foo";
124178476Sjb	command[i].result = "";
125178476Sjb	i++;
126178476Sjb
127178476Sjb	end = i;
128178476Sjb	i = 0;
129178476Sjb}
130178476Sjb
131178476Sjbtick-1ms
132178476Sjb/i < end &&
133178476Sjb    (this->result = strtok(command[i].s1, command[i].s2)) != command[i].result/
134178476Sjb{
135178476Sjb	printf("strtok(\"%s\", \"%s\") = \"%s\", expected \"%s\"",
136178476Sjb	    command[i].s1, command[i].s2,
137178476Sjb	    this->result != NULL ? this->result : "<null>",
138178476Sjb	    command[i].result != NULL ? command[i].result : "<null>");
139178476Sjb	exit(6 + i);
140178476Sjb}
141178476Sjb
142178476Sjbtick-1ms
143178476Sjb/++i == end/
144178476Sjb{
145178476Sjb	exit(0);
146178476Sjb}
147