* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config HEXEDIT
-//config: bool "hexedit"
+//config: bool "hexedit (21 kb)"
//config: default y
//config: help
//config: Edit file in hexadecimal.
i++;
}
- printf(ESC"[%u;%uH", 1 + cursor / 16, 1 + pos + (cursor & 0xf) * 3);
+ G.row = cursor / 16;
+ printf(ESC"[%u;%uH", 1 + G.row, 1 + pos + (cursor & 0xf) * 3);
}
static void redraw_cur_line(void)
);
if (G.baseaddr == MAP_FAILED) {
restore_term();
- bb_perror_msg_and_die("mmap");
+ bb_simple_perror_msg_and_die("mmap");
}
G.current_byte = G.baseaddr + cur_pos;
if (G.current_byte > G.eof_byte) {
/* _after_ eof - don't allow this */
G.current_byte -= 16;
+ if (G.current_byte < G.baseaddr)
+ move_mapping_lower();
break;
}
}
printf(ESC"[999;1H" CLEAR_TILL_EOL); /* go to last line */
if (read_line_input(NULL, "Go to (dec,0Xhex,0oct): ", buf, sizeof(buf)) > 0) {
off_t t;
- unsigned pgmask;
+ unsigned cursor;
t = bb_strtoull(buf, NULL, 0);
if (t >= G.size)
t = G.size - 1;
- pgmask = G_pagesize - 1;
- cnt = t & pgmask;
- t = t & ~(off_t)pgmask;
+ cursor = t & (G_pagesize - 1);
+ t -= cursor;
if (t < 0)
- cnt = t = 0;
- if (t != 0 && cnt < 0x1ff) {
+ cursor = t = 0;
+ if (t != 0 && cursor < 0x1ff) {
/* very close to end of page, possibly to EOF */
/* move one page lower */
t -= G_pagesize;
- cnt += G_pagesize;
+ cursor += G_pagesize;
}
G.offset = t;
- remap(cnt);
- redraw(cnt);
+ remap(cursor);
+ redraw(cursor);
break;
}
- /* EOF/error on input: fall through to exiting */
+ /* ^C/EOF/error: fall through to exiting */
}
case CTRL('X'):
restore_term();