Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 26 additions & 144 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
// xinclude_residua() done
// xml_partial_output
// xml_validate() done
// phd_acronym() done
// phd_sources() done
// phd_version() done
// php_history() done
// phd auxiliary files moved to php/phd (genphdfiles.php)

const RNG_SCHEMA_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'docbook' . DIRECTORY_SEPARATOR . 'docbook-5.2.1' . DIRECTORY_SEPARATOR . 'rng' . DIRECTORY_SEPARATOR;
const RNG_SCHEMA_FILE = RNG_SCHEMA_DIR . 'docbook.rng';
Expand Down Expand Up @@ -390,7 +387,7 @@ function find_xml_files($path) // {{{
break;

case 'history-file':
$ac['SOURCES_FILE'] = $v;
$ac['HISTORY_FILE'] = $v;
break;

case 'libxml-check':
Expand Down Expand Up @@ -1071,154 +1068,39 @@ function xml_validate_libxml( $dom )

CAT;

// All PhD stuff, after XML validation.
// PhD auxiliary files (version.xml, sources.xml, fileModHistory.php) are now
// generated by php/phd (genphdfiles.php), from the phd-conf.json handoff below.

phd_acronym();
php_history();
phd_sources();
phd_version();
phd_conf_json();

exit(0); // Finished successfully.



// TODO: Should this moved to github/php/phd?
// Any input/state can be serialized into doc-base/temp/phd-conf.json.

function phd_acronym()
{
}

function php_history()
{
global $ac;
if ($ac['HISTORY_FILE'] !== 'yes')
return;

echo 'PhD history:';

$lang_mod_file = (($ac['LANG'] !== 'en') ? ("{$ac['rootdir']}/{$ac['EN_DIR']}") : ("{$ac['rootdir']}/{$ac['LANGDIR']}")) . "/fileModHistory.php";
$doc_base_mod_file = __DIR__ . "/fileModHistory.php";

$history_file = null;
if (file_exists($lang_mod_file)) {
$history_file = include $lang_mod_file;
if (is_array($history_file)) {
echo ' copy,';
$isFileCopied = copy($lang_mod_file, $doc_base_mod_file);
echo $isFileCopied ? "" : " failed,";
} else {
echo " corrupted file '$lang_mod_file,'";
}
} else {
echo " not found,";
}

if (!is_array($history_file)) {
$history_file = [];
echo " creating empty,";
file_put_contents($doc_base_mod_file, "<?php\n\nreturn [];\n");
}
echo " done.\n";
}

function phd_sources()
// Serialize the state PhD needs to regenerate its auxiliary files
// (version.xml, sources.xml, fileModHistory.php) into doc-base/temp/phd-conf.json,
// so that generation can move out of configure.php into php/phd (genphdfiles.php).
function phd_conf_json()
{
global $ac;
if ($ac['SOURCES_FILE'] !== 'yes')
return;

echo 'PhD sources:';

echo ' reading,';
$source_map = array();
$en_dir = "{$ac['rootdir']}/{$ac['EN_DIR']}";
$source_langs = array(
array('base', $ac['srcdir'], array('manual.xml', 'funcindex.xml')),
array('en', $en_dir, find_xml_files($en_dir)),
$conf = array(
'rootdir' => $ac['rootdir'],
'srcdir' => $ac['srcdir'],
'lang' => $ac['LANG'],
'enDir' => $ac['EN_DIR'],
'langDir' => $ac['LANGDIR'],
'generate' => $ac['GENERATE'],
'xpointerReporting' => $ac['XPOINTER_REPORTING'] === 'yes',
'stderrToStdout' => $ac['STDERR_TO_STDOUT'] === 'yes',
'outputs' => array(
'version' => $ac['VERSION_FILES'] === 'yes',
'sources' => $ac['SOURCES_FILE'] === 'yes',
'history' => $ac['HISTORY_FILE'] === 'yes',
),
);
if ($ac['LANG'] !== 'en') {
$lang_dir = "{$ac['rootdir']}/{$ac['LANGDIR']}";
$source_langs[] = array($ac['LANG'], $lang_dir, find_xml_files($lang_dir));
}
foreach ($source_langs as list($source_lang, $source_dir, $source_files)) {
foreach ($source_files as $source_path) {
$source = file_get_contents("{$source_dir}/{$source_path}");
if (preg_match_all('/ xml:id=(["\'])([^"]+)\1/', $source, $matches)) {
foreach ($matches[2] as $xml_id) {
$source_map[$xml_id] = array(
'lang' => $source_lang,
'path' => $source_path,
);
}
}
}
}
asort($source_map);
echo ' transforming,';
$dom = new DOMDocument;
$dom->formatOutput = true;
$sources_elem = $dom->appendChild($dom->createElement("sources"));
foreach ($source_map as $id => $source) {
$el = $dom->createElement('item');
$el->setAttribute('id', $id);
$el->setAttribute('lang', $source["lang"]);
$el->setAttribute('path', $source["path"]);
$sources_elem->appendChild($el);
}
echo " saving,";
if ($dom->save($ac['srcdir'] . '/sources.xml')) {
echo " done.\n";
} else {
echo " fail!\n";
}
}

function phd_version()
{
global $ac;
if ($ac['VERSION_FILES'] !== 'yes')
return;

echo 'PhD version:';

$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;

$tmp = new DOMDocument;
$tmp->preserveWhiteSpace = false;

$versions = $dom->appendChild($dom->createElement("versions"));

echo ' reading,';
if ($ac["GENERATE"] != "no") {
$globdir = dirname($ac["GENERATE"]) . "/{../../}versions.xml";
}
else {
$globdir = $ac['rootdir'] . '/en';
$globdir .= "/*/*/versions.xml";
}
echo ' transforming,';
if (!defined('GLOB_BRACE')) {
define('GLOB_BRACE', 0);
}
foreach(glob($globdir, GLOB_BRACE) as $file) {
if($tmp->load($file)) {
foreach($tmp->getElementsByTagName("function") as $function) {
$function = $dom->importNode($function, true);
$versions->appendChild($function);
}
} else {
print_xml_errors();
errors_are_bad(1);
}
}
echo ' saving,';

if ($dom->save($ac['srcdir'] . '/version.xml')) {
echo " done.\n";
} else {
echo " fail!\n";
}
$path = __DIR__ . '/temp/phd-conf.json';
file_put_contents($path, json_encode($conf, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n");
}