mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-2235 .res 1.1 adds indexes[] for friendly reading and swapping
X-SVN-Rev: 13182
This commit is contained in:
parent
5ed52c5047
commit
e93e5a99cd
2 changed files with 56 additions and 16 deletions
|
@ -821,7 +821,7 @@ ures_swap(const UDataSwapper *ds,
|
|||
TempTable tempTable;
|
||||
|
||||
/* the following integers count Resource item offsets (4 bytes each), not bytes */
|
||||
int32_t bundleLength, bottom, top;
|
||||
int32_t bundleLength, stringsBottom, bottom, top;
|
||||
|
||||
/* udata_swapDataHeader checks the arguments */
|
||||
headerSize=udata_swapDataHeader(ds, inData, length, outData, pErrorCode);
|
||||
|
@ -851,7 +851,11 @@ ures_swap(const UDataSwapper *ds,
|
|||
bundleLength=-1;
|
||||
} else {
|
||||
bundleLength=(length-headerSize)/4;
|
||||
if(bundleLength<1) {
|
||||
|
||||
/* formatVersion 1.1 must have a root item and at least 5 indexes */
|
||||
if( bundleLength<
|
||||
(pInfo->formatVersion[1]==0 ? 1 : 1+5)
|
||||
) {
|
||||
udata_printError(ds, "ures_swap(): too few bytes (%d after header) for a resource bundle\n",
|
||||
length-headerSize);
|
||||
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
||||
|
@ -859,18 +863,32 @@ ures_swap(const UDataSwapper *ds,
|
|||
}
|
||||
}
|
||||
|
||||
/* preflight to get the bottom, top and maxTableLength values */
|
||||
inBundle=(const Resource *)((const char *)inData+headerSize);
|
||||
bottom=0x7fffffff;
|
||||
top=maxTableLength=0;
|
||||
rootRes=udata_readInt32(ds, *inBundle);
|
||||
ures_preflightResource(ds, inBundle, bundleLength, rootRes,
|
||||
&bottom, &top, &maxTableLength,
|
||||
pErrorCode);
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
udata_printError(ds, "ures_preflightResource(root res=%08x) failed - %s\n",
|
||||
rootRes, u_errorName(*pErrorCode));
|
||||
return 0;
|
||||
rootRes=ds->readUInt32(*inBundle);
|
||||
|
||||
if(pInfo->formatVersion[1]==0) {
|
||||
/* preflight to get the bottom, top and maxTableLength values */
|
||||
stringsBottom=1; /* just past root */
|
||||
bottom=0x7fffffff;
|
||||
top=maxTableLength=0;
|
||||
ures_preflightResource(ds, inBundle, bundleLength, rootRes,
|
||||
&bottom, &top, &maxTableLength,
|
||||
pErrorCode);
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
udata_printError(ds, "ures_preflightResource(root res=%08x) failed - %s\n",
|
||||
rootRes, u_errorName(*pErrorCode));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* formatVersion 1.1 adds the indexes[] array */
|
||||
const int32_t *inIndexes;
|
||||
|
||||
inIndexes=(const int32_t *)(inBundle+1);
|
||||
|
||||
stringsBottom=1+udata_readInt32(ds, inIndexes[URES_INDEX_LENGTH]);
|
||||
bottom=udata_readInt32(ds, inIndexes[URES_INDEX_STRINGS_TOP]);
|
||||
top=udata_readInt32(ds, inIndexes[URES_INDEX_BUNDLE_TOP]);
|
||||
maxTableLength=udata_readInt32(ds, inIndexes[URES_INDEX_MAX_TABLE_LENGTH]);
|
||||
}
|
||||
|
||||
if(length>=0) {
|
||||
|
@ -882,7 +900,8 @@ ures_swap(const UDataSwapper *ds,
|
|||
}
|
||||
|
||||
/* swap the key strings, but not the padding bytes (0xaa) after the last string and its NUL */
|
||||
udata_swapInvStringBlock(ds, inBundle+1, 4*(bottom-1), outBundle+1, pErrorCode);
|
||||
udata_swapInvStringBlock(ds, inBundle+stringsBottom, 4*(bottom-stringsBottom),
|
||||
outBundle+stringsBottom, pErrorCode);
|
||||
if(U_FAILURE(*pErrorCode)) {
|
||||
udata_printError(ds, "ures_swap().udata_swapInvStringBlock(keys[%d]) failed - %s\n", 4*(bottom-1),
|
||||
u_errorName(*pErrorCode));
|
||||
|
|
|
@ -39,8 +39,25 @@ typedef uint32_t Resource;
|
|||
#define RES_GET_INT(res) (((int32_t)((res)<<4L))>>4L)
|
||||
#define RES_GET_UINT(res) ((res)&0x0fffffff)
|
||||
|
||||
/* indexes[] value names; indexes are generally 32-bit (Resource) indexes */
|
||||
enum {
|
||||
URES_INDEX_LENGTH, /* [0] contains URES_INDEX_TOP==the length of indexes[] */
|
||||
URES_INDEX_STRINGS_TOP, /* [1] contains the top of the strings, */
|
||||
/* same as the bottom of resources, rounded up */
|
||||
URES_INDEX_RESOURCES_TOP, /* [2] contains the top of all resources */
|
||||
URES_INDEX_BUNDLE_TOP, /* [3] contains the top of the bundle, */
|
||||
/* in case it were ever different from [2] */
|
||||
URES_INDEX_MAX_TABLE_LENGTH,/* [4] max. length of any table */
|
||||
URES_INDEX_TOP
|
||||
};
|
||||
|
||||
/* number of bytes at the beginning of the bundle before the strings start */
|
||||
enum {
|
||||
URES_STRINGS_BOTTOM=(1+URES_INDEX_TOP)*4
|
||||
};
|
||||
|
||||
/*
|
||||
* File format for .res resource bundle files (formatVersion=1)
|
||||
* File format for .res resource bundle files (formatVersion=1.1)
|
||||
*
|
||||
* An ICU4C resource bundle file (.res) is a binary, memory-mappable file
|
||||
* with nested, hierarchical data structures.
|
||||
|
@ -48,7 +65,11 @@ typedef uint32_t Resource;
|
|||
*
|
||||
* Resource root; -- 32-bit Resource item, root item for this bundle's tree;
|
||||
* currently, the root item must be a table resource item
|
||||
* char keys[]; -- up to 65k of characters for key strings,
|
||||
* int32_t indexes[indexes[0]]; -- array of indexes for friendly
|
||||
* reading and swapping; see URES_INDEX_* above
|
||||
* new in formatVersion 1.1
|
||||
* char keys[]; -- up to 65k of characters for key strings
|
||||
* (minus the space for root and indexes[]),
|
||||
* which consist of invariant characters (ASCII/EBCDIC) and are NUL-terminated;
|
||||
* padded to multiple of 4 bytes for 4-alignment of the following data
|
||||
* data; -- data directly and indirectly indexed by the root item;
|
||||
|
|
Loading…
Add table
Reference in a new issue