2001-04-18 08:28:54 +04:00
|
|
|
/* $Id$ */
|
|
|
|
/**************************************************************************
|
2001-05-05 19:02:27 +04:00
|
|
|
* rcfile.c *
|
2001-04-18 08:28:54 +04:00
|
|
|
* *
|
2002-01-04 20:57:40 +03:00
|
|
|
* Copyright (C) 1999-2002 Chris Allegretta *
|
2001-04-18 08:28:54 +04: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 15:33:54 +04:00
|
|
|
* the Free Software Foundation; either version 2, or (at your option) *
|
2001-04-18 08:28:54 +04:00
|
|
|
* any later version. *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
|
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2002-01-22 23:09:20 +03:00
|
|
|
#include <stdarg.h>
|
2001-04-18 08:28:54 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "proto.h"
|
|
|
|
#include "nano.h"
|
|
|
|
|
|
|
|
#ifdef ENABLE_NANORC
|
|
|
|
|
|
|
|
#ifndef NANO_SMALL
|
|
|
|
#include <libintl.h>
|
|
|
|
#define _(string) gettext(string)
|
|
|
|
#else
|
|
|
|
#define _(string) (string)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Static stuff for the nanorc file */
|
2002-03-04 01:52:52 +03:00
|
|
|
rcoption rcopts[] = {
|
2002-01-19 19:52:34 +03:00
|
|
|
{"regexp", USE_REGEXP},
|
|
|
|
{"const", CONSTUPDATE},
|
|
|
|
{"autoindent", AUTOINDENT},
|
|
|
|
{"cut", CUT_TO_END},
|
|
|
|
{"nofollow", FOLLOW_SYMLINKS},
|
|
|
|
{"mouse", USE_MOUSE},
|
|
|
|
{"operatingdir", 0},
|
|
|
|
{"pico", PICO_MODE},
|
|
|
|
{"tabsize", 0},
|
|
|
|
{"fill", 0},
|
|
|
|
{"speller", 0},
|
|
|
|
{"tempfile", TEMP_OPT},
|
|
|
|
{"view", VIEW_MODE},
|
|
|
|
{"nowrap", NO_WRAP},
|
|
|
|
{"nohelp", NO_HELP},
|
|
|
|
{"suspend", SUSPEND},
|
|
|
|
{"multibuffer", MULTIBUFFER},
|
|
|
|
{"smooth", SMOOTHSCROLL},
|
2002-01-26 00:59:02 +03:00
|
|
|
{"keypad", ALT_KEYPAD},
|
2002-03-04 01:52:52 +03:00
|
|
|
{"noconvert", NO_CONVERT},
|
|
|
|
{"quotestr", 0},
|
|
|
|
{"", 0}
|
2002-01-19 19:52:34 +03:00
|
|
|
};
|
2001-04-18 08:28:54 +04:00
|
|
|
|
2002-01-19 00:54:35 +03:00
|
|
|
static int errors = 0;
|
|
|
|
static int lineno = 0;
|
|
|
|
static char *nanorc;
|
|
|
|
|
2001-05-05 21:45:54 +04: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 */
|
2001-04-18 08:28:54 +04:00
|
|
|
void rcfile_error(char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2002-01-19 00:54:35 +03:00
|
|
|
fprintf(stderr, _("Error in %s on line %d: "), nanorc, lineno);
|
2001-04-18 08:28:54 +04:00
|
|
|
va_start(ap, msg);
|
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(stderr, _("\nPress return to continue starting nano\n"));
|
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
while (getchar() != '\n');
|
2001-04-18 08:28:54 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-05-05 21:45:54 +04:00
|
|
|
/* Just print the error (one of many, perhaps) but don't abort, yet */
|
2002-01-19 00:54:35 +03:00
|
|
|
void rcfile_msg(char *msg, ...)
|
2001-04-18 08:28:54 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2002-01-19 00:54:35 +03:00
|
|
|
if (!errors) {
|
|
|
|
errors = 1;
|
2001-04-18 08:28:54 +04:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
va_start(ap, msg);
|
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-05-05 21:45:54 +04:00
|
|
|
/* Parse the next word from the string. Returns NULL if we hit EOL */
|
2001-04-18 08:28:54 +04:00
|
|
|
char *parse_next_word(char *ptr)
|
|
|
|
{
|
2002-01-19 19:52:34 +03:00
|
|
|
while (*ptr != ' ' && *ptr != '\t' && *ptr != '\n' && *ptr != '\0')
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (*ptr == '\0')
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Null terminate and advance ptr */
|
|
|
|
*ptr++ = 0;
|
|
|
|
|
|
|
|
while ((*ptr == ' ' || *ptr == '\t') && *ptr != '\0')
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
char *parse_next_regex(char *ptr)
|
|
|
|
{
|
2002-02-02 10:13:02 +03:00
|
|
|
while ((*ptr != '"' || (*(ptr+1) != ' ' && *(ptr+1) != '\n'))
|
|
|
|
&& *ptr != '\n' && *ptr != '\0')
|
2001-04-18 08:28:54 +04:00
|
|
|
ptr++;
|
|
|
|
|
2002-01-02 16:59:11 +03:00
|
|
|
if (*ptr == '\0')
|
2001-04-18 08:28:54 +04:00
|
|
|
return NULL;
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2001-04-18 08:28:54 +04:00
|
|
|
/* Null terminate and advance ptr */
|
|
|
|
*ptr++ = 0;
|
|
|
|
|
2001-11-29 05:42:27 +03:00
|
|
|
while ((*ptr == ' ' || *ptr == '\t') && *ptr != '\0')
|
|
|
|
ptr++;
|
|
|
|
|
2001-04-18 08:28:54 +04:00
|
|
|
return ptr;
|
2002-01-19 19:52:34 +03:00
|
|
|
|
2001-04-18 08:28:54 +04:00
|
|
|
}
|
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
int colortoint(char *colorname, int *bright)
|
2001-11-29 05:42:27 +03:00
|
|
|
{
|
|
|
|
int mcolor = 0;
|
|
|
|
|
|
|
|
if (colorname == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2002-03-04 01:52:52 +03:00
|
|
|
if (stristr(colorname, "bright")) {
|
2001-12-02 07:55:44 +03:00
|
|
|
*bright = 1;
|
2001-11-29 05:42:27 +03:00
|
|
|
colorname += 6;
|
|
|
|
}
|
2002-01-19 19:52:34 +03:00
|
|
|
|
2001-11-29 05:42:27 +03:00
|
|
|
if (!strcasecmp(colorname, "green"))
|
|
|
|
mcolor += COLOR_GREEN;
|
|
|
|
else if (!strcasecmp(colorname, "red"))
|
|
|
|
mcolor += COLOR_RED;
|
|
|
|
else if (!strcasecmp(colorname, "blue"))
|
|
|
|
mcolor += COLOR_BLUE;
|
|
|
|
else if (!strcasecmp(colorname, "white"))
|
|
|
|
mcolor += COLOR_WHITE;
|
|
|
|
else if (!strcasecmp(colorname, "yellow"))
|
|
|
|
mcolor += COLOR_YELLOW;
|
|
|
|
else if (!strcasecmp(colorname, "cyan"))
|
|
|
|
mcolor += COLOR_CYAN;
|
|
|
|
else if (!strcasecmp(colorname, "magenta"))
|
|
|
|
mcolor += COLOR_MAGENTA;
|
|
|
|
else if (!strcasecmp(colorname, "black"))
|
|
|
|
mcolor += COLOR_BLACK;
|
|
|
|
else {
|
2002-01-19 19:52:34 +03:00
|
|
|
rcfile_error(_("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"));
|
2001-11-29 05:42:27 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mcolor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
/* Parse the color stuff into the colorstrings array */
|
2002-01-19 19:52:34 +03:00
|
|
|
void parse_colors(FILE * rcstream, char *buf, char *ptr)
|
2001-11-29 05:42:27 +03:00
|
|
|
{
|
2002-01-19 19:52:34 +03:00
|
|
|
int fg, bg, bright = 0;
|
|
|
|
int expectend = 0; /* Do we expect an end= line? */
|
2001-11-29 05:42:27 +03:00
|
|
|
char *tmp = NULL, *beginning, *fgstr, *bgstr;
|
|
|
|
colortype *tmpcolor = NULL;
|
|
|
|
|
|
|
|
fgstr = ptr;
|
|
|
|
ptr = parse_next_word(ptr);
|
|
|
|
|
|
|
|
if (ptr == NULL) {
|
2002-01-19 00:54:35 +03:00
|
|
|
rcfile_error(_("Missing color name"));
|
2001-11-29 05:42:27 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr(fgstr, ",")) {
|
|
|
|
strtok(fgstr, ",");
|
|
|
|
bgstr = strtok(NULL, ",");
|
|
|
|
} else
|
|
|
|
bgstr = NULL;
|
|
|
|
|
2002-01-19 00:54:35 +03:00
|
|
|
fg = colortoint(fgstr, &bright);
|
|
|
|
bg = colortoint(bgstr, &bright);
|
2001-11-29 05:42:27 +03:00
|
|
|
|
|
|
|
/* Now the fun part, start adding regexps to individual strings
|
2002-01-19 19:52:34 +03:00
|
|
|
in the colorstrings array, woo! */
|
2001-11-29 05:42:27 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
while (*ptr != '\0') {
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
while (*ptr == ' ')
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (*ptr == '\n' || *ptr == '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!strncasecmp(ptr, "start=", 6)) {
|
|
|
|
ptr += 6;
|
|
|
|
expectend = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ptr != '"') {
|
|
|
|
rcfile_error(_("regex strings must begin and end with a \" character\n"));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ptr++;
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
beginning = ptr;
|
|
|
|
ptr = parse_next_regex(ptr);
|
|
|
|
|
|
|
|
tmp = NULL;
|
|
|
|
tmp = mallocstrcpy(tmp, beginning);
|
|
|
|
|
|
|
|
if (colorstrings == NULL) {
|
|
|
|
colorstrings = nmalloc(sizeof(colortype));
|
|
|
|
colorstrings->fg = fg;
|
|
|
|
colorstrings->bg = bg;
|
|
|
|
colorstrings->bright = bright;
|
|
|
|
colorstrings->start = tmp;
|
|
|
|
colorstrings->next = NULL;
|
|
|
|
tmpcolor = colorstrings;
|
2002-01-19 00:54:35 +03:00
|
|
|
#ifdef DEBUG
|
2002-01-19 19:52:34 +03:00
|
|
|
fprintf(stderr,
|
|
|
|
"Starting a new colorstring for fg %d bg %d\n",
|
|
|
|
fg, bg);
|
|
|
|
fprintf(stderr, "string val=%s\n", tmp);
|
2002-01-19 00:54:35 +03:00
|
|
|
#endif
|
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
} else {
|
|
|
|
for (tmpcolor = colorstrings;
|
|
|
|
tmpcolor->next != NULL; tmpcolor = tmpcolor->next);
|
2001-11-29 06:49:09 +03:00
|
|
|
#ifdef DEBUG
|
2002-01-19 19:52:34 +03:00
|
|
|
fprintf(stderr, "Adding new entry for fg %d bg %d\n", fg, bg);
|
|
|
|
fprintf(stderr, "string val=%s\n", tmp);
|
2001-11-29 06:49:09 +03:00
|
|
|
#endif
|
2001-11-29 05:42:27 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
tmpcolor->next = nmalloc(sizeof(colortype));
|
|
|
|
tmpcolor->next->fg = fg;
|
|
|
|
tmpcolor->next->bg = bg;
|
|
|
|
tmpcolor->next->bright = bright;
|
|
|
|
tmpcolor->next->start = tmp;
|
|
|
|
tmpcolor->next->next = NULL;
|
|
|
|
tmpcolor = tmpcolor->next;
|
|
|
|
}
|
2001-11-29 05:42:27 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
if (expectend) {
|
|
|
|
if (ptr == NULL || strncasecmp(ptr, "end=", 4)) {
|
|
|
|
rcfile_error(_
|
|
|
|
("\n\t\"start=\" requires a corresponding \"end=\""));
|
|
|
|
return;
|
|
|
|
}
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
ptr += 4;
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
if (*ptr != '"') {
|
|
|
|
rcfile_error(_
|
|
|
|
("regex strings must begin and end with a \" character\n"));
|
|
|
|
continue;
|
2001-11-29 05:42:27 +03:00
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
beginning = ptr;
|
|
|
|
ptr = parse_next_regex(ptr);
|
2002-01-19 00:54:35 +03:00
|
|
|
#ifdef DEBUG
|
2002-01-19 19:52:34 +03:00
|
|
|
fprintf(stderr, "For end part, beginning = \"%s\"\n",
|
|
|
|
beginning);
|
2002-01-19 00:54:35 +03:00
|
|
|
#endif
|
2002-01-19 19:52:34 +03:00
|
|
|
tmp = NULL;
|
|
|
|
tmp = mallocstrcpy(tmp, beginning);
|
|
|
|
tmpcolor->end = tmp;
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
} else
|
|
|
|
tmpcolor->end = NULL;
|
2002-01-19 00:54:35 +03:00
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
}
|
2001-11-29 05:42:27 +03:00
|
|
|
}
|
2002-01-19 19:52:34 +03:00
|
|
|
#endif /* ENABLE_COLOR */
|
2001-11-29 05:42:27 +03:00
|
|
|
|
2001-04-18 08:28:54 +04:00
|
|
|
/* Parse the RC file, once it has been opened successfully */
|
2002-01-19 19:52:34 +03:00
|
|
|
void parse_rcfile(FILE * rcstream)
|
2001-04-18 08:28:54 +04:00
|
|
|
{
|
|
|
|
char *buf, *ptr, *keyword, *option;
|
2002-03-07 03:46:17 +03:00
|
|
|
int set = 0, i, j;
|
2001-04-18 08:28:54 +04:00
|
|
|
|
2001-05-18 08:44:16 +04:00
|
|
|
buf = charalloc(1024);
|
2001-04-18 08:28:54 +04:00
|
|
|
while (fgets(buf, 1023, rcstream) > 0) {
|
|
|
|
lineno++;
|
|
|
|
ptr = buf;
|
2002-01-19 19:52:34 +03:00
|
|
|
while ((*ptr == ' ' || *ptr == '\t') &&
|
|
|
|
(*ptr != '\n' && *ptr != '\0'))
|
2001-04-18 08:28:54 +04:00
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if (*ptr == '\n' || *ptr == '\0')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*ptr == '#') {
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, _("parse_rcfile: Read a comment\n"));
|
|
|
|
#endif
|
2002-01-19 19:52:34 +03:00
|
|
|
continue; /* Skip past commented lines */
|
2001-04-18 08:28:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Else skip to the next space */
|
|
|
|
keyword = ptr;
|
|
|
|
ptr = parse_next_word(ptr);
|
|
|
|
if (!ptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Else try to parse the keyword */
|
|
|
|
if (!strcasecmp(keyword, "set"))
|
|
|
|
set = 1;
|
|
|
|
else if (!strcasecmp(keyword, "unset"))
|
|
|
|
set = -1;
|
2001-11-29 05:42:27 +03:00
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
else if (!strcasecmp(keyword, "color"))
|
2002-01-19 00:54:35 +03:00
|
|
|
parse_colors(rcstream, buf, ptr);
|
2002-01-19 19:52:34 +03:00
|
|
|
#endif /* ENABLE_COLOR */
|
2001-04-18 08:28:54 +04:00
|
|
|
else {
|
2002-01-19 00:54:35 +03:00
|
|
|
rcfile_msg(_("command %s not understood"), keyword);
|
2001-04-18 08:28:54 +04:00
|
|
|
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) {
|
2002-03-04 01:52:52 +03:00
|
|
|
for (i = 0; rcopts[i].name != ""; i++) {
|
2002-01-19 19:52:34 +03:00
|
|
|
if (!strcasecmp(option, rcopts[i].name)) {
|
2001-04-18 08:28:54 +04:00
|
|
|
#ifdef DEBUG
|
2002-01-19 19:52:34 +03:00
|
|
|
fprintf(stderr, _("parse_rcfile: Parsing option %s\n"),
|
|
|
|
rcopts[i].name);
|
2001-04-18 08:28:54 +04:00
|
|
|
#endif
|
|
|
|
if (set == 1 || rcopts[i].flag == FOLLOW_SYMLINKS) {
|
2002-01-19 19:52:34 +03:00
|
|
|
if (!strcasecmp(rcopts[i].name, "operatingdir") ||
|
2001-10-03 03:57:31 +04:00
|
|
|
!strcasecmp(rcopts[i].name, "tabsize") ||
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
2002-01-19 19:52:34 +03:00
|
|
|
!strcasecmp(rcopts[i].name, "fill") ||
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2002-03-04 01:52:52 +03:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
!strcasecmp(rcopts[i].name, "quotestr") ||
|
|
|
|
#endif
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_SPELLER
|
|
|
|
!strcasecmp(rcopts[i].name, "speller")
|
|
|
|
#else
|
2002-01-19 19:52:34 +03:00
|
|
|
0
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2002-01-19 19:52:34 +03:00
|
|
|
) {
|
2001-04-18 08:28:54 +04:00
|
|
|
|
|
|
|
if (*ptr == '\n' || *ptr == '\0') {
|
2002-01-19 19:52:34 +03:00
|
|
|
rcfile_error(_
|
|
|
|
("option %s requires an argument"),
|
|
|
|
rcopts[i].name);
|
2001-04-18 08:28:54 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
option = ptr;
|
|
|
|
ptr = parse_next_word(ptr);
|
|
|
|
if (!strcasecmp(rcopts[i].name, "fill")) {
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_WRAPJUSTIFY
|
|
|
|
|
2002-03-07 03:46:17 +03:00
|
|
|
if ((j = atoi(option)) < MIN_FILL_LENGTH) {
|
2002-01-19 19:52:34 +03:00
|
|
|
rcfile_error(_
|
|
|
|
("requested fill size %d too small"),
|
2002-03-07 03:46:17 +03:00
|
|
|
j);
|
2002-01-19 19:52:34 +03:00
|
|
|
} else
|
2002-03-07 03:46:17 +03:00
|
|
|
fill = j;
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2002-01-19 19:52:34 +03:00
|
|
|
} else
|
|
|
|
if (!strcasecmp(rcopts[i].name, "tabsize"))
|
|
|
|
{
|
2002-03-07 03:46:17 +03:00
|
|
|
if ((j = atoi(option)) <= 0) {
|
2002-01-19 19:52:34 +03:00
|
|
|
rcfile_error(_
|
|
|
|
("requested tab size %d too small"),
|
2002-03-07 03:46:17 +03:00
|
|
|
j);
|
2002-01-19 19:52:34 +03:00
|
|
|
} else {
|
2002-03-07 03:46:17 +03:00
|
|
|
tabsize = j;
|
2002-01-19 19:52:34 +03:00
|
|
|
}
|
2002-03-04 01:52:52 +03:00
|
|
|
#ifndef DISABLE_JUSTIFY
|
|
|
|
} else
|
|
|
|
if (!strcasecmp(rcopts[i].name, "quotestr"))
|
|
|
|
{
|
|
|
|
quotestr = NULL;
|
|
|
|
quotestr =
|
|
|
|
charalloc(strlen(option) + 1);
|
|
|
|
strcpy(quotestr, option);
|
|
|
|
#endif
|
2001-10-03 03:57:31 +04:00
|
|
|
} else {
|
2001-05-21 16:56:25 +04:00
|
|
|
#ifndef DISABLE_SPELLER
|
2002-01-19 19:52:34 +03:00
|
|
|
alt_speller =
|
|
|
|
charalloc(strlen(option) + 1);
|
|
|
|
strcpy(alt_speller, option);
|
2001-05-21 16:56:25 +04:00
|
|
|
#endif
|
2001-04-18 08:28:54 +04:00
|
|
|
}
|
2002-01-19 19:52:34 +03:00
|
|
|
} else
|
2001-04-18 08:28:54 +04:00
|
|
|
SET(rcopts[i].flag);
|
|
|
|
#ifdef DEBUG
|
2002-01-19 19:52:34 +03:00
|
|
|
fprintf(stderr, _("set flag %d!\n"),
|
|
|
|
rcopts[i].flag);
|
2001-04-18 08:28:54 +04:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
UNSET(rcopts[i].flag);
|
|
|
|
#ifdef DEBUG
|
2002-01-19 19:52:34 +03:00
|
|
|
fprintf(stderr, _("unset flag %d!\n"),
|
|
|
|
rcopts[i].flag);
|
2001-04-18 08:28:54 +04:00
|
|
|
#endif
|
2002-01-19 19:52:34 +03:00
|
|
|
}
|
2001-04-18 08:28:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (errors)
|
|
|
|
rcfile_error(_("Errors found in .nanorc file"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The main rc file function, tries to open the rc file */
|
|
|
|
void do_rcfile(void)
|
|
|
|
{
|
|
|
|
char *unable = _("Unable to open ~/.nanorc file, %s");
|
|
|
|
struct stat fileinfo;
|
|
|
|
FILE *rcstream;
|
|
|
|
|
|
|
|
if (getenv("HOME") == NULL)
|
|
|
|
return;
|
|
|
|
|
2002-02-16 23:34:57 +03:00
|
|
|
nanorc = charalloc(strlen(SYSCONFDIR) + 10);
|
|
|
|
sprintf(nanorc, "%s/nanorc", SYSCONFDIR);
|
|
|
|
|
|
|
|
/* Try to open system nanorc */
|
|
|
|
if (stat(nanorc, &fileinfo) != -1)
|
|
|
|
if ((rcstream = fopen(nanorc, "r")) != NULL) {
|
|
|
|
|
|
|
|
/* Parse it! */
|
|
|
|
parse_rcfile(rcstream);
|
|
|
|
fclose(rcstream);
|
|
|
|
}
|
|
|
|
|
2001-05-17 15:35:43 +04:00
|
|
|
nanorc = charalloc(strlen(getenv("HOME")) + 10);
|
2001-04-18 08:28:54 +04:00
|
|
|
sprintf(nanorc, "%s/.nanorc", getenv("HOME"));
|
|
|
|
|
|
|
|
if (stat(nanorc, &fileinfo) == -1) {
|
|
|
|
|
|
|
|
/* Abort if the file doesn't exist and there's some other kind
|
|
|
|
of error stat()ing it */
|
|
|
|
if (errno != ENOENT)
|
|
|
|
rcfile_error(unable, errno);
|
|
|
|
return;
|
2002-01-19 19:52:34 +03:00
|
|
|
}
|
2001-04-18 08:28:54 +04:00
|
|
|
|
|
|
|
if ((rcstream = fopen(nanorc, "r")) == NULL) {
|
|
|
|
rcfile_error(unable, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-19 00:54:35 +03:00
|
|
|
parse_rcfile(rcstream);
|
2001-04-18 08:28:54 +04:00
|
|
|
fclose(rcstream);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-19 19:52:34 +03:00
|
|
|
#endif /* ENABLE_NANORC */
|