]> git.saurik.com Git - apple/icu.git/blob - icuSources/tools/genrb/genrb.c
ICU-491.11.2.tar.gz
[apple/icu.git] / icuSources / tools / genrb / genrb.c
1 /*
2 *******************************************************************************
3 *
4 * Copyright (C) 1998-2012, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 *******************************************************************************
8 *
9 * File genrb.c
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 05/25/99 stephen Creation.
15 * 5/10/01 Ram removed ustdio dependency
16 *******************************************************************************
17 */
18
19 #include "genrb.h"
20 #include "unicode/uclean.h"
21
22 #include "ucmndata.h" /* TODO: for reading the pool bundle */
23
24 /* Protos */
25 void processFile(const char *filename, const char* cp, const char *inputDir, const char *outputDir,
26 const char *packageName, UBool omitBinaryCollation, UErrorCode *status);
27 static char *make_res_filename(const char *filename, const char *outputDir,
28 const char *packageName, UErrorCode *status);
29
30 /* File suffixes */
31 #define RES_SUFFIX ".res"
32 #define COL_SUFFIX ".col"
33
34 static char theCurrentFileName[2048];
35 const char *gCurrentFileName = theCurrentFileName;
36 #ifdef XP_MAC_CONSOLE
37 #include <console.h>
38 #endif
39
40 enum
41 {
42 HELP1,
43 HELP2,
44 VERBOSE,
45 QUIET,
46 VERSION,
47 SOURCEDIR,
48 DESTDIR,
49 ENCODING,
50 ICUDATADIR,
51 WRITE_JAVA,
52 COPYRIGHT,
53 /* PACKAGE_NAME, This option is deprecated and should not be used ever. */
54 BUNDLE_NAME,
55 WRITE_XLIFF,
56 STRICT,
57 NO_BINARY_COLLATION,
58 /*added by Jing*/
59 LANGUAGE,
60 NO_COLLATION_RULES,
61 FORMAT_VERSION,
62 WRITE_POOL_BUNDLE,
63 USE_POOL_BUNDLE,
64 INCLUDE_UNIHAN_COLL
65 };
66
67 UOption options[]={
68 UOPTION_HELP_H,
69 UOPTION_HELP_QUESTION_MARK,
70 UOPTION_VERBOSE,
71 UOPTION_QUIET,
72 UOPTION_VERSION,
73 UOPTION_SOURCEDIR,
74 UOPTION_DESTDIR,
75 UOPTION_ENCODING,
76 UOPTION_ICUDATADIR,
77 UOPTION_WRITE_JAVA,
78 UOPTION_COPYRIGHT,
79 /* UOPTION_PACKAGE_NAME, This option is deprecated and should not be used ever. */
80 UOPTION_BUNDLE_NAME,
81 UOPTION_DEF("write-xliff", 'x', UOPT_OPTIONAL_ARG),
82 UOPTION_DEF("strict", 'k', UOPT_NO_ARG), /* 14 */
83 UOPTION_DEF("noBinaryCollation", 'C', UOPT_NO_ARG),/* 15 */
84 UOPTION_DEF("language", 'l', UOPT_REQUIRES_ARG), /* 16 */
85 UOPTION_DEF("omitCollationRules", 'R', UOPT_NO_ARG),/* 17 */
86 UOPTION_DEF("formatVersion", '\x01', UOPT_REQUIRES_ARG),/* 18 */
87 UOPTION_DEF("writePoolBundle", '\x01', UOPT_NO_ARG),/* 19 */
88 UOPTION_DEF("usePoolBundle", '\x01', UOPT_OPTIONAL_ARG),/* 20 */
89 UOPTION_DEF("includeUnihanColl", '\x01', UOPT_NO_ARG),/* 21 */ /* temporary, don't display in usage info */
90 };
91
92 static UBool write_java = FALSE;
93 static UBool write_xliff = FALSE;
94 static const char* outputEnc ="";
95 static const char* gPackageName=NULL;
96 static const char* bundleName=NULL;
97 static struct SRBRoot *newPoolBundle = NULL;
98 UBool gIncludeUnihanColl = FALSE;
99
100 /* TODO: separate header file for ResFile? */
101 typedef struct ResFile {
102 uint8_t *fBytes;
103 const int32_t *fIndexes;
104 const char *fKeys;
105 int32_t fKeysLength;
106 int32_t fKeysCount;
107 int32_t fChecksum;
108 } ResFile;
109
110 static ResFile poolBundle = { NULL };
111
112 /*added by Jing*/
113 static const char* language = NULL;
114 static const char* xliffOutputFileName = NULL;
115 int
116 main(int argc,
117 char* argv[])
118 {
119 UErrorCode status = U_ZERO_ERROR;
120 const char *arg = NULL;
121 const char *outputDir = NULL; /* NULL = no output directory, use current */
122 const char *inputDir = NULL;
123 const char *encoding = "";
124 int i;
125
126 U_MAIN_INIT_ARGS(argc, argv);
127
128 argc = u_parseArgs(argc, argv, (int32_t)(sizeof(options)/sizeof(options[0])), options);
129
130 /* error handling, printing usage message */
131 if(argc<0) {
132 fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]);
133 } else if(argc<2) {
134 argc = -1;
135 }
136 if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) {
137 fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]);
138 argc = -1;
139 }
140 if(options[FORMAT_VERSION].doesOccur) {
141 const char *s = options[FORMAT_VERSION].value;
142 if(uprv_strlen(s) != 1 || (s[0] != '1' && s[0] != '2')) {
143 fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s);
144 argc = -1;
145 } else if(s[0] == '1' &&
146 (options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur)
147 ) {
148 fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]);
149 argc = -1;
150 } else {
151 setFormatVersion(s[0] - '0');
152 }
153 }
154
155 if(options[VERSION].doesOccur) {
156 fprintf(stderr,
157 "%s version %s (ICU version %s).\n"
158 "%s\n",
159 argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING);
160 return U_ZERO_ERROR;
161 }
162
163 if(argc<0 || options[HELP1].doesOccur || options[HELP2].doesOccur) {
164 /*
165 * Broken into chunks because the C89 standard says the minimum
166 * required supported string length is 509 bytes.
167 */
168 fprintf(stderr,
169 "Usage: %s [OPTIONS] [FILES]\n"
170 "\tReads the list of resource bundle source files and creates\n"
171 "\tbinary version of resource bundles (.res files)\n",
172 argv[0]);
173 fprintf(stderr,
174 "Options:\n"
175 "\t-h or -? or --help this usage text\n"
176 "\t-q or --quiet do not display warnings\n"
177 "\t-v or --verbose print extra information when processing files\n"
178 "\t-V or --version prints out version number and exits\n"
179 "\t-c or --copyright include copyright notice\n");
180 fprintf(stderr,
181 "\t-e or --encoding encoding of source files\n"
182 "\t-d of --destdir destination directory, followed by the path, defaults to %s\n"
183 "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n"
184 "\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
185 "\t followed by path, defaults to %s\n",
186 u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory());
187 fprintf(stderr,
188 "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n"
189 "\t defaults to ASCII and \\uXXXX format.\n");
190 /* This option is deprecated and should not be used ever.
191 "\t-p or --package-name For ICU4J: package name for writing the ListResourceBundle for ICU4J,\n"
192 "\t defaults to com.ibm.icu.impl.data\n"); */
193 fprintf(stderr,
194 "\t-b or --bundle-name bundle name for writing the ListResourceBundle for ICU4J,\n"
195 "\t defaults to LocaleElements\n"
196 "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n"
197 "\t an optional output file name.\n"
198 "\t-k or --strict use pedantic parsing of syntax\n"
199 /*added by Jing*/
200 "\t-l or --language for XLIFF: language code compliant with BCP 47.\n");
201 fprintf(stderr,
202 "\t-C or --noBinaryCollation do not generate binary collation image;\n"
203 "\t makes .res file smaller but collator instantiation much slower;\n"
204 "\t maintains ability to get tailoring rules\n"
205 "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n"
206 "\t makes .res file smaller and maintains collator instantiation speed\n"
207 "\t but tailoring rules will not be available (they are rarely used)\n");
208 fprintf(stderr,
209 "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n"
210 "\t for example, --formatVersion 1\n");
211 fprintf(stderr,
212 "\t --writePoolBundle write a pool.res file with all of the keys of all input bundles\n"
213 "\t --usePoolBundle [path-to-pool.res] point to keys from the pool.res keys pool bundle if they are available there;\n"
214 "\t makes .res files smaller but dependent on the pool bundle\n"
215 "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n");
216
217 return argc < 0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
218 }
219
220 if(options[VERBOSE].doesOccur) {
221 setVerbose(TRUE);
222 }
223
224 if(options[QUIET].doesOccur) {
225 setShowWarning(FALSE);
226 }
227 if(options[STRICT].doesOccur) {
228 setStrict(TRUE);
229 }
230 if(options[COPYRIGHT].doesOccur){
231 setIncludeCopyright(TRUE);
232 }
233
234 if(options[SOURCEDIR].doesOccur) {
235 inputDir = options[SOURCEDIR].value;
236 }
237
238 if(options[DESTDIR].doesOccur) {
239 outputDir = options[DESTDIR].value;
240 }
241 /* This option is deprecated and should never be used.
242 if(options[PACKAGE_NAME].doesOccur) {
243 gPackageName = options[PACKAGE_NAME].value;
244 if(!strcmp(gPackageName, "ICUDATA"))
245 {
246 gPackageName = U_ICUDATA_NAME;
247 }
248 if(gPackageName[0] == 0)
249 {
250 gPackageName = NULL;
251 }
252 }*/
253
254 if(options[ENCODING].doesOccur) {
255 encoding = options[ENCODING].value;
256 }
257
258 if(options[ICUDATADIR].doesOccur) {
259 u_setDataDirectory(options[ICUDATADIR].value);
260 }
261 /* Initialize ICU */
262 u_init(&status);
263 if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) {
264 /* Note: u_init() will try to open ICU property data.
265 * failures here are expected when building ICU from scratch.
266 * ignore them.
267 */
268 fprintf(stderr, "%s: can not initialize ICU. status = %s\n",
269 argv[0], u_errorName(status));
270 exit(1);
271 }
272 status = U_ZERO_ERROR;
273 if(options[WRITE_JAVA].doesOccur) {
274 write_java = TRUE;
275 outputEnc = options[WRITE_JAVA].value;
276 }
277
278 if(options[BUNDLE_NAME].doesOccur) {
279 bundleName = options[BUNDLE_NAME].value;
280 }
281
282 if(options[WRITE_XLIFF].doesOccur) {
283 write_xliff = TRUE;
284 if(options[WRITE_XLIFF].value != NULL){
285 xliffOutputFileName = options[WRITE_XLIFF].value;
286 }
287 }
288
289 initParser(options[NO_COLLATION_RULES].doesOccur);
290
291 /*added by Jing*/
292 if(options[LANGUAGE].doesOccur) {
293 language = options[LANGUAGE].value;
294 }
295
296 if(options[WRITE_POOL_BUNDLE].doesOccur) {
297 newPoolBundle = bundle_open(NULL, TRUE, &status);
298 if(U_FAILURE(status)) {
299 fprintf(stderr, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status));
300 return status;
301 } else {
302 const char *poolResName = "pool.res";
303 char *nameWithoutSuffix = uprv_malloc(uprv_strlen(poolResName) + 1);
304 if (nameWithoutSuffix == NULL) {
305 fprintf(stderr, "out of memory error\n");
306 return U_MEMORY_ALLOCATION_ERROR;
307 }
308 uprv_strcpy(nameWithoutSuffix, poolResName);
309 *uprv_strrchr(nameWithoutSuffix, '.') = 0;
310 newPoolBundle->fLocale = nameWithoutSuffix;
311 }
312 }
313
314 if(options[USE_POOL_BUNDLE].doesOccur) {
315 const char *poolResName = "pool.res";
316 FileStream *poolFile;
317 int32_t poolFileSize;
318 int32_t indexLength;
319 /*
320 * TODO: Consolidate inputDir/filename handling from main() and processFile()
321 * into a common function, and use it here as well.
322 * Try to create toolutil functions for dealing with dir/filenames and
323 * loading ICU data files without udata_open().
324 * Share code with icupkg?
325 * Also, make_res_filename() seems to be unused. Review and remove.
326 */
327 if (options[USE_POOL_BUNDLE].value!=NULL) {
328 uprv_strcpy(theCurrentFileName, options[USE_POOL_BUNDLE].value);
329 uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING);
330 } else if (inputDir) {
331 uprv_strcpy(theCurrentFileName, inputDir);
332 uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING);
333 } else {
334 *theCurrentFileName = 0;
335 }
336 uprv_strcat(theCurrentFileName, poolResName);
337 poolFile = T_FileStream_open(theCurrentFileName, "rb");
338 if (poolFile == NULL) {
339 fprintf(stderr, "unable to open pool bundle file %s\n", theCurrentFileName);
340 return 1;
341 }
342 poolFileSize = T_FileStream_size(poolFile);
343 if (poolFileSize < 32) {
344 fprintf(stderr, "the pool bundle file %s is too small\n", theCurrentFileName);
345 return 1;
346 }
347 poolBundle.fBytes = (uint8_t *)uprv_malloc((poolFileSize + 15) & ~15);
348 if (poolFileSize > 0 && poolBundle.fBytes == NULL) {
349 fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", theCurrentFileName);
350 return U_MEMORY_ALLOCATION_ERROR;
351 } else {
352 UDataSwapper *ds;
353 const DataHeader *header;
354 int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize);
355 int32_t keysBottom;
356 if (bytesRead != poolFileSize) {
357 fprintf(stderr, "unable to read the pool bundle file %s\n", theCurrentFileName);
358 return 1;
359 }
360 /*
361 * Swap the pool bundle so that a single checked-in file can be used.
362 * The swapper functions also test that the data looks like
363 * a well-formed .res file.
364 */
365 ds = udata_openSwapperForInputData(poolBundle.fBytes, bytesRead,
366 U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &status);
367 if (U_FAILURE(status)) {
368 fprintf(stderr, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n",
369 theCurrentFileName, u_errorName(status));
370 return status;
371 }
372 ures_swap(ds, poolBundle.fBytes, bytesRead, poolBundle.fBytes, &status);
373 udata_closeSwapper(ds);
374 if (U_FAILURE(status)) {
375 fprintf(stderr, "ures_swap(pool bundle %s) failed: %s\n",
376 theCurrentFileName, u_errorName(status));
377 return status;
378 }
379 header = (const DataHeader *)poolBundle.fBytes;
380 if (header->info.formatVersion[0]!=2) {
381 fprintf(stderr, "invalid format of pool bundle file %s\n", theCurrentFileName);
382 return U_INVALID_FORMAT_ERROR;
383 }
384 poolBundle.fKeys = (const char *)header + header->dataHeader.headerSize;
385 poolBundle.fIndexes = (const int32_t *)poolBundle.fKeys + 1;
386 indexLength = poolBundle.fIndexes[URES_INDEX_LENGTH] & 0xff;
387 if (indexLength <= URES_INDEX_POOL_CHECKSUM) {
388 fprintf(stderr, "insufficient indexes[] in pool bundle file %s\n", theCurrentFileName);
389 return U_INVALID_FORMAT_ERROR;
390 }
391 keysBottom = (1 + indexLength) * 4;
392 poolBundle.fKeys += keysBottom;
393 poolBundle.fKeysLength = (poolBundle.fIndexes[URES_INDEX_KEYS_TOP] * 4) - keysBottom;
394 poolBundle.fChecksum = poolBundle.fIndexes[URES_INDEX_POOL_CHECKSUM];
395 }
396 for (i = 0; i < poolBundle.fKeysLength; ++i) {
397 if (poolBundle.fKeys[i] == 0) {
398 ++poolBundle.fKeysCount;
399 }
400 }
401 T_FileStream_close(poolFile);
402 setUsePoolBundle(TRUE);
403 }
404
405 if(options[INCLUDE_UNIHAN_COLL].doesOccur) {
406 gIncludeUnihanColl = TRUE;
407 }
408
409 if((argc-1)!=1) {
410 printf("genrb number of files: %d\n", argc - 1);
411 }
412 /* generate the binary files */
413 for(i = 1; i < argc; ++i) {
414 status = U_ZERO_ERROR;
415 arg = getLongPathname(argv[i]);
416
417 if (inputDir) {
418 uprv_strcpy(theCurrentFileName, inputDir);
419 uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING);
420 } else {
421 *theCurrentFileName = 0;
422 }
423 uprv_strcat(theCurrentFileName, arg);
424
425 if (isVerbose()) {
426 printf("Processing file \"%s\"\n", theCurrentFileName);
427 }
428 processFile(arg, encoding, inputDir, outputDir, gPackageName,
429 options[NO_BINARY_COLLATION].doesOccur,
430 &status);
431 }
432
433 uprv_free(poolBundle.fBytes);
434
435 if(options[WRITE_POOL_BUNDLE].doesOccur) {
436 char outputFileName[256];
437 bundle_write(newPoolBundle, outputDir, NULL, outputFileName, sizeof(outputFileName), &status);
438 bundle_close(newPoolBundle, &status);
439 if(U_FAILURE(status)) {
440 fprintf(stderr, "unable to write the pool bundle: %s\n", u_errorName(status));
441 }
442 }
443
444 /* Dont return warnings as a failure */
445 if (U_SUCCESS(status)) {
446 return 0;
447 }
448
449 return status;
450 }
451
452 /* Process a file */
453 void
454 processFile(
455 const char *filename, const char *cp, const char *inputDir, const char *outputDir, const char *packageName,
456 UBool omitBinaryCollation, UErrorCode *status) {
457 /*FileStream *in = NULL;*/
458 struct SRBRoot *data = NULL;
459 UCHARBUF *ucbuf = NULL;
460 char *rbname = NULL;
461 char *openFileName = NULL;
462 char *inputDirBuf = NULL;
463
464 char outputFileName[256];
465
466 int32_t dirlen = 0;
467 int32_t filelen = 0;
468
469
470 if (status==NULL || U_FAILURE(*status)) {
471 return;
472 }
473 if(filename==NULL){
474 *status=U_ILLEGAL_ARGUMENT_ERROR;
475 return;
476 }else{
477 filelen = (int32_t)uprv_strlen(filename);
478 }
479
480 if(inputDir == NULL) {
481 const char *filenameBegin = uprv_strrchr(filename, U_FILE_SEP_CHAR);
482 openFileName = (char *) uprv_malloc(dirlen + filelen + 2);
483 openFileName[0] = '\0';
484 if (filenameBegin != NULL) {
485 /*
486 * When a filename ../../../data/root.txt is specified,
487 * we presume that the input directory is ../../../data
488 * This is very important when the resource file includes
489 * another file, like UCARules.txt or thaidict.brk.
490 */
491 int32_t filenameSize = (int32_t)(filenameBegin - filename + 1);
492 inputDirBuf = uprv_strncpy((char *)uprv_malloc(filenameSize), filename, filenameSize);
493
494 /* test for NULL */
495 if(inputDirBuf == NULL) {
496 *status = U_MEMORY_ALLOCATION_ERROR;
497 goto finish;
498 }
499
500 inputDirBuf[filenameSize - 1] = 0;
501 inputDir = inputDirBuf;
502 dirlen = (int32_t)uprv_strlen(inputDir);
503 }
504 }else{
505 dirlen = (int32_t)uprv_strlen(inputDir);
506
507 if(inputDir[dirlen-1] != U_FILE_SEP_CHAR) {
508 openFileName = (char *) uprv_malloc(dirlen + filelen + 2);
509
510 /* test for NULL */
511 if(openFileName == NULL) {
512 *status = U_MEMORY_ALLOCATION_ERROR;
513 goto finish;
514 }
515
516 openFileName[0] = '\0';
517 /*
518 * append the input dir to openFileName if the first char in
519 * filename is not file seperation char and the last char input directory is not '.'.
520 * This is to support :
521 * genrb -s. /home/icu/data
522 * genrb -s. icu/data
523 * The user cannot mix notations like
524 * genrb -s. /icu/data --- the absolute path specified. -s redundant
525 * user should use
526 * genrb -s. icu/data --- start from CWD and look in icu/data dir
527 */
528 if( (filename[0] != U_FILE_SEP_CHAR) && (inputDir[dirlen-1] !='.')){
529 uprv_strcpy(openFileName, inputDir);
530 openFileName[dirlen] = U_FILE_SEP_CHAR;
531 }
532 openFileName[dirlen + 1] = '\0';
533 } else {
534 openFileName = (char *) uprv_malloc(dirlen + filelen + 1);
535
536 /* test for NULL */
537 if(openFileName == NULL) {
538 *status = U_MEMORY_ALLOCATION_ERROR;
539 goto finish;
540 }
541
542 uprv_strcpy(openFileName, inputDir);
543
544 }
545 }
546
547 uprv_strcat(openFileName, filename);
548
549 ucbuf = ucbuf_open(openFileName, &cp,getShowWarning(),TRUE, status);
550 if(*status == U_FILE_ACCESS_ERROR) {
551
552 fprintf(stderr, "couldn't open file %s\n", openFileName == NULL ? filename : openFileName);
553 goto finish;
554 }
555 if (ucbuf == NULL || U_FAILURE(*status)) {
556 fprintf(stderr, "An error occured processing file %s. Error: %s\n", openFileName == NULL ? filename : openFileName,u_errorName(*status));
557 goto finish;
558 }
559 /* auto detected popular encodings? */
560 if (cp!=NULL && isVerbose()) {
561 printf("autodetected encoding %s\n", cp);
562 }
563 /* Parse the data into an SRBRoot */
564 data = parse(ucbuf, inputDir, outputDir, !omitBinaryCollation, status);
565
566 if (data == NULL || U_FAILURE(*status)) {
567 fprintf(stderr, "couldn't parse the file %s. Error:%s\n", filename,u_errorName(*status));
568 goto finish;
569 }
570 if(options[WRITE_POOL_BUNDLE].doesOccur) {
571 int32_t newKeysLength;
572 const char *newKeys, *newKeysLimit;
573 bundle_compactKeys(data, status);
574 newKeys = bundle_getKeyBytes(data, &newKeysLength);
575 bundle_addKeyBytes(newPoolBundle, newKeys, newKeysLength, status);
576 if(U_FAILURE(*status)) {
577 fprintf(stderr, "bundle_compactKeys(%s) or bundle_getKeyBytes() failed: %s\n",
578 filename, u_errorName(*status));
579 goto finish;
580 }
581 /* count the number of just-added key strings */
582 for(newKeysLimit = newKeys + newKeysLength; newKeys < newKeysLimit; ++newKeys) {
583 if(*newKeys == 0) {
584 ++newPoolBundle->fKeysCount;
585 }
586 }
587 }
588
589 if(options[USE_POOL_BUNDLE].doesOccur) {
590 data->fPoolBundleKeys = poolBundle.fKeys;
591 data->fPoolBundleKeysLength = poolBundle.fKeysLength;
592 data->fPoolBundleKeysCount = poolBundle.fKeysCount;
593 data->fPoolChecksum = poolBundle.fChecksum;
594 }
595
596 /* Determine the target rb filename */
597 rbname = make_res_filename(filename, outputDir, packageName, status);
598 if(U_FAILURE(*status)) {
599 fprintf(stderr, "couldn't make the res fileName for bundle %s. Error:%s\n", filename,u_errorName(*status));
600 goto finish;
601 }
602 if(write_java== TRUE){
603 bundle_write_java(data,outputDir,outputEnc, outputFileName, sizeof(outputFileName),packageName,bundleName,status);
604 }else if(write_xliff ==TRUE){
605 bundle_write_xml(data,outputDir,outputEnc, filename, outputFileName, sizeof(outputFileName),language, xliffOutputFileName,status);
606 }else{
607 /* Write the data to the file */
608 bundle_write(data, outputDir, packageName, outputFileName, sizeof(outputFileName), status);
609 }
610 if (U_FAILURE(*status)) {
611 fprintf(stderr, "couldn't write bundle %s. Error:%s\n", outputFileName,u_errorName(*status));
612 }
613 bundle_close(data, status);
614
615 finish:
616
617 if (inputDirBuf != NULL) {
618 uprv_free(inputDirBuf);
619 }
620
621 if (openFileName != NULL) {
622 uprv_free(openFileName);
623 }
624
625 if(ucbuf) {
626 ucbuf_close(ucbuf);
627 }
628
629 if (rbname) {
630 uprv_free(rbname);
631 }
632 }
633
634 /* Generate the target .res file name from the input file name */
635 static char*
636 make_res_filename(const char *filename,
637 const char *outputDir,
638 const char *packageName,
639 UErrorCode *status) {
640 char *basename;
641 char *dirname;
642 char *resName;
643
644 int32_t pkgLen = 0; /* length of package prefix */
645
646
647 if (U_FAILURE(*status)) {
648 return 0;
649 }
650
651 if(packageName != NULL)
652 {
653 pkgLen = (int32_t)(1 + uprv_strlen(packageName));
654 }
655
656 /* setup */
657 basename = dirname = resName = 0;
658
659 /* determine basename, and compiled file names */
660 basename = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1));
661 if(basename == 0) {
662 *status = U_MEMORY_ALLOCATION_ERROR;
663 goto finish;
664 }
665
666 get_basename(basename, filename);
667
668 dirname = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1));
669 if(dirname == 0) {
670 *status = U_MEMORY_ALLOCATION_ERROR;
671 goto finish;
672 }
673
674 get_dirname(dirname, filename);
675
676 if (outputDir == NULL) {
677 /* output in same dir as .txt */
678 resName = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(dirname)
679 + pkgLen
680 + uprv_strlen(basename)
681 + uprv_strlen(RES_SUFFIX) + 8));
682 if(resName == 0) {
683 *status = U_MEMORY_ALLOCATION_ERROR;
684 goto finish;
685 }
686
687 uprv_strcpy(resName, dirname);
688
689 if(packageName != NULL)
690 {
691 uprv_strcat(resName, packageName);
692 uprv_strcat(resName, "_");
693 }
694
695 uprv_strcat(resName, basename);
696
697 } else {
698 int32_t dirlen = (int32_t)uprv_strlen(outputDir);
699 int32_t basenamelen = (int32_t)uprv_strlen(basename);
700
701 resName = (char*) uprv_malloc(sizeof(char) * (dirlen + pkgLen + basenamelen + 8));
702
703 if (resName == NULL) {
704 *status = U_MEMORY_ALLOCATION_ERROR;
705 goto finish;
706 }
707
708 uprv_strcpy(resName, outputDir);
709
710 if(outputDir[dirlen] != U_FILE_SEP_CHAR) {
711 resName[dirlen] = U_FILE_SEP_CHAR;
712 resName[dirlen + 1] = '\0';
713 }
714
715 if(packageName != NULL)
716 {
717 uprv_strcat(resName, packageName);
718 uprv_strcat(resName, "_");
719 }
720
721 uprv_strcat(resName, basename);
722 }
723
724 finish:
725 uprv_free(basename);
726 uprv_free(dirname);
727
728 return resName;
729 }
730
731 /*
732 * Local Variables:
733 * indent-tabs-mode: nil
734 * End:
735 */