2000-05-15 19:29:11 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File reslist.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 02/21/00 weiv Creation.
|
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
#include <assert.h>
|
2000-05-15 19:29:11 +00:00
|
|
|
#include "reslist.h"
|
|
|
|
#include "unewdata.h"
|
|
|
|
#include "unicode/ures.h"
|
2002-04-23 22:25:44 +00:00
|
|
|
#include "errmsg.h"
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
#define BIN_ALIGNMENT 16
|
|
|
|
|
2001-11-03 02:54:08 +00:00
|
|
|
static UBool gIncludeCopyright = FALSE;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
uint32_t res_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static const UDataInfo dataInfo= {
|
2002-04-30 19:07:18 +00:00
|
|
|
sizeof(UDataInfo),
|
|
|
|
0,
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2002-04-30 19:07:18 +00:00
|
|
|
U_IS_BIG_ENDIAN,
|
|
|
|
U_CHARSET_FAMILY,
|
|
|
|
sizeof(UChar),
|
|
|
|
0,
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2002-04-30 19:07:18 +00:00
|
|
|
{0x52, 0x65, 0x73, 0x42}, /* dataFormat="resb" */
|
|
|
|
{1, 0, 0, 0}, /* formatVersion */
|
|
|
|
{1, 4, 0, 0} /* dataVersion take a look at version inside parsed resb*/
|
|
|
|
};
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2000-11-28 20:10:05 +00:00
|
|
|
static uint8_t calcPadding(uint32_t size) {
|
2000-05-15 19:29:11 +00:00
|
|
|
/* returns space we need to pad */
|
2001-07-11 20:31:32 +00:00
|
|
|
return (uint8_t) ((size % sizeof(uint32_t)) ? (sizeof(uint32_t) - (size % sizeof(uint32_t))) : 0);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-11-03 02:54:08 +00:00
|
|
|
void setIncludeCopyright(UBool val){
|
|
|
|
gIncludeCopyright=val;
|
|
|
|
}
|
2002-04-30 19:07:18 +00:00
|
|
|
|
2002-03-22 18:57:09 +00:00
|
|
|
UBool getIncludeCopyright(void){
|
|
|
|
return gIncludeCopyright;
|
|
|
|
}
|
2002-04-30 19:07:18 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
/* Writing Functions */
|
2001-07-11 20:31:32 +00:00
|
|
|
static uint32_t string_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
udata_write32(mem, res->u.fString.fLength);
|
2001-07-11 20:31:32 +00:00
|
|
|
udata_writeUString(mem, res->u.fString.fChars, res->u.fString.fLength + 1);
|
2000-05-15 19:29:11 +00:00
|
|
|
udata_writePadding(mem, calcPadding(res->fSize));
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
return usedOffset;
|
|
|
|
}
|
|
|
|
|
2002-06-14 06:01:13 +00:00
|
|
|
/* Writing Functions */
|
|
|
|
static uint32_t alias_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
|
|
|
udata_write32(mem, res->u.fString.fLength);
|
|
|
|
udata_writeUString(mem, res->u.fString.fChars, res->u.fString.fLength + 1);
|
|
|
|
udata_writePadding(mem, calcPadding(res->fSize));
|
|
|
|
|
|
|
|
return usedOffset;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static uint32_t array_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uint32_t *resources = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
uint32_t i = 0;
|
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
struct SResource *current = NULL;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res->u.fArray.fCount > 0) {
|
|
|
|
resources = (uint32_t *) uprv_malloc(sizeof(uint32_t) * res->u.fArray.fCount);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
if (resources == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = res->u.fArray.fFirst;
|
2001-07-11 20:31:32 +00:00
|
|
|
i = 0;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
while (current != NULL) {
|
|
|
|
if (current->fType == RES_INT) {
|
|
|
|
resources[i] = (current->fType << 28) | (current->u.fIntValue.fValue & 0xFFFFFFF);
|
|
|
|
} else if (current->fType == RES_BINARY) {
|
2000-08-09 17:39:16 +00:00
|
|
|
uint32_t uo = usedOffset;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
usedOffset = res_write(mem, current, usedOffset, status);
|
|
|
|
resources[i] = (current->fType << 28) | (usedOffset >> 2);
|
|
|
|
usedOffset += current->fSize + calcPadding(current->fSize) - (usedOffset - uo);
|
2000-05-15 19:29:11 +00:00
|
|
|
} else {
|
2001-07-11 20:31:32 +00:00
|
|
|
usedOffset = res_write(mem, current, usedOffset, status);
|
|
|
|
resources[i] = (current->fType << 28) | (usedOffset >> 2);
|
|
|
|
usedOffset += current->fSize + calcPadding(current->fSize);
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
i++;
|
|
|
|
current = current->fNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* usedOffset += res->fSize + pad; */
|
|
|
|
|
|
|
|
udata_write32(mem, res->u.fArray.fCount);
|
2001-07-11 20:31:32 +00:00
|
|
|
udata_writeBlock(mem, resources, sizeof(uint32_t) * res->u.fArray.fCount);
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(resources);
|
2001-07-11 20:31:32 +00:00
|
|
|
} else {
|
|
|
|
/* array is empty */
|
2000-05-15 19:29:11 +00:00
|
|
|
udata_write32(mem, 0);
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
return usedOffset;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static uint32_t intvector_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
2001-08-01 17:08:07 +00:00
|
|
|
uint32_t i = 0;
|
|
|
|
udata_write32(mem, res->u.fIntVector.fCount);
|
|
|
|
for(i = 0; i<res->u.fIntVector.fCount; i++) {
|
|
|
|
udata_write32(mem, res->u.fIntVector.fArray[i]);
|
|
|
|
}
|
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
return usedOffset;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static uint32_t bin_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
|
|
|
uint32_t pad = 0;
|
|
|
|
uint32_t extrapad = calcPadding(res->fSize);
|
|
|
|
uint32_t dataStart = usedOffset + sizeof(res->u.fBinaryValue.fLength);
|
|
|
|
|
|
|
|
if (dataStart % BIN_ALIGNMENT) {
|
|
|
|
pad = (BIN_ALIGNMENT - dataStart % BIN_ALIGNMENT);
|
2000-08-09 17:39:16 +00:00
|
|
|
udata_writePadding(mem, pad);
|
|
|
|
usedOffset += pad;
|
|
|
|
}
|
2000-05-18 21:25:51 +00:00
|
|
|
|
|
|
|
udata_write32(mem, res->u.fBinaryValue.fLength);
|
2001-08-28 01:00:29 +00:00
|
|
|
if (res->u.fBinaryValue.fLength > 0) {
|
|
|
|
udata_writeBlock(mem, res->u.fBinaryValue.fData, res->u.fBinaryValue.fLength);
|
|
|
|
}
|
2000-08-09 17:39:16 +00:00
|
|
|
udata_writePadding(mem, (BIN_ALIGNMENT - pad + extrapad));
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
return usedOffset;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static uint32_t int_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return usedOffset;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static uint32_t table_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
|
|
|
uint8_t pad = 0;
|
|
|
|
uint32_t i = 0;
|
|
|
|
uint16_t *keys = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
uint32_t *resources = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
struct SResource *current = NULL;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pad = calcPadding(res->fSize);
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res->u.fTable.fCount > 0) {
|
|
|
|
keys = (uint16_t *) uprv_malloc(sizeof(uint16_t) * res->u.fTable.fCount);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
if (keys == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
resources = (uint32_t *) uprv_malloc(sizeof(uint32_t) * res->u.fTable.fCount);
|
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
if (resources == NULL) {
|
|
|
|
uprv_free(keys);
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
current = res->u.fTable.fFirst;
|
2001-07-11 20:31:32 +00:00
|
|
|
i = 0;
|
|
|
|
|
|
|
|
while (current != NULL) {
|
|
|
|
assert(i < res->u.fTable.fCount);
|
|
|
|
|
|
|
|
/* where the key is plus root pointer */
|
|
|
|
keys[i] = (uint16_t) (current->fKey + sizeof(uint32_t));
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (current->fType == RES_INT) {
|
|
|
|
resources[i] = (current->fType << 28) | (current->u.fIntValue.fValue & 0xFFFFFFF);
|
|
|
|
} else if (current->fType == RES_BINARY) {
|
2000-08-09 17:39:16 +00:00
|
|
|
uint32_t uo = usedOffset;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
usedOffset = res_write(mem, current, usedOffset, status);
|
|
|
|
resources[i] = (current->fType << 28) | (usedOffset >> 2);
|
|
|
|
usedOffset += current->fSize + calcPadding(current->fSize) - (usedOffset - uo);
|
2000-08-09 17:39:16 +00:00
|
|
|
} else {
|
2001-07-11 20:31:32 +00:00
|
|
|
usedOffset = res_write(mem, current, usedOffset, status);
|
|
|
|
resources[i] = (current->fType << 28) | (usedOffset >> 2);
|
|
|
|
usedOffset += current->fSize + calcPadding(current->fSize);
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
i++;
|
|
|
|
current = current->fNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
udata_write16(mem, res->u.fTable.fCount);
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
udata_writeBlock(mem, keys, sizeof(uint16_t) * res->u.fTable.fCount);
|
2000-05-15 19:29:11 +00:00
|
|
|
udata_writePadding(mem, pad);
|
2001-07-11 20:31:32 +00:00
|
|
|
udata_writeBlock(mem, resources, sizeof(uint32_t) * res->u.fTable.fCount);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
uprv_free(keys);
|
|
|
|
uprv_free(resources);
|
2001-07-11 20:31:32 +00:00
|
|
|
} else {
|
|
|
|
/* table is empty */
|
2000-05-15 19:29:11 +00:00
|
|
|
udata_write16(mem, 0);
|
|
|
|
udata_writePadding(mem, pad);
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
return usedOffset;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
uint32_t res_write(UNewDataMemory *mem, struct SResource *res,
|
|
|
|
uint32_t usedOffset, UErrorCode *status) {
|
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res != NULL) {
|
|
|
|
switch (res->fType) {
|
2000-05-15 19:29:11 +00:00
|
|
|
case RES_STRING:
|
2001-07-11 20:31:32 +00:00
|
|
|
return string_write (mem, res, usedOffset, status);
|
2002-06-14 06:01:13 +00:00
|
|
|
case RES_ALIAS:
|
|
|
|
return alias_write (mem, res, usedOffset, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
case RES_INT_VECTOR:
|
2001-07-11 20:31:32 +00:00
|
|
|
return intvector_write (mem, res, usedOffset, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
case RES_BINARY:
|
2001-07-11 20:31:32 +00:00
|
|
|
return bin_write (mem, res, usedOffset, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
case RES_INT:
|
2001-07-11 20:31:32 +00:00
|
|
|
return int_write (mem, res, usedOffset, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
case RES_ARRAY:
|
2001-07-11 20:31:32 +00:00
|
|
|
return array_write (mem, res, usedOffset, status);
|
|
|
|
case RES_TABLE:
|
|
|
|
return table_write (mem, res, usedOffset, status);
|
|
|
|
|
2000-11-28 20:10:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
void bundle_write(struct SRBRoot *bundle, const char *outputDir, const char *outputPkg, char *writtenFilename, int writtenFilenameLen, UErrorCode *status) {
|
2001-07-11 20:31:32 +00:00
|
|
|
UNewDataMemory *mem = NULL;
|
|
|
|
uint8_t pad = 0;
|
|
|
|
uint32_t root = 0;
|
|
|
|
uint32_t usedOffset = 0;
|
2002-07-17 03:56:50 +00:00
|
|
|
char dataName[1024];
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2002-03-19 17:49:17 +00:00
|
|
|
if (writtenFilename && writtenFilenameLen) {
|
|
|
|
*writtenFilename = 0;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-19 17:49:17 +00:00
|
|
|
if (writtenFilename) {
|
2002-04-30 19:07:18 +00:00
|
|
|
int32_t off = 0, len = 0;
|
2002-03-20 02:36:59 +00:00
|
|
|
if (outputDir) {
|
2002-04-30 19:07:18 +00:00
|
|
|
len = (int32_t)uprv_strlen(outputDir);
|
2002-03-20 02:36:59 +00:00
|
|
|
if (len > writtenFilenameLen) {
|
|
|
|
len = writtenFilenameLen;
|
|
|
|
}
|
|
|
|
uprv_strncpy(writtenFilename, outputDir, len);
|
2002-03-19 17:49:17 +00:00
|
|
|
}
|
|
|
|
if (writtenFilenameLen -= len) {
|
|
|
|
off += len;
|
|
|
|
writtenFilename[off] = U_FILE_SEP_CHAR;
|
|
|
|
if (--writtenFilenameLen) {
|
|
|
|
++off;
|
2002-07-17 03:56:50 +00:00
|
|
|
if(outputPkg != NULL)
|
|
|
|
{
|
|
|
|
uprv_strcpy(writtenFilename+off, outputPkg);
|
|
|
|
off += uprv_strlen(outputPkg);
|
|
|
|
writtenFilename[off] = '_';
|
|
|
|
++off;
|
|
|
|
}
|
|
|
|
|
2002-04-30 19:07:18 +00:00
|
|
|
len = (int32_t)uprv_strlen(bundle->fLocale);
|
2002-03-19 17:49:17 +00:00
|
|
|
if (len > writtenFilenameLen) {
|
|
|
|
len = writtenFilenameLen;
|
|
|
|
}
|
|
|
|
uprv_strncpy(writtenFilename + off, bundle->fLocale, len);
|
|
|
|
if (writtenFilenameLen -= len) {
|
|
|
|
off += len;
|
|
|
|
len = 5;
|
|
|
|
if (len > writtenFilenameLen) {
|
|
|
|
len = writtenFilenameLen;
|
|
|
|
}
|
|
|
|
uprv_strncpy(writtenFilename + off, ".res", len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
if(outputPkg)
|
|
|
|
{
|
|
|
|
uprv_strcpy(dataName, outputPkg);
|
|
|
|
uprv_strcat(dataName, "_");
|
|
|
|
uprv_strcat(dataName, bundle->fLocale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uprv_strcpy(dataName, bundle->fLocale);
|
|
|
|
}
|
|
|
|
|
|
|
|
mem = udata_create(outputDir, "res", dataName, &dataInfo, (gIncludeCopyright==TRUE)? U_COPYRIGHT_STRING:NULL, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
pad = calcPadding(bundle->fKeyPoint);
|
|
|
|
|
|
|
|
usedOffset = sizeof(uint32_t) + bundle->fKeyPoint + pad ; /*this is how much root and keys are taking up*/
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
root = ((usedOffset + bundle->fRoot->u.fTable.fChildrenSize) >> 2) | (RES_TABLE << 28); /* we're gonna put the main table at the end */
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
udata_write32(mem, root);
|
|
|
|
|
|
|
|
udata_writeBlock(mem, bundle->fKeys, bundle->fKeyPoint);
|
|
|
|
|
|
|
|
udata_writePadding(mem, pad);
|
|
|
|
|
|
|
|
usedOffset = res_write(mem, bundle->fRoot, usedOffset, status);
|
|
|
|
|
|
|
|
udata_finish(mem, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Opening Functions */
|
|
|
|
struct SResource* table_open(struct SRBRoot *bundle, char *tag, UErrorCode *status) {
|
|
|
|
struct SResource *res;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res = (struct SResource *) uprv_malloc(sizeof(struct SResource));
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fType = RES_TABLE;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fNext = NULL;
|
|
|
|
res->fSize = sizeof(uint16_t);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
res->u.fTable.fCount = 0;
|
2000-05-15 19:29:11 +00:00
|
|
|
res->u.fTable.fChildrenSize = 0;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->u.fTable.fFirst = NULL;
|
|
|
|
res->u.fTable.fRoot = bundle;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SResource* array_open(struct SRBRoot *bundle, char *tag, UErrorCode *status) {
|
|
|
|
struct SResource *res;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res = (struct SResource *) uprv_malloc(sizeof(struct SResource));
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fType = RES_ARRAY;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fNext = NULL;
|
|
|
|
res->fSize = sizeof(int32_t);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
res->u.fArray.fCount = 0;
|
2000-05-15 19:29:11 +00:00
|
|
|
res->u.fArray.fChildrenSize = 0;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->u.fArray.fFirst = NULL;
|
|
|
|
res->u.fArray.fLast = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-05-20 02:56:59 +00:00
|
|
|
struct SResource *string_open(struct SRBRoot *bundle, char *tag, UChar *value, int32_t len, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
struct SResource *res;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res = (struct SResource *) uprv_malloc(sizeof(struct SResource));
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fType = RES_STRING;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fNext = NULL;
|
|
|
|
|
2000-05-20 02:56:59 +00:00
|
|
|
res->u.fString.fLength = len;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->u.fString.fChars = (UChar *) uprv_malloc(sizeof(UChar) * (len + 1));
|
|
|
|
|
|
|
|
if (res->u.fString.fChars == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
uprv_memcpy(res->u.fString.fChars, value, sizeof(UChar) * (len + 1));
|
|
|
|
res->fSize = sizeof(int32_t) + sizeof(UChar) * (len + 1);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-06-14 06:01:13 +00:00
|
|
|
/* TODO: make alias_open and string_open use the same code */
|
|
|
|
struct SResource *alias_open(struct SRBRoot *bundle, char *tag, UChar *value, int32_t len, UErrorCode *status) {
|
|
|
|
struct SResource *res;
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = (struct SResource *) uprv_malloc(sizeof(struct SResource));
|
|
|
|
|
|
|
|
if (res == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fType = RES_ALIAS;
|
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fNext = NULL;
|
|
|
|
|
|
|
|
res->u.fString.fLength = len;
|
|
|
|
res->u.fString.fChars = (UChar *) uprv_malloc(sizeof(UChar) * (len + 1));
|
|
|
|
|
|
|
|
if (res->u.fString.fChars == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_memcpy(res->u.fString.fChars, value, sizeof(UChar) * (len + 1));
|
|
|
|
res->fSize = sizeof(int32_t) + sizeof(UChar) * (len + 1);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
struct SResource* intvector_open(struct SRBRoot *bundle, char *tag, UErrorCode *status) {
|
|
|
|
struct SResource *res;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res = (struct SResource *) uprv_malloc(sizeof(struct SResource));
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-01 17:08:07 +00:00
|
|
|
res->fType = RES_INT_VECTOR;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fNext = NULL;
|
|
|
|
res->fSize = sizeof(int32_t);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
res->u.fIntVector.fCount = 0;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->u.fIntVector.fArray = (uint32_t *) uprv_malloc(sizeof(uint32_t) * RESLIST_MAX_INT_VECTOR);
|
|
|
|
|
|
|
|
if (res->u.fIntVector.fArray == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SResource *int_open(struct SRBRoot *bundle, char *tag, int32_t value, UErrorCode *status) {
|
|
|
|
struct SResource *res;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res = (struct SResource *) uprv_malloc(sizeof(struct SResource));
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fType = RES_INT;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fSize = 0;
|
|
|
|
res->fNext = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
res->u.fIntValue.fValue = value;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-08-23 20:06:20 +00:00
|
|
|
struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
struct SResource *res;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res = (struct SResource *) uprv_malloc(sizeof(struct SResource));
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
res->fType = RES_BINARY;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fNext = NULL;
|
|
|
|
|
|
|
|
res->u.fBinaryValue.fLength = length;
|
2001-08-27 18:51:43 +00:00
|
|
|
if (length > 0) {
|
|
|
|
res->u.fBinaryValue.fData = (uint8_t *) uprv_malloc(sizeof(uint8_t) * length);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2001-08-27 18:51:43 +00:00
|
|
|
if (res->u.fBinaryValue.fData == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2001-08-27 18:51:43 +00:00
|
|
|
uprv_memcpy(res->u.fBinaryValue.fData, data, length);
|
|
|
|
}
|
2001-08-28 01:00:29 +00:00
|
|
|
else {
|
|
|
|
res->u.fBinaryValue.fData = NULL;
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
res->fSize = sizeof(int32_t) + sizeof(uint8_t) * length + BIN_ALIGNMENT;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SRBRoot *bundle_open(UErrorCode *status) {
|
|
|
|
struct SRBRoot *bundle = NULL;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle = (struct SRBRoot *) uprv_malloc(sizeof(struct SRBRoot));
|
|
|
|
|
|
|
|
if (bundle == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle->fLocale = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
bundle->fKeyPoint = 0;
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle->fKeys = (char *) uprv_malloc(sizeof(char) * KEY_SPACE_SIZE);
|
|
|
|
|
|
|
|
if (bundle->fKeys == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
uprv_free(bundle);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
bundle->fCount = 0;
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle->fRoot = table_open(bundle, NULL, status);
|
|
|
|
|
|
|
|
if (bundle->fRoot == NULL || U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(bundle->fKeys);
|
|
|
|
uprv_free(bundle);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
return bundle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Closing Functions */
|
|
|
|
void table_close(struct SResource *table, UErrorCode *status) {
|
|
|
|
struct SResource *current = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
struct SResource *prev = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
current = table->u.fTable.fFirst;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
while (current != NULL) {
|
|
|
|
prev = current;
|
2000-05-15 19:29:11 +00:00
|
|
|
current = current->fNext;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
res_close(prev, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void array_close(struct SResource *array, UErrorCode *status) {
|
|
|
|
struct SResource *current = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
struct SResource *prev = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
current = array->u.fArray.fFirst;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
while (current != NULL) {
|
|
|
|
prev = current;
|
2000-05-15 19:29:11 +00:00
|
|
|
current = current->fNext;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
res_close(prev, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void string_close(struct SResource *string, UErrorCode *status) {
|
2001-07-11 20:31:32 +00:00
|
|
|
if (string->u.fString.fChars != NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(string->u.fString.fChars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-14 06:01:13 +00:00
|
|
|
void alias_close(struct SResource *alias, UErrorCode *status) {
|
|
|
|
if (alias->u.fString.fChars != NULL) {
|
|
|
|
uprv_free(alias->u.fString.fChars);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
void intvector_close(struct SResource *intvector, UErrorCode *status) {
|
2001-07-11 20:31:32 +00:00
|
|
|
if (intvector->u.fIntVector.fArray != NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(intvector->u.fIntVector.fArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void int_close(struct SResource *intres, UErrorCode *status) {
|
|
|
|
/* Intentionally left blank */
|
|
|
|
}
|
|
|
|
|
|
|
|
void bin_close(struct SResource *binres, UErrorCode *status) {
|
2001-07-11 20:31:32 +00:00
|
|
|
if (binres->u.fBinaryValue.fData != NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(binres->u.fBinaryValue.fData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void res_close(struct SResource *res, UErrorCode *status) {
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res != NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
switch(res->fType) {
|
|
|
|
case RES_STRING:
|
|
|
|
string_close(res, status);
|
|
|
|
break;
|
2002-06-14 06:01:13 +00:00
|
|
|
case RES_ALIAS:
|
|
|
|
alias_close(res, status);
|
|
|
|
break;
|
2000-05-15 19:29:11 +00:00
|
|
|
case RES_INT_VECTOR:
|
|
|
|
intvector_close(res, status);
|
|
|
|
break;
|
|
|
|
case RES_BINARY:
|
|
|
|
bin_close(res, status);
|
|
|
|
break;
|
|
|
|
case RES_INT:
|
|
|
|
int_close(res, status);
|
|
|
|
break;
|
|
|
|
case RES_ARRAY:
|
|
|
|
array_close(res, status);
|
|
|
|
break;
|
2001-07-11 20:31:32 +00:00
|
|
|
case RES_TABLE :
|
2000-05-15 19:29:11 +00:00
|
|
|
table_close(res, status);
|
|
|
|
break;
|
2000-11-28 20:10:05 +00:00
|
|
|
default:
|
|
|
|
/* Shouldn't happen */
|
|
|
|
break;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uprv_free(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bundle_close(struct SRBRoot *bundle, UErrorCode *status) {
|
|
|
|
struct SResource *current = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
struct SResource *prev = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (bundle->fRoot != NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
current = bundle->fRoot->u.fTable.fFirst;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
while (current != NULL) {
|
|
|
|
prev = current;
|
2000-05-15 19:29:11 +00:00
|
|
|
current = current->fNext;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
res_close(prev, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_free(bundle->fRoot);
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (bundle->fLocale != NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(bundle->fLocale);
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (bundle->fKeys != NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(bundle->fKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_free(bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adding Functions */
|
2001-07-11 20:31:32 +00:00
|
|
|
void table_add(struct SResource *table, struct SResource *res, int linenumber, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
struct SResource *current = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
struct SResource *prev = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
struct SResTable *list;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* remember this linenumber to report to the user if there is a duplicate key */
|
|
|
|
res->line = linenumber;
|
|
|
|
|
|
|
|
/* here we need to traverse the list */
|
2000-05-15 19:29:11 +00:00
|
|
|
list = &(table->u.fTable);
|
|
|
|
|
|
|
|
++(list->fCount);
|
|
|
|
table->fSize += sizeof(uint32_t) + sizeof(uint16_t);
|
|
|
|
|
|
|
|
table->u.fTable.fChildrenSize += res->fSize + calcPadding(res->fSize);
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res->fType == RES_TABLE) {
|
2000-05-15 19:29:11 +00:00
|
|
|
table->u.fTable.fChildrenSize += res->u.fTable.fChildrenSize;
|
|
|
|
} else if (res->fType == RES_ARRAY) {
|
|
|
|
table->u.fTable.fChildrenSize += res->u.fArray.fChildrenSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is list still empty? */
|
2001-07-11 20:31:32 +00:00
|
|
|
if (list->fFirst == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
list->fFirst = res;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fNext = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
current = list->fFirst;
|
|
|
|
|
|
|
|
while (current != NULL) {
|
|
|
|
if (uprv_strcmp(((list->fRoot->fKeys) + (current->fKey)), ((list->fRoot->fKeys) + (res->fKey))) < 0) {
|
|
|
|
prev = current;
|
2000-05-15 19:29:11 +00:00
|
|
|
current = current->fNext;
|
2001-07-11 20:31:32 +00:00
|
|
|
} else if (uprv_strcmp(((list->fRoot->fKeys) + (current->fKey)), ((list->fRoot->fKeys) + (res->fKey))) > 0) {
|
|
|
|
/* we're either in front of list, or in middle */
|
|
|
|
if (prev == NULL) {
|
|
|
|
/* front of the list */
|
2000-05-15 19:29:11 +00:00
|
|
|
list->fFirst = res;
|
2001-07-11 20:31:32 +00:00
|
|
|
} else {
|
|
|
|
/* middle of the list */
|
2000-05-15 19:29:11 +00:00
|
|
|
prev->fNext = res;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
res->fNext = current;
|
|
|
|
return;
|
2001-07-11 20:31:32 +00:00
|
|
|
} else {
|
|
|
|
/* Key already exists! ERROR! */
|
|
|
|
error(linenumber, "duplicate key '%s' in table, first appeared at line %d", list->fRoot->fKeys + current->fKey, current->line);
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end of list */
|
|
|
|
prev->fNext = res;
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fNext = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void array_add(struct SResource *array, struct SResource *res, UErrorCode *status) {
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (array->u.fArray.fFirst == NULL) {
|
2000-05-15 19:29:11 +00:00
|
|
|
array->u.fArray.fFirst = res;
|
2001-07-11 20:31:32 +00:00
|
|
|
array->u.fArray.fLast = res;
|
2000-05-15 19:29:11 +00:00
|
|
|
} else {
|
|
|
|
array->u.fArray.fLast->fNext = res;
|
2001-07-11 20:31:32 +00:00
|
|
|
array->u.fArray.fLast = res;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
(array->u.fArray.fCount)++;
|
|
|
|
|
|
|
|
array->fSize += sizeof(uint32_t);
|
|
|
|
array->u.fArray.fChildrenSize += res->fSize + calcPadding(res->fSize);
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (res->fType == RES_TABLE) {
|
2000-05-15 19:29:11 +00:00
|
|
|
array->u.fArray.fChildrenSize += res->u.fTable.fChildrenSize;
|
|
|
|
} else if (res->fType == RES_ARRAY) {
|
|
|
|
array->u.fArray.fChildrenSize += res->u.fArray.fChildrenSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void intvector_add(struct SResource *intvector, int32_t value, UErrorCode *status) {
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2000-05-15 19:29:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
*(intvector->u.fIntVector.fArray + intvector->u.fIntVector.fCount) = value;
|
|
|
|
intvector->u.fIntVector.fCount++;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
intvector->fSize += sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Misc Functions */
|
|
|
|
|
|
|
|
void bundle_setlocale(struct SRBRoot *bundle, UChar *locale, UErrorCode *status) {
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bundle->fLocale!=NULL) {
|
|
|
|
uprv_free(bundle->fLocale);
|
|
|
|
}
|
|
|
|
|
|
|
|
bundle->fLocale= (char*) uprv_malloc(sizeof(char) * (u_strlen(locale)+1));
|
|
|
|
|
|
|
|
if(bundle->fLocale == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*u_strcpy(bundle->fLocale, locale);*/
|
|
|
|
u_UCharsToChars(locale, bundle->fLocale, u_strlen(locale)+1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-08-23 20:06:20 +00:00
|
|
|
uint16_t bundle_addtag(struct SRBRoot *bundle, const char *tag, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
uint16_t keypos;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return (uint16_t) - 1;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (tag == NULL) {
|
|
|
|
return (uint16_t) - 1;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keypos = bundle->fKeyPoint;
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle->fKeyPoint += (uint16_t) (uprv_strlen(tag) + 1);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (bundle->fKeyPoint > KEY_SPACE_SIZE) {
|
2000-05-15 19:29:11 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2001-07-11 20:31:32 +00:00
|
|
|
return (uint16_t) - 1;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
uprv_strcpy(bundle->fKeys + keypos, tag);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
return keypos;
|
|
|
|
}
|