Finished with code de-duplication

This commit is contained in:
twinaphex 2015-10-26 18:41:13 +01:00
parent f6ed72b21c
commit dc01514db1
4 changed files with 32 additions and 73 deletions

View File

@ -21,7 +21,7 @@
#include <file/config_file_userdata.h>
#include <string.h>
#ifndef DONT_HAVE_STRING_LIST
#include <string/string_list.h>
#include "../string_list_special.h"
#endif
static const rarch_resampler_t *resampler_drivers[] = {
@ -99,40 +99,7 @@ const char *audio_resampler_driver_find_ident(int idx)
**/
const char* config_get_audio_resampler_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; resampler_drivers[i]; i++)
{
const char *opt = resampler_drivers[i]->ident;
options_len += strlen(opt) + 1;
string_list_append(options_l, opt, attr);
}
options = (char*)calloc(options_len, sizeof(char));
if (!options)
{
options = NULL;
goto done;
}
string_list_join_concat(options, options_len, options_l, "|");
done:
string_list_free(options_l);
options_l = NULL;
return options;
return string_list_special_new(STRING_LIST_AUDIO_RESAMPLER_DRIVERS);
}
#endif

View File

@ -18,10 +18,11 @@
#include <ctype.h>
#include <string.h>
#include <string/string_list.h>
#include "input_hid_driver.h"
#include "../general.h"
#ifndef IS_JOYCONFIG
#include "../string_list_special.h"
#endif
static hid_driver_t *hid_drivers[] = {
#if defined(__APPLE__) && defined(IOS)
@ -70,6 +71,7 @@ const char *hid_driver_find_ident(int idx)
return drv->ident;
}
#ifndef IS_JOYCONFIG
/**
* config_get_hid_driver_options:
*
@ -79,41 +81,9 @@ const char *hid_driver_find_ident(int idx)
**/
const char* config_get_hid_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; hid_drivers[i]; i++)
{
const char *opt = hid_drivers[i]->ident;
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_INPUT_HID_DRIVERS);
}
#endif
/**
* input_hid_init_first:

View File

@ -32,8 +32,10 @@
#include "gfx/video_driver.h"
#include "input/input_driver.h"
#include "input/input_hid_driver.h"
#include "input/input_joypad_driver.h"
#include "audio/audio_driver.h"
#include "audio/audio_resampler_driver.h"
#include "record/record_driver.h"
const char *string_list_special_new(enum string_list_type type)
@ -92,6 +94,15 @@ const char *string_list_special_new(enum string_list_type type)
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_AUDIO_RESAMPLER_DRIVERS:
for (i = 0; audio_resampler_driver_find_handle(i); i++)
{
const char *opt = audio_resampler_driver_find_ident(i);
len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_VIDEO_DRIVERS:
for (i = 0; video_driver_find_handle(i); i++)
{
@ -110,6 +121,15 @@ const char *string_list_special_new(enum string_list_type type)
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_INPUT_HID_DRIVERS:
for (i = 0; hid_driver_find_handle(i); i++)
{
const char *opt = hid_driver_find_ident(i);
len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_INPUT_JOYPAD_DRIVERS:
for (i = 0; joypad_driver_find_handle(i); i++)
{

View File

@ -23,10 +23,12 @@ enum string_list_type
STRING_LIST_CAMERA_DRIVERS,
STRING_LIST_LOCATION_DRIVERS,
STRING_LIST_AUDIO_DRIVERS,
STRING_LIST_AUDIO_RESAMPLER_DRIVERS,
STRING_LIST_VIDEO_DRIVERS,
STRING_LIST_INPUT_DRIVERS,
STRING_LIST_RECORD_DRIVERS,
STRING_LIST_INPUT_JOYPAD_DRIVERS
STRING_LIST_INPUT_JOYPAD_DRIVERS,
STRING_LIST_INPUT_HID_DRIVERS,
STRING_LIST_RECORD_DRIVERS
};
const char *string_list_special_new(enum string_list_type type);