C plugin APIPlugins
Functions to get infos about plugins.
weechat_plugin_get_name
Prototype:
void weechat_plugin_get_name (struct t_weechat_plugin *plugin);
Get plugin name (return "core" for WeeChat - NULL pointer).
Arguments:
: plugin pointer
Example:
const char *name = weechat_plugin_get_name (plugin);Strings
Many string functions below are already available thru standard C
functions, but it's recommended to use functions in this API because
they are ok with UTF-8 and locale.
weechat_charset_set
Prototype:
void weechat_charset_set (const char *charset);
Set new plugin charset.
Arguments:
: new charset to use
Example:
weechat_charset_set (plugin, "iso-8859-1");weechat_iconv_to_internal
Prototype:
char *weechat_iconv_to_internal (const char *charset, const char *string);
Convert string to WeeChat internal charset (UTF-8).
Arguments:
: charset to convert
: string to convert
Return value: converted string.
Result has to be free by a call to "free" after use.
Example:
char *str = weechat_iconv_to_internal (plugin, "iso-8859-1", "iso string: é à");weechat_iconv_from_internal
Prototype:
char *weechat_iconv_from_internal (const char *charset, const char *string);
Convert string from internal WeeChat charset (UTF-8) to another.
Arguments:
: target charset
: string to convert
Return value: converted string.
Result has to be free by a call to "free" after use.
Example:
char *str = weechat_iconv_from_internal ("iso-8859-1", "utf-8 string: é à");weechat_gettext
Prototype:
const char *weechat_gettext (const char *string);
Return translated string (depends on local language).
Arguments:
: string to translate
Return value: translated string.
Example:
char *str = weechat_gettext ("hello !");weechat_ngettext
Prototype:
const char *weechat_ngettext (const char *string, const char *plural, int count);
Return translated string, using single or plural form, according to
count.
Arguments:
: string to translate (single form)
: string to translate (plural form)
: used to choose between single and plural
form
Return value: translated string.
Example:
char *str = weechat_ngettext ("file", "files", num_files);weechat_strndup
Prototype:
char *weechat_strndup (const char *string, int length);
Return duplicated string, with max "length" chars.
Arguments:
: string to duplicate
: max chars to duplicate
Return value: duplicated string.
Result has to be free by a call to "free" after use.
Example:
char *str = weechat_strndup ("abcdef", 3); /* result: "abc" */weechat_string_tolower
Prototype:
void weechat_string_tolower (const char *string);
Convert UTF-8 string to lower case.
Arguments:
: string to convert
Return value: none.
Example:
weechat_string_tolower ("AbCdEé"); /* result: "abcdeé" */weechat_string_toupper
Prototype:
void weechat_string_toupper (const char *string);
Convert UTF-8 string to upper case.
Arguments:
: string to convert
Return value: none.
Example:
weechat_string_toupper ("AbCdEé"); /* result: "ABCDEé" */weechat_strcasecmp
Prototype:
int weechat_strcasecmp (const char *string1, const char *string2);
Locale and case independent string comparison.
Arguments:
: first string for comparison
: second string for comparison
Return value: difference between two strings: negative if
string1 < string2, zero if string1 == string2, positive if
string1 > string2
Example:
int diff = weechat_strcasecmp ("aaa", "CCC"); /* == -2 */ weechat_strncasecmp
Prototype:
int weechat_strncasecmp (const char *string1, const char *string2, int max);
Locale and case independent string comparison, for "max" chars.
Arguments:
: first string for comparison
: second string for comparison
: max number of chars for comparison
Return value: difference between two strings: negative if
string1 < string2, zero if string1 == string2, positive if
string1 > string2
Example:
int diff = weechat_strncasecmp ("aaa", "CCC", 2); /* == -2 */weechat_strcmp_ignore_chars
Prototype:
int weechat_strcmp_ignore_chars (
const char *string1,
const char *string2,
const char *chars_ignored,
int case_sensitive);
Locale (and optionally case independent) string comparison, ignoring
some chars.
Arguments:
: first string for comparison
: second string for comparison
: string with chars to ignore
: 1 for case sensitive comparison,
0 otherwise
Return value: difference between two strings: negative if
string1 < string2, zero if string1 == string2, positive if
string1 > string2
Example:
int diff = weechat_strcmp_ignore_chars ("a-b", "--a-e", "-", 1); /* == -3 */weechat_strcasestr
Prototype:
char *weechat_strcasestr (const char *string, const char *search);
Locale and case independent string search.
Arguments:
: string
: string to search in "string"
Return value: pointer to string found, or NULL if not found
Example:
char *pos = weechat_strcasestr ("aBcDeF", "de"); /* result: pointer to "DeF" */weechat_string_match
Prototype:
int weechat_string_match (
const char *string,
const char *mask,
int case_sensitive);
Check if a string matches a mask. Mask can begin or end with "*" (no
other "*" are allowed inside mask).
Arguments:
: string
: mask
: 1 for case sensitive search,
otherwise 0
Return value: 1 if string matches mask, otherwise 0.
Examples:
int match1 = weechat_string_match ("abcdef", "abc*", 0); /* == 1 */
int match2 = weechat_string_match ("abcdef", "*dd*", 0); /* == 0 */
int match3 = weechat_string_match ("abcdef", "*def", 0); /* == 1 */
weechat_string_replace
Prototype:
char *weechat_string_replace (const char *string, const char *search,
const char *replace);
Replace "search" string by new one in a string.
Arguments:
: string
: string to replace
: replacement for "search" string
Return value: string with "search" replaced by "replace".
Result has to be free by a call to "free" after use.
Example:
char *str = weechat_string_replace ("test", "s", "x"); /* result: "text" */weechat_string_remove_quotes
Prototype:
char *weechat_string_remove_quotes (const char *string, const char *quotes);
Remove quotes at beginning/end of string (ignore spaces if there are
before first quote or after last quote).
Arguments:
: string
: string with list of quotes
Return value: string without quotes at beginning/end.
Result has to be free by a call to "free" after use.
Example:
char *str = weechat_string_remove_quotes (string, " 'abc' ", "'"); /* result: "abc" */weechat_string_strip
Prototype:
char *weechat_string_strip (
const char *string,
int left,
int right,
const char *chars);
Strip chars at beginning and/or end of string.
Arguments:
: string
: strip left chars if different from 0
: strip right chars if different from 0
: string with chars to strip
Return value: stripped string.
Result has to be free by a call to "free" after use.
Example:
char *str = weechat_string_strip (string, " ", 0, 1); /* remove spaces at end of string */
weechat_string_has_highlight
Prototype:
int weechat_string_has_highlight (
const char *string,
const char highlight_words);
Check if a string has highlights, using list of highlight words.
Arguments:
: string
: list of highlight words,
separated by comma
Return value: 1 if string has one or more highlights, 0 otherwise.
Example:
if (weechat_string_has_highlight (string, "word1,word2")) ...weechat_string_mask_to_regex
Prototype:
char *weechat_string_mask_to_regex (const char *mask);
Return a regex, built with a mask, where only special char is "*".
All special chars for regex are escaped.
Arguments:
: mask
Return value: regex.
Example:
char *regex = weechat_string_mask_to_regex ("test*mask");weechat_string_explode
Prototype:
char **weechat_string_explode (
const char *string,
const char *separators, int keep_eol,
int num_items_max, int *num_items);
Explode a string according to one or more delimiter(s).
Arguments:
: string to explode
: delimiters used for explosion
: if different from 0, then each
argument will contain all string until end of line (see example
below)
: maximum number of items
created (0 = no limit)
: pointer to int which will
contain number of items created
Return value: array of strings, NULL if problem.
Result has to be free by a call to "weechat_string_free_exploded"
after use.
Examples:
char **argv;
int argc;
argv = weechat_string_explode ("abc de fghi", " ", 0, 0, &argc);
/* result: argv[0] == "abc"
argv[1] == "de"
argv[2] == "fghi"
argv[3] == NULL
argc == 3
*/
weechat_string_free_exploded (argv);
argv = weechat_string_explode ("abc de fghi", " ", 1, 0, &argc);
/* result: argv[0] == "abc de fghi"
argv[1] == "de fghi"
argv[2] == "fghi"
argv[3] == NULL
argc == 3
*/
weechat_string_free_exploded (argv);
weechat_string_free_exploded
Prototype:
void weechat_string_free_exploded (char **exploded_string);
Free memory used by a string explosion.
Arguments:
: string exploded by
"weechat_string_explode" function
Return value: none.
Example:
char *argv;
int argc;
argv = weechat_string_explode (string, " ", 0, 0, &argc);
...
weechat_string_free_exploded (, argv);
weechat_string_build_with_exploded
Prototype:
char *weechat_string_build_with_exploded (
char **exploded_string,
const char *separator);
Build a string with exploded string.
Arguments:
: string exploded by
"weechat_string_explode" function
: string used to separate strings
Return value: string built with exploded string.
Result has to be free by a call to "free" after use.
Example:
char **argv;
int argc;
argv = weechat_string_explode ("abc def ghi", " ", 0, 0, &argc);
char *string = weechat_string_build_with_exploded (argv, ";");
/* string == "abc;def;ghi" */
weechat_string_split_command
Prototype:
char **weechat_string_split_command (const char *command, char separator);
Split a list of commands separated by 'separator' (which can be escaped
by '\' in string).
Arguments:
: command to split
: separator
Return value: array of strings, NULL if problem.
Result has to be free by a call to
"weechat_string_free_split_command" after use.
Example:
char **argv = weechat_string_split_command ("/command1;/command2", ';');weechat_string_free_split_command
Prototype:
void weechat_string_free_split_command (char **split_command);
Free memory used by a split command.
Arguments:
: command split by
"weechat_string_split_commaand" function
Return value: none.
Example:
char **argv = weechat_string_split_command ("/command1;/command2", ';');
...
weechat_string_free_split_command (argv);
weechat_string_format_size
Prototype:
char *weechat_string_format_size (unsigned long size);
Build a string with formated size and translated unit.
Arguments:
: size
Return value: string with formated size and translated unit.
Result has to be free by a call to "free" after use.
Example:
char *str = weechat_string_format_size (0); /* str == "0 byte" (english locale) */
if (str)
free (str);
char *str = weechat_string_format_size (200); /* str == "200 bytes" (english locale) */
if (str)
free (str);
char *str = weechat_string_format_size (1536); /* str == "1.5 KB" (english locale) */
if (str)
free (str);
char *str = weechat_string_format_size (2097152); /* str == "2 MB" (english locale) */
if (str)
free (str);
weechat_string_remove_color
Prototype:
char *weechat_string_remove_color (const char *string, const char *replacement);
Remove WeeChat colors from a string.
Arguments:
: string
: if not NULL and not empty, WeeChat
color codes are replaced by first char of this string, otherwise
WeeChat color codes and following chars (if related to color) are
removed from string
Return value: string without color.
Result has to be free by a call to "free" after use.
Example:
char *str1 = weechat_string_remove_color (my_string1, NULL); /* remove colors and related chars */
char *str2 = weechat_string_remove_color (my_string2, "?"); /* replace color codes by "?" */
UTF-8
Some UTF-8 string functions.
weechat_utf8_has_8bits
Prototype:
int weechat_utf8_has_8bits (const char *string);
Check if a string has 8-bits chars.
Arguments:
: string
Return value: 1 if string has 8-buts chars, 0 if only 7-bits chars.
Example:
if (weechat_utf8_has_8bits (string)) ...weechat_utf8_is_valid
Prototype:
int weechat_utf8_is_valid (const char *string, char **error);
Check if a string is UTF-8 valid.
Arguments:
: string
: if not NULL, it is set with first non
valid UTF-8 char in string, if any
Return value: 1 if UTF-8 string is valid, 0 otherwise.
Example:
char *error;
if (weechat_utf8_is_valid (string, &error)) ...
weechat_utf8_normalize
Prototype:
void weechat_utf8_normalize (const char *string, char replacement);
Normalize UTF-8 string: remove non UTF-8 chars and replace them by a
char
Arguments:
: string
: replacement char for non UTF-8 chars
Return value: none.
Example:
weechat_utf8_normalize (string, '?');weechat_utf8_prev_char
Prototype:
char *weechat_utf8_prev_char (const char *string_start, const char *string);
Return previous UTF-8 char in a string.
Arguments:
: start of string (function will not
return a char before this pointer)
: pointer to string (must be >=
string_start)
Return value: pointer to previous UTF-8 char, NULL if not found
(start of string reached)
Example:
char *prev_char = weechat_utf8_prev_char (string, ptr_in_string);weechat_utf8_next_char
Prototype:
char *weechat_utf8_next_char (const char *string);
Return next UTF-8 char in a string.
Arguments:
: string
Return value: pointer to next UTF-8 char, NULL if not found
(end of string reached)
Example:
char *next_char = weechat_utf8_next_char (string);weechat_utf8_char_size
Prototype:
int weechat_utf8_char_size (const char *string);
Return UTF-8 char size (in bytes).
Arguments:
: string
Return value: UTF-8 char size (in bytes).
Example:
int char_size = weechat_utf8_char_size ("être"); /* == 2 */weechat_utf8_strlen
Prototype:
int weechat_utf8_strlen (const char *string);
Return UTF-8 string length (multi-byte char is considered as 1 char).
Arguments:
: string
Return value: UTF-8 string length (number of real chars).
Example:
int length = weechat_utf8_strlen ("chêne"); /* == 5 */weechat_utf8_strnlen
Prototype:
int weechat_utf8_strnlen (const char *string, int bytes);
Return UTF-8 string length (multi-byte char is considered as 1 char),
for max bytes in string
Arguments:
: string
: max bytes in string
Return value: UTF-8 string length (number of real chars).
Example:
int length = weechat_utf8_strnlen ("chêne", 4); /* == 3 */weechat_utf8_strlen_screen
Prototype:
int weechat_utf8_strlen_screen (const char *string);
Return number of chars needed on screen to display UTF-8 string.
Arguments:
: string
Return value: number of chars needed on screen to display UTF-8 string.
Example:
int length_on_screen = weechat_utf8_strlen_screen ("东"); /* == 2 */weechat_utf8_charcasecmp
Prototype:
int weechat_utf8_charcasecmp (const char *string1, const char *string2);
Compare two UTF-8 chars (case is ignored).
Arguments:
: first string for comparison
: second string for comparison
Return value: difference between first char of each string: negative if
char1 < char2, zero if char1 == char2, positive if char1 > char2
Example:
if (weechat_utf8_charcasecmp (string1, string2) != 0) ...weechat_utf8_char_size_screen
Prototype:
int weechat_utf8_char_size_screen (const char *string);
Return number of chars needed on screen to display UTF-8 char.
Arguments:
: string
Return value: number of chars needed on screen to display UTF-8 char.
Example:
int length_on_screen = weechat_utf8_char_size_screen (string)weechat_utf8_add_offset
Prototype:
char *weechat_utf8_add_offset (const char *string, int offset);
Move forward N chars in an UTF-8 string.
Arguments:
: string
: number of chars
Return value: pointer to string, N chars after (NULL if it's not
reachable).
Example:
char *ptr = weechat_utf8_add_offset ("chêne", 3); /* points to "ne" */weechat_utf8_real_pos
Prototype:
char *weechat_utf8_real_pos (const char *string, int pos);
Get real position in UTF-8 string.
Arguments:
: string
: position in chars
Return value: real position (in bytes) for "pos" chars in string.
Example:
int pos = weechat_utf8_real_pos ("chêne", 3); /* == 4 */weechat_utf8_pos
Prototype:
char *weechat_utf8_pos (const char *string, int real_pos);
Get position in UTF-8 string.
Arguments:
: string
: position in bytes
Return value: position (in chars) for "real_pos" bytes in string.
Example:
int pos = weechat_utf8_real_pos ("chêne", 4); /* == 3 */weechat_utf8_strndup
Prototype:
char *weechat_utf8_strndup (const char *string, int max_chars);
Return duplicate string, with max N chars.
Arguments:
: string
: max chars
Return value: duplicated string, NULL if error.
Example:
char *string = weechat_utf8_strndup ("chêne", 3); /* returns "chê" */Directories
Some functions related to directories.
weechat_mkdir_home
Prototype:
int weechat_mkdir_home (char *directory, int mode);
Create a directory in WeeChat home.
Arguments:
: directory to create
: mode for new directory
Return value: 1 if directory was successfully created, 0 if an
error occurred.
Example:
if (!weechat_mkdir_home ("temp")) ... weechat_mkdir
Prototype:
int weechat_mkdir (char *directory, int mode);
Create a directory.
Arguments:
: directory to create
: mode for new directory
Return value: 1 if directory was successfully created, 0 if an
error occurred.
Example:
if (!weechat_mkdir ("/tmp/mydir")) ... weechat_mkdir_parents
Prototype:
int weechat_mkdir_parents (char *directory, int mode);
Create a directory and make parent directories as needed.
Arguments:
: directory to create
: mode for new directory (and parents)
Return value: 1 if directory was successfully created, 0 if an
error occurred.
Example:
if (!weechat_mkdir_parents ("/tmp/my/dir")) ... weechat_exec_on_files
Prototype:
void weechat_exec_on_files (
const char *directory,
void *data,
int (*callback)(void *data, const char *filename));
Find files in a directory and execute a callback on each file.
Arguments:
: directory for searching files
: pointer given to callback when it is
called by WeeChat
: function called for each file
found, arguments:
TypeNameDescriptionvoid *datapointerconst char *filenamefilename found
Return value: none.
Example:
int callback (void *data, const char *filename)
{
/* ... */
return 1;
}
...
plugin->exec_on_files (plugin, "/tmp", &callback);
Util
Some useful functions.
weechat_timeval_cmp
Prototype:
int weechat_timeval_cmp (struct timeval *tv1, struct timeval *tv2);
Compare 2 timeval structures.
Arguments:
: first timeval structure
: second timeval structure
Return value: -1 if tv1 < char2, zero if tv1 == tv2, +1 if tv1 >
tv2
Example:
if (weechat_timeval_cmp (&tv1, &tv2) > 0) ...weechat_timeval_diff
Prototype:
long weechat_timeval_diff (struct timeval *tv1, struct timeval *tv2);
Return difference (in milliseconds) between 2 timeval structures.
Arguments:
: first timeval structure
: second timeval structure
Return value: difference in milliseconds.
Example:
long diff = weechat_timeval_diff (&tv1, &tv2);weechat_timeval_add
Prototype:
void weechat_timeval_add (struct timeval *tv, long interval);
Add interval (in milliseconds) to a timeval structure.
Arguments:
: timeval structure
: interval (in milliseconds)
Return value: none.
Example:
weechat_timeval_add (&tv, 2000); /* add 2 seconds */Sorted lists
Sorted list functions.
weechat_list_new
Prototype:
struct t_weelist *weechat_list_new ();
Create a new list.
Return value: pointer to new list.
Example:
struct t_weelist *list = weechat_list_new ();weechat_list_add
Prototype:
struct t_weelist_item *weechat_list_add (
struct t_weelist *weelist,
const char *data,
const char *where,
void *user_data);
Add an item in a list.
Arguments:
: list pointer
: data to insert in list
: position in list (constants are:
WEECHAT_LIST_POS_SORT, WEECHAT_LIST_POS_BEGINNING or
WEECHAT_LIST_POS_END)
: any pointer
Return value: pointer to new item.
Example:
weechat_list_add (list, "my data", WEECHAT_LIST_POS_SORT, NULL);weechat_list_search
Prototype:
struct t_weelist_item *weechat_list_search (
struct t_weelist *weelist,
const char *data);
Search an item in a list.
Arguments:
: list pointer
: data to search in list
Return value: pointer to item found, NULL if item was not found.
Example:
struct t_weelist_item *item = weechat_list_search (list, "my data");weechat_list_casesearch
Prototype:
struct t_weelist_item *weechat_list_casesearch (
struct t_weelist *weelist,
const char *data);
Search an item in a list (case sensitive search).
Arguments:
: list pointer
: data to search in list
Return value: pointer to item found, NULL if item was not found.
Example:
struct t_weelist_item *item = weechat_list_casesearch (list, "my data");weechat_list_get
Prototype:
struct t_weelist_item *weechat_list_get (
struct t_weelist *weelist,
int position);
Get an item in a list by position.
Arguments:
: list pointer
: position in list (0 is first item)
Return value: pointer to item found, NULL if item position was not
found.
Example:
struct t_weelist_item *item = weechat_list_get (list, 0); /* first item */weechat_list_set
Prototype:
void weechat_list_set (struct t_weelist_item *item, const char *value);
Set new value for an item.
Arguments:
: item pointer
: new value for item
Example:
weechat_list_set (item, "new data");weechat_list_next
Prototype:
struct t_weelist_item *weechat_list_next (struct t_weelist_item *item);
Get next item in list.
Arguments:
: item pointer
Return value: pointer to next item, NULL if pointer was last item in
list.
Example:
struct t_weelist_item *next_item = weechat_list_next_item (item);weechat_list_prev
Prototype:
struct t_weelist_item *weechat_list_prev (struct t_weelist_item *item);
Get previous item in list.
Arguments:
: item pointer
Return value: pointer to previous item, NULL if pointer was first item
in list.
Example:
struct t_weelist_item *prev_item = weechat_list_prev_item (item);weechat_list_string
Prototype:
const char *weechat_list_string (struct t_weelist_item *item);
Get string value of an item.
Arguments:
: item pointer
Return value: string value of item.
Example:
char *value = weechat_list_string (item);weechat_list_size
Prototype:
char *weechat_list_size (struct t_weelist *weelist);
Get size of list (number of items).
Arguments:
: list pointer
Return value: size of list (number of items), 0 if list is empty.
Example:
int size = weechat_list_size (list);weechat_list_remove
Prototype:
void weechat_list_remove (
struct t_weelist *weelist,
struct t_weelist_item *item);
Remove an item in a list.
Arguments:
: list pointer
: item pointer
Example:
weechat_list_remove (list, item);weechat_list_remove_all
Prototype:
void weechat_list_remove_all (struct t_weelist *weelist);
Remove all items in a list.
Arguments:
: list pointer
Example:
weechat_list_remove_all (list);weechat_list_free
Prototype:
void weechat_list_free (struct t_weelist *weelist);
Free a list.
Arguments:
: list pointer
Example:
weechat_list_free (list);Configuration files
Functions for configuration files.
weechat_config_new
Prototype:
struct t_config_file *weechat_config_new (
const char *name,
int (*callback_reload)(void *data,
struct t_config_file *config_file),
void *callback_reload_data);
Create a new configuration file.
Arguments:
: name of configuration file (without path
or extension)
: callback called when
configuration file is reloaded with /reload (optional, can be
NULL), arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_file *config_fileconfiguration file pointer
: pointer given to reload
callback when it is called by WeeChat
NULL)
Return value: pointer to new configuration file, NULL if an error
occured.
File is NOT created by this function. It will be created by call to
function (you
should do that only after adding some sections (with
) and
options (with
).
Example:
int
my_config_reload_cb (void *data, struct t_config_file *config_file)
{
/* ... */
return WEECHAT_RC_OK;
}
struct t_config_file *config_file = weechat_config_new ("test",
&my_config_reload_cb,
NULL);
weechat_config_new_section
Prototype:
struct t_config_section *weechat_config_new_section (
struct t_config_file *config_file,
const char *name,
int user_can_add_options,
int user_can_delete_options,
int (*callback_read)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value),
void *callback_read_data,
int (*callback_write)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name),
void *callback_write_data,
int (*callback_write_default)(void *data,
struct t_config_file *config_file,
const char *section_name);
void *callback_write_default_data,
int (*callback_create_option)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value),
void *callback_create_option_data,
int (*callback_delete_option)(void *data,
struct t_config_file *config_file,
struct t_config_section *section,
struct t_config_option *option),
void *callback_delete_option_data);
Create a new section in configuration file.
Arguments:
: configuration file pointer
: name of section
: 1 if user can add options
in section, or 0 if it is forbidden
: 1 if user can delete
options in section, or 0 if it is forbidden
: callback called when an option
in section is read from disk (should be NULL for most cases,
except if options in your section need custom function),
arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_file *config_fileconfiguration file pointerstruct t_config_section *sectionsection pointerconst char *option_namename of optionconst char *valuevalue
: pointer given to read
callback when it is called by WeeChat
NULL)
: callback called when section
is written in file (should be NULL for most cases, except if your
section needs to be written by a custom function), arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_file *config_fileconfiguration file pointerstruct t_config_section *sectionsection pointerconst char *option_namename of option
: pointer given to write
callback when it is called by WeeChat
NULL)
: callback called when
default values for section must be written in file, arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_file *config_fileconfiguration file pointerconst char *section_namename of section
: pointer given to
write_default callback when it is called by WeeChat
NULL)
: callback called when a
new option is created in section (NULL if section does not allow
new options to be created), arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_file *config_fileconfiguration file pointerstruct t_config_section *sectionsection pointerconst char *option_namename of optionconst char *valuevalue
: pointer given to
create_option callback when it is called by WeeChat
NULL)
: callback called when an
option is deleted (NULL if section does not allow options to be
deleted), arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_file *config_fileconfiguration file pointerstruct t_config_section *sectionsection pointerstruct t_config_option *optionoptionoption pointer
: pointer given to
delete_option callback when it is called by WeeChat
NULL)
Return value: pointer to new section in configuration file, NULL if an
error occured.
Example:
int
my_section_read_cb (void *data, struct t_config_file *config_file,
struct t_config_section *section, const char *option_name,
const char *value)
{
/* ... */
return WEECHAT_RC_OK;
}
int
my_section_write_cb (void *data, struct t_config_file *config_file,
const char *section_name)
{
/* ... */
return WEECHAT_RC_OK;
}
int
my_section_write_default_cb (void *data, struct t_config_file *config_file,
const char *section_name)
{
/* ... */
return WEECHAT_RC_OK;
}
int
my_section_create_option_cb (void *data, struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name, const char *value)
{
/* ... */
return WEECHAT_RC_OK;
}
int
my_section_delete_option_cb (void *data, struct t_config_file *config_file,
struct t_config_section *section,
struct t_config_option *option)
{
/* ... */
return WEECHAT_RC_OK;
}
/* standard section, user can not add/delete options */
struct t_config_section *new_section1 =
weechat_config_new ("section1", 0, 0,
NULL, NULL, /* read callback */
NULL, NULL, /* write callback */
NULL, NULL, /* write default callback */
NULL, NULL, /* create option callback */
NULL, NULL); /* delete option callback */
/* special section, user can add/delete options, and options need
callback to be read/written */
struct t_config_section *new_section2 =
weechat_config_new ("section2", 1, 1,
&my_section_read_cb, NULL,
&my_section_write_cb, NULL,
&my_section_write_default_cb, NULL,
&my_section_create_option_cb, NULL,
&my_section_delete_option_cb, NULL);
weechat_config_search_section
Prototype:
struct t_config_section *weechat_config_search_section (
struct t_config_file *config_file,
const char *section_name);
Search a section in a configuration file.
Arguments:
: configuration file pointer
: name of section to search
Return value: pointer to section found, NULL if section was not found.
Example:
struct t_config_section *section = weechat_config_search_section (config_file, "section");
weechat_config_new_option
Prototype:
struct t_config_option *weechat_config_new_option (
struct t_config_file *config_file,
struct t_config_section *section,
const char *name,
const char *type,
const char *description,
const char *string_values,
int min,
int max,
const char *default_value,
const char *value,
int null_value_allowed,
int (*callback_check_value)(void *data,
struct t_config_option *option,
const char *value),
void *callback_check_value_data,
int (*callback_change)(void *data,
struct t_config_option *option),
void *callback_change_data,
int (*callback_delete)(void *data,
struct t_config_option *option),
void *callback_delete_data);
Create a new option in a section of a configuration file.
Arguments:
: configuration file pointer
: section pointer
: name of option
: type of option, one of:
booleanintegerstringcolor
: description of option
: values as string (separated by
"|"), used for type integer (optional)
: minimum value (for integer)
NULL)
: maximum value (for integer)
: default value for option (used
when option is reset)
: value for option
: 1 if null (undefined value)
is allowed for option, otherwise 0
: callback called to check
new value for an option (optional), arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_option *optionoption pointerconst char *valuenew value for option
: pointer given to
check_value callback when it is called by WeeChat
NULL)
: callback called when value of
option has changed (optional), arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_option *optionoption pointer
: pointer given to change
callback when it is called by WeeChat
NULL)
: callback called when option
will be deleted (optional), arguments:
TypeNameDescriptionvoid *datapointerstruct t_config_option *optionoption pointer
: pointer given to delete
callback when it is called by WeeChat
NULL)
Return value: pointer to new option in section, NULL if an error
occured.
Example:
/* boolean */
struct t_config_option *option1 =
weechat_config_new_option (config_file, section,
"option1", "My option, type boolean"
NULL, /* string values */
0, 0, /* min, max */
"on", /* default */
"on", /* value */
0, /* null value allowed */
NULL, NULL, /* check callback */
NULL, NULL, /* change callback */
NULL, NULL); /* delete callback */
/* integer */
struct t_config_option *option2 =
weechat_config_new_option (config_file, section,
"option2", "My option, type integer"
NULL, /* string values */
0, 100, /* min, max */
"15", /* default */
"15", /* value */
0, /* null value allowed */
NULL, NULL, /* check callback */
NULL, NULL, /* change callback */
NULL, NULL); /* delete callback */
/* integer (with string values) */
struct t_config_option *option3 =
weechat_config_new_option (config_file, section,
"option3", "My option, type integer (with string values)"
"top|bottom|left|right", /* string values */
0, 0, /* min, max */
"bottom", /* default */
"bottom", /* value */
0, /* null value allowed */
NULL, NULL, /* check callback */
NULL, NULL, /* change callback */
NULL, NULL); /* delete callback */
/* string */
struct t_config_option *option4 =
weechat_config_new_option (config_file, section,
"option4", "My option, type string"
NULL, /* string values */
0, 0, /* min, max */
"test", /* default */
"test", /* value */
1, /* null value allowed */
NULL, NULL, /* check callback */
NULL, NULL, /* change callback */
NULL, NULL); /* delete callback */
/* color */
struct t_config_option *option5 =
weechat_config_new_option (config_file, section,
"option5", "My option, type color"
NULL, /* string values */
0, 0, /* min, max */
"lightblue", /* default */
"lightblue", /* value */
0, /* null value allowed */
NULL, NULL, /* check callback */
NULL, NULL, /* change callback */
NULL, NULL); /* delete callback */
weechat_config_search_option
Prototype:
struct t_config_option *weechat_config_search_option (
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name);
Search an option in a section of a configuration file.
Arguments:
: configuration file pointer
: section pointer
: name of option to search
Return value: pointer to option found, NULL if option was not found.
Example:
struct t_config_option *option =
weechat_config_search_option (config_file, section, "option");
weechat_config_search_with_string
Prototype:
void weechat_config_search_with_string (
const char *option_name,
struct t_config_file **config_file,
struct t_config_section **section,
struct t_config_option **option);
Search an option in a configuration file with string.
Arguments:
: full option name (format:
"file.section.option")
: pointer to a configuration file
pointer, will be set to configuration file of option, if found
: pointer to a section pointer, will be
set to section of option, if found
: pointer to an option pointer, will be
set to option pointer, if found
Example:
struct t_config_file *ptr_config_file;
struct t_config_section *ptr_section;
struct t_config_option *ptr_option;
weechat_config_search_with_string ("file.section.option",
&ptr_config_file,
&ptr_section,
&ptr_option);
if (ptr_option)
{
/* option found */
/* ... */
}
else
{
/* option not found */
/* ... */
}
weechat_config_string_to_boolean
Prototype:
int weechat_config_string_to_boolean (const char *text);
Check if a text is "true" or "false".
Arguments:
: text to analyze
Return value: 1 if text is "true" ("on", "yes", "y", "true", "t", "1"),
or 0 if text is "false" ("off", "no", "n", "false", "f", "0").
Example:
if (weechat_config_string_to_boolean ("on"))
{
/* true */
/* ... */
}
else
{
/* false */
/* never executed! */
}
weechat_config_option_reset
Prototype:
int weechat_config_option_reset (
struct t_config_option *option,
int run_callback);
Reset an option to its default value.
Arguments:
: option pointer
: 1 for calling change callback if
option is changed, 0 otherwise
Return value: WEECHAT_CONFIG_OPTION_SET_OK_CHANGED if option value has
been reset, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE if value was not
changed, WEECHAT_CONFIG_OPTION_SET_ERROR if an error occured.
Example:
switch (weechat_config_option_reset (option, 1))
{
case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_SET_ERROR:
/* .... */
break;
}
weechat_config_option_set
Prototype:
int weechat_config_option_set (
struct t_config_option *option,
const char *value, int run_callback);
Set new value for an option.
Arguments:
: option pointer
: new value for option
: 1 for calling change callback if
option is changed, 0 otherwise
Return value: WEECHAT_CONFIG_OPTION_SET_OK_CHANGED if option value has
been reset, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE if value was not
changed, WEECHAT_CONFIG_OPTION_SET_ERROR if an error occured.
Example:
switch (weechat_config_option_set (option, "new_value", 1))
{
case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_SET_ERROR:
/* .... */
break;
}
weechat_config_option_set_null
Prototype:
int weechat_config_option_set_null (
struct t_config_option *option,
int run_callback);
Set null (undefined value) for an option.
Arguments:
: option pointer
: 1 for calling change callback if
option is changed (if it was not null), 0 otherwise
You can set value to null only if option allows null value
(see ).
Return value: WEECHAT_CONFIG_OPTION_SET_OK_CHANGED if option value has
been reset, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE if value was not
changed, WEECHAT_CONFIG_OPTION_SET_ERROR if an error occured.
Example:
switch (weechat_config_option_set_null (option, 1))
{
case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_SET_ERROR:
/* .... */
break;
}
weechat_config_option_unset
Prototype:
int weechat_config_option_unset (struct t_config_option *option);
Unset/reset option.
Arguments:
: option pointer
Return value: WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET if option value
has not been reset, WEECHAT_CONFIG_OPTION_UNSET_OK_RESET if option
value has been reset, WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED if option
has been removed, WEECHAT_CONFIG_OPTION_UNSET_ERROR if an error
occured.
Example:
switch (weechat_config_option_unset (option))
{
case WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_UNSET_OK_RESET:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED:
/* .... */
break;
case WEECHAT_CONFIG_OPTION_UNSET_ERROR:
/* .... */
break;
}
weechat_config_option_rename
Prototype:
void weechat_config_option_rename (
struct t_config_option *option,
const char *new_name);
Rename an option.
Arguments:
: option pointer
: new name for option
Example:
weechat_config_option_rename (option, "new_name");
weechat_config_option_get_pointer
Prototype:
void *weechat_config_option_get_pointer (
struct t_config_option *option,
const char *property);
Get a pointer on an option property.
Arguments:
: option pointer
: property name:
PropertyTypeDescriptionconfig_filestruct t_config_file *configuration file pointersectionstruct t_config_section *section pointernamechar *option nametypeintoption typedescriptionchar *option descriptionstring_valueschar **string valuesminintminimum valuemaxintmaximum valuedefault_value(depends on type)default valuevalue(depends on type)current valueprev_optionstruct t_config_option *previous option pointernext_optionstruct t_config_option *next option pointer
Return value: pointer to property asked.
Example:
char *description = weechat_config_option_get_pointer (option, "description");
weechat_config_option_is_null
Prototype:
int weechat_config_option_is_null (struct t_config_option *option);
Check if an option is null (undefined value).
Arguments:
: option pointer
Example:
if (weechat_config_option_is_null (option))
{
/* value is null */
}
else
{
/* value is not null */
}
weechat_config_boolean
Prototype:
int weechat_config_boolean (struct t_config_option *option);
Get boolean value of option.
Arguments:
: option pointer
Return value: boolean value of option (0 or 1).
Example:
if (weechat_config_boolean (option))
{
/* true */
}
else
{
/* false */
}
weechat_config_boolean_default
Prototype:
int weechat_config_boolean_default (struct t_config_option *option);
Get default boolean value of option.
Arguments:
: option pointer
Return value: default boolean value of option (0 or 1).
Example:
if (weechat_config_boolean_default (option))
{
/* true */
}
else
{
/* false */
}
weechat_config_integer
Prototype:
int weechat_config_integer (struct t_config_option *option);
Get integer value of option.
Arguments:
: option pointer
Return value: integer value of option.
Example:
int value = weechat_config_integer (option);weechat_config_integer_default
Prototype:
int weechat_config_integer_default (struct t_config_option *option);
Get default integer value of option.
Arguments:
: option pointer
Return value: default integer value of option.
Example:
int value = weechat_config_integer (option);weechat_config_string
Prototype:
const char *weechat_config_string (struct t_config_option *option);
Get string value of option.
Arguments:
: option pointer
Return value: string value of option.
Example:
char *value = weechat_config_string (option);weechat_config_string_default
Prototype:
const char *weechat_config_string_default (struct t_config_option *option);
Get default string value of option.
Arguments:
: option pointer
Return value: default string value of option.
Example:
char *value = weechat_config_string_default (option);weechat_config_color
Prototype:
const char *weechat_config_color (struct t_config_option *option);
Get color value of option.
Arguments:
: option pointer
Return value: color value of option (string with name of color).
Example:
char *color = weechat_config_color (option);weechat_config_color_default
Prototype:
const char *weechat_config_color_default (struct t_config_option *option);
Get default color value of option.
Arguments:
: option pointer
Return value: default color value of option (string with name of color).
Example:
char *color = weechat_config_color_default (option);weechat_config_write_option
Prototype:
void weechat_config_write_option (
struct t_config_file *config_file,
struct t_config_option *option);
Write a line in a configuration file with option and its value (this
function should be called only in "write" or "write_default" callbacks
for a section).
Arguments:
: configuration file pointer
: option pointer
Example:
int
my_section_write_cb (void *data, struct t_config_file *config_file,
const char *section_name)
{
weechat_config_write_line (config_file, "my_section", NULL);
weechat_config_write_option (config_file, option);
return WEECHAT_RC_OK;
}
weechat_config_write_line
Prototype:
void weechat_config_write_line (
struct t_config_file *config_file,
const char *option_name,
const char *value, ...);
Write a line in a configuration file (this function should be called
only in "write" or "write_default" callbacks for a section).
Arguments:
: configuration file pointer
: option name
: value
If value is NULL, then line with section name is written
(for example: "[section]").
Example:
int
my_section_write_cb (void *data, struct t_config_file *config_file,
const char *section_name)
{
weechat_config_write_line (config_file, "my_section", NULL);
weechat_config_write_line (config_file, "option", "%s;%d",
"value", 123);
return WEECHAT_RC_OK;
}
weechat_config_write
Prototype:
int weechat_config_write (struct t_config_file *config_file);
Write configuration file to disk.
Arguments:
: configuration file pointer
Return value: WEECHAT_CONFIG_WRITE_OK if configuration was written,
WEECHAT_CONFIG_WRITE_ERROR if an error occured,
WEECHAT_CONFIG_WRITE_MEMORY_ERROR if there was not enough memory.
Example:
switch (weechat_config_write (config_file))
{
case WEECHAT_CONFIG_WRITE_OK:
/* ... */
break;
case WEECHAT_CONFIG_WRITE_ERROR:
/* ... */
break;
case WEECHAT_CONFIG_WRITE_MEMORY_ERROR:
/* ... */
break;
}
weechat_config_read
Prototype:
int weechat_config_read (struct t_config_file *config_file);
Read configuration file from disk.
Arguments:
: configuration file pointer
Return value: WEECHAT_CONFIG_READ_OK if configuration was loaded,
WEECHAT_CONFIG_READ_MEMORY_ERROR if there was not enough memory,
WEECHAT_CONFIG_READ_FILE_NOT_FOUND if file was not found.
Example:
switch (weechat_config_read (config_file))
{
case WEECHAT_CONFIG_READ_OK:
/* ... */
break;
case WEECHAT_CONFIG_READ_MEMORY_ERROR:
/* ... */
break;
case WEECHAT_CONFIG_READ_FILE_NOT_FOUND:
/* ... */
break;
}
weechat_config_reload
Prototype:
int weechat_config_reload (struct t_config_file *config_file);
Reload configuration file from disk.
Arguments:
: configuration file pointer
Return value: WEECHAT_CONFIG_READ_OK if configuration was reloaded,
WEECHAT_CONFIG_READ_MEMORY_ERROR if there was not enough memory,
WEECHAT_CONFIG_READ_FILE_NOT_FOUND if file was not found.
Example:
switch (weechat_config_reload (config_file))
{
case WEECHAT_CONFIG_READ_OK:
/* ... */
break;
case WEECHAT_CONFIG_READ_MEMORY_ERROR:
/* ... */
break;
case WEECHAT_CONFIG_READ_FILE_NOT_FOUND:
/* ... */
break;
}
weechat_config_option_free
Prototype:
void weechat_config_option_free (struct t_config_option *option);
Free an option.
Arguments:
: option pointer
Example:
weechat_config_option_free (option);weechat_config_section_free_options
Prototype:
void weechat_config_section_free_options (struct t_config_section *section);
Free all options in a section.
Arguments:
: section pointer
Example:
weechat_config_section_free_options (section);weechat_config_section_free
Prototype:
void weechat_config_section_free (struct t_config_section *section);
Free a section.
Arguments:
: section pointer
Example:
weechat_config_section_free (section);weechat_config_free
Prototype:
void weechat_config_free (struct t_config_file *config_file);
Free a configuration file.
Arguments:
: configuration file pointer
Example:
weechat_config_free (config_file);weechat_config_get
Prototype:
struct t_config_option *weechat_config_get (const char *option_name);
Search an option in a configuration file with string.
Arguments:
: full option name (format:
"file.section.option")
Return value: pointer to option found, NULL if option was not found.
Example:
struct t_config_option *option = weechat_config_get ("weechat.look.item_time_format");
weechat_config_get_plugin
Prototype:
const char *weechat_config_get_plugin (const char *option_name);
Search an option in plugins configuration file (plugins.conf), by
adding prefix with current plugin name.
Arguments:
: option name, WeeChat will add
prefix "plugins.var.xxxx." (where xxxx is current plugin name).
Return value: pointer to option found, NULL if option was not found.
Example:
/* if current plugin is "test", then look for value of option
"plugins.var.test.option" in plugins.conf file */
char *value = weechat_config_get_plugin ("option");
weechat_config_set_plugin
Prototype:
int weechat_config_set_plugin (const char *option_name, const char *value);
Set value for option in plugins configuration file (plugins.conf).
Arguments:
: option name, WeeChat will add
prefix "plugins.var.xxxx." (where xxxx is current plugin name).
: value for option
Return value: WEECHAT_CONFIG_OPTION_SET_OK_CHANGED if option value has
been reset, WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE if value was not
changed, WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND if option was not
found, WEECHAT_CONFIG_OPTION_SET_ERROR if other error occured.
Example:
weechat_config_set_plugin ("option", "test_value");
weechat_config_unset_plugin
Prototype:
int weechat_config_unset_plugin (const char *option_name);
Unset option in plugins configuration file (plugins.conf).
Arguments:
: option name, WeeChat will add
prefix "plugins.var.xxxx." (where xxxx is current plugin name).
Return value: WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET if option value
has not been reset, WEECHAT_CONFIG_OPTION_UNSET_OK_RESET if option
value has been reset, WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED if option
has been removed, WEECHAT_CONFIG_OPTION_UNSET_ERROR if an error
occured.
Example:
weechat_config_unset_plugin ("option");
Display
Functions to display text in buffers.
weechat_prefix
Prototype:
const char *weechat_prefix (const char *prefix);
Get a prefix.
Arguments:
: name of prefix:
PrefixDefault valueDescriptionerror=!=error messagenetwork--message from networkaction*self actionjoin-->someone joins current chatquit<--someone leaves current chat
Return value: prefix value, empty string if prefix is not found
(not NULL).
Example:
weechat_printf (NULL, "%sThis is an error...",
weechat_prefix ("error"));
weechat_color
Prototype:
const char *weechat_color (const char *color_name);
Get a string color code for display.
Arguments:
: name of color: can be a WeeChat
color name (from weechat.color.xxx), a color with optional
background (separated by comma), attribute ("bold", "-bold",
"reverse", "-reverse", "italic", "-italic", "underline",
"-underline", ) or a bar color ("bar_fg", "bar_delim", "bar_bg").
Return value: string with color code, or a "reset color" code if color
is not found.
Example:
weechat_printf (NULL, "Color: %sblue %schat default %sred on green",
weechat_color ("blue"),
weechat_color ("chat"),
weechat_color ("red,green"));
weechat_printf
Prototype:
void weechat_printf (struct t_gui_buffer *buffer, const char *message, ...);
Display a message on a buffer.
Arguments:
: buffer pointer, if NULL, message is
displayed on WeeChat buffer.
: message to display
Example:
weechat_printf (NULL, "Hello on WeeChat buffer");
weechat_printf (buffer, "Hello on this buffer");
weechat_printf_date
Prototype:
void weechat_printf_date (
struct t_gui_buffer *buffer, time_t date,
const char *message, ...);
Display a message on a buffer, using a custom date.
Arguments:
: buffer pointer, if NULL, message is
displayed on WeeChat buffer.
: date for message
: message to display
Example:
weechat_printf (NULL, time (NULL) - 120, "Hello, 2 minutes ago");
weechat_printf_tags
Prototype:
void weechat_printf_tags (
struct t_gui_buffer *buffer,
const char *tags,
const char *message, ...);
Display a message on a buffer, using a custom tags.
Arguments:
: buffer pointer, if NULL, message is
displayed on WeeChat buffer.
: tags for message, separated by a comma
: message to display
Example:
weechat_printf_tags (NULL, "notify_message", "Hello with a message notify tag");
weechat_printf_date_tags
Prototype:
void weechat_printf_date_tags (
struct t_gui_buffer *buffer,
time_t date,
const char *tags,
const char *message, ...);
Display a message on a buffer, using a custom date and tags.
Arguments:
: buffer pointer, if NULL, message is
displayed on WeeChat buffer.
: date for message
: tags for message, separated by a comma
: message to display
Example:
weechat_printf_date_tags (NULL, time (NULL) - 120, "notify_message",
"Hello, 2 minutes ago, with a message notify tag");
weechat_printf_y
Prototype:
void weechat_printf_y (
struct t_gui_buffer *buffer,
int y,
const char *message, ...);
Display a message on a line of a buffer with free content (see
).
Arguments:
: buffer pointer, if NULL, message is
displayed on WeeChat buffer.
: line number (0 for first line)
: message to display
Example:
weechat_printf_y (buffer, 2, "My message on third line");
Hooks
Functions to hook/unhook something.
weechat_hook_command
Prototype:
struct t_hook *weechat_hook_command (
const char *command,
const char *description,
const char *args,
const char *args_description,
const char *completion,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
int argc, char **argv,
char **argv_eol),
void *callback_data);
Hook a command.
Arguments:
: new command name
: description of command (displayed
with /help command)
: arguments for command (displayed with
/help command)
: description of arguments
(displayed with /help command)
: completion template for command:
list of completions for each arguments, separated by space. Many
completions are possible for one argument, separated by "|".
Default completion codes are:
PluginCodeDescription
&completions.xml;
Special codes:
CodeDescription%-Stop completion%*Repeat last completion
: function called when command is used,
arguments:
TypeNameDescriptionvoid *datapointerstruct t_gui_buffer *bufferbuffer where command is executedintargcargument countchar **argvargumentschar **argv_eolarguments (until end of line)
For example, if command called is
/command abc def ghi, then argv and argv_eol
contain following values:
argv[0] == "abc"argv[1] == "def"argv[2] == "ghi"argv_eol[0] == "abc def ghi"argv_eol[1] == "def ghi"argv_eol[2] == "ghi"
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_command_cb (void *data, struct t_gui_buffer *buffer, int argc,
char **argv, char **argv_eol)
{
/* ... */
return WEECHAT_RC_OK;
}
struct t_hook *my_command_hook =
weechat_hook_command ("mycommand",
"description of my command",
"[command [buffer]]",
"command: WeeChat or plugin command\n"
" buffer: buffer name",
"%w|%p %b", &my_command_cb, NULL);
weechat_hook_command_run
Prototype:
struct t_hook *weechat_hook_command_run (
const char *command,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
const char *command),
void *callback_data);
Hook a command when WeeChat runs it.
Arguments:
: command to hook, may start or end with
"*" as joker
: function called when command is run,
arguments:
TypeNameDescriptionvoid *datapointerstruct t_gui_buffer *bufferbuffer where command is executedconst char *commandthe command executed, with its arguments
The callback can return WEECHAT_RC_OK or WEECHAT_RC_OK_EAT (ok
and "eat" command, will not be executed by WeeChat after
callback).
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_command_run_cb (void *data, struct t_gui_buffer *buffer,
const char *command)
{
weechat_printf (NULL,
"You wanted to complete? I'm eating the completion ahah!");
return WEECHAT_RC_OK_EAT;
}
struct t_hook *my_command_run_hook =
weechat_hook_command_run ("/input complete*",
&my_command_run_cb, NULL);
weechat_hook_timer
Prototype:
struct t_hook *weechat_hook_timer (
long interval,
const char *align_second,
const char *max_calls,
int (*callback)(void *data, int remaining_calls),
void *callback_data);
Hook a timer.
Arguments:
: interval between two calls
(milliseconds, so 1000 = 1 second)
: alignment on a second: align timer
on a second. For example, if current time is 09:00, if
interval = 60000 (60 seconds), and align_second = 60, then timer
is called each minute when second is 00.
: number of calls to timer (if 0, then
timer has no end)
: function called when time is reached,
arguments:
TypeNameDescriptionvoid *datapointerintremaining_callsremaining calls (-1 if timer has no end)
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_timer_cb (void *data, int remaining_calls)
{
/* ... */
return WEECHAT_RC_OK;
}
/* timer called each 20 seconds */
struct t_hook *my_timer_hook =
weechat_hook_timer (20 * 1000, 0, 0, &my_timer_cb, NULL);
weechat_hook_fd
Prototype:
struct t_hook *weechat_hook_fd (
int fd,
int flag_read,
int flag_write,
int flag_exception,
int (*callback)(void *data, int fd),
void *callback_data);
Hook a file descriptor (file or socket).
Arguments:
: file descriptor
: 1 for catching read event, 0 for
ignoring it
: 1 for catching write event, 0 for
ignoring it
: 1 for catching exception event,
0 for ignoring it
: function called when a selected event
occurs, arguments:
TypeNameDescriptionvoid *datapointerintfdfile descriptor
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_fd_cb (void *data, int fd)
{
/* ... */
return WEECHAT_RC_OK;
}
int sock = socket (AF_INET, SOCK_STREAM, 0);
/* set socket options */
/* ... */
/* hook socket */
struct t_hook *my_fd_hook =
weechat_hook_fd (sock, 1, 0, 0, &my_fd_cb, NULL);
weechat_hook_process
Prototype:
struct t_hook *weechat_hook_process (
const char *command,
int timeout,
int (*callback)(void *data,
const char *command,
int return_code,
const char *stdout,
const char *stderr),
void *callback_data);
Hook a process (with fork), and catch output.
Arguments:
: command to launch in child process
: timeout for command (in milliseconds):
after this timeout, child process is killed (0 means no timeout)
: function called when data from child
is available, or when child has ended, arguments:
TypeNameDescriptionvoid *datapointerconst char *commandcommand executed by childintreturn_code
if >= 0, it's child (command) return code (it's last
call to this callback), if < 0, it can be
WEECHAT_HOOK_PROCESS_OK_RUNNING (data available, but
child still running) or WEECHAT_HOOK_PROCESS_ERROR
(error when launching command).
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_process_cb (void *data, const char *command, int return_code,
const char *stdout, const char *stderr)
{
if (return_code == WEECHAT_HOOK_PROCESS_ERROR)
{
weechat_printf (NULL, "Error with command '%s'", command);
return;
}
if (return_code >= 0)
{
weechat_printf (NULL, "return_code = %d", return_code);
}
if (stdout)
{
weechat_printf (NULL, "stdout: %s", stdout);
}
if (stderr)
{
weechat_printf (NULL, "stderr: %s", stderr);
}
return WEECHAT_RC_OK;
}
struct t_hook *my_process_hook =
weechat_hook_process ("ls", 5000, &my_process_cb, NULL);
weechat_hook_connect
Prototype:
struct t_hook *weechat_hook_connect (
const char *address,
int port,
int sock,
int ipv6,
void *gnutls_sess,
const char *local_hostname,
int (*callback)(void *data,
int status,
const char *ip_address),
void *callback_data);
Hook a connection (background connection to a remote host).
Arguments:
: name or IP address to connect to
: port number
: socket used to connect
: 1 to use IPv6, 0 to use IPv4
: GnuTLS session (optional)
: function called when connection is ok
or failed, arguments:
TypeNameDescriptionvoid *datapointerintstatus
constant with connection status:
WEECHAT_HOOK_CONNECT_OKWEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUNDWEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUNDWEECHAT_HOOK_CONNECT_CONNECTION_REFUSEDWEECHAT_HOOK_CONNECT_PROXY_ERRORWEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERRORWEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERRORWEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERRORWEECHAT_HOOK_CONNECT_MEMORY_ERRORvoid *datapointer
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_connect_cb (void *data, int status, const char *ip_address)
{
switch (status)
{
case WEECHAT_HOOK_CONNECT_OK:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_PROXY_ERROR:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR:
/* ... */
break;
case WEECHAT_HOOK_CONNECT_MEMORY_ERROR:
/* ... */
break;
}
return WEECHAT_RC_OK;
}
struct t_hook *my_connect_hook =
weechat_hook_connect (sock, 1, 0, 0, &my_connect_cb, NULL);
weechat_hook_print
Prototype:
struct t_hook *weechat_hook_print (
struct t_gui_buffer *buffer,
const char *tags,
const char *message,
int strip_colors,
int (*callback)(void *data,
struct t_gui_buffer *buffer,
time_t date,
int tags_count,
const char **tags,
int displayed,
int highlight,
const char *prefix,
const char *message),
void *callback_data);
Hook a message printed.
Arguments:
: buffer pointer, if NULL, messages from
any buffer are caught
: only messages with these tags (comma
separated list) will be caught (optional)
: only messages with this string will be
caught (optional)
: colors will be stripped from
message displayed, before calling callback
: function called when message is
printed, arguments:
TypeNameDescriptionvoid *datapointerstruct t_gui_buffer *bufferbuffer pointertime_tdatedateinttags_countnumber of tags for lineconst char **tagstags for lineintdisplayed
1 if line is displayed, 0 if it is filtered
inthighlight1 if line has highlight, otherwise 0const char *prefixprefixconst char *messagemessage
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_print_cb (void *data, struct t_gui_buffer *buffer, time_t date,
int tags_count, const char **tags,
int displayed, int highlight,
const char *prefix, const char *message)
{
/* ... */
return WEECHAT_RC_OK;
}
/* catch all messages, on all buffers, without color */
struct t_hook *my_print_hook =
weechat_hook_print (NULL, NULL, NULL, 1, &my_print_cb, NULL);
weechat_hook_signal
Prototype:
struct t_hook *weechat_hook_signal (
const char *signal,
int (*callback)(void *data,
const char *signal,
const char *type_data,
void *signal_data),
void *callback_data);
Hook a signal.
Arguments:
: signal to catch. List of signals sent by
WeeChat or plugins:
PluginSignalArgumentsDescriptionircxxx,irc_in_yyy (xxx is server name, yyy is command name)string: messageirc message from server (before irc plugin uses it)ircxxx,irc_in2_yyy (xxx is server name, yyy is command name)string: messageirc message from server (after irc plugin uses it)ircxxx,irc_out_yyy (xxx is server name, yyy is command name)string: messageirc message sent to serverircirc_ctcpstring: messageCTCP receivedircirc_dccstring: messagenew DCCircirc_pvstring: messageprivate message receivedircirc_channel_openedpointer: bufferchannel openedircirc_pvl_openedpointer: bufferprivate openedircirc_server_connectingstring: server nameconnecting to serverircirc_server_connectedstring: server nameconnected to serverircirc_server_disconnectedstring: server namedisconnected from serverircirc_ignore_removingpointer: ignoreremoving ignoreircirc_ignore_removedpointer: ignoreignore removedloggerlogger_startpointer: bufferstart logging for bufferloggerlogger_stoppointer: bufferstop logging for bufferloggerlogger_backlogpointer: bufferdisplay backlog for bufferweechatbuffer_closingpointer: bufferclosing bufferweechatbuffer_closedpointer: bufferbuffer closedweechatbuffer_lines_hiddenpointer: bufferlines hidden in bufferweechatbuffer_localvar_addedpointer: bufferlocal variable has been addedweechatbuffer_localvar_changedpointer: bufferlocal variable has changedweechatbuffer_localvar_removedpointer: bufferlocal variable has been removedweechatbuffer_movedpointer: bufferbuffer movedweechatbuffer_openedpointer: bufferbuffer openedweechatbuffer_renamedpointer: bufferbuffer renamedweechatbuffer_switchpointer: bufferswitching bufferweechatbuffer_title_changedpointer: buffertitle of buffer changedweechatbuffer_type_changedpointer: buffertype of buffer changedweechatdebug_dump-dump requestweechatfilter_addedpointer: new filterfilter addedweechatfilter_removingpointer: filterremoving filterweechatfilter_removedpointer: filterfilter removedweechatfilters_enabled-filters enabledweechatfilters_disabled-filters disabledweechathotlist_changed-hotlist changedweechatinput_paste_pending-paste pendingweechatinput_search-input searchweechatinput_text_changed-input text changedweechatinput_text_cursor_moved-input text cursor movedweechatkey_pressedstring: key pressedkey pressedweechatnicklist_changed-nicklist has changedweechatpartial_completion-partial completion happenedweechatquitarguments for command /quitcommand /quit issued by userweechatupgrade-command /upgrade issued by userweechatweechat_highlightstring: message with prefixhighlight displayedweechatweechat_pvstring: message with prefixprivate message displayedweechatwindow_scrolledpointer: windowscroll in windowweechatwindow_unzoomingpointer: current windowunzooming windowweechatwindow_unzoomedpointer: current windowwindow unzoomedweechatwindow_zoomingpointer: current windowunzooming windowweechatwindow_zoomedpointer: current windowwindow unzoomedxferxfer_addpointer: infolist with xfer infonew xferxferxfer_send_readypointer: infolist with xfer infoxfer ready (file or chat, send)xferxfer_accept_resumepointer: infolist with xfer infoxfer accepts resume (send)xferxfer_send_accept_resumepointer: infolist with xfer infoxfer accepts resume (send)xferxfer_start_resumepointer: infolist with xfer infostart resumexferxfer_resume_readypointer: infolist with xfer infoxfer resume ready
: function called when signal is
received, arguments:
TypeNameDescriptionvoid *datapointerconst char *signalsignal receivedconst char *type_data
type of data sent with signal:
WEECHAT_HOOK_SIGNAL_STRING, WEECHAT_HOOK_SIGNAL_INT
or WEECHAT_HOOK_SIGNAL_POINTER
void *signal_datadata sent with signal
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_signal_cb (void *data, const char *signal, const char *type_data,
void *signal_data)
{
/* ... */
return WEECHAT_RC_OK;
}
/* catch signal "quit", sent by WeeChat when /quit command is executed */
struct t_hook *my_signal_hook =
weechat_hook_signal ("quit", &my_signal_cb, NULL);
weechat_hook_signal_send
Prototype:
void weechat_hook_signal_send (
const char *signal,
const char *type_data,
void *signal_data);
Send a signal.
Arguments:
: signal to send
: type of data sent with signal
(see )
: data sent with signal
Example:
weechat_hook_signal_send ("my_signal", WEECHAT_HOOK_SIGNAL_STRING, my_string);
weechat_hook_config
Prototype:
struct t_hook *weechat_hook_config (
const char *option,
int (*callback)(void *data,
const char *option,
const char *value),
void *callback_data);
Hook a configuration option.
Arguments:
: option, format is full name, as used
with /set command (for example:
weechat.look.item_time_format)
: function called when configuration
option is changed, arguments:
TypeNameDescriptionvoid *datapointerconst char *optionname of optionconst char *valuenew value for option
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_config_cb (void *data, const char *option, const char *value)
{
/* ... */
return WEECHAT_RC_OK;
}
/* catch changes to option "weechat.look.item_time_format" */
struct t_hook *my_config_hook =
weechat_hook_config ("weechat.look.item_time_format",
&my_config_cb, NULL);
weechat_hook_completion
Prototype:
struct t_hook *weechat_hook_completion (
const char *completion_item,
int (*callback)(void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion),
void *callback_data);
Hook a completion.
Arguments:
: name of completion item,
after you can use %(name) in a command hooked
(argument "completion", see
)
: function called when completion item
is used (user is completing something using this item),
arguments:
TypeNameDescriptionvoid *datapointerconst char *completion_itemname of completion itemstruct t_gui_buffer *bufferbuffer where completion was donestruct t_gui_completion *completion
structure used to add words for completion
(see
)
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
int
my_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
/* ... */
return WEECHAT_RC_OK;
}
struct t_hook *my_completion_hook =
weechat_hook_completion ("myitem",
&my_completion_cb, NULL);
weechat_hook_completion_list_add
Prototype:
void weechat_hook_completion_list_add (
struct t_gui_completion *completion,
const char *word,
int nick_completion,
const char *where);
Add a word for a completion.
Arguments:
: completion pointer
: word to add
: 1 if word is a nick, 0 if word
is not a nick
: position where word will be inserted in
list: WEECHAT_LIST_POS_SORT, WEECHAT_LIST_POS_BEGINNING or
WEECHAT_LIST_POS_END
Example:
int
my_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
weechat_hook_completion_list_add (completion, "word1",
0, WEECHAT_LIST_POS_SORT);
weechat_hook_completion_list_add (completion, "test_word2",
0, WEECHAT_LIST_POS_SORT);
return WEECHAT_RC_OK;
}
struct t_hook *my_completion_hook =
weechat_hook_completion ("myitem",
&my_completion_cb, NULL);
weechat_hook_modifier
Prototype:
struct t_hook *weechat_hook_modifier (
const char *modifier,
char *(*callback)(void *data,
const char *modifier,
const char *modifier_data,
const char *string),
void *callback_data);
Hook a modifier.
Arguments:
: modifier name, list of modifiers used
by Weechat or plugins:
PluginModifierModifier dataStringOutputcharsetcharset_decodeplugin.buffer_nameany stringstring decoded from charset found for plugin/buffer to UTF-8charsetcharset_encodeplugin.buffer_nameany stringstring encoded from UTF-8 to charset found for plugin/bufferircirc_color_decode"1" to keep colors, "0" to remove colorsany stringstring with WeeChat color codes, or without colorircirc_color_encode"1" to keep colors, "0" to remove colorsany string, with user colorsstring with IRC color codes, or without colorircirc_in_xxx (xxx is IRC command name)server namecontent of message received from IRC servernew content of messageircirc_out_xxx (xxx is IRC command name)server namecontent of message about to be sent to IRC servernew content of messageweechatinput_text_contentstring with buffer pointer ("0x123..")input buffer (from user)new content of input bufferweechatinput_text_displaystring with buffer pointer ("0x123..")input buffer (from user), without cursor tagnew content of input buffer, for display only (input buffer is not changed)weechatinput_text_display_with_cursorstring with buffer pointer ("0x123..")input buffer (from user), with cursor tagnew content of input buffer, for display only (input buffer is not changed)weechatweechat_printplugin;buffer_name;tagsmessage printednew message printed
: function called when modifier is
received, arguments:
TypeNameDescriptionvoid *datapointerconst char *modifiername of modifierconst char *modifier_datamodifier dataconst char *string
string to modify (function must return copy of this
string, no changes are allowed in this string)
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
char *
my_modifier_cb (void *data, const char *modifier,
const char *modifier_data,
const char *string)
{
char *result;
int length;
if (!string)
return NULL;
length = strlen (string) + 4;
result = malloc (length);
if (result)
{
/* add "xxx" to any message printed */
snprintf (result, length, "%s xxx", string);
}
return result;
}
struct t_hook *my_modifier_hook =
weechat_hook_modifier ("weechat_print",
&my_modifier_cb, NULL);
weechat_hook_modifier_exec
Prototype:
char *weechat_hook_modifier_exec (
const char *modifier,
const char *modifier_data,
const char *string);
Execute modifier(s).
Arguments:
: modifier name
: modifier data
: string to modify
Return value: string modified, NULL if no changes in string were
made by modifier(s).
Example:
char *new_string =
weechat_hook_modifier_exec ("my_modifier", my_data, my_string);
weechat_hook_info
Prototype:
struct t_hook *weechat_hook_info (
const char *info_name,
const char *description,
const char *(*callback)(void *data,
const char *info_name,
const char *arguments),
void *callback_data);
Hook an information: callback will return pointer to info asked.
Arguments:
: name of info
: description
: function called when info is asked,
arguments:
TypeNameDescriptionvoid *datapointerconst char *info_namename of info to returnconst char *argumentsadditional arguments, depending on info
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
const char *
my_info_cb (void *data, const char *info_name, const char *arguments)
{
/* ... */
return pointer_to_string;
}
/* add info "my_info" */
struct t_hook *my_info =
weechat_hook_info ("my_info", "Some info about something",
&my_info_cb, NULL);
weechat_hook_infolist
Prototype:
struct t_hook *weechat_hook_infolist (
const char *infolist_name,
const char *description,
const char *(*callback)(void *data,
const char *infolist_name,
void *pointer,
const char *arguments),
void *callback_data);
Hook an infolist: callback will return pointer to infolist asked.
Arguments:
: name of infolist
: description
: function called when infolist is asked,
arguments:
TypeNameDescriptionvoid *datapointerconst char *infolist_namename of infolist to returnvoid *pointer
pointer to an item infolist must return (to get only
one item in infolist)
const char *argumentsadditional arguments, depending on infolist
: pointer given to callback when it
is called by WeeeChat
Return value: pointer to new hook, NULL if error occured.
Example:
struct t_infolist *
my_infolist_cb (void *data, const char *infolist_name, void *pointer,
const char *arguments)
{
/* ... build infolist ... */
return my_infolist;
}
/* add info "my_infolist" */
struct t_hook *my_infolist =
weechat_hook_infolist ("my_infolist", "Infolist with some data",
&my_infolist_cb, NULL);
weechat_unhook
Prototype:
void weechat_unhook (struct t_hook *hook);
Unhook something hooked.
Arguments:
: something hooked with weechat_hook_xxxx()
Example:
struct t_hook *my_hook = weechat_hook_command (...);
/* ... */
weechat_unhook (my_hook);
weechat_unhook_all
Prototype:
void weechat_unhook_all ();
Unhook everything that has been hooked by current plugin.
Example:
weechat_unhook_all ();
Buffers
Functions to create/query/close buffers.
weechat_buffer_new
Prototype:
struct t_gui_buffer *weechat_buffer_new (
const char *name,
int (*input_callback)(void *data,
struct t_gui_buffer *buffer,
const char *input_data),
void *input_callback_data,
int (*close_callback)(void *data,
struct t_gui_buffer *buffer),
void *close_callback_data);
Open a new buffer.
Arguments:
: name of buffer (must be unique)
: function called when input text
is entered on buffer, arguments:
TypeNameDescriptionvoid *datapointerstruct t_gui_buffer *bufferbuffer pointerconst char *input_datainput data
: pointer given to input
callback when it is called by WeeeChat
: function called when buffer is
closed, arguments:
TypeNameDescriptionvoid *datapointerstruct t_gui_buffer *bufferbuffer pointer
: pointer given to close
callback when it is called by WeeeChat
Return value: pointer to new buffer, NULL if error occured.
Example:
int
my_input_cb (void *data, struct t_gui_buffer *buffer, const char *input_data)
{
weechat_printf (buffer, "Text: %s", input_data);
return WEECHAT_RC_OK;
}
int
my_close_cb (void *data, struct t_gui_buffer *buffer)
{
weechat_printf (NULL, "Buffer '%s' will be closed!",
weechat_buffer_get_string (buffer, "name"));
return WEECHAT_RC_OK;
}
struct t_gui_buffer *my_buffer =
weechat_buffer_new ("my_buffer",
&my_input_cb, NULL, &my_close_cb, NULL);
weechat_current_buffer
Prototype:
struct t_gui_buffer *weechat_current_buffer ();
Return pointer to current buffer (buffer displayed by current window).
Return value: pointer to current buffer.
Example:
struct t_gui_buffer *current_buffer = weechat_current_buffer ();
weechat_buffer_search
Prototype:
struct t_gui_buffer *weechat_buffer_search (const char *plugin, const char *name);
Search a buffer by plugin and/or buffer name.
Arguments:
: name of plugin
: name of buffer. If it is NULL or empty
string, then current buffer is returned (buffer displayed by
current window).
Return value: pointer to buffer found, NULL if not found.
Example:
struct t_gui_buffer *weechat_buffer = weechat_buffer_search ("core", "weechat");
struct t_gui_buffer *my_buffer = weechat_buffer_search ("myplugin", "my_buffer");
weechat_buffer_clear
Prototype:
void weechat_buffer_clear (struct t_gui_buffer *buffer);
Clear content of a buffer.
Arguments:
: buffer pointer
Example:
struct t_gui_buffer *my_buffer = weechat_buffer_search ("myplugin", "my_buffer");
if (my_buffer)
{
weechat_buffer_clear (my_buffer);
}
weechat_buffer_close
Prototype:
void weechat_buffer_close (struct t_gui_buffer *buffer)
Close a buffer.
Arguments:
: buffer pointer
Example:
struct t_gui_buffer *my_buffer =
weechat_buffer_new ("my_buffer",
&my_input_cb, NULL, &my_close_cb, NULL);
/* ... */
weechat_buffer_close (my_buffer);
weechat_buffer_get_integer
Prototype:
int weechat_buffer_get_integer (struct t_gui_buffer *buffer, const char *property);
Get integer value of a buffer property.
Arguments:
: buffer pointer
: property name:
NameDescriptionnumbernumber of buffer (1 to # open buffers)num_displayednumber of windows displaying buffernotifynotify level for bufferlines_hidden
1 if at least one line is hidden on buffer
(filtered), or 0 if all lines are displayed
prefix_max_lengthmax length for prefix in this buffertime_for_each_line
1 if time is displayed for each line in buffer
(default), 0 otherwise
text_search
text search type: 0 = disabled, 1 = backward, 2 = forward
text_search_exact1 if text search is exact (case sensitive)text_search_found1 if text found, 0 otherwise
Return value: integer value of property.
Example:
weechat_printf (NULL, "my buffer number is: %d",
weechat_buffer_get_integer (my_buffer, "number"));
weechat_buffer_get_string
Prototype:
const char *weechat_buffer_get_string (struct t_gui_buffer *buffer, const char *property);
Get string value of a buffer property.
Arguments:
: buffer pointer
: property name:
NameDescriptionplugin
name of plugin which created this buffer ("core" for
WeeChat main buffer)
namename of buffershort_nameshort name of buffertiltetitle of bufferinputinput textlocalvar_xxx
get content of local varialbe "xxx" (replace
"xxx" by the name of variable you want to read)
Return value: string value of property.
Example:
weechat_printf (NULL, "name / short name of buffer are: %s / %s",
weechat_buffer_get_string (my_buffer, "name"),
weechat_buffer_get_string (my_buffer, "short_name"));
weechat_buffer_get_pointer
Prototype:
const char *weechat_buffer_pointer (struct t_gui_buffer *buffer, const char *property);
Get pointer value of a buffer property.
Arguments:
: buffer pointer
: property name:
NameDescriptionpluginplugin pointer
Return value: pointer value of property.
Example:
weechat_printf (NULL, "plugin pointer of my buffer: %lx",
weechat_buffer_get_pointer (my_buffer, "plugin"));
weechat_buffer_set
Prototype:
void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property,
const char *value);
Set string value of a buffer property.
Arguments:
: buffer pointer
: property name:
NameValueDescriptionhotlist
"+", "-", WEECHAT_HOTLIST_LOW, WEECHAT_HOTLIST_MESSAGE,
WEECHAT_HOTLIST_PRIVATE, WEECHAT_HOTLIST_HIGHLIGHT
"+": enable hotlist (global setting, buffer pointer
is not used)
"-": disable hotlist (global setting, buffer pointer
is not used); when hotlist is disabled, messages
printed in buffers does not change hotlist (but
content of current hotlist is not cleared)
priority: add buffer to hotlist with this priority
unreadN/A
set unread marker on current line for buffer
display"1", "auto"
swtich to this buffer in current window (if value is
"auto", then it's considered as auto-switch and read
marker is not reset for current buffer)
nameany stringset new name for buffershort_nameany stringset new short name for buffertype"formated" or "free"
set type for buffer: "formated" (for printing
chat messages), or "free" for free content
notify"0", "1", "2", "3"
set notify level for buffer: "0" = never add to hotlist,
"1" = add for highlights only, "2" = add for highlights
and messages, "3" = add for ell messages
titleany stringset new title for buffertime_for_each_line"0" or "1"
"0" to hide time for all lines in buffer, "1" to
see time for all lines (default for a new buffer)
nicklist"0" or "1"
"0" to remove nicklist for buffer, "1" to add
nicklist for buffer
nicklist_case_sensitive"0" or "1"
"0" to have case insensitive nicklist, "1" to have
case sensitive nicklist
nicklist_display_groups"0" or "1"
"0" to hide nicklist groups, "1" to display nicklist
groups
highlight_words"-" or comma separated list of words
"-" is a special value to disable any highlight on this
buffer, or comma separated list of words to higlkight
in this buffer, for example: "abc,def,ghi"
highlight_tagscomma separated list of tags
comma separated list of tags to highlight in this
buffer
key_bind_xxxany string
bind a new key, specific to this buffer (replace "xxx"
by the key, for example "meta-I" to bind alt+i) ; the
value is text or command to execute
key_bind_xxxN/A
unbind a key (which was bound with above property)
inputany stringset new value for buffer inputinput_get_unknown_commands"0" or "1"
"0" to disable unknown commands on this buffer
(default behaviour), "1" to get unknown commands,
for example if user type "/unknowncmd", buffer will
receive it (no error about unknown command)
localvar_set_xxxany string
set new value for a local variable (replace "xxx" by
variable name) ; variable is created if it does not
exist
localvar_del_xxxany string
remove a local variable (replace "xxx" by variable name)
Example:
/* disable hotlist (for all buffers) */
weechat_buffer_set (NULL, "hotlist", "-");
/* enable again hotlist */
weechat_buffer_set (NULL, "hotlist", "+");
/* change buffer name */
weechat_buffer_set (my_buffer, "name", "my_new_name");
/* add new local variable "toto" with value "my_value" */
weechat_buffer_set (my_buffer, "localvar_set_toto", "my_value");
/* remove local variable "toto" */
weechat_buffer_set (my_buffer, "localvar_del_toto", NULL);
weechat_buffer_set_pointer
Prototype:
void weechat_buffer_set_pointer (struct t_gui_buffer *buffer, const char *property,
void *pointer);
Set pointer value of a buffer property.
Arguments:
: buffer pointer
: property name:
NameValueDescriptionclose_callbackclose callback functionclose callback functionclose_callback_dataclose callback data pointerclose callback data pointerinput_callbackinput callback functioninput callback functioninput_callback_datainput callback data pointerinput callback data pointer
Example:
int
my_close_cb (void *data, struct t_gui_buffer *buffer)
{
/* ... */
return WEECHAT_RC_OK;
}
weechat_buffer_set_pointer (NULL, "close_callback", &my_close_cb);
weechat_buffer_string_replace_local_var
Prototype:
char *weechat_buffer_string_replace_local_var (struct t_gui_buffer *buffer,
const char *string);
Replace local variables in a string by their value, using buffer local
variables.
Arguments:
: buffer pointer
: string with text and local variables
using format "$var"
Return value: string with value for local variables.
Result has to be free by a call to "free" after use.
Example:
weechat_buffer_set (my_buffer, "localvar_set_toto", "my_value");
char *str = weechat_buffer_string_replace_local_var (my_buffer,
"test with $toto");
/* str contains "test with my_value" */
/* ... */
free (str);
Windows
Functions to query windows.
weechat_current_window
Prototype:
struct t_gui_window *weechat_current_window ();
Return pointer to current window.
Return value: pointer to current window.
Example:
struct t_gui_window *current_window = weechat_current_window ();
weechat_window_get_integer
Prototype:
int weechat_window_get_integer (struct t_gui_window *window, const char *property);
Get integer value of a window property.
Arguments:
: window pointer
: property name:
NameDescriptionwin_x
X position of window in terminal (0 is first column)
win_y
Y position of window in terminal (0 is first column)
win_widthwidth of window, in charswin_heightheight of window, in charswin_width_pct
percentage size, compared to parent window (if 50,
width is half)
win_height_pct
percentage size, compared to parent window (if 50,
height is half)
win_chat_x
X position of chat window in terminal (0 is first
column)
win_chat_y
Y position of chat window in terminal (0 is first
column)
win_chat_widthwidth of chat window, in charswin_chat_heightheight of chat window, in charsfirst_line_displayed
1 if first line of buffer is displayed on screen,
otherwise 0
scroll
1 if scroll is active on window (last line not
displayed)
scroll_lines_after
number of lines not displayed after last one displayed
(when scrolling)
Return value: integer value of property.
Example:
weechat_printf (NULL, "current window is at position (x,y): (%d,%d)",
weechat_window_get_integer (weechat_current_window, "win_x"),
weechat_window_get_integer (weechat_current_window, "win_y"));
weechat_window_get_string
Prototype:
const char *weechat_window_get_string (struct t_gui_window *window, const char *property);
Get string value of a window property. NOT USED TODAY, reserved for
future version.
Arguments:
: window pointer
: property name
Return value: string value of property.
weechat_window_get_pointer
Prototype:
void *weechat_window_get_pointer (struct t_gui_window *window, const char *property);
Get pointer value of a window property.
Arguments:
: window pointer
: property name:
NameDescriptioncurrentcurrent window pointerbufferpointer to buffer displayed by window
Return value: pointer value of property.
Example:
weechat_printf (NULL, "current window pointer is: %lx, buffer displayed is: %lx",
weechat_window_get_pointer (NULL, "current"),
weechat_window_get_integer (weechat_current_window, "buffer"));
Nicklist
Functions for buffer nicklist.
weechat_nicklist_add_group
Prototype:
struct t_gui_nick_group *weechat_nicklist_add_group (
struct t_gui_buffer *buffer,
struct t_gui_nick_group *parent_group,
const char *name,
const char *color,
int visible);
Add a group in a nicklist.
Arguments:
: buffer pointer
: pointer to parent of group, NULL
if group has no parent (nicklist root)
: group name
: 1 if group and sub-groups/nicks are
visible, 0 if they are hidden
: color option name
("weechat.color.xxx" or "file.section.option") or color name
("blue", "red",..) or "bar_fg"/"bar_bg"/"bar_delim" (bar
foreground/background/delimiter)
The group name can begin with one or more digits, followed by pipe,
and then group name. When such string is found at beginning, it's
used to sort groups in nicklist. For examples groups "1|test" and
"2|abc" will be sorted: "test" first, "abc" second, whereas "test"
and "abc" will be sorted: "abc" first, "test" second.
Return value: pointer to new group, NULL if an error occured.
Example:
struct t_gui_nick_group *my_group =
weechat_nicklist_add_group (my_buffer, my_parent_group,
"test_group", "weechat.color.nicklist_group", 1);
weechat_nicklist_search_group
Prototype:
struct t_gui_nick_group *weechat_nicklist_search_group (
struct t_gui_buffer *buffer,
struct t_gui_nick_group *from_group,
const char *name);
Search a group in a nicklist.
Arguments:
: buffer pointer
: search from this group only, if NULL,
then search in whole nicklist
: group name to search
Return value: pointer to group found, NULL if not found.
Example:
struct t_gui_nick_group *ptr_group =
weechat_nicklist_search_group (my_buffer, NULL, "test_group");
weechat_nicklist_add_nick
Prototype:
struct t_gui_nick_group *weechat_nicklist_add_nick (
struct t_gui_buffer *buffer,
struct t_gui_nick_group *group,
const char *name,
const char *color,
const char *prefix,
const char *prefix_color,
int visible);
Add a nick in a group.
Arguments:
: buffer pointer
: group pointer
: nick name
: color option name
("weechat.color.xxx" or "file.section.option") or color name
("blue", "red",..) or "bar_fg"/"bar_bg"/"bar_delim" (bar
foreground/background/delimiter)
: prefix displayed before nick
: color option name
("weechat.color.xxx" or "file.section.option") or color name
("blue", "red",..) or "bar_fg"/"bar_bg"/"bar_delim" (bar
foreground/background/delimiter)
: 1 if nick is visible, 0 if it is hidden
Return value: pointer to new nick, NULL if an error occured.
Example:
struct t_gui_nick *my_nick =
weechat_nicklist_add_nick (my_buffer, my_group,
"test_nick",
(nick_away) ? "weechat.color.nicklist_away" : "bar_fg",
"@", "lightgreen",
1);
weechat_nicklist_search_nick
Prototype:
struct t_gui_nick *weechat_nicklist_search_nick (
struct t_gui_buffer *buffer,
struct t_gui_nick_group *from_group,
const char *name);
Search a nick in a nicklist.
Arguments:
: buffer pointer
: search from this group only, if NULL,
then search in whole nicklist
: nick name to search
Return value: pointer to nick found, NULL if not found.
Example:
struct t_gui_nick *ptr_nick =
weechat_nicklist_search_nick (my_buffer, NULL, "test_nick");
weechat_nicklist_remove_group
Prototype:
void weechat_nicklist_remove_group (
struct t_gui_buffer *buffer,
struct t_gui_nick_group *group);
Remove a group from a nicklist.
Arguments:
: buffer pointer
: group pointer to remove (all
sub-groups/nicks will be removed too)
Example:
weechat_nicklist_remove_group (my_buffer, my_group);
weechat_nicklist_remove_nick
Prototype:
void weechat_nicklist_remove_nick (
struct t_gui_buffer *buffer,
struct t_gui_nick *nick);
Remove a nick from a nicklist.
Arguments:
: buffer pointer
: nick pointer to remove
Example:
weechat_nicklist_remove_nick (my_buffer, my_nick);
weechat_nicklist_remove_all
Prototype:
void weechat_nicklist_remove_all (struct t_gui_buffer *buffer);
Remove all groups/nicks from a nicklist.
Arguments:
: buffer pointer
Example:
weechat_nicklist_remove_all (my_buffer);
Bars
Functions for bars.
weechat_bar_item_search
Prototype:
struct t_gui_bar_item *weechat_bar_item_search (const char *name);
Search a bar item.
Arguments:
: bar item name
Return value: pointer to bar item found, NULL if bar item was not found.
Example:
struct t_gui_bar_item *bar_item = weechat_bar_item_search ("myitem");
weechat_bar_item_new
Prototype:
struct t_gui_bar_item *weechat_bar_item_new (
const char *name,
char *(build_callback)(void *data,
struct t_gui_bar_item *item,
struct t_gui_window *window),
void *build_callback_data);
Create a new bar item.
Arguments:
: bar item name
: function called when bar item
is built: it must return content of bar item
: pointer given to build
callback, when it is called by Weechat
Return value: pointer to new bar item, NULL if an error occured.
Example:
char *
my_build_callback (void *data,
struct t_gui_bar_item *item,
struct t_gui_window *window)
{
return strdup ("my content");
}
struct t_gui_bar_item *my_item = weechat_bar_item_new ("myitem",
&my_build_callback,
NULL);
weechat_bar_item_update
Prototype:
void weechat_bar_item_update (const char *name);
Update content of a bar item, by calling its build callback.
Arguments:
: bar item name
Example:
weechat_bar_item_update ("myitem");
weechat_bar_item_remove
Prototype:
void weechat_bar_item_remove (struct t_gui_bar_item *item);
Remove a bar item.
Arguments:
: bar item pointer
Example:
weechat_bar_item_remove (&my_item);
weechat_bar_search
Prototype:
struct t_gui_bar_item *weechat_bar_search (const char *name);
Search a bar.
Arguments:
: bar name
Return value: pointer to bar found, NULL if bar was not found.
Example:
struct t_gui_bar *bar = weechat_bar_search ("mybar");
weechat_bar_new
Prototype:
struct t_gui_bar *weechat_bar_new (
const char *name,
const char *hidden,
const char *priority,
const char *type,
const char *condition,
const char *position,
const char *filling_top_bottom,
const char *filling_left_right,
const char *size,
const char *size_max,
const char *color_fg,
const char *color_delim,
const char *color_bg,
const char *separator,
const char *items);
Create a new item.
Arguments:
: bar item name
: "on" if bar is hidden, "off" is bar is
visible
: bar priority (integer)
: "root" (bar displayed once, outside
windows), or "window" (bar displayed in each window)
: condition for displaying bar, one of
following:
ConditionDescriptionactive
bar is displayed in active window only
inactive
bar is displayed in inactive window(s) only
nicklistbar is displayed in window(s) with nicklist
: "top", "bottom", "left" or "right"
: filling when bar is in
position "top" or "bottom", one of following:
FillingDescriptionhorizontal
items are filled horitontally (space after each item)
vertical
items are filled verticaly (new line after each item)
columns_horizontal
items are filled horizontally, displayed with columns
columns_vertical
items are filled vertically, displayed with columns
: filling when bar is in
position "left" or "right", one of following:
FillingDescriptionhorizontal
items are filled horitontally (space after each item)
vertical
items are filled verticaly (new line after each item)
columns_horizontal
items are filled horizontally, displayed with columns
columns_vertical
items are filled vertically, displayed with columns
: bar size in chars (0 means automatic
size)
: max size for bar (0 means no max size)
: color for text in bar
: color for delimiters in bar
: background color for bar
: "on" if bar has separator line with
other windows/bars, "off" otherwise
: list of items in bar, separated by comma
(space between items), or "+" (glued items)
Return value: pointer to new bar, NULL if an error occured.
Example:
struct t_gui_bar *my_bar =
weechat_bar_new ("mybar",
"off",
100,
"window",
"",
"top",
"horizontal",
"vertical",
"0",
"5",
"default",
"cyan",
"blue",
"off",
"time,buffer_number+buffer_name");
weechat_bar_set
Prototype:
int weechat_bar_set (struct t_gui_bar *bar,
const char *property,
const char *value);
Set a new value for a bar property.
Arguments:
: bar pointer
: property name: name, hidden, priority,
conditions, position, filling_top_bottom, filling_left_right,
size, size_max, color_fg, color_delim, color_bg, separator, items
(see )
: new value for property
Return value: 1 if new value was set, 0 if an error occured.
Example: weechat_bar_set (mybar, "position", "bottom");weechat_bar_update
Prototype:
void weechat_bar_update (const char *name);
Refresh content of a bar on screen.
Arguments:
: bar name
Example: weechat_bar_update ("mybar");weechat_bar_remove
Prototype:
void weechat_bar_remove (struct t_gui_bar *bar);
Remove a bar.
Arguments:
: bar pointer
Example: weechat_bar_remove (mybar);Commands
Functions for executing WeeChat commands.
weechat_command
Prototype:
void weechat_command (struct t_gui_buffer *buffer,
const char *command);
Execute a command.
Arguments:
: buffer pointer (command is executed
on this buffer, use NULL for WeeChat core buffer)
: command to execute (if beginning with a
"/"), or text is sent to buffer (without leading "/")
Example:
weechat_command (weechat_buffer_search ("irc", "freenode.#weechat"),
"/whois FlashCode");
Network
Network functions.
weechat_network_pass_proxy
Prototype:
int weechat_network_pass_proxy (const char *proxy,
int sock,
const char *address,
int port);
Establish a connection/authentification to a proxy.
Arguments:
: proxy name to use
: socket to use
: address (hostname or IP)
: port
Return value: 1 if connection is ok, 0 if an error occured.
Example:
if (weechat_network_pass_proxy ("myproxy", sock, "irc.freenode.net", 6667))
{
/* OK */
}
else
{
/* error */
}
weechat_network_network_connect_to
Prototype:
int weechat_network_connect_to (const char *proxy,
int sock,
unsigned long address,
int port);
Establish a connection to a remote host.
Arguments:
: proxy name to use
: socket to use
: address
: port
Return value: 1 if connection is ok, 0 if an error occured.
Example:
struct sockaddr_in addr;
socklen_t length;
unsigned long address;
memset (&addr, 0, sizeof (struct sockaddr_in));
length = sizeof (addr);
getsockname (sock, (struct sockaddr *) &addr, &length);
addr.sin_family = AF_INET;
address = ntohl (addr.sin_addr.s_addr);
if (weechat_network_connect_to (NULL, sock, address, 6667))
{
/* OK */
}
else
{
/* error */
}
Infos
Functions to get infos.
weechat_info_get
Prototype:
const char *weechat_info_get (const char *info_name,
const char *arguments);
Get info from WeeChat or a plugin.
Arguments:
: name of info to read:
PluginNameDescription
&infos.xml;
: arguments for info asked (optional,
NULL if no argument is needed)
Return value: const string with info asked, NULL if an error occured.
Example:
weechat_printf (NULL, "Current WeeChat version is: %s (compiled on %s)",
weechat_info_get ("version", NULL),
weechat_info_get ("date", NULL));
weechat_printf (NULL, "WeeChat home is: %s",
weechat_info_get ("weechat_dir"));
Infolists
Infolists functions.
An infolist is a list of "items". Each item contains variables.
For example, infolist "irc_server" has N items (N is number of IRC
servers defined). For each item, there is variables like "name",
"buffer", "is_connected", ...
Each variable has a type and a value. Possible types are:
TypeDescriptionintegerany integer valuestringany string valuepointerany pointerbufferbuffer with fixed length, containing any datatimetime valueweechat_infolist_new
Prototype:
struct t_infolist *weechat_infolist_new ();
Create a new infolist.
Return value: pointer to new infolist.
Example:
struct t_infolist *infolist = weechat_infolist_new ();weechat_infolist_new_item
Prototype:
struct t_infolist_item *weechat_infolist_new_item (struct t_infolist *infolist);
Add an item in an infolist.
Arguments:
: infolist pointer
Return value: pointer to new item.
Example:
struct t_infolist_item *item = weechat_infolist_new_item (infolist);
weechat_infolist_new_var_integer
Prototype:
struct t_infolist_var *weechat_infolist_new_var_integer (
struct t_infolist_item *item,
const char *name,
int value);
Add an integer variable to an infolist item.
Arguments:
: infolist item pointer
: variable name
: integer value
Return value: pointer to new variable.
Example:
struct t_infolist_var *var =
weechat_infolist_new_variable_integer (item, "my_integer", 123);
weechat_infolist_new_var_string
Prototype:
struct t_infolist_var *weechat_infolist_new_var_string (
struct t_infolist_item *item,
const char *name,
const char *value);
Add a string variable to an infolist item.
Arguments:
: infolist item pointer
: variable name
: string value
Return value: pointer to new variable.
Example:
struct t_infolist_var *var =
weechat_infolist_new_variable_string (item, "my_string", "value here");
weechat_infolist_new_var_pointer
Prototype:
struct t_infolist_var *weechat_infolist_new_var_pointer (
struct t_infolist_item *item,
const char *name,
void *pointer);
Add a pointer variable to an infolist item.
Arguments:
: infolist item pointer
: variable name
: pointer
Return value: pointer to new variable.
Example:
struct t_infolist_var *var =
weechat_infolist_new_variable_pointer (item, "my_pointer", &something);
weechat_infolist_new_var_buffer
Prototype:
struct t_infolist_var *weechat_infolist_new_var_buffer (
struct t_infolist_item *item,
const char *name,
void *pointer,
int size);
Add a buffer variable to an infolist item.
Arguments:
: infolist item pointer
: variable name
: pointer to buffer
: size of buffer
Return value: pointer to new variable.
Example:
char buffer[256];
/* ... */
struct t_infolist_var *var =
weechat_infolist_new_variable_buffer (item, "my_buffer",
&buffer, sizeof (buffer));
weechat_infolist_new_var_time
Prototype:
struct t_infolist_var *weechat_infolist_new_var_time (
struct t_infolist_item *item,
const char *name,
time_t time);
Add a time variable to an infolist item.
Arguments:
: infolist item pointer
: variable name
: time value
Return value: pointer to new variable.
Example:
struct t_infolist_var *var =
weechat_infolist_new_variable_time (item, "my_time", time (NULL));
weechat_infolist_get
Prototype:
struct t_infolist *weechat_infolist_get (const char *infolist_name,
void *pointer,
const char *arguments);
Get infolist from WeeChat or a plugin.
Arguments:
: name of infolist to read:
PluginNameDescription
&infolists.xml;
: pointer to an item, to get only this
item in infolist (optional, can be NULL)
: name/type of item to retrieve
(optional, can be NULL)
Return value: pointer to infolist, NULL if an error occured.
Example:
struct t_infolist *infolist = weechat_infolist_get ("irc_server", NULL, NULL);
weechat_infolist_next
Prototype:
int weechat_infolist_next (struct t_infolist *infolist);
Move "cursor" to next item in an infolist. The first call to this
function for an infolist moves cursor to first item in infolist.
Arguments:
: infolist pointer
Return value: 1 if pointer is now on next item, 0 if end of list was
reached.
Example:
if (weechat_infolist_next (infolist))
{
/* read variables in item... */
}
else
{
/* no more item available */
}
weechat_infolist_prev
Prototype:
int weechat_infolist_prev (struct t_infolist *infolist);
Move "cursor" to previous item in an infolist. The first call to this
function for an infolist moves cursor to last item in infolist.
Arguments:
: infolist pointer
Return value: 1 if pointer is now on previous item, 0 if beginning of
list was reached.
Example:
if (weechat_infolist_prev (infolist))
{
/* read variables in item... */
}
else
{
/* no more item available */
}
weechat_infolist_reset_item_cursor
Prototype:
void weechat_infolist_reset_item_cursor (struct t_infolist *infolist);
Reset "cursor" for infolist.
Arguments:
: infolist pointer
Example: weechat_infolist_reset_item_cursor (infolist);weechat_infolist_fields
Prototype:
const char *weechat_infolist_fields (struct t_infolist *infolist);
Get list of fields for current infolist item.
Arguments:
: infolist pointer
Return value: string with list of fields for current infolist item.
List is comma separated, and contains letter for type, followed by
variable name. Types are: "i" (integer), "s" (string), "p" (pointer),
"b" (buffer), "t" (time).
Example:
const char *fields = weechat_infolist_fields (infolist);
/* fields contains something like:
"i:my_integer,s:my_string,p:my_pointer,b:my_buffer,t:my_time" */
weechat_infolist_integer
Prototype:
int weechat_infolist_integer (struct t_infolist *infolist,
const char *var);
Get value of integer variable in current infolist item.
Arguments:
: infolist pointer
: variable name (must be type "integer")
Return value: integer value of variable.
Example:
weechat_printf (NULL, "integer value = %d",
weechat_infolist_integer (infolist, "my_integer"));
weechat_infolist_string
Prototype:
const char *weechat_infolist_string (struct t_infolist *infolist,
const char *var);
Get value of string variable in current infolist item.
Arguments:
: infolist pointer
: variable name (must be type "string")
Return value: string value of variable.
Example:
weechat_printf (NULL, "string value = %s",
weechat_infolist_string (infolist, "my_string"));
weechat_infolist_pointer
Prototype:
void *weechat_infolist_pointer (struct t_infolist *infolist,
const char *var);
Get value of pointer variable in current infolist item.
Arguments:
: infolist pointer
: variable name (must be type "pointer")
Return value: pointer value of variable.
Example:
weechat_printf (NULL, "pointer value = 0x%lx",
weechat_infolist_pointer (infolist, "my_pointer"));
weechat_infolist_buffer
Prototype:
void *weechat_infolist_buffer (struct t_infolist *infolist,
const char *var,
int *size);
Get value of buffer variable in current infolist item.
Arguments:
: infolist pointer
: variable name (must be type "buffer")
: pointer to integer variable, will be set
with buffer size
Return value: buffer pointer.
Example:
int size;
void *pointer = weechat_infolist_buffer (infolist, "my_buffer", &size);
weechat_printf (NULL, "buffer pointer = 0x%lx, size = %d",
pointer, size);
weechat_infolist_time
Prototype:
time_t weechat_infolist_time (struct t_infolist *infolist,
const char *var);
Get value of time variable in current infolist item.
Arguments:
: infolist pointer
: variable name (must be type "time")
Return value: time value of variable.
Example:
weechat_printf (NULL, "time value = 0x%ld",
weechat_infolist_time (infolist, "my_time"));
weechat_infolist_free
Prototype:
void weechat_infolist_free (struct t_infolist *infolist);
Free an infolist.
Arguments:
: infolist pointer
Example:
weechat_infolist_free (infolist);Upgrade
Functions for WeeChat upgrading.
weechat_upgrade_new
Prototype:
struct t_upgrade_file *weechat_upgrade_new (const char *filename,
int write);
Create or read a file for upgrade.
Arguments:
: name of file (extension ".upgrade"
will be added to this name by WeeChat)
: 1 to create file (write mode, before
upgrade), 0 to read file (after upgrade)
Return value: pointer to new upgrade file.
Example:
struct t_upgrade_file *upgrade_file = weechat_upgrade_new ("my_file");
weechat_upgrade_write_object
Prototype:
struct t_upgrade_file *weechat_upgrade_write_object (
struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist);
Write an object in upgrade file.
Arguments:
: upgrade file pointer
: id for object
: infolist to write in file
Return value: 1 if ok, 0 if error.
Example:
weechat_upgrade_write_object (upgrade_file, 1, &infolist);
weechat_upgrade_read
Prototype:
struct t_upgrade_file *weechat_upgrade_read (
struct t_upgrade_file *upgrade_file,
int (*callback_read)(void *data,
struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist),
void *callback_read_data);
Read an upgrade file.
Arguments:
: upgrade file pointer
: callback called for each object
read in upgrade file
: pointer given to read
callback when it is called by WeeChat
Return value: 1 if ok, 0 if error.
Example:
int
my_upgrade_read_cb (struct t_upgrade_file *upgrade_file,
int object_id,
struct t_infolist *infolist)
{
/* read variables... */
return WEECHAT_RC_OK;
}
weechat_upgrade_read (upgrade_file, &my_upgrade_read_cb, NULL);
weechat_upgrade_close
Prototype:
void weechat_upgrade_close (struct t_upgrade_file *upgrade_file);
Close an upgrade file.
Arguments:
: upgrade file pointer
Example: weechat_upgrade_close (upgrade_file);