PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/buffyg/illumos-gate-1514
D | 231 lines | 157 code | 45 blank | 29 comment | 2 complexity | 3d3b44e37e89670dc2d14f5febf8c477 MD5 | raw file
Possible License(s): BSD-3-Clause-No-Nuclear-License-2014, MPL-2.0-no-copyleft-exception, AGPL-3.0, GPL-2.0, GPL-3.0, LGPL-3.0, 0BSD, AGPL-1.0, BSD-3-Clause, LGPL-2.1, LGPL-2.0, BSD-2-Clause
  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 2008 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. #pragma D option strsize=32
  28. struct {
  29. int index;
  30. int length;
  31. int nolen;
  32. int alt;
  33. } command[int];
  34. int i;
  35. BEGIN
  36. {
  37. str = "foobarbazbop";
  38. str2 = "";
  39. altstr = "CRAIG: Positioned them, I don't ";
  40. altstr2 = "know... I'm fairly wide guy.";
  41. command[i].index = 3;
  42. command[i].nolen = 1;
  43. i++;
  44. command[i].index = 300;
  45. command[i].nolen = 1;
  46. i++;
  47. command[i].index = -10;
  48. command[i].nolen = 1;
  49. i++;
  50. command[i].index = 0;
  51. command[i].nolen = 1;
  52. i++;
  53. command[i].index = 1;
  54. command[i].nolen = 1;
  55. i++;
  56. command[i].index = strlen(str) - 1;
  57. command[i].nolen = 1;
  58. i++;
  59. command[i].index = strlen(str);
  60. command[i].nolen = 1;
  61. i++;
  62. command[i].index = strlen(str) + 1;
  63. command[i].nolen = 1;
  64. i++;
  65. command[i].index = 8;
  66. command[i].length = 20;
  67. i++;
  68. command[i].index = 4;
  69. command[i].length = 4;
  70. i++;
  71. command[i].index = 5;
  72. command[i].length = strlen(str) - command[i].index + 1;
  73. i++;
  74. command[i].index = 5;
  75. command[i].length = strlen(str) - command[i].index + 2;
  76. i++;
  77. command[i].index = 400;
  78. command[i].length = 20;
  79. i++;
  80. command[i].index = 400;
  81. command[i].length = 0;
  82. i++;
  83. command[i].index = 400;
  84. command[i].length = -1;
  85. i++;
  86. command[i].index = 3;
  87. command[i].length = 0;
  88. i++;
  89. command[i].index = 3;
  90. command[i].length = -1;
  91. i++;
  92. command[i].index = 3;
  93. command[i].length = -4;
  94. i++;
  95. command[i].index = 3;
  96. command[i].length = -20;
  97. i++;
  98. command[i].index = -10;
  99. command[i].length = -5;
  100. i++;
  101. command[i].index = 0;
  102. command[i].length = 400;
  103. i++;
  104. command[i].index = -1;
  105. command[i].length = 400;
  106. i++;
  107. command[i].index = -1;
  108. command[i].length = 0;
  109. i++;
  110. command[i].index = -1;
  111. command[i].length = -1;
  112. i++;
  113. command[i].index = -2 * strlen(str);
  114. command[i].length = 2 * strlen(str);
  115. i++;
  116. command[i].index = -2 * strlen(str);
  117. command[i].length = strlen(str);
  118. i++;
  119. command[i].index = -2 * strlen(str);
  120. command[i].length = strlen(str) + 1;
  121. i++;
  122. command[i].index = -1 * strlen(str);
  123. command[i].length = strlen(str);
  124. i++;
  125. command[i].index = -1 * strlen(str);
  126. command[i].length = strlen(str) - 1;
  127. i++;
  128. command[i].index = 100;
  129. command[i].length = 10;
  130. command[i].alt = 1;
  131. i++;
  132. command[i].index = 100;
  133. command[i].nolen = 1;
  134. command[i].alt = 1;
  135. i++;
  136. end = i;
  137. i = 0;
  138. printf("#!/usr/perl5/bin/perl\n\nBEGIN {\n");
  139. }
  140. tick-1ms
  141. /i < end && command[i].nolen/
  142. {
  143. this->str = command[i].alt ? altstr : str;
  144. this->str2 = command[i].alt ? altstr2 : str2;
  145. this->result = substr(command[i].alt ?
  146. "CRAIG: Positioned them, I don't know... I'm fairly wide guy." :
  147. str, command[i].index);
  148. printf("\tif (substr(\"%s%s\", %d) ne \"%s\") {\n",
  149. this->str, this->str2, command[i].index, this->result);
  150. printf("\t\tprintf(\"perl => substr(\\\"%s%s\\\", %d) = ",
  151. this->str, this->str2, command[i].index);
  152. printf("\\\"%%s\\\"\\n\",\n\t\t substr(\"%s%s\", %d));\n",
  153. this->str, this->str2, command[i].index);
  154. printf("\t\tprintf(\" D => substr(\\\"%s%s\\\", %d) = ",
  155. this->str, this->str2, command[i].index);
  156. printf("\\\"%%s\\\"\\n\",\n\t\t \"%s\");\n", this->result);
  157. printf("\t\t$failed++;\n");
  158. printf("\t}\n\n");
  159. }
  160. tick-1ms
  161. /i < end && !command[i].nolen/
  162. {
  163. this->str = command[i].alt ? altstr : str;
  164. this->str2 = command[i].alt ? altstr2 : str2;
  165. this->result = substr(command[i].alt ?
  166. "CRAIG: Positioned them, I don't know... I'm fairly wide guy." :
  167. str, command[i].index, command[i].length);
  168. printf("\tif (substr(\"%s%s\", %d, %d) ne \"%s\") {\n",
  169. this->str, this->str2, command[i].index, command[i].length,
  170. this->result);
  171. printf("\t\tprintf(\"perl => substr(\\\"%s%s\\\", %d, %d) = ",
  172. this->str, this->str2, command[i].index, command[i].length);
  173. printf("\\\"%%s\\\"\\n\",\n\t\t substr(\"%s%s\", %d, %d));\n",
  174. this->str, this->str2, command[i].index, command[i].length);
  175. printf("\t\tprintf(\" D => substr(\\\"%s%s\\\", %d, %d) = ",
  176. this->str, this->str2, command[i].index, command[i].length);
  177. printf("\\\"%%s\\\"\\n\",\n\t\t \"%s\");\n", this->result);
  178. printf("\t\t$failed++;\n");
  179. printf("\t}\n\n");
  180. }
  181. tick-1ms
  182. /++i == end/
  183. {
  184. printf("\texit($failed);\n}\n");
  185. exit(0);
  186. }