[Compbench-devel] CompBenchmarks++ cloptions.cpp,1.14,1.15
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-02-05 20:07:48
|
Update of /cvsroot/compbench/CompBenchmarks++ In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv21607 Modified Files: cloptions.cpp Log Message: Many improvements : option categories. Handling refactored. Index: cloptions.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/cloptions.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** cloptions.cpp 31 Jan 2007 20:45:48 -0000 1.14 --- cloptions.cpp 5 Feb 2007 20:07:41 -0000 1.15 *************** *** 17,27 **** using namespace CBM; extern int optind, opterr, optopt; int parseExitValue = -1; - int optQuery = 0; - int optQueryAll = 0; - void cbmOptionsHelp(void) { --- 17,40 ---- using namespace CBM; + typedef enum { + DomainUndef, DomainHelp, DomainQuery, DomainVersion, + DomainManage, DomainLowLevel, DomainBench + } OptDomain; + + typedef struct { + unsigned int all:1; + unsigned int installed:1; + unsigned int package:1; + unsigned int benchmark:1; + } OptFilter; + + typedef enum { + ActionUndef, ActionInstall, ActionUninstall + } OptAction; + extern int optind, opterr, optopt; int parseExitValue = -1; void cbmOptionsHelp(void) { *************** *** 59,62 **** --- 72,87 ---- } + void cbmSingleDomain(OptDomain *domain, OptDomain value, std::string opt) + { + std::string str; + if (*domain!=DomainUndef) { + str="Unexpected option : "; + str+=opt; + CBM::cbmUI->Fatal(str); + } else { + *domain=value; + } + } + void cbmUnknownBenchmark(char *bench) { *************** *** 151,167 **** std::string options; static const struct option long_options[] = { {"help", no_argument, 0, 'h' }, {"version", no_argument, 0, 'v'}, ! {"install", required_argument, 0, 'i' }, {"fetch", required_argument, 0, 'f'}, - {"uninstall", required_argument, 0, 'u' }, - {"query", 0, 0, 'q' }, {"all", 0, 0, 'a' }, {"package", optional_argument, 0, 'p' }, ! {"package-benchmarks-info", 1, 0, 'I' }, {"benchmarks-info", 0, 0, 'L'}, --- 176,204 ---- std::string options; + OptDomain domain = DomainUndef; /* help/query/{install/uninstall : manage ?}/bench/version/low-level */ + OptAction action = ActionUndef; /* (install/uninstall/fetch, etc.) */ + OptFilter filter = { 0 }; /* <empty>/all/installed */ + std::string object_t; /* package/benchmark/host/compiler */ + static const struct option long_options[] = { {"help", no_argument, 0, 'h' }, + {"query", no_argument, 0, 'q' }, {"version", no_argument, 0, 'v'}, ! {"manage", no_argument, 0, 'm'}, ! {"low-level", no_argument, 0, 'M'}, ! {"bench", no_argument, 0, 'B'}, ! {"filter-installed", no_argument, 0, 'i'}, ! {"install", required_argument, 0, 'I' }, ! {"uninstall", required_argument, 0, 'U' }, ! {"fetch", required_argument, 0, 'f'}, {"all", 0, 0, 'a' }, {"package", optional_argument, 0, 'p' }, ! {"benchmark", optional_argument, 0, 'b' }, ! ! /* {"package-benchmarks-info", 1, 0, 'I' }, */ {"benchmarks-info", 0, 0, 'L'}, *************** *** 189,193 **** break; ! c = getopt_long (argc, argv, "hvi:f:u:qp::a", // uLHPCFIB", /* :011000112", */ long_options, &option_index); if (c==-1) { --- 226,230 ---- break; ! c = getopt_long (argc, argv, "hviI:f:U:qp::b::aM", // uLHPCFIB", /* :011000112", */ long_options, &option_index); if (c==-1) { *************** *** 197,246 **** switch (c) { case 'v': ! std::cout << VERSION << std::endl; ! parseExitValue=0; break; case 'q': ! optQuery=1; break; case 'a': ! optQueryAll=1; break; ! case 'h': ! cbmOptionsHelp(); ! parseExitValue=0; break; case 'p': ! printf("-p optarg=%s\n", optarg); ! if (!optQuery) { ! std::cerr << "-p option requires -q" << std::endl; ! parseExitValue=1; ! break; ! } ! ! if ((optarg) && (!optQueryAll)) { P=cbmOptionsExpectPackage(optarg); - if (P) - P->display(); - parseExitValue=0; - } else { - if (optQueryAll) { - if (optarg) { - std::cerr << "-qap options' set don't expect any argument" << std::endl; - } else { - printf("qap\n"); - // !!! - } - } else { - printf("there %x\n", (unsigned int) optarg); - if (optarg) { - P=cbmOptionsExpectPackage(optarg); - if (P) - P->display(); - parseExitValue=0; - } else { - P=cbmOptionsExpectPackage(optarg); - } - } - } break; /* --- 234,260 ---- switch (c) { case 'v': ! cbmSingleDomain(&domain, DomainVersion, "v"); break; case 'q': ! cbmSingleDomain(&domain, DomainQuery, "v"); ! // optQuery=1; ! break; ! case 'h': ! domain=DomainHelp; ! break; ! case 'm': ! domain=DomainManage; break; case 'a': ! filter.all=1; break; ! case 'i': ! filter.installed=1; break; case 'p': ! filter.package=1; ! filter.benchmark=0; ! if (optarg) P=cbmOptionsExpectPackage(optarg); break; /* *************** *** 253,268 **** !!! */ ! case 'i': P=cbmOptionsExpectPackage(optarg); - if (P) - parseExitValue=P->Install(UO_force); break; ! case 'u': P=cbmOptionsExpectPackage(optarg); - if (P) - parseExitValue=P->Uninstall(); break; case 'L': ! cbmSystem->displayAllBenchmarks(); parseExitValue=0; break; --- 267,287 ---- !!! */ ! case 'b': ! filter.package=0; ! filter.benchmark=1; ! if (optarg) ! B=cbmOptionsExpectBenchmark(optarg); ! break; ! ! case 'I': ! action=ActionInstall; P=cbmOptionsExpectPackage(optarg); break; ! case 'U': ! action=ActionUninstall; P=cbmOptionsExpectPackage(optarg); break; case 'L': ! /* cbmSystem->displayAllBenchmarks(); */ /* !!! */ parseExitValue=0; break; *************** *** 274,282 **** break; case 'H': ! cbmSystem->display(); parseExitValue=0; break; case 'P': ! cbmSystem->displayPrograms(); parseExitValue=0; break; --- 293,301 ---- break; case 'H': ! /* cbmSystem->display(); */ /* !!! */ parseExitValue=0; break; case 'P': ! /* cbmSystem->displayPrograms(); */ /* !!! */ parseExitValue=0; break; *************** *** 284,296 **** C=SC.select((char*) optarg); if (C) { ! C->display(); parseExitValue=0; } else parseExitValue=1; break; ! case 'I': B=cbmOptionsExpectBenchmark(optarg); if (B) { ! B->display(); parseExitValue=0; } --- 303,315 ---- C=SC.select((char*) optarg); if (C) { ! /* C->display(); */ /* !!! */ parseExitValue=0; } else parseExitValue=1; break; ! case 045: /* !!! */ B=cbmOptionsExpectBenchmark(optarg); if (B) { ! /* B->display(); */ /* !!! */ parseExitValue=0; } *************** *** 349,352 **** --- 368,372 ---- break; case 'B': + /* B=cbmOptionsExpectBenchmark(optarg); if (!B) *************** *** 395,398 **** --- 415,419 ---- parseExitValue=0; + */ break; case '?': *************** *** 400,403 **** --- 421,522 ---- } } + + switch(domain) { + case DomainVersion: + if ((!filter.all) && + (!filter.installed) && + (!filter.benchmark) && + (!filter.package) && + (action==ActionUndef)) { + std::cout << VERSION << std::endl; + parseExitValue=0; + } + break; + case DomainHelp: + cbmOptionsHelp(); + parseExitValue=0; + break; + case DomainQuery: + if (filter.package) { + if ((filter.all) && (!filter.installed)) { + int i; + int n = cbmSystem->packageNumber(); + + for(i=0; i<n; i++) { + P=cbmSystem->Package(i); + std::cout << P->Name() << " " << P->Version() << std::endl; + } + parseExitValue=0; + } + + if ((!filter.all) && (filter.installed)) { + int i; + int n = cbmSystem->packageNumber(); + + for(i=0; i<n; i++) { + P=cbmSystem->Package(i); + if (P->getStatus()>=CBM::Package::Preconfigured) { + std::cout << P->Name() << " " << P->Version() << std::endl; + } + } + parseExitValue=0; + } + } else if (filter.benchmark) { + if ((filter.all) && (!filter.installed)) { + int i; + int n = cbmSystem->packageNumber(); + int j; + int m; + + for(i=0; i<n; i++) { + P=cbmSystem->Package(i); + m=P->benchmarkNumber(); + for(j=0; j<m; j++) { + B=P->Benchmark(j); + std::cout << B->Name() << std::endl; + } + } + parseExitValue=0; + } + + if ((!filter.all) && (filter.installed)) { + int i; + int n = cbmSystem->packageNumber(); + int j; + int m; + + for(i=0; i<n; i++) { + P=cbmSystem->Package(i); + if (P->getStatus()>=CBM::Package::Preconfigured) { + m=P->benchmarkNumber(); + for(j=0; j<m; j++) { + B=P->Benchmark(j); + std::cout << B->Name() << std::endl; + } + } + } + parseExitValue=0; + } + } + break; + case DomainManage: + switch(action) { + case ActionInstall: + if (P) + parseExitValue=!P->Install(UO_force); + break; + case ActionUninstall: + if (P) { + parseExitValue=!P->Uninstall(); + if (parseExitValue) { + std::cerr << "Can't uninstall package." << std::endl; + } + } + break; + case ActionUndef: + std::cerr << "action not specified." << std::endl; + } + } + cbmSystem->done(); exit(parseExitValue); |