1999-12-09 18:35:11 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
|
|
|
* *
|
2003-08-08 23:39:34 +00:00
|
|
|
* Copyright (C) 1999-2003, International Business Machines *
|
2001-03-21 20:44:20 +00:00
|
|
|
* Corporation and others. All Rights Reserved. *
|
|
|
|
* *
|
|
|
|
******************************************************************************
|
1999-12-09 18:35:11 +00:00
|
|
|
* file name: uresdata.h
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 1999dec08
|
|
|
|
* created by: Markus W. Scherer
|
2002-06-24 20:58:17 +00:00
|
|
|
* 06/24/02 weiv Added support for resource sharing
|
1999-12-09 18:35:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RESDATA_H__
|
|
|
|
#define __RESDATA_H__
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/udata.h"
|
2003-08-13 20:40:12 +00:00
|
|
|
#include "udataswp.h"
|
1999-12-09 18:35:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A Resource is a 32-bit value that has 2 bit fields:
|
|
|
|
* 31..28 4-bit type, see enum below
|
|
|
|
* 27..0 28-bit four-byte-offset or value according to the type
|
|
|
|
*/
|
|
|
|
typedef uint32_t Resource;
|
|
|
|
|
|
|
|
#define RES_BOGUS 0xffffffff
|
|
|
|
|
|
|
|
#define RES_GET_TYPE(res) ((res)>>28UL)
|
2000-05-18 21:25:51 +00:00
|
|
|
#define RES_GET_OFFSET(res) ((res)&0x0fffffff)
|
1999-12-09 18:35:11 +00:00
|
|
|
#define RES_GET_POINTER(pRoot, res) ((pRoot)+RES_GET_OFFSET(res))
|
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
/* get signed and unsigned integer values directly from the Resource handle */
|
|
|
|
#define RES_GET_INT(res) (((int32_t)((res)<<4L))>>4L)
|
|
|
|
#define RES_GET_UINT(res) ((res)&0x0fffffff)
|
|
|
|
|
1999-12-09 18:35:11 +00:00
|
|
|
/*
|
2002-12-16 22:43:08 +00:00
|
|
|
* File format for .res resource bundle files (formatVersion=1)
|
|
|
|
*
|
|
|
|
* An ICU4C resource bundle file (.res) is a binary, memory-mappable file
|
|
|
|
* with nested, hierarchical data structures.
|
|
|
|
* It physically contains the following:
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
* 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;
|
|
|
|
* the structure is determined by walking the tree
|
|
|
|
*
|
|
|
|
* Each resource bundle item has a 32-bit Resource handle (see typedef above)
|
|
|
|
* which contains the item type number in its upper 4 bits (31..28) and either
|
|
|
|
* an offset or a direct value in its lower 28 bits (27..0).
|
|
|
|
* The order of items is undefined and only determined by walking the tree.
|
|
|
|
* Leaves of the tree may be stored first or last or anywhere in between,
|
|
|
|
* and it is in theory possible to have unreferenced holes in the file.
|
|
|
|
*
|
|
|
|
* Direct values:
|
|
|
|
* - Empty Unicode strings have an offset value of 0 in the Resource handle itself.
|
|
|
|
* - Integer values are 28-bit values stored in the Resource handle itself;
|
|
|
|
* the interpretation of unsigned vs. signed integers is up to the application.
|
|
|
|
*
|
|
|
|
* All other types and values use 28-bit offsets to point to the item's data.
|
|
|
|
* The offset is an index to the first 32-bit word of the value, relative to the
|
|
|
|
* start of the resource data (i.e., the root item handle is at offset 0).
|
|
|
|
* To get byte offsets, the offset is multiplied by 4 (or shifted left by 2 bits).
|
|
|
|
* All resource item values are 4-aligned.
|
|
|
|
*
|
|
|
|
* The structures (memory layouts) for the values for each item type are listed
|
|
|
|
* in the table above.
|
|
|
|
*
|
|
|
|
* Nested, hierarchical structures: -------------
|
|
|
|
*
|
|
|
|
* Table items contain key-value pairs where the keys are 16-bit offsets to char * key strings.
|
|
|
|
* Key string offsets are also relative to the start of the resource data (of the root handle),
|
|
|
|
* i.e., the first string has an offset of 4 (after the 4-byte root handle).
|
|
|
|
*
|
|
|
|
* The values of these pairs are Resource handles.
|
|
|
|
*
|
|
|
|
* Array items are simple vectors of Resource handles.
|
|
|
|
*
|
|
|
|
* An alias item is special (and new in ICU 2.4): --------------
|
|
|
|
*
|
|
|
|
* Its memory layout is just like for a UnicodeString, but at runtime it resolves to
|
|
|
|
* another resource bundle's item according to the path in the string.
|
|
|
|
* This is used to share items across bundles that are in different lookup/fallback
|
|
|
|
* chains (e.g., large collation data among zh_TW and zh_HK).
|
|
|
|
* This saves space (for large items) and maintenance effort (less duplication of data).
|
|
|
|
*
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*
|
1999-12-09 18:35:11 +00:00
|
|
|
* Resource types:
|
2002-12-16 22:43:08 +00:00
|
|
|
*
|
1999-12-09 18:35:11 +00:00
|
|
|
* Most resources have their values stored at four-byte offsets from the start
|
|
|
|
* of the resource data. These values are at least 4-aligned.
|
|
|
|
* Some resource values are stored directly in the offset field of the Resource itself.
|
2002-12-16 22:43:08 +00:00
|
|
|
* See UResType in unicode/ures.h for enumeration constants for Resource types.
|
1999-12-09 18:35:11 +00:00
|
|
|
*
|
|
|
|
* Type Name Memory layout of values
|
|
|
|
* (in parentheses: scalar, non-offset values)
|
|
|
|
*
|
|
|
|
* 0 Unicode String: int32_t length, UChar[length], (UChar)0, (padding)
|
|
|
|
* or (empty string ("") if offset==0)
|
2000-05-15 18:39:17 +00:00
|
|
|
* 1 Binary: int32_t length, uint8_t[length], (padding)
|
2000-05-18 21:25:51 +00:00
|
|
|
* - this value should be 32-aligned -
|
2000-05-15 18:39:17 +00:00
|
|
|
* 2 Table: uint16_t count, uint16_t keyStringOffsets[count], (uint16_t padding), Resource[count]
|
2002-12-16 22:43:08 +00:00
|
|
|
* 3 Alias: (physically same value layout as string, new in ICU 2.4)
|
1999-12-09 18:35:11 +00:00
|
|
|
*
|
|
|
|
* 7 Integer: (28-bit offset is integer value)
|
2000-05-15 18:39:17 +00:00
|
|
|
* 8 Array: int32_t count, Resource[count]
|
1999-12-09 18:35:11 +00:00
|
|
|
*
|
2000-05-15 18:39:17 +00:00
|
|
|
* 14 Integer Vector: int32_t length, int32_t[length]
|
|
|
|
* 15 Reserved: This value denotes special purpose resources and is for internal use.
|
2002-12-16 22:43:08 +00:00
|
|
|
*
|
|
|
|
* Note that there are 3 types with data vector values:
|
|
|
|
* - Vectors of 8-bit bytes stored as type Binary.
|
|
|
|
* - Vectors of 16-bit words stored as type Unicode String
|
|
|
|
* (no value restrictions, all values 0..ffff allowed!).
|
|
|
|
* - Vectors of 32-bit words stored as type Integer Vector.
|
1999-12-09 18:35:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure for a single, memory-mapped ResourceBundle.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
UDataMemory *data;
|
|
|
|
Resource *pRoot;
|
|
|
|
Resource rootRes;
|
|
|
|
} ResourceData;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load a resource bundle file.
|
|
|
|
* The ResourceData structure must be allocated externally.
|
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
U_CFUNC UBool
|
1999-12-09 18:35:11 +00:00
|
|
|
res_load(ResourceData *pResData,
|
|
|
|
const char *path, const char *name, UErrorCode *errorCode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release a resource bundle file.
|
|
|
|
* This does not release the ResourceData structure itself.
|
|
|
|
*/
|
|
|
|
U_CFUNC void
|
|
|
|
res_unload(ResourceData *pResData);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a pointer to a zero-terminated, const UChar* string
|
|
|
|
* and set its length in *pLength.
|
|
|
|
* Returns NULL if not found.
|
|
|
|
*/
|
|
|
|
U_CFUNC const UChar *
|
2000-05-15 18:39:17 +00:00
|
|
|
res_getString(const ResourceData *pResData, const Resource res, int32_t *pLength);
|
1999-12-09 18:35:11 +00:00
|
|
|
|
2002-06-14 06:03:08 +00:00
|
|
|
U_CFUNC const UChar *
|
|
|
|
res_getAlias(const ResourceData *pResData, const Resource res, int32_t *pLength);
|
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
U_CFUNC const uint8_t *
|
|
|
|
res_getBinary(const ResourceData *pResData, const Resource res, int32_t *pLength);
|
|
|
|
|
2001-08-01 17:08:07 +00:00
|
|
|
U_CFUNC const int32_t *
|
|
|
|
res_getIntVector(const ResourceData *pResData, const Resource res, int32_t *pLength);
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CFUNC Resource
|
|
|
|
res_getResource(const ResourceData *pResData, const char *key);
|
1999-12-09 18:35:11 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
U_CFUNC int32_t
|
|
|
|
res_countArrayItems(const ResourceData *pResData, const Resource res);
|
|
|
|
|
|
|
|
U_CFUNC int32_t res_getTableSize(const ResourceData *pResData, Resource table);
|
|
|
|
|
2002-06-24 20:58:17 +00:00
|
|
|
U_CFUNC Resource res_getArrayItem(const ResourceData *pResData, Resource array, const int32_t indexS);
|
|
|
|
U_CFUNC Resource res_getTableItemByIndex(const ResourceData *pResData, Resource table, int32_t indexS, const char ** key);
|
|
|
|
U_CFUNC Resource res_getTableItemByKey(const ResourceData *pResData, Resource table, int32_t *indexS, const char* * key);
|
2002-07-30 20:49:30 +00:00
|
|
|
U_CFUNC Resource res_findResource(const ResourceData *pResData, Resource r, const char** path, const char** key);
|
1999-12-09 18:35:11 +00:00
|
|
|
|
2003-08-08 23:39:34 +00:00
|
|
|
/**
|
|
|
|
* Swap an ICU resource bundle. See udataswp.h.
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
ures_swap(const UDataSwapper *ds,
|
|
|
|
const void *inData, int32_t length, void *outData,
|
|
|
|
UErrorCode *pErrorCode);
|
|
|
|
|
1999-12-09 18:35:11 +00:00
|
|
|
#endif
|