OILS / cpp / core.h View on Github | oilshell.org

126 lines, 75 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;
24
25Tuple2<int, int> WaitPid(int waitpid_options);
26Tuple2<int, int> Read(int fd, int n, List<BigStr*>* chunks);
27Tuple2<int, int> ReadByte(int fd);
28BigStr* ReadLineBuffered();
29Dict<BigStr*, BigStr*>* Environ();
30int Chdir(BigStr* dest_dir);
31BigStr* GetMyHomeDir();
32BigStr* GetHomeDir(BigStr* user_name);
33
34class ReadError {
35 public:
36 explicit ReadError(int err_num_) : err_num(err_num_) {
37 }
38
39 static constexpr ObjHeader obj_header() {
40 return ObjHeader::ClassFixed(kZeroMask, sizeof(ReadError));
41 }
42
43 int err_num;
44};
45
46class PasswdEntry {
47 public:
48 explicit PasswdEntry(const passwd* entry)
49 : pw_name(StrFromC(entry->pw_name)),
50 pw_uid(entry->pw_uid),
51 pw_gid(entry->pw_gid) {
52 }
53
54 static constexpr ObjHeader obj_header() {
55 return ObjHeader::ClassFixed(field_mask(), sizeof(PasswdEntry));
56 }
57
58 BigStr* pw_name;
59 int pw_uid;
60 int pw_gid;
61
62 static constexpr uint32_t field_mask() {
63 return maskbit(offsetof(PasswdEntry, pw_name));
64 }
65};
66
67List<PasswdEntry*>* GetAllUsers();
68
69BigStr* GetUserName(int uid);
70
71BigStr* OsType();
72
73Tuple2<mops::BigInt, mops::BigInt> GetRLimit(int resource);
74
75void SetRLimit(int resource, mops::BigInt soft, mops::BigInt hard);
76
77Tuple3<double, double, double> Time();
78
79void PrintTimes();
80
81bool InputAvailable(int fd);
82
83IOError_OSError* FlushStdout();
84
85Tuple2<int, void*> PushTermAttrs(int fd, int mask);
86void PopTermAttrs(int fd, int orig_local_modes, void* term_attrs);
87
88Tuple2<BigStr*, int>* MakeDirCacheKey(BigStr* path);
89
90} // namespace pyos
91
92namespace pyutil {
93
94double infinity();
95double nan();
96
97bool IsValidCharEscape(BigStr* c);
98BigStr* ChArrayToString(List<int>* ch_array);
99
100class _ResourceLoader {
101 public:
102 _ResourceLoader() {
103 }
104
105 virtual BigStr* Get(BigStr* path);
106
107 static constexpr ObjHeader obj_header() {
108 return ObjHeader::ClassFixed(kZeroMask, sizeof(_ResourceLoader));
109 }
110};
111
112_ResourceLoader* GetResourceLoader();
113
114BigStr* GetVersion(_ResourceLoader* loader);
115
116void PrintVersionDetails(_ResourceLoader* loader);
117
118BigStr* strerror(IOError_OSError* e);
119
120BigStr* BackslashEscape(BigStr* s, BigStr* meta_chars);
121
122grammar::Grammar* LoadYshGrammar(_ResourceLoader*);
123
124} // namespace pyutil
125
126#endif // CORE_H