]> xenbits.xensource.com Git - libvirt.git/commitdiff
Tue Dec 4 17:47:01 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 4 Dec 2007 18:27:52 +0000 (18:27 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 4 Dec 2007 18:27:52 +0000 (18:27 +0000)
* 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.

ChangeLog
configure.in
src/virsh.c

index 810c0109a1c48b08e2b60e2355f99a3e96d51055..e6873058516d92344aa4ffcfe7fa51c5e8905186 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
index a8457202d6e2fa12786225b14f54c4c55fa098a9..6297483063e6adb5e3157bae3ad0fe07bf59abc5 100644 (file)
@@ -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)
 
index ccd85be0e1cf6a8959d28fc0dd6d8278247b37fa..207a0ddc7252b19d8f4d02bd8bb42920b4b9b3c1 100644 (file)
@@ -13,6 +13,8 @@
  * $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"
 
@@ -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);
             }