Hi!
I've searched through the XercesC-related mailing lists, looking for hints
on compiling XercesC under FreeBSD (I'm running 4.2 and 4.4). The solution
(patch) you've posted to the *-dev list makes it possible to compile it
with ICU transcoding staff. I was able to build the package for Iconv
transcoding subsystem (the patch against yours one is attached). The main
problem is caused by the lack of wsc* functions in the FreeBSD libc and
"unexpected" behavior of wcstombs() and mbstowsc() functions, called with
NULL arguments... I was speaking about XercesC-1.5.1...
Max.
diff -ruN xerces-c-src1_5_1/src/util/Transcoders/Iconv/IconvTransService.cpp
xerces/src/util/Transcoders/Iconv/IconvTransService.cpp
--- xerces-c-src1_5_1/src/util/Transcoders/Iconv/IconvTransService.cpp Wed Jul 18
20:15:56 2001
+++ xerces/src/util/Transcoders/Iconv/IconvTransService.cpp Sun Sep 30 21:31:41
+2001
@@ -69,6 +69,9 @@
#if defined (XML_GCC) || defined (XML_PTX) || defined (XML_IBMVAOS2)
#include <wctype.h>
#endif
+#ifdef XML_FREEBSD
+#include <ctype.h>
+#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -99,7 +102,82 @@
return len;
}
+#ifdef XML_FREEBSD
+// ---------------------------------------------------------------------------
+// FreeBSD got the wide-characters support since 4.0 version. But (at least
+// up to the 4.4) this support differs from "others" in that the xxstoyys()
+// does not handle the NULL-dest argument properly. So the custom functions
+// are provided.
+// ---------------------------------------------------------------------------
+
+#define __TMP_ARRAY_SIZE__ 4
+
+static size_t
+fbsd_wcstombs( char *dest, const wchar_t *src, size_t n )
+{
+ char tarr[ __TMP_ARRAY_SIZE__ + 1 ];
+ size_t len = 0, lent = 0;
+ char* ptr;
+ size_t slen;
+ wchar_t* wptr;
+
+ if( dest )
+ return( ::wcstombs(dest, src, n) );
+ if( !src )
+ return( 0 );
+ for( wptr = (wchar_t *) src, slen = 0; *wptr; wptr++, slen++ );
+ if( slen == 0 )
+ return( 0 );
+ wptr = (wchar_t *) src;
+ ptr = dest;
+ while( (len = ::wcstombs(tarr, wptr, __TMP_ARRAY_SIZE__)) > 0 ) {
+ wptr += len;
+ lent += len;
+ }
+ if( len == (unsigned) -1 )
+ return( 0 );
+ return( lent );
+}
+
+static size_t
+fbsd_mbstowcs( wchar_t *dest, const char *src, size_t n )
+{
+ wchar_t tarr[ __TMP_ARRAY_SIZE__ + 1 ];
+ size_t len = 0, lent = 0;
+ char* ptr;
+
+ if( dest )
+ return( ::mbstowcs(dest, src, n ) );
+ ptr = (char*) src;
+ if( !src || strlen(src) == 0 )
+ return( 0 );
+ while( (len = ::mbstowcs(tarr, ptr, __TMP_ARRAY_SIZE__)) > 0 ) {
+ ptr += len;
+ lent += len;
+ }
+ if( len == (unsigned) -1 )
+ return( 0 );
+ return( lent );
+}
+
+#define x_mbstowcs fbsd_mbstowcs
+#define x_wcstombs fbsd_wcstombs
+
+
+static XMLCh towupper( XMLCh ch )
+{
+ char buf[16];
+ wcstombs( buf, (wchar_t*) &ch, 1 );
+ return toupper(ch);
+}
+
+#else
+
+#define x_mbstowcs mbstowcs
+#define x_wcstombs wcstombs
+
+#endif /* XML_FREEBSD */
// ---------------------------------------------------------------------------
// IconvTransService: Constructors and Destructor
@@ -179,7 +257,13 @@
bool IconvTransService::isSpace(const XMLCh toCheck) const
{
+#ifdef XML_FREEBSD
+ char buf[16];
+ mbstowcs( (wchar_t*) &toCheck, buf, 1 );
+ return (isspace(*buf) != 0);
+#else
return (iswspace(toCheck) != 0);
+#endif
}
@@ -235,7 +319,7 @@
if (!srcText)
return 0;
- const unsigned int retVal = ::mbstowcs(NULL, srcText, 0);
+ const unsigned int retVal = x_mbstowcs(NULL, srcText, 0);
if (retVal == ~0)
return 0;
@@ -264,7 +348,7 @@
}
wideCharBuf[wLent] = 0x00;
- const unsigned int retVal = ::wcstombs(NULL, wideCharBuf, 0);
+ const unsigned int retVal = x_wcstombs(NULL, wideCharBuf, 0);
delete [] allocatedArray;
if (retVal == ~0)
@@ -299,7 +383,7 @@
wideCharBuf[wLent] = 0x00;
// Calc the needed size.
- const size_t neededLen = ::wcstombs(NULL, wideCharBuf, 0);
+ const size_t neededLen = x_wcstombs(NULL, wideCharBuf, 0);
if (neededLen == -1)
{
delete [] allocatedArray;
@@ -307,7 +391,7 @@
}
retVal = new char[neededLen + 1];
- ::wcstombs(retVal, wideCharBuf, neededLen);
+ x_wcstombs(retVal, wideCharBuf, neededLen);
retVal[neededLen] = 0;
delete [] allocatedArray;
}
@@ -358,7 +442,7 @@
wideCharBuf[wLent] = 0x00;
// Ok, go ahead and try the transcoding. If it fails, then ...
- if (::wcstombs(toFill, wideCharBuf, maxBytes) == -1)
+ if (x_wcstombs(toFill, wideCharBuf, maxBytes) == -1)
{
delete [] allocatedArray;
return false;
@@ -394,7 +478,7 @@
else
wideCharBuf = tmpWideCharArr;
- ::mbstowcs(wideCharBuf, toTranscode, len);
+ x_mbstowcs(wideCharBuf, toTranscode, len);
retVal = new XMLCh[len + 1];
for (unsigned int i = 0; i < len; i++)
{
@@ -443,7 +527,7 @@
else
wideCharBuf = tmpWideCharArr;
- if (::mbstowcs(wideCharBuf, toTranscode, maxChars) == -1)
+ if (x_mbstowcs(wideCharBuf, toTranscode, maxChars) == -1)
{
delete [] allocatedArray;
return false;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]