//
// Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Mon Jul 11 23:36:31 PDT 2011
// Last Modified: Mon Jul 11 23:36:34 PDT 2011
// Filename:      ...sig/examples/xml/element.cpp
// Web Address:   http://sig.sapp.org/examples/museinfo/xml/element.cpp
// Syntax:        C++; museinfo
//
// Description:   Extract element info from XML files.
//

#ifndef OLDCPP
   #include <iostream>
   using namespace std;
#else
   #include <iostream.h>
#endif
   
#include "XmlFile.h"
#include "Options.h"
#include "museinfoVersion.h"



// function declarations
void      checkOptions(Options& opts, int argc, char* argv[]);
void      example(void);
void      usage(const char* command);

// global variables
Options   options;             // database for command-line arguments


///////////////////////////////////////////////////////////////////////////

int main(int argc, char** argv) {
   XmlFile xmlfile;

   // process the command-line options
   checkOptions(options, argc, argv);

   // figure out the number of input files to process
   int numinputs = options.getArgCount();

   for (int i=0; i<numinputs || i==0; i++) {
      xmlfile.clear();

      // if no command-line arguments read data file from standard input
      if (numinputs < 1) {
         xmlfile.read(cin);
      } else {
         xmlfile.read(options.getArg(i+1));
      }

      xmlfile.printElementList(cout);
   }

   return 0;
}


///////////////////////////////////////////////////////////////////////////


//////////////////////////////
//
// checkOptions -- validate and process command-line options.
//

void checkOptions(Options& opts, int argc, char* argv[]) {

   opts.define("debug=b");              // determine bad input line num
   opts.define("author=b");             // author of program
   opts.define("version=b");            // compilation info
   opts.define("example=b");            // example usages
   opts.define("h|help=b");             // short description
   opts.process(argc, argv);
   
   // handle basic options:
   if (opts.getBoolean("author")) {
      cout << "Written by Craig Stuart Sapp, "
           << "craig@ccrma.stanford.edu, Jul 2011" << endl;
      exit(0);
   } else if (opts.getBoolean("version")) {
      cout << argv[0] << ", version: 10 Jul 2011" << endl;
      cout << "compiled: " << __DATE__ << endl;
      cout << MUSEINFO_VERSION << endl;
      exit(0);
   } else if (opts.getBoolean("help")) {
      usage(opts.getCommand());
      exit(0);
   } else if (opts.getBoolean("example")) {
      example();
      exit(0);
   }

}



//////////////////////////////
//
// example -- example usage of the quality program
//

void example(void) { }



//////////////////////////////
//
// usage -- gives the usage statement for the meter program
//

void usage(const char* command) { }


// md5sum: 1f93d7a4f4eb20a0bbd8d71c4c3964c0 element.cpp [20110802]