Browse Source

shell: Add shell plugin. Not working yet

Serj Kalichev 1 year ago
parent
commit
100a7eebb8
5 changed files with 107 additions and 1 deletions
  1. 3 1
      plugins/Makefile.am
  2. 11 0
      plugins/shell/Makefile.am
  3. 41 0
      plugins/shell/plugin_init.c
  4. 19 0
      plugins/shell/private.h
  5. 33 0
      plugins/shell/shell.c

+ 3 - 1
plugins/Makefile.am

@@ -3,7 +3,9 @@ plugin_LTLIBRARIES =
 
 EXTRA_DIST += \
 	plugins/klish/Makefile.am \
-	plugins/lua/Makefile.am
+	plugins/lua/Makefile.am \
+	plugins/shell/Makefile.am
 
 include $(top_srcdir)/plugins/klish/Makefile.am
 include $(top_srcdir)/plugins/lua/Makefile.am
+include $(top_srcdir)/plugins/shell/Makefile.am

+ 11 - 0
plugins/shell/Makefile.am

@@ -0,0 +1,11 @@
+plugin_LTLIBRARIES += kplugin-shell.la
+kplugin_shell_la_SOURCES =
+kplugin_shell_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version -module
+kplugin_shell_la_LIBS =
+kplugin_shell_la_CFLAGS = $(AM_LDFLAGS)
+kplugin_shell_la_LIBADD = libklish.la
+
+kplugin_shell_la_SOURCES += \
+	plugins/shell/private.h \
+	plugins/shell/plugin_init.c \
+	plugins/shell/shell.c

+ 41 - 0
plugins/shell/plugin_init.c

@@ -0,0 +1,41 @@
+/*
+ *
+ */
+#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"
+
+
+const uint8_t kplugin_shell_major = KPLUGIN_MAJOR;
+const uint8_t kplugin_shell_minor = KPLUGIN_MINOR;
+
+
+int kplugin_shell_init(kcontext_t *context)
+{
+	kplugin_t *plugin = NULL;
+	ksym_t *sym = NULL;
+
+	assert(context);
+	plugin = kcontext_plugin(context);
+	assert(plugin);
+
+	kplugin_add_syms(plugin, ksym_new("shell", shell_shell));
+
+	return 0;
+}
+
+
+int kplugin_shell_fini(kcontext_t *context)
+{
+//	fprintf(stderr, "Plugin 'shell' fini\n");
+	context = context;
+
+	return 0;
+}

+ 19 - 0
plugins/shell/private.h

@@ -0,0 +1,19 @@
+/*
+ * private.h
+ */
+
+#ifndef _plugins_shell_h
+#define _plugins_shell_h
+
+#include <faux/faux.h>
+#include <klish/kcontext_base.h>
+
+
+C_DECL_BEGIN
+
+int shell_shell(kcontext_t *context);
+
+C_DECL_END
+
+
+#endif // _plugins_shell_h

+ 33 - 0
plugins/shell/shell.c

@@ -0,0 +1,33 @@
+/*
+ *
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#include <faux/str.h>
+#include <faux/list.h>
+#include <klish/kcontext.h>
+#include <klish/ksession.h>
+
+
+// Execute shell script
+int shell_shell(kcontext_t *context)
+{
+	const char *script = NULL;
+
+	script = kcontext_script(context);
+	if (faux_str_is_empty(script))
+		return 0;
+
+//	printf("%s", prompt);
+//	faux_str_free(prompt);
+//	fflush(stdout);
+
+	return 0;
+}