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(){
21 globaldata = GlobalData::getInstance();
25 // ifstream header("introtext.txt");
26 // while(!header.eof()){
28 // buffer = header.get();
32 /***********************************************************************/
34 InteractEngine::~InteractEngine(){
37 /***********************************************************************/
38 //This function allows the user to input commands one line at a time until they quit.
39 //If the command is garbage it does nothing.
40 bool InteractEngine::getInput(){
43 string commandName = "";
44 int quitCommandCalled = 0;
46 ErrorCheck* errorCheckor = new ErrorCheck();
48 cout << "mothur v1.2.0" << endl;
49 cout << "Last updated: 4/14/2009" << endl << endl;
51 cout << "Patrick D. Schloss" << endl << endl;
52 cout << "Department of Microbiology" << endl;
53 cout << "The University of Massachusetts" << endl;
54 cout << "pschloss@micro.umass.edu" << endl;
55 cout << "http://schloss.micro.umass.edu/mothur" << endl << endl << endl;
56 cout << "Distributed under the GNU General Public License" << endl << endl;
57 cout << "Type 'help()' for information on the commands that are available" << endl << endl;
58 cout << "Type 'quit()' to exit program" << endl;
60 while(quitCommandCalled != 1){
62 cout << endl << "mothur > ";
64 if (cin.eof()) { input = "quit()"; }
66 errorFree = errorCheckor->checkInput(input);
67 if (errorFree == true) {
68 CommandOptionParser parser(input);
69 commandName = parser.getCommandString();
71 //executes valid command
72 CommandFactory cFactory;
73 Command* command = cFactory.getCommand(commandName);
74 quitCommandCalled = command->execute();
77 cout << "Your input contains errors. Please try again." << endl;
83 cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
87 cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
93 /***********************************************************************/
94 //This function opens the batchfile to be used by BatchEngine::getInput.
95 BatchEngine::BatchEngine(string batchFileName){
97 globaldata = GlobalData::getInstance();
98 openedBatch = openInputFile(batchFileName, inputBatchFile);
102 // char buffer = ' ';
103 // ifstream header("introtext.txt");
104 // while(!header.eof()){
106 // buffer = header.get();
109 catch(exception& e) {
110 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
114 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119 /***********************************************************************/
121 BatchEngine::~BatchEngine(){
124 /***********************************************************************/
125 //This Function allows the user to run a batchfile containing several commands on Dotur
126 bool BatchEngine::getInput(){
129 string commandName = "";
131 ErrorCheck* errorCheckor = new ErrorCheck();
133 CommandFactory cFactory;
134 int quitCommandCalled = 0;
136 while(quitCommandCalled == 0){
138 getline(inputBatchFile, input);
139 if (inputBatchFile.eof()) { input = "quit()"; }
141 cout << endl << "mothur > " << input << endl;
142 errorFree = errorCheckor->checkInput(input);
143 if (errorFree == true) {
144 CommandOptionParser parser(input);
145 commandName = parser.getCommandString();
148 if (openedBatch == 0) { //able to open batchfile
149 //executes valid command
150 CommandFactory cFactory;
151 Command* command = cFactory.getCommand(commandName);
152 quitCommandCalled = command->execute();
155 cout << "Invalid." << endl;
159 cout << "Unable to open batchfile." << endl;
164 catch(exception& e) {
165 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
169 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
175 /***********************************************************************/