Browse Source

scheme: Unfinished work on kview

Serj Kalichev 3 years ago
parent
commit
e630f2918a
9 changed files with 67 additions and 39 deletions
  1. 1 0
      Makefile.am
  2. 0 7
      bin/klishd/klishd.c
  3. 2 3
      klish.xsd
  4. 3 0
      klish/Makefile.am
  5. 4 2
      klish/kparam.h
  6. 10 0
      klish/kscheme.h
  7. 1 0
      klish/kscheme/kaction.c
  8. 35 25
      klish/kscheme/kview.c
  9. 11 2
      klish/kview.h

+ 1 - 0
Makefile.am

@@ -20,6 +20,7 @@ bin_PROGRAMS =
 lib_LTLIBRARIES =
 lib_LIBRARIES =
 nobase_include_HEADERS =
+noinst_HEADERS =
 
 EXTRA_DIST =
 	klish/Makefile.am \

+ 0 - 7
bin/klishd/klishd.c

@@ -37,13 +37,6 @@
 
 #include "private.h"
 
-#define VIEW_LIST .views = &(iview_t * []) {
-#define END_VIEW_LIST NULL }
-#define VIEW &(iview_t)
-#define COMMAND_LIST .commands = &(icommand_t * []) {
-#define END_COMMAND_LIST NULL }
-#define COMMAND &(icommand_t)
-
 ischeme_t sch = {
   VIEW_LIST
 

+ 2 - 3
klish.xsd

@@ -171,11 +171,10 @@
 *******************************************************
 * <COMMAND> is used to define a command within the CLI.
 *
-* name - a textual name for this command. (This may contain
+* name="<string>" - A textual name for this command. (This may contain
 *	spaces e.g. "display acl")
 *
-* help - a textual string which describes the purpose of the
-*	command.
+* help="<string>" - Help for command.
 *
 * [view] - defines the view which will be transitioned to, on 
 *	successful execution of any <ACTION> tag. By default the

+ 3 - 0
klish/Makefile.am

@@ -14,6 +14,9 @@ nobase_include_HEADERS += \
 	klish/kcommand.h \
 	klish/kparam.h
 
+noinst_HEADERS += \
+	klish/khelper.h
+
 EXTRA_DIST += \
 	klish/ktp/Makefile.am \
 	klish/kscheme/Makefile.am

+ 4 - 2
klish/kparam.h

@@ -8,11 +8,13 @@
 
 typedef struct kparam_s kparam_t;
 
-typedef struct iparam_s {
+typedef struct iparam_s iparam_t;
+struct iparam_s {
 	char *name;
 	char *help;
 	char *ptype;
-} iparam_t;
+	iparam_t * (*params)[]; // Nested PARAMs
+};
 
 
 C_DECL_BEGIN

+ 10 - 0
klish/kscheme.h

@@ -13,6 +13,16 @@
 #include <klish/kcommand.h>
 #include <klish/kview.h>
 
+
+#define VIEW_LIST .views = &(iview_t * []) {
+#define END_VIEW_LIST NULL }
+#define VIEW &(iview_t)
+
+#define COMMAND_LIST .commands = &(icommand_t * []) {
+#define END_COMMAND_LIST NULL }
+#define COMMAND &(icommand_t)
+
+
 typedef struct kscheme_s kscheme_t;
 
 typedef struct ischeme_s {

+ 1 - 0
klish/kscheme/kaction.c

@@ -5,6 +5,7 @@
 
 #include <faux/str.h>
 #include <faux/list.h>
+#include <klish/khelper.h>
 #include <klish/kaction.h>
 
 

+ 35 - 25
klish/kscheme/kview.c

@@ -5,17 +5,21 @@
 
 #include <faux/str.h>
 #include <faux/list.h>
+#include <klish/khelper.h>
 #include <klish/kcommand.h>
 #include <klish/kview.h>
 
-
 struct kview_s {
-	bool_t is_static;
-	iview_t info;
+	char *name;
 	faux_list_t *commands;
 };
 
 
+// Simple attributes
+KGET_STR(kview, name);
+KSET_STR_ONCE(kview, name);
+
+
 static int kview_command_compare(const void *first, const void *second)
 {
 	const kcommand_t *f = (const kcommand_t *)first;
@@ -34,7 +38,7 @@ static int kview_command_kcompare(const void *key, const void *list_item)
 }
 
 
-static kview_t *kview_new_internal(iview_t info, bool_t is_static)
+static kview_t *kview_new_empty(void)
 {
 	kview_t *view = NULL;
 
@@ -44,8 +48,7 @@ static kview_t *kview_new_internal(iview_t info, bool_t is_static)
 		return NULL;
 
 	// Initialize
-	view->is_static = is_static;
-	view->info = info;
+	view->name = NULL;
 
 	view->commands = faux_list_new(FAUX_LIST_SORTED, FAUX_LIST_UNIQUE,
 		kview_command_compare, kview_command_kcompare,
@@ -56,15 +59,24 @@ static kview_t *kview_new_internal(iview_t info, bool_t is_static)
 }
 
 
-kview_t *kview_new(iview_t info)
+kview_t *kview_new(const iview_t *info, kview_error_e *error)
 {
-	return kview_new_internal(info, BOOL_FALSE);
-}
+	kview_t *view = NULL;
 
+	view = kview_new_empty();
+	assert(view);
+	if (!view)
+		return NULL;
 
-kview_t *kview_new_static(iview_t info)
-{
-	return kview_new_internal(info, BOOL_TRUE);
+	if (!info)
+		return view;
+
+	if (!kview_parse(view, info, error)) {
+		kview_free(view);
+		return NULL;
+	}
+
+	return view;
 }
 
 
@@ -73,25 +85,13 @@ void kview_free(kview_t *view)
 	if (!view)
 		return;
 
-	if (!view->is_static) {
-		faux_str_free(view->info.name);
-	}
+	faux_str_free(view->name);
 	faux_list_free(view->commands);
 
 	faux_free(view);
 }
 
 
-const char *kview_name(const kview_t *view)
-{
-	assert(view);
-	if (!view)
-		return NULL;
-
-	return view->info.name;
-}
-
-
 bool_t kview_add_command(kview_t *view, kcommand_t *command)
 {
 	assert(view);
@@ -106,3 +106,13 @@ bool_t kview_add_command(kview_t *view, kcommand_t *command)
 
 	return BOOL_TRUE;
 }
+
+
+bool_t kview_parse(kview_t *view, const iview_t *info, kview_error_e *error)
+{
+	view = view;
+	info = info;
+	error = error;
+
+	return BOOL_TRUE;
+}

+ 11 - 2
klish/kview.h

@@ -6,6 +6,7 @@
 #ifndef _klish_kview_h
 #define _klish_kview_h
 
+#include <faux/faux.h>
 #include <klish/kcommand.h>
 
 typedef struct kview_s kview_t;
@@ -16,13 +17,21 @@ typedef struct iview_s {
 } iview_t;
 
 
+typedef enum {
+	KVIEW_ERROR_OK,
+	KVIEW_ERROR_MALLOC,
+	KVIEW_ERROR_LIST
+} kview_error_e;
+
+
 C_DECL_BEGIN
 
-kview_t *kview_new(iview_t info);
-kview_t *kview_new_static(iview_t info);
+kview_t *kview_new(const iview_t *info, kview_error_e *error);
 void kview_free(kview_t *view);
+bool_t kview_parse(kview_t *view, const iview_t *info, kview_error_e *error);
 
 const char *kview_name(const kview_t *view);
+bool_t kview_set_name(kview_t *view, const char *name);
 
 bool_t kview_add_command(kview_t *view, kcommand_t *command);