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
|
|
|
|
* *
|
fix copyright years on source files; all functions in browser.c were
originally added in 2001; the oldest function in color.c is
do_colorinit() (now color_init()), which was originally added in 2001;
the oldest function in chars.c is revstrstr(), which was originally
added in 2001; the oldest function in help.c is do_help(), which was
originally added in 2000; the oldest function in prompt.c is statusq()
(now do_prompt()), which was originally added before 0.6.6, which was
apparently in 1999; all functions in rcfile.c were originally added in
2001; one of the oldest functions in search.c is do_search(), which was
originally added in 0.2.7, which was apparently in 1999; and one of the
oldest functions in text.c is do_wrap(), which was originally added in
0.3.1, which was apparently in 1999; also, for functions originally
adapted from other sources, add notices from the original files, as we
do with the tab completion functions adapted from busybox
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3172 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
2005-11-14 22:20:35 +00:00
|
|
|
|
* Copyright (C) 2001-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
|
|
|
|
|
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>
|
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[] = {
|
2004-05-29 16:38:57 +00:00
|
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
|
{"brackets", 0},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#endif
|
2005-06-17 21:08:13 +00:00
|
|
|
|
{"const", CONST_UPDATE},
|
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-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-12-22 16:30:00 +00:00
|
|
|
|
{"nofollow", NOFOLLOW_SYMLINKS},
|
2002-06-28 22:45:14 +00:00
|
|
|
|
{"nohelp", NO_HELP},
|
2005-11-05 17:35:44 +00:00
|
|
|
|
{"nonewlines", NO_NEWLINES},
|
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},
|
2005-08-10 21:22:15 +00:00
|
|
|
|
{"rebindkeypad", REBIND_KEYPAD},
|
2005-06-16 18:48:30 +00:00
|
|
|
|
#ifdef HAVE_REGEX_H
|
|
|
|
|
{"regexp", USE_REGEXP},
|
|
|
|
|
#endif
|
2002-06-28 22:45:14 +00:00
|
|
|
|
#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},
|
2005-11-15 03:17:35 +00:00
|
|
|
|
#ifndef NANO_TINY
|
2005-06-17 19:01:00 +00:00
|
|
|
|
{"autoindent", AUTOINDENT},
|
|
|
|
|
{"backup", BACKUP_FILE},
|
|
|
|
|
{"backupdir", 0},
|
|
|
|
|
{"backwards", BACKWARDS_SEARCH},
|
|
|
|
|
{"casesensitive", CASE_SENSITIVE},
|
|
|
|
|
{"cut", CUT_TO_END},
|
|
|
|
|
{"historylog", HISTORYLOG},
|
|
|
|
|
{"noconvert", NO_CONVERT},
|
2005-06-17 19:06:25 +00:00
|
|
|
|
{"quickblank", QUICK_BLANK},
|
2005-06-17 19:01:00 +00:00
|
|
|
|
{"smarthome", SMART_HOME},
|
|
|
|
|
{"smooth", SMOOTH_SCROLL},
|
|
|
|
|
{"tabstospaces", TABS_TO_SPACES},
|
2004-05-29 16:25:30 +00:00
|
|
|
|
{"whitespace", 0},
|
2005-08-10 22:12:28 +00:00
|
|
|
|
{"wordbounds", WORD_BOUNDS},
|
2004-05-29 16:25:30 +00:00
|
|
|
|
#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;
|
2005-06-28 06:25:34 +00:00
|
|
|
|
static size_t 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
|
2005-06-08 20:23:06 +00:00
|
|
|
|
* 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;
|
2005-08-01 05:54:11 +00:00
|
|
|
|
fprintf(stderr, _("Error in %s on line %lu: "), nanorc, (unsigned long)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-06-12 17:48:46 +00:00
|
|
|
|
while (!isblank(*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-06-12 17:48:46 +00:00
|
|
|
|
while (isblank(*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-06-12 17:48:46 +00:00
|
|
|
|
while (isblank(*ptr))
|
2002-07-19 01:08:59 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
2005-07-24 20:23:40 +00:00
|
|
|
|
short color_to_short(const char *colorname, bool *bright)
|
2001-11-29 02:42:27 +00:00
|
|
|
|
{
|
2005-07-13 20:18:46 +00:00
|
|
|
|
short mcolor = -1;
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-06-09 14:04:08 +00:00
|
|
|
|
assert(colorname != NULL && 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. */
|
2005-06-12 17:48:46 +00:00
|
|
|
|
while ((*ptr != '"' || (!isblank(*(ptr + 1)) &&
|
2005-03-10 20:55:11 +00:00
|
|
|
|
*(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-06-12 17:48:46 +00:00
|
|
|
|
while (isblank(*ptr))
|
2002-09-06 20:35:28 +00:00
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-29 21:42:08 +00:00
|
|
|
|
/* Compile the regular expression regex to see if it's valid. Return
|
|
|
|
|
* TRUE if it is, or FALSE otherwise. */
|
|
|
|
|
bool nregcomp(const char *regex, int eflags)
|
2003-02-03 02:56:44 +00:00
|
|
|
|
{
|
2005-07-29 21:42:08 +00:00
|
|
|
|
regex_t preg;
|
|
|
|
|
int rc = regcomp(&preg, regex, REG_EXTENDED | eflags);
|
2003-02-03 02:56:44 +00:00
|
|
|
|
|
|
|
|
|
if (rc != 0) {
|
2005-07-29 21:42:08 +00:00
|
|
|
|
size_t len = regerror(rc, &preg, NULL, 0);
|
2003-02-03 02:56:44 +00:00
|
|
|
|
char *str = charalloc(len);
|
|
|
|
|
|
2005-07-29 21:42:08 +00:00
|
|
|
|
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
|
|
|
|
|
2005-07-29 21:42:08 +00:00
|
|
|
|
regfree(&preg);
|
|
|
|
|
|
2005-07-13 20:18:46 +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;
|
2005-07-30 21:53:05 +00:00
|
|
|
|
const syntaxtype *tmpsyntax;
|
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
|
|
|
|
|
2005-07-30 21:53:05 +00:00
|
|
|
|
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
|
|
|
|
tmpsyntax = tmpsyntax->next) {
|
2005-08-01 04:34:27 +00:00
|
|
|
|
if (strcmp(nameptr, tmpsyntax->desc) == 0) {
|
2005-07-30 21:53:05 +00:00
|
|
|
|
rcfile_error(N_("Duplicate syntax name %s"), nameptr);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-07-29 21:42:08 +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;
|
2005-07-29 21:42:08 +00:00
|
|
|
|
|
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-08-01 04:59:34 +00:00
|
|
|
|
/* The "none" syntax is the same as not having a syntax at all, so
|
|
|
|
|
* we can't assign any extensions or colors to it. */
|
|
|
|
|
if (strcmp(endsyntax->desc, "none") == 0) {
|
|
|
|
|
rcfile_error(N_("The \"none\" syntax is reserved"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-01 04:23:29 +00:00
|
|
|
|
/* The default syntax should have no associated extensions. */
|
2005-08-01 04:34:27 +00:00
|
|
|
|
if (strcmp(endsyntax->desc, "default") == 0 && *ptr != '\0') {
|
2005-08-01 04:59:34 +00:00
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("The \"default\" syntax must take no extensions"));
|
2005-08-01 04:23:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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-07-29 21:42:08 +00:00
|
|
|
|
|
|
|
|
|
/* Save the extension regex if it's valid. */
|
|
|
|
|
if (nregcomp(fileregptr, REG_NOSUB)) {
|
|
|
|
|
newext->ext_regex = mallocstrcpy(NULL, fileregptr);
|
|
|
|
|
newext->ext = NULL;
|
|
|
|
|
|
2003-02-03 02:56:44 +00:00
|
|
|
|
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;
|
2005-07-14 18:33:51 +00:00
|
|
|
|
} else
|
|
|
|
|
free(newext);
|
2002-06-28 22:45:14 +00:00
|
|
|
|
}
|
2002-05-04 03:47:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-27 03:07:10 +00:00
|
|
|
|
/* Parse the color stuff into the colorstrings array. If icase is TRUE,
|
|
|
|
|
* treat the color stuff as case insensitive. */
|
|
|
|
|
void parse_colors(char *ptr, bool icase)
|
2001-11-29 02:42:27 +00:00
|
|
|
|
{
|
2005-07-13 20:18:46 +00:00
|
|
|
|
short fg, bg;
|
2005-06-08 21:17:32 +00:00
|
|
|
|
bool bright = FALSE, no_fgcolor = 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;
|
2005-06-08 21:17:32 +00:00
|
|
|
|
|
2001-11-29 02:42:27 +00:00
|
|
|
|
strtok(fgstr, ",");
|
2003-09-06 05:09:32 +00:00
|
|
|
|
bgcolorname = strtok(NULL, ",");
|
2005-06-08 21:17:32 +00:00
|
|
|
|
if (bgcolorname == NULL) {
|
|
|
|
|
/* If we have a background color without a foreground color,
|
|
|
|
|
* parse it properly. */
|
|
|
|
|
bgcolorname = fgstr + 1;
|
|
|
|
|
no_fgcolor = TRUE;
|
|
|
|
|
}
|
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-07-13 20:18:46 +00:00
|
|
|
|
bg = color_to_short(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-06-08 21:17:32 +00:00
|
|
|
|
if (!no_fgcolor) {
|
2005-07-13 20:18:46 +00:00
|
|
|
|
fg = color_to_short(fgstr, &bright);
|
2001-11-29 02:42:27 +00:00
|
|
|
|
|
2005-06-08 21:17:32 +00:00
|
|
|
|
/* Don't try to parse screwed-up foreground colors. */
|
|
|
|
|
if (fg == -1)
|
|
|
|
|
return;
|
|
|
|
|
} else
|
|
|
|
|
fg = -1;
|
2003-02-07 00:19:05 +00:00
|
|
|
|
|
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-09 01:09:00 +00:00
|
|
|
|
if (*ptr == '\0') {
|
2005-06-09 14:04:08 +00:00
|
|
|
|
rcfile_error(N_("Missing regex string"));
|
2005-06-09 01:09:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
fgstr = ptr;
|
|
|
|
|
ptr = parse_next_regex(ptr);
|
2005-03-10 20:55:11 +00:00
|
|
|
|
if (ptr == NULL)
|
|
|
|
|
break;
|
|
|
|
|
|
2005-07-29 21:42:08 +00:00
|
|
|
|
newcolor = (colortype *)nmalloc(sizeof(colortype));
|
2005-07-13 20:18:46 +00:00
|
|
|
|
|
2005-07-29 21:42:08 +00:00
|
|
|
|
/* Save the starting regex string if it's valid, and set up the
|
|
|
|
|
* color information. */
|
|
|
|
|
if (nregcomp(fgstr, icase ? REG_ICASE : 0)) {
|
2003-02-03 02:56:44 +00:00
|
|
|
|
newcolor->fg = fg;
|
|
|
|
|
newcolor->bg = bg;
|
|
|
|
|
newcolor->bright = bright;
|
2005-07-13 20:18:46 +00:00
|
|
|
|
newcolor->icase = icase;
|
2005-07-29 21:42:08 +00:00
|
|
|
|
|
|
|
|
|
newcolor->start_regex = mallocstrcpy(NULL, fgstr);
|
|
|
|
|
newcolor->start = NULL;
|
|
|
|
|
|
2005-07-14 18:33:51 +00:00
|
|
|
|
newcolor->end_regex = NULL;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
newcolor->end = NULL;
|
2005-07-29 21:42:08 +00:00
|
|
|
|
|
2005-07-13 20:18:46 +00:00
|
|
|
|
newcolor->next = NULL;
|
2003-02-03 02:56:44 +00:00
|
|
|
|
|
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-07-13 20:18:46 +00:00
|
|
|
|
fprintf(stderr, "Starting a new colorstring for fg %hd, bg %hd\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-07-13 20:18:46 +00:00
|
|
|
|
fprintf(stderr, "Adding new entry for fg %hd, bg %hd\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-07-29 21:42:08 +00:00
|
|
|
|
|
2005-03-10 20:55:11 +00:00
|
|
|
|
endcolor = newcolor;
|
2005-07-13 20:18:46 +00:00
|
|
|
|
} else {
|
|
|
|
|
free(newcolor);
|
|
|
|
|
cancelled = TRUE;
|
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
|
|
|
|
|
2005-07-29 21:42:08 +00:00
|
|
|
|
/* Save the ending regex string if it's valid. */
|
|
|
|
|
newcolor->end_regex = (nregcomp(fgstr, icase ? REG_ICASE :
|
|
|
|
|
0)) ? mallocstrcpy(NULL, fgstr) : 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-06-12 17:48:46 +00:00
|
|
|
|
while (isblank(*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)
|
2005-06-27 03:07:10 +00:00
|
|
|
|
parse_colors(ptr, FALSE);
|
|
|
|
|
else if (strcasecmp(keyword, "icolor") == 0)
|
|
|
|
|
parse_colors(ptr, TRUE);
|
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
|
|
|
|
|
2005-06-13 14:50:32 +00:00
|
|
|
|
option = mallocstrcpy(NULL, 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
|
2005-06-13 14:50:32 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure option is a valid multibyte
|
|
|
|
|
* string. */
|
|
|
|
|
if (!is_valid_mbstring(option)) {
|
|
|
|
|
rcfile_error(
|
|
|
|
|
N_("Option is not a valid multibyte string"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#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
|
2005-11-15 03:17:35 +00:00
|
|
|
|
#ifndef NANO_TINY
|
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-06-13 14:50:32 +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,
|
2005-07-26 06:13:45 +00:00
|
|
|
|
NULL);
|
2005-03-10 22:52:21 +00:00
|
|
|
|
whitespace_len[1] =
|
|
|
|
|
parse_mbchar(whitespace +
|
2005-07-26 06:13:45 +00:00
|
|
|
|
whitespace_len[0], 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-06-14 01:55:56 +00:00
|
|
|
|
if (has_blank_mbchars(punct)) {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
2005-06-14 01:55:56 +00:00
|
|
|
|
N_("Non-blank 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-06-14 01:55:56 +00:00
|
|
|
|
if (has_blank_mbchars(brackets)) {
|
2005-03-14 17:47:17 +00:00
|
|
|
|
rcfile_error(
|
2005-06-14 01:55:56 +00:00
|
|
|
|
N_("Non-blank 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
|
2005-11-15 03:17:35 +00:00
|
|
|
|
#ifndef NANO_TINY
|
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-08-01 05:54:11 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-04 04:10:09 +00:00
|
|
|
|
/* The main rcfile function. It tries to open the system-wide rcfile,
|
|
|
|
|
* followed by the local rcfile. */
|
2001-04-18 04:28:54 +00:00
|
|
|
|
void do_rcfile(void)
|
|
|
|
|
{
|
|
|
|
|
FILE *rcstream;
|
|
|
|
|
|
2002-07-19 01:08:59 +00:00
|
|
|
|
#ifdef SYSCONFDIR
|
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 */
|