-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
85 lines (80 loc) · 1.69 KB
/
main.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "pch.h"
#include <memory>
#include <map>
//==============================
struct AST_IORedirection {
enum Type {
Stdin, Stdout, StdErr, File,
};
Type type;
string fileName;
};
struct AST_Process {
virtual ~AST_Process(){}
};
typedef shared_ptr<AST_Process> AST_ProcessPtr;
struct AST_SimpleProcess: public AST_Process {
string path;
vector<string> args;
AST_IORedirection redirections[3];
};
struct AST_Pipeline: public AST_Process {
AST_ProcessPtr upstream;
AST_ProcessPtr downstream;
};
struct AST_Subshell: public AST_Process {
string cmd;
};
struct AST_Job {
AST_ProcessPtr process;
};
typedef shared_ptr<AST_Job> AST_JobPtr;
//==============================
class CommandParser {
public:
CommandParser(const char *cmd);
vector<AST_JobPtr>& getASTJobs();
private:
vector<AST_JobPtr> m_astJobs;
};
//==============================
struct Job {
int jobID;
int gid;
vector<int> pids;
};
//==============================
class ASTJobInterpreter {
public:
ASTJobInterpreter(const AST_JobPtr &astJob);
Job* getJob();
private:
Job m_job;
};
//==============================
class Shell {
public:
void addJob(Job *job);
void delJob(int jobID);
void joinJob(int jobID);
int getJobIDByGID(int pid);
private:
void _handleSIGINT();
void _handleSIGTSTP();
private:
string m_cwd;
map<string, string> m_env;
};
//==============================
static bool isSignalFound_SIGINT = false;
static bool isSignalFound_SIGTSTP = false;
static void handler_SIGINT() {
}
static void handler_SIGTSTP() {
}
static void installSignalHandlers() {
}
//==============================
int main() {
return 0;
}