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/*
23178534Sjb * Copyright 2008 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
30178534Sjb#pragma D option strsize=32
31178476Sjb
32178476Sjbstruct {
33178476Sjb	int index;
34178476Sjb	int length;
35178476Sjb	int nolen;
36178534Sjb	int alt;
37178476Sjb} command[int];
38178476Sjb
39178476Sjbint i;
40178476Sjb
41178476SjbBEGIN
42178476Sjb{
43178476Sjb	str = "foobarbazbop";
44178534Sjb	str2 = "";
45178534Sjb	altstr = "CRAIG: Positioned them, I don't ";
46178534Sjb	altstr2 = "know... I'm fairly wide guy.";
47178476Sjb
48178476Sjb	command[i].index = 3;
49178476Sjb	command[i].nolen = 1;
50178476Sjb	i++;
51178476Sjb
52178476Sjb	command[i].index = 300;
53178476Sjb	command[i].nolen = 1;
54178476Sjb	i++;
55178476Sjb
56178476Sjb	command[i].index = -10;
57178476Sjb	command[i].nolen = 1;
58178476Sjb	i++;
59178476Sjb
60178476Sjb	command[i].index = 0;
61178476Sjb	command[i].nolen = 1;
62178476Sjb	i++;
63178476Sjb
64178476Sjb	command[i].index = 1;
65178476Sjb	command[i].nolen = 1;
66178476Sjb	i++;
67178476Sjb
68178476Sjb	command[i].index = strlen(str) - 1;
69178476Sjb	command[i].nolen = 1;
70178476Sjb	i++;
71178476Sjb
72178476Sjb	command[i].index = strlen(str);
73178476Sjb	command[i].nolen = 1;
74178476Sjb	i++;
75178476Sjb
76178476Sjb	command[i].index = strlen(str) + 1;
77178476Sjb	command[i].nolen = 1;
78178476Sjb	i++;
79178476Sjb
80178476Sjb	command[i].index = 8;
81178476Sjb	command[i].length = 20;
82178476Sjb	i++;
83178476Sjb
84178476Sjb	command[i].index = 4;
85178476Sjb	command[i].length = 4;
86178476Sjb	i++;
87178476Sjb
88178476Sjb	command[i].index = 5;
89178476Sjb	command[i].length = strlen(str) - command[i].index + 1;
90178476Sjb	i++;
91178476Sjb
92178476Sjb	command[i].index = 5;
93178476Sjb	command[i].length = strlen(str) - command[i].index + 2;
94178476Sjb	i++;
95178476Sjb
96178476Sjb	command[i].index = 400;
97178476Sjb	command[i].length = 20;
98178476Sjb	i++;
99178476Sjb
100178476Sjb	command[i].index = 400;
101178476Sjb	command[i].length = 0;
102178476Sjb	i++;
103178476Sjb
104178476Sjb	command[i].index = 400;
105178476Sjb	command[i].length = -1;
106178476Sjb	i++;
107178476Sjb
108178476Sjb	command[i].index = 3;
109178476Sjb	command[i].length = 0;
110178476Sjb	i++;
111178476Sjb
112178476Sjb	command[i].index = 3;
113178476Sjb	command[i].length = -1;
114178476Sjb	i++;
115178476Sjb
116178534Sjb	command[i].index = 3;
117178534Sjb	command[i].length = -4;
118178534Sjb	i++;
119178534Sjb
120178534Sjb	command[i].index = 3;
121178534Sjb	command[i].length = -20;
122178534Sjb	i++;
123178534Sjb
124178534Sjb	command[i].index = -10;
125178534Sjb	command[i].length = -5;
126178534Sjb	i++;
127178534Sjb
128178476Sjb	command[i].index = 0;
129178476Sjb	command[i].length = 400;
130178476Sjb	i++;
131178476Sjb
132178476Sjb	command[i].index = -1;
133178476Sjb	command[i].length = 400;
134178476Sjb	i++;
135178476Sjb
136178476Sjb	command[i].index = -1;
137178476Sjb	command[i].length = 0;
138178476Sjb	i++;
139178476Sjb
140178476Sjb	command[i].index = -1;
141178476Sjb	command[i].length = -1;
142178476Sjb	i++;
143178476Sjb
144178476Sjb	command[i].index = -2 * strlen(str);
145178476Sjb	command[i].length = 2 * strlen(str);
146178476Sjb	i++;
147178476Sjb
148178476Sjb	command[i].index = -2 * strlen(str);
149178476Sjb	command[i].length = strlen(str);
150178476Sjb	i++;
151178476Sjb
152178476Sjb	command[i].index = -2 * strlen(str);
153178476Sjb	command[i].length = strlen(str) + 1;
154178476Sjb	i++;
155178476Sjb
156178476Sjb	command[i].index = -1 * strlen(str);
157178476Sjb	command[i].length = strlen(str);
158178476Sjb	i++;
159178476Sjb
160178476Sjb	command[i].index = -1 * strlen(str);
161178476Sjb	command[i].length = strlen(str) - 1;
162178476Sjb	i++;
163178476Sjb
164178534Sjb	command[i].index = 100;
165178534Sjb	command[i].length = 10;
166178534Sjb	command[i].alt = 1;
167178534Sjb	i++;
168178534Sjb
169178534Sjb	command[i].index = 100;
170178534Sjb	command[i].nolen = 1;
171178534Sjb	command[i].alt = 1;
172178534Sjb	i++;
173178534Sjb
174178476Sjb	end = i;
175178476Sjb	i = 0;
176178476Sjb	printf("#!/usr/perl5/bin/perl\n\nBEGIN {\n");
177178476Sjb
178178476Sjb}
179178476Sjb
180178476Sjbtick-1ms
181178476Sjb/i < end && command[i].nolen/
182178476Sjb{
183178534Sjb	this->str = command[i].alt ? altstr : str;
184178534Sjb	this->str2 = command[i].alt ? altstr2 : str2;
185178534Sjb	this->result = substr(command[i].alt ?
186178534Sjb	    "CRAIG: Positioned them, I don't know... I'm fairly wide guy." :
187178534Sjb	    str, command[i].index);
188178476Sjb
189178534Sjb	printf("\tif (substr(\"%s%s\", %d) ne \"%s\") {\n",
190178534Sjb	    this->str, this->str2, command[i].index, this->result);
191178476Sjb
192178534Sjb	printf("\t\tprintf(\"perl => substr(\\\"%s%s\\\", %d) = ",
193178534Sjb	    this->str, this->str2, command[i].index);
194178534Sjb	printf("\\\"%%s\\\"\\n\",\n\t\t    substr(\"%s%s\", %d));\n",
195178534Sjb	    this->str, this->str2, command[i].index);
196178534Sjb	printf("\t\tprintf(\"   D => substr(\\\"%s%s\\\", %d) = ",
197178534Sjb	    this->str, this->str2, command[i].index);
198178476Sjb	printf("\\\"%%s\\\"\\n\",\n\t\t    \"%s\");\n", this->result);
199178476Sjb	printf("\t\t$failed++;\n");
200178476Sjb	printf("\t}\n\n");
201178476Sjb}
202178476Sjb
203178476Sjbtick-1ms
204178476Sjb/i < end && !command[i].nolen/
205178476Sjb{
206178534Sjb	this->str = command[i].alt ? altstr : str;
207178534Sjb	this->str2 = command[i].alt ? altstr2 : str2;
208178534Sjb	this->result = substr(command[i].alt ?
209178534Sjb	    "CRAIG: Positioned them, I don't know... I'm fairly wide guy." :
210178534Sjb	    str, command[i].index, command[i].length);
211178528Sjb
212178534Sjb	printf("\tif (substr(\"%s%s\", %d, %d) ne \"%s\") {\n",
213178534Sjb	    this->str, this->str2, command[i].index, command[i].length,
214178534Sjb	    this->result);
215178534Sjb	printf("\t\tprintf(\"perl => substr(\\\"%s%s\\\", %d, %d) = ",
216178534Sjb	    this->str, this->str2, command[i].index, command[i].length);
217178534Sjb	printf("\\\"%%s\\\"\\n\",\n\t\t    substr(\"%s%s\", %d, %d));\n",
218178534Sjb	    this->str, this->str2, command[i].index, command[i].length);
219178534Sjb	printf("\t\tprintf(\"   D => substr(\\\"%s%s\\\", %d, %d) = ",
220178534Sjb	    this->str, this->str2, command[i].index, command[i].length);
221178476Sjb	printf("\\\"%%s\\\"\\n\",\n\t\t    \"%s\");\n", this->result);
222178476Sjb	printf("\t\t$failed++;\n");
223178476Sjb	printf("\t}\n\n");
224178476Sjb}
225178476Sjb
226178476Sjbtick-1ms
227178476Sjb/++i == end/
228178476Sjb{
229178476Sjb	printf("\texit($failed);\n}\n");
230178476Sjb	exit(0);
231178476Sjb}
232