diff --git a/icu4c/source/allinone/allinone.sln b/icu4c/source/allinone/allinone.sln index d1360dbe784..cf01180d20b 100644 --- a/icu4c/source/allinone/allinone.sln +++ b/icu4c/source/allinone/allinone.sln @@ -11,6 +11,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "date", "..\samples\date\date.vcxproj", "{38B5751A-C6F9-4409-950C-F4F9DA17275F}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "derb", "..\tools\genrb\derb.vcxproj", "{D3065ADB-8820-4CC7-9B6C-9510833961A3}" + ProjectSection(ProjectDependencies) = postProject + {C2B04507-2521-4801-BF0D-5FD79D6D518C} = {C2B04507-2521-4801-BF0D-5FD79D6D518C} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "genbrk", "..\tools\genbrk\genbrk.vcxproj", "{C2BE5000-7501-4E87-9724-B8D82494FAE6}" EndProject diff --git a/icu4c/source/tools/genrb/Makefile.in b/icu4c/source/tools/genrb/Makefile.in index ae05bed8a6c..dbbf97c6742 100644 --- a/icu4c/source/tools/genrb/Makefile.in +++ b/icu4c/source/tools/genrb/Makefile.in @@ -1,6 +1,6 @@ ################################################################################# ## Makefile.in for ICU - tools/genrb # -## Copyright (c) 1999-2011, International Business Machines Corporation and # +## Copyright (c) 1999-2013, International Business Machines Corporation and # ## others. All Rights Reserved. # ################################################################################# @@ -20,17 +20,18 @@ DERB_STUB_NAME = derb SECTION = 1 -MAN_FILES = $(TARGET_STUB_NAME).$(SECTION) $(DERB_STUB_NAME).$(SECTION) - +MAN_FILES = $(TARGET_STUB_NAME).$(SECTION) +@ICUIO_TRUE@MAN_FILES += $(DERB_STUB_NAME).$(SECTION) ## Extra files to remove for 'make clean' CLEANFILES = *~ $(MAN_FILES) $(DEPS) $(DERB_DEPS) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -DERB = $(BINDIR)/$(DERB_STUB_NAME)$(EXEEXT) +# derb depends on icuio +@ICUIO_TRUE@DERB = $(BINDIR)/$(DERB_STUB_NAME)$(EXEEXT) -CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(srcdir)/../toolutil +CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(srcdir)/../toolutil -I$(top_srcdir)/io LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) OBJECTS = errmsg.o genrb.o parse.o read.o reslist.o ustr.o rbutil.o \ @@ -57,7 +58,7 @@ distclean : distclean-local dist: dist-local check: all check-local -all-local: $(TARGET) $(DERB) $(MAN_FILES) +all-local: $(TARGET) $(DERB) $(MAN_FILES) install-local: all-local install-man $(MKINSTALLDIRS) $(DESTDIR)$(bindir) @@ -84,11 +85,11 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status $(TARGET) : $(OBJECTS) - $(LINK.cc) $(OUTOPT)$@ $^ $(LIBS) + $(LINK.cc) $(OUTOPT)$@ $^ $(LIBS) $(POST_BUILD_STEP) $(DERB) : $(DERB_OBJ) - $(LINK.cc) $(OUTOPT)$@ $^ $(LIBS) + $(LINK.cc) $(OUTOPT)$@ $^ $(LIBICUIO) $(LIBS) $(POST_BUILD_STEP) # This line is needed to serialize builds when the gmake -j option is used. diff --git a/icu4c/source/tools/genrb/derb.c b/icu4c/source/tools/genrb/derb.c index 4aff26e0bda..972e2c3d5bc 100644 --- a/icu4c/source/tools/genrb/derb.c +++ b/icu4c/source/tools/genrb/derb.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2012, International Business Machines +* Copyright (C) 1999-2013, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -18,6 +18,7 @@ #include "unicode/ucnv.h" #include "unicode/ustring.h" #include "unicode/putil.h" +#include "unicode/ustdio.h" #include "uresimp.h" #include "cmemory.h" @@ -26,32 +27,10 @@ #include "toolutil.h" #include "ustrfmt.h" -#include -#include -#include - -#if U_PLATFORM_HAS_WIN32_API -#include -#include -#define USE_FILENO_BINARY_MODE 1 -/* Windows likes to rename Unix-like functions */ -#ifndef fileno -#define fileno _fileno -#endif -#ifndef setmode -#define setmode _setmode -#endif -#ifndef O_BINARY -#define O_BINARY _O_BINARY -#endif -#endif - -#define DERB_VERSION "1.0" +#define DERB_VERSION "1.1" #define DERB_DEFAULT_TRUNC 80 -static UConverter *defaultConverter = 0; - static const int32_t indentsize = 4; static int32_t truncsize = DERB_DEFAULT_TRUNC; static UBool opt_truncate = FALSE; @@ -59,11 +38,11 @@ static UBool opt_truncate = FALSE; static const char *getEncodingName(const char *encoding); static void reportError(const char *pname, UErrorCode *status, const char *when); static UChar *quotedString(const UChar *string); -static void printOutBundle(FILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status); -static void printString(FILE *out, UConverter *converter, const UChar *str, int32_t len); -static void printCString(FILE *out, UConverter *converter, const char *str, int32_t len); -static void printIndent(FILE *out, UConverter *converter, int32_t indent); -static void printHex(FILE *out, UConverter *converter, uint8_t what); +static void printOutBundle(UFILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status); +static void printString(UFILE *out, UConverter *converter, const UChar *str, int32_t len); +static void printCString(UFILE *out, UConverter *converter, const char *str, int32_t len); +static void printIndent(UFILE *out, UConverter *converter, int32_t indent); +static void printHex(UFILE *out, UConverter *converter, uint8_t what); static UOption options[]={ UOPTION_HELP_H, @@ -77,11 +56,12 @@ static UOption options[]={ /* 8 */ { "bom", NULL, NULL, NULL, 0, UOPT_NO_ARG, 0 }, /* 9 */ UOPTION_ICUDATADIR, /* 10 */ UOPTION_VERSION, -/* 11 */ { "suppressAliases", NULL, NULL, NULL, 'A', UOPT_NO_ARG, 0 } +/* 11 */ { "suppressAliases", NULL, NULL, NULL, 'A', UOPT_NO_ARG, 0 }, }; static UBool verbose = FALSE; static UBool suppressAliases = FALSE; +static UFILE *ustderr = NULL; extern int main(int argc, char* argv[]) { @@ -97,7 +77,7 @@ main(int argc, char* argv[]) { UErrorCode status = U_ZERO_ERROR; int32_t i = 0; - UConverter *converter; + UConverter *converter = NULL; // not used const char* arg; @@ -148,7 +128,11 @@ main(int argc, char* argv[]) { } if (options[3].doesOccur) { - tostdout = 1; + if(options[2].doesOccur) { + fprintf(stderr, "%s: Error: don't specify an encoding (-e) when writing to stdout (-c).\n", pname); + return 3; + } + tostdout = 1; } if(options[4].doesOccur) { @@ -186,22 +170,8 @@ main(int argc, char* argv[]) { suppressAliases = TRUE; } - converter = ucnv_open(encoding, &status); - if (U_FAILURE(status)) { - fprintf(stderr, "%s: couldn't create %s converter for encoding\n", pname, encoding ? encoding : ucnv_getDefaultName()); - return 2; - } - ucnv_setFromUCallBack(converter, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); - if (U_FAILURE(status)) { - fprintf(stderr, "%s: couldn't configure converter for encoding\n", pname); - return 3; - } - - defaultConverter = ucnv_open(0, &status); - if (U_FAILURE(status)) { - fprintf(stderr, "%s: couldn't create %s converter for encoding\n", ucnv_getDefaultName(), pname); - return 2; - } + fflush(stderr); // use ustderr now. + ustderr = u_finit(stderr, NULL, NULL); for (i = 1; i < argc; ++i) { static const UChar sp[] = { 0x0020 }; /* " " */ @@ -213,7 +183,7 @@ main(int argc, char* argv[]) { arg = getLongPathname(argv[i]); if (verbose) { - printf("processing bundle \"%s\"\n", argv[i]); + u_fprintf(ustderr, "processing bundle \"%s\"\n", argv[i]); } p = uprv_strrchr(arg, U_FILE_SEP_CHAR); @@ -267,7 +237,7 @@ main(int argc, char* argv[]) { bundle = ures_open(fromICUData ? 0 : inputDir, locale, &status); } if (status == U_ZERO_ERROR) { - FILE *out; + UFILE *out = NULL; const char *filename = 0; const char *ext = 0; @@ -292,13 +262,7 @@ main(int argc, char* argv[]) { } if (tostdout) { - out = stdout; -#if U_PLATFORM_HAS_WIN32_API - if (setmode(fileno(out), O_BINARY) == -1) { - fprintf(stderr, "%s: couldn't set standard output to binary mode\n", pname); - return 4; - } -#endif + out = u_get_stdout(); } else { char thefile[4096], *tp; int32_t len; @@ -319,42 +283,47 @@ main(int argc, char* argv[]) { } uprv_strcpy(tp, "txt"); - out = fopen(thefile, "w"); + out = u_fopen(thefile, "w", NULL, encoding); if (!out) { - fprintf(stderr, "%s: couldn't create %s\n", pname, thefile); - return 4; + u_fprintf(ustderr, "%s: couldn't create %s\n", pname, thefile); + u_fclose(ustderr); + return 4; } } + // now, set the callback. + ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); + if (U_FAILURE(status)) { + u_fprintf(ustderr, "%s: couldn't configure converter for encoding\n", pname); + u_fclose(ustderr); + if(!tostdout) { + u_fclose(out); + } + return 3; + } + if (prbom) { /* XXX: Should be done only for UTFs */ - static const UChar bom[] = { 0xFEFF }; - printString(out, converter, bom, (int32_t)(sizeof(bom)/sizeof(*bom))); + u_fputc(0xFEFF, out); } - - printCString(out, converter, "// -*- Coding: ", -1); - printCString(out, converter, encoding ? encoding : getEncodingName(ucnv_getDefaultName()), -1); - printCString(out, converter, "; -*-\n//\n", -1); - printCString(out, converter, "// This file was dumped by derb(8) from ", -1); + u_fprintf(out, "// -*- Coding: %s; -*-\n//\n", encoding ? encoding : getEncodingName(ucnv_getDefaultName())); + u_fprintf(out, "// This file was dumped by derb(8) from "); if (thename) { - printCString(out, converter, thename, -1); + u_fprintf(out, "%s", thename); } else if (fromICUData) { - printCString(out, converter, "the ICU internal ", -1); - printCString(out, converter, locale, -1); - printCString(out, converter, " locale", -1); + u_fprintf(out, "the ICU internal %s locale", locale); } - printCString(out, converter, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n", -1); + u_fprintf(out, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n"); if (locale[0]) { - printCString(out, converter, locale, -1); + u_fprintf(out, "%s", locale); } else { - printCString(out, converter, filename, (int32_t)(ext - filename)); - printString(out, converter, sp, (int32_t)(sizeof(sp)/sizeof(*sp))); + u_fprintf(out, "%.*s%.*S", (int32_t)(ext - filename), filename, (int32_t)(sizeof(sp)/sizeof(*sp)), sp); } printOutBundle(out, converter, bundle, 0, pname, &status); - if (out != stdout) { - fclose(out); + if (!tostdout) { + u_fclose(out); } } else { @@ -364,7 +333,6 @@ main(int argc, char* argv[]) { ures_close(bundle); } - ucnv_close(defaultConverter); ucnv_close(converter); return 0; @@ -407,47 +375,19 @@ static UChar *quotedString(const UChar *string) { } -static void printString(FILE *out, UConverter *converter, const UChar *str, int32_t len) { - char buf[256]; - const UChar *strEnd; - - if (len < 0) { - len = u_strlen(str); - } - strEnd = str + len; - - do { - UErrorCode err = U_ZERO_ERROR; - char *bufp = buf, *bufend = buf + sizeof(buf) - 1 ; - - ucnv_fromUnicode(converter, &bufp, bufend, &str, strEnd, 0, 0, &err); - *bufp = 0; - - fprintf(out, "%s", buf); - } while (str < strEnd); +static void printString(UFILE *out, UConverter *converter, const UChar *str, int32_t len) { + u_file_write(str, len, out); } -static void printCString(FILE *out, UConverter *converter, const char *str, int32_t len) { - UChar buf[256]; - const char *strEnd; - - if (len < 0) { - len = (int32_t)uprv_strlen(str); - } - strEnd = str + len; - - do { - UErrorCode err = U_ZERO_ERROR; - UChar *bufp = buf, *bufend = buf + (sizeof(buf)/sizeof(buf[0])) - 1 ; - - ucnv_toUnicode(defaultConverter, &bufp, bufend, &str, strEnd, 0, 0, &err); - *bufp = 0; - - printString(out, converter, buf, (int32_t)(bufp - buf)); - } while (str < strEnd); +static void printCString(UFILE *out, UConverter *converter, const char *str, int32_t len) { + if(len==-1) { + u_fprintf(out, "%s", str); + } else { + u_fprintf(out, "%.*s", len, str); + } } -static void printIndent(FILE *out, UConverter *converter, int32_t indent) { +static void printIndent(UFILE *out, UConverter *converter, int32_t indent) { UChar inchar[256]; int32_t i = 0; for(i = 0; ifResData), r, &len); @@ -501,7 +441,7 @@ static void printOutAlias(FILE *out, UConverter *converter, UResourceBundle *pa uprv_free(string); } -static void printOutBundle(FILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) +static void printOutBundle(UFILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) { static const UChar cr[] = { '\n' }; @@ -724,7 +664,7 @@ static const char *getEncodingName(const char *encoding) { } static void reportError(const char *pname, UErrorCode *status, const char *when) { - fprintf(stderr, "%s: error %d while %s: %s\n", pname, *status, when, u_errorName(*status)); + u_fprintf(ustderr, "%s: error %d while %s: %s\n", pname, *status, when, u_errorName(*status)); } /* @@ -732,5 +672,3 @@ static void reportError(const char *pname, UErrorCode *status, const char *when) * indent-tabs-mode: nil * End: */ - - diff --git a/icu4c/source/tools/genrb/derb.vcxproj b/icu4c/source/tools/genrb/derb.vcxproj index 549b9eb4fe6..a7ef76794e1 100644 --- a/icu4c/source/tools/genrb/derb.vcxproj +++ b/icu4c/source/tools/genrb/derb.vcxproj @@ -91,7 +91,7 @@ .\x86\Release_derb/derb.tlb - ..\..\common;..\toolutil;%(AdditionalIncludeDirectories) + ..\..\i18n;..\..\common;..\toolutil;..\..\io;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -135,7 +135,7 @@ Disabled - ..\..\common;..\toolutil;%(AdditionalIncludeDirectories) + ..\..\i18n;..\..\common;..\toolutil;..\..\io;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -180,7 +180,7 @@ .\x64\Release_derb/derb.tlb - ..\..\common;..\toolutil;%(AdditionalIncludeDirectories) + ..\..\i18n;..\..\common;..\toolutil;..\..\io;%(AdditionalIncludeDirectories) WIN64;WIN32;NDEBUG;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -222,7 +222,7 @@ Disabled - ..\..\common;..\toolutil;%(AdditionalIncludeDirectories) + ..\..\i18n;..\..\common;..\toolutil;..\..\io;%(AdditionalIncludeDirectories) WIN64;WIN32;_DEBUG;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -259,6 +259,17 @@ {73c0a65b-d1f2-4de1-b3a6-15dad2c23f3d} false + + {0178b127-6269-407d-b112-93877bb62776} + + + {c2b04507-2521-4801-bf0d-5fd79d6d518c} + true + false + false + true + false + {6b231032-3cb5-4eed-9210-810d666a23a0} false @@ -267,4 +278,4 @@ - + \ No newline at end of file