From 079932c4054fa6dd435268c2945b97fe01aff579 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 26 Nov 2000 09:22:18 +0000 Subject: [PATCH] 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 --- src/core/core.c | 3 -- src/fe-common/core/themes.c | 6 +++- src/fe-text/irssi.c | 3 ++ src/perl/common/Irssi.xs | 1 + src/perl/common/Makefile.PL.in | 2 +- src/perl/common/Window.xs | 8 ++--- src/perl/common/module.h | 9 ++++-- src/perl/perl-common.c | 32 +++++++++++++++++++ src/perl/perl-common.h | 3 ++ src/perl/perl.c | 58 ++++++++++++++++++++++++++-------- 10 files changed, 101 insertions(+), 24 deletions(-) diff --git a/src/core/core.c b/src/core/core.c index ef80f2f5..5f7f76f5 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -75,9 +75,6 @@ void core_init(void) void core_deinit(void) { - while (modules != NULL) - module_unload(modules->data); - chat_commands_deinit(); nicklist_deinit(); diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c index 66c023c9..e7e17cc9 100644 --- a/src/fe-common/core/themes.c +++ b/src/fe-common/core/themes.c @@ -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); diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c index df11ea66..4ae4f541 100644 --- a/src/fe-text/irssi.c +++ b/src/fe-text/irssi.c @@ -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(); diff --git a/src/perl/common/Irssi.xs b/src/perl/common/Irssi.xs index 53e5196e..b2cb24fc 100644 --- a/src/perl/common/Irssi.xs +++ b/src/perl/common/Irssi.xs @@ -14,4 +14,5 @@ INCLUDE: Query.xs INCLUDE: Rawlog.xs INCLUDE: Server.xs INCLUDE: Settings.xs +INCLUDE: Themes.xs INCLUDE: Window.xs diff --git a/src/perl/common/Makefile.PL.in b/src/perl/common/Makefile.PL.in index df6f8c2c..9c11f0f7 100644 --- a/src/perl/common/Makefile.PL.in +++ b/src/perl/common/Makefile.PL.in @@ -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'); diff --git a/src/perl/common/Window.xs b/src/perl/common/Window.xs index 8ca06123..3b730bc6 100644 --- a/src/perl/common/Window.xs +++ b/src/perl/common/Window.xs @@ -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); diff --git a/src/perl/common/module.h b/src/perl/common/module.h index 24bc3de6..c7db2d3a 100644 --- a/src/perl/common/module.h +++ b/src/perl/common/module.h @@ -3,7 +3,9 @@ #include #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; diff --git a/src/perl/perl-common.c b/src/perl/perl-common.c index d20d3ab4..d6e6192d 100644 --- a/src/perl/perl-common.c +++ b/src/perl/perl-common.c @@ -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[] = { diff --git a/src/perl/perl-common.h b/src/perl/perl-common.h index 9684c7fd..267ab094 100644 --- a/src/perl/perl-common.h +++ b/src/perl/perl-common.h @@ -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) \ diff --git a/src/perl/perl.c b/src/perl/perl.c index 9d31fa11..3d9c0f20 100644 --- a/src/perl/perl.c +++ b/src/perl/perl.c @@ -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;