util: add truefalse and yesno macros for easy string conversion

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1118>
This commit is contained in:
Peter Hutterer 2025-01-07 10:34:31 +10:00 committed by Marge Bot
parent d52bb9ed4d
commit c3bf478d41
4 changed files with 9 additions and 3 deletions

View file

@ -159,7 +159,7 @@ multivalue_as_str(const struct multivalue *v)
xasprintf(&str, "%d", v->value.i);
break;
case 'b':
xasprintf(&str, "%s", v->value.b ? "true" : "false");
xasprintf(&str, "%s", truefalse(v->value.b));
break;
case 'c':
xasprintf(&str, "%c", v->value.c);

View file

@ -45,6 +45,11 @@
#include "util-macros.h"
#define yesno(b) ((b) ? "yes" : "no")
#define truefalse(b) ((b) ? "true" : "false")
#define YESNO(b) ((b) ? "YES" : "NO")
#define TRUEFALSE(b) ((b) ? "TRUE" : "FALSE")
static inline bool
streq(const char *str1, const char *str2)
{

View file

@ -491,7 +491,7 @@ START_TEST(parameter_permutations)
ARRAY_FOR_EACH(permutations, p) {
if (p->s == NULL)
break;
ck_assert_msg(p->found, "For %d/%s/%s", p->i, p->s, p->b ? "true" : "false");
ck_assert_msg(p->found, "For %d/%s/%s", p->i, p->s, truefalse(p->b));
}
}
END_TEST

View file

@ -53,6 +53,7 @@
#include "util-time.h"
#include "util-input-event.h"
#include "util-macros.h"
#include "util-strings.h"
static const int FILE_VERSION_NUMBER = 1;
@ -1067,7 +1068,7 @@ print_tablet_pad_button_event(struct record_device *dev,
button,
state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released",
mode,
libinput_tablet_pad_mode_group_button_is_toggle(group, button) ? "true" : "false"
truefalse(libinput_tablet_pad_mode_group_button_is_toggle(group, button))
);
}