-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequence.cc
More file actions
69 lines (55 loc) · 1.45 KB
/
Sequence.cc
File metadata and controls
69 lines (55 loc) · 1.45 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
60
61
62
63
64
65
66
67
68
/** @file Sequence.cc
* Implementation of class Sequence.
*/
#include <iostream>
#include <sys/wait.h> // for: wait(), WIF...(status)
#include <cstring> // for: strsignal()
#include "asserts.h"
#include "unix_error.h"
#include "Sequence.h"
using namespace std;
void Sequence::addPipeline(Pipeline *pp)
{
require(pp != 0);
commands.push_back(pp);
}
Sequence::~Sequence()
{
for (vector<Pipeline*>::iterator i = commands.begin() ; i != commands.end() ; ++i)
delete *i;
}
bool Sequence::isEmpty() const
{
return commands.empty();
}
// TODO: Lookout somewhere for special commands such as 'exit',
// 'logout', 'cd', etc, which may have to be
// done by the shell itself.
// Execute the pipelines in this sequence one by one
void Sequence::execute()
{
//cerr << "Sequence::execute\n";//DEBUG
// Execute each pipeline in turn.
// Also see: fork(2), nice(2), wait(2), WIF...(2), strsignal(3)
size_t j = commands.size(); // for count-down
for (vector<Pipeline*>::iterator i = commands.begin() ; i != commands.end() ; ++i, --j)
{
Pipeline *pp = *i;
if (!pp->isEmpty())
{
if (j == commands.size()) {//DEBUG
cerr << "Sequence::FIRST PIPELINE\n";//DEBUG
}//DEBUG
// if (pp->isBuiltin()) ...
pp->execute();
// TODO
if (j == 1) {//DEBUG
cerr << "Sequence::LAST PIPELINE\n";//DEBUG
} else {//DEBUG
cerr << "Sequence::WAIT FOR PIPELINE\n";//DEBUG
}//DEBUG
}
// else ignore empty pipeline
}
}
// vim:ai:aw:ts=4:sw=4: