2000-05-15 18:39:17 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2002-06-24 20:58:17 +00:00
|
|
|
* Copyright (C) 1997-2002, International Business Machines Corporation and *
|
2001-03-21 20:44:20 +00:00
|
|
|
* others. All Rights Reserved. *
|
|
|
|
******************************************************************************
|
2000-05-15 18:39:17 +00:00
|
|
|
*
|
2000-06-20 23:42:20 +00:00
|
|
|
* File URESBUND.C
|
2000-05-15 18:39:17 +00:00
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 04/01/97 aliu Creation.
|
|
|
|
* 06/14/99 stephen Removed functions taking a filename suffix.
|
|
|
|
* 07/20/99 stephen Changed for UResourceBundle typedef'd to void*
|
2000-06-07 19:52:08 +00:00
|
|
|
* 11/09/99 weiv Added ures_getLocale()
|
2000-05-15 18:39:17 +00:00
|
|
|
* March 2000 weiv Total overhaul - using data in DLLs
|
2000-06-20 23:42:20 +00:00
|
|
|
* 06/20/2000 helena OS/400 port changes; mostly typecast.
|
2002-06-24 20:58:17 +00:00
|
|
|
* 06/24/02 weiv Added support for resource sharing
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-05-15 18:39:17 +00:00
|
|
|
*/
|
|
|
|
|
2001-10-10 18:05:10 +00:00
|
|
|
#include "unicode/ustring.h"
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
#include "uresimp.h"
|
2001-05-25 17:57:14 +00:00
|
|
|
#include "cwchar.h"
|
2001-08-11 00:29:58 +00:00
|
|
|
#include "ucln_cmn.h"
|
2001-10-10 18:05:10 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "uhash.h"
|
|
|
|
#include "umutex.h"
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* this is just for internal purposes. DO NOT USE! */
|
|
|
|
static void entryCloseInt(UResourceDataEntry *resB);
|
|
|
|
|
|
|
|
|
2001-03-22 01:13:46 +00:00
|
|
|
/*
|
|
|
|
Static cache for already opened resource bundles - mostly for keeping fallback info
|
|
|
|
TODO: This cache should probably be removed when the deprecated code is
|
|
|
|
completely removed.
|
|
|
|
*/
|
2000-05-15 18:39:17 +00:00
|
|
|
static UHashtable *cache = NULL;
|
2001-03-22 01:13:46 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
static UMTX resbMutex = NULL;
|
|
|
|
|
|
|
|
/* INTERNAL: hashes an entry */
|
2001-11-21 01:02:11 +00:00
|
|
|
static int32_t U_EXPORT2 U_CALLCONV hashEntry(const UHashTok parm) {
|
2001-07-06 19:53:12 +00:00
|
|
|
UResourceDataEntry *b = (UResourceDataEntry *)parm.pointer;
|
2001-10-16 18:31:13 +00:00
|
|
|
UHashTok namekey, pathkey;
|
2001-07-06 19:53:12 +00:00
|
|
|
namekey.pointer = b->fName;
|
|
|
|
pathkey.pointer = b->fPath;
|
|
|
|
return uhash_hashChars(namekey)+37*uhash_hashChars(pathkey);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* INTERNAL: compares two entries */
|
2001-11-21 01:02:11 +00:00
|
|
|
static UBool U_EXPORT2 U_CALLCONV compareEntries(const UHashTok p1, const UHashTok p2) {
|
2001-07-06 19:53:12 +00:00
|
|
|
UResourceDataEntry *b1 = (UResourceDataEntry *)p1.pointer;
|
|
|
|
UResourceDataEntry *b2 = (UResourceDataEntry *)p2.pointer;
|
2001-10-16 18:31:13 +00:00
|
|
|
UHashTok name1, name2, path1, path2;
|
2001-07-06 19:53:12 +00:00
|
|
|
name1.pointer = b1->fName;
|
|
|
|
name2.pointer = b2->fName;
|
|
|
|
path1.pointer = b1->fPath;
|
|
|
|
path2.pointer = b2->fPath;
|
|
|
|
return (UBool)(uhash_compareChars(name1, name2) &
|
|
|
|
uhash_compareChars(path1, path2));
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal function, gets parts of locale name according
|
|
|
|
* to the position of '_' character
|
|
|
|
*/
|
2000-11-28 19:59:22 +00:00
|
|
|
static UBool chopLocale(char *name) {
|
2000-05-15 18:39:17 +00:00
|
|
|
char *i = uprv_strrchr(name, '_');
|
|
|
|
|
|
|
|
if(i != NULL) {
|
|
|
|
*i = '\0';
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
/**
|
|
|
|
* Internal function
|
|
|
|
*/
|
|
|
|
static void entryIncrease(UResourceDataEntry *entry) {
|
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
entry->fCountExisting++;
|
|
|
|
while(entry->fParent != NULL) {
|
|
|
|
entry = entry->fParent;
|
|
|
|
entry->fCountExisting++;
|
|
|
|
}
|
|
|
|
umtx_unlock(&resbMutex);
|
2000-05-24 19:58:40 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/**
|
|
|
|
* Internal function. Tries to find a resource in given Resource
|
|
|
|
* Bundle, as well as in its parents
|
|
|
|
*/
|
2001-10-04 00:12:19 +00:00
|
|
|
static const ResourceData *getFallbackData(const UResourceBundle* resBundle, const char* * resTag, UResourceDataEntry* *realData, Resource *res, UErrorCode *status) {
|
2000-05-24 19:58:40 +00:00
|
|
|
UResourceDataEntry *resB = resBundle->fData;
|
2000-05-30 17:02:26 +00:00
|
|
|
int32_t indexR = -1;
|
2000-05-15 18:39:17 +00:00
|
|
|
int32_t i = 0;
|
|
|
|
*res = RES_BOGUS;
|
|
|
|
if(resB != NULL) {
|
|
|
|
if(resB->fBogus == U_ZERO_ERROR) { /* if this resource is real, */
|
2000-05-30 17:02:26 +00:00
|
|
|
*res = res_getTableItemByKey(&(resB->fData), resB->fData.rootRes, &indexR, resTag); /* try to get data from there */
|
2000-05-15 18:39:17 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if(resBundle->fHasFallback == TRUE) {
|
|
|
|
while(*res == RES_BOGUS && resB->fParent != NULL) { /* Otherwise, we'll look in parents */
|
|
|
|
resB = resB->fParent;
|
|
|
|
if(resB->fBogus == U_ZERO_ERROR) {
|
|
|
|
i++;
|
2000-05-30 17:02:26 +00:00
|
|
|
*res = res_getTableItemByKey(&(resB->fData), resB->fData.rootRes, &indexR, resTag);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*res != RES_BOGUS) { /* If the resource is found in parents, we need to adjust the error */
|
|
|
|
if(i>1) {
|
|
|
|
if(uprv_strcmp(resB->fName, uloc_getDefault())==0 || uprv_strcmp(resB->fName, kRootLocaleName)==0) {
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_DEFAULT_WARNING;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-06-07 19:52:08 +00:00
|
|
|
*realData = resB;
|
2000-05-15 18:39:17 +00:00
|
|
|
return (&(resB->fData));
|
|
|
|
} else { /* If resource is not found, we need to give an error */
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** INTERNAL: Initializes the cache for resources */
|
2000-11-28 19:59:22 +00:00
|
|
|
static void initCache(UErrorCode *status) {
|
2000-05-15 18:39:17 +00:00
|
|
|
if(cache == NULL) {
|
|
|
|
UHashtable *newCache = uhash_open(hashEntry, compareEntries, status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
if(cache == NULL) {
|
|
|
|
cache = newCache;
|
|
|
|
newCache = NULL;
|
|
|
|
}
|
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
if(newCache != NULL) {
|
|
|
|
uhash_close(newCache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
/* Works just like ucnv_flushCache() */
|
2001-11-13 22:27:53 +00:00
|
|
|
/* TODO: figure out why fCountExisting may not go to zero. Do not make this function public yet. */
|
2001-08-11 00:29:58 +00:00
|
|
|
static int32_t ures_flushCache()
|
|
|
|
{
|
|
|
|
UResourceDataEntry *resB = NULL;
|
|
|
|
int32_t pos = -1;
|
|
|
|
int32_t rbDeletedNum = 0;
|
|
|
|
const UHashElement *e;
|
|
|
|
|
|
|
|
/*if shared data hasn't even been lazy evaluated yet
|
|
|
|
* return 0
|
|
|
|
*/
|
|
|
|
if (cache == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*creates an enumeration to iterate through every element in the table */
|
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
while ((e = uhash_nextElement(cache, &pos)) != NULL)
|
|
|
|
{
|
2001-10-16 18:31:13 +00:00
|
|
|
resB = (UResourceDataEntry *) e->value.pointer;
|
2001-08-11 00:29:58 +00:00
|
|
|
/* Deletes only if reference counter == 0
|
|
|
|
* Don't worry about the children of this node.
|
|
|
|
* Those will eventually get deleted too, if not already.
|
|
|
|
* Don't worry about the parents of this node.
|
|
|
|
* Those will eventually get deleted too, if not already.
|
|
|
|
*/
|
2002-04-17 21:19:38 +00:00
|
|
|
/* DONE: figure out why fCountExisting may not go to zero. Do not make this function public yet. */
|
|
|
|
/* 04/05/2002 [weiv] fCountExisting should now be accurate. If it's not zero, that means that */
|
|
|
|
/* some resource bundles are still open somewhere. */
|
|
|
|
|
|
|
|
if (resB->fCountExisting == 0) {
|
2001-08-11 00:29:58 +00:00
|
|
|
rbDeletedNum++;
|
|
|
|
uhash_removeElement(cache, e);
|
|
|
|
if(resB->fBogus == U_ZERO_ERROR) {
|
|
|
|
res_unload(&(resB->fData));
|
|
|
|
}
|
|
|
|
if(resB->fName != NULL) {
|
|
|
|
uprv_free(resB->fName);
|
|
|
|
}
|
|
|
|
if(resB->fPath != NULL) {
|
|
|
|
uprv_free(resB->fPath);
|
|
|
|
}
|
|
|
|
uprv_free(resB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
|
|
|
|
return rbDeletedNum;
|
|
|
|
}
|
|
|
|
|
2001-08-25 01:09:11 +00:00
|
|
|
UBool ures_cleanup(void)
|
2001-08-11 00:29:58 +00:00
|
|
|
{
|
|
|
|
if (cache != NULL) {
|
|
|
|
ures_flushCache();
|
|
|
|
if (cache != NULL && uhash_count(cache) == 0) {
|
|
|
|
uhash_close(cache);
|
|
|
|
cache = NULL;
|
|
|
|
umtx_destroy(&resbMutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (cache == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/** INTERNAL: sets the name (locale) of the resource bundle to given name */
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
static void setEntryName(UResourceDataEntry *res, char *name, UErrorCode *status) {
|
2000-05-15 18:39:17 +00:00
|
|
|
if(res->fName != NULL) {
|
|
|
|
uprv_free(res->fName);
|
|
|
|
}
|
|
|
|
res->fName = (char *)uprv_malloc(sizeof(char)*uprv_strlen(name)+1);
|
|
|
|
if(res->fName == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(res->fName, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* INTERNAL: Inits and opens an entry from a data DLL.
|
|
|
|
*/
|
2000-11-28 19:59:22 +00:00
|
|
|
static UResourceDataEntry *init_entry(const char *localeID, const char *path, UErrorCode *status) {
|
2000-05-15 18:39:17 +00:00
|
|
|
UResourceDataEntry *r = NULL;
|
|
|
|
UResourceDataEntry find;
|
|
|
|
int32_t hashValue;
|
|
|
|
char name[96];
|
|
|
|
const char *myPath = NULL;
|
2001-04-17 19:09:23 +00:00
|
|
|
char aliasName[100] = { 0 };
|
|
|
|
int32_t aliasLen = 0;
|
|
|
|
UBool isAlias = FALSE;
|
2001-10-16 18:31:13 +00:00
|
|
|
UHashTok hashkey;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* here we try to deduce the right locale name */
|
|
|
|
if(localeID == NULL) { /* if localeID is NULL, we're trying to open default locale */
|
|
|
|
uprv_strcpy(name, uloc_getDefault());
|
|
|
|
} else if(uprv_strlen(localeID) == 0) { /* if localeID is "" then we try to open root locale */
|
|
|
|
uprv_strcpy(name, kRootLocaleName);
|
|
|
|
} else { /* otherwise, we'll open what we're given */
|
|
|
|
uprv_strcpy(name, localeID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(path != NULL) { /* if we actually have path, we'll use it */
|
|
|
|
if(uprv_strcmp(path, u_getDataDirectory()) != 0) { /* unless it is system default path */
|
|
|
|
myPath = path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
find.fName = name;
|
|
|
|
find.fPath = (char *)myPath;
|
|
|
|
|
|
|
|
/* calculate the hash value of the entry */
|
2001-07-06 19:53:12 +00:00
|
|
|
hashkey.pointer = (void *)&find;
|
|
|
|
hashValue = hashEntry(hashkey);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* check to see if we already have this entry */
|
|
|
|
r = (UResourceDataEntry *)uhash_get(cache, &find);
|
|
|
|
|
|
|
|
if(r != NULL) { /* if the entry is already in the hash table */
|
|
|
|
r->fCountExisting++; /* we just increase it's reference count */
|
2002-12-11 01:39:59 +00:00
|
|
|
/* if the resource has a warning */
|
|
|
|
/* we don't want to overwrite a status with no error */
|
|
|
|
if(r->fBogus != U_ZERO_ERROR) {
|
|
|
|
*status = r->fBogus; /* set the returning status */
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else { /* otherwise, we'll try to construct a new entry */
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool result = FALSE;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
r = (UResourceDataEntry *) uprv_malloc(sizeof(UResourceDataEntry));
|
|
|
|
|
|
|
|
if(r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
r->fCountExisting = 1;
|
|
|
|
|
|
|
|
r->fName = NULL;
|
|
|
|
setEntryName(r, name, status);
|
|
|
|
|
|
|
|
r->fPath = NULL;
|
|
|
|
if(myPath != NULL && !U_FAILURE(*status)) {
|
|
|
|
r->fPath = (char *)uprv_malloc(sizeof(char)*uprv_strlen(myPath)+1);
|
|
|
|
if(r->fPath == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(r->fPath, myPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r->fHashKey = hashValue;
|
|
|
|
r->fParent = NULL;
|
|
|
|
r->fData.data = NULL;
|
|
|
|
r->fData.pRoot = NULL;
|
|
|
|
r->fData.rootRes = 0;
|
|
|
|
r->fBogus = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
/* this is the acutal loading - returns bool true/false */
|
|
|
|
result = res_load(&(r->fData), r->fPath, r->fName, status);
|
|
|
|
|
|
|
|
if (result == FALSE || U_FAILURE(*status)) {
|
|
|
|
/* we have no such entry in dll, so it will always use fallback */
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
|
|
|
r->fBogus = U_USING_FALLBACK_WARNING;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else { /* if we have a regular entry */
|
2001-07-06 04:36:08 +00:00
|
|
|
/* We might be able to do this a wee bit more efficiently (we could check whether the aliased data) */
|
|
|
|
/* is already in the cache), but it's good the way it is */
|
2000-05-15 18:39:17 +00:00
|
|
|
/* handle the alias by trying to get out the %%Alias tag.*/
|
2000-06-07 19:52:08 +00:00
|
|
|
/* We'll try to get alias string from the bundle */
|
2000-05-15 18:39:17 +00:00
|
|
|
Resource aliasres = res_getResource(&(r->fData), "%%ALIAS");
|
|
|
|
const UChar *alias = res_getString(&(r->fData), aliasres, &aliasLen);
|
|
|
|
if(alias != NULL && aliasLen > 0) { /* if there is actual alias - unload and load new data */
|
2002-07-16 18:22:36 +00:00
|
|
|
u_UCharsToChars(alias, aliasName, aliasLen+1);
|
2001-04-17 19:09:23 +00:00
|
|
|
isAlias = TRUE;
|
2000-05-15 18:39:17 +00:00
|
|
|
res_unload(&(r->fData));
|
2000-10-02 19:58:36 +00:00
|
|
|
result = res_load(&(r->fData), r->fPath, aliasName, status);
|
|
|
|
if (result == FALSE || U_FAILURE(*status)) {
|
|
|
|
/* we couldn't load aliased data - so we have no data */
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
|
|
|
r->fBogus = U_USING_FALLBACK_WARNING;
|
2000-10-02 19:58:36 +00:00
|
|
|
}
|
2001-07-06 04:36:08 +00:00
|
|
|
setEntryName(r, aliasName, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
UResourceDataEntry *oldR = NULL;
|
|
|
|
if((oldR = (UResourceDataEntry *)uhash_get(cache, r)) == NULL) { /* if the data is not cached */
|
2000-06-07 19:52:08 +00:00
|
|
|
/* just insert it in the cache */
|
2000-05-15 18:39:17 +00:00
|
|
|
uhash_put(cache, (void *)r, r, status);
|
|
|
|
} else {
|
2000-06-07 19:52:08 +00:00
|
|
|
/* somebody have already inserted it while we were working, discard newly opened data */
|
2001-07-27 17:15:30 +00:00
|
|
|
/* Also, we could get here IF we opened an alias */
|
2000-05-15 18:39:17 +00:00
|
|
|
uprv_free(r->fName);
|
|
|
|
if(r->fPath != NULL) {
|
|
|
|
uprv_free(r->fPath);
|
|
|
|
}
|
2001-08-31 02:10:39 +00:00
|
|
|
res_unload(&(r->fData));
|
2000-05-15 18:39:17 +00:00
|
|
|
uprv_free(r);
|
|
|
|
r = oldR;
|
|
|
|
r->fCountExisting++;
|
|
|
|
}
|
|
|
|
}
|
2001-04-17 19:09:23 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
/* INTERNAL: */
|
2001-10-11 18:46:18 +00:00
|
|
|
static UResourceDataEntry *findFirstExisting(const char* path, char* name, UBool *isRoot, UBool *hasChopped, UBool *isDefault, UErrorCode* status) {
|
|
|
|
UResourceDataEntry *r = NULL;
|
|
|
|
UBool hasRealData = FALSE;
|
|
|
|
const char *defaultLoc = uloc_getDefault();
|
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
|
|
|
*hasChopped = TRUE; /* we're starting with a fresh name */
|
|
|
|
|
|
|
|
while(*hasChopped && !hasRealData) {
|
|
|
|
r = init_entry(name, path, &intStatus);
|
|
|
|
*isDefault = (UBool)(uprv_strncmp(name, defaultLoc, uprv_strlen(name)) == 0);
|
|
|
|
hasRealData = (UBool)(r->fBogus == U_ZERO_ERROR);
|
|
|
|
if(!hasRealData) {
|
2002-04-17 21:19:38 +00:00
|
|
|
/* this entry is not real. We will discard it. */
|
|
|
|
/* However, the parent line for this entry is */
|
|
|
|
/* not to be used - as there might be parent */
|
|
|
|
/* lines in cache from previous openings that */
|
|
|
|
/* are not updated yet. */
|
|
|
|
r->fCountExisting--;
|
|
|
|
/*entryCloseInt(r);*/
|
2001-10-11 18:46:18 +00:00
|
|
|
r = NULL;
|
2002-08-21 19:12:24 +00:00
|
|
|
*status = U_USING_FALLBACK_WARNING;
|
2001-10-11 18:46:18 +00:00
|
|
|
} else {
|
|
|
|
uprv_strcpy(name, r->fName); /* this is needed for supporting aliases */
|
|
|
|
}
|
|
|
|
|
|
|
|
*isRoot = (UBool)(uprv_strcmp(name, kRootLocaleName) == 0);
|
|
|
|
|
|
|
|
/*Fallback data stuff*/
|
|
|
|
*hasChopped = chopLocale(name);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2000-11-28 19:59:22 +00:00
|
|
|
static UResourceDataEntry *entryOpen(const char* path, const char* localeID, UErrorCode* status) {
|
2001-10-11 18:46:18 +00:00
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
2002-12-11 22:35:01 +00:00
|
|
|
UErrorCode parentStatus = U_ZERO_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
UResourceDataEntry *r = NULL;
|
|
|
|
UResourceDataEntry *t1 = NULL;
|
|
|
|
UResourceDataEntry *t2 = NULL;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool isDefault = FALSE;
|
2000-08-10 01:59:18 +00:00
|
|
|
UBool isRoot = FALSE;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool hasRealData = FALSE;
|
2001-10-11 18:46:18 +00:00
|
|
|
UBool hasChopped = TRUE;
|
2000-05-15 18:39:17 +00:00
|
|
|
char name[96];
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
initCache(status);
|
|
|
|
|
2001-10-11 18:46:18 +00:00
|
|
|
uprv_strcpy(name, localeID);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-10-11 18:46:18 +00:00
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
{ /* umtx_lock */
|
|
|
|
/* We're going to skip all the locales that do not have any data */
|
|
|
|
r = findFirstExisting(path, name, &isRoot, &hasChopped, &isDefault, &intStatus);
|
|
|
|
|
|
|
|
if(r != NULL) { /* if there is one real locale, we can look for parents. */
|
|
|
|
t1 = r;
|
|
|
|
hasRealData = TRUE;
|
|
|
|
while (hasChopped && !isRoot && t1->fParent == NULL) {
|
|
|
|
/* insert regular parents */
|
2002-12-11 22:35:01 +00:00
|
|
|
t2 = init_entry(name, r->fPath, &parentStatus);
|
2000-05-15 18:39:17 +00:00
|
|
|
t1->fParent = t2;
|
|
|
|
t1 = t2;
|
|
|
|
hasChopped = chopLocale(name);
|
|
|
|
}
|
2001-10-11 18:46:18 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-10-11 18:46:18 +00:00
|
|
|
/* we could have reached this point without having any real data */
|
|
|
|
/* if that is the case, we need to chain in the default locale */
|
|
|
|
if(r==NULL && !isDefault && !isRoot /*&& t1->fParent == NULL*/) {
|
|
|
|
/* insert default locale */
|
|
|
|
uprv_strcpy(name, uloc_getDefault());
|
|
|
|
r = findFirstExisting(path, name, &isRoot, &hasChopped, &isDefault, &intStatus);
|
2002-08-21 19:12:24 +00:00
|
|
|
intStatus = U_USING_DEFAULT_WARNING;
|
2001-10-11 18:46:18 +00:00
|
|
|
if(r != NULL) { /* the default locale exists */
|
|
|
|
t1 = r;
|
|
|
|
hasRealData = TRUE;
|
|
|
|
isDefault = TRUE;
|
|
|
|
while (hasChopped && t1->fParent == NULL) {
|
|
|
|
/* insert chopped defaults */
|
2002-12-11 22:35:01 +00:00
|
|
|
t2 = init_entry(name, r->fPath, &parentStatus);
|
2001-10-11 18:46:18 +00:00
|
|
|
t1->fParent = t2;
|
|
|
|
t1 = t2;
|
|
|
|
hasChopped = chopLocale(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-10-11 18:46:18 +00:00
|
|
|
/* we could still have r == NULL at this point - maybe even default locale is not */
|
|
|
|
/* present */
|
|
|
|
if(r == NULL) {
|
|
|
|
uprv_strcpy(name, kRootLocaleName);
|
|
|
|
r = findFirstExisting(path, name, &isRoot, &hasChopped, &isDefault, &intStatus);
|
|
|
|
if(r != NULL) {
|
|
|
|
t1 = r;
|
2002-08-21 19:12:24 +00:00
|
|
|
intStatus = U_USING_DEFAULT_WARNING;
|
2001-10-11 18:46:18 +00:00
|
|
|
hasRealData = TRUE;
|
|
|
|
} else { /* we don't even have the root locale */
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
} else if(!isRoot && uprv_strcmp(t1->fName, kRootLocaleName) != 0 && t1->fParent == NULL) {
|
|
|
|
/* insert root locale */
|
2002-12-11 22:35:01 +00:00
|
|
|
t2 = init_entry(kRootLocaleName, r->fPath, &parentStatus);
|
2001-10-11 18:46:18 +00:00
|
|
|
if(!hasRealData) {
|
2002-08-21 19:12:24 +00:00
|
|
|
r->fBogus = U_USING_DEFAULT_WARNING;
|
2001-10-11 18:46:18 +00:00
|
|
|
}
|
|
|
|
hasRealData = (UBool)((t2->fBogus == U_ZERO_ERROR) | hasRealData);
|
|
|
|
t1->fParent = t2;
|
|
|
|
t1 = t2;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-10-11 18:46:18 +00:00
|
|
|
while(r != NULL && !isRoot && t1->fParent != NULL) {
|
|
|
|
t1->fParent->fCountExisting++;
|
|
|
|
t1 = t1->fParent;
|
|
|
|
hasRealData = (UBool)((t1->fBogus == U_ZERO_ERROR) | hasRealData);
|
|
|
|
}
|
|
|
|
} /* umtx_lock */
|
2000-05-15 18:39:17 +00:00
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)) {
|
2002-12-11 22:35:01 +00:00
|
|
|
if(U_SUCCESS(parentStatus)) {
|
|
|
|
if(intStatus != U_ZERO_ERROR) {
|
|
|
|
*status = intStatus;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
*status = parentStatus;
|
|
|
|
return NULL;
|
2002-12-11 01:39:59 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to create and destroy resource bundles.
|
|
|
|
*/
|
2002-04-17 21:19:38 +00:00
|
|
|
static void entryClose(UResourceDataEntry *resB);
|
2000-11-28 19:59:22 +00:00
|
|
|
/* INTERNAL: */
|
2002-06-14 06:35:09 +00:00
|
|
|
static UResourceBundle *init_resb_result(const ResourceData *rdata, Resource r,
|
2002-06-24 20:58:17 +00:00
|
|
|
const char *key, int32_t index, UResourceDataEntry *realData,
|
|
|
|
const UResourceBundle *parent, int32_t noAlias,
|
|
|
|
UResourceBundle *resB, UErrorCode *status)
|
|
|
|
{
|
2000-07-12 22:59:57 +00:00
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return resB;
|
|
|
|
}
|
2002-06-14 06:03:08 +00:00
|
|
|
if(RES_GET_TYPE(r) == RES_ALIAS) { /* This is an alias, need to exchange with real data */
|
2002-06-24 20:58:17 +00:00
|
|
|
if(noAlias < URES_MAX_ALIAS_LEVEL) {
|
|
|
|
int32_t len = 0;
|
|
|
|
const UChar *alias = res_getAlias(rdata, r, &len);
|
|
|
|
if(len > 0) {
|
|
|
|
/* we have an alias, now let's cut it up */
|
|
|
|
char *chAlias = NULL, *path = NULL, *locale = NULL, *keyPath = NULL;
|
|
|
|
chAlias = (char *)uprv_malloc((len+1)*sizeof(char));
|
2002-07-01 18:04:55 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if(chAlias == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2002-07-03 11:59:21 +00:00
|
|
|
return NULL;
|
2002-07-02 15:10:30 +00:00
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
u_UCharsToChars(alias, chAlias, len);
|
|
|
|
chAlias[len] = 0;
|
|
|
|
|
|
|
|
if(*chAlias == RES_PATH_SEPARATOR) {
|
|
|
|
/* there is a path included */
|
|
|
|
locale = uprv_strchr(chAlias+1, RES_PATH_SEPARATOR);
|
|
|
|
*locale = 0;
|
|
|
|
locale++;
|
|
|
|
path = chAlias+1;
|
|
|
|
if(uprv_strcmp(path, "ICUDATA") == 0) { /* want ICU data */
|
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* no path, start with a locale */
|
|
|
|
locale = chAlias;
|
|
|
|
path = realData->fPath;
|
|
|
|
}
|
|
|
|
keyPath = uprv_strchr(locale, RES_PATH_SEPARATOR);
|
|
|
|
if(keyPath) {
|
|
|
|
*keyPath = 0;
|
|
|
|
keyPath++;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
/* got almost everything, let's try to open */
|
|
|
|
/* first, open the bundle with real data */
|
2002-09-18 06:04:31 +00:00
|
|
|
UResourceBundle *result = resB;
|
2002-07-30 20:49:30 +00:00
|
|
|
const char* temp = NULL;
|
2002-12-11 01:39:59 +00:00
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
|
|
|
UResourceBundle *mainRes = ures_openDirect(path, locale, &intStatus);
|
|
|
|
if(U_SUCCESS(intStatus)) {
|
2002-09-18 06:04:31 +00:00
|
|
|
if(keyPath == NULL) {
|
|
|
|
/* no key path. This means that we are going to
|
|
|
|
* to use the corresponding resource from
|
|
|
|
* another bundle
|
|
|
|
*/
|
|
|
|
/* first, we are going to get a corresponding parent
|
|
|
|
* resource to the one we are searching.
|
|
|
|
*/
|
|
|
|
const char* aKey = parent->fResPath;
|
|
|
|
if(aKey) {
|
|
|
|
r = res_findResource(&(mainRes->fResData), mainRes->fRes, &aKey, &temp);
|
|
|
|
} else {
|
|
|
|
r = mainRes->fRes;
|
2002-06-24 20:58:17 +00:00
|
|
|
}
|
2002-09-18 06:04:31 +00:00
|
|
|
if(key) {
|
|
|
|
/* we need to make keyPath from parents fResPath and
|
|
|
|
* current key, if there is a key associated
|
|
|
|
*/
|
|
|
|
aKey = key;
|
|
|
|
r = res_findResource(&(mainRes->fResData), r, &aKey, &temp);
|
|
|
|
} else if(index != -1) {
|
|
|
|
/* if there is no key, but there is an index, try to get by the index */
|
|
|
|
/* here we have either a table or an array, so get the element */
|
|
|
|
if(RES_GET_TYPE(r) == RES_TABLE) {
|
|
|
|
r = res_getTableItemByIndex(&(mainRes->fResData), r, index, &aKey);
|
|
|
|
} else { /* array */
|
|
|
|
r = res_getArrayItem(&(mainRes->fResData), r, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(r != RES_BOGUS) {
|
|
|
|
result = init_resb_result(&(mainRes->fResData), r, key, -1, mainRes->fData, parent, noAlias+1, resB, status);
|
|
|
|
} else {
|
2002-06-24 20:58:17 +00:00
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
result = resB;
|
|
|
|
}
|
2002-09-18 06:04:31 +00:00
|
|
|
} else {
|
|
|
|
/* this one is a bit trickier.
|
|
|
|
* we start finding keys, but after we resolve one alias, the path might continue.
|
|
|
|
* Consider:
|
|
|
|
* aliastest:alias { "testtypes/anotheralias/Sequence" }
|
|
|
|
* anotheralias:alias { "/ICUDATA/sh/CollationElements" }
|
|
|
|
* aliastest resource should finally have the sequence, not collation elements.
|
|
|
|
*/
|
|
|
|
result = mainRes;
|
|
|
|
while(*keyPath && U_SUCCESS(*status)) {
|
|
|
|
r = res_findResource(&(result->fResData), result->fRes, (const char**)&keyPath, &temp);
|
|
|
|
if(r == RES_BOGUS) {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
result = resB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
resB = init_resb_result(&(result->fResData), r, key, -1, result->fData, parent, noAlias+1, resB, status);
|
|
|
|
result = resB;
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
}
|
2002-12-11 01:39:59 +00:00
|
|
|
} else { /* we failed to open the resource we're aliasing to */
|
|
|
|
*status = intStatus;
|
2002-09-18 06:04:31 +00:00
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
uprv_free(chAlias);
|
2002-07-16 18:22:36 +00:00
|
|
|
ures_close(mainRes);
|
2002-06-24 20:58:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
2002-06-14 06:03:08 +00:00
|
|
|
} else {
|
2002-06-24 20:58:17 +00:00
|
|
|
/* bad alias, should be an error */
|
2002-06-14 06:03:08 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
2002-06-24 20:58:17 +00:00
|
|
|
return resB;
|
2002-06-14 06:03:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-06-24 20:58:17 +00:00
|
|
|
*status = U_TOO_MANY_ALIASES_ERROR;
|
2002-06-14 06:03:08 +00:00
|
|
|
return resB;
|
|
|
|
}
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
if(resB == NULL) {
|
2000-06-20 23:42:20 +00:00
|
|
|
resB = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2002-07-01 18:04:55 +00:00
|
|
|
/* test for NULL */
|
2002-07-03 11:59:21 +00:00
|
|
|
if (resB == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-07-12 22:59:57 +00:00
|
|
|
ures_setIsStackObject(resB, FALSE);
|
2002-06-24 20:58:17 +00:00
|
|
|
resB->fResPath = NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-04-17 21:19:38 +00:00
|
|
|
if(resB->fData != NULL) {
|
|
|
|
entryClose(resB->fData);
|
|
|
|
}
|
|
|
|
if(resB->fVersion != NULL) {
|
|
|
|
uprv_free(resB->fVersion);
|
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
if(ures_isStackObject(resB) != FALSE) {
|
2002-04-17 21:19:38 +00:00
|
|
|
ures_initStackObject(resB);
|
2000-07-06 23:01:50 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2000-05-24 19:58:40 +00:00
|
|
|
resB->fData = realData;
|
|
|
|
entryIncrease(resB->fData);
|
2000-05-15 18:39:17 +00:00
|
|
|
resB->fHasFallback = FALSE;
|
|
|
|
resB->fIsTopLevel = FALSE;
|
|
|
|
resB->fIndex = -1;
|
|
|
|
resB->fKey = key;
|
2002-06-24 20:58:17 +00:00
|
|
|
ures_freeResPath(resB);
|
|
|
|
if(parent->fResPath) {
|
|
|
|
ures_appendResPath(resB, parent->fResPath);
|
|
|
|
}
|
|
|
|
if(key != NULL) {
|
|
|
|
ures_appendResPath(resB, key);
|
|
|
|
ures_appendResPath(resB, RES_PATH_SEPARATOR_S);
|
|
|
|
} else {
|
|
|
|
char buf[256];
|
|
|
|
T_CString_integerToString(buf, index, 10);
|
|
|
|
ures_appendResPath(resB, buf);
|
|
|
|
ures_appendResPath(resB, RES_PATH_SEPARATOR_S);
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
resB->fVersion = NULL;
|
|
|
|
resB->fRes = r;
|
2002-06-24 20:58:17 +00:00
|
|
|
/*resB->fParent = parent->fRes;*/
|
2000-05-15 18:39:17 +00:00
|
|
|
resB->fResData.data = rdata->data;
|
|
|
|
resB->fResData.pRoot = rdata->pRoot;
|
|
|
|
resB->fResData.rootRes = rdata->rootRes;
|
|
|
|
resB->fSize = res_countArrayItems(&(resB->fResData), resB->fRes);
|
|
|
|
return resB;
|
|
|
|
}
|
|
|
|
|
2001-10-04 00:12:19 +00:00
|
|
|
UResourceBundle *ures_copyResb(UResourceBundle *r, const UResourceBundle *original, UErrorCode *status) {
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool isStackObject;
|
2000-07-10 20:43:34 +00:00
|
|
|
if(U_FAILURE(*status) || r == original) {
|
2000-05-15 18:39:17 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
if(original != NULL) {
|
|
|
|
if(r == NULL) {
|
|
|
|
isStackObject = FALSE;
|
2000-06-20 23:42:20 +00:00
|
|
|
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2002-07-01 18:04:55 +00:00
|
|
|
/* test for NULL */
|
2002-07-03 11:59:21 +00:00
|
|
|
if (r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2001-07-27 17:15:30 +00:00
|
|
|
isStackObject = ures_isStackObject(r);
|
2000-07-12 22:59:57 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return r;
|
|
|
|
}
|
2002-04-17 21:19:38 +00:00
|
|
|
ures_close(r);
|
2000-07-12 22:59:57 +00:00
|
|
|
if(isStackObject == FALSE) {
|
|
|
|
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2002-07-01 18:04:55 +00:00
|
|
|
/* test for NULL */
|
2002-07-03 11:59:21 +00:00
|
|
|
if (r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-07-12 22:59:57 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
uprv_memcpy(r, original, sizeof(UResourceBundle));
|
2002-06-24 20:58:17 +00:00
|
|
|
r->fResPath = NULL;
|
|
|
|
if(original->fResPath) {
|
|
|
|
ures_appendResPath(r, original->fResPath);
|
|
|
|
}
|
2000-07-12 22:59:57 +00:00
|
|
|
ures_setIsStackObject(r, isStackObject);
|
2000-05-15 18:39:17 +00:00
|
|
|
if(r->fData != NULL) {
|
2000-06-07 19:52:08 +00:00
|
|
|
entryIncrease(r->fData);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
} else {
|
2000-07-10 20:43:34 +00:00
|
|
|
return r;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions to retrieve data from resource bundles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getString(const UResourceBundle* resB, int32_t* len, UErrorCode* status) {
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
|
|
|
case RES_STRING:
|
|
|
|
return res_getString(&(resB->fResData), resB->fRes, len);
|
|
|
|
case RES_INT:
|
|
|
|
case RES_INT_VECTOR:
|
|
|
|
case RES_BINARY:
|
|
|
|
case RES_ARRAY:
|
|
|
|
case RES_TABLE:
|
|
|
|
default:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-06-20 23:42:20 +00:00
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
U_CAPI const uint8_t* U_EXPORT2 ures_getBinary(const UResourceBundle* resB, int32_t* len,
|
2000-06-07 19:52:08 +00:00
|
|
|
UErrorCode* status) {
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
|
|
|
case RES_BINARY:
|
2001-09-05 18:44:27 +00:00
|
|
|
return res_getBinary(&(resB->fResData), resB->fRes, len);
|
2000-06-07 19:52:08 +00:00
|
|
|
case RES_INT:
|
|
|
|
case RES_STRING:
|
|
|
|
case RES_INT_VECTOR:
|
|
|
|
case RES_ARRAY:
|
|
|
|
case RES_TABLE:
|
|
|
|
default:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-05-18 21:25:51 +00:00
|
|
|
|
2000-06-20 23:42:20 +00:00
|
|
|
return NULL;
|
2000-05-18 21:25:51 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 17:08:07 +00:00
|
|
|
U_CAPI const int32_t* U_EXPORT2 ures_getIntVector(const UResourceBundle* resB, int32_t* len,
|
|
|
|
UErrorCode* status) {
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
|
|
|
case RES_INT_VECTOR:
|
2001-09-05 18:44:27 +00:00
|
|
|
return res_getIntVector(&(resB->fResData), resB->fRes, len);
|
2001-08-01 17:08:07 +00:00
|
|
|
case RES_INT:
|
|
|
|
case RES_STRING:
|
|
|
|
case RES_ARRAY:
|
|
|
|
case RES_BINARY:
|
|
|
|
case RES_TABLE:
|
|
|
|
default:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-17 23:05:08 +00:00
|
|
|
/* this function returns a signed integer */
|
|
|
|
/* it performs sign extension */
|
|
|
|
U_CAPI int32_t U_EXPORT2 ures_getInt(const UResourceBundle* resB, UErrorCode *status) {
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
2001-09-21 00:02:24 +00:00
|
|
|
if(RES_GET_TYPE(resB->fRes) != RES_INT) {
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
return RES_GET_INT(resB->fRes);
|
2001-09-17 23:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI uint32_t U_EXPORT2 ures_getUInt(const UResourceBundle* resB, UErrorCode *status) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
2001-09-21 00:02:24 +00:00
|
|
|
if(RES_GET_TYPE(resB->fRes) != RES_INT) {
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
2000-06-07 19:52:08 +00:00
|
|
|
return RES_GET_UINT(resB->fRes);
|
2000-05-18 21:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CAPI UResType U_EXPORT2 ures_getType(UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
2000-08-16 20:45:23 +00:00
|
|
|
return RES_NONE;
|
2000-06-07 19:52:08 +00:00
|
|
|
}
|
2000-06-20 23:42:20 +00:00
|
|
|
return (UResType) (RES_GET_TYPE(resB->fRes));
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const char * U_EXPORT2 ures_getKey(UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(resB->fKey);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 21:13:33 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2 ures_getSize(UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resB->fSize;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 21:13:33 +00:00
|
|
|
U_CAPI void U_EXPORT2 ures_resetIterator(UResourceBundle *resB){
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resB->fIndex = -1;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CAPI UBool U_EXPORT2 ures_hasNext(UResourceBundle *resB) {
|
2000-06-07 19:52:08 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-08-10 01:59:18 +00:00
|
|
|
return (UBool)(resB->fIndex < resB->fSize-1);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getNextString(UResourceBundle *resB, int32_t* len, const char ** key, UErrorCode *status) {
|
2000-06-07 19:52:08 +00:00
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(resB->fIndex == resB->fSize-1) {
|
|
|
|
*status = U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
} else {
|
|
|
|
resB->fIndex++;
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
|
|
|
case RES_INT:
|
|
|
|
case RES_BINARY:
|
|
|
|
case RES_STRING:
|
|
|
|
return res_getString(&(resB->fResData), resB->fRes, len);
|
|
|
|
case RES_TABLE:
|
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, resB->fIndex, key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
|
|
|
return res_getString(&(resB->fResData), r, len);
|
2000-08-24 21:20:10 +00:00
|
|
|
case RES_ARRAY:
|
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, resB->fIndex);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
|
|
|
return res_getString(&(resB->fResData), r, len);
|
2000-06-07 19:52:08 +00:00
|
|
|
case RES_INT_VECTOR:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
break;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2000-06-07 19:52:08 +00:00
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
|
2000-06-20 23:42:20 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2 ures_getNextResource(UResourceBundle *resB, UResourceBundle *fillIn, UErrorCode *status) {
|
|
|
|
const char *key = NULL;
|
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(resB->fIndex == resB->fSize-1) {
|
|
|
|
*status = U_INDEX_OUTOFBOUNDS_ERROR;
|
2000-08-24 21:20:10 +00:00
|
|
|
/*return NULL;*/
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
resB->fIndex++;
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
|
|
|
case RES_INT:
|
|
|
|
case RES_BINARY:
|
|
|
|
case RES_STRING:
|
2001-10-04 00:12:19 +00:00
|
|
|
return ures_copyResb(fillIn, resB, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
case RES_TABLE:
|
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, resB->fIndex, &key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, resB->fIndex, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
case RES_ARRAY:
|
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, resB->fIndex);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, resB->fIndex, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
case RES_INT_VECTOR:
|
|
|
|
default:
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2 ures_getByIndex(const UResourceBundle *resB, int32_t indexR, UResourceBundle *fillIn, UErrorCode *status) {
|
|
|
|
const char* key = NULL;
|
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(indexR >= 0 && resB->fSize > indexR) {
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
|
|
|
case RES_INT:
|
|
|
|
case RES_BINARY:
|
|
|
|
case RES_STRING:
|
2001-10-04 00:12:19 +00:00
|
|
|
return ures_copyResb(fillIn, resB, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
case RES_TABLE:
|
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, indexR, &key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, indexR, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
case RES_ARRAY:
|
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, indexR);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), r, key, indexR, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
case RES_INT_VECTOR:
|
|
|
|
default:
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
/*return NULL;*/
|
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getStringByIndex(const UResourceBundle *resB, int32_t indexS, int32_t* len, UErrorCode *status) {
|
|
|
|
const char* key = NULL;
|
|
|
|
Resource r = RES_BOGUS;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(indexS >= 0 && resB->fSize > indexS) {
|
|
|
|
switch(RES_GET_TYPE(resB->fRes)) {
|
|
|
|
case RES_INT:
|
|
|
|
case RES_BINARY:
|
|
|
|
case RES_STRING:
|
|
|
|
return res_getString(&(resB->fResData), resB->fRes, len);
|
|
|
|
case RES_TABLE:
|
|
|
|
r = res_getTableItemByIndex(&(resB->fResData), resB->fRes, indexS, &key);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
|
|
|
return res_getString(&(resB->fResData), r, len);
|
|
|
|
case RES_ARRAY:
|
|
|
|
r = res_getArrayItem(&(resB->fResData), resB->fRes, indexS);
|
|
|
|
if(r == RES_BOGUS && resB->fHasFallback) {
|
|
|
|
/* TODO: do the fallback */
|
|
|
|
}
|
|
|
|
return res_getString(&(resB->fResData), r, len);
|
2001-07-27 17:15:30 +00:00
|
|
|
/*case RES_INT_VECTOR:*/
|
|
|
|
/*default:*/
|
|
|
|
/*return;*/
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2002-07-16 18:22:36 +00:00
|
|
|
/*U_CAPI const char *ures_getResPath(UResourceBundle *resB) {
|
2002-06-24 20:58:17 +00:00
|
|
|
return resB->fResPath;
|
2002-07-16 18:22:36 +00:00
|
|
|
}*/
|
2002-06-24 20:58:17 +00:00
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_findResource(const char* path, UResourceBundle *fillIn, UErrorCode *status)
|
|
|
|
{
|
|
|
|
UResourceBundle *first = NULL;
|
|
|
|
UResourceBundle *result = fillIn;
|
|
|
|
char *packageName = NULL;
|
|
|
|
char *pathToResource = NULL;
|
|
|
|
char *locale = NULL, *localeEnd = NULL;
|
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
pathToResource = (char *)uprv_malloc((uprv_strlen(path)+1)*sizeof(char));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if(pathToResource == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return result;
|
2002-07-02 15:10:30 +00:00
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
uprv_strcpy(pathToResource, path);
|
|
|
|
locale = pathToResource;
|
|
|
|
if(*pathToResource == RES_PATH_SEPARATOR) { /* there is a path specification */
|
|
|
|
pathToResource++;
|
|
|
|
packageName = pathToResource;
|
|
|
|
pathToResource = uprv_strchr(pathToResource, RES_PATH_SEPARATOR);
|
|
|
|
if(pathToResource == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
} else {
|
|
|
|
*pathToResource = 0;
|
|
|
|
locale = pathToResource+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
localeEnd = strchr(locale, RES_PATH_SEPARATOR);
|
|
|
|
if(localeEnd != NULL) {
|
|
|
|
*localeEnd = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = ures_open(packageName, locale, status);
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
if(localeEnd) {
|
|
|
|
result = ures_findSubResource(first, localeEnd+1, fillIn, status);
|
|
|
|
} else {
|
|
|
|
result = ures_copyResb(fillIn, first, status);
|
|
|
|
}
|
|
|
|
ures_close(first);
|
|
|
|
}
|
|
|
|
uprv_free(pathToResource);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_findSubResource(const UResourceBundle *resB, const char* path, UResourceBundle *fillIn, UErrorCode *status)
|
|
|
|
{
|
|
|
|
Resource res = RES_BOGUS;
|
|
|
|
UResourceBundle *result = fillIn;
|
|
|
|
const char *pathToResource = path;
|
2002-07-30 20:49:30 +00:00
|
|
|
const char *key;
|
2002-06-24 20:58:17 +00:00
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* here we do looping and circular alias checking */
|
|
|
|
|
2002-07-30 20:49:30 +00:00
|
|
|
res = res_findResource(&(resB->fResData), resB->fRes, &pathToResource, &key);
|
2002-06-24 20:58:17 +00:00
|
|
|
|
|
|
|
if(res != RES_BOGUS) {
|
2002-07-30 20:49:30 +00:00
|
|
|
result = init_resb_result(&(resB->fResData), res, key, -1, resB->fData, resB, 0, fillIn, status);
|
2002-06-24 20:58:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2 ures_getByKey(const UResourceBundle *resB, const char* inKey, UResourceBundle *fillIn, UErrorCode *status) {
|
|
|
|
Resource res = RES_BOGUS;
|
2000-05-24 19:58:40 +00:00
|
|
|
UResourceDataEntry *realData = NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
const char *key = inKey;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return fillIn;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return fillIn;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(RES_GET_TYPE(resB->fRes) == RES_TABLE) {
|
|
|
|
int32_t t;
|
|
|
|
res = res_getTableItemByKey(&(resB->fResData), resB->fRes, &t, &key);
|
|
|
|
if(res == RES_BOGUS) {
|
2000-08-24 21:20:10 +00:00
|
|
|
key = inKey;
|
|
|
|
if(resB->fHasFallback == TRUE) {
|
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
|
|
|
if(U_SUCCESS(*status)) {
|
2002-06-24 20:58:17 +00:00
|
|
|
/* check if resB->fResPath gives the right name here */
|
|
|
|
return init_resb_result(rd, res, key, -1, realData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(&(resB->fResData), res, key, -1, resB->fData, resB, 0, fillIn, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
|
|
|
|
/* not currently */
|
|
|
|
else if(RES_GET_TYPE(resB->fRes) == RES_ARRAY && resB->fHasFallback == TRUE) {
|
2000-05-15 18:39:17 +00:00
|
|
|
/* here should go a first attempt to locate the key using index table */
|
2000-05-24 19:58:40 +00:00
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
2000-08-24 21:20:10 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
2002-06-24 20:58:17 +00:00
|
|
|
return init_resb_result(rd, res, key, realData, resB, fillIn, status);
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
2000-05-15 18:39:17 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-07-06 23:01:50 +00:00
|
|
|
return fillIn;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const UChar* U_EXPORT2 ures_getStringByKey(const UResourceBundle *resB, const char* inKey, int32_t* len, UErrorCode *status) {
|
|
|
|
Resource res = RES_BOGUS;
|
2000-05-24 19:58:40 +00:00
|
|
|
UResourceDataEntry *realData = NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* key = inKey;
|
|
|
|
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(resB == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 21:13:33 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(RES_GET_TYPE(resB->fRes) == RES_TABLE) {
|
|
|
|
int32_t t=0;
|
2002-02-08 00:52:08 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
res = res_getTableItemByKey(&(resB->fResData), resB->fRes, &t, &key);
|
2002-02-08 00:52:08 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(res == RES_BOGUS) {
|
2000-08-24 21:20:10 +00:00
|
|
|
key = inKey;
|
|
|
|
if(resB->fHasFallback == TRUE) {
|
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
|
|
|
if(U_SUCCESS(*status)) {
|
2002-02-08 00:52:08 +00:00
|
|
|
switch (RES_GET_TYPE(res)) {
|
|
|
|
case RES_STRING:
|
|
|
|
case RES_TABLE:
|
|
|
|
case RES_ARRAY:
|
|
|
|
return res_getString(rd, res, len);
|
|
|
|
default:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2002-02-08 00:52:08 +00:00
|
|
|
switch (RES_GET_TYPE(res)) {
|
|
|
|
case RES_STRING:
|
|
|
|
case RES_TABLE:
|
|
|
|
case RES_ARRAY:
|
|
|
|
return res_getString(&(resB->fResData), res, len);
|
|
|
|
default:
|
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* this is a kind of TODO item. If we have an array with an index table, we could do this. */
|
|
|
|
/* not currently */
|
|
|
|
else if(RES_GET_TYPE(resB->fRes) == RES_ARRAY && resB->fHasFallback == TRUE) {
|
2000-05-15 18:39:17 +00:00
|
|
|
/* here should go a first attempt to locate the key using index table */
|
2000-05-24 19:58:40 +00:00
|
|
|
const ResourceData *rd = getFallbackData(resB, &key, &realData, &res, status);
|
2000-08-24 21:20:10 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
2000-05-15 18:39:17 +00:00
|
|
|
return res_getString(rd, res, len);
|
2000-08-24 21:20:10 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
2000-05-15 18:39:17 +00:00
|
|
|
*status = U_RESOURCE_TYPE_MISMATCH;
|
|
|
|
}
|
2000-08-24 21:20:10 +00:00
|
|
|
return NULL;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO: clean from here down */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* INTERNAL: Get the name of the first real locale (not placeholder)
|
|
|
|
* that has resource bundle data.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
ures_getLocale(const UResourceBundle* resourceBundle, UErrorCode* status)
|
2000-05-15 18:39:17 +00:00
|
|
|
{
|
2000-08-24 21:20:10 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
if (!resourceBundle) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
} else {
|
2001-10-11 18:46:18 +00:00
|
|
|
return resourceBundle->fData->fName;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void entryCloseInt(UResourceDataEntry *resB) {
|
|
|
|
UResourceDataEntry *p = resB;
|
|
|
|
|
|
|
|
while(resB != NULL) {
|
|
|
|
p = resB->fParent;
|
|
|
|
resB->fCountExisting--;
|
|
|
|
|
2001-08-11 00:29:58 +00:00
|
|
|
/* Entries are left in the cache. TODO: add ures_cacheFlush() to force a flush
|
|
|
|
of the cache. */
|
2000-05-15 18:39:17 +00:00
|
|
|
/*
|
2001-08-11 00:29:58 +00:00
|
|
|
if(resB->fCountExisting <= 0) {
|
2000-05-15 18:39:17 +00:00
|
|
|
uhash_remove(cache, resB);
|
|
|
|
if(resB->fBogus == U_ZERO_ERROR) {
|
|
|
|
res_unload(&(resB->fData));
|
|
|
|
}
|
|
|
|
if(resB->fName != NULL) {
|
|
|
|
uprv_free(resB->fName);
|
|
|
|
}
|
|
|
|
if(resB->fPath != NULL) {
|
|
|
|
uprv_free(resB->fPath);
|
|
|
|
}
|
|
|
|
uprv_free(resB);
|
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
*/
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
resB = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API: closes a resource bundle and cleans up.
|
|
|
|
*/
|
|
|
|
|
2001-10-04 00:12:19 +00:00
|
|
|
static void entryClose(UResourceDataEntry *resB) {
|
2000-05-15 18:39:17 +00:00
|
|
|
umtx_lock(&resbMutex);
|
|
|
|
entryCloseInt(resB);
|
|
|
|
umtx_unlock(&resbMutex);
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
/*
|
|
|
|
U_CFUNC void ures_setResPath(UResourceBundle *resB, const char* toAdd) {
|
|
|
|
if(resB->fResPath == NULL) {
|
|
|
|
resB->fResPath = resB->fResBuf;
|
|
|
|
*(resB->fResPath) = 0;
|
|
|
|
}
|
|
|
|
resB->fResPathLen = uprv_strlen(toAdd);
|
|
|
|
if(RES_BUFSIZE <= resB->fResPathLen+1) {
|
|
|
|
if(resB->fResPath == resB->fResBuf) {
|
|
|
|
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
|
|
|
|
} else {
|
|
|
|
resB->fResPath = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uprv_strcpy(resB->fResPath, toAdd);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
U_CFUNC void ures_appendResPath(UResourceBundle *resB, const char* toAdd) {
|
|
|
|
if(resB->fResPath == NULL) {
|
|
|
|
resB->fResPath = resB->fResBuf;
|
|
|
|
*(resB->fResPath) = 0;
|
|
|
|
resB->fResPathLen = 0;
|
|
|
|
}
|
|
|
|
resB->fResPathLen += uprv_strlen(toAdd);
|
|
|
|
if(RES_BUFSIZE <= resB->fResPathLen+1) {
|
|
|
|
if(resB->fResPath == resB->fResBuf) {
|
|
|
|
resB->fResPath = (char *)uprv_malloc((resB->fResPathLen+1)*sizeof(char));
|
|
|
|
uprv_strcpy(resB->fResPath, resB->fResBuf);
|
|
|
|
} else {
|
|
|
|
resB->fResPath = (char *)uprv_realloc(resB->fResPath, (resB->fResPathLen+1)*sizeof(char));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uprv_strcat(resB->fResPath, toAdd);
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2002-06-24 20:58:17 +00:00
|
|
|
U_CFUNC void ures_freeResPath(UResourceBundle *resB) {
|
2002-08-09 18:29:37 +00:00
|
|
|
if (resB->fResPath && resB->fResPath != resB->fResBuf) {
|
2002-06-24 20:58:17 +00:00
|
|
|
uprv_free(resB->fResPath);
|
|
|
|
}
|
|
|
|
resB->fResPath = NULL;
|
|
|
|
resB->fResPathLen = 0;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
U_CFUNC const char* ures_getName(const UResourceBundle* resB) {
|
2001-07-27 17:15:30 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resB->fData->fName;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-27 17:15:30 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CFUNC const char* ures_getPath(const UResourceBundle* resB) {
|
2001-07-27 17:15:30 +00:00
|
|
|
if(resB == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resB->fData->fPath;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* OLD API implementation */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API: This function is used to open a resource bundle
|
|
|
|
* proper fallback chaining is executed while initialization.
|
|
|
|
* The result is stored in cache for later fallback search.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ures_openFillIn(UResourceBundle *r, const char* path,
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* localeID, UErrorCode* status) {
|
|
|
|
if(r == NULL) {
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
} else {
|
|
|
|
UResourceDataEntry *firstData;
|
|
|
|
r->fHasFallback = TRUE;
|
|
|
|
r->fIsTopLevel = TRUE;
|
|
|
|
r->fKey = NULL;
|
|
|
|
r->fVersion = NULL;
|
|
|
|
r->fIndex = -1;
|
2002-04-17 21:19:38 +00:00
|
|
|
if(r->fData != NULL) {
|
|
|
|
entryClose(r->fData);
|
|
|
|
}
|
|
|
|
if(r->fVersion != NULL) {
|
|
|
|
uprv_free(r->fVersion);
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fData = entryOpen(path, localeID, status);
|
|
|
|
/* this is a quick fix to get regular data in bundle - until construction is cleaned up */
|
|
|
|
firstData = r->fData;
|
|
|
|
while(firstData->fBogus != U_ZERO_ERROR && firstData->fParent != NULL) {
|
|
|
|
firstData = firstData->fParent;
|
|
|
|
}
|
|
|
|
r->fResData.data = firstData->fData.data;
|
|
|
|
r->fResData.pRoot = firstData->fData.pRoot;
|
|
|
|
r->fResData.rootRes = firstData->fData.rootRes;
|
|
|
|
r->fRes = r->fResData.rootRes;
|
|
|
|
r->fSize = res_countArrayItems(&(r->fResData), r->fRes);
|
2002-06-24 20:58:17 +00:00
|
|
|
/*r->fParent = RES_BOGUS;*/
|
|
|
|
/*r->fResPath = NULL;*/
|
|
|
|
ures_freeResPath(r);
|
|
|
|
/*
|
|
|
|
if(r->fData->fPath != NULL) {
|
|
|
|
ures_setResPath(r, r->fData->fPath);
|
|
|
|
ures_appendResPath(r, RES_PATH_PACKAGE_S);
|
|
|
|
ures_appendResPath(r, r->fData->fName);
|
|
|
|
} else {
|
|
|
|
ures_setResPath(r, r->fData->fName);
|
|
|
|
}
|
|
|
|
*/
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_open(const char* path,
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* localeID,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
2001-10-11 00:51:18 +00:00
|
|
|
char canonLocaleID[100];
|
2000-05-15 18:39:17 +00:00
|
|
|
UResourceDataEntry *hasData = NULL;
|
2001-10-11 00:51:18 +00:00
|
|
|
UResourceBundle *r;
|
|
|
|
int32_t length;
|
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first "canonicalize" the locale ID */
|
|
|
|
length = uloc_getName(localeID, canonLocaleID, sizeof(canonLocaleID), status);
|
|
|
|
if(U_FAILURE(*status) || *status == U_STRING_NOT_TERMINATED_WARNING) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2000-05-15 18:39:17 +00:00
|
|
|
if(r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->fHasFallback = TRUE;
|
|
|
|
r->fIsTopLevel = TRUE;
|
2000-07-12 22:59:57 +00:00
|
|
|
ures_setIsStackObject(r, FALSE);
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fKey = NULL;
|
|
|
|
r->fVersion = NULL;
|
|
|
|
r->fIndex = -1;
|
2001-10-11 00:51:18 +00:00
|
|
|
r->fData = entryOpen(path, canonLocaleID, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
uprv_free(r);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasData = r->fData;
|
|
|
|
while(hasData->fBogus != U_ZERO_ERROR) {
|
|
|
|
hasData = hasData->fParent;
|
|
|
|
if(hasData == NULL) {
|
2001-07-27 17:15:30 +00:00
|
|
|
/* This can happen only if fallback chain gets broken by an act of God */
|
|
|
|
/* TODO: this unlikely to happen, consider removing it */
|
2000-05-15 18:39:17 +00:00
|
|
|
entryClose(r->fData);
|
|
|
|
uprv_free(r);
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r->fResData.data = hasData->fData.data;
|
|
|
|
r->fResData.pRoot = hasData->fData.pRoot;
|
|
|
|
r->fResData.rootRes = hasData->fData.rootRes;
|
|
|
|
r->fRes = r->fResData.rootRes;
|
2002-06-24 20:58:17 +00:00
|
|
|
/*r->fParent = RES_BOGUS;*/
|
2000-05-15 18:39:17 +00:00
|
|
|
r->fSize = res_countArrayItems(&(r->fResData), r->fRes);
|
2002-06-24 20:58:17 +00:00
|
|
|
r->fResPath = NULL;
|
|
|
|
/*
|
|
|
|
if(r->fData->fPath != NULL) {
|
|
|
|
ures_setResPath(r, r->fData->fPath);
|
|
|
|
ures_appendResPath(r, RES_PATH_PACKAGE_S);
|
|
|
|
ures_appendResPath(r, r->fData->fName);
|
|
|
|
} else {
|
|
|
|
ures_setResPath(r, r->fData->fName);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2000-06-30 20:24:59 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2 ures_openU(const UChar* myPath,
|
|
|
|
const char* localeID,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
UResourceBundle *r;
|
2001-04-18 00:26:56 +00:00
|
|
|
int32_t pathSize = u_strlen(myPath) + 1;
|
|
|
|
char *path = (char *)uprv_malloc(pathSize);
|
2002-07-01 18:04:55 +00:00
|
|
|
/* test for NULL */
|
2002-07-03 11:59:21 +00:00
|
|
|
if(path == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-06-30 20:24:59 +00:00
|
|
|
|
2001-04-18 00:26:56 +00:00
|
|
|
u_UCharsToChars(myPath, path, pathSize);
|
2000-06-30 20:24:59 +00:00
|
|
|
|
|
|
|
r = ures_open(path, localeID, status);
|
2001-04-18 00:26:56 +00:00
|
|
|
uprv_free(path);
|
2000-06-30 20:24:59 +00:00
|
|
|
|
2001-04-18 00:26:56 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-06-30 20:24:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-10-10 01:13:01 +00:00
|
|
|
/**
|
|
|
|
* Opens a resource bundle without "canonicalizing" the locale name. No fallback will be performed
|
2001-10-11 18:46:18 +00:00
|
|
|
* or sought. However, alias substitution will happen!
|
2001-10-10 01:13:01 +00:00
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI UResourceBundle* U_EXPORT2
|
|
|
|
ures_openDirect(const char* path, const char* localeID, UErrorCode* status) {
|
2001-10-11 00:51:18 +00:00
|
|
|
UResourceBundle *r;
|
|
|
|
|
|
|
|
if(status == NULL || U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = (UResourceBundle *)uprv_malloc(sizeof(UResourceBundle));
|
2001-10-10 01:13:01 +00:00
|
|
|
if(r == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->fHasFallback = FALSE;
|
|
|
|
r->fIsTopLevel = TRUE;
|
|
|
|
ures_setIsStackObject(r, FALSE);
|
|
|
|
r->fIndex = -1;
|
|
|
|
r->fData = entryOpen(path, localeID, status);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
uprv_free(r);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-10-11 18:46:18 +00:00
|
|
|
if(*status != U_ZERO_ERROR /*r->fData->fBogus != U_ZERO_ERROR*/) {
|
|
|
|
/* we didn't find one we were looking for - so openDirect */
|
|
|
|
/* should fail */
|
2001-10-10 01:13:01 +00:00
|
|
|
entryClose(r->fData);
|
|
|
|
uprv_free(r);
|
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->fKey = NULL;
|
|
|
|
r->fVersion = NULL;
|
|
|
|
r->fResData.data = r->fData->fData.data;
|
|
|
|
r->fResData.pRoot = r->fData->fData.pRoot;
|
|
|
|
r->fResData.rootRes = r->fData->fData.rootRes;
|
|
|
|
r->fRes = r->fResData.rootRes;
|
2002-06-24 20:58:17 +00:00
|
|
|
/*r->fParent = RES_BOGUS;*/
|
2001-10-10 01:13:01 +00:00
|
|
|
r->fSize = res_countArrayItems(&(r->fResData), r->fRes);
|
2002-06-24 20:58:17 +00:00
|
|
|
r->fResPath = NULL;
|
|
|
|
/*
|
|
|
|
if(r->fData->fPath != NULL) {
|
|
|
|
ures_setResPath(r, r->fData->fPath);
|
|
|
|
ures_appendResPath(r, RES_PATH_PACKAGE_S);
|
|
|
|
ures_appendResPath(r, r->fData->fName);
|
|
|
|
} else {
|
|
|
|
ures_setResPath(r, r->fData->fName);
|
|
|
|
}
|
|
|
|
*/
|
2001-10-10 01:13:01 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-07-27 17:15:30 +00:00
|
|
|
U_CFUNC void ures_setIsStackObject( UResourceBundle* resB, UBool state) {
|
2001-02-16 21:45:31 +00:00
|
|
|
if(state) {
|
2000-07-12 22:59:57 +00:00
|
|
|
resB->fMagic1 = 0;
|
|
|
|
resB->fMagic2 = 0;
|
|
|
|
} else {
|
|
|
|
resB->fMagic1 = MAGIC1;
|
|
|
|
resB->fMagic2 = MAGIC2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-27 17:15:30 +00:00
|
|
|
U_CFUNC UBool ures_isStackObject(UResourceBundle* resB) {
|
|
|
|
return((resB->fMagic1 == MAGIC1 && resB->fMagic2 == MAGIC2)?FALSE:TRUE);
|
2000-07-10 20:43:34 +00:00
|
|
|
}
|
2000-06-30 20:24:59 +00:00
|
|
|
|
2002-04-17 21:19:38 +00:00
|
|
|
|
|
|
|
U_CFUNC void ures_initStackObject(UResourceBundle* resB) {
|
|
|
|
memset(resB, 0, sizeof(UResourceBundle));
|
|
|
|
ures_setIsStackObject(resB, TRUE);
|
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/**
|
|
|
|
* API: Counts members. For arrays and tables, returns number of resources.
|
|
|
|
* For strings, returns 1.
|
|
|
|
*/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ures_countArrayItems(const UResourceBundle* resourceBundle,
|
2000-05-15 18:39:17 +00:00
|
|
|
const char* resourceKey,
|
|
|
|
UErrorCode* status)
|
|
|
|
{
|
|
|
|
UResourceBundle resData;
|
2002-04-17 21:19:38 +00:00
|
|
|
ures_initStackObject(&resData);
|
2000-06-07 19:52:08 +00:00
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(resourceBundle == NULL) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
ures_getByKey(resourceBundle, resourceKey, &resData, status);
|
|
|
|
|
|
|
|
if(resData.fResData.data != NULL) {
|
2000-07-10 20:43:34 +00:00
|
|
|
int32_t result = res_countArrayItems(&resData.fResData, resData.fRes);
|
|
|
|
ures_close(&resData);
|
|
|
|
return result;
|
2000-05-15 18:39:17 +00:00
|
|
|
} else {
|
2000-07-10 20:43:34 +00:00
|
|
|
*status = U_MISSING_RESOURCE_ERROR;
|
|
|
|
ures_close(&resData);
|
|
|
|
return 0;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ures_close(UResourceBundle* resB)
|
2000-05-15 18:39:17 +00:00
|
|
|
{
|
|
|
|
if(resB != NULL) {
|
|
|
|
if(resB->fData != NULL) {
|
|
|
|
entryClose(resB->fData);
|
|
|
|
}
|
|
|
|
if(resB->fVersion != NULL) {
|
|
|
|
uprv_free(resB->fVersion);
|
|
|
|
}
|
2002-06-24 20:58:17 +00:00
|
|
|
ures_freeResPath(resB);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-07-27 17:15:30 +00:00
|
|
|
if(ures_isStackObject(resB) == FALSE) {
|
2000-05-15 18:39:17 +00:00
|
|
|
uprv_free(resB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI const char* U_EXPORT2
|
|
|
|
ures_getVersionNumber(const UResourceBundle* resourceBundle)
|
2000-05-15 18:39:17 +00:00
|
|
|
{
|
|
|
|
if (!resourceBundle) return NULL;
|
|
|
|
|
|
|
|
if(resourceBundle->fVersion == NULL) {
|
|
|
|
|
|
|
|
/* If the version ID has not been built yet, then do so. Retrieve */
|
|
|
|
/* the minor version from the file. */
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
int32_t minor_len = 0;
|
2000-10-14 01:53:59 +00:00
|
|
|
int32_t len;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
const UChar* minor_version = ures_getStringByKey(resourceBundle, kVersionTag, &minor_len, &status);
|
|
|
|
|
|
|
|
/* Determine the length of of the final version string. This is */
|
|
|
|
/* the length of the major part + the length of the separator */
|
|
|
|
/* (==1) + the length of the minor part (+ 1 for the zero byte at */
|
|
|
|
/* the end). */
|
2000-10-14 01:53:59 +00:00
|
|
|
|
|
|
|
len = (minor_len > 0) ? minor_len : 1;
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/* Allocate the string, and build it up. */
|
|
|
|
/* + 1 for zero byte */
|
|
|
|
|
|
|
|
|
|
|
|
((UResourceBundle *)resourceBundle)->fVersion = (char *)uprv_malloc(1 + len);
|
|
|
|
|
|
|
|
if(minor_len > 0) {
|
2000-10-14 01:53:59 +00:00
|
|
|
u_UCharsToChars(minor_version, resourceBundle->fVersion , minor_len);
|
2000-05-15 18:39:17 +00:00
|
|
|
resourceBundle->fVersion[len] = '\0';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uprv_strcat(resourceBundle->fVersion, kDefaultMinorVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resourceBundle->fVersion;
|
|
|
|
}
|
|
|
|
|
2000-06-30 20:24:59 +00:00
|
|
|
U_CAPI void U_EXPORT2 ures_getVersion(const UResourceBundle* resB, UVersionInfo versionInfo) {
|
|
|
|
if (!resB) return;
|
2000-08-10 19:10:12 +00:00
|
|
|
|
|
|
|
u_versionFromString(versionInfo, ures_getVersionNumber(resB));
|
2000-06-30 20:24:59 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/* eof */
|