mirror of
https://github.com/weechat/weechat.git
synced 2026-07-08 01:05:41 +02:00
Added config files management in plugins API
This commit is contained in:
@@ -45,7 +45,7 @@ struct t_config_file *last_config_file = NULL;
|
||||
*/
|
||||
|
||||
struct t_config_file *
|
||||
config_file_new (char *filename)
|
||||
config_file_new (void *plugin, char *filename)
|
||||
{
|
||||
struct t_config_file *new_config_file;
|
||||
|
||||
@@ -55,6 +55,7 @@ config_file_new (char *filename)
|
||||
new_config_file = (struct t_config_file *)malloc (sizeof (struct t_config_file));
|
||||
if (new_config_file)
|
||||
{
|
||||
new_config_file->plugin = plugin;
|
||||
new_config_file->filename = strdup (filename);
|
||||
new_config_file->file = NULL;
|
||||
new_config_file->sections = NULL;
|
||||
@@ -78,9 +79,9 @@ config_file_new (char *filename)
|
||||
|
||||
struct t_config_section *
|
||||
config_file_new_section (struct t_config_file *config_file, char *name,
|
||||
void (*callback_read)(struct t_config_file *, char *, char *),
|
||||
void (*callback_write)(struct t_config_file *),
|
||||
void (*callback_write_default)(struct t_config_file *))
|
||||
void (*callback_read)(void *, char *, char *),
|
||||
void (*callback_write)(void *),
|
||||
void (*callback_write_default)(void *))
|
||||
{
|
||||
struct t_config_section *new_section;
|
||||
|
||||
@@ -392,6 +393,42 @@ config_file_search_option (struct t_config_file *config_file,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_option_valid_for_plugin: check if an option pointer exists for a plugin
|
||||
* return 1 if option exists for plugin
|
||||
* 0 if option is not found for plugin
|
||||
*/
|
||||
|
||||
int
|
||||
config_file_option_valid_for_plugin (void *plugin,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
struct t_config_file *ptr_config;
|
||||
struct t_config_section *ptr_section;
|
||||
struct t_config_option *ptr_option;
|
||||
|
||||
for (ptr_config = config_files; ptr_config;
|
||||
ptr_config = ptr_config->next_config)
|
||||
{
|
||||
if (ptr_config->plugin == (struct t_weechat_plugin *)plugin)
|
||||
{
|
||||
for (ptr_section = ptr_config->sections; ptr_section;
|
||||
ptr_section = ptr_section->next_section)
|
||||
{
|
||||
for (ptr_option = ptr_section->options; ptr_option;
|
||||
ptr_option = ptr_option->next_option)
|
||||
{
|
||||
if (ptr_option == option)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* option not found */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* config_file_string_boolean_value: return boolean value of string
|
||||
* return -1 if error
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
struct t_config_file
|
||||
{
|
||||
struct t_weechat_plugin *plugin; /* plugin which created this cfg */
|
||||
char *filename; /* config filename (without path)*/
|
||||
FILE *file; /* file pointer */
|
||||
struct t_config_section *sections; /* config sections */
|
||||
@@ -49,12 +50,11 @@ struct t_config_section
|
||||
{
|
||||
char *name; /* section name */
|
||||
void (*callback_read) /* called when unknown option */
|
||||
(struct t_config_file *, /* is read from config file */
|
||||
char *, char *);
|
||||
(void *, char *, char *); /* is read from config file */
|
||||
void (*callback_write) /* called to write special */
|
||||
(struct t_config_file *); /* options in config file */
|
||||
(void *); /* options in config file */
|
||||
void (*callback_write_default) /* called to write default */
|
||||
(struct t_config_file *); /* options in config file */
|
||||
(void *); /* options in config file */
|
||||
struct t_config_option *options; /* options in section */
|
||||
struct t_config_option *last_option; /* last option in section */
|
||||
struct t_config_section *prev_section; /* link to previous section */
|
||||
@@ -84,12 +84,12 @@ struct t_config_option
|
||||
struct t_config_option *next_option; /* link to next option */
|
||||
};
|
||||
|
||||
extern struct t_config_file *config_file_new (char *);
|
||||
extern struct t_config_file *config_file_new (void *, char *);
|
||||
extern struct t_config_section *config_file_new_section (struct t_config_file *,
|
||||
char *,
|
||||
void (*)(struct t_config_file *, char *, char *),
|
||||
void (*)(struct t_config_file *),
|
||||
void (*)(struct t_config_file *));
|
||||
void (*)(void *, char *, char *),
|
||||
void (*)(void *),
|
||||
void (*)(void *));
|
||||
extern struct t_config_section *config_file_search_section (struct t_config_file *,
|
||||
char *);
|
||||
extern struct t_config_option *config_file_new_option_boolean (struct t_config_section *,
|
||||
@@ -117,6 +117,8 @@ extern struct t_config_option *config_file_new_option_color (struct t_config_sec
|
||||
extern struct t_config_option *config_file_search_option (struct t_config_file *,
|
||||
struct t_config_section *,
|
||||
char *);
|
||||
extern int config_file_option_valid_for_plugin (void *, struct t_config_option *);
|
||||
extern int config_file_string_boolean_value (char *);
|
||||
extern int config_file_option_set (struct t_config_option *, char *);
|
||||
extern int config_file_option_reset (struct t_config_option *);
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ config_change_nicks_colors ()
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_read_alias (struct t_config_file *config_file,
|
||||
config_weechat_read_alias (void *config_file,
|
||||
char *option_name, char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
@@ -343,7 +343,7 @@ config_weechat_read_alias (struct t_config_file *config_file,
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_read_key (struct t_config_file *config_file,
|
||||
config_weechat_read_key (void *config_file,
|
||||
char *option_name, char *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
@@ -368,7 +368,7 @@ config_weechat_read_key (struct t_config_file *config_file,
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_write_alias (struct t_config_file *config_file)
|
||||
config_weechat_write_alias (void *config_file)
|
||||
{
|
||||
struct alias *ptr_alias;
|
||||
char *string;
|
||||
@@ -396,7 +396,7 @@ config_weechat_write_alias (struct t_config_file *config_file)
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_write_alias_default_values (struct t_config_file *config_file)
|
||||
config_weechat_write_alias_default_values (void *config_file)
|
||||
{
|
||||
config_file_write_line (config_file, "SAY", "\"msg *\"");
|
||||
config_file_write_line (config_file, "BYE", "\"quit\"");
|
||||
@@ -431,7 +431,7 @@ config_weechat_write_alias_default_values (struct t_config_file *config_file)
|
||||
*/
|
||||
|
||||
void
|
||||
config_weechat_write_keys (struct t_config_file *config_file)
|
||||
config_weechat_write_keys (void *config_file)
|
||||
{
|
||||
t_gui_key *ptr_key;
|
||||
char *expanded_name, *function_name, *string;
|
||||
@@ -493,7 +493,7 @@ config_weechat_init ()
|
||||
{
|
||||
struct t_config_section *section;
|
||||
|
||||
weechat_config = config_file_new (WEECHAT_CONFIG_FILENAME);
|
||||
weechat_config = config_file_new (NULL, WEECHAT_CONFIG_FILENAME);
|
||||
if (weechat_config)
|
||||
{
|
||||
/* look */
|
||||
|
||||
@@ -141,8 +141,8 @@ demo_print_list (void *list, char *item_name)
|
||||
case 'i':
|
||||
weechat_printf (NULL, " %s: %d",
|
||||
argv[j] + 2,
|
||||
weechat_list_int (list,
|
||||
argv[j] + 2));
|
||||
weechat_list_integer (list,
|
||||
argv[j] + 2));
|
||||
break;
|
||||
case 's':
|
||||
weechat_printf (NULL, " %s: %s",
|
||||
|
||||
+280
-136
File diff suppressed because it is too large
Load Diff
@@ -44,6 +44,27 @@ extern int plugin_api_mkdir_home (struct t_weechat_plugin *, char *);
|
||||
extern void plugin_api_exec_on_files (struct t_weechat_plugin *, char *,
|
||||
int (*)(char *));
|
||||
|
||||
/* config */
|
||||
extern struct t_config_file *config_new (struct t_weechat_plugin *, char *);
|
||||
extern struct t_config_section *config_new_section (struct t_weechat_plugin *,
|
||||
void *, char *,
|
||||
void (*)(void *, char *, char *),
|
||||
void (*)(void *),
|
||||
void (*)(void *));
|
||||
extern struct t_config_option *config_new_option (struct t_weechat_plugin *,
|
||||
void *, char *, char *,
|
||||
char *, char *, int, int,
|
||||
char *, void (*)());
|
||||
extern char config_boolean (struct t_weechat_plugin *, void *);
|
||||
extern int config_integer (struct t_weechat_plugin *, void *);
|
||||
extern char *config_string (struct t_weechat_plugin *, void *);
|
||||
extern int config_color (struct t_weechat_plugin *, void *);
|
||||
extern char *plugin_api_config_get (struct t_weechat_plugin *, char *);
|
||||
extern int plugin_api_config_set (struct t_weechat_plugin *, char *, char *);
|
||||
extern char *plugin_api_plugin_config_get (struct t_weechat_plugin *, char *);
|
||||
extern int plugin_api_plugin_config_set (struct t_weechat_plugin *, char *,
|
||||
char *);
|
||||
|
||||
/* display */
|
||||
extern char *plugin_api_prefix (struct t_weechat_plugin *, char *);
|
||||
extern char *plugin_api_color (struct t_weechat_plugin *, char *);
|
||||
@@ -109,19 +130,12 @@ extern int plugin_api_list_next (struct t_weechat_plugin *,
|
||||
extern int plugin_api_list_prev (struct t_weechat_plugin *,
|
||||
void *);
|
||||
extern char *plugin_api_list_fields (struct t_weechat_plugin *, void *);
|
||||
extern int plugin_api_list_int (struct t_weechat_plugin *, void *, char *);
|
||||
extern int plugin_api_list_integer (struct t_weechat_plugin *, void *, char *);
|
||||
extern char *plugin_api_list_string (struct t_weechat_plugin *, void *, char *);
|
||||
extern void *plugin_api_list_pointer (struct t_weechat_plugin *, void *, char *);
|
||||
extern time_t plugin_api_list_time (struct t_weechat_plugin *, void *, char *);
|
||||
extern void plugin_api_list_free (struct t_weechat_plugin *, void *);
|
||||
|
||||
/* config */
|
||||
extern char *plugin_api_config_get (struct t_weechat_plugin *, char *);
|
||||
extern int plugin_api_config_set (struct t_weechat_plugin *, char *, char *);
|
||||
extern char *plugin_api_plugin_config_get (struct t_weechat_plugin *, char *);
|
||||
extern int plugin_api_plugin_config_set (struct t_weechat_plugin *, char *,
|
||||
char *);
|
||||
|
||||
/* log */
|
||||
extern void plugin_api_log (struct t_weechat_plugin *, char *, char *,
|
||||
char *, ...);
|
||||
|
||||
@@ -289,8 +289,7 @@ plugin_config_free_all ()
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_config_read_option (struct t_config_file *config_file,
|
||||
char *option_name, char *value)
|
||||
plugin_config_read_option (void *config_file, char *option_name, char *value)
|
||||
{
|
||||
char *value2;
|
||||
|
||||
@@ -309,7 +308,7 @@ plugin_config_read_option (struct t_config_file *config_file,
|
||||
*/
|
||||
|
||||
void
|
||||
plugin_config_write_options (struct t_config_file *config_file)
|
||||
plugin_config_write_options (void *config_file)
|
||||
{
|
||||
struct t_config_option *ptr_option;
|
||||
|
||||
@@ -329,7 +328,7 @@ plugin_config_write_options (struct t_config_file *config_file)
|
||||
void
|
||||
plugin_config_init ()
|
||||
{
|
||||
plugin_config = config_file_new (PLUGIN_CONFIG_FILENAME);
|
||||
plugin_config = config_file_new (NULL, PLUGIN_CONFIG_FILENAME);
|
||||
if (plugin_config)
|
||||
{
|
||||
config_file_new_section (plugin_config, "plugin",
|
||||
|
||||
@@ -93,12 +93,12 @@ plugin_list_new_item (struct t_plugin_list *list)
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_list_new_var_int: create a new integer variable in an item
|
||||
* plugin_list_new_var_integer: create a new integer variable in an item
|
||||
*/
|
||||
|
||||
struct t_plugin_list_var *
|
||||
plugin_list_new_var_int (struct t_plugin_list_item *item,
|
||||
char *name, int value)
|
||||
plugin_list_new_var_integer (struct t_plugin_list_item *item,
|
||||
char *name, int value)
|
||||
{
|
||||
struct t_plugin_list_var *new_var;
|
||||
|
||||
@@ -334,11 +334,11 @@ plugin_list_get_fields (struct t_plugin_list *list)
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin_list_get_int: get an integer variable value in current list item
|
||||
* plugin_list_get_integer: get an integer variable value in current list item
|
||||
*/
|
||||
|
||||
int
|
||||
plugin_list_get_int (struct t_plugin_list *list, char *var)
|
||||
plugin_list_get_integer (struct t_plugin_list *list, char *var)
|
||||
{
|
||||
struct t_plugin_list_var *ptr_var;
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ extern struct t_plugin_list *last_plugin_list;
|
||||
|
||||
extern struct t_plugin_list *plugin_list_new ();
|
||||
extern struct t_plugin_list_item *plugin_list_new_item (struct t_plugin_list *);
|
||||
extern struct t_plugin_list_var *plugin_list_new_var_int (struct t_plugin_list_item *,
|
||||
char *, int);
|
||||
extern struct t_plugin_list_var *plugin_list_new_var_integer (struct t_plugin_list_item *,
|
||||
char *, int);
|
||||
extern struct t_plugin_list_var *plugin_list_new_var_string (struct t_plugin_list_item *,
|
||||
char *, char *);
|
||||
extern struct t_plugin_list_var *plugin_list_new_var_pointer (struct t_plugin_list_item *,
|
||||
@@ -79,7 +79,7 @@ extern int plugin_list_valid (struct t_plugin_list *);
|
||||
extern struct t_plugin_list_item *plugin_list_next_item (struct t_plugin_list *);
|
||||
extern struct t_plugin_list_item *plugin_list_prev_item (struct t_plugin_list *);
|
||||
extern char *plugin_list_get_fields (struct t_plugin_list *);
|
||||
extern int plugin_list_get_int (struct t_plugin_list *, char *);
|
||||
extern int plugin_list_get_integer (struct t_plugin_list *, char *);
|
||||
extern char *plugin_list_get_string (struct t_plugin_list *, char *);
|
||||
extern void *plugin_list_get_pointer (struct t_plugin_list *, char *);
|
||||
extern time_t plugin_list_get_time (struct t_plugin_list *, char *);
|
||||
|
||||
@@ -269,7 +269,7 @@ plugin_load (char *filename)
|
||||
new_plugin->list_next = &plugin_api_list_next;
|
||||
new_plugin->list_prev = &plugin_api_list_prev;
|
||||
new_plugin->list_fields = &plugin_api_list_fields;
|
||||
new_plugin->list_int = &plugin_api_list_int;
|
||||
new_plugin->list_integer = &plugin_api_list_integer;
|
||||
new_plugin->list_string = &plugin_api_list_string;
|
||||
new_plugin->list_pointer = &plugin_api_list_pointer;
|
||||
new_plugin->list_time = &plugin_api_list_time;
|
||||
|
||||
+159
-100
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user