#
all: glurens ii plugs testprog
+# extra files that need generation.
+PLUG_EXTRA_DEPS=
UNAME=$(shell uname)
ifeq ($(UNAME),Linux)
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 **********************************)
endif
endif
+srcdir=$(shell pwd)
PROVIDER=provider
LIBPROVIDER=lib$(PROVIDER).a
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
# 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
# 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)
# 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)
#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
+
+$(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
-$(OUT)/icuplugins$(PLUGLIB_MAJ).txt: $(PLUGLIB_OUTLIBS)
- echo "$(PLUGLIB_NAME) coll_provider_plugin" > $@
+$(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
+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)
strcat(locID, provider_version[v]);
}
- printf("%28s : ", locID);
+ printf("%-28s = ", locID);
UErrorCode subStatus = U_ZERO_ERROR;
uint8_t bytes[200];
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);
int32_t len = ucol_getSortKey(col, stuff, -1, bytes, 200);
#endif
+ printf(" ");
+
+ int tdiffs=0;
+
for(int i=0;i<len;i++) {
if(i<oldLen&&bytes[i]!=oldBytes[i]) {
- diffs++;
- printf("*");
- } else {
- printf(" ");
- }
- printf("%02X", (0xFF&bytes[i]));
+ diffs++;
+ printf("*");
+ } else {
+ printf(" ");
+ }
+ printf("%02X", (0xFF&bytes[i]));
}
printf("\n");
printf("Err opening from new short string : %s\n", u_errorName(subStatus));
continue;
} else {
- int32_t def4 = ucol_getShortDefinitionString(col,locID/*NULL*/,xbuf4,300,&subStatus);
- printf(" --> 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);
if(i<len&&bytes[i]!=bytesb[i]) {
baddiffs++;
printf("!");
- } else {
- printf(" ");
- }
- printf("%02X", (0xFF&bytesb[i]));
+ } else {
+ // printf(" ");
+ }
+ // printf("%02X", (0xFF&bytesb[i]));
}
if(baddiffs>0) {
- 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");
--- /dev/null
+/*
+*******************************************************************************
+*
+* Copyright (C) 2009-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+*/
+
+#include <unicode/datefmt.h>
+#include <unicode/udat.h>
+#include <unicode/uclean.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+/* 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;l<LOCALE_COUNT;l++) {
+ printf("\n");
+ UChar oldChars[200];
+ int32_t oldLen = -1;
+ for(int v=0;v<=expected;v++) {
+
+ // Construct the locale ID
+ char locID[200];
+ strcpy(locID, locale[l]);
+ if((v!=expected)) { // -1 = no version
+ strcat(locID, "@sp=icu");
+ strcat(locID, provider_version[v]);
+ }
+
+ printf("%18s : ", locID);
+
+ UErrorCode subStatus = U_ZERO_ERROR;
+ UChar outchars[200];
+
+ UDateFormat *dat = udat_open(UDAT_FULL, UDAT_FULL, locID, NULL, -1, NULL, 0, &subStatus);
+
+ if(U_FAILURE(subStatus)) {
+ printf("ERR: %s\n", u_errorName(subStatus));
+ continue;
+ }
+
+ int32_t len = udat_format(dat, stuff, outchars, 200, NULL, &subStatus);
+
+ //printf("\n");
+ char utf8[200];
+ u_strToUTF8(utf8, 200, NULL, outchars, len, &subStatus);
+ if(oldLen!=len || memcmp(outchars,oldChars,len*sizeof(outchars[0]))) {
+ putchar ('!');
+ diffs++;
+ } else {
+ putchar ('=');
+ }
+ printf(" %s ", utf8);
+
+ // for(int i=0;i<len;i++) {
+ // if((i<oldLen)&&(outchars[i]!=oldChars[i])) {
+ // diffs++;
+ // printf("*", oldChars[i]);
+ // } else {
+ // printf(" ");
+ // }
+ // // printf("U+%04X", (outchars[i]));
+ // }
+ putchar('\n');
+ udat_close(dat);
+
+ oldLen = len;
+ memcpy(oldChars, outchars, len*sizeof(oldChars[0]));
+ }
+ }
+
+ if(diffs==0) {
+ printf("ERROR: 0 differences found between platforms.. are the platforms installed? Try 'icuinfo -L'\n");
+ return 1;
+ } else {
+ printf("%d differences found among provider versions!\n", diffs);
+ }
+
+ // if(gbaddiffs>0) {
+ // 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;
+}
+++ /dev/null
-/*
-*******************************************************************************
-*
-* Copyright (C) 2009-2011, International Business Machines
-* Corporation and others. All Rights Reserved.
-*
-*******************************************************************************
-*/
-
-/*
-not needed.
-*/
-
-
-static void not_needed () {
- return;
-}
-
-
-
-
/* code for some version */
#include <icuglue/gluren.h>
+
#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");
--- /dev/null
+/*
+*******************************************************************************
+*
+* Copyright (C) 2009-2011, International Business Machines
+* Corporation and others. All Rights Reserved.
+*
+*******************************************************************************
+*/
+
+#ifndef DATE_FE_DEBUG
+#define DATE_FE_DEBUG 0
+#endif
+
+#include <icuglue/icuglue.h>
+#include "unicode/udat.h"
+//#include <unicode/tblcoll.h>
+#include "unicode/datefmt.h"
+#include "unicode/smpdtfmt.h"
+#include <string.h>
+#include <stdio.h>
+#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 <icuglue/gluren.h>
+#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<avail;j++) {
+ strs[i+j].append(OICU_udat_getAvailable(j));
+ strs[i+j].append("@sp=icu");
+ strs[i+j].append( ICUGLUE_VER_STR[0] ); // X_y
+ strs[i+j].append( ICUGLUE_VER_STR[2] ); // x_Y
+#if DATE_FE_DEBUG
+ {
+ char foo[999];
+ const UChar *ss = strs[i+j].getTerminatedBuffer();
+ u_austrcpy(foo, ss);
+ // fprintf(stderr, "VCF " ICUGLUE_VER_STR " appending [%d+%d=%d] <<%s>>\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 <icuglue/fe_verlist.h>
+
+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 <stdio.h>
+#include <unicode/uversion.h>
+
+//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) */
+++ /dev/null
-# Copyright (C) 2010 International Business Machines Corporation and Others. All Rights Reserved.
-_coll_provider_plugin
#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
*/
int32_t targetLength
);
-U_STABLE int32_t U_EXPORT2
-OICU_ucol_countAvailable();
-
U_STABLE void U_EXPORT2
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);
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