Split expandos from special-vars.c to expandos.c. Added list of signals

to each expando that can might change it's value.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@964 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-12-05 00:53:04 +00:00 committed by cras
commit d1eaeca255
19 changed files with 687 additions and 520 deletions

View file

@ -17,6 +17,7 @@ libirc_core_a_SOURCES = \
irc-channels-setup.c \
irc-chatnets.c \
irc-commands.c \
irc-expandos.c \
irc-log.c \
irc-masks.c \
irc-nicklist.c \
@ -25,7 +26,6 @@ libirc_core_a_SOURCES = \
irc-servers.c \
irc-servers-reconnect.c \
irc-servers-setup.c \
irc-special-vars.c \
lag.c \
massjoin.c \
modes.c \

View file

@ -36,8 +36,8 @@ void irc_commands_deinit(void);
void irc_rawlog_init(void);
void irc_rawlog_deinit(void);
void irc_special_vars_init(void);
void irc_special_vars_deinit(void);
void irc_expandos_init(void);
void irc_expandos_deinit(void);
void irc_log_init(void);
void irc_log_deinit(void);
@ -67,14 +67,14 @@ void irc_core_init(void)
lag_init();
netsplit_init();
irc_rawlog_init();
irc_special_vars_init();
irc_expandos_init();
irc_log_init();
}
void irc_core_deinit(void)
{
irc_log_deinit();
irc_special_vars_deinit();
irc_expandos_deinit();
irc_rawlog_deinit();
netsplit_deinit();
lag_deinit();

119
src/irc/core/irc-expandos.c Normal file
View file

@ -0,0 +1,119 @@
/*
irc-expandos.c : irssi
Copyright (C) 2000 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "module.h"
#include "misc.h"
#include "expandos.h"
#include "settings.h"
#include "irc.h"
#include "irc-servers.h"
static char *last_join;
/* last person to join a channel you are on */
static char *expando_lastjoin(SERVER_REC *server, void *item, int *free_ret)
{
return last_join;
}
/* current server numeric being processed */
static char *expando_server_numeric(SERVER_REC *server, void *item, int *free_ret)
{
return current_server_event == NULL ||
!is_numeric(current_server_event, 0) ? NULL :
current_server_event;
}
/* current server name */
static char *expando_servername(SERVER_REC *server, void *item, int *free_ret)
{
IRC_SERVER_REC *ircserver = IRC_SERVER(server);
return ircserver == NULL ? "" : ircserver->real_address;
}
/* your /userhost $N address (user@host) */
static char *expando_userhost(SERVER_REC *server, void *item, int *free_ret)
{
IRC_SERVER_REC *ircserver;
const char *username;
char hostname[100];
ircserver = IRC_SERVER(server);
/* prefer the _real_ /userhost reply */
if (ircserver != NULL && ircserver->userhost != NULL)
return ircserver->userhost;
/* haven't received userhost reply yet. guess something */
*free_ret = TRUE;
if (server == NULL)
username = settings_get_str("user_name");
else
username = ircserver->connrec->username;
if (gethostname(hostname, sizeof(hostname)) != 0 || *hostname == '\0')
strcpy(hostname, "??");
return g_strconcat(username, "@", hostname, NULL);;
}
static void event_join(const char *data, IRC_SERVER_REC *server,
const char *nick, const char *address)
{
g_return_if_fail(nick != NULL);
if (g_strcasecmp(nick, server->nick) != 0) {
g_free_not_null(last_join);
last_join = g_strdup(nick);
}
}
void irc_expandos_init(void)
{
last_join = NULL;
expando_create(":", expando_lastjoin,
"event join", EXPANDO_ARG_SERVER2, NULL);
expando_create("H", expando_server_numeric,
"server event", EXPANDO_ARG_SERVER, NULL);
expando_create("S", expando_servername,
"window changed", EXPANDO_ARG_NONE,
"window server changed", EXPANDO_ARG_WINDOW, NULL);
expando_create("X", expando_userhost,
"window changed", EXPANDO_ARG_NONE,
"window server changed", EXPANDO_ARG_WINDOW, NULL);
expando_add_signal("I", "event invite", EXPANDO_ARG_SERVER2);
signal_add("event join", (SIGNAL_FUNC) event_join);
}
void irc_expandos_deinit(void)
{
g_free_not_null(last_join);
expando_destroy(":", expando_lastjoin);
expando_destroy("H", expando_server_numeric);
expando_destroy("S", expando_servername);
expando_destroy("X", expando_userhost);
signal_remove("event join", (SIGNAL_FUNC) event_join);
}

View file

@ -1,208 +0,0 @@
/*
irc-special-vars.c : irssi
Copyright (C) 2000 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "module.h"
#include "misc.h"
#include "special-vars.h"
#include "settings.h"
#include "window-item-def.h"
#include "irc.h"
#include "irc-servers.h"
#include "channels.h"
#include "queries.h"
static char *last_privmsg_from;
static char *last_sent_msg, *last_sent_msg_body;
static char *last_join, *last_public_from;
/* last person who sent you a MSG */
static char *expando_lastmsg(SERVER_REC *server, void *item, int *free_ret)
{
return last_privmsg_from;
}
/* last person to whom you sent a MSG */
static char *expando_lastmymsg(SERVER_REC *server, void *item, int *free_ret)
{
return last_sent_msg;
}
/* last person to join a channel you are on */
static char *expando_lastjoin(SERVER_REC *server, void *item, int *free_ret)
{
return last_join;
}
/* last person to send a public message to a channel you are on */
static char *expando_lastpublic(SERVER_REC *server, void *item, int *free_ret)
{
return last_public_from;
}
/* body of last MSG you sent */
static char *expando_lastmymsg_body(SERVER_REC *server, void *item, int *free_ret)
{
return last_sent_msg_body;
}
/* current server numeric being processed */
static char *expando_server_numeric(SERVER_REC *server, void *item, int *free_ret)
{
return current_server_event == NULL ||
!is_numeric(current_server_event, 0) ? NULL :
current_server_event;
}
/* channel you were last INVITEd to */
static char *expando_last_invite(SERVER_REC *server, void *item, int *free_ret)
{
IRC_SERVER_REC *ircserver = IRC_SERVER(server);
return ircserver == NULL ? "" : ircserver->last_invite;
}
/* current server name */
static char *expando_servername(SERVER_REC *server, void *item, int *free_ret)
{
IRC_SERVER_REC *ircserver = IRC_SERVER(server);
return ircserver == NULL ? "" : ircserver->real_address;
}
/* your /userhost $N address (user@host) */
static char *expando_userhost(SERVER_REC *server, void *item, int *free_ret)
{
IRC_SERVER_REC *ircserver;
const char *username;
char hostname[100];
ircserver = IRC_SERVER(server);
/* prefer the _real_ /userhost reply */
if (ircserver != NULL && ircserver->userhost != NULL)
return ircserver->userhost;
/* haven't received userhost reply yet. guess something */
*free_ret = TRUE;
if (server == NULL)
username = settings_get_str("user_name");
else
username = ircserver->connrec->username;
if (gethostname(hostname, sizeof(hostname)) != 0 || *hostname == '\0')
strcpy(hostname, "??");
return g_strconcat(username, "@", hostname, NULL);;
}
static void event_privmsg(const char *data, IRC_SERVER_REC *server,
const char *nick, const char *addr)
{
char *params, *target, *msg;
g_return_if_fail(data != NULL);
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
if (!ischannel(*target)) {
g_free_not_null(last_privmsg_from);
last_privmsg_from = g_strdup(nick);
} else {
g_free_not_null(last_public_from);
last_public_from = g_strdup(nick);
}
g_free(params);
}
static void cmd_msg(const char *data, IRC_SERVER_REC *server)
{
char *target, *msg;
void *free_arg;
g_return_if_fail(data != NULL);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
&target, &msg))
return;
if (*target != '\0' && *msg != '\0' &&
!ischannel(*target) && isalpha(*target)) {
g_free_not_null(last_sent_msg);
g_free_not_null(last_sent_msg_body);
last_sent_msg = g_strdup(target);
last_sent_msg_body = g_strdup(msg);
}
cmd_params_free(free_arg);
}
static void event_join(const char *data, IRC_SERVER_REC *server,
const char *nick, const char *address)
{
g_return_if_fail(nick != NULL);
if (g_strcasecmp(nick, server->nick) != 0) {
g_free_not_null(last_join);
last_join = g_strdup(nick);
}
}
void irc_special_vars_init(void)
{
last_privmsg_from = NULL;
last_sent_msg = NULL; last_sent_msg_body = NULL;
last_join = NULL; last_public_from = NULL;
expando_create(",", expando_lastmsg);
expando_create(".", expando_lastmymsg);
expando_create(":", expando_lastjoin);
expando_create(";", expando_lastpublic);
expando_create("B", expando_lastmymsg_body);
expando_create("H", expando_server_numeric);
expando_create("I", expando_last_invite);
expando_create("S", expando_servername);
expando_create("X", expando_userhost);
signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_add("event join", (SIGNAL_FUNC) event_join);
signal_add("command msg", (SIGNAL_FUNC) cmd_msg);
}
void irc_special_vars_deinit(void)
{
g_free_not_null(last_privmsg_from);
g_free_not_null(last_sent_msg); g_free_not_null(last_sent_msg_body);
g_free_not_null(last_join); g_free_not_null(last_public_from);
expando_destroy(",", expando_lastmsg);
expando_destroy(".", expando_lastmymsg);
expando_destroy(":", expando_lastjoin);
expando_destroy(";", expando_lastpublic);
expando_destroy("B", expando_lastmymsg_body);
expando_destroy("H", expando_server_numeric);
expando_destroy("I", expando_last_invite);
expando_destroy("S", expando_servername);
expando_destroy("X", expando_userhost);
signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_remove("event join", (SIGNAL_FUNC) event_join);
signal_remove("command msg", (SIGNAL_FUNC) cmd_msg);
}

View file

@ -237,7 +237,7 @@ char *event_get_params(const char *data, int count, ...)
return duprec;
}
static void irc_server_event(const char *line, IRC_SERVER_REC *server, const char *nick, const char *address)
static void irc_server_event(IRC_SERVER_REC *server, const char *line, const char *nick, const char *address)
{
char *event, *args, *callcmd;
GSList *list;
@ -329,7 +329,7 @@ static void irc_parse_incoming_line(IRC_SERVER_REC *server, char *line)
line = irc_parse_prefix(line, &nick, &address);
if (*line != '\0')
signal_emit_id(signal_server_event, 4, line, server, nick, address);
signal_emit_id(signal_server_event, 4, server, line, nick, address);
}
/* input function: handle incoming server messages */

View file

@ -20,7 +20,7 @@
#include "module.h"
#include "signals.h"
#include "special-vars.h"
#include "expandos.h"
#include "irc.h"
#include "irc-servers.h"
@ -168,7 +168,8 @@ void notifylist_whois_init(void)
signal_add("notifylist event whois away", (SIGNAL_FUNC) event_whois_away);
signal_add("notifylist event whois idle", (SIGNAL_FUNC) event_whois_idle);
signal_add("notifylist event whois end", (SIGNAL_FUNC) event_whois_end);
expando_create("D", expando_lastnotify);
expando_create("D", expando_lastnotify,
"notifylist event whois", EXPANDO_ARG_SERVER2, NULL);
}
void notifylist_whois_deinit(void)

View file

@ -321,7 +321,7 @@ static void sig_incoming(IRC_SERVER_REC *server, const char *line)
g_string_sprintf(next_line, "%s\n", line);
}
static void sig_server_event(const char *line, IRC_SERVER_REC *server,
static void sig_server_event(IRC_SERVER_REC *server, const char *line,
const char *nick, const char *address)
{
GSList *list;