Back to index

php5  5.3.10
makestub.php
Go to the documentation of this file.
00001 <?php
00002 $s = str_replace("\r", '', file_get_contents(dirname(__FILE__) . '/shortarc.php'));
00003 
00004 $s .= "\nExtract_Phar::go();\n__HALT_COMPILER();";
00005 $news = '';
00006 foreach (token_get_all($s) as $token) {
00007        if (is_array($token)) {
00008               if ($token[0] == T_COMMENT) {
00009                      $token[1] = '';
00010               }
00011               if ($token[0] == T_WHITESPACE) {
00012                      $n = str_repeat("\n", substr_count($token[1], "\n"));
00013                      $token[1] = strlen($n) ? $n : ' ';
00014               }
00015               $news .= $token[1];
00016        } else {
00017               $news .= $token;
00018        }
00019 }
00020 $s = $news . ' ?>';
00021 $slen = strlen($s) - strlen('index.php') - strlen("000");
00022 $s = str_replace('\\', '\\\\', $s);
00023 $s = str_replace('"', '\\"', $s);
00024 $s = str_replace("\n", '\n', $s);
00025 // now we need to find the location of web index file
00026 $webs = substr($s, 0, strpos($s, "000"));
00027 $s = substr($s, strlen($webs) + strlen("000"));
00028 $s1 = substr($s, 0, strpos($s, 'index.php'));
00029 $s2 = substr($s, strlen($s1) + strlen('index.php'));
00030 $s2 = substr($s2, 0, strpos($s2, 'XXXX'));
00031 $s3 = substr($s, strlen($s2) + 4 + strlen($s1) + strlen('index.php'));
00032 
00033 $stub = '/*
00034   +----------------------------------------------------------------------+
00035   | phar php single-file executable PHP extension generated stub         |
00036   +----------------------------------------------------------------------+
00037   | Copyright (c) 2005-' . date('Y') . ' The PHP Group                   |
00038   +----------------------------------------------------------------------+
00039   | This source file is subject to version 3.01 of the PHP license,      |
00040   | that is bundled with this package in the file LICENSE, and is        |
00041   | available through the world-wide-web at the following url:           |
00042   | http://www.php.net/license/3_01.txt.                                 |
00043   | If you did not receive a copy of the PHP license and are unable to   |
00044   | obtain it through the world-wide-web, please send a note to          |
00045   | license@php.net so we can mail you a copy immediately.               |
00046   +----------------------------------------------------------------------+
00047   | Authors: Gregory Beaver <cellog@php.net>                             |
00048   +----------------------------------------------------------------------+
00049 */
00050 
00051 /* $Id: makestub.php 264018 2008-08-01 13:48:45Z sfox $ */
00052 
00053 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)
00054 {
00055 ';
00056 $s1split = str_split($s1, 2046);
00057 $s3split = str_split($s3, 2046);
00058 $took = false;
00059 foreach ($s1split as $i => $chunk) {
00060        if ($took) {
00061               $s1split[$i] = substr($chunk, 1);
00062               $took = false;
00063        }
00064        if ($chunk[strlen($chunk) - 1] == '\\') {
00065               $s1split[$i] .= $s1split[$i + 1][0];
00066               $took = true;
00067        }
00068 }
00069 foreach ($s3split as $i => $chunk) {
00070        if ($took) {
00071               $s3split[$i] = substr($chunk, 1);
00072               $took = false;
00073        }
00074        if ($chunk[strlen($chunk) - 1] == '\\') {
00075               $s3split[$i] .= $s3split[$i + 1][0];
00076               $took = true;
00077        }
00078 }
00079 $stub .= "\tstatic const char newstub0[] = \"" . $webs . '";
00080 ';
00081 foreach ($s1split as $i => $chunk) {
00082        $s1count = $i + 1;
00083        $stub .= "\tstatic const char newstub1_" . $i . '[] = "' . $chunk . '";
00084 ';
00085 }
00086 $stub .= "\tstatic const char newstub2[] = \"" . $s2 . "\";
00087 ";
00088 foreach ($s3split as $i => $chunk) {
00089        $s3count = $i + 1;
00090        $stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '";
00091 ';
00092 }
00093 $stub .= "\n\tstatic const int newstub_len = " . $slen . ";
00094 
00095 \t*len = spprintf(stub, name_len + web_len + newstub_len, \"%s%s" . str_repeat('%s', $s1count) . '%s%s%d'
00096        . str_repeat('%s', $s3count) . '", newstub0, web';
00097 foreach ($s1split as $i => $unused) {
00098        $stub .= ', newstub1_' . $i;
00099 }
00100 $stub .= ', index_php, newstub2';
00101 $stub .= ", name_len + web_len + newstub_len";
00102 foreach ($s3split as $i => $unused) {
00103        $stub .= ', newstub3_' . $i;
00104 }
00105 $stub .= ");
00106 }";
00107 
00108 file_put_contents(dirname(__FILE__) . '/stub.h', $stub."\n");
00109 ?>