From a4cdb86128d2b81f4e94048464c1b30ed0694945 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 28 Jan 2001 04:03:56 +0000 Subject: [PATCH] /SET timestamp_format now specifies format of $Z. timestamp msg format now uses $Z instead of that horrible $[-2.0]3:$[-2.0]4 that no-one understood :) It's still possible to use the old method too. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1153 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- docs/special_vars.txt | 2 +- src/core/expandos.c | 21 +++++++++++++++++++-- src/fe-common/core/module-formats.c | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/special_vars.txt b/docs/special_vars.txt index 41b63925..1e7ac204 100644 --- a/docs/special_vars.txt +++ b/docs/special_vars.txt @@ -76,7 +76,7 @@ $A .. $Z is important. $W current working directory $X your /userhost $N address (user@host) $Y value of REALNAME - $Z time of day (hh:mm) + $Z time of day (hh:mm, can be changed with /SET timestamp_format) $$ a literal '$' $sysname system name (eg. Linux) diff --git a/src/core/expandos.c b/src/core/expandos.c index fe01b8df..68d14dcc 100644 --- a/src/core/expandos.c +++ b/src/core/expandos.c @@ -54,6 +54,7 @@ static time_t client_start_time; static char *last_sent_msg, *last_sent_msg_body; static char *last_privmsg_from, *last_public_from; static char *sysname, *sysrelease; +static const char *timestamp_format; #define CHAR_EXPANDOS_COUNT \ ((int) (sizeof(char_expandos) / sizeof(char_expandos[0]))) @@ -348,12 +349,18 @@ static char *expando_realname(SERVER_REC *server, void *item, int *free_ret) /* time of day (hh:mm) */ static char *expando_time(SERVER_REC *server, void *item, int *free_ret) { - time_t now = time(NULL); + time_t now; struct tm *tm; + char str[256]; + now = time(NULL); tm = localtime(&now); + + if (strftime(str, sizeof(str), timestamp_format, tm) == 0) + return ""; + *free_ret = TRUE; - return g_strdup_printf("%02d:%02d", tm->tm_hour, tm->tm_min); + return g_strdup(str); } /* a literal '$' */ @@ -430,12 +437,18 @@ static int sig_timer(void) return 1; } +static void read_settings(void) +{ + timestamp_format = settings_get_str("timestamp_format"); +} + void expandos_init(void) { #ifdef HAVE_SYS_UTSNAME_H struct utsname un; #endif settings_add_str("misc", "STATUS_OPER", "*"); + settings_add_str("misc", "timestamp_format", "%H:%M"); client_start_time = time(NULL); last_sent_msg = NULL; last_sent_msg_body = NULL; @@ -525,10 +538,13 @@ void expandos_init(void) "window changed", EXPANDO_ARG_NONE, "window server changed", EXPANDO_ARG_WINDOW, NULL); + read_settings(); + timer_tag = g_timeout_add(1000, (GSourceFunc) sig_timer, NULL); signal_add("message public", (SIGNAL_FUNC) sig_message_public); signal_add("message private", (SIGNAL_FUNC) sig_message_private); signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private); + signal_add("setup changed", (SIGNAL_FUNC) read_settings); } void expandos_deinit(void) @@ -554,4 +570,5 @@ void expandos_deinit(void) signal_remove("message public", (SIGNAL_FUNC) sig_message_public); signal_remove("message private", (SIGNAL_FUNC) sig_message_private); signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private); + signal_remove("setup changed", (SIGNAL_FUNC) read_settings); } diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index fef4e588..1762712c 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -29,7 +29,7 @@ FORMAT_REC fecommon_core_formats[] = { { "line_start", "{line_start}", 0 }, { "line_start_irssi", "{line_start}{hilight Irssi:} ", 0 }, - { "timestamp", "{timestamp $[-2.0]3:$[-2.0]4} ", 6, { 1, 1, 1, 1, 1, 1 } }, + { "timestamp", "{timestamp $Z} ", 6, { 1, 1, 1, 1, 1, 1 } }, { "servertag", "[$0] ", 1, { 0 } }, { "daychange", "Day changed to $[-2.0]{0} $3 $2", 4, { 1, 1, 1, 0 } }, { "talking_with", "You are now talking with {nick $0}", 1, { 0 } },