aboutsummaryrefslogtreecommitdiffhomepage
path: root/path.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-06-02 14:04:25 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-06-02 14:04:25 -0700
commitb7ba2529658e128bfd4b5aacb7702a13c6a9d820 (patch)
tree3242654c8485d7272e0c2a982193cab921873f18 /path.cpp
parentae12e1b5379d8cee2dd87891670536d01dbce45e (diff)
Restore implicit cd for paths starting with ., .., or ~
Diffstat (limited to 'path.cpp')
-rw-r--r--path.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/path.cpp b/path.cpp
index 1ffd9191..3dcfcadd 100644
--- a/path.cpp
+++ b/path.cpp
@@ -431,13 +431,38 @@ wchar_t *path_allocate_cdpath( const wcstring &dir, const wchar_t *wd )
}
-bool path_can_get_cdpath(const wcstring &in, const wchar_t *wd) {
+bool path_can_get_cdpath(const wcstring &in, const wchar_t *wd)
+{
wchar_t *tmp = path_allocate_cdpath(in, wd);
bool result = (tmp != NULL);
free(tmp);
return result;
}
+bool path_can_be_implicit_cd(const wcstring &path, wcstring *out_path, const wchar_t *wd)
+{
+ wcstring exp_path = path;
+ expand_tilde(exp_path);
+
+ bool result = false;
+ if (string_prefixes_string(L"/", exp_path) ||
+ string_prefixes_string(L"./", exp_path) ||
+ string_prefixes_string(L"../", exp_path) ||
+ exp_path == L"..")
+ {
+ /* These paths can be implicit cd. Note that a single period cannot (that's used for sourcing files anyways) */
+ wchar_t *cd_path = path_allocate_cdpath(exp_path, wd);
+ if (cd_path)
+ {
+ /* It worked. Return the path if desired */
+ if (out_path)
+ out_path->assign(cd_path);
+ free(cd_path);
+ result = true;
+ }
+ }
+ return result;
+}
bool path_get_config(wcstring &path)
{