From 9d68f540973dd6721a6ea281e710ae7518116bc0 Mon Sep 17 00:00:00 2001 From: alfsb Date: Tue, 3 Dec 2024 07:38:01 -0300 Subject: [PATCH] Recursive XInclude support and some automatix fixups for translations (#194) --- configure.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/configure.php b/configure.php index 35b34eba4..fa26ad285 100755 --- a/configure.php +++ b/configure.php @@ -775,13 +775,28 @@ function getFileModificationHistory(): array { echo "done.\n"; echo "Running XInclude/XPointer... "; -$status = $dom->xinclude(); -if ($status === -1) { +$total = 0; +$maxrun = 10; //LIBXML_VERSION >= 21100 ? 1 : 10; +for( $run = 0 ; $run < $maxrun ; $run++ ) +{ + if ( $run > 0 ) + echo "$run "; + libxml_clear_errors(); + $status = (int) $dom->xinclude(); + if ( $status <= 0 ) + break; + $total += $status; + if ( $maxrun > 1 && $run + 1 >= $maxrun ) + { + echo "Recursive XInclude is too deep.\n"; + errors_are_bad(-1); + } +} + +if ($total == 0) { echo "failed.\n"; } else { - /* For some dumb reason when no substitution are made it returns false instead of 0... */ - $status = (int) $status; - echo "done. Performed $status XIncludes\n"; + echo "done. Performed $total XIncludes.\n"; } flush(); @@ -799,6 +814,38 @@ function getFileModificationHistory(): array { } } +{ # Automatic xi:include / xi:fallback fixups + + $xpath = new DOMXPath( $dom ); + $nodes = $xpath->query( "//*[local-name()='include']" ); + foreach( $nodes as $node ) + { + $fixup = null; + $parent = $node->parentNode; + $tagName = $parent->nodeName; + switch( $tagName ) + { + case "refentry": + $fixup = ""; + break; + case "refsect1": + $fixup = ""; + break; + default: + echo "Unknown parent element, validation may fail: $tagName\n"; + continue 2; + } + if ( $fixup != "" ) + { + $other = new DOMDocument( '1.0' , 'utf8' ); + $other->loadXML( $fixup ); + $insert = $dom->importNode( $other->documentElement , true ); + $node->parentNode->insertBefore( $insert , $node ); + } + $node->parentNode->removeChild( $node ); + } +} + echo "Validating {$ac["INPUT_FILENAME"]}... "; flush(); if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{