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