Skip to content

Commit fc3772c

Browse files
André L F S Baccijordikroon
authored andcommitted
Fixes on conv/split tools
1 parent de84e9a commit fc3772c

2 files changed

Lines changed: 42 additions & 16 deletions

File tree

scripts/dtdent-conv.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
+----------------------------------------------------------------------+
1313
| Authors: André L F S Bacci <ae php.net> |
1414
+----------------------------------------------------------------------+
15-
| Description: Convert old style .ent into new style .ent XML bundle. |
15+
| Description: Convert DTD Entities files into XML Entities files. |
1616
+----------------------------------------------------------------------+
1717
18-
See `entities.php` source for detailed rationale.
18+
See `entities.php` for detailed rationale.
1919
2020
Use this for converting bundled entities files that use <!ENTITY> into
2121
XML version used by `entities.php`.
@@ -58,7 +58,7 @@
5858
$name = substr( $content , $pos1 , $pos2 - $pos1 - 1 );
5959
$text = substr( $content , $pos2 , $pos3 - $pos2 );
6060

61-
// weird &ugly; ass, namespace corret, DOMDocumentFragment -> DOMNodeList (ampunstand intended)
61+
// weird &ugly; ass, namespace correct, DOMDocumentFragment -> DOMNodeList (ampunstand intended)
6262

6363
$name = trim( $name );
6464
$text = str_replace( "&" , "&amp;" , $text );
@@ -80,5 +80,5 @@
8080
$text = $dom->saveXML( $dom->getElementsByTagName( "entity" )[0] );
8181
$text = str_replace( "&amp;" , "&" , $text );
8282

83-
echo "$text\n";
83+
echo "\n$text\n";
8484
}

scripts/dtdent-split.php

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@
1212
+----------------------------------------------------------------------+
1313
| Authors: André L F S Bacci <ae php.net> |
1414
+----------------------------------------------------------------------+
15-
| Description: Split old style .ent file into individual files. |
15+
| Description: Split old DTD .ent file into individual XML files. |
1616
+----------------------------------------------------------------------+
1717
18-
See `entities.php` source for detailed rationale.
18+
See `entities.php` for detailed rationale.
1919
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.
2222
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.
2525
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
2727
be removed. */
2828

2929
ini_set( 'display_errors' , 1 );
3030
ini_set( 'display_startup_errors' , 1 );
3131
error_reporting( E_ALL );
3232

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" );
3535

3636
$infile = $argv[1];
3737
$outdir = $argv[2];
@@ -75,22 +75,48 @@
7575
{
7676
$file = "$outdir/$name.xml";
7777
if ( file_exists( $file ) )
78-
exit( "Name colision: $file\n" );
78+
echo( "Entity name colision, OVERWROTE: $file\n" );
7979
}
8080

8181
// Write
8282

8383
foreach( $entities as $name => $text )
8484
{
8585
$file = "$outdir/$name.xml";
86-
87-
$header = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
86+
$header = "";
8887

8988
if ( $hash != "" )
9089
$header .= "<!-- EN-Revision: $hash Maintainer: $user Status: ready --><!-- CREDITS: $user -->\n";
9190

9291
file_put_contents( $file , $header . $text );
9392
}
9493

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+
95121
$total = count( $entities );
96122
print "Generated $total files.\n";

0 commit comments

Comments
 (0)