diff --git a/Readme.html b/Readme.html new file mode 100644 index 0000000000000000000000000000000000000000..bf776c751060bf55d3fec4d2047445b6fc6c74f2 --- /dev/null +++ b/Readme.html @@ -0,0 +1,10 @@ +<HTML> +<HEAD> + <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> + <TITLE>XML4C2 Readme</TITLE> +</HEAD> +<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000000" VLINK="#000000" ALINK="#000000" onLoad="javascript:document.location='doc/index.html';return;"> +<CENTER><A HREF="doc/Index.html">Click here to read the XML4C documentation</A></CENTER> +THis file will be updated soon, or replaced with something for use in the Apache world. +</BODY> +</HTML> diff --git a/STATUS b/STATUS new file mode 100644 index 0000000000000000000000000000000000000000..1b2e9955af0014f213a869981802274418d94f65 --- /dev/null +++ b/STATUS @@ -0,0 +1,26 @@ +Xerces-c status 8-Nov-99 + +This drop of Xerces-c is based on a development version of the IBM XML4C +version 3.0 code base. + +It is a snapshot of development work in progress, and is known +to contain incompletely implemented features and bugs. +This code base (8-Nov-99) builds on Linux and Windows. + +The code base is newer than that last released on IBM's alphaworks +site, and includes these new features. + + +o Namespace support +o Core and Traversal from DOM Level 2 +o Better conformance to XML specifications +o Ability to use for any transcoding service +o Restructured in preparation for Schema support. + +To do + +o More of DOM level 2, including Events and Ranges. +o More platforms supported. +o Schema, as it becomes better defined by the W3C. +o Tuning +o Improved build structure diff --git a/credits.txt b/credits.txt new file mode 100644 index 0000000000000000000000000000000000000000..e88a0bd1b6758cdda49842506e036b56ccf0e684 --- /dev/null +++ b/credits.txt @@ -0,0 +1,24 @@ +The following people (in alphabetical order) have contributed to the +development and ports of the XML4C source code, which was submitted to +the Apache Software Foundation. + + +Andy Clark +Andy Heninger +Andy Levine +Anupam Bagchi +Arundhati Bhowmick +Chih Hsiang Chou +Dean Roddey +Gereon Steffens +Glenn Marcy +John Bellardo +Michael Ottati +Mike Pogue +Paul Ferguson +Rahul Jain +Ralf Pfeiffer +Roger Webster +Steven Rosenthal +Ted Leung +Tom Watson diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..ffd2545c5405b2d6f75018bc88a86dff24eb7ca5 --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,315 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:02:54 twl +# Initial revision +# +# Revision 1.4 1999/11/08 22:36:39 anupam +# Removed the overrided definition of XML4CROOT +# +# Revision 1.3 1999/11/08 20:44:09 rahul +# Swat for adding in Product name and CVS comment log variable. +# +# + +################################################################### +# IMPORTANT NOTE # +################################################################### +# Before you try to run the Makefile, make sure you have two # +# environment variables set. # +# # +# export XML4CROOT=<the directory where you installed XML4C> # +# export ICUROOT=<the directory where you installed ICU> # +# # +# Also, to enable debugging, you must type: # +# export DEBUG=1 # +# To disable debugging, you must type: # +# unset DEBUG # +################################################################### +#MACROS defining commands +MKDIR=mkdir +CP=cp +CD=cd +RM=rm +CHMODE=chmod + +UTIL_DIR = util +SAX_DIR = sax +INTERNAL_DIR = internal +FRAMEWORK_DIR = framework +DOM_DIR = dom +PARSERS_DIR = parsers +VALIDATORS_DTD_DIR = validators/DTD +ALL_OBJECTS_DIR = ${XML4CROOT}/obj +LIB_DIR = ${XML4CROOT}/lib + +LIB = ${XML4CROOT}/lib +LIBNAME = libIXXML4C +THISLIB = ${LIB}/${LIBNAME} +VER = 3_0 + +ALL_OBJECTS = $(wildcard ${ALL_OBJECTS_DIR}/*.o) + +#all these setting come from the arguments passed in to runConfigure. +PLATFORM = @platform@ +COMPILER = @compiler@ +PREFIX = @prefix@ +MESSAGELOADER=@messageloader@ +TRANSCODER=@transcoder@ + +PRODUCTNAME=xerces +PRODUCTVERSION=${VER} +BINTARGETDIR=${HOME}/${PRODUCTNAME}-c-${PLATFORM}-${COMPILER}-${PRODUCTVERSION} + +all: Prepare Util Sax Internal Framework Parsers Dom Validators ${THISLIB}${VER}${SHLIBSUFFIX} + +compile: Prepare Util Sax Internal Framework Parsers Dom Validators + +lib: compile ${THISLIB}${VER}${SHLIBSUFFIX} + +Prepare: + @echo Preparing the directory structure for a build ... + -${MKDIR} -p ${ALL_OBJECTS_DIR} + -${MKDIR} -p ${LIB_DIR} + ${CD} $(UTIL_DIR) ; $(MAKE) includes ; ${CD} .. + ${CD} $(SAX_DIR) ; $(MAKE) includes ; ${CD} .. + ${CD} $(INTERNAL_DIR) ; $(MAKE) includes ; ${CD} .. + ${CD} $(FRAMEWORK_DIR) ; $(MAKE) includes ; ${CD} .. + ${CD} $(PARSERS_DIR) ; $(MAKE) includes ; ${CD} .. + ${CD} $(VALIDATORS_DTD_DIR) ; $(MAKE) includes ; ${CD} ../.. + ${CD} $(DOM_DIR) ; $(MAKE) includes ; ${CD} .. + +Util: + @echo Building "util" + ${CD} $(UTIL_DIR) ; $(MAKE) $(MAKE_FLAGS) ; ${CD} .. + +Sax: + @echo Building "sax" + ${CD} $(SAX_DIR) ; $(MAKE) $(MAKE_FLAGS) ; ${CD} .. + +Internal: + @echo Building "internal" + ${CD} $(INTERNAL_DIR) ; $(MAKE) $(MAKE_FLAGS) ; ${CD} .. + +Framework: + @echo Building "framework" + ${CD} $(FRAMEWORK_DIR) ; $(MAKE) $(MAKE_FLAGS) ; ${CD} .. + +Parsers: + @echo Building "parsers" + ${CD} $(PARSERS_DIR) ; $(MAKE) $(MAKE_FLAGS) ; ${CD} .. + +Dom: + @echo Building "dom" + ${CD} $(DOM_DIR) ; $(MAKE) $(MAKE_FLAGS) ; ${CD} .. + +Validators: + @echo Building "validators" + ${CD} $(VALIDATORS_DTD_DIR) ; $(MAKE) $(MAKE_FLAGS) ; ${CD} ../.. + +${THISLIB}${VER}${SHLIBSUFFIX}: + @echo Building ${THISLIB}${VER}${SHLIBSUFFIX} + ${CD} $(ALL_OBJECTS_DIR) ; $(MAKE) -k $(MAKE_FLAGS) ; ${CD} .. + +install: + ${CD} $(UTIL_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(SAX_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(INTERNAL_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(FRAMEWORK_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(PARSERS_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(DOM_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(VALIDATORS_DTD_DIR) && $(MAKE) $@ && ${CD} ../.. + ${CD} $(ALL_OBJECTS_DIR) && $(MAKE) $@ && ${CD} .. + +clean: + ${CD} $(UTIL_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(SAX_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(INTERNAL_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(FRAMEWORK_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(PARSERS_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(DOM_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(VALIDATORS_DTD_DIR) && $(MAKE) $@ && ${CD} ../.. + ${CD} $(ALL_OBJECTS_DIR) && $(MAKE) $@ && ${CD} .. + +distclean: + ${CD} $(UTIL_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(SAX_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(INTERNAL_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(FRAMEWORK_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(PARSERS_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(DOM_DIR) && $(MAKE) $@ && ${CD} .. + ${CD} $(VALIDATORS_DTD_DIR) && $(MAKE) $@ && ${CD} ../.. + ${CD} $(ALL_OBJECTS_DIR) && $(MAKE) $@ && ${CD} .. + rm -f Makefile config.cache config.log config.status + rm -f *~ core + +#docs: + +samples: + ${CD} ../samples; ${MAKE}; ${CD} ../src + +copy: lib samples + @echo Make the target directory and its main subdirectories + -${MKDIR} ${BINTARGETDIR} + -${MKDIR} ${BINTARGETDIR}/bin + -${MKDIR} ${BINTARGETDIR}/lib +ifeq (${TRANSCODER},ICU) + echo -${MKDIR} ${BINTARGETDIR}/lib/icu + echo -${MKDIR} ${BINTARGETDIR}/lib/icu/data + echo -${MKDIR} ${BINTARGETDIR}/include/icu +endif +ifeq (${MESSAGELOADER},ICU) + echo -${MKDIR} ${BINTARGETDIR}/include/icu +endif + -${MKDIR} ${BINTARGETDIR}/include + -${MKDIR} ${BINTARGETDIR}/include/sax + -${MKDIR} ${BINTARGETDIR}/include/framework + -${MKDIR} ${BINTARGETDIR}/include/internal + -${MKDIR} ${BINTARGETDIR}/include/parsers + -${MKDIR} ${BINTARGETDIR}/include/util + -${MKDIR} ${BINTARGETDIR}/include/dom + + -${MKDIR} ${BINTARGETDIR}/samples + -${MKDIR} ${BINTARGETDIR}/samples/data + -${MKDIR} ${BINTARGETDIR}/samples/SAXCount + -${MKDIR} ${BINTARGETDIR}/samples/SAXPrint + -${MKDIR} ${BINTARGETDIR}/samples/DOMCount + -${MKDIR} ${BINTARGETDIR}/samples/DOMPrint + -${MKDIR} ${BINTARGETDIR}/samples/Redirect + -${MKDIR} ${BINTARGETDIR}/samples/MemParse + -${MKDIR} ${BINTARGETDIR}/doc + -${MKDIR} ${BINTARGETDIR}/doc/apiDocs + + @echo Populate the include output directory + @echo Copying headers files ... + -${CP} -Rf ${XML4CROOT}/src/sax/*.hpp ${BINTARGETDIR}/include/sax + -${CP} -Rf ${XML4CROOT}/src/framework/*.hpp ${BINTARGETDIR}/include/framework + -${CP} -Rf ${XML4CROOT}/src/dom/DOM*.hpp ${BINTARGETDIR}/include/dom + -${CP} -Rf ${XML4CROOT}/src/internal/*.hpp ${BINTARGETDIR}/include/internal + -${CP} -Rf ${XML4CROOT}/src/internal/*.c ${BINTARGETDIR}/include/internal + -${CP} -Rf ${XML4CROOT}/src/parsers/*.hpp ${BINTARGETDIR}/include/parsers + -${CP} -Rf ${XML4CROOT}/src/util/*.hpp ${BINTARGETDIR}/include/util + -${CP} -Rf ${XML4CROOT}/src/util/*.c ${BINTARGETDIR}/include/util + -${CP} -Rf ${ICUROOT}/include/* ${BINTARGETDIR}/include/icu + + @echo Populate the binary output directory + @echo Copying binary outputs ... + -${CP} -Rf ${XML4CROOT}/bin/* ${BINTARGETDIR}/bin + -${CP} -f ${ICUROOT}/source/tools/makeconv/makeconv ${BINTARGETDIR}/bin + -${CP} -f ${ICUROOT}/lib/libicu-uc.* ${BINTARGETDIR}/lib + -${CP} -f ${XML4CROOT}/lib/*.a ${BINTARGETDIR}/lib + -${CP} -f ${XML4CROOT}/lib/*.so ${BINTARGETDIR}/lib + -${CP} -f ${XML4CROOT}/lib/*.sl ${BINTARGETDIR}/lib + + -{RM} -rf ${BINTARGETDIR}/bin/obj + + @echo Copy the locale files + -${CP} -f ${ICUROOT}/data/*.cnv ${BINTARGETDIR}/lib/icu/data/ + -${CP} -f ${ICUROOT}/data/convrtrs.txt ${BINTARGETDIR}/lib/icu/data/ + + @echo Populate the samples directory + @echo Copying sample files ... + -${CP} -f ${XML4CROOT}/samples/config.guess ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/config.h.in ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/config.sub ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/configure ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/configure.in ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/install-sh ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/runConfigure ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/Makefile.in ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/Makefile.incl ${BINTARGETDIR}/samples + -${CP} -f ${XML4CROOT}/samples/Maefile ${BINTARGETDIR}/samples + + -${CP} -Rf ${XML4CROOT}/samples/data/* ${BINTARGETDIR}/samples/data + -${CP} -Rf ${XML4CROOT}/samples/SAXCount/* ${BINTARGETDIR}/samples/SAXCount + -${CP} -Rf ${XML4CROOT}/samples/SAXPrint/* ${BINTARGETDIR}/samples/SAXPrint + -${CP} -Rf ${XML4CROOT}/samples/DOMCount/* ${BINTARGETDIR}/samples/DOMCount + -${CP} -Rf ${XML4CROOT}/samples/DOMPrint/* ${BINTARGETDIR}/samples/DOMPrint + -${CP} -Rf ${XML4CROOT}/samples/Redirect/* ${BINTARGETDIR}/samples/Redirect + -${CP} -Rf ${XML4CROOT}/samples/MemParse/* ${BINTARGETDIR}/samples/MemParse + + @echo Populate the docs directory + @echo Copying documentation .. + -${CP} -Rf ${XML4CROOT}/doc/* ${BINTARGETDIR}/doc + -${CP} -Rf ${XML4CROOT}/doc/apiDocs/* ${BINTARGETDIR}/doc/apiDocs + -${CP} ${XML4CROOT}/Readme.html ${BINTARGETDIR} + -${CP} ${XML4CROOT}/doc/license.html ${BINTARGETDIR} + + @echo Change the directory permissions + -{CHMODE} 644 `find ${BINTARGETDIR} -type f` + -{CHMODE} 755 ${BINTARGETDIR}/bin/* ${BINTARGETDIR}/lib/*.sl ${BINTARGETDIR}/lib/*.so ${BINTARGETDIR}/lib/*.a + -{CHMODE} +x ${BINTARGETDIR}/samples/runConfigure ${BINTARGETDIR}/samples/configure ${BINTARGETDIR}/samples/install-sh + -{CHMODE} +x ${BINTARGETDIR}/samples/config.sub ${BINTARGETDIR}/samples/config.guess ${BINTARGETDIR}/samples/config.status + -{CHMODE} 755 `find ${BINTARGETDIR} -type d` + +tarball: copy + @echo Now package it all up using tar + @echo TARing up all files ... + ${CD} ${BINTARGETDIR}/.. + tar -cvf ${BINTARGETDIR}.tar ${BINTARGETDIR} + @echo Finally compress the files + @echo Compressing ${BINTARGETDIR}.tar ... + gzip ${BINTARGETDIR}.tar + +zip: copy + ${CD} ${BINTARGETDIR}/.. + @echo ZIPping up all files ... + zip -r ${BINTARGETDIR}.zip ${BINTARGETDIR} + + +package_bin: zip tarball + diff --git a/src/Makefile.incl b/src/Makefile.incl new file mode 100644 index 0000000000000000000000000000000000000000..b4463e550eceb2da533e34d2a296900ac0ec65f3 --- /dev/null +++ b/src/Makefile.incl @@ -0,0 +1,328 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:02:55 twl +# Initial revision +# +# Revision 1.4 1999/11/08 20:44:09 rahul +# Swat for adding in Product name and CVS comment log variable. +# +# + +################################################################### +# IMPORTANT NOTE # +################################################################### +# Before you try to run the Makefile, make sure you have set # +# the following environment variables properly. # +# # +# export XML4CROOT=<the directory where you installed XML4C> # +# # +# In case you intend to use either the ICU transcoder or the # +# ICU message loader, you must set ICUROOT correctly. # +# export ICUROOT=<the directory where you installed ICU> # +# # +# For netaccessor, if you intend to use libwww, then you must # +# also set another environment variable called LIBWWWROOT # +# export LIBWWWROOT=<the directory where you installed libwww> # +################################################################### + +################################################################### +# SPECIAL INSTRUCTIONS FOR OS/390 BATCH MODE # +################################################################### +# If you are going to do the OS390BATCH build, make sure you have # +# the OS390BATCH environment variable set. # +# # +# export OS390BATCH=1 # +# # +# Also, search for the LOADMOD variable and set it to your # +# LOADMOD dataset. Make sure you have at least UPDATE access to # +# the dataset. # +################################################################### + +ALL: all + +ALL_OBJECTS_DIR = ${XML4CROOT}/obj + +XML_BUILD_OPTIONS = ${CXXFLAGS} + +####################### PLATFORM DEPENDENCIES ##################### + +#=============== SOLARIS SPECIFIC OPTIONS ========================= +ifeq (${PLATFORM}, SOLARIS) + ifeq (${COMPILER}, g++) + PLATFORM_CPP_COMPILER = g++ + PLATFORM_C_COMPILER = gcc + PLATFORM_LIBRARIES=-L/usr/lib -L/usr/local/lib -L/usr/ccs/lib + PLATFORM_COMPILE_OPTIONS = -fPIC -instances=static -D${PLATFORM} -D_REENTRANT + MAKE_SHARED = ${PLATFORM_CPP_COMPILER} -D${PLATFORM} -shared + MAKE_SHARED_C = ${PLATFORM_C_COMPILER} -D${PLATFORM} -shared + EXTRA_LINK_OPTIONS = -lm -lw -lgen + else + PLATFORM_CPP_COMPILER = CC + PLATFORM_C_COMPILER = cc + PLATFORM_LIBRARIES=-L/usr/local/SUNWspro/lib -L/usr/ccs/lib + PLATFORM_COMPILE_OPTIONS = -KPIC -mt -xs -instances=static -features=rtti -D${PLATFORM} -D_REENTRANT + MAKE_SHARED = ${PLATFORM_CPP_COMPILER} -D${PLATFORM} -G + MAKE_SHARED_C = ${PLATFORM_C_COMPILER} -D${PLATFORM} -G + EXTRA_LINK_OPTIONS = -lm -lw -lC -lc -lgen + endif + SHLIBSUFFIX=.so +endif + +#================= AIX SPECIFIC OPTIONS =========================== +ifeq (${PLATFORM}, AIX) +PLATFORM_CPP_COMPILER = xlC_r +PLATFORM_C_COMPILER = xlc_r +ifdef ICUROOT + PLATFORM_LIBRARIES=-L/usr/lpp/xlC/lib -L${ICUROOT}/lib + EXTRA_LINK_OPTIONS = -licu-uc -lbsd +else + PLATFORM_LIBRARIES=-L/usr/lpp/xlC/lib + EXTRA_LINK_OPTIONS = -lbsd +endif +PLATFORM_COMPILE_OPTIONS = -qnotempinc -D_THREAD_SAFE +MAKE_SHARED = makeC++SharedLib_r -p 5000 +MAKE_SHARED_C = makeC++SharedLib_r -p 5000 +SHLIBSUFFIX=.a +endif + +#=============== LINUX SPECIFIC OPTIONS ========================= +ifeq (${PLATFORM}, LINUX) +PLATFORM_CPP_COMPILER = g++ +PLATFORM_C_COMPILER = gcc +PLATFORM_LIBRARIES=-L/usr/lib -L/usr/local/lib -L/usr/ccs/lib +PLATFORM_COMPILE_OPTIONS = -fpic -instances=static -D${PLATFORM} -D_REENTRANT +MAKE_SHARED = ${PLATFORM_CPP_COMPILER} -D${PLATFORM} -shared -fpic +MAKE_SHARED_C = ${PLATFORM_C_COMPILER} -D${PLATFORM} -shared -fpic +EXTRA_LINK_OPTIONS = -lc +SHLIBSUFFIX=.so +endif + +#=============== OS2 SPECIFIC OPTIONS ========================= +ifeq (${PLATFORM}, OS/2) +PLATFORM_CPP_COMPILER = icc +PLATFORM_C_COMPILER = icc +PLATFORM_LIBRARIES= CPPOM30.LIB os2386.lib mmpm2.lib +PLATFORM_COMPILE_OPTIONS = /C+ /Gd- /Ge- /Gm+ /Gs- /Re /J+ /Ms /Sm /Sn /Ss+ +MAKE_SHARED = ilink /nofree +MAKE_SHARED_C = ilink /nofree +EXTRA_LINK_OPTIONS = /map /nod /noe /noi /packcode /packdata /exepack /align:4 +SHLIBSUFFIX= .dll +ifneq (${DEBUG}, 1) +XML_BUILD_OPTIONS = -2 +endif +endif + +#================= HP SPECIFIC OPTIONS =========================== +#ifeq (${PLATFORM}, HPUX) +# ifeq (${COMPILER}, aCC) +# PLATFORM_CPP_COMPILER = aCC +# PLATFORM_C_COMPILER = aCC +# PLATFORM_LIBRARIES=-L/opt/aCC/lib -L/usr/ccs/lib +# PLATFORM_COMPILE_OPTIONS = $(COMPILESWITCH) -D_HP_UX -DHPaCC -D_PTHREADS_DRAFT4 \ +# +DAportable -w +z +inst_compiletime +# MAKE_SHARED = ${PLATFORM_CPP_COMPILER} -D${PLATFORM} -b +# MAKE_SHARED_C = ${PLATFORM_C_COMPILER} -D${PLATFORM} -b +# EXTRA_LINK_OPTIONS = -lcma -lCsup -lstream +# SHLIBSUFFIX=.sl +# else +# ifneq (${DEBUG}, 1) +# XML_BUILD_OPTIONS = -w +O1 +# endif +# PLATFORM_CPP_COMPILER = CC +# PLATFORM_C_COMPILER = cc +# PLATFORM_LIBRARIES= -L${ICUROOT}/lib -L/opt/CC/lib -L/usr/lib +# TEMPLATESREPOSITORY = ${ALL_OBJECTS_DIR}/ptrepository +# COMMON_COMPILE_OPTIONS = $(COMPILESWITCH) -D_HP_UX -DXML4C_TMPLSINC \ +# -D_PTHREADS_DRAFT4 +DAportable -w +eh +z -z +a1 +# ifeq ($(MODULE), dom) +# PLATFORM_COMPILE_OPTIONS = -DDOM_PROJ $(COMMON_COMPILE_OPTIONS) +# else +# PLATFORM_COMPILE_OPTIONS = $(COMMON_COMPILE_OPTIONS) -ptr${TEMPLATESREPOSITORY} +# endif +# ALLINCLUDES= -I$(XML4CROOT)/src -I$(ICUROOT)/include +# MAKE_SHARED = $(PLATFORM_CPP_COMPILER) $(PLATFORM_COMPILE_OPTIONS) $(ALLINCLUDES) +# MAKE_SHARED_C = $(PLATFORM_C_COMPILER) $(PLATFORM_COMPILE_OPTIONS) $(ALLINCLUDES) +# ALLLIBS = -licu-uc -lcma -lm +# EXTRA_LINK_OPTIONS = -b -Wl,+s -Wl,-a,shared +# SHLIBSUFFIX=.sl +# endif +#endif + +ifeq (${PLATFORM}, HPUX) + + OSVERDEFINE=HPUX11 + ifeq (${OSVER}, HPUX10) + OSVERDEFINE=HPUX10 + endif + + ifeq (${COMPILER}, aCC) + PLATFORM_CPP_COMPILER = aCC + PLATFORM_C_COMPILER = aCC + PLATFORM_COMPILE_OPTIONS = $(COMPILESWITCH) -D_HP_UX -DHPaCC \ + -D_PTHREADS_DRAFT4 -D${OSVERDEFINE} +DAportable -w +z \ + +inst_compiletime + MAKE_SHARED = ${PLATFORM_CPP_COMPILER} -D${PLATFORM} -b + MAKE_SHARED_C = ${PLATFORM_C_COMPILER} -D${PLATFORM} -b + ALLLIBS = -lcma -lCsup -lstream + SHLIBSUFFIX=.sl + else + ifneq (${DEBUG}, 1) + XML_BUILD_OPTIONS = -w +O1 + endif + PLATFORM_CPP_COMPILER = CC + PLATFORM_C_COMPILER = cc +ifdef ICUROOT + PLATFORM_LIBRARIES= -L${ICUROOT}/lib +endif + TEMPLATESREPOSITORY = ${ALL_OBJECTS_DIR}/ptrepository + COMMON_COMPILE_OPTIONS = $(COMPILESWITCH) -D_HP_UX -DXML4C2_TMPLSINC \ + -D_PTHREADS_DRAFT4 -D${OSVERDEFINE} +DAportable -w +eh +z -z +a1 + ifeq ($(MODULE), dom) + PLATFORM_COMPILE_OPTIONS = -DDOM_PROJ $(COMMON_COMPILE_OPTIONS) + else + PLATFORM_COMPILE_OPTIONS = $(COMMON_COMPILE_OPTIONS) -ptr${TEMPLATESREPOSITORY} + endif +ifdef ICUROOT + ALLINCLUDES=-I$(XML4CROOT)/src/com/ibm/xml -I$(XML4CROOT)/src -I$(ICUROOT)/include +else + ALLINCLUDES=-I$(XML4CROOT)/src/com/ibm/xml -I$(XML4CROOT)/src +endif + MAKE_SHARED = $(PLATFORM_CPP_COMPILER) $(PLATFORM_COMPILE_OPTIONS) $(ALLINCLUDES) + MAKE_SHARED_C = $(PLATFORM_C_COMPILER) $(PLATFORM_COMPILE_OPTIONS) $(ALLINCLUDES) + ALLLIBS = -licu-uc -lcma -lm + EXTRA_LINK_OPTIONS = -b -Wl,+s -Wl,-a,shared + SHLIBSUFFIX=.sl + endif +endif + + +#================ OS/390 SPECIFIC OPTIONS ========================= +ifeq (${PLATFORM}, OS390) +PLATFORM_CPP_COMPILER = _CXX_CXXSUFFIX="cpp" _CXX_STEPS="-1" c++ +PLATFORM_C_COMPILER = _CXX_CXXSUFFIX="cpp" _CXX_STEPS="-1" cc +PLATFORM_LIBRARIES= +## OS390BATCH +ifeq (${OS390BATCH},1) +PLATFORM_COMPILE_OPTIONS =-Wc,dll,expo -W0,"langlvl(extended)" -D${PLATFORM} -D_OPEN_THREADS -D_XOPEN_SOURCE_EXTENDED -DOS390BATCH +else +PLATFORM_COMPILE_OPTIONS =-Wc,dll,expo -W0,"langlvl(extended)" -D${PLATFORM} -D_OPEN_THREADS -D_XOPEN_SOURCE_EXTENDED +endif +MAKE_SHARED = ${PLATFORM_CPP_COMPILER} -D${PLATFORM} -W l,dll +MAKE_SHARED_C = ${PLATFORM_C_COMPILER} -D${PLATFORM} -W l,dll +## OS390BATCH +ifeq (${OS390BATCH},1) +LOADMOD = USERID.LOAD +LOADEXP = USERID.EXP +ALLLIBS = "//'${LOADEXP}(ICUUC)'" +else +ALLLIBS = ${ICUROOT}/lib/libicu-uc.x +endif +EXTRA_LINK_OPTIONS = +SHLIBSUFFIX=.dll +OS390SIDEDECK=.x +ifneq (${DEBUG}, 1) + XML_BUILD_OPTIONS = -2 +endif +endif + +###################### STANDARD TOOLS ############################# +CP = -cp -fp +RM = -rm -f +CAT = cat +AR = ar -cqv +CD = cd +CC1 = ${PLATFORM_CPP_COMPILER} ${PLATFORM_COMPILE_OPTIONS} +JUST_CC = ${PLATFORM_C_COMPILER} -D${PLATFORM} +ECHO = echo +CREATE_DEPENDS_FILE = echo "" > depends +MAKE_DEPEND = ${CC1} -E -xM + +########################## DIRECTORIES ############################ +XML_LIB_DIR = $(XML4CROOT)/lib +XML_INC_DIR = $(XML4CROOT)/include +ifeq (${MESSAGELOADER}, ICU) + INTL_INC_DIR1 = $(ICUROOT)/include +endif +ifeq (${TRANSCODER}, ICU) + INTL_INC_DIR1 = $(ICUROOT)/include +endif + +#################### COMPILE/LINK FLAGS ########################### +ifeq (${MESSAGELOADER}, ICU) + XML_INCL = -I. -I$(XML_INC_DIR) -I$(INTL_INC_DIR1) +else + ifeq (${TRANSCODER}, ICU) + XML_INCL = -I. -I$(XML_INC_DIR) -I$(INTL_INC_DIR1) + else + XML_INCL = -I. -I$(XML_INC_DIR) + endif +endif + +##################### HELPER MACROS ############################### +DEPFILE = depends +LINKLIB = $(XML_LIB_DIR) + +######################### SUFFIX RULES ############################ +.SUFFIXES: +.SUFFIXES: .cpp .c .o + +.cpp.o: + $(CC1) -c $(XML_BUILD_OPTIONS) $(XML_DEF) $(XML_INCL) $(EXTRA_COMPILE_OPTIONS) -o $(@) $(<) + +.c.o: + $(JUST_CC) -c $(XML_BUILD_OPTIONS) $(XML_DEF) $(XML_INCL) $(EXTRA_COMPILE_OPTIONS) -o $(@) $(<) diff --git a/src/config.guess b/src/config.guess new file mode 100644 index 0000000000000000000000000000000000000000..0711ac8cc9a617d8ee1e36e5931dce07272a7c37 --- /dev/null +++ b/src/config.guess @@ -0,0 +1,977 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Written by Per Bothner <bothner@cygnus.com>. +# The master version of this file is at the FSF in /home/gd/gnu/lib. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit system type (host/target name). +# +# Only a few systems have been added to this list; please add others +# (but try to keep the structure clean). +# + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 8/24/94.) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +dummy=dummy-$$ +trap 'rm -f $dummy.c $dummy.o $dummy; exit 1' 1 2 15 + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + alpha:OSF1:*:*) + if test $UNAME_RELEASE = "V4.0"; then + UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + fi + # A Vn.n version is a released version. + # A Tn.n version is a released field test version. + # A Xn.n version is an unreleased experimental baselevel. + # 1.2 uses "1.2" for uname -r. + cat <<EOF >$dummy.s + .globl main + .ent main +main: + .frame \$30,0,\$26,0 + .prologue 0 + .long 0x47e03d80 # implver $0 + lda \$2,259 + .long 0x47e20c21 # amask $2,$1 + srl \$1,8,\$2 + sll \$2,2,\$2 + sll \$0,3,\$0 + addl \$1,\$0,\$0 + addl \$2,\$0,\$0 + ret \$31,(\$26),1 + .end main +EOF + ${CC-cc} $dummy.s -o $dummy 2>/dev/null + if test "$?" = 0 ; then + ./$dummy + case "$?" in + 7) + UNAME_MACHINE="alpha" + ;; + 15) + UNAME_MACHINE="alphaev5" + ;; + 14) + UNAME_MACHINE="alphaev56" + ;; + 10) + UNAME_MACHINE="alphapca56" + ;; + 16) + UNAME_MACHINE="alphaev6" + ;; + esac + fi + rm -f $dummy.s $dummy + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr [[A-Z]] [[a-z]]` + exit 0 ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit 0 ;; + Amiga*:UNIX_System_V:4.0:*) + echo m68k-cbm-sysv4 + exit 0;; + amiga:NetBSD:*:*) + echo m68k-cbm-netbsd${UNAME_RELEASE} + exit 0 ;; + amiga:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + *:[Aa]miga[Oo][Ss]:*:*) + echo ${UNAME_MACHINE}-unknown-amigaos + exit 0 ;; + arc64:OpenBSD:*:*) + echo mips64el-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + hkmips:OpenBSD:*:*) + echo mips-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + pmax:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sgi:OpenBSD:*:*) + echo mips-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + wgrisc:OpenBSD:*:*) + echo mipsel-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit 0;; + arm32:NetBSD:*:*) + echo arm-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + exit 0 ;; + SR2?01:HI-UX/MPP:*:*) + echo hppa1.1-hitachi-hiuxmpp + exit 0;; + Pyramid*:OSx*:*:*|MIS*:OSx*:*:*|MIS*:SMP_DC-OSx*:*:*) + # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit 0 ;; + NILE:*:*:dcosx) + echo pyramid-pyramid-svr4 + exit 0 ;; + sun4H:SunOS:5.*:*) + echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + i86pc:SunOS:5.*:*) + echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit 0 ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit 0 ;; + sun*:*:4.2BSD:*) + UNAME_RELEASE=`(head -1 /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 + case "`/bin/arch`" in + sun3) + echo m68k-sun-sunos${UNAME_RELEASE} + ;; + sun4) + echo sparc-sun-sunos${UNAME_RELEASE} + ;; + esac + exit 0 ;; + aushp:SunOS:*:*) + echo sparc-auspex-sunos${UNAME_RELEASE} + exit 0 ;; + atari*:NetBSD:*:*) + echo m68k-atari-netbsd${UNAME_RELEASE} + exit 0 ;; + atari*:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sun3*:NetBSD:*:*) + echo m68k-sun-netbsd${UNAME_RELEASE} + exit 0 ;; + sun3*:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:NetBSD:*:*) + echo m68k-apple-netbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme68k:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + mvme88k:OpenBSD:*:*) + echo m88k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + powerpc:machten:*:*) + echo powerpc-apple-machten${UNAME_RELEASE} + exit 0 ;; + macppc:NetBSD:*:*) + echo powerpc-apple-netbsd${UNAME_RELEASE} + exit 0 ;; + RISC*:Mach:*:*) + echo mips-dec-mach_bsd4.3 + exit 0 ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + 2020:CLIX:*:*) + echo clipper-intergraph-clix${UNAME_RELEASE} + exit 0 ;; + mips:*:*:UMIPS | mips:*:*:RISCos) + sed 's/^ //' << EOF >$dummy.c + int main (argc, argv) int argc; char **argv; { + #if defined (host_mips) && defined (MIPSEB) + #if defined (SYSTYPE_SYSV) + printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_SVR4) + printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); + #endif + #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) + printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); + #endif + #endif + exit (-1); + } +EOF + ${CC-cc} $dummy.c -o $dummy \ + && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo mips-mips-riscos${UNAME_RELEASE} + exit 0 ;; + Night_Hawk:Power_UNIX:*:*) + echo powerpc-harris-powerunix + exit 0 ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit 0 ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit 0 ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit 0 ;; + AViiON:dgux:*:*) + # DG/UX returns AViiON for all architectures + UNAME_PROCESSOR=`/usr/bin/uname -p` + if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88110 ] ; then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \ + -o ${TARGET_BINARY_INTERFACE}x = x ] ; then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else echo i586-dg-dgux${UNAME_RELEASE} + fi + exit 0 ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit 0 ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit 0 ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit 0 ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit 0 ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit 0 ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i?86:AIX:*:*) + echo i386-ibm-aix + exit 0 ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + sed 's/^ //' << EOF >$dummy.c + #include <sys/systemcfg.h> + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + ${CC-cc} $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo rs6000-ibm-aix3.2.5 + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit 0 ;; + *:AIX:*:4) + IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | head -1 | awk '{ print $1 }'` + if /usr/sbin/lsattr -EHl ${IBM_CPU_ID} | grep POWER >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=4.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit 0 ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit 0 ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit 0 ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit 0 ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit 0 ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit 0 ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit 0 ;; + 9000/[34678]??:HP-UX:*:*) + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/6?? | 9000/7?? | 9000/80[24] | 9000/8?[13679] | 9000/892 ) + sed 's/^ //' << EOF >$dummy.c + #include <stdlib.h> + #include <unistd.h> + + int main () + { + #if defined(_SC_KERNEL_BITS) + long bits = sysconf(_SC_KERNEL_BITS); + #endif + long cpu = sysconf (_SC_CPU_VERSION); + + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1"); break; + case CPU_PA_RISC2_0: + #if defined(_SC_KERNEL_BITS) + switch (bits) + { + case 64: puts ("hppa2.0w"); break; + /* case 32: puts ("hppa2.0n"); break; */ + case 32: puts ("hppa2.0"); break; /* modification for HPUX-11*/ + default: puts ("hppa2.0"); break; + } break; + #else /* !defined(_SC_KERNEL_BITS) */ + puts ("hppa2.0"); break; + #endif + default: puts ("hppa1.0"); break; + } + exit (0); + } +EOF + (${CC-cc} $dummy.c -o $dummy 2>/dev/null ) && HP_ARCH=`./$dummy` + rm -f $dummy.c $dummy + esac + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit 0 ;; + 3050*:HI-UX:*:*) + sed 's/^ //' << EOF >$dummy.c + #include <unistd.h> + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + ${CC-cc} $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + echo unknown-hitachi-hiuxwe2 + exit 0 ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit 0 ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit 0 ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit 0 ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit 0 ;; + i?86:OSF1:*:*) + if [ -x /usr/sbin/sysversion ] ; then + echo ${UNAME_MACHINE}-unknown-osf1mk + else + echo ${UNAME_MACHINE}-unknown-osf1 + fi + exit 0 ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit 0 ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit 0 ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit 0 ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit 0 ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit 0 ;; + CRAY*X-MP:*:*:*) + echo xmp-cray-unicos + exit 0 ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} + exit 0 ;; + CRAY*[A-Z]90:*:*:*) + echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ + -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ + exit 0 ;; + CRAY*TS:*:*:*) + echo t90-cray-unicos${UNAME_RELEASE} + exit 0 ;; + CRAY*T3E:*:*:*) + echo t3e-cray-unicosmk${UNAME_RELEASE} + exit 0 ;; + CRAY-2:*:*:*) + echo cray2-cray-unicos + exit 0 ;; + F300:UNIX_System_V:*:*) + FUJITSU_SYS=`uname -p | tr [A-Z] [a-z] | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` + echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" + exit 0 ;; + F301:UNIX_System_V:*:*) + echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'` + exit 0 ;; + hp3[0-9][05]:NetBSD:*:*) + echo m68k-hp-netbsd${UNAME_RELEASE} + exit 0 ;; + hp300:OpenBSD:*:*) + echo m68k-unknown-openbsd${UNAME_RELEASE} + exit 0 ;; + sparc*:BSD/OS:*:*) + echo sparc-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + i?86:BSD/386:*:* | i?86:BSD/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit 0 ;; + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:FreeBSD:*:*) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit 0 ;; + *:NetBSD:*:*) + echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + exit 0 ;; + *:OpenBSD:*:*) + echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + exit 0 ;; + i*:CYGWIN*:*) + echo ${UNAME_MACHINE}-pc-cygwin + exit 0 ;; + i*:MINGW*:*) + echo ${UNAME_MACHINE}-pc-mingw32 + exit 0 ;; + p*:CYGWIN*:*) + echo powerpcle-unknown-cygwin + exit 0 ;; + prep*:SunOS:5.*:*) + echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + *:GNU:*:*) + echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit 0 ;; + *:OS/390:*:*) + echo i390-ibm-mvs${UNAME_RELEASE} + exit 0 ;; + *:Linux:*:*) + # uname on the ARM produces all sorts of strangeness, and we need to + # filter it out. + case "$UNAME_MACHINE" in + arm* | sa110*) UNAME_MACHINE="arm" ;; + esac + + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. + ld_help_string=`ld --help 2>&1` + ld_supported_emulations=`echo $ld_help_string \ + | sed -ne '/supported emulations:/!d + s/[ ][ ]*/ /g + s/.*supported emulations: *// + s/ .*// + p'` + case "$ld_supported_emulations" in + i?86linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" ; exit 0 ;; + i?86coff) echo "${UNAME_MACHINE}-pc-linux-gnucoff" ; exit 0 ;; + sparclinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;; + armlinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;; + m68klinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;; + elf32ppc) echo "powerpc-unknown-linux-gnu" ; exit 0 ;; + esac + + if test "${UNAME_MACHINE}" = "alpha" ; then + sed 's/^ //' <<EOF >$dummy.s + .globl main + .ent main + main: + .frame \$30,0,\$26,0 + .prologue 0 + .long 0x47e03d80 # implver $0 + lda \$2,259 + .long 0x47e20c21 # amask $2,$1 + srl \$1,8,\$2 + sll \$2,2,\$2 + sll \$0,3,\$0 + addl \$1,\$0,\$0 + addl \$2,\$0,\$0 + ret \$31,(\$26),1 + .end main +EOF + LIBC="" + ${CC-cc} $dummy.s -o $dummy 2>/dev/null + if test "$?" = 0 ; then + ./$dummy + case "$?" in + 7) + UNAME_MACHINE="alpha" + ;; + 15) + UNAME_MACHINE="alphaev5" + ;; + 14) + UNAME_MACHINE="alphaev56" + ;; + 10) + UNAME_MACHINE="alphapca56" + ;; + 16) + UNAME_MACHINE="alphaev6" + ;; + esac + + objdump --private-headers $dummy | \ + grep ld.so.1 > /dev/null + if test "$?" = 0 ; then + LIBC="libc1" + fi + fi + rm -f $dummy.s $dummy + echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ; exit 0 + elif test "${UNAME_MACHINE}" = "mips" ; then + cat >$dummy.c <<EOF +main(argc, argv) + int argc; + char *argv[]; +{ +#ifdef __MIPSEB__ + printf ("%s-unknown-linux-gnu\n", argv[1]); +#endif +#ifdef __MIPSEL__ + printf ("%sel-unknown-linux-gnu\n", argv[1]); +#endif + return 0; +} +EOF + ${CC-cc} $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + else + # Either a pre-BFD a.out linker (linux-gnuoldld) + # or one that does not give us useful --help. + # GCC wants to distinguish between linux-gnuoldld and linux-gnuaout. + # If ld does not provide *any* "supported emulations:" + # that means it is gnuoldld. + echo "$ld_help_string" | grep >/dev/null 2>&1 "supported emulations:" + test $? != 0 && echo "${UNAME_MACHINE}-pc-linux-gnuoldld" && exit 0 + + case "${UNAME_MACHINE}" in + i?86) + VENDOR=pc; + ;; + *) + VENDOR=unknown; + ;; + esac + # Determine whether the default compiler is a.out or elf + cat >$dummy.c <<EOF +#include <features.h> +main(argc, argv) + int argc; + char *argv[]; +{ +#ifdef __ELF__ +# ifdef __GLIBC__ +# if __GLIBC__ >= 2 + printf ("%s-${VENDOR}-linux-gnu\n", argv[1]); +# else + printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]); +# endif +# else + printf ("%s-${VENDOR}-linux-gnulibc1\n", argv[1]); +# endif +#else + printf ("%s-${VENDOR}-linux-gnuaout\n", argv[1]); +#endif + return 0; +} +EOF + ${CC-cc} $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + fi ;; +# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions +# are messed up and put the nodename in both sysname and nodename. + i?86:DYNIX/ptx:4*:*) + echo i386-sequent-sysv4 + exit 0 ;; + i?86:UNIX_SV:4.2MP:2.*) + # Unixware is an offshoot of SVR4, but it has its own version + # number series starting with 2... + # I am not positive that other SVR4 systems won't match this, + # I just have to hope. -- rms. + # Use sysv4.2uw... so that sysv4* matches it. + echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} + exit 0 ;; + i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*) + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE} + fi + exit 0 ;; + i?86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name` + echo ${UNAME_MACHINE}-pc-isc$UNAME_REL + elif /bin/uname -X 2>/dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')` + (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486 + (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-pc-sysv32 + fi + exit 0 ;; + i?86:UnixWare:*:*) + if /bin/uname -X 2>/dev/null >/dev/null ; then + (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ + && UNAME_MACHINE=i586 + fi + echo ${UNAME_MACHINE}-unixware-${UNAME_RELEASE}-${UNAME_VERSION} + exit 0 ;; + pc:*:*:*) + # uname -m prints for DJGPP always 'pc', but it prints nothing about + # the processor, so we play safe by assuming i386. + echo i386-pc-msdosdjgpp + exit 0 ;; + Intel:Mach:3*:*) + echo i386-pc-mach3 + exit 0 ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit 0 ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit 0 ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit 0 ;; + M68*:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 4850:*:4.0:3.0) + OS_REL='' + test -r /etc/.relid \ + && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4.3${OS_REL} && exit 0 + /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ + && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4 && exit 0 ;; + m68*:LynxOS:2.*:*) + echo m68k-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit 0 ;; + i?86:LynxOS:2.*:*) + echo i386-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + TSUNAMI:LynxOS:2.*:*) + echo sparc-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + rs6000:LynxOS:2.*:* | PowerPC:LynxOS:2.*:*) + echo rs6000-unknown-lynxos${UNAME_RELEASE} + exit 0 ;; + SM[BE]S:UNIX_SV:*:*) + echo mips-dde-sysv${UNAME_RELEASE} + exit 0 ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit 0 ;; + PENTIUM:CPunix:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort + # says <Richard.M.Bartel@ccMail.Census.GOV> + echo i586-unisys-sysv4 + exit 0 ;; + *:UNIX_System_V:4*:FTX*) + # From Gerald Hewes <hewes@openmarket.com>. + # How about differentiating between stratus architectures? -djm + echo hppa1.1-stratus-sysv4 + exit 0 ;; + *:*:*:FTX*) + # From seanf@swdc.stratus.com. + echo i860-stratus-sysv4 + exit 0 ;; + mc68*:A/UX:*:*) + echo m68k-apple-aux${UNAME_RELEASE} + exit 0 ;; + news*:NEWS-OS:*:6*) + echo mips-sony-newsos6 + exit 0 ;; + R3000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R4000:UNIX_SV:*:*) + if [ -d /usr/nec ]; then + echo mips-nec-sysv${UNAME_RELEASE} + else + echo mips-unknown-sysv${UNAME_RELEASE} + fi + exit 0 ;; + BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. + echo powerpc-be-beos + exit 0 ;; + BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. + echo powerpc-apple-beos + exit 0 ;; + BePC:BeOS:*:*) # BeOS running on Intel PC compatible. + echo i586-pc-beos + exit 0 ;; + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit 0 ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit 0 ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +cat >$dummy.c <<EOF +#ifdef _SEQUENT_ +# include <sys/types.h> +# include <sys/utsname.h> +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include <sys/param.h> + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +#if !defined (ultrix) + printf ("vax-dec-bsd\n"); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +${CC-cc} $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm $dummy.c $dummy && exit 0 +rm -f $dummy.c $dummy + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit 0 ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + c34*) + echo c34-convex-bsd + exit 0 ;; + c38*) + echo c38-convex-bsd + exit 0 ;; + c4*) + echo c4-convex-bsd + exit 0 ;; + esac +fi + +#echo '(Unable to guess system type)' 1>&2 + +exit 1 diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..f7759c48ca582e1552013836245cc23436d77386 --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,19 @@ +/* config.h.in. Generated automatically from configure.in by autoheader. */ + +/* Define if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to signed char if not in <sys/types.h> */ +#undef XMLByte + +/* Define if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define if you have the m library (-lm). */ +#undef HAVE_LIBM + +/* Define if you have the pthread library (-lpthread). */ +#undef HAVE_LIBPTHREAD + +/* Define if you have the pthreads library (-lpthreads). */ +#undef HAVE_LIBPTHREADS diff --git a/src/config.sub b/src/config.sub new file mode 100644 index 0000000000000000000000000000000000000000..1674521d7647bf0960c46cca83517727e7620f1c --- /dev/null +++ b/src/config.sub @@ -0,0 +1,956 @@ +#! /bin/sh +# Configuration validation subroutine script, version 1.1. +# Copyright (C) 1991, 92-97, 1998 Free Software Foundation, Inc. +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# or in some cases, the newer four-part form: +# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +if [ x$1 = x ] +then + echo Configuration name missing. 1>&2 + echo "Usage: $0 CPU-MFR-OPSYS" 1>&2 + echo "or $0 ALIAS" 1>&2 + echo where ALIAS is a recognized configuration type. 1>&2 + exit 1 +fi + +# First pass through any local machine types. +case $1 in + *local*) + echo $1 + exit 0 + ;; + *) + ;; +esac + +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). +# Here we must recognize all the valid KERNEL-OS combinations. +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` +case $maybe_os in + linux-gnu*) + os=-$maybe_os + basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` + ;; + *) + basic_machine=`echo $1 | sed 's/-[^-]*$//'` + if [ $basic_machine != $1 ] + then os=`echo $1 | sed 's/.*-/-/'` + else os=; fi + ;; +esac + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ + -apple) + os= + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco5) + os=sco3.2v5 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; + -psos*) + os=-psos + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + tahoe | i860 | m32r | m68k | m68000 | m88k | ns32k | arc | arm \ + | arme[lb] | pyramid | mn10200 | mn10300 | tron | a29k \ + | 580 | i960 | h8300 | hppa | hppa1.0 | hppa1.1 | hppa2.0 \ + | alpha | alphaev5 | alphaev56 | we32k | ns16k | clipper \ + | i390 | sh | powerpc | powerpcle | 1750a | dsp16xx | pdp11 \ + | mips64 | mipsel | mips64el | mips64orion | mips64orionel \ + | mipstx39 | mipstx39el \ + | sparc | sparclet | sparclite | sparc64 | v850) + basic_machine=$basic_machine-unknown + ;; + # We use `pc' rather than `unknown' + # because (1) that's what they normally are, and + # (2) the word "unknown" tends to confuse beginning users. + i[34567]86) + basic_machine=$basic_machine-pc + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + vax-* | tahoe-* | i[34567]86-* | i860-* | m32r-* | m68k-* | m68000-* \ + | m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | arm-* | c[123]* \ + | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \ + | power-* | none-* | 580-* | cray2-* | h8300-* | i960-* \ + | xmp-* | ymp-* | hppa-* | hppa1.0-* | hppa1.1-* | hppa2.0-* \ + | alpha-* | alphaev5-* | alphaev56-* | we32k-* | cydra-* \ + | ns16k-* | pn-* | np1-* | xps100-* | clipper-* | orion-* \ + | sparclite-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \ + | sparc64-* | mips64-* | mipsel-* \ + | mips64el-* | mips64orion-* | mips64orionel-* \ + | mipstx39-* | mipstx39el-* \ + | f301-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-cbm + ;; + amigaos | amigados) + basic_machine=m68k-cbm + os=-amigaos + ;; + amigaunix | amix) + basic_machine=m68k-cbm + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + aux) + basic_machine=m68k-apple + os=-aux + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | ymp) + basic_machine=ymp-cray + os=-unicos + ;; + cray2) + basic_machine=cray2-cray + os=-unicos + ;; + [ctj]90-cray) + basic_machine=c90-cray + os=-unicos + ;; + crds | unos) + basic_machine=m68k-crds + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hppa-next) + os=-nextstep3 + ;; + i390-ibm* | ibm*) + basic_machine=i390-ibm + os=-mvs + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i[34567]86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv32 + ;; + i[34567]86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv4 + ;; + i[34567]86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-sysv + ;; + i[34567]86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` + os=-solaris2 + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + miniframe) + basic_machine=m68000-convergent + ;; + mipsel*-linux*) + basic_machine=mipsel-unknown + os=-linux-gnu + ;; + mips*-linux*) + basic_machine=mips-unknown + os=-linux-gnu + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + np1) + basic_machine=np1-gould + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pentium | p5 | k5 | nexen) + basic_machine=i586-pc + ;; + pentiumpro | p6 | k6 | 6x86) + basic_machine=i686-pc + ;; + pentiumii | pentium2) + basic_machine=i786-pc + ;; + pentium-* | p5-* | k5-* | nexen-*) + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumpro-* | p6-* | k6-* | 6x86-*) + basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pentiumii-* | pentium2-*) + basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=rs6000-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + tx39) + basic_machine=mipstx39-unknown + ;; + tx39el) + basic_machine=mipstx39el-unknown + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vpp*|vx|vx-*) + basic_machine=f301-fujitsu + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + xmp) + basic_machine=xmp-cray + os=-unicos + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + mips) + if [ x$os = x-linux-gnu ]; then + basic_machine=mips-unknown + else + basic_machine=mips-mips + fi + ;; + romp) + basic_machine=romp-ibm + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sparc) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # First match some system type aliases + # that might get confused with valid system types. + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -svr4*) + os=-sysv4 + ;; + -unixware*) + os=-sysv4.2uw + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ + | -aos* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ + | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -rhapsody* \ + | -openstep*) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -linux*) + os=`echo $os | sed -e 's|linux|linux-gnu|'` + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -ctix* | -uts*) + os=-sysv + ;; + -ns2 ) + os=-nextstep2 + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -xenix) + os=-xenix + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + *-acorn) + os=-riscix1.2 + ;; + arm*-semi) + os=-aout + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-be) + os=-beos + ;; + *-ibm) + os=-aix + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigaos + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-next ) + os=-nextstep + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i390-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + f301-fujitsu) + os=-uxpv + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -aix*) + vendor=ibm + ;; + -hpux*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -vxsim* | -vxworks*) + vendor=wrs + ;; + -aux*) + vendor=apple + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os diff --git a/src/configure b/src/configure new file mode 100755 index 0000000000000000000000000000000000000000..1c0b40b5e3879c1a3d46b058f05c9013c8485e32 --- /dev/null +++ b/src/configure @@ -0,0 +1,1759 @@ +#! /bin/sh + +# Guess values for system-dependent variables and create Makefiles. +# Generated automatically using autoconf version 2.13 +# Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. + +# Defaults: +ac_help= +ac_default_prefix=/usr/local +# Any additions from configure.in: + +# Initialize some variables set by options. +# The variables have the same names as the options, with +# dashes changed to underlines. +build=NONE +cache_file=./config.cache +exec_prefix=NONE +host=NONE +no_create= +nonopt=NONE +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +target=NONE +verbose= +x_includes=NONE +x_libraries=NONE +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datadir='${prefix}/share' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +libdir='${exec_prefix}/lib' +includedir='${prefix}/include' +oldincludedir='/usr/include' +infodir='${prefix}/info' +mandir='${prefix}/man' + +# Initialize some other variables. +subdirs= +MFLAGS= MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} +# Maximum number of lines to put in a shell here document. +ac_max_here_lines=12 + +ac_prev= +for ac_option +do + + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval "$ac_prev=\$ac_option" + ac_prev= + continue + fi + + case "$ac_option" in + -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; + *) ac_optarg= ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case "$ac_option" in + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir="$ac_optarg" ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build="$ac_optarg" ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file="$ac_optarg" ;; + + -datadir | --datadir | --datadi | --datad | --data | --dat | --da) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ + | --da=*) + datadir="$ac_optarg" ;; + + -disable-* | --disable-*) + ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` + # Reject names that are not valid shell variable names. + if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then + { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } + fi + ac_feature=`echo $ac_feature| sed 's/-/_/g'` + eval "enable_${ac_feature}=no" ;; + + -enable-* | --enable-*) + ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` + # Reject names that are not valid shell variable names. + if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then + { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } + fi + ac_feature=`echo $ac_feature| sed 's/-/_/g'` + case "$ac_option" in + *=*) ;; + *) ac_optarg=yes ;; + esac + eval "enable_${ac_feature}='$ac_optarg'" ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix="$ac_optarg" ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he) + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat << EOF +Usage: configure [options] [host] +Options: [defaults in brackets after descriptions] +Configuration: + --cache-file=FILE cache test results in FILE + --help print this message + --no-create do not create output files + --quiet, --silent do not print \`checking...' messages + --version print the version of autoconf that created configure +Directory and file names: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [same as prefix] + --bindir=DIR user executables in DIR [EPREFIX/bin] + --sbindir=DIR system admin executables in DIR [EPREFIX/sbin] + --libexecdir=DIR program executables in DIR [EPREFIX/libexec] + --datadir=DIR read-only architecture-independent data in DIR + [PREFIX/share] + --sysconfdir=DIR read-only single-machine data in DIR [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data in DIR + [PREFIX/com] + --localstatedir=DIR modifiable single-machine data in DIR [PREFIX/var] + --libdir=DIR object code libraries in DIR [EPREFIX/lib] + --includedir=DIR C header files in DIR [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc in DIR [/usr/include] + --infodir=DIR info documentation in DIR [PREFIX/info] + --mandir=DIR man documentation in DIR [PREFIX/man] + --srcdir=DIR find the sources in DIR [configure dir or ..] + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM + run sed PROGRAM on installed program names +EOF + cat << EOF +Host type: + --build=BUILD configure for building on BUILD [BUILD=HOST] + --host=HOST configure for HOST [guessed] + --target=TARGET configure for TARGET [TARGET=HOST] +Features and packages: + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --x-includes=DIR X include files are in DIR + --x-libraries=DIR X library files are in DIR +EOF + if test -n "$ac_help"; then + echo "--enable and --with options recognized:$ac_help" + fi + exit 0 ;; + + -host | --host | --hos | --ho) + ac_prev=host ;; + -host=* | --host=* | --hos=* | --ho=*) + host="$ac_optarg" ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir="$ac_optarg" ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir="$ac_optarg" ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir="$ac_optarg" ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir="$ac_optarg" ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst \ + | --locals | --local | --loca | --loc | --lo) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* \ + | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) + localstatedir="$ac_optarg" ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir="$ac_optarg" ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir="$ac_optarg" ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix="$ac_optarg" ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix="$ac_optarg" ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix="$ac_optarg" ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name="$ac_optarg" ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir="$ac_optarg" ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir="$ac_optarg" ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site="$ac_optarg" ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir="$ac_optarg" ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir="$ac_optarg" ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target="$ac_optarg" ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers) + echo "configure generated by autoconf version 2.13" + exit 0 ;; + + -with-* | --with-*) + ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` + # Reject names that are not valid shell variable names. + if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then + { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } + fi + ac_package=`echo $ac_package| sed 's/-/_/g'` + case "$ac_option" in + *=*) ;; + *) ac_optarg=yes ;; + esac + eval "with_${ac_package}='$ac_optarg'" ;; + + -without-* | --without-*) + ac_package=`echo $ac_option|sed -e 's/-*without-//'` + # Reject names that are not valid shell variable names. + if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then + { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } + fi + ac_package=`echo $ac_package| sed 's/-/_/g'` + eval "with_${ac_package}=no" ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes="$ac_optarg" ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries="$ac_optarg" ;; + + -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } + ;; + + *) + if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then + echo "configure: warning: $ac_option: invalid host type" 1>&2 + fi + if test "x$nonopt" != xNONE; then + { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } + fi + nonopt="$ac_option" + ;; + + esac +done + +if test -n "$ac_prev"; then + { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } +fi + +trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 + +# File descriptor usage: +# 0 standard input +# 1 file creation +# 2 errors and warnings +# 3 some systems may open it to /dev/tty +# 4 used on the Kubota Titan +# 6 checking for... messages and results +# 5 compiler messages saved in config.log +if test "$silent" = yes; then + exec 6>/dev/null +else + exec 6>&1 +fi +exec 5>./config.log + +echo "\ +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. +" 1>&5 + +# Strip out --no-create and --no-recursion so they do not pile up. +# Also quote any args containing shell metacharacters. +ac_configure_args= +for ac_arg +do + case "$ac_arg" in + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c) ;; + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) + ac_configure_args="$ac_configure_args '$ac_arg'" ;; + *) ac_configure_args="$ac_configure_args $ac_arg" ;; + esac +done + +# NLS nuisances. +# Only set these to C if already set. These must not be set unconditionally +# because not all systems understand e.g. LANG=C (notably SCO). +# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'! +# Non-C LC_CTYPE values break the ctype check. +if test "${LANG+set}" = set; then LANG=C; export LANG; fi +if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi +if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi +if test "${LC_CTYPE+set}" = set; then LC_CTYPE=C; export LC_CTYPE; fi + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -rf conftest* confdefs.h +# AIX cpp loses on an empty file, so make sure it contains at least a newline. +echo > confdefs.h + +# A filename unique to this package, relative to the directory that +# configure is in, which we can look for to find out if srcdir is correct. +ac_unique_file=util/XML4CDefs.hpp + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then its parent. + ac_prog=$0 + ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` + test "x$ac_confdir" = "x$ac_prog" && ac_confdir=. + srcdir=$ac_confdir + if test ! -r $srcdir/$ac_unique_file; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r $srcdir/$ac_unique_file; then + if test "$ac_srcdir_defaulted" = yes; then + { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } + else + { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } + fi +fi +srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` + +# Prefer explicitly selected file to automatically selected ones. +if test -z "$CONFIG_SITE"; then + if test "x$prefix" != xNONE; then + CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" + else + CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" + fi +fi +for ac_site_file in $CONFIG_SITE; do + if test -r "$ac_site_file"; then + echo "loading site script $ac_site_file" + . "$ac_site_file" + fi +done + +if test -r "$cache_file"; then + echo "loading cache $cache_file" + . $cache_file +else + echo "creating cache $cache_file" + > $cache_file +fi + +ac_ext=c +# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. +ac_cpp='$CPP $CPPFLAGS' +ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' +ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +cross_compiling=$ac_cv_prog_cc_cross + +ac_exeext= +ac_objext=o +if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then + # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. + if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then + ac_n= ac_c=' +' ac_t=' ' + else + ac_n=-n ac_c= ac_t= + fi +else + ac_n= ac_c='\c' ac_t= +fi + + + +# Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 +echo "configure:529: checking for $ac_word" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$ac_word; then + ac_cv_prog_CC="gcc" + break + fi + done + IFS="$ac_save_ifs" +fi +fi +CC="$ac_cv_prog_CC" +if test -n "$CC"; then + echo "$ac_t""$CC" 1>&6 +else + echo "$ac_t""no" 1>&6 +fi + +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 +echo "configure:559: checking for $ac_word" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + ac_prog_rejected=no + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$ac_word; then + if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + break + fi + done + IFS="$ac_save_ifs" +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# -gt 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + set dummy "$ac_dir/$ac_word" "$@" + shift + ac_cv_prog_CC="$@" + fi +fi +fi +fi +CC="$ac_cv_prog_CC" +if test -n "$CC"; then + echo "$ac_t""$CC" 1>&6 +else + echo "$ac_t""no" 1>&6 +fi + + if test -z "$CC"; then + case "`uname -s`" in + *win32* | *WIN32*) + # Extract the first word of "cl", so it can be a program name with args. +set dummy cl; ac_word=$2 +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 +echo "configure:610: checking for $ac_word" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$ac_word; then + ac_cv_prog_CC="cl" + break + fi + done + IFS="$ac_save_ifs" +fi +fi +CC="$ac_cv_prog_CC" +if test -n "$CC"; then + echo "$ac_t""$CC" 1>&6 +else + echo "$ac_t""no" 1>&6 +fi + ;; + esac + fi + test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } +fi + +echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 +echo "configure:642: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 + +ac_ext=c +# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. +ac_cpp='$CPP $CPPFLAGS' +ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' +ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +cross_compiling=$ac_cv_prog_cc_cross + +cat > conftest.$ac_ext << EOF + +#line 653 "configure" +#include "confdefs.h" + +main(){return(0);} +EOF +if { (eval echo configure:658: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + ac_cv_prog_cc_works=yes + # If we can't run a trivial program, we are probably using a cross compiler. + if (./conftest; exit) 2>/dev/null; then + ac_cv_prog_cc_cross=no + else + ac_cv_prog_cc_cross=yes + fi +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + ac_cv_prog_cc_works=no +fi +rm -fr conftest* +ac_ext=c +# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. +ac_cpp='$CPP $CPPFLAGS' +ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' +ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +cross_compiling=$ac_cv_prog_cc_cross + +echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 +if test $ac_cv_prog_cc_works = no; then + { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } +fi +echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 +echo "configure:684: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 +cross_compiling=$ac_cv_prog_cc_cross + +echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 +echo "configure:689: checking whether we are using GNU C" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.c <<EOF +#ifdef __GNUC__ + yes; +#endif +EOF +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:698: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then + ac_cv_prog_gcc=yes +else + ac_cv_prog_gcc=no +fi +fi + +echo "$ac_t""$ac_cv_prog_gcc" 1>&6 + +if test $ac_cv_prog_gcc = yes; then + GCC=yes +else + GCC= +fi + +ac_test_CFLAGS="${CFLAGS+set}" +ac_save_CFLAGS="$CFLAGS" +CFLAGS= +echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 +echo "configure:717: checking whether ${CC-cc} accepts -g" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + echo 'void f(){}' > conftest.c +if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then + ac_cv_prog_cc_g=yes +else + ac_cv_prog_cc_g=no +fi +rm -f conftest* + +fi + +echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 +if test "$ac_test_CFLAGS" = set; then + CFLAGS="$ac_save_CFLAGS" +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi + +for ac_prog in $CCC c++ g++ gcc CC cxx cc++ cl +do +# Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 +echo "configure:753: checking for $ac_word" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test -n "$CXX"; then + ac_cv_prog_CXX="$CXX" # Let the user override the test. +else + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$ac_word; then + ac_cv_prog_CXX="$ac_prog" + break + fi + done + IFS="$ac_save_ifs" +fi +fi +CXX="$ac_cv_prog_CXX" +if test -n "$CXX"; then + echo "$ac_t""$CXX" 1>&6 +else + echo "$ac_t""no" 1>&6 +fi + +test -n "$CXX" && break +done +test -n "$CXX" || CXX="gcc" + + +echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6 +echo "configure:785: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5 + +ac_ext=C +# CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' +ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +cross_compiling=$ac_cv_prog_cxx_cross + +cat > conftest.$ac_ext << EOF + +#line 796 "configure" +#include "confdefs.h" + +int main(){return(0);} +EOF +if { (eval echo configure:801: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + ac_cv_prog_cxx_works=yes + # If we can't run a trivial program, we are probably using a cross compiler. + if (./conftest; exit) 2>/dev/null; then + ac_cv_prog_cxx_cross=no + else + ac_cv_prog_cxx_cross=yes + fi +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + ac_cv_prog_cxx_works=no +fi +rm -fr conftest* +ac_ext=c +# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. +ac_cpp='$CPP $CPPFLAGS' +ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' +ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +cross_compiling=$ac_cv_prog_cc_cross + +echo "$ac_t""$ac_cv_prog_cxx_works" 1>&6 +if test $ac_cv_prog_cxx_works = no; then + { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; } +fi +echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 +echo "configure:827: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6 +cross_compiling=$ac_cv_prog_cxx_cross + +echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6 +echo "configure:832: checking whether we are using GNU C++" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.C <<EOF +#ifdef __GNUC__ + yes; +#endif +EOF +if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:841: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then + ac_cv_prog_gxx=yes +else + ac_cv_prog_gxx=no +fi +fi + +echo "$ac_t""$ac_cv_prog_gxx" 1>&6 + +if test $ac_cv_prog_gxx = yes; then + GXX=yes +else + GXX= +fi + +ac_test_CXXFLAGS="${CXXFLAGS+set}" +ac_save_CXXFLAGS="$CXXFLAGS" +CXXFLAGS= +echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6 +echo "configure:860: checking whether ${CXX-g++} accepts -g" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + echo 'void f(){}' > conftest.cc +if test -z "`${CXX-g++} -g -c conftest.cc 2>&1`"; then + ac_cv_prog_cxx_g=yes +else + ac_cv_prog_cxx_g=no +fi +rm -f conftest* + +fi + +echo "$ac_t""$ac_cv_prog_cxx_g" 1>&6 +if test "$ac_test_CXXFLAGS" = set; then + CXXFLAGS="$ac_save_CXXFLAGS" +elif test $ac_cv_prog_cxx_g = yes; then + if test "$GXX" = yes; then + CXXFLAGS="-g -O2" + else + CXXFLAGS="-g" + fi +else + if test "$GXX" = yes; then + CXXFLAGS="-O2" + else + CXXFLAGS= + fi +fi + +ac_aux_dir= +for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do + if test -f $ac_dir/install-sh; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f $ac_dir/install.sh; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + fi +done +if test -z "$ac_aux_dir"; then + { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; } +fi +ac_config_guess=$ac_aux_dir/config.guess +ac_config_sub=$ac_aux_dir/config.sub +ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# ./install, which can be erroneously created by make from ./install.sh. +echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 +echo "configure:922: checking for a BSD compatible install" >&5 +if test -z "$INSTALL"; then +if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":" + for ac_dir in $PATH; do + # Account for people who put trailing slashes in PATH elements. + case "$ac_dir/" in + /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + if test -f $ac_dir/$ac_prog; then + if test $ac_prog = install && + grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + else + ac_cv_path_install="$ac_dir/$ac_prog -c" + break 2 + fi + fi + done + ;; + esac + done + IFS="$ac_save_IFS" + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL="$ac_cv_path_install" + else + # As a last resort, use the slow shell script. We don't cache a + # path for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the path is relative. + INSTALL="$ac_install_sh" + fi +fi +echo "$ac_t""$INSTALL" 1>&6 + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +# Extract the first word of "autoconf", so it can be a program name with args. +set dummy autoconf; ac_word=$2 +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 +echo "configure:977: checking for $ac_word" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_AUTOCONF'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test -n "$AUTOCONF"; then + ac_cv_prog_AUTOCONF="$AUTOCONF" # Let the user override the test. +else + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$ac_word; then + ac_cv_prog_AUTOCONF="autoconf" + break + fi + done + IFS="$ac_save_ifs" + test -z "$ac_cv_prog_AUTOCONF" && ac_cv_prog_AUTOCONF="true" +fi +fi +AUTOCONF="$ac_cv_prog_AUTOCONF" +if test -n "$AUTOCONF"; then + echo "$ac_t""$AUTOCONF" 1>&6 +else + echo "$ac_t""no" 1>&6 +fi + + +echo $ac_n "checking for floor in -lm""... $ac_c" 1>&6 +echo "configure:1006: checking for floor in -lm" >&5 +ac_lib_var=`echo m'_'floor | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lm $LIBS" +cat > conftest.$ac_ext <<EOF +#line 1014 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char floor(); + +int main() { +floor() +; return 0; } +EOF +if { (eval echo configure:1025: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo m | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <<EOF +#define $ac_tr_lib 1 +EOF + + LIBS="-lm $LIBS" + +else + echo "$ac_t""no" 1>&6 +fi + + +echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6 +echo "configure:1054: checking for pthread_create in -lpthread" >&5 +ac_lib_var=`echo pthread'_'pthread_create | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lpthread $LIBS" +cat > conftest.$ac_ext <<EOF +#line 1062 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char pthread_create(); + +int main() { +pthread_create() +; return 0; } +EOF +if { (eval echo configure:1073: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo pthread | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <<EOF +#define $ac_tr_lib 1 +EOF + + LIBS="-lpthread $LIBS" + +else + echo "$ac_t""no" 1>&6 +fi + +if test $ac_cv_lib_pthread_pthread_create = no; then +echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6 +echo "configure:1102: checking for pthread_create in -lpthreads" >&5 +ac_lib_var=`echo pthreads'_'pthread_create | sed 'y%./+-%__p_%'` +if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_save_LIBS="$LIBS" +LIBS="-lpthreads $LIBS" +cat > conftest.$ac_ext <<EOF +#line 1110 "configure" +#include "confdefs.h" +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char pthread_create(); + +int main() { +pthread_create() +; return 0; } +EOF +if { (eval echo configure:1121: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_lib_$ac_lib_var=no" +fi +rm -f conftest* +LIBS="$ac_save_LIBS" + +fi +if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_lib=HAVE_LIB`echo pthreads | sed -e 's/[^a-zA-Z0-9_]/_/g' \ + -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` + cat >> confdefs.h <<EOF +#define $ac_tr_lib 1 +EOF + + LIBS="-lpthreads $LIBS" + +else + echo "$ac_t""no" 1>&6 +fi + +fi + +echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 +echo "configure:1151: checking how to run the C preprocessor" >&5 +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then +if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + # This must be in double quotes, not single quotes, because CPP may get + # substituted into the Makefile and "${CC-cc}" will confuse make. + CPP="${CC-cc} -E" + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. + cat > conftest.$ac_ext <<EOF +#line 1166 "configure" +#include "confdefs.h" +#include <assert.h> +Syntax Error +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1172: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + : +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + CPP="${CC-cc} -E -traditional-cpp" + cat > conftest.$ac_ext <<EOF +#line 1183 "configure" +#include "confdefs.h" +#include <assert.h> +Syntax Error +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1189: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + : +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + CPP="${CC-cc} -nologo -E" + cat > conftest.$ac_ext <<EOF +#line 1200 "configure" +#include "confdefs.h" +#include <assert.h> +Syntax Error +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1206: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + : +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + CPP=/lib/cpp +fi +rm -f conftest* +fi +rm -f conftest* +fi +rm -f conftest* + ac_cv_prog_CPP="$CPP" +fi + CPP="$ac_cv_prog_CPP" +else + ac_cv_prog_CPP="$CPP" +fi +echo "$ac_t""$CPP" 1>&6 + +for ac_hdr in inttypes.h +do +ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 +echo "configure:1234: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1239 "configure" +#include "confdefs.h" +#include <$ac_hdr> +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1244: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + rm -rf conftest* + eval "ac_cv_header_$ac_safe=yes" +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_header_$ac_safe=no" +fi +rm -f conftest* +fi +if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` + cat >> confdefs.h <<EOF +#define $ac_tr_hdr 1 +EOF + +else + echo "$ac_t""no" 1>&6 +fi +done + +if test $ac_cv_header_inttypes_h = no; then +HAVE_INTTYPES_H=0 +else +HAVE_INTTYPES_H=1 +fi + + +echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 +echo "configure:1278: checking for ANSI C header files" >&5 +if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1283 "configure" +#include "confdefs.h" +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <float.h> +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:1291: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + rm -rf conftest* + ac_cv_header_stdc=yes +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_header_stdc=no +fi +rm -f conftest* + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. +cat > conftest.$ac_ext <<EOF +#line 1308 "configure" +#include "confdefs.h" +#include <string.h> +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "memchr" >/dev/null 2>&1; then + : +else + rm -rf conftest* + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. +cat > conftest.$ac_ext <<EOF +#line 1326 "configure" +#include "confdefs.h" +#include <stdlib.h> +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "free" >/dev/null 2>&1; then + : +else + rm -rf conftest* + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. +if test "$cross_compiling" = yes; then + : +else + cat > conftest.$ac_ext <<EOF +#line 1347 "configure" +#include "confdefs.h" +#include <ctype.h> +#define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +#define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int main () { int i; for (i = 0; i < 256; i++) +if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); +exit (0); } + +EOF +if { (eval echo configure:1358: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + : +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_header_stdc=no +fi +rm -fr conftest* +fi + +fi +fi + +echo "$ac_t""$ac_cv_header_stdc" 1>&6 +if test $ac_cv_header_stdc = yes; then + cat >> confdefs.h <<\EOF +#define STDC_HEADERS 1 +EOF + +fi + +echo $ac_n "checking for XMLByte""... $ac_c" 1>&6 +echo "configure:1382: checking for XMLByte" >&5 +if eval "test \"`echo '$''{'ac_cv_type_XMLByte'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1387 "configure" +#include "confdefs.h" +#include <sys/types.h> +#if STDC_HEADERS +#include <stdlib.h> +#include <stddef.h> +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "(^|[^a-zA-Z_0-9])XMLByte[^a-zA-Z_0-9]" >/dev/null 2>&1; then + rm -rf conftest* + ac_cv_type_XMLByte=yes +else + rm -rf conftest* + ac_cv_type_XMLByte=no +fi +rm -f conftest* + +fi +echo "$ac_t""$ac_cv_type_XMLByte" 1>&6 +if test $ac_cv_type_XMLByte = no; then + cat >> confdefs.h <<\EOF +#define XMLByte unsigned char +EOF + +fi + + + +# Make sure we can run config.sub. +if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then : +else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; } +fi + +echo $ac_n "checking host system type""... $ac_c" 1>&6 +echo "configure:1422: checking host system type" >&5 + +host_alias=$host +case "$host_alias" in +NONE) + case $nonopt in + NONE) + if host_alias=`${CONFIG_SHELL-/bin/sh} $ac_config_guess`; then : + else { echo "configure: error: can not guess host type; you must specify one" 1>&2; exit 1; } + fi ;; + *) host_alias=$nonopt ;; + esac ;; +esac + +host=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $host_alias` +host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` +host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` +host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` +echo "$ac_t""$host" 1>&6 + + +case "${host}" in + *-*-solaris*) platform=SOLARIS ;; + *-*-linux*) platform=LINUX ;; + *-*-aix*) platform=AIX ;; + *-*-hp*) platform=HPUX ;; + *-*-mvs*) platform=OS390 ;; + *) platform=UNKNOWN ;; +esac + + +compiler=${CXX} + + +prefix=${prefix} + + +trap '' 1 2 15 +cat > confcache <<\EOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs. It is not useful on other systems. +# If it contains results you don't want to keep, you may remove or edit it. +# +# By default, configure uses ./config.cache as the cache file, +# creating it if it does not exist already. You can give configure +# the --cache-file=FILE option to use a different cache file; that is +# what configure does when it calls configure scripts in +# subdirectories, so they share the cache. +# Giving --cache-file=/dev/null disables caching, for debugging configure. +# config.status only pays attention to the cache file if you give it the +# --recheck option to rerun configure. +# +EOF +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, don't put newlines in cache variables' values. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +(set) 2>&1 | + case `(ac_space=' '; set | grep ac_space) 2>&1` in + *ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote substitution + # turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + -e "s/'/'\\\\''/g" \ + -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" + ;; + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' + ;; + esac >> confcache +if cmp -s $cache_file confcache; then + : +else + if test -w $cache_file; then + echo "updating cache $cache_file" + cat confcache > $cache_file + else + echo "not updating unwritable cache $cache_file" + fi +fi +rm -f confcache + +trap 'rm -fr conftest* confdefs* core core.* *.core $ac_clean_files; exit 1' 1 2 15 + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +# Any assignment to VPATH causes Sun make to only execute +# the first set of double-colon rules, so remove it if not needed. +# If there is a colon in the path, we need to keep it. +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=[^:]*$/d' +fi + +trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 + +# Transform confdefs.h into DEFS. +# Protect against shell expansion while executing Makefile rules. +# Protect against Makefile macro expansion. +cat > conftest.defs <<\EOF +s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g +s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g +s%\[%\\&%g +s%\]%\\&%g +s%\$%$$%g +EOF +DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '` +rm -f conftest.defs + + +# Without the "./", some shells look in PATH for config.status. +: ${CONFIG_STATUS=./config.status} + +echo creating $CONFIG_STATUS +rm -f $CONFIG_STATUS +cat > $CONFIG_STATUS <<EOF +#! /bin/sh +# Generated automatically by configure. +# Run this file to recreate the current configuration. +# This directory was configured as follows, +# on host `(hostname || uname -n) 2>/dev/null | sed 1q`: +# +# $0 $ac_configure_args +# +# Compiler output produced by configure, useful for debugging +# configure, is in ./config.log if it exists. + +ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" +for ac_option +do + case "\$ac_option" in + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" + exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; + -version | --version | --versio | --versi | --vers | --ver | --ve | --v) + echo "$CONFIG_STATUS generated by autoconf version 2.13" + exit 0 ;; + -help | --help | --hel | --he | --h) + echo "\$ac_cs_usage"; exit 0 ;; + *) echo "\$ac_cs_usage"; exit 1 ;; + esac +done + +ac_given_srcdir=$srcdir +ac_given_INSTALL="$INSTALL" + +trap 'rm -fr `echo "Makefile \ +util/Makefile \ +util/Transcoders/ICU/Makefile \ +util/Transcoders/Iconv/Makefile \ +util/Platforms/Makefile \ +util/Compilers/Makefile \ +util/MsgLoaders/InMemory/Makefile \ +util/MsgLoaders/ICU/Makefile \ +util/MsgLoaders/MsgCatalog/Makefile \ +validators/DTD/Makefile \ +framework/Makefile \ +dom/Makefile \ +parsers/Makefile \ +internal/Makefile \ +sax/Makefile \ +../obj/Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 +EOF +cat >> $CONFIG_STATUS <<EOF + +# Protect against being on the right side of a sed subst in config.status. +sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g; + s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF +$ac_vpsub +$extrasub +s%@SHELL@%$SHELL%g +s%@CFLAGS@%$CFLAGS%g +s%@CPPFLAGS@%$CPPFLAGS%g +s%@CXXFLAGS@%$CXXFLAGS%g +s%@FFLAGS@%$FFLAGS%g +s%@DEFS@%$DEFS%g +s%@LDFLAGS@%$LDFLAGS%g +s%@LIBS@%$LIBS%g +s%@exec_prefix@%$exec_prefix%g +s%@prefix@%$prefix%g +s%@program_transform_name@%$program_transform_name%g +s%@bindir@%$bindir%g +s%@sbindir@%$sbindir%g +s%@libexecdir@%$libexecdir%g +s%@datadir@%$datadir%g +s%@sysconfdir@%$sysconfdir%g +s%@sharedstatedir@%$sharedstatedir%g +s%@localstatedir@%$localstatedir%g +s%@libdir@%$libdir%g +s%@includedir@%$includedir%g +s%@oldincludedir@%$oldincludedir%g +s%@infodir@%$infodir%g +s%@mandir@%$mandir%g +s%@CC@%$CC%g +s%@CXX@%$CXX%g +s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g +s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g +s%@INSTALL_DATA@%$INSTALL_DATA%g +s%@AUTOCONF@%$AUTOCONF%g +s%@CPP@%$CPP%g +s%@HAVE_INTTYPES_H@%$HAVE_INTTYPES_H%g +s%@host@%$host%g +s%@host_alias@%$host_alias%g +s%@host_cpu@%$host_cpu%g +s%@host_vendor@%$host_vendor%g +s%@host_os@%$host_os%g +s%@platform@%$platform%g +s%@compiler@%$compiler%g + +CEOF +EOF + +cat >> $CONFIG_STATUS <<\EOF + +# Split the substitutions into bite-sized pieces for seds with +# small command number limits, like on Digital OSF/1 and HP-UX. +ac_max_sed_cmds=90 # Maximum number of lines to put in a sed script. +ac_file=1 # Number of current file. +ac_beg=1 # First line for current file. +ac_end=$ac_max_sed_cmds # Line after last line for current file. +ac_more_lines=: +ac_sed_cmds="" +while $ac_more_lines; do + if test $ac_beg -gt 1; then + sed "1,${ac_beg}d; ${ac_end}q" conftest.subs > conftest.s$ac_file + else + sed "${ac_end}q" conftest.subs > conftest.s$ac_file + fi + if test ! -s conftest.s$ac_file; then + ac_more_lines=false + rm -f conftest.s$ac_file + else + if test -z "$ac_sed_cmds"; then + ac_sed_cmds="sed -f conftest.s$ac_file" + else + ac_sed_cmds="$ac_sed_cmds | sed -f conftest.s$ac_file" + fi + ac_file=`expr $ac_file + 1` + ac_beg=$ac_end + ac_end=`expr $ac_end + $ac_max_sed_cmds` + fi +done +if test -z "$ac_sed_cmds"; then + ac_sed_cmds=cat +fi +EOF + +cat >> $CONFIG_STATUS <<EOF + +CONFIG_FILES=\${CONFIG_FILES-"Makefile \ +util/Makefile \ +util/Transcoders/ICU/Makefile \ +util/Transcoders/Iconv/Makefile \ +util/Platforms/Makefile \ +util/Compilers/Makefile \ +util/MsgLoaders/InMemory/Makefile \ +util/MsgLoaders/ICU/Makefile \ +util/MsgLoaders/MsgCatalog/Makefile \ +validators/DTD/Makefile \ +framework/Makefile \ +dom/Makefile \ +parsers/Makefile \ +internal/Makefile \ +sax/Makefile \ +../obj/Makefile"} +EOF +cat >> $CONFIG_STATUS <<\EOF +for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then + # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". + case "$ac_file" in + *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` + ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; + *) ac_file_in="${ac_file}.in" ;; + esac + + # Adjust a relative srcdir, top_srcdir, and INSTALL for subdirectories. + + # Remove last slash and all that follows it. Not all systems have dirname. + ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` + if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then + # The file is in a subdirectory. + test ! -d "$ac_dir" && mkdir "$ac_dir" + ac_dir_suffix="/`echo $ac_dir|sed 's%^\./%%'`" + # A "../" for each directory in $ac_dir_suffix. + ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` + else + ac_dir_suffix= ac_dots= + fi + + case "$ac_given_srcdir" in + .) srcdir=. + if test -z "$ac_dots"; then top_srcdir=. + else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; + /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; + *) # Relative path. + srcdir="$ac_dots$ac_given_srcdir$ac_dir_suffix" + top_srcdir="$ac_dots$ac_given_srcdir" ;; + esac + + case "$ac_given_INSTALL" in + [/$]*) INSTALL="$ac_given_INSTALL" ;; + *) INSTALL="$ac_dots$ac_given_INSTALL" ;; + esac + + echo creating "$ac_file" + rm -f "$ac_file" + configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." + case "$ac_file" in + *Makefile*) ac_comsub="1i\\ +# $configure_input" ;; + *) ac_comsub= ;; + esac + + ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` + sed -e "$ac_comsub +s%@configure_input@%$configure_input%g +s%@srcdir@%$srcdir%g +s%@top_srcdir@%$top_srcdir%g +s%@INSTALL@%$INSTALL%g +" $ac_file_inputs | (eval "$ac_sed_cmds") > $ac_file +fi; done +rm -f conftest.s* + +EOF +cat >> $CONFIG_STATUS <<EOF + +EOF +cat >> $CONFIG_STATUS <<\EOF + +exit 0 +EOF +chmod +x $CONFIG_STATUS +rm -fr confdefs* $ac_clean_files +test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1 + diff --git a/src/configure.in b/src/configure.in new file mode 100644 index 0000000000000000000000000000000000000000..7fbc01d73619707ad508f206af8ce0c478e2a5d5 --- /dev/null +++ b/src/configure.in @@ -0,0 +1,99 @@ +dnl Process this file with autoconf to produce a configure script +AC_INIT(util/XML4CDefs.hpp) +dnl AC_CONFIG_HEADER(common/icucfg.h) + +dnl Checks for programs +AC_PROG_CC +AC_PROG_CXX +AC_PROG_INSTALL +AC_CHECK_PROG(AUTOCONF, autoconf, autoconf, true) + +dnl Checks for libraries +AC_CHECK_LIB(m, floor) + +dnl special pthread handling (AIX uses pthreads instead of pthread) +AC_CHECK_LIB(pthread, pthread_create) +if test $ac_cv_lib_pthread_pthread_create = no; then +AC_CHECK_LIB(pthreads, pthread_create) +fi + +dnl Checks for header files +AC_CHECK_HEADERS(inttypes.h) +if test $ac_cv_header_inttypes_h = no; then +HAVE_INTTYPES_H=0 +else +HAVE_INTTYPES_H=1 +fi +AC_SUBST(HAVE_INTTYPES_H) + +dnl Checks for typedefs +AC_CHECK_TYPE(XMLByte,unsigned char) + +dnl Determine the host system and Makefile fragment +AC_CANONICAL_HOST + +dnl Platform-specific Makefile setup +case "${host}" in + *-*-solaris*) platform=SOLARIS ;; + *-*-linux*) platform=LINUX ;; + *-*-aix*) platform=AIX ;; + *-*-hp*) platform=HPUX ; + case "${host}" in + *-*-hpux11*) osver=HPUX11;; + *-*-hpux10*) osver=HPUX10;; + *) osver=HPUX11;; + esac;; + *-*-mvs*) platform=OS390 ;; + *) platform=UNKNOWN ;; +esac +AC_SUBST(platform) + +compiler=${CXX} +AC_SUBST(compiler) + +# prefix=${prefix} +AC_SUBST(prefix) + +AC_SUBST(osver) + +cxxflags=${CXXFLAGS} +AC_SUBST(cxxflags) + +cppflags=${CPPFLAGS} +AC_SUBST(cppflags) + +cflags=${CFLAGS} +AC_SUBST(cflags) + +ldflags=${LDCFLAGS} +AC_SUBST(ldflags) + +libs=${LIBS} +AC_SUBST(libs) + +uselibwww=${USELIBWWW} +AC_SUBST(uselibwww) + +messageloader=${MESSAGELOADER} +AC_SUBST(messageloader) + +transcoder=${TRANSCODER} +AC_SUBST(transcoder) + +dnl output the Makefiles +AC_OUTPUT([Makefile \ +util/Makefile \ +util/Transcoders/ICU/Makefile \ +util/Transcoders/Iconv/Makefile \ +util/Platforms/Makefile \ +util/Compilers/Makefile \ +util/MsgLoaders/InMemory/Makefile \ +util/MsgLoaders/ICU/Makefile \ +util/MsgLoaders/MsgCatalog/Makefile \ +validators/DTD/Makefile \ +framework/Makefile \ +dom/Makefile \ +parsers/Makefile \ +internal/Makefile \ +sax/Makefile \ +../obj/Makefile]) diff --git a/src/install-sh b/src/install-sh new file mode 100644 index 0000000000000000000000000000000000000000..e9de23842dcd44d2953129c866b1ad25f7e1f1d9 --- /dev/null +++ b/src/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + true +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=mkdir + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f $src -o -d $src ] + then + true + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + true + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + true + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' +' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + true + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + true + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/src/runConfigure b/src/runConfigure new file mode 100755 index 0000000000000000000000000000000000000000..391d8d4ab646e0c396ff6aa434a87cc2115ede3a --- /dev/null +++ b/src/runConfigure @@ -0,0 +1,328 @@ +#!/bin/sh + + +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:02:57 twl +# Initial revision +# +# Revision 1.4 1999/11/08 20:44:09 rahul +# Swat for adding in Product name and CVS comment log variable. +# +# + +# +# runConfigure : This script will run the "configure" script for the appropriate platform +# Only supported platforms are recognized + +usage() +{ + echo "runConfigure: Helper script to run \"configure\" for one of the supported platforms" + echo "Usage: runConfigure \"options\"" + echo " where options may be any of the following:" + echo " -p <platform> (accepts 'aix', 'linux', 'solaris', 'hp-10', 'hp-11')" + echo " -c <C compiler name> (e.g. gcc or xlc)" + echo " -x <C++ compiler name> (e.g. g++ or xlC)" + echo " -d (specifies that you want to build debug version)" + echo " -m <message loader> can be 'inmem', 'icu' or 'iconv'" + echo " -n <net accessor> can be 'fileonly' or 'libwww'" + echo " -t <transcoder> can be 'icu' or 'native'" + echo " -r <thread option> can be 'pthread' or 'dce' (only used on HP-11)" + echo " -l <extra linker options>" + echo " -z <extra compiler options>" + echo " -h (to get help on the above commands)" +} + +if test ${1}o = "o"; then + usage + exit -1 +fi + +if test ${XML4CROOT}o = "o"; then + echo ERROR : You have not set your XML4CROOT environment variable + echo Though this environment variable has nothing to do with creating makefiles, + echo this is just a general warning to prevent you from pitfalls in future. Please + echo set an environment variable called XML4CROOT to indicate where you installed + echo the XML4C files, and run this command again to proceed. See the documentation + echo for an example if you are still confused. + exit -1 +fi + +if test $1 = "-h"; then + usage + exit -1 +fi + +# Get the command line parameters +set -- `getopt p:c:x:dm:n:t:r:l:z:h $*` +if [ $? != 0 ] + then + usage + exit -1 +fi + +# Set up the default values for each parameter +debug=off # by default debug is off +transcoder=native # by default use native transcoder +msgloader=iconv # by default use native transcoder +netaccessor=fileonly # by default use fileonly + +for i in $* + do + case $i in + -p) + platform=$2; shift 2;; + + -c) + ccompiler=$2; shift 2;; + + -x) + cppcompiler=$2; shift 2;; + + -d) + debug=on; shift;; + + -m) + msgloader=$2; shift 2;; + + -n) + netaccessor=$2; shift 2;; + + -t) + transcoder=$2; shift 2;; + + -r) + thread=$2; shift 2;; + + -l) + linkeroption=$2; shift 2;; + + -z) + compileroption=$2; shift 2;; + + -h) + usage + exit -1;; + + --) + shift; break;; + esac +done + +echo "Generating makefiles with the following options ..." +echo "Platform: $platform" +echo "C Compiler: $ccompiler" +echo "C++ Compiler: $cppcompiler" +echo "Extra compile options: $compileroption" +echo "Extra link options: $linkeroption" +if test $debug = "off"; then + echo "Debug is OFF" + debugflag="-w -O"; +else + echo "Debug is ON" + debugflag="-g"; +fi +echo "Message Loader: $msgloader" +echo "Net Accessor: $netaccessor" +echo "Transcoder: $transcoder" +echo "Thread option: $thread" + +# Now check if the options are correct or not, bail out if incorrect +case $platform in + aix | linux | solaris | hp-10 | hp-11) + # platform has been recognized + ;; + *) + echo "I do not recognize the platform '$platform'. Please type '${0} -h' for help." + exit -1;; +esac + +# Now check for the transcoder +transcoderoption="-DXML_USE_NATIVE_TRANSCODER" +TRANSCODER=NATIVE + +if test $transcoder; then +case $transcoder in + icu) + transcoderoption="-DXML_USE_ICU_TRANSCODER" ; + TRANSCODER=ICU ;; + + native) + transcoderoption="-DXML_USE_NATIVE_TRANSCODER" ; + TRANSCODER=NATIVE ;; + + *) + echo "I do not recognize the transcoder option '$transcoder'. Please type '${0} -h' for help." + exit -1;; +esac +fi + +export TRANSCODER + +# Now check for the message loader +MESSAGELOADER=INMEM; # By default use in-memory +msgloaderoption="-DXML_USE_INMEM_MESSAGELOADER" + +if test $msgloader ; then +case $msgloader in + icu) + MESSAGELOADER=ICU; + msgloaderoption="-DXML_USE_ICU_MESSAGELOADER" ;; + + inmem) + MESSAGELOADER=INMEM; + msgloaderoption="-DXML_USE_INMEM_MESSAGELOADER" ;; + + iconv) + MESSAGELOADER=ICONV; + msgloaderoption="-DXML_USE_ICONV_MESSAGELOADER" ;; + + *) + echo "I do not recognize the message loader option '$msgloader'. Please type '${0} -h' for help." + exit -1;; +esac +fi + +export MESSAGELOADER + +# Check for the threading option only for hp-11 +if test $platform = "hp-11"; then + if test $thread; then + case $thread in + pthread) + threadingoption="-DXML_USE_PTHREAD" ;; + + dce) + threadingoption="-DXML_USE_DCE" ;; + + *) + echo "I do not recognize the thread option '$thread'. Please type '${0} -h' for help." + exit -1;; + esac + else + echo "You must provide a thread option for HPUX-11". Cannot proceed any further. + exit -1; + fi +fi + +# Set the C compiler and C++ compiler environment variables +CC=$ccompiler; export CC +CXX=$cppcompiler; export CXX + +case $cppcompiler in + xlC | xlc | xlC_r | xlc_r) + LDFLAGS="-lC"; export LDFLAGS + LIBS="-L/usr/lpp/xlC/lib"; export LIBS ;; + + g++ | c++) + LDFLAGS="-lc"; export LDFLAGS + LIBS="-L/usr/local/lib"; export LIBS ;; + + cc | CC) + LDFLAGS="-lC"; export LDFLAGS + LIBS="-L/usr/lib -L/usr/ccs/lib"; export LIBS ;; + + acc | aCC) + LDFLAGS="-lC"; export LDFLAGS + LIBS="-L/usr/lib -L/opt/aCC/lib"; export LIBS ;; + + *) + echo "I do not recognize the C++ compiler '$cppcompiler'. Continuing anyway ..." + ;; +esac + +USELIBWWW=0; # By default use file-only +# Check for the type of net accessor +if test $netaccessor ; then +case $netaccessor in + fileonly) + netaccessoroption="" ;; + + libwww) + if test -z ${LIBWWWROOT} ; then + echo "You have not defined your LIBWWWROOT environment variable. Cannot proceed further ..." + exit -1; + fi + netaccessoroption="-DXML_USE_NETACCESSOR_LIBWWW -I${LIBWWWROOT}/include" ; + LIBS="$LIBS -L${LIBWWWROOT}/lib -lwww"; + USELIBWWW=1;; + + *) + echo "I do not recognize the netaccessor option '$netaccessor'. Please type '${0} -h' for help." + exit -1;; +esac +fi + +export USELIBWWW; + +# Set the extra C and C++ compiler flags +CXXFLAGS="$debugflag $compileroption $transcoderoption $msgloaderoption $threadingoption $netaccessoroption"; export CXXFLAGS +CFLAGS="$debugflag $compileroption $transcoderoption $msgloaderoption $threadingoption $netaccessoroption"; export CFLAGS + +echo +rm -f config.cache +rm -f config.log +rm -f config.status +./configure + +echo +echo If the result of the above commands look OK to you, go to the directory +echo ${XML4CROOT}/src and type \"make\" to make the XML4C system. + +exit 0; + diff --git a/src/util/ArrayIndexOutOfBoundsException.hpp b/src/util/ArrayIndexOutOfBoundsException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..33b94ba2d25dd8153ee533d50cf5aa28e3a1ff55 --- /dev/null +++ b/src/util/ArrayIndexOutOfBoundsException.hpp @@ -0,0 +1,87 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:52 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:03 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(ARRAYINDEXOUTOFBOUNDSEXCEPTION_HPP) +#define ARRAYINDEXOUTOFBOUNDSEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLUni.hpp> +#include <util/XMLException.hpp> + + +static const XMLCh gArrayIndexOutOfBoundsException_Name[] = +{ + chLatin_A, chLatin_r, chLatin_r, chLatin_a, chLatin_y, chLatin_I + , chLatin_n, chLatin_d, chLatin_e, chLatin_x, chLatin_O, chLatin_u + , chLatin_t, chLatin_o, chLatin_f, chLatin_B, chLatin_o, chLatin_u + , chLatin_n, chLatin_d, chLatin_s, chLatin_E, chLatin_x, chLatin_c + , chLatin_e, chLatin_p, chLatin_t, chLatin_i, chLatin_o, chLatin_n + , chNull +}; + +MakeXML4CException(ArrayIndexOutOfBoundsException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/AutoSense.hpp b/src/util/AutoSense.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3295062d17d3cf0f92c820bac8741ac363accab8 --- /dev/null +++ b/src/util/AutoSense.hpp @@ -0,0 +1,176 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:55 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:03 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#ifndef AUTOSENSE_HPP +#define AUTOSENSE_HPP + +// --------------------------------------------------------------------------- +// This section attempts to auto detect the operating system. It will set +// up XML4C specific defines that are used by the rest of the code. +// --------------------------------------------------------------------------- +#if defined(_AIX) + #define XML_AIX + #define XML_UNIX +#elif defined(_HP_UX) \ +|| defined(__hpux) \ +|| defined(_HPUX_SOURCE) + #define XML_HPUX + #define XML_UNIX +#elif defined(SOLARIS) || defined(__SVR4) + #define XML_SOLARIS + #define XML_UNIX +#elif defined(__linux__) + #define XML_LINUX + #define XML_UNIX +#elif defined(__MVS__) + #define XML_OE390 + #define XML_UNIX +#elif defined(AS400) + #define XML_AS400 + #define XML_UNIX +#elif defined(__OS2__) + #define XML_OS2 +#elif defined(__TANDEM) + #define XML_TANDEM + #define XML_UNIX + #define XML_CSET +#elif defined(_WIN32) \ +|| defined(WIN32) + #define XML_WIN32 + #ifndef WIN32 + #define WIN32 + #endif +#elif defined(__WINDOWS__) + + // IBM VisualAge special handling + #if defined(__32BIT__) + #define XML_WIN32 + #else + #define XML_WIN16 + #endif + #elif defined(__MSDXML__) + #define XML_DOS + +#elif defined(macintosh) + #define XML_MACOS +#else + #error Code requires port to host OS! +#endif + + +// --------------------------------------------------------------------------- +// This section attempts to autodetect the compiler being used. It will set +// up XML4C specific defines that can be used by the rest of the code. +// --------------------------------------------------------------------------- +#if defined(_MSC_VER) + #define XML_VISUALCPP +#elif defined(__BORLANDC__) + #define XML_BORLAND +#elif defined(__xlC__) + #define XML_CSET +#elif defined(XML_SOLARIS) + #if defined(__SUNPRO_CC) + #define XML_SUNCC + #elif defined(_EDG_RUNTIME_USES_NAMESPACES) + #define XML_SOLARIS_KAICC + #elif defined(__GNUG__) + #define XML_GNUG + #endif +#elif defined(__GNUG__) + #define XML_GNUG +#elif defined(XML_HPUX) + #if defined(EXM_HPUX) + #define XML_HPUX_KAICC + #elif (__cplusplus == 1) + #define XML_HPUX_CC + #elif (__cplusplus == 199707 || __cplusplus == 199711) + #define XML_HPUX_aCC + #endif +#elif defined(XML_TANDEM) + #define XML_TANDEMCC +#elif defined(__linux__) + #define XML_GCC +#elif defined(__MVS__) && defined(__cplusplus) + #define XML_MVSCPP +#elif defined(__IBMCPP__) + #if defined(XML_WIN32) + #define XML_IBMVAW32 + #elif defined(XML_OS2) + #define XML_IBMVAOS2 + #endif +#elif defined(__IBMC__) + #if defined(XML_WIN32) + #define XML_IBMVAW32 + #elif defined(XML_OS2) + #define XML_IBMVAOS2 + #endif +#elif defined(__MWERKS__) + #define XML_METROWERKS +#else + #error Code requires port to current development environment +#endif + +#endif diff --git a/src/util/BinFileInputStream.cpp b/src/util/BinFileInputStream.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8fca7a28225b7f0ecd2a3b25ed386ec53470168e --- /dev/null +++ b/src/util/BinFileInputStream.cpp @@ -0,0 +1,155 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:59 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:56:55 droddey + * If the main xml entity does not exist, we need to get the error handling for that + * inside the main XMLScanner::scanDocument() try block so that it gets reported + * in the normal way. We have to add a little extra safety code because, when this + * happens, there is no reader on the reader stack to get position ino from. + * + * Revision 1.3 1999/11/08 20:45:03 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/BinFileInputStream.hpp> +#include <util/Janitor.hpp> +#include <util/PlatformUtils.hpp> +#include <util/XMLExceptMsgs.hpp> +#include <util/XMLString.hpp> + + +// --------------------------------------------------------------------------- +// BinFileInputStream: Constructors and Destructor +// --------------------------------------------------------------------------- +BinFileInputStream::BinFileInputStream(const XMLCh* const fileName) : + + fSource(0) +{ + // Try to open the file + fSource = XMLPlatformUtils::openFile(fileName); +} + +BinFileInputStream::BinFileInputStream(const char* const fileName) : + + fSource(0) +{ + // Transcode the file name and put a janitor on the temp buffer + XMLCh* realName = XMLString::transcode(fileName); + ArrayJanitor<XMLCh> janName(realName); + + // Try to open the file + fSource = XMLPlatformUtils::openFile(realName); +} + +BinFileInputStream::BinFileInputStream(const FileHandle toAdopt) : + + fSource(toAdopt) +{ +} + +BinFileInputStream::~BinFileInputStream() +{ + if (fSource) + XMLPlatformUtils::closeFile(fSource); +} + + +// --------------------------------------------------------------------------- +// BinFileInputStream: Getter methods +// --------------------------------------------------------------------------- +unsigned int BinFileInputStream::getSize() const +{ + return XMLPlatformUtils::fileSize(fSource); +} + + +// --------------------------------------------------------------------------- +// BinFileInputStream: Stream management methods +// --------------------------------------------------------------------------- +void BinFileInputStream::reset() +{ + XMLPlatformUtils::resetFile(fSource); +} + + +// --------------------------------------------------------------------------- +// BinFileInputStream: Implementation of the input stream interface +// --------------------------------------------------------------------------- +unsigned int BinFileInputStream::curPos() const +{ + return XMLPlatformUtils::curFilePos(fSource); +} + +unsigned int +BinFileInputStream::readBytes( XMLByte* const toFill + , const unsigned int maxToRead) +{ + // + // Read up to the maximum bytes requested. We return the number + // actually read. + // + return XMLPlatformUtils::readFileBuffer(fSource, maxToRead, toFill); +} diff --git a/src/util/BinFileInputStream.hpp b/src/util/BinFileInputStream.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b560b3b613580d0c3710df487db34197995b93be --- /dev/null +++ b/src/util/BinFileInputStream.hpp @@ -0,0 +1,137 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:00 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:03 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(BINFILEINPUTSTREAM_HPP) +#define BINFILEINPUTSTREAM_HPP + +#include <util/BinInputStream.hpp> + + +class XMLUTIL_EXPORT BinFileInputStream : public BinInputStream +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + BinFileInputStream + ( + const XMLCh* const fileName + ); + + BinFileInputStream + ( + const char* const fileName + ); + + BinFileInputStream + ( + const FileHandle toUse + ); + + virtual ~BinFileInputStream(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool getIsOpen() const; + unsigned int getSize() const; + void reset(); + + + // ----------------------------------------------------------------------- + // Implementation of the input stream interface + // ----------------------------------------------------------------------- + virtual unsigned int curPos() const; + + virtual unsigned int readBytes + ( + XMLByte* const toFill + , const unsigned int maxToRead + ); + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fSource + // The source file that we represent. The FileHandle type is defined + // per platform. + // ----------------------------------------------------------------------- + FileHandle fSource; +}; + + +// --------------------------------------------------------------------------- +// BinFileInputStream: Getter methods +// --------------------------------------------------------------------------- +inline bool BinFileInputStream::getIsOpen() const +{ + return (fSource != 0); +} + +#endif diff --git a/src/util/BinInputStream.cpp b/src/util/BinInputStream.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd688bc22490790afce9966e15ca575a21ca1d79 --- /dev/null +++ b/src/util/BinInputStream.cpp @@ -0,0 +1,87 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:02 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:04 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/BinInputStream.hpp> + + +// --------------------------------------------------------------------------- +// BinInputStream: Virtual destructor! +// --------------------------------------------------------------------------- +BinInputStream::~BinInputStream() +{ +} + + +// --------------------------------------------------------------------------- +// BinInputStream: Hidden Constructors +// --------------------------------------------------------------------------- +BinInputStream::BinInputStream() +{ +} diff --git a/src/util/BinInputStream.hpp b/src/util/BinInputStream.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4454d3b5fbe6a9bad65b2e400b669d6c297fb836 --- /dev/null +++ b/src/util/BinInputStream.hpp @@ -0,0 +1,108 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:03 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:04 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(BININPUTSTREAM_HPP) +#define BININPUTSTREAM_HPP + +#include <util/XML4CDefs.hpp> + +class XMLUTIL_EXPORT BinInputStream +{ +public : + // ----------------------------------------------------------------------- + // Virtual destructor for derived classes + // ----------------------------------------------------------------------- + virtual ~BinInputStream(); + + + // ----------------------------------------------------------------------- + // The virtual input stream interface + // ----------------------------------------------------------------------- + virtual unsigned int curPos() const = 0; + + virtual unsigned int readBytes + ( + XMLByte* const toFill + , const unsigned int maxToRead + ) = 0; + + +protected : + // ----------------------------------------------------------------------- + // Hidden Constructors + // ----------------------------------------------------------------------- + BinInputStream(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented Constructors + // ----------------------------------------------------------------------- + BinInputStream(const BinInputStream&); + void operator=(const BinInputStream&); +}; + +#endif diff --git a/src/util/BinMemInputStream.cpp b/src/util/BinMemInputStream.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb441b4b3a764d7e587225e9bd14debc8bb39231 --- /dev/null +++ b/src/util/BinMemInputStream.cpp @@ -0,0 +1,130 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:05 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:04 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/BinMemInputStream.hpp> +#include <memory.h> +#include <string.h> + + +// --------------------------------------------------------------------------- +// BinMemInputStream: Constructors and Destructor +// --------------------------------------------------------------------------- +BinMemInputStream::BinMemInputStream( const XMLByte* const initData + , const unsigned int capacity + , const BufOpts bufOpt) : + fBuffer(0) + , fBufOpt(bufOpt) + , fCapacity(capacity) + , fCurIndex(0) +{ + // According to the buffer option, do the right thing + if (fBufOpt == BufOpt_Copy) + { + XMLByte* tmpBuf = new XMLByte[fCapacity]; + memcpy(tmpBuf, initData, capacity); + fBuffer = tmpBuf; + } + else + { + fBuffer = initData; + } +} + +BinMemInputStream::~BinMemInputStream() +{ + // + // If we adopted or copied the buffer, then clean it up. We have to + // cast off the const'ness in that case in order to delete it. + // + if ((fBufOpt == BufOpt_Adopt) || (fBufOpt == BufOpt_Copy)) + delete [] (XMLByte*)fBuffer; +} + + +// --------------------------------------------------------------------------- +// MemBinInputStream: Implementation of the input stream interface +// --------------------------------------------------------------------------- +unsigned int BinMemInputStream::readBytes( XMLByte* const toFill + , const unsigned int maxToRead) +{ + // + // Figure out how much we can really read. Its the smaller of the + // amount available and the amount asked for. + // + const unsigned int available = (fCapacity - fCurIndex); + if (!available) + return 0; + + const unsigned int actualToRead = available < maxToRead ? + available : maxToRead; + for (unsigned int index = 0; index < actualToRead; index++) + toFill[index] = fBuffer[fCurIndex++]; + return actualToRead; +} diff --git a/src/util/BinMemInputStream.hpp b/src/util/BinMemInputStream.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8f765f66d204dd79cbe172d239e3c050d090f8c2 --- /dev/null +++ b/src/util/BinMemInputStream.hpp @@ -0,0 +1,159 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:07 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:04 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(BINMEMINPUTSTREAM_HPP) +#define BINMEMINPUTSTREAM_HPP + +#include <util/BinInputStream.hpp> + + +class XMLUTIL_EXPORT BinMemInputStream : public BinInputStream +{ +public : + // ----------------------------------------------------------------------- + // Class specific types + // ----------------------------------------------------------------------- + enum BufOpts + { + BufOpt_Adopt + , BufOpt_Copy + , BufOpt_Reference + }; + + + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + BinMemInputStream + ( + const XMLByte* const initData + , const unsigned int capacity + , const BufOpts bufOpt = BufOpt_Copy + ); + virtual ~BinMemInputStream(); + + + // ----------------------------------------------------------------------- + // Stream management methods + // ----------------------------------------------------------------------- + void reset(); + + + // ----------------------------------------------------------------------- + // Implementation of the input stream interface + // ----------------------------------------------------------------------- + virtual unsigned int curPos() const; + virtual unsigned int readBytes + ( + XMLByte* const toFill + , const unsigned int maxToRead + ); + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fBuffer + // The buffer of bytes that we are streaming. + // + // fBufOpt + // Indicates the ownership status of the buffer. The caller can have + // us adopt it (we delete it), reference it, or just make our own + // copy of it. + // + // fCapacity + // The size of the buffer being streamed. + // + // fCurIndex + // The current index where the next byte will be read from. When it + // hits fCapacity, we are done. + // ----------------------------------------------------------------------- + const XMLByte* fBuffer; + BufOpts fBufOpt; + unsigned int fCapacity; + unsigned int fCurIndex; +}; + + +// --------------------------------------------------------------------------- +// BinMemInputStream: Stream management methods +// --------------------------------------------------------------------------- +inline void BinMemInputStream::reset() +{ + fCurIndex = 0; +} + + +// --------------------------------------------------------------------------- +// BinMemInputStream: Implementation of the input stream interface +// --------------------------------------------------------------------------- +inline unsigned int BinMemInputStream::curPos() const +{ + return fCurIndex; +} + +#endif diff --git a/src/util/BitOps.hpp b/src/util/BitOps.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9c8411819e68b43a9f98e06e79d6e098a9b68cdb --- /dev/null +++ b/src/util/BitOps.hpp @@ -0,0 +1,106 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:08 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(BITOPS_HPP) +#define BITOPS_HPP + +#include <util/XML4CDefs.hpp> + + +class XMLUTIL_EXPORT BitOps +{ +public: + // ----------------------------------------------------------------------- + // Public static methods + // ----------------------------------------------------------------------- + static inline XMLCh swapBytes(const XMLUInt16 toSwap) + { + return XMLCh((toSwap >> 8) | (toSwap << 8)); + } + + static inline unsigned int swapBytes(const XMLUInt32 toSwap) + { + return + ( + (toSwap >> 24) + | (toSwap << 24) + | ((toSwap & 0xFF00) << 8) + | ((toSwap & 0xFF0000) >> 8) + ); + } + + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + BitOps(); + BitOps(const BitOps&); + void operator=(const BitOps); +}; + +#endif diff --git a/src/util/BitSet.cpp b/src/util/BitSet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d873d3c1f75a4d3c47950a6c7be0f202d7c8619f --- /dev/null +++ b/src/util/BitSet.cpp @@ -0,0 +1,305 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:09 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/IllegalArgumentException.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/BitSet.hpp> + + +// --------------------------------------------------------------------------- +// Local const data +// +// kBitsPerUnit +// The number of bits in each of our allocation units, which is a 32 +// bit value in this case. +// +// kGrowBy +// The minimum allocation units to grow the buffer by. +// --------------------------------------------------------------------------- +const unsigned int kBitsPerUnit = 32; +const unsigned int kGrowBy = 1; + + + +// --------------------------------------------------------------------------- +// BitSet: Constructors and Destructor +// --------------------------------------------------------------------------- +BitSet::BitSet(const unsigned int size) : + + fBits(0) + , fUnitLen(0) +{ + ensureCapacity(size); +} + +BitSet::BitSet(const BitSet& toCopy) : + + fBits(0) + , fUnitLen(toCopy.fUnitLen) +{ + fBits = new unsigned long[fUnitLen]; + for (unsigned int i = 0; i < fUnitLen; i++) + fBits[i] = toCopy.fBits[i]; +} + +BitSet::~BitSet() +{ + delete [] fBits; +} + + +// --------------------------------------------------------------------------- +// BitSet: Equality methods +// --------------------------------------------------------------------------- +bool BitSet::equals(const BitSet& other) const +{ + if (this == &other) + return true; + + if (fUnitLen != other.fUnitLen) + return false; + + for (unsigned int i = 0; i < fUnitLen; i++) + { + if (fBits[i] != other.fBits[i]) + return false; + } + return true; +} + + +// --------------------------------------------------------------------------- +// BitSet: Getter methods +// --------------------------------------------------------------------------- +bool BitSet::get(const unsigned int index) const +{ + const unsigned int unitOfBit = (index / kBitsPerUnit); + const unsigned int bitWithinUnit = index % kBitsPerUnit; + + // + // If the index is beyond our size, don't actually expand. Just return + // false, which is what the state would be if we did expand it. + // + bool retVal = false; + if (unitOfBit <= fUnitLen) + { + if (fBits[unitOfBit] & (1 << bitWithinUnit)) + retVal = true; + } + return retVal; +} + + +unsigned int BitSet::size() const +{ + return fUnitLen * kBitsPerUnit; +} + + + +// --------------------------------------------------------------------------- +// BitSet: Setter methods +// --------------------------------------------------------------------------- +bool BitSet::allAreCleared() const +{ + for (unsigned int index = 0; index < fUnitLen; index++) + { + if (fBits[index]) + return false; + } + return true; +} + +bool BitSet::allAreSet() const +{ + for (unsigned int index = 0; index < fUnitLen; index++) + { + if (fBits[index] != 0xFFFFFFFF) + return false; + } + return true; +} + +void BitSet::clearAll() +{ + // Just zero out all the units + for (unsigned int index = 0; index < fUnitLen; index++) + fBits[index] = 0; +} + +void BitSet::clear(const unsigned int index) +{ + ensureCapacity(index+1); + + const int unitOfBit = (index / kBitsPerUnit); + const int bitWithinUnit = index % kBitsPerUnit; + + fBits[unitOfBit] &= ~(1UL << bitWithinUnit); +} + + +void BitSet::set(const unsigned int index) +{ + ensureCapacity(index+1); + + const int unitOfBit = (index / kBitsPerUnit); + const int bitWithinUnit = index % kBitsPerUnit; + + fBits[unitOfBit] |= (1UL << bitWithinUnit); +} + + + +// --------------------------------------------------------------------------- +// BitSet: Bitwise logical methods +// --------------------------------------------------------------------------- +void BitSet::andWith(const BitSet& other) +{ + if (fUnitLen < other.fUnitLen) + ensureCapacity(other.fUnitLen * kBitsPerUnit); + + for (unsigned int index = 0; index < other.fUnitLen; index++) + fBits[index] &= other.fBits[index]; +} + + +void BitSet::orWith(const BitSet& other) +{ + if (fUnitLen < other.fUnitLen) + ensureCapacity(other.fUnitLen * kBitsPerUnit); + + for (unsigned int index = 0; index < other.fUnitLen; index++) + fBits[index] |= other.fBits[index]; +} + + +void BitSet::xorWith(const BitSet& other) +{ + if (fUnitLen < other.fUnitLen) + ensureCapacity(other.fUnitLen * kBitsPerUnit); + + for (unsigned int index = 0; index < other.fUnitLen; index++) + fBits[index] ^= other.fBits[index]; +} + + + +// --------------------------------------------------------------------------- +// BitSet: Miscellaneous methods +// --------------------------------------------------------------------------- +unsigned int BitSet::hash(const unsigned int hashModulus) const +{ + const unsigned char* pBytes = (const unsigned char*)fBits; + const int unsigned len = fUnitLen * sizeof(unsigned long); + + unsigned int hashVal = 0; + for (unsigned int index = 0; index < len; index++) + { + hashVal <<= 1; + hashVal ^= *pBytes; + } + return hashVal % hashModulus; +} + + + +// --------------------------------------------------------------------------- +// BitSet: Private methods +// --------------------------------------------------------------------------- +void BitSet::ensureCapacity(const unsigned int size) +{ + // Calculate the units required to hold the passed bit count. + unsigned int unitsNeeded = size / kBitsPerUnit; + if (size % kBitsPerUnit) + unitsNeeded++; + + // If its more than we have, then reallocate + if (unitsNeeded > fUnitLen) + { + // Regrow the unit length by at least the expansion unit + if (unitsNeeded < (fUnitLen + kGrowBy)) + unitsNeeded = fUnitLen + kGrowBy; + + // Allocate the array, copy the old stuff, and zero the new stuff + unsigned long* newBits = new unsigned long[unitsNeeded]; + + unsigned int index; + for (index = 0; index < fUnitLen; index++) + newBits[index] = fBits[index]; + + for (; index < unitsNeeded; index++) + newBits[index] = 0; + + delete [] fBits; + fBits = newBits; + fUnitLen = unitsNeeded; + } +} diff --git a/src/util/BitSet.hpp b/src/util/BitSet.hpp new file mode 100644 index 0000000000000000000000000000000000000000..698013113378a0dfac6bbcf5464e7bd604477541 --- /dev/null +++ b/src/util/BitSet.hpp @@ -0,0 +1,146 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:11 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(BITSET_HPP) +#define BITSET_HPP + +#include <util/XML4CDefs.hpp> + +class XMLUTIL_EXPORT BitSet +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + BitSet(const unsigned int size); + BitSet(const BitSet& toCopy); + ~BitSet(); + + + // ----------------------------------------------------------------------- + // Equality methods + // ----------------------------------------------------------------------- + bool equals(const BitSet& other) const; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool allAreCleared() const; + bool allAreSet() const; + unsigned int size() const; + bool get(const unsigned int index) const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void clear(const unsigned int index); + void clearAll(); + void set(const unsigned int index); + + + // ----------------------------------------------------------------------- + // Bitwise logical operations + // ----------------------------------------------------------------------- + void andWith(const BitSet& other); + void orWith(const BitSet& other); + void xorWith(const BitSet& other); + + + // ----------------------------------------------------------------------- + // Miscellaneous + // ----------------------------------------------------------------------- + unsigned int hash(const unsigned int hashModulus) const; + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors + // ----------------------------------------------------------------------- + BitSet(); + + + // ----------------------------------------------------------------------- + // Private methods + // ----------------------------------------------------------------------- + void ensureCapacity(const unsigned int bits); + + + // ----------------------------------------------------------------------- + // Data members + // + // fBits + // The array of unsigned longs used to store the bits. + // + // fUnitLen + // The length of the storage array, in storage units not bits. + // ----------------------------------------------------------------------- + unsigned long* fBits; + unsigned int fUnitLen; +}; + +#endif diff --git a/src/util/Compilers/BorlandCDefs.hpp b/src/util/Compilers/BorlandCDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7c608294507d5672ff1e6b184b2868561cc7d04f --- /dev/null +++ b/src/util/Compilers/BorlandCDefs.hpp @@ -0,0 +1,97 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:28 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:22 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// A define in the build for each project is also used to control whether +// the export keyword is from the project's viewpoint or the client's. +// These defines provide the platform specific keywords that they need +// to do this. +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT __declspec(dllexport) +#define PLATFORM_IMPORT __declspec(dllimport) + + + +// --------------------------------------------------------------------------- +// Indicate that we support native bools +// --------------------------------------------------------------------------- +// #define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XML character +// --------------------------------------------------------------------------- +typedef wchar_t XMLCh; + + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#ifdef _DEBUG +#define XML4C_DEBUG +#endif diff --git a/src/util/Compilers/CSetDefs.cpp b/src/util/Compilers/CSetDefs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf23585c644c9b42863fa2711314203763a4d5f7 --- /dev/null +++ b/src/util/Compilers/CSetDefs.cpp @@ -0,0 +1,93 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:30 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:22 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined (XML_IBMVAW32) || (XML_IBMVAOS2) + +#include <string.h> + +#else + +#include <util/Compilers/CSetDefs.hpp> +#include <strings.h> + + +int stricmp(const char* const str1, const char* const str2) +{ + return strcasecmp(str1, str2); +} + +int strnicmp(const char* const str1, const char* const str2, const unsigned int count) +{ + if (count == 0) + return 0; + + return strncasecmp( str1, str2, (size_t)count); +} +#endif diff --git a/src/util/Compilers/CSetDefs.hpp b/src/util/Compilers/CSetDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ffdb3f25b5dfb17dc053dcb7616872c32bd6bfe1 --- /dev/null +++ b/src/util/Compilers/CSetDefs.hpp @@ -0,0 +1,126 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:31 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:22 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Define these away for this platform +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + + +// --------------------------------------------------------------------------- +// Indicate that we do not support native bools +// --------------------------------------------------------------------------- +#define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XML character +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + +// --------------------------------------------------------------------------- +// Define unsigned 16 and 32 bits integers +// --------------------------------------------------------------------------- +typedef unsigned short XMLUInt16; +typedef unsigned int XMLUInt32; + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#if 0 +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// Provide some common string ops that are different/notavail on CSet +// --------------------------------------------------------------------------- +inline char toupper(const char toUpper) +{ + if ((toUpper >= 'a') && (toUpper <= 'z')) + return char(toUpper - 0x20); + return toUpper; +} + +inline char tolower(const char toLower) +{ + if ((toLower >= 'A') && (toLower <= 'Z')) + return char(toLower + 0x20); + return toLower; +} + +int stricmp(const char* const str1, const char* const str2); +int strnicmp(const char* const str1, const char* const str2, const unsigned int count); + + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the CSet C++ version of the system. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "libIXXML4C"; diff --git a/src/util/Compilers/CodeWarriorDefs.hpp b/src/util/Compilers/CodeWarriorDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c2bbcc3dc24c6762c1ec03c17c17d427d0318ebc --- /dev/null +++ b/src/util/Compilers/CodeWarriorDefs.hpp @@ -0,0 +1,115 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:29 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:22 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// NOTE: +// +// XML4C is not officially supported on Macintosh. This file was sent +// in by one of the Macintosh users and is included in the distribution +// just for convenience. Please send any defects / modification +// reports to xml4c@us.ibm.com +// --------------------------------------------------------------------------- + + + +// --------------------------------------------------------------------------- +// A define in the build for each project is also used to control whether +// the export keyword is from the project's viewpoint or the client's. +// These defines provide the platform specific keywords that they need +// to do this. +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + + +// --------------------------------------------------------------------------- +// Indicate that we support native bools +// --------------------------------------------------------------------------- +// #define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XMLCh. +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +//#ifdef _DEBUG +//#define XML4C_DEBUG +//#endif + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the Codewarrior version of the +// system. We append a previously defined token which holds the DLL +// versioning string. This is defined in XML4CDefs.hpp which is what this +// file is included into. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "IXXML4C" XML4C_DLLVersionStr; diff --git a/src/util/Compilers/GCCDefs.cpp b/src/util/Compilers/GCCDefs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..22c8a513f083fcff8174303ba37ff310a64f5840 --- /dev/null +++ b/src/util/Compilers/GCCDefs.cpp @@ -0,0 +1,87 @@ + +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:32 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:23 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Compilers/GCCDefs.hpp> +#include <strings.h> + + +int stricmp(const char* const str1, const char* const str2) +{ + return strcasecmp(str1, str2); +} + +int strnicmp(const char* const str1, const char* const str2, const unsigned int count) +{ + if (count == 0) + return 0; + + return strncasecmp( str1, str2, (size_t)count); +} diff --git a/src/util/Compilers/GCCDefs.hpp b/src/util/Compilers/GCCDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..73c0c38479f456373b7e65c3c232c996f77ad0d1 --- /dev/null +++ b/src/util/Compilers/GCCDefs.hpp @@ -0,0 +1,120 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:32 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:23 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Define these away for this platform +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + + +// --------------------------------------------------------------------------- +// Indicate that we do not support native bools +// --------------------------------------------------------------------------- +//#define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XML character +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#if 0 +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// Provide some common string ops that are different/notavail on GCC +// --------------------------------------------------------------------------- +inline char toupper(const char toUpper) +{ + if ((toUpper >= 'a') && (toUpper <= 'z')) + return char(toUpper - 0x20); + return toUpper; +} + +inline char tolower(const char toLower) +{ + if ((toLower >= 'A') && (toLower <= 'Z')) + return char(toLower + 0x20); + return toLower; +} + +int stricmp(const char* const str1, const char* const str2); +int strnicmp(const char* const str1, const char* const str2, const unsigned int count); + + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the GCC version of the system. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "libIXXML4C"; diff --git a/src/util/Compilers/GNUGDefs.hpp b/src/util/Compilers/GNUGDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..227bcb26a6f26084525fe9f3f9bba5fce6cb2a80 --- /dev/null +++ b/src/util/Compilers/GNUGDefs.hpp @@ -0,0 +1,109 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:33 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:23 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Define these away for this platform +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + +// --------------------------------------------------------------------------- +// Define our version of the XML character +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + +// --------------------------------------------------------------------------- +// Define unsigned 16 and 32 bits integers +// --------------------------------------------------------------------------- +typedef unsigned short XMLUInt16; +typedef unsigned int XMLUInt32; + +// --------------------------------------------------------------------------- +// Provide some common string ops that are different/notavail on GNU +// --------------------------------------------------------------------------- +inline char toupper(const char toUpper) +{ + if ((toUpper >= 'a') && (toUpper <= 'z')) + return char(toUpper - 0x20); + return toUpper; +} + +inline char tolower(const char toLower) +{ + if ((toLower >= 'A') && (toLower <= 'Z')) + return char(toLower + 0x20); + return toLower; +} + +int stricmp(const char* const str1, const char* const str2); +int strnicmp(const char* const str1, const char* const str2, const unsigned int count); + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the GNUG version of the system. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "libIXXML4C"; diff --git a/src/util/Compilers/HPCCDefs.cpp b/src/util/Compilers/HPCCDefs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ff47ccaf2776aa3d60d1539cf6af5efb032605d --- /dev/null +++ b/src/util/Compilers/HPCCDefs.cpp @@ -0,0 +1,88 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:34 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:23 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Compilers/HPCCDefs.hpp> +#include <strings.h> + + + +int stricmp(const char* const str1, const char* const str2) +{ + return strcasecmp(str1, str2); +} + +int strnicmp(const char* const str1, const char* const str2, const unsigned int count) +{ + if (count == 0) + return 0; + + return strncasecmp( str1, str2, (size_t)count); +} + diff --git a/src/util/Compilers/HPCCDefs.hpp b/src/util/Compilers/HPCCDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..42f7a555fd05c49e7d72ba66e8241e78127db105 --- /dev/null +++ b/src/util/Compilers/HPCCDefs.hpp @@ -0,0 +1,108 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:34 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:23 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Define these away for this platform +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + + +// --------------------------------------------------------------------------- +// Indicate that we do not support native bools +// --------------------------------------------------------------------------- +#if defined(XML_HPUX_CC) +#define NO_NATIVE_BOOL +#endif + + +// --------------------------------------------------------------------------- +// Define our version of the XML character +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// Provide prototypes for some string methods that are not always available +// on all platforms. +// --------------------------------------------------------------------------- +int stricmp(const char* const str1, const char* const str2); +int strnicmp(const char* const str1, const char* const str2, const unsigned int count); + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#if 0 +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the HP CC version of the system. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "libIXXML4C"; diff --git a/src/util/Compilers/IBMVAOS2Defs.hpp b/src/util/Compilers/IBMVAOS2Defs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ae6a3085070b543c06f6a13e9746002f92ef0b04 --- /dev/null +++ b/src/util/Compilers/IBMVAOS2Defs.hpp @@ -0,0 +1,114 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:35 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:24 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// A define in the build for each project is also used to control whether +// the export keyword is from the project's viewpoint or the client's. +// These defines provide the platform specific keywords that they need +// to do this. +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT __declspec(dllexport) +#define PLATFORM_IMPORT +#define XML4C_EXPORT + + +// --------------------------------------------------------------------------- +// Indicate that we support native bools +// --------------------------------------------------------------------------- +// #define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XMLCh. +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#ifdef _DEBUG +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the Visual Age C++ version of the +// system. We append a previously defined token which holds the DLL +// versioning string. This is defined in XML4CDefs.hpp which is what this +// file is included into. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "VAOXML4C" XML4C_DLLVersionStr; + + +// --------------------------------------------------------------------------- +// Include some common headers that are needed product wide +// --------------------------------------------------------------------------- +#include <STRING.h> +#include <FLOAT.h> +#include <MEMORY.h> +#include <BOOL.h> diff --git a/src/util/Compilers/IBMVAW32Defs.hpp b/src/util/Compilers/IBMVAW32Defs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5d1f4fe612f156443bc45bac35141debe166c651 --- /dev/null +++ b/src/util/Compilers/IBMVAW32Defs.hpp @@ -0,0 +1,106 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:36 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:24 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + + +// --------------------------------------------------------------------------- +// A define in the build for each project is also used to control whether +// the export keyword is from the project's viewpoint or the client's. +// These defines provide the platform specific keywords that they need +// to do this. +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT __declspec(dllexport) +#define PLATFORM_IMPORT +#define XML4C_EXPORT + + +// --------------------------------------------------------------------------- +// Indicate that we support native bools +// --------------------------------------------------------------------------- +// #define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XMLCh. +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#ifdef _DEBUG +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the Visual Age C++ version of the +// system. We append a previously defined token which holds the DLL +// versioning string. This is defined in XML4CDefs.hpp which is what this +// file is included into. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "VAWXML4C" XML4C_DLLVersionStr; diff --git a/src/util/Compilers/Makefile.in b/src/util/Compilers/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..fd503c99d16b8e74be4f9c2573ba9ad50a2049bd --- /dev/null +++ b/src/util/Compilers/Makefile.in @@ -0,0 +1,126 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:07:36 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:24 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util +SUBMODULE = Compilers + +include ../../Makefile.incl + +CPP_PUBHEADERS = \ + BorlandCDefs.hpp \ + CSetDefs.hpp \ + CodeWarriorDefs.hpp \ + GCCDefs.hpp \ + GNUGDefs.hpp \ + HPCCDefs.hpp \ + IBMVAOS2Defs.hpp \ + IBMVAW32Defs.hpp \ + SunCCDefs.hpp \ + SunKaiDefs.hpp \ + TandemCCDefs.hpp \ + VCPPDefs.hpp + + +ifeq (${COMPILER},CC) + ifeq (${PLATFORM},SOLARIS) + CPP_OBJECTS = SunCCDefs.o + endif + ifeq (${PLATFORM},HPUX) + CPP_OBJECTS = HPCCDefs.o + endif +endif +ifeq (${COMPILER},xlC_r) + CPP_OBJECTS = CSetDefs.o +endif +ifeq (${COMPILER},g++) + CPP_OBJECTS = GCCDefs.o +endif +ifeq (${COMPILER},aCC) + CPP_OBJECTS = HPCCDefs.o +endif +ifeq (${COMPILER},c++) + ifeq (${PLATFORM},OS390) + CPP_OBJECTS = MVSCPPDefs.o + endif + ifeq (${PLATFORM},LINUX) + CPP_OBJECTS = GCCDefs.o + endif +endif + + +include ../Makefile.util.submodule + diff --git a/src/util/Compilers/SunCCDefs.cpp b/src/util/Compilers/SunCCDefs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..deaf78c7a42a934d7019cc8ff88b78b4c1a282f4 --- /dev/null +++ b/src/util/Compilers/SunCCDefs.cpp @@ -0,0 +1,86 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:37 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:24 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Compilers/SunCCDefs.hpp> +#include <strings.h> + + +int stricmp(const char* const str1, const char* const str2) +{ + return strcasecmp(str1, str2); +} + +int strnicmp(const char* const str1, const char* const str2, const unsigned int count) +{ + if (count == 0) + return 0; + + return strncasecmp( str1, str2, (size_t)count); +} diff --git a/src/util/Compilers/SunCCDefs.hpp b/src/util/Compilers/SunCCDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..570be6b1e524f635be732b09eca90c9069bde8ce --- /dev/null +++ b/src/util/Compilers/SunCCDefs.hpp @@ -0,0 +1,119 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:39 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Define these away for this platform +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + + +// --------------------------------------------------------------------------- +// Indicate that we do not support native bools +// --------------------------------------------------------------------------- +#define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XML character +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#if 0 +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// Provide some common string ops that are different/notavail on CC +// --------------------------------------------------------------------------- +inline char toupper(const char toUpper) +{ + if ((toUpper >= 'a') && (toUpper <= 'z')) + return char(toUpper - 0x20); + return toUpper; +} + +inline char tolower(const char toLower) +{ + if ((toLower >= 'A') && (toLower <= 'Z')) + return char(toLower + 0x20); + return toLower; +} + +int stricmp(const char* const str1, const char* const str2); +int strnicmp(const char* const str1, const char* const str2, const unsigned int count); + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the CC version of the system. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "libIXXML4C"; diff --git a/src/util/Compilers/SunKaiDefs.hpp b/src/util/Compilers/SunKaiDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..158d181cb5cafdd605e543713432c55535d1fe97 --- /dev/null +++ b/src/util/Compilers/SunKaiDefs.hpp @@ -0,0 +1,131 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:40 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// NOTE: +// +// XML4C is not officially supported with the KAI compiler. This file +// was sent in by one of the users and is included in the distribution +// just for convenience. Please send any defects / modification +// reports to xml4c@us.ibm.com +// --------------------------------------------------------------------------- + + +// --------------------------------------------------------------------------- +// Include some runtime files that will be needed product wide +// --------------------------------------------------------------------------- +#include <memory.h> +#include <strings.h> + + + +// --------------------------------------------------------------------------- +// A define in the build for each project is also used to control whether +// the export keyword is from the project's viewpoint or the client's. +// These defines provide the platform specific keywords that they need +// to do this. +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + + + +// --------------------------------------------------------------------------- +// Indicate that we support native bools +// --------------------------------------------------------------------------- +// #define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XMLCh. +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the Visual C++ version of the +// system. We append a previously defined token which holds the DLL +// versioning string. This is defined in XML4CDefs.hpp which is what this +// file is included into. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "KAIXML4C" XML4C_DLLVersionStr; + + +// --------------------------------------------------------------------------- +// Define some platform specific defines +// --------------------------------------------------------------------------- +#define XML4C_EXPORT + + + +// --------------------------------------------------------------------------- +// Provide prototypes for some string functions that are not provided on all +// platforms. +// --------------------------------------------------------------------------- +int stricmp(const char* const str1, const char* const str2); +int strnicmp(const char* const str1, const char* const str2, const unsigned int count); + diff --git a/src/util/Compilers/TandemCCDefs.cpp b/src/util/Compilers/TandemCCDefs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14e8407adc8e9108e47fb5b846a539b44d1256fa --- /dev/null +++ b/src/util/Compilers/TandemCCDefs.cpp @@ -0,0 +1,86 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:40 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Compilers/TandemCCDefs.hpp> +#include <strings.h> + + +int stricmp(const char* const str1, const char* const str2) +{ + return strcasecmp(str1, str2); +} + +int strnicmp(const char* const str1, const char* const str2, const unsigned int count) +{ + if (count == 0) + return 0; + + return strncasecmp( str1, str2, (size_t)count); +} diff --git a/src/util/Compilers/TandemCCDefs.hpp b/src/util/Compilers/TandemCCDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9fbf33e8fc1eacc40e51b7eb50be2dc5eb529c1f --- /dev/null +++ b/src/util/Compilers/TandemCCDefs.hpp @@ -0,0 +1,120 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:40 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Define these away for this platform +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT +#define PLATFORM_IMPORT + + +// --------------------------------------------------------------------------- +// Indicate that we do not support native bools +// --------------------------------------------------------------------------- +#undef NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XML character +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; + + +// --------------------------------------------------------------------------- +// Force on the XML4C2 debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#if 0 +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// Provide some common string ops that are different. +// --------------------------------------------------------------------------- +inline char toupper(const char toUpper) +{ + if ((toUpper >= 'a') && (toUpper <= 'z')) + return char(toUpper - 0x20); + return toUpper; +} + +inline char tolower(const char toLower) +{ + if ((toLower >= 'A') && (toLower <= 'Z')) + return char(toLower + 0x20); + return toLower; +} + +int stricmp(const char* const str1, const char* const str2); +int strnicmp(const char* const str1, const char* const str2, const unsigned int count); + + + +// --------------------------------------------------------------------------- +// The name of the library that is built by the Tandem version of the system. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "libIXXML4C"; diff --git a/src/util/Compilers/VCPPDefs.hpp b/src/util/Compilers/VCPPDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a0411c65d53d3bd82d0c4b50f392bc1855f486d0 --- /dev/null +++ b/src/util/Compilers/VCPPDefs.hpp @@ -0,0 +1,116 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:41 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + + +// --------------------------------------------------------------------------- +// A define in the build for each project is also used to control whether +// the export keyword is from the project's viewpoint or the client's. +// These defines provide the platform specific keywords that they need +// to do this. +// --------------------------------------------------------------------------- +#define PLATFORM_EXPORT __declspec(dllexport) +#define PLATFORM_IMPORT __declspec(dllimport) + + +// --------------------------------------------------------------------------- +// Indicate that we support native bools +// --------------------------------------------------------------------------- +// #define NO_NATIVE_BOOL + + +// --------------------------------------------------------------------------- +// Define our version of the XMLCh. XMLCh should be mapped to the native +// wide char type (whatever wchar_t is.) In VC++, wchar_t is not an +// intrinsic type and is just mapped to unsigned short. +// --------------------------------------------------------------------------- +typedef unsigned short XMLCh; +typedef unsigned short UTF16Ch; + + +// --------------------------------------------------------------------------- +// Define unsigned 16 and 32 bits integers +// --------------------------------------------------------------------------- +typedef unsigned short XMLUInt16; +typedef unsigned int XMLUInt32; + + + +// --------------------------------------------------------------------------- +// Force on the XML4C debug token if it was on in the build environment +// --------------------------------------------------------------------------- +#if defined(_DEBUG) +#define XML4C_DEBUG +#endif + + +// --------------------------------------------------------------------------- +// The name of the DLL that is built by the Visual C++ version of the +// system. We append a previously defined token which holds the DLL +// versioning string. This is defined in XML4CDefs.hpp which is what this +// file is included into. +// --------------------------------------------------------------------------- +const char* const XML4C_DLLName = "IXXML4C" XML4C_DLLVersionStr; diff --git a/src/util/CountedPointer.c b/src/util/CountedPointer.c new file mode 100644 index 0000000000000000000000000000000000000000..555889dac2ba6872153b8cdbc08f448c21f9546c --- /dev/null +++ b/src/util/CountedPointer.c @@ -0,0 +1,150 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:12 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/CountedPointer.hpp> +#endif + + + +// --------------------------------------------------------------------------- +// CountedPointerTo: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class T> CountedPointerTo<T>:: +CountedPointerTo(const CountedPointerTo<T>& toCopy) : + + fPtr(toCopy.fPtr) +{ + if (fPtr) + fPtr->addRef(); +} + +template <class T> CountedPointerTo<T>::CountedPointerTo(T* p) : + + fPtr(p) +{ + if (fPtr) + fPtr->addRef(); +} + +template <class T> CountedPointerTo<T>::~CountedPointerTo() +{ + if (fPtr) + fPtr->removeRef(); +} + + +// --------------------------------------------------------------------------- +// CountedPointerTo: Operators +// --------------------------------------------------------------------------- +template <class T> CountedPointerTo<T>& +CountedPointerTo<T>::operator=(const CountedPointerTo<T>& other) +{ + if (this == &other) + return *this; + + if (other.fPtr) + other.fPtr->addRef(); + + if (fPtr) + fPtr->removeRef(); + + fPtr = other.fPtr; + return *this; +} + +template <class T> CountedPointerTo<T>::operator T*() +{ + return fPtr; +} + +template <class T> const T* CountedPointerTo<T>::operator->() const +{ + return fPtr; +} + +template <class T> T* CountedPointerTo<T>::operator->() +{ + return fPtr; +} + +template <class T> const T& CountedPointerTo<T>::operator*() const +{ + if (!fPtr) + ThrowXML(NullPointerException, XML4CExcepts::CPtr_PointerIsZero); + return *fPtr; +} + +template <class T> T& CountedPointerTo<T>::operator*() +{ + if (!fPtr) + ThrowXML(NullPointerException, XML4CExcepts::CPtr_PointerIsZero); + return *fPtr; +} diff --git a/src/util/CountedPointer.hpp b/src/util/CountedPointer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8f6ea0a61fde23d10d47a01dae396317b52a2f01 --- /dev/null +++ b/src/util/CountedPointer.hpp @@ -0,0 +1,114 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:13 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(COUNTEDPOINTERTO_HPP) +#define COUNTEDPOINTERTO_HPP + +#include <util/XML4CDefs.hpp> +#include <util/NullPointerException.hpp> + + +template <class T> class CountedPointerTo +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + CountedPointerTo(const CountedPointerTo<T>& toCopy); + CountedPointerTo(T* p = 0); + ~CountedPointerTo(); + + + // ----------------------------------------------------------------------- + // Operators + // ----------------------------------------------------------------------- + CountedPointerTo<T>& operator=(const CountedPointerTo<T>& other); + operator T*(); + const T* operator->() const; + T* operator->(); + const T& operator*() const; + T& operator*(); + + +private: + // ----------------------------------------------------------------------- + // Data members + // + // fPtr + // The pointer that we are counting. The T type must implement the + // addRef() and removeRef() APIs but it doesn't have to derive from + // any particular type. + // ----------------------------------------------------------------------- + T* fPtr; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/CountedPointer.c> +#endif + +#endif diff --git a/src/util/EmptyStackException.hpp b/src/util/EmptyStackException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2b7acc29081dbe8aa53a602aff69110cf095a0e7 --- /dev/null +++ b/src/util/EmptyStackException.hpp @@ -0,0 +1,84 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:14 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(EMPTYSTACKEXCEPTION_HPP) +#define EMPTYSTACKEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLUni.hpp> +#include <util/XMLException.hpp> + + +static const XMLCh gEmptyStackException_Name[] = +{ + chLatin_E, chLatin_m, chLatin_p, chLatin_t, chLatin_y, chLatin_S + , chLatin_t, chLatin_a, chLatin_c, chLatin_k, chLatin_E, chLatin_x + , chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i, chLatin_o + , chLatin_n, chNull +}; +MakeXML4CException(EmptyStackException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/FlagJanitor.c b/src/util/FlagJanitor.c new file mode 100644 index 0000000000000000000000000000000000000000..9564ba5a7fd6870fac3408fa6729b3b7fa82aab7 --- /dev/null +++ b/src/util/FlagJanitor.c @@ -0,0 +1,104 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:15 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/FlagJanitor.hpp> +#endif + + +// --------------------------------------------------------------------------- +// Constructors and Destructor +// --------------------------------------------------------------------------- +template <class T> FlagJanitor<T>::FlagJanitor(T* const valPtr, const T newVal) +{ + // Store the pointer, save the org value, and store the new value + fValPtr = valPtr; + if (fValPtr) + { + fOldVal = *fValPtr; + *fValPtr = newVal; + } +} + +template <class T> FlagJanitor<T>::~FlagJanitor() +{ + // Restore the old value + if (fValPtr) + *fValPtr = fOldVal; +} + + +// --------------------------------------------------------------------------- +// Value management methods +// --------------------------------------------------------------------------- +template <class T> void FlagJanitor<T>::release() +{ + fValPtr = 0; +} diff --git a/src/util/FlagJanitor.hpp b/src/util/FlagJanitor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..facb78ced4f35498ea0aff58be25588befdc5a51 --- /dev/null +++ b/src/util/FlagJanitor.hpp @@ -0,0 +1,118 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:17 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(FLAGJANITOR_HPP) +#define FLAGJANITOR_HPP + +#include <util/XML4CDefs.hpp> + + + +template <class T> class FlagJanitor +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + FlagJanitor(T* const valPtr, const T newVal); + ~FlagJanitor(); + + + // ----------------------------------------------------------------------- + // Value management methods + // ----------------------------------------------------------------------- + void release(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + FlagJanitor(); + FlagJanitor(const FlagJanitor<T>&); + void operator=(const FlagJanitor<T>&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fOldVal + // The old value that was in the flag when we were constructed. + // + // fValPtr + // A pointer to the flag that we are to restore the value of + // ----------------------------------------------------------------------- + T fOldVal; + T* fValPtr; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/FlagJanitor.c> +#endif + +#endif diff --git a/src/util/HeaderDummy.cpp b/src/util/HeaderDummy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6e1fa0321a8d00ea47d5d00c7bc9d18f5ede4d0e --- /dev/null +++ b/src/util/HeaderDummy.cpp @@ -0,0 +1,83 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:18 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:07 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#include <util/BinInputStream.hpp> +#include <util/BinMemInputStream.hpp> +#include <util/BinFileInputStream.hpp> +#include <util/BitOps.hpp> +#include <util/EmptyStackException.hpp> +#include <util/IllegalArgumentException.hpp> +#include <util/InvalidCastException.hpp> +#include <util/IOException.hpp> +#include <util/NoSuchElementException.hpp> +#include <util/NullPointerException.hpp> +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/TextOutputStream.hpp> +#include <util/UnexpectedEOFException.hpp> +#include <util/UnsupportedEncodingException.hpp> +#include <util/UTFDataFormatException.hpp> diff --git a/src/util/IOException.hpp b/src/util/IOException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b0ffb1d86eaf39bc6d70a693a153151176c8164f --- /dev/null +++ b/src/util/IOException.hpp @@ -0,0 +1,85 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:25 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:07 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(IOEXCEPTION_HPP) +#define IOEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + + +// Hard coded Unicode text for "IOException" +static const XMLCh gIOException_Name[] = +{ + chLatin_I, chLatin_O, chLatin_E, chLatin_x, chLatin_c, chLatin_e + , chLatin_p, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(IOException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/IllegalArgumentException.hpp b/src/util/IllegalArgumentException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..72400bed911e4790ebd677d9fb85fcc981b5148e --- /dev/null +++ b/src/util/IllegalArgumentException.hpp @@ -0,0 +1,88 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:23 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:07 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(ILLEGALARGUMENTEXCEPTION_HPP) +#define ILLEGALARGUMENTEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLUni.hpp> +#include <util/XMLException.hpp> + + +// Hard coded Unicode text for "IllegalArgumentException" +static const XMLCh gIllegalArgumentException_Name[] = +{ + chLatin_I, chLatin_l, chLatin_l, chLatin_e, chLatin_g, chLatin_a + , chLatin_l, chLatin_A, chLatin_r, chLatin_g, chLatin_u, chLatin_m + , chLatin_e, chLatin_n, chLatin_t, chLatin_E, chLatin_x, chLatin_c + , chLatin_e, chLatin_p, chLatin_t, chLatin_i, chLatin_o, chLatin_n + , chNull +}; + +MakeXML4CException(IllegalArgumentException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/InvalidCastException.hpp b/src/util/InvalidCastException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7b6c2e5f2adea6c4a6dbf72ededcddf75914f328 --- /dev/null +++ b/src/util/InvalidCastException.hpp @@ -0,0 +1,86 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:25 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:07 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(INVALIDCASTEXCEPTION_HPP) +#define INVALIDCASTEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLUni.hpp> +#include <util/XMLException.hpp> + +// Hard coded Unicode text for "InvalidCastException" +static const XMLCh gInvalidCastException_Name[] = +{ + chLatin_I, chLatin_n, chLatin_v, chLatin_a, chLatin_l, chLatin_i + , chLatin_d, chLatin_C, chLatin_a, chLatin_s, chLatin_t, chLatin_E + , chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i + , chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(InvalidCastException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/Janitor.c b/src/util/Janitor.c new file mode 100644 index 0000000000000000000000000000000000000000..04bd67314aa952d50cc708a58a1edb12321da689 --- /dev/null +++ b/src/util/Janitor.c @@ -0,0 +1,123 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:26 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:08 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/Janitor.hpp> +#endif + + + +// --------------------------------------------------------------------------- +// Janitor: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class T> Janitor<T>::Janitor(T* const toDelete) : + + fData(toDelete) +{ +} + +template <class T> Janitor<T>::~Janitor() +{ + delete fData; +} + + +// --------------------------------------------------------------------------- +// Janitor: Public, non-virtual methods +// --------------------------------------------------------------------------- +template <class T> void Janitor<T>::orphan() +{ + fData = 0; +} + + + +// ----------------------------------------------------------------------- +// ArrayJanitor: Constructors and Destructor +// ----------------------------------------------------------------------- +template <class T> ArrayJanitor<T>::ArrayJanitor(T* const toDelete) : + + fData(toDelete) +{ +} + +template <class T> ArrayJanitor<T>::~ArrayJanitor() +{ + delete [] fData; +} + + +// ----------------------------------------------------------------------- +// ArrayJanitor: Public, non-virtual methods +// ----------------------------------------------------------------------- +template <class T> void ArrayJanitor<T>::orphan() +{ + fData = 0; +} diff --git a/src/util/Janitor.hpp b/src/util/Janitor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b52e46dca4f1ae41d96720cb2e100dad1fbef86 --- /dev/null +++ b/src/util/Janitor.hpp @@ -0,0 +1,149 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:27 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:08 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(JANITOR_HPP) +#define JANITOR_HPP + +#include <util/XML4CDefs.hpp> + + +template <class T> class Janitor +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + Janitor(T* const toDelete); + ~Janitor(); + + + // ----------------------------------------------------------------------- + // Public, non-virtual methods + // ----------------------------------------------------------------------- + void orphan(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + Janitor(); + Janitor(const Janitor<T>&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fData + // This is the pointer to the object or structure that must be + // destroyed when this object is destroyed. + // ----------------------------------------------------------------------- + T* fData; +}; + + + +template <class T> class ArrayJanitor +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ArrayJanitor(T* const toDelete); + ~ArrayJanitor(); + + + // ----------------------------------------------------------------------- + // Public, non-virtual methods + // ----------------------------------------------------------------------- + void orphan(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + ArrayJanitor(); + ArrayJanitor(const ArrayJanitor<T>&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fData + // This is the pointer to the object or structure that must be + // destroyed when this object is destroyed. + // ----------------------------------------------------------------------- + T* fData; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/Janitor.c> +#endif + +#endif diff --git a/src/util/KVStringPair.cpp b/src/util/KVStringPair.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5bf22b49067c64d2f75bd7162dac4fc6eae7714a --- /dev/null +++ b/src/util/KVStringPair.cpp @@ -0,0 +1,156 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:33 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:08 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/KVStringPair.hpp> +#include <util/XMLString.hpp> + + +// --------------------------------------------------------------------------- +// KVStringPair: Constructors and Destructor +// --------------------------------------------------------------------------- +KVStringPair::KVStringPair() : + + fKey(0) + , fValue(0) +{ +} + +KVStringPair::KVStringPair(const XMLCh* const key, const XMLCh* const value) : + + fKey(0) + , fValue(0) +{ + fKey = XMLString::replicate(key); + fValue = XMLString::replicate(value); +} + +KVStringPair::KVStringPair(const KVStringPair& toCopy) : + + fKey(0) + , fValue(0) +{ + fKey = XMLString::replicate(toCopy.fKey); + fValue = XMLString::replicate(toCopy.fValue); +} + +KVStringPair::~KVStringPair() +{ + delete [] fKey; + delete [] fValue; +} + + +// --------------------------------------------------------------------------- +// KVStringPair: Getters +// --------------------------------------------------------------------------- +const XMLCh* KVStringPair::getKey() const +{ + return fKey; +} + +XMLCh* KVStringPair::getKey() +{ + return fKey; +} + +const XMLCh* KVStringPair::getValue() const +{ + return fValue; +} + +XMLCh* KVStringPair::getValue() +{ + return fValue; +} + + +// --------------------------------------------------------------------------- +// KVStringPair: Setters +// --------------------------------------------------------------------------- +void KVStringPair::setKey(const XMLCh* const newKey) +{ + delete [] fKey; + fKey = XMLString::replicate(newKey); +} + +void KVStringPair::setValue(const XMLCh* const newValue) +{ + delete [] fValue; + fValue = XMLString::replicate(newValue); +} + +void KVStringPair::set( const XMLCh* const newKey + , const XMLCh* const newValue) +{ + delete [] fKey; + delete [] fValue; + fKey = XMLString::replicate(newKey); + fValue = XMLString::replicate(newValue); +} diff --git a/src/util/KVStringPair.hpp b/src/util/KVStringPair.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d80e838ef9b647431155db534da70c3f575a77d1 --- /dev/null +++ b/src/util/KVStringPair.hpp @@ -0,0 +1,127 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:37 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:08 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(KVSTRINGPAIR_HPP) +#define KVSTRINGPAIR_HPP + +#include <util/XML4CDefs.hpp> + + +// +// This class provides a commonly used data structure, which is that of +// a pair of strings which represent a 'key=value' type mapping. It works +// only in terms of XMLCh type raw strings. +// +class XMLUTIL_EXPORT KVStringPair +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + KVStringPair(); + KVStringPair(const XMLCh* const key, const XMLCh* const value); + KVStringPair(const KVStringPair& toCopy); + ~KVStringPair(); + + + // ----------------------------------------------------------------------- + // Getters + // + // We support the + // ----------------------------------------------------------------------- + const XMLCh* getKey() const; + XMLCh* getKey(); + const XMLCh* getValue() const; + XMLCh* getValue(); + + + // ----------------------------------------------------------------------- + // Setters + // ----------------------------------------------------------------------- + void setKey(const XMLCh* const newKey); + void setValue(const XMLCh* const newValue); + void set + ( + const XMLCh* const newKey + , const XMLCh* const newValue + ); + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fKey + // The string that represents the key field of this object. + // + // fValue + // The string that represents the value of this pair object. + // ----------------------------------------------------------------------- + XMLCh* fKey; + XMLCh* fValue; +}; + +#endif diff --git a/src/util/KeyValuePair.c b/src/util/KeyValuePair.c new file mode 100644 index 0000000000000000000000000000000000000000..ed24805bf32f67d45e67c9d8773b1f5ad093cfc1 --- /dev/null +++ b/src/util/KeyValuePair.c @@ -0,0 +1,147 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:29 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:09 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Include +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/KeyValuePair.hpp> +#endif + + + +// --------------------------------------------------------------------------- +// KeyValuePair: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TKey, class TValue> KeyValuePair<TKey,TValue>::KeyValuePair() +{ +} + +template <class TKey, class TValue> KeyValuePair<TKey,TValue>:: +KeyValuePair(const TKey& key, const TValue& value) : + + fKey(key) + , fValue(value) +{ +} + +template <class TKey, class TValue> KeyValuePair<TKey,TValue>:: +KeyValuePair(const KeyValuePair<TKey,TValue>& toCopy) : + + fKey(toCopy.fKey) + , fValue(toCopy.fValue) +{ +} + +template <class TKey, class TValue> KeyValuePair<TKey,TValue>::~KeyValuePair() +{ +} + + +// --------------------------------------------------------------------------- +// KeyValuePair: Getters +// --------------------------------------------------------------------------- +template <class TKey, class TValue> const TKey& +KeyValuePair<TKey,TValue>::getKey() const +{ + return fKey; + +} + +template <class TKey, class TValue> TKey& KeyValuePair<TKey,TValue>::getKey() +{ + return fKey; +} + +template <class TKey, class TValue> const TValue& +KeyValuePair<TKey,TValue>::getValue() const +{ + return fValue; +} + +template <class TKey, class TValue> TValue& KeyValuePair<TKey,TValue>::getValue() +{ + return fValue; +} + + +// --------------------------------------------------------------------------- +// KeyValuePair: Setters +// --------------------------------------------------------------------------- +template <class TKey, class TValue> TKey& +KeyValuePair<TKey,TValue>::setKey(const TKey& newKey) +{ + fKey = newKey; + return fKey; +} + +template <class TKey, class TValue> TValue& +KeyValuePair<TKey,TValue>::setValue(const TValue& newValue) +{ + fValue = newValue; + return fValue; +} diff --git a/src/util/KeyValuePair.hpp b/src/util/KeyValuePair.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cef36763b54e2e7719f57f9fd256ddadb88275ee --- /dev/null +++ b/src/util/KeyValuePair.hpp @@ -0,0 +1,121 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:31 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:09 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(KEYVALUEPAIR_HPP) +#define KEYVALUEPAIR_HPP + + +#include <util/XML4CDefs.hpp> + + +template <class TKey, class TValue> class KeyValuePair +{ + public : + // ------------------------------------------------------------------- + // Constructors and Destructor + // ------------------------------------------------------------------- + KeyValuePair(); + KeyValuePair(const TKey& key, const TValue& value); + KeyValuePair(const KeyValuePair<TKey,TValue>& toCopy); + ~KeyValuePair(); + + + // ------------------------------------------------------------------- + // Getters + // ------------------------------------------------------------------- + const TKey& getKey() const; + TKey& getKey(); + const TValue& getValue() const; + TValue& getValue(); + + + // ------------------------------------------------------------------- + // Setters + // ------------------------------------------------------------------- + TKey& setKey(const TKey& newKey); + TValue& setValue(const TValue& newValue); + + + private : + // ------------------------------------------------------------------- + // Private data members + // + // fKey + // The object that represents the key of the pair + // + // fValue + // The object that represents the value of the pair + // ------------------------------------------------------------------- + TKey fKey; + TValue fValue; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/KeyValuePair.c> +#endif + +#endif diff --git a/src/util/Makefile.in b/src/util/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..424c60aaf27d7d14bc90d7a2e6996bc2d914ce50 --- /dev/null +++ b/src/util/Makefile.in @@ -0,0 +1,248 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:04:40 twl +# Initial revision +# +# Revision 1.4 1999/11/08 20:45:09 rahul +# Swat for adding in Product name and CVS comment log variable. +# +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util + +ifeq (${TRANSCODER},ICU) + TRANSCODERMODULE=ICU +else + TRANSCODERMODULE=Iconv +endif + +ifeq (${MESSAGELOADER},ICU) + MESSAGELOADERMODULE=ICU +else + ifeq (${MESSAGELOADER},ICONV) + MESSAGELOADERMODULE=MsgCatalog + else + MESSAGELOADERMODULE=InMemory + endif +endif + +include ../Makefile.incl + +UTIL_CPP_PUBHEADERS = \ + ArrayIndexOutOfBoundsException.hpp \ + AutoSense.hpp \ + BinFileInputStream.hpp \ + BinInputStream.hpp \ + BinMemInputStream.hpp \ + BitOps.hpp \ + BitSet.hpp \ + CountedPointer.hpp \ + EmptyStackException.hpp \ + FlagJanitor.hpp \ + IOException.hpp \ + IllegalArgumentException.hpp \ + InvalidCastException.hpp \ + Janitor.hpp \ + KVStringPair.hpp \ + KeyValuePair.hpp \ + Mutexes.hpp \ + NameIdPool.hpp \ + NoDefTranscoderException.hpp \ + NoSuchElementException.hpp \ + NullPointerException.hpp \ + PlatformUtils.hpp \ + RefArrayOf.hpp \ + RefHashTableOf.hpp \ + RefStackOf.hpp \ + RefVectorOf.hpp \ + RuntimeException.hpp \ + StdOut.hpp \ + StringPool.hpp \ + TextOutputStream.hpp \ + TransService.hpp \ + TranscodingException.hpp \ + URL.hpp \ + UTFDataFormatException.hpp \ + UnexpectedEOFException.hpp \ + UnsupportedEncodingException.hpp \ + ValueArrayOf.hpp \ + ValueStackOf.hpp \ + ValueVectorOf.hpp \ + XML4CDefs.hpp \ + XMLEnumerator.hpp \ + XMLExceptMsgs.hpp \ + XMLException.hpp \ + XMLMsgLoader.hpp \ + XMLString.hpp \ + XMLUni.hpp + +UTIL_CPP_PRIVHEADERS = + +C_FILES = \ + CountedPointer.c \ + FlagJanitor.c \ + Janitor.c \ + KeyValuePair.c \ + NameIdPool.c \ + RefArrayOf.c \ + RefHashTableOf.c \ + RefStackOf.c \ + RefVectorOf.c \ + ValueArrayOf.c \ + ValueStackOf.c \ + ValueVectorOf.c + +UTIL_CPP_OBJECTS = \ + BinFileInputStream.o \ + BinInputStream.o \ + BinMemInputStream.o \ + BitSet.o \ + HeaderDummy.o \ + KVStringPair.o \ + Mutexes.o \ + PlatformUtils.o \ + StdOut.o \ + StringPool.o \ + TextOutputStream.o \ + URL.o \ + XMLException.o \ + XMLString.o \ + XMLUni.o + + +all: includes $(UTIL_CPP_OBJECTS) platforms transcoders messageloaders compilers publish + +includes: pubheaders $(C_FILES) + cd Platforms ; $(MAKE) $@ ; cd .. + cd Transcoders/$(TRANSCODERMODULE) ; $(MAKE) $@ ; cd ../.. + cd MsgLoaders/$(MESSAGELOADERMODULE) ; $(MAKE) $@ ; cd ../.. + cd Compilers ; $(MAKE) $@ ; cd .. + +platforms: + cd Platforms ; $(MAKE) ; cd .. + +transcoders: + cd Transcoders/$(TRANSCODERMODULE) ; $(MAKE) ; cd ../.. + +messageloaders: + cd MsgLoaders/$(MESSAGELOADERMODULE) ; $(MAKE) ; cd ../.. + +compilers: + cd Compilers ; $(MAKE) ; cd .. + +pubheaders: + -mkdir -p $(XML_INC_DIR)/$(MODULE) + $(CP) $(UTIL_CPP_PUBHEADERS) $(C_FILES) $(XML_INC_DIR)/$(MODULE) + +publish: + -mkdir -p ${ALL_OBJECTS_DIR} + $(CP) $(UTIL_CPP_OBJECTS) $(ALL_OBJECTS_DIR) + +# this may generate unnecessary dependencies, but it makes life easier +depend: includes + $(MAKE_DEPEND) $(XML_INCL) *.cpp > $(DEPFILE) + +clean: + @echo "Making clean in $(MODULE) ..." + $(RM) $(UTIL_CPP_OBJECTS) + cd Platforms ; $(MAKE) $@ ; cd .. + cd Transcoders/$(TRANSCODERMODULE) ; $(MAKE) $@ ; cd ../.. + cd MsgLoaders/$(MESSAGELOADERMODULE) ; $(MAKE) $@ ; cd ../.. + cd Compilers ; $(MAKE) $@ ; cd .. + + + +distclean: clean + $(RM) Makefile $(DEPFILE) + @echo "Removing all $(MODULE) header files ..." + @for file in $(UTIL_CPP_PUBHEADERS); do \ + rm -f $(XML_INC_DIR)/$(MODULE)/$$file; \ + done + @for file in $(C_FILES); do \ + rm -f $(XML_INC_DIR)/$(MODULE)/$$file; \ + done + @echo "Removing all $(MODULE) object files ..." + @for file in $(UTIL_CPP_OBJECTS); do \ + rm -f $(ALL_OBJECTS_DIR)/$$file; \ + done + cd Platforms ; $(MAKE) $@ ; cd .. + cd Transcoders/$(TRANSCODERMODULE) ; $(MAKE) $@ ; cd ../.. + cd MsgLoaders/$(MESSAGELOADERMODULE) ; $(MAKE) $@ ; cd ../.. + cd Compilers ; $(MAKE) $@ ; cd .. + + +install: + -mkdir -p $(PREFIX)/$(MODULE) + $(CP) $(UTIL_CPP_PUBHEADERS) $(C_FILES) $(PREFIX)/$(MODULE) + cd Platforms ; $(MAKE) $@ ; cd .. + cd Transcoders/$(TRANSCODERMODULE) ; $(MAKE) $@ ; cd ../.. + cd MsgLoaders/$(MESSAGELOADERMODULE) ; $(MAKE) $@ ; cd ../.. + cd Compilers ; $(MAKE) $@ ; cd .. + diff --git a/src/util/Makefile.util.submodule b/src/util/Makefile.util.submodule new file mode 100644 index 0000000000000000000000000000000000000000..3b2012112a44ea9dee52e38dd8584214db529959 --- /dev/null +++ b/src/util/Makefile.util.submodule @@ -0,0 +1,52 @@ +# +# (C) Copyright IBM Corp. 1997-1999 All rights reserved. +# +# US Government Users Restricted Rights Use, duplication or +# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. +# +# The program is provided "as is" without any warranty express or +# implied, including the warranty of non-infringement and the implied +# warranties of merchantibility and fitness for a particular purpose. +# IBM will not be liable for any damages suffered by you as a result +# of using the Program. In no event will IBM be liable for any +# special, indirect or consequential damages or lost profits even if +# IBM has been advised of the possibility of their occurrence. IBM +# will not be liable for any third party claims against you. +# +# @version: +# + +all: includes $(CPP_OBJECTS) publish + +includes: pubheaders + +pubheaders: + -mkdir -p $(XML_INC_DIR)/$(MODULE)/$(SUBMODULE) + $(CP) $(CPP_PUBHEADERS) $(XML_INC_DIR)/$(MODULE)/$(SUBMODULE) + +publish: + -mkdir -p ${ALL_OBJECTS_DIR} + $(CP) $(CPP_OBJECTS) $(ALL_OBJECTS_DIR) + +# this may generate unnecessary dependencies, but it makes life easier +depend: includes + $(MAKE_DEPEND) $(XML_INCL) *.cpp > $(DEPFILE) + +clean: + @echo "Making clean in $(MODULE)/$(SUBMODULE) ..." + $(RM) $(CPP_OBJECTS) + +distclean: clean + $(RM) Makefile $(DEPFILE) + @echo "Removing all $(MODULE)/$(SUBMODULE) header files ..." + @for file in $(CPP_PUBHEADERS); do \ + rm -f $(XML_INC_DIR)/$(MODULE)/$(SUBMODULE)/$$file; \ + done + @echo "Removing all $(MODULE)/$(SUBMODULE) object files ..." + @for file in $(CPP_OBJECTS); do \ + rm -f $(ALL_OBJECTS_DIR)/$$file; \ + done + +install: + -mkdir -p $(PREFIX)/$(MODULE)/$(SUBMODULE) + $(CP) $(CPP_PUBHEADERS) $(PREFIX)/$(MODULE)/$(SUBMODULE) diff --git a/src/util/MsgLoaders/ICU/ICUMsgLoader.cpp b/src/util/MsgLoaders/ICU/ICUMsgLoader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..066df4aa490441b969742cfabe0fbedad01e9906 --- /dev/null +++ b/src/util/MsgLoaders/ICU/ICUMsgLoader.cpp @@ -0,0 +1,231 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:23 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:26 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/PlatformUtils.hpp> +#include <util/XMLMsgLoader.hpp> +#include <util/XMLString.hpp> +#include "ICUMsgLoader.hpp" + +#include "resbund.h" +#include "string.h" + + +// --------------------------------------------------------------------------- +// Local static methods +// --------------------------------------------------------------------------- +static const XMLCh* mapId( const XMLMsgLoader::XMLMsgId msgToLoad + , const XMLCh* bundleType) +{ + static const XMLCh test[] = { 0x65, 0x66, 0 }; + return test; +} + + +// --------------------------------------------------------------------------- +// Public Constructors and Destructor +// --------------------------------------------------------------------------- +ICUMsgLoader::ICUMsgLoader(const XMLCh* const toLoad) : + fBundle(0) + , fBundleType((XMLCh*)toLoad) +{ + // + // Use the platform util's path to figure out where the resource bundles + // are. We keep them in an NLS directory underneath the DLL/Lib path. + // + const unsigned int maxChars = 4095; + char tmpPath[maxChars + 1]; + strncpy(tmpPath, XMLPlatformUtils::fgLibLocation, maxChars); + + // Now copy the relative path part onto it + strncat(tmpPath, "NLS//ICU//", maxChars); + + if (toLoad == 0) + strncat(tmpPath, "XMLExceptMsgs", maxChars); + else if (toLoad == 0) + strncat(tmpPath, "XMLErrors", maxChars); + else + { + // <TBD> Need to do something here. Panic call? + } + + // Ok, lets try to create the bundle now + UErrorCode err = ZERO_ERROR; + fBundle = new ResourceBundle(tmpPath, err); + if (!SUCCESS(err)) + { + // <TBD> Need to panic again here? + } +} + +ICUMsgLoader::~ICUMsgLoader() +{ + delete fBundle; +} + + +// --------------------------------------------------------------------------- +// Implementation of the virtual message loader API +// --------------------------------------------------------------------------- +bool ICUMsgLoader::loadMsg( const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars) +{ + // + // Map the passed id to the required message bundle key name. We use + // a local array to map the message id to the correct string. This array + // is generated from a little utility program that can kick out the + // message text in a couple of different formats. + // + const XMLCh* const keyStr = mapId(msgToLoad, fBundleType); + if (!keyStr) + return false; + + // And now try to load that key's related message + UErrorCode err; + UnicodeString keyVal(keyStr); + const UnicodeString* msgString = fBundle->getString(keyVal, err); + if (!msgString) + return false; + + // Extract out from the UnicodeString to the passed buffer + const unsigned int len = msgString->length(); + const unsigned int lesserLen = (len < maxChars) ? len : maxChars; + msgString->extract + ( + 0 + , lesserLen + , toFill + ); + + // Cap it off and return success + toFill[lesserLen] = 0; + return true; +} + + +bool ICUMsgLoader::loadMsg( const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 + , const XMLCh* const repText3 + , const XMLCh* const repText4) +{ + // Call the other version to load up the message + if (!loadMsg(msgToLoad, toFill, maxChars)) + return false; + + // And do the token replacement + XMLString::replaceTokens(toFill, maxChars, repText1, repText2, repText3, repText4); + return true; +} + + +bool ICUMsgLoader::loadMsg( const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 + , const char* const repText3 + , const char* const repText4) +{ + // + // Transcode the provided parameters and call the other version, + // which will do the replacement work. + // + XMLCh* tmp1 = 0; + XMLCh* tmp2 = 0; + XMLCh* tmp3 = 0; + XMLCh* tmp4 = 0; + + bool bRet = false; + if (repText1) + tmp1 = XMLString::transcode(repText1); + if (repText2) + tmp2 = XMLString::transcode(repText2); + if (repText3) + tmp3 = XMLString::transcode(repText3); + if (repText4) + tmp4 = XMLString::transcode(repText4); + + bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4); + + if (tmp1) + delete [] tmp1; + if (tmp2) + delete [] tmp2; + if (tmp3) + delete [] tmp3; + if (tmp4) + delete [] tmp4; + + return bRet; +} diff --git a/src/util/MsgLoaders/ICU/ICUMsgLoader.hpp b/src/util/MsgLoaders/ICU/ICUMsgLoader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e4b743daa8bb7488a5845288e1853b101634c304 --- /dev/null +++ b/src/util/MsgLoaders/ICU/ICUMsgLoader.hpp @@ -0,0 +1,146 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:24 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:26 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(ICUMSGLOADER_HPP) +#define ICUMSGLOADER_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLMsgLoader.hpp> + +class ResourceBundle; + +// +// This is the ICU specific implementation of the XMLMsgLoader interface. +// This one uses ICU resource bundles to store its messages. +// +class XMLUTIL_EXPORT ICUMsgLoader : public XMLMsgLoader +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + ICUMsgLoader(const XMLCh* const toLoad); + ~ICUMsgLoader(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual message loader API + // ----------------------------------------------------------------------- + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 = 0 + , const XMLCh* const repText3 = 0 + , const XMLCh* const repText4 = 0 + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 = 0 + , const char* const repText3 = 0 + , const char* const repText4 = 0 + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + ICUMsgLoader(); + ICUMsgLoader(const ICUMsgLoader&); + void operator=(const ICUMsgLoader&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fBundle + // This is the ICU resource bundle that we use to track messages. + // + // fBundleType + // This is the bundle that we are using. This is used to map message + // ids to key values. + // ----------------------------------------------------------------------- + ResourceBundle* fBundle; + XMLCh* fBundleType; +}; + +#endif diff --git a/src/util/MsgLoaders/ICU/Makefile.in b/src/util/MsgLoaders/ICU/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..49a6a77b494039431308d1d92e2124f1fdefa43e --- /dev/null +++ b/src/util/MsgLoaders/ICU/Makefile.in @@ -0,0 +1,88 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:07:25 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:26 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util +SUBMODULE = MsgLoaders/ICU + +include ../../../Makefile.incl + +CPP_PUBHEADERS = \ + ICUMsgLoader.hpp + +CPP_OBJECTS = ICUMsgLoader.o + +include ../../Makefile.util.submodule diff --git a/src/util/MsgLoaders/InMemory/CppErrMsgs_EN_US.hpp b/src/util/MsgLoaders/InMemory/CppErrMsgs_EN_US.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6c98d66423967c3598e4103596c050ee7dc18c85 --- /dev/null +++ b/src/util/MsgLoaders/InMemory/CppErrMsgs_EN_US.hpp @@ -0,0 +1,265 @@ +// ---------------------------------------------------------------- +// This file was generated from the XML error message source. +// so do not edit this file directly!! +// ---------------------------------------------------------------- + +const XMLCh gXMLErrArray[][128] = +{ + { 0x0057,0x005F,0x0053,0x0074,0x0061,0x0072,0x0074,0x00 } + , { 0x004E,0x006F,0x0074,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0062,0x0065,0x0065,0x006E,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0062,0x0065,0x0065,0x006E,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0045,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x0020,0x0028,0x007B,0x0030,0x007D,0x002C,0x0020,0x0066,0x0072,0x006F,0x006D,0x0020,0x0058,0x004D,0x004C,0x0044,0x0065,0x0063,0x006C,0x0020,0x006F,0x0072,0x0020,0x006D,0x0061,0x006E,0x0075,0x0061,0x006C,0x006C,0x0079,0x0020,0x0073,0x0065,0x0074,0x0029,0x0020,0x0063,0x006F,0x006E,0x0074,0x0072,0x0061,0x0064,0x0069,0x0063,0x0074,0x0073,0x0020,0x0074,0x0068,0x0065,0x0020,0x0061,0x0075,0x0074,0x006F,0x002D,0x0073,0x0065,0x006E,0x0073,0x0065,0x0064,0x0020,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x002C,0x0020,0x0069,0x0067,0x006E,0x006F,0x0072,0x0069,0x006E,0x0067,0x0020,0x0069,0x0074,0x00 } + , { 0x0045,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0077,0x0061,0x0073,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0061,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x0020,0x0062,0x0075,0x0074,0x0020,0x006E,0x0065,0x0076,0x0065,0x0072,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0045,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0077,0x0061,0x0073,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0061,0x006E,0x0020,0x0061,0x0074,0x0074,0x006C,0x0069,0x0073,0x0074,0x0020,0x0062,0x0075,0x0074,0x0020,0x006E,0x0065,0x0076,0x0065,0x0072,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0057,0x005F,0x0045,0x006E,0x0064,0x00 } + , { 0x0045,0x005F,0x0053,0x0074,0x0061,0x0072,0x0074,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0063,0x006F,0x006D,0x006D,0x0065,0x006E,0x0074,0x0020,0x006F,0x0072,0x0020,0x0043,0x0044,0x0041,0x0054,0x0041,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x006E,0x0061,0x006D,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0020,0x006E,0x006F,0x0074,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x006E,0x0061,0x006D,0x0065,0x00 } + , { 0x0052,0x0065,0x0070,0x0065,0x0074,0x0069,0x0074,0x0069,0x006F,0x006E,0x0020,0x006F,0x0066,0x0020,0x0069,0x006E,0x0064,0x0069,0x0076,0x0069,0x0064,0x0075,0x0061,0x006C,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0073,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006C,0x0065,0x0067,0x0061,0x006C,0x0020,0x0066,0x006F,0x0072,0x0020,0x006D,0x0069,0x0078,0x0065,0x0064,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x0073,0x00 } + , { 0x0042,0x0061,0x0064,0x0020,0x0064,0x0065,0x0066,0x0061,0x0075,0x006C,0x0074,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0064,0x0065,0x0066,0x0061,0x0075,0x006C,0x0074,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x002C,0x0020,0x0061,0x0073,0x0073,0x0075,0x006D,0x0069,0x006E,0x0067,0x0020,0x0023,0x0049,0x004D,0x0050,0x004C,0x0049,0x0045,0x0044,0x0020,0x0020,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x006C,0x0069,0x0073,0x0074,0x0020,0x0073,0x0079,0x006E,0x0074,0x0061,0x0078,0x0020,0x0065,0x0072,0x0072,0x006F,0x0072,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0065,0x0071,0x0075,0x0061,0x006C,0x0020,0x0073,0x0069,0x0067,0x006E,0x00 } + , { 0x0044,0x0075,0x0070,0x006C,0x0069,0x0063,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x006E,0x0061,0x006D,0x0065,0x00 } + , { 0x0042,0x0061,0x0064,0x0020,0x0049,0x0044,0x0020,0x0066,0x006F,0x0072,0x0020,0x0078,0x006D,0x006C,0x003A,0x006C,0x0061,0x006E,0x0067,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x006E,0x0061,0x006D,0x0065,0x00 } + , { 0x004D,0x0075,0x0073,0x0074,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0077,0x0069,0x0074,0x0068,0x0020,0x0061,0x006E,0x0020,0x0058,0x004D,0x004C,0x0044,0x0065,0x0063,0x006C,0x00 } + , { 0x0043,0x006F,0x006D,0x006D,0x0065,0x006E,0x0074,0x0073,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0077,0x0069,0x0074,0x0068,0x0020,0x003C,0x0021,0x002D,0x002D,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0064,0x006F,0x0063,0x0075,0x006D,0x0065,0x006E,0x0074,0x0020,0x0073,0x0074,0x0072,0x0075,0x0063,0x0074,0x0075,0x0072,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0020,0x0027,0x0076,0x0065,0x0072,0x0073,0x0069,0x006F,0x006E,0x003D,0x0027,0x002C,0x0020,0x0027,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x003D,0x0027,0x002C,0x0020,0x006F,0x0072,0x0020,0x0027,0x0073,0x0074,0x0061,0x006E,0x0064,0x0061,0x006C,0x006F,0x006E,0x0065,0x003D,0x0027,0x00 } + , { 0x0042,0x0061,0x0064,0x0020,0x0058,0x004D,0x004C,0x0020,0x0076,0x0065,0x0072,0x0073,0x0069,0x006F,0x006E,0x0020,0x0073,0x0074,0x0072,0x0069,0x006E,0x0067,0x00 } + , { 0x0055,0x006E,0x0073,0x0075,0x0070,0x0070,0x006F,0x0072,0x0074,0x0065,0x0064,0x0020,0x0058,0x004D,0x004C,0x0020,0x0076,0x0065,0x0072,0x0073,0x0069,0x006F,0x006E,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0058,0x004D,0x004C,0x0020,0x0064,0x0065,0x0063,0x006C,0x00 } + , { 0x0042,0x0061,0x0064,0x0020,0x0058,0x004D,0x004C,0x0020,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0042,0x0061,0x0064,0x0020,0x0073,0x0074,0x0061,0x006E,0x0064,0x0061,0x006C,0x006F,0x006E,0x0065,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0063,0x006F,0x006D,0x006D,0x0065,0x006E,0x0074,0x00 } + , { 0x0050,0x0072,0x006F,0x0063,0x0065,0x0073,0x0073,0x0069,0x006E,0x0067,0x0020,0x0069,0x006E,0x0073,0x0074,0x0072,0x0075,0x0063,0x0074,0x0069,0x006F,0x006E,0x0020,0x006E,0x0061,0x006D,0x0065,0x0020,0x0065,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0070,0x0072,0x006F,0x0063,0x0065,0x0073,0x0073,0x0069,0x006E,0x0067,0x0020,0x0069,0x006E,0x0073,0x0074,0x0072,0x0075,0x0063,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x00 } + , { 0x0055,0x006E,0x0065,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0074,0x0065,0x0078,0x0074,0x0020,0x0062,0x0065,0x0066,0x006F,0x0072,0x0065,0x0020,0x0072,0x006F,0x006F,0x0074,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0074,0x0061,0x0067,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0064,0x0020,0x0074,0x0061,0x0067,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0074,0x0079,0x0070,0x0065,0x0020,0x0028,0x0043,0x0044,0x0041,0x0054,0x0041,0x002C,0x0020,0x0049,0x0044,0x002C,0x0020,0x004E,0x004D,0x0054,0x004F,0x004B,0x0045,0x004E,0x002C,0x0020,0x002E,0x002E,0x0029,0x002C,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0074,0x0061,0x0067,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0074,0x0061,0x0067,0x0020,0x006E,0x0061,0x006D,0x0065,0x002C,0x0020,0x0063,0x006F,0x006D,0x006D,0x0065,0x006E,0x0074,0x002C,0x0020,0x0050,0x0049,0x002C,0x0020,0x006F,0x0072,0x0020,0x006F,0x0074,0x0068,0x0065,0x0072,0x0020,0x006D,0x0061,0x0072,0x006B,0x0075,0x0070,0x00 } + , { 0x004E,0x006F,0x0074,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0061,0x0066,0x0074,0x0065,0x0072,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0063,0x006F,0x006D,0x006D,0x0065,0x006E,0x0074,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0063,0x006F,0x006D,0x006D,0x0065,0x006E,0x0074,0x0020,0x006F,0x0072,0x0020,0x0070,0x0072,0x006F,0x0063,0x0065,0x0073,0x0073,0x0069,0x006E,0x0067,0x0020,0x0069,0x006E,0x0073,0x0074,0x0072,0x0075,0x0063,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0077,0x0068,0x0069,0x0074,0x0065,0x0073,0x0070,0x0061,0x0063,0x0065,0x00 } + , { 0x004E,0x006F,0x0020,0x0072,0x006F,0x006F,0x0074,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0069,0x006E,0x0020,0x0044,0x004F,0x0043,0x0054,0x0059,0x0050,0x0045,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0071,0x0075,0x006F,0x0074,0x0065,0x0064,0x0020,0x0073,0x0074,0x0072,0x0069,0x006E,0x0067,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0070,0x0075,0x0062,0x006C,0x0069,0x0063,0x0020,0x0069,0x0064,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0069,0x006E,0x0020,0x0070,0x0075,0x0062,0x006C,0x0069,0x0063,0x0020,0x0069,0x0064,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0044,0x004F,0x0043,0x0054,0x0059,0x0050,0x0045,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0069,0x006E,0x0020,0x0069,0x006E,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x0020,0x0073,0x0075,0x0062,0x0073,0x0065,0x0074,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0043,0x0044,0x0041,0x0054,0x0041,0x0020,0x0073,0x0065,0x0063,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0069,0x006E,0x0069,0x0074,0x0069,0x0061,0x006C,0x0020,0x006E,0x0061,0x006D,0x0065,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x006E,0x0061,0x006D,0x0065,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x00 } + , { 0x0055,0x006E,0x0065,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0077,0x0068,0x0069,0x0074,0x0065,0x0073,0x0070,0x0061,0x0063,0x0065,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0069,0x006E,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0020,0x006D,0x0061,0x0072,0x006B,0x0075,0x0070,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0054,0x0065,0x0078,0x0074,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x006E,0x006F,0x0074,0x0020,0x006C,0x0065,0x0067,0x0061,0x006C,0x0020,0x0068,0x0065,0x0072,0x0065,0x00 } + , { 0x0043,0x006F,0x006E,0x0064,0x0069,0x0074,0x0069,0x006F,0x006E,0x0061,0x006C,0x0020,0x0073,0x0065,0x0063,0x0074,0x0069,0x006F,0x006E,0x0020,0x0069,0x006E,0x0020,0x0069,0x006E,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x0020,0x0073,0x0075,0x0062,0x0073,0x0065,0x0074,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0070,0x0061,0x0072,0x0061,0x006D,0x0065,0x0074,0x0065,0x0072,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x006E,0x0061,0x006D,0x0065,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x006E,0x0061,0x006D,0x0065,0x0020,0x0066,0x006F,0x0072,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x00 } + , { 0x0045,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0066,0x006F,0x0075,0x006E,0x0064,0x00 } + , { 0x0055,0x006E,0x0070,0x0061,0x0072,0x0073,0x0065,0x0064,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0074,0x0079,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0068,0x0065,0x0072,0x0065,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x00 } + , { 0x0052,0x0065,0x0063,0x0075,0x0072,0x0073,0x0069,0x0076,0x0065,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0065,0x0078,0x0070,0x0061,0x006E,0x0073,0x0069,0x006F,0x006E,0x00 } + , { 0x0050,0x0061,0x0072,0x0074,0x0069,0x0061,0x006C,0x0020,0x006D,0x0061,0x0072,0x006B,0x0075,0x0070,0x0020,0x0069,0x006E,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x0073,0x0070,0x0065,0x0063,0x0069,0x0066,0x0069,0x0063,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0065,0x0078,0x0070,0x0072,0x0065,0x0073,0x0073,0x0069,0x006F,0x006E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0073,0x0074,0x0065,0x0072,0x0069,0x0073,0x006B,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0043,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0073,0x0079,0x0073,0x0074,0x0065,0x006D,0x0020,0x0069,0x0064,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0073,0x0079,0x0073,0x0074,0x0065,0x006D,0x0020,0x006F,0x0072,0x0020,0x0070,0x0075,0x0062,0x006C,0x0069,0x0063,0x0020,0x0069,0x0064,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x006E,0x006F,0x0074,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0027,0x002C,0x0027,0x002C,0x0020,0x0027,0x007C,0x0027,0x002C,0x0020,0x006F,0x0072,0x0020,0x0027,0x0029,0x0027,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0073,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0027,0x007C,0x0027,0x0020,0x006F,0x0072,0x0020,0x0027,0x0029,0x0027,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0073,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0027,0x002C,0x0027,0x0020,0x006F,0x0072,0x0020,0x0027,0x0029,0x0027,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0073,0x0020,0x006F,0x0072,0x0020,0x0063,0x006C,0x006F,0x0073,0x0065,0x0020,0x0070,0x0061,0x0072,0x0065,0x006E,0x0074,0x0068,0x0065,0x0073,0x0069,0x0073,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0075,0x006D,0x0065,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x007C,0x0020,0x0065,0x006E,0x0075,0x006D,0x0065,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0073,0x0065,0x0070,0x0061,0x0072,0x0061,0x0074,0x006F,0x0072,0x002C,0x0020,0x006F,0x0072,0x0020,0x0063,0x006C,0x006F,0x0073,0x0069,0x006E,0x0067,0x0020,0x0070,0x0061,0x0072,0x0065,0x006E,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x006C,0x0069,0x0074,0x0065,0x0072,0x0061,0x006C,0x00 } + , { 0x0054,0x0068,0x0065,0x0072,0x0065,0x0020,0x0061,0x0072,0x0065,0x0020,0x006D,0x006F,0x0072,0x0065,0x0020,0x0065,0x006E,0x0064,0x0020,0x0074,0x0061,0x0067,0x0073,0x0020,0x0074,0x0068,0x0061,0x006E,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0074,0x0061,0x0067,0x0073,0x00 } + , { 0x0052,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x0020,0x0074,0x006F,0x0020,0x0065,0x0078,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0069,0x006E,0x0020,0x0073,0x0074,0x0061,0x006E,0x0064,0x0061,0x006C,0x006F,0x006E,0x0065,0x0020,0x0064,0x006F,0x0063,0x0075,0x006D,0x0065,0x006E,0x0074,0x002E,0x0020,0x0045,0x006E,0x0074,0x0069,0x0074,0x0079,0x003D,0x007B,0x0030,0x007D,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x006F,0x0070,0x0065,0x006E,0x0020,0x0070,0x0061,0x0072,0x0065,0x006E,0x0074,0x0068,0x0065,0x0073,0x0069,0x0073,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0069,0x0073,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0075,0x0073,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0031,0x007D,0x0027,0x00 } + , { 0x0041,0x0020,0x0027,0x003C,0x0027,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0075,0x0073,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0061,0x006E,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x002C,0x0020,0x0065,0x0078,0x0063,0x0065,0x0070,0x0074,0x0020,0x0074,0x0068,0x0072,0x006F,0x0075,0x0067,0x0068,0x0020,0x003C,0x00 } + , { 0x0041,0x0020,0x006C,0x0065,0x0061,0x0064,0x0069,0x006E,0x0067,0x0020,0x0073,0x0075,0x0072,0x0072,0x006F,0x0067,0x0061,0x0074,0x0065,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0066,0x006F,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0062,0x0079,0x0020,0x0061,0x0020,0x006C,0x0065,0x0067,0x0061,0x006C,0x0020,0x0073,0x0065,0x0063,0x006F,0x006E,0x0064,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0027,0x005D,0x005D,0x003E,0x0027,0x0020,0x0074,0x006F,0x0020,0x0065,0x006E,0x0064,0x0020,0x0061,0x0020,0x0063,0x006F,0x006E,0x0064,0x0069,0x0074,0x0069,0x006F,0x006E,0x0061,0x006C,0x0020,0x0073,0x0065,0x0063,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0049,0x004E,0x0043,0x004C,0x0055,0x0044,0x0045,0x0020,0x006F,0x0072,0x0020,0x0049,0x0047,0x004E,0x004F,0x0052,0x0045,0x0020,0x0068,0x0065,0x0072,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x005B,0x0020,0x0074,0x006F,0x0020,0x0066,0x006F,0x006C,0x006C,0x006F,0x0077,0x0020,0x0049,0x004E,0x0043,0x004C,0x0055,0x0044,0x0045,0x0020,0x006F,0x0072,0x0020,0x0049,0x0047,0x004E,0x004F,0x0052,0x0045,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0020,0x0054,0x0065,0x0078,0x0074,0x0044,0x0065,0x0063,0x006C,0x0020,0x0068,0x0065,0x0072,0x0065,0x003A,0x0020,0x003C,0x003F,0x0078,0x006D,0x006C,0x0020,0x002E,0x002E,0x002E,0x002E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0020,0x0058,0x004D,0x004C,0x0044,0x0065,0x0063,0x006C,0x0020,0x0068,0x0065,0x0072,0x0065,0x003A,0x0020,0x003C,0x003F,0x0078,0x006D,0x006C,0x0020,0x002E,0x002E,0x002E,0x002E,0x00 } + , { 0x0055,0x006E,0x0065,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x007B,0x0030,0x007D,0x00 } + , { 0x0041,0x0020,0x0050,0x0045,0x0020,0x0070,0x0072,0x006F,0x0070,0x006F,0x0067,0x0061,0x0074,0x0065,0x0064,0x0020,0x006F,0x0075,0x0074,0x0020,0x006F,0x0066,0x0020,0x0074,0x0068,0x0065,0x0020,0x0069,0x006E,0x0074,0x002F,0x0065,0x0078,0x0074,0x0020,0x0073,0x0075,0x0062,0x0073,0x0065,0x0074,0x002C,0x0020,0x0064,0x0069,0x0073,0x0063,0x0061,0x0072,0x0064,0x0069,0x006E,0x0067,0x0020,0x0065,0x0078,0x0074,0x0072,0x0061,0x0020,0x0074,0x0065,0x0078,0x0074,0x00 } + , { 0x0041,0x006E,0x0020,0x0065,0x0078,0x0074,0x0072,0x0061,0x0020,0x005D,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0077,0x0061,0x0073,0x0020,0x0066,0x006F,0x0075,0x006E,0x0064,0x0020,0x0061,0x006E,0x0020,0x0069,0x0067,0x006E,0x006F,0x0072,0x0065,0x0064,0x00 } + , { 0x0050,0x0045,0x0020,0x0072,0x0065,0x0066,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x006E,0x006F,0x0074,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0069,0x006E,0x0073,0x0069,0x0064,0x0065,0x0020,0x006D,0x0061,0x0072,0x006B,0x0075,0x0070,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x0069,0x006E,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x0020,0x0073,0x0075,0x0062,0x0073,0x0065,0x0074,0x00 } + , { 0x0041,0x006E,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0070,0x0072,0x006F,0x0070,0x006F,0x0067,0x0061,0x0074,0x0065,0x0064,0x0020,0x006F,0x0075,0x0074,0x0020,0x006F,0x0066,0x0020,0x0074,0x0068,0x0065,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x0073,0x0065,0x0063,0x0074,0x0069,0x006F,0x006E,0x0020,0x0069,0x006E,0x0074,0x006F,0x0020,0x004D,0x0069,0x0073,0x0063,0x0065,0x006C,0x006C,0x0061,0x006E,0x0065,0x006F,0x0075,0x0073,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0026,0x0023,0x0020,0x0074,0x006F,0x0020,0x0062,0x0065,0x0020,0x0066,0x006F,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0062,0x0079,0x0020,0x0061,0x0020,0x006E,0x0075,0x006D,0x0065,0x0072,0x0069,0x0063,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x006F,0x0070,0x0065,0x006E,0x0020,0x0062,0x0072,0x0061,0x0063,0x006B,0x0065,0x0074,0x0020,0x0028,0x0027,0x005B,0x0027,0x0029,0x0020,0x0068,0x0065,0x0072,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0073,0x0065,0x0071,0x0075,0x0065,0x006E,0x0063,0x0065,0x0020,0x0027,0x005D,0x005D,0x003E,0x0027,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0064,0x0061,0x0074,0x0061,0x00 } + , { 0x0049,0x006C,0x006C,0x0065,0x0067,0x0061,0x006C,0x0020,0x0073,0x0065,0x0071,0x0075,0x0065,0x006E,0x0063,0x0065,0x0020,0x0027,0x002D,0x002D,0x0027,0x0020,0x0069,0x006E,0x0020,0x0063,0x006F,0x006D,0x006D,0x0065,0x006E,0x0074,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0043,0x0044,0x0041,0x0054,0x0041,0x0020,0x0073,0x0065,0x0063,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x004E,0x0044,0x0041,0x0054,0x0041,0x00 } + , { 0x004E,0x0044,0x0041,0x0054,0x0041,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006C,0x0065,0x0067,0x0061,0x006C,0x0020,0x0066,0x006F,0x0072,0x0020,0x0070,0x0061,0x0072,0x0061,0x006D,0x0065,0x0074,0x0065,0x0072,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0069,0x0065,0x0073,0x00 } + , { 0x0048,0x0065,0x0078,0x0020,0x0072,0x0061,0x0064,0x0069,0x0078,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0072,0x0065,0x0066,0x0073,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0075,0x0073,0x0065,0x0020,0x0027,0x0078,0x0027,0x002C,0x0020,0x006E,0x006F,0x0074,0x0020,0x0027,0x0058,0x0027,0x00 } + , { 0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0062,0x0065,0x0065,0x006E,0x0020,0x0073,0x0065,0x0074,0x002E,0x0020,0x0049,0x0067,0x006E,0x006F,0x0072,0x0069,0x006E,0x0067,0x0020,0x0072,0x0065,0x0064,0x0075,0x006E,0x0064,0x0061,0x006E,0x0074,0x0020,0x0073,0x0065,0x0074,0x0074,0x0069,0x006E,0x0067,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0058,0x004D,0x004C,0x0044,0x0065,0x0063,0x006C,0x0020,0x0073,0x0074,0x0072,0x0069,0x006E,0x0067,0x0073,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0062,0x0065,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x006F,0x0072,0x0064,0x0065,0x0072,0x003A,0x0020,0x0076,0x0065,0x0072,0x0073,0x0069,0x006F,0x006E,0x002C,0x0020,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x002C,0x0020,0x0073,0x0074,0x0061,0x006E,0x0064,0x0061,0x006C,0x006F,0x006E,0x0065,0x00 } + , { 0x0045,0x0078,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0069,0x0065,0x0073,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0072,0x0065,0x0064,0x0020,0x0074,0x006F,0x0020,0x0066,0x0072,0x006F,0x006D,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0073,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0058,0x004D,0x004C,0x0020,0x006F,0x0072,0x0020,0x0054,0x0065,0x0078,0x0074,0x0020,0x0064,0x0065,0x0063,0x006C,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0077,0x0069,0x0074,0x0068,0x0020,0x0027,0x003C,0x003F,0x0078,0x006D,0x006C,0x0020,0x0027,0x002C,0x0020,0x006E,0x006F,0x0074,0x0020,0x0027,0x003C,0x003F,0x0058,0x004D,0x004C,0x0020,0x0027,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0061,0x0020,0x006C,0x0069,0x0074,0x0065,0x0072,0x0061,0x006C,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0020,0x006F,0x0072,0x0020,0x0050,0x0055,0x0042,0x004C,0x0049,0x0043,0x002F,0x0053,0x0059,0x0053,0x0054,0x0045,0x004D,0x0020,0x0069,0x0064,0x00 } + , { 0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0061,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0064,0x0069,0x0067,0x0069,0x0074,0x0020,0x0066,0x006F,0x0072,0x0020,0x0074,0x0068,0x0065,0x0020,0x0069,0x006E,0x0064,0x0069,0x0063,0x0061,0x0074,0x0065,0x0064,0x0020,0x0072,0x0061,0x0064,0x0069,0x0078,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0069,0x006E,0x0070,0x0075,0x0074,0x0020,0x0065,0x006E,0x0064,0x0065,0x0064,0x0020,0x0062,0x0065,0x0066,0x006F,0x0072,0x0065,0x0020,0x0061,0x006C,0x006C,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0065,0x0064,0x0020,0x0074,0x0061,0x0067,0x0073,0x0020,0x0077,0x0065,0x0072,0x0065,0x0020,0x0065,0x006E,0x0064,0x0065,0x0064,0x002E,0x0020,0x004C,0x0061,0x0073,0x0074,0x0020,0x0074,0x0061,0x0067,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0065,0x0064,0x0020,0x0077,0x0061,0x0073,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x0020,0x0066,0x006F,0x0072,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0069,0x0073,0x0020,0x0061,0x006D,0x0062,0x0069,0x0067,0x0075,0x006F,0x0075,0x0073,0x00 } + , { 0x004E,0x0065,0x0073,0x0074,0x0065,0x0064,0x0020,0x0043,0x0044,0x0041,0x0054,0x0041,0x0020,0x0073,0x0065,0x0063,0x0074,0x0069,0x006F,0x006E,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x006E,0x006F,0x0074,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0072,0x0065,0x0066,0x0069,0x0078,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0065,0x006E,0x0020,0x006D,0x0061,0x0070,0x0070,0x0065,0x0064,0x0020,0x0074,0x006F,0x0020,0x0061,0x006E,0x0079,0x0020,0x0055,0x0052,0x0049,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0061,0x006E,0x0064,0x0020,0x0074,0x0068,0x0065,0x0020,0x0065,0x006E,0x0064,0x0020,0x0074,0x0061,0x0067,0x0020,0x0077,0x0065,0x0072,0x0065,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x0064,0x0069,0x0066,0x0066,0x0065,0x0072,0x0065,0x006E,0x0074,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0069,0x0065,0x0073,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x006D,0x0061,0x0069,0x006E,0x0020,0x0058,0x004D,0x004C,0x0020,0x0064,0x006F,0x0063,0x0075,0x006D,0x0065,0x006E,0x0074,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0065,0x006D,0x0070,0x0074,0x0079,0x00 } + , { 0x0043,0x0044,0x0041,0x0054,0x0041,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x006F,0x0075,0x0074,0x0073,0x0069,0x0064,0x0065,0x0020,0x0074,0x0068,0x0065,0x0020,0x0072,0x006F,0x006F,0x0074,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x00 } + , { 0x004F,0x006E,0x006C,0x0079,0x0020,0x006E,0x0075,0x006D,0x0065,0x0072,0x0069,0x0063,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0069,0x0065,0x0073,0x0020,0x006F,0x0072,0x0020,0x0073,0x0070,0x0065,0x0063,0x0069,0x0061,0x006C,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0069,0x0065,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x006C,0x0065,0x0067,0x0061,0x006C,0x0020,0x0068,0x0065,0x0072,0x0065,0x00 } + , { 0x0047,0x006F,0x0074,0x0020,0x0061,0x006E,0x0020,0x0075,0x006E,0x0065,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0074,0x0072,0x0061,0x0069,0x006C,0x0069,0x006E,0x0067,0x0020,0x0073,0x0075,0x0072,0x0072,0x006F,0x0067,0x0061,0x0074,0x0065,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x00 } + , { 0x004E,0x006F,0x0020,0x0070,0x0072,0x006F,0x0063,0x0065,0x0073,0x0073,0x0069,0x006E,0x0067,0x0020,0x0069,0x006E,0x0073,0x0074,0x0072,0x0075,0x0063,0x0074,0x0069,0x006F,0x006E,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0073,0x0020,0x0077,0x0069,0x0074,0x0068,0x0020,0x0027,0x0078,0x006D,0x006C,0x0027,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0058,0x004D,0x004C,0x0020,0x006F,0x0072,0x0020,0x0054,0x0065,0x0078,0x0074,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0061,0x0074,0x0020,0x006C,0x0069,0x006E,0x0065,0x002F,0x0063,0x006F,0x006C,0x0075,0x006D,0x006E,0x0020,0x0031,0x002F,0x0031,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0027,0x0076,0x0065,0x0072,0x0073,0x0069,0x006F,0x006E,0x003D,0x0027,0x0020,0x0073,0x0074,0x0072,0x0069,0x006E,0x0067,0x0020,0x0069,0x0073,0x0020,0x0072,0x0065,0x0071,0x0075,0x0069,0x0072,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0061,0x006E,0x0020,0x0058,0x004D,0x004C,0x0044,0x0065,0x0063,0x006C,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0027,0x0073,0x0074,0x0061,0x006E,0x0064,0x0061,0x006C,0x006F,0x006E,0x0065,0x003D,0x0027,0x0020,0x0073,0x0074,0x0072,0x0069,0x006E,0x0067,0x0020,0x0069,0x0073,0x0020,0x006F,0x006E,0x006C,0x0079,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x006D,0x0061,0x0069,0x006E,0x0020,0x0058,0x004D,0x004C,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x00 } + , { 0x0057,0x0068,0x0065,0x006E,0x0020,0x006E,0x0061,0x006D,0x0065,0x0073,0x0070,0x0061,0x0063,0x0065,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x0065,0x006E,0x0061,0x0062,0x006C,0x0065,0x0064,0x002C,0x0020,0x0061,0x0020,0x006E,0x0061,0x006D,0x0065,0x0020,0x0063,0x0061,0x006E,0x0020,0x0068,0x0061,0x0076,0x0065,0x0020,0x006F,0x006E,0x006C,0x0079,0x0020,0x006F,0x006E,0x0065,0x0020,0x0063,0x006F,0x006C,0x006F,0x006E,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x00 } + , { 0x0057,0x0068,0x0065,0x006E,0x0020,0x006E,0x0061,0x006D,0x0065,0x0073,0x0070,0x0061,0x0063,0x0065,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x0065,0x006E,0x0061,0x0062,0x006C,0x0065,0x0064,0x002C,0x0020,0x0074,0x0068,0x0065,0x0020,0x0063,0x006F,0x006C,0x006F,0x006E,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0074,0x0068,0x0065,0x0020,0x0066,0x0069,0x0072,0x0073,0x0074,0x0020,0x006F,0x0072,0x0020,0x006C,0x0061,0x0073,0x0074,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x00 } + , { 0x0043,0x006F,0x006C,0x006F,0x006E,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x006E,0x006F,0x0074,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0069,0x0073,0x0020,0x006E,0x0061,0x006D,0x0065,0x0020,0x0077,0x0068,0x0065,0x006E,0x0020,0x006E,0x0061,0x006D,0x0065,0x0073,0x0070,0x0061,0x0063,0x0065,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x0065,0x006E,0x0061,0x0062,0x006C,0x0065,0x0064,0x00 } + , { 0x0041,0x0020,0x0073,0x0079,0x0073,0x0074,0x0065,0x006D,0x0020,0x0065,0x0078,0x0063,0x0065,0x0070,0x0074,0x0069,0x006F,0x006E,0x0020,0x006F,0x0063,0x0063,0x0075,0x0072,0x0065,0x0064,0x0020,0x0064,0x0075,0x0072,0x0069,0x006E,0x0067,0x0020,0x0070,0x0072,0x006F,0x0063,0x0065,0x0073,0x0073,0x0069,0x006E,0x0067,0x00 } + , { 0x0041,0x006E,0x0020,0x0065,0x0078,0x0063,0x0065,0x0070,0x0074,0x0069,0x006F,0x006E,0x0020,0x006F,0x0063,0x0063,0x0075,0x0072,0x0065,0x0064,0x0021,0x0020,0x0054,0x0079,0x0070,0x0065,0x003A,0x007B,0x0030,0x007D,0x002C,0x0020,0x004D,0x0065,0x0073,0x0073,0x0061,0x0067,0x0065,0x003A,0x007B,0x0031,0x007D,0x00 } + , { 0x0055,0x006E,0x0065,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x0065,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0066,0x0069,0x006C,0x0065,0x0020,0x0065,0x0078,0x0063,0x0065,0x0070,0x0074,0x0069,0x006F,0x006E,0x002E,0x0020,0x004D,0x0065,0x0073,0x0073,0x0061,0x0067,0x0065,0x003A,0x0020,0x007B,0x0030,0x007D,0x00 } + , { 0x0045,0x005F,0x0045,0x006E,0x0064,0x00 } + +}; +const unsigned int gXMLErrArraySize = 133; + +const XMLCh gXMLValidityArray[][128] = +{ + { 0x0056,0x005F,0x0053,0x0074,0x0061,0x0072,0x0074,0x00 } + , { 0x0055,0x006E,0x006B,0x006E,0x006F,0x0077,0x006E,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x006E,0x006F,0x0074,0x0020,0x0064,0x0065,0x0066,0x0069,0x006E,0x0065,0x0064,0x00 } + , { 0x004E,0x006F,0x0074,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0077,0x0061,0x0073,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x0064,0x0020,0x0062,0x0075,0x0074,0x0020,0x006E,0x0065,0x0076,0x0065,0x0072,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0052,0x006F,0x006F,0x0074,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0064,0x0069,0x0066,0x0066,0x0065,0x0072,0x0065,0x006E,0x0074,0x0020,0x0066,0x0072,0x006F,0x006D,0x0020,0x0044,0x004F,0x0043,0x0054,0x0059,0x0050,0x0045,0x00 } + , { 0x0052,0x0065,0x0071,0x0075,0x0069,0x0072,0x0065,0x0064,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0070,0x0072,0x006F,0x0076,0x0069,0x0064,0x0065,0x0064,0x00 } + , { 0x0045,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0066,0x006F,0x0072,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x003A,0x0020,0x0027,0x007B,0x0031,0x007D,0x0027,0x00 } + , { 0x0049,0x0044,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0073,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0062,0x0065,0x0020,0x0023,0x0049,0x004D,0x0050,0x004C,0x0049,0x0045,0x0044,0x0020,0x006F,0x0072,0x0020,0x0023,0x0052,0x0045,0x0051,0x0055,0x0049,0x0052,0x0045,0x0044,0x00 } + , { 0x0054,0x0068,0x0069,0x0073,0x0020,0x0074,0x0079,0x0070,0x0065,0x0020,0x006F,0x0066,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0068,0x0061,0x0076,0x0065,0x0020,0x0061,0x006E,0x0020,0x0065,0x006D,0x0070,0x0074,0x0079,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0045,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0062,0x0065,0x0065,0x006E,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0045,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x006D,0x006F,0x0072,0x0065,0x0020,0x0074,0x0068,0x0061,0x006E,0x0020,0x006F,0x006E,0x0065,0x0020,0x0049,0x0044,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x00 } + , { 0x0049,0x0044,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0062,0x0065,0x0065,0x006E,0x0020,0x0075,0x0073,0x0065,0x0064,0x00 } + , { 0x0049,0x0044,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0077,0x0061,0x0073,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0065,0x006E,0x0063,0x0065,0x0064,0x0020,0x0062,0x0075,0x0074,0x0020,0x006E,0x0065,0x0076,0x0065,0x0072,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0073,0x0020,0x0074,0x006F,0x0020,0x0061,0x006E,0x0020,0x0075,0x006E,0x006B,0x006E,0x006F,0x0077,0x006E,0x0020,0x006E,0x006F,0x0074,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0027,0x007B,0x0031,0x007D,0x0027,0x00 } + , { 0x0045,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0077,0x0061,0x0073,0x0020,0x0075,0x0073,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x0044,0x004F,0x0043,0x0054,0x0059,0x0050,0x0045,0x0020,0x0062,0x0075,0x0074,0x0020,0x006E,0x0065,0x0076,0x0065,0x0072,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x00 } + , { 0x0045,0x006D,0x0070,0x0074,0x0079,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006E,0x006F,0x0074,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0066,0x006F,0x0072,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x003A,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x007B,0x0030,0x007D,0x007D,0x007B,0x0031,0x007D,0x0027,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0064,0x0065,0x0063,0x006C,0x0061,0x0072,0x0065,0x0064,0x0020,0x0066,0x006F,0x0072,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0027,0x007B,0x0032,0x007D,0x0027,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0073,0x0020,0x006F,0x0066,0x0020,0x0074,0x0079,0x0070,0x0065,0x0020,0x0045,0x004E,0x0054,0x0049,0x0054,0x0059,0x002F,0x0045,0x004E,0x0054,0x0049,0x0054,0x0049,0x0045,0x0053,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0020,0x0074,0x006F,0x0020,0x0061,0x006E,0x0020,0x0065,0x0078,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x002C,0x0020,0x0075,0x006E,0x0070,0x0061,0x0072,0x0073,0x0065,0x0064,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0072,0x0065,0x0066,0x0065,0x0072,0x0073,0x0020,0x0074,0x006F,0x0020,0x0061,0x006E,0x0020,0x0075,0x006E,0x006B,0x006E,0x006F,0x0077,0x006E,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0027,0x007B,0x0031,0x007D,0x0027,0x00 } + , { 0x004E,0x006F,0x0074,0x0020,0x0065,0x006E,0x006F,0x0075,0x0067,0x0068,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0073,0x0020,0x0074,0x006F,0x0020,0x006D,0x0061,0x0074,0x0063,0x0068,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x0020,0x003A,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x004E,0x006F,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0064,0x0061,0x0074,0x0061,0x0020,0x0069,0x0073,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0062,0x0079,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0064,0x006F,0x0065,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006D,0x0061,0x0074,0x0063,0x0068,0x0020,0x0069,0x0074,0x0073,0x0020,0x0064,0x0065,0x0066,0x0069,0x006E,0x0065,0x0064,0x0020,0x0065,0x006E,0x0075,0x006D,0x0065,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x006F,0x0072,0x0020,0x006E,0x006F,0x0074,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x006C,0x0069,0x0073,0x0074,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0073,0x0020,0x0066,0x006F,0x0072,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0062,0x0065,0x0020,0x006E,0x0061,0x006D,0x0065,0x0073,0x0020,0x006F,0x0072,0x0020,0x006E,0x0061,0x006D,0x0065,0x0020,0x0074,0x006F,0x006B,0x0065,0x006E,0x0073,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0064,0x006F,0x0065,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0073,0x0075,0x0070,0x0070,0x006F,0x0072,0x0074,0x0020,0x006D,0x0075,0x006C,0x0074,0x0069,0x0070,0x006C,0x0065,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0073,0x00 } + , { 0x0041,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0068,0x0061,0x0073,0x0020,0x0061,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0020,0x0074,0x0068,0x0061,0x0074,0x0020,0x0064,0x006F,0x0065,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006D,0x0061,0x0074,0x0063,0x0068,0x0020,0x0069,0x0074,0x0073,0x0020,0x0023,0x0046,0x0049,0x0058,0x0045,0x0044,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0045,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0074,0x0079,0x0070,0x0065,0x0073,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0064,0x0075,0x0070,0x006C,0x0069,0x0063,0x0061,0x0074,0x0065,0x0064,0x0020,0x0069,0x006E,0x0020,0x004D,0x0069,0x0078,0x0065,0x0064,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x0073,0x00 } + , { 0x0056,0x005F,0x0045,0x006E,0x0064,0x00 } + +}; +const unsigned int gXMLValidityArraySize = 32; + +const XMLCh gXMLExceptArray[][128] = +{ + { 0x0045,0x005F,0x0053,0x0074,0x0061,0x0072,0x0074,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x0020,0x0069,0x0073,0x0020,0x0062,0x0065,0x0079,0x006F,0x006E,0x0064,0x0020,0x0074,0x0068,0x0065,0x0020,0x0061,0x0072,0x0072,0x0061,0x0079,0x0020,0x0062,0x006F,0x0075,0x006E,0x0064,0x0073,0x0020,0x0020,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x006E,0x0065,0x0077,0x0020,0x0073,0x0069,0x007A,0x0065,0x0020,0x0069,0x0073,0x0020,0x006C,0x0065,0x0073,0x0073,0x0020,0x0074,0x0068,0x0061,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x006F,0x006C,0x0064,0x0020,0x006F,0x006E,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0062,0x0069,0x0074,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x0020,0x0077,0x0061,0x0073,0x0020,0x0062,0x0065,0x0079,0x006F,0x006E,0x0064,0x0020,0x0074,0x0068,0x0065,0x0020,0x0073,0x0065,0x0074,0x0020,0x0073,0x0069,0x007A,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x006F,0x0069,0x006E,0x0074,0x0065,0x0072,0x0020,0x0068,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0065,0x006E,0x0020,0x0073,0x0065,0x0074,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0065,0x006E,0x0075,0x006D,0x0065,0x0072,0x0061,0x0074,0x006F,0x0072,0x0020,0x0063,0x006F,0x006E,0x0074,0x0061,0x0069,0x006E,0x0073,0x0020,0x006E,0x006F,0x0020,0x006D,0x006F,0x0072,0x0065,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0073,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x006F,0x0070,0x0065,0x006E,0x0020,0x0066,0x0069,0x006C,0x0065,0x003A,0x0020,0x007B,0x0030,0x007D,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0071,0x0075,0x0065,0x0072,0x0079,0x0020,0x0074,0x0068,0x0065,0x0020,0x0063,0x0075,0x0072,0x0072,0x0065,0x006E,0x0074,0x0020,0x0066,0x0069,0x006C,0x0065,0x0020,0x0070,0x006F,0x0073,0x0069,0x0074,0x0069,0x006F,0x006E,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0063,0x006C,0x006F,0x0073,0x0065,0x0020,0x0074,0x0068,0x0065,0x0020,0x0066,0x0069,0x006C,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0073,0x0065,0x0065,0x006B,0x0020,0x0074,0x006F,0x0020,0x0065,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0066,0x0069,0x006C,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0073,0x0065,0x0065,0x006B,0x0020,0x0074,0x006F,0x0020,0x0072,0x0065,0x0071,0x0075,0x0069,0x0072,0x0065,0x0064,0x0020,0x0070,0x006F,0x0073,0x0069,0x0074,0x0069,0x006F,0x006E,0x0020,0x0069,0x006E,0x0020,0x0066,0x0069,0x006C,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0064,0x0075,0x0070,0x006C,0x0069,0x0063,0x0061,0x0074,0x0065,0x0020,0x0074,0x0068,0x0065,0x0020,0x0068,0x0061,0x006E,0x0064,0x006C,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0072,0x0065,0x0061,0x0064,0x0020,0x0064,0x0061,0x0074,0x0061,0x0020,0x0066,0x0072,0x006F,0x006D,0x0020,0x0066,0x0069,0x006C,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0072,0x0065,0x0073,0x0065,0x0074,0x0020,0x0066,0x0069,0x006C,0x0065,0x0020,0x0074,0x006F,0x0020,0x0062,0x0065,0x0067,0x0069,0x006E,0x006E,0x0069,0x006E,0x0067,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0061,0x0063,0x0065,0x0072,0x0074,0x0061,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x0066,0x0069,0x006C,0x0065,0x0020,0x0073,0x0069,0x007A,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0064,0x0065,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0065,0x0020,0x0062,0x0061,0x0073,0x0065,0x0020,0x0070,0x0061,0x0074,0x0068,0x006E,0x0061,0x006D,0x0065,0x0020,0x006F,0x0066,0x0020,0x0074,0x0068,0x0065,0x0020,0x0066,0x0069,0x006C,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0068,0x0061,0x0073,0x0068,0x0020,0x006D,0x006F,0x0064,0x0075,0x006C,0x0075,0x0073,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x007A,0x0065,0x0072,0x006F,0x00 } + , { 0x0048,0x0061,0x0073,0x0068,0x0069,0x006E,0x0067,0x0020,0x0074,0x0068,0x0065,0x0020,0x006B,0x0065,0x0079,0x0020,0x0072,0x0065,0x0074,0x0075,0x0072,0x006E,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x0069,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0062,0x0061,0x0064,0x0020,0x0068,0x0061,0x0073,0x0068,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x006B,0x0065,0x0079,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x0020,0x0063,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0066,0x006F,0x0075,0x006E,0x0064,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x0068,0x0061,0x0073,0x0068,0x0020,0x0074,0x0061,0x0062,0x006C,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0063,0x0072,0x0065,0x0061,0x0074,0x0065,0x0020,0x006D,0x0075,0x0074,0x0065,0x0078,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0063,0x006C,0x006F,0x0073,0x0065,0x0020,0x006D,0x0075,0x0074,0x0065,0x0078,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x006C,0x006F,0x0063,0x006B,0x0020,0x006D,0x0075,0x0074,0x0065,0x0078,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0075,0x006E,0x006C,0x006F,0x0063,0x006B,0x0020,0x006D,0x0075,0x0074,0x0065,0x0078,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0064,0x0065,0x0073,0x0074,0x0072,0x006F,0x0079,0x0020,0x006D,0x0075,0x0074,0x0065,0x0078,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x007B,0x0030,0x007D,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0065,0x0078,0x0069,0x0073,0x0074,0x0073,0x00 } + , { 0x0048,0x0061,0x0073,0x0068,0x0069,0x006E,0x0067,0x0020,0x0074,0x0068,0x0065,0x0020,0x006B,0x0065,0x0079,0x0020,0x0072,0x0065,0x0074,0x0075,0x0072,0x006E,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x0069,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0062,0x0061,0x0064,0x0020,0x0068,0x0061,0x0073,0x0068,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0061,0x0073,0x0073,0x0065,0x0064,0x0020,0x0069,0x0064,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0066,0x006F,0x0072,0x0020,0x0074,0x0068,0x0069,0x0073,0x0020,0x0070,0x006F,0x006F,0x006C,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x006D,0x006F,0x0064,0x0075,0x006C,0x0075,0x0073,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x007A,0x0065,0x0072,0x006F,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x0020,0x0069,0x0073,0x0020,0x0070,0x0061,0x0073,0x0074,0x0020,0x0074,0x0068,0x0065,0x0020,0x0074,0x006F,0x0070,0x0020,0x006F,0x0066,0x0020,0x0073,0x0074,0x0061,0x0063,0x006B,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0073,0x0074,0x0061,0x0063,0x006B,0x0020,0x0069,0x0073,0x0020,0x0065,0x006D,0x0070,0x0074,0x0079,0x002C,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0061,0x0063,0x0063,0x0065,0x0073,0x0073,0x0020,0x006D,0x0065,0x006D,0x0062,0x0065,0x0072,0x0073,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0074,0x0061,0x0072,0x0067,0x0065,0x0074,0x0020,0x0062,0x0075,0x0066,0x0066,0x0065,0x0072,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0068,0x0061,0x0076,0x0065,0x0020,0x0061,0x0020,0x006D,0x0061,0x0078,0x0020,0x0073,0x0069,0x007A,0x0065,0x0020,0x006F,0x0066,0x0020,0x007A,0x0065,0x0072,0x006F,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0067,0x0069,0x0076,0x0065,0x006E,0x0020,0x0072,0x0061,0x0064,0x0069,0x0078,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0073,0x0075,0x0070,0x0070,0x006F,0x0072,0x0074,0x0065,0x0064,0x002E,0x0020,0x0055,0x0073,0x0065,0x0020,0x0032,0x002C,0x0020,0x0038,0x002C,0x0020,0x0031,0x0030,0x002C,0x0020,0x006F,0x0072,0x0020,0x0031,0x0036,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0074,0x0061,0x0072,0x0067,0x0065,0x0074,0x0020,0x0062,0x0075,0x0066,0x0066,0x0065,0x0072,0x0020,0x0069,0x0073,0x0020,0x0074,0x006F,0x006F,0x0020,0x0073,0x006D,0x0061,0x006C,0x006C,0x0020,0x0074,0x006F,0x0020,0x0061,0x0063,0x0063,0x0065,0x0070,0x0074,0x0020,0x0074,0x0068,0x0065,0x0020,0x0072,0x0065,0x0073,0x0075,0x006C,0x0074,0x0073,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x0020,0x0069,0x0073,0x0020,0x0070,0x0061,0x0073,0x0074,0x0020,0x0074,0x0068,0x0065,0x0020,0x0065,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0074,0x0068,0x0065,0x0020,0x0073,0x0074,0x0072,0x0069,0x006E,0x0067,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0077,0x0072,0x0069,0x0074,0x0065,0x0020,0x0074,0x006F,0x0020,0x0073,0x0074,0x0061,0x006E,0x0064,0x0061,0x0072,0x0064,0x0020,0x0065,0x0072,0x0072,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0077,0x0072,0x0069,0x0074,0x0065,0x0020,0x0074,0x006F,0x0020,0x0073,0x0074,0x0061,0x006E,0x0064,0x0061,0x0072,0x0064,0x0020,0x006F,0x0075,0x0074,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0077,0x0072,0x0069,0x0074,0x0065,0x0020,0x0074,0x006F,0x0020,0x0063,0x006F,0x006E,0x0073,0x006F,0x006C,0x0065,0x00 } + , { 0x0053,0x0074,0x0072,0x0069,0x006E,0x0067,0x0020,0x0070,0x006F,0x006F,0x006C,0x0020,0x0069,0x0064,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006C,0x0065,0x0067,0x0061,0x006C,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0055,0x0052,0x004C,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0063,0x006F,0x0072,0x0072,0x0065,0x0063,0x0074,0x006C,0x0079,0x0020,0x0066,0x006F,0x0072,0x006D,0x0065,0x0064,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0055,0x0052,0x004C,0x0020,0x0075,0x0073,0x0065,0x0064,0x0020,0x0061,0x006E,0x0020,0x0075,0x006E,0x0073,0x0075,0x0070,0x0070,0x006F,0x0072,0x0074,0x0065,0x0064,0x0020,0x0070,0x0072,0x006F,0x0074,0x006F,0x0063,0x006F,0x006C,0x00 } + , { 0x0055,0x006E,0x0073,0x0075,0x0070,0x0070,0x006F,0x0072,0x0074,0x0065,0x0064,0x0020,0x0055,0x0052,0x004C,0x0020,0x0070,0x0072,0x006F,0x0074,0x006F,0x0063,0x006F,0x006C,0x003A,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x004F,0x006E,0x006C,0x0079,0x0020,0x006C,0x006F,0x0063,0x0061,0x006C,0x0068,0x006F,0x0073,0x0074,0x0020,0x0069,0x0073,0x0020,0x0073,0x0075,0x0070,0x0070,0x006F,0x0072,0x0074,0x0065,0x0064,0x0020,0x0061,0x0074,0x0020,0x0074,0x0068,0x0069,0x0073,0x0020,0x0074,0x0069,0x006D,0x0065,0x00 } + , { 0x004E,0x006F,0x0020,0x0070,0x0072,0x006F,0x0074,0x006F,0x0063,0x006F,0x006C,0x0020,0x0070,0x0072,0x0065,0x0066,0x0069,0x0078,0x0020,0x0070,0x0072,0x0065,0x0073,0x0065,0x006E,0x0074,0x00 } + , { 0x0045,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x0020,0x002F,0x002F,0x0020,0x0061,0x0066,0x0074,0x0065,0x0072,0x0020,0x0070,0x0072,0x006F,0x0074,0x006F,0x0063,0x006F,0x006C,0x00 } + , { 0x0025,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0062,0x0065,0x0020,0x0066,0x006F,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x0020,0x0062,0x0079,0x0020,0x0074,0x0077,0x006F,0x0020,0x0068,0x0065,0x0078,0x0020,0x0064,0x0069,0x0067,0x0069,0x0074,0x0073,0x00 } + , { 0x0055,0x006E,0x0074,0x0065,0x0072,0x006D,0x0069,0x006E,0x0061,0x0074,0x0065,0x0064,0x0020,0x0068,0x006F,0x0073,0x0074,0x0020,0x0063,0x006F,0x006D,0x0070,0x006F,0x006E,0x0065,0x006E,0x0074,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0061,0x0073,0x0073,0x0065,0x0064,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x0020,0x0069,0x0073,0x0020,0x0070,0x0061,0x0073,0x0074,0x0020,0x0074,0x0068,0x0065,0x0020,0x0065,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0074,0x0068,0x0065,0x0020,0x0076,0x0065,0x0063,0x0074,0x006F,0x0072,0x00 } + , { 0x0050,0x0061,0x0072,0x0073,0x0065,0x0020,0x006D,0x0061,0x0079,0x0020,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0063,0x0061,0x006C,0x006C,0x0065,0x0064,0x0020,0x0077,0x0068,0x0069,0x006C,0x0065,0x0020,0x0070,0x0061,0x0072,0x0073,0x0069,0x006E,0x0067,0x00 } + , { 0x0041,0x0020,0x0044,0x004F,0x0043,0x0054,0x0059,0x0050,0x0045,0x0020,0x0077,0x0061,0x0073,0x0020,0x0073,0x0065,0x0065,0x006E,0x0020,0x0062,0x0075,0x0074,0x0020,0x0074,0x0068,0x0065,0x0020,0x0069,0x006E,0x0073,0x0074,0x0061,0x006C,0x006C,0x0065,0x0064,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0061,0x0074,0x006F,0x0072,0x0020,0x0064,0x006F,0x0065,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0075,0x006E,0x0064,0x0065,0x0072,0x0073,0x0074,0x0061,0x006E,0x0064,0x0020,0x0044,0x0054,0x0044,0x0073,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x006F,0x0070,0x0065,0x006E,0x0020,0x0044,0x0054,0x0044,0x0020,0x0066,0x0069,0x006C,0x0065,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x006F,0x0070,0x0065,0x006E,0x0020,0x0065,0x0078,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0027,0x007B,0x0030,0x007D,0x0027,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0065,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0069,0x006E,0x0070,0x0075,0x0074,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0065,0x0078,0x0070,0x0065,0x0063,0x0074,0x0065,0x0064,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x0020,0x0067,0x0069,0x0076,0x0065,0x006E,0x0020,0x0077,0x0061,0x0073,0x0020,0x0062,0x0065,0x0079,0x006F,0x006E,0x0064,0x0020,0x0074,0x0068,0x0065,0x0020,0x006D,0x0061,0x0078,0x0020,0x0061,0x0074,0x0074,0x0072,0x0069,0x0062,0x0075,0x0074,0x0065,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0073,0x0074,0x0061,0x0063,0x006B,0x0020,0x0069,0x0073,0x0020,0x0065,0x006D,0x0070,0x0074,0x0079,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0073,0x0074,0x0061,0x0063,0x006B,0x0020,0x0069,0x006E,0x0064,0x0065,0x0078,0x0020,0x0067,0x0069,0x0076,0x0065,0x006E,0x0020,0x0077,0x0061,0x0073,0x0020,0x0062,0x0065,0x0079,0x006F,0x006E,0x0064,0x0020,0x0074,0x0068,0x0065,0x0020,0x0073,0x0074,0x0061,0x0063,0x006B,0x0020,0x0074,0x006F,0x0070,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0073,0x0074,0x0061,0x0063,0x006B,0x0020,0x0077,0x0061,0x0073,0x0020,0x0061,0x006C,0x0072,0x0065,0x0061,0x0064,0x0079,0x0020,0x0065,0x006D,0x0070,0x0074,0x0079,0x0020,0x0077,0x0068,0x0065,0x006E,0x0020,0x0061,0x0020,0x0070,0x006F,0x0070,0x0020,0x0072,0x0065,0x0071,0x0075,0x0065,0x0073,0x0074,0x0020,0x006F,0x0063,0x0063,0x0075,0x0072,0x0065,0x0064,0x00 } + , { 0x0041,0x0020,0x0070,0x0061,0x0072,0x0065,0x006E,0x0074,0x0020,0x006F,0x0070,0x0065,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0077,0x0061,0x0073,0x0020,0x0072,0x0065,0x0071,0x0075,0x0065,0x0073,0x0074,0x0065,0x0064,0x002C,0x0020,0x0062,0x0075,0x0074,0x0020,0x006F,0x006E,0x006C,0x0079,0x0020,0x006F,0x006E,0x0065,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0069,0x0073,0x0020,0x006F,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x0073,0x0074,0x0061,0x0063,0x006B,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0069,0x006E,0x0064,0x0069,0x0063,0x0061,0x0074,0x0065,0x0064,0x0020,0x0072,0x0065,0x0061,0x0064,0x0065,0x0072,0x0020,0x0069,0x0064,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x0065,0x0076,0x0065,0x0072,0x0020,0x0066,0x006F,0x0075,0x006E,0x0064,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0061,0x0075,0x0074,0x006F,0x0020,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x0020,0x0065,0x006E,0x0075,0x006D,0x0020,0x0068,0x0061,0x0073,0x0020,0x0061,0x006E,0x0020,0x0075,0x006E,0x006B,0x006E,0x006F,0x0077,0x006E,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0063,0x0072,0x0065,0x0061,0x0074,0x0065,0x0020,0x0061,0x0020,0x0063,0x006F,0x006E,0x0076,0x0065,0x0072,0x0074,0x0065,0x0072,0x0020,0x0066,0x006F,0x0072,0x0020,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x003A,0x0020,0x007B,0x0030,0x007D,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0064,0x0065,0x0063,0x006F,0x0064,0x0065,0x0020,0x0066,0x0069,0x0072,0x0073,0x0074,0x0020,0x006C,0x0069,0x006E,0x0065,0x0020,0x006F,0x0066,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x003A,0x0020,0x007B,0x0030,0x007D,0x00 } + , { 0x0045,0x006E,0x0064,0x0020,0x006F,0x0066,0x0020,0x0069,0x006E,0x0070,0x0075,0x0074,0x0020,0x0077,0x0061,0x0073,0x0020,0x0068,0x0069,0x0074,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0065,0x0020,0x006D,0x0069,0x0064,0x0064,0x006C,0x0065,0x0020,0x006F,0x0066,0x0020,0x0061,0x0020,0x006D,0x0075,0x006C,0x0074,0x0069,0x0062,0x0079,0x0074,0x0065,0x0020,0x0073,0x0065,0x0071,0x0075,0x0065,0x006E,0x0063,0x0065,0x00 } + , { 0x0054,0x0068,0x0069,0x0073,0x0020,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x0020,0x0028,0x007B,0x0030,0x007D,0x0029,0x0073,0x0068,0x006F,0x0075,0x006C,0x0064,0x0020,0x0068,0x0061,0x0076,0x0065,0x0020,0x0068,0x0061,0x0064,0x0020,0x0061,0x0020,0x0074,0x0072,0x0061,0x006E,0x0073,0x0063,0x006F,0x0064,0x0065,0x0072,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0073,0x0065,0x0063,0x006F,0x006E,0x0064,0x0020,0x0062,0x0079,0x0074,0x0065,0x0020,0x006F,0x0066,0x0020,0x0061,0x0020,0x0055,0x0054,0x0046,0x002D,0x0038,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0073,0x0065,0x0071,0x0075,0x0065,0x006E,0x0063,0x0065,0x00 } + , { 0x0049,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0073,0x0075,0x0072,0x0072,0x006F,0x0067,0x0061,0x0074,0x0065,0x0020,0x0063,0x0068,0x0061,0x0072,0x0061,0x0063,0x0074,0x0065,0x0072,0x0020,0x0066,0x006F,0x0075,0x006E,0x0064,0x0020,0x0069,0x006E,0x0020,0x0055,0x0054,0x0046,0x002D,0x0038,0x0020,0x0064,0x0061,0x0074,0x0061,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0072,0x0069,0x006D,0x0061,0x0072,0x0079,0x0020,0x0064,0x006F,0x0063,0x0075,0x006D,0x0065,0x006E,0x0074,0x0020,0x0065,0x006E,0x0074,0x0069,0x0074,0x0079,0x0020,0x0063,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x006F,0x0070,0x0065,0x006E,0x0065,0x0064,0x002E,0x0020,0x0049,0x0064,0x003D,0x007B,0x0030,0x007D,0x00 } + , { 0x0055,0x006E,0x0062,0x0061,0x006C,0x0061,0x006E,0x0063,0x0065,0x0064,0x0020,0x0073,0x0074,0x0061,0x0072,0x0074,0x002F,0x0065,0x006E,0x0064,0x0020,0x0074,0x0061,0x0067,0x0073,0x0020,0x0066,0x006F,0x0075,0x006E,0x0064,0x002C,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0063,0x006F,0x006E,0x0074,0x0069,0x006E,0x0075,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0061,0x0073,0x0073,0x0065,0x0064,0x0020,0x0041,0x0074,0x0074,0x0054,0x0079,0x0070,0x0065,0x0073,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006B,0x006E,0x006F,0x0077,0x006E,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0061,0x0073,0x0073,0x0065,0x0064,0x0020,0x0044,0x0065,0x0066,0x0041,0x0074,0x0074,0x0054,0x0079,0x0070,0x0065,0x0073,0x0020,0x0076,0x0061,0x006C,0x0075,0x0065,0x0020,0x0069,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006B,0x006E,0x006F,0x0077,0x006E,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0062,0x0075,0x0066,0x0066,0x0065,0x0072,0x0020,0x006D,0x0061,0x006E,0x0061,0x0067,0x0065,0x0072,0x0020,0x0063,0x0061,0x006E,0x006E,0x006F,0x0074,0x0020,0x0070,0x0072,0x006F,0x0076,0x0069,0x0064,0x0065,0x0020,0x0061,0x006E,0x0079,0x0020,0x006D,0x006F,0x0072,0x0065,0x0020,0x0062,0x0075,0x0066,0x0066,0x0065,0x0072,0x0073,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0061,0x0073,0x0073,0x0065,0x0064,0x0020,0x0062,0x0075,0x0066,0x0066,0x0065,0x0072,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x0066,0x006F,0x0075,0x006E,0x0064,0x0020,0x0069,0x006E,0x0020,0x0074,0x0068,0x0069,0x0073,0x0020,0x006D,0x0061,0x006E,0x0061,0x0067,0x0065,0x0072,0x0027,0x0073,0x0020,0x0070,0x006F,0x006F,0x006C,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0070,0x0061,0x0073,0x0073,0x0065,0x0064,0x0020,0x0072,0x0065,0x0063,0x006F,0x0067,0x006E,0x0069,0x007A,0x0065,0x0072,0x0020,0x0065,0x006E,0x0063,0x006F,0x0064,0x0069,0x006E,0x0067,0x0020,0x0077,0x0061,0x0073,0x0020,0x006E,0x006F,0x0074,0x0020,0x006B,0x006E,0x006F,0x0077,0x006E,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0062,0x006C,0x006F,0x0063,0x006B,0x0020,0x006F,0x0066,0x0020,0x0058,0x004D,0x004C,0x0020,0x0064,0x0061,0x0074,0x0061,0x0020,0x0063,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0062,0x0065,0x0020,0x0074,0x0072,0x0061,0x006E,0x0073,0x0063,0x006F,0x0064,0x0065,0x0064,0x00 } + , { 0x0043,0x006F,0x0075,0x006C,0x0064,0x0020,0x006E,0x006F,0x0074,0x0020,0x0063,0x0072,0x0065,0x0061,0x0074,0x0065,0x0020,0x0061,0x0020,0x0064,0x0065,0x0066,0x0061,0x0075,0x006C,0x0074,0x0020,0x0074,0x0072,0x0061,0x006E,0x0073,0x0063,0x006F,0x0064,0x0065,0x0072,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0062,0x0069,0x006E,0x0061,0x0072,0x0079,0x0020,0x006F,0x0070,0x0065,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x006E,0x006F,0x0064,0x0065,0x0020,0x0068,0x0061,0x0064,0x0020,0x0061,0x0020,0x0075,0x006E,0x0061,0x0072,0x0079,0x0020,0x006E,0x006F,0x0064,0x0065,0x0020,0x0074,0x0079,0x0070,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x0074,0x0079,0x0070,0x0065,0x0020,0x006D,0x0075,0x0073,0x0074,0x0020,0x0062,0x0065,0x0020,0x006D,0x0069,0x0078,0x0065,0x0064,0x0020,0x006F,0x0072,0x0020,0x0063,0x0068,0x0069,0x006C,0x0064,0x0072,0x0065,0x006E,0x00 } + , { 0x0050,0x0043,0x0044,0x0041,0x0054,0x0041,0x0020,0x006E,0x006F,0x0064,0x0065,0x0073,0x0020,0x0061,0x0072,0x0065,0x0020,0x006E,0x006F,0x0074,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0068,0x0065,0x0072,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x007B,0x0030,0x007D,0x0020,0x006F,0x0070,0x0065,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x0069,0x0073,0x0020,0x0069,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x0020,0x0066,0x006F,0x0072,0x0020,0x0074,0x0068,0x0065,0x0020,0x0073,0x0070,0x0065,0x0063,0x0020,0x0074,0x0079,0x0070,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0075,0x006E,0x0061,0x0072,0x0079,0x0020,0x006F,0x0070,0x0065,0x0072,0x0061,0x0074,0x0069,0x006F,0x006E,0x0020,0x006E,0x006F,0x0064,0x0065,0x0020,0x0068,0x0061,0x0064,0x0020,0x0061,0x0020,0x0062,0x0069,0x006E,0x0061,0x0072,0x0079,0x0020,0x006E,0x006F,0x0064,0x0065,0x0020,0x0074,0x0079,0x0070,0x0065,0x00 } + , { 0x0055,0x006E,0x006B,0x006E,0x006F,0x0077,0x006E,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x006D,0x006F,0x0064,0x0065,0x006C,0x0020,0x0074,0x0079,0x0070,0x0065,0x00 } + , { 0x0055,0x006E,0x006B,0x006E,0x006F,0x0077,0x006E,0x0020,0x0063,0x006F,0x006E,0x0074,0x0065,0x006E,0x0074,0x0020,0x0073,0x0070,0x0065,0x0063,0x0020,0x0074,0x0079,0x0070,0x0065,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0065,0x006C,0x0065,0x006D,0x0065,0x006E,0x0074,0x0020,0x0069,0x0064,0x0020,0x0077,0x0061,0x0073,0x0020,0x0069,0x006E,0x0076,0x0061,0x006C,0x0069,0x0064,0x00 } + , { 0x0057,0x0068,0x0065,0x006E,0x0020,0x0072,0x0065,0x0075,0x0073,0x0069,0x006E,0x0067,0x0020,0x0074,0x0068,0x0065,0x0020,0x0076,0x0061,0x006C,0x0069,0x0064,0x0061,0x0074,0x006F,0x0072,0x002C,0x0020,0x006E,0x006F,0x0020,0x0069,0x006E,0x0074,0x0065,0x0072,0x006E,0x0061,0x006C,0x0020,0x0073,0x0075,0x0062,0x0073,0x0065,0x0074,0x0020,0x0069,0x0073,0x0020,0x0061,0x006C,0x006C,0x006F,0x0077,0x0065,0x0064,0x00 } + , { 0x0054,0x0068,0x0065,0x0020,0x0063,0x0061,0x006C,0x006C,0x0020,0x0074,0x006F,0x0020,0x0073,0x0063,0x0061,0x006E,0x004E,0x0065,0x0078,0x0074,0x0028,0x0029,0x0020,0x0069,0x0073,0x0020,0x0069,0x006C,0x006C,0x0065,0x0067,0x0061,0x006C,0x0020,0x0061,0x0074,0x0020,0x0074,0x0068,0x0069,0x0073,0x0020,0x0074,0x0069,0x006D,0x0065,0x00 } + , { 0x0045,0x005F,0x0045,0x006E,0x0064,0x00 } + +}; +const unsigned int gXMLExceptArraySize = 90; + diff --git a/src/util/MsgLoaders/InMemory/InMemMsgLoader.cpp b/src/util/MsgLoaders/InMemory/InMemMsgLoader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ea8e7b17884f3791493c49afce2eba1b606740e --- /dev/null +++ b/src/util/MsgLoaders/InMemory/InMemMsgLoader.cpp @@ -0,0 +1,225 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:19 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:26 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/BitOps.hpp> +#include <util/PlatformUtils.hpp> +#include <util/XMLMsgLoader.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> +#include "InMemMsgLoader.hpp" +#include "CppErrMsgs_EN_US.hpp" + + + +// --------------------------------------------------------------------------- +// Public Constructors and Destructor +// --------------------------------------------------------------------------- +InMemMsgLoader::InMemMsgLoader(const XMLCh* const msgDomain) : + + fMsgDomain(0) +{ + fMsgDomain = XMLString::replicate(msgDomain); + + if (XMLString::compareString(fMsgDomain, XMLUni::fgXMLErrDomain) + && XMLString::compareString(fMsgDomain, XMLUni::fgExceptDomain) + && XMLString::compareString(fMsgDomain, XMLUni::fgValidityDomain)) + { + XMLPlatformUtils::panic(XMLPlatformUtils::Panic_UnknownMsgDomain); + } +} + +InMemMsgLoader::~InMemMsgLoader() +{ + delete [] fMsgDomain; +} + + +// --------------------------------------------------------------------------- +// Implementation of the virtual message loader API +// --------------------------------------------------------------------------- +bool InMemMsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars) +{ + // + // Just use the id to map into the correct array of messages. Then + // copy that to the caller's buffer. + // + // NOTE: The source text is in little endian form. So, if we are a + // big endian machine, flip them in the process. + // + XMLCh* endPtr = toFill + maxChars; + XMLCh* outPtr = toFill; + if (!XMLString::compareString(fMsgDomain, XMLUni::fgXMLErrDomain)) + { + const XMLCh* srcPtr = gXMLErrArray[msgToLoad - 1]; + while (*srcPtr && (outPtr < endPtr)) + { + #if defined(ENDIANMODE_LITTLE) + *outPtr++ = *srcPtr++; + #else + *outPtr++ = BitOps::swapBytes(*srcPtr++); + #endif + } + *outPtr = 0; + } + else if (!XMLString::compareString(fMsgDomain, XMLUni::fgExceptDomain)) + { + const XMLCh* srcPtr = gXMLExceptArray[msgToLoad - 1]; + while (*srcPtr && (outPtr < endPtr)) + { + #if defined(ENDIANMODE_LITTLE) + *outPtr++ = *srcPtr++; + #else + *outPtr++ = BitOps::swapBytes(*srcPtr++); + #endif + } + *outPtr = 0; + } + else if (!XMLString::compareString(fMsgDomain, XMLUni::fgValidityDomain)) + { + const XMLCh* srcPtr = gXMLValidityArray[msgToLoad - 1]; + while (*srcPtr && (outPtr < endPtr)) + { + #if defined(ENDIANMODE_LITTLE) + *outPtr++ = *srcPtr++; + #else + *outPtr++ = BitOps::swapBytes(*srcPtr++); + #endif + } + *outPtr = 0; + } + else + { + return false; + } + return true; +} + + +bool InMemMsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 + , const XMLCh* const repText3 + , const XMLCh* const repText4) +{ + // Call the other version to load up the message + if (!loadMsg(msgToLoad, toFill, maxChars)) + return false; + + // And do the token replacement + XMLString::replaceTokens(toFill, maxChars, repText1, repText2, repText3, repText4); + return true; +} + + +bool InMemMsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 + , const char* const repText3 + , const char* const repText4) +{ + // + // Transcode the provided parameters and call the other version, + // which will do the replacement work. + // + XMLCh* tmp1 = 0; + XMLCh* tmp2 = 0; + XMLCh* tmp3 = 0; + XMLCh* tmp4 = 0; + + bool bRet = false; + if (repText1) + tmp1 = XMLString::transcode(repText1); + if (repText2) + tmp2 = XMLString::transcode(repText2); + if (repText3) + tmp3 = XMLString::transcode(repText3); + if (repText4) + tmp4 = XMLString::transcode(repText4); + + bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4); + + if (tmp1) + delete [] tmp1; + if (tmp2) + delete [] tmp2; + if (tmp3) + delete [] tmp3; + if (tmp4) + delete [] tmp4; + + return bRet; +} diff --git a/src/util/MsgLoaders/InMemory/InMemMsgLoader.hpp b/src/util/MsgLoaders/InMemory/InMemMsgLoader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..702e29a74281d49c69a1542af5860d2cf4a4b4fc --- /dev/null +++ b/src/util/MsgLoaders/InMemory/InMemMsgLoader.hpp @@ -0,0 +1,141 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:20 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:27 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(INMEMMSGLOADER_HPP) +#define INMEMMSGLOADER_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLMsgLoader.hpp> + +// +// This is a simple in memory message loader implementation. For those +// folks who just want a single language and want something very fast and +// efficient, can basically just provide a couple of arrays of Unicode +// strings that can be looked up by the message id. +// +class XMLUTIL_EXPORT InMemMsgLoader : public XMLMsgLoader +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + InMemMsgLoader(const XMLCh* const msgDomain); + ~InMemMsgLoader(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual message loader API + // ----------------------------------------------------------------------- + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 = 0 + , const XMLCh* const repText3 = 0 + , const XMLCh* const repText4 = 0 + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 = 0 + , const char* const repText3 = 0 + , const char* const repText4 = 0 + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + InMemMsgLoader(); + InMemMsgLoader(const InMemMsgLoader&); + void operator=(const InMemMsgLoader&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fMsgDomain + // This is the message domain that we are for loading message from. + // ----------------------------------------------------------------------- + XMLCh* fMsgDomain; +}; + +#endif diff --git a/src/util/MsgLoaders/InMemory/Makefile.in b/src/util/MsgLoaders/InMemory/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..e74f099c452613cd60f33b7d18e4cb6b546a71d5 --- /dev/null +++ b/src/util/MsgLoaders/InMemory/Makefile.in @@ -0,0 +1,90 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:07:20 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:27 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util +SUBMODULE = MsgLoaders/InMemory + +include ../../../Makefile.incl + +CPP_PUBHEADERS = \ + CppErrMsgs_EN_US.hpp \ + InMemMsgLoader.hpp + +CPP_OBJECTS = InMemMsgLoader.o + +include ../../Makefile.util.submodule + diff --git a/src/util/MsgLoaders/MsgCatalog/Makefile.in b/src/util/MsgLoaders/MsgCatalog/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..74aabbeb2e30ad5ffda223172415ffab00a73588 --- /dev/null +++ b/src/util/MsgLoaders/MsgCatalog/Makefile.in @@ -0,0 +1,88 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:07:16 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:27 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util +SUBMODULE = MsgLoaders/MsgCatalog + +include ../../../Makefile.incl + +CPP_PUBHEADERS = \ + MsgCatalogLoader.hpp + +CPP_OBJECTS = MsgCatalogLoader.o + +include ../../Makefile.util.submodule diff --git a/src/util/MsgLoaders/MsgCatalog/MsgCatalogLoader.cpp b/src/util/MsgLoaders/MsgCatalog/MsgCatalogLoader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6a152eae10db860a561fba7145687e38fe883ed --- /dev/null +++ b/src/util/MsgLoaders/MsgCatalog/MsgCatalogLoader.cpp @@ -0,0 +1,191 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:16 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:27 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/PlatformUtils.hpp> +#include <util/XMLMsgLoader.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> +#include "MsgCatalogLoader.hpp" + +#include <locale.h> +#include <stdlib.h> +#include <stdio.h> + +// --------------------------------------------------------------------------- +// Public Constructors and Destructor +// --------------------------------------------------------------------------- +MsgCatalogLoader::MsgCatalogLoader(const XMLCh* const msgDomain) : + + fCatalogHandle(0) + , fMsgDomain(0) +{ + // Try to get the module handle + char* tempLoc = setlocale(LC_ALL, ""); + fCatalogHandle = catopen("XMLMessages.cat" , 0); + if ((int)fCatalogHandle == -1) + { + // Probably have to call panic here + printf("Could not open catalog XMLMessages\n"); + // TBD: Tell user what the locale is + exit(1); + } + + fMsgDomain = XMLString::replicate(msgDomain); +} + +MsgCatalogLoader::~MsgCatalogLoader() +{ + if (fCatalogHandle) + catclose( fCatalogHandle ); + delete fMsgDomain; +} + + +// --------------------------------------------------------------------------- +// Implementation of the virtual message loader API +// --------------------------------------------------------------------------- +bool MsgCatalogLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars) +{ + int msgSet = 1; + if (!XMLString::compareString(fMsgDomain, XMLUni::fgXMLErrDomain)) + msgSet = 1; + else if (!XMLString::compareString(fMsgDomain, XMLUni::fgExceptDomain)) + msgSet = 2; + + char msgString[100]; + sprintf(msgString, "Could not find message ID %d from message set %d\n", msgToLoad, msgSet); + char* catMessage = catgets( fCatalogHandle, msgSet, (int)msgToLoad, msgString); + XMLString::copyString((XMLCh*)toFill, XMLString::transcode(catMessage)); + + return true; +} + + +bool MsgCatalogLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 + , const XMLCh* const repText3 + , const XMLCh* const repText4) +{ + // Call the other version to load up the message + if (!loadMsg(msgToLoad, toFill, maxChars)) + return false; + + // And do the token replacement + XMLString::replaceTokens(toFill, maxChars, repText1, repText2, repText3, repText4); + return true; +} + + +bool MsgCatalogLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 + , const char* const repText3 + , const char* const repText4) +{ + // + // Transcode the provided parameters and call the other version, + // which will do the replacement work. + // + XMLCh* tmp1 = 0; + XMLCh* tmp2 = 0; + XMLCh* tmp3 = 0; + XMLCh* tmp4 = 0; + + bool bRet = false; + if (repText1) + tmp1 = XMLString::transcode(repText1); + if (repText2) + tmp2 = XMLString::transcode(repText2); + if (repText3) + tmp3 = XMLString::transcode(repText3); + if (repText4) + tmp4 = XMLString::transcode(repText4); + + bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4); + + if (tmp1) + delete [] tmp1; + if (tmp2) + delete [] tmp2; + if (tmp3) + delete [] tmp3; + if (tmp4) + delete [] tmp4; + + return bRet; +} diff --git a/src/util/MsgLoaders/MsgCatalog/MsgCatalogLoader.hpp b/src/util/MsgLoaders/MsgCatalog/MsgCatalogLoader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..10a566868a927f0c0a1a5f55f2fddaa742fe2f5f --- /dev/null +++ b/src/util/MsgLoaders/MsgCatalog/MsgCatalogLoader.hpp @@ -0,0 +1,145 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:17 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(ICONVMSGLOADER_HPP) +#define ICONVMSGLOADER_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLMsgLoader.hpp> + +#include <nl_types.h> + +// +// This is a simple in Iconv RC message loader implementation. +// +class XMLUTIL_EXPORT MsgCatalogLoader : public XMLMsgLoader +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + MsgCatalogLoader(const XMLCh* const msgDomain); + ~MsgCatalogLoader(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual message loader API + // ----------------------------------------------------------------------- + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 = 0 + , const XMLCh* const repText3 = 0 + , const XMLCh* const repText4 = 0 + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 = 0 + , const char* const repText3 = 0 + , const char* const repText4 = 0 + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + MsgCatalogLoader(); + MsgCatalogLoader(const MsgCatalogLoader&); + void operator=(const MsgCatalogLoader&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fModHandle + // This is our DLL module handle that we need in order to load + // resource messages. This is set during construction. + // + // fMsgDomain + // This is the name of the error domain that this loader is for. + // ----------------------------------------------------------------------- + nl_catd fCatalogHandle; + XMLCh* fMsgDomain; + +}; + +#endif diff --git a/src/util/MsgLoaders/MsgCatalog/XMLMsgCat_EN_US.Msg b/src/util/MsgLoaders/MsgCatalog/XMLMsgCat_EN_US.Msg new file mode 100644 index 0000000000000000000000000000000000000000..db0689ab329a3477715d72973a02cfc28137904a --- /dev/null +++ b/src/util/MsgLoaders/MsgCatalog/XMLMsgCat_EN_US.Msg @@ -0,0 +1,244 @@ +$quote " +$set 1 + 2 Notation '{0}' has already been declared + 3 Attribute '{0}' has already been declared + 4 Encoding ({0}, from XMLDecl or manually set) contradicts the auto-sensed encoding, ignoring it + 5 Element '{0}' was referenced in a content model but never declared + 6 Element '{0}' was referenced in an attlist but never declared + 9 Expected comment or CDATA + 10 Expected an attribute name + 11 Expected a notation name + 12 Repetition of individual elements is not legal for mixed content models + 13 Bad default attribute declaration + 14 Expected default attribute declaration, assuming #IMPLIED + 15 Attribute list syntax error + 16 Expected equal sign + 17 Duplication attribute name + 18 Bad ID for xml:lang attribute + 19 Expected an element name + 20 Must start with an XMLDecl + 21 Comments must start with <!-- + 22 Invalid document structure + 23 Expected a 'version=', 'encoding=', or 'standalone=' + 24 Bad XML version string + 25 Unsupported XML version + 26 Unterminated XML decl + 27 Bad XML encoding declaration + 28 Bad standalone declaration + 29 Unterminated comment + 30 Processing instruction name expected + 31 Unterminated processing instruction + 32 Invalid character + 33 Unexpected text before root element + 34 Unterminated start tag + 35 Expected an attribute value + 36 Unterminated end tag + 37 Expected attribute type (CDATA, ID, NMTOKEN, ..), + 38 Expected end of tag '{0}' + 39 Expected tag name, comment, PI, or other markup + 40 Not valid after content + 41 Expected comment + 42 Expected comment or processing instruction + 43 Expected whitespace + 44 No root element in DOCTYPE + 45 Expected quoted string + 46 Expected public id + 47 Invalid character in public id + 48 Unterminated DOCTYPE declaration + 49 Invalid character in internal subset + 50 Expected CDATA section + 51 Invalid initial name character + 52 Invalid name character + 53 Unexpected whitespace + 54 Invalid character in attribute value + 55 Expected a markup declaration + 56 Text declaration not legal here + 57 Conditional section in internal subset + 58 Expected parameter entity name + 59 Unterminated entity declaration + 60 Invalid character reference + 61 Unterminated character reference + 62 Expected entity name for reference + 63 Entity '{0}' was not found + 64 Unparsed entitty references not valid here + 65 Unterminated entity reference + 66 Recursive entity expansion + 67 Partial markup in entity value + 68 Unterminated element declaration + 69 Expected content specification expression + 70 Expected asterisk + 71 Unterminated Content model + 72 Expected system id + 73 Expected system or public id + 74 Unterminated notation declaration + 75 Expected ',', '|', or ')' characters + 76 Expected '|' or ')' characters + 77 Expected ',' or ')' characters or close parenthesis + 78 Expected enumeration value + 79 Expected | enumeration separator, or closing paren + 80 Unterminated entity literal + 81 There are more end tags than start tags + 82 Reference to external declaration in standalone document. Entity={0} + 83 Expected an open parenthesis + 84 The attribute '{0}' is already used in element '{1}' + 85 A '<' character cannot be used in an attribute value, except through < + 86 A leading surrogate character was not followed by a legal second character + 87 Expected ']]>' to end a conditional section + 88 Expected INCLUDE or IGNORE here + 89 Expected [ to follow INCLUDE or IGNORE + 90 Expected a TextDecl here: <?xml .... + 91 Expected a XMLDecl here: <?xml .... + 92 Unexpected end of entity {0} + 93 A PE propogated out of the int/ext subset, discarding extra text + 94 An extra ] character was found an ignored + 95 PE refs are not allowed inside markup in the internal subset + 96 An entity propogated out of the content section into Miscellaneous + 97 Expected &# to be followed by a numeric character value + 98 Expected an open bracket ('[') here + 99 The sequence ']]>' is not allowed in character data +100 Illegal sequence '--' in comment +101 Unterminated CDATA section +102 Expected NDATA +103 NDATA is not legal for parameter entities +104 Hex radix character refs must use 'x', not 'X' +105 '{0}' has already been set. Ignoring redundant setting +106 The XMLDecl strings must be in the order: version, encoding, standalone +107 External entities cannot be referred to from attribute values +108 The XML or Text decl must start with '<?xml ', not '<?XML ' +109 Expected a literal entity value or PUBLIC/SYSTEM id +110 '{0}' is not a valid digit for the indicated radix +111 The input ended before all started tags were ended. Last tag started was '{0}' +112 The content model for element '{0}' is ambiguous +113 Nested CDATA sections are not allowed +114 The prefix '{0}' has not been mapped to any URI +115 The start and the end tag were in the different entities +116 The main XML document cannot be empty +117 CDATA is not allowed outside the root element +118 Only numeric character entities or special character entities are legal here +119 Got an unexpected trailing surrogate character +120 No processing instruction starts with 'xml' +121 The XML or Text declaration must start at line/column 1/1 +122 The 'version=' string is required in an XMLDecl +123 The 'standalone=' string is only allowed in the main XML entity +124 When namespaces are enabled, a name can have only one colon character +125 When namespaces are enabled, the colon cannot be the first or last character +126 Colons are not allowed in this name when namespaces are enabled +127 A system exception occured during processing +128 An exception occured! Type:{0}, Message:{1} +129 Unexpected end of file exception. Message: {0} + + +$set 3 + 2 Unknown element '{0}' + 3 Attribute '{0}' not defined + 4 Notation '{0}' was referenced but never declared + 5 Root element different from DOCTYPE + 6 Required attribute '{0}' was not provided + 7 Element '{0}' is not valid for content model: '{1}' + 8 ID attributes must be #IMPLIED or #REQUIRED + 9 This type of attribute cannot have an empty value + 10 Element '{0}' has already been declared + 11 Element '{0}' has more than one ID attribute + 12 ID '{0}' has already been used + 13 ID attribute '{0}' was referenced but never declared + 14 Attribute '{0}' refers to an unknown notation '{1}' + 15 Element '{0}' was used in the DOCTYPE but never declared + 16 Empty content not valid for content model: '{0}' + 17 Attribute '{{0}}{1}' is not declared for element '{2}' + 18 Attributes of type ENTITY/ENTITIES must refer to an external, unparsed entity + 19 Attribute '{0}' refers to an unknown entity '{1}' + 20 Not enough elements to match content model : '{0}' + 21 No character data is allowed by content model + 22 Attribute '{0}' does not match its defined enumeration or notation list + 23 The values for attribute '{0}' must be names or name tokens + 24 Attribute '{0}' does not support multiple values + 25 Attribute '{0}' has a value that does not match its #FIXED value + 26 Element types cannot be duplicated in Mixed content models + + +$set 2 + 2 The index is beyond the array bounds + 3 The new size is less than the old one + 4 The bit index was beyond the set size + 5 The pointer has not been set + 6 The enumerator contains no more elements + 7 Could not open file: {0} + 8 Could not query the current file position + 9 Could not close the file + 10 Could not seek to end of file + 11 Could not seek to required position in file + 12 Could not duplicate the handle + 13 Could not read data from file + 14 Could not reset file to beginning + 15 Could not acertain the file size + 16 Could not determine base pathname of the file + 17 The hash modulus cannot be zero + 18 Hashing the key returned an invalid bad hash value + 19 The key '{0}' could not be found in the hash table + 20 Could not create mutex + 21 Could not close mutex + 22 Could not lock mutex + 23 Could not unlock mutex + 24 Could not destroy mutex + 25 The element {0} already exists + 26 Hashing the key returned an invalid bad hash value + 27 The passed id is not valid for this pool + 28 The modulus value cannot be zero + 29 The index is past the top of stack + 30 The stack is empty, cannot access members + 31 The target buffer cannot have a max size of zero + 32 The given radix is not supported. Use 2, 8, 10, or 16 + 33 The target buffer is too small to accept the results + 34 The start index is past the end of the string + 35 Could not write to standard err + 36 Could not write to standard out + 37 Could not write to console + 38 String pool id was not legal + 39 The URL was not correctly formed + 40 The URL used an unsupported protocol + 41 Unsupported URL protocol: '{0}' + 42 Only localhost is supported at this time + 43 No protocol prefix present + 44 Expected // after protocol + 45 % must be followed by two hex digits + 46 Unterminated host component + 47 The passed index is past the end of the vector + 48 Parse may not be called while parsing + 49 A DOCTYPE was seen but the installed validator does not understand DTDs + 50 Could not open DTD file '{0}' + 51 Could not open external entity '{0}' + 52 The end of input was not expected + 53 The index given was beyond the max attribute index + 54 The element stack is empty + 55 The element stack index given was beyond the stack top + 56 The element stack was already empty when a pop request occured + 57 A parent operation was requested, but only one element is on the stack + 58 The indicated reader id was never found + 59 The auto encoding enum has an unknown value + 60 Could not create a converter for encoding: {0} + 61 Could not decode first line of entity: {0} + 62 End of input was hit in the middle of a multibyte sequence + 63 This encoding ({0})should have had a transcoder + 64 Invalid second byte of a UTF-8 character sequence + 65 Invalid surrogate character found in UTF-8 data + 66 The primary document entity could not be opened. Id={0} + 67 Unbalanced start/end tags found, cannot continue + 68 The passed AttTypes value is not known + 69 The passed DefAttTypes value is not known + 70 The buffer manager cannot provide any more buffers + 71 The passed buffer was not found in this manager's pool + 72 The passed recognizer encoding was not known + 73 The block of XML data could not be transcoded + 74 Could not create a default transcoder + 75 The binary operation node had a unary node type + 76 The content type must be mixed or children + 77 PCDATA nodes are not valid here + 78 The {0} operation is invalid for the spec type + 79 The unary operation node had a binary node type + 80 Unknown content model type + 81 Unknown content spec type + 82 The element id was invalid + 83 When reusing the validator, no internal subset is allowed + 84 The call to scanNext() is illegal at this time + + diff --git a/src/util/MsgLoaders/Win32/Win32MsgLoader.cpp b/src/util/MsgLoaders/Win32/Win32MsgLoader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a82e9033be555aa75f7744bab928064ce714cc50 --- /dev/null +++ b/src/util/MsgLoaders/Win32/Win32MsgLoader.cpp @@ -0,0 +1,201 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:15 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/PlatformUtils.hpp> +#include <util/XMLMsgLoader.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> +#include <windows.h> +#include "Win32MsgLoader.hpp" + + + +// --------------------------------------------------------------------------- +// Public Constructors and Destructor +// --------------------------------------------------------------------------- +Win32MsgLoader::Win32MsgLoader(const XMLCh* const msgDomain) : + + fDomainOfs(0) + , fModHandle(0) + , fMsgDomain(0) +{ + // Try to get the module handle + fModHandle = ::GetModuleHandleA(XML4C_DLLName); + if (!fModHandle) + { + // + // If we didn't find it, its probably because its a development + // build which is built as separate DLLs, so lets look for the DLL + // that we are part of. + // + static const char* const privDLLName = "IXUTIL"; + fModHandle = ::GetModuleHandle(privDLLName); + + // If neither exists, then we give up + if (!fModHandle) + { + // Probably have to call panic here + } + } + + // Store the domain name + fMsgDomain = XMLString::replicate(msgDomain); + + // And precalc the id offset we use for this domain + if (!XMLString::compareString(fMsgDomain, XMLUni::fgXMLErrDomain)) + fDomainOfs = 0; + else if (!XMLString::compareString(fMsgDomain, XMLUni::fgExceptDomain)) + fDomainOfs = 0x2000; + else if (!XMLString::compareString(fMsgDomain, XMLUni::fgValidityDomain)) + fDomainOfs = 0x4000; + else + XMLPlatformUtils::panic(XMLPlatformUtils::Panic_UnknownMsgDomain); +} + +Win32MsgLoader::~Win32MsgLoader() +{ + delete [] fMsgDomain; +} + + +// --------------------------------------------------------------------------- +// Implementation of the virtual message loader API +// --------------------------------------------------------------------------- +bool Win32MsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars) +{ + // Load the id, adjusting it by the domain offset + if (!::LoadStringW(fModHandle, msgToLoad + fDomainOfs, toFill, maxChars)) + return false; + + return true; +} + + +bool Win32MsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 + , const XMLCh* const repText3 + , const XMLCh* const repText4) +{ + // Call the other version to load up the message + if (!loadMsg(msgToLoad, toFill, maxChars)) + return false; + + // And do the token replacement + XMLString::replaceTokens(toFill, maxChars, repText1, repText2, repText3, repText4); + return true; +} + + +bool Win32MsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 + , const char* const repText3 + , const char* const repText4) +{ + // + // Transcode the provided parameters and call the other version, + // which will do the replacement work. + // + XMLCh* tmp1 = 0; + XMLCh* tmp2 = 0; + XMLCh* tmp3 = 0; + XMLCh* tmp4 = 0; + + bool bRet = false; + if (repText1) + tmp1 = XMLString::transcode(repText1); + if (repText2) + tmp2 = XMLString::transcode(repText2); + if (repText3) + tmp3 = XMLString::transcode(repText3); + if (repText4) + tmp4 = XMLString::transcode(repText4); + + bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4); + + if (tmp1) + delete [] tmp1; + if (tmp2) + delete [] tmp2; + if (tmp3) + delete [] tmp3; + if (tmp4) + delete [] tmp4; + + return bRet; +} diff --git a/src/util/MsgLoaders/Win32/Win32MsgLoader.hpp b/src/util/MsgLoaders/Win32/Win32MsgLoader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..53aaf0b2645306bcd05add409b6b44b9e8cf168b --- /dev/null +++ b/src/util/MsgLoaders/Win32/Win32MsgLoader.hpp @@ -0,0 +1,151 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:15 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(WIN32MSGLOADER_HPP) +#define WIN32MSGLOADER_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLMsgLoader.hpp> + +// +// This is a simple in Win32 RC message loader implementation. +// +class XMLUTIL_EXPORT Win32MsgLoader : public XMLMsgLoader +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + Win32MsgLoader(const XMLCh* const msgDomain); + ~Win32MsgLoader(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual message loader API + // ----------------------------------------------------------------------- + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 = 0 + , const XMLCh* const repText3 = 0 + , const XMLCh* const repText4 = 0 + ); + + virtual bool loadMsg + ( + const XMLMsgLoader::XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 = 0 + , const char* const repText3 = 0 + , const char* const repText4 = 0 + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + Win32MsgLoader(); + Win32MsgLoader(const Win32MsgLoader&); + void operator=(const Win32MsgLoader&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fDomainOfs + // This is the id offset for the current domain. Its used to bias + // the zero based id of each domain, since they are stored in the + // same file and have to have unique ids internally. This is set + // in the ctor from the domain name. We just have to agree with + // what our formatter in the NLSXlat program does. + // + // fModHandle + // This is our DLL module handle that we need in order to load + // resource messages. This is set during construction. + // + // fMsgDomain + // This is the name of the error domain that this loader is for. + // ----------------------------------------------------------------------- + unsigned int fDomainOfs; + HINSTANCE fModHandle; + XMLCh* fMsgDomain; +}; + +#endif diff --git a/src/util/Mutexes.cpp b/src/util/Mutexes.cpp new file mode 100644 index 0000000000000000000000000000000000000000..55d9732c587a85150304b9001225ac9bbaaa27f4 --- /dev/null +++ b/src/util/Mutexes.cpp @@ -0,0 +1,133 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:45 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:09 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/PlatformUtils.hpp> +#include <util/Mutexes.hpp> + + + +// --------------------------------------------------------------------------- +// XMLMutex: Constructors and Destructor +// --------------------------------------------------------------------------- +XMLMutex::XMLMutex() : + + fHandle(0) +{ +} + + +XMLMutex::~XMLMutex() +{ + if (fHandle) + { + XMLPlatformUtils::closeMutex(fHandle); + fHandle = 0; + } +} + + +// --------------------------------------------------------------------------- +// XMLMutex: Lock control methods +// --------------------------------------------------------------------------- +void XMLMutex::lock() +{ + if (!fHandle) + { + void* tmpHandle = XMLPlatformUtils::makeMutex(); + if (XMLPlatformUtils::compareAndSwap(&fHandle, tmpHandle, 0) != 0) + XMLPlatformUtils::closeMutex(tmpHandle); + } + XMLPlatformUtils::lockMutex(fHandle); +} + +void XMLMutex::unlock() +{ + XMLPlatformUtils::unlockMutex(fHandle); +} + + + +// --------------------------------------------------------------------------- +// XMLMutexLock: Constructors and Destructor +// --------------------------------------------------------------------------- +XMLMutexLock::XMLMutexLock(XMLMutex* const toLock) : + + fToLock(toLock) +{ + fToLock->lock(); +} + + +XMLMutexLock::~XMLMutexLock() +{ + fToLock->unlock(); +} diff --git a/src/util/Mutexes.hpp b/src/util/Mutexes.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d6205863929b9f19ece9865134497c549ef34145 --- /dev/null +++ b/src/util/Mutexes.hpp @@ -0,0 +1,146 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:46 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:10 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(MUTEXES_HPP) +#define MUTEXES_HPP + +#include <util/XML4CDefs.hpp> + +class XMLUTIL_EXPORT XMLMutex +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + XMLMutex(); + + ~XMLMutex(); + + + // ----------------------------------------------------------------------- + // Lock control methods + // ----------------------------------------------------------------------- + void lock(); + void unlock(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XMLMutex(const XMLMutex&); + void operator=(const XMLMutex&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fHandle + // The raw mutex handle. Its just a void pointer so we do not + // pass judgement on its value at all. We just pass it into the + // platform utilities methods which knows what's really in it. + // ----------------------------------------------------------------------- + void* fHandle; + + + // ----------------------------------------------------------------------- + // Sun PlatformUtils needs acess to fHandle to initialize the + // atomicOpsMutex at startup. + // ----------------------------------------------------------------------- + friend class XMLPlatformUtils; +}; + + +class XMLUTIL_EXPORT XMLMutexLock +{ + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- +public: + XMLMutexLock(XMLMutex* const toLock); + ~XMLMutexLock(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XMLMutexLock(); + XMLMutexLock(const XMLMutexLock&); + void operator=(const XMLMutexLock&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fToLock + // The mutex object that we are locking + // ----------------------------------------------------------------------- + XMLMutex* fToLock; +}; + +#endif diff --git a/src/util/NameIdPool.c b/src/util/NameIdPool.c new file mode 100644 index 0000000000000000000000000000000000000000..32b6ef145b4aefce9bda96dd9dd1b2b768dbd624 --- /dev/null +++ b/src/util/NameIdPool.c @@ -0,0 +1,404 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:47 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:10 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/NameIdPool.hpp> +#endif + +#include <util/IllegalArgumentException.hpp> +#include <util/NoSuchElementException.hpp> +#include <util/RuntimeException.hpp> + + + +// --------------------------------------------------------------------------- +// NameIdPoolBucketElem: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> NameIdPoolBucketElem<TElem>:: +NameIdPoolBucketElem(TElem* const value + , NameIdPoolBucketElem<TElem>* const next) : + fData(value) + , fNext(next) +{ +} + +template <class TElem> NameIdPoolBucketElem<TElem>::~NameIdPoolBucketElem() +{ + // Nothing to do +} + + +// --------------------------------------------------------------------------- +// NameIdPool: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> +NameIdPool<TElem>::NameIdPool( const unsigned int hashModulus + , const unsigned int initSize) : + fBucketList(0) + , fIdPtrs(0) + , fIdPtrsCount(initSize) + , fIdCounter(0) + , fHashModulus(hashModulus) +{ + if (!fHashModulus) + ThrowXML(IllegalArgumentException, XML4CExcepts::Pool_ZeroModulus); + + // Allocate the bucket list and zero them + fBucketList = new NameIdPoolBucketElem<TElem>*[fHashModulus]; + for (unsigned int index = 0; index < fHashModulus; index++) + fBucketList[index] = 0; + + // + // Allocate the initial id pointers array. We don't have to zero them + // out since the fIdCounter value tells us which ones are valid. The + // zeroth element is never used (and represents an invalid pool id.) + // + if (!fIdPtrsCount) + fIdPtrsCount = 256; + fIdPtrs = new TElem*[fIdPtrsCount]; + fIdPtrs[0] = 0; +} + +template <class TElem> NameIdPool<TElem>::~NameIdPool() +{ + // + // Delete the id pointers list. The stuff it points to will be cleaned + // up when we clean the bucket lists. + // + delete [] fIdPtrs; + + // Remove all elements then delete the bucket list + removeAll(); + delete [] fBucketList; +} + + +// --------------------------------------------------------------------------- +// NameIdPool: Element management +// --------------------------------------------------------------------------- +template <class TElem> bool +NameIdPool<TElem>::containsKey(const XMLCh* const key) const +{ + unsigned int hashVal; + const NameIdPoolBucketElem<TElem>* findIt = findBucketElem(key, hashVal); + return (findIt != 0); +} + + +template <class TElem> void NameIdPool<TElem>::removeAll() +{ + // Clean up the buckets first + for (unsigned int buckInd = 0; buckInd < fHashModulus; buckInd++) + { + NameIdPoolBucketElem<TElem>* curElem = fBucketList[buckInd]; + NameIdPoolBucketElem<TElem>* nextElem; + while (curElem) + { + // Save the next element before we hose this one + nextElem = curElem->fNext; + + delete curElem->fData; + delete curElem; + + curElem = nextElem; + } + + // Empty out the bucket + fBucketList[buckInd] = 0; + } + + // Reset the id counter + fIdCounter = 0; +} + + +// --------------------------------------------------------------------------- +// NameIdPool: Getters +// --------------------------------------------------------------------------- +template <class TElem> TElem* +NameIdPool<TElem>::getByKey(const XMLCh* const key) +{ + unsigned int hashVal; + NameIdPoolBucketElem<TElem>* findIt = findBucketElem(key, hashVal); + if (!findIt) + return 0; + return findIt->fData; +} + +template <class TElem> const TElem* +NameIdPool<TElem>::getByKey(const XMLCh* const key) const +{ + unsigned int hashVal; + const NameIdPoolBucketElem<TElem>* findIt = findBucketElem(key, hashVal); + if (!findIt) + return 0; + return findIt->fData; +} + +template <class TElem> TElem* +NameIdPool<TElem>::getById(const unsigned int elemId) +{ + // If its either zero or beyond our current id, its an error + if (!elemId || (elemId > fIdCounter)) + ThrowXML(IllegalArgumentException, XML4CExcepts::Pool_InvalidId); + + return fIdPtrs[elemId]; +} + +template <class TElem> +const TElem* NameIdPool<TElem>::getById(const unsigned int elemId) const +{ + // If its either zero or beyond our current id, its an error + if (!elemId || (elemId > fIdCounter)) + ThrowXML(IllegalArgumentException, XML4CExcepts::Pool_InvalidId); + + return fIdPtrs[elemId]; +} + + + +// --------------------------------------------------------------------------- +// NameIdPool: Setters +// --------------------------------------------------------------------------- +template <class TElem> +unsigned int NameIdPool<TElem>::put(TElem* const elemToAdopt) +{ + // First see if the key exists already. If so, its an error + unsigned int hashVal; + if (findBucketElem(elemToAdopt->getKey(), hashVal)) + { + ThrowXML1 + ( + IllegalArgumentException + , XML4CExcepts::Pool_ElemAlreadyExists + , elemToAdopt->getKey() + ); + } + + // Create a new bucket element and add it to the appropriate list + NameIdPoolBucketElem<TElem>* newBucket = new NameIdPoolBucketElem<TElem> + ( + elemToAdopt + , fBucketList[hashVal] + ); + fBucketList[hashVal] = newBucket; + + // + // Give this new one the next available id and add to the pointer list. + // Expand the list if that is now required. + // + if (fIdCounter + 1 == fIdPtrsCount) + { + // Create a new count 1.5 times larger and allocate a new array + unsigned int newCount = (unsigned int)(fIdPtrsCount * 1.5); + TElem** newArray = new TElem*[newCount]; + + // Copy over the old contents to the new array + memcpy(newArray, fIdPtrs, fIdPtrsCount * sizeof(TElem*)); + + // Ok, toss the old array and store the new data + delete [] fIdPtrs; + fIdPtrs = newArray; + fIdPtrsCount = newCount; + } + const unsigned int retId = ++fIdCounter; + fIdPtrs[retId] = elemToAdopt; + + // Set the id on the passed element + elemToAdopt->setId(retId); + + // Return the id that we gave to this element + return retId; +} + + +// --------------------------------------------------------------------------- +// NameIdPool: Private methods +// --------------------------------------------------------------------------- +template <class TElem> +NameIdPoolBucketElem<TElem>* NameIdPool<TElem>:: +findBucketElem(const XMLCh* const key, unsigned int& hashVal) +{ + // Hash the key + hashVal = XMLString::hash(key, fHashModulus); + + if (hashVal > fHashModulus) + ThrowXML(RuntimeException, XML4CExcepts::Pool_BadHashFromKey); + + // Search that bucket for the key + NameIdPoolBucketElem<TElem>* curElem = fBucketList[hashVal]; + while (curElem) + { + if (!XMLString::compareString(key, curElem->fData->getKey())) + return curElem; + curElem = curElem->fNext; + } + return 0; +} + +template <class TElem> +const NameIdPoolBucketElem<TElem>* NameIdPool<TElem>:: +findBucketElem(const XMLCh* const key, unsigned int& hashVal) const +{ + // Hash the key + hashVal = XMLString::hash(key, fHashModulus); + + if (hashVal > fHashModulus) + ThrowXML(RuntimeException, XML4CExcepts::Pool_BadHashFromKey); + + // Search that bucket for the key + const NameIdPoolBucketElem<TElem>* curElem = fBucketList[hashVal]; + while (curElem) + { + if (!XMLString::compareString(key, curElem->fData->getKey())) + return curElem; + + curElem = curElem->fNext; + } + return 0; +} + + + +// --------------------------------------------------------------------------- +// NameIdPoolEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> NameIdPoolEnumerator<TElem>:: +NameIdPoolEnumerator(NameIdPool<TElem>* const toEnum) : + + fCurIndex(0) + , fToEnum(toEnum) +{ + // + // Find the next available bucket element in the pool. We use the id + // array since its very easy to enumerator through by just maintaining + // an index. If the id counter is zero, then its empty and we leave the + // current index to zero. + // + if (toEnum->fIdCounter) + fCurIndex = 1; +} + +template <class TElem> NameIdPoolEnumerator<TElem>:: +NameIdPoolEnumerator(const NameIdPoolEnumerator<TElem>& toCopy) : + + fCurIndex(toCopy.fCurIndex) + , fToEnum(toCopy.fToEnum) +{ +} + +template <class TElem> NameIdPoolEnumerator<TElem>::~NameIdPoolEnumerator() +{ + // We don't own the pool being enumerated, so no cleanup required +} + + +// --------------------------------------------------------------------------- +// NameIdPoolEnumerator: Public operators +// --------------------------------------------------------------------------- +template <class TElem> NameIdPoolEnumerator<TElem>& NameIdPoolEnumerator<TElem>:: +operator=(const NameIdPoolEnumerator<TElem>& toAssign) +{ + if (this == &toAssign) + return *this; + + fCurIndex = toAssign.fCurIndex; + fToEnum = toAssign.fToEnum; + return *this; +} + + +// --------------------------------------------------------------------------- +// NameIdPoolEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TElem> bool NameIdPoolEnumerator<TElem>:: +hasMoreElements() const +{ + // If our index is zero or past the end, then we are done + if (!fCurIndex || (fCurIndex > fToEnum->fIdCounter)) + return false; + return true; +} + +template <class TElem> TElem& NameIdPoolEnumerator<TElem>::nextElement() +{ + // If our index is zero or past the end, then we are done + if (!fCurIndex || (fCurIndex > fToEnum->fIdCounter)) + ThrowXML(NoSuchElementException, XML4CExcepts::Enum_NoMoreElements); + + // Return the current element and bump the index + return *fToEnum->fIdPtrs[fCurIndex++]; +} + + +template <class TElem> void NameIdPoolEnumerator<TElem>::Reset() +{ + fCurIndex = 0; +} diff --git a/src/util/NameIdPool.hpp b/src/util/NameIdPool.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0f27ef28cc46f266f705825c7449efecc0632948 --- /dev/null +++ b/src/util/NameIdPool.hpp @@ -0,0 +1,287 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:48 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:10 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(NAMEIDPOOL_HPP) +#define NAMEIDPOOL_HPP + +#include <util/XML4CDefs.hpp> +#include <memory.h> +#include <util/XMLEnumerator.hpp> +#include <util/XMLString.hpp> + + +// +// Forward declare the enumerator so he can be our friend. Can you say +// friend? Sure... +// +template <class TElem> class NameIdPoolEnumerator; + + +// +// This class is provided to serve as the basis of many of the pools that +// are used by the scanner and validators. They often need to be able to +// store objects in such a way that they can be quickly accessed by the +// name field of the object, and such that each element added is assigned +// a unique id via which it can be accessed almost instantly. +// +// Object names are enforced as being unique, since that's what all these +// pools require. So its effectively a hash table in conjunction with an +// array of references into the hash table by id. Ids are assigned such that +// id N can be used to get the Nth element from the array of references. +// This provides very fast access by id. +// +// The way these pools are used, elements are never removed except when the +// whole thing is flushed. This makes it very easy to maintain the two +// access methods in sync. +// +// For efficiency reasons, the id refererence array is never flushed until +// the dtor. This way, it does not have to be regrown every time its reused. +// +// All elements are assumed to be owned by the pool! +// +// We have to have a bucket element structure to use to maintain the linked +// lists for each bucket. Because some of the compilers we have to support +// are totally brain dead, it cannot be a nested class as it should be. +// +template <class TElem> struct NameIdPoolBucketElem +{ +public : + NameIdPoolBucketElem + ( + TElem* const value + , NameIdPoolBucketElem<TElem>* const next + ); + ~NameIdPoolBucketElem(); + + TElem* fData; + NameIdPoolBucketElem<TElem>* fNext; +}; + + +template <class TElem> class NameIdPool +{ +public : + // ----------------------------------------------------------------------- + // Contructors and Destructor + // ----------------------------------------------------------------------- + NameIdPool + ( + const unsigned int hashModulus + , const unsigned int initSize = 128 + ); + + ~NameIdPool(); + + + // ----------------------------------------------------------------------- + // Element management + // ----------------------------------------------------------------------- + bool containsKey(const XMLCh* const key) const; + void removeAll(); + + + // ----------------------------------------------------------------------- + // Getters + // ----------------------------------------------------------------------- + TElem* getByKey(const XMLCh* const key); + const TElem* getByKey(const XMLCh* const key) const; + TElem* getById(const unsigned elemId); + const TElem* getById(const unsigned elemId) const; + + + // ----------------------------------------------------------------------- + // Putters + // + // Dups are not allowed and cause an IllegalArgumentException. The id + // of the new element is returned. + // ----------------------------------------------------------------------- + unsigned int put(TElem* const valueToAdopt); + + +protected : + // ----------------------------------------------------------------------- + // Declare the enumerator our friend so he can see our members + // ----------------------------------------------------------------------- + friend class NameIdPoolEnumerator<TElem>; + + +private : + // ----------------------------------------------------------------------- + // Unused constructors and operators + // ----------------------------------------------------------------------- + NameIdPool(const NameIdPool<TElem>&); + void operator=(const NameIdPool<TElem>&); + + + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + NameIdPoolBucketElem<TElem>* findBucketElem + ( + const XMLCh* const key + , unsigned int& hashVal + ); + const NameIdPoolBucketElem<TElem>* findBucketElem + ( + const XMLCh* const key + , unsigned int& hashVal + ) const; + + + // ----------------------------------------------------------------------- + // Data members + // + // fBucketList + // This is the array that contains the heads of all of the list + // buckets, one for each possible hash value. + // + // fIdPtrs + // fIdPtrsCount + // This is the array of pointers to the bucket elements in order of + // their assigned ids. So taking id N and referencing this array + // gives you the element with that id. The count field indicates + // the current size of this list. When fIdCounter+1 reaches this + // value the list must be expanded. + // + // fIdCounter + // This is used to give out unique ids to added elements. It starts + // at zero (which means empty), and is bumped up for each newly added + // element. So the first element is 1, the next is 2, etc... This + // means that this value is set to the top index of the fIdPtrs array. + // + // fHashModulus + // This is the modulus to use in this pool. The fBucketList array + // is of this size. It should be a prime number. + // ----------------------------------------------------------------------- + NameIdPoolBucketElem<TElem>** fBucketList; + TElem** fIdPtrs; + unsigned int fIdPtrsCount; + unsigned int fIdCounter; + unsigned int fHashModulus; +}; + + +// +// An enumerator for a name id pool. It derives from the basic enumerator +// class, so that pools can be generically enumerated. +// +template <class TElem> class NameIdPoolEnumerator : public XMLEnumerator<TElem> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + NameIdPoolEnumerator + ( + NameIdPool<TElem>* const toEnum + ); + + NameIdPoolEnumerator + ( + const NameIdPoolEnumerator<TElem>& toCopy + ); + + ~NameIdPoolEnumerator(); + + // ----------------------------------------------------------------------- + // Public operators + // ----------------------------------------------------------------------- + NameIdPoolEnumerator<TElem>& operator= + ( + const NameIdPoolEnumerator<TElem>& toAssign + ); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TElem& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Data Members + // + // fCurIndex + // This is the current index into the pool's id mapping array. This + // is now we enumerate it. + // + // fToEnum + // The name id pool that is being enumerated. + // ----------------------------------------------------------------------- + unsigned int fCurIndex; + NameIdPool<TElem>* fToEnum; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/NameIdPool.c> +#endif + +#endif diff --git a/src/util/NoDefTranscoderException.hpp b/src/util/NoDefTranscoderException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2b378fad60fa75447994c0a0946e7327adf0d7e6 --- /dev/null +++ b/src/util/NoDefTranscoderException.hpp @@ -0,0 +1,131 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:49 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:10 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(NODEFTRANSCODEREXCEPTION_HPP) +#define NODEFTRANSCODEREXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> + + +class XMLUTIL_EXPORT NoDefTranscoderException : public XMLException +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + NoDefTranscoderException() : + + XMLException("", "NoDefTranscoderException") + { + } + + NoDefTranscoderException(const XMLCh* const msg) : + + XMLException(msg, "NoDefTranscoderException") + { + } + + NoDefTranscoderException(const char* const msg) : + + XMLException(msg, "NoDefTranscoderException") + { + } + + NoDefTranscoderException(const NoDefTranscoderException& toCopy) : + + XMLException(toCopy) + { + } + + virtual ~NoDefTranscoderException() + { + } + + + // ----------------------------------------------------------------------- + // A special ctor called during init if we cannot create a def xcoder. + // This one takes both messages so that no transcoding is required in + // order to throw it. + // ----------------------------------------------------------------------- + NoDefTranscoderException(const XMLCh* const type, const XMLCh* const msg) : + + XMLException(msg, type) + { + } + + + // ----------------------------------------------------------------------- + // Miscellaneous + // ----------------------------------------------------------------------- + virtual XMLException* duplicate() const + { + return new NoDefTranscoderException(*this); + } +}; + +#endif diff --git a/src/util/NoSuchElementException.hpp b/src/util/NoSuchElementException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9ab4733a85da6798dbc8faef797307c20ad7f3a3 --- /dev/null +++ b/src/util/NoSuchElementException.hpp @@ -0,0 +1,87 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:50 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:11 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(NOSUCHELEMENTEXCEPTION_HPP) +#define NOSUCHELEMENTEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + + +// Hard coded Unicode text for "NoSuchElementException" +static const XMLCh gNoSuchElementException_Name[] = +{ + chLatin_N, chLatin_o, chLatin_S, chLatin_u, chLatin_h, chLatin_h + , chLatin_E, chLatin_l, chLatin_e, chLatin_e, chLatin_m, chLatin_e + , chLatin_n, chLatin_t, chLatin_E, chLatin_x, chLatin_c, chLatin_e + , chLatin_p, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(NoSuchElementException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/NullPointerException.hpp b/src/util/NullPointerException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8615eb3331f495615d8918955e10281e8457bbb6 --- /dev/null +++ b/src/util/NullPointerException.hpp @@ -0,0 +1,86 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:51 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:11 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(NULLPOINTEREXCEPTION_HPP) +#define NULLPOINTEREXCEPTION_HPP + + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> + + +// Hard coded Unicode text for "NullPointerException" +static const XMLCh gNullPointerException_Name[] = +{ + chLatin_N, chLatin_u, chLatin_l, chLatin_l, chLatin_P, chLatin_o + , chLatin_i, chLatin_n, chLatin_t, chLatin_e, chLatin_r, chLatin_E + , chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i + , chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(NullPointerException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/PlatformUtils.cpp b/src/util/PlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec9ad18faf11c8f4833329839c6e6a073423731d --- /dev/null +++ b/src/util/PlatformUtils.cpp @@ -0,0 +1,177 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:53 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:11 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XMLMsgLoader.hpp> +#include <util/Mutexes.hpp> +#include <util/PlatformUtils.hpp> +#include <util/XMLString.hpp> +#include <util/TransService.hpp> +#include <util/XMLUni.hpp> + + +// --------------------------------------------------------------------------- +// Local data members +// +// gMsgMutex +// This is a mutex that will be used to synchronize access to the single +// static message loader for exception messages. +// --------------------------------------------------------------------------- +static XMLMutex* gMsgMutex = 0; + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Static Data Members +// --------------------------------------------------------------------------- +const char* XMLPlatformUtils::fgLibLocation = 0; +bool XMLPlatformUtils::fgInitFlag = false; +XMLNetAccessor* XMLPlatformUtils::fgNetAccessor = 0; +XMLTransService* XMLPlatformUtils::fgTransService = 0; + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Platform independent init methods +// --------------------------------------------------------------------------- +void XMLPlatformUtils::Initialize() +{ + // + // Make sure we haven't already been initialized. Note that this is not + // thread safe and is not intended for that. Its more for those COM + // like processes that cannot keep up with whether they have initialized + // us yet or not. + // + if (fgInitFlag) + return; + fgInitFlag = true; + + // Create the message sync mutex + gMsgMutex = new XMLMutex; + + // + // Call the platform init method, which is implemented in each of the + // per-platform implementation cpp files. This one does the very low + // level per-platform setup. It cannot use any XML util services at all, + // i.e. only native services. + // + // One important thing it does is to set the fgLibLocation string, which + // can be used by any subsequent init code that needs to find stuff + // relative to the lib/DLL. + // + platformInit(); + + // + // Ask the per-platform code to make the desired transcoding service for + // us to use. This call cannot throw any exceptions or do anything that + // cause any transcoding to happen. It should create the service and + // return it or zero if it cannot. + // + // This one also cannot use any utility services. It can only create a + // transcoding service object and return it. + // + // If we cannot make one, then we call panic to end the process. + // + fgTransService = makeTransService(); + if (!fgTransService) + panic(Panic_NoTransService); + + // + // Try to create a default transcoder. This is the one that will be + // used internally by the XMLString class. If we cannot create one, then + // call the panic method. + // + XMLTranscoder* defXCode = XMLPlatformUtils::fgTransService->makeNewDefTranscoder(); + if (!defXCode) + panic(Panic_NoDefTranscoder); + XMLString::initString(defXCode); + + // + // Now lets ask the per-platform code to give us an instance of the type + // of network access implementation he wants to use. + // + fgNetAccessor = makeNetAccessor(); + if (!fgNetAccessor) + { + // <TBD> For now its returning a null, but later this will be required + } +} + + +// --------------------------------------------------------------------------- +// Platform independent Msg support methods +// --------------------------------------------------------------------------- +XMLMsgLoader* XMLPlatformUtils::loadMsgSet(const XMLCh* const msgDomain) +{ + // + // Ask the platform support to load up the correct type of message + // loader for the indicated message set. We don't check here whether it + // works or not. That's their decision. + // + return loadAMsgSet(msgDomain); +} diff --git a/src/util/PlatformUtils.hpp b/src/util/PlatformUtils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..99977a5c5b6ad9c7ebca7d256b1a26fc1ba24428 --- /dev/null +++ b/src/util/PlatformUtils.hpp @@ -0,0 +1,260 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:55 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:11 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(PLATFORMUTILS_HPP) +#define PLATFORMUTILS_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + +class XMLMsgLoader; +class XMLNetAccessor; +class XMLTransService; + + +// +// Generate an exception for platform utitilities to throw when something +// goes awry. +// +const XMLCh gXMLPlatformUtilsException_Name[] = +{ + chLatin_X, chLatin_M, chLatin_L, chLatin_P, chLatin_l, chLatin_a + , chLatin_t, chLatin_f, chLatin_o, chLatin_r, chLatin_m, chLatin_E + , chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i + , chLatin_o, chLatin_n, chNull +}; +MakeXML4CException(XMLPlatformUtilsException, XMLUTIL_EXPORT) + + +class XMLUTIL_EXPORT XMLPlatformUtils +{ +public : + // ----------------------------------------------------------------------- + // Public types + // ----------------------------------------------------------------------- + enum PanicReasons + { + Panic_NoTransService + , Panic_NoDefTranscoder + , Panic_CantFindLib + , Panic_UnknownMsgDomain + , Panic_CantLoadMsgDomain + + , PanicReasons_Count + }; + + + // ----------------------------------------------------------------------- + // Public, static data + // + // fgNetAccessor + // This is the network access implementation. This is provided by + // the per-platform driver, so each platform can choose what actual + // implementation it wants to use. + // + // fgTransService + // This is the transcoding service. This is provided by the per + // platform driver, so each platform can choose what implemenation + // it wants to use. + // + // fgLibLocation + // This is the location of the shared library or DLL. For some + // platforms, it might be some fixed directory and others will + // discover it dynamically. All other needed stuff is relative to + // this path. + // ----------------------------------------------------------------------- + static XMLNetAccessor* fgNetAccessor; + static XMLTransService* fgTransService; + static const char* fgLibLocation; + + + // ----------------------------------------------------------------------- + // Initialization method. This must be called first in any client code. + // ----------------------------------------------------------------------- + static void Initialize(); + + + // ----------------------------------------------------------------------- + // The panic mechanism. If, during init, we cannot even get far enough + // along to get transcoding up or get message loading working, we call + // this. + // + // Each platform can implement it however they want. This method is + // expected to display something meaningful and end the process. The + // enum indicates why its being called, to allow the per-platform code + // to display something more specific if desired. + // ----------------------------------------------------------------------- + static void panic + ( + const PanicReasons reason + ); + + + // ----------------------------------------------------------------------- + // File methods + // ----------------------------------------------------------------------- + static unsigned int curFilePos(FileHandle theFile); + static void closeFile(FileHandle theFile); + static unsigned int fileSize(FileHandle theFile); + static FileHandle openFile(const char* const fileName); + static FileHandle openFile(const XMLCh* const fileName); + static FileHandle openStdInHandle(); + static unsigned int readFileBuffer + ( + FileHandle theFile + , const unsigned int toRead + , XMLByte* const toFill + ); + static void resetFile(FileHandle theFile); + + + // ----------------------------------------------------------------------- + // Standard out/error support + // ----------------------------------------------------------------------- + static void writeToStdErr(const char* const toWrite); + static void writeToStdErr(const XMLCh* const toWrite); + static void writeToStdOut(const XMLCh* const toWrite); + static void writeToStdOut(const char* const toWrite); + + + // ----------------------------------------------------------------------- + // File system methods + // ----------------------------------------------------------------------- + static XMLCh* getBasePath(const XMLCh* const srcPath); + static bool isRelative(const XMLCh* const toCheck); + + + // ----------------------------------------------------------------------- + // Timing methods + // ----------------------------------------------------------------------- + static unsigned long getCurrentMillis(); + + + // ----------------------------------------------------------------------- + // Mutex methods + // ----------------------------------------------------------------------- + static void closeMutex(void* const mtxHandle); + static void lockMutex(void* const mtxHandle); + static void* makeMutex(); + static void unlockMutex(void* const mtxHandle); + + + // ----------------------------------------------------------------------- + // External message support + // ----------------------------------------------------------------------- + static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain); + + + // ----------------------------------------------------------------------- + // Miscellaneous synchronization methods + // ----------------------------------------------------------------------- + static void* compareAndSwap + ( + void** toFill + , const void* const newValue + , const void* const toCompare + ); + + + // ----------------------------------------------------------------------- + // Atomic Increment and Decrement + // + // The function return value is positive if the result of the operation + // was positive. Zero if the result of the operation was zero. Negative + // if the result of the operation was negative. Except for the zero + // case, the value returned may differ from the actual result of the + // operation - only the sign and zero/nonzero state is guaranteed to be + // correct. + // ----------------------------------------------------------------------- + static int atomicIncrement(int& location); + static int atomicDecrement(int& location); + + +private : + // ----------------------------------------------------------------------- + // Private static methods. These are provided by the per-platform + // implementation files. + // ----------------------------------------------------------------------- + static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain); + static XMLNetAccessor* makeNetAccessor(); + static XMLTransService* makeTransService(); + static void platformInit(); + + + // ----------------------------------------------------------------------- + // Private static data members + // + // fgInitFlag + // This is used to avoid multiple inits if the client code calls us + // more than once. They aren't supposed to, but some have trouble + // keeping up if they are COM objects and such. + // ----------------------------------------------------------------------- + static bool fgInitFlag; +}; + +#endif diff --git a/src/util/Platforms/AIX/AIXDefs.hpp b/src/util/Platforms/AIX/AIXDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d7ca622e0bceacd787ff378dabe85e1080cddbd6 --- /dev/null +++ b/src/util/Platforms/AIX/AIXDefs.hpp @@ -0,0 +1,77 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:10 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// AIX runs in big endian mode +// --------------------------------------------------------------------------- +#define ENDIANMODE_BIG + + +// --------------------------------------------------------------------------- +// And define our file handle abstraction +// --------------------------------------------------------------------------- +typedef void* FileHandle; diff --git a/src/util/Platforms/AIX/AIXPlatformUtils.cpp b/src/util/Platforms/AIX/AIXPlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f408abc1c5f865347904aa5536f12bfcc88c53e --- /dev/null +++ b/src/util/Platforms/AIX/AIXPlatformUtils.cpp @@ -0,0 +1,658 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:11 twl + * Initial revision + * + * Revision 1.6 1999/11/08 20:45:29 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#ifndef APP_NO_THREADS +#include <pthread.h> +#include <sys/atomic_op.h> +#endif + +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/Janitor.hpp> +#include <util/XMLString.hpp> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <libgen.h> +#include <sys/timeb.h> +#include <string.h> +#include <unistd.h> +#include <sys/ldr.h> + +#if defined (XML_USE_ICU_TRANSCODER) + #include <util/Transcoders/ICU/ICUTransService.hpp> +#else // use native transcoder + #include <util/Transcoders/Iconv/IconvTransService.hpp> +#endif + +#if defined (XML_USE_ICU_MESSAGELOADER) + #include <util/MsgLoaders/ICU/ICUMsgLoader.hpp> +#elif defined (XML_USE_ICONV_MESSAGELOADER) + #include <util/MsgLoaders/MsgCatalog/MsgCatalogLoader.hpp> +#else // use In-memory message loader + #include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> //hint for the user to include this file. +#endif + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- +static void WriteCharStr( FILE* stream, const char* const toWrite) +{ + if (fputs(toWrite, stream) == EOF) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::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, XML4CExcepts::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, XML4CExcepts::Strm_StdOutWriteFailure); + } +} + + +XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() +{ + return 0; +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Platform init method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::platformInit() +{ + // Here you would also set the fgLibLocation global variable + // XMLPlatformUtils::fgLibLocation is the variable to be set + + static const char * libraryPath = 0; + + char libName[256]; + strcpy(libName, XML4C_DLLName); + strcat(libName, gXML4CVersionStr); + strcat(libName, ".a"); + + const int bufLen = 4096; // arbitrary value big enough to hold path name + char buf[bufLen]; // it's in the stack anyway + + if (load(libName, L_LIBPATH_EXEC, ".") == NULL) { + char errorBuffer[1024]; + sprintf(errorBuffer, "Could not load library '%s'", libName); + perror (errorBuffer); + exit(-1); + } + + int retval = loadquery(L_GETINFO, buf, bufLen); + if (retval == -1) { + fprintf(stderr, "Unable to load library '%s'.\n", libName); + exit(-1); + } + + struct ld_info* oneBufPtr = (struct ld_info*)buf; + + while (oneBufPtr) + { + if (oneBufPtr != (struct ld_info*) buf) + { + char* fileName = oneBufPtr->ldinfo_filename; + if (strstr(fileName, libName) != NULL) { + char* copyTo = strrchr(fileName, '/'); + size_t chars_to_extract = copyTo - fileName; + char *libPathName = new char[chars_to_extract + 1]; + strncpy(libPathName, fileName, chars_to_extract); + libPathName[chars_to_extract] = 0; + libraryPath = new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) libraryPath, libPathName); + strcat((char *) libraryPath, "/icu/data/"); + delete libPathName; + break; + } + } + if (oneBufPtr->ldinfo_next == 0) + oneBufPtr = NULL; + else + oneBufPtr = (struct ld_info*) ((char*) oneBufPtr + oneBufPtr->ldinfo_next); + } + + XMLPlatformUtils::fgLibLocation = libraryPath; + + if (XMLPlatformUtils::fgLibLocation == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } +} + +// +// 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) +{ + // + // We need to figure out the path to the Intl classes. They will be + // in the .\Intl subdirectory under this DLL. + // + + static const char * xml4cIntlDirEnvVar = "ICU_DATA"; + static const char * sharedLibEnvVar = "LIBPATH"; + static char * intlPath = 0; + + char* envVal = getenv(xml4cIntlDirEnvVar); + //check if environment variable is set + if (envVal != NULL) + { + // Store this string in the static member + unsigned int pathLen = strlen(envVal); + intlPath = new char[pathLen + 2]; + + strcpy((char *) intlPath, envVal); + if (envVal[pathLen - 1] != '/') + { + strcat((char *) intlPath, "/"); + } + ICUTransService::setICUPath(intlPath); + if (intlPath != NULL) delete intlPath; + + return new ICUTransService; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + + char libName[256]; + strcpy(libName, XML4C_DLLName); + strcat(libName, gXML4CVersionStr); + strcat(libName, ".a"); + + char* libEnvVar = getenv(sharedLibEnvVar); + char* libPath = NULL; + + if (libEnvVar == NULL) + { + fprintf(stderr, + "Error: Could not locate i18n converter files.\n"); + fprintf(stderr, + "Environment variable '%s' is not defined.\n", sharedLibEnvVar); + fprintf(stderr, + "Environment variable 'ICU_DATA' is also not defined.\n"); + exit(-1); + } + + // + // Its necessary to create a copy because strtok() modifies the + // string as it returns tokens. We don't want to modify the string + // returned to by getenv(). + // + + libPath = new char[strlen(libEnvVar) + 1]; + strcpy(libPath, libEnvVar); + + //First do the searching process for the first directory listing + // + char* allPaths = libPath; + char* libPathName; + + while ((libPathName = strtok(allPaths, ":")) != NULL) + { + FILE* dummyFptr = 0; + allPaths = 0; + + char* libfile = new char[strlen(libPathName) + strlen(libName) + 2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + dummyFptr = (FILE *) fopen(libfile, "rb"); + delete [] libfile; + if (dummyFptr != NULL) + { + fclose(dummyFptr); + intlPath = + new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) intlPath, libPathName); + strcat((char *) intlPath, "/icu/data/"); + break; + } + + } // while + + delete libPath; + ICUTransService::setICUPath(intlPath); + + if (intlPath == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } + if (intlPath != NULL) delete intlPath; + + return new ICUTransService; +} +#elif defined (XML_USE_ICONV_TRANSCODER) +{ + return new IconvTransService; +} +#else +{ + return new IconvTransService; +} +#endif + +// +// 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. +// In our case, we use the ICU based message loader mechanism. +// +XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) +{ + XMLMsgLoader* retVal; + try + { +#if defined (XML_USE_ICU_MESSAGELOADER) + retVal = new ICUMsgLoader(msgDomain); +#elif defined (XML_USE_ICONV_MESSAGELOADER) + retVal = new MsgCatalogLoader(msgDomain); +#else + retVal = new InMemMsgLoader(msgDomain); +#endif + } + + catch(...) + { + panic( XMLPlatformUtils::Panic_NoDefTranscoder ); + } + return retVal; +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: The panic method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::panic(const PanicReasons reason) +{ + // + // We just print a message and exit + // + printf("The XML4C system could not be initialized.\n"); + printf("The most likely reason for this failure is the inability to find\n"); + printf("the international encoding files. By default, the encoding files\n"); + printf("have the extension .cnv and exist in a directory icu/data relative\n"); + printf("to the XML4C shared library. If you have kept the converter files\n"); + printf("in a different location, you need to set up an environment variable\n"); + printf("called ICU_DATA which directly points to the directory where the\n"); + printf("encoding files are kept.\n"); + + exit(-1); +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + int curPos = ftell( (FILE*)theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetSize); + + return (unsigned int)curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*)theFile)) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotCloseFile); +} + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*)theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetCurPos); + + // Seek to the end and save that value for return + if (fseek( (FILE*)theFile, 0, SEEK_END) ) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToEnd); + + long int retVal = ftell( (FILE*)theFile); + if (retVal == -1) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToEnd); + + // And put the pointer back + if (fseek( (FILE*)theFile, curPos, SEEK_SET) ) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToPos); + + return (unsigned int)retVal; +} + +FileHandle XMLPlatformUtils::openFile(const unsigned short* 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; +} + +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, XML4CExcepts::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, XML4CExcepts::File_CouldNotResetFile); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + timeb aTime; + ftime(&aTime); + return (unsigned long)(aTime.time*1000 + aTime.millitm); + +} + + + +XMLCh* XMLPlatformUtils::getBasePath(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* tmpPath = dirname((char*)newSrc); + if (!tmpPath) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetBasePathName); + } + + char* newXMLString = new char [strlen(tmpPath) +2]; + ArrayJanitor<char> newJanitor(newXMLString); + strcpy(newXMLString, tmpPath); + strcat(newXMLString , "/"); + // Return a copy of the path, in Unicode format + return XMLString::transcode(newXMLString); +} + +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; +} + +// ----------------------------------------------------------------------- +// Standard out/error support +// ----------------------------------------------------------------------- + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStr(stderr, toWrite); +} + +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} + +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} + +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStr(stdout, toWrite); +} + + +// ----------------------------------------------------------------------- +// Mutex methods +// ----------------------------------------------------------------------- +#ifndef APP_NO_THREADS +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_destroy( (pthread_mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotDestroy); + } + if ( (pthread_mutex_t*)mtxHandle) + delete mtxHandle; +} +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_lock( (pthread_mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotLock); + } + +} +void* XMLPlatformUtils::makeMutex() +{ + pthread_mutex_t* mutex = new pthread_mutex_t; + if (mutex == NULL) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotCreate); + } + + if (pthread_mutex_init(mutex, NULL)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotCreate); + } + + return (void*)(mutex); +} +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_unlock( (pthread_mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotUnlock); + } +} + +#else // #ifndef APP_NO_THREADS + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ +} + +void* XMLPlatformUtils::makeMutex() +{ + return 0; +} + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ +} + +#endif // APP_NO_THREADS + +#ifndef APP_NO_THREADS + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , + const void* const toCompare) +{ + boolean_t boolVar = compare_and_swap((atomic_p)toFill, (int *)&toCompare, (int)newValue ); + return (void *)toCompare; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +{ + int retVal = fetch_and_add( (atomic_p)&location, 1); + return retVal+1; +} +int XMLPlatformUtils::atomicDecrement(int &location) +{ + int retVal = fetch_and_add( (atomic_p)&location, -1); + return retVal-1; +} + +#else + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- + +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 + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + return (FileHandle)fdopen(dup(0), "rb"); +} + diff --git a/src/util/Platforms/HPUX/HPPlatformUtils.cpp b/src/util/Platforms/HPUX/HPPlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8236d9a84b70eb0d98677fa1ed685f77b22ff2ea --- /dev/null +++ b/src/util/Platforms/HPUX/HPPlatformUtils.cpp @@ -0,0 +1,643 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:05 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:29 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- + +#if !defined(APP_NO_THREADS) +#include <pthread.h> +#endif // APP_NO_THREADS + +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/Janitor.hpp> +#include <util/Mutexes.hpp> +#include <dl.h> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <libgen.h> +#include <string.h> +#include <unistd.h> + +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> + +#if defined (XML_USE_ICU_TRANSCODER) + #include <util/Transcoders/ICU/ICUTransService.hpp> +#else // use native transcoder + #include <util/Transcoders/Iconv/IconvTransService.hpp> +#endif + +#if defined (XML_USE_ICU_MESSAGELOADER) + #include <util/MsgLoaders/ICU/ICUMsgLoader.hpp> +#elif defined (XML_USE_ICONV_MESSAGELOADER) + #include <util/MsgLoaders/MsgCatalog/MsgCatalogLoader.hpp> +#else // use In-memory message loader + #include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> +#endif + + +#if !defined(XML_HPUX_KAICC) +#include <sys/timeb.h> // does not work with KAI compiler +#endif + + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- + +static void WriteCharStr(FILE* stream, const char* const toWrite) +{ + if (fputs(toWrite, stream) == EOF) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::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, + XML4CExcepts::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, + XML4CExcepts::Strm_StdOutWriteFailure); + } +} + + +// ----------------------------------------------------------------------- +// Standard out/error support +// ----------------------------------------------------------------------- + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStr(stderr, toWrite); +} +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStr(stdout, toWrite); +} + + +// +// This method is called by the platform independent part of this class +// during initialization. We have to create the type of net accessor that +// we want to use. +// + +XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() +{ + return 0; +} + + +// --------------------------------------------------------------------------- +// 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(); +} + + + +// --------------------------------------------------------------------------- +// 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. +// In our case, we use the ICU based message loader mechanism. +// +XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) +{ + XMLMsgLoader* retVal; + try + { +#if defined (XML_USE_ICU_MESSAGELOADER) + retVal = new ICUMsgLoader(msgDomain); +#elif defined (XML_USE_ICONV_MESSAGELOADER) + retVal = new MsgCatalogLoader(msgDomain); +#else + retVal = new InMemMsgLoader(msgDomain); +#endif + } + catch(...) + { + panic(XMLPlatformUtils::Panic_NoDefTranscoder); + } + 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) + // + // We need to figure out the path to the ICU converter files. + // + + static const char * xml4cIntlDirEnvVar = "ICU_DATA"; + + // + // Check if environment variable 'ICU_DATA' is set. + // + + char* envVal = getenv(xml4cIntlDirEnvVar); + + if (envVal != NULL) + { + unsigned int pathLen = strlen(envVal); + char* intlPath = new char[pathLen + 2]; + + strcpy((char *) intlPath, envVal); + if (envVal[pathLen - 1] != '/') + { + strcat((char *) intlPath, "/"); + } + + ICUTransService::setICUPath(intlPath); + delete intlPath; + + return new ICUTransService; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + + char libName[256]; + strcpy(libName, XML4C_DLLName); + strcat(libName, gXML4CVersionStr); + strcat(libName, ".sl"); + + shl_descriptor* desc = NULL; + int ret = 0; + int index = 1; + + ret = shl_get(index, &desc); + while (ret != -1) + { + char* fileName = desc->filename; + if (strstr(fileName, libName) != NULL) + { + char* lastSlash = strrchr(fileName, '/'); + size_t chars_to_extract = lastSlash - fileName; + char *libPathName = new char[chars_to_extract + 1]; + strncpy(libPathName, fileName, chars_to_extract); + libPathName[chars_to_extract] = 0; + fgIntlPath = new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) fgIntlPath, libPathName); + strcat((char *) fgIntlPath, "/icu/data/"); + delete libPathName; + break; + } + index++; + ret = shl_get(index, &desc); + } + + if (fgIntlPath == NULL) + { + fprintf(stderr, + "Fatal error: Could not find /icu/data relative to %s \n", + libName); + fprintf(stderr, + " while trying to auto detect the location "); + fprintf(stderr, "of the converter files.\n"); + fprintf(stderr, + " And the environment variable 'ICU_DATA' is "); + fprintf(stderr, "not defined.\n"); + panic(XMLPlatformUtils::Panic_NoTransService); + } + + ICUTransService::setICUPath(fgIntlPath); + return new ICUTransService; + +#else // Use Native transcoding service + + return new IconvTransService; + +#endif +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: The panic method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::panic(const PanicReasons reason) +{ + // + // We just print a message and exit + // + fprintf(stderr, + "The XML4C system could not be initialized.\n"); + fprintf(stderr, + "The most likely reason for this failure is the inability to find\n"); + fprintf(stderr, + "the ICU coverter files, if you are using ICU. The converter files\n"); + fprintf(stderr, + "have the extension .cnv and exist in a directory 'icu/data' relative\n"); + fprintf(stderr, + "to the XML4C shared library. If you have installed the converter files\n"); + fprintf(stderr, + "in a different location, you need to set up the environment variable\n"); + fprintf(stderr, + "'ICU_DATA' to point directly to the directory containing the\n"); + fprintf(stderr, + "converter files.\n"); + + exit(-1); +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- + +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + long curPos = ftell((FILE*) theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotGetCurPos); + + return (unsigned int) curPos; +} + + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*) theFile)) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotCloseFile); +} + + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*) theFile); + if (curPos == -1) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotGetCurPos); + } + + // Seek to the end and save that value for return + if (fseek((FILE*) theFile, 0, SEEK_END)) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotSeekToEnd); + } + + long int retVal = ftell((FILE*) theFile); + if (retVal == -1) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotGetSize); + + // And put the pointer back + if (fseek((FILE*) theFile, curPos, SEEK_SET)) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotSeekToPos); + + return (unsigned int) retVal; +} + + +FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName) +{ + char* tmpFileName = XMLString::transcode(fileName); + FileHandle retVal = (FILE*) fopen(tmpFileName , "rb"); + delete [] tmpFileName; + 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, + XML4CExcepts::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, + XML4CExcepts::File_CouldNotResetFile); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- + +unsigned long XMLPlatformUtils::getCurrentMillis() +{ +#if defined(XML_HPUX_KAICC) // should be reimplemented by someone with + // HP/UX and KAI knowledge. + return (unsigned long) 0; +#else + timeb aTime; + ftime(&aTime); + return (unsigned long)(aTime.time*1000 + aTime.millitm); +#endif +} + + + +XMLCh* XMLPlatformUtils::getBasePath(const XMLCh* const srcPath) +{ + + // + // NOTE: The path provided has always already been opened successfully, + // so we know that it is valid. It comes in native format, and goes out + // as Unicode always + // + char* newSrc = XMLString::transcode(srcPath); + + // Use a local buffer that is big enough for the largest legal path. + // Note #1186: dirName() is not thread safe. + + char* tmpPath = dirname(newSrc); // dirname() never returns NULL. + delete [] newSrc; + + char* newXMLString = new char[strlen(tmpPath) + 2]; + ArrayJanitor<char> newJanitor(newXMLString); + strcpy(newXMLString, tmpPath); + strcat(newXMLString , "/"); + + // Return a copy of the path, in Unicode format + return XMLString::transcode(newXMLString); +} + + +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) + + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + pthread_mutex_t* mutex = (pthread_mutex_t *) mtxHandle; + if (mutex != NULL) + { + if (pthread_mutex_destroy(mutex)) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::Mutex_CouldNotDestroy); + delete mutex; + } +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (mtxHandle != NULL) + { + if (pthread_mutex_lock((pthread_mutex_t *) mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::Mutex_CouldNotLock); + } + } +} + +void* XMLPlatformUtils::makeMutex() +{ + pthread_mutex_t* mutex = new pthread_mutex_t; + + if (pthread_mutex_init(mutex, pthread_mutexattr_default)) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::Mutex_CouldNotCreate); + } + return (void*) mutex; +} + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (mtxHandle != NULL) + { + if (pthread_mutex_unlock((pthread_mutex_t *) mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::Mutex_CouldNotUnlock); + } + } +} + + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- + +void* XMLPlatformUtils::compareAndSwap ( void** toFill, + const void* const newValue, + const void* const toCompare) +{ + XMLMutexLock localLock(&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::closeMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ +} + +void* XMLPlatformUtils::makeMutex() +{ + return 0; +} + +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 + diff --git a/src/util/Platforms/HPUX/HPUXDefs.hpp b/src/util/Platforms/HPUX/HPUXDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..31a90e95161746051c7bd714620e0c1c50b9b756 --- /dev/null +++ b/src/util/Platforms/HPUX/HPUXDefs.hpp @@ -0,0 +1,78 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:06 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:29 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// HPUX runs in big endian mode +// --------------------------------------------------------------------------- +#define ENDIANMODE_BIG +typedef void* FileHandle; + +#ifndef HPUX +#define HPUX +#endif + +//#define _PTHREADS_DRAFT4 diff --git a/src/util/Platforms/Linux/LinuxDefs.hpp b/src/util/Platforms/Linux/LinuxDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..16dc179bfa7627a4ef4b576f89cc0d46db5b80c7 --- /dev/null +++ b/src/util/Platforms/Linux/LinuxDefs.hpp @@ -0,0 +1,76 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:00 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:30 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// linux runs in little endian mode +// --------------------------------------------------------------------------- +#define ENDIANMODE_LITTLE +typedef void* FileHandle; + +#ifndef LINUX +#define LINUX +#endif diff --git a/src/util/Platforms/Linux/LinuxPlatformUtils.cpp b/src/util/Platforms/Linux/LinuxPlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7cc63640ced9173da4d618ecb79c9aec30821fee --- /dev/null +++ b/src/util/Platforms/Linux/LinuxPlatformUtils.cpp @@ -0,0 +1,656 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:07:01 twl + * Initial revision + * + * Revision 1.6 1999/11/08 20:45:30 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- + +#ifndef APP_NO_THREADS +#include <pthread.h> +#endif + +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <libgen.h> +#include <sys/timeb.h> +#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/XMLUni.hpp> + +#if defined (XML_USE_ICU_TRANSCODER) + #include <util/Transcoders/ICU/ICUTransService.hpp> +#else // use native transcoder + #include <util/Transcoders/Iconv/IconvTransService.hpp> +#endif + +#if defined (XML_USE_ICU_MESSAGELOADER) + #include <util/MsgLoaders/ICU/ICUMsgLoader.hpp> +#elif defined (XML_USE_ICONV_MESSAGELOADER) + #include <util/MsgLoaders/MsgCatalog/MsgCatalogLoader.hpp> +#else // use In-memory message loader + #include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> //hint for the user to include this file. +#endif + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- + +static void WriteCharStr( FILE* stream, const char* const toWrite) +{ + if (fputs(toWrite, stream) == EOF) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::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, + XML4CExcepts::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, + XML4CExcepts::Strm_StdOutWriteFailure); + } +} + +XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() +{ + return 0; +} + +// --------------------------------------------------------------------------- +// 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(); + + // Here you would also set the fgLibLocation global variable + // XMLPlatformUtils::fgLibLocation is the variable to be set + + static const char *sharedLibEnvVar = "LD_LIBRARY_PATH"; + static const char * libraryPath = 0; + + char libName[256]; + + // Construct the library name from the global variables + strcpy(libName, XML4C_DLLName); + strcat(libName, gXML4CVersionStr); + strcat(libName, ".so"); + + char* libEnvVar = getenv(sharedLibEnvVar); + char* libPath = NULL; + + if (libEnvVar == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } + + // + // Its necessary to create a copy because strtok() modifies the + // string as it returns tokens. We don't want to modify the string + // returned to by getenv(). + + libPath = new char[strlen(libEnvVar) + 1]; + strcpy(libPath, libEnvVar); + + // First do the searching process for the first directory listing + char* allPaths = libPath; + char* libPathName; + + while ((libPathName = strtok(allPaths, ":")) != NULL) + { + FILE* dummyFptr = 0; + allPaths = 0; + + char* libfile = new char[strlen(libPathName) + strlen(libName) + 2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + dummyFptr = (FILE *) fopen(libfile, "rb"); + delete [] libfile; + if (dummyFptr != NULL) + { + fclose(dummyFptr); + libraryPath = new char[strlen(libPathName)+1]; + strcpy((char *) libraryPath, libPathName); + break; + } + + } + + delete libPath; + + XMLPlatformUtils::fgLibLocation = libraryPath; + + if (XMLPlatformUtils::fgLibLocation == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } +} + + +// --------------------------------------------------------------------------- +// 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. +// In our case, we use the ICU based message loader mechanism. +// +XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) +{ + XMLMsgLoader* retVal; + try + { +#if defined (XML_USE_ICU_MESSAGELOADER) + retVal = new ICUMsgLoader(msgDomain); +#elif defined (XML_USE_ICONV_MESSAGELOADER) + retVal = new MsgCatalogLoader(msgDomain); +#else + retVal = new InMemMsgLoader(msgDomain); +#endif + } + + catch(...) + { + panic( XMLPlatformUtils::Panic_NoDefTranscoder ); + } + 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) +{ + // + // We need to figure out the path to the Intl converter files. + // + + static const char * xml4cIntlDirEnvVar = "ICU_DATA"; + static const char * sharedLibEnvVar = "LD_LIBRARY_PATH"; + static const char * intlPath = 0; + + char* envVal = getenv(xml4cIntlDirEnvVar); + //check if environment variable is set + if (envVal != NULL) // We have found an environment variable + { + // Store this string in the static member + unsigned int pathLen = strlen(envVal); + intlPath = new char[pathLen + 2]; + + strcpy((char *) intlPath, envVal); + if (envVal[pathLen - 1] != '/') + { + strcat((char *) intlPath, "/"); + } + + ICUTransService::setICUPath(intlPath); + if (intlPath != NULL) delete intlPath; + + return new ICUTransService; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + char libName[256]; + strcpy(libName, XML4C_DLLName); + strcat(libName, gXML4CVersionStr); + strcat(libName, ".so"); + + char* libEnvVar = getenv(sharedLibEnvVar); + char* libPath = NULL; + + if (libEnvVar == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } + + // + // Its necessary to create a copy because strtok() modifies the + // string as it returns tokens. We don't want to modify the string + // returned to by getenv(). + // + + libPath = new char[strlen(libEnvVar) + 1]; + strcpy(libPath, libEnvVar); + + // First do the searching process for the first directory listing + char* allPaths = libPath; + char* libPathName; + + while ((libPathName = strtok(allPaths, ":")) != NULL) + { + FILE* dummyFptr = 0; + allPaths = 0; + + char* libfile = new char[strlen(libPathName) + strlen(libName) + 2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + dummyFptr = (FILE *) fopen(libfile, "rb"); + delete [] libfile; + if (dummyFptr != NULL) + { + fclose(dummyFptr); + intlPath = new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) intlPath, libPathName); + strcat((char *) intlPath, "/icu/data/"); + break; + } + + } // while + + delete libPath; + + ICUTransService::setICUPath(intlPath); + + if (intlPath == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } + if (intlPath != NULL) delete intlPath; + + return new ICUTransService; +} +#elif defined (XML_USE_ICONV_TRANSCODER) +{ + return new IconvTransService; +} +#else +{ + return new IconvTransService; +} +#endif + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: The panic method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::panic(const PanicReasons reason) +{ + // + // We just print a message and exit + // + printf("The XML4C system could not be initialized.\n"); + printf("The most likely reason for this failure is the inability to find\n"); + printf("the international encoding files. By default, the encoding files\n"); + printf("have the extension .cnv and exist in a directory icu/data relative\n"); + printf("to the XML4C shared library. If you have kept the converter files\n"); + printf("in a different location, you need to set up an environment variable\n"); + printf("called ICU_DATA which directly points to the directory where the\n"); + printf("encoding files are kept.\n"); + + exit(-1); +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + int curPos = ftell( (FILE*)theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetSize); + + return (unsigned int)curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*)theFile)) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotCloseFile); +} + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*)theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetCurPos); + + // Seek to the end and save that value for return + if (fseek( (FILE*)theFile, 0, SEEK_END) ) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToEnd); + + long int retVal = ftell( (FILE*)theFile); + if (retVal == -1) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToEnd); + + // And put the pointer back + if (fseek( (FILE*)theFile, curPos, SEEK_SET) ) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToPos); + + return (unsigned int)retVal; +} + +FileHandle XMLPlatformUtils::openFile(const unsigned short* 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; +} + +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, XML4CExcepts::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, XML4CExcepts::File_CouldNotResetFile); +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- + +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + timeb aTime; + ftime(&aTime); + return (unsigned long)(aTime.time*1000 + aTime.millitm); + +} + +XMLCh* XMLPlatformUtils::getBasePath(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* tmpPath = dirname((char*)newSrc); + if (!tmpPath) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetBasePathName); + } + + char* newXMLString = new char [strlen(tmpPath) +2]; + ArrayJanitor<char> newJanitor(newXMLString); + strcpy(newXMLString, tmpPath); + strcat(newXMLString , "/"); + // Return a copy of the path, in Unicode format + return XMLString::transcode(newXMLString); +} + +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; +} + +// ----------------------------------------------------------------------- +// Standard out/error support +// ----------------------------------------------------------------------- + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStr(stderr, toWrite); +} +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStr(stdout, toWrite); +} + +// ----------------------------------------------------------------------- +// Mutex methods +// ----------------------------------------------------------------------- + +#ifndef APP_NO_THREADS +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_destroy( (pthread_mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotDestroy); + } + if ((pthread_mutex_t*)mtxHandle) + delete mtxHandle; +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_lock( (pthread_mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotLock); + } +} + +void* XMLPlatformUtils::makeMutex() +{ + pthread_mutex_t* mutex = new pthread_mutex_t; + + if (pthread_mutex_init(mutex, NULL)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotCreate); + } + return (void*)(mutex); +} + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_unlock( (pthread_mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotUnlock); + } +} + +#else // #ifndef APP_NO_THREADS + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ +} + +void* XMLPlatformUtils::makeMutex() +{ + return 0; +} + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ +} + +#endif // APP_NO_THREADS + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- +//atomic system calls in Solaris is only restricted to kernel libraries +//So, to make operations thread safe we implement static mutex and lock +//the atomic operations. It makes the process slow but what's the alternative! + +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , + const void* const toCompare) +{ + //return ((void*)cas32( (uint32_t*)toFill, (uint32_t)toCompare, (uint32_t)newValue) ); + // the below calls are temporarily made till the above functions are part of user library + // Currently its supported only in the kernel mode + + lockMutex(&atomicOpsMutex); + + void *retVal = *toFill; + if (*toFill == toCompare) + *toFill = (void *)newValue; + + unlockMutex(&atomicOpsMutex); + + return retVal; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +{ + //return (int)atomic_add_32_nv( (uint32_t*)&location, 1); + XMLMutexLock localLock(&atomicOpsMutex); + + return ++location; +} + +int XMLPlatformUtils::atomicDecrement(int &location) +{ + //return (int)atomic_add_32_nv( (uint32_t*)&location, -1); + XMLMutexLock localLock(&atomicOpsMutex); + + return --location; +} + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + return (FileHandle)fdopen(dup(0), "rb"); +} + diff --git a/src/util/Platforms/MacOS/MacOSDefs.hpp b/src/util/Platforms/MacOS/MacOSDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8a5d710f23297cd613ef5aa4462370d881f7d62c --- /dev/null +++ b/src/util/Platforms/MacOS/MacOSDefs.hpp @@ -0,0 +1,155 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:51 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:30 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// NOTE: +// +// XML4C is not officially supported on Macintosh. This file was sent +// in by one of the Macintosh users and is included in the distribution +// just for convenience. Please send any defects / modification +// reports to xml4c@us.ibm.com +// --------------------------------------------------------------------------- + + +#ifndef MACOS_DEFS_HPP +#define MACOS_DEFS_HPP + +#include <resources.h> + +class XMLMacAbstractFile +{ + public: + XMLMacAbstractFile() {} + virtual ~XMLMacAbstractFile() {} + + virtual unsigned int currPos() = 0; + virtual void close() = 0; + virtual unsigned int size() = 0; + virtual void open(const char* const) = 0; + virtual unsigned int read(const unsigned int, XMLByte* const) = 0; + virtual void reset() = 0; +}; + +class XMLMacFile : public XMLMacAbstractFile +{ + public: + XMLMacFile() : valid(0), fileRef(0) {} + virtual ~XMLMacFile(); + + unsigned int currPos(); + void close(); + unsigned int size(); + void open(const char* const); + unsigned int read(const unsigned int, XMLByte* const); + void reset(); + + protected: + short fileRef; + short valid; + unsigned char pStr[300]; +}; + +class XMLResFile : public XMLMacAbstractFile +{ + public: + XMLResFile() : valid(0), type(0), id(0), pos(0), len(0) {} + virtual ~XMLResFile(); + + unsigned int currPos(); + void close(); + unsigned int size(); + void open(const char* const); + unsigned int read(const unsigned int, XMLByte* const); + void reset(); + + protected: + short valid; + unsigned long type; + short id; + unsigned char name[300]; + Handle data; + long pos; + long len; +}; + + +// --------------------------------------------------------------------------- +// MacOS runs in big endian mode. +// --------------------------------------------------------------------------- +#define ENDIANMODE_BIG + + +// --------------------------------------------------------------------------- +// Define all the required platform types +// --------------------------------------------------------------------------- +typedef XMLMacAbstractFile* FileHandle; + + +int stricmp(const char *s1, const char *s2); +int strnicmp(const char *s1, const char *s2, int n); + +#endif diff --git a/src/util/Platforms/MacOS/MacOSPlatformUtils.cpp b/src/util/Platforms/MacOS/MacOSPlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..309c6f4897a7c0800ea362c460a68f55ce5fc059 --- /dev/null +++ b/src/util/Platforms/MacOS/MacOSPlatformUtils.cpp @@ -0,0 +1,854 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:55 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:30 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Note: +// XML4C is not officially supported on Macintosh. This file was sent +// in by one of the Macintosh users and is included in the distribution +// just for convenience. Please send any defects / modification +// reports to xml4c@us.ibm.com +// --------------------------------------------------------------------------- + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Janitor.hpp> +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/String.hpp> +#include <util/XMLUni.hpp> +#include <util/MacOSDefs.hpp> +#include <iostream.h> +#include <files.h> +#include <gestalt.h> +#include <traps.h> +#include <lowmem.h> +#include <Multiprocessing.h> +#include <string.h> +#include <stdlib.h> + + + +//---------------------------------------------------------------------------- +// Local Data +// +// gFileSystemReady +// This flag indicates if the file system is ready to be used. The only +// thing that might stop us is the absence of FSspec file manipulation +// routines in the OS. +// +// gGestaltAvail +// This flag indicates the presence of the gestalt manager. This version +// of the MacOS port can not run without it. +//---------------------------------------------------------------------------- +static const char *resBaseStr = "/Access The Resource Fork Instead of the data fork?"; +static bool gFileSystemReady = false; +static bool gGestaltAvail = false; +static MPCriticalRegionID gCriticalRegion; + + +//---------------------------------------------------------------------------- +// XMLResFile methods +//---------------------------------------------------------------------------- +XMLResFile::XMLResFile(); + + +void XMLResFile::open(const char* const resInfo) +{ + char option[32], value[32], command[70]; + int cmdEnd = 0, cmdStart = 0; + int optEnd = 0, sep; + int mode = -1; + int typeValid = 0; + + if (!strchr(&resInfo[cmdStart], '/')) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Malformed resource locater"); + + while(resInfo[cmdEnd] != '/') + { + if (strchr(&resInfo[cmdStart], '&') < strchr(&resInfo[cmdStart], '/') && strchr(&resInfo[cmdStart], '&') != 0) + cmdEnd = strchr(&resInfo[cmdStart], '&') - resInfo - 1; + else + cmdEnd = strchr(&resInfo[cmdStart], '/') - resInfo - 1; + + if (cmdEnd - cmdStart > 68) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- resource option too long (>68 chars)"); + + memcpy(command, &resInfo[cmdStart], cmdEnd - cmdStart + 1); + command[cmdEnd - cmdStart + 1] = 0; + if (!strchr(command, '=')) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Malformed resource locater"); + + sep = strchr(command, '=') - command; + memcpy(option, command, sep); + option[sep] = 0; + memcpy(value, &command[sep+1], strlen(command) - sep); + + if (!strcmp(option, "mode")) + { + if (!strcmp(value, "by_id")) + mode = 1; + else if (!strcmp(value, "by_id1")) + mode = 2; + else if (!strcmp(value, "by_name")) + mode = 3; + else if (!strcmp(value, "by_name1")) + mode = 4; + else + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- 'mode' has to be 'by_id' or 'by_id1' or 'by_name' or 'by_name1'"); + } + if (!strcmp(option, "type")) + { + if (strlen(value) != 4) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- 'type' has to be four characters long"); + typeValid = 1; + type = 0; + type += value[0] << 24; + type += value[1] << 16; + type += value[2] << 8; + type += value[3]; + } + + cmdStart = cmdEnd + 2; + cmdEnd++; + } + + if (mode == 0) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Malformed resource locater requires a 'mode'"); + if (typeValid == 0) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Malformed resource locater requires a 'type'"); + + switch(mode) + { + case 1: case 2: + id = atol(&resInfo[cmdEnd+1]); + if (mode == 1) + data = GetResource(type, id); + else + data = Get1Resource(type, id); + break; + + case 3: case 4: + if (strlen(&resInfo[cmdEnd]) >= 255) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Resource names have to be 255 characters or less"); + strcpy((char*)name, &resInfo[cmdEnd]); + name[0] = strlen((char*)&name[1]); + if (mode == 3) + data = GetNamedResource(type, name); + else + data = Get1NamedResource(type, name); + break; + } + + if (ResError() != noErr) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Error opening resource"); + + GetResInfo(data, &id, &type, name); + len = GetResourceSizeOnDisk(data); + if (ResError() != noErr) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Error loading resource info"); + + valid = 1; +} + +unsigned int XMLResFile::read(const unsigned int buffLen, XMLByte* const buff) +{ + unsigned int totAvail = len - pos; + unsigned int numRead = (buffLen >= totAvail) ? totAvail : buffLen; + + HLock(data); + memcpy(buff, *data, numRead); + HUnlock(data); + pos += numRead; + return numRead; +} + +void XMLResFile::close() +{ + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::curFilePos -- Not a valid file"); + ReleaseResource(data); + valid = 0; +} + +unsigned int XMLResFile::currPos() +{ + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::curFilePos -- Not a valid file"); + return pos; +} + +void XMLResFile::reset() +{ + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile -- Not a valid file"); + pos = 0; +} + +unsigned int XMLResFile::size() +{ + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize -- Not a valid file"); + return len; +} + +XMLResFile::~XMLResFile() +{ + if (valid) + close(); +} + +//---------------------------------------------------------------------------- +// XMLMacFile methods +//---------------------------------------------------------------------------- + +unsigned int XMLMacFile::currPos() +{ + long len; + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::curFilePos -- Not a valid file"); + if (noErr != GetFPos(fileRef, &len)) + throw XMLPlatformUtilsException("XMLPlatformUtils::curFilePos -- Error getting file position"); + return len; +} + +void XMLMacFile::close() +{ + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::closeFile -- Not a valid file"); + if (noErr != FSClose(fileRef)) + throw XMLPlatformUtilsException("XMLPlatformUtils::closeFile -- Error closing file"); + valid = 0; +} + +unsigned int XMLMacFile::size() +{ + long len; + + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize -- Not a valid file"); + if (noErr != GetEOF(fileRef, &len)) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize -- Error closing file"); + return len; +} + +void XMLMacFile::open(const char* const fileName) +{ + OSErr myErr; + + if (valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile -- Can't open the same file twice"); + if (strlen(fileName) > 255) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile(const char* const) -- File name too long (>255 chars)"); + + if (fileName[0] == '/') + { + strcpy((char*)&pStr[1], &fileName[1]); + pStr[0] = strlen(fileName) - 1; + pStr[strlen(fileName)] = 0; + } else { + strcpy((char*)&pStr[1], fileName); + pStr[0] = strlen(fileName); + pStr[strlen(fileName) + 1] = 0; + } + + for(int i = 1; i <= pStr[0]; i++) + if (pStr[i] == '/') + pStr[i] = ':'; + + myErr = HOpenDF(0, 0, pStr, fsRdWrPerm, &fileRef); + if (myErr != noErr) + { + cerr << myErr << endl; + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile(const char* const) -- Failed to open file."); + } + + valid = 1; +} + +unsigned int XMLMacFile::read(const unsigned int toRead, XMLByte* const toFill) +{ + long bytesRead = toRead; + + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::readFileBuff -- Not a valid file"); + if (noErr != FSRead(fileRef, &bytesRead, toFill)) + throw XMLPlatformUtilsException("XMLPlatformUtils::readFileBuffer - Read failed"); + return (unsigned int)bytesRead; +} + + +void XMLMacFile::reset() +{ + if (!valid) + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile -- Not a valid file"); + if (noErr != SetFPos(fileRef, fsFromStart, 0)) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize -- Error closing file"); +} + +XMLMacFile::~XMLMacFile() +{ + if (valid) + close(); +} + +// --------------------------------------------------------------------------- +// Local methods +// --------------------------------------------------------------------------- +static void WriteCharStrStdErr(const char* const toWrite) +{ + // Just print the data out the the MetroWerks standard error. + cerr << toWrite; +} + + +static void WriteCharStrStdOut(const char* const toWrite) +{ + // Just print the data out the the MetroWerks standard error. + cout << toWrite; +} + + +static void WriteUStrStdErr(const XMLCh* const toWrite) +{ + // Oh well, got to do it the hard way + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janTmp(tmpVal); + WriteCharStrStdErr(tmpVal); +} + + +static void WriteUStrStdOut(const XMLCh* const toWrite) +{ + // Oh well, got to do it the hard way + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janTmp(tmpVal); + WriteCharStrStdOut(tmpVal); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(const FileHandle theFile) +{ + return theFile->currPos(); +} + +void XMLPlatformUtils::closeFile(const FileHandle theFile) +{ + theFile->close(); +} + +unsigned int XMLPlatformUtils::fileSize(const FileHandle theFile) +{ + return theFile->size(); +} + +FileHandle XMLPlatformUtils::openFile(const char* const fileName) +{ + FileHandle file = 0; + int isRes = 0; + + // Check to make sure the file system is in a state where we can use it + if (!gFileSystemReady) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile(const char* const) -- File system not ready." + " Maybe missing gestalt or no support for FSSpec's."); + + if (strlen(fileName) >= strlen(resBaseStr)) + if (strstr(fileName, resBaseStr) == fileName) + isRes = 1; + + if (isRes == 0) + { + file = new XMLMacFile(); + file->open(fileName); + } + else + { + file = new XMLResFile(); + file->open(&fileName[strlen(resBaseStr)]); + } + if (file == 0) + throw XMLPlatformUtilsException("XMLPlatformUtils::openFile(const char* const) -- Failed to allocate file object."); + return file; +} + +FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName) +{ + char* tmpName = XMLString::transcode(fileName); + FileHandle retVal = openFile(tmpName); + delete [] tmpName; + + return retVal; +} + + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + throw XMLPlatformUtilsException("XMLPlatformUtils::openStdInHandle -- Standard input not supported on MacOS"); + return NULL;//(void*)&cin; +} + + +unsigned int +XMLPlatformUtils::readFileBuffer( const FileHandle theFile + , const unsigned int toRead + , XMLByte* const toFill) +{ + return theFile->read(toRead, toFill); +} + + +void XMLPlatformUtils::resetFile(FileHandle theFile) +{ + theFile->reset(); +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStrStdErr(toWrite); +} + +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} + +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStrStdOut(toWrite); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Platform methods +// --------------------------------------------------------------------------- +XMLCh* XMLPlatformUtils::getBasePath(const XMLCh* const srcPath) +{ + char* workingPath = XMLString::transcode(srcPath); + XMLCh *result; + char dirSep = '/', *lastSep = 0; + + for(int i = 0; workingPath && workingPath[i]; i++) + if (workingPath[i] == dirSep) + lastSep = &workingPath[i]; + + if (lastSep == 0) + return XMLString::transcode(""); + + lastSep++; + dirSep = *lastSep; + *lastSep = 0; +// cout << "Returning base path: " << workingPath << endl; + result = XMLString::transcode(workingPath); + *lastSep = dirSep; + delete [] workingPath; + + return result; +} + +bool XMLPlatformUtils::isRelative(const XMLCh* const toCheck) +{ + char* workingPath = XMLString::transcode(toCheck); + char dirSep = '/', *sep; + short refNum; + long freeSpace; + unsigned char volName[260]; + + if (!*workingPath) + return false; + + if (strstr(workingPath, ":")) + dirSep = ':'; + + if ( dirSep == '/' && workingPath[0] == '/') + return false; + if ( dirSep == '/' && workingPath[0] != '/') + return true; + + sep = strstr(workingPath, ":"); + if (sep == 0) + return true; + + dirSep = *sep; + *sep = 0; + + for(short i = 0; i < 7; i++) + { + if ( noErr == GetVInfo(i, volName, &refNum, &freeSpace)) + { + if (strlen(workingPath) != volName[0]) + continue; + + for(int j = 0, refNum = 0; j < volName[0]; j++) + if (workingPath[j] != volName[j+1]) + refNum = 1; + + if (!refNum) + { + *sep = dirSep; + delete [] workingPath; + return false; + } + } + } + *sep = dirSep; + delete [] workingPath; + return true; +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + return TickCount()*10; +} + + + +// --------------------------------------------------------------------------- +// Mutex methods +// --------------------------------------------------------------------------- +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (!MPLibraryIsLoaded()) + throw XMLPlatformUtilsException("XMLPlatformUtils::makeMutex -- Multiprocessing library not installed correctly. Please Install"); + + MPSemaphoreID *sema = (MPSemaphoreID*)mtxHandle; + if (!sema) return; + + if (noErr != MPDeleteSemaphore(*sema)) + throw XMLPlatformUtilsException("XMLPlatformUtils::closeMutex -- Error deleting semaphore"); +} + + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (!MPLibraryIsLoaded()) + throw XMLPlatformUtilsException("XMLPlatformUtils::makeMutex -- Multiprocessing library not installed correctly. Please Install"); + + MPSemaphoreID *sema = (MPSemaphoreID*)mtxHandle; + if (!sema) return; + + if (noErr != MPWaitOnSemaphore(*sema, -1)) + throw XMLPlatformUtilsException("XMLPlatformUtils::lockMutex -- Error locking semaphore"); +} + + +void* XMLPlatformUtils::makeMutex() +{ + if (!MPLibraryIsLoaded()) + throw XMLPlatformUtilsException("XMLPlatformUtils::makeMutex -- Multiprocessing library not installed correctly. Please Install"); + + MPSemaphoreID *result = new MPSemaphoreID; + if (!result) + throw XMLPlatformUtilsException("XMLPlatformUtils::makeMutex -- Error allocating memory for a semaphore"); + + if (noErr != MPCreateBinarySemaphore(result)) + throw XMLPlatformUtilsException("XMLPlatformUtils::makeMutex -- Error Creating semaphore"); + + return (void*)result; +} + + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (!MPLibraryIsLoaded()) + throw XMLPlatformUtilsException("XMLPlatformUtils::makeMutex -- Multiprocessing library not installed correctly. Please Install"); + + MPSemaphoreID *sema = (MPSemaphoreID*)mtxHandle; + if (!sema) return; + + if (noErr != MPSignalSemaphore(*sema)) + throw XMLPlatformUtilsException("XMLPlatformUtils::unlockMutex -- Error unlocking semaphore"); +} + + +// --------------------------------------------------------------------------- +// Miscellaneous synchronization methods +// --------------------------------------------------------------------------- +void* +XMLPlatformUtils::compareAndSwap( void** toFill + , const void* const newValue + , const void* const toCompare) +{ + // Note -- I'm note sure what this method is supposed to do. I just copied + // the code from the linux utils. + + void *retVal = *toFill; + if (*toFill == toCompare) + *toFill = (void *)newValue; + return retVal; + + throw XMLPlatformUtilsException("XMLPlatformUtils::compareAndSwap -- Not Implemented Yet."); +} + + +int XMLPlatformUtils::atomicIncrement(int &location) +{ +/* if (!MPLibraryIsLoaded()) + throw XMLPlatformUtilsException("XMLPlatformUtils::platformInit -- Multiprocessing library not installed correctly. Please Install"); + + if (noErr != MPEnterCriticalRegion(gCriticalRegion, -1)) + throw XMLPlatformUtilsException("XMLPlatformUtils::atomicIncrement -- Failed to enter the critical region.");*/ + + int result = location++; + +/* if (noErr != MPExitCriticalRegion(gCriticalRegion)) + throw XMLPlatformUtilsException("XMLPlatformUtils::atomicIncrement -- Failed to exit the critical region.");*/ + + return result; +} + + +int XMLPlatformUtils::atomicDecrement(int &location) +{ +/* if (!MPLibraryIsLoaded()) + throw XMLPlatformUtilsException("XMLPlatformUtils::platformInit -- Multiprocessing library not installed correctly. Please Install"); + + if (noErr != MPEnterCriticalRegion(gCriticalRegion, -1)) + throw XMLPlatformUtilsException("XMLPlatformUtils::atomicIncrement -- Failed to enter the critical region.");*/ + + int result = location--; + +/* if (noErr != MPExitCriticalRegion(gCriticalRegion)) + throw XMLPlatformUtilsException("XMLPlatformUtils::atomicIncrement -- Failed to exit the critical region.");*/ + + return result; +} + +// Routine to check to see if a system function is available +static bool MySWRoutineAvailable (int trapWord) +{ + TrapType trType; + + // first determine whether it is an Operating System or Toolbox routine + if ((trapWord & 0x0800) == 0) + trType = OSTrap; + else + trType = ToolTrap; + + // filter cases where older systems mask with 0x1FF rather than 0x3FF + if (trType == ToolTrap && ((trapWord & 0x03FF) >= 0x200) && + (GetToolboxTrapAddress(0xA86E) == GetToolboxTrapAddress(0xAA6E))) + return false; + else + return (NGetTrapAddress(trapWord, trType) != + GetToolboxTrapAddress(_Unimplemented)); +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Private Static Methods +// --------------------------------------------------------------------------- + +// +// This method handles the MacOS basic init functions. +// +void XMLPlatformUtils::platformInit() +{ + OSErr myErr; + long feature; + + // Figure out if we have the gestalt manager + gGestaltAvail = MySWRoutineAvailable(_Gestalt); + + // Figure out if we have the FSspec function to use + if (gGestaltAvail) + { + myErr = Gestalt(gestaltFSAttr, &feature); + if (myErr == noErr) + { + if (feature & gestaltHasFSSpecCalls) + gFileSystemReady = true; + } + } + +/* if (!MPLibraryIsLoaded()) + throw XMLPlatformUtilsException("XMLPlatformUtils::platformInit -- Multiprocessing library not installed correctly. Please Install"); + + if (noErr != MPCreateCriticalRegion(&gCriticalRegion)) + throw XMLPlatformUtilsException("XMLPlatformUtils::platformInit -- Error creating critical section");*/ +} + +// +// This is the first thing called during init. Each platform needs to set +// up the path to the Internationalization code. +// +// NOTE: It CANNOT use an String class methods, because that class has not +// be set up yet. +// +void XMLPlatformUtils::setupIntlPath() +{ +// fgIntlPath = "Macintosh HD:Desktop Folder:xml4csrc2_2_0:intlFiles:data:locales:"; + short fileRef; + unsigned char pStr[300]; + OSErr myErr; + OSType textCode = 'TEXT'; +// StandardFileReply result; +// FInfo fileInfo; + long feature; + + if (fgIntlPath != 0) + return; + + // Figure out if we have the gestalt manager + gGestaltAvail = MySWRoutineAvailable(_Gestalt); + + // Figure out if we have the FSspec function to use + if (gGestaltAvail) + { + myErr = Gestalt(gestaltFSAttr, &feature); + if (myErr == noErr) + { + if (feature & gestaltHasFSSpecCalls) + gFileSystemReady = true; + } + } + + // Check to make sure the file system is in a state where we can use it + if (!gFileSystemReady) + throw XMLPlatformUtilsException("XMLPlatformUtils::setupIntlPath -- File system not ready." + " Maybe missing gestalt or no support for FSSpec's."); + + if (noErr == HOpenDF(0, 0, "\p:locales:convrtrs.txt", fsRdWrPerm, &fileRef)) + { + if (noErr != FSClose(fileRef)) + throw XMLPlatformUtilsException("XMLPlatformUtils::setupIntlPath -- ERROR"); + + fgIntlPath = ":locales:"; + return; + } + + throw XMLPlatformUtilsException("XMLPlatformUtils::setupIntlPath -- Couldn't find data files"); +/* if (noErr != StandardGetFile("\pPlease locate the convrtrs.txt file in the locales directory:", 0, 1, &textCode, &result)) + throw XMLPlatformUtilsException("XMLPlatformUtils::setupIntlPath -- StandardGetFile failed"); + + if (result.sfGood == 0) + throw XMLPlatformUtilsException("XMLPlatformUtils::setupIntlPath -- failed to locate locale files"); + + fgIntlPath = new char[result.sfFile.[0]+1]; + fgIntlPath[result.sfFile.[0]] = 0; + memcpy(fgIntlPath, result.sfFile., result.sfFile.[0]); + cout << fgIntlPath << endl;*/ + //throw XMLPlatformUtilsException("XMLPlatformUtils::setupIntlPath -- failed to load file info"); +} + +// These functions are needed because MacOS doesn't define them +// even though they are used. +// Compare lexigraphically two strings +static char tolower(char c) +{ + if (c >= 'A' && c <= 'Z') + return c + 'a' - 'A'; + return c; +} + +int stricmp(const char *s1, const char *s2) +{ + char c1, c2; + while (1) + { + c1 = tolower(*s1++); + c2 = tolower(*s2++); + if (c1 < c2) return -1; + if (c1 > c2) return 1; + if (c1 == 0) return 0; + } +} + +// Compare lexigraphically two strings up to a max length + +int strnicmp(const char *s1, const char *s2, int n) +{ + int i; + char c1, c2; + for (i=0; i<n; i++) + { + c1 = tolower(*s1++); + c2 = tolower(*s2++); + if (c1 < c2) return -1; + if (c1 > c2) return 1; + if (!c1) return 0; + } + return 0; +} + diff --git a/src/util/Platforms/Makefile.in b/src/util/Platforms/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..d424ad95bdc6654a381a38a4d81965a3d856ebbc --- /dev/null +++ b/src/util/Platforms/Makefile.in @@ -0,0 +1,109 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:06:14 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:28 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util + +include ../../Makefile.incl + +ifeq (${PLATFORM}, SOLARIS) + SUBMODULE = Platforms/Solaris + CPP_PUBHEADERS = Solaris/SolarisDefs.hpp + CPP_OBJECTS = Solaris/SolarisPlatformUtils.o +endif +ifeq (${PLATFORM}, AIX) + SUBMODULE = Platforms/AIX + CPP_PUBHEADERS = AIX/AIXDefs.hpp + CPP_OBJECTS = AIX/AIXPlatformUtils.o +endif +ifeq (${PLATFORM}, LINUX) + SUBMODULE = Platforms/Linux + CPP_PUBHEADERS = Linux/LinuxDefs.hpp + CPP_OBJECTS = Linux/LinuxPlatformUtils.o +endif +ifeq (${PLATFORM}, HPUX) + SUBMODULE = Platforms/HPUX + CPP_PUBHEADERS = HPUX/HPUXDefs.hpp + CPP_OBJECTS = HPUX/HPPlatformUtils.o +endif +ifeq (${PLATFORM}, OS390) + SUBMODULE = Platforms/OS390 + CPP_PUBHEADERS = OS390/OS390Defs.hpp + CPP_OBJECTS = OS390/OS390PlatformUtils.o +endif + +include ../Makefile.util.submodule + diff --git a/src/util/Platforms/OS2/OS2Defs.hpp b/src/util/Platforms/OS2/OS2Defs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b29034809f9a4176bf2cd68976b5f22349f1fd95 --- /dev/null +++ b/src/util/Platforms/OS2/OS2Defs.hpp @@ -0,0 +1,77 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:42 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:31 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// OS2 always run the CPU in little endian mode. +// --------------------------------------------------------------------------- +#define ENDIANMODE_LITTLE + + +// --------------------------------------------------------------------------- +// Define all the required platform types +// --------------------------------------------------------------------------- +typedef void* FileHandle; diff --git a/src/util/Platforms/OS2/OS2PlatformUtils.cpp b/src/util/Platforms/OS2/OS2PlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2124a6f4e085381d81e0ae223e00cbb4ddf968ed --- /dev/null +++ b/src/util/Platforms/OS2/OS2PlatformUtils.cpp @@ -0,0 +1,561 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:44 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:31 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#ifndef APP_NO_THREADS +#endif + +#define INCL_DOSSEMAPHORES +#define INCL_DOSERRORS +#define INCL_DOSMISC + +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/Janitor.hpp> +#include <util/XML4CDefs.hpp> +#include <stdio.h> +#include <stdlib.h> +#include <IO.h> +#include <OS2.h> + + + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- +static void WriteCharStr( FILE* stream, const char* const toWrite) +{ + if (!fputs(toWrite, stream)) + { + throw XMLPlatformUtilsException("Could not write to standard out/err"); + } +} + +static void WriteUStrStdErr( const XMLCh* const toWrite) +{ + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janText(tmpVal); + if (!fputs(tmpVal, stderr)) + { + throw XMLPlatformUtilsException("Could not write to standard error file"); + } +} + +static void WriteUStrStdOut( const XMLCh* const toWrite) +{ + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janText(tmpVal); + if (!fputs(tmpVal, stdout)) + { + throw XMLPlatformUtilsException("Could not write to standard out file"); + } +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Platform init method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::platformInit() +{ +} + + +void XMLPlatformUtils::setupIntlPath() +{ + // + // We need to figure out the path to the Intl classes. They will be + // in the .\Intl subdirectory under this DLL. + // + + static const char * xml4cIntlDirEnvVar = "XML4C2INTLDIR"; + static const char * sharedLibEnvVar = "LIBPATH"; + + char* envVal = getenv(xml4cIntlDirEnvVar); + //check if environment variable is set + if (envVal != NULL) + { + // Store this string in the static member + unsigned int pathLen = strlen(envVal); + fgIntlPath = new char[pathLen + 2]; + + strcpy((char *) fgIntlPath, envVal); + if (envVal[pathLen - 1] != '/') + { + strcat((char *) fgIntlPath, "/"); + } + return; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + + char libName[256]; + strcpy(libName, XML4C2_DLLName); + strcat(libName, gXML4C2VersionStr); + strcat(libName, ".a"); + + char* libEnvVar = getenv(sharedLibEnvVar); + char* libPath = NULL; + + if (libEnvVar == NULL) + { + fprintf(stderr, + "Error: Could not locate i18n converter files.\n"); + fprintf(stderr, + "Environment variable '%s' is not defined.\n", sharedLibEnvVar); + fprintf(stderr, + "Environment variable 'XML4C2INTLDIR' is also not defined.\n"); + exit(-1); + } + + // + // Its necessary to create a copy because strtok() modifies the + // string as it returns tokens. We don't want to modify the string + // returned to by getenv(). + // + + libPath = new char[strlen(libEnvVar) + 1]; + strcpy(libPath, libEnvVar); + + //First do the searching process for the first directory listing + // + char* allPaths = libPath; + char* libPathName; + + while ((libPathName = strtok(allPaths, ":")) != NULL) + { + FILE* dummyFptr = 0; + allPaths = 0; + + char* libfile = new char[strlen(libPathName) + strlen(libName) + 2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + dummyFptr = (FILE *) fopen(libfile, "rb"); + delete [] libfile; + if (dummyFptr != NULL) + { + fclose(dummyFptr); + fgIntlPath = + new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) fgIntlPath, libPathName); + strcat((char *) fgIntlPath, "/icu/data/"); + break; + } + + } // while + + delete libPath; + + if (fgIntlPath == NULL) + { + fprintf(stderr, + "Could not find %s in %s for auto locating the converter files.\n", + libName, sharedLibEnvVar); + fprintf(stderr, + "And the environment variable 'XML4C2INTLDIR' not defined.\n"); + exit(-1); + } +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + int curPos = ftell( (FILE*)theFile); + if (curPos == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::curFilePos - Could not get current pos"); + + return (unsigned int)curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*)theFile)) + throw XMLPlatformUtilsException("XMLPlatformUtils::closeFile - Could not close the file handle"); +} + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*)theFile); + if (curPos == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not get current pos"); + + // Seek to the end and save that value for return + if (fseek( (FILE*)theFile, 0, SEEK_END) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not seek to end"); + + long int retVal = ftell( (FILE*)theFile); + if (retVal == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not get the file size"); + + // And put the pointer back + if (fseek( (FILE*)theFile, curPos, SEEK_SET) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not seek back to original pos"); + + return (unsigned int)retVal; +} + +FileHandle XMLPlatformUtils::openFile(const unsigned short* 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; +} + +unsigned int +XMLPlatformUtils::readFileBuffer( FileHandle theFile + , const unsigned int toRead + , XMLByte* const toFill) +// TBT +{ + size_t noOfItemsRead = fread( (void*) toFill, 1, toRead, (FILE*)theFile); + + if(ferror((FILE*)theFile)) + { + throw XMLPlatformUtilsException("XMLPlatformUtils::readFileBuffer - Read failed"); + } + + return (unsigned int)noOfItemsRead; +} + + +void XMLPlatformUtils::resetFile(FileHandle theFile) +// TBT +{ + // Seek to the start of the file + if (fseek((FILE*)theFile, 0, SEEK_SET) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile - Could not seek to beginning"); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- +unsigned long XMLPlatformUtils::getCurrentMillis() +// TBT +{ + APIRET retr; + ULONG timerBuf = 0; + + retr = DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, (PVOID) &timerBuf, + sizeof( ULONG ) ); + if ( retr != NO_ERROR ) + return (timerBuf); + + + return (timerBuf); +} + + +/* Function dirname (used in XMLPlatformUtils::getBasePath) +* +* Description: +* Function returns directoryname +* +* In: +* Path and file: e.gG.: "d:\TestDir\testfile.txt +* +* return: +* "": ERROR +* Path: Path is returned in the Format: "[drive]:\[path]\" +* e.g.: "d:\TestDir\" +* +*/ +char* dirname(char* PathName) +// TBT +// new function +{ + APIRET rc = NO_ERROR; + ULONG MaxPathLength = 0; + ULONG aulSysInfo[QSV_MAX]; + + // variables for path information + char drive[2 + 1]; // eg: drive = "d:\n"; + + // get system information + rc = DosQuerySysInfo(1L, + QSV_MAX, + (PVOID)aulSysInfo, + sizeof(ULONG)*QSV_MAX); + if(rc != NO_ERROR) return(""); + + // Get Maximum Path Length + MaxPathLength = aulSysInfo[QSV_MAX_PATH_LENGTH - 1]; + + // allocate space for pathinformation + char* dir = new char[MaxPathLength + 1]; + char* fname = new char[MaxPathLength + 1]; + char* ext = new char[MaxPathLength + 1]; + char* returnPath = new char[MaxPathLength + 1]; + + // extract pathinformation + _splitpath(PathName, drive, dir, fname, ext) ; + + strcpy(returnPath,drive); + strcat(returnPath,dir); + + return((char*) returnPath); +} + +XMLCh* XMLPlatformUtils::getBasePath(const XMLCh* const srcPath) +// TBT +// So please check if it works correct. +{ + + // + // 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* tmpPath = dirname((char*)newSrc); + if (strlen(tmpPath) == 0) + { + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile - Could not get the base path name"); + } + + char* newXMLString = new char [strlen(tmpPath) +2]; + ArrayJanitor<char> newJanitor(newXMLString); + strcpy(newXMLString, tmpPath); + // TBT + + // Return a copy of the path, in Unicode format + return XMLString::transcode(newXMLString); +} + +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; +} + +// ----------------------------------------------------------------------- +// Standard out/error support +// ----------------------------------------------------------------------- + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStr(stderr, toWrite); +} +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStr(stdout, toWrite); +} + + +// ----------------------------------------------------------------------- +// Mutex methods +// Base of Mutex handling is copied from Win32PlatformUtil.cpp and +// patially from AIXPlatformUtil.cpp +// (depended on which code was easier to understand) +// ----------------------------------------------------------------------- +#ifndef APP_NO_THREADS + + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +// TBT +{ + if (mtxHandle == NULL) + return; + + if (DosCloseMutexSem( (HMTX)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not destroy a mutex"); + } +} + + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +// +{ + if (mtxHandle == NULL) + return; + + if (DosRequestMutexSem( (HMTX)mtxHandle,(ULONG) SEM_INDEFINITE_WAIT) ) + { + throw XMLPlatformUtilsException("Could not lock a mutex"); + } +} + + +void* XMLPlatformUtils::makeMutex() +// +{ + HMTX hRet; // Mutex Handle + + if (DosCreateMutexSem(NULL, &hRet, 0, FALSE)) + throw XMLPlatformUtilsException("XMLPlatformUtils::makeMutex - Could not create mutex"); + return (void*)hRet; +} + + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +// +{ + if (mtxHandle == NULL) + return; + + if (DosReleaseMutexSem( (HMTX)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not unlock a mutex"); + } +} + +#else // #ifndef APP_NO_THREADS + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ +} + +void* XMLPlatformUtils::makeMutex() +{ + return 0; +} + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ +} + +#endif // APP_NO_THREADS + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , + const void* const toCompare) +// TBT +// +{ + void *retVal = *toFill; + if (*toFill == toCompare) + *toFill = (void *)newValue; + return retVal; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +// TBT +// +{ + return ++location; +} +int XMLPlatformUtils::atomicDecrement(int &location) +// TBT +// +{ + return --location; +} + + +FileHandle XMLPlatformUtils::openStdInHandle() +// TBT +{ + return (FileHandle)fdopen(dup(0), "rb"); +} + diff --git a/src/util/Platforms/OS2/os2ilck.asm b/src/util/Platforms/OS2/os2ilck.asm new file mode 100644 index 0000000000000000000000000000000000000000..1815f173d4febb6cbf82b688314d49e35ae7db56 --- /dev/null +++ b/src/util/Platforms/OS2/os2ilck.asm @@ -0,0 +1,37 @@ + title os2ilck.asm + .486 + +CODE32 segment dword use32 public 'CODE' +CODE32 ends +DATA32 segment dword use32 public 'DATA' +DATA32 ends +DGROUP group DATA32 + assume cs:FLAT, ds:FLAT, ss:FLAT, es:FLAT +CODE32 segment + align 04h +os2InterlockedCompareExchange proc + mov ecx, [esp+4] + mov edx, [esp+8] + mov eax, [esp+12] + lock cmpxchg [ecx], edx + ret +os2InterlockedCompareExchange endp + align 04h +os2InterlockedIncrement proc + mov eax,[esp+4] + lock inc dword ptr[eax] + ret +os2InterlockedIncrement endp + align 04h +os2InterlockedDecrement proc + mov eax,[esp+4] + lock dec dword ptr[eax] + ret +os2InterlockedDecrement endp + +public os2InterlockedCompareExchange +public os2InterlockedIncrement +public os2InterlockedDecrement +CODE32 ends +end + diff --git a/src/util/Platforms/OS390/OS390Defs.hpp b/src/util/Platforms/OS390/OS390Defs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..83ed8ed1cb991cd76d331504c3e3ed37d2ec2d3f --- /dev/null +++ b/src/util/Platforms/OS390/OS390Defs.hpp @@ -0,0 +1,73 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:36 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:31 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// OS390OE runs in big endian mode +// --------------------------------------------------------------------------- +#define ENDIANMODE_BIG +typedef void* FileHandle; + diff --git a/src/util/Platforms/OS390/OS390PlatformUtils.cpp b/src/util/Platforms/OS390/OS390PlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ee3a1d266fbb7593ab3476a1b1ce18c37d981f37 --- /dev/null +++ b/src/util/Platforms/OS390/OS390PlatformUtils.cpp @@ -0,0 +1,700 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:38 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:31 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#ifndef APP_NO_THREADS +#include <pthread.h> +#endif + +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/Janitor.hpp> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <libgen.h> +#include <sys/timeb.h> +#include <string.h> +#include <unistd.h> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> + +#include <util/Transcoders/ICU/ICUTransService.hpp> +#include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> + +#ifdef OS390BATCH +static const char CONVERTER_BINARY_FILE_DDNAME[11] = "DD:ICUDATA"; +#endif + + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- +static void WriteCharStr( FILE* stream, const char* const toWrite) +{ + if (!fputs(toWrite, stream)) + { + throw XMLPlatformUtilsException("Could not write to standard out/err"); + } +} + +static void WriteUStrStdErr( const XMLCh* const toWrite) +{ + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janText(tmpVal); + if (!fputs(tmpVal, stderr)) + { + throw XMLPlatformUtilsException("Could not write to standard error file"); + } +} + +static void WriteUStrStdOut( const XMLCh* const toWrite) +{ + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janText(tmpVal); + + if (!fputs(tmpVal, stdout)) + { + throw XMLPlatformUtilsException("Could not write to standard out file"); + } +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Platform init method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::platformInit() +{ +} + +// --------------------------------------------------------------------------- +// 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. +// In our case, we use the ICU based message loader mechanism. +// +XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) +{ + XMLMsgLoader* retVal; + try + { + retVal = new InMemMsgLoader(msgDomain); + } + + catch(...) + { + panic( XMLPlatformUtils::Panic_NoDefTranscoder ); + } + 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() +{ + // + // We need to figure out the path to the Intl classes. They will be + // in the ./Intl subdirectory under this DLL. + // +#ifdef OS390BATCH + // Unless POSIX(ON) is specified and OS/390 USS is configured,there is + // no environment variable support in an OS/390 Batch environment. + // We will define a DD name - ICUDATA for accessing the Intl classes + + static const char * BatchIntlDir = CONVERTER_BINARY_FILE_DDNAME; + unsigned int pathLen = strlen(BatchIntlDir); + fgIntlPath = new char[pathLen + 2]; + + strcpy((char *) fgIntlPath, BatchIntlDir); + return new ICUTransService; +#else + + static const char * xml4cIntlDirEnvVar = "ICU_DATA"; + static const char * sharedLibEnvVar = "LIBPATH"; + static const char * intlPath = 0; + + char* envVal = getenv(xml4cIntlDirEnvVar); + //check if environment variable is set + if (envVal != NULL) // We have found an environment variable + { + // Store this string in the static member + unsigned int pathLen = strlen(envVal); + intlPath = new char[pathLen + 2]; + + strcpy((char *) intlPath, envVal); + if (envVal[pathLen - 1] != '/') + { + strcat((char *) intlPath, "/"); + } + + ICUTransService::setICUPath(intlPath); + if (intlPath != NULL) delete intlPath; + + return new ICUTransService; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + + char libName[256]; + strcpy(libName, XML4C_DLLName); + + // --- NOT USED BY MVS --- + // strcat(libName, gXML4CVersionStr); + // strcat(libName, ".so"); + + char* libEnvVar = getenv(sharedLibEnvVar); + char* libPath = NULL; + + if (libEnvVar == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } + + // + // Its necessary to create a copy because strtok() modifies the + // string as it returns tokens. We don't want to modify the string + // returned to by getenv(). + // + + libPath = new char[strlen(libEnvVar) + 1]; + strcpy(libPath, libEnvVar); + + //First do the searching process for the first directory listing + char* allPaths = libPath; + char* libPathName; + + while ((libPathName = strtok(allPaths, ":")) != NULL) + { + FILE* dummyFptr = 0; + allPaths = 0; + + char* libfile = new char[strlen(libPathName) + strlen(libName) + 2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + dummyFptr = (FILE *) fopen(libfile, "rb"); + delete [] libfile; + if (dummyFptr != NULL) + { + fclose(dummyFptr); + intlPath = new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) intlPath, libPathName); + strcat((char *) intlPath, "/icu/data/"); + break; + } + + } // while + + delete libPath; + + ICUTransService::setICUPath(intlPath); + + if (intlPath == NULL) + { + panic( XMLPlatformUtils::Panic_NoTransService ); + } + if (intlPath != NULL) delete intlPath; + + return new ICUTransService; +#endif +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: The panic method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::panic(const PanicReasons reason) +{ + // + // We just print a message and exit + // + printf("The XML4C system could not be initialized.\n"); + printf("The most likely reason for this failure is the inability to find\n"); + printf("the international encoding files. By default, the encoding files\n"); + printf("have the extension .cnv and exist in a directory icu/data relative\n"); + printf("to the XML4C shared library. If you have kept the converter files\n"); + printf("in a different location, you need to set up an environment variable\n"); + printf("called ICU_DATA which directly points to the directory where the\n"); + printf("encoding files are kept.\n"); + + exit(-1); +} + + +/*********************** THE OLD IMPLEMENTATION ********************** +*************** DELETE THIS CHUNK WHEN NEW ONE STARTS WORKING ********* + +void XMLPlatformUtils::setupIntlPath() +{ + // + // We need to figure out the path to the Intl classes. They will be + // in the .\Intl subdirectory under this DLL. + // + +#ifdef OS390BATCH + // Unless POSIX(ON) is specified and OS/390 USS is configured,there is + // no environment variable support in an OS/390 Batch environment. + // We will define a DD name - ICUDATA for accessing the Intl classes + + static const char * BatchIntlDir = CONVERTER_BINARY_FILE_DDNAME; + unsigned int pathLen = strlen(BatchIntlDir); + fgIntlPath = new char[pathLen + 2]; + + strcpy((char *) fgIntlPath, BatchIntlDir); + return; +#else + static const char * xml4cIntlDirEnvVar = "ICU_DATA"; + static const char * sharedLibEnvVar = "LIBPATH"; + + char* envVal = getenv(xml4cIntlDirEnvVar); + //check if environment variable is set + if (envVal != NULL) + { + // Store this string in the static member + unsigned int pathLen = strlen(envVal); + fgIntlPath = new char[pathLen + 2]; + + strcpy((char *) fgIntlPath, envVal); + if (envVal[pathLen - 1] != '/') + { + strcat((char *) fgIntlPath, "/"); + } + return; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + + char libName[256]; + strcpy(libName, XML4C2_DLLName); + // -- NOT USED BY MVS -- + //strcat(libName, gXML4C2VersionStr); + //strcat(libName, ".a"); + // --------------------- + + char* libEnvVar = getenv(sharedLibEnvVar); + char* libPath = NULL; + + if (libEnvVar == NULL) + { + fprintf(stderr, + "Error: Could not locate i18n converter files.\n"); + fprintf(stderr, + "Environment variable '%s' is not defined.\n", sharedLibEnvVar); + fprintf(stderr, + "Environment variable 'ICU_DATA' is also not defined.\n"); + exit(-1); + } + + // + // Its necessary to create a copy because strtok() modifies the + // string as it returns tokens. We don't want to modify the string + // returned to by getenv(). + // + + libPath = new char[strlen(libEnvVar) + 1]; + strcpy(libPath, libEnvVar); + + //First do the searching process for the first directory listing + // + char* allPaths = libPath; + char* libPathName; + + while ((libPathName = strtok(allPaths, ":")) != NULL) + { + FILE* dummyFptr = 0; + allPaths = 0; + + char* libfile = new char[strlen(libPathName) + strlen(libName) + 2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + dummyFptr = (FILE *) fopen(libfile, "rb"); + delete [] libfile; + if (dummyFptr != NULL) + { + fclose(dummyFptr); + fgIntlPath = + new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) fgIntlPath, libPathName); + strcat((char *) fgIntlPath, "/icu/data/"); + break; + } + + } // while + + delete libPath; + + if (fgIntlPath == NULL) + { + fprintf(stderr, + "Could not find %s in %s for auto locating the converter files.\n", + libName, sharedLibEnvVar); + fprintf(stderr, + "And the environment variable 'ICU_DATA' not defined.\n"); + exit(-1); + } +#endif +} + +***************** END OLD IMPLEMENTATION ******************/ + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + int curPos = ftell( (FILE*)theFile); + if (curPos == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::curFilePos - Could not get current pos"); + + return (unsigned int)curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*)theFile)) + throw XMLPlatformUtilsException("XMLPlatformUtils::closeFile - Could not close the file handle"); +} + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*)theFile); + if (curPos == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not get current pos"); + + // Seek to the end and save that value for return + if (fseek( (FILE*)theFile, 0, SEEK_END) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not seek to end"); + + long int retVal = ftell( (FILE*)theFile); + if (retVal == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not get the file size"); + + // And put the pointer back + if (fseek( (FILE*)theFile, curPos, SEEK_SET) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not seek back to original pos"); + + return (unsigned int)retVal; +} + +FileHandle XMLPlatformUtils::openFile(const unsigned short* 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; +} + +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)) + { + throw XMLPlatformUtilsException("XMLPlatformUtils::readFileBuffer - Read failed"); + } + + return (unsigned int)noOfItemsRead; +} + + +void XMLPlatformUtils::resetFile(FileHandle theFile) +{ + // Seek to the start of the file + if (fseek((FILE*)theFile, 0, SEEK_SET) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile - Could not seek to beginning"); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + timeb aTime; + ftime(&aTime); + return (unsigned long)(aTime.time*1000 + aTime.millitm); + +} + + + +XMLCh* XMLPlatformUtils::getBasePath(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* tmpPath = dirname((char*)newSrc); + if (!tmpPath) + { + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile - Could not get the base path name"); + } + + char* newXMLString = new char [strlen(tmpPath) +2]; + ArrayJanitor<char> newJanitor(newXMLString); +#ifdef OS390BATCH + // Set it to NULL if the "DD:" convention is used + if (strncmp(newSrc, "DD:", 3)) + { + strcpy(newXMLString, tmpPath); + strcat(newXMLString , "/"); + } + else + strcpy(newXMLString, ""); +#else + strcpy(newXMLString, tmpPath); + strcat(newXMLString , "/"); +#endif + // Return a copy of the path, in Unicode format + return XMLString::transcode(newXMLString); +} +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; +} + +// ----------------------------------------------------------------------- +// Standard out/error support +// ----------------------------------------------------------------------- + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStr(stderr, toWrite); +} +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStr(stdout, toWrite); +} + + +// ----------------------------------------------------------------------- +// Mutex methods +// ----------------------------------------------------------------------- +#ifndef APP_NO_THREADS +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_destroy( (pthread_mutex_t*)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not destroy a mutex"); + } + if ( (pthread_mutex_t*)mtxHandle) + delete mtxHandle; +} +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_lock( (pthread_mutex_t*)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not lock a mutex"); + } + +} +void* XMLPlatformUtils::makeMutex() +{ + pthread_mutex_t* mutex = new pthread_mutex_t; + if (mutex == NULL) + { + throw XMLPlatformUtilsException("Could not initialize a mutex"); + } + + if (pthread_mutex_init(mutex, NULL)) + { + throw XMLPlatformUtilsException("Could not create a mutex"); + } + + return (void*)(mutex); +} +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_unlock( (pthread_mutex_t*)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not unlock a mutex"); + } +} + +#else // #ifndef APP_NO_THREADS + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ +} + +void* XMLPlatformUtils::makeMutex() +{ + return 0; +} + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ +} + +#endif // APP_NO_THREADS + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , + const void* const toCompare) +{ + int boolVar = cs( (cs_t*) &toCompare, (cs_t*) toFill, (cs_t) newValue ); + return (void*) toCompare; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +{ + int newVal, oldVal = location; + + do { + newVal = oldVal + 1; + oldVal = (int) compareAndSwap( (void**) &location, (void*) newVal, (void*) oldVal ); + } while( newVal != oldVal + 1 ); + + return newVal; +} +int XMLPlatformUtils::atomicDecrement(int &location) +{ + int newVal, oldVal = location; + + do { + newVal = oldVal - 1; + oldVal = (int) compareAndSwap( (void**) &location, (void*) newVal, (void*) oldVal ); + } while( newVal != oldVal - 1 ); + + return newVal; +} + + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + return (FileHandle)fdopen(dup(0), "rb"); +} + diff --git a/src/util/Platforms/Solaris/SolarisDefs.hpp b/src/util/Platforms/Solaris/SolarisDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..136cde0729fe3ad74fa984a8e6c14c8bf38a1bdd --- /dev/null +++ b/src/util/Platforms/Solaris/SolarisDefs.hpp @@ -0,0 +1,77 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:30 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:32 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// AIX runs in big endian mode +// --------------------------------------------------------------------------- +#define ENDIANMODE_BIG +typedef void* FileHandle; + +#ifndef SOLARIS +#define SOLARIS +#endif + diff --git a/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp b/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..851e85de30d0bd95a914b3e0a57b9b813ce18918 --- /dev/null +++ b/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp @@ -0,0 +1,640 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:31 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:32 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- + +#if !defined (APP_NO_THREADS) +#include <thread.h> +#endif // APP_NO_THREADS + + +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <libgen.h> +#include <sys/timeb.h> +#include <string.h> +#include <link.h> +#include <dlfcn.h> +#include <util/Janitor.hpp> +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/Mutexes.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> + +#if defined (XML_USE_ICU_TRANSCODER) + #include <util/Transcoders/ICU/ICUTransService.hpp> +#else // use native transcoder + #include <util/Transcoders/Iconv/IconvTransService.hpp> +#endif + +#if defined (XML_USE_ICU_MESSAGELOADER) + #include <util/MsgLoaders/ICU/ICUMsgLoader.hpp> +#elif defined (XML_USE_ICONV_MESSAGELOADER) + #include <util/MsgLoaders/MsgCatalog/MsgCatalogLoader.hpp> +#else // use In-memory message loader + #include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> +#endif + + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- +static void WriteCharStr( FILE* stream, const char* const toWrite) +{ + if (fputs(toWrite, stream) == EOF) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::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, + XML4CExcepts::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, + XML4CExcepts::Strm_StdOutWriteFailure); + } +} + +XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() +{ + return 0; +} + +// --------------------------------------------------------------------------- +// 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(); +} + + +// --------------------------------------------------------------------------- +// 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. +// In our case, we use the ICU based message loader mechanism. +// +XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) +{ + XMLMsgLoader* retVal; + try + { +#if defined (XML_USE_ICU_MESSAGELOADER) + retVal = new ICUMsgLoader(msgDomain); +#elif defined (XML_USE_ICONV_MESSAGELOADER) + retVal = new MsgCatalogLoader(msgDomain); +#else + retVal = new InMemMsgLoader(msgDomain); +#endif + } + catch(...) + { + panic(XMLPlatformUtils::Panic_NoDefTranscoder); + } + 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) + // + // We need to figure out the path to the Intl classes. They will be + // in the ./Intl subdirectory under this DLL. + // + + static const char * xml4cIntlDirEnvVar = "ICU_DATA"; + char * intlPath = 0; + + char* envVal = getenv(xml4cIntlDirEnvVar); + // + // Check if environment variable is set + // + if (envVal != NULL) // We have found an environment variable + { + unsigned int pathLen = strlen(envVal); + intlPath = new char[pathLen + 2]; + + strcpy((char *) intlPath, envVal); + if (envVal[pathLen - 1] != '/') + { + strcat((char *) intlPath, "/"); + } + + ICUTransService::setICUPath(intlPath); + if (intlPath != NULL) delete intlPath; + + return new ICUTransService; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + + char libName[256]; + strcpy(libName, XML4C_DLLName); + strcat(libName, gXML4CVersionStr); + strcat(libName, ".so"); + + void* handle = NULL; + handle = dlopen(libName, RTLD_LAZY); + if (!handle) + { + char errorBuffer[1024]; + sprintf(errorBuffer, + "Fatal error: Could not open library '%s'", libName); + perror (errorBuffer); + panic(XMLPlatformUtils::Panic_NoTransService); + } + + int ret = 0; + Link_map *firstLib = NULL; + + ret = dlinfo(handle, RTLD_DI_LINKMAP, (void*) &firstLib); + Link_map* nextLib = NULL; + nextLib = firstLib; + + while (nextLib) + { + char* fileName = nextLib->l_name; + if (strstr(fileName, libName) != NULL) + { + char* copyTo = strrchr(fileName, '/'); + size_t chars_to_extract = copyTo - fileName; + char *libPathName = new char[chars_to_extract + 1]; + strncpy(libPathName, fileName, chars_to_extract); + libPathName[chars_to_extract] = 0; + fgIntlPath = new char[strlen(libPathName)+ strlen("/icu/data/")+1]; + strcpy((char *) fgIntlPath, libPathName); + strcat((char *) fgIntlPath, "/icu/data/"); + delete libPathName; + break; + } + nextLib = nextLib->l_next; + } + + if (fgIntlPath == NULL) + { + fprintf(stderr, + "Fatal error: Could not find /icu/data relative to %s \n", + libName); + fprintf(stderr, + " while trying to auto detect the location "); + fprintf(stderr, "of the converter files.\n"); + fprintf(stderr, + " And the environment variable 'ICU_DATA' is "); + fprintf(stderr, "not defined.\n"); + panic(XMLPlatformUtils::Panic_NoTransService); + } + + ICUTransService::setICUPath(fgIntlPath); + return new ICUTransService; + +#else // Use Native transcoding service + + return new IconvTransService; + +#endif +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: The panic method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::panic(const PanicReasons reason) +{ + // + // We just print a message and exit + // + + fprintf(stderr, + "The XML4C system could not be initialized.\n"); + fprintf(stderr, + "The most likely reason for this failure is the inability to find\n"); + fprintf(stderr, + "the ICU coverter files, if you are using ICU. The converter files\n"); + fprintf(stderr, + "have the extension .cnv and exist in a directory 'icu/data' relative\n"); + fprintf(stderr, + "to the XML4C shared library. If you have installed the converter files\n"); + fprintf(stderr, + "in a different location, you need to set up the environment variable\n"); + fprintf(stderr, + "'ICU_DATA' to point directly to the directory containing the\n"); + fprintf(stderr, + "converter files.\n"); + + exit(-1); +} + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + int curPos = ftell( (FILE*)theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotGetSize); + + return (unsigned int)curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*) theFile)) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotCloseFile); +} + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*) theFile); + if (curPos == -1) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotGetCurPos); + + // Seek to the end and save that value for return + if (fseek( (FILE*) theFile, 0, SEEK_END) ) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotSeekToEnd); + + long int retVal = ftell((FILE*) theFile); + if (retVal == -1) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotSeekToEnd); + + // And put the pointer back + if (fseek((FILE*) theFile, curPos, SEEK_SET)) + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotSeekToPos); + + return (unsigned int)retVal; +} + +FileHandle XMLPlatformUtils::openFile(const unsigned short* 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; +} + +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, + XML4CExcepts::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, + XML4CExcepts::File_CouldNotResetFile); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- + +#if defined (SOLARIS) +extern "C" int ftime(struct timeb *); // Solaris headers missing this decl +#endif + +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + timeb aTime; + ftime(&aTime); + return (unsigned long)(aTime.time*1000 + aTime.millitm); +} + + + +XMLCh* XMLPlatformUtils::getBasePath(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* tmpPath = dirname((char*)newSrc); + if (!tmpPath) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::File_CouldNotGetBasePathName); + } + + char* newXMLString = new char [strlen(tmpPath) +2]; + ArrayJanitor<char> newJanitor(newXMLString); + strcpy(newXMLString, tmpPath); + strcat(newXMLString , "/"); + // Return a copy of the path, in Unicode format + return XMLString::transcode(newXMLString); +} + + +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; +} + +// ----------------------------------------------------------------------- +// Standard out/error support +// ----------------------------------------------------------------------- + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStr(stderr, toWrite); +} +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStr(stdout, toWrite); +} + + +// ----------------------------------------------------------------------- +// Mutex methods +// ----------------------------------------------------------------------- + +#if !defined (APP_NO_THREADS) + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (mutex_destroy( (mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, + XML4CExcepts::Mutex_CouldNotDestroy); + } + if ((mutex_t*)mtxHandle) + delete mtxHandle; +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (mutex_lock( (mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotLock); + } +} + +void* XMLPlatformUtils::makeMutex() +{ + mutex_t* mutex = new mutex_t; + + if (mutex_init(mutex, NULL, NULL)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotCreate); + } + return (void*)(mutex); +} +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (mutex_unlock( (mutex_t*)mtxHandle)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotUnlock); + } +} + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- +//atomic system calls in Solaris is only restricted to kernel libraries +//So, to make operations thread safe we implement static mutex and lock +//the atomic operations. It makes the process slow but what's the alternative! + +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , + const void* const toCompare) +{ + //return ((void*)cas32( (uint32_t*)toFill, (uint32_t)toCompare, (uint32_t)newValue) ); + // the below calls are temporarily made till the above functions are part of user library + // Currently its supported only in the kernel mode + + lockMutex(&atomicOpsMutex); + + void *retVal = *toFill; + if (*toFill == toCompare) + *toFill = (void *)newValue; + + unlockMutex(&atomicOpsMutex); + + return retVal; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +{ + //return (int)atomic_add_32_nv( (uint32_t*)&location, 1); + XMLMutexLock localLock(&atomicOpsMutex); + + return ++location; +} +int XMLPlatformUtils::atomicDecrement(int &location) +{ + //return (int)atomic_add_32_nv( (uint32_t*)&location, -1); + XMLMutexLock localLock(&atomicOpsMutex); + + return --location; +} + +#else // #if !defined (APP_NO_THREADS) + +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ +} + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ +} + +void* XMLPlatformUtils::makeMutex() +{ + return 0; +} + +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 + + + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + return (FileHandle)fdopen(dup(0), "rb"); +} + diff --git a/src/util/Platforms/Tandem/TandemDefs.hpp b/src/util/Platforms/Tandem/TandemDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..aa63f1ff9eefc10c7777d761755b259541b429b0 --- /dev/null +++ b/src/util/Platforms/Tandem/TandemDefs.hpp @@ -0,0 +1,73 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:24 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:32 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Tandem machines runs in big endian mode +// --------------------------------------------------------------------------- +#define ENDIANMODE_BIG +typedef void* FileHandle; + diff --git a/src/util/Platforms/Tandem/TandemPlatformUtils.cpp b/src/util/Platforms/Tandem/TandemPlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..580e9e8d2c4007a023fc9efbcb339ef078f08290 --- /dev/null +++ b/src/util/Platforms/Tandem/TandemPlatformUtils.cpp @@ -0,0 +1,466 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:24 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:32 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// NOTE: +// +// XML4C is not officially supported on Tandem. This file was sent +// in by one of the Tandem users and is included in the distribution +// just for convenience. Please send any defects / modification +// reports to xml4c@us.ibm.com +// --------------------------------------------------------------------------- + + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +// XXX #include <pthread.h> +// XXX #include <sys/atomic_op.h> + +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/Janitor.hpp> +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <libgen.h> +#include <sys/timeb.h> +#include <string.h> + + +// --------------------------------------------------------------------------- +// Local Methods +// --------------------------------------------------------------------------- +static void WriteCharStr( FILE* stream, const char* const toWrite) +{ + if (!fputs(toWrite, stream)) + { + throw XMLPlatformUtilsException("Could not write to standard out/err"); + } +} + +static void WriteUStrStdErr( const XMLCh* const toWrite) +{ + char* tmpVal = XMLString::transcode(toWrite); + if (!fputs(tmpVal, stderr)) + { + throw XMLPlatformUtilsException("Could not write to standard error file"); + } +} + +static void WriteUStrStdOut( const XMLCh* const toWrite) +{ + char* tmpVal = XMLString::transcode(toWrite); + if (!fputs(tmpVal, stdout)) + { + throw XMLPlatformUtilsException("Could not write to standard out file"); + } +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Platform init method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::platformInit() +{ +} + + +void XMLPlatformUtils::setupIntlPath() +{ + // + // We need to figure out the path to the Intl classes. They will be + // in the .\Intl subdirectory under this DLL. + // + char* tmpBuf = getenv("XML4C2INTLDIR"); + //check if environment variable is set + if (tmpBuf !=0) { + // Store this string in the static member + char cBuf[1024]; + + strcpy(cBuf, tmpBuf); + unsigned int pathLen = strlen(tmpBuf); + + if (*(tmpBuf + pathLen - 1) != '/') + strcpy((tmpBuf + pathLen), "/"); + + fgIntlPath = new char[strlen(tmpBuf)+1 ]; + strcpy((char*)fgIntlPath, tmpBuf); + return; + } + + // + // If we did not find the environment var, so lets try to go the auto + // search route. + // + + static const char* const pubDLLNameBase = XML4C2_DLLName; + char pubDLLNameReal[256]; + strcpy(pubDLLNameReal, pubDLLNameBase); + strcat(pubDLLNameReal, gXML4C2VersionStr); + strcat(pubDLLNameReal, ".a"); + + char* libName = new char[ strlen(pubDLLNameReal)]; + strcpy(libName, pubDLLNameReal); + char* libPath = getenv("LIBPATH"); + + //Now create an array of the directory listing in this path + + //First do the searching process for the first directory listing + char* libPathName = strtok(libPath, ":"); + + char* libfile = new char[ strlen(libPathName) + strlen(libName) +2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + if ((FILE*)fopen(libfile, "rb")) + { + delete libfile; + libfile=0; + if (tmpBuf) { + delete tmpBuf; + tmpBuf =0; + } + tmpBuf = new char[strlen(libPathName)+ strlen("/intlFiles/locales/")+1]; + strcpy(tmpBuf, libPathName); + strcat(tmpBuf, "/intlFiles/locales/"); + fgIntlPath = new char[strlen(tmpBuf)+1 ]; + strcpy((char*)fgIntlPath, tmpBuf); + return; + } + + //do the searching process for the rest directory listings + while (libPathName != NULL) + { + libPathName = strtok(0, ":"); + + if (libPathName == NULL) + break; + + libfile = new char[ strlen(libPathName) + strlen(libName) +2]; + strcpy(libfile, libPathName); + strcat(libfile, "/"); + strcat(libfile, libName); + + if ((FILE*)fopen(libfile, "rb")) + { + delete libfile; + libfile=0; + if (tmpBuf) { + delete tmpBuf; + tmpBuf =0; + } + tmpBuf = new char[strlen(libPathName)+ strlen("/intlFiles/locales/")+1]; + strcpy(tmpBuf, libPathName); + strcat(tmpBuf, "/intlFiles/locales/"); + fgIntlPath = new char[strlen(tmpBuf)+1 ]; + strcpy((char*)fgIntlPath, tmpBuf); + return; + } + } + if (fgIntlPath == NULL) { + printf("Environment variable 'XML4C2INTLDIR' not defined \n"); + throw RuntimeException( + "Environment variable 'XML4C2INTLDIR' not defined." + ); + } +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + int curPos = ftell( (FILE*)theFile); + if (curPos == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::curFilePos - Could not get current pos"); + + return (unsigned int)curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (fclose((FILE*)theFile)) + throw XMLPlatformUtilsException("XMLPlatformUtils::closeFile - Could not close the file handle"); +} + +unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) +{ + // Get the current position + long int curPos = ftell((FILE*)theFile); + if (curPos == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not get current pos"); + + // Seek to the end and save that value for return + if (fseek( (FILE*)theFile, 0, SEEK_END) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not seek to end"); + + long int retVal = ftell( (FILE*)theFile); + if (retVal == -1) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not get the file size"); + + // And put the pointer back + if (fseek( (FILE*)theFile, curPos, SEEK_SET) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::fileSize - Could not seek back to original pos"); + + return (unsigned int)retVal; +} + +FileHandle XMLPlatformUtils::openFile(const unsigned short* const fileName) +{ + const char* tmpFileName = XMLString::transcode(fileName); + FileHandle retVal = (FILE*)fopen( tmpFileName , "rb" ); + + if (retVal == NULL) + return 0; + return retVal; +} + +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)) + { + throw XMLPlatformUtilsException("XMLPlatformUtils::readFileBuffer - Read failed"); + } + + return (unsigned int)noOfItemsRead; +} + + +void XMLPlatformUtils::resetFile(FileHandle theFile) +{ + // Seek to the start of the file + if (fseek((FILE*)theFile, 0, SEEK_SET) ) + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile - Could not seek to beginning"); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + timeb aTime; + ftime(&aTime); + return (unsigned long)(aTime.time*1000 + aTime.millitm); + +} + + + +XMLCh* XMLPlatformUtils::getBasePath(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); + + // Use a local buffer that is big enough for the largest legal path + char* tmpPath = dirname((char*)newSrc); + if (!tmpPath) + { + throw XMLPlatformUtilsException("XMLPlatformUtils::resetFile - Could not get the base path name"); + } + + char* newXMLString = new char [strlen(tmpPath) +1]; + ArrayJanitor<char> newJanitor(newXMLString); + strcpy(newXMLString, tmpPath); + strcat(newXMLString , "/"); + // Return a copy of the path, in Unicode format + return XMLString::transcode(newXMLString); +} +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; +} + +// ----------------------------------------------------------------------- +// Standard out/error support +// ----------------------------------------------------------------------- + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + WriteCharStr(stderr, toWrite); +} +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + WriteUStrStdErr(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + WriteUStrStdOut(toWrite); +} +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + WriteCharStr(stdout, toWrite); +} + +#ifndef __TANDEM +// ----------------------------------------------------------------------- +// Mutex methods +// ----------------------------------------------------------------------- +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_destroy( (pthread_mutex_t*)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not destroy a mutex"); + } + if ( (pthread_mutex_t*)mtxHandle) + delete mtxHandle; +} +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_lock( (pthread_mutex_t*)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not lock a mutex"); + } + +} +void* XMLPlatformUtils::makeMutex() +{ + pthread_mutex_t* mutex = new pthread_mutex_t; + if (mutex == NULL) + { + throw XMLPlatformUtilsException("Could not initialize a mutex"); + } + + if (pthread_mutex_init(mutex, NULL)) + { + throw XMLPlatformUtilsException("Could not create a mutex"); + } + + return (void*)(mutex); +} +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (mtxHandle == NULL) + return; + if (pthread_mutex_unlock( (pthread_mutex_t*)mtxHandle)) + { + throw XMLPlatformUtilsException("Could not unlock a mutex"); + } +} + + +// ----------------------------------------------------------------------- +// Miscellaneous synchronization methods +// ----------------------------------------------------------------------- +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , + const void* const toCompare) +{ + boolean_t boolVar = compare_and_swap((atomic_p)toFill, (int *)&toCompare, (int)newValue ); + return (void *)toCompare; +} + +int XMLPlatformUtils::atomicIncrement(int &location) +{ + int retVal = fetch_and_add( (atomic_p)&location, 1); + return retVal+1; +} +int XMLPlatformUtils::atomicDecrement(int &location) +{ + int retVal = fetch_and_add( (atomic_p)&location, -1); + return retVal-1; +} + + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + return (FileHandle)fdopen(dup(0), "rb"); +} +#endif diff --git a/src/util/Platforms/Win32/Version.rc b/src/util/Platforms/Win32/Version.rc new file mode 100644 index 0000000000000000000000000000000000000000..6959ea15505f9c9c7ee0cacd080e1f3eddbf8844 --- /dev/null +++ b/src/util/Platforms/Win32/Version.rc @@ -0,0 +1,347 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 3,0,0,0 + PRODUCTVERSION 3,0,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "Dynamic linked library for XML4C2\0" + VALUE "CompanyName", "International Business Machines Corp.\0" + VALUE "FileDescription", "Shared Library for XML4C Version 3.0.0\0" + VALUE "FileVersion", "3, 0, 0, 0\0" + VALUE "InternalName", "IXXML4C3_0_0\0" + VALUE "LegalCopyright", "Copyright © IBM Corp. 1999 subject to licensing terms\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "IXXML4C3_0.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "XML4C Version 3.0.0\0" + VALUE "ProductVersion", "3, 0, 0, 0\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // !_MAC + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// +STRINGTABLE DISCARDABLE +BEGIN + 2 L"\x004E\x006F\x0074\x0061\x0074\x0069\x006F\x006E\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0062\x0065\x0065\x006E\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 3 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0062\x0065\x0065\x006E\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 4 L"\x0045\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x0020\x0028\x007B\x0030\x007D\x002C\x0020\x0066\x0072\x006F\x006D\x0020\x0058\x004D\x004C\x0044\x0065\x0063\x006C\x0020\x006F\x0072\x0020\x006D\x0061\x006E\x0075\x0061\x006C\x006C\x0079\x0020\x0073\x0065\x0074\x0029\x0020\x0063\x006F\x006E\x0074\x0072\x0061\x0064\x0069\x0063\x0074\x0073\x0020\x0074\x0068\x0065\x0020\x0061\x0075\x0074\x006F\x002D\x0073\x0065\x006E\x0073\x0065\x0064\x0020\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x002C\x0020\x0069\x0067\x006E\x006F\x0072\x0069\x006E\x0067\x0020\x0069\x0074\x00" + 5 L"\x0045\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0077\x0061\x0073\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x0064\x0020\x0069\x006E\x0020\x0061\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x0020\x0062\x0075\x0074\x0020\x006E\x0065\x0076\x0065\x0072\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 6 L"\x0045\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0077\x0061\x0073\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x0064\x0020\x0069\x006E\x0020\x0061\x006E\x0020\x0061\x0074\x0074\x006C\x0069\x0073\x0074\x0020\x0062\x0075\x0074\x0020\x006E\x0065\x0076\x0065\x0072\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 9 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0063\x006F\x006D\x006D\x0065\x006E\x0074\x0020\x006F\x0072\x0020\x0043\x0044\x0041\x0054\x0041\x00" + 10 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x006E\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x006E\x0061\x006D\x0065\x00" + 11 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0020\x006E\x006F\x0074\x0061\x0074\x0069\x006F\x006E\x0020\x006E\x0061\x006D\x0065\x00" + 12 L"\x0052\x0065\x0070\x0065\x0074\x0069\x0074\x0069\x006F\x006E\x0020\x006F\x0066\x0020\x0069\x006E\x0064\x0069\x0076\x0069\x0064\x0075\x0061\x006C\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0073\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x006C\x0065\x0067\x0061\x006C\x0020\x0066\x006F\x0072\x0020\x006D\x0069\x0078\x0065\x0064\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x0073\x00" + 13 L"\x0042\x0061\x0064\x0020\x0064\x0065\x0066\x0061\x0075\x006C\x0074\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 14 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0064\x0065\x0066\x0061\x0075\x006C\x0074\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x002C\x0020\x0061\x0073\x0073\x0075\x006D\x0069\x006E\x0067\x0020\x0023\x0049\x004D\x0050\x004C\x0049\x0045\x0044\x0020\x0020\x00" + 15 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x006C\x0069\x0073\x0074\x0020\x0073\x0079\x006E\x0074\x0061\x0078\x0020\x0065\x0072\x0072\x006F\x0072\x00" + 16 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0065\x0071\x0075\x0061\x006C\x0020\x0073\x0069\x0067\x006E\x00" + 17 L"\x0044\x0075\x0070\x006C\x0069\x0063\x0061\x0074\x0069\x006F\x006E\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x006E\x0061\x006D\x0065\x00" + 18 L"\x0042\x0061\x0064\x0020\x0049\x0044\x0020\x0066\x006F\x0072\x0020\x0078\x006D\x006C\x003A\x006C\x0061\x006E\x0067\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x00" + 19 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x006E\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x006E\x0061\x006D\x0065\x00" + 20 L"\x004D\x0075\x0073\x0074\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0077\x0069\x0074\x0068\x0020\x0061\x006E\x0020\x0058\x004D\x004C\x0044\x0065\x0063\x006C\x00" + 21 L"\x0043\x006F\x006D\x006D\x0065\x006E\x0074\x0073\x0020\x006D\x0075\x0073\x0074\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0077\x0069\x0074\x0068\x0020\x003C\x0021\x002D\x002D\x00" + 22 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0064\x006F\x0063\x0075\x006D\x0065\x006E\x0074\x0020\x0073\x0074\x0072\x0075\x0063\x0074\x0075\x0072\x0065\x00" + 23 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0020\x0027\x0076\x0065\x0072\x0073\x0069\x006F\x006E\x003D\x0027\x002C\x0020\x0027\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x003D\x0027\x002C\x0020\x006F\x0072\x0020\x0027\x0073\x0074\x0061\x006E\x0064\x0061\x006C\x006F\x006E\x0065\x003D\x0027\x00" + 24 L"\x0042\x0061\x0064\x0020\x0058\x004D\x004C\x0020\x0076\x0065\x0072\x0073\x0069\x006F\x006E\x0020\x0073\x0074\x0072\x0069\x006E\x0067\x00" + 25 L"\x0055\x006E\x0073\x0075\x0070\x0070\x006F\x0072\x0074\x0065\x0064\x0020\x0058\x004D\x004C\x0020\x0076\x0065\x0072\x0073\x0069\x006F\x006E\x00" + 26 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0058\x004D\x004C\x0020\x0064\x0065\x0063\x006C\x00" + 27 L"\x0042\x0061\x0064\x0020\x0058\x004D\x004C\x0020\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 28 L"\x0042\x0061\x0064\x0020\x0073\x0074\x0061\x006E\x0064\x0061\x006C\x006F\x006E\x0065\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 29 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0063\x006F\x006D\x006D\x0065\x006E\x0074\x00" + 30 L"\x0050\x0072\x006F\x0063\x0065\x0073\x0073\x0069\x006E\x0067\x0020\x0069\x006E\x0073\x0074\x0072\x0075\x0063\x0074\x0069\x006F\x006E\x0020\x006E\x0061\x006D\x0065\x0020\x0065\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x00" + 31 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0070\x0072\x006F\x0063\x0065\x0073\x0073\x0069\x006E\x0067\x0020\x0069\x006E\x0073\x0074\x0072\x0075\x0063\x0074\x0069\x006F\x006E\x00" + 32 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x00" + 33 L"\x0055\x006E\x0065\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0074\x0065\x0078\x0074\x0020\x0062\x0065\x0066\x006F\x0072\x0065\x0020\x0072\x006F\x006F\x0074\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x00" + 34 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0074\x0061\x0067\x00" + 35 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x006E\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 36 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0065\x006E\x0064\x0020\x0074\x0061\x0067\x00" + 37 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0074\x0079\x0070\x0065\x0020\x0028\x0043\x0044\x0041\x0054\x0041\x002C\x0020\x0049\x0044\x002C\x0020\x004E\x004D\x0054\x004F\x004B\x0045\x004E\x002C\x0020\x002E\x002E\x0029\x002C\x00" + 38 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0065\x006E\x0064\x0020\x006F\x0066\x0020\x0074\x0061\x0067\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 39 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0074\x0061\x0067\x0020\x006E\x0061\x006D\x0065\x002C\x0020\x0063\x006F\x006D\x006D\x0065\x006E\x0074\x002C\x0020\x0050\x0049\x002C\x0020\x006F\x0072\x0020\x006F\x0074\x0068\x0065\x0072\x0020\x006D\x0061\x0072\x006B\x0075\x0070\x00" + 40 L"\x004E\x006F\x0074\x0020\x0076\x0061\x006C\x0069\x0064\x0020\x0061\x0066\x0074\x0065\x0072\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x00" + 41 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0063\x006F\x006D\x006D\x0065\x006E\x0074\x00" + 42 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0063\x006F\x006D\x006D\x0065\x006E\x0074\x0020\x006F\x0072\x0020\x0070\x0072\x006F\x0063\x0065\x0073\x0073\x0069\x006E\x0067\x0020\x0069\x006E\x0073\x0074\x0072\x0075\x0063\x0074\x0069\x006F\x006E\x00" + 43 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0077\x0068\x0069\x0074\x0065\x0073\x0070\x0061\x0063\x0065\x00" + 44 L"\x004E\x006F\x0020\x0072\x006F\x006F\x0074\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0069\x006E\x0020\x0044\x004F\x0043\x0054\x0059\x0050\x0045\x00" + 45 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0071\x0075\x006F\x0074\x0065\x0064\x0020\x0073\x0074\x0072\x0069\x006E\x0067\x00" + 46 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0070\x0075\x0062\x006C\x0069\x0063\x0020\x0069\x0064\x00" + 47 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0069\x006E\x0020\x0070\x0075\x0062\x006C\x0069\x0063\x0020\x0069\x0064\x00" + 48 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0044\x004F\x0043\x0054\x0059\x0050\x0045\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 49 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0069\x006E\x0020\x0069\x006E\x0074\x0065\x0072\x006E\x0061\x006C\x0020\x0073\x0075\x0062\x0073\x0065\x0074\x00" + 50 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0043\x0044\x0041\x0054\x0041\x0020\x0073\x0065\x0063\x0074\x0069\x006F\x006E\x00" + 51 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0069\x006E\x0069\x0074\x0069\x0061\x006C\x0020\x006E\x0061\x006D\x0065\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x00" + 52 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x006E\x0061\x006D\x0065\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x00" + 53 L"\x0055\x006E\x0065\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0077\x0068\x0069\x0074\x0065\x0073\x0070\x0061\x0063\x0065\x00" + 54 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0069\x006E\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 55 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0020\x006D\x0061\x0072\x006B\x0075\x0070\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 56 L"\x0054\x0065\x0078\x0074\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x006E\x006F\x0074\x0020\x006C\x0065\x0067\x0061\x006C\x0020\x0068\x0065\x0072\x0065\x00" + 57 L"\x0043\x006F\x006E\x0064\x0069\x0074\x0069\x006F\x006E\x0061\x006C\x0020\x0073\x0065\x0063\x0074\x0069\x006F\x006E\x0020\x0069\x006E\x0020\x0069\x006E\x0074\x0065\x0072\x006E\x0061\x006C\x0020\x0073\x0075\x0062\x0073\x0065\x0074\x00" + 58 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0070\x0061\x0072\x0061\x006D\x0065\x0074\x0065\x0072\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x006E\x0061\x006D\x0065\x00" + 59 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 60 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x00" + 61 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x00" + 62 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x006E\x0061\x006D\x0065\x0020\x0066\x006F\x0072\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x00" + 63 L"\x0045\x006E\x0074\x0069\x0074\x0079\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0066\x006F\x0075\x006E\x0064\x00" + 64 L"\x0055\x006E\x0070\x0061\x0072\x0073\x0065\x0064\x0020\x0065\x006E\x0074\x0069\x0074\x0074\x0079\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x0073\x0020\x006E\x006F\x0074\x0020\x0076\x0061\x006C\x0069\x0064\x0020\x0068\x0065\x0072\x0065\x00" + 65 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x00" + 66 L"\x0052\x0065\x0063\x0075\x0072\x0073\x0069\x0076\x0065\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0065\x0078\x0070\x0061\x006E\x0073\x0069\x006F\x006E\x00" + 67 L"\x0050\x0061\x0072\x0074\x0069\x0061\x006C\x0020\x006D\x0061\x0072\x006B\x0075\x0070\x0020\x0069\x006E\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 68 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 69 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x0073\x0070\x0065\x0063\x0069\x0066\x0069\x0063\x0061\x0074\x0069\x006F\x006E\x0020\x0065\x0078\x0070\x0072\x0065\x0073\x0073\x0069\x006F\x006E\x00" + 70 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0073\x0074\x0065\x0072\x0069\x0073\x006B\x00" + 71 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0043\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x00" + 72 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0073\x0079\x0073\x0074\x0065\x006D\x0020\x0069\x0064\x00" + 73 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0073\x0079\x0073\x0074\x0065\x006D\x0020\x006F\x0072\x0020\x0070\x0075\x0062\x006C\x0069\x0063\x0020\x0069\x0064\x00" + 74 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x006E\x006F\x0074\x0061\x0074\x0069\x006F\x006E\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x00" + 75 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0027\x002C\x0027\x002C\x0020\x0027\x007C\x0027\x002C\x0020\x006F\x0072\x0020\x0027\x0029\x0027\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0073\x00" + 76 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0027\x007C\x0027\x0020\x006F\x0072\x0020\x0027\x0029\x0027\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0073\x00" + 77 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0027\x002C\x0027\x0020\x006F\x0072\x0020\x0027\x0029\x0027\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0073\x0020\x006F\x0072\x0020\x0063\x006C\x006F\x0073\x0065\x0020\x0070\x0061\x0072\x0065\x006E\x0074\x0068\x0065\x0073\x0069\x0073\x00" + 78 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0065\x006E\x0075\x006D\x0065\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 79 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x007C\x0020\x0065\x006E\x0075\x006D\x0065\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x0073\x0065\x0070\x0061\x0072\x0061\x0074\x006F\x0072\x002C\x0020\x006F\x0072\x0020\x0063\x006C\x006F\x0073\x0069\x006E\x0067\x0020\x0070\x0061\x0072\x0065\x006E\x00" + 80 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x006C\x0069\x0074\x0065\x0072\x0061\x006C\x00" + 81 L"\x0054\x0068\x0065\x0072\x0065\x0020\x0061\x0072\x0065\x0020\x006D\x006F\x0072\x0065\x0020\x0065\x006E\x0064\x0020\x0074\x0061\x0067\x0073\x0020\x0074\x0068\x0061\x006E\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0074\x0061\x0067\x0073\x00" + 82 L"\x0052\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x0020\x0074\x006F\x0020\x0065\x0078\x0074\x0065\x0072\x006E\x0061\x006C\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x0069\x006E\x0020\x0073\x0074\x0061\x006E\x0064\x0061\x006C\x006F\x006E\x0065\x0020\x0064\x006F\x0063\x0075\x006D\x0065\x006E\x0074\x002E\x0020\x0045\x006E\x0074\x0069\x0074\x0079\x003D\x007B\x0030\x007D\x00" + 83 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x006E\x0020\x006F\x0070\x0065\x006E\x0020\x0070\x0061\x0072\x0065\x006E\x0074\x0068\x0065\x0073\x0069\x0073\x00" + 84 L"\x0054\x0068\x0065\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0069\x0073\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0075\x0073\x0065\x0064\x0020\x0069\x006E\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0031\x007D\x0027\x00" + 85 L"\x0041\x0020\x0027\x003C\x0027\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0075\x0073\x0065\x0064\x0020\x0069\x006E\x0020\x0061\x006E\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0076\x0061\x006C\x0075\x0065\x002C\x0020\x0065\x0078\x0063\x0065\x0070\x0074\x0020\x0074\x0068\x0072\x006F\x0075\x0067\x0068\x0020\x003C\x00" + 86 L"\x0041\x0020\x006C\x0065\x0061\x0064\x0069\x006E\x0067\x0020\x0073\x0075\x0072\x0072\x006F\x0067\x0061\x0074\x0065\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0066\x006F\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0062\x0079\x0020\x0061\x0020\x006C\x0065\x0067\x0061\x006C\x0020\x0073\x0065\x0063\x006F\x006E\x0064\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x00" + 87 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0027\x005D\x005D\x003E\x0027\x0020\x0074\x006F\x0020\x0065\x006E\x0064\x0020\x0061\x0020\x0063\x006F\x006E\x0064\x0069\x0074\x0069\x006F\x006E\x0061\x006C\x0020\x0073\x0065\x0063\x0074\x0069\x006F\x006E\x00" + 88 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0049\x004E\x0043\x004C\x0055\x0044\x0045\x0020\x006F\x0072\x0020\x0049\x0047\x004E\x004F\x0052\x0045\x0020\x0068\x0065\x0072\x0065\x00" + 89 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x005B\x0020\x0074\x006F\x0020\x0066\x006F\x006C\x006C\x006F\x0077\x0020\x0049\x004E\x0043\x004C\x0055\x0044\x0045\x0020\x006F\x0072\x0020\x0049\x0047\x004E\x004F\x0052\x0045\x00" + 90 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0020\x0054\x0065\x0078\x0074\x0044\x0065\x0063\x006C\x0020\x0068\x0065\x0072\x0065\x003A\x0020\x003C\x003F\x0078\x006D\x006C\x0020\x002E\x002E\x002E\x002E\x00" + 91 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0020\x0058\x004D\x004C\x0044\x0065\x0063\x006C\x0020\x0068\x0065\x0072\x0065\x003A\x0020\x003C\x003F\x0078\x006D\x006C\x0020\x002E\x002E\x002E\x002E\x00" + 92 L"\x0055\x006E\x0065\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0065\x006E\x0064\x0020\x006F\x0066\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x007B\x0030\x007D\x00" + 93 L"\x0041\x0020\x0050\x0045\x0020\x0070\x0072\x006F\x0070\x006F\x0067\x0061\x0074\x0065\x0064\x0020\x006F\x0075\x0074\x0020\x006F\x0066\x0020\x0074\x0068\x0065\x0020\x0069\x006E\x0074\x002F\x0065\x0078\x0074\x0020\x0073\x0075\x0062\x0073\x0065\x0074\x002C\x0020\x0064\x0069\x0073\x0063\x0061\x0072\x0064\x0069\x006E\x0067\x0020\x0065\x0078\x0074\x0072\x0061\x0020\x0074\x0065\x0078\x0074\x00" + 94 L"\x0041\x006E\x0020\x0065\x0078\x0074\x0072\x0061\x0020\x005D\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0077\x0061\x0073\x0020\x0066\x006F\x0075\x006E\x0064\x0020\x0061\x006E\x0020\x0069\x0067\x006E\x006F\x0072\x0065\x0064\x00" + 95 L"\x0050\x0045\x0020\x0072\x0065\x0066\x0073\x0020\x0061\x0072\x0065\x0020\x006E\x006F\x0074\x0020\x0061\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0069\x006E\x0073\x0069\x0064\x0065\x0020\x006D\x0061\x0072\x006B\x0075\x0070\x0020\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x0069\x006E\x0074\x0065\x0072\x006E\x0061\x006C\x0020\x0073\x0075\x0062\x0073\x0065\x0074\x00" + 96 L"\x0041\x006E\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0070\x0072\x006F\x0070\x006F\x0067\x0061\x0074\x0065\x0064\x0020\x006F\x0075\x0074\x0020\x006F\x0066\x0020\x0074\x0068\x0065\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x0073\x0065\x0063\x0074\x0069\x006F\x006E\x0020\x0069\x006E\x0074\x006F\x0020\x004D\x0069\x0073\x0063\x0065\x006C\x006C\x0061\x006E\x0065\x006F\x0075\x0073\x00" + 97 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0026\x0023\x0020\x0074\x006F\x0020\x0062\x0065\x0020\x0066\x006F\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0062\x0079\x0020\x0061\x0020\x006E\x0075\x006D\x0065\x0072\x0069\x0063\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 98 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x006E\x0020\x006F\x0070\x0065\x006E\x0020\x0062\x0072\x0061\x0063\x006B\x0065\x0074\x0020\x0028\x0027\x005B\x0027\x0029\x0020\x0068\x0065\x0072\x0065\x00" + 99 L"\x0054\x0068\x0065\x0020\x0073\x0065\x0071\x0075\x0065\x006E\x0063\x0065\x0020\x0027\x005D\x005D\x003E\x0027\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x0061\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0069\x006E\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0064\x0061\x0074\x0061\x00" + 100 L"\x0049\x006C\x006C\x0065\x0067\x0061\x006C\x0020\x0073\x0065\x0071\x0075\x0065\x006E\x0063\x0065\x0020\x0027\x002D\x002D\x0027\x0020\x0069\x006E\x0020\x0063\x006F\x006D\x006D\x0065\x006E\x0074\x00" + 101 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0043\x0044\x0041\x0054\x0041\x0020\x0073\x0065\x0063\x0074\x0069\x006F\x006E\x00" + 102 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x004E\x0044\x0041\x0054\x0041\x00" + 103 L"\x004E\x0044\x0041\x0054\x0041\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x006C\x0065\x0067\x0061\x006C\x0020\x0066\x006F\x0072\x0020\x0070\x0061\x0072\x0061\x006D\x0065\x0074\x0065\x0072\x0020\x0065\x006E\x0074\x0069\x0074\x0069\x0065\x0073\x00" + 104 L"\x0048\x0065\x0078\x0020\x0072\x0061\x0064\x0069\x0078\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0072\x0065\x0066\x0073\x0020\x006D\x0075\x0073\x0074\x0020\x0075\x0073\x0065\x0020\x0027\x0078\x0027\x002C\x0020\x006E\x006F\x0074\x0020\x0027\x0058\x0027\x00" + 105 L"\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0062\x0065\x0065\x006E\x0020\x0073\x0065\x0074\x002E\x0020\x0049\x0067\x006E\x006F\x0072\x0069\x006E\x0067\x0020\x0072\x0065\x0064\x0075\x006E\x0064\x0061\x006E\x0074\x0020\x0073\x0065\x0074\x0074\x0069\x006E\x0067\x00" + 106 L"\x0054\x0068\x0065\x0020\x0058\x004D\x004C\x0044\x0065\x0063\x006C\x0020\x0073\x0074\x0072\x0069\x006E\x0067\x0073\x0020\x006D\x0075\x0073\x0074\x0020\x0062\x0065\x0020\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x006F\x0072\x0064\x0065\x0072\x003A\x0020\x0076\x0065\x0072\x0073\x0069\x006F\x006E\x002C\x0020\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x002C\x0020\x0073\x0074\x0061\x006E\x0064\x0061\x006C\x006F\x006E\x0065\x00" + 107 L"\x0045\x0078\x0074\x0065\x0072\x006E\x0061\x006C\x0020\x0065\x006E\x0074\x0069\x0074\x0069\x0065\x0073\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0072\x0065\x0066\x0065\x0072\x0072\x0065\x0064\x0020\x0074\x006F\x0020\x0066\x0072\x006F\x006D\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0076\x0061\x006C\x0075\x0065\x0073\x00" + 108 L"\x0054\x0068\x0065\x0020\x0058\x004D\x004C\x0020\x006F\x0072\x0020\x0054\x0065\x0078\x0074\x0020\x0064\x0065\x0063\x006C\x0020\x006D\x0075\x0073\x0074\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0077\x0069\x0074\x0068\x0020\x0027\x003C\x003F\x0078\x006D\x006C\x0020\x0027\x002C\x0020\x006E\x006F\x0074\x0020\x0027\x003C\x003F\x0058\x004D\x004C\x0020\x0027\x00" + 109 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0061\x0020\x006C\x0069\x0074\x0065\x0072\x0061\x006C\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0076\x0061\x006C\x0075\x0065\x0020\x006F\x0072\x0020\x0050\x0055\x0042\x004C\x0049\x0043\x002F\x0053\x0059\x0053\x0054\x0045\x004D\x0020\x0069\x0064\x00" + 110 L"\x0027\x007B\x0030\x007D\x0027\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x0061\x0020\x0076\x0061\x006C\x0069\x0064\x0020\x0064\x0069\x0067\x0069\x0074\x0020\x0066\x006F\x0072\x0020\x0074\x0068\x0065\x0020\x0069\x006E\x0064\x0069\x0063\x0061\x0074\x0065\x0064\x0020\x0072\x0061\x0064\x0069\x0078\x00" + 111 L"\x0054\x0068\x0065\x0020\x0069\x006E\x0070\x0075\x0074\x0020\x0065\x006E\x0064\x0065\x0064\x0020\x0062\x0065\x0066\x006F\x0072\x0065\x0020\x0061\x006C\x006C\x0020\x0073\x0074\x0061\x0072\x0074\x0065\x0064\x0020\x0074\x0061\x0067\x0073\x0020\x0077\x0065\x0072\x0065\x0020\x0065\x006E\x0064\x0065\x0064\x002E\x0020\x004C\x0061\x0073\x0074\x0020\x0074\x0061\x0067\x0020\x0073\x0074\x0061\x0072\x0074\x0065\x0064\x0020\x0077\x0061\x0073\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 112 L"\x0054\x0068\x0065\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x0020\x0066\x006F\x0072\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0069\x0073\x0020\x0061\x006D\x0062\x0069\x0067\x0075\x006F\x0075\x0073\x00" + 113 L"\x004E\x0065\x0073\x0074\x0065\x0064\x0020\x0043\x0044\x0041\x0054\x0041\x0020\x0073\x0065\x0063\x0074\x0069\x006F\x006E\x0073\x0020\x0061\x0072\x0065\x0020\x006E\x006F\x0074\x0020\x0061\x006C\x006C\x006F\x0077\x0065\x0064\x00" + 114 L"\x0054\x0068\x0065\x0020\x0070\x0072\x0065\x0066\x0069\x0078\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0062\x0065\x0065\x006E\x0020\x006D\x0061\x0070\x0070\x0065\x0064\x0020\x0074\x006F\x0020\x0061\x006E\x0079\x0020\x0055\x0052\x0049\x00" + 115 L"\x0054\x0068\x0065\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0061\x006E\x0064\x0020\x0074\x0068\x0065\x0020\x0065\x006E\x0064\x0020\x0074\x0061\x0067\x0020\x0077\x0065\x0072\x0065\x0020\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x0064\x0069\x0066\x0066\x0065\x0072\x0065\x006E\x0074\x0020\x0065\x006E\x0074\x0069\x0074\x0069\x0065\x0073\x00" + 116 L"\x0054\x0068\x0065\x0020\x006D\x0061\x0069\x006E\x0020\x0058\x004D\x004C\x0020\x0064\x006F\x0063\x0075\x006D\x0065\x006E\x0074\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0065\x006D\x0070\x0074\x0079\x00" + 117 L"\x0043\x0044\x0041\x0054\x0041\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x0061\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x006F\x0075\x0074\x0073\x0069\x0064\x0065\x0020\x0074\x0068\x0065\x0020\x0072\x006F\x006F\x0074\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x00" + 118 L"\x004F\x006E\x006C\x0079\x0020\x006E\x0075\x006D\x0065\x0072\x0069\x0063\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0065\x006E\x0074\x0069\x0074\x0069\x0065\x0073\x0020\x006F\x0072\x0020\x0073\x0070\x0065\x0063\x0069\x0061\x006C\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0065\x006E\x0074\x0069\x0074\x0069\x0065\x0073\x0020\x0061\x0072\x0065\x0020\x006C\x0065\x0067\x0061\x006C\x0020\x0068\x0065\x0072\x0065\x00" + 119 L"\x0047\x006F\x0074\x0020\x0061\x006E\x0020\x0075\x006E\x0065\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0074\x0072\x0061\x0069\x006C\x0069\x006E\x0067\x0020\x0073\x0075\x0072\x0072\x006F\x0067\x0061\x0074\x0065\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x00" + 120 L"\x004E\x006F\x0020\x0070\x0072\x006F\x0063\x0065\x0073\x0073\x0069\x006E\x0067\x0020\x0069\x006E\x0073\x0074\x0072\x0075\x0063\x0074\x0069\x006F\x006E\x0020\x0073\x0074\x0061\x0072\x0074\x0073\x0020\x0077\x0069\x0074\x0068\x0020\x0027\x0078\x006D\x006C\x0027\x00" + 121 L"\x0054\x0068\x0065\x0020\x0058\x004D\x004C\x0020\x006F\x0072\x0020\x0054\x0065\x0078\x0074\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x006D\x0075\x0073\x0074\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0061\x0074\x0020\x006C\x0069\x006E\x0065\x002F\x0063\x006F\x006C\x0075\x006D\x006E\x0020\x0031\x002F\x0031\x00" + 122 L"\x0054\x0068\x0065\x0020\x0027\x0076\x0065\x0072\x0073\x0069\x006F\x006E\x003D\x0027\x0020\x0073\x0074\x0072\x0069\x006E\x0067\x0020\x0069\x0073\x0020\x0072\x0065\x0071\x0075\x0069\x0072\x0065\x0064\x0020\x0069\x006E\x0020\x0061\x006E\x0020\x0058\x004D\x004C\x0044\x0065\x0063\x006C\x00" + 123 L"\x0054\x0068\x0065\x0020\x0027\x0073\x0074\x0061\x006E\x0064\x0061\x006C\x006F\x006E\x0065\x003D\x0027\x0020\x0073\x0074\x0072\x0069\x006E\x0067\x0020\x0069\x0073\x0020\x006F\x006E\x006C\x0079\x0020\x0061\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x006D\x0061\x0069\x006E\x0020\x0058\x004D\x004C\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x00" + 124 L"\x0057\x0068\x0065\x006E\x0020\x006E\x0061\x006D\x0065\x0073\x0070\x0061\x0063\x0065\x0073\x0020\x0061\x0072\x0065\x0020\x0065\x006E\x0061\x0062\x006C\x0065\x0064\x002C\x0020\x0061\x0020\x006E\x0061\x006D\x0065\x0020\x0063\x0061\x006E\x0020\x0068\x0061\x0076\x0065\x0020\x006F\x006E\x006C\x0079\x0020\x006F\x006E\x0065\x0020\x0063\x006F\x006C\x006F\x006E\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x00" + 125 L"\x0057\x0068\x0065\x006E\x0020\x006E\x0061\x006D\x0065\x0073\x0070\x0061\x0063\x0065\x0073\x0020\x0061\x0072\x0065\x0020\x0065\x006E\x0061\x0062\x006C\x0065\x0064\x002C\x0020\x0074\x0068\x0065\x0020\x0063\x006F\x006C\x006F\x006E\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0074\x0068\x0065\x0020\x0066\x0069\x0072\x0073\x0074\x0020\x006F\x0072\x0020\x006C\x0061\x0073\x0074\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x00" + 126 L"\x0043\x006F\x006C\x006F\x006E\x0073\x0020\x0061\x0072\x0065\x0020\x006E\x006F\x0074\x0020\x0061\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0069\x006E\x0020\x0074\x0068\x0069\x0073\x0020\x006E\x0061\x006D\x0065\x0020\x0077\x0068\x0065\x006E\x0020\x006E\x0061\x006D\x0065\x0073\x0070\x0061\x0063\x0065\x0073\x0020\x0061\x0072\x0065\x0020\x0065\x006E\x0061\x0062\x006C\x0065\x0064\x00" + 127 L"\x0041\x0020\x0073\x0079\x0073\x0074\x0065\x006D\x0020\x0065\x0078\x0063\x0065\x0070\x0074\x0069\x006F\x006E\x0020\x006F\x0063\x0063\x0075\x0072\x0065\x0064\x0020\x0064\x0075\x0072\x0069\x006E\x0067\x0020\x0070\x0072\x006F\x0063\x0065\x0073\x0073\x0069\x006E\x0067\x00" + 128 L"\x0041\x006E\x0020\x0065\x0078\x0063\x0065\x0070\x0074\x0069\x006F\x006E\x0020\x006F\x0063\x0063\x0075\x0072\x0065\x0064\x0021\x0020\x0054\x0079\x0070\x0065\x003A\x007B\x0030\x007D\x002C\x0020\x004D\x0065\x0073\x0073\x0061\x0067\x0065\x003A\x007B\x0031\x007D\x00" + 129 L"\x0055\x006E\x0065\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x0065\x006E\x0064\x0020\x006F\x0066\x0020\x0066\x0069\x006C\x0065\x0020\x0065\x0078\x0063\x0065\x0070\x0074\x0069\x006F\x006E\x002E\x0020\x004D\x0065\x0073\x0073\x0061\x0067\x0065\x003A\x0020\x007B\x0030\x007D\x00" +END +STRINGTABLE DISCARDABLE +BEGIN + 16386 L"\x0055\x006E\x006B\x006E\x006F\x0077\x006E\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 16387 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x006E\x006F\x0074\x0020\x0064\x0065\x0066\x0069\x006E\x0065\x0064\x00" + 16388 L"\x004E\x006F\x0074\x0061\x0074\x0069\x006F\x006E\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0077\x0061\x0073\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x0064\x0020\x0062\x0075\x0074\x0020\x006E\x0065\x0076\x0065\x0072\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 16389 L"\x0052\x006F\x006F\x0074\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0064\x0069\x0066\x0066\x0065\x0072\x0065\x006E\x0074\x0020\x0066\x0072\x006F\x006D\x0020\x0044\x004F\x0043\x0054\x0059\x0050\x0045\x00" + 16390 L"\x0052\x0065\x0071\x0075\x0069\x0072\x0065\x0064\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0070\x0072\x006F\x0076\x0069\x0064\x0065\x0064\x00" + 16391 L"\x0045\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x0076\x0061\x006C\x0069\x0064\x0020\x0066\x006F\x0072\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x003A\x0020\x0027\x007B\x0031\x007D\x0027\x00" + 16392 L"\x0049\x0044\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0073\x0020\x006D\x0075\x0073\x0074\x0020\x0062\x0065\x0020\x0023\x0049\x004D\x0050\x004C\x0049\x0045\x0044\x0020\x006F\x0072\x0020\x0023\x0052\x0045\x0051\x0055\x0049\x0052\x0045\x0044\x00" + 16393 L"\x0054\x0068\x0069\x0073\x0020\x0074\x0079\x0070\x0065\x0020\x006F\x0066\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0068\x0061\x0076\x0065\x0020\x0061\x006E\x0020\x0065\x006D\x0070\x0074\x0079\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 16394 L"\x0045\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0062\x0065\x0065\x006E\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 16395 L"\x0045\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x006D\x006F\x0072\x0065\x0020\x0074\x0068\x0061\x006E\x0020\x006F\x006E\x0065\x0020\x0049\x0044\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x00" + 16396 L"\x0049\x0044\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0062\x0065\x0065\x006E\x0020\x0075\x0073\x0065\x0064\x00" + 16397 L"\x0049\x0044\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0077\x0061\x0073\x0020\x0072\x0065\x0066\x0065\x0072\x0065\x006E\x0063\x0065\x0064\x0020\x0062\x0075\x0074\x0020\x006E\x0065\x0076\x0065\x0072\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 16398 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0072\x0065\x0066\x0065\x0072\x0073\x0020\x0074\x006F\x0020\x0061\x006E\x0020\x0075\x006E\x006B\x006E\x006F\x0077\x006E\x0020\x006E\x006F\x0074\x0061\x0074\x0069\x006F\x006E\x0020\x0027\x007B\x0031\x007D\x0027\x00" + 16399 L"\x0045\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0077\x0061\x0073\x0020\x0075\x0073\x0065\x0064\x0020\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x0044\x004F\x0043\x0054\x0059\x0050\x0045\x0020\x0062\x0075\x0074\x0020\x006E\x0065\x0076\x0065\x0072\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x00" + 16400 L"\x0045\x006D\x0070\x0074\x0079\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006E\x006F\x0074\x0020\x0076\x0061\x006C\x0069\x0064\x0020\x0066\x006F\x0072\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x003A\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 16401 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x007B\x0030\x007D\x007D\x007B\x0031\x007D\x0027\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x0064\x0065\x0063\x006C\x0061\x0072\x0065\x0064\x0020\x0066\x006F\x0072\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0027\x007B\x0032\x007D\x0027\x00" + 16402 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0073\x0020\x006F\x0066\x0020\x0074\x0079\x0070\x0065\x0020\x0045\x004E\x0054\x0049\x0054\x0059\x002F\x0045\x004E\x0054\x0049\x0054\x0049\x0045\x0053\x0020\x006D\x0075\x0073\x0074\x0020\x0072\x0065\x0066\x0065\x0072\x0020\x0074\x006F\x0020\x0061\x006E\x0020\x0065\x0078\x0074\x0065\x0072\x006E\x0061\x006C\x002C\x0020\x0075\x006E\x0070\x0061\x0072\x0073\x0065\x0064\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x00" + 16403 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0072\x0065\x0066\x0065\x0072\x0073\x0020\x0074\x006F\x0020\x0061\x006E\x0020\x0075\x006E\x006B\x006E\x006F\x0077\x006E\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0027\x007B\x0031\x007D\x0027\x00" + 16404 L"\x004E\x006F\x0074\x0020\x0065\x006E\x006F\x0075\x0067\x0068\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0073\x0020\x0074\x006F\x0020\x006D\x0061\x0074\x0063\x0068\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x0020\x003A\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 16405 L"\x004E\x006F\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0064\x0061\x0074\x0061\x0020\x0069\x0073\x0020\x0061\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0062\x0079\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x00" + 16406 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0064\x006F\x0065\x0073\x0020\x006E\x006F\x0074\x0020\x006D\x0061\x0074\x0063\x0068\x0020\x0069\x0074\x0073\x0020\x0064\x0065\x0066\x0069\x006E\x0065\x0064\x0020\x0065\x006E\x0075\x006D\x0065\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x006F\x0072\x0020\x006E\x006F\x0074\x0061\x0074\x0069\x006F\x006E\x0020\x006C\x0069\x0073\x0074\x00" + 16407 L"\x0054\x0068\x0065\x0020\x0076\x0061\x006C\x0075\x0065\x0073\x0020\x0066\x006F\x0072\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x006D\x0075\x0073\x0074\x0020\x0062\x0065\x0020\x006E\x0061\x006D\x0065\x0073\x0020\x006F\x0072\x0020\x006E\x0061\x006D\x0065\x0020\x0074\x006F\x006B\x0065\x006E\x0073\x00" + 16408 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0064\x006F\x0065\x0073\x0020\x006E\x006F\x0074\x0020\x0073\x0075\x0070\x0070\x006F\x0072\x0074\x0020\x006D\x0075\x006C\x0074\x0069\x0070\x006C\x0065\x0020\x0076\x0061\x006C\x0075\x0065\x0073\x00" + 16409 L"\x0041\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0068\x0061\x0073\x0020\x0061\x0020\x0076\x0061\x006C\x0075\x0065\x0020\x0074\x0068\x0061\x0074\x0020\x0064\x006F\x0065\x0073\x0020\x006E\x006F\x0074\x0020\x006D\x0061\x0074\x0063\x0068\x0020\x0069\x0074\x0073\x0020\x0023\x0046\x0049\x0058\x0045\x0044\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 16410 L"\x0045\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0074\x0079\x0070\x0065\x0073\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0064\x0075\x0070\x006C\x0069\x0063\x0061\x0074\x0065\x0064\x0020\x0069\x006E\x0020\x004D\x0069\x0078\x0065\x0064\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x0073\x00" +END +STRINGTABLE DISCARDABLE +BEGIN + 8194 L"\x0054\x0068\x0065\x0020\x0069\x006E\x0064\x0065\x0078\x0020\x0069\x0073\x0020\x0062\x0065\x0079\x006F\x006E\x0064\x0020\x0074\x0068\x0065\x0020\x0061\x0072\x0072\x0061\x0079\x0020\x0062\x006F\x0075\x006E\x0064\x0073\x0020\x0020\x00" + 8195 L"\x0054\x0068\x0065\x0020\x006E\x0065\x0077\x0020\x0073\x0069\x007A\x0065\x0020\x0069\x0073\x0020\x006C\x0065\x0073\x0073\x0020\x0074\x0068\x0061\x006E\x0020\x0074\x0068\x0065\x0020\x006F\x006C\x0064\x0020\x006F\x006E\x0065\x00" + 8196 L"\x0054\x0068\x0065\x0020\x0062\x0069\x0074\x0020\x0069\x006E\x0064\x0065\x0078\x0020\x0077\x0061\x0073\x0020\x0062\x0065\x0079\x006F\x006E\x0064\x0020\x0074\x0068\x0065\x0020\x0073\x0065\x0074\x0020\x0073\x0069\x007A\x0065\x00" + 8197 L"\x0054\x0068\x0065\x0020\x0070\x006F\x0069\x006E\x0074\x0065\x0072\x0020\x0068\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0062\x0065\x0065\x006E\x0020\x0073\x0065\x0074\x00" + 8198 L"\x0054\x0068\x0065\x0020\x0065\x006E\x0075\x006D\x0065\x0072\x0061\x0074\x006F\x0072\x0020\x0063\x006F\x006E\x0074\x0061\x0069\x006E\x0073\x0020\x006E\x006F\x0020\x006D\x006F\x0072\x0065\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0073\x00" + 8199 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x006F\x0070\x0065\x006E\x0020\x0066\x0069\x006C\x0065\x003A\x0020\x007B\x0030\x007D\x00" + 8200 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0071\x0075\x0065\x0072\x0079\x0020\x0074\x0068\x0065\x0020\x0063\x0075\x0072\x0072\x0065\x006E\x0074\x0020\x0066\x0069\x006C\x0065\x0020\x0070\x006F\x0073\x0069\x0074\x0069\x006F\x006E\x00" + 8201 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0063\x006C\x006F\x0073\x0065\x0020\x0074\x0068\x0065\x0020\x0066\x0069\x006C\x0065\x00" + 8202 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0073\x0065\x0065\x006B\x0020\x0074\x006F\x0020\x0065\x006E\x0064\x0020\x006F\x0066\x0020\x0066\x0069\x006C\x0065\x00" + 8203 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0073\x0065\x0065\x006B\x0020\x0074\x006F\x0020\x0072\x0065\x0071\x0075\x0069\x0072\x0065\x0064\x0020\x0070\x006F\x0073\x0069\x0074\x0069\x006F\x006E\x0020\x0069\x006E\x0020\x0066\x0069\x006C\x0065\x00" + 8204 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0064\x0075\x0070\x006C\x0069\x0063\x0061\x0074\x0065\x0020\x0074\x0068\x0065\x0020\x0068\x0061\x006E\x0064\x006C\x0065\x00" + 8205 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0072\x0065\x0061\x0064\x0020\x0064\x0061\x0074\x0061\x0020\x0066\x0072\x006F\x006D\x0020\x0066\x0069\x006C\x0065\x00" + 8206 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0072\x0065\x0073\x0065\x0074\x0020\x0066\x0069\x006C\x0065\x0020\x0074\x006F\x0020\x0062\x0065\x0067\x0069\x006E\x006E\x0069\x006E\x0067\x00" + 8207 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0061\x0063\x0065\x0072\x0074\x0061\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x0066\x0069\x006C\x0065\x0020\x0073\x0069\x007A\x0065\x00" + 8208 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0064\x0065\x0074\x0065\x0072\x006D\x0069\x006E\x0065\x0020\x0062\x0061\x0073\x0065\x0020\x0070\x0061\x0074\x0068\x006E\x0061\x006D\x0065\x0020\x006F\x0066\x0020\x0074\x0068\x0065\x0020\x0066\x0069\x006C\x0065\x00" + 8209 L"\x0054\x0068\x0065\x0020\x0068\x0061\x0073\x0068\x0020\x006D\x006F\x0064\x0075\x006C\x0075\x0073\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x007A\x0065\x0072\x006F\x00" + 8210 L"\x0048\x0061\x0073\x0068\x0069\x006E\x0067\x0020\x0074\x0068\x0065\x0020\x006B\x0065\x0079\x0020\x0072\x0065\x0074\x0075\x0072\x006E\x0065\x0064\x0020\x0061\x006E\x0020\x0069\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0062\x0061\x0064\x0020\x0068\x0061\x0073\x0068\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 8211 L"\x0054\x0068\x0065\x0020\x006B\x0065\x0079\x0020\x0027\x007B\x0030\x007D\x0027\x0020\x0063\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0066\x006F\x0075\x006E\x0064\x0020\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x0068\x0061\x0073\x0068\x0020\x0074\x0061\x0062\x006C\x0065\x00" + 8212 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0063\x0072\x0065\x0061\x0074\x0065\x0020\x006D\x0075\x0074\x0065\x0078\x00" + 8213 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0063\x006C\x006F\x0073\x0065\x0020\x006D\x0075\x0074\x0065\x0078\x00" + 8214 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x006C\x006F\x0063\x006B\x0020\x006D\x0075\x0074\x0065\x0078\x00" + 8215 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0075\x006E\x006C\x006F\x0063\x006B\x0020\x006D\x0075\x0074\x0065\x0078\x00" + 8216 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0064\x0065\x0073\x0074\x0072\x006F\x0079\x0020\x006D\x0075\x0074\x0065\x0078\x00" + 8217 L"\x0054\x0068\x0065\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x007B\x0030\x007D\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0065\x0078\x0069\x0073\x0074\x0073\x00" + 8218 L"\x0048\x0061\x0073\x0068\x0069\x006E\x0067\x0020\x0074\x0068\x0065\x0020\x006B\x0065\x0079\x0020\x0072\x0065\x0074\x0075\x0072\x006E\x0065\x0064\x0020\x0061\x006E\x0020\x0069\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0062\x0061\x0064\x0020\x0068\x0061\x0073\x0068\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 8219 L"\x0054\x0068\x0065\x0020\x0070\x0061\x0073\x0073\x0065\x0064\x0020\x0069\x0064\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x0076\x0061\x006C\x0069\x0064\x0020\x0066\x006F\x0072\x0020\x0074\x0068\x0069\x0073\x0020\x0070\x006F\x006F\x006C\x00" + 8220 L"\x0054\x0068\x0065\x0020\x006D\x006F\x0064\x0075\x006C\x0075\x0073\x0020\x0076\x0061\x006C\x0075\x0065\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x007A\x0065\x0072\x006F\x00" + 8221 L"\x0054\x0068\x0065\x0020\x0069\x006E\x0064\x0065\x0078\x0020\x0069\x0073\x0020\x0070\x0061\x0073\x0074\x0020\x0074\x0068\x0065\x0020\x0074\x006F\x0070\x0020\x006F\x0066\x0020\x0073\x0074\x0061\x0063\x006B\x00" + 8222 L"\x0054\x0068\x0065\x0020\x0073\x0074\x0061\x0063\x006B\x0020\x0069\x0073\x0020\x0065\x006D\x0070\x0074\x0079\x002C\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0061\x0063\x0063\x0065\x0073\x0073\x0020\x006D\x0065\x006D\x0062\x0065\x0072\x0073\x00" + 8223 L"\x0054\x0068\x0065\x0020\x0074\x0061\x0072\x0067\x0065\x0074\x0020\x0062\x0075\x0066\x0066\x0065\x0072\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0068\x0061\x0076\x0065\x0020\x0061\x0020\x006D\x0061\x0078\x0020\x0073\x0069\x007A\x0065\x0020\x006F\x0066\x0020\x007A\x0065\x0072\x006F\x00" + 8224 L"\x0054\x0068\x0065\x0020\x0067\x0069\x0076\x0065\x006E\x0020\x0072\x0061\x0064\x0069\x0078\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x0073\x0075\x0070\x0070\x006F\x0072\x0074\x0065\x0064\x002E\x0020\x0055\x0073\x0065\x0020\x0032\x002C\x0020\x0038\x002C\x0020\x0031\x0030\x002C\x0020\x006F\x0072\x0020\x0031\x0036\x00" + 8225 L"\x0054\x0068\x0065\x0020\x0074\x0061\x0072\x0067\x0065\x0074\x0020\x0062\x0075\x0066\x0066\x0065\x0072\x0020\x0069\x0073\x0020\x0074\x006F\x006F\x0020\x0073\x006D\x0061\x006C\x006C\x0020\x0074\x006F\x0020\x0061\x0063\x0063\x0065\x0070\x0074\x0020\x0074\x0068\x0065\x0020\x0072\x0065\x0073\x0075\x006C\x0074\x0073\x00" + 8226 L"\x0054\x0068\x0065\x0020\x0073\x0074\x0061\x0072\x0074\x0020\x0069\x006E\x0064\x0065\x0078\x0020\x0069\x0073\x0020\x0070\x0061\x0073\x0074\x0020\x0074\x0068\x0065\x0020\x0065\x006E\x0064\x0020\x006F\x0066\x0020\x0074\x0068\x0065\x0020\x0073\x0074\x0072\x0069\x006E\x0067\x00" + 8227 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0077\x0072\x0069\x0074\x0065\x0020\x0074\x006F\x0020\x0073\x0074\x0061\x006E\x0064\x0061\x0072\x0064\x0020\x0065\x0072\x0072\x00" + 8228 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0077\x0072\x0069\x0074\x0065\x0020\x0074\x006F\x0020\x0073\x0074\x0061\x006E\x0064\x0061\x0072\x0064\x0020\x006F\x0075\x0074\x00" + 8229 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0077\x0072\x0069\x0074\x0065\x0020\x0074\x006F\x0020\x0063\x006F\x006E\x0073\x006F\x006C\x0065\x00" + 8230 L"\x0053\x0074\x0072\x0069\x006E\x0067\x0020\x0070\x006F\x006F\x006C\x0020\x0069\x0064\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x006C\x0065\x0067\x0061\x006C\x00" + 8231 L"\x0054\x0068\x0065\x0020\x0055\x0052\x004C\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0063\x006F\x0072\x0072\x0065\x0063\x0074\x006C\x0079\x0020\x0066\x006F\x0072\x006D\x0065\x0064\x00" + 8232 L"\x0054\x0068\x0065\x0020\x0055\x0052\x004C\x0020\x0075\x0073\x0065\x0064\x0020\x0061\x006E\x0020\x0075\x006E\x0073\x0075\x0070\x0070\x006F\x0072\x0074\x0065\x0064\x0020\x0070\x0072\x006F\x0074\x006F\x0063\x006F\x006C\x00" + 8233 L"\x0055\x006E\x0073\x0075\x0070\x0070\x006F\x0072\x0074\x0065\x0064\x0020\x0055\x0052\x004C\x0020\x0070\x0072\x006F\x0074\x006F\x0063\x006F\x006C\x003A\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 8234 L"\x004F\x006E\x006C\x0079\x0020\x006C\x006F\x0063\x0061\x006C\x0068\x006F\x0073\x0074\x0020\x0069\x0073\x0020\x0073\x0075\x0070\x0070\x006F\x0072\x0074\x0065\x0064\x0020\x0061\x0074\x0020\x0074\x0068\x0069\x0073\x0020\x0074\x0069\x006D\x0065\x00" + 8235 L"\x004E\x006F\x0020\x0070\x0072\x006F\x0074\x006F\x0063\x006F\x006C\x0020\x0070\x0072\x0065\x0066\x0069\x0078\x0020\x0070\x0072\x0065\x0073\x0065\x006E\x0074\x00" + 8236 L"\x0045\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x0020\x002F\x002F\x0020\x0061\x0066\x0074\x0065\x0072\x0020\x0070\x0072\x006F\x0074\x006F\x0063\x006F\x006C\x00" + 8237 L"\x0025\x0020\x006D\x0075\x0073\x0074\x0020\x0062\x0065\x0020\x0066\x006F\x006C\x006C\x006F\x0077\x0065\x0064\x0020\x0062\x0079\x0020\x0074\x0077\x006F\x0020\x0068\x0065\x0078\x0020\x0064\x0069\x0067\x0069\x0074\x0073\x00" + 8238 L"\x0055\x006E\x0074\x0065\x0072\x006D\x0069\x006E\x0061\x0074\x0065\x0064\x0020\x0068\x006F\x0073\x0074\x0020\x0063\x006F\x006D\x0070\x006F\x006E\x0065\x006E\x0074\x00" + 8239 L"\x0054\x0068\x0065\x0020\x0070\x0061\x0073\x0073\x0065\x0064\x0020\x0069\x006E\x0064\x0065\x0078\x0020\x0069\x0073\x0020\x0070\x0061\x0073\x0074\x0020\x0074\x0068\x0065\x0020\x0065\x006E\x0064\x0020\x006F\x0066\x0020\x0074\x0068\x0065\x0020\x0076\x0065\x0063\x0074\x006F\x0072\x00" + 8240 L"\x0050\x0061\x0072\x0073\x0065\x0020\x006D\x0061\x0079\x0020\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0063\x0061\x006C\x006C\x0065\x0064\x0020\x0077\x0068\x0069\x006C\x0065\x0020\x0070\x0061\x0072\x0073\x0069\x006E\x0067\x00" + 8241 L"\x0041\x0020\x0044\x004F\x0043\x0054\x0059\x0050\x0045\x0020\x0077\x0061\x0073\x0020\x0073\x0065\x0065\x006E\x0020\x0062\x0075\x0074\x0020\x0074\x0068\x0065\x0020\x0069\x006E\x0073\x0074\x0061\x006C\x006C\x0065\x0064\x0020\x0076\x0061\x006C\x0069\x0064\x0061\x0074\x006F\x0072\x0020\x0064\x006F\x0065\x0073\x0020\x006E\x006F\x0074\x0020\x0075\x006E\x0064\x0065\x0072\x0073\x0074\x0061\x006E\x0064\x0020\x0044\x0054\x0044\x0073\x00" + 8242 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x006F\x0070\x0065\x006E\x0020\x0044\x0054\x0044\x0020\x0066\x0069\x006C\x0065\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 8243 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x006F\x0070\x0065\x006E\x0020\x0065\x0078\x0074\x0065\x0072\x006E\x0061\x006C\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0027\x007B\x0030\x007D\x0027\x00" + 8244 L"\x0054\x0068\x0065\x0020\x0065\x006E\x0064\x0020\x006F\x0066\x0020\x0069\x006E\x0070\x0075\x0074\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0065\x0078\x0070\x0065\x0063\x0074\x0065\x0064\x00" + 8245 L"\x0054\x0068\x0065\x0020\x0069\x006E\x0064\x0065\x0078\x0020\x0067\x0069\x0076\x0065\x006E\x0020\x0077\x0061\x0073\x0020\x0062\x0065\x0079\x006F\x006E\x0064\x0020\x0074\x0068\x0065\x0020\x006D\x0061\x0078\x0020\x0061\x0074\x0074\x0072\x0069\x0062\x0075\x0074\x0065\x0020\x0069\x006E\x0064\x0065\x0078\x00" + 8246 L"\x0054\x0068\x0065\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0073\x0074\x0061\x0063\x006B\x0020\x0069\x0073\x0020\x0065\x006D\x0070\x0074\x0079\x00" + 8247 L"\x0054\x0068\x0065\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0073\x0074\x0061\x0063\x006B\x0020\x0069\x006E\x0064\x0065\x0078\x0020\x0067\x0069\x0076\x0065\x006E\x0020\x0077\x0061\x0073\x0020\x0062\x0065\x0079\x006F\x006E\x0064\x0020\x0074\x0068\x0065\x0020\x0073\x0074\x0061\x0063\x006B\x0020\x0074\x006F\x0070\x00" + 8248 L"\x0054\x0068\x0065\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0073\x0074\x0061\x0063\x006B\x0020\x0077\x0061\x0073\x0020\x0061\x006C\x0072\x0065\x0061\x0064\x0079\x0020\x0065\x006D\x0070\x0074\x0079\x0020\x0077\x0068\x0065\x006E\x0020\x0061\x0020\x0070\x006F\x0070\x0020\x0072\x0065\x0071\x0075\x0065\x0073\x0074\x0020\x006F\x0063\x0063\x0075\x0072\x0065\x0064\x00" + 8249 L"\x0041\x0020\x0070\x0061\x0072\x0065\x006E\x0074\x0020\x006F\x0070\x0065\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x0077\x0061\x0073\x0020\x0072\x0065\x0071\x0075\x0065\x0073\x0074\x0065\x0064\x002C\x0020\x0062\x0075\x0074\x0020\x006F\x006E\x006C\x0079\x0020\x006F\x006E\x0065\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0069\x0073\x0020\x006F\x006E\x0020\x0074\x0068\x0065\x0020\x0073\x0074\x0061\x0063\x006B\x00" + 8250 L"\x0054\x0068\x0065\x0020\x0069\x006E\x0064\x0069\x0063\x0061\x0074\x0065\x0064\x0020\x0072\x0065\x0061\x0064\x0065\x0072\x0020\x0069\x0064\x0020\x0077\x0061\x0073\x0020\x006E\x0065\x0076\x0065\x0072\x0020\x0066\x006F\x0075\x006E\x0064\x00" + 8251 L"\x0054\x0068\x0065\x0020\x0061\x0075\x0074\x006F\x0020\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x0020\x0065\x006E\x0075\x006D\x0020\x0068\x0061\x0073\x0020\x0061\x006E\x0020\x0075\x006E\x006B\x006E\x006F\x0077\x006E\x0020\x0076\x0061\x006C\x0075\x0065\x00" + 8252 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0063\x0072\x0065\x0061\x0074\x0065\x0020\x0061\x0020\x0063\x006F\x006E\x0076\x0065\x0072\x0074\x0065\x0072\x0020\x0066\x006F\x0072\x0020\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x003A\x0020\x007B\x0030\x007D\x00" + 8253 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0064\x0065\x0063\x006F\x0064\x0065\x0020\x0066\x0069\x0072\x0073\x0074\x0020\x006C\x0069\x006E\x0065\x0020\x006F\x0066\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x003A\x0020\x007B\x0030\x007D\x00" + 8254 L"\x0045\x006E\x0064\x0020\x006F\x0066\x0020\x0069\x006E\x0070\x0075\x0074\x0020\x0077\x0061\x0073\x0020\x0068\x0069\x0074\x0020\x0069\x006E\x0020\x0074\x0068\x0065\x0020\x006D\x0069\x0064\x0064\x006C\x0065\x0020\x006F\x0066\x0020\x0061\x0020\x006D\x0075\x006C\x0074\x0069\x0062\x0079\x0074\x0065\x0020\x0073\x0065\x0071\x0075\x0065\x006E\x0063\x0065\x00" + 8255 L"\x0054\x0068\x0069\x0073\x0020\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x0020\x0028\x007B\x0030\x007D\x0029\x0073\x0068\x006F\x0075\x006C\x0064\x0020\x0068\x0061\x0076\x0065\x0020\x0068\x0061\x0064\x0020\x0061\x0020\x0074\x0072\x0061\x006E\x0073\x0063\x006F\x0064\x0065\x0072\x00" + 8256 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0073\x0065\x0063\x006F\x006E\x0064\x0020\x0062\x0079\x0074\x0065\x0020\x006F\x0066\x0020\x0061\x0020\x0055\x0054\x0046\x002D\x0038\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0073\x0065\x0071\x0075\x0065\x006E\x0063\x0065\x00" + 8257 L"\x0049\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0073\x0075\x0072\x0072\x006F\x0067\x0061\x0074\x0065\x0020\x0063\x0068\x0061\x0072\x0061\x0063\x0074\x0065\x0072\x0020\x0066\x006F\x0075\x006E\x0064\x0020\x0069\x006E\x0020\x0055\x0054\x0046\x002D\x0038\x0020\x0064\x0061\x0074\x0061\x00" + 8258 L"\x0054\x0068\x0065\x0020\x0070\x0072\x0069\x006D\x0061\x0072\x0079\x0020\x0064\x006F\x0063\x0075\x006D\x0065\x006E\x0074\x0020\x0065\x006E\x0074\x0069\x0074\x0079\x0020\x0063\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x006F\x0070\x0065\x006E\x0065\x0064\x002E\x0020\x0049\x0064\x003D\x007B\x0030\x007D\x00" + 8259 L"\x0055\x006E\x0062\x0061\x006C\x0061\x006E\x0063\x0065\x0064\x0020\x0073\x0074\x0061\x0072\x0074\x002F\x0065\x006E\x0064\x0020\x0074\x0061\x0067\x0073\x0020\x0066\x006F\x0075\x006E\x0064\x002C\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0063\x006F\x006E\x0074\x0069\x006E\x0075\x0065\x00" + 8260 L"\x0054\x0068\x0065\x0020\x0070\x0061\x0073\x0073\x0065\x0064\x0020\x0041\x0074\x0074\x0054\x0079\x0070\x0065\x0073\x0020\x0076\x0061\x006C\x0075\x0065\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x006B\x006E\x006F\x0077\x006E\x00" + 8261 L"\x0054\x0068\x0065\x0020\x0070\x0061\x0073\x0073\x0065\x0064\x0020\x0044\x0065\x0066\x0041\x0074\x0074\x0054\x0079\x0070\x0065\x0073\x0020\x0076\x0061\x006C\x0075\x0065\x0020\x0069\x0073\x0020\x006E\x006F\x0074\x0020\x006B\x006E\x006F\x0077\x006E\x00" + 8262 L"\x0054\x0068\x0065\x0020\x0062\x0075\x0066\x0066\x0065\x0072\x0020\x006D\x0061\x006E\x0061\x0067\x0065\x0072\x0020\x0063\x0061\x006E\x006E\x006F\x0074\x0020\x0070\x0072\x006F\x0076\x0069\x0064\x0065\x0020\x0061\x006E\x0079\x0020\x006D\x006F\x0072\x0065\x0020\x0062\x0075\x0066\x0066\x0065\x0072\x0073\x00" + 8263 L"\x0054\x0068\x0065\x0020\x0070\x0061\x0073\x0073\x0065\x0064\x0020\x0062\x0075\x0066\x0066\x0065\x0072\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x0066\x006F\x0075\x006E\x0064\x0020\x0069\x006E\x0020\x0074\x0068\x0069\x0073\x0020\x006D\x0061\x006E\x0061\x0067\x0065\x0072\x0027\x0073\x0020\x0070\x006F\x006F\x006C\x00" + 8264 L"\x0054\x0068\x0065\x0020\x0070\x0061\x0073\x0073\x0065\x0064\x0020\x0072\x0065\x0063\x006F\x0067\x006E\x0069\x007A\x0065\x0072\x0020\x0065\x006E\x0063\x006F\x0064\x0069\x006E\x0067\x0020\x0077\x0061\x0073\x0020\x006E\x006F\x0074\x0020\x006B\x006E\x006F\x0077\x006E\x00" + 8265 L"\x0054\x0068\x0065\x0020\x0062\x006C\x006F\x0063\x006B\x0020\x006F\x0066\x0020\x0058\x004D\x004C\x0020\x0064\x0061\x0074\x0061\x0020\x0063\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0062\x0065\x0020\x0074\x0072\x0061\x006E\x0073\x0063\x006F\x0064\x0065\x0064\x00" + 8266 L"\x0043\x006F\x0075\x006C\x0064\x0020\x006E\x006F\x0074\x0020\x0063\x0072\x0065\x0061\x0074\x0065\x0020\x0061\x0020\x0064\x0065\x0066\x0061\x0075\x006C\x0074\x0020\x0074\x0072\x0061\x006E\x0073\x0063\x006F\x0064\x0065\x0072\x00" + 8267 L"\x0054\x0068\x0065\x0020\x0062\x0069\x006E\x0061\x0072\x0079\x0020\x006F\x0070\x0065\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x006E\x006F\x0064\x0065\x0020\x0068\x0061\x0064\x0020\x0061\x0020\x0075\x006E\x0061\x0072\x0079\x0020\x006E\x006F\x0064\x0065\x0020\x0074\x0079\x0070\x0065\x00" + 8268 L"\x0054\x0068\x0065\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x0074\x0079\x0070\x0065\x0020\x006D\x0075\x0073\x0074\x0020\x0062\x0065\x0020\x006D\x0069\x0078\x0065\x0064\x0020\x006F\x0072\x0020\x0063\x0068\x0069\x006C\x0064\x0072\x0065\x006E\x00" + 8269 L"\x0050\x0043\x0044\x0041\x0054\x0041\x0020\x006E\x006F\x0064\x0065\x0073\x0020\x0061\x0072\x0065\x0020\x006E\x006F\x0074\x0020\x0076\x0061\x006C\x0069\x0064\x0020\x0068\x0065\x0072\x0065\x00" + 8270 L"\x0054\x0068\x0065\x0020\x007B\x0030\x007D\x0020\x006F\x0070\x0065\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x0069\x0073\x0020\x0069\x006E\x0076\x0061\x006C\x0069\x0064\x0020\x0066\x006F\x0072\x0020\x0074\x0068\x0065\x0020\x0073\x0070\x0065\x0063\x0020\x0074\x0079\x0070\x0065\x00" + 8271 L"\x0054\x0068\x0065\x0020\x0075\x006E\x0061\x0072\x0079\x0020\x006F\x0070\x0065\x0072\x0061\x0074\x0069\x006F\x006E\x0020\x006E\x006F\x0064\x0065\x0020\x0068\x0061\x0064\x0020\x0061\x0020\x0062\x0069\x006E\x0061\x0072\x0079\x0020\x006E\x006F\x0064\x0065\x0020\x0074\x0079\x0070\x0065\x00" + 8272 L"\x0055\x006E\x006B\x006E\x006F\x0077\x006E\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x006D\x006F\x0064\x0065\x006C\x0020\x0074\x0079\x0070\x0065\x00" + 8273 L"\x0055\x006E\x006B\x006E\x006F\x0077\x006E\x0020\x0063\x006F\x006E\x0074\x0065\x006E\x0074\x0020\x0073\x0070\x0065\x0063\x0020\x0074\x0079\x0070\x0065\x00" + 8274 L"\x0054\x0068\x0065\x0020\x0065\x006C\x0065\x006D\x0065\x006E\x0074\x0020\x0069\x0064\x0020\x0077\x0061\x0073\x0020\x0069\x006E\x0076\x0061\x006C\x0069\x0064\x00" + 8275 L"\x0054\x0068\x0065\x0020\x0063\x0061\x006C\x006C\x0020\x0074\x006F\x0020\x0073\x0063\x0061\x006E\x004E\x0065\x0078\x0074\x0028\x0029\x0020\x0069\x0073\x0020\x0069\x006C\x006C\x0065\x0067\x0061\x006C\x0020\x0061\x0074\x0020\x0074\x0068\x0069\x0073\x0020\x0074\x0069\x006D\x0065\x00" +END + + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// diff --git a/src/util/Platforms/Win32/Win32Defs.hpp b/src/util/Platforms/Win32/Win32Defs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4991d4c8066c415de2f2bff05d4e18e9cabf3f1e --- /dev/null +++ b/src/util/Platforms/Win32/Win32Defs.hpp @@ -0,0 +1,78 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:20 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:33 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// NT and Win98 always run the CPU in little endian mode. +// --------------------------------------------------------------------------- +#define ENDIANMODE_LITTLE + + +// --------------------------------------------------------------------------- +// Define all the required platform types. For Win32, void* is interoperable +// with the HANDLE type. +// --------------------------------------------------------------------------- +typedef void* FileHandle; diff --git a/src/util/Platforms/Win32/Win32PlatformUtils.cpp b/src/util/Platforms/Win32/Win32PlatformUtils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49ca030e0679d17e77af89f2b853df4280e31e06 --- /dev/null +++ b/src/util/Platforms/Win32/Win32PlatformUtils.cpp @@ -0,0 +1,796 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:21 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:33 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Janitor.hpp> +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/XMLExceptMsgs.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> +#include <windows.h> + +#if defined (XML_USE_ICU_TRANSCODER) + #include <util/Transcoders/ICU/ICUTransService.hpp> +#elif defined (XML_USE_WIN32_TRANSCODER) + #include <util/Transcoders/Win32/Win32TransService.hpp> +#else + #error A transcoding service must be chosen +#endif + +#if defined (XML_USE_INMEMORY_MSGLOADER) + #include <util/MsgLoaders/InMemory/InMemMsgLoader.hpp> +#elif defined (XML_USE_WIN32_MSGLOADER) + #include <util/MsgLoaders/Win32/Win32MsgLoader.hpp> +#else + #error A message loading service must be chosen +#endif + + +// --------------------------------------------------------------------------- +// Local data +// +// gOnNT +// We figure out during init if we are on NT or not. If we are, then +// we can avoid a lot of transcoding in our system services stuff. +// +// gStdErr +// gStdOut +// The file handles for standard error and standard out. We set these +// up during init. Note that they can be zero if there are no std +// handles, +// +// gStdErrRedir +// gStdOutRedir +// These flags are set to indicate whether their respective output +// handles are redirected. If they are not, then we can use console +// APIs on NT to write Unicode straight to the output. Otherwise we have +// to use file APIs, and we transcode it. +// --------------------------------------------------------------------------- +static bool gOnNT; +static HANDLE gStdErr; +static bool gStdErrRedir; +static HANDLE gStdOut; +static bool gStdOutRedir; + + +// --------------------------------------------------------------------------- +// Local methods +// --------------------------------------------------------------------------- +static void WriteCharStrStdErr(const char* const toWrite) +{ + // We always just use the file APIs for these + DWORD written; + if (!::WriteFile + ( + gStdErr + , toWrite + , strlen(toWrite) + , &written + , 0)) + { + // + // If if fails due to an invalid handle, then just assume that our + // handles were disconnected and zero it out. This will prevent us + // from getting called again. + // + if (::GetLastError() == ERROR_INVALID_HANDLE) + gStdErr = 0; + else + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_StdErrWriteFailure); + } +} + + +static void WriteCharStrStdOut(const char* const toWrite) +{ + // We always just use the file APIs for these + DWORD written; + if (!::WriteFile + ( + gStdOut + , toWrite + , strlen(toWrite) + , &written + , 0)) + { + // + // If if fails due to an invalid handle, then just assume that our + // handles were disconnected and zero it out. This will prevent us + // from getting called again. + // + if (::GetLastError() == ERROR_INVALID_HANDLE) + gStdOut = 0; + else + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_StdOutWriteFailure); + } +} + + +static void WriteUStrStdErr(const XMLCh* const toWrite) +{ + // + // If we are on NT and the handle is not redirected, then we can use + // the console API directly to send out Unicode. Otherwise we have to + // use the file APIs and transcode. + // + DWORD written; + if (gOnNT && !gStdErrRedir) + { + if (!::WriteConsoleW + ( + gStdErr + , toWrite + , XMLString::stringLen(toWrite) + , &written + , 0)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_ConWriteFailure); + } + return; + } + + // Oh well, got to do it the hard way + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janTmp(tmpVal); + WriteCharStrStdErr(tmpVal); +} + + +static void WriteUStrStdOut(const XMLCh* const toWrite) +{ + // + // If we are on NT and the handle is not redirected, then we can use + // the console API directly to send out Unicode. Otherwise we have to + // use the file APIs and transcode. + // + DWORD written; + if (gOnNT && !gStdOutRedir) + { + if (!::WriteConsoleW + ( + gStdOut + , toWrite + , XMLString::stringLen(toWrite) + , &written + , 0)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Strm_ConWriteFailure); + } + return; + } + + // Oh well, got to do it the hard way + char* tmpVal = XMLString::transcode(toWrite); + ArrayJanitor<char> janTmp(tmpVal); + WriteCharStrStdOut(tmpVal); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: The panic method +// --------------------------------------------------------------------------- +void XMLPlatformUtils::panic(const PanicReasons reason) +{ + const char* reasonStr = "Uknown 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 XML4C DLL"; + else if (reason == Panic_UnknownMsgDomain) + reasonStr = "Unknown message domain"; + else if (reason == Panic_CantLoadMsgDomain) + reasonStr = "Cannot load message domain"; + + // + // We just do a popup and exit. Replace this code to do whatever + // you need to do. + // + MessageBoxA + ( + 0 + , "XML4C Panic Error" + , reasonStr + , MB_OK | MB_ICONSTOP + ); + exit(-1); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +unsigned int XMLPlatformUtils::curFilePos(FileHandle theFile) +{ + // Get the current position + const unsigned int curPos = ::SetFilePointer(theFile, 0, 0, FILE_CURRENT); + if (curPos == 0xFFFFFFFF) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetCurPos); + + return curPos; +} + +void XMLPlatformUtils::closeFile(FileHandle theFile) +{ + if (!::CloseHandle(theFile)) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotCloseFile); +} + +unsigned int XMLPlatformUtils::fileSize(const FileHandle theFile) +{ + // Get the current position + const unsigned int curPos = ::SetFilePointer(theFile, 0, 0, FILE_CURRENT); + if (curPos == 0xFFFFFFFF) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotGetCurPos); + + // Seek to the end and save that value for return + const unsigned int retVal = ::SetFilePointer(theFile, 0, 0, FILE_END); + if (curPos == 0xFFFFFFFF) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToEnd); + + // And put the pointer back + if (::SetFilePointer(theFile, curPos, 0, FILE_BEGIN) == 0xFFFFFFFF) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotSeekToPos); + + return retVal; +} + +FileHandle XMLPlatformUtils::openFile(const char* const fileName) +{ + FileHandle retVal = ::CreateFileA + ( + fileName + , GENERIC_READ + , FILE_SHARE_READ + , 0 + , OPEN_EXISTING + , FILE_FLAG_SEQUENTIAL_SCAN + , 0 + ); + + if (retVal == INVALID_HANDLE_VALUE) + return 0; + + return retVal; +} + +FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName) +{ + FileHandle retVal = 0; + if (gOnNT) + { + retVal = ::CreateFileW + ( + fileName + , GENERIC_READ + , FILE_SHARE_READ + , 0 + , OPEN_EXISTING + , FILE_FLAG_SEQUENTIAL_SCAN + , 0 + ); + } + else + { + char* tmpName = XMLString::transcode(fileName); + retVal = ::CreateFileA + ( + tmpName + , GENERIC_READ + , FILE_SHARE_READ + , 0 + , OPEN_EXISTING + , FILE_FLAG_SEQUENTIAL_SCAN + , 0 + ); + delete [] tmpName; + } + + if (retVal == INVALID_HANDLE_VALUE) + return 0; + + return retVal; +} + + +FileHandle XMLPlatformUtils::openStdInHandle() +{ + // + // Get the standard input handle. Duplicate it and return that copy + // since the outside world cannot tell the difference and will shut + // down this handle when its done with it. If we gave out the orignal, + // shutting it would prevent any further output. + // + HANDLE stdInOrg = ::GetStdHandle(STD_INPUT_HANDLE); + if (stdInOrg == INVALID_HANDLE_VALUE) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotOpenFile); + + HANDLE retHandle; + if (!::DuplicateHandle + ( + ::GetCurrentProcess() + , stdInOrg + , ::GetCurrentProcess() + , &retHandle + , 0 + , FALSE + , DUPLICATE_SAME_ACCESS)) + { + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotDupHandle); + } + return retHandle; +} + + +unsigned int +XMLPlatformUtils::readFileBuffer( FileHandle theFile + , const unsigned int toRead + , XMLByte* const toFill) +{ + unsigned long bytesRead; + if (!::ReadFile(theFile, toFill, toRead, &bytesRead, 0)) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotReadFromFile); + return (unsigned int)bytesRead; +} + + +void XMLPlatformUtils::resetFile(FileHandle theFile) +{ + // Seek to the start of the file + if (::SetFilePointer(theFile, 0, 0, FILE_BEGIN) == 0xFFFFFFFF) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::File_CouldNotResetFile); +} + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File Methods +// --------------------------------------------------------------------------- +void XMLPlatformUtils::writeToStdErr(const XMLCh* const toWrite) +{ + // If handles never got opened, then eat the output, else output + if (gStdErr) + WriteUStrStdErr(toWrite); +} + +void XMLPlatformUtils::writeToStdErr(const char* const toWrite) +{ + // If handles never got opened, then eat the output, else output + if (gStdErr) + WriteCharStrStdErr(toWrite); +} + +void XMLPlatformUtils::writeToStdOut(const XMLCh* const toWrite) +{ + // If handles never got opened, then eat the output, else output + if (gStdOut) + WriteUStrStdOut(toWrite); +} + +void XMLPlatformUtils::writeToStdOut(const char* const toWrite) +{ + // If handles never got opened, then eat the output, else output + if (gStdOut) + WriteCharStrStdOut(toWrite); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: File system methods +// --------------------------------------------------------------------------- +XMLCh* XMLPlatformUtils::getBasePath(const XMLCh* const srcPath) +{ + // + // NOTE: THe path provided has always already been opened successfully, + // so we know that its not some pathological freaky path. + // + // If we are on NT, then use wide character APIs, else use ASCII APIs. + // We have to do it manually since we are only built in ASCII mode from + // the standpoint of the APIs. + // + if (gOnNT) + { + // Use a local buffer that is big enough for the largest legal path + const unsigned int bufSize = 1024; + XMLCh tmpPath[bufSize + 1]; + + XMLCh* namePart = 0; + if (!::GetFullPathNameW(srcPath, bufSize, tmpPath, &namePart)) + return 0; + + // Cap it off at the name part, leaving just the full path + if (namePart) + *namePart = 0; + + // Return a copy of the path + return XMLString::replicate(tmpPath); + } + else + { + // Transcode the incoming string + char* tmpSrcPath = XMLString::transcode(srcPath); + ArrayJanitor<char> janSrcPath(tmpSrcPath); + + // Use a local buffer that is big enough for the largest legal path + const unsigned int bufSize = 511; + char tmpPath[511 + 1]; + + char* namePart = 0; + if (!::GetFullPathNameA(tmpSrcPath, bufSize, tmpPath, &namePart)) + return 0; + + // Cap it off at the name part, leaving just the full path + if (namePart) + *namePart = 0; + + // Return a transcoded copy of the path + return XMLString::transcode(tmpPath); + } +} + +bool XMLPlatformUtils::isRelative(const XMLCh* const toCheck) +{ + // Check for pathological case of empty path + if (!toCheck[0]) + return false; + + // + // If its starts with a drive, then it cannot be relative. Note that + // we checked the drive not being empty above, so worst case its one + // char long and the check of the 1st char will fail because its really + // a null character. + // + if (toCheck[1] == chColon) + { + if (((toCheck[0] >= chLatin_A) && (toCheck[0] <= chLatin_Z)) + || ((toCheck[0] >= chLatin_a) && (toCheck[0] <= chLatin_z))) + { + return false; + } + } + + // + // If it starts with a double slash, then it cannot be relative since + // its a remote file. + // + if ((toCheck[0] == chBackSlash) && (toCheck[1] == chBackSlash)) + return false; + + // Else assume its a relative path + return true; +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Timing Methods +// --------------------------------------------------------------------------- +unsigned long XMLPlatformUtils::getCurrentMillis() +{ + return (unsigned long)::GetTickCount(); +} + + + +// --------------------------------------------------------------------------- +// Mutex methods +// --------------------------------------------------------------------------- +void XMLPlatformUtils::closeMutex(void* const mtxHandle) +{ + if (!::CloseHandle(mtxHandle)) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotClose); +} + + +void XMLPlatformUtils::lockMutex(void* const mtxHandle) +{ + unsigned int res = ::WaitForSingleObject(mtxHandle, INFINITE); + if (res == WAIT_FAILED) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotLock); +} + + +void* XMLPlatformUtils::makeMutex() +{ + HANDLE hRet = ::CreateMutex(0, 0, 0); + if (!hRet) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotCreate); + return hRet; +} + + +void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +{ + if (!::ReleaseMutex(mtxHandle)) + ThrowXML(XMLPlatformUtilsException, XML4CExcepts::Mutex_CouldNotUnlock); +} + + +// --------------------------------------------------------------------------- +// Miscellaneous synchronization methods +// --------------------------------------------------------------------------- +void* +XMLPlatformUtils::compareAndSwap( void** toFill + , const void* const newValue + , const void* const toCompare) +{ + // + // Windows supports InterlockedCompareExchange only on Windows 98, NT 4.0, + // and newer. Not on Win 95. So we are back to using assembler. + // + #if defined(DEVENV_VCPP) + + void* result; + __asm + { + mov eax, toCompare; + mov ebx, newValue; + mov ecx, toFill + lock cmpxchg [ecx], ebx; + mov result, eax; + } + return result; + + #elif defined(XML_IBMVAW32) + + // <TBD> Why is this not using the interlocked call below? + void *retval = *toFill; + if( *toFill == toCompare) + *toFill = (void *) newValue; + return retVal; + + #else + + // + // Note we have to cast off the constness of some of these because + // the system APIs are not C++ aware in all cases. + // + return ::InterlockedCompareExchange + ( + toFill + , (void*)newValue + , (void*)toCompare + ); + + #endif +} + + +// --------------------------------------------------------------------------- +// Atomic increment and decrement methods +// --------------------------------------------------------------------------- +int XMLPlatformUtils::atomicIncrement(int &location) +{ + return ::InterlockedIncrement(&(long &)location); +} + + +int XMLPlatformUtils::atomicDecrement(int &location) +{ + return ::InterlockedDecrement(&(long &)location); +} + + + +// --------------------------------------------------------------------------- +// XMLPlatformUtils: Private Static Methods +// --------------------------------------------------------------------------- + +// +// This method is called by the platform independent part of this class +// during initialization. We have to create the type of net accessor that +// we want to use. +// +// <TBD> For now we return zero, but later we will return the desired type +// of accessor object. +// +XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() +{ + return 0; +} + + +// +// 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. +// In our case, we use the ICU based message loader mechanism. +// +XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) +{ +#if defined (XML_USE_INMEMORY_MSGLOADER) + return new InMemMsgLoader(msgDomain); +#elif defined (XML_USE_WIN32_MSGLOADER) + return new Win32MsgLoader(msgDomain); +#else + #error You must provide a message loader +#endif +} + + +// +// 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() +{ + // + // Since we are going to use the ICU service, we have to tell it where + // its converter files are. If the ICU_DATA environment variable is set, + // then its been told. Otherwise, we tell it our default value relative + // to our DLL. + // +#if defined (XML_USE_ICU_TRANSCODER) + char tmpBuf[4096]; + if (!::GetEnvironmentVariableA("ICU_DATA", tmpBuf, 4096)) + { + strcpy(tmpBuf, fgLibLocation); + strcat(tmpBuf, "intlFiles\\Locales\\"); + ICUTransService::setICUPath(tmpBuf); + } + return new ICUTransService; +#elif defined (XML_USE_WIN32_TRANSCODER) + return new Win32TransService; +#else + #error You must provide a transcoding service implementation +#endif +} + + +// +// This method handles the Win32 per-platform basic init functions. The +// primary jobs here are getting the path to our DLL and to get the +// stdout and stderr file handles setup. +// +void XMLPlatformUtils::platformInit() +{ + // + // Lets get our own DLL path and store it. The fgLibLocation static + // member must be filled in with the path to the shared Lib or DLL + // so that other code can find any files relative to it. + // + HINSTANCE hmod = ::GetModuleHandleA(XML4C_DLLName); + if (!hmod) + { + // + // If we didn't find it, its probably because its a development + // build which is built as separate DLLs, so lets look for the DLL + // that we are part of. + // + static const char* const privDLLName = "IXUTIL"; + hmod = ::GetModuleHandle(privDLLName); + + // If neither exists, then we give up + if (!hmod) + panic(Panic_CantFindLib); + } + + // + // Get the path to our module. We explicitly get the ASCII version here + // since its stored as ASCII (or the local code page to be more specific, + // so it might be EBCDIC on some platforms.) + // + char tmpBuf[MAX_PATH + 1]; + if (!::GetModuleFileNameA(hmod, tmpBuf, MAX_PATH)) + panic(Panic_CantFindLib); + + // Find the last separator in the list and put a null in the next char + char* sepPtr = 0; + sepPtr = strrchr(tmpBuf, '\\'); + if (sepPtr) + *(sepPtr+1)= 0; + const unsigned int pathLen = strlen(tmpBuf); + + // Allocate a buffer and copy the text into it. Then store it in the static + char* actualBuf = new char[pathLen + 1]; + strcpy(actualBuf, tmpBuf); + fgLibLocation = actualBuf; + + // + // Figure out if we are on NT and save that flag for later use. + // + OSVERSIONINFO OSVer; + OSVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + ::GetVersionEx(&OSVer); + gOnNT = (OSVer.dwPlatformId == VER_PLATFORM_WIN32_NT); + + // + // Ok, we have to do a little dance here to determine if we have any + // standard output handles. First we open up the potentially redirected + // standard handles. + // + gStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE); + gStdErr = ::GetStdHandle(STD_ERROR_HANDLE); + + // + // If we got the handles, then get the console mode for them. If this + // fails, then assume for the time being that they are just redirected + // files. + // + // Above, when they are actually used, if they fail because of an + // invalid handle error, the gStdOut and gStdErr handles will get zeroed + // out all further output will be eaten. + // + DWORD dummyParm; + if (gStdOut) + { + if (!::GetConsoleMode(gStdOut, &dummyParm)) + gStdOutRedir = true; + } + + if (gStdErr) + { + if (!::GetConsoleMode(gStdErr, &dummyParm)) + gStdErrRedir = true; + } +} diff --git a/src/util/Platforms/Win32/resource.h b/src/util/Platforms/Win32/resource.h new file mode 100644 index 0000000000000000000000000000000000000000..1ef17fde3ad6a2b25c61337a1078c64fccbf4163 --- /dev/null +++ b/src/util/Platforms/Win32/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by Version.rc +// +#define DummyString 1 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/src/util/RefArrayOf.c b/src/util/RefArrayOf.c new file mode 100644 index 0000000000000000000000000000000000000000..e578f516f636f183693a69ccc6601f733448f7b5 --- /dev/null +++ b/src/util/RefArrayOf.c @@ -0,0 +1,301 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:56 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:12 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/RefArrayOf.hpp> +#endif + + +// --------------------------------------------------------------------------- +// RefArrayOf: Contructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> RefArrayOf<TElem>::RefArrayOf(const unsigned int size) : + + fSize(size) + , fArray(0) +{ + fArray = new TElem*[fSize]; + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = 0; +} + +template <class TElem> RefArrayOf<TElem>:: +RefArrayOf(TElem* values[], const unsigned int size) : + + fSize(size) + , fArray(0) +{ + fArray = new TElem*[fSize]; + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = values[index]; +} + +template <class TElem> RefArrayOf<TElem>:: +RefArrayOf(const RefArrayOf<TElem>& source) : + + fSize(source.fSize) + , fArray(0) +{ + fArray = new TElem*[fSize]; + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = source.fArray[index]; +} + +template <class TElem> RefArrayOf<TElem>::~RefArrayOf() +{ + delete [] fArray; +} + + +// --------------------------------------------------------------------------- +// RefArrayOf: Public operators +// --------------------------------------------------------------------------- +template <class TElem> TElem*& RefArrayOf<TElem>:: +operator[](const unsigned int index) +{ + if (index >= fSize) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Array_BadIndex); + return fArray[index]; +} + +template <class TElem> const TElem* RefArrayOf<TElem>:: +operator[](const unsigned int index) const +{ + if (index >= fSize) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Array_BadIndex); + return fArray[index]; +} + +template <class TElem> RefArrayOf<TElem>& RefArrayOf<TElem>:: +operator=(const RefArrayOf<TElem>& toAssign) +{ + if (this == &toAssign) + return *this; + + // Reallocate if not the same size + if (toAssign.fSize != fSize) + { + delete [] fArray; + fSize = toAssign.fSize; + fArray = new TElem*[fSize]; + } + + // Copy over the source elements + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = toAssign.fArray[index]; + + return *this; +} + +template <class TElem> bool RefArrayOf<TElem>:: +operator==(const RefArrayOf<TElem>& toCompare) const +{ + if (this == &toCompare) + return true; + + if (fSize != toCompare.fSize) + return false; + + for (unsigned int index = 0; index < fSize; index++) + { + if (fArray[index] != toCompare.fArray[index]) + return false; + } + return true; +} + +template <class TElem> bool RefArrayOf<TElem>:: +operator!=(const RefArrayOf<TElem>& toCompare) const +{ + return !operator==(toCompare); +} + + +// --------------------------------------------------------------------------- +// RefArrayOf: Copy operations +// --------------------------------------------------------------------------- +template <class TElem> unsigned int RefArrayOf<TElem>:: +copyFrom(const RefArrayOf<TElem>& srcArray) +{ + // + // Copy over as many of the source elements as will fit into + // this array. + // + const unsigned int count = fSize < srcArray.fSize ? + fSize : srcArray.fSize; + + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = srcArray.fArray[index]; + + return count; +} + + +// --------------------------------------------------------------------------- +// RefArrayOf: Getter methods +// --------------------------------------------------------------------------- +template <class TElem> unsigned int RefArrayOf<TElem>::length() const +{ + return fSize; +} + +template <class TElem> TElem** RefArrayOf<TElem>::rawData() const +{ + return fArray; +} + + +// --------------------------------------------------------------------------- +// RefArrayOf: Element management methods +// --------------------------------------------------------------------------- +template <class TElem> void RefArrayOf<TElem>::deleteAt(const unsigned int index) +{ + if (index >= fSize) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Array_BadIndex); + + delete fArray[index]; + fArray[index] = 0; +} + +template <class TElem> void RefArrayOf<TElem>::deleteAllElements() +{ + for (unsigned int index = 0; index < fSize; index++) + { + delete fArray[index]; + fArray[index] = 0; + } +} + +template <class TElem> void RefArrayOf<TElem>::resize(const unsigned int newSize) +{ + if (newSize == fSize) + return; + + if (newSize < fSize) + ThrowXML(IllegalArgumentException, XML4CExcepts::Array_BadNewSize); + + // Allocate the new array + TElem** newArray = new TElem*[newSize]; + + // Copy the existing values + unsigned int index = 0; + for (; index < fSize; index++) + newArray[index] = fArray[index]; + + for (; index < newSize; index++) + newArray[index] = 0; + + // Delete the old array and udpate our members + delete [] fArray; + fArray = newArray; + fSize = newSize; +} + + + + +// --------------------------------------------------------------------------- +// RefArrayEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> RefArrayEnumerator<TElem>:: +RefArrayEnumerator( RefArrayOf<TElem>* const toEnum + , const bool adopt) : + fAdopted(adopt) + , fCurIndex(0) + , fToEnum(toEnum) +{ +} + +template <class TElem> RefArrayEnumerator<TElem>::~RefArrayEnumerator() +{ + if (fAdopted) + delete fToEnum; +} + + +// --------------------------------------------------------------------------- +// RefArrayEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TElem> bool RefArrayEnumerator<TElem>::hasMoreElements() const +{ + if (fCurIndex >= fToEnum->length()) + return false; + return true; +} + +template <class TElem> TElem& RefArrayEnumerator<TElem>::nextElement() +{ + return *(*fToEnum)[fCurIndex++]; +} + +template <class TElem> void RefArrayEnumerator<TElem>::Reset() +{ + fCurIndex = 0; +} diff --git a/src/util/RefArrayOf.hpp b/src/util/RefArrayOf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5cdba74a9ee1835970f6796b2395ca8b95b51a74 --- /dev/null +++ b/src/util/RefArrayOf.hpp @@ -0,0 +1,179 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:57 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:12 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(REFARRAY_HPP) +#define REFARRAY_HPP + +#include <util/XML4CDefs.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/IllegalArgumentException.hpp> +#include <util/XMLEnumerator.hpp> + + +template <class TElem> class RefArrayOf +{ +public : + // ----------------------------------------------------------------------- + // Contructors and Destructor + // ----------------------------------------------------------------------- + RefArrayOf(const unsigned int size); + RefArrayOf(TElem* values[], const unsigned int size); + RefArrayOf(const RefArrayOf<TElem>& source); + ~RefArrayOf(); + + + // ----------------------------------------------------------------------- + // Public operators + // ----------------------------------------------------------------------- + TElem*& operator[](const unsigned int index); + const TElem* operator[](const unsigned int index) const; + RefArrayOf<TElem>& operator=(const RefArrayOf<TElem>& toAssign); + bool operator==(const RefArrayOf<TElem>& toCompare) const; + bool operator!=(const RefArrayOf<TElem>& toCompare) const; + + + // ----------------------------------------------------------------------- + // Copy operations + // ----------------------------------------------------------------------- + unsigned int copyFrom(const RefArrayOf<TElem>& srcArray); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + unsigned int length() const; + TElem** rawData() const; + + + // ----------------------------------------------------------------------- + // Element management methods + // ----------------------------------------------------------------------- + void deleteAt(const unsigned int index); + void deleteAllElements(); + void resize(const unsigned int newSize); + + +private : + // ----------------------------------------------------------------------- + // Data members + // ----------------------------------------------------------------------- + unsigned int fSize; + TElem** fArray; +}; + + +// +// An enumerator for a reference array. It derives from the basic enumerator +// class, so that value vectors can be generically enumerated. +// +template <class TElem> class RefArrayEnumerator : public XMLEnumerator<TElem> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RefArrayEnumerator + ( + RefArrayOf<TElem>* const toEnum + , const bool adopt = false + ); + ~RefArrayEnumerator(); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TElem& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Data Members + // + // fAdopted + // Indicates whether we have adopted the passed array. If so then + // we delete it when we are destroyed. + // + // fCurIndex + // This is the current index into the array. + // + // fToEnum + // The reference array being enumerated. + // ----------------------------------------------------------------------- + bool fAdopted; + unsigned int fCurIndex; + RefArrayOf<TElem>* fToEnum; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/RefArrayOf.c> +#endif + +#endif diff --git a/src/util/RefHashTableOf.c b/src/util/RefHashTableOf.c new file mode 100644 index 0000000000000000000000000000000000000000..e97e0a0e50f1e6947641bfabcc89788ba43980b9 --- /dev/null +++ b/src/util/RefHashTableOf.c @@ -0,0 +1,418 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:59 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:12 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Include +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/RefHashTableOf.hpp> +#endif + + +// --------------------------------------------------------------------------- +// RefHashTableOf: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TVal> RefHashTableOf<TVal>:: +RefHashTableOf( const unsigned int modulus + , const bool adoptElems) : + + fAdoptedElems(adoptElems) + , fBucketList(0) + , fHashModulus(modulus) +{ + if (modulus == 0) + ThrowXML(IllegalArgumentException, XML4CExcepts::HshTbl_ZeroModulus); + + // Allocate the bucket list and zero them + fBucketList = new RefHashTableBucketElem<TVal>*[fHashModulus]; + for (unsigned int index = 0; index < fHashModulus; index++) + fBucketList[index] = 0; +} + +template <class TVal> RefHashTableOf<TVal>::~RefHashTableOf() +{ + removeAll(); + + // Then delete the bucket list + delete [] fBucketList; +} + + +// --------------------------------------------------------------------------- +// RefHashTableOf: Element management +// --------------------------------------------------------------------------- +template <class TVal> bool RefHashTableOf<TVal>::isEmpty() const +{ + // Just check the bucket list for non-empty elements + for (unsigned int buckInd = 0; buckInd < fHashModulus; buckInd++) + { + if (fBucketList[buckInd] != 0) + return false; + } + return true; +} + +template <class TVal> bool RefHashTableOf<TVal>:: +containsKey(const XMLCh* const key) const +{ + unsigned int hashVal; + const RefHashTableBucketElem<TVal>* findIt = findBucketElem(key, hashVal); + return (findIt != 0); +} + +template <class TVal> void RefHashTableOf<TVal>:: +removeKey(const XMLCh* const key) +{ + unsigned int hashVal; + removeBucketElem(key, hashVal); +} + +template <class TVal> void RefHashTableOf<TVal>::removeAll() +{ + // Clean up the buckets first + for (unsigned int buckInd = 0; buckInd < fHashModulus; buckInd++) + { + // Get the bucket list head for this entry + RefHashTableBucketElem<TVal>* curElem = fBucketList[buckInd]; + RefHashTableBucketElem<TVal>* nextElem; + while (curElem) + { + // Save the next element before we hose this one + nextElem = curElem->fNext; + + // If we adopted the data, then delete it too + if (fAdoptedElems) + delete curElem->fData; + + // Then delete the current element and move forward + delete curElem; + curElem = nextElem; + } + + // Clean out this entry + fBucketList[buckInd] = 0; + } +} + + +// --------------------------------------------------------------------------- +// RefHashTableOf: Getters +// --------------------------------------------------------------------------- +template <class TVal> TVal* RefHashTableOf<TVal>::get(const XMLCh* const key) +{ + unsigned int hashVal; + RefHashTableBucketElem<TVal>* findIt = findBucketElem(key, hashVal); + if (!findIt) + return 0; + return findIt->fData; +} + +template <class TVal> const TVal* RefHashTableOf<TVal>:: +get(const XMLCh* const key) const +{ + unsigned int hashVal; + const RefHashTableBucketElem<TVal>* findIt = findBucketElem(key, hashVal); + if (!findIt) + return 0; + return findIt->fData; +} + + +// --------------------------------------------------------------------------- +// RefHashTableOf: Putters +// --------------------------------------------------------------------------- +template <class TVal> void RefHashTableOf<TVal>::put(TVal* const valueToAdopt) +{ + // First see if the key exists already + unsigned int hashVal; + RefHashTableBucketElem<TVal>* newBucket = findBucketElem + ( + valueToAdopt->getKey() + , hashVal + ); + + // + // If so,then update its value. If not, then we need to add it to + // the right bucket + // + if (newBucket) + { + if (fAdoptedElems) + delete newBucket->fData; + newBucket->fData = valueToAdopt; + } + else + { + newBucket = new RefHashTableBucketElem<TVal>(valueToAdopt, fBucketList[hashVal]); + fBucketList[hashVal] = newBucket; + } +} + + + +// --------------------------------------------------------------------------- +// RefHashTableOf: Private methods +// --------------------------------------------------------------------------- +template <class TVal> RefHashTableBucketElem<TVal>* RefHashTableOf<TVal>:: +findBucketElem(const XMLCh* const key, unsigned int& hashVal) +{ + // Hash the key + hashVal = XMLString::hash(key, fHashModulus); + if (hashVal > fHashModulus) + ThrowXML(RuntimeException, XML4CExcepts::HshTbl_BadHashFromKey); + + // Search that bucket for the key + RefHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; + while (curElem) + { + if (!XMLString::compareString(key, curElem->fData->getKey())) + return curElem; + + curElem = curElem->fNext; + } + return 0; +} + +template <class TVal> const RefHashTableBucketElem<TVal>* RefHashTableOf<TVal>:: +findBucketElem(const XMLCh* const key, unsigned int& hashVal) const +{ + // Hash the key + hashVal = XMLString::hash(key, fHashModulus); + if (hashVal > fHashModulus) + ThrowXML(RuntimeException, XML4CExcepts::HshTbl_BadHashFromKey); + + // Search that bucket for the key + const RefHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; + while (curElem) + { + if (!XMLString::compareString(key, curElem->fData->getKey())) + return curElem; + + curElem = curElem->fNext; + } + return 0; +} + + +template <class TVal> void RefHashTableOf<TVal>:: +removeBucketElem(const XMLCh* const key, unsigned int& hashVal) +{ + // Hash the key + hashVal = XMLString::hash(key, fHashModulus); + if (hashVal > fHashModulus) + ThrowXML(RuntimeException, XML4CExcepts::HshTbl_BadHashFromKey); + + // + // Search the given bucket for this key. Keep up with the previous + // element so we can patch around it. + // + RefHashTableBucketElem<TVal>* curElem = fBucketList[hashVal]; + RefHashTableBucketElem<TVal>* lastElem = 0; + + while (curElem) + { + if (!XMLString::compareString(key, curElem->fData->getKey())) + { + if (!lastElem) + { + // It was the first in the bucket + fBucketList[hashVal] = curElem->fNext; + } + else + { + // Patch around the current element + lastElem->fNext = curElem->fNext; + } + + // If we adopted the elements, then delete the data + if (fAdoptedElems) + delete curElem->fData; + + // Delete the current element + delete curElem; + + return; + } + + // Move both pointers upwards + lastElem = curElem; + curElem = curElem->fNext; + } + + // We never found that key + ThrowXML(NoSuchElementException, XML4CExcepts::HshTbl_NoSuchKeyExists); +} + + + + +// --------------------------------------------------------------------------- +// RefHashTableOfEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TVal> RefHashTableOfEnumerator<TVal>:: +RefHashTableOfEnumerator( RefHashTableOf<TVal>* const toEnum + , const bool adopt) : + fAdopted(adopt) + , fCurElem(0) + , fCurHash((unsigned int)-1) + , fToEnum(toEnum) +{ + // + // Find the next available bucket element in the hash table. If it + // comes back zero, that just means the table is empty. + // + // Note that the -1 in the current hash tells it to start from the + // beginning. + // + findNext(); +} + +template <class TVal> RefHashTableOfEnumerator<TVal>::~RefHashTableOfEnumerator() +{ + if (fAdopted) + delete fToEnum; +} + + +// --------------------------------------------------------------------------- +// RefHashTableOfEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TVal> bool RefHashTableOfEnumerator<TVal>:: +hasMoreElements() const +{ + // + // If our current has is at the max and there are no more elements + // in the current bucket, then no more elements. + // + if (!fCurElem && (fCurHash == fToEnum->fHashModulus)) + return false; + return true; +} + +template <class TVal> TVal& RefHashTableOfEnumerator<TVal>::nextElement() +{ + // Make sure we have an element to return + if (!hasMoreElements()) + ThrowXML(NoSuchElementException, XML4CExcepts::Enum_NoMoreElements); + + // + // Save the current element, then move up to the next one for the + // next time around. + // + RefHashTableBucketElem<TVal>* saveElem = fCurElem; + findNext(); + + return *saveElem->fData; +} + + +template <class TVal> void RefHashTableOfEnumerator<TVal>::Reset() +{ + fCurHash = (unsigned int)-1; + fCurElem = 0; + findNext(); +} + + + +// --------------------------------------------------------------------------- +// RefHashTableOfEnumerator: Private helper methods +// --------------------------------------------------------------------------- +template <class TVal> void RefHashTableOfEnumerator<TVal>::findNext() +{ + // + // If there is a current element, move to its next element. If this + // hits the end of the bucket, the next block will handle the rest. + // + if (fCurElem) + fCurElem = fCurElem->fNext; + + // + // If the current element is null, then we have to move up to the + // next hash value. If that is the hash modulus, then we cannot + // go further. + // + if (!fCurElem) + { + fCurHash++; + if (fCurHash == fToEnum->fHashModulus) + return; + + // Else find the next non-empty bucket + while (true) + { + if (fToEnum->fBucketList[fCurHash]) + break; + + // Bump to the next hash value. If we max out return + fCurHash++; + if (fCurHash == fToEnum->fHashModulus) + return; + } + fCurElem = fToEnum->fBucketList[fCurHash]; + } +} diff --git a/src/util/RefHashTableOf.hpp b/src/util/RefHashTableOf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..44a3a8d0749ff630cf78260a45962ab18e8eb8b0 --- /dev/null +++ b/src/util/RefHashTableOf.hpp @@ -0,0 +1,250 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:01 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:12 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(REFHASHTABLEOF_HPP) +#define REFHASHTABLEOF_HPP + + +#include <util/XML4CDefs.hpp> +#include <util/KeyValuePair.hpp> +#include <util/IllegalArgumentException.hpp> +#include <util/NoSuchElementException.hpp> +#include <util/RuntimeException.hpp> +#include <util/XMLExceptMsgs.hpp> +#include <util/XMLEnumerator.hpp> +#include <util/XMLString.hpp> + + +// +// Forward declare the enumerator so he can be our friend. Can you say +// friend? Sure... +// +template <class TVal> class RefHashTableOfEnumerator; +template <class TVal> struct RefHashTableBucketElem; + + + +template <class TVal> struct RefHashTableBucketElem +{ + RefHashTableBucketElem(TVal* const value, RefHashTableBucketElem<TVal>* next) : + + fData(value) + , fNext(next) + { + } + + TVal* fData; + RefHashTableBucketElem<TVal>* fNext; +}; + + + +template <class TVal> class RefHashTableOf +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RefHashTableOf + ( + const unsigned int modulus + , const bool adoptElems = true + ); + ~RefHashTableOf(); + + + // ----------------------------------------------------------------------- + // Element management + // ----------------------------------------------------------------------- + bool isEmpty() const; + bool containsKey(const XMLCh* const key) const; + void removeKey(const XMLCh* const key); + void removeAll(); + + + // ----------------------------------------------------------------------- + // Getters + // ----------------------------------------------------------------------- + TVal* get(const XMLCh* const key); + const TVal* get(const XMLCh* const key) const; + + + // ----------------------------------------------------------------------- + // Putters + // ----------------------------------------------------------------------- + void put(TVal* const valueToAdopt); + + +private : + // ----------------------------------------------------------------------- + // Declare our friends + // ----------------------------------------------------------------------- + friend class RefHashTableOfEnumerator<TVal>; + +private: + + // ----------------------------------------------------------------------- + // Private methods + // ----------------------------------------------------------------------- + RefHashTableBucketElem<TVal>* findBucketElem + ( + const XMLCh* const key, + unsigned int& hashVal + ); + const RefHashTableBucketElem<TVal>* findBucketElem + ( + const XMLCh* const key + , unsigned int& hashVal + ) const; + void removeBucketElem(const XMLCh* const key, unsigned int& hashVal); + + + // ----------------------------------------------------------------------- + // Data members + // + // fAdoptedElems + // Indicates whether the values added are adopted or just referenced. + // If adopted, then they are deleted when they are removed from the + // hash table. + // + // fBucketList + // This is the array that contains the heads of all of the list + // buckets, one for each possible hash value. + // + // fHashModulus + // The modulus used for this hash table, to hash the keys. This is + // also the number of elements in the bucket list. + // ----------------------------------------------------------------------- + bool fAdoptedElems; + RefHashTableBucketElem<TVal>** fBucketList; + unsigned int fHashModulus; +}; + + + +// +// An enumerator for a value array. It derives from the basic enumerator +// class, so that value vectors can be generically enumerated. +// +template <class TVal> class RefHashTableOfEnumerator : public XMLEnumerator<TVal> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RefHashTableOfEnumerator + ( + RefHashTableOf<TVal>* const toEnum + , const bool adopt = false + ); + ~RefHashTableOfEnumerator(); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TVal& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Private methods + // ----------------------------------------------------------------------- + void findNext(); + + + // ----------------------------------------------------------------------- + // Data Members + // + // fAdopted + // Indicates whether we have adopted the passed vector. If so then + // we delete the vector when we are destroyed. + // + // fCurElem + // This is the current bucket bucket element that we are on. + // + // fCurHash + // The is the current hash buck that we are working on. Once we hit + // the end of the bucket that fCurElem is in, then we have to start + // working this one up to the next non-empty bucket. + // + // fToEnum + // The value array being enumerated. + // ----------------------------------------------------------------------- + bool fAdopted; + RefHashTableBucketElem<TVal>* fCurElem; + unsigned int fCurHash; + RefHashTableOf<TVal>* fToEnum; +}; + +#if !defined(XML4C_TMPLSINC) +#include <util/RefHashTableOf.c> +#endif + +#endif diff --git a/src/util/RefStackOf.c b/src/util/RefStackOf.c new file mode 100644 index 0000000000000000000000000000000000000000..924f9095f90d214928f5162b2c41716a0c70aef8 --- /dev/null +++ b/src/util/RefStackOf.c @@ -0,0 +1,192 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:02 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:13 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/RefStackOf.hpp> +#endif + + + +// --------------------------------------------------------------------------- +// RefStackOf: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> RefStackOf<TElem>:: +RefStackOf(const unsigned int initElems, const bool adoptElems) : + + fVector(initElems, adoptElems) +{ +} + +template <class TElem> RefStackOf<TElem>::~RefStackOf() +{ +} + + +// --------------------------------------------------------------------------- +// RefStackOf: Element management methods +// --------------------------------------------------------------------------- +template <class TElem> const TElem* RefStackOf<TElem>:: +elementAt(const unsigned int index) const +{ + if (index > fVector.size()) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Stack_BadIndex); + return fVector.elementAt(index); +} + +template <class TElem> void RefStackOf<TElem>::push(TElem* const toPush) +{ + fVector.addElement(toPush); +} + +template <class TElem> const TElem* RefStackOf<TElem>::peek() const +{ + const int curSize = fVector.size(); + if (curSize == 0) + ThrowXML(EmptyStackException, XML4CExcepts::Stack_EmptyStack); + + return fVector.elementAt(curSize-1); +} + +template <class TElem> TElem* RefStackOf<TElem>::pop() +{ + const int curSize = fVector.size(); + if (curSize == 0) + ThrowXML(EmptyStackException, XML4CExcepts::Stack_EmptyStack); + + // Orphan off the element from the last slot in the vector + return fVector.orphanElementAt(curSize-1); +} + +template <class TElem> void RefStackOf<TElem>::removeAllElements() +{ + fVector.removeAllElements(); +} + + +// --------------------------------------------------------------------------- +// RefStackOf: Getter methods +// --------------------------------------------------------------------------- +template <class TElem> bool RefStackOf<TElem>::empty() +{ + return (fVector.size() == 0); +} + +template <class TElem> unsigned int RefStackOf<TElem>::curCapacity() +{ + return fVector.curCapacity(); +} + +template <class TElem> unsigned int RefStackOf<TElem>::size() +{ + return fVector.size(); +} + + + + +// --------------------------------------------------------------------------- +// RefStackEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> RefStackEnumerator<TElem>:: +RefStackEnumerator( RefStackOf<TElem>* const toEnum + , const bool adopt) : + fAdopted(adopt) + , fCurIndex(0) + , fToEnum(toEnum) + , fVector(&toEnum->fVector) +{ +} + +template <class TElem> RefStackEnumerator<TElem>::~RefStackEnumerator() +{ + if (fAdopted) + delete fToEnum; +} + + +// --------------------------------------------------------------------------- +// RefStackEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TElem> bool RefStackEnumerator<TElem>::hasMoreElements() const +{ + if (fCurIndex >= fVector->size()) + return false; + return true; +} + +template <class TElem> TElem& RefStackEnumerator<TElem>::nextElement() +{ + return *fVector->elementAt(fCurIndex++); +} + +template <class TElem> void RefStackEnumerator<TElem>::Reset() +{ + fCurIndex = 0; +} diff --git a/src/util/RefStackOf.hpp b/src/util/RefStackOf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..36cdfff27d31c48643a209b4bd6925570432af51 --- /dev/null +++ b/src/util/RefStackOf.hpp @@ -0,0 +1,186 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:03 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:13 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(REFSTACKOF_HPP) +#define REFSTACKOF_HPP + + +#include <util/XML4CDefs.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/EmptyStackException.hpp> +#include <util/RefVectorOf.hpp> +#include <util/XMLEnumerator.hpp> + + +// +// Forward declare the enumerator so he can be our friend. Can you say +// friend? Sure... +// +template <class TElem> class RefStackEnumerator; + + +template <class TElem> class RefStackOf +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RefStackOf(const unsigned int initElems, const bool adoptElems = true); + ~RefStackOf(); + + + // ----------------------------------------------------------------------- + // Element management methods + // ----------------------------------------------------------------------- + const TElem* elementAt(const unsigned int index) const; + void push(TElem* const toPush); + const TElem* peek() const; + TElem* pop(); + void removeAllElements(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool empty(); + unsigned int curCapacity(); + unsigned int size(); + + +private : + // ----------------------------------------------------------------------- + // Declare our friends + // ----------------------------------------------------------------------- + friend class RefStackEnumerator<TElem>; + + + // ----------------------------------------------------------------------- + // Data Members + // + // fVector + // The vector that is used as the backing data structure for the + // stack. + // ----------------------------------------------------------------------- + RefVectorOf<TElem> fVector; +}; + + + +// +// An enumerator for a value stack. It derives from the basic enumerator +// class, so that value stacks can be generically enumerated. +// +template <class TElem> class RefStackEnumerator : public XMLEnumerator<TElem> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RefStackEnumerator + ( + RefStackOf<TElem>* const toEnum + , const bool adopt = false + ); + ~RefStackEnumerator(); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TElem& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Data Members + // + // fAdopted + // Indicates whether we have adopted the passed stack. If so then + // we delete the stack when we are destroyed. + // + // fCurIndex + // This is the current index into the vector inside the stack being + // enumerated. + // + // fToEnum + // The stack that is being enumerated. This is just kept for + // adoption purposes, since we really are enumerating the vector + // inside of it. + // ----------------------------------------------------------------------- + bool fAdopted; + unsigned int fCurIndex; + RefVectorOf<TElem>* fVector; + RefStackOf<TElem>* fToEnum; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/RefStackOf.c> +#endif + +#endif diff --git a/src/util/RefVectorOf.c b/src/util/RefVectorOf.c new file mode 100644 index 0000000000000000000000000000000000000000..11c116609655281dd46806b7219d142643f674be --- /dev/null +++ b/src/util/RefVectorOf.c @@ -0,0 +1,333 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:04 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:13 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/RefVectorOf.hpp> +#endif + + +// --------------------------------------------------------------------------- +// RefVectorOf: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> RefVectorOf<TElem>:: +RefVectorOf(const unsigned int maxElems, const bool adoptElems) : + + fAdoptedElems(adoptElems) + , fCurCount(0) + , fMaxCount(maxElems) + , fElemList(0) +{ + // Allocate and initialize the array + fElemList = new TElem*[maxElems]; + for (unsigned int index = 0; index < maxElems; index++) + fElemList[index] = 0; +} + +template <class TElem> RefVectorOf<TElem>::~RefVectorOf() +{ + if (fAdoptedElems) + { + for (unsigned int index = 0; index < fCurCount; index++) + delete fElemList[index]; + } + delete [] fElemList; +} + + +// --------------------------------------------------------------------------- +// RefVectorOf: Element management +// --------------------------------------------------------------------------- +template <class TElem> void RefVectorOf<TElem>::addElement(TElem* const toAdd) +{ + ensureExtraCapacity(1); + fElemList[fCurCount] = toAdd; + fCurCount++; +} + + +template <class TElem> void +RefVectorOf<TElem>::setElementAt(TElem* const toSet, const unsigned int setAt) +{ + if (setAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + + if (fAdoptedElems) + delete fElemList[setAt]; + fElemList[setAt] = toSet; +} + +template <class TElem> void RefVectorOf<TElem>:: +insertElementAt(TElem* const toInsert, const unsigned int insertAt) +{ + if (insertAt == fCurCount) + { + addElement(toInsert); + return; + } + + if (insertAt > fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + + ensureExtraCapacity(1); + + // Make room for the newbie + for (unsigned int index = fCurCount; index > insertAt; index--) + fElemList[index] = fElemList[index-1]; + + // And stick it in and bump the count + fElemList[insertAt] = toInsert; + fCurCount++; +} + +template <class TElem> TElem* RefVectorOf<TElem>:: +orphanElementAt(const unsigned int orphanAt) +{ + if (orphanAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + + // Get the element we are going to orphan + TElem* retVal = fElemList[orphanAt]; + + // Optimize if its the last element + if (orphanAt == fCurCount-1) + { + fElemList[orphanAt] = 0; + fCurCount--; + return retVal; + } + + // Copy down every element above orphan point + for (unsigned int index = orphanAt; index < fCurCount-1; index++) + fElemList[index] = fElemList[index+1]; + + // Keep unused elements zero for sanity's sake + fElemList[fCurCount-1] = 0; + + // And bump down count + fCurCount--; + + return retVal; +} + +template <class TElem> void RefVectorOf<TElem>::removeAllElements() +{ + if (fAdoptedElems) + { + for (unsigned int index = 0; index < fCurCount; index++) + { + delete fElemList[index]; + + // Keep unused elements zero for sanity's sake + fElemList[index] = 0; + } + } + fCurCount = 0; +} + +template <class TElem> void RefVectorOf<TElem>:: +removeElementAt(const unsigned int removeAt) +{ + if (removeAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + + if (fAdoptedElems) + delete fElemList[removeAt]; + + // Optimize if its the last element + if (removeAt == fCurCount-1) + { + fElemList[removeAt] = 0; + fCurCount--; + return; + } + + // Copy down every element above remove point + for (unsigned int index = removeAt; index < fCurCount-1; index++) + fElemList[index] = fElemList[index+1]; + + // Keep unused elements zero for sanity's sake + fElemList[fCurCount-1] = 0; + + // And bump down count + fCurCount--; +} + +template <class TElem> void RefVectorOf<TElem>::removeLastElement() +{ + if (!fCurCount) + return; + fCurCount--; + + if (fAdoptedElems) + delete fElemList[fCurCount]; +} + + +// --------------------------------------------------------------------------- +// RefVectorOf: Getter methods +// --------------------------------------------------------------------------- +template <class TElem> unsigned int RefVectorOf<TElem>::curCapacity() const +{ + return fMaxCount; +} + +template <class TElem> const TElem* RefVectorOf<TElem>:: +elementAt(const unsigned int getAt) const +{ + if (getAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + return fElemList[getAt]; +} + +template <class TElem> TElem* +RefVectorOf<TElem>::elementAt(const unsigned int getAt) +{ + if (getAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + return fElemList[getAt]; +} + +template <class TElem> unsigned int RefVectorOf<TElem>::size() const +{ + return fCurCount; +} + + +// --------------------------------------------------------------------------- +// RefVectorOf: Miscellaneous +// --------------------------------------------------------------------------- +template <class TElem> void RefVectorOf<TElem>:: +ensureExtraCapacity(const unsigned int length) +{ + unsigned int newMax = fCurCount + length; + + if (newMax < fMaxCount) + return; + + // Avoid too many reallocations by providing a little more space + if (newMax < fMaxCount + 32) + newMax = fMaxCount + 32; + + // Allocate the new array and copy over the existing stuff + TElem** newList = new TElem*[newMax]; + unsigned int index = 0; + for (; index < fCurCount; index++) + newList[index] = fElemList[index]; + + // Zero out the rest of them + for (; index < newMax; index++) + newList[index] = 0; + + // Clean up the old array and update our members + delete [] fElemList; + fElemList = newList; + fMaxCount = newMax; +} + + + +// --------------------------------------------------------------------------- +// RefVectorEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> RefVectorEnumerator<TElem>:: +RefVectorEnumerator( RefVectorOf<TElem>* const toEnum + , const bool adopt) : + fAdopted(adopt) + , fCurIndex(0) + , fToEnum(toEnum) +{ +} + +template <class TElem> RefVectorEnumerator<TElem>::~RefVectorEnumerator() +{ + if (fAdopted) + delete fToEnum; +} + + +// --------------------------------------------------------------------------- +// RefVectorEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TElem> bool RefVectorEnumerator<TElem>::hasMoreElements() const +{ + if (fCurIndex >= fToEnum->size()) + return false; + return true; +} + +template <class TElem> TElem& RefVectorEnumerator<TElem>::nextElement() +{ + return *(fToEnum->elementAt(fCurIndex++)); +} + +template <class TElem> void RefVectorEnumerator<TElem>::Reset() +{ + fCurIndex = 0; +} diff --git a/src/util/RefVectorOf.hpp b/src/util/RefVectorOf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a6e8b74b9a12945dbb2f625936e36f965f1e3f47 --- /dev/null +++ b/src/util/RefVectorOf.hpp @@ -0,0 +1,172 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:05 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:13 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(REFVECTOROF_HPP) +#define REFVECTOROF_HPP + +#include <util/XML4CDefs.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/XMLEnumerator.hpp> + + +template <class TElem> class RefVectorOf +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RefVectorOf(const unsigned int maxElems, const bool adoptElems = true); + ~RefVectorOf(); + + + // ----------------------------------------------------------------------- + // Element management + // ----------------------------------------------------------------------- + void addElement(TElem* const toAdd); + void setElementAt(TElem* const toSet, const unsigned int setAt); + void insertElementAt(TElem* const toInsert, const unsigned int insertAt); + TElem* orphanElementAt(const unsigned int orphanAt); + void removeAllElements(); + void removeElementAt(const unsigned int removeAt); + void removeLastElement(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + unsigned int curCapacity() const; + const TElem* elementAt(const unsigned int getAt) const; + TElem* elementAt(const unsigned int getAt); + unsigned int size() const; + + + // ----------------------------------------------------------------------- + // Miscellaneous + // ----------------------------------------------------------------------- + void ensureExtraCapacity(const unsigned int length); + + +private: + // ----------------------------------------------------------------------- + // Data members + // ----------------------------------------------------------------------- + bool fAdoptedElems; + unsigned int fCurCount; + unsigned int fMaxCount; + TElem** fElemList; +}; + + +// +// An enumerator for a reference vector. It derives from the basic enumerator +// class, so that value vectors can be generically enumerated. +// +template <class TElem> class RefVectorEnumerator : public XMLEnumerator<TElem> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RefVectorEnumerator + ( + RefVectorOf<TElem>* const toEnum + , const bool adopt = false + ); + ~RefVectorEnumerator(); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TElem& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Data Members + // + // fAdopted + // Indicates whether we have adopted the passed vector. If so then + // we delete the vector when we are destroyed. + // + // fCurIndex + // This is the current index into the vector. + // + // fToEnum + // The reference vector being enumerated. + // ----------------------------------------------------------------------- + bool fAdopted; + unsigned int fCurIndex; + RefVectorOf<TElem>* fToEnum; +}; + +#if !defined(XML4C_TMPLSINC) +#include <util/RefVectorOf.c> +#endif + +#endif diff --git a/src/util/RuntimeException.hpp b/src/util/RuntimeException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..673aeb7ce81d77538cbf45342448b5cf61b13641 --- /dev/null +++ b/src/util/RuntimeException.hpp @@ -0,0 +1,86 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:06 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:14 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(RUNTIMEEXCEPTION_HPP) +#define RUNTIMEEXCEPTION_HPP + + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + +// Hard coded Unicode text for "RuntimeException" +const XMLCh gRuntimeException_Name[] = +{ + chLatin_R, chLatin_u, chLatin_n, chLatin_t, chLatin_i + , chLatin_m, chLatin_e, chLatin_E, chLatin_x, chLatin_c + , chLatin_e, chLatin_p, chLatin_t, chLatin_i, chLatin_o + , chLatin_n, chNull +}; + +MakeXML4CException(RuntimeException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/StdOut.cpp b/src/util/StdOut.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff26b24bd4e31b524a31b47c715c98afbabc4edb --- /dev/null +++ b/src/util/StdOut.cpp @@ -0,0 +1,137 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:08 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:14 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/StdOut.hpp> +#include <util/PlatformUtils.hpp> + + + +// --------------------------------------------------------------------------- +// XMLStdOut: Constructors and Destructor +// --------------------------------------------------------------------------- +XMLStdOut::XMLStdOut() +{ +} + +XMLStdOut::~XMLStdOut() +{ +} + + +// --------------------------------------------------------------------------- +// XMLStdOut: Implementation of the text output stream interface +// --------------------------------------------------------------------------- +void XMLStdOut::flush() +{ + // NoOp for this one +} + +void XMLStdOut::write(const XMLCh* const toWrite) +{ + XMLPlatformUtils::writeToStdOut(toWrite); +} + +void XMLStdOut::write(const char* const toWrite) +{ + XMLPlatformUtils::writeToStdOut(toWrite); +} + + + + +// --------------------------------------------------------------------------- +// XMLStdErr: Constructors and Destructor +// --------------------------------------------------------------------------- +XMLStdErr::XMLStdErr() +{ +} + +XMLStdErr::~XMLStdErr() +{ +} + + +// --------------------------------------------------------------------------- +// XMLStdErr: Implementation of the text output stream interface +// --------------------------------------------------------------------------- +void XMLStdErr::flush() +{ + // NoOp for this one +} + +void XMLStdErr::write(const XMLCh* const toWrite) +{ + XMLPlatformUtils::writeToStdErr(toWrite); +} + +void XMLStdErr::write(const char* const toWrite) +{ + XMLPlatformUtils::writeToStdErr(toWrite); +} diff --git a/src/util/StdOut.hpp b/src/util/StdOut.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d2b92fdb8c4f8a1098f9ee9e870c230965495406 --- /dev/null +++ b/src/util/StdOut.hpp @@ -0,0 +1,109 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:08 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:14 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(STDOUT_HPP) +#define STDOUT_HPP + +#include <util/XML4CDefs.hpp> +#include <util/TextOutputStream.hpp> + +class XMLUTIL_EXPORT XMLStdOut : public TextOutputStream +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + XMLStdOut(); + ~XMLStdOut(); + + // ----------------------------------------------------------------------- + // Implementation of the output stream interface + // ----------------------------------------------------------------------- + virtual void flush(); + virtual void write(const XMLCh* const toWrite); + virtual void write(const char* const toWrite); +}; + + +class XMLUTIL_EXPORT XMLStdErr : public TextOutputStream +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + XMLStdErr(); + ~XMLStdErr(); + + // ----------------------------------------------------------------------- + // Implementation of the output stream interface + // ----------------------------------------------------------------------- + virtual void flush(); + virtual void write(const XMLCh* const toWrite); + virtual void write(const char* const toWrite); +}; + + +#endif diff --git a/src/util/StringPool.cpp b/src/util/StringPool.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db620345866c179beb098f3a7631c4b019c88ae0 --- /dev/null +++ b/src/util/StringPool.cpp @@ -0,0 +1,220 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:10 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:14 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/IllegalArgumentException.hpp> +#include <util/StringPool.hpp> +#include <util/XMLExceptMsgs.hpp> +#include <util/XMLString.hpp> +#include <memory.h> + + +// --------------------------------------------------------------------------- +// StringPool::PoolElem: Constructors and Destructor +// --------------------------------------------------------------------------- +XMLStringPool::PoolElem::PoolElem( const XMLCh* const string + , const unsigned int id) : + fId(id) + , fString(0) +{ + fString = XMLString::replicate(string); +} + +XMLStringPool::PoolElem::~PoolElem() +{ + delete [] fString; +} + +// --------------------------------------------------------------------------- +// StringPool::PoolElem: Public methods +// --------------------------------------------------------------------------- +const XMLCh* XMLStringPool::PoolElem::getKey() const +{ + return fString; +} + +void +XMLStringPool::PoolElem::reset(const XMLCh* const string, const unsigned int id) +{ + fId = id; + delete [] fString; + fString = XMLString::replicate(string); +} + + + +// --------------------------------------------------------------------------- +// XMLStringPool: Constructors and Destructor +// --------------------------------------------------------------------------- +XMLStringPool::XMLStringPool(const unsigned int modulus) : + + fIdMap(0) + , fHashTable(0) + , fMapCapacity(64) + , fCurId(1) +{ + // Create the hash table, passing it the modulus + fHashTable = new RefHashTableOf<PoolElem>(modulus); + + // Do an initial allocation of the id map and zero it all out + fIdMap = new PoolElem*[fMapCapacity]; + memset(fIdMap, 0, sizeof(PoolElem*) * fMapCapacity); +} + +XMLStringPool::~XMLStringPool() +{ + delete fHashTable; + delete [] fIdMap; +} + + +// --------------------------------------------------------------------------- +// XMLStringPool: Pool management methods +// --------------------------------------------------------------------------- +unsigned int XMLStringPool::addOrFind(const XMLCh* const newString) +{ + PoolElem* elemToFind = fHashTable->get(newString); + if (elemToFind) + return elemToFind->fId; + + return addNewEntry(newString); +} + + +bool XMLStringPool::exists(const XMLCh* const newString) const +{ + return fHashTable->containsKey(newString); +} + +void XMLStringPool::flushAll() +{ + fCurId = 1; + fHashTable->removeAll(); +} + + +unsigned int XMLStringPool::getId(const XMLCh* const toFind) const +{ + PoolElem* elemToFind = fHashTable->get(toFind); + if (elemToFind) + return elemToFind->fId; + + // Not found, so return zero, which is never a legal id + return 0; +} + + +const XMLCh* XMLStringPool::getValueForId(const unsigned int id) const +{ + if (!id || (id >= fCurId)) + ThrowXML(IllegalArgumentException, XML4CExcepts::StrPool_IllegalId); + + // Just index the id map and return that element's string + return fIdMap[id]->fString; +} + + +// --------------------------------------------------------------------------- +// XMLStringPool: Private helper methods +// --------------------------------------------------------------------------- +unsigned int XMLStringPool::addNewEntry(const XMLCh* const newString) +{ + // See if we need to expand the id map + if (fCurId == fMapCapacity) + { + // Calculate the new capacity, create a temp new map, and zero it + const unsigned int newCap = (unsigned int)(fMapCapacity * 1.5); + PoolElem** newMap = new PoolElem*[newCap]; + memset(newMap, 0, sizeof(PoolElem*) * newCap); + + // + // Copy over the old elements from the old map. They are just pointers + // so we can do it all at once. + // + memcpy(newMap, fIdMap, sizeof(PoolElem*) * fMapCapacity); + + // Clean up the old map and store the new info + delete [] fIdMap; + fIdMap = newMap; + fMapCapacity = newCap; + } + + // + // Ok, now create a new element and add it to the hash table. Then store + // this new element in the id map at the current id index, then bump the + // id index. + // + PoolElem* newElem = new PoolElem(newString, fCurId); + fHashTable->put(newElem); + fIdMap[fCurId] = newElem; + + // Bump the current id and return the id of the new elem we just added + fCurId++; + return newElem->fId; +} diff --git a/src/util/StringPool.hpp b/src/util/StringPool.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c819b5ebd8164ccbe51d021dd937542a0c4e60b6 --- /dev/null +++ b/src/util/StringPool.hpp @@ -0,0 +1,165 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:11 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:15 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(STRINGPOOL_HPP) +#define STRINGPOOL_HPP + +#include <util/RefHashTableOf.hpp> + +// +// This class implements a string pool, in which strings can be added and +// given a unique id by which they can be refered. It has to provide fast +// access both mapping from a string to its id and mapping from an id to +// its string. This requires that it provide two separate data structures. +// The map one is a hash table for quick storage and look up by name. The +// other is an array ordered by unique id which maps to the element in the +// hash table. +// +// This works because strings cannot be removed from the pool once added, +// other than flushing it completely, and because ids are assigned +// sequentially from 1. +// +class XMLUTIL_EXPORT XMLStringPool +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + XMLStringPool + ( + const unsigned int modulus = 109 + ); + ~XMLStringPool(); + + + // ----------------------------------------------------------------------- + // Pool management methods + // ----------------------------------------------------------------------- + unsigned int addOrFind(const XMLCh* const newString); + bool exists(const XMLCh* const newString) const; + void flushAll(); + unsigned int getId(const XMLCh* const toFind) const; + const XMLCh* getValueForId(const unsigned int id) const; + + +private : + // ----------------------------------------------------------------------- + // Private data types + // ----------------------------------------------------------------------- + class PoolElem + { + public : + PoolElem(const XMLCh* const string, const unsigned int id); + ~PoolElem(); + + const XMLCh* getKey() const; + void reset(const XMLCh* const string, const unsigned int id); + + unsigned int fId; + XMLCh* fString; + }; + + + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XMLStringPool(const XMLStringPool&); + void operator=(const XMLStringPool&); + + + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + unsigned int addNewEntry(const XMLCh* const newString); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fIdMap + // This is an array of pointers to the pool elements. It is ordered + // by unique id, so using an id to index it gives instant access to + // the string of that id. This is grown as required. + // + // fHashTable + // This is the hash table used to store and quickly access the + // strings. + // + // fMapCapacity + // The current capacity of the id map. When the current id hits this + // value the map must must be expanded. + // + // fCurId + // This is the counter used to assign unique ids. It is just bumped + // up one for each new string added. + // ----------------------------------------------------------------------- + PoolElem** fIdMap; + RefHashTableOf<PoolElem>* fHashTable; + unsigned int fMapCapacity; + unsigned int fCurId; +}; + +#endif diff --git a/src/util/TextOutputStream.cpp b/src/util/TextOutputStream.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e6208378e8cf7ba48a1cb69d93c517eb6a3c823 --- /dev/null +++ b/src/util/TextOutputStream.cpp @@ -0,0 +1,220 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:13 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:15 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Janitor.hpp> +#include <util/TextOutputStream.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> + +#include <math.h> +#include <stdlib.h> + + +// --------------------------------------------------------------------------- +// StreamJanitor: Constructors and Destructor +// --------------------------------------------------------------------------- +StreamJanitor::StreamJanitor(TextOutputStream* const toSanitize) : + + fRadix(toSanitize->fRadix) + , fStream(toSanitize) +{ +} + +StreamJanitor::~StreamJanitor() +{ + if (fStream) + { + fStream->fRadix = fRadix; + } +} + + +// --------------------------------------------------------------------------- +// TextOutputStream: Virtual destructor +// --------------------------------------------------------------------------- +TextOutputStream::~TextOutputStream() +{ +} + + +// --------------------------------------------------------------------------- +// TextOutputStream: Formatting operators +// --------------------------------------------------------------------------- +TextOutputStream& TextOutputStream::operator<<(const XMLCh* const toWrite) +{ + write(toWrite); + return *this; +} + +TextOutputStream& TextOutputStream::operator<<(const XMLCh toWrite) +{ + XMLCh szTmp[2]; + szTmp[0] = toWrite; + szTmp[1] = 0; + + write(szTmp); + return *this; +} + +TextOutputStream& TextOutputStream::operator<<(const char* const toWrite) +{ + write(toWrite); + return *this; +} + +TextOutputStream& TextOutputStream::operator<<(const char toWrite) +{ + char szTmp[2]; + szTmp[0] = toWrite; + szTmp[1] = 0; + write(szTmp); + return *this; +} + +TextOutputStream& TextOutputStream::operator<<(const unsigned int toWrite) +{ + XMLCh szTmp[128]; + XMLString::binToText(toWrite, szTmp, 127, fRadix); + + write(szTmp); + return *this; +} + +TextOutputStream& TextOutputStream::operator<<(const long toWrite) +{ + XMLCh szTmp[128]; + XMLString::binToText(toWrite, szTmp, 127, fRadix); + + write(szTmp); + return *this; +} + +TextOutputStream& TextOutputStream::operator<<(const unsigned long toWrite) +{ + XMLCh szTmp[128]; + XMLString::binToText(toWrite, szTmp, 127, fRadix); + + write(szTmp); + return *this; +} + +TextOutputStream& TextOutputStream::operator<<(const double& toWrite) +{ + // To avoid portability issues, split into two parts + double fracPart; + double intPart; + intPart = modf(toWrite, &fracPart); + + if (fracPart < 0) + fracPart *= (double)-1.0; + + XMLCh szTmp[128]; + XMLString::binToText((long)intPart, szTmp, 127, fRadix); + write(szTmp); + + szTmp[0] = '.'; + szTmp[1] = 0; + write(szTmp); + + XMLString::binToText((long)fracPart, szTmp, 127, fRadix); + write(szTmp); + return *this; +} + +TextOutputStream& +TextOutputStream::operator<<(const TextOutputStream::Radices newRadix) +{ + fRadix = newRadix; + return *this; +} + +TextOutputStream& +TextOutputStream::operator<<(const TextOutputStream::SpecialValues newValue) +{ + static const XMLCh newLine[] = { chLF, chNull }; + + if (newValue == EndLine) + { + write(newLine); + flush(); + } + return *this; +} + + + +// --------------------------------------------------------------------------- +// TextOutputStream: Hidden Constructors and Destructor +// --------------------------------------------------------------------------- +TextOutputStream::TextOutputStream() : + + fRadix(TextOutputStream::decimal) +{ +} diff --git a/src/util/TextOutputStream.hpp b/src/util/TextOutputStream.hpp new file mode 100644 index 0000000000000000000000000000000000000000..af65f2ca938b5135166fc2ce1bced6c9ce1dd251 --- /dev/null +++ b/src/util/TextOutputStream.hpp @@ -0,0 +1,240 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:14 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:15 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(OUTPUTSTREAM_HPP) +#define OUTPUTSTREAM_HPP + +#include <util/XML4CDefs.hpp> + +class StreamJanitor; + +class XMLUTIL_EXPORT TextOutputStream +{ +public : + // ----------------------------------------------------------------------- + // Public types + // ----------------------------------------------------------------------- + enum Radices + { + bin = 2 + , decimal = 10 + , hex = 16 + }; + + enum SpecialValues + { + EndLine + }; + + + // ----------------------------------------------------------------------- + // Public virtual destructor + // ----------------------------------------------------------------------- + virtual ~TextOutputStream(); + + + // ----------------------------------------------------------------------- + // Formatting operators + // ----------------------------------------------------------------------- + TextOutputStream& operator<< + ( + const XMLCh* const toWrite + ); + + TextOutputStream& operator<< + ( + const XMLCh toWrite + ); + + TextOutputStream& operator<< + ( + const char* const toWrite + ); + + TextOutputStream& operator<< + ( + const char toWrite + ); + + TextOutputStream& operator<< + ( + const unsigned int toWrite + ); + + TextOutputStream& operator<< + ( + const long toWrite + ); + + TextOutputStream& operator<< + ( + const unsigned long toWrite + ); + + TextOutputStream& operator<< + ( + const double& toWrite + ); + + TextOutputStream& operator<< + ( + const Radices newRadix + ); + + TextOutputStream& operator<< + ( + const SpecialValues specialVal + ); + + + // ----------------------------------------------------------------------- + // Virtual interface to be provided by the derived class + // ----------------------------------------------------------------------- + virtual void flush() = 0; + virtual void write(const XMLCh* const toWrite) = 0; + virtual void write(const char* const toWrite) = 0; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + Radices getRadix() const + { + return fRadix; + } + + +protected : + // ----------------------------------------------------------------------- + // Declare our friends + // ----------------------------------------------------------------------- + friend class StreamJanitor; + + + // ----------------------------------------------------------------------- + // Hidden Constructors for derived classes only + // ----------------------------------------------------------------------- + TextOutputStream(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + TextOutputStream(const TextOutputStream&); + void operator=(const TextOutputStream&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fRadix + // The current radix to use when formatting values. + // ----------------------------------------------------------------------- + Radices fRadix; +}; + + +class XMLUTIL_EXPORT StreamJanitor +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + StreamJanitor(TextOutputStream* const toSanitize); + ~StreamJanitor(); + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + StreamJanitor(const StreamJanitor&); + void operator=(const StreamJanitor&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fRadix + // The saved radix that will be replaced. + // + // fStream + // This is the stream that we are sanitizing. + // ----------------------------------------------------------------------- + TextOutputStream::Radices fRadix; + TextOutputStream* fStream; +}; + + +// --------------------------------------------------------------------------- +// Convenenience defines for some of the special characters +// --------------------------------------------------------------------------- +#define EndLn TextOutputStream::EndLine +#define BinRadix TextOutputStream::bin +#define DecimalRadix TextOutputStream::decimal +#define HexRadix TextOutputStream::hex + +#endif diff --git a/src/util/TransService.hpp b/src/util/TransService.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2edf773bbf317c03b1be3f27338e091f7829c510 --- /dev/null +++ b/src/util/TransService.hpp @@ -0,0 +1,250 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:16 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:16 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#ifndef TRANSSERVICE_HPP +#define TRANSSERVICE_HPP + +#include <util/XML4CDefs.hpp> + +class XMLUTIL_EXPORT XMLTranscoder; + +// +// This class is an abstract base class which are used to abstract the +// transcoding services that XML4C uses. XML4C's actual transcoding needs are +// small (this does not count demo programs, just the parser system itself) +// so it is desirable to allow different implementations to be provided. +// +// Also defined here is the abstract class, XMLTranscoder, which represents +// a particular instance of a transcoder for a particular encoding. The +// transcoding service must be able to create new transcoders upon demand +// for a particular encoding. It is assumed that the service will pool +// transcoders for efficiency where possible (since their use will commonly +// occur repeatedly and for short periods of time.) +// +class XMLUTIL_EXPORT XMLTransService +{ +public : + // ----------------------------------------------------------------------- + // Class specific types + // ----------------------------------------------------------------------- + enum Codes + { + Ok + , UnsupportedEncoding + , InternalFailure + , SupportFilesNotFound + }; + + + // ----------------------------------------------------------------------- + // Public constructors and destructor + // ----------------------------------------------------------------------- + virtual ~XMLTransService(); + + + // ----------------------------------------------------------------------- + // The virtual transcoding service API + // ----------------------------------------------------------------------- + virtual int compareIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + ) = 0; + + virtual int compareNIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + , const unsigned int maxChars + ) = 0; + + virtual bool isSpace(const XMLCh toCheck) const = 0; + + virtual XMLTranscoder* makeNewDefTranscoder() = 0; + + virtual XMLTranscoder* makeNewTranscoderFor + ( + const XMLCh* const encodingName + , XMLTransService::Codes& resValue + , const unsigned int blockSize + ) = 0; + + +protected : + // ----------------------------------------------------------------------- + // Hidden constructors + // ----------------------------------------------------------------------- + XMLTransService(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XMLTransService(const XMLTransService&); + void operator=(const XMLTransService&); +}; + + + +class XMLTranscoder +{ +public : + // ----------------------------------------------------------------------- + // Public constructors and destructor + // ----------------------------------------------------------------------- + virtual ~XMLTranscoder(); + + + // ----------------------------------------------------------------------- + // The virtual transcoder API + // + // NOTE: All these APIs don't include null terminator characters in + // their parameters. So calcRequiredSize() returns the number + // of actual chars, not including the null. maxBytes and maxChars + // parameters refer to actual chars, not including the null so + // its assumed that the buffer is physically one char or byte + // larger. + // ----------------------------------------------------------------------- + virtual unsigned int calcRequiredSize(const char* const srcText) = 0; + + virtual unsigned int calcRequiredSize(const XMLCh* const srcText) = 0; + + virtual XMLCh transcodeOne + ( + const char* const srcData + , const unsigned int srcBytes + , unsigned int& bytesEaten + ) = 0; + + virtual char* transcode(const XMLCh* const toTranscode) = 0; + + virtual bool transcode + ( + const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxBytes + ) = 0; + + virtual XMLCh* transcode(const char* const toTranscode) = 0; + + virtual bool transcode + ( + const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars + ) = 0; + + virtual unsigned int transcodeXML + ( + const char* const srcData + , const unsigned int srcCount + , XMLCh* const toFill + , const unsigned int maxChars + , unsigned int& bytesEaten + ) = 0; + + +protected : + // ----------------------------------------------------------------------- + // Hidden constructors + // ----------------------------------------------------------------------- + XMLTranscoder(); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XMLTranscoder(const XMLTranscoder&); + void operator=(const XMLTranscoder&); +}; + + +// --------------------------------------------------------------------------- +// XLMTransService: Hidden constructors and destructor +// --------------------------------------------------------------------------- +inline XMLTransService::XMLTransService() +{ +} + +inline XMLTransService::~XMLTransService() +{ +} + + +// --------------------------------------------------------------------------- +// XLMTranscoder: Hidden constructors and destructor +// --------------------------------------------------------------------------- +inline XMLTranscoder::XMLTranscoder() +{ +} + +inline XMLTranscoder::~XMLTranscoder() +{ +} + +#endif diff --git a/src/util/Transcoders/ICU/ICUTransService.cpp b/src/util/Transcoders/ICU/ICUTransService.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9fdeab1a3fc9b63e3beb53d7246d8e758aa8375 --- /dev/null +++ b/src/util/Transcoders/ICU/ICUTransService.cpp @@ -0,0 +1,548 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:07 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:33 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/TranscodingException.hpp> +#include "ICUTransService.hpp" +#include <string.h> +#include <uloc.h> +#include <unicode.h> +#include <ucnv.h> +#include <ustring.h> + + +// --------------------------------------------------------------------------- +// ICUTransService: Public, static methods +// --------------------------------------------------------------------------- +void ICUTransService::setICUPath(const char* const pathToSet) +{ + uloc_setDataDirectory(pathToSet); +} + + +// --------------------------------------------------------------------------- +// ICUTransService: Constructors and Destructor +// --------------------------------------------------------------------------- +ICUTransService::ICUTransService() +{ +} + +ICUTransService::~ICUTransService() +{ +} + + +// --------------------------------------------------------------------------- +// ICUTransService: The virtual transcoding service API +// --------------------------------------------------------------------------- +int ICUTransService::compareIString(const XMLCh* const comp1 + , const XMLCh* const comp2) +{ + const XMLCh* psz1 = comp1; + const XMLCh* psz2 = comp2; + + unsigned int curCount = 0; + while (true) + { + // If an inequality, then return the difference + if (Unicode::toUpperCase(*psz1) != Unicode::toUpperCase(*psz2)) + return int(*psz1) - int(*psz2); + + // If either has ended, then they both ended, so equal + if (!*psz1 || !*psz2) + break; + + // Move upwards for the next round + psz1++; + psz2++; + } + return 0; +} + + +int ICUTransService::compareNIString(const XMLCh* const comp1 + , const XMLCh* const comp2 + , const unsigned int maxChars) +{ + const XMLCh* psz1 = comp1; + const XMLCh* psz2 = comp2; + + unsigned int curCount = 0; + while (true) + { + // If an inequality, then return difference + if (Unicode::toUpperCase(*psz1) != Unicode::toUpperCase(*psz2)) + return int(*psz1) - int(*psz2); + + // If either ended, then both ended, so equal + if (!*psz1 || !*psz2) + break; + + // Move upwards to next chars + psz1++; + psz2++; + + // + // Bump the count of chars done. If it equals the count then we + // are equal for the requested count, so break out and return + // equal. + // + curCount++; + if (maxChars == curCount) + break; + } + return 0; +} + + +bool ICUTransService::isSpace(const XMLCh toCheck) const +{ + return (Unicode::isSpaceChar(toCheck) != 0); +} + + +XMLTranscoder* ICUTransService::makeNewDefTranscoder() +{ + // + // Try to create a default converter. If it fails, return a null pointer + // which will basically cause the system to give up because we really can't + // do anything without one. + // + UErrorCode uerr = ZERO_ERROR; + UConverter* converter = ucnv_open(NULL, &uerr); + if (!converter) + return 0; + + // That went ok, so create an ICU transcoder wrapper and return it + return new ICUTranscoder(converter, 0); +} + + +XMLTranscoder* +ICUTransService::makeNewTranscoderFor( const XMLCh* const encodingName + , XMLTransService::Codes& resValue + , const unsigned int blockSize) +{ + UErrorCode uerr = ZERO_ERROR; + UConverter* converter = ucnv_openU(encodingName, &uerr); + if (!converter) + { + resValue = XMLTransService::UnsupportedEncoding; + return 0; + } + return new ICUTranscoder(converter, blockSize); +} + + + + +// --------------------------------------------------------------------------- +// ICUTranscoder: Constructors and Destructor +// --------------------------------------------------------------------------- +ICUTranscoder::ICUTranscoder( UConverter* const toAdopt + , const unsigned int blockSize) : + fCharOfsBuf(0) + , fConverter(toAdopt) +{ + // There won't be a block size if this is for a default transcoder + if (blockSize) + fCharOfsBuf = new long[blockSize]; +} + +ICUTranscoder::~ICUTranscoder() +{ + delete [] fCharOfsBuf; + + // If there is a converter, ask ICU to clean it up + if (fConverter) + { + // <TBD> Does this actually delete the structure??? + ucnv_close(fConverter); + fConverter = 0; + } +} + + +// --------------------------------------------------------------------------- +// ICUTranscoder: The virtual transcoder API +// --------------------------------------------------------------------------- +unsigned int ICUTranscoder::calcRequiredSize(const XMLCh* const srcText) +{ + if (!srcText) + return 0; + + XMLMutexLock lockConverter(&fMutex); + + UErrorCode err = ZERO_ERROR; + const int32_t targetCap = ucnv_fromUChars + ( + fConverter + , 0 + , 0 + , srcText + , &err + ); + + if (err != BUFFER_OVERFLOW_ERROR) + return 0; + + return (unsigned int)targetCap; +} + +unsigned int ICUTranscoder::calcRequiredSize(const char* const srcText) +{ + if (!srcText) + return 0; + + XMLMutexLock lockConverter(&fMutex); + + UErrorCode err = ZERO_ERROR; + const int32_t targetCap = ucnv_toUChars + ( + fConverter + , 0 + , 0 + , srcText + , strlen(srcText) + , &err + ); + + if (err != BUFFER_OVERFLOW_ERROR) + return 0; + + // Subtract one since it includes the terminator space + return (unsigned int)(targetCap - 1); +} + + +XMLCh ICUTranscoder::transcodeOne( const char* const srcData + , const unsigned int srcBytes + , unsigned int& bytesEaten) +{ + // Check for stupid stuff + if (!srcBytes) + return 0; + + XMLMutexLock lockConverter(&fMutex); + + UErrorCode err = ZERO_ERROR; + const char* startSrc = srcData; + const XMLCh chRet = ucnv_getNextUChar + ( + fConverter + , &startSrc + , (srcData + srcBytes) - 1 + , &err + ); + + // Bail out if an error + if (FAILURE(err)) + return 0; + + // Calculate the bytes eaten and return the char + bytesEaten = startSrc - srcData; + return chRet; +} + + +char* ICUTranscoder::transcode(const XMLCh* const toTranscode) +{ + char* retBuf = 0; + + // Check for a couple of special cases + if (!toTranscode) + return 0; + + if (!*toTranscode) + { + retBuf = new char[1]; + retBuf[0] = 0; + return retBuf; + } + + XMLMutexLock lockConverter(&fMutex); + + // Caculate a return buffer size not too big, but less likely to overflow + int32_t targetLen = (int32_t)(u_strlen(toTranscode) * 1.25); + + // Allocate the return buffer + retBuf = new char[targetLen + 1]; + + //Convert the Unicode string to char* using Intl stuff + UErrorCode err = ZERO_ERROR; + int32_t targetCap = ucnv_fromUChars + ( + fConverter + , retBuf + , targetLen + 1 + , toTranscode + , &err + ); + + // If targetLen is not enough then buffer overflow might occur + if (err == BUFFER_OVERFLOW_ERROR) + { + // Reset the error, delete the old buffer, allocate a new one, and try again + err = ZERO_ERROR; + delete [] retBuf; + retBuf = new char[targetCap]; + targetCap = ucnv_fromUChars(fConverter, retBuf, targetCap, toTranscode, &err); + } + + if (FAILURE(err)) + { + delete [] retBuf; + return 0; + } + + // Cap it off and return + retBuf[targetCap] = 0; + return retBuf; +} + + +bool ICUTranscoder::transcode( const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxChars) +{ + // Watch for a few psycho corner cases + if (!toTranscode || !maxChars) + { + toFill[0] = 0; + return true; + } + + if (!*toTranscode) + { + toFill[0] = 0; + return true; + } + + XMLMutexLock lockConverter(&fMutex); + + UErrorCode err = ZERO_ERROR; + int32_t targetCap; + targetCap = ucnv_fromUChars(fConverter, toFill, maxChars + 1, toTranscode, &err); + + if (FAILURE(err)) + return false; + + return true; +} + + +XMLCh* ICUTranscoder::transcode(const char* const toTranscode) +{ + // Watch for a few pyscho corner cases + if (!toTranscode) + return 0; + + XMLCh* retVal = 0; + if (!*toTranscode) + { + retVal = new XMLCh[1]; + retVal[0] = 0; + return retVal; + } + + XMLMutexLock lockConverter(&fMutex); + + // + // Get the length of the string to transcode. The Unicode string will + // almost always be no more chars than were in the source, so this is + // the best guess as to the storage needed. + // + const int32_t srcLen = (int32_t)strlen(toTranscode); + + // + // Here we don't know what the target length will be so use 0 and expect + // an BUFFER_OVERFLOW_ERROR in which case it'd get resolved by the + // correct capacity value. + // + UErrorCode err = ZERO_ERROR; + int32_t targetCap; + targetCap = ucnv_toUChars + ( + fConverter + , 0 + , 0 + , toTranscode + , srcLen + , &err + ); + + if (err != BUFFER_OVERFLOW_ERROR) + return 0; + + err = ZERO_ERROR; + retVal = new XMLCh[targetCap]; + ucnv_toUChars + ( + fConverter + , retVal + , targetCap + , toTranscode + , srcLen + , &err + ); + + if (FAILURE(err)) + return 0; + + return retVal; +} + + +bool ICUTranscoder::transcode( const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars) +{ + // Check for a couple of psycho corner cases + if (!toTranscode || !maxChars) + { + toFill[0] = 0; + return true; + } + + if (!*toTranscode) + { + toFill[0] = 0; + return true; + } + + XMLMutexLock lockConverter(&fMutex); + + UErrorCode err = ZERO_ERROR; + const int32_t srcLen = (int32_t)strlen(toTranscode); + + ucnv_toUChars + ( + fConverter + , toFill + , maxChars + 1 + , toTranscode + , srcLen + , &err + ); + + if (FAILURE(err)) + return false; + return true; +} + + +unsigned int +ICUTranscoder::transcodeXML(const char* const srcData + , const unsigned int srcCount + , XMLCh* const toFill + , const unsigned int maxChars + , unsigned int& bytesEaten) +{ + // + // If the input encoding uses fixed size characters, we can use a + // simpler, faster approach to computing the character sizes to be + // returned in the charSizes array. + // + const int maxCharSize = ucnv_getMaxCharSize(fConverter); + const int minCharSize = ucnv_getMinCharSize(fConverter); + + // + // Set up pointers to the source and destination buffers. + // + UChar* startTarget = toFill; + const char* startSrc = srcData; + const char* endSrc = srcData + srcCount; + + // + // Transoode the buffer. Buffer overflow errors are normal, occuring + // when the raw input buffer holds more characters than will fit + // in the Unicode output buffer. + // + UErrorCode err = ZERO_ERROR; + ucnv_toUnicode + ( + fConverter + , &startTarget + , toFill + maxChars + , &startSrc + , endSrc + , 0 + , false + , &err + ); + + if ((err != ZERO_ERROR) && (err != INDEX_OUTOFBOUNDS_ERROR)) + ThrowXML(TranscodingException, XML4CExcepts::Trans_CouldNotXCodeXMLData); + + // Calculate the bytes eaten and store in caller's param + bytesEaten = startSrc - srcData; + + // Return the chars we put into the target buffer + return startTarget - toFill; +} diff --git a/src/util/Transcoders/ICU/ICUTransService.hpp b/src/util/Transcoders/ICU/ICUTransService.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e1d12d660587bee05000e666a35399d161e9cd7f --- /dev/null +++ b/src/util/Transcoders/ICU/ICUTransService.hpp @@ -0,0 +1,212 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:08 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:34 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#ifndef ICUTRANSSERVICE_HPP +#define ICUTRANSSERVICE_HPP + +#include <util/Mutexes.hpp> +#include <util/TransService.hpp> + +struct UConverter; + +class XMLUTIL_EXPORT ICUTransService : public XMLTransService +{ +public : + // ----------------------------------------------------------------------- + // Public, static methods + // ----------------------------------------------------------------------- + static void setICUPath(const char* const pathToSet); + + + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ICUTransService(); + ~ICUTransService(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual transcoding service API + // ----------------------------------------------------------------------- + virtual int compareIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + ); + + virtual int compareNIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + , const unsigned int maxChars + ); + + virtual bool isSpace(const XMLCh toCheck) const; + + virtual XMLTranscoder* makeNewDefTranscoder(); + + virtual XMLTranscoder* makeNewTranscoderFor + ( + const XMLCh* const encodingName + , XMLTransService::Codes& resValue + , const unsigned int blockSize + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + ICUTransService(const ICUTransService&); + void operator=(const ICUTransService&); +}; + + + +class XMLUTIL_EXPORT ICUTranscoder : public XMLTranscoder +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ICUTranscoder(UConverter* const toAdopt, const unsigned int blockSize); + ~ICUTranscoder(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual transcoder interface + // ----------------------------------------------------------------------- + virtual unsigned int calcRequiredSize(const char* const srcText); + + virtual unsigned int calcRequiredSize(const XMLCh* const srcText); + + virtual XMLCh transcodeOne + ( + const char* const srcData + , const unsigned int srcBytes + , unsigned int& bytesEaten + ); + + virtual char* transcode(const XMLCh* const toTranscode); + + virtual bool transcode + ( + const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxChars + ); + + virtual XMLCh* transcode(const char* const toTranscode); + + virtual bool transcode + ( + const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars + ); + + virtual unsigned int transcodeXML + ( + const char* const srcData + , const unsigned int srcCount + , XMLCh* const toFill + , const unsigned int maxChars + , unsigned int& bytesEaten + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + ICUTranscoder(); + ICUTranscoder(const ICUTranscoder&); + void operator=(const ICUTranscoder&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fCharOfsBuf + // When we do the XML transcode call, the ICU stuff takes an array + // of ints that it fills with the size of each MB char as it xlats + // it. Its converted to another form for the caller, but this is used + // to get it from ICU. We don't want allocate it over and over so its + // done during ctor and left around. + // + // fConverter + // This is a pointer to the ICU converter that this transcoder + // uses. + // + // fMutex + // We have to synchronize threaded calls to the converter. + // ----------------------------------------------------------------------- + long* fCharOfsBuf; + UConverter* fConverter; + XMLMutex fMutex; +}; + +#endif diff --git a/src/util/Transcoders/ICU/Makefile.in b/src/util/Transcoders/ICU/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..520eaa4c17276954302c93dab0b13ab1dfe30259 --- /dev/null +++ b/src/util/Transcoders/ICU/Makefile.in @@ -0,0 +1,87 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:06:08 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:34 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util +SUBMODULE = Transcoders/ICU + +include ../../../Makefile.incl + +CPP_PUBHEADERS = ICUTransService.hpp + +CPP_OBJECTS = ICUTransService.o + +include ../../Makefile.util.submodule diff --git a/src/util/Transcoders/Iconv/IconvTransService.cpp b/src/util/Transcoders/Iconv/IconvTransService.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5756eda8999bb2d4deb0c8ebde22fa4e175bf0b --- /dev/null +++ b/src/util/Transcoders/Iconv/IconvTransService.cpp @@ -0,0 +1,483 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:10 twl + * Initial revision + * + * Revision 1.7 1999/11/08 20:45:34 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "IconvTransService.hpp" +#include <wchar.h> +#if defined (XML_GNUG) +#include <wctype.h> +#endif +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +static const int gTempBuffArraySize = 1024; +static unsigned int getWideCharLength(const XMLCh* const src) +{ + if (!src) + return 0; + + unsigned int len = 0; + const XMLCh* pTmp = src; + while (*pTmp++) + len++; + return len; +} + + + + +// --------------------------------------------------------------------------- +// IconvTransService: Constructors and Destructor +// --------------------------------------------------------------------------- +IconvTransService::IconvTransService() +{ +} + +IconvTransService::~IconvTransService() +{ +} + +// --------------------------------------------------------------------------- +// IconvTransService: The virtual transcoding service API +// --------------------------------------------------------------------------- +int IconvTransService::compareIString( const XMLCh* const comp1 + , const XMLCh* const comp2) +{ + unsigned int lent1 = getWideCharLength(comp1); + unsigned int lent2 = getWideCharLength(comp2); + + wchar_t* tmp1 = new wchar_t[lent1 + 1]; + wchar_t* tmp2 = new wchar_t[lent2 + 1]; + + const XMLCh* ptr = comp1; + wchar_t* target = tmp1; + while (*ptr++) + *target++ = *ptr; + *target = 0x00; + + ptr = comp2; + target = tmp2; + while (*ptr++) + *target++ = *ptr; + *target = 0x00; + + int retval = wcscasecmp(tmp1, tmp2); + + delete [] tmp1; + delete [] tmp2; + + return retval; +} + +int IconvTransService::compareNIString( const XMLCh* const comp1 + , const XMLCh* const comp2 + , const unsigned int maxChars) +{ + unsigned int lent1 = getWideCharLength(comp1); + unsigned int lent2 = getWideCharLength(comp2); + + wchar_t* tmp1 = new wchar_t[lent1 + 1]; + wchar_t* tmp2 = new wchar_t[lent2 + 1]; + + const XMLCh* ptr = comp1; + wchar_t* target = tmp1; + while (*ptr++) + *target++ = *ptr; + *target = 0x00; + + ptr = comp2; + target = tmp2; + while (*ptr++) + *target++ = *ptr; + *target = 0x00; + + int retval = wcsncasecmp(tmp1, tmp2, maxChars); + + delete [] tmp1; + delete [] tmp2; + + return retval; +} + + +bool IconvTransService::isSpace(const XMLCh toCheck) const +{ + return (iswspace(toCheck) != 0); +} + + +XMLTranscoder* IconvTransService::makeNewDefTranscoder() +{ + // Just allocate a new transcoder of our type + return new IconvTranscoder; +} + + +XMLTranscoder* +IconvTransService::makeNewTranscoderFor(const XMLCh* const encodingName + , XMLTransService::Codes& resValue + , const unsigned int ) +{ + // + // NOTE: We don't use the block size here + // + // + // This is a minimalist transcoding service, that only supports a local + // default transcoder. All named encodings return zero as a failure, + // which means that only the intrinsic encodings supported by the parser + // itself will work for XML data. + // + resValue = XMLTransService::UnsupportedEncoding; + return 0; +} + +// --------------------------------------------------------------------------- +// IconvTranscoder: Constructors and Destructor +// --------------------------------------------------------------------------- +IconvTranscoder::IconvTranscoder() +{ +} + +IconvTranscoder::~IconvTranscoder() +{ +} + + +// --------------------------------------------------------------------------- +// IconvTranscoder: The virtual transcoder API +// --------------------------------------------------------------------------- +unsigned int IconvTranscoder::calcRequiredSize(const char* const srcText) +{ + if (!srcText) + return 0; + + const unsigned int retVal = ::mbstowcs(NULL, srcText, 0); + + if (retVal == -1) + return 0; + return retVal; +} + + +unsigned int IconvTranscoder::calcRequiredSize(const XMLCh* const srcText) +{ + if (!srcText) + return 0; + + unsigned int wLent = getWideCharLength(srcText); + wchar_t tmpWideCharArr[gTempBuffArraySize]; + wchar_t* allocatedArray = 0; + wchar_t* wideCharBuf = 0; + + if (wLent >= gTempBuffArraySize) + wideCharBuf = allocatedArray = new wchar_t[wLent + 1]; + else + wideCharBuf = tmpWideCharArr; + + for (unsigned int i = 0; i < wLent; i++) + { + wideCharBuf[i] = srcText[i]; + } + wideCharBuf[wLent] = 0x00; + + const unsigned int retVal = ::wcstombs(NULL, wideCharBuf, 0); + delete [] allocatedArray; + + if (retVal == -1) + return 0; + return retVal; +} + + + +XMLCh IconvTranscoder::transcodeOne(const char* const srcData + , const unsigned int srcBytes + , unsigned int& bytesEaten) +{ + wchar_t toFill; + int eaten = ::mbtowc(&toFill, srcData, srcBytes); + if (eaten == -1) + { + bytesEaten = 0; + return 0; + } + + // Return the bytes we ate and the resulting char. + bytesEaten = eaten; + return toFill; +} + + + +char* IconvTranscoder::transcode(const XMLCh* const toTranscode) +{ + if (!toTranscode) + return 0; + + char* retVal = 0; + if (toTranscode) + { + unsigned int wLent = getWideCharLength(toTranscode); + + wchar_t tmpWideCharArr[gTempBuffArraySize]; + wchar_t* allocatedArray = 0; + wchar_t* wideCharBuf = 0; + + if (wLent >= gTempBuffArraySize) + wideCharBuf = allocatedArray = new wchar_t[wLent + 1]; + else + wideCharBuf = tmpWideCharArr; + + for (unsigned int i = 0; i < wLent; i++) + { + wideCharBuf[i] = toTranscode[i]; + } + wideCharBuf[wLent] = 0x00; + + // Calc the needed size. + const size_t neededLen = ::wcstombs(NULL, wideCharBuf, 0); + if (neededLen == 0) + { + delete [] allocatedArray; + return 0; + } + + retVal = new char[neededLen + 1]; + ::wcstombs(retVal, wideCharBuf, neededLen); + retVal[neededLen] = 0; + delete [] allocatedArray; + } + else + { + retVal = new char[1]; + retVal[0] = 0; + } + return retVal; +} + + +bool IconvTranscoder::transcode(const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxBytes) +{ + // Watch for a couple of pyscho corner cases + if (!toTranscode || !maxBytes) + { + toFill[0] = 0; + return true; + } + + if (!*toTranscode) + { + toFill[0] = 0; + return true; + } + + wchar_t tmpWideCharArr[gTempBuffArraySize]; + wchar_t* allocatedArray = 0; + wchar_t* wideCharBuf = 0; + + if (maxBytes >= gTempBuffArraySize) + wideCharBuf = allocatedArray = new wchar_t[maxBytes + 1]; + else + wideCharBuf = tmpWideCharArr; + + for (unsigned int i = 0; i < maxBytes; i++) + { + wideCharBuf[i] = toTranscode[i]; + } + wideCharBuf[maxBytes] = 0x00; + + // Ok, go ahead and try the transcoding. If it fails, then ... + // + + if (::wcstombs(toFill, wideCharBuf, maxBytes) == -1) + { + delete [] allocatedArray; + return false; + } + + // Cap it off just in case + toFill[maxBytes] = 0; + delete [] allocatedArray; + return true; +} + + + +XMLCh* IconvTranscoder::transcode(const char* const toTranscode) +{ + XMLCh* retVal = 0; + if (toTranscode) + { + const unsigned int len = calcRequiredSize(toTranscode); + if (len == 0) + return 0; + + wchar_t tmpWideCharArr[gTempBuffArraySize]; + wchar_t* allocatedArray = 0; + wchar_t* wideCharBuf = 0; + + if (len >= gTempBuffArraySize) + wideCharBuf = allocatedArray = new wchar_t[len + 1]; + else + wideCharBuf = tmpWideCharArr; + + ::mbstowcs(wideCharBuf, toTranscode, len); + retVal = new XMLCh[len + 1]; + for (unsigned int i = 0; i < len; i++) + { + retVal[i] = (XMLCh) wideCharBuf[i]; + } + retVal[len] = 0x00; + delete [] allocatedArray; + } + else + { + retVal = new XMLCh[1]; + retVal[0] = 0; + } + return retVal; +} + + +bool IconvTranscoder::transcode(const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars) +{ + // Check for a couple of psycho corner cases + if (!toTranscode || !maxChars) + { + toFill[0] = 0; + return true; + } + + if (!*toTranscode) + { + toFill[0] = 0; + return true; + } + + wchar_t tmpWideCharArr[gTempBuffArraySize]; + wchar_t* allocatedArray = 0; + wchar_t* wideCharBuf = 0; + + if (maxChars >= gTempBuffArraySize) + wideCharBuf = allocatedArray = new wchar_t[maxChars + 1]; + else + wideCharBuf = tmpWideCharArr; + + if (::mbstowcs(wideCharBuf, toTranscode, maxChars) == -1) + { + delete [] allocatedArray; + return false; + } + + for (unsigned int i = 0; i < maxChars; i++) + { + toFill[i] = (XMLCh) wideCharBuf[i]; + } + toFill[maxChars] = 0x00; + delete [] allocatedArray; + return true; +} + + +unsigned int +IconvTranscoder::transcodeXML( const char* const srcData + , const unsigned int srcCount + , XMLCh* const toFill + , const unsigned int maxChars + , unsigned int& bytesEaten) +{ + // + // For this one, because we have to maintain the offset table, we have + // to do them one char at a time until we run out of source data. + // + unsigned int countIn = 0; + unsigned int countOut = 0; + while (countOut < maxChars) + { + wchar_t oneWideChar; + const int bytesEaten = + ::mbtowc(&oneWideChar, &srcData[countIn], srcCount - countIn); + + // We are done, so break out + if (bytesEaten == -1) + break; + toFill[countOut] = (XMLCh) oneWideChar; + countIn += (unsigned int) bytesEaten; + countOut++; + } + + // Give back the counts of eaten and transcoded + bytesEaten = countIn; + return countOut; +} diff --git a/src/util/Transcoders/Iconv/IconvTransService.hpp b/src/util/Transcoders/Iconv/IconvTransService.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ba3769c3a6ea04f1597172625ea3bc312d7506ae --- /dev/null +++ b/src/util/Transcoders/Iconv/IconvTransService.hpp @@ -0,0 +1,181 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:10 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:34 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#ifndef ICONVTRANSSERVICE_HPP +#define ICONVTRANSSERVICE_HPP + +#include <util/TransService.hpp> + +class XMLUTIL_EXPORT IconvTransService : public XMLTransService +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + IconvTransService(); + ~IconvTransService(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual transcoding service API + // ----------------------------------------------------------------------- + virtual int compareIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + ); + + virtual int compareNIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + , const unsigned int maxChars + ); + + virtual bool isSpace(const XMLCh toCheck) const; + + virtual XMLTranscoder* makeNewDefTranscoder(); + + virtual XMLTranscoder* makeNewTranscoderFor + ( + const XMLCh* const encodingName + , XMLTransService::Codes& resValue + , const unsigned int blockSize + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + IconvTransService(const IconvTransService&); + void operator=(const IconvTransService&); +}; + + + + +class XMLUTIL_EXPORT IconvTranscoder : public XMLTranscoder +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + IconvTranscoder(); + ~IconvTranscoder(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual transcoder interface + // ----------------------------------------------------------------------- + virtual unsigned int calcRequiredSize(const char* const srcText); + + virtual unsigned int calcRequiredSize(const XMLCh* const srcText); + + virtual XMLCh transcodeOne + ( + const char* const srcData + , const unsigned int srcBytes + , unsigned int& bytesEaten + ); + + virtual char* transcode(const XMLCh* const toTranscode); + + virtual bool transcode + ( + const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxBytes + ); + + virtual XMLCh* transcode(const char* const toTranscode); + + virtual bool transcode + ( + const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars + ); + + virtual unsigned int transcodeXML + ( + const char* const srcData + , const unsigned int srcCount + , XMLCh* const toFill + , const unsigned int maxChars + , unsigned int& bytesEaten + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + IconvTranscoder(const IconvTranscoder&); + void operator=(const IconvTranscoder&); +}; + +#endif diff --git a/src/util/Transcoders/Iconv/Makefile.in b/src/util/Transcoders/Iconv/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..52a95bd4b64a670c0d21e2f614c5b553280a7a9f --- /dev/null +++ b/src/util/Transcoders/Iconv/Makefile.in @@ -0,0 +1,87 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:06:11 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:35 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +MODULE = util +SUBMODULE = Transcoders/Iconv + +include ../../../Makefile.incl + +CPP_PUBHEADERS = IconvTransService.hpp + +CPP_OBJECTS = IconvTransService.o + +include ../../Makefile.util.submodule diff --git a/src/util/Transcoders/Win32/Win32TransService.cpp b/src/util/Transcoders/Win32/Win32TransService.cpp new file mode 100644 index 0000000000000000000000000000000000000000..32c96da46583be5c552aa88819b6281781045785 --- /dev/null +++ b/src/util/Transcoders/Win32/Win32TransService.cpp @@ -0,0 +1,326 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:04 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:35 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "Win32TransService.hpp" +#include <windows.h> + + +// --------------------------------------------------------------------------- +// Win32TransService: Constructors and Destructor +// --------------------------------------------------------------------------- +Win32TransService::Win32TransService() +{ +} + +Win32TransService::~Win32TransService() +{ +} + + +// --------------------------------------------------------------------------- +// Win32TransService: The virtual transcoding service API +// --------------------------------------------------------------------------- +int Win32TransService::compareIString( const XMLCh* const comp1 + , const XMLCh* const comp2) +{ + return _wcsicmp(comp1, comp2); +} + +int Win32TransService::compareNIString( const XMLCh* const comp1 + , const XMLCh* const comp2 + , const unsigned int maxChars) +{ + return _wcsnicmp(comp1, comp2, maxChars); +} + +bool Win32TransService::isSpace(const XMLCh toCheck) const +{ + return (::iswspace(toCheck) != 0); +} + +XMLTranscoder* Win32TransService::makeNewDefTranscoder() +{ + // Just allocate a new transcoder of our type + return new Win32Transcoder; +} + +XMLTranscoder* +Win32TransService::makeNewTranscoderFor(const XMLCh* const encodingName + , XMLTransService::Codes& resValue + , const unsigned int ) +{ + // + // NOTE: We don't use the block size here + // + + // + // This is a minimalist transcoding service, that only supports a local + // default transcoder. All named encodings return zero as a failure, + // which means that only the intrinsic encodings supported by the parser + // itself will work for XML data. + // + resValue = XMLTransService::UnsupportedEncoding; + return 0; +} + + + + +// --------------------------------------------------------------------------- +// Win32Transcoder: Constructors and Destructor +// --------------------------------------------------------------------------- +Win32Transcoder::Win32Transcoder() +{ +} + +Win32Transcoder::~Win32Transcoder() +{ +} + + +// --------------------------------------------------------------------------- +// Win32Transcoder: The virtual transcoder API +// --------------------------------------------------------------------------- +unsigned int Win32Transcoder::calcRequiredSize(const char* const srcText) +{ + if (!srcText) + return 0; + + const unsigned int retVal = ::mbstowcs(0, srcText, 0); + if (retVal == (unsigned int)-1) + return 0; + return retVal; +} + + +unsigned int Win32Transcoder::calcRequiredSize(const XMLCh* const srcText) +{ + if (!srcText) + return 0; + + const unsigned int retVal = ::wcstombs(0, srcText, 0); + if (retVal == (unsigned int)-1) + return 0; + return retVal; +} + + +XMLCh Win32Transcoder::transcodeOne(const char* const srcData + , const unsigned int srcBytes + , unsigned int& bytesEaten) +{ + XMLCh toFill; + size_t eaten = ::mbtowc(&toFill, srcData, srcBytes); + if (eaten == size_t(-1)) + { + bytesEaten = 0; + return 0; + } + + // Return the bytes we ate and the resulting char + bytesEaten = eaten; + return toFill; +} + + +char* Win32Transcoder::transcode(const XMLCh* const toTranscode) +{ + if (!toTranscode) + return 0; + + char* retVal = 0; + if (toTranscode) + { + // Calc the needed size + const unsigned int neededLen = ::wcstombs(0, toTranscode, 0); + if (neededLen == (unsigned int)-1) + return 0; + + retVal = new char[neededLen + 1]; + ::wcstombs(retVal, toTranscode, neededLen + 1); + } + else + { + retVal = new char[1]; + retVal[0] = 0; + } + return retVal; +} + + +bool Win32Transcoder::transcode(const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxBytes) +{ + // Watch for a couple of pyscho corner cases + if (!toTranscode || !maxBytes) + { + toFill[0] = 0; + return true; + } + + if (!*toTranscode) + { + toFill[0] = 0; + return true; + } + + // Ok, go ahead and try the transcoding. If it fails, then + if (::wcstombs(toFill, toTranscode, maxBytes + 1) == size_t(-1)) + return false; + + // Cap it off just in case + toFill[maxBytes] = 0; + return true; +} + + +XMLCh* Win32Transcoder::transcode(const char* const toTranscode) +{ + if (!toTranscode) + return 0; + + XMLCh* retVal = 0; + if (toTranscode) + { + const unsigned int len = ::mbstowcs(0, toTranscode, 0); + if (len == (unsigned int)-1) + return 0; + + retVal = new XMLCh[len + 1]; + ::mbstowcs(retVal, toTranscode, len + 1); + } + else + { + retVal = new XMLCh[1]; + retVal[0] = 0; + } + return retVal; +} + + +bool Win32Transcoder::transcode(const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars) +{ + // Check for a couple of psycho corner cases + if (!toTranscode || !maxChars) + { + toFill[0] = 0; + return true; + } + + if (!*toTranscode) + { + toFill[0] = 0; + return true; + } + + // Looks ok so lets transcode it + if (::mbstowcs(toFill, toTranscode, maxChars + 1) == size_t(-1)) + return false; + return true; +} + + +unsigned int +Win32Transcoder::transcodeXML( const char* const srcData + , const unsigned int srcCount + , XMLCh* const toFill + , const unsigned int maxChars + , unsigned int& bytesEaten) +{ + // + // For this one, because we have to maintain the offset table, we have + // to do them one char at a time until we run out of source data. + // + unsigned int countIn = 0; + unsigned int countOut = 0; + while (countOut < maxChars) + { + const int bytesEaten = ::mbtowc + ( + &toFill[countOut] + , &srcData[countIn] + , srcCount - countIn + ); + + // We are done, so break out + if (bytesEaten == -1) + break; + + countIn += (unsigned int)bytesEaten; + countOut++; + } + + // Give back the counts of eaten and transcoded + bytesEaten = countIn; + return countOut; +} diff --git a/src/util/Transcoders/Win32/Win32TransService.hpp b/src/util/Transcoders/Win32/Win32TransService.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2add81835e2e424a8717dc74a2570cea5e34902e --- /dev/null +++ b/src/util/Transcoders/Win32/Win32TransService.hpp @@ -0,0 +1,181 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:06:06 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:35 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#ifndef WIN32TRANSSERVICE_HPP +#define WIN32TRANSSERVICE_HPP + +#include <util/TransService.hpp> + +class XMLUTIL_EXPORT Win32TransService : public XMLTransService +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + Win32TransService(); + ~Win32TransService(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual transcoding service API + // ----------------------------------------------------------------------- + virtual int compareIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + ); + + virtual int compareNIString + ( + const XMLCh* const comp1 + , const XMLCh* const comp2 + , const unsigned int maxChars + ); + + virtual bool isSpace(const XMLCh toCheck) const; + + virtual XMLTranscoder* makeNewDefTranscoder(); + + virtual XMLTranscoder* makeNewTranscoderFor + ( + const XMLCh* const encodingName + , XMLTransService::Codes& resValue + , const unsigned int blockSize + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + Win32TransService(const Win32TransService&); + void operator=(const Win32TransService&); +}; + + + + +class XMLUTIL_EXPORT Win32Transcoder : public XMLTranscoder +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + Win32Transcoder(); + ~Win32Transcoder(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual transcoder interface + // ----------------------------------------------------------------------- + virtual unsigned int calcRequiredSize(const char* const srcText); + + virtual unsigned int calcRequiredSize(const XMLCh* const srcText); + + virtual XMLCh transcodeOne + ( + const char* const srcData + , const unsigned int srcBytes + , unsigned int& bytesEaten + ); + + virtual char* transcode(const XMLCh* const toTranscode); + + virtual bool transcode + ( + const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxBytes + ); + + virtual XMLCh* transcode(const char* const toTranscode); + + virtual bool transcode + ( + const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars + ); + + virtual unsigned int transcodeXML + ( + const char* const srcData + , const unsigned int srcCount + , XMLCh* const toFill + , const unsigned int maxChars + , unsigned int& bytesEaten + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + Win32Transcoder(const Win32Transcoder&); + void operator=(const Win32Transcoder&); +}; + +#endif diff --git a/src/util/TranscodingException.hpp b/src/util/TranscodingException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fefa14364ca3f90da7375566b5df0877f6f7617a --- /dev/null +++ b/src/util/TranscodingException.hpp @@ -0,0 +1,86 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:15 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:16 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(TRANSCODINGEXCEPTION_HPP) +#define TRANSCODINGEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + + +// Hard coded Unicode text for "TranscodingException" +static const XMLCh gTranscodingException_Name[] = +{ + chLatin_T, chLatin_r, chLatin_a, chLatin_n, chLatin_s, chLatin_c + , chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chLatin_E + , chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i + , chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(TranscodingException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/URL.cpp b/src/util/URL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..90a2bbd17c3170abc3e8c0f9d7432c47ad065fc7 --- /dev/null +++ b/src/util/URL.cpp @@ -0,0 +1,627 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:04:20 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:16 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/BinFileInputStream.hpp> +#include <util/Janitor.hpp> +#include <util/PlatformUtils.hpp> +#include <util/RuntimeException.hpp> +#include <util/URL.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> + + +// --------------------------------------------------------------------------- +// Local types +// +// TypeEntry +// This structure defines a single entry in the list of URL types. Each +// entry indicates the prefix for that type of URL, and the SourceTypes +// value it maps to. +// --------------------------------------------------------------------------- +struct TypeEntry +{ + URL::Protocols protocol; + const XMLCh* prefix; + bool supported; +}; + + +// --------------------------------------------------------------------------- +// Local data +// +// gXXXString +// These are the strings for our prefix types. They all have to be +// Unicode strings all the time, so we can't just do regular strings. +// +// gTypeList +// The list of URL types that we support +// +// gMaxProtoLen +// gMaxColonPos +// The length of the longest protocol string and from that the maximum +// index at which we must see the colon. +// +// NOTE:!!! Be sure to keep this up to date! +// --------------------------------------------------------------------------- +static const XMLCh gFileString[] = +{ + chLatin_f, chLatin_i, chLatin_l, chLatin_e, chColon + , chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gFTPString[] = +{ + chLatin_f, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chNull +}; + +static const XMLCh gGopherString[] = +{ + chLatin_g, chLatin_o, chLatin_p, chLatin_h, chLatin_e + , chLatin_r, chColon, chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gHTTPString[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon + , chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gLocalHostString[] = +{ + chLatin_l, chLatin_o, chLatin_c, chLatin_a, chLatin_l + , chLatin_h, chLatin_o, chLatin_s, chLatin_t, chNull +}; + +static const XMLCh gMailToString[] = +{ + chLatin_m, chLatin_a, chLatin_i, chLatin_l, chLatin_t + , chLatin_o, chColon, chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gNewsString[] = +{ + chLatin_n, chLatin_e, chLatin_w, chLatin_s, chColon + , chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gNNTPString[] = +{ + chLatin_n, chLatin_n, chLatin_t, chLatin_p, chColon + , chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gTelnetString[] = +{ + chLatin_t, chLatin_e, chLatin_l, chLatin_n, chLatin_e + , chLatin_t, chColon, chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gWaisString[] = +{ + chLatin_w, chLatin_a, chLatin_i, chLatin_s, chColon + , chForwardSlash, chForwardSlash, chNull +}; + +static const XMLCh gProsperoString[] = +{ + chLatin_p, chLatin_r, chLatin_o, chLatin_s, chLatin_p + , chLatin_e, chLatin_r, chLatin_o, chColon, chForwardSlash + , chForwardSlash, chNull +}; + +static TypeEntry gTypeList[URL::Protocols_Count] = +{ + { URL::File , gFileString , true } + , { URL::HTTP , gHTTPString , false } + , { URL::FTP , gFTPString , false } + , { URL::Gopher , gGopherString , false } + , { URL::MailTo , gMailToString , false } + , { URL::News , gNewsString , false } + , { URL::NNTP , gNNTPString , false } + , { URL::Telnet , gTelnetString , false } + , { URL::Wais , gWaisString , false } + , { URL::Prospero , gProsperoString , false } +}; + +// !!! Keep these up to date with list above! +static const unsigned int gMaxProtoLen = 11; +static const unsigned int gMaxColonPos = gMaxProtoLen - 3; + + +// --------------------------------------------------------------------------- +// Local methods +// --------------------------------------------------------------------------- +static bool isHexDigit(const XMLCh toCheck) +{ + if ((toCheck >= chDigit_0) && (toCheck <= chDigit_9) + || (toCheck >= chLatin_A) && (toCheck <= chLatin_Z) + || (toCheck >= chLatin_a) && (toCheck <= chLatin_z)) + { + return true; + } + return false; +} + +static unsigned int xlatHexDigit(const XMLCh toXlat) +{ + if ((toXlat >= chDigit_0) && (toXlat <= chDigit_9)) + return (unsigned int)(toXlat - chDigit_0); + + if ((toXlat >= chLatin_A) && (toXlat <= chLatin_Z)) + return (unsigned int)(toXlat - chLatin_A) + 10; + + return (unsigned int)(toXlat - chLatin_a) + 10; +} + + + +// --------------------------------------------------------------------------- +// URL: Constructors and Destructor +// --------------------------------------------------------------------------- +URL::URL() : + + fFullURL(0) + , fHost(0) + , fPath(0) + , fProtocol(URL::File) +{ +} + +URL::URL(const URL& toCopy) : + + fFullURL(XMLString::replicate(toCopy.fFullURL)) + , fHost(XMLString::replicate(toCopy.fHost)) + , fPath(XMLString::replicate(toCopy.fPath)) + , fProtocol(toCopy.fProtocol) +{ +} + +URL::~URL() +{ + cleanup(); +} + + +// --------------------------------------------------------------------------- +// URL: Public operators +// --------------------------------------------------------------------------- +URL& URL::operator=(const URL& toAssign) +{ + if (this == &toAssign) + return *this; + + // Clean up our stuff + cleanup(); + + // And copy his stuff + fFullURL = XMLString::replicate(toAssign.fFullURL); + fHost = XMLString::replicate(toAssign.fHost); + fPath = XMLString::replicate(toAssign.fPath); + fProtocol = toAssign.fProtocol; + + return *this; +} + +bool URL::operator==(const URL& toCompare) const +{ + // Test the obvious one first + if (fProtocol != toCompare.fProtocol) + return false; + + // + // Oh well, we have to test the components. Don't test the original + // URLs, because normalization might have occured that would have made + // them equal even though actual text of the full URLs is not. + // + if (XMLString::compareString(fPath, toCompare.fPath)) + return false; + + if (XMLString::compareString(fHost, toCompare.fHost)) + return false; + + return true; +} + + + +// --------------------------------------------------------------------------- +// URL: Getter methods +// --------------------------------------------------------------------------- +const XMLCh* URL::getProtocol() const +{ + return gTypeList[fProtocol].prefix; +} + + +// --------------------------------------------------------------------------- +// URL: Setter methods +// --------------------------------------------------------------------------- +void URL::setURL(const XMLCh* const urlText) +{ + fFullURL = XMLString::replicate(urlText); + try + { + parse(); + } + + catch(...) + { + cleanup(); + throw; + } +} + +void URL::setURL(const char* const urlText) +{ + // Transcode the passed string to Unicode + fFullURL = XMLString::transcode(urlText); + try + { + parse(); + } + + catch(...) + { + cleanup(); + throw; + } +} + + + +// --------------------------------------------------------------------------- +// URL: Miscellaneous methods +// --------------------------------------------------------------------------- +BinInputStream* URL::makeNewStream() const +{ + switch(fProtocol) + { + case URL::File : + { + BinFileInputStream* retStrm = new BinFileInputStream(getPath()); + if (!retStrm->getIsOpen()) + { + delete retStrm; + return 0; + } + return retStrm; + break; + } + + default : + ThrowXML(MalformedURLException, XML4CExcepts::URL_UnsupportedProto); + break; + } + return 0; +} + + +// --------------------------------------------------------------------------- +// URL: Private helper methods +// --------------------------------------------------------------------------- + +// +// Just a central place to handle cleanup, since its done from a number +// of different spots. +// +void URL::cleanup() +{ + delete [] fFullURL; + fFullURL = 0; + delete [] fHost; + fHost = 0; + delete [] fPath; + fPath = 0; +} + + +// +// This method searches our list of protocols and sees if the passed text +// starts with one of them. The prefix is the whole thing up to the second +// forward slash. The length of the text is passed so that obvious failures +// can be found quickly. +// +URL::Protocols URL::findType(unsigned int& curPos) const +{ + XMLCh tmpStr[gMaxProtoLen+1]; + + // + // Remember the current position so we can do exploratory reads from + // the URL. Then look forward for a colon. + // + const unsigned int orgPos = curPos; + unsigned int tmpPos = curPos; + unsigned int tmpIndex = 0; + while (true) + { + // Get another char from the source URL. Indicate end of text is ok + const XMLCh nextCh = getNextCh(tmpPos, true); + + // If we hit the end, then no good + if (!nextCh) + ThrowXML(MalformedURLException, XML4CExcepts::URL_MalformedURL); + + // Store this new character + tmpStr[tmpIndex++] = nextCh; + + // If we hit the colon, break out + if (nextCh == chColon) + break; + + // If we exceed the max colon pos without finding a colon, then no good + if (tmpIndex > gMaxColonPos) + ThrowXML(MalformedURLException, XML4CExcepts::URL_MalformedURL); + } + + // + // See if the next two chars are forward slashes, If not, then undo + // our read and return local. Else store them and compare against + // the list. Indicate that end of input is ok here. + // + const bool gotSlashes = (getNextCh(tmpPos, true) == chForwardSlash) + && (getNextCh(tmpPos, true) == chForwardSlash); + if (!gotSlashes) + ThrowXML(MalformedURLException, XML4CExcepts::URL_MalformedURL); + + // Store the slashes in our temp string too + tmpStr[tmpIndex++] = chForwardSlash; + tmpStr[tmpIndex++] = chForwardSlash; + + // Update the caller's position and cap off our string + curPos = tmpPos; + tmpStr[tmpIndex] = chNull; + + // + // Ok, lets see if tmpStr matches any of the prefixes in our list of + // protocols. + // + for (unsigned int index = 0; index < Protocols_Count; index++) + { + if (!XMLString::compareString(tmpStr, gTypeList[index].prefix)) + return gTypeList[index].protocol; + } + + // Cannot be a supported URL protocol + ThrowXML(MalformedURLException, XML4CExcepts::URL_UnsupportedProto); +} + + +// +// This method is used during the parse. It gets the next character out of +// the source URL (in fFullURL, which is a copy of the original text) and +// returns it. It updates the passed position with the new position. +// +// The primary job of this method is to handle escaped characters, by reading +// them in and converting them to a Unicode char. +// +XMLCh URL::getNextCh(unsigned int& pos, const bool endOk) const +{ + // + // If we are at the end of the URL, then either return a zero or + // throw if end of URL is not legal here. + // + if (!fFullURL[pos]) + { + if (!endOk) + ThrowXML(MalformedURLException, XML4CExcepts::URL_MalformedURL); + return chNull; + } + + // + // See if the current character is a '%'. If so, then we need to + // deal with an escaped character. + // + if (fFullURL[pos] == chPercent) + { + XMLCh escapedChar = 0; + + // There must be at least two more characters + if (!fFullURL[pos+1] || !fFullURL[pos+2]) + ThrowXML(MalformedURLException, XML4CExcepts::URL_MalformedURL); + + // Get them out and test them + const XMLCh test1 = fFullURL[pos+1]; + const XMLCh test2 = fFullURL[pos+2]; + + if (!isHexDigit(test1) || !isHexDigit(test2)) + ThrowXML(MalformedURLException, XML4CExcepts::URL_MalformedURL); + + // Convert these to a character + escapedChar = XMLCh((xlatHexDigit(test1) << 4) + xlatHexDigit(test2)); + + // Bump the position up + pos += 3; + + return escapedChar; + } + + // Else just return the current char and bump the position + return fFullURL[pos++]; +} + + +// +// This method is called to parse the text into its components and validate +// that the URL is legal. It uses getNextCh() to pull characters out of the +// URL. +// +void URL::parse() +{ + // This is the current position that we track during the parse + unsigned int curPos = 0; + XMLCh nextCh; + const unsigned int bufSize = 2047; + XMLCh tmpBuf[bufSize + 1]; + unsigned int bufIndex; + + // + // Search the text for a prefix. We will get back the type of the prefix + // and the current position will be updated. + // + fProtocol = findType(curPos); + + // In order to distinguish between a malformed URL and an unsupported + // URL, we watch here for the types that we support. If its not supported + // we throw a runtime exception. + // + if (!gTypeList[fProtocol].supported) + ThrowXML(MalformedURLException, XML4CExcepts::URL_UnsupportedProto); + + // + // Check the next char. It must be either a forward slash or it will + // be the first char of the host name. We don't allow end of input + // here so it will cause an exception if we hit it. + // + nextCh = getNextCh(curPos); + if (nextCh == chForwardSlash) + { + // There is no host so make an empty one + fHost = new XMLCh[1]; + fHost[0] = chNull; + } + else + { + // Put in the lookahead char we did above before we enter the loop + bufIndex = 0; + tmpBuf[bufIndex++] = nextCh; + + // And now read up to the slash separator + while (true) + { + // Get the next char, end of input is not valid here + const XMLCh nextCh = getNextCh(curPos); + + // Break out on the forward slash + if (nextCh == chForwardSlash) + break; + + // Otherwise, save it + tmpBuf[bufIndex++] = nextCh; + + // If we max out on the temp buffer, definitely bad + if (bufIndex >= bufSize) + ThrowXML(MalformedURLException, XML4CExcepts::URL_MalformedURL); + } + + // Cap the temp buffer and replicate to our host member + tmpBuf[bufIndex] = chNull; + fHost = XMLString::replicate(tmpBuf); + } + + // + // Now we need to get the path part of the URL. This should be the + // rest of the content. So we just go until we get a null char back + // from the character spooler. This gets rid of all escaped chars + // in the URL. + // + bufIndex = 0; + while (true) + { + // Tell it that end of input is ok + const XMLCh nextCh = getNextCh(curPos, true); + tmpBuf[bufIndex++] = nextCh; + + // Break out at the end + if (!nextCh) + break; + } + + // + // And get our own copy of the temp buffer as the path. If the path + // does not start with 'x:', then assume that its a Unix style path + // and put in a leading '/'. + // + tmpBuf[bufIndex] = chNull; + if ((((tmpBuf[0] >= chLatin_A) && (tmpBuf[0] <= chLatin_Z)) + || ((tmpBuf[0] >= chLatin_a) && (tmpBuf[0] <= chLatin_z))) + && (tmpBuf[1] == chColon)) + { + fPath = XMLString::replicate(tmpBuf); + } + else + { + fPath = new XMLCh[XMLString::stringLen(tmpBuf) + 2]; + fPath[0] = chForwardSlash; + XMLString::copyString(&fPath[1], tmpBuf); + } + + // + // <TBD> When we have more complete support, get rid of this. But for + // now we only support file:// (which is checked above) and for files + // we only support an empty host or "localhost" which means the same + // thing. + // + if (fHost[0]) + { + if (XMLString::compareString(fHost, gLocalHostString)) + ThrowXML(MalformedURLException, XML4CExcepts::URL_OnlyLocalHost); + } +} diff --git a/src/util/URL.hpp b/src/util/URL.hpp new file mode 100644 index 0000000000000000000000000000000000000000..81c27e8a6b69299b6ae80ef19608d17d835cefea --- /dev/null +++ b/src/util/URL.hpp @@ -0,0 +1,226 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:22 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:16 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(URL_HPP) +#define URL_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + +class BinInputStream; + + +// Hard coded Unicode text for "MalformedURLException" +static const XMLCh gMalformedURLException_Name[] = +{ + chLatin_M, chLatin_a, chLatin_l, chLatin_f, chLatin_o, chLatin_r + , chLatin_m, chLatin_e, chLatin_d, chLatin_U, chLatin_R, chLatin_L + , chLatin_E, chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t + , chLatin_i, chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(MalformedURLException, XMLUTIL_EXPORT) + + +// +// This class provides a minimal URL implementation to be able to deal +// with file:// protocol URLs. It will be fleshed out in the future. +// +class XMLUTIL_EXPORT URL +{ +public: + // ----------------------------------------------------------------------- + // Class types + // + // Local MUST be the last one in the list! And they must remain in this + // order because they are indexes into an array internally! + // ----------------------------------------------------------------------- + enum Protocols + { + File + , HTTP + , FTP + , Gopher + , MailTo + , News + , NNTP + , Telnet + , Wais + , Prospero + + , Protocols_Count + }; + + + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + URL(); + URL(const URL& toCopy); + virtual ~URL(); + + + // ----------------------------------------------------------------------- + // Operators + // ----------------------------------------------------------------------- + URL& operator=(const URL& toAssign); + bool operator==(const URL& toCompare) const; + bool operator!=(const URL& toCompare) const; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + const XMLCh* getHost() const; + const XMLCh* getProtocol() const; + const XMLCh* getPath() const; + URL::Protocols getType() const; + const XMLCh* getURL() const; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + void setURL(const XMLCh* const urlText); + void setURL(const char* const urlText); + + + // ----------------------------------------------------------------------- + // Miscellaneous methods + // ----------------------------------------------------------------------- + BinInputStream* makeNewStream() const; + + +private: + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + void cleanup(); + URL::Protocols findType(unsigned int& curPos) const; + XMLCh getNextCh(unsigned int& pos, const bool endOk = false) const; + XMLCh peekNextCh(unsigned int pos) const; + void parse(); + + + // ----------------------------------------------------------------------- + // Data members + // + // fFullURL + // This is a copy of the original URL. + // + // fHost + // The host part of the URL that was parsed out. This one will often + // be empty (or "localhost", which also means the current machine.) + // + // fPath + // The path part of the URL that was parsed out. + // + // fProtocol + // Indicates the type of the URL's source. The text of the prefix + // can be gotten from this. + // ----------------------------------------------------------------------- + XMLCh* fFullURL; + XMLCh* fHost; + XMLCh* fPath; + Protocols fProtocol; +}; + + +// --------------------------------------------------------------------------- +// URL: Public operators +// --------------------------------------------------------------------------- +inline bool URL::operator!=(const URL& toCompare) const +{ + return !operator==(toCompare); +} + + +// --------------------------------------------------------------------------- +// URL: Getter methods +// --------------------------------------------------------------------------- +inline const XMLCh* URL::getHost() const +{ + return fHost; +} + +inline const XMLCh* URL::getPath() const +{ + return fPath; +} + +inline URL::Protocols URL::getType() const +{ + return fProtocol; +} + +inline const XMLCh* URL::getURL() const +{ + return fFullURL; +} + + +#endif diff --git a/src/util/UTFDataFormatException.hpp b/src/util/UTFDataFormatException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..eb53458e8be5068177783725240473a236fbf502 --- /dev/null +++ b/src/util/UTFDataFormatException.hpp @@ -0,0 +1,87 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:24 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:17 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(UTFDATAFORMATEXCEPTION_HPP) +#define UTFDATAFORMATEXCEPTION_HPP + + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + + +// Hard coded Unicode text for "UTFDataFormatException" +static const XMLCh gUTFDataFormatException_Name[] = +{ + chLatin_U, chLatin_T, chLatin_F, chLatin_D, chLatin_a, chLatin_t + , chLatin_a, chLatin_F, chLatin_o, chLatin_r, chLatin_m, chLatin_a + , chLatin_t, chLatin_E, chLatin_x, chLatin_c, chLatin_e, chLatin_p + , chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(UTFDataFormatException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/UnexpectedEOFException.hpp b/src/util/UnexpectedEOFException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..976e5f80edf54aa47fb67f3990e2b168b4a19dde --- /dev/null +++ b/src/util/UnexpectedEOFException.hpp @@ -0,0 +1,86 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:19 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:17 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(UNEXPECTEDEOFEXCEPTION_HPP) +#define UNEXPECTEDEOFEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + + +// Hard coded Unicode text for "UnexpectedEOFException" +static const XMLCh gUnexpectedEOFException_Name[] = +{ + chLatin_U, chLatin_n, chLatin_e, chLatin_x, chLatin_p, chLatin_e + , chLatin_c, chLatin_t, chLatin_e, chLatin_d, chLatin_E, chLatin_O + , chLatin_F, chLatin_E, chLatin_x, chLatin_c, chLatin_e, chLatin_p + , chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(UnexpectedEOFException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/UnsupportedEncodingException.hpp b/src/util/UnsupportedEncodingException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..000bda2df1ea42664607b30f1d649c656ca88639 --- /dev/null +++ b/src/util/UnsupportedEncodingException.hpp @@ -0,0 +1,87 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:21 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:17 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(UNSUPPORTEDENCODINGEXCEPTION_HPP) +#define UNSUPPORTEDENCODINGEXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLException.hpp> +#include <util/XMLUni.hpp> + + +// Hard coded Unicode text for "UnsupportedEncodingException" +static const XMLCh gUnsupportedEncodingException_Name[] = +{ + chLatin_U, chLatin_n, chLatin_s, chLatin_u, chLatin_p, chLatin_p + , chLatin_o, chLatin_r, chLatin_t, chLatin_e, chLatin_d, chLatin_E + , chLatin_n, chLatin_c, chLatin_o, chLatin_d, chLatin_i, chLatin_n + , chLatin_g, chLatin_E, chLatin_x, chLatin_c, chLatin_e, chLatin_p + , chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull +}; + +MakeXML4CException(UnsupportedEncodingException, XMLUTIL_EXPORT) + +#endif diff --git a/src/util/ValueArrayOf.c b/src/util/ValueArrayOf.c new file mode 100644 index 0000000000000000000000000000000000000000..86f761c74724a77616ba2d64f7d94d13812795b7 --- /dev/null +++ b/src/util/ValueArrayOf.c @@ -0,0 +1,284 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:26 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:17 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/ValueArrayOf.hpp> +#endif + + +// --------------------------------------------------------------------------- +// ValueArrayOf: Contructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> ValueArrayOf<TElem>:: +ValueArrayOf(const unsigned int size) : + + fSize(size) + , fArray(0) +{ + fArray = new TElem[fSize]; +} + +template <class TElem> ValueArrayOf<TElem>:: +ValueArrayOf(const TElem* values, const unsigned int size) : + + fSize(size) + , fArray(0) +{ + fArray = new TElem[fSize]; + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = values[index]; +} + +template <class TElem> ValueArrayOf<TElem>:: +ValueArrayOf(const ValueArrayOf<TElem>& source) : + + fSize(source.fSize) + , fArray(0) +{ + fArray = new TElem[fSize]; + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = source.fArray[index]; +} + +template <class TElem> ValueArrayOf<TElem>::~ValueArrayOf() +{ + delete [] fArray; +} + + +// --------------------------------------------------------------------------- +// ValueArrayOf: Public operators +// --------------------------------------------------------------------------- +template <class TElem> TElem& ValueArrayOf<TElem>:: +operator[](const unsigned int index) +{ + if (index >= fSize) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Array_BadIndex); + return fArray[index]; +} + +template <class TElem> const TElem& ValueArrayOf<TElem>:: +operator[](const unsigned int index) const +{ + if (index >= fSize) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Array_BadIndex); + return fArray[index]; +} + +template <class TElem> ValueArrayOf<TElem>& ValueArrayOf<TElem>:: +operator=(const ValueArrayOf<TElem>& toAssign) +{ + if (this == &toAssign) + return *this; + + // Reallocate if not the same size + if (toAssign.fSize != fSize) + { + delete [] fArray; + fSize = toAssign.fSize; + fArray = new TElem[fSize]; + } + + // Copy over the source elements + for (unsigned int index = 0; index < fSize; index++) + fArray[index] = toAssign.fArray[index]; + + return *this; +} + +template <class TElem> bool ValueArrayOf<TElem>:: +operator==(const ValueArrayOf<TElem>& toCompare) const +{ + if (this == &toCompare) + return true; + + if (fSize != toCompare.fSize) + return false; + + for (unsigned int index = 0; index < fSize; index++) + { + if (fArray[index] != toCompare.fArray[index]) + return false; + } + + return true; +} + +template <class TElem> bool ValueArrayOf<TElem>:: +operator!=(const ValueArrayOf<TElem>& toCompare) const +{ + return !operator==(toCompare); +} + + +// --------------------------------------------------------------------------- +// ValueArrayOf: Copy operations +// --------------------------------------------------------------------------- +template <class TElem> unsigned int ValueArrayOf<TElem>:: +copyFrom(const ValueArrayOf<TElem>& srcArray) +{ + // + // Copy over as many of the source elements as will fit into + // this array. + // + const unsigned int count = fSize < srcArray.fSize ? + fSize : srcArray.fSize; + + for (unsigned int index = 0; index < count; index++) + fArray[index] = srcArray.fArray[index]; + + return count; +} + + +// --------------------------------------------------------------------------- +// ValueArrayOf: Getter methods +// --------------------------------------------------------------------------- +template <class TElem> unsigned int ValueArrayOf<TElem>:: +length() const +{ + return fSize; +} + +template <class TElem> TElem* ValueArrayOf<TElem>:: +rawData() const +{ + return fArray; +} + + +// --------------------------------------------------------------------------- +// ValueArrayOf: Miscellaneous methods +// --------------------------------------------------------------------------- +template <class TElem> void ValueArrayOf<TElem>:: +resize(const unsigned int newSize) +{ + if (newSize == fSize) + return; + + if (newSize < fSize) + ThrowXML(IllegalArgumentException, XML4CExcepts::Array_BadNewSize); + + // Allocate the new array + TElem* newArray = new TElem[newSize]; + + // Copy the existing values + unsigned int index = 0; + for (; index < fSize; index++) + newArray[index] = fArray[index]; + + for (; index < newSize; index++) + newArray[index] = TElem(0); + + // Delete the old array and udpate our members + delete [] fArray; + fArray = newArray; + fSize = newSize; +} + + + +// --------------------------------------------------------------------------- +// ValueArrayEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> ValueArrayEnumerator<TElem>:: +ValueArrayEnumerator(ValueArrayOf<TElem>* const toEnum, const bool adopt) : + fAdopted(adopt) + , fCurIndex(0) + , fToEnum(toEnum) +{ +} + +template <class TElem> ValueArrayEnumerator<TElem>::~ValueArrayEnumerator() +{ + if (fAdopted) + delete fToEnum; +} + + +// --------------------------------------------------------------------------- +// ValueArrayEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TElem> bool ValueArrayEnumerator<TElem>::hasMoreElements() const +{ + if (fCurIndex >= fToEnum->length()) + return false; + return true; +} + +template <class TElem> TElem& ValueArrayEnumerator<TElem>::nextElement() +{ + return (*fToEnum)[fCurIndex++]; +} + +template <class TElem> void ValueArrayEnumerator<TElem>::Reset() +{ + fCurIndex = 0; +} diff --git a/src/util/ValueArrayOf.hpp b/src/util/ValueArrayOf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d683e60d3a4d1b3116f38d6a8c51811364e9d36b --- /dev/null +++ b/src/util/ValueArrayOf.hpp @@ -0,0 +1,176 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:27 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:18 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(VALUEARRAY_HPP) +#define VALUEARRAY_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLEnumerator.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/IllegalArgumentException.hpp> + +template <class TElem> class ValueArrayOf +{ +public : + // ----------------------------------------------------------------------- + // Contructors and Destructor + // ----------------------------------------------------------------------- + ValueArrayOf(const unsigned int size); + ValueArrayOf(const TElem* values, const unsigned int size); + ValueArrayOf(const ValueArrayOf<TElem>& source); + ~ValueArrayOf(); + + + // ----------------------------------------------------------------------- + // Public operators + // ----------------------------------------------------------------------- + TElem& operator[](const unsigned int index); + const TElem& operator[](const unsigned int index) const; + ValueArrayOf<TElem>& operator=(const ValueArrayOf<TElem>& toAssign); + bool operator==(const ValueArrayOf<TElem>& toCompare) const; + bool operator!=(const ValueArrayOf<TElem>& toCompare) const; + + + // ----------------------------------------------------------------------- + // Copy operations + // ----------------------------------------------------------------------- + unsigned int copyFrom(const ValueArrayOf<TElem>& srcArray); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + unsigned int length() const; + TElem* rawData() const; + + + // ----------------------------------------------------------------------- + // Miscellaneous methods + // ----------------------------------------------------------------------- + void resize(const unsigned int newSize); + + +private : + // ----------------------------------------------------------------------- + // Data members + // ----------------------------------------------------------------------- + unsigned int fSize; + TElem* fArray; +}; + + +// +// An enumerator for a value array. It derives from the basic enumerator +// class, so that value vectors can be generically enumerated. +// +template <class TElem> class ValueArrayEnumerator : public XMLEnumerator<TElem> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ValueArrayEnumerator + ( + ValueArrayOf<TElem>* const toEnum + , const bool adopt = false + ); + ~ValueArrayEnumerator(); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TElem& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Data Members + // + // fAdopted + // Indicates whether we have adopted the passed vector. If so then + // we delete the vector when we are destroyed. + // + // fCurIndex + // This is the current index into the vector. + // + // fToEnum + // The value array being enumerated. + // ----------------------------------------------------------------------- + bool fAdopted; + unsigned int fCurIndex; + ValueArrayOf<TElem>* fToEnum; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/ValueArrayOf.c> +#endif + +#endif diff --git a/src/util/ValueStackOf.c b/src/util/ValueStackOf.c new file mode 100644 index 0000000000000000000000000000000000000000..5382529873db54b3e9427d4004c5862ef79f36f1 --- /dev/null +++ b/src/util/ValueStackOf.c @@ -0,0 +1,185 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:29 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:18 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/ValueStackOf.hpp> +#endif + + +// --------------------------------------------------------------------------- +// ValueStackOf: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> ValueStackOf<TElem>:: +ValueStackOf(const unsigned int fInitCapacity) : + + fVector(fInitCapacity) +{ +} + +template <class TElem> ValueStackOf<TElem>::~ValueStackOf() +{ +} + + +// --------------------------------------------------------------------------- +// ValueStackOf: Element management methods +// --------------------------------------------------------------------------- +template <class TElem> void ValueStackOf<TElem>::push(const TElem& toPush) +{ + fVector.addElement(toPush); +} + +template <class TElem> const TElem& ValueStackOf<TElem>::peek() const +{ + const int curSize = fVector.size(); + if (curSize == 0) + ThrowXML(EmptyStackException, XML4CExcepts::Stack_EmptyStack); + + return fVector.elementAt(curSize-1); +} + +template <class TElem> TElem ValueStackOf<TElem>::pop() +{ + const int curSize = fVector.size(); + if (curSize == 0) + ThrowXML(EmptyStackException, XML4CExcepts::Stack_EmptyStack); + + TElem retVal = fVector.elementAt(curSize-1); + fVector.removeElementAt(curSize-1); + return retVal; +} + +template <class TElem> void ValueStackOf<TElem>::removeAllElements() +{ + fVector.removeAllElements(); +} + + +// --------------------------------------------------------------------------- +// ValueStackOf: Getter methods +// --------------------------------------------------------------------------- +template <class TElem> bool ValueStackOf<TElem>::empty() +{ + return (fVector.size() == 0); +} + +template <class TElem> unsigned int ValueStackOf<TElem>::curCapacity() +{ + return fVector.curCapacity(); +} + +template <class TElem> unsigned int ValueStackOf<TElem>::size() +{ + return fVector.size(); +} + + + + +// --------------------------------------------------------------------------- +// ValueStackEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> ValueStackEnumerator<TElem>:: +ValueStackEnumerator( ValueStackOf<TElem>* const toEnum + , const bool adopt) : + + fAdopted(adopt) + , fCurIndex(0) + , fToEnum(toEnum) + , fVector(&toEnum->fVector) +{ +} + +template <class TElem> ValueStackEnumerator<TElem>::~ValueStackEnumerator() +{ + if (fAdopted) + delete fToEnum; +} + + +// --------------------------------------------------------------------------- +// ValueStackEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TElem> bool ValueStackEnumerator<TElem>::hasMoreElements() const +{ + if (fCurIndex >= fVector->size()) + return false; + return true; +} + +template <class TElem> TElem& ValueStackEnumerator<TElem>::nextElement() +{ + return fVector->elementAt(fCurIndex++); +} + +template <class TElem> void ValueStackEnumerator<TElem>::Reset() +{ + fCurIndex = 0; +} diff --git a/src/util/ValueStackOf.hpp b/src/util/ValueStackOf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8eda008120cf42c6e0a8849d77006c3a7d656b50 --- /dev/null +++ b/src/util/ValueStackOf.hpp @@ -0,0 +1,183 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:30 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:18 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(VALUESTACKOF_HPP) +#define VALUESTACKOF_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLEnumerator.hpp> +#include <util/EmptyStackException.hpp> +#include <util/ValueVectorOf.hpp> + + +// +// Forward declare the enumerator so he can be our friend. Can you say +// friend? Sure... +// +template <class TElem> class ValueStackEnumerator; + + +template <class TElem> class ValueStackOf +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ValueStackOf(const unsigned int fInitCapacity); + ~ValueStackOf(); + + + // ----------------------------------------------------------------------- + // Element management methods + // ----------------------------------------------------------------------- + void push(const TElem& toPush); + const TElem& peek() const; + TElem pop(); + void removeAllElements(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool empty(); + unsigned int curCapacity(); + unsigned int size(); + + +private : + // ----------------------------------------------------------------------- + // Declare our friends + // ----------------------------------------------------------------------- + friend class ValueStackEnumerator<TElem>; + + + // ----------------------------------------------------------------------- + // Data Members + // + // fVector + // The vector that is used as the backing data structure for the + // stack. + // ----------------------------------------------------------------------- + ValueVectorOf<TElem> fVector; +}; + + + +// +// An enumerator for a value stack. It derives from the basic enumerator +// class, so that value stacks can be generically enumerated. +// +template <class TElem> class ValueStackEnumerator : public XMLEnumerator<TElem> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ValueStackEnumerator + ( + ValueStackOf<TElem>* const toEnum + , const bool adopt = false + ); + ~ValueStackEnumerator(); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TElem& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Data Members + // + // fAdopted + // Indicates whether we have adopted the passed stack. If so then + // we delete the stack when we are destroyed. + // + // fCurIndex + // This is the current index into the vector inside the stack being + // enumerated. + // + // fToEnum + // The stack that is being enumerated. This is just kept for + // adoption purposes, since we really are enumerating the vector + // inside of it. + // ----------------------------------------------------------------------- + bool fAdopted; + unsigned int fCurIndex; + ValueVectorOf<TElem>* fVector; + ValueStackOf<TElem>* fToEnum; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/ValueStackOf.c> +#endif + +#endif diff --git a/src/util/ValueVectorOf.c b/src/util/ValueVectorOf.c new file mode 100644 index 0000000000000000000000000000000000000000..ab0058a22b55bfeded73f41bf657f099c4393c4e --- /dev/null +++ b/src/util/ValueVectorOf.c @@ -0,0 +1,300 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:31 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:18 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#if defined(XML4C_TMPLSINC) +#include <util/ValueVectorOf.hpp> +#endif + + + +// --------------------------------------------------------------------------- +// ValueVectorOf: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> ValueVectorOf<TElem>:: +ValueVectorOf(const unsigned int maxElems) : + + fCurCount(0) + , fMaxCount(maxElems) + , fElemList(0) +{ + fElemList = new TElem[fMaxCount]; +} + +template <class TElem> ValueVectorOf<TElem>:: +ValueVectorOf(const ValueVectorOf<TElem>& toCopy) : + + fCurCount(toCopy.fCurCount) + , fMaxCount(toCopy.fMaxCount) + , fElemList(0) +{ + fElemList = new TElem[fMaxCount]; + for (unsigned int index = 0; index < fCurCount; index++) + fElemList[index] = toCopy.fElemList[index]; +} + +template <class TElem> ValueVectorOf<TElem>::~ValueVectorOf() +{ + delete [] fElemList; +} + + + +// --------------------------------------------------------------------------- +// ValueVectorOf: Operators +// --------------------------------------------------------------------------- +template <class TElem> ValueVectorOf<TElem>& +ValueVectorOf<TElem>::operator=(const ValueVectorOf<TElem>& toAssign) +{ + if (this == &toAssign) + return *this; + + // Reallocate if required + if (fMaxCount < toAssign.fCurCount) + { + delete [] fElemList; + fElemList = new TElem[toAssign.fMaxCount]; + fMaxCount = toAssign.fMaxCount; + } + + fCurCount = toAssign.fCurCount; + for (unsigned int index = 0; index < fCurCount; index++) + fElemList[index] = toAssign.fElemList[index]; + + return *this; +} + + +// --------------------------------------------------------------------------- +// ValueVectorOf: Element management +// --------------------------------------------------------------------------- +template <class TElem> void ValueVectorOf<TElem>::addElement(const TElem& toAdd) +{ + ensureExtraCapacity(1); + fElemList[fCurCount] = toAdd; + fCurCount++; +} + +template <class TElem> void ValueVectorOf<TElem>:: +setElementAt(const TElem& toSet, const unsigned int setAt) +{ + if (setAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + fElemList[setAt] = toSet; +} + +template <class TElem> void ValueVectorOf<TElem>:: +insertElementAt(const TElem& toInsert, const unsigned int insertAt) +{ + if (insertAt == fCurCount) + { + addElement(toInsert); + return; + } + + if (insertAt > fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + + // Make room for the newbie + for (unsigned int index = fCurCount; index > insertAt; index--) + fElemList[index] = fElemList[index-1]; + + // And stick it in and bump the count + fElemList[insertAt] = toInsert; + fCurCount++; +} + +template <class TElem> void ValueVectorOf<TElem>:: +removeElementAt(const unsigned int removeAt) +{ + if (removeAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + + if (removeAt == fCurCount-1) + { + fCurCount--; + return; + } + + // Copy down every element above remove point + for (unsigned int index = removeAt; index < fCurCount-1; index++) + fElemList[index] = fElemList[index+1]; + + // And bump down count + fCurCount--; +} + +template <class TElem> void ValueVectorOf<TElem>::removeAllElements() +{ + fCurCount = 0; +} + + +// --------------------------------------------------------------------------- +// ValueVectorOf: Getter methods +// --------------------------------------------------------------------------- +template <class TElem> const TElem& ValueVectorOf<TElem>:: +elementAt(const unsigned int getAt) const +{ + if (getAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + return fElemList[getAt]; +} + +template <class TElem> TElem& ValueVectorOf<TElem>:: +elementAt(const unsigned int getAt) +{ + if (getAt >= fCurCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Vector_BadIndex); + return fElemList[getAt]; +} + +template <class TElem> unsigned int ValueVectorOf<TElem>::curCapacity() const +{ + return fMaxCount; +} + +template <class TElem> unsigned int ValueVectorOf<TElem>::size() const +{ + return fCurCount; +} + + + +// --------------------------------------------------------------------------- +// ValueVectorOf: Miscellaneous +// --------------------------------------------------------------------------- +template <class TElem> void ValueVectorOf<TElem>:: +ensureExtraCapacity(const unsigned int length) +{ + unsigned int newMax = fCurCount + length; + + if (newMax < fMaxCount) + return; + + // Avoid too many reallocations by expanding by a percentage + unsigned int minNewMax = (unsigned int)((double)fCurCount * 1.25); + if (newMax < minNewMax) + newMax = minNewMax; + + TElem* newList = new TElem[newMax]; + for (unsigned int index = 0; index < fCurCount; index++) + newList[index] = fElemList[index]; + + delete [] fElemList; + fElemList = newList; + fMaxCount = newMax; +} + +template <class TElem> const TElem* ValueVectorOf<TElem>::rawData() const +{ + return fElemList; +} + + + +// --------------------------------------------------------------------------- +// ValueVectorEnumerator: Constructors and Destructor +// --------------------------------------------------------------------------- +template <class TElem> ValueVectorEnumerator<TElem>:: +ValueVectorEnumerator( ValueVectorOf<TElem>* const toEnum + , const bool adopt) : + fAdopted(adopt) + , fCurIndex(0) + , fToEnum(toEnum) +{ +} + +template <class TElem> ValueVectorEnumerator<TElem>::~ValueVectorEnumerator() +{ + if (fAdopted) + delete fToEnum; +} + + +// --------------------------------------------------------------------------- +// ValueVectorEnumerator: Enum interface +// --------------------------------------------------------------------------- +template <class TElem> bool +ValueVectorEnumerator<TElem>::hasMoreElements() const +{ + if (fCurIndex >= fToEnum->size()) + return false; + return true; +} + +template <class TElem> TElem& ValueVectorEnumerator<TElem>::nextElement() +{ + return fToEnum->elementAt(fCurIndex++); +} + +template <class TElem> void ValueVectorEnumerator<TElem>::Reset() +{ + fCurIndex = 0; +} diff --git a/src/util/ValueVectorOf.hpp b/src/util/ValueVectorOf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..258c75b77a2e779fac7c4d18bb3a4adfc1923c66 --- /dev/null +++ b/src/util/ValueVectorOf.hpp @@ -0,0 +1,190 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:33 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:19 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(VALUEVECTOROF_HPP) +#define VALUEVECTOROF_HPP + +#include <util/XML4CDefs.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/XMLEnumerator.hpp> + + +template <class TElem> class ValueVectorOf +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ValueVectorOf(const unsigned int maxElems); + ValueVectorOf(const ValueVectorOf<TElem>& toCopy); + ~ValueVectorOf(); + + + // ----------------------------------------------------------------------- + // Operators + // ----------------------------------------------------------------------- + ValueVectorOf<TElem>& operator=(const ValueVectorOf<TElem>& toAssign); + + + // ----------------------------------------------------------------------- + // Element management + // ----------------------------------------------------------------------- + void addElement(const TElem& toAdd); + void setElementAt(const TElem& toSet, const unsigned int setAt); + void insertElementAt(const TElem& toInsert, const unsigned int insertAt); + void removeElementAt(const unsigned int removeAt); + void removeAllElements(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + const TElem& elementAt(const unsigned int getAt) const; + TElem& elementAt(const unsigned int getAt); + unsigned int curCapacity() const; + unsigned int size() const; + + + // ----------------------------------------------------------------------- + // Miscellaneous + // ----------------------------------------------------------------------- + void ensureExtraCapacity(const unsigned int length); + const TElem* rawData() const; + + +private: + // ----------------------------------------------------------------------- + // Data members + // + // fCurCount + // The count of values current added to the vector, which may be + // less than the internal capacity. + // + // fMaxCount + // The current capacity of the vector. + // + // fElemList + // The list of elements, which is dynamically allocated to the needed + // size. + // ----------------------------------------------------------------------- + unsigned int fCurCount; + unsigned int fMaxCount; + TElem* fElemList; +}; + + +// +// An enumerator for a value vector. It derives from the basic enumerator +// class, so that value vectors can be generically enumerated. +// +template <class TElem> class ValueVectorEnumerator : public XMLEnumerator<TElem> +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ValueVectorEnumerator + ( + ValueVectorOf<TElem>* const toEnum + , const bool adopt = false + ); + ~ValueVectorEnumerator(); + + + // ----------------------------------------------------------------------- + // Enum interface + // ----------------------------------------------------------------------- + bool hasMoreElements() const; + TElem& nextElement(); + void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Data Members + // + // fAdopted + // Indicates whether we have adopted the passed vector. If so then + // we delete the vector when we are destroyed. + // + // fCurIndex + // This is the current index into the vector. + // + // fToEnum + // The value vector being enumerated. + // ----------------------------------------------------------------------- + bool fAdopted; + unsigned int fCurIndex; + ValueVectorOf<TElem>* fToEnum; +}; + + +#if !defined(XML4C_TMPLSINC) +#include <util/ValueVectorOf.c> +#endif + +#endif diff --git a/src/util/XML4CDefs.hpp b/src/util/XML4CDefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f64377d9e807beb7f6f915f29042490fa46e523d --- /dev/null +++ b/src/util/XML4CDefs.hpp @@ -0,0 +1,263 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:35 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:19 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(XML4CDEFS_HPP) +#define XML4CDEFS_HPP + + +// --------------------------------------------------------------------------- +// These are the various representations of the current version of XML4C. +// These are updated for every build. They must be at the top because they +// can be used by various per-compiler headers below. +// --------------------------------------------------------------------------- +#define XML4C_DLLVersionStr "3_0" +static const char* const gXML4CVersionStr = "3_0"; +static const char* const gXML4CFullVersionStr = "3_0_0"; +static const unsigned int gXML4CMajVersion = 3; +static const unsigned int gXML4CMinVersion = 0; +static const unsigned int gXML4CRevision = 0; + + +// --------------------------------------------------------------------------- +// Include the header that does automatic sensing of the current platform +// and compiler. +// --------------------------------------------------------------------------- +#include <util/AutoSense.hpp> + + + +// --------------------------------------------------------------------------- +// According to the platform we include a platform specific file. This guy +// will set up any platform specific stuff, such as character mode. +// --------------------------------------------------------------------------- +#if defined(XML_WIN32) +#include <util/Platforms/Win32/Win32Defs.hpp> +#endif + +#if defined(XML_AIX) +#include <util/Platforms/AIX/AIXDefs.hpp> +#endif + +#if defined(XML_SOLARIS) +#include <util/Platforms/Solaris/SolarisDefs.hpp> +#endif + +#if defined(XML_HPUX) +#include <util/Platforms/HPUX/HPUXDefs.hpp> +#endif + +#if defined(XML_TANDEM) +#include <util/Platforms/Tandem/TandemDefs.hpp> +#endif + +#if defined(XML_LINUX) +#include <util/Platforms/Linux/LinuxDefs.hpp> +#endif + +#if defined(XML_OE390) +#include <util/Platforms/OS390/OE390Defs.hpp> +#endif + +#if defined(XML_OS2) +#include <util/Platforms/OS2/OS2Defs.hpp> +#endif + +#if defined(XML_MACOS) +#include <util/Platforms/MaxOS/MacOSDefs.hpp> +#endif + + +// --------------------------------------------------------------------------- +// And now we subinclude a header according to the development environment +// we are on. This guy defines for each platform some basic stuff that is +// specific to the development environment. +// --------------------------------------------------------------------------- +#if defined(XML_VISUALCPP) +#include <util/Compilers/VCPPDefs.hpp> +#endif + +#if defined(XML_CSET) +#include <util/Compilers/CSetDefs.hpp> +#endif + +#if defined(XML_BORLAND) +#include <util/Compilers/BorlandCDefs.hpp> +#endif + +#if defined(XML_SUNCC) +#include <util/Compilers/SunCCDefs.hpp> +#endif + +#if defined(XML_SOLARIS_KAICC) +#include <util/Compilers/SunKaiDefs.hpp> +#endif + +#if defined(XML_GNUG) +#include <util/Compilers/GNUGDefs.hpp> +#endif + +#if defined(XML_HPUX_CC) || defined(XML_HPUX_aCC) || defined(XML_HPUX_KAICC) +#include <util/Compilers/HPCCDefs.hpp> +#endif + +#if defined(XML_TANDEMCC) +#include <util/Compilers/TandemCCDefs.hpp> +#endif + +#if defined(XML_GCC) +#include <util/Compilers/GCCDefs.hpp> +#endif + +#if defined(XML_MVSCPP) +#include <util/Compilers/MVSCPPDefs.hpp> +#endif + +#if defined(XML_IBMVAW32) +#include <util/Compilers/IBMVAW32Defs.hpp> +#endif + +#if defined(XML_IBMVAOS2) +#include <util/Compilers/IBMVAOS2Defs.hpp> +#endif + +#if defined(XML_METROWERKS) +#include <util/Compilers/CodeWarriorDefs.hpp> +#endif + + + +// --------------------------------------------------------------------------- +// Some general typedefs that are defined for internal flexibility. +// +// Note that UTF16Ch is fixed at 16 bits, whereas XMLCh floats in size per +// platform, to whatever is the native wide char format there. UCS4Ch is +// fixed at 32 bits. The types we defined them in terms of are defined per +// compiler, using whatever types are the right ones for them to get these +// 16/32 bit sizes. +// --------------------------------------------------------------------------- +typedef unsigned char XMLByte; +typedef XMLUInt16 UTF16Ch; +typedef XMLUInt32 UCS4Ch; + + + +// --------------------------------------------------------------------------- +// Handle boolean. If the platform can handle booleans itself, then we +// map our boolean type to the native type. Otherwise we create a default +// one as an int and define const values for true and false. +// +// This flag will be set in the per-development environment stuff above. +// --------------------------------------------------------------------------- +#if defined(NO_NATIVE_BOOL) +typedef int bool; +const bool true = 1; +const bool false = 0; +#endif + + +// --------------------------------------------------------------------------- +// Set up the import/export keyword for our core projects. The +// PLATFORM_XXXX keywords are set in the per-development environment +// include above. +// --------------------------------------------------------------------------- +#if defined(PROJ_XMLUTIL) +#define XMLUTIL_EXPORT PLATFORM_EXPORT +#else +#define XMLUTIL_EXPORT PLATFORM_IMPORT +#endif + +#if defined(PROJ_XMLPARSER) +#define XMLPARSER_EXPORT PLATFORM_EXPORT +#else +#define XMLPARSER_EXPORT PLATFORM_IMPORT +#endif + +#if defined(PROJ_SAX4C) +#define SAX_EXPORT PLATFORM_EXPORT +#else +#define SAX_EXPORT PLATFORM_IMPORT +#endif + +#if defined(PROJ_DOM) +#define CDOM_EXPORT PLATFORM_EXPORT +#else +#define CDOM_EXPORT PLATFORM_IMPORT +#endif + +#if defined(PROJ_PARSERS) +#define PARSERS_EXPORT PLATFORM_EXPORT +#else +#define PARSERS_EXPORT PLATFORM_IMPORT +#endif + +#if defined(PROJ_VALIDATORS) +#define VALIDATORS_EXPORT PLATFORM_EXPORT +#else +#define VALIDATORS_EXPORT PLATFORM_IMPORT +#endif + +#endif diff --git a/src/util/XMLEnumerator.hpp b/src/util/XMLEnumerator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5efff07f15e5dbbbacd3007ad290e575a236fa90 --- /dev/null +++ b/src/util/XMLEnumerator.hpp @@ -0,0 +1,84 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:37 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:19 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(XMLENUMERATOR_HPP) +#define XMLENUMERATOR_HPP + +#include <util/XML4CDefs.hpp> + +template <class TElem> class XMLEnumerator +{ +public : + // ----------------------------------------------------------------------- + // XMLEnumerator interface + // ----------------------------------------------------------------------- + virtual bool hasMoreElements() const = 0; + virtual TElem& nextElement() = 0; + virtual void Reset() = 0; +}; + +#endif diff --git a/src/util/XMLExceptMsgs.hpp b/src/util/XMLExceptMsgs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4fbc61c7666e8b85566b7d77202c7c104ab42d11 --- /dev/null +++ b/src/util/XMLExceptMsgs.hpp @@ -0,0 +1,105 @@ +// This file is generated, don't edit it!! + +#if !defined(ERRHEADER_XML4CExcepts) +#define ERRHEADER_XML4CExcepts + +class XML4CExcepts +{ +public : + enum Codes + { + NoError = 0 + , E_LowBounds = 1 + , Array_BadIndex = 2 + , Array_BadNewSize = 3 + , Bitset_BadIndex = 4 + , CPtr_PointerIsZero = 5 + , Enum_NoMoreElements = 6 + , File_CouldNotOpenFile = 7 + , File_CouldNotGetCurPos = 8 + , File_CouldNotCloseFile = 9 + , File_CouldNotSeekToEnd = 10 + , File_CouldNotSeekToPos = 11 + , File_CouldNotDupHandle = 12 + , File_CouldNotReadFromFile = 13 + , File_CouldNotResetFile = 14 + , File_CouldNotGetSize = 15 + , File_CouldNotGetBasePathName = 16 + , HshTbl_ZeroModulus = 17 + , HshTbl_BadHashFromKey = 18 + , HshTbl_NoSuchKeyExists = 19 + , Mutex_CouldNotCreate = 20 + , Mutex_CouldNotClose = 21 + , Mutex_CouldNotLock = 22 + , Mutex_CouldNotUnlock = 23 + , Mutex_CouldNotDestroy = 24 + , Pool_ElemAlreadyExists = 25 + , Pool_BadHashFromKey = 26 + , Pool_InvalidId = 27 + , Pool_ZeroModulus = 28 + , Stack_BadIndex = 29 + , Stack_EmptyStack = 30 + , Str_ZeroSizedTargetBuf = 31 + , Str_UnknownRadix = 32 + , Str_TargetBufTooSmall = 33 + , Str_StartIndexPastEnd = 34 + , Strm_StdErrWriteFailure = 35 + , Strm_StdOutWriteFailure = 36 + , Strm_ConWriteFailure = 37 + , StrPool_IllegalId = 38 + , URL_MalformedURL = 39 + , URL_UnsupportedProto = 40 + , URL_UnsupportedProto1 = 41 + , URL_OnlyLocalHost = 42 + , URL_NoProtocolPresent = 43 + , URL_ExpectingTwoSlashes = 44 + , URL_IncorrectEscapedCharRef = 45 + , URL_UnterminatedHostComponent = 46 + , Vector_BadIndex = 47 + , Gen_ParseInProgress = 48 + , Gen_NoDTDValidator = 49 + , Gen_CouldNotOpenDTD = 50 + , Gen_CouldNotOpenExtEntity = 51 + , Gen_UnexpectedEOF = 52 + , AttrList_BadIndex = 53 + , ElemStack_EmptyStack = 54 + , ElemStack_BadIndex = 55 + , ElemStack_StackUnderflow = 56 + , ElemStack_NoParentPushed = 57 + , RdrMgr_ReaderIdNotFound = 58 + , Reader_BadAutoEncoding = 59 + , Reader_CantCreateCvtrFor = 60 + , Reader_CouldNotDecodeFirstLine = 61 + , Reader_EOIInMultiSeq = 62 + , Reader_EncodingNeedsCvtr = 63 + , Reader_BadUTF8Seq = 64 + , Reader_BadSurrogateInUTF8 = 65 + , Scan_CouldNotOpenSource = 66 + , Scan_UnbalancedStartEnd = 67 + , AttDef_BadAttType = 68 + , AttDef_BadDefAttType = 69 + , BufMgr_NoMoreBuffers = 70 + , BufMgr_BufferNotInPool = 71 + , XMLRec_UnknownEncoding = 72 + , Trans_CouldNotXCodeXMLData = 73 + , Trans_CouldNotCreateDefCvtr = 74 + , CM_BinOpHadUnaryType = 75 + , CM_MustBeMixedOrChildren = 76 + , CM_NoPCDATAHere = 77 + , CM_NotValidForSpecType = 78 + , CM_UnaryOpHadBinType = 79 + , CM_UnknownCMType = 80 + , CM_UnknownCMSpecType = 81 + , Val_InvalidElemId = 82 + , Val_CantHaveIntSS = 83 + , Scan_BadPScanToken = 84 + , E_HighBounds = 85 + , W_LowBounds = 86 + , W_HighBounds = 87 + , V_LowBounds = 88 + , V_HighBounds = 89 + }; + +}; +#endif + diff --git a/src/util/XMLException.cpp b/src/util/XMLException.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dbe56de88420801bdb95ff8460b8dc6d7b022fda --- /dev/null +++ b/src/util/XMLException.cpp @@ -0,0 +1,292 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:39 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:19 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Mutexes.hpp> +#include <util/PlatformUtils.hpp> +#include <util/XMLException.hpp> +#include <util/XMLMsgLoader.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> + + +// --------------------------------------------------------------------------- +// Local data +// +// gMsgMutex +// This is a mutex that is used to synchronize access to our one and +// only exception text message loader. +// +// gDefErrMsg +// For now, if we cannot load an exception message, we load up the +// default. +// --------------------------------------------------------------------------- +static XMLMutex gMsgMutex; +static const XMLCh gDefErrMsg[] = +{ + chLatin_C, chLatin_o, chLatin_u, chLatin_l, chLatin_d + , chSpace, chLatin_n, chLatin_o, chLatin_t, chSpace + , chLatin_l, chLatin_o, chLatin_a, chLatin_d, chSpace + , chLatin_m, chLatin_e, chLatin_s, chLatin_s, chLatin_a + , chLatin_g, chLatin_e, chNull +}; + + + +// --------------------------------------------------------------------------- +// Local methods +// --------------------------------------------------------------------------- + +// +// This method is a lazy evaluator for the message loader for exception +// messages. +// +// NOTE: This is only ever called with the mutex locked so we don't +// have to synchronize here!! +// +static XMLMsgLoader& gGetMsgLoader() +{ + // Fault it in on first request + static XMLMsgLoader* gLoader = 0; + if (!gLoader) + { + gLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgExceptDomain); + if (!gLoader) + XMLPlatformUtils::panic(XMLPlatformUtils::Panic_CantLoadMsgDomain); + } + + // We got it, so return it + return *gLoader; +} + + + +// --------------------------------------------------------------------------- +// XMLException: Virtual destructor +// --------------------------------------------------------------------------- +XMLException::~XMLException() +{ + delete [] fMsg; + delete [] fSrcFile; +} + + +// --------------------------------------------------------------------------- +// XMLException: Setter methods +// --------------------------------------------------------------------------- +void XMLException::setPosition(const char* const file, const unsigned int line) +{ + fSrcLine = line; + delete [] fSrcFile; + fSrcFile = XMLString::replicate(file); +} + + +// --------------------------------------------------------------------------- +// XMLException: Hidden constructors and operators +// --------------------------------------------------------------------------- +XMLException::XMLException() : + + fCode(XML4CExcepts::NoError) + , fSrcFile(0) + , fSrcLine(0) + , fMsg(0) +{ +} + + +XMLException::XMLException( const char* const srcFile + , const unsigned int srcLine) : + + fCode(XML4CExcepts::NoError) + , fSrcFile(0) + , fSrcLine(srcLine) + , fMsg(0) +{ + fSrcFile = XMLString::replicate(srcFile); +} + + +XMLException::XMLException(const XMLException& toCopy) : + + fCode(toCopy.fCode) + , fSrcFile(0) + , fSrcLine(toCopy.fSrcLine) + , fMsg(XMLString::replicate(toCopy.fMsg)) +{ + if (toCopy.fSrcFile) + fSrcFile = XMLString::replicate(toCopy.fSrcFile); +} + + +void XMLException::operator=(const XMLException& toAssign) +{ + if (this != &toAssign) + { + delete [] fSrcFile; + fSrcFile = 0; + delete [] fMsg; + fMsg = 0; + + fSrcLine = toAssign.fSrcLine; + fCode = toAssign.fCode; + + if (toAssign.fMsg) + fMsg = XMLString::replicate(toAssign.fMsg); + + if (toAssign.fSrcFile) + fSrcFile = XMLString::replicate(toAssign.fSrcFile); + } +} + + + +// --------------------------------------------------------------------------- +// XMLException: Protected methods +// --------------------------------------------------------------------------- +void XMLException::loadExceptText(const XML4CExcepts::Codes toLoad) +{ + // Store the error code + fCode = toLoad; + + // Load up the text into a local buffer + const unsigned int msgSize = 2047; + XMLCh errText[msgSize + 1]; + + // Lock the message loader mutex and load the text + { + XMLMutexLock lockInit(&gMsgMutex); + if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize)) + { + fMsg = XMLString::replicate(gDefErrMsg); + return; + } + } + + // We got the text so replicate it into the message member + fMsg = XMLString::replicate(errText); +} + + +void +XMLException::loadExceptText(const XML4CExcepts::Codes toLoad + , const XMLCh* const text1 + , const XMLCh* const text2 + , const XMLCh* const text3 + , const XMLCh* const text4) +{ + // Store the error code + fCode = toLoad; + + // Load up the text into a local buffer + const unsigned int msgSize = 4095; + XMLCh errText[msgSize + 1]; + + // Lock the message loader mutex and load the text + { + XMLMutexLock lockInit(&gMsgMutex); + if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4)) + { + fMsg = XMLString::replicate(gDefErrMsg); + return; + } + } + + // We got the text so replicate it into the message member + fMsg = XMLString::replicate(errText); +} + + +void +XMLException::loadExceptText(const XML4CExcepts::Codes toLoad + , const char* const text1 + , const char* const text2 + , const char* const text3 + , const char* const text4) +{ + // Store the error code + fCode = toLoad; + + // Load up the text into a local buffer + const unsigned int msgSize = 4095; + XMLCh errText[msgSize + 1]; + + // Lock the message loader mutex and load the text + { + XMLMutexLock lockInit(&gMsgMutex); + if (!gGetMsgLoader().loadMsg(toLoad, errText, msgSize, text1, text2, text3, text4)) + { + fMsg = XMLString::replicate(gDefErrMsg); + return; + } + } + + // We got the text so replicate it into the message member + fMsg = XMLString::replicate(errText); +} diff --git a/src/util/XMLException.hpp b/src/util/XMLException.hpp new file mode 100644 index 0000000000000000000000000000000000000000..01dbad0edd771b765a0ce36dae5664cc3379c548 --- /dev/null +++ b/src/util/XMLException.hpp @@ -0,0 +1,288 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:42 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:20 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(EXCEPTION_HPP) +#define EXCEPTION_HPP + +#include <util/XML4CDefs.hpp> +#include <util/XMLExceptMsgs.hpp> + + +// --------------------------------------------------------------------------- +// This is the base class from which all the XML parser exceptions are +// derived. The virtual interface is very simple and most of the functionality +// is in this class. +// +// Because all derivatives are EXACTLY the same except for the static +// string that is used to hold the name of the class, a macro is provided +// below via which they are all created. +// --------------------------------------------------------------------------- +class XMLUTIL_EXPORT XMLException +{ +public: + // ----------------------------------------------------------------------- + // Virtual Destructor + // ----------------------------------------------------------------------- + virtual ~XMLException(); + + + // ----------------------------------------------------------------------- + // The XML exception virtual interface + // ----------------------------------------------------------------------- + virtual const XMLCh* getType() const = 0; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + XML4CExcepts::Codes getCode() const; + const XMLCh* getMessage() const; + const char* getSrcFile() const; + unsigned int getSrcLine() const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setPosition(const char* const file, const unsigned int line); + + + // ----------------------------------------------------------------------- + // Hidden constructors and operators + // + // NOTE: Technically, these should be protected, since this is a + // base class that is never used directly. However, VC++ 6.0 will + // fail to catch via a reference to base class if the ctors are + // not public!! This seems to have been caused by the install + // of IE 5.0. + // ----------------------------------------------------------------------- + XMLException(); + XMLException(const char* const srcFile, const unsigned int srcLine); + XMLException(const XMLException& toCopy); + void operator=(const XMLException& toAssign); + + +protected : + // ----------------------------------------------------------------------- + // Protected methods + // ----------------------------------------------------------------------- + void loadExceptText + ( + const XML4CExcepts::Codes toLoad + ); + void loadExceptText + ( + const XML4CExcepts::Codes toLoad + , const XMLCh* const text1 + , const XMLCh* const text2 = 0 + , const XMLCh* const text3 = 0 + , const XMLCh* const text4 = 0 + ); + void loadExceptText + ( + const XML4CExcepts::Codes toLoad + , const char* const text1 + , const char* const text2 = 0 + , const char* const text3 = 0 + , const char* const text4 = 0 + ); + + +private : + // ----------------------------------------------------------------------- + // Data members + // + // fCode + // The error code that this exception represents. + // + // fSrcFile + // fSrcLine + // These are the file and line information from the source where the + // exception was thrown from. + // + // fMsg + // The loaded message text for this exception. + // ----------------------------------------------------------------------- + XML4CExcepts::Codes fCode; + char* fSrcFile; + unsigned int fSrcLine; + XMLCh* fMsg; +}; + +// --------------------------------------------------------------------------- +// XMLException: Getter methods +// --------------------------------------------------------------------------- +inline XML4CExcepts::Codes XMLException::getCode() const +{ + return fCode; +} + +inline const XMLCh* XMLException::getMessage() const +{ + return fMsg; +} + +inline const char* XMLException::getSrcFile() const +{ + if (!fSrcFile) + return ""; + return fSrcFile; +} + +inline unsigned int XMLException::getSrcLine() const +{ + return fSrcLine; +} + + +// --------------------------------------------------------------------------- +// This macro is used to create derived classes. They are all identical +// except the name of the exception, so it crazy to type them in over and +// over. +// --------------------------------------------------------------------------- +#define MakeXML4CException(theType, expKeyword) \ +class expKeyword theType : public XMLException \ +{ \ +public: \ + \ + theType(const char* const srcFile \ + , const unsigned int srcLine \ + , const XML4CExcepts::Codes toThrow) : \ + XMLException(srcFile, srcLine) \ + { \ + loadExceptText(toThrow); \ + } \ + \ + theType(const theType& toCopy) : \ + \ + XMLException(toCopy) \ + { \ + } \ + \ + theType(const char* const srcFile \ + , const unsigned int srcLine \ + , const XML4CExcepts::Codes toThrow \ + , const XMLCh* const text1 \ + , const XMLCh* const text2 = 0 \ + , const XMLCh* const text3 = 0 \ + , const XMLCh* const text4 = 0) : \ + XMLException(srcFile, srcLine) \ + { \ + loadExceptText(toThrow, text1, text2, text3, text4); \ + } \ + \ + theType(const char* const srcFile \ + , const unsigned int srcLine \ + , const XML4CExcepts::Codes toThrow \ + , const char* const text1 \ + , const char* const text2 = 0 \ + , const char* const text3 = 0 \ + , const char* const text4 = 0) : \ + XMLException(srcFile, srcLine) \ + { \ + loadExceptText(toThrow, text1, text2, text3, text4); \ + } \ + \ + virtual ~theType() {} \ + \ + theType& operator=(const theType& toAssign) \ + { \ + XMLException::operator=(toAssign); \ + return *this; \ + } \ + \ + virtual XMLException* duplicate() const \ + { \ + return new theType(*this); \ + } \ + \ + virtual const XMLCh* getType() const \ + { \ + return g##theType##_Name; \ + } \ + \ +private : \ + theType(); \ +}; + + + +// --------------------------------------------------------------------------- +// This macros is used to actually throw an exception. It is used in order +// to make sure that source code line/col info is stored correctly, and to +// give flexibility for other stuff in the future. +// --------------------------------------------------------------------------- +#define ThrowXML(type,code) throw type(__FILE__, __LINE__, code) + +#define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1) + +#define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2) + +#define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3) + +#define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4) + +#endif diff --git a/src/util/XMLMsgLoader.hpp b/src/util/XMLMsgLoader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..df294f9d36f062f3bc0051b0187b710aaa78886b --- /dev/null +++ b/src/util/XMLMsgLoader.hpp @@ -0,0 +1,218 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:47 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:20 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(XMLMSGLOADER_HPP) +#define XMLMSGLOADER_HPP + +#include <util/XML4CDefs.hpp> + +// +// This header defines an abstract message loading API. This is the API via +// which the parser system loads translatable text, and there can be multiple +// actual implementations of this mechanism. The API is very simple because +// there can be many kinds of underlying systems on which implementations are +// based and we don't want to get into portability trouble by being overly +// smart. +// +// Each instance of the message loader loads a file of messages, which are +// accessed by key and which are associated with a particular language. The +// actual source information may be in many forms, but by the time it is +// extracted for use it will be in Unicode format. The language is always +// the default language for the local machine. +// +// Msg loader derivatives are not required to be thread safe. The parser will +// never use a single instance in more than one thread. +// +class XMLUTIL_EXPORT XMLMsgLoader +{ +public : + // ----------------------------------------------------------------------- + // Class specific types + // + // XMLMsgId + // A simple typedef to give us flexibility about the representation + // of a message id. + // ----------------------------------------------------------------------- + typedef unsigned int XMLMsgId; + + + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + virtual ~XMLMsgLoader(); + + + // ----------------------------------------------------------------------- + // The virtual message loader API + // ----------------------------------------------------------------------- + virtual bool loadMsg + ( + const XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + ) = 0; + + virtual bool loadMsg + ( + const XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const XMLCh* const repText1 + , const XMLCh* const repText2 = 0 + , const XMLCh* const repText3 = 0 + , const XMLCh* const repText4 = 0 + ) = 0; + + virtual bool loadMsg + ( + const XMLMsgId msgToLoad + , XMLCh* const toFill + , const unsigned long maxChars + , const char* const repText1 + , const char* const repText2 = 0 + , const char* const repText3 = 0 + , const char* const repText4 = 0 + ) = 0; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + const XMLCh* getLanguageName() const; + + +protected : + // ----------------------------------------------------------------------- + // Hidden Constructors + // ----------------------------------------------------------------------- + XMLMsgLoader(); + + + // ----------------------------------------------------------------------- + // Protected helper methods + // ----------------------------------------------------------------------- + void setLanguageName(XMLCh* const nameToAdopt); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XMLMsgLoader(const XMLMsgLoader&); + void operator=(const XMLMsgLoader&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fLanguage + // This is the language that is represented by this instance of the + // loader. The derived class must pass this through for storage and + // we adopt it and delete it when we go. + // ----------------------------------------------------------------------- + XMLCh* fLanguage; +}; + + +// --------------------------------------------------------------------------- +// XMLMsgLoader: Public Constructors and Destructor +// --------------------------------------------------------------------------- +inline XMLMsgLoader::~XMLMsgLoader() +{ + delete [] fLanguage; +} + + +// --------------------------------------------------------------------------- +// XMLMsgLoader: Hidden Constructors +// --------------------------------------------------------------------------- +inline XMLMsgLoader::XMLMsgLoader() : + + fLanguage(0) +{ +} + + +// --------------------------------------------------------------------------- +// XMLMsgLoader: Getter methods +// --------------------------------------------------------------------------- +inline const XMLCh* XMLMsgLoader::getLanguageName() const +{ + return fLanguage; +} + + +// --------------------------------------------------------------------------- +// XMLMsgLoader: Protected helper methods +// --------------------------------------------------------------------------- +inline void XMLMsgLoader::setLanguageName(XMLCh* const nameToAdopt) +{ + delete [] fLanguage; + fLanguage = nameToAdopt; +} + +#endif diff --git a/src/util/XMLNetAccessor.hpp b/src/util/XMLNetAccessor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8159e22cacaf66ac3ffd7ae74044a9e585d44d37 --- /dev/null +++ b/src/util/XMLNetAccessor.hpp @@ -0,0 +1,126 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:50 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:20 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(XMLNETACCESSOR_HPP) +#define XMLNETACCESSOR_HPP + +#include <util/XML4CDefs.hpp> + +class BinInputStream; + + +// +// This class is an abstract interface via which the URL class accesses +// net access services. When any source URL is not in effect a local file +// path, then the URL class is used to look at it. Then the URL class can +// be asked to make a binary input stream via which the referenced resource +// can be read in. +// +// The URL class will use an object derived from this class to create a +// binary stream for the URL to return. The object it uses is provided by +// the platform utils, and is actually provided by the per-platform init +// code so each platform can decide what actual implementation it wants to +// use. +// +class XMLUTIL_EXPORT XMLNetAccessor +{ +public : + // ----------------------------------------------------------------------- + // Virtual destructor + // ----------------------------------------------------------------------- + virtual ~XMLNetAccessor() + { + } + + + // ----------------------------------------------------------------------- + // The virtual net accessor interface + // ----------------------------------------------------------------------- + virtual BinInputStream* makeNew + ( + const XMLCh* const urlSource + , XML4CExcepts::Codes& failReason + ) = 0; + + +protected : + // ----------------------------------------------------------------------- + // Hidden constructors + // ----------------------------------------------------------------------- + XMLNetAccessor() + { + } + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XMLNetAccessor(const XMLNetAccessor&); + void operator=(const XMLNetAccessor&); +}; + +#endif diff --git a/src/util/XMLString.cpp b/src/util/XMLString.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ddfda8280bcdab55340432f0e723d4c8af44a99d --- /dev/null +++ b/src/util/XMLString.cpp @@ -0,0 +1,988 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:51 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:20 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <memory.h> +#include <string.h> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/IllegalArgumentException.hpp> +#include <util/Janitor.hpp> +#include <util/PlatformUtils.hpp> +#include <util/StdOut.hpp> +#include <util/RuntimeException.hpp> +#include <util/TransService.hpp> +#include <util/TranscodingException.hpp> +#include <util/ValueArrayOf.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> + + +// --------------------------------------------------------------------------- +// Local static data +// +// gConverter +// This is initialized when the user calls the platform init method, +// which calls our init method. This is the converter used for default +// conversion to/from the local code page. +// --------------------------------------------------------------------------- +static XMLTranscoder* gTranscoder = 0; +static XMLCh gNullStr[] = +{ + chOpenCurly, chLatin_n, chLatin_u, chLatin_l, chLatin_l, chCloseCurly, chNull +}; + + +// --------------------------------------------------------------------------- +// XMLString: Public static methods +// --------------------------------------------------------------------------- +void XMLString::binToText( const unsigned long toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + static const char digitList[16] = + { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' + , 'A', 'B', 'C', 'D', 'E', 'F' + }; + + if (!maxChars) + ThrowXML(IllegalArgumentException, XML4CExcepts::Str_ZeroSizedTargetBuf); + + // Handle special case + if (!toFormat) + { + toFill[0] = '0'; + toFill[1] = 0; + return; + } + + // This is used to fill the temp buffer + unsigned int tmpIndex = 0; + + // A copy of the conversion value that we can modify + unsigned int tmpVal = toFormat; + + // + // Convert into a temp buffer that we know is large enough. This avoids + // having to check for overflow in the inner loops, and we have to flip + // the resulting XMLString anyway. + // + char tmpBuf[128]; + + // + // For each radix, do the optimal thing. For bin and hex, we can special + // case them and do shift and mask oriented stuff. For oct and decimal + // there isn't much to do but bull through it with divides. + // + if (radix == 2) + { + while (tmpVal) + { + if (tmpVal & 0x1UL) + tmpBuf[tmpIndex++] = '1'; + else + tmpBuf[tmpIndex++] = '0'; + tmpVal >>= 1; + } + } + else if (radix == 16) + { + while (tmpVal) + { + const unsigned int charInd = (tmpVal & 0xFUL); + tmpBuf[tmpIndex++] = digitList[charInd]; + tmpVal >>= 4; + } + } + else if ((radix == 8) || (radix == 10)) + { + while (tmpVal) + { + const unsigned int charInd = (tmpVal % radix); + tmpBuf[tmpIndex++] = digitList[charInd]; + tmpVal /= radix; + } + } + else + { + ThrowXML(RuntimeException, XML4CExcepts::Str_UnknownRadix); + } + + // See if have enough room in the caller's buffer + if (tmpIndex > maxChars) + ThrowXML(IllegalArgumentException, XML4CExcepts::Str_TargetBufTooSmall); + + // Reverse the tmp buffer into the caller's buffer + unsigned int outIndex = 0; + for (; tmpIndex > 0; tmpIndex--) + toFill[outIndex++] = tmpBuf[tmpIndex-1]; + + // And cap off the caller's buffer + toFill[outIndex] = char(0); +} + +void XMLString::binToText( const unsigned int toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + // Just call the unsigned long version + binToText((unsigned long)toFormat, toFill, maxChars, radix); +} + +void XMLString::binToText( const long toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + // + // If its negative, then put a negative sign into the output and flip + // the sign of the local temp value. + // + unsigned int startInd = 0; + unsigned long actualVal; + if (toFormat < 0) + { + toFill[0] = '-'; + startInd++; + actualVal = (unsigned long)(toFormat * -1); + } + else + { + actualVal = (unsigned long)(toFormat); + } + + // And now call the unsigned long version + binToText(actualVal, &toFill[startInd], maxChars, radix); +} + +void XMLString::binToText( const int toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + // + // If its negative, then put a negative sign into the output and flip + // the sign of the local temp value. + // + unsigned int startInd = 0; + unsigned long actualVal; + if (toFormat < 0) + { + toFill[0] = '-'; + startInd++; + actualVal = (unsigned long)(toFormat * -1); + } + else + { + actualVal = (unsigned long)(toFormat); + } + + // And now call the unsigned long version + binToText(actualVal, &toFill[startInd], maxChars, radix); +} + + +void XMLString::catString(char* const target, const char* const src) +{ + strcat(target, src); +} + + +int XMLString::compareIString(const char* const str1, const char* const str2) +{ + return stricmp(str1, str2); +} + + +int XMLString::compareNString( const char* const str1 + , const char* const str2 + , const unsigned int count) +{ + // Watch for pathological secenario + if (!count) + return 0; + + return strncmp(str1, str2, count); +} + + +int XMLString::compareNIString( const char* const str1 + , const char* const str2 + , const unsigned int count) +{ + if (!count) + return 0; + + return strnicmp(str1, str2, count); +} + + +int XMLString::compareString( const char* const str1 + , const char* const str2) +{ + return strcmp(str1, str2); +} + + +void XMLString::copyString( char* const target + , const char* const src) +{ + strcpy(target, src); +} + + +unsigned int XMLString::hash( const char* const tohash + , const unsigned int hashModulus) +{ + unsigned int hashVal = 0; + const char* curCh = tohash; + while (*curCh) + { + unsigned int top = hashVal >> 24; + hashVal += (hashVal * 37) + top + (unsigned int)(*curCh); + curCh++; + } + + // Divide by modulus + return hashVal % hashModulus; +} + + +int XMLString::indexOf(const char* const toSearch, const char ch) +{ + const unsigned int len = strlen(toSearch); + for (unsigned int i = 0; i < len; i++) + { + if (toSearch[i] == ch) + return i; + } + return -1; +} + + +int XMLString::lastIndexOf(const char* const toSearch, const char ch) +{ + const int len = strlen(toSearch); + for (int i = len-1; i >= 0; i--) + { + if (toSearch[i] == ch) + return i; + } + return -1; +} + +int XMLString::lastIndexOf( const char* const toSearch + , const char ch + , const unsigned int fromIndex) +{ + const int len = strlen(toSearch); + + // Make sure the start index is within the XMLString bounds + if ((int)fromIndex > len-1) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Str_StartIndexPastEnd); + + for (int i = (int)fromIndex; i >= 0; i--) + { + if (toSearch[i] == ch) + return i; + } + return -1; +} + + +unsigned int XMLString::replaceTokens( XMLCh* const errText + , const unsigned int maxChars + , const XMLCh* const text1 + , const XMLCh* const text2 + , const XMLCh* const text3 + , const XMLCh* const text4) +{ + // + // We have to build the string back into the source string, so allocate + // a temp string and copy the orignal text to it. We'll then treat the + // incoming buffer as a target buffer. Put a janitor on it to make sure + // it gets cleaned up. + // + XMLCh* orgText = replicate(errText); + ArrayJanitor<XMLCh> janText(orgText); + + XMLCh* pszSrc = orgText; + unsigned int curOutInd = 0; + + while (*pszSrc && (curOutInd < maxChars)) + { + // + // Loop until we see a { character. Until we do, just copy chars + // from src to target, being sure not to overrun the output buffer. + // + while ((*pszSrc != chOpenCurly) && (curOutInd < maxChars)) + { + if (!*pszSrc) + break; + errText[curOutInd++] = *pszSrc++; + } + + // If we did not find a curly, then we are done + if (*pszSrc != chOpenCurly) + break; + + // + // Probe this one to see if it matches our pattern of {x}. If not + // then copy over those chars and go back to the first loop. + // + if ((*(pszSrc+1) >= chDigit_0) + && (*(pszSrc+1) <= chDigit_3) + && (*(pszSrc+2) == chCloseCurly)) + { + // + // Its one of our guys, so move the source pointer up past the + // token we are replacing. First though get out the token number + // character. + // + XMLCh tokCh = *(pszSrc+1); + pszSrc += 3; + + // Now copy over the replacement text + const XMLCh* repText = 0; + if (tokCh == chDigit_0) + repText = text1; + else if (tokCh == chDigit_1) + repText = text2; + else if (tokCh == chDigit_2) + repText = text3; + else if (tokCh == chDigit_3) + repText = text4; + + // If this one is null, copy over a null string + if (!repText) + repText = gNullStr; + + while (*repText && (curOutInd < maxChars)) + errText[curOutInd++] = *repText++; + } + else + { + // Escape the curly brace character and continue + errText[curOutInd++] = *pszSrc++; + } + } + + // Copy over a null terminator + errText[curOutInd] = 0; + + // And return the count of chars we output + return curOutInd; +} + + +char* XMLString::replicate(const char* const toRep) +{ + // If a null string, return a null string + if (!toRep) + return 0; + + // + // Get the len of the source and allocate a new buffer. Make sure to + // account for the nul terminator. + // + const unsigned int srcLen = strlen(toRep); + char* ret = new char[srcLen+1]; + + // Copy over the text, adjusting for the size of a char + memcpy(ret, toRep, (srcLen+1) * sizeof(char)); + return ret; +} + + +bool XMLString::startsWith(const char* const toTest, const char* const prefix) +{ + return (strncmp(toTest, prefix, strlen(prefix)) == 0); +} + + +bool XMLString::startsWithI(const char* const toTest + , const char* const prefix) +{ + return (strnicmp(toTest, prefix, strlen(prefix)) == 0); +} + + +unsigned int XMLString::stringLen(const char* const src) +{ + return strlen(src); +} + + +char* XMLString::transcode(const XMLCh* const toTranscode) +{ + return gTranscoder->transcode(toTranscode); +} + +bool XMLString::transcode( const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxChars) +{ + if (!gTranscoder->transcode(toTranscode, toFill, maxChars)) + return false; + return true; +} + +XMLCh* XMLString::transcode(const char* const toTranscode) +{ + return gTranscoder->transcode(toTranscode); +} + +bool XMLString::transcode( const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars) +{ + if (!gTranscoder->transcode(toTranscode, toFill, maxChars)) + return false; + return true; +} + + +void XMLString::trim(char* const toTrim) +{ + const unsigned int len = strlen(toTrim); + + unsigned int skip, scrape; + for (skip = 0; skip < len; skip++) + { + if (toTrim[skip] > ' ') + break; + } + + for (scrape = len; scrape > skip; scrape--) + { + if (toTrim[scrape - 1] > ' ') + break; + } + + // Cap off at the scrap point + if (scrape) + toTrim[scrape] = 0; + + if (skip) + { + // Copy the chars down + unsigned int index = 0; + while (toTrim[skip]) + toTrim[index++] = toTrim[skip++]; + } +} + + + +// --------------------------------------------------------------------------- +// Unicode versions of most of the string methods +// --------------------------------------------------------------------------- +void XMLString::binToText( const unsigned long toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + static const XMLCh digitList[16] = + { + chDigit_0, chDigit_1, chDigit_2, chDigit_3, chDigit_4, chDigit_5 + , chDigit_6, chDigit_7, chDigit_8, chDigit_9, chLatin_A, chLatin_B + , chLatin_C, chLatin_D, chLatin_e, chLatin_F + }; + + if (!maxChars) + ThrowXML(IllegalArgumentException, XML4CExcepts::Str_ZeroSizedTargetBuf); + + // Handle special case + if (!toFormat) + { + toFill[0] = chDigit_0; + toFill[1] = chNull; + return; + } + + // This is used to fill the temp buffer + unsigned int tmpIndex = 0; + + // A copy of the conversion value that we can modify + unsigned int tmpVal = toFormat; + + // + // Convert into a temp buffer that we know is large enough. This avoids + // having to check for overflow in the inner loops, and we have to flip + // the resulting sring anyway. + // + XMLCh tmpBuf[128]; + + // + // For each radix, do the optimal thing. For bin and hex, we can special + // case them and do shift and mask oriented stuff. For oct and decimal + // there isn't much to do but bull through it with divides. + // + if (radix == 2) + { + while (tmpVal) + { + if (tmpVal & 0x1UL) + tmpBuf[tmpIndex++] = chDigit_1; + else + tmpBuf[tmpIndex++] = chDigit_0; + tmpVal >>= 1; + } + } + else if (radix == 16) + { + while (tmpVal) + { + const unsigned int charInd = (tmpVal & 0xFUL); + tmpBuf[tmpIndex++] = digitList[charInd]; + tmpVal >>= 4; + } + } + else if ((radix == 8) || (radix == 10)) + { + while (tmpVal) + { + const unsigned int charInd = (tmpVal % radix); + tmpBuf[tmpIndex++] = digitList[charInd]; + tmpVal /= radix; + } + } + else + { + ThrowXML(RuntimeException, XML4CExcepts::Str_UnknownRadix); + } + + // See if have enough room in the caller's buffer + if (tmpIndex > maxChars) + ThrowXML(IllegalArgumentException, XML4CExcepts::Str_TargetBufTooSmall); + + // Reverse the tmp buffer into the caller's buffer + unsigned int outIndex = 0; + for (; tmpIndex > 0; tmpIndex--) + toFill[outIndex++] = tmpBuf[tmpIndex-1]; + + // And cap off the caller's buffer + toFill[outIndex] = chNull; +} + +void XMLString::binToText( const unsigned int toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + // Just call the unsigned long version + binToText((unsigned long)toFormat, toFill, maxChars, radix); +} + +void XMLString::binToText( const long toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + // + // If its negative, then put a negative sign into the output and flip + // the sign of the local temp value. + // + unsigned int startInd = 0; + unsigned long actualVal; + if (toFormat < 0) + { + toFill[0] = chDash; + startInd++; + actualVal = (unsigned long)(toFormat * -1); + } + else + { + actualVal = (unsigned long)(toFormat); + } + + // And now call the unsigned long version + binToText(actualVal, &toFill[startInd], maxChars, radix); +} + +void XMLString::binToText( const int toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix) +{ + // + // If its negative, then put a negative sign into the output and flip + // the sign of the local temp value. + // + unsigned int startInd = 0; + unsigned long actualVal; + if (toFormat < 0) + { + toFill[0] = chDash; + startInd++; + actualVal = (unsigned long)(toFormat * -1); + } + else + { + actualVal = (unsigned long)(toFormat); + } + + // And now call the unsigned long version + binToText(actualVal, &toFill[startInd], maxChars, radix); +} + + +void XMLString::catString(XMLCh* const target, const XMLCh* const src) +{ + // Get the starting point for the cat on the target XMLString + unsigned int index = stringLen(target); + + // While the source is not zero, add them to target and bump + const XMLCh* pszTmp = src; + while (*pszTmp) + target[index++] = *pszTmp++; + + // Cap off the target where we ended + target[index] = chNull; +} + + +int XMLString::compareIString( const XMLCh* const str1 + , const XMLCh* const str2) +{ + return XMLPlatformUtils::fgTransService->compareIString(str1, str2); +} + + +int XMLString::compareNString( const XMLCh* const str1 + , const XMLCh* const str2 + , const unsigned int maxChars) +{ + const XMLCh* psz1 = str1; + const XMLCh* psz2 = str2; + + unsigned int curCount = 0; + while (true) + { + // If an inequality, then return difference + if (*psz1 != *psz2) + return int(*psz1) - int(*psz2); + + // If either ended, then both ended, so equal + if (!*psz1 || !*psz2) + break; + + // Move upwards to next chars + psz1++; + psz2++; + + // + // Bump the count of chars done. If it equals the max then we are + // equal for the requested count, so break out and return equal. + // + curCount++; + if (curCount == maxChars) + break; + } + return 0; +} + + +int XMLString::compareNIString( const XMLCh* const str1 + , const XMLCh* const str2 + , const unsigned int maxChars) +{ + return XMLPlatformUtils::fgTransService->compareNIString(str1, str2, maxChars); +} + + +int XMLString::compareString( const XMLCh* const str1 + , const XMLCh* const str2) +{ + const XMLCh* psz1 = str1; + const XMLCh* psz2 = str2; + while (true) + { + // If an inequality, then return the difference + if (*psz1 != *psz2) + return int(*psz1) - int(*psz2); + + // If either has ended, then they both ended, so equal + if (!*psz1 || !*psz2) + break; + + // Move upwards for the next round + psz1++; + psz2++; + } + return 0; +} + + +void XMLString::copyString(XMLCh* const target, const XMLCh* const src) +{ + if (!src) + { + *target = 0; + return; + } + + XMLCh* pszOut = target; + const XMLCh* pszIn = src; + while (*pszIn) + *pszOut++ = *pszIn++; + + // Capp off the target where we ended + *pszOut = 0; +} + + +unsigned int XMLString::hash( const XMLCh* const tohash + , const unsigned int hashModulus) +{ + unsigned int hashVal = 0; + const XMLCh* curCh = tohash; + while (*curCh) + { + unsigned int top = hashVal >> 24; + hashVal += (hashVal * 37) + top + (unsigned int)(*curCh); + curCh++; + } + + // Divide by modulus + return hashVal % hashModulus; +} + + +unsigned int XMLString::hashN( const XMLCh* const tohash + , const unsigned int n + , const unsigned int hashModulus) +{ + unsigned int hashVal = 0; + const XMLCh* curCh = tohash; + int i = n; + while (i--) + { + unsigned int top = hashVal >> 24; + hashVal += (hashVal * 37) + top + (unsigned int)(*curCh); + curCh++; + } + + // Divide by modulus + return hashVal % hashModulus; +} + + +int XMLString::indexOf(const XMLCh* const toSearch, const XMLCh ch) +{ + const unsigned int len = stringLen(toSearch); + for (unsigned int i = 0; i < len; i++) + { + if (toSearch[i] == ch) + return i; + } + return -1; +} + + +int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch) +{ + const int len = stringLen(toSearch); + for (int i = len-1; i >= 0; i--) + { + if (toSearch[i] == ch) + return i; + } + return -1; +} + +int XMLString::lastIndexOf( const XMLCh* const toSearch + , const XMLCh ch + , const unsigned int fromIndex) +{ + const int len = stringLen(toSearch); + if ((int)fromIndex > len-1) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Str_StartIndexPastEnd); + + for (int i = (int)fromIndex; i >= 0; i--) + { + if (toSearch[i] == ch) + return i; + } + return -1; +} + + +XMLCh* +XMLString::makeUName(const XMLCh* const pszURI, const XMLCh* const pszName) +{ + // + // If there is a URI, then format out the full name in the {uri}name + // form. Otherwise, just set it to the same thing as the base name. + // + XMLCh* pszRet = 0; + const unsigned int uriLen = stringLen(pszURI); + if (uriLen) + { + pszRet = new XMLCh[uriLen + stringLen(pszName) + 3]; + + XMLCh szTmp[2]; + szTmp[1] = 0; + + szTmp[0] = chOpenCurly; + copyString(pszRet, szTmp); + catString(pszRet, pszURI); + szTmp[0] = chCloseCurly; + catString(pszRet, szTmp); + catString(pszRet, pszName); + } + else + { + pszRet = replicate(pszName); + } + return pszRet; +} + + +XMLCh* XMLString::replicate(const XMLCh* const toRep) +{ + // If a null string, return a null string + if (!toRep) + return 0; + + XMLCh* ret = new XMLCh[stringLen(toRep) + 1]; + copyString(ret, toRep); + return ret; +} + + +bool XMLString::startsWith( const XMLCh* const toTest + , const XMLCh* const prefix) +{ + return (compareNString(toTest, prefix, stringLen(prefix)) == 0); +} + + +bool XMLString::startsWithI(const XMLCh* const toTest + , const XMLCh* const prefix) +{ + return (compareNIString(toTest, prefix, stringLen(prefix)) == 0); +} + + +unsigned int XMLString::stringLen(const XMLCh* const src) +{ + if (!src) + return 0; + + unsigned int len = 0; + const XMLCh* pszTmp = src; + while (*pszTmp++) + len++; + return len; +} + + +void XMLString::trim(XMLCh* const toTrim) +{ + const unsigned int len = stringLen(toTrim); + + unsigned int skip, scrape; + for (skip = 0; skip < len; skip++) + { + if (XMLPlatformUtils::fgTransService->isSpace(toTrim[skip])) + break; + } + + for (scrape = len; scrape > skip; scrape--) + { + if (XMLPlatformUtils::fgTransService->isSpace(toTrim[scrape - 1])) + break; + } + + // Cap off at the scrap point + if (scrape) + toTrim[scrape] = 0; + + if (skip) + { + // Copy the chars down + unsigned int index = 0; + while (toTrim[skip]) + toTrim[index++] = toTrim[skip++]; + } +} + + + +// --------------------------------------------------------------------------- +// XMLString: Private static methods +// --------------------------------------------------------------------------- +void XMLString::initString(XMLTranscoder* const defToUse) +{ + // Store away the default transcoder that we are to use + gTranscoder = defToUse; +} diff --git a/src/util/XMLString.hpp b/src/util/XMLString.hpp new file mode 100644 index 0000000000000000000000000000000000000000..90803f592c9c8d0872991ebf5f59c1271ffcad68 --- /dev/null +++ b/src/util/XMLString.hpp @@ -0,0 +1,363 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:52 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:21 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(XMLSTRING_HPP) +#define XMLSTRING_HPP + +#include <util/XML4CDefs.hpp> + +class XMLTranscoder; + +class XMLUTIL_EXPORT XMLString +{ +public: + // ----------------------------------------------------------------------- + // Static methods for native character mode string manipulation + // ----------------------------------------------------------------------- + static void binToText + ( + const unsigned int toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void binToText + ( + const unsigned long toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void binToText + ( + const long toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void binToText + ( + const int toFormat + , char* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void catString + ( + char* const target + , const char* const src + ); + + static int compareIString + ( + const char* const str1 + , const char* const str2 + ); + + static int compareNString + ( + const char* const str1 + , const char* const str2 + , const unsigned int count + ); + + static int compareNIString + ( + const char* const str1 + , const char* const str2 + , const unsigned int count + ); + + static int compareString + ( + const char* const str1 + , const char* const str2 + ); + + static void copyString + ( + char* const target + , const char* const src + ); + + static unsigned int hash + ( + const char* const tohash + , const unsigned int hashModulus + ); + + static int indexOf(const char* const toSearch, const char ch); + + static int lastIndexOf(const char* const toSearch, const char ch); + + static int lastIndexOf + ( + const char* const toSearch + , const char chToFind + , const unsigned int fromIndex + ); + + static char* replicate(const char* const toRep); + + static bool startsWith + ( + const char* const toTest + , const char* const prefix + ); + + static unsigned int stringLen(const char* const src); + + static bool startsWithI + ( + const char* const toTest + , const char* const prefix + ); + + static char* transcode + ( + const XMLCh* const toTranscode + ); + + static bool transcode + ( + const XMLCh* const toTranscode + , char* const toFill + , const unsigned int maxChars + ); + + static XMLCh* transcode + ( + const char* const toTranscode + ); + + static bool transcode + ( + const char* const toTranscode + , XMLCh* const toFill + , const unsigned int maxChars + ); + + static void trim(char* const toTrim); + + + // + // XMLCh versions of everything + // + static void binToText + ( + const unsigned int toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void binToText + ( + const unsigned long toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void binToText + ( + const long toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void binToText + ( + const int toFormat + , XMLCh* const toFill + , const unsigned int maxChars + , const unsigned int radix + ); + + static void catString + ( + XMLCh* const target + , const XMLCh* const src + ); + + static int compareIString + ( + const XMLCh* const str1 + , const XMLCh* const str2 + ); + + static int compareNString + ( + const XMLCh* const str1 + , const XMLCh* const str2 + , const unsigned int count + ); + + static int compareNIString + ( + const XMLCh* const str1 + , const XMLCh* const str2 + , const unsigned int count + ); + + static int compareString + ( + const XMLCh* const str1 + , const XMLCh* const str2 + ); + + static void copyString + ( + XMLCh* const target + , const XMLCh* const src + ); + + static unsigned int hash + ( + const XMLCh* const toHash + , const unsigned int hashModulus + ); + + static unsigned int hashN + ( + const XMLCh* const toHash + , const unsigned int numChars + , const unsigned int hashModulus + ); + + static int indexOf(const XMLCh* const toSearch, const XMLCh ch); + + static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch); + + static int lastIndexOf + ( + const XMLCh* const toSearch + , const XMLCh ch + , const unsigned int fromIndex + ); + + static XMLCh* makeUName + ( + const XMLCh* const pszURI + , const XMLCh* const pszName + ); + + static unsigned int replaceTokens + ( + XMLCh* const errText + , const unsigned int maxChars + , const XMLCh* const text1 + , const XMLCh* const text2 + , const XMLCh* const text3 + , const XMLCh* const text4 + ); + + static XMLCh* replicate(const XMLCh* const toRep); + + static bool startsWith + ( + const XMLCh* const toTest + , const XMLCh* const prefix + ); + + static bool startsWithI + ( + const XMLCh* const toTest + , const XMLCh* const prefix + ); + + static unsigned int stringLen(const XMLCh* const src); + + static void trim(XMLCh* const toTrim); + + +protected : + // ----------------------------------------------------------------------- + // Declare our friends + // ----------------------------------------------------------------------- + friend class XMLPlatformUtils; + + +private : + // ----------------------------------------------------------------------- + // Unimplemented Constructors and Destructor + // ----------------------------------------------------------------------- + XMLString(); + ~XMLString(); + + + // ----------------------------------------------------------------------- + // Initialization, called from PlatformInit class + // ----------------------------------------------------------------------- + static void initString(XMLTranscoder* const defToUse); +}; + +#endif diff --git a/src/util/XMLUni.cpp b/src/util/XMLUni.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5336fc96754e4fa4474d4f98b957d7e9d8119111 --- /dev/null +++ b/src/util/XMLUni.cpp @@ -0,0 +1,457 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:54 twl + * Initial revision + * + * Revision 1.5 1999/11/08 20:45:21 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/XMLUni.hpp> + + +// --------------------------------------------------------------------------- +// XMLUni: Static data +// --------------------------------------------------------------------------- +const XMLCh XMLUni::fgAnyString[] = +{ + chLatin_A, chLatin_N, chLatin_Y, chNull +}; + +const XMLCh XMLUni::fgAttListString[] = +{ + chLatin_A, chLatin_T, chLatin_T, chLatin_L, chLatin_I, chLatin_S, chLatin_T, chNull +}; + +const XMLCh XMLUni::fgCommentString[] = +{ + chOpenAngle, chBang, chDash, chDash, chNull +}; + +const XMLCh XMLUni::fgCDATAString[] = +{ + chLatin_C, chLatin_D, chLatin_A, chLatin_T, chLatin_A, chNull +}; + +const XMLCh XMLUni::fgDefaultEBCDICEncodingString[] = +{ + chLatin_e, chLatin_b, chLatin_c, chLatin_d, chLatin_i, chLatin_c, chDash, chLatin_c, chLatin_p, chDash, chLatin_u, chLatin_s, chNull +}; + +const XMLCh XMLUni::fgDefaultString[] = +{ + chPound, chLatin_D, chLatin_E, chLatin_F, chLatin_A, chLatin_U, chLatin_L, chLatin_T, chNull +}; + +const XMLCh XMLUni::fgDocTypeString[] = +{ + chOpenAngle, chBang, chLatin_D, chLatin_O, chLatin_C, chLatin_T, chLatin_Y, chLatin_P, chLatin_E, chNull +}; + +const XMLCh XMLUni::fgEBCDICEncodingString[] = +{ + chLatin_E, chLatin_B, chLatin_C, chLatin_D, chLatin_I, chLatin_C, chNull +}; + +const XMLCh XMLUni::fgElemString[] = +{ + chLatin_E, chLatin_L, chLatin_E, chLatin_M, chLatin_E, chLatin_N, chLatin_T, chNull +}; + +const XMLCh XMLUni::fgEmptyString[] = +{ + chLatin_E, chLatin_M, chLatin_P, chLatin_T, chLatin_Y, chNull +}; + +const XMLCh XMLUni::fgEncodingString[] = +{ + chLatin_e, chLatin_n, chLatin_c, chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chNull +}; + +const XMLCh XMLUni::fgEntitString[] = +{ + chLatin_E, chLatin_N, chLatin_T, chLatin_I, chLatin_T, chNull +}; + +const XMLCh XMLUni::fgEntityString[] = +{ + chLatin_E, chLatin_N, chLatin_T, chLatin_I, chLatin_T, chLatin_Y, chNull +}; + +const XMLCh XMLUni::fgEntitiesString[] = +{ + chLatin_E, chLatin_N, chLatin_T, chLatin_I, chLatin_T, chLatin_I, chLatin_E, chLatin_S, chNull +}; + +const XMLCh XMLUni::fgEnumerationString[] = +{ + chLatin_E, chLatin_N, chLatin_U, chLatin_M, chLatin_E, chLatin_R, chLatin_A, chLatin_T, chLatin_I, chLatin_O, chLatin_N, chNull +}; + +const XMLCh XMLUni::fgExceptDomain[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c + , chLatin_h, chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g + , chForwardSlash, chLatin_x, chLatin_m, chLatin_l, chForwardSlash + , chLatin_m, chLatin_e, chLatin_s, chLatin_s, chLatin_a, chLatin_g + , chLatin_e, chLatin_s, chForwardSlash, chLatin_X, chLatin_M, chLatin_L + , chDigit_4, chLatin_C, chLatin_E, chLatin_r, chLatin_r, chLatin_o + , chLatin_r, chLatin_s, chNull +}; + +const XMLCh XMLUni::fgFixedString[] = +{ + chPound, chLatin_F, chLatin_I, chLatin_X, chLatin_E, chLatin_D, chNull +}; + +const XMLCh XMLUni::fgGlobalNSURIName[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c + , chLatin_h, chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g + , chForwardSlash, chLatin_x, chLatin_m, chLatin_l, chForwardSlash + , chLatin_G, chLatin_l, chLatin_o, chLatin_b, chLatin_a, chLatin_l + , chLatin_N, chLatin_S, chNull +}; + +const XMLCh XMLUni::fgIESString[] = +{ + chLatin_I, chLatin_E, chLatin_S, chNull +}; + +const XMLCh XMLUni::fgIDString[] = +{ + chLatin_I, chLatin_D, chNull +}; + +const XMLCh XMLUni::fgIDRefString[] = +{ + chLatin_I, chLatin_D, chLatin_R, chLatin_E, chLatin_F, chNull +}; + +const XMLCh XMLUni::fgIDRefsString[] = +{ + chLatin_I, chLatin_D, chLatin_R, chLatin_E, chLatin_F, chLatin_S, chNull +}; + +const XMLCh XMLUni::fgImpliedString[] = +{ + chPound, chLatin_I, chLatin_M, chLatin_P, chLatin_L, chLatin_I, chLatin_E, chLatin_D, chNull +}; + +const XMLCh XMLUni::fgIgnoreString[] = +{ + chLatin_I, chLatin_G, chLatin_N, chLatin_O, chLatin_R, chLatin_E, chNull +}; + +const XMLCh XMLUni::fgIncludeString[] = +{ + chLatin_I, chLatin_N, chLatin_C, chLatin_L, chLatin_U, chLatin_D, chLatin_E, chNull +}; + +const XMLCh XMLUni::fgNoString[] = +{ + chLatin_n, chLatin_o, chNull +}; + +const XMLCh XMLUni::fgNotationString[] = +{ + chLatin_N, chLatin_O, chLatin_T, chLatin_A, chLatin_T, chLatin_I, chLatin_O, chLatin_N, chNull +}; + +const XMLCh XMLUni::fgNDATAString[] = +{ + chLatin_N, chLatin_D, chLatin_A, chLatin_T, chLatin_A, chNull +}; + +const XMLCh XMLUni::fgNmTokenString[] = +{ + chLatin_N, chLatin_M, chLatin_T, chLatin_O, chLatin_K, chLatin_E, chLatin_N, chNull +}; + +const XMLCh XMLUni::fgNmTokensString[] = +{ + chLatin_N, chLatin_M, chLatin_T, chLatin_O, chLatin_K, chLatin_E, chLatin_N, chLatin_S, chNull +}; + +const XMLCh XMLUni::fgPCDATAString[] = +{ + chPound, chLatin_P, chLatin_C, chLatin_D, chLatin_A, chLatin_T, chLatin_A, chNull +}; + +const XMLCh XMLUni::fgPIString[] = +{ + chOpenAngle, chQuestion, chNull +}; + +const XMLCh XMLUni::fgPubIDString[] = +{ + chLatin_P, chLatin_U, chLatin_B, chLatin_L, chLatin_I, chLatin_C, chNull +}; + +const XMLCh XMLUni::fgRefString[] = +{ + chLatin_R, chLatin_E, chLatin_F, chNull +}; + +const XMLCh XMLUni::fgRequiredString[] = +{ + chPound, chLatin_R, chLatin_E, chLatin_Q, chLatin_U, chLatin_I, chLatin_R, chLatin_E, chLatin_D, chNull +}; + +const XMLCh XMLUni::fgStandaloneString[] = +{ + chLatin_s, chLatin_t, chLatin_a, chLatin_n, chLatin_d, chLatin_a, chLatin_l, chLatin_o, chLatin_n, chLatin_e, chNull +}; + +const XMLCh XMLUni::fgSupportedVersion[] = +{ + chDigit_1, chPeriod, chDigit_0, chNull +}; + +const XMLCh XMLUni::fgSysIDString[] = +{ + chLatin_S, chLatin_Y, chLatin_S, chLatin_T, chLatin_E, chLatin_M, chNull +}; + +const XMLCh XMLUni::fgUnknownURIName[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c + , chLatin_h, chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g + , chForwardSlash, chLatin_x, chLatin_m, chLatin_l, chForwardSlash + , chLatin_U, chLatin_k, chLatin_n, chLatin_o, chLatin_w, chLatin_n + , chLatin_N, chLatin_S, chNull +}; + +const XMLCh XMLUni::fgUCS4EncodingString[] = +{ + chLatin_U, chLatin_C, chLatin_S, chDigit_4, chNull +}; + +const XMLCh XMLUni::fgUCS4BEncodingString[] = +{ + chLatin_U, chLatin_C, chLatin_S, chDigit_4, chSpace, chOpenParen, chLatin_B, chLatin_E, chCloseParen, chNull +}; + +const XMLCh XMLUni::fgUCS4BEncodingString2[] = +{ + chLatin_U, chLatin_C, chLatin_S, chDigit_4, chLatin_B, chLatin_E, chNull +}; + +const XMLCh XMLUni::fgUCS4LEncodingString[] = +{ + chLatin_U, chLatin_C, chLatin_S, chDigit_4, chSpace, chOpenParen, chLatin_L, chLatin_E, chCloseParen, chNull +}; + +const XMLCh XMLUni::fgUCS4LEncodingString2[] = +{ + chLatin_U, chLatin_C, chLatin_S, chDigit_4, chLatin_L, chLatin_E, chNull +}; + +const XMLCh XMLUni::fgUSASCIIEncodingString[] = +{ + chLatin_U, chLatin_S, chDash, chLatin_A, chLatin_S, chLatin_C, chLatin_I, chLatin_I, chNull +}; + +const XMLCh XMLUni::fgUSASCIIEncodingString2[] = +{ + chLatin_U, chLatin_S, chLatin_A, chLatin_S, chLatin_C, chLatin_I, chLatin_I, chNull +}; + +const XMLCh XMLUni::fgUSASCIIEncodingString3[] = +{ + chLatin_A, chLatin_S, chLatin_C, chLatin_I, chLatin_I, chNull +}; + +const XMLCh XMLUni::fgUSASCIIEncodingString4[] = +{ + chLatin_U, chLatin_S, chUnderscore, chLatin_A, chLatin_S, chLatin_C, chLatin_I, chLatin_I, chNull +}; + +const XMLCh XMLUni::fgUTF8EncodingString[] = +{ + chLatin_U, chLatin_T, chLatin_F, chDash, chDigit_8, chNull +}; + +const XMLCh XMLUni::fgUTF8EncodingString2[] = +{ + chLatin_U, chLatin_T, chLatin_F, chDigit_8, chNull +}; + +const XMLCh XMLUni::fgUTF16EncodingString[] = +{ + chLatin_U, chLatin_T, chLatin_F, chDash, chDigit_1, chDigit_6, chNull +}; + +const XMLCh XMLUni::fgUTF16BEncodingString[] = +{ + chLatin_U, chLatin_T, chLatin_F, chDash, chDigit_1, chDigit_6, chSpace, chOpenParen, chLatin_B, chLatin_E, chCloseParen, chNull +}; + +const XMLCh XMLUni::fgUTF16BEncodingString2[] = +{ + chLatin_U, chLatin_T, chLatin_F, chDash, chDigit_1, chDigit_6, chLatin_B, chLatin_E, chNull +}; + +const XMLCh XMLUni::fgUTF16LEncodingString[] = +{ + chLatin_U, chLatin_T, chLatin_F, chDash, chDigit_1, chDigit_6, chSpace, chOpenParen, chLatin_L, chLatin_E, chCloseParen, chNull +}; + +const XMLCh XMLUni::fgUTF16LEncodingString2[] = +{ + chLatin_U, chLatin_T, chLatin_F, chDash, chDigit_1, chDigit_6, chLatin_L, chLatin_E, chNull +}; + +const XMLCh XMLUni::fgVersionString[] = +{ + chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i, chLatin_o, chLatin_n, chNull +}; + +const XMLCh XMLUni::fgValidityDomain[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c, chLatin_h + , chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash + , chLatin_x, chLatin_m, chLatin_l, chForwardSlash, chLatin_m, chLatin_e + , chLatin_s, chLatin_s, chLatin_a, chLatin_g, chLatin_e, chLatin_s + , chForwardSlash, chLatin_X, chLatin_M, chLatin_L, chLatin_V, chLatin_a + , chLatin_l, chLatin_i, chLatin_d, chLatin_i, chLatin_t, chLatin_y, chNull +}; + +const XMLCh XMLUni::fgXMLString[] = +{ + chLatin_x, chLatin_m, chLatin_l, chNull +}; + +const XMLCh XMLUni::fgXMLStringSpace[] = +{ + chLatin_x, chLatin_m, chLatin_l, chSpace, chNull +}; + +const XMLCh XMLUni::fgXMLStringSpaceU[] = +{ + chLatin_X, chLatin_M, chLatin_L, chSpace, chNull +}; + +const XMLCh XMLUni::fgXMLDeclString[] = +{ + chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l, chNull +}; + +const XMLCh XMLUni::fgXMLDeclStringSpace[] = +{ + chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l, chSpace, chNull +}; + +const XMLCh XMLUni::fgXMLNSString[] = +{ + chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull +}; + +const XMLCh XMLUni::fgXMLNSColonString[] = +{ + chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chColon, chNull +}; + +const XMLCh XMLUni::fgXMLNSURIName[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c + , chLatin_h, chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g + , chForwardSlash, chLatin_x, chLatin_m, chLatin_l, chForwardSlash + , chLatin_N, chLatin_S, chLatin_M, chLatin_a, chLatin_p, chLatin_U + , chLatin_R, chLatin_I, chNull +}; + +const XMLCh XMLUni::fgXMLErrDomain[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c, chLatin_h + , chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash + , chLatin_x, chLatin_m, chLatin_l, chForwardSlash, chLatin_m, chLatin_e + , chLatin_s, chLatin_s, chLatin_a, chLatin_g, chLatin_e, chLatin_s + , chForwardSlash, chLatin_X, chLatin_M, chLatin_L, chLatin_E, chLatin_r + , chLatin_r, chLatin_o, chLatin_r, chLatin_s, chNull +}; + +const XMLCh XMLUni::fgXMLURIName[] = +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w + , chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash + , chLatin_X, chLatin_M, chLatin_L, chForwardSlash, chDigit_1, chDigit_9 + , chDigit_9, chDigit_8, chForwardSlash, chLatin_n, chLatin_a, chLatin_m + , chLatin_e, chLatin_s, chLatin_p, chLatin_a, chLatin_c, chLatin_e, chNull +}; + +const XMLCh XMLUni::fgYesString[] = +{ + chLatin_y, chLatin_e, chLatin_s, chNull +}; + +const XMLCh XMLUni::fgZeroLenString[] = { chNull }; diff --git a/src/util/XMLUni.hpp b/src/util/XMLUni.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e529159433f1e62a05903a908543aba179a1613f --- /dev/null +++ b/src/util/XMLUni.hpp @@ -0,0 +1,275 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:05:56 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:21 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// This file contains the grunt work constants for Unicode characters and +// common Unicode constant strings. These cannot be created normally because +// we have to compile on systems that cannot do the L"" style prefix. So +// they must be created as constant values for Unicode code points and the +// strings built up as arrays of those constants. +// --------------------------------------------------------------------------- + +#if !defined(XMLUNI_HPP) +#define XMLUNI_HPP + +#include <util/XML4CDefs.hpp> + +// --------------------------------------------------------------------------- +// Constants for the Unicode characters of interest to us in an XML parser +// We don't put these inside the class because then they could not be const +// inline values, which would have significant performance ramifications. +// +// We cannot use a namespace because of the requirement to support old +// compilers. +// --------------------------------------------------------------------------- +const XMLCh chNull = 0x00; +const XMLCh chHTab = 0x09; +const XMLCh chLF = 0x0A; +const XMLCh chCR = 0x0D; +const XMLCh chAmpersand = 0x26; +const XMLCh chAsterisk = 0x2A; +const XMLCh chAt = 0x40; +const XMLCh chBackSlash = 0x5C; +const XMLCh chBang = 0x21; +const XMLCh chCloseAngle = 0x3E; +const XMLCh chCloseCurly = 0x7D; +const XMLCh chCloseParen = 0x29; +const XMLCh chCloseSquare = 0x5D; +const XMLCh chColon = 0x3A; +const XMLCh chComma = 0x2C; +const XMLCh chDash = 0x2D; +const XMLCh chDollarSign = 0x24; +const XMLCh chDoubleQuote = 0x22; +const XMLCh chEqual = 0x3D; +const XMLCh chForwardSlash = 0x2F; +const XMLCh chGrave = 0x60; +const XMLCh chOpenAngle = 0x3C; +const XMLCh chOpenCurly = 0x7B; +const XMLCh chOpenParen = 0x28; +const XMLCh chOpenSquare = 0x5B; +const XMLCh chPercent = 0x25; +const XMLCh chPeriod = 0x2E; +const XMLCh chPipe = 0x7C; +const XMLCh chPlus = 0x2B; +const XMLCh chPound = 0x23; +const XMLCh chQuestion = 0x3F; +const XMLCh chSingleQuote = 0x27; +const XMLCh chSpace = 0x20; +const XMLCh chSemiColon = 0x3B; +const XMLCh chTilde = 0x7E; +const XMLCh chUnderscore = 0x5F; + +const XMLCh chSwappedUnicodeMarker = XMLCh(0xFFFE); +const XMLCh chUnicodeMarker = XMLCh(0xFEFF); + +const XMLCh chDigit_0 = 0x30; +const XMLCh chDigit_1 = 0x31; +const XMLCh chDigit_2 = 0x32; +const XMLCh chDigit_3 = 0x33; +const XMLCh chDigit_4 = 0x34; +const XMLCh chDigit_5 = 0x35; +const XMLCh chDigit_6 = 0x36; +const XMLCh chDigit_7 = 0x37; +const XMLCh chDigit_8 = 0x38; +const XMLCh chDigit_9 = 0x39; + +const XMLCh chLatin_A = 0x41; +const XMLCh chLatin_B = 0x42; +const XMLCh chLatin_C = 0x43; +const XMLCh chLatin_D = 0x44; +const XMLCh chLatin_E = 0x45; +const XMLCh chLatin_F = 0x46; +const XMLCh chLatin_G = 0x47; +const XMLCh chLatin_H = 0x48; +const XMLCh chLatin_I = 0x49; +const XMLCh chLatin_J = 0x4A; +const XMLCh chLatin_K = 0x4B; +const XMLCh chLatin_L = 0x4C; +const XMLCh chLatin_M = 0x4D; +const XMLCh chLatin_N = 0x4E; +const XMLCh chLatin_O = 0x4F; +const XMLCh chLatin_P = 0x50; +const XMLCh chLatin_Q = 0x51; +const XMLCh chLatin_R = 0x52; +const XMLCh chLatin_S = 0x53; +const XMLCh chLatin_T = 0x54; +const XMLCh chLatin_U = 0x55; +const XMLCh chLatin_V = 0x56; +const XMLCh chLatin_W = 0x57; +const XMLCh chLatin_X = 0x58; +const XMLCh chLatin_Y = 0x59; +const XMLCh chLatin_Z = 0x5A; + +const XMLCh chLatin_a = 0x61; +const XMLCh chLatin_b = 0x62; +const XMLCh chLatin_c = 0x63; +const XMLCh chLatin_d = 0x64; +const XMLCh chLatin_e = 0x65; +const XMLCh chLatin_f = 0x66; +const XMLCh chLatin_g = 0x67; +const XMLCh chLatin_h = 0x68; +const XMLCh chLatin_i = 0x69; +const XMLCh chLatin_j = 0x6A; +const XMLCh chLatin_k = 0x6B; +const XMLCh chLatin_l = 0x6C; +const XMLCh chLatin_m = 0x6D; +const XMLCh chLatin_n = 0x6E; +const XMLCh chLatin_o = 0x6F; +const XMLCh chLatin_p = 0x70; +const XMLCh chLatin_q = 0x71; +const XMLCh chLatin_r = 0x72; +const XMLCh chLatin_s = 0x73; +const XMLCh chLatin_t = 0x74; +const XMLCh chLatin_u = 0x75; +const XMLCh chLatin_v = 0x76; +const XMLCh chLatin_w = 0x77; +const XMLCh chLatin_x = 0x78; +const XMLCh chLatin_y = 0x79; +const XMLCh chLatin_z = 0x7A; + + +class XMLUTIL_EXPORT XMLUni +{ +public : + // ----------------------------------------------------------------------- + // These are constant strings that are common in XML data. Because + // of the limitation of the compilers we have to work with, these are + // done as arrays of XMLCh characters, not as constant strings. + // ----------------------------------------------------------------------- + static const XMLCh fgAnyString[]; + static const XMLCh fgAttListString[]; + static const XMLCh fgCommentString[]; + static const XMLCh fgCDATAString[]; + static const XMLCh fgDefaultString[]; + static const XMLCh fgDocTypeString[]; + static const XMLCh fgDefaultEBCDICEncodingString[]; + static const XMLCh fgEBCDICEncodingString[]; + static const XMLCh fgElemString[]; + static const XMLCh fgEmptyString[]; + static const XMLCh fgEncodingString[]; + static const XMLCh fgEntitString[]; + static const XMLCh fgEntityString[]; + static const XMLCh fgEntitiesString[]; + static const XMLCh fgEnumerationString[]; + static const XMLCh fgExceptDomain[]; + static const XMLCh fgFixedString[]; + static const XMLCh fgGlobalNSURIName[]; + static const XMLCh fgIESString[]; + static const XMLCh fgIDString[]; + static const XMLCh fgIDRefString[]; + static const XMLCh fgIDRefsString[]; + static const XMLCh fgImpliedString[]; + static const XMLCh fgIgnoreString[]; + static const XMLCh fgIncludeString[]; + static const XMLCh fgNoString[]; + static const XMLCh fgNotationString[]; + static const XMLCh fgNDATAString[]; + static const XMLCh fgNmTokenString[]; + static const XMLCh fgNmTokensString[]; + static const XMLCh fgOtherEncodingStr[]; + static const XMLCh fgPCDATAString[]; + static const XMLCh fgPIString[]; + static const XMLCh fgPubIDString[]; + static const XMLCh fgRefString[]; + static const XMLCh fgRequiredString[]; + static const XMLCh fgStandaloneString[]; + static const XMLCh fgSupportedVersion[]; + static const XMLCh fgSysIDString[]; + static const XMLCh fgUnknownURIName[]; + static const XMLCh fgUCS4EncodingString[]; + static const XMLCh fgUCS4BEncodingString[]; + static const XMLCh fgUCS4BEncodingString2[]; + static const XMLCh fgUCS4LEncodingString[]; + static const XMLCh fgUCS4LEncodingString2[]; + static const XMLCh fgUSASCIIEncodingString[]; + static const XMLCh fgUSASCIIEncodingString2[]; + static const XMLCh fgUSASCIIEncodingString3[]; + static const XMLCh fgUSASCIIEncodingString4[]; + static const XMLCh fgUTF8EncodingString[]; + static const XMLCh fgUTF8EncodingString2[]; + static const XMLCh fgUTF16EncodingString[]; + static const XMLCh fgUTF16BEncodingString[]; + static const XMLCh fgUTF16BEncodingString2[]; + static const XMLCh fgUTF16LEncodingString[]; + static const XMLCh fgUTF16LEncodingString2[]; + static const XMLCh fgVersionString[]; + static const XMLCh fgValidityDomain[]; + static const XMLCh fgXMLDeclString[]; + static const XMLCh fgXMLString[]; + static const XMLCh fgXMLStringSpace[]; + static const XMLCh fgXMLStringSpaceU[]; + static const XMLCh fgXMLDeclStringSpace[]; + static const XMLCh fgXMLNSString[]; + static const XMLCh fgXMLNSColonString[]; + static const XMLCh fgXMLNSURIName[]; + static const XMLCh fgXMLErrDomain[]; + static const XMLCh fgXMLURIName[]; + static const XMLCh fgYesString[]; + static const XMLCh fgZeroLenString[]; +}; + +#endif diff --git a/src/validators/DTD/CMBinaryOp.cpp b/src/validators/DTD/CMBinaryOp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c323b69e85740b39bb3c759a77e3c4c9c2eba99f --- /dev/null +++ b/src/validators/DTD/CMBinaryOp.cpp @@ -0,0 +1,187 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:00 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:35 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/RuntimeException.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/CMBinaryOp.hpp> +#include <validators/DTD/CMStateSet.hpp> + + +// --------------------------------------------------------------------------- +// CMBinaryOp: Constructors +// --------------------------------------------------------------------------- +CMBinaryOp::CMBinaryOp( const ContentSpecNode::NodeTypes type + , CMNode* const leftToAdopt + , CMNode* const rightToAdopt) : + CMNode(type) + , fLeftChild(leftToAdopt) + , fRightChild(rightToAdopt) +{ + // Insure that its one of the types we require + if ((type != ContentSpecNode::Choice) + && (type != ContentSpecNode::Sequence)) + { + ThrowXML(RuntimeException, XML4CExcepts::CM_BinOpHadUnaryType); + } +} + +CMBinaryOp::~CMBinaryOp() +{ + delete fLeftChild; + delete fRightChild; +} + + +// --------------------------------------------------------------------------- +// CMBinaryOp: Getter methods +// --------------------------------------------------------------------------- +const CMNode* CMBinaryOp::getLeft() const +{ + return fLeftChild; +} + +CMNode* CMBinaryOp::getLeft() +{ + return fLeftChild; +} + +const CMNode* CMBinaryOp::getRight() const +{ + return fRightChild; +} + +CMNode* CMBinaryOp::getRight() +{ + return fRightChild; +} + + +// --------------------------------------------------------------------------- +// CMBinaryOp: Implementation of the public CMNode virtual interface +// --------------------------------------------------------------------------- +bool CMBinaryOp::isNullable() const +{ + // + // If its an alternation, then if either child is nullable then + // this node is nullable. If its a concatenation, then both of + // them have to be nullable. + // + if (getType() == ContentSpecNode::Choice) + return (fLeftChild->isNullable() || fRightChild->isNullable()); + + return (fLeftChild->isNullable() && fRightChild->isNullable()); +} + + +// --------------------------------------------------------------------------- +// CMBinaryOp: Implementation of the protected CMNode virtual interface +// --------------------------------------------------------------------------- +void CMBinaryOp::calcFirstPos(CMStateSet& toSet) const +{ + if (getType() == ContentSpecNode::Choice) + { + // Its the the union of the first positions of our children. + toSet = fLeftChild->getFirstPos(); + toSet |= fRightChild->getFirstPos(); + } + else if (getType() == ContentSpecNode::Sequence) + { + // + // If our left child is nullable, then its the union of our + // children's first positions. Else is our left child's first + // positions. + // + toSet = fLeftChild->getFirstPos(); + if (fLeftChild->isNullable()) + toSet |= fRightChild->getFirstPos(); + } +} + +void CMBinaryOp::calcLastPos(CMStateSet& toSet) const +{ + if (getType() == ContentSpecNode::Choice) + { + // Its the the union of the first positions of our children. + toSet = fLeftChild->getLastPos(); + toSet |= fRightChild->getLastPos(); + } + else if (getType() == ContentSpecNode::Sequence) + { + // + // If our right child is nullable, then its the union of our + // children's last positions. Else is our right child's last + // positions. + // + toSet = fRightChild->getLastPos(); + if (fRightChild->isNullable()) + toSet |= fLeftChild->getLastPos(); + } +} diff --git a/src/validators/DTD/CMBinaryOp.hpp b/src/validators/DTD/CMBinaryOp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..352dce73d1bf6ed7bbc27ff157385401c7d0aef8 --- /dev/null +++ b/src/validators/DTD/CMBinaryOp.hpp @@ -0,0 +1,126 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:02 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:35 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(CMBINARYOP_HPP) +#define CMBINARYOP_HPP + +#include <util/XML4CDefs.hpp> +#include <validators/DTD/CMNode.hpp> + +class CMStateSet; + +class CMBinaryOp : public CMNode +{ +public : + // ----------------------------------------------------------------------- + // Constructors + // ----------------------------------------------------------------------- + CMBinaryOp + ( + const ContentSpecNode::NodeTypes type + , CMNode* const leftToAdopt + , CMNode* const rightToAdopt + ); + ~CMBinaryOp(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + const CMNode* getLeft() const; + CMNode* getLeft(); + const CMNode* getRight() const; + CMNode* getRight(); + + + // ----------------------------------------------------------------------- + // Implementation of the public CMNode virtual interface + // ----------------------------------------------------------------------- + bool isNullable() const; + + +protected : + // ----------------------------------------------------------------------- + // Implementation of the protected CMNode virtual interface + // ----------------------------------------------------------------------- + void calcFirstPos(CMStateSet& toSet) const; + void calcLastPos(CMStateSet& toSet) const; + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fLeftChild + // fRightChild + // These are the references to the two nodes that are on either side + // of this binary operation. We own them both. + // ----------------------------------------------------------------------- + CMNode* fLeftChild; + CMNode* fRightChild; +}; + +#endif diff --git a/src/validators/DTD/CMLeaf.hpp b/src/validators/DTD/CMLeaf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4a142f058dc8478060cfc86fee85d4875cb303a4 --- /dev/null +++ b/src/validators/DTD/CMLeaf.hpp @@ -0,0 +1,217 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:04 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:36 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(CMLEAF_HPP) +#define CMLEAF_HPP + +#include <util/XML4CDefs.hpp> +#include <util/RuntimeException.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/CMNode.hpp> +#include <validators/DTD/CMStateSet.hpp> + +// +// This class represents a leaf in the content spec node tree of an +// element's content model. It just has an element id and a position value, +// the latter of which is used during the building of a DFA. +// +class CMLeaf : public CMNode +{ +public : + // ----------------------------------------------------------------------- + // Constructors + // ----------------------------------------------------------------------- + CMLeaf + ( + const unsigned int elemId + , const unsigned int position = (unsigned int)-1 + ); + ~CMLeaf(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + unsigned int getId() const; + unsigned int getPosition() const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setPosition(const unsigned int newPosition); + + + // ----------------------------------------------------------------------- + // Implementation of public CMNode virtual interface + // ----------------------------------------------------------------------- + bool isNullable() const; + + +protected : + // ----------------------------------------------------------------------- + // Implementation of protected CMNode virtual interface + // ----------------------------------------------------------------------- + void calcFirstPos(CMStateSet& toSet) const; + void calcLastPos(CMStateSet& toSet) const; + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fElemId + // This is the element id of the element that this leaf represents. + // + // fPosition + // Part of the algorithm to convert a regex directly to a DFA + // numbers each leaf sequentially. If its -1, that means its an + // epsilon node. All others are non-epsilon positions. + // ----------------------------------------------------------------------- + unsigned int fElemId; + unsigned int fPosition; +}; + + +// ----------------------------------------------------------------------- +// Constructors +// ----------------------------------------------------------------------- +inline CMLeaf::CMLeaf( const unsigned int elemId + , const unsigned int position) : + CMNode(ContentSpecNode::Leaf) + , fElemId(elemId) + , fPosition(position) +{ +} + +inline CMLeaf::~CMLeaf() +{ +} + + +// --------------------------------------------------------------------------- +// Getter methods +// --------------------------------------------------------------------------- +inline unsigned int CMLeaf::getId() const +{ + return fElemId; +} + +inline unsigned int CMLeaf::getPosition() const +{ + return fPosition; +} + + +// --------------------------------------------------------------------------- +// Setter methods +// --------------------------------------------------------------------------- +inline void CMLeaf::setPosition(const unsigned int newPosition) +{ + fPosition = newPosition; +} + + +// --------------------------------------------------------------------------- +// Implementation of public CMNode virtual interface +// --------------------------------------------------------------------------- +inline bool CMLeaf::isNullable() const +{ + // Leaf nodes are never nullable unless its an epsilon node + return (fPosition == -1); +} + + +// --------------------------------------------------------------------------- +// Implementation of protected CMNode virtual interface +// --------------------------------------------------------------------------- +inline void CMLeaf::calcFirstPos(CMStateSet& toSet) const +{ + // If we are an epsilon node, then the first pos is an empty set + if (fPosition == -1) + { + toSet.zeroBits(); + return; + } + + // Otherwise, its just the one bit of our position + toSet.setBit(fPosition); +} + +inline void CMLeaf::calcLastPos(CMStateSet& toSet) const +{ + // If we are an epsilon node, then the last pos is an empty set + if (fPosition == -1) + { + toSet.zeroBits(); + return; + } + + // Otherwise, its just the one bit of our position + toSet.setBit(fPosition); +} + +#endif diff --git a/src/validators/DTD/CMNode.hpp b/src/validators/DTD/CMNode.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e3deeb956a9203778a52961d7399f639d8e6bb4b --- /dev/null +++ b/src/validators/DTD/CMNode.hpp @@ -0,0 +1,219 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:05 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:36 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(CMNODE_HPP) +#define CMNODE_HPP + +#include <util/XML4CDefs.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/CMStateSet.hpp> + + +class CMNode +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructors + // ----------------------------------------------------------------------- + CMNode(const ContentSpecNode::NodeTypes type); + virtual ~CMNode(); + + + // ----------------------------------------------------------------------- + // Virtual methods to be provided derived node classes + // ----------------------------------------------------------------------- + virtual bool isNullable() const = 0; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + ContentSpecNode::NodeTypes getType() const; + const CMStateSet& getFirstPos() const; + const CMStateSet& getLastPos() const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setMaxStates(const unsigned int maxStates); + + +protected : + // ----------------------------------------------------------------------- + // Protected, abstract methods + // ----------------------------------------------------------------------- + virtual void calcFirstPos(CMStateSet& toUpdate) const = 0; + virtual void calcLastPos(CMStateSet& toUpdate) const = 0; + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + CMNode(); + CMNode(const CMNode&); + void operator=(const CMNode&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fType + // The type of node. This indicates whether its a leaf or an + // operation. + // + // fFirstPos + // The set of NFA states that represent the entry states of this + // node in the DFA. + // + // fLastPos + // The set of NFA states that represent the final states of this + // node in the DFA. + // + // fMaxStates + // The maximum number of states that the NFA has, which means the + // max number of NFA states that have to be traced in the state + // sets during the building of the DFA. Its unfortunate that it + // has to be stored redundantly, but we need to fault in the + // state set members and they have to be sized to this size. + // ----------------------------------------------------------------------- + ContentSpecNode::NodeTypes fType; + CMStateSet* fFirstPos; + CMStateSet* fLastPos; + unsigned int fMaxStates; +}; + + + +// --------------------------------------------------------------------------- +// CMNode: Constructors and Destructors +// --------------------------------------------------------------------------- +inline CMNode::CMNode(const ContentSpecNode::NodeTypes type) : + + fType(type) + , fFirstPos(0) + , fLastPos(0) + , fMaxStates(-1) +{ +} + +inline CMNode::~CMNode() +{ + // Clean up any position sets that got created + delete fFirstPos; + delete fLastPos; +} + + +// --------------------------------------------------------------------------- +// CMNode: Getter methods +// --------------------------------------------------------------------------- +inline ContentSpecNode::NodeTypes CMNode::getType() const +{ + return fType; +} + +inline const CMStateSet& CMNode::getFirstPos() const +{ + // + // Fault in the state set if needed. Since we can't use mutable members + // cast off the const'ness. + // + if (!fFirstPos) + { + CMNode* unconstThis = (CMNode*)this; + unconstThis->fFirstPos = new CMStateSet(fMaxStates); + unconstThis->calcFirstPos(*fFirstPos); + } + return *fFirstPos; +} + +inline const CMStateSet& CMNode::getLastPos() const +{ + // + // Fault in the state set if needed. Since we can't use mutable members + // cast off the const'ness. + // + if (!fLastPos) + { + CMNode* unconstThis = (CMNode*)this; + unconstThis->fLastPos = new CMStateSet(fMaxStates); + unconstThis->calcLastPos(*fLastPos); + } + return *fLastPos; +} + + +// --------------------------------------------------------------------------- +// CMNode: Setter methods +// --------------------------------------------------------------------------- +inline void CMNode::setMaxStates(const unsigned int maxStates) +{ + fMaxStates = maxStates; +} + +#endif diff --git a/src/validators/DTD/CMStateSet.hpp b/src/validators/DTD/CMStateSet.hpp new file mode 100644 index 0000000000000000000000000000000000000000..675005bcc6a5d3beae974a6f9be91dc6d7690c57 --- /dev/null +++ b/src/validators/DTD/CMStateSet.hpp @@ -0,0 +1,341 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:06 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:36 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// DESCRIPTION: +// +// This class is a specialized bitset class for the content model code of +// the validator. It assumes that its never called with two objects of +// different bit counts, and that bit sets smaller than 64 bits are far +// and away the most common. So it can be a lot more optimized than a general +// purpose utility bitset class +// + +#if !defined(CMSTATESET_HPP) +#define CMSTATESET_HPP + +#include <util/XML4CDefs.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <framework/XMLValidityCodes.hpp> +#include <string.h> +#include <memory.h> + + +class CMStateSet +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + CMStateSet(const unsigned int bitCount) : + + fBitCount(bitCount) + , fByteArray(0) + { + // + // See if we need to allocate the byte array or whether we can live + // within the 64 bit high performance scheme. + // + if (fBitCount > 64) + { + fByteCount = fBitCount / 8; + if (fBitCount % 8) + fByteCount++; + fByteArray = new XMLByte[fByteCount]; + } + + // Init all the bits to zero + zeroBits(); + } + + + /* + * This method with the 'for' statement (commented out) cannot be made inline + * because the antiquated CC (CFront) compiler under HPUX 10.20 does not allow + * the 'for' statement inside any inline method. Unfortunately, + * we have to support it. So instead, we use memcpy(). + */ + + CMStateSet(const CMStateSet& toCopy) : + fBitCount(toCopy.fBitCount) + , fByteArray(0) + { + // + // See if we need to allocate the byte array or whether we can live + // within the 64 bit high performance scheme. + // + if (fBitCount > 64) + { + fByteCount = fBitCount / 8; + if (fBitCount % 8) + fByteCount++; + fByteArray = new XMLByte[fByteCount]; + + memcpy((void *) fByteArray, + (const void *) toCopy.fByteArray, + fByteCount * sizeof(XMLByte)); + + // for (unsigned int index = 0; index < fByteCount; index++) + // fByteArray[index] = toCopy.fByteArray[index]; + } + else + { + fBits1 = toCopy.fBits1; + fBits2 = toCopy.fBits2; + } + } + + ~CMStateSet() + { + if (fByteArray) + delete [] fByteArray; + } + + + // ----------------------------------------------------------------------- + // Set manipulation methods + // ----------------------------------------------------------------------- + void operator&=(const CMStateSet& setToAnd) + { + if (fBitCount < 65) + { + fBits1 &= setToAnd.fBits1; + fBits2 &= setToAnd.fBits2; + } + else + { + for (unsigned int index = 0; index < fByteCount; index++) + fByteArray[index] &= setToAnd.fByteArray[index]; + } + } + + void operator|=(const CMStateSet& setToOr) + { + if (fBitCount < 65) + { + fBits1 |= setToOr.fBits1; + fBits2 |= setToOr.fBits2; + } + else + { + for (unsigned int index = 0; index < fByteCount; index++) + fByteArray[index] |= setToOr.fByteArray[index]; + } + } + + bool operator==(const CMStateSet& setToCompare) const + { + if (fBitCount != setToCompare.fBitCount) + return false; + + if (fBitCount < 65) + { + return ((fBits1 == setToCompare.fBits1) + && (fBits2 == setToCompare.fBits2)); + } + + for (unsigned int index = 0; index < fByteCount; index++) + { + if (fByteArray[index] != setToCompare.fByteArray[index]) + return false; + } + return true; + } + + CMStateSet& operator=(const CMStateSet& srcSet) + { + if (this == &srcSet) + return *this; + + if (fBitCount < 65) + { + fBits1 = srcSet.fBits1; + fBits2 = srcSet.fBits2; + } + else + { + for (unsigned int index = 0; index < fByteCount; index++) + fByteArray[index] = srcSet.fByteArray[index]; + } + return *this; + } + + + bool getBit(const unsigned int bitToGet) const + { + if (bitToGet >= fBitCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Bitset_BadIndex); + + if (fBitCount < 65) + { + unsigned int mask = (0x1UL << (bitToGet % 32)); + if (bitToGet < 32) + return ((fBits1 & mask) != 0); + else + return ((fBits2 & mask) != 0); + } + + // Create the mask and byte values + const XMLByte mask1 = XMLByte(0x1 << (bitToGet % 8)); + const unsigned int byteOfs = bitToGet >> 3; + + // And access the right bit and byte + return ((fByteArray[byteOfs] & mask1) != 0); + } + + bool isEmpty() const + { + if (fBitCount < 65) + return ((fBits1 == 0) && (fBits2 == 0)); + + for (unsigned int index = 0; index < fByteCount; index++) + { + if (fByteArray[index] != 0) + return false; + } + return true; + } + + void setBit(const unsigned int bitToSet) + { + if (bitToSet >= fBitCount) + ThrowXML(ArrayIndexOutOfBoundsException, XML4CExcepts::Bitset_BadIndex); + + if (fBitCount < 65) + { + const unsigned int mask = (0x1UL << (bitToSet % 32)); + if (bitToSet < 32) + { + fBits1 &= ~mask; + fBits1 |= mask; + } + else + { + fBits2 &= ~mask; + fBits2 |= mask; + } + } + else + { + // Create the mask and byte values + const XMLByte mask1 = XMLByte(0x1 << (bitToSet % 8)); + const unsigned int byteOfs = bitToSet >> 3; + + // And access the right bit and byte + fByteArray[byteOfs] &= ~mask1; + fByteArray[byteOfs] |= mask1; + } + } + + void zeroBits() + { + if (fBitCount < 65) + { + fBits1 = 0; + fBits2 = 0; + } + else + { + for (unsigned int index = 0; index < fByteCount; index++) + fByteArray[index] = 0; + } + } + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + CMStateSet(); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fBitCount + // The count of bits that the outside world wants to support, + // so its the max bit index plus one. + // + // fByteCount + // If the bit count is > 64, then we use the fByteArray member to + // store the bits, and this indicates its size in bytes. Otherwise + // its value is meaningless and unset. + // + // fBits1 + // fBits2 + // When the bit count is <= 64 (very common), these hold the bits. + // Otherwise, the fByteArray member holds htem. + // + // fByteArray + // The array of bytes used when the bit count is > 64. It is + // allocated as required. + // ----------------------------------------------------------------------- + unsigned int fBitCount; + unsigned int fByteCount; + unsigned int fBits1; + unsigned int fBits2; + XMLByte* fByteArray; +}; + +#endif diff --git a/src/validators/DTD/CMUnaryOp.cpp b/src/validators/DTD/CMUnaryOp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e557a2f7f5e08eb9bdfe8afca2d4d9c8fe99f9f --- /dev/null +++ b/src/validators/DTD/CMUnaryOp.cpp @@ -0,0 +1,137 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:08 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:37 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XML4CDefs.hpp> +#include <util/RuntimeException.hpp> +#include <validators/DTD/CMStateSet.hpp> +#include <validators/DTD/CMUnaryOp.hpp> + + +// --------------------------------------------------------------------------- +// CMUnaryOp: Constructors and Destructor +// --------------------------------------------------------------------------- +CMUnaryOp::CMUnaryOp( const ContentSpecNode::NodeTypes type + , CMNode* const nodeToAdopt) : + CMNode(type) + , fChild(nodeToAdopt) +{ + // Insure that its one of the types we require + if ((type != ContentSpecNode::ZeroOrOne) + && (type != ContentSpecNode::ZeroOrMore) + && (type != ContentSpecNode::OneOrMore)) + { + ThrowXML(RuntimeException, XML4CExcepts::CM_UnaryOpHadBinType); + } +} + +CMUnaryOp::~CMUnaryOp() +{ + delete fChild; +} + + +// --------------------------------------------------------------------------- +// CMUnaryOp: Getter methods +// --------------------------------------------------------------------------- +const CMNode* CMUnaryOp::getChild() const +{ + return fChild; +} + +CMNode* CMUnaryOp::getChild() +{ + return fChild; +} + + +// --------------------------------------------------------------------------- +// CMUnaryOp: Implementation of the public CMNode virtual interface +// --------------------------------------------------------------------------- +bool CMUnaryOp::isNullable() const +{ + // Repetition operations are always nullable + return true; +} + + +// --------------------------------------------------------------------------- +// CMUnaryOp: Implementation of the protected CMNode virtual interface +// --------------------------------------------------------------------------- +void CMUnaryOp::calcFirstPos(CMStateSet& toSet) const +{ + // Its just based on our child node's first pos + toSet = fChild->getFirstPos(); +} + +void CMUnaryOp::calcLastPos(CMStateSet& toSet) const +{ + // Its just based on our child node's last pos + toSet = fChild->getLastPos(); +} diff --git a/src/validators/DTD/CMUnaryOp.hpp b/src/validators/DTD/CMUnaryOp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f9b34145cda249fc3de2655c9d98e243945677b0 --- /dev/null +++ b/src/validators/DTD/CMUnaryOp.hpp @@ -0,0 +1,123 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:11 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:37 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(CMUNARYOP_HPP) +#define CMUNARYOP_HPP + +#include <util/XML4CDefs.hpp> +#include <validators/DTD/CMNode.hpp> +#include <validators/DTD/ContentSpecNode.hpp> + +class CMStateSet; + +class CMUnaryOp : public CMNode +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + CMUnaryOp + ( + const ContentSpecNode::NodeTypes type + , CMNode* const nodeToAdopt + ); + ~CMUnaryOp(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + const CMNode* getChild() const; + CMNode* getChild(); + + + // ----------------------------------------------------------------------- + // Implementation of the public CMNode virtual interface + // ----------------------------------------------------------------------- + bool isNullable() const; + + +protected : + // ----------------------------------------------------------------------- + // Implementation of the protected CMNode virtual interface + // ----------------------------------------------------------------------- + void calcFirstPos(CMStateSet& toSet) const; + void calcLastPos(CMStateSet& toSet) const; + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fChild + // This is the reference to the one child that we have for this + // unary operation. We own it. + // ----------------------------------------------------------------------- + CMNode* fChild; +}; + +#endif diff --git a/src/validators/DTD/ContentSpecNode.cpp b/src/validators/DTD/ContentSpecNode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..36a5a582b83d850cef1c09fde268bad2a7d466c0 --- /dev/null +++ b/src/validators/DTD/ContentSpecNode.cpp @@ -0,0 +1,187 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:12 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:37 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Janitor.hpp> +#include <util/XMLUni.hpp> +#include <framework/XMLNotationDecl.hpp> +#include <framework/XMLBuffer.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/DTDValidator.hpp> + + + +// --------------------------------------------------------------------------- +// Local methods +// --------------------------------------------------------------------------- +static void formatNode( const ContentSpecNode* const curNode + , const ContentSpecNode::NodeTypes parentType + , const XMLValidator& validator + , XMLBuffer& bufToFill) +{ + const ContentSpecNode* first = curNode->getFirst(); + const ContentSpecNode* second = curNode->getSecond(); + const ContentSpecNode::NodeTypes curType = curNode->getType(); + + // Get the type of the first node + const ContentSpecNode::NodeTypes firstType = first ? + first->getType() : + ContentSpecNode::Leaf; + + // Calculate the parens flag for the rep nodes + bool doRepParens = false; + if (((firstType != ContentSpecNode::Leaf) && (parentType != -1)) + || ((firstType == ContentSpecNode::Leaf) && (parentType == -1))) + { + doRepParens = true; + } + + // Now handle our type + unsigned int tmpVal; + switch(curType) + { + case ContentSpecNode::Leaf : + tmpVal = curNode->getElemId(); + if (tmpVal == XMLElementDecl::fgPCDataElemId) + bufToFill.append(XMLElementDecl::fgPCDataElemName); + else + bufToFill.append(validator.getElemDecl(tmpVal)->getFullName()); + break; + + case ContentSpecNode::ZeroOrOne : + if (doRepParens) + bufToFill.append(chOpenParen); + formatNode(first, curType, validator, bufToFill); + if (doRepParens) + bufToFill.append(chCloseParen); + bufToFill.append(chQuestion); + break; + + case ContentSpecNode::ZeroOrMore : + if (doRepParens) + bufToFill.append(chOpenParen); + formatNode(first, curType, validator, bufToFill); + if (doRepParens) + bufToFill.append(chCloseParen); + bufToFill.append(chAsterisk); + break; + + case ContentSpecNode::OneOrMore : + if (doRepParens) + bufToFill.append(chOpenParen); + formatNode(first, curType, validator, bufToFill); + if (doRepParens) + bufToFill.append(chCloseParen); + bufToFill.append(chPlus); + break; + + case ContentSpecNode::Choice : + if (parentType != curType) + bufToFill.append(chOpenParen); + formatNode(first, curType, validator, bufToFill); + bufToFill.append(chPipe); + formatNode(second, curType, validator, bufToFill); + if (parentType != curType) + bufToFill.append(chCloseParen); + break; + + case ContentSpecNode::Sequence : + if (parentType != curType) + bufToFill.append(chOpenParen); + formatNode(first, curType, validator, bufToFill); + bufToFill.append(chComma); + formatNode(second, curType, validator, bufToFill); + if (parentType != curType) + bufToFill.append(chCloseParen); + break; + } +} + + +// --------------------------------------------------------------------------- +// ContentSpecNode: Miscellaneous +// --------------------------------------------------------------------------- +void ContentSpecNode::formatSpec(const XMLValidator& validator + , XMLBuffer& bufToFill) const +{ + // Clean out the buffer first + bufToFill.reset(); + + if (fType == ContentSpecNode::Leaf) + bufToFill.append(chOpenParen); + formatNode + ( + this + , ContentSpecNode::NodeTypes(-1) + , validator + , bufToFill + ); + if (fType == ContentSpecNode::Leaf) + bufToFill.append(chCloseParen); +} diff --git a/src/validators/DTD/ContentSpecNode.hpp b/src/validators/DTD/ContentSpecNode.hpp new file mode 100644 index 0000000000000000000000000000000000000000..58fea0b8d9c933482e072b5a72df7944963f2b13 --- /dev/null +++ b/src/validators/DTD/ContentSpecNode.hpp @@ -0,0 +1,297 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:14 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:38 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(CONTENTSPECNODE_HPP) +#define CONTENTSPECNODE_HPP + +#include <framework/XMLElementDecl.hpp> +#include <util/XML4CDefs.hpp> + +class XMLBuffer; +class XMLValidator; + + +class ContentSpecNode +{ +public : + // ----------------------------------------------------------------------- + // Class specific types + // ----------------------------------------------------------------------- + enum NodeTypes + { + Leaf + , ZeroOrOne + , ZeroOrMore + , OneOrMore + , Choice + , Sequence + }; + + + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + ContentSpecNode(); + ContentSpecNode(const unsigned int elemId); + ContentSpecNode + ( + const NodeTypes type + , ContentSpecNode* const firstToAdopt + , ContentSpecNode* const secondToAdopt + ); + ~ContentSpecNode(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + unsigned int getElemId() const; + ContentSpecNode* getFirst(); + const ContentSpecNode* getFirst() const; + ContentSpecNode* getSecond(); + const ContentSpecNode* getSecond() const; + NodeTypes getType() const; + bool isPCData() const; + ContentSpecNode* orphanFirst(); + ContentSpecNode* orphanSecond(); + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setElemId(const unsigned int elemId); + void setFirst(ContentSpecNode* const toAdopt); + void setSecond(ContentSpecNode* const toAdopt); + void setType(const NodeTypes type); + + + // ----------------------------------------------------------------------- + // Miscellaneous + // ----------------------------------------------------------------------- + void formatSpec + ( + const XMLValidator& validator + , XMLBuffer& bufToFill + ) const; + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + ContentSpecNode(const ContentSpecNode&); + void operator=(const ContentSpecNode&); + + + // ----------------------------------------------------------------------- + // Private Data Members + // + // fElemId + // If the type is Leaf, then this is the id of the element. If its + // fgPCDataElemId, then its a PCData node. + // + // fFirst + // fSecond + // The optional first and second nodes. The fType field indicates + // which of these are valid. The validaty constraints are: + // + // Leaf = Neither valid + // ZeroOrOne, ZeroOrMore = First + // Choice, Sequence = First and Second + // + // fType + // The type of node. This controls how many of the child node fields + // are used. + // ----------------------------------------------------------------------- + unsigned int fElemId; + ContentSpecNode* fFirst; + ContentSpecNode* fSecond; + NodeTypes fType; +}; + + +// --------------------------------------------------------------------------- +// ContentSpecNode: Constructors and Destructor +// --------------------------------------------------------------------------- +inline ContentSpecNode::ContentSpecNode() : + + fElemId(XMLElementDecl::fgInvalidElemId) + , fFirst(0) + , fSecond(0) + , fType(ContentSpecNode::Leaf) +{ +} + +inline +ContentSpecNode::ContentSpecNode(const unsigned int elemId) : + + fElemId(elemId) + , fFirst(0) + , fSecond(0) + , fType(ContentSpecNode::Leaf) +{ +} + +inline +ContentSpecNode::ContentSpecNode(const NodeTypes type + , ContentSpecNode* const firstToAdopt + , ContentSpecNode* const secondToAdopt) : + + fElemId(XMLElementDecl::fgInvalidElemId) + , fFirst(firstToAdopt) + , fSecond(secondToAdopt) + , fType(type) +{ +} + +inline ContentSpecNode::~ContentSpecNode() +{ + // Delete our children, which cause recursive cleanup + delete fFirst; + delete fSecond; +} + + +// --------------------------------------------------------------------------- +// ContentSpecNode: Getter methods +// --------------------------------------------------------------------------- +inline unsigned int ContentSpecNode::getElemId() const +{ + return fElemId; +} + +inline ContentSpecNode* ContentSpecNode::getFirst() +{ + return fFirst; +} + +inline const ContentSpecNode* ContentSpecNode::getFirst() const +{ + return fFirst; +} + +inline ContentSpecNode* ContentSpecNode::getSecond() +{ + return fSecond; +} + +inline const ContentSpecNode* ContentSpecNode::getSecond() const +{ + return fSecond; +} + +inline ContentSpecNode::NodeTypes ContentSpecNode::getType() const +{ + return fType; +} + +inline bool ContentSpecNode::isPCData() const +{ + return ((fType == Leaf) && (fElemId == XMLElementDecl::fgPCDataElemId)); +} + +inline ContentSpecNode* ContentSpecNode::orphanFirst() +{ + ContentSpecNode* retNode = fFirst; + fFirst = 0; + return retNode; +} + +inline ContentSpecNode* ContentSpecNode::orphanSecond() +{ + ContentSpecNode* retNode = fSecond; + fSecond = 0; + return retNode; +} + + +// --------------------------------------------------------------------------- +// ContentSpecType: Setter methods +// --------------------------------------------------------------------------- +inline void ContentSpecNode::setElemId(const unsigned int newId) +{ + fElemId = newId; +} + +inline void ContentSpecNode::setFirst(ContentSpecNode* const toAdopt) +{ + delete fFirst; + fFirst = toAdopt; +} + +inline void ContentSpecNode::setSecond(ContentSpecNode* const toAdopt) +{ + delete fSecond; + fSecond = toAdopt; +} + +inline void ContentSpecNode::setType(const NodeTypes type) +{ + fType = type; +} + +#endif diff --git a/src/validators/DTD/DFAContentModel.cpp b/src/validators/DTD/DFAContentModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85f7acc3c5c5e0e13ebe254c4c1d2dcadc8ad35e --- /dev/null +++ b/src/validators/DTD/DFAContentModel.cpp @@ -0,0 +1,792 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:17 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:38 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/RuntimeException.hpp> +#include <framework/XMLValidator.hpp> +#include <validators/DTD/CMBinaryOp.hpp> +#include <validators/DTD/CMLeaf.hpp> +#include <validators/DTD/CMUnaryOp.hpp> +#include <validators/DTD/DFAContentModel.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/DTDElementDecl.hpp> + + +// --------------------------------------------------------------------------- +// Local static data +// +// gEOCFakeId +// gEpsilonFakeId +// We have to put in a couple of special CMLeaf nodes to represent +// special values, using fake element ids that we know won't conflict +// with real element ids. +// --------------------------------------------------------------------------- +static const unsigned int gEOCFakeId = 0xFFFFFFF1; +static const unsigned int gEpsilonFakeId = 0xFFFFFFF2; + + +// --------------------------------------------------------------------------- +// DFAContentModel: Constructors and Destructor +// --------------------------------------------------------------------------- +DFAContentModel::DFAContentModel(const DTDElementDecl& elemDecl) : + + fElemDecl(elemDecl) + , fElemMap(0) + , fElemMapSize(0) + , fEmptyOk(false) + , fEOCPos(0) + , fFinalStateFlags(0) + , fFollowList(0) + , fHeadNode(0) + , fLeafCount(0) + , fLeafList(0) + , fSpecNode(0) + , fTransTable(0) + , fTransTableSize(0) +{ + // + // Store away our content spec node. This is used all over the place + // here so its easier to store a member pointer than to pass it around. + // + fSpecNode = elemDecl.getContentSpec(); + + // And build the DFA data structures + buildDFA(); +} + +DFAContentModel::~DFAContentModel() +{ + // + // Clean up all the stuff that is not just temporary representation + // data that was cleaned up after building the DFA. + // + delete [] fFinalStateFlags; + + unsigned index; + for (index = 0; index < fTransTableSize; index++) + delete [] fTransTable[index]; + delete [] fTransTable; + + delete [] fElemMap; +} + + +// --------------------------------------------------------------------------- +// DFAContentModel: Implementation of the ContentModel virtual interface +// --------------------------------------------------------------------------- +int +DFAContentModel::validateContent( const unsigned int* childIds + , const unsigned int childCount) const +{ + // + // If there are no children, then either we fail on the 0th element + // or we return success. It depends upon whether this content model + // accepts empty content, which we determined earlier. + // + if (!childCount) + { + if (fEmptyOk) + return -1; + return 0; + } + + // + // Lets loop through the children in the array and move our way + // through the states. Note that we use the fElemMap array to map + // an element index to a state index. + // + unsigned int curState = 0; + unsigned int childIndex = 0; + for (; childIndex < childCount; childIndex++) + { + // Get the current element index out + const unsigned int curElem = childIds[childIndex]; + + // Look up this child in our element map + unsigned int elemIndex = 0; + for (; elemIndex < fElemMapSize; elemIndex++) + { + if (fElemMap[elemIndex] == curElem) + break; + } + + // If we didn't find it, then obviously not valid + if (elemIndex == fElemMapSize) + return childIndex; + + // + // Look up the next state for this input symbol when in the + // current state. + // + curState = fTransTable[curState][elemIndex]; + + // If its not a legal transition then we failed. + if (curState == -1) + return childIndex; + } + + // + // We transitioned all the way through the input list. However, that + // does not mean that we ended in a final state. So check whether + // our ending state is a final state. + // + if (!fFinalStateFlags[curState]) + return childIndex; + + return XMLValidator::Success; +} + + +// --------------------------------------------------------------------------- +// DFAContentModel: Private helper methods +// --------------------------------------------------------------------------- +void DFAContentModel::buildDFA() +{ + unsigned int index; + + + // + // The first step we need to take is to rewrite the content model using + // our CMNode objects, and in the process get rid of any repetition short + // cuts, converting them into '*' style repetitions or getting rid of + // repetitions altogether. + // + // The conversions done are: + // + // x+ -> (x|x*) + // x? -> (x|epsilon) + // + // This is a relatively complex scenario. What is happening is that we + // create a top level binary node of which the special EOC value is set + // as the right side node. The the left side is set to the rewritten + // syntax tree. The source is the original content model info from the + // decl pool. The rewrite is done by buildSyntaxTree() which recurses the + // decl pool's content of the element and builds a new tree in the + // process. + // + // Note that, during this operation, we set each non-epsilon leaf node's + // DFA state position and count the number of such leafs, which is left + // in the fLeafCount member. + // + CMLeaf* nodeEOC = new CMLeaf(gEOCFakeId); + CMNode* nodeOrgContent = buildSyntaxTree(fElemDecl.getContentSpec()); + fHeadNode = new CMBinaryOp + ( + ContentSpecNode::Sequence + , nodeOrgContent + , nodeEOC + ); + + // + // And handle specially the EOC node, which also must be numbered and + // counted as a non-epsilon leaf node. It could not be handled in the + // above tree build because it was created before all that started. We + // save the EOC position since its used during the DFA building loop. + // + fEOCPos = fLeafCount; + nodeEOC->setPosition(fLeafCount++); + + // + // Ok, so now we have to iterate the new tree and do a little more work + // now that we know the leaf count. One thing we need to do is to + // calculate the first and last position sets of each node. This is + // cached away in each of the nodes. + // + // Along the way we also set the leaf count in each node as the maximum + // state count. They must know this in order to create their first/last + // position sets. + // + // We also need to build an array of references to the non-epsilon + // leaf nodes. Since we iterate here the same way as we did during the + // initial tree build (which built their position numbers, we will put + // them in the array according to their position values. + // + fLeafList = new CMLeaf*[fLeafCount]; + postTreeBuildInit(fHeadNode, 0); + + // + // And, moving onward... We now need to build the follow position sets + // for all the nodes. So we allocate an array of pointers to state sets, + // one for each leaf node (i.e. each significant DFA position.) + // + fFollowList = new CMStateSet*[fLeafCount]; + for (index = 0; index < fLeafCount; index++) + fFollowList[index] = new CMStateSet(fLeafCount); + calcFollowList(fHeadNode); + + // + // Check the DFA for ambiguity. If it is ambiguous, then set the + // ambiguous flag member and keep going. + // + fIsAmbiguous = isAmbiguous(); + + // + // Check to see whether this content model can handle an empty content, + // which is something we need to optimize by looking now before we + // throw away the info that would tell us that. + // + // If the left node of the head (the top level of the original content) + // is nullable, then its true. + // + fEmptyOk = nodeOrgContent->isNullable(); + + // + // And finally the big push... Now we build the DFA using all the states + // and the tree we've built up. First we set up the various data + // structures we are going to use while we do this. + // + // First of all we need an array of unique element ids in our content + // model. For each transition table entry, we need a set of contiguous + // indices to represent the transitions for a particular input element. + // So we need to a zero based range of indexes that map to element types. + // This element map provides that mapping. + // + fElemMap = new unsigned int[fLeafCount]; + fElemMapSize = 0; + for (unsigned int outIndex = 0; outIndex < fLeafCount; outIndex++) + { + // Get the current leaf's element index + const unsigned int elemId = fLeafList[outIndex]->getId(); + + // See if the current leaf node's element index is in the list + unsigned int inIndex = 0; + for (; inIndex < fElemMapSize; inIndex++) + { + if (fElemMap[inIndex] == elemId) + break; + } + + // If it was not in the list, then add it and bump the map size + if (inIndex == fElemMapSize) + fElemMap[fElemMapSize++] = elemId; + } + + // + // Next lets create some arrays, some that that hold transient info + // during the DFA build and some that are permament. These are kind of + // sticky since we cannot know how big they will get, but we don't want + // to use any collection type classes because of performance. + // + // Basically they will probably be about fLeafCount*2 on average, but can + // be as large as 2^(fLeafCount*2), worst case. So we start with + // fLeafCount*4 as a middle ground. This will be very unlikely to ever + // have to expand though, it if does, the overhead will be somewhat ugly. + // + unsigned int curArraySize = fLeafCount * 4; + const CMStateSet** statesToDo = new const CMStateSet*[curArraySize]; + fFinalStateFlags = new bool[curArraySize]; + fTransTable = new unsigned int*[curArraySize]; + + // + // Ok we start with the initial set as the first pos set of the head node + // (which is the seq node that holds the content model and the EOC node.) + // + const CMStateSet* setT = new CMStateSet(fHeadNode->getFirstPos()); + + // + // Init our two state flags. Basically the unmarked state counter is + // always chasing the current state counter. When it catches up, that + // means we made a pass through that did not add any new states to the + // lists, at which time we are done. We could have used a expanding array + // of flags which we used to mark off states as we complete them, but + // this is easier though less readable maybe. + // + unsigned int unmarkedState = 0; + unsigned int curState = 0; + + // + // Init the first transition table entry, and put the initial state + // into the states to do list, then bump the current state. + // + fTransTable[curState] = makeDefStateList(); + statesToDo[curState] = setT; + curState++; + + // + // Ok, almost done with the algorithm from hell... We now enter the + // loop where we go until the states done counter catches up with + // the states to do counter. + // + CMStateSet* newSet = 0; + while (unmarkedState < curState) + { + // + // Get the next unmarked state out of the list of states to do. + // And get the associated transition table entry. + // + setT = statesToDo[unmarkedState]; + unsigned int* transEntry = fTransTable[unmarkedState]; + + // Mark this one final if it contains the EOC state + fFinalStateFlags[unmarkedState] = setT->getBit(fEOCPos); + + // Bump up the unmarked state count, marking this state done + unmarkedState++; + + // Loop through each possible input symbol in the element map + for (unsigned int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) + { + // + // Build up a set of states which is the union of all of the + // follow sets of DFA positions that are in the current state. If + // we gave away the new set last time through then create a new + // one. Otherwise, zero out the existing one. + // + if (!newSet) + newSet = new CMStateSet(fLeafCount); + else + newSet->zeroBits(); + + for (unsigned int leafIndex = 0; leafIndex < fLeafCount; leafIndex++) + { + // If this leaf index (DFA position) is in the current set... + if (setT->getBit(leafIndex)) + { + // + // If this leaf is the current input symbol, then we want + // to add its follow list to the set of states to transition + // to from the current state. + // + if (fLeafList[leafIndex]->getId() == fElemMap[elemIndex]) + *newSet |= *fFollowList[leafIndex]; + } + } + + // + // If this new set is not empty, then see if its in the list + // of states to do. If not, then add it. + // + if (!newSet->isEmpty()) + { + // + // Search the 'states to do' list to see if this new + // state set is already in there. + // + unsigned int stateIndex = 0; + for (; stateIndex < curState; stateIndex++) + { + if (*statesToDo[stateIndex] == *newSet) + break; + } + + // If we did not find it, then add it + if (stateIndex == curState) + { + // + // Put this new state into the states to do and init + // a new entry at the same index in the transition + // table. + // + statesToDo[curState] = newSet; + fTransTable[curState] = makeDefStateList(); + + // We now have a new state to do so bump the count + curState++; + + // + // Null out the new set to indicate we adopted it. This + // will cause the creation of a new set on the next time + // around the loop. + // + newSet = 0; + } + + // + // Now set this state in the transition table's entry for this + // element (using its index), with the DFA state we will move + // to from the current state when we see this input element. + // + transEntry[elemIndex] = stateIndex; + + // Expand the arrays if we're full + if (curState == curArraySize) + { + // + // Yikes, we overflowed the initial array size, so we've + // got to expand all of these arrays. So adjust up the + // size by 50% and allocate new arrays. + // + const unsigned int newSize = (unsigned int)(curArraySize * 1.5); + const CMStateSet** newToDo = new const CMStateSet*[newSize]; + bool* newFinalFlags = new bool[newSize]; + unsigned int** newTransTable = new unsigned int*[newSize]; + + // Copy over all of the existing content + for (unsigned int expIndex = 0; expIndex < curArraySize; expIndex++) + { + newToDo[expIndex] = statesToDo[expIndex]; + newFinalFlags[expIndex] = fFinalStateFlags[expIndex]; + newTransTable[expIndex] = fTransTable[expIndex]; + } + + // Clean up the old stuff + delete [] statesToDo; + delete [] fFinalStateFlags; + delete [] fTransTable; + + // Store the new array size and pointers + curArraySize = newSize; + statesToDo = newToDo; + fFinalStateFlags = newFinalFlags; + fTransTable = newTransTable; + } + } + } + } + + // Store the current state count in the trans table size + fTransTableSize = curState; + + // If the last temp set was not stored, then clean it up + if (newSet) + delete newSet; + + // + // Now we can clean up all of the temporary data that was needed during + // DFA build. + // + delete fHeadNode; + fHeadNode = 0; + + for (index = 0; index < fLeafCount; index++) + delete fFollowList[index]; + + for (index = 0; index < curState; index++) + delete (CMStateSet*)statesToDo[index]; + + delete [] fLeafList; + delete [] fFollowList; + delete [] statesToDo; +} + + +CMNode* DFAContentModel::buildSyntaxTree(const ContentSpecNode* const curNode) +{ + // Initialize a return node pointer + CMNode* retNode = 0; + + // Get the spec type of the passed node + const ContentSpecNode::NodeTypes curType = curNode->getType(); + + if (curType == ContentSpecNode::Leaf) + { + // + // Create a new leaf node, and pass it the current leaf count, which + // is its DFA state position. Bump the leaf count after storing it. + // This makes the positions zero based since we store first and then + // increment. + // + retNode = new CMLeaf(curNode->getElemId(), fLeafCount++); + } + else + { + // + // Its not a leaf, so we have to recurse its left and maybe right + // nodes. Save both values before we recurse and trash the node. + // + const ContentSpecNode* leftNode = curNode->getFirst(); + const ContentSpecNode* rightNode = curNode->getSecond(); + + if ((curType == ContentSpecNode::Choice) + || (curType == ContentSpecNode::Sequence)) + { + // + // Recurse on both children, and return a binary op node with the + // two created sub nodes as its children. The node type is the + // same type as the source. + // + CMNode* newLeft = buildSyntaxTree(leftNode); + CMNode* newRight = buildSyntaxTree(rightNode); + retNode = new CMBinaryOp(curType, newLeft, newRight); + } + else if (curType == ContentSpecNode::ZeroOrMore) + { + // This one is fine as is, just change to our form + retNode = new CMUnaryOp(curType, buildSyntaxTree(leftNode)); + } + else if (curType == ContentSpecNode::ZeroOrOne) + { + // Convert to (x|epsilon) + CMNode* newLeft = buildSyntaxTree(leftNode); + retNode = new CMBinaryOp + ( + ContentSpecNode::Choice + , newLeft + , new CMLeaf(gEpsilonFakeId) + ); + } + else if (curType == ContentSpecNode::OneOrMore) + { + // Convert to (x,x*) + CMNode* newLeft = buildSyntaxTree(leftNode); + CMNode* newLeft2 = buildSyntaxTree(leftNode); + retNode = new CMBinaryOp + ( + ContentSpecNode::Sequence + , newLeft + , new CMUnaryOp(ContentSpecNode::ZeroOrMore, newLeft2) + ); + } + else + { + ThrowXML(RuntimeException, XML4CExcepts::CM_UnknownCMSpecType); + } + } + return retNode; +} + + +void DFAContentModel::calcFollowList(CMNode* const curNode) +{ + // Get the spec type of the passed node + const ContentSpecNode::NodeTypes curType = curNode->getType(); + + if (curType == ContentSpecNode::Choice) + { + // Just recurse + calcFollowList(((CMBinaryOp*)curNode)->getLeft()); + calcFollowList(((CMBinaryOp*)curNode)->getRight()); + } + else if (curType == ContentSpecNode::Sequence) + { + // Recurse before we process this node + calcFollowList(((CMBinaryOp*)curNode)->getLeft()); + calcFollowList(((CMBinaryOp*)curNode)->getRight()); + + // + // Now handle our level. We use our left child's last pos set and our + // right child's first pos set, so get them now for convenience. + // + const CMStateSet& last = ((CMBinaryOp*)curNode)->getLeft()->getLastPos(); + const CMStateSet& first = ((CMBinaryOp*)curNode)->getRight()->getFirstPos(); + + // + // Now, for every position which is in our left child's last set + // add all of the states in our right child's first set to the + // follow set for that position. + // + for (unsigned int index = 0; index < fLeafCount; index++) + { + if (last.getBit(index)) + *fFollowList[index] |= first; + } + } + else if (curType == ContentSpecNode::ZeroOrMore) + { + // Recurse first + calcFollowList(((CMUnaryOp*)curNode)->getChild()); + + // + // Now handle our level. We use our own first and last position + // sets, so get them up front. + // + const CMStateSet& first = curNode->getFirstPos(); + const CMStateSet& last = curNode->getLastPos(); + + // + // For every position which is in our last position set, add all + // of our first position states to the follow set for that + // position. + // + for (unsigned int index = 0; index < fLeafCount; index++) + { + if (last.getBit(index)) + *fFollowList[index] |= first; + } + } + else if ((curType == ContentSpecNode::OneOrMore) + || (curType == ContentSpecNode::ZeroOrOne)) + { + ThrowXML1(RuntimeException, XML4CExcepts::CM_NotValidForSpecType, "CalcFollowList"); + } +} + + +bool DFAContentModel::isAmbiguous() const +{ + unsigned int index; + + // + // Run through the current leaves and remember the min and max element + // ids. These will be used to create a bit set that will map to element + // ids (adjusted by the min value.) + // + // Do fLeafCount - 1 because we don't want to pick up the 'EOC' node, + // which has a very large dummy value in it. + // + unsigned int minId = 0xFFFFFFFF; + unsigned int maxId = 0; + for (index = 0; index < fLeafCount - 1; index++) + { + const unsigned int curId = fLeafList[index]->getId(); + if (curId < minId) + minId = curId; + + if (curId > maxId) + maxId = curId; + } + + // + // Ok, now we can create a range value that represents the spread + // between the min/max element value. The range can never be larger + // than the number of elements in the content model, so it would + // never be outrageously large unless the content model was just + // totally pathological. + // + // With this number we can create a state set that has a bit per + // possible entry in the leaf array. + // + const unsigned int idRange = (maxId - minId) + 1; + CMStateSet idSet(idRange); + + // Check each follow list + for (index = 0; index < fLeafCount - 1; index++) + { + // Get the current follow list set + const CMStateSet* curSet = fFollowList[index]; + + // + // For each possible leaf, we now go through and get the element + // id, adjust it to zero base it, then check it in the idSet. If + // that bit is already on, its ambiguous. Else set that bit and + // keep going. + // + for (unsigned int inner = 0; inner < fLeafCount - 1; inner++) + { + // If this bit is not on in the follow set, skip to next + if (!curSet->getBit(inner)) + continue; + + // Get the adjusted id value for the element in the follow list + const unsigned int adjustedId = fLeafList[inner]->getId() - minId; + + if (idSet.getBit(adjustedId)) + return true; + idSet.setBit(adjustedId); + } + + // Zero out the bitset for the next round + idSet.zeroBits(); + } + return false; +} + + +// +// -1 is used to represent bad transitions in the transition table entry for +// each state. So each entry is initialized to an all -1 array. This method +// creates a new entry and initializes it. +// +unsigned int* DFAContentModel::makeDefStateList() const +{ + unsigned int* retArray = new unsigned int[fElemMapSize]; + for (unsigned int index = 0; index < fElemMapSize; index++) + retArray[index] = -1; + return retArray; +} + + +int DFAContentModel::postTreeBuildInit( CMNode* const nodeCur + , const unsigned int curIndex) +{ + // Set the maximum states on this node + nodeCur->setMaxStates(fLeafCount); + + // Get the spec type of the passed node + const ContentSpecNode::NodeTypes curType = nodeCur->getType(); + + // Get a copy of the index we can modify + unsigned int newIndex = curIndex; + + // Recurse as required + if ((curType == ContentSpecNode::Choice) + || (curType == ContentSpecNode::Sequence)) + { + newIndex = postTreeBuildInit(((CMBinaryOp*)nodeCur)->getLeft(), newIndex); + newIndex = postTreeBuildInit(((CMBinaryOp*)nodeCur)->getRight(), newIndex); + } + else if (curType == ContentSpecNode::ZeroOrMore) + { + newIndex = postTreeBuildInit(((CMUnaryOp*)nodeCur)->getChild(), newIndex); + } + else if (curType == ContentSpecNode::Leaf) + { + // + // Put this node in the leaf list at the current index if its + // a non-epsilon leaf. + // + if (((CMLeaf*)nodeCur)->getId() != gEpsilonFakeId) + fLeafList[newIndex++] = (CMLeaf*)nodeCur; + } + else + { + ThrowXML(RuntimeException, XML4CExcepts::CM_UnknownCMSpecType); + } + return newIndex; +} diff --git a/src/validators/DTD/DFAContentModel.hpp b/src/validators/DTD/DFAContentModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ba0d3d7cde51564ffe50e8d48236f459fd7c35a0 --- /dev/null +++ b/src/validators/DTD/DFAContentModel.hpp @@ -0,0 +1,237 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:19 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:38 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(DFACONTENTMODEL_HPP) +#define DFACONTENTMODEL_HPP + +#include <util/XML4CDefs.hpp> +#include <framework/XMLContentModel.hpp> + +class ContentSpecNode; +class CMLeaf; +class CMNode; +class CMStateSet; +class DTDElementDecl; + +// +// DFAContentModel is the heavy weight derivative of ContentModel that does +// all of the non-trivial element content validation. This guy does the full +// bore regular expression to DFA conversion to create a DFA that it then +// uses in its validation algorithm. +// +// NOTE: Upstream work insures that this guy will never see a content model +// with PCDATA in it. Any model with PCDATA is 'mixed' and is handled +// via the MixedContentModel class, since mixed models are very +// constrained in form and easily handled via a special case. This +// also makes our life much easier here. +// +class DFAContentModel : public XMLContentModel +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DFAContentModel(const DTDElementDecl& elemDecl); + virtual ~DFAContentModel(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual content model interface + // ----------------------------------------------------------------------- + virtual bool getIsAmbiguous() const; + virtual int validateContent + ( + const unsigned int* childIds + , const unsigned int childCount + ) const; + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + DFAContentModel(); + DFAContentModel(const DFAContentModel&); + void operator=(const DFAContentModel&); + + + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + void buildDFA(); + CMNode* buildSyntaxTree(const ContentSpecNode* const curNode); + void calcFollowList(CMNode* const curNode); + bool isAmbiguous() const; + unsigned int* makeDefStateList() const; + int postTreeBuildInit + ( + CMNode* const nodeCur + , const unsigned int curIndex + ); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fElemDecl + // The element decl object of the element that this is the content + // model for. Its just stored here to avoid passing it around all + // over the place while building up the DFA. + // + // fElemMap + // fElemMapSize + // This is the map of unique input symbol elements to indices into + // each state's per-input symbol transition table entry. This is part + // of the built DFA information that must be kept around to do the + // actual validation. + // + // fEmptyOk + // This is an optimization. While building the transition table we + // can see whether this content model would approve of an empty + // content (which could happen if everything was optional.) So we + // set this flag and short circuit that check, which would otherwise + // be ugly and time consuming if we tried to determine it at each + // validation call. + // + // fEOCPos + // The NFA position of the special EOC (end of content) node. This + // is saved away since its used during the DFA build. + // + // fFinalStateFlags + // This is an array of booleans, one per state (there are + // fTransTableSize states in the DFA) that indicates whether that + // state is a final state. + // + // fFollowList + // The list of follow positions for each NFA position (i.e. for each + // non-epsilon leaf node.) This is only used during the building of + // the DFA, and is let go afterwards. + // + // fHeadNode + // This is the head node of our intermediate representation. It is + // only non-null during the building of the DFA (just so that it + // does not have to be passed all around.) Once the DFA is built, + // this is no longer required so its deleted. + // + // fIsAmbiguous + // This flag is set during construction if the content model is + // ambiguous. This will be used by the scanner to report an error + // and is available for later perusal if required. + // + // fLeafCount + // The count of leaf nodes. This is an important number that set some + // limits on the sizes of data structures in the DFA process. + // + // fLeafList + // An array of non-epsilon leaf nodes, which is used during the DFA + // build operation, then dropped. These are just references to nodes + // pointed to by fHeadNode, so we don't have to clean them up, just + // the actually leaf list array itself needs cleanup. + // + // fSpecNode + // The content spec node for the element that this object represents + // the content of. This info is needed a good bit so we get it once + // and keep it. We don't own it, we just reference it. + // + // fTransTable + // fTransTableSize + // This is the transition table that is the main by product of all + // of the effort here. It is an array of arrays of ints. The first + // dimension is the number of states we end up with in the DFA. The + // second dimensions is the number of unique elements in the content + // model (fElemMapSize). Each entry in the second dimension indicates + // the new state given that input for the first dimension's start + // state. + // + // The fElemMap array handles mapping from element indexes to + // positions in the second dimension of the transition table. + // + // fTransTableSize is the number of valid entries in the transition + // table, and in the other related tables such as fFinalStateFlags. + // ----------------------------------------------------------------------- + const DTDElementDecl& fElemDecl; + unsigned int* fElemMap; + unsigned int fElemMapSize; + bool fEmptyOk; + unsigned int fEOCPos; + bool* fFinalStateFlags; + CMStateSet** fFollowList; + CMNode* fHeadNode; + bool fIsAmbiguous; + unsigned int fLeafCount; + CMLeaf** fLeafList; + const ContentSpecNode* fSpecNode; + unsigned int** fTransTable; + unsigned int fTransTableSize; +}; + + +inline bool DFAContentModel::getIsAmbiguous() const +{ + return fIsAmbiguous; +} + +#endif diff --git a/src/validators/DTD/DTDAttDef.cpp b/src/validators/DTD/DTDAttDef.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2fceaba21f26f07148820ef9303bd8094acf6410 --- /dev/null +++ b/src/validators/DTD/DTDAttDef.cpp @@ -0,0 +1,121 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:24 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:39 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <framework/XMLElementDecl.hpp> +#include <validators/DTD/DTDAttDef.hpp> + + +// --------------------------------------------------------------------------- +// DTDAttDef: Constructors and Destructor +// --------------------------------------------------------------------------- +DTDAttDef::DTDAttDef() : + + fElemId(XMLElementDecl::fgInvalidElemId) + , fName(0) +{ +} + +DTDAttDef::DTDAttDef(const XMLCh* const attName + , const XMLAttDef::AttTypes type + , const XMLAttDef::DefAttTypes defType) : + XMLAttDef(type, defType) + , fElemId(XMLElementDecl::fgInvalidElemId) + , fName(0) +{ + fName = XMLString::replicate(attName); +} + +DTDAttDef::DTDAttDef( const XMLCh* const attName + , const XMLCh* const attValue + , const XMLAttDef::AttTypes type + , const XMLAttDef::DefAttTypes defType + , const XMLCh* const enumValues) : + + XMLAttDef(attValue, type, defType, enumValues) + , fElemId(XMLElementDecl::fgInvalidElemId) + , fName(0) +{ + fName = XMLString::replicate(attName); +} + +DTDAttDef::~DTDAttDef() +{ + delete [] fName; +} + + +// --------------------------------------------------------------------------- +// DTDAttDef: Setter methods +// --------------------------------------------------------------------------- +void DTDAttDef::setName(const XMLCh* const newName) +{ + delete [] fName; + fName = XMLString::replicate(newName); +} diff --git a/src/validators/DTD/DTDAttDef.hpp b/src/validators/DTD/DTDAttDef.hpp new file mode 100644 index 0000000000000000000000000000000000000000..467df25f35670c76c5822aaa4f143786654ac9d9 --- /dev/null +++ b/src/validators/DTD/DTDAttDef.hpp @@ -0,0 +1,171 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:26 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:39 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#if !defined(DTDATTDEF_HPP) +#define DTDATTDEF_HPP + +#include <util/XMLString.hpp> +#include <framework/XMLAttDef.hpp> + + +// +// This class is a derivative of the core XMLAttDef class. This class adds +// any DTD specific data members and provides DTD specific implementations +// of any underlying attribute def virtual methods. +// +// In the DTD we don't do namespaces, so the attribute names are just the +// QName literally from the DTD. This is what we return as the full name, +// which is what is used to key these in any name keyed collections. +// +class VALIDATORS_EXPORT DTDAttDef : public XMLAttDef +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructors + // ----------------------------------------------------------------------- + DTDAttDef(); + DTDAttDef + ( + const XMLCh* const attName + , const XMLAttDef::AttTypes type = CData + , const XMLAttDef::DefAttTypes defType = Implied + ); + DTDAttDef + ( + const XMLCh* const attName + , const XMLCh* const attValue + , const XMLAttDef::AttTypes type + , const XMLAttDef::DefAttTypes defType + , const XMLCh* const enumValues = 0 + ); + ~DTDAttDef(); + + + // ----------------------------------------------------------------------- + // Implementation of the XMLAttDef interface + // ----------------------------------------------------------------------- + virtual const XMLCh* getFullName() const; + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + unsigned int getElemId() const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setElemId(const unsigned int newId); + void setName(const XMLCh* const newName); + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fElemId + // This is the id of the element (the id is into the element decl + // pool) of the element this attribute def said it belonged to. + // This is used later to link back to the element, mostly for + // validation purposes. + // + // fName + // This is the name of the attribute. Since we don't do namespaces + // in the DTD, its just the fully qualified name. + // ----------------------------------------------------------------------- + unsigned int fElemId; + XMLCh* fName; +}; + + +// --------------------------------------------------------------------------- +// DTDAttDef: Implementation of the XMLAttDef interface +// --------------------------------------------------------------------------- +inline const XMLCh* DTDAttDef::getFullName() const +{ + return fName; +} + + +// --------------------------------------------------------------------------- +// DTDAttDef: Getter methods +// --------------------------------------------------------------------------- +inline unsigned int DTDAttDef::getElemId() const +{ + return fElemId; +} + + +// --------------------------------------------------------------------------- +// DTDAttDef: Setter methods +// --------------------------------------------------------------------------- +inline void DTDAttDef::setElemId(const unsigned int newId) +{ + fElemId = newId; +} + +#endif diff --git a/src/validators/DTD/DTDAttDefList.cpp b/src/validators/DTD/DTDAttDefList.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f709e2b9eb803ff1f5afa9cb8731dc15a365cefe --- /dev/null +++ b/src/validators/DTD/DTDAttDefList.cpp @@ -0,0 +1,149 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:27 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:39 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <validators/DTD/DTDAttDefList.hpp> + + +// --------------------------------------------------------------------------- +// DTDAttDefList: Constructors and Destructor +// --------------------------------------------------------------------------- +DTDAttDefList::DTDAttDefList(RefHashTableOf<DTDAttDef>* const listToUse) : + + fEnum(0) + , fList(listToUse) +{ + fEnum = new RefHashTableOfEnumerator<DTDAttDef>(listToUse); +} + +DTDAttDefList::~DTDAttDefList() +{ + delete fEnum; +} + + +// --------------------------------------------------------------------------- +// DTDAttDefList: Implementation of the virtual interface +// --------------------------------------------------------------------------- +bool DTDAttDefList::hasMoreElements() const +{ + return fEnum->hasMoreElements(); +} + + +bool DTDAttDefList::isEmpty() const +{ + return fList->isEmpty(); +} + + +XMLAttDef* DTDAttDefList::findAttDef(const unsigned long uriID + , const XMLCh* const attName) +{ + // We don't use the URI, so we just look up the name + return fList->get(attName); +} + + +const XMLAttDef* +DTDAttDefList::findAttDef( const unsigned long uriID + , const XMLCh* const attName) const +{ + // We don't use the URI, so we just look up the name + return fList->get(attName); +} + + +XMLAttDef* DTDAttDefList::findAttDef( const XMLCh* const attURI + , const XMLCh* const attName) +{ + // We don't use the URI, so we just look up the name + return fList->get(attName); +} + + +const XMLAttDef* +DTDAttDefList::findAttDef( const XMLCh* const attURI + , const XMLCh* const attName) const +{ + // We don't use the URI, so we just look up the name + return fList->get(attName); +} + + +XMLAttDef& DTDAttDefList::nextElement() +{ + return fEnum->nextElement(); +} + + +void DTDAttDefList::Reset() +{ + fEnum->Reset(); +} diff --git a/src/validators/DTD/DTDAttDefList.hpp b/src/validators/DTD/DTDAttDefList.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4c44fad0974ad3013759c7daa09d037dcc0ff425 --- /dev/null +++ b/src/validators/DTD/DTDAttDefList.hpp @@ -0,0 +1,151 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:28 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:39 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(DTDATTDEFLIST_HPP) +#define DTDATTDEFLIST_HPP + +#include <util/RefHashTableOf.hpp> +#include <validators/DTD/DTDElementDecl.hpp> + + +// +// This is a derivative of the framework abstract class which defines the +// interface to a list of attribute defs that belong to a particular +// element. The scanner needs to be able to get a list of the attributes +// that an element supports, for use during the validation process and for +// fixed/default attribute processing. +// +// Since each validator can store attributes differently, this abstract +// interface allows each validator to provide an implementation of this +// data strucure that works best for it. +// +// For us, we just wrap the RefHashTableOf collection that the DTDElementDecl +// class uses to store the attributes that belong to it. +// +// This clss does not adopt the hash table, it just references it. The +// hash table is owned by the element decl it is a member of. +// +class DTDAttDefList : public XMLAttDefList +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DTDAttDefList + ( + RefHashTableOf<DTDAttDef>* const listToUse + ); + + ~DTDAttDefList(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual interface + // ----------------------------------------------------------------------- + virtual bool hasMoreElements() const; + virtual bool isEmpty() const; + virtual XMLAttDef* findAttDef + ( + const unsigned long uriID + , const XMLCh* const attName + ); + virtual const XMLAttDef* findAttDef + ( + const unsigned long uriID + , const XMLCh* const attName + ) const; + virtual XMLAttDef* findAttDef + ( + const XMLCh* const attURI + , const XMLCh* const attName + ); + virtual const XMLAttDef* findAttDef + ( + const XMLCh* const attURI + , const XMLCh* const attName + ) const; + virtual XMLAttDef& nextElement(); + virtual void Reset(); + + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fEnum + // This is an enerator for the list that we use to do the enumerator + // type methods of this class. + // + // fList + // The list of DTDAttDef objects that represent the attributes that + // a particular element supports. + // ----------------------------------------------------------------------- + RefHashTableOfEnumerator<DTDAttDef>* fEnum; + RefHashTableOf<DTDAttDef>* fList; +}; + +#endif diff --git a/src/validators/DTD/DTDElementDecl.cpp b/src/validators/DTD/DTDElementDecl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c058ecce567c8baeb1512deb0b2cf0345a776906 --- /dev/null +++ b/src/validators/DTD/DTDElementDecl.cpp @@ -0,0 +1,412 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:29 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:39 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> +#include <framework/XMLBuffer.hpp> +#include <validators/DTD/DTDAttDefList.hpp> +#include <validators/DTD/DFAContentModel.hpp> +#include <validators/DTD/DTDElementDecl.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/MixedContentModel.hpp> +#include <validators/DTD/SimpleContentModel.hpp> + + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Destructor is out of line to prevent having to expose +// the ContentSpecNode header. +// --------------------------------------------------------------------------- +DTDElementDecl::~DTDElementDecl() +{ + delete fAttDefs; + delete fAttList; + delete [] fBaseName; + delete fContentSpec; + delete [] fQName; +} + + + +// --------------------------------------------------------------------------- +// The virtual element decl interface +// --------------------------------------------------------------------------- +XMLAttDef* DTDElementDecl::findAttr(const XMLCh* const qName + , const unsigned int uriId + , const XMLCh* const baseName + , const LookupOpts options + , bool& wasAdded) const +{ + DTDAttDef* retVal = 0; + + // If no att list faulted in yet, then it cannot exist + if (fAttDefs) + retVal = fAttDefs->get(qName); + + // Fault it in if not found and ask to add it + if (!retVal && (options == XMLElementDecl::AddIfNotFound)) + { + // Fault in the list itself if not already + if (!fAttDefs) + faultInAttDefList(); + + // And add a default attribute for this name + retVal = new DTDAttDef(qName); + retVal->setElemId(getId()); + fAttDefs->put(retVal); + + wasAdded = true; + } + else + { + wasAdded = false; + } + return retVal; +} + + +XMLAttDefList& DTDElementDecl::getAttDefList() const +{ + if (!fAttList) + { + // If the att def list is not made yet, then fault it in too + if (!fAttDefs) + faultInAttDefList(); + + ((DTDElementDecl*)this)->fAttList = new DTDAttDefList(fAttDefs); + } + + // Reset it before we return it + fAttList->Reset(); + return *fAttList; +} + + +const XMLCh* DTDElementDecl::getBaseName() const +{ + // + // If the base name nas not been extraced, then do it now. Since we are + // faulting it in from a const method, we have to cast off the constness. + // + if (!fBaseName) + { + // + // Search for the first colon in the name. Note that, if its not + // found, then it will be -1, which will still make the replicate + // logic work correctly. + // + int colonPos = XMLString::indexOf(fQName, chColon); + ((DTDElementDecl*)this)->fBaseName = XMLString::replicate(&fQName[colonPos + 1]); + } + + // Just return our QName + return fBaseName; +} + + +XMLElementDecl::CharDataOpts DTDElementDecl::getCharDataOpts() const +{ + XMLElementDecl::CharDataOpts retVal; + switch(fModelType) + { + case Children : + retVal = XMLElementDecl::SpacesOk; + break; + + case Empty : + retVal = XMLElementDecl::NoCharData; + break; + + default : + retVal = XMLElementDecl::AllCharData; + break; + } + return retVal; +} + + +bool DTDElementDecl::hasAttDefs() const +{ + // If the collection hasn't been faulted in, then no att defs + if (!fAttDefs) + return false; + + return !fAttDefs->isEmpty(); +} + + +bool DTDElementDecl::resetDefs() +{ + // If the collection hasn't been faulted in, then no att defs + if (!fAttDefs) + return false; + + // + // Ok, run through them and clear the 'provided' flag on each of them. + // This lets the scanner use them to track which has been provided and + // which have not. + // + RefHashTableOfEnumerator<DTDAttDef> enumDefs(fAttDefs); + while (enumDefs.hasMoreElements()) + enumDefs.nextElement().setProvided(false); + return true; +} + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Getter methods +// --------------------------------------------------------------------------- +const DTDAttDef* DTDElementDecl::getAttDef(const XMLCh* const attName) const +{ + // If no list, then return a null + if (!fAttDefs) + return 0; + + return fAttDefs->get(attName); +} + + +DTDAttDef* DTDElementDecl::getAttDef(const XMLCh* const attName) +{ + // If no list, then return a null + if (!fAttDefs) + return 0; + + return fAttDefs->get(attName); +} + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Setter methods +// --------------------------------------------------------------------------- +void DTDElementDecl::setContentSpec(ContentSpecNode* toAdopt) +{ + delete fContentSpec; + fContentSpec = toAdopt; +} + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Implementation of the protected virtual interface +// --------------------------------------------------------------------------- +void DTDElementDecl::addAttDef(DTDAttDef* const toAdd) +{ + // Fault in the att list if required + if (!fAttDefs) + faultInAttDefList(); + + // Tell this guy the element id of its parent (us) + toAdd->setElemId(getId()); + + fAttDefs->put(toAdd); +} + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Implementation of the protected virtual interface +// --------------------------------------------------------------------------- +XMLCh* +DTDElementDecl::formatContentModel(const XMLValidator& validator) const +{ + XMLCh* newValue = 0; + if (fModelType == Any) + { + newValue = XMLString::replicate(XMLUni::fgAnyString); + } + else if (fModelType == Empty) + { + newValue = XMLString::replicate(XMLUni::fgEmptyString); + } + else + { + // + // Use a temp XML buffer to format into. Content models could be + // pretty long, but very few will be longer than one K. The buffer + // will expand to handle the more pathological ones. + // + XMLBuffer bufFmt; + fContentSpec->formatSpec(validator, bufFmt); + newValue = XMLString::replicate(bufFmt.getRawBuffer()); + } + return newValue; +} + +XMLContentModel* DTDElementDecl::makeContentModel() const +{ + XMLContentModel* cmRet = 0; + if (fModelType == Mixed) + { + // + // Just create a mixel content model object. This type of + // content model is optimized for mixed content validation. + // + cmRet = new MixedContentModel(*this); + } + else if (fModelType == Children) + { + // + // This method will create an optimal model for the complexity + // of the element's defined model. If its simple, it will create + // a SimpleContentModel object. If its a simple list, it will + // create a SimpleListContentModel object. If its complex, it + // will create a DFAContentModel object. + // + cmRet = createChildModel(); + } + else + { + ThrowXML(RuntimeException, XML4CExcepts::CM_MustBeMixedOrChildren); + } + return cmRet; +} + + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Private helper methods +// --------------------------------------------------------------------------- +XMLContentModel* DTDElementDecl::createChildModel() const +{ + // Get the content spec node of the element + const ContentSpecNode* specNode = getContentSpec(); + + // + // Do a sanity check that the node is does not have a PCDATA id. Since, + // if it was, it should have already gotten taken by the Mixed model. + // + if (specNode->getElemId() == XMLElementDecl::fgPCDataElemId) + ThrowXML(RuntimeException, XML4CExcepts::CM_NoPCDATAHere); + + // + // According to the type of node, we will create the correct type of + // content model. + // + if (specNode->getType() == ContentSpecNode::Leaf) + { + // Create a simple content model + return new SimpleContentModel + ( + specNode->getElemId() + , XMLElementDecl::fgInvalidElemId + , ContentSpecNode::Leaf + ); + } + else if ((specNode->getType() == ContentSpecNode::Choice) + || (specNode->getType() == ContentSpecNode::Sequence)) + { + // + // Lets see if both of the children are leafs. If so, then it has to + // be a simple content model + // + if ((specNode->getFirst()->getType() == ContentSpecNode::Leaf) + && (specNode->getSecond()->getType() == ContentSpecNode::Leaf)) + { + return new SimpleContentModel + ( + specNode->getFirst()->getElemId() + , specNode->getSecond()->getElemId() + , specNode->getType() + ); + } + } + else if ((specNode->getType() == ContentSpecNode::OneOrMore) + || (specNode->getType() == ContentSpecNode::ZeroOrMore) + || (specNode->getType() == ContentSpecNode::ZeroOrOne)) + { + // + // Its a repetition, so see if its one child is a leaf. If so its a + // repetition of a single element, so we can do a simple content + // model for that. + // + if (specNode->getFirst()->getType() == ContentSpecNode::Leaf) + { + return new SimpleContentModel + ( + specNode->getFirst()->getElemId() + , XMLElementDecl::fgInvalidElemId + , specNode->getType() + ); + } + } + else + { + ThrowXML(RuntimeException, XML4CExcepts::CM_UnknownCMSpecType); + } + + // Its not any simple type of content, so create a DFA based content model + return new DFAContentModel(*this); +} + + +void DTDElementDecl::faultInAttDefList() const +{ + // Use a hash modulus of 29 and tell it owns its elements + ((DTDElementDecl*)this)->fAttDefs = new RefHashTableOf<DTDAttDef>(29, true); +} diff --git a/src/validators/DTD/DTDElementDecl.hpp b/src/validators/DTD/DTDElementDecl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..18dcb1218bd06a7da01fedb4d68ad05d1f1b4d7a --- /dev/null +++ b/src/validators/DTD/DTDElementDecl.hpp @@ -0,0 +1,291 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:32 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:40 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(DTDELEMENTDECL_HPP) +#define DTDELEMENTDECL_HPP + +#include <util/RefHashTableOf.hpp> +#include <framework/XMLElementDecl.hpp> +#include <validators/DTD/DTDAttDef.hpp> + +class ContentSpecNode; +class DTDAttDefList; + + +// +// This class is a derivative of the basic element decl. This one implements +// the virtuals so that they work for a DTD. THe big difference is that +// they don't live in any URL in the DTD. The names are just stored as full +// QNames, so they are not split out and element decls don't live within +// URL namespaces or anything like that. +// +class VALIDATORS_EXPORT DTDElementDecl : public XMLElementDecl +{ +public : + // ----------------------------------------------------------------------- + // Class specific types + // + // ModelTypes + // Indicates the type of content model that an element has. This + // indicates how the content model is represented and validated. + // ----------------------------------------------------------------------- + enum ModelTypes + { + Empty + , Any + , Mixed + , Children + + , ModelTypes_Count + }; + + + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DTDElementDecl(); + + DTDElementDecl + ( + const XMLCh* const elemQName + , const ModelTypes modelType = Any + ); + + ~DTDElementDecl(); + + + // ----------------------------------------------------------------------- + // The virtual element decl interface + // ----------------------------------------------------------------------- + virtual XMLAttDef* findAttr + ( + const XMLCh* const qName + , const unsigned int uriId + , const XMLCh* const baseName + , const LookupOpts options + , bool& wasAdded + ) const; + virtual XMLAttDefList& getAttDefList() const; + virtual const XMLCh* getBaseName() const; + virtual CharDataOpts getCharDataOpts() const; + virtual const XMLCh* getFullName() const; + virtual bool hasAttDefs() const; + virtual bool resetDefs(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + const DTDAttDef* getAttDef(const XMLCh* const attName) const; + DTDAttDef* getAttDef(const XMLCh* const attName); + ContentSpecNode* getContentSpec(); + const ContentSpecNode* getContentSpec() const; + DTDElementDecl::ModelTypes getModelType() const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void addAttDef(DTDAttDef* const toAdd); + void setContentSpec(ContentSpecNode* toAdopt); + void setModelType(const DTDElementDecl::ModelTypes toSet); + void setName(const XMLCh* const newName); + + +protected : + // ----------------------------------------------------------------------- + // Protected, virtual methods + // ----------------------------------------------------------------------- + virtual XMLContentModel* makeContentModel() const; + virtual XMLCh* formatContentModel + ( + const XMLValidator& validator + ) const; + + +private : + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + XMLContentModel* createChildModel() const; + void faultInAttDefList() const; + + + // ----------------------------------------------------------------------- + // Private data members + // + // fAttDefs + // The list of attributes that are defined for this element. Each + // element is its own little 'namespace' for attributes, so each + // element maintains its own list of owned attribute defs. It is + // faulted in when an attribute is actually added. + // + // fAttList + // We have to return a view of our att defs via the abstract view + // that the scanner understands. It may or may not ever be asked + // for so we fault it in as needed. + // + // fBaseName + // This is faulted in upon demand from the fQName field. + // + // fContentSpec + // This is the content spec for the node. It contains the original + // content spec that was read from the DTD, as a tree of nodes. This + // one is always set up, and is used to build the fContentModel + // version if we are validating. + // + // fQName + // This is the name of the element decl. Its just a QName that may + // or may not have a prefix: part. We don't care if it does or not. + // DTDs have no means of assigning namespaces to decls, so we don't + // have any concerns about that stuff at all. + // + // fModelType + // The content model type of this element. This tells us what kind + // of content model to create. + // ----------------------------------------------------------------------- + RefHashTableOf<DTDAttDef>* fAttDefs; + DTDAttDefList* fAttList; + XMLCh* fBaseName; + ContentSpecNode* fContentSpec; + XMLCh* fQName; + ModelTypes fModelType; +}; + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Constructors and Destructor +// --------------------------------------------------------------------------- +inline DTDElementDecl::DTDElementDecl() : + + fAttDefs(0) + , fAttList(0) + , fBaseName(0) + , fContentSpec(0) + , fQName(0) + , fModelType(Any) +{ +} + +inline +DTDElementDecl::DTDElementDecl( const XMLCh* const elemName + , const DTDElementDecl::ModelTypes type) : + fAttDefs(0) + , fAttList(0) + , fBaseName(0) + , fContentSpec(0) + , fQName(XMLString::replicate(elemName)) + , fModelType(type) +{ +} + + +// --------------------------------------------------------------------------- +// DTDElementDecl: XMLElementDecl virtual interface implementation +// --------------------------------------------------------------------------- +inline const XMLCh* DTDElementDecl::getFullName() const +{ + // Just return our QName + return fQName; +} + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Getter methods +// --------------------------------------------------------------------------- +inline ContentSpecNode* DTDElementDecl::getContentSpec() +{ + return fContentSpec; +} + +inline const ContentSpecNode* DTDElementDecl::getContentSpec() const +{ + return fContentSpec; +} + +inline DTDElementDecl::ModelTypes DTDElementDecl::getModelType() const +{ + return fModelType; +} + + +// --------------------------------------------------------------------------- +// DTDElementDecl: Setter methods +// --------------------------------------------------------------------------- +inline void +DTDElementDecl::setModelType(const DTDElementDecl::ModelTypes toSet) +{ + fModelType = toSet; +} + +inline void DTDElementDecl::setName(const XMLCh* const newName) +{ + delete [] fQName; + fQName = XMLString::replicate(newName); +} + +#endif diff --git a/src/validators/DTD/DTDEntityDecl.hpp b/src/validators/DTD/DTDEntityDecl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..98d7da8ba91f742b8cb99015812738605c6c4e4f --- /dev/null +++ b/src/validators/DTD/DTDEntityDecl.hpp @@ -0,0 +1,238 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:34 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:40 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(DTDENTITYDECL_HPP) +#define DTDENTITYDECL_HPP + +#include <framework/XMLEntityDecl.hpp> + + +// +// This is a derivative of the abstract version of an entity decl in the +// framework directory. We just need to provide implementation of a couple +// of methods. +// +class VALIDATORS_EXPORT DTDEntityDecl : public XMLEntityDecl +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DTDEntityDecl(); + DTDEntityDecl + ( + const XMLCh* const entName + , const bool fromIntSubset = false + ); + DTDEntityDecl + ( + const XMLCh* const entName + , const XMLCh* const value + , const bool fromIntSubset = false + ); + DTDEntityDecl + ( + const XMLCh* const entName + , const XMLCh value + , const bool fromIntSubset = false + , const bool specialChar = false + ); + ~DTDEntityDecl(); + + + // ----------------------------------------------------------------------- + // Implementation of the virtual XMLEntityDecl interface + // ----------------------------------------------------------------------- + virtual bool getDeclaredInIntSubset() const; + virtual bool getIsParameter() const; + virtual bool getIsSpecialChar() const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + const void setDeclaredInIntSubset(const bool newValue); + void setIsParameter(const bool newValue); + void setIsSpecialChar(const bool newValue); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + DTDEntityDecl(const DTDEntityDecl&); + void operator=(DTDEntityDecl&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fDeclaredInIntSubset + // Indicates whether the entity was declared in the internal subset + // or not. If not, it cannot be referred to from a standalone + // document. + // + // fIsParameter + // Indicates whether this is a parameter entity or a general entity. + // + // fIsSpecialChar + // This indicates that its one of the special character entities, + // e.g. lt or gt or amp. We need to know this because there are + // places where only a numeric char ref or special char ref is valid + // and all others are ignored or illegal. + // ----------------------------------------------------------------------- + bool fDeclaredInIntSubset; + bool fIsParameter; + bool fIsSpecialChar; +}; + + +// --------------------------------------------------------------------------- +// DTDEntityDecl: Constructors and Destructor +// --------------------------------------------------------------------------- +inline DTDEntityDecl::DTDEntityDecl() : + + fDeclaredInIntSubset(false) + , fIsParameter(false) + , fIsSpecialChar(false) +{ +} + +inline DTDEntityDecl::DTDEntityDecl(const XMLCh* const entName + , const bool fromIntSubset) : + + XMLEntityDecl(entName) + , fDeclaredInIntSubset(fromIntSubset) + , fIsParameter(false) + , fIsSpecialChar(false) +{ +} + +inline DTDEntityDecl::DTDEntityDecl(const XMLCh* const entName + , const XMLCh* const value + , const bool fromIntSubset) : + XMLEntityDecl(entName, value) + , fDeclaredInIntSubset(fromIntSubset) + , fIsParameter(false) + , fIsSpecialChar(false) +{ +} + +inline DTDEntityDecl::DTDEntityDecl(const XMLCh* const entName + , const XMLCh value + , const bool fromIntSubset + , const bool specialChar) : + XMLEntityDecl(entName, value) + , fDeclaredInIntSubset(fromIntSubset) + , fIsParameter(false) + , fIsSpecialChar(specialChar) +{ +} + +inline DTDEntityDecl::~DTDEntityDecl() +{ +} + + +// --------------------------------------------------------------------------- +// DTDEntityDecl: Getter methods +// --------------------------------------------------------------------------- +inline bool DTDEntityDecl::getDeclaredInIntSubset() const +{ + return fDeclaredInIntSubset; +} + +inline bool DTDEntityDecl::getIsParameter() const +{ + return fIsParameter; +} + +inline bool DTDEntityDecl::getIsSpecialChar() const +{ + return fIsSpecialChar; +} + + +// --------------------------------------------------------------------------- +// DTDEntityDecl: Setter methods +// --------------------------------------------------------------------------- +inline const void DTDEntityDecl::setDeclaredInIntSubset(const bool newValue) +{ + fDeclaredInIntSubset = newValue; +} + +inline void DTDEntityDecl::setIsParameter(const bool newValue) +{ + fIsParameter = newValue; +} + +inline void DTDEntityDecl::setIsSpecialChar(const bool newValue) +{ + fIsSpecialChar = newValue; +} + +#endif diff --git a/src/validators/DTD/DTDValidator.cpp b/src/validators/DTD/DTDValidator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1bb0806546d166d2d192e5ac3dac9ee983612d43 --- /dev/null +++ b/src/validators/DTD/DTDValidator.cpp @@ -0,0 +1,944 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:35 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:40 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/Janitor.hpp> +#include <util/XMLMsgLoader.hpp> +#include <util/XMLUni.hpp> +#include <internal/ReaderMgr.hpp> +#include <internal/XMLScanner.hpp> +#include <framework/XMLBuffer.hpp> +#include <framework/XMLContentModel.hpp> +#include <framework/XMLElementDecl.hpp> +#include <framework/XMLEntityDecl.hpp> +#include <framework/XMLNotationDecl.hpp> +#include <validators/DTD/DTDValidator.hpp> +#include <validators/DTD/DocTypeHandler.hpp> + + +// --------------------------------------------------------------------------- +// Local const data +// +// These are the text for the require char refs that must always be present. +// We init these into the entity pool upon construction. +// --------------------------------------------------------------------------- +static const XMLCh gAmp[] = { chLatin_a, chLatin_m, chLatin_p, chNull }; +static const XMLCh gLT[] = { chLatin_l, chLatin_t, chNull }; +static const XMLCh gGT[] = { chLatin_g, chLatin_t, chNull }; +static const XMLCh gQuot[] = { chLatin_q, chLatin_u, chLatin_o, chLatin_t, chNull }; +static const XMLCh gApos[] = { chLatin_a, chLatin_p, chLatin_o, chLatin_s, chNull }; + + + +// --------------------------------------------------------------------------- +// Local methods +// --------------------------------------------------------------------------- + +// +// This method is called when we get a notation or enumeration type attribute +// to validate. We have to confirm that the passed value to find is one of +// the values in the passed list. The list is a space separated string of +// values to match against. +// +static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList) +{ + // + // We loop through the values in the list via this outer loop. We end + // when we hit the end of the enum list or get a match. + // + const XMLCh* listPtr = enumList; + const unsigned int findLen = XMLString::stringLen(toFind); + while (*listPtr) + { + unsigned int testInd; + for (testInd = 0; testInd < findLen; testInd++) + { + // + // If they don't match, then reset and try again. Note that + // hitting the end of the current item will cause a mismatch + // because there can be no spaces in the toFind string. + // + if (listPtr[testInd] != toFind[testInd]) + break; + } + + // + // If we went the distance, see if we matched. If we did, the current + // list character has to be null or space. + // + if (testInd == findLen) + { + if ((listPtr[testInd] == chSpace) || !listPtr[testInd]) + return true; + } + + // Run the list pointer up to the next substring + while ((*listPtr != chSpace) && *listPtr) + listPtr++; + + // If we hit the end, then we failed + if (!*listPtr) + return false; + + // Else move past the space and try again + listPtr++; + } + + // We never found it + return false; +} + + + +// --------------------------------------------------------------------------- +// DTDValidator: Constructors and Destructor +// --------------------------------------------------------------------------- +DTDValidator::DTDValidator(XMLErrorReporter* const errReporter) : + + XMLValidator(errReporter) + , fDocTypeHandler(0) + , fDumAttDef(0) + , fDumElemDecl(0) + , fDumEntityDecl(0) + , fElemDeclPool(0) + , fEntityDeclPool(0) + , fInternalSubset(false) + , fNextAttrId(1) + , fNotationDeclPool(0) + , fPEntityDeclPool(0) + , fRootElemId(XMLElementDecl::fgInvalidElemId) +{ + // + // Init all the pool members. + // + // <TBD> Investigate what the optimum values would be for the various + // pools. + // + fElemDeclPool = new NameIdPool<DTDElementDecl>(109); + fEntityDeclPool = new NameIdPool<DTDEntityDecl>(109); + fNotationDeclPool = new NameIdPool<XMLNotationDecl>(109); + fPEntityDeclPool = new NameIdPool<DTDEntityDecl>(109); + + // + // Call our own reset method. This lets us have the pool setup stuff + // done in just one place (because this stame setup stuff has to be + // done every time we are reset.) + // + reset(); +} + +DTDValidator::~DTDValidator() +{ + delete fDumAttDef; + delete fDumElemDecl; + delete fDumEntityDecl; + delete fElemDeclPool; + delete fEntityDeclPool; + delete fNotationDeclPool; + delete fPEntityDeclPool; +} + + +// --------------------------------------------------------------------------- +// DTDValidator: Pool manipulation methods +// --------------------------------------------------------------------------- +unsigned int DTDValidator::findElemId(const XMLCh* const qName) const +{ + // Look up this name in the element decl pool + const DTDElementDecl* decl = fElemDeclPool->getByKey(qName); + if (!decl) + return XMLElementDecl::fgInvalidElemId; + return decl->getId(); +} + + +// --------------------------------------------------------------------------- +// DTDValidator: Implementation of the XMLValidator interface +// --------------------------------------------------------------------------- +int DTDValidator::addOrFindNSId(const XMLCh* const uriText) +{ + return fURIStringPool.addOrFind(uriText); +} + + +int DTDValidator::checkContent( const unsigned int elemId + , const unsigned int* childIds + , const unsigned int childCount) +{ + // + // Look up the element id in our element decl pool. This will get us + // the element decl in our own way of looking at them. + // + DTDElementDecl* elemDecl = fElemDeclPool->getById(elemId); + if (!elemDecl) + ThrowXML(RuntimeException, XML4CExcepts::Val_InvalidElemId); + + // + // Get the content spec type of this element. This will tell us what + // to do to validate it. + // + const DTDElementDecl::ModelTypes modelType = elemDecl->getModelType(); + + if (modelType == DTDElementDecl::Empty) + { + // + // We can do this one here. It cannot have any children. If it does + // we return 0 as the index of the first bad child. + // + if (childCount) + return 0; + } + else if (modelType == DTDElementDecl::Any) + { + // We pass no judgement on this one, anything goes + } + else if ((modelType == DTDElementDecl::Mixed) + || (modelType == DTDElementDecl::Children)) + { + // Get the element's content model or fault it in + const XMLContentModel* elemCM = elemDecl->getContentModel(); + + // Ask it to validate and return its return + return elemCM->validateContent(childIds, childCount); + } + else + { + ThrowXML(RuntimeException, XML4CExcepts::CM_UnknownCMType); + } + + // Went ok, so return success + return XMLValidator::Success; +} + + +bool DTDValidator::checkRootElement(const unsigned int elemId) +{ + // + // If the root element was never set, then there was never a DOCTYPE. So + // we just return false. + // + if (fRootElemId == XMLElementDecl::fgInvalidElemId) + return false; + + // Else return true if our stored root element is the same as the passed one + return (elemId == fRootElemId); +} + + +void DTDValidator::faultInAttr(XMLAttr& toFill, const XMLAttDef& attDef) const +{ + // + // At this level, we cannot set the URI id. So we just set it to zero + // and leave it at that. The scanner, who called us, will look at the + // prefix we stored (if any), resolve it, and store the URL id if any. + // + const XMLCh* fullName = attDef.getFullName(); + const int colonInd = XMLString::indexOf(fullName, chColon); + if (colonInd == -1) + { + // There is no prefix, so we just do a simple and quick setting + toFill.set + ( + 0 + , fullName + , XMLUni::fgZeroLenString + , attDef.getValue() + , attDef.getType() + ); + } + else + { + // + // There is a colon, so we have to split apart the name and prefix + // part. + // + XMLBuffer bufTmp; + XMLCh* tmpNameBuf = XMLString::replicate(fullName); + ArrayJanitor<XMLCh> janNameBuf(tmpNameBuf); + + // Put a null where the colon is, to split it into two strings + tmpNameBuf[colonInd] = chNull; + + // + // And now we can set the attribute object with the prefix and name + // parts. + // + toFill.set + ( + 0 + , &tmpNameBuf[colonInd+1] + , tmpNameBuf + , attDef.getValue() + , attDef.getType() + ); + } +} + + +const XMLElementDecl* +DTDValidator::findElemDecl( const unsigned int uriId + , const XMLCh* const baseName + , const XMLCh* const qName + , const LookupOpts options + , bool& wasAdded) const +{ + // See it it exists + DTDElementDecl* retVal = fElemDeclPool->getByKey(qName); + + // If not, and they want us to add it, then fault one in + if (!retVal && (options == XMLValidator::AddIfNotFound)) + { + retVal = new DTDElementDecl(qName, DTDElementDecl::Any); + const unsigned int elemId = fElemDeclPool->put(retVal); + retVal->setId(elemId); + wasAdded = true; + } + else + { + wasAdded = false; + } + return retVal; +} + + +XMLElementDecl* +DTDValidator::findElemDecl( const unsigned int uriId + , const XMLCh* const baseName + , const XMLCh* const qName + , const LookupOpts options + , bool& wasAdded) +{ + // See it it exists + DTDElementDecl* retVal = fElemDeclPool->getByKey(qName); + + // If not, and they want us to add it, then fault one in + if (!retVal && (options == XMLValidator::AddIfNotFound)) + { + retVal = new DTDElementDecl(qName, DTDElementDecl::Any); + const unsigned int elemId = fElemDeclPool->put(retVal); + retVal->setId(elemId); + wasAdded = true; + } + else + { + wasAdded = false; + } + return retVal; +} + + +const XMLEntityDecl* +DTDValidator::findEntityDecl(const XMLCh* const entName + , const bool isPE) const +{ + if (isPE) + return fPEntityDeclPool->getByKey(entName); + return fEntityDeclPool->getByKey(entName); +} + + +XMLEntityDecl* DTDValidator::findEntityDecl(const XMLCh* const entName + , const bool isPE) +{ + if (isPE) + return fPEntityDeclPool->getByKey(entName); + return fEntityDeclPool->getByKey(entName); +} + + +unsigned int +DTDValidator::findElemId(const unsigned int uriId + , const XMLCh* const baseName + , const XMLCh* const qName) const +{ + // + // In this case, we don't return zero to mean 'not found', so we have to + // map it to the official not found value if we don't find it. + // + const DTDElementDecl* decl = fElemDeclPool->getByKey(qName); + if (!decl) + return XMLElementDecl::fgInvalidElemId; + return decl->getId(); +} + + +const XMLNotationDecl* +DTDValidator::findNotationDecl(const XMLCh* const notName) const +{ + return fNotationDeclPool->getByKey(notName); +} + + +XMLNotationDecl* DTDValidator::findNotationDecl(const XMLCh* const notName) +{ + return fNotationDeclPool->getByKey(notName); +} + + +unsigned int DTDValidator::findNSId(const XMLCh* const uriText) const +{ + // + // Look up the id for this one. It returns zero if not found, which is + // what we want to return. + // + return fURIStringPool.getId(uriText); +} + + +const XMLElementDecl* DTDValidator::getElemDecl(const unsigned int elemId) const +{ + // Look up this element decl by id + return fElemDeclPool->getById(elemId); +} + + +XMLElementDecl* DTDValidator::getElemDecl(const unsigned int elemId) +{ + // Look up this element decl by id + return fElemDeclPool->getById(elemId); +} + + +bool DTDValidator::getURIText( const unsigned int uriId + , XMLBuffer& uriBufToFill) const +{ + // Look up the URI in the string pool and return its id + const XMLCh* value = fURIStringPool.getValueForId(uriId); + if (!value) + return false; + + uriBufToFill.set(value); + return true; +} + + +void DTDValidator::postParseValidation() +{ + // + // At this time, there is nothing to do here. The scanner itself handles + // ID/IDREF validation, since that is the same no matter what kind of + // validator. + // +} + + +void DTDValidator::reset() +{ + // + // We need to reset all of the pools and a couple of the other members. + // The other stuff is not sensitive across uses of the validator. + // + fElemDeclPool->removeAll(); + fEntityDeclPool->removeAll(); + fInternalSubset = false; + fNotationDeclPool->removeAll(); + fPEntityDeclPool->removeAll(); + fURIStringPool.flushAll(); + fRootElemId = XMLElementDecl::fgInvalidElemId; + + // If there is a doc type handler, reset it + if (fDocTypeHandler) + fDocTypeHandler->resetDocType(); + + // + // Add some special URIs to the URI string pool. These represent special + // URIs that are predefined and don't come from the user data. We pass + // the ids to our base class who will store them and make them available + // to client code. + // + setBaseFields + ( + fURIStringPool.addOrFind(XMLUni::fgZeroLenString) + , fURIStringPool.addOrFind(XMLUni::fgGlobalNSURIName) + , fURIStringPool.addOrFind(XMLUni::fgUnknownURIName) + , fURIStringPool.addOrFind(XMLUni::fgXMLURIName) + , fURIStringPool.addOrFind(XMLUni::fgXMLNSURIName) + ); + + // + // Add the default entity entries for the character refs that must always + // be present. We indicate that they are from the internal subset. They + // aren't really, but they have to look that way so that they are still + // valid for use within a standalone document. + // + // We also mark them as special char entities, which allows them to be + // used in places whether other non-numeric general entities cannot. + // + fEntityDeclPool->put(new DTDEntityDecl(gAmp, chAmpersand, true, true)); + fEntityDeclPool->put(new DTDEntityDecl(gLT, chOpenAngle, true, true)); + fEntityDeclPool->put(new DTDEntityDecl(gGT, chCloseAngle, true, true)); + fEntityDeclPool->put(new DTDEntityDecl(gQuot, chDoubleQuote, true, true)); + fEntityDeclPool->put(new DTDEntityDecl(gApos, chSingleQuote, true, true)); +} + + +bool DTDValidator::requiresNamespaces() const +{ + // Namespaces are optional for DTDs + return false; +} + + +void +DTDValidator::validateAttrValue(const XMLAttDef& attDef + , const XMLCh* const attrValue) +{ + // + // Get quick refs to lost of of the stuff in the passed objects in + // order to simplify the code below, which will reference them very + // often. + // + const XMLAttDef::AttTypes type = attDef.getType(); + const XMLAttDef::DefAttTypes defType = attDef.getDefaultType(); + const XMLCh* const valueText = attDef.getValue(); + const XMLCh* const fullName = attDef.getFullName(); + const XMLCh* const enumList = attDef.getEnumeration(); + + // + // If the default type is fixed, then make sure the passed value maps + // to the fixed value. + // + if (defType == XMLAttDef::Fixed) + { + if (XMLString::compareString(attrValue, valueText)) + emitError(XML4CValid::NotSameAsFixedValue, fullName); + } + + // + // If its a CDATA attribute, then we are done with any DTD level + // validation else do the rest. + // + if (type == XMLAttDef::CData) + return; + + // An empty string cannot be valid for any of the other types + if (!attrValue[0]) + emitError(XML4CValid::InvalidEmptyAttValue, fullName); + + // See whether we are doing multiple values or not + const bool multipleValues = + ( + (type == XMLAttDef::IDRefs) + || (type == XMLAttDef::Entities) + || (type == XMLAttDef::NmTokens) + || (type == XMLAttDef::Notation) + || (type == XMLAttDef::Enumeration) + ); + + // And whether we must check for a first name char + const bool firstNameChar = + ( + (type == XMLAttDef::ID) + || (type == XMLAttDef::IDRef) + || (type == XMLAttDef::IDRefs) + || (type == XMLAttDef::Entity) + || (type == XMLAttDef::Entities) + || (type == XMLAttDef::Notation) + ); + + // Whether it requires ref checking stuff + const bool isARefType + ( + (type == XMLAttDef::ID) + || (type == XMLAttDef::IDRef) + || (type == XMLAttDef::IDRefs) + ); + + // Some trigger flags to avoid issuing redundant errors and whatnot + bool sawOneValue; + bool alreadyCapped = false; + + // + // Make a copy of the text that we can mangle and get a pointer we can + // move through the value + // + XMLCh* pszTmpVal = XMLString::replicate(attrValue); + ArrayJanitor<XMLCh> janTmpVal(pszTmpVal); + XMLCh* valPtr = pszTmpVal; + + while (true) + { + // Reset the trigger flags + sawOneValue = false; + + // + // Make sure the first character is a valid first name char, i.e. + // if its a Name value. For NmToken values we don't treat the first + // char any differently. + // + if (firstNameChar) + { + // If its not, emit and error but try to keep going + if (!XMLReader::isFirstNameChar(*valPtr)) + emitError(XML4CValid::AttrValNotName, fullName); + valPtr++; + } + + // Make sure all the remaining chars are valid name chars + while (*valPtr) + { + // + // If we hit a whitespace, its either a break between two + // or more values, or an error if we have a single value. + // + if (XMLReader::isWhitespace(*valPtr)) + { + if (!multipleValues) + { + emitError(XML4CValid::NoMultipleValues, fullName); + return; + } + break; + } + + if (!XMLReader::isNameChar(*valPtr)) + { + emitError(XML4CValid::AttrValNotName, fullName); + return; + } + valPtr++; + } + + // + // Cap it off at the current non-name char. If already capped, + // then remember this. + // + if (!(*valPtr)) + alreadyCapped = true; + *valPtr = 0; + + // + // If this type of attribute requires that we track reference + // stuff, then handle that. + // + if (isARefType) + { + if ((type == XMLAttDef::ID) + || (type == XMLAttDef::IDRef) + || (type == XMLAttDef::IDRefs)) + { + XMLRefInfo* find = getScanner()->getIDRefList().get(pszTmpVal); + if (find) + { + if (find->getDeclared() && (type == XMLAttDef::ID)) + emitError(XML4CValid::ReusedIDValue, pszTmpVal); + } + else + { + find = new XMLRefInfo(pszTmpVal); + getScanner()->getIDRefList().put(find); + } + + // + // Mark it declared or used, which might be redundant in some cases + // but not worth checking + // + if (type == XMLAttDef::ID) + find->setDeclared(true); + else + find->setUsed(true); + } + } + else if ((type == XMLAttDef::Entity) || (type == XMLAttDef::Entities)) + { + // + // If its refering to a entity, then look up the name in the + // general entity pool. If not there, then its an error. If its + // not an external unparsed entity, then its an error. + // + const XMLEntityDecl* decl = findEntityDecl(pszTmpVal, false); + if (decl) + { + if (!decl->isUnparsed()) + emitError(XML4CValid::BadEntityRefAttr, fullName); + } + else + { + emitError + ( + XML4CValid::UnknownEntityRefAttr + , fullName + , pszTmpVal + ); + } + } + else if ((type == XMLAttDef::Notation) || (type == XMLAttDef::Enumeration)) + { + // + // Make sure that this value maps to one of the enumeration or + // notation values in the enumList parameter. We don't have to + // look it up in the notation pool (if a notation) because we + // will look up the enumerated values themselves. If they are in + // the notation pool (after the DTD is parsed), then obviously + // this value will be legal since it matches one of them. + // + if (!isInList(pszTmpVal, enumList)) + emitError(XML4CValid::DoesNotMatchEnumList, fullName); + } + + // If not doing multiple values, then we are done + if (!multipleValues) + break; + + // + // If we are at the end, then break out now, else move up to the + // next char and update the base pointer. + // + if (alreadyCapped) + break; + + valPtr++; + pszTmpVal = valPtr; + } + +} + + +// --------------------------------------------------------------------------- +// DTDValidator: DTD handler interface. +// --------------------------------------------------------------------------- +void DTDValidator::scanDTD(const bool reuseValidator) +{ + // + // And now call out to the DTDValidator2.cpp file to do the actual + // scanning. When we get back, we will be through the internal and + // external subsets. + // + scanDocTypeDecl(reuseValidator); + + // If validating, then do the pre-content validation + if (getScanner()->getDoValidation()) + { + // + // Lets enumerate all of the elements in the element decl pool + // and put out an error for any that did not get declared. + // We also check all of the attributes as well. + // + NameIdPoolEnumerator<DTDElementDecl> elemEnum(fElemDeclPool); + while (elemEnum.hasMoreElements()) + { + const DTDElementDecl& curElem = elemEnum.nextElement(); + const DTDElementDecl::CreateReasons reason = curElem.getCreateReason(); + + // + // See if this element decl was ever marked as declared. If + // not, then put out an error. In some cases its just + // a warning, such as being referenced in a content model. + // + if (reason != XMLElementDecl::Declared) + { + if (reason == XMLElementDecl::AttList) + { + getScanner()->emitError + ( + XML4CErrs::UndeclaredElemInAttList + , curElem.getFullName() + ); + } + else if (reason == XMLElementDecl::AsRootElem) + { + emitError + ( + XML4CValid::UndeclaredElemInDocType + , curElem.getFullName() + ); + } + else if (reason == XMLElementDecl::InContentModel) + { + getScanner()->emitError + ( + XML4CErrs::UndeclaredElemInCM + , curElem.getFullName() + ); + } + else + { + #if defined(XML4C_DEBUG) + // <TBD> Should throw here + #endif + } + } + + // + // Check all of the attributes of the current element. + // We check for: + // + // 1) Multiple ID attributes + // 2) That all of the default values of attributes are + // valid for their type. + // 3) That for any notation types, that their lists + // of possible values refer to declared notations. + // + XMLAttDefList& attDefList = curElem.getAttDefList(); + bool seenId = false; + while (attDefList.hasMoreElements()) + { + const XMLAttDef& curAttDef = attDefList.nextElement(); + + if (curAttDef.getType() == XMLAttDef::ID) + { + if (seenId) + { + emitError + ( + XML4CValid::MultipleIdAttrs + , curElem.getFullName() + ); + break; + } + + seenId = true; + } + else if (curAttDef.getType() == XMLAttDef::Notation) + { + // + // We need to verify that all of its possible values + // (in the enum list) refer to valid notations. + // + XMLCh* list = XMLString::replicate(curAttDef.getEnumeration()); + ArrayJanitor<XMLCh> janList(list); + + // + // Search forward for a space or a null. If a null, + // we are done. If a space, cap it and look it up. + // + bool breakFlag = false; + XMLCh* listPtr = list; + XMLCh* lastPtr = listPtr; + while (true) + { + while (*listPtr && (*listPtr != chSpace)) + listPtr++; + + // + // If at the end, indicate we need to break after + // this one. Else, cap it off here. + // + if (!*listPtr) + breakFlag = true; + else + *listPtr = chNull; + + if (!fNotationDeclPool->getByKey(lastPtr)) + { + emitError + ( + XML4CValid::UnknownNotRefAttr + , curAttDef.getFullName() + , lastPtr + ); + } + + // Break out if we hit the end last time + if (breakFlag) + break; + + // Else move upwards and try again + listPtr++; + lastPtr = listPtr; + } + } + + // If it has a default/fixed value, then validate it + if (curAttDef.getValue()) + { + validateAttrValue + ( + curAttDef + , curAttDef.getValue() + ); + } + } + } + + // + // And enumerate all of the general entities. If any of them + // reference a notation, then make sure the notation exists. + // + NameIdPoolEnumerator<DTDEntityDecl> entEnum(fEntityDeclPool); + while (entEnum.hasMoreElements()) + { + const DTDEntityDecl& curEntity = entEnum.nextElement(); + + if (!curEntity.getNotationName()) + continue; + + // It has a notation name, so look it up + if (!fNotationDeclPool->getByKey(curEntity.getNotationName())) + { + emitError + ( + XML4CValid::NotationNotDeclared + , curEntity.getNotationName() + ); + } + } + } +} + diff --git a/src/validators/DTD/DTDValidator.hpp b/src/validators/DTD/DTDValidator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..519277b7e2d690e5418dcfae63bb185fd9d17a57 --- /dev/null +++ b/src/validators/DTD/DTDValidator.hpp @@ -0,0 +1,459 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:36 twl + * Initial revision + * + * Revision 1.5 1999/11/08 20:45:41 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + + +#if !defined(DTDVALIDATOR_HPP) +#define DTDVALIDATOR_HPP + +#include <util/RefHashTableOf.hpp> +#include <util/NameIdPool.hpp> +#include <util/StringPool.hpp> +#include <framework/XMLValidator.hpp> +#include <validators/DTD/DTDElementDecl.hpp> +#include <validators/DTD/DTDEntityDecl.hpp> + +class ContentSpecNode; +class DocTypeHandler; +class XMLMsgLoader; + + +// +// This is a derivative of the abstract validator interface. This class +// implements a validator that supports standard XML 1.0 DTD semantics. +// This class handles scanning the internal and external subsets of the +// DTD, and provides the standard validation services against the DTD info +// it found. +// +// NOTE: DTDs are not namespace aware, so we just use regular NameIdPool +// data structures to store element and attribute decls. They are all set +// to be in the global namespace and the full QName is used as the base name +// of the decl. This means that all the URI parameters below are expected +// to be null pointers (and anything else will cause an exception.) +// +class VALIDATORS_EXPORT DTDValidator : public XMLValidator +{ +public: + // ----------------------------------------------------------------------- + // Class specific types + // + // NOTE: This should really be private, but some of the compilers we + // have to support cannot understand that. + // + // EntityExpRes + // Returned from scanEntityRef() to indicate how the expanded text + // was treated. + // ----------------------------------------------------------------------- + enum EntityExpRes + { + EntityExp_Failed + , EntityExp_Pushed + , EntityExp_Returned + }; + + + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DTDValidator(XMLErrorReporter* const errReporter = 0); + virtual ~DTDValidator(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + NameIdPoolEnumerator<DTDElementDecl> getElemEnumerator() const; + NameIdPoolEnumerator<DTDEntityDecl> getEntityEnumerator() const; + NameIdPoolEnumerator<XMLNotationDecl> getNotationEnumerator() const; + unsigned int getRootElemId() const; + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setDocTypeHandler + ( + DocTypeHandler* const handlerToSet + ); + + + // ----------------------------------------------------------------------- + // Implementation of the XMLValidator interface + // ----------------------------------------------------------------------- + virtual int addOrFindNSId + ( + const XMLCh* const uriText + ); + + virtual int checkContent + ( + const unsigned int elemId + , const unsigned int* childIds + , const unsigned int childCount + ); + + virtual bool checkRootElement + ( + const unsigned int elemId + ); + + virtual void faultInAttr + ( + XMLAttr& toFill + , const XMLAttDef& attDef + ) const; + + virtual const XMLElementDecl* findElemDecl + ( + const unsigned int uriId + , const XMLCh* const baseName + , const XMLCh* const qName + , const LookupOpts options + , bool& wasAdded + ) const; + + virtual XMLElementDecl* findElemDecl + ( + const unsigned int uriId + , const XMLCh* const baseName + , const XMLCh* const qName + , const LookupOpts options + , bool& wasAdded + ); + + virtual const XMLEntityDecl* findEntityDecl + ( + const XMLCh* const entName + , const bool isPE + ) const; + + virtual XMLEntityDecl* findEntityDecl + ( + const XMLCh* const entName + , const bool isPE + ); + + virtual unsigned int findElemId + ( + const unsigned int uriId + , const XMLCh* const baseName + , const XMLCh* const qName + ) const; + + virtual const XMLNotationDecl* findNotationDecl + ( + const XMLCh* const notName + ) const; + + virtual XMLNotationDecl* findNotationDecl + ( + const XMLCh* const notName + ); + + virtual unsigned int findNSId + ( + const XMLCh* const nsName + ) const; + + virtual const XMLElementDecl* getElemDecl + ( + const unsigned int elemId + ) const; + + virtual XMLElementDecl* getElemDecl + ( + const unsigned int elemId + ); + + virtual bool getURIText + ( + const unsigned int uriId + , XMLBuffer& uriBufToFill + ) const; + + virtual void postParseValidation(); + + virtual void reset(); + + virtual bool requiresNamespaces() const; + + virtual void validateAttrValue + ( + const XMLAttDef& attDef + , const XMLCh* const attrValue + ); + + + // ----------------------------------------------------------------------- + // DTD specific pool methods. Many of the virtual interface methods + // above just call this one, passing along the qName (which is all that + // we deal with in this validator. + // ----------------------------------------------------------------------- + unsigned int findElemId + ( + const XMLCh* const qName + ) const; + + + + // ----------------------------------------------------------------------- + // Virtual DTD handler interface. If handlesDTD() returns true, then + // scanDocTypeDecl() will be called when a DOCTYPE is seen. The passed + // message loader and reader manager are really internal stuff but they + // are required to process the DTD external and internal subset. + // ----------------------------------------------------------------------- + virtual bool handlesDTD() const; + virtual void scanDTD(const bool reuseValidator); + + +private: + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + DTDValidator(const DTDValidator&); + void operator=(const DTDValidator&); + + +private: + // ----------------------------------------------------------------------- + // Private class types + // ----------------------------------------------------------------------- + enum IDTypes + { + IDType_Public + , IDType_External + , IDType_Either + }; + + + // ----------------------------------------------------------------------- + // Private DTD scanning methods. These are all in XMLValidator2.cpp + // ----------------------------------------------------------------------- + bool checkForPERef + ( + const bool spaceRequired + , const bool inLiteral + , const bool inMarkup + , const bool throwEndOfExt = false + ); + bool expandPERef + ( + const bool scanExternal + , const bool inLiteral + , const bool inMarkup + , const bool throwEndOfExt = false + ); + bool getQuotedString(XMLBuffer& toFill); + XMLAttDef* scanAttDef(DTDElementDecl& elemDecl, XMLBuffer& bufToUse); + bool scanAttValue(XMLBuffer& toFill, const XMLAttDef::AttTypes type); + void scanAttListDecl(); + ContentSpecNode* scanChildren(XMLBuffer& bufToUse); + bool scanCharRef(XMLCh& toFill, XMLCh& second); + void scanComment(); + bool scanContentSpec(DTDElementDecl& toFill); + void scanDefaultDecl(DTDAttDef& toFill); + void scanDocTypeDecl(const bool reuseValidator); + void scanElementDecl(); + void scanEntityDecl(); + bool scanEntityDef(); + bool scanEntityLiteral(XMLBuffer& toFill, const bool isPE); + bool scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl); + EntityExpRes scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped); + bool scanEnumeration(XMLBuffer& toFill, const bool notation); + bool scanEq(); + void scanExtSubsetDecl(const bool inIncludeSect); + bool scanId + ( + XMLBuffer& pubIdToFill + , XMLBuffer& sysIdToFill + , const IDTypes whatKind + ); + void scanIgnoredSection(); + bool scanInternalSubset(); + void scanMarkupDecl(const bool parseTextDecl); + bool scanMixed(DTDElementDecl& toFill); + void scanNotationDecl(); + void scanPI(); + bool scanPublicLiteral(XMLBuffer& toFill); + bool scanSystemLiteral(XMLBuffer& toFill); + void scanTextDecl(); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fDocTypeHandler + // This holds the optional doc type handler that can be installed + // and used to call back for all markup events. It is DTD specific. + // + // fDumAttDef + // fDumElemDecl + // fDumEntityDecl + // These are dummy objects into which mark decls are parsed when + // they are just overrides of previously declared markup decls. In + // such situations, the first one wins but we need to have somewhere + // to parse them into. So these are lazily created and used as needed + // when such markup decls are seen. + // + // fElemDeclPool + // This is the element decl pool. It contains all of the elements + // declared in the DTD (and their associated attributes.) When in + // non-validating mode, its just populated as new elements are seen + // and they are given default characteristics. + // + // fEntityDeclPool + // This is a pool of EntityDecl objects, which contains all of the + // general entities that are declared in the DTD subsets. + // + // fInternalSubset + // This is used to track whether we are in the internal subset or not, + // in which case we are in the external subset. + // + // fNextAttrId + // Since att defs are per-element, we don't have a validator wide + // attribute def pool. So we use a simpler data structure in each + // element decl to store its att defs, and we use this simple counter + // to apply a unique id to each new attribute. + // + // fNotationDeclPool + // This is a pool of NotationDecl objects, which contains all of the + // notations declared in the DTD subsets. + // + // fPEntityDeclPool + // This is a pool of EntityDecl objects, which contains all of the + // parameter entities that are declared in the DTD subsets. + // + // fRootElemId + // The id of the root element that we found in the DOCTYPE statement. + // Its initialized to ContentModel::fgInvalidElemId, so that its + // invalid unless we have a DOCTYPE. + // + // fURIStringPool + // Each validator is required to maintain a pool for URIs. It has + // to be able to assign unique ids for URIs. We use a standard string + // pool class. + // ----------------------------------------------------------------------- + DocTypeHandler* fDocTypeHandler; + DTDAttDef* fDumAttDef; + DTDElementDecl* fDumElemDecl; + DTDEntityDecl* fDumEntityDecl; + NameIdPool<DTDElementDecl>* fElemDeclPool; + NameIdPool<DTDEntityDecl>* fEntityDeclPool; + bool fInternalSubset; + unsigned int fNextAttrId; + NameIdPool<XMLNotationDecl>* fNotationDeclPool; + NameIdPool<DTDEntityDecl>* fPEntityDeclPool; + unsigned int fRootElemId; + XMLStringPool fURIStringPool; +}; + + +// --------------------------------------------------------------------------- +// DTDValidator: Getter methods +// --------------------------------------------------------------------------- +inline NameIdPoolEnumerator<DTDElementDecl> +DTDValidator::getElemEnumerator() const +{ + return NameIdPoolEnumerator<DTDElementDecl>(fElemDeclPool); +} + +inline NameIdPoolEnumerator<DTDEntityDecl> +DTDValidator::getEntityEnumerator() const +{ + return NameIdPoolEnumerator<DTDEntityDecl>(fEntityDeclPool); +} + +inline NameIdPoolEnumerator<XMLNotationDecl> +DTDValidator::getNotationEnumerator() const +{ + return NameIdPoolEnumerator<XMLNotationDecl>(fNotationDeclPool); +} + +inline unsigned int DTDValidator::getRootElemId() const +{ + return fRootElemId; +} + + +// --------------------------------------------------------------------------- +// DTDValidator: Setter methods +// --------------------------------------------------------------------------- +inline void DTDValidator::setDocTypeHandler(DocTypeHandler* const handlerToSet) +{ + fDocTypeHandler = handlerToSet; +} + + +// --------------------------------------------------------------------------- +// DTDValidator: DTD handler interface +// --------------------------------------------------------------------------- +inline bool DTDValidator::handlesDTD() const +{ + // We definitely want to handle DTD scanning + return true; +} + +#endif diff --git a/src/validators/DTD/DTDValidator2.cpp b/src/validators/DTD/DTDValidator2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..277c973423835a42d4db92b2ebf237b541051e43 --- /dev/null +++ b/src/validators/DTD/DTDValidator2.cpp @@ -0,0 +1,3560 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:38 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:45:42 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/BinMemInputStream.hpp> +#include <util/FlagJanitor.hpp> +#include <util/Janitor.hpp> +#include <util/PlatformUtils.hpp> +#include <util/UnexpectedEOFException.hpp> +#include <util/URL.hpp> +#include <util/XMLUni.hpp> +#include <framework/XMLBufferMgr.hpp> +#include <framework/XMLDocumentHandler.hpp> +#include <framework/XMLElementDecl.hpp> +#include <framework/XMLEntityHandler.hpp> +#include <framework/XMLNotationDecl.hpp> +#include <internal/URLInputSource.hpp> +#include <internal/EndOfEntityException.hpp> +#include <internal/ReaderMgr.hpp> +#include <internal/XMLScanner.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/DTDEntityDecl.hpp> +#include <validators/DTD/DTDValidator.hpp> +#include <validators/DTD/DocTypeHandler.hpp> +#include <validators/DTD/MixedContentModel.hpp> + + + +// --------------------------------------------------------------------------- +// Local methods +// --------------------------------------------------------------------------- + +// +// This method automates the grunt work of looking at a char and see if its +// a repetition suffix. If so, it creates a new correct rep node and wraps +// the pass node in it. Otherwise, it returns the previous node. +// +static ContentSpecNode* +makeRepNode(const XMLCh testCh, ContentSpecNode* const prevNode) +{ + if (testCh == chQuestion) + { + return new ContentSpecNode + ( + ContentSpecNode::ZeroOrOne + , prevNode + , 0 + ); + } + else if (testCh == chPlus) + { + return new ContentSpecNode + ( + ContentSpecNode::OneOrMore + , prevNode + , 0 + ); + } + else if (testCh == chAsterisk) + { + return new ContentSpecNode + ( + ContentSpecNode::ZeroOrMore + , prevNode + , 0 + ); + } + + // Just return the incoming node + return prevNode; +} + + + +// --------------------------------------------------------------------------- +// DTDValidator: Private scanning methods +// --------------------------------------------------------------------------- +bool DTDValidator::checkForPERef(const bool spaceRequired + , const bool inLiteral + , const bool inMarkup + , const bool throwAtEndExt) +{ + bool gotSpace = false; + + // + // See if we have any spaces up front. If so, then skip them and set + // the gotSpaces flag. + // + if (getReaderMgr()->skippedSpace()) + { + getReaderMgr()->skipPastSpaces(); + gotSpace = true; + } + + // If the next char is a percent, then expand the PERef + if (getReaderMgr()->skippedChar(chPercent)) + expandPERef(false, inLiteral, inMarkup, throwAtEndExt); + + // And skip any more spaces in the expanded value + if (getReaderMgr()->skippedSpace()) + { + getReaderMgr()->skipPastSpaces(); + gotSpace = true; + } + return gotSpace; +} + + +bool DTDValidator::expandPERef( const bool scanExternal + , const bool inLiteral + , const bool inMarkup + , const bool throwEndOfExt) +{ + XMLBufBid bbName(getBufMgr()); + + // + // If we are in the internal subset and in markup, then this is + // an error but we go ahead and do it anyway. + // + if (fInternalSubset && inMarkup) + getScanner()->emitError(XML4CErrs::PERefInMarkupInIntSubset); + + if (!getReaderMgr()->getName(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::ExpectedPEName); + + // Skip the semicolon if that's what we ended up on + getReaderMgr()->skippedChar(chSemiColon); + return false; + } + + // If no terminating semicolon, emit an error but try to keep going + if (!getReaderMgr()->skippedChar(chSemiColon)) + getScanner()->emitError(XML4CErrs::UnterminatedEntityRef); + + // + // Look it up in the PE decl pool and see if it exists. If not, just + // emit an error and continue. + // + XMLEntityDecl* decl = findEntityDecl(bbName.getRawBuffer(), true); + if (!decl) + { + getScanner()->emitError(XML4CErrs::EntityNotFound, bbName.getRawBuffer()); + return false; + } + + // + // If we are a standalone document, then it has to have been declared + // in the internal subset. Keep going though. + // + if (getScanner()->getStandalone() && !decl->getDeclaredInIntSubset()) + getScanner()->emitError(XML4CErrs::IllegalRefInStandalone, bbName.getRawBuffer()); + + // + // Okee dokee, we found it. So create either a memory stream with + // the entity value contents, or a file stream if its an external + // entity. + // + if (decl->isExternal()) + { + // And now create a reader to read this entity + InputSource* srcUsed; + XMLReader* reader = getReaderMgr()->createReader + ( + decl->getSystemId() + , decl->getPublicId() + , false + , inLiteral ? XMLReader::RefFrom_Literal : XMLReader::RefFrom_NonLiteral + , XMLReader::Type_PE + , XMLReader::Source_External + , srcUsed + ); + + // Put a janitor on the source so its cleaned up on exit + Janitor<InputSource> janSrc(srcUsed); + + // If the creation failed then throw an exception + if (!reader) + ThrowXML1(RuntimeException, XML4CExcepts::Gen_CouldNotOpenExtEntity, srcUsed->getSystemId()); + + // Set the 'throw at end' flag, to the one we were given + reader->setThrowAtEnd(throwEndOfExt); + + // + // Push the reader. If its a recursive expansion, then emit an error + // and return an failure. + // + if (!getReaderMgr()->pushReader(reader, decl)) + { + getScanner()->emitError(XML4CErrs::RecursiveEntity, decl->getName()); + return false; + } + + // + // If the caller wants us to scan the external entity, then lets + // do that now. + // + if (scanExternal) + { + XMLEntityHandler* entHandler = getScanner()->getEntityHandler(); + + // If we have an entity handler, tell it we are starting this entity + if (entHandler) + entHandler->startInputSource(*srcUsed); + + // + // Scan the external entity now. The parameter tells it that + // it is not in an include section. Get the current reader + // level so we can catch partial markup errors and be sure + // to get back to here if we get an exception out of the + // ext subset scan. + // + const unsigned int readerNum = getReaderMgr()->getCurrentReaderNum(); + try + { + scanExtSubsetDecl(false); + } + + catch(...) + { + // Pop the reader back to the original level + getReaderMgr()->cleanStackBackTo(readerNum); + + // End the input source, even though its not happy + if (entHandler) + entHandler->endInputSource(*srcUsed); + throw; + } + + // If we have an entity handler, tell it we are ending this entity + if (entHandler) + entHandler->endInputSource(*srcUsed); + } + } + else + { + // Create a reader over a memory stream over the entity value + XMLReader* valueReader = getReaderMgr()->createIntEntReader + ( + decl->getName() + , inLiteral ? XMLReader::RefFrom_Literal : XMLReader::RefFrom_NonLiteral + , XMLReader::Type_PE + , decl->getValue() + , decl->getValueLen() + , false + ); + + // + // Trt to push the entity reader onto the reader manager stack, + // where it will become the subsequent input. If it fails, that + // means the entity is recursive, so issue an error. The reader + // will have just been discarded, but we just keep going. + // + if (!getReaderMgr()->pushReader(valueReader, decl)) + getScanner()->emitError(XML4CErrs::RecursiveEntity, decl->getName()); + } + + return true; +} + + +bool DTDValidator::getQuotedString(XMLBuffer& toFill) +{ + // Reset the target buffer + toFill.reset(); + + // Get the next char which must be a single or double quote + XMLCh quoteCh; + if (!getReaderMgr()->skipIfQuote(quoteCh)) + return false; + + while (true) + { + // Get another char + const XMLCh nextCh = getReaderMgr()->getNextChar(); + + // See if it matches the starting quote char + if (nextCh == quoteCh) + break; + + // + // We should never get either an end of file null char here. If we + // do, just fail. It will be handled more gracefully in the higher + // level code that called us. + // + if (!nextCh) + return false; + + // Else add it to the buffer + toFill.append(nextCh); + } + return true; +} + + +XMLAttDef* +DTDValidator::scanAttDef(DTDElementDecl& parentElem, XMLBuffer& bufToUse) +{ + // Check for PE ref or optional whitespace + checkForPERef(false, false, true); + + // Get the name of the attribute + if (!getReaderMgr()->getName(bufToUse)) + { + getScanner()->emitError(XML4CErrs::ExpectedAttrName); + return 0; + } + + // + // Look up this attribute in the parent element's attribute list. If + // it already exists, then use the dummy. + // + DTDAttDef* decl = parentElem.getAttDef(bufToUse.getRawBuffer()); + if (decl) + { + // It already exists, so put out a warning + getScanner()->emitError(XML4CErrs::AttListAlreadyExists, bufToUse.getRawBuffer()); + + // Use the dummy decl to parse into + if (!fDumAttDef) + fDumAttDef = new DTDAttDef; + fDumAttDef->setName(bufToUse.getRawBuffer()); + decl = fDumAttDef; + } + else + { + // It does not already exist so create a new one + decl = new DTDAttDef(bufToUse.getRawBuffer()); + + // Give it the next available unique id + decl->setId(fNextAttrId++); + } + + // Set a flag to indicate whether we are doing a dummy parse + const bool isIgnored = (decl == fDumAttDef); + + // Space is required here, so check for PE ref, and require space + if (!checkForPERef(true, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // + // Next has to be one of the attribute type strings. This tells us what + // is to follow. + // + if (getReaderMgr()->skippedString(XMLUni::fgCDATAString)) + { + decl->setType(XMLAttDef::CData); + } + else if (getReaderMgr()->skippedString(XMLUni::fgIDString)) + { + if (!getReaderMgr()->skippedString(XMLUni::fgRefString)) + decl->setType(XMLAttDef::ID); + else if (!getReaderMgr()->skippedChar(chLatin_S)) + decl->setType(XMLAttDef::IDRef); + else + decl->setType(XMLAttDef::IDRefs); + } + else if (getReaderMgr()->skippedString(XMLUni::fgEntitString)) + { + if (getReaderMgr()->skippedChar(chLatin_Y)) + { + decl->setType(XMLAttDef::Entity); + } + else if (getReaderMgr()->skippedString(XMLUni::fgIESString)) + { + decl->setType(XMLAttDef::Entities); + } + else + { + getScanner()->emitError(XML4CErrs::ExpectedAttributeType); + if (isIgnored) + delete decl; + return 0; + } + } + else if (getReaderMgr()->skippedString(XMLUni::fgNmTokenString)) + { + if (getReaderMgr()->skippedChar(chLatin_S)) + decl->setType(XMLAttDef::NmTokens); + else + decl->setType(XMLAttDef::NmToken); + } + else if (getReaderMgr()->skippedString(XMLUni::fgNotationString)) + { + // Check for PE ref and require space + if (!checkForPERef(true, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + decl->setType(XMLAttDef::Notation); + if (!scanEnumeration(bufToUse, true)) + { + if (isIgnored) + delete decl; + return 0; + } + + // Set the value as the enumeration for this decl + decl->setEnumeration(bufToUse.getRawBuffer()); + } + else if (getReaderMgr()->skippedChar(chOpenParen)) + { + decl->setType(XMLAttDef::Enumeration); + if (!scanEnumeration(bufToUse, false)) + { + if (isIgnored) + delete decl; + return 0; + } + + // Set the value as the enumeration for this decl + decl->setEnumeration(bufToUse.getRawBuffer()); + } + else + { + getScanner()->emitError(XML4CErrs::ExpectedAttributeType); + if (isIgnored) + delete decl; + return 0; + } + + // Space is required here, so check for PE ref, and require space + if (!checkForPERef(true, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // And then scan for the optional default value declaration + scanDefaultDecl(*decl); + + // Add this guy to element's attr list (if not ignoring.) + if (!isIgnored) + parentElem.addAttDef(decl); + + // If validating, then do a couple of validation constraints + if (getScanner()->getDoValidation()) + { + if (decl->getType() == XMLAttDef::ID) + { + if ((decl->getDefaultType() != XMLAttDef::Implied) + && (decl->getDefaultType() != XMLAttDef::Required)) + { + emitError(XML4CValid::BadIDAttrDefType, decl->getFullName()); + } + } + } + + // If we have a doc type handler, tell it about this attdef. + if (fDocTypeHandler) + fDocTypeHandler->attDef(parentElem, *decl, isIgnored); + return decl; +} + + +void DTDValidator::scanAttListDecl() +{ + // Space is required here, so check for a PE ref + if (!checkForPERef(true, false, true)) + { + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // + // Next should be the name of the element it belongs to, so get a buffer + // and get the name into it. + // + XMLBufBid bbName(getBufMgr()); + if (!getReaderMgr()->getName(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::ExpectedElementName); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // + // Find this element's declaration. If it has not been declared yet, + // we will force one into the list, but not mark it as declared. + // + DTDElementDecl* elemDecl = fElemDeclPool->getByKey(bbName.getRawBuffer()); + if (!elemDecl) + { + // + // Lets fault in a declaration and add it to the pool. We mark + // it having been created because of an attlist. Later, if its + // declared, this will be updated. + // + elemDecl = new DTDElementDecl(bbName.getRawBuffer()); + elemDecl->setCreateReason(XMLElementDecl::AttList); + fElemDeclPool->put(elemDecl); + } + + // If we have a doc type handler, tell it the att list is starting + if (fDocTypeHandler) + fDocTypeHandler->startAttList(*elemDecl); + + // + // Now we loop until we are done with all of the attributes in this + // list. We need a buffer to use for local processing. + // + XMLBufBid bbTmp(getBufMgr()); + XMLBuffer& tmpBuf = bbTmp.getBuffer(); + bool seenAnId = false; + while (true) + { + // Get the next char out and see what it tells us to do + const XMLCh nextCh = getReaderMgr()->peekNextChar(); + + // Watch for EOF + if (!nextCh) + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + + if (nextCh == chCloseAngle) + { + // We are done with this attribute list + getReaderMgr()->getNextChar(); + break; + } + else if (XMLReader::isWhitespace(nextCh)) + { + // + // If advanced callbacks are enabled and we have a doc + // type handler, then gather up the white space and call + // back on the doctype handler. Otherwise, just skip + // whitespace. + // + if (fDocTypeHandler) + { + getReaderMgr()->getSpaces(tmpBuf); + fDocTypeHandler->doctypeWhitespace + ( + tmpBuf.getRawBuffer() + , tmpBuf.getLen() + ); + } + else + { + getReaderMgr()->skipPastSpaces(); + } + } + else if (nextCh == chPercent) + { + // Eat the percent and expand the ref + getReaderMgr()->getNextChar(); + expandPERef(false, false, true); + } + else + { + // + // It must be an attribute name, so scan it. We let + // it use our local buffer for its name scanning. + // + XMLAttDef* attDef = scanAttDef(*elemDecl, tmpBuf); + + if (!attDef) + { + getReaderMgr()->skipPastChar(chCloseAngle); + break; + } + + // + // If we are validating and its an ID type, then we have to + // make sure that we have not seen an id attribute yet. Set + // the flag to say that we've seen one now also. + // + if (attDef->getType() == XMLAttDef::ID) + { + if (seenAnId) + emitError(XML4CValid::MultipleIdAttrs, elemDecl->getFullName()); + seenAnId = true; + } + } + } + + // If we have a doc type handler, tell it the att list is ending + if (fDocTypeHandler) + fDocTypeHandler->endAttList(*elemDecl); +} + + +// +// This method is called to scan the value of an attribute in content. This +// involves some normalization and replacement of general entity and +// character references. +// +// End of entity's must be dealt with here. During DTD scan, they can come +// from external entities. During content, they can come from any entity. +// We just eat the end of entity and continue with our scan until we come +// to the closing quote. If an unterminated value causes us to go through +// subsequent entities, that will cause errors back in the calling code, +// but there's little we can do about it here. +// +bool DTDValidator::scanAttValue( XMLBuffer& toFill + , const XMLAttDef::AttTypes type) +{ + enum States + { + InWhitespace + , InContent + }; + + // Reset the target buffer + toFill.reset(); + + // Get the next char which must be a single or double quote + XMLCh quoteCh; + if (!getReaderMgr()->skipIfQuote(quoteCh)) + return false; + + // + // We have to get the current reader because we have to ignore closing + // quotes until we hit the same reader again. + // + const unsigned int curReader = getReaderMgr()->getCurrentReaderNum(); + + // + // Loop until we get the attribute value. Note that we use a double + // loop here to avoid the setup/teardown overhead of the exception + // handler on every round. + // + XMLCh nextCh; + XMLCh secondCh = 0; + States curState = InContent; + bool firstNonWS = false; + bool gotLeadingSurrogate = false; + bool escaped; + while (true) + { + try + { + while(true) + { + // Get another char. Use second char from prevous is its there + if (secondCh) + { + nextCh = secondCh; + secondCh = 0; + } + else + { + nextCh = getReaderMgr()->getNextChar(); + } + + if (!nextCh) + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + + // Check for our ending quote in the same entity + if (nextCh == quoteCh) + { + if (curReader == getReaderMgr()->getCurrentReaderNum()) + return true; + + // Watch for spillover into a previous entity + if (curReader > getReaderMgr()->getCurrentReaderNum()) + { + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + return false; + } + } + + // + // Check for an entity ref now, before we let it affect our + // whitespace normalization logic below. We ignore the empty flag + // in this one. + // + escaped = false; + if (nextCh == chAmpersand) + { + if (scanEntityRef(nextCh, secondCh, escaped) != EntityExp_Returned) + { + gotLeadingSurrogate = false; + continue; + } + } + + // Check for correct surrogate pairs + if ((nextCh >= 0xD800) && (nextCh <= 0xDBFF)) + { + if (gotLeadingSurrogate) + getScanner()->emitError(XML4CErrs::Expected2ndSurrogateChar); + else + gotLeadingSurrogate = true; + } + else + { + if (gotLeadingSurrogate) + { + if ((nextCh < 0xDC00) && (nextCh > 0xDFFF)) + getScanner()->emitError(XML4CErrs::Expected2ndSurrogateChar); + } + gotLeadingSurrogate = false; + + // Its got to at least be a valid XML character + if (!XMLReader::isXMLChar(nextCh)) + getScanner()->emitError(XML4CErrs::InvalidCharacter); + } + + // + // If its not escaped, then make sure its not a < character, which + // is not allowed in attribute values. + // + if (!escaped && (nextCh == chOpenAngle)) + getScanner()->emitError(XML4CErrs::BracketInAttrValue); + + // + // If the attribute is a CDATA type we do simple replacement of + // tabs and new lines with spaces, if the character is not escaped + // by way of a char ref. + // + // Otherwise, we do the standard non-CDATA normalization of + // compressing whitespace to single spaces and getting rid of + // leading and trailing whitespace. + // + if (type == XMLAttDef::CData) + { + if (!escaped) + { + if ((nextCh == 0x09) || (nextCh == 0x0A) || (nextCh == 0x0D)) + nextCh = chSpace; + } + } + else + { + if (curState == InWhitespace) + { + if (!XMLReader::isWhitespace(nextCh)) + { + if (firstNonWS) + toFill.append(chSpace); + curState = InContent; + firstNonWS = true; + } + else + { + continue; + } + } + else if (curState == InContent) + { + if (XMLReader::isWhitespace(nextCh)) + { + curState = InWhitespace; + continue; + } + firstNonWS = true; + } + } + + // Else add it to the buffer + toFill.append(nextCh); + } + } + + catch(const EndOfEntityException&) + { + // Just eat it and continue. + gotLeadingSurrogate = false; + escaped = false; + } + } + return true; +} + + +bool DTDValidator::scanCharRef(XMLCh& first, XMLCh& second) +{ + bool gotOne = false; + unsigned int value = 0; + + // + // Set the radix. Its supposed to be a lower case x if hex. But, in + // order to recover well, we check for an upper and put out an error + // for that. + // + unsigned int radix = 10; + + if (getReaderMgr()->skippedChar(chLatin_x)) + { + radix = 16; + } + else if (getReaderMgr()->skippedChar(chLatin_X)) + { + getScanner()->emitError(XML4CErrs::HexRadixMustBeLowerCase); + radix = 16; + } + + while (true) + { + const XMLCh nextCh = getReaderMgr()->peekNextChar(); + + // Watch for EOF + if (!nextCh) + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + + // Break out on the terminating semicolon + if (nextCh == chSemiColon) + { + getReaderMgr()->getNextChar(); + break; + } + + // + // Convert this char to a binary value, or bail out if its not + // one. + // + unsigned int nextVal; + if ((nextCh >= chDigit_0) && (nextCh <= chDigit_9)) + nextVal = (unsigned int)(nextCh - chDigit_0); + else if ((nextCh >= chLatin_A) && (nextCh <= chLatin_F)) + nextVal= (unsigned int)(10 + (nextCh - chLatin_A)); + else if ((nextCh >= chLatin_a) && (nextCh <= chLatin_f)) + nextVal = (unsigned int)(10 + (nextCh - chLatin_a)); + else + { + // + // If we got at least a sigit, then do an unterminated ref + // error. Else, do an expected a numerical ref thing. + // + if (gotOne) + getScanner()->emitError(XML4CErrs::UnterminatedCharRef); + else + getScanner()->emitError(XML4CErrs::ExpectedNumericalCharRef); + + return false; + } + + // + // Make sure its valid for the radix. If not, then just eat the + // digit and go on after issueing an error. Else, update the + // running value with this new digit. + // + if (nextVal >= radix) + { + XMLCh tmpStr[2]; + tmpStr[0] = nextCh; + tmpStr[1] = chNull; + getScanner()->emitError(XML4CErrs::BadDigitForRadix, tmpStr); + } + else + { + value = (value * radix) + nextVal; + } + + // Indicate that we got at least one good digit + gotOne = true; + + // Eat the char we just processed + getReaderMgr()->getNextChar(); + } + + // Return the char (or chars) + if (value >= 0x10000) + { + value -= 0x10000; + first = XMLCh((value >> 10) + 0xD800); + second = XMLCh((value & 0x3FF) + 0xDC00); + } + else + { + first = XMLCh(value); + second = 0; + } + return true; +} + + +ContentSpecNode* DTDValidator::scanChildren(XMLBuffer& bufToUse) +{ + // Check for a PE ref here, but don't require spaces + checkForPERef(false, false, true); + + // We have to check entity nesting here + unsigned int curReader; + + // + // We know that the caller just saw an opening parenthesis, so we need + // to parse until we hit the end of it, recursing for other nested + // parentheses we see. + // + // We have to check for one up front, since it could be something like + // (((a)*)) etc... + // + ContentSpecNode* curNode = 0; + if (getReaderMgr()->skippedChar(chOpenParen)) + { + curReader = getReaderMgr()->getCurrentReaderNum(); + + // Lets call ourself and get back the resulting node + curNode = scanChildren(bufToUse); + + // If that failed, no need to go further, return failure + if (!curNode) + return 0; + + if (curReader != getReaderMgr()->getCurrentReaderNum()) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + } + else + { + // Not a nested paren, so it must be a leaf node + if (!getReaderMgr()->getName(bufToUse)) + { + getScanner()->emitError(XML4CErrs::ExpectedElementName); + return 0; + } + + // + // Create a leaf node for it. If we can find the element id for + // this element, then use it. Else, we have to fault in an element + // decl, marked as created because of being in a content model. + // + unsigned int elemId = findElemId(bufToUse.getRawBuffer()); + if (elemId == XMLElementDecl::fgInvalidElemId) + { + DTDElementDecl* decl = new DTDElementDecl(bufToUse.getRawBuffer()); + decl->setCreateReason(XMLElementDecl::InContentModel); + fElemDeclPool->put(decl); + elemId = decl->getId(); + } + curNode = new ContentSpecNode(elemId); + + // Check for a PE ref here, but don't require spaces + const bool gotSpaces = checkForPERef(false, false, true); + + // Check for a repetition character after the leaf + const XMLCh repCh = getReaderMgr()->peekNextChar(); + ContentSpecNode* tmpNode = makeRepNode(repCh, curNode); + if (tmpNode != curNode) + { + if (gotSpaces) + getScanner()->emitError(XML4CErrs::UnexpectedWhitespace); + getReaderMgr()->getNextChar(); + curNode = tmpNode; + } + } + + // Check for a PE ref here, but don't require spaces + checkForPERef(false, false, true); + + // + // Ok, the next character tells us what kind of content this particular + // model this particular parentesized section is. Its either a choice if + // we see ',', a sequence if we see '|', or a single leaf node if we see + // a closing paren. + // + const XMLCh opCh = getReaderMgr()->peekNextChar(); + + if ((opCh != chComma) + && (opCh != chPipe) + && (opCh != chCloseParen)) + { + // Not a legal char, so delete our node and return failure + getScanner()->emitError(XML4CErrs::ExpectedSeqChoiceLeaf); + delete curNode; + return 0; + } + + // + // Create the head node of the correct type. We need this to remember + // the top of the local tree. If it was a single subexpr, then just + // set the head node to the current node. For the others, we'll build + // the tree off the second child as we move across. + // + ContentSpecNode* headNode = 0; + ContentSpecNode::NodeTypes curType; + if (opCh == chComma) + { + curType = ContentSpecNode::Sequence; + headNode = new ContentSpecNode(curType, curNode, 0); + curNode = headNode; + } + else if (opCh == chPipe) + { + curType = ContentSpecNode::Choice; + headNode = new ContentSpecNode(curType, curNode, 0); + curNode = headNode; + } + else + { + headNode = curNode; + getReaderMgr()->getNextChar(); + } + + // + // If it was a sequence or choice, we just loop until we get to the + // end of our section, adding each new leaf or sub expression to the + // right child of the current node, and making that new node the current + // node. + // + if ((opCh == chComma) || (opCh == chPipe)) + { + ContentSpecNode* lastNode = 0; + while (true) + { + // Check for a PE ref here, but don't require spaces + checkForPERef(false, false, true); + + // + // The next thing must either be another | or , character followed + // by another leaf or subexpression, or a closing parenthesis. + // + if (getReaderMgr()->skippedChar(chCloseParen)) + { + // + // We've hit the end of this section, so break out. But, we + // need to see if we left a partial sequence of choice node + // without a second node. If so, we have to undo that and + // put its left child into the right node of the previous + // node. + // + if ((curNode->getType() == ContentSpecNode::Choice) + || (curNode->getType() == ContentSpecNode::Sequence)) + { + if (!curNode->getSecond()) + { + ContentSpecNode* saveFirst = curNode->orphanFirst(); + lastNode->setSecond(saveFirst); + curNode = lastNode; + } + } + break; + } + else if (getReaderMgr()->skippedChar(opCh)) + { + // Check for a PE ref here, but don't require spaces + checkForPERef(false, false, true); + + if (getReaderMgr()->skippedChar(chOpenParen)) + { + curReader = getReaderMgr()->getCurrentReaderNum(); + + // Recurse to handle this new guy + ContentSpecNode* subNode = scanChildren(bufToUse); + + // If it failed, we are done, clean up here and return failure + if (!subNode) + { + delete headNode; + return 0; + } + + if (curReader != getReaderMgr()->getCurrentReaderNum()) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + + // Else patch it in and make it the new current + ContentSpecNode* newCur = new ContentSpecNode + ( + curType + , subNode + , 0 + ); + curNode->setSecond(newCur); + lastNode = curNode; + curNode = newCur; + } + else + { + // + // Got to be a leaf node, so get a name. If we cannot get + // one, then clean up and get outa here. + // + if (!getReaderMgr()->getName(bufToUse)) + { + delete headNode; + getScanner()->emitError(XML4CErrs::ExpectedElementName); + return 0; + } + + // + // Create a leaf node for it. If we can find the element + // id for this element, then use it. Else, we have to + // fault in an element decl, marked as created because + // of being in a content model. + // + unsigned int elemId = findElemId(bufToUse.getRawBuffer()); + if (elemId == XMLElementDecl::fgInvalidElemId) + { + DTDElementDecl* decl = new DTDElementDecl(bufToUse.getRawBuffer()); + decl->setCreateReason(XMLElementDecl::InContentModel); + fElemDeclPool->put(decl); + elemId = decl->getId(); + } + ContentSpecNode* tmpLeaf = new ContentSpecNode(elemId); + + // Check for a repetition character after the leaf + const XMLCh repCh = getReaderMgr()->peekNextChar(); + ContentSpecNode* tmpLeaf2 = makeRepNode(repCh, tmpLeaf); + if (tmpLeaf != tmpLeaf2) + getReaderMgr()->getNextChar(); + + // + // Create a new sequence or choice node, with the leaf + // (or rep surrounding it) we just got as its first node. + // Make the new node the second node of the current node, + // and then make it the current node. + // + ContentSpecNode* newCur = new ContentSpecNode + ( + curType + , tmpLeaf2 + , 0 + ); + curNode->setSecond(newCur); + lastNode = curNode; + curNode = newCur; + } + } + else + { + // Cannot be valid + if (opCh == chComma) + getScanner()->emitError(XML4CErrs::ExpectedChoiceOrCloseParen); + else + getScanner()->emitError(XML4CErrs::ExpectedSeqOrCloseParen); + delete headNode; + return 0; + } + } + } + + // + // We saw the terminating parenthesis so lets check for any repetition + // character, and create a node for that, making the head node the child + // of it. + // + XMLCh repCh = getReaderMgr()->peekNextChar(); + ContentSpecNode* retNode = makeRepNode(repCh, headNode); + if (retNode != headNode) + getReaderMgr()->getNextChar(); + + return retNode; +} + + +// +// We get here after the '<!--' part of the comment. We scan past the +// terminating '-->' It will calls the appropriate handler with the comment +// text, if one is provided. A comment can be in either the document or +// the DTD, so the fInDocument flag is used to know which handler to send +// it to. +// +void DTDValidator::scanComment() +{ + enum States + { + InText + , OneDash + , TwoDashes + }; + + // Get a buffer for this + XMLBufBid bbComment(getBufMgr()); + + // + // Get the comment text into a temp buffer. Be sure to use temp buffer + // two here, since its to be used for stuff that is potentially longer + // than just a name. + // + States curState = InText; + while (true) + { + // Get the next character + const XMLCh nextCh = getReaderMgr()->getNextChar(); + + // Watch for an end of file + if (!nextCh) + { + getScanner()->emitError(XML4CErrs::UnterminatedComment); + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + } + + // Make sure its a valid XML character + if (!XMLReader::isXMLChar(nextCh)) + getScanner()->emitError(XML4CErrs::InvalidCharacter); + + if (curState == InText) + { + // If its a dash, go to OneDash state. Otherwise take as text + if (nextCh == chDash) + curState = OneDash; + else + bbComment.append(nextCh); + } + else if (curState == OneDash) + { + // + // If its another dash, then we change to the two dashes states. + // Otherwise, we have to put in the deficit dash and the new + // character and go back to InText. + // + if (nextCh == chDash) + { + curState = TwoDashes; + } + else + { + bbComment.append(chDash); + bbComment.append(nextCh); + curState = InText; + } + } + else if (curState == TwoDashes) + { + // The next character must be the closing bracket + if (nextCh != chCloseAngle) + { + getScanner()->emitError(XML4CErrs::IllegalSequenceInComment); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + break; + } + } + + // If there is a doc type handler, then pass on the comment stuff + if (fDocTypeHandler) + fDocTypeHandler->doctypeComment(bbComment.getRawBuffer()); +} + + +bool DTDValidator::scanContentSpec(DTDElementDecl& toFill) +{ + // + // Check for for a couple of the predefined content type strings. If + // its not one of these, its got to be a parenthesized reg ex type + // expression. + // + if (getReaderMgr()->skippedString(XMLUni::fgEmptyString)) + { + toFill.setModelType(DTDElementDecl::Empty); + return true; + } + + if (getReaderMgr()->skippedString(XMLUni::fgAnyString)) + { + toFill.setModelType(DTDElementDecl::Any); + return true; + } + + // Its got to be a parenthesized regular expression + if (!getReaderMgr()->skippedChar(chOpenParen)) + { + getScanner()->emitError(XML4CErrs::ExpectedContentSpecExpr); + return false; + } + + // Get the current reader id, so we can test for partial markup + const unsigned int curReader = getReaderMgr()->getCurrentReaderNum(); + + // We could have a PE ref here, but don't require space + checkForPERef(false, false, true); + + // + // Now we look for a PCDATA string. If its PCDATA, then it must be a + // MIXED model. Otherwise, it must be a regular list of children in + // a regular expression perhaps. + // + bool status; + if (getReaderMgr()->skippedString(XMLUni::fgPCDATAString)) + { + // Set the model to mixed + toFill.setModelType(DTDElementDecl::Mixed); + status = scanMixed(toFill); + + // + // If we are validating we have to check that there are no multiple + // uses of any child elements. + // + if (getScanner()->getDoValidation()) + { + if (((const MixedContentModel*)toFill.getContentModel())->hasDups()) + emitError(XML4CValid::RepElemInMixed); + } + } + else + { + // + // We have to do a recursive scan of the content model. Create a + // buffer for it to use, for efficiency. It returns the top ofthe + // content spec node tree, which we set if successful. + // + toFill.setModelType(DTDElementDecl::Children); + XMLBufBid bbTmp(getBufMgr()); + ContentSpecNode* resNode = scanChildren(bbTmp.getBuffer()); + status = (resNode != 0); + if (status) + toFill.setContentSpec(resNode); + } + + // Make sure we are on the same reader as where we started + if (curReader != getReaderMgr()->getCurrentReaderNum()) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + + return status; +} + + +void DTDValidator::scanDefaultDecl(DTDAttDef& toFill) +{ + if (getReaderMgr()->skippedString(XMLUni::fgRequiredString)) + { + toFill.setDefaultType(XMLAttDef::Required); + return; + } + + if (getReaderMgr()->skippedString(XMLUni::fgImpliedString)) + { + toFill.setDefaultType(XMLAttDef::Implied); + return; + } + + if (getReaderMgr()->skippedString(XMLUni::fgFixedString)) + { + // + // There must be space before the fixed value. If there is not, then + // emit an error but keep going. + // + if (!getReaderMgr()->skippedSpace()) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + else + getReaderMgr()->skipPastSpaces(); + toFill.setDefaultType(XMLAttDef::Fixed); + } + else + { + toFill.setDefaultType(XMLAttDef::Default); + } + + // + // If we got here, its fixed or default, so we need to get a value. + // If we don't, then emit an error but just set the default value to + // an empty string and try to keep going. + // + XMLBufBid bbValue(getBufMgr()); + if (!scanAttValue(bbValue.getBuffer(), toFill.getType())) + getScanner()->emitError(XML4CErrs::ExpectedDefAttrDecl); + + toFill.setValue(bbValue.getRawBuffer()); +} + + +// +// This method handles the high level logic of scanning the DOCType +// declaration. This kicks off both the scanning of the internal subset and +// the scanning of the external subset, if any. +// +// When we get here the '<!DOCTYPE' part has already been scanned, which is +// what told us that we had a doc type decl to parse. +// +void DTDValidator::scanDocTypeDecl(const bool reuseValidator) +{ + // There must be some space after DOCTYPE + if (!getReaderMgr()->skipPastSpaces()) + { + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // Just skip the Doctype declaration and return + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // Get a buffer for the root element + XMLBufBid bbRootName(getBufMgr()); + + // + // Get a name from the input, which should be the name of the root + // element of the upcoming content. + // + getReaderMgr()->getName(bbRootName.getBuffer()); + if (bbRootName.isEmpty()) + { + getScanner()->emitError(XML4CErrs::NoRootElemInDOCTYPE); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // + // This element obviously is not going to exist in the element decl + // pool yet, but we need to store away an element id. So force it into + // the element decl pool, marked as being there because it was in + // the DOCTYPE. Later, when its declared, the status will be updated. + // + DTDElementDecl* rootDecl = new DTDElementDecl(bbRootName.getRawBuffer()); + rootDecl->setCreateReason(DTDElementDecl::AsRootElem); + fRootElemId = fElemDeclPool->put(rootDecl); + + // Skip any spaces after the name + getReaderMgr()->skipPastSpaces(); + + bool hasIntSubset = false; + bool hasExtSubset = false; + XMLCh* sysId = 0; + XMLCh* pubId = 0; + + // + // If the next character is '[' then we have no external subset cause + // there is no system id, just the opening character of the internal + // subset. Else, has to be an id. + // + if (getReaderMgr()->skippedChar(chOpenSquare)) + { + hasIntSubset = true; + } + else + { + // Indicate we have an external subset + hasExtSubset = true; + + // Get buffers for the ids + XMLBufBid bbPubId(getBufMgr()); + XMLBufBid bbSysId(getBufMgr()); + + // Get the external subset id + if (!scanId(bbPubId.getBuffer(), bbSysId.getBuffer(), IDType_External)) + { + getScanner()->emitError(XML4CErrs::ExpectedSystemOrPublicId); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // Get copies of the ids we got + pubId = XMLString::replicate(bbPubId.getRawBuffer()); + sysId = XMLString::replicate(bbSysId.getRawBuffer()); + + // Skip spaces and check again for the opening of an internal subset + getReaderMgr()->skipPastSpaces(); + if (getReaderMgr()->skippedChar(chOpenSquare)) + hasIntSubset = true; + } + + // Insure that the ids get cleaned up, if they got allocated + ArrayJanitor<XMLCh> janSysId(sysId); + ArrayJanitor<XMLCh> janPubId(pubId); + + // + // If we have a doc type handler and advanced callbacks are enabled, + // call the doctype event. + // + if (fDocTypeHandler) + fDocTypeHandler->doctypeDecl(*rootDecl, pubId, sysId, hasIntSubset); + + // + // Ok, if we had an internal subset, we are just past the [ character + // and need to parse that first. + // + if (hasIntSubset) + { + // We can't have any internal subset if we are reusing the validator + if (reuseValidator) + ThrowXML(RuntimeException, XML4CExcepts::Val_CantHaveIntSS); + + // Indicate we are in the internal subset now + FlagJanitor<bool> janContentFlag(&fInternalSubset, true); + + // Set the current subset flag to let the scanning code know which + if (!scanInternalSubset()) + { + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // + // Do a sanity check that some expanded PE did not propogate out of + // the doctype. This could happen if it was terminated early by bad + // syntax. + // + if (getReaderMgr()->getCurrentReaderNum() > 1) + { + getScanner()->emitError(XML4CErrs::PEPropogated); + + // Ask the reader manager to pop back down to the main level + getReaderMgr()->cleanStackBackTo(1); + } + + getReaderMgr()->skipPastSpaces(); + } + + // And that should leave us at the closing > of the DOCTYPE line + if (!getReaderMgr()->skippedChar(chCloseAngle)) + { + // + // Do a special check for the common scenario of an extra ] char at + // the end. This is easy to recover from. + // + if (getReaderMgr()->skippedChar(chCloseSquare) + && getReaderMgr()->skippedChar(chCloseAngle)) + { + getScanner()->emitError(XML4CErrs::ExtraCloseSquare); + } + else + { + getScanner()->emitError(XML4CErrs::UnterminatedDOCTYPE); + getReaderMgr()->skipPastChar(chCloseAngle); + } + } + + // + // If we had an external subset, then we need to deal with that one + // next. If we are reusing the validator, then don't scan it. + // + if (hasExtSubset && !reuseValidator) + { + // Indicate we are in the external subset now + FlagJanitor<bool> janContentFlag(&fInternalSubset, false); + + // And now create a reader to read this entity + InputSource* srcUsed; + XMLReader* reader = getReaderMgr()->createReader + ( + sysId + , pubId + , false + , XMLReader::RefFrom_NonLiteral + , XMLReader::Type_General + , XMLReader::Source_External + , srcUsed + ); + + // Put a janitor on the input source + Janitor<InputSource> janSrc(srcUsed); + + // + // If it failed then throw an exception + // + if (!reader) + ThrowXML1(RuntimeException, XML4CExcepts::Gen_CouldNotOpenDTD, srcUsed->getSystemId()); + + // + // In order to make the processing work consistently, we have to + // make this look like an external entity. So create an entity + // decl and fill it in and push it with the reader, as happens + // with an external entity. Put a janitor on it to insure it gets + // cleaned up. The reader manager does not adopt them. + // + const XMLCh gDTDStr[] = { chLatin_D, chLatin_T, chLatin_D , chNull }; + DTDEntityDecl* declDTD = new DTDEntityDecl(gDTDStr); + declDTD->setSystemId(sysId); + Janitor<DTDEntityDecl> janDecl(declDTD); + + // Mark this one as a throw at end + reader->setThrowAtEnd(true); + + // And push it onto the stack, with its pseudo name + getReaderMgr()->pushReader(reader, declDTD); + + // Tell it its not in an include section + scanExtSubsetDecl(false); + } +} + + +// +// This is called after seeing '<!ELEMENT' which indicates that an element +// markup is starting. This guy scans the rest of it and adds it to the +// element decl pool if it has not already been declared. +// +void DTDValidator::scanElementDecl() +{ + // + // Space is legal (required actually) here so check for a PE ref. If + // we don't get our whitespace, then issue and error, but try to keep + // going. + // + if (!checkForPERef(true, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // Get a buffer for the element name and scan in the name + XMLBufBid bbName(getBufMgr()); + if (!getReaderMgr()->getName(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::ExpectedElementName); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // Look this guy up in the element decl pool + DTDElementDecl* decl = fElemDeclPool->getByKey(bbName.getRawBuffer()); + + // + // If it does not exist, then we need to create it. If it does and + // its marked as declared, then that's an error, but we still need to + // scan over the content model so use the dummy declaration that the + // parsing code can fill in. + // + bool isNew = false; + if (decl) + { + if (decl->isDeclared()) + { + if (getScanner()->getDoValidation()) + emitError(XML4CValid::ElementAlreadyExists, bbName.getRawBuffer()); + + if (!fDumElemDecl) + fDumElemDecl = new DTDElementDecl(bbName.getRawBuffer()); + else + fDumElemDecl->setName(bbName.getRawBuffer()); + } + } + else + { + // Create the new empty declaration to fill in. Mark it declared + decl = new DTDElementDecl(bbName.getRawBuffer()); + isNew = true; + + // Put it in the element decl pool + fElemDeclPool->put(decl); + } + + // Set a flag for whether we will ignore this one + const bool isIgnored = (decl == fDumElemDecl); + + // Another check for a PE ref, with at least required whitespace + if (!checkForPERef(true, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // And now scan the content model for this guy. + if (!scanContentSpec(*decl)) + { + getReaderMgr()->skipPastChar(chCloseAngle); + if (isNew) + delete decl; + return; + } + + // Another check for a PE ref, but we don't require whitespace here + checkForPERef(false, false, true); + + // If this is not one we are ignoring, then set it declared + if (!isIgnored) + decl->setCreateReason(XMLElementDecl::Declared); + + // And we should have the ending angle bracket + if (!getReaderMgr()->skippedChar(chCloseAngle)) + { + getScanner()->emitError(XML4CErrs::UnterminatedElementDecl, bbName.getRawBuffer()); + getReaderMgr()->skipPastChar(chCloseAngle); + } + + // + // If we have a DTD handler tell it about the new element decl. We + // tell it if its one that can be ignored, cause its an override of a + // previously existing decl. If it is being ignored, only call back + // if advanced callbacks are enabled. + // + if (fDocTypeHandler) + { + fDocTypeHandler->elementDecl + ( + *decl + , isIgnored + ); + } +} + + +// +// This method will process a general or parameter entity reference. The +// entity name and entity text will be stored in the entity pool. The value +// of the entity will be scanned for any other parameter entity or char +// references which will be expanded. So the stored value can only have +// general entity references when done. +// +void DTDValidator::scanEntityDecl() +{ + // + // Space is required here, but we cannot check for a PE Ref since + // there could be a legal (no-ref) percent sign here. Since any + // entity that ended here would be illegal, we just skip spaces + // and then check for a percent. + // + if (!getReaderMgr()->lookingAtSpace()) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + else + getReaderMgr()->skipPastSpaces(); + const bool isPEDecl = getReaderMgr()->skippedChar(chPercent); + + // + // If a PE decl, then eat the percent and check for spaces or a + // PE ref on the other side of it. At least spaces are required. + // + if (isPEDecl) + { + if (!checkForPERef(true, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + } + + // + // Now lets get a name, which should be the name of the entity. We + // have to get a buffer for this. + // + XMLBufBid bbName(getBufMgr()); + if (!getReaderMgr()->getName(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::ExpectedPEName); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // If namespaces are enabled, then no colons allowed + if (getScanner()->getDoNamespaces()) + { + if (XMLString::indexOf(bbName.getRawBuffer(), chColon) != -1) + getScanner()->emitError(XML4CErrs::ColonNotLegalWithNS); + } + + // + // See if this entity already exists. If so, then the existing one + // takes precendence. So we use the local dummy decl to parse into + // and just ignore the results. + // + DTDEntityDecl* entityDecl = 0; + if (isPEDecl) + entityDecl = fPEntityDeclPool->getByKey(bbName.getRawBuffer()); + else + entityDecl = fEntityDeclPool->getByKey(bbName.getRawBuffer()); + + if (entityDecl) + { + if (!fDumEntityDecl) + fDumEntityDecl = new DTDEntityDecl; + fDumEntityDecl->setName(bbName.getRawBuffer()); + entityDecl = fDumEntityDecl; + } + else + { + // Its not in existence already, then create an entity decl for it + entityDecl = new DTDEntityDecl(bbName.getRawBuffer()); + + // + // Set the declaration location. The parameter indicates whether + // its declared in the content/internal subset, so we do + // whether its not in the external subset. + // + entityDecl->setDeclaredInIntSubset(fInternalSubset); + } + + // Set a flag that indicates whether we are ignoring this one + const bool isIgnored = (entityDecl == fDumEntityDecl); + + // Set the PE flag on it + entityDecl->setIsParameter(isPEDecl); + + // + // Space is legal (required actually) here so check for a PE ref. If + // we don't get our whitespace, then issue an error, but try to keep + // going. + // + if (!checkForPERef(true, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // According to the type call the value scanning method + if (!scanEntityDef(*entityDecl, isPEDecl)) + { + getReaderMgr()->skipPastChar(chCloseAngle); + if (!isIgnored) + delete entityDecl; + + getScanner()->emitError(XML4CErrs::ExpectedEntityValue); + return; + } + + // Space is legal (but not required) here so check for a PE ref + checkForPERef(false, false, true); + + // And then we have to have the closing angle bracket + if (!getReaderMgr()->skippedChar(chCloseAngle)) + { + getScanner()->emitError(XML4CErrs::UnterminatedEntityDecl); + getReaderMgr()->skipPastChar(chCloseAngle); + } + + // + // And add this guy to the appropriate entity decl pool, if it was + // not an override of an existing entity that we just parsed into the + // dummy decl. + // + if (!isIgnored) + { + if (isPEDecl) + fPEntityDeclPool->put(entityDecl); + else + fEntityDeclPool->put(entityDecl); + } + + // + // If we have a doc type handler, then call it. But only call it for + // ignored elements if advanced callbacks are enabled. + // + if (fDocTypeHandler) + { + fDocTypeHandler->entityDecl + ( + *entityDecl + , isPEDecl + , (entityDecl == fDumEntityDecl) + ); + } +} + + +// +// This method will scan a general/character entity ref. It will either +// expand a char ref and return the value directly, or it will expand +// a general entity and a reader for it onto the reader stack. +// +// The return value indicates whether the value was returned directly or +// pushed as a reader or it failed. +// +// The escaped flag tells the caller whether the returnd parameter resulted +// from a character reference, which escapes the character in some cases. It +// only makes any difference if the return indicates the value was returned +// directly. +// +// NOTE: This is only called when scanning attribute values, so we always +// expand general entities. +// +DTDValidator::EntityExpRes +DTDValidator::scanEntityRef(XMLCh& firstCh, XMLCh& secondCh, bool& escaped) +{ + // Assume no escape and no second char + escaped = false; + secondCh = 0; + + // We have to insure its all done in a single entity + const unsigned int curReader = getReaderMgr()->getCurrentReaderNum(); + + // + // If the next char is a pound, then its a character reference and we + // need to expand it always. + // + if (getReaderMgr()->skippedChar(chPound)) + { + // + // Its a character reference, so scan it and get back the numeric + // value it represents. If it fails, just return immediately. + // + if (!scanCharRef(firstCh, secondCh)) + return EntityExp_Failed; + + if (curReader != getReaderMgr()->getCurrentReaderNum()) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + + // Its now escaped since it was a char ref + escaped = true; + return EntityExp_Returned; + } + + // Get the name of the general entity + XMLBufBid bbName(getBufMgr()); + if (!getReaderMgr()->getName(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::ExpectedEntityRefName); + return EntityExp_Failed; + } + + // + // Next char must be a semi-colon. But if its not, just emit + // an error and try to continue. + // + if (!getReaderMgr()->skippedChar(chSemiColon)) + getScanner()->emitError(XML4CErrs::UnterminatedEntityRef); + + // Make sure it was all in one entity reader + if (curReader != getReaderMgr()->getCurrentReaderNum()) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + + // Look it up the name the general entity pool + XMLEntityDecl* decl = findEntityDecl(bbName.getRawBuffer(), false); + + // If it does not exist, then obviously an error + if (!decl) + { + getScanner()->emitError(XML4CErrs::EntityNotFound, bbName.getRawBuffer()); + return EntityExp_Failed; + } + + // + // If we are a standalone document, then it has to have been declared + // in the internal subset. Keep going though. + // + if (getScanner()->getStandalone() && !decl->getDeclaredInIntSubset()) + getScanner()->emitError(XML4CErrs::IllegalRefInStandalone, bbName.getRawBuffer()); + + // + // If its a special char reference, then its escaped and we can return + // it directly. + // + if (decl->getIsSpecialChar()) + { + firstCh = decl->getValue()[0]; + escaped = true; + return EntityExp_Returned; + } + + if (decl->isExternal()) + { + // If its unparsed, then its not valid here + if (decl->isUnparsed()) + { + getScanner()->emitError(XML4CErrs::NoUnparsedEntityRefs, bbName.getRawBuffer()); + return EntityExp_Failed; + } + + // We are in an attribute value, so not valid. But keep going + getScanner()->emitError(XML4CErrs::NoExtRefsInAttValue); + + // And now create a reader to read this entity + InputSource* srcUsed; + XMLReader* reader = getReaderMgr()->createReader + ( + decl->getSystemId() + , decl->getPublicId() + , false + , XMLReader::RefFrom_NonLiteral + , XMLReader::Type_General + , XMLReader::Source_External + , srcUsed + ); + + // Put a janitor on the source so it gets cleaned up on exit + Janitor<InputSource> janSrc(srcUsed); + + // + // If the creation failed then throw an exception + // + if (!reader) + ThrowXML1(RuntimeException, XML4CExcepts::Gen_CouldNotOpenExtEntity, srcUsed->getSystemId()); + + // + // Push the reader. If its a recursive expansion, then emit an error + // and return an failure. + // + if (!getReaderMgr()->pushReader(reader, decl)) + { + getScanner()->emitError(XML4CErrs::RecursiveEntity, decl->getName()); + return EntityExp_Failed; + } + + // Do a start entity reference event + if (getScanner()->getDocHandler()) + getScanner()->getDocHandler()->startEntityReference(*decl); + + // If it starts with the XML string, then parse a text decl + if (getReaderMgr()->skippedString(XMLUni::fgXMLDeclString)) + scanTextDecl(); + } + else + { + // + // Create a reader over a memory stream over the entity value + // We force it to assume UTF-16 by passing in an encoding + // string. This way it won't both trying to predecode the + // first line, looking for an XML/TextDecl. + // + XMLReader* valueReader = getReaderMgr()->createIntEntReader + ( + decl->getName() + , XMLReader::RefFrom_NonLiteral + , XMLReader::Type_General + , decl->getValue() + , decl->getValueLen() + , false + ); + + // + // Trt to push the entity reader onto the reader manager stack, + // where it will become the subsequent input. If it fails, that + // means the entity is recursive, so issue an error. The reader + // will have just been discarded, but we just keep going. + // + if (!getReaderMgr()->pushReader(valueReader, decl)) + getScanner()->emitError(XML4CErrs::RecursiveEntity, decl->getName()); + + // Do a start entity reference event + if (getScanner()->getDocHandler()) + getScanner()->getDocHandler()->startEntityReference(*decl); + } + + return EntityExp_Pushed; +} + + +// +// This method will scan a quoted literal of an entity value. It has to +// deal with replacement of PE references; however, since this is a DTD +// scanner, all such entity literals are in entity decls and therefore +// general entities are not expanded. +// +bool DTDValidator::scanEntityLiteral(XMLBuffer& toFill, const bool isPE) +{ + toFill.reset(); + + // Get the next char which must be a single or double quote + XMLCh quoteCh; + if (!getReaderMgr()->skipIfQuote(quoteCh)) + return false; + + // Get a buffer for pulling in entity names when we see GE refs + XMLBufBid bbName(getBufMgr()); + XMLBuffer& nameBuf = bbName.getBuffer(); + + // Remember the current reader + const unsigned int orgReader = getReaderMgr()->getCurrentReaderNum(); + + // + // Loop until we see the ending quote character, handling any references + // in the process. + // + XMLCh nextCh; + XMLCh secondCh = 0; + bool gotLeadingSurrogate = false; + while (true) + { + // Get the second char if we have one, else get another + if (secondCh) + { + nextCh = secondCh; + secondCh = 0; + } + else + { + nextCh = getReaderMgr()->getNextChar(); + } + + // + // Watch specifically for EOF and issue a more meaningful error + // if that occurs (since an unterminated quoted char can cause + // this easily.) + // + if (!nextCh) + { + getScanner()->emitError(XML4CErrs::UnterminatedEntityLiteral); + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + } + + // + // Break out on our terminating quote char when we are back in the + // same reader. Otherwise, we might trigger on a nested quote char + // in an expanded entity. + // + if ((nextCh == quoteCh) + && (getReaderMgr()->getCurrentReaderNum() == orgReader)) + { + break; + } + + if (nextCh == chPercent) + { + // + // Put the PE's value on the reader stack and then jump back + // to the top to start processing it. The parameter indicates + // that it should not scan the reference's content as an external + // subset. + // + expandPERef(false, true, true); + continue; + } + + // + // Ok, now that all the other special stuff is checked, we can + // look for a general entity. In here, we cannot have a naked & + // and will only expand numerical char refs or the intrinsic char + // refs. Others will be left alone. + // + if (nextCh == chAmpersand) + { + // + // Here, we only expand numeric char refs, but not any general + // entities. However, the stupid XML spec requires that we check + // and make sure it does refer to a general entity if its not + // a char ref (i.e. no naked '&' chars.) + // + if (getReaderMgr()->skippedChar(chPound)) + { + // If it failed, then just jump back to the top and try to pick up + if (!scanCharRef(nextCh, secondCh)) + { + gotLeadingSurrogate = false; + continue; + } + } + else + { + if (!getReaderMgr()->getName(nameBuf)) + { + getScanner()->emitError(XML4CErrs::ExpectedEntityRefName); + } + else + { + // + // Since we are not expanding any of this, we have to + // put the amp and name into the target buffer as data. + // + toFill.append(chAmpersand); + toFill.append(nameBuf.getRawBuffer()); + + // Make sure we skipped a trailing semicolon + if (!getReaderMgr()->skippedChar(chSemiColon)) + getScanner()->emitError(XML4CErrs::UnterminatedEntityRef); + + // And make the new character the semicolon + nextCh = chSemiColon; + } + + // Either way here we reset the surrogate flag + gotLeadingSurrogate = false; + } + } + + if ((nextCh >= 0xD800) && (nextCh <= 0xDBFF)) + { + if (gotLeadingSurrogate) + getScanner()->emitError(XML4CErrs::Expected2ndSurrogateChar); + else + gotLeadingSurrogate = true; + } + else + { + if (gotLeadingSurrogate) + { + if ((nextCh < 0xDC00) && (nextCh > 0xDFFF)) + getScanner()->emitError(XML4CErrs::Expected2ndSurrogateChar); + } + else if (!XMLReader::isXMLChar(nextCh)) + { + getScanner()->emitError(XML4CErrs::InvalidCharacter); + getReaderMgr()->skipPastChar(quoteCh); + return false; + } + gotLeadingSurrogate = false; + } + + // Looks ok, so add it to the literal + toFill.append(nextCh); + } + + // + // If we got here and did not get back to the original reader level, + // then we propogated some entity out of the literal, so issue an + // error, but don't fail. + // + if (getReaderMgr()->getCurrentReaderNum() != orgReader) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + + return true; +} + + +// +// This method is called after the entity name has been scanned, and any +// PE referenced following the name is handled. The passed decl will be +// filled in with the info scanned. +// +bool DTDValidator::scanEntityDef(DTDEntityDecl& decl, const bool isPEDecl) +{ + // Its got to be an entity literal + if (getReaderMgr()->lookingAtChar(chSingleQuote) + || getReaderMgr()->lookingAtChar(chDoubleQuote)) + { + // Get a buffer for the literal + XMLBufBid bbValue(getBufMgr()); + + if (!scanEntityLiteral(bbValue.getBuffer(), isPEDecl)) + return false; + + // Set it on the entity decl + decl.setValue(bbValue.getRawBuffer()); + return true; + } + + // + // Its got to be an external entity, so there must be an external id. + // Get buffers for them and scan an external id into them. + // + XMLBufBid bbPubId(getBufMgr()); + XMLBufBid bbSysId(getBufMgr()); + if (!scanId(bbPubId.getBuffer(), bbSysId.getBuffer(), IDType_External)) + return false; + + // Fill in the id fields of the decl with the info we got + decl.setPublicId(bbPubId.getRawBuffer()); + decl.setSystemId(bbSysId.getRawBuffer()); + + // If its a PE decl, we are done + bool gotSpaces = checkForPERef(false, false, true); + if (isPEDecl) + { + // + // Check for a common error here. NDATA is not allowed for PEs + // so check for the NDATA string. If found give a nice meaningful + // error and continue parsing to eat the NDATA text. + // + if (gotSpaces) + { + if (getReaderMgr()->skippedString(XMLUni::fgNDATAString)) + getScanner()->emitError(XML4CErrs::NDATANotValidForPE); + } + else + { + return true; + } + } + + // If looking at close angle now, we are done + if (getReaderMgr()->lookingAtChar(chCloseAngle)) + return true; + + // Else we had to have seem the whitespace + if (!gotSpaces) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // We now have to see a notation data string + if (!getReaderMgr()->skippedString(XMLUni::fgNDATAString)) + getScanner()->emitError(XML4CErrs::ExpectedNDATA); + + // Space is required here, but try to go on if not + if (!checkForPERef(false, false, true)) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // Get a name + XMLBufBid bbName(getBufMgr()); + if (!getReaderMgr()->getName(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::ExpectedNotationName); + return false; + } + + // Set the decl's notation name + decl.setNotationName(bbName.getRawBuffer()); + + return true; +} + + +// +// This method is called after an attribute decl name or a notation decl has +// been scanned and then an opening parenthesis was see, indicating the list +// of values. It scans the enumeration values and creates a single string +// which has a single space between each value. +// +// The terminating close paren ends this scan. +// +bool DTDValidator::scanEnumeration(XMLBuffer& toFill, const bool notation) +{ + // Reset the passed buffer + toFill.reset(); + + // Check for PE ref but don't require space + checkForPERef(false, false, true); + + // If this is a notation, we need an opening paren + if (notation) + { + if (!getReaderMgr()->skippedChar(chOpenParen)) + getScanner()->emitError(XML4CErrs::ExpectedOpenParen); + } + + // We need a local buffer to use as well + XMLBufBid bbTmp(getBufMgr()); + + while (true) + { + // Space is allowed here for either type so check for PE ref + checkForPERef(false, false, true); + + // And then get either a name or a name token + bool success; + if (notation) + success = getReaderMgr()->getName(bbTmp.getBuffer()); + else + success = getReaderMgr()->getNameToken(bbTmp.getBuffer()); + + if (!success) + { + getScanner()->emitError(XML4CErrs::ExpectedEnumValue); + return false; + } + + // Append this value to the target value + toFill.append(bbTmp.getRawBuffer(), bbTmp.getLen()); + + // Space is allowed here for either type so check for PE ref + checkForPERef(false, false, true); + + // Check for the terminating paren + if (getReaderMgr()->skippedChar(chCloseParen)) + break; + + // And append a space separator + toFill.append(chSpace); + + // Check for the pipe character separator + if (!getReaderMgr()->skippedChar(chPipe)) + { + getScanner()->emitError(XML4CErrs::ExpectedEnumSepOrParen); + return false; + } + } + return true; +} + + +bool DTDValidator::scanEq() +{ + getReaderMgr()->skipPastSpaces(); + if (getReaderMgr()->skippedChar(chEqual)) + { + getReaderMgr()->skipPastSpaces(); + return true; + } + return false; +} + + +// +// This method is called when an external entity reference is seen in the +// DTD or an external DTD subset is encountered, and their contents pushed +// onto the reader stack. This method will scan that contents. +// +void DTDValidator::scanExtSubsetDecl(const bool inIncludeSect) +{ + bool bAcceptDecl = !inIncludeSect; + + // Get a buffer for whitespace + XMLBufBid bbSpace(getBufMgr()); + + // + // If we have a doc type handler and we are not being called recursively + // to handle an include section, tell it the ext subset starts + // + if (fDocTypeHandler && !inIncludeSect) + fDocTypeHandler->startExtSubset(); + + // + // We have to play a trick here if the current entity we are parsing + // is a PE. Because the spooling code will put out a whitespace before + // and after an expanded PE if its being scanned outside the context of + // a literal entity, this will confuse this external subset code. + // + // So, we see if that is what is happening and, if so, eat the single + // space, a check for the <?xml string. If we find it, we parse that + // markup right now and put the space back. + // + if (getReaderMgr()->isScanningPERefOutOfLiteral()) + { + if (getReaderMgr()->skippedSpace()) + { + if (getReaderMgr()->skippedString(XMLUni::fgXMLDeclStringSpace)) + { + scanTextDecl(); + bAcceptDecl = false; + + // <TBD> Figure out how to do this + // getReaderMgr()->unGet(chSpace); + } + } + } + + // Get the current reader number + const unsigned int orgReader = getReaderMgr()->getCurrentReaderNum(); + + // + // Loop until we hit the end of the external subset entity. Note that + // we use a double loop here in order to avoid the overhead of doing + // the exception setup/teardown work on every loop. + // + bool inMarkup = false; + bool inCharData = false; + while (true) + { + try + { + while (true) + { + const XMLCh nextCh = getReaderMgr()->peekNextChar(); + + if (nextCh == chOpenAngle) + { + // Get the reader we started this on + const unsigned int orgReader = getReaderMgr()->getCurrentReaderNum(); + + // + // Now scan the markup. Set the flag so that we will know that + // we were in markup if an end of entity exception occurs. + // + getReaderMgr()->getNextChar(); + inMarkup = true; + scanMarkupDecl(bAcceptDecl); + inMarkup = false; + + // + // And see if we got back to the same level. If not, then its + // a partial markup error. + // + if (getReaderMgr()->getCurrentReaderNum() != orgReader) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + } + else if (XMLReader::isWhitespace(nextCh)) + { + // + // If we have a doc type handler, and advanced callbacks are + // enabled, then gather up whitespace and call back. Otherwise + // just skip whitespaces. + // + if (fDocTypeHandler) + { + inCharData = true; + getReaderMgr()->getSpaces(bbSpace.getBuffer()); + inCharData = false; + + fDocTypeHandler->doctypeWhitespace + ( + bbSpace.getRawBuffer() + , bbSpace.getLen() + ); + } + else + { + // + // If we hit an end of entity in the middle of white + // space, that's fine. We'll just come back in here + // again on the next round and skip some more. + // + getReaderMgr()->skipPastSpaces(); + } + } + else if (nextCh == chPercent) + { + // + // Expand (and scan if external) the reference value. Tell + // it to throw an end of entity exception at the end of the + // entity. + // + getReaderMgr()->getNextChar(); + expandPERef(true, false, false, true); + } + else if (inIncludeSect && (nextCh == chCloseSquare)) + { + // + // Its the end of a conditional include section. So scan it and + // decrement the include depth counter. + // + getReaderMgr()->getNextChar(); + if (!getReaderMgr()->skippedChar(chCloseSquare)) + { + getScanner()->emitError(XML4CErrs::ExpectedEndOfConditional); + getReaderMgr()->skipPastChar(chCloseAngle); + } + else if (!getReaderMgr()->skippedChar(chCloseAngle)) + { + getScanner()->emitError(XML4CErrs::ExpectedEndOfConditional); + getReaderMgr()->skipPastChar(chCloseAngle); + } + return; + } + else + { + getReaderMgr()->getNextChar(); + if (!XMLReader::isXMLChar(nextCh)) + getScanner()->emitError(XML4CErrs::InvalidCharacter); + else + getScanner()->emitError(XML4CErrs::InvalidDocumentStructure); + + // Try to get realigned + static const XMLCh toSkip[] = + { + chPercent, chCloseSquare, chOpenAngle, chNull + }; + getReaderMgr()->skipUntilInOrWS(toSkip); + } + bAcceptDecl = false; + } + } + + catch(const EndOfEntityException& toCatch) + { + // + // If the external entity ended while we were in markup, then that's + // a partial markup error. + // + if (inMarkup) + { + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + inMarkup = false; + } + + // If we were in char data, then send what we got + if (inCharData) + { + // Send what we got, then rethrow + if (fDocTypeHandler) + { + fDocTypeHandler->doctypeWhitespace + ( + bbSpace.getRawBuffer() + , bbSpace.getLen() + ); + } + inCharData = false; + } + + // + // If the entity that just ended was the entity that we started + // on, then this is the end of the external subset. + // + if (orgReader == toCatch.getReaderNum()) + break; + } + } + + // If we have a doc type handler, tell it the ext subset ends + if (fDocTypeHandler) + fDocTypeHandler->endExtSubset(); +} + + +// +// This method will scan for an id, either public or external. +// +bool DTDValidator::scanId( XMLBuffer& pubIdToFill + , XMLBuffer& sysIdToFill + , const IDTypes whatKind) +{ + // Clean out both return buffers + pubIdToFill.reset(); + sysIdToFill.reset(); + + // + // Check first for the system id first. If we find it, and system id + // is one of the legal values, then lets try to scan it. + // + if (getReaderMgr()->skippedString(XMLUni::fgSysIDString)) + { + // If they were looking for a public id, then we failed + if (whatKind == IDType_Public) + { + getScanner()->emitError(XML4CErrs::ExpectedPublicId); + return false; + } + + // We must skip spaces + if (!getReaderMgr()->skipPastSpaces()) + { + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + return false; + } + + // Get the system literal value + return scanSystemLiteral(sysIdToFill); + } + + // See if we have a public id string. If not, we are done and found nothing + if (!getReaderMgr()->skippedString(XMLUni::fgPubIDString)) + return false; + + // + // So following this we must have whitespace, a public literal, whitespace, + // and a system literal. + // + if (!getReaderMgr()->skipPastSpaces()) + { + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + + // + // Just in case, if they just forgot the whitespace but the next char + // is a single or double quote, then keep going. + // + const XMLCh chPeek = getReaderMgr()->peekNextChar(); + if ((chPeek != chDoubleQuote) && (chPeek != chSingleQuote)) + return false; + } + + if (!scanPublicLiteral(pubIdToFill)) + { + getScanner()->emitError(XML4CErrs::ExpectedPublicId); + return false; + } + + // If they wanted a public id, then this is all + if (whatKind == IDType_Public) + return true; + + // Else lets get the system id + if (!getReaderMgr()->skipPastSpaces()) + { + // + // In order to recover best here we need to see if we don't have + // whitespace because the next thing is a quote or because the next + // thing is some non-quote character. + // + const XMLCh chPeek = getReaderMgr()->peekNextChar(); + const bool bIsQuote = ((chPeek == chDoubleQuote) + || (chPeek == chSingleQuote)); + + if (whatKind == IDType_External) + { + // + // If its an external Id, then we need to see the system id. + // So, emit the error. But, if the next char is a quote, don't + // give up since its probably going to work. The user just + // missed the separating space. Otherwise, fail. + // + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + if (!bIsQuote) + return false; + } + else + { + // + // We can legally return here. But, if the next char is a quote, + // then that's probably not what was desired, since its probably + // just that space was forgotten and there really is a system + // id to follow. + // + // So treat it like missing whitespace if so and keep going. + // Else, just return success. + // + if (bIsQuote) + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + else + return true; + } + } + + if (!scanSystemLiteral(sysIdToFill)) + { + // Its only an error to not have it if we are doing an external + if (whatKind == IDType_External) + { + getScanner()->emitError(XML4CErrs::ExpectedSystemId); + return false; + } + } + return true; +} + + +// +// This method will scan the contents of an ignored section. It assumes that +// we already are in the body, i.e. we've seen <![IGNORE[ at this point. So +// we have to just scan until we see a matching ]]> closing markup. +// +void DTDValidator::scanIgnoredSection() +{ + // + // Depth starts at one because we are already in one section and want + // to parse until we hit its end. + // + unsigned long depth = 1; + while (true) + { + const XMLCh nextCh = getReaderMgr()->getNextChar(); + + if (!nextCh) + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + + if (nextCh == chOpenAngle) + { + if (getReaderMgr()->skippedChar(chBang) + && getReaderMgr()->skippedChar(chOpenSquare)) + { + depth++; + } + } + else if (nextCh == chCloseSquare) + { + if (getReaderMgr()->skippedChar(chCloseSquare)) + { + while (getReaderMgr()->skippedChar(chCloseSquare)) + { + // Do nothing, just skip them + } + + if (getReaderMgr()->skippedChar(chCloseAngle)) + { + depth--; + if (!depth) + break; + } + } + } + else if (!XMLReader::isXMLChar(nextCh)) + { + getScanner()->emitError(XML4CErrs::InvalidCharacter); + } + } +} + + +// +// This method scans the entire internal subset. All we can have here is +// decl markup, and PE references. The expanded PE references must contain +// whole markup, so we don't have to worry about their content at this +// level. We just scan them, expand them, push them, and parse their content +// right there, via the expandERef() method. +// +bool DTDValidator::scanInternalSubset() +{ + // If we have a doc type handler, tell it the internal subset starts + if (fDocTypeHandler) + fDocTypeHandler->startIntSubset(); + + // Get a buffer for whitespace + XMLBufBid bbSpace(getBufMgr()); + + bool noErrors = true; + while (true) + { + const XMLCh nextCh = getReaderMgr()->peekNextChar(); + + // + // If we get an end of file marker, just unget it and return a + // failure status. The caller will then see the end of file and + // faill out correctly. + // + if (!nextCh) + return false; + + // Watch for the end of internal subset marker + if (nextCh == chCloseSquare) + { + getReaderMgr()->getNextChar(); + break; + } + + if (nextCh == chPercent) + { + // + // Expand (and scan if external) the reference value. Tell + // it to set the reader to cause an end of entity exception + // when this reader dies, which is what the scanExtSubset + // method wants (who is called to scan this.) + // + getReaderMgr()->getNextChar(); + expandPERef(true, false, false, true); + } + else if (nextCh == chOpenAngle) + { + // Remember this reader before we start the scan + const unsigned int orgReader = getReaderMgr()->getCurrentReaderNum(); + + // And scan this markup + getReaderMgr()->getNextChar(); + scanMarkupDecl(false); + + // If we did not get back to entry level, then partial markup + if (getReaderMgr()->getCurrentReaderNum() != orgReader) + getScanner()->emitError(XML4CErrs::PartialMarkupInEntity); + } + else if (XMLReader::isWhitespace(nextCh)) + { + // + // IF we are doing advanced callbacks and have a doc type + // handler, then get the whitespace and call the doc type + // handler with it. Otherwise, just skip whitespace. + // + if (fDocTypeHandler) + { + getReaderMgr()->getSpaces(bbSpace.getBuffer()); + fDocTypeHandler->doctypeWhitespace + ( + bbSpace.getRawBuffer() + , bbSpace.getLen() + ); + } + else + { + getReaderMgr()->skipPastSpaces(); + } + } + else + { + getReaderMgr()->getNextChar(); + + // Not valid, so emit an error + getScanner()->emitError(XML4CErrs::InvalidCharacterInIntSubset); + + // + // If an '>', then probably an abnormally terminated + // internal subset so just return. + // + if (nextCh == chCloseAngle) + { + noErrors = false; + break; + } + + // + // Otherwise, try to sync back up by scanning forward for + // a reasonable start character. + // + static const XMLCh toSkip[] = + { + chPercent, chCloseSquare, chOpenAngle, chNull + }; + getReaderMgr()->skipUntilInOrWS(toSkip); + } + } + + // If we have a doc type handler, tell it the internal subset ends + if (fDocTypeHandler) + fDocTypeHandler->endIntSubset(); + + return noErrors; +} + + +// +// This method is called once we see a < in the input of an int/ext subset, +// which indicates the start of some sort of markup. +// +void DTDValidator::scanMarkupDecl(const bool parseTextDecl) +{ + // + // We only have two valid first characters here. One is a ! which opens + // some markup decl. The other is a ?, which could begin either a PI + // or a text decl. If parseTextDecl is false, we cannot accept a text + // decl. + // + const XMLCh nextCh = getReaderMgr()->getNextChar(); + + if (nextCh == chBang) + { + if (getReaderMgr()->skippedChar(chDash)) + { + if (getReaderMgr()->skippedChar(chDash)) + { + scanComment(); + } + else + { + getScanner()->emitError(XML4CErrs::CommentsMustStartWith); + getReaderMgr()->skipPastChar(chCloseAngle); + } + } + else if (getReaderMgr()->skippedChar(chOpenSquare)) + { + // + // Its a conditional section. This is only valid in the external + // subset, so issue an error if we aren't there. + // + if (fInternalSubset) + { + getScanner()->emitError(XML4CErrs::ConditionalSectInIntSubset); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // A PE ref can happen here, but space is not required + checkForPERef(false, false, true); + + if (getReaderMgr()->skippedString(XMLUni::fgIncludeString)) + { + checkForPERef(false, false, true); + + // Check for the following open square bracket + if (!getReaderMgr()->skippedChar(chOpenSquare)) + getScanner()->emitError(XML4CErrs::ExpectedINCLUDEBracket); + + checkForPERef(false, false, true); + + // + // Recurse back to the ext subset call again, telling it its + // in an include section. + // + scanExtSubsetDecl(true); + } + else if (getReaderMgr()->skippedString(XMLUni::fgIgnoreString)) + { + checkForPERef(false, false, true); + + // Check for the following open square bracket + if (!getReaderMgr()->skippedChar(chOpenSquare)) + getScanner()->emitError(XML4CErrs::ExpectedINCLUDEBracket); + + checkForPERef(false, false, true); + + // And scan over the ignored part + scanIgnoredSection(); + } + else + { + getScanner()->emitError(XML4CErrs::ExpectedIncOrIgn); + getReaderMgr()->skipPastChar(chCloseAngle); + } + } + else if (getReaderMgr()->skippedString(XMLUni::fgAttListString)) + { + scanAttListDecl(); + } + else if (getReaderMgr()->skippedString(XMLUni::fgElemString)) + { + scanElementDecl(); + } + else if (getReaderMgr()->skippedString(XMLUni::fgEntityString)) + { + scanEntityDecl(); + } + else if (getReaderMgr()->skippedString(XMLUni::fgNotationString)) + { + scanNotationDecl(); + } + else + { + getScanner()->emitError(XML4CErrs::ExpectedMarkupDecl); + getReaderMgr()->skipPastChar(chCloseAngle); + } + } + else if (nextCh == chQuestion) + { + // It could be a PI or the XML declaration. Check for Decl + bool gotDecl = getReaderMgr()->skippedString(XMLUni::fgXMLStringSpace); + + // + // Just in case, check for upper case. If found, issue + // an error, but keep going. + // + if (!gotDecl) + { + gotDecl = getReaderMgr()->skippedString(XMLUni::fgXMLStringSpaceU); + if (gotDecl) + getScanner()->emitError(XML4CErrs::XMLDeclMustBeLowerCase); + } + + if (gotDecl) + { + // If we are not accepting text decls, its an error + if (parseTextDecl) + { + scanTextDecl(); + } + else + { + // Emit the error and skip past this markup + getScanner()->emitError(XML4CErrs::TextDeclNotLegalHere); + getReaderMgr()->skipPastChar(chCloseAngle); + } + } + else + { + // It has to be a PI + scanPI(); + } + } + else + { + // Can't be valid so emit error and try to skip past end of this decl + getScanner()->emitError(XML4CErrs::ExpectedMarkupDecl); + getReaderMgr()->skipPastChar(chCloseAngle); + } +} + + +// +// This method is called for a mixed model element's content mode. We've +// already scanned past the '(PCDATA' part by the time we get here. So +// everything else is element names separated by | characters until we +// hit the end. The passed element decl's content model is filled in with +// the information found. +// +bool DTDValidator::scanMixed(DTDElementDecl& toFill) +{ + // + // The terminating star is only required if there is something more + // than (PCDATA). + // + bool starRequired = false; + + // Get a buffer to be used below to get element names + XMLBufBid bbName(getBufMgr()); + XMLBuffer& nameBuf = bbName.getBuffer(); + + // + // Create an initial content spec node. Its just a leaf node with a + // PCDATA element id. This current node pointer will be pushed down the + // tree as we go. + // + ContentSpecNode* curNode = new ContentSpecNode(XMLElementDecl::fgPCDataElemId); + + // + // Set the initial leaf as the temporary head. If we hit the first choice + // node, it will be set up here. When done, this is the node that's set + // as the content spec for the element. + // + ContentSpecNode* headNode = curNode; + + // Remember the original node so we can sense the first choice node + ContentSpecNode* orgNode = curNode; + + // + // We just loop around, getting the | character at the top and then + // looking for the next element name. We keep up with the last node + // and add each new one to its right node. + // + while (true) + { + // Spaces are legal here, so check for a PE ref, but don't require space + checkForPERef(false, false, true); + + // + // If its a star, then tell them they can't have reps in + // mixed model, but eat it and keep going. + // + if (getReaderMgr()->skippedChar(chAsterisk)) + { + getScanner()->emitError(XML4CErrs::NoRepInMixed); + continue; + } + + // Check for the next choice indicator + if (!getReaderMgr()->skippedChar(chPipe)) + { + // Has to be the closing paren now. + if (!getReaderMgr()->skippedChar(chCloseParen)) + { + getScanner()->emitError(XML4CErrs::UnterminatedContentModel); + delete headNode; + return false; + } + + if (!getReaderMgr()->skippedChar(chAsterisk) && starRequired) + getScanner()->emitError(XML4CErrs::ExpectedAsterisk); + + // + // Create a zero or more node and make the original head + // node its first child. + // + headNode = new ContentSpecNode + ( + ContentSpecNode::ZeroOrMore + , headNode + , 0 + ); + + // Store the head node as the content spec of the element. + toFill.setContentSpec(headNode); + break; + } + + // Its more than just a PCDATA, so an ending star will be required now + starRequired = true; + + // Space is legal here so check for a PE ref, but don't require space + checkForPERef(false, false, true); + + // Get a name token + if (!getReaderMgr()->getName(nameBuf)) + { + getScanner()->emitError(XML4CErrs::ExpectedElementName); + delete headNode; + return false; + } + + // + // Create a leaf node for it. If we can find the element id for + // this element, then use it. Else, we have to fault in an element + // decl, marked as created because of being in a content model. + // + unsigned int elemId = findElemId(nameBuf.getRawBuffer()); + if (elemId == XMLElementDecl::fgInvalidElemId) + { + DTDElementDecl* decl = new DTDElementDecl(nameBuf.getRawBuffer()); + decl->setCreateReason(XMLElementDecl::InContentModel); + fElemDeclPool->put(decl); + elemId = decl->getId(); + } + + // + // If the current node is the original node, this is the first choice + // node, so create an initial choice node with the current node and + // the new element id. Store this as the head node. + // + // Otherwise, we have to steal the right node of the previous choice + // and weave in another choice node there, which has the old choice + // as its left and the new leaf as its right. + // + if (curNode == orgNode) + { + curNode = new ContentSpecNode + ( + ContentSpecNode::Choice + , curNode + , new ContentSpecNode(elemId) + ); + + // Remember the top node + headNode = curNode; + } + else + { + ContentSpecNode* oldRight = curNode->orphanSecond(); + curNode->setSecond + ( + new ContentSpecNode + ( + ContentSpecNode::Choice + , oldRight + , new ContentSpecNode(elemId) + ) + ); + + // Make the new right node the current node + curNode = curNode->getSecond(); + } + } + + return true; +} + + +// +// This method is called when we see a '<!NOTATION' string while scanning +// markup decl. It parses out the notation and its id and stores a new +// notation decl object in the notation decl pool. +// +void DTDValidator::scanNotationDecl() +{ + // Space is required here so check for a PE ref, and require space + if (!checkForPERef(true, false, true)) + { + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // + // And now we get a name, which is the name of the notation. Get a + // buffer for the name. + // + XMLBufBid bbName(getBufMgr()); + if (!getReaderMgr()->getName(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::ExpectedNotationName); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // If namespaces are enabled, then no colons allowed + if (getScanner()->getDoNamespaces()) + { + if (XMLString::indexOf(bbName.getRawBuffer(), chColon) != -1) + getScanner()->emitError(XML4CErrs::ColonNotLegalWithNS); + } + + // Space is required here so check for a PE ref, and require space + if (!checkForPERef(true, false, true)) + { + getScanner()->emitError(XML4CErrs::ExpectedWhitespace); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // + // And scan an external or public id. We need buffers to use for both + // of these. + // + XMLBufBid bbPubId(getBufMgr()); + XMLBufBid bbSysId(getBufMgr()); + if (!scanId(bbPubId.getBuffer(), bbSysId.getBuffer(), IDType_Either)) + { + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // We can have an optional space or PE ref here + checkForPERef(false, false, true); + + // + // See if it already exists. If so, add it to the notatino decl pool. + // Otherwise, if advanced callbacks are on, create a temp one and + // call out for that one. + // + XMLNotationDecl* decl = fNotationDeclPool->getByKey(bbName.getRawBuffer()); + bool isIgnoring = (decl != 0); + if (isIgnoring) + { + getScanner()->emitError(XML4CErrs::NotationAlreadyExists, bbName.getRawBuffer()); + } + else + { + // Fill in a new notation declaration and add it to the pool + decl = new XMLNotationDecl + ( + bbName.getRawBuffer() + , bbPubId.getRawBuffer() + , bbSysId.getRawBuffer() + ); + fNotationDeclPool->put(decl); + } + + // + // If we have a document type handler, then tell it about this. If we + // are ignoring it, only call out if advanced callbacks are enabled. + // + if (fDocTypeHandler) + { + fDocTypeHandler->notationDecl + ( + *decl + , isIgnoring + ); + } + + // And one more optional space or PE ref + checkForPERef(false, false, true); + + // And skip the terminating bracket + if (!getReaderMgr()->skippedChar(chCloseAngle)) + getScanner()->emitError(XML4CErrs::UnterminatedNotationDecl); +} + + +// +// Scans a PI and calls the appropriate callbacks. A PI can happen in either +// the document or the DTD, so it calls the appropriate handler according +// to the fInDocument flag. +// +// At entry we have just scanned the <? part, and need to now start on the +// PI target name. +// +void DTDValidator::scanPI() +{ + const XMLCh* namePtr = 0; + const XMLCh* targetPtr = 0; + + // And skip any subsequent spaces before the name + getReaderMgr()->skipPastSpaces(); + + // Get a buffer for the PI name and scan it in + XMLBufBid bbName(getBufMgr()); + if (!getReaderMgr()->getNameToken(bbName.getBuffer())) + { + getScanner()->emitError(XML4CErrs::PINameExpected); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // Point the name pointer at the raw data + namePtr = bbName.getRawBuffer(); + + // See if it issome form of 'xml' and emit a warning + if (XMLString::compareIString(namePtr, XMLUni::fgXMLString)) + getScanner()->emitError(XML4CErrs::NoPIStartsWithXML); + + // If namespaces are enabled, then no colons allowed + if (getScanner()->getDoNamespaces()) + { + if (XMLString::indexOf(namePtr, chColon) != -1) + getScanner()->emitError(XML4CErrs::ColonNotLegalWithNS); + } + + // + // If we don't hit a space next, then the PI has no target. If we do + // then get out the target. Get a buffer for it as well + // + XMLBufBid bbTarget(getBufMgr()); + if (getReaderMgr()->skippedSpace()) + { + // Skip any leading spaces + getReaderMgr()->skipPastSpaces(); + + // It does have a target, so lets move on to deal with that. + while (1) + { + const XMLCh nextCh = getReaderMgr()->getNextChar(); + + // Watch for an end of file, which is always bad here + if (!nextCh) + { + getScanner()->emitError(XML4CErrs::UnterminatedPI); + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + } + + // Watch for potential terminating character + if (nextCh == chQuestion) + { + // It must be followed by '>' to be a termination of the target + if (getReaderMgr()->skippedChar(chCloseAngle)) + break; + } + + // Watch for invalid chars but try to keep going + if (!XMLReader::isXMLChar(nextCh)) + getScanner()->emitError(XML4CErrs::InvalidCharacter); + + bbTarget.append(nextCh); + } + } + else + { + // No target, but make sure its terminated ok + if (!getReaderMgr()->skippedChar(chQuestion)) + { + getScanner()->emitError(XML4CErrs::UnterminatedPI); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + if (!getReaderMgr()->skippedChar(chCloseAngle)) + { + getScanner()->emitError(XML4CErrs::UnterminatedPI); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + } + + // Point the target pointer at the raw data + targetPtr = bbTarget.getRawBuffer(); + + // + // If we have a handler, then call it. + // + if (fDocTypeHandler) + { + fDocTypeHandler->doctypePI + ( + namePtr + , targetPtr + ); + } +} + + +// +// This method scans a public literal. It must be quoted and all of its +// characters must be valid public id characters. The quotes are discarded +// and the results are returned. +// +bool DTDValidator::scanPublicLiteral(XMLBuffer& toFill) +{ + toFill.reset(); + + // Get the next char which must be a single or double quote + XMLCh quoteCh; + if (!getReaderMgr()->skipIfQuote(quoteCh)) + return false; + + while (true) + { + const XMLCh nextCh = getReaderMgr()->getNextChar(); + + // Watch for EOF + if (!nextCh) + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + + if (nextCh == quoteCh) + break; + + // + // If its not a valid public id char, then report it but keep going + // since that's the best recovery scheme. + // + if (!XMLReader::isPublicIdChar(nextCh)) + getScanner()->emitError(XML4CErrs::InvalidPublicIdChar); + + toFill.append(nextCh); + } + return true; +} + + +// +// This method handles scanning in a quoted system literal. It expects to +// start on the open quote and returns after eating the ending quote. There +// are not really any restrictions on the contents of system literals. +// +bool DTDValidator::scanSystemLiteral(XMLBuffer& toFill) +{ + toFill.reset(); + + // Get the next char which must be a single or double quote + XMLCh quoteCh; + if (!getReaderMgr()->skipIfQuote(quoteCh)) + return false; + + bool retVal = true; + while (retVal) + { + const XMLCh nextCh = getReaderMgr()->getNextChar(); + + // Watch for EOF + if (!nextCh) + ThrowXML(UnexpectedEOFException, XML4CExcepts::Gen_UnexpectedEOF); + + // Break out on terminating quote + if (nextCh == quoteCh) + break; + + toFill.append(nextCh); + } + return retVal; +} + + + +// +// This method is called to scan a text decl line, which can be the first +// line in an external entity or external subset. +// +// On entry the <? has been scanned, and next should be 'xml' followed by +// some whitespace, version string, etc... +// +void DTDValidator::scanTextDecl() +{ + // Skip any subsequent whitespace before the version string + getReaderMgr()->skipPastSpaces(); + + // Next should be the version string + XMLBufBid bbVersion(getBufMgr()); + if (getReaderMgr()->skippedString(XMLUni::fgVersionString)) + { + if (!scanEq()) + { + getScanner()->emitError(XML4CErrs::ExpectedEqSign); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // + // Followed by a single or double quoted version. Get a buffer for + // the string. + // + if (!getQuotedString(bbVersion.getBuffer())) + { + getScanner()->emitError(XML4CErrs::BadXMLVersion); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // If its not our supported version, issue an error but continue + if (XMLString::compareString(bbVersion.getRawBuffer(), XMLUni::fgSupportedVersion)) + getScanner()->emitError(XML4CErrs::UnsupportedXMLVersion, bbVersion.getRawBuffer()); + } + + // Ok, now we can have an encoding string, but we don't have to + XMLBufBid bbEncoding(getBufMgr()); + getReaderMgr()->skipPastSpaces(); + bool gotEncoding = false; + if (getReaderMgr()->skippedString(XMLUni::fgEncodingString)) + { + // There must be a equal sign next + if (!scanEq()) + { + getScanner()->emitError(XML4CErrs::ExpectedEqSign); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // Followed by a single or double quoted version string + getQuotedString(bbEncoding.getBuffer()); + if (bbEncoding.isEmpty()) + { + getScanner()->emitError(XML4CErrs::BadXMLEncoding); + getReaderMgr()->skipPastChar(chCloseAngle); + return; + } + + // Indicate that we got an encoding + gotEncoding = true; + } + + getReaderMgr()->skipPastSpaces(); + if (!getReaderMgr()->skippedChar(chQuestion)) + { + getScanner()->emitError(XML4CErrs::UnterminatedXMLDecl); + getReaderMgr()->skipPastChar(chCloseAngle); + } + else if (!getReaderMgr()->skippedChar(chCloseAngle)) + { + getScanner()->emitError(XML4CErrs::UnterminatedXMLDecl); + getReaderMgr()->skipPastChar(chCloseAngle); + } + + // + // If we have a document type handler and advanced callbacks are on, + // then call the TextDecl callback + // + if (fDocTypeHandler) + { + fDocTypeHandler->TextDecl + ( + bbVersion.getRawBuffer() + , bbEncoding.getRawBuffer() + ); + } + + // + // If we got an encoding string, then we have to call back on the reader + // to tell it what the encoding is. + // + if (!bbEncoding.isEmpty()) + { + if (!getReaderMgr()->getCurrentReader()->setEncoding(bbEncoding.getRawBuffer())) + getScanner()->emitError(XML4CErrs::ContradictoryEncoding, bbEncoding.getRawBuffer()); + } +} diff --git a/src/validators/DTD/DocTypeHandler.hpp b/src/validators/DTD/DocTypeHandler.hpp new file mode 100644 index 0000000000000000000000000000000000000000..204361b1acab56814198e1f22d4ae7c6e14d217c --- /dev/null +++ b/src/validators/DTD/DocTypeHandler.hpp @@ -0,0 +1,190 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:21 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:43 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + + +#if !defined(DOCTYPEHANDLER_HPP) +#define DOCTYPEHANDLER_HPP + +#include <util/XML4CDefs.hpp> +#include <framework/XMLNotationDecl.hpp> +#include <validators/DTD/DTDAttDef.hpp> +#include <validators/DTD/DTDElementDecl.hpp> +#include <validators/DTD/DTDEntityDecl.hpp> + + +// +// This abstract class defines the document type handler API's which can be +// used to process the DTD events generated by the validator as it scans the +// internal and external subset. The DTDValidator class allows you to plug +// in a derivative of this class in order to get callbacks for all of the +// important markup found during the DTD scan. +// +class VALIDATORS_EXPORT DocTypeHandler +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + DocTypeHandler() + { + } + + virtual ~DocTypeHandler() + { + } + + + // ----------------------------------------------------------------------- + // The document type handler virtual handler interface + // ----------------------------------------------------------------------- + virtual void attDef + ( + const DTDElementDecl& elemDecl + , const DTDAttDef& attDef + , const bool ignoring + ) = 0; + + virtual void doctypeComment + ( + const XMLCh* const comment + ) = 0; + + virtual void doctypeDecl + ( + const DTDElementDecl& elemDecl + , const XMLCh* const publicId + , const XMLCh* const systemId + , const bool hasIntSubset + ) = 0; + + virtual void doctypePI + ( + const XMLCh* const target + , const XMLCh* const data + ) = 0; + + virtual void doctypeWhitespace + ( + const XMLCh* const chars + , const unsigned int length + ) = 0; + + virtual void elementDecl + ( + const DTDElementDecl& decl + , const bool isIgnored + ) = 0; + + virtual void endAttList + ( + const DTDElementDecl& elemDecl + ) = 0; + + virtual void endIntSubset() = 0; + + virtual void endExtSubset() = 0; + + virtual void entityDecl + ( + const DTDEntityDecl& entityDecl + , const bool isPEDecl + , const bool isIgnored + ) = 0; + + virtual void resetDocType() = 0; + + virtual void notationDecl + ( + const XMLNotationDecl& notDecl + , const bool isIgnored + ) = 0; + + virtual void startAttList + ( + const DTDElementDecl& elemDecl + ) = 0; + + virtual void startIntSubset() = 0; + + virtual void startExtSubset() = 0; + + virtual void TextDecl + ( + const XMLCh* const versionStr + , const XMLCh* const encodingStr + ) = 0; + + +private: + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + DocTypeHandler(const DocTypeHandler&); + void operator=(const DocTypeHandler&); +}; + +#endif diff --git a/src/validators/DTD/Makefile.in b/src/validators/DTD/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..356d43661d7981fada9a968be871d68faf7df78b --- /dev/null +++ b/src/validators/DTD/Makefile.in @@ -0,0 +1,153 @@ +# +# 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/>. +# +# +# $Log$ +# Revision 1.1 1999/11/09 01:03:42 twl +# Initial revision +# +# Revision 1.3 1999/11/08 20:45:43 rahul +# Swat for adding in Product name and CVS comment log variable. +#: +# + +PLATFORM = @platform@ +COMPILER = @compiler@ +CXXFLAGS = @cxxflags@ +CFLAGS = @cflags@ +PREFIX = @prefix@ +LDFLAGS = @ldflags@ +LIBS = @libs@ +OSVER = @osver@ +USELIBWWW = @uselibwww@ +MESSAGELOADER = @messageloader@ +TRANSCODER = @transcoder@ + +include ../../Makefile.incl + +MODULE = validators +SUBMODULE = DTD + +VALIDATORS_DTD_CPP_PUBHEADERS = \ + CMBinaryOp.hpp \ + CMLeaf.hpp \ + CMNode.hpp \ + CMStateSet.hpp \ + CMUnaryOp.hpp \ + ContentSpecNode.hpp \ + DFAContentModel.hpp \ + DTDAttDef.hpp \ + DTDAttDefList.hpp \ + DTDElementDecl.hpp \ + DTDEntityDecl.hpp \ + DTDValidator.hpp \ + DocTypeHandler.hpp \ + MixedContentModel.hpp \ + SimpleContentModel.hpp + +VALIDATORS_DTD_CPP_PRIVHEADERS = + +VALIDATORS_DTD_C_FILES = + +VALIDATORS_DTD_CPP_OBJECTS = \ + CMBinaryOp.o \ + CMUnaryOp.o \ + ContentSpecNode.o \ + DFAContentModel.o \ + DTDAttDef.o \ + DTDAttDefList.o \ + DTDElementDecl.o \ + DTDValidator.o \ + DTDValidator2.o \ + MixedContentModel.o \ + SimpleContentModel.o + +all: includes $(VALIDATORS_DTD_CPP_OBJECTS) publish + +includes: pubheaders $(VALIDATORS_DTD_C_FILES) + +pubheaders: + -mkdir -p $(XML_INC_DIR)/$(MODULE)/$(SUBMODULE) + $(CP) $(VALIDATORS_DTD_CPP_PUBHEADERS) $(VALIDATORS_DTD_C_FILES) $(XML_INC_DIR)/$(MODULE)/$(SUBMODULE) + +publish: + -mkdir -p ${ALL_OBJECTS_DIR} + $(CP) $(VALIDATORS_DTD_CPP_OBJECTS) $(ALL_OBJECTS_DIR) + +# this may generate unnecessary dependencies, but it makes life easier +depend: includes + $(MAKE_DEPEND) $(XML_INCL) *.cpp > $(DEPFILE) + +clean: + @echo "Making clean in $(MODULE)/$(SUBMODULE) ..." + $(RM) $(VALIDATORS_DTD_CPP_OBJECTS) + +distclean: clean + $(RM) Makefile $(DEPFILE) + @echo "Removing all $(MODULE)/$(SUBMODULE) header files ..." + @for file in $(VALIDATORS_DTD_CPP_PUBHEADERS); do \ + rm -f $(XML_INC_DIR)/$(MODULE)/$(SUBMODULE)/$$file; \ + done + @for file in $(VALIDATORS_DTD_C_FILES); do \ + rm -f $(XML_INC_DIR)/$(MODULE)/$(SUBMODULE)/$$file; \ + done + @echo "Removing all $(MODULE)/$(SUBMODULE) object files ..." + @for file in $(VALIDATORS_DTD_CPP_OBJECTS); do \ + rm -f $(ALL_OBJECTS_DIR)/$$file; \ + done + +install: + -mkdir -p $(PREFIX)/$(MODULE)/$(SUBMODULE) + $(CP) $(VALIDATORS_DTD_CPP_PUBHEADERS) $(VALIDATORS_DTD_C_FILES) $(PREFIX)/$(MODULE)/$(SUBMODULE) diff --git a/src/validators/DTD/MixedContentModel.cpp b/src/validators/DTD/MixedContentModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..539bb3aabe85e256ac8aa998c551a50350303ccc --- /dev/null +++ b/src/validators/DTD/MixedContentModel.cpp @@ -0,0 +1,273 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:43 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:43 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <memory.h> +#include <string.h> +#include <util/RuntimeException.hpp> +#include <framework/XMLElementDecl.hpp> +#include <framework/XMLValidator.hpp> +#include <validators/DTD/ContentSpecNode.hpp> +#include <validators/DTD/DTDElementDecl.hpp> +#include <validators/DTD/MixedContentModel.hpp> +#include <validators/DTD/CMStateSet.hpp> + + +// --------------------------------------------------------------------------- +// MixedContentModel: Constructors and Destructor +// --------------------------------------------------------------------------- +MixedContentModel::MixedContentModel(const DTDElementDecl& parentElem) +{ + // + // Create a vector of unsigned ints that will be filled in with the + // ids of the child nodes. It will be expanded as needed but we give + // it an initial capacity of 64 which should be more than enough for + // 99% of the scenarios. + // + ValueVectorOf<unsigned int> childIds(64); + + // + // Get the parent element's content spec. This is the head of the tree + // of nodes that describes the content model. We will iterate this + // tree. + // + const ContentSpecNode* curNode = parentElem.getContentSpec(); + if (!curNode) + { + // <TBD> This is an error + } + + // And now call the private recursive method that iterates the tree + buildChildList(*curNode, childIds); + + // + // And now we know how many elements we need in our member list. So + // fill them in. + // + fCount = childIds.size(); + fChildIds = new unsigned int[fCount]; + memcpy(fChildIds, childIds.rawData(), fCount * sizeof(unsigned int)); +} + + +MixedContentModel::~MixedContentModel() +{ + delete [] fChildIds; +} + + +// --------------------------------------------------------------------------- +// MixedContentModel: Getter methods +// --------------------------------------------------------------------------- +bool MixedContentModel::hasDups() const +{ + // Can't have dups if only one child + if (fCount == 1) + return false; + + for (unsigned int index = 0; index < fCount; index++) + { + const unsigned int curVal = fChildIds[index]; + for (unsigned int iIndex = 0; iIndex < fCount; iIndex++) + { + if (iIndex == index) + continue; + + if (curVal == fChildIds[iIndex]) + return true; + } + } + return false; +} + + +// --------------------------------------------------------------------------- +// MixedContentModel: Implementation of the ContentModel virtual interface +// --------------------------------------------------------------------------- +bool MixedContentModel::getIsAmbiguous() const +{ + if (fCount < 2) + return false; + + unsigned int index; + + // + // Run through the children and remember the min and max element ids. + // These will be used to create a bit set that will map to element ids + // (adjusted by the min value.) + // + // Note that we skip the 0th element because its the PCDATA one. + // + unsigned int minId = 0xFFFFFFFF; + unsigned int maxId = 0; + for (index = 1; index < fCount; index++) + { + const unsigned int curId = fChildIds[index]; + if (curId < minId) + minId = curId; + + if (curId > maxId) + maxId = curId; + } + + // + // Ok, now we can create a range value that represents the spread + // between the min/max element value. + // + // With this number we can create a state set that has a bit per + // possible entry in the leaf array. + // + const unsigned int idRange = (maxId - minId) + 1; + CMStateSet idSet(idRange); + + for (index = 1; index < fCount; index++) + { + const unsigned int adjustedId = fChildIds[index] - minId; + if (idSet.getBit(adjustedId)) + return true; + idSet.setBit(adjustedId); + } + return false; +} + +int +MixedContentModel::validateContent( const unsigned int* childIds + , const unsigned int childCount) const +{ + // Use an outer index to search the passed list of children + for (unsigned int outIndex = 0; outIndex < childCount; outIndex++) + { + // Get the current child out of the source index + const unsigned int curChild = childIds[outIndex]; + + // If its PCDATA, then we just accept that + if (curChild == XMLElementDecl::fgPCDataElemId) + continue; + + // Otherwise try to find it in our list using an inner index + unsigned int inIndex = 0; + for (; inIndex < fCount; inIndex++) + { + if (curChild == fChildIds[inIndex]) + break; + } + + // + // We did not find this one, so the validation failed. We return + // the outer index, which is the index of the child that failed. + // + if (inIndex == fCount) + return outIndex; + } + + // Return success + return XMLValidator::Success; +} + + +// --------------------------------------------------------------------------- +// MixedContentModel: Private helper methods +// --------------------------------------------------------------------------- +void +MixedContentModel::buildChildList( const ContentSpecNode& curNode + , ValueVectorOf<unsigned int>& toFill) +{ + // Get the type of spec node our current node is + const ContentSpecNode::NodeTypes curType = curNode.getType(); + + // If its a leaf, then store its id in the target list + if (curType == ContentSpecNode::Leaf) + { + toFill.addElement(curNode.getElemId()); + return; + } + + // Get both the child node pointers + const ContentSpecNode* leftNode = curNode.getFirst(); + const ContentSpecNode* rightNode = curNode.getSecond(); + + // And recurse according to the type of node + if ((curType == ContentSpecNode::Choice) + || (curType == ContentSpecNode::Sequence)) + { + // Recurse on the left and right nodes + buildChildList(*leftNode, toFill); + + // The last node of a choice or sequence has a null right + if (rightNode) + buildChildList(*rightNode, toFill); + } + else if ((curType == ContentSpecNode::OneOrMore) + || (curType == ContentSpecNode::ZeroOrOne) + || (curType == ContentSpecNode::ZeroOrMore)) + { + // Just do the left node on this one + buildChildList(*leftNode, toFill); + } +} diff --git a/src/validators/DTD/MixedContentModel.hpp b/src/validators/DTD/MixedContentModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dc74d42000324001d2d39e0d128865e63543eb19 --- /dev/null +++ b/src/validators/DTD/MixedContentModel.hpp @@ -0,0 +1,155 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:45 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:45:43 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(MIXEDCONTENTMODEL_HPP) +#define MIXEDCONTENTMODEL_HPP + +#include <util/ValueVectorOf.hpp> +#include <framework/XMLContentModel.hpp> + +class ContentSpecNode; +class DTDElementDecl; + + +// +// MixedContentModel is a derivative of the abstract content model base +// class that handles the special case of mixed model elements. If an element +// is mixed model, it has PCDATA as its first possible content, followed +// by an alternation of the possible children. The children cannot have any +// numeration or order, so it must look like this: +// +// <!ELEMENT Foo ((#PCDATA|a|b|c|)*)> +// +// So, all we have to do is to keep an array of the possible children and +// validate by just looking up each child being validated by looking it up +// in the list. +// +class MixedContentModel : public XMLContentModel +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + MixedContentModel + ( + const DTDElementDecl& parentElem + ); + + ~MixedContentModel(); + + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool hasDups() const; + + + // ----------------------------------------------------------------------- + // Implementation of the ContentModel virtual interface + // ----------------------------------------------------------------------- + virtual bool getIsAmbiguous() const; + virtual int validateContent + ( + const unsigned int* childIds + , const unsigned int childCount + ) const; + + +private : + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + void buildChildList + ( + const ContentSpecNode& curNode + , ValueVectorOf<unsigned int>& toFill + ); + + + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + MixedContentModel(); + MixedContentModel(const MixedContentModel&); + void operator=(const MixedContentModel&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fCount + // The count of possible children in the fChildIds member. + // + // fChildIds + // The list of possible children that we have to accept. This array + // is allocated as large as needed in the constructor. + // ----------------------------------------------------------------------- + unsigned int fCount; + unsigned int* fChildIds; +}; + +#endif diff --git a/src/validators/DTD/SimpleContentModel.cpp b/src/validators/DTD/SimpleContentModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4a9122c1f57a3292e3b5dd0122ff6856898ef733 --- /dev/null +++ b/src/validators/DTD/SimpleContentModel.cpp @@ -0,0 +1,206 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:46 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:44 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/RuntimeException.hpp> +#include <validators/DTD/SimpleContentModel.hpp> + + +// --------------------------------------------------------------------------- +// SimpleContentModel: Implementation of the ContentModel virtual interface +// --------------------------------------------------------------------------- + +// +// For this content model, the only way it can be ambiguous is if it is a +// choice and both sides are the same. +// +bool SimpleContentModel::getIsAmbiguous() const +{ + if (fOp != ContentSpecNode::Choice) + return false; + + return fFirstChild == fSecondChild; +} + + +// +// This method is called to validate our content. For this one, its just a +// pretty simple 'bull your way through it' test according to what kind of +// operation it is for. +// +int +SimpleContentModel::validateContent(const unsigned int* childIds + , const unsigned int childCount) const +{ + // + // According to the type of operation, we do the correct type of + // content check. + // + unsigned int index; + switch(fOp) + { + case ContentSpecNode::Leaf : + // + // There can only be one child and it has to be of the + // element type we stored. + // + if (!childCount) + return 0; + + if (childIds[0] != fFirstChild) + return 0; + + if (childCount > 1) + return 1; + break; + + case ContentSpecNode::ZeroOrOne : + // + // If the child count is greater than one, then obviously + // bad. Otherwise, if its one, then the one child must be + // of the type we stored. + // + if ((childCount == 1) && (childIds[0] != fFirstChild)) + return 0; + + if (childCount > 1) + return 1; + break; + + case ContentSpecNode::ZeroOrMore : + // + // If the child count is zero, that's fine. If its more than + // zero, then make sure that all children are of the element + // type that we stored. + // + if (childCount > 0) + { + for (index = 0; index < childCount; index++) + { + if (childIds[index] != fFirstChild) + return index; + } + } + break; + + case ContentSpecNode::OneOrMore : + // + // If the child count is zero, that's an error. If its more + // than zero, then make sure that all children are of the + // element type that we stored. + // + if (childCount == 0) + return 0; + + for (index = 0; index < childCount; index++) + { + if (childIds[index] != fFirstChild) + return index; + } + break; + + case ContentSpecNode::Choice : + // + // There can only be one child, and it must be one of the + // two types we stored. + // + if (!childCount) + return 0; + + if ((childIds[0] != fFirstChild) && (childIds[0] != fSecondChild)) + return 0; + + if (childCount > 1) + return 1; + break; + + case ContentSpecNode::Sequence : + // + // There must be two children and they must be the two values + // we stored, in the stored order. + // + if (!childCount) + return 0; + + if ((childCount >= 1) && (childIds[0] != fFirstChild)) + return 0; + + if ((childCount >=2) && (childIds[1] != fSecondChild)) + return 1; + + if (childCount > 2) + return 2; + break; + + default : + ThrowXML(RuntimeException, XML4CExcepts::CM_UnknownCMSpecType); + break; + } + return -1; +} diff --git a/src/validators/DTD/SimpleContentModel.hpp b/src/validators/DTD/SimpleContentModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8873a58bfe94c014a8625d22d346212439263a55 --- /dev/null +++ b/src/validators/DTD/SimpleContentModel.hpp @@ -0,0 +1,172 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:03:48 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:45:44 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +#if !defined(SIMPLECONTENTMODEL_HPP) +#define SIMPLECONTENTMODEL_HPP + +#include <framework/XMLContentModel.hpp> +#include <validators/DTD/ContentSpecNode.hpp> + + +// +// SimpleContentModel is a derivative of the abstract content model base +// class that handles a small set of simple content models that are just +// way overkill to give the DFA treatment. +// +// DESCRIPTION: +// +// This guy handles the following scenarios: +// +// a +// a? +// a* +// a+ +// a,b +// a|b +// +// These all involve a unary operation with one element type, or a binary +// operation with two elements. These are very simple and can be checked +// in a simple way without a DFA and without the overhead of setting up a +// DFA for such a simple check. +// +// NOTE: Pass the XMLElementDecl::fgPCDataElemId value to represent a +// PCData node. Pass XMLElementDecl::fgInvalidElemId for unused ids. +// +class SimpleContentModel : public XMLContentModel +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + SimpleContentModel + ( + const unsigned int firstChildId + , const unsigned int secondChildId + , const ContentSpecNode::NodeTypes cmOp + ); + + ~SimpleContentModel(); + + + // ----------------------------------------------------------------------- + // Implementation of the ContentModel virtual interface + // ----------------------------------------------------------------------- + virtual bool getIsAmbiguous() const; + virtual int validateContent + ( + const unsigned int* childIds + , const unsigned int childCount + ) const; + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + SimpleContentModel(); + SimpleContentModel(const SimpleContentModel&); + void operator=(const SimpleContentModel&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fFirstChild + // fSecondChild + // The element idsof the first (and optional second) child node. The + // operation code tells us whether the second child is used or not. + // + // fOp + // The operation that this object represents. Since this class only + // does simple contents, there is only ever a single operation + // involved (i.e. the children of the operation are always one or + // two leafs.) + // ----------------------------------------------------------------------- + unsigned int fFirstChild; + unsigned int fSecondChild; + ContentSpecNode::NodeTypes fOp; +}; + + +// --------------------------------------------------------------------------- +// SimpleContentModel: Constructors and Destructor +// --------------------------------------------------------------------------- +inline +SimpleContentModel::SimpleContentModel( const unsigned int firstChildId + , const unsigned int secondChildId + , const ContentSpecNode::NodeTypes cmOp) : + fOp(cmOp) + , fFirstChild(firstChildId) + , fSecondChild(secondChildId) +{ +} + +inline SimpleContentModel::~SimpleContentModel() +{ +} + +#endif diff --git a/tests/DOM/DOMMemTest/DOMMemTest.cpp b/tests/DOM/DOMMemTest/DOMMemTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d3cbc7354e01939c7c249c213eca7114d59d04a1 --- /dev/null +++ b/tests/DOM/DOMMemTest/DOMMemTest.cpp @@ -0,0 +1,727 @@ +/* + * 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/>. + */ + +// +// Various DOM tests. +// Contents include +// 1. Basic functionality for DOMString +// 2. Regression tests for bugs fixed. +// All individual are wrapped in a memory leak checker. +// +// This is NOT a complete test of DOM functionality. +// + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:43 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:24 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#include <stdio.h> +#include <dom/DOM.hpp> +#include <dom/DomMemDebug.hpp> +#include <util/PlatformUtils.hpp> +#include <util/Exception.hpp> +#include <util/StdOut.hpp> + + +#define TASSERT(c) tassert((c), __FILE__, __LINE__) + +void tassert(bool c, char *file, int line) +{ + if (!c) + printf("Failure. Line %d, file %s\n", line, file); +}; + + +#define TESTPROLOG entryMemState = DomMemDebug(); + +#define TESTEPILOG \ + exitMemState = DomMemDebug(); \ + if (entryMemState != exitMemState) { \ + printf(" Memory leak at line %d, file %s: ", __LINE__, __FILE__); \ + exitMemState.printDifference(entryMemState); \ + } + + + +void main() +{ + DomMemDebug entryMemState, exitMemState; + + XMLStdOut errStrm; + try { + XMLPlatformUtils::Initialize(); + } + catch (const XMLException& toCatch) { + errStrm << "Error during initialization! :\n" + << toCatch.getMessage() << EndLn; + return ; + } + // + // Test 1. Basic operations on a simple string. + // + printf("DOM Memory Test.\n"); + TESTPROLOG; + { + DOMString foo = "fop"; + TASSERT(foo.length() == 3); + TASSERT(foo.equals(foo)); + TASSERT(foo != 0); + TASSERT(foo.charAt(0) == 'f'); + TASSERT(foo.charAt(2) == 'p'); + TASSERT(foo.charAt(3) == 0); + } + TESTEPILOG + + + // + // Construct from XMLCh * + // + TESTPROLOG + { + + XMLCh a[] = {'H', 'e', 'l', 'l', 'o', 0}; + DOMString x(a); + DOMString y = "Hello"; + + TASSERT(x.equals(y)); + } + TESTEPILOG + + // + // Test 2. Empty strings shouldn't leave anything lying around + // + TESTPROLOG; + { + DOMString a; + DOMString b; + TASSERT (a==0); + } + TESTEPILOG + + + // + // Test 3. Clones should be equal. + TESTPROLOG; + { + DOMString a = "hello"; + DOMString b = a.clone(); + TASSERT(a.equals(b)); + TASSERT(a != b); + } + TESTEPILOG + + + // + // Test 4. Copy construction and assignemnt + // + TESTPROLOG; + { + DOMString a = "Test 04"; + DOMString b(a); + DOMString c = a; + DOMString d; + DOMString e; + d = a; + TASSERT(a==b); + TASSERT(a==c); + TASSERT(a==d); + TASSERT(a!=e); + // printf (" test04 should have 1 handle, 1 buffer here. "); + } + TESTEPILOG + + + // + // Test 5 AppendData, degenerate cases. + // + TESTPROLOG; + { + DOMString a; + DOMString b = "Test 05"; + + a.appendData(b); + TASSERT(a.equals(b)); + TASSERT(a!=b); + TASSERT(a.equals("Test 05")); + }; + TESTEPILOG + + + // + // Test 6 Append data, degenerate case 2 + // + TESTPROLOG; + { + DOMString a; + DOMString b = "Test 06"; + + b.appendData(a); + TASSERT(!a.equals(b)); + TASSERT(a!=b); + TASSERT(b.equals("Test 06")); + TASSERT(a==0); + } + TESTEPILOG + + + // + // Test 7 Append Data, Common case, no extra space in original buffer. + // + TESTPROLOG; + { + DOMString a = "Test 07"; + DOMString b = "append"; + + a.appendData(b); + TASSERT(a.equals("Test 07append")); + TASSERT(b.equals("append")); + } + TESTEPILOG + + + // + // Test 8 Append Data, with plenty of extra space in buffer. + // + TESTPROLOG; + { + DOMString a(100); + DOMString b("Test 08"); + DOMString c("append"); + + // TASSERT(a == 0); // (should it?) + TASSERT(a.length() == 0); + a.appendData(b); + TASSERT(a.equals(b)); + TASSERT(a.equals("Test 08")); + TASSERT(a != b); + a.appendData(c); + TASSERT(a.equals("Test 08append")); + TASSERT(b.equals("Test 08")); + TASSERT(c.equals("append")); + }; + TESTEPILOG + + + + // + // Test 9 Append Data, with plenty of extra space in buffer, but with + // a clone, so that the original buffer can not be modified. + // + TESTPROLOG; + { + DOMString a(100); + DOMString b("Test 09"); + DOMString c("append"); + + TASSERT(a.length() == 0); + a.appendData(b); + TASSERT(a.equals(b)); + TASSERT(a.equals("Test 09")); + TASSERT(a != b); + + DOMString d = a.clone(); + TASSERT(a.equals("Test 09")); + TASSERT(b.equals("Test 09")); + TASSERT(d.equals("Test 09")); + TASSERT(a != b); + TASSERT(a != d); + TASSERT(b != d); + + a.appendData(c); + TASSERT(a.equals("Test 09append")); + TASSERT(b.equals("Test 09")); + TASSERT(c.equals("append")); + TASSERT(d.equals("Test 09")); + }; + TESTEPILOG + + + // + // Test Doc01 Create a new empty document + // + { + // First precondition, so that lazily created strings do not appear + // as memory leaks. + DOM_Document doc; + doc = DOM_Document::createDocument(); + } + TESTPROLOG; + { + DOM_Document doc; + doc = DOM_Document::createDocument(); + } + TESTEPILOG + + // + // Test Doc02 Create one of each kind of node using the + // document createXXX methods. + // Watch for memory leaks. + // + { + // Do all operations in a preconditioning step, to force the + // creation of implementation objects that are set up on first use. + // Don't watch for leaks in this block (no TESTPROLOG / TESTEPILOG) + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element el = doc.createElement("Doc02Element"); + DOM_DocumentFragment frag = doc.createDocumentFragment (); + DOM_Text text = doc.createTextNode("Doc02TextNode"); + DOM_Comment comment = doc.createComment("Doc02Comment"); + DOM_CDATASection cdataSec = doc.createCDATASection("Doc02CDataSection"); + DOM_DocumentType docType = doc.createDocumentType("Doc02DocumentType"); + DOM_Notation notation = doc.createNotation("Doc02Notation"); + DOM_ProcessingInstruction pi = doc.createProcessingInstruction("Doc02PITarget", + "Doc02PIData"); + DOM_NodeList nodeList = doc.getElementsByTagName("*"); + } + + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element el = doc.createElement("Doc02Element"); + } + TESTEPILOG; + + TESTPROLOG + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_DocumentFragment frag = doc.createDocumentFragment (); + }; + TESTEPILOG + + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element el = doc.createElement("Doc02Element"); + } + TESTEPILOG; + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Text text = doc.createTextNode("Doc02TextNode"); + } + TESTEPILOG; + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Comment comment = doc.createComment("Doc02Comment"); + } + TESTEPILOG; + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_CDATASection cdataSec = doc.createCDATASection("Doc02CDataSection"); + } + TESTEPILOG; + + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_DocumentType docType = doc.createDocumentType("Doc02DocumentType"); + } + TESTEPILOG; + + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Notation notation = doc.createNotation("Doc02Notation"); + } + TESTEPILOG; + + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_ProcessingInstruction pi = doc.createProcessingInstruction("Doc02PITarget", + "Doc02PIData"); + } + TESTEPILOG; + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Attr attribute = doc.createAttribute("Doc02Attribute"); + } + TESTEPILOG; + + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_EntityReference er = doc.createEntityReference("Doc02EntityReference"); + } + TESTEPILOG; + + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_NodeList nodeList = doc.getElementsByTagName("*"); + } + TESTEPILOG; + + + // + // Doc03 - Create a small document tree + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element rootEl = doc.createElement("Doc03RootElement"); + doc.appendChild(rootEl); + DOM_Text textNode = doc.createTextNode("Doc03 text stuff"); + rootEl.appendChild(textNode); + + DOM_NodeList nodeList = doc.getElementsByTagName("*"); + }; + TESTEPILOG; + + + // + // Attr01 + // + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element rootEl = doc.createElement("RootElement"); + doc.appendChild(rootEl); + { + DOM_Attr attr01 = doc.createAttribute("Attr01"); + rootEl.setAttributeNode(attr01); + } + + TESTPROLOG; + { + DOM_Attr attr02 = doc.createAttribute("Attr01"); + rootEl.setAttributeNode(attr02); + } + TESTEPILOG + }; + + // + // Attr02 + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element rootEl = doc.createElement("RootElement"); + doc.appendChild(rootEl); + DOM_Attr attr01 = doc.createAttribute("Attr02"); + rootEl.setAttributeNode(attr01); + DOM_Attr attr02 = doc.createAttribute("Attr02"); + rootEl.setAttributeNode(attr02); + } + TESTEPILOG; + + + // + // Attr03 + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element rootEl = doc.createElement("RootElement"); + doc.appendChild(rootEl); + DOM_Attr attr01 = doc.createAttribute("Attr03"); + rootEl.setAttributeNode(attr01); + + attr01.setValue("Attr03Value1"); + attr01.setValue("Attr03Value2"); + } + TESTEPILOG; + + + + // + // Text01 + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element rootEl = doc.createElement("RootElement"); + doc.appendChild(rootEl); + + + DOM_Text txt1 = doc.createTextNode("Hello Goodbye"); + rootEl.appendChild(txt1); + + txt1.splitText(6); + rootEl.normalize(); + + } + TESTEPILOG; + + + // + // Notation01 + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_DocumentType dt = doc.createDocumentType("DocType_for_Notation01"); + doc.appendChild(dt); + + + DOM_NamedNodeMap notationMap = dt.getNotations(); + DOM_Notation nt1 = doc.createNotation("Notation01"); + nt1.setPublicId("Notation01PublicId"); + notationMap.setNamedItem (nt1); + DOM_Notation nt2 = (DOM_Notation &)notationMap.getNamedItem("Notation01"); + TASSERT(nt1==nt2); + nt2 = DOM_Notation(); + nt1 = 0; + nt2 = (DOM_Notation &)notationMap.getNamedItem("Notation01"); + + + } + TESTEPILOG; + + + // + // NamedNodeMap01 - comparison operators. + // + TESTPROLOG; + { + DOM_NamedNodeMap nnm; + TASSERT(nnm == 0); + + DOM_Document doc = DOM_Document::createDocument(); + nnm = doc.getAttributes(); // Should be null, because node type + // is not Element. + TASSERT(nnm == 0); + TASSERT(!(nnm != 0)); + + DOM_Element el = doc.createElement("NamedNodeMap01"); + DOM_NamedNodeMap nnm2 = el.getAttributes(); // Should be an empty, but non-null map. + TASSERT(nnm2 != 0); + TASSERT(nnm != nnm2); + nnm = nnm2; + TASSERT(nnm == nnm2); + } + TESTEPILOG; + + + // + // importNode quick test + // + TESTPROLOG + { + DOM_Document doc1 = DOM_Document::createDocument(); + DOM_Document doc2 = DOM_Document::createDocument(); + + DOM_Element el1 = doc1.createElement("abc"); + doc1.appendChild(el1); + TASSERT(el1.getParentNode() != 0); + DOM_Node el2 = doc2.importNode(el1, true); + TASSERT(el2.getParentNode() == 0); + DOMString tagName = el2.getNodeName(); + TASSERT(tagName.equals("abc")); + TASSERT(el2.getOwnerDocument() == doc2); + TASSERT(doc1 != doc2); + } + TESTEPILOG; + + // + // getLength() tests. Both Node CharacterData and NodeList implement + // getLength(). Early versions of the DOM had a clash + // between the two, originating in the implementation class + // hirearchy, which has NodeList as a (distant) base class + // of CharacterData. This is a regression test to verify + // that the problem stays fixed. + // + TESTPROLOG + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Text tx = doc.createTextNode("Hello"); + DOM_Element el = doc.createElement("abc"); + el.appendChild(tx); + + int textLength = tx.getLength(); + TASSERT(textLength == 5); + + DOM_NodeList nl = tx.getChildNodes(); + int nodeListLen = nl.getLength(); + TASSERT(nodeListLen == 0); + + nl = el.getChildNodes(); + nodeListLen = nl.getLength(); + TASSERT(nodeListLen == 1); + } + + + // + // NodeList - comparison operators, basic operation. + // + TESTPROLOG; + { + DOM_NodeList nl; + DOM_NodeList nl2; + TASSERT(nl == 0); + TASSERT(!(nl != 0)); + TASSERT(nl == nl2); + + DOM_Document doc = DOM_Document::createDocument(); + nl = doc.getChildNodes(); // Should be non-null, but empty + + TASSERT(nl != 0); + int len = nl.getLength(); + TASSERT(len == 0); + + DOM_Element el = doc.createElement("NodeList01"); + doc.appendChild(el); + len = nl.getLength(); + TASSERT(len == 1); + TASSERT(nl != nl2); + nl2 = nl; + TASSERT(nl == nl2); + } + TESTEPILOG; + + + + // + // Name validity checking. + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + try + { + DOM_Element el = doc.createElement("!@@ bad element name"); + TASSERT(false); // Exception above should prevent us reaching here. + } + catch ( DOM_DOMException *e) + { + TASSERT(e->code == DOM_DOMException::INVALID_CHARACTER_ERR); + delete e; + } + catch (...) + { + TASSERT(false); // Wrong exception thrown. + } + } + TESTEPILOG; + + + // + // Assignment ops return value + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element el = doc.createElement("NodeList01"); + doc.appendChild(el); + + DOM_Element n1, n2, n3; + + n1 = n2 = n3 = el; + TASSERT(n1 == n2); + TASSERT(n1 == n3); + TASSERT(n1 == el); + TASSERT(n1 != 0); + n1 = n2 = n3 = 0; + TASSERT(n1 == 0); + } + TESTEPILOG; + + + // + // Cloning of a node with attributes. Regression test for a ref counting + // bug in attributes of cloned nodes that occured when the "owned" flag + // was not set in the clone. + // + TESTPROLOG; + { + DOM_Document doc = DOM_Document::createDocument(); + DOM_Element root = doc.createElement("CTestRoot"); + root.setAttribute("CTestAttr", "CTestAttrValue"); + + DOMString s = root.getAttribute("CTestAttr"); + TASSERT(s.equals("CTestAttrValue")); + + DOM_Element cloned = (DOM_Element &)root.cloneNode(true); + DOM_Attr a = cloned.getAttributeNode("CTestAttr"); + TASSERT(a != 0); + s = a.getValue(); + TASSERT(s.equals("CTestAttrValue")); + a = 0; + + a = cloned.getAttributeNode("CTestAttr"); + TASSERT(a != 0); + s = a.getValue(); + TASSERT(s.equals("CTestAttrValue")); + + } + TESTEPILOG; + + + // + // Print Final allocation stats for full test + // + DomMemDebug().print(); + +}; + diff --git a/tests/DOM/DOMTest/DTest.cpp b/tests/DOM/DOMTest/DTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..820b96d242c57f778214071461119b3c5e679761 --- /dev/null +++ b/tests/DOM/DOMTest/DTest.cpp @@ -0,0 +1,1909 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:34 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:24 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + + +/** + * This class tests methods for XML DOM implementation + * version 2.0 10/12/98 + * + * DOM_DOMException errors are tested by calls to DOMExceptionsTest from: Main, docBuilder... + * + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:34 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:24 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#include <stdio.h> +#include "DTest.h" +#include <util/PlatformUtils.hpp> +#include <util/Exception.hpp> +#include <util/StdOut.hpp> + + +#define EXCEPTIONSTEST(operation, expectedException, resultFlag, testNum) \ + { \ + try \ + { \ + operation; \ + fprintf(stderr, "Exceptions Test # %d: no Exception thrown.\n", testNum); \ + } \ + catch (DOM_DOMException *e) \ + { \ + if (e->code != expectedException) { \ + fprintf(stderr, "Exceptions Test # %d: wrong DOM_DOMException thrown.\n", \ + testNum); \ + resultFlag = false; \ + } \ + } \ + catch (...) \ + { \ + fprintf(stderr, "Exceptions Test # %d: unknown exception thrown.\n", \ + testNum); \ + resultFlag = false; \ + } \ + } + + +#define LEAKTEST(operation) \ +{ \ + operation; /* Precondition */ \ + DomMemDebug entryMemState; \ + { \ + operation; \ + } \ + DomMemDebug exitMemState; \ + if (entryMemState != exitMemState) \ + { \ + printf("Memory Leak at line %d\n", __LINE__); \ + exitMemState.printDifference(entryMemState); \ + } \ +} + + + + +DOM_Element DTest::testElementNode; +DOM_Attr DTest::testAttributeNode; +DOM_Text DTest::testTextNode; +DOM_CDATASection DTest::testCDATASectionNode; +DOM_EntityReference DTest::testEntityReferenceNode; +DOM_Entity DTest::testEntityNode; +DOM_ProcessingInstruction DTest::testProcessingInstructionNode; +DOM_Comment DTest::testCommentNode; +DOM_Document DTest::testDocumentNode; +DOM_DocumentType DTest::testDocumentTypeNode; +DOM_DocumentFragment DTest::testDocumentFragmentNode; +DOM_Notation DTest::testNotationNode; + +/** + * + * version 2.0 10/12/98 + * + */ + +DTest::DTest() +{ +}; + + +/** + * version 3.0 01/25/99 + * + * @return DOM_Document + * + */ +DOM_Document DTest::createDocument() { + return DOM_Document::createDocument(); +}; + + +/** + * version 3.0 01/25/99 + * + * @return DOM_DocumentType + * @param name DOMString + * + */ +DOM_DocumentType DTest::createDocumentType(DOM_Document doc, DOMString name) { + return doc.createDocumentType(name); //Replace with a DOM_DocumentType creator +}; + + +/** + * version 3.0 01/25/99 + * + * @return org.w3c.dom.DOM_Entity + * @param doc org.w3c.dom.DOM_Document + * @param name DOMString + * + */ +DOM_Entity DTest::createEntity(DOM_Document doc, DOMString name) { + return doc.createEntity(name); +}; + + + +/** + * version 3.0 01/25/99 + * + * @return org.w3c.dom.DOM_Notation + * @param doc org.w3c.dom.DOM_Document + * @param name DOMString + * + */ +DOM_Notation DTest::createNotation(DOM_Document doc, DOMString name) { + return doc.createNotation(name); +}; + + +/** + * This method builds test documents for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * @param name document's name + * @param type document's type + * + */ +void DTest::docBuilder(DOM_Document document, DOMString name) +{ + DOM_Document doc = document; + bool OK = true; + + DOM_Element docFirstElement = doc.createElement(name + "FirstElement"); + doc.appendChild(docFirstElement); + docFirstElement.setAttribute(name + "FirstElement", name + "firstElement"); + + DOM_ProcessingInstruction docProcessingInstruction = doc.createProcessingInstruction(name + + "TargetProcessorChannel", DOMString("This is ") + doc.getNodeName() + "'s processing instruction"); + docFirstElement.appendChild(docProcessingInstruction); + + DOM_Element docBody = doc.createElement(name + "TestBody"); + docFirstElement.appendChild(docBody); + + DOM_Element docBodyLevel21 = doc.createElement(name + "BodyLevel21"); + DOM_Element docBodyLevel22 = doc.createElement(name + "BodyLevel22"); + DOM_Element docBodyLevel23 = doc.createElement(name + "BodyLevel23"); + DOM_Element docBodyLevel24 = doc.createElement(name + "BodyLevel24"); + docBody.appendChild(docBodyLevel21); + docBody.appendChild(docBodyLevel22); + docBody.appendChild(docBodyLevel23); + docBody.appendChild(docBodyLevel24); + + DOM_Element docBodyLevel31 = doc.createElement(name + "BodyLevel31"); + DOM_Element docBodyLevel32 = doc.createElement(name + "BodyLevel32"); + DOM_Element docBodyLevel33 = doc.createElement(name + "BodyLevel33"); + DOM_Element docBodyLevel34 = doc.createElement(name + "BodyLevel34"); + docBodyLevel21.appendChild(docBodyLevel31); + docBodyLevel21.appendChild(docBodyLevel32); + docBodyLevel22.appendChild(docBodyLevel33); + docBodyLevel22.appendChild(docBodyLevel34); + + DOM_Text docTextNode11 = doc.createTextNode(name + "BodyLevel31'sChildTextNode11"); + DOM_Text docTextNode12 = doc.createTextNode(name + "BodyLevel31'sChildTextNode12"); + DOM_Text docTextNode13 = doc.createTextNode(name + "BodyLevel31'sChildTextNode13"); + DOM_Text docTextNode2 = doc.createTextNode(name + "TextNode2"); + DOM_Text docTextNode3 = doc.createTextNode(name + "TextNode3"); + DOM_Text docTextNode4 = doc.createTextNode(name + "TextNode4"); + docBodyLevel31.appendChild(docTextNode11); + docBodyLevel31.appendChild(docTextNode12); + docBodyLevel31.appendChild(docTextNode13); + docBodyLevel32.appendChild(docTextNode2); + docBodyLevel33.appendChild(docTextNode3); + docBodyLevel34.appendChild(docTextNode4); + + DOM_CDATASection docCDATASection = doc.createCDATASection("<![CDATA[<greeting>Hello, world!</greeting>]]>"); + docBodyLevel23.appendChild(docCDATASection); + + DOM_Comment docComment = doc.createComment("This should be a comment of some kind "); + docBodyLevel23.appendChild(docComment); + + DOM_EntityReference docReferenceEntity = doc.createEntityReference("ourEntityNode"); + docBodyLevel24.appendChild(docReferenceEntity); + + DTest make; + DOM_Notation docNotation = make.createNotation(doc, "ourNotationNode"); + DOM_DocumentType docType = (DOM_DocumentType &)doc.getFirstChild(); + docType.getNotations().setNamedItem(docNotation); + + DOM_DocumentFragment docDocFragment = doc.createDocumentFragment(); + +// printf("This document's first element name is " + docFirstElement.getTagName() + "\n"); + + +//***********Following are for errorTests + DOM_Text docNode3 = doc.createTextNode(name + "docTextNode3"); + DOM_Text docNode4 = doc.createTextNode(name + "docTextNode4"); + + DOM_Entity docEntity = (DOM_Entity &) doc.getDoctype().getEntities().getNamedItem("ourEntityNode"); // Get the DOM_Entity node + DOM_DocumentType docDocType = (DOM_DocumentType &) doc.getFirstChild(); // Get the DOM_DocumentType node + DOM_EntityReference & entityReferenceText = (DOM_EntityReference &) doc.getLastChild().getLastChild().getLastChild().getFirstChild(); + DOM_Text entityReferenceText2 = doc.createTextNode("entityReferenceText information"); +//************************************************* ERROR TESTS + DTest tests; + + EXCEPTIONSTEST(document.appendChild(docBody), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 1); + + EXCEPTIONSTEST(document.appendChild(docBody), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 2); + EXCEPTIONSTEST(docNode3.appendChild(docNode4), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 3); + EXCEPTIONSTEST(doc.insertBefore(docEntity, docFirstElement), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 4); + EXCEPTIONSTEST(doc.replaceChild(docCDATASection, docFirstElement), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 5); + EXCEPTIONSTEST(docFirstElement.setNodeValue("This shouldn't work!" ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 6); + EXCEPTIONSTEST(docReferenceEntity.setNodeValue("This shouldn't work!" ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 7); + EXCEPTIONSTEST(docEntity.setNodeValue("This shouldn't work!" ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 8); + EXCEPTIONSTEST(doc.setNodeValue("This shouldn't work!" ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 9); + EXCEPTIONSTEST(docDocType.setNodeValue("This shouldn't work!" ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 10); + EXCEPTIONSTEST(docDocFragment.setNodeValue("This shouldn't work!" ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 11); + EXCEPTIONSTEST(docNotation.setNodeValue("This shouldn't work!" ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 12); + EXCEPTIONSTEST(docReferenceEntity.appendChild(entityReferenceText2 ), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR , OK, 13); + EXCEPTIONSTEST(docBodyLevel32.insertBefore(docTextNode11,docBody ), DOM_DOMException::NOT_FOUND_ERR, OK, 14); + EXCEPTIONSTEST(docBodyLevel32.removeChild(docFirstElement), DOM_DOMException::NOT_FOUND_ERR, OK, 15); + EXCEPTIONSTEST(docBodyLevel32.replaceChild(docTextNode11,docFirstElement ), DOM_DOMException::NOT_FOUND_ERR, OK, 16); + + +//!! Throws a NOT_FOUND_ERR ******** + + // docBodyLevel32.getAttributes().removeNamedItem(testAttribute.getName()); 16 // To test removeNamedItem + +}; //END OF DOCBUILDER + + + +/** + * @param document org.w3c.dom.DOM_Document + */ + void DTest::findTestNodes(DOM_Document document) { + DOM_Node node = document; + int nodeCount = 0; + + // Walk the tree until you find and assign all node types needed that exist. + while (node != null && nodeCount < 12) + { + + switch (node.getNodeType()) + { + case DOM_Node::ELEMENT_NODE : + if (testElementNode == null) {testElementNode = (DOM_Element &)node; nodeCount++;} + break; + case DOM_Node::ATTRIBUTE_NODE : + if (testAttributeNode == null) {testAttributeNode = (DOM_Attr &)node; nodeCount++;} + break; + case DOM_Node::TEXT_NODE : + if (testTextNode == null) {testTextNode = (DOM_Text &)node; nodeCount++;} + break; + case DOM_Node::CDATA_SECTION_NODE : + if (testCDATASectionNode == null) {testCDATASectionNode = (DOM_CDATASection &)node; nodeCount++;} + break; + case DOM_Node::ENTITY_REFERENCE_NODE : + if (testEntityReferenceNode == null) {testEntityReferenceNode = (DOM_EntityReference &)node; nodeCount++;} + break; + case DOM_Node::ENTITY_NODE : + if (testEntityNode == null) {testEntityNode = (DOM_Entity &)node; nodeCount++;} + break; + case DOM_Node::PROCESSING_INSTRUCTION_NODE : + if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (DOM_ProcessingInstruction &)node; nodeCount++;} + break; + case DOM_Node::COMMENT_NODE : + if (testCommentNode == null) {testCommentNode = (DOM_Comment &)node; nodeCount++;} + break; + case DOM_Node::DOCUMENT_TYPE_NODE : + if (testDocumentTypeNode == null) {testDocumentTypeNode = (DOM_DocumentType &)node; nodeCount++;} + break; + case DOM_Node::DOCUMENT_FRAGMENT_NODE : + if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DOM_DocumentFragment &)node; nodeCount++;} + break; + case DOM_Node::NOTATION_NODE : + if (testNotationNode == null) {testNotationNode = (DOM_Notation &)node; nodeCount++;} + break; + case DOM_Node::DOCUMENT_NODE : + if (testDocumentNode == null) {testDocumentNode = (DOM_Document &)node; nodeCount++;} + break; + default: + ; + }// End of switch + + } // End of while +}; + + +/** + * @param document org.w3c.dom.DOM_Document + */ + void DTest::findTestNodes(DOM_Node node) { + DTest test; + DOM_Node kid; + // Walk the tree until you find and assign all node types needed that exist. + + + if (node.getFirstChild() != null) + { + kid = node.getFirstChild(); + test.findTestNodes(kid); + } + + + if (node.getNextSibling() != null) + { + kid = node.getNextSibling(); + test.findTestNodes(kid); + } + + + switch (node.getNodeType()) + { + case DOM_Node::ELEMENT_NODE : + if (testElementNode == null) {testElementNode = (DOM_Element &)node; } + break; + case DOM_Node::ATTRIBUTE_NODE : + if (testAttributeNode == null) {testAttributeNode = (DOM_Attr &)node; } + break; + case DOM_Node::TEXT_NODE : + if (testTextNode == null) {testTextNode = (DOM_Text &)node; } + break; + case DOM_Node::CDATA_SECTION_NODE : + if (testCDATASectionNode == null) {testCDATASectionNode = (DOM_CDATASection &)node; } + break; + case DOM_Node::ENTITY_REFERENCE_NODE : + if (testEntityReferenceNode == null) {testEntityReferenceNode = (DOM_EntityReference &)node;} + break; + case DOM_Node::ENTITY_NODE : + if (testEntityNode == null) {testEntityNode = (DOM_Entity &)node;} + break; + case DOM_Node::PROCESSING_INSTRUCTION_NODE : + if (testProcessingInstructionNode == null) {testProcessingInstructionNode = (DOM_ProcessingInstruction &)node;} + break; + case DOM_Node::COMMENT_NODE : + if (testCommentNode == null) {testCommentNode = (DOM_Comment &)node;} + break; + case DOM_Node::DOCUMENT_TYPE_NODE : + if (testDocumentTypeNode == null) {testDocumentTypeNode = (DOM_DocumentType &)node; } + break; + case DOM_Node::DOCUMENT_FRAGMENT_NODE : + if (testDocumentFragmentNode == null) {testDocumentFragmentNode = (DOM_DocumentFragment &)node;} + break; + case DOM_Node::NOTATION_NODE : + if (testNotationNode == null) {testNotationNode = (DOM_Notation &)node;} + break; + case DOM_Node::DOCUMENT_NODE : + if (testDocumentNode == null) {testDocumentNode = (DOM_Document &)node;} + break; + default: + ; + }// End of switch +};//End of class + +/** + * + * version 2.0 10/12/98 + * + */ + void main(int argc, char **argv) + { + + { + // Nest entire test in an inner block. + // Reference counting should recover all document + // storage when this block exits. + + DTest test; + XMLStdOut errStrm; + try { + XMLPlatformUtils::Initialize(); + } + catch (const XMLException& toCatch) { + errStrm << "Error during initialization! :\n" + << toCatch.getMessage() << EndLn; + return ; + } + + long avgTime = 0; + bool OK = true; + long startTime = 0;//****************Time the whole thing for efficiency of DOM implementation + + // for (int i=0; i< 1000; i++) + // { + // AH Revisit // startTime = System.currentTimeMillis(); + // if(!OK) + // break; + + DOM_Document d = test.createDocument(); + // DOM_Document z = test.createDocument(); + + DOM_DocumentType docDocType = test.createDocumentType(d,"testDocument1"); + d.appendChild(docDocType); + + DOM_Entity docEntity = test.createEntity( d, "ourEntityNode"); + DOM_Text entityChildText = d.createTextNode("entityChildText information"); // Build a branch for entityReference tests + docEntity.appendChild(entityChildText); // & for READONLY_ERR tests + docDocType.getEntities().setNamedItem(docEntity); + + test.docBuilder(d, "d"); + + test.findTestNodes((DOM_Node)d); + // test.docBuilder(z, "z"); + // try { + LEAKTEST(test.testAttr(d);); + LEAKTEST(test.testCDATASection(d);); + LEAKTEST(test.testCharacterData(d);); + LEAKTEST(test.testChildNodeList(d);); + LEAKTEST(test.testComment(d);); + LEAKTEST(test.testDeepNodeList(d);); + LEAKTEST(test.testDocument(d);); + LEAKTEST(test.testDocumentFragment(d);); + LEAKTEST(test.testDocumentType(d);); + LEAKTEST(test.testDOMImplementation(d);); + LEAKTEST(test.testElement(d);); + LEAKTEST(test.testEntity(d);); + LEAKTEST(test.testEntityReference(d);); + LEAKTEST(test.testNode(d);); + LEAKTEST(test.testNotation(d);); + LEAKTEST(test.testPI(d);); + LEAKTEST(test.testText(d);); + LEAKTEST(test.testDOMerrors(d);); + + //!! Throws WRONG_DOCUMENT_ERR ********** + + // z.appendChild(d.createComment("Test doc d comment"));// Tries to append z document with document d comment + // d.getDocumentElement().appendChild(z.createElement("newZdocElement"));// Tries to append d document with document z DOM_Element + // d.getLastChild().getLastChild().insertBefore(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild());// Tries to insert into d document with document z DOM_Element + // d.replaceChild(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild()); // Tries to replace in d document with document z DOM_Element + + /* Attribute newAttribute = d.createAttribute("newAttribute"); + d.getDocumentElement().setAttributeNode(newAttribute); + d.getDocumentElement().getAttributes().setNamedItem(z.createAttribute("newzAttribute")); + */ + + //!! Throws INVALID_CHARACTER_ERR ********** + // ******This just gets us through each method. JKess has a comprehensive test of Invalid Names****** + // d.createAttribute("Invalid Name"); // Name with blank space + // d.createElement("5InvalidName"); // Name starts with numeric + // d.createProcessingInstruction("This is the target processor channel","InvalidName>");// Name ends with > + // d.getDocumentElement().setAttribute("Invalid%Name",""); // Name contains % + + + //!! ******** NO_DATA_ALLOWED_ERR ********No cases to test as of 9/15 + + + //!! ******** NO_MODIFICATION_ALLOWED_ERR ******** When read only exists + /* + + + + // **** FOR DOM_Element when read only exists******** + .removeAttribute("aString"); // ***** Not until read only exists. + .removeAttributeNode(Attribute); // ***** Not until read only exists. + .setAttribute("aString", "anotherString"); // ***** Not until read only exists. + + + // **** FOR DOM_Node when read only exists******** + .appendChild(aNode); // ***** Not until read only exists. + .insertBefore(aNode, AnotherNode); // ***** Not until read only exists. + .removeChild(aNode); // ***** Not until read only exists. + .replaceChild(aNode); // ***** Not until read only exists. + + .splitText(2); // ***** Not until read only exists. + + .setNamedItem(DOM_Node); // ***** Not until read only exists. + */ + + + //!!******** NOT_SUPPORTED_ERR ********For HTML when implemented + /* + .createCDATASection("String stuff"); + .createEntityReference("String stuff"); + .createProcessingInstruction("String stuff", "Some more String stuff"); + */ + + // } catch (DOM_DOMException &e) { + // fprintf(stderr, "Unexpected DOM Exception caught. Code is: %d\n", e.code); + // OK = false; + // } + // catch (...) { + // fprintf(stderr, "Unexpected non-DOM exception caught."); + // }; + + + //System.err.println("Elapsed time (measured in seconds): " + ((System.currentTimeMillis() - startTime) / 1000.0)); + // AH revisit avgTime += System.currentTimeMillis() - startTime; + // }//END OF FOR + + + // System.err.println("Elapsed time (measured in seconds): " + + // ((System.currentTimeMillis() - startTime) / 1000.0)); + // System.err.println("Elapsed time (measured in mili-seconds): " + + // ((System.currentTimeMillis() - startTime))); + + + // System.err.println("Average Elapsed time (measured in seconds): " + (avgTime/10000000.0) ); + + // Null out the static object references in class DTest, + // which will recover their storage. Part of testing for memory leaks. + DTest::testElementNode = null; + DTest::testAttributeNode = null; + DTest::testTextNode = null; + DTest::testCDATASectionNode = null; + DTest::testEntityReferenceNode = null; + DTest::testEntityNode = null; + DTest::testProcessingInstructionNode = null; + DTest::testCommentNode = null; + DTest::testDocumentNode = null; + DTest::testDocumentTypeNode = null; + DTest::testDocumentFragmentNode = null; + DTest::testNotationNode = null; + + }; + DomMemDebug().print(); +}; + + +/** + * This method tests DOM_Attr methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testAttr(DOM_Document document) +{ + DOM_Node node; + DOM_Attr attributeNode, attribute2; + DOMString compare; + bool T = true; + bool F = false; + bool OK = true; +// For debugging***** printf("\n testAttr's outputs:\n\n"); + + DOM_Attr testAttribute = document.createAttribute("testAttribute"); + testAttribute.setValue("testAttribute's value"); + node = document.getDocumentElement(); // node gets first element + + // ((DOM_Element &)node).setAttributeNode(testAttribute); + // attributeNode = ((DOM_Element &)node).getAttributeNode("testAttribute"); + DOM_Element el = (DOM_Element &)node; + el.setAttributeNode(testAttribute); + attributeNode = el.getAttributeNode("testAttribute"); + + compare = "testAttribute"; + if (!compare.equals(attributeNode.getName())) + { + printf("Warning!!! DOM_Attr's 'getName' method failed to work properly!\n"); + OK = false; + } + compare = "testAttribute's value"; + if (!compare.equals(attributeNode.getNodeValue())) + { + printf("Warning!!! DOM_Attr's 'getNodeValue' method failed to work properly!\n"); + OK = false; + } + if (! T ==attributeNode.getSpecified()) + { + printf("Warning!!! DOM_Attr's 'getSpecified' method failed to work properly!\n"); + OK = false; + } + + if (!compare.equals(attributeNode.getValue())) + { + printf("Warning!!! DOM_Attr's 'getValue' method failed to work properly!\n"); + OK = false; + } + + + attributeNode.setNodeValue("Reset Value"); /// LEAK!!!!! + compare = "Reset Value"; + if (!compare.equals(attributeNode.getNodeValue())) + { + printf("Warning!!! DOM_Attr's 'setNodeValue' method failed to work properly!\n"); + OK = false; + } + + // IBM Specific function + attributeNode.setSpecified(F);//***** How do we change this for external use?? + if (! F ==attributeNode.getSpecified()) + { + printf("Warning!!! DOM_Attr's 'setSpecified' method failed to work properly!\n"); + OK = false; + } + + attributeNode.setValue(null); + if (! attributeNode.getValue().equals("")) + { + printf("Warning!!! DOM_Attr's 'setValue' to 'null' method failed to work properly!\n"); + OK = false; + } + + attributeNode.setValue("Another value "); + compare = "Another value "; + if (!compare.equals(attributeNode.getValue())) + { + printf("Warning!!! DOM_Attr's 'setValue' method failed to work properly!"); + OK = false; + } + + node = attributeNode.cloneNode(T); + + // Check nodes for equality, both their name and value or lack thereof + bool cloneOK = true; + if (!(node.getNodeName().equals(attributeNode.getNodeName()))) + cloneOK = false; + if (node.getNodeValue() == null && + attributeNode.getNodeValue() != null) + { + attributeNode.getNodeValue().print(); + cloneOK = false; + } + + if (node.getNodeValue() != null && attributeNode.getNodeValue() == null) + { + cloneOK = false; + node.getNodeValue().print(); + }; + + if (node.getNodeValue() != null && attributeNode.getNodeValue() != null) + { + if (!(node.getNodeValue().equals(attributeNode.getNodeValue()))) + cloneOK = false; + } + + +/* + if (! (node.getNodeName().equals(attributeNode.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && attributeNode.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(attributeNode.getNodeValue()) // If both have value nodes test those value nodes for equality + : (node.getNodeValue() == null && attributeNode.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't +*/ + if (cloneOK == false) + { + printf("'cloneNode' did not clone the Attribute node correctly\n"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + +//************************************************* ERROR TESTS + DTest tests; +//!! Throws HIERARCHY_REQUEST_ERR **************** + // doc.getDocumentElement().appendChild(attributeNode); + +//!! Throws a NOT_FOUND_ERR ******** + // attribute2 = doc.createAttribute("testAttribute2"); + // doc.getDocumentElement().removeAttributeNode(attribute2); + +//!! Throws an INUSE_ATTRIBUTE_ERR ****** + // DOM_Element element = (DOM_Element &)doc.getLastChild().getLastChild(); + // element.setAttributeNode(testAttribute );// Tests setNamedItem which generates error through justSetNamedItem. + +// For debugging***** printf("All DOM_Attr method calls worked correctly.\n"); + if (! OK) + printf("\n*****The DOM_Attr method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); + +}; + + + + +/** + * This method tests DOM_CDATASection methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testCDATASection(DOM_Document document) +{ + DOM_Node node, node2; + bool T = true; + bool OK = true; +// For debugging***** printf("\n testCDATASection's outputs:\n"); + node = document.getDocumentElement().getElementsByTagName("dBodyLevel23").item(0).getFirstChild(); // node gets DOM_CDATASection node + + node2 = node.cloneNode(T);//*****? + // Check nodes for equality, both their name and value or lack thereof + if (! (node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality + : (node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't + { + printf("'cloneNode' did not clone the DOM_CDATASection node correctly\n"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + +// For debugging***** printf("All DOM_CDATASection method calls worked correctly.\n"); + + if (! OK) + printf("\n*****The DOM_CDATASection method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); +}; + + + +/** + * This method tests DOM_CharacterData methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testCharacterData(DOM_Document document) +{ + DOM_CharacterData charData; + DOMString compareData, newData, resetData; + bool OK = true; +// For debugging***** printf("\n testCharacterData's outputs:\n"); + charData = (DOM_CharacterData &) document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // charData gets textNode11 + compareData = "dBodyLevel31'sChildTextNode11"; + if (!compareData.equals(charData.getData())) + { + printf("Warning!!! DOM_CharacterData's 'getData' failed to work properly!\n This may corrupt other DOM_CharacterData tests!!!*****\n"); + OK = false; + } + + resetData = charData.getData(); + // printf("This node's original data is: " + charData.getData()); + + newData = " This is new data for this node"; + compareData = charData.getData() + newData; + charData.appendData(newData); + if (!compareData.equals(charData.getData())) + { + printf("Warning!!! DOM_CharacterData's 'appendData' failed to work properly!\n"); + OK = false; + } + // printf("This node's appended data is: " + charData.getData()); + + compareData = "dBodyLevel"; + charData.deleteData(10, 100); + if (!compareData.equals(charData.getData())) + { + printf("Warning!!! DOM_CharacterData's 'deleteData' failed to work properly!\n"); + OK = false; + } + // printf("This node's partially deleted data is: " + charData.getData()); + + int length = 10; + if (!(length == charData.getLength())) + { + printf("Warning!!! DOM_CharacterData's 'getLength' failed to work properly!\n"); + OK = false; + } + // printf("This node's data length is: " + charData.getLength()); + + compareData = "dBody' This is data inserted into this node'Level"; + charData.insertData(5, "' This is data inserted into this node'"); + if (!compareData.equals(charData.getData())) + { + printf("Warning!!! DOM_CharacterData's 'insertData' failed to work properly!\n"); + OK = false; + } + // printf("This node's updated with insert data is: " + charData.getData()); + + compareData = "dBody' This is ' replacement data'ted into this node'Level"; + charData.replaceData(15, 10, "' replacement data'"); + if (!compareData.equals(charData.getData())) + { + printf("Warning!!! DOM_CharacterData's 'replaceData' failed to work properly!\n"); + OK = false; + } + // printf("This node's updated with replacement data is: " +charData.getData()); + + compareData = "New data A123456789B123456789C123456789D123456789E123456789"; + charData.setData("New data A123456789B123456789C123456789D123456789E123456789"); + if (!compareData.equals(charData.getData())) + { + printf("Warning!!! DOM_CharacterData's 'setData' failed to work properly!"); + OK = false; + } + // printf("This node's new data via setData: " + charData.getData()); + + compareData = "123456789D123456789E123456789"; + if (!compareData.equals(charData.substringData(30, 30))) + { + printf("Warning!!! DOM_CharacterData's 'substringData' failed to work properly!\n"); + OK = false; + } + // printf("Using subString 30,30 you get:"); charData.substringData(30,30)).print(); + + compareData = "New data A123456789B12345"; + if (!compareData.equals(charData.substringData(0, 25))) + { + printf("Warning!!! DOM_CharacterData's 'substringData' failed to work properly!\n"); + OK = false; + } + // printf("Using subString 0,25 you get: "); charData.substringData(0,25)).print(); + +//************************************************* ERROR TESTS + DTest tests; // What is this for? 'tests' is never used. + +//!! Throws INDEX_SIZE_ERR ******************** + EXCEPTIONSTEST(charData.deleteData(-1, 5), DOM_DOMException::INDEX_SIZE_ERR, OK, 101 ); + EXCEPTIONSTEST(charData.deleteData(2, -1), DOM_DOMException::INDEX_SIZE_ERR, OK, 102 ); + EXCEPTIONSTEST(charData.deleteData(100, 5), DOM_DOMException::INDEX_SIZE_ERR, OK,103 ); + + EXCEPTIONSTEST(charData.insertData(-1, "Stuff inserted"), DOM_DOMException::INDEX_SIZE_ERR, OK, 104 ); + EXCEPTIONSTEST(charData.insertData(100,"Stuff inserted"), DOM_DOMException::INDEX_SIZE_ERR, OK, 105 ); + + EXCEPTIONSTEST(charData.replaceData(-1, 5, "Replacement stuff") , DOM_DOMException::INDEX_SIZE_ERR, OK, 106 ); + EXCEPTIONSTEST(charData.replaceData(100, 5 ,"Replacement stuff"), DOM_DOMException::INDEX_SIZE_ERR, OK, 107 ); + EXCEPTIONSTEST(charData.replaceData(2, -1, "Replacement stuff"), DOM_DOMException::INDEX_SIZE_ERR, OK, 108 ); + + EXCEPTIONSTEST(charData.substringData(-1, 5), DOM_DOMException::INDEX_SIZE_ERR, OK, 109 ); + EXCEPTIONSTEST(charData.substringData(100, 5), DOM_DOMException::INDEX_SIZE_ERR, OK, 110 ); + EXCEPTIONSTEST(charData.substringData(2, -1), DOM_DOMException::INDEX_SIZE_ERR, OK, 111 ); + + +//!! Throws NO_MODIFICATION_ALLOWED_ERR ******** + DOM_Text node = (DOM_Text &)document.getDocumentElement().getElementsByTagName("dBodyLevel24"). + item(0).getFirstChild().getChildNodes().item(0); // node gets ourEntityReference node's child text + + EXCEPTIONSTEST(node.appendData("new data"), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 112 ); + EXCEPTIONSTEST(node.deleteData(5, 10), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 113 ); + EXCEPTIONSTEST(node.insertData(5, "Stuff inserted"), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 114 ); + EXCEPTIONSTEST(node.replaceData(5, 10, "Replacementstuff"), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 115 ); + EXCEPTIONSTEST(node.setData("New setdata stuff"), DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 116 ); + + +// For debugging***** printf("All DOM_CharacterData method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_CharacterData method calls listed above failed, all others worked correctly.*****\n"); + charData.setData(resetData); // reset node to original data +// printf(""\n); +}; + + + + +/** + * This method tests ChildNodeList methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testChildNodeList(DOM_Document document) +{ + DOM_Node node, node2; + bool OK = true; +// For debugging***** printf("\n testChildNodeList's outputs:\n"); + node = document.getDocumentElement().getLastChild(); // node gets doc's testBody element + + if (!(node.getChildNodes().getLength()== 4)) + OK = false; + node2 = node.getChildNodes().item(2); + if (! node2.getNodeName().equals("dBodyLevel23")) + OK = false; + +// For debugging***** printf("All ChildNodeList method calls worked correctly.\n"); + if (!OK) + printf("\n*****The ChildNodeList method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); +}; + + + +/** + * This method tests DOM_Comment methods for the XML DOM implementation + * version 1.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testComment(DOM_Document document) +{ + DOM_Node node, node2; + bool T = true; + bool OK = true; +// For debugging***** printf("\n testComment's outputs:\n"); + node = document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0).getFirstChild(); // node gets textNode11 + node2 = node.cloneNode(T); + // Check nodes for equality, both their name and value or lack thereof + if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality + : (node.getNodeValue() == null && node2.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't + //printf("'cloneNode' did not clone the DOM_Comment node correctly\n"); + OK = false; + // Deep clone test comparison is in testNode & testDocument + if (OK) +// For debugging***** printf("All DOM_Comment method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_Comment method calls listed above failed, all others worked correctly.*****\n"); +// printf("\n"); +}; + + + +/** + * This method tests DeepNodeList methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testDeepNodeList(DOM_Document document) +{ + DOM_Node node, node2; + bool OK = true; +// For debugging***** printf("\n testDeepNodeList's outputs:\n\n"); + node = document.getLastChild().getLastChild(); // node gets docBody element +// DOM_Element el = (DOM_Element &)node; +// DOM_NodeList nl = el.getElementsByTagName("*"); +// int len = nl.getLength(); +// if (len != 8) + if (!(8 == ((DOM_Element &) node).getElementsByTagName("*").getLength())) + { + printf ("Warning!!! DeepNodeList's 'getLength' failed to work properly!\n"); + OK = false; + } + node2 = ((DOM_Element &) node).getElementsByTagName("*").item(2); //This also runs through 'nextMatchingElementAfter" + if (! node2.getNodeName().equals("dBodyLevel32")) + { + printf ("Warning!!! DeepNodeList's 'item' (or DOM_Element's 'getElementsBy TagName)failed to work properly!\n"); + OK = false; + } + node2 = document.getLastChild(); + if (! ((DOM_Element &) node2).getElementsByTagName("dTestBody").item(0).getNodeName().equals("dTestBody"))//This also runs through 'nextMatchingElementAfter" + { + printf ("Warning!!! DeepNodeList's 'item' (or DOM_Element's 'getElementsBy TagName)failed to work properly!\n"); + OK = false; + } + + +// For debugging***** printf("All DeepNodeList method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DeepNodeList method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); +}; + + + +/** + * This method tests DOM_Document methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + * + **** ALL DOM_Document create methods are run in docBuilder except createAttribute which is in testAttribute** + */ +void DTest::testDocument(DOM_Document document) +{ + DTest make; + DOM_DocumentFragment docFragment, docFragment2; + DOM_Element newElement; + DOM_Node node, node2; + DOMString elementNames[] = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", + "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; + DOMString newElementNames[] = {"dFirstElement", "dTestBody", "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23"}; + bool result; + bool OK = true; +// For debugging***** printf("\n testDocument's outputs:\n \n"); + + DOM_DocumentType checkDocType = make.createDocumentType(document,"testDocument1"); + DOM_DocumentType docType = document.getDoctype(); + + if (! checkDocType.getNodeName().equals(docType.getNodeName() )) + { + printf("Warning!!! DOM_Document's 'getDocType method failed!\n" ); + OK = false; + } + + if (!checkDocType.getNodeValue().equals(docType.getNodeValue())) + { + printf("Warning!!! DOM_Document's 'getDocType method failed!\n" ); + OK = false; + } + + /* + if (! (checkDocType.getNodeName().equals(docType.getNodeName()) && // Compares node names for equality + (checkDocType.getNodeValue() != null && docType.getNodeValue() != null) // Checks to make sure each node has a value node + ? checkDocType.getNodeValue().equals(docType.getNodeValue()) // If both have value nodes test those value nodes for equality + : (checkDocType.getNodeValue() == null && docType.getNodeValue() == null))) // If one node doesn't have a value node make sure both don't + { + printf("Warning!!! DOM_Document's 'getDocType method failed!\n" ); + OK = false; + } + */ + + DOM_Node rootElement = document.getLastChild(); + if (! (rootElement.getNodeName().equals(document.getDocumentElement().getNodeName()) && // Compares node names for equality + (rootElement.getNodeValue() != null && document.getDocumentElement().getNodeValue() != null) // Checks to make sure each node has a value node + ? rootElement.getNodeValue().equals(document.getDocumentElement().getNodeValue()) // If both have value nodes test those value nodes for equality + : (rootElement.getNodeValue() == null && document.getDocumentElement().getNodeValue() == null))) // If one node doesn't have a value node make sure both don't + { + printf("Warning!!! DOM_Document's 'getDocumentElement' method failed!\n" ); + OK = false; + } + + DOM_NodeList docElements = document.getElementsByTagName("*"); + int docSize = docElements.getLength(); + int i; + for (i = 0; i < docSize; i++) + { + DOM_Node n = (DOM_Node) docElements.item(i); + if (! (elementNames[i].equals(n.getNodeName()))) + { + printf("Comparison of this document's elements failed at element number %d : ", i); + n.getNodeName().print(); + OK = false; + break; + } + } + + // What is this supposed to be doing? + // + //if (document.equals(document.getImplementation())) + //{ + // printf("Warning!!! DOM_Document's 'getImplementation' method failed!\n" ); + // OK = false; + //} + + newElement = document.createElement("NewElementTestsInsertBefore"); + // doc.insertBefore(newElement,null);//!! Throws a HIERARCHY_REQUEST_ERR ******* + // doc.removeChild(docElements.item(9));//!! Throws a NOT_FOUND_ERR ******** + + docFragment = document.createDocumentFragment(); + //Tests removeChild and stores removed branch for tree reconstruction + docFragment.appendChild(docElements.item(1).removeChild(docElements.item(9))); + docFragment2 = document.createDocumentFragment(); + //Tests removeChild and stores removed branch for tree reconstruction + docFragment2.appendChild(docElements.item(1).removeChild(docElements.item(2))); + docSize = docElements.getLength(); + for (i = 0; i < docSize; i++) + { + DOM_Node n = (DOM_Node) docElements.item(i); + if (! (newElementNames[i].equals(n.getNodeName()))) + { + printf("Comparison of new document's elements failed at element number %d : ", i); + n.getNodeName().print(); + OK = false; + break; + } + } + docElements.item(1).insertBefore(docFragment, DOM_Node()); //Reattaches removed branch to restore tree to the original + // AH Revist. Note: insertBefore should be able to take + // a null as its second parameter. + docElements.item(1).insertBefore(docFragment2, docElements.item(2)); //Reattaches removed branch to restore tree to the original + + // printf(docElements.item(2).getNodeName()); + + docSize = docElements.getLength(); + for (i = 0; i < docSize; i++) + { + DOM_Node n = (DOM_Node) docElements.item(i); + if (! (elementNames[i].equals(n.getNodeName()))) + { + printf("Comparison of restored document's elements failed at element number %d : ", i); + n.getNodeName().print(); + OK = false; + break; + } + } + + DTest tests; + + +// DOM_Document z = tests.createDocument(); +// tests.docBuilder(z, "z"); + +//!! Throws WRONG_DOCUMENT_ERR ********** +// EXCEPTIONSTEST(z.appendChild( + // z.appendChild(d.createComment("Test doc d comment"));// Tries to append z document with document d comment + // d.getDocumentElement().appendChild(z.createElement("newZdocElement"));// Tries to append d document with document z DOM_Element + // d.getLastChild().getLastChild().insertBefore(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild());// Tries to insert into d document with document z DOM_Element + // d.replaceChild(z.createElement("newZdocElement"),d.getLastChild().getLastChild().getFirstChild()); // Tries to replace in d document with document z DOM_Element + + // doc.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** + + node = document; + node2 = document.cloneNode(true); + result = treeCompare(node, node2); // Deep clone test comparison of document cloneNode + if (!result) + { + printf("Warning!!! Deep clone of the document failed!\n"); + OK = false; + } + + // Deep clone test comparison is also in testNode + + +// For debugging***** printf("All DOM_Document method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_Document method calls listed above failed, all others worked correctly.*****\n"); +// printf("\n"); +}; + + + +/** + * This method tests DOM_DocumentFragment methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + * + * + ********This really isn't needed, only exists to throw NO_MODIFICATION_ALLOWED_ERR ******** + */ +void DTest::testDocumentFragment(DOM_Document document) +{ + bool OK = true; +// For debugging***** printf("\n testDocumentFragment's outputs:\n"); + DOM_DocumentFragment testDocFragment = document.createDocumentFragment(); + + // testDocFragment.setNodeValue("This is a document fragment!");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** + +// For debugging***** printf("All DOM_DocumentFragment method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_DocumentFragment method calls listed above failed, all others worked correctly.*****\n"); +// printf("\n"); +}; + + + +/** + * This method tests DOM_DocumentType methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testDocumentType(DOM_Document document) +{ + DTest test; + DOM_DocumentType docType, holdDocType; + DOM_NamedNodeMap docEntityMap, docNotationMap; + DOM_Node node, node2; + DOMString compare; + bool OK = true; +// For debugging***** printf("\n testDocumentType's outputs:\n"); + DOM_DocumentType newDocumentType = test.createDocumentType(document, "TestDocument"); + node = document.getFirstChild(); // node gets doc's docType node + node2 = node.cloneNode(true); + // Check nodes for equality, both their name and value or lack thereof + if (! (node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality + : (node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't + { + printf("'cloneNode' did not clone the DOM_DocumentType node correctly\n"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + + docType = (DOM_DocumentType &) document.getFirstChild(); + compare = "ourEntityNode"; + docEntityMap = docType.getEntities(); + if (! compare.equals(docEntityMap.item(0).getNodeName())) + { + printf("Warning!!! DOM_DocumentType's 'getEntities' failed!\n" ); + OK = false; + } + docNotationMap = docType.getNotations(); + compare = "ourNotationNode"; + if (! compare.equals(docNotationMap.item(0).getNodeName())) + { + printf("Warning!!! DOM_DocumentType's 'getNotations' failed!\n"); + OK = false; + } + // doc.appendChild(newDocumentTypeImpl);//!! Throws a HIERARCHY_REQUEST_ERR ******* + holdDocType = (DOM_DocumentType &) document.removeChild(document.getFirstChild()); //Tests removeChild and stores removed branch for tree reconstruction + document.insertBefore(newDocumentType, document.getDocumentElement()); + //** Other aspects of insertBefore are tested in docBuilder through appendChild* + + document.removeChild(document.getFirstChild()); //Removes newDocumentType for tree restoral + document.insertBefore(holdDocType, document.getFirstChild()); //Reattaches removed branch to restore tree to the original + + +// For debugging***** printf("All DOM_DocumentType method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_DocumentType method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); +}; + + + +/** + * @param document org.w3c.dom.DOM_Document + */ +void DTest::testDOMerrors(DOM_Document document) { + bool OK = true; + + DTest tests; + + EXCEPTIONSTEST(document.appendChild(testElementNode), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 201 ); + EXCEPTIONSTEST(testTextNode.appendChild(testTextNode), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 202 ); +#ifdef skipthese + EXCEPTIONSTEST(document.insertBefore(document.getElementsByTagName("docEntity").item(0), + document.getElementsByTagName("docFirstElement").item(0)), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 203 ); + EXCEPTIONSTEST(document.replaceChild(document.getElementsByTagName("docCDATASection").item(0), + document.getElementsByTagName("docFirstElement").item(0)), DOM_DOMException::HIERARCHY_REQUEST_ERR, OK, 204 ); + + EXCEPTIONSTEST(document.getElementsByTagName("docFirstElement").item(0).setNodeValue("This shouldn't work!" ), + DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 205 ); + EXCEPTIONSTEST(docReferenceEntity.setNodeValue("This shouldn't work!"), + DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 206 ); + EXCEPTIONSTEST(docEntity.setNodeValue("This shouldn't work!"), + DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 207 ); + EXCEPTIONSTEST(document.setNodeValue("This shouldn't work!"), + DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 208 ); + EXCEPTIONSTEST(docDocType.setNodeValue("This shouldn't work!"), + DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 209 ); + EXCEPTIONSTEST(docDocFragment.setNodeValue("This shouldn't work!"), + DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 210 ); + EXCEPTIONSTEST(docNotation.setNodeValue("This shouldn't work!"), + DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 211 ); + EXCEPTIONSTEST(docReferenceEntity.appendChild(entityReferenceText2) + , DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, OK, 212 ); + + + EXCEPTIONSTEST(docBodyLevel32.insertBefore(docTextNode11,docBody), DOM_DOMException::NOT_FOUND_ERR, OK, 213 ); + EXCEPTIONSTEST(docBodyLevel32.removeChild(docFirstElement), DOM_DOMException::NOT_FOUND_ERR, OK, 214 ); + EXCEPTIONSTEST(docBodyLevel32.replaceChild(docTextNode11,docFirstElement), DOM_DOMException::NOT_FOUND_ERR ); + +#endif + +//!! Throws a NOT_FOUND_ERR ******** + + // docBodyLevel32.getAttributes().removeNamedItem(testAttribute.getName()); 16 // To test removeNamedItem + +}; + + + +/** + * This method tests DOM_DOMImplementation methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testDOMImplementation(DOM_Document document) +{ + + DOM_DOMImplementation implementation; + bool result = false; + bool OK = true; +// For debugging***** printf("\n testDOMImplementation's outputs:\n"); + implementation = document.getImplementation(); //Uses getDOMImplementation to obtain implementation + + result = implementation.hasFeature("XML", "1.0"); + if(!result) + { + fprintf(stderr, "Warning!!! DOM_DOMImplementation's 'hasFeature' that should be 'true' failed!"); + OK = false; + } + + result = implementation.hasFeature("HTML", "4.0"); + if(result) + { + fprintf(stderr, "Warning!!! DOM_DOMImplementation's 'hasFeature' that should be 'false' failed!"); + OK = false; + } + + +// For debugging***** printf("All DOM_DOMImplementation method calls worked correctly.\n"); + if (!OK) + fprintf(stderr, "\n*****The DOM_DOMImplementation method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); +}; + + + +/** + * This method tests DOM_Element methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testElement(DOM_Document document) +{ + DOM_Attr attributeNode, newAttributeNode; + DOM_Element element, element2; + DOM_Node node, node2; + DOMString attribute, compare; + DOMString attributeCompare[] = {"AnotherFirstElementAttribute", "dFirstElement", "testAttribute"}; + DOMString elementNames[] = {"dFirstElement", "dTestBody", "dBodyLevel21","dBodyLevel31","dBodyLevel32", + "dBodyLevel22","dBodyLevel33","dBodyLevel34","dBodyLevel23","dBodyLevel24"}; + DOMString textCompare[] = {"dBodyLevel31'sChildTextNode11", + "dBodyLevel31'sChildTextNode12", + "dBodyLevel31'sChildTextNode13"}; + DOM_NamedNodeMap nodeMap; + bool OK = true; +// For debugging***** printf("\n testElement's outputs:\n"); + node = document.getDocumentElement(); // node gets doc's firstElement + node2 = node.cloneNode(true); + // Check nodes for equality, both their name and value or lack thereof + if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality + :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't + { + fprintf(stderr, "'cloneNode' did not clone the DOM_Element node correctly.\n"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + + element = document.getDocumentElement(); // element gets doc's firstElement + compare = ""; + attribute = element.getAttribute(document.getNodeValue() + "'s test attribute"); + if (! compare.equals(element.getAttribute(document.getNodeValue() + "'s test attribute"))) + { + fprintf(stderr, "Warning!!! DOM_Element's 'getAttribute' failed!\n"); + OK = false; + } + + attributeNode = element.getAttributeNode(document.getNodeValue() + "FirstElement"); + if(! (attributeNode == null)) + { + fprintf(stderr, "Warning!!! DOM_Element's 'getAttributeNode' failed! It should have returned 'null' here!\n"); + OK = false; + } + + + newAttributeNode = document.createAttribute("AnotherFirstElementAttribute"); + newAttributeNode.setValue("A new attribute which helps test calls in DOM_Element"); + // This test is incorrect. It assumes that there is a defined ordering of the entries + // in a nodeMap, but there is no ordering required. +#ifdef TheFollowingCheckIsInvalid + element.setAttributeNode(newAttributeNode); + nodeMap = element.getAttributes(); + int size = nodeMap.getLength(); + int k; + for (k = 0; k < size; k++) + { + DOM_Node n = (DOM_Node) nodeMap.item(k); + if (! (attributeCompare[k].equals(n.getNodeName()))) + { + printf("Warning!!! Comparison of firstElement's attributes failed.\n"); + printf(" n.getNodeName() = \""); n.getNodeValue().print(); printf("\"\n"); + printf(" expected value = \""); attributeCompare[k].print(); printf("\"\n"); + printf(" This failure can be a result of DOM_Element's 'setValue' and/or 'setAttributeNode' and/or 'getAttributes' failing.\n"); + OK = false; + break; + } + // printf("firstElement's attribute number " + k + " : " + n.getNodeName()); + } +#endif + + nodeMap = element.getAttributes(); + int size = nodeMap.getLength(); + if (size != 2) + { + printf("DOM_Element Tests Failure 001\n"); + OK = false; + }; + element.setAttributeNode(newAttributeNode); + size = nodeMap.getLength(); + if (size != 3) + { + printf("DOM_Element Tests Failure 002\n"); + OK = false; + }; + + // Fetch the newly added attribute node back out of from the named node map, + // and check that we are returned the same node that we put in. + DOM_Attr fetchedAttr = (DOM_Attr &)nodeMap.getNamedItem("AnotherFirstElementAttribute"); + if (fetchedAttr != newAttributeNode) + { + printf("DOM_Element Tests Failure 003\n"); + OK = false; + }; + + // Fetch the newly added attribute back out directly from the element itself. + fetchedAttr = (DOM_Attr &)element.getAttributeNode("AnotherFirstElementAttribute"); + if (fetchedAttr != newAttributeNode) + { + printf("DOM_Element Tests Failure 004\n"); + OK = false; + }; + + + + DOM_NodeList docElements = document.getElementsByTagName("*"); + int docSize = docElements.getLength(); + int i; + for (i = 0; i < docSize; i++) + { + DOM_Node n = (DOM_Node &) docElements.item(i); + if (! (elementNames[i].equals(n.getNodeName()))) + { + printf("Warning!!! Comparison of DOM_Element's 'getElementsByTagName' " + "and/or 'item' failed at element number %d : ", i ); + n.getNodeName().print(); + printf("\n"); + OK = false; + break; + } + // printf("docElement's number " + i + " is: " + n.getNodeName()); + } + element = (DOM_Element &) document.getElementsByTagName("dBodyLevel21").item(0); // element gets DOM_Element test BodyLevel21 + element2 = (DOM_Element &) document.getElementsByTagName("dBodyLevel31").item(0); // element2 gets DOM_Element test BodyLevel31 + DOM_NodeList text = ((DOM_Node &) element2).getChildNodes(); + int textSize = text.getLength(); + int j; + static bool firstTime = true; + if (firstTime) + { + firstTime = false; // Temporary fix. Subsequent tests alter the doc, causing + // this test to fail on all but the first time through. + for (j = 0; j < textSize; j++) + { + DOM_Node n = (DOM_Node &) text.item(j); + if (! (textCompare[j].equals(n.getNodeValue()))) + { + printf("Warning!!! Comparison of original text nodes via DOM_Node 'getChildNodes' & DOM_NodeList 'item'\n" + " failed at text node: #%d \n ", j ); + n.getNodeValue().print(); + printf("\n"); + OK = false; + break; + } + // printf("DOM_Element testBodyLevel31's child text node " + j + " is: " + n.getNodeValue()); + } + } + + element = document.getDocumentElement(); // element gets doc's firstElement + element.normalize(); // Concatenates all adjacent text nodes in this element's subtree + DOM_NodeList text2 = ((DOM_Node) element2).getChildNodes(); + compare = "dBodyLevel31'sChildTextNode11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13"; + DOM_Node n = (DOM_Node &) text2.item(0); + if (! (compare.equals(n.getNodeValue()))) + { + printf("Warning!!! Comparison of concatenated text nodes created by DOM_Element's 'normalize' failed!\n"); + OK = false; + } + + element.setAttribute("FirstElementLastAttribute", "More attribute stuff for firstElement!!"); + element.removeAttribute("FirstElementLastAttribute"); + element.removeAttributeNode(newAttributeNode); + + // doc.getLastChild().setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR*** + +// For debugging***** printf("All DOM_Element method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_Element method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); + +}; + + + +/** + * This method tests DOM_Entity methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testEntity(DOM_Document document) +{ + DOM_Entity entity; + DOM_Node node, node2; + bool OK = true; + DOMString compare; +// For debugging***** printf("\n testEntity's outputs:\n\n"); + entity = (DOM_Entity &) document.getDoctype().getEntities().getNamedItem("ourEntityNode"); + node = entity; + node2 = entity.cloneNode(true); + // Check nodes for equality, both their name and value or lack thereof + if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + ((node.getNodeValue() != null && node2.getNodeValue() != null) ? // Checks to make sure each node has a value node + node.getNodeValue().equals(node2.getNodeValue()) : // If both have value nodes test those value nodes for equality + (node.getNodeValue() == null && node2.getNodeValue() == null)))) // If one node doesn't have a value node make sure both don't + { + printf("Warning!!! 'cloneNode' did not clone the DOM_Entity node correctly"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + + entity.setNotationName("testNotationName"); + compare = "testNotationName"; + if(! compare.equals(entity.getNotationName())) + { + printf("Warning!!! DOM_Entity's 'setNotationName' and/or getNotationName' failed!\n"); + OK = false; + } + entity.setPublicId("testPublicId"); + compare = "testPublicId"; + if(! compare.equals(entity.getPublicId())) + { + printf("Warning!!! DOM_Entity's 'setPublicId' and/or getPublicId' failed!\n"); + OK = false; + } + entity.setSystemId("testSystemId"); + compare = "testSystemId"; + if(! compare.equals(entity.getSystemId())) + { + printf("Warning!!! DOM_Entity's 'setSystemId' and/or getSystemId' failed!\n"); + OK = false; + } + // entity.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** + +// For debugging***** printf("All DOM_Entity method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_Entity method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); +}; + + +/** + * This method tests DOM_EntityReference methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testEntityReference(DOM_Document document) +{ + DOM_EntityReference entityReference; + DOM_Node node, node2; + bool OK = true; +// For debugging***** printf("\n testEntityReference's outputs:\n"); + entityReference = (DOM_EntityReference &) document.getLastChild().getLastChild().getLastChild().getFirstChild(); + node = entityReference; + node2 = node.cloneNode(true); + // Check nodes for equality, both their name and value or lack thereof + if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality + :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't + { + printf("'cloneNode' did not clone the DOM_EntityReference node correctly\n"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + + // entityReference.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** + +// For debugging***** printf("All DOM_EntityReference method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_EntityReference method calls listed above failed, all others worked correctly.*****\n"); +// printf("\n"); +}; + + + +/** + * This method tests DOM_Node methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + * + * + ********* This is only for a test of cloneNode "deep"******* + ********* And for error tests********* + */ +void DTest::testNode(DOM_Document document) +{ + DOM_Node node, node2; + bool result; + bool OK = true; +// For debugging***** printf("\n testNode's outputs:\n"); + node = document.getDocumentElement(); + node2 = node.cloneNode(true); + result = treeCompare(node, node2); // Deep clone test of cloneNode + if (result) + { + //printf("'cloneNode' successfully cloned this whole node tree (deep)!\n"); + } + else + { + printf("'cloneNode' did not successfully clone this whole node tree (deep)!\n"); + OK = false; + } + //!! The following gives a did not clone successfully message********* + node = document.getDocumentElement(); + node2 = node.getFirstChild(); + result = treeCompare(node, node2); + if (!result) + { + //printf("'cloneNode' did not successfully clone this whole node tree (deep)!\n"); + } + else + { + printf("'cloneNode' was supposed to fail here, either it or 'treeCompare' failed!!!\n"); + OK = false; + } + // Deep clone test also in testDocument + +// For debugging***** printf("All DOM_Node method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_Node method calls listed above failed, all others worked correctly.*****\n"); +// printf("\n"); +}; + + + +/** + * This method tests DOM_Notation methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testNotation(DOM_Document document) +{ + DOM_Node node, node2; + DOM_Notation notation; + bool OK = true; + DOMString compare; +// For debugging***** printf("\n testNotation's outputs:\n"); + notation = (DOM_Notation &) document.getDoctype().getNotations().getNamedItem("ourNotationNode"); + node = notation; + node2 = notation.cloneNode(true);//*****? + // Check nodes for equality, both their name and value or lack thereof + if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality + :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't + { + printf("'cloneNode' did not clone the DOM_Notation node correctly"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + + // IBM specific call... + notation.setPublicId("testPublicId");//*****? + compare = "testPublicId"; + if (!compare.equals(notation.getPublicId())) + { + printf("Warning!!! DOM_Notation's 'getPublicId' failed!"); + OK = false; + } + // IBM specific call... + notation.setSystemId("testSystemId");//*****? + compare = "testSystemId"; + if (! compare.equals(notation.getSystemId())) + { + printf("Warning!!! DOM_Notation's 'getSystemId' failed!\n"); + OK = false; + } + // notation.setNodeValue("This shouldn't work");//!! Throws a NO_MODIFICATION_ALLOWED_ERR ******** + +// For debugging***** printf("All DOM_Notation method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_Notation method calls listed above failed, all others worked correctly.*****\n"); +// printf(""); +}; + + + +/** + * This method tests DOM_ProcessingInstruction methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testPI(DOM_Document document) +{ + DOM_Node node, node2; + DOM_ProcessingInstruction pI, pI2; + DOMString compare; + bool OK = true; +// For debugging***** printf("\n testPI's outputs:\n"); + pI = (DOM_ProcessingInstruction &) document.getDocumentElement().getFirstChild();// Get doc's DOM_ProcessingInstruction + pI2 = (DOM_ProcessingInstruction &)pI.cloneNode(true);//*****? + // Check nodes for equality, both their name and value or lack thereof + if (!(pI.getNodeName().equals(pI2.getNodeName()) && // Compares node names for equality + (pI.getNodeValue() != null && pI2.getNodeValue() != null) // Checks to make sure each node has a value node + ? pI.getNodeValue().equals(pI2.getNodeValue()) // If both have value nodes test those value nodes for equality + :(pI.getNodeValue() == null && pI2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't + { + printf("'cloneNode' did not clone the DOM_Entity node correctly\n"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + // compare = "This is [#document: null]'s processing instruction"; // AH Revisit. Where id + // this ": null]" stuff come from in the Java version?? I don' think that it is right. + compare = "This is #document's processing instruction"; + if (! compare.equals(pI.getData())) + { + printf("Warning!!! PI's 'getData' failed!\n"); + OK = false; + } + + pI.setData("PI's reset data"); + compare = "PI's reset data"; + if (! compare.equals(pI.getData())) + { + printf("Warning!!! PI's 'setData' failed!\n"); + OK = false; + } + compare = "dTargetProcessorChannel"; + if (! compare.equals(pI.getTarget())) + { + printf("Warning!!! PI's 'getTarget' failed!\n"); + OK = false; + } + + + // Restore original PI data. + pI.setData("This is #document's processing instruction"); + +// For debugging***** printf("All PI method calls worked correctly.\n"); + if (!OK) + printf("\n*****The PI method calls listed above failed, all others worked correctly.*****\n"); + +// printf("\n"); +}; + + + +/** + * This method tests DOM_Text methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void DTest::testText(DOM_Document document) +{ + DOM_Node node, node2; + DOM_Text text; + DOMString compare; + bool OK = true; +// For debugging***** printf("\n testText's outputs:\n"); + DOM_Element elem = (DOM_Element &)document.getDocumentElement().getElementsByTagName("dBodyLevel31").item(0); + node = elem.getFirstChild(); // charData gets textNode11 + text = (DOM_Text &) node; + node2 = node.cloneNode(true);//*****? + // Check nodes for equality, both their name and value or lack thereof + if (!(node.getNodeName().equals(node2.getNodeName()) && // Compares node names for equality + (node.getNodeValue() != null && node2.getNodeValue() != null) // Checks to make sure each node has a value node + ? node.getNodeValue().equals(node2.getNodeValue()) // If both have value nodes test those value nodes for equality + :(node.getNodeValue() == null && node2.getNodeValue() == null)))// If one node doesn't have a value node make sure both don't + { + printf("'cloneNode' did not clone the DOM_Text node correctly\n"); + OK = false; + } + // Deep clone test comparison is in testNode & testDocument + + text.splitText(25); + // Three original text nodes were concatenated by 'normalize' in testElement + compare = "dBodyLevel31'sChildTextNo"; + if (! compare.equals(text.getNodeValue())) + { + printf("First part of DOM_Text's split text failed!\n" ); + OK = false; + } + // Three original text nodes were concatenated by 'normalize' in testElement + compare = "de11dBodyLevel31'sChildTextNode12dBodyLevel31'sChildTextNode13"; + if (! compare.equals(text.getNextSibling().getNodeValue())) + { + printf("The second part of DOM_Text's split text failed!\n") ; + OK = false; + } + + // Re-normalize the text nodes under elem, so that this test can be rerun. + elem.normalize(); + + +//************************************************* ERROR TESTS + DTest tests; + //!! Throws INDEX_SIZE_ERR ******************** + // text.splitText(-1); + // text.splitText(100); + +// For debugging***** printf("All DOM_Text method calls worked correctly.\n"); + if (!OK) + printf("\n*****The DOM_Text method calls listed above failed, all others worked correctly.*****\n"); + +// printf("\n"); +}; + + + + +/** + * + * @param node org.w3c.dom.DOM_Node + * @param node2 org.w3c.dom.DOM_Node + * + */ +bool DTest::treeCompare(DOM_Node node, DOM_Node node2) +{ + bool answer = true; + + DOM_Node kid, kid2; // Check the subtree for equality + kid = node.getFirstChild(); + kid2 = node2.getFirstChild(); + if (!kid.isNull() && !kid2.isNull()) + { + answer = treeCompare(kid, kid2); + if (!answer) + return answer; + else + if (!kid.getNextSibling().isNull() && !kid2.getNextSibling().isNull()) + { + while (!kid.getNextSibling().isNull() && !kid2.getNextSibling().isNull()) + { + answer = treeCompare(kid.getNextSibling(), kid2.getNextSibling()); + if (!answer) + return answer; + else + { + kid = kid.getNextSibling(); + kid2 = kid2.getNextSibling(); + } + } + } else + if (!(kid.getNextSibling().isNull() && kid2.getNextSibling().isNull())) + { + return false; + } + } else + if (kid != kid2) + { + // One or the other of (kid1, kid2) is null, but not both. + return false; + } + + if (!(node.getNodeName().equals(node2.getNodeName()))) + return false; + if (node.getNodeValue()==null && node2.getNodeValue()!=null) + return false; + if (node.getNodeValue()!=null && node2.getNodeValue()==null) + return false; + if (!(node.getNodeValue().equals(node2.getNodeValue()))) + return false; + + return answer; +}; + + diff --git a/tests/DOM/DOMTest/DTest.h b/tests/DOM/DOMTest/DTest.h new file mode 100644 index 0000000000000000000000000000000000000000..f36e53519efe34e54da7a59ad5225b2d2b7ec362 --- /dev/null +++ b/tests/DOM/DOMTest/DTest.h @@ -0,0 +1,351 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:38 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:24 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +/** + * This class tests methods for XML DOM implementation + * + * DOMException errors are tested by calls to DOMExceptionsTest from: Main, docBuilder... + * + */ + +#include <dom/DOM.hpp> +#include <dom/DomMemDebug.hpp> + +// define null for compatibility with original Java source code. +#define null 0 + +class DTest { +public: + static DOM_Element testElementNode; + static DOM_Attr testAttributeNode; + static DOM_Text testTextNode; + static DOM_CDATASection testCDATASectionNode; + static DOM_EntityReference testEntityReferenceNode; + static DOM_Entity testEntityNode; + static DOM_ProcessingInstruction testProcessingInstructionNode; + static DOM_Comment testCommentNode; + static DOM_Document testDocumentNode; + static DOM_DocumentType testDocumentTypeNode; + static DOM_DocumentFragment testDocumentFragmentNode; + static DOM_Notation testNotationNode; + + +DTest(); + + +/** + * version 3.0 01/25/99 + * + * @return DOM_Document + * + */ +DOM_Document createDocument(); + + +/** + * version 3.0 01/25/99 + * + * @return DOM_DocumentType + * @param name DOMString + * + */ +DOM_DocumentType createDocumentType(DOM_Document doc, DOMString name); + + +/** + * version 3.0 01/25/99 + * + * @return org.w3c.dom.DOM_Entity + * @param doc org.w3c.dom.DOM_Document + * @param name DOMString + * + */ +DOM_Entity createEntity(DOM_Document doc, DOMString name); + + +/** + * version 3.0 01/25/99 + * + * @return org.w3c.dom.DOM_Notation + * @param doc org.w3c.dom.DOM_Document + * @param name DOMString + * + */ +DOM_Notation createNotation(DOM_Document doc, DOMString name); + +/** + * This method builds test documents for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * @param name document's name + * @param type document's type + * + */ +void docBuilder(DOM_Document document, DOMString name); + + +/** + * version 3.0 01/25/99 + * + * @return boolean + * @param node java.lang.Object + * @param mNameIndex int + * @param signatureIndex int + * @param parameters java.lang.Object[] + * @param code short + * + */ +//static bool DOMExceptionsTest(Object node, DOMString methodName, Class[] methodSignature, Object[] parameters, short code) { + + +/** + * @param document org.w3c.dom.DOM_Document + */ +void findTestNodes(DOM_Document document); + +/** + * @param document org.w3c.dom.DOM_Document + */ +void findTestNodes(DOM_Node node); + + +/** + * This method tests DOM_Attr methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testAttr(DOM_Document document); + + +/** + * This method tests DOM_CDATASection methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testCDATASection(DOM_Document document); + + +/** + * This method tests CharacterData methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testCharacterData(DOM_Document document); + + +/** + * This method tests ChildNodeList methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testChildNodeList(DOM_Document document); + + +/** + * This method tests DOM_Comment methods for the XML DOM implementation + * version 1.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testComment(DOM_Document document); + + + +/** + * This method tests DeepNodeList methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testDeepNodeList(DOM_Document document); + +/** + * This method tests DOM_Document methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + * + **** ALL DOM_Document create methods are run in docBuilder except createAttribute which is in testAttribute** + */ +void testDocument(DOM_Document document); + + +/** + * This method tests DOM_DocumentFragment methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + * + * + ********This really isn't needed, only exists to throw NO_MODIFICATION_ALLOWED_ERR ******** + */ +void testDocumentFragment(DOM_Document document); + + +/** + * This method tests DOM_DocumentType methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testDocumentType(DOM_Document document); + +/** + * @param document org.w3c.dom.DOM_Document + */ +void testDOMerrors(DOM_Document document); + + + +/** + * This method tests DOMImplementation methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testDOMImplementation(DOM_Document document); + + +/** + * This method tests DOM_Element methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testElement(DOM_Document document); + + +/** + * This method tests DOM_Entity methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testEntity(DOM_Document document); + + +/** + * This method tests DOM_EntityReference methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testEntityReference(DOM_Document document); + + +/** + * This method tests DOM_Node methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + * + * + ********* This is only for a test of cloneNode "deep"******* + ********* And for error tests********* + */ +void testNode(DOM_Document document); + + +/** + * This method tests DOM_Notation methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testNotation(DOM_Document document); + + +/** + * This method tests DOM_ProcessingInstruction methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testPI(DOM_Document document); + + +/** + * This method tests DOM_Text methods for the XML DOM implementation + * version 2.0 10/12/98 + * @param document org.w3c.dom.DOM_Document + * + */ +void testText(DOM_Document document); + +/** + * + * @param node org.w3c.dom.DOM_Node + * @param node2 org.w3c.dom.DOM_Node + * + */ +bool treeCompare(DOM_Node node, DOM_Node node2); + +}; diff --git a/tests/ParserTest/ParserTest.cpp b/tests/ParserTest/ParserTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bde2a02ef4d1ed12eda548d2feb5c187f0817882 --- /dev/null +++ b/tests/ParserTest/ParserTest.cpp @@ -0,0 +1,205 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:14 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:42:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <util/PlatformUtils.hpp> +#include <util/XMLString.hpp> +#include <util/URL.hpp> +#include <internal/URLInputSource.hpp> +#include <internal/XMLScanner.hpp> +#include <validators/DTD/DTDValidator.hpp> +#include "ParserTest.hpp" + + +// --------------------------------------------------------------------------- +// Global data +// +// errStrm +// outStrm +// The streams we use to output our test data and error info. These are +// simple classes used just for XML4C2 samples and debug. They are not +// sufficient for real applications, nor are they supported for +// production code use. They merely provide a simple and portable means +// to output the Unicode data from the parser on the local host. +// --------------------------------------------------------------------------- +XMLStdErr errStrm; +XMLStdOut outStrm; + + +// --------------------------------------------------------------------------- +// Program entry point +// --------------------------------------------------------------------------- +int main(int argC, char** argV) +{ + // Init the XML platform + try + { + XMLPlatformUtils::Initialize(); + } + + catch(const XMLException& toCatch) + { + errStrm << "Error during platform init! Message:\n" + << toCatch.getMessage() << EndLn; + return 1; + } + + // + // Create our test parser object. This guy implements the internal event + // APIs and is plugged into the scanner. + // + TestParser parserTest; + + // Figure out the parameters + bool doValidation = false; + bool doNamespaces = false; + bool keepGoing = false; + XMLCh* urlPath = 0; + for (int index = 1; index < argC; index++) + { + if (!XMLString::compareIString(argV[index], "/Debug")) + parserTest.setOutputType(OutputType_Debug); + else if (!XMLString::compareIString(argV[index], "/Validate")) + doValidation = true; + else if (!XMLString::compareIString(argV[index], "/Namespaces")) + { + doNamespaces = true; + parserTest.setDoNamespaces(true); + } + else if (!XMLString::compareIString(argV[index], "/XML")) + parserTest.setOutputType(OutputType_XML); + else if (!XMLString::compareIString(argV[index], "/IntDTD")) + parserTest.setShowIntDTD(true); + else if (!XMLString::compareIString(argV[index], "/ShowWarnings")) + parserTest.setShowWarnings(true); + else if (!XMLString::compareIString(argV[index], "/ShowErrLoc")) + parserTest.setShowErrLoc(true); + else if (!XMLString::compareIString(argV[index], "/JCCanon")) + parserTest.setOutputType(OutputType_JCCanon); + else if (!XMLString::compareIString(argV[index], "/SunCanon")) + parserTest.setOutputType(OutputType_SunCanon); + else if (!XMLString::compareIString(argV[index], "/KeepGoing")) + keepGoing = true; + else if (!XMLString::compareNIString(argV[index], "/URL=", 5)) + urlPath = XMLString::transcode(&argV[index][5]); + else + errStrm << "Unknown parameter: " << argV[index] << EndLn; + } + + // We have to have a URL to work on + if (!urlPath) + { + errStrm << "A URL must be provided, /URL=xxxx" << EndLn; + return 1; + } + + // + // Create a validator of the correct type so that we can install it + // on the scanner. + // + // <TBD> Later, when Schema validators exist, we'll have a parameter + // to select one or the other + // + XMLValidator* validator = 0; + DTDValidator* dtdVal = new DTDValidator(&parserTest); + dtdVal->setDocTypeHandler(&parserTest); + validator = dtdVal; + + // And now create the scanner and give it all the handlers + XMLScanner scanner + ( + &parserTest + , 0 + , &parserTest + , validator + ); + + // Set the scanner flags that we were told to + scanner.setDoValidation(doValidation); + scanner.setDoNamespaces(doNamespaces); + scanner.setExitOnFirstFatal(!keepGoing); + + // Tell the parser about the scanner + parserTest.setScanner(&scanner); + + try + { + URLInputSource src(urlPath); + scanner.scanDocument(src); + } + + catch(const XMLException& toCatch) + { + outStrm << "Exception during scan:\n " + << toCatch.getMessage() + << EndLn; + } + + return 0; +} diff --git a/tests/ParserTest/ParserTest.hpp b/tests/ParserTest/ParserTest.hpp new file mode 100644 index 0000000000000000000000000000000000000000..780e75ed55e4b6bc41ef7252a4d40b65c71e3621 --- /dev/null +++ b/tests/ParserTest/ParserTest.hpp @@ -0,0 +1,91 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:17 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:42:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// Some types used by this program +// --------------------------------------------------------------------------- +enum OutputTypes +{ + OutputType_None + , OutputType_Debug + , OutputType_JCCanon + , OutputType_SunCanon + , OutputType_XML +}; + + +// --------------------------------------------------------------------------- +// Includes that everyone uses inside this program +// --------------------------------------------------------------------------- +#include <util/StdOut.hpp> +#include "ParserTest_Parser.hpp" + + +// --------------------------------------------------------------------------- +// Global data externs for everyone to see. These are from the main Cpp file +// --------------------------------------------------------------------------- +extern XMLStdOut outStrm; +extern XMLStdErr errStrm; diff --git a/tests/ParserTest/ParserTest_Parser.cpp b/tests/ParserTest/ParserTest_Parser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4355e7e41bee2e24eb136c60df596a9cc68f929d --- /dev/null +++ b/tests/ParserTest/ParserTest_Parser.cpp @@ -0,0 +1,1038 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:22 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:42:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <stdlib.h> +#include <util/RefVectorOf.hpp> +#include <util/XMLString.hpp> +#include <util/XMLUni.hpp> +#include <internal/XMLReader.hpp> +#include <internal/XMLScanner.hpp> +#include <framework/XMLAttr.hpp> +#include <framework/XMLNotationDecl.hpp> +#include <framework/XMLValidator.hpp> +#include <validators/DTD/DTDAttDef.hpp> +#include <validators/DTD/DTDElementDecl.hpp> +#include <validators/DTD/DTDEntityDecl.hpp> +#include "ParserTest.hpp" + +#include <util/BitOps.hpp> + +// --------------------------------------------------------------------------- +// Local functions +// --------------------------------------------------------------------------- +static int attrComp(const void* elemOne, const void* elemTwo) +{ + return XMLString::compareString + ( + (*(XMLAttr**)elemOne)->getName() + , (*(XMLAttr**)elemTwo)->getName() + ); +} + + +// --------------------------------------------------------------------------- +// TestParser: Constructors and Destructor +// --------------------------------------------------------------------------- +TestParser::TestParser() : + + fDoNamespaces(false) + , fInExtSubset(false) + , fInsideRoot(false) + , fIntDTDOutput(false) + , fNestingLevel(0) + , fOutputType(OutputType_None) + , fShowErrLoc(false) + , fShowWarnings(false) + , fSurrogate(0) +{ +} + +TestParser::~TestParser() +{ +} + + +// --------------------------------------------------------------------------- +// TestParser: The document handler interfaces +// --------------------------------------------------------------------------- +void TestParser::docCharacters( const XMLCh* const chars + , const unsigned int length + , const bool cdataSection) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got CHARS:\n Bytes: " + << length << ", CDATA?: " + << (cdataSection ? "Yes" : "No") + << "\n" << EndLn; + } + else if ((fOutputType == OutputType_JCCanon) + || (fOutputType == OutputType_SunCanon)) + { + showChars(chars, length); + } + else if (fOutputType == OutputType_XML) + { + if (cdataSection) + outStrm << "<![CDATA["; + showChars(chars, length); + if (cdataSection) + outStrm << "]]>"; + } +} + +void TestParser::docComment(const XMLCh* const comment) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got document COMMENT:\n " + << "Text: \"" << comment << "\"\n" + << EndLn; + } + else if (fOutputType == OutputType_XML) + { + outStrm << "<!--"; + showString(comment); + outStrm << "-->"; + } +} + +void TestParser::docPI( const XMLCh* const target + , const XMLCh* const data) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got document PI:\n " + << "Target: \"" << target << '"'; + + if (XMLString::stringLen(data)) + outStrm << ", Data: \"" << data << '"'; + + outStrm << "\n" << EndLn; + } + else if ((fOutputType == OutputType_XML) + || (fOutputType == OutputType_JCCanon) + || (fOutputType == OutputType_SunCanon)) + { + outStrm << "<?"; + showString(target); + outStrm << " "; + if (XMLString::stringLen(data)) + outStrm << data; + outStrm << "?>"; + } +} + + +void TestParser::endDocument() +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got ENDDOCUMENT:\n" << EndLn; + } + else if (fOutputType == OutputType_SunCanon) + { + outStrm << "\r\n"; + } +} + +void TestParser::endElement(const XMLElementDecl& elemDecl + , const unsigned int uriId + , const bool isRoot) +{ + if (fOutputType == OutputType_Debug) + { + if (fDoNamespaces) + { + XMLBuffer bufURI; + fScanner->getValidator()->getURIText(uriId, bufURI); + + outStrm << "Got ENDELEMENT:\n Name: " + << "Name: {" << bufURI.getRawBuffer() << "}" + << elemDecl.getBaseName() + << EndLn; + } + else + { + outStrm << "Got ENDELEMENT:\n Name: " + << elemDecl.getFullName() << EndLn; + } + + outStrm << EndLn; + } + else if ((fOutputType == OutputType_XML) + || (fOutputType == OutputType_JCCanon) + || (fOutputType == OutputType_SunCanon)) + { + outStrm << "</"; + showString(elemDecl.getFullName()); + outStrm << ">"; + } + + // Clear the flag that says we're now inside the root + if (isRoot) + fInsideRoot = false; +} + +void TestParser::endEntityReference(const XMLEntityDecl& entDecl) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got ENDENTITYREF:\n " + << "Name: " << entDecl.getName() << "\n" << EndLn; + } +} + +void TestParser::ignorableWhitespace(const XMLCh* const chars + , const unsigned int length + , const bool cdataSection) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got WHITESPACE:\n Bytes: " + << length << ", CDATA?: " + << (cdataSection ? "Yes" : "No") + << "\n" << EndLn; + } + else if (fOutputType == OutputType_XML) + { + if (cdataSection) + outStrm << "<![CDATA["; + showChars(chars, length); + if (cdataSection) + outStrm << "]]>"; + } + else if ((fOutputType == OutputType_JCCanon) + || (fOutputType == OutputType_SunCanon)) + { + if (!fInsideRoot) + return; + showChars(chars, length); + } +} + +void TestParser::resetDocument() +{ + if (fOutputType == OutputType_Debug) + outStrm << "Got RESETDOCUMENT:\n" << EndLn; +} + +void TestParser::startDocument() +{ + if (fOutputType == OutputType_Debug) + outStrm << "Got STARTDOCUMENT:\n" << EndLn; +} + +void +TestParser::startElement(const XMLElementDecl& elemDecl + , const unsigned int uriId + , const XMLCh* const prefixName + , const RefVectorOf<XMLAttr>& attrList + , const unsigned int attCount + , const bool isEmpty + , const bool isRoot) +{ + // Set the flag that says we're now inside the root, if its not empty + if (isRoot && !isEmpty) + fInsideRoot = true; + + if (fOutputType == OutputType_Debug) + { + XMLBuffer bufURI; + if (fDoNamespaces) + { + fScanner->getValidator()->getURIText(uriId, bufURI); + outStrm << "Got STARTELEMENT:\n " + << " Name: {" << bufURI.getRawBuffer() << "}" << elemDecl.getBaseName() + << ", AttCount: " << attCount + << ", Empty?: " + << (isEmpty ? "yes" : "no") + << "\n"; + } + else + { + outStrm << "Got STARTELEMENT:\n " + << " Name: " << elemDecl.getFullName() + << ", AttCount: " << attCount + << ", Empty?: " + << (isEmpty ? "yes" : "no") + << "\n"; + } + + // If any attributes, then show them + if (attCount) + { + outStrm << " Attrs: "; + for (unsigned int attInd = 0; attInd < attCount; attInd++) + { + const XMLAttr* curAttr = attrList.elementAt(attInd); + + if (fDoNamespaces) + { + fScanner->getValidator()->getURIText(curAttr->getURIId(), bufURI); + outStrm << "{" << bufURI.getRawBuffer() + << "}" << curAttr->getName() << "=" + << curAttr->getValue() << "\n"; + } + else + { + outStrm << curAttr->getQName() << "=" + << curAttr->getValue() << "\n"; + } + + outStrm << " "; + } + } + + outStrm << EndLn; + } + else if (fOutputType == OutputType_XML) + { + outStrm << "<"; + showString(elemDecl.getFullName()); + + if (attCount) + { + outStrm << " "; + + for (unsigned int index = 0; index < attCount; index++) + { + const XMLAttr* curAttr = attrList.elementAt(index); + showString(curAttr->getQName()); + outStrm << "=\""; + showString(curAttr->getValue()); + outStrm << "\""; + + if (index < attCount-1) + outStrm << " "; + } + } + + if (isEmpty) + outStrm << "/>"; + else + outStrm << ">"; + } + else if ((fOutputType == OutputType_JCCanon) + || (fOutputType == OutputType_SunCanon)) + { + outStrm << "<"; + showString(elemDecl.getFullName()); + + if (attCount) + { + outStrm << " "; + + // + // Get a list of attribute pointers. The canonical output + // format requires sorted attributes. If we aren't doing + // canonical output, then we don't sort it, but we still use + // the array. + // + const XMLAttr** attrTmp = new const XMLAttr*[attCount]; + unsigned int index; + for (index = 0; index < attCount; index++) + attrTmp[index] = attrList.elementAt(index); + + if (attCount > 1) + qsort(attrTmp, attCount, sizeof(XMLAttr*), attrComp); + + for (index = 0; index < attCount; index++) + { + const XMLAttr* curAttr = attrTmp[index]; + showString(curAttr->getQName()); + outStrm << "=\""; + showString(curAttr->getValue()); + outStrm << "\""; + + if (index < attCount-1) + outStrm << " "; + } + delete [] attrTmp; + } + + if (isEmpty) + { + outStrm << "></"; + showString(elemDecl.getFullName()); + outStrm << ">"; + } + else + { + outStrm << ">"; + } + } +} + +void TestParser::startEntityReference(const XMLEntityDecl& entDecl) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got STARTENTITY:\n " + << "Name: " << entDecl.getName() << "\n" << EndLn; + } +} + +void TestParser::XMLDecl(const XMLCh* const versionStr + , const XMLCh* const encodingStr + , const XMLCh* const standaloneStr + , const XMLCh* const autoEncStr) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got XMLDECL:\n " + << "Version:\"" << versionStr << "\"" + << " Encoding:\"" << encodingStr << "\"" + << " Standalone:\"" << standaloneStr << "\"" + << " Auto Encoding:\"" << autoEncStr << "\"" + << "\n" + << EndLn; + } + else if (fOutputType == OutputType_XML) + { + outStrm << "<?xml"; + + if (XMLString::stringLen(versionStr)) + outStrm << " version=\"" << versionStr << '"'; + + if (XMLString::stringLen(encodingStr)) + outStrm << " encoding=\"" << encodingStr << '"'; + + if (XMLString::stringLen(standaloneStr)) + outStrm << " standlone=\"" << standaloneStr << '"'; + + outStrm << " ?>"; + } +} + + +// ----------------------------------------------------------------------- +// TestParser: The DocTypeHandler interface +// ----------------------------------------------------------------------- +void TestParser::attDef(const DTDElementDecl& elemDecl + , const DTDAttDef& attDef + , const bool ignoring) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got ATTDEF:\n " + << "Name: " << attDef.getFullName() + << ", Type: " + << XMLAttDef::getAttTypeString(attDef.getType()) + << ", DefType: " + << XMLAttDef::getDefAttTypeString(attDef.getDefaultType()); + + if (XMLString::stringLen(attDef.getValue())) + outStrm << ", Value: \"" << attDef.getValue() << '"'; + + outStrm << "\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + { + outStrm << attDef.getFullName() << " "; + if (attDef.getType() == XMLAttDef::Enumeration) + { + outStrm << chOpenParen; + const XMLCh* curCh = attDef.getEnumeration(); + while (*curCh) + { + while (!XMLReader::isWhitespace(*curCh)) + outStrm << *curCh++; + curCh++; + if (*curCh) + outStrm << chPipe; + } + outStrm << chCloseParen; + } + else + { + outStrm << XMLAttDef::getAttTypeString(attDef.getType()); + } + + if (XMLString::stringLen(attDef.getValue())) + outStrm << " \"" << attDef.getValue() << '"'; + + if (attDef.getDefaultType() != XMLAttDef::Default) + { + outStrm << " " + << XMLAttDef::getDefAttTypeString(attDef.getDefaultType()); + } + } + } +} + +void TestParser::doctypeComment(const XMLCh* const comment) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got DTD COMMENT:\n " + << "Text: \"" << comment << "\"\n" + << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + outStrm << "<!--" << comment << "-->"; + } +} + +void TestParser::doctypeDecl(const DTDElementDecl& elemDecl + , const XMLCh* const publicId + , const XMLCh* const systemId + , const bool hasIntSubset) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got DOCTYPE:\n " + << "Root: " << elemDecl.getFullName(); + + if (XMLString::stringLen(publicId)) + outStrm << ", PUBLIC: " << publicId; + + if (XMLString::stringLen(systemId)) + outStrm << ", SYSTEM: " << systemId; + + outStrm << "\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fIntDTDOutput) + { + outStrm << "<!DOCTYPE " << elemDecl.getFullName(); + showIds(publicId, systemId); + + if (!hasIntSubset) + outStrm << ">"; + } + } +} + +void TestParser::doctypePI( const XMLCh* const target + , const XMLCh* const data) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got DTD PI:\n " + << "Target: \"" << target << '"'; + + if (XMLString::stringLen(data)) + outStrm << ", Data: \"" << data << '"'; + outStrm << "\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + { + outStrm << "<?" << target; + if (XMLString::stringLen(data)) + outStrm << " " << data; + outStrm << "?>"; + } + } +} + +void TestParser::doctypeWhitespace( const XMLCh* const chars + , const unsigned int length) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got DTD Spaces:\n Bytes: " + << length << "\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + showChars(chars, length); + } +} + +void TestParser::elementDecl(const DTDElementDecl& decl + , const bool isIgnored) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got ELEMENT DECL:\n " + << "Name: " << decl.getFullName(); + + if (isIgnored) + outStrm << " (Ignored)"; + + outStrm << ", Content: "; + outStrm << decl.getFormattedContentModel(*fScanner->getValidator()); + outStrm << "\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + { + outStrm << "<!ELEMENT " << decl.getFullName() << " "; + outStrm << decl.getFormattedContentModel(*fScanner->getValidator()); + outStrm << ">"; + } + } +} + +void TestParser::endAttList(const DTDElementDecl& elemDecl) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got ENDATTLIST:\n " + << "Name: " << elemDecl.getFullName() << "\n" + << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + outStrm << ">"; + } +} + +void TestParser::endIntSubset() +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got ENDINTSUBSET\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fIntDTDOutput) + outStrm << "]>"; + } +} + +void TestParser::endExtSubset() +{ + fInExtSubset = false; + if (fOutputType == OutputType_Debug) + outStrm << "Got ENDEXTSUBSET\n" << EndLn; +} + +void TestParser::entityDecl(const DTDEntityDecl& entityDecl + , const bool isPEDecl + , const bool isIgnored) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got ENTITYDECL:\n " + << "Name: " << entityDecl.getName() + << (isPEDecl ? " [Parameter Entity]" : " [General Entity]") + << "\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + { + outStrm << "<!ENTITY "; + if (isPEDecl) + outStrm << "% "; + outStrm << entityDecl.getName(); + + if (entityDecl.isExternal()) + showIds(entityDecl.getPublicId(), entityDecl.getSystemId()); + else + outStrm << " \"" << entityDecl.getValue() << "\""; + + outStrm << ">"; + } + } +} + +void TestParser::resetDocType() +{ + if (fOutputType == OutputType_Debug) + outStrm << "Got RESETDOCTYPE:\n" << EndLn; +} + +void TestParser::notationDecl( const XMLNotationDecl& notDecl + , const bool isIgnored) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got NOTATIONDECL:\n " + << "Name: " << notDecl.getName() + << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + { + outStrm << "<!NOTATION " << notDecl.getName() << " "; + + if (!XMLString::stringLen(notDecl.getSystemId())) + outStrm << "PUBLIC "; + else + outStrm << "SYSTEM "; + + if (XMLString::stringLen(notDecl.getPublicId())) + outStrm << "\"" << notDecl.getPublicId() << '"'; + + if (XMLString::stringLen(notDecl.getSystemId())) + outStrm << " \"" << notDecl.getSystemId() << '"'; + + outStrm << ">"; + } + } +} + +void TestParser::startAttList(const DTDElementDecl& elemDecl) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got STARTATTLIST:\n " + << "Name: " << elemDecl.getFullName() << "\n" + << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fInExtSubset) + return; + + if (fIntDTDOutput) + outStrm << "<!ATTLIST " << elemDecl.getFullName(); + } +} + +void TestParser::startIntSubset() +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got STARTINTSUBSET\n" << EndLn; + } + else if (fOutputType != OutputType_None) + { + if (fIntDTDOutput) + outStrm << " ["; + } +} + +void TestParser::startExtSubset() +{ + fInExtSubset = true; + if (fOutputType == OutputType_Debug) + outStrm << "Got STARTEXTSUBSET\n" << EndLn; +} + +void TestParser::TextDecl( const XMLCh* const versionStr + , const XMLCh* const encodingStr) +{ + if (fOutputType == OutputType_Debug) + { + outStrm << "Got TEXTDECL:\n "; + + if (XMLString::stringLen(versionStr)) + outStrm << "Version: " << versionStr; + + if (XMLString::stringLen(encodingStr)) + outStrm << "Encoding: " << encodingStr; + + outStrm << "\n" << EndLn; + } +} + + +// --------------------------------------------------------------------------- +// TestParser: Implementation of the XMLErrorReporter interface +// --------------------------------------------------------------------------- +void TestParser::error( const unsigned int errCode + , const XMLCh* const msgDomain + , const XMLErrorReporter::ErrTypes type + , const XMLCh* const text + , const XMLCh* const systemId + , const XMLCh* const publicId + , const unsigned int lineNum + , const unsigned int colNum) +{ + // + // If we are in 'show error loc' mode, then we do a special, condensed + // display of error location info. Else we fall through and do the + // normal one for human consumption. + // + if (fShowErrLoc) + { + // We only do fatal and validity errors in this case + if (type == XMLErrorReporter::ErrType_Warning) + return; + + // + // We want to display the entity name, but not the whole path, since + // this output is for regression testing and has to be compared + // against previous runs potentitally on other machines. + // + const XMLCh* entName = systemId; + int ofs = XMLString::lastIndexOf(systemId, chForwardSlash); + if (ofs == -1) + ofs = XMLString::lastIndexOf(systemId, chBackSlash); + if (ofs != -1) + entName = &systemId[ofs + 1]; + + outStrm << lineNum << "/" << colNum + << L":" << entName + << L" - " << text + << EndLn; + return; + } + + // If its a warning and we are not showing warnings, then get out + if ((type == XMLErrorReporter::ErrType_Warning) && !fShowWarnings) + return; + + const char* typeStr = "?"; + if (type == XMLErrorReporter::ErrType_Fatal) + typeStr = "ERROR"; + else if (type == XMLErrorReporter::ErrType_Warning) + typeStr = "WARNING"; + else if (type == XMLErrorReporter::ErrType_Invalid) + typeStr = "VALIDITY"; + + // Save the stream flags so that we can restore them + StreamJanitor strmJan(&errStrm); + + // Output the error heading and the error type string + outStrm << "\nError: (" << typeStr; + + // If we have either id, display them + if (XMLString::stringLen(systemId)) + outStrm << ", System Id: " << systemId; + + if (XMLString::stringLen(publicId)) + outStrm << ", Public Id: " << publicId; + + // Display the position information + outStrm << DecimalRadix + << ", Line/Col: " << lineNum << "/" << colNum + << ")\n"; + + // And finally the error text + outStrm << text << EndLn; +} + +void TestParser::resetErrors() +{ + if (fOutputType == OutputType_Debug) + outStrm << "Got RESETERRORS:\n" << EndLn; +} + + +// --------------------------------------------------------------------------- +// TestParser: Private helpers +// --------------------------------------------------------------------------- +void TestParser::showChars( const XMLCh* const chars + , const unsigned int length) +{ + static const XMLByte FirstByteMark[7] = + { + 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC + }; + + const bool doCan = ((fOutputType == OutputType_SunCanon) + || (fOutputType == OutputType_JCCanon)); + + unsigned int index = 0; + while (index < length) + { + // + // Convert the char to UTF-8 format. This will generate multiple + // short chars to display. For each one, call the showChar() + // method to display it. + // + XMLUInt32 tmpVal = chars[index++]; + + if ((tmpVal >= 0xD800) && (tmpVal <= 0xDBFF)) + { + if (index == length) + { + errStrm << "Missing trailing surrogate\n" << EndLn; + break; + } + + tmpVal = ((tmpVal - 0xD800) << 10) + + ((chars[index] - 0xDC00) + 0x10000); + index++; + } + + // Figure out how many bytes we'll kick out + unsigned int outBytes; + if (tmpVal < 0x80) + outBytes = 1; + else if (tmpVal < 0x800) + outBytes = 2; + else if (tmpVal < 0x10000) + outBytes = 3; + else if (tmpVal < 0x200000) + outBytes = 4; + else if (tmpVal < 0x4000000) + outBytes = 5; + else + { + outBytes = 6; + if (tmpVal & 0x80000000) + { + outBytes = 2; + tmpVal = 0xFFFD; + } + } + + // Get the chars into a temp buffer in the right order + char tmpOutChars[6]; + unsigned int outIndex = outBytes; + switch(outBytes) + { + case 6 : tmpOutChars[--outIndex] = char((tmpVal | 0x80) & 0xBF); + tmpVal >>= 6; + case 5 : tmpOutChars[--outIndex] = char((tmpVal | 0x80) & 0xBF); + tmpVal >>= 6; + case 4 : tmpOutChars[--outIndex] = char((tmpVal | 0x80) & 0xBF); + tmpVal >>= 6; + case 3 : tmpOutChars[--outIndex] = char((tmpVal | 0x80) & 0xBF); + tmpVal >>= 6; + case 2 : tmpOutChars[--outIndex] = char((tmpVal | 0x80) & 0xBF); + tmpVal >>= 6; + case 1 : tmpOutChars[--outIndex] = char(tmpVal | FirstByteMark[outBytes]); + } + + // And spit them out + for (outIndex = 0; outIndex < outBytes; outIndex++) + showChar(tmpOutChars[outIndex], doCan); + } +} + + +void TestParser::showChar(const char toShow, const bool doCan) +{ + if (doCan) + { + if (toShow == chLF) + outStrm << " "; + else if (toShow == chHTab) + outStrm << "	"; + else if (toShow == chCR) + outStrm << " "; + else if (toShow == chSingleQuote) + outStrm << "'"; + else if (toShow == chAmpersand) + outStrm << "&"; + else if (toShow == chDoubleQuote) + outStrm << """; + else if (toShow == chOpenAngle) + outStrm << "<"; + else if (toShow == chCloseAngle) + outStrm << ">"; + else + outStrm << toShow; + } + else + { + outStrm << toShow; + } +} + +void +TestParser::showIds(const XMLCh* const publicId, const XMLCh* const systemId) +{ + if (XMLString::stringLen(publicId) || XMLString::stringLen(systemId)) + { + if (!XMLString::stringLen(publicId)) + { + outStrm << " SYSTEM '" << systemId << "'"; + } + else + { + outStrm << " PUBLIC '" << publicId << "'"; + if (systemId) + outStrm << " '" << systemId << "'"; + } + } +} diff --git a/tests/ParserTest/ParserTest_Parser.hpp b/tests/ParserTest/ParserTest_Parser.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e2407af3a7993ba1be905a044068759c1044f947 --- /dev/null +++ b/tests/ParserTest/ParserTest_Parser.hpp @@ -0,0 +1,391 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:23 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:42:25 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <framework/XMLDocumentHandler.hpp> +#include <framework/XMLErrorReporter.hpp> +#include <validators/DTD/DocTypeHandler.hpp> + + +class TestParser : + + public XMLDocumentHandler, public XMLErrorReporter, public DocTypeHandler +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + TestParser(); + ~TestParser(); + + + // ----------------------------------------------------------------------- + // Setter methods + // ----------------------------------------------------------------------- + void setDoNamespaces(const bool state); + void setScanner(XMLScanner* const state); + void setOutputType(const OutputTypes outType); + void setShowErrLoc(const bool state); + void setShowIntDTD(const bool state); + void setShowWarnings(const bool state); + + + // ----------------------------------------------------------------------- + // The XMLDocumentHandler interface + // ----------------------------------------------------------------------- + virtual void docCharacters + ( + const XMLCh* const chars + , const unsigned int length + , const bool cdataSection + ); + + virtual void docComment + ( + const XMLCh* const comment + ); + + virtual void docPI + ( + const XMLCh* const target + , const XMLCh* const data + ); + + virtual void endDocument(); + + virtual void endElement + ( + const XMLElementDecl& elemDecl + , const unsigned int uriId + , const bool isRoot + ); + + virtual void endEntityReference + ( + const XMLEntityDecl& entDecl + ); + + virtual void ignorableWhitespace + ( + const XMLCh* const chars + , const unsigned int length + , const bool cdataSection + ); + + virtual void resetDocument(); + + virtual void startDocument(); + + virtual void startElement + ( + const XMLElementDecl& elemDecl + , const unsigned int elemURIId + , const XMLCh* const elemPrefix + , const RefVectorOf<XMLAttr>& attrList + , const unsigned int attrCount + , const bool isEmpty + , const bool isRoot + ); + + virtual void startEntityReference + ( + const XMLEntityDecl& entDecl + ); + + virtual void XMLDecl + ( + const XMLCh* const versionStr + , const XMLCh* const encodingStr + , const XMLCh* const standaloneStr + , const XMLCh* const autoEncStr + ); + + + // ----------------------------------------------------------------------- + // Implementation of the XMLErrorReporter interface + // ----------------------------------------------------------------------- + virtual void error + ( + const unsigned int errCode + , const XMLCh* const msgDomain + , const XMLErrorReporter::ErrTypes type + , const XMLCh* const text + , const XMLCh* const systemId + , const XMLCh* const publicId + , const unsigned int lineNum + , const unsigned int colNum + ); + + virtual void resetErrors(); + + + // ----------------------------------------------------------------------- + // The document type handler virtual handler interface + // ----------------------------------------------------------------------- + virtual void attDef + ( + const DTDElementDecl& elemDecl + , const DTDAttDef& attDef + , const bool ignoring + ); + + virtual void doctypeComment + ( + const XMLCh* const comment + ); + + virtual void doctypeDecl + ( + const DTDElementDecl& elemDecl + , const XMLCh* const publicId + , const XMLCh* const systemId + , const bool hasIntSubset + ); + + virtual void doctypePI + ( + const XMLCh* const target + , const XMLCh* const data + ); + + virtual void doctypeWhitespace + ( + const XMLCh* const chars + , const unsigned int length + ); + + virtual void elementDecl + ( + const DTDElementDecl& decl + , const bool isIgnored + ); + + virtual void endAttList + ( + const DTDElementDecl& elemDecl + ); + + virtual void endIntSubset(); + + virtual void endExtSubset(); + + virtual void entityDecl + ( + const DTDEntityDecl& entityDecl + , const bool isPEDecl + , const bool isIgnored + ); + + virtual void resetDocType(); + + virtual void notationDecl + ( + const XMLNotationDecl& notDecl + , const bool isIgnored + ); + + virtual void startAttList + ( + const DTDElementDecl& elemDecl + ); + + virtual void startIntSubset(); + + virtual void startExtSubset(); + + virtual void TextDecl + ( + const XMLCh* const versionStr + , const XMLCh* const encodingStr + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + TestParser(const TestParser&); + void operator=(const TestParser&); + + + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + void showChar(const char toShow, const bool doCan); + void showChars + ( + const XMLCh* const chars + , const unsigned int length + ); + void showIds(const XMLCh* const publicId, const XMLCh* const systemId); + void showString(const XMLCh* const toShow); + + + // ----------------------------------------------------------------------- + // Data members + // + // fDoNamespaces + // Indicates whether the user wanted us to be namespace aware or + // not. + // + // fInsideRoot + // This is set once the first start element event is seen, and cleared + // when the root element ends. Its used to support the canonical + // format used by the Bosak tests. Basically it allows us to supress + // the whitespace outside the internal subset but before the root + // element. + // + // fInExtSubSet + // Indicates when we are in the external subset, so that we don't + // display that part. + // + // fIntDTDOutput + // Indicates whether the data from the internal DTD subset is + // output or not (only used if fXMLOutput is true.) + // + // fNestingLevel + // This is used to handle tabbing over nested elements. Each start + // element bumps it up, and each end element bumps it down. + // + // fOutputType + // This flag controls the primary style of output used. It can + // be set to do James Clark type canonical output, Sun style + // canonical output, debug output, regular XML output, or none. + // + // fScanner + // The scanner we created to do the scanning. + // + // fShowErrLoc + // This flag turns on the special display mode that is used for + // negative test testing. It puts out a special, condensed display + // of error info that can be compared in subsequent runs to check + // for changes. If its turned on, it forces the output type to + // 'none'. + // + // fShowWarnings + // Indicates whether warning messages should be displayed or not. + // + // fSurrogate + // Indicates that we got a surrogate char, so we have to wait for + // the next char before we can output it. Its zero when not. + // ----------------------------------------------------------------------- + bool fDoNamespaces; + bool fInExtSubset; + bool fInsideRoot; + bool fIntDTDOutput; + unsigned int fNestingLevel; + OutputTypes fOutputType; + XMLScanner* fScanner; + bool fShowErrLoc; + bool fShowWarnings; + XMLCh fSurrogate; +}; + + +// --------------------------------------------------------------------------- +// TestParser: Setter Methods +// --------------------------------------------------------------------------- +inline void TestParser::setDoNamespaces(const bool state) +{ + fDoNamespaces = state; +} + +inline void TestParser::setScanner(XMLScanner* const ourScanner) +{ + fScanner = ourScanner; +} + +inline void TestParser::setOutputType(const OutputTypes outType) +{ + fOutputType = outType; +} + +inline void TestParser::setShowIntDTD(const bool state) +{ + fIntDTDOutput = state; +} + +inline void TestParser::setShowWarnings(const bool state) +{ + fShowWarnings = state; +} + +inline void TestParser::setShowErrLoc(const bool state) +{ + fShowErrLoc = state; +} + + +// --------------------------------------------------------------------------- +// TestParser: Private helpers +// --------------------------------------------------------------------------- +inline void TestParser::showString(const XMLCh* const toShow) +{ + showChars(toShow, XMLString::stringLen(toShow)); +} diff --git a/tests/UtilTests/CoreTests.hpp b/tests/UtilTests/CoreTests.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bea9eed080a085e195046c622188fb46f4daad6c --- /dev/null +++ b/tests/UtilTests/CoreTests.hpp @@ -0,0 +1,72 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:43 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:26 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#include <util/XMLException.hpp> +#include <util/XMLString.hpp> +#include <util/StdOut.hpp> +#include <util/XMLUni.hpp> + +extern XMLStdOut outStrm; diff --git a/tests/UtilTests/CoreTestsMain.cpp b/tests/UtilTests/CoreTestsMain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ee4ff51a458c97cb0b255112133016f9254c009 --- /dev/null +++ b/tests/UtilTests/CoreTestsMain.cpp @@ -0,0 +1,272 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:44 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:26 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/PlatformUtils.hpp> + + +// --------------------------------------------------------------------------- +// Global data +// --------------------------------------------------------------------------- +XMLStdOut outStrm; + + +// --------------------------------------------------------------------------- +// Externs for our testing methods. There is just one per file so a header +// for each one is a little overkill, so we just do it the old fashioned way. +// --------------------------------------------------------------------------- +extern bool testTranscoders(); +extern bool testCountedPointer(); +extern bool testBitSet(); +extern bool testRefArray(); +extern bool testRefHashTable(); +extern bool testRefStack(); +extern bool testRefVector(); +extern bool testString(); +extern bool testURL(); +extern bool testValueArray(); +extern bool testValueStack(); +extern bool testValueVector(); + + +int main() +{ + // Do the platform initialization + try + { + XMLPlatformUtils::Initialize(); + } + + catch(const XMLException& toCatch) + { + outStrm << "Parser Init Failed!\n INFO: (" + << toCatch.getSrcFile() << "." << toCatch.getSrcLine() << ") -" + << toCatch.getMessage() << EndLn; + return 0xFFFF; + } + + outStrm << "\nXML4C2 Core Utilities Unit Tester\n" << EndLn; + + // This value will return the number of failed tests + int retVal = 0; + + + try + { + // ------------------------------------------------------------------- + // Test the basic transcoding services + // ------------------------------------------------------------------- + if (!testTranscoders()) + { + outStrm << "Transcoder tests failed\n"; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the String class + // ------------------------------------------------------------------- + if (!testString()) + { + outStrm << "String tests failed\n"; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the CountedPointerTo template class + // ------------------------------------------------------------------- + if (!testCountedPointer()) + { + outStrm << "CountedPointerTo tests failed\n"; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the URL class + // ------------------------------------------------------------------- + if (!testURL()) + { + outStrm << "URL tests failed\n"; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the ValueVectorOf template class + // ------------------------------------------------------------------- + if (!testValueVector()) + { + outStrm << "ValueVectorOf tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the ValueArrayOf template class + // ------------------------------------------------------------------- + if (!testValueArray()) + { + outStrm << "ValueArrayOf tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the ValueStackOf template class + // ------------------------------------------------------------------- + if (!testValueStack()) + { + outStrm << "ValueStackOf tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the RefArrayOf template class + // ------------------------------------------------------------------- + if (!testRefArray()) + { + outStrm << "RefArrayOf tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the RefStackOf template class + // ------------------------------------------------------------------- + if (!testRefStack()) + { + outStrm << "RefStackOf tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the RefVectorOf template class + // ------------------------------------------------------------------- + if (!testRefVector()) + { + outStrm << "RefVectorOf tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the RefHashtableOf template class + // ------------------------------------------------------------------- + if (!testRefHashTable()) + { + outStrm << "RefHashTableOf tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + + + // ------------------------------------------------------------------- + // Test the BitSet class + // ------------------------------------------------------------------- + if (!testBitSet()) + { + outStrm << "BitSet tests failed" << EndLn; + retVal++; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << "Exception During Test!\n INFO: (" + << toCatch.getSrcFile() << "." << toCatch.getSrcLine() << ") -" + << toCatch.getMessage() << EndLn; + return 0xFFFF; + } + + // If we failed any tests, display a message + outStrm << "--------------------------------\n"; + if (retVal == 0) + outStrm << "<<PASSED>>: All tests passed\n"; + else + outStrm << "<<FAILED>>: Some tests failed\n"; + outStrm << "--------------------------------\n" << EndLn; + + return retVal; +} diff --git a/tests/UtilTests/CoreTests_BitSet.cpp b/tests/UtilTests/CoreTests_BitSet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0760f3b97d912873d5bd7e3399dbe1d8ea3ece2f --- /dev/null +++ b/tests/UtilTests/CoreTests_BitSet.cpp @@ -0,0 +1,292 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:47 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:26 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 Includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/BitSet.hpp> + + + +// --------------------------------------------------------------------------- +// Local testing methods +// --------------------------------------------------------------------------- +static bool basicTests() +{ + // + // Create a bitset with 32 bits. We just happen to know that this is + // the unit of expansion, so it should come back with exactly that + // number of bits of size. + // + BitSet setTest(32); + + if (setTest.size() != 32) + { + outStrm << " Ctor did not create set of correct size" << EndLn; + return false; + } + + // + // Check the value of all of the bits and make sure that they all come + // back zero. + // + const unsigned int count = setTest.size(); + unsigned int index; + for (index = 0; index < count; index++) + { + if (setTest.get(index)) + { + outStrm << " A bit's initial value was not zero" << EndLn; + return false; + } + } + + // Make sure that allAreCleared() agrees + if (!setTest.allAreCleared()) + { + outStrm << " allAreCleared() disagrees with individual bit gets" + << EndLn; + return false; + } + + // Set and clear each bit and make sure that they come back right + for (index = 0; index < count; index++) + { + setTest.set(index); + if (!setTest.get(index)) + { + outStrm << " Bit was set but get returned false" << EndLn; + return false; + } + + setTest.clear(index); + if (setTest.get(index)) + { + outStrm << " Bit was cleared but get returned true" + << EndLn; + return false; + } + } + + // And once more make sure they are all zero + for (index = 0; index < count; index++) + { + if (setTest.get(index)) + { + outStrm << " A bit remained set after clearing" << EndLn; + return false; + } + } + + // + // Set some bits, then copy construct another bitset from this one. Then + // see if they come out equal. + // + setTest.set(1); + setTest.set(16); + setTest.set(20); + setTest.set(24); + + BitSet setTest2(setTest); + if (!setTest.equals(setTest2)) + { + outStrm << " Copy ctor did not create equal sets" << EndLn; + return false; + } + + // Clear all bits of the copy and make sure they are all cleared + setTest2.clearAll(); + for (index = 0; index < count; index++) + { + if (setTest2.get(index)) + { + outStrm << " clearAll() did not clear all bits" + << EndLn; + return false; + } + } + + // Set a bit beyond the current size + setTest2.set(32); + + // Make sure it expanded + if (setTest2.size() != 64) + { + outStrm << " Set of bit beyond size did not expand" + << EndLn; + return false; + } + + // Set all the bits + for (index = 0; index < count; index++) + setTest.set(index); + + // Make sure that allAreSet() sees them all set + if (!setTest.allAreSet()) + { + outStrm << " After setting all bits, allAreSet() returned false" + << EndLn; + return false; + } + + return true; +} + +static bool bitopsTests() +{ + // Create a bit set to test + BitSet setTest(48); + + // Set some bits + setTest.set(1); + setTest.set(10); + setTest.set(16); + setTest.set(21); + setTest.set(33); + setTest.set(41); + + // Create another set to do ops on + BitSet setTest2(48); + + // Or with the new set + setTest2.orWith(setTest); + + // They should be equal now + if (!setTest.equals(setTest2)) + { + outStrm << " OR of set with empty set did not create equal sets" + << EndLn; + return false; + } + + // Xor with original which should get back an empty set + setTest2.xorWith(setTest); + if (!setTest2.allAreCleared()) + { + outStrm << " XOR against original set did not get back original" + << EndLn; + return false; + } + + // And them, which should have no effect + setTest2.andWith(setTest); + if (!setTest2.allAreCleared()) + { + outStrm << " AND against empty set changed bits" << EndLn; + return false; + } + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testBitSet() +{ + outStrm << "----------------------------------\n" + << "Testing BitSet class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + outStrm << "Testing basic BitSet methods" << EndLn; + if (!basicTests()) + { + outStrm << "Bitset basic test methods failed" << EndLn; + retVal = false; + } + else + { + outStrm << "Bitset basic tests passed" << EndLn; + } + outStrm << EndLn; + + outStrm << "Testing BitSet logical bit ops methods" << EndLn; + if (!bitopsTests()) + { + outStrm << "Bitset logical bit ops failed" << EndLn; + retVal = false; + } + else + { + outStrm << "Bitset logical bit ops passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_CountedPointer.cpp b/tests/UtilTests/CoreTests_CountedPointer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3f7b8600118cba0bc983fff2ee29d29d90873f9 --- /dev/null +++ b/tests/UtilTests/CoreTests_CountedPointer.cpp @@ -0,0 +1,140 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:50 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:26 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// XML4C2 Includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/CountedPointer.hpp> + + +// --------------------------------------------------------------------------- +// A local class used for testing +// --------------------------------------------------------------------------- +class TestClass +{ +public : + static unsigned int gCounter; + + TestClass() + { + gCounter++; + } + + ~TestClass() + { + gCounter--; + } + + void addRef() + { + refCount++; + } + + void removeRef() + { + refCount--; + if (refCount == 0) + delete this; + } + +private : + unsigned int refCount; +}; + +unsigned int TestClass::gCounter = 0; + + +// --------------------------------------------------------------------------- +// Force a full instantiation to test syntax +// --------------------------------------------------------------------------- +template class CountedPointerTo<TestClass>; + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testCountedPointer() +{ + outStrm << "----------------------------------\n" + << "Testing CountedPointerTo class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_RefArray.cpp b/tests/UtilTests/CoreTests_RefArray.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9eaf8aa70f99f35a68993779ed432fb60d52dbed --- /dev/null +++ b/tests/UtilTests/CoreTests_RefArray.cpp @@ -0,0 +1,259 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:52 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:27 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/RefArrayOf.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> + + + +// --------------------------------------------------------------------------- +// Force a full instantiation of our array and its enumerator, just to +// insure that all methods get instantiated and compiled. +// --------------------------------------------------------------------------- +template RefArrayOf<int>; +template RefArrayEnumerator<int>; + + +// --------------------------------------------------------------------------- +// Local functions +// --------------------------------------------------------------------------- +static bool constructorTests() +{ + // Some values to test with + double testVals[16]; + unsigned int index; + for (index = 0; index < 16; index++) + testVals[index] = index; + + // Do a basic constructor with just the count of elements + RefArrayOf<double> testArray1(255); + + // Make sure that it has the right initial size + if (testArray1.length() != 255) + { + outStrm << " The ctor created wrong length() value" << EndLn; + return false; + } + + // Copy construct another array from it and test the length + RefArrayOf<double> testArray2(testArray1); + + if (testArray2.length() != 255) + { + outStrm << " The copy ctor created wrong length() value" + << EndLn; + return false; + } + + // Test the equality of the two arrays + if (testArray1 != testArray2) + { + outStrm << " The copy ctor created unequal arrays" + << EndLn; + return false; + } + + // + // Do another one where we provide the initial values. + // + double* initValues[16]; + for (index = 0; index < 16; index++) + initValues[index ] = &testVals[index]; + RefArrayOf<double> testArray3(initValues, 16); + + if (testArray3.length() != 16) + { + outStrm << " The init values ctor created wrong length() value" + << EndLn; + return false; + } + + // Make sure the initial values are correct + for (index = 0; index < 16; index++) + { + if (*testArray3[index] != (double)index) + { + outStrm << " The init values ctor did not init contents correctly" + << EndLn; + return false; + } + } + + // + // Create another array of a different size and assign one of the + // existing ones to it and make sure that they are equal. + // + RefArrayOf<double> testArray4(15); + testArray4 = testArray3; + + if (testArray4 != testArray3) + { + outStrm << " Assignment did not create equal arrays" << EndLn; + return false; + } + + return true; +} + + +static bool accessTests() +{ + // Some values to test with + unsigned int testVals[16]; + unsigned int index; + for (index = 0; index < 16; index++) + testVals[index] = index; + + RefArrayOf<unsigned int> testArray1(16); + + // Fill in the array + for (index = 0; index < 16; index++) + testArray1[index] = &testVals[index]; + + // Read them back again + for (index = 0; index < 16; index++) + { + if (testArray1[index] != &testVals[index]) + { + outStrm << " Failed to read back values just set" + << EndLn; + return false; + } + } + + // Make sure we get the expected array index error + bool caughtIt = false; + try + { + testArray1[16]; + } + + catch(const ArrayIndexOutOfBoundsException&) + { + caughtIt = true; + } + + if (!caughtIt) + { + outStrm << " Failed to catch index error" << EndLn; + return false; + } + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testRefArray() +{ + outStrm << "----------------------------------\n" + << "Testing RefArrayOf template class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + // Call other local methods to do specific tests + outStrm << "Testing RefArrayOf contructors" << EndLn; + if (!constructorTests()) + { + outStrm << "RefArrayOf constructor tests failed" << EndLn; + retVal = false; + } + else + { + outStrm << "RefArrayOf constructor tests passed" << EndLn; + } + outStrm << EndLn; + + outStrm << "Testing RefArrayOf element access" << EndLn; + if (!accessTests()) + { + outStrm << "RefArrayOf element access tests failed" << EndLn; + retVal = false; + } + else + { + outStrm << "RefArrayOf element access tests passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_RefHashTable.cpp b/tests/UtilTests/CoreTests_RefHashTable.cpp new file mode 100644 index 0000000000000000000000000000000000000000..51bd63a230c8d1b175ef431cadeee8d1aeaab5de --- /dev/null +++ b/tests/UtilTests/CoreTests_RefHashTable.cpp @@ -0,0 +1,159 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:54 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:27 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/RefHashTableOf.hpp> + + +// --------------------------------------------------------------------------- +// A simple class to test the ref hash table with +// --------------------------------------------------------------------------- +class TestElem +{ + public : + TestElem( const XMLCh* const key + , const unsigned int value1 + , const double value2) : + fKey(XMLString::replicate(key)) + , fValue1(value1) + , fValue2(value2) + { + } + + ~TestElem() + { + delete [] fKey; + } + + const XMLCh* getKey() const + { + return fKey; + } + + + private : + XMLCh* fKey; + unsigned int fValue1; + double fValue2; +}; + + +// --------------------------------------------------------------------------- +// Force a full instantiation of our hashtable, and its enumerator, just to +// insure that all methods get instantiated and compiled. +// --------------------------------------------------------------------------- +template RefHashTableOf<TestElem>; +template RefHashTableOfEnumerator<TestElem>; + + + +// --------------------------------------------------------------------------- +// Local testing methods +// --------------------------------------------------------------------------- +static bool basicTests() +{ + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testRefHashTable() +{ + outStrm << "----------------------------------\n" + << "Testing RefHashTableOf class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + outStrm << "Testing basic RefHashtable methods" << EndLn; + if (!basicTests()) + { + outStrm << "RefHashtable basic test methods failed" << EndLn; + retVal = false; + } + else + { + outStrm << "RefHashtable basic tests passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_RefStack.cpp b/tests/UtilTests/CoreTests_RefStack.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9872c55ac1213ba6d73888d88a1e1397b01e1a51 --- /dev/null +++ b/tests/UtilTests/CoreTests_RefStack.cpp @@ -0,0 +1,129 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:57 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:27 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/RefStackOf.hpp> + + +// --------------------------------------------------------------------------- +// Force a full instantiation of our stack and its enumerator, just to +// insure that all methods get instantiated and compiled. +// --------------------------------------------------------------------------- +template RefStackOf<int>; +template RefStackEnumerator<int>; + + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +static bool basicTests() +{ + RefStackOf<double> testStack(500); + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testRefStack() +{ + outStrm << "----------------------------------\n" + << "Testing RefStackOf template class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + // Call other local methods to do specific tests + outStrm << "Testing RefStackOf basics" << EndLn; + if (!basicTests()) + { + outStrm << "RefStackOf basic tests failed" << EndLn; + retVal = false; + } + else + { + outStrm << "RefArrayOf constructor tests passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + + return retVal; +} diff --git a/tests/UtilTests/CoreTests_RefVector.cpp b/tests/UtilTests/CoreTests_RefVector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aab76d08d583fe5c4ba63ff6697210074124fd88 --- /dev/null +++ b/tests/UtilTests/CoreTests_RefVector.cpp @@ -0,0 +1,407 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:59 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:27 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 Includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/RefVectorOf.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> + + + +// --------------------------------------------------------------------------- +// Force a full instantiation of the vector and its enumerator just to insure +// that all methods get instantiated and compiled. +// --------------------------------------------------------------------------- +template RefVectorOf<int>; +template RefVectorEnumerator<int>; + + + +// --------------------------------------------------------------------------- +// Templatized testing code. These allow the exact same tests to be run +// for any number of instantiation types over the by value vectors. +// --------------------------------------------------------------------------- +template <class T> bool commonRefTests() +{ + const unsigned int testMax = 3; + bool caughtIt; + + // + // Create a vector of testMax of the instantiation type. Tell it that + // we adopt elements. + // + RefVectorOf<T> testVec(testMax, true); + + // Make sure the initial capacity is what we set + if (testVec.curCapacity() != testMax) + { + outStrm << " Init capacity was incorrect" << EndLn; + return false; + } + + // Make sure the initial size is zero + if (testVec.size() != 0) + { + outStrm << " Init size was not correct" << EndLn; + return false; + } + + // Add a value and check the count is 1 + testVec.addElement(new T); + if (testVec.size() != 1) + { + outStrm << " Adding one element caused bad size" << EndLn; + return false; + } + + // Add another value and check the count is 2 + testVec.addElement(new T); + if (testVec.size() != 2) + { + outStrm << " Adding another element caused bad size" << EndLn; + return false; + } + + // Add two more, which should cause an expansion of the vector + testVec.addElement(new T); + testVec.addElement(new T); + + if (testVec.curCapacity() == testMax) + { + outStrm << " Adding another element failed to cause an expansion" + << EndLn; + return false; + } + + // Check that we get an array bounds exception after an expansion + caughtIt = false; + try + { + testVec.elementAt(4); + } + + catch(const ArrayIndexOutOfBoundsException&) + { + caughtIt = true; + } + + if (!caughtIt) + { + outStrm << " Failed to catch array bounds error at element 4" + << EndLn; + return false; + } + + // Remove an item and see if the count went down by one + testVec.removeElementAt(0); + + if (testVec.size() != 3) + { + outStrm << " Removing an element did not adjust size correctly" + << EndLn; + return false; + } + + // Remove the rest of them and make sure we hit zero + testVec.removeElementAt(0); + testVec.removeElementAt(0); + testVec.removeElementAt(0); + + if (testVec.size() != 0) + { + outStrm << " Removing all elements did not zero the size" + << EndLn; + return false; + } + + // Check that we get an array bounds exception now still + caughtIt = false; + try + { + testVec.elementAt(0); + } + + catch(const ArrayIndexOutOfBoundsException&) + { + caughtIt = true; + } + + if (!caughtIt) + { + outStrm << " Failed to catch array bounds error at element 0" + << EndLn; + return false; + } + + // Add a few more elements back in, via insertion + testVec.insertElementAt(new T, 0); + testVec.insertElementAt(new T, 0); + testVec.insertElementAt(new T, 0); + if (testVec.size() != 3) + { + outStrm << " Inserting elements caused bad size" << EndLn; + return false; + } + + // Now do a remove all elements + testVec.removeAllElements(); + + if (testVec.size() != 0) + { + outStrm << " removeAllElements caused bad size" << EndLn; + return false; + } + + return true; +} + + +template <class T> bool extendedRefTests() +{ + const unsigned int testMax = 8; + + // Create a test vector and put in ascending test values + RefVectorOf<T> testVec(testMax, true); + testVec.addElement(new T(0)); + testVec.addElement(new T(1)); + testVec.addElement(new T(2)); + testVec.addElement(new T(3)); + testVec.addElement(new T(4)); + testVec.addElement(new T(5)); + testVec.addElement(new T(6)); + testVec.addElement(new T(7)); + + // Now check that they went in that way + unsigned int index; + for (index = 0; index < testMax; index++) + { + if (*testVec.elementAt(index) != T(index)) + { + outStrm << " addElement put elements in wrong order" + << EndLn; + return false; + } + } + + // Remove the zero'th element and test again + testVec.removeElementAt(0); + + for (index = 0; index < testMax-1; index++) + { + if (*testVec.elementAt(index) != T(index+1)) + { + outStrm << " removeElement at head removed wrong element" + << EndLn; + return false; + } + } + + // Test edge case by removing last element and test again + testVec.removeElementAt(6); + + for (index = 0; index < testMax-2; index++) + { + if (*testVec.elementAt(index) != T(index+1)) + { + outStrm << " removeElement at end removed wrong element" + << EndLn; + return false; + } + } + return true; +} + + + +// --------------------------------------------------------------------------- +// Local functions +// --------------------------------------------------------------------------- +static bool doBasicTests() +{ + bool retVal = true; + + // + // Do the common reference vector tests for ints, bools and strings. + // + outStrm << "Testing RefVectorOf<int>, common tests" << EndLn; + if (!commonRefTests<int>()) + { + outStrm << "RefVectorOf<int> failed" << EndLn; + retVal = false; + } + else + { + outStrm << "RefVectorOf<int> passed" << EndLn; + } + outStrm << EndLn; + + outStrm << "Testing RefVectorOf<bool>, common tests" << EndLn; + if (!commonRefTests<bool>()) + { + outStrm << "RefVectorOf<bool> failed" << EndLn; + retVal = false; + } + else + { + outStrm << "RefVectorOf<bool> passed" << EndLn; + } + outStrm << EndLn; + + + // + // And now do the second round of extended tests. These require that + // the instantiation type be of a fundamental value, because its going + // to test element ordering issues. + // + outStrm << "Testing RefVectorOf<int>, extended tests" << EndLn; + if (!extendedRefTests<int>()) + { + outStrm << "Extended RefVectorOf<int> failed" << EndLn; + retVal = false; + } + else + { + outStrm << "Extended RefVectorOf<int> passed" << EndLn; + } + outStrm << EndLn; + + return retVal; +} + + +static bool enumTests() +{ + // Create a vector and fill it in with some known values + RefVectorOf<unsigned int> testVec(32, true); + + unsigned int index; + for (index = 0; index < 32; index++) + testVec.addElement(new unsigned int(index)); + + // Create an enumeration for it + RefVectorEnumerator<unsigned int> enumTest(&testVec); + index = 0; + while (enumTest.hasMoreElements()) + { + if (enumTest.nextElement() != index++) + { + outStrm << " Enumerator sequence was incorrect" << EndLn; + return false; + } + } + + if (index != 32) + { + outStrm << " Enumerator did not enum enough elements" + << EndLn; + return false; + } + return true; +} + + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testRefVector() +{ + outStrm << "----------------------------------\n" + << "Testing RefVectorOf template class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + // Do the basic suite of tests + if (!doBasicTests()) + retVal = false; + + // Test the enumerator + outStrm << "Testing RefVectorEnumerator" << EndLn; + if (!enumTests()) + { + outStrm << "RefVectorEnumeration failed" << EndLn; + retVal = false; + } + else + { + outStrm << "RefVectorEnumeration passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_String.cpp b/tests/UtilTests/CoreTests_String.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42c995565e9665ffdfeb99e7d1ba5964d14217b9 --- /dev/null +++ b/tests/UtilTests/CoreTests_String.cpp @@ -0,0 +1,105 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:01 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/ArrayIndexOutOfBoundsException.hpp> +#include <util/ValueArrayOf.hpp> +#include <string.h> + + +// --------------------------------------------------------------------------- +// Local test functions +// --------------------------------------------------------------------------- + + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testString() +{ + outStrm << "----------------------------------\n" + << "Testing String class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_Transcoders.cpp b/tests/UtilTests/CoreTests_Transcoders.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27b76e303089df6860f6ab2e51d4e959bbede8e4 --- /dev/null +++ b/tests/UtilTests/CoreTests_Transcoders.cpp @@ -0,0 +1,172 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:03 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/PlatformUtils.hpp> +#include <util/TransService.hpp> + + +// --------------------------------------------------------------------------- +// Local test methods +// --------------------------------------------------------------------------- +static bool basicTests() +{ + const char* const testStr1 = "The test string"; + const XMLCh testStr2[] = + { + chLatin_T, chLatin_h, chLatin_e, chSpace, chLatin_t, chLatin_e + , chLatin_s, chLatin_t, chSpace, chLatin_s, chLatin_t, chLatin_r + , chLatin_i, chLatin_n, chLatin_g, chNull + }; + + // + // Ok, lets test out the very basic semantics of transcoders. This + // will test the particular transcoder system installed. First of all + // lets get a default transcoder. + // + XMLTranscoder* testX = XMLPlatformUtils::fgTransService->makeNewDefTranscoder(); + + // Ask it to do a basic transcoding of a string round trip + { + // Do the first pass and compare against the expected result + XMLCh* firstPass = testX->transcode(testStr1); + if (XMLString::compareString(firstPass, testStr2)) + { + outStrm << "Xcode from native to Unicode failed" + << EndLn; + return false; + } + + // Now transcode that back to native again + char* secondPass = testX->transcode(firstPass); + if (XMLString::compareString(secondPass, testStr1)) + { + outStrm << "Xcode from Unicode to native failed" + << EndLn; + return false; + } + } + + // Check the methods that calculate required storage + { + if (testX->calcRequiredSize(testStr1) != XMLString::stringLen(testStr1)) + { + outStrm << "Calculated size to xcode char string was wrong" + << EndLn; + return false; + } + + if (testX->calcRequiredSize(testStr2) != XMLString::stringLen(testStr2)) + { + outStrm << "Calculated size to xcode Unicode string was wrong" + << EndLn; + return false; + } + } + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testTranscoders() +{ + outStrm << "----------------------------------\n" + << "Testing transcoder classes\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + // Call other local methods to do specific tests + outStrm << "Testing basic transcoder semantics" << EndLn; + if (!basicTests()) + { + outStrm << "Transcoder basic tests failed" << EndLn; + retVal = false; + } + else + { + outStrm << "Transcoder basic tests passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_URL.cpp b/tests/UtilTests/CoreTests_URL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff39c062549a398012aeff43b1094a419170bdb4 --- /dev/null +++ b/tests/UtilTests/CoreTests_URL.cpp @@ -0,0 +1,307 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:05 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 includes +// --------------------------------------------------------------------------- +#include <util/RuntimeException.hpp> +#include <util/URL.hpp> +#include "CoreTests.hpp" + + +// --------------------------------------------------------------------------- +// Local test methods +// --------------------------------------------------------------------------- +static bool parseTests() +{ + URL testURL; + + // + // First lets set some invalid URL's and make sure that we get the + // expected malformed URL exceptions. Use an outer generic catch to + // handle anything unexpected and report it. + // + try + { + static const char* badURLS[] = + { + "myfile.txt" + , "bubba:///myfile.txt" + , "file://myfile.txt" + , 0 + }; + + unsigned int index = 0; + while (badURLS[index]) + { + bool gotIt = false; + try + { + testURL.setURL(badURLS[index]); + } + + catch(const MalformedURLException&) + { + gotIt = true; + } + + if (!gotIt) + { + outStrm << "Failed to get bad URL exception for: " + << badURLS[index] << EndLn; + } + index++; + } + } + + catch(const XMLException& toCatch) + { + outStrm << "Got an unexpected exception.\n Type:" + << toCatch.getType() << ", Message:" << toCatch.getMessage() + << EndLn; + } + + catch(...) + { + outStrm << "Got an unexpected system exception." << EndLn; + } + + + // + // Next lets test that we get runtime exceptions for unsupported + // protocols. + // + try + { + static const char* unsupportedURLS[] = + { + "http:///xyz" + , "gopher:///myfile.txt" + , "wais:///myfile.txt" + , "ftp://host/filename.txt" + , "mailto://goober.74/snobby" + , 0 + }; + + unsigned int index = 0; + while (unsupportedURLS[index]) + { + bool gotIt = false; + try + { + testURL.setURL(unsupportedURLS[index]); + } + + catch(const RuntimeException&) + { + gotIt = true; + } + + if (!gotIt) + { + outStrm << "Failed to get runtime exception for: " + << unsupportedURLS[index] << EndLn; + } + index++; + } + } + + catch(const XMLException& toCatch) + { + outStrm << "Got an unexpected exception.\n Type:" + << toCatch.getType() << ", Message:" << toCatch.getMessage() + << EndLn; + } + + catch(...) + { + outStrm << "Got an unexpected system exception." << EndLn; + } + + + return true; +} + + +static bool basicTests() +{ + // + // Set up a list of URLs and what we expect to get out of them for + // the various components. + // + struct TestInfo + { + const char* urlText; + const char* hostComp; + const char* pathComp; + const char* protocol; + }; + + static const TestInfo testList[] = + { + { "file:///A:\\abc.txt" , "" , "A:\\abc.txt" , "file://" } + , { "file://localhost/A:\\abc.txt", "localhost" , "A:\\abc.txt" , "file://" } + , { "file:///abc.txt" , "" , "/abc.txt" , "file://" } + , { "file:///A:\\a%20c.txt" , "" , "A:\\a c.txt" , "file://" } + , { 0, 0, 0, 0 } + }; + + bool result = true; + unsigned int index = 0; + while (true) + { + // Break out at the end + if (!testList[index].urlText) + break; + + // Parse the next URL in the list + URL testURL; + testURL.setURL(testList[index].urlText); + + // + // And test the various components. We have to transcode them in order + // to do the the comparison. + // + XMLCh* tmpStr = XMLString::transcode(testList[index].hostComp); + if (XMLString::compareString(testURL.getHost(), tmpStr)) + { + outStrm << "Host incorrect on URL: " << testList[index].urlText << EndLn; + result = false; + } + delete [] tmpStr; + + tmpStr = XMLString::transcode(testList[index].protocol); + if (XMLString::compareString(testURL.getProtocol(), tmpStr)) + { + outStrm << "Protocol incorrect on URL: " << testList[index].urlText << EndLn; + result = false; + } + delete [] tmpStr; + + tmpStr = XMLString::transcode(testList[index].pathComp); + if (XMLString::compareString(testURL.getPath(), tmpStr)) + { + outStrm << "Path incorrect on URL: " << testList[index].urlText << EndLn; + result = false; + } + delete [] tmpStr; + + // Move up to the next test + index++; + } + return result; +} + + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testURL() +{ + outStrm << "----------------------------------\n" + << "Testing URL class \n" + << "----------------------------------" + << EndLn; + + bool retVal = true; + try + { + // Test the URL parsing code + outStrm << "Testing URL Parsing" << EndLn; + if (!parseTests()) + { + outStrm << "URL parsing tests failed\n"; + retVal = false; + } + else + { + outStrm << "URL parsing tests passed\n"; + } + outStrm << EndLn; + + // Now test basic functionality + outStrm << "Testing URL Basics" << EndLn; + if (!basicTests()) + { + outStrm << "URL basic tests failed\n"; + retVal = false; + } + else + { + outStrm << "URL basic tests passed\n"; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_ValueArray.cpp b/tests/UtilTests/CoreTests_ValueArray.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e40dd489276d2d63e658097fc8213c944edc5bab --- /dev/null +++ b/tests/UtilTests/CoreTests_ValueArray.cpp @@ -0,0 +1,247 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:07 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:28 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/ValueArrayOf.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> + + +// --------------------------------------------------------------------------- +// Force a full instantiation of our array and its enumerator, just to +// insure that all methods get instantiated and compiled. +// --------------------------------------------------------------------------- +template ValueArrayOf<int>; +template ValueArrayEnumerator<int>; + + + +// --------------------------------------------------------------------------- +// Local functions +// --------------------------------------------------------------------------- +static bool constructorTests() +{ + // Do a basic constructor with just the count of elements + ValueArrayOf<double> testArray1(255); + + // Make sure that it has the right initial size + if (testArray1.length() != 255) + { + outStrm << " The ctor created wrong length() value" << EndLn; + return false; + } + + // Copy construct another array from it and test the length + ValueArrayOf<double> testArray2(testArray1); + + if (testArray2.length() != 255) + { + outStrm << " The copy ctor created wrong length() value" + << EndLn; + return false; + } + + // Test the equality of the two arrays + if (testArray1 != testArray2) + { + outStrm << " The copy ctor created unequal arrays" << EndLn; + return false; + } + + // + // Do another one where we provide the initial values. + // + double initValues[] = { 1.1, 2.2, 3.3, 4.4 }; + ValueArrayOf<double> testArray3(initValues, 4); + + if (testArray3.length() != 4) + { + outStrm << " The init values ctor created wrong length() value" + << EndLn; + return false; + } + + // Make sure the initial values are correct + if ((testArray3[0] != 1.1) + || (testArray3[1] != 2.2) + || (testArray3[2] != 3.3) + || (testArray3[3] != 4.4)) + { + outStrm << " The init values ctor did not init contents correctly" + << EndLn; + return false; + } + + // + // Create another array of a different size and assign one of the + // existing ones to it and make sure that they are equal. + // + ValueArrayOf<double> testArray4(15); + testArray4 = testArray3; + + if (testArray4 != testArray3) + { + outStrm << " Assignment did not create equal arrays" + << EndLn; + return false; + } + return true; +} + + +static bool accessTests() +{ + ValueArrayOf<unsigned int> testArray1(16); + + // Fill in the array + unsigned int index; + for (index = 0; index < 16; index++) + testArray1[index] = index; + + // Read them back again + for (index = 0; index < 16; index++) + { + if (testArray1[index] != index) + { + outStrm << " Failed to read back values just set" + << EndLn; + return false; + } + } + + // Make sure we get the expected array index error + bool caughtIt = false; + try + { + index = testArray1[16]; + } + + catch(const ArrayIndexOutOfBoundsException&) + { + caughtIt = true; + } + + if (!caughtIt) + { + outStrm << " Failed to catch index error" << EndLn; + return false; + } + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testValueArray() +{ + outStrm << "----------------------------------\n" + << "Testing ValueArrayOf template class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + // Call other local methods to do specific tests + outStrm << "Testing ValueArrayOf contructors" << EndLn; + if (!constructorTests()) + { + outStrm << "ValueArrayOf constructor tests failed" << EndLn; + retVal = false; + } + else + { + outStrm << "ValueArrayOf constructor tests passed" << EndLn; + } + outStrm << EndLn; + + outStrm << "Testing ValueArrayOf element access" << EndLn; + if (!accessTests()) + { + outStrm << "ValueArrayOf element access tests failed" + << EndLn; + retVal = false; + } + else + { + outStrm << "ValueArrayOf element access tests passed" + << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_ValueStack.cpp b/tests/UtilTests/CoreTests_ValueStack.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf721be17f5fd9cab1e0168961bd7277ca714d5d --- /dev/null +++ b/tests/UtilTests/CoreTests_ValueStack.cpp @@ -0,0 +1,128 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:09 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:29 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/ValueStackOf.hpp> + + +// --------------------------------------------------------------------------- +// Force a full instantiation of our stack and its enumerator, just to +// insure that all methods get instantiated and compiled. +// --------------------------------------------------------------------------- +template ValueStackOf<int>; +template ValueStackEnumerator<int>; + + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +static bool basicTests() +{ + ValueStackOf<double> testStack(500); + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testValueStack() +{ + outStrm << "----------------------------------\n" + << "Testing ValueStackOf template class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + // Call other local methods to do specific tests + outStrm << "Testing ValueStackOf basics" << EndLn; + if (!basicTests()) + { + outStrm << "ValueStackOf basic tests failed" << EndLn; + retVal = false; + } + else + { + outStrm << "ValueArrayOf constructor tests passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + return retVal; +} diff --git a/tests/UtilTests/CoreTests_ValueVector.cpp b/tests/UtilTests/CoreTests_ValueVector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1041b99fd79ee356cb810228fa6a3b220852655e --- /dev/null +++ b/tests/UtilTests/CoreTests_ValueVector.cpp @@ -0,0 +1,411 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:02:10 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:29 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +// --------------------------------------------------------------------------- +// XML4C2 includes +// --------------------------------------------------------------------------- +#include "CoreTests.hpp" +#include <util/ValueVectorOf.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> + + +// --------------------------------------------------------------------------- +// Force a full instantiation of our vector and its enumerator, just to +// insure that all methods get instantiated and compiled. +// --------------------------------------------------------------------------- +template ValueVectorOf<int>; +template ValueVectorEnumerator<int>; + + +// --------------------------------------------------------------------------- +// Templatized testing code. These allow the exact same tests to be run +// for any number of instantiation types over the by value vectors. +// --------------------------------------------------------------------------- +template <class T> bool commonValueTests() +{ + const unsigned int testMax = 3; + bool caughtIt; + + // Create a vector of testMax of the instantiation type + ValueVectorOf<T> testVec(testMax); + + // Make sure the initial capacity is what we set + if (testVec.curCapacity() != testMax) + { + outStrm << " Init capacity was bad" << EndLn; + return false; + } + + // Make sure the initial size is zero + if (testVec.size() != 0) + { + outStrm << " Init size was bad" << EndLn; + return false; + } + + // Test value for adding + T testElem; + + // Add a value and check the count is 1 + testVec.addElement(testElem); + if (testVec.size() != 1) + { + outStrm << " Adding one element caused bad size" << EndLn; + return false; + } + + // Add another value and check the count is 2 + testVec.addElement(testElem); + if (testVec.size() != 2) + { + outStrm << " Adding another element caused bad size" << EndLn; + return false; + } + + // Test that the two of them are the same + if (testVec.elementAt(0) != testVec.elementAt(1)) + { + outStrm << " First two elements did not match" << EndLn; + return false; + } + + // Add two more, which should cause an expansion of the vector + testVec.addElement(testElem); + testVec.addElement(testElem); + + if (testVec.curCapacity() == testMax) + { + outStrm << " Adding another element failed to cause an expansion" + << EndLn; + return false; + } + + // Check that we get an array bounds exception after an expansion + caughtIt = false; + try + { + testVec.elementAt(4); + } + + catch(const ArrayIndexOutOfBoundsException&) + { + caughtIt = true; + } + + if (!caughtIt) + { + outStrm << " Failed to catch array bounds error at element 4" + << EndLn; + return false; + } + + // Remove an item and see if the count went down by one + testVec.removeElementAt(0); + + if (testVec.size() != 3) + { + outStrm << " Removing an element did not adjust size correctly" + << EndLn; + return false; + } + + // Remove the rest of them and make sure we hit zero + testVec.removeElementAt(0); + testVec.removeElementAt(0); + testVec.removeElementAt(0); + + if (testVec.size() != 0) + { + outStrm << " Removing all elements did not zero the size" + << EndLn; + return false; + } + + // Check that we get an array bounds exception now still + caughtIt = false; + try + { + testVec.elementAt(0); + } + + catch(const ArrayIndexOutOfBoundsException&) + { + caughtIt = true; + } + + if (!caughtIt) + { + outStrm << " Failed to catch array bounds error at element 0" + << EndLn; + return false; + } + + // Add a few more elements back in, via insertion + testVec.insertElementAt(testElem, 0); + testVec.insertElementAt(testElem, 0); + testVec.insertElementAt(testElem, 0); + if (testVec.size() != 3) + { + outStrm << " Inserting elements caused bad size" << EndLn; + return false; + } + + // Now do a remove all elements + testVec.removeAllElements(); + + if (testVec.size() != 0) + { + outStrm << " removeAllElements caused bad size" << EndLn; + return false; + } + return true; +} + + +template <class T> bool extendedValueTests() +{ + const unsigned int testMax = 8; + + // Create a test vector and put in ascending test values + ValueVectorOf<T> testVec(testMax); + testVec.addElement(T(0)); + testVec.addElement(T(1)); + testVec.addElement(T(2)); + testVec.addElement(T(3)); + testVec.addElement(T(4)); + testVec.addElement(T(5)); + testVec.addElement(T(6)); + testVec.addElement(T(7)); + + // Now check that they went in that way + unsigned int index; + for (index = 0; index < testMax; index++) + { + if (testVec.elementAt(index) != T(index)) + { + outStrm << " addElement put elements in wrong order" + << EndLn; + return false; + } + } + + // Remove the zero'th element and test again + testVec.removeElementAt(0); + + for (index = 0; index < testMax-1; index++) + { + if (testVec.elementAt(index) != T(index+1)) + { + outStrm << " removeElement at head removed wrong element" + << EndLn; + return false; + } + } + + // Test edge case by removing last element and test again + testVec.removeElementAt(6); + + for (index = 0; index < testMax-2; index++) + { + if (testVec.elementAt(index) != T(index+1)) + { + outStrm << " removeElement at end removed wrong element" + << EndLn; + return false; + } + } + return true; +} + + +// --------------------------------------------------------------------------- +// Local functions +// --------------------------------------------------------------------------- +static bool doBasicTests() +{ + bool retVal = true; + + // + // Do the common value vector tests for ints, bools and strings. + // + outStrm << "Testing ValueVectorOf<int>, common tests" << EndLn; + if (!commonValueTests<int>()) + { + outStrm << "ValueVectorOf<int> failed" << EndLn; + retVal = false; + } + else + { + outStrm << "ValueVectorOf<int> passed" << EndLn; + } + outStrm << EndLn; + + outStrm << "Testing ValueVectorOf<bool>, common tests" << EndLn; + if (!commonValueTests<bool>()) + { + outStrm << "ValueVectorOf<bool> failed" << EndLn; + retVal = false; + } + else + { + outStrm << "ValueVectorOf<bool> passed" << EndLn; + } + outStrm << EndLn; + + + // + // And now do the second round of extended tests. These require that + // the instantiation type be of a fundamental value, because its going + // to test element ordering issues. + // + outStrm << "Testing ValueVectorOf<int>, extended tests" << EndLn; + if (!extendedValueTests<int>()) + { + outStrm << "Extended ValueVectorOf<int> failed" << EndLn; + retVal = false; + } + else + { + outStrm << "Extended ValueVectorOf<int> passed" << EndLn; + } + outStrm << EndLn; + + return retVal; +} + + +static bool enumTests() +{ + // Create a vector and fill it in with some known values + ValueVectorOf<unsigned int> testVec(32); + + unsigned int index; + for (index = 0; index < 32; index++) + testVec.addElement(index); + + // Create an enumeration for it + ValueVectorEnumerator<unsigned int> enumTest(&testVec); + index = 0; + while (enumTest.hasMoreElements()) + { + if (enumTest.nextElement() != index++) + { + outStrm << " Enumerator sequence was incorrect" << EndLn; + return false; + } + } + + if (index != 32) + { + outStrm << " Enumerator did not enum enough elements" + << EndLn; + return false; + } + + return true; +} + + +// --------------------------------------------------------------------------- +// Test entry point +// --------------------------------------------------------------------------- +bool testValueVector() +{ + outStrm << "----------------------------------\n" + << "Testing ValueVectorOf tempalte class\n" + << "----------------------------------" << EndLn; + + bool retVal = true; + + try + { + // Do the basic suite of tests, which is templatized + if (!doBasicTests()) + retVal = false; + + // Test the enumerator + outStrm << "Testing ValueVectorEnumerator" << EndLn; + if (!enumTests()) + { + outStrm << "ValueVectorEnumeration failed" << EndLn; + retVal = false; + } + else + { + outStrm << "ValueVectorEnumeration passed" << EndLn; + } + outStrm << EndLn; + } + + catch(const XMLException& toCatch) + { + outStrm << " ERROR: Unexpected exception!\n Msg: " + << toCatch.getMessage() << EndLn; + return false; + } + + return retVal; +} diff --git a/tools/NLS/Xlat/Xlat.cpp b/tools/NLS/Xlat/Xlat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2919a8bc5824b93639279ff6b6be87061ef96a36 --- /dev/null +++ b/tools/NLS/Xlat/Xlat.cpp @@ -0,0 +1,726 @@ +/* + * 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/>. + */ + + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:12 twl + * Initial revision + * + * Revision 1.5 1999/11/08 20:42:04 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// This program is designed to parse an XML file which holds error text +// data. It will build a DOM tree from that source file and can output it +// a number of different formats. +// +// In order to drastically simplify the program, it is designed only to run +// on platforms/compilers that understand Unicode. It can output the data +// in whatever format is required, so it can handle outputting for other +// platforms. This also simplifies bootstrapping new releases up on other +// platforms. Once the Win32 version is working, it can generate output for +// the other platforms so that they can have loadable text from day one. +// --------------------------------------------------------------------------- + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "Xlat.hpp" + + + +// --------------------------------------------------------------------------- +// Static data +// +// gRelativeInputPath +// This is the path, relative to the given input source root, to the +// input file. The given local suffix must also be added to it. +// --------------------------------------------------------------------------- +static XMLCh* const gRelativeInputPath = L"src/NLS/"; + + +// --------------------------------------------------------------------------- +// Global data +// --------------------------------------------------------------------------- +const XMLCh* typePrefixes[MsgTypes_Count] = +{ + L"W_" + , L"E_" + , L"V_" +}; + + +// --------------------------------------------------------------------------- +// Local data +// +// gLocale +// This is the locale suffix, e.g. US_EN, that is used to find the +// correct file and can be used on output files as well. Its set via +// the /Locale= parameter. +// +// gOutFormat +// This is the output format, which is given on the command line as +// /OutFmt= Its mapped to the internal enum which is stored here. +// +// gOutPath +// This is the path to the output path, which is given on the command +// line as /OutPath=. Its just the path, not a name, since the output +// might consist of multiple output files. They will all be based on +// the base part of the input name. +// +// gSrcRoot +// This the path to the root of the build tree. The input files needed +// are found in known places relative to it. +// --------------------------------------------------------------------------- +const XMLCh* gLocale = 0; +OutFormats gOutFormat = OutFormat_Unknown; +const XMLCh* gOutPath = 0; +const XMLCh* gSrcRoot = 0; + + +// --------------------------------------------------------------------------- +// Local utility methods +// --------------------------------------------------------------------------- + +// +// This method is called to parse the parameters. They must be in this +// order and format, for simplicity: +// +// /SrcRoot=xxx /OutPath=xxx /OutFmt=xxx /Locale=xxx +// +static bool parseParms(const int argC, XMLCh** argV) +{ + if (argC < 5) + return false; + + unsigned int curParm = 1; + + if (XMLString::startsWith(argV[curParm], L"/SrcRoot=")) + { + gSrcRoot = &argV[curParm][9]; + } + else + { + wprintf(L"\nExpected /SrcRoot=xxx. Got: %s\n", argV[curParm]); + return false; + } + + curParm++; + if (XMLString::startsWith(argV[curParm], L"/OutPath=")) + { + gOutPath = &argV[curParm][9]; + } + else + { + wprintf(L"\nExpected /OutPath=xxx. Got: %s\n", argV[curParm]); + return false; + } + + + curParm++; + if (XMLString::startsWith(argV[curParm], L"/OutFmt=")) + { + const XMLCh* tmpFmt = &argV[curParm][8]; + if (!XMLString::compareIString(tmpFmt, L"ResBundle")) + gOutFormat = OutFormat_ResBundle; + else if (!XMLString::compareIString(tmpFmt, L"Win32RC")) + gOutFormat = OutFormat_Win32RC; + else if (!XMLString::compareIString(tmpFmt, L"CppSrc")) + gOutFormat = OutFormat_CppSrc; + else if (!XMLString::compareIString(tmpFmt, L"MsgCat")) + gOutFormat = OutFormat_MsgCatalog; + else + { + wprintf(L"\n'%s' is not a legal output format\n", tmpFmt); + return false; + } + } + else + { + wprintf(L"\nExpected /OutFmt=xxx. Got: %s\n", argV[curParm]); + return false; + } + + curParm++; + if (XMLString::startsWith(argV[curParm], L"/Locale=")) + { + gLocale = &argV[curParm][8]; + } + else + { + wprintf(L"\nExpected /Locale=xxx. Got: %s\n", argV[curParm]); + return false; + } + + return true; +} + + +static void parseError(const XMLException& toCatch) +{ + wprintf(L"Parse Error:\n ERROR: %s\n\n", toCatch.getMessage()); + throw ErrReturn_ParseErr; +} + + +static void parseError(const SAXParseException& toCatch) +{ + wprintf(L"Parse Error:\n SAX ERROR: %s\n\n", toCatch.getMessage()); + throw ErrReturn_ParseErr; +} + + +static void +enumMessages( const DOM_Element srcElem + , XlatFormatter* const toCall + , FILE* const headerFl + , const MsgTypes msgType + , unsigned int& count) +{ + fwprintf + ( + headerFl + , L" , %s%-30s = %d\n" + , typePrefixes[msgType] + , L"LowBounds" + , count++ + ); + + // + // We just run through each of the child elements, each of which is + // a Message element. Each one represents a message to output. We keep + // a count so that we can output a const value afterwards. + // + DOM_Node curNode = srcElem.getFirstChild(); + while (!curNode.isNull()) + { + // Skip over text nodes or comment nodes ect... + if (curNode.getNodeType() != DOM_Node::ELEMENT_NODE) + { + curNode = curNode.getNextSibling(); + continue; + } + + // Convert it to an element node + const DOM_Element& curElem = (const DOM_Element&)curNode; + + // Ok, this should be a Message node + if (!curElem.getTagName().equals(L"Message")) + { + wprintf(L"Expected a Message node\n\n"); + throw ErrReturn_SrcFmtError; + } + + // + // Ok, lets pull out the id, text value, and message type. These are + // to be passed to the formatter. We have to translate the message + // type into one of the offical enum values. + // + XMLCh* msgText = curElem.getAttribute(L"Text").rawBuffer(); + XMLCh* msgId = curElem.getAttribute(L"Id").rawBuffer(); + + // + // Write out an entry to the target header file. These are enums, so + // we use the id as the enum name. + // + fwprintf(headerFl, L" , %-32s = %d\n", msgId, count); + + // And tell the formatter about this one + toCall->nextMessage + ( + msgText + , msgId + , count + , count + ); + + // Bump the counter, which is also the id assigner + count++; + + // Move to the next child of the source element + curNode = curNode.getNextSibling(); + } + + // Write out an upper range bracketing id for this type of error + fwprintf + ( + headerFl + , L" , %s%-30s = %d\n" + , typePrefixes[msgType] + , L"HighBounds" + , count++ + ); +} + + + +// --------------------------------------------------------------------------- +// Program entry point +// --------------------------------------------------------------------------- + +// +// This is the program entry point. It checks the parms, parses the input +// file to get a DOM tree, then passes the DOM tree to the appropriate +// output method to output the info in a particular format. +// +extern "C" int wmain(int argC, XMLCh** argV) +{ + try + { + XMLPlatformUtils::Initialize(); + } + + catch(const XMLException& toCatch) + { + wprintf(L"Parser init error.\n ERROR: %s\n\n", toCatch.getMessage()); + return ErrReturn_ParserInit; + } + + // + // Lets check the parameters and save them away in globals for use by + // the processing code. + // + if (!parseParms(argC, argV)) + { + wprintf(L"Usage:\n NLSXlat /SrcRoot=xx /OutPath=xx /OutFmt=xx /Locale=xx\n\n"); + return ErrReturn_BadParameters; + } + + DOM_Document srcDoc; + const unsigned int bufSize = 4095; + XMLCh tmpFileBuf[bufSize + 1]; + try + { + try + { + // Build the input file name + swprintf + ( + tmpFileBuf + , L"%s%s%s/XMLErrList_%s.Xml" + , gSrcRoot + , gRelativeInputPath + , gLocale + , gLocale + ); + + // + // Ok, lets invoke the DOM parser on the input file and build + // a DOM tree. Turn on validation when we do this. + // + DOMParser parser; + parser.setDoValidation(true); + XlatErrHandler errHandler; + parser.setErrorHandler(&errHandler); + parser.parse(tmpFileBuf); + srcDoc = parser.getDocument(); + } + + catch(const XMLException& toCatch) + { + parseError(toCatch); + } + + // + // Use the output format parm to create the correct kind of output + // formatter. + // + XlatFormatter* formatter = 0; + switch(gOutFormat) + { + case OutFormat_CppSrc : + formatter = new CppSrcFormatter; + break; + + case OutFormat_Win32RC : + formatter = new Win32RCFormatter; + break; + + case OutFormat_MsgCatalog : + formatter = new MsgCatFormatter; + break; + + default : + wprintf(L"Uknown formatter type enum\n\n"); + throw ErrReturn_Internal; + } + + // + // Lets handle the root element stuff first. This one holds any over + // all information. + // + DOM_Element rootElem = srcDoc.getDocumentElement(); + const XMLCh* localeStr = rootElem.getAttribute(L"Locale").rawBuffer(); + + // Make sure that the locale matches what we were given + if (XMLString::compareString(localeStr, gLocale)) + { + wprintf(L"The file's locale does not match the target locale\n"); + throw ErrReturn_LocaleErr; + } + + // + // Get a list of all the MsgDomain children. These each hold one of + // the sets of (potentially separately) loadable messages. More + // importantly they all have their own error id space. + // + DOM_NodeList msgSetList = rootElem.getElementsByTagName(L"MsgDomain"); + + // + // Loop through them and look for the domains that we know are + // supposed to be there. + // + const unsigned int count = msgSetList.getLength(); + + // + // Ok, its good enough to get started. So lets call the start output + // method on the formatter. + // + formatter->startOutput(localeStr, gOutPath); + + // + // For each message domain element, we call start and end domain + // events bracketed around the loop that sends out each message + // in that domain. + // + // Within each domain, we check for the Warning, Error, and Validity + // subelements, and then iterate all the messages in each one. + // + for (unsigned int index = 0; index < count; index++) + { + // We know its a DOM Element, so go ahead and cast it + DOM_Node curNode = msgSetList.item(index); + const DOM_Element& curElem = (const DOM_Element&)curNode; + + // + // Get some of the attribute strings that we need, and transcode + // couple that need to be in local format. + // + const XMLCh* const domainStr = curElem.getAttribute(L"Domain").rawBuffer(); + + // + // Look at the domain and set up our application specific info + // that is on a per-domain basis. We need to indicate what the + // name of the header is and what the namespace is that they + // codes will go into + // + const XMLCh* headerName = 0; + const XMLCh* errNameSpace = 0; + if (!XMLString::compareString(domainStr, XMLUni::fgXMLErrDomain)) + { + headerName = L"XMLErrorCodes.hpp"; + errNameSpace = L"XML4CErrs"; + } + else if (!XMLString::compareString(domainStr, XMLUni::fgValidityDomain)) + { + headerName = L"XMLValidityCodes.hpp"; + errNameSpace = L"XML4CValid"; + } + else if (!XMLString::compareString(domainStr, XMLUni::fgExceptDomain)) + { + headerName = L"XMLExceptMsgs.hpp"; + errNameSpace = L"XML4CExcepts"; + } + else + { + // Not one of ours, so skip it + continue; + } + + // + // Lets try to create the header file that was indicated for + // this domain. + // + swprintf + ( + tmpFileBuf + , L"%s%s" + , gOutPath + , headerName + ); + FILE* outHeader = _wfopen(tmpFileBuf, L"wt+"); + if (!outHeader) + { + wprintf(L"Could not open domain header file: %s\n\n", tmpFileBuf); + throw ErrReturn_OutFileOpenFailed; + } + + // + // Write out the opening of the class they are nested within, and + // the header protection define. + // + fwprintf(outHeader, L"// This file is generated, don't edit it!!\n\n"); + fwprintf(outHeader, L"#if !defined(ERRHEADER_%s)\n", errNameSpace); + fwprintf(outHeader, L"#define ERRHEADER_%s\n\n", errNameSpace); + + // If its not the exception domain, then we need a header included + if (XMLString::compareString(domainStr, XMLUni::fgExceptDomain)) + fwprintf(outHeader, L"#include <framework/XMLErrorReporter.hpp>\n\n"); + + fwprintf(outHeader, L"class %s\n{\npublic :\n enum Codes\n {\n", errNameSpace); + + // Tell the formatter that a new domain is starting + formatter->startDomain(domainStr); + + // + // Force out the first message, which is always implicit and is + // the 'no error' entry for that domain. + // + unsigned int count = 0; + fwprintf(outHeader, L" %-32s = %d\n", L"NoError", count++); + + // + // Loop through the children of this node, which should take us + // through the optional Warning, Error, and Validity subsections. + // + DOM_Node typeNode = curElem.getFirstChild(); + bool typeGotten[3] = { false, false, false }; + while (!typeNode.isNull()) + { + // Skip over text nodes or comment nodes ect... + if (typeNode.getNodeType() != DOM_Node::ELEMENT_NODE) + { + typeNode = typeNode.getNextSibling(); + continue; + } + + // Convert it to an element node + const DOM_Element& typeElem = (const DOM_Element&)typeNode; + + // Now get its tag name and convert that to a message type enum + DOMString typeName = typeElem.getTagName(); + + MsgTypes type; + if (typeName.equals(L"Warning")) + { + type = MsgType_Warning; + typeGotten[0] = true; + } + else if (typeName.equals(L"Error")) + { + if (!XMLString::compareString(domainStr, XMLUni::fgValidityDomain)) + { + type = MsgType_Validity; + typeGotten[2] = true; + } + else + { + type = MsgType_Error; + typeGotten[1] = true; + } + } + else + { + wprintf(L"Expected a Warning or Errornode\n\n"); + throw ErrReturn_SrcFmtError; + } + + // Call the start message type event + formatter->startMsgType(type); + + // Enumerate the messages under this subsection + enumMessages + ( + typeElem + , formatter + , outHeader + , type + , count + ); + + // Call the end message type event + formatter->endMsgType(type); + + // Move to the next child of the source element + typeNode = typeNode.getNextSibling(); + } + + // + // For any that we did not get, spit out faux boundary + // values for it. + // + for (unsigned int subIndex = 0; subIndex < 3; subIndex++) + { + if (!typeGotten[subIndex]) + { + fwprintf + ( + outHeader + , L" , %s%-30s = %d\n" + , typePrefixes[subIndex] + , L"LowBounds" + , count++ + ); + fwprintf + ( + outHeader + , L" , %s%-30s = %d\n" + , typePrefixes[subIndex] + , L"HighBounds" + , count++ + ); + } + } + + // Tell the formatter that this domain is ending + formatter->endDomain(domainStr, count); + + // Close out the enum declaration + fwprintf(outHeader, L" };\n\n"); + + // + // Generate the code that creates the simple static methods + // for testing the error types. We don't do this for the + // exceptions header. + // + if (XMLString::compareString(domainStr, XMLUni::fgExceptDomain)) + { + fwprintf + ( + outHeader + , L" static bool isFatal(const %s::Codes toCheck)\n" + L" {\n" + L" return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));\n" + L" }\n\n" + , errNameSpace + ); + + fwprintf + ( + outHeader + , L" static bool isWarning(const %s::Codes toCheck)\n" + L" {\n" + L" return ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds));\n" + L" }\n\n" + , errNameSpace + ); + + fwprintf + ( + outHeader + , L" static bool isValid(const %s::Codes toCheck)\n" + L" {\n" + L" return ((toCheck >= V_LowBounds) && (toCheck <= V_HighBounds));\n" + L" }\n\n" + , errNameSpace + ); + + fwprintf + ( + outHeader + , L" static XMLErrorReporter::ErrTypes errorType(const %s::Codes toCheck)\n" + L" {\n" + L" if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))\n" + L" return XMLErrorReporter::ErrType_Warning;\n" + L" else if ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds))\n" + L" return XMLErrorReporter::ErrType_Fatal;\n" + L" else if ((toCheck >= V_LowBounds) && (toCheck <= V_HighBounds))\n" + L" return XMLErrorReporter::ErrType_Invalid;\n" + L" return XMLErrorReporter::ErrTypes_Unknown;\n" + L" }\n" + , errNameSpace + ); + } + + // And close out the class declaration and the header file + fwprintf(outHeader, L"};\n#endif\n\n"); + fclose(outHeader); + } + + // Ok, we are done so call the end output method + formatter->endOutput(); + + // And clean up the stuff we allocated + delete formatter; + } + + catch(const ErrReturns retVal) + { + return retVal; + } + + // Went ok, so return success + return ErrReturn_Success; +} + + + +// ----------------------------------------------------------------------- +// XlatErrHandler: Implementation of the error handler interface +// ----------------------------------------------------------------------- +void XlatErrHandler::warning(const SAXParseException& toCatch) +{ + parseError(toCatch); +} + +void XlatErrHandler::error(const SAXParseException& toCatch) +{ + parseError(toCatch); +} + +void XlatErrHandler::fatalError(const SAXParseException& toCatch) +{ + parseError(toCatch); +} + +void XlatErrHandler::resetErrors() +{ +} diff --git a/tools/NLS/Xlat/Xlat.hpp b/tools/NLS/Xlat/Xlat.hpp new file mode 100644 index 0000000000000000000000000000000000000000..398986ba08305169391e3f003f2cf2476bcfbcee --- /dev/null +++ b/tools/NLS/Xlat/Xlat.hpp @@ -0,0 +1,103 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:14 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:42:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Some globally used types +// --------------------------------------------------------------------------- +enum MsgTypes +{ + MsgType_Warning + , MsgType_Error + , MsgType_Validity + + , MsgTypes_Count +}; + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <stdio.h> + +#include <util/XML4CDefs.hpp> +#include <util/PlatformUtils.hpp> +#include <util/TransService.hpp> +#include <sax/SAXParseException.hpp> +#include <parsers/DOMParser.hpp> +#include "Xlat_ErrHandler.hpp" +#include "Xlat_Types.hpp" +#include "Xlat_Formatter.hpp" +#include "Xlat_CppSrc.hpp" +#include "Xlat_Win32RC.hpp" +#include "Xlat_MsgCatalog.hpp" + + + +// --------------------------------------------------------------------------- +// Some const global data +// --------------------------------------------------------------------------- +extern const XMLCh* typePrefixes[MsgTypes_Count]; diff --git a/tools/NLS/Xlat/Xlat_CppSrc.cpp b/tools/NLS/Xlat/Xlat_CppSrc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c6deb29eefd49c879bc119e6ce9589722be7b119 --- /dev/null +++ b/tools/NLS/Xlat/Xlat_CppSrc.cpp @@ -0,0 +1,241 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:16 twl + * Initial revision + * + * Revision 1.4 1999/11/08 20:42:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "Xlat.hpp" + + +// --------------------------------------------------------------------------- +// CppSrcFormatter: Implementation of the formatter interface +// --------------------------------------------------------------------------- +void CppSrcFormatter::endDomain(const XMLCh* const domainName + , const unsigned int msgCount) +{ + // And close out the array declaration + fwprintf(fOutFl, L"\n};\n"); + + // Output the const size value + fwprintf(fOutFl, L"const unsigned int %s%s = %d;\n\n", fCurDomainName, L"Size", msgCount); +} + + +void CppSrcFormatter::endMsgType(const MsgTypes type) +{ + if (fFirst) + { + fwprintf(fOutFl, L" { "); + fFirst = false; + } + else + { + fwprintf(fOutFl, L" , { "); + } + + const XMLCh* rawData = typePrefixes[type]; + while (*rawData) + fwprintf(fOutFl, L"0x%04lX,", *rawData++); + + rawData = L"End"; + while (*rawData) + fwprintf(fOutFl, L"0x%04lX,", *rawData++); + + fwprintf(fOutFl, L"0x00 }\n"); +} + + +void CppSrcFormatter::endOutput() +{ + // Close the output file + fclose(fOutFl); +} + +void +CppSrcFormatter::nextMessage(const XMLCh* const msgText + , const XMLCh* const msgId + , const unsigned int messageId + , const unsigned int curId) +{ + // + // We do not transcode to the output format in this case. Instead we + // just store the straight Unicode format. Because we cannot assume 'L' + // type prefix support, we have to put them out as numeric character + // values. + // + const XMLCh* rawData = msgText; + if (fFirst) + { + fwprintf(fOutFl, L" { "); + fFirst = false; + } + else + { + fwprintf(fOutFl, L" , { "); + } + + while (*rawData) + fwprintf(fOutFl, L"0x%04lX,", *rawData++); + fwprintf(fOutFl, L"0x00 }\n"); +} + + +void CppSrcFormatter::startDomain(const XMLCh* const domainName) +{ + // + // We have a different array name for each domain, so store that for + // later use and for use below. + // + if (!XMLString::compareString(XMLUni::fgXMLErrDomain, domainName)) + { + fCurDomainName = L"gXMLErrArray"; + } + else if (!XMLString::compareString(XMLUni::fgExceptDomain, domainName)) + { + fCurDomainName = L"gXMLExceptArray"; + } + else if (!XMLString::compareString(XMLUni::fgValidityDomain, domainName)) + { + fCurDomainName = L"gXMLValidityArray"; + } + else + { + wprintf(L"Unknown message domain: %s\n", domainName); + throw ErrReturn_SrcFmtError; + } + + // + // Output the leading part of the array declaration. Its just an + // array of pointers to Unicode chars. + // + fwprintf(fOutFl, L"const XMLCh %s[][128] = \n{\n", fCurDomainName); + + // Reset the first message trigger + fFirst = true; +} + + +void CppSrcFormatter::startMsgType(const MsgTypes type) +{ + if (fFirst) + { + fwprintf(fOutFl, L" { "); + fFirst = false; + } + else + { + fwprintf(fOutFl, L" , { "); + } + + const XMLCh* rawData = typePrefixes[type]; + while (*rawData) + fwprintf(fOutFl, L"0x%04lX,", *rawData++); + + rawData = L"Start"; + while (*rawData) + fwprintf(fOutFl, L"0x%04lX,", *rawData++); + + fwprintf(fOutFl, L"0x00 }\n"); +} + + +void CppSrcFormatter::startOutput( const XMLCh* const locale + , const XMLCh* const outPath) +{ + // + // Ok, lets try to open the the output file. All of the messages + // for all the domains are put into a single Cpp file, which can be + // compiled into the program. + // + // CppErrMsgs_xxxx.cpp + // + // where xxx is the locale suffix passed in. + // + const unsigned int bufSize = 4095; + XMLCh tmpBuf[bufSize + 1]; + + swprintf(tmpBuf, L"%s/%s_%s.hpp", outPath, L"CppErrMsgs", locale); + fOutFl = _wfopen(tmpBuf, L"wt"); + if (!fOutFl) + { + wprintf(L"Could not open the output file: %s\n\n", tmpBuf); + throw ErrReturn_OutFileOpenFailed; + } + + // + // Ok, lets output the grunt data at the start of the file. We put out a + // comment that indicates its a generated file, and the title string. + // + fwprintf + ( + fOutFl + , L"// ----------------------------------------------------------------\n" + L"// This file was generated from the XML error message source.\n" + L"// so do not edit this file directly!!\n" + L"// ----------------------------------------------------------------\n\n" + ); +} diff --git a/tools/NLS/Xlat/Xlat_CppSrc.hpp b/tools/NLS/Xlat/Xlat_CppSrc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ed6b98677fcf4f6abeff43ff3700a6f312888fe2 --- /dev/null +++ b/tools/NLS/Xlat/Xlat_CppSrc.hpp @@ -0,0 +1,152 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:18 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +class CppSrcFormatter : public XlatFormatter +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + CppSrcFormatter() : + + fCurDomainName(0) + , fFirst(true) + , fOutFl(0) + { + } + + virtual ~CppSrcFormatter() + { + } + + + // ----------------------------------------------------------------------- + // Implementation of the formatter interface + // ----------------------------------------------------------------------- + virtual void endDomain + ( + const XMLCh* const domainName + , const unsigned int msgCount + ); + + virtual void endMsgType + ( + const MsgTypes type + ); + + virtual void endOutput(); + + virtual void nextMessage + ( + const XMLCh* const msgText + , const XMLCh* const msgId + , const unsigned int messageId + , const unsigned int curId + ); + + virtual void startDomain(const XMLCh* const domainName); + + virtual void startMsgType + ( + const MsgTypes type + ); + + virtual void startOutput + ( + const XMLCh* const locale + , const XMLCh* const outPath + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + CppSrcFormatter(const CppSrcFormatter&); + void operator=(const CppSrcFormatter&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fCurDomainName + // This is the short name for the current domain being processed. + // This is used to make the names of the array and array size + // constant. + // + // fFirst + // A trigger to catch the first message for a domain and do some + // slightly different formatting. + // + // fOutFl + // This is the current output file. Its created when a new domain + // is begun via startDomain() and closed when endDomain is called. + // ----------------------------------------------------------------------- + XMLCh* fCurDomainName; + bool fFirst; + FILE* fOutFl; +}; diff --git a/tools/NLS/Xlat/Xlat_ErrHandler.hpp b/tools/NLS/Xlat/Xlat_ErrHandler.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c3ed0a933e41efbd495549ddcd97813ad2139a9c --- /dev/null +++ b/tools/NLS/Xlat/Xlat_ErrHandler.hpp @@ -0,0 +1,92 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:20 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:05 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + +#include <util/XML4CDefs.hpp> +#include <sax/ErrorHandler.hpp> + +class XlatErrHandler : public ErrorHandler +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + XlatErrHandler() + { + } + + ~XlatErrHandler() + { + } + + + // ----------------------------------------------------------------------- + // Implementation of the error handler interface + // ----------------------------------------------------------------------- + void warning(const SAXParseException& toCatch); + void error(const SAXParseException& toCatch); + void fatalError(const SAXParseException& toCatch); + void resetErrors(); +}; diff --git a/tools/NLS/Xlat/Xlat_Formatter.hpp b/tools/NLS/Xlat/Xlat_Formatter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dfd69a7a5aff76b422cb00f7ce7d6062bf4a5af1 --- /dev/null +++ b/tools/NLS/Xlat/Xlat_Formatter.hpp @@ -0,0 +1,137 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:22 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:42:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// This is a simple abstract API that each formatter must provide. This is +// how the main program logic calls out with all of the needed information +// and events needed to create the output. +// --------------------------------------------------------------------------- +class XlatFormatter +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + virtual ~XlatFormatter() + { + } + + + // ----------------------------------------------------------------------- + // Virtual formatter interface + // ----------------------------------------------------------------------- + virtual void endDomain + ( + const XMLCh* const domainName + , const unsigned int msgCount + ) = 0; + + virtual void endMsgType + ( + const MsgTypes type + ) = 0; + + virtual void endOutput() = 0; + + virtual void nextMessage + ( + const XMLCh* const msgText + , const XMLCh* const msgId + , const unsigned int messageId + , const unsigned int curId + ) = 0; + + virtual void startDomain(const XMLCh* const domainName) = 0; + + virtual void startMsgType + ( + const MsgTypes type + ) = 0; + + virtual void startOutput + ( + const XMLCh* const locale + , const XMLCh* const outPath + ) = 0; + + +protected : + // ----------------------------------------------------------------------- + // Hidden constructors + // ----------------------------------------------------------------------- + XlatFormatter() + { + } + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + XlatFormatter(const XlatFormatter&); + void operator=(const XlatFormatter&); +}; diff --git a/tools/NLS/Xlat/Xlat_MsgCatalog.cpp b/tools/NLS/Xlat/Xlat_MsgCatalog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1fe4a99a5bfe9c2de55217cbf9813119a15843a1 --- /dev/null +++ b/tools/NLS/Xlat/Xlat_MsgCatalog.cpp @@ -0,0 +1,209 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:24 twl + * Initial revision + * + * Revision 1.5 1999/11/08 20:42:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "Xlat.hpp" + + + +// --------------------------------------------------------------------------- +// MsgCatFormatter: Constructors and Destructor +// --------------------------------------------------------------------------- +MsgCatFormatter::MsgCatFormatter() : + + fOutFl(0) + , fTranscoder(0) +{ + // + // Try to create a transcoder for the format that we were told + // to output in. + // + XMLTransService::Codes resValue; + fTranscoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor + ( + L"UTF8" + , resValue + , 0 + ); + + if (!fTranscoder) + { + wprintf(L"Could not create UTF-8 transcoder\n"); + throw ErrReturn_NoTranscoder; + } +} + +MsgCatFormatter::~MsgCatFormatter() +{ +} + + +// --------------------------------------------------------------------------- +// MsgCatFormatter: Implementation of the formatter interface +// --------------------------------------------------------------------------- +void MsgCatFormatter::endDomain(const XMLCh* const domainName + , const unsigned int msgCount) +{ + fwprintf(fOutFl, L"\n\n"); +} + + +void MsgCatFormatter::endMsgType(const MsgTypes type) +{ +} + + +void MsgCatFormatter::endOutput() +{ + // Close the output file + fclose(fOutFl); +} + +void +MsgCatFormatter::nextMessage(const XMLCh* const msgText + , const XMLCh* const msgId + , const unsigned int messageId + , const unsigned int curId) +{ + // + // We have to transcode the message text to UTF-8 in order to be able + // to write it out to a message catalog (which is not Unicode enabled.) + // If the text is just US-ASCII, this won't have any effect, but don't + // bother checking, just do it simple and stupid. + // + char* outData = fTranscoder->transcode(msgText); + fwprintf(fOutFl, L"%3d %S\n", curId, outData); + delete [] outData; +} + + +void MsgCatFormatter::startDomain(const XMLCh* const domainName) +{ + // + // We need to output a different set id for each domain. So we look + // for each one here and assign a set number. + // + unsigned int setNum; + if (!XMLString::compareString(XMLUni::fgXMLErrDomain, domainName)) + { + setNum = 1; + } + else if (!XMLString::compareString(XMLUni::fgExceptDomain, domainName)) + { + setNum = 2; + } + else if (!XMLString::compareString(XMLUni::fgValidityDomain, domainName)) + { + setNum = 3; + } + else + { + wprintf(L"Unknown message domain: %s\n", domainName); + throw ErrReturn_SrcFmtError; + } + + // + // Output the leading part of the array declaration. Its just an + // array of pointers to Unicode chars. + // + fwprintf(fOutFl, L"$set %u\n", setNum); +} + + +void MsgCatFormatter::startMsgType(const MsgTypes type) +{ +} + + +void MsgCatFormatter::startOutput( const XMLCh* const locale + , const XMLCh* const outPath) +{ + // + // Ok, lets try to open the the output file. All of the messages + // for all the domains are put into a single Msg file, which can be + // compiled into the program. + // + // CppErrMsgs_xxxx.Msg + // + // where xxx is the locale suffix passed in. + // + const unsigned int bufSize = 4095; + XMLCh tmpBuf[bufSize + 1]; + + swprintf(tmpBuf, L"%s/%s_%s.Msg", outPath, L"XMLMsgCat", locale); + fOutFl = _wfopen(tmpBuf, L"wt"); + if (!fOutFl) + { + wprintf(L"Could not open the output file: %s\n\n", tmpBuf); + throw ErrReturn_OutFileOpenFailed; + } + + // Set the message delimiter + fwprintf(fOutFl, L"$quote \"\n"); +} diff --git a/tools/NLS/Xlat/Xlat_MsgCatalog.hpp b/tools/NLS/Xlat/Xlat_MsgCatalog.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6d6f55391cba25b2a89c418068dc6770e95ea5ea --- /dev/null +++ b/tools/NLS/Xlat/Xlat_MsgCatalog.hpp @@ -0,0 +1,136 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:27 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:42:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +class MsgCatFormatter : public XlatFormatter +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + MsgCatFormatter(); + virtual ~MsgCatFormatter(); + + + // ----------------------------------------------------------------------- + // Implementation of the formatter interface + // ----------------------------------------------------------------------- + virtual void endDomain + ( + const XMLCh* const domainName + , const unsigned int msgCount + ); + + virtual void endMsgType + ( + const MsgTypes type + ); + + virtual void endOutput(); + + virtual void nextMessage + ( + const XMLCh* const msgText + , const XMLCh* const msgId + , const unsigned int messageId + , const unsigned int curId + ); + + virtual void startDomain(const XMLCh* const domainName); + + virtual void startMsgType + ( + const MsgTypes type + ); + + virtual void startOutput + ( + const XMLCh* const locale + , const XMLCh* const outPath + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + MsgCatFormatter(const MsgCatFormatter&); + void operator=(const MsgCatFormatter&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fOutFl + // This is the current output file. + // + // fTranscoder + // This is our transcoder. We transcode to UTF-8 in order to output + // Unicode based text to the message catalog. + // ----------------------------------------------------------------------- + FILE* fOutFl; + XMLTranscoder* fTranscoder; +}; diff --git a/tools/NLS/Xlat/Xlat_Types.hpp b/tools/NLS/Xlat/Xlat_Types.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bd001e5a9d3521e70a23c2894303ceed328f9680 --- /dev/null +++ b/tools/NLS/Xlat/Xlat_Types.hpp @@ -0,0 +1,100 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:28 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:06 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Data types +// +// ErrReturns +// These are the values returned from main when an error occurs. It is +// also used to throw errors out to the main for return. +// +// OutFormts +// The available output formats. This is mapped to from the /OutFmt= +// command line parameter. +// --------------------------------------------------------------------------- +enum ErrReturns +{ + ErrReturn_Success = 0 + , ErrReturn_BadParameters = 1 + , ErrReturn_OutFileOpenFailed = 4 + , ErrReturn_ParserInit = 5 + , ErrReturn_ParseErr = 6 + , ErrReturn_LocaleErr = 7 + , ErrReturn_NoTranscoder = 8 + , ErrReturn_SrcFmtError = 9 + , ErrReturn_UnknownDomain = 10 + , ErrReturn_Internal = 9999 +}; + +enum OutFormats +{ + OutFormat_Unknown + , OutFormat_CppSrc + , OutFormat_ResBundle + , OutFormat_Win32RC + , OutFormat_MsgCatalog +}; diff --git a/tools/NLS/Xlat/Xlat_Win32RC.cpp b/tools/NLS/Xlat/Xlat_Win32RC.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a14682e78a741939be014ed7336c3dcf01d667e --- /dev/null +++ b/tools/NLS/Xlat/Xlat_Win32RC.cpp @@ -0,0 +1,215 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:30 twl + * Initial revision + * + * Revision 1.3 1999/11/08 20:42:07 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "Xlat.hpp" + + +// --------------------------------------------------------------------------- +// Win32RCFormatter: Public Constructors and Destructor +// --------------------------------------------------------------------------- +Win32RCFormatter::Win32RCFormatter() : + + fCurDomainName(0) + , fMsgOffset(0) + , fOutFl(0) +{ +} + +Win32RCFormatter::~Win32RCFormatter() +{ +} + + +// --------------------------------------------------------------------------- +// Win32RCFormatter: Implementation of the formatter interface +// --------------------------------------------------------------------------- +void Win32RCFormatter::endDomain(const XMLCh* const domainName + , const unsigned int msgCount) +{ + // And close out the message table declaration + fwprintf(fOutFl, L"END\n"); +} + + +void Win32RCFormatter::endMsgType(const MsgTypes type) +{ + // No-op for us +} + + +void Win32RCFormatter::endOutput() +{ + // Close the output file + fclose(fOutFl); +} + + +void +Win32RCFormatter::nextMessage( const XMLCh* const msgText + , const XMLCh* const msgId + , const unsigned int messageId + , const unsigned int curId) +{ + // + // We do not transcode to the output format in this case. Instead we + // just store the straight Unicode format. Because we cannot assume 'L' + // type prefix support, we have to put them out as numeric character + // values. + // + fwprintf(fOutFl, L" %-16d L\"", messageId + fMsgOffset); + + const XMLCh* rawData = msgText; + while (*rawData) + fwprintf(fOutFl, L"\\x%04lX", *rawData++); + fwprintf(fOutFl, L"\\x00\"\n"); +} + + +void Win32RCFormatter::startDomain(const XMLCh* const domainName) +{ + // + // We have a different array name for each domain, so store that for + // later use and for use below. + // + if (!XMLString::compareString(XMLUni::fgXMLErrDomain, domainName)) + { + fCurDomainName = L"gXMLErrArray"; + fMsgOffset = 0; + } + else if (!XMLString::compareString(XMLUni::fgExceptDomain, domainName)) + { + fCurDomainName = L"gXMLExceptArray"; + fMsgOffset = 0x2000; + } + else if (!XMLString::compareString(XMLUni::fgValidityDomain, domainName)) + { + fCurDomainName = L"gXMLValidityArray"; + fMsgOffset = 0x4000; + } + else + { + wprintf(L"Unknown message domain: %s\n", domainName); + throw ErrReturn_SrcFmtError; + } + + // + // Output the leading part of the array declaration. Its just an + // array of pointers to Unicode chars. + // + fwprintf + ( + fOutFl + , L"STRINGTABLE DISCARDABLE\nBEGIN\n" + ); +} + + +void Win32RCFormatter::startMsgType(const MsgTypes type) +{ + // No-op for us +} + + +void Win32RCFormatter::startOutput( const XMLCh* const locale + , const XMLCh* const outPath) +{ + // + // Ok, lets try to open the the output file. All of the messages for all + // the domains are put into a single message tabble in a single RC file, + // which can be linked into the program. + // + // CppErrMsgs_xxxx.RC + // + // where xxx is the locale suffix passed in. + // + const unsigned int bufSize = 4095; + XMLCh tmpBuf[bufSize + 1]; + + swprintf(tmpBuf, L"%s/%s_%s.RC", outPath, L"CppErrMsgs", locale); + fOutFl = _wfopen(tmpBuf, L"wt"); + if (!fOutFl) + { + wprintf(L"Could not open the output file: %s\n\n", tmpBuf); + throw ErrReturn_OutFileOpenFailed; + } + + // + // Ok, lets output the grunt data at the start of the file. We put out a + // comment that indicates its a generated file, and the title string. + // + fwprintf + ( + fOutFl + , L"// ----------------------------------------------------------------\n" + L"// This file was generated from the XML error message source.\n" + L"// so do not edit this file directly!!\n" + L"// ----------------------------------------------------------------\n\n" + ); +} diff --git a/tools/NLS/Xlat/Xlat_Win32RC.hpp b/tools/NLS/Xlat/Xlat_Win32RC.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a4b52ddfb947011026c74e910767beda2baaeeb2 --- /dev/null +++ b/tools/NLS/Xlat/Xlat_Win32RC.hpp @@ -0,0 +1,147 @@ +/* + * 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/>. + */ + +/** + * $Log$ + * Revision 1.1 1999/11/09 01:01:32 twl + * Initial revision + * + * Revision 1.2 1999/11/08 20:42:07 rahul + * Swat for adding in Product name and CVS comment log variable. + * + */ + + +class Win32RCFormatter : public XlatFormatter +{ +public : + // ----------------------------------------------------------------------- + // Public Constructors and Destructor + // ----------------------------------------------------------------------- + Win32RCFormatter(); + virtual ~Win32RCFormatter(); + + + // ----------------------------------------------------------------------- + // Implementation of the formatter interface + // ----------------------------------------------------------------------- + virtual void endDomain + ( + const XMLCh* const domainName + , const unsigned int msgCount + ); + + virtual void endMsgType + ( + const MsgTypes type + ); + + virtual void endOutput(); + + virtual void nextMessage + ( + const XMLCh* const msgText + , const XMLCh* const msgId + , const unsigned int messageId + , const unsigned int curId + ); + + virtual void startDomain(const XMLCh* const domainName); + + virtual void startMsgType + ( + const MsgTypes type + ); + + virtual void startOutput + ( + const XMLCh* const locale + , const XMLCh* const outPath + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + Win32RCFormatter(const Win32RCFormatter&); + void operator=(const Win32RCFormatter&); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fCurDomainName + // This is the short name for the current domain being processed. + // This is used to create the names of information we write to the + // file. + // + // fMsgOffset + // Since we are going to put all the messages into a single message + // table, we have to provide an offset for each domain (since they + // each think that they have a unique numbering range.) So we just + // offset each new domain by 0x2000 to keep them separate. When the + // numbers are passed into the Win32RCMsgLoader, it will offset the + // incoming message ids by the appropriate amount. + // + // fOutFl + // This is the current output file. Its created when a new domain + // is begun via startDomain() and closed when endDomain is called. + // ----------------------------------------------------------------------- + XMLCh* fCurDomainName; + unsigned int fMsgOffset; + FILE* fOutFl; +};