Implement more utf8 terminal check, handle jbe in asm.pseudo

This commit is contained in:
pancake 2015-04-20 14:44:54 +02:00
parent 9508a175b7
commit 63f0dc8e3f
5 changed files with 52 additions and 21 deletions

View file

@ -5,8 +5,13 @@
# update: 2010-01-14
#
LANG=C
LC_ALL=C
LOADLIBS=1
export LANG
export LC_ALL
list () {
for a in $STATIC ; do echo "static $a" ; done
for a in $SHARED ; do echo "shared $a" ; done

View file

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2014 - pancake */
/* radare - LGPL - Copyright 2015 - pancake */
// Copypasta from http://www.linuxquestions.org/questions/programming-9/get-cursor-position-in-c-947833/
#include <r_cons.h>
@ -12,6 +12,11 @@
#define RD_EOF -1
#define RD_EIO -2
/* select utf8 terminal detection method */
#define UTF8_DETECT_ENV 1
#define UTF8_DETECT_LOCALE 0
#define UTF8_DETECT_CURSOR 0
static inline int rd(const int fd) {
unsigned char buffer[4];
ssize_t n;
@ -87,6 +92,7 @@ int current_tty(void) {
#endif
}
#if UTF8_DETECT_CURSOR
/* As the tty for current cursor position.
* This function returns 0 if success, errno code otherwise.
* Actual errno will be unchanged.
@ -201,9 +207,28 @@ static int cursor_position(const int tty, int *const rowptr, int *const colptr)
/* Done. */
return ret;
}
#endif
R_API int r_cons_is_utf8() {
int ret = 0;
#if UTF8_DETECT_ENV
char *sval = r_sys_getenv ("LC_CTYPE");
if (sval) {
r_str_case (sval, 0);
if (!strcmp (sval, "utf-8"))
ret = 1;
free (sval);
}
#endif
#if UTF8_DETECT_LOCALE
#include <locale.h>
const char *ctype = setlocale(LC_CTYPE, NULL);
if ( (ctype != NULL) && (ctype = strchr(ctype, '.')) && ctype++ &&
(strcasecmp(ctype, "UTF-8") == 0 || strcasecmp(ctype, "UTF8") == 0)) {
return 1;
}
#endif
#if UTF8_DETECT_CURSOR
int row = 0, col = 0;
int row2 = 0, col2 = 0;
int fd = current_tty();
@ -221,6 +246,8 @@ R_API int r_cons_is_utf8() {
close (fd);
write (1, "\r \r", 6);
return ((col2-col)==2);
#endif
return ret;
}
#else
R_API int r_cons_is_utf8() {

View file

@ -1272,18 +1272,8 @@ R_API int r_core_config_init(RCore *core) {
SETCB("scr.truecolor", "false", &cb_truecolor, "Manage color palette (0: ansi 16, 1: 256, 2: 16M)");
SETCB("scr.color", (core->print->flags&R_PRINT_FLAGS_COLOR)?"true":"false", &cb_color, "Enable/Disable colors");
SETCB("scr.null", "false", &cb_scrnull, "if set shows no output (disable console)");
#if 0
{
const char *val;
char *sval = r_sys_getenv ("LC_CTYPE");
r_str_case (sval, 0);
val = strcmp (sval, "utf-8")? "false": "true";
free (sval);
r_config_set_cb (cfg, "scr.utf8", val, &cb_utf8);
}
#else
SETCB("scr.utf8", "false", &cb_utf8, "Show UTF-8 characters instead of ANSI");
#endif
SETCB("scr.utf8", r_cons_is_utf8()?"true":"false",
&cb_utf8, "Show UTF-8 characters instead of ANSI");
SETPREF("scr.histsave", "true", "Always save history on exit");
/* search */
SETCB("search.contiguous", "true", &cb_contiguous, "Accept contiguous/adjacent search hits");

View file

@ -56,9 +56,10 @@ static int replace(int argc, const char *argv[], char *newstr) {
{ "je", "isZero 1)"},
{ "jle", "isLessOrEqual 1)"},
{ "jge", "isGreaterOrEqual 1)"},
{ "jbe", "isBelowOrEqual 1)"},
{ "jne", "notZero 1)"},
{ "call", "1 ()"},
{ "test", "if (1 == 2)"},
{ "test", "if (1 == 2"},
{ "xor", "1 ^= 2"},
{ NULL }
};

View file

@ -18,13 +18,21 @@ int _main() {
return 0;
}
int main() {
RRegex *rx = r_regex_new ("^hi", "");
int main(int argc, char **argv) {
const char *needle = "^hi";
const char *haystack_1 = "patata";
const char *haystack_2 = "hillow";
if (argc>3) {
needle = argv[1];
haystack_1 = argv[2];
haystack_2 = argv[3];
} else printf ("Using default values\n");
RRegex *rx = r_regex_new (needle, "");
if (rx) {
int res = r_regex_exec (rx, "patata", 0, 0, 0);
printf ("result (patata) = %d\n", res);
res = r_regex_exec (rx, "hillow", 0, 0, 0);
printf ("result (hillow) = %d\n", res);
int res = r_regex_exec (rx, haystack_1, 0, 0, 0);
printf ("result (%s) = %d\n", haystack_1, res);
res = r_regex_exec (rx, haystack_2, 0, 0, 0);
printf ("result (%s) = %d\n", haystack_2, res);
r_regex_free (rx);
} else printf ("oops, cannot compile regexp\n");
return 0;