From 427c9d16ce7e62cbe2671748cd8434132ce60482 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 22 Nov 2014 05:31:31 +0100 Subject: added globbing command EN * implements the same globbing as the EB command already did * uses Globber helper class that behaves more like UNIX glob(). glib only has a glob-style pattern matcher. * The Globber class may be extended later to provide more UNIX-like globbing. * lexer.tes has been updated to make use of globbing. Now, lexers can be automatically loaded and registered at startup. To install a new lexer, it's sufficient to copy a file to the lexers/ directory. --- src/ring.cpp | 41 +++++++++-------------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) (limited to 'src/ring.cpp') diff --git a/src/ring.cpp b/src/ring.cpp index 575d0e7..03cda37 100644 --- a/src/ring.cpp +++ b/src/ring.cpp @@ -38,8 +38,9 @@ #include "parser.h" #include "expressions.h" #include "qregisters.h" -#include "ring.h" +#include "glob.h" #include "error.h" +#include "ring.h" #ifdef HAVE_WINDOWS_H /* here it shouldn't cause conflicts with other headers */ @@ -600,8 +601,10 @@ StateEditFile::do_edit(tecoInt id) * Naturally this only has any effect in interactive * mode. * - * may also be a glob-pattern, in which case + * may also be a glob pattern, in which case * all files matching the pattern are opened/edited. + * Globbing is performed exactly the same as the + * EN command does. * * File names of buffers in the ring are normalized * by making them absolute. @@ -661,37 +664,11 @@ StateEditFile::done(const gchar *str) } if (is_glob_pattern(str)) { - gchar *dirname; - GDir *dir; - - dirname = g_path_get_dirname(str); - dir = g_dir_open(dirname, 0, NULL); - - if (dir) { - const gchar *basename; - GPatternSpec *pattern; - - basename = g_path_get_basename(str); - pattern = g_pattern_spec_new(basename); - g_free((gchar *)basename); - - while ((basename = g_dir_read_name(dir))) { - if (g_pattern_match_string(pattern, basename)) { - gchar *filename; - - filename = g_build_filename(dirname, - basename, - NIL); - do_edit(filename); - g_free(filename); - } - } - - g_pattern_spec_free(pattern); - g_dir_close(dir); - } + Globber globber(str); + gchar *filename; - g_free(dirname); + while ((filename = globber.next())) + do_edit(filename); } else { do_edit(*str ? str : NULL); } -- cgit v1.2.3