summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2007-12-02 18:02:18 +0100
committerSebastien Helleu <flashcode@flashtux.org>2007-12-02 18:02:18 +0100
commitfab33dc4df8dfd717012f046987b138e0af5b22f (patch)
tree604577ae7586baa19c2d9f282edb7b875d481c72 /src/core
parent5c579ec3b88e61a4f6f61e7dc8cbf9621a1ec2f5 (diff)
downloadweechat-fab33dc4df8dfd717012f046987b138e0af5b22f.zip
Added config files management in plugins API
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-config-file.c45
-rw-r--r--src/core/wee-config-file.h18
-rw-r--r--src/core/wee-config.c12
3 files changed, 57 insertions, 18 deletions
diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c
index 572de2142..4e4360b73 100644
--- a/src/core/wee-config-file.c
+++ b/src/core/wee-config-file.c
@@ -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;
@@ -393,6 +394,42 @@ config_file_search_option (struct t_config_file *config_file,
}
/*
+ * 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
*/
diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h
index 9254cc11c..b0e852452 100644
--- a/src/core/wee-config-file.h
+++ b/src/core/wee-config-file.h
@@ -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 *);
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index e8fb7fe69..ba599f13b 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -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 */