Supporting globs in include paths. Patch by Mike Frysinger.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4696 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2014-03-30 20:37:40 +00:00
parent b21daeb009
commit 38142830c7
3 changed files with 37 additions and 111 deletions

View File

@ -6,6 +6,9 @@
and += appending supported by automake to produce simpler files. and += appending supported by automake to produce simpler files.
* doc/Makefile.am - Drop redundant localedir, as autoconf/automake * doc/Makefile.am - Drop redundant localedir, as autoconf/automake
already creates this for us. already creates this for us.
* src/rcfile.c, doc/nanorc.sample.in - Hard-listing all the wanted
syntax files is a PITA. Support globs in include paths, so people
can easily drop in new files and have it "just work".
2014-03-27 Benno Schulenberg <bensberg@justemail.net> 2014-03-27 Benno Schulenberg <bensberg@justemail.net>
* src/nano.c (main) - Fix compilation with --disable-utf8. * src/nano.c (main) - Fix compilation with --disable-utf8.

View File

@ -228,6 +228,9 @@
## ##
## All regexes should be extended regular expressions. ## All regexes should be extended regular expressions.
# include "@PKGDATADIR@/*.nanorc"
## Key bindings ## Key bindings
## Please see nanorc(5) for more details on this ## Please see nanorc(5) for more details on this
## ##
@ -239,97 +242,3 @@
## Set this if your backspace key sends delete most of the time (2.1.3+) ## Set this if your backspace key sends delete most of the time (2.1.3+)
# bind kdel backspace all # bind kdel backspace all
## Nanorc files
# include "@PKGDATADIR@/nanorc.nanorc"
## Assembler
# include "@PKGDATADIR@/asm.nanorc"
## AWK
# include "@PKGDATADIR@/awk.nanorc"
## Bourne shell scripts
# include "@PKGDATADIR@/sh.nanorc"
## C/C++
# include "@PKGDATADIR@/c.nanorc"
## Cascading Style Sheets
# include "@PKGDATADIR@/css.nanorc"
## CMake files
# include "@PKGDATADIR@/cmake.nanorc"
## Debian files
# include "@PKGDATADIR@/debian.nanorc"
## Fortran
# include "@PKGDATADIR@/fortran.nanorc"
## Gentoo files
# include "@PKGDATADIR@/gentoo.nanorc"
## Groff
# include "@PKGDATADIR@/groff.nanorc"
## HTML
# include "@PKGDATADIR@/html.nanorc"
## Java
# include "@PKGDATADIR@/java.nanorc"
## Javascript
# include "@PKGDATADIR@/javascript.nanorc"
## Luan
# include "@PKGDATADIR@/lua.nanorc"
## Magicpoint presentations
# include "@PKGDATADIR@/mgp.nanorc"
## Makefiles
# include "@PKGDATADIR@/makefile.nanorc"
## Manpages
# include "@PKGDATADIR@/man.nanorc"
## Objective-C
# include "@PKGDATADIR@/objc.nanorc"
## OCaml
# include "@PKGDATADIR@/ocaml.nanorc"
## Patch files
# include "@PKGDATADIR@/patch.nanorc"
## Perl
# include "@PKGDATADIR@/perl.nanorc"
## PHP
# include "@PKGDATADIR@/php.nanorc"
## POV-Ray
# include "@PKGDATADIR@/pov.nanorc"
## Python
# include "@PKGDATADIR@/python.nanorc"
## Quoted emails (under e.g. mutt)
# include "@PKGDATADIR@/mutt.nanorc"
## Ruby
# include "@PKGDATADIR@/ruby.nanorc"
## Spec files (in RPMs)
# include "@PKGDATADIR@/spec.nanorc"
## TCL
# include "@PKGDATADIR@/tcl.nanorc"
## TeX
# include "@PKGDATADIR@/tex.nanorc"
## XML-type files
# include "@PKGDATADIR@/xml.nanorc"

View File

@ -23,6 +23,7 @@
#include "proto.h" #include "proto.h"
#include <glob.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -620,47 +621,38 @@ void parse_unbinding(char *ptr)
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
/* Read and parse additional syntax files. */ /* Read and parse additional syntax files. */
void parse_include(char *ptr) static void _parse_include(char *file)
{ {
struct stat rcinfo; struct stat rcinfo;
FILE *rcstream; FILE *rcstream;
char *option, *nanorc_save = nanorc, *expanded;
size_t lineno_save = lineno;
option = ptr;
if (*option == '"')
option++;
ptr = parse_argument(ptr);
/* Can't get the specified file's full path cause it may screw up /* Can't get the specified file's full path cause it may screw up
our cwd depending on the parent dirs' permissions, (see Savannah bug 25297) */ our cwd depending on the parent dirs' permissions, (see Savannah bug 25297) */
/* Don't open directories, character files, or block files. */ /* Don't open directories, character files, or block files. */
if (stat(option, &rcinfo) != -1) { if (stat(file, &rcinfo) != -1) {
if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) || if (S_ISDIR(rcinfo.st_mode) || S_ISCHR(rcinfo.st_mode) ||
S_ISBLK(rcinfo.st_mode)) { S_ISBLK(rcinfo.st_mode)) {
rcfile_error(S_ISDIR(rcinfo.st_mode) ? rcfile_error(S_ISDIR(rcinfo.st_mode) ?
_("\"%s\" is a directory") : _("\"%s\" is a directory") :
_("\"%s\" is a device file"), option); _("\"%s\" is a device file"), file);
} }
} }
expanded = real_dir_from_tilde(option);
/* Open the new syntax file. */ /* Open the new syntax file. */
if ((rcstream = fopen(expanded, "rb")) == NULL) { if ((rcstream = fopen(file, "rb")) == NULL) {
rcfile_error(_("Error reading %s: %s"), expanded, rcfile_error(_("Error reading %s: %s"), file,
strerror(errno)); strerror(errno));
return; return;
} }
/* Use the name and line number position of the new syntax file /* Use the name and line number position of the new syntax file
* while parsing it, so we can know where any errors in it are. */ * while parsing it, so we can know where any errors in it are. */
nanorc = expanded; nanorc = file;
lineno = 0; lineno = 0;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Parsing file \"%s\" (expanded from \"%s\")\n", expanded, option); fprintf(stderr, "Parsing file \"%s\"\n", file);
#endif #endif
parse_rcfile(rcstream parse_rcfile(rcstream
@ -668,12 +660,34 @@ void parse_include(char *ptr)
, TRUE , TRUE
#endif #endif
); );
}
void parse_include(char *ptr)
{
char *option, *nanorc_save = nanorc, *expanded;
size_t lineno_save = lineno, i;
glob_t files;
option = ptr;
if (*option == '"')
option++;
ptr = parse_argument(ptr);
/* Expand tildes first, then the globs. */
expanded = real_dir_from_tilde(option);
if (glob(expanded, GLOB_ERR|GLOB_NOSORT, NULL, &files) == 0) {
for (i = 0; i < files.gl_pathc; ++i)
_parse_include(files.gl_pathv[i]);
} else {
rcfile_error(_("Error expanding %s: %s"), option,
strerror(errno));
}
/* We're done with the new syntax file. Restore the original /* We're done with the new syntax file. Restore the original
* filename and line number position. */ * filename and line number position. */
nanorc = nanorc_save; nanorc = nanorc_save;
lineno = lineno_save; lineno = lineno_save;
} }
/* Return the short value corresponding to the color named in colorname, /* Return the short value corresponding to the color named in colorname,