From bf3f696830c5dfdbf2b38398a6f43bda4068b4ba Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 6 Nov 2005 12:09:44 +0000 Subject: Added /uptime command --- src/common/command.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/common/command.h | 2 +- src/common/weechat.c | 4 ++++ src/common/weechat.h | 1 + 4 files changed, 72 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/common/command.c b/src/common/command.c index 7a83344cd..037004849 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -135,6 +135,10 @@ t_weechat_command weechat_commands[] = "For each argument, '*' means all.\n" "Without argument, /unignore command lists all defined ignore."), 0, 4, weechat_cmd_unignore, NULL }, + { "uptime", N_("show WeeChat uptime"), + N_("-o"), + N_("-o: send uptime on current channel as an IRC message"), + 0, 1, weechat_cmd_uptime, NULL }, { "window", N_("manage windows"), N_("[list | -1 | +1 | b# | splith | splitv | [merge [down | up | left | right | all]]]"), N_("list: list opened windows (no parameter implies this list)\n" @@ -2639,6 +2643,68 @@ weechat_cmd_unignore (int argc, char **argv) return 0; } +/* + * weechat_cmd_uptime: display WeeChat uptime + */ + +int +weechat_cmd_uptime (int argc, char **argv) +{ + time_t running_time; + int day, hour, min, sec; + char string[256]; + + running_time = time (NULL) - weechat_start_time; + day = running_time / (60 * 60 * 24); + hour = (running_time % (60 * 60 * 24)) / (60 * 60); + min = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60; + sec = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60; + + if ((argc == 1) && (strcmp (argv[0], "-o") == 0) + && ((BUFFER_IS_CHANNEL(gui_current_window->buffer)) + || (BUFFER_IS_PRIVATE(gui_current_window->buffer)))) + { + snprintf (string, sizeof (string), + "WeeChat uptime: %d %s %02d:%02d:%02d, started on %s", + day, + (day > 1) ? _("days") : _("day"), + hour, + min, + sec, + ctime (&weechat_start_time)); + string[strlen (string) - 1] = '\0'; + user_command (SERVER(gui_current_window->buffer), + gui_current_window->buffer, + string); + } + else + { + irc_display_prefix (NULL, gui_current_window->buffer, + PREFIX_INFO); + gui_printf_nolog (gui_current_window->buffer, + _("WeeChat uptime: %s%d %s%s " + "%s%02d%s:%s%02d%s:%s%02d%s, " + "started on %s%s"), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + day, + GUI_COLOR(COLOR_WIN_CHAT), + (day > 1) ? _("days") : _("day"), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + hour, + GUI_COLOR(COLOR_WIN_CHAT), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + min, + GUI_COLOR(COLOR_WIN_CHAT), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + sec, + GUI_COLOR(COLOR_WIN_CHAT), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + ctime (&weechat_start_time)); + } + + return 0; +} + /* * weechat_cmd_window: manage windows */ diff --git a/src/common/command.h b/src/common/command.h index 015f63667..cfac06ebf 100644 --- a/src/common/command.h +++ b/src/common/command.h @@ -80,7 +80,7 @@ extern int weechat_cmd_server (int, char **); extern int weechat_cmd_set (char *); extern int weechat_cmd_unalias (char *); extern int weechat_cmd_unignore (int, char **); -extern int weechat_cmd_unset (char *); +extern int weechat_cmd_uptime (int, char **); extern int weechat_cmd_window (int, char **); #endif /* command.h */ diff --git a/src/common/weechat.c b/src/common/weechat.c index 245776975..3bf9d4a75 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -73,6 +73,7 @@ #endif +time_t weechat_start_time; /* WeeChat start time (used by /uptime command) */ int quit_weechat; /* = 1 if quit request from user... why ? :'( */ int sigsegv = 0; /* SIGSEGV received? */ char *weechat_home = NULL; /* WeeChat home dir. (example: /home/toto/.weechat) */ @@ -637,6 +638,9 @@ wee_create_home_dirs () void wee_init_vars () { + /* start time, used by /uptime command */ + weechat_start_time = time (NULL); + /* init received messages queue */ recv_msgq = NULL; msgq_last_msg = NULL; diff --git a/src/common/weechat.h b/src/common/weechat.h index 0e36a4a28..7b3ea307f 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -112,6 +112,7 @@ /* global variables and functions */ +extern time_t weechat_start_time; extern int quit_weechat; extern char *weechat_home; extern char *local_charset; -- cgit v1.2.3