mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-24 23:06:36 +00:00
Allow changing number of saved input lines ##shell
Authored-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
9935bbece0
commit
6967f63396
@ -1989,7 +1989,7 @@ static int xtensa_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf_origina
|
||||
xtensa_op0_fns[(buf_original[0] & 0xf)] (anal, op, addr, buf_original);
|
||||
|
||||
ut8 buffer[XTENSA_MAX_LENGTH] = {0};
|
||||
int len = R_MIN(op->size, XTENSA_MAX_LENGTH);
|
||||
int len = R_MIN (op->size, XTENSA_MAX_LENGTH);
|
||||
memcpy (buffer, buf_original, len);
|
||||
|
||||
unsigned int i;
|
||||
|
@ -186,15 +186,35 @@ static void unix_word_rubout(void) {
|
||||
}
|
||||
|
||||
static int inithist(void) {
|
||||
if (I.history.data) {
|
||||
int new_size = I.hist_size;
|
||||
if (new_size > 0 && I.history.size != new_size) {
|
||||
char **new_data = (char **) calloc (new_size, sizeof (char *));
|
||||
if (new_data) {
|
||||
int nb_copy_lines = R_MIN (I.history.top + 1, new_size);
|
||||
memcpy (new_data, I.history.data + (I.history.top + 1 - nb_copy_lines), sizeof (char *) * nb_copy_lines);
|
||||
int i;
|
||||
for (i = 0; i < I.history.top + 1 - nb_copy_lines; i++) {
|
||||
free (I.history.data[i]);
|
||||
}
|
||||
free (I.history.data);
|
||||
I.history.data = new_data;
|
||||
I.history.size = new_size;
|
||||
I.history.top = R_MIN (I.history.top, nb_copy_lines - 1);
|
||||
I.history.index = R_MIN (I.history.index, nb_copy_lines - 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
ZERO_FILL (I.history);
|
||||
if ((I.history.size + 1024) * sizeof (char *) < I.history.size) {
|
||||
I.history.size = I.hist_size;
|
||||
if (I.history.size <= 0) {
|
||||
return false;
|
||||
}
|
||||
I.history.data = (char **) calloc ((I.history.size + 1024), sizeof (char *));
|
||||
I.history.data = (char **) calloc (I.history.size, sizeof (char *));
|
||||
if (!I.history.data) {
|
||||
return false;
|
||||
}
|
||||
I.history.size = R_LINE_HISTSIZE;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -362,8 +382,8 @@ R_API int r_line_hist_cmd_up(RLine *line) {
|
||||
if (line->hist_up) {
|
||||
return line->hist_up (line->user);
|
||||
}
|
||||
if (!line->history.data) {
|
||||
inithist ();
|
||||
if (!inithist ()) {
|
||||
return false;
|
||||
}
|
||||
if (line->history.index > 0 && line->history.data) {
|
||||
setup_hist_match (line);
|
||||
@ -466,11 +486,17 @@ static int r_line_hist_down(void) {
|
||||
return I.cb_history_down (&I);
|
||||
}
|
||||
|
||||
R_API void r_line_hist_set_size(int size) {
|
||||
I.hist_size = R_MIN (size, 65536);
|
||||
}
|
||||
|
||||
R_API int r_line_hist_get_size(void) {
|
||||
return I.history.size;
|
||||
}
|
||||
|
||||
R_API const char *r_line_hist_get(int n) {
|
||||
int i = 0;
|
||||
if (!I.history.data) {
|
||||
inithist ();
|
||||
}
|
||||
inithist ();
|
||||
n--;
|
||||
if (I.history.data) {
|
||||
for (i = 0; i < I.history.size && I.history.data[i]; i++) {
|
||||
@ -484,9 +510,7 @@ R_API const char *r_line_hist_get(int n) {
|
||||
|
||||
R_API int r_line_hist_list(void) {
|
||||
int i = 0;
|
||||
if (!I.history.data) {
|
||||
inithist ();
|
||||
}
|
||||
inithist ();
|
||||
if (I.history.data) {
|
||||
for (i = 0; i < I.history.size && I.history.data[i]; i++) {
|
||||
const char *pad = r_str_pad (' ', 32 - strlen (I.history.data[i]));
|
||||
|
@ -24,9 +24,6 @@ R_API RLine *r_line_new(void) {
|
||||
#else
|
||||
I.vtmode = 2;
|
||||
#endif
|
||||
if (!r_line_dietline_init ()) {
|
||||
R_LOG_ERROR ("r_line_dietline_init has failed");
|
||||
}
|
||||
r_line_completion_init (&I.completion, 4096);
|
||||
return &I;
|
||||
}
|
||||
@ -105,4 +102,4 @@ R_API void r_line_completion_clear(RLineCompletion *completion) {
|
||||
r_pvector_clear (&completion->args);
|
||||
}
|
||||
|
||||
#include "dietline.c"
|
||||
#include "dietline.c"
|
||||
|
@ -2610,6 +2610,12 @@ static bool cb_scr_histblock(void *user, void *data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_scr_histsize(void *user, void *data) {
|
||||
RConfigNode *node = (RConfigNode *) data;
|
||||
r_line_hist_set_size(node->i_value);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_scrprompt(void *user, void *data) {
|
||||
RCore *core = (RCore *)user;
|
||||
RConfigNode *node = (RConfigNode *) data;
|
||||
@ -4157,6 +4163,7 @@ R_API int r_core_config_init(RCore *core) {
|
||||
SETCB ("scr.hist.block", "true", &cb_scr_histblock, "use blocks for histogram");
|
||||
SETCB ("scr.hist.filter", "true", &cb_scr_histfilter, "filter history for matching lines when using up/down keys");
|
||||
SETBPREF ("scr.hist.save", "true", "always save history on exit");
|
||||
SETICB("scr.hist.size", R_LINE_HISTSIZE, &cb_scr_histsize, "set input lines history size");
|
||||
n = NODECB ("scr.strconv", "asciiesc", &cb_scrstrconv);
|
||||
SETDESC (n, "convert string before display");
|
||||
SETOPTIONS (n, "asciiesc", "asciidot", NULL);
|
||||
|
@ -3072,11 +3072,6 @@ R_API bool r_core_init(RCore *core) {
|
||||
core->cons->user_fgets = (void *)r_core_fgets;
|
||||
#endif
|
||||
//r_line_singleton ()->user = (void *)core;
|
||||
char *histpath = r_str_home (".cache/radare2/history");
|
||||
if (histpath) {
|
||||
r_line_hist_load (histpath);
|
||||
free (histpath);
|
||||
}
|
||||
}
|
||||
core->print->cons = core->cons;
|
||||
r_cons_bind (&core->print->consbind);
|
||||
|
@ -1097,7 +1097,8 @@ struct r_line_t {
|
||||
RLineHud *hud;
|
||||
RList *sdbshell_hist;
|
||||
RListIter *sdbshell_hist_iter;
|
||||
int vtmode;
|
||||
int vtmode; // R2_580 duplicated and unused from the global RCons.vtmode
|
||||
int hist_size;
|
||||
}; /* RLine */
|
||||
|
||||
#ifdef R_API
|
||||
@ -1121,6 +1122,8 @@ R_API bool r_line_hist_save(const char *file);
|
||||
R_API int r_line_hist_label(const char *label, void(*cb)(const char*));
|
||||
R_API void r_line_label_show(void);
|
||||
R_API int r_line_hist_list(void);
|
||||
R_API int r_line_hist_get_size(void);
|
||||
R_API void r_line_hist_set_size(int size);
|
||||
R_API const char *r_line_hist_get(int n);
|
||||
|
||||
R_API int r_line_set_hist_callback(RLine *line, RLineHistoryUpCb cb_up, RLineHistoryDownCb cb_down);
|
||||
|
@ -998,6 +998,12 @@ R_API int r_main_radare2(int argc, const char **argv) {
|
||||
r_config_set_b (r->config, "scr.utf8", false);
|
||||
}
|
||||
|
||||
char *histpath = r_str_home (".cache/radare2/history");
|
||||
if (histpath) {
|
||||
r_line_hist_load (histpath);
|
||||
free (histpath);
|
||||
}
|
||||
|
||||
if (r_config_get_b (r->config, "zign.autoload")) {
|
||||
autoload_zigns (r);
|
||||
}
|
||||
|
@ -72,10 +72,10 @@ R_API char *r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr)
|
||||
y += (input & 0x2) ? 1 : -1;
|
||||
|
||||
/* assure we are still in bounds */
|
||||
x = R_MAX(x, 0);
|
||||
y = R_MAX(y, 0);
|
||||
x = R_MIN(x, FLDSIZE_X - 1);
|
||||
y = R_MIN(y, FLDSIZE_Y - 1);
|
||||
x = R_MAX (x, 0);
|
||||
y = R_MAX (y, 0);
|
||||
x = R_MIN (x, FLDSIZE_X - 1);
|
||||
y = R_MIN (y, FLDSIZE_Y - 1);
|
||||
|
||||
/* augment the field */
|
||||
if (field[x][y] < len - 2) {
|
||||
|
@ -7,6 +7,7 @@ cd "$(dirname $0)"/..
|
||||
# find calls without (
|
||||
#(git grep -n -e '[a-z](' | grep -v static | grep -v _API | grep -v shlr | grep libr/core) && exit 1
|
||||
# validated and ready to go lintings
|
||||
(git grep -e 'R_MIN(' -e 'R_MAX(' libr | grep c:) && exit 1
|
||||
(git grep -n 'cmp(' libr | grep -v R_API | grep -v static | grep c:) && exit 1
|
||||
# (git grep -n 'len(' libr | grep -v R_API | grep -v static | grep c:) && exit 1
|
||||
# (git grep -n ',"' libr | grep -v R_API | grep -v static | grep c:) && exit 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user