1
0
mirror of https://github.com/irssi/irssi.git synced 2024-06-16 06:25:24 +00:00

Perl fixes and additions. theme_register() / printformat() works now

with scripts


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@884 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-11-26 09:22:18 +00:00 committed by cras
parent 9a7491fbe6
commit 079932c405
10 changed files with 101 additions and 24 deletions

View File

@ -75,9 +75,6 @@ void core_init(void)
void core_deinit(void)
{
while (modules != NULL)
module_unload(modules->data);
chat_commands_deinit();
nicklist_deinit();

View File

@ -584,7 +584,10 @@ void theme_register_module(const char *module, FORMAT_REC *formats)
void theme_unregister_module(const char *module)
{
gpointer key, value;
gpointer key, value;
if (default_formats == NULL)
return; /* already uninitialized */
if (!g_hash_table_lookup_extended(default_formats, module, &key, &value))
return;
@ -1004,6 +1007,7 @@ void themes_deinit(void)
theme_destroy(themes->data);
g_hash_table_destroy(default_formats);
default_formats = NULL;
command_unbind("format", (SIGNAL_FUNC) cmd_format);
command_unbind("save", (SIGNAL_FUNC) cmd_save);

View File

@ -123,6 +123,9 @@ static void textui_deinit(void)
quitting = TRUE;
signal(SIGINT, SIG_DFL);
while (modules != NULL)
module_unload(modules->data);
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
gui_textwidget_deinit();
gui_special_vars_deinit();

View File

@ -14,4 +14,5 @@ INCLUDE: Query.xs
INCLUDE: Rawlog.xs
INCLUDE: Server.xs
INCLUDE: Settings.xs
INCLUDE: Themes.xs
INCLUDE: Window.xs

View File

@ -2,5 +2,5 @@ use ExtUtils::MakeMaker;
WriteMakefile('NAME' => 'Irssi',
'LIBS' => '',
'INC' => '-I@top_srcdir@/src -I@top_srcdir@/src/core @GLIB_CFLAGS@',
'INC' => '-I@top_srcdir@ -I@top_srcdir@/src -I@top_srcdir@/src/core @GLIB_CFLAGS@',
'VERSION_FROM' => '@srcdir@/Irssi.pm');

View File

@ -298,13 +298,13 @@ window_item_is_active(item)
#*******************************
MODULE = Irssi PACKAGE = Irssi::Channel
MODULE = Irssi PACKAGE = Irssi::Windowitem
#*******************************
void
print(channel, str, level=MSGLEVEL_CLIENTNOTICE)
Irssi::Channel channel
print(item, str, level=MSGLEVEL_CLIENTNOTICE)
Irssi::Windowitem item
int level
char *str
CODE:
printtext(channel->server, channel->name, level, str);
printtext(item->server, item->name, level, str);

View File

@ -3,7 +3,9 @@
#include <XSUB.h>
#undef _
#undef VERSION
#include "../module.h"
#include "network.h"
#include "commands.h"
#include "log.h"
@ -15,18 +17,21 @@
#include "chatnets.h"
#include "servers.h"
#include "servers-reconnect.h"
#include "servers-redirect.h"
#include "servers-setup.h"
#include "channels.h"
#include "queries.h"
#include "nicklist.h"
#include "perl/perl-common.h"
#include "fe-common/core/fe-windows.h"
#include "fe-common/core/formats.h"
#include "fe-common/core/printtext.h"
#include "fe-common/core/window-items.h"
#include "fe-common/core/themes.h"
#include "fe-common/core/keyboard.h"
#include "perl/perl-common.h"
typedef COMMAND_REC *Irssi__Command;
typedef LOG_REC *Irssi__Log;
typedef LOG_ITEM_REC *Irssi__LogItem;

View File

@ -39,8 +39,20 @@
#include "perl-common.h"
#include "fe-common/core/formats.h"
#include "fe-common/core/printtext.h"
GHashTable *perl_stashes;
/* returns the package who called us */
char *perl_get_package(void)
{
STRLEN n_a;
perl_eval_pv("($package) = caller;", TRUE);
return SvPV(perl_get_sv("package", FALSE), n_a);
}
HV *irssi_get_stash_item(int type, int chat_type)
{
char *str;
@ -157,6 +169,26 @@ void perl_query_fill_hash(HV *hv, QUERY_REC *query)
hv_store(hv, "unwanted", 8, newSViv(query->unwanted), 0);
}
void printformat_perl(TEXT_DEST_REC *dest, char *format, char **arglist)
{
THEME_REC *theme;
char *module, *str;
int formatnum;
module = g_strdup(perl_get_package());
theme = dest->window->theme == NULL ? current_theme :
dest->window->theme;
formatnum = format_find_tag(module, format);
signal_emit("print format", 5, theme, module,
&dest, GINT_TO_POINTER(formatnum), arglist);
str = format_get_text_theme_charargs(theme, module, dest, formatnum, arglist);
if (*str != '\0') printtext_window(dest->window, dest->level, "%s", str);
g_free(str);
g_free(module);
}
static void perl_register_protocol(CHAT_PROTOCOL_REC *rec)
{
static char *items[] = {

View File

@ -9,6 +9,9 @@
extern GHashTable *perl_stashes;
/* returns the package who called us */
char *perl_get_package(void);
HV *irssi_get_stash_item(int type, int chat_type);
#define irssi_get_stash(item) \

View File

@ -35,6 +35,9 @@
#include "perl-common.h"
#include "servers.h"
#include "fe-common/core/themes.h"
#include "fe-common/core/formats.h"
/* For compatibility with perl 5.004 and older */
#ifndef ERRSV
# define ERRSV GvSV(errgv)
@ -199,23 +202,41 @@ static int signal_destroy_hash(void *key, GSList **list, const char *package)
return TRUE;
}
static void perl_unregister_theme(const char *package)
{
FORMAT_REC *formats;
int n;
formats = g_hash_table_lookup(default_formats, package);
if (formats == NULL) return;
for (n = 0; formats[n].def != NULL; n++) {
g_free(formats[n].tag);
g_free(formats[n].def);
}
g_free(formats);
theme_unregister_module(package);
}
static int perl_script_destroy(const char *name)
{
GSList *tmp, *next;
GSList *tmp, *next, *item;
char *package;
int package_len;
if (gslist_find_string(perl_scripts, name) == NULL)
return FALSE;
item = gslist_find_string(perl_scripts, name);
if (item == NULL) return FALSE;
package = g_strdup_printf("Irssi::Script::%s::", name);
package = g_strdup_printf("Irssi::Script::%s", name);
package_len = strlen(package);
/* signals */
g_hash_table_foreach_remove(first_signals,
(GHRFunc) signal_destroy_hash, package);
g_hash_table_foreach_remove(last_signals,
(GHRFunc) signal_destroy_hash, package);
/* timeouts and input waits */
for (tmp = perl_sources; tmp != NULL; tmp = next) {
PERL_SOURCE_REC *rec = tmp->data;
@ -224,12 +245,21 @@ static int perl_script_destroy(const char *name)
perl_source_destroy(rec);
}
/* theme */
perl_unregister_theme(package);
g_free(package);
g_free(item->data);
perl_scripts = g_slist_remove(perl_scripts, item->data);
return TRUE;
}
static void irssi_perl_stop(void)
{
GSList *tmp;
char *package;
/* signals */
g_hash_table_foreach(first_signals,
(GHFunc) signal_destroy_hash, NULL);
g_hash_table_destroy(first_signals);
@ -248,13 +278,24 @@ static void irssi_perl_stop(void)
signal_remove("last signal", (SIGNAL_FUNC) sig_lastsignal);
}
/* timeouts and input waits */
while (perl_sources != NULL)
perl_source_destroy(perl_sources->data);
/* themes */
for (tmp = perl_scripts; tmp != NULL; tmp = tmp->next) {
package = g_strdup_printf("Irssi::Script::%s",
(char *) tmp->data);
perl_unregister_theme(package);
g_free(package);
}
/* scripts list */
g_slist_foreach(perl_scripts, (GFunc) g_free, NULL);
g_slist_free(perl_scripts);
perl_scripts = NULL;
/* perl interpreter */
perl_destruct(irssi_perl_interp);
perl_free(irssi_perl_interp);
irssi_perl_interp = NULL;
@ -350,15 +391,6 @@ static void cmd_perlflush(const char *data)
irssi_perl_start();
}
/* returns the package who called us */
static char *perl_get_package(void)
{
STRLEN n_a;
perl_eval_pv("($package) = caller;", TRUE);
return SvPV(perl_get_sv("package", FALSE), n_a);
}
static void perl_signal_to(const char *signal, const char *func, int last)
{
PERL_SIGNAL_REC *rec;