18 #define UTF8_DETECT_ENV 1
19 #define UTF8_DETECT_LOCALE 0
20 #define UTF8_DETECT_CURSOR 0
22 #if UTF8_DETECT_CURSOR
23 static inline int rd(
const int fd) {
41 if (errno !=
EINTR && errno !=
EAGAIN && errno != EWOULDBLOCK) {
50 int current_tty(
void) {
71 }
while (
fd == -1 && errno ==
EINTR);
79 #if UTF8_DETECT_CURSOR
84 static int cursor_position(
const int tty,
int *
const rowptr,
int *
const colptr) {
85 struct termios saved, temporary;
86 int ret, res, rows, cols, saved_errno;
95 res = tcgetattr(
tty, &saved);
103 res = tcgetattr(
tty, &temporary);
111 temporary.c_lflag &= ~
ICANON;
112 temporary.c_lflag &= ~
ECHO;
113 temporary.c_cflag &= ~
CREAD;
143 if (res == 27 || res < 1)
157 rows = 10 * rows + res -
'0';
170 cols = 10 * cols + res -
'0';
188 if (res == -1 && !ret)
200 const char *
keys[] = {
"LC_ALL",
"LC_CTYPE",
"LANG",
NULL };
206 ret = strstr(
val,
"utf-8") || strstr(
val,
"utf8");
212 #if UTF8_DETECT_LOCALE
214 const char *ctype = setlocale(LC_CTYPE,
NULL);
215 if ((ctype !=
NULL) && (ctype = strchr(ctype,
'.')) && ctype++ &&
220 #if UTF8_DETECT_CURSOR
221 int row = 0, col = 0;
222 int row2 = 0, col2 = 0;
223 int fd = current_tty();
226 if (cursor_position(
fd, &row, &col)) {
231 if (cursor_position(
fd, &row2, &col2)) {
237 return ((col2 - col) == 2);
244 return GetConsoleOutputCP() == CP_UTF8;
RZ_API bool rz_cons_is_utf8(void)
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
RZ_API void Ht_() free(HtName_(Ht) *ht)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask dev
static struct @218 keys[]
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
RZ_API void rz_str_case(char *str, bool up)
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
#define rz_xwrite(fd, buf, count)
static const z80_opcode fd[]
int read(izstream &zs, T *x, Items items)