Browse Source

ktp_session: Separate file for help_t type

Serj Kalichev 1 year ago
parent
commit
e21c9b9f32
3 changed files with 13 additions and 46 deletions
  1. 2 1
      klish/ktp/Makefile.am
  2. 0 45
      klish/ktp/ktpd_session.c
  3. 11 0
      klish/ktp_session.h

+ 2 - 1
klish/ktp/Makefile.am

@@ -1,4 +1,5 @@
 libklish_la_SOURCES += \
 	klish/ktp/ktp.c \
 	klish/ktp/ktp_session.c \
-	klish/ktp/ktpd_session.c
+	klish/ktp/ktpd_session.c \
+	klish/ktp/help.c

+ 0 - 45
klish/ktp/ktpd_session.c

@@ -439,51 +439,6 @@ static bool_t ktpd_session_process_completion(ktpd_session_t *ktpd, faux_msg_t *
 }
 
 
-typedef struct help_s {
-	char *prefix;
-	char *line;
-} help_t;
-
-
-static int help_compare(const void *first, const void *second)
-{
-	const help_t *f = (const help_t *)first;
-	const help_t *s = (const help_t *)second;
-
-	return strcmp(f->prefix, s->prefix);
-}
-
-
-static int help_kcompare(const void *key, const void *list_item)
-{
-	const char *f = (const char *)key;
-	const help_t *s = (const help_t *)list_item;
-
-	return strcmp(f, s->prefix);
-}
-
-
-static help_t *help_new(char *prefix, char *line)
-{
-	help_t *help = NULL;
-
-	help = faux_zmalloc(sizeof(*help));
-	help->prefix = prefix;
-	help->line = line;
-
-	return help;
-}
-
-
-static void help_free(void *ptr)
-{
-	help_t *help = (help_t *)ptr;
-
-	faux_free(help->prefix);
-	faux_free(help->line);
-}
-
-
 // Now help generation is simple. The 'prefix' (first help field) is generated
 // by PTYPE's help function. It can be something like 'ip', 'filter' i.e.
 // subcommand or '3..89', '<STRING>' i.e. description of type. The second

+ 11 - 0
klish/ktp_session.h

@@ -31,6 +31,17 @@ bool_t ktp_peer_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data);
 bool_t ktp_stall_cb(faux_async_t *async, size_t len, void *user_data);
 
+// Help structure
+typedef struct help_s {
+	char *prefix;
+	char *line;
+} help_t;
+
+int help_compare(const void *first, const void *second);
+int help_kcompare(const void *key, const void *list_item);
+help_t *help_new(char *prefix, char *line);
+void help_free(void *ptr);
+
 
 // Client KTP session