RetroArch/string_list_special.c

263 lines
7.6 KiB
C
Raw Normal View History

2015-10-26 07:39:35 +00:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "string_list_special.h"
#ifdef HAVE_MENU
#include "menu/menu_driver.h"
#endif
#ifdef HAVE_CAMERA
#include "camera/camera_driver.h"
#endif
2015-10-26 17:33:39 +00:00
#ifdef HAVE_LOCATION
#include "location/location_driver.h"
#endif
#include "core_info.h"
2015-10-26 18:03:29 +00:00
#include "general.h"
2015-10-26 07:59:23 +00:00
#include "gfx/video_driver.h"
#include "input/input_driver.h"
2015-10-26 17:41:13 +00:00
#include "input/input_hid_driver.h"
2015-10-26 08:06:11 +00:00
#include "input/input_joypad_driver.h"
#include "audio/audio_driver.h"
2015-10-26 17:41:13 +00:00
#include "audio/audio_resampler_driver.h"
2015-10-26 17:33:39 +00:00
#include "record/record_driver.h"
2015-10-26 18:41:20 +00:00
struct string_list *string_list_new_special(enum string_list_type type,
void *data, unsigned *len, size_t *list_size)
2015-10-26 07:39:35 +00:00
{
union string_list_elem_attr attr;
unsigned i;
2015-12-11 12:51:17 +00:00
core_info_list_t *core_info_list = NULL;
const core_info_t *core_info = NULL;
struct string_list *s = string_list_new();
2015-10-26 07:39:35 +00:00
attr.i = 0;
(void)data;
2015-10-26 18:41:20 +00:00
if (!len)
return NULL;
*len = 0;
2015-10-26 07:39:35 +00:00
if (!s)
return NULL;
switch (type)
{
case STRING_LIST_MENU_DRIVERS:
#ifdef HAVE_MENU
for (i = 0; menu_driver_find_handle(i); i++)
{
const char *opt = menu_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 07:39:35 +00:00
string_list_append(s, opt, attr);
}
break;
#endif
case STRING_LIST_CAMERA_DRIVERS:
#ifdef HAVE_CAMERA
for (i = 0; camera_driver_find_handle(i); i++)
{
const char *opt = camera_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
2015-10-26 17:33:39 +00:00
#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);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 17:33:39 +00:00
string_list_append(options_l, opt, attr);
}
break;
2015-10-26 07:39:35 +00:00
#endif
case STRING_LIST_AUDIO_DRIVERS:
for (i = 0; audio_driver_find_handle(i); i++)
{
2015-10-26 07:55:59 +00:00
const char *opt = audio_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 07:55:59 +00:00
string_list_append(s, opt, attr);
}
break;
2015-10-26 17:41:13 +00:00
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);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 17:41:13 +00:00
string_list_append(s, opt, attr);
}
break;
2015-10-26 07:55:59 +00:00
case STRING_LIST_VIDEO_DRIVERS:
for (i = 0; video_driver_find_handle(i); i++)
{
const char *opt = video_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
2015-10-26 07:59:23 +00:00
case STRING_LIST_INPUT_DRIVERS:
for (i = 0; input_driver_find_handle(i); i++)
{
const char *opt = input_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 07:59:23 +00:00
2015-10-26 08:06:11 +00:00
string_list_append(s, opt, attr);
}
break;
2015-10-26 17:41:13 +00:00
case STRING_LIST_INPUT_HID_DRIVERS:
for (i = 0; hid_driver_find_handle(i); i++)
{
const char *opt = hid_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 17:41:13 +00:00
string_list_append(s, opt, attr);
}
break;
2015-10-26 08:06:11 +00:00
case STRING_LIST_INPUT_JOYPAD_DRIVERS:
for (i = 0; joypad_driver_find_handle(i); i++)
{
const char *opt = joypad_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 08:06:11 +00:00
2015-10-26 07:59:23 +00:00
string_list_append(s, opt, attr);
}
break;
2015-10-26 17:33:39 +00:00
case STRING_LIST_RECORD_DRIVERS:
for (i = 0; record_driver_find_handle(i); i++)
{
const char *opt = record_driver_find_ident(i);
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 17:33:39 +00:00
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_SUPPORTED_CORES_PATHS:
2015-12-11 12:51:17 +00:00
runloop_ctl(RUNLOOP_CTL_CURRENT_CORE_LIST_GET, &core_info_list);
core_info_list_get_supported_cores(core_info_list,
(const char*)data, &core_info, list_size);
if (*list_size == 0)
2015-10-26 18:41:20 +00:00
goto error;
for (i = 0; i < *list_size; i++)
{
const char *opt = NULL;
const core_info_t *info = (const core_info_t*)&core_info[i];
opt = info ? info->path : NULL;
if (!opt)
2015-10-26 18:41:20 +00:00
goto error;
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_CORES_PATHS:
2015-12-11 12:51:17 +00:00
runloop_ctl(RUNLOOP_CTL_CURRENT_CORE_LIST_GET, &core_info_list);
for (i = 0; i < core_info_list_num_info_files(core_info_list); i++)
{
const char *opt = NULL;
2015-12-11 12:51:17 +00:00
core_info = (const core_info_t*)&core_info_list->list[i];
opt = core_info ? core_info->path : NULL;
if (!opt)
2015-10-26 18:41:20 +00:00
goto error;
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_SUPPORTED_CORES_NAMES:
2015-12-11 12:51:17 +00:00
runloop_ctl(RUNLOOP_CTL_CURRENT_CORE_LIST_GET, &core_info_list);
core_info_list_get_supported_cores(core_info_list,
(const char*)data, &core_info, list_size);
if (*list_size == 0)
2015-10-26 18:41:20 +00:00
goto error;
for (i = 0; i < *list_size; i++)
{
const char *opt = NULL;
const core_info_t *info = (const core_info_t*)&core_info[i];
opt = info ? info->display_name : NULL;
if (!opt)
2015-10-26 18:41:20 +00:00
goto error;
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
string_list_append(s, opt, attr);
}
break;
case STRING_LIST_CORES_NAMES:
2015-12-11 12:51:17 +00:00
runloop_ctl(RUNLOOP_CTL_CURRENT_CORE_LIST_GET, &core_info_list);
for (i = 0; i < core_info_list_num_info_files(core_info_list); i++)
2015-10-26 18:03:29 +00:00
{
const char *opt = NULL;
2015-12-11 12:51:17 +00:00
core_info = (const core_info_t*)&core_info_list->list[i];
opt = core_info ? core_info->display_name : NULL;
2015-10-26 18:03:29 +00:00
if (!opt)
2015-10-26 18:41:20 +00:00
goto error;
2015-10-26 18:03:29 +00:00
2015-10-26 18:41:20 +00:00
*len += strlen(opt) + 1;
2015-10-26 18:03:29 +00:00
string_list_append(s, opt, attr);
}
break;
2015-10-26 07:39:35 +00:00
case STRING_LIST_NONE:
default:
2015-10-26 18:41:20 +00:00
goto error;
2015-10-26 07:39:35 +00:00
}
2015-10-26 18:41:20 +00:00
return s;
error:
string_list_free(s);
s = NULL;
*len = 0;
2015-10-26 18:41:20 +00:00
return NULL;
}
const char *char_list_new_special(enum string_list_type type, void *data)
{
unsigned len;
size_t list_size;
struct string_list *s = string_list_new_special(type, data, &len, &list_size);
2015-10-26 18:41:20 +00:00
char *options = (len > 0) ? (char*)calloc(len, sizeof(char)): NULL;
2015-10-26 07:39:35 +00:00
2015-10-26 18:41:20 +00:00
if (options && s)
2015-10-26 07:39:35 +00:00
string_list_join_concat(options, len, s, "|");
string_list_free(s);
s = NULL;
return options;
}