浏览代码

Add action field to clish_ptype_t struct

Serj Kalichev 6 年之前
父节点
当前提交
f20b9c3bcf
共有 5 个文件被更改,包括 12 次插入3 次删除
  1. 2 0
      clish/ptype.h
  2. 1 0
      clish/ptype/private.h
  3. 3 0
      clish/ptype/ptype.c
  4. 5 2
      clish/shell/shell_xml.c
  5. 1 1
      clish/var/var.c

+ 2 - 0
clish/ptype.h

@@ -12,6 +12,7 @@ typedef struct clish_ptype_s clish_ptype_t;
 #include "clish/macros.h"
 #include "lub/bintree.h"
 #include "lub/argv.h"
+#include "clish/action.h"
 
 #include <stddef.h>
 
@@ -104,6 +105,7 @@ _CLISH_SET_STR_ONCE(ptype, text);
 _CLISH_GET_STR(ptype, text);
 _CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
 _CLISH_GET_STR(ptype, range);
+_CLISH_GET(ptype, clish_action_t *, action);
 
 void clish_ptype__set_pattern(clish_ptype_t * instance,
 	const char *pattern, clish_ptype_method_e method);

+ 1 - 0
clish/ptype/private.h

@@ -33,4 +33,5 @@ struct clish_ptype_s {
 		clish_ptype_integer_t integer;
 		clish_ptype_select_t select;
 	} u;
+	clish_action_t *action;
 };

+ 3 - 0
clish/ptype/ptype.c

@@ -375,6 +375,7 @@ static void clish_ptype_init(clish_ptype_t * this,
 	this->pattern = NULL;
 	this->preprocess = preprocess;
 	this->range = NULL;
+	this->action = clish_action_new();
 
 	/* Be a good binary tree citizen */
 	lub_bintree_node_init(&this->bt_node);
@@ -441,6 +442,7 @@ static void clish_ptype_fini(clish_ptype_t * this)
 	this->pattern = NULL;
 	lub_string_free(this->range);
 	this->range = NULL;
+	clish_action_delete(this->action);
 }
 
 /*--------------------------------------------------------- */
@@ -455,6 +457,7 @@ CLISH_SET_STR_ONCE(ptype, text);
 CLISH_GET_STR(ptype, text);
 CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
 CLISH_GET_STR(ptype, range);
+CLISH_GET(ptype, clish_action_t *, action);
 
 /*--------------------------------------------------------- */
 void clish_ptype__set_pattern(clish_ptype_t * this,

+ 5 - 2
clish/shell/shell_xml.c

@@ -373,6 +373,7 @@ static int process_ptype(clish_shell_t *shell, clish_xmlnode_t *element,
 	clish_ptype_method_e method;
 	clish_ptype_preprocess_e preprocess;
 	int res = -1;
+	clish_ptype_t *ptype;
 
 	char *name = clish_xmlnode_fetch_attr(element, "name");
 	char *help = clish_xmlnode_fetch_attr(element, "help");
@@ -393,10 +394,10 @@ static int process_ptype(clish_shell_t *shell, clish_xmlnode_t *element,
 	method = clish_ptype_method_resolve(method_name);
 
 	preprocess = clish_ptype_preprocess_resolve(preprocess_name);
-	clish_shell_find_create_ptype(shell,
+	ptype = clish_shell_find_create_ptype(shell,
 		name, help, pattern, method, preprocess);
 
-	res = 0;
+	res = process_children(shell, element, ptype);
 error:
 	clish_xml_release(name);
 	clish_xml_release(help);
@@ -876,6 +877,8 @@ static int process_action(clish_shell_t *shell, clish_xmlnode_t *element,
 
 	if (pname && lub_string_nocasecmp(pname, "VAR") == 0)
 		action = clish_var__get_action((clish_var_t *)parent);
+	else if (pname && lub_string_nocasecmp(pname, "PTYPE") == 0)
+		action = clish_ptype__get_action((clish_ptype_t *)parent);
 	else
 		action = clish_command__get_action((clish_command_t *)parent);
 

+ 1 - 1
clish/var/var.c

@@ -29,8 +29,8 @@ static void clish_var_fini(clish_var_t *this)
 {
 	lub_string_free(this->name);
 	lub_string_free(this->value);
-	clish_action_delete(this->action);
 	lub_string_free(this->saved);
+	clish_action_delete(this->action);
 }
 
 /*--------------------------------------------------------- */