Serj Kalichev před 3 roky
rodič
revize
b264955601
6 změnil soubory, kde provedl 103 přidání a 0 odebrání
  1. 3 0
      klish/kcommand.h
  2. 4 0
      klish/kparam.h
  3. 20 0
      klish/kscheme/kcommand.c
  4. 30 0
      klish/kscheme/kparam.c
  5. 43 0
      klish/kscheme/kview.c
  6. 3 0
      klish/kview.h

+ 3 - 0
klish/kcommand.h

@@ -20,6 +20,9 @@ kcommand_t *kcommand_new(kcommand_info_t info);
 kcommand_t *kcommand_new_static(kcommand_info_t info);
 void kcommand_free(kcommand_t *command);
 
+const char *kcommand_name(const kcommand_t *command);
+const char *kcommand_help(const kcommand_t *command);
+
 C_DECL_END
 
 #endif // _klish_kcommand_h

+ 4 - 0
klish/kparam.h

@@ -21,6 +21,10 @@ kparam_t *kparam_new(kparam_info_t info);
 kparam_t *kparam_new_static(kparam_info_t info);
 void kparam_free(kparam_t *param);
 
+const char *kparam_name(const kparam_t *param);
+const char *kparam_help(const kparam_t *param);
+const char *kparam_ptype_str(const kparam_t *param);
+
 C_DECL_END
 
 #endif // _klish_kparam_h

+ 20 - 0
klish/kscheme/kcommand.c

@@ -54,3 +54,23 @@ void kcommand_free(kcommand_t *command)
 
 	faux_free(command);
 }
+
+
+const char *kcommand_name(const kcommand_t *command)
+{
+	assert(command);
+	if (!command)
+		return NULL;
+
+	return command->info.name;
+}
+
+
+const char *kcommand_help(const kcommand_t *command)
+{
+	assert(command);
+	if (!command)
+		return NULL;
+
+	return command->info.help;
+}

+ 30 - 0
klish/kscheme/kparam.c

@@ -54,3 +54,33 @@ void kparam_free(kparam_t *param)
 
 	faux_free(param);
 }
+
+
+const char *kparam_name(const kparam_t *param)
+{
+	assert(param);
+	if (!param)
+		return NULL;
+
+	return param->info.name;
+}
+
+
+const char *kparam_help(const kparam_t *param)
+{
+	assert(param);
+	if (!param)
+		return NULL;
+
+	return param->info.help;
+}
+
+
+const char *kparam_ptype_str(const kparam_t *param)
+{
+	assert(param);
+	if (!param)
+		return NULL;
+
+	return param->info.ptype;
+}

+ 43 - 0
klish/kscheme/kview.c

@@ -4,15 +4,36 @@
 #include <assert.h>
 
 #include <faux/str.h>
+#include <faux/list.h>
+#include <klish/kcommand.h>
 #include <klish/kview.h>
 
 
 struct kview_s {
 	bool_t is_static;
 	kview_info_t info;
+	faux_list_t *commands;
 };
 
 
+static int kview_command_compare(const void *first, const void *second)
+{
+	const kcommand_t *f = (const kcommand_t *)first;
+	const kcommand_t *s = (const kcommand_t *)second;
+
+	return strcmp(kcommand_name(f), kcommand_name(s));
+}
+
+
+static int kview_command_kcompare(const void *key, const void *list_item)
+{
+	const char *f = (const char *)key;
+	const kcommand_t *s = (const kcommand_t *)list_item;
+
+	return strcmp(f, kcommand_name(s));
+}
+
+
 static kview_t *kview_new_internal(kview_info_t info, bool_t is_static)
 {
 	kview_t *view = NULL;
@@ -26,6 +47,11 @@ static kview_t *kview_new_internal(kview_info_t info, bool_t is_static)
 	view->is_static = is_static;
 	view->info = info;
 
+	view->commands = faux_list_new(FAUX_LIST_SORTED, FAUX_LIST_UNIQUE,
+		kview_command_compare, kview_command_kcompare,
+		(void (*)(void *))kcommand_free);
+	assert(view->commands);
+
 	return view;
 }
 
@@ -50,6 +76,7 @@ void kview_free(kview_t *view)
 	if (!view->is_static) {
 		faux_str_free(view->info.name);
 	}
+	faux_list_free(view->commands);
 
 	faux_free(view);
 }
@@ -63,3 +90,19 @@ const char *kview_name(const kview_t *view)
 
 	return view->info.name;
 }
+
+
+bool_t kview_add_command(kview_t *view, kcommand_t *command)
+{
+	assert(view);
+	if (!view)
+		return BOOL_FALSE;
+	assert(command);
+	if (!command)
+		return BOOL_FALSE;
+
+	if (!faux_list_add(view->commands, command))
+		return BOOL_FALSE;
+
+	return BOOL_TRUE;
+}

+ 3 - 0
klish/kview.h

@@ -6,6 +6,8 @@
 #ifndef _klish_kview_h
 #define _klish_kview_h
 
+#include <klish/kcommand.h>
+
 typedef struct kview_s kview_t;
 
 typedef struct kview_info_s {
@@ -21,6 +23,7 @@ void kview_free(kview_t *view);
 
 const char *kview_name(const kview_t *view);
 
+bool_t kview_add_command(kview_t *view, kcommand_t *command);
 
 C_DECL_END