and += appending supported by automake to produce simpler files.
* doc/Makefile.am - Drop redundant localedir, as autoconf/automake
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>
* src/nano.c (main) - Fix compilation with --disable-utf8.
##
## All regexes should be extended regular expressions.
+# include "@PKGDATADIR@/*.nanorc"
+
+
## Key bindings
## Please see nanorc(5) for more details on this
##
## Set this if your backspace key sends delete most of the time (2.1.3+)
# 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"
#include "proto.h"
+#include <glob.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#ifdef ENABLE_COLOR
/* Read and parse additional syntax files. */
-void parse_include(char *ptr)
+static void _parse_include(char *file)
{
struct stat rcinfo;
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
our cwd depending on the parent dirs' permissions, (see Savannah bug 25297) */
/* 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) ||
S_ISBLK(rcinfo.st_mode)) {
rcfile_error(S_ISDIR(rcinfo.st_mode) ?
_("\"%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. */
- if ((rcstream = fopen(expanded, "rb")) == NULL) {
- rcfile_error(_("Error reading %s: %s"), expanded,
+ if ((rcstream = fopen(file, "rb")) == NULL) {
+ rcfile_error(_("Error reading %s: %s"), file,
strerror(errno));
return;
}
/* 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. */
- nanorc = expanded;
+ nanorc = file;
lineno = 0;
#ifdef DEBUG
- fprintf(stderr, "Parsing file \"%s\" (expanded from \"%s\")\n", expanded, option);
+ fprintf(stderr, "Parsing file \"%s\"\n", file);
#endif
parse_rcfile(rcstream
, TRUE
#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
* filename and line number position. */
nanorc = nanorc_save;
lineno = lineno_save;
-
}
/* Return the short value corresponding to the color named in colorname,