1 /* This file is part of EdiTeX, an editor of mathematical
2 * expressions based on TeX syntax.
4 * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
5 * 2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
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.
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.
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
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>
31 #include "TPushParser.hh"
32 #include "TPushLexer.hh"
33 #include "TDictionary.hh"
34 #include "CLoggerConsole.hh"
35 #include "CMathMLFactoryXSLT.hh"
36 #include "CMathMLFactoryXSLTDiff.hh"
37 #include "AMathMLConsumer.hh"
39 #include "config.dirs"
41 enum CommandLineOptionId {
50 static std::string tml_xslt = PKGDATADIR"/tml-mmlp.xsl";
51 static std::string dictionary = PKGDATADIR"/dictionary-tex.xml";
52 static bool xslt = true;
55 parseBoolean(const char* s, bool& res)
58 if (!strcmp(s, "yes")) {
61 } else if (!strcmp(s, "no")) {
72 std::cout << "TeX to MathML converter " << VERSION << " - Luca Padovani (C) 2003" << std::endl
73 << "This program is covered by the GNU Lesser General Public Licence" << std::endl;
79 static char* helpMsg = "\
80 Usage: textomml [options] file\n\n\
81 -V, --version Output version information\n\
82 -h, --help This small usage guide\n\
83 -v, --verbose[=0-3] Display messages\n\
84 --dictionary=<path> Full path of the dictionary\n\
85 --tml-xslt=<path> Full path of the XSLT stylesheet\n\
86 --xslt[=yes|no] Enable/disable XSLT transformation (default='yes')\n\
89 std::cout << helpMsg << std::endl;
94 parseError(const char* option)
96 assert(option != NULL);
97 std::cerr << "error while parsing option `" << option << "'" << std::endl << std::endl;
102 main(int argc, char* argv[])
104 CLoggerConsole logger;
107 int option_index = 0;
108 static struct option long_options[] =
110 { "version", no_argument, NULL, OPTION_VERSION },
111 { "help", no_argument, NULL, OPTION_HELP },
112 { "verbose", optional_argument, NULL, OPTION_VERBOSE },
113 { "dictionary", required_argument, NULL, OPTION_DICTIONARY },
114 { "tml-xslt", required_argument, NULL, OPTION_TML_XSLT },
115 { "xslt", optional_argument, NULL, OPTION_XSLT },
117 { NULL, no_argument, NULL, 0 }
120 int c = getopt_long(argc, argv, "Vhv::", long_options, &option_index);
137 if (optarg == NULL) logger.verbosity(ALogger::Warning);
138 else logger.verbosity(ALogger::Level(*optarg - '0'));
141 case OPTION_DICTIONARY:
145 case OPTION_TML_XSLT:
150 if (optarg == NULL) printHelp();
151 else if (!parseBoolean(optarg, xslt)) parseError("xslt");
158 std::cerr << "*** getopt returned `" << c << "' value" << std::endl;
163 TDictionary dict(logger);
164 logger.info("loading dictionary: `" + dictionary + "'");
165 dict.load("dictionary-test.xml");
167 logger.info("loading stylesheet: `" + tml_xslt + "'");
168 DOM::DOMImplementation di;
169 DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
170 DOMX::XSLTStylesheet style(docStyle);
172 CMathMLFactoryXSLT factory(logger, style);
173 TPushParser parser(logger, factory, dict);
174 TPushLexer lexer(logger, parser);
178 std::ifstream file(argv[optind]);
181 std::cerr << "can't open input file `" << argv[optind] << "'" << std::endl;
187 while (file.get(ch)) lexer.push(ch);