From 97cbbb0cc8670ebd2d5711a5f80f04db056a83b7 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 25 Jan 2018 11:00:19 +0100 Subject: [PATCH] prompt: show whitespace only in the filename, not in the whole line That is, call display_string() just on the filename, not on the rest of the prompt text. This fixes https://savannah.gnu.org/bugs/?52967. Reported-by: Andreas Schamanek --- src/files.c | 14 +++++++++++--- src/prompt.c | 5 +---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/files.c b/src/files.c index e295a02c..e6fe1fb6 100644 --- a/src/files.c +++ b/src/files.c @@ -345,6 +345,9 @@ int do_lockfile(const char *filename) pidstring = charalloc(11); sprintf (pidstring, "%u", (unsigned int)lockpid); + /* Display newlines in filenames as ^J. */ + as_an_at = FALSE; + /* TRANSLATORS: The second %s is the name of the user, the third that of the editor. */ question = _("File %s is being edited (by %s with %s, PID %s); continue?"); room = COLS - strlenpt(question) + 7 - strlenpt(lockuser) - @@ -359,7 +362,7 @@ int do_lockfile(const char *filename) strcat(postedname, fragment); free(fragment); } else - postedname = mallocstrcpy(NULL, filename); + postedname = display_string(filename, 0, room, FALSE); /* Allow extra space for username (14), program name (8), PID (8), * and terminating \0 (1), minus the %s (2) for the file name. */ @@ -2193,12 +2196,17 @@ int do_writeout(bool exiting, bool withprompt) if (name_exists) { char *question = _("File \"%s\" exists; OVERWRITE? "); + char *name = display_string(answer, 0, + COLS - strlenpt(question) + 1, FALSE); char *message = charalloc(strlen(question) + - strlen(answer) + 1); - sprintf(message, question, answer); + strlen(name) + 1); + + sprintf(message, question, name); i = do_yesno_prompt(FALSE, message); + free(message); + free(name); if (i < 1) continue; diff --git a/src/prompt.c b/src/prompt.c index 3001dfac..c6b97b42 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -669,7 +669,6 @@ int do_prompt(bool allow_tabs, bool allow_files, int do_yesno_prompt(bool all, const char *msg) { int response = -2, width = 16; - char *message = display_string(msg, 0, COLS, FALSE); /* TRANSLATORS: For the next three strings, if possible, specify * the single-byte letters for both your language and English. @@ -717,7 +716,7 @@ int do_yesno_prompt(bool all, const char *msg) /* Color the statusbar over its full width and display the question. */ wattron(bottomwin, interface_color_pair[TITLE_BAR]); blank_statusbar(); - mvwaddnstr(bottomwin, 0, 0, message, actual_x(message, COLS - 1)); + mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1)); wattroff(bottomwin, interface_color_pair[TITLE_BAR]); wnoutrefresh(bottomwin); @@ -755,7 +754,5 @@ int do_yesno_prompt(bool all, const char *msg) #endif /* ENABLE_MOUSE */ } - free(message); - return response; }