From 73ebb2750c246c825147a3643171e8c3a971f508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Br=C3=BCckner?= Date: Fri, 23 Oct 2015 12:03:19 +0200 Subject: [PATCH] Better commandline parsing --- slsDetectorGui/src/qDetectorMain.cpp | 47 ++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 7777967fc..efffa5b96 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -25,6 +25,7 @@ // C++ Include Headers #include #include +#include using namespace std; @@ -47,9 +48,51 @@ int main (int argc, char **argv) { qDetectorMain::qDetectorMain(int argc, char **argv, QApplication *app, QWidget *parent) : QMainWindow(parent), theApp(app),myDet(0),detID(0),myPlot(0),tabs(0),isDeveloper(0){ -bool found; +// bool found; + int c; string configFName = ""; + optind=1; // Getting all the command line arguments + while(1) { + static struct option long_options[] = { + { "developer", no_argument, 0, 'd' }, + { "config", required_argument, 0, 'f' }, + { "id", required_argument, 0, 'i' }, + { "f", required_argument, 0, 'f' }, + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + c = getopt_long (argc, argv, "hdf:i:", long_options, NULL); + if (c == -1) break; + + switch (c) { + case 'd' : + isDeveloper=1; + break; + case 'f' : + configFName=string(optarg); + break; + case 'i' : + detID=atoi(optarg); + break; + case 'h' : + default: + cout << endl; + cout << "\t" << argv[0] << " [ARGUMENT]..." << endl; + cout << endl; + cout << "Possible Arguments are:" << endl; + cout << "\t-d, --developer \t\t : \t Enables the developer tab" << endl; + cout << "\t-f, --f, --config fname\t\t : \t Loads config file fname" << endl; + cout << "\t-i, --id NUMBER \t\t : \t Sets the multi detector id to NUMBER (the default is 0). " + "Required only when more than one multi detector object is needed." << endl; + exit(-1); + } + } + if (optind < argc) { + cout << "invalid option, try --help" << endl; + exit(-1); + } +/* for(int iarg=1; iarg