diff options
author | Craig Cornelius <ccornelius@google.com> | 2012-10-09 17:03:29 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2012-11-27 16:39:12 -0800 |
commit | 103e9ffba2cba345d0078eb8b8db33249f81840a (patch) | |
tree | 7db64141088188c7006e8027ff457a70742b824e /tools | |
parent | 31315bc7a9f2672f87f2f7c7c7611c88e447a43a (diff) | |
download | icu4c-103e9ffba2cba345d0078eb8b8db33249f81840a.tar.gz |
ICU 49.2upgrade
(cherry-pick of 83a171d1a62abf406f7f44ae671823d5ec20db7d.)
Change-Id: I2f0f13293d9f47b4605c4ac173d1096dce2b8eb4
Diffstat (limited to 'tools')
81 files changed, 2154 insertions, 775 deletions
diff --git a/tools/Makefile.in b/tools/Makefile.in index 1cfb2f05..e2c0c499 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU tools -## Copyright (c) 1999-2010, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Source directory information @@ -21,7 +21,7 @@ gentest gennorm2 gencfu .PHONY : all all-local all-recursive install install-local \ install-recursive clean clean-local clean-recursive distclean \ distclean-local distclean-recursive dist dist-local dist-recursive \ -check check-local check-recursive build-local +check check-local check-recursive build-local check-exhaustive ## Clear suffix list .SUFFIXES : @@ -34,6 +34,8 @@ distclean : distclean-recursive dist: dist-recursive check: all check-recursive +check-exhaustive: check + ## Recursive targets all-recursive install-recursive clean-recursive distclean-recursive dist-recursive check-recursive: @dot_seen=no; \ diff --git a/tools/ctestfw/Makefile.in b/tools/ctestfw/Makefile.in index 4f96959f..a134fbb3 100644 --- a/tools/ctestfw/Makefile.in +++ b/tools/ctestfw/Makefile.in @@ -1,6 +1,6 @@ #****************************************************************************** # -# Copyright (C) 1999-2010, International Business Machines +# Copyright (C) 1999-2011, International Business Machines # Corporation and others. All Rights Reserved. # #****************************************************************************** @@ -43,9 +43,6 @@ DYNAMICCXXFLAGS = $(SHAREDLIBCXXFLAGS) CFLAGS += $(LIBCFLAGS) CXXFLAGS += $(LIBCXXFLAGS) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(srcdir)/../toolutil -I$(srcdir) $(LIBCPPFLAGS) $(CPPFLAGSCTESTFW) DEFS += -DT_CTEST_IMPLEMENTATION LDFLAGS += $(LDFLAGSCTESTFW) @@ -126,6 +123,11 @@ endif ifneq ($(ENABLE_SHARED),) $(SHARED_OBJECT): $(OBJECTS) $(SHLIB.cc) $(LD_SONAME) $(OUTOPT)$@ $^ $(LIBS) +ifeq ($(ENABLE_RPATH),YES) +ifneq ($(wildcard $(libdir)/$(MIDDLE_SO_TARGET)),) + $(warning RPATH warning: --enable-rpath means test programs may use existing $(libdir)/$(MIDDLE_SO_TARGET)) +endif +endif endif ifeq (,$(MAKECMDGOALS)) diff --git a/tools/ctestfw/ctest.c b/tools/ctestfw/ctest.c index c1eb0de8..474e7542 100644 --- a/tools/ctestfw/ctest.c +++ b/tools/ctestfw/ctest.c @@ -1,7 +1,7 @@ /* ******************************************************************************** * -* Copyright (C) 1996-2011, International Business Machines +* Copyright (C) 1996-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************** @@ -902,8 +902,7 @@ int T_CTEST_EXPORT2 initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *context) { int i; - int doList = FALSE; - int argSkip = 0; + int argSkip = 0; VERBOSITY = FALSE; ERR_MSG = TRUE; @@ -928,7 +927,7 @@ initArgs( int argc, const char* const argv[], ArgHandlerPtr argHandler, void *co } else if (strcmp( argv[i], "-l" )==0 ) { - doList = TRUE; + /* doList = TRUE; */ } else if (strcmp( argv[i], "-e1") == 0) { @@ -1213,13 +1212,13 @@ ctest_xml_init(const char *rootName) { fprintf(stderr," Error: couldn't open XML output file %s\n", XML_FILE_NAME); return 1; } - while(*rootName&&!isalnum(*rootName)) { + while(*rootName&&!isalnum((int)*rootName)) { rootName++; } strcpy(XML_PREFIX,rootName); { char *p = XML_PREFIX+strlen(XML_PREFIX); - for(p--;*p&&p>XML_PREFIX&&!isalnum(*p);p--) { + for(p--;*p&&p>XML_PREFIX&&!isalnum((int)*p);p--) { *p=0; } } diff --git a/tools/ctestfw/ctestfw.vcxproj b/tools/ctestfw/ctestfw.vcxproj index a914446e..09d9ea41 100644 --- a/tools/ctestfw/ctestfw.vcxproj +++ b/tools/ctestfw/ctestfw.vcxproj @@ -107,7 +107,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin\icutest.dll</OutputFile>
+ <OutputFile>..\..\..\bin\icutest49.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<ProgramDatabaseFile>.\..\..\..\lib\icutest.pdb</ProgramDatabaseFile>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -150,7 +150,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin\icutestd.dll</OutputFile>
+ <OutputFile>..\..\..\bin\icutest49d.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\..\..\..\lib\icutestd.pdb</ProgramDatabaseFile>
@@ -190,7 +190,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin64\icutest.dll</OutputFile>
+ <OutputFile>..\..\..\bin64\icutest49.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<ProgramDatabaseFile>.\..\..\..\lib64\icutest.pdb</ProgramDatabaseFile>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -231,7 +231,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin64\icutestd.dll</OutputFile>
+ <OutputFile>..\..\..\bin64\icutest49d.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\..\..\..\lib64\icutestd.pdb</ProgramDatabaseFile>
diff --git a/tools/ctestfw/unicode/testtype.h b/tools/ctestfw/unicode/testtype.h index 6deb1cdf..9c4a72ea 100644 --- a/tools/ctestfw/unicode/testtype.h +++ b/tools/ctestfw/unicode/testtype.h @@ -1,6 +1,6 @@ /* ***************************************************************************************** - * Copyright (C) 2004-2007, International Business Machines + * Copyright (C) 2004-2011, International Business Machines * Corporation and others. All Rights Reserved. ***************************************************************************************** */ @@ -16,7 +16,7 @@ #define T_CTEST_IMPORT #endif -#if defined(U_WINDOWS) +#if defined(_MSC_VER) #define T_CTEST_EXPORT2 __cdecl #else #define T_CTEST_EXPORT2 diff --git a/tools/ctestfw/unicode/uperf.h b/tools/ctestfw/unicode/uperf.h index 5568f0e6..a46ca2a7 100644 --- a/tools/ctestfw/unicode/uperf.h +++ b/tools/ctestfw/unicode/uperf.h @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (c) 2002-2007, International Business Machines +* Copyright (c) 2002-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ @@ -65,6 +65,11 @@ U_NAMESPACE_USE class T_CTEST_EXPORT_API UPerfFunction { public: /** + * destructor + */ + virtual ~UPerfFunction(); + + /** * Subclasses must implement this method to do the action to be * measured. */ @@ -86,11 +91,6 @@ public: return -1; } /** - * destructor - */ - virtual ~UPerfFunction() {} - - /** * Call call() n times in a tight loop and return the elapsed * milliseconds. If n is small and call() is fast the return * result may be zero. Small return values have limited diff --git a/tools/ctestfw/unicode/utimer.h b/tools/ctestfw/unicode/utimer.h index 7974540f..605158b0 100644 --- a/tools/ctestfw/unicode/utimer.h +++ b/tools/ctestfw/unicode/utimer.h @@ -1,6 +1,6 @@ /* ************************************************************************ -* Copyright (c) 1997-2010, International Business Machines +* Copyright (c) 1997-2012, International Business Machines * Corporation and others. All Rights Reserved. ************************************************************************ */ @@ -10,12 +10,12 @@ #include "unicode/utypes.h" -#if defined(U_WINDOWS) +#if U_PLATFORM_HAS_WIN32_API # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN # include <windows.h> #else -# if defined(OS390) +# if U_PLATFORM == U_PF_OS390 && !defined(__UU) # define __UU /* Universal Unix - for struct timeval */ # endif # include <time.h> @@ -88,7 +88,7 @@ * } * * retVal= fn(fileLines[line].name,len,dest,destCapacity,&error); - * #if defined(U_WINDOWS) + * #if U_PLATFORM_HAS_WIN32_API * if(retVal==0 ){ * fprintf(stderr,"Normalization of string in Windows API failed for mode %s. ErrorNo: %i at line number %i\n",mode,GetLastError(),line); * return 0; @@ -160,25 +160,25 @@ typedef struct UTimer UTimer; typedef void FuntionToBeTimed(void* param); -#if defined(U_WINDOWS) +#if U_PLATFORM_HAS_WIN32_API struct UTimer{ LARGE_INTEGER start; LARGE_INTEGER placeHolder; }; - int uprv_initFrequency(UTimer* timer) +static int uprv_initFrequency(UTimer* timer) { return QueryPerformanceFrequency(&timer->placeHolder); } - void uprv_start(UTimer* timer) +static void uprv_start(UTimer* timer) { QueryPerformanceCounter(&timer->start); } - double uprv_delta(UTimer* timer1, UTimer* timer2){ +static double uprv_delta(UTimer* timer1, UTimer* timer2){ return ((double)(timer2->start.QuadPart - timer1->start.QuadPart))/((double)timer1->placeHolder.QuadPart); } - UBool uprv_compareFrequency(UTimer* timer1, UTimer* timer2){ +static UBool uprv_compareFrequency(UTimer* timer1, UTimer* timer2){ return (timer1->placeHolder.QuadPart == timer2->placeHolder.QuadPart); } @@ -189,22 +189,22 @@ typedef void FuntionToBeTimed(void* param); struct timeval placeHolder; }; - int32_t uprv_initFrequency(UTimer* /*timer*/) +static int32_t uprv_initFrequency(UTimer* /*timer*/) { return 0; } - void uprv_start(UTimer* timer) +static void uprv_start(UTimer* timer) { gettimeofday(&timer->start, 0); } - double uprv_delta(UTimer* timer1, UTimer* timer2){ +static double uprv_delta(UTimer* timer1, UTimer* timer2){ double t1, t2; t1 = (double)timer1->start.tv_sec + (double)timer1->start.tv_usec/(1000*1000); t2 = (double)timer2->start.tv_sec + (double)timer2->start.tv_usec/(1000*1000); return (t2-t1); } - UBool uprv_compareFrequency(UTimer* /*timer1*/, UTimer* /*timer2*/){ +static UBool uprv_compareFrequency(UTimer* /*timer1*/, UTimer* /*timer2*/){ return TRUE; } @@ -214,7 +214,7 @@ typedef void FuntionToBeTimed(void* param); * * @param timer A pointer to UTimer struct to recieve the current time */ -static U_INLINE void U_EXPORT2 +static inline void U_EXPORT2 utimer_getTime(UTimer* timer){ uprv_initFrequency(timer); uprv_start(timer); @@ -228,7 +228,7 @@ utimer_getTime(UTimer* timer){ * @param timer2 A pointer to UTimer struct to be used as end time * @return Time in seconds */ -static U_INLINE double U_EXPORT2 +static inline double U_EXPORT2 utimer_getDeltaSeconds(UTimer* timer1, UTimer* timer2){ if(uprv_compareFrequency(timer1,timer2)){ return uprv_delta(timer1,timer2); @@ -243,7 +243,7 @@ utimer_getDeltaSeconds(UTimer* timer1, UTimer* timer2){ * @param timer A pointer to UTimer struct to be used as starting time * @return Time elapsed in seconds */ -static U_INLINE double U_EXPORT2 +static inline double U_EXPORT2 utimer_getElapsedSeconds(UTimer* timer){ UTimer temp; utimer_getTime(&temp); @@ -259,7 +259,7 @@ utimer_getElapsedSeconds(UTimer* timer){ * @param param Parameters to be passed to the fn * @return the time elapsed in seconds */ -static U_INLINE double U_EXPORT2 +static inline double U_EXPORT2 utimer_loopUntilDone(double thresholdTimeVal, int32_t* loopCount, FuntionToBeTimed fn, diff --git a/tools/ctestfw/uperf.cpp b/tools/ctestfw/uperf.cpp index 5fb25b15..e8c34391 100644 --- a/tools/ctestfw/uperf.cpp +++ b/tools/ctestfw/uperf.cpp @@ -4,8 +4,9 @@ * others. All Rights Reserved. ********************************************************************/ -/* z/OS needs this definition for timeval */ -#include "platform_xopen_source_extended.h" +// Defines _XOPEN_SOURCE for access to POSIX functions. +// Must be before any other #includes. +#include "uposixdefs.h" #include "unicode/uperf.h" #include "uoptions.h" @@ -14,6 +15,9 @@ #include <stdlib.h> #if !UCONFIG_NO_CONVERSION + +UPerfFunction::~UPerfFunction() {} + static const char delim = '/'; static int32_t execCount = 0; UPerfTest* UPerfTest::gTest = NULL; diff --git a/tools/dumpce/dumpce.cpp b/tools/dumpce/dumpce.cpp index 6056ab2a..0917ce79 100644 --- a/tools/dumpce/dumpce.cpp +++ b/tools/dumpce/dumpce.cpp @@ -160,7 +160,7 @@ void serialize(FILE *f, const UChar *c, int l) * @param iter collation element iterator */ void serialize(FILE *f, UCollationElements *iter) { - UChar *codepoint = iter->iteratordata_.string; + const UChar *codepoint = iter->iteratordata_.string; // unlikely that sortkeys will be over this size uint8_t sortkey[64]; uint8_t *psortkey = sortkey; @@ -873,7 +873,7 @@ void outputScriptElem(ScriptElement &element, int compare, UBool expansion) while (i < element.count) { char str[128]; UChar32 codepoint; - UTF_NEXT_CHAR(element.ch, i, element.count, codepoint); + U16_NEXT(element.ch, i, element.count, codepoint); int32_t temp = u_charName(codepoint, U_UNICODE_CHAR_NAME, str, 128, &error); if (U_FAILURE(error)) { @@ -938,7 +938,7 @@ inline UBool checkInScripts(UScriptCode script[], int scriptcount, int i = 0; while (i < scriptelem.count) { UChar32 codepoint; - UTF_NEXT_CHAR(scriptelem.ch, i, scriptelem.count, codepoint); + U16_NEXT(scriptelem.ch, i, scriptelem.count, codepoint); UErrorCode error = U_ZERO_ERROR; if (checkInScripts(script, scriptcount, codepoint)) { return TRUE; @@ -1017,7 +1017,6 @@ int getScriptElementsFromExemplars(ScriptElement scriptelem[], const char* local UTF16_APPEND_CHAR_UNSAFE(scriptelem[count].ch, scriptelem[count].count, codepoint); scriptelem[count].tailored = FALSE; } - delete []pattern; count++; } diff --git a/tools/genbrk/Makefile.in b/tools/genbrk/Makefile.in index 5884cef3..77182d17 100644 --- a/tools/genbrk/Makefile.in +++ b/tools/genbrk/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/genbrk -## Copyright (c) 2002-2006 International Business Machines Corporation and +## Copyright (c) 2002-2011 International Business Machines Corporation and ## others. All Rights Reserved. ## Source directory information @@ -26,9 +26,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/genccode/Makefile.in b/tools/genccode/Makefile.in index 41913b13..fe6b60fa 100644 --- a/tools/genccode/Makefile.in +++ b/tools/genccode/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/genccode -## Copyright (c) 1999-2008, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis @@ -27,9 +27,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/genccode/genccode.c b/tools/genccode/genccode.c index 12520c3d..d489fd5d 100644 --- a/tools/genccode/genccode.c +++ b/tools/genccode/genccode.c @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 1999-2008, International Business Machines + * Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* * file name: gennames.c @@ -19,7 +19,7 @@ #include "unicode/utypes.h" -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN # define NOUSER @@ -30,7 +30,7 @@ #include <time.h> #endif -#ifdef U_LINUX +#if U_PLATFORM_IS_LINUX_BASED # define U_ELF #endif @@ -57,10 +57,6 @@ #include "uoptions.h" #include "pkg_genc.h" -#if defined(U_WINDOWS) || defined(U_ELF) -#define CAN_GENERATE_OBJECTS -#endif - enum { kOptHelpH = 0, kOptHelpQuestionMark, diff --git a/tools/gencfu/Makefile.in b/tools/gencfu/Makefile.in index b966e4ed..01856064 100644 --- a/tools/gencfu/Makefile.in +++ b/tools/gencfu/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/gencfu -## Copyright (c) 2009 International Business Machines Corporation and +## Copyright (c) 2009-2011 International Business Machines Corporation and ## others. All Rights Reserved. ## Source directory information @@ -26,9 +26,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/gencfu/gencfu.cpp b/tools/gencfu/gencfu.cpp index 79a11f9f..37bb1dad 100644 --- a/tools/gencfu/gencfu.cpp +++ b/tools/gencfu/gencfu.cpp @@ -287,8 +287,8 @@ int main(int argc, char **argv) { uspoof_close(sc); delete [] outData; - delete confusables; - delete wsConfsables; + delete [] confusables; + delete [] wsConfsables; u_cleanup(); printf("gencfu: tool completed successfully.\n"); return 0; diff --git a/tools/gencmn/Makefile.in b/tools/gencmn/Makefile.in index 2c6aafeb..8a758d13 100644 --- a/tools/gencmn/Makefile.in +++ b/tools/gencmn/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/gencmn -## Copyright (c) 1999-2008, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis @@ -27,9 +27,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/gencnval/Makefile.in b/tools/gencnval/Makefile.in index c4c2ab56..985f1e3a 100644 --- a/tools/gencnval/Makefile.in +++ b/tools/gencnval/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/gencnval -## Copyright (c) 1999-2005, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis @@ -27,9 +27,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/gencnval/gencnval.c b/tools/gencnval/gencnval.c index ccbaf146..0f0a9158 100644 --- a/tools/gencnval/gencnval.c +++ b/tools/gencnval/gencnval.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2009, International Business Machines +* Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -330,7 +330,7 @@ parseFile(FileStream *in) { /* Read non-empty lines that don't start with a space character. */ while (T_FileStream_readLine(in, lastLine, MAX_LINE_SIZE) != NULL) { lastLineSize = chomp(lastLine); - if (lineSize == 0 || (lastLineSize > 0 && isspace(*lastLine))) { + if (lineSize == 0 || (lastLineSize > 0 && isspace((int)*lastLine))) { uprv_strcpy(line + lineSize, lastLine); lineSize += lastLineSize; } else if (lineSize > 0) { @@ -341,7 +341,7 @@ parseFile(FileStream *in) { } if (validParse || lineSize > 0) { - if (isspace(*line)) { + if (isspace((int)*line)) { fprintf(stderr, "%s:%d: error: cannot start an alias with a space\n", path, lineNum-1); exit(U_PARSE_ERROR); } else if (line[0] == '{') { @@ -386,7 +386,7 @@ chomp(char *line) { *s = 0; break; } - if (!isspace(*s)) { + if (!isspace((int)*s)) { lastNonSpace = s; } ++s; @@ -417,7 +417,7 @@ parseLine(const char *line) { /* get the converter name */ start=pos; - while(line[pos]!=0 && !isspace(line[pos])) { + while(line[pos]!=0 && !isspace((int)line[pos])) { ++pos; } limit=pos; @@ -436,7 +436,7 @@ parseLine(const char *line) { for(;;) { /* skip white space */ - while(line[pos]!=0 && isspace(line[pos])) { + while(line[pos]!=0 && isspace((int)line[pos])) { ++pos; } @@ -447,7 +447,7 @@ parseLine(const char *line) { /* get an alias name */ start=pos; - while(line[pos]!=0 && line[pos]!='{' && !isspace(line[pos])) { + while(line[pos]!=0 && line[pos]!='{' && !isspace((int)line[pos])) { ++pos; } limit=pos; @@ -469,7 +469,7 @@ parseLine(const char *line) { /* addAlias(alias, 0, cnv, FALSE);*/ /* skip whitespace */ - while (line[pos] && isspace(line[pos])) { + while (line[pos] && isspace((int)line[pos])) { ++pos; } @@ -478,7 +478,7 @@ parseLine(const char *line) { ++pos; do { start = pos; - while (line[pos] && line[pos] != '}' && !isspace( line[pos])) { + while (line[pos] && line[pos] != '}' && !isspace((int)line[pos])) { ++pos; } limit = pos; @@ -489,7 +489,7 @@ parseLine(const char *line) { addAlias(alias, tag, cnv, (UBool)(line[limit-1] == '*')); } - while (line[pos] && isspace(line[pos])) { + while (line[pos] && isspace((int)line[pos])) { ++pos; } } while (line[pos] && line[pos] != '}'); diff --git a/tools/genctd/Makefile.in b/tools/genctd/Makefile.in index daefb61b..f202702d 100644 --- a/tools/genctd/Makefile.in +++ b/tools/genctd/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/genctd -## Copyright (c) 2002-2006 International Business Machines Corporation and +## Copyright (c) 2002-2011 International Business Machines Corporation and ## others. All Rights Reserved. ## Source directory information @@ -26,9 +26,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/gennorm2/Makefile.in b/tools/gennorm2/Makefile.in index f46e4664..b8f926a7 100644 --- a/tools/gennorm2/Makefile.in +++ b/tools/gennorm2/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/gennorm2 -## Copyright (c) 2009-2010, International Business Machines Corporation and +## Copyright (c) 2009-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis/Markus W. Scherer @@ -22,9 +22,6 @@ CLEANFILES = *~ $(DEPS) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/gennorm2/gennorm2.cpp b/tools/gennorm2/gennorm2.cpp index f0d981ec..597300da 100644 --- a/tools/gennorm2/gennorm2.cpp +++ b/tools/gennorm2/gennorm2.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2009-2010, International Business Machines +* Copyright (C) 2009-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -80,7 +80,6 @@ main(int argc, char* argv[]) { /* preset then read command line options */ options[SOURCEDIR].value=""; - options[UNICODE_VERSION].value=U_UNICODE_VERSION; argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[HELP_H]), options); /* error handling, printing usage message */ @@ -145,7 +144,9 @@ main(int argc, char* argv[]) { LocalPointer<Normalizer2DataBuilder> builder(new Normalizer2DataBuilder(errorCode)); errorCode.assertSuccess(); - builder->setUnicodeVersion(options[UNICODE_VERSION].value); + if(options[UNICODE_VERSION].doesOccur) { + builder->setUnicodeVersion(options[UNICODE_VERSION].value); + } if(options[OPT_FAST].doesOccur) { builder->setOptimization(Normalizer2DataBuilder::OPTIMIZE_FAST); @@ -198,6 +199,11 @@ void parseFile(FILE *f, Normalizer2DataBuilder &builder) { continue; // skip empty and comment-only lines } if(line[0]=='*') { + const char *s=u_skipWhitespace(line+1); + if(0==strncmp(s, "Unicode", 7)) { + s=u_skipWhitespace(s+7); + builder.setUnicodeVersion(s); + } continue; // reserved syntax } const char *delimiter; diff --git a/tools/gennorm2/n2builder.cpp b/tools/gennorm2/n2builder.cpp index 4d8be44e..843b1f70 100644 --- a/tools/gennorm2/n2builder.cpp +++ b/tools/gennorm2/n2builder.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2009-2010, International Business Machines +* Copyright (C) 2009-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -55,7 +55,7 @@ static UDataInfo dataInfo={ 0, { 0x4e, 0x72, 0x6d, 0x32 }, /* dataFormat="Nrm2" */ - { 1, 0, 0, 0 }, /* formatVersion */ + { 2, 0, 0, 0 }, /* formatVersion */ { 5, 2, 0, 0 } /* dataVersion (Unicode version) */ }; @@ -121,6 +121,7 @@ struct Norm { } UnicodeString *mapping; + UnicodeString *rawMapping; // non-NULL if the mapping is further decomposed UChar32 mappingCP; // >=0 if mapping to 1 code point int32_t mappingPhase; MappingType mappingType; @@ -131,8 +132,18 @@ struct Norm { UBool hasNoCompBoundaryAfter; enum OffsetType { - OFFSET_NONE, OFFSET_MAYBE_YES, - OFFSET_YES_YES, OFFSET_YES_NO, OFFSET_NO_NO, + OFFSET_NONE, + // Composition for back-combining character. Allowed, but not normally used. + OFFSET_MAYBE_YES, + // Composition for a starter that does not have a decomposition mapping. + OFFSET_YES_YES, + // Round-trip mapping & composition for a starter. + OFFSET_YES_NO_MAPPING_AND_COMPOSITION, + // Round-trip mapping for a starter that itself does not combine-forward. + OFFSET_YES_NO_MAPPING_ONLY, + // One-way mapping. + OFFSET_NO_NO, + // Delta for an algorithmic one-way mapping. OFFSET_DELTA }; enum { OFFSET_SHIFT=4, OFFSET_MASK=(1<<OFFSET_SHIFT)-1 }; @@ -165,6 +176,7 @@ Normalizer2DataBuilder::Normalizer2DataBuilder(UErrorCode &errorCode) : normMem=utm_open("gennorm2 normalization structs", 10000, 0x110100, sizeof(Norm)); norms=allocNorm(); // unused Norm struct at index 0 memset(indexes, 0, sizeof(indexes)); + memset(smallFCD, 0, sizeof(smallFCD)); } Normalizer2DataBuilder::~Normalizer2DataBuilder() { @@ -172,6 +184,7 @@ Normalizer2DataBuilder::~Normalizer2DataBuilder() { int32_t normsLength=utm_countItems(normMem); for(int32_t i=1; i<normsLength; ++i) { delete norms[i].mapping; + delete norms[i].rawMapping; delete norms[i].compositions; } utm_close(normMem); @@ -180,7 +193,19 @@ Normalizer2DataBuilder::~Normalizer2DataBuilder() { void Normalizer2DataBuilder::setUnicodeVersion(const char *v) { - u_versionFromString(unicodeVersion, v); + UVersionInfo nullVersion={ 0, 0, 0, 0 }; + UVersionInfo version; + u_versionFromString(version, v); + if( 0!=memcmp(version, unicodeVersion, U_MAX_VERSION_LENGTH) && + 0!=memcmp(nullVersion, unicodeVersion, U_MAX_VERSION_LENGTH) + ) { + char buffer[U_MAX_VERSION_STRING_LENGTH]; + u_versionToString(unicodeVersion, buffer); + fprintf(stderr, "gennorm2 error: multiple inconsistent Unicode version numbers %s vs. %s\n", + buffer, v); + exit(U_ILLEGAL_ARGUMENT_ERROR); + } + memcpy(unicodeVersion, version, U_MAX_VERSION_LENGTH); } Norm *Normalizer2DataBuilder::allocNorm() { @@ -421,7 +446,8 @@ public: UBool Normalizer2DataBuilder::decompose(UChar32 start, UChar32 end, uint32_t value) { if(norms[value].hasMapping()) { - const UnicodeString &m=*norms[value].mapping; + Norm &norm=norms[value]; + const UnicodeString &m=*norm.mapping; UnicodeString *decomposed=NULL; const UChar *s=m.getBuffer(); int32_t length=m.length(); @@ -438,7 +464,7 @@ Normalizer2DataBuilder::decompose(UChar32 start, UChar32 end, uint32_t value) { } const Norm &cNorm=getNormRef(c); if(cNorm.hasMapping()) { - if(norms[value].mappingType==Norm::ROUND_TRIP) { + if(norm.mappingType==Norm::ROUND_TRIP) { if(prev==0) { if(cNorm.mappingType!=Norm::ROUND_TRIP) { fprintf(stderr, @@ -480,7 +506,7 @@ Normalizer2DataBuilder::decompose(UChar32 start, UChar32 end, uint32_t value) { } else if(Hangul::isHangul(c)) { UChar buffer[3]; int32_t hangulLength=Hangul::decompose(c, buffer); - if(norms[value].mappingType==Norm::ROUND_TRIP && prev!=0) { + if(norm.mappingType==Norm::ROUND_TRIP && prev!=0) { fprintf(stderr, "gennorm2 error: " "U+%04lX's round-trip mapping's non-starter " @@ -498,9 +524,14 @@ Normalizer2DataBuilder::decompose(UChar32 start, UChar32 end, uint32_t value) { } } if(decomposed!=NULL) { - delete norms[value].mapping; - norms[value].mapping=decomposed; - // Not norms[value].setMappingCP(); because the original mapping + if(norm.rawMapping==NULL) { + // Remember the original mapping when decomposing recursively. + norm.rawMapping=norm.mapping; + } else { + delete norm.mapping; + } + norm.mapping=decomposed; + // Not norm.setMappingCP(); because the original mapping // is most likely to be encodable as a delta. return TRUE; } @@ -585,9 +616,17 @@ Normalizer2DataBuilder::reorder(Norm *p, BuilderReorderingBuffer &buffer) { } } +/* + * Computes the flag for the last code branch in Normalizer2Impl::hasCompBoundaryAfter(). + * A starter character with a mapping does not have a composition boundary after it + * if the character itself combines-forward (which is tested by the caller of this function), + * or it is deleted (mapped to the empty string), + * or its mapping contains no starter, + * or the last starter combines-forward. + */ UBool Normalizer2DataBuilder::hasNoCompBoundaryAfter(BuilderReorderingBuffer &buffer) { if(buffer.isEmpty()) { - return TRUE; // maps-to-empty string is no boundary of any kind + return TRUE; // maps-to-empty-string is no boundary of any kind } int32_t lastStarterIndex=buffer.lastStarterIndex(); if(lastStarterIndex<0) { @@ -602,7 +641,7 @@ UBool Normalizer2DataBuilder::hasNoCompBoundaryAfter(BuilderReorderingBuffer &bu // otherwise it is blocked. return lastStarterIndex==buffer.length()-1; } - // no Hangul in fully decomposed mapping + // Note: There can be no Hangul syllable in the fully decomposed mapping. const Norm *starterNorm=&getNormRef(starter); if(starterNorm->compositions==NULL) { return FALSE; // the last starter does not combine forward @@ -632,7 +671,9 @@ UBool Normalizer2DataBuilder::hasNoCompBoundaryAfter(BuilderReorderingBuffer &bu } // Requires p->hasMapping(). -void Normalizer2DataBuilder::writeMapping(UChar32 c, const Norm *p, UnicodeString &dataString) { +// Returns the offset of the "first unit" from the beginning of the extraData for c. +// That is the same as the length of the optional data for the raw mapping and the ccc/lccc word. +int32_t Normalizer2DataBuilder::writeMapping(UChar32 c, const Norm *p, UnicodeString &dataString) { UnicodeString &m=*p->mapping; int32_t length=m.length(); if(length>Normalizer2Impl::MAPPING_LENGTH_MASK) { @@ -656,22 +697,59 @@ void Normalizer2DataBuilder::writeMapping(UChar32 c, const Norm *p, UnicodeStrin (long)c); exit(U_INVALID_FORMAT_ERROR); } + // Write small-FCD data. + if((leadCC|trailCC)!=0) { + UChar32 lead= c<=0xffff ? c : U16_LEAD(c); + smallFCD[lead>>8]|=(uint8_t)1<<((lead>>5)&7); + } + // Write the mapping & raw mapping extraData. int32_t firstUnit=length|(trailCC<<8); - int32_t secondUnit=p->cc|(leadCC<<8); - if(secondUnit!=0) { - firstUnit|=Normalizer2Impl::MAPPING_HAS_CCC_LCCC_WORD; + int32_t preMappingLength=0; + if(p->rawMapping!=NULL) { + UnicodeString &rm=*p->rawMapping; + int32_t rmLength=rm.length(); + if(rmLength>Normalizer2Impl::MAPPING_LENGTH_MASK) { + fprintf(stderr, + "gennorm2 error: " + "raw mapping for U+%04lX longer than maximum of %d\n", + (long)c, Normalizer2Impl::MAPPING_LENGTH_MASK); + exit(U_INVALID_FORMAT_ERROR); + } + UChar rm0=rm.charAt(0); + if( rmLength==length-1 && + // 99: overlong substring lengths get pinned to remainder lengths anyway + 0==rm.compare(1, 99, m, 2, 99) && + rm0>Normalizer2Impl::MAPPING_LENGTH_MASK + ) { + // Compression: + // rawMapping=rm0+mapping.substring(2) -> store only rm0 + // + // The raw mapping is the same as the final mapping after replacing + // the final mapping's first two code units with the raw mapping's first one. + // In this case, we store only that first unit, rm0. + // This helps with a few hundred mappings. + dataString.append(rm0); + preMappingLength=1; + } else { + // Store the raw mapping with its length. + dataString.append(rm); + dataString.append((UChar)rmLength); + preMappingLength=rmLength+1; + } + firstUnit|=Normalizer2Impl::MAPPING_HAS_RAW_MAPPING; } - if(p->compositions!=NULL) { - firstUnit|=Normalizer2Impl::MAPPING_PLUS_COMPOSITION_LIST; + int32_t cccLccc=p->cc|(leadCC<<8); + if(cccLccc!=0) { + dataString.append((UChar)cccLccc); + ++preMappingLength; + firstUnit|=Normalizer2Impl::MAPPING_HAS_CCC_LCCC_WORD; } if(p->hasNoCompBoundaryAfter) { firstUnit|=Normalizer2Impl::MAPPING_NO_COMP_BOUNDARY_AFTER; } dataString.append((UChar)firstUnit); - if(secondUnit!=0) { - dataString.append((UChar)secondUnit); - } dataString.append(m); + return preMappingLength; } // Requires p->compositions!=NULL. @@ -728,7 +806,7 @@ public: ExtraDataWriter(Normalizer2DataBuilder &b) : Normalizer2DBEnumerator(b), yesYesCompositions(1000, (UChar32)0xffff, 2), // 0=inert, 1=Jamo L, 2=start of compositions - yesNoData(1000, (UChar32)0, 1) {} // 0=Hangul, 1=start of normal data + yesNoMappingsAndCompositions(1000, (UChar32)0, 1) {} // 0=Hangul, 1=start of normal data virtual UBool rangeHandler(UChar32 start, UChar32 end, uint32_t value) { if(value!=0) { if(start!=end) { @@ -744,13 +822,29 @@ public: } UnicodeString maybeYesCompositions; UnicodeString yesYesCompositions; - UnicodeString yesNoData; + UnicodeString yesNoMappingsAndCompositions; + UnicodeString yesNoMappingsOnly; UnicodeString noNoMappings; Hashtable previousNoNoMappings; // If constructed in runtime code, pass in UErrorCode. }; void Normalizer2DataBuilder::writeExtraData(UChar32 c, uint32_t value, ExtraDataWriter &writer) { Norm *p=norms+value; + if(!p->hasMapping()) { + // Write small-FCD data. + // There is similar code in writeMapping() for characters that do have a mapping. + if(c<Normalizer2Impl::MIN_CCC_LCCC_CP && p->cc!=0) { + fprintf(stderr, + "gennorm2 error: " + "U+%04lX below U+0300 has ccc!=0, not supported by ICU\n", + (long)c); + exit(U_INVALID_FORMAT_ERROR); + } + if(p->cc!=0) { + UChar32 lead= c<=0xffff ? c : U16_LEAD(c); + smallFCD[lead>>8]|=(uint8_t)1<<((lead>>5)&7); + } + } if(p->combinesBack) { if(p->hasMapping()) { fprintf(stderr, @@ -773,12 +867,15 @@ void Normalizer2DataBuilder::writeExtraData(UChar32 c, uint32_t value, ExtraData writeCompositions(c, p, writer.yesYesCompositions); } } else if(p->mappingType==Norm::ROUND_TRIP) { - p->offset= - (writer.yesNoData.length()<<Norm::OFFSET_SHIFT)| - Norm::OFFSET_YES_NO; - writeMapping(c, p, writer.yesNoData); if(p->compositions!=NULL) { - writeCompositions(c, p, writer.yesNoData); + int32_t offset=writer.yesNoMappingsAndCompositions.length()+ + writeMapping(c, p, writer.yesNoMappingsAndCompositions); + p->offset=(offset<<Norm::OFFSET_SHIFT)|Norm::OFFSET_YES_NO_MAPPING_AND_COMPOSITION; + writeCompositions(c, p, writer.yesNoMappingsAndCompositions); + } else { + int32_t offset=writer.yesNoMappingsOnly.length()+ + writeMapping(c, p, writer.yesNoMappingsOnly); + p->offset=(offset<<Norm::OFFSET_SHIFT)|Norm::OFFSET_YES_NO_MAPPING_ONLY; } } else /* one-way */ { if(p->compositions!=NULL) { @@ -791,8 +888,15 @@ void Normalizer2DataBuilder::writeExtraData(UChar32 c, uint32_t value, ExtraData } if(p->cc==0 && optimization!=OPTIMIZE_FAST) { // Try a compact, algorithmic encoding. - // Only for ccc=0, because we can't store additional information. - if(p->mappingCP>=0) { + // Only for ccc=0, because we can't store additional information + // and we do not recursively follow an algorithmic encoding for access to the ccc. + // + // Also, if hasNoCompBoundaryAfter is set, we can only use the algorithmic encoding + // if the mappingCP decomposes further, to ensure that there is a place to store it. + // We want to see that the final mapping does not have exactly 1 code point, + // or else we would have to recursively ensure that the final mapping is stored + // in normal extraData. + if(p->mappingCP>=0 && (!p->hasNoCompBoundaryAfter || 1!=p->mapping->countChar32())) { int32_t delta=p->mappingCP-c; if(-Normalizer2Impl::MAX_DELTA<=delta && delta<=Normalizer2Impl::MAX_DELTA) { p->offset=(delta<<Norm::OFFSET_SHIFT)|Norm::OFFSET_DELTA; @@ -801,22 +905,18 @@ void Normalizer2DataBuilder::writeExtraData(UChar32 c, uint32_t value, ExtraData } if(p->offset==0) { int32_t oldNoNoLength=writer.noNoMappings.length(); - writeMapping(c, p, writer.noNoMappings); + int32_t offset=oldNoNoLength+writeMapping(c, p, writer.noNoMappings); UnicodeString newMapping=writer.noNoMappings.tempSubString(oldNoNoLength); int32_t previousOffset=writer.previousNoNoMappings.geti(newMapping); if(previousOffset!=0) { // Duplicate, remove the new units and point to the old ones. writer.noNoMappings.truncate(oldNoNoLength); - p->offset= - ((previousOffset-1)<<Norm::OFFSET_SHIFT)| - Norm::OFFSET_NO_NO; + p->offset=((previousOffset-1)<<Norm::OFFSET_SHIFT)|Norm::OFFSET_NO_NO; } else { // Enter this new mapping into the hashtable, avoiding value 0 which is "not found". IcuToolErrorCode errorCode("gennorm2/writeExtraData()/Hashtable.puti()"); - writer.previousNoNoMappings.puti(newMapping, oldNoNoLength+1, errorCode); - p->offset= - (oldNoNoLength<<Norm::OFFSET_SHIFT)| - Norm::OFFSET_NO_NO; + writer.previousNoNoMappings.puti(newMapping, offset+1, errorCode); + p->offset=(offset<<Norm::OFFSET_SHIFT)|Norm::OFFSET_NO_NO; } } } @@ -857,10 +957,14 @@ void Normalizer2DataBuilder::writeNorm16(UChar32 start, UChar32 end, uint32_t va case Norm::OFFSET_YES_YES: norm16=offset; break; - case Norm::OFFSET_YES_NO: + case Norm::OFFSET_YES_NO_MAPPING_AND_COMPOSITION: norm16=indexes[Normalizer2Impl::IX_MIN_YES_NO]+offset; isDecompNo=TRUE; break; + case Norm::OFFSET_YES_NO_MAPPING_ONLY: + norm16=indexes[Normalizer2Impl::IX_MIN_YES_NO_MAPPINGS_ONLY]+offset; + isDecompNo=TRUE; + break; case Norm::OFFSET_NO_NO: norm16=indexes[Normalizer2Impl::IX_MIN_NO_NO]+offset; isDecompNo=isCompNoMaybe=TRUE; @@ -947,10 +1051,18 @@ void Normalizer2DataBuilder::processData() { BuilderReorderingBuffer buffer; int32_t normsLength=utm_countItems(normMem); for(int32_t i=1; i<normsLength; ++i) { - if(norms[i].hasMapping()) { - buffer.reset(); - reorder(norms+i, buffer); - norms[i].hasNoCompBoundaryAfter=hasNoCompBoundaryAfter(buffer); + // Set the hasNoCompBoundaryAfter flag for use by the last code branch + // in Normalizer2Impl::hasCompBoundaryAfter(). + // For details see the comments on hasNoCompBoundaryAfter(buffer). + const Norm &norm=norms[i]; + if(norm.hasMapping()) { + if(norm.compositions!=NULL) { + norms[i].hasNoCompBoundaryAfter=TRUE; + } else { + buffer.reset(); + reorder(norms+i, buffer); + norms[i].hasNoCompBoundaryAfter=hasNoCompBoundaryAfter(buffer); + } } } @@ -962,7 +1074,8 @@ void Normalizer2DataBuilder::processData() { extraData=extraDataWriter.maybeYesCompositions; extraData.append(extraDataWriter.yesYesCompositions). - append(extraDataWriter.yesNoData). + append(extraDataWriter.yesNoMappingsAndCompositions). + append(extraDataWriter.yesNoMappingsOnly). append(extraDataWriter.noNoMappings); // Pad to even length for 4-byte alignment of following data. if(extraData.length()&1) { @@ -971,9 +1084,12 @@ void Normalizer2DataBuilder::processData() { indexes[Normalizer2Impl::IX_MIN_YES_NO]= extraDataWriter.yesYesCompositions.length(); - indexes[Normalizer2Impl::IX_MIN_NO_NO]= + indexes[Normalizer2Impl::IX_MIN_YES_NO_MAPPINGS_ONLY]= indexes[Normalizer2Impl::IX_MIN_YES_NO]+ - extraDataWriter.yesNoData.length(); + extraDataWriter.yesNoMappingsAndCompositions.length(); + indexes[Normalizer2Impl::IX_MIN_NO_NO]= + indexes[Normalizer2Impl::IX_MIN_YES_NO_MAPPINGS_ONLY]+ + extraDataWriter.yesNoMappingsOnly.length(); indexes[Normalizer2Impl::IX_LIMIT_NO_NO]= indexes[Normalizer2Impl::IX_MIN_NO_NO]+ extraDataWriter.noNoMappings.length(); @@ -1051,23 +1167,32 @@ void Normalizer2DataBuilder::writeBinaryFile(const char *filename) { indexes[Normalizer2Impl::IX_NORM_TRIE_OFFSET]=offset; offset+=norm16TrieLength; indexes[Normalizer2Impl::IX_EXTRA_DATA_OFFSET]=offset; - int32_t totalSize=offset+=extraData.length()*2; - for(int32_t i=Normalizer2Impl::IX_RESERVED2_OFFSET; i<=Normalizer2Impl::IX_TOTAL_SIZE; ++i) { + offset+=extraData.length()*2; + indexes[Normalizer2Impl::IX_SMALL_FCD_OFFSET]=offset; + offset+=sizeof(smallFCD); + int32_t totalSize=offset; + for(int32_t i=Normalizer2Impl::IX_RESERVED3_OFFSET; i<=Normalizer2Impl::IX_TOTAL_SIZE; ++i) { indexes[i]=totalSize; } if(beVerbose) { printf("size of normalization trie: %5ld bytes\n", (long)norm16TrieLength); printf("size of 16-bit extra data: %5ld uint16_t\n", (long)extraData.length()); + printf("size of small-FCD data: %5ld bytes\n", (long)sizeof(smallFCD)); printf("size of binary data file contents: %5ld bytes\n", (long)totalSize); printf("minDecompNoCodePoint: U+%04lX\n", (long)indexes[Normalizer2Impl::IX_MIN_DECOMP_NO_CP]); printf("minCompNoMaybeCodePoint: U+%04lX\n", (long)indexes[Normalizer2Impl::IX_MIN_COMP_NO_MAYBE_CP]); printf("minYesNo: 0x%04x\n", (int)indexes[Normalizer2Impl::IX_MIN_YES_NO]); + printf("minYesNoMappingsOnly: 0x%04x\n", (int)indexes[Normalizer2Impl::IX_MIN_YES_NO_MAPPINGS_ONLY]); printf("minNoNo: 0x%04x\n", (int)indexes[Normalizer2Impl::IX_MIN_NO_NO]); printf("limitNoNo: 0x%04x\n", (int)indexes[Normalizer2Impl::IX_LIMIT_NO_NO]); printf("minMaybeYes: 0x%04x\n", (int)indexes[Normalizer2Impl::IX_MIN_MAYBE_YES]); } + UVersionInfo nullVersion={ 0, 0, 0, 0 }; + if(0==memcmp(nullVersion, unicodeVersion, 4)) { + u_versionFromString(unicodeVersion, U_UNICODE_VERSION); + } memcpy(dataInfo.dataVersion, unicodeVersion, 4); UNewDataMemory *pData= udata_create(NULL, NULL, filename, &dataInfo, @@ -1080,7 +1205,7 @@ void Normalizer2DataBuilder::writeBinaryFile(const char *filename) { udata_writeBlock(pData, indexes, sizeof(indexes)); udata_writeBlock(pData, norm16TrieBytes.getAlias(), norm16TrieLength); udata_writeUString(pData, extraData.getBuffer(), extraData.length()); - + udata_writeBlock(pData, smallFCD, sizeof(smallFCD)); int32_t writtenSize=udata_finish(pData, errorCode); if(errorCode.isFailure()) { fprintf(stderr, "gennorm2: error %s writing the output file\n", errorCode.errorName()); diff --git a/tools/gennorm2/n2builder.h b/tools/gennorm2/n2builder.h index d5e7dc7c..9ca4ebf7 100644 --- a/tools/gennorm2/n2builder.h +++ b/tools/gennorm2/n2builder.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2009-2010, International Business Machines +* Copyright (C) 2009-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -90,7 +90,7 @@ private: void reorder(Norm *p, BuilderReorderingBuffer &buffer); UBool hasNoCompBoundaryAfter(BuilderReorderingBuffer &buffer); void setHangulData(); - void writeMapping(UChar32 c, const Norm *p, UnicodeString &dataString); + int32_t writeMapping(UChar32 c, const Norm *p, UnicodeString &dataString); void writeCompositions(UChar32 c, const Norm *p, UnicodeString &dataString); void writeExtraData(UChar32 c, uint32_t value, ExtraDataWriter &writer); int32_t getCenterNoNoDelta() { @@ -111,6 +111,7 @@ private: int32_t indexes[Normalizer2Impl::IX_COUNT]; UTrie2 *norm16Trie; UnicodeString extraData; + uint8_t smallFCD[0x100]; UVersionInfo unicodeVersion; }; diff --git a/tools/genrb/Makefile.in b/tools/genrb/Makefile.in index 83a67db8..ae05bed8 100644 --- a/tools/genrb/Makefile.in +++ b/tools/genrb/Makefile.in @@ -1,6 +1,6 @@ ################################################################################# ## Makefile.in for ICU - tools/genrb # -## Copyright (c) 1999-2009, International Business Machines Corporation and # +## Copyright (c) 1999-2011, International Business Machines Corporation and # ## others. All Rights Reserved. # ################################################################################# @@ -30,9 +30,6 @@ CLEANFILES = *~ $(MAN_FILES) $(DEPS) $(DERB_DEPS) TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) DERB = $(BINDIR)/$(DERB_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/genrb/derb.c b/tools/genrb/derb.c index 095304fe..65db73eb 100644 --- a/tools/genrb/derb.c +++ b/tools/genrb/derb.c @@ -30,7 +30,7 @@ #include <stdio.h> #include <ctype.h> -#if defined(U_WINDOWS) || defined(U_CYGWIN) || defined(U_MINGW) +#if U_PLATFORM_HAS_WIN32_API #include <io.h> #include <fcntl.h> #define USE_FILENO_BINARY_MODE 1 @@ -237,7 +237,7 @@ main(int argc, char* argv[]) { if (!(fromICUData = !uprv_strcmp(inputDir, "-"))) { UBool absfilename = *arg == U_FILE_SEP_CHAR; -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API if (!absfilename) { absfilename = (uprv_strlen(arg) > 2 && isalpha(arg[0]) && arg[1] == ':' && arg[2] == U_FILE_SEP_CHAR); @@ -293,7 +293,7 @@ main(int argc, char* argv[]) { if (tostdout) { out = stdout; -#if defined(U_WINDOWS) || defined(U_CYGWIN) || defined(U_MINGW) +#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; diff --git a/tools/genrb/errmsg.c b/tools/genrb/errmsg.c index 8b47f261..420c1239 100644 --- a/tools/genrb/errmsg.c +++ b/tools/genrb/errmsg.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2004, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -20,7 +20,7 @@ #include "cstring.h" #include "errmsg.h" -void error(uint32_t linenumber, const char *msg, ...) +U_CFUNC void error(uint32_t linenumber, const char *msg, ...) { va_list va; @@ -33,30 +33,30 @@ void error(uint32_t linenumber, const char *msg, ...) static UBool gShowWarning = TRUE; -void setShowWarning(UBool val) +U_CFUNC void setShowWarning(UBool val) { gShowWarning = val; } -UBool getShowWarning(){ +U_CFUNC UBool getShowWarning(){ return gShowWarning; } static UBool gStrict =FALSE; -UBool isStrict(){ +U_CFUNC UBool isStrict(){ return gStrict; } -void setStrict(UBool val){ +U_CFUNC void setStrict(UBool val){ gStrict = val; } static UBool gVerbose =FALSE; -UBool isVerbose(){ +U_CFUNC UBool isVerbose(){ return gVerbose; } -void setVerbose(UBool val){ +U_CFUNC void setVerbose(UBool val){ gVerbose = val; } -void warning(uint32_t linenumber, const char *msg, ...) +U_CFUNC void warning(uint32_t linenumber, const char *msg, ...) { if (gShowWarning) { @@ -69,4 +69,3 @@ void warning(uint32_t linenumber, const char *msg, ...) va_end(va); } } - diff --git a/tools/genrb/errmsg.h b/tools/genrb/errmsg.h index dbb8c66f..190a61eb 100644 --- a/tools/genrb/errmsg.h +++ b/tools/genrb/errmsg.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-1999, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -18,11 +18,12 @@ #ifndef ERROR_H #define ERROR_H 1 -extern const char *gCurrentFileName; +U_CDECL_BEGIN -void error (uint32_t linenumber, const char *msg, ...); -void warning (uint32_t linenumber, const char *msg, ...); +extern const char *gCurrentFileName; +U_CFUNC void error(uint32_t linenumber, const char *msg, ...); +U_CFUNC void warning(uint32_t linenumber, const char *msg, ...); /* Show warnings? */ U_CFUNC void setShowWarning(UBool val); @@ -35,4 +36,7 @@ U_CFUNC UBool isStrict(void); /* verbosity */ U_CFUNC void setVerbose(UBool val); U_CFUNC UBool isVerbose(void); + +U_CDECL_END + #endif diff --git a/tools/genrb/genrb.c b/tools/genrb/genrb.c index 4cf47e0e..e0ddd4ae 100644 --- a/tools/genrb/genrb.c +++ b/tools/genrb/genrb.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2010, International Business Machines +* Copyright (C) 1998-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -22,7 +22,8 @@ #include "ucmndata.h" /* TODO: for reading the pool bundle */ /* Protos */ -void processFile(const char *filename, const char* cp, const char *inputDir, const char *outputDir, const char *packageName, UErrorCode *status); +void processFile(const char *filename, const char* cp, const char *inputDir, const char *outputDir, + const char *packageName, UBool omitBinaryCollation, UErrorCode *status); static char *make_res_filename(const char *filename, const char *outputDir, const char *packageName, UErrorCode *status); @@ -167,7 +168,7 @@ main(int argc, fprintf(stderr, "Usage: %s [OPTIONS] [FILES]\n" "\tReads the list of resource bundle source files and creates\n" - "\tbinary version of reosurce bundles (.res files)\n", + "\tbinary version of resource bundles (.res files)\n", argv[0]); fprintf(stderr, "Options:\n" @@ -285,7 +286,7 @@ main(int argc, } } - initParser(options[NO_BINARY_COLLATION].doesOccur, options[NO_COLLATION_RULES].doesOccur); + initParser(options[NO_COLLATION_RULES].doesOccur); /*added by Jing*/ if(options[LANGUAGE].doesOccur) { @@ -424,7 +425,9 @@ main(int argc, if (isVerbose()) { printf("Processing file \"%s\"\n", theCurrentFileName); } - processFile(arg, encoding, inputDir, outputDir, gPackageName, &status); + processFile(arg, encoding, inputDir, outputDir, gPackageName, + options[NO_BINARY_COLLATION].doesOccur, + &status); } uprv_free(poolBundle.fBytes); @@ -448,7 +451,9 @@ main(int argc, /* Process a file */ void -processFile(const char *filename, const char *cp, const char *inputDir, const char *outputDir, const char *packageName, UErrorCode *status) { +processFile( + const char *filename, const char *cp, const char *inputDir, const char *outputDir, const char *packageName, + UBool omitBinaryCollation, UErrorCode *status) { /*FileStream *in = NULL;*/ struct SRBRoot *data = NULL; UCHARBUF *ucbuf = NULL; @@ -471,6 +476,7 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch }else{ filelen = (int32_t)uprv_strlen(filename); } + if(inputDir == NULL) { const char *filenameBegin = uprv_strrchr(filename, U_FILE_SEP_CHAR); openFileName = (char *) uprv_malloc(dirlen + filelen + 2); @@ -555,7 +561,7 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch printf("autodetected encoding %s\n", cp); } /* Parse the data into an SRBRoot */ - data = parse(ucbuf, inputDir, outputDir, status); + data = parse(ucbuf, inputDir, outputDir, !omitBinaryCollation, status); if (data == NULL || U_FAILURE(*status)) { fprintf(stderr, "couldn't parse the file %s. Error:%s\n", filename,u_errorName(*status)); @@ -637,6 +643,7 @@ make_res_filename(const char *filename, int32_t pkgLen = 0; /* length of package prefix */ + if (U_FAILURE(*status)) { return 0; } diff --git a/tools/genrb/genrb.h b/tools/genrb/genrb.h index 4423ce72..a9afab8b 100644 --- a/tools/genrb/genrb.h +++ b/tools/genrb/genrb.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2002-2010, International Business Machines +* Copyright (C) 2002-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -39,12 +39,19 @@ /* The version of genrb */ #define GENRB_VERSION "3.3" +U_CDECL_BEGIN + +extern UBool gIncludeUnihanColl; + U_CAPI void processFile( const char *filename, const char* cp, const char *inputDir, const char *outputDir, const char *packageName, + UBool omitBinaryCollation, UErrorCode *status); +U_CDECL_END + #endif diff --git a/tools/genrb/genrb.vcxproj b/tools/genrb/genrb.vcxproj index 35c1d086..b7f48efb 100644 --- a/tools/genrb/genrb.vcxproj +++ b/tools/genrb/genrb.vcxproj @@ -240,7 +240,7 @@ <ItemGroup>
<ClCompile Include="errmsg.c" />
<ClCompile Include="genrb.c" />
- <ClCompile Include="parse.c" />
+ <ClCompile Include="parse.cpp" />
<ClCompile Include="prscmnts.cpp" />
<ClCompile Include="rbutil.c" />
<ClCompile Include="read.c" />
@@ -278,4 +278,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> +</Project>
diff --git a/tools/genrb/genrb.vcxproj.filters b/tools/genrb/genrb.vcxproj.filters index 735313a2..c45441c6 100644 --- a/tools/genrb/genrb.vcxproj.filters +++ b/tools/genrb/genrb.vcxproj.filters @@ -21,7 +21,7 @@ <ClCompile Include="genrb.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="parse.c">
+ <ClCompile Include="parse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="prscmnts.cpp">
diff --git a/tools/genrb/parse.c b/tools/genrb/parse.cpp index 893c1d24..b9e393c2 100644 --- a/tools/genrb/parse.c +++ b/tools/genrb/parse.cpp @@ -1,12 +1,12 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2011, International Business Machines +* Copyright (C) 1998-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * -* File parse.c +* File parse.cpp * * Modification History: * @@ -35,8 +35,6 @@ #include "unicode/putil.h" #include <stdio.h> -extern UBool gIncludeUnihanColl; - /* Number of tokens to read ahead of the current stream position */ #define MAX_LOOKAHEAD 3 @@ -86,9 +84,9 @@ typedef struct { uint32_t inputdirLength; const char *outputdir; uint32_t outputdirLength; + UBool makeBinaryCollation; } ParseState; -static UBool gMakeBinaryCollation = TRUE; static UBool gOmitCollationRules = FALSE; typedef struct SResource * @@ -264,7 +262,7 @@ static char *getInvariantString(ParseState* state, uint32_t *line, struct UStrin return NULL; } - result = uprv_malloc(count+1); + result = reinterpret_cast<char *>(uprv_malloc(count+1)); if (result == NULL) { @@ -277,7 +275,7 @@ static char *getInvariantString(ParseState* state, uint32_t *line, struct UStrin } static struct SResource * -parseUCARules(ParseState* state, char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) +parseUCARules(ParseState* state, char *tag, uint32_t startline, const struct UString* /*comment*/, UErrorCode *status) { struct SResource *result = NULL; struct UString *tokenValue; @@ -380,7 +378,7 @@ parseUCARules(ParseState* state, char *tag, uint32_t startline, const struct USt { c = unescape(ucbuf, status); - if (c == U_ERR) + if (c == (UChar32)U_ERR) { uprv_free(pTarget); T_FileStream_close(file); @@ -396,7 +394,7 @@ parseUCARules(ParseState* state, char *tag, uint32_t startline, const struct USt } /* Append UChar * after dissembling if c > 0xffff*/ - if (c != U_EOF) + if (c != (UChar32)U_EOF) { U_APPEND_CHAR32(c, target,len); } @@ -422,7 +420,7 @@ parseUCARules(ParseState* state, char *tag, uint32_t startline, const struct USt } static struct SResource * -parseTransliterator(ParseState* state, char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) +parseTransliterator(ParseState* state, char *tag, uint32_t startline, const struct UString* /*comment*/, UErrorCode *status) { struct SResource *result = NULL; struct UString *tokenValue; @@ -774,18 +772,23 @@ static const UChar* importFromDataFile(void* context, const char* locale, const } /* Parse the data into an SRBRoot */ - data = parse(ucbuf, genrbdata->inputDir, genrbdata->outputDir, status); + data = parse(ucbuf, genrbdata->inputDir, genrbdata->outputDir, FALSE, status); root = data->fRoot; collations = resLookup(root, "collations"); - collation = resLookup(collations, type); - sequence = resLookup(collation, "Sequence"); - urules = sequence->u.fString.fChars; - urulesLength = sequence->u.fString.fLength; - *pLength = urulesLength; + if (collations != NULL) { + collation = resLookup(collations, type); + if (collation != NULL) { + sequence = resLookup(collation, "Sequence"); + if (sequence != NULL) { + urules = sequence->u.fString.fChars; + urulesLength = sequence->u.fString.fLength; + *pLength = urulesLength; + } + } + } finish: - if (inputDirBuf != NULL) { uprv_free(inputDirBuf); } @@ -801,6 +804,27 @@ finish: return urules; } +// Quick-and-dirty escaping function. +// Assumes that we are on an ASCII-based platform. +static void +escape(const UChar *s, char *buffer) { + int32_t length = u_strlen(s); + int32_t i = 0; + for (;;) { + UChar32 c; + U16_NEXT(s, i, length, c); + if (c == 0) { + *buffer = 0; + return; + } else if (0x20 <= c && c <= 0x7e) { + // printable ASCII + *buffer++ = (char)c; // assumes ASCII-based platform + } else { + buffer += sprintf(buffer, "\\u%04X", (int)c); + } + } +} + static struct SResource * addCollation(ParseState* state, struct SResource *result, uint32_t startline, UErrorCode *status) { @@ -810,7 +834,6 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U enum ETokenType token; char subtag[1024]; UVersionInfo version; - UBool override = FALSE; uint32_t line; GenrbData genrbdata; /* '{' . (name resource)* '}' */ @@ -877,12 +900,7 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U } else if (uprv_strcmp(subtag, "Override") == 0) { - override = FALSE; - - if (u_strncmp(member->u.fString.fChars, trueValue, u_strlen(trueValue)) == 0) - { - override = TRUE; - } + // UBool override = (u_strncmp(member->u.fString.fChars, trueValue, u_strlen(trueValue)) == 0); table_add(result, member, line, status); } @@ -895,8 +913,7 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U #if UCONFIG_NO_COLLATION || UCONFIG_NO_FILE_IO warning(line, "Not building collation elements because of UCONFIG_NO_COLLATION and/or UCONFIG_NO_FILE_IO, see uconfig.h"); #else - if(gMakeBinaryCollation) { - UErrorCode intStatus = U_ZERO_ERROR; + if(state->makeBinaryCollation) { /* do the collation elements */ int32_t len = 0; @@ -910,6 +927,8 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U genrbdata.inputDir = state->inputdir; genrbdata.outputDir = state->outputdir; + UErrorCode intStatus = U_ZERO_ERROR; + uprv_memset(&parseError, 0, sizeof(parseError)); coll = ucol_openRulesForImport(member->u.fString.fChars, member->u.fString.fLength, UCOL_OFF, UCOL_DEFAULT_STRENGTH,&parseError, importFromDataFile, &genrbdata, &intStatus); @@ -935,7 +954,7 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U struct SResource *collationBin = bin_open(state->bundle, "%%CollationBin", len, data, NULL, NULL, status); table_add(result, collationBin, line, status); uprv_free(data); - + reorderCodeCount = ucol_getReorderCodes( coll, reorderCodes, USCRIPT_CODE_LIMIT + (UCOL_REORDER_CODE_LIMIT - UCOL_REORDER_CODE_FIRST), &intStatus); if (U_SUCCESS(intStatus) && reorderCodeCount > 0) { @@ -960,11 +979,23 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U else { if(intStatus == U_FILE_ACCESS_ERROR) { - error(startline, "Collation could not be built- U_FILE_ACCESS_ERROR. Make sure ICU's data has been built and is loading properly."); - *status = intStatus; - return NULL; + error(startline, "Collation could not be built- U_FILE_ACCESS_ERROR. Make sure ICU's data has been built and is loading properly."); + *status = intStatus; + return NULL; } - warning(line, "%%Collation could not be constructed from CollationElements - check context!"); + char preBuffer[100], postBuffer[100]; + escape(parseError.preContext, preBuffer); + escape(parseError.postContext, postBuffer); + warning(line, + "%%%%CollationBin could not be constructed from CollationElements\n" + " check context, check that the FractionalUCA.txt UCA version " + "matches the current UCD version\n" + " UErrorCode=%s UParseError={ line=%d offset=%d pre=<> post=<> }", + u_errorName(intStatus), + parseError.line, + parseError.offset, + preBuffer, + postBuffer); if(isStrict()){ *status = intStatus; return NULL; @@ -984,11 +1015,6 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U table_add(result, member, line, status); } } - - /*member = string_open(bundle, subtag, tokenValue->fChars, tokenValue->fLength, status);*/ - - /*expect(TOK_CLOSE_BRACE, NULL, NULL, status);*/ - if (U_FAILURE(*status)) { res_close(result); @@ -996,10 +1022,9 @@ addCollation(ParseState* state, struct SResource *result, uint32_t startline, U } } - /* not reached */ - /* A compiler warning will appear if all paths don't contain a return statement. */ -/* *status = U_INTERNAL_PROGRAM_ERROR; - return NULL;*/ + // Reached the end without a TOK_CLOSE_BRACE. Should be an error. + *status = U_INTERNAL_PROGRAM_ERROR; + return NULL; } static struct SResource * @@ -1092,7 +1117,6 @@ parseCollationElements(ParseState* state, char *tag, uint32_t startline, UBool n u_UCharsToChars(tokenValue->fChars, typeKeyword, u_strlen(tokenValue->fChars) + 1); if(uprv_strcmp(typeKeyword, "alias") == 0) { member = parseResource(state, subtag, NULL, status); - if (U_FAILURE(*status)) { res_close(result); @@ -1139,6 +1163,7 @@ realParseTable(ParseState* state, struct SResource *table, char *tag, uint32_t s UBool readToken = FALSE; /* '{' . (name resource)* '}' */ + if(isVerbose()){ printf(" parsing table %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); } @@ -1202,7 +1227,7 @@ realParseTable(ParseState* state, struct SResource *table, char *tag, uint32_t s } readToken = TRUE; ustr_deinit(&comment); - } + } /* not reached */ /* A compiler warning will appear if all paths don't contain a return statement. */ @@ -1233,7 +1258,6 @@ parseTable(ParseState* state, char *tag, uint32_t startline, const struct UStrin { return NULL; } - return realParseTable(state, result, tag, startline, status); } @@ -1454,7 +1478,7 @@ parseBinary(ParseState* state, char *tag, uint32_t startline, const struct UStri count = (uint32_t)uprv_strlen(string); if (count > 0){ if((count % 2)==0){ - value = uprv_malloc(sizeof(uint8_t) * count); + value = reinterpret_cast<uint8_t *>(uprv_malloc(sizeof(uint8_t) * count)); if (value == NULL) { @@ -1561,7 +1585,6 @@ parseImport(ParseState* state, char *tag, uint32_t startline, const struct UStri char *filename; uint32_t line; char *fullname = NULL; - int32_t numRead = 0; filename = getInvariantString(state, &line, NULL, status); if (U_FAILURE(*status)) @@ -1656,7 +1679,7 @@ parseImport(ParseState* state, char *tag, uint32_t startline, const struct UStri return NULL; } - numRead = T_FileStream_read (file, data, len); + /* int32_t numRead = */ T_FileStream_read (file, data, len); T_FileStream_close (file); result = bin_open(state->bundle, tag, len, data, fullname, comment, status); @@ -1817,7 +1840,7 @@ static struct { {"reserved", NULL, NULL} }; -void initParser(UBool omitBinaryCollation, UBool omitCollationRules) +void initParser(UBool omitCollationRules) { U_STRING_INIT(k_type_string, "string", 6); U_STRING_INIT(k_type_binary, "binary", 6); @@ -1838,11 +1861,10 @@ void initParser(UBool omitBinaryCollation, UBool omitCollationRules) U_STRING_INIT(k_type_plugin_transliterator, "process(transliterator)", 23); U_STRING_INIT(k_type_plugin_dependency, "process(dependency)", 19); - gMakeBinaryCollation = !omitBinaryCollation; gOmitCollationRules = omitCollationRules; } -static U_INLINE UBool isTable(enum EResourceType type) { +static inline UBool isTable(enum EResourceType type) { return (UBool)(type==RT_TABLE || type==RT_TABLE_NO_FALLBACK); } @@ -1865,7 +1887,7 @@ parseResourceType(ParseState* state, UErrorCode *status) /* Search for normal types */ result=RT_UNKNOWN; - while (++result < RT_RESERVED) { + while ((result=(EResourceType)(result+1)) < RT_RESERVED) { if (u_strcmp(tokenValue->fChars, gResourceTypes[result].nameUChars) == 0) { break; } @@ -1899,6 +1921,7 @@ parseResource(ParseState* state, char *tag, const struct UString *comment, UErro uint32_t startline; uint32_t line; + token = getToken(state, &tokenValue, NULL, &startline, status); if(isVerbose()){ @@ -1940,6 +1963,7 @@ parseResource(ParseState* state, char *tag, const struct UString *comment, UErro return NULL; } + if (resType == RT_UNKNOWN) { /* No explicit type, so try to work it out. At this point, we've read the first '{'. @@ -2000,6 +2024,7 @@ parseResource(ParseState* state, char *tag, const struct UString *comment, UErro return NULL; } + /* We should now know what we need to parse next, so call the appropriate parser function and return. */ parseFunction = gResourceTypes[resType].parseFunction; @@ -2016,7 +2041,8 @@ parseResource(ParseState* state, char *tag, const struct UString *comment, UErro /* parse the top-level resource */ struct SRBRoot * -parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, UErrorCode *status) +parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, UBool makeBinaryCollation, + UErrorCode *status) { struct UString *tokenValue; struct UString comment; @@ -2026,6 +2052,7 @@ parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, UErrorCode *st ParseState state; uint32_t i; + for (i = 0; i < MAX_LOOKAHEAD + 1; i++) { ustr_init(&state.lookahead[i].value); @@ -2038,6 +2065,7 @@ parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, UErrorCode *st state.inputdirLength = (state.inputdir != NULL) ? (uint32_t)uprv_strlen(state.inputdir) : 0; state.outputdir = outputDir; state.outputdirLength = (state.outputdir != NULL) ? (uint32_t)uprv_strlen(state.outputdir) : 0; + state.makeBinaryCollation = makeBinaryCollation; ustr_init(&comment); expect(&state, TOK_STRING, &tokenValue, &comment, NULL, status); @@ -2065,9 +2093,7 @@ parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, UErrorCode *st else { *status=U_PARSE_ERROR; - /* printf("asdsdweqdasdad\n"); */ - - error(line, "parse error. Stopped parsing with %s", u_errorName(*status)); + error(line, "parse error. Stopped parsing with %s", u_errorName(*status)); } } else @@ -2103,12 +2129,11 @@ parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, UErrorCode *st } /* top-level tables need not handle special table names like "collations" */ realParseTable(&state, state.bundle->fRoot, NULL, line, status); - if(dependencyArray!=NULL){ table_add(state.bundle->fRoot, dependencyArray, 0, status); dependencyArray = NULL; } - if (U_FAILURE(*status)) + if (U_FAILURE(*status)) { bundle_close(state.bundle, status); res_close(dependencyArray); diff --git a/tools/genrb/parse.h b/tools/genrb/parse.h index 7c575fa6..5d39970b 100644 --- a/tools/genrb/parse.h +++ b/tools/genrb/parse.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2006, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -24,10 +24,11 @@ U_CDECL_BEGIN /* One time parser initalisation */ -void initParser(UBool omitBinaryCollation, UBool omitCollationRules); +void initParser(UBool omitCollationRules); /* Parse a ResourceBundle text file */ -struct SRBRoot* parse(UCHARBUF *buf, const char* inputDir, const char* outputDir, UErrorCode *status); +struct SRBRoot* parse(UCHARBUF *buf, const char* inputDir, const char* outputDir, + UBool omitBinaryCollation, UErrorCode *status); U_CDECL_END diff --git a/tools/genrb/read.c b/tools/genrb/read.c index 15c4db4d..8efad67c 100644 --- a/tools/genrb/read.c +++ b/tools/genrb/read.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2009, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -47,7 +47,7 @@ static void seekUntilEndOfComment (UCHARBUF *buf, struct UString *token, UErr static UBool isWhitespace (UChar32 c); static UBool isNewline (UChar32 c); -void resetLineNumber() { +U_CFUNC void resetLineNumber() { lineCount = 1; } @@ -59,11 +59,12 @@ void resetLineNumber() { never return eString twice in a row; instead, multiple adjacent string tokens will be merged into one, with no intervening space. */ -enum ETokenType getNextToken(UCHARBUF* buf, - struct UString *token, - uint32_t *linenumber, /* out: linenumber of token */ - struct UString *comment, - UErrorCode *status) { +U_CFUNC enum ETokenType +getNextToken(UCHARBUF* buf, + struct UString *token, + uint32_t *linenumber, /* out: linenumber of token */ + struct UString *comment, + UErrorCode *status) { enum ETokenType result; UChar32 c; @@ -428,8 +429,7 @@ static void seekUntilEndOfComment(UCHARBUF *buf, } } -UChar32 unescape(UCHARBUF *buf, - UErrorCode *status) { +U_CFUNC UChar32 unescape(UCHARBUF *buf, UErrorCode *status) { if (U_FAILURE(*status)) { return U_EOF; } diff --git a/tools/genrb/read.h b/tools/genrb/read.h index 96bd9608..f79b145f 100644 --- a/tools/genrb/read.h +++ b/tools/genrb/read.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2003, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -38,14 +38,15 @@ enum ETokenType TOK_TOKEN_COUNT /* Number of "real" token types */ }; -UChar32 unescape(UCHARBUF *buf, UErrorCode *status); +U_CFUNC UChar32 unescape(UCHARBUF *buf, UErrorCode *status); -void resetLineNumber(void); +U_CFUNC void resetLineNumber(void); -enum ETokenType getNextToken(UCHARBUF *buf, - struct UString *token, - uint32_t *linenumber, /* out: linenumber of token */ - struct UString *comment, - UErrorCode *status); +U_CFUNC enum ETokenType +getNextToken(UCHARBUF *buf, + struct UString *token, + uint32_t *linenumber, /* out: linenumber of token */ + struct UString *comment, + UErrorCode *status); #endif diff --git a/tools/genrb/reslist.c b/tools/genrb/reslist.c index 66d37040..0f0130a2 100644 --- a/tools/genrb/reslist.c +++ b/tools/genrb/reslist.c @@ -24,7 +24,9 @@ #include "errmsg.h" #include "uarrsort.h" +#include "uelement.h" #include "uinvchar.h" +#include "ustr_imp.h" /* * Align binary data at a 16-byte offset from the start of the resource bundle, @@ -884,13 +886,13 @@ struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const stru } static int32_t U_CALLCONV -string_hash(const UHashTok key) { +string_hash(const UElement key) { const struct SResource *res = (struct SResource *)key.pointer; - return uhash_hashUCharsN(res->u.fString.fChars, res->u.fString.fLength); + return ustr_hashUCharsN(res->u.fString.fChars, res->u.fString.fLength); } static UBool U_CALLCONV -string_comp(const UHashTok key1, const UHashTok key2) { +string_comp(const UElement key1, const UElement key2) { const struct SResource *res1 = (struct SResource *)key1.pointer; const struct SResource *res2 = (struct SResource *)key2.pointer; return 0 == u_strCompare(res1->u.fString.fChars, res1->u.fString.fLength, diff --git a/tools/genrb/ustr.c b/tools/genrb/ustr.c index ff7487b3..faa03ade 100644 --- a/tools/genrb/ustr.c +++ b/tools/genrb/ustr.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2008, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -27,14 +27,14 @@ static void ustr_resize(struct UString *s, int32_t len, UErrorCode *status); /* Macros */ #define ALLOCATION(minSize) (minSize < 0x80 ? 0x80 : (2 * minSize + 0x80) & ~(0x80 - 1)) -void +U_CFUNC void ustr_init(struct UString *s) { s->fChars = 0; s->fLength = s->fCapacity = 0; } -void +U_CFUNC void ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode *status) { int i = 0; @@ -65,7 +65,7 @@ ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode } } -void +U_CFUNC void ustr_deinit(struct UString *s) { if (s) { @@ -75,7 +75,7 @@ ustr_deinit(struct UString *s) } } -void +U_CFUNC void ustr_cpy(struct UString *dst, const struct UString *src, UErrorCode *status) @@ -96,7 +96,7 @@ ustr_cpy(struct UString *dst, dst->fChars[dst->fLength] = 0x0000; } -void +U_CFUNC void ustr_setlen(struct UString *s, int32_t len, UErrorCode *status) @@ -114,7 +114,7 @@ ustr_setlen(struct UString *s, s->fChars[len] = 0x0000; } -void +U_CFUNC void ustr_cat(struct UString *dst, const struct UString *src, UErrorCode *status) @@ -122,7 +122,7 @@ ustr_cat(struct UString *dst, ustr_ncat(dst, src, src->fLength, status); } -void +U_CFUNC void ustr_ncat(struct UString *dst, const struct UString *src, int32_t n, @@ -143,7 +143,7 @@ ustr_ncat(struct UString *dst, dst->fChars[dst->fLength] = 0x0000; } -void +U_CFUNC void ustr_ucat(struct UString *dst, UChar c, UErrorCode *status) @@ -162,7 +162,7 @@ ustr_ucat(struct UString *dst, dst->fLength += 1; dst->fChars[dst->fLength] = 0x0000; } -void +U_CFUNC void ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status){ if(c > 0x10FFFF){ *status = U_ILLEGAL_CHAR_FOUND; @@ -175,7 +175,7 @@ ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status){ ustr_ucat(dst, (UChar) c, status); } } -void +U_CFUNC void ustr_uscat(struct UString *dst, const UChar* src,int len, UErrorCode *status) diff --git a/tools/genrb/ustr.h b/tools/genrb/ustr.h index 085643a8..b2d59725 100644 --- a/tools/genrb/ustr.h +++ b/tools/genrb/ustr.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2003, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -42,25 +42,25 @@ struct UString { int32_t fCapacity; }; -void ustr_init(struct UString *s); +U_CFUNC void ustr_init(struct UString *s); -void +U_CFUNC void ustr_initChars(struct UString *s, const char* source, int32_t length, UErrorCode *status); -void ustr_deinit(struct UString *s); +U_CFUNC void ustr_deinit(struct UString *s); -void ustr_setlen(struct UString *s, int32_t len, UErrorCode *status); +U_CFUNC void ustr_setlen(struct UString *s, int32_t len, UErrorCode *status); -void ustr_cpy(struct UString *dst, const struct UString *src, - UErrorCode *status); +U_CFUNC void ustr_cpy(struct UString *dst, const struct UString *src, + UErrorCode *status); -void ustr_cat(struct UString *dst, const struct UString *src, - UErrorCode *status); +U_CFUNC void ustr_cat(struct UString *dst, const struct UString *src, + UErrorCode *status); -void ustr_ncat(struct UString *dst, const struct UString *src, - int32_t n, UErrorCode *status); +U_CFUNC void ustr_ncat(struct UString *dst, const struct UString *src, + int32_t n, UErrorCode *status); -void ustr_ucat(struct UString *dst, UChar c, UErrorCode *status); -void ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status); -void ustr_uscat(struct UString *dst, const UChar* src,int len,UErrorCode *status); +U_CFUNC void ustr_ucat(struct UString *dst, UChar c, UErrorCode *status); +U_CFUNC void ustr_u32cat(struct UString *dst, UChar32 c, UErrorCode *status); +U_CFUNC void ustr_uscat(struct UString *dst, const UChar* src,int len,UErrorCode *status); #endif diff --git a/tools/genrb/wrtjava.c b/tools/genrb/wrtjava.c index 948fc8dd..ff6f63b0 100644 --- a/tools/genrb/wrtjava.c +++ b/tools/genrb/wrtjava.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2000-2009, International Business Machines +* Copyright (C) 2000-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -27,7 +27,6 @@ #include "unicode/ucnv.h" #include "genrb.h" #include "rle.h" -#include "ucol_tok.h" #include "uhash.h" #include "uresimp.h" #include "unicode/ustring.h" @@ -326,8 +325,6 @@ array_write_java( struct SResource *res, UErrorCode *status) { uint32_t i = 0; const char* arr ="new String[] { \n"; struct SResource *current = NULL; - struct SResource *first =NULL; - UBool decrementTabs = FALSE; UBool allStrings = TRUE; if (U_FAILURE(*status)) { @@ -352,13 +349,11 @@ array_write_java( struct SResource *res, UErrorCode *status) { write_tabs(out); T_FileStream_write(out, object, (int32_t)uprv_strlen(object)); tabCount++; - decrementTabs = TRUE; }else{ write_tabs(out); T_FileStream_write(out, arr, (int32_t)uprv_strlen(arr)); tabCount++; } - first=current; while (current != NULL) { /*if(current->fType==URES_STRING){ write_tabs(out); @@ -511,9 +506,7 @@ static UBool start = TRUE; static void table_write_java(struct SResource *res, UErrorCode *status) { uint32_t i = 0; - UBool allStrings =TRUE; struct SResource *current = NULL; - struct SResource *save = NULL; const char* obj = "new Object[][]{\n"; if (U_FAILURE(*status)) { @@ -527,7 +520,7 @@ table_write_java(struct SResource *res, UErrorCode *status) { tabCount++; } start = FALSE; - save = current = res->u.fTable.fFirst; + current = res->u.fTable.fFirst; i = 0; @@ -542,7 +535,6 @@ table_write_java(struct SResource *res, UErrorCode *status) { tabCount++; - allStrings=FALSE; write_tabs(out); if(currentKeyString != NULL) { diff --git a/tools/genrb/wrtxml.cpp b/tools/genrb/wrtxml.cpp index 52c04ea6..7e760534 100644 --- a/tools/genrb/wrtxml.cpp +++ b/tools/genrb/wrtxml.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2002-2009, International Business Machines +* Copyright (C) 2002-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -674,12 +674,10 @@ array_write_xml(struct SResource *res, const char* id, const char* language, UEr int index = 0; struct SResource *current = NULL; - struct SResource *first =NULL; sid = printContainer(res, group, array_restype, NULL, id, status); current = res->u.fArray.fFirst; - first=current; while (current != NULL) { char c[256] = {0}; @@ -910,7 +908,6 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UBo uint32_t i = 0; struct SResource *current = NULL; - struct SResource *save = NULL; char* sid = NULL; if (U_FAILURE(*status)) { @@ -923,7 +920,7 @@ table_write_xml(struct SResource *res, const char* id, const char* language, UBo sid[0] = '\0'; } - save = current = res->u.fTable.fFirst; + current = res->u.fTable.fFirst; i = 0; while (current != NULL) { diff --git a/tools/genren/genren.pl b/tools/genren/genren.pl index 689befa6..4e01028c 100755 --- a/tools/genren/genren.pl +++ b/tools/genren/genren.pl @@ -105,6 +105,10 @@ print HEADER <<"EndOfHeaderComment"; Normally (if utypes.h or umachine.h was included first) this will not be necessary as it will already be defined. */ #ifndef U_ICU_ENTRY_POINT_RENAME +#include "unicode/uconfig.h" +#endif + +#ifndef U_ICU_ENTRY_POINT_RENAME #include "unicode/umachine.h" #endif @@ -178,9 +182,9 @@ for(;@ARGV; shift(@ARGV)) { } elsif($CppName[0] =~ /^~/) { &verbose ("Skipping C++ destructor: $_\n"); } else { - &verbose( " Class: '$CppName[0]': $_ \n"); - $CppClasses{$CppName[0]}++; - $symbolCount++; + &verbose( "Skipping C++ class: '$CppName[0]': $_ \n"); + # $CppClasses{$CppName[0]}++; + # $symbolCount++; } } elsif ( my ($cfn) = m/^([A-Za-z0-9_]*)\(.*/ ) { &verbose ( "$ARGV[0]: got global C++ function $cfn with '$_'\n" ); @@ -228,15 +232,6 @@ foreach(sort keys(%CFuncs)) { # print HEADER "#define $_ $_$U_ICU_VERSION_SUFFIX\n"; } -print HEADER "\n\n"; -print HEADER "/* C++ class names renaming defines */\n\n"; -print HEADER "#ifdef XP_CPLUSPLUS\n"; -print HEADER "#if !U_HAVE_NAMESPACE\n\n"; -foreach(sort keys(%CppClasses)) { - print HEADER "#define $_ U_ICU_ENTRY_POINT_RENAME($_)\n"; -} -print HEADER "\n#endif\n"; -print HEADER "#endif\n"; print HEADER "\n#endif\n"; print HEADER "\n#endif\n"; @@ -264,4 +259,3 @@ EndHelpText exit 0; } - diff --git a/tools/gensprep/Makefile.in b/tools/gensprep/Makefile.in index be170ac4..4da97bd1 100644 --- a/tools/gensprep/Makefile.in +++ b/tools/gensprep/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/gensprep -## Copyright (c) 2001-2005, International Business Machines Corporation and +## Copyright (c) 2001-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis/Markus W. Scherer @@ -27,9 +27,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/gensprep/store.c b/tools/gensprep/store.c index d2ec3741..49ea02eb 100644 --- a/tools/gensprep/store.c +++ b/tools/gensprep/store.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2009, International Business Machines +* Copyright (C) 1999-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -22,6 +22,7 @@ #include "cstring.h" #include "filestrm.h" #include "unicode/udata.h" +#include "unicode/utf16.h" #include "utrie.h" #include "unewdata.h" #include "gensprep.h" @@ -196,8 +197,7 @@ static UNewTrie *sprepTrie; extern void init() { - sprepTrie = (UNewTrie *)uprv_malloc(sizeof(UNewTrie)); - uprv_memset(sprepTrie, 0, sizeof(UNewTrie)); + sprepTrie = (UNewTrie *)uprv_calloc(1, sizeof(UNewTrie)); /* initialize the two tries */ if(NULL==utrie_open(sprepTrie, NULL, MAX_DATA_LENGTH, 0, 0, FALSE)) { @@ -253,9 +253,7 @@ storeMappingData(){ elementCount = uhash_count(hashTable); /*initialize the mapping data */ - mappingData = (uint16_t*) uprv_malloc(U_SIZEOF_UCHAR * (mappingDataCapacity)); - - uprv_memset(mappingData,0,U_SIZEOF_UCHAR * mappingDataCapacity); + mappingData = (uint16_t*) uprv_calloc(mappingDataCapacity, U_SIZEOF_UCHAR); while(writtenElementCount < elementCount){ @@ -458,17 +456,15 @@ storeMapping(uint32_t codepoint, uint32_t* mapping,int32_t length, */ } - map = (UChar*) uprv_malloc(U_SIZEOF_UCHAR * (adjustedLen+1)); - uprv_memset(map,0,U_SIZEOF_UCHAR * (adjustedLen+1)); - + map = (UChar*) uprv_calloc(adjustedLen + 1, U_SIZEOF_UCHAR); i=0; while(i<length){ if(mapping[i] <= 0xFFFF){ map[i] = (uint16_t)mapping[i]; }else{ - map[i] = UTF16_LEAD(mapping[i]); - map[i+1] = UTF16_TRAIL(mapping[i]); + map[i] = U16_LEAD(mapping[i]); + map[i+1] = U16_TRAIL(mapping[i]); } i++; } @@ -555,12 +551,10 @@ storeRange(uint32_t start, uint32_t end, UStringPrepType type,UErrorCode* status /* folding value: just store the offset (16 bits) if there is any non-0 entry */ static uint32_t U_CALLCONV getFoldedValue(UNewTrie *trie, UChar32 start, int32_t offset) { - uint32_t foldedValue, value; + uint32_t value; UChar32 limit=0; UBool inBlockZero; - foldedValue=0; - limit=start+0x400; while(start<limit) { value=utrie_get32(trie, start, &inBlockZero); diff --git a/tools/gentest/Makefile.in b/tools/gentest/Makefile.in index 6d8e7eb1..7b70a1c0 100644 --- a/tools/gentest/Makefile.in +++ b/tools/gentest/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/gentest -## Copyright (c) 1999-2008, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Madhu Katragadda @@ -20,9 +20,6 @@ CLEANFILES = *~ $(DEPS) ## Target information TARGET = gentest$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil -I$(top_srcdir)/tools/ctestfw CPPFLAGS+= -I$(top_srcdir)/i18n LIBS = $(LIBCTESTFW) $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/icuinfo/Makefile.in b/tools/icuinfo/Makefile.in index 18b58f7b..4ba741d9 100644 --- a/tools/icuinfo/Makefile.in +++ b/tools/icuinfo/Makefile.in @@ -20,9 +20,6 @@ CLEANFILES = *~ $(DEPS) $(PLUGIN_OBJECTS) $(PLUGINFILE) $(PLUGIN) ## Target information TARGET = icuinfo$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil -I$(top_srcdir)/tools/ctestfw CPPFLAGS+= -I$(top_srcdir)/i18n LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) @@ -34,9 +31,7 @@ DEPS = $(OBJECTS:.o=.d) # pass some information -ICUINFO_OPTS=-i ../../data/out/build/$(ICUDATA_PLATFORM_NAME) - -CPPFLAGS+= "-DU_PLATFORM=\"@platform@\"" "-DU_BUILD=\"@build@\"" "-DU_HOST=\"@host@\"" "-DU_CC=\"@CC@\"" "-DU_CXX=\"@CXX@\"" +ICUINFO_OPTS=-i ../../data/out/build/$(ICUDATA_PLATFORM_NAME) -x $(top_builddir)/config/icuinfo.xml -v ## List of phony targets .PHONY : all all-local install install-local clean clean-local \ diff --git a/tools/icuinfo/icuinfo.cpp b/tools/icuinfo/icuinfo.cpp index 4144570f..4c59b908 100644 --- a/tools/icuinfo/icuinfo.cpp +++ b/tools/icuinfo/icuinfo.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2010, International Business Machines +* Copyright (C) 1999-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -43,6 +43,7 @@ static UOption options[]={ /*4*/ UOPTION_DEF("list-plugins", 'L', UOPT_NO_ARG), /*5*/ UOPTION_DEF("milisecond-time", 'm', UOPT_NO_ARG), /*6*/ UOPTION_DEF("cleanup", 'K', UOPT_NO_ARG), + /*7*/ UOPTION_DEF("xml", 'x', UOPT_REQUIRES_ARG), }; static UErrorCode initStatus = U_ZERO_ERROR; @@ -55,108 +56,58 @@ static void do_init() { } } -/** - * Print the current platform - */ -static const char *getPlatform() -{ -#if defined(U_PLATFORM) - return U_PLATFORM; -#elif defined(U_WINDOWS) - return "Windows"; -#elif defined(U_PALMOS) - return "PalmOS"; -#elif defined(_PLATFORM_H) - return "Other (POSIX-like)"; -#else - return "unknown" -#endif -} void cmd_millis() { printf("Milliseconds since Epoch: %.0f\n", uprv_getUTCtime()); } -void cmd_version(UBool noLoad) +void cmd_version(UBool /* noLoad */, UErrorCode &errorCode) { - UVersionInfo icu; - char str[200]; - printf("<ICUINFO>\n"); - printf("International Components for Unicode for C/C++\n"); - printf("%s\n", U_COPYRIGHT_STRING); - printf("Compiled-Version: %s\n", U_ICU_VERSION); - u_getVersion(icu); - u_versionToString(icu, str); - printf("Runtime-Version: %s\n", str); - printf("Compiled-Unicode-Version: %s\n", U_UNICODE_VERSION); - u_getUnicodeVersion(icu); - u_versionToString(icu, str); - printf("Runtime-Unicode-Version: %s\n", U_UNICODE_VERSION); - printf("Platform: %s\n", getPlatform()); -#if defined(U_BUILD) - printf("Build: %s\n", U_BUILD); -#if defined(U_HOST) - if(strcmp(U_BUILD,U_HOST)) { - printf("Host: %s\n", U_HOST); - } -#endif -#endif -#if defined(U_CC) - printf("C compiler: %s\n", U_CC); -#endif -#if defined(U_CXX) - printf("C++ compiler: %s\n", U_CXX); -#endif -#if defined(CYGWINMSVC) - printf("Cygwin: CYGWINMSVC\n"); -#endif - printf("ICUDATA: %s\n", U_ICUDATA_NAME); + do_init(); - printf("Data Directory: %s\n", u_getDataDirectory()); - printf("ICU Initialization returned: %s\n", u_errorName(initStatus)); - printf( "Default locale: %s\n", uloc_getDefault()); - { - UErrorCode subStatus = U_ZERO_ERROR; - ulocdata_getCLDRVersion(icu, &subStatus); - if(U_SUCCESS(subStatus)) { - u_versionToString(icu, str); - printf("CLDR-Version: %s\n", str); - } else { - printf("CLDR-Version: %s\n", u_errorName(subStatus)); - } - } + + udbg_writeIcuInfo(stdout); /* print the XML format */ -#if !UCONFIG_NO_CONVERSION - if(noLoad == FALSE) - { - printf("Default converter: %s\n", ucnv_getDefaultName()); + union { + uint8_t byte; + uint16_t word; + } u; + u.word=0x0100; + if(U_IS_BIG_ENDIAN==u.byte) { + //printf("U_IS_BIG_ENDIAN: %d\n", U_IS_BIG_ENDIAN); + } else { + fprintf(stderr, " error: U_IS_BIG_ENDIAN=%d != %d=actual 'is big endian'\n", + U_IS_BIG_ENDIAN, u.byte); + errorCode=U_INTERNAL_PROGRAM_ERROR; } -#endif -#if !UCONFIG_NO_FORMATTING - { - UChar buf[100]; - char buf2[100]; - UErrorCode subsubStatus= U_ZERO_ERROR; - int32_t len; - len = ucal_getDefaultTimeZone(buf, 100, &subsubStatus); - if(U_SUCCESS(subsubStatus)&&len>0) { - u_UCharsToChars(buf, buf2, len+1); - printf("Default TZ: %s\n", buf2); - } else { - printf("Default TZ: %s\n", u_errorName(subsubStatus)); - } + if(U_SIZEOF_WCHAR_T==sizeof(wchar_t)) { + //printf("U_SIZEOF_WCHAR_T: %d\n", U_SIZEOF_WCHAR_T); + } else { + fprintf(stderr, " error: U_SIZEOF_WCHAR_T=%d != %d=sizeof(wchar_t)\n", + U_SIZEOF_WCHAR_T, (int)sizeof(wchar_t)); + errorCode=U_INTERNAL_PROGRAM_ERROR; } - { - UErrorCode subStatus = U_ZERO_ERROR; - const char *tzVer = ucal_getTZDataVersion(&subStatus); - if(U_FAILURE(subStatus)) { - tzVer = u_errorName(subStatus); - } - printf("TZ data version: %s\n", tzVer); + + int charsetFamily; + if('A'==0x41) { + charsetFamily=U_ASCII_FAMILY; + } else if('A'==0xc1) { + charsetFamily=U_EBCDIC_FAMILY; + } else { + charsetFamily=-1; // unknown } -#endif + if(U_CHARSET_FAMILY==charsetFamily) { + //printf("U_CHARSET_FAMILY: %d\n", U_CHARSET_FAMILY); + } else { + fprintf(stderr, " error: U_CHARSET_FAMILY=%d != %d=actual charset family\n", + U_CHARSET_FAMILY, charsetFamily); + errorCode=U_INTERNAL_PROGRAM_ERROR; + } + + printf("\n\nICU Initialization returned: %s\n", u_errorName(initStatus)); + #if U_ENABLE_DYLOAD const char *pluginFile = uplug_getPluginFile(); @@ -164,7 +115,6 @@ void cmd_version(UBool noLoad) #else fprintf(stderr, "Dynamic Loading: is disabled. No plugins will be loaded at start-up.\n"); #endif - printf("</ICUINFO>\n\n"); } void cmd_cleanup() @@ -298,19 +248,32 @@ main(int argc, char* argv[]) { cmd_listplugins(); didSomething = TRUE; } - + if(options[3].doesOccur) { - cmd_version(FALSE); + cmd_version(FALSE, errorCode); didSomething = TRUE; } - + + if(options[7].doesOccur) { /* 2nd part of version: cleanup */ + FILE *out = fopen(options[7].value, "w"); + if(out==NULL) { + fprintf(stderr,"ERR: can't write to XML file %s\n", options[7].value); + return 1; + } + /* todo: API for writing DTD? */ + fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); + udbg_writeIcuInfo(out); + fclose(out); + didSomething = TRUE; + } + if(options[6].doesOccur) { /* 2nd part of version: cleanup */ cmd_cleanup(); didSomething = TRUE; } - + if(!didSomething) { - cmd_version(FALSE); /* at least print the version # */ + cmd_version(FALSE, errorCode); /* at least print the version # */ } return U_FAILURE(errorCode); diff --git a/tools/icupkg/Makefile.in b/tools/icupkg/Makefile.in index 9b67b489..a8cd5a4b 100644 --- a/tools/icupkg/Makefile.in +++ b/tools/icupkg/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/icupkg -## Copyright (c) 1999-2006, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis @@ -26,9 +26,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/icuswap/Makefile.in b/tools/icuswap/Makefile.in index d2a3ac4e..e30d3d74 100644 --- a/tools/icuswap/Makefile.in +++ b/tools/icuswap/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/icuswap -## Copyright (c) 1999-2008, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis @@ -26,9 +26,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/makeconv/Makefile.in b/tools/makeconv/Makefile.in index 365401e2..f0659e07 100644 --- a/tools/makeconv/Makefile.in +++ b/tools/makeconv/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/makeconv -## Copyright (c) 1999-2005, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Stephen F. Booth @@ -26,9 +26,6 @@ CLEANFILES = *~ $(DEPS) $(MAN_FILES) ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/makeconv/genmbcs.c b/tools/makeconv/genmbcs.cpp index 84043833..5c4c911b 100644 --- a/tools/makeconv/genmbcs.c +++ b/tools/makeconv/genmbcs.cpp @@ -1,11 +1,11 @@ /* ******************************************************************************* * -* Copyright (C) 2000-2010, International Business Machines +* Copyright (C) 2000-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* -* file name: genmbcs.c +* file name: genmbcs.cpp * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 @@ -102,12 +102,12 @@ MBCSWrite(NewConverter *cnvData, const UConverterStaticData *staticData, /* helper ------------------------------------------------------------------- */ -static U_INLINE char +static inline char hexDigit(uint8_t digit) { return digit<=9 ? (char)('0'+digit) : (char)('a'-10+digit); } -static U_INLINE char * +static inline char * printBytes(char *buffer, const uint8_t *bytes, int32_t length) { char *s=buffer; while(length>0) { @@ -555,7 +555,7 @@ MBCSIsValid(NewConverter *cnvData, static UBool MBCSSingleAddFromUnicode(MBCSData *mbcsData, - const uint8_t *bytes, int32_t length, + const uint8_t *bytes, int32_t /*length*/, UChar32 c, int8_t flag) { uint16_t *stage3, *p; @@ -1322,7 +1322,7 @@ compactStage2(MBCSData *mbcsData) { } static void -MBCSPostprocess(MBCSData *mbcsData, const UConverterStaticData *staticData) { +MBCSPostprocess(MBCSData *mbcsData, const UConverterStaticData * /*staticData*/) { UCMStates *states; int32_t maxCharLength, stage3Width; @@ -1408,7 +1408,7 @@ MBCSWrite(NewConverter *cnvData, const UConverterStaticData *staticData, int32_t i, stage1Top; uint32_t headerLength; - _MBCSHeader header={ { 0, 0, 0, 0 }, 0, 0, 0, 0, 0, 0, 0 }; + _MBCSHeader header=UCNV_MBCS_HEADER_INITIALIZER; stage2Length=mbcsData->stage2Top; if(mbcsData->omitFromU) { diff --git a/tools/makeconv/makeconv.vcxproj b/tools/makeconv/makeconv.vcxproj index f2d8f336..751a248f 100644 --- a/tools/makeconv/makeconv.vcxproj +++ b/tools/makeconv/makeconv.vcxproj @@ -239,7 +239,7 @@ </ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="gencnvex.c" />
- <ClCompile Include="genmbcs.c" />
+ <ClCompile Include="genmbcs.cpp" />
<ClCompile Include="makeconv.c" />
<ClCompile Include="ucnvstat.c" />
</ItemGroup>
@@ -260,4 +260,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> +</Project>
diff --git a/tools/makeconv/makeconv.vcxproj.filters b/tools/makeconv/makeconv.vcxproj.filters index 5ec7b299..3f34f138 100644 --- a/tools/makeconv/makeconv.vcxproj.filters +++ b/tools/makeconv/makeconv.vcxproj.filters @@ -18,7 +18,7 @@ <ClCompile Include="gencnvex.c">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="genmbcs.c">
+ <ClCompile Include="genmbcs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="makeconv.c">
diff --git a/tools/pkgdata/Makefile.in b/tools/pkgdata/Makefile.in index 1fc6fa51..04fe636e 100644 --- a/tools/pkgdata/Makefile.in +++ b/tools/pkgdata/Makefile.in @@ -1,5 +1,5 @@ ## Makefile.in for ICU - tools/pkgdata -## Copyright (c) 1999-2009, International Business Machines Corporation and +## Copyright (c) 1999-2011, International Business Machines Corporation and ## others. All Rights Reserved. ## Steven R. Loomis @@ -30,9 +30,6 @@ endif ## Target information TARGET = $(BINDIR)/$(TARGET_STUB_NAME)$(EXEEXT) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(srcdir)/../toolutil DEFS += -DUDATA_SO_SUFFIX=\".$(SO)\" -DSTATIC_O=\"$(STATIC_O)\" LIBS = $(LIBICUTOOLUTIL) $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M) diff --git a/tools/pkgdata/pkgdata.cpp b/tools/pkgdata/pkgdata.cpp index 9bbbe7d4..5df235dc 100644 --- a/tools/pkgdata/pkgdata.cpp +++ b/tools/pkgdata/pkgdata.cpp @@ -1,8 +1,8 @@ /****************************************************************************** - * Copyright (C) 2000-2011, International Business Machines + * Copyright (C) 2000-2012, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* - * file name: pkgdata.c + * file name: pkgdata.cpp * encoding: ANSI X3.4 (1968) * tab size: 8 (not used) * indentation:4 @@ -14,29 +14,22 @@ * (DLL, common data, etc.) */ -/* - * We define _XOPEN_SOURCE so that we can get popen and pclose. - */ -#if !defined(_XOPEN_SOURCE) -#if __STDC_VERSION__ >= 199901L -/* It is invalid to compile an XPG3, XPG4, XPG4v2 or XPG5 application using c99 on Solaris */ -#define _XOPEN_SOURCE 600 -#else -#define _XOPEN_SOURCE 4 -#endif -#endif - +// Defines _XOPEN_SOURCE for access to POSIX functions. +// Must be before any other #includes. +#include "uposixdefs.h" #include "unicode/utypes.h" +#include "unicode/putil.h" +#include "putilimp.h" + #if U_HAVE_POPEN -#if (defined(U_CYGWIN) || defined(U_MINGW)) && defined(__STRICT_ANSI__) +#if (U_PF_MINGW <= U_PLATFORM || U_PLATFORM <= U_PF_CYGWIN) && defined(__STRICT_ANSI__) /* popen/pclose aren't defined in strict ANSI on Cygwin and MinGW */ #undef __STRICT_ANSI__ #endif #endif -#include "unicode/putil.h" #include "cmemory.h" #include "cstring.h" #include "filestrm.h" @@ -44,7 +37,6 @@ #include "unicode/uclean.h" #include "unewdata.h" #include "uoptions.h" -#include "putilimp.h" #include "package.h" #include "pkg_icu.h" #include "pkg_genc.h" @@ -52,10 +44,10 @@ #include "flagparser.h" #include "filetools.h" - #if U_HAVE_POPEN # include <unistd.h> #endif + #include <stdio.h> #include <stdlib.h> @@ -63,43 +55,6 @@ U_CDECL_BEGIN #include "pkgtypes.h" U_CDECL_END -#ifdef U_WINDOWS -#ifdef __GNUC__ -#define WINDOWS_WITH_GNUC -#else -#define WINDOWS_WITH_MSVC -#endif -#endif -#if !defined(WINDOWS_WITH_MSVC) && !defined(U_LINUX) -#define BUILD_DATA_WITHOUT_ASSEMBLY -#endif -#if defined(WINDOWS_WITH_MSVC) || defined(U_LINUX) -#define CAN_WRITE_OBJ_CODE -#endif -#if defined(U_CYGWIN) || defined(CYGWINMSVC) -#define USING_CYGWIN -#endif - -/* - * When building the data library without assembly, - * some platforms use a single c code file for all of - * the data to generate the final data library. This can - * increase the performance of the pkdata tool. - */ -#if defined(OS400) -#define USE_SINGLE_CCODE_FILE -#endif - -/* Need to fix the file seperator character when using MinGW. */ -#if defined(WINDOWS_WITH_GNUC) || defined(USING_CYGWIN) -#define PKGDATA_FILE_SEP_STRING "/" -#else -#define PKGDATA_FILE_SEP_STRING U_FILE_SEP_STRING -#endif - -#define LARGE_BUFFER_MAX_SIZE 2048 -#define SMALL_BUFFER_MAX_SIZE 512 -#define BUFFER_PADDING_SIZE 20 static void loadLists(UPKGOptions *o, UErrorCode *status); @@ -109,7 +64,7 @@ static int32_t pkg_executeOptions(UPKGOptions *o); static int32_t pkg_createWindowsDLL(const char mode, const char *gencFilePath, UPKGOptions *o); #endif static int32_t pkg_createSymLinks(const char *targetDir, UBool specialHandling=FALSE); -static int32_t pkg_installLibrary(const char *installDir, const char *dir); +static int32_t pkg_installLibrary(const char *installDir, const char *dir, UBool noVersion); static int32_t pkg_installFileMode(const char *installDir, const char *srcDir, const char *fileListName); static int32_t pkg_installCommonMode(const char *installDir, const char *fileName); @@ -120,12 +75,17 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD static int32_t pkg_createWithAssemblyCode(const char *targetDir, const char mode, const char *gencFilePath); static int32_t pkg_generateLibraryFile(const char *targetDir, const char mode, const char *objectFile, char *command = NULL); static int32_t pkg_archiveLibrary(const char *targetDir, const char *version, UBool reverseExt); -static void createFileNames(UPKGOptions *o, const char mode, const char *version_major, const char *version, const char *libName, const UBool reverseExt); +static void createFileNames(UPKGOptions *o, const char mode, const char *version_major, const char *version, const char *libName, const UBool reverseExt, UBool noVersion); static int32_t initializePkgDataFlags(UPKGOptions *o); static int32_t pkg_getOptionsFromICUConfig(UBool verbose, UOption *option); static int runCommand(const char* command, UBool specialHandling=FALSE); +#define IN_COMMON_MODE(mode) (mode == 'a' || mode == 'c') +#define IN_DLL_MODE(mode) (mode == 'd' || mode == 'l') +#define IN_STATIC_MODE(mode) (mode == 's') +#define IN_FILES_MODE(mode) (mode == 'f') + enum { NAME, BLDOPT, @@ -144,7 +104,9 @@ enum { REVISION, FORCE_PREFIX, LIBNAME, - QUIET + QUIET, + WITHOUT_ASSEMBLY, + PDS_BUILD }; /* This sets the modes that are available */ @@ -153,7 +115,7 @@ static struct { const char *desc; } modes[] = { { "files", 0, "Uses raw data files (no effect). Installation copies all files to the target location." }, -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API { "dll", "library", "Generates one common data file and one shared library, <package>.dll"}, { "common", "archive", "Generates just the common file, <package>.dat"}, { "static", "static", "Generates one statically linked library, " LIB_PREFIX "<package>" UDATA_LIB_SUFFIX } @@ -184,9 +146,12 @@ static UOption options[]={ /*16*/ UOPTION_DEF( "revision", 'r', UOPT_REQUIRES_ARG), /*17*/ UOPTION_DEF( "force-prefix", 'f', UOPT_NO_ARG), /*18*/ UOPTION_DEF( "libname", 'L', UOPT_REQUIRES_ARG), - /*19*/ UOPTION_DEF( "quiet", 'q', UOPT_NO_ARG) + /*19*/ UOPTION_DEF( "quiet", 'q', UOPT_NO_ARG), + /*20*/ UOPTION_DEF( "without-assembly", 'w', UOPT_NO_ARG), + /*21*/ UOPTION_DEF( "zos-pds-build", 'z', UOPT_NO_ARG) }; +/* This enum and the following char array should be kept in sync. */ enum { GENCCODE_ASSEMBLY_TYPE, SO_EXT, @@ -207,6 +172,25 @@ enum { INSTALL_CMD, PKGDATA_FLAGS_SIZE }; +static const char* FLAG_NAMES[PKGDATA_FLAGS_SIZE] = { + "GENCCODE_ASSEMBLY_TYPE", + "SO", + "SOBJ", + "A", + "LIBPREFIX", + "LIB_EXT_ORDER", + "COMPILE", + "LIBFLAGS", + "GENLIB", + "LDICUDTFLAGS", + "LD_SONAME", + "RPATH_FLAGS", + "BIR_LDFLAGS", + "AR", + "ARFLAGS", + "RANLIB", + "INSTALL_CMD" +}; static char **pkgDataFlags = NULL; enum { @@ -214,9 +198,11 @@ enum { LIB_FILE_VERSION_MAJOR, LIB_FILE_VERSION, LIB_FILE_VERSION_TMP, -#ifdef U_CYGWIN +#if U_PLATFORM == U_PF_CYGWIN LIB_FILE_CYGWIN, - LIB_FILE_CYGWIN_VERSION, + LIB_FILE_CYGWIN_VERSION, +#elif U_PLATFORM == U_PF_MINGW + LIB_FILE_MINGW, #endif LIB_FILENAMES_SIZE }; @@ -246,7 +232,8 @@ const char options_help[][320]={ "Specify a version when packaging in dll or static mode", "Add package to all file names if not present", "Library name to build (if different than package name)", - "Quite mode. (e.g. Do not output a readme file for static libraries)" + "Quite mode. (e.g. Do not output a readme file for static libraries)", + "Build the data without assembly code" }; const char *progname = "PKGDATA"; @@ -386,6 +373,12 @@ main(int argc, char* argv[]) { o.quiet = FALSE; } + if(options[PDS_BUILD].doesOccur) { + o.pdsbuild = TRUE; + } else { + o.pdsbuild = FALSE; + } + o.verbose = options[VERBOSE].doesOccur; @@ -434,6 +427,16 @@ main(int argc, char* argv[]) { o.entryName = o.cShortName; } + o.withoutAssembly = FALSE; + if (options[WITHOUT_ASSEMBLY].doesOccur) { +#ifndef BUILD_DATA_WITHOUT_ASSEMBLY + fprintf(stdout, "Warning: You are using the option to build without assembly code which is not supported on this platform.\n"); + fprintf(stdout, "Warning: This option will be ignored.\n"); +#else + o.withoutAssembly = TRUE; +#endif + } + /* OK options are set up. Now the file lists. */ tail = NULL; for( n=1; n<argc; n++) { @@ -484,30 +487,32 @@ static int runCommand(const char* command, UBool specialHandling) { } if (!specialHandling) { -#if defined(USING_CYGWIN) || defined(OS400) +#if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400 if ((len + BUFFER_PADDING_SIZE) >= SMALL_BUFFER_MAX_SIZE) { cmd = (char *)uprv_malloc(len + BUFFER_PADDING_SIZE); } else { cmd = cmdBuffer; } -#ifdef USING_CYGWIN +#if defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW sprintf(cmd, "bash -c \"%s\"", command); -#elif defined(OS400) +#elif U_PLATFORM == U_PF_OS400 sprintf(cmd, "QSH CMD('%s')", command); #endif #else goto normal_command_mode; #endif } else { +#if !(defined(USING_CYGWIN) || U_PLATFORM == U_PF_MINGW || U_PLATFORM == U_PF_OS400) normal_command_mode: +#endif cmd = (char *)command; } printf("pkgdata: %s\n", cmd); int result = system(cmd); if (result != 0) { - printf("-- return status = %d\n", result); + fprintf(stderr, "-- return status = %d\n", result); } if (cmd != cmdBuffer && cmd != command) { @@ -520,11 +525,6 @@ normal_command_mode: #define LN_CMD "ln -s" #define RM_CMD "rm -f" -#define MODE_COMMON 'c' -#define MODE_STATIC 's' -#define MODE_DLL 'd' -#define MODE_FILES 'f' - static int32_t pkg_executeOptions(UPKGOptions *o) { int32_t result = 0; @@ -537,7 +537,7 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { initializePkgDataFlags(o); - if (mode == MODE_FILES) { + if (IN_FILES_MODE(mode)) { /* Copy the raw data to the installation directory. */ if (o->install != NULL) { uprv_strcpy(targetDir, o->install); @@ -552,7 +552,9 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { result = pkg_installFileMode(targetDir, o->srcDir, o->fileListFiles->str); } return result; - } else /* if (mode == MODE_COMMON || mode == MODE_STATIC || mode == MODE_DLL) */ { + } else /* if (IN_COMMON_MODE(mode) || IN_DLL_MODE(mode) || IN_STATIC_MODE(mode)) */ { + UBool noVersion = FALSE; + uprv_strcpy(targetDir, o->targetDir); uprv_strcat(targetDir, PKGDATA_FILE_SEP_STRING); @@ -575,27 +577,35 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { return result; } - if (mode == MODE_COMMON) { + if (IN_COMMON_MODE(mode)) { char targetFileNamePath[LARGE_BUFFER_MAX_SIZE] = ""; uprv_strcpy(targetFileNamePath, targetDir); uprv_strcat(targetFileNamePath, datFileName); - if (T_FileStream_file_exists(targetFileNamePath)) { - if ((result = remove(targetFileNamePath)) != 0) { - fprintf(stderr, "Unable to remove old dat file: %s\n", targetFileNamePath); - return result; + /* Move the dat file created to the target directory. */ + if (uprv_strcmp(datFileNamePath, targetFileNamePath) != 0) { + if (T_FileStream_file_exists(targetFileNamePath)) { + if ((result = remove(targetFileNamePath)) != 0) { + fprintf(stderr, "Unable to remove old dat file: %s\n", + targetFileNamePath); + return result; + } } - } - /* Move the dat file created to the target directory. */ - result = rename(datFileNamePath, targetFileNamePath); + result = rename(datFileNamePath, targetFileNamePath); - if(o->verbose) { - fprintf(stdout, "# Moving package file to %s ..\n", targetFileNamePath); - } - if (result != 0) { - fprintf(stderr, "Unable to move dat file (%s) to target location (%s).\n", datFileNamePath, targetFileNamePath); + if (o->verbose) { + fprintf(stdout, "# Moving package file to %s ..\n", + targetFileNamePath); + } + if (result != 0) { + fprintf( + stderr, + "Unable to move dat file (%s) to target location (%s).\n", + datFileNamePath, targetFileNamePath); + return result; + } } if (o->install != NULL) { @@ -603,7 +613,7 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { } return result; - } else /* if (mode[0] == MODE_STATIC || mode[0] == MODE_DLL) */ { + } else /* if (IN_STATIC_MODE(mode) || IN_DLL_MODE(mode)) */ { char gencFilePath[SMALL_BUFFER_MAX_SIZE] = ""; char version_major[10] = ""; UBool reverseExt = FALSE; @@ -618,9 +628,14 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { } version_major[i] = o->version[i]; } + } else { + noVersion = TRUE; + if (IN_DLL_MODE(mode)) { + fprintf(stdout, "Warning: Providing a revision number with the -r option is recommended when packaging data in the current mode.\n"); + } } -#ifndef OS400 +#if U_PLATFORM != U_PF_OS400 /* Certain platforms have different library extension ordering. (e.g. libicudata.##.so vs libicudata.so.##) * reverseExt is FALSE if the suffix should be the version number. */ @@ -629,9 +644,9 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { } #endif /* Using the base libName and version number, generate the library file names. */ - createFileNames(o, mode, version_major, o->version, o->libName, reverseExt); + createFileNames(o, mode, version_major, o->version == NULL ? "" : o->version, o->libName, reverseExt, noVersion); - if ((o->version!=NULL || (mode==MODE_STATIC)) && o->rebuild == FALSE) { + if ((o->version!=NULL || IN_STATIC_MODE(mode)) && o->rebuild == FALSE) { /* Check to see if a previous built data library file exists and check if it is the latest. */ sprintf(checkLibFile, "%s%s", targetDir, libFileNames[LIB_FILE_VERSION]); if (T_FileStream_file_exists(checkLibFile)) { @@ -640,7 +655,7 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { if(o->verbose) { fprintf(stdout, "# Installing already-built library into %s\n", o->install); } - result = pkg_installLibrary(o->install, targetDir); + result = pkg_installLibrary(o->install, targetDir, noVersion); } else { if(o->verbose) { printf("# Not rebuilding %s - up to date.\n", checkLibFile); @@ -655,10 +670,13 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { } } - pkg_checkFlag(o); + if (pkg_checkFlag(o) == NULL) { + /* Error occurred. */ + return result; + } #endif - if (pkgDataFlags[GENCCODE_ASSEMBLY_TYPE][0] != 0) { + if (!o->withoutAssembly && pkgDataFlags[GENCCODE_ASSEMBLY_TYPE][0] != 0) { const char* genccodeAssembly = pkgDataFlags[GENCCODE_ASSEMBLY_TYPE]; if(o->verbose) { @@ -675,12 +693,12 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { if (result != 0) { fprintf(stderr, "Error generating assembly code for data.\n"); return result; - } else if (mode == MODE_STATIC) { + } else if (IN_STATIC_MODE(mode)) { if(o->install != NULL) { if(o->verbose) { fprintf(stdout, "# Installing static library into %s\n", o->install); } - result = pkg_installLibrary(o->install, targetDir); + result = pkg_installLibrary(o->install, targetDir, noVersion); } return result; } @@ -692,23 +710,36 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { if(o->verbose) { fprintf(stdout, "# Writing object code to %s ..\n", gencFilePath); } + if (o->withoutAssembly) { +#ifdef BUILD_DATA_WITHOUT_ASSEMBLY + result = pkg_createWithoutAssemblyCode(o, targetDir, mode); +#else + /* This error should not occur. */ + fprintf(stderr, "Error- BUILD_DATA_WITHOUT_ASSEMBLY is not defined. Internal error.\n"); +#endif + } else { #ifdef CAN_WRITE_OBJ_CODE - writeObjectCode(datFileNamePath, o->tmpDir, o->entryName, NULL, NULL, gencFilePath); -#ifdef U_LINUX - result = pkg_generateLibraryFile(targetDir, mode, gencFilePath); + writeObjectCode(datFileNamePath, o->tmpDir, o->entryName, NULL, NULL, gencFilePath); +#if U_PLATFORM_IS_LINUX_BASED + result = pkg_generateLibraryFile(targetDir, mode, gencFilePath); #elif defined(WINDOWS_WITH_MSVC) - result = pkg_createWindowsDLL(mode, gencFilePath, o); + result = pkg_createWindowsDLL(mode, gencFilePath, o); #endif #elif defined(BUILD_DATA_WITHOUT_ASSEMBLY) - result = pkg_createWithoutAssemblyCode(o, targetDir, mode); + result = pkg_createWithoutAssemblyCode(o, targetDir, mode); +#else + fprintf(stderr, "Error- neither CAN_WRITE_OBJ_CODE nor BUILD_DATA_WITHOUT_ASSEMBLY are defined. Internal error.\n"); + return 1; #endif + } + if (result != 0) { fprintf(stderr, "Error generating package data.\n"); return result; } } -#ifndef U_WINDOWS - if(mode != MODE_STATIC) { +#if !U_PLATFORM_USES_ONLY_WIN32_API + if(!IN_STATIC_MODE(mode)) { /* Certain platforms uses archive library. (e.g. AIX) */ if(o->verbose) { fprintf(stdout, "# Creating data archive library file ..\n"); @@ -718,24 +749,32 @@ static int32_t pkg_executeOptions(UPKGOptions *o) { fprintf(stderr, "Error creating data archive library file.\n"); return result; } -#ifndef OS400 - /* Create symbolic links for the final library file. */ - result = pkg_createSymLinks(targetDir); - if (result != 0) { - fprintf(stderr, "Error creating symbolic links of the data library file.\n"); - return result; +#if U_PLATFORM != U_PF_OS400 + if (!noVersion) { + /* Create symbolic links for the final library file. */ +#if U_PLATFORM == U_PF_OS390 + if (!o->pdsbuild) { + result = pkg_createSymLinks(targetDir, noVersion); + } +#else + result = pkg_createSymLinks(targetDir, noVersion); +#endif + if (result != 0) { + fprintf(stderr, "Error creating symbolic links of the data library file.\n"); + return result; + } } #endif - } /* !MODE_STATIC */ + } /* !IN_STATIC_MODE */ #endif -#if !defined(U_WINDOWS) || defined(USING_CYGWIN) +#if !U_PLATFORM_USES_ONLY_WIN32_API /* Install the libraries if option was set. */ if (o->install != NULL) { if(o->verbose) { fprintf(stdout, "# Installing library file to %s ..\n", o->install); } - result = pkg_installLibrary(o->install, targetDir); + result = pkg_installLibrary(o->install, targetDir, noVersion); if (result != 0) { fprintf(stderr, "Error installing the data library.\n"); return result; @@ -786,7 +825,7 @@ static int32_t initializePkgDataFlags(UPKGOptions *o) { fprintf(stdout, "# Reading options file %s\n", o->options); } status = U_ZERO_ERROR; - tmpResult = parseFlagsFile(o->options, pkgDataFlags, currentBufferSize, (int32_t)PKGDATA_FLAGS_SIZE, &status); + tmpResult = parseFlagsFile(o->options, pkgDataFlags, currentBufferSize, FLAG_NAMES, (int32_t)PKGDATA_FLAGS_SIZE, &status); if (status == U_BUFFER_OVERFLOW_ERROR) { for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) { uprv_free(pkgDataFlags[i]); @@ -798,9 +837,9 @@ static int32_t initializePkgDataFlags(UPKGOptions *o) { } #endif if(o->verbose) { - fprintf(stdout, "# pkgDataFlags="); - for(int32_t i=0;i<PKGDATA_FLAGS_SIZE && pkgDataFlags[i][0];i++) { - fprintf(stdout, "%c \"%s\"", (i>0)?',':' ',pkgDataFlags[i]); + fprintf(stdout, "# pkgDataFlags=\n"); + for(int32_t i=0;i<PKGDATA_FLAGS_SIZE;i++) { + fprintf(stdout, " [%d] %s: %s\n", i, FLAG_NAMES[i], pkgDataFlags[i]); } fprintf(stdout, "\n"); } @@ -816,39 +855,81 @@ static int32_t initializePkgDataFlags(UPKGOptions *o) { * Given the base libName and version numbers, generate the libary file names and store it in libFileNames. * Depending on the configuration, the library name may either end with version number or shared object suffix. */ -static void createFileNames(UPKGOptions *o, const char mode, const char *version_major, const char *version, const char *libName, UBool reverseExt) { +static void createFileNames(UPKGOptions *o, const char mode, const char *version_major, const char *version, const char *libName, UBool reverseExt, UBool noVersion) { +#if U_PLATFORM == U_PF_MINGW + /* MinGW does not need the library prefix when building in dll mode. */ + if (IN_DLL_MODE(mode)) { + sprintf(libFileNames[LIB_FILE], "%s", libName); + } else { + sprintf(libFileNames[LIB_FILE], "%s%s", + pkgDataFlags[LIBPREFIX], + libName); + } +#else sprintf(libFileNames[LIB_FILE], "%s%s", pkgDataFlags[LIBPREFIX], libName); +#endif if(o->verbose) { fprintf(stdout, "# libFileName[LIB_FILE] = %s\n", libFileNames[LIB_FILE]); } - if (version != NULL) { -#if defined(U_CYGWIN) - sprintf(libFileNames[LIB_FILE_CYGWIN], "cyg%s.%s", - libName, - pkgDataFlags[SO_EXT]); - sprintf(libFileNames[LIB_FILE_CYGWIN_VERSION], "cyg%s%s.%s", - libName, - version_major, - pkgDataFlags[SO_EXT]); - - uprv_strcat(pkgDataFlags[SO_EXT], "."); - uprv_strcat(pkgDataFlags[SO_EXT], pkgDataFlags[A_EXT]); - -#elif defined(OS400) || defined(_AIX) - sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s.%s", +#if U_PLATFORM == U_PF_MINGW + sprintf(libFileNames[LIB_FILE_MINGW], "%s%s.lib", pkgDataFlags[LIBPREFIX], libName); +#elif U_PLATFORM == U_PF_CYGWIN + sprintf(libFileNames[LIB_FILE_CYGWIN], "cyg%s.%s", + libName, + pkgDataFlags[SO_EXT]); + sprintf(libFileNames[LIB_FILE_CYGWIN_VERSION], "cyg%s%s.%s", + libName, + version_major, + pkgDataFlags[SO_EXT]); + + uprv_strcat(pkgDataFlags[SO_EXT], "."); + uprv_strcat(pkgDataFlags[SO_EXT], pkgDataFlags[A_EXT]); +#elif U_PLATFORM == U_PF_OS400 || defined(_AIX) + sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s.%s", + libFileNames[LIB_FILE], + pkgDataFlags[SOBJ_EXT]); +#elif U_PLATFROM == U_PF_OS390 + if (o->pdsbuild) { + sprintf(libFileNames[LIB_FILE], "%s", + libName); + sprintf(libFileNames[LIB_FILE_VERSION_TMP], "\"%s\"", + libFileNames[LIB_FILE]); + } else { + sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s%s%s.%s", + libFileNames[LIB_FILE], + pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", + reverseExt ? version : pkgDataFlags[SOBJ_EXT], + reverseExt ? pkgDataFlags[SOBJ_EXT] : version); + } +#else + if (noVersion && !reverseExt) { + sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s%s%s", libFileNames[LIB_FILE], + pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", pkgDataFlags[SOBJ_EXT]); -#else + } else { sprintf(libFileNames[LIB_FILE_VERSION_TMP], "%s%s%s.%s", libFileNames[LIB_FILE], pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", reverseExt ? version : pkgDataFlags[SOBJ_EXT], reverseExt ? pkgDataFlags[SOBJ_EXT] : version); + } #endif + if (noVersion && !reverseExt) { + sprintf(libFileNames[LIB_FILE_VERSION_MAJOR], "%s%s%s", + libFileNames[LIB_FILE], + pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", + pkgDataFlags[SO_EXT]); + + sprintf(libFileNames[LIB_FILE_VERSION], "%s%s%s", + libFileNames[LIB_FILE], + pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", + pkgDataFlags[SO_EXT]); + } else { sprintf(libFileNames[LIB_FILE_VERSION_MAJOR], "%s%s%s.%s", libFileNames[LIB_FILE], pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", @@ -860,17 +941,18 @@ static void createFileNames(UPKGOptions *o, const char mode, const char *version pkgDataFlags[LIB_EXT_ORDER][0] == '.' ? "." : "", reverseExt ? version : pkgDataFlags[SO_EXT], reverseExt ? pkgDataFlags[SO_EXT] : version); + } - if(o->verbose) { - fprintf(stdout, "# libFileName[LIB_FILE_VERSION] = %s\n", libFileNames[LIB_FILE_VERSION]); - } + if(o->verbose) { + fprintf(stdout, "# libFileName[LIB_FILE_VERSION] = %s\n", libFileNames[LIB_FILE_VERSION]); + } -#if defined(U_CYGWIN) || defined(U_MINGW) - /* Cygwin and MinGW only deals with the version major number. */ - uprv_strcpy(libFileNames[LIB_FILE_VERSION_TMP], libFileNames[LIB_FILE_VERSION_MAJOR]); +#if U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN + /* Cygwin and MinGW only deals with the version major number. */ + uprv_strcpy(libFileNames[LIB_FILE_VERSION_TMP], libFileNames[LIB_FILE_VERSION_MAJOR]); #endif - } - if(mode == MODE_STATIC) { + + if(IN_STATIC_MODE(mode)) { sprintf(libFileNames[LIB_FILE_VERSION], "%s.%s", libFileNames[LIB_FILE], pkgDataFlags[A_EXT]); libFileNames[LIB_FILE_VERSION_MAJOR][0]=0; if(o->verbose) { @@ -886,12 +968,7 @@ static int32_t pkg_createSymLinks(const char *targetDir, UBool specialHandling) char name1[SMALL_BUFFER_MAX_SIZE]; /* symlink file name */ char name2[SMALL_BUFFER_MAX_SIZE]; /* file name to symlink */ -#if defined (U_MINGW) - /* On MINGW, symbolic links don't need to be created. */ - return result; -#endif - -#ifndef USING_CYGWIN +#if !defined(USING_CYGWIN) && U_PLATFORM != U_PF_MINGW /* No symbolic link to make. */ if (uprv_strlen(libFileNames[LIB_FILE_VERSION]) == 0 || uprv_strlen(libFileNames[LIB_FILE_VERSION_MAJOR]) == 0 || uprv_strcmp(libFileNames[LIB_FILE_VERSION], libFileNames[LIB_FILE_VERSION_MAJOR]) == 0) { @@ -907,19 +984,22 @@ static int32_t pkg_createSymLinks(const char *targetDir, UBool specialHandling) libFileNames[LIB_FILE_VERSION_MAJOR]); result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error creating symbolic links. Failed command: %s\n", cmd); return result; } #endif if (specialHandling) { -#ifdef U_CYGWIN +#if U_PLATFORM == U_PF_CYGWIN sprintf(name1, "%s", libFileNames[LIB_FILE_CYGWIN]); sprintf(name2, "%s", libFileNames[LIB_FILE_CYGWIN_VERSION]); #else goto normal_symlink_mode; #endif } else { +#if U_PLATFORM != U_PF_CYGWIN normal_symlink_mode: +#endif sprintf(name1, "%s.%s", libFileNames[LIB_FILE], pkgDataFlags[SO_EXT]); sprintf(name2, "%s", libFileNames[LIB_FILE_VERSION]); } @@ -937,7 +1017,7 @@ normal_symlink_mode: return result; } -static int32_t pkg_installLibrary(const char *installDir, const char *targetDir) { +static int32_t pkg_installLibrary(const char *installDir, const char *targetDir, UBool noVersion) { int32_t result = 0; char cmd[SMALL_BUFFER_MAX_SIZE]; @@ -951,6 +1031,7 @@ static int32_t pkg_installLibrary(const char *installDir, const char *targetDir) result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error installing library. Failed command: %s\n", cmd); return result; } @@ -964,9 +1045,10 @@ static int32_t pkg_installLibrary(const char *installDir, const char *targetDir) result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error installing library. Failed command: %s\n", cmd); return result; } -#elif defined(U_CYGWIN) +#elif U_PLATFORM == U_PF_CYGWIN sprintf(cmd, "cd %s && %s %s %s", targetDir, pkgDataFlags[INSTALL_CMD], @@ -976,11 +1058,16 @@ static int32_t pkg_installLibrary(const char *installDir, const char *targetDir) result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error installing library. Failed command: %s\n", cmd); return result; } #endif - return pkg_createSymLinks(installDir, TRUE); + if (noVersion) { + return result; + } else { + return pkg_createSymLinks(installDir, TRUE); + } } static int32_t pkg_installCommonMode(const char *installDir, const char *fileName) { @@ -1099,6 +1186,7 @@ static int32_t pkg_archiveLibrary(const char *targetDir, const char *version, UB result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error creating archive library. Failed command: %s\n", cmd); return result; } @@ -1109,6 +1197,7 @@ static int32_t pkg_archiveLibrary(const char *targetDir, const char *version, UB result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error creating archive library. Failed command: %s\n", cmd); return result; } @@ -1120,6 +1209,7 @@ static int32_t pkg_archiveLibrary(const char *targetDir, const char *version, UB result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error creating archive library. Failed command: %s\n", cmd); return result; } @@ -1148,7 +1238,7 @@ static int32_t pkg_generateLibraryFile(const char *targetDir, const char mode, c cmd = command; } - if (mode == MODE_STATIC) { + if (IN_STATIC_MODE(mode)) { if (cmd == NULL) { length = uprv_strlen(pkgDataFlags[AR]) + uprv_strlen(pkgDataFlags[ARFLAGS]) + uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_VERSION]) + uprv_strlen(objectFile) + uprv_strlen(pkgDataFlags[RANLIB]) + BUFFER_PADDING_SIZE; @@ -1174,15 +1264,17 @@ static int32_t pkg_generateLibraryFile(const char *targetDir, const char mode, c result = runCommand(cmd); } - } else /* if (mode == MODE_DLL) */ { + } else /* if (IN_DLL_MODE(mode)) */ { if (cmd == NULL) { length = uprv_strlen(pkgDataFlags[GENLIB]) + uprv_strlen(pkgDataFlags[LDICUDTFLAGS]) + - uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_VERSION_TMP]) + + ((uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_VERSION_TMP])) * 2) + uprv_strlen(objectFile) + uprv_strlen(pkgDataFlags[LD_SONAME]) + uprv_strlen(pkgDataFlags[LD_SONAME][0] == 0 ? "" : libFileNames[LIB_FILE_VERSION_MAJOR]) + uprv_strlen(pkgDataFlags[RPATH_FLAGS]) + uprv_strlen(pkgDataFlags[BIR_FLAGS]) + BUFFER_PADDING_SIZE; -#ifdef U_CYGWIN +#if U_PLATFORM == U_PF_CYGWIN length += uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_CYGWIN_VERSION]); +#elif U_PLATFORM == U_PF_MINGW + length += uprv_strlen(targetDir) + uprv_strlen(libFileNames[LIB_FILE_MINGW]); #endif if ((cmd = (char *)uprv_malloc(sizeof(char) * length)) == NULL) { fprintf(stderr, "Unable to allocate memory for command.\n"); @@ -1190,13 +1282,31 @@ static int32_t pkg_generateLibraryFile(const char *targetDir, const char mode, c } freeCmd = TRUE; } -#if defined(U_CYGWIN) +#if U_PLATFORM == U_PF_MINGW + sprintf(cmd, "%s%s%s %s -o %s%s %s %s%s %s %s", + pkgDataFlags[GENLIB], + targetDir, + libFileNames[LIB_FILE_MINGW], + pkgDataFlags[LDICUDTFLAGS], + targetDir, + libFileNames[LIB_FILE_VERSION_TMP], +#elif U_PLATFORM == U_PF_CYGWIN sprintf(cmd, "%s%s%s %s -o %s%s %s %s%s %s %s", pkgDataFlags[GENLIB], targetDir, libFileNames[LIB_FILE_VERSION_TMP], pkgDataFlags[LDICUDTFLAGS], - targetDir, libFileNames[LIB_FILE_CYGWIN_VERSION], + targetDir, + libFileNames[LIB_FILE_CYGWIN_VERSION], +#elif U_PLATFORM == U_PF_AIX + sprintf(cmd, "%s %s%s;%s %s -o %s%s %s %s%s %s %s", + RM_CMD, + targetDir, + libFileNames[LIB_FILE_VERSION_TMP], + pkgDataFlags[GENLIB], + pkgDataFlags[LDICUDTFLAGS], + targetDir, + libFileNames[LIB_FILE_VERSION_TMP], #else sprintf(cmd, "%s %s -o %s%s %s %s%s %s %s", pkgDataFlags[GENLIB], @@ -1214,6 +1324,10 @@ static int32_t pkg_generateLibraryFile(const char *targetDir, const char mode, c result = runCommand(cmd); } + if (result != 0) { + fprintf(stderr, "Error generating library file. Failed command: %s\n", cmd); + } + if (freeCmd) { uprv_free(cmd); } @@ -1250,6 +1364,7 @@ static int32_t pkg_createWithAssemblyCode(const char *targetDir, const char mode result = runCommand(cmd); uprv_free(cmd); if (result != 0) { + fprintf(stderr, "Error creating with assembly code. Failed command: %s\n", cmd); return result; } @@ -1296,6 +1411,7 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD char tempObjectFile[SMALL_BUFFER_MAX_SIZE] = ""; #ifdef USE_SINGLE_CCODE_FILE char icudtAll[SMALL_BUFFER_MAX_SIZE] = ""; + FileStream *icudtAllFile = NULL; sprintf(icudtAll, "%s%s%sall.c", o->tmpDir, @@ -1306,6 +1422,11 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD fprintf(stderr, "Unable to remove old icudtall file: %s\n", icudtAll); return result; } + + if((icudtAllFile = T_FileStream_open(icudtAll, "w"))==NULL) { + fprintf(stderr, "Unable to write to icudtall file: %s\n", icudtAll); + return result; + } #endif if (list == NULL || listNames == NULL) { @@ -1388,20 +1509,16 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD } } + if(o->verbose) { + printf("# Generating %s \n", gencmnFile); + } + writeCCode(file, o->tmpDir, dataName[0] != 0 ? dataName : o->shortName, newName[0] != 0 ? newName : NULL, gencmnFile); + #ifdef USE_SINGLE_CCODE_FILE - sprintf(cmd, "cat %s >> %s", gencmnFile, icudtAll); - - result = runCommand(cmd); - if (result != 0) { - break; - } else { - /* Remove the c code file after concatenating it to icudtall.c file. */ - if ((result = remove(gencmnFile)) != 0) { - fprintf(stderr, "Unable to remove c code file: %s\n", gencmnFile); - return result; - } - } + sprintf(cmd, "#include \"%s\"\n", gencmnFile); + T_FileStream_writeLine(icudtAllFile, cmd); + /* don't delete the file */ #endif } @@ -1416,6 +1533,7 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD gencmnFile); result = runCommand(cmd); if (result != 0) { + fprintf(stderr, "Error creating library without assembly code. Failed command: %s\n", cmd); break; } @@ -1431,10 +1549,11 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD } #ifdef USE_SINGLE_CCODE_FILE + T_FileStream_close(icudtAllFile); uprv_strcpy(tempObjectFile, icudtAll); tempObjectFile[uprv_strlen(tempObjectFile) - 1] = 'o'; - sprintf(cmd, "%s %s -o %s %s", + sprintf(cmd, "%s %s -I. -o %s %s", pkgDataFlags[COMPILER], pkgDataFlags[LIBFLAGS], tempObjectFile, @@ -1444,12 +1563,22 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD if (result == 0) { uprv_strcat(buffer, " "); uprv_strcat(buffer, tempObjectFile); + } else { + fprintf(stderr, "Error creating library without assembly code. Failed command: %s\n", cmd); } #endif if (result == 0) { /* Generate the library file. */ - result = pkg_generateLibraryFile(targetDir, mode, buffer, cmd); +#if U_PLATFORM == U_PF_OS390 + if (o->pdsbuild && IN_DLL_MODE(mode)) { + result = pkg_generateLibraryFile("",mode, buffer, cmd); + } else { + result = pkg_generateLibraryFile(targetDir,mode, buffer, cmd); + } +#else + result = pkg_generateLibraryFile(targetDir,mode, buffer, cmd); +#endif } uprv_free(buffer); @@ -1468,21 +1597,32 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD #define DLL_EXT UDATA_SO_SUFFIX static int32_t pkg_createWindowsDLL(const char mode, const char *gencFilePath, UPKGOptions *o) { + int32_t result = 0; char cmd[LARGE_BUFFER_MAX_SIZE]; - if (mode == MODE_STATIC) { + if (IN_STATIC_MODE(mode)) { char staticLibFilePath[SMALL_BUFFER_MAX_SIZE] = ""; - uprv_strcpy(staticLibFilePath, o->tmpDir); - uprv_strcat(staticLibFilePath, PKGDATA_FILE_SEP_STRING); - - uprv_strcat(staticLibFilePath, o->entryName); - uprv_strcat(staticLibFilePath, LIB_EXT); +#ifdef CYGWINMSVC + sprintf(staticLibFilePath, "%s%s%s%s%s", + o->targetDir, + PKGDATA_FILE_SEP_STRING, + pkgDataFlags[LIBPREFIX], + o->libName, + LIB_EXT); +#else + sprintf(staticLibFilePath, "%s%s%s%s%s", + o->targetDir, + PKGDATA_FILE_SEP_STRING, + (strstr(o->libName, "icudt") ? "s" : ""), + o->libName, + LIB_EXT); +#endif sprintf(cmd, "%s\"%s\" \"%s\"", LIB_CMD, staticLibFilePath, gencFilePath); - } else if (mode == MODE_DLL) { + } else if (IN_DLL_MODE(mode)) { char dllFilePath[SMALL_BUFFER_MAX_SIZE] = ""; char libFilePath[SMALL_BUFFER_MAX_SIZE] = ""; char resFilePath[SMALL_BUFFER_MAX_SIZE] = ""; @@ -1540,12 +1680,17 @@ static int32_t pkg_createWindowsDLL(const char mode, const char *gencFilePath, U ); } - return runCommand(cmd, TRUE); + result = runCommand(cmd, TRUE); + if (result != 0) { + fprintf(stderr, "Error creating Windows DLL library. Failed command: %s\n", cmd); + } + + return result; } #endif static UPKGOptions *pkg_checkFlag(UPKGOptions *o) { -#ifdef U_AIX +#if U_PLATFORM == U_PF_AIX /* AIX needs a map file. */ char *flag = NULL; int32_t length = 0; @@ -1554,7 +1699,39 @@ static UPKGOptions *pkg_checkFlag(UPKGOptions *o) { FileStream *f = NULL; char mapFile[SMALL_BUFFER_MAX_SIZE] = ""; int32_t start = -1; - int32_t count = 0; + uint32_t count = 0; + const char rm_cmd[] = "rm -f all ;"; + + flag = pkgDataFlags[GENLIB]; + + /* This portion of the code removes 'rm -f all' in the GENLIB. + * Only occurs in AIX. + */ + if (uprv_strstr(flag, rm_cmd) != NULL) { + char *tmpGenlibFlagBuffer = NULL; + int32_t i, offset; + + length = uprv_strlen(flag) + 1; + tmpGenlibFlagBuffer = (char *)uprv_malloc(length); + if (tmpGenlibFlagBuffer == NULL) { + /* Memory allocation error */ + fprintf(stderr,"Unable to allocate buffer of size: %d.\n", length); + return NULL; + } + + uprv_strcpy(tmpGenlibFlagBuffer, flag); + + offset = uprv_strlen(rm_cmd); + + for (i = 0; i < (length - offset); i++) { + flag[i] = tmpGenlibFlagBuffer[offset + i]; + } + + /* Zero terminate the string */ + flag[i] = 0; + + uprv_free(tmpGenlibFlagBuffer); + } flag = pkgDataFlags[BIR_FLAGS]; length = uprv_strlen(pkgDataFlags[BIR_FLAGS]); @@ -1602,6 +1779,7 @@ static UPKGOptions *pkg_checkFlag(UPKGOptions *o) { f = T_FileStream_open(mapFile, "w"); if (f == NULL) { fprintf(stderr,"Unable to create map file: %s.\n", mapFile); + return NULL; } else { sprintf(tmpbuffer, "%s%s ", o->entryName, UDATA_CMN_INTERMEDIATE_SUFFIX); @@ -1610,7 +1788,7 @@ static UPKGOptions *pkg_checkFlag(UPKGOptions *o) { T_FileStream_close(f); } } -#elif defined(U_CYGWIN) +#elif U_PLATFORM == U_PF_CYGWIN || U_PLATFORM == U_PF_MINGW /* Cygwin needs to change flag options. */ char *flag = NULL; int32_t length = 0; @@ -1628,8 +1806,8 @@ static UPKGOptions *pkg_checkFlag(UPKGOptions *o) { } uprv_memset(flag + position, 0, length - position); -#elif defined(OS400) - /* OS400 needs to fix the ld options (swap single quote with double quote) */ +#elif U_PLATFORM == U_PF_OS400 + /* OS/400 needs to fix the ld options (swap single quote with double quote) */ char *flag = NULL; int32_t length = 0; @@ -1738,7 +1916,7 @@ static void loadLists(UPKGOptions *o, UErrorCode *status) /* normal mode.. o->files is just the bare list without package names */ o->files = pkg_appendToList(o->files, &tail, uprv_strdup(linePtr)); - if(uprv_pathIsAbsolute(s)) { + if(uprv_pathIsAbsolute(s) || s[0] == '.') { fprintf(stderr, "pkgdata: Error: absolute path encountered. Old style paths are not supported. Use relative paths such as 'fur.res' or 'translit%cfur.res'.\n\tBad path: '%s'\n", U_FILE_SEP_CHAR, s); exit(U_ILLEGAL_ARGUMENT_ERROR); } @@ -1772,7 +1950,9 @@ static void loadLists(UPKGOptions *o, UErrorCode *status) /* #1 try the same path where pkgdata was called from. */ findDirname(progname, cmdBuf, 1024, &status); if(U_SUCCESS(status)) { - uprv_strncat(cmdBuf, U_FILE_SEP_STRING, 1024); + if (cmdBuf[0] != 0) { + uprv_strncat(cmdBuf, U_FILE_SEP_STRING, 1024); + } uprv_strncat(cmdBuf, cmd, 1024); if(verbose) { diff --git a/tools/pkgdata/pkgtypes.c b/tools/pkgdata/pkgtypes.c index 7b71054c..2769e453 100644 --- a/tools/pkgdata/pkgtypes.c +++ b/tools/pkgdata/pkgtypes.c @@ -1,6 +1,6 @@ /************************************************************************** * -* Copyright (C) 2000-2008, International Business Machines +* Copyright (C) 2000-2011, International Business Machines * Corporation and others. All Rights Reserved. * *************************************************************************** @@ -22,7 +22,7 @@ #include "cmemory.h" #include "cstring.h" #include "pkgtypes.h" - +#include "putilimp.h" const char *pkg_writeCharListWrap(FileStream *s, CharList *l, const char *delim, const char *brk, int32_t quote) { diff --git a/tools/pkgdata/pkgtypes.h b/tools/pkgdata/pkgtypes.h index 2f47239d..0bba60c5 100644 --- a/tools/pkgdata/pkgtypes.h +++ b/tools/pkgdata/pkgtypes.h @@ -1,6 +1,6 @@ /************************************************************************** * -* Copyright (C) 2000-2009, International Business Machines +* Copyright (C) 2000-2012, International Business Machines * Corporation and others. All Rights Reserved. * *************************************************************************** @@ -125,6 +125,8 @@ typedef struct UPKGOptions_ UBool rebuild; UBool verbose; UBool quiet; + UBool withoutAssembly; + UBool pdsbuild; /* for building PDS in z/OS */ } UPKGOptions; char * convertToNativePathSeparators(char *path); @@ -132,7 +134,7 @@ char * convertToNativePathSeparators(char *path); /* set up common defines for library naming */ -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API # ifndef UDATA_SO_SUFFIX # define UDATA_SO_SUFFIX ".dll" # endif @@ -141,7 +143,7 @@ char * convertToNativePathSeparators(char *path); # define OBJ_SUFFIX ".obj" # define UDATA_LIB_SUFFIX ".lib" -#elif defined(U_CYGWIN) +#elif U_PLATFORM == U_PF_CYGWIN # define LIB_PREFIX "cyg" # define LIB_STATIC_PREFIX "lib" # define OBJ_SUFFIX ".o" diff --git a/tools/toolutil/Makefile.in b/tools/toolutil/Makefile.in index 02ab0e8e..ffec2b4d 100644 --- a/tools/toolutil/Makefile.in +++ b/tools/toolutil/Makefile.in @@ -43,10 +43,12 @@ DYNAMICCXXFLAGS = $(SHAREDLIBCXXFLAGS) CFLAGS += $(LIBCFLAGS) CXXFLAGS += $(LIBCXXFLAGS) -ifneq ($(top_builddir),$(top_srcdir)) -CPPFLAGS += -I$(top_builddir)/common -endif CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n $(LIBCPPFLAGS) + +# from icuinfo +CPPFLAGS+= "-DU_BUILD=\"@build@\"" "-DU_HOST=\"@host@\"" "-DU_CC=\"@CC@\"" "-DU_CXX=\"@CXX@\"" + + DEFS += -DU_TOOLUTIL_IMPLEMENTATION LDFLAGS += $(LDFLAGSICUTOOLUTIL) LIBS = $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS) @@ -55,7 +57,7 @@ OBJECTS = filestrm.o package.o pkgitems.o swapimpl.o toolutil.o unewdata.o \ denseranges.o \ ucm.o ucmstate.o uoptions.o uparse.o \ ucbuf.o xmlparser.o writesrc.o \ -pkg_icu.o pkg_genc.o pkg_gencmn.o flagparser.o filetools.o \ +pkg_icu.o pkg_genc.o pkg_gencmn.o ppucd.o flagparser.o filetools.o \ udbgutil.o dbgutil.o ucln_tu.o STATIC_OBJECTS = $(OBJECTS:.o=.$(STATIC_O)) @@ -132,6 +134,11 @@ endif ifneq ($(ENABLE_SHARED),) $(SHARED_OBJECT): $(OBJECTS) $(SHLIB.cc) $(LD_SONAME) $(OUTOPT)$@ $^ $(LIBS) +ifeq ($(ENABLE_RPATH),YES) +ifneq ($(wildcard $(libdir)/$(MIDDLE_SO_TARGET)),) + $(warning RPATH warning: --enable-rpath means test programs may use existing $(libdir)/$(MIDDLE_SO_TARGET)) +endif +endif endif ifeq (,$(MAKECMDGOALS)) diff --git a/tools/toolutil/dbgutil.h b/tools/toolutil/dbgutil.h index be2ad992..9e5b6c88 100644 --- a/tools/toolutil/dbgutil.h +++ b/tools/toolutil/dbgutil.h @@ -1,7 +1,7 @@ /* ************************************************************************ -* Copyright (c) 2007-2010, International Business Machines +* Copyright (c) 2007-2011, International Business Machines * Corporation and others. All Rights Reserved. ************************************************************************ */ @@ -17,26 +17,26 @@ #if !UCONFIG_NO_FORMATTING -U_CAPI const U_NAMESPACE_QUALIFIER UnicodeString& U_EXPORT2 +U_CAPI const icu::UnicodeString& U_EXPORT2 udbg_enumString(UDebugEnumType type, int32_t field); /** * @return enum offset, or UDBG_INVALID_ENUM on error */ U_CAPI int32_t U_EXPORT2 -udbg_enumByString(UDebugEnumType type, const U_NAMESPACE_QUALIFIER UnicodeString& string); +udbg_enumByString(UDebugEnumType type, const icu::UnicodeString& string); /** * Convert a UnicodeString (with ascii digits) into a number. * @param s string * @return numerical value, or 0 on error */ -U_CAPI int32_t U_EXPORT2 udbg_stoi(const U_NAMESPACE_QUALIFIER UnicodeString &s); +U_CAPI int32_t U_EXPORT2 udbg_stoi(const icu::UnicodeString &s); -U_CAPI double U_EXPORT2 udbg_stod(const U_NAMESPACE_QUALIFIER UnicodeString &s); +U_CAPI double U_EXPORT2 udbg_stod(const icu::UnicodeString &s); -U_CAPI U_NAMESPACE_QUALIFIER UnicodeString * U_EXPORT2 -udbg_escape(const U_NAMESPACE_QUALIFIER UnicodeString &s, U_NAMESPACE_QUALIFIER UnicodeString *dst); +U_CAPI icu::UnicodeString * U_EXPORT2 +udbg_escape(const icu::UnicodeString &s, icu::UnicodeString *dst); #endif diff --git a/tools/toolutil/filestrm.c b/tools/toolutil/filestrm.c index bf646916..7309747c 100644 --- a/tools/toolutil/filestrm.c +++ b/tools/toolutil/filestrm.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 1997-2005, International Business Machines +* Copyright (C) 1997-2011, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -43,7 +43,7 @@ U_CAPI FileStream* U_EXPORT2 T_FileStream_wopen(const wchar_t* filename, const wchar_t* mode) { // TBD: _wfopen is believed to be MS-specific? -#if defined(U_WINDOWS) +#if U_PLATFORM_USES_ONLY_WIN32_API FILE* result = _wfopen(filename, mode); return (FileStream*)result; #else diff --git a/tools/toolutil/filetools.cpp b/tools/toolutil/filetools.cpp index 058a6f7c..7f560f6c 100644 --- a/tools/toolutil/filetools.cpp +++ b/tools/toolutil/filetools.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2009, International Business Machines + * Copyright (C) 2009-2011, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ @@ -8,6 +8,7 @@ #include "filestrm.h" #include "cstring.h" #include "unicode/putil.h" +#include "putilimp.h" #include <stdio.h> #include <stdlib.h> diff --git a/tools/toolutil/flagparser.c b/tools/toolutil/flagparser.c index 41ec9c9c..318cfd97 100644 --- a/tools/toolutil/flagparser.c +++ b/tools/toolutil/flagparser.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2009-2010, International Business Machines + * Copyright (C) 2009-2011, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ @@ -13,17 +13,18 @@ static int32_t currentBufferSize = DEFAULT_BUFFER_SIZE; -static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, UErrorCode *status); +static int32_t extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status); static int32_t getFlagOffset(const char *buffer, int32_t bufferSize); /* * Opens the given fileName and reads in the information storing the data in flagBuffer. */ U_CAPI int32_t U_EXPORT2 -parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, int32_t numOfFlags, UErrorCode *status) { +parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status) { char* buffer = uprv_malloc(sizeof(char) * currentBufferSize); + char* tmpFlagBuffer = uprv_malloc(sizeof(char) * flagBufferSize); UBool allocateMoreSpace = FALSE; - int32_t i; + int32_t index, i; int32_t result = 0; FileStream *f = T_FileStream_open(fileName, "r"); @@ -44,15 +45,19 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, uprv_free(buffer); buffer = uprv_malloc(sizeof(char) * currentBufferSize); if (buffer == NULL) { + uprv_free(tmpFlagBuffer); *status = U_MEMORY_ALLOCATION_ERROR; return -1; } } - for (i = 0; i < numOfFlags; i++) { + for (i = 0; i < numOfFlags;) { if (T_FileStream_readLine(f, buffer, currentBufferSize) == NULL) { - *status = U_FILE_ACCESS_ERROR; + /* End of file reached. */ break; } + if (buffer[0] == '#') { + continue; + } if (uprv_strlen(buffer) == (currentBufferSize - 1) && buffer[currentBufferSize-2] != '\n') { /* Allocate more space for buffer if it didnot read the entrire line */ @@ -60,7 +65,7 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, T_FileStream_rewind(f); break; } else { - extractFlag(buffer, currentBufferSize, flagBuffer[i], flagBufferSize, status); + index = extractFlag(buffer, currentBufferSize, tmpFlagBuffer, flagBufferSize, flagNames, numOfFlags, status); if (U_FAILURE(*status)) { if (*status == U_BUFFER_OVERFLOW_ERROR) { result = currentBufferSize; @@ -68,11 +73,23 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, result = -1; } break; + } else { + if (flagNames != NULL) { + if (index >= 0) { + uprv_strcpy(flagBuffer[index], tmpFlagBuffer); + } else { + /* No match found. Skip it. */ + continue; + } + } else { + uprv_strcpy(flagBuffer[i++], tmpFlagBuffer); + } } } } } while (allocateMoreSpace && U_SUCCESS(*status)); + uprv_free(tmpFlagBuffer); uprv_free(buffer); T_FileStream_close(f); @@ -88,10 +105,10 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, /* * Extract the setting after the '=' and store it in flag excluding the newline character. */ -static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, UErrorCode *status) { - int32_t i; +static int32_t extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, const char **flagNames, int32_t numOfFlags, UErrorCode *status) { + int32_t i, index = -1; char *pBuffer; - int32_t offset; + int32_t offset=0; UBool bufferWritten = FALSE; if (buffer[0] != 0) { @@ -101,7 +118,7 @@ static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t fl for(i = 0;;i++) { if (i >= flagSize) { *status = U_BUFFER_OVERFLOW_ERROR; - return; + return -1; } if (pBuffer[i+1] == 0) { /* Indicates a new line character. End here. */ @@ -119,6 +136,18 @@ static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t fl if (!bufferWritten) { flag[0] = 0; } + + if (flagNames != NULL && offset>0) { + offset--; /* Move offset back 1 because of '='*/ + for (i = 0; i < numOfFlags; i++) { + if (uprv_strncmp(buffer, flagNames[i], offset) == 0) { + index = i; + break; + } + } + } + + return index; } /* diff --git a/tools/toolutil/flagparser.h b/tools/toolutil/flagparser.h index 64056ed7..32a51e3d 100644 --- a/tools/toolutil/flagparser.h +++ b/tools/toolutil/flagparser.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2009-2010, International Business Machines +* Copyright (C) 2009-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -25,6 +25,6 @@ #include "unicode/utypes.h" U_CAPI int32_t U_EXPORT2 -parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, int32_t numOfFlags, UErrorCode *status); +parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status); #endif diff --git a/tools/toolutil/package.cpp b/tools/toolutil/package.cpp index d289703c..a6ed2468 100644 --- a/tools/toolutil/package.cpp +++ b/tools/toolutil/package.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2011, International Business Machines +* Copyright (C) 1999-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -1236,7 +1236,7 @@ void Package::setItemCapacity(int32_t max) Item *newItems = (Item*)uprv_malloc(max * sizeof(items[0])); Item *oldItems = items; if(newItems == NULL) { - fprintf(stderr, "icupkg: Out of memory trying to allocate %ld bytes for %d items\n", max*sizeof(items[0]), max); + fprintf(stderr, "icupkg: Out of memory trying to allocate %lu bytes for %d items\n", max*sizeof(items[0]), max); exit(U_MEMORY_ALLOCATION_ERROR); } if(items && itemCount>0) { diff --git a/tools/toolutil/pkg_genc.c b/tools/toolutil/pkg_genc.c index 931a4418..57c6f619 100644 --- a/tools/toolutil/pkg_genc.c +++ b/tools/toolutil/pkg_genc.c @@ -1,11 +1,11 @@ /****************************************************************************** - * Copyright (C) 2009-2010, International Business Machines + * Copyright (C) 2009-2011, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ #include "unicode/utypes.h" -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN # define NOUSER @@ -19,7 +19,7 @@ # endif #endif -#ifdef U_LINUX +#if U_PLATFORM_IS_LINUX_BASED # define U_ELF #endif @@ -51,9 +51,6 @@ #define HEX_0X 0 /* 0x1234 */ #define HEX_0H 1 /* 01234h */ -#if defined(U_WINDOWS) || defined(U_ELF) -#define CAN_GENERATE_OBJECTS -#endif /* prototypes --------------------------------------------------------------- */ static void @@ -65,7 +62,7 @@ write8(FileStream *out, uint8_t byte, uint32_t column); static uint32_t write32(FileStream *out, uint32_t byte, uint32_t column); -#ifdef OS400 +#if U_PLATFORM == U_PF_OS400 static uint32_t write8str(FileStream *out, uint8_t byte, uint32_t column); #endif @@ -359,7 +356,7 @@ writeCCode(const char *filename, const char *destdir, const char *optName, const } } -#ifdef OS400 +#if U_PLATFORM == U_PF_OS400 /* TODO: Fix this once the compiler implements this feature. Keep in sync with udatamem.c @@ -373,8 +370,11 @@ writeCCode(const char *filename, const char *destdir, const char *optName, const [grhoten 4/24/2003] */ sprintf(buffer, + "#ifndef IN_GENERATED_CCODE\n" + "#define IN_GENERATED_CCODE\n" "#define U_DISABLE_RENAMING 1\n" "#include \"unicode/umachine.h\"\n" + "#endif\n" "U_CDECL_BEGIN\n" "const struct {\n" " double bogus;\n" @@ -397,8 +397,11 @@ writeCCode(const char *filename, const char *destdir, const char *optName, const #else /* Function renaming shouldn't be done in data */ sprintf(buffer, + "#ifndef IN_GENERATED_CCODE\n" + "#define IN_GENERATED_CCODE\n" "#define U_DISABLE_RENAMING 1\n" "#include \"unicode/umachine.h\"\n" + "#endif\n" "U_CDECL_BEGIN\n" "const struct {\n" " double bogus;\n" @@ -531,7 +534,7 @@ write8(FileStream *out, uint8_t byte, uint32_t column) { return column; } -#ifdef OS400 +#if U_PLATFORM == U_PF_OS400 static uint32_t write8str(FileStream *out, uint8_t byte, uint32_t column) { char s[8]; @@ -628,7 +631,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char #ifdef U_ELF Elf32_Ehdr header32; /* Elf32_Ehdr and ELF64_Ehdr are identical for the necessary fields. */ -#elif defined(U_WINDOWS) +#elif U_PLATFORM_HAS_WIN32_API IMAGE_FILE_HEADER header; #endif } buffer; @@ -639,7 +642,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char #ifdef U_ELF -#elif defined(U_WINDOWS) +#elif U_PLATFORM_HAS_WIN32_API const IMAGE_FILE_HEADER *pHeader; #else # error "Unknown platform for CAN_GENERATE_OBJECTS." @@ -654,7 +657,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char *pCPU=EM_386; *pBits=32; *pIsBigEndian=(UBool)(U_IS_BIG_ENDIAN ? ELFDATA2MSB : ELFDATA2LSB); -#elif defined(U_WINDOWS) +#elif U_PLATFORM_HAS_WIN32_API /* _M_IA64 should be defined in windows.h */ # if defined(_M_IA64) *pCPU=IMAGE_FILE_MACHINE_IA64; @@ -715,7 +718,7 @@ getArchitecture(uint16_t *pCPU, uint16_t *pBits, UBool *pIsBigEndian, const char /* TODO: Support byte swapping */ *pCPU=buffer.header32.e_machine; -#elif defined(U_WINDOWS) +#elif U_PLATFORM_HAS_WIN32_API if(length<sizeof(IMAGE_FILE_HEADER)) { fprintf(stderr, "genccode: match-arch file %s is too short\n", filename); exit(U_UNSUPPORTED_ERROR); @@ -975,7 +978,7 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP newSuffix=".o"; -#elif defined(U_WINDOWS) +#elif U_PLATFORM_HAS_WIN32_API struct { IMAGE_FILE_HEADER fileHeader; IMAGE_SECTION_HEADER sections[2]; @@ -1002,7 +1005,7 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP /* deal with options, files and the entry point name */ getArchitecture(&cpu, &bits, &makeBigEndian, optMatchArch); printf("genccode: --match-arch cpu=%hu bits=%hu big-endian=%hu\n", cpu, bits, makeBigEndian); -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API if(cpu==IMAGE_FILE_MACHINE_I386) { entryOffset=1; } @@ -1087,7 +1090,7 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP if(paddingSize!=0) { T_FileStream_write(out, padding, paddingSize); } -#elif defined(U_WINDOWS) +#elif U_PLATFORM_HAS_WIN32_API /* populate the .obj headers */ uprv_memset(&objHeader, 0, sizeof(objHeader)); uprv_memset(&symbols, 0, sizeof(symbols)); @@ -1148,7 +1151,7 @@ writeObjectCode(const char *filename, const char *destdir, const char *optEntryP T_FileStream_write(out, buffer, (int32_t)length); } -#ifdef U_WINDOWS +#if U_PLATFORM_HAS_WIN32_API /* write the symbol table */ T_FileStream_write(out, symbols, IMAGE_SIZEOF_SYMBOL); T_FileStream_write(out, &symbolNames, symbolNames.sizeofLongNames); diff --git a/tools/toolutil/pkg_genc.h b/tools/toolutil/pkg_genc.h index 750b363a..9bd312b9 100644 --- a/tools/toolutil/pkg_genc.h +++ b/tools/toolutil/pkg_genc.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2008-2009, International Business Machines + * Copyright (C) 2008-2011, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ @@ -8,6 +8,63 @@ #define __PKG_GENC_H__ #include "unicode/utypes.h" +#include "toolutil.h" + +#include "unicode/putil.h" +#include "putilimp.h" + +/*** Platform #defines move here ***/ +#if U_PLATFORM_HAS_WIN32_API +#ifdef __GNUC__ +#define WINDOWS_WITH_GNUC +#else +#define WINDOWS_WITH_MSVC +#endif +#endif + + +#if !defined(WINDOWS_WITH_MSVC) +#define BUILD_DATA_WITHOUT_ASSEMBLY +#endif + +#ifndef U_DISABLE_OBJ_CODE /* testing */ +#if defined(WINDOWS_WITH_MSVC) || U_PLATFORM_IS_LINUX_BASED +#define CAN_WRITE_OBJ_CODE +#endif +#if U_PLATFORM_HAS_WIN32_API || defined(U_ELF) +#define CAN_GENERATE_OBJECTS +#endif +#endif + +#if U_PLATFORM == U_PF_CYGWIN || defined(CYGWINMSVC) +#define USING_CYGWIN +#endif + +/* + * When building the data library without assembly, + * some platforms use a single c code file for all of + * the data to generate the final data library. This can + * increase the performance of the pkdata tool. + */ +#if U_PLATFORM == U_PF_OS400 +#define USE_SINGLE_CCODE_FILE +#endif + +/* Need to fix the file seperator character when using MinGW. */ +#if defined(WINDOWS_WITH_GNUC) || defined(USING_CYGWIN) +#define PKGDATA_FILE_SEP_STRING "/" +#else +#define PKGDATA_FILE_SEP_STRING U_FILE_SEP_STRING +#endif + +#define LARGE_BUFFER_MAX_SIZE 2048 +#define SMALL_BUFFER_MAX_SIZE 512 +#define SMALL_BUFFER_FLAG_NAMES 32 +#define BUFFER_PADDING_SIZE 20 + +/** End platform defines **/ + + U_INTERNAL void U_EXPORT2 printAssemblyHeadersToStdErr(void); diff --git a/tools/toolutil/pkg_gencmn.c b/tools/toolutil/pkg_gencmn.c index 59f4d79e..ced82138 100644 --- a/tools/toolutil/pkg_gencmn.c +++ b/tools/toolutil/pkg_gencmn.c @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2008-2011, International Business Machines + * Copyright (C) 2008-2012, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ @@ -92,6 +92,7 @@ static uint32_t fileMax = 0; static char *symPrefix = NULL; +#define LINE_BUFFER_SIZE 512 /* prototypes --------------------------------------------------------------- */ static void @@ -115,12 +116,21 @@ U_CAPI void U_EXPORT2 createCommonDataFile(const char *destDir, const char *name, const char *entrypointName, const char *type, const char *source, const char *copyRight, const char *dataFile, uint32_t max_size, UBool sourceTOC, UBool verbose, char *gencmnFileName) { static char buffer[4096]; - char line[512]; - char *s; + char *line; + char *linePtr; + char *s = NULL; UErrorCode errorCode=U_ZERO_ERROR; uint32_t i, fileOffset, basenameOffset, length, nread; FileStream *in, *file; + line = (char *)uprv_malloc(sizeof(char) * LINE_BUFFER_SIZE); + if (line == NULL) { + fprintf(stderr, "gencmn: unable to allocate memory for line buffer of size %d\n", LINE_BUFFER_SIZE); + exit(U_MEMORY_ALLOCATION_ERROR); + } + + linePtr = line; + maxSize = max_size; if (destDir == NULL) { @@ -155,11 +165,20 @@ createCommonDataFile(const char *destDir, const char *name, const char *entrypoi } /* read the list of files and get their lengths */ - while(T_FileStream_readLine(in, line, sizeof(line))!=NULL) { - /* remove trailing newline characters */ - s=line; + while((s != NULL && *s != 0) || (s=T_FileStream_readLine(in, (line=linePtr), + LINE_BUFFER_SIZE))!=NULL) { + /* remove trailing newline characters and parse space separated items */ + if (s != NULL && *s != 0) { + line=s; + } else { + s=line; + } while(*s!=0) { - if(*s=='\r' || *s=='\n') { + if(*s==' ') { + *s=0; + ++s; + break; + } else if(*s=='\r' || *s=='\n') { *s=0; break; } @@ -184,6 +203,10 @@ createCommonDataFile(const char *destDir, const char *name, const char *entrypoi addFile(getLongPathname(line), name, source, sourceTOC, verbose); } + if (linePtr) { + uprv_free(linePtr); + } + if(in!=T_FileStream_stdin()) { T_FileStream_close(in); } @@ -315,14 +338,14 @@ createCommonDataFile(const char *destDir, const char *name, const char *entrypoi /* write the source file */ sprintf(buffer, "/*\n" - " * ICU common data table of contents for %s.%s ,\n" + " * ICU common data table of contents for %s.%s\n" " * Automatically generated by icu/source/tools/gencmn/gencmn .\n" " */\n\n" "#include \"unicode/utypes.h\"\n" "#include \"unicode/udata.h\"\n" "\n" - "/* external symbol declarations for data */\n", - name, type); + "/* external symbol declarations for data (%d files) */\n", + name, type, fileCount); T_FileStream_writeLine(out, buffer); sprintf(buffer, "extern const char\n %s%s[]", symPrefix?symPrefix:"", files[0].pathname); @@ -389,7 +412,7 @@ addFile(const char *filename, const char *name, const char *source, UBool source fileMax += CHUNK_FILE_COUNT; files = uprv_realloc(files, fileMax*sizeof(files[0])); /* note: never freed. */ if(files==NULL) { - fprintf(stderr, "pkgdata/gencmn: Could not allocate %ld bytes for %d files\n", (fileMax*sizeof(files[0])), fileCount); + fprintf(stderr, "pkgdata/gencmn: Could not allocate %u bytes for %d files\n", (unsigned int)(fileMax*sizeof(files[0])), fileCount); exit(U_MEMORY_ALLOCATION_ERROR); } } @@ -402,7 +425,6 @@ addFile(const char *filename, const char *name, const char *source, UBool source exit(U_ILLEGAL_ARGUMENT_ERROR); } fullPath = pathToFullPath(filename, source); - /* store the pathname */ length = (uint32_t)(uprv_strlen(filename) + 1 + uprv_strlen(name) + 1); s=allocString(length); @@ -445,7 +467,6 @@ addFile(const char *filename, const char *name, const char *source, UBool source files[fileCount].fileSize=length; } else { char *t; - /* get and store the basename */ /* need to include the package name */ length = (uint32_t)(uprv_strlen(filename) + 1 + uprv_strlen(name) + 1); @@ -455,8 +476,6 @@ addFile(const char *filename, const char *name, const char *source, UBool source uprv_strcat(s, filename); fixDirToTreePath(s); files[fileCount].basename=s; - - /* turn the basename into an entry point name and store in the pathname field */ t=files[fileCount].pathname=allocString(length); while(--length>0) { @@ -504,6 +523,8 @@ pathToFullPath(const char *path, const char *source) { fullPath[0] = 0; } n = (int32_t)uprv_strlen(fullPath); + fullPath[n] = 0; /* Suppress compiler warning for unused variable n */ + /* when conditional code below is not compiled. */ uprv_strcat(fullPath, path); #if (U_FILE_ALT_SEP_CHAR != U_TREE_ENTRY_SEP_CHAR) diff --git a/tools/toolutil/pkg_icu.h b/tools/toolutil/pkg_icu.h index 77798e80..75e2edd0 100644 --- a/tools/toolutil/pkg_icu.h +++ b/tools/toolutil/pkg_icu.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2008-2009, International Business Machines + * Copyright (C) 2008-2011, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ @@ -13,10 +13,10 @@ U_CAPI int U_EXPORT2 writePackageDatFile(const char *outFilename, const char *outComment, - const char *sourcePath, const char *addList, U_NAMESPACE_QUALIFIER Package *pkg, + const char *sourcePath, const char *addList, icu::Package *pkg, char outType); -U_CAPI U_NAMESPACE_QUALIFIER Package * U_EXPORT2 +U_CAPI icu::Package * U_EXPORT2 readList(const char *filesPath, const char *listname, UBool readContents); #endif diff --git a/tools/toolutil/pkgitems.cpp b/tools/toolutil/pkgitems.cpp index ba5e827d..4a5a7218 100644 --- a/tools/toolutil/pkgitems.cpp +++ b/tools/toolutil/pkgitems.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2003-2010, International Business Machines +* Copyright (C) 2003-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -390,7 +390,7 @@ ures_enumDependencies(const char *itemName, const UDataInfo *pInfo, } } - U_NAMESPACE_QUALIFIER NativeItem nativePool; + icu::NativeItem nativePool; if(resData.usesPoolBundle) { char poolName[200]; diff --git a/tools/toolutil/ppucd.cpp b/tools/toolutil/ppucd.cpp new file mode 100644 index 00000000..c2a1b77d --- /dev/null +++ b/tools/toolutil/ppucd.cpp @@ -0,0 +1,565 @@ +/* +******************************************************************************* +* Copyright (C) 2011-2012, International Business Machines +* Corporation and others. All Rights Reserved. +******************************************************************************* +* file name: ppucd.cpp +* encoding: US-ASCII +* tab size: 8 (not used) +* indentation:4 +* +* created on: 2011dec11 +* created by: Markus W. Scherer +*/ + +#include "unicode/utypes.h" +#include "unicode/uchar.h" +#include "charstr.h" +#include "cstring.h" +#include "ppucd.h" +#include "uassert.h" +#include "uparse.h" + +#include <stdio.h> +#include <string.h> + +#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) + +U_NAMESPACE_BEGIN + +PropertyNames::~PropertyNames() {} + +int32_t +PropertyNames::getPropertyEnum(const char *name) const { + return u_getPropertyEnum(name); +} + +int32_t +PropertyNames::getPropertyValueEnum(int32_t property, const char *name) const { + return u_getPropertyValueEnum((UProperty)property, name); +} + +UniProps::UniProps() + : start(U_SENTINEL), end(U_SENTINEL), + bmg(U_SENTINEL), + scf(U_SENTINEL), slc(U_SENTINEL), stc(U_SENTINEL), suc(U_SENTINEL), + digitValue(-1), numericValue(NULL), + name(NULL), nameAlias(NULL) { + memset(binProps, 0, sizeof(binProps)); + memset(intProps, 0, sizeof(intProps)); + memset(age, 0, 4); +} + +UniProps::~UniProps() {} + +const int32_t PreparsedUCD::kNumLineBuffers; + +PreparsedUCD::PreparsedUCD(const char *filename, UErrorCode &errorCode) + : icuPnames(new PropertyNames()), pnames(icuPnames), + file(NULL), + defaultLineIndex(-1), blockLineIndex(-1), lineIndex(0), + lineNumber(0), + lineType(NO_LINE), + fieldLimit(NULL), lineLimit(NULL) { + if(U_FAILURE(errorCode)) { return; } + + if(filename==NULL || *filename==0 || (*filename=='-' && filename[1]==0)) { + filename=NULL; + file=stdin; + } else { + file=fopen(filename, "r"); + } + if(file==NULL) { + perror("error opening preparsed UCD"); + fprintf(stderr, "error opening preparsed UCD file %s\n", filename); + errorCode=U_FILE_ACCESS_ERROR; + return; + } + + memset(ucdVersion, 0, 4); + lines[0][0]=0; +} + +PreparsedUCD::~PreparsedUCD() { + if(file!=stdin) { + fclose(file); + } + delete icuPnames; +} + +// Same order as the LineType values. +static const char *lineTypeStrings[]={ + NULL, + NULL, + "ucd", + "property", + "binary", + "value", + "defaults", + "block", + "cp", + "algnamesrange" +}; + +PreparsedUCD::LineType +PreparsedUCD::readLine(UErrorCode &errorCode) { + if(U_FAILURE(errorCode)) { return NO_LINE; } + // Select the next available line buffer. + while(!isLineBufferAvailable(lineIndex)) { + ++lineIndex; + if (lineIndex == kNumLineBuffers) { + lineIndex = 0; + } + } + char *line=lines[lineIndex]; + *line=0; + lineLimit=fieldLimit=line; + lineType=NO_LINE; + char *result=fgets(line, sizeof(lines[0]), file); + if(result==NULL) { + if(ferror(file)) { + perror("error reading preparsed UCD"); + fprintf(stderr, "error reading preparsed UCD before line %ld\n", (long)lineNumber); + errorCode=U_FILE_ACCESS_ERROR; + } + return NO_LINE; + } + ++lineNumber; + if(*line=='#') { + fieldLimit=strchr(line, 0); + return lineType=EMPTY_LINE; + } + // Remove trailing /r/n. + char c; + char *limit=strchr(line, 0); + while(line<limit && ((c=*(limit-1))=='\n' || c=='\r')) { --limit; } + // Remove trailing white space. + while(line<limit && ((c=*(limit-1))==' ' || c=='\t')) { --limit; } + *limit=0; + lineLimit=limit; + if(line==limit) { + fieldLimit=limit; + return lineType=EMPTY_LINE; + } + // Split by ';'. + char *semi=line; + while((semi=strchr(semi, ';'))!=NULL) { *semi++=0; } + fieldLimit=strchr(line, 0); + // Determine the line type. + int32_t type; + for(type=EMPTY_LINE+1;; ++type) { + if(type==LINE_TYPE_COUNT) { + fprintf(stderr, + "error in preparsed UCD: unknown line type (first field) '%s' on line %ld\n", + line, (long)lineNumber); + errorCode=U_PARSE_ERROR; + return NO_LINE; + } + if(0==strcmp(line, lineTypeStrings[type])) { + break; + } + } + lineType=(LineType)type; + if(lineType==UNICODE_VERSION_LINE && fieldLimit<lineLimit) { + u_versionFromString(ucdVersion, fieldLimit+1); + } + return lineType; +} + +const char * +PreparsedUCD::firstField() { + char *field=lines[lineIndex]; + fieldLimit=strchr(field, 0); + return field; +} + +const char * +PreparsedUCD::nextField() { + if(fieldLimit==lineLimit) { return NULL; } + char *field=fieldLimit+1; + fieldLimit=strchr(field, 0); + return field; +} + +const UniProps * +PreparsedUCD::getProps(UnicodeSet &newValues, UErrorCode &errorCode) { + if(U_FAILURE(errorCode)) { return NULL; } + newValues.clear(); + if(!lineHasPropertyValues()) { + errorCode=U_ILLEGAL_ARGUMENT_ERROR; + return NULL; + } + firstField(); + const char *field=nextField(); + if(field==NULL) { + // No range field after the type. + fprintf(stderr, + "error in preparsed UCD: missing default/block/cp range field " + "(no second field) on line %ld\n", + (long)lineNumber); + errorCode=U_PARSE_ERROR; + return NULL; + } + UChar32 start, end; + if(!parseCodePointRange(field, start, end, errorCode)) { return NULL; } + UniProps *props; + switch(lineType) { + case DEFAULTS_LINE: + if(defaultLineIndex>=0) { + fprintf(stderr, + "error in preparsed UCD: second line with default properties on line %ld\n", + (long)lineNumber); + errorCode=U_PARSE_ERROR; + return NULL; + } + if(start!=0 || end!=0x10ffff) { + fprintf(stderr, + "error in preparsed UCD: default range must be 0..10FFFF, not '%s' on line %ld\n", + field, (long)lineNumber); + errorCode=U_PARSE_ERROR; + return NULL; + } + props=&defaultProps; + defaultLineIndex=lineIndex; + break; + case BLOCK_LINE: + blockProps=defaultProps; // Block inherits default properties. + props=&blockProps; + blockLineIndex=lineIndex; + break; + case CP_LINE: + if(blockProps.start<=start && end<=blockProps.end) { + // Code point range fully inside the last block inherits the block properties. + cpProps=blockProps; + } else if(start>blockProps.end || end<blockProps.start) { + // Code point range fully outside the last block inherits the default properties. + cpProps=defaultProps; + } else { + // Code point range partially overlapping with the last block is illegal. + fprintf(stderr, + "error in preparsed UCD: cp range %s on line %ld only " + "partially overlaps with block range %04lX..%04lX\n", + field, (long)lineNumber, (long)blockProps.start, (long)blockProps.end); + errorCode=U_PARSE_ERROR; + return NULL; + } + props=&cpProps; + break; + default: + // Will not occur because of the range check above. + errorCode=U_ILLEGAL_ARGUMENT_ERROR; + return NULL; + } + props->start=start; + props->end=end; + while((field=nextField())!=NULL) { + if(!parseProperty(*props, field, newValues, errorCode)) { return NULL; } + } + return props; +} + +static const struct { + const char *name; + int32_t prop; +} ppucdProperties[]={ + { "Name_Alias", PPUCD_NAME_ALIAS }, + { "Conditional_Case_Mappings", PPUCD_CONDITIONAL_CASE_MAPPINGS }, + { "Turkic_Case_Folding", PPUCD_TURKIC_CASE_FOLDING } +}; + +// Returns TRUE for "ok to continue parsing fields". +UBool +PreparsedUCD::parseProperty(UniProps &props, const char *field, UnicodeSet &newValues, + UErrorCode &errorCode) { + CharString pBuffer; + const char *p=field; + const char *v=strchr(p, '='); + int binaryValue; + if(*p=='-') { + if(v!=NULL) { + fprintf(stderr, + "error in preparsed UCD: mix of binary-property-no and " + "enum-property syntax '%s' on line %ld\n", + field, (long)lineNumber); + errorCode=U_PARSE_ERROR; + return FALSE; + } + binaryValue=0; + ++p; + } else if(v==NULL) { + binaryValue=1; + } else { + binaryValue=-1; + // Copy out the property name rather than modifying the field (writing a NUL). + pBuffer.append(p, (int32_t)(v-p), errorCode); + p=pBuffer.data(); + ++v; + } + int32_t prop=pnames->getPropertyEnum(p); + if(prop<0) { + for(int32_t i=0;; ++i) { + if(i==LENGTHOF(ppucdProperties)) { + // Ignore unknown property names. + return TRUE; + } + if(0==uprv_stricmp(p, ppucdProperties[i].name)) { + prop=ppucdProperties[i].prop; + U_ASSERT(prop>=0); + break; + } + } + } + if(prop<UCHAR_BINARY_LIMIT) { + if(binaryValue>=0) { + props.binProps[prop]=(UBool)binaryValue; + } else { + // No binary value for a binary property. + fprintf(stderr, + "error in preparsed UCD: enum-property syntax '%s' " + "for binary property on line %ld\n", + field, (long)lineNumber); + errorCode=U_PARSE_ERROR; + } + } else if(binaryValue>=0) { + // Binary value for a non-binary property. + fprintf(stderr, + "error in preparsed UCD: binary-property syntax '%s' " + "for non-binary property on line %ld\n", + field, (long)lineNumber); + errorCode=U_PARSE_ERROR; + } else if(prop<UCHAR_INT_LIMIT) { + int32_t value=pnames->getPropertyValueEnum(prop, v); + if(value==UCHAR_INVALID_CODE && prop==UCHAR_CANONICAL_COMBINING_CLASS) { + // TODO: Make getPropertyValueEnum(UCHAR_CANONICAL_COMBINING_CLASS, v) work. + char *end; + unsigned long ccc=uprv_strtoul(v, &end, 10); + if(v<end && *end==0 && ccc<=254) { + value=(int32_t)ccc; + } + } + if(value==UCHAR_INVALID_CODE) { + fprintf(stderr, + "error in preparsed UCD: '%s' is not a valid value on line %ld\n", + field, (long)lineNumber); + errorCode=U_PARSE_ERROR; + } else { + props.intProps[prop-UCHAR_INT_START]=value; + } + } else if(*v=='<') { + // Do not parse default values like <code point>, just set null values. + switch(prop) { + case UCHAR_BIDI_MIRRORING_GLYPH: + props.bmg=U_SENTINEL; + break; + case UCHAR_SIMPLE_CASE_FOLDING: + props.scf=U_SENTINEL; + break; + case UCHAR_SIMPLE_LOWERCASE_MAPPING: + props.slc=U_SENTINEL; + break; + case UCHAR_SIMPLE_TITLECASE_MAPPING: + props.stc=U_SENTINEL; + break; + case UCHAR_SIMPLE_UPPERCASE_MAPPING: + props.suc=U_SENTINEL; + break; + case UCHAR_CASE_FOLDING: + props.cf.remove(); + break; + case UCHAR_LOWERCASE_MAPPING: + props.lc.remove(); + break; + case UCHAR_TITLECASE_MAPPING: + props.tc.remove(); + break; + case UCHAR_UPPERCASE_MAPPING: + props.uc.remove(); + break; + case UCHAR_SCRIPT_EXTENSIONS: + props.scx.clear(); + break; + default: + fprintf(stderr, + "error in preparsed UCD: '%s' is not a valid default value on line %ld\n", + field, (long)lineNumber); + errorCode=U_PARSE_ERROR; + } + } else { + char c; + switch(prop) { + case UCHAR_NUMERIC_VALUE: + props.numericValue=v; + c=*v; + if('0'<=c && c<='9' && v[1]==0) { + props.digitValue=c-'0'; + } else { + props.digitValue=-1; + } + break; + case UCHAR_NAME: + props.name=v; + break; + case UCHAR_AGE: + u_versionFromString(props.age, v); // Writes 0.0.0.0 if v is not numeric. + break; + case UCHAR_BIDI_MIRRORING_GLYPH: + props.bmg=parseCodePoint(v, errorCode); + break; + case UCHAR_SIMPLE_CASE_FOLDING: + props.scf=parseCodePoint(v, errorCode); + break; + case UCHAR_SIMPLE_LOWERCASE_MAPPING: + props.slc=parseCodePoint(v, errorCode); + break; + case UCHAR_SIMPLE_TITLECASE_MAPPING: + props.stc=parseCodePoint(v, errorCode); + break; + case UCHAR_SIMPLE_UPPERCASE_MAPPING: + props.suc=parseCodePoint(v, errorCode); + break; + case UCHAR_CASE_FOLDING: + parseString(v, props.cf, errorCode); + break; + case UCHAR_LOWERCASE_MAPPING: + parseString(v, props.lc, errorCode); + break; + case UCHAR_TITLECASE_MAPPING: + parseString(v, props.tc, errorCode); + break; + case UCHAR_UPPERCASE_MAPPING: + parseString(v, props.uc, errorCode); + break; + case PPUCD_NAME_ALIAS: + props.nameAlias=v; + break; + case PPUCD_CONDITIONAL_CASE_MAPPINGS: + case PPUCD_TURKIC_CASE_FOLDING: + // No need to parse their values: They are hardcoded in the runtime library. + break; + case UCHAR_SCRIPT_EXTENSIONS: + parseScriptExtensions(v, props.scx, errorCode); + break; + default: + // Ignore unhandled properties. + return TRUE; + } + } + if(U_SUCCESS(errorCode)) { + newValues.add((UChar32)prop); + return TRUE; + } else { + return FALSE; + } +} + +UBool +PreparsedUCD::getRangeForAlgNames(UChar32 &start, UChar32 &end, UErrorCode &errorCode) { + if(U_FAILURE(errorCode)) { return FALSE; } + if(lineType!=ALG_NAMES_RANGE_LINE) { + errorCode=U_ILLEGAL_ARGUMENT_ERROR; + return FALSE; + } + firstField(); + const char *field=nextField(); + if(field==NULL) { + // No range field after the type. + fprintf(stderr, + "error in preparsed UCD: missing algnamesrange range field " + "(no second field) on line %ld\n", + (long)lineNumber); + errorCode=U_PARSE_ERROR; + return FALSE; + } + return parseCodePointRange(field, start, end, errorCode); +} + +UChar32 +PreparsedUCD::parseCodePoint(const char *s, UErrorCode &errorCode) { + char *end; + uint32_t value=(uint32_t)uprv_strtoul(s, &end, 16); + if(end<=s || *end!=0 || value>=0x110000) { + fprintf(stderr, + "error in preparsed UCD: '%s' is not a valid code point on line %ld\n", + s, (long)lineNumber); + errorCode=U_PARSE_ERROR; + return U_SENTINEL; + } + return (UChar32)value; +} + +UBool +PreparsedUCD::parseCodePointRange(const char *s, UChar32 &start, UChar32 &end, UErrorCode &errorCode) { + uint32_t st, e; + u_parseCodePointRange(s, &st, &e, &errorCode); + if(U_FAILURE(errorCode)) { + fprintf(stderr, + "error in preparsed UCD: '%s' is not a valid code point range on line %ld\n", + s, (long)lineNumber); + return FALSE; + } + start=(UChar32)st; + end=(UChar32)e; + return TRUE; +} + +void +PreparsedUCD::parseString(const char *s, UnicodeString &uni, UErrorCode &errorCode) { + UChar *buffer=uni.getBuffer(-1); + int32_t length=u_parseString(s, buffer, uni.getCapacity(), NULL, &errorCode); + if(errorCode==U_BUFFER_OVERFLOW_ERROR) { + errorCode=U_ZERO_ERROR; + uni.releaseBuffer(0); + buffer=uni.getBuffer(length); + length=u_parseString(s, buffer, uni.getCapacity(), NULL, &errorCode); + } + uni.releaseBuffer(length); + if(U_FAILURE(errorCode)) { + fprintf(stderr, + "error in preparsed UCD: '%s' is not a valid Unicode string on line %ld\n", + s, (long)lineNumber); + } +} + +void +PreparsedUCD::parseScriptExtensions(const char *s, UnicodeSet &scx, UErrorCode &errorCode) { + if(U_FAILURE(errorCode)) { return; } + scx.clear(); + CharString scString; + for(;;) { + const char *scs; + const char *scLimit=strchr(s, ' '); + if(scLimit!=NULL) { + scs=scString.clear().append(s, (int32_t)(scLimit-s), errorCode).data(); + if(U_FAILURE(errorCode)) { return; } + } else { + scs=s; + } + int32_t script=pnames->getPropertyValueEnum(UCHAR_SCRIPT, scs); + if(script==UCHAR_INVALID_CODE) { + fprintf(stderr, + "error in preparsed UCD: '%s' is not a valid script code on line %ld\n", + scs, (long)lineNumber); + errorCode=U_PARSE_ERROR; + return; + } else if(scx.contains(script)) { + fprintf(stderr, + "error in preparsed UCD: scx has duplicate '%s' codes on line %ld\n", + scs, (long)lineNumber); + errorCode=U_PARSE_ERROR; + return; + } else { + scx.add(script); + } + if(scLimit!=NULL) { + s=scLimit+1; + } else { + break; + } + } + if(scx.isEmpty()) { + fprintf(stderr, "error in preparsed UCD: empty scx= on line %ld\n", (long)lineNumber); + errorCode=U_PARSE_ERROR; + } +} + +U_NAMESPACE_END diff --git a/tools/toolutil/ppucd.h b/tools/toolutil/ppucd.h new file mode 100644 index 00000000..ae90b204 --- /dev/null +++ b/tools/toolutil/ppucd.h @@ -0,0 +1,174 @@ +/* +******************************************************************************* +* Copyright (C) 2011-2012, International Business Machines +* Corporation and others. All Rights Reserved. +******************************************************************************* +* file name: ppucd.h +* encoding: US-ASCII +* tab size: 8 (not used) +* indentation:4 +* +* created on: 2011dec11 +* created by: Markus W. Scherer +*/ + +#ifndef __PPUCD_H__ +#define __PPUCD_H__ + +#include "unicode/utypes.h" +#include "unicode/uniset.h" +#include "unicode/unistr.h" + +#include <stdio.h> + +/** Additions to the uchar.h enum UProperty. */ +enum { + /** Name_Alias */ + PPUCD_NAME_ALIAS=UCHAR_STRING_LIMIT, + PPUCD_CONDITIONAL_CASE_MAPPINGS, + PPUCD_TURKIC_CASE_FOLDING +}; + +U_NAMESPACE_BEGIN + +class U_TOOLUTIL_API PropertyNames { +public: + virtual ~PropertyNames(); + virtual int32_t getPropertyEnum(const char *name) const; + virtual int32_t getPropertyValueEnum(int32_t property, const char *name) const; +}; + +struct U_TOOLUTIL_API UniProps { + UniProps(); + ~UniProps(); + + int32_t getIntProp(int32_t prop) const { return intProps[prop-UCHAR_INT_START]; } + + UChar32 start, end; + UBool binProps[UCHAR_BINARY_LIMIT]; + int32_t intProps[UCHAR_INT_LIMIT-UCHAR_INT_START]; + UVersionInfo age; + UChar32 bmg; + UChar32 scf, slc, stc, suc; + int32_t digitValue; + const char *numericValue; + const char *name; + const char *nameAlias; + UnicodeString cf, lc, tc, uc; + UnicodeSet scx; +}; + +class U_TOOLUTIL_API PreparsedUCD { +public: + enum LineType { + /** No line, end of file. */ + NO_LINE, + /** Empty line. (Might contain a comment.) */ + EMPTY_LINE, + + /** ucd;6.1.0 */ + UNICODE_VERSION_LINE, + + /** property;Binary;Alpha;Alphabetic */ + PROPERTY_LINE, + /** binary;N;No;F;False */ + BINARY_LINE, + /** value;gc;Zs;Space_Separator */ + VALUE_LINE, + + /** defaults;0000..10FFFF;age=NA;bc=L;... */ + DEFAULTS_LINE, + /** block;0000..007F;age=1.1;blk=ASCII;ea=Na;... */ + BLOCK_LINE, + /** cp;0030;AHex;bc=EN;gc=Nd;na=DIGIT ZERO;... */ + CP_LINE, + + /** algnamesrange;4E00..9FCC;han;CJK UNIFIED IDEOGRAPH- */ + ALG_NAMES_RANGE_LINE, + + LINE_TYPE_COUNT + }; + + /** + * Constructor. + * Prepare this object for a new, empty package. + */ + PreparsedUCD(const char *filename, UErrorCode &errorCode); + + /** Destructor. */ + ~PreparsedUCD(); + + /** Sets (aliases) a non-standard PropertyNames implementation. Caller retains ownership. */ + void setPropertyNames(const PropertyNames *pn) { pnames=pn; } + + /** + * Reads a line from the preparsed UCD file. + * Splits the line by replacing each ';' with a NUL. + */ + LineType readLine(UErrorCode &errorCode); + + /** Returns the number of the line read by readLine(). */ + int32_t getLineNumber() const { return lineNumber; } + + /** Returns the line's next field, or NULL. */ + const char *nextField(); + + /** Returns the Unicode version when or after the UNICODE_VERSION_LINE has been read. */ + const UVersionInfo &getUnicodeVersion() const { return ucdVersion; } + + /** Returns TRUE if the current line has property values. */ + UBool lineHasPropertyValues() const { return DEFAULTS_LINE<=lineType && lineType<=CP_LINE; } + + /** + * Parses properties from the current line. + * Clears newValues and sets UProperty codes for property values mentioned + * on the current line (as opposed to being inherited). + * Returns a pointer to the filled-in UniProps, or NULL if something went wrong. + * The returned UniProps are usable until the next line of the same type is read. + */ + const UniProps *getProps(UnicodeSet &newValues, UErrorCode &errorCode); + + /** + * Returns the code point range for the current algnamesrange line. + * Calls & parses nextField(). + * Further nextField() calls will yield the range's type & prefix string. + * Returns U_SUCCESS(errorCode). + */ + UBool getRangeForAlgNames(UChar32 &start, UChar32 &end, UErrorCode &errorCode); + +private: + UBool isLineBufferAvailable(int32_t i) { + return defaultLineIndex!=i && blockLineIndex!=i; + } + + /** Resets the field iterator and returns the line's first field (the line type field). */ + const char *firstField(); + + UBool parseProperty(UniProps &props, const char *field, UnicodeSet &newValues, + UErrorCode &errorCode); + UChar32 parseCodePoint(const char *s, UErrorCode &errorCode); + UBool parseCodePointRange(const char *s, UChar32 &start, UChar32 &end, UErrorCode &errorCode); + void parseString(const char *s, UnicodeString &uni, UErrorCode &errorCode); + void parseScriptExtensions(const char *s, UnicodeSet &scx, UErrorCode &errorCode); + + static const int32_t kNumLineBuffers=3; + + PropertyNames *icuPnames; // owned + const PropertyNames *pnames; // aliased + FILE *file; + int32_t defaultLineIndex, blockLineIndex, lineIndex; + int32_t lineNumber; + LineType lineType; + char *fieldLimit; + char *lineLimit; + + UVersionInfo ucdVersion; + UniProps defaultProps, blockProps, cpProps; + // Multiple lines so that default and block properties can maintain pointers + // into their line buffers. + char lines[kNumLineBuffers][4096]; +}; + +U_NAMESPACE_END + +#endif // __PPUCD_H__ diff --git a/tools/toolutil/swapimpl.cpp b/tools/toolutil/swapimpl.cpp index ae911e0f..90c1eb41 100644 --- a/tools/toolutil/swapimpl.cpp +++ b/tools/toolutil/swapimpl.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2005-2011, International Business Machines +* Copyright (C) 2005-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -63,6 +63,7 @@ #include "uspoof_impl.h" #endif +U_NAMESPACE_USE /* definitions */ @@ -334,7 +335,7 @@ ucase_swap(const UDataSwapper *ds, ((pInfo->formatVersion[0]==1 && pInfo->formatVersion[2]==UTRIE_SHIFT && pInfo->formatVersion[3]==UTRIE_INDEX_SHIFT) || - pInfo->formatVersion[0]==2) + pInfo->formatVersion[0]==2 || pInfo->formatVersion[0]==3) )) { udata_printError(ds, "ucase_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as case mapping data\n", pInfo->dataFormat[0], pInfo->dataFormat[1], @@ -749,7 +750,7 @@ udata_swap(const UDataSwapper *ds, UErrorCode *pErrorCode) { char dataFormatChars[4]; const UDataInfo *pInfo; - int32_t headerSize, i, swappedLength; + int32_t i, swappedLength; if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { return 0; @@ -762,7 +763,7 @@ udata_swap(const UDataSwapper *ds, * information. Otherwise we would have to pass some of the information * and not be able to use the UDataSwapFn signature. */ - headerSize=udata_swapDataHeader(ds, inData, -1, NULL, pErrorCode); + udata_swapDataHeader(ds, inData, -1, NULL, pErrorCode); /* * If we wanted udata_swap() to also handle non-loadable data like a UTrie, diff --git a/tools/toolutil/toolutil.cpp b/tools/toolutil/toolutil.cpp index 33f3346f..7c02efc3 100644 --- a/tools/toolutil/toolutil.cpp +++ b/tools/toolutil/toolutil.cpp @@ -22,7 +22,11 @@ #include <sys/stat.h> #include "unicode/utypes.h" -#ifdef U_WINDOWS +#ifndef U_TOOLUTIL_IMPLEMENTATION +#error U_TOOLUTIL_IMPLEMENTATION not set - must be set for all ICU source files in common/ - see http://userguide.icu-project.org/howtouseicu +#endif + +#if U_PLATFORM_USES_ONLY_WIN32_API # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN # define NOUSER @@ -37,7 +41,7 @@ #endif /* In MinGW environment, io.h needs to be included for _mkdir() */ -#ifdef U_MINGW +#if U_PLATFORM == U_PF_MINGW #include <io.h> #endif @@ -86,7 +90,7 @@ U_CAPI int32_t U_EXPORT2 getCurrentYear() { U_CAPI const char * U_EXPORT2 getLongPathname(const char *pathname) { -#ifdef U_WINDOWS +#if U_PLATFORM_USES_ONLY_WIN32_API /* anticipate problems with "short" pathnames */ static WIN32_FIND_DATAA info; HANDLE file=FindFirstFileA(pathname, &info); @@ -121,9 +125,9 @@ findDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status) } #endif if(!basename) { - /* no basename - return '.'. */ - resultPtr = "."; - resultLen = 1; + /* no basename - return ''. */ + resultPtr = ""; + resultLen = 0; } else { resultPtr = path; resultLen = basename - path; @@ -166,13 +170,13 @@ U_CAPI void U_EXPORT2 uprv_mkdir(const char *pathname, UErrorCode *status) { int retVal = 0; -#if defined(U_WINDOWS) || defined(U_MINGW) +#if U_PLATFORM_USES_ONLY_WIN32_API retVal = _mkdir(pathname); #else retVal = mkdir(pathname, S_IRWXU | (S_IROTH | S_IXOTH) | (S_IROTH | S_IXOTH)); #endif if (retVal && errno != EEXIST) { -#if defined(U_CYGWIN) || defined(U_MINGW) +#if U_PF_MINGW <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN /*if using Cygwin and the mkdir says it failed...check if the directory already exists..*/ /* if it does...don't give the error, if it does not...give the error - Brian Rower - 6/25/08 */ struct stat st; diff --git a/tools/toolutil/toolutil.h b/tools/toolutil/toolutil.h index be32942c..7b93211c 100644 --- a/tools/toolutil/toolutil.h +++ b/tools/toolutil/toolutil.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2010, International Business Machines +* Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -21,7 +21,8 @@ #include "unicode/utypes.h" -#ifdef XP_CPLUSPLUS + +#ifdef __cplusplus #include "unicode/errorcode.h" @@ -83,7 +84,7 @@ findBasename(const char *filename); * If successful, copies the directory name into the output buffer along with * a terminating NULL. * - * If there isn't a directory name in the path, it returns the current directory string ('.'). + * If there isn't a directory name in the path, it returns an empty string. * @param path the full pathname to inspect. * @param buffer the output buffer * @param bufLen the output buffer length diff --git a/tools/toolutil/toolutil.vcxproj b/tools/toolutil/toolutil.vcxproj index e565bdfb..abb57fdf 100644 --- a/tools/toolutil/toolutil.vcxproj +++ b/tools/toolutil/toolutil.vcxproj @@ -107,7 +107,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin\icutu48.dll</OutputFile>
+ <OutputFile>..\..\..\bin\icutu49.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ProgramDatabaseFile>.\..\..\..\lib\icutu.pdb</ProgramDatabaseFile>
@@ -151,7 +151,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin\icutu48d.dll</OutputFile>
+ <OutputFile>..\..\..\bin\icutu49d.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -193,7 +193,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin64\icutu48.dll</OutputFile>
+ <OutputFile>..\..\..\bin64\icutu49.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\..\lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ProgramDatabaseFile>.\..\..\..\lib64\icutu.pdb</ProgramDatabaseFile>
@@ -235,7 +235,7 @@ <Culture>0x0409</Culture>
</ResourceCompile>
<Link>
- <OutputFile>..\..\..\bin64\icutu48d.dll</OutputFile>
+ <OutputFile>..\..\..\bin64\icutu49d.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\..\lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -265,6 +265,7 @@ </ClCompile>
<ClCompile Include="pkg_icu.cpp" />
<ClCompile Include="pkgitems.cpp" />
+ <ClCompile Include="ppucd.cpp" />
<ClCompile Include="swapimpl.cpp" />
<ClCompile Include="toolutil.cpp">
<DisableLanguageExtensions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</DisableLanguageExtensions>
@@ -299,7 +300,7 @@ <ClInclude Include="pkg_gencmn.h" />
<ClInclude Include="pkg_icu.h" />
<ClInclude Include="pkg_imp.h" />
- <ClInclude Include="platform_xopen_source_extended.h" />
+ <ClInclude Include="ppucd.h" />
<ClInclude Include="swapimpl.h" />
<ClInclude Include="toolutil.h" />
<ClInclude Include="ucbuf.h" />
diff --git a/tools/toolutil/ucbuf.c b/tools/toolutil/ucbuf.c index 5194ea6f..23f2c9f1 100644 --- a/tools/toolutil/ucbuf.c +++ b/tools/toolutil/ucbuf.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2008, International Business Machines +* Copyright (C) 1998-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -17,14 +17,15 @@ #include "unicode/utypes.h" #include "unicode/putil.h" +#include "unicode/uchar.h" #include "unicode/ucnv.h" #include "unicode/ucnv_err.h" +#include "unicode/ustring.h" +#include "unicode/utf16.h" #include "filestrm.h" #include "cstring.h" #include "cmemory.h" #include "ustrfmt.h" -#include "unicode/ustring.h" -#include "unicode/uchar.h" #include "ucbuf.h" #include <stdio.h> @@ -65,7 +66,7 @@ ucbuf_autodetect_fs(FileStream* in, const char** cp, UConverter** conv, int32_t* /* unread the bytes beyond what was consumed for U+FEFF */ T_FileStream_rewind(in); if (*signatureLength > 0) { - numRead = T_FileStream_read(in, start, *signatureLength); + T_FileStream_read(in, start, *signatureLength); } if(*cp==NULL){ @@ -353,8 +354,8 @@ ucbuf_getc32(UCHARBUF* buf,UErrorCode* error){ return U_EOF; } } - if(UTF_IS_LEAD(*(buf->currentPos))){ - retVal=UTF16_GET_PAIR_VALUE(buf->currentPos[0],buf->currentPos[1]); + if(U16_IS_LEAD(*(buf->currentPos))){ + retVal=U16_GET_SUPPLEMENTARY(buf->currentPos[0],buf->currentPos[1]); buf->currentPos+=2; }else{ retVal = *(buf->currentPos++); diff --git a/tools/toolutil/ucmstate.c b/tools/toolutil/ucmstate.c index e1adb974..5d8c8777 100644 --- a/tools/toolutil/ucmstate.c +++ b/tools/toolutil/ucmstate.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2003-2010, International Business Machines +* Copyright (C) 2003-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -976,7 +976,7 @@ ucm_countChars(UCMStates *states, uint8_t state; offset=0; - i=count=0; + count=0; state=0; if(states->countStates==0) { diff --git a/tools/toolutil/udbgutil.cpp b/tools/toolutil/udbgutil.cpp index 3fa35d7e..d9f7869a 100644 --- a/tools/toolutil/udbgutil.cpp +++ b/tools/toolutil/udbgutil.cpp @@ -1,11 +1,16 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2007-2010, International Business Machines Corporation and + * Copyright (c) 2007-2012, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ #include "udbgutil.h" #include <string.h> +#include "ustr_imp.h" +#include "cstring.h" +#include "putilimp.h" +#include "unicode/ulocdata.h" +#include "unicode/ucnv.h" /* To add a new enum type @@ -327,3 +332,223 @@ int32_t udbg_enumByName(UDebugEnumType type, const char *value) { // fail return -1; } + +/* platform info */ +/** + * Print the current platform + */ +U_CAPI const char *udbg_getPlatform(void) +{ +#if U_PLATFORM_HAS_WIN32_API + return "Windows"; +#elif U_PLATFORM == U_PF_UNKNOWN + return "unknown"; +#else + return "Other (POSIX-like)"; +#endif +} + +struct USystemParams; + +typedef int32_t U_CALLCONV USystemParameterCallback(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status); + +struct USystemParams { + const char *paramName; + USystemParameterCallback *paramFunction; + const char *paramStr; + int32_t paramInt; +}; + +/* parameter types */ +U_CAPI int32_t +paramEmpty(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { + if(U_FAILURE(*status))return 0; + return u_terminateChars(target, targetCapacity, 0, status); +} + +U_CAPI int32_t +paramStatic(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) { + if(param->paramStr==NULL) return paramEmpty(param,target,targetCapacity,status); + if(U_FAILURE(*status))return 0; + int32_t len = uprv_strlen(param->paramStr); + if(target!=NULL) { + uprv_strncpy(target,param->paramStr,uprv_min(len,targetCapacity)); + } + return u_terminateChars(target, targetCapacity, len, status); +} + +static int32_t stringToStringBuffer(char *target, int32_t targetCapacity, const char *str, UErrorCode *status) { + int32_t len = uprv_strlen(str); + if(target!=NULL) { + uprv_strncpy(target,str,uprv_min(len,targetCapacity)); + } + return u_terminateChars(target, targetCapacity, len, status); +} + +static int32_t integerToStringBuffer(char *target, int32_t targetCapacity, int32_t n, int32_t radix, UErrorCode *status) { + if(U_FAILURE(*status)) return 0; + char str[300]; + T_CString_integerToString(str,n,radix); + return stringToStringBuffer(target,targetCapacity,str,status); +} + +U_CAPI int32_t +paramInteger(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) { + if(U_FAILURE(*status))return 0; + if(param->paramStr==NULL || param->paramStr[0]=='d') { + return integerToStringBuffer(target,targetCapacity,param->paramInt, 10,status); + } else if(param->paramStr[0]=='x') { + return integerToStringBuffer(target,targetCapacity,param->paramInt, 16,status); + } else if(param->paramStr[0]=='o') { + return integerToStringBuffer(target,targetCapacity,param->paramInt, 8,status); + } else if(param->paramStr[0]=='b') { + return integerToStringBuffer(target,targetCapacity,param->paramInt, 2,status); + } else { + *status = U_INTERNAL_PROGRAM_ERROR; + return 0; + } +} + + +U_CAPI int32_t +paramCldrVersion(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { + if(U_FAILURE(*status))return 0; + char str[200]=""; + UVersionInfo icu; + + ulocdata_getCLDRVersion(icu, status); + if(U_SUCCESS(*status)) { + u_versionToString(icu, str); + return stringToStringBuffer(target,targetCapacity,str,status); + } else { + return 0; + } +} + + +#if !UCONFIG_NO_FORMATTING +U_CAPI int32_t +paramTimezoneDefault(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { + if(U_FAILURE(*status))return 0; + UChar buf[100]; + char buf2[100]; + int32_t len; + + len = ucal_getDefaultTimeZone(buf, 100, status); + if(U_SUCCESS(*status)&&len>0) { + u_UCharsToChars(buf, buf2, len+1); + return stringToStringBuffer(target,targetCapacity, buf2,status); + } else { + return 0; + } +} +#endif + +U_CAPI int32_t +paramLocaleDefaultBcp47(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { + if(U_FAILURE(*status))return 0; + const char *def = uloc_getDefault(); + return uloc_toLanguageTag(def,target,targetCapacity,FALSE,status); +} + + +/* simple 1-liner param functions */ +#define STRING_PARAM(func, str) U_CAPI int32_t \ + func(const USystemParams *, char *target, int32_t targetCapacity, UErrorCode *status) \ + { return stringToStringBuffer(target,targetCapacity,(str),status); } + +STRING_PARAM(paramIcudataPath, u_getDataDirectory()) +STRING_PARAM(paramPlatform, udbg_getPlatform()) +STRING_PARAM(paramLocaleDefault, uloc_getDefault()) +#if !UCONFIG_NO_CONVERSION +STRING_PARAM(paramConverterDefault, ucnv_getDefaultName()) +#endif + +#if !UCONFIG_NO_FORMATTING +STRING_PARAM(paramTimezoneVersion, ucal_getTZDataVersion(status)) +#endif + +static USystemParams systemParams[] = { + { "copyright", paramStatic, U_COPYRIGHT_STRING,0 }, + { "product", paramStatic, "icu4c",0 }, + { "product.full", paramStatic, "International Components for Unicode for C/C++",0 }, + { "version", paramStatic, U_ICU_VERSION,0 }, + { "version.unicode", paramStatic, U_UNICODE_VERSION,0 }, + { "platform.number", paramInteger, "d",U_PLATFORM}, + { "platform.type", paramPlatform, NULL ,0}, + { "locale.default", paramLocaleDefault, NULL, 0}, + { "locale.default.bcp47", paramLocaleDefaultBcp47, NULL, 0}, +#if !UCONFIG_NO_CONVERSION + { "converter.default", paramConverterDefault, NULL, 0}, +#endif + { "icudata.name", paramStatic, U_ICUDATA_NAME, 0}, + { "icudata.path", paramIcudataPath, NULL, 0}, + + { "cldr.version", paramCldrVersion, NULL, 0}, + +#if !UCONFIG_NO_FORMATTING + { "tz.version", paramTimezoneVersion, NULL, 0}, + { "tz.default", paramTimezoneDefault, NULL, 0}, +#endif + + { "cpu.bits", paramInteger, "d", (sizeof(void*))*8}, + { "cpu.big_endian", paramInteger, "b", U_IS_BIG_ENDIAN}, + { "os.wchar_width", paramInteger, "d", U_SIZEOF_WCHAR_T}, + { "os.charset_family", paramInteger, "d", U_CHARSET_FAMILY}, +#if defined (U_HOST) + { "os.host", paramStatic, U_HOST, 0}, +#endif +#if defined (U_BUILD) + { "build.build", paramStatic, U_BUILD, 0}, +#endif +#if defined (U_CC) + { "build.cc", paramStatic, U_CC, 0}, +#endif +#if defined (U_CXX) + { "build.cxx", paramStatic, U_CXX, 0}, +#endif +#if defined (CYGWINMSVC) + { "build.cygwinmsvc", paramInteger, "b", 1}, +#endif + { "uconfig.internal_digitlist", paramInteger, "b", UCONFIG_INTERNAL_DIGITLIST}, + { "uconfig.have_parseallinput", paramInteger, "b", UCONFIG_HAVE_PARSEALLINPUT}, + { "uconfig.format_fastpaths_49",paramInteger, "b", UCONFIG_FORMAT_FASTPATHS_49}, + + +}; + +#define U_SYSPARAM_COUNT (sizeof(systemParams)/sizeof(systemParams[0])) + +U_CAPI const char *udbg_getSystemParameterNameByIndex(int32_t i) { + if(i>=0 && i < (int32_t)U_SYSPARAM_COUNT) { + return systemParams[i].paramName; + } else { + return NULL; + } +} + + +U_CAPI int32_t udbg_getSystemParameterValueByIndex(int32_t i, char *buffer, int32_t bufferCapacity, UErrorCode *status) { + if(i>=0 && i< (int32_t)U_SYSPARAM_COUNT) { + return systemParams[i].paramFunction(&(systemParams[i]),buffer,bufferCapacity,status); + } else { + return 0; + } +} + +U_CAPI void udbg_writeIcuInfo(FILE *out) { + char str[2000]; + /* todo: API for writing DTD? */ + fprintf(out, " <icuSystemParams type=\"icu4c\">\n"); + const char *paramName; + for(int32_t i=0;(paramName=udbg_getSystemParameterNameByIndex(i))!=NULL;i++) { + UErrorCode status2 = U_ZERO_ERROR; + udbg_getSystemParameterValueByIndex(i, str,2000,&status2); + if(U_SUCCESS(status2)) { + fprintf(out," <param name=\"%s\">%s</param>\n", paramName,str); + } else { + fprintf(out," <!-- n=\"%s\" ERROR: %s -->\n", paramName, u_errorName(status2)); + } + } + fprintf(out, " </icuSystemParams>\n"); +} diff --git a/tools/toolutil/udbgutil.h b/tools/toolutil/udbgutil.h index 1938c793..0f4da6cb 100644 --- a/tools/toolutil/udbgutil.h +++ b/tools/toolutil/udbgutil.h @@ -1,6 +1,6 @@ /* ************************************************************************ -* Copyright (c) 2008-2010, International Business Machines +* Copyright (c) 2008-2011, International Business Machines * Corporation and others. All Rights Reserved. ************************************************************************ */ @@ -11,7 +11,7 @@ #define _UDBGUTIL_H #include "unicode/utypes.h" - +#include <stdio.h> enum UDebugEnumType { UDBG_UDebugEnumType = 0, /* Self-referential, strings for UDebugEnumType. Count=ENUM_COUNT. */ @@ -75,4 +75,32 @@ U_CAPI int32_t U_EXPORT2 udbg_enumArrayValue(UDebugEnumType type, int32_t field) */ U_CAPI int32_t U_EXPORT2 udbg_enumByName(UDebugEnumType type, const char *name); + +/** + * Return the Platform (U_PLATFORM) as a string + */ +U_CAPI const char *udbg_getPlatform(void); + +/** + * Get the nth system parameter's name + * @param i index of name, starting from zero + * @return name, or NULL if off the end + * @see udbg_getSystemParameterValue + */ +U_CAPI const char *udbg_getSystemParameterNameByIndex(int32_t i); + +/** + * Get the nth system parameter's value, in a user supplied buffer + * @parameter i index of value, starting from zero + * @param status error status + * @return length written (standard termination rules) + * @see udbg_getSystemParameterName + */ +U_CAPI int32_t udbg_getSystemParameterValueByIndex(int32_t i, char *buffer, int32_t bufferCapacity, UErrorCode *status); + +/** + * Write ICU info as XML + */ +U_CAPI void udbg_writeIcuInfo(FILE *f); + #endif diff --git a/tools/toolutil/uoptions.h b/tools/toolutil/uoptions.h index 55e30f68..43db65f2 100644 --- a/tools/toolutil/uoptions.h +++ b/tools/toolutil/uoptions.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2000, International Business Machines +* Copyright (C) 2000-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -22,7 +22,7 @@ #include "unicode/utypes.h" /* This should usually be called before calling u_parseArgs */ -/*#if defined(OS390) && (U_CHARSET_FAMILY == U_ASCII_FAMILY)*/ +/*#if U_PLATFORM == U_PF_OS390 && (U_CHARSET_FAMILY == U_ASCII_FAMILY)*/ /* translate args from EBCDIC to ASCII */ /*# define U_MAIN_INIT_ARGS(argc, argv) __argvtoascii_a(argc, argv)*/ /*#elif defined(XP_MAC_CONSOLE)*/ diff --git a/tools/toolutil/uparse.c b/tools/toolutil/uparse.c index 9902c5c2..3d098cbf 100644 --- a/tools/toolutil/uparse.c +++ b/tools/toolutil/uparse.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2000-2010, International Business Machines +* Copyright (C) 2000-2011, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -19,11 +19,12 @@ */ #include "unicode/utypes.h" +#include "unicode/uchar.h" +#include "unicode/ustring.h" +#include "unicode/utf16.h" #include "cstring.h" #include "filestrm.h" #include "uparse.h" -#include "unicode/uchar.h" -#include "unicode/ustring.h" #include "ustr_imp.h" #include <stdio.h> diff --git a/tools/toolutil/writesrc.c b/tools/toolutil/writesrc.c index fc19e380..6db9087e 100644 --- a/tools/toolutil/writesrc.c +++ b/tools/toolutil/writesrc.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2005-2010, International Business Machines +* Copyright (C) 2005-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -25,7 +25,8 @@ #include "writesrc.h" static FILE * -usrc_createWithHeader(const char *path, const char *filename, const char *header) { +usrc_createWithHeader(const char *path, const char *filename, + const char *generator, const char *header) { char buffer[1024]; const char *p; char *q; @@ -54,8 +55,12 @@ usrc_createWithHeader(const char *path, const char *filename, const char *header time(&t); lt=localtime(&t); strftime(year, sizeof(year), "%Y", lt); - strftime(buffer, sizeof(buffer), "%Y-%m-%d", lt); - fprintf(f, header, year, filename, buffer); + if(generator==NULL) { + strftime(buffer, sizeof(buffer), "%Y-%m-%d", lt); + fprintf(f, header, year, filename, buffer); + } else { + fprintf(f, header, year, filename, generator); + } } else { fprintf( stderr, @@ -66,30 +71,30 @@ usrc_createWithHeader(const char *path, const char *filename, const char *header } U_CAPI FILE * U_EXPORT2 -usrc_create(const char *path, const char *filename) { - const char *header= +usrc_create(const char *path, const char *filename, const char *generator) { + static const char *header= "/*\n" " * Copyright (C) 1999-%s, International Business Machines\n" " * Corporation and others. All Rights Reserved.\n" " *\n" " * file name: %s\n" " *\n" - " * machine-generated on: %s\n" + " * machine-generated by: %s\n" " */\n\n"; - return usrc_createWithHeader(path, filename, header); + return usrc_createWithHeader(path, filename, generator, header); } U_CAPI FILE * U_EXPORT2 -usrc_createTextData(const char *path, const char *filename) { - const char *header= +usrc_createTextData(const char *path, const char *filename, const char *generator) { + static const char *header= "# Copyright (C) 1999-%s, International Business Machines\n" "# Corporation and others. All Rights Reserved.\n" "#\n" "# file name: %s\n" "#\n" - "# machine-generated on: %s\n" + "# machine-generated by: %s\n" "#\n\n"; - return usrc_createWithHeader(path, filename, header); + return usrc_createWithHeader(path, filename, generator, header); } U_CAPI void U_EXPORT2 diff --git a/tools/toolutil/writesrc.h b/tools/toolutil/writesrc.h index 9085d75d..f4ca0810 100644 --- a/tools/toolutil/writesrc.h +++ b/tools/toolutil/writesrc.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2005-2010, International Business Machines +* Copyright (C) 2005-2012, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -24,18 +24,18 @@ #include "utrie2.h" /** - * Creates a source text file and write a header comment with the ICU copyright. - * Writes a C/Java-style comment. + * Creates a source text file and writes a header comment with the ICU copyright. + * Writes a C/Java-style comment with the generator name. */ U_CAPI FILE * U_EXPORT2 -usrc_create(const char *path, const char *filename); +usrc_create(const char *path, const char *filename, const char *generator); /** - * Creates a source text file and write a header comment with the ICU copyright. + * Creates a source text file and writes a header comment with the ICU copyright. * Writes the comment with # lines, as used in scripts and text data. */ U_CAPI FILE * U_EXPORT2 -usrc_createTextData(const char *path, const char *filename); +usrc_createTextData(const char *path, const char *filename, const char *generator); /** * Writes the contents of an array of 8/16/32-bit words. |