2001-04-18 04:28:54 +00:00
|
|
|
|
/* $Id$ */
|
|
|
|
|
/**************************************************************************
|
2001-05-05 15:02:27 +00:00
|
|
|
|
* rcfile.c *
|
2001-04-18 04:28:54 +00:00
|
|
|
|
* *
|
2005-01-12 19:29:44 +00:00
|
|
|
|
* Copyright (C) 1999-2005 Chris Allegretta *
|
2001-04-18 04:28:54 +00:00
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
2001-10-24 11:33:54 +00:00
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option) *
|
2001-04-18 04:28:54 +00:00
|
|
|
|
* any later version. *
|
|
|
|
|
* *
|
2005-05-15 19:57:17 +00:00
|
|
|
|
* This program is distributed in the hope that it will be useful, but *
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
|
|
|
* General Public License for more details. *
|
2001-04-18 04:28:54 +00:00
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
|
* along with this program; if not, write to the Free Software *
|
2005-05-15 19:57:17 +00:00
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
|
|
|
|
|
* 02110-1301, USA. *
|
2001-04-18 04:28:54 +00:00
|
|
|
|
* *
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2004-11-17 23:17:05 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
2002-09-13 18:14:04 +00:00
|
|
|
|
|
2001-04-18 04:28:54 +00:00
|
|
|
|
#include <stdlib.h>
|
2002-01-22 20:09:20 +00:00
|
|
|
|
#include <stdarg.h>
|
2001-04-18 04:28:54 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
2002-05-11 03:04:44 +00:00
|
|
|
|
#include <unistd.h>
|
2004-05-13 17:19:54 +00:00
|
|
|
|
#include <ctype.h>
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#include <assert.h>
|
2001-04-18 04:28:54 +00:00
|
|
|
|
#include "proto.h"
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_NANORC
|
|
|
|
|
|
2002-09-13 18:14:04 +00:00
|
|
|
|
const static rcoption rcopts[] = {
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
2002-01-19 16:52:34 +00:00
|
|
|
|
{"autoindent", AUTOINDENT},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
{"backup", BACKUP_FILE},
|
2004-02-28 16:24:31 +00:00
|
|
|
|
{"backupdir", 0},
|
2004-05-29 16:38:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
|
{"brackets", 0},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif
|
|
|
|
|
{"const", CONSTUPDATE},
|
|
|
|
|
#ifndef NANO_SMALL
|
2002-01-19 16:52:34 +00:00
|
|
|
|
{"cut", CUT_TO_END},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
2002-06-28 22:45:14 +00:00
|
|
|
|
{"fill", 0},
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#endif
|
2003-09-06 21:44:37 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
|
{"historylog", HISTORYLOG},
|
|
|
|
|
#endif
|
2003-10-03 20:26:25 +00:00
|
|
|
|
#ifndef DISABLE_MOUSE
|
2002-01-19 16:52:34 +00:00
|
|
|
|
{"mouse", USE_MOUSE},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
|
|
|
|
{"multibuffer", MULTIBUFFER},
|
|
|
|
|
#endif
|
2005-01-17 05:06:55 +00:00
|
|
|
|
{"morespace", MORE_SPACE},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
|
{"noconvert", NO_CONVERT},
|
|
|
|
|
#endif
|
2002-12-22 16:30:00 +00:00
|
|
|
|
{"nofollow", NOFOLLOW_SYMLINKS},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
{"nohelp", NO_HELP},
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#ifndef DISABLE_WRAPPING
|
2002-06-28 22:45:14 +00:00
|
|
|
|
{"nowrap", NO_WRAP},
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#endif
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
2002-01-19 16:52:34 +00:00
|
|
|
|
{"operatingdir", 0},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif
|
2003-01-13 01:35:15 +00:00
|
|
|
|
{"preserve", PRESERVE},
|
2002-12-22 16:30:00 +00:00
|
|
|
|
#ifndef DISABLE_JUSTIFY
|
2004-05-29 16:38:57 +00:00
|
|
|
|
{"punct", 0},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
{"quotestr", 0},
|
|
|
|
|
#endif
|
2004-04-21 22:25:16 +00:00
|
|
|
|
{"rebinddelete", REBIND_DELETE},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
2004-05-22 20:15:20 +00:00
|
|
|
|
{"smarthome", SMART_HOME},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
{"smooth", SMOOTHSCROLL},
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DISABLE_SPELLER
|
2002-01-19 16:52:34 +00:00
|
|
|
|
{"speller", 0},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif
|
|
|
|
|
{"suspend", SUSPEND},
|
|
|
|
|
{"tabsize", 0},
|
2004-07-03 03:09:12 +00:00
|
|
|
|
{"tempfile", TEMP_FILE},
|
2002-01-19 16:52:34 +00:00
|
|
|
|
{"view", VIEW_MODE},
|
2004-05-29 16:25:30 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
|
{"whitespace", 0},
|
|
|
|
|
#endif
|
2002-09-13 18:14:04 +00:00
|
|
|
|
{NULL, 0}
|
2002-01-19 16:52:34 +00:00
|
|
|
|
};
|
2001-04-18 04:28:54 +00:00
|
|
|
|
|
2004-07-30 22:52:44 +00:00
|
|
|
|
static bool errors = FALSE;
|
2002-01-18 21:54:35 +00:00
|
|
|
|
static int lineno = 0;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
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
|
2002-01-18 21:54:35 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* 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. */
|
2002-08-21 16:10:37 +00:00
|
|
|
|
void rcfile_error(const char *msg, ...)
|
2001-04-18 04:28:54 +00:00
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2004-07-30 22:52:44 +00:00
|
|
|
|
if (lineno > 0) {
|
|
|
|
|
errors = TRUE;
|
2002-03-29 19:41:57 +00:00
|
|
|
|
fprintf(stderr, _("Error in %s on line %d: "), nanorc, lineno);
|
2004-07-30 22:52:44 +00:00
|
|
|
|
}
|
2002-03-29 19:41:57 +00:00
|
|
|
|
|
2001-04-18 04:28:54 +00:00
|
|
|
|
va_start(ap, msg);
|
2004-07-12 03:10:30 +00:00
|
|
|
|
vfprintf(stderr, _(msg), ap);
|
2001-04-18 04:28:54 +00:00
|
|
|
|
va_end(ap);
|
2004-08-11 05:13:08 +00:00
|
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2001-04-18 04:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Parse the next word from the string. Return points to '\0' if we hit
|
|
|
|
|
* the end of the line. */
|
2002-08-21 16:10:37 +00:00
|
|
|
|
char *parse_next_word(char *ptr)
|
2001-04-18 04:28:54 +00:00
|
|
|
|
{
|
2005-03-10 20:55:11 +00:00
|
|
|
|
while (!is_blank_char(*ptr) && *ptr != '\0')
|
2002-01-19 16:52:34 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
|
|
if (*ptr == '\0')
|
2005-03-10 20:55:11 +00:00
|
|
|
|
return ptr;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Null-terminate and advance ptr. */
|
|
|
|
|
*ptr++ = '\0';
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
|
while (is_blank_char(*ptr))
|
2002-01-19 16:52:34 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
2002-01-18 21:54:35 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* 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. */
|
2002-08-21 16:10:37 +00:00
|
|
|
|
char *parse_argument(char *ptr)
|
|
|
|
|
{
|
2002-07-19 01:08:59 +00:00
|
|
|
|
const char *ptr_bak = ptr;
|
|
|
|
|
char *last_quote = NULL;
|
|
|
|
|
|
|
|
|
|
assert(ptr != NULL);
|
|
|
|
|
|
|
|
|
|
if (*ptr != '"')
|
|
|
|
|
return parse_next_word(ptr);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
ptr++;
|
|
|
|
|
if (*ptr == '"')
|
|
|
|
|
last_quote = ptr;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
} while (*ptr != '\0');
|
2002-07-19 01:08:59 +00:00
|
|
|
|
|
|
|
|
|
if (last_quote == NULL) {
|
|
|
|
|
if (*ptr == '\0')
|
|
|
|
|
ptr = NULL;
|
|
|
|
|
else
|
|
|
|
|
*ptr++ = '\0';
|
2004-08-11 05:13:08 +00:00
|
|
|
|
rcfile_error(N_("Argument %s has unterminated \""), ptr_bak);
|
2002-07-19 01:08:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
*last_quote = '\0';
|
|
|
|
|
ptr = last_quote + 1;
|
|
|
|
|
}
|
|
|
|
|
if (ptr != NULL)
|
2005-01-12 03:25:57 +00:00
|
|
|
|
while (is_blank_char(*ptr))
|
2002-07-19 01:08:59 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
2005-03-10 20:55:11 +00:00
|
|
|
|
int color_to_int(const char *colorname, bool *bright)
|
2001-11-29 02:42:27 +00:00
|
|
|
|
{
|
2005-03-10 20:55:11 +00:00
|
|
|
|
int mcolor = -1;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (colorname == NULL) {
|
|
|
|
|
rcfile_error(N_("Missing color name"));
|
2001-11-29 02:42:27 +00:00
|
|
|
|
return -1;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(bright != NULL);
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2004-07-31 14:10:23 +00:00
|
|
|
|
if (strncasecmp(colorname, "bright", 6) == 0) {
|
2005-03-10 20:55:11 +00:00
|
|
|
|
*bright = TRUE;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
colorname += 6;
|
|
|
|
|
}
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
2004-07-31 14:10:23 +00:00
|
|
|
|
if (strcasecmp(colorname, "green") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_GREEN;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(colorname, "red") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_RED;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(colorname, "blue") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_BLUE;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(colorname, "white") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_WHITE;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(colorname, "yellow") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_YELLOW;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(colorname, "cyan") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_CYAN;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(colorname, "magenta") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_MAGENTA;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(colorname, "black") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
mcolor = COLOR_BLACK;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
else
|
2004-07-12 03:10:30 +00:00
|
|
|
|
rcfile_error(N_("Color %s not understood.\n"
|
2005-03-10 20:55:11 +00:00
|
|
|
|
"Valid colors are \"green\", \"red\", \"blue\",\n"
|
|
|
|
|
"\"white\", \"yellow\", \"cyan\", \"magenta\" and\n"
|
|
|
|
|
"\"black\", with the optional prefix \"bright\"\n"
|
2004-08-11 05:13:08 +00:00
|
|
|
|
"for foreground colors."), colorname);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2001-11-29 02:42:27 +00:00
|
|
|
|
return mcolor;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-06 20:35:28 +00:00
|
|
|
|
char *parse_next_regex(char *ptr)
|
|
|
|
|
{
|
2005-03-10 20:55:11 +00:00
|
|
|
|
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')
|
2002-09-06 20:35:28 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
assert(*ptr == '"' || *ptr == '\0');
|
|
|
|
|
|
|
|
|
|
if (*ptr == '\0') {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Regex strings must begin and end with a \" character"));
|
2002-09-06 20:35:28 +00:00
|
|
|
|
return NULL;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
}
|
2002-09-06 20:35:28 +00:00
|
|
|
|
|
2004-01-09 23:04:55 +00:00
|
|
|
|
/* Null terminate and advance ptr. */
|
2002-09-06 20:35:28 +00:00
|
|
|
|
*ptr++ = '\0';
|
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
|
while (is_blank_char(*ptr))
|
2002-09-06 20:35:28 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Compile the regular expression regex to preg. Return FALSE on
|
2004-07-03 03:09:12 +00:00
|
|
|
|
* success, or TRUE if the expression is invalid. */
|
2005-03-10 20:55:11 +00:00
|
|
|
|
bool nregcomp(regex_t *preg, const char *regex, int eflags)
|
2003-02-03 02:56:44 +00:00
|
|
|
|
{
|
2004-07-03 03:09:12 +00:00
|
|
|
|
int rc = regcomp(preg, regex, REG_EXTENDED | eflags);
|
2003-02-03 02:56:44 +00:00
|
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
|
size_t len = regerror(rc, preg, NULL, 0);
|
|
|
|
|
char *str = charalloc(len);
|
|
|
|
|
|
|
|
|
|
regerror(rc, preg, str, len);
|
2004-08-11 05:13:08 +00:00
|
|
|
|
rcfile_error(N_("Bad regex \"%s\": %s"), regex, str);
|
2003-02-03 02:56:44 +00:00
|
|
|
|
free(str);
|
|
|
|
|
}
|
2005-03-04 15:09:55 +00:00
|
|
|
|
|
|
|
|
|
return (rc != 0);
|
2003-02-03 02:56:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-21 16:10:37 +00:00
|
|
|
|
void parse_syntax(char *ptr)
|
2002-05-04 03:47:33 +00:00
|
|
|
|
{
|
2002-07-19 01:08:59 +00:00
|
|
|
|
const char *fileregptr = NULL, *nameptr = NULL;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
exttype *endext = NULL;
|
|
|
|
|
/* The end of the extensions list for this syntax. */
|
2002-05-04 03:47:33 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
assert(ptr != NULL);
|
2002-05-04 03:47:33 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (*ptr == '\0') {
|
|
|
|
|
rcfile_error(N_("Missing syntax name"));
|
2002-05-04 03:47:33 +00:00
|
|
|
|
return;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
}
|
2002-05-04 03:47:33 +00:00
|
|
|
|
|
|
|
|
|
if (*ptr != '"') {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Regex strings must begin and end with a \" character"));
|
2002-05-04 04:23:30 +00:00
|
|
|
|
return;
|
2002-05-04 03:47:33 +00:00
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2002-05-04 03:47:33 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
|
|
nameptr = ptr;
|
|
|
|
|
ptr = parse_next_regex(ptr);
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (ptr == NULL)
|
2002-05-04 04:23:30 +00:00
|
|
|
|
return;
|
2002-05-04 03:47:33 +00:00
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
|
if (syntaxes == NULL) {
|
|
|
|
|
syntaxes = (syntaxtype *)nmalloc(sizeof(syntaxtype));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
endsyntax = syntaxes;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
} else {
|
2005-03-10 20:55:11 +00:00
|
|
|
|
endsyntax->next = (syntaxtype *)nmalloc(sizeof(syntaxtype));
|
|
|
|
|
endsyntax = endsyntax->next;
|
2002-05-04 03:47:33 +00:00
|
|
|
|
#ifdef DEBUG
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fprintf(stderr, "Adding new syntax after first one\n");
|
2002-05-04 03:47:33 +00:00
|
|
|
|
#endif
|
2002-07-19 01:08:59 +00:00
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
endsyntax->desc = mallocstrcpy(NULL, nameptr);
|
|
|
|
|
endsyntax->color = NULL;
|
|
|
|
|
endcolor = NULL;
|
|
|
|
|
endsyntax->extensions = NULL;
|
|
|
|
|
endsyntax->next = NULL;
|
2002-05-04 03:47:33 +00:00
|
|
|
|
#ifdef DEBUG
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fprintf(stderr, "Starting a new syntax type: \"%s\"\n", nameptr);
|
2002-05-04 03:47:33 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Now load the extensions into their part of the struct. */
|
|
|
|
|
while (*ptr != '\0') {
|
2003-02-03 02:56:44 +00:00
|
|
|
|
exttype *newext;
|
|
|
|
|
/* The new extension structure. */
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
while (*ptr != '"' && *ptr != '\0')
|
2002-05-04 03:47:33 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (*ptr == '\0')
|
2002-05-04 03:47:33 +00:00
|
|
|
|
return;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2002-05-04 03:47:33 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
|
|
fileregptr = ptr;
|
|
|
|
|
ptr = parse_next_regex(ptr);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
break;
|
2002-05-04 03:47:33 +00:00
|
|
|
|
|
2003-02-03 02:56:44 +00:00
|
|
|
|
newext = (exttype *)nmalloc(sizeof(exttype));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (nregcomp(&newext->val, fileregptr, REG_NOSUB))
|
2003-02-03 02:56:44 +00:00
|
|
|
|
free(newext);
|
|
|
|
|
else {
|
|
|
|
|
if (endext == NULL)
|
2005-03-10 20:55:11 +00:00
|
|
|
|
endsyntax->extensions = newext;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
else
|
|
|
|
|
endext->next = newext;
|
|
|
|
|
endext = newext;
|
|
|
|
|
endext->next = NULL;
|
2002-05-04 03:47:33 +00:00
|
|
|
|
}
|
2002-06-28 22:45:14 +00:00
|
|
|
|
}
|
2002-05-04 03:47:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Parse the color stuff into the colorstrings array. */
|
2002-08-21 16:10:37 +00:00
|
|
|
|
void parse_colors(char *ptr)
|
2001-11-29 02:42:27 +00:00
|
|
|
|
{
|
2005-03-10 20:55:11 +00:00
|
|
|
|
int fg, bg;
|
|
|
|
|
bool bright = FALSE;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
char *fgstr;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
assert(ptr != NULL);
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (*ptr == '\0') {
|
2004-08-11 05:13:08 +00:00
|
|
|
|
rcfile_error(N_("Missing color name"));
|
2002-05-04 04:23:30 +00:00
|
|
|
|
return;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fgstr = ptr;
|
|
|
|
|
ptr = parse_next_word(ptr);
|
|
|
|
|
|
|
|
|
|
if (strchr(fgstr, ',') != NULL) {
|
2003-09-06 05:09:32 +00:00
|
|
|
|
char *bgcolorname;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
strtok(fgstr, ",");
|
2003-09-06 05:09:32 +00:00
|
|
|
|
bgcolorname = strtok(NULL, ",");
|
2004-07-31 14:10:23 +00:00
|
|
|
|
if (strncasecmp(bgcolorname, "bright", 6) == 0) {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Background color %s cannot be bright"),
|
|
|
|
|
bgcolorname);
|
2003-09-06 05:09:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
bg = color_to_int(bgcolorname, &bright);
|
2001-11-29 02:42:27 +00:00
|
|
|
|
} else
|
2002-07-19 01:08:59 +00:00
|
|
|
|
bg = -1;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fg = color_to_int(fgstr, &bright);
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Don't try to parse screwed-up foreground colors. */
|
2003-02-07 00:19:05 +00:00
|
|
|
|
if (fg == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-05-04 03:47:33 +00:00
|
|
|
|
if (syntaxes == NULL) {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Cannot add a color directive without a syntax line"));
|
2002-05-04 04:23:30 +00:00
|
|
|
|
return;
|
2002-05-04 03:47:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-03 19:10:47 +00:00
|
|
|
|
/* Now for the fun part. Start adding regexes to individual strings
|
2005-03-10 20:55:11 +00:00
|
|
|
|
* in the colorstrings array, woo! */
|
|
|
|
|
while (ptr != NULL && *ptr != '\0') {
|
2003-02-03 02:56:44 +00:00
|
|
|
|
colortype *newcolor;
|
|
|
|
|
/* The new color structure. */
|
2005-03-10 20:55:11 +00:00
|
|
|
|
bool cancelled = FALSE;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
/* The start expression was bad. */
|
2005-03-10 20:55:11 +00:00
|
|
|
|
bool expectend = FALSE;
|
|
|
|
|
/* Do we expect an end= line? */
|
2002-01-19 16:52:34 +00:00
|
|
|
|
|
2004-07-31 14:10:23 +00:00
|
|
|
|
if (strncasecmp(ptr, "start=", 6) == 0) {
|
2002-01-19 16:52:34 +00:00
|
|
|
|
ptr += 6;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
expectend = TRUE;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*ptr != '"') {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Regex strings must begin and end with a \" character"));
|
2002-09-18 00:28:57 +00:00
|
|
|
|
ptr = parse_next_regex(ptr);
|
2002-01-19 16:52:34 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2002-01-19 16:52:34 +00:00
|
|
|
|
ptr++;
|
2002-01-18 21:54:35 +00:00
|
|
|
|
|
2003-02-03 02:56:44 +00:00
|
|
|
|
newcolor = (colortype *)nmalloc(sizeof(colortype));
|
|
|
|
|
fgstr = ptr;
|
|
|
|
|
ptr = parse_next_regex(ptr);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (nregcomp(&newcolor->start, fgstr, 0)) {
|
2003-02-03 02:56:44 +00:00
|
|
|
|
free(newcolor);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
cancelled = TRUE;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
} else {
|
2003-02-03 02:56:44 +00:00
|
|
|
|
newcolor->fg = fg;
|
|
|
|
|
newcolor->bg = bg;
|
|
|
|
|
newcolor->bright = bright;
|
|
|
|
|
newcolor->next = NULL;
|
|
|
|
|
newcolor->end = NULL;
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (endcolor == NULL) {
|
|
|
|
|
endsyntax->color = newcolor;
|
2001-11-29 03:49:09 +00:00
|
|
|
|
#ifdef DEBUG
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fprintf(stderr, "Starting a new colorstring for fg %d, bg %d\n", fg, bg);
|
2001-11-29 03:49:09 +00:00
|
|
|
|
#endif
|
2003-02-03 02:56:44 +00:00
|
|
|
|
} else {
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#ifdef DEBUG
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fprintf(stderr, "Adding new entry for fg %d, bg %d\n", fg, bg);
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#endif
|
2005-03-10 20:55:11 +00:00
|
|
|
|
endcolor->next = newcolor;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
endcolor = newcolor;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
|
|
2003-02-03 02:56:44 +00:00
|
|
|
|
if (expectend) {
|
2004-07-31 14:10:23 +00:00
|
|
|
|
if (ptr == NULL || strncasecmp(ptr, "end=", 4) != 0) {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("\"start=\" requires a corresponding \"end=\""));
|
2002-01-19 16:52:34 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ptr += 4;
|
|
|
|
|
if (*ptr != '"') {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Regex strings must begin and end with a \" character"));
|
2002-01-19 16:52:34 +00:00
|
|
|
|
continue;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2001-11-29 02:42:27 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
2003-02-03 02:56:44 +00:00
|
|
|
|
fgstr = ptr;
|
2002-01-19 16:52:34 +00:00
|
|
|
|
ptr = parse_next_regex(ptr);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
break;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
|
|
|
|
|
/* If the start regex was invalid, skip past the end regex to
|
|
|
|
|
* stay in sync. */
|
|
|
|
|
if (cancelled)
|
|
|
|
|
continue;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2003-02-03 02:56:44 +00:00
|
|
|
|
newcolor->end = (regex_t *)nmalloc(sizeof(regex_t));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (nregcomp(newcolor->end, fgstr, 0)) {
|
2003-02-03 02:56:44 +00:00
|
|
|
|
free(newcolor->end);
|
|
|
|
|
newcolor->end = NULL;
|
|
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
|
}
|
2002-01-19 16:52:34 +00:00
|
|
|
|
}
|
2001-11-29 02:42:27 +00:00
|
|
|
|
}
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Parse the rcfile, once it has been opened successfully. */
|
2002-08-21 16:10:37 +00:00
|
|
|
|
void parse_rcfile(FILE *rcstream)
|
2001-04-18 04:28:54 +00:00
|
|
|
|
{
|
2005-03-10 20:55:11 +00:00
|
|
|
|
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';
|
2001-04-18 04:28:54 +00:00
|
|
|
|
|
|
|
|
|
lineno++;
|
|
|
|
|
ptr = buf;
|
2005-01-12 03:25:57 +00:00
|
|
|
|
while (is_blank_char(*ptr))
|
2001-04-18 04:28:54 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* If we have a blank line or a comment, skip to the next
|
|
|
|
|
* line. */
|
|
|
|
|
if (*ptr == '\0' || *ptr == '#')
|
2001-04-18 04:28:54 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Otherwise, skip to the next space. */
|
2001-04-18 04:28:54 +00:00
|
|
|
|
keyword = ptr;
|
|
|
|
|
ptr = parse_next_word(ptr);
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Try to parse the keyword. */
|
2004-07-31 14:10:23 +00:00
|
|
|
|
if (strcasecmp(keyword, "set") == 0)
|
2001-04-18 04:28:54 +00:00
|
|
|
|
set = 1;
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(keyword, "unset") == 0)
|
2001-04-18 04:28:54 +00:00
|
|
|
|
set = -1;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(keyword, "syntax") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
parse_syntax(ptr);
|
2004-07-31 14:10:23 +00:00
|
|
|
|
else if (strcasecmp(keyword, "color") == 0)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
parse_colors(ptr);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
#endif /* ENABLE_COLOR */
|
|
|
|
|
else
|
2004-08-11 05:13:08 +00:00
|
|
|
|
rcfile_error(N_("Command %s not understood"), keyword);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
|
|
|
|
if (set == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (*ptr == '\0') {
|
|
|
|
|
rcfile_error(N_("Missing flag"));
|
2001-04-18 04:28:54 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
option = ptr;
|
|
|
|
|
ptr = parse_next_word(ptr);
|
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
for (i = 0; rcopts[i].name != NULL; i++) {
|
|
|
|
|
if (strcasecmp(option, rcopts[i].name) == 0) {
|
2001-04-18 04:28:54 +00:00
|
|
|
|
#ifdef DEBUG
|
2005-03-10 20:55:11 +00:00
|
|
|
|
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
|
|
|
|
|
*<EFBFBD>an argument. */
|
|
|
|
|
if (*ptr == '\0') {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Option %s requires an argument"),
|
|
|
|
|
rcopts[i].name);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
option = ptr;
|
|
|
|
|
if (*option == '"')
|
|
|
|
|
option++;
|
|
|
|
|
ptr = parse_argument(ptr);
|
2005-06-08 19:50:02 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure option is a valid multibyte
|
|
|
|
|
* string. */
|
2005-03-14 18:47:21 +00:00
|
|
|
|
option = make_mbstring(option);
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#ifdef DEBUG
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fprintf(stderr, "option = \"%s\"\n", option);
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifndef DISABLE_OPERATINGDIR
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (strcasecmp(rcopts[i].name, "operatingdir") == 0)
|
2005-03-14 18:47:21 +00:00
|
|
|
|
operating_dir = option;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
else
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#endif
|
2001-05-21 12:56:25 +00:00
|
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (strcasecmp(rcopts[i].name, "fill") == 0) {
|
|
|
|
|
if (!parse_num(option, &wrap_at)) {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Requested fill size %s invalid"),
|
|
|
|
|
option);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
wrap_at = -CHARS_FROM_EOL;
|
2005-03-14 18:47:21 +00:00
|
|
|
|
} else
|
|
|
|
|
free(option);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
} else
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#endif
|
2004-05-29 16:47:52 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
|
2005-03-14 18:47:21 +00:00
|
|
|
|
whitespace = option;
|
2005-03-10 22:52:21 +00:00
|
|
|
|
if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Two single-column characters required"));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
free(whitespace);
|
|
|
|
|
whitespace = NULL;
|
2005-03-10 22:52:21 +00:00
|
|
|
|
} else {
|
|
|
|
|
whitespace_len[0] =
|
|
|
|
|
parse_mbchar(whitespace, NULL,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
whitespace_len[1] =
|
|
|
|
|
parse_mbchar(whitespace +
|
|
|
|
|
whitespace_len[0], NULL,
|
|
|
|
|
NULL, NULL);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
}
|
|
|
|
|
} else
|
2004-05-29 16:47:52 +00:00
|
|
|
|
#endif
|
2002-03-03 22:52:52 +00:00
|
|
|
|
#ifndef DISABLE_JUSTIFY
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (strcasecmp(rcopts[i].name, "punct") == 0) {
|
2005-03-14 18:47:21 +00:00
|
|
|
|
punct = option;
|
2005-03-14 17:47:17 +00:00
|
|
|
|
if (strchr(punct, '\t') != NULL ||
|
|
|
|
|
strchr(punct, ' ') != NULL) {
|
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Non-tab and non-space characters required"));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
free(punct);
|
|
|
|
|
punct = NULL;
|
|
|
|
|
}
|
2005-03-14 17:47:17 +00:00
|
|
|
|
} else if (strcasecmp(rcopts[i].name,
|
|
|
|
|
"brackets") == 0) {
|
2005-03-14 18:47:21 +00:00
|
|
|
|
brackets = option;
|
2005-03-14 17:47:17 +00:00
|
|
|
|
if (strchr(brackets, '\t') != NULL ||
|
|
|
|
|
strchr(brackets, ' ') != NULL) {
|
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Non-tab and non-space characters required"));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
free(brackets);
|
|
|
|
|
brackets = NULL;
|
|
|
|
|
}
|
2005-03-14 17:47:17 +00:00
|
|
|
|
} else if (strcasecmp(rcopts[i].name,
|
|
|
|
|
"quotestr") == 0)
|
2005-03-14 18:47:21 +00:00
|
|
|
|
quotestr = option;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
else
|
2002-03-03 22:52:52 +00:00
|
|
|
|
#endif
|
2004-02-28 16:24:31 +00:00
|
|
|
|
#ifndef NANO_SMALL
|
2005-03-14 17:47:17 +00:00
|
|
|
|
if (strcasecmp(rcopts[i].name,
|
|
|
|
|
"backupdir") == 0)
|
2005-03-14 18:47:21 +00:00
|
|
|
|
backup_dir = option;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
else
|
2004-02-28 16:24:31 +00:00
|
|
|
|
#endif
|
2001-05-21 12:56:25 +00:00
|
|
|
|
#ifndef DISABLE_SPELLER
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (strcasecmp(rcopts[i].name, "speller") == 0)
|
2005-03-14 18:47:21 +00:00
|
|
|
|
alt_speller = option;
|
2005-03-10 20:55:11 +00:00
|
|
|
|
else
|
|
|
|
|
#endif
|
2005-03-14 17:47:17 +00:00
|
|
|
|
if (strcasecmp(rcopts[i].name,
|
|
|
|
|
"tabsize") == 0) {
|
|
|
|
|
if (!parse_num(option, &tabsize) ||
|
|
|
|
|
tabsize <= 0) {
|
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Requested tab size %s invalid"),
|
|
|
|
|
option);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
tabsize = -1;
|
2005-03-14 18:47:21 +00:00
|
|
|
|
} else
|
|
|
|
|
free(option);
|
2002-01-19 16:52:34 +00:00
|
|
|
|
} else
|
2005-03-10 20:55:11 +00:00
|
|
|
|
assert(FALSE);
|
|
|
|
|
}
|
2001-04-18 04:28:54 +00:00
|
|
|
|
#ifdef DEBUG
|
2005-03-27 01:34:40 +00:00
|
|
|
|
fprintf(stderr, "flag = %ld\n", rcopts[i].flag);
|
2001-04-18 04:28:54 +00:00
|
|
|
|
#endif
|
2005-03-10 20:55:11 +00:00
|
|
|
|
} else if (rcopts[i].flag != 0)
|
|
|
|
|
UNSET(rcopts[i].flag);
|
|
|
|
|
else
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(N_("Cannot unset flag %s"),
|
|
|
|
|
rcopts[i].name);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
break;
|
2001-04-18 04:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (rcopts[i].name == NULL)
|
|
|
|
|
rcfile_error(N_("Unknown flag %s"), option);
|
2001-04-18 04:28:54 +00:00
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
|
free(buf);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
fclose(rcstream);
|
|
|
|
|
lineno = 0;
|
2004-07-30 22:52:44 +00:00
|
|
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
|
errors = FALSE;
|
2005-03-14 17:47:17 +00:00
|
|
|
|
fprintf(stderr,
|
|
|
|
|
_("\nPress Return to continue starting nano\n"));
|
2004-07-30 22:52:44 +00:00
|
|
|
|
while (getchar() != '\n')
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-18 04:28:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The main rc file function, tries to open the rc file */
|
|
|
|
|
void do_rcfile(void)
|
|
|
|
|
{
|
|
|
|
|
FILE *rcstream;
|
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#ifdef SYSCONFDIR
|
|
|
|
|
assert(sizeof(SYSCONFDIR) == strlen(SYSCONFDIR) + 1);
|
2005-03-04 15:09:55 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
nanorc = mallocstrcpy(nanorc, SYSCONFDIR "/nanorc");
|
|
|
|
|
/* Try to open the system-wide nanorc. */
|
2004-08-17 05:23:38 +00:00
|
|
|
|
rcstream = fopen(nanorc, "r");
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (rcstream != NULL)
|
2002-07-19 01:08:59 +00:00
|
|
|
|
parse_rcfile(rcstream);
|
|
|
|
|
#endif
|
2002-02-16 20:34:57 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
#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
|
2002-05-11 03:04:44 +00:00
|
|
|
|
|
2005-02-08 20:37:53 +00:00
|
|
|
|
get_homedir();
|
2003-02-13 03:36:15 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (homedir == NULL)
|
2004-08-17 05:23:38 +00:00
|
|
|
|
rcfile_error(N_("I can't find my home directory! Wah!"));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
else {
|
|
|
|
|
nanorc = charealloc(nanorc, strlen(homedir) + 9);
|
|
|
|
|
sprintf(nanorc, "%s/.nanorc", homedir);
|
2004-08-17 05:23:38 +00:00
|
|
|
|
rcstream = fopen(nanorc, "r");
|
2005-03-10 20:55:11 +00:00
|
|
|
|
|
2004-08-17 05:23:38 +00:00
|
|
|
|
if (rcstream == NULL) {
|
2005-03-10 20:55:11 +00:00
|
|
|
|
/* Don't complain about the file's not existing. */
|
|
|
|
|
if (errno != ENOENT)
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(N_("Error reading %s: %s"), nanorc,
|
|
|
|
|
strerror(errno));
|
2005-03-10 20:55:11 +00:00
|
|
|
|
} else
|
2002-07-19 01:08:59 +00:00
|
|
|
|
parse_rcfile(rcstream);
|
2001-04-18 04:28:54 +00:00
|
|
|
|
}
|
2005-03-04 15:09:55 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
free(nanorc);
|
|
|
|
|
nanorc = NULL;
|
2001-04-18 04:28:54 +00:00
|
|
|
|
|
2002-09-27 14:21:59 +00:00
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
|
set_colorpairs();
|
|
|
|
|
#endif
|
2001-04-18 04:28:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif /* ENABLE_NANORC */
|