Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions scripts/broken.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@

require_once __DIR__ . '/translation/lib/XmlErrorFilter.php';

ini_set( 'display_errors' , 1 );
ini_set( 'display_startup_errors' , 1 );
error_reporting( E_ALL );

if ( count( $argv ) < 2 )
print_usage_exit( $argv[0] );
array_shift( $argv );
Expand All @@ -49,16 +45,15 @@

foreach( $paths as $path )
{
$dnt = true;
if ( $path == 'en' || str_ends_with( $path , '/en' ) )
$dnt = false;

if ( file_exists( $path ) )
{
$checkDnt = ! file_exists( "$path/manual.xml" );

if ( is_file( $path ) )
testFile( $path , $dnt );
testFile( $path , $checkDnt );
if ( is_dir( $path ) )
testDir( $path , $dnt );
testDir( $path , $checkDnt );

continue;
}
echo "Path does not exist: $path\n";
Expand Down
99 changes: 18 additions & 81 deletions scripts/text-entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@

*/

// For while XML Entities are not fully implanted in all languages
// Can be removed when all languages have an doc-lang/entities dir.
const PARTIAL_IMPL = true;

ini_set( 'display_errors' , 1 );
ini_set( 'display_startup_errors' , 1 );
error_reporting( E_ALL );

Entities::truncateOutputFile();

$langs = [];
Expand All @@ -129,7 +121,7 @@
$entDir = __DIR__ . "/../../$lang/entities";
$refDir = __DIR__ . "/../../$lang/reference";

loadDirEntities( $entDir );
loadDirEntities( $entDir , $lang );
loadDirRecurse( $refDir );
Entities::$countLanguages++;
}
Expand Down Expand Up @@ -214,7 +206,20 @@ static function truncateOutputFile()

static function writeOutputFile()
{
outputFiles( Entities::$filename , Entities::$merged );
$file = fopen( Entities::$filename , "w" );
fputs( $file , "\n<!-- Autogenerated by text-entities.php -->\n\n" );

foreach( Entities::$merged as $name => $entity )
{
$name = $entity->name;
$body = $entity->text;

$escaped = str_replace( "'" , '&apos;' , $body );

fputs( $file , "<!ENTITY $name '{$escaped}'>\n\n" );
}

fclose( $file );
}

static function checkReplaces( bool $debug )
Expand Down Expand Up @@ -272,21 +277,12 @@ static function checkReplaces( bool $debug )
}
}

function loadDirEntities( string $dir )
function loadDirEntities( string $dir , string $lang )
{
if ( realpath( $dir ) === false || ! is_dir( $dir ) )
{
if ( PARTIAL_IMPL )
{
global $lang;
print "(skiped $lang/entities) ";
return;
}
else
{
print "\n Not a directory: $dir\n";
exit( 1 );
}
print "(missing $lang/entities) ";
return;
}

$dir = realpath( $dir );
Expand Down Expand Up @@ -421,62 +417,3 @@ function loadEntitySingle( string $path )

Entities::put( $path , $name , $text );
}

function outputFiles( string $filename , array $entities )
{
$file = fopen( $filename , "w" );
fputs( $file , "\n<!-- Autogenerated by text-entities.php -->\n\n" );

$sepFileDir = __DIR__ . "/../temp/text-entities/";

if ( file_exists( $sepFileDir ) == false )
mkdir( $sepFileDir , recursive: true );

foreach( $entities as $name => $entity )
{
$name = $entity->name;
$body = $entity->text;

$quote = "'";
$count = 0;

if ( str_contains( $body , "'" ) )
{
$quote = '"';
$count++;
}
if ( str_contains( $body , '"' ) )
{
$quote = "'";
$count++;
}

if ( $count < 2 )
{
// Fast path for single or no quote:
// entity body directly quoted on output file.

fputs( $file , "<!ENTITY $name {$quote}{$body}{$quote}>\n\n" );
continue;
}

// Slow path: entity body as an external file,
// as to avoid (re)quotation hell.

$path = $sepFileDir . "/{$entity->name}.xml";

if ( file_exists( $path ) )
{
print "\nDuplicated text-entity file: '{$path}'.\n";
exit( 1 );
}

// realpath() only after file creation

file_put_contents( $path , $body );
$path = realpath( $path );
fputs( $file , "<!ENTITY $name SYSTEM '{$path}'>\n\n" );
}

fclose( $file );
}
Loading