aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-06-12 15:12:59 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-06-12 15:12:59 +0200
commit7919aca84cdea7746b60fec9795e9617c266dd1d (patch)
tree90db8c7d899b69014d085af0cf3327741691df6a /src/parser.cpp
parent3551924ccd580a59190ac80e25c59b729ec4f613 (diff)
downloadsciteco-7919aca84cdea7746b60fec9795e9617c266dd1d.tar.gz
support UNIX-shell-like tilde-expansions in file names and directories
* expands to the value of $HOME (the env variable instead of the register which currently makes a slight difference). * supported for tab-completions * supported for all file-name accepting commands. The expansion is done centrally in StateExpectFile::done(). A new virtual method StateExpectFile::got_file() has been introduced to pass the expanded/processed file name to command implementations. * sciteco(7) has been updated: There is now a separate section on file name arguments and file name handling in SciTECO. This information is important but has been scattered across the document previously. * optimized is_glob_pattern() in glob.h
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 6462933..3e3f387 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -40,6 +40,7 @@
#include "spawn.h"
#include "glob.h"
#include "cmdline.h"
+#include "ioview.h"
#include "error.h"
namespace SciTECO {
@@ -473,6 +474,7 @@ StateExpectString::custom(gchar chr)
if (string_building)
machine.reset();
+ /* FIXME: possible memleak because of `string`? */
next = done(string ? : "");
g_free(string);
return next;
@@ -502,6 +504,23 @@ StateExpectString::custom(gchar chr)
return this;
}
+State *
+StateExpectFile::done(const gchar *str)
+{
+ gchar *filename = expand_path(str);
+ State *next;
+
+ try {
+ next = got_file(filename);
+ } catch (...) {
+ g_free(filename);
+ throw;
+ }
+
+ g_free(filename);
+ return next;
+}
+
StateStart::StateStart() : State()
{
transitions['\0'] = this;
@@ -1579,8 +1598,9 @@ UndoTokenChangeDir::run(void)
* as set by the \fBHOME\fP environment variable.
* This variable is alwas initialized by \*(ST
* (see \fBsciteco\fP(1)).
- * Therefore \(lqFG\fB$\fP\(rq is roughly equivalent
- * to \(lqFG^EQ[$HOME]\fB$\fP\(rq.
+ * Therefore the expression \(lqFG\fB$\fP\(rq is
+ * roughly equivalent to both \(lqFG~\fB$\fP\(rq and
+ * \(lqFG^EQ[$HOME]\fB$\fP\(rq.
*
* The current working directory is also mapped to
* the Q-Register \(lq$\(rq (dollar sign) which
@@ -1590,20 +1610,20 @@ UndoTokenChangeDir::run(void)
* command and directories can be tab-completed.
*/
State *
-StateChangeDir::done(const gchar *str)
+StateChangeDir::got_file(const gchar *filename)
{
BEGIN_EXEC(&States::start);
/* passes ownership of string to undo token object */
undo.push(new UndoTokenChangeDir(g_get_current_dir()));
- if (!*str)
- str = g_getenv("HOME");
+ if (!*filename)
+ filename = g_getenv("HOME");
- if (g_chdir(str))
+ if (g_chdir(filename))
/* FIXME: Is errno usable on Windows here? */
throw Error("Cannot change working directory "
- "to \"%s\"", str);
+ "to \"%s\"", filename);
return &States::start;
}