xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/funcs/tst.index.d (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
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 ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #pragma D option quiet
30 
31 struct {
32 	string str;
33 	string substr;
34 	int haspos;
35 	int position;
36 } command[int];
37 
38 int i;
39 
40 BEGIN
41 {
42 	command[i].str = "foobarbaz";
43 	command[i].substr = "barbaz";
44 	i++;
45 
46 	command[i].str = "foofoofoo";
47 	command[i].substr = "foo";
48 	i++;
49 
50 	command[i].str = "boofoofoo";
51 	command[i].substr = "foo";
52 	i++;
53 
54 	command[i].str = "foobarbaz";
55 	command[i].substr = "barbazzy";
56 	i++;
57 
58 	command[i].str = "foobar";
59 	command[i].substr = "foobar";
60 	i++;
61 
62 	command[i].str = "foobar";
63 	command[i].substr = "foobarbaz";
64 	i++;
65 
66 	command[i].str = "";
67 	command[i].substr = "foobar";
68 	i++;
69 
70 	command[i].str = "foobar";
71 	command[i].substr = "";
72 	i++;
73 
74 	command[i].str = "";
75 	command[i].substr = "";
76 	i++;
77 
78 	command[i].str = "foo";
79 	command[i].substr = "";
80 	i++;
81 
82 	end = j = k = 0;
83 	printf("#!/usr/perl5/bin/perl\n\nBEGIN {\n");
84 }
85 
86 tick-1ms
87 /j < i && end == 0/
88 {
89 	command[i + k].str = command[j].str;
90 	command[i + k].substr = command[j].substr;
91 	command[i + k].haspos = 1;
92 	command[i + k].position = -400;
93 	k++;
94 
95 	command[i + k].str = command[j].str;
96 	command[i + k].substr = command[j].substr;
97 	command[i + k].haspos = 1;
98 	command[i + k].position = -1;
99 	k++;
100 
101 	command[i + k].str = command[j].str;
102 	command[i + k].substr = command[j].substr;
103 	command[i + k].haspos = 1;
104 	command[i + k].position = 0;
105 	k++;
106 
107 	command[i + k].str = command[j].str;
108 	command[i + k].substr = command[j].substr;
109 	command[i + k].haspos = 1;
110 	command[i + k].position = strlen(command[j].str) / 2;
111 	k++;
112 
113 	command[i + k].str = command[j].str;
114 	command[i + k].substr = command[j].substr;
115 	command[i + k].haspos = 1;
116 	command[i + k].position = strlen(command[j].str);
117 	k++;
118 
119 	command[i + k].str = command[j].str;
120 	command[i + k].substr = command[j].substr;
121 	command[i + k].haspos = 1;
122 	command[i + k].position = strlen(command[j].str) + 1;
123 	k++;
124 
125 	command[i + k].str = command[j].str;
126 	command[i + k].substr = command[j].substr;
127 	command[i + k].haspos = 1;
128 	command[i + k].position = strlen(command[j].str) + 2;
129 	k++;
130 
131 	command[i + k].str = command[j].str;
132 	command[i + k].substr = command[j].substr;
133 	command[i + k].haspos = 1;
134 	command[i + k].position = 400;
135 	k++;
136 
137 	j++;
138 }
139 
140 tick-1ms
141 /j == i && end == 0/
142 {
143 	end = k;
144 	i = 0;
145 }
146 
147 tick-1ms
148 /end != 0 && i < end && !command[i].haspos/
149 {
150 	this->result = index(command[i].str, command[i].substr);
151 
152 	printf("\tif (index(\"%s\", \"%s\") != %d) {\n",
153 	    command[i].str, command[i].substr, this->result);
154 	printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\") = ",
155 	    command[i].str, command[i].substr);
156 	printf("%%d\\n\",\n\t\t    index(\"%s\", \"%s\"));\n",
157 	    command[i].str, command[i].substr);
158 	printf("\t\tprintf(\"   D => index(\\\"%s\\\", \\\"%s\\\") = ",
159 	    command[i].str, command[i].substr);
160 	printf("%d\\n\");\n", this->result);
161 	printf("\t\t$failed++;\n");
162 	printf("\t}\n\n");
163 }
164 
165 tick-1ms
166 /end != 0 && i < end && !command[i].haspos/
167 {
168 	this->result = rindex(command[i].str, command[i].substr);
169 
170 	printf("\tif (rindex(\"%s\", \"%s\") != %d) {\n",
171 	    command[i].str, command[i].substr, this->result);
172 	printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\") = ",
173 	    command[i].str, command[i].substr);
174 	printf("%%d\\n\",\n\t\t    rindex(\"%s\", \"%s\"));\n",
175 	    command[i].str, command[i].substr);
176 	printf("\t\tprintf(\"   D => rindex(\\\"%s\\\", \\\"%s\\\") = ",
177 	    command[i].str, command[i].substr);
178 	printf("%d\\n\");\n", this->result);
179 	printf("\t\t$failed++;\n");
180 	printf("\t}\n\n");
181 }
182 
183 tick-1ms
184 /end != 0 && i < end && command[i].haspos/
185 {
186 	this->result = index(command[i].str,
187 	    command[i].substr, command[i].position);
188 
189 	printf("\tif (index(\"%s\", \"%s\", %d) != %d) {\n", command[i].str,
190 	    command[i].substr, command[i].position, this->result);
191 	printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\", %d) = ",
192 	    command[i].str, command[i].substr, command[i].position);
193 	printf("%%d\\n\",\n\t\t    index(\"%s\", \"%s\", %d));\n",
194 	    command[i].str, command[i].substr, command[i].position);
195 	printf("\t\tprintf(\"   D => index(\\\"%s\\\", \\\"%s\\\", %d) = ",
196 	    command[i].str, command[i].substr, command[i].position);
197 	printf("%d\\n\");\n", this->result);
198 	printf("\t\t$failed++;\n");
199 	printf("\t}\n\n");
200 }
201 
202 tick-1ms
203 /end != 0 && i < end && command[i].haspos/
204 {
205 	this->result = rindex(command[i].str,
206 	    command[i].substr, command[i].position);
207 
208 	printf("\tif (rindex(\"%s\", \"%s\", %d) != %d) {\n", command[i].str,
209 	    command[i].substr, command[i].position, this->result);
210 	printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ",
211 	    command[i].str, command[i].substr, command[i].position);
212 	printf("%%d\\n\",\n\t\t    rindex(\"%s\", \"%s\", %d));\n",
213 	    command[i].str, command[i].substr, command[i].position);
214 	printf("\t\tprintf(\"   D => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ",
215 	    command[i].str, command[i].substr, command[i].position);
216 	printf("%d\\n\");\n", this->result);
217 	printf("\t\t$failed++;\n");
218 	printf("\t}\n\n");
219 }
220 
221 tick-1ms
222 /end != 0 && ++i == end/
223 {
224 	printf("\texit($failed);\n}\n");
225 	exit(0);
226 }
227