Browse Source

scheme: Unfinished refactoring

Serj Kalichev 3 years ago
parent
commit
ed15d2f185

+ 29 - 0
klish/iaction.h

@@ -0,0 +1,29 @@
+/** @file iaction.h
+ *
+ * @brief Klish scheme's "action" entry
+ */
+
+#ifndef _klish_iaction_h
+#define _klish_iaction_h
+
+#include <faux/error.h>
+
+typedef struct kaction_s kaction_t;
+
+typedef struct iaction_s {
+	char *sym;
+	char *lock;
+	char *interrupt;
+	char *interactive;
+	char *exec_on;
+	char *update_retcode;
+	char *script;
+} iaction_t;
+
+C_DECL_BEGIN
+
+char *iaction_to_text(const iaction_t *iaction, int level);
+
+C_DECL_END
+
+#endif // _klish_iaction_h

+ 25 - 0
klish/icommand.h

@@ -0,0 +1,25 @@
+/** @file icommand.h
+ *
+ * @brief Klish scheme's "command" entry
+ */
+
+#ifndef _klish_icommand_h
+#define _klish_icommand_h
+
+#include <klish/iparam.h>
+#include <klish/iaction.h>
+
+typedef struct icommand_s {
+	char *name;
+	char *help;
+	iparam_t * (*params)[];
+	iaction_t * (*actions)[];
+} icommand_t;
+
+C_DECL_BEGIN
+
+char *icommand_to_text(const icommand_t *icommand, int level);
+
+C_DECL_END
+
+#endif // _klish_icommand_h

+ 26 - 0
klish/iparam.h

@@ -0,0 +1,26 @@
+/** @file iparam.h
+ *
+ * @brief Klish scheme's "param" entry
+ */
+
+#ifndef _klish_iparam_h
+#define _klish_iparam_h
+
+
+typedef struct iparam_s iparam_t;
+
+struct iparam_s {
+	char *name;
+	char *help;
+	char *ptype;
+	iparam_t * (*params)[]; // Nested PARAMs
+};
+
+C_DECL_BEGIN
+
+// iparam_t
+char *iparam_to_text(const iparam_t *iparam, int level);
+
+C_DECL_END
+
+#endif // _klish_iparam_h

+ 24 - 0
klish/iplugin.h

@@ -0,0 +1,24 @@
+/** @file iplugin.h
+ *
+ * @brief Klish scheme's "plugin" entry
+ */
+
+#ifndef _klish_iplugin_h
+#define _klish_iplugin_h
+
+typedef struct iplugin_s {
+	char *name;
+	char *id;
+	char *file;
+	char *global;
+	char *conf;
+} iplugin_t;
+
+
+C_DECL_BEGIN
+
+char *iplugin_to_text(const iplugin_t *iplugin, int level);
+
+C_DECL_END
+
+#endif // _klish_iplugin_h

+ 23 - 0
klish/iptype.h

@@ -0,0 +1,23 @@
+/** @file iptype.h
+ *
+ * @brief Klish scheme's "ptype" entry
+ */
+
+#ifndef _klish_iptype_h
+#define _klish_iptype_h
+
+#include <klish/iaction.h>
+
+typedef struct iptype_s {
+	char *name;
+	char *help;
+	iaction_t * (*actions)[];
+} iptype_t;
+
+C_DECL_BEGIN
+
+char *iptype_to_text(const iptype_t *iptype, int level);
+
+C_DECL_END
+
+#endif // _klish_iptype_h

+ 52 - 0
klish/ischeme.h

@@ -0,0 +1,52 @@
+/** @file ischeme.h
+ *
+ * @brief Klish Scheme
+ */
+
+#ifndef _klish_ischeme_h
+#define _klish_ischeme_h
+
+#include <klish/iptype.h>
+#include <klish/iplugin.h>
+#include <klish/iview.h>
+
+
+#define VIEW_LIST .views = &(iview_t * []) {
+#define END_VIEW_LIST NULL }
+#define VIEW &(iview_t)
+
+#define PTYPE_LIST .ptypes = &(iptype_t * []) {
+#define END_PTYPE_LIST NULL }
+#define PTYPE &(iptype_t)
+
+#define COMMAND_LIST .commands = &(icommand_t * []) {
+#define END_COMMAND_LIST NULL }
+#define COMMAND &(icommand_t)
+
+#define PARAM_LIST .params = &(iparam_t * []) {
+#define END_PARAM_LIST NULL }
+#define PARAM &(iparam_t)
+
+#define ACTION_LIST .actions = &(iaction_t * []) {
+#define END_ACTION_LIST NULL }
+#define ACTION &(iaction_t)
+
+#define PLUGIN_LIST .plugins = &(iplugin_t * []) {
+#define END_PLUGIN_LIST NULL }
+#define PLUGIN &(iplugin_t)
+
+
+typedef struct ischeme_s {
+	char *name;
+	iplugin_t * (*plugins)[];
+	iptype_t * (*ptypes)[];
+	iview_t * (*views)[];
+} ischeme_t;
+
+C_DECL_BEGIN
+
+char *ischeme_to_text(const ischeme_t *ischeme, int level);
+
+C_DECL_END
+
+#endif // _klish_ischeme_h

+ 8 - 0
klish/ischeme/Makefile.am

@@ -0,0 +1,8 @@
+libklish_la_SOURCES += \
+	klish/kscheme/ischeme.c \
+	klish/kscheme/iptype.c \
+	klish/kscheme/iaction.c \
+	klish/kscheme/iview.c \
+	klish/kscheme/icommand.c \
+	klish/kscheme/iparam.c \
+	klish/kscheme/iplugin.c

+ 1 - 3
klish/kscheme/iaction.c → klish/ischeme/iaction.c

@@ -5,9 +5,7 @@
 
 #include <faux/str.h>
 #include <faux/conv.h>
-#include <klish/khelper.h>
-#include <klish/kaction.h>
-
+#include <klish/iaction.h>
 
 char *iaction_to_text(const iaction_t *iaction, int level)
 {

+ 1 - 3
klish/kscheme/icommand.c → klish/ischeme/icommand.c

@@ -5,9 +5,7 @@
 
 #include <faux/str.h>
 #include <faux/conv.h>
-#include <klish/khelper.h>
-#include <klish/kcommand.h>
-#include <klish/kaction.h>
+#include <klish/icommand.h>
 
 
 char *icommand_to_text(const icommand_t *icommand, int level)

+ 1 - 2
klish/kscheme/iparam.c → klish/ischeme/iparam.c

@@ -5,8 +5,7 @@
 
 #include <faux/str.h>
 #include <faux/conv.h>
-#include <klish/khelper.h>
-#include <klish/kparam.h>
+#include <klish/iparam.h>
 
 
 char *iparam_to_text(const iparam_t *iparam, int level)

+ 1 - 2
klish/kscheme/iplugin.c → klish/ischeme/iplugin.c

@@ -5,8 +5,7 @@
 
 #include <faux/str.h>
 #include <faux/conv.h>
-#include <klish/khelper.h>
-#include <klish/kplugin.h>
+#include <klish/iplugin.h>
 
 
 char *iplugin_to_text(const iplugin_t *iplugin, int level)

+ 1 - 3
klish/kscheme/iptype.c → klish/ischeme/iptype.c

@@ -5,9 +5,7 @@
 
 #include <faux/str.h>
 #include <faux/conv.h>
-#include <klish/khelper.h>
-#include <klish/kptype.h>
-#include <klish/kaction.h>
+#include <klish/iptype.h>
 
 
 char *iptype_to_text(const iptype_t *iptype, int level)

+ 1 - 4
klish/kscheme/ischeme.c → klish/ischeme/ischeme.c

@@ -4,10 +4,7 @@
 #include <assert.h>
 
 #include <faux/str.h>
-#include <klish/khelper.h>
-#include <klish/kview.h>
-#include <klish/kptype.h>
-#include <klish/kscheme.h>
+#include <klish/ischeme.h>
 
 
 char *ischeme_to_text(const ischeme_t *ischeme, int level)

+ 1 - 3
klish/kscheme/iview.c → klish/ischeme/iview.c

@@ -5,9 +5,7 @@
 
 #include <faux/str.h>
 #include <faux/conv.h>
-#include <klish/khelper.h>
-#include <klish/kview.h>
-#include <klish/kcommand.h>
+#include <klish/iview.h>
 
 
 char *iview_to_text(const iview_t *iview, int level)

+ 22 - 0
klish/iview.h

@@ -0,0 +1,22 @@
+/** @file view.h
+ *
+ * @brief Klish scheme's "view" entry
+ */
+
+#ifndef _klish_iview_h
+#define _klish_iview_h
+
+#include <klish/icommand.h>
+
+typedef struct iview_s {
+	char *name;
+	icommand_t * (*commands)[];
+} iview_t;
+
+C_DECL_BEGIN
+
+char *iview_to_text(const iview_t *iview, int level);
+
+C_DECL_END
+
+#endif // _klish_iview_h

+ 2 - 17
klish/kaction.h

@@ -1,4 +1,4 @@
-/** @file action.h
+/** @file kaction.h
  *
  * @brief Klish scheme's "action" entry
  */
@@ -7,18 +7,7 @@
 #define _klish_kaction_h
 
 #include <faux/error.h>
-
-typedef struct kaction_s kaction_t;
-
-typedef struct iaction_s {
-	char *sym;
-	char *lock;
-	char *interrupt;
-	char *interactive;
-	char *exec_on;
-	char *update_retcode;
-	char *script;
-} iaction_t;
+#include <klish/iaction.h>
 
 
 typedef enum {
@@ -44,10 +33,6 @@ typedef enum {
 
 C_DECL_BEGIN
 
-// iaction_t
-char *iaction_to_text(const iaction_t *iaction, int level);
-
-// kaction_t
 kaction_t *kaction_new(const iaction_t *info, kaction_error_e *error);
 void kaction_free(kaction_t *action);
 const char *kaction_strerror(kaction_error_e error);

+ 1 - 0
klish/kcommand.h

@@ -6,6 +6,7 @@
 #ifndef _klish_kcommand_h
 #define _klish_kcommand_h
 
+#include <klish/icommand.h>
 #include <klish/kparam.h>
 #include <klish/kaction.h>
 

+ 1 - 13
klish/kparam.h

@@ -7,18 +7,10 @@
 #define _klish_kparam_h
 
 #include <faux/error.h>
+#include <klish/iparam.h>
 
 typedef struct kparam_s kparam_t;
 
-typedef struct iparam_s iparam_t;
-struct iparam_s {
-	char *name;
-	char *help;
-	char *ptype;
-	iparam_t * (*params)[]; // Nested PARAMs
-};
-
-
 typedef enum {
 	KPARAM_ERROR_OK,
 	KPARAM_ERROR_INTERNAL,
@@ -31,10 +23,6 @@ typedef enum {
 
 C_DECL_BEGIN
 
-// iparam_t
-char *iparam_to_text(const iparam_t *iparam, int level);
-
-// kparam_t
 kparam_t *kparam_new(const iparam_t *info, kparam_error_e *error);
 void kparam_free(kparam_t *param);
 const char *kparam_strerror(kparam_error_e error);

+ 1 - 13
klish/kplugin.h

@@ -9,6 +9,7 @@
 #include <stdint.h>
 #include <faux/error.h>
 
+#include <klish/iplugin.h>
 #include <klish/ksym.h>
 
 // Current API version
@@ -32,15 +33,6 @@
 
 typedef struct kplugin_s kplugin_t;
 
-typedef struct iplugin_s {
-	char *name;
-	char *id;
-	char *file;
-	char *global;
-	char *conf;
-} iplugin_t;
-
-
 typedef enum {
 	KPLUGIN_ERROR_OK,
 	KPLUGIN_ERROR_INTERNAL,
@@ -55,10 +47,6 @@ typedef enum {
 
 C_DECL_BEGIN
 
-// iplugin_t
-char *iplugin_to_text(const iplugin_t *iplugin, int level);
-
-// kplugin_t
 void kplugin_free(kplugin_t *plugin);
 bool_t kplugin_parse(kplugin_t *plugin, const iplugin_t *info, kplugin_error_e *error);
 kplugin_t *kplugin_new(const iplugin_t *info, kplugin_error_e *error);

+ 1 - 11
klish/kptype.h

@@ -7,17 +7,11 @@
 #define _klish_kptype_h
 
 #include <faux/error.h>
+#include <klish/iptype.h>
 #include <klish/kaction.h>
 
 typedef struct kptype_s kptype_t;
 
-typedef struct iptype_s {
-	char *name;
-	char *help;
-	iaction_t * (*actions)[];
-} iptype_t;
-
-
 typedef enum {
 	KPTYPE_ERROR_OK,
 	KPTYPE_ERROR_INTERNAL,
@@ -29,10 +23,6 @@ typedef enum {
 
 C_DECL_BEGIN
 
-// iptype_t
-char *iptype_to_text(const iptype_t *iptype, int level);
-
-// kptype_t
 void kptype_free(kptype_t *ptype);
 bool_t kptype_parse(kptype_t *ptype, const iptype_t *info, kptype_error_e *error);
 kptype_t *kptype_new(const iptype_t *info, kptype_error_e *error);

+ 1 - 41
klish/kscheme.h

@@ -8,49 +8,13 @@
 
 #include <faux/error.h>
 
-#include <klish/kptype.h>
+#include <klish/ischeme.h>
 #include <klish/kplugin.h>
 #include <klish/kaction.h>
-#include <klish/kparam.h>
-#include <klish/kcommand.h>
 #include <klish/kview.h>
 
-
-#define VIEW_LIST .views = &(iview_t * []) {
-#define END_VIEW_LIST NULL }
-#define VIEW &(iview_t)
-
-#define PTYPE_LIST .ptypes = &(iptype_t * []) {
-#define END_PTYPE_LIST NULL }
-#define PTYPE &(iptype_t)
-
-#define COMMAND_LIST .commands = &(icommand_t * []) {
-#define END_COMMAND_LIST NULL }
-#define COMMAND &(icommand_t)
-
-#define PARAM_LIST .params = &(iparam_t * []) {
-#define END_PARAM_LIST NULL }
-#define PARAM &(iparam_t)
-
-#define ACTION_LIST .actions = &(iaction_t * []) {
-#define END_ACTION_LIST NULL }
-#define ACTION &(iaction_t)
-
-#define PLUGIN_LIST .plugins = &(iplugin_t * []) {
-#define END_PLUGIN_LIST NULL }
-#define PLUGIN &(iplugin_t)
-
-
 typedef struct kscheme_s kscheme_t;
 
-typedef struct ischeme_s {
-	char *name;
-	iplugin_t * (*plugins)[];
-	iptype_t * (*ptypes)[];
-	iview_t * (*views)[];
-} ischeme_t;
-
-
 typedef enum {
 	KSCHEME_ERROR_OK,
 	KSCHEME_ERROR_INTERNAL,
@@ -60,10 +24,6 @@ typedef enum {
 
 C_DECL_BEGIN
 
-// ischeme_t
-char *ischeme_to_text(const ischeme_t *ischeme, int level);
-
-// kscheme_t
 kscheme_t *kscheme_new(kscheme_error_e *error);
 void kscheme_free(kscheme_t *scheme);
 const char *kscheme_strerror(kscheme_error_e error);

+ 0 - 10
klish/kscheme/Makefile.am

@@ -8,13 +8,3 @@ libklish_la_SOURCES += \
 	klish/kscheme/kcommand.c \
 	klish/kscheme/kview.c \
 	klish/kscheme/kscheme.c
-
-libklish_la_SOURCES += \
-	klish/kscheme/ischeme.c \
-	klish/kscheme/iptype.c \
-	klish/kscheme/iaction.c \
-	klish/kscheme/iview.c \
-	klish/kscheme/icommand.c \
-	klish/kscheme/iparam.c \
-	klish/kscheme/iplugin.c
-

+ 1 - 1
klish/kustore.h

@@ -1,6 +1,6 @@
 /** @file kustore.h
  *
- * @brief Klish ustore
+ * @brief Klish user data store. List of kudata_t object.
  */
 
 #ifndef _klish_kustore_h

+ 1 - 9
klish/kview.h

@@ -8,16 +8,11 @@
 
 #include <faux/faux.h>
 #include <faux/error.h>
+#include <klish/iview.h>
 #include <klish/kcommand.h>
 
 typedef struct kview_s kview_t;
 
-typedef struct iview_s {
-	char *name;
-	icommand_t * (*commands)[];
-} iview_t;
-
-
 typedef enum {
 	KVIEW_ERROR_OK,
 	KVIEW_ERROR_INTERNAL,
@@ -28,9 +23,6 @@ typedef enum {
 
 C_DECL_BEGIN
 
-// iview_t
-char *iview_to_text(const iview_t *iview, int level);
-
 // kview_t
 kview_t *kview_new(const iview_t *info, kview_error_e *error);
 void kview_free(kview_t *view);