From f123412b5321c199f2ae32feb544f2eba5300f76 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 3 Sep 2020 10:02:52 +0200 Subject: [PATCH] vsh: Introduce wrapper for add_history() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- 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 #include -#if WITH_READLINE -# include -# include -#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 #include -#if WITH_READLINE -# include -# include -#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__)