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