File: missing-entities.php.in

package info (click to toggle)
php-doc 20061001-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 45,764 kB
  • ctags: 1,611
  • sloc: xml: 502,485; php: 7,645; cpp: 500; makefile: 297; perl: 161; sh: 141; awk: 28
file content (156 lines) | stat: -rw-r--r-- 5,113 bytes parent folder | download
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
151
152
153
154
155
156
<?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.24 2006/01/14 22:02:30 tony2001 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
$windows = (strpos(PHP_OS, 'WIN') !== false);

// If PHP wasn't compiled on Cygwin, then the path to NSGMLS (if it is
// *nix path in case NSGMLS is installed via Cygwin setup) should be
// fixed for exec command to work
if ($windows 
    && (strpos(php_uname(), 'CYGWIN') === false)
    && (strncmp($NSGMLS, "/usr/bin/", 9) === 0)) 
{
    $cygbin = trim(`cygpath -d /usr/bin/`);
    $NSGMLS = preg_replace('!^/usr/bin/!', $cygbin, $NSGMLS) . '.exe';
}

// '..' components are not allowed in exec path to executable
$NSGMLS = realpath($NSGMLS);


// Execute a test of the manual
$envy = explode(" ", "@SP_OPTIONS@");
array_map('putenv', $envy);
exec(
    "$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) {
         preg_match('!(?<=ID.)".+"!', $line, $id);
        $missing_ids[] = "<para id=" . $id[0] . " xreflabel=" .  $id[0]  . "></para>\n";
        $missing_ids_display[] = "id=" .  $id[0] . "\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);

// missing ids for display
$missing_ids_display=isset($missing_ids_display) ? array_unique($missing_ids_display) : array();
sort($missing_ids_display);

// 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: entities/missing-ids.xml\n";
if (!empty($missing_ids_display)) {
    foreach ($missing_ids_display as $k => $v) {
        echo "* " . preg_replace('@[\s]+@', ' ', $v) . "\n";
    }
} else {
    echo "* No missing ids found\n";
}

?>