提交 4338271f 编写于 作者: R Richard W.M. Jones

Tue Dec 4 17:47:01 UTC 2007 Richard W.M. Jones <rjones@redhat.com>

	* configure.in: curses is not actually required to build libvirt
	* configure.in, src/virsh.c: Make readline optional.  If not
	  available then virsh is built without support for command
	  line editing.
上级 025c5df8
Tue Dec 4 17:47:01 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
* configure.in: curses is not actually required to build libvirt
* configure.in, src/virsh.c: Make readline optional. If not
available then virsh is built without support for command
line editing.
Mon Dec 3 20:44:01 CET 2007 Jim Meyering <meyering@redhat.com>
Avoid compile failure when HAVE_AVAHI is not defined.
......
......@@ -383,16 +383,10 @@ AC_SUBST(AVAHI_CFLAGS)
AC_SUBST(AVAHI_LIBS)
dnl virsh libraries
AC_CHECK_LIB(curses, initscr,
[VIRSH_LIBS="$VIRSH_LIBS -lcurses"],
[AC_CHECK_LIB(ncurses, initscr,
[VIRSH_LIBS="$VIRSH_LIBS -lncurses"],
[AC_MSG_ERROR([curses/ncurses library not found])],
[$VIRSH_LIBS])],
[$VIRSH_LIBS])
AC_CHECK_HEADERS([readline/readline.h])
AC_CHECK_LIB(readline, main,
[VIRSH_LIBS="$VIRSH_LIBS -lreadline"],
[AC_MSG_ERROR([readline library not found])],
[AC_MSG_WARN([readline library not found])],
[$VIRSH_LIBS])
AC_SUBST(VIRSH_LIBS)
......
......@@ -13,6 +13,8 @@
* $Id$
*/
#include "config.h"
#include "libvirt/libvirt.h"
#include "libvirt/virterror.h"
#include <stdio.h>
......@@ -39,10 +41,11 @@
#include <libxml/tree.h>
#include <libxml/xpath.h>
#ifdef HAVE_READLINE_READLINE_H
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include "config.h"
#include "internal.h"
#include "console.h"
......@@ -4656,6 +4659,8 @@ vshCloseLogFile(vshControl *ctl)
}
}
#ifdef HAVE_READLINE_READLINE_H
/* -----------------
* Readline stuff
* -----------------
......@@ -4773,6 +4778,41 @@ vshReadlineInit(void)
rl_attempted_completion_function = vshReadlineCompletion;
}
static char *
vshReadline (vshControl *ctl ATTRIBUTE_UNUSED, const char *prompt)
{
return readline (prompt);
}
#else /* !HAVE_READLINE_READLINE_H */
static void
vshReadlineInit (void)
{
/* empty */
}
static char *
vshReadline (vshControl *ctl, const char *prompt)
{
char line[1024];
char *r;
int len;
fputs (prompt, stdout);
r = fgets (line, sizeof line, stdin);
if (r == NULL) return NULL; /* EOF */
/* Chomp trailing \n */
len = strlen (r);
if (len > 0 && r[len-1] == '\n')
r[len-1] = '\0';
return vshStrdup (ctl, r);
}
#endif /* !HAVE_READLINE_READLINE_H */
/*
* Deinitliaze virsh
*/
......@@ -5013,11 +5053,13 @@ main(int argc, char **argv)
vshReadlineInit();
do {
ctl->cmdstr =
readline(ctl->uid == 0 ? VSH_PROMPT_RW : VSH_PROMPT_RO);
vshReadline(ctl, ctl->uid == 0 ? VSH_PROMPT_RW : VSH_PROMPT_RO);
if (ctl->cmdstr == NULL)
break; /* EOF */
if (*ctl->cmdstr) {
#if HAVE_READLINE_READLINE_H
add_history(ctl->cmdstr);
#endif
if (vshCommandParse(ctl, ctl->cmdstr))
vshCommandRun(ctl, ctl->cmd);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册