From db5d8d248bdd391bcc14e69127ecd29a5cd633ec Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 26 Oct 2015 19:41:20 +0100 Subject: [PATCH] Create new char_list_new_special --- audio/audio_driver.c | 2 +- audio/audio_resampler_driver.c | 2 +- camera/camera_driver.c | 2 +- gfx/video_driver.c | 2 +- input/input_driver.c | 2 +- input/input_hid_driver.c | 2 +- input/input_joypad_driver.c | 2 +- location/location_driver.c | 2 +- menu/menu_driver.c | 2 +- record/record_driver.c | 2 +- string_list_special.c | 68 ++++++++++++++++++++-------------- string_list_special.h | 7 +++- 12 files changed, 56 insertions(+), 39 deletions(-) diff --git a/audio/audio_driver.c b/audio/audio_driver.c index 232570976d..7f07bfe6e5 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -225,7 +225,7 @@ const char *audio_driver_find_ident(int idx) **/ const char *config_get_audio_driver_options(void) { - return string_list_special_new(STRING_LIST_AUDIO_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_AUDIO_DRIVERS, NULL); } void find_audio_driver(void) diff --git a/audio/audio_resampler_driver.c b/audio/audio_resampler_driver.c index 6a55bbde66..b1a9b87cf7 100644 --- a/audio/audio_resampler_driver.c +++ b/audio/audio_resampler_driver.c @@ -99,7 +99,7 @@ const char *audio_resampler_driver_find_ident(int idx) **/ const char* config_get_audio_resampler_driver_options(void) { - return string_list_special_new(STRING_LIST_AUDIO_RESAMPLER_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_AUDIO_RESAMPLER_DRIVERS, NULL); } #endif diff --git a/camera/camera_driver.c b/camera/camera_driver.c index 494860f516..9920a5b447 100644 --- a/camera/camera_driver.c +++ b/camera/camera_driver.c @@ -80,7 +80,7 @@ const char *camera_driver_find_ident(int idx) **/ const char* config_get_camera_driver_options(void) { - return string_list_special_new(STRING_LIST_CAMERA_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_CAMERA_DRIVERS, NULL); } void find_camera_driver(void) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index f94852fc88..00a96f0e45 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -151,7 +151,7 @@ const char *video_driver_find_ident(int idx) **/ const char* config_get_video_driver_options(void) { - return string_list_special_new(STRING_LIST_VIDEO_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_VIDEO_DRIVERS, NULL); } void find_video_driver(void) diff --git a/input/input_driver.c b/input/input_driver.c index 475354e4c0..dd1e2937c3 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -108,7 +108,7 @@ const char *input_driver_find_ident(int idx) **/ const char* config_get_input_driver_options(void) { - return string_list_special_new(STRING_LIST_INPUT_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_INPUT_DRIVERS, NULL); } void find_input_driver(void) diff --git a/input/input_hid_driver.c b/input/input_hid_driver.c index 1722703fe8..1c0070f4f8 100644 --- a/input/input_hid_driver.c +++ b/input/input_hid_driver.c @@ -81,7 +81,7 @@ const char *hid_driver_find_ident(int idx) **/ const char* config_get_hid_driver_options(void) { - return string_list_special_new(STRING_LIST_INPUT_HID_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_INPUT_HID_DRIVERS, NULL); } #endif diff --git a/input/input_joypad_driver.c b/input/input_joypad_driver.c index 33300118ef..6e6dd4b7d2 100644 --- a/input/input_joypad_driver.c +++ b/input/input_joypad_driver.c @@ -109,7 +109,7 @@ const char *joypad_driver_find_ident(int idx) **/ const char* config_get_joypad_driver_options(void) { - return string_list_special_new(STRING_LIST_INPUT_JOYPAD_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_INPUT_JOYPAD_DRIVERS, NULL); } #endif diff --git a/location/location_driver.c b/location/location_driver.c index d8886168a4..aa369c09dd 100644 --- a/location/location_driver.c +++ b/location/location_driver.c @@ -73,7 +73,7 @@ const char *location_driver_find_ident(int idx) **/ const char* config_get_location_driver_options(void) { - return string_list_special_new(STRING_LIST_LOCATION_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_LOCATION_DRIVERS, NULL); } void find_location_driver(void) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index b7ffc8b3c6..2f0cd0deaa 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -87,7 +87,7 @@ const char *menu_driver_find_ident(int idx) **/ const char *config_get_menu_driver_options(void) { - return string_list_special_new(STRING_LIST_MENU_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_MENU_DRIVERS, NULL); } void find_menu_driver(void) diff --git a/record/record_driver.c b/record/record_driver.c index 6e628e6b51..c35edd1771 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -76,7 +76,7 @@ const void *record_driver_find_handle(int idx) **/ const char* config_get_record_driver_options(void) { - return string_list_special_new(STRING_LIST_RECORD_DRIVERS, NULL); + return char_list_new_special(STRING_LIST_RECORD_DRIVERS, NULL); } void find_record_driver(void) diff --git a/string_list_special.c b/string_list_special.c index 5fd04ac9e1..30aa27ff64 100644 --- a/string_list_special.c +++ b/string_list_special.c @@ -14,7 +14,6 @@ */ #include -#include #include "string_list_special.h" @@ -39,14 +38,13 @@ #include "audio/audio_resampler_driver.h" #include "record/record_driver.h" -const char *string_list_special_new(enum string_list_type type, void *data) +struct string_list *string_list_new_special(enum string_list_type type, + void *data, unsigned *len) { union string_list_elem_attr attr; unsigned i; size_t list_size; - char *options = NULL; const core_info_t *core_info = NULL; - int len = 0; global_t *global = global_get_ptr(); struct string_list *s = string_list_new(); @@ -54,6 +52,11 @@ const char *string_list_special_new(enum string_list_type type, void *data) (void)data; + if (!len) + return NULL; + + *len = 0; + if (!s) return NULL; @@ -64,7 +67,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; menu_driver_find_handle(i); i++) { const char *opt = menu_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -75,7 +78,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; camera_driver_find_handle(i); i++) { const char *opt = camera_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -86,7 +89,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; location_driver_find_handle(i); i++) { const char *opt = location_driver_find_ident(i); - options_len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(options_l, opt, attr); } break; @@ -95,7 +98,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; audio_driver_find_handle(i); i++) { const char *opt = audio_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -104,7 +107,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; audio_resampler_driver_find_handle(i); i++) { const char *opt = audio_resampler_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -113,7 +116,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; video_driver_find_handle(i); i++) { const char *opt = video_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -122,7 +125,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; input_driver_find_handle(i); i++) { const char *opt = input_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -131,7 +134,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; hid_driver_find_handle(i); i++) { const char *opt = hid_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -140,7 +143,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; joypad_driver_find_handle(i); i++) { const char *opt = joypad_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -149,7 +152,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) for (i = 0; record_driver_find_handle(i); i++) { const char *opt = record_driver_find_ident(i); - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } @@ -159,7 +162,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) (const char*)data, &core_info, &list_size); if (list_size == 0) - goto end; + goto error; for (i = 0; i < list_size; i++) { @@ -168,9 +171,9 @@ const char *string_list_special_new(enum string_list_type type, void *data) opt = info ? info->path : NULL; if (!opt) - goto end; + goto error; - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } break; @@ -182,9 +185,9 @@ const char *string_list_special_new(enum string_list_type type, void *data) opt = core_info ? core_info->path : NULL; if (!opt) - goto end; + goto error; - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } break; @@ -193,7 +196,7 @@ const char *string_list_special_new(enum string_list_type type, void *data) (const char*)data, &core_info, &list_size); if (list_size == 0) - goto end; + goto error; for (i = 0; i < list_size; i++) { @@ -202,9 +205,9 @@ const char *string_list_special_new(enum string_list_type type, void *data) opt = info ? info->display_name : NULL; if (!opt) - goto end; + goto error; - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } break; @@ -217,23 +220,32 @@ const char *string_list_special_new(enum string_list_type type, void *data) opt = core_info ? core_info->display_name : NULL; if (!opt) - goto end; + goto error; - len += strlen(opt) + 1; + *len += strlen(opt) + 1; string_list_append(s, opt, attr); } break; case STRING_LIST_NONE: default: - goto end; + goto error; } - options = (char*)calloc(len, sizeof(char)); + return s; - if (options) +error: + return NULL; +} + +const char *char_list_new_special(enum string_list_type type, void *data) +{ + unsigned len; + struct string_list *s = string_list_new_special(type, data, &len); + char *options = (len > 0) ? (char*)calloc(len, sizeof(char)): NULL; + + if (options && s) string_list_join_concat(options, len, s, "|"); -end: string_list_free(s); s = NULL; diff --git a/string_list_special.h b/string_list_special.h index 22e151b358..86f80e356e 100644 --- a/string_list_special.h +++ b/string_list_special.h @@ -16,6 +16,8 @@ #ifndef _STRING_LIST_SPECIAL_H #define _STRING_LIST_SPECIAL_H +#include + enum string_list_type { STRING_LIST_NONE = 0, @@ -35,6 +37,9 @@ enum string_list_type STRING_LIST_CORES_NAMES }; -const char *string_list_special_new(enum string_list_type type, void *data); +struct string_list *string_list_new_special(enum string_list_type type, + void *data, unsigned *len); + +const char *char_list_new_special(enum string_list_type type, void *data); #endif