diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2025-03-02 18:30:52 +0100 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2025-03-02 19:13:28 +0100 |
| commit | bdd02cba9ffa1eee3684063b46091f2f868b32b8 (patch) | |
| tree | e1cb90b85ec71dec640143cdbd0c11168f3c79f9 /src | |
| parent | f5f01c663816235bed38b3056771c6898744f567 (diff) | |
| download | luasystem-bdd02cba9ffa1eee3684063b46091f2f868b32b8.tar.gz luasystem-bdd02cba9ffa1eee3684063b46091f2f868b32b8.tar.bz2 luasystem-bdd02cba9ffa1eee3684063b46091f2f868b32b8.zip | |
refactor(term): feature check, not platform check
Diffstat (limited to 'src')
| -rw-r--r-- | src/term.c | 71 |
1 files changed, 43 insertions, 28 deletions
| @@ -107,16 +107,16 @@ typedef struct ls_RegConst { | |||
| 107 | // This is needed because some flags are not defined on all platforms. So we | 107 | // This is needed because some flags are not defined on all platforms. So we |
| 108 | // still export the constants, but they will be all 0, and hence not do anything. | 108 | // still export the constants, but they will be all 0, and hence not do anything. |
| 109 | #ifdef _WIN32 | 109 | #ifdef _WIN32 |
| 110 | // check compatibility: Windows virtual terminal processing was added in 2015, | 110 | // check compatibility: Windows virtual terminal processing was added in 2015, |
| 111 | // some older compiler suites don't have the proper headers. | 111 | // some older compiler suites don't have the proper headers. |
| 112 | #ifndef ENABLE_VIRTUAL_TERMINAL_INPUT | 112 | #ifndef ENABLE_VIRTUAL_TERMINAL_INPUT |
| 113 | #error Virtual terminal macros are undefined (eg. ENABLE_VIRTUAL_TERMINAL_INPUT). Update the toolchain or revert to Luasystem < 0.4 | 113 | #error Virtual terminal macros are undefined (eg. ENABLE_VIRTUAL_TERMINAL_INPUT). Update the toolchain or revert to Luasystem < 0.4 |
| 114 | #endif | 114 | #endif |
| 115 | #define CHECK_WIN_FLAG_OR_ZERO(flag) flag | 115 | #define CHECK_WIN_FLAG_OR_ZERO(flag) flag |
| 116 | #define CHECK_NIX_FLAG_OR_ZERO(flag) 0 | 116 | #define CHECK_NIX_FLAG_OR_ZERO(flag) 0 |
| 117 | #else | 117 | #else |
| 118 | #define CHECK_WIN_FLAG_OR_ZERO(flag) 0 | 118 | #define CHECK_WIN_FLAG_OR_ZERO(flag) 0 |
| 119 | #define CHECK_NIX_FLAG_OR_ZERO(flag) flag | 119 | #define CHECK_NIX_FLAG_OR_ZERO(flag) flag |
| 120 | #endif | 120 | #endif |
| 121 | 121 | ||
| 122 | // Export Windows constants to Lua | 122 | // Export Windows constants to Lua |
| @@ -166,8 +166,8 @@ static const struct ls_RegConst nix_console_i_flags[] = { | |||
| 166 | {"I_INLCR", CHECK_NIX_FLAG_OR_ZERO(INLCR)}, | 166 | {"I_INLCR", CHECK_NIX_FLAG_OR_ZERO(INLCR)}, |
| 167 | {"I_IGNCR", CHECK_NIX_FLAG_OR_ZERO(IGNCR)}, | 167 | {"I_IGNCR", CHECK_NIX_FLAG_OR_ZERO(IGNCR)}, |
| 168 | {"I_ICRNL", CHECK_NIX_FLAG_OR_ZERO(ICRNL)}, | 168 | {"I_ICRNL", CHECK_NIX_FLAG_OR_ZERO(ICRNL)}, |
| 169 | #ifdef __linux__ | 169 | #ifdef IUCLC |
| 170 | {"I_IUCLC", CHECK_NIX_FLAG_OR_ZERO(IUCLC)}, // Might also exist on AIX | 170 | {"I_IUCLC", CHECK_NIX_FLAG_OR_ZERO(IUCLC)}, |
| 171 | #else | 171 | #else |
| 172 | {"I_IUCLC", 0}, | 172 | {"I_IUCLC", 0}, |
| 173 | #endif | 173 | #endif |
| @@ -181,8 +181,8 @@ static const struct ls_RegConst nix_console_i_flags[] = { | |||
| 181 | static const struct ls_RegConst nix_console_o_flags[] = { | 181 | static const struct ls_RegConst nix_console_o_flags[] = { |
| 182 | // Output flags (c_oflag) | 182 | // Output flags (c_oflag) |
| 183 | {"O_OPOST", CHECK_NIX_FLAG_OR_ZERO(OPOST)}, | 183 | {"O_OPOST", CHECK_NIX_FLAG_OR_ZERO(OPOST)}, |
| 184 | #ifdef __linux__ | 184 | #ifdef OLCUC |
| 185 | {"O_OLCUC", CHECK_NIX_FLAG_OR_ZERO(OLCUC)}, // Might also exist on AIX | 185 | {"O_OLCUC", CHECK_NIX_FLAG_OR_ZERO(OLCUC)}, |
| 186 | #else | 186 | #else |
| 187 | {"O_OLCUC", 0}, | 187 | {"O_OLCUC", 0}, |
| 188 | #endif | 188 | #endif |
| @@ -190,29 +190,44 @@ static const struct ls_RegConst nix_console_o_flags[] = { | |||
| 190 | {"O_OCRNL", CHECK_NIX_FLAG_OR_ZERO(OCRNL)}, | 190 | {"O_OCRNL", CHECK_NIX_FLAG_OR_ZERO(OCRNL)}, |
| 191 | {"O_ONOCR", CHECK_NIX_FLAG_OR_ZERO(ONOCR)}, | 191 | {"O_ONOCR", CHECK_NIX_FLAG_OR_ZERO(ONOCR)}, |
| 192 | {"O_ONLRET", CHECK_NIX_FLAG_OR_ZERO(ONLRET)}, | 192 | {"O_ONLRET", CHECK_NIX_FLAG_OR_ZERO(ONLRET)}, |
| 193 | #if defined(__APPLE__) || defined(__linux__) | 193 | #ifdef OFILL |
| 194 | {"O_OFILL", CHECK_NIX_FLAG_OR_ZERO(OFILL)}, // Might also exist on AIX | 194 | {"O_OFILL", CHECK_NIX_FLAG_OR_ZERO(OFILL)}, |
| 195 | {"O_OFDEL", CHECK_NIX_FLAG_OR_ZERO(OFDEL)}, // Might also exist on AIX | ||
| 196 | {"O_NLDLY", CHECK_NIX_FLAG_OR_ZERO(NLDLY)}, // Might also exist on AIX | ||
| 197 | {"O_CRDLY", CHECK_NIX_FLAG_OR_ZERO(CRDLY)}, // Might also exist on AIX | ||
| 198 | #else | 195 | #else |
| 199 | {"O_OFILL", 0}, | 196 | {"O_OFILL", 0}, |
| 197 | #endif | ||
| 198 | #ifdef OFDEL | ||
| 199 | {"O_OFDEL", CHECK_NIX_FLAG_OR_ZERO(OFDEL)}, | ||
| 200 | #else | ||
| 200 | {"O_OFDEL", 0}, | 201 | {"O_OFDEL", 0}, |
| 202 | #endif | ||
| 203 | #ifdef NLDLY | ||
| 204 | {"O_NLDLY", CHECK_NIX_FLAG_OR_ZERO(NLDLY)}, | ||
| 205 | #else | ||
| 201 | {"O_NLDLY", 0}, | 206 | {"O_NLDLY", 0}, |
| 207 | #endif | ||
| 208 | #ifdef CRDLY | ||
| 209 | {"O_CRDLY", CHECK_NIX_FLAG_OR_ZERO(CRDLY)}, | ||
| 210 | #else | ||
| 202 | {"O_CRDLY", 0}, | 211 | {"O_CRDLY", 0}, |
| 203 | #endif | 212 | #endif |
| 204 | #if !defined(__NetBSD__) | 213 | #ifdef TABDLY |
| 205 | {"O_TABDLY", CHECK_NIX_FLAG_OR_ZERO(TABDLY)}, | 214 | {"O_TABDLY", CHECK_NIX_FLAG_OR_ZERO(TABDLY)}, |
| 206 | #else | 215 | #else |
| 207 | {"O_TABDLY", 0}, | 216 | {"O_TABDLY", 0}, |
| 208 | #endif | 217 | #endif |
| 209 | #if defined(__APPLE__) || defined(__linux__) | 218 | #ifdef BSDLY |
| 210 | {"O_BSDLY", CHECK_NIX_FLAG_OR_ZERO(BSDLY)}, // Might also exist on AIX | 219 | {"O_BSDLY", CHECK_NIX_FLAG_OR_ZERO(BSDLY)}, |
| 211 | {"O_VTDLY", CHECK_NIX_FLAG_OR_ZERO(VTDLY)}, // Might also exist on AIX | ||
| 212 | {"O_FFDLY", CHECK_NIX_FLAG_OR_ZERO(FFDLY)}, // Might also exist on AIX | ||
| 213 | #else | 220 | #else |
| 214 | {"O_BSDLY", 0}, | 221 | {"O_BSDLY", 0}, |
| 222 | #endif | ||
| 223 | #ifdef VTDLY | ||
| 224 | {"O_VTDLY", CHECK_NIX_FLAG_OR_ZERO(VTDLY)}, | ||
| 225 | #else | ||
| 215 | {"O_VTDLY", 0}, | 226 | {"O_VTDLY", 0}, |
| 227 | #endif | ||
| 228 | #ifdef FFDLY | ||
| 229 | {"O_FFDLY", CHECK_NIX_FLAG_OR_ZERO(FFDLY)}, | ||
| 230 | #else | ||
| 216 | {"O_FFDLY", 0}, | 231 | {"O_FFDLY", 0}, |
| 217 | #endif | 232 | #endif |
| 218 | {NULL, 0} | 233 | {NULL, 0} |
| @@ -222,8 +237,8 @@ static const struct ls_RegConst nix_console_l_flags[] = { | |||
| 222 | // Local flags (c_lflag) | 237 | // Local flags (c_lflag) |
| 223 | {"L_ISIG", CHECK_NIX_FLAG_OR_ZERO(ISIG)}, | 238 | {"L_ISIG", CHECK_NIX_FLAG_OR_ZERO(ISIG)}, |
| 224 | {"L_ICANON", CHECK_NIX_FLAG_OR_ZERO(ICANON)}, | 239 | {"L_ICANON", CHECK_NIX_FLAG_OR_ZERO(ICANON)}, |
| 225 | #ifdef __linux__ | 240 | #ifdef XCASE |
| 226 | {"L_XCASE", CHECK_NIX_FLAG_OR_ZERO(XCASE)}, // Might also exist on AIX | 241 | {"L_XCASE", CHECK_NIX_FLAG_OR_ZERO(XCASE)}, |
| 227 | #else | 242 | #else |
| 228 | {"L_XCASE", 0}, | 243 | {"L_XCASE", 0}, |
| 229 | #endif | 244 | #endif |
| @@ -233,9 +248,9 @@ static const struct ls_RegConst nix_console_l_flags[] = { | |||
| 233 | {"L_ECHONL", CHECK_NIX_FLAG_OR_ZERO(ECHONL)}, | 248 | {"L_ECHONL", CHECK_NIX_FLAG_OR_ZERO(ECHONL)}, |
| 234 | {"L_NOFLSH", CHECK_NIX_FLAG_OR_ZERO(NOFLSH)}, | 249 | {"L_NOFLSH", CHECK_NIX_FLAG_OR_ZERO(NOFLSH)}, |
| 235 | {"L_TOSTOP", CHECK_NIX_FLAG_OR_ZERO(TOSTOP)}, | 250 | {"L_TOSTOP", CHECK_NIX_FLAG_OR_ZERO(TOSTOP)}, |
| 236 | {"L_ECHOCTL", CHECK_NIX_FLAG_OR_ZERO(ECHOCTL)}, // Might not be available on all systems | 251 | {"L_ECHOCTL", CHECK_NIX_FLAG_OR_ZERO(ECHOCTL)}, |
| 237 | {"L_ECHOPRT", CHECK_NIX_FLAG_OR_ZERO(ECHOPRT)}, // Might not be available on all systems | 252 | {"L_ECHOPRT", CHECK_NIX_FLAG_OR_ZERO(ECHOPRT)}, |
| 238 | {"L_ECHOKE", CHECK_NIX_FLAG_OR_ZERO(ECHOKE)}, // Might not be available on all systems | 253 | {"L_ECHOKE", CHECK_NIX_FLAG_OR_ZERO(ECHOKE)}, |
| 239 | {"L_FLUSHO", CHECK_NIX_FLAG_OR_ZERO(FLUSHO)}, | 254 | {"L_FLUSHO", CHECK_NIX_FLAG_OR_ZERO(FLUSHO)}, |
| 240 | {"L_PENDIN", CHECK_NIX_FLAG_OR_ZERO(PENDIN)}, | 255 | {"L_PENDIN", CHECK_NIX_FLAG_OR_ZERO(PENDIN)}, |
| 241 | {"L_IEXTEN", CHECK_NIX_FLAG_OR_ZERO(IEXTEN)}, | 256 | {"L_IEXTEN", CHECK_NIX_FLAG_OR_ZERO(IEXTEN)}, |
