- 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)
+ (DLR) David Benbennick: Make sure that no rcfile error
+ messages end in newlines.
- Don't treat the return value of strn?(case)?cmp() as boolean.
(DLR and David Benbennick)
- Automatically install a symlink "rnano" pointing to nano.
- Add various #ifdefs to fix warnings and compilation problems
when compiling with every option manually turned on, including
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:
get_next_filename()
- Tweak for efficiency, and add the ".save" suffix to the file
the mode of newly created files 666 instead of 600 before
it's modified by the umask. (DLR)
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
case. (DLR)
- Fix spacing problem in the "Save Under Different Name"
used in the actual functions. (DLR)
- Remove unused declaration of temp_opt. (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_msg()
- Removed along with the related static int errors, and replaced
- Use parse_num() to interpret a line entered by the user, and
start the search for a line from current instead of fileage.
(DLR)
- do_gotopos()
+ do_gotopos(), find_node(), free_history()
- Tweak for efficiency. (David Benbennick)
+ free_history()
+ - Only include when DEBUG is defined. (David Benbennick)
- utils.c:
parse_num()
- New function to parse numeric values, so that we don't have to
duplicate code that calls strtol() all over the place. (David
Benbennick) DLR: Renamed from parse_int() to parse_num() and
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:
get_kbinput()
- Since the only valid values for escapes are 0, 1, and 2,
|| ISSET(MULTIBUFFER)
#endif
)
- statusbar("%s: %s", strerror(errno), filename);
+ statusbar("Error reading %s: %s", filename, strerror(errno));
if (!insert)
new_file();
return FALSE;
/* 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 */
-#ifdef PATH_MAX
d_here = getcwd(NULL, PATH_MAX + 1);
-#else
- d_here = getcwd(NULL, 0);
-#endif
if (d_here != NULL) {
free(d_there);
-#ifdef PATH_MAX
d_there = getcwd(NULL, PATH_MAX + 1);
-#else
- d_there = getcwd(NULL, 0);
-#endif
align(&d_there);
if (d_there != NULL) {
/* If we're using restricted mode, the filename isn't blank,
* and we're at the "Write File" prompt, disable tab
* completion. */
- i = statusq(!ISSET(RESTRICTED) || filename[0] == '\0' ? TRUE :
- FALSE, writefile_list,
+ i = statusq(!ISSET(RESTRICTED) || filename[0] == '\0',
+ writefile_list,
#ifndef NANO_SMALL
ans, NULL, "%s%s%s", _(msg), formatstr, backupstr
#else
} else {
-#ifdef PATH_MAX
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;
else
tmp = buf;
path = new_path;
return do_browser(path);
- /* Goto a specific directory */
+ /* Go to a specific directory */
case NANO_GOTO_KEY:
case NANO_GOTO_FKEY:
case 'G': /* Pico compatibility */
#ifndef NANO_SMALL
NULL,
#endif
- _("Goto Directory"));
+ _("Go To Directory"));
bottombars(browser_list);
curs_set(0);
if (j < 0) {
- statusbar(_("Goto Cancelled"));
+ statusbar(_("Cancelled"));
break;
}
}
#endif /* !DISABLE_BROWSER */
-#ifndef NANO_SMALL
-#ifdef ENABLE_NANORC
+#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
void load_history(void)
{
FILE *hist;
if (homenv != NULL) {
- nanohist = charealloc(nanohist, strlen(homenv) + 15);
- sprintf(nanohist, "%s/.nano_history", homenv);
+ nanohist = charealloc(nanohist, strlen(homenv) + 15);
+ sprintf(nanohist, "%s/.nano_history", homenv);
} else {
userage = getpwuid(geteuid());
endpwent();
- nanohist = charealloc(nanohist, strlen(userage->pw_dir) + 15);
- sprintf(nanohist, "%s/.nano_history", userage->pw_dir);
+ nanohist = charealloc(nanohist, strlen(userage->pw_dir) + 15);
+ 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) {
hist = fopen(nanohist, "r");
if (hist == NULL) {
- if (errno != ENOENT) {
+ if (errno != ENOENT) {
/* Don't save history when we quit. */
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);
} else {
/* don't save unchanged or empty histories */
if ((search_history.count == 0 && replace_history.count == 0) ||
- !ISSET(HISTORY_CHANGED) || ISSET(VIEW_MODE))
+ !ISSET(HISTORY_CHANGED) || ISSET(VIEW_MODE))
return;
if (homenv != NULL) {
if (homenv != NULL || userage != NULL) {
hist = fopen(nanohist, "wb");
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 {
/* set rw only by owner for security ?? */
chmod(nanohist, S_IRUSR | S_IWUSR);
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\n"), strerror(errno));
+ rcfile_error(N_("Error writing %s: %s"), nanohist, strerror(errno));
goto come_from;
}
}
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;
}
for (h = replace_history.tail; h->prev; h = h->prev) {
free(nanohist);
}
}
-#endif /* ENABLE_NANORC */
-#endif /* !NANO_SMALL */
+#endif /* !NANO_SMALL && ENABLE_NANORC */
#endif
case 'T':
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);
}
break;
#ifndef DISABLE_WRAPJUSTIFY
case 'r':
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);
}
fill_flag_used = TRUE;
char *do_browser(const char *inpath);
char *do_browse_from(const char *inpath);
#endif
+#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
+void load_history(void);
+void save_history(void);
+#endif
/* Public functions in global.c */
size_t length_of_list(const shortcut *s);
void do_find_bracket(void);
#ifndef NANO_SMALL
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 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_newer(historyheadtype *h);
char *get_history_completion(historyheadtype *h, char *s);
+#ifdef DEBUG
void free_history(historyheadtype *h);
-#ifdef ENABLE_NANORC
-void load_history(void);
-void save_history(void);
#endif
#endif
va_start(ap, msg);
vfprintf(stderr, _(msg), ap);
va_end(ap);
+
+ fprintf(stderr, "\n");
}
/* Parse the next word from the string. Returns NULL if we hit EOL. */
ptr = NULL;
else
*ptr++ = '\0';
- rcfile_error(N_("Argument %s has unterminated \"\n"), ptr_bak);
+ rcfile_error(N_("Argument %s has unterminated \""), ptr_bak);
} else {
*last_quote = '\0';
ptr = last_quote + 1;
"Valid colors are \"green\", \"red\", \"blue\", \n"
"\"white\", \"yellow\", \"cyan\", \"magenta\" and \n"
"\"black\", with the optional prefix \"bright\" \n"
- "for foreground colors.\n"), colorname);
+ "for foreground colors."), colorname);
mcolor = -1;
}
return mcolor;
char *str = charalloc(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);
}
return rc != 0;
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"));
return;
}
ptr++;
ptr = parse_next_regex(ptr);
if (ptr == NULL) {
- rcfile_error(N_("Missing syntax name\n"));
+ rcfile_error(N_("Missing syntax name"));
return;
}
ptr = parse_next_word(ptr);
if (ptr == NULL) {
- rcfile_error(N_("Missing color name\n"));
+ rcfile_error(N_("Missing color name"));
return;
}
strtok(fgstr, ",");
bgcolorname = strtok(NULL, ",");
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;
}
bg = colortoint(bgcolorname, &bright);
return;
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;
}
}
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);
continue;
}
if (expectend) {
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;
}
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"));
continue;
}
ptr++;
parse_colors(ptr);
#endif /* ENABLE_COLOR */
else {
- rcfile_error(N_("Command %s not understood\n"), keyword);
+ rcfile_error(N_("Command %s not understood"), keyword);
continue;
}
#endif
) {
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;
}
option = ptr;
#ifndef DISABLE_WRAPJUSTIFY
if (strcasecmp(rcopts[i].name, "fill") == 0) {
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;
}
} else
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\n"));
+ rcfile_error(N_("Two non-control characters required"));
free(whitespace);
whitespace = NULL;
}
if (strcasecmp(rcopts[i].name, "punct") == 0) {
punct = mallocstrcpy(NULL, option);
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);
punct = NULL;
}
} else if (strcasecmp(rcopts[i].name, "brackets") == 0) {
brackets = mallocstrcpy(NULL, option);
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);
brackets = NULL;
}
#endif
if (strcasecmp(rcopts[i].name, "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;
}
} else
endpwent();
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);
} else {
nanorc = charealloc(nanorc, strlen(userage->pw_dir) + 9);
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\n"), strerror(errno));
+ rcfile_error(N_("Error reading %s: %s"), nanorc, strerror(errno));
SET(NO_RCFILE);
}
} else {
}
/* 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)
if (strcmp(s, h->data) == 0)
a = (historytype *)nmalloc(sizeof(historytype));
a->next = h->next;
- a->prev = h->next->prev;
+ a->prev = h;
h->next->prev = a;
h->next = a;
a->data = mallocstrcpy(NULL, s);
}
/* update history list */
-void update_history(historyheadtype *h, char *s)
+void update_history(historyheadtype *h, const char *s)
{
historytype *p;
return s;
}
+#ifdef DEBUG
/* free a history list */
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);
}
+#endif
/* end of history support functions */
#endif /* !NANO_SMALL */
if (n > 0)
return (tolower(*s1) - tolower(*s2));
- else if (n == 0)
- return 0;
else
- return -1;
+ return 0;
}
#endif