xref: /onnv-gate/usr/src/cmd/dtrace/test/tst/common/funcs/tst.index.d (revision 2633:71bab08d24b2)
1*2633Sahl /*
2*2633Sahl  * CDDL HEADER START
3*2633Sahl  *
4*2633Sahl  * The contents of this file are subject to the terms of the
5*2633Sahl  * Common Development and Distribution License (the "License").
6*2633Sahl  * You may not use this file except in compliance with the License.
7*2633Sahl  *
8*2633Sahl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2633Sahl  * or http://www.opensolaris.org/os/licensing.
10*2633Sahl  * See the License for the specific language governing permissions
11*2633Sahl  * and limitations under the License.
12*2633Sahl  *
13*2633Sahl  * When distributing Covered Code, include this CDDL HEADER in each
14*2633Sahl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2633Sahl  * If applicable, add the following below this CDDL HEADER, with the
16*2633Sahl  * fields enclosed by brackets "[]" replaced with your own identifying
17*2633Sahl  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2633Sahl  *
19*2633Sahl  * CDDL HEADER END
20*2633Sahl  */
21*2633Sahl 
22*2633Sahl /*
23*2633Sahl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*2633Sahl  * Use is subject to license terms.
25*2633Sahl  */
26*2633Sahl 
27*2633Sahl #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*2633Sahl 
29*2633Sahl #pragma D option quiet
30*2633Sahl 
31*2633Sahl struct {
32*2633Sahl 	string str;
33*2633Sahl 	string substr;
34*2633Sahl 	int haspos;
35*2633Sahl 	int position;
36*2633Sahl } command[int];
37*2633Sahl 
38*2633Sahl int i;
39*2633Sahl 
40*2633Sahl BEGIN
41*2633Sahl {
42*2633Sahl 	command[i].str = "foobarbaz";
43*2633Sahl 	command[i].substr = "barbaz";
44*2633Sahl 	i++;
45*2633Sahl 
46*2633Sahl 	command[i].str = "foofoofoo";
47*2633Sahl 	command[i].substr = "foo";
48*2633Sahl 	i++;
49*2633Sahl 
50*2633Sahl 	command[i].str = "boofoofoo";
51*2633Sahl 	command[i].substr = "foo";
52*2633Sahl 	i++;
53*2633Sahl 
54*2633Sahl 	command[i].str = "foobarbaz";
55*2633Sahl 	command[i].substr = "barbazzy";
56*2633Sahl 	i++;
57*2633Sahl 
58*2633Sahl 	command[i].str = "foobar";
59*2633Sahl 	command[i].substr = "foobar";
60*2633Sahl 	i++;
61*2633Sahl 
62*2633Sahl 	command[i].str = "foobar";
63*2633Sahl 	command[i].substr = "foobarbaz";
64*2633Sahl 	i++;
65*2633Sahl 
66*2633Sahl 	command[i].str = "";
67*2633Sahl 	command[i].substr = "foobar";
68*2633Sahl 	i++;
69*2633Sahl 
70*2633Sahl 	command[i].str = "foobar";
71*2633Sahl 	command[i].substr = "";
72*2633Sahl 	i++;
73*2633Sahl 
74*2633Sahl 	command[i].str = "";
75*2633Sahl 	command[i].substr = "";
76*2633Sahl 	i++;
77*2633Sahl 
78*2633Sahl 	command[i].str = "foo";
79*2633Sahl 	command[i].substr = "";
80*2633Sahl 	i++;
81*2633Sahl 
82*2633Sahl 	end = j = k = 0;
83*2633Sahl 	printf("#!/usr/perl5/bin/perl\n\nBEGIN {\n");
84*2633Sahl }
85*2633Sahl 
86*2633Sahl tick-1ms
87*2633Sahl /j < i && end == 0/
88*2633Sahl {
89*2633Sahl 	command[i + k].str = command[j].str;
90*2633Sahl 	command[i + k].substr = command[j].substr;
91*2633Sahl 	command[i + k].haspos = 1;
92*2633Sahl 	command[i + k].position = -400;
93*2633Sahl 	k++;
94*2633Sahl 
95*2633Sahl 	command[i + k].str = command[j].str;
96*2633Sahl 	command[i + k].substr = command[j].substr;
97*2633Sahl 	command[i + k].haspos = 1;
98*2633Sahl 	command[i + k].position = -1;
99*2633Sahl 	k++;
100*2633Sahl 
101*2633Sahl 	command[i + k].str = command[j].str;
102*2633Sahl 	command[i + k].substr = command[j].substr;
103*2633Sahl 	command[i + k].haspos = 1;
104*2633Sahl 	command[i + k].position = 0;
105*2633Sahl 	k++;
106*2633Sahl 
107*2633Sahl 	command[i + k].str = command[j].str;
108*2633Sahl 	command[i + k].substr = command[j].substr;
109*2633Sahl 	command[i + k].haspos = 1;
110*2633Sahl 	command[i + k].position = strlen(command[j].str) / 2;
111*2633Sahl 	k++;
112*2633Sahl 
113*2633Sahl 	command[i + k].str = command[j].str;
114*2633Sahl 	command[i + k].substr = command[j].substr;
115*2633Sahl 	command[i + k].haspos = 1;
116*2633Sahl 	command[i + k].position = strlen(command[j].str);
117*2633Sahl 	k++;
118*2633Sahl 
119*2633Sahl 	command[i + k].str = command[j].str;
120*2633Sahl 	command[i + k].substr = command[j].substr;
121*2633Sahl 	command[i + k].haspos = 1;
122*2633Sahl 	command[i + k].position = strlen(command[j].str) + 1;
123*2633Sahl 	k++;
124*2633Sahl 
125*2633Sahl 	command[i + k].str = command[j].str;
126*2633Sahl 	command[i + k].substr = command[j].substr;
127*2633Sahl 	command[i + k].haspos = 1;
128*2633Sahl 	command[i + k].position = strlen(command[j].str) + 2;
129*2633Sahl 	k++;
130*2633Sahl 
131*2633Sahl 	command[i + k].str = command[j].str;
132*2633Sahl 	command[i + k].substr = command[j].substr;
133*2633Sahl 	command[i + k].haspos = 1;
134*2633Sahl 	command[i + k].position = 400;
135*2633Sahl 	k++;
136*2633Sahl 
137*2633Sahl 	j++;
138*2633Sahl }
139*2633Sahl 
140*2633Sahl tick-1ms
141*2633Sahl /j == i && end == 0/
142*2633Sahl {
143*2633Sahl 	end = k;
144*2633Sahl 	i = 0;
145*2633Sahl }
146*2633Sahl 
147*2633Sahl tick-1ms
148*2633Sahl /end != 0 && i < end && !command[i].haspos/
149*2633Sahl {
150*2633Sahl 	this->result = index(command[i].str, command[i].substr);
151*2633Sahl 
152*2633Sahl 	printf("\tif (index(\"%s\", \"%s\") != %d) {\n",
153*2633Sahl 	    command[i].str, command[i].substr, this->result);
154*2633Sahl 	printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\") = ",
155*2633Sahl 	    command[i].str, command[i].substr);
156*2633Sahl 	printf("%%d\\n\",\n\t\t    index(\"%s\", \"%s\"));\n",
157*2633Sahl 	    command[i].str, command[i].substr);
158*2633Sahl 	printf("\t\tprintf(\"   D => index(\\\"%s\\\", \\\"%s\\\") = ",
159*2633Sahl 	    command[i].str, command[i].substr);
160*2633Sahl 	printf("%d\\n\");\n", this->result);
161*2633Sahl 	printf("\t\t$failed++;\n");
162*2633Sahl 	printf("\t}\n\n");
163*2633Sahl }
164*2633Sahl 
165*2633Sahl tick-1ms
166*2633Sahl /end != 0 && i < end && !command[i].haspos/
167*2633Sahl {
168*2633Sahl 	this->result = rindex(command[i].str, command[i].substr);
169*2633Sahl 
170*2633Sahl 	printf("\tif (rindex(\"%s\", \"%s\") != %d) {\n",
171*2633Sahl 	    command[i].str, command[i].substr, this->result);
172*2633Sahl 	printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\") = ",
173*2633Sahl 	    command[i].str, command[i].substr);
174*2633Sahl 	printf("%%d\\n\",\n\t\t    rindex(\"%s\", \"%s\"));\n",
175*2633Sahl 	    command[i].str, command[i].substr);
176*2633Sahl 	printf("\t\tprintf(\"   D => rindex(\\\"%s\\\", \\\"%s\\\") = ",
177*2633Sahl 	    command[i].str, command[i].substr);
178*2633Sahl 	printf("%d\\n\");\n", this->result);
179*2633Sahl 	printf("\t\t$failed++;\n");
180*2633Sahl 	printf("\t}\n\n");
181*2633Sahl }
182*2633Sahl 
183*2633Sahl tick-1ms
184*2633Sahl /end != 0 && i < end && command[i].haspos/
185*2633Sahl {
186*2633Sahl 	this->result = index(command[i].str,
187*2633Sahl 	    command[i].substr, command[i].position);
188*2633Sahl 
189*2633Sahl 	printf("\tif (index(\"%s\", \"%s\", %d) != %d) {\n", command[i].str,
190*2633Sahl 	    command[i].substr, command[i].position, this->result);
191*2633Sahl 	printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\", %d) = ",
192*2633Sahl 	    command[i].str, command[i].substr, command[i].position);
193*2633Sahl 	printf("%%d\\n\",\n\t\t    index(\"%s\", \"%s\", %d));\n",
194*2633Sahl 	    command[i].str, command[i].substr, command[i].position);
195*2633Sahl 	printf("\t\tprintf(\"   D => index(\\\"%s\\\", \\\"%s\\\", %d) = ",
196*2633Sahl 	    command[i].str, command[i].substr, command[i].position);
197*2633Sahl 	printf("%d\\n\");\n", this->result);
198*2633Sahl 	printf("\t\t$failed++;\n");
199*2633Sahl 	printf("\t}\n\n");
200*2633Sahl }
201*2633Sahl 
202*2633Sahl tick-1ms
203*2633Sahl /end != 0 && i < end && command[i].haspos/
204*2633Sahl {
205*2633Sahl 	this->result = rindex(command[i].str,
206*2633Sahl 	    command[i].substr, command[i].position);
207*2633Sahl 
208*2633Sahl 	printf("\tif (rindex(\"%s\", \"%s\", %d) != %d) {\n", command[i].str,
209*2633Sahl 	    command[i].substr, command[i].position, this->result);
210*2633Sahl 	printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ",
211*2633Sahl 	    command[i].str, command[i].substr, command[i].position);
212*2633Sahl 	printf("%%d\\n\",\n\t\t    rindex(\"%s\", \"%s\", %d));\n",
213*2633Sahl 	    command[i].str, command[i].substr, command[i].position);
214*2633Sahl 	printf("\t\tprintf(\"   D => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ",
215*2633Sahl 	    command[i].str, command[i].substr, command[i].position);
216*2633Sahl 	printf("%d\\n\");\n", this->result);
217*2633Sahl 	printf("\t\t$failed++;\n");
218*2633Sahl 	printf("\t}\n\n");
219*2633Sahl }
220*2633Sahl 
221*2633Sahl tick-1ms
222*2633Sahl /end != 0 && ++i == end/
223*2633Sahl {
224*2633Sahl 	printf("\texit($failed);\n}\n");
225*2633Sahl 	exit(0);
226*2633Sahl }
227