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
This commit is contained in:
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(),
quotes_match(), do_para_search(), do_para_begin(),
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:
close_open_file()
- Tweak to no longer rely on the return values of

View File

@ -2955,7 +2955,7 @@ void load_history(void)
if (errno != ENOENT) {
/* Don't save history when we quit. */
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);
} else {
@ -3005,7 +3005,7 @@ void save_history(void)
if (homenv != NULL || userage != NULL) {
hist = fopen(nanohist, "wb");
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 {
/* set rw only by owner for security ?? */
chmod(nanohist, S_IRUSR | S_IWUSR);
@ -3014,19 +3014,19 @@ void save_history(void)
h->data = charealloc(h->data, strlen(h->data) + 2);
strcat(h->data, "\n");
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;
}
}
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;
}
for (h = replace_history.tail; h->prev; h = h->prev) {
h->data = charealloc(h->data, strlen(h->data) + 2);
strcat(h->data, "\n");
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;
}
}

View File

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

View File

@ -99,6 +99,7 @@ const static rcoption rcopts[] = {
{NULL, 0}
};
static bool errors = FALSE;
static int lineno = 0;
static char *nanorc;
@ -109,16 +110,14 @@ void rcfile_error(const char *msg, ...)
va_list ap;
fprintf(stderr, "\n");
if (lineno > 0)
if (lineno > 0) {
errors = TRUE;
fprintf(stderr, _("Error in %s on line %d: "), nanorc, lineno);
}
va_start(ap, msg);
vfprintf(stderr, _(msg), 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. */
@ -167,7 +166,7 @@ char *parse_argument(char *ptr)
ptr = NULL;
else
*ptr++ = '\0';
rcfile_error(N_("Argument %s has unterminated \""), ptr_bak);
rcfile_error(N_("Argument %s has unterminated \"\n"), ptr_bak);
} else {
*last_quote = '\0';
ptr = last_quote + 1;
@ -248,7 +247,7 @@ int nregcomp(regex_t *preg, const char *regex, int eflags)
char *str = charalloc(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);
}
return rc != 0;
@ -277,7 +276,7 @@ void parse_syntax(char *ptr)
ptr = parse_next_regex(ptr);
if (ptr == NULL) {
rcfile_error(N_("Missing syntax name"));
rcfile_error(N_("Missing syntax name\n"));
return;
}
@ -346,7 +345,7 @@ void parse_colors(char *ptr)
ptr = parse_next_word(ptr);
if (ptr == NULL) {
rcfile_error(N_("Missing color name"));
rcfile_error(N_("Missing color name\n"));
return;
}
@ -355,7 +354,7 @@ void parse_colors(char *ptr)
strtok(fgstr, ",");
bgcolorname = strtok(NULL, ",");
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;
}
bg = colortoint(bgcolorname, &bright);
@ -369,7 +368,7 @@ void parse_colors(char *ptr)
return;
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;
}
@ -435,7 +434,7 @@ void parse_colors(char *ptr)
if (expectend) {
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;
}
@ -506,7 +505,7 @@ void parse_rcfile(FILE *rcstream)
parse_colors(ptr);
#endif /* ENABLE_COLOR */
else {
rcfile_error(N_("Command %s not understood"), keyword);
rcfile_error(N_("Command %s not understood\n"), keyword);
continue;
}
@ -545,7 +544,7 @@ void parse_rcfile(FILE *rcstream)
#endif
) {
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;
}
option = ptr;
@ -563,7 +562,7 @@ void parse_rcfile(FILE *rcstream)
#ifndef DISABLE_WRAPJUSTIFY
if (!strcasecmp(rcopts[i].name, "fill")) {
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;
}
} else
@ -574,7 +573,7 @@ void parse_rcfile(FILE *rcstream)
whitespace = mallocstrcpy(NULL, option);
ws_len = strlen(whitespace);
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);
whitespace = NULL;
}
@ -584,14 +583,14 @@ void parse_rcfile(FILE *rcstream)
if (!strcasecmp(rcopts[i].name, "punct")) {
punct = mallocstrcpy(NULL, option);
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);
punct = NULL;
}
} else if (!strcasecmp(rcopts[i].name, "brackets")) {
brackets = mallocstrcpy(NULL, option);
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);
brackets = NULL;
}
@ -611,7 +610,7 @@ void parse_rcfile(FILE *rcstream)
#endif
if (!strcasecmp(rcopts[i].name, "tabsize")) {
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;
}
} else
@ -632,6 +631,14 @@ void parse_rcfile(FILE *rcstream)
}
}
free(buf);
if (errors) {
errors = FALSE;
fprintf(stderr, _("\nPress Return to continue starting nano\n"));
while (getchar() != '\n')
;
}
return;
}
@ -666,7 +673,7 @@ void do_rcfile(void)
endpwent();
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);
} else {
nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9);
@ -686,7 +693,7 @@ void do_rcfile(void)
if ((rcstream = fopen(nanorc, "r")) == NULL) {
/* Don't complain about the file not existing */
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);
}
} else {