From bcc911019d7817e86b5779fa1c640d497e0b6544 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 30 Jan 2022 15:22:18 +0100 Subject: [PATCH] [config] trick with union { const char *, char * } --- src/config/kbdbind.c | 8 ++++---- src/config/kbdbind.h | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/config/kbdbind.c b/src/config/kbdbind.c index 996f9897..e0956f2a 100644 --- a/src/config/kbdbind.c +++ b/src/config/kbdbind.c @@ -27,7 +27,7 @@ #define table table_elinks #define ACTION_(map, name, action, caption, flags) \ - { name, ACT_##map##_##action, KEYMAP_ID, caption, flags } + { {name}, ACT_##map##_##action, KEYMAP_ID, {caption}, flags } #undef KEYMAP_ID #define KEYMAP_ID KEYMAP_MAIN @@ -275,7 +275,7 @@ get_action_name_from_keystroke(keymap_id_T keymap_id, const struct action *action = get_action_from_keystroke(keymap_id, keystroke_str); - return action ? action->str : NULL; + return action ? action->astr : NULL; } action_id_T @@ -308,7 +308,7 @@ get_action_name(keymap_id_T keymap_id, action_id_T action_id) { const struct action *action = get_action(keymap_id, action_id); - return action ? action->str : NULL; + return action ? action->astr : NULL; } static char * @@ -316,7 +316,7 @@ get_action_desc(keymap_id_T keymap_id, action_id_T action_id) { const struct action *action = get_action(keymap_id, action_id); - return action ? (action->desc ? action->desc : action->str) + return action ? (action->adesc ? action->adesc : action->astr) : NULL; } diff --git a/src/config/kbdbind.h b/src/config/kbdbind.h index aadb98a3..7d9d803a 100644 --- a/src/config/kbdbind.h +++ b/src/config/kbdbind.h @@ -28,10 +28,16 @@ enum keymap_id { }; struct action { - char *str; + union { + const char *str; + char *astr; + }; action_id_T num; keymap_id_T keymap_id; - char *desc; + union { + const char *desc; + char *adesc; + }; unsigned int flags; };