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 *******************************************************************************
23 #include "unicode/localpointer.h"
24 #include "unicode/uclean.h"
25 #include "unicode/utf16.h"
29 #include "ucmndata.h" /* TODO: for reading the pool bundle */
34 void processFile(const char *filename
, const char* cp
, const char *inputDir
, const char *outputDir
,
35 const char *packageName
,
36 SRBRoot
*newPoolBundle
, UBool omitBinaryCollation
, UErrorCode
&status
);
37 static char *make_res_filename(const char *filename
, const char *outputDir
,
38 const char *packageName
, UErrorCode
&status
);
41 #define RES_SUFFIX ".res"
42 #define COL_SUFFIX ".col"
44 const char *gCurrentFileName
= NULL
;
49 void ResFile::close() {
84 UOPTION_HELP_QUESTION_MARK
,
94 UOPTION_DEF("java-package", '\x01', UOPT_REQUIRES_ARG
),
96 UOPTION_DEF("write-xliff", 'x', UOPT_OPTIONAL_ARG
),
97 UOPTION_DEF("strict", 'k', UOPT_NO_ARG
), /* 14 */
98 UOPTION_DEF("noBinaryCollation", 'C', UOPT_NO_ARG
),/* 15 */
99 UOPTION_DEF("language", 'l', UOPT_REQUIRES_ARG
), /* 16 */
100 UOPTION_DEF("omitCollationRules", 'R', UOPT_NO_ARG
),/* 17 */
101 UOPTION_DEF("formatVersion", '\x01', UOPT_REQUIRES_ARG
),/* 18 */
102 UOPTION_DEF("writePoolBundle", '\x01', UOPT_NO_ARG
),/* 19 */
103 UOPTION_DEF("usePoolBundle", '\x01', UOPT_OPTIONAL_ARG
),/* 20 */
104 UOPTION_DEF("includeUnihanColl", '\x01', UOPT_NO_ARG
),/* 21 */ /* temporary, don't display in usage info */
107 static UBool write_java
= FALSE
;
108 static UBool write_xliff
= FALSE
;
109 static const char* outputEnc
="";
111 static ResFile poolBundle
;
114 static const char* language
= NULL
;
115 static const char* xliffOutputFileName
= NULL
;
120 UErrorCode status
= U_ZERO_ERROR
;
121 const char *arg
= NULL
;
122 const char *outputDir
= NULL
; /* NULL = no output directory, use current */
123 const char *inputDir
= NULL
;
124 const char *encoding
= "";
126 UBool illegalArg
= FALSE
;
128 U_MAIN_INIT_ARGS(argc
, argv
);
130 options
[JAVA_PACKAGE
].value
= "com.ibm.icu.impl.data";
131 options
[BUNDLE_NAME
].value
= "LocaleElements";
132 argc
= u_parseArgs(argc
, argv
, UPRV_LENGTHOF(options
), options
);
134 /* error handling, printing usage message */
136 fprintf(stderr
, "%s: error in command line argument \"%s\"\n", argv
[0], argv
[-argc
]);
141 if(options
[WRITE_POOL_BUNDLE
].doesOccur
&& options
[USE_POOL_BUNDLE
].doesOccur
) {
142 fprintf(stderr
, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv
[0]);
145 if(options
[FORMAT_VERSION
].doesOccur
) {
146 const char *s
= options
[FORMAT_VERSION
].value
;
147 if(uprv_strlen(s
) != 1 || (s
[0] < '1' && '3' < s
[0])) {
148 fprintf(stderr
, "%s: unsupported --formatVersion %s\n", argv
[0], s
);
150 } else if(s
[0] == '1' &&
151 (options
[WRITE_POOL_BUNDLE
].doesOccur
|| options
[USE_POOL_BUNDLE
].doesOccur
)
153 fprintf(stderr
, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv
[0]);
156 setFormatVersion(s
[0] - '0');
160 if((options
[JAVA_PACKAGE
].doesOccur
|| options
[BUNDLE_NAME
].doesOccur
) &&
161 !options
[WRITE_JAVA
].doesOccur
) {
163 "%s error: command line argument --java-package or --bundle-name "
164 "without --write-java\n",
169 if(options
[VERSION
].doesOccur
) {
171 "%s version %s (ICU version %s).\n"
173 argv
[0], GENRB_VERSION
, U_ICU_VERSION
, U_COPYRIGHT_STRING
);
179 if(illegalArg
|| options
[HELP1
].doesOccur
|| options
[HELP2
].doesOccur
) {
181 * Broken into chunks because the C89 standard says the minimum
182 * required supported string length is 509 bytes.
185 "Usage: %s [OPTIONS] [FILES]\n"
186 "\tReads the list of resource bundle source files and creates\n"
187 "\tbinary version of resource bundles (.res files)\n",
191 "\t-h or -? or --help this usage text\n"
192 "\t-q or --quiet do not display warnings\n"
193 "\t-v or --verbose print extra information when processing files\n"
194 "\t-V or --version prints out version number and exits\n"
195 "\t-c or --copyright include copyright notice\n");
197 "\t-e or --encoding encoding of source files\n"
198 "\t-d of --destdir destination directory, followed by the path, defaults to %s\n"
199 "\t-s or --sourcedir source directory for files followed by path, defaults to %s\n"
200 "\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
201 "\t followed by path, defaults to %s\n",
202 u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory());
204 "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n"
205 "\t defaults to ASCII and \\uXXXX format.\n"
206 "\t --java-package For --write-java: package name for writing the ListResourceBundle,\n"
207 "\t defaults to com.ibm.icu.impl.data\n");
209 "\t-b or --bundle-name For --write-java: root resource bundle name for writing the ListResourceBundle,\n"
210 "\t defaults to LocaleElements\n"
211 "\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n"
212 "\t an optional output file name.\n"
213 "\t-k or --strict use pedantic parsing of syntax\n"
215 "\t-l or --language for XLIFF: language code compliant with BCP 47.\n");
217 "\t-C or --noBinaryCollation do not generate binary collation image;\n"
218 "\t makes .res file smaller but collator instantiation much slower;\n"
219 "\t maintains ability to get tailoring rules\n"
220 "\t-R or --omitCollationRules do not include collation (tailoring) rules;\n"
221 "\t makes .res file smaller and maintains collator instantiation speed\n"
222 "\t but tailoring rules will not be available (they are rarely used)\n");
224 "\t --formatVersion write a .res file compatible with the requested formatVersion (single digit);\n"
225 "\t for example, --formatVersion 1\n");
227 "\t --writePoolBundle write a pool.res file with all of the keys of all input bundles\n"
228 "\t --usePoolBundle [path-to-pool.res] point to keys from the pool.res keys pool bundle if they are available there;\n"
229 "\t makes .res files smaller but dependent on the pool bundle\n"
230 "\t (--writePoolBundle and --usePoolBundle cannot be combined)\n");
232 return illegalArg
? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
235 if(options
[VERBOSE
].doesOccur
) {
239 if(options
[QUIET
].doesOccur
) {
240 setShowWarning(FALSE
);
242 if(options
[STRICT
].doesOccur
) {
245 if(options
[COPYRIGHT
].doesOccur
){
246 setIncludeCopyright(TRUE
);
249 if(options
[SOURCEDIR
].doesOccur
) {
250 inputDir
= options
[SOURCEDIR
].value
;
253 if(options
[DESTDIR
].doesOccur
) {
254 outputDir
= options
[DESTDIR
].value
;
257 if(options
[ENCODING
].doesOccur
) {
258 encoding
= options
[ENCODING
].value
;
261 if(options
[ICUDATADIR
].doesOccur
) {
262 u_setDataDirectory(options
[ICUDATADIR
].value
);
266 if (U_FAILURE(status
) && status
!= U_FILE_ACCESS_ERROR
) {
267 /* Note: u_init() will try to open ICU property data.
268 * failures here are expected when building ICU from scratch.
271 fprintf(stderr
, "%s: can not initialize ICU. status = %s\n",
272 argv
[0], u_errorName(status
));
275 status
= U_ZERO_ERROR
;
276 if(options
[WRITE_JAVA
].doesOccur
) {
278 outputEnc
= options
[WRITE_JAVA
].value
;
281 if(options
[WRITE_XLIFF
].doesOccur
) {
283 if(options
[WRITE_XLIFF
].value
!= NULL
){
284 xliffOutputFileName
= options
[WRITE_XLIFF
].value
;
291 if(options
[LANGUAGE
].doesOccur
) {
292 language
= options
[LANGUAGE
].value
;
295 LocalPointer
<SRBRoot
> newPoolBundle
;
296 if(options
[WRITE_POOL_BUNDLE
].doesOccur
) {
297 newPoolBundle
.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL
, TRUE
, status
), status
);
298 if(U_FAILURE(status
)) {
299 fprintf(stderr
, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status
));
302 const char *poolResName
= "pool.res";
303 char *nameWithoutSuffix
= static_cast<char *>(uprv_malloc(uprv_strlen(poolResName
) + 1));
304 if (nameWithoutSuffix
== NULL
) {
305 fprintf(stderr
, "out of memory error\n");
306 return U_MEMORY_ALLOCATION_ERROR
;
308 uprv_strcpy(nameWithoutSuffix
, poolResName
);
309 *uprv_strrchr(nameWithoutSuffix
, '.') = 0;
310 newPoolBundle
->fLocale
= nameWithoutSuffix
;
314 if(options
[USE_POOL_BUNDLE
].doesOccur
) {
315 const char *poolResName
= "pool.res";
316 FileStream
*poolFile
;
317 int32_t poolFileSize
;
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.
327 CharString poolFileName
;
328 if (options
[USE_POOL_BUNDLE
].value
!=NULL
) {
329 poolFileName
.append(options
[USE_POOL_BUNDLE
].value
, status
);
330 } else if (inputDir
) {
331 poolFileName
.append(inputDir
, status
);
333 poolFileName
.appendPathPart(poolResName
, status
);
334 if (U_FAILURE(status
)) {
337 poolFile
= T_FileStream_open(poolFileName
.data(), "rb");
338 if (poolFile
== NULL
) {
339 fprintf(stderr
, "unable to open pool bundle file %s\n", poolFileName
.data());
342 poolFileSize
= T_FileStream_size(poolFile
);
343 if (poolFileSize
< 32) {
344 fprintf(stderr
, "the pool bundle file %s is too small\n", poolFileName
.data());
347 poolBundle
.fBytes
= new uint8_t[(poolFileSize
+ 15) & ~15];
348 if (poolFileSize
> 0 && poolBundle
.fBytes
== NULL
) {
349 fprintf(stderr
, "unable to allocate memory for the pool bundle file %s\n", poolFileName
.data());
350 return U_MEMORY_ALLOCATION_ERROR
;
354 const DataHeader
*header
;
355 int32_t bytesRead
= T_FileStream_read(poolFile
, poolBundle
.fBytes
, poolFileSize
);
356 if (bytesRead
!= poolFileSize
) {
357 fprintf(stderr
, "unable to read the pool bundle file %s\n", poolFileName
.data());
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.
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 poolFileName
.data(), u_errorName(status
));
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 poolFileName
.data(), u_errorName(status
));
379 header
= (const DataHeader
*)poolBundle
.fBytes
;
380 if (header
->info
.formatVersion
[0] < 2) {
381 fprintf(stderr
, "invalid format of pool bundle file %s\n", poolFileName
.data());
382 return U_INVALID_FORMAT_ERROR
;
384 const int32_t *pRoot
= (const int32_t *)(
385 (const char *)header
+ header
->dataHeader
.headerSize
);
386 poolBundle
.fIndexes
= pRoot
+ 1;
387 indexLength
= poolBundle
.fIndexes
[URES_INDEX_LENGTH
] & 0xff;
388 if (indexLength
<= URES_INDEX_POOL_CHECKSUM
) {
389 fprintf(stderr
, "insufficient indexes[] in pool bundle file %s\n", poolFileName
.data());
390 return U_INVALID_FORMAT_ERROR
;
392 int32_t keysBottom
= 1 + indexLength
;
393 int32_t keysTop
= poolBundle
.fIndexes
[URES_INDEX_KEYS_TOP
];
394 poolBundle
.fKeys
= (const char *)(pRoot
+ keysBottom
);
395 poolBundle
.fKeysLength
= (keysTop
- keysBottom
) * 4;
396 poolBundle
.fChecksum
= poolBundle
.fIndexes
[URES_INDEX_POOL_CHECKSUM
];
398 for (i
= 0; i
< poolBundle
.fKeysLength
; ++i
) {
399 if (poolBundle
.fKeys
[i
] == 0) {
400 ++poolBundle
.fKeysCount
;
404 // 16BitUnits[] begins with strings-v2.
405 // The strings-v2 may optionally be terminated by what looks like
406 // an explicit string length that exceeds the number of remaining 16-bit units.
407 int32_t stringUnitsLength
= (poolBundle
.fIndexes
[URES_INDEX_16BIT_TOP
] - keysTop
) * 2;
408 if (stringUnitsLength
>= 2 && getFormatVersion() >= 3) {
409 poolBundle
.fStrings
= new PseudoListResource(NULL
, status
);
410 if (poolBundle
.fStrings
== NULL
) {
411 fprintf(stderr
, "unable to allocate memory for the pool bundle strings %s\n",
412 poolFileName
.data());
413 return U_MEMORY_ALLOCATION_ERROR
;
415 // The PseudoListResource constructor call did not allocate further memory.
416 assert(U_SUCCESS(status
));
417 const UChar
*p
= (const UChar
*)(pRoot
+ keysTop
);
418 int32_t remaining
= stringUnitsLength
;
421 int8_t numCharsForLength
;
423 if (!U16_IS_TRAIL(first
)) {
425 numCharsForLength
= 0;
427 length
< remaining
&& p
[length
] != 0;
429 } else if (first
< 0xdfef) {
430 numCharsForLength
= 1;
431 length
= first
& 0x3ff;
432 } else if (first
< 0xdfff && remaining
>= 2) {
433 numCharsForLength
= 2;
434 length
= ((first
- 0xdfef) << 16) | p
[1];
435 } else if (first
== 0xdfff && remaining
>= 3) {
436 numCharsForLength
= 3;
437 length
= ((int32_t)p
[1] << 16) | p
[2];
441 // Check for overrun before changing remaining,
442 // so that it is always accurate after the loop body.
443 if ((numCharsForLength
+ length
) >= remaining
||
444 p
[numCharsForLength
+ length
] != 0) {
445 break; // overrun or explicitly terminated
447 int32_t poolStringIndex
= stringUnitsLength
- remaining
;
448 // Maximum pool string index when suffix-sharing the last character.
449 int32_t maxStringIndex
= poolStringIndex
+ numCharsForLength
+ length
- 1;
450 if (maxStringIndex
>= RES_MAX_OFFSET
) {
451 // pool string index overrun
454 p
+= numCharsForLength
;
455 remaining
-= numCharsForLength
;
458 new StringResource(poolStringIndex
, numCharsForLength
,
461 fprintf(stderr
, "unable to allocate memory for a pool bundle string %s\n",
462 poolFileName
.data());
463 return U_MEMORY_ALLOCATION_ERROR
;
465 poolBundle
.fStrings
->add(sr
);
466 poolBundle
.fStringIndexLimit
= maxStringIndex
+ 1;
467 // The StringResource constructor did not allocate further memory.
468 assert(U_SUCCESS(status
));
471 remaining
-= length
+ 1;
472 } while (remaining
> 0);
473 if (poolBundle
.fStrings
->fCount
== 0) {
474 delete poolBundle
.fStrings
;
475 poolBundle
.fStrings
= NULL
;
479 T_FileStream_close(poolFile
);
480 setUsePoolBundle(TRUE
);
481 if (isVerbose() && poolBundle
.fStrings
!= NULL
) {
482 printf("number of shared strings: %d\n", (int)poolBundle
.fStrings
->fCount
);
483 int32_t length
= poolBundle
.fStringIndexLimit
+ 1; // incl. last NUL
484 printf("16-bit units for strings: %6d = %6d bytes\n",
485 (int)length
, (int)length
* 2);
489 if(!options
[FORMAT_VERSION
].doesOccur
&& getFormatVersion() == 3 &&
490 poolBundle
.fStrings
== NULL
&&
491 !options
[WRITE_POOL_BUNDLE
].doesOccur
) {
492 // If we just default to formatVersion 3
493 // but there are no pool bundle strings to share
494 // and we do not write a pool bundle,
495 // then write formatVersion 2 which is just as good.
499 if(options
[INCLUDE_UNIHAN_COLL
].doesOccur
) {
500 puts("genrb option --includeUnihanColl ignored: \n"
501 "CLDR 26/ICU 54 unihan data is small, except\n"
502 "the ucadata-unihan.icu version of the collation root data\n"
503 "is about 300kB larger than the ucadata-implicithan.icu version.");
507 printf("genrb number of files: %d\n", argc
- 1);
509 /* generate the binary files */
510 for(i
= 1; i
< argc
; ++i
) {
511 status
= U_ZERO_ERROR
;
512 arg
= getLongPathname(argv
[i
]);
514 CharString theCurrentFileName
;
516 theCurrentFileName
.append(inputDir
, status
);
518 theCurrentFileName
.appendPathPart(arg
, status
);
519 if (U_FAILURE(status
)) {
523 gCurrentFileName
= theCurrentFileName
.data();
525 printf("Processing file \"%s\"\n", theCurrentFileName
.data());
527 processFile(arg
, encoding
, inputDir
, outputDir
, NULL
,
528 newPoolBundle
.getAlias(),
529 options
[NO_BINARY_COLLATION
].doesOccur
, status
);
534 if(U_SUCCESS(status
) && options
[WRITE_POOL_BUNDLE
].doesOccur
) {
535 char outputFileName
[256];
536 newPoolBundle
->write(outputDir
, NULL
, outputFileName
, sizeof(outputFileName
), status
);
537 if(U_FAILURE(status
)) {
538 fprintf(stderr
, "unable to write the pool bundle: %s\n", u_errorName(status
));
544 /* Dont return warnings as a failure */
545 if (U_SUCCESS(status
)) {
554 processFile(const char *filename
, const char *cp
,
555 const char *inputDir
, const char *outputDir
, const char *packageName
,
556 SRBRoot
*newPoolBundle
,
557 UBool omitBinaryCollation
, UErrorCode
&status
) {
558 LocalPointer
<SRBRoot
> data
;
559 UCHARBUF
*ucbuf
= NULL
;
561 char *openFileName
= NULL
;
562 char *inputDirBuf
= NULL
;
564 char outputFileName
[256];
569 if (U_FAILURE(status
)) {
573 status
=U_ILLEGAL_ARGUMENT_ERROR
;
576 filelen
= (int32_t)uprv_strlen(filename
);
579 if(inputDir
== NULL
) {
580 const char *filenameBegin
= uprv_strrchr(filename
, U_FILE_SEP_CHAR
);
581 openFileName
= (char *) uprv_malloc(dirlen
+ filelen
+ 2);
582 openFileName
[0] = '\0';
583 if (filenameBegin
!= NULL
) {
585 * When a filename ../../../data/root.txt is specified,
586 * we presume that the input directory is ../../../data
587 * This is very important when the resource file includes
588 * another file, like UCARules.txt or thaidict.brk.
590 int32_t filenameSize
= (int32_t)(filenameBegin
- filename
+ 1);
591 inputDirBuf
= uprv_strncpy((char *)uprv_malloc(filenameSize
), filename
, filenameSize
);
594 if(inputDirBuf
== NULL
) {
595 status
= U_MEMORY_ALLOCATION_ERROR
;
599 inputDirBuf
[filenameSize
- 1] = 0;
600 inputDir
= inputDirBuf
;
601 dirlen
= (int32_t)uprv_strlen(inputDir
);
604 dirlen
= (int32_t)uprv_strlen(inputDir
);
606 if(inputDir
[dirlen
-1] != U_FILE_SEP_CHAR
) {
607 openFileName
= (char *) uprv_malloc(dirlen
+ filelen
+ 2);
610 if(openFileName
== NULL
) {
611 status
= U_MEMORY_ALLOCATION_ERROR
;
615 openFileName
[0] = '\0';
617 * append the input dir to openFileName if the first char in
618 * filename is not file seperation char and the last char input directory is not '.'.
619 * This is to support :
620 * genrb -s. /home/icu/data
622 * The user cannot mix notations like
623 * genrb -s. /icu/data --- the absolute path specified. -s redundant
625 * genrb -s. icu/data --- start from CWD and look in icu/data dir
627 if( (filename
[0] != U_FILE_SEP_CHAR
) && (inputDir
[dirlen
-1] !='.')){
628 uprv_strcpy(openFileName
, inputDir
);
629 openFileName
[dirlen
] = U_FILE_SEP_CHAR
;
631 openFileName
[dirlen
+ 1] = '\0';
633 openFileName
= (char *) uprv_malloc(dirlen
+ filelen
+ 1);
636 if(openFileName
== NULL
) {
637 status
= U_MEMORY_ALLOCATION_ERROR
;
641 uprv_strcpy(openFileName
, inputDir
);
646 uprv_strcat(openFileName
, filename
);
648 ucbuf
= ucbuf_open(openFileName
, &cp
,getShowWarning(),TRUE
, &status
);
649 if(status
== U_FILE_ACCESS_ERROR
) {
651 fprintf(stderr
, "couldn't open file %s\n", openFileName
== NULL
? filename
: openFileName
);
654 if (ucbuf
== NULL
|| U_FAILURE(status
)) {
655 fprintf(stderr
, "An error occured processing file %s. Error: %s\n",
656 openFileName
== NULL
? filename
: openFileName
, u_errorName(status
));
659 /* auto detected popular encodings? */
660 if (cp
!=NULL
&& isVerbose()) {
661 printf("autodetected encoding %s\n", cp
);
663 /* Parse the data into an SRBRoot */
664 data
.adoptInstead(parse(ucbuf
, inputDir
, outputDir
, filename
,
665 !omitBinaryCollation
, options
[NO_COLLATION_RULES
].doesOccur
, &status
));
667 if (data
.isNull() || U_FAILURE(status
)) {
668 fprintf(stderr
, "couldn't parse the file %s. Error:%s\n", filename
, u_errorName(status
));
671 if(options
[WRITE_POOL_BUNDLE
].doesOccur
) {
672 data
->fWritePoolBundle
= newPoolBundle
;
673 data
->compactKeys(status
);
674 int32_t newKeysLength
;
675 const char *newKeys
= data
->getKeyBytes(&newKeysLength
);
676 newPoolBundle
->addKeyBytes(newKeys
, newKeysLength
, status
);
677 if(U_FAILURE(status
)) {
678 fprintf(stderr
, "bundle_compactKeys(%s) or bundle_getKeyBytes() failed: %s\n",
679 filename
, u_errorName(status
));
682 /* count the number of just-added key strings */
683 for(const char *newKeysLimit
= newKeys
+ newKeysLength
; newKeys
< newKeysLimit
; ++newKeys
) {
685 ++newPoolBundle
->fKeysCount
;
690 if(options
[USE_POOL_BUNDLE
].doesOccur
) {
691 data
->fUsePoolBundle
= &poolBundle
;
694 /* Determine the target rb filename */
695 rbname
= make_res_filename(filename
, outputDir
, packageName
, status
);
696 if(U_FAILURE(status
)) {
697 fprintf(stderr
, "couldn't make the res fileName for bundle %s. Error:%s\n",
698 filename
, u_errorName(status
));
701 if(write_java
== TRUE
){
702 bundle_write_java(data
.getAlias(), outputDir
, outputEnc
,
703 outputFileName
, sizeof(outputFileName
),
704 options
[JAVA_PACKAGE
].value
, options
[BUNDLE_NAME
].value
, &status
);
705 }else if(write_xliff
==TRUE
){
706 bundle_write_xml(data
.getAlias(), outputDir
, outputEnc
,
707 filename
, outputFileName
, sizeof(outputFileName
),
708 language
, xliffOutputFileName
, &status
);
710 /* Write the data to the file */
711 data
->write(outputDir
, packageName
, outputFileName
, sizeof(outputFileName
), status
);
713 if (U_FAILURE(status
)) {
714 fprintf(stderr
, "couldn't write bundle %s. Error:%s\n", outputFileName
, u_errorName(status
));
719 if (inputDirBuf
!= NULL
) {
720 uprv_free(inputDirBuf
);
723 if (openFileName
!= NULL
) {
724 uprv_free(openFileName
);
736 /* Generate the target .res file name from the input file name */
738 make_res_filename(const char *filename
,
739 const char *outputDir
,
740 const char *packageName
,
741 UErrorCode
&status
) {
746 int32_t pkgLen
= 0; /* length of package prefix */
749 if (U_FAILURE(status
)) {
753 if(packageName
!= NULL
)
755 pkgLen
= (int32_t)(1 + uprv_strlen(packageName
));
759 basename
= dirname
= resName
= 0;
761 /* determine basename, and compiled file names */
762 basename
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename
) + 1));
764 status
= U_MEMORY_ALLOCATION_ERROR
;
768 get_basename(basename
, filename
);
770 dirname
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename
) + 1));
772 status
= U_MEMORY_ALLOCATION_ERROR
;
776 get_dirname(dirname
, filename
);
778 if (outputDir
== NULL
) {
779 /* output in same dir as .txt */
780 resName
= (char*) uprv_malloc(sizeof(char) * (uprv_strlen(dirname
)
782 + uprv_strlen(basename
)
783 + uprv_strlen(RES_SUFFIX
) + 8));
785 status
= U_MEMORY_ALLOCATION_ERROR
;
789 uprv_strcpy(resName
, dirname
);
791 if(packageName
!= NULL
)
793 uprv_strcat(resName
, packageName
);
794 uprv_strcat(resName
, "_");
797 uprv_strcat(resName
, basename
);
800 int32_t dirlen
= (int32_t)uprv_strlen(outputDir
);
801 int32_t basenamelen
= (int32_t)uprv_strlen(basename
);
803 resName
= (char*) uprv_malloc(sizeof(char) * (dirlen
+ pkgLen
+ basenamelen
+ 8));
805 if (resName
== NULL
) {
806 status
= U_MEMORY_ALLOCATION_ERROR
;
810 uprv_strcpy(resName
, outputDir
);
812 if(outputDir
[dirlen
] != U_FILE_SEP_CHAR
) {
813 resName
[dirlen
] = U_FILE_SEP_CHAR
;
814 resName
[dirlen
+ 1] = '\0';
817 if(packageName
!= NULL
)
819 uprv_strcat(resName
, packageName
);
820 uprv_strcat(resName
, "_");
823 uprv_strcat(resName
, basename
);
835 * indent-tabs-mode: nil