-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmpw-shell.h
76 lines (49 loc) · 1.44 KB
/
mpw-shell.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef __mpw_shell_h__
#define __mpw_shell_h__
#include <string>
#include <vector>
#include <unordered_map>
#include <memory>
#include <cstdint>
#include "environment.h"
#include "fdset.h"
const unsigned char escape = 0xb6;
class token {
public:
enum {
text = 0,
eof,
equivalent,
not_equivalent,
// remainder are characters.
};
unsigned type = text;
std::string string;
token() = default;
token(token &&) = default;
token(const token&) = default;
token &operator=(token &&) = default;
token &operator=(const token &) = default;
token(const std::string &s, unsigned t = text) :
type(t), string(s)
{}
token(std::string &&s, unsigned t = text) :
type(t), string(std::move(s))
{}
operator std::string() const {
return string;
}
};
std::vector<token> tokenize(std::string &s, bool eval = false);
std::string expand_vars(const std::string &s, class Environment &, const fdmask &fds = fdmask());
//std::string quote(std::string &&s);
std::string quote(const std::string &s);
struct process;
struct value;
class fdmask;
void parse_tokens(std::vector<token> &&tokens, process &p);
int32_t evaluate_expression(Environment &e, const std::string &name, std::vector<token> &&tokens);
int read_file(Environment &e, const std::string &file, const fdmask &fds = fdmask());
int read_string(Environment &e, const std::string &s, const fdmask &fds = fdmask());
int read_fd(Environment &e, int fd, const fdmask &fds = fdmask());
#endif