Date: Thu, 30 Nov 2000 08:25:51 -0800 From: Dave Viner <dviner@yahoo-inc.com> To: xerces-c-dev@xml.apache.org, freebsd-ports@FreeBSD.ORG Subject: Porting Xerces-c to FreeBSD (round 1) Message-ID: <3A267F8F.C5E97DFE@yahoo-inc.com> References: <B56392D22C80D411AF7900508BDC9145070F2E@maestro.in.aventail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------738FF325BE1652B734ACC55F Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I have updated the original Xerces-FreeBSD patch file from 1.1 to 1.3. This port completely works under FreeBSD 4.1, however, the functionality of Xerces is slightly limited (no unicode) Here are the steps to use it: tar xvzf <xerces tar file> patch -p < Xerces-FreeBSD-v1.patch ( you should prob. check for reject files with find . -name "*rej"... if any .rej files exist, there was a problem with the patch) cd xerces-c-src1_3_0 setenv XERCESCROOT `pwd` OR export XERCESCROOT=`pwd` cd src chmod 775 runConfigure ./runConfigure -p freebsd -c gcc -x g++ ( -c is the c compiler to use, and -x is the c++ compiler) gmake >& gmake.out cd ../samples chmod 775 runConfigure chmod 775 configure ./runConfigure -p freebsd -c gcc -x g++ gmake >& gmake.out (I have also attached a short shell script which does *most* of this work.. it needs a little brushing up tho) Notes on the build process... -- the 1st gmake builds the libxerces-c1_3.so in $XERCESCROOT/lib. the 2nd gmake build the sample programs in $XERCESCROOT/bin. They should all work, except for the StdInParse... i couldn't make that one work... not sure why. -- in order to run the sample programs, you must have the lib subdirectory in your LD_LIBRARY_PATH variable. otherwise, the programs won't find the .so Notes on the port... -- I have not fully tested the resultant library built by this patch, but all the samples run, and some basic other tests i created work -- I've only built this library using the "Iconv" Transcoder. I haven't used the ICU stuff from IBM. -- This port removes the unicode capabilities of Xerces. I could not successfully get the unicode stuff to work on bsd. So I replaced the unicode stuff with standard C calls (strlen, strcpy, etc). The main problem is that BSD uses runes to handle multibyte chars, which is unlike any other os that is supported by xerces. the main file that i found was causing problems with unicode was src/util/Transcoders/Iconv/IconvTransService.cpp. This file instantiates a IconvLCPTranscoder object which is responsible for handling the ugliness in string work (more precisely, it handles the "transcode()" function from the main body of the Xerces parser). There are a few problem with this file. It relies on the wcstombs and mbstowcs functions, and that if the first argument is a null pointer, the function will return the length to move from one type of string to the other (mbs = multibyte string, wcs = wide character string). However, the current manifestation of these functions in BSD do not support this function. However, there is a patch available that handles it. See http://www.FreeBSD.org/cgi/query-pr.cgi?pr=17694 for details on the problem and the patch. It requires recompiling libc. This patch fixes the ansi.c file to handle this case. However, I couldn't get the function to return my multibyte or wide character string at all. Essentially the returned pointer contained either only 1 character or was null every time. (simple program to test: #include <stdlib.h> int main(int argc, char **argv) { int len; wchar_t foo [10]; len = mbstowcs(NULL, "SE", 0); printf("len = %d (should be 2)\n", len); len = mbstowcs(foo,"SE",len); printf("len = %d (should be 2) string = %s (should be SE)\n",len,foo); } The output is: >./mbtest len = 2 (should be 2) len = 2 (should be 2) string = S (should be SE) I could not get around this issue. Perhaps someone on the BSD porters list can help with this issue? In the IconvTransService.cpp file, I added several lines of debugging that can be enabled by using a -DFREEBSD_DEBUG during compile... although i don't guarentee that it will still work properly. An alternative to patching the libc was proposed by Mikko Työläjärvi and is in the file as the mbstowcs_wrapper and wcstombs_wrapper functions. Conclusion: The patch isn't perfect, but it's a big start. If you don't need Unicode support, you can run the patch, and compile, and code on top of Xerces. I hope that others out there will be able to assist in overcoming the final hurdles and get the unicode stuff all working on FreeBSD. --------------738FF325BE1652B734ACC55F Content-Type: text/plain; charset=iso-8859-1; name="Xerces-FreeBSD-v1.patch" Content-Transfer-Encoding: 8bit Content-Disposition: inline; filename="Xerces-FreeBSD-v1.patch" diff -ruN xerces-c-src1_3_0/samples/Makefile.incl xerces-c-src1_3_0/samples/Makefile.incl --- xerces-c-src1_3_0/samples/Makefile.incl Sat Sep 30 10:37:24 2000 +++ xerces-c-src1_3_0/samples/Makefile.incl Wed Nov 22 13:58:06 2000 @@ -166,6 +166,16 @@ SHLIBSUFFIX=.so endif +#=============== FREEBSD SPECIFIC OPTIONS ========================= +ifeq (${PLATFORM}, FREEBSD) +CMP= -c ${CXXFLAGS} +CC= gcc -c -D${PLATFORM} -D_REENTRANT -fpic -instances=static +LINK = $(CXX) -g -D${PLATFORM} -fpic +PLATFORM_LIB_LINK_OPTIONS=-L/usr/lib -L/usr/local/lib +EXTRA_LINK_OPTIONS=-lc -lc_r -lstdc++ -pthread -lcompat -ldes -ldescrypt -ldes_p -ldescrypt_p +SHLIBSUFFIX=.so +endif + #================= HP SPECIFIC OPTIONS =========================== ifeq (${PLATFORM}, HPUX) ifeq (${COMPILER}, aCC) diff -ruN xerces-c-src1_3_0/samples/aclocal.m4 xerces-c-src1_3_0/samples/aclocal.m4 --- xerces-c-src1_3_0/samples/aclocal.m4 Thu Jan 1 01:00:00 1970 +++ xerces-c-src1_3_0/samples/aclocal.m4 Sat Dec 25 08:41:27 1999 @@ -0,0 +1,25 @@ +dnl aclocal.m4 for xerces +dnl Jonathan McDowell <noodles@earth.li> + +dnl FreeBSD -pthread check - Jonathan McDowell <noodles@earth.li> +AC_DEFUN(AC_PTHREAD_FREEBSD, +[AC_MSG_CHECKING([if we need -pthread for threads]) +AC_CACHE_VAL(ac_ldflag_pthread, +[ac_save_LDFLAGS="$LDFLAGS" +LDFLAGS="-pthread $LDFLAGS" +AC_TRY_LINK( +[ +char pthread_create(); +], +pthread_create();, +eval "ac_ldflag_pthread=yes", +eval "ac_ldflag_pthread=no"), +LIBS="$ac_save_LDFLAGS" +]) +if eval "test \"`echo $ac_ldflag_pthread`\" = yes"; then + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +]) + diff -ruN xerces-c-src1_3_0/samples/configure.in freebsd/xerces-c-src1_3_0/samples/configure.in --- xerces-c-src1_3_0/samples/configure.in Wed Dec 1 18:58:20 1999 +++ xerces-c-src1_3_0/samples/configure.in Sat Dec 25 08:41:27 1999 @@ -11,10 +11,14 @@ AC_CHECK_LIB(m, floor) dnl special pthread handling (AIX uses pthreads instead of pthread) +dnl and FreeBSD uses -pthread instead of -lpthread AC_CHECK_LIB(pthread, pthread_create) if test $ac_cv_lib_pthread_pthread_create = no; then AC_CHECK_LIB(pthreads, pthread_create) fi +if test $ac_cv_lib_pthread_pthread_create = no; then +AC_PTHREAD_FREEBSD +fi dnl Checks for header files AC_CHECK_HEADERS(inttypes.h) @@ -39,6 +39,7 @@ *-*-UnixWare*) platform=UNIXWARE ;; *-*-unixware*) platform=UNIXWARE ;; *-*-linux*) platform=LINUX ;; + *-*-freebsd*) platform=FREEBSD ;; *-*-irix*) platform=IRIX ;; *-*-aix*) platform=AIX ;; *-*-hp*) platform=HPUX ; diff -uN xerces-c-src1_3_0/samples/runConfigure xerces-c-src1_3_0/samples/runConfigure --- xerces-c-src1_3_0/samples/runConfigure Sat Sep 30 10:37:24 2000 +++ xerces-c-src1_3_0/samples/runConfigure Tue Nov 21 15:23:10 2000 @@ -71,7 +71,7 @@ echo "Usage: runConfigure \"options\"" echo " where options may be any of the following:" echo " -p <platform> (accepts 'aix', 'linux', 'solaris', -'hp-10', 'hp-11', 'os400', 'irix', 'ptx', 'tru64')" +'hp-10', 'hp-11', 'os400', 'irix', 'ptx', 'tru64', 'freebsd')" echo " -c <C compiler name> (e.g. gcc, xlc or icc)" echo " -x <C++ compiler name> (e.g. g++, xlC, or icc)" echo " -d (specifies that you want to build debug version)" @@ -164,7 +164,7 @@ # Now check if the options are correct or not, bail out if incorrect case $platform in - aix | linux | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64) + aix | linux | solaris | hp-10 | hp-11 | os400 | irix | ptx | tru64 | freebsd) # platform has been recognized ;; *) @@ -181,8 +181,8 @@ LDFLAGS="-lC"; export LDFLAGS LIBS="-L/usr/lpp/xlC/lib"; export LIBS ;; - g++ | c++) - LDFLAGS="-lc"; export LDFLAGS + g++ | c++ | /usr/local/egcs-1.1.2/bin/g++ ) + LDFLAGS="-lc -lcompat"; export LDFLAGS if test $platform = "ptx"; then if test -z $XMLINSTALL; then XMLINSTALL=$ICUROOT @@ -227,7 +227,8 @@ elif test $platform = "ptx"; then ./configure --prefix=$XMLINSTALL else -./configure +autoconf +./configure $configureoptions fi echo diff -ruN xerces-c-src1_3_0/src/Makefile.incl freebsd/xerces-c-src1_3_0/src/Makefile.incl --- xerces-c-src1_3_0/src/Makefile.incl Thu Dec 23 05:57:10 1999 +++ xerces-c-src1_3_0/src/Makefile.incl Sat Dec 25 08:36:51 1999 @@ -227,6 +227,19 @@ SHLIBSUFFIX=.so endif +#=============== FREEBSD SPECIFIC OPTIONS ========================= +ifeq (${PLATFORM}, FREEBSD) +PLATFORM_COMPILE_OPTIONS = -fpic -instances=static -D${PLATFORM} -D_REENTRANT +MAKE_SHARED = ${CXX} -D${PLATFORM} -shared -fpic +MAKE_SHARED_C = ${CC} -D${PLATFORM} -shared -fpic +ifeq (${TRANSCODER}, ICU) + ALLLIBS = ${LIBS} -L/usr/lib -L/usr/local/lib -L/usr/ccs/lib -licu-uc -lc +else + ALLLIBS = ${LIBS} -L/usr/lib -L/usr/local/lib -L/usr/ccs/lib -lc +endif +SHLIBSUFFIX=.so +endif + #=============== IRIX SPECIFIC OPTIONS ============================ ifeq (${PLATFORM}, IRIX) PLATFORM_COMPILE_OPTIONS = -mips4 -LANG:pch -LANG:std -O2 \ diff -ruN xerces-c-src1_3_0/src/aclocal.m4 freebsd/xerces-c-src1_3_0/src/aclocal.m4 --- xerces-c-src1_3_0/src/aclocal.m4 Thu Jan 1 01:00:00 1970 +++ xerces-c-src1_3_0/src/aclocal.m4 Sat Dec 25 08:41:28 1999 @@ -0,0 +1,25 @@ +dnl aclocal.m4 for xerces +dnl Jonathan McDowell <noodles@earth.li> + +dnl FreeBSD -pthread check - Jonathan McDowell <noodles@earth.li> +AC_DEFUN(AC_PTHREAD_FREEBSD, +[AC_MSG_CHECKING([if we need -pthread for threads]) +AC_CACHE_VAL(ac_ldflag_pthread, +[ac_save_LDFLAGS="$LDFLAGS" +LDFLAGS="-pthread $LDFLAGS" +AC_TRY_LINK( +[ +char pthread_create(); +], +pthread_create();, +eval "ac_ldflag_pthread=yes", +eval "ac_ldflag_pthread=no"), +LIBS="$ac_save_LDFLAGS" +]) +if eval "test \"`echo $ac_ldflag_pthread`\" = yes"; then + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi +]) + diff -ruN xerces-c-src1_3_0/src/configure.in freebsd/xerces-c-src1_3_0/src/configure.in --- xerces-c-src1_3_0/src/configure.in Thu Dec 23 05:57:10 1999 +++ xerces-c-src1_3_0/src/configure.in Sat Dec 25 08:39:04 1999 @@ -11,6 +11,9 @@ dnl Checks for libraries AC_CHECK_LIB(m, floor) +dnl Do we need libcompat for ftime (FreeBSD does) +AC_CHECK_LIB(compat, ftime) + dnl dnl Do not know how to use this macro, so comment it out. dnl @@ -21,6 +24,12 @@ dnl fi dnl +ldflags=${LDCFLAGS} +AC_SUBST(ldflags) + +dnl Check if for FreeBSD threads +AC_PTHREAD_FREEBSD + dnl Checks for typedefs AC_CHECK_TYPE(XMLByte,unsigned char) @@ -34,6 +43,7 @@ *-*-UnixWare*) platform=UNIXWARE ;; *-*-unixware*) platform=UNIXWARE ;; *-*-linux*) platform=LINUX ;; + *-*-freebsd*) platform=FREEBSD ;; *-*-irix*) platform=IRIX ;; *-*-aix*) platform=AIX ;; *-*-hp*) platform=HPUX ; @@ -64,9 +74,6 @@ cflags=${CFLAGS} AC_SUBST(cflags) - -ldflags=${LDCFLAGS} -AC_SUBST(ldflags) libs=${LIBS} AC_SUBST(libs) @@ -98,6 +105,7 @@ util/Platforms/Solaris/Makefile \ util/Platforms/AIX/Makefile \ util/Platforms/Linux/Makefile \ +util/Platforms/FreeBSD/Makefile \ util/Platforms/HPUX/Makefile \ util/Platforms/OS390/Makefile \ util/Platforms/OS400/Makefile \ diff -ruN xerces-c-src1_3_0/src/runConfigure freebsd/xerces-c-src1_3_0/src/runConfigure --- xerces-c-src1_3_0/src/runConfigure Thu Dec 23 05:57:10 1999 +++ xerces-c-src1_3_0/src/runConfigure Sat Dec 25 08:41:28 1999 @@ -79,7 +79,7 @@ echo "Usage: runConfigure \"options\"" echo " where options may be any of the following:" echo " -p <platform> (accepts 'aix', 'linux', 'solaris', - 'hp-10', 'hp-11', 'unixware', 'os400', 'irix', 'ptx', 'tru64' )" + 'hp-10', 'hp-11', 'unixware', 'os400', 'irix', 'ptx', 'tru64', 'freebsd' )" echo " -c <C compiler name> (e.g. gcc, cc, xlc_r, icc)" echo " -x <C++ compiler name> (e.g. g++, CC, xlC_r, icc, c++)" echo " -d (specifies that you want to build debug version)" @@ -201,7 +201,7 @@ # case $platform in - aix | linux | solaris | hp-10 | hp-11 | irix | unixware | os400 | ptx | tru64) + aix | linux | solaris | hp-10 | hp-11 | irix | unixware | os400 | ptx | tru64 | freebsd) # platform has been recognized ;; *) @@ -275,6 +275,8 @@ elif test $platform = "hp-10"; then threadingLibs="-lcma" threadingDefines="-DXML_USE_DCE" +elif test $platform = "freebsd"; then + threadingLibs="" fi @@ -436,6 +438,7 @@ elif test $platform = "ptx"; then ./configure --prefix=$XMLINSTALL else +autoconf ./configure $configureoptions fi echo @@ -450,6 +453,7 @@ echo export CFLAGS=\"$CFLAGS\" echo export LIBS=\"$LIBS\" echo export NETACCESSOR=\"$NETACCESSOR\" +echo autoconf echo configure $configureoptions echo diff -ruN xerces-c-src1_3_0/src/util/AutoSense.hpp freebsd/xerces-c-src1_3_0/src/util/AutoSense.hpp --- xerces-c-src1_3_0/src/util/AutoSense.hpp Thu Dec 23 05:57:26 1999 +++ xerces-c-src1_3_0/src/util/AutoSense.hpp Sat Dec 25 08:40:59 1999 @@ -100,6 +100,9 @@ #elif defined(__linux__) #define XML_LINUX #define XML_UNIX +#elif defined(__FreeBSD__) + #define XML_FREEBSD + #define XML_UNIX #elif defined(IRIX) #define XML_IRIX #define XML_UNIX @@ -207,7 +207,7 @@ #elif defined(__GNUG__) #define XML_GCC #endif -#elif defined (__GNUG__) || defined(__linux__) +#elif defined (__GNUG__) || defined(__linux__) || defined(__FreeBSD__) #define XML_GCC #elif defined(XML_HPUX) #if defined(EXM_HPUX) diff -uN xerces-c-src1_3_0/src/util/Platforms/FreeBSD/Makefile.in freebsd/xerces-c-src1_3_0/src/util/Platforms/FreeBSD/Makefile.in --- xerces-c-src1_3_0/src/util/Platforms/FreeBSD/Makefile.in Tue Nov 21 10:13:42 2000 +++ xerces-c-src1_3_0/src/util/Platforms/FreeBSD/Makefile.in Tue Nov 21 10:11:11 2000 @@ -0,0 +1,85 @@ +# +# The Apache Software License, Version 1.1 +# +# Copyright (c) 1999-2000 The Apache Software Foundation. All rights +# reserved. +# +# 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. +# +# 3. The end-user documentation included with the redistribution, +# if any, must include the following acknowledgment: +# "This product includes software developed by the +# Apache Software Foundation (http://www.apache.org/)." +# Alternately, this acknowledgment may appear in the software itself, +# if and wherever such third-party acknowledgments normally appear. +# +# 4. The names "Xerces" and "Apache Software Foundation" must +# not be used to endorse or promote products derived from this +# software without prior written permission. For written +# permission, please contact apache\@apache.org. +# +# 5. Products derived from this software may not be called "Apache", +# nor may "Apache" appear in their name, without prior written +# permission of the Apache Software Foundation. +# +# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR +# ITS 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. +# ==================================================================== +# +# This software consists of voluntary contributions made by many +# individuals on behalf of the Apache Software Foundation, and was +# originally based on software copyright (c) 1999, International +# Business Machines, Inc., http://www.ibm.com . For more information +# on the Apache Software Foundation, please see +# <http://www.apache.org/>. +# +# $Log: Makefile.in,v $ +# Revision 1.1 2000/03/01 22:33:38 abagchi +# Initial checkin to create object files directly under obj +#: +# + +PLATFORM = @platform@ +CC = @cc@ +CXX = @cxx@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util + +include ../../../Makefile.incl + +SUBMODULE = Platforms/FreeBSD +CXXFLAGS += -D_GNU_SOURCE -D__USE_GNU +CPP_PUBHEADERS = FreeBSDDefs.hpp +CPP_OBJECTS = FreeBSDPlatformUtils.$(TO) + +include ../../Makefile.util.submodule + diff -ruN xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDDefs.hpp freebsd/xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDDefs.hpp --- xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDDefs.hpp Thu Jan 1 01:00:00 1970 +++ xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDDefs.hpp Sat Dec 25 08:41:28 1999 @@ -0,0 +1,65 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999 The Apache Software Foundation. All rights + * reserved. + * + * 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. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xerces" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache\@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR + * ITS 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. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation, and was + * originally based on software copyright (c) 1999, International + * Business Machines, Inc., http://www.ibm.com . For more information + * on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +// --------------------------------------------------------------------------- +// FreeBSD Runs in little endian mode +// --------------------------------------------------------------------------- +#define ENDIANMODE_LITTLE +typedef void* FileHandle; + +#ifndef FREEBSD +#define FREEBSD +#endif diff -uN xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp --- xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp Mon Nov 27 13:43:58 2000 +++ xerces-c-src1_3_0/src/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp Mon Nov 27 13:43:58 2000 @@ -0,0 +1,730 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2000 The Apache Software Foundation. All rights + * reserved. + * + * 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. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Xerces" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache\@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR + * ITS 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. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation, and was + * originally based on software copyright (c) 1999, International + * Business Machines, Inc., http://www.ibm.com . For more information + * on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + +/* + * $Log: LinuxPlatformUtils.cpp,v $ + * Revision 1.17 2000/07/25 22:29:55 aruna1 + * Char definitions in XMLUni moved to XMLUniDefs + * + * Revision 1.16 2000/03/24 00:13:03 aruna1 + * Platform initialization taken care for both threaded and non-threaded environment + * + * Revision 1.15 2000/03/20 23:48:52 rahulj + * Added Socket based NetAccessor. This will enable one to + * use HTTP URL's for system id's. Default build options do + * not use this NetAccessor. Specify the '-n socket' option + * to 'runConfigure' to configure Xerces-C to use this new + * feature. The code works under Solaris 2.6, Linux, AIX + * and HPUX 11 with aCC. + * Todo's: enable proper error handling. + * + * Revision 1.14 2000/03/18 00:00:00 roddey + * Initial updates for two way transcoding support + * + * Revision 1.13 2000/03/02 21:10:36 abagchi + * Added empty function platformTerm() + * + * Revision 1.12 2000/03/02 20:42:41 abagchi + * Fixed typo in XMLExcepts + * + * Revision 1.11 2000/03/02 19:55:24 roddey + * This checkin includes many changes done while waiting for the + * 1.1.0 code to be finished. I can't list them all here, but a list is + * available elsewhere. + * + * Revision 1.10 2000/02/22 00:58:15 aruna1 + * openFile API updated + * + * Revision 1.9 2000/02/06 07:48:28 rahulj + * Year 2K copyright swat. + * + * Revision 1.8 2000/01/25 22:32:56 aruna1 + * Updated panic information + * + * Revision 1.7 2000/01/19 23:21:37 abagchi + * Made this file compatible with ICU 1.4 + * + * Revision 1.6 2000/01/19 17:37:48 abagchi + * Removed the streaming classes + * + * Revision 1.5 2000/01/14 02:04:43 abagchi + * Introduced getFullPath() and weavePath() + * + * Revision 1.4 1999/12/14 23:53:33 rahulj + * Removed the offending Ctrl-M's from the commit message + * logs which was giving packaging problems. + * + * PR: + * Obtained from: + * Submitted by: + * Reviewed by: + * + * Revision 1.3 1999/11/23 02:00:48 rahulj + * Code now works under HPUX 11. Tested inmemory message loader. + * Revamped makefiles. Builds with both DCE threads as well as pthread libraries. + * + * Revision 1.2 1999/11/17 22:35:33 rahulj + * Replaced default attr mutexes with recursive mutexes. Also code works with ICU transcoding service + * + * Revision 1.1.1.1 1999/11/09 01:07:01 twl + * Initial checkin + * + * Revision 1.6 1999/11/08 20:45:30 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- + +#if !defined(APP_NO_THREADS) +#include <pthread.h> +#endif + + +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> + // #include <libgen.h> +#include <sys/types.h> +// #include <sys/timeb.h> +#include <sys/time.h> // for gettimeofday +#include <string.h> +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/Janitor.hpp> +#include <util/Mutexes.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUniDefs.hpp> +#include <util/XMLUni.hpp> + +#if defined(XML_USE_ICU_TRANSCODER) + #include <util/Transcoders/ICU/ICUTransService.hpp> +#else + // Use native transcoder. Same as -DXML_USE_NATIVE_TRANSCODER + #include <util/Transcoders/Iconv/IconvTransService.hpp> +#endif + + +#if defined(XML_USE_ICU_MESSAGELOADER) + #include <util/MsgLoaders/ICU/ICUMsgLoader.hpp> +#else + // Same as -DXML_USE_INMEM_MESSAGELOADER + #include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> +#endif + + +#if defined (XML_USE_NETACCESSOR_SOCKET) + #include <util/NetAccessors/Socket/SocketNetAccessor.hpp> +#endif + + + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- + +static void WriteCharStr( FILE* stream, const char* const toWrite) +{ + if (fputs(toWrite, stream) == EOF) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::Strm_StdErrWriteFailure); + } +} + +static void WriteUStrStdErr( const XMLCh* const toWrite) +{ + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janText(tmpVal); + if (fputs(tmpVal, stderr) == EOF) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::Strm_StdErrWriteFailure); + } +} + +static void WriteUStrStdOut( const XMLCh* const toWrite) + { + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janText(tmpVal); + if (fputs(tmpVal, stdout) == EOF) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::Strm_StdOutWriteFailure); + } +} + +XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() +{ +#if defined (XML_USE_NETACCESSOR_SOCKET) + return new SocketNetAccessor(); +#else + return 0; +#endif +} + + + +XMLCh* XMLPlatformUtils::weavePaths(const XMLCh* const basePath + , const XMLCh* const relativePath) + +{ + // Create a buffer as large as both parts and empty it + XMLCh* tmpBuf = new XMLCh[XMLString::stringLen(basePath) + + XMLString::stringLen(relativePath) + + 2]; + *tmpBuf = 0; + + // + // If we have no base path, then just take the relative path as + // is. + // + if (!basePath) + { + XMLString::copyString(tmpBuf, relativePath); + return tmpBuf; + } + + if (!*basePath) + { + XMLString::copyString(tmpBuf, relativePath); + return tmpBuf; + } + + const XMLCh* basePtr = basePath + (XMLString::stringLen(basePath) - 1); + if ((*basePtr != chForwardSlash) + && (*basePtr != chBackSlash)) + { + while ((basePtr >= basePath) + && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash))) + { + basePtr--; + } + } + + // There is no relevant base path, so just take the relative part + if (basePtr < basePath) + { + XMLString::copyString(tmpBuf, relativePath); + return tmpBuf; + } + + // After this, make sure the buffer gets handled if we exit early + ArrayJanitor<XMLCh> janBuf(tmpBuf); + + // + // We have some path part, so we need to check to see if we ahve to + // weave any of the parts together. + // + const XMLCh* pathPtr = relativePath; + while (true) + { + // If it does not start with some period, then we are done + if (*pathPtr != chPeriod) + break; + + unsigned int periodCount = 1; + pathPtr++; + if (*pathPtr == chPeriod) + { + pathPtr++; + periodCount++; + } + + // Has to be followed by a \ or / or the null to mean anything + if ((*pathPtr != chForwardSlash) && (*pathPtr != chBackSlash) + && *pathPtr) + { + break; + } + if (*pathPtr) + pathPtr++; + + // If its one period, just eat it, else move backwards in the base + if (periodCount == 2) + { + basePtr--; + while ((basePtr >= basePath) + && ((*basePtr != chForwardSlash) && (*basePtr != chBackSlash))) + { + basePtr--; + } + + // The base cannot provide enough levels, so its in error/ + if (basePtr < basePath) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_BasePathUnderflow); + } + } + + // Copy the base part up to the base pointer + XMLCh* bufPtr = tmpBuf; + const XMLCh* tmpPtr = basePath; + while (tmpPtr <= basePtr) + *bufPtr++ = *tmpPtr++; + + // And then copy on the rest of our path + XMLString::copyString(bufPtr, pathPtr); + + // Orphan the buffer and return it + janBuf.orphan(); + return tmpBuf; +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Private Static Methods +// --------------------------------------------------------------------------- + +// +// This method is called by the platform independent part of this class +// when client code asks to have one of the supported message sets loaded. +// + +XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) +{ + XMLMsgLoader* retVal; + try + { +#if defined (XML_USE_ICU_MESSAGELOADER) + retVal = new ICUMsgLoader(msgDomain); +#else + // same as -DXML_USE_INMEM_MESSAGELOADER + retVal = new InMemMsgLoader(msgDomain); +#endif + } + + catch(...) + { + panic(XMLPlatformUtils::Panic_CantLoadMsgDomain); + } + return retVal; +} + + +// +// This method is called very early in the bootstrapping process. This guy +// must create a transcoding service and return it. It cannot use any string +// methods, any transcoding services, throw any exceptions, etc... It just +// makes a transcoding service and returns it, or returns zero on failure. +// + +XMLTransService* XMLPlatformUtils::makeTransService() +{ +#if defined (XML_USE_ICU_TRANSCODER) + // Use ICU transcoding services. + // same as -DXML_USE_ICU_MESSAGELOADER + return new ICUTransService; +#else + // Use native transcoding services. + // same as -DXML_USE_INMEM_MESSAGELOADER + return new IconvTransService; + +#endif +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: The panic method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::panic(const PanicReasons reason) +{ + const char* reasonStr = "Unknown reason"; + if (reason == Panic_NoTransService) + reasonStr = "Could not load a transcoding service"; + else if (reason == Panic_NoDefTranscoder) + reasonStr = "Could not load a local code page transcoder"; + else if (reason == Panic_CantFindLib) + reasonStr = "Could not find the xerces-c DLL"; + else if (reason == Panic_UnknownMsgDomain) + reasonStr = "Unknown message domain"; + else if (reason == Panic_CantLoadMsgDomain) + reasonStr = "Cannot load message domain"; + else if (reason == Panic_SynchronizationErr) + reasonStr = "Cannot synchronize system or mutex"; + else if (reason == Panic_SystemInit) + reasonStr = "Cannot initialize the system or mutex"; + + fprintf(stderr, "%s\n", reasonStr); + + exit(-1); +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- + +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + int curPos = ftell( (FILE*)theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotGetSize); + + return (unsigned int)curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*)theFile)) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotCloseFile); +} + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*) theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotGetCurPos); + + // Seek to the end and save that value for return + if (fseek((FILE*) theFile, 0, SEEK_END)) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotSeekToEnd); + + long int retVal = ftell((FILE*)theFile); + if (retVal == -1) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotSeekToEnd); + + // And put the pointer back + + if (fseek( (FILE*)theFile, curPos, SEEK_SET) ) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotSeekToPos); + + return (unsigned int)retVal; +} + +FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName) +{ + const char* tmpFileName = XMLString::transcode(fileName); + ArrayJanitor<char> janText((char*)tmpFileName); + FileHandle retVal = (FILE*)fopen( tmpFileName , "rb" ); + + if (retVal == NULL) + return 0; + return retVal; +} + +FileHandle XMLPlatformUtils::openFile(const char* const fileName) +{ + FileHandle retVal = (FILE*)fopen( fileName , "rb" ); + + if (retVal == NULL) + return 0; + return retVal; +} + + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + return (FileHandle)fdopen(dup(0), "rb"); +} + + + +unsigned int +XMLPlatformUtils::readFileBuffer( FileHandle theFile + , const unsigned int toRead + , XMLByte* const toFill) +{ + size_t noOfItemsRead = fread((void*) toFill, 1, toRead, (FILE*)theFile); + + if(ferror((FILE*)theFile)) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotReadFromFile); + } + + return (unsigned int)noOfItemsRead; +} + + +void XMLPlatformUtils::resetFile(FileHandle theFile) +{ + // Seek to the start of the file + if (fseek((FILE*)theFile, 0, SEEK_SET)) + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::File_CouldNotResetFile); +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- + +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + // timeb aTime; + // ftime(&aTime); + struct timeval aTime; + gettimeofday(&aTime,NULL); + // return (unsigned long)(aTime.time*1000 + aTime.millitm); + return (unsigned long)(aTime.tv_sec*1000 + aTime.tv_usec); + +} + +XMLCh* XMLPlatformUtils::getFullPath(const XMLCh* const srcPath) +{ + + // + // NOTE: THe path provided has always already been opened successfully, + // so we know that its not some pathological freaky path. It comes in + // in native format, and goes out as Unicode always + // + char* newSrc = XMLString::transcode(srcPath); + ArrayJanitor<char> janText(newSrc); + + // Use a local buffer that is big enough for the largest legal path + char *absPath = new char[1024]; + // get the absolute path + char* retPath = realpath(newSrc, absPath); + ArrayJanitor<char> janText2(retPath); + + if (!retPath) + { + ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName); + } + return XMLString::transcode(absPath); +} + +bool XMLPlatformUtils::isRelative(const XMLCh* const toCheck) +{ + // Check for pathological case of empty path + if (!toCheck[0]) + return false; + + // + // If it starts with a slash, then it cannot be relative. This covers + // both something like "\Test\File.xml" and an NT Lan type remote path + // that starts with a node like "\\MyNode\Test\File.xml". + // + if (toCheck[0] == XMLCh('/')) + return false; + + // Else assume its a relative path + return true; +} + + +// ----------------------------------------------------------------------- +// Mutex methods +// ----------------------------------------------------------------------- + +#if !defined(APP_NO_THREADS) + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Platform init method +// --------------------------------------------------------------------------- + +static XMLMutex atomicOpsMutex; + +void XMLPlatformUtils::platformInit() +{ + // + // The atomicOps mutex needs to be created early. + // Normally, mutexes are created on first use, but there is a + // circular dependency between compareAndExchange() and + // mutex creation that must be broken. + + atomicOpsMutex.fHandle = XMLPlatformUtils::makeMutex(); +} + +void* XMLPlatformUtils::makeMutex() +{ + pthread_mutex_t* mutex = new pthread_mutex_t; + pthread_mutexattr_t* attr = new pthread_mutexattr_t; + pthread_mutexattr_init(attr); + pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); + if (pthread_mutex_init(mutex, attr)) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotCreate); + } + pthread_mutexattr_destroy(attr); + delete attr; + return (void*)(mutex); + +} + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (mtxHandle != NULL) + { + if (pthread_mutex_destroy((pthread_mutex_t*) mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotDestroy); + } + delete mtxHandle; + } +} + + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (mtxHandle != NULL) + { + if (pthread_mutex_lock((pthread_mutex_t*) mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotLock); + } + } +} + + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (mtxHandle != NULL) + { + if (pthread_mutex_unlock((pthread_mutex_t*) mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotUnlock); + } + } +} + + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- + +void* XMLPlatformUtils::compareAndSwap(void** toFill + , const void* const newValue + , const void* const toCompare) +{ + XMLMutexLock lockMutex(&atomicOpsMutex); + + void *retVal = *toFill; + if (*toFill == toCompare) + *toFill = (void *)newValue; + + return retVal; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +{ + XMLMutexLock localLock(&atomicOpsMutex); + + return ++location; +} + +int XMLPlatformUtils::atomicDecrement(int &location) +{ + XMLMutexLock localLock(&atomicOpsMutex); + + return --location; +} + +#else // #if !defined (APP_NO_THREADS) + +void XMLPlatformUtils::platformInit() +{ +} + +void* XMLPlatformUtils::makeMutex() +{ + return 0; +} + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ +} + +void* XMLPlatformUtils::compareAndSwap (void** toFill, + const void* const newValue, + const void* const toCompare) +{ + void *retVal = *toFill; + if (*toFill == toCompare) + *toFill = (void *)newValue; + return retVal; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +{ + return ++location; +} + +int XMLPlatformUtils::atomicDecrement(int &location) +{ + return --location; +} + +#endif // APP_NO_THREADS + +void XMLPlatformUtils::platformTerm() +{ + // We don't have any termination requirements at this time +} + diff -ruN xerces-c-src1_3_0/src/util/Platforms/Makefile.in freebsd/xerces-c-src1_3_0/src/util/Platforms/Makefile.in --- xerces-c-src1_3_0/src/util/Platforms/Makefile.in Thu Dec 23 05:57:52 1999 +++ xerces-c-src1_3_0/src/util/Platforms/Makefile.in Sat Dec 25 08:41:28 1999 @@ -127,6 +127,9 @@ ifeq (${PLATFORM}, LINUX) SUBMODULE = Linux endif +ifeq (${PLATFORM}, FREEBSD) + SUBMODULE = FreeBSD +endif ifeq (${PLATFORM}, HPUX) SUBMODULE = HPUX endif diff -ruN xerces-c-src1_3_0/src/util/XercesDefs.hpp freebsd/xerces-c-src1_3_0/src/util/XercesDefs.hpp --- xerces-c-src1_3_0/src/util/XercesDefs.hpp Thu Dec 23 05:57:28 1999 +++ xerces-c-src1_3_0/src/util/XercesDefs.hpp Sat Dec 25 08:41:28 1999 @@ -190,6 +190,10 @@ #include <util/Platforms/Linux/LinuxDefs.hpp> #endif +#if defined(XML_FREEBSD) +#include <util/Platforms/FreeBSD/FreeBSDDefs.hpp> +#endif + #if defined(XML_OS390) #include <util/Platforms/OS390/OS390Defs.hpp> #endif diff -uN xerces-c-src1_3_0/src/util/Transcoders/Iconv/IconvTransService.cpp xerces-c-src1_3_0/src/util/Transcoders/Iconv/IconvTransService.cpp --- xerces-c-src1_3_0/src/util/Transcoders/Iconv/IconvTransService.cpp Sat Sep 30 10:37:34 2000 +++ xerces-c-src1_3_0/src/util/Transcoders/Iconv/IconvTransService.cpp Tue Nov 28 08:35:48 2000 @@ -65,14 +65,26 @@ #include <util/XMLUniDefs.hpp> #include <util/XMLUni.hpp> #include "IconvTransService.hpp" +#if defined (FREEBSD) +#include <rune.h> +#include <stddef.h> +#include <ctype.h> // for the isspace function +#include <locale.h> // for the setlocale function +typedef unsigned int wint_t; +#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> +#if defined(FREEBSD_DEBUG) +#include <iostream.h> // gets cerr +#endif + // --------------------------------------------------------------------------- // Local, const data @@ -124,15 +136,15 @@ while ( (*cptr1 != 0) && (*cptr2 != 0) ) { - wint_t wch1 = towupper(*cptr1); - wint_t wch2 = towupper(*cptr2); + wint_t wch1 = toupper(*cptr1); + wint_t wch2 = toupper(*cptr2); if (wch1 != wch2) break; cptr1++; cptr2++; } - return (int) ( towupper(*cptr1) - towupper(*cptr2) ); + return (int) ( toupper(*cptr1) - toupper(*cptr2) ); } @@ -146,8 +158,8 @@ while ( (*cptr1 != 0) && (*cptr2 != 0) && (n < maxChars) ) { - wint_t wch1 = towupper(*cptr1); - wint_t wch2 = towupper(*cptr2); + wint_t wch1 = toupper(*cptr1); + wint_t wch2 = toupper(*cptr2); if (wch1 != wch2) break; @@ -155,7 +167,7 @@ cptr2++; n++; } - return (int) ( towupper(*cptr1) - towupper(*cptr2) ); + return (int) ( toupper(*cptr1) - toupper(*cptr2) ); } @@ -167,7 +179,7 @@ bool IconvTransService::isSpace(const XMLCh toCheck) const { - return (iswspace(toCheck) != 0); + return (isspace(toCheck) != 0); } @@ -208,7 +220,7 @@ XMLCh* outPtr = toUpperCase; while (*outPtr) { - *outPtr = towupper(*outPtr); + *outPtr = toupper(*outPtr); outPtr++; } } @@ -218,15 +230,73 @@ // --------------------------------------------------------------------------- // IconvLCPTranscoder: The virtual transcoder API // --------------------------------------------------------------------------- + +/* + wrappers from Mikko_Työläjärvi +*/ +#if defined(FREEBSD) +size_t +mbstowcs_wrapper(wchar_t *wcs, const char *s, size_t n) +{ +#if defined(FREEBSD_DEBUG) + cerr<<"(IconvTransServer.cpp) wrapper called with "<<s<<endl; +#endif + if (wcs == NULL) { +#if defined(FREEBSD_DEBUG) + cerr << "the destination pointer is null... generating length"<<endl; +#endif + n = strlen(s) + 1; + wcs = (wchar_t *)alloca(n * sizeof(wchar_t)); +#if defined(FREEBSD_DEBUG) + cerr<<"generated length of "<<n<<endl; +#endif + } + return mbstowcs(wcs, s, n); +} + +size_t +wcstombs_wrapper(char *s, wchar_t *wcs, size_t n) +{ + wchar_t *w; + + if (s == NULL) { + for (w=wcs; *w; w++) /* We have no wcslen() either... */ + ; + + n = (w - wcs) * 3 + 1; /* 3 is worst case on FreeBSD - could be 6 */ + s = (char *)alloca(n); + } + return wcstombs(s, wcs, n); +} +#endif + unsigned int IconvLCPTranscoder::calcRequiredSize(const char* const srcText) { if (!srcText) return 0; +#if defined(FREEBSD) + const unsigned int retVal = mbstowcs_wrapper(NULL,srcText,0); +#else const unsigned int retVal = ::mbstowcs(NULL, srcText, 0); +#endif - if (retVal == ~0) - return 0; +#if defined(FREEBSD_DEBUG) + cerr << "(IconvTransService.cpp) the string to be calculated is \"" + << srcText + << "\" and it's length is " << retVal << endl; +#endif + + //if (retVal == ~0){ + if (retVal == -1){ +#if defined(FREEBSD_DEBUG) + cerr << "(IconvTransService.cpp) the return value " << retVal + << " (originally matches ~0) " + << " and now matches -1" + << endl; +#endif + return 0; + } return retVal; } @@ -252,7 +322,13 @@ } wideCharBuf[wLent] = 0x00; +#if defined(FREEBSD) + const unsigned int retVal = wcstombs_wrapper(NULL,wideCharBuf,0); +#else const unsigned int retVal = ::wcstombs(NULL, wideCharBuf, 0); +#endif + + delete [] allocatedArray; if (retVal == ~0) @@ -263,8 +339,18 @@ char* IconvLCPTranscoder::transcode(const XMLCh* const toTranscode) { - if (!toTranscode) + if (!toTranscode){ +#if defined(FREEBSD_DEBUG) + cerr << "(IconvTransService.cpp) the string to be transcoded is NULL!!!" + << endl; +#endif return 0; + } + +#if defined(FREEBSD_DEBUG) + cerr << " (IconvTransService.cpp)the string to be transcoded is \"" + << toTranscode << "\""<< endl; +#endif char* retVal = 0; if (toTranscode) @@ -287,7 +373,14 @@ wideCharBuf[wLent] = 0x00; // Calc the needed size. +#if defined(FREEBSD) + const size_t neededLen = wcstombs_wrapper(NULL,wideCharBuf,0); +#else const size_t neededLen = ::wcstombs(NULL, wideCharBuf, 0); +#endif + + + if (neededLen == 0) { delete [] allocatedArray; @@ -354,16 +447,32 @@ } - XMLCh* IconvLCPTranscoder::transcode(const char* const toTranscode) { XMLCh* retVal = 0; if (toTranscode) { - const unsigned int len = calcRequiredSize(toTranscode); + unsigned int len = 0; + /* + this totally does not use the wchar stuff at all... + it assumes that the strings coming in are char + and the each char of the string can be cast to XMLCh + */ +#if !defined (FREEBSD) + len = calcRequiredSize(toTranscode); +#else + /* + FreeBSD can't seem to get the length from the string + see the mbstowcs_wrapper function for as close as i could get + (actually, we could probably use _wrapper to get the length + */ + len = strlen(toTranscode); +#endif + // make sure we got some output if (len == 0) return 0; +#if !defined (FREEBSD) wchar_t tmpWideCharArr[gTempBuffArraySize]; wchar_t* allocatedArray = 0; wchar_t* wideCharBuf = 0; @@ -375,12 +484,41 @@ ::mbstowcs(wideCharBuf, toTranscode, len); retVal = new XMLCh[len + 1]; +#else + /* + FreeBSD doesn't seem to do the work here very well + the goal is to set up the retVal pointer to be large enuff + to handle what needs to be transcoded + */ + retVal = new XMLCh[len]; +#endif + +#if defined(FREEBSD_DEBUG) + cerr<<"whole buffer looks like: "<<wideCharBuf<<endl; +#endif for (unsigned int i = 0; i < len; i++) { +#if defined(FREEBSD_DEBUG) + cerr<< "adding char "<<i<<" to retVal array: " + <<endl; +#endif + +#if !defined(FREEBSD) retVal[i] = (XMLCh) wideCharBuf[i]; +#else + /* + since the freebsd implementation currently doesn't have + a wideCharBuf to look at, just loop thru the toTranscode + array, and cast each char as an XMLCh + */ + retVal[i] = (XMLCh) toTranscode[i]; +#endif } retVal[len] = 0x00; + +#if !defined(FREEBSD) delete [] allocatedArray; +#endif } else { @@ -389,6 +527,7 @@ } return retVal; } + bool IconvLCPTranscoder::transcode( const char* const toTranscode diff -uN xerces-c-src1_3_0/src/internal/XMLScanner.cpp xerces-c-src1_3_0/src/internal/XMLScanner.cpp --- xerces-c-src1_3_0/src/internal/XMLScanner.cpp Sat Sep 30 10:37:28 2000 +++ xerces-c-src1_3_0/src/internal/XMLScanner.cpp Tue Nov 28 08:37:49 2000 @@ -88,7 +88,9 @@ #include <internal/XMLScanner.hpp> #include <internal/EndOfEntityException.hpp> - +#if defined(FREEBSD_DEBUG) +#include <iostream.h> // for cerr +#endif // --------------------------------------------------------------------------- // Local static data @@ -243,8 +245,25 @@ void XMLScanner::scanDocument( const char* const systemId , const bool reuseValidator) { - // We just delegate this to the XMLCh version after transcoding - XMLCh* tmpBuf = XMLString::transcode(systemId); +#if defined(FREEBSD_DEBUG) + //debug + cerr << "(XMLScanner.cpp:249) The systemId that is to be transcoded is " + << systemId + << " thank you" << endl; + //end debug +#endif + + // We just delegate this to the XMLCh version after transcoding + XMLCh* tmpBuf = XMLString::transcode(systemId); + +#if defined(FREEBSD_DEBUG) + //debug + cerr << "(XMLScanner.cpp) The systemId that has been transcoded is " + << tmpBuf + << " thank you" << endl; + //end debug +#endif + ArrayJanitor<XMLCh> janBuf(tmpBuf); scanDocument(tmpBuf, reuseValidator); } diff -uN xerces-c-src1_3_0/src/util/Compilers/Makefile.in ../try3_patch/public/xerces-c-src1_3_0/src/util/Compilers/Makefile.in --- xerces-c-src1_3_0/src/util/Compilers/Makefile.in Sat Sep 30 10:37:28 2000 +++ ../try3_patch/public/xerces-c-src1_3_0/src/util/Compilers/Makefile.in Tue Nov 28 19:30:53 2000 @@ -114,6 +114,9 @@ ifeq (${CXX},g++) CPP_OBJECTS = GCCDefs.$(TO) endif +ifeq (${CXX},/usr/local/egcs-1.1.2/bin/g++) + CPP_OBJECTS = GCCDefs.$(TO) +endif ifeq (${CXX},aCC) CPP_OBJECTS = HPCCDefs.$(TO) endif diff -uN xerces-c-src1_3_0/src/util/Compilers/GCCDefs.hpp xerces-c-src1_3_0/src/util/Compilers/GCCDefs.hpp --- xerces-c-src1_3_0/src/util/Compilers/GCCDefs.hpp Sat Sep 30 10:37:28 2000 +++ xerces-c-src1_3_0/src/util/Compilers/GCCDefs.hpp Mon Nov 27 10:59:04 2000 @@ -115,8 +115,8 @@ // Define our version of the XML character // --------------------------------------------------------------------------- // typedef unsigned short XMLCh; // is another option, now considered old -typedef wchar_t XMLCh; - +//typedef wchar_t XMLCh; +typedef unsigned short XMLCh; // test for freebsd // --------------------------------------------------------------------------- // Define unsigned 16 and 32 bits integers // --------------------------------------------------------------------------- diff -uN xerces-c-src1_3_0/src/util/XMLURL.cpp xerces-c-src1_3_0/src/util/XMLURL.cpp --- xerces-c-src1_3_0/src/util/XMLURL.cpp Sat Sep 30 10:37:34 2000 +++ xerces-c-src1_3_0/src/util/XMLURL.cpp Wed Nov 22 16:14:44 2000 @@ -807,7 +807,7 @@ void XMLURL::parse(const XMLCh* const urlText) { // Simplify things by checking for the psycho scenarios first - if (!*urlText) + if ((!urlText) || (!*urlText)) ThrowXML(MalformedURLException, XMLExcepts::URL_NoProtocolPresent); // --------------738FF325BE1652B734ACC55F Content-Type: application/x-sh; name="compile_xerces.sh" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="compile_xerces.sh" #!/bin/sh ## assumes that you have Xerces-FreeBSD-dv2.patch in current dir ## assumes that you have xerces-c-src1_3_0.tar.gz in one dir up ## assumes you want to run configure as ##./runConfigure -p freebsd -c gcc -x /usr/local/egcs-1.1.2/bin/g++ LOG="/tmp/Xerces.install.log" touch ${LOG} echo "*********************************************" echo " UNTARRING XERCES" echo "*********************************************" tar xvzf ../xerces-c-src1_3_0.tar.gz echo "*********************************************" echo " PATCHING XERCES" echo "*********************************************" patch -pf < Xerces-FreeBSD-dv2.patch bad=`find . -name "*rej" -print` if [ "x${bad}" != "x" ] ; then echo "problem patching: ${bad}" exit 1 else echo "patch succeeded" fi echo "*********************************************" echo " MISC SETUP" echo "*********************************************" cd xerces-c-src1_3_0 export XERCESCROOT=`pwd` cd src chmod 775 runConfigure echo "*********************************************" echo " CONFIGURING SETUP" echo "*********************************************" ./runConfigure -p freebsd -c gcc -x /usr/local/egcs-1.1.2/bin/g++ echo "*********************************************" echo " BUILDING XERCES" echo "*********************************************" gmake >& /tmp/gmake.final.out echo "*********************************************" echo " CONFIGURING SAMPLES" echo "*********************************************" cd ../samples chmod 775 runConfigure chmod 775 configure ## set ld_library_path ./runConfigure -p freebsd -c gcc -x /usr/local/egcs-1.1.2/bin/g++ gmake --------------738FF325BE1652B734ACC55F-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A267F8F.C5E97DFE>