1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1998-2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
13 * Modification History:
15 * Date Name Description
16 * 05/25/99 stephen Creation.
17 * 5/10/01 Ram removed ustdio dependency
18 *******************************************************************************
28 #include "unicode/localpointer.h"
29 #include "unicode/uclean.h"
30 #include "unicode/utf16.h"
35 #include "ucmndata.h" /* TODO: for reading the pool bundle */
40 void processFile(const char *filename
, const char* cp
,
41 const char *inputDir
, const char *outputDir
, const char *filterDir
,
42 const char *packageName
,
43 SRBRoot
*newPoolBundle
, UBool omitBinaryCollation
, UErrorCode
&status
);
44 static char *make_res_filename(const char *filename
, const char *outputDir
,
45 const char *packageName
, UErrorCode
&status
);
48 #define RES_SUFFIX ".res"
49 #define COL_SUFFIX ".col"
51 const char *gCurrentFileName
= NULL
;
56 void ResFile::close() {
92 UOPTION_HELP_QUESTION_MARK
,
102 UOPTION_DEF("java-package", '\x01', UOPT_REQUIRES_ARG
),
104 UOPTION_DEF("write-xliff", 'x', UOPT_OPTIONAL_ARG
),
105 UOPTION_DEF("strict", 'k', UOPT_NO_ARG
), /* 14 */
106 UOPTION_DEF("noBinaryCollation", 'C', UOPT_NO_ARG
),/* 15 */
107 UOPTION_DEF("language", 'l', UOPT_REQUIRES_ARG
), /* 16 */
108 UOPTION_DEF("omitCollationRules", 'R', UOPT_NO_ARG
),/* 17 */
109 UOPTION_DEF("formatVersion", '\x01', UOPT_REQUIRES_ARG
),/* 18 */
110 UOPTION_DEF("writePoolBundle", '\x01', UOPT_OPTIONAL_ARG
),/* 19 */
111 UOPTION_DEF("usePoolBundle", '\x01', UOPT_OPTIONAL_ARG
),/* 20 */
112 UOPTION_DEF("includeUnihanColl", '\x01', UOPT_NO_ARG
),/* 21 */ /* temporary, don't display in usage info */
113 UOPTION_DEF("filterDir", '\x01', UOPT_OPTIONAL_ARG
), /* 22 */
116 static UBool write_java
= FALSE
;
117 static UBool write_xliff
= FALSE
;
118 static const char* outputEnc
="";
120 static ResFile poolBundle
;
123 static const char* language
= NULL
;
124 static const char* xliffOutputFileName
= NULL
;
129 UErrorCode status
= U_ZERO_ERROR
;
130 const char *arg
= NULL
;
131 const char *outputDir
= NULL
; /* NULL = no output directory, use current */
132 const char *inputDir
= NULL
;
133 const char *filterDir
= NULL
;
134 const char *encoding
= "";
136 UBool illegalArg
= FALSE
;
138 U_MAIN_INIT_ARGS(argc
, argv
);
140 options
[JAVA_PACKAGE
].value
= "com.ibm.icu.impl.data";
141 options
[BUNDLE_NAME
].value
= "LocaleElements";
142 argc
= u_parseArgs(argc
, argv
, UPRV_LENGTHOF(options
), options
);
144 /* error handling, printing usage message */
146 fprintf(stderr
, "%s: error in command line argument \"%s\"\n", argv
[0], argv
[-argc
]);
151 if(options
[WRITE_POOL_BUNDLE
].doesOccur
&& options
[USE_POOL_BUNDLE
].doesOccur
) {
152 fprintf(stderr
, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv
[0]);
155 if(options
[FORMAT_VERSION
].doesOccur
) {
156 const char *s
= options
[FORMAT_VERSION
].value
;
157 if(uprv_strlen(s
) != 1 || (s
[0] < '1' && '3' < s
[0])) {
158 fprintf(stderr
, "%s: unsupported --formatVersion %s\n", argv
[0], s
);
160 } else if(s
[0] == '1' &&
161 (options
[WRITE_POOL_BUNDLE
].doesOccur
|| options
[USE_POOL_BUNDLE
].doesOccur
)
163 fprintf(stderr
, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv
[0]);
166 setFormatVersion(s
[0] - '0');
170 if((options
[JAVA_PACKAGE
].doesOccur
|| options
[BUNDLE_NAME
].doesOccur
) &&
171 !options
[WRITE_JAVA
].doesOccur
) {
173 "%s error: command line argument --java-package or --bundle-name "
174 "without --write-java\n",
179 if(options
[VERSION
].doesOccur
) {
181 "%s version %s (ICU version %s).\n"
183 argv
[0], GENRB_VERSION
, U_ICU_VERSION
, U_COPYRIGHT_STRING
);
189 if(illegalArg
|| options
[HELP1
].doesOccur
|| options
[HELP2
].doesOccur
) {
191 * Broken into chunks because the C89 standard says the minimum
192 * required supported string length is 509 bytes.
195 "Usage: %s [OPTIONS] [FILES]\n"
196 "\tReads the list of resource bundle source files and creates\n"
197 "\tbinary version of resource bundles (.res files)\n",
201 "\t-h or -? or --help this usage text\n"
202 "\t-q or --quiet do not display warnings\n"
203 "\t-v or --verbose print extra information when processing files\n"
204 "\t-V or --version prints out version number and exits\n"
205 "\t-c or --copyright include copyright notice\n");
207 "\t-e or --encoding encoding of source files\n"
208 "\t-d or --destdir destination directory, followed by the path, defaults to '%s'\n"
209 "\t-s or --sourcedir source directory for files followed by path, defaults to '%s'\n"
210 "\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
211 "\t followed by path, defaults to '%s'\n",
212 u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory());
214 "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n"
215 "\t defaults to ASCII and \\uXXXX format.\n"
216 "\t --java-package For --write-java: package name for writing the ListResourceBundle,\n"
217 "\t defaults to com.ibm.icu.impl.data\n");
219 "\t-b or --bundle-name For --write-java: root resource bundle name for writing the ListResourceBundle,\n"
220 "\t defaults to LocaleElements\n"
221 "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n"
222 "\t an optional output file name.\n"
223 "\t-k or --strict use pedantic parsing of syntax\n"
225 "\t-l or --language for XLIFF: language code compliant with BCP 47.\n");
227 "\t-C or --noBinaryCollation do not generate binary collation image;\n"
228 "\t makes .res file smaller but collator instantiation much slower;\n"
229 "\t maintains ability to get tailoring rules\n"
230 "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n"
231 "\t makes .res file smaller and maintains collator instantiation speed\n"
232 "\t but tailoring rules will not be available (they are rarely used)\n");
234 "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n"
235 "\t for example, --formatVersion 1\n");
237 "\t --writePoolBundle [directory] write a pool.res file with all of the keys of all input bundles\n"
238 "\t --usePoolBundle [directory] point to keys from the pool.res keys pool bundle if they are available there;\n"
239 "\t makes .res files smaller but dependent on the pool bundle\n"
240 "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n");
242 "\t --filterDir Input directory where filter files are available.\n"
243 "\t For more on filter files, see ICU Data Build Tool.\n");
245 return illegalArg
? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
248 if(options
[VERBOSE
].doesOccur
) {
252 if(options
[QUIET
].doesOccur
) {
253 setShowWarning(FALSE
);
255 if(options
[STRICT
].doesOccur
) {
258 if(options
[COPYRIGHT
].doesOccur
){
259 setIncludeCopyright(TRUE
);
262 if(options
[SOURCEDIR
].doesOccur
) {
263 inputDir
= options
[SOURCEDIR
].value
;
266 if(options
[DESTDIR
].doesOccur
) {
267 outputDir
= options
[DESTDIR
].value
;
270 if (options
[FILTERDIR
].doesOccur
) {
271 filterDir
= options
[FILTERDIR
].value
;
274 if(options
[ENCODING
].doesOccur
) {
275 encoding
= options
[ENCODING
].value
;
278 if(options
[ICUDATADIR
].doesOccur
) {
279 u_setDataDirectory(options
[ICUDATADIR
].value
);
283 if (U_FAILURE(status
) && status
!= U_FILE_ACCESS_ERROR
) {
284 /* Note: u_init() will try to open ICU property data.
285 * failures here are expected when building ICU from scratch.
288 fprintf(stderr
, "%s: can not initialize ICU. status = %s\n",
289 argv
[0], u_errorName(status
));
292 status
= U_ZERO_ERROR
;
293 if(options
[WRITE_JAVA
].doesOccur
) {
295 outputEnc
= options
[WRITE_JAVA
].value
;
298 if(options
[WRITE_XLIFF
].doesOccur
) {
300 if(options
[WRITE_XLIFF
].value
!= NULL
){
301 xliffOutputFileName
= options
[WRITE_XLIFF
].value
;
308 if(options
[LANGUAGE
].doesOccur
) {
309 language
= options
[LANGUAGE
].value
;
312 LocalPointer
<SRBRoot
> newPoolBundle
;
313 if(options
[WRITE_POOL_BUNDLE
].doesOccur
) {
314 newPoolBundle
.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL
, TRUE
, status
), status
);
315 if(U_FAILURE(status
)) {
316 fprintf(stderr
, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status
));
319 const char *poolResName
= "pool.res";
320 char *nameWithoutSuffix
= static_cast<char *>(uprv_malloc(uprv_strlen(poolResName
) + 1));
321 if (nameWithoutSuffix
== NULL
) {
322 fprintf(stderr
, "out of memory error\n");
323 return U_MEMORY_ALLOCATION_ERROR
;
325 uprv_strcpy(nameWithoutSuffix
, poolResName
);
326 *uprv_strrchr(nameWithoutSuffix
, '.') = 0;
327 newPoolBundle
->fLocale
= nameWithoutSuffix
;
331 if(options
[USE_POOL_BUNDLE
].doesOccur
) {
332 const char *poolResName
= "pool.res";
333 FileStream
*poolFile
;
334 int32_t poolFileSize
;
337 * TODO: Consolidate inputDir/filename handling from main() and processFile()
338 * into a common function, and use it here as well.
339 * Try to create toolutil functions for dealing with dir/filenames and
340 * loading ICU data files without udata_open().
341 * Share code with icupkg?
342 * Also, make_res_filename() seems to be unused. Review and remove.
344 CharString poolFileName
;
345 if (options
[USE_POOL_BUNDLE
].value
!=NULL
) {
346 poolFileName
.append(options
[USE_POOL_BUNDLE
].value
, status
);
347 } else if (inputDir
) {
348 poolFileName
.append(inputDir
, status
);
350 poolFileName
.appendPathPart(poolResName
, status
);
351 if (U_FAILURE(status
)) {
354 poolFile
= T_FileStream_open(poolFileName
.data(), "rb");
355 if (poolFile
== NULL
) {
356 fprintf(stderr
, "unable to open pool bundle file %s\n", poolFileName
.data());
359 poolFileSize
= T_FileStream_size(poolFile
);
360 if (poolFileSize
< 32) {
361 fprintf(stderr
, "the pool bundle file %s is too small\n", poolFileName
.data());
364 poolBundle
.fBytes
= new uint8_t[(poolFileSize
+ 15) & ~15];
365 if (poolFileSize
> 0 && poolBundle
.fBytes
== NULL
) {
366 fprintf(stderr
, "unable to allocate memory for the pool bundle file %s\n", poolFileName
.data());
367 return U_MEMORY_ALLOCATION_ERROR
;
371 const DataHeader
*header
;
372 int32_t bytesRead
= T_FileStream_read(poolFile
, poolBundle
.fBytes
, poolFileSize
);
373 if (bytesRead
!= poolFileSize
) {
374 fprintf(stderr
, "unable to read the pool bundle file %s\n", poolFileName
.data());
378 * Swap the pool bundle so that a single checked-in file can be used.
379 * The swapper functions also test that the data looks like
380 * a well-formed .res file.
382 ds
= udata_openSwapperForInputData(poolBundle
.fBytes
, bytesRead
,
383 U_IS_BIG_ENDIAN
, U_CHARSET_FAMILY
, &status
);
384 if (U_FAILURE(status
)) {
385 fprintf(stderr
, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n",
386 poolFileName
.data(), u_errorName(status
));
389 ures_swap(ds
, poolBundle
.fBytes
, bytesRead
, poolBundle
.fBytes
, &status
);
390 udata_closeSwapper(ds
);
391 if (U_FAILURE(status
)) {
392 fprintf(stderr
, "ures_swap(pool bundle %s) failed: %s\n",
393 poolFileName
.data(), u_errorName(status
));
396 header
= (const DataHeader
*)poolBundle
.fBytes
;
397 if (header
->info
.formatVersion
[0] < 2) {
398 fprintf(stderr
, "invalid format of pool bundle file %s\n", poolFileName
.data());
399 return U_INVALID_FORMAT_ERROR
;
401 const int32_t *pRoot
= (const int32_t *)(
402 (const char *)header
+ header
->dataHeader
.headerSize
);
403 poolBundle
.fIndexes
= pRoot
+ 1;
404 indexLength
= poolBundle
.fIndexes
[URES_INDEX_LENGTH
] & 0xff;
405 if (indexLength
<= URES_INDEX_POOL_CHECKSUM
) {
406 fprintf(stderr
, "insufficient indexes[] in pool bundle file %s\n", poolFileName
.data());
407 return U_INVALID_FORMAT_ERROR
;
409 int32_t keysBottom
= 1 + indexLength
;
410 int32_t keysTop
= poolBundle
.fIndexes
[URES_INDEX_KEYS_TOP
];
411 poolBundle
.fKeys
= (const char *)(pRoot
+ keysBottom
);
412 poolBundle
.fKeysLength
= (keysTop
- keysBottom
) * 4;
413 poolBundle
.fChecksum
= poolBundle
.fIndexes
[URES_INDEX_POOL_CHECKSUM
];
415 for (i
= 0; i
< poolBundle
.fKeysLength
; ++i
) {
416 if (poolBundle
.fKeys
[i
] == 0) {
417 ++poolBundle
.fKeysCount
;
421 // 16BitUnits[] begins with strings-v2.
422 // The strings-v2 may optionally be terminated by what looks like
423 // an explicit string length that exceeds the number of remaining 16-bit units.
424 int32_t stringUnitsLength
= (poolBundle
.fIndexes
[URES_INDEX_16BIT_TOP
] - keysTop
) * 2;
425 if (stringUnitsLength
>= 2 && getFormatVersion() >= 3) {
426 poolBundle
.fStrings
= new PseudoListResource(NULL
, status
);
427 if (poolBundle
.fStrings
== NULL
) {
428 fprintf(stderr
, "unable to allocate memory for the pool bundle strings %s\n",
429 poolFileName
.data());
430 return U_MEMORY_ALLOCATION_ERROR
;
432 // The PseudoListResource constructor call did not allocate further memory.
433 assert(U_SUCCESS(status
));
434 const UChar
*p
= (const UChar
*)(pRoot
+ keysTop
);
435 int32_t remaining
= stringUnitsLength
;
438 int8_t numCharsForLength
;
440 if (!U16_IS_TRAIL(first
)) {
442 numCharsForLength
= 0;
444 length
< remaining
&& p
[length
] != 0;
446 } else if (first
< 0xdfef) {
447 numCharsForLength
= 1;
448 length
= first
& 0x3ff;
449 } else if (first
< 0xdfff && remaining
>= 2) {
450 numCharsForLength
= 2;
451 length
= ((first
- 0xdfef) << 16) | p
[1];
452 } else if (first
== 0xdfff && remaining
>= 3) {
453 numCharsForLength
= 3;
454 length
= ((int32_t)p
[1] << 16) | p
[2];
458 // Check for overrun before changing remaining,
459 // so that it is always accurate after the loop body.
460 if ((numCharsForLength
+ length
) >= remaining
||
461 p
[numCharsForLength
+ length
] != 0) {
462 break; // overrun or explicitly terminated
464 int32_t poolStringIndex
= stringUnitsLength
- remaining
;
465 // Maximum pool string index when suffix-sharing the last character.
466 int32_t maxStringIndex
= poolStringIndex
+ numCharsForLength
+ length
- 1;
467 if (maxStringIndex
>= RES_MAX_OFFSET
) {
468 // pool string index overrun
471 p
+= numCharsForLength
;
472 remaining
-= numCharsForLength
;
475 new StringResource(poolStringIndex
, numCharsForLength
,
478 fprintf(stderr
, "unable to allocate memory for a pool bundle string %s\n",
479 poolFileName
.data());
480 return U_MEMORY_ALLOCATION_ERROR
;
482 poolBundle
.fStrings
->add(sr
);
483 poolBundle
.fStringIndexLimit
= maxStringIndex
+ 1;
484 // The StringResource constructor did not allocate further memory.
485 assert(U_SUCCESS(status
));
488 remaining
-= length
+ 1;
489 } while (remaining
> 0);
490 if (poolBundle
.fStrings
->fCount
== 0) {
491 delete poolBundle
.fStrings
;
492 poolBundle
.fStrings
= NULL
;
496 T_FileStream_close(poolFile
);
497 setUsePoolBundle(TRUE
);
498 if (isVerbose() && poolBundle
.fStrings
!= NULL
) {
499 printf("number of shared strings: %d\n", (int)poolBundle
.fStrings
->fCount
);
500 int32_t length
= poolBundle
.fStringIndexLimit
+ 1; // incl. last NUL
501 printf("16-bit units for strings: %6d = %6d bytes\n",
502 (int)length
, (int)length
* 2);
506 if(!options
[FORMAT_VERSION
].doesOccur
&& getFormatVersion() == 3 &&
507 poolBundle
.fStrings
== NULL
&&
508 !options
[WRITE_POOL_BUNDLE
].doesOccur
) {
509 // If we just default to formatVersion 3
510 // but there are no pool bundle strings to share
511 // and we do not write a pool bundle,
512 // then write formatVersion 2 which is just as good.
516 if(options
[INCLUDE_UNIHAN_COLL
].doesOccur
) {
517 puts("genrb option --includeUnihanColl ignored: \n"
518 "CLDR 26/ICU 54 unihan data is small, except\n"
519 "the ucadata-unihan.icu version of the collation root data\n"
520 "is about 300kB larger than the ucadata-implicithan.icu version.");
524 printf("genrb number of files: %d\n", argc
- 1);
526 /* generate the binary files */
527 for(i
= 1; i
< argc
; ++i
) {
528 status
= U_ZERO_ERROR
;
529 arg
= getLongPathname(argv
[i
]);
531 CharString theCurrentFileName
;
533 theCurrentFileName
.append(inputDir
, status
);
535 theCurrentFileName
.appendPathPart(arg
, status
);
536 if (U_FAILURE(status
)) {
540 gCurrentFileName
= theCurrentFileName
.data();
542 printf("Processing file \"%s\"\n", theCurrentFileName
.data());
544 processFile(arg
, encoding
, inputDir
, outputDir
, filterDir
, NULL
,
545 newPoolBundle
.getAlias(),
546 options
[NO_BINARY_COLLATION
].doesOccur
, status
);
551 if(U_SUCCESS(status
) && options
[WRITE_POOL_BUNDLE
].doesOccur
) {
552 const char* writePoolDir
;
553 if (options
[WRITE_POOL_BUNDLE
].value
!=NULL
) {
554 writePoolDir
= options
[WRITE_POOL_BUNDLE
].value
;
556 writePoolDir
= outputDir
;
558 char outputFileName
[256];
559 newPoolBundle
->write(writePoolDir
, NULL
, outputFileName
, sizeof(outputFileName
), status
);
560 if(U_FAILURE(status
)) {
561 fprintf(stderr
, "unable to write the pool bundle: %s\n", u_errorName(status
));
567 /* Dont return warnings as a failure */
568 if (U_SUCCESS(status
)) {
577 processFile(const char *filename
, const char *cp
,
578 const char *inputDir
, const char *outputDir
, const char *filterDir
,
579 const char *packageName
,
580 SRBRoot
*newPoolBundle
,
581 UBool omitBinaryCollation
, UErrorCode
&status
) {
582 LocalPointer
<SRBRoot
> data
;
583 LocalUCHARBUFPointer ucbuf
;
584 CharString openFileName
;
585 CharString inputDirBuf
;
587 char outputFileName
[256];
590 if (U_FAILURE(status
)) {
594 status
=U_ILLEGAL_ARGUMENT_ERROR
;
598 if(inputDir
== NULL
) {
599 const char *filenameBegin
= uprv_strrchr(filename
, U_FILE_SEP_CHAR
);
600 if (filenameBegin
!= NULL
) {
602 * When a filename ../../../data/root.txt is specified,
603 * we presume that the input directory is ../../../data
604 * This is very important when the resource file includes
605 * another file, like UCARules.txt or thaidict.brk.
607 int32_t filenameSize
= (int32_t)(filenameBegin
- filename
+ 1);
608 inputDirBuf
.append(filename
, filenameSize
, status
);
610 inputDir
= inputDirBuf
.data();
611 dirlen
= inputDirBuf
.length();
614 dirlen
= (int32_t)uprv_strlen(inputDir
);
616 if(inputDir
[dirlen
-1] != U_FILE_SEP_CHAR
) {
618 * append the input dir to openFileName if the first char in
619 * filename is not file seperation char and the last char input directory is not '.'.
620 * This is to support :
621 * genrb -s. /home/icu/data
623 * The user cannot mix notations like
624 * genrb -s. /icu/data --- the absolute path specified. -s redundant
626 * genrb -s. icu/data --- start from CWD and look in icu/data dir
628 if( (filename
[0] != U_FILE_SEP_CHAR
) && (inputDir
[dirlen
-1] !='.')){
629 openFileName
.append(inputDir
, status
);
632 openFileName
.append(inputDir
, status
);
635 openFileName
.appendPathPart(filename
, status
);
637 // Test for CharString failure
638 if (U_FAILURE(status
)) {
642 ucbuf
.adoptInstead(ucbuf_open(openFileName
.data(), &cp
,getShowWarning(),TRUE
, &status
));
643 if(status
== U_FILE_ACCESS_ERROR
) {
645 fprintf(stderr
, "couldn't open file %s\n", openFileName
.data());
648 if (ucbuf
.isNull() || U_FAILURE(status
)) {
649 fprintf(stderr
, "An error occurred processing file %s. Error: %s\n",
650 openFileName
.data(), u_errorName(status
));
653 /* auto detected popular encodings? */
654 if (cp
!=NULL
&& isVerbose()) {
655 printf("autodetected encoding %s\n", cp
);
657 /* Parse the data into an SRBRoot */
658 data
.adoptInstead(parse(ucbuf
.getAlias(), inputDir
, outputDir
, filename
,
659 !omitBinaryCollation
, options
[NO_COLLATION_RULES
].doesOccur
, &status
));
661 if (data
.isNull() || U_FAILURE(status
)) {
662 fprintf(stderr
, "couldn't parse the file %s. Error:%s\n", filename
, u_errorName(status
));
666 // Run filtering before writing pool bundle
667 if (filterDir
!= nullptr) {
668 CharString
filterFileName(filterDir
, status
);
669 filterFileName
.appendPathPart(filename
, status
);
670 if (U_FAILURE(status
)) {
674 // Open the file and read it into filter
675 SimpleRuleBasedPathFilter filter
;
676 std::ifstream
f(filterFileName
.data());
678 std::cerr
<< "genrb error: unable to open " << filterFileName
.data() << std::endl
;
679 status
= U_FILE_ACCESS_ERROR
;
682 std::string currentLine
;
683 while (std::getline(f
, currentLine
)) {
684 // Ignore # comments and empty lines
685 if (currentLine
.empty() || currentLine
[0] == '#') {
688 filter
.addRule(currentLine
, status
);
689 if (U_FAILURE(status
)) {
695 filter
.print(std::cout
);
698 // Apply the filter to the data
700 data
->fRoot
->applyFilter(filter
, path
, data
.getAlias());
703 if(options
[WRITE_POOL_BUNDLE
].doesOccur
) {
704 data
->fWritePoolBundle
= newPoolBundle
;
705 data
->compactKeys(status
);
706 int32_t newKeysLength
;
707 const char *newKeys
= data
->getKeyBytes(&newKeysLength
);
708 newPoolBundle
->addKeyBytes(newKeys
, newKeysLength
, status
);
709 if(U_FAILURE(status
)) {
710 fprintf(stderr
, "bundle_compactKeys(%s) or bundle_getKeyBytes() failed: %s\n",
711 filename
, u_errorName(status
));
714 /* count the number of just-added key strings */
715 for(const char *newKeysLimit
= newKeys
+ newKeysLength
; newKeys
< newKeysLimit
; ++newKeys
) {
717 ++newPoolBundle
->fKeysCount
;
722 if(options
[USE_POOL_BUNDLE
].doesOccur
) {
723 data
->fUsePoolBundle
= &poolBundle
;
726 /* Determine the target rb filename */
727 uprv_free(make_res_filename(filename
, outputDir
, packageName
, status
));
728 if(U_FAILURE(status
)) {
729 fprintf(stderr
, "couldn't make the res fileName for bundle %s. Error:%s\n",
730 filename
, u_errorName(status
));
733 if(write_java
== TRUE
){
734 bundle_write_java(data
.getAlias(), outputDir
, outputEnc
,
735 outputFileName
, sizeof(outputFileName
),
736 options
[JAVA_PACKAGE
].value
, options
[BUNDLE_NAME
].value
, &status
);
737 }else if(write_xliff
==TRUE
){
738 bundle_write_xml(data
.getAlias(), outputDir
, outputEnc
,
739 filename
, outputFileName
, sizeof(outputFileName
),
740 language
, xliffOutputFileName
, &status
);
742 /* Write the data to the file */
743 data
->write(outputDir
, packageName
, outputFileName
, sizeof(outputFileName
), status
);
745 if (U_FAILURE(status
)) {
746 fprintf(stderr
, "couldn't write bundle %s. Error:%s\n", outputFileName
, u_errorName(status
));
750 /* Generate the target .res file name from the input file name */
752 make_res_filename(const char *filename
,
753 const char *outputDir
,
754 const char *packageName
,
755 UErrorCode
&status
) {
760 int32_t pkgLen
= 0; /* length of package prefix */
763 if (U_FAILURE(status
)) {
767 if(packageName
!= NULL
)
769 pkgLen
= (int32_t)(1 + uprv_strlen(packageName
));
773 basename
= dirname
= resName
= 0;
775 /* determine basename, and compiled file names */
776 basename
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename
) + 1));
778 status
= U_MEMORY_ALLOCATION_ERROR
;
782 get_basename(basename
, filename
);
784 dirname
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename
) + 1));
786 status
= U_MEMORY_ALLOCATION_ERROR
;
790 get_dirname(dirname
, filename
);
792 if (outputDir
== NULL
) {
793 /* output in same dir as .txt */
794 resName
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(dirname
)
796 + uprv_strlen(basename
)
797 + uprv_strlen(RES_SUFFIX
) + 8));
799 status
= U_MEMORY_ALLOCATION_ERROR
;
803 uprv_strcpy(resName
, dirname
);
805 if(packageName
!= NULL
)
807 uprv_strcat(resName
, packageName
);
808 uprv_strcat(resName
, "_");
811 uprv_strcat(resName
, basename
);
814 int32_t dirlen
= (int32_t)uprv_strlen(outputDir
);
815 int32_t basenamelen
= (int32_t)uprv_strlen(basename
);
817 resName
= (char*) uprv_malloc(sizeof(char) * (dirlen
+ pkgLen
+ basenamelen
+ 8));
819 if (resName
== NULL
) {
820 status
= U_MEMORY_ALLOCATION_ERROR
;
824 uprv_strcpy(resName
, outputDir
);
826 if(outputDir
[dirlen
] != U_FILE_SEP_CHAR
) {
827 resName
[dirlen
] = U_FILE_SEP_CHAR
;
828 resName
[dirlen
+ 1] = '\0';
831 if(packageName
!= NULL
)
833 uprv_strcat(resName
, packageName
);
834 uprv_strcat(resName
, "_");
837 uprv_strcat(resName
, basename
);
849 * indent-tabs-mode: nil