Implement &: for queue commands ##core (#18885)

This commit is contained in:
pancake 2021-07-05 20:55:15 +02:00 committed by GitHub
parent 52e1b2b126
commit d6208e8b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 17 deletions

View File

@ -2477,6 +2477,10 @@ static int cmd_tasks(void *data, const char *input) {
case 'j': // "&j"
r_core_task_list (core, *input);
break;
case ':': { // "&:"
r_core_cmd_queue (core, input + 1);
}
break;
case 'b': { // "&b"
if (r_sandbox_enable (0)) {
eprintf ("This command is disabled in sandbox mode\n");

View File

@ -111,6 +111,7 @@ static const char *help_msg_prg[] = {
static const char *help_msg_amper[] = {
"Usage:", "&[-|<cmd>]", "Manage tasks (WARNING: Experimental. Use with caution!)",
"&", " <cmd>", "run <cmd> in a new background task",
"&:", "<cmd>", "queue <cmd> to be executed later when possible",
"&t", " <cmd>", "run <cmd> in a new transient background task (auto-delete when it is finished)",
"&", "", "list all tasks",
"&j", "", "list all tasks (in JSON)",

View File

@ -2817,7 +2817,7 @@ R_API bool r_core_init(RCore *core) {
// ideally sdb_ns_set should be used here, but it doesnt seems to work well. must fix
// sdb_ns_set (DB, "charset", core->print->charset->db);
core->stkcmd = NULL;
core->cmdqueue = NULL;
core->cmdqueue = r_list_newf (free);
core->cmdrepeat = true;
core->yank_buf = r_buf_new ();
core->num = r_num_new (&num_callback, &str_callback, core);
@ -3017,7 +3017,7 @@ R_API void r_core_fini(RCore *c) {
free (c->cmdlog);
free (c->lastsearch);
R_FREE (c->cons->pager);
free (c->cmdqueue);
r_list_free (c->cmdqueue);
free (c->lastcmd);
free (c->stkcmd);
r_project_free (c->prj);
@ -3204,6 +3204,15 @@ static void set_prompt(RCore *r) {
R_FREE (prompt);
}
R_API void r_core_cmd_queue(RCore *core, const char *line) {
if (line) {
r_list_append (core->cmdqueue, strdup (line));
} else {
r_list_free (core->cmdqueue);
core->cmdqueue = r_list_newf (free);
}
}
R_API int r_core_prompt(RCore *r, int sync) {
char line[4096];
@ -3220,8 +3229,7 @@ R_API int r_core_prompt(RCore *r, int sync) {
if (sync) {
return r_core_prompt_exec (r);
}
free (r->cmdqueue);
r->cmdqueue = strdup (line);
r_core_cmd_queue (r, line);
if (r->scr_gadgets && *line && *line != 'q') {
r_core_cmd0 (r, "pg");
}
@ -3230,18 +3238,30 @@ R_API int r_core_prompt(RCore *r, int sync) {
}
R_API int r_core_prompt_exec(RCore *r) {
int ret = r_core_cmd (r, r->cmdqueue, true);
r->rc = r->num->value;
//int ret = r_core_cmd (r, r->cmdqueue, true);
if (r->cons && r->cons->use_tts) {
const char *buf = r_cons_get_buffer();
r_sys_tts (buf, true);
r->cons->use_tts = false;
}
r_cons_echo (NULL);
r_cons_flush ();
if (r->cons && r->cons->line && r->cons->line->zerosep) {
r_cons_zero ();
int ret = -1;
while (!r_list_empty (r->cmdqueue)) {
char *cmd = r_list_pop (r->cmdqueue);
if (!cmd) {
break;
}
ret = r_core_cmd (r, cmd, true);
if (ret < 0) {
r_core_cmd_queue (r, NULL);
break;
}
r->rc = r->num->value;
// int ret = r_core_cmd (r, cmd, true);
free (cmd);
if (r->cons && r->cons->use_tts) {
const char *buf = r_cons_get_buffer ();
r_sys_tts (buf, true);
r->cons->use_tts = false;
}
r_cons_echo (NULL);
r_cons_flush ();
if (r->cons && r->cons->line && r->cons->line->zerosep) {
r_cons_zero ();
}
}
return ret;
}

View File

@ -298,7 +298,7 @@ struct r_core_t {
RAGraph *graph;
RPanelsRoot *panels_root;
RPanels* panels;
char *cmdqueue;
RList *cmdqueue;
char *lastcmd;
char *cmdlog;
bool cfglog; // cfg.corelog
@ -427,6 +427,7 @@ R_API int r_core_fgets(char *buf, int len);
R_API RFlagItem *r_core_flag_get_by_spaces(RFlag *f, ut64 off);
R_API int r_core_cmdf(RCore *core, const char *fmt, ...) R_PRINTF_CHECK(2, 3);
R_API int r_core_cmd0(RCore *core, const char *cmd);
R_API void r_core_cmd_queue(RCore *core, const char *line);
R_API void r_core_cmd_init(RCore *core);
R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd);
R_API char *r_core_cmd_str(RCore *core, const char *cmd);