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.lezc...@free.fr>
---
 powerdebug.c |   45 ++++++++++++++++++++++++---------------------
 1 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/powerdebug.c b/powerdebug.c
index c7f9574..86f51bc 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;
 }
-- 
1.7.1


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to