char * twc_bar_item_buffer_plugin(void *data, struct t_gui_bar_item *item, struct t_gui_window *window, struct t_gui_buffer *buffer, struct t_hashtable *extra_info) { struct t_twc_profile *profile = twc_profile_search_buffer(buffer); char string[256]; const char *plugin_name = weechat_plugin_get_name(weechat_plugin); if (!profile) return strdup(plugin_name); const char *profile_name = profile->name; snprintf(string, sizeof(string), "%s%s/%s%s%s/%s%s", plugin_name, weechat_color("bar_delim"), weechat_color("bar_fg"), profile_name, weechat_color("bar_delim"), weechat_color("bar_fg"), profile->tox_online ? "online" : "offline"); return strdup(string); }
struct t_irc_raw_message * irc_raw_message_add (struct t_irc_server *server, int send, int modified, const char *message) { char *buf, *buf2, prefix[256]; const unsigned char *ptr_buf; const char *hexa = "0123456789ABCDEF"; int pos_buf, pos_buf2, char_size, i; struct t_irc_raw_message *new_raw_message; buf = weechat_iconv_to_internal (NULL, message); buf2 = malloc ((strlen (buf) * 3) + 1); if (buf2) { ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message; pos_buf = 0; pos_buf2 = 0; while (ptr_buf[pos_buf]) { if (ptr_buf[pos_buf] < 32) { buf2[pos_buf2++] = '\\'; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16]; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16]; pos_buf++; } else { char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf)); for (i = 0; i < char_size; i++) { buf2[pos_buf2++] = ptr_buf[pos_buf++]; } } } buf2[pos_buf2] = '\0'; } snprintf (prefix, sizeof (prefix), "%s%s%s%s%s", (server) ? weechat_color ("chat_server") : "", (server) ? server->name : "", (server) ? " " : "", (send) ? weechat_color ("chat_prefix_quit") : weechat_color ("chat_prefix_join"), (send) ? ((modified) ? IRC_RAW_PREFIX_SEND_MOD : IRC_RAW_PREFIX_SEND) : ((modified) ? IRC_RAW_PREFIX_RECV_MOD : IRC_RAW_PREFIX_RECV)); new_raw_message = irc_raw_message_add_to_list (time (NULL), prefix, (buf2) ? buf2 : ((buf) ? buf : message)); if (buf) free (buf); if (buf2) free (buf2); return new_raw_message; }
int xfer_command_me (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_xfer *ptr_xfer; /* make C compiler happy */ (void) data; (void) argc; (void) argv; ptr_xfer = xfer_search_by_buffer (buffer); if (!ptr_xfer) { weechat_printf (NULL, _("%s%s: can't find xfer for buffer \"%s\""), weechat_prefix ("error"), XFER_PLUGIN_NAME, weechat_buffer_get_string (buffer, "name")); return WEECHAT_RC_OK; } if (!XFER_HAS_ENDED(ptr_xfer->status)) { xfer_chat_sendf (ptr_xfer, "\01ACTION %s\01\n", (argv_eol[1]) ? argv_eol[1] : ""); weechat_printf_tags (buffer, "no_highlight", "%s%s%s %s%s", weechat_prefix ("action"), weechat_color ("chat_nick_self"), ptr_xfer->local_nick, weechat_color ("chat"), (argv_eol[1]) ? argv_eol[1] : ""); } return WEECHAT_RC_OK; }
void logger_list () { struct t_infolist *ptr_infolist; struct t_logger_buffer *ptr_logger_buffer; struct t_gui_buffer *ptr_buffer; char status[128]; weechat_printf (NULL, ""); weechat_printf (NULL, _("Logging on buffers:")); ptr_infolist = weechat_infolist_get ("buffer", NULL, NULL); if (ptr_infolist) { while (weechat_infolist_next (ptr_infolist)) { ptr_buffer = weechat_infolist_pointer (ptr_infolist, "pointer"); if (ptr_buffer) { ptr_logger_buffer = logger_buffer_search_buffer (ptr_buffer); if (ptr_logger_buffer) { snprintf (status, sizeof (status), _("logging (level: %d)"), ptr_logger_buffer->log_level); } else { snprintf (status, sizeof (status), "%s", _("not logging")); } weechat_printf (NULL, " %s[%s%d%s]%s (%s) %s%s%s: %s%s%s%s", weechat_color("chat_delimiters"), weechat_color("chat"), weechat_infolist_integer (ptr_infolist, "number"), weechat_color("chat_delimiters"), weechat_color("chat"), weechat_infolist_string (ptr_infolist, "plugin_name"), weechat_color("chat_buffer"), weechat_infolist_string (ptr_infolist, "name"), weechat_color("chat"), status, (ptr_logger_buffer) ? " (" : "", (ptr_logger_buffer) ? ((ptr_logger_buffer->log_filename) ? ptr_logger_buffer->log_filename : _("log not started")) : "", (ptr_logger_buffer) ? ")" : ""); } } weechat_infolist_free (ptr_infolist); } }
int xfer_chat_buffer_input_cb (void *data, struct t_gui_buffer *buffer, const char *input_data) { struct t_xfer *ptr_xfer; char *input_data_color, str_tags[256], *str_color; /* make C compiler happy */ (void) data; ptr_xfer = xfer_search_by_buffer (buffer); if (ptr_xfer) { if (!XFER_HAS_ENDED(ptr_xfer->status)) { xfer_chat_sendf (ptr_xfer, "%s\r\n", input_data); if (!XFER_HAS_ENDED(ptr_xfer->status)) { str_color = xfer_chat_color_for_tags (weechat_config_color (weechat_config_get ("weechat.color.chat_nick_self"))); snprintf (str_tags, sizeof (str_tags), "irc_privmsg,no_highlight,prefix_nick_%s,nick_%s,log1", (str_color) ? str_color : "default", ptr_xfer->local_nick); if (str_color) free (str_color); input_data_color = weechat_hook_modifier_exec ("irc_color_decode", "1", input_data); weechat_printf_tags (buffer, str_tags, "%s%s\t%s", weechat_color ("chat_nick_self"), ptr_xfer->local_nick, (input_data_color) ? input_data_color : input_data); if (input_data_color) free (input_data_color); } } } return WEECHAT_RC_OK; }
void trigger_callback_run_command (struct t_trigger *trigger, struct t_gui_buffer *buffer, struct t_hashtable *pointers, struct t_hashtable *extra_vars, int display_monitor) { char *command_eval; int i; if (!trigger->commands) return; if (!buffer) { buffer = weechat_buffer_search_main (); if (!buffer) return; } for (i = 0; trigger->commands[i]; i++) { command_eval = weechat_string_eval_expression (trigger->commands[i], pointers, extra_vars, NULL); if (command_eval) { /* display debug info on trigger buffer */ if (trigger_buffer && display_monitor) { weechat_printf_tags (trigger_buffer, "no_trigger", _("%s running command %s\"%s%s%s\"%s " "on buffer %s%s%s"), "\t", weechat_color ("chat_delimiters"), weechat_color ("reset"), command_eval, weechat_color ("chat_delimiters"), weechat_color ("reset"), weechat_color ("chat_buffer"), weechat_buffer_get_string (buffer, "full_name"), weechat_color ("reset")); } weechat_command (buffer, command_eval); trigger->hook_count_cmd++; } free (command_eval); } }
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 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; }
char * irc_color_decode_ansi_cb (void *data, const char *text) { struct t_irc_color_ansi_state *ansi_state; char *text2, **items, *output, str_color[128]; int i, length, num_items, value, color; ansi_state = (struct t_irc_color_ansi_state *)data; /* if we don't keep colors of if text is empty, just return empty string */ if (!ansi_state->keep_colors || !text || !text[0]) return strdup (""); /* only sequences ending with 'm' are used, the others are discarded */ length = strlen (text); if (text[length - 1] != 'm') return strdup (""); /* sequence "\33[m" resets color */ if (length < 4) return strdup (weechat_color ("reset")); text2 = NULL; items = NULL; output = NULL; /* extract text between "\33[" and "m" */ text2 = weechat_strndup (text + 2, length - 3); if (!text2) goto end; items = weechat_string_split (text2, ";", 0, 0, &num_items); if (!items) goto end; output = malloc ((32 * num_items) + 1); if (!output) goto end; output[0] = '\0'; for (i = 0; i < num_items; i++) { value = atoi (items[i]); switch (value) { case 0: /* reset */ strcat (output, IRC_COLOR_RESET_STR); ansi_state->bold = 0; ansi_state->underline = 0; ansi_state->italic = 0; break; case 1: /* bold */ if (!ansi_state->bold) { strcat (output, IRC_COLOR_BOLD_STR); ansi_state->bold = 1; } break; case 2: /* remove bold */ case 21: case 22: if (ansi_state->bold) { strcat (output, IRC_COLOR_BOLD_STR); ansi_state->bold = 0; } break; case 3: /* italic */ if (!ansi_state->italic) { strcat (output, IRC_COLOR_ITALIC_STR); ansi_state->italic = 1; } break; case 4: /* underline */ if (!ansi_state->underline) { strcat (output, IRC_COLOR_UNDERLINE_STR); ansi_state->underline = 1; } break; case 23: /* remove italic */ if (ansi_state->italic) { strcat (output, IRC_COLOR_ITALIC_STR); ansi_state->italic = 0; } break; case 24: /* remove underline */ if (ansi_state->underline) { strcat (output, IRC_COLOR_UNDERLINE_STR); ansi_state->underline = 0; } break; case 30: /* text color */ case 31: case 32: case 33: case 34: case 35: case 36: case 37: snprintf (str_color, sizeof (str_color), "%c%02d", IRC_COLOR_COLOR_CHAR, irc_color_term2irc[value - 30]); strcat (output, str_color); break; case 38: /* text color */ if (i + 1 < num_items) { switch (atoi (items[i + 1])) { case 2: /* RGB color */ if (i + 4 < num_items) { color = irc_color_convert_rgb2irc ( (atoi (items[i + 2]) << 16) | (atoi (items[i + 3]) << 8) | atoi (items[i + 4])); if (color >= 0) { snprintf (str_color, sizeof (str_color), "%c%02d", IRC_COLOR_COLOR_CHAR, color); strcat (output, str_color); } i += 4; } break; case 5: /* terminal color (0-255) */ if (i + 2 < num_items) { color = irc_color_convert_term2irc (atoi (items[i + 2])); if (color >= 0) { snprintf (str_color, sizeof (str_color), "%c%02d", IRC_COLOR_COLOR_CHAR, color); strcat (output, str_color); } i += 2; } break; } } break; case 39: /* default text color */ snprintf (str_color, sizeof (str_color), "%c15", IRC_COLOR_COLOR_CHAR); strcat (output, str_color); break; case 40: /* background color */ case 41: case 42: case 43: case 44: case 45: case 46: case 47: snprintf (str_color, sizeof (str_color), "%c,%02d", IRC_COLOR_COLOR_CHAR, irc_color_term2irc[value - 40]); strcat (output, str_color); break; case 48: /* background color */ if (i + 1 < num_items) { switch (atoi (items[i + 1])) { case 2: /* RGB color */ if (i + 4 < num_items) { color = irc_color_convert_rgb2irc ( (atoi (items[i + 2]) << 16) | (atoi (items[i + 3]) << 8) | atoi (items[i + 4])); if (color >= 0) { snprintf (str_color, sizeof (str_color), "%c,%02d", IRC_COLOR_COLOR_CHAR, color); strcat (output, str_color); } i += 4; } break; case 5: /* terminal color (0-255) */ if (i + 2 < num_items) { color = irc_color_convert_term2irc (atoi (items[i + 2])); if (color >= 0) { snprintf (str_color, sizeof (str_color), "%c,%02d", IRC_COLOR_COLOR_CHAR, color); strcat (output, str_color); } i += 2; } break; } } break; case 49: /* default background color */ snprintf (str_color, sizeof (str_color), "%c,01", IRC_COLOR_COLOR_CHAR); strcat (output, str_color); break; case 90: /* text color (bright) */ case 91: case 92: case 93: case 94: case 95: case 96: case 97: snprintf (str_color, sizeof (str_color), "%c%02d", IRC_COLOR_COLOR_CHAR, irc_color_term2irc[value - 90 + 8]); strcat (output, str_color); break; case 100: /* background color (bright) */ case 101: case 102: case 103: case 104: case 105: case 106: case 107: snprintf (str_color, sizeof (str_color), "%c,%02d", IRC_COLOR_COLOR_CHAR, irc_color_term2irc[value - 100 + 8]); strcat (output, str_color); break; } } end: if (items) weechat_string_free_split (items); if (text2) free (text2); return (output) ? output : strdup (""); }
void relay_buffer_refresh (const char *hotlist) { struct t_relay_client *ptr_client, *client_selected; char str_color[256], str_status[64], str_date_start[128], str_date_end[128]; char *str_recv, *str_sent; int i, length, line; struct tm *date_tmp; if (relay_buffer) { weechat_buffer_clear (relay_buffer); line = 0; client_selected = relay_client_search_by_number (relay_buffer_selected_line); weechat_printf_y (relay_buffer, 0, "%s%s%s%s%s%s%s", weechat_color("green"), _("Actions (letter+enter):"), weechat_color("lightgreen"), /* disconnect */ (client_selected && !RELAY_CLIENT_HAS_ENDED(client_selected)) ? _(" [D] Disconnect") : "", /* remove */ (client_selected && RELAY_CLIENT_HAS_ENDED(client_selected)) ? _(" [R] Remove") : "", /* purge old */ _(" [P] Purge finished"), /* quit */ _(" [Q] Close this buffer")); for (ptr_client = relay_clients; ptr_client; ptr_client = ptr_client->next_client) { snprintf (str_color, sizeof (str_color), "%s,%s", (line == relay_buffer_selected_line) ? weechat_config_string (relay_config_color_text_selected) : weechat_config_string (relay_config_color_text), weechat_config_string (relay_config_color_text_bg)); snprintf (str_status, sizeof (str_status), "%s", _(relay_client_status_string[ptr_client->status])); length = weechat_utf8_strlen_screen (str_status); if (length < 20) { for (i = 0; i < 20 - length; i++) { strcat (str_status, " "); } } str_date_start[0] = '\0'; date_tmp = localtime (&(ptr_client->start_time)); if (date_tmp) { strftime (str_date_start, sizeof (str_date_start), "%a, %d %b %Y %H:%M:%S", date_tmp); } str_date_end[0] = '-'; str_date_end[1] = '\0'; if (ptr_client->end_time > 0) { date_tmp = localtime (&(ptr_client->end_time)); if (date_tmp) { strftime (str_date_end, sizeof (str_date_end), "%a, %d %b %Y %H:%M:%S", date_tmp); } } str_recv = weechat_string_format_size (ptr_client->bytes_recv); str_sent = weechat_string_format_size (ptr_client->bytes_sent); /* first line with status, description and bytes recv/sent */ weechat_printf_y (relay_buffer, (line * 2) + 2, _("%s%s[%s%s%s%s] %s, received: %s, sent: %s"), weechat_color(str_color), (line == relay_buffer_selected_line) ? "*** " : " ", weechat_color(weechat_config_string (relay_config_color_status[ptr_client->status])), str_status, weechat_color ("reset"), weechat_color (str_color), ptr_client->desc, (str_recv) ? str_recv : "?", (str_sent) ? str_sent : "?"); /* second line with start/end time */ weechat_printf_y (relay_buffer, (line * 2) + 3, _("%s%-26s started on: %s, ended on: %s"), weechat_color(str_color), " ", str_date_start, str_date_end); if (str_recv) free (str_recv); if (str_sent) free (str_sent); line++; } if (hotlist) weechat_buffer_set (relay_buffer, "hotlist", hotlist); } }
void relay_raw_message_add (struct t_relay_client *client, int flags, const char *data, int data_size) { char *buf, *buf2, prefix[256], prefix_arrow[16]; const unsigned char *ptr_buf; const char *hexa = "0123456789ABCDEF"; int pos_buf, pos_buf2, char_size, i; struct t_relay_raw_message *new_raw_message; buf = NULL; buf2 = NULL; if (flags & RELAY_RAW_FLAG_BINARY) { /* binary message */ buf = weechat_string_hex_dump (data, data_size, 16, " > ", NULL); snprintf (prefix, sizeof (prefix), " "); } else { /* text message */ buf = weechat_iconv_to_internal (NULL, data); buf2 = weechat_string_replace (buf, "\r", ""); if (buf2) { free (buf); buf = buf2; buf2 = NULL; } buf2 = malloc ((strlen (buf) * 4) + 1); if (buf2) { ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)data; pos_buf = 0; pos_buf2 = 0; while (ptr_buf[pos_buf]) { if ((ptr_buf[pos_buf] < 32) && (ptr_buf[pos_buf] != '\n')) { buf2[pos_buf2++] = '\\'; buf2[pos_buf2++] = 'x'; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16]; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16]; pos_buf++; } else { char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf)); for (i = 0; i < char_size; i++) { buf2[pos_buf2++] = ptr_buf[pos_buf++]; } } } buf2[pos_buf2] = '\0'; } /* build prefix with arrow */ prefix_arrow[0] = '\0'; switch (flags & (RELAY_RAW_FLAG_RECV | RELAY_RAW_FLAG_SEND)) { case RELAY_RAW_FLAG_RECV: strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV); break; case RELAY_RAW_FLAG_SEND: strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND); break; default: if (flags & RELAY_RAW_FLAG_RECV) strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV); else strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND); break; } if (client) { snprintf (prefix, sizeof (prefix), "%s%s %s[%s%d%s] %s%s%s%s", (flags & RELAY_RAW_FLAG_SEND) ? weechat_color ("chat_prefix_quit") : weechat_color ("chat_prefix_join"), prefix_arrow, weechat_color ("chat_delimiters"), weechat_color ("chat"), client->id, weechat_color ("chat_delimiters"), weechat_color ("chat_server"), relay_protocol_string[client->protocol], (client->protocol_args) ? "." : "", (client->protocol_args) ? client->protocol_args : ""); } else { snprintf (prefix, sizeof (prefix), "%s%s", (flags & RELAY_RAW_FLAG_SEND) ? weechat_color ("chat_prefix_quit") : weechat_color ("chat_prefix_join"), prefix_arrow); } } new_raw_message = relay_raw_message_add_to_list ( time (NULL), prefix, (buf2) ? buf2 : ((buf) ? buf : data)); if (new_raw_message) { if (relay_raw_buffer) relay_raw_message_print (new_raw_message); if (weechat_config_integer (relay_config_look_raw_messages) == 0) relay_raw_message_free (new_raw_message); } if (buf) free (buf); if (buf2) free (buf2); }
void relay_command_client_list (int full) { struct t_relay_client *ptr_client; char date_start[128], date_activity[128]; struct tm *date_tmp; int num_found; num_found = 0; for (ptr_client = relay_clients; ptr_client; ptr_client = ptr_client->next_client) { if (!full && RELAY_CLIENT_HAS_ENDED(ptr_client)) continue; if (num_found == 0) { weechat_printf (NULL, ""); weechat_printf (NULL, (full) ? _("Clients for relay:") : _("Connected clients for relay:")); } num_found++; date_start[0] = '\0'; date_tmp = localtime (&(ptr_client->start_time)); if (date_tmp) { strftime (date_start, sizeof (date_start), "%a, %d %b %Y %H:%M:%S", date_tmp); } date_activity[0] = '\0'; date_tmp = localtime (&(ptr_client->last_activity)); if (date_tmp) { strftime (date_activity, sizeof (date_activity), "%a, %d %b %Y %H:%M:%S", date_tmp); } if (full) { weechat_printf (NULL, _(" %s%s%s (%s%s%s), started on: %s, last activity: %s, " "bytes: %lu recv, %lu sent"), RELAY_COLOR_CHAT_CLIENT, ptr_client->desc, RELAY_COLOR_CHAT, weechat_color (weechat_config_string (relay_config_color_status[ptr_client->status])), relay_client_status_string[ptr_client->status], RELAY_COLOR_CHAT, date_start, date_activity, ptr_client->bytes_recv, ptr_client->bytes_sent); } else { weechat_printf (NULL, _(" %s%s%s (%s%s%s), started on: %s"), RELAY_COLOR_CHAT_CLIENT, ptr_client->desc, RELAY_COLOR_CHAT, weechat_color (weechat_config_string (relay_config_color_status[ptr_client->status])), relay_client_status_string[ptr_client->status], RELAY_COLOR_CHAT, date_start); } } if (num_found == 0) { weechat_printf (NULL, (full) ? _("No client for relay") : _("No connected client for relay")); } }
void xfer_buffer_refresh (const char *hotlist) { struct t_xfer *ptr_xfer, *xfer_selected; char str_color[256], suffix[32], status[64], date[128], eta[128]; char str_ip[128], str_hash[128]; char *progress_bar, *str_pos, *str_total, *str_bytes_per_sec; int i, length, line, progress_bar_size, num_bars; unsigned long long pos, pct_complete; struct tm *date_tmp; if (xfer_buffer) { weechat_buffer_clear (xfer_buffer); line = 0; xfer_selected = xfer_search_by_number (xfer_buffer_selected_line); weechat_printf_y (xfer_buffer, 0, "%s%s%s%s%s%s%s%s", weechat_color ("green"), _("Actions (letter+enter):"), weechat_color ("lightgreen"), /* accept */ (xfer_selected && XFER_IS_RECV(xfer_selected->type) && (xfer_selected->status == XFER_STATUS_WAITING)) ? _(" [A] Accept") : "", /* cancel */ (xfer_selected && !XFER_HAS_ENDED(xfer_selected->status)) ? _(" [C] Cancel") : "", /* remove */ (xfer_selected && XFER_HAS_ENDED(xfer_selected->status)) ? _(" [R] Remove") : "", /* purge old */ _(" [P] Purge finished"), /* quit */ _(" [Q] Close this buffer")); for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer) { suffix[0] = '\0'; if (ptr_xfer->filename_suffix >= 0) { snprintf (suffix, sizeof (suffix), " (.%d)", ptr_xfer->filename_suffix); } snprintf (str_color, sizeof (str_color), "%s,%s", (line == xfer_buffer_selected_line) ? weechat_config_string (xfer_config_color_text_selected) : weechat_config_string (xfer_config_color_text), weechat_config_string (xfer_config_color_text_bg)); str_ip[0] = '\0'; if (ptr_xfer->remote_address_str) { snprintf (str_ip, sizeof (str_ip), " (%s)", ptr_xfer->remote_address_str); } str_hash[0] = '\0'; if (ptr_xfer->hash_target && ptr_xfer->hash_handle && (ptr_xfer->hash_status != XFER_HASH_STATUS_UNKNOWN) && ((ptr_xfer->status == XFER_STATUS_ACTIVE) || (ptr_xfer->status == XFER_STATUS_DONE) || (ptr_xfer->status == XFER_STATUS_HASHING))) { snprintf (str_hash, sizeof (str_hash), " (%s)", _(xfer_hash_status_string[ptr_xfer->hash_status])); } /* display first line with remote nick, filename and plugin name/id */ weechat_printf_y (xfer_buffer, (line * 2) + 2, "%s%s%-24s %s%s%s%s (%s.%s)%s%s", weechat_color (str_color), (line == xfer_buffer_selected_line) ? "*** " : " ", ptr_xfer->remote_nick, (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "", (XFER_IS_FILE(ptr_xfer->type)) ? ptr_xfer->filename : _("xfer chat"), (XFER_IS_FILE(ptr_xfer->type)) ? "\"" : "", suffix, ptr_xfer->plugin_name, ptr_xfer->plugin_id, str_ip, str_hash); snprintf (status, sizeof (status), "%s", _(xfer_status_string[ptr_xfer->status])); length = weechat_utf8_strlen_screen (status); if (length < 20) { for (i = 0; i < 20 - length; i++) { strcat (status, " "); } } if (XFER_IS_CHAT(ptr_xfer->type)) { /* display second line for chat with status and date */ date[0] = '\0'; date_tmp = localtime (&(ptr_xfer->start_time)); if (date_tmp) { if (strftime (date, sizeof (date), "%a, %d %b %Y %H:%M:%S", date_tmp) == 0) date[0] = '\0'; } weechat_printf_y (xfer_buffer, (line * 2) + 3, "%s%s%s %s%s%s%s%s", weechat_color (str_color), (line == xfer_buffer_selected_line) ? "*** " : " ", (XFER_IS_SEND(ptr_xfer->type)) ? "<<--" : "-->>", weechat_color (weechat_config_string (xfer_config_color_status[ptr_xfer->status])), status, weechat_color ("reset"), weechat_color (str_color), date); } else { /* build progress bar */ pos = (ptr_xfer->pos <= ptr_xfer->size) ? ptr_xfer->pos : ptr_xfer->size; progress_bar = NULL; progress_bar_size = weechat_config_integer (xfer_config_look_progress_bar_size); if (progress_bar_size > 0) { progress_bar = malloc (1 + progress_bar_size + 1 + 1 + 1); strcpy (progress_bar, "["); if (ptr_xfer->size == 0) { if (ptr_xfer->status == XFER_STATUS_DONE) num_bars = progress_bar_size; else num_bars = 0; } else num_bars = (int)(((float)(pos)/(float)(ptr_xfer->size)) * (float)progress_bar_size); for (i = 0; i < num_bars - 1; i++) { strcat (progress_bar, "="); } if (num_bars > 0) strcat (progress_bar, ">"); for (i = 0; i < progress_bar_size - num_bars; i++) { strcat (progress_bar, " "); } strcat (progress_bar, "] "); } /* computes percentage */ if (ptr_xfer->size == 0) { if (ptr_xfer->status == XFER_STATUS_DONE) pct_complete = 100; else pct_complete = 0; } else pct_complete = (unsigned long long)(((float)(pos)/(float)(ptr_xfer->size)) * 100); /* position, total and bytes per second */ str_pos = weechat_string_format_size (pos); str_total = weechat_string_format_size (ptr_xfer->size); str_bytes_per_sec = weechat_string_format_size (ptr_xfer->bytes_per_sec); /* ETA */ eta[0] = '\0'; if (ptr_xfer->status == XFER_STATUS_ACTIVE) { snprintf (eta, sizeof (eta), "%s: %.2llu:%.2llu:%.2llu - ", _("ETA"), ptr_xfer->eta / 3600, (ptr_xfer->eta / 60) % 60, ptr_xfer->eta % 60); } /* display second line for file with status, progress bar and estimated time */ weechat_printf_y (xfer_buffer, (line * 2) + 3, "%s%s%s %s%s%s%s%3llu%% %s / %s (%s%s/s)", weechat_color (str_color), (line == xfer_buffer_selected_line) ? "*** " : " ", (XFER_IS_SEND(ptr_xfer->type)) ? "<<--" : "-->>", weechat_color (weechat_config_string (xfer_config_color_status[ptr_xfer->status])), status, weechat_color (str_color), (progress_bar) ? progress_bar : "", pct_complete, (str_pos) ? str_pos : "?", (str_total) ? str_total : "?", eta, str_bytes_per_sec); if (progress_bar) free (progress_bar); if (str_pos) free (str_pos); if (str_total) free (str_total); if (str_bytes_per_sec) free (str_bytes_per_sec); } line++; } weechat_buffer_set (xfer_buffer, "hotlist", hotlist); } }
void xfer_command_xfer_list (int full) { struct t_xfer *ptr_xfer; int i; char date[128]; unsigned long long pct_complete; struct tm *date_tmp; if (xfer_list) { weechat_printf (NULL, ""); weechat_printf (NULL, _("Xfer list:")); i = 1; for (ptr_xfer = xfer_list; ptr_xfer; ptr_xfer = ptr_xfer->next_xfer) { /* xfer info */ if (XFER_IS_FILE(ptr_xfer->type)) { if (ptr_xfer->size == 0) { if (ptr_xfer->status == XFER_STATUS_DONE) pct_complete = 100; else pct_complete = 0; } else pct_complete = (unsigned long long)(((float)(ptr_xfer->pos)/(float)(ptr_xfer->size)) * 100); weechat_printf (NULL, _("%3d. %s (%s), file: \"%s\" (local: " "\"%s\"), %s %s, status: %s%s%s " "(%llu %%)"), i, xfer_type_string[ptr_xfer->type], xfer_protocol_string[ptr_xfer->protocol], ptr_xfer->filename, ptr_xfer->local_filename, (XFER_IS_SEND(ptr_xfer->type)) ? _("sent to") : _("received from"), ptr_xfer->remote_nick, weechat_color ( weechat_config_string ( xfer_config_color_status[ptr_xfer->status])), _(xfer_status_string[ptr_xfer->status]), weechat_color ("chat"), pct_complete); } else { date[0] = '\0'; date_tmp = localtime (&(ptr_xfer->start_time)); if (date_tmp) { strftime (date, sizeof (date), "%a, %d %b %Y %H:%M:%S", date_tmp); } weechat_printf (NULL, /* TRANSLATORS: "%s" after "started on" is a date */ _("%3d. %s, chat with %s (local nick: %s), " "started on %s, status: %s%s"), i, xfer_type_string[ptr_xfer->type], ptr_xfer->remote_nick, ptr_xfer->local_nick, date, weechat_color( weechat_config_string( xfer_config_color_status[ptr_xfer->status])), _(xfer_status_string[ptr_xfer->status])); } if (full) { /* second line of xfer info */ if (XFER_IS_FILE(ptr_xfer->type)) { weechat_printf (NULL, _(" plugin: %s (id: %s), file: %llu " "bytes (position: %llu), address: " "%d.%d.%d.%d (port %d)"), ptr_xfer->plugin_name, ptr_xfer->plugin_id, ptr_xfer->size, ptr_xfer->pos, ptr_xfer->address >> 24, (ptr_xfer->address >> 16) & 0xff, (ptr_xfer->address >> 8) & 0xff, ptr_xfer->address & 0xff, ptr_xfer->port); date[0] = '\0'; date_tmp = localtime (&(ptr_xfer->start_transfer)); if (date_tmp) { strftime (date, sizeof (date), "%a, %d %b %Y %H:%M:%S", date_tmp); } weechat_printf (NULL, /* TRANSLATORS: "%s" after "started on" is a date */ _(" fast_send: %s, blocksize: %d, " "started on %s"), (ptr_xfer->fast_send) ? _("yes") : _("no"), ptr_xfer->blocksize, date); } } i++; } }
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"); }
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; }
struct t_relay_raw_message * relay_raw_message_add (struct t_relay_client *client, int flags, const char *message) { char *buf, *buf2, prefix[256], prefix_arrow[16]; const unsigned char *ptr_buf; const char *hexa = "0123456789ABCDEF"; int pos_buf, pos_buf2, char_size, i; struct t_relay_raw_message *new_raw_message; buf = weechat_iconv_to_internal (NULL, message); buf2 = malloc ((strlen (buf) * 3) + 1); if (buf2) { ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message; pos_buf = 0; pos_buf2 = 0; while (ptr_buf[pos_buf]) { if (ptr_buf[pos_buf] < 32) { buf2[pos_buf2++] = '\\'; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16]; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16]; pos_buf++; } else { char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf)); for (i = 0; i < char_size; i++) { buf2[pos_buf2++] = ptr_buf[pos_buf++]; } } } buf2[pos_buf2] = '\0'; } /* build prefix with arrow */ prefix_arrow[0] = '\0'; switch (flags & (RELAY_RAW_FLAG_RECV | RELAY_RAW_FLAG_SEND)) { case RELAY_RAW_FLAG_RECV: strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV); break; case RELAY_RAW_FLAG_SEND: strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND); break; default: if (flags & RELAY_RAW_FLAG_RECV) strcpy (prefix_arrow, RELAY_RAW_PREFIX_RECV); else strcpy (prefix_arrow, RELAY_RAW_PREFIX_SEND); break; } if (client) { snprintf (prefix, sizeof (prefix), "%s[%s%d%s] %s%s%s%s %s%s", weechat_color ("chat_delimiters"), weechat_color ("chat"), client->id, weechat_color ("chat_delimiters"), weechat_color ("chat_server"), relay_protocol_string[client->protocol], (client->protocol_args) ? "." : "", (client->protocol_args) ? client->protocol_args : "", (flags & RELAY_RAW_FLAG_SEND) ? weechat_color ("chat_prefix_quit") : weechat_color ("chat_prefix_join"), prefix_arrow); } else { snprintf (prefix, sizeof (prefix), "%s%s", (flags & RELAY_RAW_FLAG_SEND) ? weechat_color ("chat_prefix_quit") : weechat_color ("chat_prefix_join"), prefix_arrow); } new_raw_message = relay_raw_message_add_to_list (time (NULL), prefix, (buf2) ? buf2 : ((buf) ? buf : message)); if (buf) free (buf); if (buf2) free (buf2); return new_raw_message; }
struct t_irc_raw_message * irc_raw_message_add (struct t_irc_server *server, int flags, const char *message) { char *buf, *buf2, prefix[256], prefix_arrow[16]; const unsigned char *ptr_buf; const char *hexa = "0123456789ABCDEF"; int pos_buf, pos_buf2, char_size, i; struct t_irc_raw_message *new_raw_message; buf = weechat_iconv_to_internal (NULL, message); buf2 = malloc ((strlen (buf) * 3) + 1); if (buf2) { ptr_buf = (buf) ? (unsigned char *)buf : (unsigned char *)message; pos_buf = 0; pos_buf2 = 0; while (ptr_buf[pos_buf]) { if (ptr_buf[pos_buf] < 32) { buf2[pos_buf2++] = '\\'; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] / 16]; buf2[pos_buf2++] = hexa[ptr_buf[pos_buf] % 16]; pos_buf++; } else { char_size = weechat_utf8_char_size ((const char *)(ptr_buf + pos_buf)); for (i = 0; i < char_size; i++) { buf2[pos_buf2++] = ptr_buf[pos_buf++]; } } } buf2[pos_buf2] = '\0'; } /* build prefix with arrow */ prefix_arrow[0] = '\0'; switch (flags & (IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED | IRC_RAW_FLAG_REDIRECT)) { case IRC_RAW_FLAG_RECV: strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV); break; case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_MODIFIED: strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_MODIFIED); break; case IRC_RAW_FLAG_RECV | IRC_RAW_FLAG_REDIRECT: strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV_REDIRECT); break; case IRC_RAW_FLAG_SEND: strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND); break; case IRC_RAW_FLAG_SEND | IRC_RAW_FLAG_MODIFIED: strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND_MODIFIED); break; default: if (flags & IRC_RAW_FLAG_RECV) strcpy (prefix_arrow, IRC_RAW_PREFIX_RECV); else strcpy (prefix_arrow, IRC_RAW_PREFIX_SEND); break; } snprintf (prefix, sizeof (prefix), "%s%s%s%s%s", (server) ? weechat_color ("chat_server") : "", (server) ? server->name : "", (server) ? " " : "", (flags & IRC_RAW_FLAG_SEND) ? weechat_color ("chat_prefix_quit") : weechat_color ("chat_prefix_join"), prefix_arrow); new_raw_message = irc_raw_message_add_to_list (time (NULL), prefix, (buf2) ? buf2 : ((buf) ? buf : message)); if (buf) free (buf); if (buf2) free (buf2); return new_raw_message; }
void exec_command_list () { struct t_exec_cmd *ptr_exec_cmd; char str_elapsed[32], str_time1[256], str_time2[256]; time_t elapsed_time; struct tm *local_time; weechat_printf (NULL, ""); if (!exec_cmds) { weechat_printf (NULL, _("No command is running")); return; } weechat_printf (NULL, _("Commands:")); for (ptr_exec_cmd = exec_cmds; ptr_exec_cmd; ptr_exec_cmd = ptr_exec_cmd->next_cmd) { elapsed_time = (ptr_exec_cmd->end_time == 0) ? time (NULL) - ptr_exec_cmd->start_time : ptr_exec_cmd->end_time - ptr_exec_cmd->start_time; if (elapsed_time >= 3600) { snprintf (str_elapsed, sizeof (str_elapsed), /* TRANSLATORS: format: hours + minutes, for example: 3h59 */ _("%dh%02d"), elapsed_time / 3600, elapsed_time % 3600); } else if (elapsed_time >= 60) { snprintf (str_elapsed, sizeof (str_elapsed), /* TRANSLATORS: format: minutes + seconds, for example: 3m59 */ _("%dm%02d"), elapsed_time / 60, elapsed_time % 60); } else { snprintf (str_elapsed, sizeof (str_elapsed), /* TRANSLATORS: format: seconds, for example: 59s */ _("%ds"), elapsed_time); } if (ptr_exec_cmd->end_time == 0) { /* running command */ weechat_printf (NULL, /* TRANSLATORS: %s before "ago" is elapsed time, for example: "3m59" */ _(" %s%s%s %d%s%s%s: %s\"%s%s%s\"%s (pid: %d, " "started %s ago)"), weechat_color (weechat_config_string (exec_config_color_flag_running)), ">>", weechat_color ("reset"), ptr_exec_cmd->number, (ptr_exec_cmd->name) ? " (" : "", (ptr_exec_cmd->name) ? ptr_exec_cmd->name : "", (ptr_exec_cmd->name) ? ")" : "", weechat_color ("chat_delimiters"), weechat_color ("reset"), ptr_exec_cmd->command, weechat_color ("chat_delimiters"), weechat_color ("reset"), ptr_exec_cmd->pid, str_elapsed); } else { /* process has ended */ local_time = localtime (&ptr_exec_cmd->start_time); strftime (str_time1, sizeof (str_time1), "%Y-%m-%d %H:%M:%S", local_time); local_time = localtime (&ptr_exec_cmd->end_time); strftime (str_time2, sizeof (str_time2), "%Y-%m-%d %H:%M:%S", local_time); weechat_printf (NULL, " %s%s%s %d%s%s%s: %s\"%s%s%s\"%s (%s -> %s, %s)", weechat_color (weechat_config_string (exec_config_color_flag_finished)), "[]", weechat_color ("reset"), ptr_exec_cmd->number, (ptr_exec_cmd->name) ? " (" : "", (ptr_exec_cmd->name) ? ptr_exec_cmd->name : "", (ptr_exec_cmd->name) ? ")" : "", weechat_color ("chat_delimiters"), weechat_color ("reset"), ptr_exec_cmd->command, weechat_color ("chat_delimiters"), weechat_color ("reset"), str_time1, str_time2, str_elapsed); } } }
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; char *result, *ptr_string, *pos_space, *ptr_end, save_end; const char *color_normal, *color_error; int buffer_has_changed, utf8_char_int, char_size; int length, index_result, length_word, word_ok; int length_color_normal, length_color_error, rc; /* make C compiler happy */ (void) data; (void) modifier; if (!aspell_enabled) return NULL; if (!string || !string[0]) return NULL; rc = sscanf (modifier_data, "%lx", &value); if ((rc == EOF) || (rc == 0)) return NULL; buffer = (struct t_gui_buffer *)value; buffer_has_changed = 0; if (buffer != aspell_buffer_spellers) { weechat_aspell_create_spellers (buffer); aspell_buffer_spellers = buffer; buffer_has_changed = 1; } if (!weechat_aspell_spellers) return NULL; /* check text 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; /* * for performance: return last string built if input string is the * same (for example user just change cursor position, or input text is * refreshed with same content) */ if (!buffer_has_changed && aspell_last_modifier_string && (strcmp (string, aspell_last_modifier_string) == 0)) { return (aspell_last_modifier_result) ? strdup (aspell_last_modifier_result) : NULL; } /* free last modifier string and result */ if (aspell_last_modifier_string) { free (aspell_last_modifier_string); aspell_last_modifier_string = NULL; } if (aspell_last_modifier_result) { free (aspell_last_modifier_result); aspell_last_modifier_result = NULL; } /* save last modifier string received */ aspell_last_modifier_string = strdup (string); color_normal = weechat_color ("bar_fg"); length_color_normal = strlen (color_normal); color_error = weechat_color (weechat_config_string (weechat_aspell_config_look_color)); length_color_error = strlen (color_error); length = strlen (string); result = malloc (length + (length * length_color_error) + 1); if (result) { result[0] = '\0'; ptr_string = aspell_last_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, aspell_last_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; } while (ptr_string[0]) { /* find start of word */ utf8_char_int = weechat_utf8_char_int (ptr_string); while ((!iswalnum (utf8_char_int) && (utf8_char_int != '\'') && (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; if (!ptr_string[0]) break; utf8_char_int = weechat_utf8_char_int (ptr_string); } if (!ptr_string[0]) break; 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 == '-')) { ptr_end = weechat_utf8_next_char (ptr_end); if (!ptr_end[0]) break; utf8_char_int = weechat_utf8_char_int (ptr_end); } 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_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; } result[index_result] = '\0'; } if (!result) return NULL; aspell_last_modifier_result = strdup (result); return result; }
void logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines) { const char *charset; struct t_logger_line *last_lines, *ptr_lines; char *pos_message, *pos_tab, *error, *message; time_t datetime, time_now; struct tm tm_line; int num_lines; charset = weechat_info_get ("charset_terminal", ""); weechat_buffer_set (buffer, "print_hooks_enabled", "0"); num_lines = 0; last_lines = logger_tail_file (filename, lines); ptr_lines = last_lines; while (ptr_lines) { datetime = 0; pos_message = strchr (ptr_lines->data, '\t'); if (pos_message) { /* initialize structure, because strptime does not do it */ memset (&tm_line, 0, sizeof (struct tm)); /* * we get current time to initialize daylight saving time in * structure tm_line, otherwise printed time will be shifted * and will not use DST used on machine */ time_now = time (NULL); localtime_r (&time_now, &tm_line); pos_message[0] = '\0'; error = strptime (ptr_lines->data, weechat_config_string (logger_config_file_time_format), &tm_line); if (error && !error[0] && (tm_line.tm_year > 0)) datetime = mktime (&tm_line); pos_message[0] = '\t'; } pos_message = (pos_message && (datetime != 0)) ? pos_message + 1 : ptr_lines->data; message = (charset) ? weechat_iconv_to_internal (charset, pos_message) : strdup (pos_message); if (message) { pos_tab = strchr (message, '\t'); if (pos_tab) pos_tab[0] = '\0'; weechat_printf_date_tags (buffer, datetime, "no_highlight,notify_none,logger_backlog", "%s%s%s%s%s", weechat_color (weechat_config_string (logger_config_color_backlog_line)), message, (pos_tab) ? "\t" : "", (pos_tab) ? weechat_color (weechat_config_string (logger_config_color_backlog_line)) : "", (pos_tab) ? pos_tab + 1 : ""); if (pos_tab) pos_tab[0] = '\t'; free (message); } num_lines++; ptr_lines = ptr_lines->next_line; } if (last_lines) logger_tail_free (last_lines); if (num_lines > 0) { weechat_printf_date_tags (buffer, datetime, "no_highlight,notify_none,logger_backlog_end", _("%s===\t%s========== End of backlog (%d lines) =========="), weechat_color (weechat_config_string (logger_config_color_backlog_end)), weechat_color (weechat_config_string (logger_config_color_backlog_end)), num_lines); weechat_buffer_set (buffer, "unread", ""); } weechat_buffer_set (buffer, "print_hooks_enabled", "1"); }
char * irc_bar_item_input_prompt (void *data, struct t_gui_bar_item *item, struct t_gui_window *window, struct t_gui_buffer *buffer, struct t_hashtable *extra_info) { struct t_irc_server *server; struct t_irc_channel *channel; struct t_irc_nick *ptr_nick; char *buf, str_prefix[64]; int length; /* make C compiler happy */ (void) data; (void) item; (void) window; (void) extra_info; if (!buffer) return NULL; irc_buffer_get_server_and_channel (buffer, &server, &channel); if (!server || !server->nick) return NULL; /* build prefix */ str_prefix[0] = '\0'; if (weechat_config_boolean (irc_config_look_item_nick_prefix) && channel && (channel->type == IRC_CHANNEL_TYPE_CHANNEL)) { ptr_nick = irc_nick_search (server, channel, server->nick); if (ptr_nick) { if (ptr_nick->prefix[0] != ' ') { snprintf (str_prefix, sizeof (str_prefix), "%s%s", weechat_color (irc_nick_get_prefix_color_name (server, ptr_nick->prefix[0])), ptr_nick->prefix); } } } /* build bar item */ length = 64 + strlen (server->nick) + 64 + ((server->nick_modes) ? strlen (server->nick_modes) : 0) + 64 + 1; buf = malloc (length); if (buf) { if (weechat_config_boolean (irc_config_look_item_nick_modes) && server->nick_modes && server->nick_modes[0]) { snprintf (buf, length, "%s%s%s%s(%s%s%s)", str_prefix, IRC_COLOR_INPUT_NICK, server->nick, IRC_COLOR_BAR_DELIM, IRC_COLOR_BAR_FG, server->nick_modes, IRC_COLOR_BAR_DELIM); } else { snprintf (buf, length, "%s%s%s", str_prefix, IRC_COLOR_INPUT_NICK, server->nick); } } return buf; }
void trigger_command_display_trigger_internal (const char *name, int enabled, const char *hook, const char *arguments, const char *conditions, int hooks_count, int hook_count_cb, int hook_count_cmd, int regex_count, struct t_trigger_regex *regex, int commands_count, char **commands, int return_code, int verbose) { char str_conditions[64], str_regex[64], str_command[64], str_rc[64]; char spaces[256]; int i, length; if (verbose >= 1) { weechat_printf_tags ( NULL, "no_trigger", " %s%s%s: %s%s%s%s%s%s%s", (enabled) ? weechat_color (weechat_config_string (trigger_config_color_trigger)) : weechat_color (weechat_config_string (trigger_config_color_trigger_disabled)), name, weechat_color ("reset"), hook, weechat_color ("chat_delimiters"), (arguments && arguments[0]) ? "(" : "", weechat_color ("reset"), arguments, weechat_color ("chat_delimiters"), (arguments && arguments[0]) ? ")" : ""); length = weechat_strlen_screen (name) + 3; if (length >= (int)sizeof (spaces)) length = sizeof (spaces) - 1; memset (spaces, ' ', length); spaces[length] = '\0'; if (verbose >= 2) { weechat_printf_tags (NULL, "no_trigger", "%s hooks: %d", spaces, hooks_count); weechat_printf_tags (NULL, "no_trigger", "%s callback: %d", spaces, hook_count_cb); weechat_printf_tags (NULL, "no_trigger", "%s commands: %d", spaces, hook_count_cmd); } if (conditions && conditions[0]) { weechat_printf_tags (NULL, "no_trigger", "%s %s=? %s\"%s%s%s\"", spaces, weechat_color (weechat_config_string (trigger_config_color_flag_conditions)), weechat_color ("chat_delimiters"), weechat_color ("reset"), conditions, weechat_color ("chat_delimiters")); } for (i = 0; i < regex_count; i++) { weechat_printf_tags (NULL, "no_trigger", "%s %s~%d %s\"%s%s%s\" --> " "\"%s%s%s\"%s%s%s%s", spaces, weechat_color (weechat_config_string (trigger_config_color_flag_regex)), i + 1, weechat_color ("chat_delimiters"), weechat_color (weechat_config_string (trigger_config_color_regex)), regex[i].str_regex, weechat_color ("chat_delimiters"), weechat_color (weechat_config_string (trigger_config_color_replace)), regex[i].replace, weechat_color ("chat_delimiters"), weechat_color ("reset"), (regex[i].variable) ? " (" : "", (regex[i].variable) ? regex[i].variable : "", (regex[i].variable) ? ")" : ""); } if (commands) { for (i = 0; commands[i]; i++) { weechat_printf_tags (NULL, "no_trigger", "%s %s/%d %s\"%s%s%s\"", spaces, weechat_color (weechat_config_string (trigger_config_color_flag_command)), i + 1, weechat_color ("chat_delimiters"), weechat_color ("reset"), commands[i], weechat_color ("chat_delimiters")); } } if ((return_code >= 0) && (return_code != TRIGGER_RC_OK)) { weechat_printf_tags (NULL, "no_trigger", "%s %s=> %s%s", spaces, weechat_color (weechat_config_string (trigger_config_color_flag_return_code)), weechat_color ("reset"), trigger_return_code_string[return_code]); } } else { str_conditions[0] ='\0'; str_regex[0] = '\0'; str_command[0] = '\0'; str_rc[0] = '\0'; if (conditions && conditions[0]) { snprintf (str_conditions, sizeof (str_conditions), " %s=?%s", weechat_color (weechat_config_string (trigger_config_color_flag_conditions)), weechat_color ("reset")); } if (regex_count > 0) { snprintf (str_regex, sizeof (str_regex), " %s~%d%s", weechat_color (weechat_config_string (trigger_config_color_flag_regex)), regex_count, weechat_color ("reset")); } if (commands_count > 0) { snprintf (str_command, sizeof (str_command), " %s/%d%s", weechat_color (weechat_config_string (trigger_config_color_flag_command)), commands_count, weechat_color ("reset")); } if ((return_code >= 0) && (return_code != TRIGGER_RC_OK)) { snprintf (str_rc, sizeof (str_rc), " %s=>%s", weechat_color (weechat_config_string (trigger_config_color_flag_return_code)), weechat_color ("reset")); } weechat_printf_tags ( NULL, "no_trigger", " %s%s%s: %s%s%s%s%s%s%s%s%s%s%s%s", (enabled) ? weechat_color (weechat_config_string (trigger_config_color_trigger)) : weechat_color (weechat_config_string (trigger_config_color_trigger_disabled)), name, weechat_color ("reset"), hook, weechat_color ("chat_delimiters"), (arguments && arguments[0]) ? "(" : "", weechat_color ("reset"), arguments, weechat_color ("chat_delimiters"), (arguments && arguments[0]) ? ")" : "", weechat_color ("reset"), str_conditions, str_regex, str_command, str_rc); } }
int xfer_chat_recv_cb (void *arg_xfer, int fd) { struct t_xfer *xfer; static char buffer[4096 + 2]; char *buf2, *pos, *ptr_buf, *ptr_buf2, *next_ptr_buf; char *ptr_buf_decoded, *ptr_buf_without_weechat_colors, *ptr_buf_color; char str_tags[256], *str_color; const char *pv_tags; int num_read, length, ctcp_action; /* make C compiler happy */ (void) fd; xfer = (struct t_xfer *)arg_xfer; num_read = recv (xfer->sock, buffer, sizeof (buffer) - 2, 0); if (num_read > 0) { buffer[num_read] = '\0'; buf2 = NULL; ptr_buf = buffer; if (xfer->unterminated_message) { buf2 = malloc (strlen (xfer->unterminated_message) + strlen (buffer) + 1); if (buf2) { strcpy (buf2, xfer->unterminated_message); strcat (buf2, buffer); } ptr_buf = buf2; free (xfer->unterminated_message); xfer->unterminated_message = NULL; } while (ptr_buf && ptr_buf[0]) { next_ptr_buf = NULL; pos = strstr (ptr_buf, "\n"); if (pos) { pos[0] = '\0'; next_ptr_buf = pos + 1; } else { xfer->unterminated_message = strdup (ptr_buf); ptr_buf = NULL; next_ptr_buf = NULL; } if (ptr_buf) { ctcp_action = 0; length = strlen (ptr_buf); if (ptr_buf[length - 1] == '\r') { ptr_buf[length - 1] = '\0'; length--; } if ((ptr_buf[0] == '\01') && (ptr_buf[length - 1] == '\01')) { ptr_buf[length - 1] = '\0'; ptr_buf++; if (strncmp (ptr_buf, "ACTION ", 7) == 0) { ptr_buf += 7; ctcp_action = 1; } } ptr_buf_decoded = (xfer->charset_modifier) ? weechat_hook_modifier_exec ("charset_decode", xfer->charset_modifier, ptr_buf) : NULL; ptr_buf_without_weechat_colors = weechat_string_remove_color ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf, "?"); ptr_buf_color = weechat_hook_modifier_exec ("irc_color_decode", "1", (ptr_buf_without_weechat_colors) ? ptr_buf_without_weechat_colors : ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf)); ptr_buf2 = (ptr_buf_color) ? ptr_buf_color : ((ptr_buf_without_weechat_colors) ? ptr_buf_without_weechat_colors : ((ptr_buf_decoded) ? ptr_buf_decoded : ptr_buf)); pv_tags = weechat_config_string (xfer_config_look_pv_tags); if (ctcp_action) { snprintf (str_tags, sizeof (str_tags), "irc_privmsg,irc_action,%s%snick_%s,log1", (pv_tags && pv_tags[0]) ? pv_tags : "", (pv_tags && pv_tags[0]) ? "," : "", xfer->remote_nick); weechat_printf_tags (xfer->buffer, str_tags, "%s%s%s%s%s%s", weechat_prefix ("action"), weechat_color ((xfer->remote_nick_color) ? xfer->remote_nick_color : "chat_nick_other"), xfer->remote_nick, weechat_color ("chat"), (ptr_buf2[0]) ? " " : "", ptr_buf2); } else { str_color = xfer_chat_color_for_tags ( (xfer->remote_nick_color) ? xfer->remote_nick_color : weechat_config_color (weechat_config_get ("weechat.color.chat_nick_other"))); snprintf (str_tags, sizeof (str_tags), "irc_privmsg,%s%sprefix_nick_%s,nick_%s,log1", (pv_tags && pv_tags[0]) ? pv_tags : "", (pv_tags && pv_tags[0]) ? "," : "", (str_color) ? str_color : "default", xfer->remote_nick); if (str_color) free (str_color); weechat_printf_tags (xfer->buffer, str_tags, "%s%s\t%s", weechat_color ((xfer->remote_nick_color) ? xfer->remote_nick_color : "chat_nick_other"), xfer->remote_nick, ptr_buf2); } if (ptr_buf_decoded) free (ptr_buf_decoded); if (ptr_buf_without_weechat_colors) free (ptr_buf_without_weechat_colors); if (ptr_buf_color) free (ptr_buf_color); } ptr_buf = next_ptr_buf; } if (buf2) free (buf2); } else { xfer_close (xfer, XFER_STATUS_ABORTED); xfer_buffer_refresh (WEECHAT_HOTLIST_MESSAGE); } return WEECHAT_RC_OK; }
void script_buffer_display_detail_script (struct t_script_repo *script) { struct tm *tm; char str_time[1024]; char *labels[] = { N_("Script"), N_("Version"), N_("Version loaded"), N_("Author"), N_("License"), N_("Description"), N_("Tags"), N_("Status"), N_("Date added"), N_("Date updated"), N_("URL"), N_("MD5"), N_("Requires"), N_("Min WeeChat"), N_("Max WeeChat"), NULL }; int i, length, max_length, line; struct t_weelist *list; struct t_weelist_item *ptr_item; max_length = 0; for (i = 0; labels[i]; i++) { length = weechat_utf8_strlen_screen (_(labels[i])); if (length > max_length) max_length = length; } line = 0; weechat_printf_y (script_buffer, line + 1, "%s: %s%s%s.%s", script_buffer_detail_label (_(labels[line]), max_length), weechat_color (weechat_config_string (script_config_color_text_name)), script->name, weechat_color (weechat_config_string (script_config_color_text_extension)), script_extension[script->language]); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s%s", script_buffer_detail_label (_(labels[line]), max_length), weechat_color (weechat_config_string (script_config_color_text_version)), script->version); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s%s", script_buffer_detail_label (_(labels[line]), max_length), weechat_color (weechat_config_string (script_config_color_text_version_loaded)), (script->version_loaded) ? script->version_loaded : "-"); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s <%s>", script_buffer_detail_label (_(labels[line]), max_length), script->author, script->mail); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->license); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->description); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->tags); line++; if ((script->popularity == 0) && (script->status == 0)) { weechat_printf_y (script_buffer, line + 1, "%s: -", script_buffer_detail_label (_(labels[line]), max_length)); } else { weechat_printf_y (script_buffer, line + 1, "%s: %s%s (%s)", script_buffer_detail_label (_(labels[line]), max_length), script_repo_get_status_for_display (script, "*iaHrN", 1), weechat_color ("chat"), script_repo_get_status_desc_for_display (script, "*iaHrN")); } line++; tm = localtime (&script->date_added); strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm); weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), str_time); line++; tm = localtime (&script->date_updated); strftime (str_time, sizeof (str_time), "%Y-%m-%d %H:%M:%S", tm); weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), str_time); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->url); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), script->md5sum); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), (script->requirements) ? script->requirements : "-"); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), (script->min_weechat) ? script->min_weechat : "-"); line++; weechat_printf_y (script_buffer, line + 1, "%s: %s", script_buffer_detail_label (_(labels[line]), max_length), (script->max_weechat) ? script->max_weechat : "-"); line++; if (script->status & SCRIPT_STATUS_RUNNING) { list = script_buffer_get_script_usage (script); if (list) { line++; weechat_printf_y (script_buffer, line + 1, _("Script has defined:")); i = 0; ptr_item = weechat_list_get (list, 0); while (ptr_item) { line++; weechat_printf_y (script_buffer, line + 1, " %s", weechat_list_string (ptr_item)); ptr_item = weechat_list_next (ptr_item); i++; } if (i == 0) { line++; weechat_printf_y (script_buffer, line + 1, " %s", _("(nothing)")); } line++; weechat_list_free (list); } } script_buffer_detail_script_last_line = line + 2; script_buffer_detail_script_line_diff = -1; }
char * weechat_aspell_bar_item_suggest (void *data, struct t_gui_bar_item *item, struct t_gui_window *window, struct t_gui_buffer *buffer, struct t_hashtable *extra_info) { const char *ptr_suggestions, *pos; char **suggestions, *suggestions2; int i, num_suggestions, length; /* make C compiler happy */ (void) data; (void) item; (void) window; (void) extra_info; if (!aspell_enabled) return NULL; if (!buffer) return NULL; ptr_suggestions = weechat_buffer_get_string (buffer, "localvar_aspell_suggest"); if (!ptr_suggestions) return NULL; pos = strchr (ptr_suggestions, ':'); if (pos) pos++; else pos = ptr_suggestions; suggestions = weechat_string_split (pos, "/", 0, 0, &num_suggestions); if (suggestions) { length = 64 + 1; for (i = 0; i < num_suggestions; i++) { length += strlen (suggestions[i]) + 64; } suggestions2 = malloc (length); if (suggestions2) { suggestions2[0] = '\0'; strcat (suggestions2, weechat_color (weechat_config_string (weechat_aspell_config_color_suggestions))); for (i = 0; i < num_suggestions; i++) { if (i > 0) { strcat (suggestions2, weechat_color ("bar_delim")); strcat (suggestions2, "/"); strcat (suggestions2, weechat_color (weechat_config_string (weechat_aspell_config_color_suggestions))); } strcat (suggestions2, suggestions[i]); } weechat_string_free_split (suggestions); return suggestions2; } weechat_string_free_split (suggestions); } return strdup (pos); }