17
17
18
18
# Description
19
19
20
- This script creates various "file entities", that is, antities and files
21
- that define DTD <!ENTITY name SYSTEM 'path'> , named and composed of:
20
+ This script creates various "file entities", that is, DTD entities that
21
+ point to files and file listings , named and composed of:
22
22
23
23
- dir.dir.file : pulls in a dir/dir/file.xml file
24
- - dir.dif.entities.dir : pulls in a entity list for dir/dir/dir/*.xml
24
+ - dir.dif.entities.dir : pulls in all files of dir/dir/dir/*.xml
25
25
26
26
In the original file-entities.php.in, the files are created at:
27
27
44
44
so it would be possible to detect accidental overwriting of structural
45
45
entities, the "list of entities" moved to/as normal entity text. PS: This
46
46
will NOT work, with libxml recusing to load .manuxal.xml.in because of an
47
- "Detected an entity reference loop", that does not exist. Sigh.
47
+ "Detected an entity reference loop", that does not exist. Sigh. PPS: May
48
+ be possible with LIBXML_PARSEHUGE after all.
48
49
49
50
*/
50
51
60
61
61
62
// Usage
62
63
63
- $ root = realpath ( __DIR__ . "/../.. " );
64
+ $ root = realpain ( __DIR__ . "/../.. " );
64
65
$ lang = "" ;
65
66
$ chmonly = false ;
66
67
$ debug = false ;
93
94
if ( $ lang != "" )
94
95
generate_file_entities ( $ root , $ lang );
95
96
96
- pushEntity ( "global.function-index " , path: realpath ( __DIR__ . "/.. " ) . "/funcindex.xml " );
97
+ // TODO BACKPORT: Fixed relative path, move this directly into manual.xml.in
98
+ pushEntity ( "global.function-index " , path: realpain ( __DIR__ . "/.. " ) . "/funcindex.xml " );
97
99
98
100
if ( ! $ chmonly )
99
101
foreach ( $ entities as $ ent )
100
102
if ( str_starts_with ( $ ent ->name , "chmonly. " ) )
101
103
$ ent ->path = '' ;
102
104
103
- $ outfile = __DIR__ . "/../temp/file-entities.ent " ;
104
- touch ( $ outfile );
105
- $ outfile = realpath ( $ outfile );
105
+ $ outfile = realpain ( __DIR__ . "/../temp/file-entities.ent " , touch: true );
106
106
107
107
$ file = fopen ( $ outfile , "w " );
108
108
if ( ! $ file )
@@ -149,48 +149,12 @@ function pushEntity( string $name , string $text = '' , string $path = '' )
149
149
echo "Something went wrong on file-entities.php. \n" ;
150
150
exit (-1 );
151
151
}
152
-
153
- if ( DIRECTORY_SEPARATOR == '/ ' )
154
- return ;
155
-
156
- // While https://github.com/php/doc-en/pull/4288 is not
157
- // replicated on on all languages, let's sleeping dogs lies
158
-
159
- $ marks = ['! ' ,'@ ' ,'# ' ];
160
- $ parts = explode ( '. ' , $ name );
161
- foreach ( $ parts as & $ part )
162
- if ( strtolower ( $ part ) == 'pdo ' )
163
- $ part = array_shift ( $ marks );
164
-
165
- $ mixin = implode ( '. ' , $ parts );
166
- $ l1 = ['pdo ' ,'PDO ' ];
167
- $ l2 = ['pdo ' ,'PDO ' ];
168
- $ l3 = ['pdo ' ,'PDO ' ];
169
-
170
- if ( str_contains ( $ mixin , '! ' ) )
171
- {
172
- //echo "\n\n$mixin\n";
173
- foreach ( $ l1 as $ s1 )
174
- foreach ( $ l2 as $ s2 )
175
- foreach ( $ l3 as $ s3 )
176
- {
177
- $ tmp = $ mixin ;
178
- $ tmp = str_replace ( '! ' , $ s1 , $ tmp );
179
- $ tmp = str_replace ( '@ ' , $ s2 , $ tmp );
180
- $ tmp = str_replace ( '# ' , $ s3 , $ tmp );
181
- //echo "$tmp\n";
182
-
183
- $ ent = new Entity ( $ tmp , $ text , $ path );
184
- $ entities [ $ tmp ] = $ ent ;
185
- }
186
- //echo "\n";
187
- }
188
152
}
189
153
190
154
function generate_file_entities ( string $ root , string $ lang )
191
155
{
192
156
$ path = "$ root/ $ lang " ;
193
- $ test = realpath ( $ path );
157
+ $ test = realpain ( $ path );
194
158
if ( $ test === false || is_dir ( $ path ) == false )
195
159
{
196
160
echo "Language directory not found: $ path \n. " ;
@@ -242,7 +206,7 @@ function file_entities_recurse( string $langroot , array $dirs )
242
206
function generate_list_entities ( string $ root , string $ lang )
243
207
{
244
208
$ path = "$ root/ $ lang " ;
245
- $ test = realpath ( $ path );
209
+ $ test = realpain ( $ path );
246
210
if ( $ test === false || is_dir ( $ path ) == false )
247
211
{
248
212
echo "Language directory not found: $ path \n. " ;
@@ -292,26 +256,6 @@ function list_entities_recurse( string $root , array $dirs )
292
256
}
293
257
ksort ( $ list );
294
258
295
- // The entity file names collected on
296
- //
297
- // doc-lang/reference/apache/functions
298
- //
299
- // generate an entity named
300
- //
301
- // reference.apache.ENTITIES.functions
302
- //
303
- // that is saved on parent directory, with filename
304
- //
305
- // doc-lang/reference/apache/ENTITIES.functions.xml
306
- //
307
- // new style has the files saved as
308
- //
309
- // doc-base/temp/file-entities.reference.apache.functions.ent
310
- //
311
- // and in a far future, may only outputs: (see doc-base PR 183)
312
- //
313
- // doc-base/temp/file-entities.xml
314
-
315
259
$ copy = $ dirs ;
316
260
$ last = array_pop ( $ copy );
317
261
$ copy [] = "entities " ;
@@ -322,15 +266,15 @@ function list_entities_recurse( string $root , array $dirs )
322
266
323
267
if ( $ text != "" )
324
268
{
325
- // pushEntity( $name , text: $text ); // See TODO item 2
269
+ // pushEntity( $name , text: $text ); // See TODO item 2 // LIBXML_PARSEHUGE
326
270
327
271
if ( BACKPORT )
328
272
$ path = "$ dir/../entities. $ last.xml " ;
329
273
else
330
274
$ path = __DIR__ . "/../temp/file-entities. " . implode ( '. ' , $ dirs ) . ".ent " ;
331
275
332
276
file_put_contents ( $ path , $ text );
333
- $ path = realpath ( $ path );
277
+ $ path = realpain ( $ path );
334
278
pushEntity ( $ name , path: $ path );
335
279
}
336
280
@@ -365,3 +309,21 @@ function writeEntity( $file , Entity $ent )
365
309
366
310
fwrite ( $ file , $ line );
367
311
}
312
+
313
+ function realpain ( string $ path , bool $ touch = false ) : string
314
+ {
315
+ // pain is real
316
+
317
+ // care for external XML tools (realpath() everywhere)
318
+ // care for Windows builds (foward slashes everywhere)
319
+ // avoid `cd` and chdir() like the plague
320
+
321
+ if ( $ touch && ! file_exists ( $ path ) )
322
+ touch ( $ path );
323
+
324
+ $ res = realpath ( $ path );
325
+ if ($ res !== false )
326
+ $ path = $ res ;
327
+
328
+ return $ path ;
329
+ }
0 commit comments