option-parser: replace int/0/1 with bool/false/true

These are already used as bools by all callers, let's make that official.

Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Daniel Stone <daniels@collabora.com>
dev
Eric Engestrom 8 years ago committed by Daniel Stone
parent 58e056ab2d
commit 0c30fa5503
  1. 39
      shared/option-parser.c

@ -25,6 +25,7 @@
#include "config.h" #include "config.h"
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -35,7 +36,7 @@
#include "config-parser.h" #include "config-parser.h"
#include "string-helpers.h" #include "string-helpers.h"
static int static bool
handle_option(const struct weston_option *option, char *value) handle_option(const struct weston_option *option, char *value)
{ {
char* p; char* p;
@ -43,23 +44,23 @@ handle_option(const struct weston_option *option, char *value)
switch (option->type) { switch (option->type) {
case WESTON_OPTION_INTEGER: case WESTON_OPTION_INTEGER:
if (!safe_strtoint(value, option->data)) if (!safe_strtoint(value, option->data))
return 0; return false;
return 1; return true;
case WESTON_OPTION_UNSIGNED_INTEGER: case WESTON_OPTION_UNSIGNED_INTEGER:
errno = 0; errno = 0;
* (uint32_t *) option->data = strtoul(value, &p, 10); * (uint32_t *) option->data = strtoul(value, &p, 10);
if (errno != 0 || p == value || *p != '\0') if (errno != 0 || p == value || *p != '\0')
return 0; return false;
return 1; return true;
case WESTON_OPTION_STRING: case WESTON_OPTION_STRING:
* (char **) option->data = strdup(value); * (char **) option->data = strdup(value);
return 1; return true;
default: default:
assert(0); assert(0);
} }
} }
static int static bool
long_option(const struct weston_option *options, int count, char *arg) long_option(const struct weston_option *options, int count, char *arg)
{ {
int k, len; int k, len;
@ -76,17 +77,17 @@ long_option(const struct weston_option *options, int count, char *arg)
if (!arg[len + 2]) { if (!arg[len + 2]) {
* (int32_t *) options[k].data = 1; * (int32_t *) options[k].data = 1;
return 1; return true;
} }
} else if (arg[len+2] == '=') { } else if (arg[len+2] == '=') {
return handle_option(options + k, arg + len + 3); return handle_option(options + k, arg + len + 3);
} }
} }
return 0; return false;
} }
static int static bool
long_option_with_arg(const struct weston_option *options, int count, char *arg, long_option_with_arg(const struct weston_option *options, int count, char *arg,
char *param) char *param)
{ {
@ -108,16 +109,16 @@ long_option_with_arg(const struct weston_option *options, int count, char *arg,
return handle_option(options + k, param); return handle_option(options + k, param);
} }
return 0; return false;
} }
static int static bool
short_option(const struct weston_option *options, int count, char *arg) short_option(const struct weston_option *options, int count, char *arg)
{ {
int k; int k;
if (!arg[1]) if (!arg[1])
return 0; return false;
for (k = 0; k < count; k++) { for (k = 0; k < count; k++) {
if (options[k].short_name != arg[1]) if (options[k].short_name != arg[1])
@ -127,25 +128,25 @@ short_option(const struct weston_option *options, int count, char *arg)
if (!arg[2]) { if (!arg[2]) {
* (int32_t *) options[k].data = 1; * (int32_t *) options[k].data = 1;
return 1; return true;
} }
} else if (arg[2]) { } else if (arg[2]) {
return handle_option(options + k, arg + 2); return handle_option(options + k, arg + 2);
} else { } else {
return 0; return false;
} }
} }
return 0; return false;
} }
static int static bool
short_option_with_arg(const struct weston_option *options, int count, char *arg, char *param) short_option_with_arg(const struct weston_option *options, int count, char *arg, char *param)
{ {
int k; int k;
if (!arg[1]) if (!arg[1])
return 0; return false;
for (k = 0; k < count; k++) { for (k = 0; k < count; k++) {
if (options[k].short_name != arg[1]) if (options[k].short_name != arg[1])
@ -157,7 +158,7 @@ short_option_with_arg(const struct weston_option *options, int count, char *arg,
return handle_option(options + k, param); return handle_option(options + k, param);
} }
return 0; return false;
} }
int int

Loading…
Cancel
Save