]> granicus.if.org Git - icu/commitdiff
ICU-8157 update, support dateformat
authorSteven R. Loomis <srl@icu-project.org>
Wed, 13 Jul 2011 01:26:20 +0000 (01:26 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Wed, 13 Jul 2011 01:26:20 +0000 (01:26 +0000)
X-SVN-Rev: 30321

tools/multi/proj/provider/Makefile
tools/multi/proj/provider/coldiff.cpp
tools/multi/proj/provider/datediff.cpp [new file with mode: 0644]
tools/multi/proj/provider/glue/coll_fe.c [deleted file]
tools/multi/proj/provider/glue/coll_fe.cpp
tools/multi/proj/provider/glue/date_fe.cpp [new file with mode: 0644]
tools/multi/proj/provider/glue/export.txt [deleted file]
tools/multi/proj/provider/glue/oicu.h

index b2ddc3b60e05a03fbb9e80da0e28937ca8af81ec..f4fe8b6bcb50577ccf986c231f8169d6bbf7214d 100644 (file)
@@ -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
+
+$(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)
 
index 5870b90be66e1b6d888afd7e6e66855a6f40c21b..563816cc0a313afa1486e2932c0941726ac1cc66 100644 (file)
@@ -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<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");
 
@@ -121,8 +125,10 @@ int main(int /* argc*/ , const char * /*argv*/ []) {
               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);
 
@@ -131,18 +137,18 @@ int main(int /* argc*/ , const char * /*argv*/ []) {
              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");
 
             
 
diff --git a/tools/multi/proj/provider/datediff.cpp b/tools/multi/proj/provider/datediff.cpp
new file mode 100644 (file)
index 0000000..78bbc95
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+*******************************************************************************
+*
+*   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;
+}
diff --git a/tools/multi/proj/provider/glue/coll_fe.c b/tools/multi/proj/provider/glue/coll_fe.c
deleted file mode 100644 (file)
index d7627fd..0000000
+++ /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;
-}
-
-
-
-
index d2f43ae8198b723bf7fec2a2ef7eb87422733dec..148a3f27db2c97c341f67f99b81a8ddb4e76dd49 100644 (file)
@@ -103,8 +103,14 @@ static UCollationStrength _getUCollationStrength(
 
 /* 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");
diff --git a/tools/multi/proj/provider/glue/date_fe.cpp b/tools/multi/proj/provider/glue/date_fe.cpp
new file mode 100644 (file)
index 0000000..495bf2c
--- /dev/null
@@ -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 <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) */
diff --git a/tools/multi/proj/provider/glue/export.txt b/tools/multi/proj/provider/glue/export.txt
deleted file mode 100644 (file)
index 07ab784..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-# Copyright (C) 2010 International Business Machines Corporation and Others. All Rights Reserved. 
-_coll_provider_plugin
index beb8bd895155646e8981d175735913b5b433fa5f..5fca507dcf3da8e4b4e1d69dc3be6968a9610d6c 100644 (file)
 #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