option-parser: Make bools boolean
authorDaniel Stone <daniels@collabora.com>
Tue, 26 Nov 2019 00:32:22 +0000 (00:32 +0000)
committerDaniel Stone <daniel@fooishbar.org>
Thu, 28 Nov 2019 19:24:13 +0000 (19:24 +0000)
When option-parser is confronted with a boolean option, have it write a
bool rather than treating the value as a pointer to an int32.

(lib)weston already heavily uses bool types internally, so this has the
nice side effect of eliminating quite a few local variables which only
existed as integer shadows of internal boolean variables.

Signed-off-by: Daniel Stone <daniels@collabora.com>
clients/confine.c
clients/editor.c
clients/eventdemo.c
clients/nested.c
clients/subsurfaces.c
clients/terminal.c
compositor/main.c
shared/option-parser.c
tools/zunitc/src/zunitc_impl.c

index 01caae07b5a295f33b7792fa388f529c801faa67..6f3845712c49469a991618b1806518cfd23e57bf 100644 (file)
@@ -45,8 +45,8 @@
 
 #define NUM_COMPLEX_REGION_RECTS 9
 
-static int32_t option_complex_confine_region;
-static int32_t option_help;
+static bool option_complex_confine_region;
+static bool option_help;
 
 struct confine {
        struct display *display;
index c3d9491d6d436cd4b4d36e3addd8c0f919b83743..a59f9679a682715b93495c9b181bd17e67027d69 100644 (file)
@@ -77,7 +77,7 @@ struct text_entry {
        uint32_t serial;
        uint32_t reset_serial;
        uint32_t content_purpose;
-       uint32_t click_to_show;
+       bool click_to_show;
        char *preferred_language;
        bool button_pressed;
 };
@@ -1504,10 +1504,10 @@ global_handler(struct display *display, uint32_t name,
 }
 
 /** Display help for command line options, and exit */
-static uint32_t opt_help = 0;
+static bool opt_help = false;
 
 /** Require a distinct click to show the input panel (virtual keyboard) */
-static uint32_t opt_click_to_show = 0;
+static bool opt_click_to_show = false;
 
 /** Set a specific (RFC-3066) language.  Used for the virtual keyboard, etc. */
 static const char *opt_preferred_language = NULL;
index 9193bf1bc47181f81e8b6bca1e8a089f0b54cb4c..0a1a7ca91f7587087d56557092686c712243a527 100644 (file)
@@ -55,7 +55,7 @@ static int width = 500;
 static int height = 400;
 
 /** set if window has no borders */
-static int noborder = 0;
+static bool noborder = false;
 
 /** if non-zero, maximum window width */
 static int width_max = 0;
@@ -64,25 +64,25 @@ static int width_max = 0;
 static int height_max = 0;
 
 /** set to log redrawing */
-static int log_redraw = 0;
+static bool log_redraw = false;
 
 /** set to log resizing */
-static int log_resize = 0;
+static bool log_resize = false;
 
 /** set to log keyboard focus */
-static int log_focus = 0;
+static bool log_focus = false;
 
 /** set to log key events */
-static int log_key = 0;
+static bool log_key = false;
 
 /** set to log button events */
-static int log_button = 0;
+static bool log_button = false;
 
 /** set to log axis events */
-static int log_axis = 0;
+static bool log_axis = false;
 
 /** set to log motion events */
-static int log_motion = 0;
+static bool log_motion = false;
 
 /**
  * \struct eventdemo
@@ -513,7 +513,7 @@ main(int argc, char *argv[])
        if (!log_redraw && !log_resize && !log_focus && !log_key &&
            !log_button && !log_axis && !log_motion)
          log_redraw = log_resize = log_focus = log_key =
-           log_button = log_axis = log_motion = 1;
+           log_button = log_axis = log_motion = true;
 
        /* Connect to the display and have the arguments parsed */
        d = display_create(&argc, argv);
index 2ec80ceb2edcc74f77ef9faa5dad9bedcf26c44a..4bbaa27ea21fc7a1d96936e582f028e39f36eeba 100644 (file)
@@ -54,7 +54,7 @@
 #include "shared/weston-egl-ext.h"
 
 
-static int option_blit;
+static bool option_blit;
 
 struct nested {
        struct display *display;
index 79f7ade90dd9575ecbcddfab83adebd3aa6610ad..df4372f0db082e563a3ca23e93e76ed533d2b729 100644 (file)
@@ -56,8 +56,8 @@
 
 static int32_t option_red_mode;
 static int32_t option_triangle_mode;
-static int32_t option_no_triangle;
-static int32_t option_help;
+static bool option_no_triangle;
+static bool option_help;
 
 static const struct weston_option options[] = {
        { WESTON_OPTION_INTEGER, "red-mode", 'r', &option_red_mode },
index ec767641e4215301f4d9bb7bc9b77e9d2137f8f9..66e2bf549e0f53537886745dc8557c91fc65536a 100644 (file)
@@ -50,8 +50,8 @@
 #include "shared/xalloc.h"
 #include "window.h"
 
-static int option_fullscreen;
-static int option_maximize;
+static bool option_fullscreen;
+static bool option_maximize;
 static char *option_font;
 static int option_font_size;
 static char *option_term;
index 24edb6c0b5d8f979dbe4c5eafb34bf7ed6558b98..8eb8a470e243e2687818c993630677c9c988df05 100644 (file)
@@ -945,7 +945,7 @@ wet_get_bindir_path(const char *name)
 
 static int
 load_modules(struct weston_compositor *ec, const char *modules,
-            int *argc, char *argv[], int32_t *xwayland)
+            int *argc, char *argv[], bool *xwayland)
 {
        const char *p, *end;
        char buffer[256];
@@ -963,7 +963,7 @@ load_modules(struct weston_compositor *ec, const char *modules,
                                   "Please use --xwayland command line option "
                                   "or set xwayland=true in the [core] section "
                                   "in weston.ini\n");
-                       *xwayland = 1;
+                       *xwayland = true;
                } else {
                        if (wet_load_module(ec, buffer, argc, argv) < 0)
                                return -1;
@@ -2480,30 +2480,23 @@ load_drm_backend(struct weston_compositor *c,
        struct weston_drm_backend_config config = {{ 0, }};
        struct weston_config_section *section;
        struct wet_compositor *wet = to_wet_compositor(c);
-       bool use_shadow;
        int ret = 0;
-       bool use_pixman_config_;
-       int drm_use_current_mode = 0;
-       int32_t use_pixman_;
 
        wet->drm_use_current_mode = false;
 
        section = weston_config_get_section(wc, "core", NULL, NULL);
-       weston_config_section_get_bool(section, "use-pixman", &use_pixman_config_,
+       weston_config_section_get_bool(section, "use-pixman", &config.use_pixman,
                                       false);
-       use_pixman_ = use_pixman_config_;
 
        const struct weston_option options[] = {
                { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
                { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
                { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
-               { WESTON_OPTION_BOOLEAN, "current-mode", 0, &drm_use_current_mode },
-               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman_ },
+               { WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
+               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
        };
 
        parse_options(options, ARRAY_LENGTH(options), argc, argv);
-       wet->drm_use_current_mode = drm_use_current_mode;
-       config.use_pixman = use_pixman_;
 
        section = weston_config_get_section(wc, "core", NULL, NULL);
        weston_config_section_get_string(section,
@@ -2511,8 +2504,8 @@ load_drm_backend(struct weston_compositor *c,
                                         NULL);
        weston_config_section_get_uint(section, "pageflip-timeout",
                                       &config.pageflip_timeout, 0);
-       weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, true);
-       config.use_pixman_shadow = use_shadow;
+       weston_config_section_get_bool(section, "pixman-shadow",
+                                      &config.use_pixman_shadow, true);
 
        config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
        config.base.struct_size = sizeof(struct weston_drm_backend_config);
@@ -2557,38 +2550,30 @@ load_headless_backend(struct weston_compositor *c,
        const struct weston_windowed_output_api *api;
        struct weston_headless_backend_config config = {{ 0, }};
        struct weston_config_section *section;
-       int no_outputs = 0;
+       bool no_outputs;
        int ret = 0;
        char *transform = NULL;
-       bool use_pixman_config_;
-       int use_pixman_;
-       bool use_gl_config_;
-       bool use_gl_;
 
        struct wet_output_config *parsed_options = wet_init_parsed_options(c);
        if (!parsed_options)
                return -1;
 
        section = weston_config_get_section(wc, "core", NULL, NULL);
-       weston_config_section_get_bool(section, "use-pixman", &use_pixman_config_,
+       weston_config_section_get_bool(section, "use-pixman", &config.use_pixman,
                                       false);
-       use_pixman_ = use_pixman_config_;
-       weston_config_section_get_bool(section, "use-gl", &use_gl_config_,
+       weston_config_section_get_bool(section, "use-gl", &config.use_gl,
                                       false);
-       use_gl_ = use_gl_config_;
 
        const struct weston_option options[] = {
                { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
                { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
-               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman_ },
-               { WESTON_OPTION_BOOLEAN, "use-gl", 0, &use_gl_ },
+               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
+               { WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
                { WESTON_OPTION_STRING, "transform", 0, &transform },
                { WESTON_OPTION_BOOLEAN, "no-outputs", 0, &no_outputs },
        };
 
        parse_options(options, ARRAY_LENGTH(options), argc, argv);
-       config.use_pixman = use_pixman_;
-       config.use_gl = use_gl_;
 
        if (transform) {
                if (weston_parse_transform(transform, &parsed_options->transform) < 0) {
@@ -2785,34 +2770,26 @@ load_x11_backend(struct weston_compositor *c,
        int output_count = 0;
        char const *section_name;
        int i;
-       bool use_pixman_config_;
-       int fullscreen = 0;
-       int no_input = 0;
-       int use_pixman_;
 
        struct wet_output_config *parsed_options = wet_init_parsed_options(c);
        if (!parsed_options)
                return -1;
 
        section = weston_config_get_section(wc, "core", NULL, NULL);
-       weston_config_section_get_bool(section, "use-pixman", &use_pixman_config_,
+       weston_config_section_get_bool(section, "use-pixman", &config.use_pixman,
                                       false);
-       use_pixman_ = use_pixman_config_;
 
        const struct weston_option options[] = {
               { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
               { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
               { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
-              { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &fullscreen },
+              { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &config.fullscreen },
               { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
-              { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
-              { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman_ },
+              { WESTON_OPTION_BOOLEAN, "no-input", 0, &config.no_input },
+              { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
        };
 
        parse_options(options, ARRAY_LENGTH(options), argc, argv);
-       config.fullscreen = fullscreen;
-       config.no_input = no_input;
-       config.use_pixman = use_pixman_;
 
        config.base.struct_version = WESTON_X11_BACKEND_CONFIG_VERSION;
        config.base.struct_size = sizeof(struct weston_x11_backend_config);
@@ -2901,10 +2878,6 @@ load_wayland_backend(struct weston_compositor *c,
        int count = 1;
        int ret = 0;
        int i;
-       int32_t use_pixman_;
-       int32_t sprawl_ = 0;
-       int32_t fullscreen_ = 0;
-       bool use_pixman_config_;
 
        struct wet_output_config *parsed_options = wet_init_parsed_options(c);
        if (!parsed_options)
@@ -2915,25 +2888,21 @@ load_wayland_backend(struct weston_compositor *c,
        config.display_name = NULL;
 
        section = weston_config_get_section(wc, "core", NULL, NULL);
-       weston_config_section_get_bool(section, "use-pixman", &use_pixman_config_,
+       weston_config_section_get_bool(section, "use-pixman", &config.use_pixman,
                                       false);
-       use_pixman_ = use_pixman_config_;
 
        const struct weston_option wayland_options[] = {
                { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
                { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
                { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
                { WESTON_OPTION_STRING, "display", 0, &config.display_name },
-               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman_ },
+               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
                { WESTON_OPTION_INTEGER, "output-count", 0, &count },
-               { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fullscreen_ },
-               { WESTON_OPTION_BOOLEAN, "sprawl", 0, &sprawl_ },
+               { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &config.fullscreen },
+               { WESTON_OPTION_BOOLEAN, "sprawl", 0, &config.sprawl },
        };
 
        parse_options(wayland_options, ARRAY_LENGTH(wayland_options), argc, argv);
-       config.sprawl = sprawl_;
-       config.fullscreen = fullscreen_;
-       config.use_pixman = use_pixman_;
 
        section = weston_config_get_section(wc, "shell", NULL, NULL);
        weston_config_section_get_string(section, "cursor-theme",
@@ -3119,8 +3088,7 @@ wet_main(int argc, char *argv[])
        int i, fd;
        char *backend = NULL;
        char *shell = NULL;
-       int32_t xwayland = 0;
-       bool xwayland_config_;
+       bool xwayland = false;
        char *modules = NULL;
        char *option_modules = NULL;
        char *log = NULL;
@@ -3146,8 +3114,7 @@ wet_main(int argc, char *argv[])
        struct weston_log_subscriber *flight_rec = NULL;
        sigset_t mask;
 
-       int32_t wait_for_debugger = 0;
-       bool wait_for_debugger_config_;
+       bool wait_for_debugger = false;
        struct wl_protocol_logger *protologger = NULL;
 
        const struct weston_option core_options[] = {
@@ -3257,8 +3224,7 @@ wet_main(int argc, char *argv[])
 
        if (!wait_for_debugger) {
                weston_config_section_get_bool(section, "wait-for-debugger",
-                                              &wait_for_debugger_config_, false);
-               wait_for_debugger = wait_for_debugger_config_;
+                                              &wait_for_debugger, false);
        }
        if (wait_for_debugger) {
                weston_log("Weston PID is %ld - "
@@ -3362,9 +3328,8 @@ wet_main(int argc, char *argv[])
                goto out;
 
        if (!xwayland) {
-               weston_config_section_get_bool(section, "xwayland",
-                                              &xwayland_config_, false);
-               xwayland = xwayland_config_;
+               weston_config_section_get_bool(section, "xwayland", &xwayland,
+                                              false);
        }
        if (xwayland) {
                if (wet_load_xwayland(wet.compositor) < 0)
index c1c7b9c8f12c6bd71c12ee8ab73bb39722c1c6b6..55be1b5f554e3861d13344e94c191e7bafb3ca22 100644 (file)
@@ -76,7 +76,7 @@ long_option(const struct weston_option *options, int count, char *arg)
 
                if (options[k].type == WESTON_OPTION_BOOLEAN) {
                        if (!arg[len + 2]) {
-                               * (int32_t *) options[k].data = 1;
+                               * (bool *) options[k].data = true;
 
                                return true;
                        }
@@ -127,7 +127,7 @@ short_option(const struct weston_option *options, int count, char *arg)
 
                if (options[k].type == WESTON_OPTION_BOOLEAN) {
                        if (!arg[2]) {
-                               * (int32_t *) options[k].data = 1;
+                               * (bool *) options[k].data = true;
 
                                return true;
                        }
index 05db02297367897a21799377b0019ae2442c9e72..395bdd748ee180c5446815e23504f7ead2609109 100644 (file)
@@ -524,13 +524,13 @@ int
 zuc_initialize(int *argc, char *argv[], bool *help_flagged)
 {
        int rc = EXIT_FAILURE;
-       int opt_help = 0;
-       int opt_nofork = 0;
-       int opt_list = 0;
+       bool opt_help = false;
+       bool opt_nofork = false;
+       bool opt_list = false;
        int opt_repeat = 0;
        int opt_random = 0;
-       int opt_break_on_failure = 0;
-       int opt_junit = 0;
+       bool opt_break_on_failure = false;
+       bool opt_junit = false;
        char *opt_filter = NULL;
 
        char *help_param = NULL;