From b8d85c6939eaa3fca676af832b5d64320b2296ca Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 30 Nov 2022 12:51:59 -0800 Subject: [PATCH 2/5] Update for SDL3 coding style (#6717) I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594 (cherry picked from commit 5750bcb174300011b91d1de20edb288fcca70f8c) --- src/core/linux/SDL_evdev_kbd.c | 92 ++++++++++++++++------------------ 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c index f7f01deb4..42b634a92 100644 --- a/src/core/linux/SDL_evdev_kbd.c +++ b/src/core/linux/SDL_evdev_kbd.c @@ -53,33 +53,31 @@ * Handler Tables. */ -#define K_HANDLERS\ - k_self, k_fn, k_spec, k_pad,\ - k_dead, k_cons, k_cur, k_shift,\ - k_meta, k_ascii, k_lock, k_lowercase,\ - k_slock, k_dead2, k_brl, k_ignore +#define K_HANDLERS \ + k_self, k_fn, k_spec, k_pad, \ + k_dead, k_cons, k_cur, k_shift, \ + k_meta, k_ascii, k_lock, k_lowercase, \ + k_slock, k_dead2, k_brl, k_ignore -typedef void (k_handler_fn)(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag); +typedef void(k_handler_fn)(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag); static k_handler_fn K_HANDLERS; static k_handler_fn *k_handler[16] = { K_HANDLERS }; -typedef void (fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd); +typedef void(fn_handler_fn)(SDL_EVDEV_keyboard_state *kbd); static void fn_enter(SDL_EVDEV_keyboard_state *kbd); static void fn_caps_toggle(SDL_EVDEV_keyboard_state *kbd); static void fn_caps_on(SDL_EVDEV_keyboard_state *kbd); static void fn_num(SDL_EVDEV_keyboard_state *kbd); static void fn_compose(SDL_EVDEV_keyboard_state *kbd); -static fn_handler_fn *fn_handler[] = -{ - NULL, fn_enter, NULL, NULL, - NULL, NULL, NULL, fn_caps_toggle, - fn_num, NULL, NULL, NULL, - NULL, fn_caps_on, fn_compose, NULL, - NULL, NULL, NULL, fn_num +static fn_handler_fn *fn_handler[] = { + NULL, fn_enter, NULL, NULL, + NULL, NULL, NULL, fn_caps_toggle, + fn_num, NULL, NULL, NULL, + NULL, fn_caps_on, fn_compose, NULL, + NULL, NULL, NULL, fn_num }; - /* * Keyboard State */ @@ -89,12 +87,12 @@ struct SDL_EVDEV_keyboard_state int console_fd; int old_kbd_mode; unsigned short **key_maps; - unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ + unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ SDL_bool dead_key_next; - int npadch; /* -1 or number assembled on pad */ + int npadch; /* -1 or number assembled on pad */ struct kbdiacrs *accents; unsigned int diacr; - SDL_bool rep; /* flag telling character repeat */ + SDL_bool rep; /* flag telling character repeat */ unsigned char lockstate; unsigned char slockstate; unsigned char ledflagstate; @@ -114,7 +112,7 @@ static void SDL_EVDEV_dump_accents(SDL_EVDEV_keyboard_state *kbd) for (i = 0; i < kbd->accents->kb_cnt; ++i) { struct kbdiacr *diacr = &kbd->accents->kbdiacr[i]; printf(" { 0x%.2x, 0x%.2x, 0x%.2x },\n", - diacr->diacr, diacr->base, diacr->result); + diacr->diacr, diacr->base, diacr->result); } while (i < 256) { printf(" { 0x00, 0x00, 0x00 },\n"); @@ -134,7 +132,7 @@ static void SDL_EVDEV_dump_keymap(SDL_EVDEV_keyboard_state *kbd) if (kbd->key_maps[i]) { printf("static unsigned short default_key_map_%d[NR_KEYS] = {", i); for (j = 0; j < NR_KEYS; ++j) { - if ((j%8) == 0) { + if ((j % 8) == 0) { printf("\n "); } printf("0x%.4x, ", kbd->key_maps[i][j]); @@ -194,23 +192,22 @@ static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd) return 0; } -static SDL_EVDEV_keyboard_state * kbd_cleanup_state = NULL; +static SDL_EVDEV_keyboard_state *kbd_cleanup_state = NULL; static int kbd_cleanup_sigactions_installed = 0; static int kbd_cleanup_atexit_installed = 0; static struct sigaction old_sigaction[NSIG]; -static int fatal_signals[] = -{ +static int fatal_signals[] = { /* Handlers for SIGTERM and SIGINT are installed in SDL_QuitInit. */ - SIGHUP, SIGQUIT, SIGILL, SIGABRT, - SIGFPE, SIGSEGV, SIGPIPE, SIGBUS, + SIGHUP, SIGQUIT, SIGILL, SIGABRT, + SIGFPE, SIGSEGV, SIGPIPE, SIGBUS, SIGSYS }; static void kbd_cleanup(void) { - SDL_EVDEV_keyboard_state* kbd = kbd_cleanup_state; + SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state; if (kbd == NULL) { return; } @@ -219,18 +216,17 @@ static void kbd_cleanup(void) ioctl(kbd->console_fd, KDSKBMODE, kbd->old_kbd_mode); } -static void -SDL_EVDEV_kbd_reraise_signal(int sig) +static void SDL_EVDEV_kbd_reraise_signal(int sig) { raise(sig); } -siginfo_t* SDL_EVDEV_kdb_cleanup_siginfo = NULL; -void* SDL_EVDEV_kdb_cleanup_ucontext = NULL; +siginfo_t *SDL_EVDEV_kdb_cleanup_siginfo = NULL; +void *SDL_EVDEV_kdb_cleanup_ucontext = NULL; -static void kbd_cleanup_signal_action(int signum, siginfo_t* info, void* ucontext) +static void kbd_cleanup_signal_action(int signum, siginfo_t *info, void *ucontext) { - struct sigaction* old_action_p = &(old_sigaction[signum]); + struct sigaction *old_action_p = &(old_sigaction[signum]); sigset_t sigset; /* Restore original signal handler before going any further. */ @@ -264,7 +260,7 @@ static void kbd_unregister_emerg_cleanup() kbd_cleanup_sigactions_installed = 0; for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) { - struct sigaction* old_action_p; + struct sigaction *old_action_p; struct sigaction cur_action; signum = fatal_signals[tabidx]; old_action_p = &(old_sigaction[signum]); @@ -293,7 +289,7 @@ static void kbd_cleanup_atexit(void) kbd_unregister_emerg_cleanup(); } -static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) +static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd) { int tabidx, signum; @@ -317,9 +313,9 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) kbd_cleanup_sigactions_installed = 1; for (tabidx = 0; tabidx < sizeof(fatal_signals) / sizeof(fatal_signals[0]); ++tabidx) { - struct sigaction* old_action_p; + struct sigaction *old_action_p; struct sigaction new_action; - signum = fatal_signals[tabidx]; + signum = fatal_signals[tabidx]; old_action_p = &(old_sigaction[signum]); if (sigaction(signum, NULL, old_action_p)) { continue; @@ -328,7 +324,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state * kbd) /* Skip SIGHUP and SIGPIPE if handler is already installed * - assume the handler will do the cleanup */ - if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void(*)(int))old_action_p->sa_sigaction != SIG_DFL)) { + if ((signum == SIGHUP || signum == SIGPIPE) && (old_action_p->sa_handler != SIG_DFL || (void (*)(int))old_action_p->sa_sigaction != SIG_DFL)) { continue; } @@ -345,7 +341,7 @@ SDL_EVDEV_kbd_init(void) SDL_EVDEV_keyboard_state *kbd; int i; char flag_state; - char shift_state[ sizeof (long) ] = {TIOCL_GETSHIFTSTATE, 0}; + char shift_state[sizeof(long)] = { TIOCL_GETSHIFTSTATE, 0 }; kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd)); if (kbd == NULL) { @@ -411,8 +407,7 @@ SDL_EVDEV_kbd_init(void) return kbd; } -void -SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) +void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) { if (kbd == NULL) { return; @@ -447,7 +442,7 @@ SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd) static void put_queue(SDL_EVDEV_keyboard_state *kbd, uint c) { /* c is already part of a UTF-8 sequence and safe to add as a character */ - if (kbd->text_len < (sizeof(kbd->text)-1)) { + if (kbd->text_len < (sizeof(kbd->text) - 1)) { kbd->text[kbd->text_len++] = (char)c; } } @@ -615,7 +610,7 @@ static void k_self(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_f { if (up_flag) { return; /* no action, if this is a key release */ - } + } if (kbd->diacr) { value = handle_diacr(kbd, value); @@ -639,7 +634,7 @@ static void k_deadunicode(SDL_EVDEV_keyboard_state *kbd, unsigned int value, cha static void k_dead(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_flag) { - const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' }; + const unsigned char ret_diacr[NR_DEAD] = { '`', '\'', '^', '~', '"', ',' }; k_deadunicode(kbd, ret_diacr[value], up_flag); } @@ -666,7 +661,7 @@ static void k_pad(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl static const char pad_chars[] = "0123456789+-*/\015,.?()#"; if (up_flag) - return; /* no action, if this is a key release */ + return; /* no action, if this is a key release */ if (!vc_kbd_led(kbd, K_NUMLOCK)) { /* unprintable action */ @@ -768,8 +763,7 @@ static void k_brl(SDL_EVDEV_keyboard_state *kbd, unsigned char value, char up_fl { } -void -SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down) +void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode, int down) { unsigned char shift_final; unsigned char type; @@ -841,13 +835,11 @@ SDL_EVDEV_kbd_init(void) return NULL; } -void -SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down) +void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode, int down) { } -void -SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state) +void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *state) { } -- 2.39.2