From 7bea7bddf7ca13260f4d3965182dc4fb58d035e7 Mon Sep 17 00:00:00 2001 From: Luca Padovani Date: Fri, 31 Jan 2003 09:13:55 +0000 Subject: [PATCH] * code cleanup * added logger class and a simple implementation on console * moved transformation code from test into a mathml factory class * added .cvsignore files --- helm/DEVEL/mathml_editor/.cvsignore | 15 ++ helm/DEVEL/mathml_editor/LICENSE | 2 +- helm/DEVEL/mathml_editor/src/.cvsignore | 8 + helm/DEVEL/mathml_editor/src/ALogger.hh | 29 ++++ .../mathml_editor/src/AMathMLConsumer.hh | 14 ++ .../DEVEL/mathml_editor/src/AMathMLFactory.hh | 44 +++++ helm/DEVEL/mathml_editor/src/APushLexer.hh | 5 +- helm/DEVEL/mathml_editor/src/APushParser.hh | 32 +++- .../DEVEL/mathml_editor/src/CLoggerConsole.cc | 11 ++ .../DEVEL/mathml_editor/src/CLoggerConsole.hh | 16 ++ .../mathml_editor/src/CMathMLFactoryXSLT.cc | 72 ++++++++ .../mathml_editor/src/CMathMLFactoryXSLT.hh | 23 +++ helm/DEVEL/mathml_editor/src/Makefile.am | 6 + helm/DEVEL/mathml_editor/src/Makefile.in | 14 +- helm/DEVEL/mathml_editor/src/TDictionary.cc | 4 +- helm/DEVEL/mathml_editor/src/TDocument.cc | 2 +- helm/DEVEL/mathml_editor/src/TPushLexer.cc | 10 +- helm/DEVEL/mathml_editor/src/TPushLexer.hh | 2 +- helm/DEVEL/mathml_editor/src/TPushParser.cc | 16 +- helm/DEVEL/mathml_editor/src/TPushParser.hh | 10 +- helm/DEVEL/mathml_editor/src/TTokenizer.cc | 2 +- helm/DEVEL/mathml_editor/src/TTokenizer.hh | 4 +- helm/DEVEL/mathml_editor/src/dom.hh | 1 + helm/DEVEL/mathml_editor/test/.cvsignore | 6 + helm/DEVEL/mathml_editor/test/Makefile.am | 4 +- helm/DEVEL/mathml_editor/test/Makefile.in | 19 +-- helm/DEVEL/mathml_editor/test/editor.cc | 157 +++-------------- helm/DEVEL/mathml_editor/test/guiGTK.c | 6 +- helm/DEVEL/mathml_editor/test/main.cc | 158 ------------------ helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl | 52 ++++-- 30 files changed, 382 insertions(+), 362 deletions(-) create mode 100644 helm/DEVEL/mathml_editor/.cvsignore create mode 100644 helm/DEVEL/mathml_editor/src/.cvsignore create mode 100644 helm/DEVEL/mathml_editor/src/ALogger.hh create mode 100644 helm/DEVEL/mathml_editor/src/AMathMLConsumer.hh create mode 100644 helm/DEVEL/mathml_editor/src/AMathMLFactory.hh create mode 100644 helm/DEVEL/mathml_editor/src/CLoggerConsole.cc create mode 100644 helm/DEVEL/mathml_editor/src/CLoggerConsole.hh create mode 100644 helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc create mode 100644 helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh create mode 100644 helm/DEVEL/mathml_editor/test/.cvsignore delete mode 100644 helm/DEVEL/mathml_editor/test/main.cc diff --git a/helm/DEVEL/mathml_editor/.cvsignore b/helm/DEVEL/mathml_editor/.cvsignore new file mode 100644 index 000000000..42bb76f78 --- /dev/null +++ b/helm/DEVEL/mathml_editor/.cvsignore @@ -0,0 +1,15 @@ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +config.h +config.h.in +config.log +config.status +configure +editex-config +libtool +result.xml +stamp-h +stamp-h.in +t1lib.log diff --git a/helm/DEVEL/mathml_editor/LICENSE b/helm/DEVEL/mathml_editor/LICENSE index f67b1308a..122827fd6 100644 --- a/helm/DEVEL/mathml_editor/LICENSE +++ b/helm/DEVEL/mathml_editor/LICENSE @@ -1,4 +1,4 @@ -// Copyright (C) 2002, Luca Padovani . +// Copyright (C) 2002-2003, Luca Padovani . // // This file is part of EdiTeX, an editor of mathematical // expressions based on TeX syntax diff --git a/helm/DEVEL/mathml_editor/src/.cvsignore b/helm/DEVEL/mathml_editor/src/.cvsignore new file mode 100644 index 000000000..87f480ef5 --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/.cvsignore @@ -0,0 +1,8 @@ +*~ +*.lo +*.o +*.la +.deps +.libs +Makefile +Makefile.in diff --git a/helm/DEVEL/mathml_editor/src/ALogger.hh b/helm/DEVEL/mathml_editor/src/ALogger.hh new file mode 100644 index 000000000..d3636f57e --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/ALogger.hh @@ -0,0 +1,29 @@ + +#ifndef __ALogger_hh__ +#define __ALogger_hh__ + +#include + +class ALogger +{ +public: + enum Level { Error, Warning, Info, Debug }; + + ALogger(void) { level = Error; } + virtual ~ALogger() { } + void debug(const std::string& msg) { if (level >= Debug) message(Debug, msg); } + void info(const std::string& msg) { if (level >= Info) message(Info, msg); } + void warning(const std::string& msg) { if (level >= Warning) message(Warning, msg); } + void error(const std::string& msg) { if (level >= Error) message(Error, msg); } + + Level verbosity(void) const { return level; } + void verbosity(Level lvl) { level = lvl; } + +protected: + virtual void message(Level, const std::string&) = 0; + +private: + Level level; +}; + +#endif // __ALogger_hh__ diff --git a/helm/DEVEL/mathml_editor/src/AMathMLConsumer.hh b/helm/DEVEL/mathml_editor/src/AMathMLConsumer.hh new file mode 100644 index 000000000..76b641742 --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/AMathMLConsumer.hh @@ -0,0 +1,14 @@ + + +#ifndef __AMathMLConsumer_hh__ +#define __AMathMLConsumer_hh__ + +class AMathMLConsumer +{ +public: + AMathMLConsumer(void) { }; + virtual ~AMathMLConsumer() { }; + virtual void documentModified(const DOM::Document&) = 0; +}; + +#endif // __AMathMLConsumer_hh__ diff --git a/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh b/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh new file mode 100644 index 000000000..a514e9453 --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh @@ -0,0 +1,44 @@ +// Copyright (C) 2002-2003, Luca Padovani . +// +// This file is part of EdiTeX, an editor of mathematical +// expressions based on TeX syntax +// +// EdiTeX 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. +// +// EdiTeX 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 EdiTeX; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// For details, see the EdiTeX World-Wide-Web page, +// http://helm.cs.unibo.it/editex, or send a mail to +// + +#ifndef __AMathMLFactory_hh__ +#define __AMathMLFactory_hh__ + +#include "dom.hh" + +class AMathMLFactory +{ +public: + AMathMLFactory(class ALogger& l) : logger(l), consumer(0) { }; + AMathMLFactory(class ALogger& l, class AMathMLConsumer& c) : logger(l), consumer(&c) { }; + virtual ~AMathMLFactory() { }; + + virtual void documentModified(class TDocument&) = 0; + virtual DOM::Document document(void) const = 0; + +protected: + class ALogger& logger; + class AMathMLConsumer* consumer; +}; + +#endif // __AMathMLFactory_hh__ diff --git a/helm/DEVEL/mathml_editor/src/APushLexer.hh b/helm/DEVEL/mathml_editor/src/APushLexer.hh index 2243426d2..4fca8cf76 100644 --- a/helm/DEVEL/mathml_editor/src/APushLexer.hh +++ b/helm/DEVEL/mathml_editor/src/APushLexer.hh @@ -5,16 +5,15 @@ class APushLexer { public: - APushLexer(class APushParser& p) : parser(p) { }; + APushLexer(class ALogger& l, class APushParser& p) : logger(l), parser(p) { }; virtual ~APushLexer() { }; virtual void push(char) = 0; virtual void reset(void) = 0; virtual bool error(void) const = 0; - //virtual void freeze(void); - //virtual void thaw(void); protected: + class ALogger& logger; class APushParser& parser; }; diff --git a/helm/DEVEL/mathml_editor/src/APushParser.hh b/helm/DEVEL/mathml_editor/src/APushParser.hh index c2978106c..c7989614e 100644 --- a/helm/DEVEL/mathml_editor/src/APushParser.hh +++ b/helm/DEVEL/mathml_editor/src/APushParser.hh @@ -1,3 +1,25 @@ +// Copyright (C) 2002-2003, Luca Padovani . +// +// This file is part of EdiTeX, an editor of mathematical +// expressions based on TeX syntax +// +// EdiTeX 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. +// +// EdiTeX 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 EdiTeX; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// For details, see the EdiTeX World-Wide-Web page, +// http://helm.cs.unibo.it/editex, or send a mail to +// #ifndef __APushParser_hh__ #define __APushParser_hh__ @@ -5,10 +27,16 @@ class APushParser { public: - APushParser(void) { }; + APushParser(class ALogger& l) : logger(l), factory(0) { }; + APushParser(class ALogger& l, class AMathMLFactory& f) : logger(l), factory(&f) { }; + virtual ~APushParser() { }; virtual void push(const TToken&) = 0; - virtual void setCursor(const std::string&) = 0; + virtual void setCursorHint(const std::string&) = 0; + +protected: + class ALogger& logger; + class AMathMLFactory* factory; }; #endif // __APushParser_hh__ diff --git a/helm/DEVEL/mathml_editor/src/CLoggerConsole.cc b/helm/DEVEL/mathml_editor/src/CLoggerConsole.cc new file mode 100644 index 000000000..194a6faf3 --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/CLoggerConsole.cc @@ -0,0 +1,11 @@ + +#include + +#include "CLoggerConsole.hh" + +void +CLoggerConsole::message(Level l, const std::string& msg) +{ + const char* ls[] = { "Error", "Warning", "Info", "Debug" }; + cerr << "*** " << ls[l] << ": " << msg << endl; +} diff --git a/helm/DEVEL/mathml_editor/src/CLoggerConsole.hh b/helm/DEVEL/mathml_editor/src/CLoggerConsole.hh new file mode 100644 index 000000000..a4da0d09b --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/CLoggerConsole.hh @@ -0,0 +1,16 @@ + +#ifndef __CLoggerConsole_hh__ +#define __CLoggerConsole_hh__ + +#include "ALogger.hh" + +class CLoggerConsole : public ALogger +{ +public: + CLoggerConsole(void) { }; + +protected: + virtual void message(Level, const std::string&); +}; + +#endif // __CLoggerConsole_hh__ diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc new file mode 100644 index 000000000..244d3640b --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc @@ -0,0 +1,72 @@ + +#include "dom.hh" +#include "TNode.hh" +#include "TDocument.hh" +#include "CMathMLFactoryXSLT.hh" +#include "AMathMLConsumer.hh" + +void +CMathMLFactoryXSLT::documentModified(TDocument& doc) +{ + if (TNode dirty = doc.dirtyNode()) + { + std::vector< std::pair > dirtyId; + if (result) + dirtyId.push_back(std::make_pair(DOM::GdomeString("id"), + DOM::GdomeString("'" + std::string(dirty["id"]) + "'"))); + DOM::Document res = style.apply(doc.document(), dirtyId); + assert(res); + //style.save(doc.document(), stdout); + //style.save(res, stdout); + if (result) + { + DOM::Element root = res.get_documentElement(); + assert(root); + assert(root.hasAttribute("xref")); + + try + { + bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); + assert(ok); + } + catch (DOM::DOMException& e) + { + cout << "!!!!!!!!!!!!!!!! EXCEPTION " << e.code << " " << e.msg << endl; + assert(0); + } + } + else + result = res; + + doc.clearDirty(); + + if (consumer) consumer->documentModified(result); + } +} + +bool +CMathMLFactoryXSLT::subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2) +{ + assert(e1); + assert(e2); + if (e1.getAttribute("xref") == id) + { + DOM::Node parent = e1.get_parentNode(); + assert(parent); + parent.replaceChild(e2, e1); + return true; + } + else + { + DOM::Node p = e1.get_firstChild(); + while (p) + { + while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling(); + if (p) + if (subst(p, id, e2)) return true; + else p = p.get_nextSibling(); + } + return false; + } +} + diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh new file mode 100644 index 000000000..70998e092 --- /dev/null +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh @@ -0,0 +1,23 @@ + +#ifndef __CMathMLFactoryXSLT_hh__ +#define __CMathMLFactoryXSLT_hh__ + +#include "AMathMLFactory.hh" + +class CMathMLFactoryXSLT : public AMathMLFactory +{ +public: + CMathMLFactoryXSLT(class ALogger& l, const DOM::XSLTStylesheet& s) : AMathMLFactory(l), style(s) { }; + CMathMLFactoryXSLT(class ALogger& l, class AMathMLConsumer& c, const DOM::XSLTStylesheet& s) : AMathMLFactory(l, c), style(s) { }; + + virtual void documentModified(class TDocument&); + virtual DOM::Document document(void) const { return result; }; + +private: + static bool subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2); + + const DOM::XSLTStylesheet& style; + DOM::Document result; +}; + +#endif // __CMathMLFactoryXSLT_hh__ diff --git a/helm/DEVEL/mathml_editor/src/Makefile.am b/helm/DEVEL/mathml_editor/src/Makefile.am index f440e528c..c0afe28ee 100644 --- a/helm/DEVEL/mathml_editor/src/Makefile.am +++ b/helm/DEVEL/mathml_editor/src/Makefile.am @@ -4,16 +4,22 @@ lib_LTLIBRARIES = libeditex.la libeditex_la_LDFLAGS = -version-info @EDITEX_VERSION_INFO@ libeditex_la_SOURCES = \ + CLoggerConsole.cc \ TPushLexer.cc \ TPushParser.cc \ + CMathMLFactoryXSLT.cc \ TDictionary.cc \ TDocument.cc \ TNode.cc \ TTokenizer.cc pkginclude_HEADERS = \ + ALogger.hh \ + CLoggerConsole.hh \ APushLexer.hh \ APushParser.hh \ + AMathMLFactory.hh \ + CMathMLFactoryXSLT.hh \ TPushLexer.hh \ TPushParser.hh \ TTokenizer.hh \ diff --git a/helm/DEVEL/mathml_editor/src/Makefile.in b/helm/DEVEL/mathml_editor/src/Makefile.in index b614c8f92..0592ae444 100644 --- a/helm/DEVEL/mathml_editor/src/Makefile.in +++ b/helm/DEVEL/mathml_editor/src/Makefile.in @@ -89,10 +89,10 @@ lib_LTLIBRARIES = libeditex.la libeditex_la_LDFLAGS = -version-info @EDITEX_VERSION_INFO@ -libeditex_la_SOURCES = TPushLexer.cc TPushParser.cc TDictionary.cc TDocument.cc TNode.cc TTokenizer.cc +libeditex_la_SOURCES = CLoggerConsole.cc TPushLexer.cc TPushParser.cc CMathMLFactoryXSLT.cc TDictionary.cc TDocument.cc TNode.cc TTokenizer.cc -pkginclude_HEADERS = APushLexer.hh APushParser.hh TPushLexer.hh TPushParser.hh TTokenizer.hh TDictionary.hh TDocument.hh TNode.hh TListener.hh dom.hh +pkginclude_HEADERS = ALogger.hh CLoggerConsole.hh APushLexer.hh APushParser.hh AMathMLFactory.hh CMathMLFactoryXSLT.hh TPushLexer.hh TPushParser.hh TTokenizer.hh TDictionary.hh TDocument.hh TNode.hh TListener.hh dom.hh INCLUDES = $(GMETADOM_CFLAGS) $(GDOMEXSLT_CFLAGS) @@ -105,8 +105,9 @@ LTLIBRARIES = $(lib_LTLIBRARIES) DEFS = @DEFS@ -I. -I$(srcdir) -I.. LIBS = @LIBS@ libeditex_la_LIBADD = -libeditex_la_OBJECTS = TPushLexer.lo TPushParser.lo TDictionary.lo \ -TDocument.lo TNode.lo TTokenizer.lo +libeditex_la_OBJECTS = CLoggerConsole.lo TPushLexer.lo TPushParser.lo \ +CMathMLFactoryXSLT.lo TDictionary.lo TDocument.lo TNode.lo \ +TTokenizer.lo CXXFLAGS = @CXXFLAGS@ CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) @@ -121,8 +122,9 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best -DEP_FILES = .deps/TDictionary.P .deps/TDocument.P .deps/TNode.P \ -.deps/TPushLexer.P .deps/TPushParser.P .deps/TTokenizer.P +DEP_FILES = .deps/CLoggerConsole.P .deps/CMathMLFactoryXSLT.P \ +.deps/TDictionary.P .deps/TDocument.P .deps/TNode.P .deps/TPushLexer.P \ +.deps/TPushParser.P .deps/TTokenizer.P SOURCES = $(libeditex_la_SOURCES) OBJECTS = $(libeditex_la_OBJECTS) diff --git a/helm/DEVEL/mathml_editor/src/TDictionary.cc b/helm/DEVEL/mathml_editor/src/TDictionary.cc index dcaf1d627..8c16d2ba9 100644 --- a/helm/DEVEL/mathml_editor/src/TDictionary.cc +++ b/helm/DEVEL/mathml_editor/src/TDictionary.cc @@ -4,6 +4,7 @@ #include "dom.hh" #include "TDictionary.hh" #include "TTokenizer.hh" +#include "CLoggerConsole.hh" static TDictionary::Entry undefinedEntry; @@ -18,7 +19,8 @@ TDictionary::load(const char* uri) DOM::Element root = doc.get_documentElement(); assert(root); - TTokenizer tokenizer; + CLoggerConsole logger; + TTokenizer tokenizer(logger); for (DOM::Node p = root.get_firstChild(); p; p = p.get_nextSibling()) if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "entry") diff --git a/helm/DEVEL/mathml_editor/src/TDocument.cc b/helm/DEVEL/mathml_editor/src/TDocument.cc index 4c3bbbaea..a7b5c8d3a 100644 --- a/helm/DEVEL/mathml_editor/src/TDocument.cc +++ b/helm/DEVEL/mathml_editor/src/TDocument.cc @@ -11,8 +11,8 @@ TDocument::TDocument() DOM::DocumentType dt; doc = di.createDocument(TML_NS_URI, "tml:tex", dt); DOM::Element root = doc.get_documentElement(); - root.setAttributeNS(XMLNS_NS_URI, "xmlns:tml", TML_NS_URI); assert(root); + root.setAttributeNS(XMLNS_NS_URI, "xmlns:tml", TML_NS_URI); DOM::EventTarget et(doc); assert(et); diff --git a/helm/DEVEL/mathml_editor/src/TPushLexer.cc b/helm/DEVEL/mathml_editor/src/TPushLexer.cc index 466ee2bd8..1d25abbe9 100644 --- a/helm/DEVEL/mathml_editor/src/TPushLexer.cc +++ b/helm/DEVEL/mathml_editor/src/TPushLexer.cc @@ -3,7 +3,7 @@ #include "TPushLexer.hh" #include "APushParser.hh" -TPushLexer::TPushLexer(APushParser& p) : APushLexer(p) +TPushLexer::TPushLexer(ALogger& l, APushParser& p) : APushLexer(l, p) { state = ACCEPT; } @@ -133,10 +133,10 @@ TPushLexer::push(char ch) switch (state) { - case ESCAPE: parser.setCursor("\\"); break; - case MACRO: parser.setCursor("\\" + buffer); break; - case PARAMETER: parser.setCursor("#"); break; - default: parser.setCursor("?"); break; + case ESCAPE: parser.setCursorHint("\\"); break; + case MACRO: parser.setCursorHint("\\" + buffer); break; + case PARAMETER: parser.setCursorHint("#"); break; + default: parser.setCursorHint(""); break; } } diff --git a/helm/DEVEL/mathml_editor/src/TPushLexer.hh b/helm/DEVEL/mathml_editor/src/TPushLexer.hh index 6fd212a3d..a12a9bf63 100644 --- a/helm/DEVEL/mathml_editor/src/TPushLexer.hh +++ b/helm/DEVEL/mathml_editor/src/TPushLexer.hh @@ -9,7 +9,7 @@ class TPushLexer : public APushLexer { public: - TPushLexer(class APushParser&); + TPushLexer(class ALogger&, class APushParser&); virtual ~TPushLexer() { }; virtual void push(char); diff --git a/helm/DEVEL/mathml_editor/src/TPushParser.cc b/helm/DEVEL/mathml_editor/src/TPushParser.cc index d3dd893d7..325b9aa3c 100644 --- a/helm/DEVEL/mathml_editor/src/TPushParser.cc +++ b/helm/DEVEL/mathml_editor/src/TPushParser.cc @@ -1,13 +1,14 @@ +#include "ALogger.hh" #include "TPushParser.hh" -#include "TListener.hh" +#include "AMathMLFactory.hh" -TPushParser::TPushParser(const TDictionary& d) : dictionary(d), listener(0) +TPushParser::TPushParser(ALogger& l, const TDictionary& d) : APushParser(l), dictionary(d) { init(); } -TPushParser::TPushParser(const TDictionary& d, TListener& l) : dictionary(d), listener(&l) +TPushParser::TPushParser(ALogger& l, AMathMLFactory& f, const TDictionary& d) : APushParser(l, f), dictionary(d) { init(); } @@ -1178,7 +1179,7 @@ TPushParser::push(const TToken& token) cout << "ignored token" << endl; } - if (listener) listener->callback(doc); //it shoul be repristened if you remove the comment in the else above + //if (listener) listener->callback(doc); //it shoul be repristened if you remove the comment in the else above } // this end corresponds to the if ((doc.root().first() && doc.root().first().is("math")) || token.category == TToken::SHIFT) else @@ -1188,8 +1189,7 @@ TPushParser::push(const TToken& token) cout << "push: ignored token...you have to enter in math mode...insert $" << endl; } - - //if (listener) listener->callback(doc); + if (factory) factory->documentModified(doc); if (frames.empty()) cout << "stack vuoto" << endl; else cout << "stack non vuoto" << endl; @@ -1231,8 +1231,8 @@ TPushParser::advance(const TNode& node) } void -TPushParser::setCursor(const std::string& c) +TPushParser::setCursorHint(const std::string& c) { cursor["val"] = c; - if (listener) listener->callback(doc); + if (factory) factory->documentModified(doc); } diff --git a/helm/DEVEL/mathml_editor/src/TPushParser.hh b/helm/DEVEL/mathml_editor/src/TPushParser.hh index 951fb874a..09bfe713d 100644 --- a/helm/DEVEL/mathml_editor/src/TPushParser.hh +++ b/helm/DEVEL/mathml_editor/src/TPushParser.hh @@ -13,13 +13,14 @@ class TPushParser : public APushParser { public: - TPushParser(const class TDictionary&); - TPushParser(const class TDictionary&, class TListener&); + TPushParser(class ALogger&, const class TDictionary&); + TPushParser(class ALogger&, class AMathMLFactory&, const class TDictionary&); virtual ~TPushParser(); virtual void push(const TToken&); - virtual void setCursor(const std::string&); + virtual void setCursorHint(const std::string&); +protected: TDocument document(void) const { return doc; } private: @@ -61,13 +62,10 @@ private: }; std::stack frames; - //std::list buffer; unsigned nextId; TDocument doc; TNode cursor; - const class TDictionary& dictionary; - class TListener* listener; }; #endif // __TPushParser_hh__ diff --git a/helm/DEVEL/mathml_editor/src/TTokenizer.cc b/helm/DEVEL/mathml_editor/src/TTokenizer.cc index 93cadefd7..cfa10ec71 100644 --- a/helm/DEVEL/mathml_editor/src/TTokenizer.cc +++ b/helm/DEVEL/mathml_editor/src/TTokenizer.cc @@ -7,7 +7,7 @@ std::vector TTokenizer::tokenize(const std::string& s) { - TPushLexer lexer(*this); + TPushLexer lexer(logger, *this); tokens.clear(); for (std::string::const_iterator p = s.begin(); diff --git a/helm/DEVEL/mathml_editor/src/TTokenizer.hh b/helm/DEVEL/mathml_editor/src/TTokenizer.hh index d0a54bf28..54618c88b 100644 --- a/helm/DEVEL/mathml_editor/src/TTokenizer.hh +++ b/helm/DEVEL/mathml_editor/src/TTokenizer.hh @@ -12,13 +12,13 @@ class TTokenizer : private APushParser { public: - TTokenizer(void) { }; + TTokenizer(class ALogger& l) : APushParser(l) { }; std::vector tokenize(const std::string&); private: virtual void push(const TToken&); - virtual void setCursor(const std::string&) { }; + virtual void setCursorHint(const std::string&) { }; std::list tokens; }; diff --git a/helm/DEVEL/mathml_editor/src/dom.hh b/helm/DEVEL/mathml_editor/src/dom.hh index f2c42dba0..a2058302e 100644 --- a/helm/DEVEL/mathml_editor/src/dom.hh +++ b/helm/DEVEL/mathml_editor/src/dom.hh @@ -3,6 +3,7 @@ #define __dom_hh__ #include +#include namespace DOM = GdomeSmartDOM; diff --git a/helm/DEVEL/mathml_editor/test/.cvsignore b/helm/DEVEL/mathml_editor/test/.cvsignore new file mode 100644 index 000000000..6a37f8d48 --- /dev/null +++ b/helm/DEVEL/mathml_editor/test/.cvsignore @@ -0,0 +1,6 @@ +.deps +.libs +Makefile +Makefile.in +editor +test diff --git a/helm/DEVEL/mathml_editor/test/Makefile.am b/helm/DEVEL/mathml_editor/test/Makefile.am index 24ebd7c42..a1fef0cf0 100644 --- a/helm/DEVEL/mathml_editor/test/Makefile.am +++ b/helm/DEVEL/mathml_editor/test/Makefile.am @@ -1,7 +1,6 @@ -noinst_PROGRAMS = test editor +noinst_PROGRAMS = editor -test_SOURCES = main.cc editor_SOURCES = editor.cc guiGTK.c aux.cc LDADDS = \ @@ -10,7 +9,6 @@ LDADDS = \ $(GTKMATHVIEW_LIBS) \ $(top_builddir)/src/.libs/libeditex.a -test_LDADD = $(LDADDS) editor_LDADD = $(LDADDS) INCLUDES = \ diff --git a/helm/DEVEL/mathml_editor/test/Makefile.in b/helm/DEVEL/mathml_editor/test/Makefile.in index 3c69a2a1c..2bf438dc5 100644 --- a/helm/DEVEL/mathml_editor/test/Makefile.in +++ b/helm/DEVEL/mathml_editor/test/Makefile.in @@ -85,15 +85,13 @@ RANLIB = @RANLIB@ STRIP = @STRIP@ VERSION = @VERSION@ -noinst_PROGRAMS = test editor +noinst_PROGRAMS = editor -test_SOURCES = main.cc editor_SOURCES = editor.cc guiGTK.c aux.cc LDADDS = $(GMETADOM_LIBS) $(GDOMEXSLT_LIBS) $(GTKMATHVIEW_LIBS) $(top_builddir)/src/.libs/libeditex.a -test_LDADD = $(LDADDS) editor_LDADD = $(LDADDS) INCLUDES = $(GMETADOM_CFLAGS) $(GDOMEXSLT_CFLAGS) $(GTKMATHVIEW_CFLAGS) -I$(top_srcdir)/src @@ -101,15 +99,12 @@ INCLUDES = $(GMETADOM_CFLAGS) $(GDOMEXSLT_CFLAGS) $(GTKMATHVIEW_CFLAGS) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = -noinst_PROGRAMS = test$(EXEEXT) editor$(EXEEXT) +noinst_PROGRAMS = editor$(EXEEXT) PROGRAMS = $(noinst_PROGRAMS) DEFS = @DEFS@ -I. -I$(srcdir) -I.. LIBS = @LIBS@ -test_OBJECTS = main.$(OBJEXT) -test_DEPENDENCIES = $(top_builddir)/src/.libs/libeditex.a -test_LDFLAGS = editor_OBJECTS = editor.$(OBJEXT) guiGTK.$(OBJEXT) aux.$(OBJEXT) editor_DEPENDENCIES = $(top_builddir)/src/.libs/libeditex.a editor_LDFLAGS = @@ -129,9 +124,9 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = tar GZIP_ENV = --best -DEP_FILES = .deps/aux.P .deps/editor.P .deps/guiGTK.P .deps/main.P -SOURCES = $(test_SOURCES) $(editor_SOURCES) -OBJECTS = $(test_OBJECTS) $(editor_OBJECTS) +DEP_FILES = .deps/aux.P .deps/editor.P .deps/guiGTK.P +SOURCES = $(editor_SOURCES) +OBJECTS = $(editor_OBJECTS) all: all-redirect .SUFFIXES: @@ -191,10 +186,6 @@ distclean-libtool: maintainer-clean-libtool: -test$(EXEEXT): $(test_OBJECTS) $(test_DEPENDENCIES) - @rm -f test$(EXEEXT) - $(CXXLINK) $(test_LDFLAGS) $(test_OBJECTS) $(test_LDADD) $(LIBS) - editor$(EXEEXT): $(editor_OBJECTS) $(editor_DEPENDENCIES) @rm -f editor$(EXEEXT) $(CXXLINK) $(editor_LDFLAGS) $(editor_OBJECTS) $(editor_LDADD) $(LIBS) diff --git a/helm/DEVEL/mathml_editor/test/editor.cc b/helm/DEVEL/mathml_editor/test/editor.cc index e12700e3a..9d548289c 100644 --- a/helm/DEVEL/mathml_editor/test/editor.cc +++ b/helm/DEVEL/mathml_editor/test/editor.cc @@ -1,147 +1,35 @@ -#include "TNode.hh" -#include "TToken.hh" -#include "TDocument.hh" +#include "dom.hh" #include "TPushParser.hh" #include "TPushLexer.hh" #include "TDictionary.hh" -#include "TListener.hh" -#include +#include "CLoggerConsole.hh" +#include "CMathMLFactoryXSLT.hh" +#include "AMathMLConsumer.hh" #include "guiGTK.h" -class MyResultListener : public DOM::EventListener -{ -public: - MyResultListener(const std::string& s) : msg(s) { }; - - virtual void handleEvent(const DOM::Event&); - -private: - const std::string msg; -}; - -void -MyResultListener::handleEvent(const DOM::Event& ev) -{ - cout << "RECEIVED EVENT: " << ev.get_type() << " " << msg << " "; - const DOM::MutationEvent& me(ev); - assert(me); - const DOM::Node target(me.get_target()); - assert(target); - cout << "target = " << target.get_nodeName() << " " << target.get_nodeType() << endl; -} - -MyResultListener l1("?"); - TDictionary dictionary; -DOM::Document result; extern void *parseMathMLFile(char *); -bool -subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2) -{ - assert(e1); - assert(e2); - if (e1.getAttribute("xref") == id) - { - DOM::Node parent = e1.get_parentNode(); - assert(parent); - DOM::Node next = e1.get_nextSibling(); - parent.removeChild(e1); - parent.insertBefore(e2, next); - //parent.replaceChild(e2, e1); - return true; - } - else - { - DOM::Node p = e1.get_firstChild(); - while (p) - { - while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling(); - if (p) - if (subst(p, id, e2)) return true; - else p = p.get_nextSibling(); - } - return false; - } -} - -class MyListener : public TListener +class CMathMLConsumer : public AMathMLConsumer { public: - MyListener(const DOM::XSLTStylesheet& s) : style(s) { }; + CMathMLConsumer(void) { firstTime = true; }; - void callback(TDocument& doc) + virtual void documentModified(const DOM::Document& result) { - cout << "listener callback " << static_cast(doc.document()) << endl; - TNode dirty = doc.dirtyNode(); - if (dirty) + if (firstTime) { - cout << "recreating subtree with id " << std::string(dirty["id"]) << endl; - std::vector< std::pair > dirtyId; - if (result) - dirtyId.push_back(std::make_pair(DOM::GdomeString("id"), - DOM::GdomeString("'" + std::string(dirty["id"]) + "'"))); - - DOM::Document res = style.apply(doc.document(), dirtyId); - assert(res); - style.save(doc.document(), stdout); - //style.save(res, stdout); - if (result) - { - cout << "REPLACING A FRAGMENT OF THE DOCUMENT" << endl; - DOM::Element root = res.get_documentElement(); - assert(root); - assert(root.hasAttribute("xref")); - - if (result.get_documentElement().getAttribute("xref") == root.getAttribute("xref")) - { - cout << "REPLACING ROOT" << endl; - result.replaceChild(result.importNode(root, true), result.get_documentElement()); -#if 0 - // the following remove should not be necessary - // according to the spec replaceChild should work just fine - result.removeChild(result.get_documentElement()); - result.appendChild(result.importNode(root, true)); -#endif - } - else - try - { - cout << "before" << endl; - bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); - assert(ok); - cout << "after" << endl; - } - catch (DOM::DOMException e) - { - cout << "!!!!!!!!!!!!!!!! EXCEPTION " << e.code << " " << e.msg << endl; - assert(0); - } - } - else - { - cout << "SETTING THE DOCUMENT FOR THE FIRST TIME" << endl; - result = res; - - DOM::EventTarget et(result); - assert(et); - cout << "SETTING EVENT LISTENER (EDITOR) ON " << static_cast(result) << endl; - et.addEventListener("DOMSubtreeModified", l1, true); - - if (GUI_load_document(gdome_cast_doc(static_cast(result))) < 0) - cerr << "c'e' stato un errore" << endl; - } - style.save(result, stdout); - - doc.clearDirty(); + if (GUI_load_document(gdome_cast_doc(static_cast(result))) < 0) + cerr << "c'e' stato un errore" << endl; + firstTime = false; } } private: - const DOM::XSLTStylesheet& style; + bool firstTime; }; struct Context @@ -150,11 +38,7 @@ struct Context void send(void) { - if (i < buffer.length()) - { - cout << "document is " << static_cast(result) << endl; - lexer.push(buffer[i++]); - } + if (i < buffer.length()) lexer.push(buffer[i++]); else lexer.push('\n'); } @@ -184,17 +68,19 @@ push_char(Context* context, gchar ch) main(int argc, char* argv[]) { - cout << "loading the dictionary..." << endl; + CLoggerConsole logger; + logger.info("loading the dictionary..."); dictionary.load("dictionary.xml"); - cout << "loading the stylesheet..." << endl; + logger.info("loading the stylesheet..."); DOM::DOMImplementation di; DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl"); DOM::XSLTStylesheet style(docStyle); - - MyListener listener(style); - TPushParser parser(dictionary, listener); - TPushLexer lexer(parser); + + CMathMLConsumer consumer; + CMathMLFactoryXSLT factory(logger, consumer, style); + TPushParser parser(logger, factory, dictionary); + TPushLexer lexer(logger, parser); #if 0 lexer.push('$'); @@ -211,7 +97,6 @@ main(int argc, char* argv[]) Context context("", lexer); - cout << "passing context " << &context << endl; GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context); GUI_run(); GUI_uninit(); diff --git a/helm/DEVEL/mathml_editor/test/guiGTK.c b/helm/DEVEL/mathml_editor/test/guiGTK.c index 88b85f8b5..cd1c7c878 100644 --- a/helm/DEVEL/mathml_editor/test/guiGTK.c +++ b/helm/DEVEL/mathml_editor/test/guiGTK.c @@ -340,7 +340,7 @@ selection_parent(GtkWidget* widget, gpointer data) gdome_el_unref(root_selected, &exc); g_assert(exc == 0); root_selected = parent; - gtk_math_view_set_selection(GTK_MATH_VIEW(main_area), root_selected); + /* gtk_math_view_set_selection(GTK_MATH_VIEW(main_area), root_selected); */ } } @@ -350,7 +350,7 @@ selection_reset(GtkWidget* widget, gpointer data) if (root_selected != NULL) { GdomeException exc = 0; - gtk_math_view_reset_selection(GTK_MATH_VIEW(main_area), root_selected); + /* gtk_math_view_reset_selection(GTK_MATH_VIEW(main_area), root_selected); */ gdome_el_unref(root_selected, &exc); g_assert(exc == 0); root_selected = NULL; @@ -481,7 +481,7 @@ selection_changed(GtkMathView* math_view, GdomeElement* first, GdomeElement* las root_selected = find_common_ancestor(first, last); /* printf("selecting root %p\n", first, last, root_selected); */ - gtk_math_view_set_selection(math_view, root_selected); + /* gtk_math_view_set_selection(math_view, root_selected); */ g_assert(exc == 0); } } diff --git a/helm/DEVEL/mathml_editor/test/main.cc b/helm/DEVEL/mathml_editor/test/main.cc deleted file mode 100644 index 3122d529b..000000000 --- a/helm/DEVEL/mathml_editor/test/main.cc +++ /dev/null @@ -1,158 +0,0 @@ - -#include "TNode.hh" -#include "TToken.hh" -#include "TDocument.hh" -#include "TPushParser.hh" -#include "TPushLexer.hh" -#include "TDictionary.hh" -#include "TListener.hh" -#include - -TDictionary dictionary; -DOM::Document result; - -bool -subst(const DOM::Element& e1, const DOM::GdomeString& id, const DOM::Element& e2) -{ - assert(e1); - assert(e2); - if (e1.getAttribute("xref") == id) - { - DOM::Node parent = e1.get_parentNode(); - assert(parent); - parent.replaceChild(e2, e1); - return true; - } - else - { - DOM::Node p = e1.get_firstChild(); - while (p) - { - while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling(); - if (p) - if (subst(p, id, e2)) return true; - else p = p.get_nextSibling(); - } - return false; - } -} - -#if 0 -bool -subst(const DOM::Node& parent, const DOM::GdomeString& id, const DOM::Element& newElem) -{ - assert(parent); - assert(newElem); - - DOM::Node p = parent.get_firstChild(); - while (p) - { - while (p && p.get_nodeType() != DOM::Node::ELEMENT_NODE) p = p.get_nextSibling(); - if (p) - { - DOM::Element el = p; - assert(el); - if (el.getAttribute("xref") == id) - { - parent.replaceChild(el, newElem); - return true; - } - else if (subst(el, id, newElem)) - return true; - else - p = p.get_nextSibling(); - } - } - - return false; -} -#endif - -class MyListener : public TListener -{ -public: - MyListener(const DOM::XSLTStylesheet& s) : style(s) { }; - - void callback(TDocument& doc) - { - TNode dirty = doc.dirtyNode(); - if (dirty) - { - cout << "recreating subtree with id " << std::string(dirty["id"]) << endl; - std::vector< std::pair > dirtyId; - if (result) - dirtyId.push_back(std::make_pair(DOM::GdomeString("id"), - DOM::GdomeString("'" + std::string(dirty["id"]) + "'"))); - DOM::Document res = style.apply(doc.document(), dirtyId); - assert(res); - style.save(res, stdout); - if (result) - { - DOM::Element root = res.get_documentElement(); - assert(root); - assert(root.hasAttribute("xref")); - - if (result.get_documentElement().getAttribute("xref") == root.getAttribute("xref")) - { - // the following remove should not be necessary - // according to the spec replaceChild should work just fine - result.removeChild(result.get_documentElement()); - result.appendChild(result.importNode(root, true)); - } - else - try - { - cout << "before" << endl; - bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); - assert(ok); - cout << "after" << endl; - } - catch (DOM::DOMException e) - { - cerr << "exception " << e.code << " " << e.msg << endl; - assert(0); - } - } - else - result = res; - - doc.clearDirty(); - } - } - -private: - const DOM::XSLTStylesheet& style; -}; - -main(int argc, char* argv[]) -{ - if (argc != 2) - { - cerr << "specify a string, please" << endl; - return -1; - } - - cout << "loading the dictionary..." << endl; - dictionary.load("dictionary.xml"); - - cout << "loading the stylesheet..." << endl; - DOM::DOMImplementation di; - DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl"); - DOM::XSLTStylesheet style(docStyle); - - MyListener listener(style); - TPushParser parser(dictionary, listener); - TPushLexer lexer(parser); - - std::string s = argv[1]; - for (unsigned long i = 0; i < s.length(); i++) - lexer.push(s[i]); - lexer.push('\n'); - - cout << "finished" << endl; - di.saveDocumentToFile(result, "result.xml", GDOME_SAVE_LIBXML_INDENT); - - cout << "done" << endl; - - parser.document().serialize("output.xml"); -} diff --git a/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl b/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl index 034c5073a..9054b9c99 100644 --- a/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl +++ b/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl @@ -68,7 +68,7 @@ - + @@ -84,13 +84,30 @@ - - - - - - - + + + + + + I + + + + + + + + + + + + + + + + + + @@ -196,9 +213,12 @@ + - + + + @@ -208,7 +228,9 @@ - + + + @@ -219,7 +241,9 @@ - + + + @@ -669,6 +693,12 @@ + + + } + + + -- 2.39.2