aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@free.fr>2011-03-26 22:06:21 +0100
committerAmit Kucheria <amit.kucheria@linaro.org>2011-04-04 03:24:50 +0300
commitc08f1f2d5f3ff9a2eaff82f740fedcd8302c6adc (patch)
tree95acf0f0042419c36cd93484bddde32c646f0753
parentef32319dfd87a7c1cc16d6598b90d8cc54242951 (diff)
downloadpowerdebug-c08f1f2d5f3ff9a2eaff82f740fedcd8302c6adc.tar.gz
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 <daniel.lezcano@free.fr> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
-rw-r--r--powerdebug.c45
1 files changed, 24 insertions, 21 deletions
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;
}