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 v.1.3.0" << endl;
50 cout << "Last updated: 4/25/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 //allow user to omit the () on the quit command
68 if (input == "quit") { input = "quit()"; }
70 errorFree = errorCheckor->checkInput(input);
71 if (errorFree == true) {
72 CommandOptionParser parser(input);
73 commandName = parser.getCommandString();
75 //executes valid command
76 CommandFactory cFactory;
77 Command* command = cFactory.getCommand(commandName);
78 quitCommandCalled = command->execute();
81 cout << "Your input contains errors. Please try again." << endl;
87 cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
91 cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
97 /***********************************************************************/
98 //This function opens the batchfile to be used by BatchEngine::getInput.
99 BatchEngine::BatchEngine(string path, string batchFileName){
101 globaldata = GlobalData::getInstance();
102 openedBatch = openInputFile(batchFileName, inputBatchFile);
103 globaldata->argv = path;
107 // char buffer = ' ';
108 // ifstream header("introtext.txt");
109 // while(!header.eof()){
111 // buffer = header.get();
114 catch(exception& e) {
115 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124 /***********************************************************************/
126 BatchEngine::~BatchEngine(){
129 /***********************************************************************/
130 //This Function allows the user to run a batchfile containing several commands on Dotur
131 bool BatchEngine::getInput(){
133 //check if this is a valid batchfile
134 if (openedBatch == 1) { cout << "unable to open batchfile" << endl; return 1; }
137 string commandName = "";
139 ErrorCheck* errorCheckor = new ErrorCheck();
141 CommandFactory cFactory;
142 int quitCommandCalled = 0;
144 while(quitCommandCalled == 0){
146 getline(inputBatchFile, input);
147 if (input[0] != '#') {
148 if (inputBatchFile.eof()) { input = "quit()"; }
150 cout << endl << "mothur > " << input << endl;
152 //allow user to omit the () on the quit command
153 if (input == "quit") { input = "quit()"; }
155 errorFree = errorCheckor->checkInput(input);
156 if (errorFree == true) {
157 CommandOptionParser parser(input);
158 commandName = parser.getCommandString();
161 if (openedBatch == 0) { //able to open batchfile
162 //executes valid command
163 CommandFactory cFactory;
164 Command* command = cFactory.getCommand(commandName);
165 quitCommandCalled = command->execute();
168 cout << "Invalid." << endl;
172 cout << "Unable to open batchfile." << endl;
174 }else { if (inputBatchFile.eof()) { input = "quit()"; } }
178 catch(exception& e) {
179 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
183 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
189 /***********************************************************************/