-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshelpers.hpp
More file actions
35 lines (28 loc) · 1.13 KB
/
shelpers.hpp
File metadata and controls
35 lines (28 loc) · 1.13 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
#pragma once
#include <string>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vector>
//You shouldn't need to touch these or call them directly
bool splitOnSymbol(std::vector<std::string>& words, int i, char c);
std::vector<std::string> tokenize(const std::string& s);
//You'll need to fork/exec for each one of these!,
//Initially, assume the user tries to only execute 1 command.
struct Command{
std::string exec; //the name of the executable
//remember argv[0] should be the name of the program (same as exec)
//Also, argv should end with a nullptr!
std::vector<const char*> argv;
int fdStdin, fdStdout;
bool background;
};
//useful for debugging (implemented for you)
std::ostream& operator<<(std::ostream& outs, const Command& c);
//Read this function. You'll need to fill in a few parts to implement
//I/O redirection and (possibly) backgrounded commands.
//Most of the places you need to fill in contain an assert(false), so you'll
//discover them when you try to use more functionality
std::vector<Command> getCommands(const std::vector<std::string>& tokens);