mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-07 04:34:03 -05:00
config: wrap LOG_AND_NOTIFY_*() in do {} while (0)
This allows us to use these macros in if-statement without braces.
This commit is contained in:
parent
9b65531d6a
commit
593cad3680
1 changed files with 25 additions and 27 deletions
52
config.c
52
config.c
|
|
@ -97,45 +97,43 @@ static const char *const search_binding_action_map[] = {
|
||||||
static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT,
|
static_assert(ALEN(search_binding_action_map) == BIND_ACTION_SEARCH_COUNT,
|
||||||
"search binding action map size mismatch");
|
"search binding action map size mismatch");
|
||||||
|
|
||||||
#define LOG_AND_NOTIFY_ERR(fmt, ...) \
|
#define LOG_AND_NOTIFY_ERR(fmt, ...) \
|
||||||
LOG_ERR(fmt, ## __VA_ARGS__); \
|
do { \
|
||||||
{ \
|
LOG_ERR(fmt, ## __VA_ARGS__); \
|
||||||
char *text = xasprintf(fmt, ## __VA_ARGS__); \
|
char *text = xasprintf(fmt, ## __VA_ARGS__); \
|
||||||
struct user_notification notif = { \
|
struct user_notification notif = { \
|
||||||
.kind = USER_NOTIFICATION_ERROR, \
|
.kind = USER_NOTIFICATION_ERROR, \
|
||||||
.text = text, \
|
.text = text, \
|
||||||
}; \
|
}; \
|
||||||
tll_push_back(conf->notifications, notif); \
|
tll_push_back(conf->notifications, notif); \
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
#define LOG_AND_NOTIFY_WARN(fmt, ...) \
|
#define LOG_AND_NOTIFY_WARN(fmt, ...) \
|
||||||
LOG_WARN(fmt, ## __VA_ARGS__); \
|
do { \
|
||||||
{ \
|
LOG_WARN(fmt, ## __VA_ARGS__); \
|
||||||
char *text = xasprintf(fmt, ## __VA_ARGS__); \
|
char *text = xasprintf(fmt, ## __VA_ARGS__); \
|
||||||
struct user_notification notif = { \
|
struct user_notification notif = { \
|
||||||
.kind = USER_NOTIFICATION_WARNING, \
|
.kind = USER_NOTIFICATION_WARNING, \
|
||||||
.text = text, \
|
.text = text, \
|
||||||
}; \
|
}; \
|
||||||
tll_push_back(conf->notifications, notif); \
|
tll_push_back(conf->notifications, notif); \
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
#define LOG_AND_NOTIFY_ERRNO(fmt, ...) \
|
#define LOG_AND_NOTIFY_ERRNO(fmt, ...) \
|
||||||
{ \
|
do { \
|
||||||
int _errno = errno; \
|
int _errno = errno; \
|
||||||
LOG_ERRNO(fmt, ## __VA_ARGS__); \
|
LOG_ERRNO(fmt, ## __VA_ARGS__); \
|
||||||
{ \
|
int len = snprintf(NULL, 0, fmt, ## __VA_ARGS__); \
|
||||||
int len = snprintf(NULL, 0, fmt, ## __VA_ARGS__); \
|
int errno_len = snprintf(NULL, 0, ": %s", strerror(_errno)); \
|
||||||
int errno_len = snprintf(NULL, 0, ": %s", strerror(_errno)); \
|
char *text = xmalloc(len + errno_len + 1); \
|
||||||
char *text = xmalloc(len + errno_len + 1); \
|
snprintf(text, len + errno_len + 1, fmt, ## __VA_ARGS__); \
|
||||||
snprintf(text, len + errno_len + 1, fmt, ## __VA_ARGS__); \
|
snprintf(&text[len], errno_len + 1, ": %s", strerror(_errno)); \
|
||||||
snprintf(&text[len], errno_len + 1, ": %s", strerror(_errno)); \
|
struct user_notification notif = { \
|
||||||
struct user_notification notif = { \
|
.kind = USER_NOTIFICATION_ERROR, \
|
||||||
.kind = USER_NOTIFICATION_ERROR, \
|
.text = text, \
|
||||||
.text = text, \
|
}; \
|
||||||
}; \
|
tll_push_back(conf->notifications, notif); \
|
||||||
tll_push_back(conf->notifications, notif); \
|
} while(0)
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_shell(void)
|
get_shell(void)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue