aboutsummaryrefslogtreecommitdiff
path: root/src/navigator.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-20 11:43:38 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-20 11:43:38 +0000
commit81091690ba8794b38536b2f171ae56cf714295d7 (patch)
tree440bc6bd5e52d631662fe945981cec6c3ac380d1 /src/navigator.c
parentf0448375624d7d81808995ebb3a2f9352c21dfc4 (diff)
downloadimv-81091690ba8794b38536b2f171ae56cf714295d7.tar.gz
Add support for -n PATH starting specifier
Fixes #36
Diffstat (limited to 'src/navigator.c')
-rw-r--r--src/navigator.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/navigator.c b/src/navigator.c
index d719791..7ece6a0 100644
--- a/src/navigator.c
+++ b/src/navigator.c
@@ -185,6 +185,27 @@ void imv_navigator_set_path(struct imv_navigator *nav, const int path)
nav->changed = prev_path != nav->cur_path;
}
+int imv_navigator_find_path(struct imv_navigator *nav, const char *path)
+{
+ /* first try to match the exact path */
+ for(int i = 0; i < nav->num_paths; ++i) {
+ if(strcmp(path, nav->paths[i]) == 0) {
+ return i;
+ }
+ }
+
+ /* no exact matches, try the final portion of the path */
+ for(int i = 0; i < nav->num_paths; ++i) {
+ char *last_sep = strrchr(nav->paths[i], '/');
+ if(last_sep && strcmp(last_sep+1, path) == 0) {
+ return i;
+ }
+ }
+
+ /* no matches at all, give up */
+ return -1;
+}
+
int imv_navigator_has_changed(struct imv_navigator *nav)
{
if(nav->changed) {