1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 00:03:12 +02:00

Added config files management in plugins API

This commit is contained in:
Sebastien Helleu
2007-12-02 18:02:18 +01:00
parent 5c579ec3b8
commit fab33dc4df
11 changed files with 532 additions and 277 deletions
+41 -4
View File
@@ -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
+10 -8
View File
@@ -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 *);
+6 -6
View File
@@ -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 */