Skip to content

Commit

Permalink
(config_file) Use flags
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Sep 8, 2024
1 parent f4e2fbb commit 9efb498
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cheat_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ bool cheat_manager_save(
if (!(conf = config_file_new_alloc()))
return false;

conf->guaranteed_no_duplicates = true;
conf->flags |= CONF_FILE_FLG_GUARANTEED_NO_DUPLICATES;

config_set_int(conf, "cheats", cheat_st->size);

Expand Down
8 changes: 4 additions & 4 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -5534,7 +5534,7 @@ int8_t config_save_overrides(enum override_type type,
tmp_i = sizeof(settings->paths) / sizeof(settings->paths.placeholder);
path_overrides = populate_settings_path(overrides, &tmp_i);

if (conf->modified)
if (conf->flags & CONF_FILE_FLG_MODIFIED)
RARCH_LOG("[Overrides]: Looking for changed settings..\n");

if (conf)
Expand Down Expand Up @@ -5748,12 +5748,12 @@ int8_t config_save_overrides(enum override_type type,
break;
}

if (!conf->modified && !remove)
if (!(conf->flags & CONF_FILE_FLG_MODIFIED) && !remove)
ret = -1;

if (!string_is_empty(override_path))
{
if (!conf->modified && !remove)
if (!(conf->flags & CONF_FILE_FLG_MODIFIED) && !remove)
if (path_is_valid(override_path))
remove = true;

Expand All @@ -5767,7 +5767,7 @@ int8_t config_save_overrides(enum override_type type,
"Deleted", override_path);
}
}
else if (conf->modified)
else if (conf->flags & CONF_FILE_FLG_MODIFIED)
{
ret = config_file_write(conf, override_path, true);

Expand Down
6 changes: 3 additions & 3 deletions gfx/video_shader_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1601,9 +1601,9 @@ static bool video_shader_write_referenced_preset(
/* Add the reference path to the config */
config_file_add_reference(conf, path_to_ref);

/* Set modified to true so when you run config_file_write
* it will save a file */
conf->modified = true;
/* Set modified flag to true so when
* you run config_file_write it will save a file */
conf->flags |= CONF_FILE_FLG_MODIFIED;

/*
Compare the shader to a shader created from the referenced
Expand Down
29 changes: 14 additions & 15 deletions libretro-common/file/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static char *config_file_extract_value(char *line)
return strdup(value);
}

/* Note 2: This is an unrolled strldup call
/* Note 2: This is an unrolled strldup call
* to avoid an unnecessary dependency -
* call is strldup("", sizeof(""))
**/
Expand Down Expand Up @@ -464,8 +464,8 @@ static int config_file_load_internal(
continue;
}

if (
!string_is_empty(line)
if (
!string_is_empty(line)
&& config_file_parse_line(conf, list, line, cb))
{
if (conf->entries)
Expand Down Expand Up @@ -522,7 +522,7 @@ static bool config_file_parse_line(config_file_t *conf,
bool reference_found = string_starts_with_size(comment,
"reference ", STRLEN_CONST("reference "));

/* All comments except those starting with the include or
/* All comments except those starting with the include or
* reference directive are ignored */
if (!include_found && !reference_found)
return false;
Expand Down Expand Up @@ -708,7 +708,7 @@ static int config_file_from_string_internal(
/* Get next line of config file */
line = strtok_r(NULL, "\n", &save_ptr);
}

return 0;
}

Expand Down Expand Up @@ -826,7 +826,7 @@ config_file_t *config_file_new_from_string(char *from_string,
const char *path)
{
struct config_file *conf = config_file_new_alloc();
if ( conf
if ( conf
&& config_file_from_string_internal(
conf, from_string, path) != -1)
return conf;
Expand Down Expand Up @@ -934,8 +934,7 @@ void config_file_initialize(struct config_file *conf)
conf->references = NULL;
conf->includes = NULL;
conf->include_depth = 0;
conf->guaranteed_no_duplicates = false;
conf->modified = false;
conf->flags = 0;
}

config_file_t *config_file_new_alloc(void)
Expand Down Expand Up @@ -1195,7 +1194,7 @@ bool config_get_path(config_file_t *conf, const char *key,

/**
* config_get_bool:
*
*
* Extracts a boolean from config.
* Valid boolean true are "true" and "1". Valid false are "false" and "0".
* Other values will be treated as an error.
Expand Down Expand Up @@ -1241,7 +1240,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)

last = conf->entries;

if (conf->guaranteed_no_duplicates)
if (conf->flags & CONF_FILE_FLG_GUARANTEED_NO_DUPLICATES)
{
if (conf->last)
last = conf->last;
Expand All @@ -1268,7 +1267,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
* is no longer considered 'read only' */
entry->value = strdup(val);
entry->readonly = false;
conf->modified = true;
conf->flags |= CONF_FILE_FLG_MODIFIED;
return;
}
}
Expand All @@ -1282,7 +1281,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
entry->key = strdup(key);
entry->value = strdup(val);
entry->next = NULL;
conf->modified = true;
conf->flags |= CONF_FILE_FLG_MODIFIED;

if (last)
last->next = entry;
Expand Down Expand Up @@ -1317,7 +1316,7 @@ void config_unset(config_file_t *conf, const char *key)

entry->key = NULL;
entry->value = NULL;
conf->modified = true;
conf->flags |= CONF_FILE_FLG_MODIFIED;
}

void config_set_path(config_file_t *conf, const char *entry, const char *val)
Expand Down Expand Up @@ -1403,7 +1402,7 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort)
if (!conf)
return false;

if (conf->modified)
if (conf->flags & CONF_FILE_FLG_MODIFIED)
{
if (string_is_empty(path))
config_file_dump(conf, stdout, sort);
Expand All @@ -1426,7 +1425,7 @@ bool config_file_write(config_file_t *conf, const char *path, bool sort)

/* Only update modified flag if config file
* is actually written to disk */
conf->modified = false;
conf->flags &= ~CONF_FILE_FLG_MODIFIED;
}
}

Expand Down
11 changes: 8 additions & 3 deletions libretro-common/include/file/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ RETRO_BEGIN_DECLS
base->var = tmp; \
} while(0)

enum config_file_flags
{
CONF_FILE_FLG_MODIFIED = (1 << 0),
CONF_FILE_FLG_GUARANTEED_NO_DUPLICATES = (1 << 1)
};

struct config_file
{
char *path;
Expand All @@ -61,8 +67,7 @@ struct config_file
struct config_include_list *includes;
struct path_linked_list *references;
unsigned include_depth;
bool guaranteed_no_duplicates;
bool modified;
uint8_t flags;
};

typedef struct config_file config_file_t;
Expand Down Expand Up @@ -277,7 +282,7 @@ bool config_get_path(config_file_t *conf, const char *entry, char *s, size_t len

/**
* config_get_bool:
*
*
* Extracts a boolean from config.
* Valid boolean true are "true" and "1". Valid false are "false" and "0".
* Other values will be treated as an error.
Expand Down
2 changes: 1 addition & 1 deletion runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -5239,7 +5239,7 @@ void core_options_flush(void)
* exist (e.g. if it gets deleted manually while
* a core is running) */
if (!path_is_valid(path_core_options))
runloop_st->core_options->conf->modified = true;
runloop_st->core_options->conf->flags |= CONF_FILE_FLG_MODIFIED;

success = config_file_write(runloop_st->core_options->conf,
path_core_options, true);
Expand Down
7 changes: 2 additions & 5 deletions tasks/task_menu_explore.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,9 @@ static void task_menu_explore_init_handler(retro_task_t *task)
}
}

static bool task_menu_explore_init_finder(
retro_task_t *task, void *user_data)
static bool task_menu_explore_init_finder(retro_task_t *task, void *user_data)
{
if (task && task->handler == task_menu_explore_init_handler)
return true;
return false;
return (task && task->handler == task_menu_explore_init_handler);
}

bool task_push_menu_explore_init(const char *directory_playlist,
Expand Down

0 comments on commit 9efb498

Please sign in to comment.