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"
TXT_CHAN_NOT_FOUND,
TXT_CHAN_NOT_SYNCED,
TXT_ILLEGAL_PROTO,
- TXT_NOT_GOOD_IDEA
+ TXT_NOT_GOOD_IDEA,
+ TXT_INVALID_TIME,
+ TXT_INVALID_CHARSET,
+ TXT_EVAL_MAX_RECURSE,
+ TXT_PROGRAM_NOT_FOUND
};
+int command_hide_output;
+
/* keep the whole command line here temporarily. we need it in
"default command" event handler, but there we don't know if the start of
the line had one or two command chars, and which one.. */
static const char *current_cmdline;
-static int hide_output;
static GTimeVal time_command_last, time_command_now;
static int last_command_cmd, command_cmd;
recvlen = read(f, tmpbuf, sizeof(tmpbuf));
ret = line_split(tmpbuf, recvlen, &str, &buffer);
- if (ret > 0)
- printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str);
+ if (ret > 0) {
+ printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP |
+ MSGLEVEL_NEVER, "%s", str);
+ }
} while (ret > 0);
line_split_free(buffer);
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();
{
const char *cmdchar;
- if (*data == '\0') {
- /* empty line, forget it. */
- signal_stop();
- return;
- }
-
/* save current command line */
current_cmdline = data;
last_command_cmd = command_cmd;
g_get_current_time(&time_command_now);
- command_cmd = strchr(settings_get_str("cmdchars"), *data) != NULL;
+ command_cmd = *data != '\0' &&
+ strchr(settings_get_str("cmdchars"), *data) != NULL;
/* /^command hides the output of the command */
- cmdchar = strchr(settings_get_str("cmdchars"), *data);
+ cmdchar = *data == '\0' ? NULL :
+ strchr(settings_get_str("cmdchars"), *data);
if (cmdchar != NULL && (data[1] == '^' ||
- (data[1] == *cmdchar && data[2] == '^'))) {
- hide_output = TRUE;
+ (data[1] == *cmdchar && data[2] == '^'))
+ && !command_hide_output++) {
signal_add_first("print starting", (SIGNAL_FUNC) sig_stop);
signal_add_first("print format", (SIGNAL_FUNC) sig_stop);
signal_add_first("print text", (SIGNAL_FUNC) sig_stop);
static void event_command_last(const char *data)
{
- if (hide_output) {
- hide_output = FALSE;
+ if (command_hide_output && !--command_hide_output) {
signal_remove("print starting", (SIGNAL_FUNC) sig_stop);
signal_remove("print format", (SIGNAL_FUNC) sig_stop);
signal_remove("print text", (SIGNAL_FUNC) sig_stop);
void fe_core_commands_init(void)
{
- hide_output = FALSE;
+ command_hide_output = 0;
command_cmd = FALSE;
memset(&time_command_now, 0, sizeof(GTimeVal));
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);
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);