X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..d5d484b0fbe924d3663b177965538d517ee412c1:/icuSources/tools/genrb/wrtxml.c diff --git a/icuSources/tools/genrb/wrtxml.c b/icuSources/tools/genrb/wrtxml.c index 57813b76..4e0cd731 100644 --- a/icuSources/tools/genrb/wrtxml.c +++ b/icuSources/tools/genrb/wrtxml.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2002-2004, International Business Machines +* Copyright (C) 2002-2006, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -123,166 +123,46 @@ static uint32_t computeCRC(char *ptr, uint32_t len, uint32_t lastcrc){ return(crc); } -/*check the language with ISO 639 standard*/ -static UBool checkISOLanguage(char* language) { - int i = 0; - int result = -1; - - while(ISOLanguages[i] != '\0') { - result = uprv_strcmp(language, ISOLanguages[i]); - if(result == 0) { - return TRUE; - } - i++; - } - return FALSE; -} - -/*check the language with ISO 639 standard*/ -static UBool checkISOCountry(char* country) { - int i = 0; - int result = -1; - - while(ISOCountries[i]!='\0') { - result = uprv_strcmp(country, ISOCountries[i]); - if(result == 0) { - return TRUE; +static void strnrepchr(char* src, int32_t srcLen, char s, char r){ + int32_t i = 0; + for(i=0;i\n" @@ -291,7 +171,7 @@ static const char* xmlHeader = "\n" static const char* bundleStart = "\n"; static const char* bundleEnd = "\n"; -void res_write_xml(struct SResource *res, const char* id, const char* language, UErrorCode *status); +void res_write_xml(struct SResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status); static char* convertAndEscape(char** pDest, int32_t destCap, int32_t* destLength, const UChar* src, int32_t srcLen, UErrorCode* status){ @@ -408,6 +288,7 @@ static char* convertAndEscape(char** pDest, int32_t destCap, int32_t* destLength temp = (char*) uprv_malloc(sizeof(char)*destCap); if(temp==NULL){ *status=U_MEMORY_ALLOCATION_ERROR; + uprv_free(dest); return NULL; } uprv_memmove(temp,dest,destLen); @@ -428,13 +309,7 @@ static char* convertAndEscape(char** pDest, int32_t destCap, int32_t* destLength #define LF 0x000D #define AT_SIGN 0x0040 -static const UChar tokens[][11] = { - {0x0040, 0x0074, 0x0072, 0x0061, 0x006e, 0x0073, 0x006c, 0x0061, 0x0074, 0x0065, 0x0000}, /* @translate */ - {0x0040, 0x006e, 0x006f, 0x0074, 0x0065, 0x0000} /* @note */ -}; -static const UChar yes[] = { 0x0079, 0x0065, 0x0073, 0x0000}; /* yes */ -static const UChar no[] ={ 0x006e, 0x006f, 0x0000 }; /* no */ @@ -597,7 +472,7 @@ string_write_xml(struct SResource *res, const char* id, const char* language, UE char* sid = NULL; const char* strStart = "", 2); + /* T_FileStream_write(out,language, (int32_t)uprv_strlen(language)); */ + T_FileStream_write(out,">", 1); buf = convertAndEscape(&buf,0,&bufLen,res->u.fString.fChars,res->u.fString.fLength,status); @@ -662,8 +537,8 @@ string_write_xml(struct SResource *res, const char* id, const char* language, UE write_tabs(out); T_FileStream_write(out,valStrStart, (int32_t)uprv_strlen(valStrStart)); - T_FileStream_write(out,language, (int32_t)uprv_strlen(language)); - T_FileStream_write(out,"\">", 2); + /*T_FileStream_write(out,language, (int32_t)uprv_strlen(language));*/ + T_FileStream_write(out,">", 1); buf = convertAndEscape(&buf,0,&bufLen,res->u.fString.fChars,res->u.fString.fLength,status); if(U_FAILURE(*status)){ @@ -802,7 +677,7 @@ array_write_xml( struct SResource *res, const char* id, const char* language, UE index++; subId = getID(sid, c, subId); - res_write_xml(current, subId, language, status); + res_write_xml(current, subId, language, FALSE, status); uprv_free(subId); subId = NULL; if(U_FAILURE(*status)){ @@ -823,7 +698,7 @@ intvector_write_xml( struct SResource *res, const char* id, const char* language const char* end = "\n"; const char* startKey= "resname=\""; - const char* intStart = "u.fBinaryValue.fFileName!=NULL){ uprv_strcpy(fileName, res->u.fBinaryValue.fFileName); f = uprv_strrchr(fileName, '\\'); - f++; + if (f != NULL) { + f++; + } + else { + f = fileName; + } ext = uprv_strrchr(fileName, '.'); + if (ext == NULL) { + fprintf(stderr, "Error: %s is an unknown binary filename type.\n", fileName); + exit(U_ILLEGAL_ARGUMENT_ERROR); + } if(uprv_strcmp(ext, ".jpg")==0 || uprv_strcmp(ext, ".jpeg")==0 || uprv_strcmp(ext, ".gif")==0 ){ m_type = "\"image"; } else if(uprv_strcmp(ext, ".wav")==0 || uprv_strcmp(ext, ".au")==0 ){ @@ -1107,16 +991,16 @@ bin_write_xml( struct SResource *res, const char* id, const char* language, UErr write_tabs(out); T_FileStream_write(out,end,(int32_t)uprv_strlen(end)); - uprv_free(fn); uprv_free(sid); sid = NULL; } + uprv_free(fn); } static void -table_write_xml(struct SResource *res, const char* id, const char* language, UErrorCode *status) { +table_write_xml(struct SResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status) { uint32_t i = 0; @@ -1140,6 +1024,13 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr if(res->fKey<0 || uprv_strcmp(srBundle->fKeys+res->fKey ,"")==0){ T_FileStream_write(out, start, (int32_t)uprv_strlen(start)); + if(isTopLevel){ + int32_t len = uprv_strlen(id); + T_FileStream_write(out, idstr, (int32_t)uprv_strlen(idstr)); + T_FileStream_write(out, id,len); + T_FileStream_write(out, "\" ", 2); + id=""; + } sid = getID(id, NULL, sid); /* only write the id if the sid!="" */ if(sid[0]!='\0'){ @@ -1149,6 +1040,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr } + if(res->fComment!=NULL && res->fComment->fChars != NULL){ printComments(res->fComment, sid, FALSE, status); printNoteElements(res->fComment, status); @@ -1181,7 +1073,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr save = current = res->u.fTable.fFirst; i = 0; while (current != NULL) { - res_write_xml(current, sid, language, status); + res_write_xml(current, sid, language, FALSE, status); if(U_FAILURE(*status)){ return; @@ -1228,7 +1120,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UEr } void -res_write_xml(struct SResource *res, const char* id, const char* language, UErrorCode *status) { +res_write_xml(struct SResource *res, const char* id, const char* language, UBool isTopLevel, UErrorCode *status) { if (U_FAILURE(*status)) { return ; @@ -1256,7 +1148,7 @@ res_write_xml(struct SResource *res, const char* id, const char* language, UErro return; case URES_TABLE: case URES_TABLE32: - table_write_xml (res, id, language, status); + table_write_xml (res, id, language, isTopLevel, status); return; default: @@ -1276,7 +1168,7 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu char* outputFileName = NULL; char* originalFileName = NULL; const char* fileStart = "fRoot, srBundle->fLocale, lang, status); + res_write_xml(bundle->fRoot, bundle->fLocale, lang, TRUE, status); tabCount--; write_tabs(out); @@ -1450,6 +1342,7 @@ bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outpu ucnv_close(conv); +cleanup_bundle_write_xml: if(originalFileName!= NULL) { uprv_free(originalFileName); originalFileName = NULL;