From 01c3684b1070b8e0998c5ce17cc7bda05c7e836d Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sat, 21 Jan 2023 22:25:38 +0100 Subject: [PATCH] Cleanups - try to remove stdio.h include where possible --- gfx/drivers_font/ctr_font.c | 2 +- gfx/drivers_font/ps2_font.c | 2 +- gfx/drivers_font/switch_font.c | 2 +- gfx/drivers_font/wiiu_font.c | 2 +- gfx/drivers_font_renderer/bitmapfont_10x10.c | 10 +-- gfx/drivers_font_renderer/bitmapfont_6x10.c | 89 +++++++++----------- input/drivers/dos_input.c | 4 +- led/drivers/led_overlay.c | 3 +- led/drivers/led_win32_keyboard.c | 2 +- led/drivers/led_x11_keyboard.c | 31 ++++--- tasks/task_core_backup.c | 2 +- tasks/task_core_updater.c | 2 +- tasks/task_manual_content_scan.c | 2 +- tasks/task_menu_explore.c | 2 +- tasks/task_pl_thumbnail_download.c | 3 +- tasks/task_playlist_manager.c | 4 +- tasks/task_screenshot.c | 14 +-- 17 files changed, 84 insertions(+), 92 deletions(-) diff --git a/gfx/drivers_font/ctr_font.c b/gfx/drivers_font/ctr_font.c index e4c7dd6fc4..3f4a4c7a81 100644 --- a/gfx/drivers_font/ctr_font.c +++ b/gfx/drivers_font/ctr_font.c @@ -14,7 +14,7 @@ * If not, see . */ -#include +#include #include #include #include diff --git a/gfx/drivers_font/ps2_font.c b/gfx/drivers_font/ps2_font.c index 64d8f5069d..205d7fa73d 100644 --- a/gfx/drivers_font/ps2_font.c +++ b/gfx/drivers_font/ps2_font.c @@ -13,7 +13,7 @@ * If not, see . */ -#include +#include #include #include #include diff --git a/gfx/drivers_font/switch_font.c b/gfx/drivers_font/switch_font.c index 8183b2173b..8fdb212df9 100644 --- a/gfx/drivers_font/switch_font.c +++ b/gfx/drivers_font/switch_font.c @@ -15,7 +15,7 @@ * If not, see . */ -#include +#include #include #include #include diff --git a/gfx/drivers_font/wiiu_font.c b/gfx/drivers_font/wiiu_font.c index 3606f4a237..15f02993e2 100644 --- a/gfx/drivers_font/wiiu_font.c +++ b/gfx/drivers_font/wiiu_font.c @@ -14,7 +14,7 @@ * If not, see . */ -#include +#include #include #include #include diff --git a/gfx/drivers_font_renderer/bitmapfont_10x10.c b/gfx/drivers_font_renderer/bitmapfont_10x10.c index 05c1a46f10..baf39ac667 100644 --- a/gfx/drivers_font_renderer/bitmapfont_10x10.c +++ b/gfx/drivers_font_renderer/bitmapfont_10x10.c @@ -16,11 +16,9 @@ * If not, see . */ -#include - +#include #include #include -#include #include #include @@ -140,8 +138,7 @@ bitmapfont_lut_t *bitmapfont_10x10_load(unsigned language) num_glyphs = (glyph_max - glyph_min) + 1; /* Initialise font struct */ - font = (bitmapfont_lut_t*)calloc(1, sizeof(bitmapfont_lut_t)); - if (!font) + if (!(font = (bitmapfont_lut_t*)calloc(1, sizeof(bitmapfont_lut_t)))) goto error; font->glyph_min = glyph_min; @@ -150,8 +147,7 @@ bitmapfont_lut_t *bitmapfont_10x10_load(unsigned language) /* Note: Need to use a calloc() here, otherwise * we'll get undefined behaviour when calling * bitmapfont_free_lut() if the following loop fails */ - font->lut = (bool**)calloc(1, num_glyphs * sizeof(bool*)); - if (!font->lut) + if (!(font->lut = (bool**)calloc(1, num_glyphs * sizeof(bool*)))) goto error; /* Loop over all possible characters */ diff --git a/gfx/drivers_font_renderer/bitmapfont_6x10.c b/gfx/drivers_font_renderer/bitmapfont_6x10.c index 1f3ea7f980..c0974a86e0 100644 --- a/gfx/drivers_font_renderer/bitmapfont_6x10.c +++ b/gfx/drivers_font_renderer/bitmapfont_6x10.c @@ -17,11 +17,9 @@ * If not, see . */ -#include - +#include #include #include -#include #include #include @@ -70,51 +68,46 @@ bitmapfont_lut_t *bitmapfont_6x10_load(unsigned language) * specified language */ switch (language) { - /* Needed individually for any non-Latin languages */ - case RETRO_LANGUAGE_ENGLISH: - { - font_file = FONT_6X10_FILE_ENG; - font_size = FONT_6X10_SIZE_ENG; - glyph_min = FONT_6X10_GLYPH_MIN_ENG; - glyph_max = FONT_6X10_GLYPH_MAX_ENG; - break; - } - - /* All Latin alphabet languages go here */ - case RETRO_LANGUAGE_FRENCH: - case RETRO_LANGUAGE_SPANISH: - case RETRO_LANGUAGE_GERMAN: - case RETRO_LANGUAGE_ITALIAN: - case RETRO_LANGUAGE_DUTCH: - case RETRO_LANGUAGE_PORTUGUESE_BRAZIL: - case RETRO_LANGUAGE_PORTUGUESE_PORTUGAL: - case RETRO_LANGUAGE_ESPERANTO: - case RETRO_LANGUAGE_POLISH: - case RETRO_LANGUAGE_VIETNAMESE: - case RETRO_LANGUAGE_TURKISH: - case RETRO_LANGUAGE_SLOVAK: - case RETRO_LANGUAGE_ASTURIAN: - case RETRO_LANGUAGE_FINNISH: - case RETRO_LANGUAGE_INDONESIAN: - case RETRO_LANGUAGE_SWEDISH: - case RETRO_LANGUAGE_CZECH: - case RETRO_LANGUAGE_HUNGARIAN: - /* These languages are not yet added - case RETRO_LANGUAGE_ROMANIAN: - case RETRO_LANGUAGE_CROATIAN: - case RETRO_LANGUAGE_SERBIAN: - case RETRO_LANGUAGE_WELSH: - */ - { - font_file = FONT_6X10_FILE_LSE; - font_size = FONT_6X10_SIZE_LSE; - glyph_min = FONT_6X10_GLYPH_MIN_LSE; - glyph_max = FONT_6X10_GLYPH_MAX_LSE; - break; - } - - default: - break; + /* Needed individually for any non-Latin languages */ + case RETRO_LANGUAGE_ENGLISH: + font_file = FONT_6X10_FILE_ENG; + font_size = FONT_6X10_SIZE_ENG; + glyph_min = FONT_6X10_GLYPH_MIN_ENG; + glyph_max = FONT_6X10_GLYPH_MAX_ENG; + break; + /* All Latin alphabet languages go here */ + case RETRO_LANGUAGE_FRENCH: + case RETRO_LANGUAGE_SPANISH: + case RETRO_LANGUAGE_GERMAN: + case RETRO_LANGUAGE_ITALIAN: + case RETRO_LANGUAGE_DUTCH: + case RETRO_LANGUAGE_PORTUGUESE_BRAZIL: + case RETRO_LANGUAGE_PORTUGUESE_PORTUGAL: + case RETRO_LANGUAGE_ESPERANTO: + case RETRO_LANGUAGE_POLISH: + case RETRO_LANGUAGE_VIETNAMESE: + case RETRO_LANGUAGE_TURKISH: + case RETRO_LANGUAGE_SLOVAK: + case RETRO_LANGUAGE_ASTURIAN: + case RETRO_LANGUAGE_FINNISH: + case RETRO_LANGUAGE_INDONESIAN: + case RETRO_LANGUAGE_SWEDISH: + case RETRO_LANGUAGE_CZECH: + case RETRO_LANGUAGE_HUNGARIAN: +#if 0 + /* These languages are not yet added */ + case RETRO_LANGUAGE_ROMANIAN: + case RETRO_LANGUAGE_CROATIAN: + case RETRO_LANGUAGE_SERBIAN: + case RETRO_LANGUAGE_WELSH: +#endif + font_file = FONT_6X10_FILE_LSE; + font_size = FONT_6X10_SIZE_LSE; + glyph_min = FONT_6X10_GLYPH_MIN_LSE; + glyph_max = FONT_6X10_GLYPH_MAX_LSE; + break; + default: + break; } /* Sanity check: should only trigger on bug */ diff --git a/input/drivers/dos_input.c b/input/drivers/dos_input.c index ca9833d5ba..bee207104a 100644 --- a/input/drivers/dos_input.c +++ b/input/drivers/dos_input.c @@ -15,13 +15,11 @@ * If not, see . */ -#include +#include #include #include -#include "../../config.def.h" - #include "../input_driver.h" #include "../input_keymaps.h" #include "../drivers_keyboard/keyboard_event_dos.h" diff --git a/led/drivers/led_overlay.c b/led/drivers/led_overlay.c index c42db71487..dd87672453 100644 --- a/led/drivers/led_overlay.c +++ b/led/drivers/led_overlay.c @@ -1,11 +1,10 @@ -#include +#include #include "../led_driver.h" #include "../led_defines.h" #include "../../input/input_overlay.h" #include "../../configuration.h" -#include "../../retroarch.h" typedef struct { diff --git a/led/drivers/led_win32_keyboard.c b/led/drivers/led_win32_keyboard.c index 1c89ddcd7d..7257b66be5 100644 --- a/led/drivers/led_win32_keyboard.c +++ b/led/drivers/led_win32_keyboard.c @@ -1,4 +1,4 @@ -#include +#include #include "../led_driver.h" #include "../led_defines.h" diff --git a/led/drivers/led_x11_keyboard.c b/led/drivers/led_x11_keyboard.c index 630da830ef..a55860532a 100644 --- a/led/drivers/led_x11_keyboard.c +++ b/led/drivers/led_x11_keyboard.c @@ -1,12 +1,12 @@ #include + +#include +#include + #include "../led_driver.h" #include "../led_defines.h" #include "../../configuration.h" -#include "../../retroarch.h" - -#include -#include /* Keys when setting in XKeyboardControl.led */ #define XK_NUMLOCK 2 @@ -49,33 +49,38 @@ static keyboard_led_t *x11kb_cur = &x11kb_curins; static int get_led(int led) { - Display *dpy = XOpenDisplay(0); XKeyboardState state; + Display *dpy = XOpenDisplay(0); + XGetKeyboardControl(dpy, &state); XCloseDisplay(dpy); switch (led) { case XK_NUMLOCK: - return (state.led_mask & XM_NUMLOCK) ? 1 : 0; + if (state.led_mask & XM_NUMLOCK) + return 1; break; case XK_CAPSLOCK: - return (state.led_mask & XM_CAPSLOCK) ? 1 : 0; + if (state.led_mask & XM_CAPSLOCK) + return 1; break; case XK_SCROLLLOCK: - return (state.led_mask & XM_SCROLLLOCK) ? 1 : 0; + if (state.led_mask & XM_SCROLLLOCK) + return 1; break; default: break; } + return 0; } static void set_led(int led, int state) { - Display *dpy = XOpenDisplay(0); XKeyboardControl values; - values.led = led; + Display *dpy = XOpenDisplay(0); + values.led = led; values.led_mode = state ? LedModeOn : LedModeOff; XChangeKeyboardControl(dpy, KBLed | KBLedMode, &values); XCloseDisplay(dpy); @@ -116,9 +121,9 @@ static void keyboard_init(void) for (i = 0; i < MAX_LEDS; i++) { - x11kb_cur->setup[i] = keyboard_led(i, -1); - x11kb_cur->state[i] = -1; - x11kb_cur->map[i] = settings->uints.led_map[i]; + x11kb_cur->setup[i] = keyboard_led(i, -1); + x11kb_cur->state[i] = -1; + x11kb_cur->map[i] = settings->uints.led_map[i]; if (x11kb_cur->map[i] < 0) x11kb_cur->map[i] = i; } diff --git a/tasks/task_core_backup.c b/tasks/task_core_backup.c index 4da2b00398..ccce07fd6e 100644 --- a/tasks/task_core_backup.c +++ b/tasks/task_core_backup.c @@ -16,9 +16,9 @@ * If not, see . */ +#include #include #include -#include #include #include diff --git a/tasks/task_core_updater.c b/tasks/task_core_updater.c index ea984e4bd0..b1ee1e93f2 100644 --- a/tasks/task_core_updater.c +++ b/tasks/task_core_updater.c @@ -16,9 +16,9 @@ * If not, see . */ +#include #include #include -#include #include #include diff --git a/tasks/task_manual_content_scan.c b/tasks/task_manual_content_scan.c index 0b3cfcec9d..709d1bc1e6 100644 --- a/tasks/task_manual_content_scan.c +++ b/tasks/task_manual_content_scan.c @@ -16,9 +16,9 @@ * If not, see . */ +#include #include #include -#include #include #include diff --git a/tasks/task_menu_explore.c b/tasks/task_menu_explore.c index 5ca2bfcb7f..fda8373aad 100644 --- a/tasks/task_menu_explore.c +++ b/tasks/task_menu_explore.c @@ -15,9 +15,9 @@ * If not, see . */ +#include #include #include -#include #include #include diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index 9a62b1ec3f..4ced46e8e6 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -15,9 +15,10 @@ * If not, see . */ +#include +#include #include #include -#include #include #include diff --git a/tasks/task_playlist_manager.c b/tasks/task_playlist_manager.c index 94c1e6a647..2934a27894 100644 --- a/tasks/task_playlist_manager.c +++ b/tasks/task_playlist_manager.c @@ -15,9 +15,10 @@ * If not, see . */ +#include +#include #include #include -#include #include #include @@ -27,7 +28,6 @@ #include "tasks_internal.h" -#include "../configuration.h" #include "../msg_hash.h" #include "../file_path_special.h" #include "../playlist.h" diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index 1c2be4d46a..65e35de1bd 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -15,17 +15,17 @@ * If not, see . */ +#include +#include +#include +#include + +#include + #ifdef HAVE_CONFIG_H #include "../config.h" #endif -#include -#include -#include -#include -#include -#include - #include #include #include