5 * Created by Pat Schloss on 8/15/08.
6 * Copyright 2008 Patrick D. Schloss. All rights reserved.
8 * There's a TON of duplicated code between InteractEngine and BatchEngine
9 * I couldn't figure out how to transition between ifstream (batch) and cin (interact)
10 * Fix later, don't have time now.
17 /***********************************************************************/
19 InteractEngine::InteractEngine(string path){
21 globaldata = GlobalData::getInstance();
22 globaldata->argv = path;
26 // ifstream header("introtext.txt");
27 // while(!header.eof()){
29 // buffer = header.get();
33 /***********************************************************************/
35 InteractEngine::~InteractEngine(){
38 /***********************************************************************/
39 //This function allows the user to input commands one line at a time until they quit.
40 //If the command is garbage it does nothing.
41 bool InteractEngine::getInput(){
44 string commandName = "";
46 int quitCommandCalled = 0;
48 //ErrorCheck* errorCheckor = new ErrorCheck();
50 cout << "mothur v.1.3.0" << endl;
51 cout << "Last updated: 5/29/2009" << endl << endl;
53 cout << "Patrick D. Schloss" << endl << endl;
54 cout << "Department of Microbiology" << endl;
55 cout << "The University of Massachusetts" << endl;
56 cout << "pschloss@micro.umass.edu" << endl;
57 cout << "http://schloss.micro.umass.edu/mothur" << endl << endl << endl;
58 cout << "Distributed under the GNU General Public License" << endl << endl;
59 cout << "Type 'help()' for information on the commands that are available" << endl << endl;
60 cout << "Type 'quit()' to exit program" << endl;
62 while(quitCommandCalled != 1){
64 cout << endl << "mothur > ";
66 if (cin.eof()) { input = "quit()"; }
68 //allow user to omit the () on the quit command
69 if (input == "quit") { input = "quit()"; }
71 //errorFree = errorCheckor->checkInput(input);
72 //if (errorFree == true) {
73 CommandOptionParser parser(input);
74 commandName = parser.getCommandString();
75 options = parser.getOptionString();
77 if (commandName != "") {
79 //executes valid command
80 CommandFactory cFactory;
81 Command* command = cFactory.getCommand(commandName, options);
82 quitCommandCalled = command->execute();
85 cout << "Your input contains errors. Please try again." << endl;
91 cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
95 cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
101 /***********************************************************************/
102 //This function opens the batchfile to be used by BatchEngine::getInput.
103 BatchEngine::BatchEngine(string path, string batchFileName){
105 globaldata = GlobalData::getInstance();
106 openedBatch = openInputFile(batchFileName, inputBatchFile);
107 globaldata->argv = path;
111 // char buffer = ' ';
112 // ifstream header("introtext.txt");
113 // while(!header.eof()){
115 // buffer = header.get();
118 catch(exception& e) {
119 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 /***********************************************************************/
130 BatchEngine::~BatchEngine(){
133 /***********************************************************************/
134 //This Function allows the user to run a batchfile containing several commands on Dotur
135 bool BatchEngine::getInput(){
137 //check if this is a valid batchfile
138 if (openedBatch == 1) { cout << "unable to open batchfile" << endl; return 1; }
141 string commandName = "";
144 //CommandFactory cFactory;
145 int quitCommandCalled = 0;
147 while(quitCommandCalled == 0){
149 if (inputBatchFile.eof()) { input = "quit()"; }
150 else { getline(inputBatchFile, input); }
152 if (input[0] != '#') {
154 cout << endl << "mothur > " << input << endl;
156 //allow user to omit the () on the quit command
157 if (input == "quit") { input = "quit()"; }
159 CommandOptionParser parser(input);
160 commandName = parser.getCommandString();
161 options = parser.getOptionString();
163 if (commandName != "") {
165 //executes valid command
166 CommandFactory cFactory;
167 Command* command = cFactory.getCommand(commandName, options);
168 quitCommandCalled = command->execute();
169 }else { cout << "Invalid." << endl; }
175 catch(exception& e) {
176 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
180 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
186 /***********************************************************************/