nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] support globs in include paths


From: Mike Frysinger
Subject: [Nano-devel] [PATCH] support globs in include paths
Date: Sat, 29 Mar 2014 01:11:34 -0400

Hard listing all the files is a pita.  Support globs in include paths
so people can easily drop in new files and have it "just work".
---
 doc/nanorc.sample.in | 97 ++--------------------------------------------------
 src/rcfile.c         | 48 +++++++++++++++++---------
 2 files changed, 34 insertions(+), 111 deletions(-)

diff --git a/doc/nanorc.sample.in b/doc/nanorc.sample.in
index e357a83..e6a96ef 100644
--- a/doc/nanorc.sample.in
+++ b/doc/nanorc.sample.in
@@ -228,6 +228,9 @@
 ##
 ## All regexes should be extended regular expressions.
 
+# include "@PKGDATADIR@/*.nanorc"
+
+
 ## Key bindings
 ## 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+)
 # 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"
diff --git a/src/rcfile.c b/src/rcfile.c
index 2d00871..4e73324 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -23,6 +23,7 @@
 
 #include "proto.h"
 
+#include <glob.h>
 #include <stdarg.h>
 #include <string.h>
 #include <stdio.h>
@@ -620,47 +621,38 @@ void parse_unbinding(char *ptr)
 
 #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
@@ -668,12 +660,34 @@ void parse_include(char *ptr)
        , 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,
-- 
1.9.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]