Browse Source

entry: Use entry instead view within klevel_t and kpath_t

Serj Kalichev 2 years ago
parent
commit
10454c3315
6 changed files with 48 additions and 29 deletions
  1. 3 3
      klish/kpath.h
  2. 1 0
      klish/kscheme.h
  3. 2 2
      klish/ksession.h
  4. 7 7
      klish/ksession/klevel.c
  5. 0 1
      klish/ksession/kpath.c
  6. 35 16
      klish/ksession/ksession.c

+ 3 - 3
klish/kpath.h

@@ -7,7 +7,7 @@
 #define _klish_kpath_h
 
 #include <faux/list.h>
-#include <klish/kview.h>
+#include <klish/kentry.h>
 
 typedef struct kpath_s kpath_t;
 typedef struct klevel_s klevel_t;
@@ -19,10 +19,10 @@ C_DECL_BEGIN
 
 // Level
 
-klevel_t *klevel_new(kview_t *view);
+klevel_t *klevel_new(kentry_t *entry);
 void klevel_free(klevel_t *level);
 
-kview_t *klevel_view(const klevel_t *level);
+kentry_t *klevel_entry(const klevel_t *level);
 
 // Path
 

+ 1 - 0
klish/kscheme.h

@@ -55,6 +55,7 @@ kscheme_plugins_node_t *kscheme_plugins_iter(const kscheme_t *scheme);
 kplugin_t *kscheme_plugins_each(kscheme_plugins_node_t **iter);
 
 // ENTRYs
+kentry_t *kscheme_find_entry_by_path(const kscheme_t *scheme, const char *name);
 faux_list_t *kscheme_entrys(const kscheme_t *scheme);
 bool_t kscheme_add_entry(kscheme_t *scheme, kentry_t *entry);
 kentry_t *kscheme_find_entry(const kscheme_t *scheme, const char *name);

+ 2 - 2
klish/ksession.h

@@ -8,14 +8,14 @@
 
 #include <klish/kscheme.h>
 
-#define KSESSION_DEFAULT_VIEW "main"
+#define KSESSION_STARTING_ENTRY "main"
 
 typedef struct ksession_s ksession_t;
 
 
 C_DECL_BEGIN
 
-ksession_t *ksession_new(const kscheme_t *scheme, const char *start_view);
+ksession_t *ksession_new(const kscheme_t *scheme, const char *start_entry);
 void ksession_free(ksession_t *session);
 
 const kscheme_t *ksession_scheme(const ksession_t *session);

+ 7 - 7
klish/ksession/klevel.c

@@ -8,22 +8,22 @@
 #include <faux/str.h>
 #include <klish/khelper.h>
 #include <klish/kpath.h>
-#include <klish/kview.h>
+#include <klish/kentry.h>
 
 struct klevel_s {
-	kview_t *view;
+	kentry_t *entry;
 };
 
 
-// View
-KGET(level, kview_t *, view);
+// ENTRY
+KGET(level, kentry_t *, entry);
 
 
-klevel_t *klevel_new(kview_t *view)
+klevel_t *klevel_new(kentry_t *entry)
 {
 	klevel_t *level = NULL;
 
-	if (!view)
+	if (!entry)
 		return NULL;
 
 	level = faux_zmalloc(sizeof(*level));
@@ -32,7 +32,7 @@ klevel_t *klevel_new(kview_t *view)
 		return NULL;
 
 	// Initialize
-	level->view = view;
+	level->entry = entry;
 
 	return level;
 }

+ 0 - 1
klish/ksession/kpath.c

@@ -7,7 +7,6 @@
 
 #include <faux/list.h>
 #include <klish/khelper.h>
-#include <klish/kudata.h>
 #include <klish/kpath.h>
 
 struct kpath_s {

+ 35 - 16
klish/ksession/ksession.c

@@ -27,30 +27,30 @@ KGET(session, const kscheme_t *, scheme);
 KGET(session, kpath_t *, path);
 
 
-ksession_t *ksession_new(const kscheme_t *scheme, const char *start_view)
+ksession_t *ksession_new(const kscheme_t *scheme, const char *start_entry)
 {
 	ksession_t *session = NULL;
-	kview_t *view = NULL;
-	const char *view_to_search = NULL;
+	kentry_t *entry = NULL;
+	const char *entry_to_search = NULL;
 	klevel_t *level = NULL;
 
 	assert(scheme);
 	if (!scheme)
 		return NULL;
 
-	// Before real session allocation we will try to find starting view.
-	// Starting view can be get from function argument, from STARTUP tag or
+	// Before real session allocation we will try to find starting entry.
+	// Starting entry can be get from function argument, from STARTUP tag or
 	// default name 'main' can be used. Don't create session if we can't get
-	// starting view at all. Priorities are (from higher) argument, STARTUP,
+	// starting entry at all. Priorities are (from higher) argument, STARTUP,
 	// default name.
-	if (start_view)
-		view_to_search = start_view;
+	if (start_entry)
+		entry_to_search = start_entry;
 	// STARTUP is not implemented yet
 	else
-		view_to_search = KSESSION_DEFAULT_VIEW;
-	view = kscheme_find_view(scheme, view_to_search);
-	if (view)
-		return NULL; // Can't find starting view
+		entry_to_search = KSESSION_STARTING_ENTRY;
+	entry = kscheme_find_entry_by_path(scheme, entry_to_search);
+	if (entry)
+		return NULL; // Can't find starting entry
 
 	session = faux_zmalloc(sizeof(*session));
 	assert(session);
@@ -62,7 +62,7 @@ ksession_t *ksession_new(const kscheme_t *scheme, const char *start_view)
 	// Create kpath_t stack
 	session->path = kpath_new();
 	assert(session->path);
-	level = klevel_new(view);
+	level = klevel_new(entry);
 	assert(level);
 	kpath_push(session->path, level);
 
@@ -80,11 +80,30 @@ void ksession_free(ksession_t *session)
 	free(session);
 }
 
-/*
-kpargv_t *ksession_parse_line(ksession_t session, const faux_argv_t *argv)
+
+kpargv_t *ksession_parse_line(ksession_t *session, const char *line)
 {
+	const kscheme_t *scheme = ksession_scheme(session);
+	faux_argv_t *argv = NULL;
+
+	assert(session);
+	if (!session)
+		return NULL;
+	assert(line);
+	if (!line)
+		return NULL;
 
+	// Split line to arguments
+	argv = faux_argv_new();
+	assert(argv);
+	if (!argv)
+		return NULL;
+	if (faux_argv_parse(argv, line) <= 0) {
+		faux_argv_free(argv);
+		return NULL;
+	}
 
+	scheme = scheme;
 
+	return NULL;
 }
-*/