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