Browse Source

New function clish_pargv_find_value

Useful because it allows more convenient access to param values in plugin actions.

Many of my actions use parameters instead of parsing the action script.
Ingo Albrecht 3 years ago
parent
commit
c74e823f94
3 changed files with 13 additions and 3 deletions
  1. 2 0
      clish/pargv.h
  2. 10 0
      clish/pargv/pargv.c
  3. 1 3
      clish/shell/shell_var.c

+ 2 - 0
clish/pargv.h

@@ -28,6 +28,8 @@ clish_pargv_t *clish_pargv_new(void);
 void clish_pargv_delete(clish_pargv_t * instance);
 const clish_parg_t *clish_pargv_find_arg(clish_pargv_t * instance,
 	const char *name);
+const char *clish_pargv_find_value(clish_pargv_t * instance,
+	const char *name);
 int clish_pargv_insert(clish_pargv_t * instance,
 	const clish_param_t * param, const char *value);
 clish_pargv_t *clish_pargv_clone(const clish_pargv_t *src);

+ 10 - 0
clish/pargv/pargv.c

@@ -161,3 +161,13 @@ const clish_parg_t *clish_pargv_find_arg(clish_pargv_t * this, const char *name)
 }
 
 /*--------------------------------------------------------- */
+const char *clish_pargv_find_value(clish_pargv_t * this, const char *name)
+{
+	clish_parg_t *parg;
+	if (!this)
+		return NULL;
+	parg = find_parg(this, name);
+	if (!parg)
+		return NULL;
+	return clish_parg__get_value(parg);
+}

+ 1 - 3
clish/shell/shell_var.c

@@ -511,9 +511,7 @@ char *clish_shell_expand_var_ex(const char *name, clish_context_t *context, clis
 
 	/* try and substitute a parameter value */
 	if (pargv && (flags & SHELL_EXPAND_PARAM)) {
-		const clish_parg_t *parg = clish_pargv_find_arg(pargv, name);
-		if (parg)
-			tmp = clish_parg__get_value(parg);
+		tmp = clish_pargv_find_value(pargv, name);
 	}
 
 	/* try and substitute the param's default */