Browse Source

scheme: Real symbol resolving

Serj Kalichev 3 years ago
parent
commit
a94f36c755

+ 4 - 4
bin/klishd/sch.c

@@ -23,12 +23,12 @@ ischeme_t sch = {
    ACTION_LIST
 
     ACTION {
-     .sym = "internal",
+     .sym = "nop",
      .script = "cat /etc/passwd",
     },
 
     ACTION {
-     .sym = "internal",
+     .sym = "nop@base",
      .script = "cat /etc/group",
     },
 
@@ -120,12 +120,12 @@ ischeme_t sch = {
      ACTION_LIST
 
       ACTION {
-       .sym = "internal",
+       .sym = "nop@klish",
        .script = "cat /etc/passwd",
       },
 
       ACTION {
-       .sym = "internal",
+       .sym = "nop",
        .script = "cat /etc/group",
       },
 

+ 8 - 8
klish/kcontext.h

@@ -14,14 +14,14 @@ C_DECL_BEGIN
 
 int kcontext_retcode(const kcontext_t *context);
 bool_t kcontext_set_retcode(kcontext_t *context, int retcode);
-const kplugin_t *kcontext_plugin(const kcontext_t *context);
-bool_t kcontext_set_plugin(kcontext_t *context, const kplugin_t *plugin);
-const ksym_t *kcontext_sym(const kcontext_t *context);
-bool_t kcontext_set_sym(kcontext_t *context, const ksym_t *sym);
-const kaction_t *kcontext_action(const kcontext_t *context);
-bool_t kcontext_set_action(kcontext_t *context, const kaction_t *action);
-const kcommand_t *kcontext_command(const kcontext_t *context);
-bool_t kcontext_set_command(kcontext_t *context, const kcommand_t *command);
+kplugin_t *kcontext_plugin(const kcontext_t *context);
+bool_t kcontext_set_plugin(kcontext_t *context, kplugin_t *plugin);
+ksym_t *kcontext_sym(const kcontext_t *context);
+bool_t kcontext_set_sym(kcontext_t *context, ksym_t *sym);
+kaction_t *kcontext_action(const kcontext_t *context);
+bool_t kcontext_set_action(kcontext_t *context, kaction_t *action);
+kcommand_t *kcontext_command(const kcontext_t *context);
+bool_t kcontext_set_command(kcontext_t *context, kcommand_t *command);
 
 C_DECL_END
 

+ 3 - 0
klish/kcontext_base.h

@@ -6,6 +6,9 @@
 #ifndef _klish_kcontext_base_h
 #define _klish_kcontext_base_h
 
+#include <faux/faux.h>
+
+
 typedef struct kcontext_s kcontext_t;
 
 typedef enum {

+ 5 - 0
klish/kscheme/kscheme.c

@@ -11,6 +11,7 @@
 #include <klish/kptype.h>
 #include <klish/kview.h>
 #include <klish/kscheme.h>
+#include <klish/kcontext.h>
 
 
 struct kscheme_s {
@@ -120,6 +121,8 @@ bool_t kscheme_load_plugins(kscheme_t *scheme, kcontext_t *context,
 			retcode = BOOL_FALSE;
 			continue; // Try to load all plugins
 		}
+		kcontext_set_type(context, KCONTEXT_PLUGIN_INIT);
+		kcontext_set_plugin(context, plugin);
 		if ((init_retcode = kplugin_init(plugin, context)) < 0) {
 			faux_error_sprintf(error,
 				TAG ": Can't init plugin \"%s\" (%d)",
@@ -149,6 +152,8 @@ bool_t kscheme_fini_plugins(kscheme_t *scheme, kcontext_t *context,
 	iter = kscheme_plugins_iter(scheme);
 	while ((plugin = kscheme_plugins_each(&iter))) {
 		int fini_retcode = -1;
+		kcontext_set_type(context, KCONTEXT_PLUGIN_FINI);
+		kcontext_set_plugin(context, plugin);
 		if ((fini_retcode = kplugin_fini(plugin, context)) < 0) {
 			faux_error_sprintf(error,
 				TAG ": Can't fini plugin \"%s\" (%d)",

+ 4 - 4
klish/kscheme/ksym.c

@@ -13,7 +13,7 @@
 
 struct ksym_s {
 	char *name;
-	const ksym_fn *function;
+	ksym_fn function;
 };
 
 
@@ -24,11 +24,11 @@ KGET_STR(sym, name);
 KSET_STR_ONCE(sym, name);
 
 // Function
-KGET(sym, const ksym_fn *, function);
-KSET(sym, const ksym_fn *, function);
+KGET(sym, ksym_fn, function);
+KSET(sym, ksym_fn, function);
 
 
-ksym_t *ksym_new(const char *name, const ksym_fn *function)
+ksym_t *ksym_new(const char *name, ksym_fn function)
 {
 	ksym_t *sym = NULL;
 

+ 12 - 12
klish/ksession/kcontext.c

@@ -14,10 +14,10 @@
 struct kcontext_s {
 	kcontext_type_e type;
 	int retcode;
-	const kplugin_t *plugin;
-	const ksym_t *sym;
-	const kaction_t *action;
-	const kcommand_t *command;
+	kplugin_t *plugin;
+	ksym_t *sym;
+	kaction_t *action;
+	kcommand_t *command;
 };
 
 
@@ -32,20 +32,20 @@ KGET(context, int, retcode);
 KSET(context, int, retcode);
 
 // Plugin
-KGET(context, const kplugin_t *, plugin);
-KSET(context, const kplugin_t *, plugin);
+KGET(context, kplugin_t *, plugin);
+KSET(context, kplugin_t *, plugin);
 
 // Sym
-KGET(context, const ksym_t *, sym);
-KSET(context, const ksym_t *, sym);
+KGET(context, ksym_t *, sym);
+KSET(context, ksym_t *, sym);
 
 // Action
-KGET(context, const kaction_t *, action);
-KSET(context, const kaction_t *, action);
+KGET(context, kaction_t *, action);
+KSET(context, kaction_t *, action);
 
 // Command
-KGET(context, const kcommand_t *, command);
-KSET(context, const kcommand_t *, command);
+KGET(context, kcommand_t *, command);
+KSET(context, kcommand_t *, command);
 
 
 kcontext_t *kcontext_new(kcontext_type_e type)

+ 3 - 3
klish/ksym.h

@@ -17,12 +17,12 @@ typedef int (*ksym_fn)(kcontext_t *context);
 C_DECL_BEGIN
 
 // ksym_t
-ksym_t *ksym_new(const char *name, const ksym_fn *function);
+ksym_t *ksym_new(const char *name, ksym_fn function);
 void ksym_free(ksym_t *sym);
 
 const char *ksym_name(const ksym_t *sym);
-const ksym_fn *ksym_function(const ksym_t *sym);
-bool_t ksym_set_function(ksym_t *sym, const ksym_fn *fn);
+ksym_fn ksym_function(const ksym_t *sym);
+bool_t ksym_set_function(ksym_t *sym, ksym_fn fn);
 
 C_DECL_END
 

+ 2 - 1
plugins/klish/Makefile.am

@@ -6,7 +6,8 @@ kplugin_klish_la_CFLAGS = $(AM_LDFLAGS)
 kplugin_klish_la_LIBADD = libklish.la
 
 kplugin_klish_la_SOURCES += \
-	plugins/klish/plugin_init.c
+	plugins/klish/plugin_init.c \
+	plugins/klish/misc.c
 #	plugins/klish/hook_access.c \
 #	plugins/klish/hook_config.c \
 #	plugins/klish/hook_log.c \

+ 20 - 0
plugins/klish/misc.c

@@ -0,0 +1,20 @@
+/*
+ *
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <klish/kcontext.h>
+
+
+int klish_nop(kcontext_t *context)
+{
+	context = context; // Happy compiler
+
+	return 0;
+}

+ 10 - 26
plugins/klish/plugin_init.c

@@ -4,12 +4,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <assert.h>
 
 #include <faux/faux.h>
 #include <klish/kplugin.h>
 #include <klish/kcontext.h>
 
-//#include "private.h"
+#include "private.h"
 
 
 const uint8_t kplugin_klish_major = KPLUGIN_MAJOR;
@@ -18,31 +19,14 @@ const uint8_t kplugin_klish_minor = KPLUGIN_MINOR;
 
 int kplugin_klish_init(kcontext_t *context)
 {
-	/* Add hooks */
-/*	clish_plugin_add_phook(plugin, clish_hook_access,
-		"clish_hook_access", CLISH_SYM_TYPE_ACCESS);
-	clish_plugin_add_phook(plugin, clish_hook_config,
-		"clish_hook_config", CLISH_SYM_TYPE_CONFIG);
-	clish_plugin_add_phook(plugin, clish_hook_log,
-		"clish_hook_log", CLISH_SYM_TYPE_LOG);
-*/
-
-	/* Add builtin syms */
-/*	clish_plugin_add_psym(plugin, clish_close, "clish_close");
-	clish_plugin_add_psym(plugin, clish_overview, "clish_overview");
-	clish_plugin_add_psym(plugin, clish_source, "clish_source");
-	clish_plugin_add_psym(plugin, clish_source_nostop, "clish_source_nostop");
-	clish_plugin_add_psym(plugin, clish_history, "clish_history");
-	clish_plugin_add_psym(plugin, clish_nested_up, "clish_nested_up");
-	clish_plugin_add_psym(plugin, clish_nop, "clish_nop");
-	clish_plugin_add_psym(plugin, clish_wdog, "clish_wdog");
-	clish_plugin_add_psym(plugin, clish_macros, "clish_macros");
-	clish_plugin_add_osym(plugin, clish_script, "clish_script");
-	clish_plugin_add_psym(plugin, clish_machine_interface, "clish_machine_interface");
-	clish_plugin_add_psym(plugin, clish_human_interface, "clish_human_interface");
-	clish_plugin_add_psym(plugin, clish_print_script, "clish_print_script");
-	clish_plugin_add_psym(plugin, clish_print_var, "clish_print_var");
-*/
+	kplugin_t *plugin = NULL;
+
+	assert(context);
+	plugin = kcontext_plugin(context);
+	assert(plugin);
+
+	kplugin_add_sym(plugin, ksym_new("nop", klish_nop));
+
 //	fprintf(stderr, "Plugin 'klish' init\n");
 	context = context; // Happy compiler
 

+ 16 - 24
plugins/klish/private.h

@@ -1,27 +1,19 @@
 /*
- * builtin private.h
+ * private.h
  */
 
-#include "clish/plugin.h"
-#include "clish/shell.h"
-
-/* Hooks */
-CLISH_HOOK_ACCESS(clish_hook_access);
-CLISH_HOOK_CONFIG(clish_hook_config);
-CLISH_HOOK_LOG(clish_hook_log);
-
-/* Navy, etc. syms */
-CLISH_PLUGIN_SYM(clish_close);
-CLISH_PLUGIN_SYM(clish_source);
-CLISH_PLUGIN_SYM(clish_source_nostop);
-CLISH_PLUGIN_SYM(clish_overview);
-CLISH_PLUGIN_SYM(clish_history);
-CLISH_PLUGIN_SYM(clish_nested_up);
-CLISH_PLUGIN_SYM(clish_nop);
-CLISH_PLUGIN_SYM(clish_wdog);
-CLISH_PLUGIN_OSYM(clish_script);
-CLISH_PLUGIN_SYM(clish_macros);
-CLISH_PLUGIN_SYM(clish_machine_interface);
-CLISH_PLUGIN_SYM(clish_human_interface);
-CLISH_PLUGIN_SYM(clish_print_script);
-CLISH_PLUGIN_SYM(clish_print_var);
+#ifndef _plugins_klish_h
+#define _plugins_klish_h
+
+#include <faux/faux.h>
+#include <klish/kcontext_base.h>
+
+
+C_DECL_BEGIN
+
+int klish_nop(kcontext_t *context);
+
+C_DECL_END
+
+
+#endif