OILS / cpp / core.h View on Github | oils.pub

133 lines, 79 significant
1// core.h: Replacement for core/*.py
2
3#ifndef CORE_H
4#define CORE_H
5
6#include <pwd.h> // passwd
7#include <termios.h>
8
9#include "_gen/frontend/syntax.asdl.h"
10#include "cpp/pgen2.h"
11#include "mycpp/runtime.h"
12
13// Hacky forward declaration
14namespace completion {
15class RootCompleter;
16};
17
18namespace pyos {
19
20const int TERM_ICANON = ICANON;
21const int TERM_ECHO = ECHO;
22const int EOF_SENTINEL = 256;
23const int NEWLINE_CH = 10;
24const int BACKSLASH_CH = 92;
25
26Tuple2<int, int> WaitPid(int waitpid_options);
27Tuple2<int, int> Read(int fd, int n, List<BigStr*>* chunks);
28Tuple2<int, int> ReadByte(int fd);
29BigStr* ReadLineBuffered();
30Dict<BigStr*, BigStr*>* Environ();
31int Chdir(BigStr* dest_dir);
32BigStr* GetMyHomeDir();
33BigStr* GetHomeDir(BigStr* user_name);
34
35class ReadError {
36 public:
37 explicit ReadError(int err_num_) : err_num(err_num_) {
38 }
39
40 static constexpr ObjHeader obj_header() {
41 return ObjHeader::ClassFixed(kZeroMask, sizeof(ReadError));
42 }
43
44 int err_num;
45};
46
47class PasswdEntry {
48 public:
49 explicit PasswdEntry(const passwd* entry)
50 : pw_name(StrFromC(entry->pw_name)),
51 pw_uid(entry->pw_uid),
52 pw_gid(entry->pw_gid) {
53 }
54
55 static constexpr ObjHeader obj_header() {
56 return ObjHeader::ClassFixed(field_mask(), sizeof(PasswdEntry));
57 }
58
59 BigStr* pw_name;
60 int pw_uid;
61 int pw_gid;
62
63 static constexpr uint32_t field_mask() {
64 return maskbit(offsetof(PasswdEntry, pw_name));
65 }
66};
67
68List<PasswdEntry*>* GetAllUsers();
69
70BigStr* GetUserName(int uid);
71
72BigStr* OsType();
73
74Tuple2<mops::BigInt, mops::BigInt> GetRLimit(int resource);
75
76void SetRLimit(int resource, mops::BigInt soft, mops::BigInt hard);
77
78Tuple3<double, double, double> Time();
79
80void PrintTimes();
81
82bool InputAvailable(int fd);
83
84List<int>* WaitForReading(List<int>* fd_list);
85
86IOError_OSError* FlushStdout();
87
88Tuple2<int, void*> PushTermAttrs(int fd, int mask);
89void PopTermAttrs(int fd, int orig_local_modes, void* term_attrs);
90
91Tuple2<BigStr*, int>* MakeDirCacheKey(BigStr* path);
92
93bool IsSameFile(BigStr* path1, BigStr* path2);
94
95int Unlink(BigStr* path);
96
97} // namespace pyos
98
99namespace pyutil {
100
101double infinity();
102double nan();
103
104bool IsValidCharEscape(BigStr* c);
105BigStr* ChArrayToString(List<int>* ch_array);
106
107class _ResourceLoader {
108 public:
109 _ResourceLoader() {
110 }
111
112 virtual BigStr* Get(BigStr* path);
113
114 static constexpr ObjHeader obj_header() {
115 return ObjHeader::ClassFixed(kZeroMask, sizeof(_ResourceLoader));
116 }
117};
118
119_ResourceLoader* GetResourceLoader();
120
121BigStr* GetVersion(_ResourceLoader* loader);
122
123void PrintVersionDetails(_ResourceLoader* loader);
124
125BigStr* strerror(IOError_OSError* e);
126
127BigStr* BackslashEscape(BigStr* s, BigStr* meta_chars);
128
129grammar::Grammar* LoadYshGrammar(_ResourceLoader*);
130
131} // namespace pyutil
132
133#endif // CORE_H