1+ #!/usr/bin/env php
12<?php
23
34use Gettext \Languages \Exporter \Exporter ;
@@ -7,55 +8,12 @@ use Gettext\Languages\Language;
78// This is a really life-saving approach.
89error_reporting (E_ALL );
910set_error_handler (function ($ errno , $ errstr , $ errfile , $ errline ) {
10- fprintf (STDERR, "{$errstr}\nFile: {$errfile}\nLine: {$errline}\nCode: {$errno}\n");
11+ fwrite (STDERR , "{$ errstr }\nFile: {$ errfile }\nLine: {$ errline }\nCode: {$ errno }\n" );
1112 exit (5 );
1213});
1314
1415require_once dirname (__DIR__ ) . '/src/autoloader.php ' ;
1516
16- // Parse the command line options
17- Enviro::initialize();
18-
19- try {
20- if (isset(Enviro::$languages)) {
21- $languages = array();
22- foreach (Enviro::$languages as $languageId) {
23- $language = Language::getById($languageId);
24- if (!isset($language)) {
25- throw new Exception("Unable to find the language with id '{$languageId}'");
26- }
27- $languages[] = $language;
28- }
29- } else {
30- $languages = Language::getAll();
31- }
32- if (Enviro::$reduce) {
33- $languages = Enviro::reduce($languages);
34- }
35- if (Enviro::$noExtraParenthesis) {
36- $languages = array_map(
37- function (Language $language) {
38- $language->formula = $language->buildFormula(true);
39-
40- return $language;
41- },
42- $languages
43- );
44- }
45- if (isset(Enviro::$outputFilename)) {
46- echo call_user_func(array(Exporter::getExporterClassName(Enviro::$outputFormat), 'toFile'), $languages, Enviro::$outputFilename, array('us-ascii' => Enviro::$outputUSAscii));
47- } else {
48- echo call_user_func(array(Exporter::getExporterClassName(Enviro::$outputFormat), 'toString'), $languages, array('us-ascii' => Enviro::$outputUSAscii));
49- }
50- } catch (Exception $x) {
51- fprintf(STDERR, $x->getMessage() . "\n");
52- fprintf(STDERR, "Trace:\n");
53- fprintf(STDERR, $x->getTraceAsString() . "\n");
54- exit(4);
55- }
56-
57- exit(0);
58-
5917/**
6018 * Helper class to handle command line options.
6119 */
@@ -146,7 +104,7 @@ class Enviro
146104 default :
147105 if (preg_match ('/^--output=.+$/ ' , $ argLC )) {
148106 if (isset (self ::$ outputFilename )) {
149- fprintf (STDERR, "The output file name has been specified more than once!\n");
107+ fwrite (STDERR , "The output file name has been specified more than once! \n" );
150108 self ::showSyntax ();
151109 exit (3 );
152110 }
@@ -162,13 +120,13 @@ class Enviro
162120 }
163121 } elseif (isset ($ exporters [$ argLC ])) {
164122 if (isset (self ::$ outputFormat )) {
165- fprintf (STDERR, "The output format has been specified more than once!\n");
123+ fwrite (STDERR , "The output format has been specified more than once! \n" );
166124 self ::showSyntax ();
167125 exit (3 );
168126 }
169127 self ::$ outputFormat = $ argLC ;
170128 } else {
171- fprintf (STDERR, "Unknown option: {$arg}\n");
129+ fwrite (STDERR , "Unknown option: {$ arg }\n" );
172130 self ::showSyntax ();
173131 exit (2 );
174132 }
@@ -197,7 +155,7 @@ class Enviro
197155 $ basename = basename (__FILE__ );
198156 $ exporters = array_keys (Exporter::getExporters (true ));
199157 $ exporterList = implode ('| ' , $ exporters );
200- fprintf (
158+ fwrite (
201159 STDERR ,
202160 <<<EOT
203161Syntax:
238196 );
239197 $ len = max (array_map ('strlen ' , $ exporters ));
240198 foreach ($ exporters as $ exporter ) {
241- fprintf (STDERR, ' ' . str_pad($exporter, $len) . ': ' . Exporter::getExporterDescription($exporter) . "\n");
199+ fwrite (STDERR , ' ' . str_pad ($ exporter , $ len ) . ': ' . Exporter::getExporterDescription ($ exporter ) . "\n" );
242200 }
243- fprintf (STDERR, "\n");
201+ fwrite (STDERR , "\n" );
244202 }
245203
246204 /**
287245 return $ languages ;
288246 }
289247}
248+
249+ // Parse the command line options
250+ Enviro::initialize ();
251+
252+ try {
253+ if (isset (Enviro::$ languages )) {
254+ $ languages = array ();
255+ foreach (Enviro::$ languages as $ languageId ) {
256+ $ language = Language::getById ($ languageId );
257+ if (!isset ($ language )) {
258+ throw new Exception ("Unable to find the language with id ' {$ languageId }' " );
259+ }
260+ $ languages [] = $ language ;
261+ }
262+ } else {
263+ $ languages = Language::getAll ();
264+ }
265+ if (Enviro::$ reduce ) {
266+ $ languages = Enviro::reduce ($ languages );
267+ }
268+ if (Enviro::$ noExtraParenthesis ) {
269+ $ languages = array_map (
270+ function (Language $ language ) {
271+ $ language ->formula = $ language ->buildFormula (true );
272+
273+ return $ language ;
274+ },
275+ $ languages
276+ );
277+ }
278+ if (isset (Enviro::$ outputFilename )) {
279+ echo call_user_func (array (Exporter::getExporterClassName (Enviro::$ outputFormat ), 'toFile ' ), $ languages , Enviro::$ outputFilename , array ('us-ascii ' => Enviro::$ outputUSAscii ));
280+ } else {
281+ echo call_user_func (array (Exporter::getExporterClassName (Enviro::$ outputFormat ), 'toString ' ), $ languages , array ('us-ascii ' => Enviro::$ outputUSAscii ));
282+ }
283+ } catch (Exception $ x ) {
284+ fwrite (STDERR , $ x ->getMessage () . "\n" );
285+ fwrite (STDERR , "Trace: \n" );
286+ fwrite (STDERR , $ x ->getTraceAsString () . "\n" );
287+ exit (4 );
288+ }
289+
290+ exit (0 );
0 commit comments