diff options
author | Timo Sirainen <cras@irssi.org> | 2001-09-23 17:32:05 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-09-23 17:32:05 +0000 |
commit | 26d84e25ab6418936cef456a490cc4627fe85036 (patch) | |
tree | dd26ff1eb3363f4e0c5ed43c7579f1f608f8fc4d /src/core/expandos.c | |
parent | a51170c00fd48a09963d236e69a97d5971eb2984 (diff) | |
download | irssi-26d84e25ab6418936cef456a490cc4627fe85036.zip |
added expando_get_signals() and special_vars_get_signals() to return list
of signals the expandos use. Also added "time changed" signal which gets
emitted when $Z changes.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1814 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core/expandos.c')
-rw-r--r-- | src/core/expandos.c | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/core/expandos.c b/src/core/expandos.c index 9114a3c9..4659f5ac 100644 --- a/src/core/expandos.c +++ b/src/core/expandos.c @@ -54,7 +54,10 @@ 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; + static const char *timestamp_format; +static int timestamp_seconds; +static time_t last_timestamp; #define CHAR_EXPANDO(chr) \ (char_expandos[(int) (unsigned char) chr]) @@ -209,6 +212,38 @@ void expando_unbind(const char *key, int funccount, SIGNAL_FUNC *funcs) } } +/* Returns [<signal id>, EXPANDO_ARG_xxx, <signal id>, ..., -1] */ +int *expando_get_signals(const char *key) +{ + EXPANDO_REC *rec; + int *signals; + int n; + + g_return_val_if_fail(key != NULL, NULL); + + rec = expando_find(key); + if (rec == NULL || rec->signals < 0) + return NULL; + + if (rec->signals == 0) { + /* it's unknown when this expando changes.. + check it once in a second */ + signals = g_new(int, 3); + signals[0] = signal_get_uniq_id("expando timer"); + signals[1] = EXPANDO_ARG_NONE; + signals[2] = -1; + return signals; + } + + signals = g_new(int, rec->signals*2+1); + for (n = 0; n < rec->signals; n++) { + signals[n*2] = rec->signal_ids[n]; + signals[n*2+1] = rec->signal_args[n]; + } + signals[rec->signals*2] = -1; + return signals; +} + EXPANDO_FUNC expando_find_char(char chr) { return CHAR_EXPANDO(chr) == NULL ? NULL : @@ -437,13 +472,41 @@ static void sig_message_own_private(SERVER_REC *server, const char *msg, static int sig_timer(void) { + time_t now; + struct tm *tm; + int last_min; + signal_emit("expando timer", 0); + + /* check if $Z has changed */ + now = time(NULL); + if (last_timestamp != now) { + if (!timestamp_seconds) { + /* assume it changes every minute */ + tm = localtime(&last_timestamp); + last_min = tm->tm_min; + + tm = localtime(&now); + if (tm->tm_min == last_min) + return 1; + } + + signal_emit("time changed", 0); + last_timestamp = now; + } + return 1; } static void read_settings(void) { - timestamp_format = settings_get_str("timestamp_format"); + timestamp_format = settings_get_str("timestamp_format"); + timestamp_seconds = + strstr(timestamp_format, "%r") != NULL || + strstr(timestamp_format, "%s") != NULL || + strstr(timestamp_format, "%S") != NULL || + strstr(timestamp_format, "%T") != NULL; + } void expandos_init(void) @@ -457,6 +520,7 @@ void expandos_init(void) 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; sysname = sysrelease = sysarch = NULL; #ifdef HAVE_SYS_UTSNAME_H @@ -523,7 +587,8 @@ void expandos_init(void) expando_create("Y", expando_realname, "window changed", EXPANDO_ARG_NONE, "window server changed", EXPANDO_ARG_WINDOW, NULL); - expando_create("Z", expando_time, NULL); + expando_create("Z", expando_time, + "time changed", EXPANDO_ARG_NONE, NULL); expando_create("$", expando_dollar, "", EXPANDO_NEVER, NULL); |