struct t_hashtable * trigger_callback_focus_cb (void *data, struct t_hashtable *info) { const char *ptr_value; long unsigned int value; int rc; TRIGGER_CALLBACK_CB_INIT(info); TRIGGER_CALLBACK_CB_NEW_POINTERS; /* add data in hashtables used for conditions/replace/command */ ptr_value = weechat_hashtable_get (info, "_window"); if (ptr_value && ptr_value[0] && (strncmp (ptr_value, "0x", 2) == 0)) { rc = sscanf (ptr_value + 2, "%lx", &value); if ((rc != EOF) && (rc >= 1)) weechat_hashtable_set (pointers, "window", (void *)value); } ptr_value = weechat_hashtable_get (info, "_buffer"); if (ptr_value && ptr_value[0] && (strncmp (ptr_value, "0x", 2) == 0)) { rc = sscanf (ptr_value + 2, "%lx", &value); if ((rc != EOF) && (rc >= 1)) weechat_hashtable_set (pointers, "buffer", (void *)value); } /* execute the trigger (conditions, regex, command) */ trigger_callback_execute (trigger, NULL, pointers, info); end: TRIGGER_CALLBACK_CB_END(info); }
int relay_weechat_protocol_is_sync (struct t_relay_client *ptr_client, struct t_gui_buffer *buffer, int flags) { int *ptr_flags; /* search buffer using its full name */ if (buffer) { ptr_flags = weechat_hashtable_get (RELAY_WEECHAT_DATA(ptr_client, buffers_sync), weechat_buffer_get_string (buffer, "full_name")); if (ptr_flags) return ((*ptr_flags) & flags) ? 1 : 0; } /* search special name "*" as fallback */ ptr_flags = weechat_hashtable_get (RELAY_WEECHAT_DATA(ptr_client, buffers_sync), "*"); if (ptr_flags) return ((*ptr_flags) & flags) ? 1 : 0; /* * buffer not found at all in hashtable (neither name, neither "*") * => it is NOT synchronized */ return 0; }
int irc_redirect_pattern_hsignal_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable) { const char *pattern, *str_timeout, *cmd_start, *cmd_stop, *cmd_extra; char *error; int number, timeout; /* make C compiler happy */ (void) pointer; (void) data; (void) signal; if (!hashtable) return WEECHAT_RC_ERROR; pattern = weechat_hashtable_get (hashtable, "pattern"); str_timeout = weechat_hashtable_get (hashtable, "timeout"); cmd_start = weechat_hashtable_get (hashtable, "cmd_start"); cmd_stop = weechat_hashtable_get (hashtable, "cmd_stop"); cmd_extra = weechat_hashtable_get (hashtable, "cmd_extra"); if (!pattern || !pattern[0]) { weechat_printf ( NULL, _("%s%s: missing argument \"%s\" for redirect pattern"), weechat_prefix ("error"), IRC_PLUGIN_NAME, "pattern"); return WEECHAT_RC_ERROR; } if (!cmd_stop || !cmd_stop[0]) { weechat_printf ( NULL, _("%s%s: missing argument \"%s\" for redirect pattern"), weechat_prefix ("error"), IRC_PLUGIN_NAME, "cmd_stop"); return WEECHAT_RC_ERROR; } timeout = 0; if (str_timeout && str_timeout[0]) { number = (int)strtol (str_timeout, &error, 10); if (error && !error[0]) timeout = number; } /* * create a temporary redirect pattern (it will be removed when a * redirect will use it) */ irc_redirect_pattern_new (pattern, 1, timeout, cmd_start, cmd_stop, cmd_extra); return WEECHAT_RC_OK; }
int irc_redirect_message_match_hash (struct t_irc_redirect *redirect, const char *command, char **arguments_argv, int arguments_argc, struct t_hashtable *cmd_hash) { int *value; value = weechat_hashtable_get (cmd_hash, command); if (!value) return 0; /* * if string is in redirect and that this command requires string to * be in message, then search for this string */ if (redirect->string && redirect->string[0] && (*value >= 0)) { if (!arguments_argv || (*value >= arguments_argc)) return 0; if (weechat_strcasecmp (arguments_argv[*value], redirect->string) != 0) return 0; } return 1; }
void twc_group_namelist_change_callback(Tox *tox, int group_number, int peer_number, uint8_t change_type, void *data) { struct t_twc_profile *profile = data; struct t_twc_chat *chat = twc_chat_search_group(profile, group_number, false); struct t_gui_nick *nick; char *name = twc_get_peer_name_nt(profile->tox, group_number, peer_number); if (change_type == TOX_CHAT_CHANGE_PEER_DEL || change_type == TOX_CHAT_CHANGE_PEER_NAME) { nick = weechat_hashtable_get(chat->nicks, &peer_number); weechat_nicklist_remove_nick(chat->buffer, nick); weechat_hashtable_remove(chat->nicks, &peer_number); } if (change_type == TOX_CHAT_CHANGE_PEER_ADD || change_type == TOX_CHAT_CHANGE_PEER_NAME) { nick = weechat_nicklist_add_nick(chat->buffer, chat->nicklist_group, name, NULL, NULL, NULL, 1); weechat_hashtable_set(chat->nicks, &peer_number, nick); } }
void irc_ctcp_reply_to_nick (struct t_irc_server *server, const char *command, struct t_irc_channel *channel, const char *nick, const char *ctcp, const char *arguments) { struct t_hashtable *hashtable; int number; char hash_key[32]; const char *str_args; hashtable = irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW | IRC_SERVER_SEND_RETURN_HASHTABLE, NULL, "NOTICE %s :\01%s%s%s\01", nick, ctcp, (arguments) ? " " : "", (arguments) ? arguments : ""); if (hashtable) { if (weechat_config_boolean (irc_config_look_display_ctcp_reply)) { number = 1; while (1) { snprintf (hash_key, sizeof (hash_key), "args%d", number); str_args = weechat_hashtable_get (hashtable, hash_key); if (!str_args) break; weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, nick, NULL, "ctcp", (channel) ? channel->buffer : NULL), irc_protocol_tags (command, "irc_ctcp,irc_ctcp_reply," "notify_none,no_highlight", NULL), _("%sCTCP reply to %s%s%s: %s%s%s%s%s"), weechat_prefix ("network"), irc_nick_color_for_message (server, NULL, nick), nick, IRC_COLOR_RESET, IRC_COLOR_CHAT_CHANNEL, ctcp, (str_args[0]) ? IRC_COLOR_RESET : "", (str_args[0]) ? " " : "", str_args); number++; } } weechat_hashtable_free (hashtable); } }
struct t_aspell_speller_buffer * weechat_aspell_speller_buffer_new (struct t_gui_buffer *buffer) { const char *buffer_dicts; char **dicts; int num_dicts, i; struct t_aspell_speller_buffer *new_speller_buffer; AspellSpeller *ptr_speller; if (!buffer) return NULL; weechat_hashtable_remove (weechat_aspell_speller_buffer, buffer); new_speller_buffer = malloc (sizeof (*new_speller_buffer)); if (!new_speller_buffer) return NULL; new_speller_buffer->spellers = NULL; new_speller_buffer->modifier_string = NULL; new_speller_buffer->input_pos = -1; new_speller_buffer->modifier_result = NULL; buffer_dicts = weechat_aspell_get_dict (buffer); if (buffer_dicts) { dicts = weechat_string_split (buffer_dicts, ",", 0, 0, &num_dicts); if (dicts && (num_dicts > 0)) { new_speller_buffer->spellers = malloc ((num_dicts + 1) * sizeof (AspellSpeller *)); if (new_speller_buffer->spellers) { for (i = 0; i < num_dicts; i++) { ptr_speller = weechat_hashtable_get (weechat_aspell_spellers, dicts[i]); if (!ptr_speller) ptr_speller = weechat_aspell_speller_new (dicts[i]); new_speller_buffer->spellers[i] = ptr_speller; } new_speller_buffer->spellers[num_dicts] = NULL; } } if (dicts) weechat_string_free_split (dicts); } weechat_hashtable_set (weechat_aspell_speller_buffer, buffer, new_speller_buffer); weechat_bar_item_update ("aspell_dict"); return new_speller_buffer; }
int irc_notify_timer_ison_cb (const void *pointer, void *data, int remaining_calls) { char *message, hash_key[32]; const char *str_message; int num_nicks, number; struct t_irc_server *ptr_server; struct t_hashtable *hashtable; /* make C compiler happy */ (void) pointer; (void) data; (void) remaining_calls; for (ptr_server = irc_servers; ptr_server; ptr_server = ptr_server->next_server) { if (ptr_server->is_connected && ptr_server->notify_list && (ptr_server->monitor == 0)) { message = irc_notify_build_message_with_nicks (ptr_server, "ISON :", " ", &num_nicks); if (message && (num_nicks > 0)) { hashtable = irc_message_split (ptr_server, message); if (hashtable) { number = 1; while (1) { snprintf (hash_key, sizeof (hash_key), "msg%d", number); str_message = weechat_hashtable_get (hashtable, hash_key); if (!str_message) break; irc_redirect_new (ptr_server, "ison", "notify", 1, NULL, 0, NULL); irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "%s", str_message); number++; } weechat_hashtable_free (hashtable); } } if (message) free (message); } } return WEECHAT_RC_OK; }
static cksum_xfer_t* cksum_xfers_find(const char* filename) { if (filename) { struct t_hashtable *xfers = cksum_global_data->xfers; cksum_xfer_t *xfer = (cksum_xfer_t*) weechat_hashtable_get(xfers, (void*) filename); return xfer; } return NULL; }
struct t_hashtable * irc_bar_item_focus_buffer_nicklist (void *data, struct t_hashtable *info) { long unsigned int value; int rc; struct t_gui_buffer *buffer; struct t_irc_nick *ptr_nick; const char *str_buffer, *nick; str_buffer = weechat_hashtable_get (info, "_buffer"); if (!str_buffer || !str_buffer[0]) return NULL; rc = sscanf (str_buffer, "%lx", &value); if ((rc == EOF) || (rc == 0)) return NULL; buffer = (struct t_gui_buffer *)value; IRC_BUFFER_GET_SERVER_CHANNEL(buffer); /* make C compiler happy */ (void) data; if (ptr_server && ptr_channel) { nick = weechat_hashtable_get (info, "nick"); if (nick) { ptr_nick = irc_nick_search (ptr_server, ptr_channel, nick); if (ptr_nick && ptr_nick->host) { weechat_hashtable_set (info, "irc_host", ptr_nick->host); return info; } } } return NULL; }
struct t_hashtable * irc_info_get_info_hashtable_cb (void *data, const char *info_name, struct t_hashtable *hashtable) { const char *server, *message; struct t_irc_server *ptr_server; struct t_hashtable *value; /* make C compiler happy */ (void) data; if (!hashtable) return NULL; if (weechat_strcasecmp (info_name, "irc_message_parse") == 0) { server = weechat_hashtable_get (hashtable, "server"); ptr_server = (server) ? irc_server_search (server) : NULL; message = weechat_hashtable_get (hashtable, "message"); if (message) { value = irc_message_parse_to_hashtable (ptr_server, message); return value; } } else if (weechat_strcasecmp (info_name, "irc_message_split") == 0) { server = weechat_hashtable_get (hashtable, "server"); ptr_server = (server) ? irc_server_search (server) : NULL; message = weechat_hashtable_get (hashtable, "message"); if (message) { value = irc_message_split (ptr_server, message); return value; } } return NULL; }
/** * Get a message queue for a friend, or create one if it does not exist. */ struct t_twc_list * twc_message_queue_get_or_create(struct t_twc_profile *profile, int32_t friend_number) { struct t_twc_list *message_queue = weechat_hashtable_get(profile->message_queues, &friend_number); if (!message_queue) { message_queue = twc_list_new(); weechat_hashtable_set(profile->message_queues, &friend_number, message_queue); } return message_queue; }
void irc_input_send_user_message (struct t_gui_buffer *buffer, int flags, const char *tags, char *message) { int number, action; char hash_key[32], *str_args; struct t_hashtable *hashtable; IRC_BUFFER_GET_SERVER_CHANNEL(buffer); if (!ptr_server || !ptr_channel || !message || !message[0]) return; if (!ptr_server->is_connected) { weechat_printf (buffer, _("%s%s: you are not connected to server"), weechat_prefix ("error"), IRC_PLUGIN_NAME); return; } hashtable = irc_server_sendf (ptr_server, flags | IRC_SERVER_SEND_RETURN_HASHTABLE, tags, "PRIVMSG %s :%s", ptr_channel->name, message); if (hashtable) { action = (strncmp (message, "\01ACTION ", 8) == 0); number = 1; while (1) { snprintf (hash_key, sizeof (hash_key), "args%d", number); str_args = weechat_hashtable_get (hashtable, hash_key); if (!str_args) break; irc_input_user_message_display (buffer, action, str_args); number++; } weechat_hashtable_free (hashtable); } }
void irc_notify_send_monitor (struct t_irc_server *server) { struct t_hashtable *hashtable; char *message, hash_key[32]; const char *str_message; int num_nicks, number; message = irc_notify_build_message_with_nicks (server, "MONITOR + ", ",", &num_nicks); if (message && (num_nicks > 0)) { hashtable = irc_message_split (server, message); if (hashtable) { number = 1; while (1) { snprintf (hash_key, sizeof (hash_key), "msg%d", number); str_message = weechat_hashtable_get (hashtable, hash_key); if (!str_message) break; irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL, "%s", str_message); number++; } weechat_hashtable_free (hashtable); } } if (message) free (message); }
int irc_redirect_command_hsignal_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable) { const char *server, *pattern, *redirect_signal, *str_count, *string; const char *str_timeout, *cmd_filter; char *error; struct t_irc_server *ptr_server; int number, count, timeout; /* make C compiler happy */ (void) pointer; (void) data; (void) signal; if (!hashtable) return WEECHAT_RC_ERROR; server = weechat_hashtable_get (hashtable, "server"); pattern = weechat_hashtable_get (hashtable, "pattern"); redirect_signal = weechat_hashtable_get (hashtable, "signal"); str_count = weechat_hashtable_get (hashtable, "count"); string = weechat_hashtable_get (hashtable, "string"); str_timeout = weechat_hashtable_get (hashtable, "timeout"); cmd_filter = weechat_hashtable_get (hashtable, "cmd_filter"); if (!server || !server[0]) { weechat_printf ( NULL, _("%s%s: missing argument \"%s\" for redirect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, "server"); return WEECHAT_RC_ERROR; } ptr_server = irc_server_search (server); if (!ptr_server) { weechat_printf ( NULL, _("%s%s: server \"%s\" not found for redirect"), weechat_prefix ("error"), IRC_PLUGIN_NAME, server); return WEECHAT_RC_ERROR; } count = 1; if (str_count && str_count[0]) { number = (int)strtol (str_count, &error, 10); if (error && !error[0]) count = number; } timeout = 0; if (str_timeout && str_timeout[0]) { number = (int)strtol (str_timeout, &error, 10); if (error && !error[0]) timeout = number; } irc_redirect_new (ptr_server, pattern, redirect_signal, count, string, timeout, cmd_filter); return WEECHAT_RC_OK; }
int relay_weechat_protocol_hsignal_nicklist_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable) { struct t_relay_client *ptr_client; struct t_gui_nick_group *parent_group, *group; struct t_gui_nick *nick; struct t_gui_buffer *ptr_buffer; struct t_relay_weechat_nicklist *ptr_nicklist; char diff; /* make C compiler happy */ (void) data; ptr_client = (struct t_relay_client *)pointer; if (!ptr_client || !relay_client_valid (ptr_client)) return WEECHAT_RC_OK; /* check if buffer is synchronized with flag "nicklist" */ ptr_buffer = weechat_hashtable_get (hashtable, "buffer"); if (!relay_weechat_protocol_is_sync (ptr_client, ptr_buffer, RELAY_WEECHAT_PROTOCOL_SYNC_NICKLIST)) return WEECHAT_RC_OK; parent_group = weechat_hashtable_get (hashtable, "parent_group"); group = weechat_hashtable_get (hashtable, "group"); nick = weechat_hashtable_get (hashtable, "nick"); /* if there is no parent group (for example "root" group), ignore the signal */ if (!parent_group) return WEECHAT_RC_OK; ptr_nicklist = weechat_hashtable_get (RELAY_WEECHAT_DATA(ptr_client, buffers_nicklist), ptr_buffer); if (!ptr_nicklist) { ptr_nicklist = relay_weechat_nicklist_new (); if (!ptr_nicklist) return WEECHAT_RC_OK; ptr_nicklist->nicklist_count = weechat_buffer_get_integer (ptr_buffer, "nicklist_count"); weechat_hashtable_set (RELAY_WEECHAT_DATA(ptr_client, buffers_nicklist), ptr_buffer, ptr_nicklist); } /* set diff type */ diff = RELAY_WEECHAT_NICKLIST_DIFF_UNKNOWN; if ((strcmp (signal, "nicklist_group_added") == 0) || (strcmp (signal, "nicklist_nick_added") == 0)) { diff = RELAY_WEECHAT_NICKLIST_DIFF_ADDED; } else if ((strcmp (signal, "nicklist_group_removing") == 0) || (strcmp (signal, "nicklist_nick_removing") == 0)) { diff = RELAY_WEECHAT_NICKLIST_DIFF_REMOVED; } else if ((strcmp (signal, "nicklist_group_changed") == 0) || (strcmp (signal, "nicklist_nick_changed") == 0)) { diff = RELAY_WEECHAT_NICKLIST_DIFF_CHANGED; } if (diff != RELAY_WEECHAT_NICKLIST_DIFF_UNKNOWN) { /* * add items if nicklist was not empty or very small (otherwise we will * send full nicklist) */ if (ptr_nicklist->nicklist_count > 1) { /* add nicklist item for parent group and group/nick */ relay_weechat_nicklist_add_item (ptr_nicklist, RELAY_WEECHAT_NICKLIST_DIFF_PARENT, parent_group, NULL); relay_weechat_nicklist_add_item (ptr_nicklist, diff, group, nick); } /* add timer to send nicklist */ if (RELAY_WEECHAT_DATA(ptr_client, hook_timer_nicklist)) { weechat_unhook (RELAY_WEECHAT_DATA(ptr_client, hook_timer_nicklist)); RELAY_WEECHAT_DATA(ptr_client, hook_timer_nicklist) = NULL; } relay_weechat_hook_timer_nicklist (ptr_client); } return WEECHAT_RC_OK; }
void script_buffer_display_line_script (int line, struct t_script_repo *script) { char str_line[16384], str_item[1024], str_color_name[256], str_color[32]; char str_format[256], str_date[64], str_key[2], utf_char[16], *tags; const char *columns, *ptr_col; int char_size, *ptr_max_length, max_length, num_spaces, unknown; struct tm *tm; snprintf (str_color_name, sizeof (str_color_name), "%s,%s", (line == script_buffer_selected_line) ? weechat_config_string (script_config_color_text_selected) : weechat_config_string (script_config_color_text), (line == script_buffer_selected_line) ? weechat_config_string (script_config_color_text_bg_selected) : weechat_config_string (script_config_color_text_bg)); snprintf (str_color, sizeof (str_color), "%s", weechat_color (str_color_name)); columns = weechat_config_string (script_config_look_columns); ptr_col = columns; str_line[0] = '\0'; while (ptr_col[0]) { unknown = 0; str_item[0] = '\0'; num_spaces = 0; char_size = weechat_utf8_char_size (ptr_col); memcpy (utf_char, ptr_col, char_size); utf_char[char_size] = '\0'; if (utf_char[0] == '%') { ptr_col += char_size; char_size = weechat_utf8_char_size (ptr_col); memcpy (utf_char, ptr_col, char_size); utf_char[char_size] = '\0'; str_key[0] = ptr_col[0]; str_key[1] = '\0'; ptr_max_length = weechat_hashtable_get (script_repo_max_length_field, str_key); max_length = (ptr_max_length) ? *ptr_max_length : 0; num_spaces = max_length; switch (utf_char[0]) { case 'a': /* author */ if (script->author) { num_spaces = max_length - weechat_utf8_strlen_screen (script->author); snprintf (str_item, sizeof (str_item), "%s", script->author); } break; case 'd': /* description */ if (script->description) { num_spaces = max_length - weechat_utf8_strlen_screen (script->description); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_description_selected : script_config_color_text_description)), script->description); } break; case 'D': /* date added */ if (script->date_added > 0) { tm = localtime (&script->date_added); strftime (str_date, sizeof (str_date), "%Y-%m-%d", tm); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_date_selected : script_config_color_text_date)), str_date); } else num_spaces = 10; break; case 'e': /* file extension */ if (script->language >= 0) { num_spaces = max_length - weechat_utf8_strlen_screen (script_extension[script->language]); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_extension_selected : script_config_color_text_extension)), script_extension[script->language]); } break; case 'l': /* language */ if (script->language >= 0) { num_spaces = max_length - weechat_utf8_strlen_screen (script_language[script->language]); snprintf (str_item, sizeof (str_item), "%s", script_language[script->language]); } break; case 'L': /* license */ if (script->license) { num_spaces = max_length - weechat_utf8_strlen_screen (script->license); snprintf (str_item, sizeof (str_item), "%s", script->license); } break; case 'n': /* name + extension */ if (script->name_with_extension) { num_spaces = max_length - weechat_utf8_strlen_screen (script->name_with_extension); snprintf (str_item, sizeof (str_item), "%s%s%s.%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_name_selected : script_config_color_text_name)), script->name, weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_extension_selected : script_config_color_text_extension)), script_extension[script->language]); } break; case 'N': /* name (without extension) */ if (script->name) { num_spaces = max_length - weechat_utf8_strlen_screen (script->name); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_name_selected : script_config_color_text_name)), script->name); } break; case 'r': /* requirements */ if (script->requirements) { num_spaces = max_length - weechat_utf8_strlen_screen (script->requirements); snprintf (str_item, sizeof (str_item), "%s", script->requirements); } break; case 's': /* status */ snprintf (str_item, sizeof (str_item), "%s", script_repo_get_status_for_display (script, "*iaHrN", 0)); break; case 't': /* tags */ if (script->tags) { num_spaces = max_length - weechat_utf8_strlen_screen (script->tags); tags = weechat_string_replace (script->tags, ",", " "); if (tags) { snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_tags_selected : script_config_color_text_tags)), tags); free (tags); } } break; case 'u': /* date updated */ if (script->date_updated > 0) { tm = localtime (&script->date_updated); strftime (str_date, sizeof (str_date), "%Y-%m-%d", tm); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_date_selected : script_config_color_text_date)), str_date); } else num_spaces = 10; break; case 'v': /* version */ if (script->version) { num_spaces = max_length - weechat_utf8_strlen_screen (script->version); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_version_selected : script_config_color_text_version)), script->version); } break; case 'V': /* version loaded */ if (script->version_loaded) { num_spaces = max_length - weechat_utf8_strlen_screen (script->version_loaded); snprintf (str_item, sizeof (str_item), "%s%s", weechat_color ( weechat_config_string ( (line == script_buffer_selected_line) ? script_config_color_text_version_loaded_selected : script_config_color_text_version_loaded)), script->version_loaded); } break; case 'w': /* min_weechat */ if (script->min_weechat) { num_spaces = max_length - weechat_utf8_strlen_screen (script->min_weechat); snprintf (str_item, sizeof (str_item), "%s", script->min_weechat); } break; case 'W': /* max_weechat */ if (script->max_weechat) { num_spaces = max_length - weechat_utf8_strlen_screen (script->max_weechat); snprintf (str_item, sizeof (str_item), "%s", script->max_weechat); } break; case '%': /* "%%" will display a single "%" */ snprintf (str_item, sizeof (str_item), "%s%%", weechat_color (weechat_config_string (script_config_color_text_delimiters))); break; default: unknown = 1; break; } } else { snprintf (str_item, sizeof (str_item), "%s%s", weechat_color (weechat_config_string (script_config_color_text_delimiters)), utf_char); } if (!unknown) { if (str_item[0]) { strcat (str_line, str_color); strcat (str_line, str_item); } if (num_spaces > 0) { snprintf (str_format, sizeof (str_format), "%%-%ds", num_spaces); snprintf (str_item, sizeof (str_item), str_format, " "); strcat (str_line, str_item); } } ptr_col += char_size; } weechat_printf_y (script_buffer, line, "%s", str_line); }
char * weechat_aspell_modifier_cb (void *data, const char *modifier, const char *modifier_data, const char *string) { long unsigned int value; struct t_gui_buffer *buffer; struct t_aspell_speller_buffer *ptr_speller_buffer; char *result, *ptr_string, *pos_space, *ptr_end, *ptr_end_valid, save_end; char *word_for_suggestions, *old_suggestions, *suggestions; char *word_and_suggestions; const char *color_normal, *color_error, *ptr_suggestions; int utf8_char_int, char_size; int length, index_result, length_word, word_ok; int length_color_normal, length_color_error, rc; int input_pos, current_pos, word_start_pos, word_end_pos, word_end_pos_valid; /* make C compiler happy */ (void) data; (void) modifier; if (!aspell_enabled) return NULL; if (!string) return NULL; rc = sscanf (modifier_data, "%lx", &value); if ((rc == EOF) || (rc == 0)) return NULL; buffer = (struct t_gui_buffer *)value; /* check text during search only if option is enabled */ if (weechat_buffer_get_integer (buffer, "text_search") && !weechat_config_boolean (weechat_aspell_config_check_during_search)) return NULL; /* get structure with speller info for buffer */ ptr_speller_buffer = weechat_hashtable_get (weechat_aspell_speller_buffer, buffer); if (!ptr_speller_buffer) { ptr_speller_buffer = weechat_aspell_speller_buffer_new (buffer); if (!ptr_speller_buffer) return NULL; } if (!ptr_speller_buffer->spellers) return NULL; /* * for performance: return last string built if input string is the * same (and cursor position is the same, if suggestions are enabled) */ input_pos = weechat_buffer_get_integer (buffer, "input_pos"); if (ptr_speller_buffer->modifier_string && (strcmp (string, ptr_speller_buffer->modifier_string) == 0) && ((weechat_config_integer (weechat_aspell_config_check_suggestions) < 0) || (input_pos == ptr_speller_buffer->input_pos))) { return (ptr_speller_buffer->modifier_result) ? strdup (ptr_speller_buffer->modifier_result) : NULL; } /* free last modifier string and result */ if (ptr_speller_buffer->modifier_string) { free (ptr_speller_buffer->modifier_string); ptr_speller_buffer->modifier_string = NULL; } if (ptr_speller_buffer->modifier_result) { free (ptr_speller_buffer->modifier_result); ptr_speller_buffer->modifier_result = NULL; } word_for_suggestions = NULL; /* save last modifier string received */ ptr_speller_buffer->modifier_string = strdup (string); ptr_speller_buffer->input_pos = input_pos; color_normal = weechat_color ("bar_fg"); length_color_normal = strlen (color_normal); color_error = weechat_color (weechat_config_string (weechat_aspell_config_color_misspelled)); length_color_error = strlen (color_error); length = strlen (string); result = malloc (length + (length * length_color_error) + 1); if (result) { result[0] = '\0'; ptr_string = ptr_speller_buffer->modifier_string; index_result = 0; /* check if string is a command */ if (!weechat_string_input_for_buffer (ptr_string)) { char_size = weechat_utf8_char_size (ptr_string); ptr_string += char_size; 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 */ if (!weechat_aspell_command_authorized (ptr_string)) { free (result); return NULL; } memcpy (result + index_result, ptr_speller_buffer->modifier_string, char_size); index_result += char_size; strcpy (result + index_result, ptr_string); index_result += strlen (ptr_string); pos_space[0] = ' '; ptr_string = pos_space; } current_pos = 0; while (ptr_string[0]) { /* find start of word: it must start with an alphanumeric char */ utf8_char_int = weechat_utf8_char_int (ptr_string); while ((!iswalnum (utf8_char_int)) || iswspace (utf8_char_int)) { char_size = weechat_utf8_char_size (ptr_string); memcpy (result + index_result, ptr_string, char_size); index_result += char_size; ptr_string += char_size; current_pos++; if (!ptr_string[0]) break; utf8_char_int = weechat_utf8_char_int (ptr_string); } if (!ptr_string[0]) break; word_start_pos = current_pos; word_end_pos = current_pos; word_end_pos_valid = current_pos; /* find end of word: ' and - allowed in word, but not at the end */ ptr_end_valid = ptr_string; ptr_end = weechat_utf8_next_char (ptr_string); utf8_char_int = weechat_utf8_char_int (ptr_end); while (iswalnum (utf8_char_int) || (utf8_char_int == '\'') || (utf8_char_int == '-')) { word_end_pos++; if (iswalnum (utf8_char_int)) { /* pointer to last alphanumeric char in the word */ ptr_end_valid = ptr_end; word_end_pos_valid = word_end_pos; } ptr_end = weechat_utf8_next_char (ptr_end); if (!ptr_end[0]) break; utf8_char_int = weechat_utf8_char_int (ptr_end); } ptr_end = weechat_utf8_next_char (ptr_end_valid); word_end_pos = word_end_pos_valid; word_ok = 0; if (weechat_aspell_string_is_url (ptr_string)) { /* * word is an URL, then it is OK, and search for next space * (will be end of word) */ word_ok = 1; if (ptr_end[0]) { utf8_char_int = weechat_utf8_char_int (ptr_end); while (!iswspace (utf8_char_int)) { ptr_end = weechat_utf8_next_char (ptr_end); if (!ptr_end[0]) break; utf8_char_int = weechat_utf8_char_int (ptr_end); } } } save_end = ptr_end[0]; ptr_end[0] = '\0'; length_word = ptr_end - ptr_string; if (!word_ok) { if ((save_end != '\0') || (weechat_config_integer (weechat_aspell_config_check_real_time))) { word_ok = weechat_aspell_check_word (buffer, ptr_speller_buffer, ptr_string); if (!word_ok && (input_pos >= word_start_pos)) { /* * if word is misspelled and that cursor is after * the beginning of this word, save the word (we will * look for suggestions after this loop) */ if (word_for_suggestions) free (word_for_suggestions); word_for_suggestions = strdup (ptr_string); } } else word_ok = 1; } /* add error color */ if (!word_ok) { strcpy (result + index_result, color_error); index_result += length_color_error; } /* add word */ strcpy (result + index_result, ptr_string); index_result += length_word; /* add normal color (after misspelled word) */ if (!word_ok) { strcpy (result + index_result, color_normal); index_result += length_color_normal; } if (save_end == '\0') break; ptr_end[0] = save_end; ptr_string = ptr_end; current_pos = word_end_pos + 1; } result[index_result] = '\0'; } /* save old suggestions in buffer */ ptr_suggestions = weechat_buffer_get_string (buffer, "localvar_aspell_suggest"); old_suggestions = (ptr_suggestions) ? strdup (ptr_suggestions) : NULL; /* if there is a misspelled word, get suggestions and set them in buffer */ if (word_for_suggestions) { suggestions = weechat_aspell_get_suggestions (ptr_speller_buffer, word_for_suggestions); if (suggestions) { length = strlen (word_for_suggestions) + 1 /* ":" */ + strlen (suggestions) + 1; word_and_suggestions = malloc (length); if (word_and_suggestions) { snprintf (word_and_suggestions, length, "%s:%s", word_for_suggestions, suggestions); weechat_buffer_set (buffer, "localvar_set_aspell_suggest", word_and_suggestions); free (word_and_suggestions); } else { weechat_buffer_set (buffer, "localvar_del_aspell_suggest", ""); } free (suggestions); } else { weechat_buffer_set (buffer, "localvar_del_aspell_suggest", ""); } free (word_for_suggestions); } else { weechat_buffer_set (buffer, "localvar_del_aspell_suggest", ""); } /* * if suggestions have changed, update the bar item * and send signal "aspell_suggest" */ ptr_suggestions = weechat_buffer_get_string (buffer, "localvar_aspell_suggest"); if ((old_suggestions && !ptr_suggestions) || (!old_suggestions && ptr_suggestions) || (old_suggestions && ptr_suggestions && (strcmp (old_suggestions, ptr_suggestions) != 0))) { weechat_bar_item_update ("aspell_suggest"); weechat_hook_signal_send ("aspell_suggest", WEECHAT_HOOK_SIGNAL_POINTER, buffer); } if (old_suggestions) free (old_suggestions); if (!result) return NULL; ptr_speller_buffer->modifier_result = strdup (result); return result; }
int irc_notify_hsignal_cb (const void *pointer, void *data, const char *signal, struct t_hashtable *hashtable) { const char *error, *server, *pattern, *command, *output; char **messages, **nicks_sent, **nicks_recv, *irc_cmd, *arguments; char *ptr_args, *pos; int i, j, num_messages, num_nicks_sent, num_nicks_recv, nick_was_sent; int away_message_updated, no_such_nick; struct t_irc_server *ptr_server; struct t_irc_notify *ptr_notify; /* make C compiler happy */ (void) pointer; (void) data; (void) signal; error = weechat_hashtable_get (hashtable, "error"); server = weechat_hashtable_get (hashtable, "server"); pattern = weechat_hashtable_get (hashtable, "pattern"); command = weechat_hashtable_get (hashtable, "command"); output = weechat_hashtable_get (hashtable, "output"); /* if there is an error on redirection, just ignore result */ if (error && error[0]) return WEECHAT_RC_OK; /* missing things in redirection */ if (!server || !pattern || !command || !output) return WEECHAT_RC_OK; /* search server */ ptr_server = irc_server_search (server); if (!ptr_server) return WEECHAT_RC_OK; /* search for start of arguments in command sent to server */ ptr_args = strchr (command, ' '); if (!ptr_args) return WEECHAT_RC_OK; ptr_args++; while ((ptr_args[0] == ' ') || (ptr_args[0] == ':')) { ptr_args++; } if (!ptr_args[0]) return WEECHAT_RC_OK; /* read output of command */ if (strcmp (pattern, "ison") == 0) { /* redirection of command "ison" */ messages = weechat_string_split ( output, "\n", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_messages); if (messages) { nicks_sent = weechat_string_split ( ptr_args, " ", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_nicks_sent); if (!nicks_sent) return WEECHAT_RC_OK; for (ptr_notify = ptr_server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { ptr_notify->ison_received = 0; } for (i = 0; i < num_messages; i++) { irc_message_parse (ptr_server, messages[i], NULL, NULL, NULL, NULL, NULL, NULL, &arguments, NULL, NULL, NULL, NULL, NULL); if (arguments) { pos = strchr (arguments, ' '); if (pos) { pos++; while ((pos[0] == ' ') || (pos[0] == ':')) { pos++; } if (pos[0]) { nicks_recv = weechat_string_split ( pos, " ", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_nicks_recv); if (nicks_recv) { for (j = 0; j < num_nicks_recv; j++) { for (ptr_notify = ptr_server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { if (irc_server_strcasecmp (ptr_server, ptr_notify->nick, nicks_recv[j]) == 0) { irc_notify_set_is_on_server (ptr_notify, NULL, 1); ptr_notify->ison_received = 1; } } } weechat_string_free_split (nicks_recv); } } } free (arguments); } } for (ptr_notify = ptr_server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { if (!ptr_notify->ison_received) { nick_was_sent = 0; for (j = 0; j < num_nicks_sent; j++) { if (irc_server_strcasecmp (ptr_server, nicks_sent[j], ptr_notify->nick) == 0) { nick_was_sent = 1; break; } } if (nick_was_sent) { irc_notify_set_is_on_server (ptr_notify, NULL, 0); } } } weechat_string_free_split (messages); } } else if (strcmp (pattern, "whois") == 0) { /* redirection of command "whois" */ ptr_notify = irc_notify_search (ptr_server, ptr_args); if (ptr_notify) { away_message_updated = 0; no_such_nick = 0; messages = weechat_string_split ( output, "\n", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_messages); if (messages) { for (i = 0; i < num_messages; i++) { irc_message_parse (ptr_server, messages[i], NULL, NULL, NULL, NULL, &irc_cmd, NULL, &arguments, NULL, NULL, NULL, NULL, NULL); if (irc_cmd && arguments) { if (strcmp (irc_cmd, "401") == 0) { /* no such nick/channel */ no_such_nick = 1; } else if (strcmp (irc_cmd, "301") == 0) { /* away message */ pos = strchr (arguments, ':'); if (pos) { pos++; /* nick is away */ irc_notify_set_away_message (ptr_notify, pos); away_message_updated = 1; } } } if (irc_cmd) free (irc_cmd); if (arguments) free (arguments); } } if (!away_message_updated && !no_such_nick) { /* nick is back */ irc_notify_set_away_message (ptr_notify, NULL); } } } return WEECHAT_RC_OK; }
char * trigger_callback_modifier_cb (void *data, const char *modifier, const char *modifier_data, const char *string) { struct t_gui_buffer *buffer; const char *ptr_string; char *string_modified, *pos, *pos2, *plugin_name, *buffer_name; char *buffer_full_name, *str_tags, **tags, *prefix, *string_no_color; int length, num_tags; TRIGGER_CALLBACK_CB_INIT(NULL); buffer = NULL; tags = NULL; num_tags = 0; string_no_color = NULL; /* split IRC message (if string is an IRC message) */ if ((strncmp (modifier, "irc_in_", 7) == 0) || (strncmp (modifier, "irc_in2_", 8) == 0) || (strncmp (modifier, "irc_out1_", 9) == 0) || (strncmp (modifier, "irc_out_", 8) == 0)) { extra_vars = trigger_callback_irc_message_parse (string, modifier_data); if (extra_vars) weechat_hashtable_set (extra_vars, "server", modifier_data); } TRIGGER_CALLBACK_CB_NEW_POINTERS; if (!extra_vars) { TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS; } /* add data in hashtable used for conditions/replace/command */ weechat_hashtable_set (extra_vars, "tg_modifier", modifier); weechat_hashtable_set (extra_vars, "tg_modifier_data", modifier_data); weechat_hashtable_set (extra_vars, "tg_string", string); string_no_color = weechat_string_remove_color (string, NULL); if (string_no_color) { weechat_hashtable_set (extra_vars, "tg_string_nocolor", string_no_color); } /* add special variables for a WeeChat message */ if (strcmp (modifier, "weechat_print") == 0) { /* set "tg_prefix" and "tg_message" */ pos = strchr (string, '\t'); if (pos) { if (pos > string) { prefix = weechat_strndup (string, pos - string); if (prefix) { weechat_hashtable_set (extra_vars, "tg_prefix", prefix); free (prefix); } } pos++; if (pos[0] == '\t') pos++; weechat_hashtable_set (extra_vars, "tg_message", pos); } else weechat_hashtable_set (extra_vars, "tg_message", string); /* set "tg_prefix_nocolor" and "tg_message_nocolor" */ if (string_no_color) { pos = strchr (string_no_color, '\t'); if (pos) { if (pos > string_no_color) { prefix = weechat_strndup (string_no_color, pos - string_no_color); if (prefix) { weechat_hashtable_set (extra_vars, "tg_prefix_nocolor", prefix); free (prefix); } } pos++; if (pos[0] == '\t') pos++; weechat_hashtable_set (extra_vars, "tg_message_nocolor", pos); } else { weechat_hashtable_set (extra_vars, "tg_message_nocolor", string_no_color); } } /* * extract buffer/tags from modifier data * (format: "plugin;buffer_name;tags") */ pos = strchr (modifier_data, ';'); if (pos) { plugin_name = weechat_strndup (modifier_data, pos - modifier_data); if (plugin_name) { weechat_hashtable_set (extra_vars, "tg_plugin", plugin_name); pos++; pos2 = strchr (pos, ';'); if (pos2) { buffer_name = weechat_strndup (pos, pos2 - pos); if (buffer_name) { buffer = weechat_buffer_search (plugin_name, buffer_name); length = strlen (plugin_name) + 1 + strlen (buffer_name) + 1; buffer_full_name = malloc (length); if (buffer_full_name) { snprintf (buffer_full_name, length, "%s.%s", plugin_name, buffer_name); weechat_hashtable_set (extra_vars, "tg_buffer", buffer_full_name); free (buffer_full_name); } free (buffer_name); } pos2++; if (pos2[0]) { tags = weechat_string_split (pos2, ",", 0, 0, &num_tags); length = 1 + strlen (pos2) + 1 + 1; str_tags = malloc (length); if (str_tags) { snprintf (str_tags, length, ",%s,", pos2); weechat_hashtable_set (extra_vars, "tg_tags", str_tags); free (str_tags); } } } free (plugin_name); } } weechat_hashtable_set (pointers, "buffer", buffer); } if (tags) { if (!trigger_callback_set_tags (buffer, (const char **)tags, num_tags, extra_vars)) { goto end; } } /* execute the trigger (conditions, regex, command) */ trigger_callback_execute (trigger, buffer, pointers, extra_vars); end: ptr_string = weechat_hashtable_get (extra_vars, "tg_string"); string_modified = (ptr_string && (strcmp (ptr_string, string) != 0)) ? strdup (ptr_string) : NULL; if (tags) weechat_string_free_split (tags); if (string_no_color) free (string_no_color); TRIGGER_CALLBACK_CB_END(string_modified); }
void trigger_callback_replace_regex (struct t_trigger *trigger, struct t_hashtable *pointers, struct t_hashtable *extra_vars, int display_monitor) { char *value; const char *ptr_key, *ptr_value; int i, pointers_allocated; pointers_allocated = 0; if (trigger->regex_count == 0) return; if (!pointers) { pointers = weechat_hashtable_new (32, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_POINTER, NULL, NULL); if (!pointers) return; pointers_allocated = 1; } for (i = 0; i < trigger->regex_count; i++) { /* if regex is not set (invalid), skip it */ if (!trigger->regex[i].regex) continue; ptr_key = (trigger->regex[i].variable) ? trigger->regex[i].variable : trigger_hook_regex_default_var[weechat_config_integer (trigger->options[TRIGGER_OPTION_HOOK])]; if (!ptr_key || !ptr_key[0]) { if (trigger_buffer && display_monitor) { weechat_printf_tags (trigger_buffer, "no_trigger", "\t regex %d: %s", i + 1, _("no variable")); } continue; } ptr_value = weechat_hashtable_get (extra_vars, ptr_key); if (!ptr_value) { if (trigger_buffer && display_monitor) { weechat_printf_tags (trigger_buffer, "no_trigger", "\t regex %d (%s): %s", i + 1, ptr_key, _("empty variable")); } continue; } weechat_hashtable_set (pointers, "regex", trigger->regex[i].regex); weechat_hashtable_set (trigger_callback_hashtable_options_regex, "regex_replace", trigger->regex[i].replace_escaped); value = weechat_string_eval_expression ( ptr_value, pointers, extra_vars, trigger_callback_hashtable_options_regex); if (value) { /* display debug info on trigger buffer */ if (trigger_buffer && display_monitor) { weechat_printf_tags (trigger_buffer, "no_trigger", "\t regex %d %s(%s%s%s)%s: " "%s\"%s%s%s\"", i + 1, weechat_color ("chat_delimiters"), weechat_color ("reset"), ptr_key, weechat_color ("chat_delimiters"), weechat_color ("reset"), weechat_color ("chat_delimiters"), weechat_color ("reset"), value, weechat_color ("chat_delimiters")); } weechat_hashtable_set (extra_vars, ptr_key, value); free (value); } } if (pointers_allocated) weechat_hashtable_free (pointers); else weechat_hashtable_remove (pointers, "regex"); }
void trigger_callback_replace_regex (struct t_trigger *trigger, struct t_hashtable *pointers, struct t_hashtable *extra_vars, int display_monitor) { char *value, *replace_eval; const char *ptr_key, *ptr_value; int i; if (trigger->regex_count == 0) return; for (i = 0; i < trigger->regex_count; i++) { /* if regex is not set (invalid), skip it */ if (!trigger->regex[i].regex) continue; ptr_key = (trigger->regex[i].variable) ? trigger->regex[i].variable : trigger_hook_regex_default_var[weechat_config_integer (trigger->options[TRIGGER_OPTION_HOOK])]; if (!ptr_key || !ptr_key[0]) { if (trigger_buffer && display_monitor) { weechat_printf_tags (trigger_buffer, "no_trigger", "\t regex %d: %s", i + 1, _("no variable")); } continue; } ptr_value = weechat_hashtable_get (extra_vars, ptr_key); if (!ptr_value) { if (trigger_buffer && display_monitor) { weechat_printf_tags (trigger_buffer, "no_trigger", "\t regex %d (%s): %s", i + 1, ptr_key, _("empty variable")); } continue; } replace_eval = weechat_string_eval_expression ( trigger->regex[i].replace_escaped, pointers, extra_vars, NULL); if (replace_eval) { value = weechat_string_replace_regex (ptr_value, trigger->regex[i].regex, replace_eval, '$', NULL, NULL); if (value) { /* display debug info on trigger buffer */ if (trigger_buffer && display_monitor) { weechat_printf_tags (trigger_buffer, "no_trigger", "\t regex %d %s(%s%s%s)%s: " "%s\"%s%s%s\"", i + 1, weechat_color ("chat_delimiters"), weechat_color ("reset"), ptr_key, weechat_color ("chat_delimiters"), weechat_color ("reset"), weechat_color ("chat_delimiters"), weechat_color ("reset"), value, weechat_color ("chat_delimiters")); } weechat_hashtable_set (extra_vars, ptr_key, value); free (value); } free (replace_eval); } } }
void weechat_aspell_command_add_word (struct t_gui_buffer *buffer, const char *dict, const char *word) { struct t_aspell_speller_buffer *ptr_speller_buffer; #ifdef USE_ENCHANT EnchantDict *new_speller, *ptr_speller; #else AspellSpeller *new_speller, *ptr_speller; #endif new_speller = NULL; if (dict) { ptr_speller = weechat_hashtable_get (weechat_aspell_spellers, dict); if (!ptr_speller) { if (!weechat_aspell_speller_dict_supported (dict)) { weechat_printf (NULL, _("%s: error: dictionary \"%s\" is not " "available on your system"), ASPELL_PLUGIN_NAME, dict); return; } new_speller = weechat_aspell_speller_new (dict); if (!new_speller) return; ptr_speller = new_speller; } } else { ptr_speller_buffer = weechat_hashtable_get (weechat_aspell_speller_buffer, buffer); if (!ptr_speller_buffer) ptr_speller_buffer = weechat_aspell_speller_buffer_new (buffer); if (!ptr_speller_buffer) goto error; if (!ptr_speller_buffer->spellers || !ptr_speller_buffer->spellers[0]) { weechat_printf (NULL, _("%s%s: no dictionary on this buffer for " "adding word"), weechat_prefix ("error"), ASPELL_PLUGIN_NAME); return; } else if (ptr_speller_buffer->spellers[1]) { weechat_printf (NULL, _("%s%s: many dictionaries are defined for " "this buffer, please specify dictionary"), weechat_prefix ("error"), ASPELL_PLUGIN_NAME); return; } ptr_speller = ptr_speller_buffer->spellers[0]; } #ifdef USE_ENCHANT enchant_dict_add (ptr_speller, word, strlen (word)); #else if (aspell_speller_add_to_personal (ptr_speller, word, strlen (word)) == 1) { weechat_printf (NULL, _("%s: word \"%s\" added to personal dictionary"), ASPELL_PLUGIN_NAME, word); } else goto error; #endif goto end; error: weechat_printf (NULL, _("%s%s: failed to add word to personal " "dictionary"), weechat_prefix ("error"), ASPELL_PLUGIN_NAME); end: if (new_speller) weechat_hashtable_remove (weechat_aspell_spellers, dict); }
char * irc_color_decode (const char *string, int keep_colors) { unsigned char *out, *out2, *ptr_string; int out_length, length, out_pos, length_to_add; char str_fg[3], str_bg[3], str_color[128], str_key[128], str_to_add[128]; const char *remapped_color; int fg, bg, bold, reverse, italic, underline, rc; if (!string) return NULL; /* * create output string with size of length*2 (with min 128 bytes), * this string will be realloc() later with a larger size if needed */ out_length = (strlen (string) * 2) + 1; if (out_length < 128) out_length = 128; out = malloc (out_length); if (!out) return NULL; /* initialize attributes */ bold = 0; reverse = 0; italic = 0; underline = 0; ptr_string = (unsigned char *)string; out[0] = '\0'; out_pos = 0; while (ptr_string && ptr_string[0]) { str_to_add[0] = '\0'; switch (ptr_string[0]) { case IRC_COLOR_BOLD_CHAR: if (keep_colors) { snprintf (str_to_add, sizeof (str_to_add), "%s", weechat_color ((bold) ? "-bold" : "bold")); } bold ^= 1; ptr_string++; break; case IRC_COLOR_RESET_CHAR: if (keep_colors) { snprintf (str_to_add, sizeof (str_to_add), "%s", weechat_color ("reset")); } bold = 0; reverse = 0; italic = 0; underline = 0; ptr_string++; break; case IRC_COLOR_FIXED_CHAR: ptr_string++; break; case IRC_COLOR_REVERSE_CHAR: if (keep_colors) { snprintf (str_to_add, sizeof (str_to_add), "%s", weechat_color ((reverse) ? "-reverse" : "reverse")); } reverse ^= 1; ptr_string++; break; case IRC_COLOR_ITALIC_CHAR: if (keep_colors) { snprintf (str_to_add, sizeof (str_to_add), "%s", weechat_color ((italic) ? "-italic" : "italic")); } italic ^= 1; ptr_string++; break; case IRC_COLOR_UNDERLINE_CHAR: if (keep_colors) { snprintf (str_to_add, sizeof (str_to_add), "%s", weechat_color ((underline) ? "-underline" : "underline")); } underline ^= 1; ptr_string++; break; case IRC_COLOR_COLOR_CHAR: ptr_string++; str_fg[0] = '\0'; str_bg[0] = '\0'; if (isdigit (ptr_string[0])) { str_fg[0] = ptr_string[0]; str_fg[1] = '\0'; ptr_string++; if (isdigit (ptr_string[0])) { str_fg[1] = ptr_string[0]; str_fg[2] = '\0'; ptr_string++; } } if ((ptr_string[0] == ',') && (isdigit (ptr_string[1]))) { ptr_string++; str_bg[0] = ptr_string[0]; str_bg[1] = '\0'; ptr_string++; if (isdigit (ptr_string[0])) { str_bg[1] = ptr_string[0]; str_bg[2] = '\0'; ptr_string++; } } if (keep_colors) { if (str_fg[0] || str_bg[0]) { fg = -1; bg = -1; if (str_fg[0]) { rc = sscanf (str_fg, "%d", &fg); if ((rc != EOF) && (rc >= 1)) { fg %= IRC_NUM_COLORS; } } if (str_bg[0]) { rc = sscanf (str_bg, "%d", &bg); if ((rc != EOF) && (rc >= 1)) { bg %= IRC_NUM_COLORS; } } /* search "fg,bg" in hashtable of remapped colors */ snprintf (str_key, sizeof (str_key), "%d,%d", fg, bg); remapped_color = weechat_hashtable_get ( irc_config_hashtable_color_mirc_remap, str_key); if (remapped_color) { snprintf (str_color, sizeof (str_color), "|%s", remapped_color); } else { snprintf (str_color, sizeof (str_color), "|%s%s%s", (fg >= 0) ? irc_color_to_weechat[fg] : "", (bg >= 0) ? "," : "", (bg >= 0) ? irc_color_to_weechat[bg] : ""); } snprintf (str_to_add, sizeof (str_to_add), "%s", weechat_color (str_color)); } else { snprintf (str_to_add, sizeof (str_to_add), "%s", weechat_color ("resetcolor")); } } break; default: /* * we are not on an IRC color code, just copy the UTF-8 char * into "str_to_add" */ length = weechat_utf8_char_size ((char *)ptr_string); if (length == 0) length = 1; memcpy (str_to_add, ptr_string, length); str_to_add[length] = '\0'; ptr_string += length; break; } /* add "str_to_add" (if not empty) to "out" */ if (str_to_add[0]) { /* if "out" is too small for adding "str_to_add", do a realloc() */ length_to_add = strlen (str_to_add); if (out_pos + length_to_add + 1 > out_length) { /* try to double the size of "out" */ out_length *= 2; out2 = realloc (out, out_length); if (!out2) return (char *)out; out = out2; } /* add "str_to_add" to "out" */ memcpy (out + out_pos, str_to_add, length_to_add + 1); out_pos += length_to_add; } } return (char *)out; }