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