Преглед изворни кода

plugin.klish: COMMAND_CASE ptype

Serj Kalichev пре 3 година
родитељ
комит
6a394421fc
3 измењених фајлова са 24 додато и 1 уклоњено
  1. 1 0
      plugins/klish/plugin_init.c
  2. 1 0
      plugins/klish/private.h
  3. 22 1
      plugins/klish/ptypes.c

+ 1 - 0
plugins/klish/plugin_init.c

@@ -31,6 +31,7 @@ int kplugin_klish_init(kcontext_t *context)
 
 	// PTYPEs
 	kplugin_add_syms(plugin, ksym_new("COMMAND", klish_ptype_COMMAND));
+	kplugin_add_syms(plugin, ksym_new("COMMAND_CASE", klish_ptype_COMMAND_CASE));
 
 	context = context; // Happy compiler
 

+ 1 - 0
plugins/klish/private.h

@@ -16,6 +16,7 @@ int klish_tsym(kcontext_t *context);
 
 // PTYPEs
 int klish_ptype_COMMAND(kcontext_t *context);
+int klish_ptype_COMMAND_CASE(kcontext_t *context);
 
 
 C_DECL_END

+ 22 - 1
plugins/klish/ptypes.c

@@ -22,7 +22,7 @@ int klish_ptype_COMMAND(kcontext_t *context)
 	const char *value = NULL;
 	const char *command_name = NULL;
 
-	parg = kpargv_candidate_parg(kcontext_parent_pargv(context));
+	parg = kcontext_candidate_parg(context);
 	entry = kparg_entry(parg);
 	value = kparg_value(parg);
 
@@ -34,3 +34,24 @@ int klish_ptype_COMMAND(kcontext_t *context)
 
 	return faux_str_casecmp(value, command_name);
 }
+
+
+int klish_ptype_COMMAND_CASE(kcontext_t *context)
+{
+	kparg_t *parg = NULL;
+	const kentry_t *entry = NULL;
+	const char *value = NULL;
+	const char *command_name = NULL;
+
+	parg = kcontext_candidate_parg(context);
+	entry = kparg_entry(parg);
+	value = kparg_value(parg);
+
+	command_name = kentry_value(entry);
+	if (!command_name)
+		command_name = kentry_name(entry);
+	if (!command_name)
+		return -1;
+
+	return strcmp(value, command_name);
+}