// // Programmer: Craig Stuart Sapp // Creation Date: Sat Aug 11 11:16:00 PDT 2012 // Last Modified: Sat Aug 11 11:16:10 PDT 2012 // Filename: ...sig/examples/all/scab.cpp // Web Address: http://sig.sapp.org/examples/museinfo/score/scab.cpp // Syntax: C++; museinfo // // Description: Display staff information for a SCORE page file. // #include "PerlRegularExpression.h" #include "ScorePageSet.h" #include "Options.h" #include #include #include // function declarations: void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void printAbsBeatInfo (ScorePageSet& work, Array& sysstaves); // block parsing functions: void fillFieldData (Array& field, const char* fieldstring, int maxval); void processFieldEntry (Array& field, const char* string, int maxval); void removeDollarsFromString(Array& buffer, int maxval); void printInfo (ScorePage& page); // interface variables: Options options; int verboseQ = 0; // used with -v option int debugQ = 0; // used with --debug option int breakQ = 0; // used with -b option int infoQ = 0; // used with -i option int staffQ = 0; // used with -s option int plainQ = 0; // used with -p option int htmlQ = 0; // used with -h option ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { checkOptions(options, argc, argv); int i; ScorePageSet work; for (i=1; i<=options.getArgCount(); i++) { work.appendRead(options.getArg(i), verboseQ); } work.analyzeContent(); // determine the extraction staves Array sysstaves; if (staffQ) { fillFieldData(sysstaves, options.getString("staff-list"), work.getPartCount()); for (i=0; i& sysstaves) { Array filter(work.getSystemStaffCount()); filter.setAll(0); int i; for (i=0; i& field, const char* fieldstring, int maxval) { field.setSize(maxval); field.setGrowth(0); field.setAll(0); Array tempfield; tempfield.setSize(maxval); tempfield.setSize(0); PerlRegularExpression pre; Array buffer; buffer.setSize(strlen(fieldstring)+1); strcpy(buffer.getBase(), fieldstring); pre.sar(buffer, "\\s", "", "gs"); int start = 0; int value = 0; value = pre.search(buffer.getBase(), "^([^,]+,?)"); while (value != 0) { start += value - 1; start += strlen(pre.getSubmatch(1)); processFieldEntry(tempfield, pre.getSubmatch(), maxval); value = pre.search(buffer.getBase() + start, "^([^,]+,?)"); } if (debugQ) { cout << "# tempfield: " << tempfield << endl; } field = tempfield; //int i; //for (i=0; i& field, const char* string, int maxval) { PerlRegularExpression pre; Array buffer; buffer.setSize(strlen(string)+1); strcpy(buffer.getBase(), string); // remove any comma left at end of input string (or anywhere else) pre.sar(buffer, ",", " ", "g"); pre.sar(buffer, "\\s+$", ""); pre.sar(buffer, "^\\s+", ""); if (debugQ) { cout << "MAXBLOCK = " << maxval << endl; cout << "INPUT BLOCK STRING TO DOLLAR: " << buffer << endl; } // first remove $ symbols and replace with the correct values removeDollarsFromString(buffer, maxval); if (debugQ) { cout << "OUTPUT BLOCK STRING FROM DOLLAR: " << buffer << endl; } if (pre.search(buffer.getBase(), "^(\\d+)-(\\d+)$")) { int firstone = strtol(pre.getSubmatch(1), NULL, 10); int lastone = strtol(pre.getSubmatch(2), NULL, 10); if ((firstone < 1) && (firstone != 0)) { cerr << "Error: range token: \"" << string << "\"" << " contains too small a number at start: " << firstone << endl; cerr << "Minimum number allowed is " << 1 << endl; exit(1); } if ((lastone < 1) && (lastone != 0)) { cerr << "Error: range token: \"" << string << "\"" << " contains too small a number at end: " << lastone << endl; cerr << "Minimum number allowed is " << 1 << endl; exit(1); } if (firstone > maxval) { cerr << "Error: range token: \"" << string << "\"" << " contains number too large at start: " << firstone << endl; cerr << "Maximum number allowed is " << maxval << endl; exit(1); } if (lastone > maxval) { cerr << "Error: range token: \"" << string << "\"" << " contains number too large at end: " << lastone << endl; cerr << "Maximum number allowed is " << maxval << endl; exit(1); } int i; if (firstone > lastone) { for (i=firstone; i>=lastone; i--) { field.append(i); } } else { for (i=firstone; i<=lastone; i++) { field.append(i); } } } else if (pre.search(buffer.getBase(), "^(\\d+)")) { int value = strtol(pre.getSubmatch(1), NULL, 10); if ((value < 1) && (value != 0)) { cerr << "Error: range token: \"" << string << "\"" << " contains too small a number at end: " << value << endl; cerr << "Minimum number allowed is " << 1 << endl; exit(1); } if (value > maxval) { cerr << "Error: range token: \"" << string << "\"" << " contains number too large at start: " << value << endl; cerr << "Maximum number allowed is " << maxval << endl; exit(1); } field.append(value); } } ////////////////////////////// // // removeDollarsFromString -- substitute $ sign for maximum track count. // void removeDollarsFromString(Array& buffer, int maxval) { PerlRegularExpression pre; char buf2[128] = {0}; int value2; if (debugQ) { cout << "IN DOLLAR STRING MAXBLOCK = " << maxval << endl; } if (pre.search(buffer.getBase(), "\\$$")) { sprintf(buf2, "%d", maxval); pre.sar(buffer, "\\$$", buf2); } if (debugQ) { cout << "IN DOLLAR STRING = " << buffer << endl; } if (pre.search(buffer.getBase(), "\\$(?![\\d-])")) { // don't know how this case could happen, however... sprintf(buf2, "%d", maxval); pre.sar(buffer, "\\$(?![\\d-])", buf2, "g"); } if (pre.search(buffer.getBase(), "\\$0")) { // replace $0 with maxval (used for reverse orderings) sprintf(buf2, "%d", maxval); pre.sar(buffer, "\\$0", buf2, "g"); } while (pre.search(buffer.getBase(), "\\$(-?\\d+)")) { value2 = maxval - (int)fabs(strtol(pre.getSubmatch(1), NULL, 10)); sprintf(buf2, "%d", value2); pre.sar(buffer, "\\$-?\\d+", buf2); } } // // Spine field list extraction functions // /////////////////////////////////////////////////////////////////////////// // md5sum: 83e9b976dd2e3af3f8890573fcfa2cdf scab.cpp [20120903]