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