From patchwork Thu Jun 16 20:29:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1992 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 C35C323F3F for ; Thu, 16 Jun 2011 20:31:46 +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 92980A18585 for ; Thu, 16 Jun 2011 20:31:46 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 12so2092663vxk.11 for ; Thu, 16 Jun 2011 13:31:46 -0700 (PDT) Received: by 10.52.100.72 with SMTP id ew8mr1840899vdb.247.1308256306363; Thu, 16 Jun 2011 13:31:46 -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 em2cs211205vdc; Thu, 16 Jun 2011 13:31:45 -0700 (PDT) Received: by 10.216.81.69 with SMTP id l47mr1332344wee.78.1308256303073; Thu, 16 Jun 2011 13:31:43 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp08.smtpout.orange.fr [80.12.242.130]) by mx.google.com with ESMTP id e62si5076389wes.33.2011.06.16.13.31.42; Thu, 16 Jun 2011 13:31:43 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.130 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.130; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.130 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.76.78]) by mwinf5d16 with ME id wkXf1g0031hMfSL03kXiJV; Thu, 16 Jun 2011 22:31:42 +0200 From: Daniel Lezcano To: patches@linaro.org Subject: [PATCH 07/28] reorganize code to prevent forward declaration Date: Thu, 16 Jun 2011 22:29:36 +0200 Message-Id: <1308256197-29155-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> References: <1308256197-29155-1-git-send-email-daniel.lezcano@linaro.org> That will cleanup the powerdebug header because these functions are used in the clock code only. Signed-off-by: Daniel Lezcano --- clocks.c | 142 +++++++++++++++++++++++++++++----------------------------- powerdebug.h | 4 -- 2 files changed, 71 insertions(+), 75 deletions(-) diff --git a/clocks.c b/clocks.c index 4d8a2be..677db01 100644 --- a/clocks.c +++ b/clocks.c @@ -372,63 +372,28 @@ void print_clock_info(int verbose, int hrow, int selected) clock_line_no = 0; } -void read_and_dump_clock_info_one(char *clk, bool dump) -{ - printf("\nParents for \"%s\" Clock :\n\n", clk); - read_clock_info(clk_dir_path); - dump_all_parents(clk, dump); - printf("\n\n"); -} - -void read_and_dump_clock_info(int verbose) -{ - (void)verbose; - printf("\nClock Tree :\n"); - printf("**********\n"); - read_clock_info(clk_dir_path); - dump_clock_info(clocks_info, 1, 1); - printf("\n\n"); -} - -void read_clock_info(char *clkpath) +static void insert_children(struct clock_info **parent, struct clock_info *clk) { - DIR *dir; - struct dirent *item; - char filename[NAME_MAX], clockname[NAME_MAX]; - struct clock_info *child; - struct clock_info *cur; - - dir = opendir(clkpath); - if (!dir) - return; - - clocks_info = (struct clock_info *)malloc(sizeof(struct clock_info)); - memset(clocks_info, 0, sizeof(clocks_info)); - strcpy(clocks_info->name, "/"); - clocks_info->level = 0; - - while ((item = readdir(dir))) { - /* skip hidden dirs except ".." */ - if (item->d_name[0] == '.') - continue; - - strcpy(clockname, item->d_name); - sprintf(filename, "%s/%s", clkpath, item->d_name); - cur = (struct clock_info *)malloc(sizeof(struct clock_info)); - memset(cur, 0, sizeof(struct clock_info)); - strcpy(cur->name, clockname); - cur->parent = clocks_info; - cur->num_children = 0; - cur->expanded = 0; - cur->level = 1; - insert_children(&clocks_info, cur); - child = read_clock_info_recur(filename, 2, cur); - } - closedir(dir); + if (!(*parent)->num_children || (*parent)->children == NULL) { + (*parent)->children = (struct clock_info **) + malloc(sizeof(struct clock_info *)*2); + (*parent)->num_children = 0; + } else + (*parent)->children = (struct clock_info **) + realloc((*parent)->children, + sizeof(struct clock_info *) * + ((*parent)->num_children + 2)); + if ((*parent)->num_children > 0) + (*parent)->children[(*parent)->num_children - 1]->last_child + = 0; + clk->last_child = 1; + (*parent)->children[(*parent)->num_children] = clk; + (*parent)->children[(*parent)->num_children + 1] = NULL; + (*parent)->num_children++; } -struct clock_info *read_clock_info_recur(char *clkpath, int level, - struct clock_info *parent) +static struct clock_info *read_clock_info_recur(char *clkpath, int level, + struct clock_info *parent) { int ret = 0; DIR *dir; @@ -486,24 +451,49 @@ struct clock_info *read_clock_info_recur(char *clkpath, int level, return cur; } -void insert_children(struct clock_info **parent, struct clock_info *clk) +void read_clock_info(char *clkpath) { - if (!(*parent)->num_children || (*parent)->children == NULL) { - (*parent)->children = (struct clock_info **) - malloc(sizeof(struct clock_info *)*2); - (*parent)->num_children = 0; - } else - (*parent)->children = (struct clock_info **) - realloc((*parent)->children, - sizeof(struct clock_info *) * - ((*parent)->num_children + 2)); - if ((*parent)->num_children > 0) - (*parent)->children[(*parent)->num_children - 1]->last_child - = 0; - clk->last_child = 1; - (*parent)->children[(*parent)->num_children] = clk; - (*parent)->children[(*parent)->num_children + 1] = NULL; - (*parent)->num_children++; + DIR *dir; + struct dirent *item; + char filename[NAME_MAX], clockname[NAME_MAX]; + struct clock_info *child; + struct clock_info *cur; + + dir = opendir(clkpath); + if (!dir) + return; + + clocks_info = (struct clock_info *)malloc(sizeof(struct clock_info)); + memset(clocks_info, 0, sizeof(clocks_info)); + strcpy(clocks_info->name, "/"); + clocks_info->level = 0; + + while ((item = readdir(dir))) { + /* skip hidden dirs except ".." */ + if (item->d_name[0] == '.') + continue; + + strcpy(clockname, item->d_name); + sprintf(filename, "%s/%s", clkpath, item->d_name); + cur = (struct clock_info *)malloc(sizeof(struct clock_info)); + memset(cur, 0, sizeof(struct clock_info)); + strcpy(cur->name, clockname); + cur->parent = clocks_info; + cur->num_children = 0; + cur->expanded = 0; + cur->level = 1; + insert_children(&clocks_info, cur); + child = read_clock_info_recur(filename, 2, cur); + } + closedir(dir); +} + +void read_and_dump_clock_info_one(char *clk, bool dump) +{ + printf("\nParents for \"%s\" Clock :\n\n", clk); + read_clock_info(clk_dir_path); + dump_all_parents(clk, dump); + printf("\n\n"); } void dump_clock_info(struct clock_info *clk, int level, int bmp) @@ -560,3 +550,13 @@ void dump_clock_info(struct clock_info *clk, int level, int bmp) } } } + +void read_and_dump_clock_info(int verbose) +{ + (void)verbose; + printf("\nClock Tree :\n"); + printf("**********\n"); + read_clock_info(clk_dir_path); + dump_clock_info(clocks_info, 1, 1); + printf("\n\n"); +} diff --git a/powerdebug.h b/powerdebug.h index a122b7f..1018998 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -31,10 +31,6 @@ enum {CLOCK_SELECTED = 1, REFRESH_WINDOW}; extern void read_and_dump_clock_info(int verbose); extern void read_and_dump_clock_info_one(char *clk, bool dump); extern void read_clock_info(char *clkpath); -extern struct clock_info *read_clock_info_recur(char *clkpath, int level, - struct clock_info *parent); -extern void dump_clock_info(struct clock_info *clk, int level, int bmp); -extern void insert_children(struct clock_info **parent, struct clock_info *clk); extern void find_parents_for_clock(char *clkname, int complete); extern int read_and_print_clock_info(int verbose, int hrow, int selected); extern void print_clock_info(int verbose, int hrow, int selected);