From 9dda74b4b1489343337405981ff9ccc1fcb9f912 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 13 Jul 2011 01:26:20 +0000 Subject: [PATCH] ICU-8157 update, support dateformat X-SVN-Rev: 30321 --- tools/multi/proj/provider/Makefile | 88 ++++-- tools/multi/proj/provider/coldiff.cpp | 40 +-- tools/multi/proj/provider/datediff.cpp | 123 ++++++++ tools/multi/proj/provider/glue/coll_fe.c | 21 -- tools/multi/proj/provider/glue/coll_fe.cpp | 6 + tools/multi/proj/provider/glue/date_fe.cpp | 338 +++++++++++++++++++++ tools/multi/proj/provider/glue/export.txt | 2 - tools/multi/proj/provider/glue/oicu.h | 41 ++- 8 files changed, 589 insertions(+), 70 deletions(-) create mode 100644 tools/multi/proj/provider/datediff.cpp delete mode 100644 tools/multi/proj/provider/glue/coll_fe.c create mode 100644 tools/multi/proj/provider/glue/date_fe.cpp delete mode 100644 tools/multi/proj/provider/glue/export.txt diff --git a/tools/multi/proj/provider/Makefile b/tools/multi/proj/provider/Makefile index b2ddc3b60e0..f4fe8b6bcb5 100644 --- a/tools/multi/proj/provider/Makefile +++ b/tools/multi/proj/provider/Makefile @@ -3,6 +3,8 @@ # all: glurens ii plugs testprog +# extra files that need generation. +PLUG_EXTRA_DEPS= UNAME=$(shell uname) ifeq ($(UNAME),Linux) @@ -14,7 +16,8 @@ PLUGLIB_SO=so else ifeq ($(UNAME),Darwin) LIBPATH_VAR=DYLD_LIBRARY_PATH -PLUG_EXTRA_LDFLAGS=-exported_symbols_list glue/export.txt -dynamiclib -dynamic +PLUG_EXTRA_LDFLAGS=-exported_symbols_list $(GLUE_EXPORT) -dynamiclib -dynamic +PLUG_EXTRA_DEPS+=$(GLUE_EXPORT) PLUGLIB_SO=dylib else $(warning **********************************) @@ -22,6 +25,7 @@ $(warning this script may not know how to handle your $(UNAME) system) endif endif +srcdir=$(shell pwd) PROVIDER=provider LIBPROVIDER=lib$(PROVIDER).a @@ -59,6 +63,7 @@ SRC=$(M_TMP)/$(P_PREFIX)src OUT=$(TOP)/out SOURCE=$(S_SRCDIR) GLUE=glue +GLUE_EXPORT=$(GLUE)/export.txt GLOUT=$(M_TMP)/$(P_PREFIX)glout # header locations INCGLUE=$(TOP)/$(GLUE)/include @@ -92,18 +97,15 @@ MAKE_XTRA_OPTS="PKGDATA_MODE=static" # additional options passed to make install MAKE_INSTALL_XTRA_OPTS=$(MAKE_XTRA_OPTS) -# Munged source names: list of C, C++, O etc files for Backend -#GL_BE_C=$(shell cd $(GLUE) ; ls *_be.c) -#GL_BE_CXX=$(shell cd $(GLUE) ; ls *_be.cpp) -#GL_BE_O=$(GL_BE_C:%.c=%.o) $(GL_BE_CPP:%.cpp=%.o) -# Munged source names: list of C, C++, O etc files for Frontend -#GL_FE_C=$(shell cd $(GLUE) ; ls *_fe.c) -GL_FE_CXX=$(shell cd $(GLUE) ; ls *_fe.cpp) +# Munged source names: list of C++, O etc files for Frontend +PARTSUFF=_fe +GL_FE_CXX=$(shell cd $(GLUE) ; ls *$(PARTSUFF).cpp) +GL_FE_FILES=$(GL_FE_CXX:%.cpp=$(GLUE)/%.cpp) GL_FE_O=$(GL_FE_CPP:%.cpp=%.o) +GL_PARTS=$(GL_FE_CXX:%$(PARTSUFF).cpp=%) # C flags used in Glue compilation GLUE_CFLAGS=-I$(INCGLUE) $(GLUE_EXTRA_CFLAGS) - # icu-config switches for compiling: C and C++ ICU_CONFIG_COMMON=--cppflags # icu-config switches for C @@ -135,7 +137,7 @@ $(PLUGLIB_ICU_CONFIG): # build the glue objects for TARGET # used to be %/* instead of $(PLUGLIB) - now, wire it down to pluglib. -$(GLOUT)/$(PLUGLIB)/obj-$(OK): $(GLOUT) glurens $(PLUGLIB_ICU_CONFIG) +$(GLOUT)/$(PLUGLIB)/obj-$(OK): $(GLOUT) glurens $(PLUGLIB_ICU_CONFIG) $(GL_FE_FILES) -mkdir $(GLOUT)/$(PLUGLIB) # $(shell $(BUILD)/$(PLUGLIB)/config/$(ICU_CONFIG) $(ICU_CONFIG_CC)) $(GLUE_CFLAGS) -c -DICUGLUE_VER=$(PLUGLIB) -o $(GLOUT)/$(PLUGLIB)/gl_be_c_$(PLUGLIB).o $(GL_BE_C:%.c=$(GLUE)/%.c) # $(shell $(BUILD)/$(PLUGLIB)/config/$(ICU_CONFIG) $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -c -DICUGLUE_VER=$(PLUGLIB) -o $(GLOUT)/$(PLUGLIB)/gl_be_cxx_$(PLUGLIB).o $(GL_BE_CXX:%.cpp=$(GLUE)/%.cpp) @@ -144,21 +146,26 @@ $(GLOUT)/$(PLUGLIB)/obj-$(OK): $(GLOUT) glurens $(PLUGLIB_ICU_CONFIG) # for each version.. build all OTHER FE files # TODO: check is unnecessary, not permitted. # TODO: change to depend instead of for list. - for ver in $(PLUGLIB_AVAILABLE) ; \ + @for ver in $(PLUGLIB_AVAILABLE) ; \ do \ echo building $$ver for $(PLUGLIB) ; \ if [ ! "$$ver" = "$(PLUGLIB)" ]; \ then \ - $(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -c -I$(TOP)/$(BUILD)/$$ver/gluren/include -DICUGLUE_VER=$$ver "-DICUGLUE_VER_STR=\"$$ver\"" "-DGLUE_SYM(x)=glue ## x ## $$ver" -o $(GLOUT)/$(PLUGLIB)/gl_fe_cxx_$${ver}_x_$(PLUGLIB).o $(GL_FE_CXX:%.cpp=$(GLUE)/%.cpp) $(XOPTS) ; \ + for part in $(GL_PARTS) ; \ + do \ + echo $(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -c -I$(TOP)/$(BUILD)/$$ver/gluren/include -DICUGLUE_VER=$$ver "-DICUGLUE_VER_STR=\"$$ver\"" "-DGLUE_SYM(x)=glue ## x ## $$ver" -o $(GLOUT)/$(PLUGLIB)/$${part}_$${ver}_for_$(PLUGLIB).o $(GLUE)/$${part}$(PARTSUFF).cpp $(XOPTS) ; \ + $(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -c -I$(TOP)/$(BUILD)/$$ver/gluren/include -DICUGLUE_VER=$$ver "-DICUGLUE_VER_STR=\"$$ver\"" "-DGLUE_SYM(x)=glue ## x ## $$ver" -o $(GLOUT)/$(PLUGLIB)/$${part}_$${ver}_for_$(PLUGLIB).o $(GLUE)/$${part}$(PARTSUFF).cpp $(XOPTS) || exit 1; \ + done ; \ echo " GLUE_VER( $$ver ) " >> $(GLOUT)/$(PLUGLIB)/include/icuglue/glver.h; \ fi \ done # build 'this version' FE files @echo Building FE for $(PLUGLIB) - $(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -I$(GLOUT)/$(PLUGLIB)/include -c -o $(GLOUT)/$(PLUGLIB)/gl_fe_cxx_$(PLUGLIB).o $(GL_FE_CXX:%.cpp=$(GLUE)/%.cpp) $(XOPTS) -# build 'this version' BE files (disabled for now) -# $(shell $(BUILD)/$(PLUGLIB)/config/$(ICU_CONFIG) $(ICU_CONFIG_CC)) $(GLUE_CFLAGS) -c -DICUGLUE_VER=$(PLUGLIB) -o $(GLOUT)/$(PLUGLIB)/gl_be_c_$(PLUGLIB).o $(GL_BE_C:%.c=$(GLUE)/%.c) -# $(shell $(BUILD)/$(PLUGLIB)/config/$(ICU_CONFIG) $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -c -DICUGLUE_VER=$(PLUGLIB) -o $(GLOUT)/$(PLUGLIB)/gl_be_cxx_$(PLUGLIB).o $(GL_BE_CXX:%.cpp=$(GLUE)/%.cpp) + @for part in $(GL_PARTS) ; \ + do \ + echo $(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -I$(GLOUT)/$(PLUGLIB)/include -c -o $(GLOUT)/$(PLUGLIB)/$${part}_$(PLUGLIB).o $(GLUE)/$${part}$(PARTSUFF).cpp $(XOPTS) ; \ + $(shell $(PLUGLIB_ICU_CONFIG) --noverify $(ICU_CONFIG_CXX)) $(GLUE_CFLAGS) -I$(GLOUT)/$(PLUGLIB)/include -c -o $(GLOUT)/$(PLUGLIB)/$${part}_$(PLUGLIB).o $(GLUE)/$${part}$(PARTSUFF).cpp $(XOPTS) || exit 1; \ + done touch $@ plugs: $(PLUGLIB_OUTLIBS) $(OUT)/$(PLUGLIB_MAJ:%=icuplugins%.txt) @@ -169,29 +176,58 @@ install-plugs: $(PLUGLIB_INST)/lib/$(PLUGLIB_NAME) $(PLUGLIB_INST)/lib/icu/icupl #TODO: should be 'install' not 'cp' $(PLUGLIB_INST)/lib/$(PLUGLIB_NAME) $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt: $(PLUGLIB_OUTLIBS) cp $(PLUGLIB_OUTLIBS) $(PLUGLIB_INST)/lib - echo "$(PLUGLIB_NAME) coll_provider_plugin" > $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt + echo "# Generated. " > $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt + @for part in $(GL_PARTS) ; \ + do \ + echo "$(PLUGLIB_NAME) $${part}_provider_plugin" >> $(PLUGLIB_INST)/lib/icu/icuplugins$(PLUGLIB_MAJ).txt ; \ + echo " $${part}_provider_plugin" ; \ + done -$(OUT)/icuplugins$(PLUGLIB_MAJ).txt: $(PLUGLIB_OUTLIBS) - echo "$(PLUGLIB_NAME) coll_provider_plugin" > $@ +$(GLUE_EXPORT): Makefile $(GL_FE_FILES) + echo "# Generated for installation. " > $@ + @for part in $(GL_PARTS) ; \ + do \ + echo "_$${part}_provider_plugin" >> $@ ; \ + echo " _$${part}_provider_plugin" ; \ + done -TESTPROG=coldiff +$(OUT)/icuplugins$(PLUGLIB_MAJ).txt: $(PLUGLIB_OUTLIBS) Makefile + echo "# Generated for testing." > $@ + @for part in $(GL_PARTS) ; \ + do \ + echo "$(PLUGLIB_NAME) $${part}_provider_plugin" >> $@ ; \ + echo " $${part}_provider_plugin" ; \ + done + +TESTPROG=coldiff datediff testprog: $(PLUGLIB:%=$(OUT)/%/bin/$(TESTPROG)) check: all testprog $(OUT)/icuplugins$(PLUGLIB_MAJ).txt ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib $(PLUGLIB_INST)/bin/icuinfo || ( echo "ICU broken." ; /bin/false ) ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib $(PLUGLIB_INST)/bin/icuinfo -L || ( echo "Plugin broken." ; /bin/false ) - ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib out/$(PLUGLIB)/bin/coldiff || ( echo "coldiff failed." ; /bin/false ) + @for prog in $(TESTPROG) ; \ + do \ + echo "# ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib out/$(PLUGLIB)/bin/$${prog}" ; \ + ICU_PLUGINS=$(OUT) $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib:out/$(PLUGLIB)/lib out/$(PLUGLIB)/bin/$${prog} || ( echo "$${prog} failed." ; /bin/false ) ; \ + done install-check: install-plugs $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib $(PLUGLIB_INST)/bin/icuinfo -L || ( echo "Plugin broken." ; /bin/false ) - $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib out/$(PLUGLIB)/bin/coldiff || ( echo "coldiff failed." ; /bin/false ) + @for prog in $(TESTPROG) ; \ + do \ + echo "# $${prog}" ; \ + $(LIBPATH_VAR)=$(PLUGLIB_INST)/lib out/$(PLUGLIB)/bin/$${prog} || ( echo "$${prog} against installed failed." ; /bin/false ) ; \ + done -$(OUT)/%/bin/$(TESTPROG): $(TESTPROG).cpp $(OUT)/$(PLUGLIB)/provider_version.h - -mkdir -p $(OUT)/$*/bin - $(shell $(PLUGLIB_ICU_CONFIG) --cxx --cxxflags --cppflags --ldflags) -o $@ -I$(OUT)/$(PLUGLIB) $(TESTPROG).cpp +$(OUT)/$(PLUGLIB)/bin/$(TESTPROG): $(GLOUT)/$(PLUGLIB)/obj-$(OK) $(OUT)/$(PLUGLIB)/provider_version.h + -mkdir -p $(OUT)/$(PLUGLIB)/bin + @for prog in $(TESTPROG) ; \ + do \ + $(shell $(PLUGLIB_ICU_CONFIG) --cxx --cxxflags --cppflags --ldflags) -o $(OUT)/$(PLUGLIB)/bin/$${prog} -I$(OUT)/$(PLUGLIB) $(srcdir)/$${prog}.cpp ; \ + done -$(OUT)/%/lib/$(PLUGLIB_NAME): $(GLOUT)/%/obj-$(OK) +$(OUT)/%/lib/$(PLUGLIB_NAME): $(GLOUT)/%/obj-$(OK) $(PLUG_EXTRA_DEPS) -mkdir -p $(OUT)/$*/lib $(shell $(PLUGLIB_ICU_CONFIG) --cxx --cxxflags --cppflags --ldflags) $(PLUG_EXTRA_LDFLAGS) -shared -o $@ $(GLOUT)/$*/*.o $(PLUGLIB_AVAILABLE_DATA) $(PLUGLIB_AVAILABLE_STATICS) diff --git a/tools/multi/proj/provider/coldiff.cpp b/tools/multi/proj/provider/coldiff.cpp index 5870b90be66..563816cc0a3 100644 --- a/tools/multi/proj/provider/coldiff.cpp +++ b/tools/multi/proj/provider/coldiff.cpp @@ -60,7 +60,7 @@ int main(int /* argc*/ , const char * /*argv*/ []) { strcat(locID, provider_version[v]); } - printf("%28s : ", locID); + printf("%-28s = ", locID); UErrorCode subStatus = U_ZERO_ERROR; uint8_t bytes[200]; @@ -80,7 +80,7 @@ int main(int /* argc*/ , const char * /*argv*/ []) { strcpy(xbuf2,"X/"); strcat(xbuf2,locID); strcat(xbuf2,"/"); - printf(" -> %s\n", xbuf2); + //printf(" -> %s\n", xbuf2); UCollator *col = ucol_openFromShortString(xbuf2, FALSE,NULL, &subStatus); #else UCollator *col = ucol_open(locID, &subStatus); @@ -104,14 +104,18 @@ int main(int /* argc*/ , const char * /*argv*/ []) { int32_t len = ucol_getSortKey(col, stuff, -1, bytes, 200); #endif + printf(" "); + + int tdiffs=0; + for(int i=0;i reopened = %s (%s)\n", xbuf4, u_errorName(subStatus)); + int32_t def4 = ucol_getShortDefinitionString(col,locID/*NULL*/,xbuf4,200,&subStatus); + if(strcmp(xbuf4,xbuf3)) { + printf(" --> reopened = %s (%s)\n", xbuf4, u_errorName(subStatus)); + } } int32_t len2 = ucol_getSortKey(col2, stuff, -1, bytesb, 200); @@ -131,18 +137,18 @@ int main(int /* argc*/ , const char * /*argv*/ []) { if(i0) { - printf(" - ERR! Diffs from %s in %d places", xbuf2,baddiffs); + printf(" - ERR! Diffs from %s in %d places\n", xbuf2,baddiffs); gbaddiffs+=baddiffs; } else { - printf(" OK.\n"); + //printf(" OK.\n"); } - printf("\n"); + // printf("\n"); diff --git a/tools/multi/proj/provider/datediff.cpp b/tools/multi/proj/provider/datediff.cpp new file mode 100644 index 00000000000..78bbc9541cf --- /dev/null +++ b/tools/multi/proj/provider/datediff.cpp @@ -0,0 +1,123 @@ +/* +******************************************************************************* +* +* Copyright (C) 2009-2011, International Business Machines +* Corporation and others. All Rights Reserved. +* +******************************************************************************* +*/ + +#include +#include +#include +#include +#include +#include + + +/* String to use. */ +const UDate stuff = 1299977771000.0L; + +#include "provider_version.h" + + +#define LOCALE_COUNT 4 +const char *locale[LOCALE_COUNT] = { "fi", "en_US", "ja", "ml" }; /* List of locales to test */ + +/** + * Set up ICU, print # of available collators + */ +void setup(UErrorCode &status) { + u_init(&status); + + fprintf(stderr, "ICU %s init: %s\n", U_ICU_VERSION, u_errorName(status)); + + // int32_t count; + // StringEnumeration *se = DateFormat::getAvailableLocales(); + // count = se->count(status); + // fprintf(stderr, "# DateFormats now available: %d,\t%s - %d providers expected.\n", count, u_errorName(status), (int32_t)PROVIDER_COUNT); +} + +int main(int /* argc*/ , const char * /*argv*/ []) { + UErrorCode status = U_ZERO_ERROR; + int diffs = 0; + int gbaddiffs =0; + setup(status); + if(U_FAILURE(status)) return 1; + + int expected = PROVIDER_COUNT; + + for(int l=0;l0) { + // printf("ERROR: %d diffs found between a collator and it's reopened (from shortstring) variant.\n", gbaddiffs); + // return 2; + // } else { + // printf("Collator and reopened (shortstring) are OK.\n"); + // } + + printf("Success!\n"); + + return 0; +} diff --git a/tools/multi/proj/provider/glue/coll_fe.c b/tools/multi/proj/provider/glue/coll_fe.c deleted file mode 100644 index d7627fd6d3c..00000000000 --- a/tools/multi/proj/provider/glue/coll_fe.c +++ /dev/null @@ -1,21 +0,0 @@ -/* -******************************************************************************* -* -* Copyright (C) 2009-2011, International Business Machines -* Corporation and others. All Rights Reserved. -* -******************************************************************************* -*/ - -/* -not needed. -*/ - - -static void not_needed () { - return; -} - - - - diff --git a/tools/multi/proj/provider/glue/coll_fe.cpp b/tools/multi/proj/provider/glue/coll_fe.cpp index d2f43ae8198..148a3f27db2 100644 --- a/tools/multi/proj/provider/glue/coll_fe.cpp +++ b/tools/multi/proj/provider/glue/coll_fe.cpp @@ -103,8 +103,14 @@ static UCollationStrength _getUCollationStrength( /* code for some version */ #include + #include "oicu.h" +/* Expand GLUE_VER to define the class */ +#ifdef GLUE_VER +GLUE_VER( ICUGLUE_VER ) +#endif + GLUE_SYM ( Collator ) :: ~ GLUE_SYM(Collator) () { #if COLL_FE_DEBUG fprintf(stderr, "VCF " ICUGLUE_VER_STR " ucol_close"); diff --git a/tools/multi/proj/provider/glue/date_fe.cpp b/tools/multi/proj/provider/glue/date_fe.cpp new file mode 100644 index 00000000000..495bf2ca838 --- /dev/null +++ b/tools/multi/proj/provider/glue/date_fe.cpp @@ -0,0 +1,338 @@ +/* +******************************************************************************* +* +* Copyright (C) 2009-2011, International Business Machines +* Corporation and others. All Rights Reserved. +* +******************************************************************************* +*/ + +#ifndef DATE_FE_DEBUG +#define DATE_FE_DEBUG 0 +#endif + +#include +#include "unicode/udat.h" +//#include +#include "unicode/datefmt.h" +#include "unicode/smpdtfmt.h" +#include +#include +#include "unicode/ustring.h" +#include "unicode/gregocal.h" + + + +/** + * Macro to define the Collator_glue_4_2 class + */ +#ifdef GLUE_VER +#error GLUE_VER is defined +#endif + +#define GLUE_VER(x) class GLUE_SYM_V( DateFormat, x ) : public DateFormat { \ + public: static DateFormat *create(const Locale &loc, const char *ver); \ + private: UDateFormat *_this; GLUE_SYM_V( DateFormat, x ) ( UDateFormat* tn ); \ + virtual ~ GLUE_SYM_V ( DateFormat, x) (); \ + public: \ + virtual void* getDynamicClassID() const; \ + static void* getStaticClassID() ; \ + virtual UnicodeString& format( Calendar& cal, UnicodeString& appendTo, FieldPosition& pos) const; \ + virtual void parse( const UnicodeString& text, Calendar& cal, ParsePosition& pos) const; \ + virtual Format* clone(void) const; \ + public: static int32_t countAvailable(); \ +public: static int32_t appendAvailable(UnicodeString* strs, int32_t i, int32_t count); \ + }; \ + + + +/** ==================================== The following code runs inside the 'target' version (i.e. old ICU) ========== **/ +#if defined ( ICUGLUE_VER ) + + + +/* code for some version */ +#include +#include "oicu.h" + +#ifdef GLUE_VER +GLUE_VER( ICUGLUE_VER ) +#endif + +GLUE_SYM (DateFormat ) :: GLUE_SYM(DateFormat) ( UDateFormat* tn) : + _this(tn) +{ + + UErrorCode status = U_ZERO_ERROR; + adoptCalendar(new GregorianCalendar(status)); +} + +GLUE_SYM ( DateFormat ) :: ~ GLUE_SYM(DateFormat) () { +#if DATE_FE_DEBUG + fprintf(stderr, "VCF " ICUGLUE_VER_STR " udat_close"); +#endif + OICU_udat_close(_this); +} + +DateFormat * +GLUE_SYM ( DateFormat ) :: create(const Locale &loc, const char */*ver*/) { + // TODO: save 'ver' off. + UErrorCode status = U_ZERO_ERROR; + char locBuf[200]; + char kwvBuf[200]; + // int32_t len = loc.getKeywordValue("collation", kwvBuf, 200, status); + //strcpy(locBuf,loc.getBaseName()); + // if(len>0) { + // strcat(locBuf,"@collator="); + // strcat(locBuf,kwvBuf); + // } + UDateFormat * uc = OICU_udat_open( UDAT_FULL, UDAT_FULL, loc.getName(), + NULL, + -1, + NULL, + -1, + &status); + if(U_FAILURE(status)) return NULL; // TODO: ERR? + DateFormat *c = new GLUE_SYM( DateFormat ) ( uc ); +#if DATE_FE_DEBUG + fprintf(stderr, "VCF " ICUGLUE_VER_STR " udat_open=%s ->> %p\n", loc.getName(), (void*)c); +#endif + return c; +} + +UnicodeString& GLUE_SYM (DateFormat ) :: format( Calendar& cal, UnicodeString& appendTo, FieldPosition& pos) const +{ +#if DATE_FE_DEBUG + fprintf(stderr, "VCF " ICUGLUE_VER_STR " - formatting. \n"); +#endif + int32_t len = appendTo.length(); + + UChar junk[200]; + UErrorCode status = U_ZERO_ERROR; + + UFieldPosition pos2; + + int32_t nlen = OICU_udat_format(_this, + cal.getTime(status), + junk, + 200, + &pos2, + &status); + + // todo: use pos2 + pos.setBeginIndex(len); + pos.setEndIndex(len += nlen); + appendTo.append(junk, nlen); + + return appendTo; +} + +void GLUE_SYM (DateFormat ) :: parse( const UnicodeString& text, Calendar& cal, ParsePosition& pos) const +{ + return; +} + +Format* GLUE_SYM (DateFormat ) :: clone(void) const +{ + return NULL; +} + + + + int32_t GLUE_SYM ( DateFormat ) :: countAvailable() { + int32_t count = OICU_udat_countAvailable(); + return count; + } + + +int32_t GLUE_SYM ( DateFormat ) :: appendAvailable(UnicodeString* strs, int32_t i, int32_t /*count*/) { + int avail = OICU_udat_countAvailable(); + UErrorCode status = U_ZERO_ERROR; + OICU_u_init(&status); +#if DATE_FE_DEBUG + fprintf(stderr, "VCF " ICUGLUE_VER_STR " avail %d - init %s\n", avail, u_errorName(status)); +#endif + for(int j=0;j>\n", i, j, i+j, foo); + } +#endif + } + return OICU_ucol_countAvailable(); + } + +UOBJECT_DEFINE_RTTI_IMPLEMENTATION( GLUE_SYM( DateFormat ) ) + + + + +#else +/** ==================================== The following code runs inside the 'provider' version (i.e. current ICU) ========== **/ + +// define Collator_XX +#include "icuglue/glver.h" + +// generate list of versions +static +#include + +class VersionDateFormatFactory : public UObject { +public: + virtual DateFormat *createFormat(const Locale &loc); + virtual const UnicodeString *getSupportedIDs(int32_t &count, UErrorCode &status); + virtual void* getDynamicClassID() const; + static void* getStaticClassID() ; +}; + +UOBJECT_DEFINE_RTTI_IMPLEMENTATION( VersionDateFormatFactory ) + +DateFormat *VersionDateFormatFactory::createFormat(const Locale &loc) { + // pull off provider # + char provider[200]; + UErrorCode status = U_ZERO_ERROR; +#if DATE_FE_DEBUG + fprintf(stderr, "VCF:CC %s\n", loc.getName()); +#endif + int32_t len = loc.getKeywordValue("sp", provider, 200, status); + if(U_FAILURE(status)||len==0) return NULL; +#if DATE_FE_DEBUG + fprintf(stderr, "VCF:KWV> %s/%d\n", u_errorName(status), len); +#endif + provider[len]=0; +#if DATE_FE_DEBUG + fprintf(stderr, "VCF:KWV %s\n", provider); +#endif + if(strncmp(provider,"icu",3)) return NULL; + const char *icuver=provider+3; +#if DATE_FE_DEBUG + fprintf(stderr, "VCF:ICUV %s\n", icuver); +#endif + +#if defined(GLUE_VER) +#undef GLUE_VER +#endif +#define GLUE_VER(x) /*printf("%c/%c|%c/%c\n", icuver[0],(#x)[0],icuver[1],(#x)[2]);*/ if(icuver[0]== (#x)[0] && icuver[1]==(#x)[2]) { DateFormat *c = glue ## DateFormat ## x :: create(loc, icuver); /*fprintf(stderr, "VCF::CC %s -> %p\n", loc.getName(), c);*/ return c; } +#include "icuglue/glver.h" +#if DATE_FE_DEBUG + fprintf(stderr, "VCF:CC %s failed\n", loc.getName()); +#endif + + return NULL; +} + + +static const UnicodeString *gLocalesDate = NULL; +static int32_t gLocCountDate = 0; + + +const UnicodeString +*VersionDateFormatFactory::getSupportedIDs(int32_t &count, UErrorCode &/*status*/) { + if(gLocalesDate==NULL) { + count = 0; + + + /* gather counts */ + +#if defined(GLUE_VER) +#undef GLUE_VER +#endif +#define GLUE_VER(x) count += glue ## DateFormat ## x :: countAvailable(); +#include "icuglue/glver.h" + +#if DATE_FE_DEBUG + printf("VCF: count=%d\n", count); +#endif + UnicodeString *strs = new UnicodeString[count]; + int32_t i = 0; + +#if defined(GLUE_VER) +#undef GLUE_VER +#endif +#define GLUE_VER(x) i += glue ## DateFormat ## x :: appendAvailable(strs, i, count); +#include "icuglue/glver.h" + +#if DATE_FE_DEBUG + printf("VCF: appended count=%d\n", count); +#endif + + gLocCountDate = count; + gLocalesDate = strs; + } + count = gLocCountDate; + return gLocalesDate; +} + + +/* Plugin Code */ + +#include +#include + +//static URegistryKey rkdate = NULL; + +VersionDateFormatFactory vdf; + +extern "C" UDateFormat *versionDateFormatOpener(UDateFormatStyle timeStyle, + UDateFormatStyle dateStyle, + const char *locale, + const UChar *tzID, + int32_t tzIDLength, + const UChar *pattern, + int32_t patternLength, + UErrorCode *status) { + Locale loc(locale); + DateFormat *df = vdf.createFormat(loc); + // printf("Hey! I got: %s -> %p\n", locale, df); + return (UDateFormat*)df; +} + +void date_provider_register(UErrorCode &status) { + udat_registerOpener(versionDateFormatOpener, &status); + // rkdate = DateFormat::registerFactory(new VersionDateFormatFactory(), status); +} + +void date_provider_unregister(UErrorCode &status) { + udat_unregisterOpener(versionDateFormatOpener, &status); +} + +/* Plugin- only ICU 4.4+ */ +#if (U_ICU_VERSION_MAJOR_NUM > 4) || ((U_ICU_VERSION_MAJOR_NUM==4)&&(U_ICU_VERSION_MINOR_NUM>3)) +#include "unicode/icuplug.h" + +U_CAPI UPlugTokenReturn U_EXPORT2 date_provider_plugin (UPlugData *data, UPlugReason reason, UErrorCode *status); + +U_CAPI UPlugTokenReturn U_EXPORT2 date_provider_plugin (UPlugData *data, UPlugReason reason, UErrorCode *status) +{ + switch(reason) { + case UPLUG_REASON_QUERY: + uplug_setPlugName(data, "Date Provider Plugin"); + uplug_setPlugLevel(data, UPLUG_LEVEL_HIGH); + break; + case UPLUG_REASON_LOAD: + date_provider_register(*status); + break; + case UPLUG_REASON_UNLOAD: + date_provider_unregister(*status); + break; + default: + break; /* not handled */ + } + return UPLUG_TOKEN; +} +#else + +/* + Note: this ICU version must explicitly call 'date_provider_plugin' +*/ + +#endif /* plugin */ + +#endif /* provider side (vs target) */ diff --git a/tools/multi/proj/provider/glue/export.txt b/tools/multi/proj/provider/glue/export.txt deleted file mode 100644 index 07ab78402ef..00000000000 --- a/tools/multi/proj/provider/glue/export.txt +++ /dev/null @@ -1,2 +0,0 @@ -# Copyright (C) 2010 International Business Machines Corporation and Others. All Rights Reserved. -_coll_provider_plugin diff --git a/tools/multi/proj/provider/glue/oicu.h b/tools/multi/proj/provider/glue/oicu.h index beb8bd89515..5fca507dcf3 100644 --- a/tools/multi/proj/provider/glue/oicu.h +++ b/tools/multi/proj/provider/glue/oicu.h @@ -10,12 +10,14 @@ #ifndef _OICU #define _OICU +#include "unicode/uclean.h" /** uclean.h */ U_STABLE void U_EXPORT2 OICU_u_init(UErrorCode *status); +#include "unicode/ucol.h" /** ucol.h */ @@ -40,9 +42,6 @@ const UChar * target, int32_t targetLength ); -U_STABLE int32_t U_EXPORT2 -OICU_ucol_countAvailable(); - U_STABLE void U_EXPORT2 OICU_ucol_setStrength(const UCollator *, UCollationStrength ); @@ -54,6 +53,10 @@ OICU_ucol_setStrength(const UCollator *, UCollationStrength ); U_STABLE const char * U_EXPORT2 OICU_ucol_getAvailable(int32_t i); +U_STABLE int32_t U_EXPORT2 +OICU_ucol_countAvailable(); + + U_STABLE UCollationStrength U_EXPORT2 OICU_ucol_getStrength(UCollator *col); @@ -71,11 +74,41 @@ OICU_ucol_safeClone(const UCollator *coll, int32_t *pBufferSize, UErrorCode *status); +#include "unicode/udat.h" +U_STABLE UDateFormat* U_EXPORT2 +OICU_udat_open(UDateFormatStyle timeStyle, + UDateFormatStyle dateStyle, + const char *locale, + const UChar *tzID, + int32_t tzIDLength, + const UChar *pattern, + int32_t patternLength, + UErrorCode *status); + +U_STABLE const char * U_EXPORT2 +OICU_udat_getAvailable(int32_t i); + +U_STABLE int32_t U_EXPORT2 +OICU_udat_countAvailable(); + + +U_STABLE void U_EXPORT2 +OICU_udat_close(UDateFormat* format); + +U_STABLE int32_t U_EXPORT2 +OICU_udat_format( const UDateFormat* format, + UDate dateToFormat, + UChar* result, + int32_t resultLength, + UFieldPosition* position, + UErrorCode* status); + + /** end ucol.h */ // define version -GLUE_VER( ICUGLUE_VER ) + #endif