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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2020-09-03 10:02:52 +02:00
parent 028d6c0513
commit f123412b53
4 changed files with 18 additions and 16 deletions

View File

@ -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);
}

View File

@ -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);
}

View 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 */
/*

View 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__)