|
12 | 12 | +----------------------------------------------------------------------+ |
13 | 13 | | Authors: André L F S Bacci <ae php.net> | |
14 | 14 | +----------------------------------------------------------------------+ |
15 | | -| Description: Split old style .ent file into individual files. | |
| 15 | +| Description: Split old DTD .ent file into individual XML files. | |
16 | 16 | +----------------------------------------------------------------------+ |
17 | 17 |
|
18 | | -See `entities.php` source for detailed rationale. |
| 18 | +See `entities.php` for detailed rationale. |
19 | 19 |
|
20 | | -Use this for spliting `language-snippets-ent` or other "big" entities |
21 | | -files into individual .xml files. |
| 20 | +Use this for spliting `language-snippets-ent` and possible other DTD |
| 21 | +entities files into individual .xml files. |
22 | 22 |
|
23 | | -After spliting, add the new directory entities/ with they contents, |
24 | | -and remove `language-snippets-ent`, in one go. |
| 23 | +After spliting, add generated files under doc-lang/entities/ , and |
| 24 | +the original file, in one go. |
25 | 25 |
|
26 | | -After all old style .ent files are split or converted, this script can |
| 26 | +After all DTD .ent files are split or converted, this script can |
27 | 27 | be removed. */ |
28 | 28 |
|
29 | 29 | ini_set( 'display_errors' , 1 ); |
30 | 30 | ini_set( 'display_startup_errors' , 1 ); |
31 | 31 | error_reporting( E_ALL ); |
32 | 32 |
|
33 | | -if ( count( $argv ) < 4 ) |
34 | | - die(" Syntax: php $argv[0] infile outdir [hash user]\n" ); |
| 33 | +if ( count( $argv ) < 3 ) |
| 34 | + die(" Syntax: php $argv[0] infile outdir [hash user]\n" ); |
35 | 35 |
|
36 | 36 | $infile = $argv[1]; |
37 | 37 | $outdir = $argv[2]; |
|
75 | 75 | { |
76 | 76 | $file = "$outdir/$name.xml"; |
77 | 77 | if ( file_exists( $file ) ) |
78 | | - exit( "Name colision: $file\n" ); |
| 78 | + echo( "Entity name colision, OVERWROTE: $file\n" ); |
79 | 79 | } |
80 | 80 |
|
81 | 81 | // Write |
82 | 82 |
|
83 | 83 | foreach( $entities as $name => $text ) |
84 | 84 | { |
85 | 85 | $file = "$outdir/$name.xml"; |
86 | | - |
87 | | - $header = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; |
| 86 | + $header = ""; |
88 | 87 |
|
89 | 88 | if ( $hash != "" ) |
90 | 89 | $header .= "<!-- EN-Revision: $hash Maintainer: $user Status: ready --><!-- CREDITS: $user -->\n"; |
91 | 90 |
|
92 | 91 | file_put_contents( $file , $header . $text ); |
93 | 92 | } |
94 | 93 |
|
| 94 | +// Test |
| 95 | + |
| 96 | +$dom = new DOMDocument(); |
| 97 | +$dom->recover = true; |
| 98 | +$dom->resolveExternals = false; |
| 99 | +libxml_use_internal_errors( true ); |
| 100 | + |
| 101 | +foreach( $entities as $name => $text ) |
| 102 | +{ |
| 103 | + $file = "$outdir/$name.xml"; |
| 104 | + |
| 105 | + $text = file_get_contents( $file ); |
| 106 | + $text = "<frag>$text</frag>"; |
| 107 | + |
| 108 | + $dom->loadXML( $text ); |
| 109 | + $err = libxml_get_errors(); |
| 110 | + libxml_clear_errors(); |
| 111 | + |
| 112 | + foreach( $err as $e ) |
| 113 | + { |
| 114 | + $msg = trim( $e->message ); |
| 115 | + if ( str_starts_with( $msg , "Entity '" ) && str_ends_with( $msg , "' not defined" ) ) |
| 116 | + continue; |
| 117 | + die( "Failed to load $file\n" ); |
| 118 | + } |
| 119 | +} |
| 120 | + |
95 | 121 | $total = count( $entities ); |
96 | 122 | print "Generated $total files.\n"; |
0 commit comments