From: Daniel Lezcano <daniel.lezc...@free.fr> That has the benefit to simplify the code.
Signed-off-by: Daniel Lezcano <daniel.lezc...@linaro.org> --- powerdebug.c | 65 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/powerdebug.c b/powerdebug.c index 6cf3a1b..555beea 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -31,6 +31,17 @@ extern void sigwinch_handler(int); +#define REGULATOR_OPTION 0x01 +#define SENSOR_OPTION 0x02 +#define CLOCK_OPTION 0x04 +#define GPIO_OPTION 0x08 + +#define VERBOSE_OPTION 0x10 +#define DUMP_OPTION 0x20 + +#define DEFAULT_OPTION (REGULATOR_OPTION | SENSOR_OPTION | \ + CLOCK_OPTION | GPIO_OPTION) + void usage(void) { printf("Usage: powerdebug [OPTIONS]\n"); @@ -86,12 +97,7 @@ static struct option long_options[] = { }; struct powerdebug_options { - bool verbose; - bool regulators; - bool sensors; - bool clocks; - bool gpios; - bool dump; + int flags; unsigned int ticktime; int selectedwindow; char *clkname; @@ -115,39 +121,38 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options) switch (c) { case 'r': - options->regulators = true; + options->flags |= REGULATOR_OPTION; options->selectedwindow = REGULATOR; break; case 's': - options->sensors = true; + options->flags |= SENSOR_OPTION; options->selectedwindow = SENSOR; break; case 'c': - options->clocks = true; + options->flags |= CLOCK_OPTION; options->selectedwindow = CLOCK; break; case 'g': - options->gpios = true; + options->flags |= GPIO_OPTION; options->selectedwindow = GPIO; break; + case 'd': + options->flags |= DUMP_OPTION; + break; + case 'v': + options->flags |= VERBOSE_OPTION; + break; case 'p': options->clkname = strdup(optarg); if (!options->clkname) { fprintf(stderr, "failed to allocate memory"); return -1; } - options->dump = true; /* Assume -dc in case of -p */ - options->clocks = true; + options->flags |= (DUMP_OPTION | CLOCK_OPTION); break; case 't': options->ticktime = atoi(optarg); break; - case 'd': - options->dump = true; - break; - case 'v': - options->verbose = true; - break; case 'V': version(); break; @@ -160,10 +165,8 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options) } /* No system specified to be dump, let's default to all */ - if (!options->regulators && !options->clocks && - !options->sensors && !options->gpios) - options->regulators = options->clocks = - options->sensors = options->gpios = true; + if (!(options->flags & DEFAULT_OPTION)) + options->flags |= DEFAULT_OPTION; if (options->selectedwindow == -1) options->selectedwindow = CLOCK; @@ -173,16 +176,16 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options) static int powerdebug_dump(struct powerdebug_options *options) { - if (options->regulators) + if (options->flags & REGULATOR_OPTION) regulator_dump(); - if (options->clocks) + if (options->flags & CLOCK_OPTION) clock_dump(options->clkname); - if (options->sensors) + if (options->flags & SENSOR_OPTION) sensor_dump(); - if (options->gpios) + if (options->flags & GPIO_OPTION) gpio_dump(); return 0; @@ -248,25 +251,25 @@ int main(int argc, char **argv) if (regulator_init()) { printf("failed to initialize regulator\n"); - options->regulators = false; + options->flags &= ~REGULATOR_OPTION; } if (clock_init()) { printf("failed to initialize clock details (check debugfs)\n"); - options->clocks = false; + options->flags &= ~CLOCK_OPTION; } if (sensor_init()) { printf("failed to initialize sensors\n"); - options->sensors = false; + options->flags &= SENSOR_OPTION; } if (gpio_init()) { printf("failed to initialize gpios\n"); - options->gpios = false; + options->flags &= GPIO_OPTION; } - ret = options->dump ? powerdebug_dump(options) : + ret = options->flags & DUMP_OPTION ? powerdebug_dump(options) : powerdebug_display(options); return ret < 0; -- 1.9.1 _______________________________________________ linaro-dev mailing list linaro-dev@lists.linaro.org https://lists.linaro.org/mailman/listinfo/linaro-dev