-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command.hpp
65 lines (48 loc) · 2.3 KB
/
Command.hpp
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
#ifndef _COMMAND_HPP_
#define _COMMAND_HPP_
/*****************************************************
* Basic representation of a command. Also allows *
* next command to be read in from keyboard *
*****************************************************/
#include <ostream>
#include <string>
using namespace std;
// commands are pulled froma stream of Tokens. You do NOT
// need to unserstand this to use the Command class.
#include "TokenStream.hpp"
// maximum number of arguments any COmmand can have (includes command itself)
#define MAX_ARGS 100
class Command
{
private:
string _args[MAX_ARGS]; // arary of arguments
int _numArgs; // actual number of arguments
string _in; // input redirect filename, if any
string _out; // input redirect filename, if any
bool _pipeOut; // true if output is to be sent to a pipe
bool _backgrounded; // true if command is to be run in background
TokenStream _inputStream; // stream from which command is read.
public:
Command(); // Basic command (allows reads from keyboard)
Command(const Command &c); // build (duplicated) version of existing command.
// note that copy has pipeOut set to false!
void read(); // read the next command
const string& name() const {return _args[0];} // returns command name
const string* args() const {return _args;} // returns array of arguments
int numArgs() const {return _numArgs;} // returns how many arguments
// returns input redirection file
const string& inputRedirectFile() const {return _in;}
// returns input redirection file
const string& outputRedirectFile() const {return _out;}
// the following indicate if input/output redirection is happening and how
bool pipeOut() const {return _pipeOut;} // is there an output pipe?
bool redirIn() const {return _in.length()!=0;} // output redirection?
bool redirOut() const {return _out.length()!=0;}// input redirection?
// is this command followed by a "&" for backgrounding?
bool backgrounded() const {return _backgrounded;}
// prints Command to specified stream
ostream& print(ostream &os) const;
// overloads << to be able to print a Command.
friend ostream& operator<<(ostream &os, const Command &c);
};
#endif