int rbe_lines;
if (!rbe)
return i - 1;
-// fprintf(stderr, "found: %s\n", rbe->msg);
rbe_lines = NUM_LINES(rbe->len);
if (rbe_lines > bot.lines)
return -1;
new->len = len;
new->msg = msg;
old = ringbuffer_add(bot_win_rb, new);
-// fprintf(stderr, "added: %s\n", new->msg);
if (old) {
free(old->msg);
free(old);
static __printf_2_3 void curses_log(int ll, const char *fmt,...)
{
- int color;
- char *msg;
va_list ap;
- unsigned bytes;
- if (ll < loglevel || !curses_active())
+ if (ll < loglevel)
return;
- switch (ll) {
- case LL_DEBUG:
- case LL_INFO:
- case LL_NOTICE:
- color = COLOR_MSG;
- break;
- default:
- color = COLOR_ERRMSG;
- }
va_start(ap, fmt);
- bytes = xvasprintf(&msg, fmt, ap);
+ if (curses_active()) {
+ int color = ll <= LL_NOTICE? COLOR_MSG : COLOR_ERRMSG;
+ char *msg;
+ unsigned bytes = xvasprintf(&msg, fmt, ap);
+ if (bytes > 0 && msg[bytes - 1] == '\n')
+ msg[bytes - 1] = '\0'; /* cut trailing newline */
+ rb_add_entry(color, msg);
+ wrefresh(bot.win);
+ } else if (cmd_pid <= 0) /* no external command running */
+ vfprintf(stderr, fmt, ap);
va_end(ap);
- if (bytes > 0 && msg[bytes - 1] == '\n')
- msg[bytes - 1] = '\0'; /* cut trailing newline */
- rb_add_entry(color, msg);
- wrefresh(bot.win);
}
__printf_2_3 void (*para_log)(int, const char*, ...) = curses_log;
break;
rbe_lines = NUM_LINES(rbe->len);
lines += rbe_lines;
-// fprintf(stderr, "msg: %s\n", rbe->msg);
wattron(bot.win, COLOR_PAIR(rbe->color));
waddstr(bot.win, "\n");
waddstr(bot.win, rbe->msg);
if (conf.help_given || conf.detailed_help_given)
print_help_and_die();
cf = configfile_exists();
- if (!cf && conf.config_file_given) {
- fprintf(stderr, "can not read config file %s\n",
+ if (!cf && conf.config_file_given)
+ msg_n_exit(EXIT_FAILURE, "can not read config file %s\n",
conf.config_file_arg);
- exit(EXIT_FAILURE);
- }
if (cf) {
struct gui_cmdline_parser_params params = {
.override = 0,
gui_cmdline_parser_config_file(cf, &conf, ¶ms);
loglevel = get_loglevel_by_name(conf.loglevel_arg);
}
- if (check_key_map_args() < 0) {
- fprintf(stderr, "invalid key map\n");
- exit(EXIT_FAILURE);
- }
+ if (check_key_map_args() < 0)
+ msg_n_exit(EXIT_FAILURE, "invalid key map\n");
theme_init(conf.theme_arg, &theme);
setup_signal_handling();
bot_win_rb = ringbuffer_new(RINGBUFFER_SIZE);