rcfile tweaks: prompt only once for all rcfile errors instead of once

for each separate error, make sure all the messages end in newlines,
etc.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1876 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-07-30 22:52:44 +00:00
parent 906257932f
commit a6d26d04fd
4 changed files with 40 additions and 30 deletions

View File

@ -60,6 +60,11 @@ CVS code -
New functions begpar() and inpar(); changes to quote_length(), New functions begpar() and inpar(); changes to quote_length(),
quotes_match(), do_para_search(), do_para_begin(), quotes_match(), do_para_search(), do_para_begin(),
do_para_end(), and do_justify(). (David Benbennick) do_para_end(), and do_justify(). (David Benbennick)
- Readded the errors flag and moved the ending prompt from
rcfile_error() to parse_rcfile() so that we only get prompted
once for all errors instead of separately for each error.
Also make sure that each rcfile error message ends in a
newline. (DLR)
- files.c: - files.c:
close_open_file() close_open_file()
- Tweak to no longer rely on the return values of - Tweak to no longer rely on the return values of

View File

@ -2955,7 +2955,7 @@ void load_history(void)
if (errno != ENOENT) { if (errno != ENOENT) {
/* Don't save history when we quit. */ /* Don't save history when we quit. */
UNSET(HISTORYLOG); UNSET(HISTORYLOG);
rcfile_error(N_("Unable to open ~/.nano_history file: %s"), strerror(errno)); rcfile_error(N_("Unable to open ~/.nano_history file: %s\n"), strerror(errno));
} }
free(nanohist); free(nanohist);
} else { } else {
@ -3005,7 +3005,7 @@ void save_history(void)
if (homenv != NULL || userage != NULL) { if (homenv != NULL || userage != NULL) {
hist = fopen(nanohist, "wb"); hist = fopen(nanohist, "wb");
if (hist == NULL) if (hist == NULL)
rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno)); rcfile_error(N_("Unable to write ~/.nano_history file: %s\n"), strerror(errno));
else { else {
/* set rw only by owner for security ?? */ /* set rw only by owner for security ?? */
chmod(nanohist, S_IRUSR | S_IWUSR); chmod(nanohist, S_IRUSR | S_IWUSR);
@ -3014,19 +3014,19 @@ void save_history(void)
h->data = charealloc(h->data, strlen(h->data) + 2); h->data = charealloc(h->data, strlen(h->data) + 2);
strcat(h->data, "\n"); strcat(h->data, "\n");
if (fputs(h->data, hist) == EOF) { if (fputs(h->data, hist) == EOF) {
rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno)); rcfile_error(N_("Unable to write ~/.nano_history file: %s\n"), strerror(errno));
goto come_from; goto come_from;
} }
} }
if (fputs("\n", hist) == EOF) { if (fputs("\n", hist) == EOF) {
rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno)); rcfile_error(N_("Unable to write ~/.nano_history file: %s\n"), strerror(errno));
goto come_from; goto come_from;
} }
for (h = replace_history.tail; h->prev; h = h->prev) { for (h = replace_history.tail; h->prev; h = h->prev) {
h->data = charealloc(h->data, strlen(h->data) + 2); h->data = charealloc(h->data, strlen(h->data) + 2);
strcat(h->data, "\n"); strcat(h->data, "\n");
if (fputs(h->data, hist) == EOF) { if (fputs(h->data, hist) == EOF) {
rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno)); rcfile_error(N_("Unable to write ~/.nano_history file: %s\n"), strerror(errno));
goto come_from; goto come_from;
} }
} }

View File

@ -3154,8 +3154,7 @@ int main(int argc, char *argv[])
#endif #endif
case 'T': case 'T':
if (parse_num(optarg, &tabsize) == -1 || tabsize <= 0) { if (parse_num(optarg, &tabsize) == -1 || tabsize <= 0) {
fprintf(stderr, _("Requested tab size %s invalid"), optarg); fprintf(stderr, _("Requested tab size %s invalid\n"), optarg);
fprintf(stderr, "\n");
exit(1); exit(1);
} }
break; break;
@ -3203,8 +3202,7 @@ int main(int argc, char *argv[])
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
case 'r': case 'r':
if (parse_num(optarg, &wrap_at) == -1) { if (parse_num(optarg, &wrap_at) == -1) {
fprintf(stderr, _("Requested fill size %s invalid"), optarg); fprintf(stderr, _("Requested fill size %s invalid\n"), optarg);
fprintf(stderr, "\n");
exit(1); exit(1);
} }
fill_flag_used = TRUE; fill_flag_used = TRUE;

View File

@ -99,6 +99,7 @@ const static rcoption rcopts[] = {
{NULL, 0} {NULL, 0}
}; };
static bool errors = FALSE;
static int lineno = 0; static int lineno = 0;
static char *nanorc; static char *nanorc;
@ -109,16 +110,14 @@ void rcfile_error(const char *msg, ...)
va_list ap; va_list ap;
fprintf(stderr, "\n"); fprintf(stderr, "\n");
if (lineno > 0) if (lineno > 0) {
errors = TRUE;
fprintf(stderr, _("Error in %s on line %d: "), nanorc, lineno); fprintf(stderr, _("Error in %s on line %d: "), nanorc, lineno);
}
va_start(ap, msg); va_start(ap, msg);
vfprintf(stderr, _(msg), ap); vfprintf(stderr, _(msg), ap);
va_end(ap); va_end(ap);
fprintf(stderr, _("\nPress Return to continue\n"));
while (getchar() != '\n')
;
} }
/* Parse the next word from the string. Returns NULL if we hit EOL. */ /* Parse the next word from the string. Returns NULL if we hit EOL. */
@ -167,7 +166,7 @@ char *parse_argument(char *ptr)
ptr = NULL; ptr = NULL;
else else
*ptr++ = '\0'; *ptr++ = '\0';
rcfile_error(N_("Argument %s has unterminated \""), ptr_bak); rcfile_error(N_("Argument %s has unterminated \"\n"), ptr_bak);
} else { } else {
*last_quote = '\0'; *last_quote = '\0';
ptr = last_quote + 1; ptr = last_quote + 1;
@ -248,7 +247,7 @@ int nregcomp(regex_t *preg, const char *regex, int eflags)
char *str = charalloc(len); char *str = charalloc(len);
regerror(rc, preg, str, len); regerror(rc, preg, str, len);
rcfile_error(N_("Bad regex \"%s\": %s"), regex, str); rcfile_error(N_("Bad regex \"%s\": %s\n"), regex, str);
free(str); free(str);
} }
return rc != 0; return rc != 0;
@ -277,7 +276,7 @@ void parse_syntax(char *ptr)
ptr = parse_next_regex(ptr); ptr = parse_next_regex(ptr);
if (ptr == NULL) { if (ptr == NULL) {
rcfile_error(N_("Missing syntax name")); rcfile_error(N_("Missing syntax name\n"));
return; return;
} }
@ -346,7 +345,7 @@ void parse_colors(char *ptr)
ptr = parse_next_word(ptr); ptr = parse_next_word(ptr);
if (ptr == NULL) { if (ptr == NULL) {
rcfile_error(N_("Missing color name")); rcfile_error(N_("Missing color name\n"));
return; return;
} }
@ -355,7 +354,7 @@ void parse_colors(char *ptr)
strtok(fgstr, ","); strtok(fgstr, ",");
bgcolorname = strtok(NULL, ","); bgcolorname = strtok(NULL, ",");
if (!strncasecmp(bgcolorname, "bright", 6)) { if (!strncasecmp(bgcolorname, "bright", 6)) {
rcfile_error(N_("Background color %s cannot be bright"), bgcolorname); rcfile_error(N_("Background color %s cannot be bright\n"), bgcolorname);
return; return;
} }
bg = colortoint(bgcolorname, &bright); bg = colortoint(bgcolorname, &bright);
@ -369,7 +368,7 @@ void parse_colors(char *ptr)
return; return;
if (syntaxes == NULL) { if (syntaxes == NULL) {
rcfile_error(N_("Cannot add a color directive without a syntax line")); rcfile_error(N_("Cannot add a color directive without a syntax line\n"));
return; return;
} }
@ -435,7 +434,7 @@ void parse_colors(char *ptr)
if (expectend) { if (expectend) {
if (ptr == NULL || strncasecmp(ptr, "end=", 4)) { if (ptr == NULL || strncasecmp(ptr, "end=", 4)) {
rcfile_error(N_("\"start=\" requires a corresponding \"end=\"")); rcfile_error(N_("\"start=\" requires a corresponding \"end=\"\n"));
return; return;
} }
@ -506,7 +505,7 @@ void parse_rcfile(FILE *rcstream)
parse_colors(ptr); parse_colors(ptr);
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
else { else {
rcfile_error(N_("Command %s not understood"), keyword); rcfile_error(N_("Command %s not understood\n"), keyword);
continue; continue;
} }
@ -545,7 +544,7 @@ void parse_rcfile(FILE *rcstream)
#endif #endif
) { ) {
if (*ptr == '\n' || *ptr == '\0') { if (*ptr == '\n' || *ptr == '\0') {
rcfile_error(N_("Option %s requires an argument"), rcopts[i].name); rcfile_error(N_("Option %s requires an argument\n"), rcopts[i].name);
continue; continue;
} }
option = ptr; option = ptr;
@ -563,7 +562,7 @@ void parse_rcfile(FILE *rcstream)
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
if (!strcasecmp(rcopts[i].name, "fill")) { if (!strcasecmp(rcopts[i].name, "fill")) {
if (parse_num(option, &wrap_at) == -1) { if (parse_num(option, &wrap_at) == -1) {
rcfile_error(N_("Requested fill size %s invalid"), option); rcfile_error(N_("Requested fill size %s invalid\n"), option);
wrap_at = -CHARS_FROM_EOL; wrap_at = -CHARS_FROM_EOL;
} }
} else } else
@ -574,7 +573,7 @@ void parse_rcfile(FILE *rcstream)
whitespace = mallocstrcpy(NULL, option); whitespace = mallocstrcpy(NULL, option);
ws_len = strlen(whitespace); ws_len = strlen(whitespace);
if (ws_len != 2 || (ws_len == 2 && (is_cntrl_char(whitespace[0]) || is_cntrl_char(whitespace[1])))) { if (ws_len != 2 || (ws_len == 2 && (is_cntrl_char(whitespace[0]) || is_cntrl_char(whitespace[1])))) {
rcfile_error(N_("Two non-control characters required")); rcfile_error(N_("Two non-control characters required\n"));
free(whitespace); free(whitespace);
whitespace = NULL; whitespace = NULL;
} }
@ -584,14 +583,14 @@ void parse_rcfile(FILE *rcstream)
if (!strcasecmp(rcopts[i].name, "punct")) { if (!strcasecmp(rcopts[i].name, "punct")) {
punct = mallocstrcpy(NULL, option); punct = mallocstrcpy(NULL, option);
if (strchr(punct, '\t') != NULL || strchr(punct, ' ') != NULL) { if (strchr(punct, '\t') != NULL || strchr(punct, ' ') != NULL) {
rcfile_error(N_("Non-tab and non-space characters required")); rcfile_error(N_("Non-tab and non-space characters required\n"));
free(punct); free(punct);
punct = NULL; punct = NULL;
} }
} else if (!strcasecmp(rcopts[i].name, "brackets")) { } else if (!strcasecmp(rcopts[i].name, "brackets")) {
brackets = mallocstrcpy(NULL, option); brackets = mallocstrcpy(NULL, option);
if (strchr(brackets, '\t') != NULL || strchr(brackets, ' ') != NULL) { if (strchr(brackets, '\t') != NULL || strchr(brackets, ' ') != NULL) {
rcfile_error(N_("Non-tab and non-space characters required")); rcfile_error(N_("Non-tab and non-space characters required\n"));
free(brackets); free(brackets);
brackets = NULL; brackets = NULL;
} }
@ -611,7 +610,7 @@ void parse_rcfile(FILE *rcstream)
#endif #endif
if (!strcasecmp(rcopts[i].name, "tabsize")) { if (!strcasecmp(rcopts[i].name, "tabsize")) {
if (parse_num(option, &tabsize) == -1 || tabsize <= 0) if (parse_num(option, &tabsize) == -1 || tabsize <= 0)
rcfile_error(N_("Requested tab size %s invalid"), option); rcfile_error(N_("Requested tab size %s invalid\n"), option);
tabsize = -1; tabsize = -1;
} }
} else } else
@ -632,6 +631,14 @@ void parse_rcfile(FILE *rcstream)
} }
} }
free(buf); free(buf);
if (errors) {
errors = FALSE;
fprintf(stderr, _("\nPress Return to continue starting nano\n"));
while (getchar() != '\n')
;
}
return; return;
} }
@ -666,7 +673,7 @@ void do_rcfile(void)
endpwent(); endpwent();
if (userage == NULL) { if (userage == NULL) {
rcfile_error(N_("I can't find my home directory! Wah!")); rcfile_error(N_("I can't find my home directory! Wah!\n"));
SET(NO_RCFILE); SET(NO_RCFILE);
} else { } else {
nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9); nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9);
@ -686,7 +693,7 @@ void do_rcfile(void)
if ((rcstream = fopen(nanorc, "r")) == NULL) { if ((rcstream = fopen(nanorc, "r")) == NULL) {
/* Don't complain about the file not existing */ /* Don't complain about the file not existing */
if (errno != ENOENT) { if (errno != ENOENT) {
rcfile_error(N_("Unable to open ~/.nanorc file: %s"), strerror(errno)); rcfile_error(N_("Unable to open ~/.nanorc file: %s\n"), strerror(errno));
SET(NO_RCFILE); SET(NO_RCFILE);
} }
} else { } else {