X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FTDictionary.cc;h=b0366338838b4ea20dae7910465f0f3a4159df06;hb=c112706f347e08e7f345131fbc4c3aa0e9ecc7b5;hp=8c16d2ba91327bf0dba38ed1ecc3cb554a905276;hpb=7bea7bddf7ca13260f4d3965182dc4fb58d035e7;p=helm.git diff --git a/helm/DEVEL/mathml_editor/src/TDictionary.cc b/helm/DEVEL/mathml_editor/src/TDictionary.cc index 8c16d2ba9..b03663388 100644 --- a/helm/DEVEL/mathml_editor/src/TDictionary.cc +++ b/helm/DEVEL/mathml_editor/src/TDictionary.cc @@ -1,3 +1,27 @@ +/* This file is part of EdiTeX, an editor of mathematical + * expressions based on TeX syntax. + * + * Copyright (C) 2002-2003 Luca Padovani , + * 2003 Paolo Marinelli . + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please visit the project's home page + * http://helm.cs.unibo.it/editex/ + * or send an email to + */ #include @@ -8,12 +32,42 @@ static TDictionary::Entry undefinedEntry; +static std::string +getURIBase(const std::string& uri) +{ + std::string::size_type slash = uri.rfind('/'); + if (slash != std::string::npos) return uri.substr(0, slash + 1); + else return ""; +} + +static std::string +getURIName(const std::string& uri) +{ + std::string::size_type slash = uri.rfind('/'); + if (slash != std::string::npos) return uri.substr(slash + 1, uri.size()); + else return uri; +} + void -TDictionary::load(const char* uri) +TDictionary::load(const std::string& uri) { + load(getURIName(uri), getURIBase(uri)); +} + +void +TDictionary::load(const std::string& name, const std::string& base) +{ + logger.debug("Dictionary: loading `" + base + name + "'"); + DOM::DOMImplementation di; + DOM::Document doc = di.createDocumentFromURI((base + name).c_str()); + assert(doc); + load(doc, base); +} - DOM::Document doc = di.createDocumentFromURI(uri); +void +TDictionary::load(const DOM::Document& doc, const std::string& base) +{ assert(doc); DOM::Element root = doc.get_documentElement(); @@ -23,7 +77,23 @@ TDictionary::load(const char* uri) TTokenizer tokenizer(logger); for (DOM::Node p = root.get_firstChild(); p; p = p.get_nextSibling()) - if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "entry") + if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "include") + { + DOM::Element el = p; + assert(el); + if (el.hasAttribute("href")) + { + // WARNING: this may result into an infinite loop! + std::string href = el.getAttribute("href"); + std::string newBase = getURIBase(href); + std::string newName = getURIName(href); + if (newBase != "") load(newName, newBase); + else load(newName, base); + } + else + logger.warning("Dictionary: include statement with no href attribute (ignored)"); + } + else if (p.get_nodeType() == DOM::Node::ELEMENT_NODE && p.get_nodeName() == "entry") { DOM::Element el = p; assert(el); @@ -31,7 +101,7 @@ TDictionary::load(const char* uri) std::string name = el.getAttribute("name"); if (entries.find(name) != entries.end()) - cerr << "WARNING: entry `" << name << "' is being redefined" << endl; + logger.info("Dictionary: `" + name + "' is being redefined"); Entry entry; @@ -50,13 +120,13 @@ TDictionary::load(const char* uri) { entry.value = el.getAttribute("val"); if (entry.cls == MACRO) - cerr << "WARNING: `" << name << "' has a specified value, but is classified as macro" << endl; + logger.warning("Dictionary: `" + name + "' has a specified value, but is classified as macro"); } if (el.hasAttribute("pattern")) { if (entry.cls != MACRO) - cerr << "WARNING: `" << name << "' has a specified pattern, but is not classified as macro" << endl; + logger.warning("Dictionary: `" + name + "' has a specified pattern, but is not classified as macro"); std::string pattern = el.getAttribute("pattern"); if (pattern == "{}") @@ -69,6 +139,7 @@ TDictionary::load(const char* uri) entry.pattern = tokenizer.tokenize(pattern); } +#if 0 if (el.hasAttribute("infix")) { std::istringstream is(el.getAttribute("infix")); @@ -104,6 +175,7 @@ TDictionary::load(const char* uri) if (!el.hasAttribute("prefix")) entry.prefix = postfix; } } +#endif if (el.hasAttribute("limits")) { @@ -124,7 +196,7 @@ TDictionary::load(const char* uri) if (el.hasAttribute("delimiter")) { if (entry.cls != OPERATOR && !entry.embellishment) - cerr << "WARNING: `" << name << "' delimiter ignored for non-operator" << endl; + logger.warning("Dictionary: `" + name + "' delimiter ignored for non-operator"); std::istringstream is(el.getAttribute("delimiter")); unsigned delimiter; @@ -135,7 +207,7 @@ TDictionary::load(const char* uri) if (el.hasAttribute("table")) { if (entry.cls != MACRO) - cerr << "WARNING: `" << name << "' table ignored for non-macro" << endl; + logger.warning("Dictionary: `" + name + "' table ignored for non-macro"); std::istringstream is(el.getAttribute("table")); unsigned table;