]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/test/editor.cc
* this is a large commit
[helm.git] / helm / DEVEL / mathml_editor / test / editor.cc
1
2 #include "dom.hh"
3 #include "TPushParser.hh"
4 #include "TPushLexer.hh"
5 #include "TDictionary.hh"
6 #include "CLoggerConsole.hh"
7 #include "CMathMLFactoryXSLT.hh"
8 #include "CMathMLFactoryXSLTDiff.hh"
9 #include "AMathMLConsumer.hh"
10
11 #include "guiGTK.h"
12
13 extern void *parseMathMLFile(char *);
14
15 struct Context
16 {
17   Context(const std::string& s, TPushLexer& l, TPushParser& p) : buffer(s), i(0), lexer(l), parser(p) { };
18
19   void send(void)
20   {
21     if (i < buffer.length()) lexer.push(buffer[i++]);
22     else lexer.push('\n');
23   }
24
25   std::string buffer;
26   unsigned i;
27   TPushLexer& lexer;
28   TPushParser& parser;
29 };
30
31 extern "C" int
32 edit_timeout(Context* data)
33 {
34   assert(data);
35   GUI_freeze();
36   data->send();
37   GUI_thaw();
38   return 1;
39 }
40
41 extern "C" void
42 edit_push_char(Context* context, gchar ch)
43 {
44   assert(context != NULL);
45   GUI_freeze();
46   cout << "*** SENDING " << ch << endl;
47   context->lexer.push(ch);
48   GUI_thaw();
49 }
50
51 extern "C" void
52 edit_push_string(Context* context, const gchar* s)
53 {
54   assert(context != NULL);
55   assert(s != NULL);
56   GUI_freeze();
57   context->parser.freeze();
58   for (unsigned i = 0; s[i]; i++) context->lexer.push(s[i]);
59   context->parser.thaw();
60   GUI_thaw();
61 }
62
63 extern "C" void
64 edit_drop(Context* context, gboolean alt)
65 {
66   assert(context != NULL);
67   GUI_freeze();
68   context->lexer.drop(alt);
69   GUI_thaw();
70 }
71
72 void
73 main(int argc, char* argv[])
74 {
75   CLoggerConsole logger;
76   logger.verbosity(ALogger::Debug);
77
78   TDictionary dictionary(logger);
79   logger.info("loading the dictionary...");
80   dictionary.load("dictionary-test.xml");
81
82   logger.info("loading the stylesheet...");
83   DOM::DOMImplementation di;
84   DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
85   DOMX::XSLTStylesheet style(docStyle);
86
87   CMathMLFactoryXSLTDiff factory(logger, style);
88   TPushParser parser(logger, factory, dictionary);
89   TPushLexer lexer(logger, parser);
90
91 #if 0
92   lexer.push('$');
93   lexer.push(' ');
94   assert(result);
95 #endif
96
97 #if 0
98   DOM::Document doc = parser.document().document();
99   std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > np;
100   result = style.apply(doc, np);
101   style.save(result, stdout);
102 #endif
103
104   Context context("", lexer, parser);
105
106   GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context);
107   GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(factory.document())));
108   GUI_run();
109   GUI_uninit();
110   GUI_unload_document();
111 }