// // Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu> // Creation Date: Mon Jun 7 14:43:27 PDT 2010 // Last Modified: Mon Jun 7 14:43:31 PDT 2010 // Filename: ...sig/examples/all/musetype.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/musetype.cpp // Syntax: C++; museinfo // // Description: Print the record type for each line in a MuseData file. // Basic debugging program for parsing MuseData files. // #include "MuseData.h" #include "Options.h" #include "museinfo.h" #ifndef OLDCPP using namespace std; #endif // function declarations void checkOptions(Options& opts, int argc, char* argv[]); void example(void); void usage(const char* command); void printData(MuseData& infile); // global variables Options options; // database for command-line arguments int linenumberQ = 0; // used with -l option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { checkOptions(options, argc, argv); int numinputs = options.getArgCount(); MuseData infile; for (int i=0; i<numinputs || i==0; i++) { infile.clear(); // if no command-line arguments read data file from standard input if (numinputs < 1) { infile.read(cin); } else { infile.read(options.getArg(i+1)); } printData(infile); } return 0; } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // printData -- // void printData(MuseData& infile) { int i; for (i=0; i<infile.getNumLines(); i++) { if (linenumberQ) { cout << i+1 << ":"; } cout << (char)infile[i].getType() << '\t'; cout << infile[i] << endl; } } ////////////////////////////// // // checkOptions -- validate and process command-line options. // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("l|linenumber=b", "print the line number of each record"); 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, June 2010" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: 7 June 2010" << 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); } linenumberQ = opts.getBoolean("linenumber"); } ////////////////////////////// // // example -- example usage of the program // void example(void) { cout << " \n" << endl; } ////////////////////////////// // // usage -- gives the usage statement for the program // void usage(const char* command) { cout << " \n" << endl; } // md5sum: 8a129673760992b3d61a02ca00fc2445 musetype.cpp [20100607]