|
19 | 19 | +----------------------------------------------------------------------+
|
20 | 20 | */
|
21 | 21 |
|
22 |
| -error_reporting(-1); |
23 |
| -$cvs_id = '$Id$'; |
| 22 | +ini_set( 'display_errors' , 1 ); |
| 23 | +ini_set( 'display_startup_errors' , 1 ); |
| 24 | +error_reporting( E_ALL ); |
| 25 | +ob_implicit_flush(); |
24 | 26 |
|
25 |
| -echo "configure.php: $cvs_id\n"; |
| 27 | +echo "configure.php on PHP " . phpversion() . "\n\n"; |
26 | 28 |
|
27 | 29 | const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-v5.2-os' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR;
|
28 | 30 | const RNG_SCHEMA_FILE = RNG_SCHEMA_DIR . 'docbook.rng';
|
@@ -101,7 +103,6 @@ function checking($for) // {{{
|
101 | 103 |
|
102 | 104 | if ($ac['quiet'] != 'yes') {
|
103 | 105 | echo "Checking {$for}... ";
|
104 |
| - flush(); |
105 | 106 | }
|
106 | 107 | } // }}}
|
107 | 108 |
|
@@ -191,40 +192,44 @@ function make_scripts_executable($filename) // {{{
|
191 | 192 | }
|
192 | 193 | } // }}}
|
193 | 194 |
|
194 |
| -// Loop through and print out all XML validation errors {{{ |
195 |
| -function print_xml_errors($details = true) { |
| 195 | +function print_xml_errors() |
| 196 | +{ |
196 | 197 | global $ac;
|
| 198 | + $report = $ac['LANG'] == 'en' || $ac['XPOINTER_REPORTING'] == 'yes'; |
| 199 | + $output = ( $ac['STDERR_TO_STDOUT'] == 'yes' ) ? STDOUT : STDERR ; |
| 200 | + |
197 | 201 | $errors = libxml_get_errors();
|
198 |
| - $output = ( $ac['STDERR_TO_STDOUT'] == 'yes' ) ? STDOUT : STDERR; |
199 |
| - if ($errors && count($errors) > 0) { |
200 |
| - foreach($errors as $err) { |
201 |
| - if ($ac['LANG'] != 'en' && // translations |
202 |
| - $ac['XPOINTER_REPORTING'] != 'yes' && // can disable |
203 |
| - strncmp($err->message, 'XPointer evaluation failed:', 27) == 0) { |
204 |
| - continue; |
205 |
| - } |
206 |
| - $errmsg = wordwrap(" " . trim($err->message), 80, "\n "); |
207 |
| - if ($details && $err->file) { |
208 |
| - $file = file(urldecode($err->file)); // libxml appears to urlencode() its errors strings |
209 |
| - if (isset($file[$err->line])) { |
210 |
| - $line = rtrim($file[$err->line - 1]); |
211 |
| - $padding = str_repeat("-", $err->column) . "^"; |
212 |
| - fprintf($output, "\nERROR (%s:%s:%s)\n%s\n%s\n%s\n", $err->file, $err->line, $err->column, $line, $padding, $errmsg); |
213 |
| - } else { |
214 |
| - fprintf($output, "\nERROR (%s:unknown)\n%s\n", $err->file, $errmsg); |
215 |
| - } |
216 |
| - } else { |
217 |
| - fprintf($output, "%s\n", $errmsg); |
218 |
| - } |
219 |
| - // Error too severe, stopping |
220 |
| - if ($err->level === LIBXML_ERR_FATAL) { |
221 |
| - fprintf($output, "\n\nPrevious errors too severe. Stopping here.\n\n"); |
222 |
| - break; |
223 |
| - } |
224 |
| - } |
225 |
| - } |
226 | 202 | libxml_clear_errors();
|
227 |
| -} // }}} |
| 203 | + |
| 204 | + $filePrefix = "file:///"; |
| 205 | + $tempPrefix = realpath( __DIR__ . "/temp" ) . "/"; |
| 206 | + $rootPrefix = realpath( __DIR__ . "/.." ) . "/"; |
| 207 | + |
| 208 | + if ( count( $errors ) > 0 ) |
| 209 | + fprintf( $output , "\n" ); |
| 210 | + |
| 211 | + foreach( $errors as $error ) |
| 212 | + { |
| 213 | + $mssg = rtrim( $error->message ); |
| 214 | + $file = $error->file; |
| 215 | + $line = $error->line; |
| 216 | + $clmn = $error->column; |
| 217 | + |
| 218 | + if ( str_starts_with( $mssg , 'XPointer evaluation failed:' ) && ! $report ) |
| 219 | + continue; // Translations can omit these, to focus on fatal errors |
| 220 | + |
| 221 | + if ( str_starts_with( $file , $filePrefix ) ) |
| 222 | + $file = substr( $file , strlen( $filePrefix ) ); |
| 223 | + if ( str_starts_with( $file , $tempPrefix ) ) |
| 224 | + $file = substr( $file , strlen( $tempPrefix ) ); |
| 225 | + if ( str_starts_with( $file , $rootPrefix ) ) |
| 226 | + $file = substr( $file , strlen( $rootPrefix ) ); |
| 227 | + |
| 228 | + $prefix = $error->level === LIBXML_ERR_FATAL ? "FATAL" : "error"; |
| 229 | + |
| 230 | + fwrite( $output , "[$prefix $file {$line}:{$clmn}] {$mssg}\n" ); |
| 231 | + } |
| 232 | +} |
228 | 233 |
|
229 | 234 | function find_xml_files($path) // {{{
|
230 | 235 | {
|
@@ -351,16 +356,6 @@ function getFileModificationHistory(): array {
|
351 | 356 | $php_bin_names = array('php', 'php5', 'cli/php', 'php.exe', 'php5.exe', 'php-cli.exe', 'php-cgi.exe');
|
352 | 357 | // }}}
|
353 | 358 |
|
354 |
| -// Reject old PHP installations {{{ |
355 |
| -if (phpversion() < 5) { |
356 |
| - echo "PHP 5 or above is required. Version detected: " . phpversion() . "\n"; |
357 |
| - exit(100); |
358 |
| -} else { |
359 |
| - echo "PHP version: " . phpversion() . "\n"; |
360 |
| -} // }}} |
361 |
| - |
362 |
| -echo "\n"; |
363 |
| - |
364 | 359 | $acd = array( // {{{
|
365 | 360 | 'srcdir' => $srcdir,
|
366 | 361 | 'basedir' => $basedir,
|
@@ -676,10 +671,6 @@ function getFileModificationHistory(): array {
|
676 | 671 | libxml_use_internal_errors(true);
|
677 | 672 | }
|
678 | 673 |
|
679 |
| -$compact = defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0; |
680 |
| -$big_lines = defined('LIBXML_BIGLINES') ? LIBXML_BIGLINES : 0; |
681 |
| -$LIBXML_OPTS = LIBXML_NOENT | $big_lines | $compact; |
682 |
| - |
683 | 674 | if ($ac['VERSION_FILES'] === 'yes') {
|
684 | 675 | $dom = new DOMDocument;
|
685 | 676 | $dom->preserveWhiteSpace = false;
|
@@ -777,22 +768,39 @@ function getFileModificationHistory(): array {
|
777 | 768 | checking('whether to save an invalid .manual.xml');
|
778 | 769 | checkvalue($ac['FORCE_DOM_SAVE']);
|
779 | 770 |
|
780 |
| -echo "Loading and parsing {$ac["INPUT_FILENAME"]}... "; |
781 |
| -flush(); |
782 | 771 |
|
783 | 772 | $dom = new DOMDocument();
|
784 | 773 |
|
785 |
| -// realpath() is important: omitting it causes severe performance degradation |
786 |
| -// and doubled memory usage on Windows. |
787 |
| -$didLoad = $dom->load(realpath("{$ac['srcdir']}/{$ac["INPUT_FILENAME"]}"), $LIBXML_OPTS); |
| 774 | +function dom_load( DOMDocument $dom , string $filename ) : bool |
| 775 | +{ |
| 776 | + $filename = realpath( $filename ); |
| 777 | + $options = LIBXML_NOENT | LIBXML_COMPACT | LIBXML_BIGLINES | LIBXML_PARSEHUGE; |
| 778 | + return $dom->load( $filename , $options ); |
| 779 | +} |
| 780 | + |
| 781 | +function dom_saveload( DOMDocument $dom , string $filename = "" ) |
| 782 | +{ |
| 783 | + if ( $filename == "" ) |
| 784 | + $filename = __DIR__ . "/temp/manual.xml"; |
| 785 | + |
| 786 | + $dom->save( $filename ); |
| 787 | + dom_load( $dom , $filename ); |
| 788 | +} |
788 | 789 |
|
789 |
| -// Check if the XML was simply broken, if so then just bail out |
790 |
| -if ($didLoad === false) { |
| 790 | +echo "Loading and parsing {$ac["INPUT_FILENAME"]}... "; |
| 791 | + |
| 792 | +if ( dom_load( $dom , "{$ac['srcdir']}/{$ac["INPUT_FILENAME"]}" ) ) |
| 793 | +{ |
| 794 | + dom_saveload( $dom ); // correct file/line/column on error messages |
| 795 | + echo "done.\n"; |
| 796 | +} |
| 797 | +else |
| 798 | +{ |
791 | 799 | echo "failed.\n";
|
792 | 800 | print_xml_errors();
|
793 | 801 | errors_are_bad(1);
|
794 | 802 | }
|
795 |
| -echo "done.\n"; |
| 803 | + |
796 | 804 |
|
797 | 805 | echo "Running XInclude/XPointer... ";
|
798 | 806 | $total = 0;
|
@@ -892,7 +900,7 @@ function getFileModificationHistory(): array {
|
892 | 900 | }
|
893 | 901 |
|
894 | 902 | echo "Validating {$ac["INPUT_FILENAME"]}... ";
|
895 |
| -flush(); |
| 903 | + |
896 | 904 | if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{
|
897 | 905 | $dom->relaxNGValidate(RNG_SCHEMA_FILE); // we don't care if the validation works or not
|
898 | 906 | $node = $dom->getElementById($ac['PARTIAL']);
|
@@ -934,15 +942,11 @@ function getFileModificationHistory(): array {
|
934 | 942 | $mxml = $ac["OUTPUT_FILENAME"];
|
935 | 943 |
|
936 | 944 | /* TODO: For some reason libxml does not validate the RelaxNG schema unless reloading the document in full */
|
937 |
| -$dom->save($mxml); |
938 |
| -$dom->load($mxml, $LIBXML_OPTS); |
| 945 | +dom_saveload( $dom ); // idempotent path |
| 946 | +$dom->save($mxml); // non idempotent, historical path |
939 | 947 | if ($dom->relaxNGValidate(RNG_SCHEMA_FILE)) {
|
940 | 948 | echo "done.\n";
|
941 |
| - printf("\nAll good. Saving %s... ", basename($ac["OUTPUT_FILENAME"])); |
942 |
| - flush(); |
943 |
| - $dom->save($mxml); |
944 |
| - |
945 |
| - echo "done.\n"; |
| 949 | + printf("\nAll good. Saved %s\n", basename($ac["OUTPUT_FILENAME"])); |
946 | 950 | echo "All you have to do now is run 'phd -d {$mxml}'\n";
|
947 | 951 | echo "If the script hangs here, you can abort with ^C.\n";
|
948 | 952 | echo <<<CAT
|
|
0 commit comments