#include <stdio.h>
#include <errno.h>
#include <unistd.h>
-#include <fcntl.h>
#include <ctype.h>
#include <assert.h>
#include "proto.h"
static bool errors = FALSE;
static int lineno = 0;
-static const char *nanorc;
+static char *nanorc = NULL;
+#ifdef ENABLE_COLOR
+static syntaxtype *endsyntax = NULL;
+ /* The end of the list of syntaxes. */
+static colortype *endcolor = NULL;
+ /* The end of the color list for the current syntax. */
+#endif
-/* We have an error in some part of the rcfile; put it on stderr and
- make the user hit return to continue starting up nano. */
+/* We have an error in some part of the rcfile. Put it on stderr and
+ * make the user hit return to continue starting up nano. */
void rcfile_error(const char *msg, ...)
{
va_list ap;
fprintf(stderr, "\n");
}
-/* Parse the next word from the string. Returns NULL if we hit EOL. */
+/* Parse the next word from the string. Return points to '\0' if we hit
+ * the end of the line. */
char *parse_next_word(char *ptr)
{
- while (!is_blank_char(*ptr) && *ptr != '\n' && *ptr != '\0')
+ while (!is_blank_char(*ptr) && *ptr != '\0')
ptr++;
if (*ptr == '\0')
- return NULL;
+ return ptr;
- /* Null terminate and advance ptr */
- *ptr++ = 0;
+ /* Null-terminate and advance ptr. */
+ *ptr++ = '\0';
while (is_blank_char(*ptr))
ptr++;
return ptr;
}
-/* The keywords operatingdir, backupdir, fill, tabsize, speller,
- * punct, brackets, quotestr, and whitespace take an argument when set.
- * Among these, operatingdir, backupdir, speller, punct, brackets,
- * quotestr, and whitespace have to allow tabs and spaces in the
- * argument. Thus, if the next word starts with a ", we say it ends
- * with the last " of the line. Otherwise, the word is interpreted as
- * usual. That is so the arguments can contain "s too. */
+/* The keywords operatingdir, backupdir, fill, tabsize, speller, punct,
+ * brackets, quotestr, and whitespace take an argument when set. Among
+ * these, operatingdir, backupdir, speller, punct, brackets, quotestr,
+ * and whitespace have to allow tabs and spaces in the argument. Thus,
+ * if the next word starts with a ", we say it ends with the last " of
+ * the line. Otherwise, the word is interpreted as usual. That is so
+ * the arguments can contain "s too. */
char *parse_argument(char *ptr)
{
const char *ptr_bak = ptr;
ptr++;
if (*ptr == '"')
last_quote = ptr;
- } while (*ptr != '\n' && *ptr != '\0');
+ } while (*ptr != '\0');
if (last_quote == NULL) {
if (*ptr == '\0')
}
#ifdef ENABLE_COLOR
-
-int colortoint(const char *colorname, int *bright)
+int color_to_int(const char *colorname, bool *bright)
{
- int mcolor = 0;
+ int mcolor = -1;
- if (colorname == NULL)
+ if (colorname == NULL) {
+ rcfile_error(N_("Missing color name"));
return -1;
+ }
+
+ assert(bright != NULL);
if (strncasecmp(colorname, "bright", 6) == 0) {
- *bright = 1;
+ *bright = TRUE;
colorname += 6;
}
mcolor = COLOR_MAGENTA;
else if (strcasecmp(colorname, "black") == 0)
mcolor = COLOR_BLACK;
- else {
+ else
rcfile_error(N_("Color %s not understood.\n"
- "Valid colors are \"green\", \"red\", \"blue\", \n"
- "\"white\", \"yellow\", \"cyan\", \"magenta\" and \n"
- "\"black\", with the optional prefix \"bright\" \n"
+ "Valid colors are \"green\", \"red\", \"blue\",\n"
+ "\"white\", \"yellow\", \"cyan\", \"magenta\" and\n"
+ "\"black\", with the optional prefix \"bright\"\n"
"for foreground colors."), colorname);
- mcolor = -1;
- }
+
return mcolor;
}
char *parse_next_regex(char *ptr)
{
- while ((*ptr != '"' || (*(ptr + 1) != ' ' && *(ptr + 1) != '\n'))
- && *ptr != '\n' && *ptr != '\0')
+ assert(ptr != NULL);
+
+ /* Continue until the end of the line, or a " followed by a space, a
+ * blank character, or \0. */
+ while ((*ptr != '"' || (!is_blank_char(*(ptr + 1)) &&
+ *(ptr + 1) != '\0')) && *ptr != '\0')
ptr++;
- if (*ptr == '\0')
+ assert(*ptr == '"' || *ptr == '\0');
+
+ if (*ptr == '\0') {
+ rcfile_error(N_("Regex strings must begin and end with a \" character"));
return NULL;
+ }
/* Null terminate and advance ptr. */
*ptr++ = '\0';
return ptr;
}
-/* Compile the regular expression regex to preg. Returns FALSE on
+/* Compile the regular expression regex to preg. Return FALSE on
* success, or TRUE if the expression is invalid. */
-int nregcomp(regex_t *preg, const char *regex, int eflags)
+bool nregcomp(regex_t *preg, const char *regex, int eflags)
{
int rc = regcomp(preg, regex, REG_EXTENDED | eflags);
void parse_syntax(char *ptr)
{
- syntaxtype *tmpsyntax = NULL;
const char *fileregptr = NULL, *nameptr = NULL;
exttype *endext = NULL;
/* The end of the extensions list for this syntax. */
- while (*ptr == ' ')
- ptr++;
+ assert(ptr != NULL);
- if (*ptr == '\n' || *ptr == '\0')
+ if (*ptr == '\0') {
+ rcfile_error(N_("Missing syntax name"));
return;
+ }
if (*ptr != '"') {
rcfile_error(N_("Regex strings must begin and end with a \" character"));
return;
}
+
ptr++;
nameptr = ptr;
ptr = parse_next_regex(ptr);
- if (ptr == NULL) {
- rcfile_error(N_("Missing syntax name"));
+ if (ptr == NULL)
return;
- }
if (syntaxes == NULL) {
syntaxes = (syntaxtype *)nmalloc(sizeof(syntaxtype));
- tmpsyntax = syntaxes;
- SET(COLOR_SYNTAX);
+ endsyntax = syntaxes;
} else {
- for (tmpsyntax = syntaxes; tmpsyntax->next != NULL;
- tmpsyntax = tmpsyntax->next)
- ;
- tmpsyntax->next = (syntaxtype *)nmalloc(sizeof(syntaxtype));
- tmpsyntax = tmpsyntax->next;
+ endsyntax->next = (syntaxtype *)nmalloc(sizeof(syntaxtype));
+ endsyntax = endsyntax->next;
#ifdef DEBUG
- fprintf(stderr, "Adding new syntax after 1st\n");
+ fprintf(stderr, "Adding new syntax after first one\n");
#endif
}
- tmpsyntax->desc = mallocstrcpy(NULL, nameptr);
- tmpsyntax->color = NULL;
- tmpsyntax->extensions = NULL;
- tmpsyntax->next = NULL;
+ endsyntax->desc = mallocstrcpy(NULL, nameptr);
+ endsyntax->color = NULL;
+ endcolor = NULL;
+ endsyntax->extensions = NULL;
+ endsyntax->next = NULL;
#ifdef DEBUG
- fprintf(stderr, "Starting a new syntax type\n");
- fprintf(stderr, "string val=%s\n", nameptr);
+ fprintf(stderr, "Starting a new syntax type: \"%s\"\n", nameptr);
#endif
- /* Now load in the extensions to their part of the struct */
- while (*ptr != '\n' && *ptr != '\0') {
+ /* Now load the extensions into their part of the struct. */
+ while (*ptr != '\0') {
exttype *newext;
/* The new extension structure. */
- while (*ptr != '"' && *ptr != '\n' && *ptr != '\0')
+ while (*ptr != '"' && *ptr != '\0')
ptr++;
- if (*ptr == '\n' || *ptr == '\0')
+ if (*ptr == '\0')
return;
+
ptr++;
fileregptr = ptr;
ptr = parse_next_regex(ptr);
+ if (ptr == NULL)
+ break;
newext = (exttype *)nmalloc(sizeof(exttype));
- if (nregcomp(&newext->val, fileregptr, REG_NOSUB) != 0)
+ if (nregcomp(&newext->val, fileregptr, REG_NOSUB))
free(newext);
else {
if (endext == NULL)
- tmpsyntax->extensions = newext;
+ endsyntax->extensions = newext;
else
endext->next = newext;
endext = newext;
}
}
-/* Parse the color stuff into the colorstrings array */
+/* Parse the color stuff into the colorstrings array. */
void parse_colors(char *ptr)
{
- int fg, bg, bright = 0;
- int expectend = 0; /* Do we expect an end= line? */
+ int fg, bg;
+ bool bright = FALSE;
char *fgstr;
- colortype *tmpcolor = NULL;
- syntaxtype *tmpsyntax = NULL;
- fgstr = ptr;
- ptr = parse_next_word(ptr);
+ assert(ptr != NULL);
- if (ptr == NULL) {
+ if (*ptr == '\0') {
rcfile_error(N_("Missing color name"));
return;
}
- if (strstr(fgstr, ",")) {
+ fgstr = ptr;
+ ptr = parse_next_word(ptr);
+
+ if (strchr(fgstr, ',') != NULL) {
char *bgcolorname;
strtok(fgstr, ",");
bgcolorname = strtok(NULL, ",");
rcfile_error(N_("Background color %s cannot be bright"), bgcolorname);
return;
}
- bg = colortoint(bgcolorname, &bright);
+
+ bg = color_to_int(bgcolorname, &bright);
} else
bg = -1;
- fg = colortoint(fgstr, &bright);
+ fg = color_to_int(fgstr, &bright);
- /* Don't try and parse screwed up fg colors */
+ /* Don't try to parse screwed-up foreground colors. */
if (fg == -1)
return;
return;
}
- for (tmpsyntax = syntaxes; tmpsyntax->next != NULL;
- tmpsyntax = tmpsyntax->next)
- ;
-
- /* Now the fun part, start adding regexps to individual strings
- in the colorstrings array, woo! */
+ /* Now for the fun part. Start adding regexps to individual strings
+ * in the colorstrings array, woo! */
- while (*ptr != '\0') {
+ while (ptr != NULL && *ptr != '\0') {
colortype *newcolor;
/* The new color structure. */
- int cancelled = 0;
+ bool cancelled = FALSE;
/* The start expression was bad. */
-
- while (*ptr == ' ')
- ptr++;
-
- if (*ptr == '\n' || *ptr == '\0')
- break;
+ bool expectend = FALSE;
+ /* Do we expect an end= line? */
if (strncasecmp(ptr, "start=", 6) == 0) {
ptr += 6;
- expectend = 1;
+ expectend = TRUE;
}
if (*ptr != '"') {
ptr = parse_next_regex(ptr);
continue;
}
+
ptr++;
newcolor = (colortype *)nmalloc(sizeof(colortype));
fgstr = ptr;
ptr = parse_next_regex(ptr);
- if (nregcomp(&newcolor->start, fgstr, 0) != 0) {
+ if (ptr == NULL)
+ break;
+
+ if (nregcomp(&newcolor->start, fgstr, 0)) {
free(newcolor);
- cancelled = 1;
+ cancelled = TRUE;
} else {
newcolor->fg = fg;
newcolor->bg = bg;
newcolor->next = NULL;
newcolor->end = NULL;
- if (tmpsyntax->color == NULL) {
- tmpsyntax->color = newcolor;
+ if (endcolor == NULL) {
+ endsyntax->color = newcolor;
#ifdef DEBUG
- fprintf(stderr, "Starting a new colorstring for fg %d bg %d\n", fg, bg);
+ fprintf(stderr, "Starting a new colorstring for fg %d, bg %d\n", fg, bg);
#endif
} else {
- for (tmpcolor = tmpsyntax->color; tmpcolor->next != NULL;
- tmpcolor = tmpcolor->next)
- ;
#ifdef DEBUG
- fprintf(stderr, "Adding new entry for fg %d bg %d\n", fg, bg);
+ fprintf(stderr, "Adding new entry for fg %d, bg %d\n", fg, bg);
#endif
- tmpcolor->next = newcolor;
+ endcolor->next = newcolor;
}
+ endcolor = newcolor;
}
if (expectend) {
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"));
continue;
}
+
ptr++;
fgstr = ptr;
ptr = parse_next_regex(ptr);
+ if (ptr == NULL)
+ break;
/* If the start regex was invalid, skip past the end regex to
* stay in sync. */
if (cancelled)
continue;
+
newcolor->end = (regex_t *)nmalloc(sizeof(regex_t));
- if (nregcomp(newcolor->end, fgstr, 0) != 0) {
+ if (nregcomp(newcolor->end, fgstr, 0)) {
free(newcolor->end);
newcolor->end = NULL;
}
}
}
}
-
#endif /* ENABLE_COLOR */
-/* Parse the RC file, once it has been opened successfully */
+/* Parse the rcfile, once it has been opened successfully. */
void parse_rcfile(FILE *rcstream)
{
- char *buf, *ptr, *keyword, *option;
- int set = 0, i;
+ char *buf = NULL;
+ ssize_t len;
+ size_t n;
+
+ while ((len = getline(&buf, &n, rcstream)) > 0) {
+ char *ptr, *keyword, *option;
+ int set = 0, i;
+
+ /* Ignore the \n. */
+ buf[len - 1] = '\0';
- buf = charalloc(1024);
- while (fgets(buf, 1023, rcstream) != 0) {
lineno++;
ptr = buf;
while (is_blank_char(*ptr))
ptr++;
- if (*ptr == '\n' || *ptr == '\0')
+ /* If we have a blank line or a comment, skip to the next
+ * line. */
+ if (*ptr == '\0' || *ptr == '#')
continue;
- if (*ptr == '#') {
-#ifdef DEBUG
- fprintf(stderr, "%s: Read a comment\n", "parse_rcfile()");
-#endif
- continue; /* Skip past commented lines */
- }
-
- /* Else skip to the next space */
+ /* Otherwise, skip to the next space. */
keyword = ptr;
ptr = parse_next_word(ptr);
- if (ptr == NULL)
- continue;
- /* Else try to parse the keyword */
+ /* Try to parse the keyword. */
if (strcasecmp(keyword, "set") == 0)
set = 1;
else if (strcasecmp(keyword, "unset") == 0)
parse_syntax(ptr);
else if (strcasecmp(keyword, "color") == 0)
parse_colors(ptr);
-#endif /* ENABLE_COLOR */
- else {
+#endif /* ENABLE_COLOR */
+ else
rcfile_error(N_("Command %s not understood"), keyword);
+
+ if (set == 0)
+ continue;
+
+ if (*ptr == '\0') {
+ rcfile_error(N_("Missing flag"));
continue;
}
option = ptr;
ptr = parse_next_word(ptr);
- /* We don't care if ptr == NULL, as it should if using proper syntax */
- if (set != 0) {
- for (i = 0; rcopts[i].name != NULL; i++) {
- if (strcasecmp(option, rcopts[i].name) == 0) {
+ for (i = 0; rcopts[i].name != NULL; i++) {
+ if (strcasecmp(option, rcopts[i].name) == 0) {
#ifdef DEBUG
- fprintf(stderr, "%s: Parsing option %s\n",
- "parse_rcfile()", rcopts[i].name);
-#endif
- if (set == 1) {
- if (strcasecmp(rcopts[i].name, "tabsize") == 0
-#ifndef DISABLE_OPERATINGDIR
- || strcasecmp(rcopts[i].name, "operatingdir") == 0
-#endif
-#ifndef DISABLE_WRAPJUSTIFY
- || strcasecmp(rcopts[i].name, "fill") == 0
-#endif
-#ifndef NANO_SMALL
- || strcasecmp(rcopts[i].name, "whitespace") == 0
-#endif
-#ifndef DISABLE_JUSTIFY
- || strcasecmp(rcopts[i].name, "punct") == 0
- || strcasecmp(rcopts[i].name, "brackets") == 0
- || strcasecmp(rcopts[i].name, "quotestr") == 0
-#endif
-#ifndef NANO_SMALL
- || strcasecmp(rcopts[i].name, "backupdir") == 0
-#endif
-#ifndef DISABLE_SPELLER
- || strcasecmp(rcopts[i].name, "speller") == 0
-#endif
- ) {
- if (*ptr == '\n' || *ptr == '\0') {
- rcfile_error(N_("Option %s requires an argument"), rcopts[i].name);
- continue;
- }
- option = ptr;
- if (*option == '"')
- option++;
- ptr = parse_argument(ptr);
+ fprintf(stderr, "parse_rcfile(): name = \"%s\"\n", rcopts[i].name);
+#endif
+ if (set == 1) {
+ if (rcopts[i].flag != 0)
+ /* This option has a flag, so it doesn't take an
+ * argument. */
+ SET(rcopts[i].flag);
+ else {
+ /* This option doesn't have a flag, so it takes
+ * an argument. */
+ if (*ptr == '\0') {
+ rcfile_error(N_("Option %s requires an argument"), rcopts[i].name);
+ break;
+ }
+ option = ptr;
+ if (*option == '"')
+ option++;
+ ptr = parse_argument(ptr);
#ifdef DEBUG
- fprintf(stderr, "option = %s\n", option);
+ fprintf(stderr, "option = \"%s\"\n", option);
#endif
#ifndef DISABLE_OPERATINGDIR
- if (strcasecmp(rcopts[i].name, "operatingdir") == 0)
- operating_dir = mallocstrcpy(NULL, option);
- else
+ if (strcasecmp(rcopts[i].name, "operatingdir") == 0)
+ operating_dir = mallocstrcpy(NULL, option);
+ else
#endif
#ifndef DISABLE_WRAPJUSTIFY
- if (strcasecmp(rcopts[i].name, "fill") == 0) {
- if (!parse_num(option, &wrap_at)) {
- rcfile_error(N_("Requested fill size %s invalid"), option);
- wrap_at = -CHARS_FROM_EOL;
- }
- } else
+ if (strcasecmp(rcopts[i].name, "fill") == 0) {
+ if (!parse_num(option, &wrap_at)) {
+ rcfile_error(N_("Requested fill size %s invalid"), option);
+ wrap_at = -CHARS_FROM_EOL;
+ }
+ } else
#endif
#ifndef NANO_SMALL
- if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
- size_t ws_len;
- 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"));
- free(whitespace);
- whitespace = NULL;
- }
- } else
+ if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
+ size_t ws_len;
+ 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"));
+ free(whitespace);
+ whitespace = NULL;
+ }
+ } else
#endif
#ifndef DISABLE_JUSTIFY
- 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"));
- 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"));
- free(brackets);
- brackets = NULL;
- }
- } else if (strcasecmp(rcopts[i].name, "quotestr") == 0)
- quotestr = mallocstrcpy(NULL, option);
- else
+ 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"));
+ 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"));
+ free(brackets);
+ brackets = NULL;
+ }
+ } else if (strcasecmp(rcopts[i].name, "quotestr") == 0)
+ quotestr = mallocstrcpy(NULL, option);
+ else
#endif
#ifndef NANO_SMALL
- if (strcasecmp(rcopts[i].name, "backupdir") == 0)
- backup_dir = mallocstrcpy(NULL, option);
- else
+ if (strcasecmp(rcopts[i].name, "backupdir") == 0)
+ backup_dir = mallocstrcpy(NULL, option);
+ else
#endif
#ifndef DISABLE_SPELLER
- if (strcasecmp(rcopts[i].name, "speller") == 0)
- alt_speller = mallocstrcpy(NULL, option);
- else
-#endif
- if (strcasecmp(rcopts[i].name, "tabsize") == 0) {
- if (!parse_num(option, &tabsize) || tabsize <= 0) {
- rcfile_error(N_("Requested tab size %s invalid"), option);
- tabsize = -1;
- }
+ if (strcasecmp(rcopts[i].name, "speller") == 0)
+ alt_speller = mallocstrcpy(NULL, option);
+ else
+#endif
+ if (strcasecmp(rcopts[i].name, "tabsize") == 0) {
+ if (!parse_num(option, &tabsize) || tabsize <= 0) {
+ rcfile_error(N_("Requested tab size %s invalid"), option);
+ tabsize = -1;
}
} else
- SET(rcopts[i].flag);
-#ifdef DEBUG
- fprintf(stderr, "set flag %ld!\n",
- rcopts[i].flag);
-#endif
- } else {
- UNSET(rcopts[i].flag);
+ assert(FALSE);
+ }
#ifdef DEBUG
- fprintf(stderr, "unset flag %ld!\n",
- rcopts[i].flag);
+ fprintf(stderr, "flag = %d\n", rcopts[i].flag);
#endif
- }
- }
+ } else if (rcopts[i].flag != 0)
+ UNSET(rcopts[i].flag);
+ else
+ rcfile_error(N_("Cannot unset flag %s"), rcopts[i].name);
+ break;
}
}
+ if (rcopts[i].name == NULL)
+ rcfile_error(N_("Unknown flag %s"), option);
}
+
free(buf);
+ fclose(rcstream);
+ lineno = 0;
if (errors) {
errors = FALSE;
#ifdef SYSCONFDIR
assert(sizeof(SYSCONFDIR) == strlen(SYSCONFDIR) + 1);
- nanorc = SYSCONFDIR "/nanorc";
- /* Try to open system nanorc */
+ nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc");
+ /* Try to open the system-wide nanorc. */
rcstream = fopen(nanorc, "r");
- if (rcstream != NULL) {
- /* Parse it! */
+ if (rcstream != NULL)
parse_rcfile(rcstream);
- fclose(rcstream);
- }
#endif
- lineno = 0;
+#if defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
+ /* We've already read SYSCONFDIR/nanorc, if it's there. If we're
+ * root and --disable-wrapping-as-root is used, turn wrapping
+ * off now. */
+ if (geteuid() == NANO_ROOT_UID)
+ SET(NO_WRAP);
+#endif
get_homedir();
- if (homedir == NULL) {
+ if (homedir == NULL)
rcfile_error(N_("I can't find my home directory! Wah!"));
- SET(NO_RCFILE);
- } else {
- size_t homelen = strlen(homedir);
- char *nanorcf = charalloc(homelen + 9);
-
- nanorc = nanorcf;
- strcpy(nanorcf, homedir);
- strcpy(nanorcf + homelen, "/.nanorc");
-
-#if defined(DISABLE_ROOTWRAP) && !defined(DISABLE_WRAPPING)
- /* If we've already read SYSCONFDIR/nanorc (if it's there), we're
- root, and --disable-wrapping-as-root is used, turn wrapping off */
- if (geteuid() == NANO_ROOT_UID)
- SET(NO_WRAP);
-#endif
+ else {
+ nanorc = charealloc(nanorc, strlen(homedir) + 9);
+ sprintf(nanorc, "%s/.nanorc", homedir);
rcstream = fopen(nanorc, "r");
+
if (rcstream == NULL) {
- /* Don't complain about the file not existing */
- if (errno != ENOENT) {
+ /* Don't complain about the file's not existing. */
+ if (errno != ENOENT)
rcfile_error(N_("Error reading %s: %s"), nanorc, strerror(errno));
- SET(NO_RCFILE);
- }
- } else {
+ } else
parse_rcfile(rcstream);
- fclose(rcstream);
- }
- free(nanorcf);
}
- lineno = 0;
+ free(nanorc);
+ nanorc = NULL;
#ifdef ENABLE_COLOR
set_colorpairs();