From 8d15b9f68470945a45ce96dbc1c892742c85cb9c Mon Sep 17 00:00:00 2001 From: Luca Padovani Date: Thu, 13 Feb 2003 12:40:34 +0000 Subject: [PATCH] * added show/hide cursro methods * some code cleanup * fix in reset * fix in get_tex (binding ocaml) * added tex to mml translator --- helm/DEVEL/mathml_editor/Makefile.am | 2 +- helm/DEVEL/mathml_editor/Makefile.in | 2 +- helm/DEVEL/mathml_editor/TML.dtd | 5 +- helm/DEVEL/mathml_editor/configure.ac | 2 + helm/DEVEL/mathml_editor/dictionary-tex.xml | 5 - .../mathml_editor/ocaml/c_mathml_editor.cc | 20 ++- .../mathml_editor/ocaml/c_mathml_editor.h | 2 + .../mathml_editor/ocaml/i_mathml_editor.ml | 6 + .../mathml_editor/ocaml/mathml_editor.ml | 6 + .../mathml_editor/ocaml/ml_mathml_editor.c | 16 ++ .../DEVEL/mathml_editor/src/AMathMLFactory.hh | 1 - helm/DEVEL/mathml_editor/src/APushParser.cc | 6 - helm/DEVEL/mathml_editor/src/APushParser.hh | 4 +- .../mathml_editor/src/CMathMLFactoryXSLT.cc | 51 +++--- .../mathml_editor/src/CMathMLFactoryXSLT.hh | 1 - .../src/CMathMLFactoryXSLTDiff.cc | 55 ++---- .../src/CMathMLFactoryXSLTDiff.hh | 1 - helm/DEVEL/mathml_editor/src/LPushLexer.hh | 2 +- helm/DEVEL/mathml_editor/src/TDocument.cc | 16 +- helm/DEVEL/mathml_editor/src/TDocument.hh | 1 + helm/DEVEL/mathml_editor/src/TPushParser.cc | 47 ++++- helm/DEVEL/mathml_editor/src/TPushParser.hh | 5 + helm/DEVEL/mathml_editor/src/TTokenizer.cc | 6 + helm/DEVEL/mathml_editor/src/TTokenizer.hh | 3 + helm/DEVEL/mathml_editor/test/.cvsignore | 1 - helm/DEVEL/mathml_editor/test/editor.cc | 38 +++- helm/DEVEL/mathml_editor/test/guiGTK.c | 18 ++ helm/DEVEL/mathml_editor/textomml/.cvsignore | 6 + helm/DEVEL/mathml_editor/textomml/Makefile.am | 17 ++ .../mathml_editor/textomml/config.dirs.in | 1 + helm/DEVEL/mathml_editor/textomml/main.cc | 168 ++++++++++++++++++ helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl | 7 +- helm/DEVEL/mathml_editor/xsl/tml-tex.xsl | 8 +- 33 files changed, 424 insertions(+), 105 deletions(-) create mode 100644 helm/DEVEL/mathml_editor/textomml/.cvsignore create mode 100644 helm/DEVEL/mathml_editor/textomml/Makefile.am create mode 100644 helm/DEVEL/mathml_editor/textomml/config.dirs.in create mode 100644 helm/DEVEL/mathml_editor/textomml/main.cc diff --git a/helm/DEVEL/mathml_editor/Makefile.am b/helm/DEVEL/mathml_editor/Makefile.am index 8f4639ebf..20f515335 100644 --- a/helm/DEVEL/mathml_editor/Makefile.am +++ b/helm/DEVEL/mathml_editor/Makefile.am @@ -1,5 +1,5 @@ #EXTRA_DIST = BUGS HISTORY LICENSE aclocal.m4 debian/ -SUBDIRS = src test ocaml +SUBDIRS = src test ocaml textomml CLEANFILES = core bin_SCRIPTS = editex-config diff --git a/helm/DEVEL/mathml_editor/Makefile.in b/helm/DEVEL/mathml_editor/Makefile.in index fdf08ab3e..cdb115fcd 100644 --- a/helm/DEVEL/mathml_editor/Makefile.in +++ b/helm/DEVEL/mathml_editor/Makefile.in @@ -101,7 +101,7 @@ RANLIB = @RANLIB@ STRIP = @STRIP@ VERSION = @VERSION@ -SUBDIRS = src test ocaml +SUBDIRS = src test ocaml textomml CLEANFILES = core bin_SCRIPTS = editex-config diff --git a/helm/DEVEL/mathml_editor/TML.dtd b/helm/DEVEL/mathml_editor/TML.dtd index a808c5ba7..dcff7abad 100644 --- a/helm/DEVEL/mathml_editor/TML.dtd +++ b/helm/DEVEL/mathml_editor/TML.dtd @@ -54,5 +54,8 @@ left-open (0|1) #IMPLIED> - + diff --git a/helm/DEVEL/mathml_editor/configure.ac b/helm/DEVEL/mathml_editor/configure.ac index dd7b07b7b..be109d69c 100644 --- a/helm/DEVEL/mathml_editor/configure.ac +++ b/helm/DEVEL/mathml_editor/configure.ac @@ -240,6 +240,8 @@ AC_CONFIG_FILES([ Makefile src/Makefile test/Makefile + textomml/Makefile + textomml/config.dirs ocaml/Makefile editex-config ]) diff --git a/helm/DEVEL/mathml_editor/dictionary-tex.xml b/helm/DEVEL/mathml_editor/dictionary-tex.xml index 6bb3c5eb9..4eff38632 100644 --- a/helm/DEVEL/mathml_editor/dictionary-tex.xml +++ b/helm/DEVEL/mathml_editor/dictionary-tex.xml @@ -349,9 +349,4 @@ - - - - - diff --git a/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.cc b/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.cc index 284f1ed50..88acf9b19 100644 --- a/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.cc +++ b/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.cc @@ -119,13 +119,29 @@ c_mathml_editor_drop(Editor* editor, int alt) editor->lexer->drop(alt != 0); } +extern "C" int +c_mathml_editor_cursor_hide(Editor* editor) +{ + assert(editor); + return editor->parser->hideCursor(); +} + +extern "C" int +c_mathml_editor_cursor_show(Editor* editor) +{ + assert(editor); + return editor->parser->showCursor(); +} + extern "C" char* c_mathml_editor_get_tex(const Editor* editor) { assert(editor); DOM::Document res = editor->tml_tex->apply(editor->parser->document()); - DOM::Element root = res.get_documentElement(); - return strdup(std::string(root.get_nodeValue()).c_str()); + assert(res); + res.normalize(); + assert(res.get_firstChild() && res.get_firstChild().get_nodeName() == "#text"); + return strdup(std::string(res.get_firstChild().get_nodeValue()).c_str()); } extern "C" void diff --git a/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.h b/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.h index 7e7c0e38e..729ca0151 100644 --- a/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.h +++ b/helm/DEVEL/mathml_editor/ocaml/c_mathml_editor.h @@ -13,6 +13,8 @@ int c_mathml_editor_thaw(Editor*); void c_mathml_editor_reset(Editor*); void c_mathml_editor_push(Editor*, char); void c_mathml_editor_drop(Editor*, int); +int c_mathml_editor_cursor_hide(Editor*); +int c_mathml_editor_cursor_show(Editor*); char* c_mathml_editor_get_tex(const Editor*); GdomeDocument* c_mathml_editor_get_tml(const Editor*); GdomeDocument* c_mathml_editor_get_mml(const Editor*); diff --git a/helm/DEVEL/mathml_editor/ocaml/i_mathml_editor.ml b/helm/DEVEL/mathml_editor/ocaml/i_mathml_editor.ml index f3ca57454..62c1a3805 100644 --- a/helm/DEVEL/mathml_editor/ocaml/i_mathml_editor.ml +++ b/helm/DEVEL/mathml_editor/ocaml/i_mathml_editor.ml @@ -24,6 +24,12 @@ external push : editor:t -> ch:char -> unit external drop : editor:t -> alt:bool -> unit = "ml_mathml_editor_drop" +external cursor_hide : editor:t -> unit + = "ml_mathml_cursor_hide" + +external cursor_show : editor:t -> unit + = "ml_mathml_cursor_show" + external get_tex : editor:t -> string = "ml_mathml_editor_get_tex" diff --git a/helm/DEVEL/mathml_editor/ocaml/mathml_editor.ml b/helm/DEVEL/mathml_editor/ocaml/mathml_editor.ml index 58ca8f769..7354c8e95 100644 --- a/helm/DEVEL/mathml_editor/ocaml/mathml_editor.ml +++ b/helm/DEVEL/mathml_editor/ocaml/mathml_editor.ml @@ -18,6 +18,12 @@ let push = I_mathml_editor.push let drop = I_mathml_editor.drop ;; +let cursor_hide = I_mathml_editor.cursor_hide +;; + +let cursor_show = I_mathml_editor.cursor_show +;; + let get_tex = I_mathml_editor.get_tex ;; diff --git a/helm/DEVEL/mathml_editor/ocaml/ml_mathml_editor.c b/helm/DEVEL/mathml_editor/ocaml/ml_mathml_editor.c index 79594c2a8..bbe888435 100644 --- a/helm/DEVEL/mathml_editor/ocaml/ml_mathml_editor.c +++ b/helm/DEVEL/mathml_editor/ocaml/ml_mathml_editor.c @@ -102,6 +102,22 @@ ml_mathml_editor_drop(value v, value alt) CAMLreturn(Val_unit); } +value +ml_mathml_editor_cursor_hide(value v) +{ + CAMLparam1(v); + ml_Editor* editor = Editor_val(v); + CAMLreturn(Val_bool(c_mathml_editor_cursor_hide(editor->c_editor))); +} + +value +ml_mathml_editor_cursor_show(value v) +{ + CAMLparam1(v); + ml_Editor* editor = Editor_val(v); + CAMLreturn(Val_bool(c_mathml_editor_cursor_show(editor->c_editor))); +} + value ml_mathml_editor_get_tex(value v) { diff --git a/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh b/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh index 5186c63bb..92c1eb409 100644 --- a/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh +++ b/helm/DEVEL/mathml_editor/src/AMathMLFactory.hh @@ -32,7 +32,6 @@ public: AMathMLFactory(class ALogger& l) : logger(l) { }; virtual ~AMathMLFactory() { }; - virtual void reset(void) = 0; virtual void documentModified(class TDocument&) = 0; virtual DOM::Document document(void) const = 0; diff --git a/helm/DEVEL/mathml_editor/src/APushParser.cc b/helm/DEVEL/mathml_editor/src/APushParser.cc index 9ff5eff1f..76690c044 100644 --- a/helm/DEVEL/mathml_editor/src/APushParser.cc +++ b/helm/DEVEL/mathml_editor/src/APushParser.cc @@ -2,12 +2,6 @@ #include "APushParser.hh" #include "AMathMLFactory.hh" -void -APushParser::reset() -{ - if (factory) factory->reset(); -} - bool APushParser::freeze() { diff --git a/helm/DEVEL/mathml_editor/src/APushParser.hh b/helm/DEVEL/mathml_editor/src/APushParser.hh index 3a3aa8842..5344b7272 100644 --- a/helm/DEVEL/mathml_editor/src/APushParser.hh +++ b/helm/DEVEL/mathml_editor/src/APushParser.hh @@ -33,10 +33,12 @@ public: APushParser(class ALogger& l, class AMathMLFactory& f) : logger(l), factory(&f), freeze_level(0) { }; virtual ~APushParser() { }; - virtual void reset(void); + virtual void reset(void) = 0; virtual void push(const class TToken&) = 0; virtual std::string drop(void) = 0; virtual void setCursorHint(const std::string&) = 0; + virtual bool hideCursor(void) = 0; + virtual bool showCursor(void) = 0; virtual bool freeze(void); virtual bool thaw(void); diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc index 2b714cb91..027aebcdf 100644 --- a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.cc @@ -7,12 +7,6 @@ CMathMLFactoryXSLT::CMathMLFactoryXSLT(ALogger& l, const DOMX::XSLTStylesheet& s) : AMathMLFactory(l), style(s) -{ - reset(); -} - -void -CMathMLFactoryXSLT::reset() { DOM::DOMImplementation di; DOM::DocumentType dt; @@ -22,32 +16,31 @@ CMathMLFactoryXSLT::reset() void CMathMLFactoryXSLT::documentModified(TDocument& doc) { - if (TNode dirty = doc.dirtyNode()) - { - std::vector< std::pair > dirtyId; - if (result.get_documentElement().hasAttribute("xref")) - 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); - - DOM::Element root = res.get_documentElement(); - assert(root); - assert(root.hasAttribute("xref")); + cout << "passo di qui" << endl; + std::vector< std::pair > dirtyId; + if (TNode dirty = doc.dirtyNode()) + if (result.get_documentElement().hasAttribute("xref")) + 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); - if (result.get_documentElement().hasAttribute("xref")) - { - bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); - assert(ok); - } - else - result.replaceChild(result.importNode(root, true), result.get_documentElement()); - - style.save(result, stdout); + DOM::Element root = res.get_documentElement(); + assert(root); + assert(root.hasAttribute("xref")); - doc.clearDirty(); + if (result.get_documentElement().hasAttribute("xref")) + { + bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); + assert(ok); } + else + result.replaceChild(result.importNode(root, true), result.get_documentElement()); + + style.save(result, stdout); + + doc.clearDirty(); } bool diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh index 9d129a378..898d95897 100644 --- a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLT.hh @@ -10,7 +10,6 @@ class CMathMLFactoryXSLT : public AMathMLFactory public: CMathMLFactoryXSLT(class ALogger&, const class GdomeSmartDOMExt::XSLTStylesheet&); - virtual void reset(void); virtual void documentModified(class TDocument&); virtual GdomeSmartDOM::Document document(void) const { return result; }; diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.cc b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.cc index 53fa5aa36..c26407b2e 100644 --- a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.cc +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.cc @@ -8,12 +8,6 @@ CMathMLFactoryXSLTDiff::CMathMLFactoryXSLTDiff(ALogger& l, const DOMX::XSLTStylesheet& s) : AMathMLFactory(l), style(s) -{ - reset(); -} - -void -CMathMLFactoryXSLTDiff::reset() { DOM::DOMImplementation di; DOM::DocumentType dt; @@ -23,40 +17,27 @@ CMathMLFactoryXSLTDiff::reset() void CMathMLFactoryXSLTDiff::documentModified(TDocument& doc) { - if (TNode dirty = doc.dirtyNode()) - { - std::vector< std::pair > dirtyId; - if (false && result.get_documentElement().hasAttribute("xref")) - 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); - //cout << "*** THE DIRTY FRAGMENT HAS ID = " << std::string(dirty["id"]) << endl; - //style.save(doc.document(), stdout); - cout << "*** THE CURRENT DOCUMENT:" << endl; - if (result) style.save(result, stdout); - cout << "*** THE NEW DOCUMENT:" << endl; - style.save(res, stdout); - cout << "*** THE DIFF:" << endl; - DOMX::Diff diff = DOMX::Diff::diff(result, res); - style.save(diff.document(), stdout); - diff.patch(); #if 0 - DOM::Element root = res.get_documentElement(); - assert(root); - assert(root.hasAttribute("xref")); - if (result.get_documentElement().hasAttribute("xref")) - { - bool ok = subst(result.get_documentElement(), root.getAttribute("xref"), result.importNode(root, true)); - assert(ok); - } - else - result = res; + std::vector< std::pair > dirtyId; + if (TNode dirty = doc.dirtyNode()) + if (false && result.get_documentElement().hasAttribute("xref")) + dirtyId.push_back(std::make_pair(DOM::GdomeString("id"), + DOM::GdomeString("'" + std::string(dirty["id"]) + "'"))); #endif - //style.save(result, stdout); + DOM::Document res = style.apply(doc.document()); + assert(res); + //cout << "*** THE DIRTY FRAGMENT HAS ID = " << std::string(dirty["id"]) << endl; + //style.save(doc.document(), stdout); + cout << "*** THE CURRENT DOCUMENT:" << endl; + if (result) style.save(result, stdout); + cout << "*** THE NEW DOCUMENT:" << endl; + style.save(res, stdout); + cout << "*** THE DIFF:" << endl; + DOMX::Diff diff = DOMX::Diff::diff(result, res); + style.save(diff.document(), stdout); + diff.patch(); - doc.clearDirty(); - } + doc.clearDirty(); } bool diff --git a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.hh b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.hh index ac933b5d7..fdc298f19 100644 --- a/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.hh +++ b/helm/DEVEL/mathml_editor/src/CMathMLFactoryXSLTDiff.hh @@ -9,7 +9,6 @@ class CMathMLFactoryXSLTDiff : public AMathMLFactory public: CMathMLFactoryXSLTDiff(class ALogger&, const DOMX::XSLTStylesheet&); - virtual void reset(void); virtual void documentModified(class TDocument&); virtual DOM::Document document(void) const { return result; }; diff --git a/helm/DEVEL/mathml_editor/src/LPushLexer.hh b/helm/DEVEL/mathml_editor/src/LPushLexer.hh index 1466298b0..03ba29c02 100644 --- a/helm/DEVEL/mathml_editor/src/LPushLexer.hh +++ b/helm/DEVEL/mathml_editor/src/LPushLexer.hh @@ -1,5 +1,5 @@ -#ifndef __TPushLexer_hh__ +#ifndef __LPushLexer_hh__ #define __LPushLexer_hh__ #include diff --git a/helm/DEVEL/mathml_editor/src/TDocument.cc b/helm/DEVEL/mathml_editor/src/TDocument.cc index e578b79f4..cbf163c7a 100644 --- a/helm/DEVEL/mathml_editor/src/TDocument.cc +++ b/helm/DEVEL/mathml_editor/src/TDocument.cc @@ -27,6 +27,15 @@ TDocument::~TDocument() et.removeEventListener("DOMSubtreeModified", *this, false); } +void +TDocument::reset() +{ + DOM::Element root = doc.createElementNS(TML_NS_URI, "tml:tex"); + root.setAttributeNS(XMLNS_NS_URI, "xmlns:tml", TML_NS_URI); + doc.replaceChild(root, doc.get_documentElement()); + clearDirty(); +} + void TDocument::serialize(const char* filename) const { @@ -89,7 +98,7 @@ TDocument::findCommonAncestor(const DOM::Node& node1, const DOM::Node& node2) unsigned d1 = nodeDepth(n1); unsigned d2 = nodeDepth(n2); - cout << "finding common ancestor " << d1 << " " << d2 << endl; + // cout << "finding common ancestor " << d1 << " " << d2 << endl; while (d1 < d2) { @@ -157,10 +166,12 @@ TDocument::handleEvent(const DOM::Event& ev) DOM::MutationEvent me(ev); assert(me); +#if 0 if (dirty) cout << "TDocument::handleEvent DIRTY BEFORE = " << dirty.getAttribute("id") << endl; else cout << "TDocument::handleEvent DIRTY BEFORE = (nil)" << endl; +#endif if (DOM::Node node = me.get_target()) if (dirty) @@ -170,7 +181,8 @@ TDocument::handleEvent(const DOM::Event& ev) else assert(0); +#if 0 cout << "TDocument::handleEvent target = " << DOM::Node(me.get_target()).get_nodeName() << " DIRTY AFTER = " << dirty.getAttribute("id") << " ME = " << DOM::Node(me.get_target()).get_nodeName() << endl; - +#endif } diff --git a/helm/DEVEL/mathml_editor/src/TDocument.hh b/helm/DEVEL/mathml_editor/src/TDocument.hh index b1ca562c6..e1ef85892 100644 --- a/helm/DEVEL/mathml_editor/src/TDocument.hh +++ b/helm/DEVEL/mathml_editor/src/TDocument.hh @@ -11,6 +11,7 @@ public: TDocument(void); ~TDocument(); + void reset(void); TNode create(const std::string&, unsigned = 0) const; TNode createG(unsigned id = 0) const { return create("g", id); }; TNode createC(const std::string&, unsigned = 0) const; diff --git a/helm/DEVEL/mathml_editor/src/TPushParser.cc b/helm/DEVEL/mathml_editor/src/TPushParser.cc index 836be35a8..a3fb97729 100644 --- a/helm/DEVEL/mathml_editor/src/TPushParser.cc +++ b/helm/DEVEL/mathml_editor/src/TPushParser.cc @@ -5,27 +5,36 @@ TPushParser::TPushParser(ALogger& l, const TDictionary& d) : APushParser(l), dictionary(d) { - reset(); + init(); } TPushParser::TPushParser(ALogger& l, AMathMLFactory& f, const TDictionary& d) : APushParser(l, f), dictionary(d) { - reset(); + init(); } TPushParser::~TPushParser() { } +void +TPushParser::init() +{ + cursor = doc.create("cursor"); + cursor["visible"] = "1"; + hiddenCursor = 0; + reset(); +} + void TPushParser::reset() { - APushParser::reset(); + cout << "passo di qui dentro pushparser " << factory << endl; nextId = 1; - cursor = doc.create("cursor"); - cursor["id"] = "I0"; - doc.clearDirty(); + if (cursor.parent()) cursor.remove(); + doc.reset(); doc.root().append(cursor); + if (factory) factory->documentModified(doc); } std::string @@ -1688,6 +1697,32 @@ TPushParser::setCursorHint(const std::string& c) } } +bool +TPushParser::hideCursor() +{ + if (hiddenCursor++ == 0) + { + cursor["visible"] = "0"; + if (factory && doc.dirtyNode() && !frozen()) factory->documentModified(doc); + return true; + } + else + return false; +} + +bool +TPushParser::showCursor() +{ + if (hiddenCursor > 0 && --hiddenCursor == 0) + { + cursor["visible"] = "1"; + if (factory && doc.dirtyNode() && !frozen()) factory->documentModified(doc); + return true; + } + else + return false; +} + bool TPushParser::thaw() { diff --git a/helm/DEVEL/mathml_editor/src/TPushParser.hh b/helm/DEVEL/mathml_editor/src/TPushParser.hh index 186e9087a..06020b52f 100644 --- a/helm/DEVEL/mathml_editor/src/TPushParser.hh +++ b/helm/DEVEL/mathml_editor/src/TPushParser.hh @@ -21,12 +21,16 @@ public: virtual void push(const TToken&); virtual std::string drop(void); virtual void setCursorHint(const std::string&); + virtual bool hideCursor(void); + virtual bool showCursor(void); virtual bool thaw(void); DOM::Document document(void) const { return doc.document().cloneNode(true); } private: + void init(void); + std::string PRIME(void) const; bool isPrimes(const TNode&) const; @@ -82,6 +86,7 @@ private: unsigned nextId; TDocument doc; TNode cursor; + unsigned hiddenCursor; const class TDictionary& dictionary; }; diff --git a/helm/DEVEL/mathml_editor/src/TTokenizer.cc b/helm/DEVEL/mathml_editor/src/TTokenizer.cc index 1002733a7..a78b7cc5d 100644 --- a/helm/DEVEL/mathml_editor/src/TTokenizer.cc +++ b/helm/DEVEL/mathml_editor/src/TTokenizer.cc @@ -24,6 +24,12 @@ TTokenizer::tokenize(const std::string& s) return res; } +void +TTokenizer::reset() +{ + assert(0); +} + void TTokenizer::push(const TToken& token) { diff --git a/helm/DEVEL/mathml_editor/src/TTokenizer.hh b/helm/DEVEL/mathml_editor/src/TTokenizer.hh index 62d08241c..da534fed7 100644 --- a/helm/DEVEL/mathml_editor/src/TTokenizer.hh +++ b/helm/DEVEL/mathml_editor/src/TTokenizer.hh @@ -17,9 +17,12 @@ public: std::vector tokenize(const std::string&); private: + virtual void reset(void); virtual void push(const TToken&); virtual std::string drop(void); virtual void setCursorHint(const std::string&) { }; + virtual bool hideCursor(void) { return false; }; + virtual bool showCursor(void) { return false; }; std::list tokens; }; diff --git a/helm/DEVEL/mathml_editor/test/.cvsignore b/helm/DEVEL/mathml_editor/test/.cvsignore index 6a37f8d48..bdefc79b9 100644 --- a/helm/DEVEL/mathml_editor/test/.cvsignore +++ b/helm/DEVEL/mathml_editor/test/.cvsignore @@ -3,4 +3,3 @@ Makefile Makefile.in editor -test diff --git a/helm/DEVEL/mathml_editor/test/editor.cc b/helm/DEVEL/mathml_editor/test/editor.cc index 62435ca78..181dbf540 100644 --- a/helm/DEVEL/mathml_editor/test/editor.cc +++ b/helm/DEVEL/mathml_editor/test/editor.cc @@ -14,7 +14,8 @@ extern void *parseMathMLFile(char *); struct Context { - Context(const std::string& s, TPushLexer& l, TPushParser& p) : buffer(s), i(0), lexer(l), parser(p) { }; + Context(const std::string& s, TPushLexer& l, TPushParser& p, DOMX::XSLTStylesheet& ts) + : buffer(s), i(0), lexer(l), parser(p), texStyle(ts) { }; void send(void) { @@ -26,8 +27,22 @@ struct Context unsigned i; TPushLexer& lexer; TPushParser& parser; + DOMX::XSLTStylesheet& texStyle; }; +extern "C" void +edit_output_tex(Context* data) +{ + assert(data); + DOM::Document res = data->texStyle.apply(data->parser.document()); +#if 0 + res.normalize(); + DOM::Node c = res.get_firstChild(); + if (c) cout << "HEY, there is a child! " << c.get_nodeName() << " " << c.get_nodeValue() << endl; +#endif + data->texStyle.save(res, stdout); +} + extern "C" int edit_timeout(Context* data) { @@ -69,6 +84,16 @@ edit_drop(Context* context, gboolean alt) GUI_thaw(); } +extern "C" void +edit_reset_tex(Context* context) +{ + assert(context != NULL); + GUI_freeze(); + context->lexer.reset(); + context->parser.reset(); + GUI_thaw(); +} + void main(int argc, char* argv[]) { @@ -81,10 +106,13 @@ main(int argc, char* argv[]) logger.info("loading the stylesheet..."); DOM::DOMImplementation di; - DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl"); - DOMX::XSLTStylesheet style(docStyle); + DOM::Document mmlStyleDoc = di.createDocumentFromURI("./xsl/tml-mmlp.xsl"); + DOMX::XSLTStylesheet mmlStyle(mmlStyleDoc); + + DOM::Document texStyleDoc = di.createDocumentFromURI("./xsl/tml-tex.xsl"); + DOMX::XSLTStylesheet texStyle(texStyleDoc); - CMathMLFactoryXSLTDiff factory(logger, style); + CMathMLFactoryXSLTDiff factory(logger, mmlStyle); TPushParser parser(logger, factory, dictionary); TPushLexer lexer(logger, parser); @@ -101,7 +129,7 @@ main(int argc, char* argv[]) style.save(result, stdout); #endif - Context context("", lexer, parser); + Context context("", lexer, parser, texStyle); GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context); GUI_load_document(gdome_cast_doc(static_cast(factory.document()))); diff --git a/helm/DEVEL/mathml_editor/test/guiGTK.c b/helm/DEVEL/mathml_editor/test/guiGTK.c index 7426e3f5d..306ec67fa 100644 --- a/helm/DEVEL/mathml_editor/test/guiGTK.c +++ b/helm/DEVEL/mathml_editor/test/guiGTK.c @@ -48,6 +48,7 @@ static GtkWidget* get_main_menu(void); static void file_open(GtkWidget*, gpointer); static void file_re_open(GtkWidget*, gpointer); static void file_close(GtkWidget*, gpointer); +static void file_output_tex(GtkWidget*, gpointer); static void options_font_manager(GtkWidget*, FontManagerId); static void options_set_font_size(GtkWidget*, gpointer); static void options_change_font_size(GtkWidget*, gboolean); @@ -57,6 +58,7 @@ static void options_transparency(GtkWidget*, gpointer); static void edit_delete_selection(GtkWidget*, gpointer); static void edit_select_parent(GtkWidget*, gpointer); static void edit_reset_selection(GtkWidget*, gpointer); +static void edit_reset(GtkWidget*, gpointer); static void edit_insert(GtkWidget*, gpointer); static void help_about(GtkWidget*, gpointer); @@ -65,6 +67,7 @@ static GtkItemFactoryEntry menu_items[] = { { "/File/_Open...", "O", file_open, 0, NULL }, { "/File/_Reopen", NULL, file_re_open, 0, NULL }, { "/File/_Close", "W", file_close, 0, NULL }, + { "/File/Output _TeX", NULL, file_output_tex, 0, NULL }, { "/File/sep1", NULL, NULL, 0, "" }, { "/File/_Quit", "Q", gtk_main_quit, 0, NULL }, @@ -73,6 +76,7 @@ static GtkItemFactoryEntry menu_items[] = { { "/Edit/Delete Selection", NULL, edit_delete_selection, 0, NULL }, { "/Edit/Select Parent", NULL, edit_select_parent, 0, NULL }, { "/Edit/sep1", NULL, NULL, 0, "" }, + { "/Edit/_Reset", NULL, edit_reset, 0, NULL }, { "/Edit/Insert...", "I", edit_insert, 0, NULL }, { "/_Options", NULL, NULL, 0, "" }, @@ -298,6 +302,13 @@ file_open(GtkWidget* widget, gpointer data) gtk_widget_show (fs); } +static void +file_output_tex(GtkWidget* widget, gpointer data) +{ + g_assert(context != NULL); + edit_output_tex(context); +} + static void options_font_manager(GtkWidget* widget, FontManagerId id) { @@ -369,6 +380,13 @@ edit_reset_selection(GtkWidget* widget, gpointer data) } } +static void +edit_reset(GtkWidget* widget, gpointer data) +{ + g_assert(context != NULL); + edit_reset_tex(context); +} + static void insert_tex(GtkWidget* widget, GtkEntry* entry) { diff --git a/helm/DEVEL/mathml_editor/textomml/.cvsignore b/helm/DEVEL/mathml_editor/textomml/.cvsignore new file mode 100644 index 000000000..c54770a84 --- /dev/null +++ b/helm/DEVEL/mathml_editor/textomml/.cvsignore @@ -0,0 +1,6 @@ +.deps +.libs +Makefile +Makefile.in +textomml +config.dirs diff --git a/helm/DEVEL/mathml_editor/textomml/Makefile.am b/helm/DEVEL/mathml_editor/textomml/Makefile.am new file mode 100644 index 000000000..d547d937f --- /dev/null +++ b/helm/DEVEL/mathml_editor/textomml/Makefile.am @@ -0,0 +1,17 @@ + +bin_PROGRAMS = textomml + +textomml_SOURCES = main.cc + +LDADDS = \ + $(GMETADOM_LIBS) \ + $(GDOMEXSLT_LIBS) \ + $(top_builddir)/src/.libs/libeditex.a + +textomml_LDADD = $(LDADDS) + +INCLUDES = \ + $(GMETADOM_CFLAGS) \ + $(GDOMEXSLT_CFLAGS) \ + -I$(top_srcdir)/src + diff --git a/helm/DEVEL/mathml_editor/textomml/config.dirs.in b/helm/DEVEL/mathml_editor/textomml/config.dirs.in new file mode 100644 index 000000000..49791891b --- /dev/null +++ b/helm/DEVEL/mathml_editor/textomml/config.dirs.in @@ -0,0 +1 @@ +#define PKGDATADIR "@prefix@/share/@PACKAGE@" diff --git a/helm/DEVEL/mathml_editor/textomml/main.cc b/helm/DEVEL/mathml_editor/textomml/main.cc new file mode 100644 index 000000000..377494068 --- /dev/null +++ b/helm/DEVEL/mathml_editor/textomml/main.cc @@ -0,0 +1,168 @@ + +#include + +#include + +#include "dom.hh" +#include "TPushParser.hh" +#include "TPushLexer.hh" +#include "TDictionary.hh" +#include "CLoggerConsole.hh" +#include "CMathMLFactoryXSLT.hh" +#include "CMathMLFactoryXSLTDiff.hh" +#include "AMathMLConsumer.hh" + +#include "config.dirs" + +enum CommandLineOptionId { + OPTION_VERSION = 256, + OPTION_HELP, + OPTION_VERBOSE, + OPTION_DICTIONARY, + OPTION_TML_XSLT, + OPTION_XSLT +}; + +static std::string tml_xslt = PKGDATADIR"/tml-mmlp.xsl"; +static std::string dictionary = PKGDATADIR"/dictionary-tex.xml"; +static bool xslt = true; + +static bool +parseBoolean(const char* s, bool& res) +{ + assert(s != NULL); + if (!strcmp(s, "yes")) { + res = true; + return true; + } else if (!strcmp(s, "no")) { + res = false; + return true; + } + + return false; +} + +static void +printVersion() +{ + std::cout << "TeX to MathML converter " << VERSION << " - Luca Padovani (C) 2003" << std::endl + << "This program is covered by the GNU Lesser General Public Licence" << std::endl; +} + +static void +printHelp() +{ + static char* helpMsg = "\ +Usage: textomml [options] file\n\n\ + -V, --version Output version information\n\ + -h, --help This small usage guide\n\ + -v, --verbose[=0-3] Display messages\n\ + --dictionary= Full path of the dictionary\n\ + --tml-xslt= Full path of the XSLT stylesheet\n\ + --xslt[=yes|no] Enable/disable XSLT transformation (default='yes')\n\ +"; + + std::cout << helpMsg << std::endl; + exit(0); +} + +static void +parseError(const char* option) +{ + assert(option != NULL); + std::cerr << "error while parsing option `" << option << "'" << std::endl << std::endl; + printHelp(); +} + +void +main(int argc, char* argv[]) +{ + CLoggerConsole logger; + + while (TRUE) { + int option_index = 0; + static struct option long_options[] = + { + { "version", no_argument, NULL, OPTION_VERSION }, + { "help", no_argument, NULL, OPTION_HELP }, + { "verbose", optional_argument, NULL, OPTION_VERBOSE }, + { "dictionary", required_argument, NULL, OPTION_DICTIONARY }, + { "tml-xslt", required_argument, NULL, OPTION_TML_XSLT }, + { "xslt", optional_argument, NULL, OPTION_XSLT }, + + { NULL, no_argument, NULL, 0 } + }; + + int c = getopt_long(argc, argv, "Vhv::", long_options, &option_index); + + if (c == -1) break; + + switch (c) { + case OPTION_VERSION: + case 'V': + printVersion(); + break; + + case OPTION_HELP: + case 'h': + printHelp(); + break; + + case OPTION_VERBOSE: + case 'v': + if (optarg == NULL) logger.verbosity(ALogger::Warning); + else logger.verbosity(ALogger::Level(*optarg - '0')); + break; + + case OPTION_DICTIONARY: + dictionary = optarg; + break; + + case OPTION_TML_XSLT: + tml_xslt = optarg; + break; + + case OPTION_XSLT: + if (optarg == NULL) printHelp(); + else if (!parseBoolean(optarg, xslt)) parseError("xslt"); + break; + + case '?': + break; + + default: + std::cerr << "*** getopt returned `" << c << "' value" << std::endl; + break; + } + } + + TDictionary dict(logger); + logger.info("loading dictionary: `" + dictionary + "'"); + dict.load("dictionary-test.xml"); + + logger.info("loading stylesheet: `" + tml_xslt + "'"); + DOM::DOMImplementation di; + DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl"); + DOMX::XSLTStylesheet style(docStyle); + + CMathMLFactoryXSLT factory(logger, style); + TPushParser parser(logger, factory, dict); + TPushLexer lexer(logger, parser); + + if (optind < argc) + { + ifstream file(argv[optind]); + if (!file) + { + std::cerr << "can't open input file `" << argv[optind] << "'" << std::endl; + exit(1); + } + + parser.freeze(); + char ch; + while (file.get(ch)) lexer.push(ch); + parser.thaw(); + } + else + printHelp(); +} diff --git a/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl b/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl index 873605387..34f44b3e8 100644 --- a/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl +++ b/helm/DEVEL/mathml_editor/xsl/tml-mmlp.xsl @@ -93,7 +93,7 @@ - + @@ -110,6 +110,9 @@ + + + @@ -699,7 +702,7 @@ - + } diff --git a/helm/DEVEL/mathml_editor/xsl/tml-tex.xsl b/helm/DEVEL/mathml_editor/xsl/tml-tex.xsl index f3ba8d5ce..a8b9878d8 100644 --- a/helm/DEVEL/mathml_editor/xsl/tml-tex.xsl +++ b/helm/DEVEL/mathml_editor/xsl/tml-tex.xsl @@ -34,7 +34,9 @@ - \ + \ + + {\it } @@ -42,7 +44,9 @@ - \ + \ + + {\rm } -- 2.39.2