Implement V% to move cursor to the next matching pair

This commit is contained in:
pancake 2015-02-13 00:36:05 +01:00
parent 6ae594b426
commit e627b3a0a5
2 changed files with 40 additions and 2 deletions

View File

@ -870,7 +870,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) {
if (fcn) {
r_anal_fcn_xref_del (core->anal, fcn, a, b, -1);
} else eprintf ("Cannot del reference to non-function\n");
} else eprintf ("Usage: afr- [src] [dst]\n");
} else eprintf ("Usage: afx- [src] [dst]\n");
free (mi);
}
break;
@ -898,7 +898,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) {
"af*", "", "output radare commands",
"afa", "[?] [idx] [type] [name]", "add function argument",
"af[aAv?]", "[arg]", "manipulate args, fastargs and variables in function",
"afb+", " fcn_at bbat bbsz [jump] [fail] ([type] ([diff]))", "add bb to function @ fcnaddr",
"afb+", " fa a sz [j] [f] ([t]( [d]))","add bb to function @ fcnaddr",
"afb", " [addr]", "List basic blocks of given function",
"afB", " 16", "set current function as thumb (change asm.bits)",
"afc", "@[addr]", "calculate the Cyclomatic Complexity (starting at addr)",

View File

@ -89,6 +89,7 @@ static void visual_help() {
"Visual mode help:\n"
" ? show this help or manpage in cursor mode\n"
" & rotate asm.bits between supported 8, 16, 32, 64\n"
" % in cursor mode moves cursor to the next matching pair\n"
" @ set cmd.vprompt to run commands before the visual prompt\n"
" ! run r2048 game\n"
" _ enter the hud\n"
@ -299,6 +300,36 @@ static void setdiff (RCore *core) {
r_config_set (core->config, "diff.to", to);
}
static void findPair (RCore *core) {
ut8 buf[256];
int len, d = cursor+1;
int delta = 0;
const ut8 *p, *q;
const char *keys = "{}[]()<>";
ut8 ch = core->block[cursor];
p = (const ut8*)strchr (keys, ch);
if (p) {
delta = (size_t)(p-(const ut8*)keys);
ch = (delta%2)? p[-1]: p[1];
}
len = 1;
buf[0] = ch;
q = r_mem_mem (core->block+d, core->blocksize-d,
(const ut8*)buf, len);
if (!q) {
q = r_mem_mem (core->block, R_MIN (core->blocksize, d),
(const ut8*)buf, len);
}
if (q) {
cursor = (int)(size_t)(q-core->block);
if (len>1) {
ocursor = cursor+len-1;
} else ocursor = -1;
showcursor (core, R_TRUE);
}
}
// TODO: integrate in '/' command with search.inblock ?
static void visual_search (RCore *core) {
const ut8 *p;
@ -1130,6 +1161,13 @@ R_API int r_core_visual_cmd(RCore *core, int ch) {
case 'P':
setprintmode (core, -1);
break;
case '%':
if (curset) {
findPair (core);
} else {
/* do nothing? */
}
break;
case 'm':
r_core_visual_mark (core, r_cons_readchar ());
break;