void textbuffer_view_remove_lines_by_level(TEXT_BUFFER_VIEW_REC *view, int level) { LINE_REC *line, *next; term_refresh_freeze(); line = textbuffer_view_get_lines(view); while (line != NULL) { next = line->next; if (line->info.level & level) textbuffer_view_remove_line(view, line); line = next; } textbuffer_view_redraw(view); term_refresh_thaw(); }
/* SYNTAX: SCROLLBACK REDRAW */ static void cmd_scrollback_redraw(void) { GUI_WINDOW_REC *gui; LINE_REC *line, *next; gui = WINDOW_GUI(active_win); term_refresh_freeze(); line = textbuffer_view_get_lines(gui->view); while (line != NULL) { next = line->next; textbuffer_reformat_line(active_win, line); line = next; } gui_window_redraw(active_win); term_refresh_thaw(); }
static void window_lastlog_clear(WINDOW_REC *window) { TEXT_BUFFER_VIEW_REC *view; LINE_REC *line, *next; term_refresh_freeze(); view = WINDOW_GUI(window)->view; line = textbuffer_view_get_lines(view); while (line != NULL) { next = line->next; if (line->info.level & MSGLEVEL_LASTLOG) textbuffer_view_remove_line(view, line); line = next; } textbuffer_view_redraw(view); term_refresh_thaw(); }
static void show_lastlog(const char *searchtext, GHashTable *optlist, int start, int count, FILE *fhandle) { WINDOW_REC *window; LINE_REC *startline; GList *list, *tmp; GString *line; char *str; int level, before, after, len, date = FALSE; 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) { textbuffer_view_remove_lines_by_level(WINDOW_GUI(active_win)->view, MSGLEVEL_LASTLOG); if (*searchtext == '\0') return; } /* 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 (window == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_REFNUM_NOT_FOUND, str); return; } } if (g_hash_table_lookup(optlist, "new") != NULL) startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_check"); else if (g_hash_table_lookup(optlist, "away") != NULL) startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_away"); else startline = NULL; if (startline == NULL) startline = textbuffer_view_get_lines(WINDOW_GUI(window)->view); str = g_hash_table_lookup(optlist, "#"); if (str != NULL) { before = after = atoi(str); } else { str = g_hash_table_lookup(optlist, "before"); before = str == NULL ? 0 : *str != '\0' ? atoi(str) : DEFAULT_LASTLOG_BEFORE; str = g_hash_table_lookup(optlist, "after"); if (str == NULL) str = g_hash_table_lookup(optlist, "a"); after = str == NULL ? 0 : *str != '\0' ? atoi(str) : DEFAULT_LASTLOG_AFTER; } if (g_hash_table_lookup(optlist, "date") != NULL) date = TRUE; list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline, level, MSGLEVEL_LASTLOG, searchtext, before, after, g_hash_table_lookup(optlist, "regexp") != NULL, g_hash_table_lookup(optlist, "word") != NULL, g_hash_table_lookup(optlist, "case") != NULL); len = g_list_length(list); if (count <= 0) tmp = list; else { int pos = len-count-start; if (pos < 0) pos = 0; tmp = pos > len ? NULL : g_list_nth(list, pos); len = g_list_length(tmp); } if (g_hash_table_lookup(optlist, "count") != NULL) { printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_LASTLOG_COUNT, len); g_list_free(list); return; } if (len > MAX_LINES_WITHOUT_FORCE && fhandle == NULL && g_hash_table_lookup(optlist, "force") == NULL) { printformat_window(active_win, MSGLEVEL_CLIENTNOTICE|MSGLEVEL_LASTLOG, TXT_LASTLOG_TOO_LONG, len); g_list_free(list); return; } if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL) printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START); line = g_string_new(NULL); while (tmp != NULL && (count < 0 || count > 0)) { LINE_REC *rec = tmp->data; if (rec == NULL) { if (tmp->next == NULL) break; if (fhandle != NULL) { fwrite("--\n", 3, 1, fhandle); } else { printformat_window(active_win, MSGLEVEL_LASTLOG, TXT_LASTLOG_SEPARATOR); } tmp = tmp->next; continue; } /* get the line text */ textbuffer_line2text(rec, fhandle == NULL, line); if (!settings_get_bool("timestamps")) { struct tm *tm = localtime(&rec->info.time); char timestamp[10]; g_snprintf(timestamp, sizeof(timestamp), "%02d:%02d ", tm->tm_hour, tm->tm_min); g_string_prepend(line, timestamp); } if (date == TRUE) prepend_date(window, rec, line); /* write to file/window */ if (fhandle != NULL) { fwrite(line->str, line->len, 1, fhandle); fputc('\n', fhandle); } else { printtext_window(active_win, MSGLEVEL_LASTLOG, "%s", line->str); } count--; tmp = tmp->next; } g_string_free(line, TRUE); if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL) printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END); textbuffer_view_set_bookmark_bottom(WINDOW_GUI(window)->view, "lastlog_last_check"); g_list_free(list); }
static void scrollback_goto_time(const char *datearg, const char *timearg) { LINE_REC *line; struct tm tm; time_t now, stamp; int day, month; /* [dd[.mm] | -<days ago>] hh:mi[:ss] */ now = stamp = time(NULL); if (*datearg == '-') { /* -<days ago> */ stamp -= atoi(datearg+1) * 3600*24; memcpy(&tm, localtime(&stamp), sizeof(struct tm)); } else if (*timearg != '\0') { /* dd[.mm] */ memcpy(&tm, localtime(&stamp), sizeof(struct tm)); day = month = 0; sscanf(datearg, "%d.%d", &day, &month); if (day <= 0) return; if (month <= 0) { /* month not given */ if (day > tm.tm_mday) { /* last month's day */ if (tm.tm_mon > 0) tm.tm_mon--; else { /* last year's day.. */ tm.tm_year--; tm.tm_mon = 11; } } } else { month--; if (month > tm.tm_mon) tm.tm_year--; tm.tm_mon = month; } tm.tm_mday = day; stamp = mktime(&tm); } else { /* only time given, move it to timearg */ timearg = datearg; } /* hh:mi[:ss] */ memcpy(&tm, localtime(&stamp), sizeof(struct tm)); tm.tm_sec = 0; sscanf(timearg, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec); stamp = mktime(&tm); if (stamp > now && timearg == datearg) { /* we used /SB GOTO 23:59 or something, we want to jump to previous day's 23:59 time instead of into future. */ stamp -= 3600*24; } if (stamp > now) { /* we're still looking into future, don't bother checking */ return; } /* scroll to first line after timestamp */ line = textbuffer_view_get_lines(WINDOW_GUI(active_win)->view); for (; line != NULL; line = line->next) { if (line->info.time >= stamp) { gui_window_scroll_line(active_win, line); break; } } }