intl/icu/source/tools/genrb/wrtjava.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/genrb/wrtjava.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,697 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 2000-2012, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*
    1.12 +* File wrtjava.c
    1.13 +*
    1.14 +* Modification History:
    1.15 +*
    1.16 +*   Date        Name        Description
    1.17 +*   01/11/02    Ram         Creation.
    1.18 +*   02/12/08    Spieth      Fix errant 'new Object[][]{' insertion
    1.19 +*   02/19/08    Spieth      Removed ICUListResourceBundle dependancy
    1.20 +*******************************************************************************
    1.21 +*/
    1.22 +
    1.23 +#include <assert.h>
    1.24 +#include "reslist.h"
    1.25 +#include "unewdata.h"
    1.26 +#include "unicode/ures.h"
    1.27 +#include "errmsg.h"
    1.28 +#include "filestrm.h"
    1.29 +#include "cstring.h"
    1.30 +#include "unicode/ucnv.h"
    1.31 +#include "genrb.h"
    1.32 +#include "rle.h"
    1.33 +#include "uhash.h"
    1.34 +#include "uresimp.h"
    1.35 +#include "unicode/ustring.h"
    1.36 +
    1.37 +void res_write_java(struct SResource *res,UErrorCode *status);
    1.38 +
    1.39 +
    1.40 +static const char copyRight[] =
    1.41 +    "/* \n"
    1.42 +    " *******************************************************************************\n"
    1.43 +    " *\n"
    1.44 +    " *   Copyright (C) International Business Machines\n"
    1.45 +    " *   Corporation and others.  All Rights Reserved.\n"
    1.46 +    " *\n"
    1.47 +    " *******************************************************************************\n"
    1.48 +    " * $" "Source:  $ \n"
    1.49 +    " * $" "Date:  $ \n"
    1.50 +    " * $" "Revision:  $ \n"
    1.51 +    " *******************************************************************************\n"
    1.52 +    " */\n\n";
    1.53 +static const char warningMsg[] =
    1.54 +    "/*********************************************************************\n"
    1.55 +    "######################################################################\n"
    1.56 +    "\n"
    1.57 +    "   WARNING: This file is generated by genrb Version " GENRB_VERSION ".\n"
    1.58 +    "            If you edit this file, please make sure that, the source\n"
    1.59 +    "            of this file (XXXX.txt in LocaleElements_XXXX.java)\n"
    1.60 +    "            is also edited.\n"
    1.61 +    "######################################################################\n"
    1.62 +    " *********************************************************************\n"
    1.63 +    " */\n\n";
    1.64 +static const char* openBrace="{\n";
    1.65 +static const char* closeClass="    };\n"
    1.66 +                              "}\n";
    1.67 +
    1.68 +static const char* javaClass =  "import java.util.ListResourceBundle;\n\n"
    1.69 +                                "public class ";
    1.70 +
    1.71 +static const char* javaClass1=  " extends ListResourceBundle {\n\n"
    1.72 +                                "    /**\n"
    1.73 +                                "     * Overrides ListResourceBundle \n"
    1.74 +                                "     */\n"
    1.75 +                                "    public final Object[][] getContents() { \n"
    1.76 +                                "          return  contents;\n"
    1.77 +                                "    }\n\n"
    1.78 +                                "    private static Object[][] contents = {\n";
    1.79 +/*static const char* javaClassICU= " extends ListResourceBundle {\n\n"
    1.80 +                                 "    public %s  () {\n"
    1.81 +                                 "          super.contents = data;\n"
    1.82 +                                 "    }\n"
    1.83 +                                 "    static final Object[][] data = new Object[][] { \n";*/
    1.84 +static int tabCount = 3;
    1.85 +
    1.86 +static FileStream* out=NULL;
    1.87 +static struct SRBRoot* srBundle ;
    1.88 +/*static const char* outDir = NULL;*/
    1.89 +
    1.90 +static const char* bName=NULL;
    1.91 +static const char* pName=NULL;
    1.92 +
    1.93 +static void write_tabs(FileStream* os){
    1.94 +    int i=0;
    1.95 +    for(;i<=tabCount;i++){
    1.96 +        T_FileStream_write(os,"    ",4);
    1.97 +    }
    1.98 +}
    1.99 +
   1.100 +#define ZERO 0x30
   1.101 +
   1.102 +static const char* enc ="";
   1.103 +static UConverter* conv = NULL;
   1.104 +
   1.105 +static int32_t
   1.106 +uCharsToChars( char* target,int32_t targetLen, UChar* source, int32_t sourceLen,UErrorCode* status){
   1.107 +    int i=0, j=0;
   1.108 +    char str[30]={'\0'};
   1.109 +    while(i<sourceLen){
   1.110 +        if (source[i] == '\n') {
   1.111 +            if (j + 2 < targetLen) {
   1.112 +                uprv_strcat(target, "\\n");
   1.113 +            }
   1.114 +            j += 2;
   1.115 +        }else if(source[i]==0x0D){
   1.116 +            if(j+2<targetLen){
   1.117 +                uprv_strcat(target,"\\f");
   1.118 +            }
   1.119 +            j+=2;
   1.120 +        }else if(source[i] == '"'){
   1.121 +            if(source[i-1]=='\''){
   1.122 +                if(j+2<targetLen){
   1.123 +                    uprv_strcat(target,"\\");
   1.124 +                    target[j+1]= (char)source[i];
   1.125 +                }
   1.126 +                j+=2;
   1.127 +            }else if(source[i-1]!='\\'){
   1.128 +
   1.129 +                if(j+2<targetLen){
   1.130 +                    uprv_strcat(target,"\\");
   1.131 +                    target[j+1]= (char)source[i];
   1.132 +                }
   1.133 +                j+=2;
   1.134 +            }else if(source[i-1]=='\\'){
   1.135 +                target[j++]= (char)source[i];
   1.136 +            }
   1.137 +        }else if(source[i]=='\\'){
   1.138 +            if(i+1<sourceLen){
   1.139 +                switch(source[i+1]){
   1.140 +                case ',':
   1.141 +                case '!':
   1.142 +                case '?':
   1.143 +                case '#':
   1.144 +                case '.':
   1.145 +                case '%':
   1.146 +                case '&':
   1.147 +                case ':':
   1.148 +                case ';':
   1.149 +                    if(j+2<targetLen){
   1.150 +                       uprv_strcat(target,"\\\\");
   1.151 +                    }
   1.152 +                    j+=2;
   1.153 +                    break;
   1.154 +                case '"':
   1.155 +                case '\'':
   1.156 +                    if(j+3<targetLen){
   1.157 +                       uprv_strcat(target,"\\\\\\");
   1.158 +                    }
   1.159 +                    j+=3;
   1.160 +                    break;
   1.161 +                default :
   1.162 +                    if(j<targetLen){
   1.163 +                        target[j]=(char)source[i];
   1.164 +                    }
   1.165 +                    j++;
   1.166 +                    break;
   1.167 +                }
   1.168 +            }else{
   1.169 +                if(j<targetLen){
   1.170 +                    uprv_strcat(target,"\\\\");
   1.171 +                }
   1.172 +                j+=2;
   1.173 +            }
   1.174 +        }else if(source[i]>=0x20 && source[i]<0x7F/*ASCII*/){
   1.175 +            if(j<targetLen){
   1.176 +                target[j] = (char) source[i];
   1.177 +            }
   1.178 +            j++;
   1.179 +        }else{
   1.180 +            if(*enc =='\0' || source[i]==0x0000){
   1.181 +                uprv_strcpy(str,"\\u");
   1.182 +                itostr(str+2,source[i],16,4);
   1.183 +                if(j+6<targetLen){
   1.184 +                    uprv_strcat(target,str);
   1.185 +                }
   1.186 +                j+=6;
   1.187 +            }else{
   1.188 +                char dest[30] = {0};
   1.189 +                int retVal=ucnv_fromUChars(conv,dest,30,source+i,1,status);
   1.190 +                if(U_FAILURE(*status)){
   1.191 +                    return 0;
   1.192 +                }
   1.193 +                if(j+retVal<targetLen){
   1.194 +                    uprv_strcat(target,dest);
   1.195 +                }
   1.196 +                j+=retVal;
   1.197 +            }
   1.198 +        }
   1.199 +        i++;
   1.200 +    }
   1.201 +    return j;
   1.202 +}
   1.203 +
   1.204 +
   1.205 +static uint32_t
   1.206 +strrch(const char* source,uint32_t sourceLen,char find){
   1.207 +    const char* tSourceEnd =source + (sourceLen-1);
   1.208 +    while(tSourceEnd>= source){
   1.209 +        if(*tSourceEnd==find){
   1.210 +            return (uint32_t)(tSourceEnd-source);
   1.211 +        }
   1.212 +        tSourceEnd--;
   1.213 +    }
   1.214 +    return (uint32_t)(tSourceEnd-source);
   1.215 +}
   1.216 +
   1.217 +static int32_t getColumnCount(int32_t len){
   1.218 +    int32_t columnCount = 80;
   1.219 +    int32_t maxLines = 3000;
   1.220 +    int32_t adjustedLen = len*5; /* assume that every codepoint is represented in \uXXXX format*/
   1.221 +    /*
   1.222 +     * calculate the number of lines that
   1.223 +     * may be required if column count is 80
   1.224 +     */
   1.225 +    if (maxLines  < (adjustedLen / columnCount) ){
   1.226 +        columnCount = adjustedLen / maxLines;
   1.227 +    }
   1.228 +    return columnCount;
   1.229 +}
   1.230 +static void
   1.231 +str_write_java( uint16_t* src, int32_t srcLen, UBool printEndLine, UErrorCode *status){
   1.232 +
   1.233 +    uint32_t length = srcLen*8;
   1.234 +    uint32_t bufLen = 0;
   1.235 +    uint32_t columnCount;
   1.236 +    char* buf = (char*) malloc(sizeof(char)*length);
   1.237 +
   1.238 +    if(buf == NULL) {
   1.239 +        *status = U_MEMORY_ALLOCATION_ERROR;
   1.240 +        return;
   1.241 +    }
   1.242 +
   1.243 +    columnCount = getColumnCount(srcLen);
   1.244 +    memset(buf,0,length);
   1.245 +
   1.246 +    bufLen = uCharsToChars(buf,length,src,srcLen,status);
   1.247 +
   1.248 +    if(printEndLine)
   1.249 +        write_tabs(out);
   1.250 +
   1.251 +    if(U_FAILURE(*status)){
   1.252 +        uprv_free(buf);
   1.253 +        return;
   1.254 +    }
   1.255 +
   1.256 +    if(bufLen+(tabCount*4) > columnCount  ){
   1.257 +        uint32_t len = 0;
   1.258 +        char* current = buf;
   1.259 +        uint32_t add;
   1.260 +        while(len < bufLen){
   1.261 +            add = columnCount-(tabCount*4)-5/* for ", +\n */;
   1.262 +            current = buf +len;
   1.263 +            if (add < (bufLen-len)) {
   1.264 +                uint32_t idx = strrch(current,add,'\\');
   1.265 +                if (idx > add) {
   1.266 +                    idx = add;
   1.267 +                } else {
   1.268 +                    int32_t num =idx-1;
   1.269 +                    uint32_t seqLen;
   1.270 +                    while(num>0){
   1.271 +                        if(current[num]=='\\'){
   1.272 +                            num--;
   1.273 +                        }else{
   1.274 +                            break;
   1.275 +                        }
   1.276 +                    }
   1.277 +                    if ((idx-num)%2==0) {
   1.278 +                        idx--;
   1.279 +                    }
   1.280 +                    seqLen = (current[idx+1]=='u') ? 6 : 2;
   1.281 +                    if ((add-idx) < seqLen) {
   1.282 +                        add = idx + seqLen;
   1.283 +                    }
   1.284 +                }
   1.285 +            }
   1.286 +            T_FileStream_write(out,"\"",1);
   1.287 +            if(len+add<bufLen){
   1.288 +                T_FileStream_write(out,current,add);
   1.289 +                T_FileStream_write(out,"\" +\n",4);
   1.290 +                write_tabs(out);
   1.291 +            }else{
   1.292 +                T_FileStream_write(out,current,bufLen-len);
   1.293 +            }
   1.294 +            len+=add;
   1.295 +        }
   1.296 +    }else{
   1.297 +        T_FileStream_write(out,"\"",1);
   1.298 +        T_FileStream_write(out, buf,bufLen);
   1.299 +    }
   1.300 +    if(printEndLine){
   1.301 +        T_FileStream_write(out,"\",\n",3);
   1.302 +    }else{
   1.303 +        T_FileStream_write(out,"\"",1);
   1.304 +    }
   1.305 +    uprv_free(buf);
   1.306 +}
   1.307 +
   1.308 +/* Writing Functions */
   1.309 +static void
   1.310 +string_write_java(struct SResource *res,UErrorCode *status) {
   1.311 +    char resKeyBuffer[8];
   1.312 +    const char *resname = res_getKeyString(srBundle, res, resKeyBuffer);
   1.313 +
   1.314 +    str_write_java(res->u.fString.fChars,res->u.fString.fLength,TRUE,status);
   1.315 +    
   1.316 +	if(resname != NULL && uprv_strcmp(resname,"Rule")==0)
   1.317 +	{
   1.318 +        UChar* buf = (UChar*) uprv_malloc(sizeof(UChar)*res->u.fString.fLength);
   1.319 +        uprv_memcpy(buf,res->u.fString.fChars,res->u.fString.fLength);
   1.320 +        uprv_free(buf);
   1.321 +    }
   1.322 +
   1.323 +}
   1.324 +
   1.325 +static void
   1.326 +array_write_java( struct SResource *res, UErrorCode *status) {
   1.327 +
   1.328 +    uint32_t  i         = 0;
   1.329 +    const char* arr ="new String[] { \n";
   1.330 +    struct SResource *current = NULL;
   1.331 +    UBool allStrings    = TRUE;
   1.332 +
   1.333 +    if (U_FAILURE(*status)) {
   1.334 +        return;
   1.335 +    }
   1.336 +
   1.337 +    if (res->u.fArray.fCount > 0) {
   1.338 +
   1.339 +        current = res->u.fArray.fFirst;
   1.340 +        i = 0;
   1.341 +        while(current != NULL){
   1.342 +            if(current->fType!=URES_STRING){
   1.343 +                allStrings = FALSE;
   1.344 +                break;
   1.345 +            }
   1.346 +            current= current->fNext;
   1.347 +        }
   1.348 +
   1.349 +        current = res->u.fArray.fFirst;
   1.350 +        if(allStrings==FALSE){
   1.351 +            const char* object = "new Object[]{\n";
   1.352 +            write_tabs(out);
   1.353 +            T_FileStream_write(out, object, (int32_t)uprv_strlen(object));
   1.354 +            tabCount++;
   1.355 +        }else{
   1.356 +            write_tabs(out);
   1.357 +            T_FileStream_write(out, arr, (int32_t)uprv_strlen(arr));
   1.358 +            tabCount++;
   1.359 +        }
   1.360 +        while (current != NULL) {
   1.361 +            /*if(current->fType==URES_STRING){
   1.362 +                write_tabs(out);
   1.363 +            }*/
   1.364 +            res_write_java(current, status);
   1.365 +            if(U_FAILURE(*status)){
   1.366 +                return;
   1.367 +            }
   1.368 +            i++;
   1.369 +            current = current->fNext;
   1.370 +        }
   1.371 +        T_FileStream_write(out,"\n",1);
   1.372 +
   1.373 +        tabCount--;
   1.374 +        write_tabs(out);
   1.375 +        T_FileStream_write(out,"},\n",3);
   1.376 +
   1.377 +    } else {
   1.378 +        write_tabs(out);
   1.379 +        T_FileStream_write(out,arr,(int32_t)uprv_strlen(arr));
   1.380 +        write_tabs(out);
   1.381 +        T_FileStream_write(out,"},\n",3);
   1.382 +    }
   1.383 +}
   1.384 +
   1.385 +static void
   1.386 +intvector_write_java( struct SResource *res, UErrorCode *status) {
   1.387 +    uint32_t i = 0;
   1.388 +    const char* intArr = "new int[] {\n";
   1.389 +    /* const char* intC   = "new Integer(";   */
   1.390 +    const char* stringArr = "new String[]{\n";
   1.391 +    char resKeyBuffer[8];
   1.392 +    const char *resname = res_getKeyString(srBundle, res, resKeyBuffer);
   1.393 +    char buf[100];
   1.394 +    int len =0;
   1.395 +    buf[0]=0;
   1.396 +    write_tabs(out);
   1.397 +
   1.398 +    if(resname != NULL && uprv_strcmp(resname,"DateTimeElements")==0){
   1.399 +        T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr));
   1.400 +        tabCount++;
   1.401 +        for(i = 0; i<res->u.fIntVector.fCount; i++) {
   1.402 +            write_tabs(out);
   1.403 +            len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
   1.404 +            T_FileStream_write(out,"\"",1);
   1.405 +            T_FileStream_write(out,buf,len);
   1.406 +            T_FileStream_write(out,"\",",2);
   1.407 +            T_FileStream_write(out,"\n",1);
   1.408 +        }
   1.409 +    }else{
   1.410 +        T_FileStream_write(out, intArr, (int32_t)uprv_strlen(intArr));
   1.411 +        tabCount++;
   1.412 +        for(i = 0; i<res->u.fIntVector.fCount; i++) {
   1.413 +            write_tabs(out);
   1.414 +            /* T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); */
   1.415 +            len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
   1.416 +            T_FileStream_write(out,buf,len);
   1.417 +            /* T_FileStream_write(out,"),",2);  */
   1.418 +            /* T_FileStream_write(out,"\n",1);  */
   1.419 +            T_FileStream_write(out,",\n",2);
   1.420 +        }
   1.421 +    }
   1.422 +    tabCount--;
   1.423 +    write_tabs(out);
   1.424 +    T_FileStream_write(out,"},\n",3);
   1.425 +}
   1.426 +
   1.427 +static void
   1.428 +int_write_java(struct SResource *res,UErrorCode *status) {
   1.429 +    const char* intC   =  "new Integer(";
   1.430 +    char buf[100];
   1.431 +    int len =0;
   1.432 +    buf[0]=0;
   1.433 +
   1.434 +    /* write the binary data */
   1.435 +    write_tabs(out);
   1.436 +    T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC));
   1.437 +    len=itostr(buf, res->u.fIntValue.fValue, 10, 0);
   1.438 +    T_FileStream_write(out,buf,len);
   1.439 +    T_FileStream_write(out,"),\n",3 );
   1.440 +
   1.441 +}
   1.442 +
   1.443 +static void
   1.444 +bytes_write_java( struct SResource *res, UErrorCode *status) {
   1.445 +	const char* type  = "new byte[] {";
   1.446 +	const char* byteDecl = "%i, ";
   1.447 +    char byteBuffer[100] = { 0 };
   1.448 +	uint8_t*  byteArray = NULL;
   1.449 +    int byteIterator = 0;
   1.450 +	
   1.451 +    int32_t srcLen=res->u.fBinaryValue.fLength;
   1.452 +	
   1.453 +    if(srcLen>0 )
   1.454 +	{
   1.455 +        byteArray = res->u.fBinaryValue.fData;
   1.456 +
   1.457 +        write_tabs(out);
   1.458 +        T_FileStream_write(out, type, (int32_t)uprv_strlen(type));
   1.459 +        T_FileStream_write(out, "\n", 1);
   1.460 +        tabCount++;
   1.461 +
   1.462 +		for (;byteIterator<srcLen;byteIterator++)
   1.463 +		{
   1.464 +            if (byteIterator%16 == 0)
   1.465 +			{
   1.466 +			    write_tabs(out);
   1.467 +			}
   1.468 +
   1.469 +			if (byteArray[byteIterator] < 128)
   1.470 +			{
   1.471 +                sprintf(byteBuffer, byteDecl, byteArray[byteIterator]);
   1.472 +			}
   1.473 +			else
   1.474 +			{
   1.475 +                sprintf(byteBuffer, byteDecl, (byteArray[byteIterator]-256));
   1.476 +			}
   1.477 +
   1.478 +            T_FileStream_write(out, byteBuffer, (int32_t)uprv_strlen(byteBuffer));
   1.479 +
   1.480 +			if (byteIterator%16 == 15)
   1.481 +			{
   1.482 +                T_FileStream_write(out, "\n", 1);
   1.483 +			}
   1.484 +
   1.485 +		}
   1.486 +
   1.487 +        if (((byteIterator-1)%16) != 15)
   1.488 +		{
   1.489 +            T_FileStream_write(out, "\n", 1);
   1.490 +	    }
   1.491 +
   1.492 +		tabCount--;
   1.493 +        write_tabs(out);
   1.494 +		T_FileStream_write(out, "},\n", 3);
   1.495 +
   1.496 +	}
   1.497 +	else
   1.498 +    {
   1.499 +		/* Empty array */
   1.500 +        write_tabs(out);
   1.501 +        T_FileStream_write(out,type,(int32_t)uprv_strlen(type));
   1.502 +		T_FileStream_write(out,"},\n",3);
   1.503 +    }
   1.504 +
   1.505 +}
   1.506 +
   1.507 +static UBool start = TRUE;
   1.508 +
   1.509 +static void
   1.510 +table_write_java(struct SResource *res, UErrorCode *status) {
   1.511 +    uint32_t  i         = 0;
   1.512 +    struct SResource *current = NULL;
   1.513 +    const char* obj = "new Object[][]{\n";
   1.514 +
   1.515 +    if (U_FAILURE(*status)) {
   1.516 +        return ;
   1.517 +    }
   1.518 +
   1.519 +    if (res->u.fTable.fCount > 0) {
   1.520 +        if(start==FALSE){
   1.521 +            write_tabs(out);
   1.522 +            T_FileStream_write(out, obj, (int32_t)uprv_strlen(obj));
   1.523 +            tabCount++;
   1.524 +        }
   1.525 +        start = FALSE;
   1.526 +        current = res->u.fTable.fFirst;
   1.527 +        i       = 0;
   1.528 +
   1.529 +
   1.530 +        while (current != NULL) {
   1.531 +            char currentKeyBuffer[8];
   1.532 +            const char *currentKeyString = res_getKeyString(srBundle, current, currentKeyBuffer);
   1.533 +
   1.534 +            assert(i < res->u.fTable.fCount);
   1.535 +            write_tabs(out);
   1.536 +
   1.537 +            T_FileStream_write(out, openBrace, 2);
   1.538 +
   1.539 +
   1.540 +            tabCount++;
   1.541 +
   1.542 +            write_tabs(out);
   1.543 +            if(currentKeyString != NULL) {
   1.544 +                T_FileStream_write(out, "\"", 1);
   1.545 +                T_FileStream_write(out, currentKeyString,
   1.546 +                                   (int32_t)uprv_strlen(currentKeyString));
   1.547 +                T_FileStream_write(out, "\",\n", 2);
   1.548 +
   1.549 +                T_FileStream_write(out, "\n", 1);
   1.550 +            }
   1.551 +            res_write_java(current, status);
   1.552 +            if(U_FAILURE(*status)){
   1.553 +                return;
   1.554 +            }
   1.555 +            i++;
   1.556 +            current = current->fNext;
   1.557 +            tabCount--;
   1.558 +            write_tabs(out);
   1.559 +            T_FileStream_write(out, "},\n", 3);
   1.560 +        }
   1.561 +        if(tabCount>4){
   1.562 +            tabCount--;
   1.563 +            write_tabs(out);
   1.564 +            T_FileStream_write(out, "},\n", 3);
   1.565 +        }
   1.566 +
   1.567 +    } else {
   1.568 +        write_tabs(out);
   1.569 +        T_FileStream_write(out,obj,(int32_t)uprv_strlen(obj));
   1.570 +
   1.571 +        write_tabs(out);
   1.572 +        T_FileStream_write(out,"},\n",3);
   1.573 +
   1.574 +    }
   1.575 +
   1.576 +}
   1.577 +
   1.578 +void
   1.579 +res_write_java(struct SResource *res,UErrorCode *status) {
   1.580 +
   1.581 +    if (U_FAILURE(*status)) {
   1.582 +        return ;
   1.583 +    }
   1.584 +
   1.585 +    if (res != NULL) {
   1.586 +        switch (res->fType) {
   1.587 +        case URES_STRING:
   1.588 +             string_write_java    (res, status);
   1.589 +             return;
   1.590 +        case URES_ALIAS:
   1.591 +             printf("Encountered unsupported resource type %d of alias\n", res->fType);
   1.592 +             *status = U_UNSUPPORTED_ERROR;
   1.593 +			 return;
   1.594 +        case URES_INT_VECTOR:
   1.595 +             intvector_write_java (res, status);
   1.596 +             return;
   1.597 +        case URES_BINARY:
   1.598 +             bytes_write_java     (res, status);
   1.599 +             return;
   1.600 +        case URES_INT:
   1.601 +             int_write_java       (res, status);
   1.602 +             return;
   1.603 +        case URES_ARRAY:
   1.604 +             array_write_java     (res, status);
   1.605 +             return;
   1.606 +        case URES_TABLE:
   1.607 +             table_write_java     (res, status);
   1.608 +             return;
   1.609 +        default:
   1.610 +            break;
   1.611 +        }
   1.612 +    }
   1.613 +
   1.614 +    *status = U_INTERNAL_PROGRAM_ERROR;
   1.615 +}
   1.616 +
   1.617 +void
   1.618 +bundle_write_java(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc,
   1.619 +                  char *writtenFilename, int writtenFilenameLen,
   1.620 +                  const char* packageName, const char* bundleName,
   1.621 +                  UErrorCode *status) {
   1.622 +
   1.623 +    char fileName[256] = {'\0'};
   1.624 +    char className[256]={'\0'};
   1.625 +    /*char constructor[1000] = { 0 };*/
   1.626 +    /*UBool j1 =FALSE;*/
   1.627 +    /*outDir = outputDir;*/
   1.628 +
   1.629 +    start = TRUE;                        /* Reset the start indictor*/
   1.630 +
   1.631 +    bName = (bundleName==NULL) ? "LocaleElements" : bundleName;
   1.632 +    pName = (packageName==NULL)? "com.ibm.icu.impl.data" : packageName;
   1.633 +
   1.634 +    uprv_strcpy(className, bName);
   1.635 +    srBundle = bundle;
   1.636 +    if(uprv_strcmp(srBundle->fLocale,"root")!=0){
   1.637 +        uprv_strcat(className,"_");
   1.638 +        uprv_strcat(className,srBundle->fLocale);
   1.639 +    }
   1.640 +    if(outputDir){
   1.641 +        uprv_strcpy(fileName, outputDir);
   1.642 +        if(outputDir[uprv_strlen(outputDir)-1] !=U_FILE_SEP_CHAR){
   1.643 +            uprv_strcat(fileName,U_FILE_SEP_STRING);
   1.644 +        }
   1.645 +        uprv_strcat(fileName,className);
   1.646 +        uprv_strcat(fileName,".java");
   1.647 +    }else{
   1.648 +        uprv_strcat(fileName,className);
   1.649 +        uprv_strcat(fileName,".java");
   1.650 +    }
   1.651 +
   1.652 +    if (writtenFilename) {
   1.653 +        uprv_strncpy(writtenFilename, fileName, writtenFilenameLen);
   1.654 +    }
   1.655 +
   1.656 +    if (U_FAILURE(*status)) {
   1.657 +        return;
   1.658 +    }
   1.659 +
   1.660 +    out= T_FileStream_open(fileName,"w");
   1.661 +
   1.662 +    if(out==NULL){
   1.663 +        *status = U_FILE_ACCESS_ERROR;
   1.664 +        return;
   1.665 +    }
   1.666 +    if(getIncludeCopyright()){
   1.667 +        T_FileStream_write(out, copyRight, (int32_t)uprv_strlen(copyRight));
   1.668 +        T_FileStream_write(out, warningMsg, (int32_t)uprv_strlen(warningMsg));
   1.669 +    }
   1.670 +    T_FileStream_write(out,"package ",(int32_t)uprv_strlen("package "));
   1.671 +    T_FileStream_write(out,pName,(int32_t)uprv_strlen(pName));
   1.672 +    T_FileStream_write(out,";\n\n",3);
   1.673 +    T_FileStream_write(out, javaClass, (int32_t)uprv_strlen(javaClass));
   1.674 +    T_FileStream_write(out, className, (int32_t)uprv_strlen(className));
   1.675 +	T_FileStream_write(out, javaClass1, (int32_t)uprv_strlen(javaClass1));
   1.676 +
   1.677 +    /* if(j1){
   1.678 +          T_FileStream_write(out, javaClass1, (int32_t)uprv_strlen(javaClass1));
   1.679 +       }else{
   1.680 +           sprintf(constructor,javaClassICU,className);
   1.681 +           T_FileStream_write(out, constructor, (int32_t)uprv_strlen(constructor));
   1.682 +       }
   1.683 +    */
   1.684 +
   1.685 +    if(outputEnc && *outputEnc!='\0'){
   1.686 +        /* store the output encoding */
   1.687 +        enc = outputEnc;
   1.688 +        conv=ucnv_open(enc,status);
   1.689 +        if(U_FAILURE(*status)){
   1.690 +            return;
   1.691 +        }
   1.692 +    }
   1.693 +    res_write_java(bundle->fRoot, status);
   1.694 +
   1.695 +    T_FileStream_write(out, closeClass, (int32_t)uprv_strlen(closeClass));
   1.696 +
   1.697 +    T_FileStream_close(out);
   1.698 +
   1.699 +    ucnv_close(conv);
   1.700 +}

mercurial