aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ring.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-22 05:31:31 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-22 05:31:31 +0100
commit427c9d16ce7e62cbe2671748cd8434132ce60482 (patch)
treeb3b4657c8178dcc9308790abaa1c2cf9bbc4c09b /src/ring.cpp
parent28fd3dbdc831f28c91d521e1804a9d9ff5bbf3db (diff)
downloadsciteco-427c9d16ce7e62cbe2671748cd8434132ce60482.tar.gz
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.
Diffstat (limited to 'src/ring.cpp')
-rw-r--r--src/ring.cpp41
1 files changed, 9 insertions, 32 deletions
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.
*
- * <file> may also be a glob-pattern, in which case
+ * <file> 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);
}