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();
107 openedBatch = openInputFile(batchFileName, inputBatchFile);
108 globaldata->argv = path;
112 // char buffer = ' ';
113 // ifstream header("introtext.txt");
114 // while(!header.eof()){
116 // buffer = header.get();
119 catch(exception& e) {
120 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 /***********************************************************************/
131 BatchEngine::~BatchEngine(){
134 /***********************************************************************/
135 //This Function allows the user to run a batchfile containing several commands on Dotur
136 bool BatchEngine::getInput(){
138 //check if this is a valid batchfile
139 if (openedBatch == 1) { cout << "unable to open batchfile" << endl; return 1; }
142 string commandName = "";
146 //CommandFactory cFactory;
147 int quitCommandCalled = 0;
149 while(quitCommandCalled == 0){
151 if (inputBatchFile.eof()) { input = "quit()"; }
152 else { getline(inputBatchFile, input); }
154 //cout << "command number" << count << endl; count++;
156 if (input[0] != '#') {
158 cout << endl << "mothur > " << input << endl;
160 //allow user to omit the () on the quit command
161 if (input == "quit") { input = "quit()"; }
163 CommandOptionParser parser(input);
164 commandName = parser.getCommandString();
165 options = parser.getOptionString();
167 if (commandName != "") {
169 //executes valid command
170 CommandFactory cFactory;
171 Command* command = cFactory.getCommand(commandName, options);
172 quitCommandCalled = command->execute();
173 }else { cout << "Invalid." << endl; }
176 gobble(inputBatchFile);
180 catch(exception& e) {
181 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
185 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
191 /***********************************************************************/
192 /***********************************************************************/
193 //This function opens the batchfile to be used by BatchEngine::getInput.
194 ScriptEngine::ScriptEngine(string path, string commandString){
196 globaldata = GlobalData::getInstance();
199 listOfCommands = commandString.substr(1, (commandString.length()-1));
201 globaldata->argv = path;
206 catch(exception& e) {
207 cout << "Standard Error: " << e.what() << " has occurred in the ScriptEngine class Function ScriptEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
211 cout << "An unknown error has occurred in the ScriptEngine class function ScriptEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
216 /***********************************************************************/
218 ScriptEngine::~ScriptEngine(){
221 /***********************************************************************/
222 //This Function allows the user to run a batchfile containing several commands on Dotur
223 bool ScriptEngine::getInput(){
227 string commandName = "";
231 //CommandFactory cFactory;
232 int quitCommandCalled = 0;
234 while(quitCommandCalled == 0){
236 input = getNextCommand(listOfCommands);
238 if (input == "") { input = "quit()"; }
239 //cout << "command number" << count << endl; count++;
241 cout << endl << "mothur > " << input << endl;
243 //allow user to omit the () on the quit command
244 if (input == "quit") { input = "quit()"; }
246 CommandOptionParser parser(input);
247 commandName = parser.getCommandString();
248 options = parser.getOptionString();
250 if (commandName != "") {
252 //executes valid command
253 CommandFactory cFactory;
254 Command* command = cFactory.getCommand(commandName, options);
255 quitCommandCalled = command->execute();
256 }else { cout << "Invalid." << endl; }
262 catch(exception& e) {
263 cout << "Standard Error: " << e.what() << " has occurred in the ScriptEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
267 cout << "An unknown error has occurred in the ScriptEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
271 /***********************************************************************/
272 string ScriptEngine::getNextCommand(string& commandString) {
274 string nextcommand = "";
276 nextcommand = commandString.substr(0,commandString.find_first_of(';'));
279 if ((commandString.find_first_of(';')+1) <= commandString.length()) {
280 commandString = commandString.substr(commandString.find_first_of(';')+1, commandString.length());
281 }else { commandString = ""; } //you have reached the last command.
283 //get rid of any extra spaces in between commands
284 //string space = " ";
286 //while(commandString.at(0) == ' ')
287 //commandString = commandString.substr(1, commandString.length());
291 catch(exception& e) {
292 cout << "Standard Error: " << e.what() << " has occurred in the ScriptEngine class Function getNextCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
296 cout << "An unknown error has occurred in the ScriptEngine class function getNextCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
300 /***********************************************************************/