]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/toolutil/pkgitems.cpp
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / pkgitems.cpp
CommitLineData
73c04bcf
A
1/*
2*******************************************************************************
3*
2ca993e8 4* Copyright (C) 2003-2015, International Business Machines
73c04bcf
A
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8* file name: pkgitems.cpp
9* encoding: US-ASCII
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 2005sep18
14* created by: Markus W. Scherer
15*
16* Companion file to package.cpp. Deals with details of ICU data item formats.
17* Used for item dependencies.
729e4ab9 18* Contains adapted code from ucnv_bld.c (swapper code from 2003).
73c04bcf
A
19*/
20
21#include "unicode/utypes.h"
22#include "unicode/ures.h"
23#include "unicode/putil.h"
24#include "unicode/udata.h"
25#include "cstring.h"
729e4ab9 26#include "uinvchar.h"
73c04bcf
A
27#include "ucmndata.h"
28#include "udataswp.h"
29#include "swapimpl.h"
30#include "toolutil.h"
31#include "package.h"
32#include "pkg_imp.h"
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37
38/* item formats in common */
39
40#include "uresdata.h"
41#include "ucnv_bld.h"
42#include "ucnv_io.h"
43
44// general definitions ----------------------------------------------------- ***
45
73c04bcf
A
46U_CDECL_BEGIN
47
48static void U_CALLCONV
49printError(void *context, const char *fmt, va_list args) {
50 vfprintf((FILE *)context, fmt, args);
51}
52
53U_CDECL_END
54
729e4ab9
A
55// a data item in native-platform form ------------------------------------- ***
56
57U_NAMESPACE_BEGIN
58
59class NativeItem {
60public:
61 NativeItem() : pItem(NULL), pInfo(NULL), bytes(NULL), swapped(NULL), length(0) {}
62 NativeItem(const Item *item, UDataSwapFn *swap) : swapped(NULL) {
63 setItem(item, swap);
64 }
65 ~NativeItem() {
66 delete [] swapped;
67 }
68 const UDataInfo *getDataInfo() const {
69 return pInfo;
70 }
71 const uint8_t *getBytes() const {
72 return bytes;
73 }
74 int32_t getLength() const {
75 return length;
76 }
77
78 void setItem(const Item *item, UDataSwapFn *swap) {
79 pItem=item;
80 int32_t infoLength, itemHeaderLength;
81 UErrorCode errorCode=U_ZERO_ERROR;
82 pInfo=::getDataInfo(pItem->data, pItem->length, infoLength, itemHeaderLength, &errorCode);
83 if(U_FAILURE(errorCode)) {
84 exit(errorCode); // should succeed because readFile() checks headers
85 }
86 length=pItem->length-itemHeaderLength;
87
88 if(pInfo->isBigEndian==U_IS_BIG_ENDIAN && pInfo->charsetFamily==U_CHARSET_FAMILY) {
89 bytes=pItem->data+itemHeaderLength;
90 } else {
91 UDataSwapper *ds=udata_openSwapper((UBool)pInfo->isBigEndian, pInfo->charsetFamily, U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &errorCode);
92 if(U_FAILURE(errorCode)) {
93 fprintf(stderr, "icupkg: udata_openSwapper(\"%s\") failed - %s\n",
94 pItem->name, u_errorName(errorCode));
95 exit(errorCode);
96 }
97
98 ds->printError=printError;
99 ds->printErrorContext=stderr;
100
101 swapped=new uint8_t[pItem->length];
102 if(swapped==NULL) {
103 fprintf(stderr, "icupkg: unable to allocate memory for swapping \"%s\"\n", pItem->name);
104 exit(U_MEMORY_ALLOCATION_ERROR);
105 }
106 swap(ds, pItem->data, pItem->length, swapped, &errorCode);
107 pInfo=::getDataInfo(swapped, pItem->length, infoLength, itemHeaderLength, &errorCode);
108 bytes=swapped+itemHeaderLength;
109 udata_closeSwapper(ds);
110 }
111 }
112
113private:
114 const Item *pItem;
115 const UDataInfo *pInfo;
116 const uint8_t *bytes;
117 uint8_t *swapped;
118 int32_t length;
119};
120
73c04bcf
A
121// check a dependency ------------------------------------------------------ ***
122
123/*
124 * assemble the target item name from the source item name, an ID
125 * and a suffix
126 */
127static void
729e4ab9
A
128makeTargetName(const char *itemName, const char *id, int32_t idLength, const char *suffix,
129 char *target, int32_t capacity,
130 UErrorCode *pErrorCode) {
73c04bcf
A
131 const char *itemID;
132 int32_t treeLength, suffixLength, targetLength;
133
134 // get the item basename
135 itemID=strrchr(itemName, '/');
136 if(itemID!=NULL) {
137 ++itemID;
138 } else {
139 itemID=itemName;
140 }
141
142 // build the target string
143 treeLength=(int32_t)(itemID-itemName);
144 if(idLength<0) {
145 idLength=(int32_t)strlen(id);
146 }
147 suffixLength=(int32_t)strlen(suffix);
148 targetLength=treeLength+idLength+suffixLength;
729e4ab9
A
149 if(targetLength>=capacity) {
150 fprintf(stderr, "icupkg/makeTargetName(%s) target item name length %ld too long\n",
73c04bcf
A
151 itemName, (long)targetLength);
152 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
153 return;
154 }
155
156 memcpy(target, itemName, treeLength);
157 memcpy(target+treeLength, id, idLength);
158 memcpy(target+treeLength+idLength, suffix, suffixLength+1); // +1 includes the terminating NUL
729e4ab9 159}
73c04bcf 160
729e4ab9
A
161static void
162checkIDSuffix(const char *itemName, const char *id, int32_t idLength, const char *suffix,
163 CheckDependency check, void *context,
164 UErrorCode *pErrorCode) {
165 char target[200];
166 makeTargetName(itemName, id, idLength, suffix, target, (int32_t)sizeof(target), pErrorCode);
167 if(U_SUCCESS(*pErrorCode)) {
168 check(context, itemName, target);
169 }
73c04bcf
A
170}
171
172/* assemble the target item name from the item's parent item name */
173static void
174checkParent(const char *itemName, CheckDependency check, void *context,
175 UErrorCode *pErrorCode) {
176 const char *itemID, *parent, *parentLimit, *suffix;
177 int32_t parentLength;
178
179 // get the item basename
180 itemID=strrchr(itemName, '/');
181 if(itemID!=NULL) {
182 ++itemID;
183 } else {
184 itemID=itemName;
185 }
186
187 // get the item suffix
188 suffix=strrchr(itemID, '.');
189 if(suffix==NULL) {
190 // empty suffix, point to the end of the string
191 suffix=strrchr(itemID, 0);
192 }
193
194 // get the position of the last '_'
195 for(parentLimit=suffix; parentLimit>itemID && *--parentLimit!='_';) {}
196
197 if(parentLimit!=itemID) {
198 // get the parent item name by truncating the last part of this item's name */
199 parent=itemID;
200 parentLength=(int32_t)(parentLimit-itemID);
201 } else {
202 // no '_' in the item name: the parent is the root bundle
203 parent="root";
204 parentLength=4;
205 if((suffix-itemID)==parentLength && 0==memcmp(itemID, parent, parentLength)) {
206 // the item itself is "root", which does not depend on a parent
207 return;
208 }
209 }
210 checkIDSuffix(itemName, parent, parentLength, suffix, check, context, pErrorCode);
211}
212
213// get dependencies from resource bundles ---------------------------------- ***
214
729e4ab9 215static const UChar SLASH=0x2f;
73c04bcf
A
216
217/*
729e4ab9 218 * Check for the alias from the string or alias resource res.
73c04bcf
A
219 */
220static void
729e4ab9
A
221checkAlias(const char *itemName,
222 Resource res, const UChar *alias, int32_t length, UBool useResSuffix,
223 CheckDependency check, void *context, UErrorCode *pErrorCode) {
224 int32_t i;
73c04bcf 225
729e4ab9
A
226 if(!uprv_isInvariantUString(alias, length)) {
227 fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) alias string contains non-invariant characters\n",
228 itemName, res);
229 *pErrorCode=U_INVALID_CHAR_FOUND;
73c04bcf
A
230 return;
231 }
232
729e4ab9
A
233 // extract the locale ID from alias strings like
234 // locale_ID/key1/key2/key3
235 // locale_ID
73c04bcf 236
729e4ab9
A
237 // search for the first slash
238 for(i=0; i<length && alias[i]!=SLASH; ++i) {}
73c04bcf 239
729e4ab9
A
240 if(res_getPublicType(res)==URES_ALIAS) {
241 // ignore aliases with an initial slash:
242 // /ICUDATA/... and /pkgname/... go to a different package
243 // /LOCALE/... are for dynamic sideways fallbacks and don't go to a fixed bundle
244 if(i==0) {
245 return; // initial slash ('/')
73c04bcf 246 }
46f4442e 247
729e4ab9
A
248 // ignore the intra-bundle path starting from the first slash ('/')
249 length=i;
250 } else /* URES_STRING */ {
251 // the whole string should only consist of a locale ID
252 if(i!=length) {
253 fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) %%ALIAS contains a '/'\n",
254 itemName, res);
255 *pErrorCode=U_UNSUPPORTED_ERROR;
256 return;
46f4442e 257 }
729e4ab9 258 }
73c04bcf 259
729e4ab9
A
260 // convert the Unicode string to char *
261 char localeID[32];
262 if(length>=(int32_t)sizeof(localeID)) {
263 fprintf(stderr, "icupkg/ures_enumDependencies(%s res=%08x) alias locale ID length %ld too long\n",
264 itemName, res, (long)length);
265 *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
266 return;
267 }
268 u_UCharsToChars(alias, localeID, length);
269 localeID[length]=0;
73c04bcf 270
729e4ab9
A
271 checkIDSuffix(itemName, localeID, -1, (useResSuffix ? ".res" : ""), check, context, pErrorCode);
272}
73c04bcf 273
729e4ab9
A
274/*
275 * Enumerate one resource item and its children and extract dependencies from
276 * aliases.
277 */
278static void
279ures_enumDependencies(const char *itemName,
280 const ResourceData *pResData,
281 Resource res, const char *inKey, const char *parentKey, int32_t depth,
282 CheckDependency check, void *context,
283 Package *pkg,
284 UErrorCode *pErrorCode) {
285 switch(res_getPublicType(res)) {
286 case URES_STRING:
287 {
288 UBool useResSuffix = TRUE;
289 // Check for %%ALIAS
290 if(depth==1 && inKey!=NULL) {
291 if(0!=strcmp(inKey, "%%ALIAS")) {
292 break;
73c04bcf
A
293 }
294 }
729e4ab9
A
295 // Check for %%DEPENDENCY
296 else if(depth==2 && parentKey!=NULL) {
297 if(0!=strcmp(parentKey, "%%DEPENDENCY")) {
298 break;
73c04bcf 299 }
729e4ab9 300 useResSuffix = FALSE;
73c04bcf 301 } else {
729e4ab9
A
302 // we ignore all other strings
303 break;
73c04bcf 304 }
729e4ab9
A
305 int32_t length;
306 const UChar *alias=res_getString(pResData, res, &length);
307 checkAlias(itemName, res, alias, length, useResSuffix, check, context, pErrorCode);
308 }
309 break;
310 case URES_ALIAS:
311 {
312 int32_t length;
313 const UChar *alias=res_getAlias(pResData, res, &length);
314 checkAlias(itemName, res, alias, length, TRUE, check, context, pErrorCode);
73c04bcf
A
315 }
316 break;
317 case URES_TABLE:
73c04bcf 318 {
73c04bcf 319 /* recurse */
729e4ab9
A
320 int32_t count=res_countArrayItems(pResData, res);
321 for(int32_t i=0; i<count; ++i) {
322 const char *itemKey;
323 Resource item=res_getTableItemByIndex(pResData, res, i, &itemKey);
73c04bcf 324 ures_enumDependencies(
729e4ab9
A
325 itemName, pResData,
326 item, itemKey,
46f4442e 327 inKey, depth+1,
73c04bcf 328 check, context,
729e4ab9 329 pkg,
73c04bcf
A
330 pErrorCode);
331 if(U_FAILURE(*pErrorCode)) {
729e4ab9
A
332 fprintf(stderr, "icupkg/ures_enumDependencies(%s table res=%08x)[%d].recurse(%s: %08x) failed\n",
333 itemName, res, i, itemKey, item);
73c04bcf
A
334 break;
335 }
336 }
337 }
338 break;
339 case URES_ARRAY:
340 {
73c04bcf 341 /* recurse */
729e4ab9
A
342 int32_t count=res_countArrayItems(pResData, res);
343 for(int32_t i=0; i<count; ++i) {
344 Resource item=res_getArrayItem(pResData, res, i);
73c04bcf 345 ures_enumDependencies(
729e4ab9
A
346 itemName, pResData,
347 item, NULL,
348 inKey, depth+1,
73c04bcf 349 check, context,
729e4ab9 350 pkg,
73c04bcf
A
351 pErrorCode);
352 if(U_FAILURE(*pErrorCode)) {
729e4ab9
A
353 fprintf(stderr, "icupkg/ures_enumDependencies(%s array res=%08x)[%d].recurse(%08x) failed\n",
354 itemName, res, i, item);
73c04bcf
A
355 break;
356 }
357 }
358 }
359 break;
360 default:
361 break;
362 }
73c04bcf
A
363}
364
73c04bcf 365static void
729e4ab9 366ures_enumDependencies(const char *itemName, const UDataInfo *pInfo,
73c04bcf
A
367 const uint8_t *inBytes, int32_t length,
368 CheckDependency check, void *context,
729e4ab9 369 Package *pkg,
73c04bcf 370 UErrorCode *pErrorCode) {
729e4ab9 371 ResourceData resData;
73c04bcf 372
729e4ab9
A
373 res_read(&resData, pInfo, inBytes, length, pErrorCode);
374 if(U_FAILURE(*pErrorCode)) {
375 fprintf(stderr, "icupkg: .res format version %02x.%02x not supported, or bundle malformed\n",
376 pInfo->formatVersion[0], pInfo->formatVersion[1]);
73c04bcf
A
377 exit(U_UNSUPPORTED_ERROR);
378 }
379
73c04bcf
A
380 /*
381 * if the bundle attributes are present and the nofallback flag is not set,
382 * then add the parent bundle as a dependency
383 */
729e4ab9
A
384 if(pInfo->formatVersion[0]>1 || (pInfo->formatVersion[0]==1 && pInfo->formatVersion[1]>=1)) {
385 if(!resData.noFallback) {
386 /* this bundle participates in locale fallback */
387 checkParent(itemName, check, context, pErrorCode);
73c04bcf
A
388 }
389 }
729e4ab9 390
4388f060 391 icu::NativeItem nativePool;
729e4ab9
A
392
393 if(resData.usesPoolBundle) {
394 char poolName[200];
395 makeTargetName(itemName, "pool", 4, ".res", poolName, (int32_t)sizeof(poolName), pErrorCode);
396 if(U_FAILURE(*pErrorCode)) {
397 return;
398 }
399 check(context, itemName, poolName);
400 int32_t index=pkg->findItem(poolName);
401 if(index<0) {
402 // We cannot work with a bundle if its pool resource is missing.
403 // check() already printed a complaint.
404 return;
405 }
406 // TODO: Cache the native version in the Item itself.
407 nativePool.setItem(pkg->getItem(index), ures_swap);
408 const UDataInfo *poolInfo=nativePool.getDataInfo();
409 if(poolInfo->formatVersion[0]<=1) {
410 fprintf(stderr, "icupkg: %s is not a pool bundle\n", poolName);
411 return;
412 }
2ca993e8
A
413 const int32_t *poolRoot=(const int32_t *)nativePool.getBytes();
414 const int32_t *poolIndexes=poolRoot+1;
729e4ab9
A
415 int32_t poolIndexLength=poolIndexes[URES_INDEX_LENGTH]&0xff;
416 if(!(poolIndexLength>URES_INDEX_POOL_CHECKSUM &&
417 (poolIndexes[URES_INDEX_ATTRIBUTES]&URES_ATT_IS_POOL_BUNDLE))
418 ) {
419 fprintf(stderr, "icupkg: %s is not a pool bundle\n", poolName);
420 return;
421 }
422 if(resData.pRoot[1+URES_INDEX_POOL_CHECKSUM]==poolIndexes[URES_INDEX_POOL_CHECKSUM]) {
423 resData.poolBundleKeys=(const char *)(poolIndexes+poolIndexLength);
2ca993e8 424 resData.poolBundleStrings=(const uint16_t *)(poolRoot+poolIndexes[URES_INDEX_KEYS_TOP]);
729e4ab9
A
425 } else {
426 fprintf(stderr, "icupkg: %s has mismatched checksum for %s\n", poolName, itemName);
427 return;
428 }
429 }
430
431 ures_enumDependencies(
432 itemName, &resData,
433 resData.rootRes, NULL, NULL, 0,
434 check, context,
435 pkg,
436 pErrorCode);
73c04bcf
A
437}
438
439// get dependencies from conversion tables --------------------------------- ***
440
441/* code adapted from ucnv_swap() */
442static void
443ucnv_enumDependencies(const UDataSwapper *ds,
444 const char *itemName, const UDataInfo *pInfo,
445 const uint8_t *inBytes, int32_t length,
446 CheckDependency check, void *context,
447 UErrorCode *pErrorCode) {
448 uint32_t staticDataSize;
449
450 const UConverterStaticData *inStaticData;
451
452 const _MBCSHeader *inMBCSHeader;
453 uint8_t outputType;
454
455 /* check format version */
456 if(!(
457 pInfo->formatVersion[0]==6 &&
458 pInfo->formatVersion[1]>=2
459 )) {
460 fprintf(stderr, "icupkg/ucnv_enumDependencies(): .cnv format version %02x.%02x not supported\n",
461 pInfo->formatVersion[0], pInfo->formatVersion[1]);
462 exit(U_UNSUPPORTED_ERROR);
463 }
464
465 /* read the initial UConverterStaticData structure after the UDataInfo header */
466 inStaticData=(const UConverterStaticData *)inBytes;
467
468 if( length<(int32_t)sizeof(UConverterStaticData) ||
469 (uint32_t)length<(staticDataSize=ds->readUInt32(inStaticData->structSize))
470 ) {
471 udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after header) for an ICU .cnv conversion table\n",
472 length);
473 *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
474 return;
475 }
476
477 inBytes+=staticDataSize;
478 length-=(int32_t)staticDataSize;
479
480 /* check for supported conversionType values */
481 if(inStaticData->conversionType==UCNV_MBCS) {
482 /* MBCS data */
46f4442e 483 uint32_t mbcsHeaderLength, mbcsHeaderFlags, mbcsHeaderOptions;
73c04bcf
A
484 int32_t extOffset;
485
486 inMBCSHeader=(const _MBCSHeader *)inBytes;
487
488 if(length<(int32_t)sizeof(_MBCSHeader)) {
489 udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table\n",
490 length);
491 *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
492 return;
493 }
46f4442e
A
494 if(inMBCSHeader->version[0]==4 && inMBCSHeader->version[1]>=1) {
495 mbcsHeaderLength=MBCS_HEADER_V4_LENGTH;
496 } else if(inMBCSHeader->version[0]==5 && inMBCSHeader->version[1]>=3 &&
497 ((mbcsHeaderOptions=ds->readUInt32(inMBCSHeader->options))&
498 MBCS_OPT_UNKNOWN_INCOMPATIBLE_MASK)==0
499 ) {
500 mbcsHeaderLength=mbcsHeaderOptions&MBCS_OPT_LENGTH_MASK;
501 } else {
73c04bcf
A
502 udata_printError(ds, "icupkg/ucnv_enumDependencies(): unsupported _MBCSHeader.version %d.%d\n",
503 inMBCSHeader->version[0], inMBCSHeader->version[1]);
504 *pErrorCode=U_UNSUPPORTED_ERROR;
505 return;
506 }
507
508 mbcsHeaderFlags=ds->readUInt32(inMBCSHeader->flags);
509 extOffset=(int32_t)(mbcsHeaderFlags>>8);
510 outputType=(uint8_t)mbcsHeaderFlags;
511
512 if(outputType==MBCS_OUTPUT_EXT_ONLY) {
513 /*
514 * extension-only file,
515 * contains a base name instead of normal base table data
516 */
517 char baseName[32];
518 int32_t baseNameLength;
519
520 /* there is extension data after the base data, see ucnv_ext.h */
521 if(length<(extOffset+UCNV_EXT_INDEXES_MIN_LENGTH*4)) {
522 udata_printError(ds, "icupkg/ucnv_enumDependencies(): too few bytes (%d after headers) for an ICU MBCS .cnv conversion table with extension data\n",
523 length);
524 *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
525 return;
526 }
527
528 /* swap the base name, between the header and the extension data */
46f4442e
A
529 const char *inBaseName=(const char *)inBytes+mbcsHeaderLength*4;
530 baseNameLength=(int32_t)strlen(inBaseName);
73c04bcf
A
531 if(baseNameLength>=(int32_t)sizeof(baseName)) {
532 udata_printError(ds, "icupkg/ucnv_enumDependencies(%s): base name length %ld too long\n",
533 itemName, baseNameLength);
534 *pErrorCode=U_UNSUPPORTED_ERROR;
535 return;
536 }
46f4442e 537 ds->swapInvChars(ds, inBaseName, baseNameLength+1, baseName, pErrorCode);
73c04bcf
A
538
539 checkIDSuffix(itemName, baseName, -1, ".cnv", check, context, pErrorCode);
540 }
541 }
542}
543
544// ICU data formats -------------------------------------------------------- ***
545
546static const struct {
547 uint8_t dataFormat[4];
548} dataFormats[]={
549 { { 0x52, 0x65, 0x73, 0x42 } }, /* dataFormat="ResB" */
550 { { 0x63, 0x6e, 0x76, 0x74 } }, /* dataFormat="cnvt" */
551 { { 0x43, 0x76, 0x41, 0x6c } } /* dataFormat="CvAl" */
552};
553
554enum {
555 FMT_RES,
556 FMT_CNV,
557 FMT_ALIAS,
558 FMT_COUNT
559};
560
561static int32_t
562getDataFormat(const uint8_t dataFormat[4]) {
563 int32_t i;
564
565 for(i=0; i<FMT_COUNT; ++i) {
566 if(0==memcmp(dataFormats[i].dataFormat, dataFormat, 4)) {
567 return i;
568 }
569 }
570 return -1;
571}
572
573// enumerate dependencies of a package item -------------------------------- ***
574
73c04bcf 575void
46f4442e 576Package::enumDependencies(Item *pItem, void *context, CheckDependency check) {
729e4ab9
A
577 int32_t infoLength, itemHeaderLength;
578 UErrorCode errorCode=U_ZERO_ERROR;
579 const UDataInfo *pInfo=getDataInfo(pItem->data, pItem->length, infoLength, itemHeaderLength, &errorCode);
73c04bcf
A
580 if(U_FAILURE(errorCode)) {
581 return; // should not occur because readFile() checks headers
582 }
583
584 // find the data format and call the corresponding function, if any
729e4ab9 585 int32_t format=getDataFormat(pInfo->dataFormat);
73c04bcf 586 if(format>=0) {
73c04bcf
A
587 switch(format) {
588 case FMT_RES:
729e4ab9
A
589 {
590 /*
591 * Swap the resource bundle (if necessary) so that we can use
592 * the normal runtime uresdata.c code to read it.
593 * We do not want to duplicate that code, especially not together with on-the-fly swapping.
594 */
595 NativeItem nrb(pItem, ures_swap);
596 ures_enumDependencies(pItem->name, nrb.getDataInfo(), nrb.getBytes(), nrb.getLength(), check, context, this, &errorCode);
597 break;
598 }
73c04bcf 599 case FMT_CNV:
729e4ab9
A
600 {
601 // TODO: share/cache swappers
602 UDataSwapper *ds=udata_openSwapper(
603 (UBool)pInfo->isBigEndian, pInfo->charsetFamily,
604 U_IS_BIG_ENDIAN, U_CHARSET_FAMILY,
605 &errorCode);
606 if(U_FAILURE(errorCode)) {
607 fprintf(stderr, "icupkg: udata_openSwapper(\"%s\") failed - %s\n",
608 pItem->name, u_errorName(errorCode));
609 exit(errorCode);
610 }
611
612 ds->printError=printError;
613 ds->printErrorContext=stderr;
614
615 const uint8_t *inBytes=pItem->data+itemHeaderLength;
616 int32_t length=pItem->length-itemHeaderLength;
617
618 ucnv_enumDependencies(ds, pItem->name, pInfo, inBytes, length, check, context, &errorCode);
619 udata_closeSwapper(ds);
620 break;
621 }
73c04bcf
A
622 default:
623 break;
624 }
625
73c04bcf
A
626 if(U_FAILURE(errorCode)) {
627 exit(errorCode);
628 }
629 }
630}
729e4ab9 631
73c04bcf 632U_NAMESPACE_END