#!/usr/bin/php -q $script) { add_output($script); // add print or echo if missing up_version($script, $func); // use test-up.php "up_functionname" #-- output sample script text from doc print_script($script); #-- create temp script, run it if ($MANY) { $tmp = "$tmpdir/$func#$i.php"; } $script = ltrim($script); file_put_contents( $tmp, "" ); echo "==>\033[32m\n"; passthru("$php $tmp 2>&1"); echo "\033[0;37m\n\n"; } #-- pause before next func/script sleep($PAUSE); echo "\n-------------------------------------------------------------------\n\n"; } else { echo "NO EXAMPLES found in doc, skipping"; } echo "\n"; } } #-- clean up if ($CLEAN) { unlink($tmp); } } #-- even more clean if ($MANY && $CLEAN) { @rmdir($tmpdir); } function emulated_functions($upgrade_php = "upgrade.php") { preg_match_all("/function[ ]+(?:up_)?([_\w\d]+)\s*\(/", file_get_contents($upgrade_php), $uu); return $uu[1]; } function php_interpreter() { $php = $_SERVER["argv"][1]; $php = trim(`which $php`); if (!$php) { die(__FILE__.": Given PHP interpreter not in your %PATH!\n"); } return $php; } function get_manual() { $dir = $_SERVER["argv"][2]; if (!is_dir($dir) || !file_exists("$dir/function.print.html")) { die(__FILE__.": PHP manual does not live under '$dir'.\n"); } return $dir; } function get_lynx() { ($html = `which w3m`) or ($html = `which lynx`); if (!($html = trim($html))) { die(__FILE__.": lynx or w3m required.\n"); } return $html; } function tmp() { global $MANY; $tmp = "/tmp/upgrade.php.doctest.tmp"; $tmpdir = $tmp; if ($MANY) { @unlink($tmpdir); @mkdir($tmpdir); } return $tmp; } #-- generate list of really emulated functions function simulated() { global $php; $simulated = `echo '' | $php -q`; $simulated = unserialize($simulated); return $simulated["internal"]; } function func2fn($func) { global $dir; $fn = "$dir/function.".strtr($func, "_", "-").".html"; if (file_exists($fn)) { return $fn; } } function example_scripts($func) { global $html; $fn = func2fn($func); $text = `$html -dump $fn`; preg_match_all("/<\?php(.+?)\?".">/ms", $text, $uu); return($uu[1]); } function add_output(&$scr) { #-- fix output-less scripts: find last assigned-to variable name if (!preg_match("/echo|print|var_dump/", $scr)) { if (preg_match('/^.+(\$[_\w\d\[\"\'\]]+)\s*=/s', $scr, $uu)) { $scr .= "\n\n#-- auto-added\nprint_r($uu[1]);\n"; } else { $scr .= "\n\n#-- this script gives no useful output, or does it?"; } } #-- fix compatibility to older PHP versions $scr = preg_replace('/(\s)private(\s\$)/', '$1var$2', $scr); } function up_version(&$scr, $func) { $scr = preg_replace("/$func/", "up_$func", $scr); } function print_script($scr) { global $i, $PAUSE; #-- output sample script text from doc if ($i) { echo "\n++++++++++++++++++++++++++++\n\n"; sleep($PAUSE); } echo "\033[1;30m\033[0;37m\n"; } ?>