Browse Source

Macros for clish_var_t

Serj Kalichev 6 years ago
parent
commit
d9b654d32b
3 changed files with 22 additions and 86 deletions
  1. 2 2
      clish/shell/shell_var.c
  2. 9 20
      clish/var.h
  3. 11 64
      clish/var/var.c

+ 2 - 2
clish/shell/shell_var.c

@@ -151,7 +151,7 @@ static char *find_context_var(const char *name, clish_context_t *this)
 static char *find_var(const char *name, lub_bintree_t *tree, clish_context_t *context)
 {
 	clish_var_t *var = lub_bintree_find(tree, name);
-	char *value;
+	const char *value;
 	bool_t dynamic;
 	char *res = NULL;
 
@@ -161,7 +161,7 @@ static char *find_var(const char *name, lub_bintree_t *tree, clish_context_t *co
 	/* Try to get saved value for static var */
 	dynamic = clish_var__get_dynamic(var);
 	if (!dynamic) {
-		char *saved = clish_var__get_saved(var);
+		const char *saved = clish_var__get_saved(var);
 		if (saved)
 			return lub_string_dup(saved);
 	}

+ 9 - 20
clish/var.h

@@ -7,31 +7,20 @@
 
 typedef struct clish_var_s clish_var_t;
 
-/*=====================================
- * VAR INTERFACE
- *===================================== */
-/*-----------------
- * meta functions
- *----------------- */
 int clish_var_bt_compare(const void *clientnode, const void *clientkey);
 void clish_var_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
 size_t clish_var_bt_offset(void);
 clish_var_t *clish_var_new(const char *name);
-/*-----------------
- * methods
- *----------------- */
 void clish_var_delete(clish_var_t *instance);
 void clish_var_dump(const clish_var_t *instance);
-/*-----------------
- * attributes
- *----------------- */
-const char *clish_var__get_name(const clish_var_t *instance);
-void clish_var__set_dynamic(clish_var_t *instance, bool_t defval);
-bool_t clish_var__get_dynamic(const clish_var_t *instance);
-void clish_var__set_value(clish_var_t *instance, const char *value);
-char *clish_var__get_value(const clish_var_t *instance);
-clish_action_t *clish_var__get_action(const clish_var_t *instance);
-void clish_var__set_saved(clish_var_t *instance, const char *value);
-char *clish_var__get_saved(const clish_var_t *instance);
+
+_CLISH_GET_STR(var, name);
+_CLISH_SET(var, bool_t, dynamic);
+_CLISH_GET(var, bool_t, dynamic);
+_CLISH_SET_STR(var, value);
+_CLISH_GET_STR(var, value);
+_CLISH_SET_STR(var, saved);
+_CLISH_GET_STR(var, saved);
+_CLISH_GET(var, clish_action_t *, action);
 
 #endif /* _clish_var_h */

+ 11 - 64
clish/var/var.c

@@ -11,9 +11,7 @@
 #include "lub/string.h"
 #include "private.h"
 
-/*---------------------------------------------------------
- * PRIVATE METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 static void clish_var_init(clish_var_t *this, const char *name)
 {
 	this->name = lub_string_dup(name);
@@ -35,9 +33,7 @@ static void clish_var_fini(clish_var_t *this)
 	lub_string_free(this->saved);
 }
 
-/*---------------------------------------------------------
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 int clish_var_bt_compare(const void *clientnode, const void *clientkey)
 {
 	const clish_var_t *this = clientnode;
@@ -70,67 +66,18 @@ clish_var_t *clish_var_new(const char *name)
 	return this;
 }
 
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 void clish_var_delete(clish_var_t *this)
 {
 	clish_var_fini(this);
 	free(this);
 }
 
-/*---------------------------------------------------------
- * PUBLIC ATTRIBUTES
- *--------------------------------------------------------- */
-const char *clish_var__get_name(const clish_var_t *this)
-{
-	if (!this)
-		return NULL;
-	return this->name;
-}
-
-/*--------------------------------------------------------- */
-void clish_var__set_dynamic(clish_var_t *this, bool_t dynamic)
-{
-	this->dynamic = dynamic;
-}
-
-/*--------------------------------------------------------- */
-bool_t clish_var__get_dynamic(const clish_var_t *this)
-{
-	return this->dynamic;
-}
-
-/*--------------------------------------------------------- */
-void clish_var__set_value(clish_var_t *this, const char *value)
-{
-	if (this->value)
-		lub_string_free(this->value);
-	this->value = lub_string_dup(value);
-}
-
-/*--------------------------------------------------------- */
-char *clish_var__get_value(const clish_var_t *this)
-{
-	return this->value;
-}
-
-/*--------------------------------------------------------- */
-clish_action_t *clish_var__get_action(const clish_var_t *this)
-{
-	return this->action;
-}
-
-/*--------------------------------------------------------- */
-void clish_var__set_saved(clish_var_t *this, const char *value)
-{
-	if (this->saved)
-		lub_string_free(this->saved);
-	this->saved = lub_string_dup(value);
-}
-
-/*--------------------------------------------------------- */
-char *clish_var__get_saved(const clish_var_t *this)
-{
-	return this->saved;
-}
+CLISH_GET_STR(var, name);
+CLISH_SET(var, bool_t, dynamic);
+CLISH_GET(var, bool_t, dynamic);
+CLISH_SET_STR(var, value);
+CLISH_GET_STR(var, value);
+CLISH_SET_STR(var, saved);
+CLISH_GET_STR(var, saved);
+CLISH_GET(var, clish_action_t *, action);