]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/genrb/reslist.c
ICU-400.37.tar.gz
[apple/icu.git] / icuSources / tools / genrb / reslist.c
index 32b4593707956a6f006d0b09cbb98b0b2ca44a08..b389ef1814f2b0278d34f95738ce84ec27e73f11 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2000-2004, International Business Machines
+*   Copyright (C) 2000-2008, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 
 static UBool gIncludeCopyright = FALSE;
 
 
 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);
 
 uint32_t res_write(UNewDataMemory *mem, struct SResource *res,
                    uint32_t usedOffset, UErrorCode *status);
 
@@ -40,7 +47,7 @@ static const UDataInfo dataInfo= {
     0,
 
     {0x52, 0x65, 0x73, 0x42},     /* dataFormat="resb" */
     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*/
 };
 
     {1, 4, 0, 0}                  /* dataVersion take a look at version inside parsed resb*/
 };
 
@@ -393,12 +400,22 @@ void bundle_write(struct SRBRoot *bundle, const char *outputDir, const char *out
      * write int32_t indexes[] after root and before the strings
      * to make it easier to parse resource bundles in icuswap or from Java etc.
      */
      * 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;
 
     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));
 
     /* write the indexes[] */
     udata_writeBlock(mem, indexes, sizeof(indexes));
 
@@ -436,19 +453,18 @@ struct SResource* res_open(const struct UString* comment, UErrorCode* status){
     }
     uprv_memset(res, 0, sizeof(struct SResource));
 
     }
     uprv_memset(res, 0, sizeof(struct SResource));
 
-    res->fComment = NULL;
+    ustr_init(&res->fComment);
     if(comment != NULL){
     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;
 
 }
     }
     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);
 struct SResource* table_open(struct SRBRoot *bundle, char *tag,  const struct UString* comment, UErrorCode *status) {
 
     struct SResource *res = res_open(comment, status);
@@ -456,8 +472,7 @@ struct SResource* table_open(struct SRBRoot *bundle, char *tag,  const struct US
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*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 NULL;
     }
 
@@ -478,7 +493,7 @@ struct SResource* table_open(struct SRBRoot *bundle, char *tag,  const struct US
     return res;
 }
 
     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);
 
 
     struct SResource *res = res_open(comment, status);
 
@@ -490,7 +505,6 @@ struct SResource* array_open(struct SRBRoot *bundle, char *tag, const struct USt
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
-        uprv_free(res->fComment);
         uprv_free(res);
         return NULL;
     }
         uprv_free(res);
         return NULL;
     }
@@ -517,7 +531,6 @@ struct SResource *string_open(struct SRBRoot *bundle, char *tag, const UChar *va
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
-        uprv_free(res->fComment);
         uprv_free(res);
         return NULL;
     }
         uprv_free(res);
         return NULL;
     }
@@ -551,7 +564,6 @@ struct SResource *alias_open(struct SRBRoot *bundle, char *tag, UChar *value, in
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
-        uprv_free(res->fComment);
         uprv_free(res);
         return NULL;
     }
         uprv_free(res);
         return NULL;
     }
@@ -585,7 +597,6 @@ struct SResource* intvector_open(struct SRBRoot *bundle, char *tag, const struct
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
-        uprv_free(res->fComment);
         uprv_free(res);
         return NULL;
     }
         uprv_free(res);
         return NULL;
     }
@@ -616,7 +627,6 @@ struct SResource *int_open(struct SRBRoot *bundle, char *tag, int32_t value, con
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
-        uprv_free(res->fComment);
         uprv_free(res);
         return NULL;
     }
         uprv_free(res);
         return NULL;
     }
@@ -639,7 +649,6 @@ struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t len
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
     res->fKey  = bundle_addtag(bundle, tag, status);
 
     if (U_FAILURE(*status)) {
-        uprv_free(res->fComment);
         uprv_free(res);
         return NULL;
     }
         uprv_free(res);
         return NULL;
     }
@@ -724,7 +733,7 @@ struct SRBRoot *bundle_open(const struct UString* comment, UErrorCode *status) {
 }
 
 /* Closing Functions */
 }
 
 /* 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;
 
     struct SResource *current = NULL;
     struct SResource *prev    = NULL;
 
@@ -734,108 +743,100 @@ void table_close(struct SResource *table, UErrorCode *status) {
         prev    = current;
         current = current->fNext;
 
         prev    = current;
         current = current->fNext;
 
-        res_close(prev, status);
+        res_close(prev);
     }
 
     table->u.fTable.fFirst = NULL;
 }
 
     }
 
     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;
     struct SResource *current = NULL;
     struct SResource *prev    = NULL;
-
+    
+    if(array==NULL){
+        return;
+    }
     current = array->u.fArray.fFirst;
     current = array->u.fArray.fFirst;
-
+    
     while (current != NULL) {
         prev    = current;
         current = current->fNext;
 
     while (current != NULL) {
         prev    = current;
         current = current->fNext;
 
-        res_close(prev, status);
+        res_close(prev);
     }
     array->u.fArray.fFirst = NULL;
 }
 
     }
     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;
     }
 }
 
     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;
     }
 }
 
     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;
     }
 }
 
     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 */
 }
 
     /* 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;
     }
 }
 
     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:
     if (res != NULL) {
         switch(res->fType) {
         case URES_STRING:
-            string_close(res, status);
+            string_close(res);
             break;
         case URES_ALIAS:
             break;
         case URES_ALIAS:
-            alias_close(res, status);
+            alias_close(res);
             break;
         case URES_INT_VECTOR:
             break;
         case URES_INT_VECTOR:
-            intvector_close(res, status);
+            intvector_close(res);
             break;
         case URES_BINARY:
             break;
         case URES_BINARY:
-            bin_close(res, status);
+            bin_close(res);
             break;
         case URES_INT:
             break;
         case URES_INT:
-            int_close(res, status);
+            int_close(res);
             break;
         case URES_ARRAY:
             break;
         case URES_ARRAY:
-            array_close(res, status);
+            array_close(res);
             break;
         case URES_TABLE:
         case URES_TABLE32:
             break;
         case URES_TABLE:
         case URES_TABLE32:
-            table_close(res, status);
+            table_close(res);
             break;
         default:
             /* Shouldn't happen */
             break;
         }
 
             break;
         default:
             /* Shouldn't happen */
             break;
         }
 
+        ustr_deinit(&res->fComment);
         uprv_free(res);
     }
 }
 
 void bundle_close(struct SRBRoot *bundle, UErrorCode *status) {
         uprv_free(res);
     }
 }
 
 void bundle_close(struct SRBRoot *bundle, UErrorCode *status) {
-    struct SResource *current = NULL;
-    struct SResource *prev    = NULL;
-
     if (bundle->fRoot != 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 (bundle->fLocale != NULL) {
@@ -858,6 +859,9 @@ void table_add(struct SResource *table, struct SResource *res, int linenumber, U
     if (U_FAILURE(*status)) {
         return;
     }
     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;
 
     /* remember this linenumber to report to the user if there is a duplicate key */
     res->line = linenumber;