]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/test/editor.cc
* temporary fix for handling relative/absolute filenames in
[helm.git] / helm / DEVEL / mathml_editor / test / editor.cc
index 62435ca788e95322d9ca128f88231a17960039da..b251d4ede2ff8fe4988e0d37ef318375c90e592f 100644 (file)
@@ -2,6 +2,7 @@
 #include "dom.hh"
 #include "TPushParser.hh"
 #include "TPushLexer.hh"
+#include "LPushLexer.hh"
 #include "TDictionary.hh"
 #include "CLoggerConsole.hh"
 #include "CMathMLFactoryXSLT.hh"
@@ -14,20 +15,34 @@ 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, APushLexer& l, TPushParser& p, DOMX::XSLTStylesheet& ts) 
+    : buffer(s), i(0), lexer(l), parser(p), texStyle(ts) { };
 
   void send(void)
   {
     if (i < buffer.length()) lexer.push(buffer[i++]);
-    else lexer.push('\n');
   }
 
   std::string buffer;
   unsigned i;
-  TPushLexer& lexer;
+  APushLexer& 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)
 {
@@ -48,16 +63,28 @@ edit_push_char(Context* context, gchar ch)
   GUI_thaw();
 }
 
+#include <unistd.h>
+
 extern "C" void
 edit_push_string(Context* context, const gchar* s)
 {
   assert(context != NULL);
   assert(s != NULL);
-  GUI_freeze();
-  context->parser.freeze();
-  for (unsigned i = 0; s[i]; i++) context->lexer.push(s[i]);
-  context->parser.thaw();
-  GUI_thaw();
+#if 0
+//   GUI_freeze();
+//   context->parser.freeze();
+  for (unsigned i = 0; s[i]; i++)
+    {
+      GUI_freeze();
+      context->lexer.push(s[i]);
+      GUI_thaw();
+      usleep(100000);
+      usleep(100000);
+    }
+//   context->parser.thaw();
+//   GUI_thaw();
+#endif
+  context->buffer = s;
 }
 
 extern "C" void
@@ -69,6 +96,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[])
 {
@@ -77,16 +114,19 @@ main(int argc, char* argv[])
 
   TDictionary dictionary(logger);
   logger.info("loading the dictionary...");
-  dictionary.load("dictionary-test.xml");
+  dictionary.load("/home/luca/projects/helm/DEVEL/mathml_editor/dictionary-test.xml");
 
   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);
+  CMathMLFactoryXSLT factory(logger, mmlStyle);
   TPushParser parser(logger, factory, dictionary);
-  TPushLexer lexer(logger, parser);
+  LPushLexer lexer(logger, parser);
 
 #if 0
   lexer.push('$');
@@ -101,7 +141,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<GdomeNode*>(factory.document())));