From a4a4ec30bb6d33b0db85fbe2e8bcbdbc14ffef5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Meg=C3=ADa=20L=C3=B3pez?= Date: Fri, 7 Sep 2018 11:03:06 +0200 Subject: [PATCH 1/3] Bug hangs pressing F3 next time with filenames longer than 136 chars 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 --- Changes | 9 +++++++++ display.c | 41 +++++++++++++++++++++++++++++++++-------- file.c | 14 +++++++++++++- hexedit.c | 1 - hexedit.h | 3 +-- 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Changes b/Changes index 5b31e09..fcb8731 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 + novembre 2016: - mark cursor position in both HEX and ASCII - skip whitespace when parsing hex-strings diff --git a/display.c b/display.c index 6e41481..2c32c8e 100644 --- a/display.c +++ b/display.c @@ -166,22 +166,29 @@ 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()); if (mode == bySector) printw("--sector %lld", (base + cursor) / SECTOR_SIZE); + printw(" %s", baseName); + move(cursor / lineLength, computeCursorXCurrentPos()); } @@ -214,6 +221,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(); } @@ -253,7 +262,7 @@ int displayMessageAndGetString(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(); @@ -266,11 +275,27 @@ int displayMessageAndGetString(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..9bf2456 100644 --- a/file.c +++ b/file.c @@ -89,7 +89,19 @@ 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 (RETURN loads %s): ", p); + int center = page / lineLength / 2; + int lines = strlen(msg) / COLS; + 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 4fa670f..43ace9f 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 e05c71e..c5bb6f5 100644 --- a/hexedit.h +++ b/hexedit.h @@ -27,7 +27,6 @@ #include /* for BLKGETSIZE */ #endif - #define INT off_t /*******************************************************************************/ @@ -157,7 +156,7 @@ void displayOneLineMessage(char *msg); void displayTwoLineMessage(char *msg1, char *msg2); void displayMessageAndWaitForKey(char *msg); int displayMessageAndGetString(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); From 4b9ec33148c00ead6675a5aebea19d9d66cd14f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Meg=C3=ADa=20L=C3=B3pez?= Date: Sat, 8 Sep 2018 07:48:19 +0200 Subject: [PATCH 2/3] Added conditions to add one blank line after message --- file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/file.c b/file.c index 9bf2456..3e9ecf8 100644 --- a/file.c +++ b/file.c @@ -94,7 +94,10 @@ int findFile(void) snprintf(msg, 4096, "File name (RETURN loads %s): ", p); int center = page / lineLength / 2; int lines = strlen(msg) / COLS; - if (strlen(msg) % COLS) lines++; + 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); } From 74d0331abd7f214f46e11b41335872e572676bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Meg=C3=ADa=20L=C3=B3pez?= Date: Tue, 16 Oct 2018 07:22:45 +0200 Subject: [PATCH 3/3] Updated to show filename between [] if is longer than 136 chars --- file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file.c b/file.c index 3e9ecf8..bc518a2 100644 --- a/file.c +++ b/file.c @@ -91,7 +91,7 @@ int findFile(void) p = lastFindFile ? strdup(lastFindFile) : NULL; if ((p != NULL) && (strlen(p) > 136)) { char msg[4097]; - snprintf(msg, 4096, "File name (RETURN loads %s): ", p); + 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++;