cvs: phpdoc / configure.php

From: Date: Thu, 24 Jan 2008 05:41:37 +0000
Subject: cvs: phpdoc / configure.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-1066@lists.php.net to get a copy of this message
gwynne Thu Jan 24 05:41:37 2008 UTC Modified files: /phpdoc configure.php Log: update to PEAR coding style, consolidate functions versus 'main'. suggested: function-ize further for clarity

http://cvs.php.net/viewvc.cgi/phpdoc/configure.php?r1=1.22&r2=1.23&diff_format=u Index: phpdoc/configure.php diff -u phpdoc/configure.php:1.22 phpdoc/configure.php:1.23 --- phpdoc/configure.php:1.22 Wed Jan 23 20:16:38 2008 +++ phpdoc/configure.php Thu Jan 24 05:41:37 2008 @@ -17,22 +17,182 @@ | Authors: Dave Barr <dave@php.net> | +----------------------------------------------------------------------+ - $Id: configure.php,v 1.22 2008/01/23 20:16:38 bjori Exp $ + $Id: configure.php,v 1.23 2008/01/24 05:41:37 gwynne Exp $ */ error_reporting(E_ALL); - -$srcdir = "."; -$cvs_id = '$Id: configure.php,v 1.22 2008/01/23 20:16:38 bjori Exp $'; +$cvs_id = '$Id: configure.php,v 1.23 2008/01/24 05:41:37 gwynne Exp $'; echo "configure.php: $cvs_id\n"; -// Settings +function usage() // {{{ +{ + global $acd; + + echo <<<HELPCHUNK +configure.php configures this package to adapt to many kinds of systems, and PhD +builds too. + +Usage: ./configure [OPTION]... + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + -V, --version display version information and exit + -q, --quiet, --silent do not print `checking...' messages + --srcdir=DIR find the sources in DIR [configure dir or `.'] + +Package-specific: + --enable-force-dom-save force .manual.xml to be saved in a full build even + if it fails validation [{$acd['FORCE_DOM_SAVE']}] + --enable-chm enable Windows HTML Help Edition pages [{$acd['CHMENABLED']}] + --enable-internals include internals documentation [{$acd['INTERNALSENABLED']}] + --with-php=PATH Path to php CLI executable [detect] + --with-phd=PATH Path to phd [detect] + --with-inipath=PATH Path to php.ini file [@srcdir@/scripts] + --with-lang=LANG Language to build [{$acd['LANG']}] + --with-partial=ID Root ID to build [{$acd['PARTIAL']}] + +HELPCHUNK; +} // }}} + +function checking($for) // {{{ +{ + global $ac; + + if ($ac['quiet'] != 'yes') { + echo "Checking {$for}... "; + flush( STDOUT ); + } +} // }}} + +function checkerror($msg) // {{{ +{ + global $ac; + + if ($ac['quiet'] != 'yes') { + echo "\n"; + } + echo "error: {$msg}\n"; + exit(1); +} // }}} + +function checkvalue($v) // {{{ +{ + global $ac; + + if ($ac['quiet'] != 'yes') { + echo "{$v}\n"; + } +} // }}} + +function abspath($path) // {{{ +{ + return function_exists('realpath' ? realpath($path) : $path); +} // }}} + +function quietechorun($e) // {{{ +{ + if ($GLOBALS['ac']['quiet'] != 'yes') { + echo "{$e}\n"; + } + passthru($e); +} // }}} + +function find_file($file_array) // {{{ +{ + $paths = explode(PATH_SEPARATOR, getenv('PATH')); + + if (is_array($paths)) { + foreach ($paths as $path) { + foreach ($file_array as $name) { + if (file_exists("{$path}/{$name}") && is_file("{$path}/{$name}")) { + return "{$path}/{$name}"; + } + } + } + } + + return ''; +} // }}} + +// Recursive glob() with a callback function {{{ +function globbetyglob($globber, $userfunc) +{ + foreach (glob("$globber/*") as $file) { + if (is_dir($file)) { + globbetyglob($file, $userfunc); + } else { + call_user_func($userfunc, $file); + } + } +} // }}} + +function find_dot_in($filename) // {{{ +{ + if (substr($filename, -3) == '.in') { + $GLOBALS['infiles'][] = $filename; + } +} // }}} + +function generate_output_file($in, $out, $ac) // {{{ +{ + $data = file_get_contents($in); + + if ($data === false) { + return false; + } + foreach ($ac as $k => $v) { + $data = preg_replace('/@' . preg_quote($k) . '@/', $v, $data); + } + + return file_put_contents($out, $data); +} // }}} + +function make_scripts_executable($filename) // {{{ +{ + if (substr($filename, -3) == '.sh') { + chmod($filename, 0755); + } +} // }}} + +// Loop through and print out all XML validation errors {{{ +function print_errors($errors, $die = true) { + $errors = libxml_get_errors(); + if ($errors) { + $valid = true; + foreach($errors as $err) { + // Skip all XInclude errors + if (!strpos($err->message, "include")) { + $valid = false; + + $file = file($err->file); + $line = rtrim($file[$err->line-1]); + $padding = str_repeat("-", $err->column) . "^"; + + printf("\nERROR (%s:%d)\n%s\n%s\n\t%s\n", $err->file, $err->line, $line, $padding, $err->message); + } + } + + if (!$valid && $die) { + echo "eyh man. No worries. Happ shittens. Try again after fixing the errors above\n"; + exit(1); + } + } + libxml_clear_errors(); +} // }}} + + +$srcdir = "."; + +// Settings {{{ $cygwin_php_bat = $srcdir .'/../phpdoc-tools/php.bat'; $cygwin_phd_bat = $srcdir .'/../phpdoc-tools/phd.bat'; $php_bin_names = array('php', 'php5', 'cli/php', 'php.exe', 'php5.exe', 'php-cli.exe', 'php-cgi.exe'); $phd_bin_names = array('phd', 'phd.exe'); $nsgmls_bin_names = array('nsgmls', 'onsgmls', 'nsgmls.exe', 'onsgmls.exe'); +// }}} // Reject old PHP installations {{{ if (phpversion() < 5) { @@ -44,7 +204,7 @@ echo "\n"; -$acd = array( +$acd = array( // {{{ 'srcdir' => $srcdir, 'quiet' => 'no', 'WORKDIR' => $srcdir, @@ -73,45 +233,14 @@ 'WINJADE' => '0', 'NSGMLS' => 'nsgmls', 'SP_OPTIONS' => 'SP_ENCODING=XML SP_CHARSET_FIXED=YES', -); +); // }}} $ac = $acd; -function usage() { - global $acd; - - echo <<<HELPCHUNK -configure.php configures this package to adapt to many kinds of systems, and PhD -builds too. - -Usage: ./configure [OPTION]... - -Defaults for the options are specified in brackets. - -Configuration: - -h, --help display this help and exit - -V, --version display version information and exit - -q, --quiet, --silent do not print `checking...' messages - --srcdir=DIR find the sources in DIR [configure dir or `.'] - -Package-specific: - --enable-force-dom-save force .manual.xml to be saved in a full build even - if it fails validation [{$acd['FORCE_DOM_SAVE']}] - --enable-chm enable Windows HTML Help Edition pages [{$acd['CHMENABLED']}] - --enable-internals include internals documentation [{$acd['INTERNALSENABLED']}] - --with-php=PATH Path to php CLI executable [detect] - --with-phd=PATH Path to phd [detect] - --with-inipath=PATH Path to php.ini file [@srcdir@/scripts] - --with-lang=LANG Language to build [{$acd['LANG']}] - --with-partial=ID Root ID to build [{$acd['PARTIAL']}] - -HELPCHUNK; -} - $srcdir_dependant_settings = array( 'INIPATH', 'LANGDIR' ); $overridden_settings = array(); -foreach ($_SERVER['argv'] as $opt) { +foreach ($_SERVER['argv'] as $opt) { // {{{ $parts = explode('=', $opt, 2); if (strncmp($opt, '--enable-', 9) == 0) { $o = substr($parts[0], 9); @@ -191,57 +320,7 @@ $ac['PARTIAL'] = $v; break; } -} - -function checking($for) { - global $ac; - - if ($ac['quiet'] != 'yes') { - echo "Checking {$for}... "; - flush( STDOUT ); - } -} -function checkerror($msg) { - global $ac; - - if ($ac['quiet'] != 'yes') { - echo "\n"; - } - echo "error: {$msg}\n"; - exit(1); -} -function checkvalue($v) { - global $ac; - - if ($ac['quiet'] != 'yes') { - echo "{$v}\n"; - } -} - -if (function_exists('realpath')) { - function abspath($path) { - return realpath($path); - } -} else { - function abspath($path) { - return $path; - } -} -function find_file($file_array) { - $paths = explode(PATH_SEPARATOR, getenv('PATH')); - - if (is_array($paths)) { - foreach ($paths as $path) { - foreach ($file_array as $name) { - if (file_exists("{$path}/{$name}") && is_file("{$path}/{$name}")) { - return "{$path}/{$name}"; - } - } - } - } - - return ''; -} +} // }}} checking('for source directory'); if (!file_exists($ac['srcdir']) || !is_dir($ac['srcdir']) || !is_writable($ac['srcdir'])) { @@ -266,8 +345,7 @@ checking("for PHP executable"); if ($ac['PHP'] == '' || $ac['PHP'] == 'no') { $ac['PHP'] = find_file($php_bin_names); -} -else if (file_exists($cygwin_php_bat)) { +} else if (file_exists($cygwin_php_bat)) { $ac['PHP'] = $cygwin_php_bat; } @@ -284,8 +362,7 @@ checking("for PHD executable"); if ($ac['PHD'] == '' || $ac['PHD'] == 'no') { $ac['PHD'] = find_file($phd_bin_names); -} -else if (file_exists($cygwin_phd_bat)) { +} else if (file_exists($cygwin_phd_bat)) { $ac['PHD'] = $cygwin_phd_bat; } @@ -310,8 +387,7 @@ checking("for language to build"); if ($ac['LANG'] == '' || $ac['LANG'] == 'no') { checkerror("Using '--with-lang=' or '--without-lang' is just going to cause trouble."); -} -if ($ac['LANG'] == 'yes') { +} else if ($ac['LANG'] == 'yes') { $ac['LANG'] = 'en'; } checkvalue($ac['LANG']); @@ -328,46 +404,10 @@ checking("for partial build"); checkvalue($ac['PARTIAL']); +// Do NOT add a commandline setting for this. We only support $ac[ 'NSGMLS' ] to +// keep missing-entities.php.in working. $ac['NSGMLS'] = abspath(find_file($nsgmls_bin_names)); -/* recursive glob() with a callback function */ -function globbetyglob($globber, $userfunc) { - foreach (glob("$globber/*") as $file) { - if (is_dir($file)) { - globbetyglob($file, $userfunc); - } - else { - call_user_func($userfunc, $file); - } - } -} - -function find_dot_in($filename) { // {{{ - if (substr($filename, -3) == '.in') { - $GLOBALS['infiles'][] = $filename; - } -} // }}} - -function generate_output_file($in, $out, $ac) { // {{{ - $data = file_get_contents($in); - - if ($data === false) { - return false; - } - - foreach ($ac as $k => $v) { - $data = preg_replace('/@' . preg_quote($k) . '@/', $v, $data); - } - - return file_put_contents($out, $data); -} // }}} - -function make_scripts_executable($filename) { // {{{ - if (substr($filename, -3) == '.sh') { - chmod($filename, 0755); - } -} // }}} - $infiles = array(); globbetyglob($ac['srcdir'], 'find_dot_in'); @@ -382,18 +422,10 @@ echo "generating $out: "; if (generate_output_file($in, $out, $ac)) { echo "done\n"; - } - else { + } else { echo "fail\n"; exit(117); } -} // }}} - -function quietechorun($e) { - if ($GLOBALS['ac']['quiet'] != 'yes') { - echo "{$e}\n"; - } - passthru($e); } globbetyglob("{$ac['srcdir']}/scripts", 'make_scripts_executable'); @@ -403,37 +435,10 @@ $redir = ($ac['quiet'] == 'yes') ? "> /dev/null" : ''; quietechorun("\"{$ac['PHP']}\" {$ini} -q \"{$ac['srcdir']}/scripts/file-entities.php\" {$redir}"); quietechorun("rm -f \"{$ac['srcdir']}/entities/missing*\""); -quietechorun("rm -f \"{$ac['srcdir']}/entities/missing-ids.xml\""); quietechorun("\"{$ac['PHP']}\" {$ini} -q \"{$ac['srcdir']}/scripts/missing-entities.php\" {$redir}"); libxml_use_internal_errors(true); -// Loop through and print out all XML validation errors {{{ -function print_errors($errors, $die = true) { - $errors = libxml_get_errors(); - if ($errors) { - $valid = true; - foreach($errors as $err) { - // Skip all XInclude errors - if (!strpos($err->message, "include")) { - $valid = false; - - $file = file($err->file); - $line = rtrim($file[$err->line-1]); - $padding = str_repeat("-", $err->column) . "^"; - - printf("\nERROR (%s:%d)\n%s\n%s\n\t%s\n", $err->file, $err->line, $line, $padding, $err->message); - } - } - - if (!$valid && $die) { - echo "eyh man. No worries. Happ shittens. Try again after fixing the errors above\n"; - exit(1); - } - } - libxml_clear_errors(); -} // }}} - $dom = new DOMDocument(); $die = $dom->load("manual.xml", LIBXML_DTDVALID|LIBXML_NOENT); @@ -494,3 +499,5 @@ exit(1); // Tell the shell that this script finished with an error. } } + +?>
« previous php.doc.cvs (#1066) next »