void gui_input_text_changed_modifier_and_signal (struct t_gui_buffer *buffer) { char str_buffer[128], *new_input; /* send modifier, and change input if needed */ snprintf (str_buffer, sizeof (str_buffer), "0x%lx", (long unsigned int)buffer); new_input = hook_modifier_exec (NULL, "input_text_content", str_buffer, (buffer->input_buffer) ? buffer->input_buffer : ""); if (new_input) { if (strcmp (new_input, buffer->input_buffer) != 0) { /* input has been changed by modifier, use it */ gui_input_replace_input (buffer, new_input); } free (new_input); } /* send signal */ hook_signal_send ("input_text_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL); }
void gui_history_add (struct t_gui_buffer *buffer, const char *string) { char *string2, str_buffer[128]; snprintf (str_buffer, sizeof (str_buffer), "0x%lx", (long unsigned int)(buffer)); string2 = hook_modifier_exec (NULL, "history_add", str_buffer, string); /* * if message was NOT dropped by modifier, then we add it to buffer and * global history */ if (!string2 || string2[0]) { gui_history_buffer_add (buffer, (string2) ? string2 : string); gui_history_global_add ((string2) ? string2 : string); } if (string2) free (string2); }
void gui_chat_printf_date_tags (struct t_gui_buffer *buffer, time_t date, const char *tags, const char *message, ...) { time_t date_printed; int display_time, length, at_least_one_message_printed, msg_discarded; char *pos, *pos_prefix, *pos_tab, *pos_end, *pos_lines; char *modifier_data, *new_msg, *ptr_msg, *lines_waiting; struct t_gui_line *ptr_line; if (!message) return; if (!gui_buffer_valid (buffer)) return; if (gui_init_ok) { if (!buffer) buffer = gui_buffer_search_main (); if (!buffer || buffer->closing) return; if (buffer->type != GUI_BUFFER_TYPE_FORMATTED) buffer = gui_buffers; if (buffer->type != GUI_BUFFER_TYPE_FORMATTED) return; } /* if mute is enabled for buffer (or all buffers), then just return */ if ((gui_chat_mute == GUI_CHAT_MUTE_ALL_BUFFERS) || ((gui_chat_mute == GUI_CHAT_MUTE_BUFFER) && (gui_chat_mute_buffer == buffer))) return; weechat_va_format (message); if (!vbuffer) return; utf8_normalize (vbuffer, '?'); date_printed = time (NULL); if (date <= 0) date = date_printed; at_least_one_message_printed = 0; pos = vbuffer; while (pos) { /* display until next end of line */ pos_end = strchr (pos, '\n'); if (pos_end) pos_end[0] = '\0'; /* call modifier for message printed ("weechat_print") */ new_msg = NULL; msg_discarded = 0; if (buffer) { length = strlen (gui_buffer_get_plugin_name (buffer)) + 1 + strlen (buffer->name) + 1 + ((tags) ? strlen (tags) : 0) + 1; modifier_data = malloc (length); if (modifier_data) { snprintf (modifier_data, length, "%s;%s;%s", gui_buffer_get_plugin_name (buffer), buffer->name, (tags) ? tags : ""); new_msg = hook_modifier_exec (NULL, "weechat_print", modifier_data, pos); free (modifier_data); if (new_msg) { if (!new_msg[0] && pos[0]) { /* * modifier returned empty message, then we'll not * print anything */ free (new_msg); new_msg = NULL; msg_discarded = 1; } else if (strcmp (message, new_msg) == 0) { /* no changes in new message */ free (new_msg); new_msg = NULL; } } } } if (!msg_discarded) { pos_prefix = NULL; display_time = 1; ptr_msg = (new_msg) ? new_msg : pos; /* space followed by tab => prefix ignored */ if ((ptr_msg[0] == ' ') && (ptr_msg[1] == '\t')) { ptr_msg += 2; } else { /* if two first chars are tab, then do not display time */ if ((ptr_msg[0] == '\t') && (ptr_msg[1] == '\t')) { display_time = 0; ptr_msg += 2; } else { /* if tab found, use prefix (before tab) */ pos_tab = strchr (ptr_msg, '\t'); if (pos_tab) { pos_tab[0] = '\0'; pos_prefix = ptr_msg; ptr_msg = pos_tab + 1; } } } if (gui_init_ok) { ptr_line = gui_line_add (buffer, (display_time) ? date : 0, date_printed, tags, pos_prefix, ptr_msg); if (ptr_line) { if (buffer && buffer->print_hooks_enabled) hook_print_exec (buffer, ptr_line); if (ptr_line->data->displayed) at_least_one_message_printed = 1; } } else { length = ((pos_prefix) ? strlen (pos_prefix) + 1 : 0) + strlen (ptr_msg) + 1; if (gui_chat_lines_waiting_buffer) { length += strlen (gui_chat_lines_waiting_buffer) + 1; lines_waiting = realloc (gui_chat_lines_waiting_buffer, length); if (lines_waiting) { gui_chat_lines_waiting_buffer = lines_waiting; } else { free (gui_chat_lines_waiting_buffer); gui_chat_lines_waiting_buffer = NULL; } } else { gui_chat_lines_waiting_buffer = malloc (length); if (gui_chat_lines_waiting_buffer) gui_chat_lines_waiting_buffer[0] = '\0'; } if (gui_chat_lines_waiting_buffer) { pos_lines = gui_chat_lines_waiting_buffer + strlen (gui_chat_lines_waiting_buffer); if (pos_lines > gui_chat_lines_waiting_buffer) { pos_lines[0] = '\n'; pos_lines++; } if (pos_prefix) { memcpy (pos_lines, pos_prefix, strlen (pos_prefix)); pos_lines += strlen (pos_prefix); pos_lines[0] = '\t'; pos_lines++; } memcpy (pos_lines, ptr_msg, strlen (ptr_msg) + 1); } } } if (new_msg) free (new_msg); pos = (pos_end && pos_end[1]) ? pos_end + 1 : NULL; } if (gui_init_ok && at_least_one_message_printed) gui_buffer_ask_chat_refresh (buffer, 1); free (vbuffer); }
int input_data (struct t_gui_buffer *buffer, const char *data) { char *pos, *buf, str_buffer[128], *new_data, *buffer_full_name; const char *ptr_data, *ptr_data_for_buffer; int length, char_size, first_command, rc; rc = WEECHAT_RC_OK; if (!buffer || !gui_buffer_valid (buffer) || !data || !data[0] || (data[0] == '\r') || (data[0] == '\n')) { return WEECHAT_RC_ERROR; } buffer_full_name = strdup (buffer->full_name); if (!buffer_full_name) return WEECHAT_RC_ERROR; /* execute modifier "input_text_for_buffer" */ snprintf (str_buffer, sizeof (str_buffer), "0x%lx", (long unsigned int)buffer); new_data = hook_modifier_exec (NULL, "input_text_for_buffer", str_buffer, data); /* data was dropped? */ if (new_data && !new_data[0]) goto end; first_command = 1; ptr_data = (new_data) ? new_data : data; while (ptr_data && ptr_data[0]) { /* * if the buffer pointer is not valid any more (or if it's another * buffer), use the current buffer for the next command */ if (!first_command && (!gui_buffer_valid (buffer) || (strcmp (buffer->full_name, buffer_full_name) != 0))) { if (!gui_current_window || !gui_current_window->buffer) break; buffer = gui_current_window->buffer; free (buffer_full_name); buffer_full_name = strdup (buffer->full_name); if (!buffer_full_name) break; } pos = strchr (ptr_data, '\n'); if (pos) pos[0] = '\0'; ptr_data_for_buffer = string_input_for_buffer (ptr_data); if (ptr_data_for_buffer) { /* * input string is NOT a command, send it to buffer input * callback */ if (string_is_command_char (ptr_data_for_buffer)) { char_size = utf8_char_size (ptr_data_for_buffer); length = strlen (ptr_data_for_buffer) + char_size + 1; buf = malloc (length); if (buf) { memcpy (buf, ptr_data_for_buffer, char_size); snprintf (buf + char_size, length - char_size, "%s", ptr_data_for_buffer); input_exec_data (buffer, buf); free (buf); } } else input_exec_data (buffer, ptr_data_for_buffer); } else { /* input string is a command */ rc = input_exec_command (buffer, 1, buffer->plugin, ptr_data); } if (pos) { pos[0] = '\n'; ptr_data = pos + 1; } else ptr_data = NULL; first_command = 0; } end: if (new_data) free (new_data); if (buffer_full_name) free (buffer_full_name); return rc; }
void gui_chat_printf_date_tags (struct t_gui_buffer *buffer, time_t date, const char *tags, const char *message, ...) { va_list argptr; time_t date_printed; int display_time, length, at_least_one_message_printed; char *pos, *pos_prefix, *pos_tab, *pos_end; char *modifier_data, *new_msg, *ptr_msg; struct t_gui_line *ptr_line; if (!gui_buffer_valid (buffer)) return; if (!message) return; if (gui_init_ok) { if (!buffer) buffer = gui_buffer_search_main (); if (!buffer) return; if (buffer->type != GUI_BUFFER_TYPE_FORMATTED) buffer = gui_buffers; if (buffer->type != GUI_BUFFER_TYPE_FORMATTED) return; } if (!gui_chat_buffer) gui_chat_buffer = malloc (GUI_CHAT_BUFFER_PRINTF_SIZE); if (!gui_chat_buffer) return; va_start (argptr, message); vsnprintf (gui_chat_buffer, GUI_CHAT_BUFFER_PRINTF_SIZE, message, argptr); va_end (argptr); utf8_normalize (gui_chat_buffer, '?'); date_printed = time (NULL); if (date <= 0) date = date_printed; at_least_one_message_printed = 0; pos = gui_chat_buffer; while (pos) { /* display until next end of line */ pos_end = strchr (pos, '\n'); if (pos_end) pos_end[0] = '\0'; /* call modifier for message printed ("weechat_print") */ new_msg = NULL; if (buffer) { length = strlen (plugin_get_name (buffer->plugin)) + 1 + strlen (buffer->name) + 1 + ((tags) ? strlen (tags) : 0) + 1; modifier_data = malloc (length); if (modifier_data) { snprintf (modifier_data, length, "%s;%s;%s", plugin_get_name (buffer->plugin), buffer->name, (tags) ? tags : ""); new_msg = hook_modifier_exec (NULL, "weechat_print", modifier_data, pos); /* no changes in new message */ if (new_msg && (strcmp (message, new_msg) == 0)) { free (new_msg); new_msg = NULL; } free (modifier_data); } } pos_prefix = NULL; display_time = 1; ptr_msg = (new_msg) ? new_msg : pos; /* space followed by tab => prefix ignored */ if ((ptr_msg[0] == ' ') && (ptr_msg[1] == '\t')) { ptr_msg += 2; } else { /* if two first chars are tab, then do not display time */ if ((ptr_msg[0] == '\t') && (ptr_msg[1] == '\t')) { display_time = 0; ptr_msg += 2; } else { /* if tab found, use prefix (before tab) */ pos_tab = strchr (ptr_msg, '\t'); if (pos_tab) { pos_tab[0] = '\0'; pos_prefix = ptr_msg; ptr_msg = pos_tab + 1; } } } if (gui_init_ok) { ptr_line = gui_line_add (buffer, (display_time) ? date : 0, (display_time) ? date_printed : 0, tags, pos_prefix, ptr_msg); if (ptr_line) { if (buffer->print_hooks_enabled) hook_print_exec (buffer, ptr_line); if (ptr_line->data->displayed) at_least_one_message_printed = 1; } } else { if (pos_prefix) string_iconv_fprintf (stdout, "%s ", pos_prefix); string_iconv_fprintf (stdout, "%s\n", ptr_msg); } if (new_msg) free (new_msg); pos = (pos_end && pos_end[1]) ? pos_end + 1 : NULL; } if (gui_init_ok && at_least_one_message_printed) gui_buffer_ask_chat_refresh (buffer, 1); }
void input_data (struct t_gui_buffer *buffer, const char *data) { char *pos, *buf, str_buffer[128], *new_data; const char *ptr_data, *ptr_data_for_buffer; int length, char_size; if (!buffer || !data || !data[0] || (data[0] == '\r') || (data[0] == '\n')) return; /* execute modifier "input_text_for_buffer" */ snprintf (str_buffer, sizeof (str_buffer), "0x%lx", (long unsigned int)buffer); new_data = hook_modifier_exec (NULL, "input_text_for_buffer", str_buffer, data); /* data not dropped? */ if (!new_data || new_data[0]) { ptr_data = (new_data) ? new_data : data; while (ptr_data && ptr_data[0]) { pos = strchr (ptr_data, '\n'); if (pos) pos[0] = '\0'; ptr_data_for_buffer = string_input_for_buffer (ptr_data); if (ptr_data_for_buffer) { /* * input string is NOT a command, send it to buffer input * callback */ if (string_is_command_char (ptr_data_for_buffer)) { char_size = utf8_char_size (ptr_data_for_buffer); length = strlen (ptr_data_for_buffer) + char_size + 1; buf = malloc (length); if (buf) { memcpy (buf, ptr_data_for_buffer, char_size); snprintf (buf + char_size, length - char_size, "%s", ptr_data_for_buffer); input_exec_data (buffer, buf); free (buf); } } else input_exec_data (buffer, ptr_data_for_buffer); } else { /* input string is a command */ input_exec_command (buffer, 1, buffer->plugin, ptr_data); } if (pos) { pos[0] = '\n'; ptr_data = pos + 1; } else ptr_data = NULL; } } if (new_data) free (new_data); }