New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Offset history #9591
Offset history #9591
Changes from 7 commits
23999ed
349da7e
cc68dc4
32f711c
511f834
0efed08
7380086
a6757c3
11c6840
3e98cda
b0c593c
03b12d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,6 +313,19 @@ static int r_line_hist_up() { | |
if (!I.history.data) { | ||
inithist (); | ||
} | ||
if (I.offset_prompt) { | ||
RCore *core = I.user; | ||
RIOUndo *undo = &core->io->undo; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rcons shouldnt have access to core or io |
||
char line[R_LINE_BUFSIZE - 1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont do 4096 in the stack. you only need 64bytes to do an snprintf of pfmt64x |
||
if (I.offset_index <= -undo->undos) { | ||
return false; | ||
} | ||
I.offset_index--; | ||
sprintf(line, "0x%"PFMT64x, undo->seek[undo->idx + I.offset_index]); | ||
strncpy(I.buffer.data, line, R_LINE_BUFSIZE - 1); | ||
I.buffer.index = I.buffer.length = strlen (I.buffer.data); | ||
return true; | ||
} | ||
if (I.history.index > 0) { | ||
strncpy (I.buffer.data, I.history.data[--I.history.index], R_LINE_BUFSIZE - 1); | ||
I.buffer.index = I.buffer.length = strlen (I.buffer.data); | ||
|
@@ -325,6 +338,24 @@ static int r_line_hist_down() { | |
if (I.hist_down) { | ||
return I.hist_down (I.user); | ||
} | ||
if (I.offset_prompt) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we use tabs. not spaces |
||
RCore *core = I.user; | ||
RIOUndo *undo = &core->io->undo; | ||
if (I.offset_index >= undo->redos) { | ||
return false; | ||
} | ||
I.offset_index++; | ||
if (I.offset_index == undo->redos) { | ||
I.buffer.data[0] = '\0'; | ||
I.buffer.index = I.buffer.length = 0; | ||
return false; | ||
} | ||
char line[R_LINE_BUFSIZE - 1]; | ||
sprintf(line, "0x%"PFMT64x, undo->seek[undo->idx + I.offset_index]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use snprintf or r_str_newf and avoid abusing the stack with this char line[R_LINE_BUFSIZE] because to fill a PFMT64x you dont need more than 64 bytes. not 4096 |
||
strncpy(I.buffer.data, line, R_LINE_BUFSIZE - 1); | ||
I.buffer.index = I.buffer.length = strlen (I.buffer.data); | ||
return true; | ||
} | ||
I.buffer.index = 0; | ||
if (!I.history.data) { | ||
inithist (); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -845,13 +845,16 @@ static void reset_print_cur(RPrint *p) { | |
static void visual_offset(RCore *core) { | ||
char buf[256]; | ||
r_line_set_prompt ("[offset]> "); | ||
core->cons->line->offset_prompt = true; | ||
core->cons->line->offset_index = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about doing: r_line_set_history_callback() and implement the logic of offset_prompt in here? |
||
strcpy (buf, "s "); | ||
if (r_cons_fgets (buf + 2, sizeof (buf) - 3, 0, NULL) > 0) { | ||
if (buf[2] == '.') { | ||
buf[1] = '.'; | ||
} | ||
r_core_cmd0 (core, buf); | ||
reset_print_cur (core->print); | ||
core->cons->line->offset_prompt = false; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use tabs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally the solution should be to delegate the logic of the history to the caller, not embed that in here