2 *******************************************************************************
4 * Copyright (C) 1998-2016, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 05/25/99 stephen Creation.
15 * 5/10/01 Ram removed ustdio dependency
16 *******************************************************************************
21 #include "unicode/localpointer.h"
22 #include "unicode/uclean.h"
23 #include "unicode/utf16.h"
27 #include "ucmndata.h" /* TODO: for reading the pool bundle */
32 void processFile(const char *filename
, const char* cp
, const char *inputDir
, const char *outputDir
,
33 const char *packageName
,
34 SRBRoot
*newPoolBundle
, UBool omitBinaryCollation
, UErrorCode
&status
);
35 static char *make_res_filename(const char *filename
, const char *outputDir
,
36 const char *packageName
, UErrorCode
&status
);
39 #define RES_SUFFIX ".res"
40 #define COL_SUFFIX ".col"
42 const char *gCurrentFileName
= NULL
;
47 void ResFile::close() {
82 UOPTION_HELP_QUESTION_MARK
,
92 UOPTION_DEF("java-package", '\x01', UOPT_REQUIRES_ARG
),
94 UOPTION_DEF("write-xliff", 'x', UOPT_OPTIONAL_ARG
),
95 UOPTION_DEF("strict", 'k', UOPT_NO_ARG
), /* 14 */
96 UOPTION_DEF("noBinaryCollation", 'C', UOPT_NO_ARG
),/* 15 */
97 UOPTION_DEF("language", 'l', UOPT_REQUIRES_ARG
), /* 16 */
98 UOPTION_DEF("omitCollationRules", 'R', UOPT_NO_ARG
),/* 17 */
99 UOPTION_DEF("formatVersion", '\x01', UOPT_REQUIRES_ARG
),/* 18 */
100 UOPTION_DEF("writePoolBundle", '\x01', UOPT_NO_ARG
),/* 19 */
101 UOPTION_DEF("usePoolBundle", '\x01', UOPT_OPTIONAL_ARG
),/* 20 */
102 UOPTION_DEF("includeUnihanColl", '\x01', UOPT_NO_ARG
),/* 21 */ /* temporary, don't display in usage info */
105 static UBool write_java
= FALSE
;
106 static UBool write_xliff
= FALSE
;
107 static const char* outputEnc
="";
109 static ResFile poolBundle
;
112 static const char* language
= NULL
;
113 static const char* xliffOutputFileName
= NULL
;
118 UErrorCode status
= U_ZERO_ERROR
;
119 const char *arg
= NULL
;
120 const char *outputDir
= NULL
; /* NULL = no output directory, use current */
121 const char *inputDir
= NULL
;
122 const char *encoding
= "";
124 UBool illegalArg
= FALSE
;
126 U_MAIN_INIT_ARGS(argc
, argv
);
128 options
[JAVA_PACKAGE
].value
= "com.ibm.icu.impl.data";
129 options
[BUNDLE_NAME
].value
= "LocaleElements";
130 argc
= u_parseArgs(argc
, argv
, UPRV_LENGTHOF(options
), options
);
132 /* error handling, printing usage message */
134 fprintf(stderr
, "%s: error in command line argument \"%s\"\n", argv
[0], argv
[-argc
]);
139 if(options
[WRITE_POOL_BUNDLE
].doesOccur
&& options
[USE_POOL_BUNDLE
].doesOccur
) {
140 fprintf(stderr
, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv
[0]);
143 if(options
[FORMAT_VERSION
].doesOccur
) {
144 const char *s
= options
[FORMAT_VERSION
].value
;
145 if(uprv_strlen(s
) != 1 || (s
[0] < '1' && '3' < s
[0])) {
146 fprintf(stderr
, "%s: unsupported --formatVersion %s\n", argv
[0], s
);
148 } else if(s
[0] == '1' &&
149 (options
[WRITE_POOL_BUNDLE
].doesOccur
|| options
[USE_POOL_BUNDLE
].doesOccur
)
151 fprintf(stderr
, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv
[0]);
154 setFormatVersion(s
[0] - '0');
158 if((options
[JAVA_PACKAGE
].doesOccur
|| options
[BUNDLE_NAME
].doesOccur
) &&
159 !options
[WRITE_JAVA
].doesOccur
) {
161 "%s error: command line argument --java-package or --bundle-name "
162 "without --write-java\n",
167 if(options
[VERSION
].doesOccur
) {
169 "%s version %s (ICU version %s).\n"
171 argv
[0], GENRB_VERSION
, U_ICU_VERSION
, U_COPYRIGHT_STRING
);
177 if(illegalArg
|| options
[HELP1
].doesOccur
|| options
[HELP2
].doesOccur
) {
179 * Broken into chunks because the C89 standard says the minimum
180 * required supported string length is 509 bytes.
183 "Usage: %s [OPTIONS] [FILES]\n"
184 "\tReads the list of resource bundle source files and creates\n"
185 "\tbinary version of resource bundles (.res files)\n",
189 "\t-h or -? or --help this usage text\n"
190 "\t-q or --quiet do not display warnings\n"
191 "\t-v or --verbose print extra information when processing files\n"
192 "\t-V or --version prints out version number and exits\n"
193 "\t-c or --copyright include copyright notice\n");
195 "\t-e or --encoding encoding of source files\n"
196 "\t-d of --destdir destination directory, followed by the path, defaults to %s\n"
197 "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n"
198 "\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
199 "\t followed by path, defaults to %s\n",
200 u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory());
202 "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n"
203 "\t defaults to ASCII and \\uXXXX format.\n"
204 "\t --java-package For --write-java: package name for writing the ListResourceBundle,\n"
205 "\t defaults to com.ibm.icu.impl.data\n");
207 "\t-b or --bundle-name For --write-java: root resource bundle name for writing the ListResourceBundle,\n"
208 "\t defaults to LocaleElements\n"
209 "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n"
210 "\t an optional output file name.\n"
211 "\t-k or --strict use pedantic parsing of syntax\n"
213 "\t-l or --language for XLIFF: language code compliant with BCP 47.\n");
215 "\t-C or --noBinaryCollation do not generate binary collation image;\n"
216 "\t makes .res file smaller but collator instantiation much slower;\n"
217 "\t maintains ability to get tailoring rules\n"
218 "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n"
219 "\t makes .res file smaller and maintains collator instantiation speed\n"
220 "\t but tailoring rules will not be available (they are rarely used)\n");
222 "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n"
223 "\t for example, --formatVersion 1\n");
225 "\t --writePoolBundle write a pool.res file with all of the keys of all input bundles\n"
226 "\t --usePoolBundle [path-to-pool.res] point to keys from the pool.res keys pool bundle if they are available there;\n"
227 "\t makes .res files smaller but dependent on the pool bundle\n"
228 "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n");
230 return illegalArg
? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
233 if(options
[VERBOSE
].doesOccur
) {
237 if(options
[QUIET
].doesOccur
) {
238 setShowWarning(FALSE
);
240 if(options
[STRICT
].doesOccur
) {
243 if(options
[COPYRIGHT
].doesOccur
){
244 setIncludeCopyright(TRUE
);
247 if(options
[SOURCEDIR
].doesOccur
) {
248 inputDir
= options
[SOURCEDIR
].value
;
251 if(options
[DESTDIR
].doesOccur
) {
252 outputDir
= options
[DESTDIR
].value
;
255 if(options
[ENCODING
].doesOccur
) {
256 encoding
= options
[ENCODING
].value
;
259 if(options
[ICUDATADIR
].doesOccur
) {
260 u_setDataDirectory(options
[ICUDATADIR
].value
);
264 if (U_FAILURE(status
) && status
!= U_FILE_ACCESS_ERROR
) {
265 /* Note: u_init() will try to open ICU property data.
266 * failures here are expected when building ICU from scratch.
269 fprintf(stderr
, "%s: can not initialize ICU. status = %s\n",
270 argv
[0], u_errorName(status
));
273 status
= U_ZERO_ERROR
;
274 if(options
[WRITE_JAVA
].doesOccur
) {
276 outputEnc
= options
[WRITE_JAVA
].value
;
279 if(options
[WRITE_XLIFF
].doesOccur
) {
281 if(options
[WRITE_XLIFF
].value
!= NULL
){
282 xliffOutputFileName
= options
[WRITE_XLIFF
].value
;
289 if(options
[LANGUAGE
].doesOccur
) {
290 language
= options
[LANGUAGE
].value
;
293 LocalPointer
<SRBRoot
> newPoolBundle
;
294 if(options
[WRITE_POOL_BUNDLE
].doesOccur
) {
295 newPoolBundle
.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL
, TRUE
, status
), status
);
296 if(U_FAILURE(status
)) {
297 fprintf(stderr
, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status
));
300 const char *poolResName
= "pool.res";
301 char *nameWithoutSuffix
= static_cast<char *>(uprv_malloc(uprv_strlen(poolResName
) + 1));
302 if (nameWithoutSuffix
== NULL
) {
303 fprintf(stderr
, "out of memory error\n");
304 return U_MEMORY_ALLOCATION_ERROR
;
306 uprv_strcpy(nameWithoutSuffix
, poolResName
);
307 *uprv_strrchr(nameWithoutSuffix
, '.') = 0;
308 newPoolBundle
->fLocale
= nameWithoutSuffix
;
312 if(options
[USE_POOL_BUNDLE
].doesOccur
) {
313 const char *poolResName
= "pool.res";
314 FileStream
*poolFile
;
315 int32_t poolFileSize
;
318 * TODO: Consolidate inputDir/filename handling from main() and processFile()
319 * into a common function, and use it here as well.
320 * Try to create toolutil functions for dealing with dir/filenames and
321 * loading ICU data files without udata_open().
322 * Share code with icupkg?
323 * Also, make_res_filename() seems to be unused. Review and remove.
325 CharString poolFileName
;
326 if (options
[USE_POOL_BUNDLE
].value
!=NULL
) {
327 poolFileName
.append(options
[USE_POOL_BUNDLE
].value
, status
);
328 } else if (inputDir
) {
329 poolFileName
.append(inputDir
, status
);
331 poolFileName
.appendPathPart(poolResName
, status
);
332 if (U_FAILURE(status
)) {
335 poolFile
= T_FileStream_open(poolFileName
.data(), "rb");
336 if (poolFile
== NULL
) {
337 fprintf(stderr
, "unable to open pool bundle file %s\n", poolFileName
.data());
340 poolFileSize
= T_FileStream_size(poolFile
);
341 if (poolFileSize
< 32) {
342 fprintf(stderr
, "the pool bundle file %s is too small\n", poolFileName
.data());
345 poolBundle
.fBytes
= new uint8_t[(poolFileSize
+ 15) & ~15];
346 if (poolFileSize
> 0 && poolBundle
.fBytes
== NULL
) {
347 fprintf(stderr
, "unable to allocate memory for the pool bundle file %s\n", poolFileName
.data());
348 return U_MEMORY_ALLOCATION_ERROR
;
352 const DataHeader
*header
;
353 int32_t bytesRead
= T_FileStream_read(poolFile
, poolBundle
.fBytes
, poolFileSize
);
354 if (bytesRead
!= poolFileSize
) {
355 fprintf(stderr
, "unable to read the pool bundle file %s\n", poolFileName
.data());
359 * Swap the pool bundle so that a single checked-in file can be used.
360 * The swapper functions also test that the data looks like
361 * a well-formed .res file.
363 ds
= udata_openSwapperForInputData(poolBundle
.fBytes
, bytesRead
,
364 U_IS_BIG_ENDIAN
, U_CHARSET_FAMILY
, &status
);
365 if (U_FAILURE(status
)) {
366 fprintf(stderr
, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n",
367 poolFileName
.data(), u_errorName(status
));
370 ures_swap(ds
, poolBundle
.fBytes
, bytesRead
, poolBundle
.fBytes
, &status
);
371 udata_closeSwapper(ds
);
372 if (U_FAILURE(status
)) {
373 fprintf(stderr
, "ures_swap(pool bundle %s) failed: %s\n",
374 poolFileName
.data(), u_errorName(status
));
377 header
= (const DataHeader
*)poolBundle
.fBytes
;
378 if (header
->info
.formatVersion
[0] < 2) {
379 fprintf(stderr
, "invalid format of pool bundle file %s\n", poolFileName
.data());
380 return U_INVALID_FORMAT_ERROR
;
382 const int32_t *pRoot
= (const int32_t *)(
383 (const char *)header
+ header
->dataHeader
.headerSize
);
384 poolBundle
.fIndexes
= pRoot
+ 1;
385 indexLength
= poolBundle
.fIndexes
[URES_INDEX_LENGTH
] & 0xff;
386 if (indexLength
<= URES_INDEX_POOL_CHECKSUM
) {
387 fprintf(stderr
, "insufficient indexes[] in pool bundle file %s\n", poolFileName
.data());
388 return U_INVALID_FORMAT_ERROR
;
390 int32_t keysBottom
= 1 + indexLength
;
391 int32_t keysTop
= poolBundle
.fIndexes
[URES_INDEX_KEYS_TOP
];
392 poolBundle
.fKeys
= (const char *)(pRoot
+ keysBottom
);
393 poolBundle
.fKeysLength
= (keysTop
- keysBottom
) * 4;
394 poolBundle
.fChecksum
= poolBundle
.fIndexes
[URES_INDEX_POOL_CHECKSUM
];
396 for (i
= 0; i
< poolBundle
.fKeysLength
; ++i
) {
397 if (poolBundle
.fKeys
[i
] == 0) {
398 ++poolBundle
.fKeysCount
;
402 // 16BitUnits[] begins with strings-v2.
403 // The strings-v2 may optionally be terminated by what looks like
404 // an explicit string length that exceeds the number of remaining 16-bit units.
405 int32_t stringUnitsLength
= (poolBundle
.fIndexes
[URES_INDEX_16BIT_TOP
] - keysTop
) * 2;
406 if (stringUnitsLength
>= 2 && getFormatVersion() >= 3) {
407 poolBundle
.fStrings
= new PseudoListResource(NULL
, status
);
408 if (poolBundle
.fStrings
== NULL
) {
409 fprintf(stderr
, "unable to allocate memory for the pool bundle strings %s\n",
410 poolFileName
.data());
411 return U_MEMORY_ALLOCATION_ERROR
;
413 // The PseudoListResource constructor call did not allocate further memory.
414 assert(U_SUCCESS(status
));
415 const UChar
*p
= (const UChar
*)(pRoot
+ keysTop
);
416 int32_t remaining
= stringUnitsLength
;
419 int8_t numCharsForLength
;
421 if (!U16_IS_TRAIL(first
)) {
423 numCharsForLength
= 0;
425 length
< remaining
&& p
[length
] != 0;
427 } else if (first
< 0xdfef) {
428 numCharsForLength
= 1;
429 length
= first
& 0x3ff;
430 } else if (first
< 0xdfff && remaining
>= 2) {
431 numCharsForLength
= 2;
432 length
= ((first
- 0xdfef) << 16) | p
[1];
433 } else if (first
== 0xdfff && remaining
>= 3) {
434 numCharsForLength
= 3;
435 length
= ((int32_t)p
[1] << 16) | p
[2];
439 // Check for overrun before changing remaining,
440 // so that it is always accurate after the loop body.
441 if ((numCharsForLength
+ length
) >= remaining
||
442 p
[numCharsForLength
+ length
] != 0) {
443 break; // overrun or explicitly terminated
445 int32_t poolStringIndex
= stringUnitsLength
- remaining
;
446 // Maximum pool string index when suffix-sharing the last character.
447 int32_t maxStringIndex
= poolStringIndex
+ numCharsForLength
+ length
- 1;
448 if (maxStringIndex
>= RES_MAX_OFFSET
) {
449 // pool string index overrun
452 p
+= numCharsForLength
;
453 remaining
-= numCharsForLength
;
456 new StringResource(poolStringIndex
, numCharsForLength
,
459 fprintf(stderr
, "unable to allocate memory for a pool bundle string %s\n",
460 poolFileName
.data());
461 return U_MEMORY_ALLOCATION_ERROR
;
463 poolBundle
.fStrings
->add(sr
);
464 poolBundle
.fStringIndexLimit
= maxStringIndex
+ 1;
465 // The StringResource constructor did not allocate further memory.
466 assert(U_SUCCESS(status
));
469 remaining
-= length
+ 1;
470 } while (remaining
> 0);
471 if (poolBundle
.fStrings
->fCount
== 0) {
472 delete poolBundle
.fStrings
;
473 poolBundle
.fStrings
= NULL
;
477 T_FileStream_close(poolFile
);
478 setUsePoolBundle(TRUE
);
479 if (isVerbose() && poolBundle
.fStrings
!= NULL
) {
480 printf("number of shared strings: %d\n", (int)poolBundle
.fStrings
->fCount
);
481 int32_t length
= poolBundle
.fStringIndexLimit
+ 1; // incl. last NUL
482 printf("16-bit units for strings: %6d = %6d bytes\n",
483 (int)length
, (int)length
* 2);
487 if(!options
[FORMAT_VERSION
].doesOccur
&& getFormatVersion() == 3 &&
488 poolBundle
.fStrings
== NULL
&&
489 !options
[WRITE_POOL_BUNDLE
].doesOccur
) {
490 // If we just default to formatVersion 3
491 // but there are no pool bundle strings to share
492 // and we do not write a pool bundle,
493 // then write formatVersion 2 which is just as good.
497 if(options
[INCLUDE_UNIHAN_COLL
].doesOccur
) {
498 puts("genrb option --includeUnihanColl ignored: \n"
499 "CLDR 26/ICU 54 unihan data is small, except\n"
500 "the ucadata-unihan.icu version of the collation root data\n"
501 "is about 300kB larger than the ucadata-implicithan.icu version.");
505 printf("genrb number of files: %d\n", argc
- 1);
507 /* generate the binary files */
508 for(i
= 1; i
< argc
; ++i
) {
509 status
= U_ZERO_ERROR
;
510 arg
= getLongPathname(argv
[i
]);
512 CharString theCurrentFileName
;
514 theCurrentFileName
.append(inputDir
, status
);
516 theCurrentFileName
.appendPathPart(arg
, status
);
517 if (U_FAILURE(status
)) {
521 gCurrentFileName
= theCurrentFileName
.data();
523 printf("Processing file \"%s\"\n", theCurrentFileName
.data());
525 processFile(arg
, encoding
, inputDir
, outputDir
, NULL
,
526 newPoolBundle
.getAlias(),
527 options
[NO_BINARY_COLLATION
].doesOccur
, status
);
532 if(U_SUCCESS(status
) && options
[WRITE_POOL_BUNDLE
].doesOccur
) {
533 char outputFileName
[256];
534 newPoolBundle
->write(outputDir
, NULL
, outputFileName
, sizeof(outputFileName
), status
);
535 if(U_FAILURE(status
)) {
536 fprintf(stderr
, "unable to write the pool bundle: %s\n", u_errorName(status
));
542 /* Dont return warnings as a failure */
543 if (U_SUCCESS(status
)) {
552 processFile(const char *filename
, const char *cp
,
553 const char *inputDir
, const char *outputDir
, const char *packageName
,
554 SRBRoot
*newPoolBundle
,
555 UBool omitBinaryCollation
, UErrorCode
&status
) {
556 LocalPointer
<SRBRoot
> data
;
557 UCHARBUF
*ucbuf
= NULL
;
559 char *openFileName
= NULL
;
560 char *inputDirBuf
= NULL
;
562 char outputFileName
[256];
567 if (U_FAILURE(status
)) {
571 status
=U_ILLEGAL_ARGUMENT_ERROR
;
574 filelen
= (int32_t)uprv_strlen(filename
);
577 if(inputDir
== NULL
) {
578 const char *filenameBegin
= uprv_strrchr(filename
, U_FILE_SEP_CHAR
);
579 openFileName
= (char *) uprv_malloc(dirlen
+ filelen
+ 2);
580 openFileName
[0] = '\0';
581 if (filenameBegin
!= NULL
) {
583 * When a filename ../../../data/root.txt is specified,
584 * we presume that the input directory is ../../../data
585 * This is very important when the resource file includes
586 * another file, like UCARules.txt or thaidict.brk.
588 int32_t filenameSize
= (int32_t)(filenameBegin
- filename
+ 1);
589 inputDirBuf
= uprv_strncpy((char *)uprv_malloc(filenameSize
), filename
, filenameSize
);
592 if(inputDirBuf
== NULL
) {
593 status
= U_MEMORY_ALLOCATION_ERROR
;
597 inputDirBuf
[filenameSize
- 1] = 0;
598 inputDir
= inputDirBuf
;
599 dirlen
= (int32_t)uprv_strlen(inputDir
);
602 dirlen
= (int32_t)uprv_strlen(inputDir
);
604 if(inputDir
[dirlen
-1] != U_FILE_SEP_CHAR
) {
605 openFileName
= (char *) uprv_malloc(dirlen
+ filelen
+ 2);
608 if(openFileName
== NULL
) {
609 status
= U_MEMORY_ALLOCATION_ERROR
;
613 openFileName
[0] = '\0';
615 * append the input dir to openFileName if the first char in
616 * filename is not file seperation char and the last char input directory is not '.'.
617 * This is to support :
618 * genrb -s. /home/icu/data
620 * The user cannot mix notations like
621 * genrb -s. /icu/data --- the absolute path specified. -s redundant
623 * genrb -s. icu/data --- start from CWD and look in icu/data dir
625 if( (filename
[0] != U_FILE_SEP_CHAR
) && (inputDir
[dirlen
-1] !='.')){
626 uprv_strcpy(openFileName
, inputDir
);
627 openFileName
[dirlen
] = U_FILE_SEP_CHAR
;
629 openFileName
[dirlen
+ 1] = '\0';
631 openFileName
= (char *) uprv_malloc(dirlen
+ filelen
+ 1);
634 if(openFileName
== NULL
) {
635 status
= U_MEMORY_ALLOCATION_ERROR
;
639 uprv_strcpy(openFileName
, inputDir
);
644 uprv_strcat(openFileName
, filename
);
646 ucbuf
= ucbuf_open(openFileName
, &cp
,getShowWarning(),TRUE
, &status
);
647 if(status
== U_FILE_ACCESS_ERROR
) {
649 fprintf(stderr
, "couldn't open file %s\n", openFileName
== NULL
? filename
: openFileName
);
652 if (ucbuf
== NULL
|| U_FAILURE(status
)) {
653 fprintf(stderr
, "An error occured processing file %s. Error: %s\n",
654 openFileName
== NULL
? filename
: openFileName
, u_errorName(status
));
657 /* auto detected popular encodings? */
658 if (cp
!=NULL
&& isVerbose()) {
659 printf("autodetected encoding %s\n", cp
);
661 /* Parse the data into an SRBRoot */
662 data
.adoptInstead(parse(ucbuf
, inputDir
, outputDir
, filename
,
663 !omitBinaryCollation
, options
[NO_COLLATION_RULES
].doesOccur
, &status
));
665 if (data
.isNull() || U_FAILURE(status
)) {
666 fprintf(stderr
, "couldn't parse the file %s. Error:%s\n", filename
, u_errorName(status
));
669 if(options
[WRITE_POOL_BUNDLE
].doesOccur
) {
670 data
->fWritePoolBundle
= newPoolBundle
;
671 data
->compactKeys(status
);
672 int32_t newKeysLength
;
673 const char *newKeys
= data
->getKeyBytes(&newKeysLength
);
674 newPoolBundle
->addKeyBytes(newKeys
, newKeysLength
, status
);
675 if(U_FAILURE(status
)) {
676 fprintf(stderr
, "bundle_compactKeys(%s) or bundle_getKeyBytes() failed: %s\n",
677 filename
, u_errorName(status
));
680 /* count the number of just-added key strings */
681 for(const char *newKeysLimit
= newKeys
+ newKeysLength
; newKeys
< newKeysLimit
; ++newKeys
) {
683 ++newPoolBundle
->fKeysCount
;
688 if(options
[USE_POOL_BUNDLE
].doesOccur
) {
689 data
->fUsePoolBundle
= &poolBundle
;
692 /* Determine the target rb filename */
693 rbname
= make_res_filename(filename
, outputDir
, packageName
, status
);
694 if(U_FAILURE(status
)) {
695 fprintf(stderr
, "couldn't make the res fileName for bundle %s. Error:%s\n",
696 filename
, u_errorName(status
));
699 if(write_java
== TRUE
){
700 bundle_write_java(data
.getAlias(), outputDir
, outputEnc
,
701 outputFileName
, sizeof(outputFileName
),
702 options
[JAVA_PACKAGE
].value
, options
[BUNDLE_NAME
].value
, &status
);
703 }else if(write_xliff
==TRUE
){
704 bundle_write_xml(data
.getAlias(), outputDir
, outputEnc
,
705 filename
, outputFileName
, sizeof(outputFileName
),
706 language
, xliffOutputFileName
, &status
);
708 /* Write the data to the file */
709 data
->write(outputDir
, packageName
, outputFileName
, sizeof(outputFileName
), status
);
711 if (U_FAILURE(status
)) {
712 fprintf(stderr
, "couldn't write bundle %s. Error:%s\n", outputFileName
, u_errorName(status
));
717 if (inputDirBuf
!= NULL
) {
718 uprv_free(inputDirBuf
);
721 if (openFileName
!= NULL
) {
722 uprv_free(openFileName
);
734 /* Generate the target .res file name from the input file name */
736 make_res_filename(const char *filename
,
737 const char *outputDir
,
738 const char *packageName
,
739 UErrorCode
&status
) {
744 int32_t pkgLen
= 0; /* length of package prefix */
747 if (U_FAILURE(status
)) {
751 if(packageName
!= NULL
)
753 pkgLen
= (int32_t)(1 + uprv_strlen(packageName
));
757 basename
= dirname
= resName
= 0;
759 /* determine basename, and compiled file names */
760 basename
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename
) + 1));
762 status
= U_MEMORY_ALLOCATION_ERROR
;
766 get_basename(basename
, filename
);
768 dirname
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename
) + 1));
770 status
= U_MEMORY_ALLOCATION_ERROR
;
774 get_dirname(dirname
, filename
);
776 if (outputDir
== NULL
) {
777 /* output in same dir as .txt */
778 resName
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(dirname
)
780 + uprv_strlen(basename
)
781 + uprv_strlen(RES_SUFFIX
) + 8));
783 status
= U_MEMORY_ALLOCATION_ERROR
;
787 uprv_strcpy(resName
, dirname
);
789 if(packageName
!= NULL
)
791 uprv_strcat(resName
, packageName
);
792 uprv_strcat(resName
, "_");
795 uprv_strcat(resName
, basename
);
798 int32_t dirlen
= (int32_t)uprv_strlen(outputDir
);
799 int32_t basenamelen
= (int32_t)uprv_strlen(basename
);
801 resName
= (char*) uprv_malloc(sizeof(char) * (dirlen
+ pkgLen
+ basenamelen
+ 8));
803 if (resName
== NULL
) {
804 status
= U_MEMORY_ALLOCATION_ERROR
;
808 uprv_strcpy(resName
, outputDir
);
810 if(outputDir
[dirlen
] != U_FILE_SEP_CHAR
) {
811 resName
[dirlen
] = U_FILE_SEP_CHAR
;
812 resName
[dirlen
+ 1] = '\0';
815 if(packageName
!= NULL
)
817 uprv_strcat(resName
, packageName
);
818 uprv_strcat(resName
, "_");
821 uprv_strcat(resName
, basename
);
833 * indent-tabs-mode: nil