option-parser: Make bools boolean

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>
dev
Daniel Stone 5 years ago committed by Daniel Stone
parent b8c3926445
commit dd8219b3fb
  1. 4
      clients/confine.c
  2. 6
      clients/editor.c
  3. 18
      clients/eventdemo.c
  4. 2
      clients/nested.c
  5. 4
      clients/subsurfaces.c
  6. 4
      clients/terminal.c
  7. 85
      compositor/main.c
  8. 4
      shared/option-parser.c
  9. 10
      tools/zunitc/src/zunitc_impl.c

@ -45,8 +45,8 @@
#define NUM_COMPLEX_REGION_RECTS 9 #define NUM_COMPLEX_REGION_RECTS 9
static int32_t option_complex_confine_region; static bool option_complex_confine_region;
static int32_t option_help; static bool option_help;
struct confine { struct confine {
struct display *display; struct display *display;

@ -77,7 +77,7 @@ struct text_entry {
uint32_t serial; uint32_t serial;
uint32_t reset_serial; uint32_t reset_serial;
uint32_t content_purpose; uint32_t content_purpose;
uint32_t click_to_show; bool click_to_show;
char *preferred_language; char *preferred_language;
bool button_pressed; bool button_pressed;
}; };
@ -1504,10 +1504,10 @@ global_handler(struct display *display, uint32_t name,
} }
/** Display help for command line options, and exit */ /** 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) */ /** 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. */ /** Set a specific (RFC-3066) language. Used for the virtual keyboard, etc. */
static const char *opt_preferred_language = NULL; static const char *opt_preferred_language = NULL;

@ -55,7 +55,7 @@ static int width = 500;
static int height = 400; static int height = 400;
/** set if window has no borders */ /** set if window has no borders */
static int noborder = 0; static bool noborder = false;
/** if non-zero, maximum window width */ /** if non-zero, maximum window width */
static int width_max = 0; static int width_max = 0;
@ -64,25 +64,25 @@ static int width_max = 0;
static int height_max = 0; static int height_max = 0;
/** set to log redrawing */ /** set to log redrawing */
static int log_redraw = 0; static bool log_redraw = false;
/** set to log resizing */ /** set to log resizing */
static int log_resize = 0; static bool log_resize = false;
/** set to log keyboard focus */ /** set to log keyboard focus */
static int log_focus = 0; static bool log_focus = false;
/** set to log key events */ /** set to log key events */
static int log_key = 0; static bool log_key = false;
/** set to log button events */ /** set to log button events */
static int log_button = 0; static bool log_button = false;
/** set to log axis events */ /** set to log axis events */
static int log_axis = 0; static bool log_axis = false;
/** set to log motion events */ /** set to log motion events */
static int log_motion = 0; static bool log_motion = false;
/** /**
* \struct eventdemo * \struct eventdemo
@ -513,7 +513,7 @@ main(int argc, char *argv[])
if (!log_redraw && !log_resize && !log_focus && !log_key && if (!log_redraw && !log_resize && !log_focus && !log_key &&
!log_button && !log_axis && !log_motion) !log_button && !log_axis && !log_motion)
log_redraw = log_resize = log_focus = log_key = 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 */ /* Connect to the display and have the arguments parsed */
d = display_create(&argc, argv); d = display_create(&argc, argv);

@ -54,7 +54,7 @@
#include "shared/weston-egl-ext.h" #include "shared/weston-egl-ext.h"
static int option_blit; static bool option_blit;
struct nested { struct nested {
struct display *display; struct display *display;

@ -56,8 +56,8 @@
static int32_t option_red_mode; static int32_t option_red_mode;
static int32_t option_triangle_mode; static int32_t option_triangle_mode;
static int32_t option_no_triangle; static bool option_no_triangle;
static int32_t option_help; static bool option_help;
static const struct weston_option options[] = { static const struct weston_option options[] = {
{ WESTON_OPTION_INTEGER, "red-mode", 'r', &option_red_mode }, { WESTON_OPTION_INTEGER, "red-mode", 'r', &option_red_mode },

@ -50,8 +50,8 @@
#include "shared/xalloc.h" #include "shared/xalloc.h"
#include "window.h" #include "window.h"
static int option_fullscreen; static bool option_fullscreen;
static int option_maximize; static bool option_maximize;
static char *option_font; static char *option_font;
static int option_font_size; static int option_font_size;
static char *option_term; static char *option_term;

@ -945,7 +945,7 @@ wet_get_bindir_path(const char *name)
static int static int
load_modules(struct weston_compositor *ec, const char *modules, 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; const char *p, *end;
char buffer[256]; char buffer[256];
@ -963,7 +963,7 @@ load_modules(struct weston_compositor *ec, const char *modules,
"Please use --xwayland command line option " "Please use --xwayland command line option "
"or set xwayland=true in the [core] section " "or set xwayland=true in the [core] section "
"in weston.ini\n"); "in weston.ini\n");
*xwayland = 1; *xwayland = true;
} else { } else {
if (wet_load_module(ec, buffer, argc, argv) < 0) if (wet_load_module(ec, buffer, argc, argv) < 0)
return -1; return -1;
@ -2480,30 +2480,23 @@ load_drm_backend(struct weston_compositor *c,
struct weston_drm_backend_config config = {{ 0, }}; struct weston_drm_backend_config config = {{ 0, }};
struct weston_config_section *section; struct weston_config_section *section;
struct wet_compositor *wet = to_wet_compositor(c); struct wet_compositor *wet = to_wet_compositor(c);
bool use_shadow;
int ret = 0; int ret = 0;
bool use_pixman_config_;
int drm_use_current_mode = 0;
int32_t use_pixman_;
wet->drm_use_current_mode = false; wet->drm_use_current_mode = false;
section = weston_config_get_section(wc, "core", NULL, 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); false);
use_pixman_ = use_pixman_config_;
const struct weston_option options[] = { const struct weston_option options[] = {
{ WESTON_OPTION_STRING, "seat", 0, &config.seat_id }, { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
{ WESTON_OPTION_INTEGER, "tty", 0, &config.tty }, { WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
{ WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device }, { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
{ WESTON_OPTION_BOOLEAN, "current-mode", 0, &drm_use_current_mode }, { WESTON_OPTION_BOOLEAN, "current-mode", 0, &wet->drm_use_current_mode },
{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman_ }, { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
}; };
parse_options(options, ARRAY_LENGTH(options), argc, argv); 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); section = weston_config_get_section(wc, "core", NULL, NULL);
weston_config_section_get_string(section, weston_config_section_get_string(section,
@ -2511,8 +2504,8 @@ load_drm_backend(struct weston_compositor *c,
NULL); NULL);
weston_config_section_get_uint(section, "pageflip-timeout", weston_config_section_get_uint(section, "pageflip-timeout",
&config.pageflip_timeout, 0); &config.pageflip_timeout, 0);
weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, true); weston_config_section_get_bool(section, "pixman-shadow",
config.use_pixman_shadow = use_shadow; &config.use_pixman_shadow, true);
config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION; config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
config.base.struct_size = sizeof(struct weston_drm_backend_config); 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; const struct weston_windowed_output_api *api;
struct weston_headless_backend_config config = {{ 0, }}; struct weston_headless_backend_config config = {{ 0, }};
struct weston_config_section *section; struct weston_config_section *section;
int no_outputs = 0; bool no_outputs;
int ret = 0; int ret = 0;
char *transform = NULL; 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); struct wet_output_config *parsed_options = wet_init_parsed_options(c);
if (!parsed_options) if (!parsed_options)
return -1; return -1;
section = weston_config_get_section(wc, "core", NULL, 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); false);
use_pixman_ = use_pixman_config_; weston_config_section_get_bool(section, "use-gl", &config.use_gl,
weston_config_section_get_bool(section, "use-gl", &use_gl_config_,
false); false);
use_gl_ = use_gl_config_;
const struct weston_option options[] = { const struct weston_option options[] = {
{ WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width }, { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
{ WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height }, { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman_ }, { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
{ WESTON_OPTION_BOOLEAN, "use-gl", 0, &use_gl_ }, { WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
{ WESTON_OPTION_STRING, "transform", 0, &transform }, { WESTON_OPTION_STRING, "transform", 0, &transform },
{ WESTON_OPTION_BOOLEAN, "no-outputs", 0, &no_outputs }, { WESTON_OPTION_BOOLEAN, "no-outputs", 0, &no_outputs },
}; };
parse_options(options, ARRAY_LENGTH(options), argc, argv); parse_options(options, ARRAY_LENGTH(options), argc, argv);
config.use_pixman = use_pixman_;
config.use_gl = use_gl_;
if (transform) { if (transform) {
if (weston_parse_transform(transform, &parsed_options->transform) < 0) { if (weston_parse_transform(transform, &parsed_options->transform) < 0) {
@ -2785,34 +2770,26 @@ load_x11_backend(struct weston_compositor *c,
int output_count = 0; int output_count = 0;
char const *section_name; char const *section_name;
int i; 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); struct wet_output_config *parsed_options = wet_init_parsed_options(c);
if (!parsed_options) if (!parsed_options)
return -1; return -1;
section = weston_config_get_section(wc, "core", NULL, 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); false);
use_pixman_ = use_pixman_config_;
const struct weston_option options[] = { const struct weston_option options[] = {
{ WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width }, { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
{ WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height }, { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
{ WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale }, { 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_INTEGER, "output-count", 0, &option_count },
{ WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input }, { WESTON_OPTION_BOOLEAN, "no-input", 0, &config.no_input },
{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman_ }, { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
}; };
parse_options(options, ARRAY_LENGTH(options), argc, argv); 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_version = WESTON_X11_BACKEND_CONFIG_VERSION;
config.base.struct_size = sizeof(struct weston_x11_backend_config); 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 count = 1;
int ret = 0; int ret = 0;
int i; 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); struct wet_output_config *parsed_options = wet_init_parsed_options(c);
if (!parsed_options) if (!parsed_options)
@ -2915,25 +2888,21 @@ load_wayland_backend(struct weston_compositor *c,
config.display_name = NULL; config.display_name = NULL;
section = weston_config_get_section(wc, "core", NULL, 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); false);
use_pixman_ = use_pixman_config_;
const struct weston_option wayland_options[] = { const struct weston_option wayland_options[] = {
{ WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width }, { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
{ WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height }, { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
{ WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale }, { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
{ WESTON_OPTION_STRING, "display", 0, &config.display_name }, { 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_INTEGER, "output-count", 0, &count },
{ WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fullscreen_ }, { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &config.fullscreen },
{ WESTON_OPTION_BOOLEAN, "sprawl", 0, &sprawl_ }, { WESTON_OPTION_BOOLEAN, "sprawl", 0, &config.sprawl },
}; };
parse_options(wayland_options, ARRAY_LENGTH(wayland_options), argc, argv); 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); section = weston_config_get_section(wc, "shell", NULL, NULL);
weston_config_section_get_string(section, "cursor-theme", weston_config_section_get_string(section, "cursor-theme",
@ -3119,8 +3088,7 @@ wet_main(int argc, char *argv[])
int i, fd; int i, fd;
char *backend = NULL; char *backend = NULL;
char *shell = NULL; char *shell = NULL;
int32_t xwayland = 0; bool xwayland = false;
bool xwayland_config_;
char *modules = NULL; char *modules = NULL;
char *option_modules = NULL; char *option_modules = NULL;
char *log = NULL; char *log = NULL;
@ -3146,8 +3114,7 @@ wet_main(int argc, char *argv[])
struct weston_log_subscriber *flight_rec = NULL; struct weston_log_subscriber *flight_rec = NULL;
sigset_t mask; sigset_t mask;
int32_t wait_for_debugger = 0; bool wait_for_debugger = false;
bool wait_for_debugger_config_;
struct wl_protocol_logger *protologger = NULL; struct wl_protocol_logger *protologger = NULL;
const struct weston_option core_options[] = { const struct weston_option core_options[] = {
@ -3257,8 +3224,7 @@ wet_main(int argc, char *argv[])
if (!wait_for_debugger) { if (!wait_for_debugger) {
weston_config_section_get_bool(section, "wait-for-debugger", weston_config_section_get_bool(section, "wait-for-debugger",
&wait_for_debugger_config_, false); &wait_for_debugger, false);
wait_for_debugger = wait_for_debugger_config_;
} }
if (wait_for_debugger) { if (wait_for_debugger) {
weston_log("Weston PID is %ld - " weston_log("Weston PID is %ld - "
@ -3362,9 +3328,8 @@ wet_main(int argc, char *argv[])
goto out; goto out;
if (!xwayland) { if (!xwayland) {
weston_config_section_get_bool(section, "xwayland", weston_config_section_get_bool(section, "xwayland", &xwayland,
&xwayland_config_, false); false);
xwayland = xwayland_config_;
} }
if (xwayland) { if (xwayland) {
if (wet_load_xwayland(wet.compositor) < 0) if (wet_load_xwayland(wet.compositor) < 0)

@ -76,7 +76,7 @@ long_option(const struct weston_option *options, int count, char *arg)
if (options[k].type == WESTON_OPTION_BOOLEAN) { if (options[k].type == WESTON_OPTION_BOOLEAN) {
if (!arg[len + 2]) { if (!arg[len + 2]) {
* (int32_t *) options[k].data = 1; * (bool *) options[k].data = true;
return 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 (options[k].type == WESTON_OPTION_BOOLEAN) {
if (!arg[2]) { if (!arg[2]) {
* (int32_t *) options[k].data = 1; * (bool *) options[k].data = true;
return true; return true;
} }

@ -524,13 +524,13 @@ int
zuc_initialize(int *argc, char *argv[], bool *help_flagged) zuc_initialize(int *argc, char *argv[], bool *help_flagged)
{ {
int rc = EXIT_FAILURE; int rc = EXIT_FAILURE;
int opt_help = 0; bool opt_help = false;
int opt_nofork = 0; bool opt_nofork = false;
int opt_list = 0; bool opt_list = false;
int opt_repeat = 0; int opt_repeat = 0;
int opt_random = 0; int opt_random = 0;
int opt_break_on_failure = 0; bool opt_break_on_failure = false;
int opt_junit = 0; bool opt_junit = false;
char *opt_filter = NULL; char *opt_filter = NULL;
char *help_param = NULL; char *help_param = NULL;

Loading…
Cancel
Save