int main(int argc, char *argv[]) { Ensemble ensemble; // Note that ensemble is internally converted to pointer-type SyncFiles syncFiles(ensemble); std::string noteOpts; // Annotation *notes=0; std::string annotText; std::string outputText; std::string path; if( argc == 1 ) { syncFiles.description(); return 3; } GetOpt opt; opt.opterr=0; int copt; std::string str; std::string str0; std::string oStr("Ad:Ehl:mMP:p:St:T"); oStr += "<--only-marked>"; oStr += "<--help>"; oStr += "<--line-feed>:"; oStr += "<--note>:"; while( (copt = opt.getopt(argc, argv, oStr.c_str() )) != -1 ) { if( opt.longOption > 0 ) { str0=opt.longOption; if( str0 == "--help" ) { syncFiles.description(); return 3; } if( str0 == "--line-feed" ) { syncFiles.enableNewLine(opt.optarg); continue; } if( str0 == "--note" ) { noteOpts=opt.optarg; continue; } if( str0 == "--only-marked" ) { syncFiles.isPrintOnlyMarked=true; continue; } } switch ( copt ) { case 'A': //obsolete break; case 'd': { str0=opt.optarg; std::string str("_"); size_t p=0; if( (p=str0.find('/')) < std::string::npos ) str = str0.replace(p, 0, "_") ; // is a range else if( (p=str0.find('-')) < std::string::npos ) str = str0.replace(p, 0, "_") ; // is a range else if( hdhC::isNumber(str0) ) str += str0 ; // end time else return 3; syncFiles.setTimeLimit(str) ; } break; case 'E': syncFiles.enablePrintEnsemble(); break; case 'h': syncFiles.description(); return 3; break; case 'l': syncFiles.setTimeLimit(opt.optarg); break; case 'm': syncFiles.enableMixingRefused(); break; case 'M': syncFiles.enableModificationTimeTest(); break; case 'P': path = opt.optarg ; syncFiles.setPath(path) ; break; case 'p': syncFiles.setQA_target(opt.optarg) ; break; case 'S': // printing date range of each file in output requested syncFiles.enablePrintDateRange(); break; case 't': { str0=opt.optarg; std::string str("/"); size_t p=0; if( (p=str0.find('-')) < std::string::npos ) str = str0.replace(p, 0, "/") ; // is a range else if( (p=str0.find('/')) < std::string::npos ) str = str0 ; // is a range separated by '/' else if( hdhC::isNumber(str0) ) str += str0 ; // end time else return 3; syncFiles.setTimeLimit(str) ; } break; case 'T': syncFiles.enablePrintTotalTimeRange() ; break; default: std::ostringstream ostr(std::ios::app); ostr << "syncFiles:getopt() unknown option -" ; ostr << copt; ostr << "\nreturned option -" << copt ; std::cout << ostr.str() << std::endl ; break; } } // Note= argc counts from 1, but argv[0] == this executable if( opt.optind == argc ) syncFiles.readInput(); else syncFiles.readArgv(opt.optind, argc, argv); // this does all return syncFiles.run(); }
void parseOptions(int argc, char *org_argv[], IObjContainer &ioc) { GetOpt opt; opt.opterr=0; int copt; std::string str0("null"); std::string str1; // std::vector<std::string> inputFilename; std::vector<std::string> outputFilename; // working with std::string is preferred std::vector<std::string> argv; for( int i=0 ; i < argc ; ++i) argv.push_back( org_argv[i] ); // read options from file? readOptions(argv); int sz=argv.size(); // printing is split, so remember bool isPrintTest=false; // getopt expects char*[]. char **pargv = new char* [sz+1] ; for( int i=0 ; i < sz ; ++i ) pargv[i] = const_cast<char*>(argv[i].c_str()); while( (copt = opt.getopt(sz, pargv, "f:p:t:v:<--cpu-time><--help><--post><--printTest>")) != -1 ) { if( opt.longOption > 0 ) str0=opt.longOption; if( opt.longOption && str0 == "--help" ) { Base::help(); // CellStatistics::help(); FD_interface::help(); InFile::help(); // Oper::help(); // OutFile::help(); QA::help(); // TimeControl::help(); exit(1); } if( opt.longOption && str0 == "--cpu-time" ) { isCPU_time=true; continue; } if( opt.longOption && str0 == "--post" ) { isPostProc=true; continue; } if( opt.longOption && str0 == "--printTest" ) { isPrintTest=true; continue; } switch ( copt ) { case 'f': ::NC_FILENAME = opt.optarg ; break; case 'p': ::NC_PATH = opt.optarg ; break; case 't': ::TABLE_PATH = opt.optarg ; break; default: // description(); break; } } // Note: pargv are pointers to argv items. std::vector<std::string> aargv; for( int i=opt.optind ; i < sz ; ++i) aargv.push_back( pargv[i] ); argv = aargv ; delete[] pargv ; // parse argv for instructions of making objects // and their linkage. Parse parse(argv); std::vector<std::vector<std::string> > linkList = parse.getLinkList(); if( isPrintTest ) parse.printList(); // exits // objects are created makeObject(linkList, ioc); // apply parameters to objects setObjProperties(linkList, ioc); linkObj(linkList, ioc); scanGdRelation(linkList, ioc); return ; }