-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommand.h
56 lines (47 loc) · 1.56 KB
/
Command.h
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
#ifndef _COMMAND_H_
#define _COMMAND_H_
#include <vector>
#include <string>
/*
* class that stores information about a command
*
* in_file - string containing the redirected input filename, if it exists
* out_file - string containing the redirected output filename, if it exists
* args - vector of strings containing the arguments of the command
*
* whether or not the command should be run in the background is also stored
* accessible by calling ->isBackground()
*/
class Command {
private:
// full command stored for internal convenience
std::string cmd;
// list of quoted strings in command
std::vector<std::string> inner_strings;
// whether or not the command should be run in the background
bool bg;
public:
// filename of redirected input file, if it exists
std::string in_file;
// filename of redirected output file, if it exists
std::string out_file;
// command arguments
std::vector<std::string> args;
// constructor - takes command and calls internal convenience
// functions to parse the arguments
Command (const std::string _cmd, std::vector<std::string> _inner_strings);
// destructor
~Command () {}
// boolean functions to return if command has I/O redirection
// or runs in background
bool hasInput ();
bool hasOutput ();
bool isBackground ();
private:
// convenience functions to trim whitespace, find input/output filename,
// and parse arguments
std::string trim (const std::string in);
void findInOut ();
void parseArgs ();
};
#endif