|
@@ -28,20 +28,30 @@ static void clish_nspace_init(clish_nspace_t * this, clish_view_t * view)
|
|
|
this->context_help = BOOL_FALSE;
|
|
|
this->inherit = BOOL_TRUE;
|
|
|
this->prefix_cmd = NULL;
|
|
|
- this->proxy_cmd = NULL;
|
|
|
+
|
|
|
+
|
|
|
+ lub_bintree_init(&this->tree,
|
|
|
+ clish_command_bt_offset(),
|
|
|
+ clish_command_bt_compare, clish_command_bt_getkey);
|
|
|
}
|
|
|
|
|
|
|
|
|
static void clish_nspace_fini(clish_nspace_t * this)
|
|
|
{
|
|
|
+ clish_command_t *cmd;
|
|
|
+
|
|
|
|
|
|
lub_string_free(this->prefix);
|
|
|
this->prefix = NULL;
|
|
|
+
|
|
|
+ while ((cmd = lub_bintree_findfirst(&this->tree))) {
|
|
|
+
|
|
|
+ lub_bintree_remove(&this->tree, cmd);
|
|
|
|
|
|
- if (this->proxy_cmd) {
|
|
|
- clish_command_delete(this->proxy_cmd);
|
|
|
- this->proxy_cmd = NULL;
|
|
|
+
|
|
|
+ clish_command_delete(cmd);
|
|
|
}
|
|
|
+
|
|
|
if (this->prefix_cmd) {
|
|
|
clish_command_delete(this->prefix_cmd);
|
|
|
this->prefix_cmd = NULL;
|
|
@@ -64,29 +74,37 @@ clish_command_t * clish_nspace_create_prefix_cmd(clish_nspace_t * this,
|
|
|
static clish_command_t *clish_nspace_find_create_command(clish_nspace_t * this,
|
|
|
const char *prefix, const clish_command_t * ref)
|
|
|
{
|
|
|
+ clish_command_t *cmd;
|
|
|
char *name = NULL;
|
|
|
|
|
|
- if (this->proxy_cmd) {
|
|
|
- clish_command_delete(this->proxy_cmd);
|
|
|
- this->proxy_cmd = NULL;
|
|
|
- }
|
|
|
-
|
|
|
assert(prefix);
|
|
|
if (!ref) {
|
|
|
assert(this->prefix_cmd);
|
|
|
- this->proxy_cmd = clish_command_new_link(prefix, this->prefix_cmd);
|
|
|
- return this->proxy_cmd;
|
|
|
+ name = lub_string_dup(prefix);
|
|
|
+ ref = this->prefix_cmd;
|
|
|
+ } else {
|
|
|
+ lub_string_catn(&name, prefix, strlen(prefix));
|
|
|
+ lub_string_catn(&name, " ", 1);
|
|
|
+ lub_string_catn(&name, clish_command__get_name(ref),
|
|
|
+ strlen(clish_command__get_name(ref)));
|
|
|
}
|
|
|
|
|
|
- lub_string_catn(&name, prefix, strlen(prefix));
|
|
|
- lub_string_catn(&name, " ", 1);
|
|
|
- lub_string_catn(&name, clish_command__get_name(ref),
|
|
|
- strlen(clish_command__get_name(ref)));
|
|
|
-
|
|
|
- this->proxy_cmd = clish_command_new_link(name, ref);
|
|
|
+
|
|
|
+ if (cmd = lub_bintree_find(&this->tree, name)) {
|
|
|
+ free(name);
|
|
|
+ return cmd;
|
|
|
+ }
|
|
|
+ cmd = clish_command_new_link(name, ref);
|
|
|
free(name);
|
|
|
+ assert(cmd);
|
|
|
+
|
|
|
+
|
|
|
+ if (-1 == lub_bintree_insert(&this->tree, cmd)) {
|
|
|
+ clish_command_delete(cmd);
|
|
|
+ cmd = NULL;
|
|
|
+ }
|
|
|
|
|
|
- return this->proxy_cmd;
|
|
|
+ return cmd;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -113,7 +131,7 @@ void clish_nspace_delete(clish_nspace_t * this)
|
|
|
|
|
|
|
|
|
static const char *clish_nspace_after_prefix(const char *prefix,
|
|
|
- const char *line)
|
|
|
+ const char *line)
|
|
|
{
|
|
|
const char *in_line = NULL;
|
|
|
regex_t regexp;
|
|
@@ -131,15 +149,7 @@ static const char *clish_nspace_after_prefix(const char *prefix,
|
|
|
return NULL;
|
|
|
in_line = line + pmatch[0].rm_eo;
|
|
|
|
|
|
-
|
|
|
- if (in_line[0] == '\0')
|
|
|
- return NULL;
|
|
|
-
|
|
|
-
|
|
|
- if (in_line[0] != ' ')
|
|
|
- return NULL;
|
|
|
-
|
|
|
- return (in_line + 1);
|
|
|
+ return in_line;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -153,10 +163,19 @@ clish_command_t *clish_nspace_find_command(clish_nspace_t * this, const char *na
|
|
|
if (!prefix)
|
|
|
return clish_view_find_command(view, name, this->inherit);
|
|
|
|
|
|
+
|
|
|
if (!(in_line = clish_nspace_after_prefix(prefix, name)))
|
|
|
return NULL;
|
|
|
|
|
|
- cmd = clish_view_find_command(view, in_line, this->inherit);
|
|
|
+
|
|
|
+ if (in_line[0] == ' ')
|
|
|
+ in_line++;
|
|
|
+
|
|
|
+ if (in_line[0] != '\0') {
|
|
|
+ cmd = clish_view_find_command(view, in_line, this->inherit);
|
|
|
+ if (!cmd)
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
|
|
|
return clish_nspace_find_create_command(this, prefix, cmd);
|
|
|
}
|
|
@@ -174,9 +193,14 @@ const clish_command_t *clish_nspace_find_next_completion(clish_nspace_t * this,
|
|
|
if (!prefix)
|
|
|
return clish_view_find_next_completion(view, iter_cmd, line, field, this->inherit);
|
|
|
|
|
|
+
|
|
|
if (!(in_line = clish_nspace_after_prefix(prefix, line)))
|
|
|
return NULL;
|
|
|
|
|
|
+ if (in_line[0] != '\0') {
|
|
|
+
|
|
|
+ if (in_line[0] == ' ')
|
|
|
+ in_line++;
|
|
|
if (iter_cmd &&
|
|
|
(lub_string_nocasestr(iter_cmd, prefix) == iter_cmd) &&
|
|
|
(lub_string_nocasecmp(iter_cmd, prefix)))
|
|
@@ -184,6 +208,10 @@ const clish_command_t *clish_nspace_find_next_completion(clish_nspace_t * this,
|
|
|
cmd = clish_view_find_next_completion(view, in_iter, in_line, field, this->inherit);
|
|
|
if (!cmd)
|
|
|
return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!cmd && iter_cmd && !lub_string_nocasecmp(iter_cmd, prefix))
|
|
|
+ return NULL;
|
|
|
|
|
|
return clish_nspace_find_create_command(this, prefix, cmd);
|
|
|
}
|
|
@@ -260,7 +288,7 @@ bool_t clish_nspace__get_inherit(const clish_nspace_t * this)
|
|
|
|
|
|
bool_t
|
|
|
clish_nspace__get_visibility(const clish_nspace_t * instance,
|
|
|
- clish_nspace_visibility_t field)
|
|
|
+ clish_nspace_visibility_t field)
|
|
|
{
|
|
|
bool_t result = BOOL_FALSE;
|
|
|
|