]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/test/editor.cc
debian release 0.4.1-1
[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, DOMX::XSLTStylesheet& ts) 
18     : buffer(s), i(0), lexer(l), parser(p), texStyle(ts) { };
19
20   void send(void)
21   {
22     if (i < buffer.length()) lexer.push(buffer[i++]);
23     else lexer.push('\n');
24   }
25
26   std::string buffer;
27   unsigned i;
28   TPushLexer& 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 extern "C" void
67 edit_push_string(Context* context, const gchar* s)
68 {
69   assert(context != NULL);
70   assert(s != NULL);
71   GUI_freeze();
72   context->parser.freeze();
73   for (unsigned i = 0; s[i]; i++) context->lexer.push(s[i]);
74   context->parser.thaw();
75   GUI_thaw();
76 }
77
78 extern "C" void
79 edit_drop(Context* context, gboolean alt)
80 {
81   assert(context != NULL);
82   GUI_freeze();
83   context->lexer.drop(alt);
84   GUI_thaw();
85 }
86
87 extern "C" void
88 edit_reset_tex(Context* context)
89 {
90   assert(context != NULL);
91   GUI_freeze();
92   context->lexer.reset();
93   context->parser.reset();
94   GUI_thaw();
95 }
96
97 void
98 main(int argc, char* argv[])
99 {
100   CLoggerConsole logger;
101   logger.verbosity(ALogger::Debug);
102
103   TDictionary dictionary(logger);
104   logger.info("loading the dictionary...");
105   dictionary.load("dictionary-test.xml");
106
107   logger.info("loading the stylesheet...");
108   DOM::DOMImplementation di;
109   DOM::Document mmlStyleDoc = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
110   DOMX::XSLTStylesheet mmlStyle(mmlStyleDoc);
111
112   DOM::Document texStyleDoc = di.createDocumentFromURI("./xsl/tml-tex.xsl");
113   DOMX::XSLTStylesheet texStyle(texStyleDoc);
114
115   CMathMLFactoryXSLTDiff factory(logger, mmlStyle);
116   TPushParser parser(logger, factory, dictionary);
117   TPushLexer lexer(logger, parser);
118
119 #if 0
120   lexer.push('$');
121   lexer.push(' ');
122   assert(result);
123 #endif
124
125 #if 0
126   DOM::Document doc = parser.document().document();
127   std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > np;
128   result = style.apply(doc, np);
129   style.save(result, stdout);
130 #endif
131
132   Context context("", lexer, parser, texStyle);
133
134   GUI_init(&argc, &argv, "mathmleditor", 500, 600, &context);
135   GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(factory.document())));
136   GUI_run();
137   GUI_uninit();
138   GUI_unload_document();
139 }