From 95ae124891a1ca34ee2f81753777733f96fddde1 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 20 Oct 2019 14:25:22 +0200 Subject: [PATCH] history: don't wait when there is something wrong with the history files Do not wait for the user to press a key when there is some problem with any of the history files. Just start and indicate the problem on the status bar. The precise error message is stored and will be shown on the terminal when exiting from nano. This addresses https://savannah.gnu.org/bugs/?56524. --- src/global.c | 4 ++-- src/history.c | 21 ++++----------------- src/nano.c | 4 ++-- src/proto.h | 3 ++- src/rcfile.c | 10 ++++++++-- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/global.c b/src/global.c index 6be49627..9755f76a 100644 --- a/src/global.c +++ b/src/global.c @@ -261,8 +261,8 @@ int menusymbols[NUMBER_OF_MENUS] = { MMAIN, MWHEREIS, MREPLACE, MREPLACEWITH, MBROWSER, MWHEREISFILE, MGOTODIR, MMOST|MHELP|MYESNO }; -char *rcfile_with_errors = NULL; - /* The first nanorc file, if any, that produced warnings. */ +char *startup_problem = NULL; + /* An error message (if any) about nanorc files or history files. */ #endif bool spotlighted = FALSE; diff --git a/src/history.c b/src/history.c index ac936b45..d18f5c61 100644 --- a/src/history.c +++ b/src/history.c @@ -229,19 +229,6 @@ char *get_history_completion(linestruct **h, char *s, size_t len) } #endif /* ENABLE_TABCOMP */ -void history_error(const char *msg, ...) -{ - va_list ap; - - va_start(ap, msg); - vfprintf(stderr, _(msg), ap); - va_end(ap); - - fprintf(stderr, _("\nPress Enter to continue\n")); - while (getchar() != '\n') - ; -} - /* Check whether we have or could make a directory for history files. */ bool have_statedir(void) { @@ -280,14 +267,14 @@ bool have_statedir(void) free(statepath); } if (mkdir(statedir, S_IRWXU) == -1) { - history_error(N_("Unable to create directory %s: %s\n" + jot_error(N_("Unable to create directory %s: %s\n" "It is required for saving/loading " "search history or cursor positions.\n"), statedir, strerror(errno)); return FALSE; } } else if (!S_ISDIR(dirstat.st_mode)) { - history_error(N_("Path %s is not a directory and needs to be.\n" + jot_error(N_("Path %s is not a directory and needs to be.\n" "Nano will be unable to load or save " "search history or cursor positions.\n"), statedir); @@ -308,7 +295,7 @@ void load_history(void) if (errno != ENOENT) { /* When reading failed, don't save history when we quit. */ UNSET(HISTORYLOG); - history_error(N_("Error reading %s: %s"), histname, + jot_error(N_("Error reading %s: %s"), histname, strerror(errno)); } } else { @@ -404,7 +391,7 @@ void load_poshistory(void) if (errno != ENOENT) { /* When reading failed, don't save history when we quit. */ UNSET(POSITIONLOG); - history_error(N_("Error reading %s: %s"), poshistname, strerror(errno)); + jot_error(N_("Error reading %s: %s"), poshistname, strerror(errno)); } } else { char *line = NULL, *lineptr, *xptr; diff --git a/src/nano.c b/src/nano.c index 57f0e677..a12b49cd 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2685,8 +2685,8 @@ int main(int argc, char **argv) prepare_for_display(); #ifdef ENABLE_NANORC - if (rcfile_with_errors != NULL) - statusline(ALERT, _("Mistakes in '%s'"), rcfile_with_errors); + if (startup_problem != NULL) + statusline(ALERT, startup_problem); #endif #ifdef ENABLE_HELP diff --git a/src/proto.h b/src/proto.h index f7b6b098..0028e498 100644 --- a/src/proto.h +++ b/src/proto.h @@ -174,7 +174,7 @@ extern int interface_color_pair[NUMBER_OF_ELEMENTS]; extern char *homedir; extern char *statedir; #ifdef ENABLE_NANORC -extern char *rcfile_with_errors; +extern char *startup_problem; #endif extern bool spotlighted; @@ -471,6 +471,7 @@ int do_yesno_prompt(bool all, const char *msg); /* Most functions in rcfile.c. */ #ifdef ENABLE_NANORC void display_rcfile_errors(void); +void jot_error(const char *msg, ...); #ifdef ENABLE_COLOR void parse_one_include(char *file, syntaxtype *syntax); void grab_and_store(const char *kind, char *ptr, regexlisttype **storage); diff --git a/src/rcfile.c b/src/rcfile.c index 0ab73ad1..581b7f38 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -174,8 +174,13 @@ void jot_error(const char *msg, ...) errors_tail->next = error; errors_tail = error; - if (rcfile_with_errors == NULL) - rcfile_with_errors = copy_of(nanorc); + if (startup_problem == NULL) { + if (nanorc != NULL) { + snprintf(textbuf, MAXSIZE, _("Mistakes in '%s'"), nanorc); + startup_problem = copy_of(textbuf); + } else + startup_problem = copy_of(_("Problems with history file")); + } if (lineno > 0) length = snprintf(textbuf, MAXSIZE, _("Error in %s on line %zu: "), @@ -1358,6 +1363,7 @@ void do_rcfiles(void) check_vitals_mapped(); free(nanorc); + nanorc = NULL; } #endif /* ENABLE_NANORC */