1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Added my_asctime()

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1114 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-01-14 18:16:39 +00:00 committed by cras
parent d427f74143
commit 93ba91b8ed
6 changed files with 27 additions and 60 deletions

View File

@ -591,3 +591,17 @@ char *show_lowascii(const char *channel)
return str; 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;
}

View File

@ -71,4 +71,7 @@ int dec2octal(int decimal);
/* convert all low-ascii (<32) to ^<A..> combinations */ /* convert all low-ascii (<32) to ^<A..> combinations */
char *show_lowascii(const char *channel); char *show_lowascii(const char *channel);
/* Get time in human readable form with localtime() + asctime() */
char *my_asctime(time_t t);
#endif #endif

View File

@ -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) static void event_topic_info(IRC_SERVER_REC *server, const char *data)
{ {
char *params, *timestr, *channel, *topicby, *topictime; char *params, *timestr, *channel, *topicby, *topictime;
struct tm *tm;
time_t t;
g_return_if_fail(data != NULL); g_return_if_fail(data != NULL);
params = event_get_params(data, 4, NULL, &channel, params = event_get_params(data, 4, NULL, &channel,
&topicby, &topictime); &topicby, &topictime);
t = (time_t) atol(topictime); timestr = my_asctime((time_t) atol(topictime));
tm = localtime(&t);
timestr = g_strdup(asctime(tm));
if (timestr[strlen(timestr)-1] == '\n')
timestr[strlen(timestr)-1] = '\0';
printformat(server, channel, MSGLEVEL_CRAP, printformat(server, channel, MSGLEVEL_CRAP,
IRCTXT_TOPIC_INFO, topicby, timestr); 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) static void event_channel_created(IRC_SERVER_REC *server, const char *data)
{ {
char *params, *channel, *createtime, *timestr; char *params, *channel, *createtime, *timestr;
time_t t;
struct tm *tm;
g_return_if_fail(data != NULL); g_return_if_fail(data != NULL);
params = event_get_params(data, 3, NULL, &channel, &createtime); params = event_get_params(data, 3, NULL, &channel, &createtime);
t = (time_t) atol(createtime); timestr = my_asctime((time_t) atol(createtime));
tm = localtime(&t);
timestr = g_strdup(asctime(tm));
if (timestr[strlen(timestr)-1] == '\n')
timestr[strlen(timestr)-1] = '\0';
printformat(server, channel, MSGLEVEL_CRAP, printformat(server, channel, MSGLEVEL_CRAP,
IRCTXT_CHANNEL_CREATED, channel, timestr); IRCTXT_CHANNEL_CREATED, channel, timestr);
g_free(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) 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; long days, hours, mins, secs;
time_t signon; 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, printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE,
nick, days, hours, mins, secs); nick, days, hours, mins, secs);
else { else {
char *timestr; timestr = my_asctime(signon);
struct tm *tim;
tim = localtime(&signon);
timestr = g_strdup(asctime(tim));
if (timestr[strlen(timestr)-1] == '\n')
timestr[strlen(timestr)-1] = '\0';
printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE_SIGNON, printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE_SIGNON,
nick, days, hours, mins, secs, timestr); nick, days, hours, mins, secs, timestr);
g_free(timestr); g_free(timestr);

View File

@ -22,6 +22,7 @@
#include "module-formats.h" #include "module-formats.h"
#include "signals.h" #include "signals.h"
#include "commands.h" #include "commands.h"
#include "misc.h"
#include "special-vars.h" #include "special-vars.h"
#include "settings.h" #include "settings.h"
@ -332,7 +333,6 @@ static void cmd_topic(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{ {
CHANNEL_REC *channel; CHANNEL_REC *channel;
char *timestr; char *timestr;
struct tm *tm;
g_return_if_fail(data != NULL); g_return_if_fail(data != NULL);
@ -344,11 +344,7 @@ static void cmd_topic(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
channel->name, channel->topic); channel->name, channel->topic);
if (channel->topic_time > 0) { if (channel->topic_time > 0) {
tm = localtime(&channel->topic_time); timestr = my_asctime(channel->topic_time);
timestr = g_strdup(asctime(tm));
if (timestr[strlen(timestr)-1] == '\n')
timestr[strlen(timestr)-1] = '\0';
printformat(server, channel->name, MSGLEVEL_CRAP, printformat(server, channel->name, MSGLEVEL_CRAP,
IRCTXT_TOPIC_INFO, channel->topic_by, timestr); IRCTXT_TOPIC_INFO, channel->topic_by, timestr);
g_free(timestr); g_free(timestr);

View File

@ -21,6 +21,7 @@
#include "module.h" #include "module.h"
#include "signals.h" #include "signals.h"
#include "levels.h" #include "levels.h"
#include "misc.h"
#include "special-vars.h" #include "special-vars.h"
#include "settings.h" #include "settings.h"
@ -99,17 +100,11 @@ static void ctcp_time(IRC_SERVER_REC *server, const char *data,
const char *nick) const char *nick)
{ {
char *str, *reply; char *str, *reply;
struct tm *tm;
time_t t;
g_return_if_fail(server != NULL); g_return_if_fail(server != NULL);
g_return_if_fail(nick != NULL); g_return_if_fail(nick != NULL);
t = time(NULL); reply = my_asctime(time(NULL));
tm = localtime(&t);
reply = g_strdup(asctime(tm));
if (reply[strlen(reply)-1] == '\n') reply[strlen(reply)-1] = '\0';
str = g_strdup_printf("NOTICE %s :\001TIME %s\001", nick, reply); str = g_strdup_printf("NOTICE %s :\001TIME %s\001", nick, reply);
ctcp_send_reply(server, str); ctcp_send_reply(server, str);
g_free(str); g_free(str);

View File

@ -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, static void event_nick(SERVER_REC *server, const char *data,
const char *orignick) const char *orignick)
{ {
IRC_CHANNEL_REC *channel;
NICK_REC *nickrec;
GSList *nicks, *tmp;
char *params, *nick; char *params, *nick;
g_return_if_fail(data != NULL); 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); signal_emit("server nick changed", 1, server);
} }
nicks = nicklist_get_same(server, orignick); nicklist_rename(server, orignick, nick);
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);
g_free(params); g_free(params);
} }