Browse Source

Get rid of expand_fn callbacks

git-svn-id: https://klish.googlecode.com/svn/trunk@436 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
77f6dce4a5

+ 2 - 3
clish/command.h

@@ -21,8 +21,7 @@ typedef struct clish_command_s clish_command_t;
 /*-----------------
  * meta functions
  *----------------- */
-clish_command_t *clish_command_new(const char *name, const char *help,
-	clish_var_expand_fn_t *fn);
+clish_command_t *clish_command_new(const char *name, const char *help);
 clish_command_t *clish_command_new_link(const char *name,
 	const char *help, const clish_command_t * ref);
 clish_command_t * clish_command_alias_to_link(clish_command_t * instance);
@@ -54,7 +53,7 @@ const char *clish_command__get_escape_chars(const clish_command_t * instance);
 const clish_param_t *clish_command__get_args(const clish_command_t * instance);
 clish_action_t *clish_command__get_action(const clish_command_t *instance);
 clish_view_t *clish_command__get_view(const clish_command_t * instance);
-char *clish_command__get_viewid(const clish_command_t *instance, void *context);
+char *clish_command__get_viewid(const clish_command_t *instance);
 const unsigned clish_command__get_param_count(const clish_command_t * instance);
 const clish_param_t *clish_command__get_param(const clish_command_t * instance,
 	unsigned index);

+ 5 - 8
clish/command/command.c

@@ -18,13 +18,11 @@
  * PRIVATE METHODS
  *--------------------------------------------------------- */
 static void
-clish_command_init(clish_command_t * this, const char *name, const char *text,
-	clish_var_expand_fn_t *fn)
+clish_command_init(clish_command_t *this, const char *name, const char *text)
 {
 	/* initialise the node part */
 	this->name = lub_string_dup(name);
 	this->text = lub_string_dup(text);
-	this->var_expand_fn = fn ? fn : clish_var_expand_default;
 
 	/* Be a good binary tree citizen */
 	lub_bintree_node_init(&this->bt_node);
@@ -97,13 +95,12 @@ void clish_command_bt_getkey(const void *clientnode, lub_bintree_key_t * key)
 }
 
 /*--------------------------------------------------------- */
-clish_command_t *clish_command_new(const char *name, const char *help,
-	clish_var_expand_fn_t *fn)
+clish_command_t *clish_command_new(const char *name, const char *help)
 {
 	clish_command_t *this = malloc(sizeof(clish_command_t));
 
 	if (this)
-		clish_command_init(this, name, help, fn);
+		clish_command_init(this, name, help);
 
 	return this;
 }
@@ -284,9 +281,9 @@ void clish_command__force_viewid(clish_command_t * this, const char *viewid)
 }
 
 /*--------------------------------------------------------- */
-char *clish_command__get_viewid(const clish_command_t * this, void *context)
+char *clish_command__get_viewid(const clish_command_t * this)
 {
-	return this->var_expand_fn(this->viewid, context);
+	return this->viewid;
 }
 
 /*--------------------------------------------------------- */

+ 0 - 1
clish/command/private.h

@@ -26,5 +26,4 @@ struct clish_command_s {
 	bool_t lock;
 	bool_t interrupt;
 	bool_t dynamic; /* Is command dynamically created */
-	clish_var_expand_fn_t *var_expand_fn;
 };

+ 1 - 1
clish/nspace/nspace.c

@@ -67,7 +67,7 @@ clish_command_t * clish_nspace_create_prefix_cmd(clish_nspace_t * this,
 		this->prefix_cmd = NULL;
 	}
 
-	return (this->prefix_cmd = clish_command_new(name, help, NULL));
+	return (this->prefix_cmd = clish_command_new(name, help));
 }
 
 /*--------------------------------------------------------- */

+ 2 - 1
clish/shell/shell_execute.c

@@ -294,7 +294,8 @@ bool_t clish_shell_execute(clish_context_t *context, char **out)
 	/* Move into the new view */
 	if (BOOL_TRUE == result) {
 		clish_view_t *view = clish_command__get_view(cmd);
-		char *viewid = clish_command__get_viewid(cmd, context);
+		char *viewid = clish_shell_expand(
+			clish_command__get_viewid(cmd), context);
 		if (view) {
 			/* Save the current config PWD */
 			char *line = clish_shell__get_line(cmd, pargv);

+ 1 - 1
clish/shell/shell_view.c

@@ -14,7 +14,7 @@ clish_view_t *clish_shell_find_create_view(clish_shell_t * this,
 
 	if (NULL == view) {
 		/* create a view */
-		view = clish_view_new(name, prompt, clish_shell_expand);
+		view = clish_view_new(name, prompt);
 		assert(view);
 		clish_shell_insert_view(this, view);
 	} else {

+ 0 - 3
clish/var.h

@@ -7,9 +7,6 @@
 
 typedef struct clish_var_s clish_var_t;
 
-typedef char *clish_var_expand_fn_t(const char *str, void *context);
-char *clish_var_expand_default(const char *str, void *context);
-
 /*=====================================
  * VAR INTERFACE
  *===================================== */

+ 0 - 7
clish/var/var.c

@@ -46,13 +46,6 @@ int clish_var_bt_compare(const void *clientnode, const void *clientkey)
 	return strcmp(this->name, key);
 }
 
-/*-------------------------------------------------------- */
-clish_var_expand_fn_t clish_var_expand_default;
-inline char *clish_var_expand_default(const char *str, void *context)
-{
-	return lub_string_dup(str);
-}
-
 /*-------------------------------------------------------- */
 void clish_var_bt_getkey(const void *clientnode, lub_bintree_key_t * key)
 {

+ 1 - 2
clish/view.h

@@ -34,8 +34,7 @@ typedef enum {
 /*-----------------
  * meta functions
  *----------------- */
-clish_view_t *clish_view_new(const char *name, const char *prompt,
-	clish_var_expand_fn_t *fn);
+clish_view_t *clish_view_new(const char *name, const char *prompt);
 int clish_view_bt_compare(const void *clientnode, const void *clientkey);
 void clish_view_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
 size_t clish_view_bt_offset(void);

+ 0 - 1
clish/view/private.h

@@ -16,5 +16,4 @@ struct clish_view_s {
 	clish_nspace_t **nspacev;
 	unsigned int depth;
 	clish_view_restore_t restore;
-	clish_var_expand_fn_t *var_expand_fn;
 };

+ 4 - 8
clish/view/view.c

@@ -37,8 +37,7 @@ void clish_view_bt_getkey(const void *clientnode, lub_bintree_key_t * key)
 /*---------------------------------------------------------
  * PRIVATE METHODS
  *--------------------------------------------------------- */
-static void clish_view_init(clish_view_t * this, const char *name, const char *prompt,
-	clish_var_expand_fn_t *fn)
+static void clish_view_init(clish_view_t * this, const char *name, const char *prompt)
 {
 	/* set up defaults */
 	this->name = lub_string_dup(name);
@@ -47,7 +46,6 @@ static void clish_view_init(clish_view_t * this, const char *name, const char *p
 	this->nspacev = NULL;
 	this->depth = 0;
 	this->restore = CLISH_RESTORE_NONE;
-	this->var_expand_fn = fn ? fn : clish_var_expand_default;
 
 	/* Be a good binary tree citizen */
 	lub_bintree_node_init(&this->bt_node);
@@ -100,13 +98,12 @@ size_t clish_view_bt_offset(void)
 }
 
 /*--------------------------------------------------------- */
-clish_view_t *clish_view_new(const char *name, const char *prompt,
-	clish_var_expand_fn_t *fn)
+clish_view_t *clish_view_new(const char *name, const char *prompt)
 {
 	clish_view_t *this = malloc(sizeof(clish_view_t));
 
 	if (this)
-		clish_view_init(this, name, prompt, fn);
+		clish_view_init(this, name, prompt);
 	return this;
 }
 
@@ -124,8 +121,7 @@ clish_command_t *clish_view_new_command(clish_view_t * this,
 	const char *name, const char *help)
 {
 	/* allocate the memory for a new parameter definition */
-	clish_command_t *cmd = clish_command_new(name, help,
-		this->var_expand_fn);
+	clish_command_t *cmd = clish_command_new(name, help);
 	assert(cmd);
 
 	/* if this is a command other than the startup command... */