From 7676272b18a14d337beece7f0f875289da504910 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 9 May 2016 10:39:19 +0200 Subject: [PATCH] Add sj and s= commands --- libr/core/cmd_seek.c | 4 +++- libr/include/r_io.h | 2 +- libr/io/undo.c | 45 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/libr/core/cmd_seek.c b/libr/core/cmd_seek.c index 62307078aa..00d1cbe59a 100644 --- a/libr/core/cmd_seek.c +++ b/libr/core/cmd_seek.c @@ -287,7 +287,9 @@ static int cmd_seek(void *data, const char *input) { r_core_seek_base (core, input); break; case '*': - r_io_sundo_list (core->io); + case '=': + case 'j': + r_io_sundo_list (core->io, input[0]); break; case '+': if (input[1]!='\0') { diff --git a/libr/include/r_io.h b/libr/include/r_io.h index d2c5e03098..87e571ec49 100644 --- a/libr/include/r_io.h +++ b/libr/include/r_io.h @@ -427,7 +427,7 @@ R_API ut64 r_io_sundo(RIO *io, ut64 offset); R_API ut64 r_io_sundo_redo(RIO *io); R_API void r_io_sundo_push(RIO *io, ut64 off); R_API void r_io_sundo_reset(RIO *io); -R_API void r_io_sundo_list(RIO *io); +R_API void r_io_sundo_list(RIO *io, int mode); /* write undo */ R_API void r_io_wundo_new(RIO *io, ut64 off, const ut8 *data, int len); R_API void r_io_wundo_apply_all(RIO *io, int set); diff --git a/libr/io/undo.c b/libr/io/undo.c index 5a06ee80df..4b3dd6308d 100644 --- a/libr/io/undo.c +++ b/libr/io/undo.c @@ -87,7 +87,7 @@ R_API void r_io_sundo_reset(RIO *io) { io->undo.redos = 0; } -R_API void r_io_sundo_list(RIO *io) { +R_API void r_io_sundo_list(RIO *io, int mode) { int idx, undos, redos, i, j, start, end; if (!io->undo.s_enable) @@ -104,16 +104,45 @@ R_API void r_io_sundo_list(RIO *io) { end = (idx + redos + 1) % R_IO_UNDOS; j = 0; - for (i = start; i != end || j == 0; i = (i + 1) % R_IO_UNDOS) { - if (j < undos) { - io->cb_printf ("f undo_%d @ 0x%"PFMT64x"\n", undos - j - 1, io->undo.seek[i]); - } else if (j == undos && j != 0 && redos != 0) { - io->cb_printf ("# Current undo/redo position.\n"); - } else if (j != undos) { - io->cb_printf ("f redo_%d @ 0x%"PFMT64x"\n", j - undos - 1, io->undo.seek[i]); + switch (mode) { + case 'j': + io->cb_printf ("["); + break; + } + for (i = start; i < end || j == 0; i = (i + 1) % R_IO_UNDOS) { + int idx = (j< undos)? undos - j - 1: j - undos - 1; + ut64 addr = io->undo.seek[i]; + ut64 notLast = j+1cb_printf ("%"PFMT64d"%s", addr, notLast? ",": ""); + } + break; + case '*': + if (j < undos) { + io->cb_printf ("f undo_%d @ 0x%"PFMT64x"\n", idx, addr); + } else if (j == undos && j != 0 && redos != 0) { + io->cb_printf ("# Current undo/redo position.\n"); + } else if (j != undos) { + io->cb_printf ("f redo_%d @ 0x%"PFMT64x"\n", idx, addr); + } } j++; } + switch (mode) { + case '=': + io->cb_printf ("\n"); + break; + case 'j': + io->cb_printf ("]\n"); + break; + } } /* undo writez */