Revert this - was getting crashes in both OSX and MSVC 2003

in config_file.c inside config_get_entry
This commit is contained in:
twinaphex 2018-10-10 23:34:16 +02:00
parent 9862579610
commit 7d0dba3007
6 changed files with 399 additions and 457 deletions

View File

@ -66,7 +66,7 @@ struct config_include_list
}; };
static config_file_t *config_file_new_internal( static config_file_t *config_file_new_internal(
const char *path, unsigned depth, config_file_cb_t *cb); const char *path, unsigned depth);
static int config_sort_compare_func(struct config_entry_list *a, static int config_sort_compare_func(struct config_entry_list *a,
struct config_entry_list *b) struct config_entry_list *b)
@ -267,7 +267,7 @@ static void add_child_list(config_file_t *parent, config_file_t *child)
parent->tail = NULL; parent->tail = NULL;
} }
static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb) static void add_sub_conf(config_file_t *conf, char *path)
{ {
char real_path[PATH_MAX_LENGTH]; char real_path[PATH_MAX_LENGTH];
config_file_t *sub_conf = NULL; config_file_t *sub_conf = NULL;
@ -314,7 +314,7 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb)
#endif #endif
sub_conf = (config_file_t*) sub_conf = (config_file_t*)
config_file_new_internal(real_path, conf->include_depth + 1, cb); config_file_new_internal(real_path, conf->include_depth + 1);
if (!sub_conf) if (!sub_conf)
return; return;
@ -324,7 +324,7 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb)
} }
static bool parse_line(config_file_t *conf, static bool parse_line(config_file_t *conf,
struct config_entry_list *list, char *line, config_file_cb_t *cb) struct config_entry_list *list, char *line)
{ {
char *comment = NULL; char *comment = NULL;
char *key_tmp = NULL; char *key_tmp = NULL;
@ -351,7 +351,7 @@ static bool parse_line(config_file_t *conf,
if (conf->include_depth >= MAX_INCLUDE_DEPTH) if (conf->include_depth >= MAX_INCLUDE_DEPTH)
fprintf(stderr, "!!! #include depth exceeded for config. Might be a cycle.\n"); fprintf(stderr, "!!! #include depth exceeded for config. Might be a cycle.\n");
else else
add_sub_conf(conf, path, cb); add_sub_conf(conf, path);
free(path); free(path);
} }
goto error; goto error;
@ -396,19 +396,18 @@ error:
} }
static config_file_t *config_file_new_internal( static config_file_t *config_file_new_internal(
const char *path, unsigned depth, config_file_cb_t *cb) const char *path, unsigned depth)
{ {
RFILE *file = NULL; RFILE *file = NULL;
struct config_file *conf = (struct config_file*)malloc(sizeof(*conf)); struct config_file *conf = (struct config_file*)malloc(sizeof(*conf));
if (!conf) if (!conf)
return NULL; return NULL;
conf->path = NULL; conf->path = NULL;
conf->entries = NULL; conf->entries = NULL;
conf->tail = NULL; conf->tail = NULL;
conf->includes = NULL; conf->includes = NULL;
conf->include_depth = 0; conf->include_depth = 0;
conf->guaranteed_no_duplicates = false ;
if (!path || !*path) if (!path || !*path)
return conf; return conf;
@ -456,7 +455,7 @@ static config_file_t *config_file_new_internal(
continue; continue;
} }
if (*line && parse_line(conf, list, line, cb)) if (*line && parse_line(conf, list, line))
{ {
if (conf->entries) if (conf->entries)
conf->tail->next = list; conf->tail->next = list;
@ -464,9 +463,6 @@ static config_file_t *config_file_new_internal(
conf->entries = list; conf->entries = list;
conf->tail = list; conf->tail = list;
if (cb != NULL && list->key != NULL && list->value != NULL)
cb->config_file_new_entry_cb(list->key, list->value) ;
} }
free(line); free(line);
@ -555,12 +551,11 @@ config_file_t *config_file_new_from_string(const char *from_string)
if (!from_string) if (!from_string)
return conf; return conf;
conf->path = NULL; conf->path = NULL;
conf->entries = NULL; conf->entries = NULL;
conf->tail = NULL; conf->tail = NULL;
conf->includes = NULL; conf->includes = NULL;
conf->include_depth = 0; conf->include_depth = 0;
conf->guaranteed_no_duplicates = false ;
lines = string_split(from_string, "\n"); lines = string_split(from_string, "\n");
if (!lines) if (!lines)
@ -585,7 +580,7 @@ config_file_t *config_file_new_from_string(const char *from_string)
if (line && conf) if (line && conf)
{ {
if (*line && parse_line(conf, list, line, NULL)) if (*line && parse_line(conf, list, line))
{ {
if (conf->entries) if (conf->entries)
conf->tail->next = list; conf->tail->next = list;
@ -605,13 +600,9 @@ config_file_t *config_file_new_from_string(const char *from_string)
return conf; return conf;
} }
config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb)
{
return config_file_new_internal(path, 0, cb);
}
config_file_t *config_file_new(const char *path) config_file_t *config_file_new(const char *path)
{ {
return config_file_new_internal(path, 0, NULL); return config_file_new_internal(path, 0);
} }
static struct config_entry_list *config_get_entry(const config_file_t *conf, static struct config_entry_list *config_get_entry(const config_file_t *conf,
@ -843,7 +834,7 @@ bool config_get_bool(config_file_t *conf, const char *key, bool *in)
void config_set_string(config_file_t *conf, const char *key, const char *val) void config_set_string(config_file_t *conf, const char *key, const char *val)
{ {
struct config_entry_list *last = conf->entries; struct config_entry_list *last = conf->entries;
struct config_entry_list *entry = conf->guaranteed_no_duplicates?NULL:config_get_entry(conf, key, &last); struct config_entry_list *entry = config_get_entry(conf, key, &last);
if (entry && !entry->readonly) if (entry && !entry->readonly)
{ {

View File

@ -58,7 +58,6 @@ struct config_file
struct config_entry_list *entries; struct config_entry_list *entries;
struct config_entry_list *tail; struct config_entry_list *tail;
unsigned include_depth; unsigned include_depth;
bool guaranteed_no_duplicates;
struct config_include_list *includes; struct config_include_list *includes;
}; };
@ -66,13 +65,6 @@ struct config_file
typedef struct config_file config_file_t; typedef struct config_file config_file_t;
struct config_file_cb
{
void (*config_file_new_entry_cb)(char*, char*);
};
typedef struct config_file_cb config_file_cb_t ;
/* Config file format /* Config file format
* - # are treated as comments. Rest of the line is ignored. * - # are treated as comments. Rest of the line is ignored.
* - Format is: key = value. There can be as many spaces as you like in-between. * - Format is: key = value. There can be as many spaces as you like in-between.
@ -87,11 +79,6 @@ typedef struct config_file_cb config_file_cb_t ;
* NULL path will create an empty config file. */ * NULL path will create an empty config file. */
config_file_t *config_file_new(const char *path); config_file_t *config_file_new(const char *path);
/* Loads a config file. Returns NULL if file doesn't exist.
* NULL path will create an empty config file.
* Includes cb callbacks to run custom code during config file processing.*/
config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb);
/* Load a config file from a string. */ /* Load a config file from a string. */
config_file_t *config_file_new_from_string(const char *from_string); config_file_t *config_file_new_from_string(const char *from_string);
@ -191,4 +178,3 @@ bool config_file_exists(const char *path);
RETRO_END_DECLS RETRO_END_DECLS
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -77,8 +77,7 @@ enum cheat_rumble_type
RUMBLE_TYPE_LT_VALUE, RUMBLE_TYPE_LT_VALUE,
RUMBLE_TYPE_GT_VALUE, RUMBLE_TYPE_GT_VALUE,
RUMBLE_TYPE_INCREASE_BY_VALUE, RUMBLE_TYPE_INCREASE_BY_VALUE,
RUMBLE_TYPE_DECREASE_BY_VALUE, RUMBLE_TYPE_DECREASE_BY_VALUE
RUMBLE_TYPE_END_LIST
}; };
/* Some codes are ridiculously large - over 10000 bytes */ /* Some codes are ridiculously large - over 10000 bytes */
@ -179,8 +178,6 @@ struct cheat_manager
unsigned browse_address; unsigned browse_address;
char working_desc[CHEAT_DESC_SCRATCH_SIZE] ; char working_desc[CHEAT_DESC_SCRATCH_SIZE] ;
char working_code[CHEAT_CODE_SCRATCH_SIZE] ; char working_code[CHEAT_CODE_SCRATCH_SIZE] ;
unsigned int loading_cheat_size;
unsigned int loading_cheat_offset;
}; };
typedef struct cheat_manager cheat_manager_t; typedef struct cheat_manager cheat_manager_t;

View File

@ -45,7 +45,7 @@ RETRO_BEGIN_DECLS
#endif #endif
#ifndef MAX_CHEAT_COUNTERS #ifndef MAX_CHEAT_COUNTERS
#define MAX_CHEAT_COUNTERS 6000 #define MAX_CHEAT_COUNTERS 100
#endif #endif
#define MENU_SETTINGS_CORE_INFO_NONE 0xffff #define MENU_SETTINGS_CORE_INFO_NONE 0xffff

View File

@ -4745,7 +4745,7 @@ static bool setting_append_list(
config_uint_cbs(cheat_manager_state.working_cheat.rumble_type, CHEAT_RUMBLE_TYPE, config_uint_cbs(cheat_manager_state.working_cheat.rumble_type, CHEAT_RUMBLE_TYPE,
setting_uint_action_left_default,setting_uint_action_right_default, setting_uint_action_left_default,setting_uint_action_right_default,
MENU_ENUM_LABEL_RUMBLE_TYPE_DISABLED,&setting_get_string_representation_uint_as_enum, MENU_ENUM_LABEL_RUMBLE_TYPE_DISABLED,&setting_get_string_representation_uint_as_enum,
RUMBLE_TYPE_DISABLED,RUMBLE_TYPE_END_LIST-1,1) ; RUMBLE_TYPE_DISABLED,RUMBLE_TYPE_GT_VALUE,1) ;
(*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint;
config_uint_cbs(cheat_manager_state.working_cheat.rumble_value, CHEAT_RUMBLE_VALUE, config_uint_cbs(cheat_manager_state.working_cheat.rumble_value, CHEAT_RUMBLE_VALUE,