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 = "";
45 int quitCommandCalled = 0;
47 ErrorCheck* errorCheckor = new ErrorCheck();
49 cout << "mothur v1.2.0" << endl;
50 cout << "Last updated: 4/14/2009" << endl << endl;
52 cout << "Patrick D. Schloss" << endl << endl;
53 cout << "Department of Microbiology" << endl;
54 cout << "The University of Massachusetts" << endl;
55 cout << "pschloss@micro.umass.edu" << endl;
56 cout << "http://schloss.micro.umass.edu/mothur" << endl << endl << endl;
57 cout << "Distributed under the GNU General Public License" << endl << endl;
58 cout << "Type 'help()' for information on the commands that are available" << endl << endl;
59 cout << "Type 'quit()' to exit program" << endl;
61 while(quitCommandCalled != 1){
63 cout << endl << "mothur > ";
65 if (cin.eof()) { input = "quit()"; }
67 errorFree = errorCheckor->checkInput(input);
68 if (errorFree == true) {
69 CommandOptionParser parser(input);
70 commandName = parser.getCommandString();
72 //executes valid command
73 CommandFactory cFactory;
74 Command* command = cFactory.getCommand(commandName);
75 quitCommandCalled = command->execute();
78 cout << "Your input contains errors. Please try again." << endl;
84 cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
88 cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94 /***********************************************************************/
95 //This function opens the batchfile to be used by BatchEngine::getInput.
96 BatchEngine::BatchEngine(string path, string batchFileName){
98 globaldata = GlobalData::getInstance();
99 openedBatch = openInputFile(batchFileName, inputBatchFile);
100 globaldata->argv = path;
104 // char buffer = ' ';
105 // ifstream header("introtext.txt");
106 // while(!header.eof()){
108 // buffer = header.get();
111 catch(exception& e) {
112 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
116 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 /***********************************************************************/
123 BatchEngine::~BatchEngine(){
126 /***********************************************************************/
127 //This Function allows the user to run a batchfile containing several commands on Dotur
128 bool BatchEngine::getInput(){
131 string commandName = "";
133 ErrorCheck* errorCheckor = new ErrorCheck();
135 CommandFactory cFactory;
136 int quitCommandCalled = 0;
138 while(quitCommandCalled == 0){
140 getline(inputBatchFile, input);
141 if (input[0] != '#') {
142 if (inputBatchFile.eof()) { input = "quit()"; }
144 cout << endl << "mothur > " << input << endl;
145 errorFree = errorCheckor->checkInput(input);
146 if (errorFree == true) {
147 CommandOptionParser parser(input);
148 commandName = parser.getCommandString();
151 if (openedBatch == 0) { //able to open batchfile
152 //executes valid command
153 CommandFactory cFactory;
154 Command* command = cFactory.getCommand(commandName);
155 quitCommandCalled = command->execute();
158 cout << "Invalid." << endl;
162 cout << "Unable to open batchfile." << endl;
164 }else { if (inputBatchFile.eof()) { input = "quit()"; } }
168 catch(exception& e) {
169 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
173 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
179 /***********************************************************************/