From 93ba91b8ed23284cfe14f5d77d5910e112039424 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 14 Jan 2001 18:16:39 +0000 Subject: [PATCH] Added my_asctime() git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1114 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/misc.c | 14 +++++++++++++ src/core/misc.h | 3 +++ src/fe-common/irc/fe-events-numeric.c | 29 ++++----------------------- src/fe-common/irc/fe-irc-commands.c | 10 +++------ src/irc/core/ctcp.c | 9 ++------- src/irc/core/irc-nicklist.c | 22 +------------------- 6 files changed, 27 insertions(+), 60 deletions(-) diff --git a/src/core/misc.c b/src/core/misc.c index 2363eee7..0ae36b96 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -591,3 +591,17 @@ char *show_lowascii(const char *channel) return str; } +/* Get time in human readable form with localtime() + asctime() */ +char *my_asctime(time_t t) +{ + struct tm *tm; + char *str; + int len; + + tm = localtime(&t); + str = g_strdup(asctime(tm)); + + len = strlen(str); + if (len > 0) str[len-1] = '\0'; + return str; +} diff --git a/src/core/misc.h b/src/core/misc.h index 176c7a3d..22fe9211 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -71,4 +71,7 @@ int dec2octal(int decimal); /* convert all low-ascii (<32) to ^ combinations */ char *show_lowascii(const char *channel); +/* Get time in human readable form with localtime() + asctime() */ +char *my_asctime(time_t t); + #endif diff --git a/src/fe-common/irc/fe-events-numeric.c b/src/fe-common/irc/fe-events-numeric.c index 2cac549a..6e37dff3 100644 --- a/src/fe-common/irc/fe-events-numeric.c +++ b/src/fe-common/irc/fe-events-numeric.c @@ -296,20 +296,13 @@ static void event_topic_get(IRC_SERVER_REC *server, const char *data) static void event_topic_info(IRC_SERVER_REC *server, const char *data) { char *params, *timestr, *channel, *topicby, *topictime; - struct tm *tm; - time_t t; g_return_if_fail(data != NULL); params = event_get_params(data, 4, NULL, &channel, &topicby, &topictime); - t = (time_t) atol(topictime); - tm = localtime(&t); - - timestr = g_strdup(asctime(tm)); - if (timestr[strlen(timestr)-1] == '\n') - timestr[strlen(timestr)-1] = '\0'; + timestr = my_asctime((time_t) atol(topictime)); printformat(server, channel, MSGLEVEL_CRAP, IRCTXT_TOPIC_INFO, topicby, timestr); @@ -332,20 +325,12 @@ static void event_channel_mode(IRC_SERVER_REC *server, const char *data) static void event_channel_created(IRC_SERVER_REC *server, const char *data) { char *params, *channel, *createtime, *timestr; - time_t t; - struct tm *tm; g_return_if_fail(data != NULL); params = event_get_params(data, 3, NULL, &channel, &createtime); - t = (time_t) atol(createtime); - tm = localtime(&t); - - timestr = g_strdup(asctime(tm)); - if (timestr[strlen(timestr)-1] == '\n') - timestr[strlen(timestr)-1] = '\0'; - + timestr = my_asctime((time_t) atol(createtime)); printformat(server, channel, MSGLEVEL_CRAP, IRCTXT_CHANNEL_CREATED, channel, timestr); g_free(timestr); @@ -397,7 +382,7 @@ static void event_whois(IRC_SERVER_REC *server, const char *data) static void event_whois_idle(IRC_SERVER_REC *server, const char *data) { - char *params, *nick, *secstr, *signonstr, *rest; + char *params, *nick, *secstr, *signonstr, *rest, *timestr; long days, hours, mins, secs; time_t signon; @@ -419,13 +404,7 @@ static void event_whois_idle(IRC_SERVER_REC *server, const char *data) printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE, nick, days, hours, mins, secs); else { - char *timestr; - struct tm *tim; - - tim = localtime(&signon); - timestr = g_strdup(asctime(tim)); - if (timestr[strlen(timestr)-1] == '\n') - timestr[strlen(timestr)-1] = '\0'; + timestr = my_asctime(signon); printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE_SIGNON, nick, days, hours, mins, secs, timestr); g_free(timestr); diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c index 33e5455d..8d739c8b 100644 --- a/src/fe-common/irc/fe-irc-commands.c +++ b/src/fe-common/irc/fe-irc-commands.c @@ -22,6 +22,7 @@ #include "module-formats.h" #include "signals.h" #include "commands.h" +#include "misc.h" #include "special-vars.h" #include "settings.h" @@ -332,8 +333,7 @@ static void cmd_topic(const char *data, SERVER_REC *server, WI_ITEM_REC *item) { CHANNEL_REC *channel; char *timestr; - struct tm *tm; - + g_return_if_fail(data != NULL); channel = *data != '\0' ? channel_find(server, data) : CHANNEL(item); @@ -344,11 +344,7 @@ static void cmd_topic(const char *data, SERVER_REC *server, WI_ITEM_REC *item) channel->name, channel->topic); if (channel->topic_time > 0) { - tm = localtime(&channel->topic_time); - timestr = g_strdup(asctime(tm)); - if (timestr[strlen(timestr)-1] == '\n') - timestr[strlen(timestr)-1] = '\0'; - + timestr = my_asctime(channel->topic_time); printformat(server, channel->name, MSGLEVEL_CRAP, IRCTXT_TOPIC_INFO, channel->topic_by, timestr); g_free(timestr); diff --git a/src/irc/core/ctcp.c b/src/irc/core/ctcp.c index 3d904dd0..b9efbdb3 100644 --- a/src/irc/core/ctcp.c +++ b/src/irc/core/ctcp.c @@ -21,6 +21,7 @@ #include "module.h" #include "signals.h" #include "levels.h" +#include "misc.h" #include "special-vars.h" #include "settings.h" @@ -99,17 +100,11 @@ static void ctcp_time(IRC_SERVER_REC *server, const char *data, const char *nick) { char *str, *reply; - struct tm *tm; - time_t t; g_return_if_fail(server != NULL); g_return_if_fail(nick != NULL); - t = time(NULL); - tm = localtime(&t); - reply = g_strdup(asctime(tm)); - if (reply[strlen(reply)-1] == '\n') reply[strlen(reply)-1] = '\0'; - + reply = my_asctime(time(NULL)); str = g_strdup_printf("NOTICE %s :\001TIME %s\001", nick, reply); ctcp_send_reply(server, str); g_free(str); diff --git a/src/irc/core/irc-nicklist.c b/src/irc/core/irc-nicklist.c index 391399bf..245d1fdd 100644 --- a/src/irc/core/irc-nicklist.c +++ b/src/irc/core/irc-nicklist.c @@ -268,9 +268,6 @@ static void event_target_unavailable(IRC_SERVER_REC *server, const char *data) static void event_nick(SERVER_REC *server, const char *data, const char *orignick) { - IRC_CHANNEL_REC *channel; - NICK_REC *nickrec; - GSList *nicks, *tmp; char *params, *nick; g_return_if_fail(data != NULL); @@ -286,24 +283,7 @@ static void event_nick(SERVER_REC *server, const char *data, signal_emit("server nick changed", 1, server); } - nicks = nicklist_get_same(server, orignick); - for (tmp = nicks; tmp != NULL; tmp = tmp->next->next) { - channel = tmp->data; - nickrec = tmp->next->data; - - /* remove old nick from hash table */ - g_hash_table_remove(channel->nicks, nickrec->nick); - - g_free(nickrec->nick); - nickrec->nick = g_strdup(nick); - - /* add new nick to hash table */ - g_hash_table_insert(channel->nicks, nickrec->nick, nickrec); - - signal_emit("nicklist changed", 3, channel, nickrec, orignick); - } - g_slist_free(nicks); - + nicklist_rename(server, orignick, nick); g_free(params); }