1717
1818# Description
1919
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:
2222
2323- 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
2525
2626In the original file-entities.php.in, the files are created at:
2727
4444so it would be possible to detect accidental overwriting of structural
4545entities, the "list of entities" moved to/as normal entity text. PS: This
4646will 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.
4849
4950*/
5051
6061
6162// Usage
6263
63- $ root = realpath ( __DIR__ . "/../.. " );
64+ $ root = realpain ( __DIR__ . "/../.. " );
6465$ lang = "" ;
6566$ chmonly = false ;
6667$ debug = false ;
9394if ( $ lang != "" )
9495 generate_file_entities ( $ root , $ lang );
9596
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 " );
9799
98100if ( ! $ chmonly )
99101 foreach ( $ entities as $ ent )
100102 if ( str_starts_with ( $ ent ->name , "chmonly. " ) )
101103 $ ent ->path = '' ;
102104
103- $ outfile = __DIR__ . "/../temp/file-entities.ent " ;
104- touch ( $ outfile );
105- $ outfile = realpath ( $ outfile );
105+ $ outfile = realpain ( __DIR__ . "/../temp/file-entities.ent " , touch: true );
106106
107107$ file = fopen ( $ outfile , "w " );
108108if ( ! $ file )
@@ -149,48 +149,12 @@ function pushEntity( string $name , string $text = '' , string $path = '' )
149149 echo "Something went wrong on file-entities.php. \n" ;
150150 exit (-1 );
151151 }
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- }
188152}
189153
190154function generate_file_entities ( string $ root , string $ lang )
191155{
192156 $ path = "$ root/ $ lang " ;
193- $ test = realpath ( $ path );
157+ $ test = realpain ( $ path );
194158 if ( $ test === false || is_dir ( $ path ) == false )
195159 {
196160 echo "Language directory not found: $ path \n. " ;
@@ -242,7 +206,7 @@ function file_entities_recurse( string $langroot , array $dirs )
242206function generate_list_entities ( string $ root , string $ lang )
243207{
244208 $ path = "$ root/ $ lang " ;
245- $ test = realpath ( $ path );
209+ $ test = realpain ( $ path );
246210 if ( $ test === false || is_dir ( $ path ) == false )
247211 {
248212 echo "Language directory not found: $ path \n. " ;
@@ -292,26 +256,6 @@ function list_entities_recurse( string $root , array $dirs )
292256 }
293257 ksort ( $ list );
294258
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-
315259 $ copy = $ dirs ;
316260 $ last = array_pop ( $ copy );
317261 $ copy [] = "entities " ;
@@ -322,15 +266,15 @@ function list_entities_recurse( string $root , array $dirs )
322266
323267 if ( $ text != "" )
324268 {
325- // pushEntity( $name , text: $text ); // See TODO item 2
269+ // pushEntity( $name , text: $text ); // See TODO item 2 // LIBXML_PARSEHUGE
326270
327271 if ( BACKPORT )
328272 $ path = "$ dir/../entities. $ last.xml " ;
329273 else
330274 $ path = __DIR__ . "/../temp/file-entities. " . implode ( '. ' , $ dirs ) . ".ent " ;
331275
332276 file_put_contents ( $ path , $ text );
333- $ path = realpath ( $ path );
277+ $ path = realpain ( $ path );
334278 pushEntity ( $ name , path: $ path );
335279 }
336280
@@ -365,3 +309,21 @@ function writeEntity( $file , Entity $ent )
365309
366310 fwrite ( $ file , $ line );
367311}
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