Browse Source

Add macros.h

Serj Kalichev 5 years ago
parent
commit
46d86390dc
5 changed files with 38 additions and 38 deletions
  1. 6 16
      clish/action.h
  2. 7 22
      clish/action/action.c
  3. 2 0
      clish/command.h
  4. 22 0
      clish/macros.h
  5. 1 0
      clish/module.am

+ 6 - 16
clish/action.h

@@ -1,36 +1,26 @@
 /*
  * action.h
  */
+
 #ifndef _clish_action_h
 #define _clish_action_h
 
 typedef struct clish_action_s clish_action_t;
 
 #include "lub/bintree.h"
+#include "clish/macros.h"
 #include "clish/plugin.h"
 
-/*=====================================
- * ACTION INTERFACE
- *===================================== */
-/*-----------------
- * meta functions
- *----------------- */
 clish_action_t *clish_action_new(void);
-
-/*-----------------
- * methods
- *----------------- */
 void clish_action_delete(clish_action_t *instance);
 void clish_action_dump(const clish_action_t *instance);
 
-/*-----------------
- * attributes
- *----------------- */
 void clish_action__set_script(clish_action_t *instance, const char *script);
-char *clish_action__get_script(const clish_action_t *instance);
+_CLISH_GET(action, const char *, script);
+_CLISH_GET(action, clish_sym_t *, builtin);
 void clish_action__set_builtin(clish_action_t *instance, clish_sym_t *builtin);
-clish_sym_t *clish_action__get_builtin(const clish_action_t *instance);
+//clish_sym_t *clish_action__get_builtin(const clish_action_t *instance);
 void clish_action__set_shebang(clish_action_t *instance, const char *shebang);
 const char *clish_action__get_shebang(const clish_action_t *instance);
 
-#endif				/* _clish_action_h */
+#endif // _clish_action_h

+ 7 - 22
clish/action/action.c

@@ -13,9 +13,7 @@
 #include "lub/bintree.h"
 #include "lub/string.h"
 
-/*---------------------------------------------------------
- * PRIVATE METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 static void clish_action_init(clish_action_t *this)
 {
 	this->script = NULL;
@@ -30,9 +28,7 @@ static void clish_action_fini(clish_action_t *this)
 	lub_string_free(this->shebang);
 }
 
-/*---------------------------------------------------------
- * PUBLIC META FUNCTIONS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 clish_action_t *clish_action_new(void)
 {
 	clish_action_t *this = malloc(sizeof(clish_action_t));
@@ -43,18 +39,14 @@ clish_action_t *clish_action_new(void)
 	return this;
 }
 
-/*---------------------------------------------------------
- * PUBLIC METHODS
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 void clish_action_delete(clish_action_t *this)
 {
 	clish_action_fini(this);
 	free(this);
 }
 
-/*---------------------------------------------------------
- * PUBLIC ATTRIBUTES
- *--------------------------------------------------------- */
+/*--------------------------------------------------------- */
 void clish_action__set_script(clish_action_t *this, const char *script)
 {
 	if (this->script)
@@ -62,11 +54,7 @@ void clish_action__set_script(clish_action_t *this, const char *script)
 	this->script = lub_string_dup(script);
 }
 
-/*--------------------------------------------------------- */
-char *clish_action__get_script(const clish_action_t *this)
-{
-	return this->script;
-}
+CLISH_GET(action, const char *, script);
 
 /*--------------------------------------------------------- */
 void clish_action__set_builtin(clish_action_t *this, clish_sym_t *builtin)
@@ -74,11 +62,7 @@ void clish_action__set_builtin(clish_action_t *this, clish_sym_t *builtin)
 	this->builtin = builtin;
 }
 
-/*--------------------------------------------------------- */
-clish_sym_t *clish_action__get_builtin(const clish_action_t *this)
-{
-	return this->builtin;
-}
+CLISH_GET(action, clish_sym_t *, builtin);
 
 /*--------------------------------------------------------- */
 void clish_action__set_shebang(clish_action_t *this, const char *shebang)
@@ -93,6 +77,7 @@ void clish_action__set_shebang(clish_action_t *this, const char *shebang)
 	this->shebang = lub_string_dup(prog);
 }
 
+//CLISH_GET(clish_action__get_script, clish_action_t, const char *, script);
 /*--------------------------------------------------------- */
 const char *clish_action__get_shebang(const clish_action_t *this)
 {

+ 2 - 0
clish/command.h

@@ -1,6 +1,7 @@
 /*
  * command.h
  */
+
 #ifndef _clish_command_h
 #define _clish_command_h
 
@@ -9,6 +10,7 @@ typedef struct clish_command_s clish_command_t;
 #include "lub/bintree.h"
 #include "lub/argv.h"
 #include "clish/types.h"
+#include "clish/macros.h"
 #include "clish/pargv.h"
 #include "clish/view.h"
 #include "clish/param.h"

+ 22 - 0
clish/macros.h

@@ -0,0 +1,22 @@
+/* Macros for simplifying to write subsystem's service functions */
+
+#ifndef _clish_macros_h
+#define _clish_macros_h
+
+#include <assert.h>
+
+/* Function to get value from structure by name */
+#define _CLISH_GET(obj, type, name) \
+	type clish_##obj##__get_##name(const clish_##obj##_t *obj)
+#define CLISH_GET(obj, type, name) \
+	_CLISH_GET(obj, type, name) { \
+		assert(obj); \
+		return obj->name; \
+	}
+
+#define CLISH_SET(obj_type, field_type, field_name, value)
+
+
+
+
+#endif // _clish_macros_h

+ 1 - 0
clish/module.am

@@ -17,6 +17,7 @@ libclish_la_LIBADD = \
 
 nobase_include_HEADERS += \
 	clish/types.h \
+	clish/macros.h \
 	clish/command.h \
 	clish/param.h \
 	clish/pargv.h \