@@ -52,7 +52,6 @@ Japanese, it doesn't *claim* to have Japanese.
52
52
53
53
#include " string.h"
54
54
#include " charstr.h" // ICU internal header
55
- #include < unicode/ustdio.h>
56
55
#include < unicode/ures.h>
57
56
#include < unicode/udata.h>
58
57
#include < unicode/putil.h>
@@ -69,36 +68,36 @@ CharString packageName;
69
68
const char * locale = RES_INDEX; // locale referring to our index
70
69
71
70
void usage () {
72
- u_printf (" Usage: %s [options]\n " , PROG);
73
- u_printf (
71
+ printf (" Usage: %s [options]\n " , PROG);
72
+ printf (
74
73
" This program lists and optionally regenerates the locale "
75
74
" manifests\n "
76
75
" in ICU 'res_index.res' files.\n " );
77
- u_printf (
76
+ printf (
78
77
" -i ICUDATA Set ICUDATA dir to ICUDATA.\n "
79
78
" 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 (
84
83
" if Verbose mode, then missing (unopenable)"
85
84
" locales\n "
86
85
" will be listed preceded by a '#'.\n " );
87
- u_printf (
86
+ printf (
88
87
" -b res_index.txt Write 'corrected' bundle "
89
88
" to res_index.txt\n "
90
89
" missing bundles will be "
91
90
" OMITTED\n " );
92
- u_printf (
91
+ printf (
93
92
" -T TREE Choose tree TREE\n "
94
93
" (TREE should be one of: \n "
95
94
" ROOT, brkitr, coll, curr, lang, rbnf, region, zone)\n " );
96
95
// see ureslocs.h and elsewhere
97
- u_printf (
96
+ printf (
98
97
" -N NAME Choose name NAME\n "
99
98
" (default: '%s')\n " ,
100
99
U_ICUDATA_NAME);
101
- u_printf (
100
+ printf (
102
101
" \n NOTE: for best results, this tool ought to be "
103
102
" linked against\n "
104
103
" stubdata. i.e. '%s -l' SHOULD return an error with "
@@ -108,7 +107,7 @@ void usage() {
108
107
109
108
#define ASSERT_SUCCESS (status, what ) \
110
109
if (U_FAILURE(*status)) { \
111
- u_printf (" %s:%d: %s: ERROR: %s %s\n " , \
110
+ printf (" %s:%d: %s: ERROR: %s %s\n " , \
112
111
__FILE__, \
113
112
__LINE__, \
114
113
PROG, \
@@ -130,7 +129,7 @@ void calculatePackageName(UErrorCode* status) {
130
129
}
131
130
}
132
131
if (VERBOSE) {
133
- u_printf (" packageName: %s\n " , packageName.data ());
132
+ printf (" packageName: %s\n " , packageName.data ());
134
133
}
135
134
}
136
135
@@ -146,41 +145,41 @@ void calculatePackageName(UErrorCode* status) {
146
145
int localeExists (const char * loc, UBool* exists) {
147
146
UErrorCode status = U_ZERO_ERROR;
148
147
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);
150
149
}
151
150
LocalUResourceBundlePointer aResource (
152
151
ures_openDirect (packageName.data (), loc, &status));
153
152
*exists = FALSE ;
154
153
if (U_SUCCESS (status)) {
155
154
*exists = true ;
156
155
if (VERBOSE > 1 ) {
157
- u_printf (" %s:%s existed!\n " , packageName.data (), loc);
156
+ printf (" %s:%s existed!\n " , packageName.data (), loc);
158
157
}
159
158
return 0 ;
160
159
} else if (status == U_MISSING_RESOURCE_ERROR) {
161
160
*exists = false ;
162
161
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));
167
166
}
168
167
return 0 ; // "good" failure
169
168
} else {
170
169
// 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);
177
176
return 1 ; // abort
178
177
}
179
178
}
180
179
181
- void printIndent (const LocalUFILEPointer * bf, int indent) {
180
+ void printIndent (FILE * bf, int indent) {
182
181
for (int i = 0 ; i < indent + 1 ; i++) {
183
- u_fprintf (bf-> getAlias () , " " );
182
+ fprintf (bf, " " );
184
183
}
185
184
}
186
185
@@ -191,7 +190,7 @@ void printIndent(const LocalUFILEPointer* bf, int indent) {
191
190
*/
192
191
int dumpAllButInstalledLocales (int lev,
193
192
LocalUResourceBundlePointer* bund,
194
- LocalUFILEPointer * bf,
193
+ FILE * bf,
195
194
UErrorCode* status) {
196
195
ures_resetIterator (bund->getAlias ());
197
196
LocalUResourceBundlePointer t;
@@ -200,30 +199,30 @@ int dumpAllButInstalledLocales(int lev,
200
199
ASSERT_SUCCESS (status, " while processing table" );
201
200
const char * key = ures_getKey (t.getAlias ());
202
201
if (VERBOSE > 1 ) {
203
- u_printf (" dump@%d: got key %s\n " , lev, key);
202
+ printf (" dump@%d: got key %s\n " , lev, key);
204
203
}
205
204
if (lev == 0 && !strcmp (key, INSTALLEDLOCALES)) {
206
205
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);
208
207
}
209
208
} else {
210
209
printIndent (bf, lev);
211
- u_fprintf (bf-> getAlias () , " %s" , key);
210
+ fprintf (bf, " %s" , key);
212
211
switch (ures_getType (t.getAlias ())) {
213
212
case URES_STRING: {
214
213
int32_t len = 0 ;
215
214
const UChar* s = ures_getString (t.getAlias (), &len, status);
216
215
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, " \" }" );
220
219
} break ;
221
220
default : {
222
- u_printf (" ERROR: unhandled type in dumpAllButInstalledLocales().\n " );
221
+ printf (" ERROR: unhandled type in dumpAllButInstalledLocales().\n " );
223
222
return 1 ;
224
223
} break ;
225
224
}
226
- u_fprintf (bf-> getAlias () , " \n " );
225
+ fprintf (bf, " \n " );
227
226
}
228
227
}
229
228
return 0 ;
@@ -232,28 +231,27 @@ int dumpAllButInstalledLocales(int lev,
232
231
int list (const char * toBundle) {
233
232
UErrorCode status = U_ZERO_ERROR;
234
233
235
- LocalUFILEPointer bf;
234
+ FILE* bf = NULL ;
236
235
237
236
if (toBundle != NULL ) {
238
237
if (VERBOSE) {
239
- u_printf (" writing to bundle %s\n " , toBundle);
238
+ printf (" writing to bundle %s\n " , toBundle);
240
239
}
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);
245
243
return 1 ;
246
244
}
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 " );
249
247
}
250
248
251
249
// first, calculate the bundle name.
252
250
calculatePackageName (&status);
253
251
ASSERT_SUCCESS (&status, " calculating package name" );
254
252
255
253
if (VERBOSE) {
256
- u_printf (" \" locale\" : %s\n " , locale);
254
+ printf (" \" locale\" : %s\n " , locale);
257
255
}
258
256
259
257
LocalUResourceBundlePointer bund (
@@ -265,33 +263,34 @@ int list(const char* toBundle) {
265
263
266
264
int32_t count = ures_getSize (installedLocales.getAlias ());
267
265
if (VERBOSE) {
268
- u_printf (" Locales: %d\n " , count);
266
+ printf (" Locales: %d\n " , count);
269
267
}
270
268
271
- if (bf. isValid () ) {
269
+ if (bf != NULL ) {
272
270
// 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);
285
284
return 1 ;
286
285
}
287
286
// in case an error was missed
288
287
ASSERT_SUCCESS (&status, " while writing prolog" );
289
288
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);
295
294
}
296
295
297
296
// OK, now list them.
@@ -305,35 +304,38 @@ int list(const char* toBundle) {
305
304
306
305
const char * key = ures_getKey (subkey.getAlias ());
307
306
if (VERBOSE > 1 ) {
308
- u_printf (" @%d: %s\n " , i, key);
307
+ printf (" @%d: %s\n " , i, key);
309
308
}
310
309
// now, see if the locale is installed..
311
310
312
311
UBool exists;
313
312
if (localeExists (key, &exists)) {
313
+ if (bf != NULL ) fclose (bf);
314
314
return 1 ; // get out.
315
315
}
316
316
if (exists) {
317
317
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);
321
321
}
322
322
} else {
323
- if (bf. isValid () ) {
324
- u_fprintf (bf. getAlias () , " // %s {\"\" }\n " , key);
323
+ if (bf != NULL ) {
324
+ fprintf (bf, " // %s {\"\" }\n " , key);
325
325
}
326
326
if (VERBOSE) {
327
- u_printf (" #%s\n " , key); // verbosity one - '' vs '#'
327
+ printf (" #%s\n " , key); // verbosity one - '' vs '#'
328
328
}
329
329
}
330
330
}
331
331
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);
334
334
// write the HEADER
335
- u_fprintf (bf.getAlias (), " }\n " );
335
+ fprintf (bf, " }\n " );
336
+ fclose (bf);
336
337
}
338
+
337
339
return 0 ;
338
340
}
339
341
@@ -346,24 +348,24 @@ int main(int argc, const char* argv[]) {
346
348
VERBOSE++;
347
349
} else if (!strcmp (arg, " -i" ) && (argsLeft >= 1 )) {
348
350
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 " );
350
352
usage ();
351
353
return 1 ;
352
354
}
353
355
const char * dir = argv[++i];
354
356
u_setDataDirectory (dir);
355
357
if (VERBOSE) {
356
- u_printf (" ICUDATA is now %s\n " , dir);
358
+ printf (" ICUDATA is now %s\n " , dir);
357
359
}
358
360
} else if (!strcmp (arg, " -T" ) && (argsLeft >= 1 )) {
359
361
TREE = argv[++i];
360
362
if (VERBOSE) {
361
- u_printf (" TREE is now %s\n " , TREE);
363
+ printf (" TREE is now %s\n " , TREE);
362
364
}
363
365
} else if (!strcmp (arg, " -N" ) && (argsLeft >= 1 )) {
364
366
NAME = argv[++i];
365
367
if (VERBOSE) {
366
- u_printf (" NAME is now %s\n " , NAME);
368
+ printf (" NAME is now %s\n " , NAME);
367
369
}
368
370
} else if (!strcmp (arg, " -?" ) || !strcmp (arg, " -h" )) {
369
371
usage ();
@@ -377,7 +379,7 @@ int main(int argc, const char* argv[]) {
377
379
return 1 ;
378
380
}
379
381
} else {
380
- u_printf (" Unknown or malformed option: %s\n " , arg);
382
+ printf (" Unknown or malformed option: %s\n " , arg);
381
383
usage ();
382
384
return 1 ;
383
385
}
0 commit comments