[Sheepdog] [PATCH 2/2] collie: remove ncurses dependency

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu May 20 10:06:04 CEST 2010


Using ncurses library is overkill.  We only want to use the bold text.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/Makefile   |    1 -
 collie/collie.c   |   27 +++++++++++----------------
 collie/treeview.c |   12 +++++++-----
 3 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/collie/Makefile b/collie/Makefile
index 98ef2b1..0dc6ed5 100644
--- a/collie/Makefile
+++ b/collie/Makefile
@@ -2,7 +2,6 @@ sbindir ?= $(PREFIX)/sbin
 
 CFLAGS += -g -O2 -Wall -Wstrict-prototypes -I../include
 CFLAGS += -D_GNU_SOURCE
-LIBS += -lncurses
 
 PROGRAMS = collie
 COLLIE_OBJS = collie.o treeview.o ../lib/event.o ../lib/net.o ../lib/logger.o
diff --git a/collie/collie.c b/collie/collie.c
index 9efb532..714eeac 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -25,7 +25,6 @@
 #include <time.h>
 #include <sys/time.h>
 #include <term.h>
-#include <curses.h>
 
 #include "sheepdog_proto.h"
 #include "sheep.h"
@@ -36,6 +35,9 @@ static char program_name[] = "collie";
 static int sdport = SD_LISTEN_PORT;
 static int highlight = 1;
 
+#define TEXT_NORMAL "\033[0m"
+#define TEXT_BOLD   "\033[1m"
+
 #define COMMON_LONG_OPTIONS				\
 	{"port", required_argument, NULL, 'p'},		\
 	{"help", no_argument, NULL, 'h'},		\
@@ -367,9 +369,8 @@ static void print_vm_list(uint32_t vid, char *name, uint32_t tag,
 	size_to_str(my_objs * SD_DATA_OBJ_SIZE, my_objs_str, sizeof(my_objs_str));
 	size_to_str(cow_objs * SD_DATA_OBJ_SIZE, cow_objs_str, sizeof(cow_objs_str));
 	if (i < vli->nr_vms) {
-		char *tmp;
-		if (vli->highlight && (tmp = tgetstr((char *)"md", (char **)NULL)))
-			tputs(tmp, 1, putchar);
+		if (vli->highlight)
+			printf(TEXT_BOLD);
 
 		printf("%-16s|%9s|%9s|%9s| running on %d.%d.%d.%d", name,
 		       vdi_size_str, my_objs_str, cow_objs_str,
@@ -377,8 +378,8 @@ static void print_vm_list(uint32_t vid, char *name, uint32_t tag,
 		       vli->vm_list_entries[i].host_addr[13],
 		       vli->vm_list_entries[i].host_addr[14],
 		       vli->vm_list_entries[i].host_addr[15]);
-		if (vli->highlight && (tmp = tgetstr((char *)"me", (char **)NULL)))
-			tputs(tmp, 1, putchar);
+		if (vli->highlight)
+			printf(TEXT_NORMAL);
 		printf("\n");
 	} else
 		printf("%-16s|%9s|%9s|%9s| not running\n", name,
@@ -542,13 +543,11 @@ static int node_list(int argc, char **argv)
 		print_node_list_entry(&node_list_entries[i], data, sizeof(data));
 
 		if (i == master_idx) {
-			const char *tmp;
-
-			if (highlight && (tmp = tgetstr((char *)"md", (char **)NULL)))
-				tputs(tmp, 1, putchar);
+			if (highlight)
+				printf(TEXT_BOLD);
 			printf("* %d\t%s\n", i, data);
-			if (highlight && (tmp = tgetstr((char *)"me", (char **)NULL)))
-				tputs(tmp, 1, putchar);
+			if (highlight)
+				printf(TEXT_NORMAL);
 		} else
 			printf("  %d\t%s\n", i, data);
 	}
@@ -1041,12 +1040,8 @@ static unsigned long setup_command(char *cmd, char *subcmd)
 int main(int argc, char **argv)
 {
 	int ch, longindex, ret;
-	char termcap_area[1024];
 	unsigned long flags;
 
-	if (getenv("TERM"))
-		tgetent(termcap_area, getenv("TERM"));
-
 	if (argc < 3)
 		usage(0);
 
diff --git a/collie/treeview.c b/collie/treeview.c
index c5adb96..2f21dd7 100644
--- a/collie/treeview.c
+++ b/collie/treeview.c
@@ -21,6 +21,9 @@
 #define MAX_DEPTH    100
 #endif
 
+#define TEXT_NORMAL "\033[0m"
+#define TEXT_BOLD   "\033[1m"
+
 struct vdi_tree {
 	char name[1024];
 	char label[256];
@@ -143,18 +146,17 @@ static void indent(int level, int first, int last)
 
 static void _dump_tree(struct vdi_tree *current, int level, int first, int last)
 {
-	char *tmp;
 	struct vdi_tree *vdi;
 
 	indent(level, first, last);
 
-	if (current->highlight && (tmp = tgetstr("md", NULL)))
-		tputs(tmp, 1, putchar);
+	if (current->highlight)
+		printf(TEXT_BOLD);
 
 	printf(current->label);
 
-	if (current->highlight && (tmp = tgetstr("me", NULL)))
-		tputs(tmp, 1, putchar);
+	if (current->highlight)
+		printf(TEXT_NORMAL);
 
 	if (list_empty(&current->children)) {
 		putchar('\n');
-- 
1.5.6.5




More information about the sheepdog mailing list