mirror of git://git.sv.gnu.org/nano.git
properly handle invalid tab sizes in nanorc files and make a few more
cosmetic cleanups git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1859 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
24f10c30c3
commit
36dd87b1fb
|
@ -37,7 +37,8 @@ CVS code -
|
|||
while keeping the ability to hold negative numbers in case of
|
||||
errors. Also exit instead of calling usage() in the event of
|
||||
an invalid fill value, for consistency with how an invalid
|
||||
tabsize value is handled.
|
||||
tabsize value is handled. Finally, handle invalid tabsize
|
||||
entries in the rcfile the same way as on the command line.
|
||||
- Remove several unnecessary reset_cursor() calls. (David
|
||||
Benbennick)
|
||||
- Include <sys/types.h> in proto.h. (David Benbennick) DLR:
|
||||
|
|
34
src/files.c
34
src/files.c
|
@ -1535,8 +1535,7 @@ int write_file(const char *name, int tmp, int append, int nonamechange)
|
|||
utime(backupname, &filetime) == -1) {
|
||||
free(backupname);
|
||||
if (copy_status == -1)
|
||||
statusbar(_("Error reading %s: %s"), realname,
|
||||
strerror(errno));
|
||||
statusbar(_("Error reading %s: %s"), realname, strerror(errno));
|
||||
else
|
||||
statusbar(_("Error writing %s: %s"), backupname,
|
||||
strerror(errno));
|
||||
|
@ -2694,14 +2693,16 @@ char *do_browser(const char *inpath)
|
|||
* directory if it is .. or if it is a symlink to
|
||||
* directory outside the operating directory. */
|
||||
if (check_operating_dir(filelist[selected], FALSE) != 0) {
|
||||
statusbar(_("Can't go outside of %s in restricted mode"), operating_dir);
|
||||
statusbar(_("Can't go outside of %s in restricted mode"),
|
||||
operating_dir);
|
||||
beep();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (stat(filelist[selected], &st) == -1) {
|
||||
statusbar(_("Can't open \"%s\": %s"), filelist[selected], strerror(errno));
|
||||
statusbar(_("Can't open \"%s\": %s"), filelist[selected],
|
||||
strerror(errno));
|
||||
beep();
|
||||
break;
|
||||
}
|
||||
|
@ -2728,7 +2729,8 @@ char *do_browser(const char *inpath)
|
|||
|
||||
if (!readable_dir(new_path)) {
|
||||
/* We can't open this dir for some reason. Complain */
|
||||
statusbar(_("Can't open \"%s\": %s"), new_path, strerror(errno));
|
||||
statusbar(_("Can't open \"%s\": %s"), new_path,
|
||||
strerror(errno));
|
||||
free(new_path);
|
||||
break;
|
||||
}
|
||||
|
@ -2953,8 +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"), strerror(errno));
|
||||
}
|
||||
free(nanohist);
|
||||
} else {
|
||||
|
@ -3003,10 +3004,9 @@ 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));
|
||||
} else {
|
||||
if (hist == NULL)
|
||||
rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno));
|
||||
else {
|
||||
/* set rw only by owner for security ?? */
|
||||
chmod(nanohist, S_IRUSR | S_IWUSR);
|
||||
/* write oldest first */
|
||||
|
@ -3014,25 +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"), 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"), 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"), strerror(errno));
|
||||
goto come_from;
|
||||
}
|
||||
}
|
||||
|
|
42
src/rcfile.c
42
src/rcfile.c
|
@ -268,8 +268,7 @@ void parse_syntax(char *ptr)
|
|||
return;
|
||||
|
||||
if (*ptr != '"') {
|
||||
rcfile_error(
|
||||
N_("Regex strings must begin and end with a \" character\n"));
|
||||
rcfile_error(N_("Regex strings must begin and end with a \" character\n"));
|
||||
return;
|
||||
}
|
||||
ptr++;
|
||||
|
@ -356,8 +355,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"), bgcolorname);
|
||||
return;
|
||||
}
|
||||
bg = colortoint(bgcolorname, &bright);
|
||||
|
@ -400,8 +398,7 @@ void parse_colors(char *ptr)
|
|||
}
|
||||
|
||||
if (*ptr != '"') {
|
||||
rcfile_error(
|
||||
N_("Regex strings must begin and end with a \" character\n"));
|
||||
rcfile_error(N_("Regex strings must begin and end with a \" character\n"));
|
||||
ptr = parse_next_regex(ptr);
|
||||
continue;
|
||||
}
|
||||
|
@ -439,16 +436,14 @@ 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=\""));
|
||||
return;
|
||||
}
|
||||
|
||||
ptr += 4;
|
||||
|
||||
if (*ptr != '"') {
|
||||
rcfile_error(
|
||||
N_("Regex strings must begin and end with a \" character\n"));
|
||||
rcfile_error(N_("Regex strings must begin and end with a \" character\n"));
|
||||
continue;
|
||||
}
|
||||
ptr++;
|
||||
|
@ -551,9 +546,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"), rcopts[i].name);
|
||||
continue;
|
||||
}
|
||||
option = ptr;
|
||||
|
@ -571,9 +564,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"), option);
|
||||
} else
|
||||
#endif
|
||||
#ifndef NANO_SMALL
|
||||
|
@ -582,8 +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"));
|
||||
free(whitespace);
|
||||
whitespace = NULL;
|
||||
}
|
||||
|
@ -593,16 +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"));
|
||||
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"));
|
||||
free(brackets);
|
||||
brackets = NULL;
|
||||
}
|
||||
|
@ -621,10 +609,9 @@ void parse_rcfile(FILE *rcstream)
|
|||
else
|
||||
#endif
|
||||
if (!strcasecmp(rcopts[i].name, "tabsize")) {
|
||||
if (parse_num(option, &tabsize) == -1)
|
||||
rcfile_error(
|
||||
N_("Requested tab size %s invalid"),
|
||||
option);
|
||||
if (parse_num(option, &tabsize) == -1 ||
|
||||
tabsize <= 0)
|
||||
rcfile_error(N_("Requested tab size %s invalid"), option);
|
||||
}
|
||||
} else
|
||||
SET(rcopts[i].flag);
|
||||
|
@ -698,8 +685,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"), strerror(errno));
|
||||
SET(NO_RCFILE);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue