2828
2929echo "configure.php on PHP " . phpversion () . ", libxml " . LIBXML_DOTTED_VERSION . "\n\n" ;
3030
31- // gereral structure/ordeing for refactoring this code
31+ // general structure/ordering for refactoring this code
3232
3333// init_parse() // todo: argv parsing into a typed static class, remove all global
3434// init_check() // todo: move all checks in one place
4242// xinclude_xpointer() done
4343// xinclude_residua() done
4444// xml_partial_output
45- // xml_validation partial
45+ // xml_validate() done
4646// phd_acronym() done
4747// phd_sources() done
4848// phd_version() done
@@ -105,7 +105,7 @@ function realpain( string $path , bool $touch = false , bool $mkdir = false ) :
105105 // pain is real
106106
107107 // care for external XML tools (realpath() everywhere)
108- // care for Windows builds (foward slashes everywhere)
108+ // care for Windows builds (forward slashes everywhere)
109109 // avoid `cd` and chdir() like the plague
110110
111111 $ path = str_replace ( "\\" , '/ ' , $ path );
@@ -911,7 +911,7 @@ function xinclude_residual_fixup( DOMDocument $dom )
911911 echo "\n\n" ;
912912 }
913913
914- // Duplicated strucutral xml:ids are fatal on doc-en
914+ // Duplicated structural xml:ids are fatal on doc-en
915915
916916 $ fatal = $ GLOBALS ['ac ' ]['LANG ' ] == 'en ' ;
917917
@@ -975,36 +975,67 @@ function xinclude_residual_list( DOMDocument $dom ) : DOMNodeList
975975 exit (0 );
976976} // }}}
977977
978- echo " Validating temp/manual.xml... " ;
978+ xml_validate ( $ dom ) ;
979979
980- if ( $ dom-> relaxNGValidate ( RNG_SCHEMA_FILE ) )
980+ function xml_validate ( $ dom )
981981{
982- echo "done. \n" ;
983- }
984- else
985- {
986- echo "failed. " ;
982+ // libxml2's RelaxNG validation shows quadratic to cubic behavior in some cases.
987983
988- // First, tries to use Jing, that has better error reporting than libxml, because:
989984 // > As it stands, libxml2's Relax NG validator doesn't seem suitable for production.
990985 // -- https://gitlab.gnome.org/GNOME/libxml2/-/issues/448
991986
987+ // Jing is faster, but depends on Java.
988+
992989 $ out = null ;
993990 $ ret = null ;
994991 exec ( "java -version 2>&1 " , $ out , $ ret );
995992
993+ if ( $ ret == 0 )
994+ xml_validate_jing ();
995+ else
996+ xml_validate_libxml ( $ dom );
997+ }
998+
999+ function xml_validate_jing ()
1000+ {
1001+ global $ srcdir ; // TODO, static typed field on Conf class
1002+ global $ idempath ; // TODO, static typed field on Conf class
1003+
1004+ echo "Validating temp/manual.xml (jing)... " ;
1005+
1006+ $ out = null ;
1007+ $ ret = null ;
1008+ $ schema = RNG_SCHEMA_FILE ;
1009+ $ cmdJing = "java -jar {$ srcdir }/docbook/jing.jar {$ schema } {$ idempath }" ;
1010+ exec ( $ cmdJing , $ out , $ ret );
1011+
9961012 if ( $ ret == 0 )
9971013 {
998- echo "Issues (jing): \n" ;
999- $ schema = RNG_SCHEMA_FILE ;
1000- $ cmdJing = "java -jar {$ srcdir }/docbook/jing.jar {$ schema } {$ idempath }" ;
1001- passthru ( $ cmdJing );
1014+ echo "done. \n" ;
1015+ return ;
1016+ }
1017+
1018+ echo "failed. \n" ;
1019+ if ( is_array ( $ out ) )
1020+ foreach ( $ out as $ line )
1021+ echo "$ line \n" ;
1022+
1023+ errors_are_bad ( 1 );
1024+ }
1025+
1026+ function xml_validate_libxml ( $ dom )
1027+ {
1028+ echo "Validating temp/manual.xml (libxml)... " ;
1029+
1030+ if ( $ dom ->relaxNGValidate ( RNG_SCHEMA_FILE ) )
1031+ {
1032+ echo "done. \n" ;
10021033 }
10031034 else
10041035 {
1005- echo "Issues (libxml): \n" ;
1036+ echo "failed. \n" ;
10061037 print_xml_errors ();
1007- errors_are_bad (1 );
1038+ errors_are_bad ( 1 );
10081039 }
10091040}
10101041
@@ -1029,15 +1060,11 @@ function xinclude_residual_list( DOMDocument $dom ) : DOMNodeList
10291060
10301061// All PhD stuff, after XML validation.
10311062
1032- echo "PhD scripts started. \n" ;
1033-
10341063phd_acronym ();
10351064php_history ();
10361065phd_sources ();
10371066phd_version ();
10381067
1039- echo "PhD scripts completed. \n" ;
1040-
10411068exit (0 ); // Finished successfully.
10421069
10431070
0 commit comments