Merge branch 'PHP-7.4'

* PHP-7.4:
  Apply tidy formatting
This commit is contained in:
Nikita Popov 2020-02-03 13:41:45 +01:00
commit 169805777c
41 changed files with 6875 additions and 6875 deletions

View file

@ -1,6 +1,6 @@
<?php
if (function_exists("date_default_timezone_set")) {
date_default_timezone_set("UTC");
date_default_timezone_set("UTC");
}
function simple() {
@ -220,30 +220,30 @@ function heapsort_r($n, &$ra) {
$ir = $n;
while (1) {
if ($l > 1) {
$rra = $ra[--$l];
} else {
$rra = $ra[$ir];
$ra[$ir] = $ra[1];
if (--$ir == 1) {
$ra[1] = $rra;
return;
}
}
$i = $l;
$j = $l << 1;
while ($j <= $ir) {
if (($j < $ir) && ($ra[$j] < $ra[$j+1])) {
$j++;
}
if ($rra < $ra[$j]) {
$ra[$i] = $ra[$j];
$j += ($i = $j);
} else {
$j = $ir + 1;
}
}
$ra[$i] = $rra;
if ($l > 1) {
$rra = $ra[--$l];
} else {
$rra = $ra[$ir];
$ra[$ir] = $ra[1];
if (--$ir == 1) {
$ra[1] = $rra;
return;
}
}
$i = $l;
$j = $l << 1;
while ($j <= $ir) {
if (($j < $ir) && ($ra[$j] < $ra[$j+1])) {
$j++;
}
if ($rra < $ra[$j]) {
$ra[$i] = $ra[$j];
$j += ($i = $j);
} else {
$j = $ir + 1;
}
}
$ra[$i] = $rra;
}
}
@ -268,9 +268,9 @@ function mkmatrix ($rows, $cols) {
$count = 1;
$mx = array();
for ($i=0; $i<$rows; $i++) {
for ($j=0; $j<$cols; $j++) {
$mx[$i][$j] = $count++;
}
for ($j=0; $j<$cols; $j++) {
$mx[$i][$j] = $count++;
}
}
return($mx);
}
@ -278,13 +278,13 @@ function mkmatrix ($rows, $cols) {
function mmult ($rows, $cols, $m1, $m2) {
$m3 = array();
for ($i=0; $i<$rows; $i++) {
for ($j=0; $j<$cols; $j++) {
$x = 0;
for ($k=0; $k<$cols; $k++) {
$x += $m1[$i][$k] * $m2[$k][$j];
}
$m3[$i][$j] = $x;
}
for ($j=0; $j<$cols; $j++) {
$x = 0;
for ($k=0; $k<$cols; $k++) {
$x += $m1[$i][$k] * $m2[$k][$j];
}
$m3[$i][$j] = $x;
}
}
return($m3);
}
@ -353,7 +353,7 @@ function gethrtime()
function start_test()
{
ob_start();
ob_start();
return gethrtime();
}
@ -367,7 +367,7 @@ function end_test($start, $name)
$pad = str_repeat(" ", 24-strlen($name)-strlen($num));
echo $name.$pad.$num."\n";
ob_start();
ob_start();
return gethrtime();
}

View file

@ -22,220 +22,220 @@ function simpleicall($n) {
}
class Foo {
static $a = 0;
public $b = 0;
const TEST = 0;
static $a = 0;
public $b = 0;
const TEST = 0;
static function read_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = self::$a;
}
}
static function read_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = self::$a;
}
}
static function write_static($n) {
for ($i = 0; $i < $n; ++$i) {
self::$a = 0;
}
}
static function write_static($n) {
for ($i = 0; $i < $n; ++$i) {
self::$a = 0;
}
}
static function isset_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset(self::$a);
}
}
static function isset_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset(self::$a);
}
}
static function empty_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty(self::$a);
}
}
static function empty_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty(self::$a);
}
}
static function f() {
}
static function f() {
}
static function call_static($n) {
for ($i = 0; $i < $n; ++$i) {
self::f();
}
}
static function call_static($n) {
for ($i = 0; $i < $n; ++$i) {
self::f();
}
}
function read_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $this->b;
}
}
function read_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $this->b;
}
}
function write_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b = 0;
}
}
function write_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b = 0;
}
}
function assign_add_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b += 2;
}
}
function assign_add_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b += 2;
}
}
function pre_inc_prop($n) {
for ($i = 0; $i < $n; ++$i) {
++$this->b;
}
}
function pre_inc_prop($n) {
for ($i = 0; $i < $n; ++$i) {
++$this->b;
}
}
function pre_dec_prop($n) {
for ($i = 0; $i < $n; ++$i) {
--$this->b;
}
}
function pre_dec_prop($n) {
for ($i = 0; $i < $n; ++$i) {
--$this->b;
}
}
function post_inc_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b++;
}
}
function post_inc_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b++;
}
}
function post_dec_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b--;
}
}
function post_dec_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$this->b--;
}
}
function isset_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset($this->b);
}
}
function isset_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset($this->b);
}
}
function empty_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty($this->b);
}
}
function empty_prop($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty($this->b);
}
}
function g() {
}
function g() {
}
function call($n) {
for ($i = 0; $i < $n; ++$i) {
$this->g();
}
}
function call($n) {
for ($i = 0; $i < $n; ++$i) {
$this->g();
}
}
function read_const($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $this::TEST;
}
}
function read_const($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $this::TEST;
}
}
}
function read_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = Foo::$a;
}
for ($i = 0; $i < $n; ++$i) {
$x = Foo::$a;
}
}
function write_static($n) {
for ($i = 0; $i < $n; ++$i) {
Foo::$a = 0;
}
for ($i = 0; $i < $n; ++$i) {
Foo::$a = 0;
}
}
function isset_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = isset(Foo::$a);
}
for ($i = 0; $i < $n; ++$i) {
$x = isset(Foo::$a);
}
}
function empty_static($n) {
for ($i = 0; $i < $n; ++$i) {
$x = empty(Foo::$a);
}
for ($i = 0; $i < $n; ++$i) {
$x = empty(Foo::$a);
}
}
function call_static($n) {
for ($i = 0; $i < $n; ++$i) {
Foo::f();
}
for ($i = 0; $i < $n; ++$i) {
Foo::f();
}
}
function create_object($n) {
for ($i = 0; $i < $n; ++$i) {
$x = new Foo();
}
for ($i = 0; $i < $n; ++$i) {
$x = new Foo();
}
}
define('TEST', null);
function read_const($n) {
for ($i = 0; $i < $n; ++$i) {
$x = TEST;
}
for ($i = 0; $i < $n; ++$i) {
$x = TEST;
}
}
function read_auto_global($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $_GET;
}
for ($i = 0; $i < $n; ++$i) {
$x = $_GET;
}
}
$g_var = 0;
function read_global_var($n) {
for ($i = 0; $i < $n; ++$i) {
$x = $GLOBALS['g_var'];
}
for ($i = 0; $i < $n; ++$i) {
$x = $GLOBALS['g_var'];
}
}
function read_hash($n) {
$hash = array('test' => 0);
for ($i = 0; $i < $n; ++$i) {
$x = $hash['test'];
}
$hash = array('test' => 0);
for ($i = 0; $i < $n; ++$i) {
$x = $hash['test'];
}
}
function read_str_offset($n) {
$str = "test";
for ($i = 0; $i < $n; ++$i) {
$x = $str[1];
}
$str = "test";
for ($i = 0; $i < $n; ++$i) {
$x = $str[1];
}
}
function issetor($n) {
$val = array(0,1,2,3,4,5,6,7,8,9);
for ($i = 0; $i < $n; ++$i) {
$x = $val ?: null;
}
$val = array(0,1,2,3,4,5,6,7,8,9);
for ($i = 0; $i < $n; ++$i) {
$x = $val ?: null;
}
}
function issetor2($n) {
$f = false; $j = 0;
for ($i = 0; $i < $n; ++$i) {
$x = $f ?: $j + 1;
}
$f = false; $j = 0;
for ($i = 0; $i < $n; ++$i) {
$x = $f ?: $j + 1;
}
}
function ternary($n) {
$val = array(0,1,2,3,4,5,6,7,8,9);
$f = false;
for ($i = 0; $i < $n; ++$i) {
$x = $f ? null : $val;
}
$val = array(0,1,2,3,4,5,6,7,8,9);
$f = false;
for ($i = 0; $i < $n; ++$i) {
$x = $f ? null : $val;
}
}
function ternary2($n) {
$f = false; $j = 0;
for ($i = 0; $i < $n; ++$i) {
$x = $f ? $f : $j + 1;
}
$f = false; $j = 0;
for ($i = 0; $i < $n; ++$i) {
$x = $f ? $f : $j + 1;
}
}
/*****/
function empty_loop($n) {
for ($i = 0; $i < $n; ++$i) {
}
for ($i = 0; $i < $n; ++$i) {
}
}
function gethrtime()

File diff suppressed because it is too large Load diff

View file

@ -21,8 +21,8 @@
/* {{{ error
*/
function error($message) {
printf('Error: %s%s', $message, PHP_EOL);
exit;
printf('Error: %s%s', $message, PHP_EOL);
exit;
}
/* }}} */
@ -114,152 +114,152 @@ OPTIONS
--help This help
HELP;
exit;
exit;
}
/* }}} */
/* {{{ task
*/
function task($label, $callback) {
printf('%s... ', $label);
printf('%s... ', $label);
$callback();
$callback();
printf('done%s', PHP_EOL);
printf('done%s', PHP_EOL);
}
/* }}} */
/* {{{ print_success
*/
function print_success() {
global $options;
global $options;
if (PHP_OS_FAMILY != 'Windows') {
$file_prefix = './';
$make_prefix = '';
} else {
$file_prefix = '';
$make_prefix = 'n';
}
if (PHP_OS_FAMILY != 'Windows') {
$file_prefix = './';
$make_prefix = '';
} else {
$file_prefix = '';
$make_prefix = 'n';
}
printf('%1$sSuccess. The extension is now ready to be compiled. To do so, use the%s', PHP_EOL);
printf('following steps:%1$s%1$s', PHP_EOL);
printf('cd /path/to/php-src/ext/%s%s', $options['ext'], PHP_EOL);
printf('phpize%s', PHP_EOL);
printf('%sconfigure%s', $file_prefix, PHP_EOL);
printf('%smake%2$s%2$s', $make_prefix, PHP_EOL);
printf('Don\'t forget to run tests once the compilation is done:%s', PHP_EOL);
printf('%smake test%2$s%2$s', $make_prefix, PHP_EOL);
printf('Thank you for using PHP!%s', PHP_EOL);
printf('%1$sSuccess. The extension is now ready to be compiled. To do so, use the%s', PHP_EOL);
printf('following steps:%1$s%1$s', PHP_EOL);
printf('cd /path/to/php-src/ext/%s%s', $options['ext'], PHP_EOL);
printf('phpize%s', PHP_EOL);
printf('%sconfigure%s', $file_prefix, PHP_EOL);
printf('%smake%2$s%2$s', $make_prefix, PHP_EOL);
printf('Don\'t forget to run tests once the compilation is done:%s', PHP_EOL);
printf('%smake test%2$s%2$s', $make_prefix, PHP_EOL);
printf('Thank you for using PHP!%s', PHP_EOL);
}
/* }}} */
/* {{{ process_args
*/
function process_args($argv, $argc) {
$options = [
'unix' => true,
'windows' => true,
'ext' => '',
'dir' => __DIR__ . DIRECTORY_SEPARATOR,
'skel' => __DIR__ . DIRECTORY_SEPARATOR . 'skeleton' . DIRECTORY_SEPARATOR,
'author' => false,
'experimental' => false,
'std' => false
];
$options = [
'unix' => true,
'windows' => true,
'ext' => '',
'dir' => __DIR__ . DIRECTORY_SEPARATOR,
'skel' => __DIR__ . DIRECTORY_SEPARATOR . 'skeleton' . DIRECTORY_SEPARATOR,
'author' => false,
'experimental' => false,
'std' => false
];
for($i = 1; $i < $argc; ++$i)
{
$val = $argv[$i];
for($i = 1; $i < $argc; ++$i)
{
$val = $argv[$i];
if($val[0] != '-' || $val[1] != '-')
{
continue;
}
if($val[0] != '-' || $val[1] != '-')
{
continue;
}
switch($opt = strtolower(substr($val, 2)))
{
case 'help': {
print_help();
}
case 'onlyunix': {
$options['windows'] = false;
}
break;
case 'onlywindows': {
$options['unix'] = false;
}
break;
case 'experimental': {
$options['experimental'] = true;
}
break;
case 'std': {
$options['std'] = true;
}
break;
case 'ext':
case 'dir':
case 'author': {
if (!isset($argv[$i + 1]) || ($argv[$i + 1][0] == '-' && $argv[$i + 1][1] == '-')) {
error('Argument "' . $val . '" expects a value, none passed');
} else if ($opt == 'dir' && empty($argv[$i + 1])) {
continue 2;
}
switch($opt = strtolower(substr($val, 2)))
{
case 'help': {
print_help();
}
case 'onlyunix': {
$options['windows'] = false;
}
break;
case 'onlywindows': {
$options['unix'] = false;
}
break;
case 'experimental': {
$options['experimental'] = true;
}
break;
case 'std': {
$options['std'] = true;
}
break;
case 'ext':
case 'dir':
case 'author': {
if (!isset($argv[$i + 1]) || ($argv[$i + 1][0] == '-' && $argv[$i + 1][1] == '-')) {
error('Argument "' . $val . '" expects a value, none passed');
} else if ($opt == 'dir' && empty($argv[$i + 1])) {
continue 2;
}
$options[$opt] = ($opt == 'dir' ? realpath($argv[$i + 1]) . DIRECTORY_SEPARATOR : $argv[$i + 1]);
}
break;
default: {
error('Unsupported argument "' . $val . '" passed');
}
}
}
$options[$opt] = ($opt == 'dir' ? realpath($argv[$i + 1]) . DIRECTORY_SEPARATOR : $argv[$i + 1]);
}
break;
default: {
error('Unsupported argument "' . $val . '" passed');
}
}
}
if (empty($options['ext'])) {
error('No extension name passed, use "--ext <name>"');
} else if (!$options['unix'] && !$options['windows']) {
error('Cannot pass both --onlyunix and --onlywindows');
} else if (!is_dir($options['skel'])) {
error('The skeleton directory was not found');
}
if (empty($options['ext'])) {
error('No extension name passed, use "--ext <name>"');
} else if (!$options['unix'] && !$options['windows']) {
error('Cannot pass both --onlyunix and --onlywindows');
} else if (!is_dir($options['skel'])) {
error('The skeleton directory was not found');
}
// Validate extension name
if (!preg_match('/^[a-z][a-z0-9_]+$/i', $options['ext'])) {
error('Invalid extension name. Valid names start with a letter,'
.' followed by any number of letters, numbers, or underscores.'
.' Using only lower case letters is preferred.');
}
// Validate extension name
if (!preg_match('/^[a-z][a-z0-9_]+$/i', $options['ext'])) {
error('Invalid extension name. Valid names start with a letter,'
.' followed by any number of letters, numbers, or underscores.'
.' Using only lower case letters is preferred.');
}
$options['ext'] = str_replace(['\\', '/'], '', strtolower($options['ext']));
$options['ext'] = str_replace(['\\', '/'], '', strtolower($options['ext']));
return $options;
return $options;
}
/* }}} */
/* {{{ process_source_tags
*/
function process_source_tags($file, $short_name) {
global $options;
global $options;
$source = file_get_contents($file);
$source = file_get_contents($file);
if ($source === false) {
error('Unable to open file for reading: ' . $short_name);
}
if ($source === false) {
error('Unable to open file for reading: ' . $short_name);
}
$source = str_replace('%EXTNAME%', $options['ext'], $source);
$source = str_replace('%EXTNAMECAPS%', strtoupper($options['ext']), $source);
$source = str_replace('%EXTNAME%', $options['ext'], $source);
$source = str_replace('%EXTNAMECAPS%', strtoupper($options['ext']), $source);
if (strpos($short_name, '.c') !== false || strpos($short_name, '.h') !== false) {
static $header;
if (strpos($short_name, '.c') !== false || strpos($short_name, '.h') !== false) {
static $header;
if (!$header) {
if ($options['std']) {
$author_len = strlen($options['author']);
$credits = $options['author'] . ($author_len && $author_len <= 60 ? str_repeat(' ', 60 - $author_len) : '');
if (!$header) {
if ($options['std']) {
$author_len = strlen($options['author']);
$credits = $options['author'] . ($author_len && $author_len <= 60 ? str_repeat(' ', 60 - $author_len) : '');
$header = <<<"HEADER"
$header = <<<"HEADER"
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
@ -276,141 +276,141 @@ function process_source_tags($file, $short_name) {
+----------------------------------------------------------------------+
*/
HEADER;
} else {
if ($options['author']) {
$header = sprintf('/* %s extension for PHP (c) %d %s */', $options['ext'], date('Y'), $options['author']);
} else {
$header = sprintf('/* %s extension for PHP */', $options['ext']);
}
}
}
} else {
if ($options['author']) {
$header = sprintf('/* %s extension for PHP (c) %d %s */', $options['ext'], date('Y'), $options['author']);
} else {
$header = sprintf('/* %s extension for PHP */', $options['ext']);
}
}
}
$source = str_replace('%HEADER%', $header, $source);
}
$source = str_replace('%HEADER%', $header, $source);
}
if (!file_put_contents($file, $source)) {
error('Unable to save contents to file: ' . $short_name);
}
if (!file_put_contents($file, $source)) {
error('Unable to save contents to file: ' . $short_name);
}
}
/* }}} */
/* {{{ copy_config_scripts
*/
function copy_config_scripts() {
global $options;
global $options;
$files = [];
$files = [];
if ($options['unix']) {
$files[] = 'config.m4';
}
if ($options['unix']) {
$files[] = 'config.m4';
}
if ($options['windows']) {
$files[] = 'config.w32';
}
if ($options['windows']) {
$files[] = 'config.w32';
}
$files[] = '.gitignore';
$files[] = '.gitignore';
foreach($files as $config_script) {
$new_config_script = $options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $config_script;
foreach($files as $config_script) {
$new_config_script = $options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $config_script;
if (!copy($options['skel'] . $config_script . '.in', $new_config_script)) {
error('Unable to copy config script: ' . $config_script);
}
if (!copy($options['skel'] . $config_script . '.in', $new_config_script)) {
error('Unable to copy config script: ' . $config_script);
}
process_source_tags($new_config_script, $config_script);
}
process_source_tags($new_config_script, $config_script);
}
}
/* }}} */
/* {{{ copy_sources
*/
function copy_sources() {
global $options;
global $options;
$files = [
'skeleton.c' => $options['ext'] . '.c',
'skeleton.stub.php' => $options['ext'] . '.stub.php',
'php_skeleton.h' => 'php_' . $options['ext'] . '.h'
];
$files = [
'skeleton.c' => $options['ext'] . '.c',
'skeleton.stub.php' => $options['ext'] . '.stub.php',
'php_skeleton.h' => 'php_' . $options['ext'] . '.h'
];
foreach ($files as $src_file => $dst_file) {
if (!copy($options['skel'] . $src_file, $options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $dst_file)) {
error('Unable to copy source file: ' . $src_file);
}
foreach ($files as $src_file => $dst_file) {
if (!copy($options['skel'] . $src_file, $options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $dst_file)) {
error('Unable to copy source file: ' . $src_file);
}
process_source_tags($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $dst_file, $dst_file);
}
process_source_tags($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $dst_file, $dst_file);
}
}
/* }}} */
/* {{{ copy_tests
*/
function copy_tests() {
global $options;
global $options;
$test_files = glob($options['skel'] . 'tests/*', GLOB_MARK);
$test_files = glob($options['skel'] . 'tests/*', GLOB_MARK);
if (!$test_files) {
return;
}
if (!$test_files) {
return;
}
foreach ($test_files as $test) {
if (is_dir($test)) {
continue;
}
foreach ($test_files as $test) {
if (is_dir($test)) {
continue;
}
$new_test = str_replace([$options['skel'], '/'], ['', DIRECTORY_SEPARATOR], $test);
$new_test = str_replace([$options['skel'], '/'], ['', DIRECTORY_SEPARATOR], $test);
if (!copy($test, $options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $new_test)) {
error('Unable to copy file: ' . $new_test);
}
if (!copy($test, $options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $new_test)) {
error('Unable to copy file: ' . $new_test);
}
process_source_tags($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $new_test, $new_test);
}
process_source_tags($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . $new_test, $new_test);
}
}
/* }}} */
if (PHP_SAPI != 'cli') {
error('This script is only suited for CLI');
error('This script is only suited for CLI');
}
if ($argc < 1) {
print_help();
exit;
print_help();
exit;
}
$options = process_args($argv, $argc);
if (!$options['dir'] || !is_dir($options['dir'])) {
error('The selected output directory does not exist');
error('The selected output directory does not exist');
} else if (is_dir($options['dir'] . $options['ext'])) {
error('There is already a folder named "' . $options['ext'] . '" in the output directory');
error('There is already a folder named "' . $options['ext'] . '" in the output directory');
} else if (!mkdir($options['dir'] . $options['ext'])) {
error('Unable to create extension directory in the output directory');
error('Unable to create extension directory in the output directory');
} else if (!mkdir($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . 'tests')) {
error('Unable to create the tests directory');
error('Unable to create the tests directory');
}
if ($options['experimental']) {
print('Creating EXPERIMENTAL... ');
print('Creating EXPERIMENTAL... ');
if (file_put_contents($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . 'EXPERIMENTAL', '') === false) {
error('Unable to create the EXPERIMENTAL file');
}
if (file_put_contents($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . 'EXPERIMENTAL', '') === false) {
error('Unable to create the EXPERIMENTAL file');
}
printf('done%s', PHP_EOL);
printf('done%s', PHP_EOL);
}
if (!empty($options['author'])) {
print('Creating CREDITS... ');
print('Creating CREDITS... ');
if (!file_put_contents($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . 'CREDITS', $options['ext'] . PHP_EOL . $options['author'])) {
error('Unable to create the CREDITS file');
}
if (!file_put_contents($options['dir'] . $options['ext'] . DIRECTORY_SEPARATOR . 'CREDITS', $options['ext'] . PHP_EOL . $options['author'])) {
error('Unable to create the CREDITS file');
}
printf('done%s', PHP_EOL);
printf('done%s', PHP_EOL);
}
date_default_timezone_set('UTC');

View file

@ -2,17 +2,17 @@
/* This is a generated file, do not modify */
/* Usage: php create_data_file.php /path/to/magic.mgc > data_file.c */
<?php
$dta = file_get_contents( $argv[1] );
$dta_l = strlen($dta);
$j = 0;
$dta = file_get_contents( $argv[1] );
$dta_l = strlen($dta);
$j = 0;
echo "const unsigned char php_magic_database[$dta_l] = {\n";
for ($i = 0; $i < $dta_l; $i++) {
printf("0x%02X, ", ord($dta[$i]));
if ($j % 16 == 15) {
echo "\n";
}
$j++;
}
echo "};\n";
echo "const unsigned char php_magic_database[$dta_l] = {\n";
for ($i = 0; $i < $dta_l; $i++) {
printf("0x%02X, ", ord($dta[$i]));
if ($j % 16 == 15) {
echo "\n";
}
$j++;
}
echo "};\n";
?>

View file

@ -5,68 +5,68 @@
This gives rather interesting results :)
Measures on a Notebook P4M-1.7 256MB Windows 2000:
sha1 0.556691
tiger160,3 0.774469
tiger192,3 0.776314
tiger128,3 0.777004
ripemd128 0.896674
sha256 1.011164
md5 1.016032
tiger160,4 1.056617
tiger128,4 1.063101
tiger192,4 1.069258
haval160,3 1.125099
haval128,3 1.125679
haval224,3 1.128017
haval192,3 1.130026
haval256,3 1.134846
ripemd160 1.150693
haval128,4 1.686261
haval192,4 1.687274
haval160,4 1.693091
haval256,4 1.699323
haval224,4 1.743094
haval160,5 2.003452
haval192,5 2.008341
haval256,5 2.009048
haval128,5 2.009555
haval224,5 2.015539
sha384 3.370734
sha512 3.381121
whirlpool 6.912327
snefru 9.268168
sha1 0.556691
tiger160,3 0.774469
tiger192,3 0.776314
tiger128,3 0.777004
ripemd128 0.896674
sha256 1.011164
md5 1.016032
tiger160,4 1.056617
tiger128,4 1.063101
tiger192,4 1.069258
haval160,3 1.125099
haval128,3 1.125679
haval224,3 1.128017
haval192,3 1.130026
haval256,3 1.134846
ripemd160 1.150693
haval128,4 1.686261
haval192,4 1.687274
haval160,4 1.693091
haval256,4 1.699323
haval224,4 1.743094
haval160,5 2.003452
haval192,5 2.008341
haval256,5 2.009048
haval128,5 2.009555
haval224,5 2.015539
sha384 3.370734
sha512 3.381121
whirlpool 6.912327
snefru 9.268168
Measures on a Desktop P4-2.4 512MB Debian (Linux-2.4):
md5 0.147739
haval128,3 0.317006
haval192,3 0.317524
haval256,3 0.317526
haval160,3 0.323035
haval224,3 0.333318
ripemd128 0.353447
sha1 0.376200
ripemd160 0.413758
sha256 0.435957
haval160,4 0.452357
haval224,4 0.454531
haval128,4 0.458026
haval256,4 0.459051
haval192,4 0.468094
haval128,5 0.524262
haval160,5 0.529573
haval224,5 0.533655
haval256,5 0.534446
haval192,5 0.543726
tiger128,3 0.577975
tiger160,3 0.579951
tiger192,3 0.597111
tiger192,4 0.781408
tiger160,4 0.801243
tiger128,4 0.812239
sha512 1.298627
sha384 1.313607
whirlpool 1.556159
snefru 5.703742
md5 0.147739
haval128,3 0.317006
haval192,3 0.317524
haval256,3 0.317526
haval160,3 0.323035
haval224,3 0.333318
ripemd128 0.353447
sha1 0.376200
ripemd160 0.413758
sha256 0.435957
haval160,4 0.452357
haval224,4 0.454531
haval128,4 0.458026
haval256,4 0.459051
haval192,4 0.468094
haval128,5 0.524262
haval160,5 0.529573
haval224,5 0.533655
haval256,5 0.534446
haval192,5 0.543726
tiger128,3 0.577975
tiger160,3 0.579951
tiger192,3 0.597111
tiger192,4 0.781408
tiger160,4 0.801243
tiger128,4 0.812239
sha512 1.298627
sha384 1.313607
whirlpool 1.556159
snefru 5.703742
*/
@ -76,17 +76,17 @@ $data = file_get_contents(__FILE__);
$time = array();
for ($j = 0; $j < 10; $j++) {
foreach (hash_algos() as $algo) {
$start = microtime(true);
for ($i = 0; $i < 1000; $i++) {
hash($algo, $data);
}
$time[$algo] += microtime(true)-$start;
}
foreach (hash_algos() as $algo) {
$start = microtime(true);
for ($i = 0; $i < 1000; $i++) {
hash($algo, $data);
}
$time[$algo] += microtime(true)-$start;
}
}
asort($time, SORT_NUMERIC);
foreach ($time as $a => $t) {
printf("%-12s %02.6f\n", $a, $t);
printf("%-12s %02.6f\n", $a, $t);
}
?>

View file

@ -1,28 +1,28 @@
#!/usr/bin/env php
<?php
$codes = array();
$maxlen = 0;
$codes = array();
$maxlen = 0;
while (!feof(STDIN)) {
$line = fgets(STDIN);
while (!feof(STDIN)) {
$line = fgets(STDIN);
if (ereg('^\{[[:space:]]+(ER_.*)[[:space:]]+,[[:space:]]*"(.*)",[[:space:]]*"(.*)"', $line, $matches)) {
$codes[$matches[1]] = $matches[2];
$maxlen = max($maxlen, strlen($matches[1]));
}
}
if (ereg('^\{[[:space:]]+(ER_.*)[[:space:]]+,[[:space:]]*"(.*)",[[:space:]]*"(.*)"', $line, $matches)) {
$codes[$matches[1]] = $matches[2];
$maxlen = max($maxlen, strlen($matches[1]));
}
}
if (empty($codes)) {
fputs(STDERR, "input doesn't look like a MySQL sql_state.h file\n");
exit(3);
}
if (empty($codes)) {
fputs(STDERR, "input doesn't look like a MySQL sql_state.h file\n");
exit(3);
}
echo "/* DO NOT EDIT THIS FILE!!! It is auto generated by get_error_codes.php */\n";
foreach ($codes as $code => $state) {
echo "#ifdef $code\n";
printf(" case %-{$maxlen}s: return \"%s\";\n", $code, $state);
echo "#endif\n";
}
echo "/* DO NOT EDIT THIS FILE!!! It is auto generated by get_error_codes.php */\n";
foreach ($codes as $code => $state) {
echo "#ifdef $code\n";
printf(" case %-{$maxlen}s: return \"%s\";\n", $code, $state);
echo "#endif\n";
}
?>

View file

@ -10,44 +10,44 @@
* Phar Command
*/
foreach(array("SPL", "Reflection", "Phar") as $ext) {
if (!extension_loaded($ext)) {
echo "$argv[0] requires PHP extension $ext.\n";
exit(1);
}
if (!extension_loaded($ext)) {
echo "$argv[0] requires PHP extension $ext.\n";
exit(1);
}
}
<?php
$classes = array(
'DirectoryTreeIterator',
'DirectoryGraphIterator',
'InvertedRegexIterator',
'CLICommand',
'PharCommand',
);
'DirectoryTreeIterator',
'DirectoryGraphIterator',
'InvertedRegexIterator',
'CLICommand',
'PharCommand',
);
foreach($classes as $name) {
echo "if (!class_exists('$name', 0))\n{\n";
$f = file(dirname(__FILE__) . '/phar/' . strtolower($name) . '.inc');
unset($f[0]);
$c = count($f);
while ($c && (strlen($f[$c]) == 0 || $f[$c] == "\n" || $f[$c] == "\r\n")) {
unset($f[$c--]);
}
if (substr($f[$c], -2) == "\r\n") {
$f[$c] = substr($f[$c], 0, -2);
}
if (substr($f[$c], -1) == "\n") {
$f[$c] = substr($f[$c], 0, -1);
}
if (substr($f[$c], -2) == '?>') {
$f[$c] = substr($f[$c], 0,-2);
}
while ($c && (strlen($f[$c]) == 0 || $f[$c] == "\n" || $f[$c] == "\r\n")) {
unset($f[$c--]);
}
echo join('', $f);
echo "\n}\n\n";
echo "if (!class_exists('$name', 0))\n{\n";
$f = file(dirname(__FILE__) . '/phar/' . strtolower($name) . '.inc');
unset($f[0]);
$c = count($f);
while ($c && (strlen($f[$c]) == 0 || $f[$c] == "\n" || $f[$c] == "\r\n")) {
unset($f[$c--]);
}
if (substr($f[$c], -2) == "\r\n") {
$f[$c] = substr($f[$c], 0, -2);
}
if (substr($f[$c], -1) == "\n") {
$f[$c] = substr($f[$c], 0, -1);
}
if (substr($f[$c], -2) == '?>') {
$f[$c] = substr($f[$c], 0,-2);
}
while ($c && (strlen($f[$c]) == 0 || $f[$c] == "\n" || $f[$c] == "\r\n")) {
unset($f[$c--]);
}
echo join('', $f);
echo "\n}\n\n";
}
echo 'new PharCommand($argc, $argv);'."\n";

View file

@ -4,18 +4,18 @@ $s = str_replace("\r", '', file_get_contents(dirname(__FILE__) . '/shortarc.php'
$s .= "\nExtract_Phar::go();\n__HALT_COMPILER();";
$news = '';
foreach (token_get_all($s) as $token) {
if (is_array($token)) {
if ($token[0] == T_COMMENT) {
$token[1] = '';
}
if ($token[0] == T_WHITESPACE) {
$n = str_repeat("\n", substr_count($token[1], "\n"));
$token[1] = strlen($n) ? $n : ' ';
}
$news .= $token[1];
} else {
$news .= $token;
}
if (is_array($token)) {
if ($token[0] == T_COMMENT) {
$token[1] = '';
}
if ($token[0] == T_WHITESPACE) {
$n = str_repeat("\n", substr_count($token[1], "\n"));
$token[1] = strlen($n) ? $n : ' ';
}
$news .= $token[1];
} else {
$news .= $token;
}
}
$s = $news . ' ?>';
$slen = strlen($s) - strlen('index.php') - strlen("000");
@ -55,50 +55,50 @@ $s1split = str_split($s1, 2046);
$s3split = str_split($s3, 2046);
$took = false;
foreach ($s1split as $i => $chunk) {
if ($took) {
$s1split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s1split[$i] .= $s1split[$i + 1][0];
$took = true;
}
if ($took) {
$s1split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s1split[$i] .= $s1split[$i + 1][0];
$took = true;
}
}
foreach ($s3split as $i => $chunk) {
if ($took) {
$s3split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s3split[$i] .= $s3split[$i + 1][0];
$took = true;
}
if ($took) {
$s3split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s3split[$i] .= $s3split[$i + 1][0];
$took = true;
}
}
$stub .= "\tstatic const char newstub0[] = \"" . $webs . '";
';
foreach ($s1split as $i => $chunk) {
$s1count = $i + 1;
$stub .= "\tstatic const char newstub1_" . $i . '[] = "' . $chunk . '";
$s1count = $i + 1;
$stub .= "\tstatic const char newstub1_" . $i . '[] = "' . $chunk . '";
';
}
$stub .= "\tstatic const char newstub2[] = \"" . $s2 . "\";
";
foreach ($s3split as $i => $chunk) {
$s3count = $i + 1;
$stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '";
$s3count = $i + 1;
$stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '";
';
}
$stub .= "\n\tstatic const int newstub_len = " . $slen . ";
\t*len = spprintf(stub, name_len + web_len + newstub_len, \"%s%s" . str_repeat('%s', $s1count) . '%s%s%d'
. str_repeat('%s', $s3count) . '", newstub0, web';
. str_repeat('%s', $s3count) . '", newstub0, web';
foreach ($s1split as $i => $unused) {
$stub .= ', newstub1_' . $i;
$stub .= ', newstub1_' . $i;
}
$stub .= ', index_php, newstub2';
$stub .= ", name_len + web_len + newstub_len";
foreach ($s3split as $i => $unused) {
$stub .= ', newstub3_' . $i;
$stub .= ', newstub3_' . $i;
}
$stub .= ");
}";

View file

@ -12,37 +12,37 @@
if (!extension_loaded('phar'))
{
if (!class_exists('PHP_Archive', 0)) {
echo "Neither Extension Phar nor class PHP_Archive are available.\n";
exit(1);
}
if (!in_array('phar', stream_get_wrappers())) {
stream_wrapper_register('phar', 'PHP_Archive');
}
if (!class_exists('Phar',0)) {
require 'phar://'.__FILE__.'/phar.inc';
}
if (!class_exists('PHP_Archive', 0)) {
echo "Neither Extension Phar nor class PHP_Archive are available.\n";
exit(1);
}
if (!in_array('phar', stream_get_wrappers())) {
stream_wrapper_register('phar', 'PHP_Archive');
}
if (!class_exists('Phar',0)) {
require 'phar://'.__FILE__.'/phar.inc';
}
}
foreach(array("SPL", "Reflection") as $ext)
{
if (!extension_loaded($ext)) {
echo "$argv[0] requires PHP extension $ext.\n";
exit(1);
}
if (!extension_loaded($ext)) {
echo "$argv[0] requires PHP extension $ext.\n";
exit(1);
}
}
function command_include($file)
{
$file = 'phar://' . __FILE__ . '/' . $file;
if (file_exists($file)) {
include($file);
}
$file = 'phar://' . __FILE__ . '/' . $file;
if (file_exists($file)) {
include($file);
}
}
function command_autoload($classname)
{
command_include(strtolower($classname) . '.inc');
command_include(strtolower($classname) . '.inc');
}
Phar::mapPhar();

View file

@ -78,43 +78,43 @@ function snmp_read_mib(string $filename): bool {}
class SNMP
{
function __construct(int $version, string $host, string $community, int $timeout = UNKNOWN, int $retries = UNKNOWN) {}
function __construct(int $version, string $host, string $community, int $timeout = UNKNOWN, int $retries = UNKNOWN) {}
/** @return bool */
function close() {}
/** @return bool */
function close() {}
/** @return bool */
function setSecurity(string $sec_level, string $auth_protocol = '', string $auth_passphrase = '', string $priv_protocol = '', string $priv_passphrase = '', string $contextName = '', string $contextEngineID = '') {}
/** @return bool */
function setSecurity(string $sec_level, string $auth_protocol = '', string $auth_passphrase = '', string $priv_protocol = '', string $priv_passphrase = '', string $contextName = '', string $contextEngineID = '') {}
/**
* @param array|string $object_id
* @return array|bool
*/
function get($object_id, bool $use_orignames = false) {}
/**
* @param array|string $object_id
* @return array|bool
*/
function get($object_id, bool $use_orignames = false) {}
/**
* @param array|string $object_id
* @return array|bool
*/
function getnext($object_id) {}
/**
* @param array|string $object_id
* @return array|bool
*/
function getnext($object_id) {}
/**
* @param array|string $object_id
* @return array|bool
*/
function walk($object_id, bool $suffix_keys = false, int $max_repetitions = UNKNOWN, int $non_repeaters = UNKNOWN) {}
/**
* @param array|string $object_id
* @return array|bool
*/
function walk($object_id, bool $suffix_keys = false, int $max_repetitions = UNKNOWN, int $non_repeaters = UNKNOWN) {}
/**
* @param array|string $object_id
* @param array|string $type
* @param array|string $value
* @return array|bool
*/
function set($object_id, $type, $value) {}
/**
* @param array|string $object_id
* @param array|string $type
* @param array|string $value
* @return array|bool
*/
function set($object_id, $type, $value) {}
/** @return int */
function getErrno() {}
/** @return int */
function getErrno() {}
/** @return string */
function getError() {}
/** @return string */
function getError() {}
}

View file

@ -5,8 +5,8 @@ $z->open('a.zip', ZIPARCHIVE::CREATE);
/* or 'remove_all_path' => 0*/
$options = array(
'remove_path' => '/home/francis/myimages',
'add_path' => 'images/',
'remove_path' => '/home/francis/myimages',
'add_path' => 'images/',
);
$found = $z->addGlob("/home/pierre/cvs/gd/libgd/tests/*.png", 0, $options);
var_dump($found);

View file

@ -9,9 +9,9 @@ $zip = new ZipArchive();
$filename = "./test112.zip";
if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
exit("cannot open <$filename>\n");
exit("cannot open <$filename>\n");
} else {
echo "file <$filename> OK\n";
echo "file <$filename> OK\n";
}
$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");

View file

@ -15,7 +15,7 @@ echo "filename: " . $za->filename . "\n";
echo "comment: " . $za->comment . "\n";
for ($i=0; $i<$za->numFiles;$i++) {
echo "index: $i\n";
print_r($za->statIndex($i));
echo "index: $i\n";
print_r($za->statIndex($i));
}
echo "numFile:" . $za->numFiles . "\n";

View file

@ -40,9 +40,9 @@ $zip->close();
echo "== Stream with context\n";
$ctx = stream_context_create(array(
'zip' => array(
'password' => $pass
)
'zip' => array(
'password' => $pass
)
));
$text = file_get_contents("zip://$name#$file", false, $ctx);
printf("Size = %d\n", strlen($text));

View file

@ -19,9 +19,9 @@ echo $zip->filename . "\n";
var_dump($zip);
$files = array('test', 'testdir/test2');
if (!$zip->extractTo("./testext/path/to", $files)) {
echo "error!\n";
echo $zip->status . "\n";
echo $zip->statusSys . "\n";
echo "error!\n";
echo $zip->status . "\n";
echo $zip->statusSys . "\n";
}

View file

@ -15,9 +15,9 @@ echo $zip->filename . "\n";
var_dump($zip);
$files = array('test', 'testdir/test2');
if (!$zip->extractTo("./testext/path/to")) {
echo "error!\n";
echo $zip->status . "\n";
echo $zip->statusSys . "\n";
echo "error!\n";
echo $zip->status . "\n";
echo $zip->statusSys . "\n";
}

View file

@ -6,11 +6,11 @@ if (!extension_loaded('zip')) {
$fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r');
if (!$fp) {
exit("cannot open\n");
exit("cannot open\n");
}
while (!feof($fp)) {
$contents .= fread($fp, 2);
echo "$contents\n";
$contents .= fread($fp, 2);
echo "$contents\n";
}
fclose($fp);
@ -25,7 +25,7 @@ $fp = $z->getStream('test');
var_dump($fp);
if(!$fp) exit("\n");
while (!feof($fp)) {
$contents .= fread($fp, 2);
$contents .= fread($fp, 2);
}
fclose($fp);

View file

@ -7,9 +7,9 @@ $z->open('t.zip');
print_r($z);
for ($i=0; $i<$z->numFiles; $i++) {
echo "index: $i\n";
print_r($z->getCommentIndex($i));
echo "\n\n";
echo "index: $i\n";
print_r($z->getCommentIndex($i));
echo "\n\n";
}
echo "foobar/ " . $z->getCommentName('foobar/') . "\n";
@ -22,9 +22,9 @@ $z->setCommentName('foobar/', 'new comment foobar/');
$z->setArchiveComment( 'new archive comment');
for ($i=0; $i<$z->numFiles; $i++) {
echo "index: $i\n";
print_r($z->getCommentIndex($i));
echo "\n\n";
echo "index: $i\n";
print_r($z->getCommentIndex($i));
echo "\n\n";
}
echo $z->getCommentName('foobar/') . "\n";

View file

@ -5,16 +5,16 @@ $reader = new XMLReader();
$reader->open('zip://' . dirname(__FILE__) . '/test.odt#meta.xml');
$odt_meta = array();
while ($reader->read()) {
if ($reader->nodeType == XMLREADER::ELEMENT) {
$elm = $reader->name;
} else {
if ($reader->nodeType == XMLREADER::END_ELEMENT && $reader->name == 'office:meta') {
break;
}
if (!trim($reader->value)) {
continue;
}
$odt_meta[$elm] = $reader->value;
}
if ($reader->nodeType == XMLREADER::ELEMENT) {
$elm = $reader->name;
} else {
if ($reader->nodeType == XMLREADER::END_ELEMENT && $reader->name == 'office:meta') {
break;
}
if (!trim($reader->value)) {
continue;
}
$odt_meta[$elm] = $reader->value;
}
}
print_r($odt_meta);

View file

@ -4,14 +4,14 @@ $zip = zip_open('examples/test1.zip');
var_dump($zip);
if ($zip) {
$i = 0;
while ($zip_entry = zip_read($zip)) {
var_dump($zip_entry);
$txt = zip_entry_read($zip_entry, 10);
$i = 0;
while ($zip_entry = zip_read($zip)) {
var_dump($zip_entry);
$txt = zip_entry_read($zip_entry, 10);
echo $i . ": " . $txt . "size: " . zip_entry_filesize($zip_entry) .
"comp_method: " . zip_entry_compressionmethod($zip_entry) .
"\n";
$i++;
}
var_dump($zip_entry);
"comp_method: " . zip_entry_compressionmethod($zip_entry) .
"\n";
$i++;
}
var_dump($zip_entry);
}

View file

@ -8,7 +8,7 @@ $zip = new ZipArchive();
$filename = "a.zip";
if (!$zip->open($filename, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) {
exit("cannot open <$filename>\n");
exit("cannot open <$filename>\n");
}
$zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");

File diff suppressed because it is too large Load diff

View file

@ -8,36 +8,36 @@ $source = count($_SERVER['argv']) > 1 ? $_SERVER['argv'][1] : 'https://raw.githu
// See if we can actually load it.
$types = @file($source);
if ($types === false) {
fprintf(STDERR, "Error: unable to read $source\n");
exit(1);
fprintf(STDERR, "Error: unable to read $source\n");
exit(1);
}
// Remove comments and flip into an extensions array.
$extensions = [];
array_walk($types, function ($line) use (&$extensions) {
$line = trim($line);
if ($line && $line[0] != '#') {
$fields = preg_split('/\s+/', $line);
if (count($fields) > 1) {
$mime = array_shift($fields);
foreach ($fields as $extension) {
$extensions[$extension] = $mime;
}
}
}
$line = trim($line);
if ($line && $line[0] != '#') {
$fields = preg_split('/\s+/', $line);
if (count($fields) > 1) {
$mime = array_shift($fields);
foreach ($fields as $extension) {
$extensions[$extension] = $mime;
}
}
}
});
$additional_mime_maps = [
"map" => "application/json", // from commit: a0d62f08ae8cbebc88e5c92e08fca8d0cdc7309d
"jsm" => "application/javascript",
"map" => "application/json", // from commit: a0d62f08ae8cbebc88e5c92e08fca8d0cdc7309d
"jsm" => "application/javascript",
];
foreach($additional_mime_maps as $ext => $mime) {
if (!isset($extensions[$ext])) {
$extensions[$ext] = $mime;
} else {
printf(STDERR, "Ignored exist mime type: $ext => $mime\n");
}
if (!isset($extensions[$ext])) {
$extensions[$ext] = $mime;
} else {
printf(STDERR, "Ignored exist mime type: $ext => $mime\n");
}
}
?>
@ -64,15 +64,15 @@ foreach($additional_mime_maps as $ext => $mime) {
#define PHP_CLI_SERVER_MIME_TYPE_MAP_H
typedef struct php_cli_server_ext_mime_type_pair {
const char *ext;
const char *mime_type;
const char *ext;
const char *mime_type;
} php_cli_server_ext_mime_type_pair;
static const php_cli_server_ext_mime_type_pair mime_type_map[] = {
<?php foreach ($extensions as $extension => $mime): ?>
{ "<?= addcslashes($extension, "\0..\37!@\@\177..\377") ?>", "<?= addcslashes($mime, "\0..\37!@\@\177..\377") ?>" },
{ "<?= addcslashes($extension, "\0..\37!@\@\177..\377") ?>", "<?= addcslashes($mime, "\0..\37!@\@\177..\377") ?>" },
<?php endforeach ?>
{ NULL, NULL }
{ NULL, NULL }
};
#endif /* PHP_CLI_SERVER_MIME_TYPE_MAP_H */

View file

@ -30,37 +30,37 @@ $file = "";
$cmdargv = "";
if (isset($argc) && $argc > 1) {
$post_ddash = false;
for ($i = 1; $i < $argc; $i++) {
if ($argv[$i][0] == "-" && !$post_ddash) {
switch (substr($argv[$i], 1)) {
case "p":
$phpdbg = $argv[++$i];
break;
case "n":
$pass_options .= " -n";
break;
case "d":
$pass_options .= " -d ".escapeshellarg($argv[++$i]);
$ini[] = $argv[$i];
break;
case "-":
$post_ddash = true;
break;
}
} else {
$real_argv[] = $argv[$i];
}
}
if (isset($real_argv[0])) {
$file = realpath($real_argv[0]);
$cmdargv = implode(" ", array_map("escapeshellarg", array_slice($real_argv, 1)));
}
$post_ddash = false;
for ($i = 1; $i < $argc; $i++) {
if ($argv[$i][0] == "-" && !$post_ddash) {
switch (substr($argv[$i], 1)) {
case "p":
$phpdbg = $argv[++$i];
break;
case "n":
$pass_options .= " -n";
break;
case "d":
$pass_options .= " -d ".escapeshellarg($argv[++$i]);
$ini[] = $argv[$i];
break;
case "-":
$post_ddash = true;
break;
}
} else {
$real_argv[] = $argv[$i];
}
}
if (isset($real_argv[0])) {
$file = realpath($real_argv[0]);
$cmdargv = implode(" ", array_map("escapeshellarg", array_slice($real_argv, 1)));
}
}
$proc = proc_open("$phpdbg $pass_options $file -- $cmdargv", [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes);
if (!$proc) {
die("Couldn't start phpdbg\n");
die("Couldn't start phpdbg\n");
}
$input = $output = "";
@ -68,47 +68,47 @@ $input = $output = "";
stream_set_blocking(STDIN, false);
do {
$r = [$pipes[1], STDIN];
$w = $e = null;
$n = @stream_select($r, $w, $e, null);
$r = [$pipes[1], STDIN];
$w = $e = null;
$n = @stream_select($r, $w, $e, null);
if ($n > 0) {
if ("" != $in = fread(STDIN, 1024)) {
$input .= $in;
fwrite($pipes[0], $in);
continue;
}
if ($n > 0) {
if ("" != $in = fread(STDIN, 1024)) {
$input .= $in;
fwrite($pipes[0], $in);
continue;
}
if (feof(STDIN)) {
die("stdin closed?!\n");
}
if (feof(STDIN)) {
die("stdin closed?!\n");
}
if (feof($pipes[1])) {
$n = false;
} else {
$output .= $c = fgetc($pipes[1]);
echo $c;
}
}
if (feof($pipes[1])) {
$n = false;
} else {
$output .= $c = fgetc($pipes[1]);
echo $c;
}
}
} while ($n !== false);
stream_set_blocking(STDIN, true);
print "\n";
if (!isset($name)) {
print "Specify the test description: ";
$desc = trim(fgets(STDIN));
print "Specify the test description: ";
$desc = trim(fgets(STDIN));
}
while (!isset($testfile)) {
print "Specify the test file name (leave empty to write to stderr): ";
$testfile = trim(fgets(STDIN));
if ($testfile != "" && file_exists($testfile)) {
print "That file already exists. Type y or yes to overwrite: ";
$y = trim(fgets(STDIN));
if ($y !== "y" && $y !== "yes") {
unset($testfile);
}
}
print "Specify the test file name (leave empty to write to stderr): ";
$testfile = trim(fgets(STDIN));
if ($testfile != "" && file_exists($testfile)) {
print "That file already exists. Type y or yes to overwrite: ";
$y = trim(fgets(STDIN));
if ($y !== "y" && $y !== "yes") {
unset($testfile);
}
}
}
$output = str_replace("string(".strlen($file).") \"$file\"", 'string(%d) "%s"', $output);
@ -125,24 +125,24 @@ $output
TEST;
if (!empty($ini)) {
$testdata .= "\n--INI--\n".implode("\n", $ini);
$testdata .= "\n--INI--\n".implode("\n", $ini);
}
if ($cmdargv != "") {
$testdata .= "\n--ARGS--\n$cmdargv";
$testdata .= "\n--ARGS--\n$cmdargv";
}
if ($file != "") {
$testdata .= "\n--FILE--\n".file_get_contents($file);
$testdata .= "\n--FILE--\n".file_get_contents($file);
}
if ($testfile == "") {
print "\n";
print "\n";
} elseif (file_put_contents($testfile, $testdata)) {
print "Test saved to $testfile\n";
print "Test saved to $testfile\n";
} else {
print "The test could not be saved to $testfile; outputting on stderr now\n";
$testfile = "";
print "The test could not be saved to $testfile; outputting on stderr now\n";
$testfile = "";
}
if ($testfile == "") {
fwrite(STDERR, $testdata);
fwrite(STDERR, $testdata);
}

View file

@ -1,35 +1,35 @@
<?php
if (isset($include)) {
include (sprintf("%s/web-bootstrap.php", dirname(__FILE__)));
include (sprintf("%s/web-bootstrap.php", dirname(__FILE__)));
}
$stdout = fopen("php://stdout", "w+");
class phpdbg {
private $sprintf = "%s: %s\n";
private $sprintf = "%s: %s\n";
public function isGreat($greeting = null) {
printf($this->sprintf, __METHOD__, $greeting);
return $this;
}
public function isGreat($greeting = null) {
printf($this->sprintf, __METHOD__, $greeting);
return $this;
}
}
function mine() {
var_dump(func_get_args());
var_dump(func_get_args());
}
function test($x, $y = 0) {
$var = $x + 1;
$var += 2;
$var <<= 3;
$var = $x + 1;
$var += 2;
$var <<= 3;
$foo = function () {
echo "bar!\n";
};
$foo = function () {
echo "bar!\n";
};
$foo();
$foo();
yield $var;
yield $var;
}
$dbg = new phpdbg();
@ -38,43 +38,43 @@ var_dump(
$dbg->isGreat("PHP Rocks!!"));
foreach (test(1,2) as $gen)
continue;
continue;
echo "it works!\n";
if (isset($dump))
var_dump($_SERVER);
var_dump($_SERVER);
function phpdbg_test_ob()
{
echo 'Start';
ob_start();
echo 'Hello';
$b = ob_get_clean();
echo 'End';
echo $b;
echo 'Start';
ob_start();
echo 'Hello';
$b = ob_get_clean();
echo 'End';
echo $b;
}
$array = [
1,
2,
[3, 4],
[5, 6],
1,
2,
[3, 4],
[5, 6],
];
$array[] = 7;
array_walk($array, function (&$item) {
if (is_array($item))
$item[0] += 2;
else
$item -= 1;
if (is_array($item))
$item[0] += 2;
else
$item -= 1;
});
class testClass {
public $a = 2;
protected $b = [1, 3];
private $c = 7;
public $a = 2;
protected $b = [1, 3];
private $c = 7;
}
$obj = new testClass;

View file

@ -29,349 +29,349 @@ ini_set('pcre.backtrack_limit', 10000000);
$API_params = array(
'a' => array('zval**'), // array
'A' => array('zval**'), // array or object
'b' => array('zend_bool*'), // boolean
'd' => array('double*'), // double
'f' => array('zend_fcall_info*', 'zend_fcall_info_cache*'), // function
'h' => array('HashTable**'), // array as an HashTable*
'H' => array('HashTable**'), // array or HASH_OF(object)
'l' => array('zend_long*'), // long
//TODO 'L' => array('zend_long*, '), // long
'o' => array('zval**'), //object
'O' => array('zval**', 'zend_class_entry*'), // object of given type
'P' => array('zend_string**'), // valid path
'r' => array('zval**'), // resource
'S' => array('zend_string**'), // string
'z' => array('zval**'), // zval*
'Z' => array('zval***') // zval**
// 's', 'p', 'C' handled separately
'a' => array('zval**'), // array
'A' => array('zval**'), // array or object
'b' => array('zend_bool*'), // boolean
'd' => array('double*'), // double
'f' => array('zend_fcall_info*', 'zend_fcall_info_cache*'), // function
'h' => array('HashTable**'), // array as an HashTable*
'H' => array('HashTable**'), // array or HASH_OF(object)
'l' => array('zend_long*'), // long
//TODO 'L' => array('zend_long*, '), // long
'o' => array('zval**'), //object
'O' => array('zval**', 'zend_class_entry*'), // object of given type
'P' => array('zend_string**'), // valid path
'r' => array('zval**'), // resource
'S' => array('zend_string**'), // string
'z' => array('zval**'), // zval*
'Z' => array('zval***') // zval**
// 's', 'p', 'C' handled separately
);
/** reports an error, according to its level */
function error($str, $level = 0)
{
global $current_file, $current_function, $line;
global $current_file, $current_function, $line;
if ($level <= REPORT_LEVEL) {
if (strpos($current_file,PHPDIR) === 0) {
$filename = substr($current_file, strlen(PHPDIR)+1);
} else {
$filename = $current_file;
}
echo $filename , " [$line] $current_function : $str\n";
}
if ($level <= REPORT_LEVEL) {
if (strpos($current_file,PHPDIR) === 0) {
$filename = substr($current_file, strlen(PHPDIR)+1);
} else {
$filename = $current_file;
}
echo $filename , " [$line] $current_function : $str\n";
}
}
/** this updates the global var $line (for error reporting) */
function update_lineno($offset)
{
global $lines_offset, $line;
global $lines_offset, $line;
$left = 0;
$right = $count = count($lines_offset)-1;
$left = 0;
$right = $count = count($lines_offset)-1;
// a nice binary search :)
do {
$mid = intval(($left + $right)/2);
$val = $lines_offset[$mid];
// a nice binary search :)
do {
$mid = intval(($left + $right)/2);
$val = $lines_offset[$mid];
if ($val < $offset) {
if (++$mid > $count || $lines_offset[$mid] > $offset) {
$line = $mid;
return;
} else {
$left = $mid;
}
} else if ($val > $offset) {
if ($lines_offset[--$mid] < $offset) {
$line = $mid+1;
return;
} else {
$right = $mid;
}
} else {
$line = $mid+1;
return;
}
} while (true);
if ($val < $offset) {
if (++$mid > $count || $lines_offset[$mid] > $offset) {
$line = $mid;
return;
} else {
$left = $mid;
}
} else if ($val > $offset) {
if ($lines_offset[--$mid] < $offset) {
$line = $mid+1;
return;
} else {
$right = $mid;
}
} else {
$line = $mid+1;
return;
}
} while (true);
}
/** parses the sources and fetches its vars name, type and if they are initialized or not */
function get_vars($txt)
{
$ret = array();
preg_match_all('/((?:(?:unsigned|struct)\s+)?\w+)(?:\s*(\*+)\s+|\s+(\**))(\w+(?:\[\s*\w*\s*\])?)\s*(?:(=)[^,;]+)?((?:\s*,\s*\**\s*\w+(?:\[\s*\w*\s*\])?\s*(?:=[^,;]+)?)*)\s*;/S', $txt, $m, PREG_SET_ORDER);
$ret = array();
preg_match_all('/((?:(?:unsigned|struct)\s+)?\w+)(?:\s*(\*+)\s+|\s+(\**))(\w+(?:\[\s*\w*\s*\])?)\s*(?:(=)[^,;]+)?((?:\s*,\s*\**\s*\w+(?:\[\s*\w*\s*\])?\s*(?:=[^,;]+)?)*)\s*;/S', $txt, $m, PREG_SET_ORDER);
foreach ($m as $x) {
// the first parameter is special
if (!in_array($x[1], array('else', 'endif', 'return'))) // hack to skip reserved words
$ret[$x[4]] = array($x[1] . $x[2] . $x[3], $x[5]);
foreach ($m as $x) {
// the first parameter is special
if (!in_array($x[1], array('else', 'endif', 'return'))) // hack to skip reserved words
$ret[$x[4]] = array($x[1] . $x[2] . $x[3], $x[5]);
// are there more vars?
if ($x[6]) {
preg_match_all('/(\**)\s*(\w+(?:\[\s*\w*\s*\])?)\s*(=?)/S', $x[6], $y, PREG_SET_ORDER);
foreach ($y as $z) {
$ret[$z[2]] = array($x[1] . $z[1], $z[3]);
}
}
}
// are there more vars?
if ($x[6]) {
preg_match_all('/(\**)\s*(\w+(?:\[\s*\w*\s*\])?)\s*(=?)/S', $x[6], $y, PREG_SET_ORDER);
foreach ($y as $z) {
$ret[$z[2]] = array($x[1] . $z[1], $z[3]);
}
}
}
// if ($GLOBALS['current_function'] == 'for_debugging') { print_r($m);print_r($ret); }
return $ret;
return $ret;
}
/** run diagnostic checks against one var. */
function check_param($db, $idx, $exp, $optional, $allow_uninit = false)
{
global $error_few_vars_given;
global $error_few_vars_given;
if ($idx >= count($db)) {
if (!$error_few_vars_given) {
error("too few variables passed to function");
$error_few_vars_given = true;
}
return;
} elseif ($db[$idx][0] === '**dummy**') {
return;
}
if ($idx >= count($db)) {
if (!$error_few_vars_given) {
error("too few variables passed to function");
$error_few_vars_given = true;
}
return;
} elseif ($db[$idx][0] === '**dummy**') {
return;
}
if ($db[$idx][1] != $exp) {
error("{$db[$idx][0]}: expected '$exp' but got '{$db[$idx][1]}' [".($idx+1).']');
}
if ($db[$idx][1] != $exp) {
error("{$db[$idx][0]}: expected '$exp' but got '{$db[$idx][1]}' [".($idx+1).']');
}
if (!$optional && $db[$idx][2]) {
error("not optional var is initialized: {$db[$idx][0]} [".($idx+1).']', 2);
}
if (!$allow_uninit && $optional && !$db[$idx][2]) {
error("optional var not initialized: {$db[$idx][0]} [".($idx+1).']', 1);
}
if (!$optional && $db[$idx][2]) {
error("not optional var is initialized: {$db[$idx][0]} [".($idx+1).']', 2);
}
if (!$allow_uninit && $optional && !$db[$idx][2]) {
error("optional var not initialized: {$db[$idx][0]} [".($idx+1).']', 1);
}
}
/** fetch params passed to zend_parse_params*() */
function get_params($vars, $str)
{
$ret = array();
preg_match_all('/(?:\([^)]+\))?(&?)([\w>.()-]+(?:\[\w+\])?)\s*,?((?:\)*\s*=)?)/S', $str, $m, PREG_SET_ORDER);
$ret = array();
preg_match_all('/(?:\([^)]+\))?(&?)([\w>.()-]+(?:\[\w+\])?)\s*,?((?:\)*\s*=)?)/S', $str, $m, PREG_SET_ORDER);
foreach ($m as $x) {
$name = $x[2];
foreach ($m as $x) {
$name = $x[2];
// little hack for last parameter
if (strpos($name, '(') === false) {
$name = rtrim($name, ')');
}
// little hack for last parameter
if (strpos($name, '(') === false) {
$name = rtrim($name, ')');
}
if (empty($vars[$name][0])) {
error("variable not found: '$name'", 3);
$ret[][] = '**dummy**';
if (empty($vars[$name][0])) {
error("variable not found: '$name'", 3);
$ret[][] = '**dummy**';
} else {
$ret[] = array($name, $vars[$name][0] . ($x[1] ? '*' : ''), $vars[$name][1]);
}
} else {
$ret[] = array($name, $vars[$name][0] . ($x[1] ? '*' : ''), $vars[$name][1]);
}
// the end (yes, this is a little hack :P)
if ($x[3]) {
break;
}
}
// the end (yes, this is a little hack :P)
if ($x[3]) {
break;
}
}
// if ($GLOBALS['current_function'] == 'for_debugging') { var_dump($m); var_dump($ret); }
return $ret;
return $ret;
}
/** run tests on a function. the code is passed in $txt */
function check_function($name, $txt, $offset)
{
global $API_params;
global $API_params;
$regex = '/
(?: zend_parse_parameters(?:_throw)? \s*\([^,]+
| zend_parse_(?:parameters_ex|method_parameters) \s*\([^,]+,[^,]+
| zend_parse_method_parameters_ex \s*\([^,]+,[^,]+,[^,+]
)
,\s*"([^"]*)"\s*
,\s*([^{;]*)
/Sx';
if (preg_match_all($regex, $txt, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
$regex = '/
(?: zend_parse_parameters(?:_throw)? \s*\([^,]+
| zend_parse_(?:parameters_ex|method_parameters) \s*\([^,]+,[^,]+
| zend_parse_method_parameters_ex \s*\([^,]+,[^,]+,[^,+]
)
,\s*"([^"]*)"\s*
,\s*([^{;]*)
/Sx';
if (preg_match_all($regex, $txt, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
$GLOBALS['current_function'] = $name;
$GLOBALS['current_function'] = $name;
foreach ($matches as $m) {
$GLOBALS['error_few_vars_given'] = false;
update_lineno($offset + $m[2][1]);
foreach ($matches as $m) {
$GLOBALS['error_few_vars_given'] = false;
update_lineno($offset + $m[2][1]);
$vars = get_vars(substr($txt, 0, $m[0][1])); // limit var search to current location
$params = get_params($vars, $m[2][0]);
$optional = $varargs = false;
$last_char = '';
$j = -1;
$vars = get_vars(substr($txt, 0, $m[0][1])); // limit var search to current location
$params = get_params($vars, $m[2][0]);
$optional = $varargs = false;
$last_char = '';
$j = -1;
$spec = $m[1][0];
$len = strlen($spec);
for ($i = 0; $i < $len; ++$i) {
$char = $spec[$i];
switch ($char = $spec[$i]) {
// separator for optional parameters
case '|':
if ($optional) {
error("more than one optional separator at char #$i");
} else {
$optional = true;
if ($i == $len-1) {
error("unnecessary optional separator");
}
}
break;
$spec = $m[1][0];
$len = strlen($spec);
for ($i = 0; $i < $len; ++$i) {
$char = $spec[$i];
switch ($char = $spec[$i]) {
// separator for optional parameters
case '|':
if ($optional) {
error("more than one optional separator at char #$i");
} else {
$optional = true;
if ($i == $len-1) {
error("unnecessary optional separator");
}
}
break;
// separate_zval_if_not_ref
case '/':
if (in_array($last_char, array('l', 'L', 'd', 'b'))) {
error("the '/' specifier should not be applied to '$last_char'");
}
break;
// separate_zval_if_not_ref
case '/':
if (in_array($last_char, array('l', 'L', 'd', 'b'))) {
error("the '/' specifier should not be applied to '$last_char'");
}
break;
// nullable arguments
case '!':
if (in_array($last_char, array('l', 'L', 'd', 'b'))) {
check_param($params, ++$j, 'zend_bool*', $optional);
}
break;
// nullable arguments
case '!':
if (in_array($last_char, array('l', 'L', 'd', 'b'))) {
check_param($params, ++$j, 'zend_bool*', $optional);
}
break;
// variadic arguments
case '+':
case '*':
if ($varargs) {
error("A varargs specifier can only be used once. repeated char at column $i");
} else {
check_param($params, ++$j, 'zval**', $optional);
check_param($params, ++$j, 'int*', $optional);
$varargs = true;
}
break;
// variadic arguments
case '+':
case '*':
if ($varargs) {
error("A varargs specifier can only be used once. repeated char at column $i");
} else {
check_param($params, ++$j, 'zval**', $optional);
check_param($params, ++$j, 'int*', $optional);
$varargs = true;
}
break;
case 's':
case 'p':
check_param($params, ++$j, 'char**', $optional, $allow_uninit=true);
check_param($params, ++$j, 'size_t*', $optional, $allow_uninit=true);
if ($optional && !$params[$j-1][2] && !$params[$j][2]
&& $params[$j-1][0] !== '**dummy**' && $params[$j][0] !== '**dummy**') {
error("one of optional vars {$params[$j-1][0]} or {$params[$j][0]} must be initialized", 1);
}
break;
case 's':
case 'p':
check_param($params, ++$j, 'char**', $optional, $allow_uninit=true);
check_param($params, ++$j, 'size_t*', $optional, $allow_uninit=true);
if ($optional && !$params[$j-1][2] && !$params[$j][2]
&& $params[$j-1][0] !== '**dummy**' && $params[$j][0] !== '**dummy**') {
error("one of optional vars {$params[$j-1][0]} or {$params[$j][0]} must be initialized", 1);
}
break;
case 'C':
// C must always be initialized, independently of whether it's optional
check_param($params, ++$j, 'zend_class_entry**', false);
break;
case 'C':
// C must always be initialized, independently of whether it's optional
check_param($params, ++$j, 'zend_class_entry**', false);
break;
default:
if (!isset($API_params[$char])) {
error("unknown char ('$char') at column $i");
}
default:
if (!isset($API_params[$char])) {
error("unknown char ('$char') at column $i");
}
// If an is_null flag is in use, only that flag is required to be
// initialized
$allow_uninit = $i+1 < $len && $spec[$i+1] === '!'
&& in_array($char, array('l', 'L', 'd', 'b'));
// If an is_null flag is in use, only that flag is required to be
// initialized
$allow_uninit = $i+1 < $len && $spec[$i+1] === '!'
&& in_array($char, array('l', 'L', 'd', 'b'));
foreach ($API_params[$char] as $exp) {
check_param($params, ++$j, $exp, $optional, $allow_uninit);
}
}
foreach ($API_params[$char] as $exp) {
check_param($params, ++$j, $exp, $optional, $allow_uninit);
}
}
$last_char = $char;
}
}
}
$last_char = $char;
}
}
}
}
/** the main recursion function. splits files in functions and calls the other functions */
function recurse($path)
{
foreach (scandir($path) as $file) {
if ($file == '.' || $file == '..' || $file == 'CVS') continue;
foreach (scandir($path) as $file) {
if ($file == '.' || $file == '..' || $file == 'CVS') continue;
$file = "$path/$file";
if (is_dir($file)) {
recurse($file);
continue;
}
$file = "$path/$file";
if (is_dir($file)) {
recurse($file);
continue;
}
// parse only .c and .cpp files
if (substr_compare($file, '.c', -2) && substr_compare($file, '.cpp', -4)) continue;
// parse only .c and .cpp files
if (substr_compare($file, '.c', -2) && substr_compare($file, '.cpp', -4)) continue;
$txt = file_get_contents($file);
// remove comments (but preserve the number of lines)
$txt = preg_replace('@//.*@S', '', $txt);
$txt = preg_replace_callback('@/\*.*\*/@SsU', function($matches) {
return preg_replace("/[^\r\n]+/S", "", $matches[0]);
}, $txt);
$txt = file_get_contents($file);
// remove comments (but preserve the number of lines)
$txt = preg_replace('@//.*@S', '', $txt);
$txt = preg_replace_callback('@/\*.*\*/@SsU', function($matches) {
return preg_replace("/[^\r\n]+/S", "", $matches[0]);
}, $txt);
$split = preg_split('/PHP_(?:NAMED_)?(?:FUNCTION|METHOD)\s*\((\w+(?:,\s*\w+)?)\)/S', $txt, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE);
$split = preg_split('/PHP_(?:NAMED_)?(?:FUNCTION|METHOD)\s*\((\w+(?:,\s*\w+)?)\)/S', $txt, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE);
if (count($split) < 2) continue; // no functions defined on this file
array_shift($split); // the first part isn't relevant
if (count($split) < 2) continue; // no functions defined on this file
array_shift($split); // the first part isn't relevant
// generate the line offsets array
$j = 0;
$lines = preg_split("/(\r\n?|\n)/S", $txt, -1, PREG_SPLIT_DELIM_CAPTURE);
$lines_offset = array();
// generate the line offsets array
$j = 0;
$lines = preg_split("/(\r\n?|\n)/S", $txt, -1, PREG_SPLIT_DELIM_CAPTURE);
$lines_offset = array();
for ($i = 0; $i < count($lines); ++$i) {
$j += strlen($lines[$i]) + strlen(@$lines[++$i]);
$lines_offset[] = $j;
}
for ($i = 0; $i < count($lines); ++$i) {
$j += strlen($lines[$i]) + strlen(@$lines[++$i]);
$lines_offset[] = $j;
}
$GLOBALS['lines_offset'] = $lines_offset;
$GLOBALS['current_file'] = $file;
$GLOBALS['lines_offset'] = $lines_offset;
$GLOBALS['current_file'] = $file;
for ($i = 0; $i < count($split); $i+=2) {
// if the /* }}} */ comment is found use it to reduce false positives
// TODO: check the other indexes
list($f) = preg_split('@/\*\s*}}}\s*\*/@S', $split[$i+1][0]);
check_function(preg_replace('/\s*,\s*/S', '::', $split[$i][0]), $f, $split[$i][1]);
}
}
for ($i = 0; $i < count($split); $i+=2) {
// if the /* }}} */ comment is found use it to reduce false positives
// TODO: check the other indexes
list($f) = preg_split('@/\*\s*}}}\s*\*/@S', $split[$i+1][0]);
check_function(preg_replace('/\s*,\s*/S', '::', $split[$i][0]), $f, $split[$i][1]);
}
}
}
$dirs = array();
if (isset($argc) && $argc > 1) {
if ($argv[1] == '-h' || $argv[1] == '-help' || $argv[1] == '--help') {
echo <<<HELP
if ($argv[1] == '-h' || $argv[1] == '-help' || $argv[1] == '--help') {
echo <<<HELP
Synopsis:
php check_parameters.php [directories]
HELP;
exit(0);
}
for ($i = 1; $i < $argc; $i++) {
$dirs[] = $argv[$i];
}
exit(0);
}
for ($i = 1; $i < $argc; $i++) {
$dirs[] = $argv[$i];
}
} else {
$dirs[] = PHPDIR;
$dirs[] = PHPDIR;
}
foreach($dirs as $dir) {
if (is_dir($dir)) {
if (!is_readable($dir)) {
echo "ERROR: directory '", $dir ,"' is not readable\n";
exit(1);
}
} else {
echo "ERROR: bogus directory '", $dir ,"'\n";
exit(1);
}
if (is_dir($dir)) {
if (!is_readable($dir)) {
echo "ERROR: directory '", $dir ,"' is not readable\n";
exit(1);
}
} else {
echo "ERROR: bogus directory '", $dir ,"'\n";
exit(1);
}
}
foreach ($dirs as $dir) {
recurse(realpath($dir));
recurse(realpath($dir));
}

View file

@ -201,27 +201,27 @@ function get_phpt_files($dir, &$phpt_file_count, &$all_phpt)
* Extract tests from a specified file, returns an array of tested function tokens
*/
function extract_tests($file) {
$code = file_get_contents($file);
$code = file_get_contents($file);
if (!preg_match('/--FILE--\s*(.*)\s*--(EXPECTF|EXPECTREGEX|EXPECT)?--/is', $code, $r)) {
//print "Unable to get code in ".$file."\n";
return array();
}
if (!preg_match('/--FILE--\s*(.*)\s*--(EXPECTF|EXPECTREGEX|EXPECT)?--/is', $code, $r)) {
//print "Unable to get code in ".$file."\n";
return array();
}
$tokens = token_get_all($r[1]);
$functions = array_filter($tokens, 'filter_functions');
$functions = array_map( 'map_token_value',$functions);
$functions = array_unique($functions);
$tokens = token_get_all($r[1]);
$functions = array_filter($tokens, 'filter_functions');
$functions = array_map( 'map_token_value',$functions);
$functions = array_unique($functions);
return $functions;
return $functions;
}
function filter_functions($x) {
return $x[0] == 307;
return $x[0] == 307;
}
function map_token_value($x) {
return $x[1];
return $x[1];
}

View file

@ -32,38 +32,38 @@ $classes = array_merge(get_declared_classes(), get_declared_interfaces());
$extensions = array();
foreach(get_loaded_extensions() as $ext) {
$cnt_modules++;
if (strpos($ext, "_") !== false) {
$err++;
$extensions[$ext] = array();
}
$cnt_modules++;
if (strpos($ext, "_") !== false) {
$err++;
$extensions[$ext] = array();
}
}
$cnt_classes = count($classes);
foreach($classes as $c) {
if (strpos($c, "_") !== false) {
$err++;
$ref = new ReflectionClass($c);
if (!($ext = $ref->getExtensionName())) {;
$ext = $ref->isInternal() ? "<internal>" : "<user>";
}
if (!array_key_exists($ext, $extensions)) {
$extensions[$ext] = array();
}
$extensions[$ext][$c] = array();
foreach(get_class_methods($c) as $method) {
$cnt_methods++;
if (strpos(substr($method, substr($method, 0, 2) != "__" ? 0 : 2), "_") !== false) {
$err++;
$extensions[$ext][$c][] = $method;
}
}
}
else
{
$cnt_methods += count(get_class_methods($c));
}
if (strpos($c, "_") !== false) {
$err++;
$ref = new ReflectionClass($c);
if (!($ext = $ref->getExtensionName())) {;
$ext = $ref->isInternal() ? "<internal>" : "<user>";
}
if (!array_key_exists($ext, $extensions)) {
$extensions[$ext] = array();
}
$extensions[$ext][$c] = array();
foreach(get_class_methods($c) as $method) {
$cnt_methods++;
if (strpos(substr($method, substr($method, 0, 2) != "__" ? 0 : 2), "_") !== false) {
$err++;
$extensions[$ext][$c][] = $method;
}
}
}
else
{
$cnt_methods += count(get_class_methods($c));
}
}
$cnt = $cnt_modules + $cnt_classes + $cnt_methods;
@ -79,15 +79,15 @@ printf("\n");
ksort($extensions);
foreach($extensions as $ext => &$classes) {
echo "Extension: $ext\n";
ksort($classes);
foreach($classes as $classname => &$methods) {
echo " Class: $classname\n";
ksort($methods);
foreach($methods as $method) {
echo " Method: $method\n";
}
}
echo "Extension: $ext\n";
ksort($classes);
foreach($classes as $classname => &$methods) {
echo " Class: $classname\n";
ksort($methods);
foreach($methods as $method) {
echo " Method: $method\n";
}
}
}
printf("\n");

View file

@ -31,136 +31,136 @@ $pecl_dll_deps = array();
function get_depends($module)
{
static $no_dist = array(
/* windows system dlls that should not be bundled */
'advapi32.dll', 'comdlg32.dll', 'crypt32.dll', 'gdi32.dll', 'kernel32.dll', 'ntdll.dll',
'odbc32.dll', 'ole32.dll', 'oleaut32.dll', 'rpcrt4.dll',
'shell32.dll', 'shlwapi.dll', 'user32.dll', 'ws2_32.dll', 'ws2help.dll',
'comctl32.dll', 'winmm.dll', 'wsock32.dll', 'winspool.drv', 'msasn1.dll',
'secur32.dll', 'netapi32.dll', 'dnsapi.dll', 'psapi.dll', 'normaliz.dll',
'iphlpapi.dll', 'bcrypt.dll',
static $no_dist = array(
/* windows system dlls that should not be bundled */
'advapi32.dll', 'comdlg32.dll', 'crypt32.dll', 'gdi32.dll', 'kernel32.dll', 'ntdll.dll',
'odbc32.dll', 'ole32.dll', 'oleaut32.dll', 'rpcrt4.dll',
'shell32.dll', 'shlwapi.dll', 'user32.dll', 'ws2_32.dll', 'ws2help.dll',
'comctl32.dll', 'winmm.dll', 'wsock32.dll', 'winspool.drv', 'msasn1.dll',
'secur32.dll', 'netapi32.dll', 'dnsapi.dll', 'psapi.dll', 'normaliz.dll',
'iphlpapi.dll', 'bcrypt.dll',
/* apache */
'apachecore.dll',
/* apache */
'apachecore.dll',
/* apache 2 */
'libhttpd.dll', 'libapr.dll', 'libaprutil.dll','libapr-1.dll', 'libaprutil-1.dll',
/* apache 2 */
'libhttpd.dll', 'libapr.dll', 'libaprutil.dll','libapr-1.dll', 'libaprutil-1.dll',
/* oracle */
'oci.dll', 'ociw32.dll',
/* oracle */
'oci.dll', 'ociw32.dll',
/* sybase */
'libcs.dll', 'libct.dll',
/* sybase */
'libcs.dll', 'libct.dll',
/* firebird */
'fbclient.dll',
/* firebird */
'fbclient.dll',
/* visual C++; mscvrt.dll is present on everyones system,
* but the debug version (msvcrtd.dll) and those from visual studio.net
* (msvcrt7x.dll) are not */
'msvcrt.dll',
'msvcr90.dll',
'wldap32.dll',
'vcruntime140.dll',
'msvcp140.dll',
);
static $no_dist_re = array(
"api-ms-win-crt-.+\.dll",
);
global $build_dir, $extra_dll_deps, $ext_targets, $sapi_targets, $pecl_targets, $phpdll, $per_module_deps, $pecl_dll_deps;
/* visual C++; mscvrt.dll is present on everyones system,
* but the debug version (msvcrtd.dll) and those from visual studio.net
* (msvcrt7x.dll) are not */
'msvcrt.dll',
'msvcr90.dll',
'wldap32.dll',
'vcruntime140.dll',
'msvcp140.dll',
);
static $no_dist_re = array(
"api-ms-win-crt-.+\.dll",
);
global $build_dir, $extra_dll_deps, $ext_targets, $sapi_targets, $pecl_targets, $phpdll, $per_module_deps, $pecl_dll_deps;
$bd = strtolower(realpath($build_dir));
$bd = strtolower(realpath($build_dir));
$is_pecl = in_array($module, $pecl_targets);
$is_pecl = in_array($module, $pecl_targets);
$cmd = "$GLOBALS[build_dir]\\deplister.exe \"$module\" \"$GLOBALS[build_dir]\"";
$proc = proc_open($cmd,
array(1 => array("pipe", "w")),
$pipes);
$cmd = "$GLOBALS[build_dir]\\deplister.exe \"$module\" \"$GLOBALS[build_dir]\"";
$proc = proc_open($cmd,
array(1 => array("pipe", "w")),
$pipes);
$n = 0;
while (($line = fgetcsv($pipes[1]))) {
$n++;
$n = 0;
while (($line = fgetcsv($pipes[1]))) {
$n++;
$dep = strtolower($line[0]);
$depbase = basename($dep);
/* ignore stuff in our build dir, but only if it is
* one of our targets */
if (((in_array($depbase, $sapi_targets) ||
in_array($depbase, $ext_targets) || in_array($depbase, $pecl_targets)) ||
$depbase == $phpdll) && file_exists($GLOBALS['build_dir'] . "/$depbase")) {
continue;
}
/* ignore some well-known system dlls */
if (in_array(basename($dep), $no_dist)) {
continue;
} else {
$skip = false;
foreach ($no_dist_re as $re) {
if (preg_match(",$re,", basename($dep)) > 0) {
$skip = true;
break;
}
}
if ($skip) {
continue;
}
}
$dep = strtolower($line[0]);
$depbase = basename($dep);
/* ignore stuff in our build dir, but only if it is
* one of our targets */
if (((in_array($depbase, $sapi_targets) ||
in_array($depbase, $ext_targets) || in_array($depbase, $pecl_targets)) ||
$depbase == $phpdll) && file_exists($GLOBALS['build_dir'] . "/$depbase")) {
continue;
}
/* ignore some well-known system dlls */
if (in_array(basename($dep), $no_dist)) {
continue;
} else {
$skip = false;
foreach ($no_dist_re as $re) {
if (preg_match(",$re,", basename($dep)) > 0) {
$skip = true;
break;
}
}
if ($skip) {
continue;
}
}
if ($is_pecl) {
if (!in_array($dep, $pecl_dll_deps)) {
$pecl_dll_deps[] = $dep;
}
} else {
if (!in_array($dep, $extra_dll_deps)) {
$extra_dll_deps[] = $dep;
}
}
if ($is_pecl) {
if (!in_array($dep, $pecl_dll_deps)) {
$pecl_dll_deps[] = $dep;
}
} else {
if (!in_array($dep, $extra_dll_deps)) {
$extra_dll_deps[] = $dep;
}
}
if (!isset($per_module_deps[basename($module)]) || !in_array($dep, $per_module_deps[basename($module)])) {
$per_module_deps[basename($module)][] = $dep;
//recursively check dll dependencies
get_depends($dep);
}
}
fclose($pipes[1]);
proc_close($proc);
if (!isset($per_module_deps[basename($module)]) || !in_array($dep, $per_module_deps[basename($module)])) {
$per_module_deps[basename($module)][] = $dep;
//recursively check dll dependencies
get_depends($dep);
}
}
fclose($pipes[1]);
proc_close($proc);
//echo "Module $module [$n lines]\n";
}
function copy_file_list($source_dir, $dest_dir, $list)
{
global $is_debug, $dist_dir;
global $is_debug, $dist_dir;
foreach ($list as $item) {
if (empty($item)) {
continue;
} elseif (!is_file($source_dir . DIRECTORY_SEPARATOR . $item)) {
echo "WARNING: $item not found\n";
continue;
}
foreach ($list as $item) {
if (empty($item)) {
continue;
} elseif (!is_file($source_dir . DIRECTORY_SEPARATOR . $item)) {
echo "WARNING: $item not found\n";
continue;
}
echo "Copying $item from $source_dir to $dest_dir\n";
copy($source_dir . DIRECTORY_SEPARATOR . $item, $dest_dir . DIRECTORY_SEPARATOR . $item);
if ($is_debug) {
$itemdb = preg_replace("/\.(exe|dll|lib)$/i", ".pdb", $item);
if (file_exists("$source_dir/$itemdb")) {
copy("$source_dir/$itemdb", "$dist_dir/dev/$itemdb");
}
}
if (preg_match("/\.(exe|dll)$/i", $item)) {
get_depends($source_dir . '/' . $item);
}
}
echo "Copying $item from $source_dir to $dest_dir\n";
copy($source_dir . DIRECTORY_SEPARATOR . $item, $dest_dir . DIRECTORY_SEPARATOR . $item);
if ($is_debug) {
$itemdb = preg_replace("/\.(exe|dll|lib)$/i", ".pdb", $item);
if (file_exists("$source_dir/$itemdb")) {
copy("$source_dir/$itemdb", "$dist_dir/dev/$itemdb");
}
}
if (preg_match("/\.(exe|dll)$/i", $item)) {
get_depends($source_dir . '/' . $item);
}
}
}
function copy_text_file($source, $dest)
{
$text = file_get_contents($source);
$text = preg_replace("/(\r\n?)|\n/", "\r\n", $text);
$fp = fopen($dest, "w");
fwrite($fp, $text);
fclose($fp);
$text = file_get_contents($source);
$text = preg_replace("/(\r\n?)|\n/", "\r\n", $text);
$fp = fopen($dest, "w");
fwrite($fp, $text);
fclose($fp);
}
/* very light-weight function to extract a single named file from
@ -168,57 +168,57 @@ function copy_text_file($source, $dest)
* based on the PEAR info set in $packages. */
function extract_file_from_tarball($pkg, $filename, $dest_dir) /* {{{ */
{
global $packages;
global $packages;
$name = $pkg . '-' . $packages[$pkg];
$tarball = $dest_dir . "/" . $name . '.tgz';
$filename = $name . '/' . $filename;
$destfilename = $dest_dir . "/" . basename($filename);
$name = $pkg . '-' . $packages[$pkg];
$tarball = $dest_dir . "/" . $name . '.tgz';
$filename = $name . '/' . $filename;
$destfilename = $dest_dir . "/" . basename($filename);
$fp = gzopen($tarball, 'rb');
$fp = gzopen($tarball, 'rb');
$done = false;
do {
/* read the header */
$hdr_data = gzread($fp, 512);
if (strlen($hdr_data) == 0)
break;
$checksum = 0;
for ($i = 0; $i < 148; $i++)
$checksum += ord($hdr_data{$i});
for ($i = 148; $i < 156; $i++)
$checksum += 32;
for ($i = 156; $i < 512; $i++)
$checksum += ord($hdr_data{$i});
$done = false;
do {
/* read the header */
$hdr_data = gzread($fp, 512);
if (strlen($hdr_data) == 0)
break;
$checksum = 0;
for ($i = 0; $i < 148; $i++)
$checksum += ord($hdr_data{$i});
for ($i = 148; $i < 156; $i++)
$checksum += 32;
for ($i = 156; $i < 512; $i++)
$checksum += ord($hdr_data{$i});
$hdr = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $hdr_data);
$hdr = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $hdr_data);
$hdr['checksum'] = octdec(trim($hdr['checksum']));
$hdr['checksum'] = octdec(trim($hdr['checksum']));
if ($hdr['checksum'] != $checksum) {
echo "Checksum for $tarball $hdr[filename] is invalid\n";
print_r($hdr);
return;
}
if ($hdr['checksum'] != $checksum) {
echo "Checksum for $tarball $hdr[filename] is invalid\n";
print_r($hdr);
return;
}
$hdr['size'] = octdec(trim($hdr['size']));
echo "File: $hdr[filename] $hdr[size]\n";
$hdr['size'] = octdec(trim($hdr['size']));
echo "File: $hdr[filename] $hdr[size]\n";
if ($filename == $hdr['filename']) {
echo "Found the file we want\n";
$dest = fopen($destfilename, 'wb');
$x = stream_copy_to_stream($fp, $dest, $hdr['size']);
fclose($dest);
echo "Wrote $x bytes into $destfilename\n";
break;
}
if ($filename == $hdr['filename']) {
echo "Found the file we want\n";
$dest = fopen($destfilename, 'wb');
$x = stream_copy_to_stream($fp, $dest, $hdr['size']);
fclose($dest);
echo "Wrote $x bytes into $destfilename\n";
break;
}
/* skip body of the file */
$size = 512 * ceil((int)$hdr['size'] / 512);
echo "Skipping $size bytes\n";
gzseek($fp, gztell($fp) + $size);
/* skip body of the file */
$size = 512 * ceil((int)$hdr['size'] / 512);
echo "Skipping $size bytes\n";
gzseek($fp, gztell($fp) + $size);
} while (!$done);
} while (!$done);
} /* }}} */
@ -233,8 +233,8 @@ $phplib = str_replace(".dll", ".lib", $phpdll);
copy("$build_dir/$phplib", "$dist_dir/dev/$phplib");
/* debug builds; copy the symbols too */
if ($is_debug) {
$phppdb = str_replace(".dll", ".pdb", $phpdll);
copy("$build_dir/$phppdb", "$dist_dir/dev/$phppdb");
$phppdb = str_replace(".dll", ".pdb", $phpdll);
copy("$build_dir/$phppdb", "$dist_dir/dev/$phppdb");
}
/* copy the sapi */
copy_file_list($build_dir, "$dist_dir", $sapi_targets);
@ -244,30 +244,30 @@ copy_file_list($build_dir, "$dist_dir/ext", $ext_targets);
/* pecl sapi and extensions */
if(sizeof($pecl_targets)) {
copy_file_list($build_dir, $pecl_dir, $pecl_targets);
copy_file_list($build_dir, $pecl_dir, $pecl_targets);
}
/* populate reading material */
$text_files = array(
"LICENSE" => "license.txt",
"NEWS" => "news.txt",
"README.md" => "README.md",
"README.REDIST.BINS" => "readme-redist-bins.txt",
"php.ini-development" => "php.ini-development",
"php.ini-production" => "php.ini-production"
"LICENSE" => "license.txt",
"NEWS" => "news.txt",
"README.md" => "README.md",
"README.REDIST.BINS" => "readme-redist-bins.txt",
"php.ini-development" => "php.ini-development",
"php.ini-production" => "php.ini-production"
);
foreach ($text_files as $src => $dest) {
copy_text_file($src, $dist_dir . '/' . $dest);
copy_text_file($src, $dist_dir . '/' . $dest);
}
/* general other files */
$general_files = array(
"$GLOBALS[build_dir]\\deplister.exe" => "deplister.exe",
"$GLOBALS[build_dir]\\deplister.exe" => "deplister.exe",
);
foreach ($general_files as $src => $dest) {
copy($src, $dist_dir . '/' . $dest);
copy($src, $dist_dir . '/' . $dest);
}
/* include a snapshot identifier */
@ -289,40 +289,40 @@ $exts = get_loaded_extensions();
fprintf($fp, "\r\nBuilt-in Extensions\r\n");
fwrite($fp, "===========================\r\n");
foreach ($exts as $ext) {
fprintf($fp, "%s\r\n", $ext);
fprintf($fp, "%s\r\n", $ext);
}
fwrite($fp, "\r\n\r\n");
/* list dependencies */
fprintf($fp, "Dependency information:\r\n");
foreach ($per_module_deps as $modulename => $deps) {
if (in_array($modulename, $pecl_targets))
continue;
if (in_array($modulename, $pecl_targets))
continue;
fprintf($fp, "Module: %s\r\n", $modulename);
fwrite($fp, "===========================\r\n");
foreach ($deps as $dll) {
fprintf($fp, "\t%s\r\n", basename($dll));
}
fwrite($fp, "\r\n");
fprintf($fp, "Module: %s\r\n", $modulename);
fwrite($fp, "===========================\r\n");
foreach ($deps as $dll) {
fprintf($fp, "\t%s\r\n", basename($dll));
}
fwrite($fp, "\r\n");
}
fclose($fp);
/* Now add those dependencies */
foreach ($extra_dll_deps as $dll) {
if (!file_exists($dll)) {
/* try template dir */
$tdll = $snapshot_template . "/dlls/" . basename($dll);
if (!file_exists($tdll)) {
$tdll = $php_build_dir . '/bin/' . basename($dll);
if (!file_exists($tdll)) {
echo "WARNING: distro depends on $dll, but could not find it on your system\n";
continue;
}
}
$dll = $tdll;
}
copy($dll, "$dist_dir/" . basename($dll));
if (!file_exists($dll)) {
/* try template dir */
$tdll = $snapshot_template . "/dlls/" . basename($dll);
if (!file_exists($tdll)) {
$tdll = $php_build_dir . '/bin/' . basename($dll);
if (!file_exists($tdll)) {
echo "WARNING: distro depends on $dll, but could not find it on your system\n";
continue;
}
}
$dll = $tdll;
}
copy($dll, "$dist_dir/" . basename($dll));
}
/* TODO:
@ -333,168 +333,168 @@ deps. For example, libenchant.dll loads libenchant_myspell.dll or
libenchant_ispell.dll
*/
$ENCHANT_DLLS = array(
array('', 'glib-2.dll'),
array('', 'gmodule-2.dll'),
array('lib/enchant', 'libenchant_myspell.dll'),
array('lib/enchant', 'libenchant_ispell.dll'),
array('', 'glib-2.dll'),
array('', 'gmodule-2.dll'),
array('lib/enchant', 'libenchant_myspell.dll'),
array('lib/enchant', 'libenchant_ispell.dll'),
);
foreach ($ENCHANT_DLLS as $dll) {
$dest = "$dist_dir/$dll[0]";
$filename = $dll[1];
$dest = "$dist_dir/$dll[0]";
$filename = $dll[1];
if (!file_exists("$dest") || !is_dir("$dest")) {
if (!mkdir("$dest", 0777, true)) {
echo "WARNING: couldn't create '$dest' for enchant plugins ";
}
}
if (!file_exists("$dest") || !is_dir("$dest")) {
if (!mkdir("$dest", 0777, true)) {
echo "WARNING: couldn't create '$dest' for enchant plugins ";
}
}
if (!copy($php_build_dir . '/bin/' . $filename, "$dest/" . basename($filename))) {
echo "WARNING: couldn't copy $filename into the dist dir";
}
if (!copy($php_build_dir . '/bin/' . $filename, "$dest/" . basename($filename))) {
echo "WARNING: couldn't copy $filename into the dist dir";
}
}
$SASL_DLLS = $php_build_dir . "/bin/sasl2/sasl*.dll";
$fls = glob($SASL_DLLS);
if (!empty($fls)) {
$sasl_dest_dir = "$dist_dir/sasl2";
if (!file_exists($sasl_dest_dir) || !is_dir($sasl_dest_dir)) {
if (!mkdir("$sasl_dest_dir", 0777, true)) {
echo "WARNING: couldn't create '$sasl_dest_dir' for SASL2 auth plugins ";
}
}
foreach ($fls as $fl) {
if (!copy($fl, "$sasl_dest_dir/" . basename($fl))) {
echo "WARNING: couldn't copy $fl into the $sasl_dest_dir";
}
}
$sasl_dest_dir = "$dist_dir/sasl2";
if (!file_exists($sasl_dest_dir) || !is_dir($sasl_dest_dir)) {
if (!mkdir("$sasl_dest_dir", 0777, true)) {
echo "WARNING: couldn't create '$sasl_dest_dir' for SASL2 auth plugins ";
}
}
foreach ($fls as $fl) {
if (!copy($fl, "$sasl_dest_dir/" . basename($fl))) {
echo "WARNING: couldn't copy $fl into the $sasl_dest_dir";
}
}
}
/* and those for pecl */
foreach ($pecl_dll_deps as $dll) {
if (in_array($dll, $extra_dll_deps)) {
/* already in main distro */
continue;
}
if (!file_exists($dll)) {
/* try template dir */
$tdll = $snapshot_template . "/dlls/" . basename($dll);
if (!file_exists($tdll)) {
echo "WARNING: distro depends on $dll, but could not find it on your system\n";
continue;
}
$dll = $tdll;
}
copy($dll, "$pecl_dir/" . basename($dll));
if (in_array($dll, $extra_dll_deps)) {
/* already in main distro */
continue;
}
if (!file_exists($dll)) {
/* try template dir */
$tdll = $snapshot_template . "/dlls/" . basename($dll);
if (!file_exists($tdll)) {
echo "WARNING: distro depends on $dll, but could not find it on your system\n";
continue;
}
$dll = $tdll;
}
copy($dll, "$pecl_dir/" . basename($dll));
}
function copy_dir($source, $dest)
{
if (!is_dir($dest)) {
if (!mkdir($dest)) {
return false;
}
}
if (!is_dir($dest)) {
if (!mkdir($dest)) {
return false;
}
}
$d = opendir($source);
while (($f = readdir($d)) !== false) {
if ($f == '.' || $f == '..' || $f == '.svn') {
continue;
}
$fs = $source . '/' . $f;
$fd = $dest . '/' . $f;
if (is_dir($fs)) {
copy_dir($fs, $fd);
} else {
copy($fs, $fd);
}
}
closedir($d);
$d = opendir($source);
while (($f = readdir($d)) !== false) {
if ($f == '.' || $f == '..' || $f == '.svn') {
continue;
}
$fs = $source . '/' . $f;
$fd = $dest . '/' . $f;
if (is_dir($fs)) {
copy_dir($fs, $fd);
} else {
copy($fs, $fd);
}
}
closedir($d);
}
function copy_test_dir($directory, $dest)
{
if(substr($directory,-1) == '/') {
$directory = substr($directory,0,-1);
}
if(substr($directory,-1) == '/') {
$directory = substr($directory,0,-1);
}
if ($directory == 'tests' || $directory == 'examples') {
if (!is_dir($dest . '/tests')) {
mkdir($dest . '/tests', 0775, true);
}
copy_dir($directory, $dest . '/tests/');
if ($directory == 'tests' || $directory == 'examples') {
if (!is_dir($dest . '/tests')) {
mkdir($dest . '/tests', 0775, true);
}
copy_dir($directory, $dest . '/tests/');
return false;
}
return false;
}
if(!file_exists($directory) || !is_dir($directory)) {
echo "failed... $directory\n";
return FALSE;
}
if(!file_exists($directory) || !is_dir($directory)) {
echo "failed... $directory\n";
return FALSE;
}
$directory_list = opendir($directory);
$directory_list = opendir($directory);
while (FALSE !== ($file = readdir($directory_list))) {
$full_path = $directory . '/' . $file;
if($file != '.' && $file != '..' && $file != '.svn' && is_dir($full_path)) {
if ($file == 'tests' || $file == 'examples') {
if (!is_dir($dest . '/' . $full_path)) {
mkdir($dest . '/' . $full_path , 0775, true);
}
copy_dir($full_path, $dest . '/' . $full_path . '/');
continue;
} else {
copy_test_dir($full_path, $dest);
}
}
}
while (FALSE !== ($file = readdir($directory_list))) {
$full_path = $directory . '/' . $file;
if($file != '.' && $file != '..' && $file != '.svn' && is_dir($full_path)) {
if ($file == 'tests' || $file == 'examples') {
if (!is_dir($dest . '/' . $full_path)) {
mkdir($dest . '/' . $full_path , 0775, true);
}
copy_dir($full_path, $dest . '/' . $full_path . '/');
continue;
} else {
copy_test_dir($full_path, $dest);
}
}
}
closedir($directory_list);
closedir($directory_list);
}
function make_phar_dot_phar($dist_dir)
{
if (!extension_loaded('phar')) {
return;
}
if (!extension_loaded('phar')) {
return;
}
$path_to_phar = realpath(__DIR__ . '/../../ext/phar');
$path_to_phar = realpath(__DIR__ . '/../../ext/phar');
echo "Generating pharcommand.phar\n";
$phar = new Phar($dist_dir . '/pharcommand.phar', 0, 'pharcommand');
echo "Generating pharcommand.phar\n";
$phar = new Phar($dist_dir . '/pharcommand.phar', 0, 'pharcommand');
foreach (new DirectoryIterator($path_to_phar . '/phar') as $file) {
if ($file->isDir() || $file == 'phar.php') {
continue;
}
foreach (new DirectoryIterator($path_to_phar . '/phar') as $file) {
if ($file->isDir() || $file == 'phar.php') {
continue;
}
echo 'adding ', $file, "\n";
$phar[(string) $file] = file_get_contents($path_to_phar. '/phar/' . $file);
}
echo 'adding ', $file, "\n";
$phar[(string) $file] = file_get_contents($path_to_phar. '/phar/' . $file);
}
$phar->setSignatureAlgorithm(Phar::SHA1);
$stub = file($path_to_phar . '/phar/phar.php');
$phar->setSignatureAlgorithm(Phar::SHA1);
$stub = file($path_to_phar . '/phar/phar.php');
unset($stub[0]); // remove hashbang
$phar->setStub(implode('', $stub));
unset($stub[0]); // remove hashbang
$phar->setStub(implode('', $stub));
echo "Creating phar.phar.bat\n";
file_put_contents($dist_dir . '/phar.phar.bat', "\"%~dp0php.exe\" \"%~dp0pharcommand.phar\" %*\r\n");
echo "Creating phar.phar.bat\n";
file_put_contents($dist_dir . '/phar.phar.bat', "\"%~dp0php.exe\" \"%~dp0pharcommand.phar\" %*\r\n");
}
if (!is_dir($test_dir)) {
mkdir($test_dir);
mkdir($test_dir);
}
$dirs = array(
'ext',
'Sapi',
'Zend',
'tests'
'ext',
'Sapi',
'Zend',
'tests'
);
foreach ($dirs as $dir) {
copy_test_dir($dir, $test_dir);
copy_test_dir($dir, $test_dir);
}
copy('run-tests.php', $test_dir . '/run-tests.php');
@ -503,82 +503,82 @@ copy('run-tests.php', $test_dir . '/run-tests.php');
$use_pear_template = true;
if (!$use_pear_template) {
/* Let's do a PEAR-less pear setup */
mkdir("$dist_dir/PEAR");
mkdir("$dist_dir/PEAR/go-pear-bundle");
/* Let's do a PEAR-less pear setup */
mkdir("$dist_dir/PEAR");
mkdir("$dist_dir/PEAR/go-pear-bundle");
/* grab the bootstrap script */
echo "Downloading go-pear\n";
copy("https://pear.php.net/go-pear.phar", "$dist_dir/PEAR/go-pear.php");
/* grab the bootstrap script */
echo "Downloading go-pear\n";
copy("https://pear.php.net/go-pear.phar", "$dist_dir/PEAR/go-pear.php");
/* import the package list -- sets $packages variable */
include "pear/go-pear-list.php";
/* import the package list -- sets $packages variable */
include "pear/go-pear-list.php";
/* download the packages into the destination */
echo "Fetching packages\n";
/* download the packages into the destination */
echo "Fetching packages\n";
foreach ($packages as $name => $version) {
$filename = "$name-$version.tgz";
$destfilename = "$dist_dir/PEAR/go-pear-bundle/$filename";
if (file_exists($destfilename))
continue;
$url = "http://pear.php.net/get/$filename";
echo "Downloading $name from $url\n";
flush();
copy($url, $destfilename);
}
foreach ($packages as $name => $version) {
$filename = "$name-$version.tgz";
$destfilename = "$dist_dir/PEAR/go-pear-bundle/$filename";
if (file_exists($destfilename))
continue;
$url = "http://pear.php.net/get/$filename";
echo "Downloading $name from $url\n";
flush();
copy($url, $destfilename);
}
echo "Download complete. Extracting bootstrap files\n";
echo "Download complete. Extracting bootstrap files\n";
/* Now, we want PEAR.php, Getopt.php (Console_Getopt) and Tar.php (Archive_Tar)
* broken out of the tarballs */
extract_file_from_tarball('PEAR', 'PEAR.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Archive_Tar', 'Archive/Tar.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Console_Getopt', 'Console/Getopt.php', "$dist_dir/PEAR/go-pear-bundle");
/* Now, we want PEAR.php, Getopt.php (Console_Getopt) and Tar.php (Archive_Tar)
* broken out of the tarballs */
extract_file_from_tarball('PEAR', 'PEAR.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Archive_Tar', 'Archive/Tar.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Console_Getopt', 'Console/Getopt.php', "$dist_dir/PEAR/go-pear-bundle");
}
/* add extras from the template dir */
if (file_exists($snapshot_template)) {
$items = glob("$snapshot_template/*");
print_r($items);
$items = glob("$snapshot_template/*");
print_r($items);
foreach ($items as $item) {
$bi = basename($item);
if (is_dir($item)) {
if ($bi == 'dlls' || $bi == 'symbols') {
continue;
} else if ($bi == 'PEAR') {
if ($use_pear_template) {
/* copy to top level */
copy_dir($item, "$dist_dir/$bi");
}
} else {
/* copy that dir into extras */
copy_dir($item, "$dist_dir/extras/$bi");
}
} else {
if ($bi == 'go-pear.bat') {
/* copy to top level */
copy($item, "$dist_dir/$bi");
} else {
/* copy to extras */
copy($item, "$dist_dir/extras/$bi");
}
}
}
foreach ($items as $item) {
$bi = basename($item);
if (is_dir($item)) {
if ($bi == 'dlls' || $bi == 'symbols') {
continue;
} else if ($bi == 'PEAR') {
if ($use_pear_template) {
/* copy to top level */
copy_dir($item, "$dist_dir/$bi");
}
} else {
/* copy that dir into extras */
copy_dir($item, "$dist_dir/extras/$bi");
}
} else {
if ($bi == 'go-pear.bat') {
/* copy to top level */
copy($item, "$dist_dir/$bi");
} else {
/* copy to extras */
copy($item, "$dist_dir/extras/$bi");
}
}
}
/* copy c++ runtime */
$items = glob("$snapshot_template/dlls/*.CRT");
/* copy c++ runtime */
$items = glob("$snapshot_template/dlls/*.CRT");
foreach ($items as $item) {
$bi = basename($item);
if (is_dir($item)) {
copy_dir($item, "$dist_dir/$bi");
copy_dir($item, "$dist_dir/ext/$bi");
}
}
foreach ($items as $item) {
$bi = basename($item);
if (is_dir($item)) {
copy_dir($item, "$dist_dir/$bi");
copy_dir($item, "$dist_dir/ext/$bi");
}
}
} else {
echo "WARNING: you don't have a snapshot template, your dist will not be complete\n";
echo "WARNING: you don't have a snapshot template, your dist will not be complete\n";
}
make_phar_dot_phar($dist_dir);