Bläddra i källkod

Untested completion sym

Serj Kalichev 1 år sedan
förälder
incheckning
f315084dc7
5 ändrade filer med 96 tillägg och 68 borttagningar
  1. 2 1
      src/Makefile.am
  2. 4 31
      src/plugin.c
  3. 0 36
      src/private.h
  4. 71 0
      src/syms.c
  5. 19 0
      src/syms.h

+ 2 - 1
src/Makefile.am

@@ -9,8 +9,9 @@ kplugin_sysrepo_la_CFLAGS = $(AM_LDFLAGS)
 #kplugin_sysrepo_la_LIBADD = libsysrepo.la
 
 kplugin_sysrepo_la_SOURCES += \
-	src/private.h \
 	src/plugin.c \
+	src/syms.h \
+	src/syms.c \
 	src/sr_copypaste.h \
 	src/sr_copypaste.c \
 	src/pline.h \

+ 4 - 31
src/plugin.c

@@ -13,7 +13,7 @@
 #include <sysrepo.h>
 #include <sysrepo/xpath.h>
 
-#include "private.h"
+#include "syms.h"
 
 
 const uint8_t kplugin_sysrepo_major = KPLUGIN_MAJOR;
@@ -46,36 +46,9 @@ int kplugin_sysrepo_init(kcontext_t *context)
 
 	kplugin_set_udata(plugin, sess);
 
-/*
-	// Misc
-	kplugin_add_syms(plugin, ksym_new_ext("nop", klish_nop,
-		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
-	kplugin_add_syms(plugin, ksym_new("tsym", klish_tsym));
-	kplugin_add_syms(plugin, ksym_new("print", klish_print));
-	kplugin_add_syms(plugin, ksym_new_ext("pwd", klish_pwd,
-		KSYM_PERMANENT, KSYM_SYNC));
-
-	// Navigation
-	// Navigation must be permanent (no dry-run) and sync. Because unsync
-	// actions will be fork()-ed so it can't change current path.
-	kplugin_add_syms(plugin, ksym_new_ext("nav", klish_nav,
-		KSYM_PERMANENT, KSYM_SYNC));
-
-	// PTYPEs
-	// These PTYPEs are simple and fast so set SYNC flag
-	kplugin_add_syms(plugin, ksym_new_ext("COMMAND", klish_ptype_COMMAND,
-		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
-	kplugin_add_syms(plugin, ksym_new_ext("completion_COMMAND", klish_completion_COMMAND,
-		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
-	kplugin_add_syms(plugin, ksym_new_ext("COMMAND_CASE", klish_ptype_COMMAND_CASE,
-		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
-	kplugin_add_syms(plugin, ksym_new_ext("INT", klish_ptype_INT,
-		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
-	kplugin_add_syms(plugin, ksym_new_ext("UINT", klish_ptype_UINT,
-		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
-	kplugin_add_syms(plugin, ksym_new_ext("STRING", klish_ptype_STRING,
-		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
-*/
+	// Symbols
+	kplugin_add_syms(plugin, ksym_new("srp_compl", srp_compl));
+
 	return 0;
 }
 

+ 0 - 36
src/private.h

@@ -1,36 +0,0 @@
-/*
- * private.h
- */
-
-#ifndef _private_h
-#define _private_h
-
-#include <faux/faux.h>
-#include <klish/kcontext_base.h>
-
-
-C_DECL_BEGIN
-
-/*
-// Misc
-int klish_nop(kcontext_t *context);
-int klish_tsym(kcontext_t *context);
-int klish_print(kcontext_t *context);
-int klish_pwd(kcontext_t *context);
-
-// Navigation
-int klish_nav(kcontext_t *context);
-
-// PTYPEs
-int klish_ptype_COMMAND(kcontext_t *context);
-int klish_completion_COMMAND(kcontext_t *context);
-int klish_ptype_COMMAND_CASE(kcontext_t *context);
-int klish_ptype_INT(kcontext_t *context);
-int klish_ptype_UINT(kcontext_t *context);
-int klish_ptype_STRING(kcontext_t *context);
-*/
-
-C_DECL_END
-
-
-#endif // _private_h

+ 71 - 0
src/syms.c

@@ -0,0 +1,71 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <sysrepo.h>
+#include <sysrepo/xpath.h>
+
+#include <faux/faux.h>
+#include <faux/argv.h>
+#include <faux/str.h>
+#include <faux/list.h>
+#include <faux/error.h>
+#include <klish/khelper.h>
+#include <klish/kplugin.h>
+#include <klish/kentry.h>
+#include <klish/kscheme.h>
+#include <klish/kcontext.h>
+#include <klish/kpargv.h>
+
+#include "pline.h"
+
+
+int srp_compl(kcontext_t *context)
+{
+	const kpargv_t *pargv = NULL;
+	const kentry_t *candidate = NULL;
+	faux_list_node_t *iter = NULL;
+	faux_list_t *pargs = NULL;
+	faux_argv_t *args = faux_argv_new();
+	pline_t *pline = NULL;
+
+	pargv = kcontext_parent_pargv(context);
+	pargs = kpargv_pargs(pargv);
+	candidate = kparg_entry(kpargv_candidate_parg(pargv));
+	sr_session_ctx_t *sess = NULL;
+
+	iter = faux_list_tail(pargs);
+	do {
+		faux_list_node_t *prev = faux_list_prev_node(iter);
+		if (prev) {
+			kparg_t *parg = (kparg_t *)faux_list_data(prev);
+			if (kparg_entry(parg) != candidate)
+				break;
+		} else {
+			break;
+		}
+		iter = prev;
+	} while (iter);
+
+	while (iter) {
+		kparg_t *parg = (kparg_t *)faux_list_data(iter);
+		faux_argv_add(args, kparg_value(parg));
+		iter = faux_list_next_node(iter);
+	}
+
+	faux_argv_set_continuable(args, kpargv_continuable(pargv));
+
+
+	sess = (sr_session_ctx_t *)kplugin_udata(kcontext_plugin(context));
+
+	faux_argv_del_continuable(args);
+	pline = pline_parse(sess, args, 0);
+	faux_argv_free(args);
+	pline_print_completions(pline, BOOL_TRUE);
+	pline_free(pline);
+
+	faux_argv_free(args);
+
+	return 0;
+}

+ 19 - 0
src/syms.h

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