]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/test/editor.cc
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / mathml_editor / test / editor.cc
1 /* This file is part of EdiTeX, an editor of mathematical
2  * expressions based on TeX syntax.
3  * 
4  * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
5  *                    2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * For more information, please visit the project's home page
22  * http://helm.cs.unibo.it/editex/
23  * or send an email to <lpadovan@cs.unibo.it>
24  */
25
26 #include <cassert>
27
28 #include "dom.hh"
29 #include "TPushParser.hh"
30
31 #include "ILPushLexer.hh"
32 #include "TDictionary.hh"
33 #include "CLoggerConsole.hh"
34 #include "CMathMLFactoryXSLT.hh"
35 #include "CMathMLFactoryXSLTDiff.hh"
36 #include "AMathMLConsumer.hh"
37
38 #include "guiGTK.h"
39
40 extern void *parseMathMLFile(char *);
41
42 struct Context
43 {
44   /*
45   Context(const std::string& s, TPushLexer& l, TPushParser& p) : buffer(s), i(0), lexer(l), parser(p) { };
46   */
47   Context(const std::string& s, APushLexer& l, TPushParser& p, DOMX::XSLTStylesheet& ts) 
48     : buffer(s), i(0), lexer(l), parser(p), texStyle(ts) { };
49
50   void send(void)
51   {
52     if (i < buffer.length()) lexer.push(buffer[i++]);
53   }
54
55   std::string buffer;
56   unsigned i;
57   APushLexer& lexer;
58   TPushParser& parser;
59   DOMX::XSLTStylesheet& texStyle;
60 };
61
62 extern "C" void
63 edit_output_tex(Context* data)
64 {
65   assert(data);
66   DOM::Document res = data->texStyle.apply(data->parser.document());
67 #if 0
68   res.normalize();
69   DOM::Node c = res.get_firstChild();
70   if (c) std::cout << "HEY, there is a child! " << c.get_nodeName() << " " << c.get_nodeValue() << std::endl;
71 #endif
72   data->texStyle.save(res, stdout);
73 }
74
75 extern "C" int
76 edit_timeout(Context* data)
77 {
78   assert(data);
79   GUI_freeze();
80   data->send();
81   GUI_thaw();
82   return 1;
83 }
84
85 extern "C" void
86 edit_push_char(Context* context, gchar ch)
87 {
88   assert(context != NULL);
89   GUI_freeze();
90   std::cout << "*** SENDING " << ch << std::endl;
91   context->lexer.push(ch);
92   GUI_thaw();
93 }
94
95 #include <unistd.h>
96
97 extern "C" void
98 edit_push_string(Context* context, const gchar* s)
99 {
100   assert(context != NULL);
101   assert(s != NULL);
102 #if 0
103 //   GUI_freeze();
104 //   context->parser.freeze();
105   for (unsigned i = 0; s[i]; i++)
106     {
107       GUI_freeze();
108       context->lexer.push(s[i]);
109       GUI_thaw();
110       usleep(100000);
111       usleep(100000);
112     }
113 //   context->parser.thaw();
114 //   GUI_thaw();
115 #endif
116   context->buffer = s;
117 }
118
119 extern "C" void
120 edit_drop(Context* context, gboolean alt, gboolean control)
121 {
122   // At the moment, the last parameter is not used, but it will
123   // be useful when we will handle the "fast" deletion
124   assert(context != NULL);
125   GUI_freeze();
126   context->lexer.drop(alt);
127   GUI_thaw();
128 }
129
130 extern "C" void
131 edit_reset_tex(Context* context)
132 {
133   assert(context != NULL);
134   GUI_freeze();
135   context->lexer.reset();
136   context->parser.reset();
137   GUI_thaw();
138 }
139
140 extern "C" void
141 edit_complete(Context* context)
142 {
143   assert(context != NULL);
144   GUI_freeze();
145   if (!context->lexer.complete()) context->lexer.push('\t');
146   GUI_thaw();
147 }
148
149 int
150 main(int argc, char* argv[])
151 {
152   CLoggerConsole logger;
153   logger.verbosity(ALogger::Debug);
154
155   TDictionary dictionary(logger);
156   logger.info("loading the dictionary...");
157   dictionary.load("/usr/share/editex/dictionary-tex.xml");
158
159   logger.info("loading the stylesheet...");
160   DOM::DOMImplementation di;
161   DOM::Document mmlStyleDoc = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
162   DOMX::XSLTStylesheet mmlStyle(mmlStyleDoc);
163
164   DOM::Document texStyleDoc = di.createDocumentFromURI("./xsl/tml-texid.xsl");
165   DOMX::XSLTStylesheet texStyle(texStyleDoc);
166
167   CMathMLFactoryXSLTDiff factory(logger, mmlStyle);
168   TPushParser parser(logger, factory, dictionary);
169   ILPushLexer lexer(logger, parser, dictionary);
170
171 #if 0
172   lexer.push('$');
173   lexer.push(' ');
174   assert(result);
175 #endif
176
177 #if 0
178   DOM::Document doc = parser.document().document();
179   std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > np;
180   result = style.apply(doc, np);
181   style.save(result, stdout);
182 #endif
183
184   Context context("", lexer, parser, texStyle);
185
186   GUI_init(&argc, &argv, "EditTeX", 500, 600, &context);
187   GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(factory.document())));
188   GUI_run();
189   GUI_uninit();
190   GUI_unload_document();
191
192 }