makestub.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. $s = str_replace("\r", '', file_get_contents(dirname(__FILE__) . '/shortarc.php'));
  3. $s .= "\nExtract_Phar::go();\n__HALT_COMPILER();";
  4. $news = '';
  5. foreach (token_get_all($s) as $token) {
  6. if (is_array($token)) {
  7. if ($token[0] == T_COMMENT) {
  8. $token[1] = '';
  9. }
  10. if ($token[0] == T_WHITESPACE) {
  11. $n = str_repeat("\n", substr_count($token[1], "\n"));
  12. $token[1] = strlen($n) ? $n : ' ';
  13. }
  14. $news .= $token[1];
  15. } else {
  16. $news .= $token;
  17. }
  18. }
  19. $s = $news . ' ?>';
  20. $slen = strlen($s) - strlen('index.php') - strlen("000");
  21. $s = str_replace('\\', '\\\\', $s);
  22. $s = str_replace('"', '\\"', $s);
  23. $s = str_replace("\n", '\n', $s);
  24. // now we need to find the location of web index file
  25. $webs = substr($s, 0, strpos($s, "000"));
  26. $s = substr($s, strlen($webs) + strlen("000"));
  27. $s1 = substr($s, 0, strpos($s, 'index.php'));
  28. $s2 = substr($s, strlen($s1) + strlen('index.php'));
  29. $s2 = substr($s2, 0, strpos($s2, 'XXXX'));
  30. $s3 = substr($s, strlen($s2) + 4 + strlen($s1) + strlen('index.php'));
  31. $stub = '/*
  32. +----------------------------------------------------------------------+
  33. | phar php single-file executable PHP extension generated stub |
  34. +----------------------------------------------------------------------+
  35. | Copyright (c) 2005-' . date('Y') . ' The PHP Group |
  36. +----------------------------------------------------------------------+
  37. | This source file is subject to version 3.01 of the PHP license, |
  38. | that is bundled with this package in the file LICENSE, and is |
  39. | available through the world-wide-web at the following url: |
  40. | http://www.php.net/license/3_01.txt. |
  41. | If you did not receive a copy of the PHP license and are unable to |
  42. | obtain it through the world-wide-web, please send a note to |
  43. | license@php.net so we can mail you a copy immediately. |
  44. +----------------------------------------------------------------------+
  45. | Authors: Gregory Beaver <cellog@php.net> |
  46. +----------------------------------------------------------------------+
  47. */
  48. /* $Id$ */
  49. static inline void phar_get_stub(const char *index_php, const char *web, size_t *len, char **stub, const int name_len, const int web_len TSRMLS_DC)
  50. {
  51. ';
  52. $s1split = str_split($s1, 2046);
  53. $s3split = str_split($s3, 2046);
  54. $took = false;
  55. foreach ($s1split as $i => $chunk) {
  56. if ($took) {
  57. $s1split[$i] = substr($chunk, 1);
  58. $took = false;
  59. }
  60. if ($chunk[strlen($chunk) - 1] == '\\') {
  61. $s1split[$i] .= $s1split[$i + 1][0];
  62. $took = true;
  63. }
  64. }
  65. foreach ($s3split as $i => $chunk) {
  66. if ($took) {
  67. $s3split[$i] = substr($chunk, 1);
  68. $took = false;
  69. }
  70. if ($chunk[strlen($chunk) - 1] == '\\') {
  71. $s3split[$i] .= $s3split[$i + 1][0];
  72. $took = true;
  73. }
  74. }
  75. $stub .= "\tstatic const char newstub0[] = \"" . $webs . '";
  76. ';
  77. foreach ($s1split as $i => $chunk) {
  78. $s1count = $i + 1;
  79. $stub .= "\tstatic const char newstub1_" . $i . '[] = "' . $chunk . '";
  80. ';
  81. }
  82. $stub .= "\tstatic const char newstub2[] = \"" . $s2 . "\";
  83. ";
  84. foreach ($s3split as $i => $chunk) {
  85. $s3count = $i + 1;
  86. $stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '";
  87. ';
  88. }
  89. $stub .= "\n\tstatic const int newstub_len = " . $slen . ";
  90. \t*len = spprintf(stub, name_len + web_len + newstub_len, \"%s%s" . str_repeat('%s', $s1count) . '%s%s%d'
  91. . str_repeat('%s', $s3count) . '", newstub0, web';
  92. foreach ($s1split as $i => $unused) {
  93. $stub .= ', newstub1_' . $i;
  94. }
  95. $stub .= ', index_php, newstub2';
  96. $stub .= ", name_len + web_len + newstub_len";
  97. foreach ($s3split as $i => $unused) {
  98. $stub .= ', newstub3_' . $i;
  99. }
  100. $stub .= ");
  101. }";
  102. file_put_contents(dirname(__FILE__) . '/stub.h', $stub."\n");
  103. ?>