//
// Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Dec  2 14:49:47 PST 2000
// Last Modified: Sat Dec  2 14:49:52 PST 2000
// Filename:      ...sig/examples/all/assemble.cpp
// Web Address:   http://sig.sapp.org/examples/museinfo/humdrum/assemble.cpp
// Syntax:        C++; museinfo
// 

#include "humdrum.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          debugQ     = 0;     // used with the --debug option
int          alloc      = 0;     // used with --alloc option


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

int main(int argc, char* argv[]) {

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

   // figure out the number of input files to process
   int numinputs = options.getArgCount();
   if (numinputs < 2) {
      return 0;
   }

   HumdrumFile infiles[numinputs];
   HumdrumFile output[numinputs];
   int i;
   for (i=0; i<options.getArgCount(); i++) {
      if (alloc > 0) {
         infiles[i].setAllocation(alloc);
      }
      infiles[i].read(options.getArg(i+1));
      if (i==0) {
         output[0] = infiles[0];
      } else {
         HumdrumFile::combine(output[i], output[i-1], infiles[i], debugQ);
      }
   }
   cout << output[numinputs-1];

   return 0;
}


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


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

void checkOptions(Options& opts, int argc, char* argv[]) {
   opts.define("alloc=i:0",  "specify allocation size for reading input");   
   opts.define("debug=b",  "trace input parsing");   
   opts.define("author=b",  "author of the program");   
   opts.define("version=b", "compilation information"); 
   opts.define("example=b", "example usage"); 
   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, Nov 2000" << endl;
      exit(0);
   } else if (opts.getBoolean("version")) {
      cout << argv[0] << ", version: Nov 2000" << 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);
   }

   alloc = options.getInteger("alloc");
   debugQ = opts.getBoolean("debug");
}



//////////////////////////////
//
// example -- example usage of the tertian program
//

void example(void) {
   cout <<
   "                                                                        \n"
   << endl;
}



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

void usage(const char* command) {
   cout <<
   "                                                                        \n"
   << endl;
}


// md5sum: 4bcc940573de69667f19b88f553590c1 assemble.cpp [20080920]