Revert V* behaviour, add < command and make dietline reuse rcons.readChar

This commit is contained in:
pancake 2018-02-28 01:19:08 +01:00
parent ebd92e91be
commit 7b5ab319f8
4 changed files with 41 additions and 13 deletions

View file

@ -109,15 +109,22 @@ R_API int r_line_dietline_init() {
/* read utf8 char into 's', return the length in bytes */
static int r_line_readchar_utf8(ut8 *s, int slen) {
// TODO: add support for w32
ssize_t len, t, i;
ssize_t len, i;
if (slen < 1) {
return 0;
}
int ch = r_cons_readchar ();
if (ch == -1) {
return -1;
}
*s = ch;
#if 0
if ((t = read (0, s, 1)) != 1) {
return t;
}
s[0] = r_cons_controlz (s[0]);
if (s[0] < 0x80) {
#endif
*s = r_cons_controlz (*s);
if (*s < 0x80) {
len = 1;
} else if ((s[0] & 0xe0) == 0xc0) {
len = 2;
@ -132,8 +139,10 @@ static int r_line_readchar_utf8(ut8 *s, int slen) {
return -1;
}
for (i = 1; i < len; i++) {
if ((t = read (0, s + i, 1)) != 1) {
return t;
int ch = r_cons_readchar ();
if (ch != -1) {
s[i] = ch;
return 1;
}
if ((s[i] & 0xc0) != 0x80) {
return -1;
@ -199,6 +208,9 @@ do_it_again:
return buf[0];
}
#endif
#if 0
// TODO use define here to hac
static int r_line_readchar() {
ut8 buf[2];
*buf = '\0';
@ -237,7 +249,8 @@ do_it_again:
}
if (buf[0] == 70) {
return 5;
} else if (buf[0] == 72) {
}
if (buf[0] == 72) {
return 1;
}
return 0;
@ -262,6 +275,7 @@ do_it_again:
#endif
return buf[0];
}
#endif
R_API int r_line_hist_add(const char *line) {
if (!line || !*line) {
@ -548,6 +562,7 @@ R_API void r_line_autocomplete() {
R_API const char *r_line_readline() {
return r_line_readline_cb (NULL, NULL);
}
#if __WINDOWS__ && !__CYGWIN__
R_API const char *r_line_readline_cb_win(RLineReadCallback cb, void *user) {
int columns = r_cons_get_size (NULL) - 2;
@ -961,9 +976,8 @@ _end:
R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) {
#if __WINDOWS__ && !__CYGWIN__
#if 1 // new implementation for read input at windows by skuater. If something fail set this to 0
// new implementation for read input at windows by skuater. If something fail set this to 0
return r_line_readline_cb_win (cb, user);
#endif
#endif
int columns = r_cons_get_size (NULL) - 2;
const char *gcomp_line = "";
@ -1019,7 +1033,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) {
}
buf[utflen] = 0;
#else
ch = r_line_readchar ();
ch = r_cons_readchar ();
if (ch == -1) {
r_cons_break_pop ();
return NULL;
@ -1242,7 +1256,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) {
}
break;
case 27:// esc-5b-41-00-00
buf[0] = r_line_readchar ();
buf[0] = r_cons_readchar ();
switch (buf[0]) {
case 127: // alt+bkspace
unix_word_rubout ();
@ -1283,7 +1297,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) {
}
break;
default:
buf[1] = r_line_readchar ();
buf[1] = r_cons_readchar ();
if (buf[1] == -1) {
r_cons_break_pop ();
return NULL;
@ -1296,7 +1310,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) {
I.buffer.data + I.buffer.index + 1,
strlen (I.buffer.data + I.buffer.index + 1) + 1);
}
buf[1] = r_line_readchar ();
buf[1] = r_cons_readchar ();
if (buf[1] == -1) {
r_cons_break_pop ();
return NULL;

View file

@ -190,7 +190,7 @@ static void r_cons_rgb_gen (char *outstr, ut8 a, ut8 r, ut8 g, ut8 b) {
/* Return the computed color string for the specified color */
R_API char *r_cons_rgb_str (char *outstr, RColor *rcolor) {
if (!rcolor || (!outstr && !(outstr = malloc (32)))) {
if (!rcolor || (!outstr && !(outstr = malloc (128)))) {
return NULL;
}
*outstr = 0;

View file

@ -1173,6 +1173,7 @@ static int cmd_visual(void *data, const char *input) {
if (!r_config_get_i (core->config, "scr.interactive")) {
return false;
}
#if 0
char *buf = strdup (input);
int len = r_str_unescape (buf);
r_cons_readpush (buf, len);
@ -1180,6 +1181,17 @@ static int cmd_visual(void *data, const char *input) {
int res = r_core_visual ((RCore *)data, ""); //input);
r_cons_readflush ();
return res;
#else
return r_core_visual ((RCore *)data, input);
#endif
}
static int cmd_pipein(void *user, const char *input) {
char *buf = strdup (input);
int len = r_str_unescape (buf);
r_cons_readpush (buf, len);
free (buf);
return 0;
}
static int task_finished(void *user, void *data) {
@ -3635,6 +3647,7 @@ R_API void r_core_cmd_init(RCore *core) {
{"Text", "Text log utility", cmd_log, cmd_log_init},
{"u", "uname/undo", cmd_uname},
{"visual", "enter visual mode", cmd_visual},
{"<", "pipe into RCons.readChar", cmd_pipein},
{"Visual", "enter visual mode", cmd_visual},
{"write", "write bytes", cmd_write, cmd_write_init},
{"x", "alias for px", cmd_hexdump},

View file

@ -26,6 +26,7 @@ static const char *help_msg_root[] = {
"(macro arg0 arg1)", "", "Manage scripting macros",
".", "[?] [-|(m)|f|!sh|cmd]", "Define macro or load r2, cparse or rlang file",
"=","[?] [cmd]", "Send/Listen for Remote Commands (rap://, http://, <fd>)",
"<","[...]", "Push escaped string into the RCons.readChar buffer",
"/","[?]", "Search for bytes, regexps, patterns, ..",
"!","[?] [cmd]", "Run given command as in system(3)",
"#","[?] !lang [..]", "Hashbang to run an rlang script",