Commit 6420d445 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add a bunch of DB's miscellaneous fixes, plus a few of mine

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1890 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 049e4a5d
Showing with 76 additions and 73 deletions
+76 -73
...@@ -68,8 +68,8 @@ CVS code - ...@@ -68,8 +68,8 @@ CVS code -
- Readded the errors flag and moved the ending prompt from - Readded the errors flag and moved the ending prompt from
rcfile_error() to parse_rcfile() so that we only get prompted rcfile_error() to parse_rcfile() so that we only get prompted
once for all errors instead of separately for each error. once for all errors instead of separately for each error.
Also make sure that each rcfile error message ends in a (DLR) David Benbennick: Make sure that no rcfile error
newline. (DLR) messages end in newlines.
- Don't treat the return value of strn?(case)?cmp() as boolean. - Don't treat the return value of strn?(case)?cmp() as boolean.
(DLR and David Benbennick) (DLR and David Benbennick)
- Automatically install a symlink "rnano" pointing to nano. - Automatically install a symlink "rnano" pointing to nano.
...@@ -83,6 +83,10 @@ CVS code - ...@@ -83,6 +83,10 @@ CVS code -
- Add various #ifdefs to fix warnings and compilation problems - Add various #ifdefs to fix warnings and compilation problems
when compiling with every option manually turned on, including when compiling with every option manually turned on, including
NANO_SMALL. (David Benbennick) NANO_SMALL. (David Benbennick)
- Simplify some of the rcfile and statusbar error messages, and
make some of them more consistent. (David Benbennick and DLR)
- Change some functions to take const char*'s instead of char*'s
where possible. (David Benbennick)
- files.c: - files.c:
get_next_filename() get_next_filename()
- Tweak for efficiency, and add the ".save" suffix to the file - Tweak for efficiency, and add the ".save" suffix to the file
...@@ -95,7 +99,7 @@ CVS code - ...@@ -95,7 +99,7 @@ CVS code -
the mode of newly created files 666 instead of 600 before the mode of newly created files 666 instead of 600 before
it's modified by the umask. (DLR) it's modified by the umask. (DLR)
do_writeout() do_writeout()
- If we're in restricted mode abd the current filename isn't - If we're in restricted mode and the current filename isn't
blank, we can't change it, so disable tab completion in that blank, we can't change it, so disable tab completion in that
case. (DLR) case. (DLR)
- Fix spacing problem in the "Save Under Different Name" - Fix spacing problem in the "Save Under Different Name"
...@@ -170,6 +174,8 @@ CVS code - ...@@ -170,6 +174,8 @@ CVS code -
used in the actual functions. (DLR) used in the actual functions. (DLR)
- Remove unused declaration of temp_opt. (David Benbennick) - Remove unused declaration of temp_opt. (David Benbennick)
- Add missing copy_file() prototype. (David Benbennick) - Add missing copy_file() prototype. (David Benbennick)
- Move the load_history() and save_history() prototypes up to
match their corresponding location in files.c. (DLR)
- rcfile.c: - rcfile.c:
rcfile_msg() rcfile_msg()
- Removed along with the related static int errors, and replaced - Removed along with the related static int errors, and replaced
...@@ -197,14 +203,20 @@ CVS code - ...@@ -197,14 +203,20 @@ CVS code -
- Use parse_num() to interpret a line entered by the user, and - Use parse_num() to interpret a line entered by the user, and
start the search for a line from current instead of fileage. start the search for a line from current instead of fileage.
(DLR) (DLR)
do_gotopos() do_gotopos(), find_node(), free_history()
- Tweak for efficiency. (David Benbennick) - Tweak for efficiency. (David Benbennick)
free_history()
- Only include when DEBUG is defined. (David Benbennick)
- utils.c: - utils.c:
parse_num() parse_num()
- New function to parse numeric values, so that we don't have to - New function to parse numeric values, so that we don't have to
duplicate code that calls strtol() all over the place. (David duplicate code that calls strtol() all over the place. (David
Benbennick) DLR: Renamed from parse_int() to parse_num() and Benbennick) DLR: Renamed from parse_int() to parse_num() and
converted to use ssize_t instead of int. converted to use ssize_t instead of int.
nstrnicmp()
- Remove code chacking for n's being less than 0 that will never
be run, since n is a size_t and is hence unsigned. (David
Benbennick)
- winio.c: - winio.c:
get_kbinput() get_kbinput()
- Since the only valid values for escapes are 0, 1, and 2, - Since the only valid values for escapes are 0, 1, and 2,
......
...@@ -371,7 +371,7 @@ bool open_file(const char *filename, int insert, int quiet) ...@@ -371,7 +371,7 @@ bool open_file(const char *filename, int insert, int quiet)
|| ISSET(MULTIBUFFER) || ISSET(MULTIBUFFER)
#endif #endif
) )
statusbar("%s: %s", strerror(errno), filename); statusbar("Error reading %s: %s", filename, strerror(errno));
if (!insert) if (!insert)
new_file(); new_file();
return FALSE; return FALSE;
...@@ -1026,11 +1026,7 @@ char *get_full_path(const char *origpath) ...@@ -1026,11 +1026,7 @@ char *get_full_path(const char *origpath)
/* first, get the current directory, and tack a slash onto the end of /* first, get the current directory, and tack a slash onto the end of
it, unless it turns out to be "/", in which case leave it alone */ it, unless it turns out to be "/", in which case leave it alone */
#ifdef PATH_MAX
d_here = getcwd(NULL, PATH_MAX + 1); d_here = getcwd(NULL, PATH_MAX + 1);
#else
d_here = getcwd(NULL, 0);
#endif
if (d_here != NULL) { if (d_here != NULL) {
...@@ -1096,11 +1092,7 @@ char *get_full_path(const char *origpath) ...@@ -1096,11 +1092,7 @@ char *get_full_path(const char *origpath)
free(d_there); free(d_there);
#ifdef PATH_MAX
d_there = getcwd(NULL, PATH_MAX + 1); d_there = getcwd(NULL, PATH_MAX + 1);
#else
d_there = getcwd(NULL, 0);
#endif
align(&d_there); align(&d_there);
if (d_there != NULL) { if (d_there != NULL) {
...@@ -1847,8 +1839,8 @@ int do_writeout(int exiting) ...@@ -1847,8 +1839,8 @@ int do_writeout(int exiting)
/* If we're using restricted mode, the filename isn't blank, /* If we're using restricted mode, the filename isn't blank,
* and we're at the "Write File" prompt, disable tab * and we're at the "Write File" prompt, disable tab
* completion. */ * completion. */
i = statusq(!ISSET(RESTRICTED) || filename[0] == '\0' ? TRUE : i = statusq(!ISSET(RESTRICTED) || filename[0] == '\0',
FALSE, writefile_list, writefile_list,
#ifndef NANO_SMALL #ifndef NANO_SMALL
ans, NULL, "%s%s%s", _(msg), formatstr, backupstr ans, NULL, "%s%s%s", _(msg), formatstr, backupstr
#else #else
...@@ -2115,12 +2107,7 @@ char **cwd_tab_completion(char *buf, int *num_matches) ...@@ -2115,12 +2107,7 @@ char **cwd_tab_completion(char *buf, int *num_matches)
} else { } else {
#ifdef PATH_MAX
if ((dirname = getcwd(NULL, PATH_MAX + 1)) == NULL) if ((dirname = getcwd(NULL, PATH_MAX + 1)) == NULL)
#else
/* The better, but apparently segfault-causing way */
if ((dirname = getcwd(NULL, 0)) == NULL)
#endif /* PATH_MAX */
return matches; return matches;
else else
tmp = buf; tmp = buf;
...@@ -2742,7 +2729,7 @@ char *do_browser(const char *inpath) ...@@ -2742,7 +2729,7 @@ char *do_browser(const char *inpath)
path = new_path; path = new_path;
return do_browser(path); return do_browser(path);
/* Goto a specific directory */ /* Go to a specific directory */
case NANO_GOTO_KEY: case NANO_GOTO_KEY:
case NANO_GOTO_FKEY: case NANO_GOTO_FKEY:
case 'G': /* Pico compatibility */ case 'G': /* Pico compatibility */
...@@ -2752,12 +2739,12 @@ char *do_browser(const char *inpath) ...@@ -2752,12 +2739,12 @@ char *do_browser(const char *inpath)
#ifndef NANO_SMALL #ifndef NANO_SMALL
NULL, NULL,
#endif #endif
_("Goto Directory")); _("Go To Directory"));
bottombars(browser_list); bottombars(browser_list);
curs_set(0); curs_set(0);
if (j < 0) { if (j < 0) {
statusbar(_("Goto Cancelled")); statusbar(_("Cancelled"));
break; break;
} }
...@@ -2926,8 +2913,7 @@ char *do_browse_from(const char *inpath) ...@@ -2926,8 +2913,7 @@ char *do_browse_from(const char *inpath)
} }
#endif /* !DISABLE_BROWSER */ #endif /* !DISABLE_BROWSER */
#ifndef NANO_SMALL #if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
#ifdef ENABLE_NANORC
void load_history(void) void load_history(void)
{ {
FILE *hist; FILE *hist;
...@@ -2939,24 +2925,24 @@ void load_history(void) ...@@ -2939,24 +2925,24 @@ void load_history(void)
if (homenv != NULL) { if (homenv != NULL) {
nanohist = charealloc(nanohist, strlen(homenv) + 15); nanohist = charealloc(nanohist, strlen(homenv) + 15);
sprintf(nanohist, "%s/.nano_history", homenv); sprintf(nanohist, "%s/.nano_history", homenv);
} else { } else {
userage = getpwuid(geteuid()); userage = getpwuid(geteuid());
endpwent(); endpwent();
nanohist = charealloc(nanohist, strlen(userage->pw_dir) + 15); nanohist = charealloc(nanohist, strlen(userage->pw_dir) + 15);
sprintf(nanohist, "%s/.nano_history", userage->pw_dir); sprintf(nanohist, "%s/.nano_history", userage->pw_dir);
} }
/* assume do_rcfile has reported missing home dir */ /* assume do_rcfile() has reported missing home dir */
if (homenv != NULL || userage != NULL) { if (homenv != NULL || userage != NULL) {
hist = fopen(nanohist, "r"); hist = fopen(nanohist, "r");
if (hist == NULL) { if (hist == NULL) {
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\n"), strerror(errno)); rcfile_error(N_("Error reading %s: %s"), nanohist, strerror(errno));
} }
free(nanohist); free(nanohist);
} else { } else {
...@@ -2990,7 +2976,7 @@ void save_history(void) ...@@ -2990,7 +2976,7 @@ void save_history(void)
/* don't save unchanged or empty histories */ /* don't save unchanged or empty histories */
if ((search_history.count == 0 && replace_history.count == 0) || if ((search_history.count == 0 && replace_history.count == 0) ||
!ISSET(HISTORY_CHANGED) || ISSET(VIEW_MODE)) !ISSET(HISTORY_CHANGED) || ISSET(VIEW_MODE))
return; return;
if (homenv != NULL) { if (homenv != NULL) {
...@@ -3006,7 +2992,7 @@ void save_history(void) ...@@ -3006,7 +2992,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\n"), strerror(errno)); rcfile_error(N_("Error writing %s: %s"), nanohist, 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);
...@@ -3015,12 +3001,12 @@ void save_history(void) ...@@ -3015,12 +3001,12 @@ 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\n"), strerror(errno)); rcfile_error(N_("Error writing %s: %s"), nanohist, 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\n"), strerror(errno)); rcfile_error(N_("Error writing %s: %s"), nanohist, 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) {
...@@ -3037,5 +3023,4 @@ void save_history(void) ...@@ -3037,5 +3023,4 @@ void save_history(void)
free(nanohist); free(nanohist);
} }
} }
#endif /* ENABLE_NANORC */ #endif /* !NANO_SMALL && ENABLE_NANORC */
#endif /* !NANO_SMALL */
...@@ -3158,7 +3158,8 @@ int main(int argc, char *argv[]) ...@@ -3158,7 +3158,8 @@ int main(int argc, char *argv[])
#endif #endif
case 'T': case 'T':
if (!parse_num(optarg, &tabsize) || tabsize <= 0) { if (!parse_num(optarg, &tabsize) || tabsize <= 0) {
fprintf(stderr, _("Requested tab size %s invalid\n"), optarg); fprintf(stderr, _("Requested tab size %s invalid"), optarg);
fprintf(stderr, "\n");
exit(1); exit(1);
} }
break; break;
...@@ -3206,7 +3207,8 @@ int main(int argc, char *argv[]) ...@@ -3206,7 +3207,8 @@ int main(int argc, char *argv[])
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
case 'r': case 'r':
if (!parse_num(optarg, &wrap_at)) { if (!parse_num(optarg, &wrap_at)) {
fprintf(stderr, _("Requested fill size %s invalid\n"), optarg); fprintf(stderr, _("Requested fill size %s invalid"), optarg);
fprintf(stderr, "\n");
exit(1); exit(1);
} }
fill_flag_used = TRUE; fill_flag_used = TRUE;
......
...@@ -223,6 +223,10 @@ char **browser_init(const char *path, int *longest, int *numents); ...@@ -223,6 +223,10 @@ char **browser_init(const char *path, int *longest, int *numents);
char *do_browser(const char *inpath); char *do_browser(const char *inpath);
char *do_browse_from(const char *inpath); char *do_browse_from(const char *inpath);
#endif #endif
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
void load_history(void);
void save_history(void);
#endif
/* Public functions in global.c */ /* Public functions in global.c */
size_t length_of_list(const shortcut *s); size_t length_of_list(const shortcut *s);
...@@ -409,17 +413,15 @@ void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww); ...@@ -409,17 +413,15 @@ void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww);
void do_find_bracket(void); void do_find_bracket(void);
#ifndef NANO_SMALL #ifndef NANO_SMALL
void history_init(void); void history_init(void);
historytype *find_node(historytype *h, char *s); historytype *find_node(historytype *h, const char *s);
void remove_node(historytype *r); void remove_node(historytype *r);
void insert_node(historytype *h, const char *s); void insert_node(historytype *h, const char *s);
void update_history(historyheadtype *h, char *s); void update_history(historyheadtype *h, const char *s);
char *get_history_older(historyheadtype *h); char *get_history_older(historyheadtype *h);
char *get_history_newer(historyheadtype *h); char *get_history_newer(historyheadtype *h);
char *get_history_completion(historyheadtype *h, char *s); char *get_history_completion(historyheadtype *h, char *s);
#ifdef DEBUG
void free_history(historyheadtype *h); void free_history(historyheadtype *h);
#ifdef ENABLE_NANORC
void load_history(void);
void save_history(void);
#endif #endif
#endif #endif
......
...@@ -118,6 +118,8 @@ void rcfile_error(const char *msg, ...) ...@@ -118,6 +118,8 @@ void rcfile_error(const char *msg, ...)
va_start(ap, msg); va_start(ap, msg);
vfprintf(stderr, _(msg), ap); vfprintf(stderr, _(msg), ap);
va_end(ap); va_end(ap);
fprintf(stderr, "\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. */
...@@ -166,7 +168,7 @@ char *parse_argument(char *ptr) ...@@ -166,7 +168,7 @@ char *parse_argument(char *ptr)
ptr = NULL; ptr = NULL;
else else
*ptr++ = '\0'; *ptr++ = '\0';
rcfile_error(N_("Argument %s has unterminated \"\n"), ptr_bak); rcfile_error(N_("Argument %s has unterminated \""), ptr_bak);
} else { } else {
*last_quote = '\0'; *last_quote = '\0';
ptr = last_quote + 1; ptr = last_quote + 1;
...@@ -212,7 +214,7 @@ int colortoint(const char *colorname, int *bright) ...@@ -212,7 +214,7 @@ int colortoint(const char *colorname, int *bright)
"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."), colorname);
mcolor = -1; mcolor = -1;
} }
return mcolor; return mcolor;
...@@ -247,7 +249,7 @@ int nregcomp(regex_t *preg, const char *regex, int eflags) ...@@ -247,7 +249,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\n"), regex, str); rcfile_error(N_("Bad regex \"%s\": %s"), regex, str);
free(str); free(str);
} }
return rc != 0; return rc != 0;
...@@ -267,7 +269,7 @@ void parse_syntax(char *ptr) ...@@ -267,7 +269,7 @@ void parse_syntax(char *ptr)
return; return;
if (*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"));
return; return;
} }
ptr++; ptr++;
...@@ -276,7 +278,7 @@ void parse_syntax(char *ptr) ...@@ -276,7 +278,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\n")); rcfile_error(N_("Missing syntax name"));
return; return;
} }
...@@ -345,7 +347,7 @@ void parse_colors(char *ptr) ...@@ -345,7 +347,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\n")); rcfile_error(N_("Missing color name"));
return; return;
} }
...@@ -354,7 +356,7 @@ void parse_colors(char *ptr) ...@@ -354,7 +356,7 @@ void parse_colors(char *ptr)
strtok(fgstr, ","); strtok(fgstr, ",");
bgcolorname = strtok(NULL, ","); bgcolorname = strtok(NULL, ",");
if (strncasecmp(bgcolorname, "bright", 6) == 0) { if (strncasecmp(bgcolorname, "bright", 6) == 0) {
rcfile_error(N_("Background color %s cannot be bright\n"), bgcolorname); rcfile_error(N_("Background color %s cannot be bright"), bgcolorname);
return; return;
} }
bg = colortoint(bgcolorname, &bright); bg = colortoint(bgcolorname, &bright);
...@@ -368,7 +370,7 @@ void parse_colors(char *ptr) ...@@ -368,7 +370,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\n")); rcfile_error(N_("Cannot add a color directive without a syntax line"));
return; return;
} }
...@@ -397,7 +399,7 @@ void parse_colors(char *ptr) ...@@ -397,7 +399,7 @@ void parse_colors(char *ptr)
} }
if (*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"));
ptr = parse_next_regex(ptr); ptr = parse_next_regex(ptr);
continue; continue;
} }
...@@ -434,14 +436,14 @@ void parse_colors(char *ptr) ...@@ -434,14 +436,14 @@ void parse_colors(char *ptr)
if (expectend) { if (expectend) {
if (ptr == NULL || strncasecmp(ptr, "end=", 4) != 0) { if (ptr == NULL || strncasecmp(ptr, "end=", 4) != 0) {
rcfile_error(N_("\"start=\" requires a corresponding \"end=\"\n")); rcfile_error(N_("\"start=\" requires a corresponding \"end=\""));
return; return;
} }
ptr += 4; ptr += 4;
if (*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"));
continue; continue;
} }
ptr++; ptr++;
...@@ -505,7 +507,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -505,7 +507,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\n"), keyword); rcfile_error(N_("Command %s not understood"), keyword);
continue; continue;
} }
...@@ -544,7 +546,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -544,7 +546,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\n"), rcopts[i].name); rcfile_error(N_("Option %s requires an argument"), rcopts[i].name);
continue; continue;
} }
option = ptr; option = ptr;
...@@ -562,7 +564,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -562,7 +564,7 @@ void parse_rcfile(FILE *rcstream)
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
if (strcasecmp(rcopts[i].name, "fill") == 0) { if (strcasecmp(rcopts[i].name, "fill") == 0) {
if (!parse_num(option, &wrap_at)) { if (!parse_num(option, &wrap_at)) {
rcfile_error(N_("Requested fill size %s invalid\n"), option); rcfile_error(N_("Requested fill size %s invalid"), option);
wrap_at = -CHARS_FROM_EOL; wrap_at = -CHARS_FROM_EOL;
} }
} else } else
...@@ -573,7 +575,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -573,7 +575,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\n")); rcfile_error(N_("Two non-control characters required"));
free(whitespace); free(whitespace);
whitespace = NULL; whitespace = NULL;
} }
...@@ -583,14 +585,14 @@ void parse_rcfile(FILE *rcstream) ...@@ -583,14 +585,14 @@ void parse_rcfile(FILE *rcstream)
if (strcasecmp(rcopts[i].name, "punct") == 0) { if (strcasecmp(rcopts[i].name, "punct") == 0) {
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\n")); rcfile_error(N_("Non-tab and non-space characters required"));
free(punct); free(punct);
punct = NULL; punct = NULL;
} }
} else if (strcasecmp(rcopts[i].name, "brackets") == 0) { } else if (strcasecmp(rcopts[i].name, "brackets") == 0) {
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\n")); rcfile_error(N_("Non-tab and non-space characters required"));
free(brackets); free(brackets);
brackets = NULL; brackets = NULL;
} }
...@@ -610,7 +612,7 @@ void parse_rcfile(FILE *rcstream) ...@@ -610,7 +612,7 @@ void parse_rcfile(FILE *rcstream)
#endif #endif
if (strcasecmp(rcopts[i].name, "tabsize") == 0) { if (strcasecmp(rcopts[i].name, "tabsize") == 0) {
if (!parse_num(option, &tabsize) || tabsize <= 0) if (!parse_num(option, &tabsize) || tabsize <= 0)
rcfile_error(N_("Requested tab size %s invalid\n"), option); rcfile_error(N_("Requested tab size %s invalid"), option);
tabsize = -1; tabsize = -1;
} }
} else } else
...@@ -673,7 +675,7 @@ void do_rcfile(void) ...@@ -673,7 +675,7 @@ void do_rcfile(void)
endpwent(); endpwent();
if (userage == NULL) { if (userage == NULL) {
rcfile_error(N_("I can't find my home directory! Wah!\n")); rcfile_error(N_("I can't find my home directory! Wah!"));
SET(NO_RCFILE); SET(NO_RCFILE);
} else { } else {
nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9); nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9);
...@@ -693,7 +695,7 @@ void do_rcfile(void) ...@@ -693,7 +695,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\n"), strerror(errno)); rcfile_error(N_("Error reading %s: %s"), nanorc, strerror(errno));
SET(NO_RCFILE); SET(NO_RCFILE);
} }
} else { } else {
......
...@@ -1006,7 +1006,7 @@ void history_init(void) ...@@ -1006,7 +1006,7 @@ void history_init(void)
} }
/* find first node containing string *s in history list *h */ /* find first node containing string *s in history list *h */
historytype *find_node(historytype *h, char *s) historytype *find_node(historytype *h, const char *s)
{ {
for (; h->next != NULL; h = h->next) for (; h->next != NULL; h = h->next)
if (strcmp(s, h->data) == 0) if (strcmp(s, h->data) == 0)
...@@ -1030,14 +1030,14 @@ void insert_node(historytype *h, const char *s) ...@@ -1030,14 +1030,14 @@ void insert_node(historytype *h, const char *s)
a = (historytype *)nmalloc(sizeof(historytype)); a = (historytype *)nmalloc(sizeof(historytype));
a->next = h->next; a->next = h->next;
a->prev = h->next->prev; a->prev = h;
h->next->prev = a; h->next->prev = a;
h->next = a; h->next = a;
a->data = mallocstrcpy(NULL, s); a->data = mallocstrcpy(NULL, s);
} }
/* update history list */ /* update history list */
void update_history(historyheadtype *h, char *s) void update_history(historyheadtype *h, const char *s)
{ {
historytype *p; historytype *p;
...@@ -1095,14 +1095,16 @@ char *get_history_completion(historyheadtype *h, char *s) ...@@ -1095,14 +1095,16 @@ char *get_history_completion(historyheadtype *h, char *s)
return s; return s;
} }
#ifdef DEBUG
/* free a history list */ /* free a history list */
void free_history(historyheadtype *h) void free_history(historyheadtype *h)
{ {
historytype *p, *n; historytype *p;
for (p = h->next; (n = p->next); p = n) for (p = h->next; p->next != NULL; p = p->next)
remove_node(p); remove_node(p);
} }
#endif
/* end of history support functions */ /* end of history support functions */
#endif /* !NANO_SMALL */ #endif /* !NANO_SMALL */
...@@ -167,10 +167,8 @@ int nstrnicmp(const char *s1, const char *s2, size_t n) ...@@ -167,10 +167,8 @@ int nstrnicmp(const char *s1, const char *s2, size_t n)
if (n > 0) if (n > 0)
return (tolower(*s1) - tolower(*s2)); return (tolower(*s1) - tolower(*s2));
else if (n == 0)
return 0;
else else
return -1; return 0;
} }
#endif #endif
......
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