Add autocompletion for pf.fmt.ele

This commit is contained in:
sivaramaaa 2018-06-10 00:37:13 +05:30 committed by radare
parent 5830198378
commit 772ada399d
1 changed files with 37 additions and 2 deletions

View File

@ -885,6 +885,33 @@ out:
free (input);
}
//TODO: make it recursive to handle nested struct
static int autocomplete_pfele (RCore *core, char *key, char *pfx, int idx, char *ptr) {
int i, ret = 0;
int len = strlen (ptr);
char* fmt = sdb_get (core->print->formats, key, NULL);
if (fmt) {
int nargs = r_str_word_set0_stack (fmt);
if (nargs > 1) {
for (i = 1; i < nargs; i++) {
const char *arg = r_str_word_get0 (fmt, i);
char *p = strchr (arg, '(');
char *p2 = strchr (arg, ')');
// remove '(' and ')' from fmt
if (p && p2) {
arg = p + 1;
*p2 = '\0';
}
if (!len || !strncmp (ptr, arg, len)) {
tmp_argv[ret++] = r_str_newf ("pf%s.%s.%s", pfx, key, arg);
}
}
}
}
free (fmt);
return ret;
}
#define ADDARG(x) if (!strncmp (line->buffer.data+chr, x, strlen (line->buffer.data+chr))) { tmp_argv[j++] = x; }
static int autocomplete(RLine *line) {
@ -1017,8 +1044,15 @@ static int autocomplete(RLine *line) {
int j = 0;
ls_foreach (sls, iter, kv) {
int len = strlen (line->buffer.data + chr);
if (!len || !strncmp (line->buffer.data + chr, kv->key, len)) {
tmp_argv[j++] = r_str_newf ("pf%s.%s", pfx, kv->key);
int minlen = R_MIN (len, strlen (kv->key));
if (!len || !strncmp (line->buffer.data + chr, kv->key, minlen)) {
char *p = strchr (line->buffer.data + chr, '.');
if (p) {
j += autocomplete_pfele (core, kv->key, pfx, j, p + 1);
break;
} else {
tmp_argv[j++] = r_str_newf ("pf%s.%s", pfx, kv->key);
}
}
}
if (j > 0) tmp_argv_heap = true;
@ -1086,6 +1120,7 @@ static int autocomplete(RLine *line) {
line->completion.argc = i;
line->completion.argv = tmp_argv;
} else if (!strncmp (line->buffer.data, "ts ", 3)
|| !strncmp (line->buffer.data, "tl ", 3)
|| !strncmp (line->buffer.data, "tss ", 4)
|| !strncmp (line->buffer.data, "ts* ", 4)) {
int i = 0;