/*
*******************************************************************************
*
-* Copyright (C) 2000-2004, International Business Machines
+* Copyright (C) 2000-2008, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
static UBool gIncludeCopyright = FALSE;
+/*
+ * res_none() returns the address of kNoResource,
+ * for use in non-error cases when no resource is to be added to the bundle.
+ * (NULL is used in error cases.)
+ */
+static struct SResource kNoResource = { RES_NONE };
+
uint32_t res_write(UNewDataMemory *mem, struct SResource *res,
uint32_t usedOffset, UErrorCode *status);
0,
{0x52, 0x65, 0x73, 0x42}, /* dataFormat="resb" */
- {1, 1, 0, 0}, /* formatVersion */
+ {1, 2, 0, 0}, /* formatVersion */
{1, 4, 0, 0} /* dataVersion take a look at version inside parsed resb*/
};
* write int32_t indexes[] after root and before the strings
* to make it easier to parse resource bundles in icuswap or from Java etc.
*/
+ uprv_memset(indexes, 0, sizeof(indexes));
indexes[URES_INDEX_LENGTH]= URES_INDEX_TOP;
indexes[URES_INDEX_STRINGS_TOP]= (int32_t)(usedOffset>>2);
indexes[URES_INDEX_RESOURCES_TOP]= (int32_t)(top>>2);
indexes[URES_INDEX_BUNDLE_TOP]= indexes[URES_INDEX_RESOURCES_TOP];
indexes[URES_INDEX_MAX_TABLE_LENGTH]= bundle->fMaxTableLength;
+ /*
+ * formatVersion 1.2 (ICU 3.6):
+ * write indexes[URES_INDEX_ATTRIBUTES] with URES_ATT_NO_FALLBACK set or not set
+ * the memset() above initialized all indexes[] to 0
+ */
+ if(bundle->noFallback) {
+ indexes[URES_INDEX_ATTRIBUTES]=URES_ATT_NO_FALLBACK;
+ }
+
/* write the indexes[] */
udata_writeBlock(mem, indexes, sizeof(indexes));
}
uprv_memset(res, 0, sizeof(struct SResource));
- res->fComment = NULL;
+ ustr_init(&res->fComment);
if(comment != NULL){
- res->fComment = (struct UString *) uprv_malloc(sizeof(struct UString));
- if(res->fComment == NULL){
- *status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
- }
- ustr_init(res->fComment);
- ustr_cpy(res->fComment, comment, status);
+ ustr_cpy(&res->fComment, comment, status);
}
return res;
}
+
+struct SResource* res_none() {
+ return &kNoResource;
+}
+
struct SResource* table_open(struct SRBRoot *bundle, char *tag, const struct UString* comment, UErrorCode *status) {
struct SResource *res = res_open(comment, status);
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {
- uprv_free(res->fComment);
- uprv_free(res);
+ res_close(res);
return NULL;
}
return res;
}
-struct SResource* array_open(struct SRBRoot *bundle, char *tag, const struct UString* comment, UErrorCode *status) {
+struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status) {
struct SResource *res = res_open(comment, status);
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {
- uprv_free(res->fComment);
uprv_free(res);
return NULL;
}
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {
- uprv_free(res->fComment);
uprv_free(res);
return NULL;
}
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {
- uprv_free(res->fComment);
uprv_free(res);
return NULL;
}
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {
- uprv_free(res->fComment);
uprv_free(res);
return NULL;
}
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {
- uprv_free(res->fComment);
uprv_free(res);
return NULL;
}
res->fKey = bundle_addtag(bundle, tag, status);
if (U_FAILURE(*status)) {
- uprv_free(res->fComment);
uprv_free(res);
return NULL;
}
}
/* Closing Functions */
-void table_close(struct SResource *table, UErrorCode *status) {
+static void table_close(struct SResource *table) {
struct SResource *current = NULL;
struct SResource *prev = NULL;
prev = current;
current = current->fNext;
- res_close(prev, status);
+ res_close(prev);
}
table->u.fTable.fFirst = NULL;
}
-void array_close(struct SResource *array, UErrorCode *status) {
+static void array_close(struct SResource *array) {
struct SResource *current = NULL;
struct SResource *prev = NULL;
-
+
+ if(array==NULL){
+ return;
+ }
current = array->u.fArray.fFirst;
-
+
while (current != NULL) {
prev = current;
current = current->fNext;
- res_close(prev, status);
+ res_close(prev);
}
array->u.fArray.fFirst = NULL;
}
-void string_close(struct SResource *string, UErrorCode *status) {
+static void string_close(struct SResource *string) {
if (string->u.fString.fChars != NULL) {
uprv_free(string->u.fString.fChars);
string->u.fString.fChars =NULL;
}
}
-void alias_close(struct SResource *alias, UErrorCode *status) {
+static void alias_close(struct SResource *alias) {
if (alias->u.fString.fChars != NULL) {
uprv_free(alias->u.fString.fChars);
alias->u.fString.fChars =NULL;
}
}
-void intvector_close(struct SResource *intvector, UErrorCode *status) {
+static void intvector_close(struct SResource *intvector) {
if (intvector->u.fIntVector.fArray != NULL) {
uprv_free(intvector->u.fIntVector.fArray);
intvector->u.fIntVector.fArray =NULL;
}
}
-void int_close(struct SResource *intres, UErrorCode *status) {
+static void int_close(struct SResource *intres) {
/* Intentionally left blank */
}
-void bin_close(struct SResource *binres, UErrorCode *status) {
+static void bin_close(struct SResource *binres) {
if (binres->u.fBinaryValue.fData != NULL) {
uprv_free(binres->u.fBinaryValue.fData);
binres->u.fBinaryValue.fData = NULL;
}
}
-void res_close(struct SResource *res, UErrorCode *status) {
+void res_close(struct SResource *res) {
if (res != NULL) {
switch(res->fType) {
case URES_STRING:
- string_close(res, status);
+ string_close(res);
break;
case URES_ALIAS:
- alias_close(res, status);
+ alias_close(res);
break;
case URES_INT_VECTOR:
- intvector_close(res, status);
+ intvector_close(res);
break;
case URES_BINARY:
- bin_close(res, status);
+ bin_close(res);
break;
case URES_INT:
- int_close(res, status);
+ int_close(res);
break;
case URES_ARRAY:
- array_close(res, status);
+ array_close(res);
break;
case URES_TABLE:
case URES_TABLE32:
- table_close(res, status);
+ table_close(res);
break;
default:
/* Shouldn't happen */
break;
}
+ ustr_deinit(&res->fComment);
uprv_free(res);
}
}
void bundle_close(struct SRBRoot *bundle, UErrorCode *status) {
- struct SResource *current = NULL;
- struct SResource *prev = NULL;
-
if (bundle->fRoot != NULL) {
- current = bundle->fRoot->u.fTable.fFirst;
-
- while (current != NULL) {
- prev = current;
- current = current->fNext;
-
- res_close(prev, status);
- }
-
- uprv_free(bundle->fRoot);
+ res_close(bundle->fRoot);
}
if (bundle->fLocale != NULL) {
if (U_FAILURE(*status)) {
return;
}
+ if (res == &kNoResource) {
+ return;
+ }
/* remember this linenumber to report to the user if there is a duplicate key */
res->line = linenumber;