From c08f1f2d5f3ff9a2eaff82f740fedcd8302c6adc Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Sat, 26 Mar 2011 22:06:21 +0100 Subject: create a specific function for display In order to have the code more clear, let's create a function for the display like what we did with the dump function. Signed-off-by: Daniel Lezcano Signed-off-by: Amit Kucheria --- powerdebug.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'powerdebug.c') diff --git a/powerdebug.c b/powerdebug.c index 9874f5a..230155b 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -330,6 +330,20 @@ static int powerdebug_dump(struct powerdebug_options *options, return 0; } +static int powerdebug_display(struct powerdebug_options *options, + struct regulator_info *reg_info, int nr_reg) +{ + if (display_init()) { + printf("failed to initialize display\n"); + return -1; + } + + if (mainloop(options, reg_info, nr_reg)) + return -1; + + return 0; +} + static struct powerdebug_options *powerdebug_init(void) { struct powerdebug_options *options; @@ -347,7 +361,7 @@ int main(int argc, char **argv) { struct powerdebug_options *options; struct regulator_info *regulators_info; - int numregulators; + int numregulators, ret; options = powerdebug_init(); if (!options) { @@ -355,14 +369,14 @@ int main(int argc, char **argv) return 1; } - regulators_info = regulator_init(&numregulators); - if (!regulators_info) { - printf("not enough memory to allocate regulators info\n"); + if (getoptions(argc, argv, options)) { + usage(); return 1; } - if (getoptions(argc, argv, options)) { - usage(); + regulators_info = regulator_init(&numregulators); + if (!regulators_info) { + printf("not enough memory to allocate regulators info\n"); return 1; } @@ -371,20 +385,9 @@ int main(int argc, char **argv) options->clocks = false; } - /* we just dump the informations */ - if (options->dump) { - if (powerdebug_dump(options, regulators_info, numregulators)) - return 1; - return 0; - } - - if (display_init()) { - printf("failed to initialize display\n"); - return 1; - } + ret = options->dump ? + powerdebug_dump(options, regulators_info, numregulators) : + powerdebug_display(options, regulators_info, numregulators); - if (mainloop(options, regulators_info, numregulators)) - return 1; - - return 0; + return ret < 0; } -- cgit v1.2.3