mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-22 03:12:20 -04:00
+ porting ctpp2 for MS visual compiler
This commit is contained in:
parent
1749286e3d
commit
6d632a7aa5
@ -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. */
|
||||
|
@ -39,7 +39,11 @@
|
||||
|
||||
// C Includes
|
||||
#include <sys/types.h>
|
||||
#ifdef WIN32
|
||||
#include <stdintport.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(linux) || defined(CYGWIN) || defined(__CYGWIN__)
|
||||
|
||||
|
@ -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 <errno.h>
|
||||
|
||||
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.
|
Loading…
x
Reference in New Issue
Block a user