diff options
author | Timo Sirainen <cras@irssi.org> | 2001-06-27 22:56:17 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-06-27 22:56:17 +0000 |
commit | 89d7498019b64ae5f89b6f09f32aaa9d876a9da3 (patch) | |
tree | 1b289e5394b6dc0db092459fbabaaf049b285715 /src/perl/ui | |
parent | d7342a6c4fac7956ddef141c8a2f88a1e7b0378c (diff) | |
download | irssi-89d7498019b64ae5f89b6f09f32aaa9d876a9da3.zip |
Moved fe_perl module to use Irssi::UI .. this breaks several scripts that
use UI-specific code, but simply adding the "use Irssi::UI;" after use
Irssi; should work. make install now removes libfe_perl.* files from global
module directory, but if you have it somewhere else you should manually
remove it.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1582 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/perl/ui')
-rw-r--r-- | src/perl/ui/.cvsignore | 7 | ||||
-rw-r--r-- | src/perl/ui/Makefile.PL.in | 7 | ||||
-rw-r--r-- | src/perl/ui/Themes.xs | 124 | ||||
-rw-r--r-- | src/perl/ui/UI.pm | 24 | ||||
-rw-r--r-- | src/perl/ui/UI.xs | 132 | ||||
-rw-r--r-- | src/perl/ui/Window.xs | 277 | ||||
-rw-r--r-- | src/perl/ui/module.h | 14 | ||||
-rw-r--r-- | src/perl/ui/typemap | 16 |
8 files changed, 601 insertions, 0 deletions
diff --git a/src/perl/ui/.cvsignore b/src/perl/ui/.cvsignore new file mode 100644 index 00000000..239deafc --- /dev/null +++ b/src/perl/ui/.cvsignore @@ -0,0 +1,7 @@ +Makefile +Makefile.PL +UI.c +UI.bs +*.o +pm_to_blib +blib diff --git a/src/perl/ui/Makefile.PL.in b/src/perl/ui/Makefile.PL.in new file mode 100644 index 00000000..601c3b9d --- /dev/null +++ b/src/perl/ui/Makefile.PL.in @@ -0,0 +1,7 @@ +use ExtUtils::MakeMaker; + +WriteMakefile('NAME' => 'Irssi::UI', + 'LIBS' => '', + 'TYPEMAPS' => ['../common/typemap'], + 'INC' => '-I../../.. -I@top_srcdir@/src -I@top_srcdir@/src/core -I@top_srcdir@/src/fe-common/core @GLIB_CFLAGS@', + 'VERSION_FROM' => '@srcdir@/UI.pm'); diff --git a/src/perl/ui/Themes.xs b/src/perl/ui/Themes.xs new file mode 100644 index 00000000..427952ff --- /dev/null +++ b/src/perl/ui/Themes.xs @@ -0,0 +1,124 @@ + +MODULE = Irssi::UI PACKAGE = Irssi + +void +theme_register(formats) + SV *formats +PREINIT: + STRLEN n_a; + AV *av; + FORMAT_REC *formatrecs; + char *key, *value; + int len, n, fpos; +CODE: + + if (!SvROK(formats)) + croak("formats is not a reference to list"); + av = (AV *) SvRV(formats); + len = av_len(av)+1; + if (len == 0 || (len & 1) != 0) + croak("formats list is invalid - not dividable by 3 (%d)", len); + + formatrecs = g_new0(FORMAT_REC, len/2+2); + formatrecs[0].tag = g_strdup(perl_get_package()); + formatrecs[0].def = g_strdup("Perl script"); + + for (fpos = 1, n = 0; n < len; n++, fpos++) { + key = SvPV(*av_fetch(av, n, 0), n_a); n++; + value = SvPV(*av_fetch(av, n, 0), n_a); + + formatrecs[fpos].tag = g_strdup(key); + formatrecs[fpos].def = g_strdup(value); + formatrecs[fpos].params = MAX_FORMAT_PARAMS; + } + + theme_register_module(perl_get_package(), formatrecs); + +void +printformat(level, format, ...) + int level + char *format +PREINIT: + STRLEN n_a; + TEXT_DEST_REC dest; + char *arglist[MAX_FORMAT_PARAMS]; + int n; +CODE: + format_create_dest(&dest, NULL, NULL, level, NULL); + memset(arglist, 0, sizeof(arglist)); + for (n = 2; n < 2+MAX_FORMAT_PARAMS; n++) { + arglist[n-2] = n < items ? SvPV(ST(n), n_a) : ""; + } + + printformat_perl(&dest, format, arglist); + +#******************************* +MODULE = Irssi::UI PACKAGE = Irssi::Server +#******************************* + +void +printformat(server, target, level, format, ...) + Irssi::Server server + char *target + int level + char *format +PREINIT: + STRLEN n_a; + TEXT_DEST_REC dest; + char *arglist[MAX_FORMAT_PARAMS]; + int n; +CODE: + format_create_dest(&dest, server, target, level, NULL); + memset(arglist, 0, sizeof(arglist)); + for (n = 4; n < 4+MAX_FORMAT_PARAMS; n++) { + arglist[n-4] = n < items ? SvPV(ST(n), n_a) : ""; + } + + printformat_perl(&dest, format, arglist); + +#******************************* +MODULE = Irssi::UI PACKAGE = Irssi::UI::Window +#******************************* + +void +printformat(window, level, format, ...) + Irssi::UI::Window window + int level + char *format +PREINIT: + STRLEN n_a; + TEXT_DEST_REC dest; + char *arglist[MAX_FORMAT_PARAMS]; + int n; +CODE: + format_create_dest(&dest, NULL, NULL, level, window); + memset(arglist, 0, sizeof(arglist)); + for (n = 3; n < 3+MAX_FORMAT_PARAMS; n++) { + arglist[n-3] = n < items ? SvPV(ST(n), n_a) : ""; + } + + printformat_perl(&dest, format, arglist); + +#******************************* +MODULE = Irssi::UI PACKAGE = Irssi::Windowitem +#******************************* + +void +printformat(item, level, format, ...) + Irssi::Windowitem item + int level + char *format +PREINIT: + STRLEN n_a; + TEXT_DEST_REC dest; + char *arglist[MAX_FORMAT_PARAMS]; + int n; +CODE: + format_create_dest(&dest, item->server, item->name, level, NULL); + memset(arglist, 0, sizeof(arglist)); + for (n = 3; n < 3+MAX_FORMAT_PARAMS; n++) { + arglist[n-3] = n < items ? SvPV(ST(n), n_a) : ""; + } + + printformat_perl(&dest, format, arglist); + diff --git a/src/perl/ui/UI.pm b/src/perl/ui/UI.pm new file mode 100644 index 00000000..acf60e8b --- /dev/null +++ b/src/perl/ui/UI.pm @@ -0,0 +1,24 @@ +# +# Perl interface to irssi functions. +# + +package Irssi::UI; + +use strict; +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); + +$VERSION = "0.20"; + +require Exporter; +require DynaLoader; + +@ISA = qw(Exporter DynaLoader); +@EXPORT = qw(active_win active_server print command printformat); +@EXPORT_OK = qw(); + +bootstrap Irssi::UI $VERSION; + +Irssi::UI::init(); + +1; + diff --git a/src/perl/ui/UI.xs b/src/perl/ui/UI.xs new file mode 100644 index 00000000..165e73de --- /dev/null +++ b/src/perl/ui/UI.xs @@ -0,0 +1,132 @@ +#include "module.h" + +static void perl_process_fill_hash(HV *hv, PROCESS_REC *process) +{ + hv_store(hv, "id", 2, newSViv(process->id), 0); + hv_store(hv, "name", 4, new_pv(process->name), 0); + hv_store(hv, "args", 4, new_pv(process->args), 0); + + hv_store(hv, "pid", 3, newSViv(process->pid), 0); + hv_store(hv, "target", 6, new_pv(process->target), 0); + if (process->target_win != NULL) { + hv_store(hv, "target_win", 10, + plain_bless(process->target_win, "Irssi::UI::Window"), 0); + } + hv_store(hv, "shell", 5, newSViv(process->shell), 0); + hv_store(hv, "notice", 6, newSViv(process->notice), 0); + hv_store(hv, "silent", 6, newSViv(process->silent), 0); +} + +static void perl_window_fill_hash(HV *hv, WINDOW_REC *window) +{ + hv_store(hv, "refnum", 6, newSViv(window->refnum), 0); + hv_store(hv, "name", 4, new_pv(window->name), 0); + + if (window->active) + hv_store(hv, "active", 6, irssi_bless(window->active), 0); + if (window->active_server) + hv_store(hv, "active_server", 13, irssi_bless(window->active_server), 0); + + hv_store(hv, "level", 5, newSViv(window->level), 0); + hv_store(hv, "data_level", 8, newSViv(window->data_level), 0); + hv_store(hv, "hilight_color", 10, new_pv(window->hilight_color), 0); + hv_store(hv, "last_timestamp", 14, newSViv(window->last_timestamp), 0); + hv_store(hv, "last_line", 9, newSViv(window->last_line), 0); +} + +static void perl_text_dest_fill_hash(HV *hv, TEXT_DEST_REC *dest) +{ + hv_store(hv, "window", 6, plain_bless(dest->window, "Irssi::UI::Window"), 0); + hv_store(hv, "server", 6, irssi_bless(dest->server), 0); + hv_store(hv, "target", 6, new_pv(dest->target), 0); + hv_store(hv, "level", 5, newSViv(dest->level), 0); + + hv_store(hv, "hilight_priority", 16, newSViv(dest->hilight_priority), 0); + hv_store(hv, "hilight_color", 13, new_pv(dest->hilight_color), 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_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 void sig_script_destroy(const char *type, const char *name, + const char *package) +{ + if (strcmp(type, "PERL") == 0) + perl_unregister_theme(package); +} + +static void sig_perl_stop(void) +{ + GSList *tmp; + char *package; + + /* 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); + } +} + +static PLAIN_OBJECT_INIT_REC fe_plains[] = { + { "Irssi::UI::Process", (PERL_OBJECT_FUNC) perl_process_fill_hash }, + { "Irssi::UI::Window", (PERL_OBJECT_FUNC) perl_window_fill_hash }, + { "Irssi::UI::TextDest", (PERL_OBJECT_FUNC) perl_text_dest_fill_hash }, + + { NULL, NULL } +}; + +MODULE = Irssi::UI PACKAGE = Irssi::UI + +PROTOTYPES: ENABLE + +void +init() +PREINIT: + static int initialized = FALSE; +CODE: + if (initialized) return; + initialized = TRUE; + + irssi_add_plains(fe_plains); + + signal_add("script destroy", (SIGNAL_FUNC) sig_script_destroy); + signal_add("perl stop", (SIGNAL_FUNC) sig_perl_stop); + + +INCLUDE: Themes.xs +INCLUDE: Window.xs diff --git a/src/perl/ui/Window.xs b/src/perl/ui/Window.xs new file mode 100644 index 00000000..cbee5a82 --- /dev/null +++ b/src/perl/ui/Window.xs @@ -0,0 +1,277 @@ +MODULE = Irssi::UI PACKAGE = Irssi + +void +windows() +PREINIT: + GSList *tmp; +PPCODE: + for (tmp = windows; tmp != NULL; tmp = tmp->next) { + XPUSHs(sv_2mortal(plain_bless(tmp->data, "Irssi::UI::Window"))); + } + + +Irssi::UI::Window +active_win() +CODE: + RETVAL = active_win; +OUTPUT: + RETVAL + +Irssi::Server +active_server() +CODE: + RETVAL = active_win->active_server; +OUTPUT: + RETVAL + +void +print(str, level=MSGLEVEL_CLIENTNOTICE) + char *str + int level; +CODE: + printtext_string(NULL, NULL, level, str); + +void +command(cmd) + char *cmd +CODE: + perl_command(cmd, active_win->active_server, active_win->active); + +Irssi::UI::Window +window_find_name(name) + char *name + +Irssi::UI::Window +window_find_refnum(refnum) + int refnum + +int +window_refnum_prev(refnum, wrap) + int refnum + int wrap + +int +window_refnum_next(refnum, wrap) + int refnum + int wrap + +int +windows_refnum_last() + +Irssi::UI::Window +window_find_level(level) + int level +CODE: + RETVAL = window_find_level(NULL, level); +OUTPUT: + RETVAL + +Irssi::UI::Window +window_find_item(name) + char *name +CODE: + RETVAL = window_find_item(NULL, name); +OUTPUT: + RETVAL + +Irssi::UI::Window +window_find_closest(name, level) + char *name + int level +CODE: + RETVAL = window_find_closest(NULL, name, level); +OUTPUT: + RETVAL + +Irssi::Windowitem +window_item_find(name) + char *name +CODE: + RETVAL = window_item_find(NULL, name); +OUTPUT: + RETVAL + + +#******************************* +MODULE = Irssi::UI PACKAGE = Irssi::Server +#******************************* + +void +command(server, cmd) + Irssi::Server server + char *cmd +CODE: + perl_command(cmd, server, active_win->active); + +void +print(server, channel, str, level) + Irssi::Server server + char *channel + char *str + int level +CODE: + printtext_string(server, channel, level, str); + +Irssi::Windowitem +window_item_find(server, name) + Irssi::Server server + char *name + +Irssi::UI::Window +window_find_item(server, name) + Irssi::Server server + char *name + +Irssi::UI::Window +window_find_level(server, level) + Irssi::Server server + int level + +Irssi::UI::Window +window_find_closest(server, name, level) + Irssi::Server server + char *name + int level + + +#******************************* +MODULE = Irssi::UI PACKAGE = Irssi::UI::Window PREFIX=window_ +#******************************* + +void +items(window) + Irssi::UI::Window window +PREINIT: + GSList *tmp; +PPCODE: + for (tmp = window->items; tmp != NULL; tmp = tmp->next) { + CHANNEL_REC *rec = tmp->data; + + XPUSHs(sv_2mortal(irssi_bless(rec))); + } + +void +print(window, str, level=MSGLEVEL_CLIENTNOTICE) + Irssi::UI::Window window + char *str + int level; +CODE: + printtext_window(window, level, str); + +void +command(window, cmd) + Irssi::UI::Window window + char *cmd +CODE: + perl_command(cmd, window->active_server, window->active); + +void +window_item_add(window, item, automatic) + Irssi::UI::Window window + Irssi::Windowitem item + int automatic + +void +window_item_remove(item) + Irssi::Windowitem item + +void +window_item_destroy(item) + Irssi::Windowitem item + +void +window_item_prev(window) + Irssi::UI::Window window + +void +window_item_next(window) + Irssi::UI::Window window + +void +window_destroy(window) + Irssi::UI::Window window + +void +window_set_active(window) + Irssi::UI::Window window + +void +window_change_server(window, server) + Irssi::UI::Window window + Irssi::Server server + +void +window_set_refnum(window, refnum) + Irssi::UI::Window window + int refnum + +void +window_set_name(window, name) + Irssi::UI::Window window + char *name + +void +window_set_level(window, level) + Irssi::UI::Window window + int level + +char * +window_get_active_name(window) + Irssi::UI::Window window + +Irssi::Windowitem +window_item_find(window, server, name) + Irssi::UI::Window window + Irssi::Server server + char *name +CODE: + RETVAL = window_item_find_window(window, server, name); +OUTPUT: + RETVAL + +#******************************* +MODULE = Irssi::UI PACKAGE = Irssi::Windowitem PREFIX = window_item_ +#******************************* + +void +print(item, str, level=MSGLEVEL_CLIENTNOTICE) + Irssi::Windowitem item + int level + char *str +CODE: + printtext_string(item->server, item->name, level, str); + +void +command(item, cmd) + Irssi::Windowitem item + char *cmd +CODE: + perl_command(cmd, item->server, item); + +Irssi::UI::Window +window_create(item, automatic) + Irssi::Windowitem item + int automatic + +Irssi::UI::Window +window(item) + Irssi::Windowitem item +CODE: + RETVAL = window_item_window(item); +OUTPUT: + RETVAL + +void +window_item_change_server(item, server) + Irssi::Windowitem item + Irssi::Server server + +int +window_item_is_active(item) + Irssi::Windowitem item + +void +window_item_set_active(item) + Irssi::Windowitem item +CODE: + window_item_set_active(window_item_window(item), item); diff --git a/src/perl/ui/module.h b/src/perl/ui/module.h new file mode 100644 index 00000000..31775039 --- /dev/null +++ b/src/perl/ui/module.h @@ -0,0 +1,14 @@ +#include "../common/module.h" + +#include "fe-windows.h" +#include "fe-exec.h" +#include "formats.h" +#include "printtext.h" +#include "window-items.h" +#include "themes.h" +#include "keyboard.h" + +typedef WINDOW_REC *Irssi__UI__Window; +typedef TEXT_DEST_REC *Irssi__UI__TextDest; +typedef THEME_REC *Irssi__UI__Theme; +typedef KEYINFO_REC *Irssi__UI__Keyinfo; diff --git a/src/perl/ui/typemap b/src/perl/ui/typemap new file mode 100644 index 00000000..ee156e5c --- /dev/null +++ b/src/perl/ui/typemap @@ -0,0 +1,16 @@ +TYPEMAP +Irssi::UI::Theme T_PlainObj +Irssi::UI::Window T_PlainObj +Irssi::UI::Keyinfo T_PlainObj +Irssi::UI::TextDest T_PlainObj + +INPUT + +T_PlainObj + $var = irssi_ref_object($arg) + +OUTPUT + +T_PlainObj + $arg = irssi_bless_plain(\"$type\", $var); + |