diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-03 21:09:51 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-28 15:13:29 +0100 |
commit | d274eb4be44eac6d9bf30774ef90224b85cd4e2b (patch) | |
tree | 53b16b90d3364d7d7a4229c554ff846785043ccb | |
parent | 347c3f321466af6a7e057701693e6547b7d47d95 (diff) | |
download | weechat-d274eb4be44eac6d9bf30774ef90224b85cd4e2b.zip |
core: add priority in config file (issue #1872)
Priority is now allowed in function config_file_new, parameter `name`, with the
same format as hooks: "priority|name" (for example: "2000|test").
If not specified, the default priority is 1000.
-rw-r--r-- | src/core/wee-config-file.c | 22 | ||||
-rw-r--r-- | src/core/wee-config-file.h | 4 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 6311f020e..3fa2f5b8b 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -121,36 +121,40 @@ config_file_new (struct t_weechat_plugin *plugin, const char *name, void *callback_reload_data) { struct t_config_file *new_config_file; + const char *ptr_name; char *filename; - int length; + int priority, length; - if (!name) + string_get_priority_and_name (name, &priority, &ptr_name, + CONFIG_PRIORITY_DEFAULT); + + if (!ptr_name || !ptr_name[0]) return NULL; /* two configuration files can not have same name */ - if (config_file_search (name)) + if (config_file_search (ptr_name)) return NULL; new_config_file = malloc (sizeof (*new_config_file)); if (new_config_file) { new_config_file->plugin = plugin; - new_config_file->name = strdup (name); + new_config_file->priority = priority; + new_config_file->name = strdup (ptr_name); if (!new_config_file->name) { free (new_config_file); return NULL; } - length = strlen (name) + 8 + 1; + new_config_file->filename = NULL; + length = strlen (ptr_name) + 8 + 1; filename = malloc (length); if (filename) { - snprintf (filename, length, "%s.conf", name); + snprintf (filename, length, "%s.conf", ptr_name); new_config_file->filename = strdup (filename); free (filename); } - else - new_config_file->filename = strdup (name); if (!new_config_file->filename) { free (new_config_file->name); @@ -3233,6 +3237,7 @@ config_file_hdata_config_file_cb (const void *pointer, void *data, if (hdata) { HDATA_VAR(struct t_config_file, plugin, POINTER, 0, NULL, "plugin"); + HDATA_VAR(struct t_config_file, priority, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_config_file, name, STRING, 0, NULL, NULL); HDATA_VAR(struct t_config_file, filename, STRING, 0, NULL, NULL); HDATA_VAR(struct t_config_file, file, POINTER, 0, NULL, NULL); @@ -3546,6 +3551,7 @@ config_file_print_log () log_printf (" plugin . . . . . . . . : 0x%lx ('%s')", ptr_config_file->plugin, plugin_get_name (ptr_config_file->plugin)); + log_printf (" priority . . . . . . . : %d", ptr_config_file->priority); log_printf (" name . . . . . . . . . : '%s'", ptr_config_file->name); log_printf (" filename . . . . . . . : '%s'", ptr_config_file->filename); log_printf (" file . . . . . . . . . : 0x%lx", ptr_config_file->file); diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index 05b074814..c0ab4dce2 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -23,6 +23,8 @@ #include <stdio.h> +#define CONFIG_PRIORITY_DEFAULT 1000 + #define CONFIG_BOOLEAN(option) (*((int *)((option)->value))) #define CONFIG_BOOLEAN_DEFAULT(option) (*((int *)((option)->default_value))) @@ -46,6 +48,8 @@ struct t_config_option; struct t_config_file { struct t_weechat_plugin *plugin; /* plugin which created this cfg */ + int priority; /* config files are sorted by */ + /* priority then name */ char *name; /* name (example: "weechat") */ char *filename; /* filename (without path) */ /* (example: "weechat.conf") */ |