--- /dev/null
+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
-// Copyright (C) 2002, Luca Padovani <luca.padovani@cs.unibo.it>.
+// Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>.
//
// This file is part of EdiTeX, an editor of mathematical
// expressions based on TeX syntax
--- /dev/null
+*~
+*.lo
+*.o
+*.la
+.deps
+.libs
+Makefile
+Makefile.in
--- /dev/null
+
+#ifndef __ALogger_hh__
+#define __ALogger_hh__
+
+#include <string>
+
+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__
--- /dev/null
+
+
+#ifndef __AMathMLConsumer_hh__
+#define __AMathMLConsumer_hh__
+
+class AMathMLConsumer
+{
+public:
+ AMathMLConsumer(void) { };
+ virtual ~AMathMLConsumer() { };
+ virtual void documentModified(const DOM::Document&) = 0;
+};
+
+#endif // __AMathMLConsumer_hh__
--- /dev/null
+// Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>.
+//
+// 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
+// <luca.padovani@cs.unibo.it>
+
+#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__
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;
};
+// Copyright (C) 2002-2003, Luca Padovani <luca.padovani@cs.unibo.it>.
+//
+// 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
+// <luca.padovani@cs.unibo.it>
#ifndef __APushParser_hh__
#define __APushParser_hh__
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__
--- /dev/null
+
+#include <iostream>
+
+#include "CLoggerConsole.hh"
+
+void
+CLoggerConsole::message(Level l, const std::string& msg)
+{
+ const char* ls[] = { "Error", "Warning", "Info", "Debug" };
+ cerr << "*** " << ls[l] << ": " << msg << endl;
+}
--- /dev/null
+
+#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__
--- /dev/null
+
+#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<DOM::GdomeString, DOM::GdomeString> > 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;
+ }
+}
+
--- /dev/null
+
+#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__
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 \
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)
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)
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)
#include "dom.hh"
#include "TDictionary.hh"
#include "TTokenizer.hh"
+#include "CLoggerConsole.hh"
static TDictionary::Entry undefinedEntry;
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")
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);
#include "TPushLexer.hh"
#include "APushParser.hh"
-TPushLexer::TPushLexer(APushParser& p) : APushLexer(p)
+TPushLexer::TPushLexer(ALogger& l, APushParser& p) : APushLexer(l, p)
{
state = ACCEPT;
}
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;
}
}
class TPushLexer : public APushLexer
{
public:
- TPushLexer(class APushParser&);
+ TPushLexer(class ALogger&, class APushParser&);
virtual ~TPushLexer() { };
virtual void push(char);
+#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();
}
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
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;
}
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);
}
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:
};
std::stack<Frame> frames;
- //std::list<TToken> buffer;
unsigned nextId;
TDocument doc;
TNode cursor;
-
const class TDictionary& dictionary;
- class TListener* listener;
};
#endif // __TPushParser_hh__
std::vector<TToken>
TTokenizer::tokenize(const std::string& s)
{
- TPushLexer lexer(*this);
+ TPushLexer lexer(logger, *this);
tokens.clear();
for (std::string::const_iterator p = s.begin();
class TTokenizer : private APushParser
{
public:
- TTokenizer(void) { };
+ TTokenizer(class ALogger& l) : APushParser(l) { };
std::vector<TToken> tokenize(const std::string&);
private:
virtual void push(const TToken&);
- virtual void setCursor(const std::string&) { };
+ virtual void setCursorHint(const std::string&) { };
std::list<TToken> tokens;
};
#define __dom_hh__
#include <GdomeSmartDOM.hh>
+#include <GdomeSmartDOMXSLT.hh>
namespace DOM = GdomeSmartDOM;
--- /dev/null
+.deps
+.libs
+Makefile
+Makefile.in
+editor
+test
-noinst_PROGRAMS = test editor
+noinst_PROGRAMS = editor
-test_SOURCES = main.cc
editor_SOURCES = editor.cc guiGTK.c aux.cc
LDADDS = \
$(GTKMATHVIEW_LIBS) \
$(top_builddir)/src/.libs/libeditex.a
-test_LDADD = $(LDADDS)
editor_LDADD = $(LDADDS)
INCLUDES = \
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
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 =
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:
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)
-#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 <GdomeSmartDOMXSLT.hh>
+#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<GdomeNode*>(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<DOM::GdomeString, DOM::GdomeString> > 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<GdomeNode*>(result) << endl;
- et.addEventListener("DOMSubtreeModified", l1, true);
-
- if (GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(result))) < 0)
- cerr << "c'e' stato un errore" << endl;
- }
- style.save(result, stdout);
-
- doc.clearDirty();
+ if (GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(result))) < 0)
+ cerr << "c'e' stato un errore" << endl;
+ firstTime = false;
}
}
private:
- const DOM::XSLTStylesheet& style;
+ bool firstTime;
};
struct Context
void send(void)
{
- if (i < buffer.length())
- {
- cout << "document is " << static_cast<GdomeNode*>(result) << endl;
- lexer.push(buffer[i++]);
- }
+ if (i < buffer.length()) lexer.push(buffer[i++]);
else lexer.push('\n');
}
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('$');
Context context("", lexer);
- cout << "passing context " << &context << endl;
GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context);
GUI_run();
GUI_uninit();
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); */
}
}
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;
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);
}
}
+++ /dev/null
-
-#include "TNode.hh"
-#include "TToken.hh"
-#include "TDocument.hh"
-#include "TPushParser.hh"
-#include "TPushLexer.hh"
-#include "TDictionary.hh"
-#include "TListener.hh"
-#include <GdomeSmartDOMXSLT.hh>
-
-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<DOM::GdomeString, DOM::GdomeString> > 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");
-}
</m:mo>
</xsl:template>
- <xsl:template match="tml:cursor">
+ <xsl:template name="cursor">
<xsl:choose>
<xsl:when test="substring(@val,1,1)='\'">
<m:mrow>
</xsl:when>
<xsl:otherwise>
<m:mtext mathcolor="blue">
- <xsl:if test="@id">
- <xsl:attribute name="xref">
- <xsl:value-of select="@id"/>
- </xsl:attribute>
- </xsl:if>
- <xsl:value-of select="@val"/>
- </m:mtext>
+ <xsl:if test="@id">
+ <xsl:attribute name="xref">
+ <xsl:value-of select="@id"/>
+ </xsl:attribute>
+ </xsl:if>
+ I
+ </m:mtext>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template match="tml:cursor">
+ <xsl:param name="annotation" select="/.."/>
+ <xsl:choose>
+ <xsl:when test="$annotation">
+ <m:msub>
+ <xsl:call-template name="cursor"/>
+ <m:mtext>
+ <xsl:value-of select="$annotation"/>
+ </m:mtext>
+ </m:msub>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="cursor"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:template>
<xsl:template match="tml:g">
+ <xsl:param name="annotation" select="/.."/>
<xsl:choose>
<xsl:when test="not(@id) and count(*) = 1">
- <xsl:apply-templates select="*[1]"/>
+ <xsl:apply-templates select="*[1]">
+ <xsl:with-param name="annotation" select="$annotation"/>
+ </xsl:apply-templates>
</xsl:when>
<xsl:when test="tml:cursor">
<m:mstyle mathbackground="#e0e0e0">
</xsl:attribute>
</xsl:if>
<m:mrow>
- <xsl:apply-templates select="*"/>
+ <xsl:apply-templates select="*">
+ <xsl:with-param name="annotation" select="$annotation"/>
+ </xsl:apply-templates>
</m:mrow>
</m:mstyle>
</xsl:when>
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
- <xsl:apply-templates select="*"/>
+ <xsl:apply-templates select="*">
+ <xsl:with-param name="annotation" select="$annotation"/>
+ </xsl:apply-templates>
</m:mrow>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="*[1]"/>
+ <xsl:if test="tml:g/tml:cursor">
+ <m:msub>
+ <m:mtext mathcolor="#808080">}</m:mtext>
+ <m:mtext><xsl:value-of select="@name"/></m:mtext>
+ </m:msub>
+ </xsl:if>
</m:mstyle>
</xsl:template>