]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/test/editor.cc
* code cleanup
[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 "AMathMLConsumer.hh"
9
10 #include "guiGTK.h"
11
12 TDictionary dictionary;
13
14 extern void *parseMathMLFile(char *);
15
16 class CMathMLConsumer : public AMathMLConsumer
17 {
18 public:
19   CMathMLConsumer(void) { firstTime = true; };
20
21   virtual void documentModified(const DOM::Document& result)
22   {
23     if (firstTime)
24       {
25         if (GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(result))) < 0)
26           cerr << "c'e' stato un errore" << endl;
27         firstTime = false;
28       }
29   }
30
31 private:
32   bool firstTime;
33 };
34
35 struct Context
36 {
37   Context(const std::string& s, TPushLexer& l) : buffer(s), i(0), lexer(l) { };
38
39   void send(void)
40   {
41     if (i < buffer.length()) lexer.push(buffer[i++]);
42     else lexer.push('\n');
43   }
44
45   std::string buffer;
46   unsigned i;
47   TPushLexer& lexer;
48 };
49
50 extern "C" int
51 edit_timeout(Context* data)
52 {
53   assert(data);
54   GUI_freeze();
55   data->send();
56   GUI_thaw();
57   return 1;
58 }
59
60 extern "C" void
61 push_char(Context* context, gchar ch)
62 {
63   GUI_freeze();
64   cout << "*** SENDING " << ch << endl;
65   context->lexer.push(ch);
66   GUI_thaw();
67 }
68
69 main(int argc, char* argv[])
70 {
71   CLoggerConsole logger;
72   logger.info("loading the dictionary...");
73   dictionary.load("dictionary.xml");
74
75   logger.info("loading the stylesheet...");
76   DOM::DOMImplementation di;
77   DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
78   DOM::XSLTStylesheet style(docStyle);
79
80   CMathMLConsumer consumer;
81   CMathMLFactoryXSLT factory(logger, consumer, style);
82   TPushParser parser(logger, factory, dictionary);
83   TPushLexer lexer(logger, parser);
84
85 #if 0
86   lexer.push('$');
87   lexer.push(' ');
88   assert(result);
89 #endif
90
91 #if 0
92   DOM::Document doc = parser.document().document();
93   std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > np;
94   result = style.apply(doc, np);
95   style.save(result, stdout);
96 #endif
97
98   Context context("", lexer);
99
100   GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context);
101   GUI_run();
102   GUI_uninit();
103   GUI_unload_document();
104 }