Add option aspell.check.real_time (off by default), fix bugs with aspell and utf-8 chars, add function utf8_char_int to API

This commit is contained in:
Sebastien Helleu 2009-03-22 16:38:06 +01:00
parent 558c9f2614
commit 7c793257ff
29 changed files with 287 additions and 127 deletions

View File

@ -36,6 +36,16 @@
</listitem>
</itemizedlist>
<command>aspell.check.real_time</command>: real-time spell checking of words (slower, disabled by default: words are checked only if there's delimiter after)
<itemizedlist>
<listitem>
<para>type: boolean</para>
</listitem>
<listitem>
<para>values: on, off (default value: off)</para>
</listitem>
</itemizedlist>
<command>aspell.check.word_min_length</command>: minimum length for a word to be spell checked (use 0 to check all words)
<itemizedlist>
<listitem>

View File

@ -362,7 +362,7 @@ den Server dazu bringen, seine Konfigurationsdatei neu zu laden
den Server dazu bringen, sich selbst neu zu starten
</programlisting>
<command>/server [list [servername]] | [listfull [servername]] | [add servername hostname[/port] [-auto | -noauto] [-ipv6] [-ssl]] | [copy servername newservername] | [rename servername newservername] | [keep servername] | [del servername] | [deloutq] | [switch]</command>
<command>/server [list [servername]] | [listfull [servername]] | [add servername hostname[/port] [-auto | -noauto] [-ipv6] [-ssl]] | [copy servername newservername] | [rename servername newservername] | [keep servername] | [del servername] | [deloutq] | [raw] | [switch]</command>
<programlisting>
list, add or remove IRC servers
@ -380,6 +380,7 @@ servername: server name, for internal and display use
keep: keep server in config file (for temporary servers only)
del: delete a server
deloutq: delete messages out queue for all servers (all messages WeeChat is currently sending)
raw: open buffer with raw IRC data
switch: switch active server (when one buffer is used for all servers, default key: alt-s on server buffer)
Examples:

View File

@ -166,6 +166,16 @@
</listitem>
</itemizedlist>
<command>irc.look.raw_messages</command>: number of IRC raw messages to save in memory when raw data buffer is closed (messages will be displayed when opening raw data buffer)
<itemizedlist>
<listitem>
<para>type: integer</para>
</listitem>
<listitem>
<para>values: 0 .. 65535 (default value: 256)</para>
</listitem>
</itemizedlist>
<command>irc.look.show_away_once</command>: in privaten Unterhaltungen nur einmalig eine Abwesenheitsnachricht anzeigen
<itemizedlist>
<listitem>

View File

@ -281,7 +281,14 @@ This command run again a WeeChat binary, so it should have been compiled or inst
<programlisting>
zeigt die Uptime von Weechat an
-o: sendet die Weechat-Uptime als IRC-Nachricht in den aktuellen Channel
-o: send uptime to current buffer as input
</programlisting>
<command>/version [-o]</command>
<programlisting>
show WeeChat version and compilation date
-o: send version to current buffer as input
</programlisting>
<command>/window [list | -1 | +1 | b# | up | down | left | right | splith [pct] | splitv [pct] | resize pct | merge [all] | page_up | page_down | refresh | scroll | scroll_up | scroll_down | scroll_top | scroll_bottom | scroll_previous_highlight | scroll_next_highlight | zoom]</command>

View File

@ -36,6 +36,16 @@
</listitem>
</itemizedlist>
<command>aspell.check.real_time</command>: real-time spell checking of words (slower, disabled by default: words are checked only if there's delimiter after)
<itemizedlist>
<listitem>
<para>type: boolean</para>
</listitem>
<listitem>
<para>values: on, off (default value: off)</para>
</listitem>
</itemizedlist>
<command>aspell.check.word_min_length</command>: minimum length for a word to be spell checked (use 0 to check all words)
<itemizedlist>
<listitem>

View File

@ -362,7 +362,7 @@ tell the server to reload its config file
tell the server to restart itself
</programlisting>
<command>/server [list [servername]] | [listfull [servername]] | [add servername hostname[/port] [-auto | -noauto] [-ipv6] [-ssl]] | [copy servername newservername] | [rename servername newservername] | [keep servername] | [del servername] | [deloutq] | [switch]</command>
<command>/server [list [servername]] | [listfull [servername]] | [add servername hostname[/port] [-auto | -noauto] [-ipv6] [-ssl]] | [copy servername newservername] | [rename servername newservername] | [keep servername] | [del servername] | [deloutq] | [raw] | [switch]</command>
<programlisting>
list, add or remove IRC servers
@ -380,6 +380,7 @@ servername: server name, for internal and display use
keep: keep server in config file (for temporary servers only)
del: delete a server
deloutq: delete messages out queue for all servers (all messages WeeChat is currently sending)
raw: open buffer with raw IRC data
switch: switch active server (when one buffer is used for all servers, default key: alt-s on server buffer)
Examples:

View File

@ -166,6 +166,16 @@
</listitem>
</itemizedlist>
<command>irc.look.raw_messages</command>: number of IRC raw messages to save in memory when raw data buffer is closed (messages will be displayed when opening raw data buffer)
<itemizedlist>
<listitem>
<para>type: integer</para>
</listitem>
<listitem>
<para>values: 0 .. 65535 (default value: 256)</para>
</listitem>
</itemizedlist>
<command>irc.look.show_away_once</command>: show remote away message only once in private
<itemizedlist>
<listitem>

View File

@ -281,7 +281,14 @@ This command run again a WeeChat binary, so it should have been compiled or inst
<programlisting>
show WeeChat uptime
-o: send uptime on current channel as an IRC message
-o: send uptime to current buffer as input
</programlisting>
<command>/version [-o]</command>
<programlisting>
show WeeChat version and compilation date
-o: send version to current buffer as input
</programlisting>
<command>/window [list | -1 | +1 | b# | up | down | left | right | splith [pct] | splitv [pct] | resize pct | merge [all] | page_up | page_down | refresh | scroll | scroll_up | scroll_down | scroll_top | scroll_bottom | scroll_previous_highlight | scroll_next_highlight | zoom]</command>

View File

@ -36,6 +36,16 @@
</listitem>
</itemizedlist>
<command>aspell.check.real_time</command>: vérification orthographique des mots en temps réel (plus lent, désactivé par défaut: les mots sont vérifiés seulement s'il y a un délimiteur après)
<itemizedlist>
<listitem>
<para>type: booléen</para>
</listitem>
<listitem>
<para>valeurs: on, off (valeur par défaut: off)</para>
</listitem>
</itemizedlist>
<command>aspell.check.word_min_length</command>: longueur minimum d'un mot pour que l'otrhographe soit vérifiée (utilisez 0 pour vérifier tous les mots)
<itemizedlist>
<listitem>

View File

@ -362,7 +362,7 @@ demander au serveur de recharger son fichier de configuration
demander au serveur de redémarrer
</programlisting>
<command>/server [list [nom_serveur]] | [listfull [nom_serveur]] | [add nom_serveur nom[/port] [-temp] [-auto | -noauto] [-ipv6] [-ssl]] | [copy nom_serveur nouveau_nom_serveur] | [rename nom_serveur nouveau_nom_serveur] | [keep nom_serveur] | [del nom_serveur] | [deloutq] | [switch]</command>
<command>/server [list [nom_serveur]] | [listfull [nom_serveur]] | [add nom_serveur nom[/port] [-temp] [-auto | -noauto] [-ipv6] [-ssl]] | [copy nom_serveur nouveau_nom_serveur] | [rename nom_serveur nouveau_nom_serveur] | [keep nom_serveur] | [del nom_serveur] | [deloutq] | [raw] | [switch]</command>
<programlisting>
liste, ajoute ou retire des serveurs IRC
@ -380,6 +380,7 @@ nom_serveur: nom du serveur, pour usage interne et affichage
keep: garder le serveur dans le fichier de configuration (pour les serveurs temporaires seulement)
del: supprimer un serveur
deloutq: supprimer la file d'attente des messages sortants pour tous les serveurs (tous les messages que WeeChat est actuellement en train d'envoyer)
raw: ouvre le tampon avec les données brutes IRC
switch: changer le serveur actif (quand un tampon est utilisé pour tous les serveurs, touche par défaut: alt-s sur le tampon serveur)
Exemples :

View File

@ -166,6 +166,16 @@
</listitem>
</itemizedlist>
<command>irc.look.raw_messages</command>: nombre de messages IRC bruts à sauvegarder en mémoire lorsque le tampon des données brutes est fermé (ces messages seront affichés lors de l'ouverture du tampon des données brutes)
<itemizedlist>
<listitem>
<para>type: entier</para>
</listitem>
<listitem>
<para>valeurs: 0 .. 65535 (valeur par défaut: 256)</para>
</listitem>
</itemizedlist>
<command>irc.look.show_away_once</command>: voir le message d'absence distant une seule fois en privé
<itemizedlist>
<listitem>

View File

@ -280,7 +280,14 @@ Cette commande lance à nouveau un binaire WeeChat, il doit donc avoir été com
<programlisting>
montrer l'uptime de WeeChat
-o: envoyer l'uptime sur le canal courant en tant que message IRC
-o: envoyer l'uptime sur le tampon courant comme entrée
</programlisting>
<command>/version [-o]</command>
<programlisting>
afficher la version de WeeChat et la date de compilation
-o: envoyer la version sur le tampon courant comme entrée
</programlisting>
<command>/window [list | -1 | +1 | b# | up | down | left | right | splith [pct] | splitv [ptc] | resize pct | merge [all] | page_up | page_down | refresh | scroll | scroll_up | scroll_down | scroll_top | scroll_bottom | scroll_previous_highlight | scroll_next_highlight | zoom]</command>

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-03-21 15:56+0100\n"
"POT-Creation-Date: 2009-03-22 16:17+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2181,11 +2181,16 @@ msgid ""
"for which you didn't explicitely enabled it)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgid "check words during text search in buffer"
msgstr ""
msgid "check words during text search in buffer"
msgid ""
"real-time spell checking of words (slower, disabled by default: words are "
"checked only if there's delimiter after)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgstr ""
#, c-format

View File

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-03-21 15:56+0100\n"
"POT-Creation-Date: 2009-03-22 16:17+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Thomas Schuetz <i18n@internet-villa.de>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2192,11 +2192,16 @@ msgid ""
"for which you didn't explicitely enabled it)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgid "check words during text search in buffer"
msgstr ""
msgid "check words during text search in buffer"
msgid ""
"real-time spell checking of words (slower, disabled by default: words are "
"checked only if there's delimiter after)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgstr ""
#, c-format

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-03-21 15:56+0100\n"
"POT-Creation-Date: 2009-03-22 16:17+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Roberto González Cardenete <robert.glez@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2165,11 +2165,16 @@ msgid ""
"for which you didn't explicitely enabled it)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgid "check words during text search in buffer"
msgstr ""
msgid "check words during text search in buffer"
msgid ""
"real-time spell checking of words (slower, disabled by default: words are "
"checked only if there's delimiter after)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgstr ""
#, c-format

View File

@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-03-21 15:56+0100\n"
"PO-Revision-Date: 2009-03-21 15:57+0100\n"
"POT-Creation-Date: 2009-03-22 16:17+0100\n"
"PO-Revision-Date: 2009-03-22 16:17+0100\n"
"Last-Translator: FlashCode <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"MIME-Version: 1.0\n"
@ -2284,15 +2284,22 @@ msgstr ""
"blanc pour désactiver aspell sur les tampons pour lesquels vous ne l'avez "
"pas explicitement activé)"
msgid "check words during text search in buffer"
msgstr "vérifier les mots pendant la recherche de texte dans le tampon"
msgid ""
"real-time spell checking of words (slower, disabled by default: words are "
"checked only if there's delimiter after)"
msgstr ""
"vérification orthographique des mots en temps réel (plus lent, désactivé par "
"défaut: les mots sont vérifiés seulement s'il y a un délimiteur après)"
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgstr ""
"longueur minimum d'un mot pour que l'otrhographe soit vérifiée (utilisez 0 "
"pour vérifier tous les mots)"
msgid "check words during text search in buffer"
msgstr "vérifier les mots pendant la recherche de texte dans le tampon"
#, c-format
msgid "%s: warning: dictionary \"%s\" is not available on your system"
msgstr ""

View File

@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-03-21 15:56+0100\n"
"POT-Creation-Date: 2009-03-22 16:17+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2201,11 +2201,16 @@ msgid ""
"for which you didn't explicitely enabled it)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgid "check words during text search in buffer"
msgstr ""
msgid "check words during text search in buffer"
msgid ""
"real-time spell checking of words (slower, disabled by default: words are "
"checked only if there's delimiter after)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgstr ""
#, c-format

View File

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.2.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-03-21 15:56+0100\n"
"POT-Creation-Date: 2009-03-22 16:17+0100\n"
"PO-Revision-Date: 2009-01-03 00:42+0100\n"
"Last-Translator: Pavel Shevchuk <stlwrt@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@ -2205,11 +2205,16 @@ msgid ""
"for which you didn't explicitely enabled it)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgid "check words during text search in buffer"
msgstr ""
msgid "check words during text search in buffer"
msgid ""
"real-time spell checking of words (slower, disabled by default: words are "
"checked only if there's delimiter after)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgstr ""
#, c-format

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-03-21 15:56+0100\n"
"POT-Creation-Date: 2009-03-22 16:17+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1877,11 +1877,16 @@ msgid ""
"for which you didn't explicitely enabled it)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgid "check words during text search in buffer"
msgstr ""
msgid "check words during text search in buffer"
msgid ""
"real-time spell checking of words (slower, disabled by default: words are "
"checked only if there's delimiter after)"
msgstr ""
msgid ""
"minimum length for a word to be spell checked (use 0 to check all words)"
msgstr ""
#, c-format

View File

@ -225,6 +225,61 @@ utf8_next_char (const char *string)
return (char *)string + 1;
}
/*
* utf8_char_int: return UTF-8 char as integer
*/
int
utf8_char_int (const char *string)
{
const unsigned char *ptr_string;
if (!string)
return 0;
ptr_string = (unsigned char *)string;
/* UTF-8, 2 bytes: 110vvvvv 10vvvvvv */
if ((ptr_string[0] & 0xE0) == 0xC0)
{
if (!ptr_string[1])
return (int)(ptr_string[0] & 0x1F);
return ((int)(ptr_string[0] & 0x1F) << 6) +
((int)(ptr_string[1] & 0x3F));
}
/* UTF-8, 3 bytes: 1110vvvv 10vvvvvv 10vvvvvv */
else if ((ptr_string[0] & 0xF0) == 0xE0)
{
if (!ptr_string[1])
return (int)(ptr_string[0] & 0x0F);
if (!ptr_string[2])
return (((int)(ptr_string[0] & 0x0F)) << 6) +
((int)(ptr_string[1] & 0x3F));
return (((int)(ptr_string[0] & 0x0F)) << 12) +
(((int)(ptr_string[1] & 0x3F)) << 6) +
((int)(ptr_string[2] & 0x3F));
}
/* UTF-8, 4 bytes: 11110vvv 10vvvvvv 10vvvvvv 10vvvvvv */
else if ((ptr_string[0] & 0xF8) == 0xF0)
{
if (!ptr_string[1])
return (int)ptr_string[0] & 0x07;
if (!ptr_string[2])
return (((int)(ptr_string[0] & 0x07)) << 6) +
((int)(ptr_string[1] & 0x3F));
if (!ptr_string[3])
return (((int)(ptr_string[0] & 0x07)) << 12) +
(((int)(ptr_string[1] & 0x3F)) << 6) +
((int)(ptr_string[2] & 0x3F));
return (((int)(ptr_string[0] & 0x07)) << 18) +
(((int)(ptr_string[1] & 0x3F)) << 12) +
(((int)(ptr_string[2] & 0x3F)) << 6) +
((int)(ptr_string[3] & 0x3F));
}
/* UTF-8, 1 byte: 0vvvvvvv */
return (int)ptr_string[0];
}
/*
* utf8_char_size: return UTF-8 char size (in bytes)
*/

View File

@ -38,6 +38,7 @@ extern int utf8_is_valid (const char *string, char **error);
extern void utf8_normalize (const char *string, char replacement);
extern char *utf8_prev_char (const char *string_start, const char *string);
extern char *utf8_next_char (const char *string);
extern int utf8_char_int (const char *string);
extern int utf8_char_size (const char *string);
extern int utf8_strlen (const char *string);
extern int utf8_strnlen (const char *string, int bytes);

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* aspell-config.c: aspell configuration options */
/* weechat-aspell-config.c: aspell configuration options */
#include <stdlib.h>
@ -40,8 +40,9 @@ struct t_config_option *weechat_aspell_config_look_color;
struct t_config_option *weechat_aspell_config_check_commands;
struct t_config_option *weechat_aspell_config_check_default_dict;
struct t_config_option *weechat_aspell_config_check_word_min_length;
struct t_config_option *weechat_aspell_config_check_during_search;
struct t_config_option *weechat_aspell_config_check_real_time;
struct t_config_option *weechat_aspell_config_check_word_min_length;
char **weechat_aspell_commands_to_check = NULL;
@ -304,17 +305,23 @@ weechat_aspell_config_init ()
"aspell on buffers for which you didn't explicitely enabled it)"),
NULL, 0, 0, "", NULL, 0,
NULL, NULL, &weechat_aspell_config_change_default_dict, NULL, NULL, NULL);
weechat_aspell_config_check_during_search = weechat_config_new_option (
weechat_aspell_config_file, ptr_section,
"during_search", "boolean",
N_("check words during text search in buffer"),
NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
weechat_aspell_config_check_real_time = weechat_config_new_option (
weechat_aspell_config_file, ptr_section,
"real_time", "boolean",
N_("real-time spell checking of words (slower, disabled by default: "
"words are checked only if there's delimiter after)"),
NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
weechat_aspell_config_check_word_min_length = weechat_config_new_option (
weechat_aspell_config_file, ptr_section,
"word_min_length", "integer",
N_("minimum length for a word to be spell checked (use 0 to check all "
"words)"),
NULL, 0, INT_MAX, "2", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
weechat_aspell_config_check_during_search = weechat_config_new_option (
weechat_aspell_config_file, ptr_section,
"during_search", "boolean",
N_("check words during text search in buffer"),
NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
/* dict */
ptr_section = weechat_config_new_section (weechat_aspell_config_file, "dict",

View File

@ -27,8 +27,9 @@ extern struct t_config_option *weechat_aspell_config_look_color;
extern struct t_config_option *weechat_aspell_config_check_commands;
extern struct t_config_option *weechat_aspell_config_check_default_dict;
extern struct t_config_option *weechat_aspell_config_check_word_min_length;
extern struct t_config_option *weechat_aspell_config_check_during_search;
extern struct t_config_option *weechat_aspell_config_check_real_time;
extern struct t_config_option *weechat_aspell_config_check_word_min_length;
extern char **weechat_aspell_commands_to_check;
extern int weechat_aspell_count_commands_to_check;
@ -41,4 +42,4 @@ extern int weechat_aspell_config_read ();
extern int weechat_aspell_config_write ();
extern void weechat_aspell_config_free ();
#endif /* aspell-config.h */
#endif /* weechat-aspell-config.h */

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* aspell-speller.c: speller management for aspell plugin */
/* weechat-aspell-speller.c: speller management for aspell plugin */
#include <stdlib.h>

View File

@ -38,4 +38,4 @@ extern struct t_aspell_speller *weechat_aspell_speller_new (const char *lang);
extern void weechat_aspell_speller_free (struct t_aspell_speller *speller);
extern void weechat_aspell_speller_free_all ();
#endif /* aspell-speller.h */
#endif /* weechat-aspell-speller.h */

View File

@ -16,14 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* aspell.c: aspell plugin for WeeChat */
/* weechat-aspell.c: aspell plugin for WeeChat */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <ctype.h>
#include <wctype.h>
#include "../weechat-plugin.h"
#include "weechat-aspell.h"
@ -550,45 +550,6 @@ weechat_aspell_command_authorized (const char *command)
return 0;
}
/*
* weechat_aspell_string_strip_punctuation: strip punctuation chars at the
* begining and at the end of a word
*/
char *
weechat_aspell_string_strip_punctuation (const char *word)
{
const char *ptr_start, *ptr_end;
if (!word)
return NULL;
ptr_start = word;
while (ptr_start[0])
{
if (!ispunct (ptr_start[0]))
break;
ptr_start++;
}
if (!ptr_start[0])
return strdup ("");
ptr_end = ptr_start + strlen (ptr_start) - 1;
while (ptr_end >= ptr_start)
{
if (!ispunct (ptr_end[0]))
break;
ptr_end--;
}
if (ptr_end < ptr_start)
return strdup ("");
return weechat_strndup (ptr_start, ptr_end - ptr_start + 1);
}
/*
* weechat_aspell_string_is_url: detect if a word is an url
*/
@ -629,17 +590,17 @@ weechat_aspell_string_is_url (const char *word)
int
weechat_aspell_string_is_simili_number (const char *word)
{
const char *ptr_word;
int utf8_char_int;
if (!word)
if (!word || !word[0])
return 0;
ptr_word = word;
while (ptr_word[0])
while (word && word[0])
{
if (!ispunct (ptr_word[0]) && !isdigit (ptr_word[0]))
utf8_char_int = weechat_utf8_char_int (word);
if (!iswpunct (utf8_char_int) && !iswdigit (utf8_char_int))
return 0;
ptr_word++;
word = weechat_utf8_next_char (word);
}
/* there's only digit or punctuation */
@ -654,35 +615,29 @@ weechat_aspell_string_is_simili_number (const char *word)
int
weechat_aspell_check_word (struct t_gui_buffer *buffer, const char *word)
{
char *clean_word;
struct t_aspell_speller *ptr_speller;
int rc;
clean_word = weechat_aspell_string_strip_punctuation (word);
if (!clean_word)
return 1;
rc = 0;
/* word too small? then do not check word */
if ((weechat_config_integer (weechat_aspell_config_check_word_min_length) > 0)
&& ((int)strlen (clean_word) < weechat_config_integer (weechat_aspell_config_check_word_min_length)))
&& ((int)strlen (word) < weechat_config_integer (weechat_aspell_config_check_word_min_length)))
rc = 1;
else
{
/* word is URL? then do not check word */
if (weechat_aspell_string_is_url (clean_word))
if (weechat_aspell_string_is_url (word))
rc = 1;
else
{
/* word is a number? then do not check word */
if (weechat_aspell_string_is_simili_number (clean_word))
if (weechat_aspell_string_is_simili_number (word))
rc = 1;
else
{
/* word is a nick of nicklist on this buffer? then do not check word */
if (weechat_nicklist_search_nick (buffer, NULL, clean_word))
if (weechat_nicklist_search_nick (buffer, NULL, word))
rc = 1;
else
{
@ -690,7 +645,7 @@ weechat_aspell_check_word (struct t_gui_buffer *buffer, const char *word)
for (ptr_speller = weechat_aspell_spellers; ptr_speller;
ptr_speller = ptr_speller->next_speller)
{
if (aspell_speller_check (ptr_speller->speller, clean_word, -1) == 1)
if (aspell_speller_check (ptr_speller->speller, word, -1) == 1)
{
rc = 1;
break;
@ -701,8 +656,6 @@ weechat_aspell_check_word (struct t_gui_buffer *buffer, const char *word)
}
}
free (clean_word);
return rc;
}
@ -716,8 +669,9 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
{
long unsigned int value;
struct t_gui_buffer *buffer;
char *result, *ptr_string, *pos_space;
char *result, *ptr_string, *pos_space, *ptr_end, save_end;
const char *color_normal, *color_error;
int utf8_char_int, char_size;
int length, index_result, length_word, word_ok;
int length_color_normal, length_color_error;
@ -784,13 +738,17 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
&& (ptr_string[1] != ' '))
{
ptr_string++;
pos_space = strchr (ptr_string, ' ');
if (!pos_space)
pos_space = ptr_string;
while (pos_space && pos_space[0] && (pos_space[0] != ' '))
{
pos_space = weechat_utf8_next_char (pos_space);
}
if (!pos_space || !pos_space[0])
{
free (result);
return NULL;
}
pos_space[0] = '\0';
/* exit if command is not authorized for spell checking */
@ -809,24 +767,39 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
while (ptr_string[0])
{
while (ptr_string[0] == ' ')
/* find start of word */
utf8_char_int = weechat_utf8_char_int (ptr_string);
while (!iswalnum (utf8_char_int) || iswspace (utf8_char_int))
{
result[index_result++] = ' ';
ptr_string++;
char_size = weechat_utf8_char_size (ptr_string);
memcpy (result + index_result, ptr_string, char_size);
index_result += char_size;
ptr_string += char_size;
if (!ptr_string[0])
break;
utf8_char_int = weechat_utf8_char_int (ptr_string);
}
if (!ptr_string[0])
break;
pos_space = strchr (ptr_string, ' ');
if (pos_space)
ptr_end = weechat_utf8_next_char (ptr_string);
utf8_char_int = weechat_utf8_char_int (ptr_end);
while (iswalnum (utf8_char_int))
{
pos_space[0] = '\0';
length_word = pos_space - ptr_string;
ptr_end = weechat_utf8_next_char (ptr_end);
if (!ptr_end[0])
break;
utf8_char_int = weechat_utf8_char_int (ptr_end);
}
else
length_word = strlen (ptr_string);
save_end = ptr_end[0];
ptr_end[0] = '\0';
length_word = ptr_end - ptr_string;
word_ok = weechat_aspell_check_word (buffer, ptr_string);
if ((save_end != '\0')
|| (weechat_config_integer (weechat_aspell_config_check_real_time)))
word_ok = weechat_aspell_check_word (buffer, ptr_string);
else
word_ok = 1;
/* add error color */
if (!word_ok)
@ -846,13 +819,11 @@ weechat_aspell_modifier_cb (void *data, const char *modifier,
index_result += length_color_normal;
}
if (pos_space)
{
pos_space[0] = ' ';
ptr_string = pos_space;
}
else
if (save_end == '\0')
break;
ptr_end[0] = save_end;
ptr_string = ptr_end;
}
result[index_result] = '\0';

View File

@ -38,4 +38,4 @@ extern struct t_aspell_code countries_avail[];
extern void weechat_aspell_create_spellers (struct t_gui_buffer *buffer);
#endif /* aspell.h */
#endif /* weechat-aspell.h */

View File

@ -420,6 +420,7 @@ plugin_load (const char *filename)
new_plugin->utf8_normalize = &utf8_normalize;
new_plugin->utf8_prev_char = &utf8_prev_char;
new_plugin->utf8_next_char = &utf8_next_char;
new_plugin->utf8_char_int = &utf8_char_int;
new_plugin->utf8_char_size = &utf8_char_size;
new_plugin->utf8_strlen = &utf8_strlen;
new_plugin->utf8_strnlen = &utf8_strnlen;

View File

@ -175,6 +175,7 @@ struct t_weechat_plugin
void (*utf8_normalize) (const char *string, char replacement);
char *(*utf8_prev_char) (const char *string_start, const char *string);
char *(*utf8_next_char) (const char *string);
int (*utf8_char_int) (const char *string);
int (*utf8_char_size) (const char *string);
int (*utf8_strlen) (const char *string);
int (*utf8_strnlen) (const char *string, int bytes);
@ -708,6 +709,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->utf8_prev_char(__start, __string)
#define weechat_utf8_next_char(__string) \
weechat_plugin->utf8_next_char(__string)
#define weechat_utf8_char_int(__string) \
weechat_plugin->utf8_char_int(__string)
#define weechat_utf8_char_size(__string) \
weechat_plugin->utf8_char_size(__string)
#define weechat_utf8_strlen(__string) \