+ if(options[WRITE_POOL_BUNDLE].doesOccur) {
+ newPoolBundle = bundle_open(NULL, TRUE, &status);
+ if(U_FAILURE(status)) {
+ fprintf(stderr, "unable to create an empty bundle for the pool keys: %s\n", u_errorName(status));
+ return status;
+ } else {
+ const char *poolResName = "pool.res";
+ char *nameWithoutSuffix = uprv_malloc(uprv_strlen(poolResName) + 1);
+ if (nameWithoutSuffix == NULL) {
+ fprintf(stderr, "out of memory error\n");
+ return U_MEMORY_ALLOCATION_ERROR;
+ }
+ uprv_strcpy(nameWithoutSuffix, poolResName);
+ *uprv_strrchr(nameWithoutSuffix, '.') = 0;
+ newPoolBundle->fLocale = nameWithoutSuffix;
+ }
+ }
+
+ if(options[USE_POOL_BUNDLE].doesOccur) {
+ const char *poolResName = "pool.res";
+ FileStream *poolFile;
+ int32_t poolFileSize;
+ int32_t indexLength;
+ /*
+ * TODO: Consolidate inputDir/filename handling from main() and processFile()
+ * into a common function, and use it here as well.
+ * Try to create toolutil functions for dealing with dir/filenames and
+ * loading ICU data files without udata_open().
+ * Share code with icupkg?
+ * Also, make_res_filename() seems to be unused. Review and remove.
+ */
+ if (options[USE_POOL_BUNDLE].value!=NULL) {
+ uprv_strcpy(theCurrentFileName, options[USE_POOL_BUNDLE].value);
+ uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING);
+ } else if (inputDir) {
+ uprv_strcpy(theCurrentFileName, inputDir);
+ uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING);
+ } else {
+ *theCurrentFileName = 0;
+ }
+ uprv_strcat(theCurrentFileName, poolResName);
+ poolFile = T_FileStream_open(theCurrentFileName, "rb");
+ if (poolFile == NULL) {
+ fprintf(stderr, "unable to open pool bundle file %s\n", theCurrentFileName);
+ return 1;
+ }
+ poolFileSize = T_FileStream_size(poolFile);
+ if (poolFileSize < 32) {
+ fprintf(stderr, "the pool bundle file %s is too small\n", theCurrentFileName);
+ return 1;
+ }
+ poolBundle.fBytes = (uint8_t *)uprv_malloc((poolFileSize + 15) & ~15);
+ if (poolFileSize > 0 && poolBundle.fBytes == NULL) {
+ fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", theCurrentFileName);
+ return U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ UDataSwapper *ds;
+ const DataHeader *header;
+ int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize);
+ int32_t keysBottom;
+ if (bytesRead != poolFileSize) {
+ fprintf(stderr, "unable to read the pool bundle file %s\n", theCurrentFileName);
+ return 1;
+ }
+ /*
+ * Swap the pool bundle so that a single checked-in file can be used.
+ * The swapper functions also test that the data looks like
+ * a well-formed .res file.
+ */
+ ds = udata_openSwapperForInputData(poolBundle.fBytes, bytesRead,
+ U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &status);
+ if (U_FAILURE(status)) {
+ fprintf(stderr, "udata_openSwapperForInputData(pool bundle %s) failed: %s\n",
+ theCurrentFileName, u_errorName(status));
+ return status;
+ }
+ ures_swap(ds, poolBundle.fBytes, bytesRead, poolBundle.fBytes, &status);
+ udata_closeSwapper(ds);
+ if (U_FAILURE(status)) {
+ fprintf(stderr, "ures_swap(pool bundle %s) failed: %s\n",
+ theCurrentFileName, u_errorName(status));
+ return status;
+ }
+ header = (const DataHeader *)poolBundle.fBytes;
+ if (header->info.formatVersion[0]!=2) {
+ fprintf(stderr, "invalid format of pool bundle file %s\n", theCurrentFileName);
+ return U_INVALID_FORMAT_ERROR;
+ }
+ poolBundle.fKeys = (const char *)header + header->dataHeader.headerSize;
+ poolBundle.fIndexes = (const int32_t *)poolBundle.fKeys + 1;
+ indexLength = poolBundle.fIndexes[URES_INDEX_LENGTH] & 0xff;
+ if (indexLength <= URES_INDEX_POOL_CHECKSUM) {
+ fprintf(stderr, "insufficient indexes[] in pool bundle file %s\n", theCurrentFileName);
+ return U_INVALID_FORMAT_ERROR;
+ }
+ keysBottom = (1 + indexLength) * 4;
+ poolBundle.fKeys += keysBottom;
+ poolBundle.fKeysLength = (poolBundle.fIndexes[URES_INDEX_KEYS_TOP] * 4) - keysBottom;
+ poolBundle.fChecksum = poolBundle.fIndexes[URES_INDEX_POOL_CHECKSUM];
+ }
+ for (i = 0; i < poolBundle.fKeysLength; ++i) {
+ if (poolBundle.fKeys[i] == 0) {
+ ++poolBundle.fKeysCount;
+ }
+ }
+ T_FileStream_close(poolFile);
+ setUsePoolBundle(TRUE);
+ }
+
+ if(options[INCLUDE_UNIHAN_COLL].doesOccur) {
+ gIncludeUnihanColl = TRUE;
+ }
+
+ if((argc-1)!=1) {
+ printf("genrb number of files: %d\n", argc - 1);
+ }