diff options
author | Chris Davis <cd.rattan@gmail.com> | 2014-08-09 17:11:00 -0700 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-10-01 14:32:10 +0200 |
commit | b96c43219480c442d0264834101e5bee675e3b04 (patch) | |
tree | 239f65cb5fcf422ef928d91c60f43cb819cf6565 | |
parent | 3c6541c44e2bfca2d1dfb7a971064d2c7143106f (diff) | |
download | samba-b96c43219480c442d0264834101e5bee675e3b04.tar.gz samba-b96c43219480c442d0264834101e5bee675e3b04.tar.xz samba-b96c43219480c442d0264834101e5bee675e3b04.zip |
regedit: handle del and backspace in hexeditor
Signed-off-by: Chris Davis <cd.rattan@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
-rw-r--r-- | source3/utils/regedit_dialog.c | 6 | ||||
-rw-r--r-- | source3/utils/regedit_hexedit.c | 72 | ||||
-rw-r--r-- | source3/utils/regedit_hexedit.h | 4 |
3 files changed, 71 insertions, 11 deletions
diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c index 3dc18dd5ec..d0b486feef 100644 --- a/source3/utils/regedit_dialog.c +++ b/source3/utils/regedit_dialog.c @@ -1093,7 +1093,11 @@ static void hexedit_on_input(struct dialog *dia, switch (c) { case KEY_BACKSPACE: - // FIXME hexedit_driver(hexedit->buf, c); + hexedit_driver(hexedit->buf, HE_BACKSPACE); + break; + case '\x7f': + case KEY_DC: + hexedit_driver(hexedit->buf, HE_DELETE); break; default: hexedit_driver(hexedit->buf, c); diff --git a/source3/utils/regedit_hexedit.c b/source3/utils/regedit_hexedit.c index 8a7c8a1659..377eef97ad 100644 --- a/source3/utils/regedit_hexedit.c +++ b/source3/utils/regedit_hexedit.c @@ -125,11 +125,12 @@ void hexedit_set_cursor(struct hexedit *buf) wmove(buf->win, max_rows(buf->win), 0); wattron(buf->win, A_REVERSE | A_STANDOUT); wclrtoeol(buf->win); - if (buf->len) { + if (buf->cursor_offset < buf->len) { wprintw(buf->win, "Len:%lu Off:%lu Val:0x%X", buf->len, buf->cursor_offset, buf->data[buf->cursor_offset]); } else { - wprintw(buf->win, "Len:%lu (empty)", buf->len); + wprintw(buf->win, "Len:%lu Off:%lu", buf->len, + buf->cursor_offset); } wattroff(buf->win, A_REVERSE | A_STANDOUT); wmove(buf->win, buf->cursor_y, buf->cursor_x); @@ -341,9 +342,6 @@ static void cursor_right(struct hexedit *buf) { int new_x = buf->cursor_x + 1; - if (buf->len == 0) { - return; - } if (new_x == ASCII_COL_END) { return; } @@ -385,10 +383,6 @@ static void do_edit(struct hexedit *buf, int c) { uint8_t *byte; - if (buf->len == 0) { - return; - } - if (buf->cursor_offset == buf->len) { hexedit_resize_buffer(buf, buf->len + 1); } @@ -445,6 +439,60 @@ static void do_edit(struct hexedit *buf, int c) hexedit_refresh(buf); } +static void erase_at(struct hexedit *buf, size_t pos) +{ + if (pos >= buf->len) { + return; + } + + if (pos < buf->len - 1) { + /* squeeze the character out of the buffer */ + uint8_t *p = buf->data + pos; + uint8_t *end = buf->data + buf->len; + memmove(p, p + 1, end - p - 1); + } + + buf->len--; + hexedit_refresh(buf); +} + +static void do_backspace(struct hexedit *buf) +{ + size_t off; + bool erase = true; + + if (buf->cursor_offset == 0) { + return; + } + + off = buf->cursor_offset; + if (buf->cursor_x == ASCII_COL) { + cursor_up(buf); + buf->cursor_line_offset = 7; + buf->cursor_x = ASCII_COL_END - 1; + calc_cursor_offset(buf); + } else if (buf->cursor_x == HEX_COL1) { + cursor_up(buf); + buf->cursor_line_offset = 7; + buf->cursor_x = HEX_COL2_END - 1; + buf->nibble = 1; + calc_cursor_offset(buf); + } else { + if (buf->cursor_x < ASCII_COL && buf->nibble) { + erase = false; + } + cursor_left(buf); + } + if (erase) { + erase_at(buf, off - 1); + } +} + +static void do_delete(struct hexedit *buf) +{ + erase_at(buf, buf->cursor_offset); +} + void hexedit_driver(struct hexedit *buf, int c) { switch (c) { @@ -464,6 +512,12 @@ void hexedit_driver(struct hexedit *buf, int c) break; case HE_CURSOR_PGDN: break; + case HE_BACKSPACE: + do_backspace(buf); + break; + case HE_DELETE: + do_delete(buf); + break; default: do_edit(buf, c & 0xff); break; diff --git a/source3/utils/regedit_hexedit.h b/source3/utils/regedit_hexedit.h index dc13c21194..dfbe27a5d8 100644 --- a/source3/utils/regedit_hexedit.h +++ b/source3/utils/regedit_hexedit.h @@ -28,7 +28,9 @@ enum { HE_CURSOR_LEFT = 0x1200, HE_CURSOR_RIGHT = 0x1300, HE_CURSOR_PGUP = 0x1400, - HE_CURSOR_PGDN = 0x1500 + HE_CURSOR_PGDN = 0x1500, + HE_BACKSPACE = 0x1600, + HE_DELETE = 0x1700, }; #define LINE_WIDTH 44 |