diff --git a/Changes b/Changes index 49824ce..f4399f9 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,12 @@ +september 2018: + - Now writes before of filename, file position and file size at status line because if filename is long, + user cannot view file position and file size + - fix clean filename at end of line after load with F3 when filename reach end of line + - fix input long filename (longer than 136 chars) with F3 for next time. It repeats long filename until bottom screen and hangs. + Only works CTRL+C. I think that is a bug in ncurses. My work around is to print the long filename (if is longer than 136 chars), + but you can't edit it. You can load it pressing the RETURN key + - fix copy & paste bytes unchanged between bytes changed. Paste leave bytes unchanged to 00 + september 2017 - 1.4.2 - fix spelling errors in manpage diff --git a/display.c b/display.c index b3e7cca..d730cf9 100644 --- a/display.c +++ b/display.c @@ -191,23 +191,30 @@ void display(void) for (; i < page; i += lineLength) { int j; move(i / lineLength, 0); - for (j = 0; j < colsUsed; j++) printw(" "); /* cleanup the line */ + clrtoeol(); move(i / lineLength, 0); PRINTW(("%08lX", (int) (base + i))); } attrset(NORMAL); move(LINES - 1, 0); - for (i = 0; i < colsUsed; i++) printw("-"); + int szBuffer = 100; + char buffer[szBuffer]; + int len = snprintf(buffer, szBuffer, "%08llX", base + i) - 8; + for (i = 0; i < colsUsed + len; i++) printw("-"); + clrtoeol(); move(LINES - 1, 0); if (isReadOnly) i = '%'; else if (edited) i = '*'; else i = '-'; - printw("-%c%c %s --0x%llX", i, i, baseName, base + cursor); + printw("-%c%c --0x%llX", i, i, base + cursor); + if (MAX(fileSize, lastEditedLoc)) printw("/0x%llX", getfilesize()); printw("--%i%%", 100 * (base + cursor + getfilesize()/200) / getfilesize() ); if (mode == bySector) printw("--sector %lld", (base + cursor) / SECTOR_SIZE); + printw(" %s", baseName); + move(cursor / lineLength, computeCursorXCurrentPos()); } @@ -240,6 +247,8 @@ void displayLine(int offset, int max) else if (buffer[i] >= ' ' && buffer[i] < 127) ATTRPRINTW((cursor == i && hexOrAscii==1 ? mark_color : 0) | bufferAttr[i], ("%c", buffer[i])); else ATTRPRINTW((cursor == i && hexOrAscii == 1 ? mark_color : 0) | bufferAttr[i], (".")); } + PRINTW((" ")); + clrtoeol(); } void clr_line(int line) { move(line, 0); clrtoeol(); } @@ -279,7 +288,7 @@ int displayMessageAndGetString(const char *msg, char **last, char *p, int p_size int ret = TRUE; displayOneLineMessage(msg); - ungetstr(*last); + ungetstr(*last, p_size); echo(); getnstr(p, p_size - 1); noecho(); @@ -292,11 +301,27 @@ int displayMessageAndGetString(const char *msg, char **last, char *p, int p_size return ret; } -void ungetstr(char *s) +void ungetstr(char *s, size_t p_size) { - char *p; - if (s) - for (p = s + strlen(s) - 1; p >= s; p--) ungetch(*p); + wchar_t ws[p_size]; + wchar_t *w; + bool nonASCII = false; + + if (s) { + swprintf(ws, p_size, L"%hs", s); + int i; + for (i=0; i 127) nonASCII = true; + } + if ((wcslen(ws) < 137) && (!nonASCII)) { + for (w = ws + wcslen(ws) - 1; w >= ws; w--) { + if (unget_wch(*w) != OK) { + printf("unget_wch ERROR!"); + break; + } + } + } + } } int get_number(INT *i) diff --git a/file.c b/file.c index b14fa4f..bc518a2 100644 --- a/file.c +++ b/file.c @@ -89,7 +89,22 @@ int findFile(void) { char *p, tmp[BLOCK_SEARCH_SIZE]; p = lastFindFile ? strdup(lastFindFile) : NULL; - if (!displayMessageAndGetString("File name: ", &p, tmp, sizeof(tmp))) return FALSE; + if ((p != NULL) && (strlen(p) > 136)) { + char msg[4097]; + snprintf(msg, 4096, "File name [%s]: ", p); + int center = page / lineLength / 2; + int lines = strlen(msg) / COLS; + if ((strlen(msg) > COLS) && (strlen(msg) % COLS)) lines++; + if ((strlen(msg) % COLS) > (int)(COLS * 0.8)) lines++; + if ((strlen(msg) % COLS) > (int)(COLS * 0.8) && (strlen(msg) < COLS)) lines++; + if (strlen(msg) == COLS) lines++; + for (int i = 2; i < lines + 1; i++) { + clr_line(center + i); + } + if (!displayMessageAndGetString(msg, &p, tmp, sizeof(tmp))) return FALSE; + } else { + if (!displayMessageAndGetString("File name: ", &p, tmp, sizeof(tmp))) return FALSE; + } if (!is_file(tmp)) return FALSE; FREE(lastFindFile); lastFindFile = fileName; fileName = p; diff --git a/hexedit.c b/hexedit.c index 0f634e7..137929a 100644 --- a/hexedit.c +++ b/hexedit.c @@ -16,7 +16,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/ #include "hexedit.h" - /*******************************************************************************/ /* Global variables */ /*******************************************************************************/ diff --git a/hexedit.h b/hexedit.h index fc57aa9..e3b1ea9 100644 --- a/hexedit.h +++ b/hexedit.h @@ -27,7 +27,6 @@ #include /* for BLKGETSIZE */ #endif - #define INT off_t /*******************************************************************************/ @@ -158,7 +157,7 @@ void displayOneLineMessage(const char *msg); void displayTwoLineMessage(const char *msg1, const char *msg2); void displayMessageAndWaitForKey(const char *msg); int displayMessageAndGetString(const char *msg, char **last, char *p, int p_size); -void ungetstr(char *s); +void ungetstr(char *s, size_t p_size); int get_number(INT *i); diff --git a/interact.c b/interact.c index e51c9f9..9cdc58a 100644 --- a/interact.c +++ b/interact.c @@ -262,7 +262,7 @@ static void goto_char(void) INT i; displayOneLineMessage("New position ? "); - ungetstr("0x"); + ungetstr("0x", BLOCK_SEARCH_SIZE); if (!get_number(&i) || !set_cursor(i)) displayMessageAndWaitForKey("Invalid position!"); }