Browse Source

Macros for clish_plugin_t

Serj Kalichev 6 years ago
parent
commit
95ec186ccf

+ 10 - 36
clish/pargv.h

@@ -1,14 +1,7 @@
 /*
  * pargv.h
+ * This class represents a vector of command line arguments.
  */
- /**
-\ingroup clish
-\defgroup clish_pargv pargv
-@{
-
-\brief This class represents a vector of command line arguments.
-
-*/
 
 #ifndef _clish_pargv_h
 #define _clish_pargv_h
@@ -28,16 +21,10 @@ typedef struct clish_parg_s clish_parg_t;
 #include "clish/command.h"
 #include "clish/param.h"
 
-/*=====================================
- * PARGV INTERFACE
- *===================================== */
-/*-----------------
- * meta functions
- *----------------- */
+/* Class pargv */
+
 clish_pargv_t *clish_pargv_new(void);
-/*-----------------
- * methods
- *----------------- */
+
 void clish_pargv_delete(clish_pargv_t * instance);
 const clish_parg_t *clish_pargv_find_arg(clish_pargv_t * instance,
 	const char *name);
@@ -45,31 +32,18 @@ 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);
 void clish_pargv_dump(const clish_pargv_t * instance);
-/*-----------------
- * attributes
- *----------------- */
+
 unsigned clish_pargv__get_count(clish_pargv_t * instance);
 clish_parg_t *clish_pargv__get_parg(clish_pargv_t * instance, unsigned index);
 const clish_param_t *clish_pargv__get_param(clish_pargv_t * instance,
 	unsigned index);
 
-/*=====================================
- * PARG INTERFACE
- *===================================== */
-/*-----------------
- * meta functions
- *----------------- */
-/*-----------------
- * methods
- *----------------- */
+/* Class parg */
+
 void clish_parg_dump(const clish_parg_t * instance);
 
-/*-----------------
- * attributes 
- *----------------- */
-const char *clish_parg__get_name(const clish_parg_t * instance);
-const char *clish_parg__get_value(const clish_parg_t * instance);
-const clish_ptype_t *clish_parg__get_ptype(const clish_parg_t * instance);
+_CLISH_GET_STR(parg, value);
+_CLISH_GET_STR(parg, name);
+_CLISH_GET(parg, clish_ptype_t *, ptype);
 
 #endif				/* _clish_pargv_h */
-/** @} clish_pargv */

+ 1 - 0
clish/pargv/module.am

@@ -1,4 +1,5 @@
 libclish_la_SOURCES += \
 	clish/pargv/pargv.c \
+	clish/pargv/parg.c \
 	clish/pargv/pargv_dump.c \
 	clish/pargv/private.h

+ 0 - 24
clish/pargv/pargv.c

@@ -152,30 +152,6 @@ const clish_param_t *clish_pargv__get_param(clish_pargv_t * this,
 	return tmp->param;
 }
 
-/*--------------------------------------------------------- */
-const char *clish_parg__get_value(const clish_parg_t * this)
-{
-	if (!this)
-		return NULL;
-	return this->value;
-}
-
-/*--------------------------------------------------------- */
-const char *clish_parg__get_name(const clish_parg_t * this)
-{
-	if (!this)
-		return NULL;
-	return clish_param__get_name(this->param);
-}
-
-/*--------------------------------------------------------- */
-const clish_ptype_t *clish_parg__get_ptype(const clish_parg_t * this)
-{
-	if (!this)
-		return NULL;
-	return clish_param__get_ptype(this->param);
-}
-
 /*--------------------------------------------------------- */
 const clish_parg_t *clish_pargv_find_arg(clish_pargv_t * this, const char *name)
 {

+ 29 - 29
clish/plugin.h

@@ -72,19 +72,20 @@ extern clish_plugin_builtin_list_t clish_plugin_builtin_list[];
 int clish_sym_compare(const void *first, const void *second);
 clish_sym_t *clish_sym_new(const char *name, void *func, int type);
 void clish_sym_free(clish_sym_t *instance);
-void clish_sym__set_func(clish_sym_t *instance, void *func);
+int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
+
+_CLISH_SET(sym, const void *, func);
 _CLISH_GET(sym, const void *, func);
-void clish_sym__set_name(clish_sym_t *instance, const char *name);
-char *clish_sym__get_name(clish_sym_t *instance);
-void clish_sym__set_permanent(clish_sym_t *instance, bool_t permanent);
+_CLISH_SET(sym, bool_t, permanent);
 _CLISH_GET(sym, bool_t, permanent);
-void clish_sym__set_plugin(clish_sym_t *instance, clish_plugin_t *plugin);
-clish_plugin_t *clish_sym__get_plugin(clish_sym_t *instance);
-void clish_sym__set_type(clish_sym_t *instance, int type);
-int clish_sym__get_type(const clish_sym_t *instance);
-void clish_sym__set_api(clish_sym_t *instance, clish_sym_api_e api);
-clish_sym_api_e clish_sym__get_api(const clish_sym_t *instance);
-int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
+_CLISH_SET_STR(sym, name);
+_CLISH_GET_STR(sym, name);
+_CLISH_SET(sym, clish_plugin_t *, plugin);
+_CLISH_GET(sym, clish_plugin_t *, plugin);
+_CLISH_SET(sym, int, type);
+_CLISH_GET(sym, int, type);
+_CLISH_SET(sym, clish_sym_api_e, api);
+_CLISH_GET(sym, clish_sym_api_e, api);
 
 /* Plugin */
 
@@ -107,25 +108,24 @@ clish_sym_t *clish_plugin_add_hook(clish_plugin_t *instance,
 	void *func, const char *name, int type);
 clish_sym_t *clish_plugin_add_phook(clish_plugin_t *instance,
 	void *func, const char *name, int type);
-void clish_plugin_add_fini(clish_plugin_t *instance,
-	clish_plugin_fini_t *fini);
-clish_plugin_fini_t * clish_plugin_get_fini(clish_plugin_t *instance);
-void clish_plugin_add_init(clish_plugin_t *instance,
-	clish_plugin_init_t *init);
-clish_plugin_init_t * clish_plugin_get_init(clish_plugin_t *instance);
 void clish_plugin_dump(const clish_plugin_t *instance);
-char *clish_plugin__get_name(const clish_plugin_t *instance);
-void clish_plugin__set_alias(clish_plugin_t *instance, const char *alias);
-char *clish_plugin__get_alias(const clish_plugin_t *instance);
-char *clish_plugin__get_pubname(const clish_plugin_t *instance);
-void clish_plugin__set_file(clish_plugin_t *instance, const char *file);
-char *clish_plugin__get_file(const clish_plugin_t *instance);
-void clish_plugin__set_builtin_flag(clish_plugin_t *instance, bool_t builtin_flag);
-bool_t clish_plugin__get_builtin_flag(const clish_plugin_t *instance);
-void clish_plugin__set_conf(clish_plugin_t *instance, const char *conf);
-char *clish_plugin__get_conf(const clish_plugin_t *instance);
-void clish_plugin__set_rtld_global(clish_plugin_t *instance, bool_t rtld_global);
-bool_t clish_plugin__get_rtld_global(const clish_plugin_t *instance);
+
+_CLISH_SET(plugin, clish_plugin_fini_t *, fini);
+_CLISH_GET(plugin, clish_plugin_fini_t *, fini);
+_CLISH_SET(plugin, clish_plugin_init_t *, init);
+_CLISH_GET(plugin, clish_plugin_init_t *, init);
+_CLISH_GET_STR(plugin, name);
+_CLISH_SET_STR(plugin, alias);
+_CLISH_GET_STR(plugin, alias);
+_CLISH_SET_STR(plugin, file);
+_CLISH_GET_STR(plugin, file);
+_CLISH_SET_STR(plugin, conf);
+_CLISH_GET_STR(plugin, conf);
+_CLISH_SET(plugin, bool_t, builtin_flag);
+_CLISH_GET(plugin, bool_t, builtin_flag);
+_CLISH_SET(plugin, bool_t, rtld_global);
+_CLISH_GET(plugin, bool_t, rtld_global);
+_CLISH_GET_STR(plugin, pubname);
 
 #endif				/* _clish_plugin_h */
 /** @} clish_plugin */

+ 1 - 0
clish/plugin/module.am

@@ -1,4 +1,5 @@
 libclish_la_SOURCES += \
 	clish/plugin/plugin.c \
+	clish/plugin/sym.c \
 	clish/plugin/plugin_dump.c \
 	clish/plugin/private.h

+ 18 - 217
clish/plugin/plugin.c

@@ -18,126 +18,6 @@
 #include <dlfcn.h>
 #endif
 
-/**********************************************************
- * SYM functions                                          *
- **********************************************************/
-
-/*--------------------------------------------------------- */
-int clish_sym_compare(const void *first, const void *second)
-{
-	const clish_sym_t *f = (const clish_sym_t *)first;
-	const clish_sym_t *s = (const clish_sym_t *)second;
-
-	return strcmp(f->name, s->name);
-}
-
-/*--------------------------------------------------------- */
-clish_sym_t *clish_sym_new(const char *name, void *func, int type)
-{
-	clish_sym_t *this;
-
-	this = malloc(sizeof(*this));
-	this->name = lub_string_dup(name);
-	this->func = func;
-	this->type = type;
-	this->api = CLISH_SYM_API_SIMPLE;
-	this->permanent = BOOL_FALSE;
-
-	return this;
-}
-
-/*--------------------------------------------------------- */
-void clish_sym_free(clish_sym_t *this)
-{
-	if (!this)
-		return;
-	lub_string_free(this->name);
-	free(this);
-}
-
-/*--------------------------------------------------------- */
-void clish_sym__set_func(clish_sym_t *this, void *func)
-{
-	this->func = func;
-}
-
-CLISH_GET(sym, const void *, func);
-
-/*--------------------------------------------------------- */
-void clish_sym__set_permanent(clish_sym_t *this, bool_t permanent)
-{
-	this->permanent = permanent;
-}
-
-CLISH_GET(sym, bool_t, permanent);
-
-/*--------------------------------------------------------- */
-void clish_sym__set_name(clish_sym_t *this, const char *name)
-{
-	lub_string_free(this->name);
-	this->name = lub_string_dup(name);
-}
-
-/*--------------------------------------------------------- */
-char *clish_sym__get_name(clish_sym_t *this)
-{
-	return this->name;
-}
-
-/*--------------------------------------------------------- */
-void clish_sym__set_plugin(clish_sym_t *this, clish_plugin_t *plugin)
-{
-	this->plugin = plugin;
-}
-
-/*--------------------------------------------------------- */
-clish_plugin_t *clish_sym__get_plugin(clish_sym_t *this)
-{
-	return this->plugin;
-}
-
-/*--------------------------------------------------------- */
-void clish_sym__set_type(clish_sym_t *this, int type)
-{
-	this->type = type;
-}
-
-/*--------------------------------------------------------- */
-int clish_sym__get_type(const clish_sym_t *this)
-{
-	return this->type;
-}
-
-/*--------------------------------------------------------- */
-void clish_sym__set_api(clish_sym_t *this, clish_sym_api_e api)
-{
-	this->api = api;
-}
-
-/*--------------------------------------------------------- */
-clish_sym_api_e clish_sym__get_api(const clish_sym_t *this)
-{
-	return this->api;
-}
-
-/*--------------------------------------------------------- */
-int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src)
-{
-	char *name;
-
-	if (!dst || !src)
-		return -1;
-	name = dst->name;
-	*dst = *src;
-	dst->name = name;
-
-	return 0;
-}
-
-/**********************************************************
- * PLUGIN functions                                       *
- **********************************************************/
-
 /*--------------------------------------------------------- */
 clish_plugin_t *clish_plugin_new(const char *name)
 {
@@ -275,31 +155,6 @@ clish_sym_t *clish_plugin_add_phook(clish_plugin_t *this,
 		name, type, BOOL_TRUE);
 }
 
-/*--------------------------------------------------------- */
-void clish_plugin_add_fini(clish_plugin_t *this,
-	clish_plugin_fini_t *fini)
-{
-	this->fini = fini;
-}
-
-/*--------------------------------------------------------- */
-clish_plugin_fini_t * clish_plugin_get_fini(clish_plugin_t *this)
-{
-	return this->fini;
-}
-
-/*--------------------------------------------------------- */
-void clish_plugin_add_init(clish_plugin_t *this,
-	clish_plugin_init_t *init)
-{
-	this->init = init;
-}
-
-/*--------------------------------------------------------- */
-clish_plugin_init_t * clish_plugin_get_init(clish_plugin_t *this)
-{
-	return this->init;
-}
 
 /*--------------------------------------------------------- */
 clish_sym_t *clish_plugin_get_sym(clish_plugin_t *this, const char *name, int type)
@@ -399,79 +254,25 @@ int clish_plugin_load(clish_plugin_t *this, void *userdata)
 	return res;
 }
 
-/*--------------------------------------------------------- */
-char *clish_plugin__get_name(const clish_plugin_t *this)
-{
-	return this->name;
-}
+CLISH_SET(plugin, clish_plugin_fini_t *, fini);
+CLISH_GET(plugin, clish_plugin_fini_t *, fini);
+CLISH_SET(plugin, clish_plugin_init_t *, init);
+CLISH_GET(plugin, clish_plugin_init_t *, init);
+CLISH_GET_STR(plugin, name);
+CLISH_SET_STR(plugin, alias);
+CLISH_GET_STR(plugin, alias);
+CLISH_SET_STR(plugin, file);
+CLISH_GET_STR(plugin, file);
+CLISH_SET_STR(plugin, conf);
+CLISH_GET_STR(plugin, conf);
+CLISH_SET(plugin, bool_t, builtin_flag);
+CLISH_GET(plugin, bool_t, builtin_flag);
+CLISH_SET(plugin, bool_t, rtld_global);
+CLISH_GET(plugin, bool_t, rtld_global);
 
 /*--------------------------------------------------------- */
-void clish_plugin__set_alias(clish_plugin_t *this, const char *alias)
+_CLISH_GET_STR(plugin, pubname)
 {
-	lub_string_free(this->alias);
-	this->alias = lub_string_dup(alias);
+	assert(inst);
+	return (inst->alias ? inst->alias : inst->name);
 }
-
-/*--------------------------------------------------------- */
-char *clish_plugin__get_alias(const clish_plugin_t *this)
-{
-	return this->alias;
-}
-
-/*--------------------------------------------------------- */
-char *clish_plugin__get_pubname(const clish_plugin_t *this)
-{
-	return (this->alias ? this->alias : this->name);
-}
-
-/*--------------------------------------------------------- */
-void clish_plugin__set_file(clish_plugin_t *this, const char *file)
-{
-	lub_string_free(this->file);
-	this->file = lub_string_dup(file);
-}
-
-/*--------------------------------------------------------- */
-char *clish_plugin__get_file(const clish_plugin_t *this)
-{
-	return this->file;
-}
-
-/*--------------------------------------------------------- */
-void clish_plugin__set_builtin_flag(clish_plugin_t *this, bool_t builtin_flag)
-{
-	this->builtin_flag = builtin_flag;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_plugin__get_builtin_flag(const clish_plugin_t *this)
-{
-	return this->builtin_flag;
-}
-
-/*--------------------------------------------------------- */
-void clish_plugin__set_conf(clish_plugin_t *this, const char *conf)
-{
-	lub_string_free(this->conf);
-	this->conf = lub_string_dup(conf);
-}
-
-/*--------------------------------------------------------- */
-char *clish_plugin__get_conf(const clish_plugin_t *this)
-{
-	return this->conf;
-}
-
-/*--------------------------------------------------------- */
-void clish_plugin__set_rtld_global(clish_plugin_t *this, bool_t rtld_global)
-{
-	this->rtld_global = rtld_global;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_plugin__get_rtld_global(const clish_plugin_t *this)
-{
-	return this->rtld_global;
-}
-
-/*--------------------------------------------------------- */

+ 1 - 1
clish/plugin/private.h

@@ -11,7 +11,7 @@
 
 struct clish_sym_s {
 	char *name; /* Symbol name */
-	void *func; /* Function address */
+	const void *func; /* Function address */
 	int type; /* Function type */
 	clish_sym_api_e api; /* Function API */
 	bool_t permanent; /* If permanent the dry-run can't switch it off */

+ 1 - 1
clish/shell/shell_plugin.c

@@ -187,7 +187,7 @@ clish_sym_t *clish_shell_add_unresolved_sym(clish_shell_t *this,
 static int link_unresolved_sym(clish_shell_t *this, clish_sym_t *sym)
 {
 	clish_sym_t *plugin_sym;
-	char *sym_name = NULL;
+	const char *sym_name = NULL;
 	int sym_type;
 
 	if (clish_sym__get_func(sym)) /* Don't relink non-null fn */

+ 1 - 1
clish/shell/shell_startup.c

@@ -171,7 +171,7 @@ int clish_shell_prepare(clish_shell_t *this)
 		clish_plugin_t *plugin;
 		plugin = clish_shell_find_create_plugin(this,
 			clish_plugin_builtin_list[i].name);
-		clish_plugin_add_init(plugin,
+		clish_plugin__set_init(plugin,
 			clish_plugin_builtin_list[i].init);
 		clish_plugin__set_builtin_flag(plugin, BOOL_TRUE);
 		i++;

+ 1 - 1
examples/explugin/anplug.c

@@ -26,7 +26,7 @@ CLISH_PLUGIN_INIT(anplug)
 
 	printf("anplug: INIT shell = %p\n", clish_shell);
 	/* Set a fini function */
-	clish_plugin_add_fini(plugin, clish_plugin_anplug_fini);
+	clish_plugin__set_fini(plugin, clish_plugin_anplug_fini);
 	/* Add symbols */
 	clish_plugin_add_sym(plugin, anplug_fn, "an_fn");
 	/* Show plugin config from <PLUGIN>...</PLUGIN> */

+ 1 - 1
plugins/lua/plugin_init.c

@@ -19,7 +19,7 @@ CLISH_PLUGIN_INIT(lua)
 	if(clish_plugin_init_lua(clish_shell))
 		return (-1);
 
-	clish_plugin_add_fini(plugin, clish_plugin_lua_fini);
+	clish_plugin__set_fini(plugin, clish_plugin_lua_fini);
 	clish_plugin_add_sym(plugin, clish_plugin_lua_action, "lua");
 
 	return 0;