TEST(Utf8, Normalize) { char *str; str = strdup (noel_invalid); utf8_normalize (NULL, '?'); utf8_normalize (str, '?'); STRCMP_EQUAL(noel_invalid_norm, str); free (str); str = strdup (noel_invalid2); utf8_normalize (str, '?'); STRCMP_EQUAL(noel_invalid2_norm, str); free (str); }
void gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...) { va_list argptr; struct t_gui_line *ptr_line; if (gui_init_ok) { if (!buffer) buffer = gui_buffer_search_main (); if (buffer->type != GUI_BUFFER_TYPE_FREE) buffer = gui_buffers; if (buffer->type != GUI_BUFFER_TYPE_FREE) 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, '?'); /* no message: delete line */ if (!gui_chat_buffer[0]) { if (gui_init_ok) { for (ptr_line = buffer->own_lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { if (ptr_line->data->y >= y) break; } if (ptr_line && (ptr_line->data->y == y)) { gui_line_free (buffer, ptr_line); gui_buffer_ask_chat_refresh (buffer, 2); } } } else { if (gui_init_ok) { gui_line_add_y (buffer, y, gui_chat_buffer); gui_buffer_ask_chat_refresh (buffer, 1); } else string_iconv_fprintf (stdout, "%s\n", gui_chat_buffer); } }
int upgrade_file_read_string_utf8 (struct t_upgrade_file *upgrade_file, char **string) { if (!upgrade_file_read_string (upgrade_file, string)) return 0; if (string && *string) utf8_normalize (*string, '?'); return 1; }
void gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...) { struct t_gui_line *ptr_line; int i, num_lines_to_add; 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_FREE) buffer = gui_buffers; if (buffer->type != GUI_BUFFER_TYPE_FREE) return; } weechat_va_format (message); if (!vbuffer) return; utf8_normalize (vbuffer, '?'); /* no message: delete line */ if (!vbuffer[0]) { if (gui_init_ok && (y >= 0)) { for (ptr_line = buffer->own_lines->first_line; ptr_line; ptr_line = ptr_line->next_line) { if (ptr_line->data->y >= y) break; } if (ptr_line && (ptr_line->data->y == y)) { if (ptr_line->next_line) gui_line_clear (ptr_line); else gui_line_free (buffer, ptr_line); gui_buffer_ask_chat_refresh (buffer, 2); } } } else { if (gui_init_ok) { /* if y is negative, add a line -N lines after the last line */ if (y < 0) { y = (buffer->own_lines && buffer->own_lines->last_line) ? buffer->own_lines->last_line->data->y - y : (-1 * y) - 1; } /* compute the number of lines to add before y */ if (buffer->own_lines && buffer->own_lines->last_line) num_lines_to_add = y - buffer->own_lines->last_line->data->y - 1; else num_lines_to_add = y; if (num_lines_to_add > 0) { /* * add empty line(s) before asked line, to ensure there is at * least "y" lines in buffer, and then be able to scroll * properly buffer page by page */ for (i = y - num_lines_to_add; i < y; i++) { gui_line_add_y (buffer, i, ""); } } gui_line_add_y (buffer, y, vbuffer); gui_buffer_ask_chat_refresh (buffer, 1); } else string_fprintf (stdout, "%s\n", vbuffer); } free (vbuffer); }
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); }
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); }