2000-05-15 19:29:11 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2006-03-30 05:36:01 +00:00
|
|
|
* Copyright (C) 2000-2006, International Business Machines
|
2000-05-15 19:29:11 +00:00
|
|
|
* 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>
|
2003-09-24 00:26:23 +00:00
|
|
|
#include <stdio.h>
|
2000-05-15 19:29:11 +00:00
|
|
|
#include "reslist.h"
|
|
|
|
#include "unewdata.h"
|
|
|
|
#include "unicode/ures.h"
|
2004-09-23 00:24:36 +00:00
|
|
|
#include "unicode/putil.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" */
|
2005-11-28 23:59:33 +00:00
|
|
|
{1, 2, 0, 0}, /* formatVersion */
|
2002-04-30 19:07:18 +00:00
|
|
|
{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) {
|
2003-04-16 23:52:32 +00:00
|
|
|
if (current->fType == URES_INT) {
|
2001-07-11 20:31:32 +00:00
|
|
|
resources[i] = (current->fType << 28) | (current->u.fIntValue.fValue & 0xFFFFFFF);
|
2003-04-16 23:52:32 +00:00
|
|
|
} else if (current->fType == URES_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;
|
2003-09-24 17:52:44 +00:00
|
|
|
uint16_t *keys16 = NULL;
|
|
|
|
int32_t *keys32 = 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) {
|
2003-09-24 17:52:44 +00:00
|
|
|
if(res->fType == URES_TABLE) {
|
|
|
|
keys16 = (uint16_t *) uprv_malloc(sizeof(uint16_t) * res->u.fTable.fCount);
|
|
|
|
if (keys16 == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
keys32 = (int32_t *) uprv_malloc(sizeof(int32_t) * res->u.fTable.fCount);
|
|
|
|
if (keys32 == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2003-09-24 17:52:44 +00:00
|
|
|
uprv_free(keys16);
|
|
|
|
uprv_free(keys32);
|
2000-05-15 19:29:11 +00:00
|
|
|
*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);
|
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
/* where the key is */
|
|
|
|
if(res->fType == URES_TABLE) {
|
|
|
|
keys16[i] = (uint16_t) current->fKey;
|
|
|
|
} else {
|
|
|
|
keys32[i] = current->fKey;
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2003-04-16 23:52:32 +00:00
|
|
|
if (current->fType == URES_INT) {
|
2001-07-11 20:31:32 +00:00
|
|
|
resources[i] = (current->fType << 28) | (current->u.fIntValue.fValue & 0xFFFFFFF);
|
2003-04-16 23:52:32 +00:00
|
|
|
} else if (current->fType == URES_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;
|
|
|
|
}
|
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
if(res->fType == URES_TABLE) {
|
|
|
|
udata_write16(mem, (uint16_t)res->u.fTable.fCount);
|
|
|
|
|
|
|
|
udata_writeBlock(mem, keys16, sizeof(uint16_t) * res->u.fTable.fCount);
|
|
|
|
udata_writePadding(mem, pad);
|
|
|
|
} else {
|
|
|
|
udata_write32(mem, res->u.fTable.fCount);
|
|
|
|
|
|
|
|
udata_writeBlock(mem, keys32, sizeof(int32_t) * res->u.fTable.fCount);
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
|
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
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
uprv_free(keys16);
|
|
|
|
uprv_free(keys32);
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(resources);
|
2001-07-11 20:31:32 +00:00
|
|
|
} else {
|
|
|
|
/* table is empty */
|
2003-09-24 17:52:44 +00:00
|
|
|
if(res->fType == URES_TABLE) {
|
|
|
|
udata_write16(mem, 0);
|
|
|
|
udata_writePadding(mem, pad);
|
|
|
|
} else {
|
|
|
|
udata_write32(mem, 0);
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_STRING:
|
2001-07-11 20:31:32 +00:00
|
|
|
return string_write (mem, res, usedOffset, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ALIAS:
|
2002-06-14 06:01:13 +00:00
|
|
|
return alias_write (mem, res, usedOffset, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_INT_VECTOR:
|
2001-07-11 20:31:32 +00:00
|
|
|
return intvector_write (mem, res, usedOffset, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_BINARY:
|
2001-07-11 20:31:32 +00:00
|
|
|
return bin_write (mem, res, usedOffset, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_INT:
|
2001-07-11 20:31:32 +00:00
|
|
|
return int_write (mem, res, usedOffset, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ARRAY:
|
2001-07-11 20:31:32 +00:00
|
|
|
return array_write (mem, res, usedOffset, status);
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_TABLE:
|
2003-09-24 17:52:44 +00:00
|
|
|
case URES_TABLE32:
|
2001-07-11 20:31:32 +00:00
|
|
|
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;
|
2003-09-24 00:26:23 +00:00
|
|
|
uint32_t top, size;
|
2002-07-17 03:56:50 +00:00
|
|
|
char dataName[1024];
|
2003-09-24 00:26:23 +00:00
|
|
|
int32_t indexes[URES_INDEX_TOP];
|
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);
|
2003-12-07 21:41:09 +00:00
|
|
|
off += (int32_t)uprv_strlen(outputPkg);
|
2002-07-17 03:56:50 +00:00
|
|
|
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);
|
2002-12-04 23:31:10 +00:00
|
|
|
if(U_FAILURE(*status)){
|
2002-12-04 02:38:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
pad = calcPadding(bundle->fKeyPoint);
|
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
usedOffset = bundle->fKeyPoint + pad ; /* top of the strings */
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
/* we're gonna put the main table at the end */
|
|
|
|
top = usedOffset + bundle->fRoot->u.fTable.fChildrenSize;
|
|
|
|
root = (top) >> 2 | (bundle->fRoot->fType << 28);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
/* write the root item */
|
2000-05-15 19:29:11 +00:00
|
|
|
udata_write32(mem, root);
|
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
/* add to top the size of the root item */
|
|
|
|
top += bundle->fRoot->fSize;
|
|
|
|
top += calcPadding(top);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* formatVersion 1.1 (ICU 2.8):
|
|
|
|
* write int32_t indexes[] after root and before the strings
|
|
|
|
* to make it easier to parse resource bundles in icuswap or from Java etc.
|
|
|
|
*/
|
2005-11-28 23:59:33 +00:00
|
|
|
uprv_memset(indexes, 0, sizeof(indexes));
|
2003-09-24 00:26:23 +00:00
|
|
|
indexes[URES_INDEX_LENGTH]= URES_INDEX_TOP;
|
|
|
|
indexes[URES_INDEX_STRINGS_TOP]= (int32_t)(usedOffset>>2);
|
|
|
|
indexes[URES_INDEX_RESOURCES_TOP]= (int32_t)(top>>2);
|
|
|
|
indexes[URES_INDEX_BUNDLE_TOP]= indexes[URES_INDEX_RESOURCES_TOP];
|
|
|
|
indexes[URES_INDEX_MAX_TABLE_LENGTH]= bundle->fMaxTableLength;
|
|
|
|
|
2005-11-28 23:59:33 +00:00
|
|
|
/*
|
|
|
|
* formatVersion 1.2 (ICU 3.6):
|
|
|
|
* write indexes[URES_INDEX_ATTRIBUTES] with URES_ATT_NO_FALLBACK set or not set
|
|
|
|
* the memset() above initialized all indexes[] to 0
|
|
|
|
*/
|
|
|
|
if(bundle->noFallback) {
|
|
|
|
indexes[URES_INDEX_ATTRIBUTES]=URES_ATT_NO_FALLBACK;
|
|
|
|
}
|
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
/* write the indexes[] */
|
|
|
|
udata_writeBlock(mem, indexes, sizeof(indexes));
|
|
|
|
|
|
|
|
/* write the table key strings */
|
|
|
|
udata_writeBlock(mem, bundle->fKeys+URES_STRINGS_BOTTOM,
|
|
|
|
bundle->fKeyPoint-URES_STRINGS_BOTTOM);
|
|
|
|
|
|
|
|
/* write the padding bytes after the table key strings */
|
2000-05-15 19:29:11 +00:00
|
|
|
udata_writePadding(mem, pad);
|
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
/* write all of the bundle contents: the root item and its children */
|
2000-05-15 19:29:11 +00:00
|
|
|
usedOffset = res_write(mem, bundle->fRoot, usedOffset, status);
|
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
size = udata_finish(mem, status);
|
|
|
|
if(top != size) {
|
|
|
|
fprintf(stderr, "genrb error: wrote %u bytes but counted %u\n",
|
2004-05-19 04:01:34 +00:00
|
|
|
(int)size, (int)top);
|
2003-09-24 00:26:23 +00:00
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Opening Functions */
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource* res_open(const struct UString* comment, 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;
|
|
|
|
}
|
2003-09-24 17:52:44 +00:00
|
|
|
uprv_memset(res, 0, sizeof(struct SResource));
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
res->fComment = NULL;
|
|
|
|
if(comment != NULL){
|
|
|
|
res->fComment = (struct UString *) uprv_malloc(sizeof(struct UString));
|
|
|
|
if(res->fComment == NULL){
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2006-03-30 05:36:01 +00:00
|
|
|
uprv_free(res);
|
2003-08-26 02:36:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ustr_init(res->fComment);
|
|
|
|
ustr_cpy(res->fComment, comment, status);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
struct SResource* table_open(struct SRBRoot *bundle, char *tag, const struct UString* comment, UErrorCode *status) {
|
|
|
|
|
|
|
|
struct SResource *res = res_open(comment, status);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2003-08-26 02:36:57 +00:00
|
|
|
uprv_free(res->fComment);
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->fNext = NULL;
|
2003-09-24 17:52:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* always open a table not a table32 in case it remains empty -
|
|
|
|
* try to use table32 only when necessary
|
|
|
|
*/
|
|
|
|
res->fType = URES_TABLE;
|
2000-05-15 19:29:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource* array_open(struct SRBRoot *bundle, char *tag, const struct UString* comment, UErrorCode *status) {
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource *res = res_open(comment, 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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-16 23:52:32 +00:00
|
|
|
res->fType = URES_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)) {
|
2003-08-26 02:36:57 +00:00
|
|
|
uprv_free(res->fComment);
|
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;
|
|
|
|
}
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource *string_open(struct SRBRoot *bundle, char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status) {
|
|
|
|
struct SResource *res = res_open(comment, 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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-16 23:52:32 +00:00
|
|
|
res->fType = URES_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)) {
|
2003-08-26 02:36:57 +00:00
|
|
|
uprv_free(res->fComment);
|
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));
|
2002-12-05 02:36:34 +00:00
|
|
|
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 */
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource *alias_open(struct SRBRoot *bundle, char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status) {
|
|
|
|
struct SResource *res = res_open(comment, status);
|
2002-06-14 06:01:13 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-16 23:52:32 +00:00
|
|
|
res->fType = URES_ALIAS;
|
2002-06-14 06:01:13 +00:00
|
|
|
res->fKey = bundle_addtag(bundle, tag, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
2003-08-26 02:36:57 +00:00
|
|
|
uprv_free(res->fComment);
|
2002-06-14 06:01:13 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource* intvector_open(struct SRBRoot *bundle, char *tag, const struct UString* comment, UErrorCode *status) {
|
|
|
|
struct SResource *res = res_open(comment, 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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-16 23:52:32 +00:00
|
|
|
res->fType = URES_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)) {
|
2003-08-26 02:36:57 +00:00
|
|
|
uprv_free(res->fComment);
|
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;
|
|
|
|
}
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource *int_open(struct SRBRoot *bundle, char *tag, int32_t value, const struct UString* comment, UErrorCode *status) {
|
|
|
|
struct SResource *res = res_open(comment, 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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-16 23:52:32 +00:00
|
|
|
res->fType = URES_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)) {
|
2003-08-26 02:36:57 +00:00
|
|
|
uprv_free(res->fComment);
|
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;
|
|
|
|
}
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, const char* fileName, const struct UString* comment, UErrorCode *status) {
|
|
|
|
struct SResource *res = res_open(comment, 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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-16 23:52:32 +00:00
|
|
|
res->fType = URES_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)) {
|
2003-08-26 02:36:57 +00:00
|
|
|
uprv_free(res->fComment);
|
2000-05-15 19:29:11 +00:00
|
|
|
uprv_free(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
res->fNext = NULL;
|
|
|
|
|
|
|
|
res->u.fBinaryValue.fLength = length;
|
2002-10-10 01:05:51 +00:00
|
|
|
res->u.fBinaryValue.fFileName = NULL;
|
|
|
|
if(fileName!=NULL && uprv_strcmp(fileName, "") !=0){
|
2002-12-04 02:38:39 +00:00
|
|
|
res->u.fBinaryValue.fFileName = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(fileName)+1));
|
2002-10-10 01:05:51 +00:00
|
|
|
uprv_strcpy(res->u.fBinaryValue.fFileName,fileName);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
struct SRBRoot *bundle_open(const struct UString* comment, UErrorCode *status) {
|
2000-05-15 19:29:11 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-09-24 00:26:23 +00:00
|
|
|
uprv_memset(bundle, 0, sizeof(struct SRBRoot));
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle->fLocale = NULL;
|
2003-09-24 00:26:23 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle->fKeys = (char *) uprv_malloc(sizeof(char) * KEY_SPACE_SIZE);
|
2003-09-24 17:52:44 +00:00
|
|
|
bundle->fKeysCapacity = KEY_SPACE_SIZE;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
if(comment != NULL){
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
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
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
/* formatVersion 1.1: start fKeyPoint after the root item and indexes[] */
|
|
|
|
bundle->fKeyPoint = URES_STRINGS_BOTTOM;
|
|
|
|
uprv_memset(bundle->fKeys, 0, URES_STRINGS_BOTTOM);
|
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
bundle->fCount = 0;
|
2003-08-26 02:36:57 +00:00
|
|
|
bundle->fRoot = table_open(bundle, NULL, comment, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
if (bundle->fRoot == NULL || U_FAILURE(*status)) {
|
2003-09-24 00:26:23 +00:00
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
*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);
|
|
|
|
}
|
2003-05-20 00:50:45 +00:00
|
|
|
|
|
|
|
table->u.fTable.fFirst = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void array_close(struct SResource *array, UErrorCode *status) {
|
|
|
|
struct SResource *current = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
struct SResource *prev = NULL;
|
2006-04-21 01:15:46 +00:00
|
|
|
|
|
|
|
if(array==NULL){
|
|
|
|
return;
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
current = array->u.fArray.fFirst;
|
2006-04-21 01:15:46 +00:00
|
|
|
|
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);
|
|
|
|
}
|
2003-05-20 00:50:45 +00:00
|
|
|
array->u.fArray.fFirst = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2003-05-20 00:50:45 +00:00
|
|
|
string->u.fString.fChars =NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2003-05-20 00:50:45 +00:00
|
|
|
alias->u.fString.fChars =NULL;
|
2002-06-14 06:01:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2003-05-20 00:50:45 +00:00
|
|
|
intvector->u.fIntVector.fArray =NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2003-05-20 00:50:45 +00:00
|
|
|
binres->u.fBinaryValue.fData = NULL;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_STRING:
|
2000-05-15 19:29:11 +00:00
|
|
|
string_close(res, status);
|
|
|
|
break;
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ALIAS:
|
2002-06-14 06:01:13 +00:00
|
|
|
alias_close(res, status);
|
|
|
|
break;
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_INT_VECTOR:
|
2000-05-15 19:29:11 +00:00
|
|
|
intvector_close(res, status);
|
|
|
|
break;
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_BINARY:
|
2000-05-15 19:29:11 +00:00
|
|
|
bin_close(res, status);
|
|
|
|
break;
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_INT:
|
2000-05-15 19:29:11 +00:00
|
|
|
int_close(res, status);
|
|
|
|
break;
|
2003-04-16 23:52:32 +00:00
|
|
|
case URES_ARRAY:
|
2000-05-15 19:29:11 +00:00
|
|
|
array_close(res, status);
|
|
|
|
break;
|
2003-09-24 17:52:44 +00:00
|
|
|
case URES_TABLE:
|
|
|
|
case URES_TABLE32:
|
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);
|
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
if(table->fType == URES_TABLE && res->fKey > 0xffff) {
|
|
|
|
/* this table straddles the 64k strings boundary, update to a table32 */
|
|
|
|
table->fType = URES_TABLE32;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* increase the size because count and each string offset
|
|
|
|
* increase from uint16_t to int32_t
|
|
|
|
*/
|
|
|
|
table->fSize += (1 + list->fCount) * 2;
|
|
|
|
}
|
|
|
|
|
2000-05-15 19:29:11 +00:00
|
|
|
++(list->fCount);
|
2003-09-24 17:52:44 +00:00
|
|
|
if(list->fCount > (uint32_t)list->fRoot->fMaxTableLength) {
|
2003-09-24 00:26:23 +00:00
|
|
|
list->fRoot->fMaxTableLength = list->fCount;
|
|
|
|
}
|
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
/*
|
|
|
|
* URES_TABLE: 6 bytes = 1 uint16_t key string offset + 1 uint32_t Resource
|
|
|
|
* URES_TABLE32: 8 bytes = 1 int32_t key string offset + 1 uint32_t Resource
|
|
|
|
*/
|
|
|
|
table->fSize += table->fType == URES_TABLE ? 6 : 8;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
table->u.fTable.fChildrenSize += res->fSize + calcPadding(res->fSize);
|
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
if (res->fType == URES_TABLE || res->fType == URES_TABLE32) {
|
2000-05-15 19:29:11 +00:00
|
|
|
table->u.fTable.fChildrenSize += res->u.fTable.fChildrenSize;
|
2003-04-16 23:52:32 +00:00
|
|
|
} else if (res->fType == URES_ARRAY) {
|
2000-05-15 19:29:11 +00:00
|
|
|
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);
|
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
if (res->fType == URES_TABLE || res->fType == URES_TABLE32) {
|
2000-05-15 19:29:11 +00:00
|
|
|
array->u.fArray.fChildrenSize += res->u.fTable.fChildrenSize;
|
2003-04-16 23:52:32 +00:00
|
|
|
} else if (res->fType == URES_ARRAY) {
|
2000-05-15 19:29:11 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-08-26 02:36:57 +00:00
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
int32_t
|
|
|
|
bundle_addtag(struct SRBRoot *bundle, const char *tag, UErrorCode *status) {
|
|
|
|
int32_t keypos, length;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2003-09-24 00:26:23 +00:00
|
|
|
return -1;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (tag == NULL) {
|
2003-09-24 00:26:23 +00:00
|
|
|
/* do not set an error: the root table has a NULL tag */
|
|
|
|
return -1;
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
keypos = bundle->fKeyPoint;
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
bundle->fKeyPoint += length = (int32_t) (uprv_strlen(tag) + 1);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
2003-09-24 17:52:44 +00:00
|
|
|
if (bundle->fKeyPoint >= bundle->fKeysCapacity) {
|
|
|
|
/* overflow - resize the keys buffer */
|
|
|
|
bundle->fKeysCapacity += KEY_SPACE_SIZE;
|
|
|
|
bundle->fKeys = uprv_realloc(bundle->fKeys, bundle->fKeysCapacity);
|
|
|
|
if(bundle->fKeys == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
2000-05-15 19:29:11 +00:00
|
|
|
}
|
|
|
|
|
2003-09-24 00:26:23 +00:00
|
|
|
uprv_memcpy(bundle->fKeys + keypos, tag, length);
|
2000-05-15 19:29:11 +00:00
|
|
|
|
|
|
|
return keypos;
|
|
|
|
}
|