diff --git a/libr/cons/cutf8.c b/libr/cons/cutf8.c index 5a54a53bab..284b26cbec 100644 --- a/libr/cons/cutf8.c +++ b/libr/cons/cutf8.c @@ -18,6 +18,7 @@ #define RD_EIO (-2) /* select utf8 terminal detection method */ +#define R_UTF8_DETECT_R2ENV 1 #define R_UTF8_DETECT_ENV 1 #define R_UTF8_DETECT_LOCALE 0 #define R_UTF8_DETECT_CURSOR 0 @@ -205,6 +206,19 @@ static int cursor_position(const int tty, int *const rowptr, int *const colptr) R_API bool r_cons_is_utf8(void) { bool ret = false; +#if R_UTF8_DETECT_R2ENV + char *e = r_sys_getenv ("R2_UTF8"); + if (e) { + bool is_set = *e; + if (is_set) { + ret = r_str_is_true (e); + } + free (e); + if (is_set) { + return ret; + } + } +#endif #if R_UTF8_DETECT_ENV const char *keys[] = { "LC_ALL", "LC_CTYPE", "LANG", NULL }; const char **key = keys; @@ -220,8 +234,8 @@ R_API bool r_cons_is_utf8(void) { #endif #if R_UTF8_DETECT_LOCALE const char *ctype = setlocale (LC_CTYPE, NULL); - if ( (ctype != NULL) && (ctype = strchr(ctype, '.')) && ctype++ && - (r_str_casecmp(ctype, "UTF-8") == 0 || r_str_casecmp(ctype, "UTF8") == 0)) { + if ((ctype != NULL) && (ctype = strchr (ctype, '.')) && ctype++ && + (!r_str_casecmp (ctype, "UTF-8") || !r_str_casecmp (ctype, "UTF8"))) { return true; } #endif @@ -231,7 +245,7 @@ R_API bool r_cons_is_utf8(void) { int fd = current_tty (); if (fd == -1) return false; - if (cursor_position(fd, &row, &col)) { + if (cursor_position (fd, &row, &col)) { close (fd); return false; } diff --git a/libr/core/cfile.c b/libr/core/cfile.c index d1cab0c2f2..5f65df8a0e 100644 --- a/libr/core/cfile.c +++ b/libr/core/cfile.c @@ -221,6 +221,7 @@ R_API void r_core_sysenv_end(RCore *core, const char *cmd) { r_sys_setenv ("R2_FILE", NULL); r_sys_setenv ("R2_BYTES", NULL); r_sys_setenv ("R2_OFFSET", NULL); + r_sys_setenv ("R2_UTF8", NULL); // remove temporary R2_CONFIG file char *r2_config = r_sys_getenv ("R2_CONFIG"); @@ -257,28 +258,32 @@ R_API char *r_core_sysenv_begin(RCore * core, const char *cmd) { r_sys_setenv ("R2_XOFFSET", sdb_fmt ("0x%08"PFMT64x, core->offset)); r_sys_setenv ("R2_ENDIAN", core->rasm->big_endian? "big": "little"); r_sys_setenv ("R2_BSIZE", sdb_fmt ("%d", core->blocksize)); - +#if 0 // dump current config file so other r2 tools can use the same options char *config_sdb_path = NULL; int config_sdb_fd = r_file_mkstemp (NULL, &config_sdb_path); if (config_sdb_fd >= 0) { close (config_sdb_fd); } - Sdb *config_sdb = sdb_new (NULL, config_sdb_path, 0); r_config_serialize (core->config, config_sdb); sdb_sync (config_sdb); sdb_free (config_sdb); r_sys_setenv ("R2_CONFIG", config_sdb_path); - +#endif r_sys_setenv ("RABIN2_LANG", r_config_get (core->config, "bin.lang")); r_sys_setenv ("RABIN2_DEMANGLE", r_config_get (core->config, "bin.demangle")); r_sys_setenv ("R2_ARCH", r_config_get (core->config, "asm.arch")); r_sys_setenv ("R2_BITS", sdb_fmt ("%"PFMT64u, r_config_get_i (core->config, "asm.bits"))); - r_sys_setenv ("R2_COLOR", r_config_get_i (core->config, "scr.color")? "1": "0"); - r_sys_setenv ("R2_DEBUG", r_config_get_i (core->config, "cfg.debug")? "1": "0"); - r_sys_setenv ("R2_IOVA", r_config_get_i (core->config, "io.va")? "1": "0"); + char *s = sdb_itoa (r_config_get_i (core->config, "scr.color"), NULL, 10); + r_sys_setenv ("R2_COLOR", s); + free (s); + r_sys_setenv ("R2_UTF8", r_config_get_b (core->config, "scr.utf8")? "1": "0"); + r_sys_setenv ("R2_DEBUG", r_config_get_b (core->config, "cfg.debug")? "1": "0"); + r_sys_setenv ("R2_IOVA", r_config_get_b (core->config, "io.va")? "1": "0"); +#if 0 free (config_sdb_path); +#endif return ret; }