/* fe-ignore.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "module.h" #include #include #include #include #include #include #include #include #include static char *ignore_get_key(IGNORE_REC *rec) { char *chans, *ret; if (rec->channels == NULL) return g_strdup(rec->mask != NULL ? rec->mask : "*" ); chans = g_strjoinv(",", rec->channels); if (rec->mask == NULL) return chans; ret = g_strdup_printf("%s %s", rec->mask, chans); g_free(chans); return ret; } static void ignore_print(int index, IGNORE_REC *rec) { GString *options; char *key, *levels; struct tm ts; char buf[20]; key = ignore_get_key(rec); levels = bits2level(rec->level); options = g_string_new(NULL); if (rec->exception) g_string_append(options, "-except "); if (rec->regexp) { g_string_append(options, "-regexp "); if (rec->pattern == NULL) g_string_append(options, "[INVALID! -pattern missing] "); else if (rec->preg == NULL) g_string_append(options, "[INVALID!] "); } if (rec->fullword) g_string_append(options, "-full "); if (rec->replies) g_string_append(options, "-replies "); if (rec->servertag != NULL) g_string_append_printf(options, "-network %s ", rec->servertag); if (rec->pattern != NULL) g_string_append_printf(options, "-pattern %s ", rec->pattern); if (rec->unignore_time != 0) { ts = *localtime(&rec->unignore_time); strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &ts); g_string_append_printf(options, "ignore ends: %s ", buf); } if (options->len > 1) g_string_truncate(options, options->len-1); if (index >= 0) { printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_IGNORE_LINE, index, key != NULL ? key : "", levels != NULL ? levels : "", options->str); } else { printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, options->len > 0 ? TXT_IGNORED_OPTIONS : TXT_IGNORED, key != NULL ? key : "", levels != NULL ? levels : "", options->str); } g_string_free(options, TRUE); g_free(key); g_free(levels); } static void cmd_ignore_show(void) { GSList *tmp; int index; if (ignores == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_IGNORE_NO_IGNORES); return; } printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_IGNORE_HEADER); index = 1; for (tmp = ignores; tmp != NULL; tmp = tmp->next, index++) { IGNORE_REC *rec = tmp->data; ignore_print(index, rec); } printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_IGNORE_FOOTER); } /* SYNTAX: IGNORE [-regexp | -full] [-pattern ] [-except] [-replies] [-network ] [-channels ] [-time