2005-09-20 18:40:04 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2010-08-15 00:55:54 +00:00
|
|
|
* Copyright (C) 2003-2010, International Business Machines
|
2005-09-20 18:40:04 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: pkgitems.cpp
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2005sep18
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* Companion file to package.cpp. Deals with details of ICU data item formats.
|
|
|
|
* Used for item dependencies.
|
2009-07-17 22:57:26 +00:00
|
|
|
* Contains adapted code from ucnv_bld.c (swapper code from 2003).
|
2005-09-20 18:40:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/ures.h"
|
|
|
|
#include "unicode/putil.h"
|
|
|
|
#include "unicode/udata.h"
|
|
|
|
#include "cstring.h"
|
2009-07-17 22:57:26 +00:00
|
|
|
#include "uinvchar.h"
|
2005-09-20 18:40:04 +00:00
|
|
|
#include "ucmndata.h"
|
|
|
|
#include "udataswp.h"
|
|
|
|
#include "swapimpl.h"
|
|
|
|
#include "toolutil.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "pkg_imp.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* item formats in common */
|
|
|
|
|
|
|
|
#include "uresdata.h"
|
|
|
|
#include "ucnv_bld.h"
|
|
|
|
#include "ucnv_io.h"
|
|
|
|
|
|
|
|
// general definitions ----------------------------------------------------- ***
|
|
|
|
|
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
|
|
|
U_CDECL_BEGIN
|
|
|
|
|
|
|
|
static void U_CALLCONV
|
|
|
|
printError(void *context, const char *fmt, va_list args) {
|
|
|
|
vfprintf((FILE *)context, fmt, args);
|
|
|
|
}
|
|
|
|
|
2005-09-21 00:33:51 +00:00
|
|
|
U_CDECL_END
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
// a data item in native-platform form ------------------------------------- ***
|
|
|
|
|
2009-07-20 22:09:12 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
class NativeItem {
|
|
|
|
public:
|
|
|
|
NativeItem() : pItem(NULL), pInfo(NULL), bytes(NULL), swapped(NULL), length(0) {}
|
|
|
|
NativeItem(const Item *item, UDataSwapFn *swap) : swapped(NULL) {
|
|
|
|
setItem(item, swap);
|
|
|
|
}
|
|
|
|
~NativeItem() {
|
|
|
|
delete [] swapped;
|
|
|
|
}
|
|
|
|
const UDataInfo *getDataInfo() const {
|
|
|
|
return pInfo;
|
|
|
|
}
|
|
|
|
const uint8_t *getBytes() const {
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
int32_t getLength() const {
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setItem(const Item *item, UDataSwapFn *swap) {
|
|
|
|
pItem=item;
|
|
|
|
int32_t infoLength, itemHeaderLength;
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
pInfo=::getDataInfo(pItem->data, pItem->length, infoLength, itemHeaderLength, &errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
exit(errorCode); // should succeed because readFile() checks headers
|
|
|
|
}
|
|
|
|
length=pItem->length-itemHeaderLength;
|
|
|
|
|
|
|
|
if(pInfo->isBigEndian==U_IS_BIG_ENDIAN && pInfo->charsetFamily==U_CHARSET_FAMILY) {
|
|
|
|
bytes=pItem->data+itemHeaderLength;
|
|
|
|
} else {
|
|
|
|
UDataSwapper *ds=udata_openSwapper((UBool)pInfo->isBigEndian, pInfo->charsetFamily, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
fprintf(stderr, "icupkg: udata_openSwapper(\"%s\") failed - %s\n",
|
|
|
|
pItem->name, u_errorName(errorCode));
|
|
|
|
exit(errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->printError=printError;
|
|
|
|
ds->printErrorContext=stderr;
|
|
|
|
|
|
|
|
swapped=new uint8_t[pItem->length];
|
|
|
|
if(swapped==NULL) {
|
|
|
|
fprintf(stderr, "icupkg: unable to allocate memory for swapping \"%s\"\n", pItem->name);
|
|
|
|
exit(U_MEMORY_ALLOCATION_ERROR);
|
|
|
|
}
|
|
|
|
swap(ds, pItem->data, pItem->length, swapped, &errorCode);
|
|
|
|
pInfo=::getDataInfo(swapped, pItem->length, infoLength, itemHeaderLength, &errorCode);
|
|
|
|
bytes=swapped+itemHeaderLength;
|
|
|
|
udata_closeSwapper(ds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Item *pItem;
|
|
|
|
const UDataInfo *pInfo;
|
|
|
|
const uint8_t *bytes;
|
|
|
|
uint8_t *swapped;
|
|
|
|
int32_t length;
|
|
|
|
};
|
|
|
|
|
2009-07-20 22:09:12 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2005-09-20 18:40:04 +00:00
|
|
|
// check a dependency ------------------------------------------------------ ***
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assemble the target item name from the source item name, an ID
|
2005-11-29 00:13:56 +00:00
|
|
|
* and a suffix
|
2005-09-20 18:40:04 +00:00
|
|
|
*/
|
2005-09-21 00:33:51 +00:00
|
|
|
static void
|
2009-07-17 22:57:26 +00:00
|
|
|
makeTargetName(const char *itemName, const char *id, int32_t idLength, const char *suffix,
|
|
|
|
char *target, int32_t capacity,
|
|
|
|
UErrorCode *pErrorCode) {
|
2005-09-20 18:40:04 +00:00
|
|
|
const char *itemID;
|
2005-11-29 00:13:56 +00:00
|
|
|
int32_t treeLength, suffixLength, targetLength;
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2005-11-29 00:13:56 +00:00
|
|
|
// get the item basename
|
2005-09-20 18:40:04 +00:00
|
|
|
itemID=strrchr(itemName, '/');
|
|
|
|
if(itemID!=NULL) {
|
|
|
|
++itemID;
|
|
|
|
} else {
|
|
|
|
itemID=itemName;
|
|
|
|
}
|
|
|
|
|
2005-11-29 00:13:56 +00:00
|
|
|
// build the target string
|
2005-09-20 18:40:04 +00:00
|
|
|
treeLength=(int32_t)(itemID-itemName);
|
2005-11-29 00:13:56 +00:00
|
|
|
if(idLength<0) {
|
|
|
|
idLength=(int32_t)strlen(id);
|
|
|
|
}
|
2005-09-20 18:40:04 +00:00
|
|
|
suffixLength=(int32_t)strlen(suffix);
|
|
|
|
targetLength=treeLength+idLength+suffixLength;
|
2009-07-17 22:57:26 +00:00
|
|
|
if(targetLength>=capacity) {
|
|
|
|
fprintf(stderr, "icupkg/makeTargetName(%s) target item name length %ld too long\n",
|
2006-03-26 00:43:34 +00:00
|
|
|
itemName, (long)targetLength);
|
2005-09-20 18:40:04 +00:00
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(target, itemName, treeLength);
|
|
|
|
memcpy(target+treeLength, id, idLength);
|
|
|
|
memcpy(target+treeLength+idLength, suffix, suffixLength+1); // +1 includes the terminating NUL
|
2009-07-17 22:57:26 +00:00
|
|
|
}
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
static void
|
|
|
|
checkIDSuffix(const char *itemName, const char *id, int32_t idLength, const char *suffix,
|
|
|
|
CheckDependency check, void *context,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
char target[200];
|
|
|
|
makeTargetName(itemName, id, idLength, suffix, target, (int32_t)sizeof(target), pErrorCode);
|
|
|
|
if(U_SUCCESS(*pErrorCode)) {
|
|
|
|
check(context, itemName, target);
|
|
|
|
}
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2005-11-29 00:13:56 +00:00
|
|
|
/* assemble the target item name from the item's parent item name */
|
|
|
|
static void
|
|
|
|
checkParent(const char *itemName, CheckDependency check, void *context,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
const char *itemID, *parent, *parentLimit, *suffix;
|
|
|
|
int32_t parentLength;
|
|
|
|
|
|
|
|
// get the item basename
|
|
|
|
itemID=strrchr(itemName, '/');
|
|
|
|
if(itemID!=NULL) {
|
|
|
|
++itemID;
|
|
|
|
} else {
|
|
|
|
itemID=itemName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the item suffix
|
|
|
|
suffix=strrchr(itemID, '.');
|
|
|
|
if(suffix==NULL) {
|
|
|
|
// empty suffix, point to the end of the string
|
|
|
|
suffix=strrchr(itemID, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the position of the last '_'
|
|
|
|
for(parentLimit=suffix; parentLimit>itemID && *--parentLimit!='_';) {}
|
|
|
|
|
|
|
|
if(parentLimit!=itemID) {
|
|
|
|
// get the parent item name by truncating the last part of this item's name */
|
|
|
|
parent=itemID;
|
|
|
|
parentLength=(int32_t)(parentLimit-itemID);
|
|
|
|
} else {
|
|
|
|
// no '_' in the item name: the parent is the root bundle
|
|
|
|
parent="root";
|
|
|
|
parentLength=4;
|
|
|
|
if((suffix-itemID)==parentLength && 0==memcmp(itemID, parent, parentLength)) {
|
|
|
|
// the item itself is "root", which does not depend on a parent
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkIDSuffix(itemName, parent, parentLength, suffix, check, context, pErrorCode);
|
|
|
|
}
|
|
|
|
|
2005-09-20 18:40:04 +00:00
|
|
|
// get dependencies from resource bundles ---------------------------------- ***
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
static const UChar SLASH=0x2f;
|
2005-09-20 18:40:04 +00:00
|
|
|
|
|
|
|
/*
|
2009-07-17 22:57:26 +00:00
|
|
|
* Check for the alias from the string or alias resource res.
|
2005-09-20 18:40:04 +00:00
|
|
|
*/
|
|
|
|
static void
|
2009-07-17 22:57:26 +00:00
|
|
|
checkAlias(const char *itemName,
|
|
|
|
Resource res, const UChar *alias, int32_t length, UBool useResSuffix,
|
|
|
|
CheckDependency check, void *context, UErrorCode *pErrorCode) {
|
|
|
|
int32_t i;
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
if(!uprv_isInvariantUString(alias, length)) {
|
|
|
|
fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) alias string contains non-invariant characters\n",
|
|
|
|
itemName, res);
|
|
|
|
*pErrorCode=U_INVALID_CHAR_FOUND;
|
2005-09-20 18:40:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
// extract the locale ID from alias strings like
|
|
|
|
// locale_ID/key1/key2/key3
|
|
|
|
// locale_ID
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
// search for the first slash
|
|
|
|
for(i=0; i<length && alias[i]!=SLASH; ++i) {}
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
if(res_getPublicType(res)==URES_ALIAS) {
|
|
|
|
// ignore aliases with an initial slash:
|
|
|
|
// /ICUDATA/... and /pkgname/... go to a different package
|
|
|
|
// /LOCALE/... are for dynamic sideways fallbacks and don't go to a fixed bundle
|
|
|
|
if(i==0) {
|
|
|
|
return; // initial slash ('/')
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
2007-12-13 03:00:29 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
// ignore the intra-bundle path starting from the first slash ('/')
|
|
|
|
length=i;
|
|
|
|
} else /* URES_STRING */ {
|
|
|
|
// the whole string should only consist of a locale ID
|
|
|
|
if(i!=length) {
|
|
|
|
fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) %%ALIAS contains a '/'\n",
|
|
|
|
itemName, res);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
2007-12-13 03:00:29 +00:00
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
}
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
// convert the Unicode string to char *
|
|
|
|
char localeID[32];
|
|
|
|
if(length>=(int32_t)sizeof(localeID)) {
|
|
|
|
fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) alias locale ID length %ld too long\n",
|
|
|
|
itemName, res, (long)length);
|
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
u_UCharsToChars(alias, localeID, length);
|
|
|
|
localeID[length]=0;
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
checkIDSuffix(itemName, localeID, -1, (useResSuffix ? ".res" : ""), check, context, pErrorCode);
|
|
|
|
}
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
/*
|
|
|
|
* Enumerate one resource item and its children and extract dependencies from
|
|
|
|
* aliases.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ures_enumDependencies(const char *itemName,
|
|
|
|
const ResourceData *pResData,
|
|
|
|
Resource res, const char *inKey, const char *parentKey, int32_t depth,
|
|
|
|
CheckDependency check, void *context,
|
2010-08-15 00:55:54 +00:00
|
|
|
Package *pkg,
|
2009-07-17 22:57:26 +00:00
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
switch(res_getPublicType(res)) {
|
|
|
|
case URES_STRING:
|
|
|
|
{
|
|
|
|
UBool useResSuffix = TRUE;
|
|
|
|
// Check for %%ALIAS
|
|
|
|
if(depth==1 && inKey!=NULL) {
|
|
|
|
if(0!=strcmp(inKey, "%%ALIAS")) {
|
|
|
|
break;
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
// Check for %%DEPENDENCY
|
|
|
|
else if(depth==2 && parentKey!=NULL) {
|
|
|
|
if(0!=strcmp(parentKey, "%%DEPENDENCY")) {
|
|
|
|
break;
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
useResSuffix = FALSE;
|
2005-09-20 18:40:04 +00:00
|
|
|
} else {
|
2009-07-17 22:57:26 +00:00
|
|
|
// we ignore all other strings
|
|
|
|
break;
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
int32_t length;
|
|
|
|
const UChar *alias=res_getString(pResData, res, &length);
|
|
|
|
checkAlias(itemName, res, alias, length, useResSuffix, check, context, pErrorCode);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case URES_ALIAS:
|
|
|
|
{
|
|
|
|
int32_t length;
|
|
|
|
const UChar *alias=res_getAlias(pResData, res, &length);
|
|
|
|
checkAlias(itemName, res, alias, length, TRUE, check, context, pErrorCode);
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case URES_TABLE:
|
|
|
|
{
|
|
|
|
/* recurse */
|
2009-07-17 22:57:26 +00:00
|
|
|
int32_t count=res_countArrayItems(pResData, res);
|
|
|
|
for(int32_t i=0; i<count; ++i) {
|
|
|
|
const char *itemKey;
|
|
|
|
Resource item=res_getTableItemByIndex(pResData, res, i, &itemKey);
|
2005-09-20 18:40:04 +00:00
|
|
|
ures_enumDependencies(
|
2009-07-17 22:57:26 +00:00
|
|
|
itemName, pResData,
|
|
|
|
item, itemKey,
|
2007-12-13 03:00:29 +00:00
|
|
|
inKey, depth+1,
|
2005-09-20 18:40:04 +00:00
|
|
|
check, context,
|
2010-08-15 00:55:54 +00:00
|
|
|
pkg,
|
2005-09-20 18:40:04 +00:00
|
|
|
pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
2009-07-17 22:57:26 +00:00
|
|
|
fprintf(stderr, "icupkg/ures_enumDependencies(%s table res=%08x)[%d].recurse(%s: %08x) failed\n",
|
|
|
|
itemName, res, i, itemKey, item);
|
2005-09-20 18:40:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case URES_ARRAY:
|
|
|
|
{
|
|
|
|
/* recurse */
|
2009-07-17 22:57:26 +00:00
|
|
|
int32_t count=res_countArrayItems(pResData, res);
|
|
|
|
for(int32_t i=0; i<count; ++i) {
|
|
|
|
Resource item=res_getArrayItem(pResData, res, i);
|
2005-09-20 18:40:04 +00:00
|
|
|
ures_enumDependencies(
|
2009-07-17 22:57:26 +00:00
|
|
|
itemName, pResData,
|
|
|
|
item, NULL,
|
|
|
|
inKey, depth+1,
|
2005-09-20 18:40:04 +00:00
|
|
|
check, context,
|
2010-08-15 00:55:54 +00:00
|
|
|
pkg,
|
2005-09-20 18:40:04 +00:00
|
|
|
pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
2009-07-17 22:57:26 +00:00
|
|
|
fprintf(stderr, "icupkg/ures_enumDependencies(%s array res=%08x)[%d].recurse(%08x) failed\n",
|
|
|
|
itemName, res, i, item);
|
2005-09-20 18:40:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-07-17 22:57:26 +00:00
|
|
|
ures_enumDependencies(const char *itemName, const UDataInfo *pInfo,
|
2005-09-20 18:40:04 +00:00
|
|
|
const uint8_t *inBytes, int32_t length,
|
|
|
|
CheckDependency check, void *context,
|
2010-08-15 00:55:54 +00:00
|
|
|
Package *pkg,
|
2005-09-20 18:40:04 +00:00
|
|
|
UErrorCode *pErrorCode) {
|
2009-07-17 22:57:26 +00:00
|
|
|
ResourceData resData;
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2009-07-17 22:57:26 +00:00
|
|
|
res_read(&resData, pInfo, inBytes, length, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
fprintf(stderr, "icupkg: .res format version %02x.%02x not supported, or bundle malformed\n",
|
|
|
|
pInfo->formatVersion[0], pInfo->formatVersion[1]);
|
2005-09-20 18:40:04 +00:00
|
|
|
exit(U_UNSUPPORTED_ERROR);
|
|
|
|
}
|
|
|
|
|
2005-11-29 00:13:56 +00:00
|
|
|
/*
|
|
|
|
* if the bundle attributes are present and the nofallback flag is not set,
|
|
|
|
* then add the parent bundle as a dependency
|
|
|
|
*/
|
2009-07-17 22:57:26 +00:00
|
|
|
if(pInfo->formatVersion[0]>1 || (pInfo->formatVersion[0]==1 && pInfo->formatVersion[1]>=1)) {
|
|
|
|
if(!resData.noFallback) {
|
|
|
|
/* this bundle participates in locale fallback */
|
|
|
|
checkParent(itemName, check, context, pErrorCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-20 22:09:12 +00:00
|
|
|
U_NAMESPACE_QUALIFIER NativeItem nativePool;
|
2009-07-17 22:57:26 +00:00
|
|
|
|
|
|
|
if(resData.usesPoolBundle) {
|
|
|
|
char poolName[200];
|
|
|
|
makeTargetName(itemName, "pool", 4, ".res", poolName, (int32_t)sizeof(poolName), pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
check(context, itemName, poolName);
|
|
|
|
int32_t index=pkg->findItem(poolName);
|
|
|
|
if(index<0) {
|
|
|
|
// We cannot work with a bundle if its pool resource is missing.
|
|
|
|
// check() already printed a complaint.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO: Cache the native version in the Item itself.
|
|
|
|
nativePool.setItem(pkg->getItem(index), ures_swap);
|
|
|
|
const UDataInfo *poolInfo=nativePool.getDataInfo();
|
|
|
|
if(poolInfo->formatVersion[0]<=1) {
|
|
|
|
fprintf(stderr, "icupkg: %s is not a pool bundle\n", poolName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int32_t *poolIndexes=(const int32_t *)nativePool.getBytes()+1;
|
|
|
|
int32_t poolIndexLength=poolIndexes[URES_INDEX_LENGTH]&0xff;
|
|
|
|
if(!(poolIndexLength>URES_INDEX_POOL_CHECKSUM &&
|
|
|
|
(poolIndexes[URES_INDEX_ATTRIBUTES]&URES_ATT_IS_POOL_BUNDLE))
|
|
|
|
) {
|
|
|
|
fprintf(stderr, "icupkg: %s is not a pool bundle\n", poolName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(resData.pRoot[1+URES_INDEX_POOL_CHECKSUM]==poolIndexes[URES_INDEX_POOL_CHECKSUM]) {
|
|
|
|
resData.poolBundleKeys=(const char *)(poolIndexes+poolIndexLength);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "icupkg: %s has mismatched checksum for %s\n", poolName, itemName);
|
|
|
|
return;
|
2005-11-29 00:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
|
|
|
|
ures_enumDependencies(
|
|
|
|
itemName, &resData,
|
|
|
|
resData.rootRes, NULL, NULL, 0,
|
|
|
|
check, context,
|
2010-08-15 00:55:54 +00:00
|
|
|
pkg,
|
2009-07-17 22:57:26 +00:00
|
|
|
pErrorCode);
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get dependencies from conversion tables --------------------------------- ***
|
|
|
|
|
|
|
|
/* code adapted from ucnv_swap() */
|
|
|
|
static void
|
|
|
|
ucnv_enumDependencies(const UDataSwapper *ds,
|
|
|
|
const char *itemName, const UDataInfo *pInfo,
|
|
|
|
const uint8_t *inBytes, int32_t length,
|
|
|
|
CheckDependency check, void *context,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
uint32_t staticDataSize;
|
|
|
|
|
|
|
|
const UConverterStaticData *inStaticData;
|
|
|
|
|
|
|
|
const _MBCSHeader *inMBCSHeader;
|
|
|
|
uint8_t outputType;
|
|
|
|
|
|
|
|
/* check format version */
|
|
|
|
if(!(
|
|
|
|
pInfo->formatVersion[0]==6 &&
|
|
|
|
pInfo->formatVersion[1]>=2
|
|
|
|
)) {
|
|
|
|
fprintf(stderr, "icupkg/ucnv_enumDependencies(): .cnv format version %02x.%02x not supported\n",
|
|
|
|
pInfo->formatVersion[0], pInfo->formatVersion[1]);
|
|
|
|
exit(U_UNSUPPORTED_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the initial UConverterStaticData structure after the UDataInfo header */
|
|
|
|
inStaticData=(const UConverterStaticData *)inBytes;
|
|
|
|
|
2006-03-22 08:17:49 +00:00
|
|
|
if( length<(int32_t)sizeof(UConverterStaticData) ||
|
2005-09-20 18:40:04 +00:00
|
|
|
(uint32_t)length<(staticDataSize=ds->readUInt32(inStaticData->structSize))
|
|
|
|
) {
|
|
|
|
udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after header) for an ICU .cnv conversion table\n",
|
|
|
|
length);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inBytes+=staticDataSize;
|
|
|
|
length-=(int32_t)staticDataSize;
|
|
|
|
|
|
|
|
/* check for supported conversionType values */
|
|
|
|
if(inStaticData->conversionType==UCNV_MBCS) {
|
|
|
|
/* MBCS data */
|
2007-10-25 17:05:36 +00:00
|
|
|
uint32_t mbcsHeaderLength, mbcsHeaderFlags, mbcsHeaderOptions;
|
2005-09-20 18:40:04 +00:00
|
|
|
int32_t extOffset;
|
|
|
|
|
|
|
|
inMBCSHeader=(const _MBCSHeader *)inBytes;
|
|
|
|
|
2006-03-22 08:17:49 +00:00
|
|
|
if(length<(int32_t)sizeof(_MBCSHeader)) {
|
2005-09-20 18:40:04 +00:00
|
|
|
udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table\n",
|
|
|
|
length);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2007-10-25 17:05:36 +00:00
|
|
|
if(inMBCSHeader->version[0]==4 && inMBCSHeader->version[1]>=1) {
|
|
|
|
mbcsHeaderLength=MBCS_HEADER_V4_LENGTH;
|
|
|
|
} else if(inMBCSHeader->version[0]==5 && inMBCSHeader->version[1]>=3 &&
|
|
|
|
((mbcsHeaderOptions=ds->readUInt32(inMBCSHeader->options))&
|
|
|
|
MBCS_OPT_UNKNOWN_INCOMPATIBLE_MASK)==0
|
|
|
|
) {
|
|
|
|
mbcsHeaderLength=mbcsHeaderOptions&MBCS_OPT_LENGTH_MASK;
|
|
|
|
} else {
|
2005-09-20 18:40:04 +00:00
|
|
|
udata_printError(ds, "icupkg/ucnv_enumDependencies(): unsupported _MBCSHeader.version %d.%d\n",
|
|
|
|
inMBCSHeader->version[0], inMBCSHeader->version[1]);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mbcsHeaderFlags=ds->readUInt32(inMBCSHeader->flags);
|
|
|
|
extOffset=(int32_t)(mbcsHeaderFlags>>8);
|
|
|
|
outputType=(uint8_t)mbcsHeaderFlags;
|
|
|
|
|
|
|
|
if(outputType==MBCS_OUTPUT_EXT_ONLY) {
|
|
|
|
/*
|
|
|
|
* extension-only file,
|
|
|
|
* contains a base name instead of normal base table data
|
|
|
|
*/
|
|
|
|
char baseName[32];
|
|
|
|
int32_t baseNameLength;
|
|
|
|
|
|
|
|
/* there is extension data after the base data, see ucnv_ext.h */
|
|
|
|
if(length<(extOffset+UCNV_EXT_INDEXES_MIN_LENGTH*4)) {
|
|
|
|
udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table with extension data\n",
|
|
|
|
length);
|
|
|
|
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* swap the base name, between the header and the extension data */
|
2007-10-25 17:05:36 +00:00
|
|
|
const char *inBaseName=(const char *)inBytes+mbcsHeaderLength*4;
|
|
|
|
baseNameLength=(int32_t)strlen(inBaseName);
|
2005-09-20 18:40:04 +00:00
|
|
|
if(baseNameLength>=(int32_t)sizeof(baseName)) {
|
|
|
|
udata_printError(ds, "icupkg/ucnv_enumDependencies(%s): base name length %ld too long\n",
|
|
|
|
itemName, baseNameLength);
|
|
|
|
*pErrorCode=U_UNSUPPORTED_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2007-10-25 17:05:36 +00:00
|
|
|
ds->swapInvChars(ds, inBaseName, baseNameLength+1, baseName, pErrorCode);
|
2005-09-20 18:40:04 +00:00
|
|
|
|
2005-11-29 00:13:56 +00:00
|
|
|
checkIDSuffix(itemName, baseName, -1, ".cnv", check, context, pErrorCode);
|
2005-09-20 18:40:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ICU data formats -------------------------------------------------------- ***
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
uint8_t dataFormat[4];
|
|
|
|
} dataFormats[]={
|
|
|
|
{ { 0x52, 0x65, 0x73, 0x42 } }, /* dataFormat="ResB" */
|
|
|
|
{ { 0x63, 0x6e, 0x76, 0x74 } }, /* dataFormat="cnvt" */
|
|
|
|
{ { 0x43, 0x76, 0x41, 0x6c } } /* dataFormat="CvAl" */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FMT_RES,
|
|
|
|
FMT_CNV,
|
|
|
|
FMT_ALIAS,
|
|
|
|
FMT_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
static int32_t
|
|
|
|
getDataFormat(const uint8_t dataFormat[4]) {
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for(i=0; i<FMT_COUNT; ++i) {
|
|
|
|
if(0==memcmp(dataFormats[i].dataFormat, dataFormat, 4)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enumerate dependencies of a package item -------------------------------- ***
|
|
|
|
|
2005-09-20 22:29:20 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2005-09-20 18:40:04 +00:00
|
|
|
void
|
2007-04-27 19:12:15 +00:00
|
|
|
Package::enumDependencies(Item *pItem, void *context, CheckDependency check) {
|
2009-07-17 22:57:26 +00:00
|
|
|
int32_t infoLength, itemHeaderLength;
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
const UDataInfo *pInfo=getDataInfo(pItem->data, pItem->length, infoLength, itemHeaderLength, &errorCode);
|
2005-09-20 18:40:04 +00:00
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
return; // should not occur because readFile() checks headers
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the data format and call the corresponding function, if any
|
2009-07-17 22:57:26 +00:00
|
|
|
int32_t format=getDataFormat(pInfo->dataFormat);
|
2005-09-20 18:40:04 +00:00
|
|
|
if(format>=0) {
|
|
|
|
switch(format) {
|
|
|
|
case FMT_RES:
|
2009-07-17 22:57:26 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Swap the resource bundle (if necessary) so that we can use
|
|
|
|
* the normal runtime uresdata.c code to read it.
|
|
|
|
* We do not want to duplicate that code, especially not together with on-the-fly swapping.
|
|
|
|
*/
|
|
|
|
NativeItem nrb(pItem, ures_swap);
|
2010-08-15 00:55:54 +00:00
|
|
|
ures_enumDependencies(pItem->name, nrb.getDataInfo(), nrb.getBytes(), nrb.getLength(), check, context, this, &errorCode);
|
2009-07-17 22:57:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-09-20 18:40:04 +00:00
|
|
|
case FMT_CNV:
|
2009-07-17 22:57:26 +00:00
|
|
|
{
|
|
|
|
// TODO: share/cache swappers
|
|
|
|
UDataSwapper *ds=udata_openSwapper(
|
|
|
|
(UBool)pInfo->isBigEndian, pInfo->charsetFamily,
|
|
|
|
U_IS_BIG_ENDIAN, U_CHARSET_FAMILY,
|
|
|
|
&errorCode);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
fprintf(stderr, "icupkg: udata_openSwapper(\"%s\") failed - %s\n",
|
|
|
|
pItem->name, u_errorName(errorCode));
|
|
|
|
exit(errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds->printError=printError;
|
|
|
|
ds->printErrorContext=stderr;
|
|
|
|
|
|
|
|
const uint8_t *inBytes=pItem->data+itemHeaderLength;
|
|
|
|
int32_t length=pItem->length-itemHeaderLength;
|
|
|
|
|
|
|
|
ucnv_enumDependencies(ds, pItem->name, pInfo, inBytes, length, check, context, &errorCode);
|
|
|
|
udata_closeSwapper(ds);
|
|
|
|
break;
|
|
|
|
}
|
2005-09-20 18:40:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
exit(errorCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 22:57:26 +00:00
|
|
|
|
2005-09-20 22:29:20 +00:00
|
|
|
U_NAMESPACE_END
|