X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..2ca993e82fb37b597a3c73ecd1586a139a6579c5:/icuSources/tools/toolutil/pkg_icu.cpp diff --git a/icuSources/tools/toolutil/pkg_icu.cpp b/icuSources/tools/toolutil/pkg_icu.cpp index 7af5b1c1..471b1d45 100644 --- a/icuSources/tools/toolutil/pkg_icu.cpp +++ b/icuSources/tools/toolutil/pkg_icu.cpp @@ -1,9 +1,10 @@ /****************************************************************************** - * Copyright (C) 2008-2009, International Business Machines + * Copyright (C) 2008-2015, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ #include "unicode/utypes.h" +#include "unicode/localpointer.h" #include "unicode/putil.h" #include "cstring.h" #include "toolutil.h" @@ -16,9 +17,6 @@ #include #include - -#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) - // read a file list -------------------------------------------------------- *** U_NAMESPACE_USE @@ -38,7 +36,7 @@ isListTextFile(const char *listname) { const char *listNameEnd=strchr(listname, 0); const char *suffix; int32_t i, length; - for(i=0; ilength && 0==memcmp(listNameEnd-length, suffix, length)) { @@ -56,8 +54,8 @@ isListTextFile(const char *listname) { * Otherwise, read the file itself as a single-item list. */ U_CAPI Package * U_EXPORT2 -readList(const char *filesPath, const char *listname, UBool readContents) { - Package *listPkg; +readList(const char *filesPath, const char *listname, UBool readContents, Package *listPkgIn) { + Package *listPkg = listPkgIn; FILE *file; const char *listNameEnd; @@ -66,10 +64,12 @@ readList(const char *filesPath, const char *listname, UBool readContents) { return NULL; } - listPkg=new Package(); - if(listPkg==NULL) { - fprintf(stderr, "icupkg: not enough memory\n"); - exit(U_MEMORY_ALLOCATION_ERROR); + if (listPkg == NULL) { + listPkg=new Package(); + if(listPkg==NULL) { + fprintf(stderr, "icupkg: not enough memory\n"); + exit(U_MEMORY_ALLOCATION_ERROR); + } } listNameEnd=strchr(listname, 0); @@ -133,6 +133,8 @@ readList(const char *filesPath, const char *listname, UBool readContents) { fclose(file); } else if((listNameEnd-listname)>4 && 0==memcmp(listNameEnd-4, ".dat", 4)) { // read the ICU .dat package + // Accept a .dat file whose name differs from the ToC prefixes. + listPkg->setAutoPrefix(); listPkg->readPackage(listname); } else { // list the single file itself @@ -148,33 +150,25 @@ readList(const char *filesPath, const char *listname, UBool readContents) { U_CAPI int U_EXPORT2 writePackageDatFile(const char *outFilename, const char *outComment, const char *sourcePath, const char *addList, Package *pkg, char outType) { - Package *addListPkg = NULL; - UBool pkgDelete = FALSE; + LocalPointer ownedPkg; + LocalPointer addListPkg; if (pkg == NULL) { - pkg = new Package; - if(pkg == NULL) { + ownedPkg.adoptInstead(new Package); + if(ownedPkg.isNull()) { fprintf(stderr, "icupkg: not enough memory\n"); return U_MEMORY_ALLOCATION_ERROR; } + pkg = ownedPkg.getAlias(); - addListPkg = readList(sourcePath, addList, TRUE); - if(addListPkg != NULL) { + addListPkg.adoptInstead(readList(sourcePath, addList, TRUE, NULL)); + if(addListPkg.isValid()) { pkg->addItems(*addListPkg); } else { return U_ILLEGAL_ARGUMENT_ERROR; } - - pkgDelete = TRUE; } pkg->writePackage(outFilename, outType, outComment); - - if (pkgDelete) { - delete pkg; - delete addListPkg; - } - return 0; } -