]> git.donarmstrong.com Git - mothur.git/blob - commandoptionparser.cpp
added modify names parameter to set.dir
[mothur.git] / commandoptionparser.cpp
1 /*
2  *  commandoptionparser.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 10/23/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10
11 #include "commandoptionparser.hpp"
12
13
14 //**********************************************************************************************************************
15 //This Function parses through the command line and pulls out the command then sends the options to  the parseGlobalData
16 CommandOptionParser::CommandOptionParser(string input){
17         try {
18                 m = MothurOut::getInstance();
19                 
20                 int openParen = input.find_first_of('(');
21                 int closeParen = input.find_last_of(')');
22                 optionString = "";
23                 commandString = "";
24
25                 if(openParen != -1 && closeParen != -1){        
26             //gobble extra spaces
27             int spot = 0;
28             for (int i = 0; i < input.length(); i++) {  if (!(isspace(input[i]))) { spot = i; break; } }
29             if (spot > openParen) { spot = 0; }
30                         commandString = input.substr(spot, openParen-spot);   //commandString contains everything before "("
31                         optionString = input.substr((openParen+1), (closeParen-openParen-1)); //optionString contains everything between "(" and ")".
32                 }
33                 else if (openParen == -1) { m->mothurOut("[ERROR]: You are missing ("); m->mothurOutEndLine(); }
34                 else if (closeParen == -1) { m->mothurOut("[ERROR]:You are missing )"); m->mothurOutEndLine(); }
35     }
36         catch(exception& e) {
37                 m->errorOut(e, "CommandOptionParser", "CommandOptionParser");
38                 exit(1);
39         }
40 }
41
42 //**********************************************************************************************************************
43
44 string CommandOptionParser::getCommandString()  {       return commandString;   }
45
46 //**********************************************************************************************************************
47
48 string CommandOptionParser::getOptionString()   {       return optionString;    }
49
50 //**********************************************************************************************************************