Browse Source

kaction contain reference to sym's plugin

Serj Kalichev 3 months ago
parent
commit
52f2608793
3 changed files with 20 additions and 4 deletions
  1. 4 0
      klish/kaction.h
  2. 7 0
      klish/kscheme/kaction.c
  3. 9 4
      klish/kscheme/kscheme.c

+ 4 - 0
klish/kaction.h

@@ -8,6 +8,7 @@
 
 #include <faux/error.h>
 #include <klish/ksym.h>
+#include <klish/kplugin.h>
 
 
 typedef struct kaction_s kaction_t;
@@ -51,6 +52,9 @@ bool_t kaction_set_script(kaction_t *action, const char *script);
 ksym_t *kaction_sym(const kaction_t *action);
 bool_t kaction_set_sym(kaction_t *action, ksym_t *sym);
 
+kplugin_t *kaction_plugin(const kaction_t *action);
+bool_t kaction_set_plugin(kaction_t *action, kplugin_t *plugin);
+
 tri_t kaction_permanent(const kaction_t *action);
 bool_t kaction_set_permanent(kaction_t *action, tri_t permanent);
 bool_t kaction_is_permanent(const kaction_t *action);

+ 7 - 0
klish/kscheme/kaction.c

@@ -9,11 +9,13 @@
 #include <klish/khelper.h>
 #include <klish/kaction.h>
 #include <klish/ksym.h>
+#include <klish/kplugin.h>
 
 
 struct kaction_s {
 	char *sym_ref; // Text reference to symbol
 	ksym_t *sym; // Symbol itself
+	kplugin_t *plugin; // Source of symbol
 	char *lock; // Named lock
 	bool_t interrupt;
 	bool_t interactive;
@@ -67,6 +69,10 @@ KSET_STR(action, script);
 KGET(action, ksym_t *, sym);
 KSET(action, ksym_t *, sym);
 
+// Plugin. Source of sym
+KGET(action, kplugin_t *, plugin);
+KSET(action, kplugin_t *, plugin);
+
 
 kaction_t *kaction_new(void)
 {
@@ -86,6 +92,7 @@ kaction_t *kaction_new(void)
 	action->update_retcode = BOOL_TRUE;
 	action->script = NULL;
 	action->sym = NULL;
+	action->plugin = NULL;
 
 	return action;
 }

+ 9 - 4
klish/kscheme/kscheme.c

@@ -171,7 +171,8 @@ bool_t kscheme_fini(kscheme_t *scheme, kcontext_t *context, faux_error_t *error)
 }
 
 
-ksym_t *kscheme_find_sym(const kscheme_t *scheme, const char *name)
+static ksym_t *kscheme_find_sym(const kscheme_t *scheme, const char *name,
+	kplugin_t **src_plugin)
 {
 	char *saveptr = NULL;
 	const char *delim = "@";
@@ -179,6 +180,7 @@ ksym_t *kscheme_find_sym(const kscheme_t *scheme, const char *name)
 	char *cmd_name = NULL;
 	char *full_name = NULL;
 	ksym_t *sym = NULL;
+	kplugin_t *plugin = NULL; // Source of sym
 
 	assert(scheme);
 	if (!scheme)
@@ -198,7 +200,6 @@ ksym_t *kscheme_find_sym(const kscheme_t *scheme, const char *name)
 
 	// Search for symbol within specified PLUGIN only
 	if (plugin_name) {
-		kplugin_t *plugin = NULL;
 		plugin = kscheme_find_plugin(scheme, plugin_name);
 		if (!plugin) {
 			faux_str_free(full_name);
@@ -209,7 +210,6 @@ ksym_t *kscheme_find_sym(const kscheme_t *scheme, const char *name)
 	// Search for symbol within all PLUGINs
 	} else {
 		kscheme_plugins_node_t *iter = NULL;
-		kplugin_t *plugin = NULL;
 		iter = kscheme_plugins_iter(scheme);
 		while ((plugin = kscheme_plugins_each(&iter))) {
 			sym = kplugin_find_sym(plugin, cmd_name);
@@ -218,6 +218,9 @@ ksym_t *kscheme_find_sym(const kscheme_t *scheme, const char *name)
 		}
 	}
 
+	if (sym && src_plugin)
+		*src_plugin = plugin;
+
 	faux_str_free(full_name);
 
 	return sym;
@@ -247,8 +250,9 @@ bool_t kscheme_prepare_action_list(kscheme_t *scheme, kentry_t *entry,
 	iter = faux_list_head(action_list);
 	while ((action = (kaction_t *)faux_list_each(&iter))) {
 		ksym_t *sym = NULL;
+		kplugin_t *plugin = NULL;
 		const char *sym_ref = kaction_sym_ref(action);
-		sym = kscheme_find_sym(scheme, sym_ref);
+		sym = kscheme_find_sym(scheme, sym_ref, &plugin);
 		if (!sym) {
 			faux_error_sprintf(error, "Can't find symbol \"%s\"",
 				sym_ref);
@@ -256,6 +260,7 @@ bool_t kscheme_prepare_action_list(kscheme_t *scheme, kentry_t *entry,
 			continue;
 		}
 		kaction_set_sym(action, sym);
+		kaction_set_plugin(action, plugin);
 		// Filter can't contain sync symbols.
 		if (kentry_filter(entry) && kaction_is_sync(action)) {
 			faux_error_sprintf(error, "Filter \"%s\" can't contain "