void upgrade_weechat_read_buffer_line (struct t_infolist *infolist) { struct t_gui_line *new_line; if (!upgrade_current_buffer) return; switch (upgrade_current_buffer->type) { case GUI_BUFFER_TYPE_FORMATTED: new_line = gui_line_add (upgrade_current_buffer, infolist_time (infolist, "date"), infolist_time (infolist, "date_printed"), infolist_string (infolist, "tags"), infolist_string (infolist, "prefix"), infolist_string (infolist, "message")); if (new_line) { new_line->data->highlight = infolist_integer (infolist, "highlight"); if (infolist_integer (infolist, "last_read_line")) upgrade_current_buffer->lines->last_read_line = new_line; } break; case GUI_BUFFER_TYPE_FREE: gui_line_add_y (upgrade_current_buffer, infolist_integer (infolist, "y"), infolist_string (infolist, "message")); break; case GUI_BUFFER_NUM_TYPES: break; } }
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 upgrade_weechat_read_cb (void *data, struct t_upgrade_file *upgrade_file, int object_id, struct t_infolist *infolist) { const char *key, *var_name, *type, *name, *group_name, *plugin_name; const char *buffer_name; char option_name[64], *option_key, *option_var; struct t_gui_nick_group *ptr_group; struct t_gui_buffer *ptr_buffer; struct t_gui_line *new_line; struct t_gui_hotlist *new_hotlist; struct timeval creation_time; void *buf; int i, size, index, length; /* make C compiler happy */ (void) data; (void) upgrade_file; infolist_reset_item_cursor (infolist); while (infolist_next (infolist)) { switch (object_id) { case UPGRADE_WEECHAT_TYPE_HISTORY: if (upgrade_current_buffer) { gui_history_buffer_add (upgrade_current_buffer, infolist_string (infolist, "text")); } else { gui_history_global_add (infolist_string (infolist, "text")); } break; case UPGRADE_WEECHAT_TYPE_BUFFER: plugin_name = infolist_string (infolist, "plugin_name"); name = infolist_string (infolist, "name"); gui_layout_buffer_add (&upgrade_layout_buffers, &last_upgrade_layout_buffer, plugin_name, name, infolist_integer (infolist, "number")); if (gui_buffer_is_main (plugin_name, name)) { /* use WeeChat main buffer */ upgrade_current_buffer = gui_buffers; } else { /* * create buffer if it was created by a plugin (ie not * WeeChat main buffer) */ upgrade_current_buffer = gui_buffer_new ( NULL, infolist_string (infolist, "name"), NULL, NULL, NULL, NULL); if (upgrade_current_buffer) { if (infolist_integer (infolist, "current_buffer")) upgrade_set_current_buffer = upgrade_current_buffer; upgrade_current_buffer->plugin_name_for_upgrade = strdup (infolist_string (infolist, "plugin_name")); gui_buffer_build_full_name (upgrade_current_buffer); upgrade_current_buffer->short_name = (infolist_string (infolist, "short_name")) ? strdup (infolist_string (infolist, "short_name")) : NULL; upgrade_current_buffer->type = infolist_integer (infolist, "type"); upgrade_current_buffer->notify = infolist_integer (infolist, "notify"); upgrade_current_buffer->nicklist_case_sensitive = infolist_integer (infolist, "nicklist_case_sensitive"); upgrade_current_buffer->nicklist_display_groups = infolist_integer (infolist, "nicklist_display_groups"); upgrade_current_buffer->title = (infolist_string (infolist, "title")) ? strdup (infolist_string (infolist, "title")) : NULL; upgrade_current_buffer->lines->first_line_not_read = infolist_integer (infolist, "first_line_not_read"); upgrade_current_buffer->time_for_each_line = infolist_integer (infolist, "time_for_each_line"); upgrade_current_buffer->input = infolist_integer (infolist, "input"); upgrade_current_buffer->input_get_unknown_commands = infolist_integer (infolist, "input_get_unknown_commands"); if (infolist_integer (infolist, "input_buffer_alloc") > 0) { upgrade_current_buffer->input_buffer = malloc (infolist_integer (infolist, "input_buffer_alloc")); if (upgrade_current_buffer->input_buffer) { upgrade_current_buffer->input_buffer_size = infolist_integer (infolist, "input_buffer_size"); upgrade_current_buffer->input_buffer_length = infolist_integer (infolist, "input_buffer_length"); upgrade_current_buffer->input_buffer_pos = infolist_integer (infolist, "input_buffer_pos"); upgrade_current_buffer->input_buffer_1st_display = infolist_integer (infolist, "input_buffer_1st_display"); if (infolist_string (infolist, "input_buffer")) strcpy (upgrade_current_buffer->input_buffer, infolist_string (infolist, "input_buffer")); else upgrade_current_buffer->input_buffer[0] = '\0'; } } upgrade_current_buffer->text_search = infolist_integer (infolist, "text_search"); upgrade_current_buffer->text_search_exact = infolist_integer (infolist, "text_search_exact"); upgrade_current_buffer->text_search_found = infolist_integer (infolist, "text_search_found"); if (infolist_string (infolist, "text_search_input")) upgrade_current_buffer->text_search_input = strdup (infolist_string (infolist, "text_search_input")); gui_buffer_set_highlight_words (upgrade_current_buffer, infolist_string (infolist, "highlight_words")); gui_buffer_set_highlight_regex (upgrade_current_buffer, infolist_string (infolist, "highlight_regex")); gui_buffer_set_highlight_tags (upgrade_current_buffer, infolist_string (infolist, "highlight_tags")); gui_buffer_set_hotlist_max_level_nicks (upgrade_current_buffer, infolist_string (infolist, "hotlist_max_level_nicks")); index = 0; while (1) { snprintf (option_name, sizeof (option_name), "key_%05d", index); key = infolist_string (infolist, option_name); if (!key) break; length = 16 + strlen (key) + 1; option_key = malloc (length); if (option_key) { snprintf (option_key, length, "key_bind_%s", key); snprintf (option_name, sizeof (option_name), "key_command_%05d", index); gui_buffer_set (upgrade_current_buffer, option_key, infolist_string (infolist, option_name)); free (option_key); } index++; } index = 0; while (1) { snprintf (option_name, sizeof (option_name), "localvar_name_%05d", index); var_name = infolist_string (infolist, option_name); if (!var_name) break; length = 32 + strlen (var_name) + 1; option_var = malloc (length); if (option_var) { snprintf (option_var, length, "localvar_set_%s", var_name); snprintf (option_name, sizeof (option_name), "localvar_value_%05d", index); gui_buffer_set (upgrade_current_buffer, option_var, infolist_string (infolist, option_name)); free (option_var); } index++; } } } break; case UPGRADE_WEECHAT_TYPE_BUFFER_LINE: /* add line to current buffer */ if (upgrade_current_buffer) { switch (upgrade_current_buffer->type) { case GUI_BUFFER_TYPE_FORMATTED: new_line = gui_line_add ( upgrade_current_buffer, infolist_time (infolist, "date"), infolist_time (infolist, "date_printed"), infolist_string (infolist, "tags"), infolist_string (infolist, "prefix"), infolist_string (infolist, "message")); if (new_line) { new_line->data->highlight = infolist_integer (infolist, "highlight"); if (infolist_integer (infolist, "last_read_line")) upgrade_current_buffer->lines->last_read_line = new_line; } break; case GUI_BUFFER_TYPE_FREE: gui_line_add_y ( upgrade_current_buffer, infolist_integer (infolist, "y"), infolist_string (infolist, "message")); break; case GUI_BUFFER_NUM_TYPES: break; } } break; case UPGRADE_WEECHAT_TYPE_NICKLIST: if (upgrade_current_buffer) { upgrade_current_buffer->nicklist = 1; ptr_group = NULL; type = infolist_string (infolist, "type"); if (type) { if (strcmp (type, "group") == 0) { name = infolist_string (infolist, "name"); if (name && (strcmp (name, "root") != 0)) { group_name = infolist_string (infolist, "parent_name"); if (group_name) ptr_group = gui_nicklist_search_group (upgrade_current_buffer, NULL, group_name); gui_nicklist_add_group ( upgrade_current_buffer, ptr_group, name, infolist_string (infolist, "color"), infolist_integer (infolist, "visible")); } } else if (strcmp (type, "nick") == 0) { group_name = infolist_string (infolist, "group_name"); if (group_name) ptr_group = gui_nicklist_search_group (upgrade_current_buffer, NULL, group_name); gui_nicklist_add_nick ( upgrade_current_buffer, ptr_group, infolist_string (infolist, "name"), infolist_string (infolist, "color"), infolist_string (infolist, "prefix"), infolist_string (infolist, "prefix_color"), infolist_integer (infolist, "visible")); } } } break; case UPGRADE_WEECHAT_TYPE_MISC: weechat_first_start_time = infolist_time (infolist, "start_time"); weechat_upgrade_count = infolist_integer (infolist, "upgrade_count"); upgrade_set_current_window = infolist_integer (infolist, "current_window_number"); break; case UPGRADE_WEECHAT_TYPE_HOTLIST: if (!hotlist_reset) { gui_hotlist_clear (); hotlist_reset = 1; } plugin_name = infolist_string (infolist, "plugin_name"); buffer_name = infolist_string (infolist, "buffer_name"); if (plugin_name && buffer_name) { ptr_buffer = gui_buffer_search_by_name (plugin_name, buffer_name); if (ptr_buffer) { buf = infolist_buffer (infolist, "creation_time", &size); if (buf) { memcpy (&creation_time, buf, size); new_hotlist = gui_hotlist_add (ptr_buffer, infolist_integer (infolist, "priority"), &creation_time); if (new_hotlist) { for (i = 0; i < GUI_HOTLIST_NUM_PRIORITIES; i++) { snprintf (option_name, sizeof (option_name), "count_%02d", i); new_hotlist->count[i] = infolist_integer (infolist, option_name); } } } } } break; case UPGRADE_WEECHAT_TYPE_LAYOUT_WINDOW: gui_layout_window_add (&upgrade_layout_windows, infolist_integer (infolist, "internal_id"), gui_layout_window_search_by_id (upgrade_layout_windows, infolist_integer (infolist, "parent_id")), infolist_integer (infolist, "split_pct"), infolist_integer (infolist, "split_horiz"), infolist_string (infolist, "plugin_name"), infolist_string (infolist, "buffer_name")); break; } } return WEECHAT_RC_OK; }
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); }