X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=commandoptionparser.cpp;h=0038a714f4ae356e11d7dea57b4840a81eb946f4;hp=a46c0a6ccfc47859d06ae6cae21e87a441be460c;hb=cf9987b67aa49777a4c91c2d21f96e58bf17aa82;hpb=c5c7502f435e1413c19e373dab1dfebcaa67588d diff --git a/commandoptionparser.cpp b/commandoptionparser.cpp index a46c0a6..0038a71 100644 --- a/commandoptionparser.cpp +++ b/commandoptionparser.cpp @@ -8,10 +8,6 @@ */ -using namespace std; - - -#include "globaldata.hpp" #include "commandoptionparser.hpp" @@ -19,28 +15,28 @@ using namespace std; //This Function parses through the command line and pulls out the command then sends the options to the parseGlobalData CommandOptionParser::CommandOptionParser(string input){ try { + m = MothurOut::getInstance(); + int openParen = input.find_first_of('('); int closeParen = input.find_last_of(')'); - string optionString = ""; + optionString = ""; commandString = ""; - - if(openParen != -1 && closeParen != -1){ - commandString = input.substr(0, openParen); //commandString contains everything before "(" - optionString = input.substr(openParen+1, closeParen-openParen-1); //optionString contains everything between "(" and ")". + + if(openParen != -1 && closeParen != -1){ + //gobble extra spaces + int spot = 0; + for (int i = 0; i < input.length(); i++) { if (!(isspace(input[i]))) { spot = i; break; } } + if (spot > openParen) { spot = 0; } + commandString = input.substr(spot, openParen-spot); //commandString contains everything before "(" + optionString = input.substr((openParen+1), (closeParen-openParen-1)); //optionString contains everything between "(" and ")". } - - GlobalData* globaldata = GlobalData::getInstance(); - globaldata->parseGlobalData(commandString, optionString); //parser to separate and check options - } + else if (openParen == -1) { m->mothurOut("[ERROR]: You are missing ("); m->mothurOutEndLine(); } + else if (closeParen == -1) { m->mothurOut("[ERROR]: You are missing )"); m->mothurOutEndLine(); } + } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the CommandOptionParser class Function CommandOptionParser. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the CommandOptionParser class function CommandOptionParser. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "CommandOptionParser", "CommandOptionParser"); exit(1); } - } //********************************************************************************************************************** @@ -48,3 +44,7 @@ CommandOptionParser::CommandOptionParser(string input){ string CommandOptionParser::getCommandString() { return commandString; } //********************************************************************************************************************** + +string CommandOptionParser::getOptionString() { return optionString; } + +//**********************************************************************************************************************