+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.
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)
* $Id$
*/
+#include "config.h"
+
#include "libvirt/libvirt.h"
#include "libvirt/virterror.h"
#include <stdio.h>
#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"
}
}
+#ifdef HAVE_READLINE_READLINE_H
+
/* -----------------
* Readline stuff
* -----------------
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
*/
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);
}