Translators:

Questo manuale documenta il client di chat WeeChat, ed è parte del programma stesso.

La versione più recente di questo documento si trova qui: https://weechat.org/doc

1. Introduzione

WeeChat (Wee Enhanced Environment for Chat) è un client di chat libero, veloce e leggero, realizzato per molti sistemi operativi.

Questo manuale documenta le API per i plugin di WeeChat, utilizzate dai plugin C per interagire con il core di WeeChat.

2. Plugin in WeeChat

Un plugin è un programma C che può richiamare le funzioni di WeeChat definite in un’interfaccia.

Questo programma C non richiede i sorgenti di WeeChat per essere compilato e può essere caricato dinamicamente in WeeChat con il comano /plugin.

Il plugin deve essere una libreria dinamica, per essere caricato dinamicamente dal del sistema operativo. In GNU/Linux, il file ha estensione ".so", ".dll" in Windows.

Il plugin deve includere il file "weechat-plugin.h" (disponibile nel codice sorgente di WeeChat). Il file definisce strutture e tipi utilizzati per comunicare con WeeChat.

In order to call WeeChat functions in the format displayed in Plugin API, the following global pointer must be declared and initialized in the function weechat_plugin_init:

struct t_weechat_plugin *weechat_plugin;

2.1. Macro

Il plugin deve utilizzare alcune macro (per definire alcune variabili):

WEECHAT_PLUGIN_NAME("nome")

nome del plugin

WEECHAT_PLUGIN_DESCRIPTION("descrizione")

breve descrizione del plugin

WEECHAT_PLUGIN_VERSION("1.0")

versione del plugin

WEECHAT_PLUGIN_LICENSE("GPL3")

licenza del plugin

WEECHAT_PLUGIN_PRIORITY(1000)

the plugin priority (optional, see below)

2.2. Funzioni principali

Il plugin deve usare due funzioni:

  • weechat_plugin_init

  • weechat_plugin_end

2.2.1. weechat_plugin_init

Questa funzione viene chiamata quando il plugin è caricato. da WeeChat.

Prototipo:

int weechat_plugin_init (struct t_weechat_plugin *plugin,
                         int argc, char *argv[]);

Argomenti:

  • plugin: puntatore alla struttura del plugin di WeeChat, used to initialize the convenience global pointer weechat_plugin

  • argc: numero di argomenti per il plugin

  • argv: argomenti per il plugin (see below)

Valori restituiti:

  • WEECHAT_RC_OK se l’operazione ha successo (il plugin verrà caricato)

  • WEECHAT_RC_ERROR se c’è un errore (il plugin NON verrà caricato)

Plugin arguments

When the plugin is loaded by WeeChat, it receives the list of arguments in parameter argv and the number of arguments in argc.

The arguments can be:

  • command line arguments when running the WeeChat binary,

  • arguments given to the command /plugin load xxx, when the plugin is manually loaded by the user.

When the arguments come from the command line, only these arguments are sent to the plugin:

-a, --no-connect

Disabilita la connessione automatica ai server all’avvio di WeeChat.

-s, --no-script

Disabilita il caricamento automatico dei script.

plugin:option

Option for a plugin: only the plugin-related options are sent, for example only the options starting with irc: are sent to the plugin called "irc".

Plugin priority

When plugins are auto-loaded (for example on startup), WeeChat first loads all plugins, and then calls the init functions, using the priority defined in each plugin. A high priority means that the init function is called first.

Default priority is 1000 (with such priority, the plugin is loaded after all default plugins).

The default WeeChat plugins are initialized in this order:

  1. charset (15000)

  2. logger (14000)

  3. exec (13000)

  4. trigger (12000)

  5. spell (11000)

  6. alias (10000)

  7. buflist (9000)

  8. fifo (8000)

  9. xfer (7000)

  10. irc (6000)

  11. relay (5000)

  12. guile, javascript, lua, perl, php, python, ruby, tcl (4000)

  13. script (3000)

  14. fset (2000)

2.2.2. weechat_plugin_end

Questa funzione viene chiamata quando il plugin viene scaricato da WeeChat.

Prototipo:

int weechat_plugin_end (struct t_weechat_plugin *plugin);

Argomenti:

  • plugin: puntatore alla struttura plugin di WeeChat

Valori restituiti:

  • WEECHAT_RC_OK se l’operazione ha successo

  • WEECHAT_RC_ERROR se c’è un errore

2.3. Compilazione del plugin

La compilazione non richiede i sorgenti di WeeChat, è richiesto solo il file weechat-plugin.h.

Per compilare un plugin che ha un file "tizio.c" (in GNU/Linux):

$ gcc -fPIC -Wall -c tizio.c
$ gcc -shared -fPIC -o tizio.so tizio.o

2.4. Caricamento del plugin

Copiare il file tizio.so nella cartella plugin di sistema (ad esempio /usr/local/lib/weechat/plugins) oppure nella cartella plugin dell’utente (ad esempio /home/xxx/.weechat/plugins).

In WeeChat:

/plugin load tizio

2.5. Plugin di esempio

Un esempio completo di plugin, che aggiunge un comando /double: visualizza due volte gli argomenti nel buffer corrente, oppure esegue un comando due volte (ok, non sarà molto utile, ma è solo un esempio!):

#include <stdlib.h>

#include "weechat-plugin.h"

WEECHAT_PLUGIN_NAME("double");
WEECHAT_PLUGIN_DESCRIPTION("Test plugin for WeeChat");
WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu <flashcode@flashtux.org>");
WEECHAT_PLUGIN_VERSION("0.1");
WEECHAT_PLUGIN_LICENSE("GPL3");

struct t_weechat_plugin *weechat_plugin = NULL;


/* callback per il comando "/double" */

int
command_double_cb (const void *pointer, void *data,
                   struct t_gui_buffer *buffer,
                   int argc, char **argv, char **argv_eol)
{
    /* fa felice il compilatore C */
    (void) pointer;
    (void) data;
    (void) buffer;
    (void) argv;

    if (argc > 1)
    {
        weechat_command (NULL, argv_eol[1]);
        weechat_command (NULL, argv_eol[1]);
    }

    return WEECHAT_RC_OK;
}

int
weechat_plugin_init (struct t_weechat_plugin *plugin,
                     int argc, char *argv[])
{
    weechat_plugin = plugin;

    weechat_hook_command ("double",
                          "Visualizza due volte un messaggio "
                          "oppure esegue un comando due volte",
                          "messaggio | comando",
                          "messaggio: messaggio da visualizzare due volte\n"
                          "comando: comando da eseguire due volte",
                          NULL,
                          &command_double_cb, NULL, NULL);

    return WEECHAT_RC_OK;
}

int
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
    /* fa felice il compilatore C */
    (void) plugin;

    return WEECHAT_RC_OK;
}

3. Plugin API

I capitoli seguenti descrivono le funzioni nelle API, organizzate in categorie.

Per ogni funzione, viene fornita:

  • descrizione della funzione,

  • prototipo C,

  • dettaglio degli argomenti,

  • valore restituito,

  • esempio C,

  • esempio nello script Python (la sintassi è simile per gli altri linguaggi di scripting).

3.1. Registering

Functions to register a script: used only by scripting API, not the C API.

3.1.1. register

Register the script.

For more information, see the WeeChat scripting guide.

Script (Python):

# prototype
weechat.register(name, author, version, license, description, shutdown_function, charset)
Note
This function is not available in the C API.

3.2. Plugin

Funzioni per ottenere informazioni sui plugin.

3.2.1. plugin_get_name

Ottiene il nome del plugin.

Prototipo:

const char *weechat_plugin_get_name (struct t_weechat_plugin *plugin);

Argomenti:

  • plugin: puntatore alla struttura plugin di WeeChat (può essere NULL)

Valore restituito:

  • nome del plugin, "core" per il core di WeeChat (se il puntatore al plugin è NULL)

Esempio in C:

const char *name = weechat_plugin_get_name (plugin);

Script (Python):

# prototipo
name = weechat.plugin_get_name(plugin)

# esempio
plugin = weechat.buffer_get_pointer(weechat.current_buffer(), "plugin")
name = weechat.plugin_get_name(plugin)

3.3. Stringhe

Molte delle funzioni stringa che seguono sono già disponibili tramite funzioni standard in C, ma si raccomanda di utilizzare le funzioni in questa API perché compatibili con UTF-8 e il locale.

3.3.1. charset_set

Imposta il nuovo set caratteri del nuovo plugin (il set caratteri predefinito è UTF-8, così se il plugin usa UTF-8 non è necessario chiamare questa funzione).

Prototipo:

void weechat_charset_set (const char *charset);

Argomenti:

  • charset: nuovo set caratteri da usare

Esempio in C:

weechat_charset_set ("iso-8859-1");

Script (Python):

# prototipo
weechat.charset_set(charset)

# esempio
weechat.charset_set("iso-8859-1")

3.3.2. iconv_to_internal

Converte le stringhe per il set caratteri interno di WeeChat (UTF-8).

Prototipo:

char *weechat_iconv_to_internal (const char *charset, const char *string);

Argomenti:

  • charset: set caratteri da convertire

  • string: stringa da convertire

Valore restituito:

  • la stringa convertita (deve essere liberata richiamando "free" dopo l’utilizzo)

Esempio in C:

char *str = weechat_iconv_to_internal ("iso-8859-1", "iso string: é à");
/* ... */
free (str);

Script (Python):

# prototipo
str = weechat.iconv_to_internal(charset, string)

# esempio
str = weechat.iconv_to_internal("iso-8859-1", "iso string: é à")

3.3.3. iconv_from_internal

Converte la stringa dal set caratteri interno di WeeChat (UTF-8) in un’altra.

Prototipo:

char *weechat_iconv_from_internal (const char *charset, const char *string);

Argomenti:

  • charset: set caratteri in uscita

  • string: stringa da convertire

Valore restituito:

  • la stringa convertita (deve essere liberata richiamando "free" dopo l’utilizzo

Esempio in C:

char *str = weechat_iconv_from_internal ("iso-8859-1", "utf-8 string: é à");
/* ... */
free (str);

Script (Python):

# prototipo
str = weechat.iconv_from_internal(charset, string)

# esempio
str = weechat.iconv_from_internal("iso-8859-1", "utf-8 string: é à")

3.3.4. gettext

Restituisce la stringa tradotta (dipende dalla lingua).

Prototipo:

const char *weechat_gettext (const char *string);

Argomenti:

  • string: stringa da tradurre

Valore restituito:

  • translated string or string if there is no translation available in local language

Esempio in C:

char *str = weechat_gettext ("hello");

Script (Python):

# prototipo
str = weechat.gettext(string)

# esempio
str = weechat.gettext("hello")

3.3.5. ngettext

Restituisce la stringa tradotta, utilizzando il singolare o il plurale, in base all’argomento count (contatore).

Prototipo:

const char *weechat_ngettext (const char *string, const char *plural,
                              int count);

Argomenti:

  • string: stringa da tradurre, singolare

  • plural: stringa da tradurre, plurale

  • count: utilizzato per scegliere tra singolare e plurale (la scelta viene fatta in base alla lingua locale)

Valore restituito:

  • translated string or string / plural if there is no translation available in local language

Esempio in C:

char *str = weechat_ngettext ("file", "files", num_files);

Script (Python):

# prototipo
str = weechat.ngettext(string, plural, count)

# esempio
num_files = 2
str = weechat.ngettext("file", "files", num_files)

3.3.6. strndup

Restituisce una stringa duplicata, con un massimo di caratteri impostato su chars.

Prototipo:

char *weechat_strndup (const char *string, int length);

Argomenti:

  • string: stringa da duplicare

  • length: caratteri massimi da duplicare

Valore restituito:

  • stringa duplicata (deve essere liberata chiamando "free" dopo l’utilizzo)

Esempio in C:

char *str = weechat_strndup ("abcdef", 3);  /* result: "abc" */
/* ... */
free (str);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.7. string_tolower

Converte una stringa UTF-8 in minuscolo.

Prototipo:

void weechat_string_tolower (char *string);

Argomenti:

  • string: stringa da convertire

Esempio in C:

char str[] = "AbCdé";
weechat_string_tolower (str);  /* str ora è: "abcdé" */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.8. string_toupper

Converte una stringa UTF-8 in maiuscolo.

Prototipo:

void weechat_string_toupper (char *string);

Argomenti:

  • string: stringa da convertire

Esempio in C:

char str[] = "AbCdé";
weechat_string_toupper (str);  /* str ora è: "ABCDé" */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.9. strcasecmp

Updated in 1.0.

Confronta stringa non sensibile alle maiuscole e alla localizzazione.

Prototipo:

int weechat_strcasecmp (const char *string1, const char *string2);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

Valore restituito:

  • -1 se stringa1 < stringa2

  • 0 se stringa1 == stringa1

  • 1 se stringa1 > stringa2

Esempio in C:

int diff = weechat_strcasecmp ("aaa", "CCC");  /* == -2 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.10. strcasecmp_range

WeeChat ≥ 0.3.7, updated in 1.0.

Confronta stringa non sensibile alle maiuscole e alla localizzazione, usando una serie per il confronto.

Prototipo:

int weechat_strcasecmp_range (const char *string1, const char *string2, int range);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

  • range: numero di caratteri nel confronto maiuscole/minuscole, ad esempio:

    • 26: A-Z vengono ridotti ad a-z

    • 29: A-Z [ \ ] vengono ridotti ad a-z { | }

    • 30: A-Z [ \ ] ^ vengono ridotti ad a-z { | } ~

Note
I valori 29 e 30 vengono usati da alcuni protocolli come IRC.

Valore restituito:

  • -1 se stringa1 < stringa2

  • 0 se stringa1 == stringa1

  • 1 se stringa1 > stringa2

Esempio in C:

int diff = weechat_strcasecmp_range ("nick{away}", "NICK[away]", 29);  /* == 0 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.11. strncasecmp

Updated in 1.0.

Confronta stringa indipendente non sensibile alle maiuscole e alla localizzazione, per un numero max di caratteri.

Prototipo:

int weechat_strncasecmp (const char *string1, const char *string2, int max);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

  • max: numero massimo di caratteri da comparare

Valore restituito:

  • -1 se stringa1 < stringa2

  • 0 se stringa1 == stringa1

  • 1 se stringa1 > stringa2

Esempio in C:

int diff = weechat_strncasecmp ("aabb", "aacc", 2);  /* == 0 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.12. strncasecmp_range

WeeChat ≥ 0.3.7, updated in 1.0.

Confronta una stringa non sensibile alle maiuscole e alla localizzazione, per un numero max di caratteri, usando una serie per il confronto.

Prototipo:

int weechat_strncasecmp_range (const char *string1, const char *string2, int max, int range);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

  • max: numero massimo di caratteri da comparare

  • range: numero di caratteri nel confronto maiuscole/minuscole, ad esempio:

    • 26: A-Z vengono ridotti ad a-z

    • 29: A-Z [ \ ] vengono ridotti ad a-z { | }

    • 30: A-Z [ \ ] ^ vengono ridotti ad a-z { | } ~

Note
I valori 29 e 30 vengono usati da alcuni protocolli come IRC.

Valore restituito:

  • -1 se stringa1 < stringa2

  • 0 se stringa1 == stringa1

  • 1 se stringa1 > stringa2

Esempio in C:

int diff = weechat_strncasecmp_range ("nick{away}", "NICK[away]", 6, 29);  /* == 0 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.13. strcmp_ignore_chars

Updated in 1.0.

Confronta una stringa localizzata (e opzionalmente non sensibile alle maiuscole), ignorando alcuni caratteri.

Prototipo:

int weechat_strcmp_ignore_chars (const char *string1, const char *string2,
                                 const char *chars_ignored,
                                 int case_sensitive);

Argomenti:

  • string1: prima stringa per il confronto

  • string2: seconda stringa per il confronto

  • chars_ignored: stringa con caratteri da ignorare

  • case_sensitive: 1 per il confronto sensibile alle maiuscole, altrimenti 0

Valore restituito:

  • -1 se stringa1 < stringa2

  • 0 se stringa1 == stringa1

  • 1 se stringa1 > stringa2

Esempio in C:

int diff = weechat_strcmp_ignore_chars ("a-b", "--a-e", "-", 1);  /* == -3 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.14. strcasestr

Updated in 1.3.

Cerca una stringa non sensibile alle maiuscole e indipendente dalla localizzazione.

Prototipo:

const char *weechat_strcasestr (const char *string, const char *search);

Argomenti:

  • string: stringa

  • search: stringa da cercare in string

Valore restituito:

  • puntatore alla stringa trovata, o NULL se non trovata (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *pos = weechat_strcasestr ("aBcDeF", "de");  /* risultato: puntatore a "DeF" */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.15. strlen_screen

WeeChat ≥ 0.4.2.

Restituisce il numero di caratteri necessari per visualizzare la stringa UTF-8 su schermo. Non-printable chars have a width of 1 (this is the difference with the function utf8_strlen_screen).

Prototipo:

int weechat_strlen_screen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • numero di caratteri necessari per visualizzare la stringa UTF-8 su schermo

Esempio in C:

int length_on_screen = weechat_strlen_screen ("é");  /* == 1 */

Script (Python):

# prototipo
length = weechat.strlen_screen(string)

# esempio
length = weechat.strlen_screen("é")  # 1

3.3.16. string_match

Updated in 1.0.

Verifica se una stringa coincide ad una mask.

Prototipo:

int weechat_string_match (const char *string, const char *mask,
                          int case_sensitive);

Argomenti:

  • string: stringa

  • mask: mask with wildcards (*), each wildcard matches 0 or more chars in the string

  • case_sensitive: 1 per il confronto sensibile alle maiuscole, altrimenti 0

Note
Since version 1.0, wildcards are allowed inside the mask (not only beginning/end of mask).

Valore restituito:

  • 1 se la stringa coincide alla mask, altrimenti 0

Esempio in C:

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 */
int match4 = weechat_string_match ("abcdef", "*de*", 0);   /* == 1 */
int match5 = weechat_string_match ("abcdef", "*b*d*", 0);  /* == 1 */

Script (Python):

# prototipo
match = weechat.string_match(string, mask, case_sensitive)

# esempio
match1 = weechat.string_match("abcdef", "abc*", 0)   # == 1
match2 = weechat.string_match("abcdef", "*dd*", 0)   # == 0
match3 = weechat.string_match("abcdef", "*def", 0)   # == 1
match4 = weechat.string_match("abcdef", "*de*", 0)   # == 1
match5 = weechat.string_match("abcdef", "*b*d*", 0)  # == 1

3.3.17. string_match_list

WeeChat ≥ 2.5.

Check if a string matches a list of masks where negative mask is allowed with the format "!word". A negative mask has higher priority than a standard mask.

Prototipo:

int weechat_string_match_list (const char *string, const char **masks,
                               int case_sensitive);

Argomenti:

  • string: string

  • masks: list of masks, with a NULL after the last mask in list; each mask is compared to the string with the function string_match

  • case_sensitive: 1 for case sensitive comparison, otherwise 0

Valore restituito:

  • 1 if string matches list of masks (at least one mask matches and no negative mask matches), otherwise 0

Esempio in C:

const char *masks[3] = { "*", "!abc*", NULL };
int match1 = weechat_string_match_list ("abc", masks, 0);     /* == 0 */
int match2 = weechat_string_match_list ("abcdef", masks, 0);  /* == 0 */
int match3 = weechat_string_match_list ("def", masks, 0);     /* == 1 */

Script (Python):

# prototipo
match = weechat.string_match_list(string, masks, case_sensitive)

# esempio
match1 = weechat.string_match("abc", "*,!abc*", 0)     # == 0
match2 = weechat.string_match("abcdef", "*,!abc*", 0)  # == 0
match3 = weechat.string_match("def", "*,!abc*", 0)     # == 1

3.3.18. string_expand_home

WeeChat ≥ 0.3.3.

Sostituisce la ~ iniziale con la stringa con la cartella home. Se la stringa non inizia con ~, viene restituita la stessa stringa.

Prototipo:

char *weechat_string_expand_home (const char *path);

Argomenti:

  • path: percorso

Valore restituito:

  • percorso con la ~ iniziale sostituita dalla cartella home (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_expand_home ("~/file.txt");
/* result: "/home/xxx/file.txt" */
/* ... */
free (str);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.19. string_eval_path_home

WeeChat ≥ 1.3.

Evaluate a path in 3 steps:

  1. replace leading %h by WeeChat home directory,

  2. replace leading ~ by user home directory (call to string_expand_home),

  3. evaluate variables (see string_eval_expression).

Prototipo:

char *weechat_string_eval_path_home (const char *path,
                                     struct t_hashtable *pointers,
                                     struct t_hashtable *extra_vars,
                                     struct t_hashtable *options);

Argomenti:

Valore restituito:

  • evaluated path (must be freed by calling "free" after use)

Esempio in C:

char *str = weechat_string_eval_path_home ("%h/test", NULL, NULL, NULL);
/* result: "/home/xxx/.weechat/test" */
/* ... */
free (str);

Script (Python):

# prototipo
path = weechat.string_eval_path_home(path, pointers, extra_vars, options)

# esempio
path = weechat.string_eval_path_home("%h/test", {}, {}, {})
# path == "/home/xxx/.weechat/test"

3.3.20. string_remove_quotes

Rimuove le virgolette all’inizio e alla fine della stringa (ignora gli spazi se presenti prima delle prime virgolette o dopo le ultime virgolette).

Prototipo:

char *weechat_string_remove_quotes (const char *string, const char *quotes);

Argomenti:

  • string: stringa

  • quotes: stringa con elenco di virgolette

Valore restituito:

  • stringa senza virgolette all’inizio/fine (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_remove_quotes (string, " 'Non posso' ", "'");
/* risultato: "Non posso" */
/* ... */
free (str);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.21. string_strip

Rimuove i caratteri ad inizio/fine della stringa.

Prototipo:

char *weechat_string_strip (const char *string, int left, int right,
                            const char *chars);

Argomenti:

  • string: stringa

  • left: rimuove i caratteri a sinistra se diversi da 0

  • right: rimuove i caratteri a destra se diversi da 0

  • chars: stringa con i caratteri da rimuovere

Valore restituito:

  • stringa corretta (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_strip (".abc -", 0, 1, "- .");  /* risultato: ".abc" */
/* ... */
free (str);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.22. string_convert_escaped_chars

WeeChat ≥ 1.0.

Convert escaped chars to their value:

  • \": double quote

  • \\: backslash

  • \a: alert (BEL)

  • \b: backspace

  • \e: escape

  • \f: form feed

  • \n: new line

  • \r: carriage return

  • \t: horizontal tab

  • \v: vertical tab

  • \0ooo: char as octal value (ooo is 0 to 3 digits)

  • \xhh: char as hexadecimal value (hh is 1 to 2 digits)

  • \uhhhh: unicode char as hexadecimal value (hhhh is 1 to 4 digits)

  • \Uhhhhhhhh: unicode char as hexadecimal value (hhhhhhhh is 1 to 8 digits)

Prototipo:

char *weechat_string_convert_escaped_chars (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • string with escaped chars replaced by their value (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_convert_escaped_chars ("snowman: \\u2603");
/* str == "snowman: ☃" */
/* ... */
free (str);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.23. string_mask_to_regex

Restituisce una espressione regolare con una mask, dove l’unico carattere speciale è *. Tutti gli altri caratteri speciali per le espressioni regolari non vengono riconosciuti.

Prototipo:

char *weechat_string_mask_to_regex (const char *mask);

Argomenti:

  • mask: mask

Valore restituito:

  • espressione regolare, come stringa (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str_regex = weechat_string_mask_to_regex ("test*mask");
/* result: "test.*mask" */
/* ... */
free (str_regex);

Script (Python):

# prototipo
regex = weechat.string_mask_to_regex(mask)

# esempio
regex = weechat.string_mask_to_regex("test*mask")  # "test.*mask"

3.3.24. string_regex_flags

WeeChat ≥ 0.3.7.

Restituisce sia il puntatore sulla stringa dopo le flag che la mask con le flag per compilare l’espressione regolare.

Prototipo:

const char *weechat_string_regex_flags (const char *regex, int default_flags, int *flags)

Argomenti:

  • regex: POSIX extended regular expression

  • default_flags: combinazione dei seguenti valori (consultare man regcomp):

    • REG_EXTENDED

    • REG_ICASE

    • REG_NEWLINE

    • REG_NOSUB

  • flags: pointer value is set with flags used in regular expression (default flags + flags set in regular expression)

Flags must be at beginning of regular expression. Format is: "(?eins-eins)string".

Allowed flags are:

  • e: POSIX extended regular expression (REG_EXTENDED)

  • i: case insensitive (REG_ICASE)

  • n: match-any-character operators don_t match a newline (REG_NEWLINE)

  • s: support for substring addressing of matches is not required (REG_NOSUB)

Valore restituito:

  • pointer in regex, after flags

Esempio in C:

const char *regex = "(?i)test";
int flags;
const char *ptr_regex = weechat_string_regex_flags (regex, REG_EXTENDED, &flags);
/* ptr_regex == "test", flags == REG_EXTENDED | REG_ICASE */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.25. string_regcomp

WeeChat ≥ 0.3.7.

Compile a POSIX extended regular expression using optional flags at beginning of string (for format of flags, see string_regex_flags).

Prototipo:

int weechat_string_regcomp (void *preg, const char *regex, int default_flags)

Argomenti:

  • preg: pointer to regex_t structure

  • regex: POSIX extended regular expression

  • default_flags: combination of following values (see man regcomp):

    • REG_EXTENDED

    • REG_ICASE

    • REG_NEWLINE

    • REG_NOSUB

Valore restituito:

  • same return code as function regcomp (0 if ok, other value for error, see man regcomp)

Esempio in C:

regex_t my_regex;
if (weechat_string_regcomp (&my_regex, "(?i)test", REG_EXTENDED) != 0)
{
    /* error */
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.26. string_has_highlight

Controlla se una stringa ha uno o più eventi, usando la lista di parole per gli eventi.

Prototipo:

int weechat_string_has_highlight (const char *string,
                                  const char highlight_words);

Argomenti:

  • string: stringa

  • highlight_words: lista di parole per gli eventi, separate da virgole

Valore restituito:

  • 1 se la stringa ha uno o più eventi, altrimenti 0

Esempio in C:

int hl = weechat_string_has_highlight ("my test string", "test,word2");  /* == 1 */

Script (Python):

# prototipo
highlight = weechat.string_has_highlight(string, highlight_words)

# esempio
highlight = weechat.string_has_highlight("my test string", "test,word2")  # 1

3.3.27. string_has_highlight_regex

WeeChat ≥ 0.3.4.

Check if a string has one or more highlights, using a POSIX extended regular expression.
For at least one match of regular expression on string, it must be surrounded by delimiters (chars different from: alphanumeric, -, _ and |).

Prototipo:

int weechat_string_has_highlight_regex (const char *string, const char *regex);

Argomenti:

  • string: stringa

  • regex: POSIX extended regular expression

Valore restituito:

  • 1 se la stringa ha uno o più eventi, altrimenti 0

Esempio in C:

int hl = weechat_string_has_highlight_regex ("my test string", "test|word2");  /* == 1 */

Script (Python):

# prototipo
highlight = weechat.string_has_highlight_regex(string, regex)

# esempio
highlight = weechat.string_has_highlight_regex("my test string", "test|word2")  # 1

3.3.28. string_replace

Sostituisce tutte le ricorrenze di una stringa con un’altra.

Prototipo:

char *weechat_string_replace (const char *string, const char *search,
                              const char *replace);

Argomenti:

  • string: stringa

  • search: stringa da sostituire

  • replace: sostituzione per la stringa search

Valore restituito:

  • la stringa dopo search sostituita da replace (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *str = weechat_string_replace ("test", "s", "x");  /* result: "text" */
/* ... */
free (str);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.29. string_replace_regex

WeeChat ≥ 1.0.

Replace text in a string using a regular expression, replacement text and optional callback.

Prototipo:

char *weechat_string_replace_regex (const char *string, void *regex,
                                    const char *replace, const char reference_char,
                                    char *(*callback)(void *data, const char *text),
                                    void *callback_data);

Argomenti:

  • string: string

  • regex: pointer to a regular expression (regex_t structure) compiled with WeeChat function string_regcomp or regcomp (see man regcomp)

  • replace: replacement text, where following references are allowed:

    • $0 to $99: match 0 to 99 in regular expression (0 is the whole match, 1 to 99 are groups captured between parentheses)

    • $+: the last match (with highest number)

    • $.*N: match N (can be + or 0 to 99), with all chars replaced by * (the * char can be any char between space (32) and ~ (126))

  • reference_char: the char used for reference to match (commonly $)

  • callback: an optional callback called for each reference in replace (except for matches replaced by a char); the callback must return:

    • newly allocated string: it is used as replacement text (it is freed after use)

    • NULL: the text received in callback is used as replacement text (without changes)

  • callback_data: pointer given to callback when it is called

Valore restituito:

  • string with text replaced, NULL if problem (must be freed by calling "free" after use)

Esempio in C:

regex_t my_regex;
char *string;
if (weechat_string_regcomp (&my_regex, "([0-9]{4})-([0-9]{2})-([0-9]{2})",
                            REG_EXTENDED) == 0)
{
    string = weechat_string_replace_regex ("date: 2014-02-14", &my_regex,
                                           "$3/$2/$1", '$', NULL, NULL);
    /* string == "date: 14/02/2014" */
    if (string)
        free (string);
    regfree (&my_regex);
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.30. string_split

Updated in 2.5, 2.6.

Divide una stringa in base a uno o più delimitatori.

Prototipo:

char **weechat_string_split (const char *string, const char *separators,
                             const char *strip_items, int flags,
                             int num_items_max, int *num_items);

Argomenti:

  • string: stringa da dividere

  • separators: delimitatori usati per dividere

  • strip_items: chars to strip from returned items (left/right); optional, can be NULL

  • flags: combination values to change the default behavior; if the value is 0, the default behavior is used (no strip of separators at beginning/end of string, multiple separators are kept as-is so empty strings can be returned); the following flags are accepted:

    • WEECHAT_STRING_SPLIT_STRIP_LEFT: strip separators on the left (beginning of string)

    • WEECHAT_STRING_SPLIT_STRIP_RIGHT: strip separators on the right (end of string)

    • WEECHAT_STRING_SPLIT_COLLAPSE_SEPS: collapse multiple consecutive separators into a single one

    • WEECHAT_STRING_SPLIT_KEEP_EOL: keep end of line for each value

  • num_items_max: numero massimo di elementi creati (0 = nessun limite)

  • num_items: puntatore ad int che conterrà il numero di elementi creati

Note
With WeeChat ≤ 2.4, the flags argument was called keep_eol and took other values, which must be converted like that:
keep_eol flags

0

WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS

1

WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS | WEECHAT_STRING_SPLIT_KEEP_EOL

2

WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS | WEECHAT_STRING_SPLIT_KEEP_EOL

Valore restituito:

  • array di stringhe, NULL se si verifica un problema (deve essere liberata chiamando string_free_split dopo l’uso)

Esempi:

char **argv;
int argc;

argv = weechat_string_split ("abc de  fghi ", " ", NULL, 0, 0, &argc);
/* result: argv[0] == "abc"
           argv[1] == "de"
           argv[2] = ""
           argv[3] == "fghi"
           argv[4] = ""
           argv[5] == NULL
           argc == 5
*/
weechat_string_free_split (argv);

argv = weechat_string_split ("abc de  fghi ", " ", NULL,
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                             0, &argc);
/* result: argv[0] == "abc"
           argv[1] == "de"
           argv[2] == "fghi"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);

argv = weechat_string_split ("abc de  fghi ", " ", NULL,
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
                             | WEECHAT_STRING_SPLIT_KEEP_EOL,
                             0, &argc);
/* result: argv[0] == "abc de  fghi"
           argv[1] == "de  fghi"
           argv[2] == "fghi"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);

argv = weechat_string_split ("abc de  fghi ", " ", NULL,
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS
                             | WEECHAT_STRING_SPLIT_KEEP_EOL,
                             0, &argc);
/* result: argv[0] == "abc de  fghi "
           argv[1] == "de  fghi "
           argv[2] == "fghi "
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);

argv = weechat_string_split (" abc, de,, fghi ", ",", " ",
                             WEECHAT_STRING_SPLIT_STRIP_LEFT
                             | WEECHAT_STRING_SPLIT_STRIP_RIGHT
                             | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
                             0, &argc);
/* result: argv[0] == "abc"
           argv[1] == "de"
           argv[2] == "fghi"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.31. string_split_shell

WeeChat ≥ 1.0.

Split a string like the shell does for a command with arguments.

This function is a C conversion of Python class "shlex" (file: Lib/shlex.py in Python repository), see: https://docs.python.org/3/library/shlex.html.

Prototipo:

char **weechat_string_split_shell (const char *string, int *num_items);

Argomenti:

  • string: stringa da dividere

  • num_items: puntatore ad int che conterrà il numero di elementi creati

Valore restituito:

  • array di stringhe, NULL se si verifica un problema (deve essere liberata chiamando string_free_split dopo l’uso)

Esempio in C:

char **argv;
int argc;
argv = weechat_string_split_shell ("test 'first arg'  \"second arg\"", &argc);
/* result: argv[0] == "test"
           argv[1] == "first arg"
           argv[2] == "second arg"
           argv[3] == NULL
           argc == 3
*/
weechat_string_free_split (argv);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.32. string_free_split

Libera la memoria usata per la divisione di una stringa.

Prototipo:

void weechat_string_free_split (char **split_string);

Argomenti:

Esempio in C:

char *argv;
int argc;
argv = weechat_string_split (string, " ", 0, 0, &argc);
/* ... */
weechat_string_free_split (argv);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.33. string_build_with_split_string

Compila una stringa con una stringa divisa.

Prototipo:

char *weechat_string_build_with_split_string (char **split_string,
                                              const char *separator);

Argomenti:

  • split_string: stringa divisa dalla funzione string_split

  • separator: stringa usata per separare le stringhe

Valore restituito:

  • stringa compilata con la stringa divisa (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char **argv;
int argc;
argv = weechat_string_split ("abc def ghi", " ", 0, 0, &argc);
char *str = weechat_string_build_with_split_string (argv, ";");
/* str == "abc;def;ghi" */
/* ... */
free (str);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.34. string_split_command

Divide una lista di comandi separata da separator (che può essere omesso aggiungendo \ nella stringa).

Prototipo:

char **weechat_string_split_command (const char *command, char separator);

Argomenti:

  • command: comando da dividere

  • separator: separatore

Valore restituito:

  • array di stringhe, NULL in caso di problemi (deve essere liberata chiamando free_split_command dopo l’uso)

Esempio in C:

char **argv = weechat_string_split_command ("/command1 arg;/command2", ';');
/* result: argv[0] == "/command1 arg"
           argv[1] == "/command2"
           argv[2] == NULL
*/
weechat_free_split_command (argv);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.35. string_free_split_command

Libera la memoria utilizzata dalla divisione di un comando.

Prototipo:

void weechat_string_free_split_command (char **split_command);

Argomenti:

Esempio in C:

char **argv = weechat_string_split_command ("/command1 arg;/command2", ';');
/* ... */
weechat_free_split_command (argv);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.36. string_format_size

Compila una stringa con un file di dimensione fissa ed una unità tradotta nella lingua locale.

Prototipo:

char *weechat_string_format_size (unsigned long long size);

Argomenti:

  • size: dimensione (in byte)

Valore restituito:

  • stringa formattata (deve essere liberata chiamando "free" dopo l’uso)

Esempi in C:

/* esempi in lingua inglese */

char *str = weechat_string_format_size (0);  /* str == "0 bytes" */
/* ... */
free (str);

char *str = weechat_string_format_size (1);  /* str == "1 byte" */
/* ... */
free (str);

char *str = weechat_string_format_size (200);  /* str == "200 bytes" */
/* ... */
free (str);

char *str = weechat_string_format_size (15200);  /* str == "15.2 KB" */
/* ... */
free (str);

char *str = weechat_string_format_size (2097152);  /* str == "2.10 MB" */
/* ... */
free (str);

Script (Python), WeeChat ≥ 2.2:

# prototipo
str = weechat.string_format_size(size)

# esempio
str = weechat.string_format_size(15200)  # == "15.2 KB"

3.3.37. string_remove_color

Rimuove i colori di WeeChat da una stringa.

Prototipo:

char *weechat_string_remove_color (const char *string,
                                   const char *replacement);

Argomenti:

  • string: stringa

  • replacement: se non NULL e non vuota, i codici colore di WeeChat sono sostituiti dal primo carattere di questa stringa, altrimenti i codici colori di WeeChat ed i caratteri seguenti (se correlate al colore) sono rimossi dalla stringa

Valore restituito:

  • stringa senza un colore (deve essere liberata chiamando "free" dopo l’uso)

Esempi:

/* rimuove i codici colore */
char *str = weechat_string_remove_color (my_string1, NULL);
/* ... */
free (str);

/* sostituisce i codici colore con "?" */
char *str = weechat_string_remove_color (my_string2, "?");
/* ... */
free (str);

Script (Python):

# prototipo
str = weechat.string_remove_color(string, replacement)

# esempio
str = weechat.string_remove_color(my_string, "?")

3.3.38. string_base_encode

WeeChat ≥ 2.4.

Encode a string in base 16, 32, or 64.

Prototipo:

int weechat_string_base_encode (int base, const char *from, int length, char *to);

Argomenti:

  • base: 16, 32, or 64

  • from: stringa da codificare

  • length: lunghezza della stringa da codificare (ad esempio strlen(from))

  • to: puntatore alla stringa per memorizzare il risultato (deve essere sufficientemente lunga, il risultato è più lungo della stringa iniziale)

Valore restituito:

  • lunghezza della stringa memorizzata in *to (lo \0 finale non conta), -1 if error

Esempio in C:

char *string = "abcdefgh", result[128];
int length;
length = weechat_string_base_encode (16, string, strlen (string), result);
/* length == 16, result == "6162636465666768" */
length = weechat_string_base_encode (32, string, strlen (string), result);
/* length == 16, result == "MFRGGZDFMZTWQ===" */
length = weechat_string_base_encode (64, string, strlen (string), result);
/* length == 12, result == "YWJjZGVmZ2g=" */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.39. string_base_decode

WeeChat ≥ 2.4.

Decode a string encoded in base 16, 32, or 64.

Prototipo:

int weechat_string_base_decode (int base, const char *from, char *to);

Argomenti:

  • base: 16, 32, or 64

  • from: stringa da decodificare

  • to: puntatore alla stringa per memorizzare il risultato (deve essere sufficientemente lunga, il risultato è più lungo della stringa iniziale)

Valore restituito:

  • lunghezza della stringa memorizzata in *to (lo \0 finale non conta), -1 if error

Esempio in C:

char result[128];
int length;
length = weechat_string_base_decode (16, "6162636465666768", result);
/* length == 8, result == "abcdefgh" */
length = weechat_string_base_decode (32, "MFRGGZDFMZTWQ===", result);
/* length == 8, result == "abcdefgh" */
length = weechat_string_base_decode (64, "YWJjZGVmZ2g=", result);
/* length == 8, result == "abcdefgh" */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.40. string_hex_dump

WeeChat ≥ 1.4.

Display a dump of data as hexadecimal and ascii bytes.

Prototipo:

char *string_hex_dump (const char *data, int data_size, int bytes_per_line,
                       const char *prefix, const char *suffix);

Argomenti:

  • data: the data to dump

  • data_size: number of bytes to dump in data

  • bytes_per_line: number of bytes to display in each line

  • prefix: the prefix to display at the beginning of each line (optional, can be NULL)

  • suffix: the suffix to display at the end of each line (optional, can be NULL)

Valore restituito:

  • string with dump of data (must be freed by calling "free" after use)

Esempio in C:

char *string = "abc def-ghi";
char *dump = weechat_string_hex_dump (string, strlen (string), 8, " >> ", NULL);
/* dump == " >> 61 62 63 20 64 65 66 2D   a b c   d e f - \n"
           " >> 67 68 69                  g h i           "  */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.41. string_is_command_char

WeeChat ≥ 0.3.2.

Verifica che il primo carattere della stringa sia un carattere comando (il comando carattere predefinito è /).

Prototipo:

int weechat_string_is_command_char (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • 1 se il primo carattere della stringa è un comando carattere, altrimenti 0

Esempi in C:

int command_char1 = weechat_string_is_command_char ("/test");  /* == 1 */
int command_char2 = weechat_string_is_command_char ("test");   /* == 0 */

Script (Python):

# prototipo
is_cmdchar = weechat.string_is_command_char(string)

# esempi
command_char1 = weechat.string_is_command_char("/test")  # == 1
command_char2 = weechat.string_is_command_char("test")   # == 0

3.3.42. string_input_for_buffer

WeeChat ≥ 0.3.2.

Restituisce il puntatore al testo in input per il buffer (puntatore all’interno dell’argomento "string"), oppure NULL se è un comando.

Prototipo:

const char *weechat_string_input_for_buffer (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • puntatore all’interno di "string", oppure NULL

Esempi in C:

const char *str1 = weechat_string_input_for_buffer ("test");    /* "test"  */
const char *str2 = weechat_string_input_for_buffer ("/test");   /* NULL    */
const char *str3 = weechat_string_input_for_buffer ("//test");  /* "/test" */

Script (Python):

# prototipo
str = weechat.string_input_for_buffer(string)

# esempi
str1 = weechat.string_input_for_buffer("test")    # "test"
str2 = weechat.string_input_for_buffer("/test")   # ""
str3 = weechat.string_input_for_buffer("//test")  # "/test"

3.3.43. string_eval_expression

WeeChat ≥ 0.4.0, updated in 0.4.2, 0.4.3, 1.0, 1.1, 1.2, 1.3, 1.6, 1.8, 2.0, 2.2, 2.3 and 2.7.

Evaluate an expression and return result as a string. Special variables with format ${variable} are expanded (see table below).

Note
Since version 1.0, nested variables are supported, for example: ${color:${variable}}.

Prototipo:

char *weechat_string_eval_expression (const char *expr,
                                      struct t_hashtable *pointers,
                                      struct t_hashtable *extra_vars,
                                      struct t_hashtable *options);

Argomenti:

  • expr: the expression to evaluate (see conditions and variables)

  • pointers: hashtable with pointers (keys must be string, values must be pointer); pointers "window" and "buffer" are automatically added if they are not in hashtable (with pointer to current window/buffer) (can be NULL):

    • regex: pointer to a regular expression (regex_t structure) compiled with WeeChat function string_regcomp or regcomp (see man regcomp); this option is similar to regex in hashtable options (below), but is used for better performance

  • extra_vars: extra variables that will be expanded (can be NULL)

  • options: a hashtable with some options (keys and values must be string) (can be NULL):

    • type: default behavior is just to replace values in expression, other types can be selected:

      • condition: the expression is evaluated as a condition: operators and parentheses are used, result is a boolean ("0" or "1")

    • prefix: prefix before variables to replace (default: ${)

    • suffix: suffix after variables to replace (default: })

    • extra: default behavior is to just replace extra variables (extra_vars), other behavior can be selected:

      • eval: extra variables (extra_vars) are evaluated themselves before replacing (WeeChat ≥ 1.6)

    • regex: a regex used to replace text in expr (which is then not evaluated)

    • regex_replace: the replacement text to use with regex, to replace text in expr (the regex_replace is evaluated on each match of regex against expr, until no match is found)

Valore restituito:

  • evaluated expression (must be freed by calling "free" after use), or NULL if problem (invalid expression or not enough memory)

Esempi in C:

/* conditions */
struct t_hashtable *options1 = weechat_hashtable_new (8,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      NULL,
                                                      NULL);
weechat_hashtable_set (options1, "type", "condition");
char *str1 = weechat_string_eval_expression ("${window.win_width} > 100", NULL, NULL, options1);  /* "1" */
char *str2 = weechat_string_eval_expression ("abc =~ def", NULL, NULL, options1);                 /* "0" */

/* simple expression */
char *str3 = weechat_string_eval_expression ("${buffer.full_name}", NULL, NULL, NULL);  /* "core.weechat" */

/* replace with regex */
struct t_hashtable *options2 = weechat_hashtable_new (8,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      WEECHAT_HASHTABLE_STRING,
                                                      NULL,
                                                      NULL);
/* add brackets around URLs */
weechat_hashtable_set (options2, "regex", "[a-zA-Z0-9_]+://[^ ]+");
weechat_hashtable_set (options2, "regex_replace", "[ ${re:0} ]");
char *str4 = weechat_string_eval_expression ("test: https://weechat.org", NULL, NULL, NULL);  /* "test: [ https://weechat.org ]" */

/* hide passwords */
weechat_hashtable_set (options2, "regex", "(password=)([^ ]+)");
weechat_hashtable_set (options2, "regex_replace", "${re:1}${hide:*,${re:2}}");
char *str5 = weechat_string_eval_expression ("password=abc password=def", NULL, NULL, NULL);  /* "password=*** password=***" */

Script (Python):

# prototipo
str = weechat.string_eval_expression(expr, pointers, extra_vars, options)

# esempi

# conditions
str1 = weechat.string_eval_expression("${window.win_width} > 100", {}, {}, {"type": "condition"})  # "1"
str2 = weechat.string_eval_expression("abc =~ def", {}, {}, {"type": "condition"})                 # "0"

# simple expression
str3 = weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) # "core.weechat"

# replace with regex: add brackets around URLs
options = {
    "regex": "[a-zA-Z0-9_]+://[^ ]+",
    "regex_replace": "[ ${re:0} ]",
}
str4 = weechat.string_eval_expression("test: https://weechat.org", {}, {}, options)  # "test: [ https://weechat.org ]"

# replace with regex: hide passwords
options = {
    "regex": "(password=)([^ ]+)",
    "regex_replace": "${re:1}${hide:*,${re:2}}",
}
str5 = weechat.string_eval_expression("password=abc password=def", {}, {}, options)  # "password=*** password=***"
Conditions

List of logical operators that can be used in conditions (by order of priority, from first used to last):

Operator Description Examples Results

&&

Logical "and"

25 && 77
25 && 0

1
0

||

Logical "or"

25 || 0
0 || 0

1
0

List of comparison operators that can be used in conditions (by order of priority, from first used to last):

Operator Description Examples Results

=~

Is matching POSIX extended regex (optional flags are allowed, see function string_regcomp)

abc def =~ ab.*ef
abc def =~ y.*z

1
0

!~

Is NOT matching POSIX extended regex (optional flags are allowed, see function string_regcomp)

abc def !~ ab.*ef
abc def !~ y.*z

0
1

=*
(WeeChat ≥ 1.8)

Is matching mask where "*" is allowed (see function string_match)

abc def =* a*f
abc def =* y*z

1
0

!*
(WeeChat ≥ 1.8)

Is NOT matching mask where "*" is allowed (see function string_match)

abc def !* a*f
abc def !* y*z

0
1

==

Equal

test == test
test == string

1
0

!=

Not equal

test != test
test != string

0
1

<=

Less or equal

abc <= defghi
abc <= abc
defghi <= abc
15 <= 2

1
1
0
0

<

Less

abc < defghi
abc < abc
defghi < abc
15 < 2

1
0
0
0

>=

Greater or equal

defghi >= abc
abc >= abc
abc >= defghi
15 >= 2

1
1
0
1

>

Greater

defghi > abc
abc > abc
abc > defghi
15 > 2

1
0
0
1

The comparison is made using floating point numbers if the two expressions are valid numbers, with one of the following formats:

  • integer (examples: 5, -7)

  • floating point number (examples: 5.2, -7.5, 2.83e-2) (WeeChat ≥ 2.0)

  • hexadecimal number (examples: 0xA3, -0xA3) (WeeChat ≥ 2.0)

To force a string comparison, you can add double quotes around each expression, for example:

  • 50 > 100 returns 0 (number comparison)

  • "50" > "100" returns 1 (string comparison)

Variables

List of variables expanded in expression (by order of priority, from first expanded to last):

Format Description Examples Results

${name}

Variable name from hashtable extra_vars.

${name}

value

${eval:xxx}
(WeeChat ≥ 1.3)

String to evaluate.

${eval:${date:${weechat.look.buffer_time_format}}}

19:02:45 (with colors if there are color codes in the option weechat.look.buffer_time_format)

${esc:xxx}
${\xxx}
(WeeChat ≥ 1.0)

String with escaped chars.

${esc:prefix\tmessage}
${\ua9}

prefix<TAB>message
©

${hide:x,string}
(WeeChat ≥ 1.1)

String with hidden chars (all chars in string replaced x).

${hide:*,password}

********

${cut:max,suffix,string}
${cut:+max,suffix,string}
(WeeChat ≥ 1.8)

String with max chars, and optional suffix if string is cut.
With the format +max, the suffix is counted in max length.

${cut:4,…,this is a test}
${cut:+4,…,this is a test}
${cut:2,>>,こんにちは世界}

this…
t…
こん>>

${cutscr:max,suffix,string}
${cutscr:+max,suffix,string}
(WeeChat ≥ 1.8)

String with max chars displayed on screen, and optional suffix if string is cut.
With the format +max, the suffix is counted in max length.

${cutscr:4,…,this is a test}
${cutscr:+4,…,this is a test}
${cutscr:2,>>,こんにちは世界}

this…
thi…
こ>>

${rev:xxx}
(WeeChat ≥ 2.2)

Reversed string (color codes are reversed, so the string should not contain color codes).

${rev:Hello, world!}
${rev:Hello, ${color:red}world!}

!dlrow ,olleH
!dlrow30F ,olleH (no color, the color code is reversed)

${revscr:xxx}
(WeeChat ≥ 2.7)

Reversed string for screen, color codes are not reversed.

${revscr:Hello, world!}
${revscr:Hello, ${color:red}world!}

!dlrow ,olleH
!dlrow ,olleH ( ,olleH in red)

${repeat:count,string}
(WeeChat ≥ 2.3)

Repeated string.

${repeat:5,-}

-----

${length:xxx}
(WeeChat ≥ 2.7)

Length of string (number of UTF-8 chars), color codes are ignored.

${length:test}
${length:こんにちは世界}

4
7

${lengthscr:xxx}
(WeeChat ≥ 2.7)

Length of string displayed on screen, color codes are ignored.

${lengthscr:test}
${lengthscr:こんにちは世界}

4
14

${re:N}
(WeeChat ≥ 1.1)

Regex captured group: 0 = whole string matching, 1 to 99 = group captured, + = last group captured, # = index of last group captured (WeeChat ≥ 1.8).

${re:0}
${re:1}
${re:2}
${re:+}
${re:#}

test1 test2
test1
test2
test2
2

${color:name}
(WeeChat ≥ 0.4.2)

WeeChat color code (the name of color has optional attributes), see function color for supported formats.

${color:red}red text
${color:*214}bold orange text

red text (in red)
bold orange text (in bold orange)

${modifier:name,data,string}
(WeeChat ≥ 2.7)

Result of a modifier, see function hook_modifier_exec.

${modifier:eval_path_home,,~}
${modifier:eval_path_home,,%h/python}

/home/xxx
/home/xxx/.weechat/python

${info:name}
${info:name,arguments}
(WeeChat ≥ 0.4.3)

Info from WeeChat or a plugin, see function info_get.

${info:version}
${info:nick_color_name,foo}

1.0
lightblue

${date}
${date:xxx}
(WeeChat ≥ 1.3)

Current date/time, with custom format (see man strftime), default format is %F %T.

${date}
${date:%H:%M:%S}

2015-06-30 19:02:45
19:02:45

${env:NAME}
(WeeChat ≥ 1.2)

Value of the environment variable NAME.

${env:HOME}

/home/user

${if:condition}
${if:condition?true} ${if:condition?true:false}
(WeeChat ≥ 1.8)

Ternary operator with a condition, a value if the condition is true (optional) and another value if the condition is false (optional). If values are not given, "1" or "0" are returned, according to the result of the condition.

${if:${info:term_width}>80?big:small}

big

${calc:xxx}
(WeeChat ≥ 2.7)

Result of expression, where parentheses and the following operators are supported:
+: addition
-: subtraction
*: multiplication
/: division
//: result of division without fractional part
%: remainder of division
**: power.

${calc:5+2*3}
${calc:(5+2)*3}
${calc:10/4}
${calc:10//4}
${calc:9.2%3}
${calc:2**16}

11
21
2.5
2
0.2
65536

${sec.data.name}

Value of the secured data name.

${sec.data.freenode_pass}

my_password

${file.section.option}

Value of the option.

${weechat.look.buffer_time_format}

%H:%M:%S

${name}

Value of local variable name in buffer.

${nick}

FlashCode

${hdata.var1.var2...}
${hdata[list].var1.var2...}

Hdata value (pointers window and buffer are set by default with current window/buffer).

${buffer[gui_buffers].full_name}
${window.buffer.number}

core.weechat
1

3.3.44. string_dyn_alloc

WeeChat ≥ 1.8.

Allocate a dynamic string, with a variable length.
Internally, a structure is allocated with the string pointer, the allocated size and current length of string.

Only the pointer to string pointer (**string) is used in all the string_dyn_* functions.

Prototipo:

char **weechat_string_dyn_alloc (int size_alloc);

Argomenti:

  • size_alloc: the initial allocated size (must be greater than zero)

Valore restituito:

  • pointer to the dynamic string

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.45. string_dyn_copy

WeeChat ≥ 1.8.

Copy a string in a dynamic string.

The pointer *string can change if the string is reallocated (if there is not enough space to copy the string).

Prototipo:

int weechat_string_dyn_copy (char **string, const char *new_string);

Argomenti:

  • string: pointer to dynamic string

  • new_string: the string to copy

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
if (weechat_string_dyn_copy (string, "test"))
{
    /* OK */
}
else
{
    /* error */
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.46. string_dyn_concat

WeeChat ≥ 1.8.

Concatenate a string to a dynamic string.

The pointer *string can change if the string is reallocated (if there is not enough space to concatenate the string).

Prototipo:

int weechat_string_dyn_concat (char **string, const char *add);

Argomenti:

  • string: pointer to dynamic string

  • add: the string to add

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
if (weechat_string_dyn_copy (string, "test"))
{
    if (weechat_string_dyn_concat (string, "abc"))
    {
        /* ... */
    }
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.3.47. string_dyn_free

WeeChat ≥ 1.8.

Free a dynamic string.

Prototipo:

char *weechat_string_dyn_free (char **string, int free_string);

Argomenti:

  • string: pointer to dynamic string

  • free_string: free the string itself; if 0, the content of *string remains valid after the call to this function

Valore restituito:

  • string pointer if free_string is 0, otherwise NULL

Esempio in C:

char **string = weechat_string_dyn_alloc (256);
if (weechat_string_dyn_concat (string, "test"))
{
    /* OK */
}
else
{
    /* error */
}
/* ... */
weechat_string_dyn_free (string, 1);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4. UTF-8

Alcune funzioni stringa UTF-8.

3.4.1. utf8_has_8bits

Verifica che una stringa abbia caratteri a 8-bit.

Prototipo:

int weechat_utf8_has_8bits (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • 1 se la stringa ha caratteri a 8-bit, 0 se solo a 7-bit

Esempio in C:

if (weechat_utf8_has_8bits (string))
{
    /* ... */
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.2. utf8_is_valid

Updated in 1.4.

Verifica che una stringa sia valida in UTF-8.

Prototipo:

int weechat_utf8_is_valid (const char *string, int length, char **error);

Argomenti:

  • string: stringa

  • length: max number of UTF-8 chars to check; if ≤ 0, the whole string is checked (WeeChat ≥ 1.4)

  • error: se non NULL, *error è impostato con il puntatore al primo carattere UTF-8 non valido nella stringa, se esiste

Valore restituito:

  • 1 se la stringa UTF-8 è valida, altrimenti 0

Esempio in C:

char *error;
if (weechat_utf8_is_valid (string, -1, &error))
{
    /* ... */
}
else
{
    /* "error" punta al primo carattere non valido */
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.3. utf8_normalize

Normalizza le stringhe UTF-8: rimuove i caratteri non UTF-8 e li sostituisce con un carattere.

Prototipo:

void weechat_utf8_normalize (char *string, char replacement);

Argomenti:

  • string: stringa

  • replacement: carattere sotitutivo per i caratteri non validi

Esempio in C:

weechat_utf8_normalize (string, '?');
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.4. utf8_prev_char

Updated in 1.3.

Restituisce il puntatore al carattere UTF-8 precedente in una stringa.

Prototipo:

const char *weechat_utf8_prev_char (const char *string_start,
                                    const char *string);

Argomenti:

  • string_start: inizio della stringa (la funzione non restituirà un carattere prima di questo puntatore)

  • string: puntatore alla stringa (deve essere ≥ string_start)

Valore restituito:

  • puntatore al precedente carattere UTF-8, NULL se non trovata (raggiunta l’inizio della stringa) (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *prev_char = weechat_utf8_prev_char (string, ptr_in_string);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.5. utf8_next_char

Updated in 1.3.

Restituisce il puntatore al successivo carattere UTF-8 in una stringa.

Prototipo:

const char *weechat_utf8_next_char (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • puntatore al carattere UTF-8 successivo, NULL se non trovato (raggiunta la fine della stringa) (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *next_char = weechat_utf8_next_char (string);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.6. utf8_char_int

Restituisce un carattere UTF-8 come intero.

Prototipo:

int weechat_utf8_char_int (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • carattere UTF-8 come intero

Esempio in C:

int char_int = weechat_utf8_char_int ("être");  /* "ê" come intero */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.7. utf8_char_size

Restituisce la dimensione di un carattere UTF-8 (in byte).

Prototipo:

int weechat_utf8_char_size (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • dimensione carattere UTF-8 (in byte)

Esempio in C:

int char_size = weechat_utf8_char_size ("être");  /* == 2 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.8. utf8_strlen

Restituisce la lunghezza della stringa UTF-8 (nei caratteri UTF-8).

Prototipo:

int weechat_utf8_strlen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • lunghezza della stringa UTF-8 (numero di caratteri UTF-8)

Esempio in C:

int length = weechat_utf8_strlen ("chêne");  /* == 5 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.9. utf8_strnlen

Restituisce la lunghezza della stringa UTF-8 (in caratteri UTF-8), per un massimo di bytes nella stringa.

Prototipo:

int weechat_utf8_strnlen (const char *string, int bytes);

Argomenti:

  • string: stringa

  • bytes: massimo di byte

Valore restituito:

  • lunghezza della stringa UTF-8 (numero di caratteri UTF-8)

Esempio in C:

int length = weechat_utf8_strnlen ("chêne", 4);  /* == 3 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.10. utf8_strlen_screen

Restituisce il numero di caratteri necessari per visualizzare la stringa UTF-8 su schermo.

Prototipo:

int weechat_utf8_strlen_screen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • numero di caratteri necessari per visualizzare la stringa UTF-8 su schermo

Esempio in C:

int length_on_screen = weechat_utf8_strlen_screen ("é");  /* == 1 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.11. utf8_charcmp

Updated in 1.0.

Confronta due caratteri UTF-8.

Prototipo:

int weechat_utf8_charcmp (const char *string1, const char *string2);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

Valore restituito:

  • -1 se string1 < string2

  • 0 se string1 == string2

  • 1 se string1 > string2

Esempio in C:

int diff = weechat_utf8_charcmp ("aaa", "ccc");  /* == -2 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.12. utf8_charcasecmp

Updated in 1.0.

Confronta due caratteri UTF-8, ignorando la sensibilità alle maiuscole.

Prototipo:

int weechat_utf8_charcasecmp (const char *string1, const char *string2);

Argomenti:

  • string1: prima stringa da comparare

  • string2: seconda stringa da comparare

Valore restituito:

  • -1 se string1 < string2

  • 0 se string1 == string2

  • 1 se string1 > string2

Esempio in C:

int diff = weechat_utf8_charcasecmp ("aaa", "CCC");  /* == -2 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.13. utf8_char_size_screen

Restituisce il numero di caratteri necessari per visualizzare il carattere UTF-8 sullo schermo.

Prototipo:

int weechat_utf8_char_size_screen (const char *string);

Argomenti:

  • string: stringa

Valore restituito:

  • numero di caratteri necessario per visualizzare il carattere UTF-8 su schermo

Esempio in C:

int length_on_screen = weechat_utf8_char_size_screen ("é");  /* == 1 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.14. utf8_add_offset

Updated in 1.3.

Si sposta in avanti di N caratteri in una stringa UTF-8.

Prototipo:

const char *weechat_utf8_add_offset (const char *string, int offset);

Argomenti:

  • string: stringa

  • offset: numero di caratteri

Valore restituito:

  • puntatore alla stringa, N caratteri dopo (NULL se non raggiungibile) (WeeChat ≥ 1.3: pointer returned is a const char * instead of char *)

Esempio in C:

const char *str = "chêne";
const char *str2 = weechat_utf8_add_offset (str, 3);  /* points to "ne" */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.15. utf8_real_pos

Restituisce la posizione reale nella stringa UTF-8.

Prototipo:

int weechat_utf8_real_pos (const char *string, int pos);

Argomenti:

  • string: stringa

  • pos: posizione (numero di caratteri)

Valore restituito:

  • pozisione reale (in byte)

Esempio in C:

int pos = weechat_utf8_real_pos ("chêne", 3);  /* == 4 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.16. utf8_pos

Restituisce la posizione nella stringa UTF-8.

Prototipo:

int weechat_utf8_pos (const char *string, int real_pos);

Argomenti:

  • string: stringa

  • real_pos: posizione (byte)

Valore restituito:

  • posizione (numero di caratteri)

Esempio in C:

int pos = weechat_utf8_pos ("chêne", 4);  /* == 3 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.4.17. utf8_strndup

Restituisce la stringa duplicata, di lunghezza massima length.

Prototipo:

char *weechat_utf8_strndup (const char *string, int length);

Argomenti:

  • string: stringa

  • length: caratteri massimi da duplicare

Valore restituito:

  • stringa duplicata (deve essere liberata chiamando "free" dopo l’uso)

Esempio in C:

char *string = weechat_utf8_strndup ("chêne", 3);  /* restituisce "chê" */
/* ... */
free (string);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.5. Cryptography

Some cryptographic functions.

3.5.1. crypto_hash

WeeChat ≥ 2.8.

Compute hash of data.

Prototipo:

int weechat_crypto_hash (const void *data, int data_size, const char *hash_algo,
                         void *hash, int *hash_size);

Argomenti:

  • data: the data to hash

  • data_size: number of bytes to hash in data

  • hash_algo: the hash algorithm, see table below

  • hash: pointer to the hash variable, which is used to store the resulting hash (the buffer must be large enough, according to the algorithm, see table below)

  • hash_size: pointer to a variable used to store the length of the hash computed (in bytes) (can be NULL)

Supported hash algorithms:

Value Algorithm Hash size Notes

crc32

CRC32

4 bytes (32 bits)

Not a hash algorithm in the cryptographic sense.

md5

MD5

16 bytes (128 bits)

Weak, not recommended for cryptography usage.

sha1

SHA-1

20 bytes (160 bits)

Weak, not recommended for cryptography usage.

sha224

SHA-224

28 bytes (224 bits)

sha256

SHA-256

32 bytes (256 bits)

sha384

SHA-384

48 bytes (384 bits)

sha512

SHA-512

64 bytes (512 bits)

sha3-224

SHA3-224

28 bytes (224 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

sha3-256

SHA3-256

32 bytes (256 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

sha3-384

SHA3-384

48 bytes (384 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

sha3-512

SHA3-512

64 bytes (512 bits)

Algorithm available with libgcrypt ≥ 1.7.0.

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

const char *data = "abcdefghijklmnopqrstuvwxyz";
char hash[256 / 8];
int rc, hash_size;
rc = weechat_crypto_hash (data, strlen (data), "sha256", hash, &hash_size);
/* rc == 1, hash_size == 32 and hash is a buffer with:
   71 c4 80 df 93 d6 ae 2f 1e fa d1 44 7c 66 c9 52 5e 31 62 18 cf 51 fc 8d 9e d8 32 f2 da f1 8b 73 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.5.2. crypto_hash_pbkdf2

WeeChat ≥ 2.8.

Compute PKCS#5 Passphrase Based Key Derivation Function number 2 (PBKDF2) hash of data.

Prototipo:

int weechat_crypto_hash_pbkdf2 (const void *data, int data_size,
                                const char *hash_algo,
                                const void *salt, int salt_size,
                                int iterations,
                                void *hash, int *hash_size);

Argomenti:

  • data: the data to hash

  • data_size: number of bytes to hash in data

  • hash_algo: hash algorithm used by the key derivation function, see table in function crypto_hash

  • salt: the salt

  • salt_size: number of bytes in salt

  • iterations: number of iterations

  • hash: pointer to the hash variable, which is used to store the resulting hash (the buffer must be large enough, according to the algorithm, see table in function crypto_hash)

  • hash_size: pointer to a variable used to store the size of the hash computed (in bytes) (can be NULL)

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

const char *data = "abcdefghijklmnopqrstuvwxyz";
const char *salt = "12345678901234567890123456789012";  /* 32 bytes */
char hash[256 / 8];
int rc, hash_size;
rc = weechat_crypto_hash_pbkdf2 (data, strlen (data), "sha256", salt, strlen (salt), 100000,
                                 hash, &hash_size);
/* rc == 1, hash_size == 32 and hash is a buffer with:
   99 b3 5e 42 53 d1 a7 a8 49 c1 dc 2c e2 53 c2 b6 6d a1 8b dc 6e 78 a7 06 e0 ef 34 db 0a 7a a2 bb */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.6. Cartelle

Alcune funzioni legate alle cartelle.

3.6.1. mkdir_home

Crea una cartella nella home di WeeChat.

Prototipo:

int weechat_mkdir_home (char *directory, int mode);

Argomenti:

  • directory: nome della cartella da creare

  • mode: modalità per la cartella

Valore restituito:

  • 1 se la cartella è stata creata con successo, 0 in caso di errore

Esempio in C:

if (!weechat_mkdir_home ("temp", 0755))
{
    /* errore */
}

Script (Python):

# prototipo
weechat.mkdir_home(directory, mode)

# esempio
weechat.mkdir_home("temp", 0755)

3.6.2. mkdir

Crea una cartella.

Prototipo:

int weechat_mkdir (char *directory, int mode);

Argomenti:

  • directory: nome della cartella da creare

  • mode: modalità per la cartella

Valore restituito:

  • 1 se la cartella è stata creata con successo, 0 in caso di errore

Esempio in C:

if (!weechat_mkdir ("/tmp/mydir", 0755))
{
    /* errore */
}

Script (Python):

# prototipo
weechat.mkdir(directory, mode)

# esempio
weechat.mkdir("/tmp/mydir", 0755)

3.6.3. mkdir_parents

Crea una cartella e le cartelle genitore se necessario.

Prototipo:

int weechat_mkdir_parents (char *directory, int mode);

Argomenti:

  • directory: nome della cartella da creare

  • mode: modalità per la cartella

Valore restituito:

  • 1 se la cartella è stata creata con successo, 0 in caso di errore

Esempio in C:

if (!weechat_mkdir_parents ("/tmp/my/dir", 0755))
{
    /* errore */
}

Script (Python):

# prototipo
weechat.mkdir_parents(directory, mode)

# esempio
weechat.mkdir_parents("/tmp/my/dir", 0755)

3.6.4. exec_on_files

Updated in 1.5, 2.0.

Cerca i file in una cartella ed esegue una callback su ogni file.

Prototipo:

void weechat_exec_on_files (const char *directory,
                            int recurse_subdirs,
                            int hidden_files,
                            void (*callback)(void *data,
                                             const char *filename),
                            void *callback_data);

Argomenti:

  • directory: cartella in cui cercare i file

  • recurse_subdirs: 1 to recurse into sub-directories (WeeChat ≥ 2.0)

  • hidden_files: 1 per includere i file nascosti, altrimenti 0

  • callback: funzione chiamata per ogni file trovato, argomenti:

    • void *data: puntatore

    • const char *filename: nome file trovato

  • callback_data: puntatore fornito alla callback quando chiamata da WeeChat

Esempio in C:

void callback (void *data, const char *filename)
{
    /* ... */
}
...
weechat_exec_on_files ("/tmp", 0, 0, &callback, NULL);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.6.5. file_get_content

WeeChat ≥ 0.3.1.

Ottiene il contenuto del file di testo in una stringa.

Prototipo:

char *weechat_file_get_content (const char *filename);

Argomenti:

  • filename: percorso e nome file

Valore restituito:

  • contenuto del file come stringa (deve essere liberata chiamando "free dopo l’uso)

Esempio in C:

char *content;

content = weechat_file_get_content ("/tmp/test.txt");
/* ... */
free (content);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.7. Utilità

Alcune funzioni utili.

3.7.1. util_timeval_cmp

Confronta due strutture "timeval".

Prototipo:

int weechat_util_timeval_cmp (struct timeval *tv1, struct timeval *tv2);

Argomenti:

  • tv1: prima struttura "timeval"

  • tv2: seconda struttura "timeval"

Valore restituito:

  • -1 se tv1 < tv2

  • zero se tv1 == tv2

  • +1 se tv1 > tv2

Esempio in C:

if (weechat_util_timeval_cmp (&tv1, &tv2) > 0)
{
    /* tv1 > tv2 */
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.7.2. util_timeval_diff

Updated in 1.1.

Return difference (in microseconds) between two "timeval" structures.

Prototipo:

long long weechat_util_timeval_diff (struct timeval *tv1, struct timeval *tv2);

Argomenti:

  • tv1: prima struttura "timeval"

  • tv2: seconda struttura "timeval"

Valore restituito:

  • difference in microseconds

Note
With WeeChat ≤ 1.0, the returned value was in milliseconds.

Esempio in C:

long long diff = weechat_util_timeval_diff (&tv1, &tv2);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.7.3. util_timeval_add

Updated in 1.1.

Add interval (in microseconds) to a timeval structure.

Prototipo:

void weechat_util_timeval_add (struct timeval *tv, long long interval);

Argomenti:

  • tv: struttura timeval

  • interval: interval (in microseconds)

Note
With WeeChat ≤ 1.0, the interval was expressed in milliseconds.

Esempio in C:

weechat_util_timeval_add (&tv, 2000000);  /* aggiunge 2 secondi */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.7.4. util_get_time_string

WeeChat ≥ 0.3.2, updated in 1.3.

Get date/time as a string built with "strftime" and the format defined in option weechat.look.time_format.

Prototipo:

const char *weechat_util_get_time_string (const time_t *date);

Argomenti:

  • date: puntatore alla data

Valore restituito:

  • pointer to a string with date/time

Esempio in C:

time_t date = time (NULL);
weechat_printf (NULL, "date: %s",
                weechat_util_get_time_string (&date));
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.7.5. util_version_number

WeeChat ≥ 0.3.9.

Convert a string with WeeChat version to a number.

Prototipo:

int weechat_util_version_number (const char *version);

Argomenti:

  • version: WeeChat version as string (example: "0.3.9" or "0.3.9-dev")

Esempio in C:

version_number = weechat_util_version_number ("0.3.8");      /* == 0x00030800 */
version_number = weechat_util_version_number ("0.3.9-dev");  /* == 0x00030900 */
version_number = weechat_util_version_number ("0.3.9-rc1");  /* == 0x00030900 */
version_number = weechat_util_version_number ("0.3.9");      /* == 0x00030900 */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.8. Elenchi ordinati

Funzioni lista ordinata.

3.8.1. list_new

Crea una nuova lista.

Prototipo:

struct t_weelist *weechat_list_new ();

Valore restituito:

  • puntatore alla nuova lista

Esempio in C:

struct t_weelist *list = weechat_list_new ();

Script (Python):

# prototipo
list = weechat.list_new()

# esempio
list = weechat.list_new()

3.8.2. list_add

Aggiunge un elemento in una lista.

Prototipo:

struct t_weelist_item *weechat_list_add (struct t_weelist *weelist,
                                         const char *data,
                                         const char *where,
                                         void *user_data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da inserire nella lista

  • where: posizione nella lista:

    • WEECHAT_LIST_POS_SORT: aggiunge alla lista, mantenendola ordinata

    • WEECHAT_LIST_POS_BEGINNING: aggiunge all’inizio della lista

    • WEECHAT_LIST_POS_END: aggiunge alla fine della lista

  • user_data: qualsiasi puntatore

Valore restituito:

  • puntatore al nuovo elemento

Esempio in C:

struct t_weelist_item *my_item =
    weechat_list_add (list, "my data", WEECHAT_LIST_POS_SORT, NULL);

Script (Python):

# prototipo
item = weechat.list_add(list, data, where, user_data)

# esempio
item = weechat.list_add(list, "my data", weechat.WEECHAT_LIST_POS_SORT, "")

Cerca un elemento nella lista.

Prototipo:

struct t_weelist_item *weechat_list_search (struct t_weelist *weelist,
                                            const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • puntatore all’elemento trovato, NULL se non trovato

Esempio in C:

struct t_weelist_item *item = weechat_list_search (list, "my data");

Script (Python):

# prototipo
item = weechat.list_search(list, data)

# esempio
item = weechat.list_search(list, "my data")

3.8.4. list_search_pos

WeeChat ≥ 0.3.4.

Cerca la posizione di un elemento nella lista.

Prototipo:

int weechat_list_search_pos (struct t_weelist *weelist,
                             const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • posizione dell’elemento trovato, -1 se non trovato

Esempio in C:

int pos_item = weechat_list_search_pos (list, "my data");

Script (Python):

# prototipo
pos_item = weechat.list_search_pos(list, data)

# esempio
pos_item = weechat.list_search_pos(list, "my data")

3.8.5. list_casesearch

Cerca un elemento nella lista, senza effettuare una ricerca esatta.

Prototipo:

struct t_weelist_item *weechat_list_casesearch (struct t_weelist *weelist,
                                                const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • puntatore all’elemento trovato, NULL se non trovato

Esempio in C:

struct t_weelist_item *item = weechat_list_casesearch (list, "my data");

Script (Python):

# prototipo
item = weechat.list_casesearch(list, data)

# esempio
item = weechat.list_casesearch(list, "my data")

3.8.6. list_casesearch_pos

WeeChat ≥ 0.3.4.

Cerca la posizione di un elemento in una lista, ricerca normale.

Prototipo:

int weechat_list_casesearch_pos (struct t_weelist *weelist,
                                 const char *data);

Argomenti:

  • weelist: puntatore alla lista

  • data: dati da cercare nella lista

Valore restituito:

  • posizione dell’elemento trovato, -1 se non trovato

Esempio in C:

int pos_item = weechat_list_casesearch_pos (list, "my data");

Script (Python):

# prototipo
pos_item = weechat.list_casesearch_pos(list, data)

# esempio
pos_item = weechat.list_casesearch_pos(list, "my data")

3.8.7. list_get

Restituisce un elemento in una lista in base alla sua posizione.

Prototipo:

struct t_weelist_item *weechat_list_get (struct t_weelist *weelist,
                                         int position);

Argomenti:

  • weelist: puntatore alla lista

  • position: posizione nella lista (il primo elemento è 0)

Valore restituito:

  • puntatore all’elemento trovato, NULL se non trovato

Esempio in C:

struct t_weelist_item *item = weechat_list_get (list, 0);  /* primo elemento */

Script (Python):

# prototipo
item = weechat.list_get(list, position)

# esempio
item = weechat.list_get(list, 0)

3.8.8. list_set

Imposta un nuovo valore per un elemento.

Prototipo:

void weechat_list_set (struct t_weelist_item *item, const char *value);

Argomenti:

  • item: puntatore all’elemento

  • value: nuovo valore per l’elemento

Esempio in C:

weechat_list_set (item, "nuovi dati");

Script (Python):

# prototipo
weechat.list_set(item, value)

# esempio
weechat.list_set(item, "nuovi dati")

3.8.9. list_next

Restituisce l’elemento successivo nella lista.

Prototipo:

struct t_weelist_item *weechat_list_next (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • puntatore all’elemento successivo, NULL se il puntatore è l’ultimo oggetto nella lista

Esempio in C:

struct t_weelist_item *next_item = weechat_list_next (item);

Script (Python):

# prototipo
item = weechat.list_next(item)

# esempio
item = weechat.list_next(item)

3.8.10. list_prev

Restituisce l’elemento precedente nella lista.

Prototipo:

struct t_weelist_item *weechat_list_prev (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • pointer to previous item, NULL if pointer was first item in list

Esempio in C:

struct t_weelist_item *prev_item = weechat_list_prev (item);

Script (Python):

# prototipo
item = weechat.list_prev(item)

# esempio
item = weechat.list_prev(item)

3.8.11. list_string

Restituisce il valore stringa di un elemento.

Prototipo:

const char *weechat_list_string (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • valore stringa di un elemento

Esempio in C:

weechat_printf (NULL, "valore dell'elemento: %s", weechat_list_string (item));

Script (Python):

# prototipo
value = weechat.list_string(item)

# esempio
weechat.prnt("", "valore dell'elemento: %s" % weechat.list_string(item))

3.8.12. list_user_data

WeeChat ≥ 2.6.

Return pointer to the user data of an item.

Prototipo:

void *weechat_list_user_data (struct t_weelist_item *item);

Argomenti:

  • item: puntatore all’elemento

Valore restituito:

  • pointer to the user data of item

Esempio in C:

weechat_printf (NULL, "user data of item: 0x%lx", weechat_list_user_data (item));
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.8.13. list_size

Restituisce la dimensione della lista (numero di elementi).

Prototipo:

char *weechat_list_size (struct t_weelist *weelist);

Argomenti:

  • weelist: puntatore alla lista

Valore restituito:

  • dimensione della lista (numero di elementi), 0 se la lista è vuota

Esempio in C:

weechat_printf (NULL, "dimensione della lista: %d", weechat_list_size (list));

Script (Python):

# prototipo
size = weechat.list_size(list)

# esempio
weechat.prnt("", "dimensione della lista: %d" % weechat.list_size(list))

3.8.14. list_remove

Rimuove un elemento in una lista.

Prototipo:

void weechat_list_remove (struct t_weelist *weelist,
                          struct t_weelist_item *item);

Argomenti:

  • weelist: puntatore alla lista

  • item: puntatore all’elemento

Esempio in C:

weechat_list_remove (list, item);

Script (Python):

# prototipo
weechat.list_remove(list, item)

# esempio
weechat.list_remove(list, item)

3.8.15. list_remove_all

Rimuove tutti gli elementi in una lista.

Prototipo:

void weechat_list_remove_all (struct t_weelist *weelist);

Argomenti:

  • weelist: puntatore alla lista

Esempio in C:

weechat_list_remove_all (list);

Script (Python):

# prototipo
weechat.list_remove_all(list)

# esempio
weechat.list_remove_all(list)

3.8.16. list_free

Libera una lista.

Prototipo:

void weechat_list_free (struct t_weelist *weelist);

Argomenti:

  • weelist: puntatore alla lista

Esempio in C:

weechat_list_free (list);

Script (Python):

# prototipo
weechat.list_free(list)

# esempio
weechat.list_free(list)

3.9. Array lists

Array list functions.

An array list is a list of pointers with a dynamic size and optional sort.

3.9.1. arraylist_new

WeeChat ≥ 1.8.

Create a new array list.

Prototipo:

struct t_arraylist *weechat_arraylist_new (int initial_size,
                                           int sorted,
                                           int allow_duplicates,
                                           int (*callback_cmp)(void *data,
                                                               struct t_arraylist *arraylist,
                                                               void *pointer1,
                                                               void *pointer2),
                                           void *callback_cmp_data,
                                           void (*callback_free)(void *data,
                                                                 struct t_arraylist *arraylist,
                                                                 void *pointer),
                                           void *callback_free_data);

Argomenti:

  • initial_size: initial size of the array list (not the number of items)

  • sorted: 1 to sort the array list, 0 for no sort

  • allow_duplicates: 1 to allow duplicate entries, 0 to prevent a same entry to be added again

  • callback_cmp: callback used to compare two items (optional), arguments and return value:

    • void *data: pointer

    • struct t_arraylist *arraylist: array list pointer

    • void *pointer1: pointer to first item

    • void *pointer2: pointer to second item

    • return value:

      • negative number if first item is less than second item

      • 0 if first item equals second item

      • positive number if first item is greater than second item

  • callback_cmp_data: pointer given to callback when it is called by WeeChat

  • callback_free: callback used to free an item (optional), arguments:

    • void *data: pointer

    • struct t_arraylist *arraylist: array list pointer

    • void *pointer: pointer to item

  • callback_free_data: pointer given to callback when it is called by WeeChat

Valore restituito:

  • pointer to new array list

Esempio in C:

int
cmp_cb (void *data, struct t_arraylist *arraylist,
        void *pointer1, void *pointer2)
{
    if (...)
        return -1;
    else if (...)
        return 1;
    else
        return 0;
}

struct t_arraylist *list = weechat_arraylist_new (32, 1, 1,
                                                  &cmp_cb, NULL, NULL, NULL);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.9.2. arraylist_size

WeeChat ≥ 1.8.

Return size of array list (number of item pointers).

Prototipo:

int weechat_list_size (struct t_arraylist *arraylist);

Argomenti:

  • arraylist: array list pointer

Valore restituito:

  • size of array list (number of items), 0 if array list is empty

Esempio in C:

weechat_printf (NULL, "size of array list: %d", weechat_arraylist_size (arraylist));
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.9.3. arraylist_get

WeeChat ≥ 1.8.

Return an item pointer by position.

Prototipo:

void *weechat_arraylist_get (struct t_arraylist *arraylist, int index);

Argomenti:

  • arraylist: array list pointer

  • index: index in list (first pointer is 0)

Valore restituito:

  • pointer found, NULL if pointer was not found

Esempio in C:

void *pointer = weechat_arraylist_get (arraylist, 0);  /* first item */
Note
Questa funzione non è disponibile nelle API per lo scripting.

WeeChat ≥ 1.8.

Search an item in an array list.

Prototipo:

void *weechat_arraylist_search (struct t_arraylist *arraylist, void *pointer,
                                int *index, int *index_insert);

Argomenti:

  • arraylist: array list pointer

  • pointer: pointer to the item to search in array list

  • index: pointer to integer that will be set to the index found, or -1 if not found (optional)

  • index_insert: pointer to integer that will be set with the index that must be used to insert the element in the arraylist (to keep arraylist sorted) (optional)

Valore restituito:

  • pointer to item found, NULL if item was not found

Esempio in C:

int index, index_insert;
void *item = weechat_arraylist_search (arraylist, pointer, &index, &index_insert);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.9.5. arraylist_insert

WeeChat ≥ 1.8.

Insert an item in an array list.

Prototipo:

int weechat_arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer);

Argomenti:

  • arraylist: array list pointer

  • index: position of the item in array list or -1 to add at the end (this argument is used only if the array list is not sorted, it is ignored if the array list is sorted)

  • pointer: pointer to the item to insert

Valore restituito:

  • index of new item (>= 0), -1 if error.

Esempio in C:

int index = weechat_arraylist_insert (arraylist, -1, pointer);  /* insert at the end if not sorted */
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.9.6. arraylist_add

WeeChat ≥ 1.8.

Add an item in an array list.

Prototipo:

int weechat_arraylist_add (struct t_arraylist *arraylist, void *pointer);

Argomenti:

  • arraylist: array list pointer

  • pointer: pointer to the item to add

Valore restituito:

  • index of new item (>= 0), -1 if error.

Esempio in C:

int index = weechat_arraylist_add (arraylist, pointer);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.9.7. arraylist_remove

WeeChat ≥ 1.8.

Remove an item from an array list.

Prototipo:

int weechat_arraylist_remove (struct t_arraylist *arraylist, int index);

Argomenti:

  • arraylist: array list pointer

  • index: index of the item to remove

Valore restituito:

  • index of item removed, -1 if error.

Esempio in C:

int index_removed = weechat_arraylist_remove (arraylist, index);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.9.8. arraylist_clear

WeeChat ≥ 1.8.

Remove all items from an array list.

Prototipo:

int weechat_arraylist_clear (struct t_arraylist *arraylist);

Argomenti:

  • arraylist: array list pointer

Valore restituito:

  • 1 if OK, 0 if error

Esempio in C:

if (weechat_arraylist_clear (arraylist))
{
    /* OK */
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.9.9. arraylist_free

WeeChat ≥ 1.8.

Free an array list.

Prototipo:

void weechat_arraylist_free (struct t_arraylist *arraylist);

Argomenti:

  • arraylist: array list pointer

Esempio in C:

weechat_arraylist_free (arraylist);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10. Tabelle hash

Funzioni per le tabelle hash.

3.10.1. hashtable_new

WeeChat ≥ 0.3.3.

Crea una nuova tabella hash.

Prototipo:

struct t_hashtable *weechat_hashtable_new (int size,
                                           const char *type_keys,
                                           const char *type_values,
                                           unsigned long long (*callback_hash_key)(struct t_hashtable *hashtable,
                                                                                   const void *key),
                                           int (*callback_keycmp)(struct t_hashtable *hashtable,
                                                                  const void *key1,
                                                                  const void *key2));

Argomenti:

  • size: dimensione dell’array interno per memorizzare le chiavi con hash, un valore più alto usa più memoria, ma ha migliori performance. (questo non è un limite per il numero di elementi nella tabella hash)

  • type_keys: tipo per le chiavi nella tabella hash:

    • WEECHAT_HASHTABLE_INTEGER

    • WEECHAT_HASHTABLE_STRING

    • WEECHAT_HASHTABLE_POINTER

    • WEECHAT_HASHTABLE_BUFFER

    • WEECHAT_HASHTABLE_TIME

  • type_values: tipo per i valori nella tabella hash:

    • WEECHAT_HASHTABLE_INTEGER

    • WEECHAT_HASHTABLE_STRING

    • WEECHAT_HASHTABLE_POINTER

    • WEECHAT_HASHTABLE_BUFFER

    • WEECHAT_HASHTABLE_TIME

  • callback_hash_key: callback used to "hash" a key (key as integer value), can be NULL if key type is not "buffer" (a default hash function is used), arguments and return value:

    • struct t_hashtable *hashtable: puntatore alla tabella hash

    • const void *key: chiave

    • return value: hash della chiave

  • callback_keycmp: callback used to compare two keys, can be NULL if key type is not "buffer" (a default comparison function is used), arguments and return value:

    • struct t_hashtable *hashtable: puntatore alla tabella hash

    • const void *key1: prima chiave

    • const void *key2: seconda chiave

    • valore restituito:

      • numero negativo se key1 è minore di key2

      • 0 se key1 è uguale a key2

      • numero positivo se key1 è maggiore di key2

Valore restituito:

  • puntatore alla nuova tabella hash, NULL in caso di errore

Esempio in C:

struct t_hashtable *hashtable = weechat_hashtable_new (8,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       WEECHAT_HASHTABLE_STRING,
                                                       NULL,
                                                       NULL);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.2. hashtable_set_with_size

WeeChat ≥ 0.3.3, updated in 0.4.2.

Aggiunge o aggiorna un elemento nella tabella hash con la dimensione per la chiave ed il valore.

Prototipo:

struct t_hashtable_item *weechat_hashtable_set_with_size (struct t_hashtable *hashtable,
                                                          const void *key, int key_size,
                                                          const void *value, int value_size);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

  • key_size: dimensione della chiave (in byte), usata solo se il tipo delle chiavi nella tabella hash è "buffer"

  • value: puntatore al valore

  • value_size: dimensione del valore (in byte), utilizzata solo se il tipo dei valori nella tabella è "buffer"

Valore restituito:

  • pointer to item created/updated, NULL if error

Esempio in C:

weechat_hashtable_set_with_size (hashtable, "my_key", 0,
                                 my_buffer, sizeof (my_buffer_struct));
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.3. hashtable_set

WeeChat ≥ 0.3.3, updated in 0.4.2.

Aggiunge o aggiorna un elemento nella tabella hash.

Prototipo:

struct t_hashtable_item *weechat_hashtable_set (struct t_hashtable *hashtable,
                                                const void *key, const void *value);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

  • value: puntatore al valore

Valore restituito:

  • pointer to item created/updated, NULL if error

Esempio in C:

weechat_hashtable_set (hashtable, "my_key", "my_value");

3.10.4. hashtable_get

WeeChat ≥ 0.3.3.

Ottiene il valore associato ad una chiave in una tabella hash.

Prototipo:

void *weechat_hashtable_get (struct t_hashtable *hashtable, void *key);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

Valore restituito:

  • valore per la chiave, NULL se non trovata

Esempio in C:

void *value = weechat_hashtable_get (hashtable, "my_key");
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.5. hashtable_has_key

WeeChat ≥ 0.3.4.

Check if a key is in the hashtable.

Prototipo:

int weechat_hashtable_has_key (struct t_hashtable *hashtable, void *key);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • key: puntatore alla chiave

Valore restituito:

  • 1 se la chiave si trova nella tabella hash, 0 in caso contrario

Esempio in C:

if (weechat_hashtable_has_key (hashtable, "my_key"))
{
    /* la chiave è nella tabella hash */
    /* ... */
}
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.6. hashtable_map

WeeChat ≥ 0.3.3.

Chiama una funzione su tutte le voci della tabella hash.

Prototipo:

void weechat_hashtable_map (struct t_hashtable *hashtable,
                            void (*callback_map)(void *data,
                                                 struct t_hashtable *hashtable,
                                                 const void *key,
                                                 const void *value),
                            void *callback_map_data);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • callback_map: funzione chiamata per ogni voce nella tabella hash

  • callback_map_data: puntatore fornito alla mappa di callback quando chiamata

Esempio in C:

void
map_cb (void *data, struct t_hashtable *hashtable,
        const void *key, const void *value)
{
    /* display key and value (they are both strings here) */
    weechat_printf (NULL, "key: '%s', value: '%s'",
                    (const char *)key,
                    (const char *)value);
}
/* ... */
weechat_hashtable_map (hashtable, &map_cb, NULL);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.7. hashtable_map_string

WeeChat ≥ 0.3.7.

Chiama una funzione su tutte le voci della tabella hash, inviando chiavi e valori come stringhe.

Prototipo:

void weechat_hashtable_map_string (struct t_hashtable *hashtable,
                                   void (*callback_map)(void *data,
                                                        struct t_hashtable *hashtable,
                                                        const char *key,
                                                        const char *value),
                                   void *callback_map_data);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • callback_map: funzione chiamata per ogni voce nella tabella hash

  • callback_map_data: puntatore fornito alla mappa di callback quando chiamata

Note
Le stringhe key e value inviate alla callback sono temporanee, vengono eliminate dopo la chiamata alla callback.

Esempio in C:

void
map_cb (void *data, struct t_hashtable *hashtable,
        const char *key, const char *value)
{
    /* display key and value */
    weechat_printf (NULL, "key: '%s', value: '%s'",
                    key, value);
}
/* ... */
weechat_hashtable_map_string (hashtable, &map_cb, NULL);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.8. hashtable_dup

WeeChat ≥ 1.0.

Duplicate a hashtable.

Prototipo:

struct t_hashtable *weechat_hashtable_dup (struct t_hashtable *hashtable);

Argomenti:

  • hashtable: puntatore alla tabella hash

Valore restituito:

  • duplicated hashtable

Esempio in C:

struct t_hashtable *new_hashtable = weechat_hashtable_dup (hashtable);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.9. hashtable_get_integer

WeeChat ≥ 0.3.3.

Restituisce un valore intero per la proprietà di una tabella hash.

Prototipo:

int weechat_hashtable_get_integer (struct t_hashtable *hashtable,
                                   void *property);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • property: nome della proprietà:

    • size: dimensione dell’array interno "htable" nella tabella hash

    • items_count: numero di elementi nella tabella hash

Valore restituito:

  • valore intero della proprietà

Esempio in C:

int items_count = weechat_hashtable_get_integer (hashtable, "items_count");
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.10. hashtable_get_string

WeeChat ≥ 0.3.4.

Restituisce il valore stringa della proprietà di una tabella hash.

Prototipo:

const char *weechat_hashtable_get_string (struct t_hashtable *hashtable,
                                          const char *property);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • property: nome della proprietà:

    • type_keys: tipo per le chiavi:

      • integer: intero

      • string: stringa

      • pointer: puntatore

      • buffer: buffer

      • time: tempo

    • type_values: tipo per i valori:

      • integer: intero

      • string: stringa

      • pointer: puntatore

      • buffer: buffer

      • time: tempo

    • keys: stringa con la lista di chiavi (formato: "chiave1,chiave2,chiave3")

    • keys_sorted: stringa con l’elenco di chiavi ordinate (formato: "chiave1,chiave2,chiave3")

    • values: stringa con la lista di valori (formato: "valore1,valore2,valore3")

    • keys_values: stringa con la lista di valori e chiavi (formato: "chiave1:valore1,chiave2:valore2,chiave3:valore3")

    • keys_values_sorted: stringa con la lista di chiavi e valori (ordinata per chiavi) (formato: "chiave1:valore1,chiave2:valore2,chiave3:valore3")

Valore restituito:

  • valore stringa della proprietà

Esempio in C:

weechat_printf (NULL, "keys are type: %s",
                weechat_hashtable_get_string (hashtable, "type_keys"));
weechat_printf (NULL, "list of keys: %s",
                weechat_hashtable_get_string (hashtable, "keys"));
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.11. hashtable_set_pointer

WeeChat ≥ 0.3.4.

Imposta il valore puntatore della proprietà di una tabella hash.

Prototipo:

void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
                                    const char *property, void *pointer);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • property: nome della proprietà:

    • callback_free_key: set callback function used to free keys in hashtable (WeeChat ≥ 0.4.2)

    • callback_free_value: imposta la funzione callback usata per liberare i valori nella tabella hash

  • pointer: new pointer value for property

Esempio in C:

void
my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
{
    /* ... */
}

void
my_free_key_cb (struct t_hashtable *hashtable, void *key)
{
    /* ... */
}

weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
weechat_hashtable_set_pointer (hashtable, "callback_free_key", &my_free_key_cb);
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.12. hashtable_add_to_infolist

WeeChat ≥ 0.3.3.

Aggiunge elementi della tabella hash ad un elemento della lista info.

Prototipo:

int weechat_hashtable_add_to_infolist (struct t_hashtable *hashtable,
                                       struct t_infolist_item *infolist_item,
                                       const char *prefix);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • infolist_item: puntatore all’elemento della lista info

  • prefix: stringa usata come prefisso per i nomi nella lista info

Valore restituito:

  • 1 se ok, 0 in caso di errore

Esempio in C:

weechat_hashtable_add_to_infolist (hashtable, infolist_item, "testhash");

/* se la tabella hash contiene:
     "key1" => "value 1"
     "key2" => "value 2"
   allora le seguenti variabili verranno aggiunti all'elemento  della lista info:
     "testhash_name_00000"  = "key1"
     "testhash_value_00000" = "value 1"
     "testhash_name_00001"  = "key2"
     "testhash_value_00001" = "value 2"
*/
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.13. hashtable_add_from_infolist

WeeChat ≥ 2.2.

Add infolist items in a hashtable.

Prototipo:

int weechat_hashtable_add_from_infolist (struct t_hashtable *hashtable,
                                         struct t_infolist *infolist,
                                         const char *prefix);

Argomenti:

  • hashtable: puntatore alla tabella hash

  • infolist: infolist pointer

  • prefix: stringa usata come prefisso per i nomi nella lista info

Valore restituito:

  • 1 se ok, 0 in caso di errore

Esempio in C:

weechat_hashtable_add_from_infolist (hashtable, infolist, "testhash");

/* if infolist contains:
     "testhash_name_00000"  = "key1"
     "testhash_value_00000" = "value 1"
     "testhash_name_00001"  = "key2"
     "testhash_value_00001" = "value 2"
   then following variables will be added to hashtable:
     "key1" => "value 1"
     "key2" => "value 2"
*/
Note
Questa funzione non è disponibile nelle API per lo scripting.

3.10.14. hashtable_remove

WeeChat ≥ 0.3.3.

Rimuove un elemento in una tabella hash.

Prototipo:

void weechat_hashtable_remove (str