]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/genrb/wrtjava.c
ICU-8.11.1.tar.gz
[apple/icu.git] / icuSources / tools / genrb / wrtjava.c
index 8ec3709a9b07d51393799a5d3d6f9659e13f6cc9..a4293ae2807cfa3938c6e0bddc1544edb72d000e 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2000-2003, International Business Machines
+*   Copyright (C) 2000-2006, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -33,7 +33,7 @@
 void res_write_java(struct SResource *res,UErrorCode *status);
 
 
-static const char copyRight[] = 
+static const char copyRight[] =
     "/* \n"
     " *******************************************************************************\n"
     " *\n"
@@ -46,7 +46,7 @@ static const char copyRight[] =
     " * $" "Revision:  $ \n"
     " *******************************************************************************\n"
     " */\n\n";
-static const char warningMsg[] = 
+static const char warningMsg[] =
     "/*********************************************************************\n"
     "######################################################################\n"
     "\n"
@@ -64,7 +64,7 @@ static const char* closeClass="    };\n"
 static const char* javaClass =  "import java.util.ListResourceBundle;\n"
                                 "import com.ibm.icu.impl.ICUListResourceBundle;\n\n"
                                 "public class ";
+
 static const char* javaClass1=  " extends ICUListResourceBundle {\n\n"
                                 "    /**\n"
                                 "     * Overrides ListResourceBundle \n"
@@ -93,10 +93,14 @@ static void write_tabs(FileStream* os){
         T_FileStream_write(os,"    ",4);
     }
 }
+
+#define ZERO 0x30
+
 static const char* enc ="";
 static UConverter* conv = NULL;
+static char NUMBER = ZERO;
 
-static int32_t 
+static int32_t
 uCharsToChars( char* target,int32_t targetLen, UChar* source, int32_t sourceLen,UErrorCode* status){
     int i=0, j=0;
     char str[30]={'\0'};
@@ -119,7 +123,7 @@ uCharsToChars( char* target,int32_t targetLen, UChar* source, int32_t sourceLen,
                 }
                 j+=2;
             }else if(source[i-1]!='\\'){
-                     
+
                 if(j+2<targetLen){
                     uprv_strcat(target,"\\");
                     target[j+1]= (char)source[i];
@@ -169,7 +173,7 @@ uCharsToChars( char* target,int32_t targetLen, UChar* source, int32_t sourceLen,
             if(j<targetLen){
                 target[j] = (char) source[i];
             }
-            j++;            
+            j++;
         }else{
             if(*enc =='\0' || source[i]==0x0000){
                 uprv_strcpy(str,"\\u");
@@ -196,7 +200,7 @@ uCharsToChars( char* target,int32_t targetLen, UChar* source, int32_t sourceLen,
 }
 
 
-static uint32_t 
+static uint32_t
 strrch(const char* source,uint32_t sourceLen,char find){
     const char* tSourceEnd =source + (sourceLen-1);
     while(tSourceEnd>= source){
@@ -226,26 +230,27 @@ str_write_java( uint16_t* src, int32_t srcLen, UBool printEndLine, UErrorCode *s
 
     uint32_t length = srcLen*8;
     uint32_t bufLen = 0;
+    uint32_t columnCount;
     char* buf = (char*) malloc(sizeof(char)*length);
-    
-    uint32_t columnCount = getColumnCount(srcLen);
 
-    /* test for NULL */
     if(buf == NULL) {
         *status = U_MEMORY_ALLOCATION_ERROR;
         return;
     }
-    
+
+    columnCount = getColumnCount(srcLen);
     memset(buf,0,length);
-  
+
     bufLen = uCharsToChars(buf,length,src,srcLen,status);
 
-    if(printEndLine) write_tabs(out);
+    if(printEndLine)
+        write_tabs(out);
 
     if(U_FAILURE(*status)){
+        uprv_free(buf);
         return;
     }
-    
+
     if(bufLen+(tabCount*4) > columnCount  ){
         uint32_t len = 0;
         char* current = buf;
@@ -295,14 +300,12 @@ str_write_java( uint16_t* src, int32_t srcLen, UBool printEndLine, UErrorCode *s
     }else{
         T_FileStream_write(out,"\"",1);
     }
+    uprv_free(buf);
 }
 
-/* Writing Functions */
-static void 
-string_write_java(struct SResource *res,UErrorCode *status) {       
-    if(uprv_strcmp(srBundle->fKeys+res->fKey,"%%UCARULES")==0 ){
+static void
+write_utf8_file(struct SResource *res, const char *file, UErrorCode *status){
         char fileName[1024] ={0};
-        const char* file = "UCARules.utf8";
         FileStream* datFile = NULL;
         const char* type = "new ICUListResourceBundle.ResourceString(";
         char* dest  = (char*) uprv_malloc( 8 * res->u.fString.fLength);
@@ -314,7 +317,7 @@ string_write_java(struct SResource *res,UErrorCode *status) {
             }
         }
         uprv_strcat(fileName,file);/* UCARULES.utf8 UTF-8 file */
-        
+
         write_tabs(out);
 
         T_FileStream_write(out, type, (int32_t)uprv_strlen(type));
@@ -322,11 +325,11 @@ string_write_java(struct SResource *res,UErrorCode *status) {
         T_FileStream_write(out, file, (int32_t)uprv_strlen(file));
         T_FileStream_write(out, "\")\n", 3);
         datFile=T_FileStream_open(fileName,"w");
-        
+
         if(!dest){
             *status=U_MEMORY_ALLOCATION_ERROR;
         }
-        
+
         u_strToUTF8(dest,8*res->u.fString.fLength,&len,res->u.fString.fChars,res->u.fString.fLength,status);
         if(U_FAILURE(*status)){
             T_FileStream_close(datFile);
@@ -336,32 +339,49 @@ string_write_java(struct SResource *res,UErrorCode *status) {
         T_FileStream_write(datFile,dest,len);
         T_FileStream_close(datFile);
         uprv_free(dest);
-           
+}
+#define MAX_SEQUENCE_LENGTH 30000
+/* Writing Functions */
+static void
+string_write_java(struct SResource *res,UErrorCode *status) {
+    if(res->fKey > 0 && uprv_strcmp(srBundle->fKeys+res->fKey,"%%UCARULES")==0 ){
+
+        const char* file = "UCARules.utf8";
+        write_utf8_file(res, file, status);
+    }else if(res->fKey > 0 && uprv_strcmp(srBundle->fKeys+res->fKey,"Sequence")==0
+             && res->fType == RES_STRING
+             && res->u.fString.fLength > MAX_SEQUENCE_LENGTH){
+        char file[1024] = {0};
+        uprv_strcpy(file, "CollationSequence_");
+        uprv_strcat(file, srBundle->fLocale);
+        uprv_strcat(file, ".utf8");
+        write_utf8_file(res, file, status);
+
     }else{
         str_write_java(res->u.fString.fChars,res->u.fString.fLength,TRUE,status);
 
-        if(uprv_strcmp(srBundle->fKeys+res->fKey,"Rule")==0){
+        if(res->fKey > 0 && uprv_strcmp(srBundle->fKeys+res->fKey,"Rule")==0){
             UChar* buf = (UChar*) uprv_malloc(sizeof(UChar)*res->u.fString.fLength);
-            uprv_memcpy(buf,res->u.fString.fChars,res->u.fString.fLength);      
+            uprv_memcpy(buf,res->u.fString.fChars,res->u.fString.fLength);
             uprv_free(buf);
         }
     }
 
 }
 
-static void 
+static void
 alias_write_java(struct SResource *res,UErrorCode *status) {
     static const char str[] = "new ICUListResourceBundle.Alias(";
     write_tabs(out);
-    T_FileStream_write(out,str,uprv_strlen(str));
-    
+    T_FileStream_write(out,str,(int32_t)uprv_strlen(str));
+
     /*str_write_java(res->u.fString.fChars,res->u.fString.fLength,FALSE,status);*/
     /*if(*res->u.fString.fChars == RES_PATH_SEPARATOR) {*/
-        /* there is a path included 
+        /* there is a path included
         locale = u_strchr(res->u.fString.fChars +1, RES_PATH_SEPARATOR);
         *locale = 0;
         locale++;
-        
+
         T_FileStream_write(out,"\"/",2);
         T_FileStream_write(out,apName,(int32_t)uprv_strlen(apName));
         T_FileStream_write(out,"/",1);
@@ -371,13 +391,13 @@ alias_write_java(struct SResource *res,UErrorCode *status) {
     } else {
         str_write_java(res->u.fString.fChars,res->u.fString.fLength,FALSE,status);
     }*/
-    
+
     str_write_java(res->u.fString.fChars,res->u.fString.fLength,FALSE,status);
-    
+
     T_FileStream_write(out,"),\n",3);
 }
 
-static void 
+static void
 array_write_java( struct SResource *res, UErrorCode *status) {
 
     uint32_t  i         = 0;
@@ -435,24 +455,24 @@ array_write_java( struct SResource *res, UErrorCode *status) {
 
     } else {
         write_tabs(out);
-        T_FileStream_write(out,arr,uprv_strlen(arr));
+        T_FileStream_write(out,arr,(int32_t)uprv_strlen(arr));
         write_tabs(out);
         T_FileStream_write(out,"},\n",3);
     }
 }
 
-static void 
+static void
 intvector_write_java( struct SResource *res, UErrorCode *status) {
     uint32_t i = 0;
     const char* intArr = "new Integer[] {\n";
     const char* intC   = "new Integer(";
-    const char* stringArr = "new String[]{\n"; 
+    const char* stringArr = "new String[]{\n";
     char buf[100];
     int len =0;
     buf[0]=0;
     write_tabs(out);
 
-    if(uprv_strcmp(srBundle->fKeys+res->fKey,"DateTimeElements")==0){
+    if(res->fKey > 0 && uprv_strcmp(srBundle->fKeys+res->fKey,"DateTimeElements")==0){
         T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr));
         tabCount++;
         for(i = 0; i<res->u.fIntVector.fCount; i++) {
@@ -480,7 +500,7 @@ intvector_write_java( struct SResource *res, UErrorCode *status) {
     T_FileStream_write(out,"},\n",3);
 }
 
-static void 
+static void
 int_write_java(struct SResource *res,UErrorCode *status) {
     const char* intC   =  "new Integer(";
     char buf[100];
@@ -496,7 +516,7 @@ int_write_java(struct SResource *res,UErrorCode *status) {
 
 }
 
-static void 
+static void
 bin_write_java( struct SResource *res, UErrorCode *status) {
     const char* type = "new ICUListResourceBundle.CompressedBinary(";
     const char* ext;
@@ -507,7 +527,7 @@ bin_write_java( struct SResource *res, UErrorCode *status) {
         uint16_t* saveTarget = NULL;
         int32_t tgtLen = 0;
 
-        if(uprv_strcmp(srBundle->fKeys+res->fKey,"%%CollationBin")==0 || uprv_strcmp(srBundle->fKeys+res->fKey,"BreakDictionaryData")==0){
+        if(res->fKey > 0 && (uprv_strcmp(srBundle->fKeys+res->fKey,"%%CollationBin")==0 || uprv_strcmp(srBundle->fKeys+res->fKey,"BreakDictionaryData")==0)){
             char fileName[1024] ={0};
             char fn[1024] =  {0};
             FileStream* datFile = NULL;
@@ -521,8 +541,13 @@ bin_write_java( struct SResource *res, UErrorCode *status) {
             if(uprv_strcmp(srBundle->fLocale,"root")!=0){
                 uprv_strcat(fileName,"_");
                 uprv_strcat(fileName,srBundle->fLocale);
+                if(NUMBER > ZERO){
+                    uprv_strcat(fileName, "_");
+                    uprv_strcat(fileName, &NUMBER);
+                }
+                NUMBER++;
             }
-            
+
             uprv_strcat(fileName,ext);
             if(outDir ){
                 uprv_strcat(fn,outDir);
@@ -564,7 +589,7 @@ bin_write_java( struct SResource *res, UErrorCode *status) {
                     /* test for NULL */
                     if(myTarget == NULL) {
                         *status = U_MEMORY_ALLOCATION_ERROR;
-                        return; 
+                        return;
                     }
 
                     int i=0;
@@ -604,10 +629,10 @@ bin_write_java( struct SResource *res, UErrorCode *status) {
             free(target);
 
         }
-    
+
    }else{
         write_tabs(out);
-        T_FileStream_write(out,type,uprv_strlen(type));
+        T_FileStream_write(out,type,(int32_t)uprv_strlen(type));
         T_FileStream_write(out,"null),\n",7);
    }
 
@@ -616,7 +641,7 @@ bin_write_java( struct SResource *res, UErrorCode *status) {
 
 static UBool start = TRUE;
 
-static void 
+static void
 table_write_java(struct SResource *res, UErrorCode *status) {
     uint32_t  i         = 0;
     UBool allStrings =TRUE;
@@ -627,7 +652,7 @@ table_write_java(struct SResource *res, UErrorCode *status) {
     if (U_FAILURE(*status)) {
         return ;
     }
-    
+
     if (res->u.fTable.fCount > 0) {
         if(start==FALSE){
             write_tabs(out);
@@ -642,7 +667,7 @@ table_write_java(struct SResource *res, UErrorCode *status) {
         while (current != NULL) {
             assert(i < res->u.fTable.fCount);
             write_tabs(out);
-            
+
             T_FileStream_write(out, openBrace, 2);
 
 
@@ -650,14 +675,14 @@ table_write_java(struct SResource *res, UErrorCode *status) {
             allStrings=FALSE;
 
             write_tabs(out);
+            if(current->fKey > 0){
+                T_FileStream_write(out, "\"", 1);
+                T_FileStream_write(out, srBundle->fKeys+current->fKey,
+                                   (int32_t)uprv_strlen(srBundle->fKeys+current->fKey));
+                T_FileStream_write(out, "\",\n", 2);
 
-            T_FileStream_write(out, "\"", 1);
-            T_FileStream_write(out, srBundle->fKeys+current->fKey,
-                               (int32_t)uprv_strlen(srBundle->fKeys+current->fKey));
-            T_FileStream_write(out, "\",\n", 2);
-
-            T_FileStream_write(out, "\n", 1);
-           
+                T_FileStream_write(out, "\n", 1);
+            }
             res_write_java(current, status);
             if(U_FAILURE(*status)){
                 return;
@@ -676,7 +701,7 @@ table_write_java(struct SResource *res, UErrorCode *status) {
 
     } else {
         write_tabs(out);
-        T_FileStream_write(out,obj,uprv_strlen(obj));
+        T_FileStream_write(out,obj,(int32_t)uprv_strlen(obj));
 
         write_tabs(out);
         T_FileStream_write(out,"},\n",3);
@@ -685,9 +710,9 @@ table_write_java(struct SResource *res, UErrorCode *status) {
 
 }
 
-void 
+void
 res_write_java(struct SResource *res,UErrorCode *status) {
-    
+
     if (U_FAILURE(*status)) {
         return ;
     }
@@ -713,6 +738,7 @@ res_write_java(struct SResource *res,UErrorCode *status) {
              array_write_java     (res, status);
              return;
         case URES_TABLE:
+        case URES_TABLE32:
              table_write_java     (res, status);
              return;
 
@@ -724,21 +750,21 @@ res_write_java(struct SResource *res,UErrorCode *status) {
     *status = U_INTERNAL_PROGRAM_ERROR;
 }
 
-void 
-bundle_write_java(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, 
-                  char *writtenFilename, int writtenFilenameLen, 
+void
+bundle_write_java(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc,
+                  char *writtenFilename, int writtenFilenameLen,
                   const char* packageName, const char* bundleName,
                   UErrorCode *status) {
 
     char fileName[256] = {'\0'};
     char className[256]={'\0'};
-    char constructor[1000] = { 0 };    
+    char constructor[1000] = { 0 };
     UBool j1 =FALSE;
     outDir = outputDir;
 
     bName = (bundleName==NULL) ? "LocaleElements" : bundleName;
     pName = (packageName==NULL)? "com.ibm.icu.impl.data" : packageName;
-    
+
     uprv_strcpy(className, bName);
     srBundle = bundle;
     if(uprv_strcmp(srBundle->fLocale,"root")!=0){
@@ -764,7 +790,7 @@ bundle_write_java(struct SRBRoot *bundle, const char *outputDir,const char* outp
     if (U_FAILURE(*status)) {
         return;
     }
-    
+
     out= T_FileStream_open(fileName,"w");
 
     if(out==NULL){