From 466166010b751efc622af444e00c33a843c98063 Mon Sep 17 00:00:00 2001 From: Vesa Pirila Date: Sun, 8 Feb 2015 12:39:23 +0200 Subject: [PATCH 1/3] Added a -date parameter to /lastlog to prepend each row with the row's date --- docs/help/in/lastlog.in | 1 + src/fe-text/lastlog.c | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/help/in/lastlog.in b/docs/help/in/lastlog.in index 3815f5d2..e6f5886a 100644 --- a/docs/help/in/lastlog.in +++ b/docs/help/in/lastlog.in @@ -14,6 +14,7 @@ -clear: Removes the previous results from the active window. -count: Displays how many lines match. -case: Performs a case-sensitive matching. + -date: Prepends each row with the message's date (YYYY-MM-DD). -regexp: The given text pattern is a regular expression. -word: The text must match full words. -force: Forces to display the lastlog, even if it exceeds 1000 lines. diff --git a/src/fe-text/lastlog.c b/src/fe-text/lastlog.c index 417eb484..fe3cf5af 100644 --- a/src/fe-text/lastlog.c +++ b/src/fe-text/lastlog.c @@ -74,6 +74,17 @@ int cmd_options_get_level(const char *cmd, GHashTable *optlist) return retlevel; } +static void prepend_date(LINE_REC *rec, GString *line) +{ + struct tm *tm = localtime(&rec->info.time); + char timestamp[12]; + + g_snprintf(timestamp, sizeof(timestamp), + "%04d-%02d-%02d ", + tm->tm_year+1900, tm->tm_mon, tm->tm_mday); + g_string_prepend(line, timestamp); +} + static void show_lastlog(const char *searchtext, GHashTable *optlist, int start, int count, FILE *fhandle) { @@ -82,7 +93,7 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, GList *list, *tmp; GString *line; char *str; - int level, before, after, len; + int level, before, after, len, date = FALSE; level = cmd_options_get_level("lastlog", optlist); if (level == -1) return; /* error in options */ @@ -132,6 +143,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, 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, @@ -199,6 +213,9 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, g_string_prepend(line, timestamp); } + if (date == TRUE) + prepend_date(rec, line); + /* write to file/window */ if (fhandle != NULL) { fwrite(line->str, line->len, 1, fhandle); @@ -223,7 +240,7 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, } /* SYNTAX: LASTLOG [-] [-file ] [-window ] [-new | -away] - [- -] [-clear] [-count] [-case] + [- -] [-clear] [-count] [-case] [-date] [-regexp | -word] [-before [<#>]] [-after [<#>]] [-<# before+after>] [] [ []] */ static void cmd_lastlog(const char *data) @@ -285,7 +302,7 @@ void lastlog_init(void) { command_bind("lastlog", NULL, (SIGNAL_FUNC) cmd_lastlog); - command_set_options("lastlog", "!- # force clear -file -window new away word regexp case count @a @after @before"); + command_set_options("lastlog", "!- # force clear -file -window new away word regexp case count date @a @after @before"); } void lastlog_deinit(void) From cd5a571fd8aba12b6b8ddbf54e947ac4cc1e516e Mon Sep 17 00:00:00 2001 From: Vesa Pirila Date: Sun, 8 Feb 2015 16:58:30 +0200 Subject: [PATCH 2/3] Added customization possibility for the lastlog date format, lastlog_date --- docs/help/in/lastlog.in | 2 +- src/fe-text/lastlog.c | 22 +++++++++++++++------- src/fe-text/module-formats.c | 1 + src/fe-text/module-formats.h | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/help/in/lastlog.in b/docs/help/in/lastlog.in index e6f5886a..25879d31 100644 --- a/docs/help/in/lastlog.in +++ b/docs/help/in/lastlog.in @@ -14,7 +14,7 @@ -clear: Removes the previous results from the active window. -count: Displays how many lines match. -case: Performs a case-sensitive matching. - -date: Prepends each row with the message's date (YYYY-MM-DD). + -date: Prepends each row with the message's date -regexp: The given text pattern is a regular expression. -word: The text must match full words. -force: Forces to display the lastlog, even if it exceeds 1000 lines. diff --git a/src/fe-text/lastlog.c b/src/fe-text/lastlog.c index fe3cf5af..3c700d76 100644 --- a/src/fe-text/lastlog.c +++ b/src/fe-text/lastlog.c @@ -74,15 +74,23 @@ int cmd_options_get_level(const char *cmd, GHashTable *optlist) return retlevel; } -static void prepend_date(LINE_REC *rec, GString *line) +static void prepend_date(WINDOW_REC *window, LINE_REC *rec, GString *line) { + THEME_REC *theme = NULL; + TEXT_DEST_REC dest = {0}; + char *format = NULL, datestamp[20] = {0}; struct tm *tm = localtime(&rec->info.time); - char timestamp[12]; + int ret = 0; - g_snprintf(timestamp, sizeof(timestamp), - "%04d-%02d-%02d ", - tm->tm_year+1900, tm->tm_mon, tm->tm_mday); - g_string_prepend(line, timestamp); + theme = window->theme != NULL ? window->theme : current_theme; + format_create_dest(&dest, NULL, NULL, MSGLEVEL_LASTLOG, window); + format = format_get_text_theme(theme, MODULE_NAME, &dest, TXT_LASTLOG_DATE); + + ret = strftime(datestamp, sizeof(datestamp), format, tm); + g_free(format); + if (ret <= 0) return; + + g_string_prepend(line, datestamp); } static void show_lastlog(const char *searchtext, GHashTable *optlist, @@ -214,7 +222,7 @@ static void show_lastlog(const char *searchtext, GHashTable *optlist, } if (date == TRUE) - prepend_date(rec, line); + prepend_date(window, rec, line); /* write to file/window */ if (fhandle != NULL) { diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c index 1d905095..899827c2 100644 --- a/src/fe-text/module-formats.c +++ b/src/fe-text/module-formats.c @@ -33,6 +33,7 @@ FORMAT_REC gui_text_formats[] = { "lastlog_start", "{hilight Lastlog}:", 0 }, { "lastlog_end", "{hilight End of Lastlog}", 0 }, { "lastlog_separator", "--", 0 }, + { "lastlog_date", "%%F ", 0 }, /* ---- */ { NULL, "Windows", 0 }, diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h index 4eebfc3e..3fa8c511 100644 --- a/src/fe-text/module-formats.h +++ b/src/fe-text/module-formats.h @@ -10,6 +10,7 @@ enum { TXT_LASTLOG_START, TXT_LASTLOG_END, TXT_LASTLOG_SEPARATOR, + TXT_LASTLOG_DATE, TXT_FILL_2, From 895ac10c4eaa347cf2dbe184fc9480a8f47168ee Mon Sep 17 00:00:00 2001 From: Vesa Pirila Date: Mon, 16 Feb 2015 09:49:22 +0200 Subject: [PATCH 3/3] lastlog.c is a mix of tab and space indentation. My changes now use tabs. --- src/fe-text/lastlog.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/fe-text/lastlog.c b/src/fe-text/lastlog.c index 3c700d76..166d2847 100644 --- a/src/fe-text/lastlog.c +++ b/src/fe-text/lastlog.c @@ -76,19 +76,19 @@ int cmd_options_get_level(const char *cmd, GHashTable *optlist) static void prepend_date(WINDOW_REC *window, LINE_REC *rec, GString *line) { - THEME_REC *theme = NULL; - TEXT_DEST_REC dest = {0}; - char *format = NULL, datestamp[20] = {0}; + THEME_REC *theme = NULL; + TEXT_DEST_REC dest = {0}; + char *format = NULL, datestamp[20] = {0}; struct tm *tm = localtime(&rec->info.time); int ret = 0; - theme = window->theme != NULL ? window->theme : current_theme; - format_create_dest(&dest, NULL, NULL, MSGLEVEL_LASTLOG, window); - format = format_get_text_theme(theme, MODULE_NAME, &dest, TXT_LASTLOG_DATE); + theme = window->theme != NULL ? window->theme : current_theme; + format_create_dest(&dest, NULL, NULL, MSGLEVEL_LASTLOG, window); + format = format_get_text_theme(theme, MODULE_NAME, &dest, TXT_LASTLOG_DATE); ret = strftime(datestamp, sizeof(datestamp), format, tm); - g_free(format); - if (ret <= 0) return; + g_free(format); + if (ret <= 0) return; g_string_prepend(line, datestamp); }