void printformat_module_window_args(const char *module, WINDOW_REC *window, int level, int formatnum, va_list va) { TEXT_DEST_REC dest; format_create_dest(&dest, NULL, NULL, level, window); printformat_module_dest_args(module, &dest, formatnum, va); }
void printformat_module_args(const char *module, void *server, const char *target, int level, int formatnum, va_list va) { TEXT_DEST_REC dest; format_create_dest(&dest, server, target, level, NULL); printformat_module_dest_args(module, &dest, formatnum, va); }
void gui_window_reformat_line(WINDOW_REC *window, LINE_REC *line) { GUI_WINDOW_REC *gui; TEXT_DEST_REC dest; GString *raw; char *str, *tmp, *prestr, *linestart, *leveltag; gui = WINDOW_GUI(window); raw = g_string_new(NULL); str = gui_window_line_get_format(window, line, raw); if (str == NULL && raw->len == 2 && raw->str[1] == (char)LINE_CMD_FORMAT_CONT) { /* multiline format, format explained in one the following lines. remove this line. */ gui_window_line_remove(window, line, FALSE); } else if (str != NULL) { /* FIXME: ugly ugly .. and this can't handle non-formatted lines.. */ g_string_append_c(raw, '\0'); g_string_append_c(raw, (char)LINE_CMD_EOL); gui_window_line_text_free(gui, line); gui->temp_line = line; gui->temp_line->text = gui->cur_text->buffer+gui->cur_text->pos; gui->cur_text->lines++; gui->eol_marked = FALSE; format_create_dest(&dest, NULL, NULL, line->level, window); linestart = format_get_line_start(current_theme, &dest, line->time); leveltag = format_get_level_tag(current_theme, &dest); prestr = g_strconcat(linestart == NULL ? "" : linestart, leveltag, NULL); g_free_not_null(linestart); g_free_not_null(leveltag); tmp = format_add_linestart(str, prestr); g_free(str); g_free(prestr); format_send_to_gui(&dest, tmp); g_free(tmp); gui_window_line_append(gui, raw->str, raw->len); gui->eol_marked = TRUE; gui->temp_line = NULL; } g_string_free(raw, TRUE); }
void textbuffer_reformat_line(WINDOW_REC *window, LINE_REC *line) { GUI_WINDOW_REC *gui; TEXT_DEST_REC dest; LINE_REC *line_prev; LINE_INFO_REC line_info; GString *raw; char *str, *tmp, *prestr, *linestart, *leveltag; gui = WINDOW_GUI(window); raw = g_string_new(NULL); str = textbuffer_line_get_format(window, line, raw); if (str == NULL && raw->len == 2 && raw->str[1] == (char)LINE_CMD_FORMAT_CONT) { /* multiline format, format explained in one the following lines. remove this line. */ textbuffer_view_remove_line(gui->view, line); } else if (str != NULL) { /* FIXME: ugly ugly .. and this can't handle unformatted lines.. */ g_string_append_c(raw, '\0'); g_string_append_c(raw, (char)LINE_CMD_EOL); line_prev = line->prev; memcpy(&line_info, &line->info, sizeof(line_info)); textbuffer_view_remove_line(gui->view, line); line = NULL; format_create_dest(&dest, NULL, NULL, line_info.level, window); linestart = format_get_line_start(current_theme, &dest, line_info.time); leveltag = format_get_level_tag(current_theme, &dest); prestr = g_strconcat(linestart == NULL ? "" : linestart, leveltag, NULL); g_free_not_null(linestart); g_free_not_null(leveltag); tmp = format_add_linestart(str, prestr); g_free(str); g_free(prestr); gui_printtext_after(&dest, line_prev, tmp); g_free(tmp); line = textbuffer_insert(gui->view->buffer, gui->insert_after, (unsigned char *) raw->str, raw->len, &line_info); textbuffer_view_insert_line(gui->view, line); } g_string_free(raw, TRUE); }
/* Write text to target - convert color codes */ void printtext(void *server, const char *target, int level, const char *text, ...) { TEXT_DEST_REC dest; va_list va; g_return_if_fail(text != NULL); format_create_dest(&dest, server, target, level, NULL); va_start(va, text); printtext_dest_args(&dest, text, va); va_end(va); }
void printtext_window(WINDOW_REC *window, int level, const char *text, ...) { TEXT_DEST_REC dest; va_list va; g_return_if_fail(text != NULL); format_create_dest(&dest, NULL, NULL, level, window != NULL ? window : active_win); va_start(va, text); printtext_dest_args(&dest, text, va); va_end(va); }
static void window_print_daychange(WINDOW_REC *window, struct tm *tm) { THEME_REC *theme; TEXT_DEST_REC dest; char *format, str[256]; theme = active_win->theme != NULL ? active_win->theme : current_theme; format_create_dest(&dest, NULL, NULL, MSGLEVEL_NEVER, window); format = format_get_text_theme(theme, MODULE_NAME, &dest, TXT_DAYCHANGE); if (strftime(str, sizeof(str), format, tm) <= 0) str[0] = '\0'; g_free(format); printtext_string_window(window, MSGLEVEL_NEVER, str); }
static void prepend_date(WINDOW_REC *window, LINE_REC *rec, GString *line) { THEME_REC *theme = NULL; TEXT_DEST_REC dest = {0}; char *format = NULL, datestamp[20] = {0}; struct tm *tm = localtime(&rec->info.time); int ret = 0; theme = window->theme != NULL ? window->theme : current_theme; format_create_dest(&dest, NULL, NULL, MSGLEVEL_LASTLOG, window); format = format_get_text_theme(theme, MODULE_NAME, &dest, TXT_LASTLOG_DATE); ret = strftime(datestamp, sizeof(datestamp), format, tm); g_free(format); if (ret <= 0) return; g_string_prepend(line, datestamp); }
/* Like printtext(), but don't handle %s etc. */ void printtext_string(void *server, const char *target, int level, const char *text) { TEXT_DEST_REC dest; char *str; g_return_if_fail(text != NULL); format_create_dest(&dest, server, target, level, NULL); if (!sending_print_starting) { sending_print_starting = TRUE; signal_emit_id(signal_print_starting, 1, &dest); sending_print_starting = FALSE; } str = printtext_expand_formats(text, &dest.flags); print_line(&dest, str); g_free(str); }
static int PyTextDest_init(PyTextDest *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"target", "level", "server", "window", NULL}; char *target; int level = MSGLEVEL_CLIENTNOTICE; PyObject *server = NULL, *window = NULL; TEXT_DEST_REC *dest; if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ioo", kwlist, &target, &level, &server, &window)) return -1; if (server == Py_None) server = NULL; if (window == Py_None) window = NULL; if (server && !pyserver_check(server)) { PyErr_Format(PyExc_TypeError, "arg 3 isnt server"); return -1; } if (window && !pywindow_check(window)) { PyErr_Format(PyExc_TypeError, "arg 4 isnt window"); return -1; } if (self->data) { PyErr_Format(PyExc_RuntimeError, "TextDest already wrapped"); return -1; } dest = g_new0(TEXT_DEST_REC, 1); format_create_dest(dest, DATA(server), g_strdup(target), level, DATA(window)); if (!pytextdest_setup(self, dest, 1)) return -1; return 0; }
/* Like printtext_window(), but don't handle %s etc. */ void printtext_string_window(WINDOW_REC *window, int level, const char *text) { TEXT_DEST_REC dest; char *str; g_return_if_fail(text != NULL); format_create_dest(&dest, NULL, NULL, level, window != NULL ? window : active_win); if (!sending_print_starting) { sending_print_starting = TRUE; signal_emit_id(signal_print_starting, 1, &dest); sending_print_starting = FALSE; } str = printtext_expand_formats(text, &dest.flags); print_line(&dest, str); g_free(str); }
static void sig_message_public(SERVER_REC *server, const char *msg, const char *nick, const char *address, const char *target, NICK_REC *nickrec) { CHANNEL_REC *chanrec; const char *printnick; int for_me, print_channel, level; char *nickmode, *color, *freemsg = NULL; HILIGHT_REC *hilight; TEXT_DEST_REC dest; /* NOTE: this may return NULL if some channel is just closed with /WINDOW CLOSE and server still sends the few last messages */ chanrec = channel_find(server, target); if (nickrec == NULL && chanrec != NULL) nickrec = nicklist_find(chanrec, nick); for_me = !settings_get_bool("hilight_nick_matches") ? FALSE : !settings_get_bool("hilight_nick_matches_everywhere") ? nick_match_msg(chanrec, msg, server->nick) : nick_match_msg_everywhere(chanrec, msg, server->nick); hilight = for_me ? NULL : hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC, msg); color = (hilight == NULL) ? NULL : hilight_get_color(hilight); print_channel = chanrec == NULL || !window_item_is_active((WI_ITEM_REC *) chanrec); if (!print_channel && settings_get_bool("print_active_channel") && window_item_window((WI_ITEM_REC *) chanrec)->items->next != NULL) print_channel = TRUE; level = MSGLEVEL_PUBLIC; if (for_me) level |= MSGLEVEL_HILIGHT; ignore_check_plus(server, nick, address, target, msg, &level, FALSE); if (settings_get_bool("emphasis")) msg = freemsg = expand_emphasis((WI_ITEM_REC *) chanrec, msg); /* get nick mode & nick what to print the msg with (in case there's multiple identical nicks) */ nickmode = channel_get_nickmode_rec(nickrec); printnick = nickrec == NULL ? nick : g_hash_table_lookup(printnicks, nickrec); if (printnick == NULL) printnick = nick; format_create_dest(&dest, server, target, level, NULL); dest.address = address; dest.nick = nick; if (color != NULL) { /* highlighted nick */ hilight_update_text_dest(&dest,hilight); if (!print_channel) /* message to active channel in window */ printformat_dest(&dest, TXT_PUBMSG_HILIGHT, color, printnick, msg, nickmode); else /* message to not existing/active channel */ printformat_dest(&dest, TXT_PUBMSG_HILIGHT_CHANNEL, color, printnick, target, msg, nickmode); } else { if (!print_channel) printformat_dest(&dest, for_me ? TXT_PUBMSG_ME : TXT_PUBMSG, printnick, msg, nickmode); else printformat_dest(&dest, for_me ? TXT_PUBMSG_ME_CHANNEL : TXT_PUBMSG_CHANNEL, printnick, target, msg, nickmode); } g_free_not_null(nickmode); g_free_not_null(freemsg); g_free_not_null(color); }
static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist) { WINDOW_REC *window; TEXT_DEST_REC dest; GString *str; GSList *tmp; char *format, *stripped, *prefix_format; char *linebuf, nickmode[2] = { 0, 0 }; int *columns, cols, rows, last_col_rows, col, row, max_width; int item_extra, linebuf_size, formatnum; window = window_find_closest(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP); max_width = window->width; /* get the length of item extra stuff ("[ ] ") */ format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, TXT_NAMES_NICK, " ", ""); stripped = strip_codes(format); item_extra = strlen(stripped); g_free(stripped); g_free(format); if (settings_get_int("names_max_width") > 0 && settings_get_int("names_max_width") < max_width) max_width = settings_get_int("names_max_width"); /* remove width of the timestamp from max_width */ format_create_dest(&dest, channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, NULL); format = format_get_line_start(current_theme, &dest, time(NULL)); if (format != NULL) { stripped = strip_codes(format); max_width -= strlen(stripped); g_free(stripped); g_free(format); } /* remove width of the prefix from max_width */ prefix_format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, TXT_NAMES_PREFIX, channel->visible_name); if (prefix_format != NULL) { stripped = strip_codes(prefix_format); max_width -= strlen(stripped); g_free(stripped); } if (max_width <= 0) { /* we should always have at least some space .. if we really don't, it won't show properly anyway. */ max_width = 10; } /* calculate columns */ cols = get_max_column_count(nicklist, get_nick_length, max_width, settings_get_int("names_max_columns"), item_extra, 3, &columns, &rows); nicklist = columns_sort_list(nicklist, rows); /* rows in last column */ last_col_rows = rows-(cols*rows-g_slist_length(nicklist)); if (last_col_rows == 0) last_col_rows = rows; str = g_string_new(prefix_format); linebuf_size = max_width+1; linebuf = g_malloc(linebuf_size); col = 0; row = 0; for (tmp = nicklist; tmp != NULL; tmp = tmp->next) { NICK_REC *rec = tmp->data; if (rec->other) nickmode[0] = rec->other; else if (rec->op) nickmode[0] = '@'; else if (rec->halfop) nickmode[0] = '%'; else if (rec->voice) nickmode[0] = '+'; else nickmode[0] = ' '; if (linebuf_size < columns[col]-item_extra+1) { linebuf_size = (columns[col]-item_extra+1)*2; linebuf = g_realloc(linebuf, linebuf_size); } memset(linebuf, ' ', columns[col]-item_extra); linebuf[columns[col]-item_extra] = '\0'; memcpy(linebuf, rec->nick, strlen(rec->nick)); formatnum = rec->op ? TXT_NAMES_NICK_OP : rec->halfop ? TXT_NAMES_NICK_HALFOP : rec->voice ? TXT_NAMES_NICK_VOICE : TXT_NAMES_NICK; format = format_get_text(MODULE_NAME, NULL, channel->server, channel->visible_name, formatnum, nickmode, linebuf); g_string_append(str, format); g_free(format); if (++col == cols) { printtext(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, "%s", str->str); g_string_truncate(str, 0); if (prefix_format != NULL) g_string_assign(str, prefix_format); col = 0; row++; if (row == last_col_rows) cols--; } } if (str->len > strlen(prefix_format)) { printtext(channel->server, channel->visible_name, MSGLEVEL_CLIENTCRAP, "%s", str->str); } g_slist_free(nicklist); g_string_free(str, TRUE); g_free_not_null(columns); g_free_not_null(prefix_format); g_free(linebuf); }
static char *gui_window_line_get_format(WINDOW_REC *window, LINE_REC *line, GString *raw) { const unsigned char *text; char *module, *format_name, *args[MAX_FORMAT_PARAMS], *ret; TEXT_DEST_REC dest; int formatnum, argcount; text = (const unsigned char *) line->text; /* skip the beginning of the line until we find the format */ g_free(line_read_format(&text)); if (text[1] == LINE_CMD_FORMAT_CONT) { g_string_append_c(raw, '\0'); g_string_append_c(raw, (char)LINE_CMD_FORMAT_CONT); return NULL; } /* read format information */ module = line_read_format(&text); format_name = line_read_format(&text); if (raw != NULL) { g_string_append_c(raw, '\0'); g_string_append_c(raw, (char)LINE_CMD_FORMAT); g_string_append(raw, module); g_string_append_c(raw, '\0'); g_string_append_c(raw, (char)LINE_CMD_FORMAT); g_string_append(raw, format_name); } formatnum = format_find_tag(module, format_name); if (formatnum == -1) ret = NULL; else { argcount = 0; memset(args, 0, sizeof(args)); while (*text != '\0' || text[1] != LINE_CMD_EOL) { args[argcount] = line_read_format(&text); if (raw != NULL) { g_string_append_c(raw, '\0'); g_string_append_c(raw, (char)LINE_CMD_FORMAT); g_string_append(raw, args[argcount]); } argcount++; } /* get the format text */ format_create_dest(&dest, NULL, NULL, line->level, window); ret = format_get_text_theme_charargs(current_theme, module, &dest, formatnum, args); while (argcount > 0) g_free(args[--argcount]); } g_free(module); g_free(format_name); return ret; }
static void help_category(GSList *cmdlist, int items) { WINDOW_REC *window; TEXT_DEST_REC dest; GString *str; GSList *tmp; int *columns, cols, rows, col, row, last_col_rows, max_width; char *linebuf, *format, *stripped; window = window_find_closest(NULL, NULL, MSGLEVEL_CLIENTCRAP); max_width = window->width; /* remove width of timestamp from max_width */ format_create_dest(&dest, NULL, NULL, MSGLEVEL_CLIENTCRAP, NULL); format = format_get_line_start(current_theme, &dest, time(NULL)); if (format != NULL) { stripped = strip_codes(format); max_width -= strlen(stripped); g_free(stripped); g_free(format); } /* calculate columns */ cols = get_max_column_count(cmdlist, get_cmd_length, max_width, 6, 1, 3, &columns, &rows); cmdlist = columns_sort_list(cmdlist, rows); /* rows in last column */ last_col_rows = rows-(cols*rows-g_slist_length(cmdlist)); if (last_col_rows == 0) last_col_rows = rows; str = g_string_new(NULL); linebuf = g_malloc(max_width+1); col = 0; row = 0; for (tmp = cmdlist; tmp != NULL; tmp = tmp->next) { COMMAND_REC *rec = tmp->data; memset(linebuf, ' ', columns[col]); linebuf[columns[col]] = '\0'; memcpy(linebuf, rec->cmd, strlen(rec->cmd)); g_string_append(str, linebuf); if (++col == cols) { printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str->str); g_string_truncate(str, 0); col = 0; row++; if (row == last_col_rows) cols--; } } if (str->len != 0) printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str->str); g_slist_free(cmdlist); g_string_free(str, TRUE); g_free(columns); g_free(linebuf); }