diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 984b3548..1b22cbe5 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -60,15 +60,15 @@ static char **autolog_ignore_targets; static char *log_colorizer_strip(const char *str) { - return strip_codes(str); + return strip_codes(str); } static void log_add_targets(LOG_REC *log, const char *targets, const char *tag) { char **tmp, **items; - g_return_if_fail(log != NULL); - g_return_if_fail(targets != NULL); + g_return_if_fail(log != NULL); + g_return_if_fail(targets != NULL); items = g_strsplit(targets, " ", -1); @@ -83,18 +83,18 @@ static void log_add_targets(LOG_REC *log, const char *targets, const char *tag) [] */ static void cmd_log_open(const char *data) { - SERVER_REC *server; - GHashTable *optlist; + SERVER_REC *server; + GHashTable *optlist; char *targetarg, *fname, *levels, *servertag; void *free_arg; char window[MAX_INT_STRLEN]; LOG_REC *log; int level; - if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | - PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_OPTIONS | - PARAM_FLAG_STRIP_TRAILING_WS, "log open", &optlist, - &fname, &levels)) + if (!cmd_get_params(data, &free_arg, + 2 | PARAM_FLAG_GETREST | PARAM_FLAG_UNKNOWN_OPTIONS | + PARAM_FLAG_OPTIONS | PARAM_FLAG_STRIP_TRAILING_WS, + "log open", &optlist, &fname, &levels)) return; if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); @@ -112,8 +112,7 @@ static void cmd_log_open(const char *data) ltoa(window, active_win->refnum); targetarg = window; } - log_item_add(log, LOG_ITEM_WINDOW_REFNUM, targetarg, - servertag); + log_item_add(log, LOG_ITEM_WINDOW_REFNUM, targetarg, servertag); } else { targetarg = g_hash_table_lookup(optlist, "targets"); if (targetarg != NULL && *targetarg != '\0') @@ -133,14 +132,13 @@ static void cmd_log_open(const char *data) if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) { /* start logging */ if (log_start_logging(log)) { - printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, - TXT_LOG_OPENED, fname); + printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOG_OPENED, fname); } else { log_close(log); } } - cmd_params_free(free_arg); + cmd_params_free(free_arg); } static LOG_REC *log_find_from_data(const char *data) @@ -209,7 +207,7 @@ static char *log_items_get_list(LOG_REC *log) for (tmp = log->items; tmp != NULL; tmp = tmp->next) { rec = tmp->data; - g_string_append_printf(str, "%s, ", rec->name); + g_string_append_printf(str, "%s, ", rec->name); } g_string_truncate(str, str->len-2); if(rec->servertag != NULL) @@ -231,13 +229,11 @@ static void cmd_log_list(void) LOG_REC *rec = tmp->data; levelstr = bits2level(rec->level); - items = rec->items == NULL ? NULL : - log_items_get_list(rec); + items = rec->items == NULL ? NULL : log_items_get_list(rec); - printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_LOG_LIST, - index, rec->fname, items != NULL ? items : "", - levelstr, rec->autoopen ? " -autoopen" : "", - rec->handle != -1 ? " active" : ""); + printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_LOG_LIST, index, rec->fname, + items != NULL ? items : "", levelstr, rec->autoopen ? " -autoopen" : "", + rec->handle != -1 ? " active" : ""); g_free_not_null(items); g_free(levelstr); @@ -253,8 +249,8 @@ static void cmd_log(const char *data, SERVER_REC *server, void *item) command_runsub("log", data, server, item); } -static LOG_REC *logs_find_item(int type, const char *item, - const char *servertag, LOG_ITEM_REC **ret_item) +static LOG_REC *logs_find_item(int type, const char *item, const char *servertag, + LOG_ITEM_REC **ret_item) { LOG_ITEM_REC *logitem; GSList *tmp; @@ -284,17 +280,17 @@ static void cmd_window_log(const char *data) if (!cmd_get_params(data, &free_arg, 2, &set, &fname)) return; - ltoa(window, active_win->refnum); + ltoa(window, active_win->refnum); log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL); - open_log = close_log = FALSE; + open_log = close_log = FALSE; if (g_ascii_strcasecmp(set, "ON") == 0) open_log = TRUE; else if (g_ascii_strcasecmp(set, "OFF") == 0) { close_log = TRUE; } else if (g_ascii_strcasecmp(set, "TOGGLE") == 0) { - open_log = log == NULL; - close_log = log != NULL; + open_log = log == NULL; + close_log = log != NULL; } else { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_NOT_TOGGLE); cmd_params_free(free_arg); @@ -309,7 +305,7 @@ static void cmd_window_log(const char *data) active_win->name != NULL ? "" : window); log = log_create_rec(fname, MSGLEVEL_ALL); log->colorizer = log_colorizer_strip; - log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL); + log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, NULL); log_update(log); g_free(fname); } @@ -322,7 +318,7 @@ static void cmd_window_log(const char *data) printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOG_CLOSED, log->fname); } - cmd_params_free(free_arg); + cmd_params_free(free_arg); } /* Create log file entry to window, but don't start logging */ @@ -332,7 +328,7 @@ static void cmd_window_logfile(const char *data) LOG_REC *log; char window[MAX_INT_STRLEN]; - ltoa(window, active_win->refnum); + ltoa(window, active_win->refnum); log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, window, NULL, NULL); if (log != NULL) { @@ -355,7 +351,7 @@ static void sig_window_refnum_changed(WINDOW_REC *window, gpointer old_refnum) LOG_REC *log; LOG_ITEM_REC *item; - ltoa(winnum, GPOINTER_TO_INT(old_refnum)); + ltoa(winnum, GPOINTER_TO_INT(old_refnum)); log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, winnum, NULL, &item); if (log != NULL) { @@ -368,7 +364,7 @@ static void sig_window_refnum_changed(WINDOW_REC *window, gpointer old_refnum) static void sig_server_disconnected(SERVER_REC *server) { - LOG_ITEM_REC *logitem; + LOG_ITEM_REC *logitem; GSList *tmp, *next; for (tmp = logs; tmp != NULL; tmp = next) { @@ -376,13 +372,13 @@ static void sig_server_disconnected(SERVER_REC *server) next = tmp->next; if (!log->temp || log->items == NULL) - continue; + continue; logitem = log->items->data; - if (logitem->type == LOG_ITEM_TARGET && - logitem->servertag != NULL && + if (logitem->type == LOG_ITEM_TARGET && logitem->servertag != NULL && g_ascii_strcasecmp(logitem->servertag, server->tag) == 0 && - server_ischannel(server, logitem->name)) /* kludge again.. so we won't close dcc chats */ + server_ischannel( + server, logitem->name)) /* kludge again.. so we won't close dcc chats */ log_close(log); } } @@ -414,15 +410,14 @@ static char *escape_target(const char *target) *p++ = *target; } - target++; + target++; } *p = '\0'; - return str; + return str; } -static void autolog_open(SERVER_REC *server, const char *server_tag, - const char *target) +static void autolog_open(SERVER_REC *server, const char *server_tag, const char *target) { LOG_REC *log; char *fname, *dir, *fixed_target, *params; @@ -443,17 +438,16 @@ static void autolog_open(SERVER_REC *server, const char *server_tag, if (CHAT_PROTOCOL(server)->case_insensitive) ascii_strdown(fixed_target); - /* $0 = target, $1 = server tag */ - params = g_strconcat(fixed_target, " ", server_tag, NULL); + /* $0 = target, $1 = server tag */ + params = g_strconcat(fixed_target, " ", server_tag, NULL); g_free(fixed_target); - fname = parse_special_string(autolog_path, server, NULL, - params, NULL, 0); + fname = parse_special_string(autolog_path, server, NULL, params, NULL, 0); g_free(params); if (log_find(fname) == NULL) { log = log_create_rec(fname, autolog_level); - if (!settings_get_bool("autolog_colors")) + if (!settings_get_bool("autolog_colors")) log->colorizer = log_colorizer_strip; log_item_add(log, LOG_ITEM_TARGET, target, server_tag); @@ -484,8 +478,8 @@ static void autolog_open_check(TEXT_DEST_REC *dest) we're parting the channel with /WINDOW CLOSE.. Maybe a small timeout would be nice instead of immediately closing the log file after "window item destroyed" */ - if (level == MSGLEVEL_PARTS || - (autolog_level & level) == 0 || target == NULL || *target == '\0') + if (level == MSGLEVEL_PARTS || (autolog_level & level) == 0 || target == NULL || + *target == '\0') return; deftarget = server ? server->nick : "unknown"; @@ -495,8 +489,7 @@ static void autolog_open_check(TEXT_DEST_REC *dest) && channel_setup_find(target, server_tag) == NULL) return; - if (autolog_ignore_targets != NULL && - strarray_find_dest(autolog_ignore_targets, dest)) + if (autolog_ignore_targets != NULL && strarray_find_dest(autolog_ignore_targets, dest)) return; if (target != NULL) @@ -512,8 +505,7 @@ static void log_single_line(WINDOW_REC *window, const char *server_tag, const ch if (window != NULL) { /* save to log created with /WINDOW LOG */ ltoa(windownum, window->refnum); - log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, - windownum, NULL, NULL); + log = logs_find_item(LOG_ITEM_WINDOW_REFNUM, windownum, NULL, NULL); if (log != NULL) log_write_rec(log, text, level, t); } @@ -553,8 +545,7 @@ static void log_line(TEXT_DEST_REC *dest, const char *text) g_strfreev(lines); } -static void sig_printtext(TEXT_DEST_REC *dest, const char *text, - const char *stripped) +static void sig_printtext(TEXT_DEST_REC *dest, const char *text, const char *stripped) { if (skip_next_printtext) { skip_next_printtext = FALSE; @@ -564,8 +555,8 @@ static void sig_printtext(TEXT_DEST_REC *dest, const char *text, log_line(dest, text); } -static void sig_print_format(THEME_REC *theme, const char *module, - TEXT_DEST_REC *dest, void *formatnum, char **args) +static void sig_print_format(THEME_REC *theme, const char *module, TEXT_DEST_REC *dest, + void *formatnum, char **args) { char *str, *linestart, *tmp; @@ -579,14 +570,14 @@ static void sig_print_format(THEME_REC *theme, const char *module, if (theme == log_theme) return; - str = format_get_text_theme_charargs(log_theme, module, dest, - GPOINTER_TO_INT(formatnum), args); + str = format_get_text_theme_charargs(log_theme, module, dest, GPOINTER_TO_INT(formatnum), + args); if (str != NULL && *str != '\0') { skip_next_printtext = TRUE; /* add the line start format */ linestart = format_get_level_tag(log_theme, dest); - tmp = str; + tmp = str; str = format_add_linestart(tmp, linestart); g_free_not_null(linestart); g_free(tmp); @@ -605,14 +596,14 @@ static int sig_autoremove(void) GSList *tmp, *next; time_t removetime; - removetime = time(NULL)-AUTOLOG_INACTIVITY_CLOSE; + removetime = time(NULL) - AUTOLOG_INACTIVITY_CLOSE; for (tmp = logs; tmp != NULL; tmp = next) { LOG_REC *log = tmp->data; next = tmp->next; if (!log->temp || log->last > removetime || log->items == NULL) - continue; + continue; /* Close only logs with private messages */ logitem = log->items->data; @@ -620,8 +611,8 @@ static int sig_autoremove(void) continue; server = server_find_tag(logitem->servertag); - if (logitem->type == LOG_ITEM_TARGET && - server != NULL && !server_ischannel(server, logitem->name)) + if (logitem->type == LOG_ITEM_TARGET && server != NULL && + !server_ischannel(server, logitem->name)) log_close(log); } return 1; @@ -632,43 +623,40 @@ static void sig_window_item_remove(WINDOW_REC *window, WI_ITEM_REC *item) LOG_REC *log; log = logs_find_item(LOG_ITEM_TARGET, item->visible_name, - item->server == NULL ? NULL : - item->server->tag, NULL); + item->server == NULL ? NULL : item->server->tag, NULL); if (log != NULL && log->temp) log_close(log); } static void sig_log_locked(LOG_REC *log) { - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, - TXT_LOG_LOCKED, log->real_fname); + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_LOG_LOCKED, log->real_fname); } static void sig_log_create_failed(LOG_REC *log) { - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, - TXT_LOG_CREATE_FAILED, - log->real_fname, g_strerror(errno)); + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_LOG_CREATE_FAILED, log->real_fname, + g_strerror(errno)); } static void sig_log_new(LOG_REC *log) { if (!settings_get_bool("awaylog_colors") && g_strcmp0(log->fname, settings_get_str("awaylog_file")) == 0) - log->colorizer = log_colorizer_strip; + log->colorizer = log_colorizer_strip; } static void sig_log_config_read(LOG_REC *log, CONFIG_NODE *node) { - if (!config_node_get_bool(node, "colors", FALSE)) + if (!config_node_get_bool(node, "colors", FALSE)) log->colorizer = log_colorizer_strip; } static void sig_log_config_save(LOG_REC *log, CONFIG_NODE *node) { - if (log->colorizer == NULL) + if (log->colorizer == NULL) iconfig_node_set_bool(node, "colors", TRUE); - else + else iconfig_node_set_str(node, "colors", NULL); } @@ -685,7 +673,7 @@ static void sig_awaylog_show(LOG_REC *log, gpointer pmsgs, gpointer pfilepos) else { printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOG_AWAY_MSGS, log->real_fname, msgs); - str = g_strdup_printf("\"%s\" %d", log->real_fname, filepos); + str = g_strdup_printf("\"%s\" %d", log->real_fname, filepos); signal_emit("command cat", 1, str); g_free(str); } @@ -746,13 +734,13 @@ void fe_log_init(void) skip_next_printtext = FALSE; settings_add_bool("log", "awaylog_colors", TRUE); - settings_add_bool("log", "autolog", FALSE); + settings_add_bool("log", "autolog", FALSE); settings_add_bool("log", "autolog_colors", FALSE); settings_add_bool("log", "autolog_only_saved_channels", FALSE); settings_add_choice("log", "log_server_time", 2, "off;on;auto"); settings_add_str("log", "autolog_path", "~/irclogs/$tag/$0.log"); settings_add_level("log", "autolog_level", "all -crap -clientcrap -ctcps"); - settings_add_str("log", "log_theme", ""); + settings_add_str("log", "log_theme", ""); settings_add_str("log", "autolog_ignore_targets", ""); autolog_level = 0;