diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-02-21 07:06:01 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-03-16 20:42:18 +0100 |
commit | 66571a0b634ef28307f6d6ceef1ba29c091ca524 (patch) | |
tree | 08cc8a4eb2968952307dbfc394f51383f5dfc45e /doc | |
parent | 7b8e5b36c0e894df40642b3ce993767844edc16b (diff) | |
download | weechat-66571a0b634ef28307f6d6ceef1ba29c091ca524.zip |
core: add configuration version, add API function config_set_version
Diffstat (limited to 'doc')
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 176 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 182 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 177 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 177 | ||||
-rw-r--r-- | doc/sr/weechat_plugin_api.sr.adoc | 181 |
5 files changed, 891 insertions, 2 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index db0b597d0..feb7f26ac 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -6366,6 +6366,182 @@ def my_config_reload_cb(data: str, config_file: str) -> int: config_file = weechat.config_new("test", "my_config_reload_cb", "") ---- +==== config_set_version + +_WeeChat ≥ 3.9._ + +Set configuration file version and a callback to update config sections/options +on-the-fly when the config is read. + +Prototype: + +[source,c] +---- +int config_file_set_version (struct t_config_file *config_file, + int version, + struct t_hashtable *(*callback_update)(const void *pointer, + void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read), + const void *callback_update_pointer, + void *callback_update_data); +---- + +Arguments: + +* _config_file_: configuration file pointer +* _version_: version, must be ≥ 2 +* _callback_update_: function called when configuration file is read, for each + section and each option, if the version read is less than the expected version, + (optional, can be NULL, see below), arguments and return value: +** _const void *pointer_: pointer +** _void *data_: pointer +** _struct t_config_file *config_file_: configuration file pointer +** _int version_read_: version read in configuration file (1 by default) +** _struct t_hashtable *data_read_: hashtable with data read from configuration file + (see below) +** return value: +*** either "data_read" pointer (hashtable completed), or pointer to a new + hashtable (created by callback, with keys and values of type "string") +* _callback_update_pointer_: pointer given to callback when it is called by + WeeChat +* _callback_update_data_: pointer given to callback when it is called by + WeeChat; if not NULL, it must have been allocated with malloc (or similar + function) and it is automatically freed when the configuration file is freed + +Update callback: + +* The callback receives a hashtable with data read from configuration file: + +[width="100%",cols="1m,2,8",options="header"] +|=== +| Key | Availability | Value +| config | Always set | Name of configuration file, without extension (eg: `weechat`) +| section | Always set | Name of section being read +| option | For option only | Name of the option +| value | For option only | Value of the option (if not NULL) +| value_null | For option only | Option as NULL value (value is always `1`) +|=== + +* The callback can update "section" for a line with a section and "option", "value" + and "value_null" for a line with an option. +* If "option" is set to empty string by the callback, the line read in + configuration file is ignored. +* Field "value_null" is set to force a NULL value for the option. + +Return value: + +* 1 if OK, 0 if error + +C example: + +[source,c] +---- +struct t_hashtable * +my_config_update_cb (const void *pointer, void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read) +{ + const char *ptr_section, *ptr_option; + + /* return now if version is already up-to-date */ + if (version_read >= 2) + return NULL; + + ptr_section = hashtable_get (data_read, "section"); + ptr_option = hashtable_get (data_read, "option"); + + /* rename section "abc" to "def" */ + if (ptr_section && !ptr_option && (strcmp (ptr_section, "abc") == 0)) + { + hashtable_set (data_read, "section", "def"); + return data_read; + } + + /* limit other changes to section "test" */ + if (!ptr_section || !ptr_option || (strcmp (ptr_section, "test") != 0)) + return NULL; + + /* rename option "test1" to "test2" */ + if (strcmp (ptr_option, "test1") == 0) + { + hashtable_set (data_read, "option", "test2"); + return data_read; + } + + /* set value to "xxx" for option "test" */ + if (strcmp (ptr_option, "test") == 0) + { + hashtable_set (data_read, "value", "xxx"); + return data_read; + } + + /* set value to NULL for option "test_null" */ + if (strcmp (ptr_option, "test_null") == 0) + { + hashtable_set (data_read, "value_null", "1"); + return data_read; + } + + /* no changes */ + return NULL; +} + +struct t_config_file *config_file = weechat_config_new ("test", NULL, NULL, NULL); +weechat_config_set_version (config_file, 2, &my_config_update_cb, NULL, NULL); +weechat_config_read (config_file); +---- + +Script (Python): + +[source,python] +---- +# prototype +def config_set_version(config_file: str, version: int, callback_update: str, callback_update_data: str) -> int: ... + +# example +def my_config_update_cb(data: str, config_file: str, version_read: int, data_read: Dict[str, str]) -> Dict[str, str]: + # return now if version is already up-to-date + if version_read >= 2: + return {} + + section = data_read.get("section") + option = data_read.get("option") + + # rename section "abc" to "def" + if section and not option and section == "abc": + data_read["section"] = "def" + return data_read + + # limit other changes to section "test" + if not section or not option or section != "test": + return {} + + # rename option "test1" to "test2" + if option == "test1": + data_read["option"] = "test2" + return data_read + + # set value to "xxx" for option "test" + if option == "test": + data_read["value"] = "xxx" + return data_read + + # set value to NULL for option "test_null" + if option == "test_null": + data_read["value_null"] = "1" + return data_read + + # no changes + return {} + +config_file = weechat.config_new("test", "", "") +weechat.config_set_version(config_file, 2, "my_config_update_cb", "") +weechat.config_read(config_file) +---- + ==== config_new_section _Updated in 1.5._ diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 021c9829c..6cbb2b480 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -6469,6 +6469,188 @@ def my_config_reload_cb(data: str, config_file: str) -> int: config_file = weechat.config_new("test", "my_config_reload_cb", "") ---- +==== config_set_version + +_WeeChat ≥ 3.9._ + +Définir la version du fichier de configuration et une fonction de rappel pour +la mise à jour des sections/options à la volée lorsque la configuration est lue. + +Prototype : + +[source,c] +---- +int config_file_set_version (struct t_config_file *config_file, + int version, + struct t_hashtable *(*callback_update)(const void *pointer, + void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read), + const void *callback_update_pointer, + void *callback_update_data); +---- + +Paramètres : + +* _config_file_ : pointeur vers le fichier de configuration +* _version_ : version, doit être ≥ 2 +* _callback_update_ : fonction appelée lorsque le fichier de configuration est + lu, pour chaque section et option, si la version lue est inférieure à la + version attendue (optionnelle, peut être NULL, voir ci-dessous), paramètres + et valeur de retour : +** _const void *pointer_ : pointeur +** _void *data_ : pointeur +** _struct t_config_file *config_file_ : pointeur vers le fichier de configuration +** _int version_read_ : version lue dans le fichier de configuration (1 par défaut) +** _struct t_hashtable *data_read_ : table de hachage avec les données lues du + fichier de configuration (voir ci-dessous) +** valeur de retour : +*** soit le pointeur vers la table de hachage "data_read" (avec la + table de hachage complétée), ou un pointeur vers une nouvelle table de + hachage (créée par la fonction de rappel, avec clés et valeurs de type + "string") +* _callback_update_pointer_: pointeur donné à la fonction de rappel lorsqu'elle + est appelée par WeeChat +* _callback_update_data_ : pointeur donné à la fonction de rappel lorsqu'elle est + appelée par WeeChat; si non NULL, doit avoir été alloué par malloc (ou une + fonction similaire) et est automatiquement libéré (par free) lorsque le + fichier de configuration est libéré + +Fonction de rappel de mise à jour : + +* La fonction de rappel reçoit une table de hachage avec les données lues du + fichier de configuration : + +[width="100%",cols="1m,2,8",options="header"] +|=== +| Clé | Disponibilité | Valeur +| config | Toujours définie | Nom du fichier de configuration sans l'extension (par exemple : `weechat`) +| section | Toujours définie | Nom de la section lue +| option | Pour une option seulement | Nom de l'option +| value | Pour une option seulement | Valeur de l'option (si non NULL) +| value_null | Pour une option seulement | L'option a une valeur NULL (la valeur est toujours `1`) +|=== + +* La fonction de rappel peut mettre à jour la "section" pour une ligne avec une + section et "option", "value" et "value_null" pour une ligne avec une option. +* Si "option" est changée en chaîne vide par la fonction de rappel, la ligne lue + dans le fichier de configuration est ignorée. +* Le champ "value_null" peut être positionné pour forcer une valeur NULL dans + l'option. + +Valeur de retour : + +* 1 si OK, 0 si erreur + +Exemple en C : + +[source,c] +---- +struct t_hashtable * +my_config_update_cb (const void *pointer, void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read) +{ + const char *ptr_section, *ptr_option; + + /* retourner maintenant si la version est déjà la dernière */ + if (version_read >= 2) + return NULL; + + ptr_section = hashtable_get (data_read, "section"); + ptr_option = hashtable_get (data_read, "option"); + + /* renommer la section "abc" en "def" */ + if (ptr_section && !ptr_option && (strcmp (ptr_section, "abc") == 0)) + { + hashtable_set (data_read, "section", "def"); + return data_read; + } + + /* limiter les autres changements à la section "test" */ + if (!ptr_section || !ptr_option || (strcmp (ptr_section, "test") != 0)) + return NULL; + + /* renommer l'option "test1" en "test2" */ + if (strcmp (ptr_option, "test1") == 0) + { + hashtable_set (data_read, "option", "test2"); + return data_read; + } + + /* définir la valeur à "xxx" pour l'option "test" */ + if (strcmp (ptr_option, "test") == 0) + { + hashtable_set (data_read, "value", "xxx"); + return data_read; + } + + /* définir la valeur à NULL pour l'option "test_null" */ + if (strcmp (ptr_option, "test_null") == 0) + { + hashtable_set (data_read, "value_null", "1"); + return data_read; + } + + /* aucun changement */ + return NULL; +} + +struct t_config_file *config_file = weechat_config_new ("test", NULL, NULL, NULL); +weechat_config_set_version (config_file, 2, &my_config_update_cb, NULL, NULL); +weechat_config_read (config_file); +---- + +Script (Python) : + +[source,python] +---- +# prototype +def config_set_version(config_file: str, version: int, callback_update: str, callback_update_data: str) -> int: ... + +# exemple +def my_config_update_cb(data: str, config_file: str, version_read: int, data_read: Dict[str, str]) -> Dict[str, str]: + # retourner maintenant si la version est déjà la dernière + if version_read >= 2: + return {} + + section = data_read.get("section") + option = data_read.get("option") + + # renommer la section "abc" en "def" + if section and not option and section == "abc": + data_read["section"] = "def" + return data_read + + # limiter les autres changements à la section "test" + if not section or not option or section != "test": + return {} + + # renommer l'option "test1" en "test2" + if option == "test1": + data_read["option"] = "test2" + return data_read + + # définir la valeur à "xxx" pour l'option "test" + if option == "test": + data_read["value"] = "xxx" + return data_read + + # définir la valeur à NULL pour l'option "test_null" + if option == "test_null": + data_read["value_null"] = "1" + return data_read + + # aucun changement + return {} + +config_file = weechat.config_new("test", "", "") +weechat.config_set_version(config_file, 2, "my_config_update_cb", "") +weechat.config_read(config_file) +---- + ==== config_new_section _Mis à jour dans la 1.5._ diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 24c4ba195..c8747797c 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -6638,6 +6638,183 @@ def my_config_reload_cb(data: str, config_file: str) -> int: config_file = weechat.config_new("test", "my_config_reload_cb", "") ---- +// TRANSLATION MISSING +==== config_set_version + +_WeeChat ≥ 3.9._ + +Set configuration file version and a callback to update config sections/options +on-the-fly when the config is read. + +Prototipo: + +[source,c] +---- +int config_file_set_version (struct t_config_file *config_file, + int version, + struct t_hashtable *(*callback_update)(const void *pointer, + void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read), + const void *callback_update_pointer, + void *callback_update_data); +---- + +Argomenti: + +* _config_file_: configuration file pointer +* _version_: version, must be ≥ 2 +* _callback_update_: function called when configuration file is read, for each + section and each option, if the version read is less than the expected version, + (optional, can be NULL, see below), arguments and return value: +** _const void *pointer_: pointer +** _void *data_: pointer +** _struct t_config_file *config_file_: configuration file pointer +** _int version_read_: version read in configuration file (1 by default) +** _struct t_hashtable *data_read_: hashtable with data read from configuration file + (see below) +** return value: +*** either "data_read" pointer (hashtable completed), or pointer to a new + hashtable (created by callback, with keys and values of type "string") +* _callback_update_pointer_: pointer given to callback when it is called by + WeeChat +* _callback_update_data_: pointer given to callback when it is called by + WeeChat; if not NULL, it must have been allocated with malloc (or similar + function) and it is automatically freed when the configuration file is freed + +Update callback: + +* The callback receives a hashtable with data read from configuration file: + +[width="100%",cols="1m,2,8",options="header"] +|=== +| Key | Availability | Value +| config | Always set | Name of configuration file, without extension (eg: `weechat`) +| section | Always set | Name of section being read +| option | For option only | Name of the option +| value | For option only | Value of the option (if not NULL) +| value_null | For option only | Option as NULL value (value is always `1`) +|=== + +* The callback can update "section" for a line with a section and "option", "value" + and "value_null" for a line with an option. +* If "option" is set to empty string by the callback, the line read in + configuration file is ignored. +* Field "value_null" is set to force a NULL value for the option. + +Valore restituito: + +* 1 if OK, 0 if error + +Esempio in C: + +[source,c] +---- +struct t_hashtable * +my_config_update_cb (const void *pointer, void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read) +{ + const char *ptr_section, *ptr_option; + + /* return now if version is already up-to-date */ + if (version_read >= 2) + return NULL; + + ptr_section = hashtable_get (data_read, "section"); + ptr_option = hashtable_get (data_read, "option"); + + /* rename section "abc" to "def" */ + if (ptr_section && !ptr_option && (strcmp (ptr_section, "abc") == 0)) + { + hashtable_set (data_read, "section", "def"); + return data_read; + } + + /* limit other changes to section "test" */ + if (!ptr_section || !ptr_option || (strcmp (ptr_section, "test") != 0)) + return NULL; + + /* rename option "test1" to "test2" */ + if (strcmp (ptr_option, "test1") == 0) + { + hashtable_set (data_read, "option", "test2"); + return data_read; + } + + /* set value to "xxx" for option "test" */ + if (strcmp (ptr_option, "test") == 0) + { + hashtable_set (data_read, "value", "xxx"); + return data_read; + } + + /* set value to NULL for option "test_null" */ + if (strcmp (ptr_option, "test_null") == 0) + { + hashtable_set (data_read, "value_null", "1"); + return data_read; + } + + /* no changes */ + return NULL; +} + +struct t_config_file *config_file = weechat_config_new ("test", NULL, NULL, NULL); +weechat_config_set_version (config_file, 2, &my_config_update_cb, NULL, NULL); +weechat_config_read (config_file); +---- + +Script (Python): + +[source,python] +---- +# prototipo +def config_set_version(config_file: str, version: int, callback_update: str, callback_update_data: str) -> int: ... + +# esempio +def my_config_update_cb(data: str, config_file: str, version_read: int, data_read: Dict[str, str]) -> Dict[str, str]: + # return now if version is already up-to-date + if version_read >= 2: + return {} + + section = data_read.get("section") + option = data_read.get("option") + + # rename section "abc" to "def" + if section and not option and section == "abc": + data_read["section"] = "def" + return data_read + + # limit other changes to section "test" + if not section or not option or section != "test": + return {} + + # rename option "test1" to "test2" + if option == "test1": + data_read["option"] = "test2" + return data_read + + # set value to "xxx" for option "test" + if option == "test": + data_read["value"] = "xxx" + return data_read + + # set value to NULL for option "test_null" + if option == "test_null": + data_read["value_null"] = "1" + return data_read + + # no changes + return {} + +config_file = weechat.config_new("test", "", "") +weechat.config_set_version(config_file, 2, "my_config_update_cb", "") +weechat.config_read(config_file) +---- + ==== config_new_section // TRANSLATION MISSING diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 52edf1b77..d66c9a1aa 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -6448,6 +6448,183 @@ def my_config_reload_cb(data: str, config_file: str) -> int: config_file = weechat.config_new("test", "my_config_reload_cb", "") ---- +// TRANSLATION MISSING +==== config_set_version + +_WeeChat ≥ 3.9._ + +Set configuration file version and a callback to update config sections/options +on-the-fly when the config is read. + +プロトタイプ: + +[source,c] +---- +int config_file_set_version (struct t_config_file *config_file, + int version, + struct t_hashtable *(*callback_update)(const void *pointer, + void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read), + const void *callback_update_pointer, + void *callback_update_data); +---- + +引数: + +* _config_file_: configuration file pointer +* _version_: version, must be ≥ 2 +* _callback_update_: function called when configuration file is read, for each + section and each option, if the version read is less than the expected version, + (optional, can be NULL, see below), arguments and return value: +** _const void *pointer_: pointer +** _void *data_: pointer +** _struct t_config_file *config_file_: configuration file pointer +** _int version_read_: version read in configuration file (1 by default) +** _struct t_hashtable *data_read_: hashtable with data read from configuration file + (see below) +** return value: +*** either "data_read" pointer (hashtable completed), or pointer to a new + hashtable (created by callback, with keys and values of type "string") +* _callback_update_pointer_: pointer given to callback when it is called by + WeeChat +* _callback_update_data_: pointer given to callback when it is called by + WeeChat; if not NULL, it must have been allocated with malloc (or similar + function) and it is automatically freed when the configuration file is freed + +Update callback: + +* The callback receives a hashtable with data read from configuration file: + +[width="100%",cols="1m,2,8",options="header"] +|=== +| Key | Availability | Value +| config | Always set | Name of configuration file, without extension (eg: `weechat`) +| section | Always set | Name of section being read +| option | For option only | Name of the option +| value | For option only | Value of the option (if not NULL) +| value_null | For option only | Option as NULL value (value is always `1`) +|=== + +* The callback can update "section" for a line with a section and "option", "value" + and "value_null" for a line with an option. +* If "option" is set to empty string by the callback, the line read in + configuration file is ignored. +* Field "value_null" is set to force a NULL value for the option. + +戻り値: + +* 1 if OK, 0 if error + +C 言語での使用例: + +[source,c] +---- +struct t_hashtable * +my_config_update_cb (const void *pointer, void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read) +{ + const char *ptr_section, *ptr_option; + + /* return now if version is already up-to-date */ + if (version_read >= 2) + return NULL; + + ptr_section = hashtable_get (data_read, "section"); + ptr_option = hashtable_get (data_read, "option"); + + /* rename section "abc" to "def" */ + if (ptr_section && !ptr_option && (strcmp (ptr_section, "abc") == 0)) + { + hashtable_set (data_read, "section", "def"); + return data_read; + } + + /* limit other changes to section "test" */ + if (!ptr_section || !ptr_option || (strcmp (ptr_section, "test") != 0)) + return NULL; + + /* rename option "test1" to "test2" */ + if (strcmp (ptr_option, "test1") == 0) + { + hashtable_set (data_read, "option", "test2"); + return data_read; + } + + /* set value to "xxx" for option "test" */ + if (strcmp (ptr_option, "test") == 0) + { + hashtable_set (data_read, "value", "xxx"); + return data_read; + } + + /* set value to NULL for option "test_null" */ + if (strcmp (ptr_option, "test_null") == 0) + { + hashtable_set (data_read, "value_null", "1"); + return data_read; + } + + /* no changes */ + return NULL; +} + +struct t_config_file *config_file = weechat_config_new ("test", NULL, NULL, NULL); +weechat_config_set_version (config_file, 2, &my_config_update_cb, NULL, NULL); +weechat_config_read (config_file); +---- + +スクリプト (Python) での使用例: + +[source,python] +---- +# プロトタイプ +def config_set_version(config_file: str, version: int, callback_update: str, callback_update_data: str) -> int: ... + +# 例 +def my_config_update_cb(data: str, config_file: str, version_read: int, data_read: Dict[str, str]) -> Dict[str, str]: + # return now if version is already up-to-date + if version_read >= 2: + return {} + + section = data_read.get("section") + option = data_read.get("option") + + # rename section "abc" to "def" + if section and not option and section == "abc": + data_read["section"] = "def" + return data_read + + # limit other changes to section "test" + if not section or not option or section != "test": + return {} + + # rename option "test1" to "test2" + if option == "test1": + data_read["option"] = "test2" + return data_read + + # set value to "xxx" for option "test" + if option == "test": + data_read["value"] = "xxx" + return data_read + + # set value to NULL for option "test_null" + if option == "test_null": + data_read["value_null"] = "1" + return data_read + + # no changes + return {} + +config_file = weechat.config_new("test", "", "") +weechat.config_set_version(config_file, 2, "my_config_update_cb", "") +weechat.config_read(config_file) +---- + ==== config_new_section _WeeChat バージョン 1.5 で更新。_ diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index e58e2d8d1..d77c22c69 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -6136,7 +6136,7 @@ struct t_config_file *weechat_config_new (const char *name, * _name_: име конфигурационог фајла (без путање или екстензије); приоритет је дозвољен испред имена, у формату `nnn|име` где је `nnn` цео позитиван број који представља приоритет; подразумевани приоритет је 1000; када се извршава - команда `/reload` фајлови се сортирају према приоритету, од вишег ка нижем + команда `/reload` фајлови се сортирају према приоритету, од вишег ка нижем (погледајте приоритет конфигурационих фајлова испод) * _callback_reload_: функција која се позива када се командом `/reload` поново учита конфигурациони фајл (није обавезна, може да буде NULL, погледајте испод), аргументи и повратна вредност су: ** _const void *pointer_: показивач @@ -6199,6 +6199,183 @@ def my_config_reload_cb(data: str, config_file: str) -> int: config_file = weechat.config_new("test", "my_config_reload_cb", "") ---- +// TRANSLATION MISSING +==== config_set_version + +_WeeChat ≥ 3.9._ + +Set configuration file version and a callback to update config sections/options +on-the-fly when the config is read. + +Прототип: + +[source,c] +---- +int config_file_set_version (struct t_config_file *config_file, + int version, + struct t_hashtable *(*callback_update)(const void *pointer, + void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read), + const void *callback_update_pointer, + void *callback_update_data); +---- + +Аргументи: + +* _config_file_: configuration file pointer +* _version_: version, must be ≥ 2 +* _callback_update_: function called when configuration file is read, for each + section and each option, if the version read is less than the expected version, + (optional, can be NULL, see below), arguments and return value: +** _const void *pointer_: pointer +** _void *data_: pointer +** _struct t_config_file *config_file_: configuration file pointer +** _int version_read_: version read in configuration file (1 by default) +** _struct t_hashtable *data_read_: hashtable with data read from configuration file + (see below) +** return value: +*** either "data_read" pointer (hashtable completed), or pointer to a new + hashtable (created by callback, with keys and values of type "string") +* _callback_update_pointer_: pointer given to callback when it is called by + WeeChat +* _callback_update_data_: pointer given to callback when it is called by + WeeChat; if not NULL, it must have been allocated with malloc (or similar + function) and it is automatically freed when the configuration file is freed + +Update callback: + +* The callback receives a hashtable with data read from configuration file: + +[width="100%",cols="1m,2,8",options="header"] +|=== +| Key | Availability | Value +| config | Always set | Name of configuration file, without extension (eg: `weechat`) +| section | Always set | Name of section being read +| option | For option only | Name of the option +| value | For option only | Value of the option (if not NULL) +| value_null | For option only | Option as NULL value (value is always `1`) +|=== + +* The callback can update "section" for a line with a section and "option", "value" + and "value_null" for a line with an option. +* If "option" is set to empty string by the callback, the line read in + configuration file is ignored. +* Field "value_null" is set to force a NULL value for the option. + +Повратна вредност: + +* 1 if OK, 0 if error + +C пример: + +[source,c] +---- +struct t_hashtable * +my_config_update_cb (const void *pointer, void *data, + struct t_config_file *config_file, + int version_read, + struct t_hashtable *data_read) +{ + const char *ptr_section, *ptr_option; + + /* return now if version is already up-to-date */ + if (version_read >= 2) + return NULL; + + ptr_section = hashtable_get (data_read, "section"); + ptr_option = hashtable_get (data_read, "option"); + + /* rename section "abc" to "def" */ + if (ptr_section && !ptr_option && (strcmp (ptr_section, "abc") == 0)) + { + hashtable_set (data_read, "section", "def"); + return data_read; + } + + /* limit other changes to section "test" */ + if (!ptr_section || !ptr_option || (strcmp (ptr_section, "test") != 0)) + return NULL; + + /* rename option "test1" to "test2" */ + if (strcmp (ptr_option, "test1") == 0) + { + hashtable_set (data_read, "option", "test2"); + return data_read; + } + + /* set value to "xxx" for option "test" */ + if (strcmp (ptr_option, "test") == 0) + { + hashtable_set (data_read, "value", "xxx"); + return data_read; + } + + /* set value to NULL for option "test_null" */ + if (strcmp (ptr_option, "test_null") == 0) + { + hashtable_set (data_read, "value_null", "1"); + return data_read; + } + + /* no changes */ + return NULL; +} + +struct t_config_file *config_file = weechat_config_new ("test", NULL, NULL, NULL); +weechat_config_set_version (config_file, 2, &my_config_update_cb, NULL, NULL); +weechat_config_read (config_file); +---- + +Script (Python): + +[source,python] +---- +# прототип +def config_set_version(config_file: str, version: int, callback_update: str, callback_update_data: str) -> int: ... + +# пример +def my_config_update_cb(data: str, config_file: str, version_read: int, data_read: Dict[str, str]) -> Dict[str, str]: + # return now if version is already up-to-date + if version_read >= 2: + return {} + + section = data_read.get("section") + option = data_read.get("option") + + # rename section "abc" to "def" + if section and not option and section == "abc": + data_read["section"] = "def" + return data_read + + # limit other changes to section "test" + if not section or not option or section != "test": + return {} + + # rename option "test1" to "test2" + if option == "test1": + data_read["option"] = "test2" + return data_read + + # set value to "xxx" for option "test" + if option == "test": + data_read["value"] = "xxx" + return data_read + + # set value to NULL for option "test_null" + if option == "test_null": + data_read["value_null"] = "1" + return data_read + + # no changes + return {} + +config_file = weechat.config_new("test", "", "") +weechat.config_set_version(config_file, 2, "my_config_update_cb", "") +weechat.config_read(config_file) +---- + ==== config_new_section _Ажурирано у верзији 1.5._ @@ -10993,7 +11170,7 @@ struct t_hook *weechat_hook_signal (const char *signal, | weechat | [[hook_signal_upgrade]] upgrade | | Стринг: „quit” ако је уз /upgrade наведен аргумент „-quit”, „save” - ако је уз /upgrade наведен аргумент „-save”, у супротном NULL. + ако је уз /upgrade наведен аргумент „-save”, у супротном NULL. | Корисник је задао команду `/upgrade`. | weechat | [[hook_signal_upgrade_ended]] upgrade_ended | 0.3.4 |