//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Tue Nov 14 16:32:36 PST 2000
// Last Modified: Tue Nov 14 16:32:39 PST 2000
// Filename: ...sig/examples/all/ditto.cpp
// Web Address: http://sig.sapp.org/examples/museinfo/humdrum/ditto.cpp
// Syntax: C++; museinfo
//
// Description: Fills in the meaning of null tokens.
//
#include "humdrum.h"
// function declarations
void checkOptions(Options& opts, int argc, char* argv[]);
void example(void);
void printOutput(HumdrumFile& infile);
void usage(const char* command);
// global variables
Options options; // database for command-line arguments
int parensQ = 0; // used with the -p option
///////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
HumdrumFile infile;
// 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++) {
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));
}
printOutput(infile);
}
return 0;
}
///////////////////////////////////////////////////////////////////////////
//////////////////////////////
//
// checkOptions -- validate and process command-line options.
//
void checkOptions(Options& opts, int argc, char* argv[]) {
opts.define("p|parens=b", "print parentheses around ditto data");
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, Nov 2000" << endl;
exit(0);
} else if (opts.getBoolean("version")) {
cout << argv[0] << ", version: 14 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);
}
parensQ = opts.getBoolean("parens");
}
//////////////////////////////
//
// example -- example usage of the ditto program
//
void example(void) {
cout <<
" \n"
<< endl;
}
//////////////////////////////
//
// printOutput -- display the filled results
//
void printOutput(HumdrumFile& infile) {
int i, j;
for (i=0; i<infile.getNumLines(); i++) {
if (infile[i].getType() && (E_humrec_data == 0)) {
cout << infile[i].getLine() << "\n";
} else {
for (j=0; j<infile[i].getFieldCount(); j++) {
if (strcmp(infile[i][j], ".") == 0) {
if (parensQ) {
cout << "(";
}
cout << infile.getDotValue(i, j);
if (parensQ) {
cout << ")";
}
} else {
cout << infile[i][j];
}
if (j < infile[i].getFieldCount() - 1) {
cout << "\t";
}
}
cout << "\n";
}
}
}
//////////////////////////////
//
// usage -- gives the usage statement for the ditto program
//
void usage(const char* command) {
cout <<
" \n"
<< endl;
}
// md5sum: fd59e6c3941038fd1f49b8c0a15c8713 ditto.cpp [20050403]