From 9da0ca72a5f0ab96ef966a05ad59fd87ece0903c Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Fri, 20 Oct 2006 12:50:08 +0000 Subject: [PATCH] uptime command by Lauri Nurmi with some modifications by me, bug #458. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4389 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- irssi.conf | 1 - src/core/core.c | 2 ++ src/core/core.h | 3 +++ src/core/expandos.c | 3 +-- src/fe-common/core/fe-core-commands.c | 19 +++++++++++++++++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/irssi.conf b/irssi.conf index a1d748e9..51a0fd9a 100644 --- a/irssi.conf +++ b/irssi.conf @@ -90,7 +90,6 @@ aliases = { GOTO = "sb goto"; CHAT = "dcc chat"; RUN = "SCRIPT LOAD"; - UPTIME = "eval exec - expr `date +%s` - \\$F | awk '{print \"Irssi uptime: \"int(\\\\\\$1/3600/24)\"d \"int(\\\\\\$1/3600%24)\"h \"int(\\\\\\$1/60%60)\"m \"int(\\\\\\$1%60)\"s\" }'"; CALC = "exec - if which bc &>/dev/null\\; then echo '$*' | bc | awk '{print \"$*=\"$$1}'\\; else echo bc was not found\\; fi"; SBAR = "STATUSBAR"; INVITELIST = "mode $C +I"; diff --git a/src/core/core.c b/src/core/core.c index e0fcad13..2f2f7329 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -61,6 +61,7 @@ void log_away_deinit(void); int irssi_gui; int irssi_init_finished; int reload_config; +time_t client_start_time; static char *irssi_dir, *irssi_config_file; static GSList *dialog_type_queue, *dialog_text_queue; @@ -215,6 +216,7 @@ void core_init(int argc, char *argv[]) { dialog_type_queue = NULL; dialog_text_queue = NULL; + client_start_time = time(NULL); modules_init(); #ifndef WIN32 diff --git a/src/core/core.h b/src/core/core.h index 74317166..242b8df4 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -1,6 +1,8 @@ #ifndef __IRSSI_CORE_H #define __IRSSI_CORE_H +#include + /* for determining what GUI is currently in use: */ #define IRSSI_GUI_NONE 0 #define IRSSI_GUI_TEXT 1 @@ -12,6 +14,7 @@ extern int irssi_gui; extern int irssi_init_finished; /* TRUE after "irssi init finished" signal is sent */ extern int reload_config; /* TRUE after received SIGHUP. */ +extern time_t client_start_time; void core_init_paths(int argc, char *argv[]); diff --git a/src/core/expandos.c b/src/core/expandos.c index eb8ebed6..306c2223 100644 --- a/src/core/expandos.c +++ b/src/core/expandos.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "core.h" #include "module.h" #include "modules.h" #include "signals.h" @@ -52,7 +53,6 @@ static int timer_tag; static EXPANDO_REC *char_expandos[255]; static GHashTable *expandos; -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, *sysarch; @@ -577,7 +577,6 @@ void expandos_init(void) settings_add_str("lookandfeel", "timestamp_format", "%H:%M"); settings_add_bool("lookandfeel", "chanmode_expando_strip", FALSE); - client_start_time = time(NULL); last_sent_msg = NULL; last_sent_msg_body = NULL; last_privmsg_from = NULL; last_public_from = NULL; last_timestamp = 0; diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 51b68b3d..69bab326 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "core.h" #include "module.h" #include "module-formats.h" #include "signals.h" @@ -194,6 +195,22 @@ static void cmd_join(const char *data, SERVER_REC *server) cmd_params_free(free_arg); } +/* SYNTAX: UPTIME */ +static void cmd_uptime(char *data) +{ + time_t uptime; + + g_return_if_fail(data != NULL); + + if (*data == '\0') { + uptime = time(NULL) - client_start_time; + printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE, + "Uptime: %ldd %ldh %ldm %lds", + uptime/3600/24, uptime/3600%24, + uptime/60%60, uptime%60); + } +} + static void sig_stop(void) { signal_stop(); @@ -327,6 +344,7 @@ void fe_core_commands_init(void) command_bind("version", NULL, (SIGNAL_FUNC) cmd_version); command_bind("cat", NULL, (SIGNAL_FUNC) cmd_cat); command_bind("beep", NULL, (SIGNAL_FUNC) cmd_beep); + command_bind("uptime", NULL, (SIGNAL_FUNC) cmd_uptime); command_bind_first("nick", NULL, (SIGNAL_FUNC) cmd_nick); command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_join); @@ -345,6 +363,7 @@ void fe_core_commands_deinit(void) command_unbind("version", (SIGNAL_FUNC) cmd_version); command_unbind("cat", (SIGNAL_FUNC) cmd_cat); command_unbind("beep", (SIGNAL_FUNC) cmd_beep); + command_unbind("uptime", (SIGNAL_FUNC) cmd_uptime); command_unbind("nick", (SIGNAL_FUNC) cmd_nick); command_unbind("join", (SIGNAL_FUNC) cmd_join);