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.
This commit is contained in:
Benno Schulenberg 2019-10-20 14:25:22 +02:00
parent 1a8646393a
commit 95ae124891
5 changed files with 18 additions and 24 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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 */