]> git.donarmstrong.com Git - mothur.git/blob - mothur.cpp
added checks for ^C to quit command instead of program
[mothur.git] / mothur.cpp
1 /*
2  *  interface.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 8/14/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9  
10 #include "mothur.h"
11 #include "engine.hpp"
12 #include "globaldata.hpp"
13 #include "mothurout.h"
14
15 /**************************************************************************************************/
16
17 GlobalData* GlobalData::_uniqueInstance = 0;
18 CommandFactory* CommandFactory::_uniqueInstance = 0;
19 MothurOut* MothurOut::_uniqueInstance = 0;
20
21 /***********************************************************************/
22 volatile int ctrlc_pressed = 0;
23 void ctrlc_handler ( int sig ) {
24         MothurOut* m = MothurOut::getInstance();
25     ctrlc_pressed = 1;
26         m->control_pressed = ctrlc_pressed;
27         
28         if (m->executing) { //if mid command quit execution, else quit mothur
29                 m->mothurOutEndLine(); m->mothurOut("quitting command...");  m->mothurOutEndLine();
30         }else{
31                 m->mothurOut("quitting mothur");  m->mothurOutEndLine();
32                 exit(1);
33         }
34 }
35 /***********************************************************************/
36 int main(int argc, char *argv[]){
37         MothurOut* m = MothurOut::getInstance();
38         try {
39                 
40                 signal(SIGINT, ctrlc_handler );
41                                 
42                 time_t ltime = time(NULL); /* calendar time */  
43                 string logFileName = "mothur." + toString(ltime) + ".logfile";
44                 
45                 m->setFileName(logFileName);
46                 
47                 //version
48                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
49                         system("clear");
50                         #if defined (__APPLE__) || (__MACH__)
51                                 m->mothurOutJustToLog("Mac version");
52                                 m->mothurOutEndLine(); m->mothurOutEndLine();
53                         #else
54                                 m->mothurOutJustToLog("Linux version");
55                                 >m->mothurOutEndLine(); m->mothurOutEndLine();
56                         #endif
57
58                 #else
59                         system("CLS");
60                         m->mothurOutJustToLog("Windows version");
61                         m->mothurOutEndLine(); m->mothurOutEndLine();
62                 #endif          
63                 
64                 #ifdef USE_READLINE
65                         m->mothurOutJustToLog("Using ReadLine");
66                         m->mothurOutEndLine(); m->mothurOutEndLine();
67                 #endif
68                 
69                 //header
70                 m->mothurOut("mothur v.1.8");
71                 m->mothurOutEndLine();          
72                 m->mothurOut("Last updated: 2/02/2010");
73                 m->mothurOutEndLine();  
74                 m->mothurOutEndLine();          
75                 m->mothurOut("by");
76                 m->mothurOutEndLine();          
77                 m->mothurOut("Patrick D. Schloss");
78                 m->mothurOutEndLine();
79                 m->mothurOutEndLine();                  
80                 m->mothurOut("Department of Microbiology & Immunology");
81                 m->mothurOutEndLine();  
82                 m->mothurOut("University of Michigan");
83                 m->mothurOutEndLine();                  
84                 m->mothurOut("pschloss@umich.edu");
85                 m->mothurOutEndLine();          
86                 m->mothurOut("http://www.mothur.org");
87                 m->mothurOutEndLine();
88                 m->mothurOutEndLine();
89                 m->mothurOut("When using, please cite:");
90                 m->mothurOutEndLine();
91                 m->mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41.");
92                 m->mothurOutEndLine();  
93                 m->mothurOutEndLine();          
94                 m->mothurOut("Distributed under the GNU General Public License");
95                 m->mothurOutEndLine();
96                 m->mothurOutEndLine();                  
97                 m->mothurOut("Type 'help()' for information on the commands that are available");
98                 m->mothurOutEndLine();
99                 m->mothurOutEndLine();                  
100                 m->mothurOut("Type 'quit()' to exit program");
101                 m->mothurOutEndLine();  
102
103                                 
104                 //srand(54321);
105                 srand( (unsigned)time( NULL ) );
106                 
107                 Engine* mothur;
108                 bool bail = 0;
109                 string input;
110
111                 if(argc>1){
112                         input = argv[1];
113
114                         if (input[0] == '#') {
115                                 m->mothurOutJustToLog("Script Mode");
116                                 m->mothurOutEndLine(); m->mothurOutEndLine();
117
118                                 mothur = new ScriptEngine(argv[0], argv[1]);
119                         }else{
120                                 m->mothurOutJustToLog("Batch Mode");
121                                 m->mothurOutEndLine(); m->mothurOutEndLine();
122                                 
123                                 mothur = new BatchEngine(argv[0], argv[1]);
124                         }
125                 }
126                 else{
127                         m->mothurOutJustToLog("Interactive Mode");
128                         m->mothurOutEndLine(); m->mothurOutEndLine();
129                         
130                         mothur = new InteractEngine(argv[0]);   
131                 }
132                 
133                 while(bail == 0)                {       bail = mothur->getInput();                      }
134                 
135                 string outputDir = mothur->getOutputDir();
136                 string newlogFileName = outputDir + logFileName;
137         
138                 //need this because m->mothurOut makes the logfile, but doesn't know where to put it
139                 rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp
140                 
141                 delete mothur;
142
143                 return 0;
144         }
145         catch(exception& e) {
146                 m->errorOut(e, "mothur", "main");
147                 exit(1);
148         }
149 }
150
151 /**************************************************************************************************/
152