From 6d632a7aa59cc735813ddac379ac9925936f1cd0 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sun, 27 Mar 2011 11:50:31 +0000 Subject: [PATCH] + porting ctpp2 for MS visual compiler --- src/ctpp2/include/CTPP2SysHeaders.h | 16 ++- src/ctpp2/include/CTPP2SysTypes.h | 4 + src/ctpp2/include/{stdint.h => stdintport.h} | 0 .../src/CTPP2StringIconvOutputCollector.cpp | 118 ------------------ 4 files changed, 15 insertions(+), 123 deletions(-) rename src/ctpp2/include/{stdint.h => stdintport.h} (100%) delete mode 100644 src/ctpp2/src/CTPP2StringIconvOutputCollector.cpp diff --git a/src/ctpp2/include/CTPP2SysHeaders.h b/src/ctpp2/include/CTPP2SysHeaders.h index 68e4657..4fa8fa6 100644 --- a/src/ctpp2/include/CTPP2SysHeaders.h +++ b/src/ctpp2/include/CTPP2SysHeaders.h @@ -35,7 +35,6 @@ #define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_TIME_H 0 -#undef HAVE_SYS_TIME_H #define HAVE_SYS_UIO_H 1 @@ -50,21 +49,18 @@ #define HAVE_STRING_H 1 #define HAVE_STRINGS_H 0 -#undef HAVE_STRINGS_H #define HAVE_TIME_H 1 #define HAVE_UNISTD_H 1 #define HAVE_SYSEXITS_H 0 -#undef HAVE_SYSEXITS_H /* #undef DEBUG_MODE */ /* #undef NO_STL_STD_NS_PREFIX */ #define GETTEXT_SUPPORT 0 -#undef GETTEXT_SUPPORT #define MD5_SUPPORT 0 #undef MD5_SUPPORT @@ -78,7 +74,6 @@ #define CTPP_MAX_TEMPLATE_RECURSION_DEPTH 1024 #define ICONV_SUPPORT 0 -#undef ICONV_SUPPORT #define ICONV_DISCARD_ILSEQ 1 @@ -90,5 +85,16 @@ /* #undef THROW_EXCEPTION_IN_COMPARATORS */ +/* + * Header files + */ +#ifdef WIN32 +#undef HAVE_SYS_TIME_H +#undef HAVE_STRINGS_H +#undef HAVE_SYSEXITS_H +#undef GETTEXT_SUPPORT +#undef ICONV_SUPPORT +#endif + #endif /* _CTPP2_SYS_HEADERS_H__ */ /* End. */ diff --git a/src/ctpp2/include/CTPP2SysTypes.h b/src/ctpp2/include/CTPP2SysTypes.h index 562d116..bfad99f 100644 --- a/src/ctpp2/include/CTPP2SysTypes.h +++ b/src/ctpp2/include/CTPP2SysTypes.h @@ -39,7 +39,11 @@ // C Includes #include +#ifdef WIN32 +#include +#else #include +#endif #if defined(__linux__) || defined(linux) || defined(CYGWIN) || defined(__CYGWIN__) diff --git a/src/ctpp2/include/stdint.h b/src/ctpp2/include/stdintport.h similarity index 100% rename from src/ctpp2/include/stdint.h rename to src/ctpp2/include/stdintport.h diff --git a/src/ctpp2/src/CTPP2StringIconvOutputCollector.cpp b/src/ctpp2/src/CTPP2StringIconvOutputCollector.cpp deleted file mode 100644 index cec041e..0000000 --- a/src/ctpp2/src/CTPP2StringIconvOutputCollector.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * Copyright (c) 2004 - 2010 CTPP Team - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the CTPP Team nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * CTPP2StringIconvOutputCollector.cpp - * - * $CTPP$ - */ - -#include "CTPP2StringIconvOutputCollector.hpp" -#include "CTPP2Exception.hpp" - -#include - -namespace CTPP // C++ Template Engine -{ - -// -// Constructor -// -StringIconvOutputCollector::StringIconvOutputCollector(STLW::string & sIResult, - const STLW::string & sISrcEnc, - const STLW::string & sIDstEnc, - const UINT_32 iIFlags): sResult(sIResult), - sSrcEnc(sISrcEnc), - sDstEnc(sIDstEnc), - iFlags(iIFlags) -{ - oIconv = iconv_open(sDstEnc.c_str(), sSrcEnc.c_str()); - // Check error - if (oIconv == (iconv_t)(-1)) - { - throw CTPPCharsetRecodeException(sSrcEnc.c_str(), sDstEnc.c_str()); - } - -#if (_LIBICONV_VERSION >= 0x0108) - int iFlag = 1; - // Discard illegal characters - if (iFlags & C_ICONV_DISCARD_ILSEQ) { iconvctl(oIconv, ICONV_SET_DISCARD_ILSEQ, &iFlag); } - - // Ånable transliteration in the conver-sion - if (iFlags & C_ICONV_TRANSLITERATE) { iconvctl(oIconv, ICONV_SET_TRANSLITERATE, &iFlag); } -#endif -} - -// -// A destructor -// -StringIconvOutputCollector::~StringIconvOutputCollector() throw() -{ - iconv_close(oIconv); -} - -// -// Collect data -// -INT_32 StringIconvOutputCollector::Collect(const void * vData, - const UINT_32 iDataLength) -{ - // Allocate memory - size_t iSrcLength = iDataLength; - size_t iDstLength = CTPP_ESCAPE_BUFFER_LEN; - - char aDstData[CTPP_ESCAPE_BUFFER_LEN]; -#if defined(linux) || defined(__APPLE__) - char * aSrcData = (char *)vData; -#else - const char * aSrcData = (const char *)vData; -#endif - - for (;;) - { - char * aDstTMP = aDstData; - size_t iDstLengthTMP = iDstLength; - size_t iResult = iconv(oIconv, &aSrcData, &iSrcLength, &aDstTMP, &iDstLengthTMP); - - if (aDstTMP - aDstData > 0) { sResult.append(aDstData, aDstTMP - aDstData); } - - // All data converted? - if (iResult != (size_t)-1) { break; } - else - { - if (errno != E2BIG) - { - ++aSrcData; - --iSrcLength; - } - } - } - -return 0; -} - -} // namespace CTPP -// End.