#include "xml/XmlParser.h"#include "xml/Dom.h"#include "xmlUtil/Source.h"#include "xmlUtil/Constants.h"#include "xmlUtil/Arith.h"#include "xmlUtil/Substitute.h"#include <dom/DOM_Element.hpp>#include <dom/DOM_NodeList.hpp>#include <dom/DOM_NamedNodeMap.hpp>#include <dom/DOM_DocumentType.hpp>#include <string>#include <iostream>#include <fstream>Go to the source code of this file.
Functions | |
| std::ostream * | openOut (char *outfile) |
| void | outProlog (const DOM_DocumentType &doctype, std::ostream &out) |
| const std::string | dquote (&chDoubleQ[0]) |
| const std::string | myId ("$Id:makeXmlForProg.cxx, v 1.7 2002/04/05 18:25:18 jrb Exp$") |
| const std::string | idTemplate ("#Id:not committed$") |
| int | main (int argc, char *argv[]) |
Variables | |
| const char | chDoubleQ [2] = {0x22, 0x0} |
|
|
Referenced by outProlog(). |
|
|
Referenced by main(). |
|
||||||||||||
|
Main program for the eval application.
Definition at line 53 of file makeXmlForProg.cxx. References xmlUtil::Source::add(), xmlUtil::Constants::evalConstants(), xmlUtil::Substitute::execute(), idTemplate(), myId(), xmlUtil::Constants::normalizePrimary(), openOut(), outProlog(), and xmlUtil::Constants::pruneConstants().
00053 {
00054 std::ostream *out;
00055 if (argc < 3) { // instructions
00056 std::cout << "Required first argument is xml file to be parsed"
00057 << std::endl;
00058 std::cout << "Required second argument is output file (- for stdout)"
00059 << std::endl;
00060 exit(0);
00061 }
00062
00063 xml::XmlParser* parser = new xml::XmlParser();
00064 DOM_Document doc = parser->parse(argv[1]);
00065
00066 if (doc == 0) {
00067 std::cout << "Document failed to parse correctly" << std::endl;
00068 exit(0);
00069 }
00070
00071 // Else successful. Open output
00072 out = openOut(argv[2]);
00073
00074 DOM_Element docElt = doc.getDocumentElement();
00075 DOM_DocumentType doctype = doc.getDoctype(); // check for gdd??
00076 xmlUtil::Constants *constants = new xmlUtil::Constants(doc);
00077
00078 // prim processing
00079 constants->normalizePrimary();
00080
00081 // Evaluate all constants. Most would be evaluated even without
00082 // this step because of the use of Substitute, but if there happens
00083 // to be a constant not actually used in the <section> part of
00084 // the file, Substitute would not cause that constant to be evaluated.
00085 constants->evalConstants();
00086
00087 // Search for all dimension and position references, substitute
00088 // value of referenced element.
00089 DOM_NodeList sections = docElt.getElementsByTagName(DOMString("section"));
00090 int nSec = sections.getLength();
00091 int iSec;
00092
00093 xmlUtil::Substitute* sub = new xmlUtil::Substitute(doc);
00094
00095 DOM_Node dict = (docElt.getElementsByTagName(DOMString("idDict"))).item(0);
00096 DOM_Element& dictElt = static_cast<DOM_Element &> (dict);
00097 int nDictSub = sub->execute(dictElt);
00098 std::cout << "#elements substituted for id dictionary: " << nDictSub
00099 << std::endl;
00100
00101 for (iSec = 0; iSec < nSec; iSec++) {
00102 int nSub;
00103 DOM_Node secNode = sections.item(iSec);
00104 DOM_Element& secElt = static_cast<DOM_Element &> (secNode);
00105 nSub = sub->execute(secElt);
00106 std::cout << "#elements substituted for in this section: " << nSub
00107 << std::endl;
00108 }
00109
00110 // Get rid of any <derCategory> without the save attribute set to "true".
00111 // For the rest, prune element content from all <const> children;
00112 // it's no longer needed.
00113 DOM_Element derived = xml::Dom::findFirstChildByName(docElt, "constants");
00114 if (derived != DOM_Element() ) {
00115 derived = xml::Dom::findFirstChildByName(derived, "derived");
00116
00117 if (derived != DOM_Element()) {
00118 DOM_NodeList cats = derived.getElementsByTagName("derCategory");
00119 int nCat = cats.getLength();
00120 int iCat;
00121 for (iCat=0; iCat < nCat; iCat++) {
00122 DOM_Node node = cats.item(iCat);
00123 DOM_Node attNode = (node.getAttributes()).getNamedItem("save");
00124 if ((attNode.getNodeValue()).equals(DOMString("false")) ) { // remove
00125 DOM_Element& toPrune = static_cast<DOM_Element &>(node);
00126 xml::Dom::prune(toPrune);
00127 (toPrune.getParentNode()).removeChild(toPrune);
00128 // compensate for changing node list
00129 iCat--; nCat--;
00130 }
00131 }
00132
00133 // Now just get rid of all content for <const> children
00134 // in remaining derived categories
00135 constants->pruneConstants();
00136 }
00137 }
00138
00139 // Add a <source> child to the outer gdd element
00140 xmlUtil::Source * source =
00141 new xmlUtil::Source(doc, "xmlUtil/v1/src/forProg.exe", myId.c_str());
00142 source->add();
00143
00144 // Output the xml declaration and all the text in the DOCTYPE (see DOMPrint)
00145 outProlog(doctype, *out);
00146
00147 // If have gdd element with CVSid attribute, null it out. Don't have
00148 // a real CVS id until the file has been committed
00149 if (docElt.getAttribute("CVSid") != DOMString() ) {
00150 std::string noId(idTemplate);
00151 noId.replace(0, 1, "$");
00152 docElt.setAttribute("CVSid", noId.c_str());
00153 }
00154
00155 // Finally output the elements
00156 // May want option to exclude comments here
00157 xml::Dom::prettyPrintElement(docElt, *out, "");
00158
00159 delete parser;
00160 return(0);
00161 }
|
|
||||||||||||
|
Referenced by main(). |
|
|
Open specified output file (may be standard output if "-" is given as input argument) Definition at line 167 of file makeXmlForProg.cxx. Referenced by main().
00168 {
00169 char *hyphen = "-";
00170 std::ostream* out;
00171
00172 if (*outfile == *hyphen) {
00173 out = &std::cout;
00174 }
00175 else { // try to open file as ostream
00176 out = new std::ofstream(outfile);
00177 }
00178 return out;
00179 }
|
|
||||||||||||
|
Write out an xml declaration and copy the input DOCTYPE declaration to the output Definition at line 185 of file makeXmlForProg.cxx. References dquote(). Referenced by main().
00185 {
00186 // write the xml declaration: <?xml version="1.0" ?>
00187
00188 out << "<?xml version=" << dquote << "1.0" << dquote << "?>" << std::endl;
00189 if (doctype != DOM_DocumentType()) {
00190 char* transcoded = xml::Dom::transToChar(doctype.getName());
00191 if (transcoded != 0) {
00192 // out << "<!DOCTYPE " << xml::Dom::transToChar(doctype.getName()) << " ";
00193 out << "<!DOCTYPE " << transcoded << " ";
00194 }
00195 else
00196 {
00197 std::cout << "Failed to transcode doctype " << std::endl;
00198 return;
00199 }
00200
00201 DOMString id = doctype.getPublicId();
00202 if (id != 0) {
00203 transcoded = xml::Dom::transToChar(id);
00204 // out << " PUBLIC " << dquote << xml::Dom::transToChar(id) << dquote;
00205 if (transcoded != 0) {
00206 out << " PUBLIC " << dquote << transcoded << dquote;
00207 }
00208 else {
00209 std::cout << "Failed to transcode public id " << std::endl;
00210 return;
00211 }
00212 id = doctype.getSystemId();
00213 if (id != 0) {
00214 transcoded = xml::Dom::transToChar(id);
00215 if (transcoded != 0) {
00216 out << " " << dquote << transcoded << dquote;
00217 }
00218 else {
00219 std::cout << "Failed to transcode system id " << std::endl;
00220 return;
00221 }
00222 }
00223 }
00224 else {
00225 id = doctype.getSystemId();
00226 if (id != 0) {
00227 // out << " SYSTEM " << dquote << xml::Dom::transToChar(id) << dquote;
00228 transcoded = xml::Dom::transToChar(id);
00229 if (transcoded != 0) {
00230 out << " " << dquote << transcoded << dquote;
00231 }
00232 else {
00233 std::cout << "Failed to transcode system id " << std::endl;
00234 return;
00235 }
00236 }
00237 }
00238 id = doctype.getInternalSubset();
00239 if (id !=0) {
00240 transcoded = xml::Dom::transToChar(id);
00241 if (transcoded != 0) {
00242 // out << "[" << xml::Dom::transToChar(id) << "]";
00243 out << "[" << transcoded << "]";
00244 }
00245 else {
00246 std::cout << "Failed to transcode internal subset" << std::endl;
00247 return;
00248 }
00249 }
00250 out << ">" << std::endl;
00251 }
00252 }
|
|
|
Definition at line 39 of file makeXmlForProg.cxx. |
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001