From fa15c62af36ef16d77bb003000467442331d072d Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Sat, 9 Aug 2003 00:27:31 +0000 Subject: [PATCH] ICU-2235 add udata_printError() output X-SVN-Rev: 12801 --- icu4c/source/common/putil.c | 4 ++ icu4c/source/common/udataswp.c | 3 ++ icu4c/source/common/uresdata.c | 65 ++++++++++++++++++++------ icu4c/source/tools/icuswap/icuswap.cpp | 15 ++++-- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/icu4c/source/common/putil.c b/icu4c/source/common/putil.c index 2c0dcd1421..b45f6332cc 100644 --- a/icu4c/source/common/putil.c +++ b/icu4c/source/common/putil.c @@ -2171,6 +2171,8 @@ uprv_ebcdicFromAscii(const UDataSwapper *ds, while(count>0) { c=*s++; if(!CHAR_IS_INVARIANT(c)) { + udata_printError(ds, "uprv_ebcdicFromAscii() string[%] contains a variant character in position %d\n", + length, length-count); *pErrorCode=U_INVALID_CHAR_FOUND; return 0; } @@ -2206,6 +2208,8 @@ uprv_asciiFromEbcdic(const UDataSwapper *ds, while(count>0) { c=*s++; if(c!=0 && ((c=asciiFromEbcdic[c])==0 || !CHAR_IS_INVARIANT(c))) { + udata_printError(ds, "uprv_asciiFromEbcdic() string[%] contains a variant character in position %d\n", + length, length-count); *pErrorCode=U_INVALID_CHAR_FOUND; return 0; } diff --git a/icu4c/source/common/udataswp.c b/icu4c/source/common/udataswp.c index 176f1288ab..1e0131f974 100644 --- a/icu4c/source/common/udataswp.c +++ b/icu4c/source/common/udataswp.c @@ -175,6 +175,7 @@ udata_swapDataHeader(const UDataSwapper *ds, pHeader->dataHeader.magic2!=0x27 || pHeader->info.sizeofUChar!=2 ) { + udata_printError(ds, "udata_swapDataHeader(): initial bytes do not look like ICU data\n"); *pErrorCode=U_UNSUPPORTED_ERROR; return 0; } @@ -187,6 +188,8 @@ udata_swapDataHeader(const UDataSwapper *ds, headerSize<(sizeof(pHeader->dataHeader)+infoSize) || (length>=0 && length0) { - do { + if(offset<=length) { + for(i=0; ireadUInt32(*p++); ures_preflightResource(ds, inBundle, length, item, pBottom, pTop, pMaxTableLength, pErrorCode); - } while(U_SUCCESS(*pErrorCode) && --count>0); + if(U_FAILURE(*pErrorCode)) { + udata_printError(ds, "ures_preflightResource(table res=%08x)[%d].recurse(%08x) failed - %s\n", + res, i, item, u_errorName(*pErrorCode)); + break; + } + } } } break; case URES_ARRAY: { Resource item; - int32_t count; + int32_t i, count; /* top=offset+1+(array length) */ count=udata_readInt32(ds, (int32_t)*p++); offset+=1+count; /* recurse */ - if(offset<=length && count>0) { - do { + if(offset<=length) { + for(i=0; ireadUInt32(*p++); ures_preflightResource(ds, inBundle, length, item, pBottom, pTop, pMaxTableLength, pErrorCode); - } while(U_SUCCESS(*pErrorCode) && --count>0); + if(U_FAILURE(*pErrorCode)) { + udata_printError(ds, "ures_preflightResource(array res=%08x)[%d].recurse(%08x) failed - %s\n", + res, i, item, u_errorName(*pErrorCode)); + break; + } + } } } break; @@ -569,6 +581,7 @@ ures_preflightResource(const UDataSwapper *ds, break; default: /* also catches RES_BOGUS */ + udata_printError(ds, "ures_preflightResource(res=%08x) unknown resource type\n", res); *pErrorCode=U_UNSUPPORTED_ERROR; break; } @@ -576,6 +589,8 @@ ures_preflightResource(const UDataSwapper *ds, if(U_FAILURE(*pErrorCode)) { /* nothing to do */ } else if(0<=length && length*pTop) { *pTop=offset; @@ -644,7 +659,7 @@ ures_swapResource(const UDataSwapper *ds, q=outBundle+offset; /* recurse */ - for(i=0; U_SUCCESS(*pErrorCode) && ireadUInt32(p[i]); /* * ### TODO detect a collation binary that is to be swapped via @@ -655,9 +670,11 @@ ures_swapResource(const UDataSwapper *ds, * because the common library cannot directly call into the i18n library */ ures_swapResource(ds, inBundle, outBundle, item, pTempTable, pErrorCode); - } - if(U_FAILURE(*pErrorCode)) { - return; + if(U_FAILURE(*pErrorCode)) { + udata_printError(ds, "ures_swapResource(table res=%08x)[%d].recurse(%08x) failed - %s\n", + res, i, item, u_errorName(*pErrorCode)); + return; + } } /* @@ -683,6 +700,8 @@ ures_swapResource(const UDataSwapper *ds, ures_compareRows, pTempTable->keyChars, FALSE, pErrorCode); if(U_FAILURE(*pErrorCode)) { + udata_printError(ds, "ures_swapResource(table res=%08x).uprv_sortArray(%d items) failed - %s\n", + res, count, u_errorName(*pErrorCode)); return; } @@ -726,9 +745,14 @@ ures_swapResource(const UDataSwapper *ds, ds->swapArray32(ds, p++, 4, q++, pErrorCode); /* recurse */ - for(i=0; U_SUCCESS(*pErrorCode) && ireadUInt32(p[i]); ures_swapResource(ds, inBundle, outBundle, item, pTempTable, pErrorCode); + if(U_FAILURE(*pErrorCode)) { + udata_printError(ds, "ures_swapResource(array res=%08x)[%d].recurse(%08x) failed - %s\n", + res, i, item, u_errorName(*pErrorCode)); + return; + } } /* swap items */ @@ -778,10 +802,13 @@ ures_swap(const UDataSwapper *ds, pInfo->dataFormat[3]==0x42 && pInfo->formatVersion[0]==1 )) { + udata_printError(ds, "ures_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not a resource bundle\n", + pInfo->dataFormat[0], pInfo->dataFormat[1], + pInfo->dataFormat[2], pInfo->dataFormat[3], + pInfo->formatVersion[0]); *pErrorCode=U_UNSUPPORTED_ERROR; return 0; } - /* ### TODO add ds->printError() output where errors occur */ /* a resource bundle must contain at least one resource item */ if(length<0) { @@ -789,6 +816,8 @@ ures_swap(const UDataSwapper *ds, } else { bundleLength=(length-headerSize)/4; if(bundleLength<1) { + udata_printError(ds, "ures_swap(): too few bytes (%d after header) for a resource bundle\n", + length-headerSize); *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } @@ -803,6 +832,8 @@ ures_swap(const UDataSwapper *ds, &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; } @@ -825,6 +856,8 @@ ures_swap(const UDataSwapper *ds, } else { tempTable.rows=(Row *)uprv_malloc(maxTableLength*sizeof(Row)+maxTableLength*4); if(tempTable.rows==NULL) { + udata_printError(ds, "ures_swap(): unable to allocate memory for sorting tables (max length: %d)\n", + maxTableLength); *pErrorCode=U_MEMORY_ALLOCATION_ERROR; return 0; } @@ -833,6 +866,10 @@ ures_swap(const UDataSwapper *ds, /* swap the resources */ ures_swapResource(ds, inBundle, outBundle, rootRes, &tempTable, pErrorCode); + if(U_FAILURE(*pErrorCode)) { + udata_printError(ds, "ures_swapResource(root res=%08x) failed - %s\n", + rootRes, u_errorName(*pErrorCode)); + } if(tempTable.rows!=rows) { uprv_free(tempTable.rows); diff --git a/icu4c/source/tools/icuswap/icuswap.cpp b/icu4c/source/tools/icuswap/icuswap.cpp index bb08f6130a..728f0c57af 100644 --- a/icu4c/source/tools/icuswap/icuswap.cpp +++ b/icu4c/source/tools/icuswap/icuswap.cpp @@ -72,6 +72,11 @@ udata_swap(const UDataSwapper *ds, const void *inData, int32_t length, void *outData, UErrorCode *pErrorCode); +static void U_CALLCONV +printError(void *context, const char *fmt, va_list args) { + vfprintf((FILE *)context, fmt, args); +} + static int printUsage(const char *pname, UBool ishelp) { fprintf(stderr, @@ -107,9 +112,9 @@ main(int argc, char *argv[]) { U_MAIN_INIT_ARGS(argc, argv); /* get the program basename */ - pname=strchr(argv[0], U_FILE_SEP_CHAR); + pname=strrchr(argv[0], U_FILE_SEP_CHAR); if(pname==NULL) { - pname=strchr(argv[0], '/'); + pname=strrchr(argv[0], '/'); } if(pname!=NULL) { ++pname; @@ -190,7 +195,8 @@ main(int argc, char *argv[]) { goto done; } - /* ### TODO set ds->printError with a simple fprintf() implementation */ + ds->printError=printError; + ds->printErrorContext=stderr; length=udata_swap(ds, data, length, data, &errorCode); udata_closeSwapper(ds); @@ -279,6 +285,9 @@ udata_swap(const UDataSwapper *ds, } /* the dataFormat was not recognized */ + udata_printError(ds, "udata_swap(): unknown data format %02x.%02x.%02x.%02x\n", + pInfo->dataFormat[0], pInfo->dataFormat[1], + pInfo->dataFormat[2], pInfo->dataFormat[3]); *pErrorCode=U_UNSUPPORTED_ERROR; return 0; }