Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

eval.cxx File Reference

#include "xml/XmlParser.h"
#include "xml/Dom.h"
#include "xmlUtil/Arith.h"
#include "xmlUtil/Substitute.h"
#include "xmlUtil/Constants.h"
#include "xmlUtil/Source.h"
#include <dom/DOM_Element.hpp>
#include <dom/DOM_NodeList.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 addSourceElt (DOM_Document doc)
void outProlog (const DOM_DocumentType &doctype, std::ostream &out)
char * stripDollar (char *toStrip)
const std::string dquote (&chDoubleQ)
const std::string myId ("$Id:eval.cxx, v 1.4 2002/07/23 20:01:20 jrb Exp$")
int main (int argc, char *argv[])

Variables

const char chDoubleQ = 0x22


Function Documentation

void addSourceElt DOM_Document    doc
 

const std::string dquote   chDoubleQ
 

Referenced by outProlog().

int main int    argc,
char *    argv[]
 

Main program for the eval application.

Parameters:
arg1  is the input xml file
arg2  is specification for the output file, or "-" to output to std::cout

Definition at line 46 of file eval.cxx.

References xmlUtil::Source::add(), xmlUtil::Constants::evalConstants(), xmlUtil::Substitute::execute(), xmlUtil::Constants::normalizePrimary(), openOut(), and outProlog().

00046                                  {
00047   std::ostream *out;
00048   if (argc < 3) {  // instructions
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   // Else successful.   Open output
00065   out = openOut(argv[2]);
00066 
00067   DOM_Element docElt = doc.getDocumentElement();
00068   DOM_DocumentType  doctype = doc.getDoctype(); //  check for gdd?? 
00069 
00070   // prim processing
00071   xmlUtil::Constants *constants = new xmlUtil::Constants(doc);
00072   constants->normalizePrimary();
00073 
00074   // No longer need the evaluate step since substitution will
00075   // evaluate any constant which has not yet been evaluated.
00076 
00077   // Search for all dimension and position references, substitute
00078   // value of referenced element.
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   // In case there were no sections to substitute, do eval here
00095   constants->evalConstants();
00096 
00097   // Get rid of the whole <derived> part of <constants>.  No longer needed.
00098   /*
00099   DOM_Element derived;
00100   if (docElt.getTagName().equals(DOMString("constants"))) {
00101     derived = xml::Dom::findFirstChildByName(docElt, "derived");
00102   }
00103   else {  
00104     derived = xml::Dom::findFirstChildByName(docElt, "constants");
00105     if (derived != DOM_Element() ) {
00106       derived = xml::Dom::findFirstChildByName(derived, "derived");
00107     }
00108   }
00109 
00110 
00111   if (derived != DOM_Element()) {
00112     xml::Dom::prune(derived);
00113     (derived.getParentNode()).removeChild(derived);
00114   }
00115   */
00116 
00117   // Add a <source> child to the outer gdd element
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   // Output the xml declaration and all the text in the DOCTYPE (see DOMPrint)
00123   outProlog(doctype, *out);
00124 
00125   // Finally output the elements
00126   // May want option to exclude comments here
00127   xml::Dom::prettyPrintElement(docElt, *out, "");
00128 
00129   delete parser;
00130   return(0);
00131 }

const std::string myId "$Id:eval.    cxx,
v 1.4 2002/07/23 20:01:20 jrb Exp$"   
 

std::ostream * openOut char *    outfile
 

Open specified output file (may be standard output if "-" is given as input argument)

Definition at line 137 of file eval.cxx.

00138 {
00139   char  *hyphen = "-";
00140   std::ostream* out;
00141   
00142   if (*outfile == *hyphen) {
00143     out = &std::cout;
00144   }
00145   else {   // try to open file as ostream
00146     out = new std::ofstream(outfile);
00147   }
00148   return out;
00149 }

void outProlog const DOM_DocumentType &    doctype,
std::ostream &    out
 

Write out an xml declaration and copy the input DOCTYPE declaration to the output

Definition at line 155 of file eval.cxx.

References dquote().

00155                                                                  {
00156   // write the xml declaration: <?xml version="1.0" ?>
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 }

char* stripDollar char *    toStrip
 

Definition at line 11 of file Source.cxx.

Referenced by xmlUtil::Source::add(), and xmlUtil::Source::Source().

00011                                     {
00012     const char dollar = '$';
00013     
00014     char   nothing = 0;
00015     unsigned len = strlen(toStrip);
00016     
00017     if (dollar == toStrip[len - 1]) {
00018       len--;
00019       toStrip[len] = nothing;
00020     }
00021     if (dollar == toStrip[0]) {
00022       return (toStrip + 1);
00023     }
00024     return toStrip;
00025   }


Variable Documentation

const char chDoubleQ = 0x22
 

Definition at line 36 of file eval.cxx.


Generated on Wed Oct 16 14:02:48 2002 by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001