From 0d8043574d0dc39c8faa449278a0757dd346aad9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 8 Dec 2005 10:23:34 +0000 Subject: [PATCH] virsh is more sexy now --- ChangeLog | 4 + configure.in | 11 + src/Makefile.am | 3 +- src/virsh.c | 1455 +++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 1375 insertions(+), 98 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b5dac79e5..b80ef0b113 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Dec 8 11:19:48 CET 2005 Karel Zak + * src/Makefile.am src/virsh.c configure.in: adding readline support, + and implement basic commands to virsh. + Thu Dec 8 11:12:36 CET 2005 Daniel Veillard * src/libvir.c src/xen_internal.c: fixed the new Xen hypervisor call diff --git a/configure.in b/configure.in index 2751a725c1..78148e0abe 100644 --- a/configure.in +++ b/configure.in @@ -77,4 +77,15 @@ AC_SUBST(STATIC_BINARIES) dnl search for the low level Xen library AC_SEARCH_LIBS(xs_read, [xenstore], [], [AC_MSG_ERROR([Xen store library not found])]) +dnl virsh libraries +AC_CHECK_LIB(curses, initscr, + [VIRSH_LIBS="$VIRSH_LIBS -lcurses"], + [AC_MSG_ERROR([curses library not found])], + [$VIRSH_LIBS]) +AC_CHECK_LIB(readline, main, + [VIRSH_LIBS="$VIRSH_LIBS -lreadline"], + [AC_MSG_ERROR([readline library not found])], + [$VIRSH_LIBS]) +AC_SUBST(VIRSH_LIBS) + AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile libvir.pc libvir.spec) diff --git a/src/Makefile.am b/src/Makefile.am index d70d6e4fb8..4da4f3714f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,6 +3,7 @@ INCLUDES = -I$(top_builddir)/include -I@srcdir@/include DEPS = libvir.la LDADDS = @STATIC_BINARIES@ libvir.la +VIRSH_LIBS = @VIRSH_LIBS@ EXTRA_DIST = libvir_sym.version @@ -20,5 +21,5 @@ noinst_PROGRAMS=virsh virsh_SOURCES=virsh.c virsh_LDFLAGS = virsh_DEPENDENCIES = $(DEPS) -virsh_LDADD= $(LDADDS) +virsh_LDADD= $(LDADDS) $(VIRSH_LIBS) diff --git a/src/virsh.c b/src/virsh.c index 349662c479..0ea7721aff 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -8,113 +8,1374 @@ * Daniel Veillard */ +#define _GNU_SOURCE /* isblank() */ + #include "libvir.h" #include +#include +#include +#include #include +#include #include +#include + +#include +#include + +#include "config.h" + +static char *progname; + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +#define VSH_PROMPT_RW "virsh # " +#define VSH_PROMPT_RO "virsh > " + +#define GETTIMEOFDAY(T) gettimeofday(T, NULL) +#define DIFF_MSEC(T, U) \ + ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ + ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) + +typedef enum { + VSH_MESG, /* standard output */ + VSH_HEADER, /* header for standard output */ + VSH_FOOTER, /* timing, last command state, or whatever */ + VSH_DEBUG1, /* debugN where 'N' = level */ + VSH_DEBUG2, + VSH_DEBUG3, + VSH_DEBUG4, + VSH_DEBUG5 +} vshOutType; + +/* + * virsh command line grammar: + * + * command_line = \n | ; ; ... + * + * command =