Index: source/tools/genrb/genrb.cpp |
diff --git a/source/tools/genrb/genrb.c b/source/tools/genrb/genrb.cpp |
similarity index 64% |
rename from source/tools/genrb/genrb.c |
rename to source/tools/genrb/genrb.cpp |
index 85c02897e6a5cced1336791b2352baa3824961f6..720ace6183e4f8a8ff56e4745d959ba349f325ff 100644 |
--- a/source/tools/genrb/genrb.c |
+++ b/source/tools/genrb/genrb.cpp |
@@ -1,12 +1,12 @@ |
/* |
******************************************************************************* |
* |
-* Copyright (C) 1998-2014, International Business Machines |
+* Copyright (C) 1998-2015, International Business Machines |
* Corporation and others. All Rights Reserved. |
* |
******************************************************************************* |
* |
-* File genrb.c |
+* File genrb.cpp |
* |
* Modification History: |
* |
@@ -16,27 +16,40 @@ |
******************************************************************************* |
*/ |
+#include <assert.h> |
#include "genrb.h" |
+#include "unicode/localpointer.h" |
#include "unicode/uclean.h" |
- |
+#include "unicode/utf16.h" |
+#include "charstr.h" |
+#include "reslist.h" |
#include "ucmndata.h" /* TODO: for reading the pool bundle */ |
+U_NAMESPACE_USE |
+ |
/* Protos */ |
void processFile(const char *filename, const char* cp, const char *inputDir, const char *outputDir, |
- const char *packageName, UBool omitBinaryCollation, UErrorCode *status); |
+ const char *packageName, |
+ SRBRoot *newPoolBundle, UBool omitBinaryCollation, UErrorCode &status); |
static char *make_res_filename(const char *filename, const char *outputDir, |
- const char *packageName, UErrorCode *status); |
+ const char *packageName, UErrorCode &status); |
/* File suffixes */ |
#define RES_SUFFIX ".res" |
#define COL_SUFFIX ".col" |
-static char theCurrentFileName[2048]; |
-const char *gCurrentFileName = theCurrentFileName; |
+const char *gCurrentFileName = NULL; |
#ifdef XP_MAC_CONSOLE |
#include <console.h> |
#endif |
+void ResFile::close() { |
+ delete[] fBytes; |
+ fBytes = NULL; |
+ delete fStrings; |
+ fStrings = NULL; |
+} |
+ |
enum |
{ |
HELP1, |
@@ -91,19 +104,8 @@ UOption options[]={ |
static UBool write_java = FALSE; |
static UBool write_xliff = FALSE; |
static const char* outputEnc =""; |
-static struct SRBRoot *newPoolBundle = NULL; |
- |
-/* TODO: separate header file for ResFile? */ |
-typedef struct ResFile { |
- uint8_t *fBytes; |
- const int32_t *fIndexes; |
- const char *fKeys; |
- int32_t fKeysLength; |
- int32_t fKeysCount; |
- int32_t fChecksum; |
-} ResFile; |
-static ResFile poolBundle = { NULL }; |
+static ResFile poolBundle; |
/*added by Jing*/ |
static const char* language = NULL; |
@@ -129,40 +131,31 @@ main(int argc, |
/* error handling, printing usage message */ |
if(argc<0) { |
fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]); |
+ illegalArg = TRUE; |
} else if(argc<2) { |
- argc = -1; |
+ illegalArg = TRUE; |
} |
if(options[WRITE_POOL_BUNDLE].doesOccur && options[USE_POOL_BUNDLE].doesOccur) { |
fprintf(stderr, "%s: cannot combine --writePoolBundle and --usePoolBundle\n", argv[0]); |
- argc = -1; |
+ illegalArg = TRUE; |
} |
if(options[FORMAT_VERSION].doesOccur) { |
const char *s = options[FORMAT_VERSION].value; |
- if(uprv_strlen(s) != 1 || (s[0] != '1' && s[0] != '2')) { |
+ if(uprv_strlen(s) != 1 || (s[0] < '1' && '3' < s[0])) { |
fprintf(stderr, "%s: unsupported --formatVersion %s\n", argv[0], s); |
- argc = -1; |
+ illegalArg = TRUE; |
} else if(s[0] == '1' && |
(options[WRITE_POOL_BUNDLE].doesOccur || options[USE_POOL_BUNDLE].doesOccur) |
) { |
fprintf(stderr, "%s: cannot combine --formatVersion 1 with --writePoolBundle or --usePoolBundle\n", argv[0]); |
- argc = -1; |
+ illegalArg = TRUE; |
} else { |
setFormatVersion(s[0] - '0'); |
} |
} |
- if(options[VERSION].doesOccur) { |
- fprintf(stderr, |
- "%s version %s (ICU version %s).\n" |
- "%s\n", |
- argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); |
- return U_ZERO_ERROR; |
- } |
- |
- if(argc<0) { |
- illegalArg = TRUE; |
- } else if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) && |
- !options[WRITE_JAVA].doesOccur) { |
+ if((options[JAVA_PACKAGE].doesOccur || options[BUNDLE_NAME].doesOccur) && |
+ !options[WRITE_JAVA].doesOccur) { |
fprintf(stderr, |
"%s error: command line argument --java-package or --bundle-name " |
"without --write-java\n", |
@@ -170,6 +163,16 @@ main(int argc, |
illegalArg = TRUE; |
} |
+ if(options[VERSION].doesOccur) { |
+ fprintf(stderr, |
+ "%s version %s (ICU version %s).\n" |
+ "%s\n", |
+ argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); |
+ if(!illegalArg) { |
+ return U_ZERO_ERROR; |
+ } |
+ } |
+ |
if(illegalArg || options[HELP1].doesOccur || options[HELP2].doesOccur) { |
/* |
* Broken into chunks because the C89 standard says the minimum |
@@ -286,14 +289,15 @@ main(int argc, |
language = options[LANGUAGE].value; |
} |
+ LocalPointer<SRBRoot> newPoolBundle; |
if(options[WRITE_POOL_BUNDLE].doesOccur) { |
- newPoolBundle = bundle_open(NULL, TRUE, &status); |
+ newPoolBundle.adoptInsteadAndCheckErrorCode(new SRBRoot(NULL, TRUE, status), 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); |
+ char *nameWithoutSuffix = static_cast<char *>(uprv_malloc(uprv_strlen(poolResName) + 1)); |
if (nameWithoutSuffix == NULL) { |
fprintf(stderr, "out of memory error\n"); |
return U_MEMORY_ALLOCATION_ERROR; |
@@ -317,82 +321,176 @@ main(int argc, |
* Share code with icupkg? |
* Also, make_res_filename() seems to be unused. Review and remove. |
*/ |
+ CharString poolFileName; |
if (options[USE_POOL_BUNDLE].value!=NULL) { |
- uprv_strcpy(theCurrentFileName, options[USE_POOL_BUNDLE].value); |
- uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); |
+ poolFileName.append(options[USE_POOL_BUNDLE].value, status); |
} else if (inputDir) { |
- uprv_strcpy(theCurrentFileName, inputDir); |
- uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); |
- } else { |
- *theCurrentFileName = 0; |
+ poolFileName.append(inputDir, status); |
+ } |
+ poolFileName.appendPathPart(poolResName, status); |
+ if (U_FAILURE(status)) { |
+ return status; |
} |
- uprv_strcat(theCurrentFileName, poolResName); |
- poolFile = T_FileStream_open(theCurrentFileName, "rb"); |
+ poolFile = T_FileStream_open(poolFileName.data(), "rb"); |
if (poolFile == NULL) { |
- fprintf(stderr, "unable to open pool bundle file %s\n", theCurrentFileName); |
+ fprintf(stderr, "unable to open pool bundle file %s\n", poolFileName.data()); |
return 1; |
} |
poolFileSize = T_FileStream_size(poolFile); |
if (poolFileSize < 32) { |
- fprintf(stderr, "the pool bundle file %s is too small\n", theCurrentFileName); |
+ fprintf(stderr, "the pool bundle file %s is too small\n", poolFileName.data()); |
return 1; |
} |
- poolBundle.fBytes = (uint8_t *)uprv_malloc((poolFileSize + 15) & ~15); |
+ poolBundle.fBytes = new uint8_t[(poolFileSize + 15) & ~15]; |
if (poolFileSize > 0 && poolBundle.fBytes == NULL) { |
- fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", theCurrentFileName); |
+ fprintf(stderr, "unable to allocate memory for the pool bundle file %s\n", poolFileName.data()); |
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]; |
} |
+ |
+ UDataSwapper *ds; |
+ const DataHeader *header; |
+ int32_t bytesRead = T_FileStream_read(poolFile, poolBundle.fBytes, poolFileSize); |
+ if (bytesRead != poolFileSize) { |
+ fprintf(stderr, "unable to read the pool bundle file %s\n", poolFileName.data()); |
+ 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", |
+ poolFileName.data(), 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", |
+ poolFileName.data(), 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", poolFileName.data()); |
+ return U_INVALID_FORMAT_ERROR; |
+ } |
+ const int32_t *pRoot = (const int32_t *)( |
+ (const char *)header + header->dataHeader.headerSize); |
+ poolBundle.fIndexes = pRoot + 1; |
+ indexLength = poolBundle.fIndexes[URES_INDEX_LENGTH] & 0xff; |
+ if (indexLength <= URES_INDEX_POOL_CHECKSUM) { |
+ fprintf(stderr, "insufficient indexes[] in pool bundle file %s\n", poolFileName.data()); |
+ return U_INVALID_FORMAT_ERROR; |
+ } |
+ int32_t keysBottom = 1 + indexLength; |
+ int32_t keysTop = poolBundle.fIndexes[URES_INDEX_KEYS_TOP]; |
+ poolBundle.fKeys = (const char *)(pRoot + keysBottom); |
+ poolBundle.fKeysLength = (keysTop - keysBottom) * 4; |
+ poolBundle.fChecksum = poolBundle.fIndexes[URES_INDEX_POOL_CHECKSUM]; |
+ |
for (i = 0; i < poolBundle.fKeysLength; ++i) { |
if (poolBundle.fKeys[i] == 0) { |
++poolBundle.fKeysCount; |
} |
} |
+ |
+ // 16BitUnits[] begins with strings-v2. |
+ // The strings-v2 may optionally be terminated by what looks like |
+ // an explicit string length that exceeds the number of remaining 16-bit units. |
+ int32_t stringUnitsLength = (poolBundle.fIndexes[URES_INDEX_16BIT_TOP] - keysTop) * 2; |
+ if (stringUnitsLength >= 2 && getFormatVersion() >= 3) { |
+ poolBundle.fStrings = new PseudoListResource(NULL, status); |
+ if (poolBundle.fStrings == NULL) { |
+ fprintf(stderr, "unable to allocate memory for the pool bundle strings %s\n", |
+ poolFileName.data()); |
+ return U_MEMORY_ALLOCATION_ERROR; |
+ } |
+ // The PseudoListResource constructor call did not allocate further memory. |
+ assert(U_SUCCESS(status)); |
+ const UChar *p = (const UChar *)(pRoot + keysTop); |
+ int32_t remaining = stringUnitsLength; |
+ do { |
+ int32_t first = *p; |
+ int8_t numCharsForLength; |
+ int32_t length; |
+ if (!U16_IS_TRAIL(first)) { |
+ // NUL-terminated |
+ numCharsForLength = 0; |
+ for (length = 0; |
+ length < remaining && p[length] != 0; |
+ ++length) {} |
+ } else if (first < 0xdfef) { |
+ numCharsForLength = 1; |
+ length = first & 0x3ff; |
+ } else if (first < 0xdfff && remaining >= 2) { |
+ numCharsForLength = 2; |
+ length = ((first - 0xdfef) << 16) | p[1]; |
+ } else if (first == 0xdfff && remaining >= 3) { |
+ numCharsForLength = 3; |
+ length = ((int32_t)p[1] << 16) | p[2]; |
+ } else { |
+ break; // overrun |
+ } |
+ // Check for overrun before changing remaining, |
+ // so that it is always accurate after the loop body. |
+ if ((numCharsForLength + length) >= remaining || |
+ p[numCharsForLength + length] != 0) { |
+ break; // overrun or explicitly terminated |
+ } |
+ int32_t poolStringIndex = stringUnitsLength - remaining; |
+ // Maximum pool string index when suffix-sharing the last character. |
+ int32_t maxStringIndex = poolStringIndex + numCharsForLength + length - 1; |
+ if (maxStringIndex >= RES_MAX_OFFSET) { |
+ // pool string index overrun |
+ break; |
+ } |
+ p += numCharsForLength; |
+ remaining -= numCharsForLength; |
+ if (length != 0) { |
+ StringResource *sr = |
+ new StringResource(poolStringIndex, numCharsForLength, |
+ p, length, status); |
+ if (sr == NULL) { |
+ fprintf(stderr, "unable to allocate memory for a pool bundle string %s\n", |
+ poolFileName.data()); |
+ return U_MEMORY_ALLOCATION_ERROR; |
+ } |
+ poolBundle.fStrings->add(sr); |
+ poolBundle.fStringIndexLimit = maxStringIndex + 1; |
+ // The StringResource constructor did not allocate further memory. |
+ assert(U_SUCCESS(status)); |
+ } |
+ p += length + 1; |
+ remaining -= length + 1; |
+ } while (remaining > 0); |
+ if (poolBundle.fStrings->fCount == 0) { |
+ delete poolBundle.fStrings; |
+ poolBundle.fStrings = NULL; |
+ } |
+ } |
+ |
T_FileStream_close(poolFile); |
setUsePoolBundle(TRUE); |
+ if (isVerbose() && poolBundle.fStrings != NULL) { |
+ printf("number of shared strings: %d\n", (int)poolBundle.fStrings->fCount); |
+ int32_t length = poolBundle.fStringIndexLimit + 1; // incl. last NUL |
+ printf("16-bit units for strings: %6d = %6d bytes\n", |
+ (int)length, (int)length * 2); |
+ } |
+ } |
+ |
+ if(!options[FORMAT_VERSION].doesOccur && getFormatVersion() == 3 && |
+ poolBundle.fStrings == NULL && |
+ !options[WRITE_POOL_BUNDLE].doesOccur) { |
+ // If we just default to formatVersion 3 |
+ // but there are no pool bundle strings to share |
+ // and we do not write a pool bundle, |
+ // then write formatVersion 2 which is just as good. |
+ setFormatVersion(2); |
} |
if(options[INCLUDE_UNIHAN_COLL].doesOccur) { |
@@ -410,28 +508,29 @@ main(int argc, |
status = U_ZERO_ERROR; |
arg = getLongPathname(argv[i]); |
+ CharString theCurrentFileName; |
if (inputDir) { |
- uprv_strcpy(theCurrentFileName, inputDir); |
- uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); |
- } else { |
- *theCurrentFileName = 0; |
+ theCurrentFileName.append(inputDir, status); |
+ } |
+ theCurrentFileName.appendPathPart(arg, status); |
+ if (U_FAILURE(status)) { |
+ break; |
} |
- uprv_strcat(theCurrentFileName, arg); |
+ gCurrentFileName = theCurrentFileName.data(); |
if (isVerbose()) { |
- printf("Processing file \"%s\"\n", theCurrentFileName); |
+ printf("Processing file \"%s\"\n", theCurrentFileName.data()); |
} |
processFile(arg, encoding, inputDir, outputDir, NULL, |
- options[NO_BINARY_COLLATION].doesOccur, |
- &status); |
+ newPoolBundle.getAlias(), |
+ options[NO_BINARY_COLLATION].doesOccur, status); |
} |
- uprv_free(poolBundle.fBytes); |
+ poolBundle.close(); |
- if(options[WRITE_POOL_BUNDLE].doesOccur) { |
+ if(U_SUCCESS(status) && options[WRITE_POOL_BUNDLE].doesOccur) { |
char outputFileName[256]; |
- bundle_write(newPoolBundle, outputDir, NULL, outputFileName, sizeof(outputFileName), &status); |
- bundle_close(newPoolBundle, &status); |
+ newPoolBundle->write(outputDir, NULL, outputFileName, sizeof(outputFileName), status); |
if(U_FAILURE(status)) { |
fprintf(stderr, "unable to write the pool bundle: %s\n", u_errorName(status)); |
} |
@@ -449,11 +548,11 @@ main(int argc, |
/* Process a file */ |
void |
-processFile( |
- const char *filename, const char *cp, const char *inputDir, const char *outputDir, const char *packageName, |
- UBool omitBinaryCollation, UErrorCode *status) { |
- /*FileStream *in = NULL;*/ |
- struct SRBRoot *data = NULL; |
+processFile(const char *filename, const char *cp, |
+ const char *inputDir, const char *outputDir, const char *packageName, |
+ SRBRoot *newPoolBundle, |
+ UBool omitBinaryCollation, UErrorCode &status) { |
+ LocalPointer<SRBRoot> data; |
UCHARBUF *ucbuf = NULL; |
char *rbname = NULL; |
char *openFileName = NULL; |
@@ -464,12 +563,11 @@ processFile( |
int32_t dirlen = 0; |
int32_t filelen = 0; |
- |
- if (status==NULL || U_FAILURE(*status)) { |
+ if (U_FAILURE(status)) { |
return; |
} |
if(filename==NULL){ |
- *status=U_ILLEGAL_ARGUMENT_ERROR; |
+ status=U_ILLEGAL_ARGUMENT_ERROR; |
return; |
}else{ |
filelen = (int32_t)uprv_strlen(filename); |
@@ -491,7 +589,7 @@ processFile( |
/* test for NULL */ |
if(inputDirBuf == NULL) { |
- *status = U_MEMORY_ALLOCATION_ERROR; |
+ status = U_MEMORY_ALLOCATION_ERROR; |
goto finish; |
} |
@@ -507,7 +605,7 @@ processFile( |
/* test for NULL */ |
if(openFileName == NULL) { |
- *status = U_MEMORY_ALLOCATION_ERROR; |
+ status = U_MEMORY_ALLOCATION_ERROR; |
goto finish; |
} |
@@ -533,7 +631,7 @@ processFile( |
/* test for NULL */ |
if(openFileName == NULL) { |
- *status = U_MEMORY_ALLOCATION_ERROR; |
+ status = U_MEMORY_ALLOCATION_ERROR; |
goto finish; |
} |
@@ -544,14 +642,15 @@ processFile( |
uprv_strcat(openFileName, filename); |
- ucbuf = ucbuf_open(openFileName, &cp,getShowWarning(),TRUE, status); |
- if(*status == U_FILE_ACCESS_ERROR) { |
+ ucbuf = ucbuf_open(openFileName, &cp,getShowWarning(),TRUE, &status); |
+ if(status == U_FILE_ACCESS_ERROR) { |
fprintf(stderr, "couldn't open file %s\n", openFileName == NULL ? filename : openFileName); |
goto finish; |
} |
- if (ucbuf == NULL || U_FAILURE(*status)) { |
- fprintf(stderr, "An error occured processing file %s. Error: %s\n", openFileName == NULL ? filename : openFileName,u_errorName(*status)); |
+ if (ucbuf == NULL || U_FAILURE(status)) { |
+ fprintf(stderr, "An error occured processing file %s. Error: %s\n", |
+ openFileName == NULL ? filename : openFileName, u_errorName(status)); |
goto finish; |
} |
/* auto detected popular encodings? */ |
@@ -559,26 +658,26 @@ processFile( |
printf("autodetected encoding %s\n", cp); |
} |
/* Parse the data into an SRBRoot */ |
- data = parse(ucbuf, inputDir, outputDir, filename, |
- !omitBinaryCollation, options[NO_COLLATION_RULES].doesOccur, status); |
+ data.adoptInstead(parse(ucbuf, inputDir, outputDir, filename, |
+ !omitBinaryCollation, options[NO_COLLATION_RULES].doesOccur, &status)); |
- if (data == NULL || U_FAILURE(*status)) { |
- fprintf(stderr, "couldn't parse the file %s. Error:%s\n", filename,u_errorName(*status)); |
+ if (data.isNull() || U_FAILURE(status)) { |
+ fprintf(stderr, "couldn't parse the file %s. Error:%s\n", filename, u_errorName(status)); |
goto finish; |
} |
if(options[WRITE_POOL_BUNDLE].doesOccur) { |
+ data->fWritePoolBundle = newPoolBundle; |
+ data->compactKeys(status); |
int32_t newKeysLength; |
- const char *newKeys, *newKeysLimit; |
- bundle_compactKeys(data, status); |
- newKeys = bundle_getKeyBytes(data, &newKeysLength); |
- bundle_addKeyBytes(newPoolBundle, newKeys, newKeysLength, status); |
- if(U_FAILURE(*status)) { |
+ const char *newKeys = data->getKeyBytes(&newKeysLength); |
+ newPoolBundle->addKeyBytes(newKeys, newKeysLength, status); |
+ if(U_FAILURE(status)) { |
fprintf(stderr, "bundle_compactKeys(%s) or bundle_getKeyBytes() failed: %s\n", |
- filename, u_errorName(*status)); |
+ filename, u_errorName(status)); |
goto finish; |
} |
/* count the number of just-added key strings */ |
- for(newKeysLimit = newKeys + newKeysLength; newKeys < newKeysLimit; ++newKeys) { |
+ for(const char *newKeysLimit = newKeys + newKeysLength; newKeys < newKeysLimit; ++newKeys) { |
if(*newKeys == 0) { |
++newPoolBundle->fKeysCount; |
} |
@@ -586,31 +685,31 @@ processFile( |
} |
if(options[USE_POOL_BUNDLE].doesOccur) { |
- data->fPoolBundleKeys = poolBundle.fKeys; |
- data->fPoolBundleKeysLength = poolBundle.fKeysLength; |
- data->fPoolBundleKeysCount = poolBundle.fKeysCount; |
- data->fPoolChecksum = poolBundle.fChecksum; |
+ data->fUsePoolBundle = &poolBundle; |
} |
/* Determine the target rb filename */ |
rbname = make_res_filename(filename, outputDir, packageName, status); |
- if(U_FAILURE(*status)) { |
- fprintf(stderr, "couldn't make the res fileName for bundle %s. Error:%s\n", filename,u_errorName(*status)); |
+ if(U_FAILURE(status)) { |
+ fprintf(stderr, "couldn't make the res fileName for bundle %s. Error:%s\n", |
+ filename, u_errorName(status)); |
goto finish; |
} |
if(write_java== TRUE){ |
- bundle_write_java(data,outputDir,outputEnc, outputFileName, sizeof(outputFileName), |
- options[JAVA_PACKAGE].value, options[BUNDLE_NAME].value, status); |
+ bundle_write_java(data.getAlias(), outputDir, outputEnc, |
+ outputFileName, sizeof(outputFileName), |
+ options[JAVA_PACKAGE].value, options[BUNDLE_NAME].value, &status); |
}else if(write_xliff ==TRUE){ |
- bundle_write_xml(data,outputDir,outputEnc, filename, outputFileName, sizeof(outputFileName),language, xliffOutputFileName,status); |
+ bundle_write_xml(data.getAlias(), outputDir, outputEnc, |
+ filename, outputFileName, sizeof(outputFileName), |
+ language, xliffOutputFileName, &status); |
}else{ |
/* Write the data to the file */ |
- bundle_write(data, outputDir, packageName, outputFileName, sizeof(outputFileName), status); |
+ data->write(outputDir, packageName, outputFileName, sizeof(outputFileName), status); |
} |
- if (U_FAILURE(*status)) { |
- fprintf(stderr, "couldn't write bundle %s. Error:%s\n", outputFileName,u_errorName(*status)); |
+ if (U_FAILURE(status)) { |
+ fprintf(stderr, "couldn't write bundle %s. Error:%s\n", outputFileName, u_errorName(status)); |
} |
- bundle_close(data, status); |
finish: |
@@ -636,7 +735,7 @@ static char* |
make_res_filename(const char *filename, |
const char *outputDir, |
const char *packageName, |
- UErrorCode *status) { |
+ UErrorCode &status) { |
char *basename; |
char *dirname; |
char *resName; |
@@ -644,7 +743,7 @@ make_res_filename(const char *filename, |
int32_t pkgLen = 0; /* length of package prefix */ |
- if (U_FAILURE(*status)) { |
+ if (U_FAILURE(status)) { |
return 0; |
} |
@@ -659,7 +758,7 @@ make_res_filename(const char *filename, |
/* determine basename, and compiled file names */ |
basename = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1)); |
if(basename == 0) { |
- *status = U_MEMORY_ALLOCATION_ERROR; |
+ status = U_MEMORY_ALLOCATION_ERROR; |
goto finish; |
} |
@@ -667,7 +766,7 @@ make_res_filename(const char *filename, |
dirname = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1)); |
if(dirname == 0) { |
- *status = U_MEMORY_ALLOCATION_ERROR; |
+ status = U_MEMORY_ALLOCATION_ERROR; |
goto finish; |
} |
@@ -680,7 +779,7 @@ make_res_filename(const char *filename, |
+ uprv_strlen(basename) |
+ uprv_strlen(RES_SUFFIX) + 8)); |
if(resName == 0) { |
- *status = U_MEMORY_ALLOCATION_ERROR; |
+ status = U_MEMORY_ALLOCATION_ERROR; |
goto finish; |
} |
@@ -701,7 +800,7 @@ make_res_filename(const char *filename, |
resName = (char*) uprv_malloc(sizeof(char) * (dirlen + pkgLen + basenamelen + 8)); |
if (resName == NULL) { |
- *status = U_MEMORY_ALLOCATION_ERROR; |
+ status = U_MEMORY_ALLOCATION_ERROR; |
goto finish; |
} |