From 08a97a4ca32a9f2d2abae60c460ddeb3e248f0da Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 26 Oct 2015 08:39:35 +0100 Subject: [PATCH] Create string_list_special.c --- Makefile.common | 1 + griffin/griffin.c | 1 + menu/menu_driver.c | 32 ++------------------- string_list_special.c | 66 +++++++++++++++++++++++++++++++++++++++++++ string_list_special.h | 27 ++++++++++++++++++ 5 files changed, 98 insertions(+), 29 deletions(-) create mode 100644 string_list_special.c create mode 100644 string_list_special.h diff --git a/Makefile.common b/Makefile.common index 696caae392..e6f346389a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -137,6 +137,7 @@ OBJ += frontend/frontend.o \ libretro-common/string/stdstring.o \ libretro-common/memmap/memalign.o \ dir_list_special.o \ + string_list_special.o \ file_ops.o \ libretro-common/file/nbio/nbio_stdio.o \ libretro-common/file/file_path.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 56eecd9f79..bbbd69e16d 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -608,6 +608,7 @@ FILE #include "../libretro-common/file/retro_file.c" #include "../libretro-common/file/retro_stat.c" #include "../dir_list_special.c" +#include "../string_list_special.c" #include "../libretro-common/string/string_list.c" #include "../libretro-common/string/stdstring.c" #include "../file_ops.c" diff --git a/menu/menu_driver.c b/menu/menu_driver.c index fe1e2c7768..b934cc818f 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -15,11 +15,11 @@ */ #include -#include #include "menu.h" #include "menu_display.h" #include "../general.h" +#include "../string_list_special.h" static bool menu_alive = false; @@ -85,35 +85,9 @@ const char *menu_driver_find_ident(int idx) * Returns: string listing of all menu driver names, * separated by '|'. **/ -const char* config_get_menu_driver_options(void) +const char *config_get_menu_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; menu_driver_find_handle(i); i++) - { - const char *opt = menu_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_join_concat(options, options_len, options_l, "|"); - - string_list_free(options_l); - options_l = NULL; - - return options; + return string_list_special_new(STRING_LIST_MENU_DRIVERS); } void find_menu_driver(void) diff --git a/string_list_special.c b/string_list_special.c new file mode 100644 index 0000000000..e0913d7d5e --- /dev/null +++ b/string_list_special.c @@ -0,0 +1,66 @@ +/* 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 . + */ + +#include +#include + +#include "string_list_special.h" + +#ifdef HAVE_MENU +#include "menu/menu_driver.h" +#endif + +const char *string_list_special_new(enum string_list_type type) +{ + union string_list_elem_attr attr; + unsigned i; + char *options = NULL; + int len = 0; + struct string_list *s = string_list_new(); + + attr.i = 0; + + 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); + len += strlen(opt) + 1; + + string_list_append(s, opt, attr); + } + break; +#endif + case STRING_LIST_NONE: + default: + goto end; + } + + options = (char*)calloc(len, sizeof(char)); + + if (options) + string_list_join_concat(options, len, s, "|"); + +end: + string_list_free(s); + s = NULL; + + return options; +} diff --git a/string_list_special.h b/string_list_special.h new file mode 100644 index 0000000000..fba7696955 --- /dev/null +++ b/string_list_special.h @@ -0,0 +1,27 @@ +/* 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 . + */ + +#ifndef _STRING_LIST_SPECIAL_H +#define _STRING_LIST_SPECIAL_H + +enum string_list_type +{ + STRING_LIST_NONE = 0, + STRING_LIST_MENU_DRIVERS +}; + +const char *string_list_special_new(enum string_list_type type); + +#endif