Commit 36dd87b1 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

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
No related merge requests found
Showing with 34 additions and 53 deletions
+34 -53
...@@ -37,7 +37,8 @@ CVS code - ...@@ -37,7 +37,8 @@ CVS code -
while keeping the ability to hold negative numbers in case of while keeping the ability to hold negative numbers in case of
errors. Also exit instead of calling usage() in the event of errors. Also exit instead of calling usage() in the event of
an invalid fill value, for consistency with how an invalid 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 - Remove several unnecessary reset_cursor() calls. (David
Benbennick) Benbennick)
- Include <sys/types.h> in proto.h. (David Benbennick) DLR: - Include <sys/types.h> in proto.h. (David Benbennick) DLR:
......
...@@ -1535,8 +1535,7 @@ int write_file(const char *name, int tmp, int append, int nonamechange) ...@@ -1535,8 +1535,7 @@ int write_file(const char *name, int tmp, int append, int nonamechange)
utime(backupname, &filetime) == -1) { utime(backupname, &filetime) == -1) {
free(backupname); free(backupname);
if (copy_status == -1) if (copy_status == -1)
statusbar(_("Error reading %s: %s"), realname, statusbar(_("Error reading %s: %s"), realname, strerror(errno));
strerror(errno));
else else
statusbar(_("Error writing %s: %s"), backupname, statusbar(_("Error writing %s: %s"), backupname,
strerror(errno)); strerror(errno));
...@@ -2694,14 +2693,16 @@ char *do_browser(const char *inpath) ...@@ -2694,14 +2693,16 @@ char *do_browser(const char *inpath)
* directory if it is .. or if it is a symlink to * directory if it is .. or if it is a symlink to
* directory outside the operating directory. */ * directory outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE) != 0) { 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(); beep();
break; break;
} }
#endif #endif
if (stat(filelist[selected], &st) == -1) { 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(); beep();
break; break;
} }
...@@ -2728,7 +2729,8 @@ char *do_browser(const char *inpath) ...@@ -2728,7 +2729,8 @@ char *do_browser(const char *inpath)
if (!readable_dir(new_path)) { if (!readable_dir(new_path)) {
/* We can't open this dir for some reason. Complain */ /* 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); free(new_path);
break; break;
} }
...@@ -2953,8 +2955,7 @@ void load_history(void) ...@@ -2953,8 +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"), rcfile_error(N_("Unable to open ~/.nano_history file: %s"), strerror(errno));
strerror(errno));
} }
free(nanohist); free(nanohist);
} else { } else {
...@@ -3003,10 +3004,9 @@ void save_history(void) ...@@ -3003,10 +3004,9 @@ 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"), rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno));
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);
/* write oldest first */ /* write oldest first */
...@@ -3014,25 +3014,19 @@ void save_history(void) ...@@ -3014,25 +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( rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno));
N_("Unable to write ~/.nano_history file: %s"),
strerror(errno));
goto come_from; goto come_from;
} }
} }
if (fputs("\n", hist) == EOF) { if (fputs("\n", hist) == EOF) {
rcfile_error( rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno));
N_("Unable to write ~/.nano_history file: %s"),
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( rcfile_error(N_("Unable to write ~/.nano_history file: %s"), strerror(errno));
N_("Unable to write ~/.nano_history file: %s"),
strerror(errno));
goto come_from; goto come_from;
} }
} }
......
...@@ -210,10 +210,10 @@ int colortoint(const char *colorname, int *bright) ...@@ -210,10 +210,10 @@ int colortoint(const char *colorname, int *bright)
mcolor = COLOR_BLACK; mcolor = COLOR_BLACK;
else { else {
rcfile_error(N_("Color %s not understood.\n" rcfile_error(N_("Color %s not understood.\n"
"Valid colors are \"green\", \"red\", \"blue\", \n" "Valid colors are \"green\", \"red\", \"blue\", \n"
"\"white\", \"yellow\", \"cyan\", \"magenta\" and \n" "\"white\", \"yellow\", \"cyan\", \"magenta\" and \n"
"\"black\", with the optional prefix \"bright\" \n" "\"black\", with the optional prefix \"bright\" \n"
"for foreground colors.\n"), colorname); "for foreground colors.\n"), colorname);
mcolor = -1; mcolor = -1;
} }
return mcolor; return mcolor;
...@@ -268,8 +268,7 @@ void parse_syntax(char *ptr) ...@@ -268,8 +268,7 @@ void parse_syntax(char *ptr)
return; return;
if (*ptr != '"') { if (*ptr != '"') {
rcfile_error( rcfile_error(N_("Regex strings must begin and end with a \" character\n"));
N_("Regex strings must begin and end with a \" character\n"));
return; return;
} }
ptr++; ptr++;
...@@ -356,8 +355,7 @@ void parse_colors(char *ptr) ...@@ -356,8 +355,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"), rcfile_error(N_("Background color %s cannot be bright"), bgcolorname);
bgcolorname);
return; return;
} }
bg = colortoint(bgcolorname, &bright); bg = colortoint(bgcolorname, &bright);
...@@ -400,8 +398,7 @@ void parse_colors(char *ptr) ...@@ -400,8 +398,7 @@ void parse_colors(char *ptr)
} }
if (*ptr != '"') { if (*ptr != '"') {
rcfile_error( rcfile_error(N_("Regex strings must begin and end with a \" character\n"));
N_("Regex strings must begin and end with a \" character\n"));
ptr = parse_next_regex(ptr); ptr = parse_next_regex(ptr);
continue; continue;
} }
...@@ -439,16 +436,14 @@ void parse_colors(char *ptr) ...@@ -439,16 +436,14 @@ 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( rcfile_error(N_("\"start=\" requires a corresponding \"end=\""));
N_("\"start=\" requires a corresponding \"end=\""));
return; return;
} }
ptr += 4; ptr += 4;
if (*ptr != '"') { if (*ptr != '"') {
rcfile_error( rcfile_error(N_("Regex strings must begin and end with a \" character\n"));
N_("Regex strings must begin and end with a \" character\n"));
continue; continue;
} }
ptr++; ptr++;
...@@ -551,9 +546,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -551,9 +546,7 @@ void parse_rcfile(FILE *rcstream)
#endif #endif
) { ) {
if (*ptr == '\n' || *ptr == '\0') { if (*ptr == '\n' || *ptr == '\0') {
rcfile_error( rcfile_error(N_("Option %s requires an argument"), rcopts[i].name);
N_("Option %s requires an argument"),
rcopts[i].name);
continue; continue;
} }
option = ptr; option = ptr;
...@@ -571,9 +564,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -571,9 +564,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( rcfile_error(N_("Requested fill size %s invalid"), option);
N_("Requested fill size %s invalid"),
option);
} else } else
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
...@@ -582,8 +573,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -582,8 +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( rcfile_error(N_("Two non-control characters required"));
N_("Two non-control characters required"));
free(whitespace); free(whitespace);
whitespace = NULL; whitespace = NULL;
} }
...@@ -593,16 +583,14 @@ void parse_rcfile(FILE *rcstream) ...@@ -593,16 +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( rcfile_error(N_("Non-tab and non-space characters required"));
N_("Non-tab and non-space characters required"));
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( rcfile_error(N_("Non-tab and non-space characters required"));
N_("Non-tab and non-space characters required"));
free(brackets); free(brackets);
brackets = NULL; brackets = NULL;
} }
...@@ -621,10 +609,9 @@ void parse_rcfile(FILE *rcstream) ...@@ -621,10 +609,9 @@ void parse_rcfile(FILE *rcstream)
else else
#endif #endif
if (!strcasecmp(rcopts[i].name, "tabsize")) { if (!strcasecmp(rcopts[i].name, "tabsize")) {
if (parse_num(option, &tabsize) == -1) if (parse_num(option, &tabsize) == -1 ||
rcfile_error( tabsize <= 0)
N_("Requested tab size %s invalid"), rcfile_error(N_("Requested tab size %s invalid"), option);
option);
} }
} else } else
SET(rcopts[i].flag); SET(rcopts[i].flag);
...@@ -698,8 +685,7 @@ void do_rcfile(void) ...@@ -698,8 +685,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"), rcfile_error(N_("Unable to open ~/.nanorc file: %s"), strerror(errno));
strerror(errno));
SET(NO_RCFILE); SET(NO_RCFILE);
} }
} else { } else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment