summaryrefslogtreecommitdiff
path: root/src/core/wee-config-file.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-01-03 21:09:51 +0100
committerSébastien Helleu <flashcode@flashtux.org>2023-01-28 15:13:29 +0100
commitd274eb4be44eac6d9bf30774ef90224b85cd4e2b (patch)
tree53b16b90d3364d7d7a4229c554ff846785043ccb /src/core/wee-config-file.c
parent347c3f321466af6a7e057701693e6547b7d47d95 (diff)
downloadweechat-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.
Diffstat (limited to 'src/core/wee-config-file.c')
-rw-r--r--src/core/wee-config-file.c22
1 files changed, 14 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);