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.
16 #include "utilities.hpp"
17 #include "globaldata.hpp"
18 #include "commandoptionparser.hpp"
19 #include "command.hpp"
20 #include "commandfactory.hpp"
21 #include "errorchecking.h"
24 /***********************************************************************/
26 InteractEngine::InteractEngine(){
28 globaldata = GlobalData::getInstance();
32 // ifstream header("introtext.txt");
33 // while(!header.eof()){
35 // buffer = header.get();
39 /***********************************************************************/
41 InteractEngine::~InteractEngine(){
44 /***********************************************************************/
45 //This function allows the user to input commands one line at a time until they quit.
46 //If the command is garbage it does nothing.
47 bool InteractEngine::getInput(){
50 string commandName = "";
51 int quitCommandCalled = 0;
53 ErrorCheck* errorCheckor = new ErrorCheck();
55 cout << "mothur v1.0" << endl;
56 cout << "Last updated: 1/29/2009" << endl << endl;
58 cout << "Patrick D. Schloss" << endl << endl;
59 cout << "Department of Microbiology" << endl;
60 cout << "The University of Massachusetts" << endl;
61 cout << "pschloss@micro.umass.edu" << endl;
62 cout << "http://schloss.micro.umass.edu/mothur" << endl << endl << endl;
63 cout << "Distributed under the GNU General Public License" << endl << endl;
64 cout << "Type 'help()' for information on the commands that are available" << endl << endl;
65 cout << "Type 'quit()' to exit program" << endl;
67 while(quitCommandCalled != 1){
69 cout << endl << "mothur > ";
71 if (cin.eof()) { input = "quit()"; }
73 errorFree = errorCheckor->checkInput(input);
74 if (errorFree == true) {
75 CommandOptionParser parser(input);
76 commandName = parser.getCommandString();
78 //executes valid command
79 CommandFactory cFactory;
80 Command* command = cFactory.getCommand(commandName);
81 quitCommandCalled = command->execute();
84 cout << "Your input contains errors. Please try again." << endl;
90 cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94 cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100 /***********************************************************************/
101 //This function opens the batchfile to be used by BatchEngine::getInput.
102 BatchEngine::BatchEngine(string batchFileName){
104 globaldata = GlobalData::getInstance();
105 openedBatch = openInputFile(batchFileName, inputBatchFile);
109 // char buffer = ' ';
110 // ifstream header("introtext.txt");
111 // while(!header.eof()){
113 // buffer = header.get();
116 catch(exception& e) {
117 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 /***********************************************************************/
128 BatchEngine::~BatchEngine(){
131 /***********************************************************************/
132 //This Function allows the user to run a batchfile containing several commands on Dotur
133 bool BatchEngine::getInput(){
136 string commandName = "";
138 ErrorCheck* errorCheckor = new ErrorCheck();
140 CommandFactory cFactory;
141 int quitCommandCalled = 0;
143 while(quitCommandCalled == 0){
145 getline(inputBatchFile, input);
146 if (inputBatchFile.eof()) { input = "quit()"; }
148 cout << endl << "mothur > " << input << endl;
149 errorFree = errorCheckor->checkInput(input);
150 if (errorFree == true) {
151 CommandOptionParser parser(input);
152 commandName = parser.getCommandString();
155 if (openedBatch == 0) { //able to open batchfile
156 //executes valid command
157 CommandFactory cFactory;
158 Command* command = cFactory.getCommand(commandName);
159 quitCommandCalled = command->execute();
162 cout << "Invalid." << endl;
166 cout << "Unable to open batchfile." << endl;
171 catch(exception& e) {
172 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 /***********************************************************************/