From patchwork Mon Jun 20 22:58:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2102 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id B7C4723E52 for ; Mon, 20 Jun 2011 22:59:00 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id 88DC2A1805E for ; Mon, 20 Jun 2011 22:59:00 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 7so2987210vxd.11 for ; Mon, 20 Jun 2011 15:59:00 -0700 (PDT) Received: by 10.52.100.72 with SMTP id ew8mr815001vdb.247.1308610740365; Mon, 20 Jun 2011 15:59:00 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs32817vdc; Mon, 20 Jun 2011 15:58:59 -0700 (PDT) Received: by 10.216.58.136 with SMTP id q8mr5224915wec.97.1308610737357; Mon, 20 Jun 2011 15:58:57 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr [80.12.242.125]) by mx.google.com with ESMTP id h62si13987094wed.98.2011.06.20.15.58.55; Mon, 20 Jun 2011 15:58:56 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.125 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.125; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.125 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.95.191]) by mwinf5d06 with ME id yNyp1g00347kPVY03NyvDF; Tue, 21 Jun 2011 00:58:55 +0200 From: Daniel Lezcano To: linaro-dev@lists.linaro.org Subject: [powerdebug 12/17] find a clock with a clock name Date: Tue, 21 Jun 2011 00:58:20 +0200 Message-Id: <1308610705-23281-12-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308610705-23281-1-git-send-email-daniel.lezcano@linaro.org> References: <1308610705-23281-1-git-send-email-daniel.lezcano@linaro.org> and add a 'find' ops. Signed-off-by: Daniel Lezcano --- clocks.c | 87 ++++++++++++++++++++++++++++++++++-------------------------- display.c | 17 ++++++++++-- display.h | 1 + 3 files changed, 64 insertions(+), 41 deletions(-) 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 #include #include +#include #include #include #include @@ -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,