diff mbox

[powerdebug,12/17] find a clock with a clock name

Message ID 1308610705-23281-12-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 20, 2011, 10:58 p.m. UTC
and add a 'find' ops.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 clocks.c  |   87 ++++++++++++++++++++++++++++++++++--------------------------
 display.c |   17 ++++++++++--
 display.h |    1 +
 3 files changed, 64 insertions(+), 41 deletions(-)
diff mbox

Patch

diff --git a/clocks.c b/clocks.c
index 59db8a7..2ae2f5a 100644
--- a/clocks.c
+++ b/clocks.c
@@ -159,28 +159,6 @@  static int dump_all_parents(char *clkarg)
 	return tree_for_each_parent(tree, dump_clock_cb, NULL);
 }
 
-void find_parents_for_clock(char *clkname, int complete)
-{
-	char name[256];
-
-	name[0] = '\0';
-	if (!complete) {
-		char str[256];
-
-		strcat(name, clkname);
-		sprintf(str, "Enter Clock Name : %s\n", name);
-		display_reset_cursor(CLOCK);
-		display_print_line(CLOCK, 0, str, 1, NULL);
-		display_refresh_pad(CLOCK);
-		return;
-	}
-	sprintf(name, "Parents for \"%s\" Clock : \n", clkname);
-	display_reset_cursor(CLOCK);
-	display_print_line(CLOCK, 0, name, 1, NULL);
-	display_refresh_pad(CLOCK);
-	dump_all_parents(clkname);
-}
-
 static inline int read_clock_cb(struct tree *t, void *data)
 {
 	struct clock_info *clk = t->private;
@@ -192,9 +170,9 @@  static inline int read_clock_cb(struct tree *t, void *data)
 	return 0;
 }
 
-static int read_clock_info(void)
+static int read_clock_info(struct tree *tree)
 {
-	return tree_for_each(clock_tree, read_clock_cb, NULL);
+	return tree_for_each(tree, read_clock_cb, NULL);
 }
 
 static int fill_clock_cb(struct tree *t, void *data)
@@ -259,20 +237,12 @@  free_clkname:
 	return clkline;
 }
 
-static int clock_print_info_cb(struct tree *t, void *data)
+static int _clock_print_info_cb(struct tree *t, void *data)
 {
 	struct clock_info *clock = t->private;
 	int *line = data;
 	char *buffer;
 
-        /* we skip the root node of the tree */
-	if (!t->parent)
-		return 0;
-
-        /* show the clock when *all* its parent is expanded */
-	if (tree_for_each_parent(t->parent, is_collapsed, NULL))
-		return 0;
-
 	buffer = clock_line(t);
 	if (!buffer)
 		return -1;
@@ -286,6 +256,19 @@  static int clock_print_info_cb(struct tree *t, void *data)
 	return 0;
 }
 
+static int clock_print_info_cb(struct tree *t, void *data)
+{
+        /* we skip the root node of the tree */
+	if (!t->parent)
+		return 0;
+
+        /* show the clock when *all* its parent is expanded */
+	if (tree_for_each_parent(t->parent, is_collapsed, NULL))
+		return 0;
+
+	return _clock_print_info_cb(t, data);
+}
+
 static int clock_print_header(void)
 {
 	char *buf;
@@ -302,7 +285,7 @@  static int clock_print_header(void)
 	return ret;
 }
 
-static int clock_print_info(void)
+static int clock_print_info(struct tree *tree)
 {
 	int ret, line = 0;
 
@@ -310,7 +293,7 @@  static int clock_print_info(void)
 
 	clock_print_header();
 
-	ret = tree_for_each(clock_tree, clock_print_info_cb, &line);
+	ret = tree_for_each(tree, clock_print_info_cb, &line);
 
 	display_refresh_pad(CLOCK);
 
@@ -334,10 +317,37 @@  static int clock_toggle_expanded(void)
  */
 static int clock_display(void)
 {
-	if (read_clock_info())
+	if (read_clock_info(clock_tree))
 		return -1;
 
-	return clock_print_info();
+	return clock_print_info(clock_tree);
+}
+
+int clock_find(const char *name)
+{
+	struct tree **ptree = NULL;
+	int i, nr, line = 0, ret = 0;
+
+	nr = tree_finds(clock_tree, name, &ptree);
+
+	display_reset_cursor(CLOCK);
+
+	for (i = 0; i < nr; i++) {
+
+		ret = read_clock_info(ptree[i]);
+		if (ret)
+			break;
+
+		ret = _clock_print_info_cb(ptree[i], &line);
+		if (ret)
+			break;
+	}
+
+	display_refresh_pad(CLOCK);
+
+	free(ptree);
+
+	return ret;
 }
 
 /*
@@ -350,7 +360,7 @@  int clock_dump(char *clk)
 {
 	int ret;
 
-	if (read_clock_info())
+	if (read_clock_info(clock_tree))
 		return -1;
 
 	if (clk) {
@@ -370,6 +380,7 @@  int clock_dump(char *clk)
 static struct display_ops clock_ops = {
 	.display = clock_display,
 	.select  = clock_toggle_expanded,
+	.find    = clock_find,
 };
 
 /*
diff --git a/display.c b/display.c
index 12eb052..1dc11dd 100644
--- a/display.c
+++ b/display.c
@@ -16,6 +16,7 @@ 
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <ctype.h>
 #include <ncurses.h>
 #include <sys/types.h>
 #include <regex.h>
@@ -424,7 +425,6 @@  static int display_find_keystroke(int fd, void *data)
 	regex_t *reg = findd->reg;
 	char *string = findd->string;
 	int keystroke = getch();
-
 	char match[2] = { [0] = (char)keystroke, [1] = '\0' };
 	regmatch_t m[1];
 
@@ -434,6 +434,14 @@  static int display_find_keystroke(int fd, void *data)
 		display_find_form_fini(findd);
 		return display_switch_to_main(fd);
 
+	case KEY_DOWN:
+		display_next_line();
+		break;
+
+	case KEY_UP:
+		display_prev_line();
+		break;
+
 	case KEY_BACKSPACE:
 		if (strlen(string))
 			string[strlen(string) - 1] = '\0';
@@ -455,10 +463,13 @@  static int display_find_keystroke(int fd, void *data)
 		break;
 	}
 
-	if (display_show_header(current_win))
+	if (!windata[current_win].ops || !windata[current_win].ops->find)
+		return 0;
+
+	if (windata[current_win].ops->find(string))
 		return -1;
 
-	if (display_refresh(current_win))
+	if (display_show_header(current_win))
 		return -1;
 
 	if (display_show_footer(current_win, strlen(string) ? string :
diff --git a/display.h b/display.h
index f9a762c..fe084cb 100644
--- a/display.h
+++ b/display.h
@@ -18,6 +18,7 @@  enum { CLOCK, REGULATOR, SENSOR };
 struct display_ops {
 	int (*display)(void);
 	int (*select)(void);
+	int (*find)(const char *);
 };
 
 extern int display_print_line(int window, int line, char *str,