]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/test/editor.cc
* temporary fix for handling relative/absolute filenames in
[helm.git] / helm / DEVEL / mathml_editor / test / editor.cc
1
2 #include "dom.hh"
3 #include "TPushParser.hh"
4 #include "TPushLexer.hh"
5 #include "LPushLexer.hh"
6 #include "TDictionary.hh"
7 #include "CLoggerConsole.hh"
8 #include "CMathMLFactoryXSLT.hh"
9 #include "CMathMLFactoryXSLTDiff.hh"
10 #include "AMathMLConsumer.hh"
11
12 #include "guiGTK.h"
13
14 extern void *parseMathMLFile(char *);
15
16 struct Context
17 {
18   Context(const std::string& s, APushLexer& l, TPushParser& p, DOMX::XSLTStylesheet& ts) 
19     : buffer(s), i(0), lexer(l), parser(p), texStyle(ts) { };
20
21   void send(void)
22   {
23     if (i < buffer.length()) lexer.push(buffer[i++]);
24   }
25
26   std::string buffer;
27   unsigned i;
28   APushLexer& lexer;
29   TPushParser& parser;
30   DOMX::XSLTStylesheet& texStyle;
31 };
32
33 extern "C" void
34 edit_output_tex(Context* data)
35 {
36   assert(data);
37   DOM::Document res = data->texStyle.apply(data->parser.document());
38 #if 0
39   res.normalize();
40   DOM::Node c = res.get_firstChild();
41   if (c) cout << "HEY, there is a child! " << c.get_nodeName() << " " << c.get_nodeValue() << endl;
42 #endif
43   data->texStyle.save(res, stdout);
44 }
45
46 extern "C" int
47 edit_timeout(Context* data)
48 {
49   assert(data);
50   GUI_freeze();
51   data->send();
52   GUI_thaw();
53   return 1;
54 }
55
56 extern "C" void
57 edit_push_char(Context* context, gchar ch)
58 {
59   assert(context != NULL);
60   GUI_freeze();
61   cout << "*** SENDING " << ch << endl;
62   context->lexer.push(ch);
63   GUI_thaw();
64 }
65
66 #include <unistd.h>
67
68 extern "C" void
69 edit_push_string(Context* context, const gchar* s)
70 {
71   assert(context != NULL);
72   assert(s != NULL);
73 #if 0
74 //   GUI_freeze();
75 //   context->parser.freeze();
76   for (unsigned i = 0; s[i]; i++)
77     {
78       GUI_freeze();
79       context->lexer.push(s[i]);
80       GUI_thaw();
81       usleep(100000);
82       usleep(100000);
83     }
84 //   context->parser.thaw();
85 //   GUI_thaw();
86 #endif
87   context->buffer = s;
88 }
89
90 extern "C" void
91 edit_drop(Context* context, gboolean alt)
92 {
93   assert(context != NULL);
94   GUI_freeze();
95   context->lexer.drop(alt);
96   GUI_thaw();
97 }
98
99 extern "C" void
100 edit_reset_tex(Context* context)
101 {
102   assert(context != NULL);
103   GUI_freeze();
104   context->lexer.reset();
105   context->parser.reset();
106   GUI_thaw();
107 }
108
109 void
110 main(int argc, char* argv[])
111 {
112   CLoggerConsole logger;
113   logger.verbosity(ALogger::Debug);
114
115   TDictionary dictionary(logger);
116   logger.info("loading the dictionary...");
117   dictionary.load("/home/luca/projects/helm/DEVEL/mathml_editor/dictionary-test.xml");
118
119   logger.info("loading the stylesheet...");
120   DOM::DOMImplementation di;
121   DOM::Document mmlStyleDoc = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
122   DOMX::XSLTStylesheet mmlStyle(mmlStyleDoc);
123
124   DOM::Document texStyleDoc = di.createDocumentFromURI("./xsl/tml-tex.xsl");
125   DOMX::XSLTStylesheet texStyle(texStyleDoc);
126
127   CMathMLFactoryXSLT factory(logger, mmlStyle);
128   TPushParser parser(logger, factory, dictionary);
129   LPushLexer lexer(logger, parser);
130
131 #if 0
132   lexer.push('$');
133   lexer.push(' ');
134   assert(result);
135 #endif
136
137 #if 0
138   DOM::Document doc = parser.document().document();
139   std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > np;
140   result = style.apply(doc, np);
141   style.save(result, stdout);
142 #endif
143
144   Context context("", lexer, parser, texStyle);
145
146   GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context);
147   GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(factory.document())));
148   GUI_run();
149   GUI_uninit();
150   GUI_unload_document();
151 }