]> git.donarmstrong.com Git - mothur.git/blob - engine.cpp
fixed blast code path problem
[mothur.git] / engine.cpp
1 /*
2  *  engine.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 8/15/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
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.
11  *
12  */
13 using namespace std;
14
15 #include "engine.hpp"
16
17 /***********************************************************************/
18
19 InteractEngine::InteractEngine(string path){
20
21         globaldata = GlobalData::getInstance();
22         globaldata->argv = path;
23         
24         system("clear");
25 //      char buffer = ' ';
26 //      ifstream header("introtext.txt");
27 //      while(!header.eof()){
28 //              cout << buffer;
29 //              buffer = header.get();
30 //      }
31 }
32
33 /***********************************************************************/
34
35 InteractEngine::~InteractEngine(){
36         }
37
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(){
42         try {
43                 string input = "";
44                 string commandName = "";
45                 int quitCommandCalled = 0;
46                 bool errorFree;
47                 ErrorCheck* errorCheckor = new ErrorCheck();
48                 
49                 cout << "mothur v1.2.0" << endl;
50                 cout << "Last updated: 4/14/2009" << endl << endl;
51                 cout << "by" << 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;
60
61                 while(quitCommandCalled != 1){
62
63                         cout << endl << "mothur > ";
64                         getline(cin, input);
65                         if (cin.eof()) { input = "quit()"; }
66                         
67                         errorFree = errorCheckor->checkInput(input);
68                         if (errorFree == true) {
69                                 CommandOptionParser parser(input);
70                                 commandName = parser.getCommandString();
71                         
72                                 //executes valid command
73                                 CommandFactory cFactory;
74                                 Command* command = cFactory.getCommand(commandName);
75                                 quitCommandCalled = command->execute();
76                 
77                         }else {
78                                         cout << "Your input contains errors. Please try again." << endl;
79                         }
80                 }       
81                 return 1;
82         }
83         catch(exception& e) {
84                 cout << "Standard Error: " << e.what() << " has occurred in the InteractEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
85                 exit(1);
86         }
87         catch(...) {
88                 cout << "An unknown error has occurred in the InteractEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89                 exit(1);
90         }
91
92 }
93
94 /***********************************************************************/
95 //This function opens the batchfile to be used by BatchEngine::getInput.
96 BatchEngine::BatchEngine(string path, string batchFileName){
97         try {
98                 globaldata = GlobalData::getInstance();
99                 openedBatch = openInputFile(batchFileName, inputBatchFile);
100                 globaldata->argv = path;
101
102                 system("clear");
103         
104         //      char buffer = ' ';
105         //      ifstream header("introtext.txt");
106         //      while(!header.eof()){
107         //              cout << buffer;
108         //              buffer = header.get();
109         //      }
110         }
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";
113                 exit(1);
114         }
115         catch(...) {
116                 cout << "An unknown error has occurred in the BatchEngine class function BatchEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
117                 exit(1);
118         }
119 }
120
121 /***********************************************************************/
122
123 BatchEngine::~BatchEngine(){
124         }
125
126 /***********************************************************************/
127 //This Function allows the user to run a batchfile containing several commands on Dotur
128 bool BatchEngine::getInput(){
129         try {
130                 string input = "";
131                 string commandName = "";
132                 bool errorFree;
133                 ErrorCheck* errorCheckor = new ErrorCheck();
134
135                 CommandFactory cFactory;
136                 int quitCommandCalled = 0;
137         
138                 while(quitCommandCalled == 0){
139                 
140                         getline(inputBatchFile, input);
141                         if (inputBatchFile.eof()) { input = "quit()"; }
142                         
143                         cout << endl << "mothur > " << input << endl;
144                         errorFree = errorCheckor->checkInput(input);
145                         if (errorFree == true) {
146                                 CommandOptionParser parser(input);
147                                 commandName = parser.getCommandString();
148                                 ifstream filehandle;
149                 
150                                 if (openedBatch == 0) { //able to open batchfile
151                                         //executes valid command
152                                         CommandFactory cFactory;
153                                         Command* command = cFactory.getCommand(commandName);
154                                         quitCommandCalled = command->execute();
155                                 }
156                                 else {
157                                         cout << "Invalid." << endl;
158                                 }
159                         }
160                         else {
161                                 cout << "Unable to open batchfile." << endl;
162                         }
163                 }
164                 return 1;
165         }
166         catch(exception& e) {
167                 cout << "Standard Error: " << e.what() << " has occurred in the BatchEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
168                 exit(1);
169         }
170         catch(...) {
171                 cout << "An unknown error has occurred in the BatchEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
172                 exit(1);
173         }
174 }
175
176
177 /***********************************************************************/
178