PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/src/cmd/dtrace/test/tst/common/funcs/tst.index.d

https://bitbucket.org/nexenta/illumos-nexenta
D | 226 lines | 167 code | 35 blank | 24 comment | 20 complexity | 62713389795944600ff7b4c2792981f4 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, MPL-2.0-no-copyleft-exception, AGPL-1.0, GPL-3.0, LGPL-3.0, BSD-2-Clause, AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-2.1, 0BSD
  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. * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  23. * Use is subject to license terms.
  24. */
  25. #pragma ident "%Z%%M% %I% %E% SMI"
  26. #pragma D option quiet
  27. struct {
  28. string str;
  29. string substr;
  30. int haspos;
  31. int position;
  32. } command[int];
  33. int i;
  34. BEGIN
  35. {
  36. command[i].str = "foobarbaz";
  37. command[i].substr = "barbaz";
  38. i++;
  39. command[i].str = "foofoofoo";
  40. command[i].substr = "foo";
  41. i++;
  42. command[i].str = "boofoofoo";
  43. command[i].substr = "foo";
  44. i++;
  45. command[i].str = "foobarbaz";
  46. command[i].substr = "barbazzy";
  47. i++;
  48. command[i].str = "foobar";
  49. command[i].substr = "foobar";
  50. i++;
  51. command[i].str = "foobar";
  52. command[i].substr = "foobarbaz";
  53. i++;
  54. command[i].str = "";
  55. command[i].substr = "foobar";
  56. i++;
  57. command[i].str = "foobar";
  58. command[i].substr = "";
  59. i++;
  60. command[i].str = "";
  61. command[i].substr = "";
  62. i++;
  63. command[i].str = "foo";
  64. command[i].substr = "";
  65. i++;
  66. end = j = k = 0;
  67. printf("#!/usr/perl5/bin/perl\n\nBEGIN {\n");
  68. }
  69. tick-1ms
  70. /j < i && end == 0/
  71. {
  72. command[i + k].str = command[j].str;
  73. command[i + k].substr = command[j].substr;
  74. command[i + k].haspos = 1;
  75. command[i + k].position = -400;
  76. k++;
  77. command[i + k].str = command[j].str;
  78. command[i + k].substr = command[j].substr;
  79. command[i + k].haspos = 1;
  80. command[i + k].position = -1;
  81. k++;
  82. command[i + k].str = command[j].str;
  83. command[i + k].substr = command[j].substr;
  84. command[i + k].haspos = 1;
  85. command[i + k].position = 0;
  86. k++;
  87. command[i + k].str = command[j].str;
  88. command[i + k].substr = command[j].substr;
  89. command[i + k].haspos = 1;
  90. command[i + k].position = strlen(command[j].str) / 2;
  91. k++;
  92. command[i + k].str = command[j].str;
  93. command[i + k].substr = command[j].substr;
  94. command[i + k].haspos = 1;
  95. command[i + k].position = strlen(command[j].str);
  96. k++;
  97. command[i + k].str = command[j].str;
  98. command[i + k].substr = command[j].substr;
  99. command[i + k].haspos = 1;
  100. command[i + k].position = strlen(command[j].str) + 1;
  101. k++;
  102. command[i + k].str = command[j].str;
  103. command[i + k].substr = command[j].substr;
  104. command[i + k].haspos = 1;
  105. command[i + k].position = strlen(command[j].str) + 2;
  106. k++;
  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 = 400;
  111. k++;
  112. j++;
  113. }
  114. tick-1ms
  115. /j == i && end == 0/
  116. {
  117. end = k;
  118. i = 0;
  119. }
  120. tick-1ms
  121. /end != 0 && i < end && !command[i].haspos/
  122. {
  123. this->result = index(command[i].str, command[i].substr);
  124. printf("\tif (index(\"%s\", \"%s\") != %d) {\n",
  125. command[i].str, command[i].substr, this->result);
  126. printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\") = ",
  127. command[i].str, command[i].substr);
  128. printf("%%d\\n\",\n\t\t index(\"%s\", \"%s\"));\n",
  129. command[i].str, command[i].substr);
  130. printf("\t\tprintf(\" D => index(\\\"%s\\\", \\\"%s\\\") = ",
  131. command[i].str, command[i].substr);
  132. printf("%d\\n\");\n", this->result);
  133. printf("\t\t$failed++;\n");
  134. printf("\t}\n\n");
  135. }
  136. tick-1ms
  137. /end != 0 && i < end && !command[i].haspos/
  138. {
  139. this->result = rindex(command[i].str, command[i].substr);
  140. printf("\tif (rindex(\"%s\", \"%s\") != %d) {\n",
  141. command[i].str, command[i].substr, this->result);
  142. printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\") = ",
  143. command[i].str, command[i].substr);
  144. printf("%%d\\n\",\n\t\t rindex(\"%s\", \"%s\"));\n",
  145. command[i].str, command[i].substr);
  146. printf("\t\tprintf(\" D => rindex(\\\"%s\\\", \\\"%s\\\") = ",
  147. command[i].str, command[i].substr);
  148. printf("%d\\n\");\n", this->result);
  149. printf("\t\t$failed++;\n");
  150. printf("\t}\n\n");
  151. }
  152. tick-1ms
  153. /end != 0 && i < end && command[i].haspos/
  154. {
  155. this->result = index(command[i].str,
  156. command[i].substr, command[i].position);
  157. printf("\tif (index(\"%s\", \"%s\", %d) != %d) {\n", command[i].str,
  158. command[i].substr, command[i].position, this->result);
  159. printf("\t\tprintf(\"perl => index(\\\"%s\\\", \\\"%s\\\", %d) = ",
  160. command[i].str, command[i].substr, command[i].position);
  161. printf("%%d\\n\",\n\t\t index(\"%s\", \"%s\", %d));\n",
  162. command[i].str, command[i].substr, command[i].position);
  163. printf("\t\tprintf(\" D => index(\\\"%s\\\", \\\"%s\\\", %d) = ",
  164. command[i].str, command[i].substr, command[i].position);
  165. printf("%d\\n\");\n", this->result);
  166. printf("\t\t$failed++;\n");
  167. printf("\t}\n\n");
  168. }
  169. tick-1ms
  170. /end != 0 && i < end && command[i].haspos/
  171. {
  172. this->result = rindex(command[i].str,
  173. command[i].substr, command[i].position);
  174. printf("\tif (rindex(\"%s\", \"%s\", %d) != %d) {\n", command[i].str,
  175. command[i].substr, command[i].position, this->result);
  176. printf("\t\tprintf(\"perl => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ",
  177. command[i].str, command[i].substr, command[i].position);
  178. printf("%%d\\n\",\n\t\t rindex(\"%s\", \"%s\", %d));\n",
  179. command[i].str, command[i].substr, command[i].position);
  180. printf("\t\tprintf(\" D => rindex(\\\"%s\\\", \\\"%s\\\", %d) = ",
  181. command[i].str, command[i].substr, command[i].position);
  182. printf("%d\\n\");\n", this->result);
  183. printf("\t\t$failed++;\n");
  184. printf("\t}\n\n");
  185. }
  186. tick-1ms
  187. /end != 0 && ++i == end/
  188. {
  189. printf("\texit($failed);\n}\n");
  190. exit(0);
  191. }