7 #include "TPushParser.hh"
8 #include "TPushLexer.hh"
9 #include "TDictionary.hh"
10 #include "CLoggerConsole.hh"
11 #include "CMathMLFactoryXSLT.hh"
12 #include "CMathMLFactoryXSLTDiff.hh"
13 #include "AMathMLConsumer.hh"
15 #include "config.dirs"
17 enum CommandLineOptionId {
26 static std::string tml_xslt = PKGDATADIR"/tml-mmlp.xsl";
27 static std::string dictionary = PKGDATADIR"/dictionary-tex.xml";
28 static bool xslt = true;
31 parseBoolean(const char* s, bool& res)
34 if (!strcmp(s, "yes")) {
37 } else if (!strcmp(s, "no")) {
48 std::cout << "TeX to MathML converter " << VERSION << " - Luca Padovani (C) 2003" << std::endl
49 << "This program is covered by the GNU Lesser General Public Licence" << std::endl;
55 static char* helpMsg = "\
56 Usage: textomml [options] file\n\n\
57 -V, --version Output version information\n\
58 -h, --help This small usage guide\n\
59 -v, --verbose[=0-3] Display messages\n\
60 --dictionary=<path> Full path of the dictionary\n\
61 --tml-xslt=<path> Full path of the XSLT stylesheet\n\
62 --xslt[=yes|no] Enable/disable XSLT transformation (default='yes')\n\
65 std::cout << helpMsg << std::endl;
70 parseError(const char* option)
72 assert(option != NULL);
73 std::cerr << "error while parsing option `" << option << "'" << std::endl << std::endl;
78 main(int argc, char* argv[])
80 CLoggerConsole logger;
84 static struct option long_options[] =
86 { "version", no_argument, NULL, OPTION_VERSION },
87 { "help", no_argument, NULL, OPTION_HELP },
88 { "verbose", optional_argument, NULL, OPTION_VERBOSE },
89 { "dictionary", required_argument, NULL, OPTION_DICTIONARY },
90 { "tml-xslt", required_argument, NULL, OPTION_TML_XSLT },
91 { "xslt", optional_argument, NULL, OPTION_XSLT },
93 { NULL, no_argument, NULL, 0 }
96 int c = getopt_long(argc, argv, "Vhv::", long_options, &option_index);
113 if (optarg == NULL) logger.verbosity(ALogger::Warning);
114 else logger.verbosity(ALogger::Level(*optarg - '0'));
117 case OPTION_DICTIONARY:
121 case OPTION_TML_XSLT:
126 if (optarg == NULL) printHelp();
127 else if (!parseBoolean(optarg, xslt)) parseError("xslt");
134 std::cerr << "*** getopt returned `" << c << "' value" << std::endl;
139 TDictionary dict(logger);
140 logger.info("loading dictionary: `" + dictionary + "'");
141 dict.load("dictionary-test.xml");
143 logger.info("loading stylesheet: `" + tml_xslt + "'");
144 DOM::DOMImplementation di;
145 DOM::Document docStyle = di.createDocumentFromURI("./xsl/tml-mmlp.xsl");
146 DOMX::XSLTStylesheet style(docStyle);
148 CMathMLFactoryXSLT factory(logger, style);
149 TPushParser parser(logger, factory, dict);
150 TPushLexer lexer(logger, parser);
154 ifstream file(argv[optind]);
157 std::cerr << "can't open input file `" << argv[optind] << "'" << std::endl;
163 while (file.get(ch)) lexer.push(ch);