## YACS specifics
##
-FIND_PACKAGE(SalomeExpat REQUIRED)
-
# Detection summary:
SALOME_PACKAGE_REPORT_AND_CHECK()
SET(KERNEL_ROOT_DIR "${KERNEL_ROOT_DIR}")
SET(GUI_ROOT_DIR "${GUI_ROOT_DIR}")
SET(QT4_ROOT_DIR "${QT4_ROOT_DIR}")
-SET(EXPAT_ROOT_DIR "${EXPAT_ROOT_DIR}")
SET(QSCINTILLA_ROOT_DIR "${QSCINTILLA_ROOT_DIR}")
SET(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include")
# Build variables that will be expanded when configuring Salome<MODULE>Config.cmake:
-SALOME_CONFIGURE_PREPARE(Expat QScintilla Qt4)
+SALOME_CONFIGURE_PREPARE(QScintilla Qt4)
CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_NAME}Config.cmake.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}"
PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE_LOCAL CMAKE_INSTALL_PREFIX
- KERNEL_ROOT_DIR GUI_ROOT_DIR QT4_ROOT_DIR EXPAT_ROOT_DIR QSCINTILLA_ROOT_DIR)
+ KERNEL_ROOT_DIR GUI_ROOT_DIR QT4_ROOT_DIR QSCINTILLA_ROOT_DIR)
# - in the install tree (VSR 16/08/2013: TEMPORARILY COMMENT THIS - TO REMOVE?):
# Get the relative path of the include directory so
# ${PROJECT_BINARY_DIR}/to_install/${PROJECT_NAME}Config.cmake
# INSTALL_DESTINATION "${SALOME_INSTALL_CMAKE_LOCAL}"
# PATH_VARS CONF_INCLUDE_DIRS SALOME_INSTALL_CMAKE_LOCAL CMAKE_INSTALL_PREFIX
-# KERNEL_ROOT_DIR GUI_ROOT_DIR QT4_ROOT_DIR EXPAT_ROOT_DIR QSCINTILLA_ROOT_DIR)
+# KERNEL_ROOT_DIR GUI_ROOT_DIR QT4_ROOT_DIR QSCINTILLA_ROOT_DIR)
WRITE_BASIC_PACKAGE_VERSION_FILE(${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${${PROJECT_NAME_UC}_VERSION}
SET(SALOME_YACS_USE_QSCINTILLA @SALOME_YACS_USE_QSCINTILLA@)
SET(SALOME_YACS_USE_SWIG @SALOME_YACS_USE_SWIG@)
-# Level 1 prerequisites:
-SET_AND_CHECK(EXPAT_ROOT_DIR_EXP "@PACKAGE_EXPAT_ROOT_DIR@")
-
# Optional level 1 prerequisites:
IF(SALOME_YACS_USE_KERNEL)
SET_AND_CHECK(KERNEL_ROOT_DIR_EXP "@PACKAGE_KERNEL_ROOT_DIR@")
# These files are data, module or lib files
SET(_adm_data
- FindExpat.cmake
- FindSalomeExpat.cmake
FindQScintilla.cmake
FindSalomeQScintilla.cmake
FindSphinx.cmake
+++ /dev/null
-# Copyright (C) 2006-2014 CEA/DEN, EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library 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
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-FIND_LIBRARY(EXPAT_LIBRARIES NAMES expat libexpat)
-
-FIND_PATH(EXPAT_INCLUDE_DIR expat.h)
-
-# Handle the standard arguments of the find_package() command:
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(Expat REQUIRED_VARS EXPAT_LIBRARIES EXPAT_INCLUDE_DIR)
+++ /dev/null
-# Copyright (C) 2013-2014 CEA/DEN, EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library 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
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-# Expat detection for Salome
-#
-# !! Please read the generic detection procedure in SalomeMacros.cmake !!
-#
-SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(Expat EXPAT_ROOT_DIR 0)
-MARK_AS_ADVANCED(EXPAT_LIBRARIES EXPAT_INCLUDE_DIR)
-#IF(Expat_FOUND OR EXPAT_FOUND)
-# MESSAGE(STATUS "EXPAT include dir is: ${EXPAT_INCLUDE_DIR}")
-#ENDIF()
-
-IF(Expat_FOUND OR EXPAT_FOUND)
- SALOME_ACCUMULATE_HEADERS(EXPAT_INCLUDE_DIR)
- SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${EXPAT_LIBRARIES})
-ENDIF()
check_boost.m4
check_cas.m4
check_cppunit.m4
- check_expat.m4
check_htmlgen.m4
check_libxml.m4
check_omniorb.m4
+++ /dev/null
-dnl Copyright (C) 2006-2014 CEA/DEN, EDF R&D
-dnl
-dnl This library is free software; you can redistribute it and/or
-dnl modify it under the terms of the GNU Lesser General Public
-dnl License as published by the Free Software Foundation; either
-dnl version 2.1 of the License, or (at your option) any later version.
-dnl
-dnl This library is distributed in the hope that it will be useful,
-dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-dnl Lesser General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU Lesser General Public
-dnl License along with this library; if not, write to the Free Software
-dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-dnl
-dnl See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-dnl
-
-AC_DEFUN([AC_CHECK_EXPAT],[
-
-AC_CHECKING(for expat)
-
-CXXFLAGS_old=$CXXFLAGS
-CPPFLAGS_old=$CPPFLAGS
-
-# Custom location of expat package can be specified
-# through EXPAT_DIR variable
-EXPATDIR=
-if test "x$EXPAT_DIR" != "x"
-then
- EXPATDIR=$EXPAT_DIR
-elif test "x$EXPAT_ROOT" != "x"
-then
- EXPATDIR=$EXPAT_ROOT
-fi
-
-if test "x$EXPATDIR" != "x"
-then
- if test "x$EXPATDIR" = "x/usr"
- then
- AC_MSG_NOTICE(Trying native Expat...)
- TMPLIBS="-lexpat $LIBS"
- else
- AC_MSG_NOTICE(Trying Expat from $EXPATDIR ...)
- TMPLIBS="-L$EXPATDIR/lib -lexpat $LIBS"
- CXXFLAGS="$CXXFLAGS -I$EXPATDIR/include"
- CPPFLAGS="$CPPFLAGS -I$EXPATDIR/include"
- EXPAT_INCLUDES="-I$EXPATDIR/include"
- fi
-else
- AC_MSG_NOTICE(Trying native Expat...)
- TMPLIBS="-lexpat $LIBS"
-fi
-
-AC_CHECK_HEADER(expat.h,expat_ok="yes",expat_ok="no")
-
-if test "x$expat_ok" = "xyes"
-then
- LIBS_old=$LIBS
- LIBS=$TMPLIBS
- AC_CHECK_LIB(expat,XML_ExpatVersionInfo,expat_ok="yes",expat_ok="no",)
- LIBS=$LIBS_old
-fi
-
-if test "x$expat_ok" = "xyes"
-then
- EXPAT_LIBS=$TMPLIBS
-fi
-
-AC_MSG_RESULT(for expat: $expat_ok)
-
-CXXFLAGS=$CXXFLAGS_old
-CPPFLAGS=$CPPFLAGS_old
-
-AC_SUBST(EXPAT_LIBS)
-AC_SUBST(EXPAT_INCLUDES)
-
-])dnl
-dnl
-
For building %YACS, you need some prerequisites
- g++ 4.1 or more (mandatory)
- libxml2 (mandatory)
- - expat (mandatory)
- omniorb 4.1 or more (mandatory)
- python 2.3 and + (mandatory)
- swig 1.3.31 (mandatory)
# additional include directories
INCLUDE_DIRECTORIES(
${PYTHON_INCLUDE_DIR}
- ${EXPAT_INCLUDE_DIR}
${OMNIORB_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
${GRAPHVIZ_INCLUDE_DIRS}
SalomeWrap
HMI
SalomeResourcesManager
- ${EXPAT_LIBRARIES}
${LIBXML2_LIBRARIES}
${GRAPHVIZ_LIBRARIES}
)
# libraries to link to
SET(_link_LIBRARIES
- ${EXPAT_LIBRARIES}
${LIBXML2_LIBRARIES}
YACSRuntimeSALOME
YACSloader
# additional include directories
INCLUDE_DIRECTORIES(
${OMNIORB_INCLUDE_DIR}
- ${EXPAT_INCLUDE_DIR}
${PYTHON_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/src/bases
${PROJECT_SOURCE_DIR}/src/engine
# libraries to link to
SET(YACSloader_LIBRARIES
${OMNIORB_LIBRARIES}
- ${EXPAT_LIBRARIES}
+ ${LIBXML2_LIBRARIES}
YACSlibEngine
)
SET(_link_LIBRARIES
${CPPUNIT_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIR}
${OMNIORB_INCLUDE_DIR}
- ${EXPAT_INCLUDE_DIR}
${KERNEL_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/../../bases
virtual void onEnd(const char *el,parser* child);
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
static functypeParser funcParser;
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
void componentinstancetypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
void machinetypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
void containertypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
void loadtypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("container",attr);
for (int i = 0; attr[i]; i += 2)
{
}
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
}
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
for (int i = 0; attr[i]; i += 2)
{
if((std::string(attr[i]) == "control")
template <class T>
void looptypeParser<T>::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
template <class T>
void forlooptypeParser<T>::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("name",attr);
this->required("type",attr);
for (int i = 0; attr[i]; i += 2)
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("name",attr);
this->required("lib",attr);
this->required("entry",attr);
}
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
required("type",attr);
for (int i = 0; attr[i]; i += 2)
}
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
DEBTRACE("outputdatatypeParser::buildAttr");
required("name",attr);
required("type",attr);
template <class T>
void outnodetypeParser<T>::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
DEBTRACE("outnodetypeParser::buildAttr");
this->required("name",attr);
for (int i = 0; attr[i]; i += 2)
//#define _DEVDEBUG_
#include "YacsTrace.hxx"
+#include <libxml/parserInternals.h>
YACS::ENGINE::Proc* currentProc;
-XML_Parser p ;
-std::stack<YACS::parser*> sp;
+_xmlParserCtxt* saxContext;
namespace YACS
{
parser parser::main_parser;
+ std::stack<parser*> parser::_stackParser;
parser::~parser()
{
std::stack<parser*>& parser::getStack()
{
- return sp;
+ return _stackParser;
}
void parser::SetUserDataAndPush(parser* pp)
{
- XML_SetUserData(p,pp);
- sp.push(pp);
+ XML_SetUserData(saxContext,pp);
+ _stackParser.push(pp);
DEBTRACE("parser::SetUserDataAndPush, stack size: " << sp.size());
}
-void XMLCALL parser::start(void *data, const XML_Char* el, const XML_Char** attr)
-{
- DEBTRACE("parser::start, stack size: " << sp.size());
- parser* pp=static_cast <parser *> (data);
- pp->incrCount(el);
- pp->onStart(el,attr);
-}
-
-void parser::onEnd(const XML_Char *el,parser* child)
+void parser::onEnd(const XML_Char *el, parser* child)
{
DEBTRACE("parser::onEnd: " << el)
}
-void XMLCALL parser::end(void *data, const char *el)
-{
- DEBTRACE("parser::end: " << el);
- parser* child=static_cast <parser *> (data);
- sp.pop();
- DEBTRACE("parser::end, stack size: " << sp.size());
- parser* pp=sp.top();
- XML_SetUserData(p,pp);
- pp->onEnd(el,child);
- child->endParser();
-}
-
void parser::charData(const XML_Char *s, int len)
{
_content=_content+std::string(s,len);
}
-void XMLCALL parser::charac(void *data, const XML_Char *s, int len)
-{
- parser* pp=static_cast <parser *> (data);
- pp->charData(s,len);
-}
-
void parser::endParser()
{
DEBTRACE("parser::endParser, level: " <<_level);
void parser::incrCount(const XML_Char *el)
{
- if(_counts->count(el)==0)
+ if((*_counts).find(el)==(*_counts).end())
(*_counts)[el]=1;
else
(*_counts)[el]=(*_counts)[el]+1;
void parser::required(const std::string& name, const XML_Char** attr)
{
- for (int i = 0; attr[i]; i += 2)
+ for (int i = 0; attr[i]; i += 2)
{
if(name == std::string(attr[i]))return;
}
void parser::buildAttr(const XML_Char** attr)
{
- for (int i = 0; attr[i]; i += 2)
- {
- DEBTRACE(attr[i] << "=" << attr[i + 1]);
- }
+ if (!attr)
+ return;
+ for (int i = 0; attr[i]; i += 2)
+ {
+ DEBTRACE(attr[i] << "=" << attr[i + 1]);
+ }
}
void parser::onStart(const XML_Char* el, const XML_Char** attr)
void parser::logError(const std::string& reason)
{
DEBTRACE( "parser::logError: " << _file );
- currentProc->getLogger("parser")->error(reason,main_parser._file.c_str(),XML_GetCurrentLineNumber(p));
+ currentProc->getLogger("parser")->error(reason,main_parser._file.c_str(),saxContext->input->line);
+}
+void parser::XML_SetUserData(_xmlParserCtxt* ctxt,
+ parser* par)
+{
+ ctxt->userData = par;
+}
+
+void XMLCALL parser::start_document(void* data)
+{
+ DEBTRACE("parser::start_document");
+ parser *currentParser = static_cast<parser *> (data);
+}
+
+void XMLCALL parser::end_document(void* data)
+{
+ DEBTRACE("parser::end_document");
+ parser *currentParser = static_cast<parser *> (data);
+}
+
+void XMLCALL parser::start_element(void* data,
+ const xmlChar* name,
+ const xmlChar** p)
+{
+ DEBTRACE("parser::start_element " << name);
+ parser *currentParser = static_cast<parser *> (data);
+ currentParser->incrCount((const XML_Char *)name);
+ currentParser->onStart((const XML_Char *)name, (const XML_Char **)p);
+}
+
+void XMLCALL parser::end_element(void* data,
+ const xmlChar* name)
+{
+ DEBTRACE("parser::end_element");
+ parser *childParser = static_cast<parser *> (data);
+ _stackParser.pop();
+ parser* pp=_stackParser.top();
+ XML_SetUserData(saxContext, pp);
+ pp->onEnd((const XML_Char *)name, childParser);
+ childParser->endParser();
+ }
+
+void XMLCALL parser::characters(void* data,
+ const xmlChar* ch,
+ int len)
+{
+ DEBTRACE("parser::characters " << len);
+ parser *currentParser = (parser *) (data);
+ currentParser->charData((const XML_Char*) ch, len);
+}
+
+void XMLCALL parser::comment(void* data,
+ const xmlChar* value)
+{
+ DEBTRACE("parser::comment");
+ parser *currentParser = static_cast<parser *> (data);
+}
+
+void XMLCALL parser::cdata_block(void* data,
+ const xmlChar* value,
+ int len)
+{
+ DEBTRACE("parser::cdata_block");
+ parser *currentParser = static_cast<parser *> (data);
+ currentParser->charData((const XML_Char*) value, len);
+}
+
+void XMLCALL parser::warning(void* data,
+ const char* fmt, ...)
+{
+ DEBTRACE("parser::warning");
+ parser *currentParser = static_cast<parser *> (data);
+ va_list args;
+ va_start(args, fmt);
+ std::string format = "%s";
+ if (format == fmt)
+ {
+ char* parv;
+ parv = va_arg(args, char*);
+ std::cerr << parv ;
+ }
+ else std::cerr << __FILE__ << " [" << __LINE__ << "] : "
+ << "error format not taken into account: " << fmt << std::endl;
+ va_end(args);
+}
+
+void XMLCALL parser::error(void* data,
+ const char* fmt, ...)
+{
+ DEBTRACE("parser::error");
+ parser *currentParser = static_cast<parser *> (data);
+ va_list args;
+ va_start(args, fmt);
+ std::string format = "%s";
+ if (format == fmt)
+ {
+ char* parv;
+ parv = va_arg(args, char*);
+ std::cerr << parv ;
+ }
+ else std::cerr << __FILE__ << " [" << __LINE__ << "] : "
+ << "error format not taken into account: " << fmt << std::endl;
+ va_end(args);
+}
+
+void XMLCALL parser::fatal_error(void* data,
+ const char* fmt, ...)
+{
+ DEBTRACE("parser::fatal_error");
+ parser *currentParser = static_cast<parser *> (data);
+ va_list args;
+ va_start(args, fmt);
+ std::string format = "%s";
+ if (format == fmt)
+ {
+ char* parv;
+ parv = va_arg(args, char*);
+ std::cerr << parv ;
+ }
+ else std::cerr << __FILE__ << " [" << __LINE__ << "] : "
+ << "error format not taken into account: " << fmt << std::endl;
+ va_end(args);
}
}
#include "YACSloaderExport.hxx"
-#include <expat.h>
#include <stack>
#include <map>
#include <string>
#include <iostream>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlreader.h>
+
namespace YACS
{
+typedef char XML_Char;
+
struct YACSLOADER_EXPORT parser
{
static parser main_parser;
+ static std::stack<parser*> _stackParser;
parser():_level(0),_defaultParsersMap(0)
{
_counts=new std::map<std::string,int>;
}
virtual ~parser();
-
virtual void SetUserDataAndPush(parser* pp);
virtual void onStart(const XML_Char *el, const XML_Char** attr);
- static void XMLCALL start(void *data, const XML_Char* el, const XML_Char** attr);
-
- virtual void onEnd(const XML_Char *el,parser* child);
-
- static void XMLCALL end(void *data, const char *el);
-
+ virtual void onEnd(const XML_Char *el, parser* child);
virtual void charData(const XML_Char *s, int len);
-
- static void XMLCALL charac(void *data, const XML_Char *s, int len);
-
virtual void endParser();
-
virtual void init();
-
- virtual void incrCount(const XML_Char *el);
-
+ virtual void incrCount(const XML_Char *elem);
virtual void checkOrder(std::string& el);
-
virtual void maxcount(std::string name, int max, std::string& el);
-
virtual void mincount(std::string name,int min );
-
virtual void maxchoice(std::string *names, int max, std::string& el);
-
virtual void minchoice(std::string *names, int min);
-
virtual void pre(){_content="";};
virtual void required(const std::string& name, const XML_Char** attr);
-
virtual void buildAttr(const XML_Char** attr);
-
+
+ static void XMLCALL start_document(void* data);
+ static void XMLCALL end_document (void* data);
+ static void XMLCALL start_element (void* data,
+ const xmlChar* name,
+ const xmlChar** p);
+ static void XMLCALL end_element (void* data,
+ const xmlChar* name);
+ static void XMLCALL characters (void* data,
+ const xmlChar* ch,
+ int len);
+ static void XMLCALL comment (void* data,
+ const xmlChar* value);
+ static void XMLCALL cdata_block (void* data,
+ const xmlChar* value,
+ int len);
+ static void XMLCALL warning (void* data,
+ const char* fmt, ...);
+ static void XMLCALL error (void* data,
+ const char* fmt, ...);
+ static void XMLCALL fatal_error (void* data,
+ const char* fmt, ...);
+
+ static void XML_SetUserData(_xmlParserCtxt* ctxt, parser* par);
+
std::stack<parser*>& getStack();
template<class T>
#include "parsers.hxx"
-#include <expat.h>
#include <iostream>
#include <stdexcept>
#include <cstdio>
//#define _DEVDEBUG_
#include "YacsTrace.hxx"
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlreader.h>
+#include <libxml/parserInternals.h>
YACS::ENGINE::Runtime* theRuntime=0;
#define BUFFSIZE 8192
char Buff[BUFFSIZE];
extern YACS::ENGINE::Proc* currentProc;
-extern XML_Parser p ;
-
+extern _xmlParserCtxt* saxContext;
namespace YACS
{
YACSLoader::YACSLoader()
{
_defaultParsersMap.clear();
-
theRuntime = ENGINE::getRuntime();
}
ENGINE::Proc* YACSLoader::load(const char * file)
{
DEBTRACE("YACSLoader::load: " << file);
- FILE* fin=fopen(file,"r");
- if (! fin)
- {
- std::cerr << "Couldn't open schema file" << std::endl;
- throw std::invalid_argument("Couldn't open schema file");
- }
-
- p = XML_ParserCreate(NULL);
- if (! p)
- {
- std::cerr << "Couldn't allocate memory for parser" << std::endl;
- throw Exception("Couldn't allocate memory for parser");
- }
- XML_SetElementHandler(p, parser::start,parser::end);
- XML_SetCharacterDataHandler(p,parser::charac );
+ parser::main_parser.init();
+ parser::main_parser._stackParser.push(&parser::main_parser);
+ xmlSAXHandler baseHandler =
+ {
+ 0, // internal_subset,
+ 0, // isStandalone
+ 0, // hasInternalSubset
+ 0, // hasExternalSubset
+ 0, // resolveEntity
+ 0, // getEntity
+ 0, // entityDecl
+ 0, // notationDecl
+ 0, // attributeDecl
+ 0, // elementDecl
+ 0, // unparsedEntityDecl
+ 0, // setDocumentLocator
+ parser::start_document, // startDocument
+ parser::end_document, // endDocument
+ parser::start_element, // startElement
+ parser::end_element, // endElement
+ 0, // reference
+ parser::characters, // characters
+ 0, // ignorableWhitespace
+ 0, // processingInstruction
+ parser::comment, // comment
+ parser::warning, // warning
+ parser::error, // error
+ parser::fatal_error, // fatalError
+ 0, // getParameterEntity
+ parser::cdata_block, // cdataBlock
+ 0 // externalSubset
+ };
+ FILE* fin=fopen(file,"r");
+ if (! fin)
+ {
+ std::cerr << "Couldn't open schema file" << std::endl;
+ throw std::invalid_argument("Couldn't open schema file");
+ }
+
+ saxContext = xmlCreateFileParserCtxt(file);
+
+ if (!saxContext)
+ {
+ std::cerr << "Couldn't allocate memory for parser" << std::endl;
+ throw Exception("Couldn't allocate memory for parser");
+ }
+ saxContext->sax = &baseHandler;
parser::main_parser.SetUserDataAndPush(&YACS::roottypeParser::rootParser);
-
- // OCC: san -- Allow external parsers for handling of unknown elements
- // and attributes. This capability is used by YACS GUI to read
- // graph presentation data
if ( !_defaultParsersMap.empty() )
roottypeParser::rootParser.setDefaultMap(&_defaultParsersMap);
else
roottypeParser::rootParser.setDefaultMap(0);
-
- parser::main_parser._file=file;
- currentProc=0;
+ parser::main_parser._file = file;
+ currentProc = 0;
try
+ {
+ if ( xmlParseDocument(saxContext) == -1 )
{
- for (;;)
- {
- int done;
- int len;
-
- len = fread(Buff, 1, BUFFSIZE, fin);
- if (ferror(fin))
- {
- std::cerr << "Read error" << std::endl;
- throw Exception("Read error");
- }
- done = feof(fin);
-
- if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR)
- {
- if(currentProc==0)
- {
- std::cerr <<XML_ErrorString(XML_GetErrorCode(p))<<" "<<file<<" "<<XML_GetCurrentLineNumber(p)<<std::endl;
- break;
- }
- YACS::ENGINE::Logger* logger=currentProc->getLogger("parser");
- logger->fatal(XML_ErrorString(XML_GetErrorCode(p)),file,XML_GetCurrentLineNumber(p));
- break;
- }
-
- if (done)
- break;
- }
- XML_ParserFree (p);
- p=0;
- return currentProc;
+ YACS::ENGINE::Logger* logger = currentProc->getLogger("parser");
+ logger->fatal( saxContext->lastError.message, file, saxContext->input->line );
}
+ saxContext = 0;
+ return currentProc;
+ }
catch(Exception& e)
- {
- //get line number from XML parser
- YACS::ENGINE::Logger* logger=currentProc->getLogger("parser");
- logger->fatal(e.what(),file,XML_GetCurrentLineNumber(p));
- XML_ParserFree (p);
- p=0;
- return currentProc;
- }
+ {
+ YACS::ENGINE::Logger* logger = currentProc->getLogger("parser");
+ logger->fatal(e.what(), file, saxContext->input->line);
+ saxContext = 0;
+ return currentProc;
+ }
}
YACSLoader::~YACSLoader()
INCLUDE_DIRECTORIES(
${CPPUNIT_INCLUDE_DIRS}
${PTHREADS_INCLUDE_DIRS}
- ${EXPAT_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/../../bases
template <class T>
void inporttypeParser<T>::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
required("type",attr);
for (int i = 0; attr[i]; i += 2)
}
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
DEBTRACE("presetdatatypeParser::buildAttr");
required("name",attr);
required("type",attr);
template <class T>
void presettypeParser<T>::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
DEBTRACE("presettypeParser::buildAttr");
this->required("name",attr);
for (int i = 0; attr[i]; i += 2)
virtual void onEnd(const char *el,parser* child);
virtual void buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
for (int i = 0; attr[i]; i += 2)
{
if(std::string(attr[i]) == "state")
void propertytypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
required("value",attr);
for (int i = 0; attr[i]; i += 2)
void casetypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("id",attr);
for (int i = 0; attr[i]; i += 2)
{
void defaultcasetypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
for (int i = 0; attr[i]; i += 2)
{
DEBTRACE( attr[i] << "=" << attr[i + 1] )
void switchtypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
this->required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
void typetypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
required("kind",attr);
for (int i = 0; attr[i]; i += 2)
}
void seqtypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
required("content",attr);
for (int i = 0; attr[i]; i += 2)
}
void objtypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
void membertypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
required("type",attr);
for (int i = 0; attr[i]; i += 2)
}
void structtypeParser::buildAttr(const XML_Char** attr)
{
+ if (!attr)
+ return;
required("name",attr);
for (int i = 0; attr[i]; i += 2)
{
//#define _DEVDEBUG_
#include "YacsTrace.hxx"
-// --- specific part for libxml2 ----------------------------------------------
-
-#ifdef USE_LIBXML2
extern "C"
{
#include <libxml/parserInternals.h> // for xmlCreateFileParserCtxt
{
ctxt->userData = parser;
}
-#endif
-
-// --- specific part for expat ------------------------------------------------
-
-#ifdef USE_EXPAT
-XML_Parser xmlParserBase::_xmlParser;
-#endif
// --- generic part -----------------------------------------------------------
/*! callback called for significant characters inside tags: \verbatim <tag>content</tag> \endverbatim
- * or outside tags, like space or new line.
- * with expat get also the CDATA tags: \verbatim <tag>![CDATA[content]]></tag> \endverbatim
+ * or outside tags, like space or new line;
+ * get also the CDATA tags: \verbatim <tag>![CDATA[content]]></tag> \endverbatim
*/
void XMLCALL xmlParserBase::characters (void* userData,
{
}
-/*! Throws an exception. different implementation with libxml2 and expat
+/*! Throws an exception.
*/
void xmlParserBase::stopParse(std::string what)
{
-#ifdef USE_LIBXML2
xmlStopParser(_xmlParser);
-#endif
-#ifdef USE_EXPAT
- throw Exception(what);
-#endif
}
// ----------------------------------------------------------------------------
-#ifdef USE_LIBXML2
-
/*! libxml2 parser initialisation
* \param parser dedicated parser
*/
xmlParseDocument(saxContext);
_rootParser->cleanGarbage();
- xmlFileClose(saxContext);
- xmlFreeParserCtxt(saxContext);
+ if ( saxContext->myDoc != NULL ) {
+ xmlFreeDoc( saxContext->myDoc );
+ saxContext->myDoc = NULL;
+ }
+ if ( saxContext != NULL ) {
+ saxContext->sax = old_sax;
+ xmlFreeParserCtxt( saxContext );
+ }
DEBTRACE("xmlParserBase::end of parse, garbage size = " << _rootParser->getGarbageSize());
}
-#endif
-
-// ----------------------------------------------------------------------------
-
-#ifdef USE_EXPAT
-
-#define SIZEBUF 8192
-char Buffer[SIZEBUF];
-
-/*! expat parser initialisation
- * \param parser dedicated parser
- */
-
-xmlReader::xmlReader(xmlParserBase* parser): _rootParser(parser)
-{
- xmlParserBase::_xmlParser= XML_ParserCreate(NULL);
- if (! _rootParser )
- {
- cerr << "Couldn't allocate memory for parser" << endl;
- throw Exception("Couldn't allocate memory for parser");
- }
-}
-
-/*! expat parse
- * \param xmlFile file to parse
- */
-
-void xmlReader::parse(std::string xmlFile)
-{
- FILE* fin=fopen(xmlFile.c_str(),"r");
- if (! fin)
- {
- std::cerr << "Couldn't open schema file" << std::endl;
- throw std::invalid_argument("Couldn't open schema file");
- //throw Exception("Couldn't open schema file");
- }
-
- XML_SetElementHandler(xmlParserBase::_xmlParser,
- xmlParserBase::start_element,
- xmlParserBase::end_element);
- XML_SetCharacterDataHandler(xmlParserBase::_xmlParser,
- xmlParserBase::characters );
- XML_SetUserData(xmlParserBase::_xmlParser, _rootParser);
- _rootParser->init(0);
- _rootParser->_stackParser.push(_rootParser);
-
- try
- {
- for (;;)
- {
- int done;
- int len;
-
- len = fread(Buffer, 1, SIZEBUF, fin);
- if (ferror(fin))
- {
- std::cerr << "Read error" << std::endl;
- throw Exception("Read error");
- }
- done = feof(fin);
-
- if (XML_Parse(xmlParserBase::_xmlParser, Buffer, len, done) == XML_STATUS_ERROR)
- {
- throw Exception(XML_ErrorString(XML_GetErrorCode(xmlParserBase::_xmlParser)));
- }
-
- if (done)
- break;
- }
- XML_ParserFree (xmlParserBase::_xmlParser);
- xmlParserBase::_xmlParser=0;
- _rootParser->cleanGarbage();
- DEBTRACE("xmlParserBase::end of parse, garbage size = " << _rootParser->getGarbageSize());
- }
- catch(Exception& e)
- {
- _rootParser->cleanGarbage();
- //get line number from XML parser
- cerr << "Error at line: " << XML_GetCurrentLineNumber(xmlParserBase::_xmlParser) << endl;
- throw e;
- }
-}
-#endif
// ----------------------------------------------------------------------------
#define __XMLPARSERBASE_HXX_
-// --- select only one of the following packages ------------------------------
-// - libxml2 comes with gnome, so it's almost always already installed,
-// but may not not work (see below).
-// - libexpat is a less common package, but light, and works fine.
-
-// With standard installation of libxml2, C++ exception cannot be catched
-// during the parse process. This is required for normal use of yacs.
-// libxml2 must be generated with configure --with-fexceptions ...
-// (to be tested)
-// Developpement and tests are done with libexpat.
-
-//#define USE_LIBXML2
-#define USE_EXPAT
-
-// --- specific part for libxml2 ----------------------------------------------
-
-#ifdef USE_LIBXML2
extern "C"
{
#include <libxml/parser.h>
#define XMLCALL
#define XML_Char char
inline XML_Char* tochar(const xmlChar *c) { return (XML_Char*)c; };
-#endif
-
-// --- specific part for expat ------------------------------------------------
-
-#ifdef USE_EXPAT
- #include <expat.h>
-#define xmlChar XML_Char
-inline const XML_Char* tochar(const xmlChar *c) { return c; };
-#endif
-
// --- generic part -----------------------------------------------------------
std::map< std::string, int > counts;
-#ifdef USE_LIBXML2
static _xmlParserCtxt* _xmlParser;
static void XML_SetUserData(_xmlParserCtxt* ctxt,
xmlParserBase* parser);
-#endif
-
-#ifdef USE_EXPAT
- static XML_Parser _xmlParser;
-#endif
static std::stack<xmlParserBase*> _stackParser;
${PROJECT_SOURCE_DIR}/src/yacsloader
${PROJECT_BINARY_DIR}/src/engine_swig
${OMNIORB_INCLUDE_DIR}
- ${EXPAT_INCLUDE_DIR}
${PYTHON_INCLUDE_DIRS}
)