Remove the selectedwindow options.

There is no logic behind the default window selection. The last
option parsed set the default window. Instead of having a specific
boolean set, use the first bit found in the flags for selecting the
the windows.

eg. powerdebug -s -g
	=> flags = SENSOR_OPTION | GPIO_OPTION;
	=> flags = 0x2 | 0x8 = 0x0a
	=> flags = b01010000
	=> fsl(flags) = 2
	=> default window = 1 << fsl(flags) - 1
	=> default window = 1 << 2 - 1
	=> default window = 1 << 1
	=> default window = 2 = SENSOR_OPTION

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
diff --git a/display.c b/display.c
index ed010b3..eada839 100644
--- a/display.c
+++ b/display.c
@@ -21,6 +21,9 @@
 
 #include <stdio.h>
 #include <string.h>
+#define _GNU_SOURCE
+#include <strings.h>
+#undef _GNU_SOURCE
 #include <stdlib.h>
 #include <ctype.h>
 #include <ncurses.h>
@@ -548,12 +551,12 @@
 	return 0;
 }
 
-int display_init(int wdefault)
+int display_init(struct powerdebug_options *options)
 {
 	int i, maxx, maxy;
 	size_t array_size = sizeof(windata) / sizeof(windata[0]);
 
-	current_win = wdefault;
+	current_win = 1 << (ffs(options->flags & DEFAULT_OPTION) - 1);
 
 	if (mainloop_add(0, display_keystroke, NULL))
 		return -1;
@@ -605,13 +608,13 @@
 	if (!footer_win)
 		return -1;
 
-	if (display_show_header(wdefault))
+	if (display_show_header(current_win))
 		return -1;
 
-	if (display_show_footer(wdefault, NULL))
+	if (display_show_footer(current_win, NULL))
 		return -1;
 
-	return display_refresh(wdefault, true);
+	return display_refresh(current_win, true);
 }
 
 int display_column_name(const char *line)
diff --git a/display.h b/display.h
index 8882918..d8f87bf 100644
--- a/display.h
+++ b/display.h
@@ -29,6 +29,8 @@
 	int (*change)(int keyvalue);
 };
 
+struct powerdebug_options;
+
 extern int display_print_line(int window, int line, char *str,
 			      int bold, void *data);
 extern void display_message(int window, char *buf);
@@ -37,7 +39,7 @@
 extern int display_reset_cursor(int window);
 extern void *display_get_row_data(int window);
 
-extern int display_init(int wdefault);
+extern int display_init(struct powerdebug_options *opt);
 extern int display_register(int win, struct display_ops *ops);
 extern int display_column_name(const char *line);
 
diff --git a/powerdebug.c b/powerdebug.c
index b626b05..b0d2ade 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -93,7 +93,6 @@
 
 	memset(options, 0, sizeof(*options));
 	options->ticktime = 10;
-	options->selectedwindow = -1;
 
 	while (1) {
 		int optindex = 0;
@@ -106,19 +105,15 @@
 		switch (c) {
 		case 'r':
 			options->flags |= REGULATOR_OPTION;
-			options->selectedwindow = REGULATOR;
 			break;
 		case 's':
 			options->flags |= SENSOR_OPTION;
-			options->selectedwindow = SENSOR;
 			break;
 		case 'c':
 			options->flags |= CLOCK_OPTION;
-			options->selectedwindow = CLOCK;
 			break;
 		case 'g':
 			options->flags |= GPIO_OPTION;
-			options->selectedwindow = GPIO;
 			break;
 		case 'd':
 			options->flags |= DUMP_OPTION;
@@ -152,9 +147,6 @@
 	if (!(options->flags & DEFAULT_OPTION))
 		options->flags |= DEFAULT_OPTION;
 
-	if (options->selectedwindow == -1)
-		options->selectedwindow = CLOCK;
-
 	return 0;
 }
 
@@ -177,7 +169,7 @@
 
 static int powerdebug_display(struct powerdebug_options *options)
 {
-	if (display_init(options->selectedwindow)) {
+	if (display_init(options)) {
 		printf("failed to initialize display\n");
 		return -1;
 	}
diff --git a/powerdebug.h b/powerdebug.h
index 2df0a27..3852ca8 100644
--- a/powerdebug.h
+++ b/powerdebug.h
@@ -35,7 +35,6 @@
 struct powerdebug_options {
 	int flags;
 	unsigned int ticktime;
-	int selectedwindow;
 	char *clkname;
 };