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;
}
/* 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 */
char *show_lowascii(const char *channel);
/* Get time in human readable form with localtime() + asctime() */
char *my_asctime(time_t t);
#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)
{
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);

View File

@ -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);

View File

@ -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);

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,
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);
}