]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/test/editor.cc
ocaml 3.09 transition
[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 #include "timer.hh"
31
32 #include "ILPushLexer.hh"
33 #include "TDictionary.hh"
34 #include "CLoggerConsole.hh"
35 #include "CMathMLFactoryXSLT.hh"
36 #include "CMathMLFactoryXSLTDiff.hh"
37 #include "AMathMLConsumer.hh"
38
39 #include "guiGTK.h"
40
41 extern void *parseMathMLFile(char *);
42
43 struct Context
44 {
45   /*
46   Context(const std::string& s, TPushLexer& l, TPushParser& p) : buffer(s), i(0), lexer(l), parser(p) { };
47   */
48   Context(const std::string& s, APushLexer& l, TPushParser& p, DOMX::XSLTStylesheet& ts) 
49     : buffer(s), i(0), lexer(l), parser(p), texStyle(ts) { };
50
51   void send(void)
52   {
53     if (i < buffer.length()) lexer.push(buffer[i++]);
54   }
55
56   std::string buffer;
57   unsigned i;
58   APushLexer& lexer;
59   TPushParser& parser;
60   DOMX::XSLTStylesheet& texStyle;
61 };
62
63 extern "C" void
64 edit_output_tex(Context* data)
65 {
66   assert(data);
67   DOM::Document res = data->texStyle.apply(data->parser.document());
68 #if 0
69   res.normalize();
70   DOM::Node c = res.get_firstChild();
71   if (c) std::cout << "HEY, there is a child! " << c.get_nodeName() << " " << c.get_nodeValue() << std::endl;
72 #endif
73   //data->texStyle.save(res, stdout);
74 }
75
76 extern "C" int
77 edit_timeout(Context* data)
78 {
79   assert(data);
80   GUI_freeze();
81   data->send();
82   GUI_thaw();
83   return 1;
84 }
85
86 extern "C" void
87 edit_push_char(Context* context, gchar ch)
88 {
89   assert(context != NULL);
90   long t0 = getTimer();
91   GUI_freeze();
92   std::cout << "*** SENDING " << ch << std::endl;
93   context->lexer.push(ch);
94   GUI_thaw();
95   long t1 = getTimer();
96   std::cout << "=== OVERALL TIME = " << (t1 - t0) / 1000 << std::endl;
97 }
98
99 #include <unistd.h>
100
101 extern "C" void
102 edit_push_string(Context* context, const gchar* s)
103 {
104   assert(context != NULL);
105   assert(s != NULL);
106 #if 0
107 //   GUI_freeze();
108 //   context->parser.freeze();
109   for (unsigned i = 0; s[i]; i++)
110     {
111       GUI_freeze();
112       context->lexer.push(s[i]);
113       GUI_thaw();
114       usleep(100000);
115       usleep(100000);
116     }
117 //   context->parser.thaw();
118 //   GUI_thaw();
119 #endif
120   context->buffer = s;
121 }
122
123 extern "C" void
124 edit_drop(Context* context, gboolean alt, gboolean control)
125 {
126   // At the moment, the last parameter is not used, but it will
127   // be useful when we will handle the "fast" deletion
128   assert(context != NULL);
129   GUI_freeze();
130   context->lexer.drop(alt);
131   GUI_thaw();
132 }
133
134 extern "C" void
135 edit_reset_tex(Context* context)
136 {
137   assert(context != NULL);
138   GUI_freeze();
139   context->lexer.reset();
140   context->parser.reset();
141   GUI_thaw();
142 }
143
144 extern "C" void
145 edit_complete(Context* context)
146 {
147   assert(context != NULL);
148   GUI_freeze();
149   if (!context->lexer.complete()) context->lexer.push('\t');
150   GUI_thaw();
151 }
152
153 int
154 main(int argc, char* argv[])
155 {
156   CLoggerConsole logger;
157   logger.verbosity(ALogger::Debug);
158
159   TDictionary dictionary(logger);
160   logger.info("loading the dictionary...");
161   dictionary.load("./dict/dictionary-tex.xml");
162
163   logger.info("loading the stylesheet...");
164   DOM::DOMImplementation di;
165   DOM::Document mmlStyleDoc = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
166   DOMX::XSLTStylesheet mmlStyle(mmlStyleDoc);
167
168   DOM::Document texStyleDoc = di.createDocumentFromURI("./xsl/tml-texid.xsl");
169   DOMX::XSLTStylesheet texStyle(texStyleDoc);
170
171   CMathMLFactoryXSLT factory(logger, mmlStyle);
172   TPushParser parser(logger, factory, dictionary);
173   ILPushLexer lexer(logger, parser, dictionary);
174
175 #if 0
176   lexer.push('$');
177   lexer.push(' ');
178   assert(result);
179 #endif
180
181 #if 0
182   DOM::Document doc = parser.document().document();
183   std::vector< std::pair<DOM::GdomeString, DOM::GdomeString> > np;
184   result = style.apply(doc, np);
185   style.save(result, stdout);
186 #endif
187
188   Context context("", lexer, parser, texStyle);
189
190   GUI_init(&argc, &argv, "EditTeX", 500, 600, &context);
191   GUI_load_document(gdome_cast_doc(static_cast<GdomeNode*>(factory.document())));
192   GUI_run();
193   GUI_uninit();
194   GUI_unload_document();
195
196 }