From f6ed72b21cc506161c633ef50ef9b03a0ab37950 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 26 Oct 2015 18:33:39 +0100 Subject: [PATCH] More code deduplication --- input/input_joypad_driver.c | 4 ++++ location/location_driver.c | 36 ++--------------------------- record/record_driver.c | 36 ++--------------------------- string_list_special.c | 32 ++++++++++++++++++------- string_list_special.h | 2 ++ tools/retroarch-joyconfig-griffin.c | 2 -- 6 files changed, 34 insertions(+), 78 deletions(-) diff --git a/input/input_joypad_driver.c b/input/input_joypad_driver.c index 406318d158..816e5e4941 100644 --- a/input/input_joypad_driver.c +++ b/input/input_joypad_driver.c @@ -20,7 +20,9 @@ #include "input_keymaps.h" #include "../general.h" +#ifndef IS_JOYCONFIG #include "../string_list_special.h" +#endif static input_device_driver_t *joypad_drivers[] = { #ifdef __CELLOS_LV2__ @@ -97,6 +99,7 @@ const char *joypad_driver_find_ident(int idx) return drv->ident; } +#ifndef IS_JOYCONFIG /** * config_get_joypad_driver_options: * @@ -108,6 +111,7 @@ const char* config_get_joypad_driver_options(void) { return string_list_special_new(STRING_LIST_INPUT_JOYPAD_DRIVERS); } +#endif /** * input_joypad_init_driver: diff --git a/location/location_driver.c b/location/location_driver.c index 7bffac0294..a16ae6deab 100644 --- a/location/location_driver.c +++ b/location/location_driver.c @@ -15,9 +15,9 @@ */ #include -#include #include "../general.h" +#include "../string_list_special.h" static const location_driver_t *location_drivers[] = { #ifdef ANDROID @@ -73,39 +73,7 @@ const char *location_driver_find_ident(int idx) **/ const char* config_get_location_driver_options(void) { - union string_list_elem_attr attr; - unsigned i; - char *options = NULL; - int options_len = 0; - struct string_list *options_l = string_list_new(); - - attr.i = 0; - - if (!options_l) - return NULL; - - for (i = 0; location_driver_find_handle(i); i++) - { - const char *opt = location_driver_find_ident(i); - options_len += strlen(opt) + 1; - string_list_append(options_l, opt, attr); - } - - options = (char*)calloc(options_len, sizeof(char)); - - if (!options) - { - string_list_free(options_l); - options_l = NULL; - return NULL; - } - - string_list_join_concat(options, options_len, options_l, "|"); - - string_list_free(options_l); - options_l = NULL; - - return options; + return string_list_special_new(STRING_LIST_LOCATION_DRIVERS); } void find_location_driver(void) diff --git a/record/record_driver.c b/record/record_driver.c index 67509a0053..2b5ff1b078 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -23,6 +23,7 @@ #include "../driver.h" #include "../general.h" #include "../msg_hash.h" +#include "../string_list_special.h" #ifdef HAVE_CONFIG_H #include "../config.h" @@ -75,40 +76,7 @@ const void *record_driver_find_handle(int idx) **/ const char* config_get_record_driver_options(void) { - union string_list_elem_attr attr; - unsigned i; - char *options = NULL; - int options_len = 0; - struct string_list *options_l = string_list_new(); - - attr.i = 0; - - if (!options_l) - return NULL; - - for (i = 0; record_driver_find_handle(i); i++) - { - const char *opt = record_driver_find_ident(i); - - options_len += strlen(opt) + 1; - string_list_append(options_l, opt, attr); - } - - options = (char*)calloc(options_len, sizeof(char)); - - if (!options) - { - string_list_free(options_l); - options_l = NULL; - return NULL; - } - - string_list_join_concat(options, options_len, options_l, "|"); - - string_list_free(options_l); - options_l = NULL; - - return options; + return string_list_special_new(STRING_LIST_RECORD_DRIVERS); } void find_record_driver(void) diff --git a/string_list_special.c b/string_list_special.c index 39fb3267f1..3fe7461c30 100644 --- a/string_list_special.c +++ b/string_list_special.c @@ -26,10 +26,15 @@ #include "camera/camera_driver.h" #endif +#ifdef HAVE_LOCATION +#include "location/location_driver.h" +#endif + #include "gfx/video_driver.h" #include "input/input_driver.h" #include "input/input_joypad_driver.h" #include "audio/audio_driver.h" +#include "record/record_driver.h" const char *string_list_special_new(enum string_list_type type) { @@ -48,7 +53,6 @@ const char *string_list_special_new(enum string_list_type type) { case STRING_LIST_MENU_DRIVERS: #ifdef HAVE_MENU -#ifndef IS_JOYCONFIG for (i = 0; menu_driver_find_handle(i); i++) { const char *opt = menu_driver_find_ident(i); @@ -57,7 +61,6 @@ const char *string_list_special_new(enum string_list_type type) string_list_append(s, opt, attr); } break; -#endif #endif case STRING_LIST_CAMERA_DRIVERS: #ifdef HAVE_CAMERA @@ -69,9 +72,18 @@ const char *string_list_special_new(enum string_list_type type) string_list_append(s, opt, attr); } break; +#endif + case STRING_LIST_LOCATION_DRIVERS: +#ifdef HAVE_LOCATION + for (i = 0; location_driver_find_handle(i); i++) + { + const char *opt = location_driver_find_ident(i); + options_len += strlen(opt) + 1; + string_list_append(options_l, opt, attr); + } + break; #endif case STRING_LIST_AUDIO_DRIVERS: -#ifndef IS_JOYCONFIG for (i = 0; audio_driver_find_handle(i); i++) { const char *opt = audio_driver_find_ident(i); @@ -79,10 +91,8 @@ const char *string_list_special_new(enum string_list_type type) string_list_append(s, opt, attr); } -#endif break; case STRING_LIST_VIDEO_DRIVERS: -#ifndef IS_JOYCONFIG for (i = 0; video_driver_find_handle(i); i++) { const char *opt = video_driver_find_ident(i); @@ -90,10 +100,8 @@ const char *string_list_special_new(enum string_list_type type) string_list_append(s, opt, attr); } -#endif break; case STRING_LIST_INPUT_DRIVERS: -#ifndef IS_JOYCONFIG for (i = 0; input_driver_find_handle(i); i++) { const char *opt = input_driver_find_ident(i); @@ -101,7 +109,6 @@ const char *string_list_special_new(enum string_list_type type) string_list_append(s, opt, attr); } -#endif break; case STRING_LIST_INPUT_JOYPAD_DRIVERS: for (i = 0; joypad_driver_find_handle(i); i++) @@ -112,6 +119,15 @@ const char *string_list_special_new(enum string_list_type type) string_list_append(s, opt, attr); } break; + case STRING_LIST_RECORD_DRIVERS: + for (i = 0; record_driver_find_handle(i); i++) + { + const char *opt = record_driver_find_ident(i); + len += strlen(opt) + 1; + + string_list_append(s, opt, attr); + } + break; case STRING_LIST_NONE: default: goto end; diff --git a/string_list_special.h b/string_list_special.h index 853889475a..05849441de 100644 --- a/string_list_special.h +++ b/string_list_special.h @@ -21,9 +21,11 @@ enum string_list_type STRING_LIST_NONE = 0, STRING_LIST_MENU_DRIVERS, STRING_LIST_CAMERA_DRIVERS, + STRING_LIST_LOCATION_DRIVERS, STRING_LIST_AUDIO_DRIVERS, STRING_LIST_VIDEO_DRIVERS, STRING_LIST_INPUT_DRIVERS, + STRING_LIST_RECORD_DRIVERS, STRING_LIST_INPUT_JOYPAD_DRIVERS }; diff --git a/tools/retroarch-joyconfig-griffin.c b/tools/retroarch-joyconfig-griffin.c index baf256b04c..4ad54e7b82 100644 --- a/tools/retroarch-joyconfig-griffin.c +++ b/tools/retroarch-joyconfig-griffin.c @@ -24,8 +24,6 @@ #include "../libretro-common/file/retro_file.c" #include "../libretro-common/file/retro_stat.c" -#include "../string_list_special.c" - #if defined(__linux) && !defined(ANDROID) #include "../input/drivers/linuxraw_input.c" #include "../input/drivers_joypad/linuxraw_joypad.c"