void ekg_debug_handler(int level, const char *format, va_list ap) { static GString *line = NULL; char *tmp = NULL; char *theme_format; int is_UI = 0; if (!config_debug) return; if (line) { g_string_append_vprintf(line, format, ap); if (line->len == 0 || line->str[line->len - 1] != '\n') return; line->str[line->len - 1] = '\0'; /* remove '\n' */ tmp = g_string_free(line, FALSE); line = NULL; } else { int tmplen = g_vasprintf(&tmp, format, ap); if (tmplen < 0 || !tmp) /* OutOfMemory? */ return; if (tmplen == 0 || tmp[tmplen - 1] != '\n') { line = g_string_new_len(tmp, tmplen); g_free(tmp); return; } tmp[tmplen - 1] = 0; /* remove '\n' */ } switch(level) { case 0: theme_format = "debug"; break; case DEBUG_IO: theme_format = "iodebug"; break; case DEBUG_IORECV: theme_format = "iorecvdebug"; break; case DEBUG_FUNCTION: theme_format = "fdebug"; break; case DEBUG_ERROR: theme_format = "edebug"; break; case DEBUG_WHITE: theme_format = "wdebug"; break; case DEBUG_WARN: theme_format = "warndebug"; break; case DEBUG_OK: theme_format = "okdebug"; break; default: theme_format = "debug"; break; } ekg_fix_utf8(tmp); /* debug message can contain random data */ buffer_add(&buffer_debug, theme_format, tmp); query_emit(NULL, "ui-is-initialized", &is_UI); if (is_UI && window_debug) { print_window_w(window_debug, EKG_WINACT_NONE, theme_format, tmp); } #ifdef STDERR_DEBUG /* STDERR debug */ else fprintf(stderr, "%s\n", tmp); #endif xfree(tmp); }
static void irc_convert_in(irc_private_t *j, GString *line) { gchar **ep; if (j->auto_guess_encoding) { for (ep = j->auto_guess_encoding; *ep; ep++) { if (ekg_try_recode_gstring_from(*ep, line)) return; } } if (j->conv) ekg_recode_gstring_from(j->conv, line); else ekg_fix_utf8(line->str); }
static void logs_buffer_raw_display(window_t *w) { char *line, **lines; logs_log_t *ll; int i, j, n, all = (config_logs_remind_number <= 0); if (!w || !w->session) return; if ((WINDOW_STATUS_ID == w->id) || (WINDOW_CONTACTS_ID == w->id) || (WINDOW_LASTLOG_ID ==w->id )) return; if (!(ll = logs_log_open(session_uid_get(w->session), w->target, TRUE))) return; if (!all) lines = g_new0(char *, config_logs_remind_number + 1); // read log n = 0; fseek(ll->file, 0, SEEK_SET); while ((line = read_file(ll->file, 0))) { ekg_fix_utf8(line); if (all) { time_t t = g_ascii_strtoll(line, &line, 10); if (t>0 && *line == ' ') line++; logs_print_window(w->session, w, line, t); } else { j = n % config_logs_remind_number; g_free(lines[j]); lines[j] = g_strdup(line); n++; } } if (all) { query_emit(NULL, "ui-window-refresh"); return; } ftruncate(fileno(ll->file), 0); // display and rewrite log w->lock++; for (i=0; i < config_logs_remind_number; i++, n++) { time_t t; j = n % config_logs_remind_number; if (!lines[j]) continue; fputs(lines[j], ll->file); fputc('\n', ll->file); t = g_ascii_strtoll(lines[j], &line, 10); if (t>0 && *line == ' ') line++; logs_print_window(w->session, w, line, t); } w->lock--; g_strfreev(lines); query_emit(NULL, "ui-window-refresh"); }