Skip to content

Commit 46833d4

Browse files
alfsbAndré L F S Bacci
authored andcommitted
Fix counters, detailed messages and comments (#312)
1 parent 67f6bad commit 46833d4

1 file changed

Lines changed: 28 additions & 19 deletions

File tree

scripts/text-entities.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@
9696
9797
*/
9898

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

101103
ini_set( 'display_errors' , 1 );
102104
ini_set( 'display_startup_errors' , 1 );
@@ -106,23 +108,18 @@
106108

107109
$langs = [];
108110
$debug = false;
111+
$argv0 = array_shift( $argv );
109112
$usage = in_array( '--help' , $argv ) || in_array( '-h' , $argv );
110113

111-
if ( count( $argv ) < 2 || $usage )
112-
{
113-
print "\nUsage: {$argv[0]} langCode [langCode] [--debug]\n\n";
114-
if ( $usage )
115-
exit( 0 );
116-
else
117-
exit( 1 );
118-
}
119-
array_shift( $argv );
120114
foreach( $argv as $arg )
121115
if ( $arg == "--debug" )
122116
$debug = true;
123117
else
124118
$langs[] = $arg;
125119

120+
if ( count( $argv ) == 0 || $usage )
121+
usage_and_exit( $argv0 );
122+
126123
print "Running text-entities.php... ";
127124
if ( $debug )
128125
print "\n";
@@ -140,15 +137,27 @@
140137
Entities::writeOutputFile();
141138
Entities::checkReplaces( $debug );
142139

143-
echo "done: " , Entities::$countTotalGenerated , " entities";
140+
print "done: " . Entities::$countTotalGenerated . " entities";
144141
if ( Entities::$countTransFailures > 0 )
145-
echo ", " , Entities::$countTransFailures , " untranslated";
142+
print ", " . Entities::$countTransFailures . " untranslated";
146143
if ( Entities::$countOtherFailures > 0 )
147-
echo ", " , Entities::$countOtherFailures , " other failures";
148-
echo ".\n";
144+
print ", " . Entities::$countOtherFailures . " errors";
145+
print ".\n";
149146

147+
if ( Entities::$countOtherFailures > 0 && ! $debug )
148+
{
149+
$langs[] = '--debug';
150+
$opts = implode( ' ' , $langs );
151+
print "(Run 'php $argv0 $opts' for details.)\n";
152+
}
150153
exit;
151154

155+
function usage_and_exit( $argv0 )
156+
{
157+
print "\nUsage: $argv0 langCode [langCode] [--debug]\n\n";
158+
exit( 0 );
159+
}
160+
152161
enum EntityCheck
153162
{
154163
case Unique; // Expected once
@@ -189,9 +198,10 @@ static function put( string $path , string $name , string $text , bool $unique =
189198
if ( $remove )
190199
Entities::$remove[ $name ] = $name;
191200

192-
if ( ! isset( Entities::$nameCount[ $name ] ) )
193-
Entities::$nameCount[ $name ] = 0;
194-
Entities::$nameCount[ $name ]++;
201+
if ( isset( Entities::$nameCount[ $name ] ) )
202+
Entities::$nameCount[ $name ] += 1;
203+
else
204+
Entities::$nameCount[ $name ] = 1;
195205
}
196206

197207
static function truncateOutputFile()
@@ -281,7 +291,6 @@ function loadDirEntities( string $dir )
281291
$dir = realpath( $dir );
282292
$files = scandir( $dir );
283293
foreach( $files as $file )
284-
foreach( $files as $file )
285294
{
286295
$path = realpath( "$dir/$file" );
287296

@@ -457,7 +466,7 @@ function outputFiles( string $filename , array $entities )
457466

458467
if ( file_exists( $path ) )
459468
{
460-
echo "\nDuplicated text-entity file: '{$path}'.\n";
469+
print "\nDuplicated text-entity file: '{$path}'.\n";
461470
exit( 1 );
462471
}
463472

0 commit comments

Comments
 (0)