Skip to content

Commit

Permalink
* Fix scrolling in visual (drop s eip in cmd.vprompt)
Browse files Browse the repository at this point in the history
* Add cmd.visual that runs when entering in visual mode
  • Loading branch information
radare committed Mar 12, 2009
1 parent d292b4f commit cfc2882
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo
echo $new_env $SHELL \
| sed -e 's, ,\n,g' \
| sed -e 's,^, ,g' \
| sed -e 's,$,\\,'
| sed -e 's,$, \\,'
echo

eval $new_env $SHELL
Expand Down
6 changes: 3 additions & 3 deletions libr/core/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ static int cmd_seek(void *data, const char *input)
if (input[0]=='\0') {
r_cons_printf("0x%llx\n", core->seek);
} else {
u64 off = r_num_math(&core->num, input+1);
int idelta = (input[1]==' ')?2:1;
u64 off = r_num_math(&core->num, input+idelta);
switch(input[0]) {
case ' ':
r_core_seek(core, off);
Expand Down Expand Up @@ -345,7 +346,7 @@ static int cmd_print(void *data, const char *input)
r_print_bytes(&core->print, core->block, len, "%02x");
break;
default:
fprintf(stderr, "Usage: p[8] [len]\n"
r_cons_printf("Usage: p[8] [len]\n"
" p8 [len] 8bit hexpair list of bytes\n"
" px [len] hexdump of N bytes\n"
" po [len] octal dump of N bytes\n"
Expand All @@ -367,7 +368,6 @@ static int cmd_flag(void *data, const char *input)
{
struct r_core_t *core = (struct r_core_t *)data;
int len = strlen(input)+1;
char *ptr;
char *str = alloca(len);
memcpy(str, input+1, len);

Expand Down
1 change: 1 addition & 0 deletions libr/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ int r_core_config_init(struct r_core_t *core)
config_set("cmd.touchtrace", "");
#endif
r_config_set(cfg, "cmd.prompt", "");
r_config_set(cfg, "cmd.visual", "? f && ?? s eip");
r_config_set(cfg, "cmd.vprompt", "p%");
r_config_set(cfg, "cmd.vprompt2", "CFV");
r_config_set(cfg, "cmd.vprompt3", "");
Expand Down
5 changes: 3 additions & 2 deletions libr/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ int r_core_init(struct r_core_t *core)
core->num.callback = &num_callback;
core->num.userptr = core;
r_print_init(&core->print);
core->print.printf = r_cons_printf;
r_lang_init(&core->lang);
r_lang_set_user_ptr(&core->lang, core);
r_anal_init(&core->anal);
Expand Down Expand Up @@ -247,12 +248,12 @@ int r_core_seek_delta(struct r_core_t *core, s64 addr)
/* check end of file */
if (0) { // tmp+addr>) {
addr = 0;
} else addr+=tmp;
} else addr += tmp;
} else {
/* check < 0 */
if (tmp+addr<0) {
addr = 0;
} else addr+=tmp;
} else addr += tmp;
}
core->seek = addr;
ret = r_core_block_read(core, 0);
Expand Down
3 changes: 2 additions & 1 deletion libr/core/t/radare2.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ int main(int argc, char **argv)
r_core_cmd(&r, ".dr*", 0);
r_core_cmd(&r, "s eip", 0);
r_core_cmd(&r, "e cmd.prompt=.dr",0);
r_core_cmd(&r, "\"e cmd.vprompt=.dr&&s eip\"",0);
r_core_cmd(&r, "\"e cmd.vprompt=.dr\"",0);
r_core_cmd(&r, "\"e cmd.visual=.dr&&s eip\"",0);
}

if (seek)
Expand Down
13 changes: 8 additions & 5 deletions libr/core/visual.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int r_core_visual_cmd(struct r_core_t *core, int ch)
if (ocursor ==-1) ocursor=cursor;
cursor--;
} else
r_core_cmd(core, "s- 2", 0);
r_core_cmd(core, "s-2", 0);
break;
case 'J':
if (curset) {
Expand All @@ -81,26 +81,26 @@ int r_core_visual_cmd(struct r_core_t *core, int ch)
if (ocursor ==-1) ocursor=cursor;
cursor++;
} else
r_core_cmd(core, "s+ 2", 0);
r_core_cmd(core, "s+2", 0);
break;
/* move */
case 'h':
if (curset) {
cursor--;
ocursor=-1;
} else r_core_cmd(core, "s- 1", 0);
} else r_core_cmd(core, "s-1", 0);
break;
case 'l':
if (curset) {
cursor++;
ocursor=-1;
} else r_core_cmd(core, "s+ 1", 0);
} else r_core_cmd(core, "s+1", 0);
break;
case 'j':
if (curset) {
cursor+=16;
ocursor=-1;
} else r_core_cmd(core, "s+ 16", 0);
} else r_core_cmd(core, "s+16", 0);
break;
case 'k':
if (curset) {
Expand Down Expand Up @@ -170,6 +170,9 @@ int r_core_visual(struct r_core_t *core, const char *input)
{
int ch;

char *vi = r_config_get(&core->config, "cmd.visual");
if (vi) r_core_cmd(core, vi, 0);

while(input[0]) {
if (!r_core_visual_cmd(core, input[0])) {
r_cons_clear00();
Expand Down

0 comments on commit cfc2882

Please sign in to comment.