summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosé Expósito <jose.exposito89@gmail.com>2021-09-12 17:09:20 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2021-09-12 21:16:32 +0000
commitdbcb003c5e579a8dcbcb622f230be4f3672ea3c8 (patch)
tree06751c238a5c69c991bab03fb6dd18bd3c5893a6 /src
parentd8088176149a6086927eb765a6e617cf0041ec10 (diff)
util: add a function to parse bool properties
Move the logic used to parse boolean quirks and udev flags to a common function in utils. Refactor, no functional changes. Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/evdev.c10
-rw-r--r--src/quirks.c18
-rw-r--r--src/util-prop-parsers.c16
-rw-r--r--src/util-prop-parsers.h1
4 files changed, 26 insertions, 19 deletions
diff --git a/src/evdev.c b/src/evdev.c
index e8b37674..f332bc1b 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -94,19 +94,21 @@ parse_udev_flag(struct evdev_device *device,
const char *property)
{
const char *val;
+ bool b;
val = udev_device_get_property_value(udev_device, property);
if (!val)
return false;
- if (streq(val, "1"))
- return true;
- if (!streq(val, "0"))
+ if (!parse_boolean_property(val, &b)) {
evdev_log_error(device,
"property %s has invalid value '%s'\n",
property,
val);
- return false;
+ return false;
+ }
+
+ return b;
}
int
diff --git a/src/quirks.c b/src/quirks.c
index 502c8bd0..795d2925 100644
--- a/src/quirks.c
+++ b/src/quirks.c
@@ -660,11 +660,7 @@ parse_model(struct quirks_context *ctx,
assert(strneq(key, "Model", 5));
- if (streq(value, "1"))
- b = true;
- else if (streq(value, "0"))
- b = false;
- else
+ if (!parse_boolean_property(value, &b))
return false;
do {
@@ -789,22 +785,14 @@ parse_attr(struct quirks_context *ctx,
rc = true;
} else if (streq(key, quirk_get_name(QUIRK_ATTR_USE_VELOCITY_AVERAGING))) {
p->id = QUIRK_ATTR_USE_VELOCITY_AVERAGING;
- if (streq(value, "1"))
- b = true;
- else if (streq(value, "0"))
- b = false;
- else
+ if (!parse_boolean_property(value, &b))
goto out;
p->type = PT_BOOL;
p->value.b = b;
rc = true;
} else if (streq(key, quirk_get_name(QUIRK_ATTR_TABLET_SMOOTHING))) {
p->id = QUIRK_ATTR_TABLET_SMOOTHING;
- if (streq(value, "1"))
- b = true;
- else if (streq(value, "0"))
- b = false;
- else
+ if (!parse_boolean_property(value, &b))
goto out;
p->type = PT_BOOL;
p->value.b = b;
diff --git a/src/util-prop-parsers.c b/src/util-prop-parsers.c
index cfd6c59d..62902520 100644
--- a/src/util-prop-parsers.c
+++ b/src/util-prop-parsers.c
@@ -283,6 +283,22 @@ parse_range_property(const char *prop, int *hi, int *lo)
return true;
}
+bool
+parse_boolean_property(const char *prop, bool *b)
+{
+ if (!prop)
+ return false;
+
+ if (streq(prop, "1"))
+ *b = true;
+ else if (streq(prop, "0"))
+ *b = false;
+ else
+ return false;
+
+ return true;
+}
+
static bool
parse_evcode_string(const char *s, int *type_out, int *code_out)
{
diff --git a/src/util-prop-parsers.h b/src/util-prop-parsers.h
index 5f0d8673..8fbeacd0 100644
--- a/src/util-prop-parsers.h
+++ b/src/util-prop-parsers.h
@@ -36,6 +36,7 @@ int parse_mouse_wheel_click_count_property(const char *prop);
bool parse_dimension_property(const char *prop, size_t *width, size_t *height);
bool parse_calibration_property(const char *prop, float calibration[6]);
bool parse_range_property(const char *prop, int *hi, int *lo);
+bool parse_boolean_property(const char *prop, bool *b);
#define EVENT_CODE_UNDEFINED 0xffff
bool parse_evcode_property(const char *prop, struct input_event *events, size_t *nevents);
bool parse_input_prop_property(const char *prop, unsigned int *props_out, size_t *nprops);