diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index a3b06c23e..89708624f 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -3822,6 +3822,347 @@ weechat.list_free(list) weechat.list_free(list) ---- +[[array_lists]] +=== Array lists + +Array list functions. + +An array list is a list of pointers with a dynamic size and optional sort. + +==== arraylist_new + +_WeeChat ≥ 1.8._ + +Create a new array list. + +Prototype: + +[source,C] +---- +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); +---- + +Arguments: + +* _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, 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 + +Return value: + +* pointer to new array list + +C example: + +[source,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] +This function is not available in scripting API. + +==== arraylist_size + +_WeeChat ≥ 1.8._ + +Return size of array list (number of item pointers). + +Prototype: + +[source,C] +---- +int weechat_list_size (struct t_arraylist *arraylist); +---- + +Arguments: + +* _arraylist_: array list pointer + +Return value: + +* size of array list (number of items), 0 if array list is empty + +C example: + +[source,C] +---- +weechat_printf (NULL, "size of array list: %d", weechat_arraylist_size (arraylist)); +---- + +[NOTE] +This function is not available in scripting API. + +==== arraylist_get + +_WeeChat ≥ 1.8._ + +Return an item pointer by position. + +Prototype: + +[source,C] +---- +void *weechat_arraylist_get (struct t_arraylist *arraylist, int index); +---- + +Arguments: + +* _arraylist_: array list pointer +* _index_: index in list (first pointer is 0) + +Return value: + +* pointer found, NULL if pointer was not found + +C example: + +[source,C] +---- +void *pointer = weechat_arraylist_get (arraylist, 0); /* first item */ +---- + +[NOTE] +This function is not available in scripting API. + +==== arraylist_search + +_WeeChat ≥ 1.8._ + +Search an item in an array list. + +Prototype: + +[source,C] +---- +void *weechat_arraylist_search (struct t_arraylist *arraylist, void *pointer, + int *index, int *index_insert); +---- + +Arguments: + +* _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) + +Return value: + +* pointer to item found, NULL if item was not found + +C example: + +[source,C] +---- +int index, index_insert; +void *item = weechat_arraylist_search (arraylist, pointer, &index, &index_insert); +---- + +[NOTE] +This function is not available in scripting API. + +==== arraylist_insert + +_WeeChat ≥ 1.8._ + +Insert an item in an array list. + +Prototype: + +[source,C] +---- +int weechat_arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer); +---- + +Arguments: + +* _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 + +Return value: + +* index of new item (>= 0), -1 if error. + +C example: + +[source,C] +---- +int index = weechat_arraylist_insert (arraylist, -1, pointer); /* insert at the end if not sorted */ +---- + +[NOTE] +This function is not available in scripting API. + +==== arraylist_add + +_WeeChat ≥ 1.8._ + +Add an item in an array list. + +Prototype: + +[source,C] +---- +int weechat_arraylist_add (struct t_arraylist *arraylist, void *pointer); +---- + +Arguments: + +* _arraylist_: array list pointer +* _pointer_: pointer to the item to add + +Return value: + +* index of new item (>= 0), -1 if error. + +C example: + +[source,C] +---- +int index = weechat_arraylist_add (arraylist, pointer); +---- + +[NOTE] +This function is not available in scripting API. + +==== arraylist_remove + +_WeeChat ≥ 1.8._ + +Remove an item from an array list. + +Prototype: + +[source,C] +---- +int weechat_arraylist_remove (struct t_arraylist *arraylist, int index); +---- + +Arguments: + +* _arraylist_: array list pointer +* _index_: index of the item to remove + +Return value: + +* index of item removed, -1 if error. + +C example: + +[source,C] +---- +int index_removed = weechat_arraylist_remove (arraylist, index); +---- + +[NOTE] +This function is not available in scripting API. + +==== arraylist_clear + +_WeeChat ≥ 1.8._ + +Remove all items from an array list. + +Prototype: + +[source,C] +---- +int weechat_arraylist_clear (struct t_arraylist *arraylist); +---- + +Arguments: + +* _arraylist_: array list pointer + +Return value: + +* 1 if OK, 0 if error + +C example: + +[source,C] +---- +if (weechat_arraylist_clear (arraylist)) +{ + /* OK */ +} +---- + +[NOTE] +This function is not available in scripting API. + +==== arraylist_free + +_WeeChat ≥ 1.8._ + +Free an array list. + +Prototype: + +[source,C] +---- +void weechat_arraylist_free (struct t_arraylist *arraylist); +---- + +Arguments: + +* _arraylist_: array list pointer + +C example: + +[source,C] +---- +weechat_arraylist_free (arraylist); +---- + +[NOTE] +This function is not available in scripting API. + [[hashtables]] === Hashtables diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index e97bacc02..930bc887f 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -3884,6 +3884,352 @@ weechat.list_free(list) weechat.list_free(list) ---- +[[array_lists]] +=== Listes avec tableau + +Fonctions pour les listes avec tableau. + +Une liste avec tableau est une liste de pointeurs avec une taille dynamique et un tri optionnel. + +==== arraylist_new + +_WeeChat ≥ 1.8._ + +Créer une nouvelle liste avec tableau. + +Prototype : + +[source,C] +---- +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); +---- + +Paramètres : + +* _initial_size_ : taille initiale de la liste avec tableau (ce n'est pas le nombre d'éléments) +* _sorted_ : 1 pour trier la liste avec tableau, 0 pour ne pas trier +* _allow_duplicates_ : 1 pour autoriser les entrées dupliquées, 0 pour empêcher + une même entrée d'être ajoutée à nouveau +* _callback_cmp_ : fonction appelée pour comparer deux éléments, paramètres et + valeur de retour : +** _void *data_ : pointeur +** _struct t_arraylist *arraylist_ : pointeur vers la liste avec tableau +** _void *pointer1_ : pointeur vers le premier élément +** _void *pointer2_ : pointeur vers le second élément +** valeur de retour : +*** nombre négatif si le premier élément est inférieur au second élément +*** 0 si le premier élément est égal au second élément +*** nombre positif si le premier élément est supérieur au second élément +* _callback_cmp_data_ : pointeur donné à la fonction de rappel lorsqu'elle est + appelée par WeeChat +* _callback_free_ : fonction utilisée pour libérer les éléments (optionnelle), + paramètres : +** _void *data_ : pointeur +** _struct t_arraylist *arraylist_ : pointeur vers la liste avec tableau +** _void *pointer_ : pointeur vers l'élément +* _callback_free_data_ : pointeur donné à la fonction de rappelle lorsqu'elle est + appelée par WeeChat + +Valeur de retour : + +* pointeur vers la nouvelle liste avec tableau + +Exemple en C : + +[source,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] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_size + +_WeeChat ≥ 1.8._ + +Retourner la taille de la liste (nombre de pointeurs vers des éléments). + +Prototype : + +[source,C] +---- +int weechat_list_size (struct t_arraylist *arraylist); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau + +Valeur de retour : + +* taille de la liste avec tableau (nombre d'éléments), 0 si la liste avec tableau est vide + +Exemple en C : + +[source,C] +---- +weechat_printf (NULL, "size of array list: %d", weechat_arraylist_size (arraylist)); +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_get + +_WeeChat ≥ 1.8._ + +Retourner un pointeur avec un élément par sa position. + +Prototype : + +[source,C] +---- +void *weechat_arraylist_get (struct t_arraylist *arraylist, int index); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau +* _index_ : index dans la liste (le premier pointeur est 0) + +Valeur de retour : + +* pointeur trouvé, NULL si le pointeur n'est pas trouvé + +Exemple en C : + +[source,C] +---- +void *pointer = weechat_arraylist_get (arraylist, 0); /* first item */ +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_search + +_WeeChat ≥ 1.8._ + +Chercher un élément dans une liste avec tableau. + +Prototype : + +[source,C] +---- +void *weechat_arraylist_search (struct t_arraylist *arraylist, void *pointer, + int *index, int *index_insert); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau +* _pointer_ : pointeur vers l'élément à chercher dans la liste avec tableau +* _index_ : pointeur vers un entier qui sera défini avec l'index trouvé, ou -1 si non trouvé + (optionnel) +* _index_insert_ : pointeur vers un entier qui sera défini avec l'index qui doit être utilisé + pour insérer un élément dans la liste avec tableau (pour garder la liste avec tableau triée) + (optionnel) + +Valeur de retour : + +* pointeur vers l'élément trouvé, NULL si l'élément n'est pas trouvé + +Exemple en C : + +[source,C] +---- +int index, index_insert; +void *item = weechat_arraylist_search (arraylist, pointer, &index, &index_insert); +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_insert + +_WeeChat ≥ 1.8._ + +Insérer un élément dans une liste avec tableau. + +Prototype : + +[source,C] +---- +int weechat_arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau +* _index_ : position de l'élément dans la liste avec tableau ou -1 pour ajouter + l'élément à la fin (ce paramètre est utilisé seulement si la liste avec tableau + n'est pas triée, il est ignoré si la liste avec tableau est triée) +* _pointeur_ : pointeur vers l'élément à insérer + +Valeur de retour : + +* index du nouvel élément (>= 0), -1 si erreur. + +Exemple en C : + +[source,C] +---- +int index = weechat_arraylist_insert (arraylist, -1, pointer); /* insert at the end if not sorted */ +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_add + +_WeeChat ≥ 1.8._ + +Ajouter un élément dans une liste avec tableau. + +Prototype : + +[source,C] +---- +int weechat_arraylist_add (struct t_arraylist *arraylist, void *pointer); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau +* _pointer_ : pointeur vers l'élément à ajouter + +Valeur de retour : + +* index du nouvel élément (>= 0), -1 si erreur. + +Exemple en C : + +[source,C] +---- +int index = weechat_arraylist_add (arraylist, pointer); +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_remove + +_WeeChat ≥ 1.8._ + +Supprimer un élément d'une liste avec tableau. + +Prototype : + +[source,C] +---- +int weechat_arraylist_remove (struct t_arraylist *arraylist, int index); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau +* _index_ : index de l'élément à supprimer + +Valeur de retour : + +* index de l'élément supprimé, -1 si erreur. + +Exemple en C : + +[source,C] +---- +int index_removed = weechat_arraylist_remove (arraylist, index); +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_clear + +_WeeChat ≥ 1.8._ + +Supprimer tous les éléments d'une liste avec tableau. + +Prototype : + +[source,C] +---- +int weechat_arraylist_clear (struct t_arraylist *arraylist); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau + +Valeur de retour : + +* 1 if OK, 0 if error + +Exemple en C : + +[source,C] +---- +if (weechat_arraylist_clear (arraylist)) +{ + /* OK */ +} +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + +==== arraylist_free + +_WeeChat ≥ 1.8._ + +Supprimer une liste avec tableau. + +Prototype : + +[source,C] +---- +void weechat_arraylist_free (struct t_arraylist *arraylist); +---- + +Paramètres : + +* _arraylist_ : pointeur vers la liste avec tableau + +Exemple en C : + +[source,C] +---- +weechat_arraylist_free (arraylist); +---- + +[NOTE] +Cette fonction n'est pas disponible dans l'API script. + [[hashtables]] === Tables de hachage diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 0b208b799..05d7ac51a 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -3950,6 +3950,374 @@ weechat.list_free(list) weechat.list_free(list) ---- +[[array_lists]] +=== Array lists + +// TRANSLATION MISSING +Array list functions. + +An array list is a list of pointers with a dynamic size and optional sort. + +==== arraylist_new + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Create a new array list. + +Prototipo: + +[source,C] +---- +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: + +// TRANSLATION MISSING +* _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, 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: + +// TRANSLATION MISSING +* pointer to new array list + +Esempio in C: + +[source,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. + +==== arraylist_size + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Return size of array list (number of item pointers). + +Prototipo: + +[source,C] +---- +int weechat_list_size (struct t_arraylist *arraylist); +---- + +Argomenti: + +// TRANSLATION MISSING +* _arraylist_: array list pointer + +Valore restituito: + +// TRANSLATION MISSING +* size of array list (number of items), 0 if array list is empty + +Esempio in C: + +[source,C] +---- +weechat_printf (NULL, "size of array list: %d", weechat_arraylist_size (arraylist)); +---- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + +==== arraylist_get + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Return an item pointer by position. + +Prototipo: + +[source,C] +---- +void *weechat_arraylist_get (struct t_arraylist *arraylist, int index); +---- + +Argomenti: + +// TRANSLATION MISSING +* _arraylist_: array list pointer +* _index_: index in list (first pointer is 0) + +Valore restituito: + +// TRANSLATION MISSING +* pointer found, NULL if pointer was not found + +Esempio in C: + +[source,C] +---- +void *pointer = weechat_arraylist_get (arraylist, 0); /* first item */ +---- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + +==== arraylist_search + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Search an item in an array list. + +Prototipo: + +[source,C] +---- +void *weechat_arraylist_search (struct t_arraylist *arraylist, void *pointer, + int *index, int *index_insert); +---- + +Argomenti: + +// TRANSLATION MISSING +* _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: + +// TRANSLATION MISSING +* pointer to item found, NULL if item was not found + +Esempio in C: + +[source,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. + +==== arraylist_insert + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Insert an item in an array list. + +Prototipo: + +[source,C] +---- +int weechat_arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer); +---- + +Argomenti: + +// TRANSLATION MISSING +* _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: + +// TRANSLATION MISSING +* index of new item (>= 0), -1 if error. + +Esempio in C: + +[source,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. + +==== arraylist_add + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Add an item in an array list. + +Prototipo: + +[source,C] +---- +int weechat_arraylist_add (struct t_arraylist *arraylist, void *pointer); +---- + +Argomenti: + +// TRANSLATION MISSING +* _arraylist_: array list pointer +* _pointer_: pointer to the item to add + +Valore restituito: + +// TRANSLATION MISSING +* index of new item (>= 0), -1 if error. + +Esempio in C: + +[source,C] +---- +int index = weechat_arraylist_add (arraylist, pointer); +---- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + +==== arraylist_remove + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Remove an item from an array list. + +Prototipo: + +[source,C] +---- +int weechat_arraylist_remove (struct t_arraylist *arraylist, int index); +---- + +Argomenti: + +// TRANSLATION MISSING +* _arraylist_: array list pointer +* _index_: index of the item to remove + +Valore restituito: + +// TRANSLATION MISSING +* index of item removed, -1 if error. + +Esempio in C: + +[source,C] +---- +int index_removed = weechat_arraylist_remove (arraylist, index); +---- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + +==== arraylist_clear + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Remove all items from an array list. + +Prototipo: + +[source,C] +---- +int weechat_arraylist_clear (struct t_arraylist *arraylist); +---- + +Argomenti: + +// TRANSLATION MISSING +* _arraylist_: array list pointer + +Valore restituito: + +// TRANSLATION MISSING +* 1 if OK, 0 if error + +Esempio in C: + +[source,C] +---- +if (weechat_arraylist_clear (arraylist)) +{ + /* OK */ +} +---- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + +==== arraylist_free + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Free an array list. + +Prototipo: + +[source,C] +---- +void weechat_arraylist_free (struct t_arraylist *arraylist); +---- + +Argomenti: + +// TRANSLATION MISSING +* _arraylist_: array list pointer + +Esempio in C: + +[source,C] +---- +weechat_arraylist_free (arraylist); +---- + +[NOTE] +Questa funzione non è disponibile nelle API per lo scripting. + [[hashtables]] === Tabelle hash @@ -16072,7 +16440,7 @@ weechat_hdata_set (hdata, pointer, "message", "test"); ---- [NOTE] -This function is not available in scripting API. +Questa funzione non è disponibile nelle API per lo scripting. // TRANSLATION MISSING ==== hdata_update diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 2746bc2c2..3b581ea8b 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -3843,6 +3843,374 @@ weechat.list_free(list) weechat.list_free(list) ---- +[[array_lists]] +=== Array lists + +// TRANSLATION MISSING +Array list functions. + +An array list is a list of pointers with a dynamic size and optional sort. + +==== arraylist_new + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Create a new array list. + +プロトタイプ: + +[source,C] +---- +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); +---- + +引数: + +// TRANSLATION MISSING +* _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, 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 + +戻り値: + +// TRANSLATION MISSING +* pointer to new array list + +C 言語での使用例: + +[source,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] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_size + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Return size of array list (number of item pointers). + +プロトタイプ: + +[source,C] +---- +int weechat_list_size (struct t_arraylist *arraylist); +---- + +引数: + +// TRANSLATION MISSING +* _arraylist_: array list pointer + +戻り値: + +// TRANSLATION MISSING +* size of array list (number of items), 0 if array list is empty + +C 言語での使用例: + +[source,C] +---- +weechat_printf (NULL, "size of array list: %d", weechat_arraylist_size (arraylist)); +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_get + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Return an item pointer by position. + +プロトタイプ: + +[source,C] +---- +void *weechat_arraylist_get (struct t_arraylist *arraylist, int index); +---- + +引数: + +// TRANSLATION MISSING +* _arraylist_: array list pointer +* _index_: index in list (first pointer is 0) + +戻り値: + +// TRANSLATION MISSING +* pointer found, NULL if pointer was not found + +C 言語での使用例: + +[source,C] +---- +void *pointer = weechat_arraylist_get (arraylist, 0); /* first item */ +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_search + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Search an item in an array list. + +プロトタイプ: + +[source,C] +---- +void *weechat_arraylist_search (struct t_arraylist *arraylist, void *pointer, + int *index, int *index_insert); +---- + +引数: + +// TRANSLATION MISSING +* _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) + +戻り値: + +// TRANSLATION MISSING +* pointer to item found, NULL if item was not found + +C 言語での使用例: + +[source,C] +---- +int index, index_insert; +void *item = weechat_arraylist_search (arraylist, pointer, &index, &index_insert); +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_insert + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Insert an item in an array list. + +プロトタイプ: + +[source,C] +---- +int weechat_arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer); +---- + +引数: + +// TRANSLATION MISSING +* _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 + +戻り値: + +// TRANSLATION MISSING +* index of new item (>= 0), -1 if error. + +C 言語での使用例: + +[source,C] +---- +int index = weechat_arraylist_insert (arraylist, -1, pointer); /* insert at the end if not sorted */ +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_add + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Add an item in an array list. + +プロトタイプ: + +[source,C] +---- +int weechat_arraylist_add (struct t_arraylist *arraylist, void *pointer); +---- + +引数: + +// TRANSLATION MISSING +* _arraylist_: array list pointer +* _pointer_: pointer to the item to add + +戻り値: + +// TRANSLATION MISSING +* index of new item (>= 0), -1 if error. + +C 言語での使用例: + +[source,C] +---- +int index = weechat_arraylist_add (arraylist, pointer); +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_remove + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Remove an item from an array list. + +プロトタイプ: + +[source,C] +---- +int weechat_arraylist_remove (struct t_arraylist *arraylist, int index); +---- + +引数: + +// TRANSLATION MISSING +* _arraylist_: array list pointer +* _index_: index of the item to remove + +戻り値: + +// TRANSLATION MISSING +* index of item removed, -1 if error. + +C 言語での使用例: + +[source,C] +---- +int index_removed = weechat_arraylist_remove (arraylist, index); +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_clear + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Remove all items from an array list. + +プロトタイプ: + +[source,C] +---- +int weechat_arraylist_clear (struct t_arraylist *arraylist); +---- + +引数: + +// TRANSLATION MISSING +* _arraylist_: array list pointer + +戻り値: + +// TRANSLATION MISSING +* 1 if OK, 0 if error + +C 言語での使用例: + +[source,C] +---- +if (weechat_arraylist_clear (arraylist)) +{ + /* OK */ +} +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + +==== arraylist_free + +_WeeChat ≥ 1.8._ + +// TRANSLATION MISSING +Free an array list. + +プロトタイプ: + +[source,C] +---- +void weechat_arraylist_free (struct t_arraylist *arraylist); +---- + +引数: + +// TRANSLATION MISSING +* _arraylist_: array list pointer + +C 言語での使用例: + +[source,C] +---- +weechat_arraylist_free (arraylist); +---- + +[NOTE] +スクリプト API ではこの関数を利用できません。 + [[hashtables]] === ハッシュテーブル @@ -9477,7 +9845,7 @@ struct t_hook *weechat_hook_hsignal (const char *signal, void *callback_data); ---- -Arguments: +引数: * _signal_: キャッチするシグナル、ワイルドカード `+*+` を使うことができます (優先度の設定が可能、<>に関する注意を参照) diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index c89ca6614..326df8edf 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -689,6 +689,16 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->list_remove_all = &weelist_remove_all; new_plugin->list_free = &weelist_free; + new_plugin->arraylist_new = arraylist_new; + new_plugin->arraylist_size = arraylist_size; + new_plugin->arraylist_get = arraylist_get; + new_plugin->arraylist_search = arraylist_search; + new_plugin->arraylist_insert = arraylist_insert; + new_plugin->arraylist_add = arraylist_add; + new_plugin->arraylist_remove = arraylist_remove; + new_plugin->arraylist_clear = arraylist_clear; + new_plugin->arraylist_free = arraylist_free; + new_plugin->hashtable_new = &hashtable_new; new_plugin->hashtable_set_with_size = &hashtable_set_with_size; new_plugin->hashtable_set = &hashtable_set; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 3d7fc2e1b..4858b810b 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -44,6 +44,7 @@ struct t_gui_completion; struct t_infolist; struct t_infolist_item; struct t_weelist; +struct t_arraylist; struct t_hashtable; struct t_hdata; struct timeval; @@ -58,7 +59,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20170303-01" +#define WEECHAT_PLUGIN_API_VERSION "20170312-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -391,6 +392,30 @@ struct t_weechat_plugin void (*list_remove_all) (struct t_weelist *weelist); void (*list_free) (struct t_weelist *weelist); + /* array lists */ + struct t_arraylist *(*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); + int (*arraylist_size) (struct t_arraylist *arraylist); + void *(*arraylist_get) (struct t_arraylist *arraylist, int index); + void *(*arraylist_search) (struct t_arraylist *arraylist, void *pointer, + int *index, int *index_insert); + int (*arraylist_insert) (struct t_arraylist *arraylist, int index, + void *pointer); + int (*arraylist_add) (struct t_arraylist *arraylist, void *pointer); + int (*arraylist_remove) (struct t_arraylist *arraylist, int index); + int (*arraylist_clear) (struct t_arraylist *arraylist); + void (*arraylist_free) (struct t_arraylist *arraylist); + /* hash tables */ struct t_hashtable *(*hashtable_new) (int size, const char *type_keys, @@ -1292,6 +1317,34 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_list_free(__list) \ (weechat_plugin->list_free)(__list) +/* array lists */ +#define weechat_arraylist_new(__initial_size, __sorted, \ + __allow_duplicates, __callback_cmp, \ + __callback_cmp_data, __callback_free, \ + __callback_free_data) \ + (weechat_plugin->arraylist_new)(__initial_size, __sorted, \ + __allow_duplicates, __callback_cmp, \ + __callback_cmp_data, __callback_free, \ + __callback_free_data) +#define weechat_arraylist_size(__arraylist) \ + (weechat_plugin->arraylist_size)(__arraylist) +#define weechat_arraylist_get(__arraylist, __index) \ + (weechat_plugin->arraylist_get)(__arraylist, __index) +#define weechat_arraylist_search(__arraylist, __pointer, __index, \ + __index_insert) \ + (weechat_plugin->arraylist_search)(__arraylist, __pointer, __index, \ + __index_insert) +#define weechat_arraylist_insert(__arraylist, __index, __pointer) \ + (weechat_plugin->arraylist_insert)(__arraylist, __index, __pointer) +#define weechat_arraylist_add(__arraylist, __pointer) \ + (weechat_plugin->arraylist_add)(__arraylist, __pointer) +#define weechat_arraylist_remove(__arraylist, __index) \ + (weechat_plugin->arraylist_remove)(__arraylist, __index) +#define weechat_arraylist_clear(__arraylist) \ + (weechat_plugin->arraylist_clear)(__arraylist) +#define weechat_arraylist_free(__arraylist) \ + (weechat_plugin->arraylist_free)(__arraylist) + /* hash tables */ #define weechat_hashtable_new(__size, __type_keys, __type_values, \ __callback_hash_key, __callback_keycmp) \