1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
<?php
/*
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2004 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Hartmut Holzgraefe <hholzgra@php.net> |
| Gabor Hojtsy <goba@php.net> |
+----------------------------------------------------------------------+
$Id: missing-entities.php.in,v 1.17 2005/02/09 23:46:00 hholzgra Exp $
*/
set_time_limit(0);
// Print out info for the viewer and log files
echo "\nTesting the manual for missing elements...\n";
// If we are in a scripts dir, go one dir up
// (because the NSGMLS path is relative to that directory!)
$wrkdir = getcwd();
if (strpos($wrkdir, "scripts") !== FALSE) {
chdir("..");
}
$NSGMLS = "@NSGMLS@";
$NSGMLS_OUTPUT = "missing-entities.out";
// Support for Windows systems
if (substr(PHP_OS, 0, 3) == 'WIN') {
$NSGMLS = str_replace("/", "\\", "$NSGMLS");
}
// Execute a test of the manual
if("@SP_OPTIONS@" == "" || substr(PHP_OS, 0, 3) == 'WIN') {
exec(
"$NSGMLS -f $NSGMLS_OUTPUT -i lang-@LANG@ -D . " .
"-s @SRCDIR@/dtds/dbxml-4.1.2/phpdocxml.dcl manual.xml"
);
}
else {
exec(
"@SP_OPTIONS@ $NSGMLS -f $NSGMLS_OUTPUT -i lang-@LANG@ -D . " .
"-s @SRCDIR@/dtds/dbxml-4.1.2/phpdocxml.dcl manual.xml"
);
}
// Try to open files for rewriting
$ment = fopen("entities/missing-entities.ent", "w");
$mids = fopen("entities/missing-ids.xml", "w");
// Exit if we cannot rewrite the files
if (!$ment || !$mids) {
die("ERROR: Cannot open files for writing\n");
}
// Write out XML declaration
fwrite($ment, "<" . "?xml version='1.0' encoding='iso-8859-1'?>\n\n");
fwrite($mids, "<" . "?xml version='1.0' encoding='iso-8859-1'?>\n\n");
// Initalize arrays
$missing_ids = array();
$missing_entities = array();
// Open output file
$results = file($NSGMLS_OUTPUT);
// Try to find missing IDs and entities
foreach ($results as $line) {
trim($line);
// missing entity found
if (strpos($line, "not defined") !== FALSE) {
$line = preg_replace('!^.[^"]*"!', '<!ENTITY ', $line);
$line = preg_replace('!".*!', ' "???">', $line);
$missing_entities[] = $line;
}
// missing ID found
else if (strpos($line, "non-existent") !== FALSE) {
$missing_ids[] = preg_replace("!^.* ID !", " <para id=", $line) . "></para>\n";
}
}
// Find unique elements (one error message can occur several times)
$missing_ids = array_unique($missing_ids);
$missing_entities = array_unique($missing_entities);
// Sort elements (just to make handwork easier, if needed)
sort($missing_ids);
sort($missing_entities);
// Write out missing entities to file
foreach ($missing_entities as $ent) {
fwrite($ment, $ent);
}
// That's all for missing entities
fclose($ment);
// If we have missing IDs, write them out as an appendix
if (count($missing_ids) > 0) {
fwrite($mids, "<appendix id=\"missing-stuff\"><title>&MissingStuff;</title>\n");
foreach ($missing_ids as $idpara) {
fwrite($mids, $idpara);
}
fwrite($mids, "</appendix>\n");
}
// That's all for missing IDs
fclose($mids);
// print out success info
echo "\nCreated file: entities/missing-entities.ent\n";
if (!empty($missing_entities)) {
foreach ($missing_entities as $k => $v) {
echo "* " . preg_replace('@[\s]+@', ' ', $v) . "\n";
}
} else {
echo "* No missing entities were found\n";
}
echo "\nCreated file: @LANGDIR@/missing-ids.xml\n";
if (!empty($missing_ids)) {
foreach ($missing_ids as $k => $v) {
if (false !== strpos('<para id="zend"', $v)) {
echo "* " . preg_replace('@[\s]+@', ' ', $v) . "\n";
} else {
echo "* Zend id is missing. (Don't worry about this)\n";
if (count($missing_ids) === 1) {
echo "* No other missing ids were found\n";
}
}
}
} else {
echo "* No missing ids found\n";
}
?>
|