-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathtest_missing-entities.php.in
More file actions
189 lines (144 loc) · 5.63 KB
/
test_missing-entities.php.in
File metadata and controls
189 lines (144 loc) · 5.63 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/*
+----------------------------------------------------------------------+
| Copyright (c) 1997-2023 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 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: |
| https://www.php.net/license/3_01.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> |
+----------------------------------------------------------------------+
$Id$
*/
/*
ATTENTION: don't use this script!!!
its only meant to test the creation of missings
together with xmllint.
For testing you must change following lines from manual.xml.in
<!-- Autogenerated missing entites and IDs to make build work -->
<!ENTITY % missing-entities SYSTEM "entities/missing-entities.ent">
%missing-entities;
<!ENTITY missing-ids SYSTEM "entities/missing-ids.xml">
]>
to:
<!-- Autogenerated missing entites and IDs to make build work -->
<!ENTITY % missing-entities SYSTEM "entities/test_missing-entities.ent">
%missing-entities;
<!ENTITY missing-ids SYSTEM "entities/test_missing-ids.xml">
]>
The results are _only_ usefull, if all entities are valid,
this means any entitie must have the trailing ;
*/
##########################
# Function declacarions #
##########################
function test_manual ($XMLLINT) {
// Execute a test of the manual
exec(
"$XMLLINT --noout --noent --valid manual.xml 2>&1",
$results,
$retcode
);
return $results;
} // end test_manual
function catch_output ($results, $what="") {
// catch the output from xmllint
$missings = array();
switch ($what) {
case "entities":
foreach ($results as $line) {
// missing entitiy found, replace each with "???"
if (strpos($line, "not defined") !== FALSE) {
$line = preg_replace('!^.[^\']*\'!', '<!ENTITY ', $line);
$line = preg_replace('!\'.*!', ' "???">', $line);
$missings[] = $line;
}
}
break;
case "ids":
foreach ($results as $line) {
// missing ID found
if (strpos($line, "an unknown ID") !== FALSE) {
$missings[] = preg_replace("!^.* ID !", " <para id=", $line) . "></para>\n";
}
}
break;
}
// Sort elements (just to make handwork easier, if needed)
$missings = array_unique($missings);
sort($missings);
return $missings;
} // catch_output
function write_file ($missings, $what="") {
// Try to open file for rewriting
if ($what === "entities") {
$handle = fopen(MISSING_ENT, "w");
// Exit if we cannot rewrite the files
if (!$handle) {
exit ("ERROR: Cannot open ".MISSING_ENT." for writing\n");
}
// Write out XML declaration
fwrite($handle, XML_DECL);
// Write out missings to file
foreach ($missings as $ent) {
fwrite($handle, $ent."\n");
}
fclose($handle);
// print out success info
echo MISSING_ENT." created\n";
}
if ($what === "ids") {
$handle = fopen(MISSING_ID, "w");
// Exit if we cannot rewrite the files
if (!$handle) {
exit ("ERROR: Cannot open ".MISSING_ID." for writing\n");
}
// Write out XML declaration and appendix part
fwrite($handle, XML_DECL);
fwrite($handle, APPENDIX_START);
foreach ($missings as $idpara) {
fwrite($handle, $idpara);
}
fwrite($handle, APPENDIX_END);
fclose($handle);
// print out success info
echo MISSING_ID." created\n";
}
} //end write_file
######################################################################
# #
# main part #
# #
######################################################################
// define some constants
define ('XML_DECL', "<" . "?xml version='1.0' encoding='iso-8859-1'?>\n\n");
define ('APPENDIX_START', "<appendix id=\"missing-stuff\"><title>&MissingStuff;</title>\n");
define ('APPENDIX_END', "</appendix>\n");
define ('MISSING_ENT', "entities/test_missing-entities.ent");
define ('MISSING_ID', "entities/test_missing-ids.xml");
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
$wrkdir = getcwd();
if (strpos($wrkdir, "scripts") !== FALSE) {
chdir("..");
}
$XMLLINT = "@XMLLINT@";
// Support for Windows systems
if (substr(PHP_OS, 0, 3) == 'WIN') {
$XMLLINT = str_replace("/", "\\", "$XMLLINT");
}
$results = test_manual($XMLLINT);
$missings = catch_output ($results,"entities");
write_file ($missings, "entities");
unset ($results, $missings);
$results = test_manual($XMLLINT);
$missings = catch_output ($results,"ids");
write_file ($missings, "ids");
?>