diff options
Diffstat (limited to 'vmchooser/main.cxx')
-rw-r--r-- | vmchooser/main.cxx | 188 |
1 files changed, 97 insertions, 91 deletions
diff --git a/vmchooser/main.cxx b/vmchooser/main.cxx index 531dfc9..84e4a60 100644 --- a/vmchooser/main.cxx +++ b/vmchooser/main.cxx @@ -6,6 +6,7 @@ #include "inc/SWindow.h" #include "inc/DataEntry.h" #include "inc/functions.h" +#include "inc/anyoption.h" using namespace std; using namespace fltk; @@ -21,98 +22,103 @@ using namespace fltk; * * */ -int main(int argc, char** argv) -{ +int main(int argc, char** argv) { + AnyOption* opt = new AnyOption(); + char* xmlpath = NULL; + char* slxgroup = NULL; + char* lsesspath = NULL; + + opt->setVerbose(); + opt->autoUsagePrint(true); + + opt->addUsage(""); + opt->addUsage("SessionChooser Usage:"); + opt->addUsage("\t{-p |--path=} path to vmware (.xml) files"); + opt->addUsage("\t{-l |--lpath=} path to linux session (.desktop) files"); + opt->addUsage("\t{-g |--group=} group name"); + opt->addUsage("\t{-h |--help} prints help"); + opt->addUsage(""); + + opt->setFlag("help",'h'); + opt->setOption("path", 'p'); + opt->setOption("lpath", 'l'); + opt->setOption("group",'g'); + + opt->processCommandArgs(argc, argv); + + /** HELP */ + if(opt->getFlag("help") || opt->getFlag('h')) { + opt->printUsage(); + return 1; + } + + /** XML - PATH */ + if(opt->getValue('p')!=NULL) { + xmlpath = opt->getValue('p'); + } + if(opt->getValue("path")!= NULL) { + xmlpath = opt->getValue("path"); + } + if (xmlpath == NULL) { + //xmlpath="../../../../../../../session-choosers/xml/"; + xmlpath = "/var/lib/vmware/"; + } + + /** SLX GROUP */ + if(opt->getValue('g')!=NULL) { + xmlpath = opt->getValue('g'); + } + if(opt->getValue("group")!= NULL) { + xmlpath = opt->getValue("group"); + } + if (slxgroup == NULL) { + slxgroup = "default"; + } + + /** LINUX SESSION PATH */ + if(opt->getValue('l')!=NULL) { + lsesspath = opt->getValue('l'); + } + if(opt->getValue("lpath")!= NULL) { + lsesspath = opt->getValue("lpath"); + } + if (lsesspath == NULL) { + lsesspath = "/usr/share/xsessions/"; + } + + delete opt; + + /* read xml files */ + DataEntry** sessions = NULL; + DataEntry** lsessions = NULL; + if (xmlpath != NULL) { + sessions = readXmlDir(xmlpath); + } else { + fprintf(stderr,"Please give a path to xml directory for session images!"); + exit(1); + } + lsessions = readLinSess(lsesspath); + + SWindow& win = *SWindow::getInstance(); + + if(lsessions != NULL) { + win.set_lin_entries(lsessions, slxgroup); + } + if (sessions != NULL) { + win.set_entries(sessions, slxgroup); + } + + //cout << win.pname << endl; - if (argc > 1 && !(strcmp(argv[1],"-h") | strcmp(argv[1], "--help")) ) { - /* print help */ - printf("SessionChooser \n"); - printf("\t{-p |--path=}[path to vmware (.xml) files]\n"); - printf("\t{-l |--lpath=}[path to linux session (.desktop) files]\n"); - printf("\t{-g |--group=}[group name]\n"); - printf("\t{-h |--help}[ as first parameter - prints help ]\n"); - exit(0); - } + + win.unfold_entries(); + win.show(argc,argv); + win.border(false); - char* xmlpath = NULL; - char* slxgroup = NULL; - char* lsesspath = NULL; - - for (int i=0; i<argc; i++) { - /* Get path parameter - path to XML files */ - if (strstr(argv[i],"-p") != NULL) { - i++; - xmlpath = argv[i]; - } - if (strstr(argv[i],"--path=") != NULL) { - char* temp = strpbrk("=", argv[i] ); - xmlpath = (temp ++); - } - - /* Get path for linux sessions */ - if (strstr(argv[i],"-l") != NULL) { - i++; - lsesspath = argv[i]; - } - if (strstr(argv[i],"--lpath=") != NULL) { - char* temp = strpbrk("=", argv[i] ); - lsesspath = (temp ++); - } - - /* Get group parameter - SLXGroup */ - if (strstr(argv[i],"-g") != NULL) { - i++; - slxgroup = argv[i]; - } - if (strstr(argv[i],"--group=") != NULL) { - char* temp = strpbrk("=", argv[i] ); - slxgroup =( temp ++ ); - } - } - - if (xmlpath == NULL) { - xmlpath="../../../../../../../session-choosers/xml/"; - //xmlpath = "/var/lib/vmware/"; - } - if (slxgroup == NULL) { - slxgroup = "default"; - } - if (lsesspath == NULL) { - lsesspath = "/usr/share/xsessions/"; - } - - - /* read xml files */ - DataEntry** sessions = NULL; - DataEntry** lsessions = NULL; - if (xmlpath != NULL) { - sessions = readXmlDir(xmlpath); - } else { - fprintf(stderr,"Please give a path to xml directory for session images!"); - exit(1); - } - lsessions = readLinSess(lsesspath); - - SWindow& win = *SWindow::getInstance(); - - if(lsessions != NULL) { - win.set_lin_entries(lsessions, slxgroup); - } - if (sessions != NULL) { - win.set_entries(sessions, slxgroup); - } - - //cout << win.pname << endl; - - - win.unfold_entries(); - win.show(argc,argv); - win.border(false); - - bool retval = run(); - - win.free_entries(); - - return retval; + bool retval = run(); + + win.free_entries(); + + return retval; } |