PageRenderTime 55ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/dilos/onarm-gate
D | 195 lines | 126 code | 40 blank | 29 comment | 2 complexity | 02bd9dcf354b0f0feceeaf8c3b5f4b4f MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, AGPL-3.0, MIT, Apache-2.0, 0BSD, GPL-2.0, LGPL-2.0, AGPL-1.0, BSD-3-Clause, LGPL-3.0, BSD-3-Clause-No-Nuclear-License-2014
  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. int index;
  29. int length;
  30. int nolen;
  31. } command[int];
  32. int i;
  33. BEGIN
  34. {
  35. str = "foobarbazbop";
  36. command[i].index = 3;
  37. command[i].nolen = 1;
  38. i++;
  39. command[i].index = 300;
  40. command[i].nolen = 1;
  41. i++;
  42. command[i].index = -10;
  43. command[i].nolen = 1;
  44. i++;
  45. command[i].index = 0;
  46. command[i].nolen = 1;
  47. i++;
  48. command[i].index = 1;
  49. command[i].nolen = 1;
  50. i++;
  51. command[i].index = strlen(str) - 1;
  52. command[i].nolen = 1;
  53. i++;
  54. command[i].index = strlen(str);
  55. command[i].nolen = 1;
  56. i++;
  57. command[i].index = strlen(str) + 1;
  58. command[i].nolen = 1;
  59. i++;
  60. command[i].index = 8;
  61. command[i].length = 20;
  62. i++;
  63. command[i].index = 4;
  64. command[i].length = 4;
  65. i++;
  66. command[i].index = 5;
  67. command[i].length = strlen(str) - command[i].index + 1;
  68. i++;
  69. command[i].index = 5;
  70. command[i].length = strlen(str) - command[i].index + 2;
  71. i++;
  72. command[i].index = 400;
  73. command[i].length = 20;
  74. i++;
  75. command[i].index = 400;
  76. command[i].length = 0;
  77. i++;
  78. command[i].index = 400;
  79. command[i].length = -1;
  80. i++;
  81. command[i].index = 3;
  82. command[i].length = 0;
  83. i++;
  84. command[i].index = 3;
  85. command[i].length = -1;
  86. i++;
  87. command[i].index = 0;
  88. command[i].length = 400;
  89. i++;
  90. command[i].index = -1;
  91. command[i].length = 400;
  92. i++;
  93. command[i].index = -1;
  94. command[i].length = 0;
  95. i++;
  96. command[i].index = -1;
  97. command[i].length = -1;
  98. i++;
  99. command[i].index = -2 * strlen(str);
  100. command[i].length = 2 * strlen(str);
  101. i++;
  102. command[i].index = -2 * strlen(str);
  103. command[i].length = strlen(str);
  104. i++;
  105. command[i].index = -2 * strlen(str);
  106. command[i].length = strlen(str) + 1;
  107. i++;
  108. command[i].index = -1 * strlen(str);
  109. command[i].length = strlen(str);
  110. i++;
  111. command[i].index = -1 * strlen(str);
  112. command[i].length = strlen(str) - 1;
  113. i++;
  114. end = i;
  115. i = 0;
  116. printf("#!/usr/perl5/bin/perl\n\nBEGIN {\n");
  117. }
  118. tick-1ms
  119. /i < end && command[i].nolen/
  120. {
  121. this->result = substr(str, command[i].index);
  122. printf("\tif (substr(\"%s\", %d) != \"%s\") {\n",
  123. str, command[i].index, this->result);
  124. printf("\t\tprintf(\"perl => substr(\\\"%s\\\", %d) = ",
  125. str, command[i].index);
  126. printf("\\\"%%s\\\"\\n\",\n\t\t substr(\"%s\", %d));\n",
  127. str, command[i].index);
  128. printf("\t\tprintf(\" D => substr(\\\"%s\\\", %d) = ",
  129. str, command[i].index);
  130. printf("\\\"%%s\\\"\\n\",\n\t\t \"%s\");\n", this->result);
  131. printf("\t\t$failed++;\n");
  132. printf("\t}\n\n");
  133. }
  134. tick-1ms
  135. /i < end && !command[i].nolen/
  136. {
  137. this->result = substr(str, command[i].index, command[i].length);
  138. printf("\tif (substr(\"%s\", %d, %d) != \"%s\") {\n",
  139. str, command[i].index, command[i].length, this->result);
  140. printf("\t\tprintf(\"perl => substr(\\\"%s\\\", %d, %d) = ",
  141. str, command[i].index, command[i].length);
  142. printf("\\\"%%s\\\"\\n\",\n\t\t substr(\"%s\", %d, %d));\n",
  143. str, command[i].index, command[i].length);
  144. printf("\t\tprintf(\" D => substr(\\\"%s\\\", %d, %d) = ",
  145. str, command[i].index, command[i].length);
  146. printf("\\\"%%s\\\"\\n\",\n\t\t \"%s\");\n", this->result);
  147. printf("\t\t$failed++;\n");
  148. printf("\t}\n\n");
  149. }
  150. tick-1ms
  151. /++i == end/
  152. {
  153. printf("\texit($failed);\n}\n");
  154. exit(0);
  155. }