diff --git a/Makefile b/Makefile index 88bef5f0d4..5fda198409 100644 --- a/Makefile +++ b/Makefile @@ -11,29 +11,13 @@ endif OBJ := JOYCONFIG_OBJ := +RETROLAUNCH_OBJ := LIBS := DEFINES := -DHAVE_CONFIG_H -DRARCH_INTERNAL -DHAVE_CC_RESAMPLER -DHAVE_OVERLAY DEFINES += -DGLOBAL_CONFIG_DIR='"$(GLOBAL_CONFIG_DIR)"' include Makefile.common -JOYCONFIG_OBJ += tools/retroarch-joyconfig.o \ - conf/config_file.o \ - file_path.o \ - compat/compat.o \ - tools/input_common_joyconfig.o - -RETROLAUNCH_OBJ = tools/retrolaunch/main.o \ - hash.o \ - tools/retrolaunch/parser.o \ - tools/retrolaunch/cd_detect.o \ - compat/fnmatch_rarch.o \ - tools/input_common_launch.o \ - file_path.o \ - compat/compat.o \ - conf/config_file.o \ - settings.o - HEADERS = $(wildcard */*/*.h) $(wildcard */*.h) $(wildcard *.h) ifeq ($(HAVE_DYLIB), 1) diff --git a/Makefile.common b/Makefile.common index 8b742aa7d6..2c027d738e 100644 --- a/Makefile.common +++ b/Makefile.common @@ -91,6 +91,7 @@ OBJ += frontend/frontend.o \ retroarch.o \ file.o \ file_list.o \ + string_list.o \ file_path.o \ hash.o \ driver.o \ @@ -596,3 +597,24 @@ ifeq ($(HAVE_FFMPEG), 1) DEFINES += $(AVCODEC_CFLAGS) $(AVFORMAT_CFLAGS) $(AVUTIL_CFLAGS) $(SWSCALE_CFLAGS) DEFINES += -DHAVE_FFMPEG -Iffmpeg endif + +# Joyconfig / RetroLaunch binaries + +JOYCONFIG_OBJ += tools/retroarch-joyconfig.o \ + conf/config_file.o \ + file_path.o \ + string_list.o \ + compat/compat.o \ + tools/input_common_joyconfig.o + +RETROLAUNCH_OBJ += tools/retrolaunch/main.o \ + hash.o \ + tools/retrolaunch/parser.o \ + tools/retrolaunch/cd_detect.o \ + compat/fnmatch_rarch.o \ + tools/input_common_launch.o \ + file_path.o \ + string_list.o \ + compat/compat.o \ + conf/config_file.o \ + settings.o diff --git a/Makefile.win b/Makefile.win index fb10946d18..ba1127cda4 100644 --- a/Makefile.win +++ b/Makefile.win @@ -69,12 +69,6 @@ LDFLAGS := -L. -static-libgcc include Makefile.common -JOYCONFIG_OBJ += conf/config_file.o \ - tools/retroarch-joyconfig.o \ - compat/compat.o \ - file_path.o \ - tools/input_common_joyconfig.o - HEADERS = $(wildcard */*/*.h) $(wildcard */*.h) $(wildcard *.h) ifneq ($(HOST_PREFIX),) diff --git a/file_path.c b/file_path.c index 245be4b23c..f5d668f3bc 100644 --- a/file_path.c +++ b/file_path.c @@ -1,5 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - 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- @@ -245,158 +246,6 @@ error: return false; } -void string_list_free(struct string_list *list) -{ - size_t i; - if (!list) - return; - - for (i = 0; i < list->size; i++) - free(list->elems[i].data); - free(list->elems); - free(list); -} - -static bool string_list_capacity(struct string_list *list, size_t cap) -{ - rarch_assert(cap > list->size); - - struct string_list_elem *new_data = (struct string_list_elem*) - realloc(list->elems, cap * sizeof(*new_data)); - if (!new_data) - return false; - - list->elems = new_data; - list->cap = cap; - return true; -} - -struct string_list *string_list_new(void) -{ - struct string_list *list = (struct string_list*)calloc(1, sizeof(*list)); - if (!list) - return NULL; - - if (!string_list_capacity(list, 32)) - { - string_list_free(list); - return NULL; - } - - return list; -} - -bool string_list_append(struct string_list *list, const char *elem, - union string_list_elem_attr attr) -{ - if (list->size >= list->cap && - !string_list_capacity(list, list->cap * 2)) - return false; - - char *dup = strdup(elem); - if (!dup) - return false; - - list->elems[list->size].data = dup; - list->elems[list->size].attr = attr; - - list->size++; - return true; -} - -void string_list_set(struct string_list *list, unsigned index, const char *str) -{ - free(list->elems[index].data); - rarch_assert(list->elems[index].data = strdup(str)); -} - -void string_list_join_concat(char *buffer, size_t size, - const struct string_list *list, const char *sep) -{ - size_t len = strlen(buffer); - rarch_assert(len < size); - buffer += len; - size -= len; - - size_t i; - for (i = 0; i < list->size; i++) - { - strlcat(buffer, list->elems[i].data, size); - if ((i + 1) < list->size) - strlcat(buffer, sep, size); - } -} - -struct string_list *string_split(const char *str, const char *delim) -{ - char *copy = NULL; - const char *tmp = NULL; - - struct string_list *list = string_list_new(); - if (!list) - goto error; - - copy = strdup(str); - if (!copy) - goto error; - - char *save; - tmp = strtok_r(copy, delim, &save); - while (tmp) - { - union string_list_elem_attr attr; - memset(&attr, 0, sizeof(attr)); - - if (!string_list_append(list, tmp, attr)) - goto error; - - tmp = strtok_r(NULL, delim, &save); - } - - free(copy); - return list; - -error: - string_list_free(list); - free(copy); - return NULL; -} - -bool string_list_find_elem(const struct string_list *list, const char *elem) -{ - size_t i; - if (!list) - return false; - - for (i = 0; i < list->size; i++) - { - if (strcasecmp(list->elems[i].data, elem) == 0) - return true; - } - - return false; -} - -bool string_list_find_elem_prefix(const struct string_list *list, - const char *prefix, const char *elem) -{ - size_t i; - if (!list) - return false; - - char prefixed[PATH_MAX]; - snprintf(prefixed, sizeof(prefixed), "%s%s", prefix, elem); - - for (i = 0; i < list->size; i++) - { - if (strcasecmp(list->elems[i].data, elem) == 0 || - strcasecmp(list->elems[i].data, prefixed) == 0) - return true; - } - - return false; -} - const char *path_get_extension(const char *path) { const char *ext = strrchr(path_basename(path), '.'); diff --git a/file_path.h b/file_path.h index cd5f9123a7..b053ff72a0 100644 --- a/file_path.h +++ b/file_path.h @@ -1,5 +1,6 @@ /* RetroArch - A frontend for libretro. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2014 - 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- @@ -21,6 +22,7 @@ #include #include #include +#include "string_list.h" #ifdef __cplusplus extern "C" { @@ -48,44 +50,12 @@ bool read_file_string(const char *path, char **buf); bool write_file(const char *path, const void *buf, size_t size); bool write_empty_file(const char *path); -union string_list_elem_attr -{ - bool b; - int i; - void *p; -}; - -struct string_list_elem -{ - char *data; - union string_list_elem_attr attr; -}; - -struct string_list -{ - struct string_list_elem *elems; - size_t size; - size_t cap; -}; - struct string_list *compressed_file_list_new(const char *filename, const char* ext); struct string_list *dir_list_new(const char *dir, const char *ext, bool include_dirs); void dir_list_sort(struct string_list *list, bool dir_first); void dir_list_free(struct string_list *list); -bool string_list_find_elem(const struct string_list *list, const char *elem); -bool string_list_find_elem_prefix(const struct string_list *list, - const char *prefix, const char *elem); -struct string_list *string_split(const char *str, const char *delim); -struct string_list *string_list_new(void); -bool string_list_append(struct string_list *list, const char *elem, - union string_list_elem_attr attr); -void string_list_free(struct string_list *list); -void string_list_join_concat(char *buffer, size_t size, - const struct string_list *list, const char *sep); -void string_list_set(struct string_list *list, unsigned index, - const char *str); /* path_is_compressed_file also means: The compressed file is supported */ bool path_is_compressed_file(const char *path); diff --git a/griffin/griffin.c b/griffin/griffin.c index bd23cf49de..4062a4f032 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -524,6 +524,7 @@ DYNAMIC FILE ============================================================ */ #include "../file.c" +#include "../string_list.c" #include "../file_path.c" #include "../file_list.c"