@@ -52,7 +52,6 @@ Japanese, it doesn't *claim* to have Japanese.
5252
5353#include " string.h"
5454#include " charstr.h" // ICU internal header
55- #include < unicode/ustdio.h>
5655#include < unicode/ures.h>
5756#include < unicode/udata.h>
5857#include < unicode/putil.h>
@@ -69,36 +68,36 @@ CharString packageName;
6968const char * locale = RES_INDEX; // locale referring to our index
7069
7170void usage () {
72- u_printf (" Usage: %s [options]\n " , PROG);
73- u_printf (
71+ printf (" Usage: %s [options]\n " , PROG);
72+ printf (
7473 " This program lists and optionally regenerates the locale "
7574 " manifests\n "
7675 " in ICU 'res_index.res' files.\n " );
77- u_printf (
76+ printf (
7877 " -i ICUDATA Set ICUDATA dir to ICUDATA.\n "
7978 " NOTE: this must be the first option given.\n " );
80- u_printf (" -h This Help\n " );
81- u_printf (" -v Verbose Mode on\n " );
82- u_printf (" -l List locales to stdout\n " );
83- u_printf (
79+ printf (" -h This Help\n " );
80+ printf (" -v Verbose Mode on\n " );
81+ printf (" -l List locales to stdout\n " );
82+ printf (
8483 " if Verbose mode, then missing (unopenable)"
8584 " locales\n "
8685 " will be listed preceded by a '#'.\n " );
87- u_printf (
86+ printf (
8887 " -b res_index.txt Write 'corrected' bundle "
8988 " to res_index.txt\n "
9089 " missing bundles will be "
9190 " OMITTED\n " );
92- u_printf (
91+ printf (
9392 " -T TREE Choose tree TREE\n "
9493 " (TREE should be one of: \n "
9594 " ROOT, brkitr, coll, curr, lang, rbnf, region, zone)\n " );
9695 // see ureslocs.h and elsewhere
97- u_printf (
96+ printf (
9897 " -N NAME Choose name NAME\n "
9998 " (default: '%s')\n " ,
10099 U_ICUDATA_NAME);
101- u_printf (
100+ printf (
102101 " \n NOTE: for best results, this tool ought to be "
103102 " linked against\n "
104103 " stubdata. i.e. '%s -l' SHOULD return an error with "
@@ -108,7 +107,7 @@ void usage() {
108107
109108#define ASSERT_SUCCESS (status, what ) \
110109 if (U_FAILURE(*status)) { \
111- u_printf (" %s:%d: %s: ERROR: %s %s\n " , \
110+ printf (" %s:%d: %s: ERROR: %s %s\n " , \
112111 __FILE__, \
113112 __LINE__, \
114113 PROG, \
@@ -130,7 +129,7 @@ void calculatePackageName(UErrorCode* status) {
130129 }
131130 }
132131 if (VERBOSE) {
133- u_printf (" packageName: %s\n " , packageName.data ());
132+ printf (" packageName: %s\n " , packageName.data ());
134133 }
135134}
136135
@@ -146,41 +145,41 @@ void calculatePackageName(UErrorCode* status) {
146145int localeExists (const char * loc, UBool* exists) {
147146 UErrorCode status = U_ZERO_ERROR;
148147 if (VERBOSE > 1 ) {
149- u_printf (" Trying to open %s:%s\n " , packageName.data (), loc);
148+ printf (" Trying to open %s:%s\n " , packageName.data (), loc);
150149 }
151150 LocalUResourceBundlePointer aResource (
152151 ures_openDirect (packageName.data (), loc, &status));
153152 *exists = FALSE ;
154153 if (U_SUCCESS (status)) {
155154 *exists = true ;
156155 if (VERBOSE > 1 ) {
157- u_printf (" %s:%s existed!\n " , packageName.data (), loc);
156+ printf (" %s:%s existed!\n " , packageName.data (), loc);
158157 }
159158 return 0 ;
160159 } else if (status == U_MISSING_RESOURCE_ERROR) {
161160 *exists = false ;
162161 if (VERBOSE > 1 ) {
163- u_printf (" %s:%s did NOT exist (%s)!\n " ,
164- packageName.data (),
165- loc,
166- u_errorName (status));
162+ printf (" %s:%s did NOT exist (%s)!\n " ,
163+ packageName.data (),
164+ loc,
165+ u_errorName (status));
167166 }
168167 return 0 ; // "good" failure
169168 } else {
170169 // some other failure..
171- u_printf (" %s:%d: %s: ERROR %s opening %s: %s for test.\n " ,
172- __FILE__,
173- __LINE__,
174- u_errorName (status),
175- packageName.data (),
176- loc);
170+ printf (" %s:%d: %s: ERROR %s opening %s for test.\n " ,
171+ __FILE__,
172+ __LINE__,
173+ u_errorName (status),
174+ packageName.data (),
175+ loc);
177176 return 1 ; // abort
178177 }
179178}
180179
181- void printIndent (const LocalUFILEPointer * bf, int indent) {
180+ void printIndent (FILE * bf, int indent) {
182181 for (int i = 0 ; i < indent + 1 ; i++) {
183- u_fprintf (bf-> getAlias () , " " );
182+ fprintf (bf, " " );
184183 }
185184}
186185
@@ -191,7 +190,7 @@ void printIndent(const LocalUFILEPointer* bf, int indent) {
191190 */
192191int dumpAllButInstalledLocales (int lev,
193192 LocalUResourceBundlePointer* bund,
194- LocalUFILEPointer * bf,
193+ FILE * bf,
195194 UErrorCode* status) {
196195 ures_resetIterator (bund->getAlias ());
197196 LocalUResourceBundlePointer t;
@@ -200,30 +199,30 @@ int dumpAllButInstalledLocales(int lev,
200199 ASSERT_SUCCESS (status, " while processing table" );
201200 const char * key = ures_getKey (t.getAlias ());
202201 if (VERBOSE > 1 ) {
203- u_printf (" dump@%d: got key %s\n " , lev, key);
202+ printf (" dump@%d: got key %s\n " , lev, key);
204203 }
205204 if (lev == 0 && !strcmp (key, INSTALLEDLOCALES)) {
206205 if (VERBOSE > 1 ) {
207- u_printf (" dump: skipping '%s' as it must be evaluated.\n " , key);
206+ printf (" dump: skipping '%s' as it must be evaluated.\n " , key);
208207 }
209208 } else {
210209 printIndent (bf, lev);
211- u_fprintf (bf-> getAlias () , " %s" , key);
210+ fprintf (bf, " %s" , key);
212211 switch (ures_getType (t.getAlias ())) {
213212 case URES_STRING: {
214213 int32_t len = 0 ;
215214 const UChar* s = ures_getString (t.getAlias (), &len, status);
216215 ASSERT_SUCCESS (status, " getting string" );
217- u_fprintf (bf-> getAlias () , " :string {\" " );
218- u_file_write (s, len, bf-> getAlias () );
219- u_fprintf (bf-> getAlias () , " \" }" );
216+ fprintf (bf, " :string {\" " );
217+ fwrite (s, len, 1 , bf );
218+ fprintf (bf, " \" }" );
220219 } break ;
221220 default : {
222- u_printf (" ERROR: unhandled type in dumpAllButInstalledLocales().\n " );
221+ printf (" ERROR: unhandled type in dumpAllButInstalledLocales().\n " );
223222 return 1 ;
224223 } break ;
225224 }
226- u_fprintf (bf-> getAlias () , " \n " );
225+ fprintf (bf, " \n " );
227226 }
228227 }
229228 return 0 ;
@@ -232,28 +231,27 @@ int dumpAllButInstalledLocales(int lev,
232231int list (const char * toBundle) {
233232 UErrorCode status = U_ZERO_ERROR;
234233
235- LocalUFILEPointer bf;
234+ FILE* bf = NULL ;
236235
237236 if (toBundle != NULL ) {
238237 if (VERBOSE) {
239- u_printf (" writing to bundle %s\n " , toBundle);
238+ printf (" writing to bundle %s\n " , toBundle);
240239 }
241- // we write UTF-8 with BOM only. No exceptions.
242- bf.adoptInstead (u_fopen (toBundle, " w" , " en_US_POSIX" , " UTF-8" ));
243- if (bf.isNull ()) {
244- u_printf (" ERROR: Could not open '%s' for writing.\n " , toBundle);
240+ bf = fopen (toBundle, " wb" );
241+ if (bf == NULL ) {
242+ printf (" ERROR: Could not open '%s' for writing.\n " , toBundle);
245243 return 1 ;
246244 }
247- u_fputc ( 0xFEFF , bf. getAlias ()) ; // write BOM
248- u_fprintf (bf. getAlias () , " // -*- Coding: utf-8; -*-\n //\n " );
245+ fprintf (bf, " \xEF\xBB\xBF " ) ; // write UTF-8 BOM
246+ fprintf (bf, " // -*- Coding: utf-8; -*-\n //\n " );
249247 }
250248
251249 // first, calculate the bundle name.
252250 calculatePackageName (&status);
253251 ASSERT_SUCCESS (&status, " calculating package name" );
254252
255253 if (VERBOSE) {
256- u_printf (" \" locale\" : %s\n " , locale);
254+ printf (" \" locale\" : %s\n " , locale);
257255 }
258256
259257 LocalUResourceBundlePointer bund (
@@ -265,33 +263,34 @@ int list(const char* toBundle) {
265263
266264 int32_t count = ures_getSize (installedLocales.getAlias ());
267265 if (VERBOSE) {
268- u_printf (" Locales: %d\n " , count);
266+ printf (" Locales: %d\n " , count);
269267 }
270268
271- if (bf. isValid () ) {
269+ if (bf != NULL ) {
272270 // write the HEADER
273- u_fprintf (bf.getAlias (),
274- " // Warning this file is automatically generated\n "
275- " // Updated by %s based on %s:%s.txt\n " ,
276- PROG,
277- packageName.data (),
278- locale);
279- u_fprintf (bf.getAlias (),
280- " %s:table(nofallback) {\n "
281- " // First, everything besides InstalledLocales:\n " ,
282- locale);
283- if (dumpAllButInstalledLocales (0 , &bund, &bf, &status)) {
284- u_printf (" Error dumping prolog for %s\n " , toBundle);
271+ fprintf (bf,
272+ " // Warning this file is automatically generated\n "
273+ " // Updated by %s based on %s:%s.txt\n " ,
274+ PROG,
275+ packageName.data (),
276+ locale);
277+ fprintf (bf,
278+ " %s:table(nofallback) {\n "
279+ " // First, everything besides InstalledLocales:\n " ,
280+ locale);
281+ if (dumpAllButInstalledLocales (0 , &bund, bf, &status)) {
282+ printf (" Error dumping prolog for %s\n " , toBundle);
283+ fclose (bf);
285284 return 1 ;
286285 }
287286 // in case an error was missed
288287 ASSERT_SUCCESS (&status, " while writing prolog" );
289288
290- u_fprintf (bf. getAlias () ,
291- " %s:table { // %d locales in input %s.res\n " ,
292- INSTALLEDLOCALES,
293- count,
294- locale);
289+ fprintf (bf,
290+ " %s:table { // %d locales in input %s.res\n " ,
291+ INSTALLEDLOCALES,
292+ count,
293+ locale);
295294 }
296295
297296 // OK, now list them.
@@ -305,35 +304,38 @@ int list(const char* toBundle) {
305304
306305 const char * key = ures_getKey (subkey.getAlias ());
307306 if (VERBOSE > 1 ) {
308- u_printf (" @%d: %s\n " , i, key);
307+ printf (" @%d: %s\n " , i, key);
309308 }
310309 // now, see if the locale is installed..
311310
312311 UBool exists;
313312 if (localeExists (key, &exists)) {
313+ if (bf != NULL ) fclose (bf);
314314 return 1 ; // get out.
315315 }
316316 if (exists) {
317317 validCount++;
318- u_printf (" %s\n " , key);
319- if (bf. isValid () ) {
320- u_fprintf (bf. getAlias () , " %s {\"\" }\n " , key);
318+ printf (" %s\n " , key);
319+ if (bf != NULL ) {
320+ fprintf (bf, " %s {\"\" }\n " , key);
321321 }
322322 } else {
323- if (bf. isValid () ) {
324- u_fprintf (bf. getAlias () , " // %s {\"\" }\n " , key);
323+ if (bf != NULL ) {
324+ fprintf (bf, " // %s {\"\" }\n " , key);
325325 }
326326 if (VERBOSE) {
327- u_printf (" #%s\n " , key); // verbosity one - '' vs '#'
327+ printf (" #%s\n " , key); // verbosity one - '' vs '#'
328328 }
329329 }
330330 }
331331
332- if (bf. isValid () ) {
333- u_fprintf (bf. getAlias () , " } // %d/%d valid\n " , validCount, count);
332+ if (bf != NULL ) {
333+ fprintf (bf, " } // %d/%d valid\n " , validCount, count);
334334 // write the HEADER
335- u_fprintf (bf.getAlias (), " }\n " );
335+ fprintf (bf, " }\n " );
336+ fclose (bf);
336337 }
338+
337339 return 0 ;
338340}
339341
@@ -346,24 +348,24 @@ int main(int argc, const char* argv[]) {
346348 VERBOSE++;
347349 } else if (!strcmp (arg, " -i" ) && (argsLeft >= 1 )) {
348350 if (i != 1 ) {
349- u_printf (" ERROR: -i must be the first argument given.\n " );
351+ printf (" ERROR: -i must be the first argument given.\n " );
350352 usage ();
351353 return 1 ;
352354 }
353355 const char * dir = argv[++i];
354356 u_setDataDirectory (dir);
355357 if (VERBOSE) {
356- u_printf (" ICUDATA is now %s\n " , dir);
358+ printf (" ICUDATA is now %s\n " , dir);
357359 }
358360 } else if (!strcmp (arg, " -T" ) && (argsLeft >= 1 )) {
359361 TREE = argv[++i];
360362 if (VERBOSE) {
361- u_printf (" TREE is now %s\n " , TREE);
363+ printf (" TREE is now %s\n " , TREE);
362364 }
363365 } else if (!strcmp (arg, " -N" ) && (argsLeft >= 1 )) {
364366 NAME = argv[++i];
365367 if (VERBOSE) {
366- u_printf (" NAME is now %s\n " , NAME);
368+ printf (" NAME is now %s\n " , NAME);
367369 }
368370 } else if (!strcmp (arg, " -?" ) || !strcmp (arg, " -h" )) {
369371 usage ();
@@ -377,7 +379,7 @@ int main(int argc, const char* argv[]) {
377379 return 1 ;
378380 }
379381 } else {
380- u_printf (" Unknown or malformed option: %s\n " , arg);
382+ printf (" Unknown or malformed option: %s\n " , arg);
381383 usage ();
382384 return 1 ;
383385 }
0 commit comments