diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/plugin-api.c | 92 | ||||
-rw-r--r-- | src/plugins/plugin-api.h | 37 | ||||
-rw-r--r-- | src/plugins/plugin-list.c | 145 | ||||
-rw-r--r-- | src/plugins/plugin-list.h | 6 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 40 |
5 files changed, 302 insertions, 18 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 68566712a..1a6794552 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -849,7 +849,7 @@ plugin_api_list_get_add_buffer_line (struct t_plugin_list *list, /* * plugin_api_list_get: get list with infos about WeeChat structures * WARNING: caller has to free string returned - * by this function after use, with weechat_free() + * by this function after use, with weechat_list_free() */ struct t_plugin_list * @@ -932,6 +932,96 @@ plugin_api_list_get (struct t_weechat_plugin *plugin, char *name, } /* + * plugin_api_list_next: get next item in a list + * if current item pointer is NULL, + * then return first item of list + */ + +struct t_plugin_list_item * +plugin_api_list_next (struct t_weechat_plugin *plugin, void *list) +{ + if (!plugin || !list) + return NULL; + + return plugin_list_next_item ((struct t_plugin_list *)list); +} + +/* + * plugin_api_list_prev: get previousi item in a list + * if current item pointer is NULL, + * then return last item of list + */ + +struct t_plugin_list_item * +plugin_api_list_prev (struct t_weechat_plugin *plugin, void *list) +{ + if (!plugin || !list) + return NULL; + + return plugin_list_prev_item ((struct t_plugin_list *)list); +} + +/* + * plugin_api_list_int: get an integer variable value in an item + */ + +int +plugin_api_list_int (struct t_weechat_plugin *plugin, void *list_item, + char *var) +{ + if (!plugin || !list_item) + return 0; + + return plugin_list_get_int ((struct t_plugin_list_item *)list_item, + var); +} + +/* + * plugin_api_list_string: get a string variable value in an item + */ + +char * +plugin_api_list_string (struct t_weechat_plugin *plugin, void *list_item, + char *var) +{ + if (!plugin || !list_item) + return NULL; + + return plugin_list_get_string ((struct t_plugin_list_item *)list_item, + var); +} + +/* + * plugin_api_list_pointer: get a pointer variable value in an item + */ + +void * +plugin_api_list_pointer (struct t_weechat_plugin *plugin, void *list_item, + char *var) +{ + if (!plugin || !list_item) + return NULL; + + return plugin_list_get_pointer ((struct t_plugin_list_item *)list_item, + var); +} + +/* + * plugin_api_list_time: get a time variable value in an item + */ + +time_t +plugin_api_list_time (struct t_weechat_plugin *plugin, void *list_item, + char *var) +{ + if (!plugin || !list_item) + return 0; + + return plugin_list_get_time ((struct t_plugin_list_item *)list_item, + var); +} + +/* * plugin_api_get_config_str_value: return string value for any option * This function should never be called directly * (only used by weechat_get_config) diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index aa4664726..551da324f 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -22,14 +22,20 @@ /* strings */ extern void plugin_api_charset_set (struct t_weechat_plugin *, char *); -extern char *plugin_api_iconv_to_internal (struct t_weechat_plugin *, char *, char *); -extern char *plugin_api_iconv_from_internal (struct t_weechat_plugin *, char *, char *); +extern char *plugin_api_iconv_to_internal (struct t_weechat_plugin *, char *, + char *); +extern char *plugin_api_iconv_from_internal (struct t_weechat_plugin *, char *, + char *); extern char *plugin_api_gettext (struct t_weechat_plugin *, char *); -extern char *plugin_api_ngettext (struct t_weechat_plugin *, char *, char *, int); +extern char *plugin_api_ngettext (struct t_weechat_plugin *, char *, char *, + int); extern int plugin_api_strcasecmp (struct t_weechat_plugin *,char *, char *); -extern int plugin_api_strncasecmp (struct t_weechat_plugin *,char *, char *, int); -extern char **plugin_api_explode_string (struct t_weechat_plugin *, char *, char *, int, int *); -extern void plugin_api_free_exploded_string (struct t_weechat_plugin *, char **); +extern int plugin_api_strncasecmp (struct t_weechat_plugin *,char *, char *, + int); +extern char **plugin_api_explode_string (struct t_weechat_plugin *, char *, + char *, int, int *); +extern void plugin_api_free_exploded_string (struct t_weechat_plugin *, + char **); /* directories */ extern int plugin_api_mkdir_home (struct t_weechat_plugin *, char *); @@ -84,13 +90,28 @@ extern void plugin_api_command (struct t_weechat_plugin *, void *, char *); /* infos */ extern char *plugin_api_info_get (struct t_weechat_plugin *, char *); +/* lists */ +extern struct t_plugin_list *(*list_get) (struct t_weechat_plugin *, char *, + void *); +extern struct t_plugin_list_item *list_next (struct t_weechat_plugin *, + void *); +extern struct t_plugin_list_item *list_prev (struct t_weechat_plugin *, + void *); +extern int *list_int (struct t_weechat_plugin *, void *, char *); +extern char *list_str (struct t_weechat_plugin *, void *, char *); +extern void *list_pointer (struct t_weechat_plugin *, void *, char *); +extern time_t list_time (struct t_weechat_plugin *, void *, char *); +extern void 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 *); +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 *, ...); +extern void plugin_api_log (struct t_weechat_plugin *, char *, char *, + char *, ...); #endif /* plugin-api.h */ diff --git a/src/plugins/plugin-list.c b/src/plugins/plugin-list.c index 9bcaa301f..5ade3a504 100644 --- a/src/plugins/plugin-list.c +++ b/src/plugins/plugin-list.c @@ -28,6 +28,7 @@ #include "../core/weechat.h" #include "../core/wee-log.h" +#include "../core/wee-string.h" #include "plugin-list.h" @@ -214,6 +215,150 @@ plugin_list_new_var_time (struct t_plugin_list_item *item, } /* + * plugin_list_next_item: return next item for a list + * if current item pointer is NULL, + * then return first item of list + */ + +struct t_plugin_list_item * +plugin_list_next_item (struct t_plugin_list *list) +{ + if (!list->ptr_item) + { + list->ptr_item = list->items; + return list->ptr_item; + } + list->ptr_item = list->ptr_item->next_item; + return list->ptr_item; +} + +/* + * plugin_list_prev_item: return previous item for a list + * if current item pointer is NULL, + * then return last item of list + */ + +struct t_plugin_list_item * +plugin_list_prev_item (struct t_plugin_list *list) +{ + if (!list->ptr_item) + { + list->ptr_item = list->last_item; + return list->ptr_item; + } + list->ptr_item = list->ptr_item->prev_item; + return list->ptr_item; +} + +/* + * plugin_list_get_int: get an integer variable value in an item + */ + +int +plugin_list_get_int (struct t_plugin_list_item *item, char *var) +{ + struct t_plugin_list_var *ptr_var; + + if (!item || !var || !var[0]) + return 0; + + for (ptr_var = item->vars; ptr_var; ptr_var = ptr_var->next_var) + { + if (string_strcasecmp (ptr_var->name, var) == 0) + { + if (ptr_var->type == PLUGIN_LIST_VAR_INTEGER) + return ptr_var->value_int; + else + return 0; + } + } + + /* variable not found */ + return 0; +} + +/* + * plugin_list_get_string: get a string variable value in an item + */ + +char * +plugin_list_get_string (struct t_plugin_list_item *item, char *var) +{ + struct t_plugin_list_var *ptr_var; + + if (!item || !var || !var[0]) + return NULL; + + for (ptr_var = item->vars; ptr_var; ptr_var = ptr_var->next_var) + { + if (string_strcasecmp (ptr_var->name, var) == 0) + { + if (ptr_var->type == PLUGIN_LIST_VAR_STRING) + return ptr_var->value_string; + else + return NULL; + } + } + + /* variable not found */ + return NULL; +} + +/* + * plugin_list_get_pointer: get a pointer variable value in an item + */ + +void * +plugin_list_get_pointer (struct t_plugin_list_item *item, char *var) +{ + struct t_plugin_list_var *ptr_var; + + if (!item || !var || !var[0]) + return NULL; + + for (ptr_var = item->vars; ptr_var; ptr_var = ptr_var->next_var) + { + if (string_strcasecmp (ptr_var->name, var) == 0) + { + if (ptr_var->type == PLUGIN_LIST_VAR_POINTER) + return ptr_var->value_pointer; + else + return NULL; + } + } + + /* variable not found */ + return NULL; +} + +/* + * plugin_list_get_time: get a time variable value in an item + */ + +time_t +plugin_list_get_time (struct t_plugin_list_item *item, char *var) +{ + struct t_plugin_list_var *ptr_var; + + if (!item || !var || !var[0]) + return 0; + + for (ptr_var = item->vars; ptr_var; ptr_var = ptr_var->next_var) + { + if (string_strcasecmp (ptr_var->name, var) == 0) + { + if (ptr_var->type == PLUGIN_LIST_VAR_TIME) + return ptr_var->value_time; + else + return 0; + } + } + + /* variable not found */ + return 0; +} + +/* * plugin_list_var_free: free a plugin list variable */ diff --git a/src/plugins/plugin-list.h b/src/plugins/plugin-list.h index 251a0168b..8b870d9b8 100644 --- a/src/plugins/plugin-list.h +++ b/src/plugins/plugin-list.h @@ -76,6 +76,12 @@ extern struct t_plugin_list_var *plugin_list_new_var_pointer (struct t_plugin_li char *, void *); extern struct t_plugin_list_var *plugin_list_new_var_time (struct t_plugin_list_item *, char *, time_t); +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 int plugin_list_get_int (struct t_plugin_list_item *, char *); +extern char *plugin_list_get_string (struct t_plugin_list_item *, char *); +extern void *plugin_list_get_pointer (struct t_plugin_list_item *, char *); +extern time_t plugin_list_get_time (struct t_plugin_list_item *, char *); extern void plugin_list_free (struct t_plugin_list *); extern void plugin_list_print_log (); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 86d9f9a07..22fe8d009 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -49,12 +49,12 @@ struct t_weechat_plugin struct t_weechat_plugin *prev_plugin; /* link to previous plugin */ struct t_weechat_plugin *next_plugin; /* link to next plugin */ - /* plugin functions (interface) */ + /* plugin functions (API) */ - /* IMPORTANT NOTE for WeeChat developers: always add new interface functions + /* IMPORTANT NOTE for WeeChat developers: always add new API functions at the END of functions, for keeping backward compatibility with existing plugins */ - + /* strings */ void (*charset_set) (struct t_weechat_plugin *, char *); char *(*iconv_to_internal) (struct t_weechat_plugin *, char *, char *); @@ -66,19 +66,19 @@ struct t_weechat_plugin char **(*explode_string) (struct t_weechat_plugin *, char *, char *, int, int *); void (*free_exploded_string) (struct t_weechat_plugin *, char **); - + /* directories */ int (*mkdir_home) (struct t_weechat_plugin *, char *); void (*exec_on_files) (struct t_weechat_plugin *, char *, int (*)(char *)); - + /* display */ void (*printf) (struct t_weechat_plugin *, void *, char *, ...); char *(*prefix) (struct t_weechat_plugin *, char *); char *(*color) (struct t_weechat_plugin *, char *); void (*print_infobar) (struct t_weechat_plugin *, int, char *, ...); void (*infobar_remove) (struct t_weechat_plugin *, int); - + /* hooks */ struct t_hook *(*hook_command) (struct t_weechat_plugin *, char *, char *, char *, char *, char *, @@ -108,16 +108,21 @@ struct t_weechat_plugin /* command */ void (*command) (struct t_weechat_plugin *, void *, char *); - + /* infos */ char *(*info_get) (struct t_weechat_plugin *, char *); - + /* lists */ struct t_plugin_list *(*list_get) (struct t_weechat_plugin *, char *, void *); + struct t_plugin_list *(*list_next) (struct t_weechat_plugin *, void *); + struct t_plugin_list *(*list_prev) (struct t_weechat_plugin *, void *); + int (*list_int) (struct t_weechat_plugin *, void *, char *); + char *(*list_string) (struct t_weechat_plugin *, void *, char *); + void *(*list_pointer) (struct t_weechat_plugin *, void *, char *); + time_t (*list_time) (struct t_weechat_plugin *, void *, char *); void (*list_free) (struct t_weechat_plugin *, void *); - /* config */ char *(*config_get) (struct t_weechat_plugin *, char *); int (*config_set) (struct t_weechat_plugin *, char *, char *); @@ -188,6 +193,23 @@ struct t_weechat_plugin #define weechat_info_get(infoname) \ weechat_plugin->info_get(weechat_plugin, infoname) +#define weechat_list_get(name, pointer) \ + weechat_plugin->list_get(weechat_plugin, name, pointer) +#define weechat_list_next(ptrlist) \ + weechat_plugin->list_next(weechat_plugin, ptrlist) +#define weechat_list_prev(ptrlist) \ + weechat_plugin->list_prev(weechat_plugin, ptrlist) +#define weechat_list_int(ptritem, var) \ + weechat_plugin->list_int(weechat_plugin, ptritem, var) +#define weechat_list_string(ptritem, var) \ + weechat_plugin->list_string(weechat_plugin, ptritem, var) +#define weechat_list_pointer(ptritem, var) \ + weechat_plugin->list_pointer(weechat_plugin, ptritem, var) +#define weechat_list_time(ptritem, var) \ + weechat_plugin->list_time(weechat_plugin, ptritem, var) +#define weechat_list_free(ptrlist) \ + weechat_plugin->list_free(weechat_plugin, ptrlist) + #define weechat_config_get(option) \ weechat_plugin->config_get(weechat_plugin, option) #define weechat_config_set(option, value) \ |