X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..f59164e3d128c7675a4d3934206346a3384e53a5:/icuSources/extra/uconv/uconv.cpp diff --git a/icuSources/extra/uconv/uconv.cpp b/icuSources/extra/uconv/uconv.cpp index 0add6cfc..6729b3b2 100644 --- a/icuSources/extra/uconv/uconv.cpp +++ b/icuSources/extra/uconv/uconv.cpp @@ -1,6 +1,6 @@ /***************************************************************************** * -* Copyright (C) 1999-2010, International Business Machines +* Copyright (C) 1999-2016, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************/ @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -40,10 +41,10 @@ U_NAMESPACE_USE -#if (defined(U_WINDOWS) || defined(U_CYGWIN)) && !defined(__STRICT_ANSI__) +#if U_PLATFORM_USES_ONLY_WIN32_API && !defined(__STRICT_ANSI__) #include #include -#if defined(U_WINDOWS) +#if U_PLATFORM_USES_ONLY_WIN32_API #define USE_FILENO_BINARY_MODE 1 /* Windows likes to rename Unix-like functions */ #ifndef fileno @@ -65,8 +66,6 @@ U_NAMESPACE_USE U_CFUNC char uconvmsg_dat[]; #endif -#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) - #define DEFAULT_BUFSZ 4096 #define UCONVMSG "uconvmsg" @@ -88,7 +87,7 @@ static void initMsg(const char *pname) { ps = 1; /* Set up our static data - if any */ -#ifdef UCONVMSG_LINK +#if defined(UCONVMSG_LINK) && U_PLATFORM != U_PF_OS390 /* On z/OS, this is failing. */ udata_setAppData(UCONVMSG, (const void*) uconvmsg_dat, &err); if (U_FAILURE(err)) { fprintf(stderr, "%s: warning, problem installing our static resource bundle data uconvmsg: %s - trying anyways.\n", @@ -174,7 +173,7 @@ static struct callback_ent { static const struct callback_ent *findCallback(const char *name) { int i, count = - sizeof(transcode_callbacks) / sizeof(*transcode_callbacks); + UPRV_LENGTHOF(transcode_callbacks); /* We'll do a linear search, there aren't many of them and bsearch() may not be that portable. */ @@ -593,6 +592,7 @@ ConvertFile::convertFile(const char *pname, UConverter *convto = 0; UErrorCode err = U_ZERO_ERROR; UBool flush; + UBool closeFile = FALSE; const char *cbufp, *prevbufp; char *bufp; @@ -628,6 +628,7 @@ ConvertFile::convertFile(const char *pname, u_wmsg(stderr, "cantOpenInputF", str1.getBuffer(), str2.getBuffer()); return FALSE; } + closeFile = TRUE; } else { infilestr = "-"; infile = stdin; @@ -656,9 +657,9 @@ ConvertFile::convertFile(const char *pname, parse.line = -1; if (uprv_strchr(translit, ':') || uprv_strchr(translit, '>') || uprv_strchr(translit, '<') || uprv_strchr(translit, '>')) { - t = Transliterator::createFromRules("Uconv", str, UTRANS_FORWARD, parse, err); + t = Transliterator::createFromRules(UNICODE_STRING_SIMPLE("Uconv"), str, UTRANS_FORWARD, parse, err); } else { - t = Transliterator::createInstance(translit, UTRANS_FORWARD, err); + t = Transliterator::createInstance(UnicodeString(translit, -1, US_INV), UTRANS_FORWARD, err); } if (U_FAILURE(err)) { @@ -943,7 +944,7 @@ ConvertFile::convertFile(const char *pname, int8_t i, length, errorLength; UErrorCode localError = U_ZERO_ERROR; - errorLength = (int8_t)LENGTHOF(errorUChars); + errorLength = UPRV_LENGTHOF(errorUChars); ucnv_getInvalidUChars(convto, errorUChars, &errorLength, &localError); if (U_FAILURE(localError) || errorLength == 0) { // need at least 1 so that we don't access beyond the length of fromoffsets[] @@ -1051,7 +1052,7 @@ normal_exit: delete t; #endif - if (infile != stdin) { + if (closeFile) { fclose(infile); } @@ -1081,7 +1082,7 @@ static void usage(const char *pname, int ecode) { /* Now dump callbacks and finish. */ int i, count = - sizeof(transcode_callbacks) / sizeof(*transcode_callbacks); + UPRV_LENGTHOF(transcode_callbacks); for (i = 0; i < count; ++i) { fprintf(fp, " %s", transcode_callbacks[i].name); } @@ -1134,7 +1135,7 @@ main(int argc, char **argv) // Get and prettify pname. pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); -#ifdef U_WINDOWS +#if U_PLATFORM_USES_ONLY_WIN32_API if (!pname) { pname = uprv_strrchr(*argv, '/'); } @@ -1378,6 +1379,8 @@ normal_exit: fclose(outfile); } + u_cleanup(); + return ret; }