Skip to content

Commit 28e3433

Browse files
committed
to_squash: Add offset determining
1 parent f89a074 commit 28e3433

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ctl/ctl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ int umfCtlExec(const char *name, void *ctx, void *arg) {
9999
* ctl_find_node -- (internal) searches for a matching entry point in the
100100
* provided nodes
101101
*
102+
* Name offset is used to return the offset of the name in the query string.
102103
* The caller is responsible for freeing all of the allocated indexes,
103104
* regardless of the return value.
104105
*/
105106
static const struct ctl_node *ctl_find_node(const struct ctl_node *nodes,
106107
const char *name,
107-
struct ctl_index_utlist *indexes) {
108+
struct ctl_index_utlist *indexes,
109+
int *name_offset) {
108110
const struct ctl_node *n = NULL;
109111
char *sptr = NULL;
110112
char *parse_str = Strdup(name);
@@ -119,6 +121,7 @@ static const struct ctl_node *ctl_find_node(const struct ctl_node *nodes,
119121
* in the main ctl tree.
120122
*/
121123
while (node_name != NULL) {
124+
*name_offset = node_name - parse_str;
122125
if (n != NULL && n->type == CTL_NODE_SUBTREE) {
123126
break;
124127
}
@@ -362,13 +365,15 @@ int ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source,
362365
}
363366

364367
int ret = -1;
368+
int name_offset = 0;
365369

366-
const struct ctl_node *n = ctl_find_node(CTL_NODE(global), name, indexes);
370+
const struct ctl_node *n =
371+
ctl_find_node(CTL_NODE(global), name, indexes, &name_offset);
367372

368373
if (n == NULL && ctl) {
369374
ctl_delete_indexes(indexes);
370375
indexes = NULL;
371-
n = ctl_find_node(ctl->root, name, indexes);
376+
n = ctl_find_node(ctl->root, name, indexes, &name_offset);
372377
}
373378

374379
if (n == NULL ||

0 commit comments

Comments
 (0)