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(){
130 //check if this is a valid batchfile
131 if (openedBatch == 1) { cout << "unable to open batchfile" << endl; return 1; }
134 string commandName = "";
136 ErrorCheck* errorCheckor = new ErrorCheck();
138 CommandFactory cFactory;
139 int quitCommandCalled = 0;
141 while(quitCommandCalled == 0){
143 getline(inputBatchFile, input);
144 if (input[0] != '#') {
145 if (inputBatchFile.eof()) { input = "quit()"; }
147 cout << endl << "mothur > " << input << endl;
148 errorFree = errorCheckor->checkInput(input);
149 if (errorFree == true) {
150 CommandOptionParser parser(input);
151 commandName = parser.getCommandString();
154 if (openedBatch == 0) { //able to open batchfile
155 //executes valid command
156 CommandFactory cFactory;
157 Command* command = cFactory.getCommand(commandName);
158 quitCommandCalled = command->execute();
161 cout << "Invalid." << endl;
165 cout << "Unable to open batchfile." << endl;
167 }else { if (inputBatchFile.eof()) { input = "quit()"; } }
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 /***********************************************************************/