mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Merge pull request #1398 from ailin-nemui/lastlog-crash
get line texts before printing lastlog
(cherry picked from commit a57cc1c55e
)
This commit is contained in:
parent
1b6b92ffff
commit
476774662a
@ -87,8 +87,10 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
{
|
{
|
||||||
WINDOW_REC *window;
|
WINDOW_REC *window;
|
||||||
LINE_REC *startline;
|
LINE_REC *startline;
|
||||||
GList *list, *tmp;
|
TEXT_BUFFER_VIEW_REC *view;
|
||||||
GString *line;
|
TEXT_BUFFER_REC *buffer;
|
||||||
|
GSList *texts, *tmp;
|
||||||
|
GList *list, *tmp2;
|
||||||
char *str;
|
char *str;
|
||||||
int level, before, after, len, date = FALSE;
|
int level, before, after, len, date = FALSE;
|
||||||
|
|
||||||
@ -96,8 +98,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
if (level == -1) return; /* error in options */
|
if (level == -1) return; /* error in options */
|
||||||
if (level == 0) level = MSGLEVEL_ALL;
|
if (level == 0) level = MSGLEVEL_ALL;
|
||||||
|
|
||||||
|
view = WINDOW_GUI(active_win)->view;
|
||||||
if (g_hash_table_lookup(optlist, "clear") != NULL) {
|
if (g_hash_table_lookup(optlist, "clear") != NULL) {
|
||||||
textbuffer_view_remove_lines_by_level(WINDOW_GUI(active_win)->view, MSGLEVEL_LASTLOG);
|
textbuffer_view_remove_lines_by_level(view, MSGLEVEL_LASTLOG);
|
||||||
if (*searchtext == '\0')
|
if (*searchtext == '\0')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -117,14 +120,14 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_hash_table_lookup(optlist, "new") != NULL)
|
if (g_hash_table_lookup(optlist, "new") != NULL)
|
||||||
startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_check");
|
startline = textbuffer_view_get_bookmark(view, "lastlog_last_check");
|
||||||
else if (g_hash_table_lookup(optlist, "away") != NULL)
|
else if (g_hash_table_lookup(optlist, "away") != NULL)
|
||||||
startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_away");
|
startline = textbuffer_view_get_bookmark(view, "lastlog_last_away");
|
||||||
else
|
else
|
||||||
startline = NULL;
|
startline = NULL;
|
||||||
|
|
||||||
if (startline == NULL)
|
if (startline == NULL)
|
||||||
startline = textbuffer_view_get_lines(WINDOW_GUI(window)->view);
|
startline = textbuffer_view_get_lines(view);
|
||||||
|
|
||||||
str = g_hash_table_lookup(optlist, "#");
|
str = g_hash_table_lookup(optlist, "#");
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
@ -143,22 +146,21 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
if (g_hash_table_lookup(optlist, "date") != NULL)
|
if (g_hash_table_lookup(optlist, "date") != NULL)
|
||||||
date = TRUE;
|
date = TRUE;
|
||||||
|
|
||||||
list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline,
|
buffer = view->buffer;
|
||||||
level, MSGLEVEL_LASTLOG,
|
list = textbuffer_find_text(buffer, startline, level, MSGLEVEL_LASTLOG, searchtext, before,
|
||||||
searchtext, before, after,
|
after, g_hash_table_lookup(optlist, "regexp") != NULL,
|
||||||
g_hash_table_lookup(optlist, "regexp") != NULL,
|
|
||||||
g_hash_table_lookup(optlist, "word") != NULL,
|
g_hash_table_lookup(optlist, "word") != NULL,
|
||||||
g_hash_table_lookup(optlist, "case") != NULL);
|
g_hash_table_lookup(optlist, "case") != NULL);
|
||||||
|
|
||||||
len = g_list_length(list);
|
len = g_list_length(list);
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
tmp = list;
|
tmp2 = list;
|
||||||
else {
|
else {
|
||||||
int pos = len-count-start;
|
int pos = len-count-start;
|
||||||
if (pos < 0) pos = 0;
|
if (pos < 0) pos = 0;
|
||||||
|
|
||||||
tmp = pos > len ? NULL : g_list_nth(list, pos);
|
tmp2 = pos > len ? NULL : g_list_nth(list, pos);
|
||||||
len = g_list_length(tmp);
|
len = g_list_length(tmp2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_hash_table_lookup(optlist, "count") != NULL) {
|
if (g_hash_table_lookup(optlist, "count") != NULL) {
|
||||||
@ -177,29 +179,21 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL)
|
/* collect the line texts */
|
||||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START);
|
texts = NULL;
|
||||||
|
for (; tmp2 != NULL && (count < 0 || count > 0); tmp2 = tmp2->next) {
|
||||||
line = g_string_new(NULL);
|
GString *line;
|
||||||
while (tmp != NULL && (count < 0 || count > 0)) {
|
LINE_REC *rec = tmp2->data;
|
||||||
LINE_REC *rec = tmp->data;
|
|
||||||
|
|
||||||
if (rec == NULL) {
|
if (rec == NULL) {
|
||||||
if (tmp->next == NULL)
|
if (tmp2->next == NULL)
|
||||||
break;
|
break;
|
||||||
if (fhandle != NULL) {
|
texts = g_slist_prepend(texts, NULL);
|
||||||
fwrite("--\n", 3, 1, fhandle);
|
|
||||||
} else {
|
|
||||||
printformat_window(active_win,
|
|
||||||
MSGLEVEL_LASTLOG,
|
|
||||||
TXT_LASTLOG_SEPARATOR);
|
|
||||||
}
|
|
||||||
tmp = tmp->next;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the line text */
|
line = g_string_new(NULL);
|
||||||
textbuffer_line2text(WINDOW_GUI(window)->view->buffer, rec, fhandle == NULL, line);
|
textbuffer_line2text(buffer, rec, fhandle == NULL, line);
|
||||||
if (!settings_get_bool("timestamps")) {
|
if (!settings_get_bool("timestamps")) {
|
||||||
struct tm *tm = localtime(&rec->info.time);
|
struct tm *tm = localtime(&rec->info.time);
|
||||||
char timestamp[10];
|
char timestamp[10];
|
||||||
@ -213,6 +207,30 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
if (date == TRUE)
|
if (date == TRUE)
|
||||||
prepend_date(window, rec, line);
|
prepend_date(window, rec, line);
|
||||||
|
|
||||||
|
texts = g_slist_prepend(texts, line);
|
||||||
|
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
texts = g_slist_reverse(texts);
|
||||||
|
|
||||||
|
if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL)
|
||||||
|
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START);
|
||||||
|
|
||||||
|
for (tmp = texts; tmp != NULL; tmp = tmp->next) {
|
||||||
|
GString *line = tmp->data;
|
||||||
|
|
||||||
|
if (line == NULL) {
|
||||||
|
if (tmp->next == NULL)
|
||||||
|
break;
|
||||||
|
if (fhandle != NULL) {
|
||||||
|
fwrite("--\n", 3, 1, fhandle);
|
||||||
|
} else {
|
||||||
|
printformat_window(active_win, MSGLEVEL_LASTLOG,
|
||||||
|
TXT_LASTLOG_SEPARATOR);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* write to file/window */
|
/* write to file/window */
|
||||||
if (fhandle != NULL) {
|
if (fhandle != NULL) {
|
||||||
fwrite(line->str, line->len, 1, fhandle);
|
fwrite(line->str, line->len, 1, fhandle);
|
||||||
@ -221,18 +239,15 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist,
|
|||||||
printtext_window(active_win, MSGLEVEL_LASTLOG,
|
printtext_window(active_win, MSGLEVEL_LASTLOG,
|
||||||
"%s", line->str);
|
"%s", line->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
count--;
|
|
||||||
tmp = tmp->next;
|
|
||||||
}
|
|
||||||
g_string_free(line, TRUE);
|
g_string_free(line, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL)
|
if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL)
|
||||||
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END);
|
printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END);
|
||||||
|
|
||||||
textbuffer_view_set_bookmark_bottom(WINDOW_GUI(window)->view,
|
textbuffer_view_set_bookmark_bottom(view, "lastlog_last_check");
|
||||||
"lastlog_last_check");
|
|
||||||
|
|
||||||
|
g_slist_free(texts);
|
||||||
g_list_free(list);
|
g_list_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user