File: commandoptionparser.cpp

package info (click to toggle)
mothur 1.48.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,692 kB
  • sloc: cpp: 161,866; makefile: 122; sh: 31
file content (59 lines) | stat: -rwxr-xr-x 2,445 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 *  commandoptionparser.cpp
 *  
 *
 *  Created by Pat Schloss on 10/23/08.
 *  Copyright 2008 Patrick D. Schloss. All rights reserved.
 *
 */


#include "commandoptionparser.hpp"


//**********************************************************************************************************************
//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();
        CurrentFile* current = CurrentFile::getInstance();
		
		int openParen = input.find_first_of('(');
		int closeParen = input.find_last_of(')');
		optionString = "";
		commandString = "";
       
        if(openParen != string::npos && closeParen != string::npos){
            //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 ")".
            if (!(commandString == "set.logfile")) {
                if (m->getLogFileName() == "") {
                    time_t ltime = time(nullptr); /* calendar time */
                    string outputPath = current->getOutputDir();
                    string logFileName = outputPath + "mothur." + toString(ltime) + ".logfile";
                    m->setLogFileName(logFileName, false);
                }
            }
		}
		else if (openParen == -1) { m->mothurOut("[ERROR]: You are missing (\n");  }
		else if (closeParen == -1) { m->mothurOut("[ERROR]: You are missing )\n"); }
    }
	catch(exception& e) {
		m->errorOut(e, "CommandOptionParser", "CommandOptionParser");
		exit(1);
	}
}

//**********************************************************************************************************************

string CommandOptionParser::getCommandString()	{	return commandString;	}

//**********************************************************************************************************************

string CommandOptionParser::getOptionString()	{	return optionString;	}

//**********************************************************************************************************************