Files
doc-gtk/scripts/gen_chapterents.php

71 lines
2.1 KiB
PHP

<?php
/**
* generates a "chapters.ent" file from the existing
* xml documentation files
*
* the chapters.ent is part of the manual DTD used for
* linking to the single xml files so that their contents
* can be accessed from within the xml tree
*/
function gen_ent($path, $file, $lang)
{
global $base_dir;
$relpath = substr($path . '/' . $file, strlen($base_dir));
$ent = preg_replace("%[\\/]%",".", preg_replace("%^(?:..[\\/])?en[\\/]((userguide|reference)[\\/])?(.*)\.xml$%",'\\3', substr($relpath, strlen($lang) + 1, -4)));
return "<!ENTITY $ent SYSTEM \"".preg_replace('%^(?:..[\\/])?en([\\/](userguide|reference)[\\/])?%', "$lang\\1", $relpath)."\">";
}//function gen_ent($path, $file, $lang)
function gen_dir_ents($path)
{
global $entities, $lang;
$dir_handle = opendir($path);
while ($file = readdir($dir_handle)) {
if (($file != "CVS") && ($file != ".cvsignore") && ($file != ".svn") && ($file != ".") && ($file != "..")) {
if (is_dir($path."/".$file)) {
gen_dir_ents($path."/".$file);
} else {
if (substr($file, -4) == ".xml") {
if ($lang != "UTF8dir/en" && file_exists(preg_replace("%^(..[\\/])?en(/?|$)%", "\\1".$lang."\\2", $path)."/".$file)) {
$entities[] = gen_ent($path, $file, $lang);
} else {
$entities[] = gen_ent($path, $file, "UTF8dir/en");
}
}
}
}
}
closedir($dir_handle);
}//function gen_dir_ents($path)
if ($GLOBALS['argc'] < 2 || strlen($GLOBALS['argv'][1]) != 2) {
die("\r\nError: Pass the desired language as only parameter\r\n");
}
$lang = $GLOBALS['argv'][1];
$entities = array();
if (!is_dir('manual/' . $lang)) {
die("\r\nPlease run configure from the top dir of php-gtk-doc checkout.\r\n");
}
$base_dir = 'manual/';
gen_dir_ents('manual/' . $lang);
sort($entities, SORT_STRING);
//write it into manual/$lang/chapters.ent
$chapfile = $base_dir . 'chapters.ent';
$hdl = fopen($chapfile, 'w+');
fwrite($hdl, "<!-- DO NOT EDIT THIS FILE! IT IS GENERATED AUTOMATICALLY BY gen_chapterents.php -->\r\n");
foreach ($entities as $val) {
fwrite($hdl, $val . "\r\n");
}
fclose($hdl);
echo 'wrote ' . count($entities) . ' entities into file ' . $chapfile . "\r\n";
?>