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.
23 #include "utilities.hpp"
24 #include "globaldata.hpp"
25 #include "commandoptionparser.hpp"
26 #include "command.hpp"
27 #include "commandfactory.hpp"
28 #include "errorchecking.h"
31 /***********************************************************************/
33 InteractEngine::InteractEngine(){
35 globaldata = GlobalData::getInstance();
39 // ifstream header("introtext.txt");
40 // while(!header.eof()){
42 // buffer = header.get();
46 /***********************************************************************/
48 InteractEngine::~InteractEngine(){
51 /***********************************************************************/
52 //This function allows the user to input commands one line at a time until they quit.
53 //If the command is garbage it does nothing.
54 bool InteractEngine::getInput(){
57 string commandName = "";
58 int quitCommandCalled = 0;
60 ErrorCheck* errorCheckor = new ErrorCheck();
62 cout << "mothur v1.0" << endl;
63 cout << "Last updated: 1/29/2009" << endl << endl;
65 cout << "Patrick D. Schloss" << endl << endl;
66 cout << "Department of Microbiology" << endl;
67 cout << "The University of Massachusetts" << endl;
68 cout << "pschloss@micro.umass.edu" << endl;
69 cout << "http://schloss.micro.umass.edu/mothur" << endl << endl << endl;
70 cout << "Distributed under the GNU General Public License" << endl << endl;
71 cout << "Type 'help()' for information on the commands that are available" << endl << endl;
72 cout << "Type 'quit()' to exit program" << endl;
74 while(quitCommandCalled != 1){
76 cout << endl << "mothur > ";
78 errorFree = errorCheckor->checkInput(input);
79 if (errorFree == true) {
80 CommandOptionParser parser(input);
81 commandName = parser.getCommandString();
83 //executes valid command
84 CommandFactory cFactory;
85 Command* command = cFactory.getCommand(commandName);
86 quitCommandCalled = command->execute();
89 cout << "Your input contains errors. Please try again." << endl;
95 cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
99 cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
105 /***********************************************************************/
106 //This function opens the batchfile to be used by BatchEngine::getInput.
107 BatchEngine::BatchEngine(string batchFileName){
109 globaldata = GlobalData::getInstance();
110 openedBatch = openInputFile(batchFileName, inputBatchFile);
114 // char buffer = ' ';
115 // ifstream header("introtext.txt");
116 // while(!header.eof()){
118 // buffer = header.get();
121 catch(exception& e) {
122 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131 /***********************************************************************/
133 BatchEngine::~BatchEngine(){
136 /***********************************************************************/
137 //This Function allows the user to run a batchfile containing several commands on Dotur
138 bool BatchEngine::getInput(){
141 string commandName = "";
143 ErrorCheck* errorCheckor = new ErrorCheck();
145 CommandFactory cFactory;
146 int quitCommandCalled = 0;
148 while(quitCommandCalled == 0){
150 getline(inputBatchFile, input);
151 cout << endl << "dotur > " << input << endl;
152 errorFree = errorCheckor->checkInput(input);
153 if (errorFree == true) {
154 CommandOptionParser parser(input);
155 commandName = parser.getCommandString();
158 if (openedBatch == 0) { //able to open batchfile
159 //executes valid command
160 CommandFactory cFactory;
161 Command* command = cFactory.getCommand(commandName);
162 quitCommandCalled = command->execute();
165 cout << "Invalid." << endl;
169 cout << "Unable to open batchfile." << endl;
174 catch(exception& e) {
175 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
179 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
185 /***********************************************************************/