Implement Ll, Llq and #!?q commands for better rlang listing ##shell

This commit is contained in:
pancake 2022-11-25 00:19:14 +01:00
parent 93c5a89b07
commit a935629aae
3 changed files with 43 additions and 12 deletions

View File

@ -8,6 +8,7 @@ const char *help_msg_hash[] = {
"#!", "", "list all available interpreters",
"#!?", "", "show this help message",
"#!?j", "", "list all available interpreters in JSON",
"#!?q", "", "list all available lang plugin names (See Ll?)",
"#!v?", "", "show vlang script example",
"#!python?", "", "show python script example",
"#!python", "", "run python commandline",
@ -405,10 +406,14 @@ static int cmd_hash_bang(RCore *core, const char *input) {
R_LOG_ERROR ("scr.interactive required to run the rlang prompt");
}
}
} else if (av[0][0] == '?' && av[0][1] == 'j') {
r_lang_list (core->lang, 'j');
} else if (av[0][0] == '?' || av[0][0] == '*') {
r_lang_list (core->lang, 0);
} else if (av[0][0] == '?') {
if (av[0][1] == 'j') {
r_lang_list (core->lang, 'j');
} else if (av[0][1] == '*') {
r_lang_list (core->lang, 0);
} else if (av[0][1] == 'q') {
r_lang_list (core->lang, 'q');
}
}
} else {
r_lang_list (core->lang, 0);

View File

@ -31,7 +31,7 @@ static const char *help_msg_L[] = {
"Lg", "", "list egg plugins",
"Lh", "", "list hash plugins (ph)",
"Li", "[j]", "list bin plugins (iL)",
"Ll", "[j]", "list lang plugins (#!)",
"Ll", "[qj]", "list lang plugins (#!)",
"LL", "", "lock screen",
"Lm", "[j]", "list fs plugins (mL)",
"Lo", "", "list io plugins (oL)",
@ -497,10 +497,16 @@ static int cmd_plugins(void *data, const char *input) {
}
break;
case 'l': // "Ll"
if (input[1] == 'j') {
r_core_cmd0 (core, "#!?j");
if (input[1] == 'j') { // "Llj" "#!?j"
r_lang_list (core->lang, 'j');
} else if (input[1] == 'q') { // "Llq" "#!?q"
r_lang_list (core->lang, 'q');
} else if (input[1] == ',') { // "Ll,"
r_lang_list (core->lang, ','); // TODO: take table query as argument
} else if (input[1] == '?') { // "Ll?"
r_cons_printf ("Usage: Ll[jq] - list r_lang plugins\n");
} else {
r_core_cmd0 (core, "#!");
r_lang_list (core->lang, 0);
}
break;
case 'L': // "LL"

View File

@ -1,4 +1,4 @@
/* radare2 - LGPL - Copyright 2009-2021 - pancake */
/* radare2 - LGPL - Copyright 2009-2022 - pancake */
#include <r_lang.h>
#include <r_util.h>
@ -153,19 +153,34 @@ R_API void r_lang_list(RLang *lang, int mode) {
return;
}
PJ *pj = NULL;
RTable *table = NULL;
if (mode == 'j') {
pj = pj_new ();
pj_a (pj);
} else if (mode == ',') {
table = r_table_new ("langs");
RTableColumnType *typeString = r_table_type ("string");
r_table_add_column (table, typeString, "name", 0);
r_table_add_column (table, typeString, "license", 0);
r_table_add_column (table, typeString, "desc", 0);
}
r_list_foreach (lang->langs, iter, h) {
const char *license = h->license
? h->license : "???";
if (mode == 'j') {
pj_o (pj);
pj_ks (pj, "name", h->name);
pj_ks (pj, "license", h->license);
pj_ks (pj, "description", h->desc);
pj_ks (pj, "name", r_str_get (h->name));
pj_ks (pj, "license", r_str_get (h->license));
pj_ks (pj, "description", r_str_get (h->desc));
pj_end (pj);
} else if (mode == 'q') {
lang->cb_printf ("%s\n", h->name);
} else if (mode == ',') {
r_table_add_row (table,
r_str_get (h->name),
r_str_get (h->license),
r_str_get (h->desc), 0);
} else {
lang->cb_printf ("%s: (%s) %s\n",
h->name, license, h->desc);
@ -176,6 +191,11 @@ R_API void r_lang_list(RLang *lang, int mode) {
char *s = pj_drain (pj);
lang->cb_printf ("%s\n", s);
free (s);
} else if (table) {
char *s = r_table_tostring (table);
lang->cb_printf ("%s\n", s);
free (s);
r_table_free (table);
}
}