]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vsh: Introduce wrapper for add_history()
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Sep 2020 08:02:52 +0000 (10:02 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Sep 2020 14:25:43 +0000 (16:25 +0200)
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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh.c
tools/virt-admin.c
tools/vsh.c
tools/vsh.h

index 06ff5e833655c16bce8c26f1a7c81167b1b14818..ac9b7ad2385f32f45acb09e2eedf7dec7c19fe60 100644 (file)
 #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);
             }
index 774661b2ca87b85988bc875dcaa320e61ad7c2b7..72084a78e906a53040173f3ce376cf4890e98f08 100644 (file)
 #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);
             }
index 11f493f969e8eb499d27181c9614fe3ee422b157..2511089e6e2e09308581205f36d0d19e71c2c98c 100644 (file)
@@ -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 */
 
 /*
index 290bb71f3e8cfa1191ecf62bf6d6cf2489681ba9..0a40995bf5d1921748f9a3bc264270f7e6431d9c 100644 (file)
@@ -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__)