forked from oils-for-unix/oils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.h
166 lines (120 loc) · 3.13 KB
/
core.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// core.h: Replacement for core/*.py
#ifndef LEAKY_CORE_H
#define LEAKY_CORE_H
#include <pwd.h> // passwd
#include <signal.h> // sighandler_t
#include <termios.h>
#include "_gen/frontend/syntax.asdl.h"
#include "cpp/pgen2.h"
#include "mycpp/runtime.h"
// Hacky forward declaration
namespace completion {
class RootCompleter;
};
namespace pyos {
const int TERM_ICANON = ICANON;
const int TERM_ECHO = ECHO;
const int EOF_SENTINEL = 256;
const int NEWLINE_CH = 10;
const int UNTRAPPED_SIGWINCH = -1;
const int kMaxSignalsInFlight = 1024;
Tuple2<int, int> WaitPid();
Tuple2<int, int> Read(int fd, int n, List<Str*>* chunks);
Tuple2<int, int> ReadByte(int fd);
Str* ReadLine();
Dict<Str*, Str*>* Environ();
int Chdir(Str* dest_dir);
Str* GetMyHomeDir();
Str* GetHomeDir(Str* user_name);
class ReadError {
public:
explicit ReadError(int err_num_)
: GC_CLASS_FIXED(header_, kZeroMask, sizeof(ReadError)),
err_num(err_num_) {
}
GC_OBJ(header_);
int err_num;
};
class PasswdEntry {
public:
explicit PasswdEntry(const passwd* entry)
: GC_CLASS_FIXED(header_, field_mask(), sizeof(PasswdEntry)),
pw_name(StrFromC(entry->pw_name)),
pw_uid(entry->pw_uid),
pw_gid(entry->pw_gid) {
}
GC_OBJ(header_);
Str* pw_name;
int pw_uid;
int pw_gid;
static constexpr uint16_t field_mask() {
return maskbit(offsetof(PasswdEntry, pw_name));
}
};
List<PasswdEntry*>* GetAllUsers();
Str* GetUserName(int uid);
Str* OsType();
Tuple3<double, double, double> Time();
void PrintTimes();
bool InputAvailable(int fd);
inline void FlushStdout() {
// Flush libc buffers
fflush(stdout);
}
class TermState {
public:
TermState(int fd, int mask) {
assert(0);
}
void Restore() {
assert(0);
}
};
class SignalHandler {
public:
SignalHandler()
: GC_CLASS_FIXED(header_, field_mask(), sizeof(SignalHandler)),
signal_queue_(nullptr),
last_sig_num_(0),
sigwinch_num_(UNTRAPPED_SIGWINCH),
sigint_count_(0) {
}
void Update(int sig_num);
List<int>* TakeSignalQueue();
GC_OBJ(header_);
List<int>* signal_queue_;
int last_sig_num_;
int sigwinch_num_;
int sigint_count_;
static constexpr uint16_t field_mask() {
return maskbit(offsetof(SignalHandler, signal_queue_));
}
};
void Sigaction(int sig_num, sighandler_t handler);
void RegisterSignalInterest(int sig_num);
List<int>* TakeSignalQueue();
int LastSignal();
int SigintCount();
void SetSigwinchCode(int code);
void InitShell();
Tuple2<Str*, int>* MakeDirCacheKey(Str* path);
} // namespace pyos
namespace pyutil {
bool IsValidCharEscape(Str* c);
Str* ChArrayToString(List<int>* ch_array);
class _ResourceLoader {
public:
_ResourceLoader()
: GC_CLASS_FIXED(header_, kZeroMask, sizeof(_ResourceLoader)) {
}
virtual Str* Get(Str* path);
GC_OBJ(header_);
};
_ResourceLoader* GetResourceLoader();
Str* GetVersion(_ResourceLoader* loader);
Str* ShowAppVersion(Str* app_name, _ResourceLoader* loader);
Str* strerror(IOError_OSError* e);
Str* BackslashEscape(Str* s, Str* meta_chars);
grammar::Grammar* LoadOilGrammar(_ResourceLoader*);
} // namespace pyutil
#endif // LEAKY_CORE_H