Skip to content

Commit

Permalink
core/graph: make alternative movement speed configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ret2libc authored and radare committed Jul 2, 2015
1 parent 647e957 commit e5bd85e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions libr/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ R_API int r_core_config_init(RCore *core) {
SETPREF("graph.web", "false", "Display graph in web browser (VV)");
SETI("graph.from", UT64_MAX, "");
SETI("graph.to", UT64_MAX, "");
SETI("graph.scroll", 5, "Scroll speed in ascii-art graph");

/* hud */
SETPREF("hud.path", "", "Set a custom path for the HUD file");
Expand Down
18 changes: 12 additions & 6 deletions libr/core/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ static int mousemode = 0;
#define MIN_NODE_HEIGTH BORDER_HEIGHT
#define INIT_HISTORY_CAPACITY 16
#define TITLE_LEN 128
#define SLOW_MOV 1
#define FAST_MOV 5
#define DEFAULT_SPEED 1

#define ZOOM_STEP 10
#define ZOOM_DEFAULT 100
Expand Down Expand Up @@ -1046,6 +1045,12 @@ static int agraph_refresh(struct agraph_refresh_data *grd) {
return R_TRUE;
}

static void agraph_toggle_speed (AGraph *g) {
int alt = r_config_get_i (g->core->config, "graph.scroll");

g->movspeed = g->movspeed == DEFAULT_SPEED ? alt : DEFAULT_SPEED;
}

static void agraph_init(AGraph *g) {
g->is_callgraph = R_FALSE;
g->is_instep = R_FALSE;
Expand All @@ -1056,7 +1061,7 @@ static void agraph_init(AGraph *g) {
g->history = r_stack_new (INIT_HISTORY_CAPACITY);
g->graph = r_graph_new ();
g->zoom = ZOOM_DEFAULT;
g->movspeed = SLOW_MOV;
g->movspeed = DEFAULT_SPEED;
}

static AGraph *agraph_new(RCore *core, RConsCanvas *can, RAnalFunction *fcn) {
Expand Down Expand Up @@ -1105,7 +1110,7 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti
goto err_graph_new;
}

grd = (struct agraph_refresh_data *)malloc (sizeof(*grd));
grd = R_NEW (struct agraph_refresh_data);
grd->g = g;
grd->fs = is_interactive;

Expand Down Expand Up @@ -1221,7 +1226,7 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti
" p - toggle mini-graph\n"
" u - select previous node\n"
" V - toggle basicblock / call graphs\n"
" w - toggle between movements speed 1 and 5\n"
" w - toggle between movements speed 1 and graph.scroll\n"
" x/X - jump to xref/ref\n"
" z/Z - step / step over\n"
" +/-/0 - zoom in/out/default\n"
Expand Down Expand Up @@ -1324,7 +1329,7 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti
// refresh graph
break;
case 'w':
g->movspeed = g->movspeed == SLOW_MOV ? FAST_MOV : SLOW_MOV;
agraph_toggle_speed (g);
break;
case -1: // EOF
case 'q':
Expand All @@ -1342,6 +1347,7 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti
}
}

free (grd);
agraph_free(g);
err_graph_new:
r_config_set_i (core->config, "scr.color", can->color);
Expand Down

0 comments on commit e5bd85e

Please sign in to comment.