diff options
author | Timo Sirainen <cras@irssi.org> | 2000-10-28 20:14:19 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-10-28 20:14:19 +0000 |
commit | 4dcbe05c0f67fe9e914ba323ce7e179885ebb1f7 (patch) | |
tree | f235d6f427cd0dd7e98dfbd36813a1098e127faa /src | |
parent | 8653c6ea36c29067a358ed59782b71ffd1401fc3 (diff) | |
download | irssi-4dcbe05c0f67fe9e914ba323ce7e179885ebb1f7.zip |
Cleaned up printtext.c, split part of it to formats.c
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@796 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
46 files changed, 733 insertions, 632 deletions
diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am index aa4432ac..cea60d81 100644 --- a/src/fe-common/core/Makefile.am +++ b/src/fe-common/core/Makefile.am @@ -22,6 +22,7 @@ libfe_common_core_a_SOURCES = \ fe-queries.c \ fe-server.c \ fe-settings.c \ + formats.c \ hilight-text.c \ keyboard.c \ module-formats.c \ @@ -39,6 +40,7 @@ noinst_HEADERS = \ completion.h \ fe-common-core.h \ fe-queries.h \ + formats.h \ hilight-text.h \ keyboard.h \ module-formats.h \ diff --git a/src/fe-common/core/fe-channels.c b/src/fe-common/core/fe-channels.c index 19ad6c84..7f220752 100644 --- a/src/fe-common/core/fe-channels.c +++ b/src/fe-common/core/fe-channels.c @@ -32,6 +32,7 @@ #include "windows.h" #include "window-items.h" +#include "printtext.h" static void signal_channel_created(CHANNEL_REC *channel, gpointer automatic) { diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index ac6b846c..50617981 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -29,6 +29,7 @@ #include "irssi-version.h" #include "windows.h" +#include "printtext.h" #define PASTE_CHECK_SPEED 200 /* 0.2 sec */ diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c index 051d7767..db2d4ad3 100644 --- a/src/fe-common/core/fe-ignore.c +++ b/src/fe-common/core/fe-ignore.c @@ -27,6 +27,7 @@ #include "servers.h" #include "ignore.h" +#include "printtext.h" static void fe_unignore(IGNORE_REC *rec); diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 35c570c1..1ded4f9b 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -31,7 +31,9 @@ #include "windows.h" #include "window-items.h" +#include "formats.h" #include "themes.h" +#include "printtext.h" /* close autologs after 5 minutes of inactivity */ #define AUTOLOG_INACTIVITY_CLOSE (60*5) @@ -419,13 +421,10 @@ static void sig_printtext_stripped(WINDOW_REC *window, void *server, } static void sig_print_format(THEME_REC *theme, const char *module, - TEXT_DEST_REC *dest, gpointer formatnump, + TEXT_DEST_REC *dest, void *formatnum, va_list va) { - MODULE_THEME_REC *module_theme; - FORMAT_REC *formats; - int formatnum; - char *str, *str2, *stripped, *tmp; + char *str, *stripped, *linestart, *tmp; if (log_theme == NULL) { /* theme isn't loaded for some reason (/reload destroys it), @@ -437,31 +436,20 @@ static void sig_print_format(THEME_REC *theme, const char *module, if (theme == log_theme) return; - /* log uses a different theme .. very ugly kludge follows.. : */ - formatnum = GPOINTER_TO_INT(formatnump); - module_theme = g_hash_table_lookup(log_theme->modules, module); - formats = g_hash_table_lookup(default_formats, module); + str = format_get_text_theme_args(log_theme, module, dest, + GPOINTER_TO_INT(formatnum), va); + skip_next_printtext = TRUE; - str = output_format_text_args(dest, &formats[formatnum], - module_theme->expanded_formats[formatnum], va); if (*str != '\0') { - /* get_line_start_text() gets the line start with - current theme. */ - THEME_REC *old_theme = current_theme; - current_theme = log_theme; - tmp = get_line_start_text(dest); - current_theme = old_theme; - - /* line start + text */ - str2 = tmp == NULL ? str : - g_strconcat(tmp, str, NULL); - if (str2 != str) g_free(str); - str = str2; - g_free_not_null(tmp); + /* add the line start format */ + linestart = format_get_line_start(log_theme, dest); + tmp = str; + str = format_add_linestart(tmp, linestart); + g_free_not_null(linestart); + g_free(tmp); /* strip colors from text, log it. */ stripped = strip_codes(str); - skip_next_printtext = TRUE; log_line(dest->window, dest->server, dest->target, dest->level, stripped); g_free(stripped); @@ -558,10 +546,10 @@ static void read_settings(void) /* write to log files with different theme? */ log_theme_name = settings_get_str("log_theme"); - if (old_log_theme == NULL && *log_theme_name != '\0') { + if (*old_log_theme == '\0' && *log_theme_name != '\0') { /* theme set */ signal_add("print format", (SIGNAL_FUNC) sig_print_format); - } else if (old_log_theme != NULL && *log_theme_name == '\0') { + } else if (*old_log_theme != '\0' && *log_theme_name == '\0') { /* theme unset */ signal_remove("print format", (SIGNAL_FUNC) sig_print_format); } @@ -581,6 +569,7 @@ void fe_log_init(void) settings_add_str("log", "log_theme", ""); autolog_level = 0; + log_theme_name = ""; read_settings(); command_bind("log", NULL, (SIGNAL_FUNC) cmd_log); @@ -605,7 +594,7 @@ void fe_log_init(void) void fe_log_deinit(void) { g_source_remove(autoremove_tag); - if (log_theme_name != NULL && *log_theme_name != '\0') + if (*log_theme_name != '\0') signal_remove("print format", (SIGNAL_FUNC) sig_print_format); command_unbind("log", (SIGNAL_FUNC) cmd_log); diff --git a/src/fe-common/core/fe-messages.c b/src/fe-common/core/fe-messages.c index 1a074f31..934f01b8 100644 --- a/src/fe-common/core/fe-messages.c +++ b/src/fe-common/core/fe-messages.c @@ -33,6 +33,7 @@ #include "nicklist.h" #include "hilight-text.h" #include "ignore.h" +#include "printtext.h" static char *get_nickmode(CHANNEL_REC *channel, const char *nick) { diff --git a/src/fe-common/core/fe-modules.c b/src/fe-common/core/fe-modules.c index 1db51731..4dd97d56 100644 --- a/src/fe-common/core/fe-modules.c +++ b/src/fe-common/core/fe-modules.c @@ -25,6 +25,8 @@ #include "commands.h" #include "levels.h" +#include "printtext.h" + static void sig_module_error(void *number, const char *module, const char *data) { switch (GPOINTER_TO_INT(number)) { diff --git a/src/fe-common/core/fe-queries.c b/src/fe-common/core/fe-queries.c index f9f0840e..5875640c 100644 --- a/src/fe-common/core/fe-queries.c +++ b/src/fe-common/core/fe-queries.c @@ -30,6 +30,7 @@ #include "windows.h" #include "window-items.h" +#include "printtext.h" static int queryclose_tag, query_auto_close, querycreate_level; diff --git a/src/fe-common/core/fe-server.c b/src/fe-common/core/fe-server.c index 53160037..72ac7b50 100644 --- a/src/fe-common/core/fe-server.c +++ b/src/fe-common/core/fe-server.c @@ -31,6 +31,7 @@ #include "servers-reconnect.h" #include "module-formats.h" +#include "printtext.h" static void print_servers(void) { diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c index 4d8266dd..15968002 100644 --- a/src/fe-common/core/fe-settings.c +++ b/src/fe-common/core/fe-settings.c @@ -28,6 +28,7 @@ #include "settings.h" #include "levels.h" +#include "printtext.h" static void set_print(SETTINGS_REC *rec) { diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c new file mode 100644 index 00000000..dd2fe8a4 --- /dev/null +++ b/src/fe-common/core/formats.c @@ -0,0 +1,354 @@ +/* + formats.c : irssi + + Copyright (C) 1999-2000 Timo Sirainen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "module.h" +#include "module-formats.h" +#include "signals.h" +#include "special-vars.h" + +#include "levels.h" + +#include "windows.h" +#include "formats.h" +#include "themes.h" + +int format_expand_styles(GString *out, char format, TEXT_DEST_REC *dest) +{ + static const char *backs = "04261537"; + static const char *fores = "kbgcrmyw"; + static const char *boldfores = "KBGCRMYW"; + char *p; + + switch (format) { + case 'U': + /* Underline on/off */ + g_string_append_c(out, 4); + g_string_append_c(out, FORMAT_STYLE_UNDERLINE); + break; + case '9': + case '_': + /* bold on/off */ + g_string_append_c(out, 4); + g_string_append_c(out, FORMAT_STYLE_BOLD); + break; + case '8': + /* reverse */ + g_string_append_c(out, 4); + g_string_append_c(out, FORMAT_STYLE_REVERSE); + break; + case '%': + g_string_append_c(out, '%'); + break; + case ':': + /* Newline */ + g_string_append_c(out, '\n'); + break; + case '|': + /* Indent here */ + g_string_append_c(out, 4); + g_string_append_c(out, FORMAT_STYLE_INDENT); + break; + case 'F': + /* flashing - ignore */ + break; + case 'N': + /* don't put clear-color tag at the end of the output - ignore */ + break; + case 'n': + /* default color */ + g_string_append_c(out, 4); + g_string_append_c(out, FORMAT_STYLE_DEFAULTS); + break; + default: + /* check if it's a background color */ + p = strchr(backs, format); + if (p != NULL) { + g_string_append_c(out, 4); + g_string_append_c(out, FORMAT_COLOR_NOCHANGE); + g_string_append_c(out, (int) (p-backs)+'0'); + break; + } + + /* check if it's a foreground color */ + if (format == 'p') format = 'm'; + p = strchr(fores, format); + if (p != NULL) { + g_string_append_c(out, 4); + g_string_append_c(out, (int) (p-fores)+'0'); + g_string_append_c(out, FORMAT_COLOR_NOCHANGE); + break; + } + + /* check if it's a bold foreground color */ + if (format == 'P') format = 'M'; + p = strchr(boldfores, format); + if (p != NULL) { + g_string_append_c(out, 4); + g_string_append_c(out, 8+(int) (p-boldfores)+'0'); + g_string_append_c(out, FORMAT_COLOR_NOCHANGE); + break; + } + + return FALSE; + } + + return TRUE; +} + +static void read_arglist(va_list va, FORMAT_REC *format, + char **arglist, int arglist_size, + char *buffer, int buffer_size) +{ + int num, len, bufpos; + + bufpos = 0; + arglist[format->params] = NULL; + for (num = 0; num < format->params && num < arglist_size; num++) { + switch (format->paramtypes[num]) { + case FORMAT_STRING: + arglist[num] = (char *) va_arg(va, char *); + if (arglist[num] == NULL) { + g_warning("read_arglist() : parameter %d is NULL", num); + arglist[num] = ""; + } + break; + case FORMAT_INT: { + int d = (int) va_arg(va, int); + + if (bufpos >= buffer_size) { + arglist[num] = ""; + break; + } + + arglist[num] = buffer+bufpos; + len = g_snprintf(buffer+bufpos, buffer_size-bufpos, + "%d", d); + bufpos += len+1; + break; + } + case FORMAT_LONG: { + long l = (long) va_arg(va, long); + + if (bufpos >= buffer_size) { + arglist[num] = ""; + break; + } + + arglist[num] = buffer+bufpos; + len = g_snprintf(buffer+bufpos, buffer_size-bufpos, + "%ld", l); + bufpos += len+1; + break; + } + case FORMAT_FLOAT: { + double f = (double) va_arg(va, double); + + if (bufpos >= buffer_size) { + arglist[num] = ""; + break; + } + + arglist[num] = buffer+bufpos; + len = g_snprintf(buffer+bufpos, buffer_size-bufpos, + "%0.2f", f); + bufpos += len+1; + break; + } + } + } +} + +void format_create_dest(TEXT_DEST_REC *dest, + void *server, const char *target, + int level, WINDOW_REC *window) +{ + dest->server = server; + dest->target = target; + dest->level = level; + dest->window = window != NULL ? window : + window_find_closest(server, target, level); +} + +static char *format_get_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format, + const char *text, va_list va) +{ + GString *out; + char *arglist[10]; + char buffer[200]; /* should be enough? (won't overflow even if it isn't) */ + + char code, *ret; + int need_free; + + /* read all optional arguments to arglist[] list + so they can be used in any order.. */ + read_arglist(va, format, + arglist, sizeof(arglist)/sizeof(void*), + buffer, sizeof(buffer)); + + out = g_string_new(NULL); + + code = 0; + while (*text != '\0') { + if (code == '%') { + /* color code */ + if (!format_expand_styles(out, *text, dest)) { + g_string_append_c(out, '%'); + g_string_append_c(out, '%'); + g_string_append_c(out, *text); + } + code = 0; + } else if (code == '$') { + /* argument */ + char *ret; + + ret = parse_special((char **) &text, active_win->active_server, + active_win->active, arglist, &need_free, NULL); + + if (ret != NULL) { + /* string shouldn't end with \003 or it could + mess up the next one or two characters */ + int diff; + int len = strlen(ret); + while (len > 0 && ret[len-1] == 3) len--; + diff = strlen(ret)-len; + + g_string_append(out, ret); + if (diff > 0) + g_string_truncate(out, out->len-diff); + if (need_free) g_free(ret); + } + code = 0; + } else { + if (*text == '%' || *text == '$') + code = *text; + else + g_string_append_c(out, *text); + } + + text++; + } + + ret = out->str; + g_string_free(out, FALSE); + return ret; +} + +char *format_get_text_theme(THEME_REC *theme, const char *module, + TEXT_DEST_REC *dest, int formatnum, ...) +{ + va_list va; + char *str; + + if (theme == NULL) { + theme = dest->window->theme == NULL ? current_theme : + dest->window->theme; + } + + va_start(va, formatnum); + str = format_get_text_theme_args(theme, module, dest, formatnum, va); + va_end(va); + + return str; +} + +char *format_get_text_theme_args(THEME_REC *theme, const char *module, + TEXT_DEST_REC *dest, int formatnum, + va_list va) +{ + MODULE_THEME_REC *module_theme; + FORMAT_REC *formats; + char *str; + + module_theme = g_hash_table_lookup(theme->modules, module); + formats = g_hash_table_lookup(default_formats, module); + + str = format_get_text_args(dest, &formats[formatnum], + module_theme->expanded_formats[formatnum], va); + return str; +} + +char *format_get_text(const char *module, WINDOW_REC *window, + void *server, const char *target, + int formatnum, ...) +{ + TEXT_DEST_REC dest; + THEME_REC *theme; + va_list va; + char *str; + + format_create_dest(&dest, server, target, 0, window); + theme = dest.window->theme == NULL ? current_theme : + dest.window->theme; + + va_start(va, formatnum); + str = format_get_text_theme_args(theme, module, &dest, formatnum, va); + va_end(va); + + return str; +} + +/* add `linestart' to start of each line in `text'. `text' may contain + multiple lines separated with \n. */ +char *format_add_linestart(const char *text, const char *linestart) +{ + GString *str; + char *ret; + + if (linestart == NULL) + return g_strdup(text); + + if (strchr(text, '\n') == NULL) + return g_strconcat(linestart, text, NULL); + + str = g_string_new(linestart); + while (*text != '\0') { + g_string_append_c(str, *text); + if (*text == '\n') + g_string_append(str, linestart); + text++; + } + + ret = str->str; + g_string_free(str, FALSE); + return ret; +} + +#define LINE_START_IRSSI_LEVEL \ + (MSGLEVEL_CLIENTERROR | MSGLEVEL_CLIENTNOTICE) + +#define NOT_LINE_START_LEVEL \ + (MSGLEVEL_NEVER | MSGLEVEL_LASTLOG | MSGLEVEL_CLIENTCRAP | \ + MSGLEVEL_MSGS | MSGLEVEL_PUBLIC | MSGLEVEL_DCC | MSGLEVEL_DCCMSGS | \ + MSGLEVEL_ACTIONS | MSGLEVEL_NOTICES | MSGLEVEL_SNOTES | MSGLEVEL_CTCPS) + +/* return the "-!- " text at the start of the line */ +char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest) +{ + int format; + + if (dest->level & LINE_START_IRSSI_LEVEL) + format = IRCTXT_LINE_START_IRSSI; + else if ((dest->level & NOT_LINE_START_LEVEL) == 0) + format = IRCTXT_LINE_START; + else + return NULL; + + return format_get_text_theme(theme, MODULE_NAME, dest, format); +} diff --git a/src/fe-common/core/formats.h b/src/fe-common/core/formats.h new file mode 100644 index 00000000..a448bc21 --- /dev/null +++ b/src/fe-common/core/formats.h @@ -0,0 +1,62 @@ +#ifndef __FORMATS_H +#define __FORMATS_H + +#include "themes.h" +#include "windows.h" + +enum { + FORMAT_STRING, + FORMAT_INT, + FORMAT_LONG, + FORMAT_FLOAT +}; + +struct _FORMAT_REC { + char *tag; + char *def; + + int params; + int paramtypes[10]; +}; + +typedef struct { + WINDOW_REC *window; + void *server; + const char *target; + int level; +} TEXT_DEST_REC; + +char *format_get_text(const char *module, WINDOW_REC *window, + void *server, const char *target, + int formatnum, ...); + +char *format_get_text_theme(THEME_REC *theme, const char *module, + TEXT_DEST_REC *dest, int formatnum, ...); +char *format_get_text_theme_args(THEME_REC *theme, const char *module, + TEXT_DEST_REC *dest, int formatnum, + va_list va); + +/* add `linestart' to start of each line in `text'. `text' may contain + multiple lines separated with \n. */ +char *format_add_linestart(const char *text, const char *linestart); + +/* return the "-!- " text at the start of the line */ +char *format_get_line_start(THEME_REC *theme, TEXT_DEST_REC *dest); + + +/* "private" functions for printtext */ +void format_create_dest(TEXT_DEST_REC *dest, + void *server, const char *target, + int level, WINDOW_REC *window); + +#define FORMAT_COLOR_NOCHANGE ('0'-1) + +#define FORMAT_STYLE_SPECIAL 0x60 +#define FORMAT_STYLE_UNDERLINE (0x01 + FORMAT_STYLE_SPECIAL) +#define FORMAT_STYLE_BOLD (0x02 + FORMAT_STYLE_SPECIAL) +#define FORMAT_STYLE_REVERSE (0x03 + FORMAT_STYLE_SPECIAL) +#define FORMAT_STYLE_INDENT (0x04 + FORMAT_STYLE_SPECIAL) +#define FORMAT_STYLE_DEFAULTS (0x05 + FORMAT_STYLE_SPECIAL) +int format_expand_styles(GString *out, char format, TEXT_DEST_REC *dest); + +#endif diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c index 06029fe9..94b2952f 100644 --- a/src/fe-common/core/hilight-text.c +++ b/src/fe-common/core/hilight-text.c @@ -30,6 +30,7 @@ #include "servers.h" #include "hilight-text.h" +#include "printtext.h" #define DEFAULT_HILIGHT_LEVEL \ (MSGLEVEL_PUBLIC | MSGLEVEL_MSGS | \ diff --git a/src/fe-common/core/keyboard.c b/src/fe-common/core/keyboard.c index 80704db9..a21c11c1 100644 --- a/src/fe-common/core/keyboard.c +++ b/src/fe-common/core/keyboard.c @@ -29,6 +29,7 @@ #include "keyboard.h" #include "windows.h" +#include "printtext.h" GSList *keyinfos; static GHashTable *keys; diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 91c7c1e7..43379fa8 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -19,7 +19,7 @@ */ #include "module.h" -#include "printtext.h" +#include "formats.h" FORMAT_REC fecommon_core_formats[] = { { MODULE_NAME, "Core", 0 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 362b9074..57246414 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -1,4 +1,4 @@ -#include "printtext.h" +#include "formats.h" enum { IRCTXT_MODULE_NAME, diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c index dc352c13..d7ddb50a 100644 --- a/src/fe-common/core/printtext.c +++ b/src/fe-common/core/printtext.c @@ -23,7 +23,6 @@ #include "modules.h" #include "signals.h" #include "commands.h" -#include "special-vars.h" #include "settings.h" #include "levels.h" @@ -32,6 +31,7 @@ #include "translation.h" #include "themes.h" #include "windows.h" +#include "printtext.h" static int beep_msg_level, beep_when_away; static int timestamps, msgs_timestamps, hide_text_style; @@ -43,7 +43,7 @@ static int signal_print_text; static int signal_print_text_finished; static int signal_print_format; -static void print_string(TEXT_DEST_REC *dest, const char *text); +static void print_line(TEXT_DEST_REC *dest, const char *text); void printbeep(void) { @@ -51,23 +51,47 @@ void printbeep(void) GINT_TO_POINTER(PRINTFLAG_BEEP), "", MSGLEVEL_NEVER); } -static void skip_mirc_color(char **str) +static void get_mirc_color(const char **str, int *fg_ret, int *bg_ret) { - if (!isdigit((int) **str)) - return; - - /* foreground */ - (*str)++; - if (isdigit((int) **str)) (*str)++; - - if (**str != ',' || !isdigit((int) (*str)[1])) return; + int fg, bg; + + fg = fg_ret == NULL ? -1 : *fg_ret; + bg = bg_ret == NULL ? -1 : *bg_ret; + + if (!isdigit((int) **str) && **str != ',') { + fg = -1; + bg = -1; + } else { + /* foreground color */ + if (**str != ',') { + fg = **str-'0'; + (*str)++; + if (isdigit((int) **str)) { + fg = fg*10 + (**str-'0'); + (*str)++; + } + } + if (**str == ',') { + /* background color */ + (*str)++; + if (!isdigit((int) **str)) + bg = -1; + else { + bg = **str-'0'; + (*str)++; + if (isdigit((int) **str)) { + bg = bg*10 + (**str-'0'); + (*str)++; + } + } + } + } - /* background */ - (*str) += 2; - if (isdigit((int) **str)) (*str)++; + if (fg_ret) *fg_ret = fg; + if (bg_ret) *bg_ret = bg; } -#define is_color_code(c) \ +#define IS_COLOR_CODE(c) \ ((c) == 2 || (c) == 3 || (c) == 4 || (c) == 6 || (c) == 7 || \ (c) == 15 || (c) == 22 || (c) == 27 || (c) == 31) @@ -81,25 +105,26 @@ char *strip_codes(const char *input) if (*p == 3) { p++; - if (*p < 17 && *p > 0) { - /* irssi color */ - if (p[1] < 17 && p[1] > 0) p++; - continue; - } - /* mirc color */ - skip_mirc_color((char **) &p); + get_mirc_color(&p, NULL, NULL); p--; continue; } - if (*p == 4 && p[1] != '\0' && p[2] != '\0') { + if (*p == 4 && p[1] != '\0') { + if (p[1] >= FORMAT_STYLE_SPECIAL) { + p++; + continue; + } + /* irssi color */ - p += 2; - continue; + if (p[2] != '\0') { + p += 2; + continue; + } } - if (!is_color_code(*p)) + if (!IS_COLOR_CODE(*p)) *out++ = *p; } @@ -108,20 +133,20 @@ char *strip_codes(const char *input) } /* parse ANSI color string */ -static char *convert_ansi(THEME_REC *theme, char *str, - int *fgcolor, int *bgcolor, int *flags) +static char *get_ansi_color(THEME_REC *theme, char *str, + int *fg_ret, int *bg_ret, int *flags_ret) { static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; char *start; - int fg, bg, fl, num; + int fg, bg, flags, num; if (*str != '[') return str; start = str++; - fg = *fgcolor < 0 ? theme->default_color : *fgcolor; - bg = *bgcolor < 0 ? -1 : *bgcolor; - fl = *flags; + fg = fg_ret == NULL || *fg_ret < 0 ? theme->default_color : *fg_ret; + bg = bg_ret == NULL || *bg_ret < 0 ? -1 : *bg_ret; + flags = flags_ret == NULL ? 0 : *flags_ret; num = 0; for (;; str++) { @@ -140,19 +165,19 @@ static char *convert_ansi(THEME_REC *theme, char *str, /* reset colors back to default */ fg = theme->default_color; bg = -1; - fl &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT); + flags &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT); break; case 1: /* hilight */ - fl |= PRINTFLAG_BOLD; + flags |= PRINTFLAG_BOLD; break; case 5: /* blink */ - fl |= PRINTFLAG_BLINK; + flags |= PRINTFLAG_BLINK; break; case 7: /* reverse */ - fl |= PRINTFLAG_REVERSE; + flags |= PRINTFLAG_REVERSE; break; default: if (num >= 30 && num <= 37) @@ -166,11 +191,10 @@ static char *convert_ansi(THEME_REC *theme, char *str, num = 0; if (*str == 'm') { - if (!hide_text_style) { - *fgcolor = fg; - *bgcolor = bg; - *flags = fl; - } + if (fg_ret != NULL) *fg_ret = fg; + if (bg_ret != NULL) *bg_ret = bg; + if (flags_ret != NULL) *flags_ret = flags; + str++; break; } @@ -179,301 +203,23 @@ static char *convert_ansi(THEME_REC *theme, char *str, return str; } -static int expand_styles(GString *out, char format, TEXT_DEST_REC *dest) -{ - static const char *backs = "04261537"; - static const char *fores = "kbgcrmyw"; - static const char *boldfores = "KBGCRMYW"; - char *p; - - switch (format) { - case 'U': - /* Underline on/off */ - g_string_append_c(out, 4); - g_string_append_c(out, -1); - g_string_append_c(out, 2); - break; - case '9': - case '_': - /* bold on/off */ - g_string_append_c(out, 4); - g_string_append_c(out, -1); - g_string_append_c(out, 1); - break; - case '8': - /* reverse */ - g_string_append_c(out, 4); - g_string_append_c(out, -1); - g_string_append_c(out, 3); - break; - case '%': - g_string_append_c(out, '%'); - break; - case ':': - /* Newline */ - print_string(dest, out->str); - g_string_truncate(out, 0); - break; - case '|': - /* Indent here */ - g_string_append_c(out, 4); - g_string_append_c(out, -1); - g_string_append_c(out, 4); - break; - case 'F': - /* flashing - ignore */ - break; - case 'N': - /* don't put clear-color tag at the end of the output - ignore */ - break; - case 'n': - /* default color */ - g_string_append_c(out, 4); - g_string_append_c(out, -1); - g_string_append_c(out, -1); - break; - default: - /* check if it's a background color */ - p = strchr(backs, format); - if (p != NULL) { - g_string_append_c(out, 4); - g_string_append_c(out, -2); - g_string_append_c(out, (int) (p-backs)+1); - break; - } - - /* check if it's a foreground color */ - if (format == 'p') format = 'm'; - p = strchr(fores, format); - if (p != NULL) { - g_string_append_c(out, 4); - g_string_append_c(out, (int) (p-fores)+1); - g_string_append_c(out, -2); - break; - } - - /* check if it's a bold foreground color */ - if (format == 'P') format = 'M'; - p = strchr(boldfores, format); - if (p != NULL) { - g_string_append_c(out, 4); - g_string_append_c(out, 8+(int) (p-boldfores)+1); - g_string_append_c(out, -2); - break; - } - - return FALSE; - } - - return TRUE; -} - -static void read_arglist(va_list va, FORMAT_REC *format, - char **arglist, int arglist_size, - char *buffer, int buffer_size) -{ - int num, len, bufpos; - - bufpos = 0; - arglist[format->params] = NULL; - for (num = 0; num < format->params && num < arglist_size; num++) { - switch (format->paramtypes[num]) { - case FORMAT_STRING: - arglist[num] = (char *) va_arg(va, char *); - if (arglist[num] == NULL) { - g_warning("read_arglist() : parameter %d is NULL", num); - arglist[num] = ""; - } - break; - case FORMAT_INT: { - int d = (int) va_arg(va, int); - - if (bufpos >= buffer_size) { - arglist[num] = ""; - break; - } - - arglist[num] = buffer+bufpos; - len = g_snprintf(buffer+bufpos, buffer_size-bufpos, - "%d", d); - bufpos += len+1; - break; - } - case FORMAT_LONG: { - long l = (long) va_arg(va, long); - - if (bufpos >= buffer_size) { - arglist[num] = ""; - break; - } - - arglist[num] = buffer+bufpos; - len = g_snprintf(buffer+bufpos, buffer_size-bufpos, - "%ld", l); - bufpos += len+1; - break; - } - case FORMAT_FLOAT: { - double f = (double) va_arg(va, double); - - if (bufpos >= buffer_size) { - arglist[num] = ""; - break; - } - - arglist[num] = buffer+bufpos; - len = g_snprintf(buffer+bufpos, buffer_size-bufpos, - "%0.2f", f); - bufpos += len+1; - break; - } - } - } -} - -static void create_dest_rec(TEXT_DEST_REC *dest, - void *server, const char *target, - int level, WINDOW_REC *window) -{ - dest->server = server; - dest->target = target; - dest->level = level; - dest->window = window != NULL ? window : - window_find_closest(server, target, level); -} - -char *output_format_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format, - const char *text, va_list va) -{ - GString *out; - char *arglist[10]; - char buffer[200]; /* should be enough? (won't overflow even if it isn't) */ - - char code, *ret; - int need_free; - - /* read all optional arguments to arglist[] list - so they can be used in any order.. */ - read_arglist(va, format, - arglist, sizeof(arglist)/sizeof(void*), - buffer, sizeof(buffer)); - - out = g_string_new(NULL); - - code = 0; - while (*text != '\0') { - if (code == '%') { - /* color code */ - if (!expand_styles(out, *text, dest)) { - g_string_append_c(out, '%'); - g_string_append_c(out, '%'); - g_string_append_c(out, *text); - } - code = 0; - } else if (code == '$') { - /* argument */ - char *ret; - - ret = parse_special((char **) &text, active_win->active_server, - active_win->active, arglist, &need_free, NULL); - - if (ret != NULL) { - /* string shouldn't end with \003 or it could - mess up the next one or two characters */ - int diff; - int len = strlen(ret); - while (len > 0 && ret[len-1] == 3) len--; - diff = strlen(ret)-len; - - g_string_append(out, ret); - if (diff > 0) - g_string_truncate(out, out->len-diff); - if (need_free) g_free(ret); - } - code = 0; - } else { - if (*text == '%' || *text == '$') - code = *text; - else - g_string_append_c(out, *text); - } - - text++; - } - - ret = out->str; - g_string_free(out, FALSE); - return ret; -} - -char *output_format_get_text(const char *module, WINDOW_REC *window, - void *server, const char *target, - int formatnum, ...) -{ - TEXT_DEST_REC dest; - THEME_REC *theme; - MODULE_THEME_REC *module_theme; - FORMAT_REC *formats; - va_list va; - char *ret; - - create_dest_rec(&dest, server, target, 0, window); - theme = dest.window->theme == NULL ? current_theme : - dest.window->theme; - - module_theme = g_hash_table_lookup(theme->modules, module); - formats = g_hash_table_lookup(default_formats, module); - - va_start(va, formatnum); - ret = output_format_text_args(&dest, &formats[formatnum], - module_theme->expanded_formats[formatnum], va); - va_end(va); - - return ret; -} - -static char *output_format_text(TEXT_DEST_REC *dest, int formatnum, ...) -{ - THEME_REC *theme; - MODULE_THEME_REC *module_theme; - va_list va; - char *ret; - - theme = dest->window->theme == NULL ? current_theme : - dest->window->theme; - module_theme = g_hash_table_lookup(theme->modules, MODULE_NAME); - - va_start(va, formatnum); - ret = output_format_text_args(dest, &fecommon_core_formats[formatnum], - module_theme->expanded_formats[formatnum], va); - va_end(va); - - return ret; -} - void printformat_module_args(const char *module, void *server, const char *target, int level, int formatnum, va_list va) { THEME_REC *theme; - MODULE_THEME_REC *module_theme; TEXT_DEST_REC dest; - FORMAT_REC *formats; char *str; - create_dest_rec(&dest, server, target, level, NULL); + format_create_dest(&dest, server, target, level, NULL); theme = dest.window->theme == NULL ? current_theme : dest.window->theme; signal_emit_id(signal_print_format, 5, theme, module, &dest, GINT_TO_POINTER(formatnum), va); - module_theme = g_hash_table_lookup(theme->modules, module); - formats = g_hash_table_lookup(default_formats, module); - - str = output_format_text_args(&dest, &formats[formatnum], - module_theme->expanded_formats[formatnum], va); - if (*str != '\0') print_string(&dest, str); + str = format_get_text_theme_args(theme, module, &dest, formatnum, va); + if (*str != '\0') print_line(&dest, str); g_free(str); } @@ -490,24 +236,18 @@ void printformat_module_window_args(const char *module, WINDOW_REC *window, int level, int formatnum, va_list va) { THEME_REC *theme; - MODULE_THEME_REC *module_theme; TEXT_DEST_REC dest; - FORMAT_REC *formats; char *str; - create_dest_rec(&dest, NULL, NULL, level, window); + format_create_dest(&dest, NULL, NULL, level, window); theme = window->theme == NULL ? current_theme : window->theme; signal_emit_id(signal_print_format, 5, theme, module, &dest, GINT_TO_POINTER(formatnum), va); - module_theme = g_hash_table_lookup(theme->modules, module); - formats = g_hash_table_lookup(default_formats, module); - - str = output_format_text_args(&dest, &formats[formatnum], - module_theme->expanded_formats[formatnum], va); - if (*str != '\0') print_string(&dest, str); + str = format_get_text_theme_args(theme, module, &dest, formatnum, va); + if (*str != '\0') print_line(&dest, str); g_free(str); } @@ -521,37 +261,16 @@ void printformat_module_window(const char *module, WINDOW_REC *window, va_end(va); } -#define LINE_START_IRSSI_LEVEL \ - (MSGLEVEL_CLIENTERROR | MSGLEVEL_CLIENTNOTICE) - -#define NOT_LINE_START_LEVEL \ - (MSGLEVEL_NEVER | MSGLEVEL_LASTLOG | MSGLEVEL_CLIENTCRAP | \ - MSGLEVEL_MSGS | MSGLEVEL_PUBLIC | MSGLEVEL_DCC | MSGLEVEL_DCCMSGS | \ - MSGLEVEL_ACTIONS | MSGLEVEL_NOTICES | MSGLEVEL_SNOTES | MSGLEVEL_CTCPS) - -/* return the "-!- " text at the start of the line */ -char *get_line_start_text(TEXT_DEST_REC *dest) +static void print_line(TEXT_DEST_REC *dest, const char *text) { - if (dest->level & LINE_START_IRSSI_LEVEL) - return output_format_text(dest, IRCTXT_LINE_START_IRSSI); - - if ((dest->level & NOT_LINE_START_LEVEL) == 0) - return output_format_text(dest, IRCTXT_LINE_START); - - return NULL; -} - -static void print_string(TEXT_DEST_REC *dest, const char *text) -{ - gpointer levelp; + void *levelp; char *str, *tmp; g_return_if_fail(dest != NULL); g_return_if_fail(text != NULL); - tmp = get_line_start_text(dest); - str = tmp == NULL ? (char *) text : - g_strconcat(tmp, text, NULL); + tmp = format_get_line_start(current_theme, dest); + str = format_add_linestart(text, tmp); g_free_not_null(tmp); levelp = GINT_TO_POINTER(dest->level); @@ -562,7 +281,7 @@ static void print_string(TEXT_DEST_REC *dest, const char *text) g_free(tmp); signal_emit_id(signal_print_text, 5, dest->window, dest->server, dest->target, levelp, str); - if (str != text) g_free(str); + g_free(str); } /* append string to `out', expand newlines. */ @@ -572,7 +291,7 @@ static void printtext_append_str(TEXT_DEST_REC *dest, GString *out, const char * if (*str != '\n') g_string_append_c(out, *str); else { - print_string(dest, out->str); + print_line(dest, out->str); g_string_truncate(out, 0); } str++; @@ -631,7 +350,7 @@ static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va break; } default: - if (!expand_styles(out, *str, dest)) { + if (!format_expand_styles(out, *str, dest)) { g_string_append_c(out, '%'); g_string_append_c(out, *str); } @@ -653,13 +372,13 @@ void printtext(void *server, const char *target, int level, const char *text, .. g_return_if_fail(text != NULL); - create_dest_rec(&dest, server, target, level, NULL); + format_create_dest(&dest, server, target, level, NULL); va_start(va, text); str = printtext_get_args(&dest, text, va); va_end(va); - print_string(&dest, str); + print_line(&dest, str); g_free(str); } @@ -671,14 +390,14 @@ void printtext_window(WINDOW_REC *window, int level, const char *text, ...) g_return_if_fail(text != NULL); - create_dest_rec(&dest, NULL, NULL, level, - window != NULL ? window : active_win); + format_create_dest(&dest, NULL, NULL, level, + window != NULL ? window : active_win); va_start(va, text); str = printtext_get_args(&dest, text, va); va_end(va); - print_string(&dest, str); + print_line(&dest, str); g_free(str); } @@ -715,9 +434,10 @@ static char *get_timestamp(TEXT_DEST_REC *dest) } tm = localtime(&t); - return output_format_text(dest, IRCTXT_TIMESTAMP, - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); + return format_get_text_theme(NULL, MODULE_NAME, dest, IRCTXT_TIMESTAMP, + tm->tm_year+1900, + tm->tm_mon+1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); } static char *get_server_tag(TEXT_DEST_REC *dest) @@ -730,7 +450,8 @@ static char *get_server_tag(TEXT_DEST_REC *dest) (dest->window->active != NULL && dest->window->active->server == server)) return NULL; - return output_format_text(dest, IRCTXT_SERVERTAG, server->tag); + return format_get_text_theme(NULL, MODULE_NAME, dest, + IRCTXT_SERVERTAG, server->tag); } static void msg_beep_check(SERVER_REC *server, int level) @@ -742,197 +463,166 @@ static void msg_beep_check(SERVER_REC *server, int level) } } +static char *fix_line_start(TEXT_DEST_REC *dest, const char *text) +{ + char *timestamp, *servertag; + char *linestart, *str; + + timestamp = get_timestamp(dest); + servertag = get_server_tag(dest); + + if (timestamp == NULL && servertag == NULL) + return g_strdup(text); + + linestart = g_strconcat(timestamp != NULL ? timestamp : "", + servertag, NULL); + str = format_add_linestart(text, linestart); + g_free(linestart); + + g_free_not_null(timestamp); + g_free_not_null(servertag); + return str; +} + static void sig_print_text(WINDOW_REC *window, SERVER_REC *server, const char *target, gpointer level, const char *text) { - TEXT_DEST_REC dest; - char *dup, *ptr, type, *str, *timestamp, *servertag; - int fgcolor, bgcolor; - int flags; - - g_return_if_fail(text != NULL); - g_return_if_fail(window != NULL); - - create_dest_rec(&dest, server, target, GPOINTER_TO_INT(level), window); - msg_beep_check(server, dest.level); - - flags = 0; fgcolor = -1; bgcolor = -1; type = '\0'; - window->last_line = time(NULL); - newline(window); - - timestamp = get_timestamp(&dest); - servertag = get_server_tag(&dest); - str = g_strconcat(timestamp != NULL ? timestamp : "", - servertag != NULL ? servertag : "", - text, NULL); - g_free_not_null(timestamp); - g_free_not_null(servertag); - - dup = str; - while (*str != '\0') - { - for (ptr = str; *ptr != '\0'; ptr++) - { - if (is_color_code(*ptr)) - { - type = *ptr; - *ptr++ = '\0'; - break; - } - - *ptr = (char) translation_in[(gint) (guchar) *ptr]; - } + TEXT_DEST_REC dest; + char *dup, *ptr, type, *str; + int fgcolor, bgcolor; + int flags; - if (type == 7) - { - /* bell */ - if (settings_get_bool("bell_beeps")) - flags |= PRINTFLAG_BEEP; - } - if (*str != '\0' || flags & PRINTFLAG_BEEP) - { - signal_emit_id(signal_gui_print_text, 6, window, - GINT_TO_POINTER(fgcolor), GINT_TO_POINTER(bgcolor), - GINT_TO_POINTER(flags), str, level); - flags &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT); - } - if (*ptr == '\0') break; - - switch (type) - { - case 2: - /* bold */ - if (!hide_text_style) - flags ^= PRINTFLAG_BOLD; - break; - case 6: - /* blink */ - if (!hide_text_style) - flags ^= PRINTFLAG_BLINK; - break; - case 15: - /* remove all styling */ - flags &= PRINTFLAG_BEEP; - fgcolor = bgcolor = -1; - break; - case 22: - /* reverse */ - if (!hide_text_style) - flags ^= PRINTFLAG_REVERSE; - break; - case 31: - /* underline */ - if (!hide_text_style) - flags ^= PRINTFLAG_UNDERLINE; - case 27: - /* ansi color code */ - ptr = convert_ansi(window->theme == NULL ? current_theme : - window->theme, ptr, &fgcolor, &bgcolor, &flags); - break; - case 4: - /* user specific colors */ - flags &= ~PRINTFLAG_MIRC_COLOR; - if ((signed char) *ptr == -1) - { - ptr++; - if ((signed char) *ptr == -1) - { - fgcolor = bgcolor = -1; - flags &= PRINTFLAG_INDENT; - } - else if (*ptr == 1) - flags ^= PRINTFLAG_BOLD; - else if (*ptr == 2) - flags ^= PRINTFLAG_UNDERLINE; - else if (*ptr == 3) - flags ^= PRINTFLAG_REVERSE; - else if (*ptr == 4) - flags |= PRINTFLAG_INDENT; - } - else - { - if ((signed char) *ptr != -2) - { - fgcolor = (guchar) *ptr-1; - if (fgcolor <= 7) - flags &= ~PRINTFLAG_BOLD; - else - { - /* bold */ - if (fgcolor != 8) fgcolor -= 8; - flags |= PRINTFLAG_BOLD; + g_return_if_fail(text != NULL); + g_return_if_fail(window != NULL); + + format_create_dest(&dest, server, target, + GPOINTER_TO_INT(level), window); + msg_beep_check(server, dest.level); + + window->last_line = time(NULL); + newline(window); + + dup = str = fix_line_start(&dest, text); + flags = 0; fgcolor = -1; bgcolor = -1; type = '\0'; + while (*str != '\0') { + for (ptr = str; *ptr != '\0'; ptr++) { + if (IS_COLOR_CODE(*ptr)) { + type = *ptr; + *ptr++ = '\0'; + break; } - } - ptr++; - if ((signed char) *ptr != -2) - bgcolor = (signed char) *ptr == -1 ? -1 : *ptr-1; - } - ptr++; - break; - case 3: - if (*ptr < 17) - { - /* mostly just for irssi's internal use.. */ - fgcolor = (*ptr++)-1; - if (*ptr == 0 || *ptr >= 17) - bgcolor = -1; - else - bgcolor = (*ptr++)-1; - if (fgcolor & 8) - flags |= PRINTFLAG_BOLD; - else - flags &= ~PRINTFLAG_BOLD; - break; - } - /* MIRC color */ - if (hide_text_style) - { - /* don't show them. */ - skip_mirc_color(&ptr); - break; - } + *ptr = (char) translation_in[(int) (unsigned char) *ptr]; + } - flags |= PRINTFLAG_MIRC_COLOR; - if (!isdigit((gint) *ptr) && *ptr != ',') - { - fgcolor = -1; - bgcolor = -1; + if (type == 7) { + /* bell */ + if (settings_get_bool("bell_beeps")) + flags |= PRINTFLAG_BEEP; } - else + if (*str != '\0' || flags & PRINTFLAG_BEEP) { + /* send the text to gui handler */ + signal_emit_id(signal_gui_print_text, 6, window, + GINT_TO_POINTER(fgcolor), + GINT_TO_POINTER(bgcolor), + GINT_TO_POINTER(flags), str, level); + flags &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT); + } + + if (*ptr == '\0') + break; + + switch (type) { - /* foreground color */ - if (*ptr != ',') - { - fgcolor = *ptr++-'0'; - if (isdigit((gint) *ptr)) - fgcolor = fgcolor*10 + (*ptr++-'0'); - } - if (*ptr == ',') - { - /* back color */ - bgcolor = 0; - if (!isdigit((gint) *++ptr)) - bgcolor = -1; - else - { - bgcolor = *ptr++-'0'; - if (isdigit((gint) *ptr)) - bgcolor = bgcolor*10 + (*ptr++-'0'); + case 2: + /* bold */ + if (!hide_text_style) + flags ^= PRINTFLAG_BOLD; + break; + case 6: + /* blink */ + if (!hide_text_style) + flags ^= PRINTFLAG_BLINK; + break; + case 15: + /* remove all styling */ + flags &= PRINTFLAG_BEEP; + fgcolor = bgcolor = -1; + break; + case 22: + /* reverse */ + if (!hide_text_style) + flags ^= PRINTFLAG_REVERSE; + break; + case 31: + /* underline */ + if (!hide_text_style) + flags ^= PRINTFLAG_UNDERLINE; + case 27: + /* ansi color code */ + ptr = get_ansi_color(window->theme == NULL ? + current_theme : window->theme, + ptr, + hide_text_style ? NULL : &fgcolor, + hide_text_style ? NULL : &bgcolor, + hide_text_style ? NULL : &flags); + break; + case 4: + /* user specific colors */ + flags &= ~PRINTFLAG_MIRC_COLOR; + switch (*ptr) { + case FORMAT_STYLE_UNDERLINE: + flags ^= PRINTFLAG_UNDERLINE; + break; + case FORMAT_STYLE_BOLD: + flags ^= PRINTFLAG_BOLD; + break; + case FORMAT_STYLE_REVERSE: + flags ^= PRINTFLAG_REVERSE; + break; + case FORMAT_STYLE_INDENT: + flags |= PRINTFLAG_INDENT; + break; + case FORMAT_STYLE_DEFAULTS: + fgcolor = bgcolor = -1; + flags &= PRINTFLAG_INDENT; + break; + default: + if (*ptr != FORMAT_COLOR_NOCHANGE) { + fgcolor = (unsigned char) *ptr-'0'; + if (fgcolor <= 7) + flags &= ~PRINTFLAG_BOLD; + else { + /* bold */ + if (fgcolor != 8) fgcolor -= 8; + flags |= PRINTFLAG_BOLD; + } + } + ptr++; + if (*ptr != FORMAT_COLOR_NOCHANGE) + bgcolor = *ptr-'0'; } - } + ptr++; + break; + case 3: + /* MIRC color */ + get_mirc_color((const char **) &ptr, + hide_text_style ? NULL : &fgcolor, + hide_text_style ? NULL : &bgcolor); + if (!hide_text_style) + flags |= PRINTFLAG_MIRC_COLOR; + break; } - break; - } - str = ptr; - } - g_free(dup); - signal_emit_id(signal_print_text_finished, 1, window); + str = ptr; + } + g_free(dup); + signal_emit_id(signal_print_text_finished, 1, window); } -void printtext_multiline(void *server, const char *target, int level, const char *format, const char *text) +void printtext_multiline(void *server, const char *target, int level, + const char *format, const char *text) { char **lines, **tmp; diff --git a/src/fe-common/core/printtext.h b/src/fe-common/core/printtext.h index e75a105a..9ec79023 100644 --- a/src/fe-common/core/printtext.h +++ b/src/fe-common/core/printtext.h @@ -3,21 +3,6 @@ #include "windows.h" -enum { - FORMAT_STRING, - FORMAT_INT, - FORMAT_LONG, - FORMAT_FLOAT -}; - -typedef struct { - char *tag; - char *def; - - int params; - int paramtypes[10]; -} FORMAT_REC; - #define PRINTFLAG_BOLD 0x01 #define PRINTFLAG_REVERSE 0x02 #define PRINTFLAG_UNDERLINE 0x04 @@ -26,10 +11,6 @@ typedef struct { #define PRINTFLAG_MIRC_COLOR 0x20 #define PRINTFLAG_INDENT 0x40 -char *output_format_get_text(const char *module, WINDOW_REC *window, - void *server, const char *target, - int formatnum, ...); - void printformat_module(const char *module, void *server, const char *target, int level, int formatnum, ...); void printformat_module_window(const char *module, WINDOW_REC *window, int level, int formatnum, ...); @@ -67,9 +48,10 @@ void printtext_deinit(void); printformat_module_window(MODULE_NAME, window, level, formatnum, __VA_ARGS__) #else /* inline/static */ -static #ifdef G_CAN_INLINE -inline +G_INLINE_FUNC +#else +static #endif void printformat(void *server, const char *target, int level, int formatnum, ...) { @@ -80,9 +62,10 @@ void printformat(void *server, const char *target, int level, int formatnum, ... va_end(va); } -static #ifdef G_CAN_INLINE -inline +G_INLINE_FUNC +#else +static #endif void printformat_window(WINDOW_REC *window, int level, int formatnum, ...) { @@ -94,18 +77,4 @@ void printformat_window(WINDOW_REC *window, int level, int formatnum, ...) } #endif -/* semi-private functions.. */ -typedef struct { - WINDOW_REC *window; - void *server; - const char *target; - int level; -} TEXT_DEST_REC; - -char *output_format_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format, - const char *text, va_list va); - -/* return the "-!- " text at the start of the line */ -char *get_line_start_text(TEXT_DEST_REC *dest); - #endif diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c index c9026e46..24685c17 100644 --- a/src/fe-common/core/themes.c +++ b/src/fe-common/core/themes.c @@ -29,6 +29,7 @@ #include "settings.h" #include "themes.h" +#include "printtext.h" GSList *themes; THEME_REC *current_theme; diff --git a/src/fe-common/core/themes.h b/src/fe-common/core/themes.h index c5e48355..cfca4c0d 100644 --- a/src/fe-common/core/themes.h +++ b/src/fe-common/core/themes.h @@ -1,8 +1,6 @@ #ifndef __THEMES_H #define __THEMES_H -#include "printtext.h" - typedef struct { char *name; @@ -26,6 +24,8 @@ typedef struct { void *gui_data; } THEME_REC; +typedef struct _FORMAT_REC FORMAT_REC; + extern GSList *themes; extern THEME_REC *current_theme; extern GHashTable *default_formats; diff --git a/src/fe-common/core/window-commands.c b/src/fe-common/core/window-commands.c index 60fa1c9b..b9ef8450 100644 --- a/src/fe-common/core/window-commands.c +++ b/src/fe-common/core/window-commands.c @@ -31,6 +31,7 @@ #include "windows.h" #include "window-items.h" #include "window-save.h" +#include "printtext.h" static void cmd_window(const char *data, void *server, WI_ITEM_REC *item) { diff --git a/src/fe-common/core/window-items.c b/src/fe-common/core/window-items.c index 443ca586..52065d86 100644 --- a/src/fe-common/core/window-items.c +++ b/src/fe-common/core/window-items.c @@ -29,6 +29,7 @@ #include "windows.h" #include "window-items.h" +#include "printtext.h" void window_add_item(WINDOW_REC *window, WI_ITEM_REC *item, int automatic) { diff --git a/src/fe-common/irc/dcc/fe-dcc.c b/src/fe-common/irc/dcc/fe-dcc.c index 08869107..bcd6ae34 100644 --- a/src/fe-common/irc/dcc/fe-dcc.c +++ b/src/fe-common/irc/dcc/fe-dcc.c @@ -35,6 +35,7 @@ #include "windows.h" #include "module-formats.h" +#include "printtext.h" static void dcc_connected(DCC_REC *dcc) { diff --git a/src/fe-common/irc/dcc/module-formats.c b/src/fe-common/irc/dcc/module-formats.c index 4fe22dbd..3994e9d3 100644 --- a/src/fe-common/irc/dcc/module-formats.c +++ b/src/fe-common/irc/dcc/module-formats.c @@ -19,7 +19,7 @@ */ #include "module.h" -#include "printtext.h" +#include "formats.h" FORMAT_REC fecommon_irc_dcc_formats[] = { { MODULE_NAME, "IRC", 0 }, diff --git a/src/fe-common/irc/dcc/module-formats.h b/src/fe-common/irc/dcc/module-formats.h index ac07846d..f1a89e62 100644 --- a/src/fe-common/irc/dcc/module-formats.h +++ b/src/fe-common/irc/dcc/module-formats.h @@ -1,4 +1,4 @@ -#include "printtext.h" +#include "formats.h" enum { IRCTXT_MODULE_NAME, diff --git a/src/fe-common/irc/fe-ctcp.c b/src/fe-common/irc/fe-ctcp.c index 1c2ed843..02703883 100644 --- a/src/fe-common/irc/fe-ctcp.c +++ b/src/fe-common/irc/fe-ctcp.c @@ -32,6 +32,7 @@ #include "windows.h" #include "window-items.h" +#include "printtext.h" static void ctcp_print(const char *pre, const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target) { diff --git a/src/fe-common/irc/fe-events-numeric.c b/src/fe-common/irc/fe-events-numeric.c index 0bc6d245..fb506d68 100644 --- a/src/fe-common/irc/fe-events-numeric.c +++ b/src/fe-common/irc/fe-events-numeric.c @@ -30,6 +30,8 @@ #include "irc-channels.h" #include "nicklist.h" +#include "printtext.h" + static char *last_away_nick = NULL; static char *last_away_msg = NULL; @@ -96,10 +98,10 @@ static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist, gint it memset(linebuf, ' ', max); nickmode[0] = rec->op ? '@' : rec->voice ? '+' : ' '; memcpy(linebuf, rec->nick, strlen(rec->nick)); - ret = output_format_get_text(MODULE_NAME, NULL, - channel->server, channel->name, - IRCTXT_NAMES_NICK, nickmode, linebuf); - g_string_append(str, ret); + ret = format_get_text(MODULE_NAME, NULL, + channel->server, channel->name, + IRCTXT_NAMES_NICK, nickmode, linebuf); + g_string_append(str, ret); g_free(ret); cols++; } diff --git a/src/fe-common/irc/fe-events.c b/src/fe-common/irc/fe-events.c index acce8c20..4e1c70f7 100644 --- a/src/fe-common/irc/fe-events.c +++ b/src/fe-common/irc/fe-events.c @@ -36,6 +36,7 @@ #include "irc-channels.h" #include "irc-nicklist.h" #include "windows.h" +#include "printtext.h" #include "completion.h" diff --git a/src/fe-common/irc/fe-irc-channels.c b/src/fe-common/irc/fe-irc-channels.c index 8a7de92d..ef9a79b8 100644 --- a/src/fe-common/irc/fe-irc-channels.c +++ b/src/fe-common/irc/fe-irc-channels.c @@ -28,6 +28,8 @@ #include "irc.h" #include "channel-rejoin.h" +#include "printtext.h" + static void sig_channel_rejoin(IRC_SERVER_REC *server, REJOIN_REC *rec) { g_return_if_fail(rec != NULL); diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c index aae3bbc1..43bf0e94 100644 --- a/src/fe-common/irc/fe-irc-commands.c +++ b/src/fe-common/irc/fe-irc-commands.c @@ -36,6 +36,7 @@ #include "fe-queries.h" #include "windows.h" #include "window-items.h" +#include "printtext.h" /* SYNTAX: ME <message> */ static void cmd_me(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) diff --git a/src/fe-common/irc/fe-irc-server.c b/src/fe-common/irc/fe-irc-server.c index ace02feb..635391c4 100644 --- a/src/fe-common/irc/fe-irc-server.c +++ b/src/fe-common/irc/fe-irc-server.c @@ -32,6 +32,7 @@ #include "irc-servers-setup.h" #include "windows.h" +#include "printtext.h" static void sig_server_add_create(IRC_SERVER_SETUP_REC **rec, GHashTable *optlist) diff --git a/src/fe-common/irc/fe-ircnet.c b/src/fe-common/irc/fe-ircnet.c index 090c8a61..99dd7a69 100644 --- a/src/fe-common/irc/fe-ircnet.c +++ b/src/fe-common/irc/fe-ircnet.c @@ -28,6 +28,7 @@ #include "irc-servers.h" #include "irc-chatnets.h" +#include "printtext.h" static void cmd_ircnet_list(void) { diff --git a/src/fe-common/irc/fe-netjoin.c b/src/fe-common/irc/fe-netjoin.c index 9ce718db..40b43dcb 100644 --- a/src/fe-common/irc/fe-netjoin.c +++ b/src/fe-common/irc/fe-netjoin.c @@ -31,6 +31,8 @@ #include "ignore.h" #include "netsplit.h" +#include "printtext.h" + #define NETJOIN_WAIT_TIME 2 /* how many seconds to wait for the netsplitted JOIN messages to stop */ #define NETJOIN_MAX_WAIT 30 /* how many seconds to wait for nick to join to the rest of the channels she was before the netsplit */ diff --git a/src/fe-common/irc/fe-netsplit.c b/src/fe-common/irc/fe-netsplit.c index a756ea7a..4b3a19a6 100644 --- a/src/fe-common/irc/fe-netsplit.c +++ b/src/fe-common/irc/fe-netsplit.c @@ -30,6 +30,8 @@ #include "ignore.h" #include "netsplit.h" +#include "printtext.h" + #define SPLIT_WAIT_TIME 2 /* how many seconds to wait for the QUIT split messages to stop */ static int split_tag; diff --git a/src/fe-common/irc/flood/fe-flood.c b/src/fe-common/irc/flood/fe-flood.c index ce96699f..7f5a0ee5 100644 --- a/src/fe-common/irc/flood/fe-flood.c +++ b/src/fe-common/irc/flood/fe-flood.c @@ -27,6 +27,7 @@ #include "irc/flood/autoignore.h" #include "themes.h" +#include "printtext.h" static void event_autoignore_new(IRC_SERVER_REC *server, AUTOIGNORE_REC *ignore) { diff --git a/src/fe-common/irc/flood/module-formats.c b/src/fe-common/irc/flood/module-formats.c index 2cca360f..29b76ace 100644 --- a/src/fe-common/irc/flood/module-formats.c +++ b/src/fe-common/irc/flood/module-formats.c @@ -19,7 +19,7 @@ */ #include "module.h" -#include "printtext.h" +#include "formats.h" FORMAT_REC fecommon_irc_flood_formats[] = { diff --git a/src/fe-common/irc/flood/module-formats.h b/src/fe-common/irc/flood/module-formats.h index 7386dd2a..73e313ba 100644 --- a/src/fe-common/irc/flood/module-formats.h +++ b/src/fe-common/irc/flood/module-formats.h @@ -1,4 +1,4 @@ -#include "printtext.h" +#include "formats.h" enum { IRCTXT_MODULE_NAME, diff --git a/src/fe-common/irc/module-formats.c b/src/fe-common/irc/module-formats.c index 01197397..4229faff 100644 --- a/src/fe-common/irc/module-formats.c +++ b/src/fe-common/irc/module-formats.c @@ -19,7 +19,7 @@ */ #include "module.h" -#include "printtext.h" +#include "formats.h" FORMAT_REC fecommon_irc_formats[] = { { MODULE_NAME, "IRC", 0 }, diff --git a/src/fe-common/irc/module-formats.h b/src/fe-common/irc/module-formats.h index 4bf14185..c1ad6d9d 100644 --- a/src/fe-common/irc/module-formats.h +++ b/src/fe-common/irc/module-formats.h @@ -1,4 +1,4 @@ -#include "printtext.h" +#include "formats.h" enum { IRCTXT_MODULE_NAME, diff --git a/src/fe-common/irc/notifylist/fe-notifylist.c b/src/fe-common/irc/notifylist/fe-notifylist.c index cd9adf9c..a408fb15 100644 --- a/src/fe-common/irc/notifylist/fe-notifylist.c +++ b/src/fe-common/irc/notifylist/fe-notifylist.c @@ -33,6 +33,7 @@ #include "irc/notifylist/notifylist.h" #include "themes.h" +#include "printtext.h" /* add the nick of a hostmask to list if it isn't there already */ static GSList *mask_add_once(GSList *list, const char *mask) diff --git a/src/fe-common/irc/notifylist/module-formats.c b/src/fe-common/irc/notifylist/module-formats.c index 345dfe24..0b29406e 100644 --- a/src/fe-common/irc/notifylist/module-formats.c +++ b/src/fe-common/irc/notifylist/module-formats.c @@ -19,7 +19,7 @@ */ #include "module.h" -#include "printtext.h" +#include "formats.h" FORMAT_REC fecommon_irc_notifylist_formats[] = { diff --git a/src/fe-common/irc/notifylist/module-formats.h b/src/fe-common/irc/notifylist/module-formats.h index e37045f1..e934def3 100644 --- a/src/fe-common/irc/notifylist/module-formats.h +++ b/src/fe-common/irc/notifylist/module-formats.h @@ -1,4 +1,4 @@ -#include "printtext.h" +#include "formats.h" enum { IRCTXT_MODULE_NAME, diff --git a/src/fe-text/gui-textwidget.c b/src/fe-text/gui-textwidget.c index 9b16e691..04055bb4 100644 --- a/src/fe-text/gui-textwidget.c +++ b/src/fe-text/gui-textwidget.c @@ -28,6 +28,7 @@ #include "irc-servers.h" #include "windows.h" +#include "printtext.h" #include "screen.h" #include "gui-windows.h" @@ -56,8 +57,8 @@ static gchar *gui_window_line2text(LINE_REC *line) { /* set color */ color = *ptr; - g_string_sprintfa(str, "\003%c%c", (color & 0x07)+1, ((color & 0xf0) >> 4)+1); - if (color & 0x08) g_string_sprintfa(str, "\002"); + g_string_sprintfa(str, "\004%c%c", (color & 0x0f)+'0', + ((color & 0xf0) >> 4)+'0'); } else switch ((guchar) *ptr) { @@ -73,16 +74,19 @@ static gchar *gui_window_line2text(LINE_REC *line) g_string_append_c(str, 31); break; case LINE_CMD_COLOR0: - g_string_sprintfa(str, "\003%c%c", 1, ((color & 0xf0) >> 4)+1); + g_string_sprintfa(str, "\004%c%c", + '0', ((color & 0xf0) >> 4)+'0'); break; case LINE_CMD_COLOR8: - g_string_sprintfa(str, "\003%c%c", 9, ((color & 0xf0) >> 4)+1); + g_string_sprintfa(str, "\004%c%c", + '8', ((color & 0xf0) >> 4)+'0'); color &= 0xfff0; color |= 8|ATTR_COLOR8; break; case LINE_CMD_BLINK: color |= 0x80; - g_string_sprintfa(str, "\003%c%c", (color & 0x0f)+1, ((color & 0xf0) >> 4)+1); + g_string_sprintfa(str, "\004%c%c", (color & 0x0f)+'0', + ((color & 0xf0) >> 4)+'0'); break; case LINE_CMD_INDENT: break; diff --git a/src/fe-text/mainwindows.c b/src/fe-text/mainwindows.c index 2ba547dc..48bbf0b9 100644 --- a/src/fe-text/mainwindows.c +++ b/src/fe-text/mainwindows.c @@ -24,6 +24,7 @@ #include "commands.h" #include "levels.h" #include "misc.h" +#include "printtext.h" #include "screen.h" #include "statusbar.h" diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c index 4114ca50..935e6eee 100644 --- a/src/fe-text/module-formats.c +++ b/src/fe-text/module-formats.c @@ -19,7 +19,7 @@ */ #include "module.h" -#include "printtext.h" +#include "formats.h" FORMAT_REC gui_text_formats[] = { diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h index 2af040eb..06d02727 100644 --- a/src/fe-text/module-formats.h +++ b/src/fe-text/module-formats.h @@ -1,4 +1,4 @@ -#include "printtext.h" +#include "formats.h" enum { IRCTXT_MODULE_NAME, |