2002-03-16 03:40:05 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File wrtjava.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 01/11/02 Ram Creation.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include "reslist.h"
|
|
|
|
#include "unewdata.h"
|
|
|
|
#include "unicode/ures.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "filestrm.h"
|
2002-03-20 23:56:22 +00:00
|
|
|
#include "cstring.h"
|
2002-03-16 03:40:05 +00:00
|
|
|
#include "unicode/ucnv.h"
|
|
|
|
#include "genrb.h"
|
|
|
|
#include "rle.h"
|
|
|
|
#include "ucol_tok.h"
|
|
|
|
#include "uhash.h"
|
|
|
|
|
|
|
|
void res_write_java(struct SResource *res,UErrorCode *status);
|
|
|
|
|
|
|
|
|
2002-04-04 02:45:18 +00:00
|
|
|
static const char copyRight[] =
|
|
|
|
"/* \n"
|
|
|
|
" *******************************************************************************\n"
|
|
|
|
" *\n"
|
|
|
|
" * Copyright (C) International Business Machines\n"
|
|
|
|
" * Corporation and others. All Rights Reserved.\n"
|
|
|
|
" *\n"
|
|
|
|
" *******************************************************************************\n"
|
|
|
|
" * $Source: /xsrl/Nsvn/icu/icu/source/tools/genrb/wrtjava.c,v $ \n"
|
|
|
|
" * $Date: 2002/04/04 02:43:27 $ \n"
|
|
|
|
" * $Revision: 1.9 $ \n"
|
|
|
|
" *******************************************************************************\n"
|
|
|
|
" */\n\n";
|
|
|
|
static const char warningMsg[] =
|
|
|
|
"/*********************************************************************\n"
|
|
|
|
"######################################################################\n"
|
|
|
|
"\n"
|
|
|
|
" WARNING: This file is generated by genrb Version " GENRB_VERSION ".\n"
|
|
|
|
" If you edit this file, please make sure that, the source\n"
|
|
|
|
" of this file (XXXX.txt in LocaleElements_XXXX.java)\n"
|
|
|
|
" is also edited.\n"
|
|
|
|
"######################################################################\n"
|
|
|
|
" *********************************************************************\n"
|
|
|
|
" */\n\n";
|
2002-03-16 03:40:05 +00:00
|
|
|
static const char* openBrace="{\n";
|
|
|
|
static const char* closeBrace="}\n";
|
|
|
|
static const char* closeClass=" };\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* javaClass = "package com.ibm.icu.impl.data;\n\n"
|
|
|
|
"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"
|
|
|
|
" */\n"
|
|
|
|
" public final Object[][] getContents() { \n"
|
|
|
|
" return contents;\n"
|
|
|
|
" }\n"
|
|
|
|
" private static Object[][] contents = {\n";
|
|
|
|
static const char* javaClassICU= " extends ICUListResourceBundle {\n\n"
|
|
|
|
" public %s () {\n"
|
|
|
|
" contents = new Object[][] { \n";
|
|
|
|
static int tabCount = 3;
|
|
|
|
|
|
|
|
static FileStream* out=NULL;
|
|
|
|
static struct SRBRoot* srBundle ;
|
|
|
|
static const char* outDir = NULL;
|
|
|
|
|
2002-04-02 03:06:50 +00:00
|
|
|
static void write_tabs(FileStream* os){
|
2002-03-16 03:40:05 +00:00
|
|
|
int i=0;
|
|
|
|
for(;i<=tabCount;i++){
|
2002-04-02 03:06:50 +00:00
|
|
|
T_FileStream_write(os," ",4);
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static const char* enc ="";
|
|
|
|
static UConverter* conv = NULL;
|
|
|
|
|
|
|
|
#define MAX_DIGITS 10
|
|
|
|
static int32_t
|
|
|
|
itostr(char * buffer, int32_t i, uint32_t radix, int32_t pad)
|
|
|
|
{
|
|
|
|
int32_t length = 0;
|
|
|
|
int32_t num = 0;
|
|
|
|
int32_t save = i;
|
|
|
|
int digit;
|
|
|
|
int32_t j;
|
|
|
|
char temp;
|
|
|
|
|
|
|
|
/* if i is negative make it positive */
|
|
|
|
if(i<0){
|
|
|
|
i=-i;
|
|
|
|
}
|
|
|
|
|
|
|
|
do{
|
|
|
|
digit = (int)(i % radix);
|
2002-04-02 03:06:50 +00:00
|
|
|
buffer[length++]=(char)(digit<=9?(0x0030+digit):(0x0030+digit+7));
|
2002-03-16 03:40:05 +00:00
|
|
|
i=i/radix;
|
|
|
|
} while(i);
|
|
|
|
|
|
|
|
while (length < pad){
|
|
|
|
buffer[length++] = 0x0030;/*zero padding */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if i is negative add the negative sign */
|
|
|
|
if(save < 0){
|
|
|
|
buffer[length++]='-';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* null terminate the buffer */
|
|
|
|
if(length<MAX_DIGITS){
|
|
|
|
buffer[length] = 0x0000;
|
|
|
|
}
|
|
|
|
|
|
|
|
num= (pad>=length) ? pad :length;
|
|
|
|
|
|
|
|
|
|
|
|
/* Reverses the string */
|
|
|
|
for (j = 0; j < (num / 2); j++){
|
|
|
|
temp = buffer[(length-1) - j];
|
|
|
|
buffer[(length-1) - j] = buffer[j];
|
|
|
|
buffer[j] = temp;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'};
|
|
|
|
while(i<sourceLen){
|
2002-03-22 03:15:27 +00:00
|
|
|
if (source[i] == '\n') {
|
|
|
|
if (j + 2 < targetLen) {
|
|
|
|
uprv_strcat(target, "\\n");
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
2002-03-22 03:15:27 +00:00
|
|
|
j += 2;
|
2002-03-16 03:40:05 +00:00
|
|
|
}else if(source[i]==0x0D){
|
|
|
|
if(j+2<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,"\\f");
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
j+=2;
|
|
|
|
}else if(source[i] == '"'){
|
|
|
|
if(source[i-1]=='\''){
|
|
|
|
if(j+2<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,"\\");
|
2002-03-16 03:40:05 +00:00
|
|
|
target[j+1]= (char)source[i];
|
|
|
|
}
|
|
|
|
j+=2;
|
|
|
|
}else if(source[i-1]!='\\'){
|
|
|
|
if(j+2<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,"\\");
|
2002-03-16 03:40:05 +00:00
|
|
|
target[j+1]= (char)source[i];
|
|
|
|
}
|
|
|
|
j+=2;
|
|
|
|
}
|
|
|
|
}else if(source[i]=='\\'){
|
|
|
|
if(i+1<sourceLen){
|
|
|
|
switch(source[i+1]){
|
|
|
|
case ',':
|
|
|
|
case '!':
|
|
|
|
case '?':
|
|
|
|
case '#':
|
|
|
|
case '.':
|
|
|
|
case '%':
|
|
|
|
case '&':
|
|
|
|
case ':':
|
|
|
|
case ';':
|
|
|
|
if(j+2<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,"\\\\");
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
j+=2;
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
case '\'':
|
|
|
|
if(j+3<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,"\\\\\\");
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
j+=3;
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
if(j<targetLen){
|
|
|
|
target[j]=(char)source[i];
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(j<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,"\\\\");
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
j+=2;
|
|
|
|
}
|
|
|
|
}else if(source[i]>=0x20 && source[i]<0x7F/*ASCII*/){
|
|
|
|
if(j<targetLen){
|
|
|
|
target[j] = (char) source[i];
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}else{
|
2002-04-02 03:06:50 +00:00
|
|
|
if(*enc =='\0' || source[i]==0x0000){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcpy(str,"\\u");
|
2002-03-16 03:40:05 +00:00
|
|
|
itostr(str+2,source[i],16,4);
|
|
|
|
if(j+6<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,str);
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
j+=6;
|
|
|
|
}else{
|
|
|
|
char dest[30] = {0};
|
|
|
|
int retVal=ucnv_fromUChars(conv,dest,30,source+i,1,status);
|
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(j+retVal<targetLen){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(target,dest);
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
j+=retVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
strrch(const char* source,uint32_t sourceLen,char find){
|
|
|
|
const char* tSourceEnd =source + (sourceLen-1);
|
|
|
|
while(tSourceEnd>= source){
|
|
|
|
if(*tSourceEnd==find){
|
|
|
|
return (tSourceEnd-source);
|
|
|
|
}
|
|
|
|
tSourceEnd--;
|
|
|
|
}
|
|
|
|
return (tSourceEnd-source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
str_write_java( uint16_t* src, int32_t srcLen, UErrorCode *status){
|
|
|
|
|
|
|
|
uint32_t length = srcLen*8;
|
|
|
|
uint32_t retVal = 0;
|
|
|
|
char* buf = (char*) malloc(sizeof(char)*length);
|
|
|
|
memset(buf,0,length);
|
|
|
|
|
|
|
|
retVal = uCharsToChars(buf,length,src,srcLen,status);
|
2002-03-22 23:47:27 +00:00
|
|
|
write_tabs(out);
|
2002-03-16 03:40:05 +00:00
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-22 23:47:27 +00:00
|
|
|
if(retVal+(tabCount*4) > 70 ){
|
2002-03-16 03:40:05 +00:00
|
|
|
uint32_t len = 0;
|
|
|
|
char* current = buf;
|
|
|
|
uint32_t add;
|
|
|
|
uint32_t index;
|
|
|
|
while(len < retVal){
|
|
|
|
index =0;
|
2002-03-22 23:47:27 +00:00
|
|
|
add = 70-(tabCount*4)-5/* for ", +\n */;
|
2002-03-16 03:40:05 +00:00
|
|
|
current = buf +len;
|
|
|
|
index = strrch(current,add,'\\');
|
|
|
|
if(current[index+1]=='u'){
|
|
|
|
if((add-index)<6){
|
|
|
|
add+= (6-(add-index));
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(current[index-1]!='\\'){
|
|
|
|
if((add-index)<2){
|
|
|
|
add+= (2-(add-index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
T_FileStream_write(out,"\"",1);
|
|
|
|
if(len+add<retVal){
|
|
|
|
T_FileStream_write(out,current,add);
|
2002-03-22 23:47:27 +00:00
|
|
|
T_FileStream_write(out,"\" +\n",4);
|
2002-03-16 03:40:05 +00:00
|
|
|
write_tabs(out);
|
|
|
|
}else{
|
|
|
|
T_FileStream_write(out,current,retVal-len);
|
|
|
|
}
|
|
|
|
len+=add;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
T_FileStream_write(out,"\"",1);
|
|
|
|
T_FileStream_write(out, buf,retVal);
|
|
|
|
}
|
|
|
|
T_FileStream_write(out,"\",\n",3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writing Functions */
|
|
|
|
static void
|
|
|
|
string_write_java(struct SResource *res,UErrorCode *status) {
|
|
|
|
str_write_java(res->u.fString.fChars,res->u.fString.fLength,status);
|
2002-03-20 23:56:22 +00:00
|
|
|
if(uprv_strcmp(srBundle->fKeys+res->fKey,"Rule")==0){
|
2002-03-16 03:40:05 +00:00
|
|
|
UChar* buf = (UChar*) uprv_malloc(sizeof(UChar)*res->u.fString.fLength);
|
|
|
|
uprv_memcpy(buf,res->u.fString.fChars,res->u.fString.fLength);
|
|
|
|
uprv_free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
array_write_java( struct SResource *res, UErrorCode *status) {
|
|
|
|
|
|
|
|
uint32_t i = 0;
|
2002-04-02 03:06:50 +00:00
|
|
|
const char* arr ="new String[] { \n";
|
2002-03-16 03:40:05 +00:00
|
|
|
struct SResource *current = NULL;
|
|
|
|
struct SResource *first =NULL;
|
|
|
|
UBool decrementTabs = FALSE;
|
|
|
|
UBool allStrings = TRUE;
|
2002-04-02 03:06:50 +00:00
|
|
|
|
2002-03-16 03:40:05 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res->u.fArray.fCount > 0) {
|
|
|
|
|
|
|
|
current = res->u.fArray.fFirst;
|
|
|
|
i = 0;
|
|
|
|
while(current != NULL){
|
|
|
|
if(current->fType!=RES_STRING){
|
|
|
|
allStrings = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
current= current->fNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = res->u.fArray.fFirst;
|
2002-03-22 23:47:27 +00:00
|
|
|
if(allStrings==FALSE){
|
2002-04-02 03:06:50 +00:00
|
|
|
const char* object = "new Object[]{\n";
|
2002-03-16 03:40:05 +00:00
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out, object,uprv_strlen(object));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
decrementTabs = TRUE;
|
|
|
|
}else{
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,arr,uprv_strlen(arr));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
}
|
|
|
|
first=current;
|
|
|
|
while (current != NULL) {
|
2002-03-22 23:47:27 +00:00
|
|
|
/*if(current->fType==RES_STRING){
|
2002-03-16 03:40:05 +00:00
|
|
|
write_tabs(out);
|
2002-03-22 23:47:27 +00:00
|
|
|
}*/
|
2002-03-16 03:40:05 +00:00
|
|
|
res_write_java(current, status);
|
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
current = current->fNext;
|
|
|
|
}
|
|
|
|
T_FileStream_write(out,"\n",1);
|
|
|
|
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* array is empty */
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
intvector_write_java( struct SResource *res, UErrorCode *status) {
|
|
|
|
uint32_t i = 0;
|
2002-04-02 03:06:50 +00:00
|
|
|
const char* intArr = "new Integer[] {\n";
|
|
|
|
const char* intC = "new Integer(";
|
|
|
|
const char* stringArr = "new String[]{\n";
|
2002-03-16 03:40:05 +00:00
|
|
|
char buf[100];
|
|
|
|
int len =0;
|
|
|
|
buf[0]=0;
|
|
|
|
write_tabs(out);
|
|
|
|
|
2002-03-20 23:56:22 +00:00
|
|
|
if(uprv_strcmp(srBundle->fKeys+res->fKey,"DateTimeElements")==0){
|
|
|
|
T_FileStream_write(out,stringArr,uprv_strlen(stringArr));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
for(i = 0; i<res->u.fIntVector.fCount; i++) {
|
|
|
|
write_tabs(out);
|
|
|
|
len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
|
|
|
|
T_FileStream_write(out,"\"",1);
|
|
|
|
T_FileStream_write(out,buf,len);
|
|
|
|
T_FileStream_write(out,"\",",2);
|
|
|
|
T_FileStream_write(out,"\n",1);
|
|
|
|
}
|
|
|
|
}else{
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,intArr,uprv_strlen(intArr));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
for(i = 0; i<res->u.fIntVector.fCount; i++) {
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,intC,uprv_strlen(intC));
|
2002-03-16 03:40:05 +00:00
|
|
|
len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
|
|
|
|
T_FileStream_write(out,buf,len);
|
|
|
|
T_FileStream_write(out,"),",2);
|
|
|
|
T_FileStream_write(out,"\n",1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
int_write_java(struct SResource *res,UErrorCode *status) {
|
2002-04-02 03:06:50 +00:00
|
|
|
const char* intC = "new Integer(";
|
2002-03-16 03:40:05 +00:00
|
|
|
char buf[100];
|
|
|
|
int len =0;
|
|
|
|
buf[0]=0;
|
|
|
|
|
|
|
|
/* write the binary data */
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,intC,uprv_strlen(intC));
|
2002-03-16 03:40:05 +00:00
|
|
|
len=itostr(buf,res->u.fIntValue.fValue,10,0);
|
|
|
|
T_FileStream_write(out,buf,len);
|
|
|
|
T_FileStream_write(out,"),\n",3 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bin_write_java( struct SResource *res, UErrorCode *status) {
|
2002-04-02 03:06:50 +00:00
|
|
|
const char* arr ="new Object[][]{\n";
|
|
|
|
const char* type = "COMPRESSED_BINARY, ";
|
2002-04-04 02:45:18 +00:00
|
|
|
const char* ext;
|
2002-03-16 03:40:05 +00:00
|
|
|
int32_t srcLen=res->u.fBinaryValue.fLength;
|
2002-04-02 03:06:50 +00:00
|
|
|
|
2002-03-16 03:40:05 +00:00
|
|
|
if(srcLen>0 ){
|
|
|
|
uint16_t* target=NULL;
|
|
|
|
uint16_t* saveTarget = NULL;
|
|
|
|
int32_t tgtLen = 0;
|
2002-03-20 23:56:22 +00:00
|
|
|
if(uprv_strcmp(srBundle->fKeys+res->fKey,"%%CollationBin")==0 || uprv_strcmp(srBundle->fKeys+res->fKey,"BreakDictionaryData")==0){
|
2002-03-16 03:40:05 +00:00
|
|
|
char fileName[1024] ={0};
|
|
|
|
char fn[1024] = {0};
|
|
|
|
FileStream* datFile = NULL;
|
2002-03-20 23:56:22 +00:00
|
|
|
if(uprv_strcmp(srBundle->fKeys+res->fKey,"BreakDictionaryData")==0){
|
|
|
|
uprv_strcat(fileName,"BreakDictionaryData");
|
2002-03-16 03:40:05 +00:00
|
|
|
ext = ".ucs";
|
|
|
|
}else{
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(fileName,"CollationElements");
|
2002-03-16 03:40:05 +00:00
|
|
|
ext=".res";
|
|
|
|
}
|
2002-03-20 23:56:22 +00:00
|
|
|
if(uprv_strcmp(srBundle->fLocale,"root")!=0){
|
|
|
|
uprv_strcat(fileName,"_");
|
|
|
|
uprv_strcat(fileName,srBundle->fLocale);
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(fileName,ext);
|
2002-03-16 03:40:05 +00:00
|
|
|
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(fn,outDir);
|
|
|
|
if(outDir[uprv_strlen(outDir)-1]!=U_FILE_SEP_CHAR){
|
|
|
|
uprv_strcat(fn,U_FILE_SEP_STRING);
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(fn,fileName);
|
2002-03-16 03:40:05 +00:00
|
|
|
type = "RESOURCE_BINARY,";
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,arr,uprv_strlen(arr));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,openBrace,uprv_strlen(openBrace));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,type,uprv_strlen(type));
|
2002-03-16 03:40:05 +00:00
|
|
|
T_FileStream_write(out,"\"",1);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,fileName,uprv_strlen(fileName));
|
2002-03-16 03:40:05 +00:00
|
|
|
T_FileStream_write(out,"\"\n",2);
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
datFile=T_FileStream_open(fn,"w");
|
|
|
|
T_FileStream_write(datFile,res->u.fBinaryValue.fData,res->u.fBinaryValue.fLength);
|
|
|
|
T_FileStream_close(datFile);
|
|
|
|
|
|
|
|
}else{
|
2002-03-20 23:56:22 +00:00
|
|
|
if(uprv_strcmp(srBundle->fKeys+res->fKey,"BreakDictionaryData")==0){
|
2002-03-16 03:40:05 +00:00
|
|
|
srcLen = res->u.fBinaryValue.fLength/2;
|
|
|
|
target = (uint16_t*)malloc(sizeof(uint16_t) * srcLen);
|
|
|
|
if(target){
|
|
|
|
saveTarget = target;
|
|
|
|
type = "COMPRESSED_STRING, ";
|
|
|
|
tgtLen = usArrayToRLEString((uint16_t*)res->u.fBinaryValue.fData,
|
|
|
|
srcLen,target, srcLen,status);
|
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
printf("Could not encode got error : %s \n", u_errorName(*status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if DEBUG
|
|
|
|
{
|
|
|
|
/***************** Test Roundtripping *********************/
|
2002-03-16 04:17:12 +00:00
|
|
|
int32_t myTargetLen = rleStringToUCharArray(target,tgtLen,NULL,0,status);
|
2002-03-16 03:40:05 +00:00
|
|
|
uint16_t* myTarget = (uint16_t*) malloc(sizeof(uint16_t) * myTargetLen);
|
|
|
|
int i=0;
|
|
|
|
int32_t retVal=0;
|
|
|
|
uint16_t* saveSrc = (uint16_t*)res->u.fBinaryValue.fData;
|
|
|
|
*status = U_ZERO_ERROR;
|
2002-03-16 04:17:12 +00:00
|
|
|
retVal=rleStringToUCharArray(target,tgtLen,myTarget,myTargetLen,status);
|
2002-03-16 03:40:05 +00:00
|
|
|
if(U_SUCCESS(*status)){
|
|
|
|
|
|
|
|
for(i=0; i< srcLen;i++){
|
|
|
|
if(saveSrc[i]!= myTarget[i]){
|
|
|
|
printf("the encoded string cannot be decoded Expected : 0x%04X Got : %: 0x%04X at %i\n",res->u.fBinaryValue.fData[i],myTarget[i], i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
printf("Could not decode got error : %s \n", u_errorName(*status));
|
|
|
|
}
|
|
|
|
free(myTarget);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}else{
|
|
|
|
*status= U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
srcLen = res->u.fBinaryValue.fLength;
|
|
|
|
target = (uint16_t*)malloc(sizeof(uint16_t) * srcLen);
|
|
|
|
saveTarget = target;
|
|
|
|
if(target){
|
|
|
|
tgtLen = byteArrayToRLEString(res->u.fBinaryValue.fData,
|
|
|
|
srcLen,target, srcLen,status);
|
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
printf("Could not encode got error : %s \n", u_errorName(*status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if DEBUG
|
|
|
|
/***************** Test Roundtripping *********************/
|
|
|
|
{
|
2002-03-16 04:17:12 +00:00
|
|
|
int32_t myTargetLen = rleStringToByteArray(target,tgtLen,NULL,0,status);
|
2002-03-16 03:40:05 +00:00
|
|
|
uint8_t* myTarget = (uint8_t*) malloc(sizeof(uint8_t) * myTargetLen);
|
|
|
|
int i=0;
|
|
|
|
int32_t retVal=0;
|
|
|
|
|
|
|
|
*status = U_ZERO_ERROR;
|
2002-03-16 04:17:12 +00:00
|
|
|
retVal=rleStringToByteArray(target,tgtLen,myTarget,myTargetLen,status);
|
2002-03-16 03:40:05 +00:00
|
|
|
if(U_SUCCESS(*status)){
|
|
|
|
|
|
|
|
for(i=0; i< srcLen;i++){
|
|
|
|
if(res->u.fBinaryValue.fData[i]!= myTarget[i]){
|
|
|
|
printf("the encoded string cannot be decoded Expected : 0x%02X Got : %: 0x%02X at %i\n",res->u.fBinaryValue.fData[i],myTarget[i], i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
printf("Could not decode got error : %s \n", u_errorName(*status));
|
|
|
|
}
|
|
|
|
free(myTarget);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}else{
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,arr,uprv_strlen(arr));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,openBrace,uprv_strlen(openBrace));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,type,uprv_strlen(type));
|
2002-03-16 03:40:05 +00:00
|
|
|
str_write_java(target,tgtLen,status);
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
|
|
|
|
|
|
|
|
free(target);
|
|
|
|
}
|
|
|
|
}
|
2002-03-20 23:56:22 +00:00
|
|
|
/* uprv_strcpy(buffer,"(byte) 0x");
|
2002-03-16 03:40:05 +00:00
|
|
|
|
|
|
|
if(res->u.fBinaryValue.fLength>0 ){
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,byte,uprv_strlen(byte));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
write_tabs(out);
|
|
|
|
while(i<res->u.fBinaryValue.fLength){
|
|
|
|
uint8_t data= res->u.fBinaryValue.fData[i];
|
|
|
|
buffer[9] =0;
|
|
|
|
len=itostr(&buffer[9],data,16,2);
|
|
|
|
T_FileStream_write(out,buffer,len+9);
|
|
|
|
T_FileStream_write(out,", ",2);
|
|
|
|
if(count==10){
|
|
|
|
count=0;
|
|
|
|
T_FileStream_write(out,"\n",1);
|
|
|
|
write_tabs(out);
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
T_FileStream_write(out,"\n",1);
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static UBool start = TRUE;
|
|
|
|
|
|
|
|
static void
|
|
|
|
table_write_java(struct SResource *res, UErrorCode *status) {
|
|
|
|
uint32_t i = 0;
|
|
|
|
UBool allStrings =TRUE;
|
|
|
|
struct SResource *current = NULL;
|
|
|
|
struct SResource *save = NULL;
|
2002-04-02 03:06:50 +00:00
|
|
|
const char* obj = "new Object[][]{\n";
|
2002-03-16 03:40:05 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res->u.fTable.fCount > 0) {
|
|
|
|
if(start==FALSE){
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,obj,uprv_strlen(obj));
|
2002-03-16 03:40:05 +00:00
|
|
|
tabCount++;
|
|
|
|
}
|
|
|
|
start = FALSE;
|
|
|
|
save = current = res->u.fTable.fFirst;
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while (current != NULL) {
|
|
|
|
assert(i < res->u.fTable.fCount);
|
|
|
|
write_tabs(out);
|
|
|
|
|
|
|
|
T_FileStream_write(out,"{\n",2);
|
|
|
|
|
|
|
|
|
|
|
|
tabCount++;
|
|
|
|
allStrings=FALSE;
|
|
|
|
|
|
|
|
write_tabs(out);
|
|
|
|
|
|
|
|
T_FileStream_write(out,"\"",1);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,srBundle->fKeys+current->fKey,uprv_strlen(srBundle->fKeys+current->fKey));
|
2002-03-22 23:47:27 +00:00
|
|
|
T_FileStream_write(out,"\",\n",2);
|
2002-03-16 03:40:05 +00:00
|
|
|
|
2002-03-22 23:47:27 +00:00
|
|
|
T_FileStream_write(out,"\n",1);
|
|
|
|
|
2002-03-16 03:40:05 +00:00
|
|
|
res_write_java(current, status);
|
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
current = current->fNext;
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
}
|
|
|
|
if(tabCount>4){
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"},\n",3);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* table is empty */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
res_write_java(struct SResource *res,UErrorCode *status) {
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res != NULL) {
|
|
|
|
switch (res->fType) {
|
|
|
|
case RES_STRING:
|
|
|
|
string_write_java (res, status);
|
|
|
|
return;
|
|
|
|
case RES_INT_VECTOR:
|
|
|
|
intvector_write_java (res, status);
|
|
|
|
return;
|
|
|
|
case RES_BINARY:
|
|
|
|
bin_write_java (res, status);
|
|
|
|
return;
|
|
|
|
case RES_INT:
|
|
|
|
int_write_java (res, status);
|
|
|
|
return;
|
|
|
|
case RES_ARRAY:
|
|
|
|
array_write_java (res, status);
|
|
|
|
return;
|
|
|
|
case RES_TABLE:
|
|
|
|
table_write_java (res, status);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-03-19 17:49:17 +00:00
|
|
|
bundle_write_java(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, char *writtenFilename, int writtenFilenameLen, UErrorCode *status) {
|
2002-03-16 03:40:05 +00:00
|
|
|
|
|
|
|
char fileName[256] = {'\0'};
|
|
|
|
char className[256]={'\0'};
|
|
|
|
char constructor[1000] = { 0 };
|
|
|
|
UBool j1 =FALSE;
|
|
|
|
outDir = outputDir;
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcpy(className, "LocaleElements");
|
2002-03-16 03:40:05 +00:00
|
|
|
srBundle = bundle;
|
2002-03-20 23:56:22 +00:00
|
|
|
if(uprv_strcmp(srBundle->fLocale,"root")!=0){
|
|
|
|
uprv_strcat(className,"_");
|
|
|
|
uprv_strcat(className,srBundle->fLocale);
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
if(outputDir){
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcpy(fileName, outputDir);
|
|
|
|
if(outputDir[uprv_strlen(outputDir)-1] !=U_FILE_SEP_CHAR){
|
|
|
|
uprv_strcat(fileName,U_FILE_SEP_STRING);
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(fileName,className);
|
|
|
|
uprv_strcat(fileName,".java");
|
2002-03-16 03:40:05 +00:00
|
|
|
}else{
|
2002-03-20 23:56:22 +00:00
|
|
|
uprv_strcat(fileName,className);
|
|
|
|
uprv_strcat(fileName,".java");
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
2002-03-19 17:49:17 +00:00
|
|
|
|
|
|
|
if (writtenFilename) {
|
|
|
|
uprv_strncpy(writtenFilename, fileName, writtenFilenameLen);
|
|
|
|
}
|
|
|
|
|
2002-03-16 03:40:05 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out= T_FileStream_open(fileName,"w");
|
|
|
|
|
|
|
|
if(out==NULL){
|
|
|
|
*status = U_FILE_ACCESS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2002-03-22 18:57:09 +00:00
|
|
|
if(getIncludeCopyright()){
|
|
|
|
T_FileStream_write(out,copyRight,uprv_strlen(copyRight));
|
2002-04-04 02:45:18 +00:00
|
|
|
T_FileStream_write(out,warningMsg,uprv_strlen(warningMsg));
|
2002-03-22 18:57:09 +00:00
|
|
|
}
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,javaClass,uprv_strlen(javaClass));
|
|
|
|
T_FileStream_write(out,className,uprv_strlen(className));
|
2002-03-16 03:40:05 +00:00
|
|
|
if(j1){
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,javaClass1,uprv_strlen(javaClass1));
|
2002-03-16 03:40:05 +00:00
|
|
|
}else{
|
|
|
|
sprintf(constructor,javaClassICU,className);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,constructor,uprv_strlen(constructor));
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
2002-04-02 03:06:50 +00:00
|
|
|
if(outputEnc && *outputEnc!='\0'){
|
2002-03-16 03:40:05 +00:00
|
|
|
/* store the output encoding */
|
|
|
|
enc = outputEnc;
|
|
|
|
conv=ucnv_open(enc,status);
|
|
|
|
if(U_FAILURE(*status)){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res_write_java(bundle->fRoot, status);
|
|
|
|
if(j1){
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,closeClass, uprv_strlen(closeClass));
|
2002-03-16 03:40:05 +00:00
|
|
|
}else{
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
|
|
|
T_FileStream_write(out,"};\n",3);
|
|
|
|
tabCount--;
|
|
|
|
write_tabs(out);
|
2002-03-20 23:56:22 +00:00
|
|
|
T_FileStream_write(out,closeBrace,uprv_strlen(closeBrace));
|
|
|
|
T_FileStream_write(out,closeBrace,uprv_strlen(closeBrace));
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T_FileStream_close(out);
|
|
|
|
|
|
|
|
ucnv_close(conv);
|
|
|
|
}
|