From 1d53f3ca29bfb0efa94ee9064ef7decbae923143 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 25 Aug 2020 18:38:12 +0200 Subject: [PATCH] Move static functions to the top --- libretro-common/file/config_file.c | 107 +++++++++++++++-------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 9df53eff0d..b2757ae971 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -570,6 +570,60 @@ static bool config_file_parse_line(config_file_t *conf, return true; } +static int config_file_from_string_internal( + struct config_file *conf, + char *from_string, + const char *path) +{ + char *lines = from_string; + char *save_ptr = NULL; + char *line = NULL; + + if (!string_is_empty(path)) + conf->path = strdup(path); + if (string_is_empty(lines)) + return 0; + + /* Get first line of config file */ + line = strtok_r(lines, "\n", &save_ptr); + + while (line) + { + struct config_entry_list *list = (struct config_entry_list*) + malloc(sizeof(*list)); + + if (!list) + return -1; + + list->readonly = false; + list->key = NULL; + list->value = NULL; + list->next = NULL; + + /* Parse current line */ + if ( + !string_is_empty(line) + && config_file_parse_line(conf, list, line, NULL)) + { + if (conf->entries) + conf->tail->next = list; + else + conf->entries = list; + + conf->tail = list; + } + + if (list != conf->tail) + free(list); + + /* Get next line of config file */ + line = strtok_r(NULL, "\n", &save_ptr); + } + + return 0; +} + + bool config_file_deinitialize(config_file_t *conf) { struct config_include_list *inc_tmp = NULL; @@ -637,59 +691,6 @@ bool config_append_file(config_file_t *conf, const char *path) return true; } -static int config_file_from_string_internal( - struct config_file *conf, - char *from_string, - const char *path) -{ - char *lines = from_string; - char *save_ptr = NULL; - char *line = NULL; - - if (!string_is_empty(path)) - conf->path = strdup(path); - if (string_is_empty(lines)) - return 0; - - /* Get first line of config file */ - line = strtok_r(lines, "\n", &save_ptr); - - while (line) - { - struct config_entry_list *list = (struct config_entry_list*) - malloc(sizeof(*list)); - - if (!list) - return -1; - - list->readonly = false; - list->key = NULL; - list->value = NULL; - list->next = NULL; - - /* Parse current line */ - if ( - !string_is_empty(line) - && config_file_parse_line(conf, list, line, NULL)) - { - if (conf->entries) - conf->tail->next = list; - else - conf->entries = list; - - conf->tail = list; - } - - if (list != conf->tail) - free(list); - - /* Get next line of config file */ - line = strtok_r(NULL, "\n", &save_ptr); - } - - return 0; -} - config_file_t *config_file_new_from_string(char *from_string, const char *path) {