Max Gotlib wrote:
>
> 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...
I've tried your patch and first of all - after successfully patching the
source and configuring with
runConfigure -p freebsd -nsocket -tnative -rpthread
(I suppose that's what you intended - right?)
I got the following error message from the gcc compiler:
IconvTransService.cpp:68: wchar.h: No such file or directory
IconvTransService.cpp:70: wctype.h: No such file or directory
I found that you still include these files which don't exist on FreeBSD 4.3
(and most probably also don't exist on 4.2 or 4.4).
I modified the ifdef's so that these include files are not requested
if XML_FREEBSD is defined.
Then I got the following error:
IconvTransService.cpp: In method `int IconvTransService::compareIString(const
XMLCh *, const XMLCh *)':
IconvTransService.cpp:207: syntax error before `='
Obviously, wint_t is unknown to the compiler, and since the towupper function
provided by you returns XMLCh, I added a definition
#define wint_t XMLCh
into the XML_FREEBSD branch from above.
With these modifications, I could create the library, and it seems to work
with our applications as well as the version with ICU transcoder.
I'm attaching the modified patch for Iconv.
If you agree to my changes, I can create a new patch for both,
i.e. my ICU patch from last week with your Iconv patch integrated.
Michael
--- util/Transcoders/Iconv/IconvTransService.cpp.orig Wed Jul 18 16:15:56 2001
+++ util/Transcoders/Iconv/IconvTransService.cpp Mon Oct 1 16:55:06 2001
@@ -65,10 +65,15 @@
#include <util/XMLUniDefs.hpp>
#include <util/XMLUni.hpp>
#include "IconvTransService.hpp"
+#ifdef XML_FREEBSD
+#include <ctype.h>
+#define wint_t XMLCh
+#else
#include <wchar.h>
#if defined (XML_GCC) || defined (XML_PTX) || defined (XML_IBMVAOS2)
#include <wctype.h>
#endif
+#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@@ -99,8 +104,83 @@
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 +259,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 +321,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 +350,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 +385,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 +393,7 @@
}
retVal = new char[neededLen + 1];
- ::wcstombs(retVal, wideCharBuf, neededLen);
+ x_wcstombs(retVal, wideCharBuf, neededLen);
retVal[neededLen] = 0;
delete [] allocatedArray;
}
@@ -358,7 +444,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 +480,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 +529,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]