Add scr.fgets and fix rax2 -s for emscripten

This commit is contained in:
pancake 2013-09-16 04:08:08 +02:00
parent c1629360f9
commit 92bdbf0c0a
6 changed files with 41 additions and 9 deletions

View File

@ -3,5 +3,13 @@ BINDEPS=r_util
include ../rules.mk
pub:
U=$(LTOP)/../shlr/www/enyo/node_modules/uglify-js/bin/uglifyjs
$U:
cd $(LTOP)/../shlr/www/enyo ; ${MAKE}
rax2.min.js: $U
$U < rax2.js > rax2.min.js
pub: rax2.min.js
scp index.html main.js rax2.min.js radare.org:/srv/http/radareorg/js/rax2

View File

@ -118,9 +118,10 @@ static int rax (char *str, int len, int last) {
if (flags & 512) { // -k
ut32 n = r_num_math (num, str);
ut8 *np = (ut8*)&n;
if (flags & 1) write (1, &n, sizeof (n));
if (flags & 1) fwrite (&n, sizeof (n), 1, stdout);
else printf ("%02x%02x%02x%02x\n",
np[0], np[1], np[2], np[3]);
fflush (stdout);
return R_TRUE;
}
if (flags & 256) { // -k
@ -148,7 +149,11 @@ static int rax (char *str, int len, int last) {
buf = malloc (n);
memset (buf, '\0', n);
n = r_hex_str2bin (str, (ut8*)buf);
write (1, buf, n);
fwrite (buf, n, 1, stdout);
#if __EMSCRIPTEN__
puts ("");
#endif
fflush (stdout);
free (buf);
return R_TRUE;
}

View File

@ -126,10 +126,8 @@ R_API int r_cons_arrow_to_hjkl(int ch) {
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) {
RCons *cons = r_cons_singleton ();
int color = cons->pal.input && *cons->pal.input;
if (cons->user_fgets) {
int ret = cons->user_fgets (buf, len);
return ret;
}
if (cons->user_fgets)
return cons->user_fgets (buf, len);
*buf = '\0';
fflush (cons->fdin);
if (color) {

View File

@ -2,6 +2,15 @@
#include <r_core.h>
static int config_scrfgets_callback(void* user, void* data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode*) data;
if (node->i_value)
core->cons->user_fgets = NULL;
else core->cons->user_fgets = (void *)r_core_fgets;
return R_TRUE;
}
static int config_scrcolumns_callback(void* user, void* data) {
RConfigNode *node = (RConfigNode*) data;
int n = atoi (node->value);
@ -788,6 +797,13 @@ r_config_set (cfg, "asm.arch", R_SYS_ARCH);
r_config_set (cfg, "graph.font", "Courier");
r_config_desc (cfg, "graph.font", "font to be used by the dot graphs");
#if __EMSCRIPTEN__
r_config_set_cb (cfg, "scr.fgets", "true", config_scrfgets_callback);
#else
r_config_set_cb (cfg, "scr.fgets", "false", config_scrfgets_callback);
#endif
r_config_desc (cfg, "scr.fgets", "Use fgets instead of dietline for prompt input");
r_config_set_cb (cfg, "scr.columns", "0", config_scrcolumns_callback);
r_config_set_cb (cfg, "scr.rows", "0", config_scrrows_callback);
r_config_set_cb (cfg, "scr.sparse", "false", config_scrsparse_callback);

View File

@ -402,7 +402,7 @@ static int autocomplete(RLine *line) {
return R_TRUE;
}
static int myfgets(char *buf, int len) {
R_API int r_core_fgets(char *buf, int len) {
/* TODO: link against dietline if possible for autocompletion */
char *ptr;
RLine *rli = r_line_singleton ();
@ -496,7 +496,11 @@ R_API int r_core_init(RCore *core) {
if (singleton) {
r_cons_new ();
core->cons->line->user = core;
core->cons->user_fgets = (void *)myfgets;
#if __EMSCRIPTEN__
core->cons->user_fgets = NULL;
#else
core->cons->user_fgets = (void *)r_core_fgets;
#endif
//r_line_singleton()->user = (void *)core;
r_line_hist_load (R2_HOMEDIR"/history");
singleton = R_FALSE;

View File

@ -171,6 +171,7 @@ R_API void r_core_prompt_loop(RCore *core);
R_API int r_core_cmd(RCore *core, const char *cmd, int log);
R_API void r_core_cmd_repeat(RCore *core, int next);
R_API char *r_core_editor (RCore *core, const char *str);
R_API int r_core_fgets(char *buf, int len);
// FIXME: change (void *user) to (RCore *core)
R_API int r_core_cmdf(void *user, const char *fmt, ...);
R_API int r_core_flush(void *user, const char *cmd);