19512fe85Sahl /*
29512fe85Sahl  * CDDL HEADER START
39512fe85Sahl  *
49512fe85Sahl  * The contents of this file are subject to the terms of the
59512fe85Sahl  * Common Development and Distribution License (the "License").
69512fe85Sahl  * You may not use this file except in compliance with the License.
79512fe85Sahl  *
89512fe85Sahl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99512fe85Sahl  * or http://www.opensolaris.org/os/licensing.
109512fe85Sahl  * See the License for the specific language governing permissions
119512fe85Sahl  * and limitations under the License.
129512fe85Sahl  *
139512fe85Sahl  * When distributing Covered Code, include this CDDL HEADER in each
149512fe85Sahl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159512fe85Sahl  * If applicable, add the following below this CDDL HEADER, with the
169512fe85Sahl  * fields enclosed by brackets "[]" replaced with your own identifying
179512fe85Sahl  * information: Portions Copyright [yyyy] [name of copyright owner]
189512fe85Sahl  *
199512fe85Sahl  * CDDL HEADER END
209512fe85Sahl  */
219512fe85Sahl 
229512fe85Sahl /*
23*6009dbc6Sahl  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
249512fe85Sahl  * Use is subject to license terms.
259512fe85Sahl  */
269512fe85Sahl 
279512fe85Sahl #pragma D option quiet
28*6009dbc6Sahl #pragma D option strsize=32
299512fe85Sahl 
309512fe85Sahl struct {
319512fe85Sahl 	int index;
329512fe85Sahl 	int length;
339512fe85Sahl 	int nolen;
34*6009dbc6Sahl 	int alt;
359512fe85Sahl } command[int];
369512fe85Sahl 
379512fe85Sahl int i;
389512fe85Sahl 
399512fe85Sahl BEGIN
409512fe85Sahl {
419512fe85Sahl 	str = "foobarbazbop";
42*6009dbc6Sahl 	str2 = "";
43*6009dbc6Sahl 	altstr = "CRAIG: Positioned them, I don't ";
44*6009dbc6Sahl 	altstr2 = "know... I'm fairly wide guy.";
459512fe85Sahl 
469512fe85Sahl 	command[i].index = 3;
479512fe85Sahl 	command[i].nolen = 1;
489512fe85Sahl 	i++;
499512fe85Sahl 
509512fe85Sahl 	command[i].index = 300;
519512fe85Sahl 	command[i].nolen = 1;
529512fe85Sahl 	i++;
539512fe85Sahl 
549512fe85Sahl 	command[i].index = -10;
559512fe85Sahl 	command[i].nolen = 1;
569512fe85Sahl 	i++;
579512fe85Sahl 
589512fe85Sahl 	command[i].index = 0;
599512fe85Sahl 	command[i].nolen = 1;
609512fe85Sahl 	i++;
619512fe85Sahl 
629512fe85Sahl 	command[i].index = 1;
639512fe85Sahl 	command[i].nolen = 1;
649512fe85Sahl 	i++;
659512fe85Sahl 
669512fe85Sahl 	command[i].index = strlen(str) - 1;
679512fe85Sahl 	command[i].nolen = 1;
689512fe85Sahl 	i++;
699512fe85Sahl 
709512fe85Sahl 	command[i].index = strlen(str);
719512fe85Sahl 	command[i].nolen = 1;
729512fe85Sahl 	i++;
739512fe85Sahl 
749512fe85Sahl 	command[i].index = strlen(str) + 1;
759512fe85Sahl 	command[i].nolen = 1;
769512fe85Sahl 	i++;
779512fe85Sahl 
789512fe85Sahl 	command[i].index = 8;
799512fe85Sahl 	command[i].length = 20;
809512fe85Sahl 	i++;
819512fe85Sahl 
829512fe85Sahl 	command[i].index = 4;
839512fe85Sahl 	command[i].length = 4;
849512fe85Sahl 	i++;
859512fe85Sahl 
869512fe85Sahl 	command[i].index = 5;
879512fe85Sahl 	command[i].length = strlen(str) - command[i].index + 1;
889512fe85Sahl 	i++;
899512fe85Sahl 
909512fe85Sahl 	command[i].index = 5;
919512fe85Sahl 	command[i].length = strlen(str) - command[i].index + 2;
929512fe85Sahl 	i++;
939512fe85Sahl 
949512fe85Sahl 	command[i].index = 400;
959512fe85Sahl 	command[i].length = 20;
969512fe85Sahl 	i++;
979512fe85Sahl 
989512fe85Sahl 	command[i].index = 400;
999512fe85Sahl 	command[i].length = 0;
1009512fe85Sahl 	i++;
1019512fe85Sahl 
1029512fe85Sahl 	command[i].index = 400;
1039512fe85Sahl 	command[i].length = -1;
1049512fe85Sahl 	i++;
1059512fe85Sahl 
1069512fe85Sahl 	command[i].index = 3;
1079512fe85Sahl 	command[i].length = 0;
1089512fe85Sahl 	i++;
1099512fe85Sahl 
1109512fe85Sahl 	command[i].index = 3;
1119512fe85Sahl 	command[i].length = -1;
1129512fe85Sahl 	i++;
1139512fe85Sahl 
114*6009dbc6Sahl 	command[i].index = 3;
115*6009dbc6Sahl 	command[i].length = -4;
116*6009dbc6Sahl 	i++;
117*6009dbc6Sahl 
118*6009dbc6Sahl 	command[i].index = 3;
119*6009dbc6Sahl 	command[i].length = -20;
120*6009dbc6Sahl 	i++;
121*6009dbc6Sahl 
122*6009dbc6Sahl 	command[i].index = -10;
123*6009dbc6Sahl 	command[i].length = -5;
124*6009dbc6Sahl 	i++;
125*6009dbc6Sahl 
1269512fe85Sahl 	command[i].index = 0;
1279512fe85Sahl 	command[i].length = 400;
1289512fe85Sahl 	i++;
1299512fe85Sahl 
1309512fe85Sahl 	command[i].index = -1;
1319512fe85Sahl 	command[i].length = 400;
1329512fe85Sahl 	i++;
1339512fe85Sahl 
1349512fe85Sahl 	command[i].index = -1;
1359512fe85Sahl 	command[i].length = 0;
1369512fe85Sahl 	i++;
1379512fe85Sahl 
1389512fe85Sahl 	command[i].index = -1;
1399512fe85Sahl 	command[i].length = -1;
1409512fe85Sahl 	i++;
1419512fe85Sahl 
1429512fe85Sahl 	command[i].index = -2 * strlen(str);
1439512fe85Sahl 	command[i].length = 2 * strlen(str);
1449512fe85Sahl 	i++;
1459512fe85Sahl 
1469512fe85Sahl 	command[i].index = -2 * strlen(str);
1479512fe85Sahl 	command[i].length = strlen(str);
1489512fe85Sahl 	i++;
1499512fe85Sahl 
1509512fe85Sahl 	command[i].index = -2 * strlen(str);
1519512fe85Sahl 	command[i].length = strlen(str) + 1;
1529512fe85Sahl 	i++;
1539512fe85Sahl 
1549512fe85Sahl 	command[i].index = -1 * strlen(str);
1559512fe85Sahl 	command[i].length = strlen(str);
1569512fe85Sahl 	i++;
1579512fe85Sahl 
1589512fe85Sahl 	command[i].index = -1 * strlen(str);
1599512fe85Sahl 	command[i].length = strlen(str) - 1;
1609512fe85Sahl 	i++;
1619512fe85Sahl 
162*6009dbc6Sahl 	command[i].index = 100;
163*6009dbc6Sahl 	command[i].length = 10;
164*6009dbc6Sahl 	command[i].alt = 1;
165*6009dbc6Sahl 	i++;
166*6009dbc6Sahl 
167*6009dbc6Sahl 	command[i].index = 100;
168*6009dbc6Sahl 	command[i].nolen = 1;
169*6009dbc6Sahl 	command[i].alt = 1;
170*6009dbc6Sahl 	i++;
171*6009dbc6Sahl 
1729512fe85Sahl 	end = i;
1739512fe85Sahl 	i = 0;
1749512fe85Sahl 	printf("#!/usr/perl5/bin/perl\n\nBEGIN {\n");
1759512fe85Sahl 
1769512fe85Sahl }
1779512fe85Sahl 
1789512fe85Sahl tick-1ms
1799512fe85Sahl /i < end && command[i].nolen/
1809512fe85Sahl {
181*6009dbc6Sahl 	this->str = command[i].alt ? altstr : str;
182*6009dbc6Sahl 	this->str2 = command[i].alt ? altstr2 : str2;
183*6009dbc6Sahl 	this->result = substr(command[i].alt ?
184*6009dbc6Sahl 	    "CRAIG: Positioned them, I don't know... I'm fairly wide guy." :
185*6009dbc6Sahl 	    str, command[i].index);
1869512fe85Sahl 
187*6009dbc6Sahl 	printf("\tif (substr(\"%s%s\", %d) ne \"%s\") {\n",
188*6009dbc6Sahl 	    this->str, this->str2, command[i].index, this->result);
1899512fe85Sahl 
190*6009dbc6Sahl 	printf("\t\tprintf(\"perl => substr(\\\"%s%s\\\", %d) = ",
191*6009dbc6Sahl 	    this->str, this->str2, command[i].index);
192*6009dbc6Sahl 	printf("\\\"%%s\\\"\\n\",\n\t\t    substr(\"%s%s\", %d));\n",
193*6009dbc6Sahl 	    this->str, this->str2, command[i].index);
194*6009dbc6Sahl 	printf("\t\tprintf(\"   D => substr(\\\"%s%s\\\", %d) = ",
195*6009dbc6Sahl 	    this->str, this->str2, command[i].index);
1969512fe85Sahl 	printf("\\\"%%s\\\"\\n\",\n\t\t    \"%s\");\n", this->result);
1979512fe85Sahl 	printf("\t\t$failed++;\n");
1989512fe85Sahl 	printf("\t}\n\n");
1999512fe85Sahl }
2009512fe85Sahl 
2019512fe85Sahl tick-1ms
2029512fe85Sahl /i < end && !command[i].nolen/
2039512fe85Sahl {
204*6009dbc6Sahl 	this->str = command[i].alt ? altstr : str;
205*6009dbc6Sahl 	this->str2 = command[i].alt ? altstr2 : str2;
206*6009dbc6Sahl 	this->result = substr(command[i].alt ?
207*6009dbc6Sahl 	    "CRAIG: Positioned them, I don't know... I'm fairly wide guy." :
2089512fe85Sahl 	    str, command[i].index, command[i].length);
209*6009dbc6Sahl 
210*6009dbc6Sahl 	printf("\tif (substr(\"%s%s\", %d, %d) ne \"%s\") {\n",
211*6009dbc6Sahl 	    this->str, this->str2, command[i].index, command[i].length,
212*6009dbc6Sahl 	    this->result);
213*6009dbc6Sahl 	printf("\t\tprintf(\"perl => substr(\\\"%s%s\\\", %d, %d) = ",
214*6009dbc6Sahl 	    this->str, this->str2, command[i].index, command[i].length);
215*6009dbc6Sahl 	printf("\\\"%%s\\\"\\n\",\n\t\t    substr(\"%s%s\", %d, %d));\n",
216*6009dbc6Sahl 	    this->str, this->str2, command[i].index, command[i].length);
217*6009dbc6Sahl 	printf("\t\tprintf(\"   D => substr(\\\"%s%s\\\", %d, %d) = ",
218*6009dbc6Sahl 	    this->str, this->str2, command[i].index, command[i].length);
2199512fe85Sahl 	printf("\\\"%%s\\\"\\n\",\n\t\t    \"%s\");\n", this->result);
2209512fe85Sahl 	printf("\t\t$failed++;\n");
2219512fe85Sahl 	printf("\t}\n\n");
2229512fe85Sahl }
2239512fe85Sahl 
2249512fe85Sahl tick-1ms
2259512fe85Sahl /++i == end/
2269512fe85Sahl {
2279512fe85Sahl 	printf("\texit($failed);\n}\n");
2289512fe85Sahl 	exit(0);
2299512fe85Sahl }
230