[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH v2 1/2] vsh: Introduce wrapper for add_history()



This allows us to drop include of readline header files from
virsh.c and virt-admin.c because they needed it only because of
the add_history() function.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 tools/virsh.c      | 10 ++--------
 tools/virt-admin.c | 10 ++--------
 tools/vsh.c        | 12 ++++++++++++
 tools/vsh.h        |  2 ++
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 06ff5e8336..ac9b7ad238 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -30,11 +30,6 @@
 #include <sys/stat.h>
 #include <inttypes.h>
 
-#if WITH_READLINE
-# include <readline/readline.h>
-# include <readline/history.h>
-#endif
-
 #include "internal.h"
 #include "virerror.h"
 #include "virbuffer.h"
@@ -920,9 +915,8 @@ main(int argc, char **argv)
             if (ctl->cmdstr == NULL)
                 break;          /* EOF */
             if (*ctl->cmdstr) {
-#if WITH_READLINE
-                add_history(ctl->cmdstr);
-#endif
+                vshReadlineHistoryAdd(ctl->cmdstr);
+
                 if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
                     vshCommandRun(ctl, ctl->cmd);
             }
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 774661b2ca..72084a78e9 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -24,11 +24,6 @@
 #include <unistd.h>
 #include <getopt.h>
 
-#if WITH_READLINE
-# include <readline/readline.h>
-# include <readline/history.h>
-#endif
-
 #include "internal.h"
 #include "virt-admin.h"
 #include "viralloc.h"
@@ -1597,9 +1592,8 @@ main(int argc, char **argv)
             if (ctl->cmdstr == NULL)
                 break;          /* EOF */
             if (*ctl->cmdstr) {
-#if WITH_READLINE
-                add_history(ctl->cmdstr);
-#endif
+                vshReadlineHistoryAdd(ctl->cmdstr);
+
                 if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
                     vshCommandRun(ctl, ctl->cmd);
             }
diff --git a/tools/vsh.c b/tools/vsh.c
index 11f493f969..2511089e6e 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2925,6 +2925,12 @@ vshReadline(vshControl *ctl G_GNUC_UNUSED, const char *prompt)
     return readline(prompt);
 }
 
+void
+vshReadlineHistoryAdd(const char *cmd)
+{
+    return add_history(cmd);
+}
+
 #else /* !WITH_READLINE */
 
 static int
@@ -2960,6 +2966,12 @@ vshReadline(vshControl *ctl G_GNUC_UNUSED,
     return g_strdup(r);
 }
 
+void
+vshReadlineHistoryAdd(const char *cmd)
+{
+    /* empty */
+}
+
 #endif /* !WITH_READLINE */
 
 /*
diff --git a/tools/vsh.h b/tools/vsh.h
index 290bb71f3e..0a40995bf5 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -463,6 +463,8 @@ bool cmdComplete(vshControl *ctl, const vshCmd *cmd);
 /* readline */
 char * vshReadline(vshControl *ctl, const char *prompt);
 
+void vshReadlineHistoryAdd(const char *cmd);
+
 /* allocation wrappers */
 void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
 #define vshMalloc(_ctl, _sz)    _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
-- 
2.26.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]