[Compbench-devel] CompBenchmarks++/compbenchmarks-plan cloptions.cpp, NONE, 1.1 cloptions.h, NONE,
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-05-28 17:49:50
|
Update of /cvsroot/compbench/CompBenchmarks++/compbenchmarks-plan In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9908 Added Files: cloptions.cpp cloptions.h main.cpp main.h Makefile.am Log Message: First import. --- NEW FILE: cloptions.cpp --- /* ---------------------------------------------------------------------------- $Id: cloptions.cpp,v 1.1 2007/05/28 17:49:46 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <compbenchmarks-plan/cloptions.h> #include <Base/Config.h> #include <Plan/Plan.h> #include <UI/UI.h> #include <config.h> #include <iostream> #include <string> #include <unistd.h> #include <getopt.h> #include <stdio.h> using namespace CBM; typedef enum { ActionUndef, ActionRegisterPlan, ActionUnregisterPlan } OptAction; typedef struct { unsigned int defaultPlan:1; } OptFilter; extern int optind, opterr, optopt; int parseExitValue = -1; void cbmOptionsHelp(void) { std::cout << "Usage: compbenchmarks-core [OPTIONS]" << std::endl << "Plan management :" << std::endl << " --plan-register <file> [--default] : Create file[.xml] plan." << std::endl << " --plan-unregister <file> : Remove a plan." << std::endl << std::endl; } void appendXML(std::string& file) { unsigned int s = file.length(); if (s>=4) { if (file.find(".xml", 0)!=s-4) { file+=".xml"; } } else { file+=".xml"; } } int cbmPlanOptionsParse(int argc, char *argv[]) { int c; OptAction action = ActionUndef; /* (install/uninstall/fetch, etc.) */ OptFilter filter = { 0 }; /* <empty>/all/installed */ int not_done = 1; std::string planFileName; CBM::Plan *P; static const struct option long_options[] = { {"help", no_argument, 0, 'h' }, {"plan-register", required_argument, 0, 'r'}, {"plan-unregister", required_argument, 0, 'u'}, {"default", no_argument, 0, 1003}, {"version", no_argument, 0, 'v'}, { 0, 0, 0, 0} }; while (not_done) { int option_index = 0; if (parseExitValue!=-1) break; c = getopt_long (argc, argv, "hr:u::", long_options, &option_index); if (c==-1) { break; } switch (c) { case 'v': break; case 'h': break; case 'r': action=ActionRegisterPlan; planFileName=optarg; appendXML(planFileName); break; case 'u': action=ActionUnregisterPlan; planFileName=optarg; appendXML(planFileName); break; case 1003: filter.defaultPlan=1; if ((action!=ActionRegisterPlan) && (planFileName=="")) { planFileName=cbmSystem->Config()->getDefaultPlan(); } break; default: case '?': break; } } switch(action) { case ActionRegisterPlan: if (cbmSystem->fileExists(planFileName)) { std::cerr << "File " << planFileName << " exists." << std::endl << "Choose another name or use --unregister to remove this plan." << std::endl; break; } P = new CBM::Plan; parseExitValue=!(P->store(planFileName)); if (filter.defaultPlan) { cbmSystem->Config()->setDefaultPlan(planFileName); cbmSystem->storeConfiguration(); } if (!parseExitValue) { std::cout << planFileName << " created"; if (filter.defaultPlan) { std::cout << " (default plan)"; } std::cout << "." << std::endl; } delete(P); break; case ActionUnregisterPlan: if (filter.defaultPlan) { std::cerr << "--default not supported with this option." << std::endl; break; } P=new CBM::Plan; if (P->restore(planFileName)) { parseExitValue=!(cbmSystem->unlink(planFileName)); if (!parseExitValue) { if (cbmSystem->Config()->getDefaultPlan()!="") { std::string abs = cbmSystem->Config()->Path(CBM::System::CurrentWD); abs+="/"; abs+=planFileName; if (abs==cbmSystem->Config()->getDefaultPlan()) { cbmSystem->Config()->setDefaultPlan(""); cbmSystem->storeConfiguration(); std::cout << planFileName << " removed, and is not default plan anymore." << std::endl; } } else { std::cout << planFileName << " removed." << std::endl; } } } else { std::cerr << "Plan file not detected." << std::endl; } delete(P); break; default: printf("?\n"); break; } cbmSystem->done(); exit(parseExitValue); } --- NEW FILE: main.cpp --- /* ---------------------------------------------------------------------------- $Id: main.cpp,v 1.1 2007/05/28 17:49:46 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <config.h> #include <libcompbenchmarks.h> #include <compbenchmarks-plan/cloptions.h> int main(int argc, char *argv[]) { CBM_SYSTEM sys; int r; sys.init(); r=cbmPlanOptionsParse(argc, argv); sys.done(); return(r); } --- NEW FILE: Makefile.am --- # ----------------------------------------------------------------------------- # $Id: Makefile.am,v 1.1 2007/05/28 17:49:46 xfred Exp $ # # This is free software. # For details, see the GNU Public License in the COPYING file, or # Look http://www.fsf.org # ----------------------------------------------------------------------------- bin_PROGRAMS = compbenchmarks-plan compbenchmarks_plan_SOURCES = cloptions.cpp main.cpp libcompbenchmarksincludedir = $(includedir)/compbenchmarks compbenchmarks_plan_LDADD = ../libcompbenchmarks/libcompbenchmarks.la compbenchmarks_plan_DEPENDENCIES = ../libcompbenchmarks/libcompbenchmarks.la noinst_HEADERS = $(compbenchmarks_plan_SOURCES:.cpp=.h) # EXTRA_DIST = compbenchmarks-core.pod compbenchmarks-core.1 INCLUDES = -I $(top_srcdir)/libcompbenchmarks -I $(top_srcdir) # man_MANS = compbenchmarks-core.1 #compbenchmarks-core.1: compbenchmarks-core.pod # pod2man $< > $@ --- NEW FILE: cloptions.h --- /* ---------------------------------------------------------------------------- $Id: cloptions.h,v 1.1 2007/05/28 17:49:46 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMPLANCLOPTIONS #define H_CBMPLANCLOPTIONS 1 #include <libcompbenchmarks.h> /** Parse command line arguments. High-level function to parse arguments through getopt.h. */ int cbmPlanOptionsParse(int argc, char *argv[]); #endif --- NEW FILE: main.h --- /* ---------------------------------------------------------------------------- $Id: main.h,v 1.1 2007/05/28 17:49:46 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBMPLANMAIN #define H_CBMPLANMAIN #endif |