00001
00017 #include "xml/XmlParser.h"
00018 #include "xml/Dom.h"
00019 #include "xmlUtil/Arith.h"
00020 #include "xmlUtil/Substitute.h"
00021 #include "xmlUtil/Constants.h"
00022 #include "xmlUtil/Source.h"
00023 #include <dom/DOM_Element.hpp>
00024 #include <dom/DOM_NodeList.hpp>
00025 #include <dom/DOM_DocumentType.hpp>
00026
00027 #include <string>
00028 #include <iostream>
00029 #include <fstream>
00030
00031 std::ostream *openOut(char * outfile);
00032 void addSourceElt(DOM_Document doc);
00033 void outProlog(const DOM_DocumentType& doctype, std::ostream& out);
00034 char * stripDollar(char *toStrip);
00035
00036 const char chDoubleQ = 0x22;
00037 const std::string dquote(&chDoubleQ);
00038 const std::string myId("$Id: eval.cxx,v 1.4 2002/07/23 20:01:20 jrb Exp $");
00039
00046 int main(int argc, char* argv[]) {
00047 std::ostream *out;
00048 if (argc < 3) {
00049 std::cout << "Required first argument is xml file to be parsed"
00050 << std::endl;
00051 std::cout << "Required second argument is output file (- for stdout)"
00052 << std::endl;
00053 exit(0);
00054 }
00055
00056 xml::XmlParser* parser = new xml::XmlParser();
00057 DOM_Document doc = parser->parse(argv[1]);
00058
00059 if (doc == 0) {
00060 std::cout << "Document failed to parse correctly" << std::endl;
00061 exit(0);
00062 }
00063
00064
00065 out = openOut(argv[2]);
00066
00067 DOM_Element docElt = doc.getDocumentElement();
00068 DOM_DocumentType doctype = doc.getDoctype();
00069
00070
00071 xmlUtil::Constants *constants = new xmlUtil::Constants(doc);
00072 constants->normalizePrimary();
00073
00074
00075
00076
00077
00078
00079 DOM_NodeList sections = docElt.getElementsByTagName(DOMString("section"));
00080 int nSec = sections.getLength();
00081 int iSec;
00082
00083 xmlUtil::Substitute* sub = new xmlUtil::Substitute(doc);
00084
00085 for (iSec = 0; iSec < nSec; iSec++) {
00086 int nSub;
00087 DOM_Node secNode = sections.item(iSec);
00088 DOM_Element& secElt = static_cast<DOM_Element &> (secNode);
00089 nSub = sub->execute(secElt);
00090 std::cout << "#elements substituted for in this section: " << nSub
00091 << std::endl;
00092 }
00093
00094
00095 constants->evalConstants();
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 xmlUtil::Source *source =
00119 new xmlUtil::Source(doc, "xmlUtil/v1/src/eval.exe", "$Id: eval.cxx,v 1.4 2002/07/23 20:01:20 jrb Exp $");
00120 source->add();
00121
00122
00123 outProlog(doctype, *out);
00124
00125
00126
00127 xml::Dom::prettyPrintElement(docElt, *out, "");
00128
00129 delete parser;
00130 return(0);
00131 }
00132
00137 std::ostream *openOut(char * outfile)
00138 {
00139 char *hyphen = "-";
00140 std::ostream* out;
00141
00142 if (*outfile == *hyphen) {
00143 out = &std::cout;
00144 }
00145 else {
00146 out = new std::ofstream(outfile);
00147 }
00148 return out;
00149 }
00150
00155 void outProlog(const DOM_DocumentType& doctype, std::ostream& out) {
00156
00157
00158 out << "<?xml version=" << dquote << "1.0" << dquote << "?>" << std::endl;
00159 if (doctype != DOM_DocumentType()) {
00160
00161 out << "<!DOCTYPE " << xml::Dom::transToChar(doctype.getName()) << " ";
00162
00163 DOMString id = doctype.getPublicId();
00164 if (id != 0) {
00165 out << " PUBLIC " << dquote << xml::Dom::transToChar(id) << dquote;
00166 id = doctype.getSystemId();
00167 if (id != 0) {
00168 out << " " << dquote << xml::Dom::transToChar(id) << dquote;
00169 }
00170 }
00171 else {
00172 id = doctype.getSystemId();
00173 if (id != 0) {
00174 out << " SYSTEM " << dquote << xml::Dom::transToChar(id) << dquote;
00175 }
00176 }
00177 id = doctype.getInternalSubset();
00178 if (id !=0) {
00179 out << "[" << xml::Dom::transToChar(id) << "]";
00180 }
00181 out << ">" << std::endl;
00182 }
00183 }
00184
00185
00186
00187
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260