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/* 23178476Sjb * Copyright 2006 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 30178476Sjb 31178476Sjbstruct { 32178476Sjb string str; 33178476Sjb string substr; 34178476Sjb int haspos; 35178476Sjb int position; 36178476Sjb} command[int]; 37178476Sjb 38178476Sjbint i; 39178476Sjb 40178476SjbBEGIN 41178476Sjb{ 42178476Sjb command[i].str = "foobarbaz"; 43178476Sjb command[i].substr = "barbaz"; 44178476Sjb i++; 45178476Sjb 46178476Sjb command[i].str = "foofoofoo"; 47178476Sjb command[i].substr = "foo"; 48178476Sjb i++; 49178476Sjb 50178476Sjb command[i].str = "boofoofoo"; 51178476Sjb command[i].substr = "foo"; 52178476Sjb i++; 53178476Sjb 54178476Sjb command[i].str = "foobarbaz"; 55178476Sjb command[i].substr = "barbazzy"; 56178476Sjb i++; 57178476Sjb 58178476Sjb command[i].str = "foobar"; 59178476Sjb command[i].substr = "foobar"; 60178476Sjb i++; 61178476Sjb 62178476Sjb command[i].str = "foobar"; 63178476Sjb command[i].substr = "foobarbaz"; 64178476Sjb i++; 65178476Sjb 66178476Sjb command[i].str = ""; 67178476Sjb command[i].substr = "foobar"; 68178476Sjb i++; 69178476Sjb 70178476Sjb command[i].str = "foobar"; 71178476Sjb command[i].substr = ""; 72178476Sjb i++; 73178476Sjb 74178476Sjb command[i].str = ""; 75178476Sjb command[i].substr = ""; 76178476Sjb i++; 77178476Sjb 78178476Sjb command[i].str = "foo"; 79178476Sjb command[i].substr = ""; 80178476Sjb i++; 81178476Sjb 82178476Sjb end = j = k = 0; 83211545Srpaulo printf("#!/usr/bin/perl\n\nBEGIN {\n"); 84178476Sjb} 85178476Sjb 86178476Sjbtick-1ms 87178476Sjb/j < i && end == 0/ 88178476Sjb{ 89178476Sjb command[i + k].str = command[j].str; 90178476Sjb command[i + k].substr = command[j].substr; 91178476Sjb command[i + k].haspos = 1; 92178476Sjb command[i + k].position = -400; 93178476Sjb k++; 94178476Sjb 95178476Sjb command[i + k].str = command[j].str; 96178476Sjb command[i + k].substr = command[j].substr; 97178476Sjb command[i + k].haspos = 1; 98178476Sjb command[i + k].position = -1; 99178476Sjb k++; 100178476Sjb 101178476Sjb command[i + k].str = command[j].str; 102178476Sjb command[i + k].substr = command[j].substr; 103178476Sjb command[i + k].haspos = 1; 104178476Sjb command[i + k].position = 0; 105178476Sjb k++; 106178476Sjb 107178476Sjb command[i + k].str = command[j].str; 108178476Sjb command[i + k].substr = command[j].substr; 109178476Sjb command[i + k].haspos = 1; 110178476Sjb command[i + k].position = strlen(command[j].str) / 2; 111178476Sjb k++; 112178476Sjb 113178476Sjb command[i + k].str = command[j].str; 114178476Sjb command[i + k].substr = command[j].substr; 115178476Sjb command[i + k].haspos = 1; 116178476Sjb command[i + k].position = strlen(command[j].str); 117178476Sjb k++; 118178476Sjb 119178476Sjb command[i + k].str = command[j].str; 120178476Sjb command[i + k].substr = command[j].substr; 121178476Sjb command[i + k].haspos = 1; 122178476Sjb command[i + k].position = strlen(command[j].str) + 1; 123178476Sjb k++; 124178476Sjb 125178476Sjb command[i + k].str = command[j].str; 126178476Sjb command[i + k].substr = command[j].substr; 127178476Sjb command[i + k].haspos = 1; 128178476Sjb command[i + k].position = strlen(command[j].str) + 2; 129178476Sjb k++; 130178476Sjb 131178476Sjb command[i + k].str = command[j].str; 132178476Sjb command[i + k].substr = command[j].substr; 133178476Sjb command[i + k].haspos = 1; 134178476Sjb command[i + k].position = 400; 135178476Sjb k++; 136178476Sjb 137178476Sjb j++; 138178476Sjb} 139178476Sjb 140178476Sjbtick-1ms 141178476Sjb/j == i && end == 0/ 142178476Sjb{ 143178476Sjb end = k; 144178476Sjb i = 0; 145178476Sjb} 146178476Sjb 147178476Sjbtick-1ms 148178476Sjb/end != 0 && i < end && !command[i].haspos/ 149178476Sjb{ 150178476Sjb this->result = index(command[i].str, command[i].substr); 151178476Sjb 152178476Sjb printf("\tif (index(\"%s\", \"%s\") != %d) {\n", 153178476Sjb command[i].str, command[i].substr, this->result); 154178476Sjb printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\") = ", 155178476Sjb command[i].str, command[i].substr); 156178476Sjb printf("%%d\\n\",\n\t\t index(\"%s\", \"%s\"));\n", 157178476Sjb command[i].str, command[i].substr); 158178476Sjb printf("\t\tprintf(\" D => index(\\\"%s\\\", \\\"%s\\\") = ", 159178476Sjb command[i].str, command[i].substr); 160178476Sjb printf("%d\\n\");\n", this->result); 161178476Sjb printf("\t\t$failed++;\n"); 162178476Sjb printf("\t}\n\n"); 163178476Sjb} 164178476Sjb 165178476Sjbtick-1ms 166178476Sjb/end != 0 && i < end && !command[i].haspos/ 167178476Sjb{ 168178476Sjb this->result = rindex(command[i].str, command[i].substr); 169178476Sjb 170178476Sjb printf("\tif (rindex(\"%s\", \"%s\") != %d) {\n", 171178476Sjb command[i].str, command[i].substr, this->result); 172178476Sjb printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\") = ", 173178476Sjb command[i].str, command[i].substr); 174178476Sjb printf("%%d\\n\",\n\t\t rindex(\"%s\", \"%s\"));\n", 175178476Sjb command[i].str, command[i].substr); 176178476Sjb printf("\t\tprintf(\" D => rindex(\\\"%s\\\", \\\"%s\\\") = ", 177178476Sjb command[i].str, command[i].substr); 178178476Sjb printf("%d\\n\");\n", this->result); 179178476Sjb printf("\t\t$failed++;\n"); 180178476Sjb printf("\t}\n\n"); 181178476Sjb} 182178476Sjb 183178476Sjbtick-1ms 184178476Sjb/end != 0 && i < end && command[i].haspos/ 185178476Sjb{ 186178476Sjb this->result = index(command[i].str, 187178476Sjb command[i].substr, command[i].position); 188178476Sjb 189178476Sjb printf("\tif (index(\"%s\", \"%s\", %d) != %d) {\n", command[i].str, 190178476Sjb command[i].substr, command[i].position, this->result); 191178476Sjb printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\", %d) = ", 192178476Sjb command[i].str, command[i].substr, command[i].position); 193178476Sjb printf("%%d\\n\",\n\t\t index(\"%s\", \"%s\", %d));\n", 194178476Sjb command[i].str, command[i].substr, command[i].position); 195178476Sjb printf("\t\tprintf(\" D => index(\\\"%s\\\", \\\"%s\\\", %d) = ", 196178476Sjb command[i].str, command[i].substr, command[i].position); 197178476Sjb printf("%d\\n\");\n", this->result); 198178476Sjb printf("\t\t$failed++;\n"); 199178476Sjb printf("\t}\n\n"); 200178476Sjb} 201178476Sjb 202178476Sjbtick-1ms 203178476Sjb/end != 0 && i < end && command[i].haspos/ 204178476Sjb{ 205178476Sjb this->result = rindex(command[i].str, 206178476Sjb command[i].substr, command[i].position); 207178476Sjb 208178476Sjb printf("\tif (rindex(\"%s\", \"%s\", %d) != %d) {\n", command[i].str, 209178476Sjb command[i].substr, command[i].position, this->result); 210178476Sjb printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ", 211178476Sjb command[i].str, command[i].substr, command[i].position); 212178476Sjb printf("%%d\\n\",\n\t\t rindex(\"%s\", \"%s\", %d));\n", 213178476Sjb command[i].str, command[i].substr, command[i].position); 214178476Sjb printf("\t\tprintf(\" D => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ", 215178476Sjb command[i].str, command[i].substr, command[i].position); 216178476Sjb printf("%d\\n\");\n", this->result); 217178476Sjb printf("\t\t$failed++;\n"); 218178476Sjb printf("\t}\n\n"); 219178476Sjb} 220178476Sjb 221178476Sjbtick-1ms 222178476Sjb/end != 0 && ++i == end/ 223178476Sjb{ 224178476Sjb printf("\texit($failed);\n}\n"); 225178476Sjb exit(0); 226178476Sjb} 227