-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (47 loc) · 1.23 KB
/
main.cpp
File metadata and controls
60 lines (47 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#endif
#ifdef WIN32
#define stat _stat
#endif
using namespace std;
int main(int argc, char *argv[]){
if (argc == 3){
std::string compiler = argv[1];
std::string filename = argv[2];
string tmp = compiler + " " + filename + " -o output && ./output";
const char* command = tmp.c_str();
bool isMonitoring = true;
auto mod_time = 0, prev_mod_time = 0;
cout<<"Welcome to CPPMon 1.0"<<endl;
cout<<"---------------------"<<endl;
cout<<"Created by Abthahi Ahmed Rifat :D"<<endl;
cout<<endl;
while (isMonitoring){
struct stat result;
if(stat(filename.c_str(), &result) == 0)
{
prev_mod_time = mod_time;
mod_time = result.st_mtime;
if (mod_time != 0 && mod_time > prev_mod_time){
cout<<"[cppmon] Starting... "<<" " <<command<<endl;
cout<<"[cppmon] Compiling..."<<endl;
cout<<endl;
system(command);
cout<<endl;
cout<<"[cppmon] Waiting for file changes..."<<endl;
}
}else{
cout<<"[cppmon] Cannot get file informations"<<endl;
break;
}
}
}else{
cout<<"[cppmon] Wrong command!"<<endl;
cout<<"Syntax : cppmon [g++/gcc] main.cpp"<<endl;
}
return 0;
}