summaryrefslogtreecommitdiffstats
path: root/source3/utils
diff options
context:
space:
mode:
authorChris Davis <cd.rattan@gmail.com>2014-08-02 17:29:31 -0700
committerMichael Adam <obnox@samba.org>2014-10-01 14:32:09 +0200
commitfd95b0aa96067d4c9ce60b73168bf9fe5c95ffac (patch)
treeecf924a9d5d12054cd1cb5c4c635e951e87d2d24 /source3/utils
parentbcab659516382d5dc51b1558a895a9a26d81c6b8 (diff)
downloadsamba-fd95b0aa96067d4c9ce60b73168bf9fe5c95ffac.tar.gz
samba-fd95b0aa96067d4c9ce60b73168bf9fe5c95ffac.tar.xz
samba-fd95b0aa96067d4c9ce60b73168bf9fe5c95ffac.zip
regedit: find previous items
Signed-off-by: Chris Davis <cd.rattan@gmail.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/regedit.c28
-rw-r--r--source3/utils/regedit_treeview.c41
-rw-r--r--source3/utils/regedit_treeview.h1
3 files changed, 62 insertions, 8 deletions
diff --git a/source3/utils/regedit.c b/source3/utils/regedit.c
index a5fb913e5d..34a63d74fd 100644
--- a/source3/utils/regedit.c
+++ b/source3/utils/regedit.c
@@ -222,6 +222,11 @@ static WERROR regedit_search(struct regedit *regedit, struct tree_node *node,
bool search_key, need_sync;
char *save_value_name;
WERROR rv;
+ bool (*iterate)(struct tree_node **, bool, WERROR *);
+ struct value_item *(*find_item)(struct value_list *,
+ struct value_item *,
+ const char *,
+ regedit_search_match_fn_t);
opts = &regedit->active_search;
@@ -237,6 +242,13 @@ static WERROR regedit_search(struct regedit *regedit, struct tree_node *node,
save_value_name = NULL;
search_key = opts->search_key;
need_sync = false;
+ iterate = tree_node_next;
+ find_item = value_list_find_next_item;
+
+ if (flags & SEARCH_PREV) {
+ iterate = tree_node_prev;
+ find_item = value_list_find_prev_item;
+ }
if (opts->search_value) {
struct value_item *it;
@@ -258,7 +270,7 @@ static WERROR regedit_search(struct regedit *regedit, struct tree_node *node,
if (!vitem && (flags & SEARCH_REPEAT)) {
if (opts->search_value) {
search_key = false;
- } else if (!tree_node_next(&node, opts->search_recursive, &rv)) {
+ } else if (!iterate(&node, opts->search_recursive, &rv)) {
beep();
return rv;
}
@@ -283,10 +295,8 @@ static WERROR regedit_search(struct regedit *regedit, struct tree_node *node,
}
need_sync = true;
}
- found_value = value_list_find_next_item(regedit->vl,
- vitem,
- opts->query,
- opts->match);
+ found_value = find_item(regedit->vl, vitem, opts->query,
+ opts->match);
if (found_value) {
found = node;
} else {
@@ -294,7 +304,7 @@ static WERROR regedit_search(struct regedit *regedit, struct tree_node *node,
search_key = opts->search_key;
}
}
- } while (!found && tree_node_next(&node, opts->search_recursive, &rv));
+ } while (!found && iterate(&node, opts->search_recursive, &rv));
if (!W_ERROR_IS_OK(rv)) {
goto out;
@@ -589,7 +599,7 @@ static void handle_main_input(struct regedit *regedit, int c)
if (rv == DIALOG_OK) {
SMB_ASSERT(opts->query != NULL);
opts->match = find_substring_nocase;
- node = regedit->keys->root;
+ node = regedit->keys->root->child_head;
if (opts->search_case) {
opts->match = find_substring;
}
@@ -602,9 +612,11 @@ static void handle_main_input(struct regedit *regedit, int c)
break;
}
case 'x':
- case 'X':
regedit_search_repeat(regedit, SEARCH_NEXT);
break;
+ case 'X':
+ regedit_search_repeat(regedit, SEARCH_PREV);
+ break;
case '\t':
regedit->tree_input = !regedit->tree_input;
print_heading(regedit);
diff --git a/source3/utils/regedit_treeview.c b/source3/utils/regedit_treeview.c
index cf071de3d8..4c68feab8b 100644
--- a/source3/utils/regedit_treeview.c
+++ b/source3/utils/regedit_treeview.c
@@ -342,6 +342,30 @@ static WERROR next_depth_first(struct tree_node **node)
return rv;
}
+static WERROR prev_depth_first(struct tree_node **node)
+{
+ WERROR rv = WERR_OK;
+
+ SMB_ASSERT(node != NULL && *node != NULL);
+
+ if ((*node)->previous) {
+ *node = (*node)->previous;
+ while (tree_node_has_children(*node)) {
+ rv = tree_node_load_children(*node);
+ if (W_ERROR_IS_OK(rv)) {
+ SMB_ASSERT((*node)->child_head != NULL);
+ *node = tree_node_last((*node)->child_head);
+ }
+ }
+ } else if (!tree_node_is_top_level(*node)) {
+ *node = (*node)->parent;
+ } else {
+ *node = NULL;
+ }
+
+ return rv;
+}
+
bool tree_node_next(struct tree_node **node, bool depth, WERROR *err)
{
*err = WERR_OK;
@@ -359,6 +383,23 @@ bool tree_node_next(struct tree_node **node, bool depth, WERROR *err)
return *node != NULL && W_ERROR_IS_OK(*err);
}
+bool tree_node_prev(struct tree_node **node, bool depth, WERROR *err)
+{
+ *err = WERR_OK;
+
+ if (*node == NULL) {
+ return false;
+ }
+
+ if (depth) {
+ *err = prev_depth_first(node);
+ } else {
+ *node = (*node)->previous;
+ }
+
+ return *node != NULL && W_ERROR_IS_OK(*err);
+}
+
void tree_view_clear(struct tree_view *view)
{
multilist_set_data(view->list, NULL);
diff --git a/source3/utils/regedit_treeview.h b/source3/utils/regedit_treeview.h
index ba0cd0a8ae..4b892bbb84 100644
--- a/source3/utils/regedit_treeview.h
+++ b/source3/utils/regedit_treeview.h
@@ -61,6 +61,7 @@ struct tree_node *tree_node_pop(struct tree_node **plist);
struct tree_node *tree_node_first(struct tree_node *list);
struct tree_node *tree_node_last(struct tree_node *list);
bool tree_node_next(struct tree_node **node, bool depth, WERROR *err);
+bool tree_node_prev(struct tree_node **node, bool depth, WERROR *err);
void tree_node_append_last(struct tree_node *list, struct tree_node *node);
size_t tree_node_print_path(WINDOW *label, struct tree_node *node);
const char **tree_node_get_path(TALLOC_CTX *ctx, struct tree_node *node);