mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Moved /LASTLOG handling to lastlog.c. Added options -file <filename>
for writing lastlog to file, -window <ref#|name> for specifying which window's lastlog to print (output is always to active window) and -clear option to remove all lastlog lines from window. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1255 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
1191bc2c2c
commit
6b4a838813
@ -26,6 +26,7 @@ irssi_SOURCES = \
|
||||
gui-readline.c \
|
||||
gui-textwidget.c \
|
||||
gui-windows.c \
|
||||
lastlog.c \
|
||||
mainwindows.c \
|
||||
mainwindow-activity.c \
|
||||
mainwindows-save.c \
|
||||
|
@ -165,13 +165,18 @@ void gui_window_line_text_free(GUI_WINDOW_REC *gui, LINE_REC *line)
|
||||
|
||||
/* free the last block */
|
||||
chunk = text_chunk_find(gui, text);
|
||||
if (--chunk->lines == 0)
|
||||
text_chunk_free(gui, chunk);
|
||||
if (--chunk->lines == 0) {
|
||||
if (gui->cur_text == chunk)
|
||||
chunk->pos = 0;
|
||||
else
|
||||
text_chunk_free(gui, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line)
|
||||
void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line, int redraw)
|
||||
{
|
||||
GUI_WINDOW_REC *gui;
|
||||
GUI_WINDOW_REC *gui;
|
||||
GList *last;
|
||||
int screenchange;
|
||||
|
||||
g_return_if_fail(window != NULL);
|
||||
@ -179,6 +184,10 @@ void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line)
|
||||
|
||||
gui = WINDOW_GUI(window);
|
||||
|
||||
screenchange = g_list_find(gui->startline, line) != NULL;
|
||||
if (screenchange) gui->ypos -= gui_window_get_linecount(gui, line);
|
||||
|
||||
gui_window_cache_remove(gui, line);
|
||||
gui_window_line_text_free(gui, line);
|
||||
if (gui->lastlog_last_check != NULL &&
|
||||
gui->lastlog_last_check->data == line)
|
||||
@ -187,20 +196,12 @@ void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line)
|
||||
gui->lastlog_last_away->data == line)
|
||||
gui->lastlog_last_away = NULL;
|
||||
|
||||
screenchange = g_list_find(gui->startline, line) != NULL;
|
||||
if (screenchange) gui->ypos--;
|
||||
|
||||
if (gui->startline->data == line) {
|
||||
/* first line in screen removed */
|
||||
if (gui->startline->next != NULL) {
|
||||
gui->startline = gui->startline->next;
|
||||
gui->subline = 0;
|
||||
} else {
|
||||
gui->startline = gui->startline->prev;
|
||||
gui->subline = gui->last_subline+1;
|
||||
gui->ypos = -1;
|
||||
}
|
||||
}
|
||||
last = g_list_last(gui->bottom_startline);
|
||||
if (last->data == line) {
|
||||
/* removing last line */
|
||||
gui->last_subline =
|
||||
gui_window_get_linecount(gui, last->prev->data)-1;
|
||||
}
|
||||
|
||||
if (gui->bottom_startline->data == line) {
|
||||
/* bottom line removed */
|
||||
@ -213,6 +214,20 @@ void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line)
|
||||
}
|
||||
}
|
||||
|
||||
if (gui->startline->data == line) {
|
||||
/* first line in screen removed */
|
||||
if (gui->startline->next != NULL) {
|
||||
gui->startline = gui->startline->next;
|
||||
gui->subline = 0;
|
||||
} else {
|
||||
gui->startline = gui->startline->prev;
|
||||
gui->subline = gui->last_subline+1;
|
||||
gui->ypos = -1;
|
||||
gui->empty_linecount = gui->parent->lines;
|
||||
gui->bottom = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
window->lines--;
|
||||
g_mem_chunk_free(gui->line_chunk, line);
|
||||
gui->lines = g_list_remove(gui->lines, line);
|
||||
@ -220,7 +235,7 @@ void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line)
|
||||
if (window->lines == 0)
|
||||
gui_window_clear(window);
|
||||
|
||||
if (screenchange && is_window_visible(window))
|
||||
if (redraw && screenchange && is_window_visible(window))
|
||||
gui_window_redraw(window);
|
||||
}
|
||||
|
||||
@ -255,7 +270,7 @@ static void remove_old_lines(WINDOW_REC *window)
|
||||
/* too new line, don't remove yet */
|
||||
break;
|
||||
}
|
||||
gui_window_line_remove(window, line);
|
||||
gui_window_line_remove(window, line, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -404,7 +419,8 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
|
||||
gui->eol_marked = FALSE;
|
||||
|
||||
line = create_line(gui, 0);
|
||||
if (gui->temp_line == NULL || g_list_find(gui->startline, gui->temp_line) != NULL)
|
||||
if (gui->temp_line == NULL ||
|
||||
g_list_find(gui->startline, gui->temp_line) != NULL)
|
||||
gui_window_newline(gui, visible);
|
||||
|
||||
gui->last_subline = 0;
|
||||
|
@ -30,7 +30,7 @@ void gui_printtext_init(void);
|
||||
void gui_printtext_deinit(void);
|
||||
|
||||
void gui_window_line_append(GUI_WINDOW_REC *gui, const char *str, int len);
|
||||
void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line);
|
||||
void gui_window_line_remove(WINDOW_REC *window, LINE_REC *line, int redraw);
|
||||
void gui_window_line_text_free(GUI_WINDOW_REC *gui, LINE_REC *line);
|
||||
|
||||
void gui_printtext(int xpos, int ypos, const char *str, ...);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
gui-textwidget.c : irssi
|
||||
|
||||
Copyright (C) 1999 Timo Sirainen
|
||||
Copyright (C) 1999-2001 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
|
||||
@ -19,234 +19,15 @@
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "module-formats.h"
|
||||
#include "signals.h"
|
||||
#include "commands.h"
|
||||
#include "misc.h"
|
||||
#include "levels.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "irc-servers.h"
|
||||
#include "fe-windows.h"
|
||||
#include "servers.h"
|
||||
#include "printtext.h"
|
||||
|
||||
#include "screen.h"
|
||||
#include "gui-windows.h"
|
||||
|
||||
static gchar *gui_window_line2text(LINE_REC *line)
|
||||
{
|
||||
GString *str;
|
||||
gint color;
|
||||
gchar *ret, *ptr, *tmp;
|
||||
|
||||
g_return_val_if_fail(line != NULL, NULL);
|
||||
|
||||
str = g_string_new(NULL);
|
||||
|
||||
color = 0;
|
||||
for (ptr = line->text; ; ptr++)
|
||||
{
|
||||
if (*ptr != 0)
|
||||
{
|
||||
g_string_append_c(str, *ptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
if ((*ptr & 0x80) == 0)
|
||||
{
|
||||
/* set color */
|
||||
color = *ptr;
|
||||
g_string_sprintfa(str, "\004%c%c", (color & 0x0f)+'0',
|
||||
((color & 0xf0) >> 4)+'0');
|
||||
}
|
||||
else switch ((guchar) *ptr)
|
||||
{
|
||||
case LINE_CMD_EOL:
|
||||
case LINE_CMD_FORMAT:
|
||||
ret = str->str;
|
||||
g_string_free(str, FALSE);
|
||||
return ret;
|
||||
case LINE_CMD_CONTINUE:
|
||||
memcpy(&tmp, ptr+1, sizeof(gchar *));
|
||||
ptr = tmp-1;
|
||||
break;
|
||||
case LINE_CMD_UNDERLINE:
|
||||
g_string_append_c(str, 31);
|
||||
break;
|
||||
case LINE_CMD_COLOR0:
|
||||
g_string_sprintfa(str, "\004%c%c",
|
||||
'0', ((color & 0xf0) >> 4)+'0');
|
||||
break;
|
||||
case LINE_CMD_COLOR8:
|
||||
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, "\004%c%c", (color & 0x0f)+'0',
|
||||
((color & 0xf0) >> 4)+'0');
|
||||
break;
|
||||
case LINE_CMD_INDENT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define LASTLOG_FLAG_NEW_LAST 0x01
|
||||
#define LASTLOG_FLAG_NEW_AWAY 0x02
|
||||
#define LASTLOG_FLAG_NOHEADERS 0x04
|
||||
#define LASTLOG_FLAG_WORD 0x08
|
||||
#define LASTLOG_FLAG_REGEXP 0x10
|
||||
|
||||
static int lastlog_parse_options(GHashTable *options, int *flags)
|
||||
{
|
||||
GSList *list, *tmp;
|
||||
int level, optlevel;
|
||||
|
||||
/* move all keys from `options' to linked list */
|
||||
list = hashtable_get_keys(options);
|
||||
|
||||
/* level can be specified in arguments.. */
|
||||
level = 0; *flags = 0;
|
||||
for (tmp = list; tmp != NULL; tmp = tmp->next) {
|
||||
char *opt = tmp->data;
|
||||
|
||||
if (strcmp(opt, "-") == 0)
|
||||
*flags |= LASTLOG_FLAG_NOHEADERS;
|
||||
else if (g_strcasecmp(opt, "new") == 0)
|
||||
*flags |= LASTLOG_FLAG_NEW_LAST;
|
||||
else if (g_strcasecmp(opt, "away") == 0)
|
||||
*flags |= LASTLOG_FLAG_NEW_AWAY;
|
||||
else if (g_strcasecmp(opt, "word") == 0)
|
||||
*flags |= LASTLOG_FLAG_WORD;
|
||||
else if (g_strcasecmp(opt, "regexp") == 0)
|
||||
*flags |= LASTLOG_FLAG_REGEXP;
|
||||
else {
|
||||
optlevel = level2bits(opt);
|
||||
if (optlevel != 0)
|
||||
level |= optlevel;
|
||||
else {
|
||||
signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN), opt);
|
||||
level = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (level == 0) level = MSGLEVEL_ALL;
|
||||
|
||||
g_slist_free(list);
|
||||
return level;
|
||||
}
|
||||
|
||||
#define lastlog_match(line, level) \
|
||||
(((line)->level & level) != 0 && ((line)->level & MSGLEVEL_LASTLOG) == 0)
|
||||
|
||||
static GList *lastlog_find_startline(GList *list, int count, int start, int level)
|
||||
{
|
||||
GList *tmp;
|
||||
|
||||
if (count <= 0) return list;
|
||||
|
||||
for (tmp = g_list_last(list); tmp != NULL; tmp = tmp->prev) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if (!lastlog_match(rec, level))
|
||||
continue;
|
||||
|
||||
if (start > 0) {
|
||||
start--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (--count == 0)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/* SYNTAX: LASTLOG [-] [-new | -away] [-regexp | -word] [-<levels>]
|
||||
[<pattern>] [<count> [<start>]] */
|
||||
static void cmd_lastlog(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
GList *startline, *list, *tmp;
|
||||
char *str, *text, *countstr, *start;
|
||||
void *free_arg;
|
||||
struct tm *tm;
|
||||
int level, flags, count;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS,
|
||||
"lastlog", &optlist, &text, &countstr, &start))
|
||||
return;
|
||||
|
||||
if (*start == '\0' && is_numeric(text, 0)) {
|
||||
if (is_numeric(countstr, 0))
|
||||
start = countstr;
|
||||
countstr = text;
|
||||
text = "";
|
||||
}
|
||||
count = atoi(countstr);
|
||||
if (count == 0) count = -1;
|
||||
|
||||
level = lastlog_parse_options(optlist, &flags);
|
||||
if (level == -1) {
|
||||
/* error in options */
|
||||
cmd_params_free(free_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((flags & LASTLOG_FLAG_NOHEADERS) == 0)
|
||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START);
|
||||
|
||||
if (flags & LASTLOG_FLAG_NEW_LAST)
|
||||
startline = WINDOW_GUI(active_win)->lastlog_last_check;
|
||||
else if (flags & LASTLOG_FLAG_NEW_AWAY)
|
||||
startline = WINDOW_GUI(active_win)->lastlog_last_away;
|
||||
else
|
||||
startline = NULL;
|
||||
if (startline == NULL) startline = WINDOW_GUI(active_win)->lines;
|
||||
|
||||
list = gui_window_find_text(active_win, text, startline, flags & LASTLOG_FLAG_REGEXP, flags & LASTLOG_FLAG_WORD);
|
||||
tmp = lastlog_find_startline(list, count, atoi(start), level);
|
||||
|
||||
for (; tmp != NULL && (count < 0 || count > 0); tmp = tmp->next) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if (!lastlog_match(rec, level))
|
||||
continue;
|
||||
count--;
|
||||
|
||||
text = gui_window_line2text(rec);
|
||||
if (settings_get_bool("timestamps"))
|
||||
printtext(NULL, NULL, MSGLEVEL_LASTLOG, "%s", text);
|
||||
else {
|
||||
tm = localtime(&rec->time);
|
||||
|
||||
str = g_strdup_printf("[%02d:%02d] %s", tm->tm_hour, tm->tm_min, text);
|
||||
printtext(NULL, NULL, MSGLEVEL_LASTLOG, "%s", str);
|
||||
g_free(str);
|
||||
}
|
||||
g_free(text);
|
||||
}
|
||||
|
||||
if ((flags & LASTLOG_FLAG_NOHEADERS) == 0)
|
||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END);
|
||||
|
||||
WINDOW_GUI(active_win)->lastlog_last_check =
|
||||
g_list_last(WINDOW_GUI(active_win)->bottom_startline);
|
||||
|
||||
g_list_free(list);
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
static void cmd_scrollback(gchar *data, SERVER_REC *server, WI_ITEM_REC *item)
|
||||
{
|
||||
command_runsub("scrollback", data, server, item);
|
||||
@ -461,7 +242,7 @@ static void cmd_scrollback_status(void)
|
||||
total_lines, total_kb);
|
||||
}
|
||||
|
||||
static void sig_away_changed(IRC_SERVER_REC *server)
|
||||
static void sig_away_changed(SERVER_REC *server)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
@ -478,7 +259,6 @@ static void sig_away_changed(IRC_SERVER_REC *server)
|
||||
|
||||
void gui_textwidget_init(void)
|
||||
{
|
||||
command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog);
|
||||
command_bind("scrollback", NULL, (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_bind("scrollback clear", NULL, (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_bind("scrollback goto", NULL, (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
@ -486,14 +266,12 @@ void gui_textwidget_init(void)
|
||||
command_bind("scrollback end", NULL, (SIGNAL_FUNC) cmd_scrollback_end);
|
||||
command_bind("scrollback redraw", NULL, (SIGNAL_FUNC) cmd_scrollback_redraw);
|
||||
command_bind("scrollback status", NULL, (SIGNAL_FUNC) cmd_scrollback_status);
|
||||
command_set_options("lastlog", "!- new away word regexp");
|
||||
|
||||
signal_add("away mode changed", (SIGNAL_FUNC) sig_away_changed);
|
||||
}
|
||||
|
||||
void gui_textwidget_deinit(void)
|
||||
{
|
||||
command_unbind("lastlog", (SIGNAL_FUNC) cmd_lastlog);
|
||||
command_unbind("scrollback", (SIGNAL_FUNC) cmd_scrollback);
|
||||
command_unbind("scrollback clear", (SIGNAL_FUNC) cmd_scrollback_clear);
|
||||
command_unbind("scrollback goto", (SIGNAL_FUNC) cmd_scrollback_goto);
|
||||
|
@ -789,7 +789,8 @@ static void signal_window_changed(WINDOW_REC *window)
|
||||
screen_refresh_thaw();
|
||||
}
|
||||
|
||||
GList *gui_window_find_text(WINDOW_REC *window, gchar *text, GList *startline, int regexp, int fullword)
|
||||
GList *gui_window_find_text(WINDOW_REC *window, const char *text,
|
||||
GList *startline, int regexp, int fullword)
|
||||
{
|
||||
#ifdef HAVE_REGEX_H
|
||||
regex_t preg;
|
||||
@ -1130,7 +1131,7 @@ void gui_window_reformat_line(WINDOW_REC *window, LINE_REC *line)
|
||||
raw->str[1] == (char)LINE_CMD_FORMAT_CONT) {
|
||||
/* multiline format, format explained in one the
|
||||
following lines. remove this line. */
|
||||
gui_window_line_remove(window, line);
|
||||
gui_window_line_remove(window, line, FALSE);
|
||||
} else if (str != NULL) {
|
||||
/* FIXME: ugly ugly .. and this can't handle
|
||||
non-formatted lines.. */
|
||||
|
@ -97,7 +97,8 @@ void gui_windows_deinit(void);
|
||||
WINDOW_REC *gui_window_create(MAIN_WINDOW_REC *parent);
|
||||
|
||||
void gui_window_set_server(WINDOW_REC *window, SERVER_REC *server);
|
||||
GList *gui_window_find_text(WINDOW_REC *window, char *text, GList *startline, int regexp, int fullword);
|
||||
GList *gui_window_find_text(WINDOW_REC *window, const char *text,
|
||||
GList *startline, int regexp, int fullword);
|
||||
|
||||
/* get number of real lines that line record takes */
|
||||
int gui_window_get_linecount(GUI_WINDOW_REC *gui, LINE_REC *line);
|
||||
|
@ -58,6 +58,9 @@ void gui_expandos_deinit(void);
|
||||
void gui_textwidget_init(void);
|
||||
void gui_textwidget_deinit(void);
|
||||
|
||||
void lastlog_init(void);
|
||||
void lastlog_deinit(void);
|
||||
|
||||
void mainwindow_activity_init(void);
|
||||
void mainwindow_activity_deinit(void);
|
||||
|
||||
@ -126,6 +129,7 @@ static void textui_finish_init(void)
|
||||
gui_printtext_init();
|
||||
gui_readline_init();
|
||||
gui_textwidget_init();
|
||||
lastlog_init();
|
||||
mainwindows_init();
|
||||
mainwindow_activity_init();
|
||||
mainwindows_save_init();
|
||||
@ -162,6 +166,7 @@ static void textui_deinit(void)
|
||||
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
|
||||
|
||||
gui_textwidget_deinit();
|
||||
lastlog_deinit();
|
||||
statusbar_deinit();
|
||||
gui_printtext_deinit();
|
||||
gui_readline_deinit();
|
||||
|
332
src/fe-text/lastlog.c
Normal file
332
src/fe-text/lastlog.c
Normal file
@ -0,0 +1,332 @@
|
||||
/*
|
||||
lastlog.c : irssi
|
||||
|
||||
Copyright (C) 1999-2001 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 "signals.h"
|
||||
#include "commands.h"
|
||||
#include "misc.h"
|
||||
#include "levels.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "module-formats.h"
|
||||
#include "printtext.h"
|
||||
|
||||
#include "gui-windows.h"
|
||||
#include "gui-printtext.h"
|
||||
|
||||
static void window_lastlog_clear(WINDOW_REC *window)
|
||||
{
|
||||
GList *tmp, *next;
|
||||
|
||||
for (tmp = WINDOW_GUI(window)->lines; tmp != NULL; tmp = next) {
|
||||
LINE_REC *line = tmp->data;
|
||||
|
||||
next = tmp->next;
|
||||
if (line->level & MSGLEVEL_LASTLOG)
|
||||
gui_window_line_remove(window, line, FALSE);
|
||||
}
|
||||
gui_window_redraw(window);
|
||||
}
|
||||
|
||||
static char *gui_window_line2text(LINE_REC *line, int coloring)
|
||||
{
|
||||
GString *str;
|
||||
int color;
|
||||
char *ret, *ptr, *tmp;
|
||||
|
||||
g_return_val_if_fail(line != NULL, NULL);
|
||||
|
||||
str = g_string_new(NULL);
|
||||
|
||||
color = 0;
|
||||
for (ptr = line->text; ; ptr++) {
|
||||
if (*ptr != 0) {
|
||||
g_string_append_c(str, *ptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
if (!coloring) {
|
||||
/* no colors, handle only commands that don't
|
||||
have anything to do with colors */
|
||||
switch ((unsigned char) *ptr) {
|
||||
case LINE_CMD_EOL:
|
||||
case LINE_CMD_FORMAT:
|
||||
ret = str->str;
|
||||
g_string_free(str, FALSE);
|
||||
return ret;
|
||||
case LINE_CMD_CONTINUE:
|
||||
memcpy(&tmp, ptr+1, sizeof(char *));
|
||||
ptr = tmp-1;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*ptr & 0x80) == 0) {
|
||||
/* set color */
|
||||
color = *ptr;
|
||||
g_string_sprintfa(str, "\004%c%c", (color & 0x0f)+'0',
|
||||
((color & 0xf0) >> 4)+'0');
|
||||
}
|
||||
else switch ((unsigned char) *ptr)
|
||||
{
|
||||
case LINE_CMD_EOL:
|
||||
case LINE_CMD_FORMAT:
|
||||
ret = str->str;
|
||||
g_string_free(str, FALSE);
|
||||
return ret;
|
||||
case LINE_CMD_CONTINUE:
|
||||
memcpy(&tmp, ptr+1, sizeof(char *));
|
||||
ptr = tmp-1;
|
||||
break;
|
||||
case LINE_CMD_UNDERLINE:
|
||||
g_string_append_c(str, 31);
|
||||
break;
|
||||
case LINE_CMD_COLOR0:
|
||||
g_string_sprintfa(str, "\004%c%c",
|
||||
'0', ((color & 0xf0) >> 4)+'0');
|
||||
break;
|
||||
case LINE_CMD_COLOR8:
|
||||
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, "\004%c%c", (color & 0x0f)+'0',
|
||||
((color & 0xf0) >> 4)+'0');
|
||||
break;
|
||||
case LINE_CMD_INDENT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Only unknown keys in `optlist' should be levels.
|
||||
Returns -1 if unknown option was given. */
|
||||
int cmd_options_get_level(const char *cmd, GHashTable *optlist)
|
||||
{
|
||||
GSList *list, *tmp, *next;
|
||||
int level, retlevel;
|
||||
|
||||
/* get all the options, then remove the known ones. there should
|
||||
be only one left - the server tag. */
|
||||
list = hashtable_get_keys(optlist);
|
||||
if (cmd != NULL) {
|
||||
for (tmp = list; tmp != NULL; tmp = next) {
|
||||
char *option = tmp->data;
|
||||
next = tmp->next;
|
||||
|
||||
if (command_have_option(cmd, option))
|
||||
list = g_slist_remove(list, option);
|
||||
}
|
||||
}
|
||||
|
||||
retlevel = 0;
|
||||
while (list != NULL) {
|
||||
level = level_get(list->data);
|
||||
if (level == 0) {
|
||||
/* unknown option */
|
||||
signal_emit("error command", 2,
|
||||
GINT_TO_POINTER(CMDERR_OPTION_UNKNOWN),
|
||||
list->data);
|
||||
retlevel = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
retlevel |= level;
|
||||
list = g_slist_remove(list, list->data);
|
||||
}
|
||||
|
||||
return retlevel;
|
||||
}
|
||||
|
||||
#define lastlog_match(line, level) \
|
||||
(((line)->level & level) != 0 && ((line)->level & MSGLEVEL_LASTLOG) == 0)
|
||||
|
||||
static GList *lastlog_find_startline(GList *list, int count, int start, int level)
|
||||
{
|
||||
GList *tmp;
|
||||
|
||||
if (count <= 0) return list;
|
||||
|
||||
for (tmp = g_list_last(list); tmp != NULL; tmp = tmp->prev) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if (!lastlog_match(rec, level))
|
||||
continue;
|
||||
|
||||
if (start > 0) {
|
||||
start--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (--count == 0)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
||||
int start, int count)
|
||||
{
|
||||
WINDOW_REC *window;
|
||||
GList *startline, *list, *tmp;
|
||||
char *str, *line;
|
||||
int level, fhandle;
|
||||
|
||||
level = cmd_options_get_level("lastlog", optlist);
|
||||
if (level == -1) return; /* error in options */
|
||||
if (level == 0) level = MSGLEVEL_ALL;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "clear") != NULL) {
|
||||
window_lastlog_clear(active_win);
|
||||
if (*searchtext == '\0')
|
||||
return;
|
||||
}
|
||||
|
||||
/* target where to print it */
|
||||
fhandle = -1;
|
||||
str = g_hash_table_lookup(optlist, "file");
|
||||
if (str != NULL) {
|
||||
str = convert_home(str);
|
||||
fhandle = open(str, O_WRONLY | O_APPEND | O_CREAT,
|
||||
octal2dec(settings_get_int("log_create_mode")));
|
||||
g_free(str);
|
||||
|
||||
if (fhandle == -1) {
|
||||
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
|
||||
"%s", g_strerror(errno));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fhandle == -1 && g_hash_table_lookup(optlist, "-") == NULL)
|
||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START);
|
||||
|
||||
/* which window's lastlog to look at? */
|
||||
window = active_win;
|
||||
str = g_hash_table_lookup(optlist, "window");
|
||||
if (str != NULL) {
|
||||
window = is_numeric(str, '\0') ?
|
||||
window_find_refnum(atoi(str)) :
|
||||
window_find_item(NULL, str);
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(optlist, "new") != NULL)
|
||||
startline = WINDOW_GUI(window)->lastlog_last_check;
|
||||
else if (g_hash_table_lookup(optlist, "away") != NULL)
|
||||
startline = WINDOW_GUI(window)->lastlog_last_away;
|
||||
else
|
||||
startline = NULL;
|
||||
if (startline == NULL) startline = WINDOW_GUI(window)->lines;
|
||||
|
||||
list = gui_window_find_text(window, searchtext, startline,
|
||||
g_hash_table_lookup(optlist, "regexp") != NULL,
|
||||
g_hash_table_lookup(optlist, "word") != NULL);
|
||||
tmp = lastlog_find_startline(list, count, start, level);
|
||||
|
||||
for (; tmp != NULL && (count < 0 || count > 0); tmp = tmp->next) {
|
||||
LINE_REC *rec = tmp->data;
|
||||
|
||||
if (!lastlog_match(rec, level))
|
||||
continue;
|
||||
count--;
|
||||
|
||||
/* get the line text */
|
||||
line = gui_window_line2text(rec, fhandle == -1);
|
||||
if (settings_get_bool("timestamps"))
|
||||
str = line;
|
||||
else {
|
||||
struct tm *tm = localtime(&rec->time);
|
||||
str = g_strdup_printf("%02d:%02d %s",
|
||||
tm->tm_hour, tm->tm_min, line);
|
||||
}
|
||||
|
||||
/* write to file/window */
|
||||
if (fhandle != -1) {
|
||||
write(fhandle, line, strlen(line));
|
||||
write(fhandle, "\n", 1);
|
||||
} else {
|
||||
printtext_window(active_win, MSGLEVEL_LASTLOG,
|
||||
"%s", line);
|
||||
}
|
||||
|
||||
if (str != line) g_free(str);
|
||||
g_free(line);
|
||||
}
|
||||
|
||||
if (fhandle == -1 && g_hash_table_lookup(optlist, "-") == NULL)
|
||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END);
|
||||
|
||||
if (fhandle != -1)
|
||||
close(fhandle);
|
||||
|
||||
WINDOW_GUI(window)->lastlog_last_check =
|
||||
g_list_last(WINDOW_GUI(window)->bottom_startline);
|
||||
|
||||
g_list_free(list);
|
||||
}
|
||||
|
||||
/* SYNTAX: LASTLOG [-] [-file <filename>] [-clear] [-<level> -<level...>]
|
||||
[-new | -away] [-regexp | -word]
|
||||
[<pattern>] [<count> [<start>]] */
|
||||
static void cmd_lastlog(const char *data)
|
||||
{
|
||||
GHashTable *optlist;
|
||||
char *text, *countstr, *start;
|
||||
void *free_arg;
|
||||
int count;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS | PARAM_FLAG_UNKNOWN_OPTIONS,
|
||||
"lastlog", &optlist, &text, &countstr, &start))
|
||||
return;
|
||||
|
||||
if (*start == '\0' && is_numeric(text, 0)) {
|
||||
if (is_numeric(countstr, 0))
|
||||
start = countstr;
|
||||
countstr = text;
|
||||
text = "";
|
||||
}
|
||||
count = atoi(countstr);
|
||||
if (count == 0) count = -1;
|
||||
|
||||
show_lastlog(text, optlist, atoi(start), count);
|
||||
cmd_params_free(free_arg);
|
||||
}
|
||||
|
||||
void lastlog_init(void)
|
||||
{
|
||||
command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog);
|
||||
|
||||
command_set_options("lastlog", "!- clear -file -window new away word regexp");
|
||||
}
|
||||
|
||||
void lastlog_deinit(void)
|
||||
{
|
||||
command_unbind("lastlog", (SIGNAL_FUNC) cmd_lastlog);
|
||||
}
|
Loading…
Reference in New Issue
Block a user