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:
parent
028d6c0513
commit
f123412b53
@ -30,11 +30,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#if WITH_READLINE
|
|
||||||
# include <readline/readline.h>
|
|
||||||
# include <readline/history.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
#include "virbuffer.h"
|
#include "virbuffer.h"
|
||||||
@ -920,9 +915,8 @@ main(int argc, char **argv)
|
|||||||
if (ctl->cmdstr == NULL)
|
if (ctl->cmdstr == NULL)
|
||||||
break; /* EOF */
|
break; /* EOF */
|
||||||
if (*ctl->cmdstr) {
|
if (*ctl->cmdstr) {
|
||||||
#if WITH_READLINE
|
vshReadlineHistoryAdd(ctl->cmdstr);
|
||||||
add_history(ctl->cmdstr);
|
|
||||||
#endif
|
|
||||||
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
|
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
|
||||||
vshCommandRun(ctl, ctl->cmd);
|
vshCommandRun(ctl, ctl->cmd);
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#if WITH_READLINE
|
|
||||||
# include <readline/readline.h>
|
|
||||||
# include <readline/history.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "virt-admin.h"
|
#include "virt-admin.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
@ -1597,9 +1592,8 @@ main(int argc, char **argv)
|
|||||||
if (ctl->cmdstr == NULL)
|
if (ctl->cmdstr == NULL)
|
||||||
break; /* EOF */
|
break; /* EOF */
|
||||||
if (*ctl->cmdstr) {
|
if (*ctl->cmdstr) {
|
||||||
#if WITH_READLINE
|
vshReadlineHistoryAdd(ctl->cmdstr);
|
||||||
add_history(ctl->cmdstr);
|
|
||||||
#endif
|
|
||||||
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
|
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
|
||||||
vshCommandRun(ctl, ctl->cmd);
|
vshCommandRun(ctl, ctl->cmd);
|
||||||
}
|
}
|
||||||
|
12
tools/vsh.c
12
tools/vsh.c
@ -2925,6 +2925,12 @@ vshReadline(vshControl *ctl G_GNUC_UNUSED, const char *prompt)
|
|||||||
return readline(prompt);
|
return readline(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
vshReadlineHistoryAdd(const char *cmd)
|
||||||
|
{
|
||||||
|
return add_history(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
#else /* !WITH_READLINE */
|
#else /* !WITH_READLINE */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2960,6 +2966,12 @@ vshReadline(vshControl *ctl G_GNUC_UNUSED,
|
|||||||
return g_strdup(r);
|
return g_strdup(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
vshReadlineHistoryAdd(const char *cmd)
|
||||||
|
{
|
||||||
|
/* empty */
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* !WITH_READLINE */
|
#endif /* !WITH_READLINE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -463,6 +463,8 @@ bool cmdComplete(vshControl *ctl, const vshCmd *cmd);
|
|||||||
/* readline */
|
/* readline */
|
||||||
char * vshReadline(vshControl *ctl, const char *prompt);
|
char * vshReadline(vshControl *ctl, const char *prompt);
|
||||||
|
|
||||||
|
void vshReadlineHistoryAdd(const char *cmd);
|
||||||
|
|
||||||
/* allocation wrappers */
|
/* allocation wrappers */
|
||||||
void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
|
void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
|
||||||
#define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
|
#define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user