mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 04:16:38 +02:00
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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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") */
|
||||
|
||||
Reference in New Issue
Block a user