From 4a6ceffb98a0b785494f680d3776c4bfc4052f9e Mon Sep 17 00:00:00 2001 From: "berkeviktor@aol.com" Date: Thu, 24 Feb 2011 04:14:30 +0100 Subject: add xchat r1489 --- plugins/perl/Makefile.am | 20 + plugins/perl/alt_completion.pl | 507 +++++ plugins/perl/char_count.pl | 101 + plugins/perl/generate_header | 50 + plugins/perl/generate_html | 27 + plugins/perl/lib/IRC.pm | 257 +++ plugins/perl/lib/Pod/Html.pm | 2399 +++++++++++++++++++++++ plugins/perl/lib/Xchat.pm | 506 +++++ plugins/perl/lib/Xchat.pod | 1326 +++++++++++++ plugins/perl/lib/Xchat/Embed.pm | 253 +++ plugins/perl/lib/Xchat/List/Network.pm | 32 + plugins/perl/lib/Xchat/List/Network/AutoJoin.pm | 82 + plugins/perl/lib/Xchat/List/Network/Entry.pm | 105 + plugins/perl/perl.c | 1522 ++++++++++++++ plugins/perl/perl.def | 4 + plugins/perl/syntax_highlight | 69 + plugins/perl/xchat2-perl.html | 1166 +++++++++++ plugins/perl/xchat2-perldocs.html | 475 +++++ plugins/perl/xcperl_build.bat | 43 + 19 files changed, 8944 insertions(+) create mode 100644 plugins/perl/Makefile.am create mode 100644 plugins/perl/alt_completion.pl create mode 100644 plugins/perl/char_count.pl create mode 100644 plugins/perl/generate_header create mode 100644 plugins/perl/generate_html create mode 100644 plugins/perl/lib/IRC.pm create mode 100644 plugins/perl/lib/Pod/Html.pm create mode 100644 plugins/perl/lib/Xchat.pm create mode 100644 plugins/perl/lib/Xchat.pod create mode 100644 plugins/perl/lib/Xchat/Embed.pm create mode 100644 plugins/perl/lib/Xchat/List/Network.pm create mode 100644 plugins/perl/lib/Xchat/List/Network/AutoJoin.pm create mode 100644 plugins/perl/lib/Xchat/List/Network/Entry.pm create mode 100644 plugins/perl/perl.c create mode 100644 plugins/perl/perl.def create mode 100644 plugins/perl/syntax_highlight create mode 100644 plugins/perl/xchat2-perl.html create mode 100644 plugins/perl/xchat2-perldocs.html create mode 100644 plugins/perl/xcperl_build.bat (limited to 'plugins/perl') diff --git a/plugins/perl/Makefile.am b/plugins/perl/Makefile.am new file mode 100644 index 00000000..816ae67c --- /dev/null +++ b/plugins/perl/Makefile.am @@ -0,0 +1,20 @@ + +EXTRA_DIST=alt_completion.pl xchat2-perldocs.html xchat2-perl.html \ + generate_header lib/Xchat.pm lib/Xchat/Embed.pm lib/Xchat/List/Network.pm \ + lib/Xchat/List/Network/Entry.pm lib/Xchat/List/Network/AutoJoin.pm \ + lib/IRC.pm + +libdir = $(xchatlibdir)/plugins + +lib_LTLIBRARIES = perl.la +perl_la_SOURCES = perl.c +perl_la_LDFLAGS = -avoid-version -module +perl_la_LIBADD = $(PERL_LDFLAGS) +BUILT_SOURCES = xchat.pm.h irc.pm.h +#CFLAGS = @CFLAGS@ -Wno-unused +INCLUDES = $(PERL_CFLAGS) $(COMMON_CFLAGS) -I$(srcdir)/.. +CLEANFILES = xchat.pm.h irc.pm.h +xchat.pm.h irc.pm.h: lib/Xchat.pm lib/Xchat/Embed.pm \ + lib/Xchat/List/Network.pm lib/Xchat/List/Network/Entry.pm \ + lib/Xchat/List/Network/AutoJoin.pm lib/IRC.pm + perl generate_header diff --git a/plugins/perl/alt_completion.pl b/plugins/perl/alt_completion.pl new file mode 100644 index 00000000..2572fb81 --- /dev/null +++ b/plugins/perl/alt_completion.pl @@ -0,0 +1,507 @@ +use strict; +use warnings; +use Xchat (); +use File::Spec (); +use File::Basename qw(fileparse); + +# if the last time you addressed someone was greater than this many minutes +# ago, ignore it +# this avoids having people you have talked to a long time ago coming up too +# early in the completion list +# Setting this to 0 will disable the check which is effectively the same as +# setting it to infinity +my $last_use_threshold = 10; # 10 minutes + +# added to the front of a completion the same way as a suffix, only if +# the word is at the beginning of the line +my $prefix = ''; + +# ignore leading non-alphanumeric characters: -[\]^_`{|} +# Assuming you have the following nicks in a channel: +# [SomeNick] _SomeNick_ `SomeNick SomeNick SomeOtherNick +# when $ignore_leading_non_alnum is set to 0 +# s will cycle through SomeNick and SomeOtherNick +# when $ignore_leading_non_alnum is set to 1 +# s will cycle through [SomeNick] _SomeNick_ `SomeNick SomeNick +# SomeOtherNick +my $ignore_leading_non_alnum = 0; + +# enable path completion +my $path_completion = 1; +my $base_path = ''; + +Xchat::register( + "Tab Completion", "1.0401", "Alternative tab completion behavior" +); +Xchat::hook_print( "Key Press", \&complete ); +Xchat::hook_print( "Close Context", \&close_context ); +Xchat::hook_print( "Focus Tab", \&focus_tab ); +Xchat::hook_print( "Part", \&clean_selected ); +Xchat::hook_print( "Part with Reason", \&clean_selected ); +Xchat::hook_command( "", \&track_selected ); + +sub SHIFT() { 1 } +sub CTRL() { 4 } +sub ALT() { 8 } + +sub TAB() { 0xFF09 } +sub LEFT_TAB() { 0xFE20 } + +my %completions; +my %last_visit; +my %selected; +my %escape_map = ( + '[' => qr![\[{]!, + '{' => qr![\[{]!, + '}' => qr![\]}]!, + ']' => qr![\]}]!, + '\\' => qr![\\\|]!, + '|' => qr![\\\|]!, + '.' => qr!\.!, + '^' => qr!\^!, + '$' => qr!\$!, + '*' => qr!\*!, + '+' => qr!\+!, + '?' => qr!\?!, + '(' => qr!\(!, + ')' => qr!\)!, + '-' => qr!\-!, +); + +my $escapes = join "", keys %escape_map; +$escapes = qr/[\Q$escapes\E]/; + +# used to determine if a word is the start of a path +my $path_pattern = qr{^(?:~|/|[[:alpha:]]:\\)}; + +sub complete { + my ($key, $modifiers) = @{$_[0]}; + # if $_[0][0] contains the value of the key pressed + # $_[0][1] contains modifiers + # the value for tab is 0xFF09 + # the value for shift-tab(Left Tab) is 0xFE20 + # we don't care about other keys + + # the key must be a tab and left tab + return Xchat::EAT_NONE unless $key == TAB || $key == LEFT_TAB; + + # if it is a tab then it must not have any modifiers + return Xchat::EAT_NONE if $key == TAB && $modifiers & (CTRL|ALT|SHIFT); + + # loop backwards for shift+tab/left tab + my $delta = $modifiers & SHIFT ? -1 : 1; + my $context = Xchat::get_context; + $completions{$context} ||= {}; + + my $completions = $completions{$context}; + $completions->{pos} ||= -1; + + my $suffix = Xchat::get_prefs( "completion_suffix" ); + $suffix =~ s/^\s+//; + + my $input = Xchat::get_info( "inputbox" ); + my $cursor_pos = Xchat::get_info( "state_cursor" ); + my $left = substr( $input, 0, $cursor_pos ); + my $right = substr( $input, $cursor_pos ); + my $length = length $left; + + # trim spaces from the end of $left to avoid grabbing the wrong word + # this is mainly needed for completion at the very beginning where a space + # is added after the completion + $left =~ s/\s+$//; + + # always add one to the index because + # 1) if a space is found we want the position after it + # 2) if a space isn't found then we get back -1 + my $word_start = rindex( $left, " " ) + 1; + my $word = substr( $left, $word_start ); + $left = substr( $left, 0, -length $word ); + + if( $cursor_pos == $completions->{pos} ) { + my $previous_word = $completions->{completed}; + my $new_left = $input; + substr( $new_left, $cursor_pos ) = ""; + + if( $previous_word and $new_left =~ s/(\Q$previous_word\E)$// ) { + $word = $1; + $word_start = length( $new_left ); + $left = $new_left; + } + } + + my $command_char = Xchat::get_prefs( "input_command_char" ); + # ignore commands + if( ($word !~ m{^[${command_char}]}) + or ( $word =~ m{^[${command_char}]} and $word_start != 0 ) ) { + + if( $cursor_pos == length $input # end of input box + # not a valid nick char + && $input =~ /(?{pos} # not continuing a completion + && $word !~ m{^(?:[&#/~]|[[:alpha:]]:\\)} # not a channel or path + ) { + # check for path completion + unless( $path_completion and $word =~ $path_pattern ) { + $word_start = $cursor_pos; + $left = $input; + $length = length $length; + $right = ""; + $word = ""; + } + } + + if( $word_start == 0 && $prefix && $word =~ /^\Q$prefix/ ) { + $word =~ s/^\Q$prefix//; + } + + my $completed; # this is going to be the "completed" word + + # for parital completions and channel names so a : isn't added + #$completions->{skip_suffix} = ($word =~ /^[&#]/) ? 1 : 0; + + # continuing from a previous completion + if( + exists $completions->{matches} && @{$completions->{matches}} + && $cursor_pos == $completions->{pos} + && $word =~ /^\Q$completions->{matches}[$completions->{index}]/ + ) { + $completions->{index} += $delta; + + if( $completions->{index} < 0 ) { + $completions->{index} += @{$completions->{matches}}; + } else { + $completions->{index} %= @{$completions->{matches}}; + } + + } else { + + if( $word =~ /^[&#]/ ) { + # channel name completion + $completions->{matches} = [ matching_channels( $word ) ]; + $completions->{skip_suffix} = 0; + } elsif( $path_completion and $word =~ $path_pattern ) { + # file name completion + $completions->{matches} = [ matching_files( $word ) ]; + $completions->{skip_suffix} = 1; + } else { + # nick completion + # fix $word so { equals [, ] equals }, \ equals | + # and escape regex metacharacters + $word =~ s/($escapes)/$escape_map{$1}/g; + + $completions->{matches} = [ matching_nicks( $word ) ]; + $completions->{skip_suffix} = 0; + } + $completions->{index} = 0; + + } + $completed = $completions->{matches}[ $completions->{index} ]; + $completions->{completed} = $completed; + + my $completion_amount = Xchat::get_prefs( "completion_amount" ); + + # don't cycle if the number of possible completions is greater than + # completion_amount + if( + @{$completions->{matches}} > $completion_amount + && @{$completions->{matches}} != 1 + ) { + # don't print if we tabbed in the beginning and the list of possible + # completions includes all nicks in the channel + my $context_type = Xchat::context_info->{type}; + if( $context_type != 2 # not a channel + or @{$completions->{matches}} < Xchat::get_list("users") + ) { + Xchat::print( join " ", @{$completions->{matches}}, "\n" ); + } + + $completed = lcs( $completions->{matches} ); + $completions->{skip_suffix} = 1; + } + + if( $completed ) { + + if( $word_start == 0 && !$completions->{skip_suffix} ) { + # at the start of the line append completion suffix + Xchat::command( "settext $prefix$completed$suffix$right"); + $completions->{pos} = length( "$prefix$completed$suffix" ); + } else { + Xchat::command( "settext $left$completed$right" ); + $completions->{pos} = length( "$left$completed" ); + } + + Xchat::command( "setcursor $completions->{pos}" ); + } + +=begin +# debugging stuff + local $, = " "; + my $input_length = length $input; + Xchat::print [ + qq{input[$input]}, + qq{input_length[$input_length]}, + qq{cursor[$cursor_pos]}, + qq{start[$word_start]}, + qq{length[$length]}, + qq{left[$left]}, + qq{word[$word]}, qq{right[$right]}, + qq{completed[}. ($completed||""). qq{]}, + qq{pos[$completions->{pos}]}, + ]; + use Data::Dumper; + local $Data::Dumper::Indent = 0; + Xchat::print Dumper $completions->{matches}; +=cut + + return Xchat::EAT_ALL; + } else { + return Xchat::EAT_NONE; + } +} + + +# all channels starting with $word +sub matching_channels { + my $word = shift; + + # for use in compare_channels(); + our $current_chan; + local $current_chan = Xchat::get_info( "channel" ); + + my $conn_id = Xchat::get_info( "id" ); + $word =~ s/^[&#]+//; + + return + map { $_->[1]->{channel} } + sort compare_channels map { + my $chan = $_->{channel}; + $chan =~ s/^[#&]+//; + + # comparisons will be done based only on the name + # matching name, same connection, only channels + $chan =~ /^$word/i && $_->{id} == $conn_id ? + [ $chan, $_ ] : + () + } channels(); +} + +sub channels { + return grep { $_->{type} == 2 } Xchat::get_list( "channels" ); +} + +sub compare_channels { + # package variable, value set in matching_channels() + our $current_chan; + + # turn off warnings generated from channels that have not yet been visited + # since the script was loaded + no warnings "uninitialized"; + + # the current channel is always first, then ordered by most recently visited + return + $a->[1]{channel} eq $current_chan ? -1 : + $b->[1]{channel} eq $current_chan ? 1 : + $last_visit{ $b->[1]{context} } <=> $last_visit{ $a->[1]{context} } + || $a->[1]{channel} cmp $b->[1]{channel}; + +} + +sub matching_nicks { + my $word_re = shift; + + # for use in compare_nicks() + our ($my_nick, $selections, $now); + local $my_nick = Xchat::get_info( "nick" ); + local $selections = $selected{ Xchat::get_context() }; + local $now = time; + + my $pattern = $ignore_leading_non_alnum ? + qr/^[\-\[\]^_`{|}\\]*$word_re/i : qr/^$word_re/i; + return + map { $_->{nick} } + sort compare_nicks grep { + $_->{nick} =~ $pattern; + } Xchat::get_list( "users" ) + +} + +sub max { + return unless @_; + my $max = shift; + for(@_) { + $max = $_ if $_ > $max; + } + return $max; +} + +sub compare_times { + # package variables set in matching_nicks() + our $selections; + our $now; + + for my $nick ( $a->{nick}, $b->{nick} ) { + # turn off the warnings that get generated from users who have yet + # to speak since the script was loaded + no warnings "uninitialized"; + + if( $last_use_threshold + && (( $now - $selections->{$nick}) > ($last_use_threshold * 60)) ) { + delete $selections->{ $nick } + } + } + my $a_time = $selections->{ $a->{nick} } || 0 ; + my $b_time = $selections->{ $b->{nick} } || 0 ; + + if( $a_time || $b_time ) { + return $b_time <=> $a_time; + } elsif( !$a_time && !$b_time ) { + return $b->{lasttalk} <=> $a->{lasttalk}; + } + +} + +sub compare_nicks { + # more package variables, value set in matching_nicks() + our $my_nick; + + # our own nick is always last, then ordered by the people we spoke to most + # recently and the people who were speaking most recently + return + $a->{nick} eq $my_nick ? 1 : + $b->{nick} eq $my_nick ? -1 : + compare_times() + || Xchat::nickcmp( $a->{nick}, $b->{nick} ); + +# $selections->{ $b->{nick} } <=> $selections->{ $a->{nick} } +# || $b->{lasttalk} <=> $a->{lasttalk} + +} + +sub matching_files { + my $word = shift; + + my ($file, $input_dir) = fileparse( $word ); + + my $dir = expand_tilde( $input_dir ); + + if( opendir my $dir_handle, $dir ) { + my @files; + + if( $file ) { + @files = grep { + #Xchat::print( $_ ); + /^\Q$file/ } readdir $dir_handle; + } else { + @files = readdir $dir_handle; + } + + return map { + File::Spec->catfile( $input_dir, $_ ); + } sort + grep { !/^[.]{1,2}$/ } @files; + } else { + return (); + } +} + +# Remove completion related data for tabs that are closed +sub close_context { + my $context = Xchat::get_context; + delete $completions{$context}; + delete $last_visit{$context}; + return Xchat::EAT_NONE; +} + +# track visit times +sub focus_tab { + $last_visit{Xchat::get_context()} = time(); + return Xchat::EAT_NONE; +} + +# keep track of the last time a message was addressed to someone +# a message is considered addressed to someone if their nick is used followed +# by the completion suffix +sub track_selected { + my $input = $_[1][0]; + return Xchat::EAT_NONE unless defined $input; + + my $suffix = Xchat::get_prefs( "completion_suffix" ); + for( grep defined, $input =~ /^(.+)\Q$suffix/, $_[0][0] ) { + if( in_channel( $_ ) ) { + $selected{Xchat::get_context()}{$_} = time(); + last; + } + } + + return Xchat::EAT_NONE; +} + +# if a user is in the current channel +# user_info() can also be used instead of the loop +sub in_channel { + my $target = shift; + for my $nick ( nicks() ) { + if( $nick eq $target ) { + return 1; + } + } + + return 0; +} + +# list of nicks in the current channel +sub nicks { + return map { $_->{nick} } Xchat::get_list( "users" ); +} + +# remove people from the selected list when they leave the channel +sub clean_selected { + delete $selected{ Xchat::get_context() }{$_[0][0]}; + return Xchat::EAT_NONE; +} + +# Longest common substring +# Used for partial completion when using non-cycling completion +sub lcs { + my @nicks = @{+shift}; + return "" if @nicks == 0; + return $nicks[0] if @nicks == 1; + + my $substring = shift @nicks; + + while(@nicks) { + $substring = common_string( $substring, shift @nicks ); + } + + return $substring; +} + +sub common_string { + my ($nick1, $nick2) = @_; + my $index = 0; + + $index++ while( + ($index < length $nick1) && ($index < length $nick2) && + lc(substr( $nick1, $index, 1 )) eq lc(substr( $nick2, $index, 1 )) + ); + + + return substr( $nick1, 0, $index ); +} + +sub expand_tilde { + my $file = shift; + + $file =~ s/^~/home_dir()/e; + return $file; +} + +sub home_dir { + return $base_path if $base_path; + + if ( $^O eq "MSWin32" ) { + return $ENV{USERPROFILE}; + } else { + return ((getpwuid($>))[7] || $ENV{HOME} || $ENV{LOGDIR}); + } +} diff --git a/plugins/perl/char_count.pl b/plugins/perl/char_count.pl new file mode 100644 index 00000000..418046f4 --- /dev/null +++ b/plugins/perl/char_count.pl @@ -0,0 +1,101 @@ + +use strict; +use warnings; +use Xchat qw(:all); +use Glib qw(TRUE FALSE); +use Gtk2 -init; + +sub get_inputbox { + my $widget = Glib::Object->new_from_pointer( get_info( "win_ptr" ), 0 ); + my $input_box; + + my @containers = ($widget); + + while( @containers ) { + my $container = shift @containers; + + for my $child ( $container->get_children ) { + if( $child->get( "name" ) eq 'xchat-inputbox' ) { + $input_box = $child; + last; + } elsif( $child->isa( "Gtk2::Container" ) ) { + push @containers, $child; + } + } + } + return $input_box; +} + +sub get_hbox { + my $widget = shift; + my $hbox; + + while( $widget->parent ) { + if( $widget->parent->isa( "Gtk2::HBox" ) ) { + return $widget->parent; + } + $widget = $widget->parent; + } + +} + +my $input_box = get_inputbox(); + +if( $input_box ) { + my $hbox = get_hbox( $input_box ); + if( $hbox ) { + my $label = Gtk2::Label->new(); + $label->set_alignment( 0.5, ($label->get_alignment)[1] ); + $hbox->pack_end( $label, 0, 0, 5 ); + $label->show(); + + my $update_label = sub { + my $ctx_type = context_info->{"type"}; + hook_timer( 0, sub { + if( $ctx_type == 2 || $ctx_type == 3 ) { + my $count = length get_info "inputbox"; + $label->set_text( $count ? $count : "" ); + } else { + $label->set_text( "" ); + } + return REMOVE; + }); + return EAT_NONE; + }; + + hook_print( "Key Press", $update_label ); + hook_print( "Focus Tab", $update_label ); + hook_print( "Focus Window", $update_label ); + hook_command( "", + sub { + $label->set_text( "" ); + return EAT_NONE; + } + ); + + my @handlers; + my $buffer = $input_box->get_buffer; + my $handler = sub { $update_label->(); return TRUE }; + + if( $buffer->isa( "Gtk2::TextBuffer" ) ) { + push @handlers, $buffer->signal_connect( "changed", $handler ); + } elsif( $buffer->isa( "Gtk2::EntryBuffer" ) ) { + push @handlers, + $buffer->signal_connect( "deleted-text", $handler ); + $buffer->signal_connect( "inserted-text", $handler ); + } + + register( "Character Counter", "1.0.0", + "Display the number of characters in the inputbox", + sub { + $hbox->remove( $label ); + $buffer->signal_handler_disconnect( $_ ) for @handlers; + } + ); + } else { + prnt "Counldn't find hbox"; + } + +} else { + prnt "Couldn't fint input box"; +} diff --git a/plugins/perl/generate_header b/plugins/perl/generate_header new file mode 100644 index 00000000..d6c8a65f --- /dev/null +++ b/plugins/perl/generate_header @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +sub header { + my $file = shift; + open my $input, "<", $file or die "Couldn't open '$file':$!"; + my @file = <$input>; + close $file; + return toc(@file); +} + +sub toc { + my @lines = @_; + for( @lines ) { + if( /^\s*$/s ) { $_ = qq{"\\n"\n}; next; } + if( /^\s*#/ ) { $_ = qq{"\\n"\n}; next; } + s/\\/\\\\/g; # double the number of \'s + s/"/\\"/g; + s/^\s*/"/; + s/\n/\\n"\n/; + } + return @lines; +} + +for my $files ( + [ "xchat.pm.h", # output file + "lib/Xchat.pm", # input files + "lib/Xchat/Embed.pm", + "lib/Xchat/List/Network.pm", + "lib/Xchat/List/Network/Entry.pm", + "lib/Xchat/List/Network/AutoJoin.pm", + ], + [ "irc.pm.h", # output file + "lib/IRC.pm" # input file + ] +) { + my ($output,@inputs) = @$files; + + open my $header, ">", $output or die "Couldn't open '$output': $!"; + + for my $input ( @inputs ) { + print $header qq["{\\n"\n]; + print $header qq{"#line 1 \\"$input\\"\\n"\n}; + print $header header( $input ); + print $header qq["}\\n"\n]; + } + close $header; +} diff --git a/plugins/perl/generate_html b/plugins/perl/generate_html new file mode 100644 index 00000000..c144ce7e --- /dev/null +++ b/plugins/perl/generate_html @@ -0,0 +1,27 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use File::Basename qw(dirname); + +sub __DIR__ { + return dirname +(caller 0)[1]; +} + +# this must go before use Pod::Html to use our private copy +use lib __DIR__ . '/lib'; +use Pod::Html; + +chdir( __DIR__ ) or die $!; +pod2html( +# "pod2html", + "--header", + "--infile=lib/Xchat.pod", + "--outfile=xchat2-perl.html", +); + +#system( qw(tidy -m -i -xml -utf8 -quiet xchat2-perl.html) ); +unlink( "pod2htmd.tmp" ); +unlink( "pod2htmi.tmp" ); + +exec( "./syntax_highlight", "xchat2-perl.html" ) + or die $!; diff --git a/plugins/perl/lib/IRC.pm b/plugins/perl/lib/IRC.pm new file mode 100644 index 00000000..c22a8e73 --- /dev/null +++ b/plugins/perl/lib/IRC.pm @@ -0,0 +1,257 @@ + +package IRC; +sub IRC::register { + my ($script_name, $version, $callback) = @_; + my $package = caller; + $callback = Xchat::Embed::fix_callback( $package, $callback) if $callback; + Xchat::register( $script_name, $version, undef, $callback ); +} + + +sub IRC::add_command_handler { + my ($command, $callback) = @_; + my $package = caller; + + $callback = Xchat::Embed::fix_callback( $package, $callback ); + + # starting index for word_eol array + # this is for compatibility with '' as the command + my $start_index = $command ? 1 : 0; + + Xchat::hook_command( $command, + sub { + no strict 'refs'; + return &{$callback}($_[1][$start_index]); + } + ); + return; +} + +sub IRC::add_message_handler { + my ($message, $callback) = @_; + my $package = caller; + $callback = Xchat::Embed::fix_callback( $package, $callback ); + + Xchat::hook_server( $message, + sub { + no strict 'refs'; + return &{$callback}( $_[1][0] ); + } + ); + return; +} + +sub IRC::add_print_handler { + my ($event, $callback) = @_; + my $package = caller; + $callback = Xchat::Embed::fix_callback( $package, $callback ); + Xchat::hook_print( $event, + sub { + my @word = @{$_[0]}; + no strict 'refs'; + return &{$callback}( join( ' ', @word[0..3] ), @word ); + } + ); + return; +} + +sub IRC::add_timeout_handler { + my ($timeout, $callback) = @_; + my $package = caller; + $callback = Xchat::Embed::fix_callback( $package, $callback ); + Xchat::hook_timer( $timeout, + sub { + no strict 'refs'; + &{$callback}; + return 0; + } + ); + return; +} + +sub IRC::command { + my $command = shift; + if( $command =~ m{^/} ) { + $command =~ s{^/}{}; + Xchat::command( $command ); + } else { + Xchat::command( qq[say $command] ); + } +} + +sub IRC::command_with_channel { + my ($command, $channel, $server) = @_; + my $old_ctx = Xchat::get_context; + my $ctx = Xchat::find_context( $channel, $server ); + + if( $ctx ) { + Xchat::set_context( $ctx ); + IRC::command( $command ); + Xchat::set_context( $ctx ); + } +} + +sub IRC::command_with_server { + my ($command, $server) = @_; + my $old_ctx = Xchat::get_context; + my $ctx = Xchat::find_context( undef, $server ); + + if( $ctx ) { + Xchat::set_context( $ctx ); + IRC::command( $command ); + Xchat::set_context( $ctx ); + } +} + +sub IRC::dcc_list { + my @dccs; + for my $dcc ( Xchat::get_list( 'dcc' ) ) { + push @dccs, $dcc->{nick}; + push @dccs, $dcc->{file} ? $dcc->{file} : ''; + push @dccs, @{$dcc}{qw(type status cps size)}; + push @dccs, $dcc->{type} == 0 ? $dcc->{pos} : $dcc->{resume}; + push @dccs, $dcc->{address32}; + push @dccs, $dcc->{destfile} ? $dcc->{destfile} : ''; + } + return @dccs; +} + +sub IRC::channel_list { + my @channels; + for my $channel ( Xchat::get_list( 'channels' ) ) { + push @channels, @{$channel}{qw(channel server)}, + Xchat::context_info( $channel->{context} )->{nick}; + } + return @channels; +} + +sub IRC::get_info { + my $id = shift; + my @ids = qw(version nick channel server xchatdir away network host topic); + + if( $id >= 0 && $id <= 8 && $id != 5 ) { + my $info = Xchat::get_info($ids[$id]); + return defined $info ? $info : ''; + } else { + if( $id == 5 ) { + return Xchat::get_info( 'away' ) ? 1 : 0; + } else { + return 'Error2'; + } + } +} + +sub IRC::get_prefs { + return 'Unknown variable' unless defined $_[0]; + my $result = Xchat::get_prefs(shift); + return defined $result ? $result : 'Unknown variable'; +} + +sub IRC::ignore_list { + my @ignores; + for my $ignore ( Xchat::get_list( 'ignore' ) ) { + push @ignores, $ignore->{mask}; + my $flags = $ignore->{flags}; + push @ignores, $flags & 1, $flags & 2, $flags & 4, $flags & 8, $flags & 16, + $flags & 32, ':'; + } + return @ignores; +} + +sub IRC::print { + Xchat::print( $_ ) for @_; + return; +} + +sub IRC::print_with_channel { + Xchat::print( @_ ); +} + +sub IRC::send_raw { + Xchat::commandf( qq[quote %s], shift ); +} + +sub IRC::server_list { + my @servers; + for my $channel ( Xchat::get_list( 'channels' ) ) { + push @servers, $channel->{server} if $channel->{server}; + } + return @servers; +} + +sub IRC::user_info { + my $user; + if( @_ > 0 ) { + $user = Xchat::user_info( shift ); + } else { + $user = Xchat::user_info(); + } + + my @info; + if( $user ) { + push @info, $user->{nick}; + if( $user->{host} ) { + push @info, $user->{host}; + } else { + push @info, 'FETCHING'; + } + push @info, $user->{prefix} eq '@' ? 1 : 0; + push @info, $user->{prefix} eq '+' ? 1 : 0; + } + return @info; +} + +sub IRC::user_list { + my ($channel, $server) = @_; + my $ctx = Xchat::find_context( $channel, $server ); + my $old_ctx = Xchat::get_context; + + if( $ctx ) { + Xchat::set_context( $ctx ); + my @users; + for my $user ( Xchat::get_list( 'users' ) ) { + push @users, $user->{nick}; + if( $user->{host} ) { + push @users, $user->{host}; + } else { + push @users, 'FETCHING'; + } + push @users, $user->{prefix} eq '@' ? 1 : 0; + push @users, $user->{prefix} eq '+' ? 1 : 0; + push @users, ':'; + } + Xchat::set_context( $old_ctx ); + return @users; + } else { + return; + } +} + +sub IRC::user_list_short { + my ($channel, $server) = @_; + my $ctx = Xchat::find_context( $channel, $server ); + my $old_ctx = Xchat::get_context; + + if( $ctx ) { + Xchat::set_context( $ctx ); + my @users; + for my $user ( Xchat::get_list( 'users' ) ) { + my $nick = $user->{nick}; + my $host = $user->{host} || 'FETCHING'; + push @users, $nick, $host; + } + Xchat::set_context( $old_ctx ); + return @users; + } else { + return; + } + +} + +sub IRC::add_user_list {} +sub IRC::sub_user_list {} +sub IRC::clear_user_list {} +sub IRC::notify_list {} +sub IRC::perl_script_list {} + +1 diff --git a/plugins/perl/lib/Pod/Html.pm b/plugins/perl/lib/Pod/Html.pm new file mode 100644 index 00000000..3695564b --- /dev/null +++ b/plugins/perl/lib/Pod/Html.pm @@ -0,0 +1,2399 @@ +package Pod::Html; +use strict; +require Exporter; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); +$VERSION = 1.08; +@ISA = qw(Exporter); +@EXPORT = qw(pod2html htmlify); +@EXPORT_OK = qw(anchorify); + +use Carp; +use Config; +use Cwd; +use File::Spec; +use File::Spec::Unix; +use Getopt::Long; + +use locale; # make \w work right in non-ASCII lands + +=head1 NAME + +Pod::Html - module to convert pod files to HTML + +=head1 SYNOPSIS + + use Pod::Html; + pod2html([options]); + +=head1 DESCRIPTION + +Converts files from pod format (see L) to HTML format. It +can automatically generate indexes and cross-references, and it keeps +a cache of things it knows how to cross-reference. + +=head1 FUNCTIONS + +=head2 pod2html + + pod2html("pod2html", + "--podpath=lib:ext:pod:vms", + "--podroot=/usr/src/perl", + "--htmlroot=/perl/nmanual", + "--libpods=perlfunc:perlguts:perlvar:perlrun:perlop", + "--recurse", + "--infile=foo.pod", + "--outfile=/perl/nmanual/foo.html"); + +pod2html takes the following arguments: + +=over 4 + +=item backlink + + --backlink="Back to Top" + +Adds "Back to Top" links in front of every C heading (except for +the first). By default, no backlinks are generated. + +=item cachedir + + --cachedir=name + +Creates the item and directory caches in the given directory. + +=item css + + --css=stylesheet + +Specify the URL of a cascading style sheet. Also disables all HTML/CSS +C + + + +$block +END_OF_HEAD + + # load/reload/validate/cache %Pages and %Items + get_cache( $Dircache, $Itemcache, \@Podpath, $Podroot, $Recurse ); + + # scan the pod for =item directives + scan_items( \%Local_Items, "", @poddata ); + + # put an index at the top of the file. note, if $Doindex is 0 we + # still generate an index, but surround it with an html comment. + # that way some other program can extract it if desired. + $index =~ s/--+/-/g; + + my $hr = ( $Doindex and $index ) ? qq(
) : ""; + + unless ($Doindex) { + $index = qq(\n); + } + + print HTML << "END_OF_INDEX"; + + +
+

+$index +$hr +
+ + +END_OF_INDEX + + # now convert this file + my $after_item; # set to true after an =item + my $need_dd = 0; + warn "Converting input file $Podfile\n" if $Verbose; + foreach my $i ( 0 .. $#poddata ) { + $_ = $poddata[$i]; + $Paragraph = $i + 1; + if (/^(=.*)/s) { # is it a pod directive? + $Ignore = 0; + $after_item = 0; + $need_dd = 0; + $_ = $1; + if (/^=begin\s+(\S+)\s*(.*)/si) { # =begin + process_begin( $1, $2 ); + } elsif (/^=end\s+(\S+)\s*(.*)/si) { # =end + process_end( $1, $2 ); + } elsif (/^=cut/) { # =cut + process_cut(); + } elsif (/^=pod/) { # =pod + process_pod(); + } else { + next if @Begin_Stack && $Begin_Stack[-1] ne 'html'; + + if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading + process_head( $1, $2, $Doindex && $index ); + } elsif (/^=item\s*(.*\S)?/sm) { # =item text + $need_dd = process_item($1); + $after_item = 1; + } elsif (/^=over\s*(.*)/) { # =over N + process_over(); + } elsif (/^=back/) { # =back + process_back($need_dd); + } elsif (/^=for\s+(\S+)\s*(.*)/si) { # =for + process_for( $1, $2 ); + } else { + /^=(\S*)\s*/; + warn "$0: $Podfile: unknown pod directive '$1' in " + . "paragraph $Paragraph. ignoring.\n" + unless $Quiet; + } + } + $Top = 0; + } else { + next if $Ignore; + next if @Begin_Stack && $Begin_Stack[-1] ne 'html'; + print HTML and next if @Begin_Stack && $Begin_Stack[-1] eq 'html'; + print HTML "
\n" if $need_dd; + my $text = $_; + if ( $text =~ /\A\s+/ ) { + process_pre( \$text ); + print HTML "
\n$text
\n"; + + } else { + process_text( \$text ); + + # experimental: check for a paragraph where all lines + # have some ...\t...\t...\n pattern + if ( $text =~ /\t/ ) { + my @lines = split( "\n", $text ); + if ( @lines > 1 ) { + my $all = 2; + foreach my $line (@lines) { + if ( $line =~ /\S/ && $line !~ /\t/ ) { + $all--; + last if $all == 0; + } + } + if ( $all > 0 ) { + $text =~ s/\t+//g; + $text =~ s/^//gm; + $text = + '' + . $text + . '
'; + } + } + } + ## end of experimental + + if ($after_item) { + $After_Lpar = 1; + } + print HTML "

$text

\n"; + } + print HTML "
\n" if $need_dd; + $after_item = 0; + } + } + + # finish off any pending directives + finish_list(); + + # link to page index + print HTML "

$Backlink

\n" + if $Doindex + and $index + and $Backlink; + + print HTML < + + +END_OF_TAIL + + # close the html file + close(HTML); + + warn "Finished\n" if $Verbose; +} + +############################################################################## + +sub usage { + my $podfile = shift; + warn "$0: $podfile: @_\n" if @_; + die < --infile= --outfile= + --podpath=:...: --podroot= + --libpods=:...: --recurse --verbose --index + --netscape --norecurse --noindex --cachedir= + + --backlink - set text for "back to top" links (default: none). + --cachedir - directory for the item and directory cache files. + --css - stylesheet URL + --flush - flushes the item and directory caches. + --[no]header - produce block header/footer (default is no headers). + --help - prints this message. + --hiddendirs - search hidden directories in podpath + --htmldir - directory for resulting HTML files. + --htmlroot - http-server base directory from which all relative paths + in podpath stem (default is /). + --[no]index - generate an index at the top of the resulting html + (default behaviour). + --infile - filename for the pod to convert (input taken from stdin + by default). + --libpods - colon-separated list of pages to search for =item pod + directives in as targets of C<> and implicit links (empty + by default). note, these are not filenames, but rather + page names like those that appear in L<> links. + --outfile - filename for the resulting html file (output sent to + stdout by default). + --podpath - colon-separated list of directories containing library + pods (empty by default). + --podroot - filesystem base directory from which all relative paths + in podpath stem (default is .). + --[no]quiet - suppress some benign warning messages (default is off). + --[no]recurse - recurse on those subdirectories listed in podpath + (default behaviour). + --title - title that will appear in resulting html file. + --[no]verbose - self-explanatory (off by default). + --[no]netscape - deprecated, has no effect. for backwards compatibility only. + +END_OF_USAGE + +} + +sub parse_command_line { + my ( + $opt_backlink, $opt_cachedir, $opt_css, $opt_flush, + $opt_header, $opt_help, $opt_htmldir, $opt_htmlroot, + $opt_index, $opt_infile, $opt_libpods, $opt_netscape, + $opt_outfile, $opt_podpath, $opt_podroot, $opt_quiet, + $opt_recurse, $opt_title, $opt_verbose, $opt_hiddendirs + ); + + unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html}; + my $result = GetOptions( + 'backlink=s' => \$opt_backlink, + 'cachedir=s' => \$opt_cachedir, + 'css=s' => \$opt_css, + 'flush' => \$opt_flush, + 'header!' => \$opt_header, + 'help' => \$opt_help, + 'hiddendirs!' => \$opt_hiddendirs, + 'htmldir=s' => \$opt_htmldir, + 'htmlroot=s' => \$opt_htmlroot, + 'index!' => \$opt_index, + 'infile=s' => \$opt_infile, + 'libpods=s' => \$opt_libpods, + 'netscape!' => \$opt_netscape, + 'outfile=s' => \$opt_outfile, + 'podpath=s' => \$opt_podpath, + 'podroot=s' => \$opt_podroot, + 'quiet!' => \$opt_quiet, + 'recurse!' => \$opt_recurse, + 'title=s' => \$opt_title, + 'verbose!' => \$opt_verbose, + ); + usage( "-", "invalid parameters" ) if not $result; + + usage("-") if defined $opt_help; # see if the user asked for help + $opt_help = ""; # just to make -w shut-up. + + @Podpath = split( ":", $opt_podpath ) if defined $opt_podpath; + @Libpods = split( ":", $opt_libpods ) if defined $opt_libpods; + + $Backlink = $opt_backlink if defined $opt_backlink; + $Cachedir = $opt_cachedir if defined $opt_cachedir; + $Css = $opt_css if defined $opt_css; + $Header = $opt_header if defined $opt_header; + $Htmldir = $opt_htmldir if defined $opt_htmldir; + $Htmlroot = $opt_htmlroot if defined $opt_htmlroot; + $Doindex = $opt_index if defined $opt_index; + $Podfile = $opt_infile if defined $opt_infile; + $HiddenDirs = $opt_hiddendirs if defined $opt_hiddendirs; + $Htmlfile = $opt_outfile if defined $opt_outfile; + $Podroot = $opt_podroot if defined $opt_podroot; + $Quiet = $opt_quiet if defined $opt_quiet; + $Recurse = $opt_recurse if defined $opt_recurse; + $Title = $opt_title if defined $opt_title; + $Verbose = $opt_verbose if defined $opt_verbose; + + warn "Flushing item and directory caches\n" + if $opt_verbose && defined $opt_flush; + $Dircache = "$Cachedir/pod2htmd.tmp"; + $Itemcache = "$Cachedir/pod2htmi.tmp"; + if ( defined $opt_flush ) { + 1 while unlink( $Dircache, $Itemcache ); + } +} + +my $Saved_Cache_Key; + +sub get_cache { + my ( $dircache, $itemcache, $podpath, $podroot, $recurse ) = @_; + my @cache_key_args = @_; + + # A first-level cache: + # Don't bother reading the cache files if they still apply + # and haven't changed since we last read them. + + my $this_cache_key = cache_key(@cache_key_args); + + return if $Saved_Cache_Key and $this_cache_key eq $Saved_Cache_Key; + + # load the cache of %Pages and %Items if possible. $tests will be + # non-zero if successful. + my $tests = 0; + if ( -f $dircache && -f $itemcache ) { + warn "scanning for item cache\n" if $Verbose; + $tests = load_cache( $dircache, $itemcache, $podpath, $podroot ); + } + + # if we didn't succeed in loading the cache then we must (re)build + # %Pages and %Items. + if ( !$tests ) { + warn "scanning directories in pod-path\n" if $Verbose; + scan_podpath( $podroot, $recurse, 0 ); + } + $Saved_Cache_Key = cache_key(@cache_key_args); +} + +sub cache_key { + my ( $dircache, $itemcache, $podpath, $podroot, $recurse ) = @_; + return join( '!', + $dircache, $itemcache, $recurse, @$podpath, $podroot, stat($dircache), + stat($itemcache) ); +} + +# +# load_cache - tries to find if the caches stored in $dircache and $itemcache +# are valid caches of %Pages and %Items. if they are valid then it loads +# them and returns a non-zero value. +# +sub load_cache { + my ( $dircache, $itemcache, $podpath, $podroot ) = @_; + my ($tests); + local $_; + + $tests = 0; + + open( CACHE, "<$itemcache" ) + || die "$0: error opening $itemcache for reading: $!\n"; + $/ = "\n"; + + # is it the same podpath? + $_ = ; + chomp($_); + $tests++ if ( join( ":", @$podpath ) eq $_ ); + + # is it the same podroot? + $_ = ; + chomp($_); + $tests++ if ( $podroot eq $_ ); + + # load the cache if its good + if ( $tests != 2 ) { + close(CACHE); + return 0; + } + + warn "loading item cache\n" if $Verbose; + while () { + /(.*?) (.*)$/; + $Items{$1} = $2; + } + close(CACHE); + + warn "scanning for directory cache\n" if $Verbose; + open( CACHE, "<$dircache" ) + || die "$0: error opening $dircache for reading: $!\n"; + $/ = "\n"; + $tests = 0; + + # is it the same podpath? + $_ = ; + chomp($_); + $tests++ if ( join( ":", @$podpath ) eq $_ ); + + # is it the same podroot? + $_ = ; + chomp($_); + $tests++ if ( $podroot eq $_ ); + + # load the cache if its good + if ( $tests != 2 ) { + close(CACHE); + return 0; + } + + warn "loading directory cache\n" if $Verbose; + while () { + /(.*?) (.*)$/; + $Pages{$1} = $2; + } + + close(CACHE); + + return 1; +} + +# +# scan_podpath - scans the directories specified in @podpath for directories, +# .pod files, and .pm files. it also scans the pod files specified in +# @Libpods for =item directives. +# +sub scan_podpath { + my ( $podroot, $recurse, $append ) = @_; + my ( $pwd, $dir ); + my ( $libpod, $dirname, $pod, @files, @poddata ); + + unless ($append) { + %Items = (); + %Pages = (); + } + + # scan each directory listed in @Podpath + $pwd = getcwd(); + chdir($podroot) + || die "$0: error changing to directory $podroot: $!\n"; + foreach $dir (@Podpath) { + scan_dir( $dir, $recurse ); + } + + # scan the pods listed in @Libpods for =item directives + foreach $libpod (@Libpods) { + + # if the page isn't defined then we won't know where to find it + # on the system. + next unless defined $Pages{$libpod} && $Pages{$libpod}; + + # if there is a directory then use the .pod and .pm files within it. + # NOTE: Only finds the first so-named directory in the tree. + # if ($Pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) { + if ( $Pages{$libpod} =~ /([^:]*(?; + close(POD); + clean_data( \@poddata ); + + scan_items( \%Items, "$dirname/$pod", @poddata ); + } + + # use the names of files as =item directives too. +### Don't think this should be done this way - confuses issues.(WL) +### foreach $pod (@files) { +### $pod =~ /^(.*)(\.pod|\.pm)$/; +### $Items{$1} = "$dirname/$1.html" if $1; +### } + } elsif ( $Pages{$libpod} =~ /([^:]*\.pod):/ + || $Pages{$libpod} =~ /([^:]*\.pm):/ ) + { + + # scan the .pod or .pm file for =item directives + $pod = $1; + open( POD, "<$pod" ) + || die "$0: error opening $pod for input: $!\n"; + @poddata = ; + close(POD); + clean_data( \@poddata ); + + scan_items( \%Items, "$pod", @poddata ); + } else { + warn "$0: shouldn't be here (line " . __LINE__ . "\n" unless $Quiet; + } + } + @poddata = (); # clean-up a bit + + chdir($pwd) + || die "$0: error changing to directory $pwd: $!\n"; + + # cache the item list for later use + warn "caching items for later use\n" if $Verbose; + open( CACHE, ">$Itemcache" ) + || die "$0: error open $Itemcache for writing: $!\n"; + + print CACHE join( ":", @Podpath ) . "\n$podroot\n"; + foreach my $key ( keys %Items ) { + print CACHE "$key $Items{$key}\n"; + } + + close(CACHE); + + # cache the directory list for later use + warn "caching directories for later use\n" if $Verbose; + open( CACHE, ">$Dircache" ) + || die "$0: error open $Dircache for writing: $!\n"; + + print CACHE join( ":", @Podpath ) . "\n$podroot\n"; + foreach my $key ( keys %Pages ) { + print CACHE "$key $Pages{$key}\n"; + } + + close(CACHE); +} + +# +# scan_dir - scans the directory specified in $dir for subdirectories, .pod +# files, and .pm files. notes those that it finds. this information will +# be used later in order to figure out where the pages specified in L<> +# links are on the filesystem. +# +sub scan_dir { + my ( $dir, $recurse ) = @_; + my ( $t, @subdirs, @pods, $pod, $dirname, @dirs ); + local $_; + + @subdirs = (); + @pods = (); + + opendir( DIR, $dir ) + || die "$0: error opening directory $dir: $!\n"; + while ( defined( $_ = readdir(DIR) ) ) { + if ( -d "$dir/$_" + && $_ ne "." + && $_ ne ".." + && ( $HiddenDirs || !/^\./ ) ) + { # directory + $Pages{$_} = "" unless defined $Pages{$_}; + $Pages{$_} .= "$dir/$_:"; + push( @subdirs, $_ ); + } elsif (/\.pod\z/) { # .pod + s/\.pod\z//; + $Pages{$_} = "" unless defined $Pages{$_}; + $Pages{$_} .= "$dir/$_.pod:"; + push( @pods, "$dir/$_.pod" ); + } elsif (/\.html\z/) { # .html + s/\.html\z//; + $Pages{$_} = "" unless defined $Pages{$_}; + $Pages{$_} .= "$dir/$_.pod:"; + } elsif (/\.pm\z/) { # .pm + s/\.pm\z//; + $Pages{$_} = "" unless defined $Pages{$_}; + $Pages{$_} .= "$dir/$_.pm:"; + push( @pods, "$dir/$_.pm" ); + } elsif ( -T "$dir/$_" ) { # script(?) + local *F; + if ( open( F, "$dir/$_" ) ) { + my $line; + while ( defined( $line = ) ) { + if ( $line =~ /^=(?:pod|head1)/ ) { + $Pages{$_} = "" unless defined $Pages{$_}; + $Pages{$_} .= "$dir/$_.pod:"; + last; + } + } + close(F); + } + } + } + closedir(DIR); + + # recurse on the subdirectories if necessary + if ($recurse) { + foreach my $subdir (@subdirs) { + scan_dir( "$dir/$subdir", $recurse ); + } + } +} + +# +# scan_headings - scan a pod file for head[1-6] tags, note the tags, and +# build an index. +# +sub scan_headings { + my ( $sections, @data ) = @_; + my ( $tag, $which_head, $otitle, $listdepth, $index ); + + local $Ignore = 0; + + $listdepth = 0; + $index = ""; + + # scan for =head directives, note their name, and build an index + # pointing to each of them. + foreach my $line (@data) { + if ( $line =~ /^=(head)([1-6])\s+(.*)/ ) { + ( $tag, $which_head, $otitle ) = ( $1, $2, $3 ); + + my $title = depod($otitle); + my $name = anchorify($title); + $$sections{$name} = 1; + $title = process_text( \$otitle ); + + while ( $which_head != $listdepth ) { + if ( $which_head > $listdepth ) { + $index .= "\n" + . ( "\t" x ($listdepth) ) + . ( $listdepth > 0 ? qq{
  • \n} + . "\t"x($listdepth + 1): "" ) + . "
      "; + $listdepth++; + } elsif ( $which_head < $listdepth ) { + $listdepth--; + $index .= "\n" + . ( "\t" x $listdepth ) + . ( $listdepth > 0 ? "\t" : "" ) + . "
    " + . ( $listdepth >= 0 ? "\n" . ("\t"x$listdepth) + . "
  • " : "" ) + . "\n"; + } + } + + $index .= "\n" + . ( "\t" x $listdepth ) . "
  • " + . "" + . $title + . "
  • "; + } + } + + # finish off the lists + while ( $listdepth-- ) { + $index .= "\n" . ( "\t" x $listdepth ) + . ($listdepth > 0 ? "\t" : "") + ."\n" + . ($listdepth > 0 ? ("\t" x $listdepth) . "" : "" ); + } + + # get rid of bogus lists + $index =~ s,\t*
      \s*
    \n,,g; + + return $index; +} + +# +# scan_items - scans the pod specified by $pod for =item directives. we +# will use this information later on in resolving C<> links. +# +sub scan_items { + my ( $itemref, $pod, @poddata ) = @_; + my ( $i, $item ); + local $_; + + $pod =~ s/\.pod\z//; + $pod .= ".html" if $pod; + + foreach $i ( 0 .. $#poddata ) { + my $txt = depod( $poddata[$i] ); + + # figure out what kind of item it is. + # Build string for referencing this item. + if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet + next unless $1; + $item = $1; + } elsif ( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list + $item = $1; + } elsif ( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item + $item = $1; + } else { + next; + } + my $fid = fragment_id($item); + $$itemref{$fid} = "$pod" if $fid; + } +} + +# +# process_head - convert a pod head[1-6] tag and convert it to HTML format. +# +sub process_head { + my ( $tag, $heading, $hasindex ) = @_; + + # figure out the level of the =head + $tag =~ /head([1-6])/; + my $level = $1; + + if ($Listlevel) { + warn +"$0: $Podfile: unterminated list at =head in paragraph $Paragraph. ignoring.\n" + unless $Quiet; + while ($Listlevel) { + process_back(); + } + } + + print HTML "

    \n"; + if ( $level == 1 && !$Top ) { + print HTML "$Backlink\n" + if $hasindex and $Backlink; + print HTML "

    \n
    \n"; + } else { + print HTML "

    \n"; + } + + my $name = anchorify( depod($heading) ); + my $convert = process_text( \$heading ); + $convert =~ s{]+>}{}g; + print HTML "$convert\n"; +} + +# +# emit_item_tag - print an =item's text +# Note: The global $EmittedItem is used for inhibiting self-references. +# +my $EmittedItem; + +sub emit_item_tag($$$) { + my ( $otext, $text, $compact ) = @_; + my $item = fragment_id( depod($text), -generate ); + Carp::confess( "Undefined fragment '$text' (" + . depod($text) + . ") from fragment_id() in emit_item_tag() in $Podfile" ) + if !defined $item; + $EmittedItem = $item; + ### print STDERR "emit_item_tag=$item ($text)\n"; + + print HTML ''; + if ( $Items_Named{$item}++ ) { + print HTML process_text( \$otext ); + } else { + my $name = $item; + $name = anchorify($name); + print HTML +#qq{}, + process_text( \$otext ), + # '' + ; + } + print HTML "\n"; + undef($EmittedItem); +} + +sub emit_li { + my ($tag) = @_; + if ( $Items_Seen[$Listlevel]++ == 0 ) { + push( @Listend, "" ); + print HTML "<$tag>\n"; + } + my $emitted = $tag eq 'dl' ? 'dt' : 'li'; + print HTML "<$emitted>"; + return $emitted; +} + +# +# process_item - convert a pod item tag and convert it to HTML format. +# +sub process_item { + my ($otext) = @_; + my $need_dd = 0; # set to 1 if we need a
    after an item + + # lots of documents start a list without doing an =over. this is + # bad! but, the proper thing to do seems to be to just assume + # they did do an =over. so warn them once and then continue. + if ( $Listlevel == 0 ) { + warn +"$0: $Podfile: unexpected =item directive in paragraph $Paragraph. ignoring.\n" + unless $Quiet; + process_over(); + } + + # formatting: insert a paragraph if preceding item has >1 paragraph + if ($After_Lpar) { + print HTML $need_dd ? "\n" : "\n" if $After_Lpar; + $After_Lpar = 0; + } + + # remove formatting instructions from the text + my $text = depod($otext); + + my $emitted; # the tag actually emitted, used for closing + + # all the list variants: + if ( $text =~ /\A\*/ ) { # bullet + $emitted = emit_li('ul'); + if ( $text =~ /\A\*\s+(\S.*)\Z/s ) { # with additional text + my $tag = $1; + $otext =~ s/\A\*\s+//; + emit_item_tag( $otext, $tag, 1 ); + } + print HTML "" + } elsif ( $text =~ /\A\d+/ ) { # numbered list + $emitted = emit_li('ol'); + if ( $text =~ /\A(?>\d+\.?)\s*(\S.*)\Z/s ) { # with additional text + my $tag = $1; + $otext =~ s/\A\d+\.?\s*//; + emit_item_tag( $otext, $tag, 1 ); + } + print HTML ""; + } else { # definition list + $emitted = emit_li('dl'); + if ( $text =~ /\A(.+)\Z/s ) { # should have text + emit_item_tag( $otext, $text, 1 ); + } + $need_dd = 1; + } + print HTML "\n"; + return $need_dd; +} + +# +# process_over - process a pod over tag and start a corresponding HTML list. +# +sub process_over { + + # start a new list + $Listlevel++; + push( @Items_Seen, 0 ); + $After_Lpar = 0; +} + +# +# process_back - process a pod back tag and convert it to HTML format. +# +sub process_back { + my $need_dd = shift; + if ( $Listlevel == 0 ) { + warn +"$0: $Podfile: unexpected =back directive in paragraph $Paragraph. ignoring.\n" + unless $Quiet; + return; + } + + # close off the list. note, I check to see if $Listend[$Listlevel] is + # defined because an =item directive may have never appeared and thus + # $Listend[$Listlevel] may have never been initialized. + $Listlevel--; + if ( defined $Listend[$Listlevel] ) { + print HTML $need_dd ? "\n" : "\n" if $After_Lpar; + print HTML $Listend[$Listlevel]; + print HTML "\n"; + pop(@Listend); + } + $After_Lpar = 0; + + # clean up item count + pop(@Items_Seen); +} + +# +# process_cut - process a pod cut tag, thus start ignoring pod directives. +# +sub process_cut { + $Ignore = 1; +} + +# +# process_pod - process a pod tag, thus stop ignoring pod directives +# until we see a corresponding cut. +# +sub process_pod { + + # no need to set $Ignore to 0 cause the main loop did it +} + +# +# process_for - process a =for pod tag. if it's for html, spit +# it out verbatim, if illustration, center it, otherwise ignore it. +# +sub process_for { + my ( $whom, $text ) = @_; + if ( $whom =~ /^(pod2)?html$/i ) { + print HTML $text; + } elsif ( $whom =~ /^illustration$/i ) { + 1 while chomp $text; + for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) { + $text .= $ext, last if -r "$text$ext"; + } + print HTML +qq{

    $text illustration

    }; + } +} + +# +# process_begin - process a =begin pod tag. this pushes +# whom we're beginning on the begin stack. if there's a +# begin stack, we only print if it us. +# +sub process_begin { + my ( $whom, $text ) = @_; + $whom = lc($whom); + push( @Begin_Stack, $whom ); + if ( $whom =~ /^(pod2)?html$/ ) { + print HTML $text if $text; + } +} + +# +# process_end - process a =end pod tag. pop the +# begin stack. die if we're mismatched. +# +sub process_end { + my ( $whom, $text ) = @_; + $whom = lc($whom); + if ( !defined $Begin_Stack[-1] or $Begin_Stack[-1] ne $whom ) { + Carp::confess( + "Unmatched begin/end at chunk $Paragraph in pod $Podfile\n"); + } + pop(@Begin_Stack); +} + +# +# process_pre - indented paragraph, made into
    
    +#
    +sub process_pre {
    +	my ($text) = @_;
    +	my ($rest);
    +	return if $Ignore;
    +
    +	$rest = $$text;
    +
    +	# insert spaces in place of tabs
    +	$rest =~ s#(.+)#
    +	    my $line = $1;
    +            1 while $line =~ s/(\t+)/' ' x ((length($1) * 8) - $-[0] % 8)/e;
    +	    $line;
    +	#eg;
    +
    +	# convert some special chars to HTML escapes
    +	$rest = html_escape($rest);
    +
    +	# try and create links for all occurrences of perl.* within
    +	# the preformatted text.
    +	$rest =~ s{
    +	         (\s*)(perl\w+)
    +	      }{
    +		 if ( defined $Pages{$2} ){	# is a link
    +		     qq($1$2);
    +		 } elsif (defined $Pages{dosify($2)}) {	# is a link
    +		     qq($1$2);
    +		 } else {
    +		     "$1$2";
    +		 }
    +	      }xeg;
    +	$rest =~ s{
    +		 ('
    +	|			# or:
    +	    [$punc]*		# 0 or more punctuation
    +	    (?:			#   followed
    +		[^$any]		#   by a non-url char
    +	    |			#   or
    +		$		#   end of the string
    +	    )			#
    +	|			# or else
    +	    $			#   then end of the string
    +        )
    +      }{$1}igox;
    +
    +	# text should be as it is (verbatim)
    +	$$text = $rest;
    +}
    +
    +#
    +# pure text processing
    +#
    +# pure_text/inIS_text: differ with respect to automatic C<> recognition.
    +# we don't want this to happen within IS
    +#
    +sub pure_text($) {
    +	my $text = shift();
    +	process_puretext( $text, 1 );
    +}
    +
    +sub inIS_text($) {
    +	my $text = shift();
    +	process_puretext( $text, 0 );
    +}
    +
    +#
    +# process_puretext - process pure text (without pod-escapes) converting
    +#  double-quotes and handling implicit C<> links.
    +#
    +sub process_puretext {
    +	my ( $text, $notinIS ) = @_;
    +
    +	## Guessing at func() or [\$\@%&]*var references in plain text is destined
    +	## to produce some strange looking ref's. uncomment to disable:
    +	## $notinIS = 0;
    +
    +	my ( @words, $lead, $trail );
    +
    +	# keep track of leading and trailing white-space
    +	$lead  = ( $text =~ s/\A(\s+)//s ? $1 : "" );
    +	$trail = ( $text =~ s/(\s+)\Z//s ? $1 : "" );
    +
    +	# split at space/non-space boundaries
    +	@words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
    +
    +	# process each word individually
    +	foreach my $word (@words) {
    +
    +		# skip space runs
    +		next if $word =~ /^\s*$/;
    +
    +		# see if we can infer a link or a function call
    +		#
    +		# NOTE: This is a word based search, it won't automatically
    +		# mark "substr($var, 1, 2)" because the 1st word would be "substr($var"
    +		# User has to enclose those with proper C<>
    +
    +		if (
    +			   $notinIS
    +			&& $word =~ m/
    +		^([a-z_]{2,})                 # The function name
    +		\(
    +		    ([0-9][a-z]*              # Manual page(1) or page(1M)
    +		    |[^)]*[\$\@\%][^)]+       # ($foo), (1, @foo), (%hash)
    +		    |                         # ()
    +		    )
    +		\)
    +		([.,;]?)$                     # a possible punctuation follows
    +	    /xi
    +			)
    +		{
    +
    +			# has parenthesis so should have been a C<> ref
    +			## try for a pagename (perlXXX(1))?
    +			my ( $func, $args, $rest ) = ( $1, $2, $3 || '' );
    +			if ( $args =~ /^\d+$/ ) {
    +				my $url = page_sect( $word, '' );
    +				if ( defined $url ) {
    +					$word =
    +qq(the $word manpage$rest);
    +					next;
    +				}
    +			}
    +			## try function name for a link, append tt'ed argument list
    +			$word = emit_C( $func, '', "($args)" ) . $rest;
    +
    +#### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
    +##      } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
    +##	    # perl variables, should be a C<> ref
    +##	    $word = emit_C( $word );
    +
    +		} elsif ( $word =~ m,^\w+://\w, ) {
    +
    +			# looks like a URL
    +			# Don't relativize it: leave it as the author intended
    +			$word = qq($word);
    +		} elsif ( $word =~ /[\w.-]+\@[\w-]+\.\w/ ) {
    +
    +			# looks like an e-mail address
    +			my ( $w1, $w2, $w3 ) = ( "", $word, "" );
    +			( $w1, $w2, $w3 ) = ( "(", $1, ")$2" ) if $word =~ /^\((.*?)\)(,?)/;
    +			( $w1, $w2, $w3 ) = ( "<", $1, ">$2" )
    +				if $word =~ /^<(.*?)>(,?)/;
    +			$word = qq($w1$w2$w3);
    +		} else {
    +			$word = html_escape($word) if $word =~ /["&<>]/;
    +		}
    +	}
    +
    +	# put everything back together
    +	return $lead . join( '', @words ) . $trail;
    +}
    +
    +#
    +# process_text - handles plaintext that appears in the input pod file.
    +# there may be pod commands embedded within the text so those must be
    +# converted to html commands.
    +#
    +
    +sub process_text1($$;$$);
    +sub pattern ($) { $_[0] ? '\s+' . ( '>' x ( $_[0] + 1 ) ) : '>' }
    +sub closing ($) { local ($_) = shift; ( defined && s/\s+\z// ) ? length : 0 }
    +
    +sub process_text {
    +	return if $Ignore;
    +	my ($tref) = @_;
    +	my $res = process_text1( 0, $tref );
    +	$res =~ s/\s+$//s;
    +	$$tref = $res;
    +}
    +
    +sub process_text_rfc_links {
    +	my $text = shift;
    +
    +	# For every "RFCnnnn" or "RFC nnn", link it to the authoritative
    +	# ource. Do not use the /i modifier here. Require "RFC" to be written in
    +	#  in capital letters.
    +
    +	$text =~ s{
    +	(?<=[^<>[:alpha:]])           # Make sure this is not an URL already
    +	(RFC\s*([0-9]{1,5}))(?![0-9]) # max 5 digits
    +    }
    +    {$1}gx;
    +
    +	$text;
    +}
    +
    +sub process_text1($$;$$) {
    +	my ( $lev, $rstr, $func, $closing ) = @_;
    +	my $res = '';
    +
    +	unless ( defined $func ) {
    +		$func = '';
    +		$lev++;
    +	}
    +
    +	if ( $func eq 'B' ) {
    +
    +		# B - boldface
    +		$res = '' . process_text1( $lev, $rstr ) . '';
    +
    +	} elsif ( $func eq 'C' ) {
    +
    +		# C - can be a ref or 
    +		# need to extract text
    +		my $par = go_ahead( $rstr, 'C', $closing );
    +
    +		## clean-up of the link target
    +		my $text = depod($par);
    +
    +		### my $x = $par =~ /[BI]call emit_C($par) lev=$lev, par with BI=$x\n";
    +
    +		$res = emit_C( $text, $lev > 1 || ( $par =~ /[BI] - convert to character
    +		$$rstr =~ s/^([^>]*)>//;
    +		my $escape = $1;
    +		$escape =~ s/^(\d+|X[\dA-F]+)$/#$1/i;
    +		$res = "&$escape;";
    +
    +	} elsif ( $func eq 'F' ) {
    +
    +		# F - italicize
    +		$res = '' . process_text1( $lev, $rstr ) . '';
    +
    +	} elsif ( $func eq 'I' ) {
    +
    +		# I - italicize
    +		$res = '' . process_text1( $lev, $rstr ) . '';
    +
    +	} elsif ( $func eq 'L' ) {
    +
    +		# L - link
    +		## L => produce text, use cross-ref for linking
    +		## L => make text from cross-ref
    +		## need to extract text
    +		my $par = go_ahead( $rstr, 'L', $closing );
    +
    +		# some L<>'s that shouldn't be:
    +		# a) full-blown URL's are emitted as-is
    +		if ( $par =~ m{^\w+://}s ) {
    +			return make_URL_href($par);
    +		}
    +
    +		# b) C<...> is stripped and treated as C<>
    +		if ( $par =~ /^C<(.*)>$/ ) {
    +			my $text = depod($1);
    +			return emit_C( $text, $lev > 1 || ( $par =~ /[BI] L<$par> to page $page, ident $ident\n";
    +
    +		} elsif ( $par =~ m{^(.*?)/"?(.*?)"?$} ) {    # [name]/"section"
    +			    # even though this should be a "section", we go for ident first
    +			( $page, $ident ) = ( $1, $2 );
    +			### print STDERR "--> L<$par> to page $page, section $section\n";
    +
    +		} elsif ( $par =~ /\s/ ) {  # this must be a section with missing quotes
    +			( $page, $section ) = ( '', $par );
    +			### print STDERR "--> L<$par> to void page, section $section\n";
    +
    +		} else {
    +			( $page, $section ) = ( $par, '' );
    +			### print STDERR "--> L<$par> to page $par, void section\n";
    +		}
    +
    +		# now, either $section or $ident is defined. the convoluted logic
    +		# below tries to resolve L<> according to what the user specified.
    +		# failing this, we try to find the next best thing...
    +		my ( $url, $ltext, $fid );
    +
    +	RESOLVE: {
    +			if ( defined $ident ) {
    +				## try to resolve $ident as an item
    +				( $url, $fid ) = coderef( $page, $ident );
    +				if ($url) {
    +					if ( !defined($linktext) ) {
    +						$linktext = $ident;
    +						$linktext .= " in " if $ident && $page;
    +						$linktext .= "the $page manpage" if $page;
    +					}
    +					###  print STDERR "got coderef url=$url\n";
    +					last RESOLVE;
    +				}
    +				## no luck: go for a section (auto-quoting!)
    +				$section = $ident;
    +			}
    +			## now go for a section
    +			my $htmlsection = htmlify($section);
    +			$url = page_sect( $page, $htmlsection );
    +			if ($url) {
    +				if ( !defined($linktext) ) {
    +					$linktext = $section;
    +					$linktext .= " in " if $section && $page;
    +					$linktext .= "the $page manpage" if $page;
    +				}
    +				### print STDERR "got page/section url=$url\n";
    +				last RESOLVE;
    +			}
    +			## no luck: go for an ident
    +			if ($section) {
    +				$ident = $section;
    +			} else {
    +				$ident = $page;
    +				$page  = undef();
    +			}
    +			( $url, $fid ) = coderef( $page, $ident );
    +			if ($url) {
    +				if ( !defined($linktext) ) {
    +					$linktext = $ident;
    +					$linktext .= " in " if $ident && $page;
    +					$linktext .= "the $page manpage" if $page;
    +				}
    +				### print STDERR "got section=>coderef url=$url\n";
    +				last RESOLVE;
    +			}
    +
    +			# warning; show some text.
    +			$linktext = $opar unless defined $linktext;
    +			warn
    +"$0: $Podfile: cannot resolve L<$opar> in paragraph $Paragraph.\n"
    +				unless $Quiet;
    +		}
    +
    +		# now we have a URL or just plain code
    +		$$rstr = $linktext . '>' . $$rstr;
    +		if ( defined($url) ) {
    +			$res = "" . process_text1( $lev, $rstr ) . '';
    +		} else {
    +			$res = '' . process_text1( $lev, $rstr ) . '';
    +		}
    +
    +	} elsif ( $func eq 'S' ) {
    +
    +		# S - non-breaking spaces
    +		$res = process_text1( $lev, $rstr );
    +		$res =~ s/ / /g;
    +
    +	} elsif ( $func eq 'X' ) {
    +
    +		# X<> - ignore
    +		warn "$0: $Podfile: invalid X<> in paragraph $Paragraph.\n"
    +			unless $$rstr =~ s/^[^>]*>//
    +				or $Quiet;
    +	} elsif ( $func eq 'Z' ) {
    +
    +		# Z<> - empty
    +		warn "$0: $Podfile: invalid Z<> in paragraph $Paragraph.\n"
    +			unless $$rstr =~ s/^>//
    +				or $Quiet;
    +
    +	} else {
    +		my $term = pattern $closing;
    +		while ( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ) {
    +
    +			# all others: either recurse into new function or
    +			# terminate at closing angle bracket(s)
    +			my $pt = $1;
    +			$pt .= $2 if !$3 && $lev == 1;
    +			$res .= $lev == 1 ? pure_text($pt) : inIS_text($pt);
    +			return $res if !$3 && $lev > 1;
    +			if ($3) {
    +				$res .= process_text1( $lev, $rstr, $3, closing $4 );
    +			}
    +		}
    +		if ( $lev == 1 ) {
    +			$res .= pure_text($$rstr);
    +		} elsif ( !$Quiet ) {
    +			my $snippet = substr( $$rstr, 0, 60 );
    +			warn
    +"$0: $Podfile: undelimited $func<> in paragraph $Paragraph: '$snippet'.\n"
    +
    +		}
    +		$res = process_text_rfc_links($res);
    +	}
    +	return $res;
    +}
    +
    +#
    +# go_ahead: extract text of an IS (can be nested)
    +#
    +sub go_ahead($$$) {
    +	my ( $rstr, $func, $closing ) = @_;
    +	my $res     = '';
    +	my @closing = ($closing);
    +	while ( $$rstr =~
    +		s/\A(.*?)(([BCEFILSXZ])<(<+\s+)?|@{[pattern $closing[0]]})//s )
    +	{
    +		$res .= $1;
    +		unless ($3) {
    +			shift @closing;
    +			return $res unless @closing;
    +		} else {
    +			unshift @closing, closing $4;
    +		}
    +		$res .= $2;
    +	}
    +	unless ($Quiet) {
    +		my $snippet = substr( $$rstr, 0, 60 );
    +		warn
    +"$0: $Podfile: undelimited $func<> in paragraph $Paragraph (go_ahead): '$snippet'.\n";
    +	}
    +	return $res;
    +}
    +
    +#
    +# emit_C - output result of C
    +#    $text is the depod-ed text
    +#
    +sub emit_C($;$$) {
    +	my ( $text, $nocode, $args ) = @_;
    +	$args = '' unless defined $args;
    +	my $res;
    +	my ( $url, $fid ) = coderef( undef(), $text );
    +
    +	# need HTML-safe text
    +	my $linktext = html_escape("$text$args");
    +
    +	if ( $text !~ /^[\$@%]/
    +		&& defined($url)
    +		&& ( !defined($EmittedItem) || $EmittedItem ne $fid ) )
    +	{
    +		$res = "$linktext";
    +	} elsif ( 0 && $nocode ) {
    +		$res = $linktext;
    +	} else {
    +		$res = "$linktext";
    +	}
    +	return $res;
    +}
    +
    +#
    +# html_escape: make text safe for HTML
    +#
    +sub html_escape {
    +	my $rest = $_[0];
    +	$rest =~ s/&/&/g;
    +	$rest =~ s//>/g;
    +	$rest =~ s/"/"/g;
    +
    +	# ' is only in XHTML, not HTML4.  Be conservative
    +	#$rest   =~ s/'/'/g;
    +	return $rest;
    +}
    +
    +#
    +# dosify - convert filenames to 8.3
    +#
    +sub dosify {
    +	my ($str) = @_;
    +	return lc($str) if $^O eq 'VMS';    # VMS just needs casing
    +	if ($Is83) {
    +		$str = lc $str;
    +		$str =~ s/(\.\w+)/substr ($1,0,4)/ge;
    +		$str =~ s/(\w+)/substr ($1,0,8)/ge;
    +	}
    +	return $str;
    +}
    +
    +#
    +# page_sect - make a URL from the text of a L<>
    +#
    +sub page_sect($$) {
    +	my ( $page, $section ) = @_;
    +	my ( $linktext, $page83, $link );    # work strings
    +
    +	# check if we know that this is a section in this page
    +	if ( !defined $Pages{$page} && defined $Sections{$page} ) {
    +		$section = $page;
    +		$page    = "";
    +		### print STDERR "reset page='', section=$section\n";
    +	}
    +
    +	$page83 = dosify($page);
    +	$page = $page83 if ( defined $Pages{$page83} );
    +	if ( $page eq "" ) {
    +		$link = "#" . anchorify($section);
    +	} elsif ( $page =~ /::/ ) {
    +		$page =~ s,::,/,g;
    +
    +		# Search page cache for an entry keyed under the html page name,
    +		# then look to see what directory that page might be in.  NOTE:
    +		# this will only find one page. A better solution might be to produce
    +		# an intermediate page that is an index to all such pages.
    +		my $page_name = $page;
    +		$page_name =~ s,^.*/,,s;
    +		if ( defined( $Pages{$page_name} )
    +			&& $Pages{$page_name} =~ /([^:]*$page)\.(?:pod|pm):/ )
    +		{
    +			$page = $1;
    +		} else {
    +
    +			# NOTE: This branch assumes that all A::B pages are located in
    +			# $Htmlroot/A/B.html . This is often incorrect, since they are
    +			# often in $Htmlroot/lib/A/B.html or such like. Perhaps we could
    +			# analyze the contents of %Pages and figure out where any
    +			# cousins of A::B are, then assume that.  So, if A::B isn't found,
    +			# but A::C is found in lib/A/C.pm, then A::B is assumed to be in
    +			# lib/A/B.pm. This is also limited, but it's an improvement.
    +			# Maybe a hints file so that the links point to the correct places
    +			# nonetheless?
    +
    +		}
    +		$link = "$Htmlroot/$page.html";
    +		$link .= "#" . anchorify($section) if ($section);
    +	} elsif ( !defined $Pages{$page} ) {
    +		$link = "";
    +	} else {
    +		$section = anchorify($section) if $section ne "";
    +		### print STDERR "...section=$section\n";
    +
    +		# if there is a directory by the name of the page, then assume that an
    +		# appropriate section will exist in the subdirectory
    +		#	if ($section ne "" && $Pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
    +		if ( $section ne "" && $Pages{$page} =~ /([^:]*(?, Foo.(pod|pm) is preferred to A/Foo.(pod|pm)
    +			if ( $Pages{$page} =~ /([^:]*)\.(?:pod|pm):/ ) {
    +				$link = "$Htmlroot/$1.html$section";
    +			} else {
    +				$link = "";
    +			}
    +		}
    +	}
    +
    +	if ($link) {
    +
    +		# Here, we take advantage of the knowledge that $Htmlfileurl ne ''
    +		# implies $Htmlroot eq ''. This means that the link in question
    +		# needs a prefix of $Htmldir if it begins with '/'. The test for
    +		# the initial '/' is done to avoid '#'-only links, and to allow
    +		# for other kinds of links, like file:, ftp:, etc.
    +		my $url;
    +		if ( $Htmlfileurl ne '' ) {
    +			$link = "$Htmldir$link" if $link =~ m{^/}s;
    +			$url = relativize_url( $link, $Htmlfileurl );
    +
    +			# print( "  b: [$link,$Htmlfileurl,$url]\n" );
    +		} else {
    +			$url = $link;
    +		}
    +		return $url;
    +
    +	} else {
    +		return undef();
    +	}
    +}
    +
    +#
    +# relativize_url - convert an absolute URL to one relative to a base URL.
    +# Assumes both end in a filename.
    +#
    +sub relativize_url {
    +	my ( $dest, $source ) = @_;
    +
    +	my ( $dest_volume, $dest_directory, $dest_file ) =
    +		File::Spec::Unix->splitpath($dest);
    +	$dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' );
    +
    +	my ( $source_volume, $source_directory, $source_file ) =
    +		File::Spec::Unix->splitpath($source);
    +	$source =
    +		File::Spec::Unix->catpath( $source_volume, $source_directory, '' );
    +
    +	my $rel_path = '';
    +	if ( $dest ne '' ) {
    +		$rel_path = File::Spec::Unix->abs2rel( $dest, $source );
    +	}
    +
    +	if (   $rel_path ne ''
    +		&& substr( $rel_path, -1 ) ne '/'
    +		&& substr( $dest_file, 0, 1 ) ne '#' )
    +	{
    +		$rel_path .= "/$dest_file";
    +	} else {
    +		$rel_path .= "$dest_file";
    +	}
    +
    +	return $rel_path;
    +}
    +
    +#
    +# coderef - make URL from the text of a C<>
    +#
    +sub coderef($$) {
    +	my ( $page, $item ) = @_;
    +	my ($url);
    +
    +	my $fid = fragment_id($item);
    +
    +	if ( defined($page) && $page ne "" ) {
    +
    +		# we have been given a $page...
    +		$page =~ s{::}{/}g;
    +
    +		Carp::confess(
    +"Undefined fragment '$item' from fragment_id() in coderef() in $Podfile"
    +		) if !defined $fid;
    +
    +		# Do we take it? Item could be a section!
    +		my $base = $Items{$fid} || "";
    +		$base =~ s{[^/]*/}{};
    +		if ( $base ne "$page.html" ) {
    +			###   print STDERR "coderef( $page, $item ): items{$fid} = $Items{$fid} = $base => discard page!\n";
    +			$page = undef();
    +		}
    +
    +	} else {
    +
    +		# no page - local items precede cached items
    +		if ( defined($fid) ) {
    +			if ( exists $Local_Items{$fid} ) {
    +				$page = $Local_Items{$fid};
    +			} else {
    +				$page = $Items{$fid};
    +			}
    +		}
    +	}
    +
    +	# if there was a pod file that we found earlier with an appropriate
    +	# =item directive, then create a link to that page.
    +	if ( defined $page ) {
    +		if ($page) {
    +			if ( exists $Pages{$page} and $Pages{$page} =~ /([^:.]*)\.[^:]*:/ )
    +			{
    +				$page = $1 . '.html';
    +			}
    +			my $link = "$Htmlroot/$page#" . anchorify($fid);
    +
    +			# Here, we take advantage of the knowledge that $Htmlfileurl
    +			# ne '' implies $Htmlroot eq ''.
    +			if ( $Htmlfileurl ne '' ) {
    +				$link = "$Htmldir$link";
    +				$url = relativize_url( $link, $Htmlfileurl );
    +			} else {
    +				$url = $link;
    +			}
    +		} else {
    +			$url = "#" . anchorify($fid);
    +		}
    +
    +		confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
    +	}
    +	return ( $url, $fid );
    +}
    +
    +#
    +# Adapted from Nick Ing-Simmons' PodToHtml package.
    +sub relative_url {
    +	my $source_file      = shift;
    +	my $destination_file = shift;
    +
    +	my $source = URI::file->new_abs($source_file);
    +	my $uo = URI::file->new( $destination_file, $source )->abs;
    +	return $uo->rel->as_string;
    +}
    +
    +#
    +# finish_list - finish off any pending HTML lists.  this should be called
    +# after the entire pod file has been read and converted.
    +#
    +sub finish_list {
    +	while ( $Listlevel > 0 ) {
    +		print HTML "\n";
    +		$Listlevel--;
    +	}
    +}
    +
    +#
    +# htmlify - converts a pod section specification to a suitable section
    +# specification for HTML. Note that we keep spaces and special characters
    +# except ", ? (Netscape problem) and the hyphen (writer's problem...).
    +#
    +sub htmlify {
    +	my ($heading) = @_;
    +	$heading =~ s/(\s+)/ /g;
    +	$heading =~ s/\s+\Z//;
    +	$heading =~ s/\A\s+//;
    +
    +	# The hyphen is a disgrace to the English language.
    +	# $heading =~ s/[-"?]//g;
    +	$heading =~ s/["?]//g;
    +	$heading = lc($heading);
    +	return $heading;
    +}
    +
    +#
    +# similar to htmlify, but turns non-alphanumerics into underscores
    +#
    +sub anchorify {
    +	my ($anchor) = @_;
    +	$anchor =~ s/\([^)]*\)//;
    +	$anchor = htmlify($anchor);
    +	$anchor =~ s/\W/_/g;
    +	$anchor =~ tr/_/_/s;
    +	return $anchor;
    +}
    +
    +#
    +# depod - convert text by eliminating all interior sequences
    +# Note: can be called with copy or modify semantics
    +#
    +my %E2c;
    +$E2c{lt}     = '<';
    +$E2c{gt}     = '>';
    +$E2c{sol}    = '/';
    +$E2c{verbar} = '|';
    +$E2c{amp}    = '&';    # in Tk's pods
    +
    +sub depod1($;$$);
    +
    +sub depod($) {
    +	my $string;
    +	if ( ref( $_[0] ) ) {
    +		$string = ${ $_[0] };
    +		${ $_[0] } = depod1( \$string );
    +	} else {
    +		$string = $_[0];
    +		depod1( \$string );
    +	}
    +}
    +
    +sub depod1($;$$) {
    +	my ( $rstr, $func, $closing ) = @_;
    +	my $res = '';
    +	return $res unless defined $$rstr;
    +	if ( !defined($func) ) {
    +
    +		# skip to next begin of an interior sequence
    +		while ( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?//s ) {
    +
    +			# recurse into its text
    +			$res .= $1 . depod1( $rstr, $2, closing $3);
    +		}
    +		$res .= $$rstr;
    +	} elsif ( $func eq 'E' ) {
    +
    +		# E - convert to character
    +		$$rstr =~ s/^([^>]*)>//;
    +		$res .= $E2c{$1} || "";
    +	} elsif ( $func eq 'X' ) {
    +
    +		# X<> - ignore
    +		$$rstr =~ s/^[^>]*>//;
    +	} elsif ( $func eq 'Z' ) {
    +
    +		# Z<> - empty
    +		$$rstr =~ s/^>//;
    +	} else {
    +
    +		# all others: either recurse into new function or
    +		# terminate at closing angle bracket
    +		my $term = pattern $closing;
    +		while ( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ) {
    +			$res .= $1;
    +			last unless $3;
    +			$res .= depod1( $rstr, $3, closing $4 );
    +		}
    +		## If we're here and $2 ne '>': undelimited interior sequence.
    +		## Ignored, as this is called without proper indication of where we are.
    +		## Rely on process_text to produce diagnostics.
    +	}
    +	return $res;
    +}
    +
    +{
    +	my %seen;    # static fragment record hash
    +
    +	sub fragment_id_readable {
    +		my $text     = shift;
    +		my $generate = shift;    # optional flag
    +
    +		my $orig = $text;
    +
    +		# leave the words for the fragment identifier,
    +		# change everything else to underbars.
    +		$text =~
    +			s/[^A-Za-z0-9_]+/_/g;    # do not use \W to avoid locale dependency.
    +		$text =~ s/_{2,}/_/g;
    +		$text =~ s/\A_//;
    +		$text =~ s/_\Z//;
    +
    +		unless ($text) {
    +
    +			# Nothing left after removing punctuation, so leave it as is
    +			# E.g. if option is named: "=item -#"
    +
    +			$text = $orig;
    +		}
    +
    +		if ($generate) {
    +			if ( exists $seen{$text} ) {
    +
    +				# This already exists, make it unique
    +				$seen{$text}++;
    +				$text = $text . $seen{$text};
    +			} else {
    +				$seen{$text} = 1;    # first time seen this fragment
    +			}
    +		}
    +
    +		$text;
    +	}
    +}
    +
    +my @HC;
    +
    +sub fragment_id_obfuscated {         # This was the old "_2d_2d__"
    +	my $text     = shift;
    +	my $generate = shift;            # optional flag
    +
    +	# text? Normalize by obfuscating the fragment id to make it unique
    +	$text =~ s/\s+/_/sg;
    +
    +	$text =~ s{(\W)}{
    +        defined( $HC[ord($1)] ) ? $HC[ord($1)]
    +        : ( $HC[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
    +	$text = substr( $text, 0, 50 );
    +
    +	$text;
    +}
    +
    +#
    +# fragment_id - construct a fragment identifier from:
    +#   a) =item text
    +#   b) contents of C<...>
    +#
    +
    +sub fragment_id {
    +	my $text     = shift;
    +	my $generate = shift;    # optional flag
    +
    +	$text =~ s/\s+\Z//s;
    +	if ($text) {
    +
    +		# a method or function?
    +		return $1 if $text =~ /(\w+)\s*\(/;
    +		return $1 if $text =~ /->\s*(\w+)\s*\(?/;
    +
    +		# a variable name?
    +		return $1 if $text =~ /^([\$\@%*]\S+)/;
    +
    +		# some pattern matching operator?
    +		return $1 if $text =~ m|^(\w+/).*/\w*$|;
    +
    +		# fancy stuff... like "do { }"
    +		return $1 if $text =~ m|^(\w+)\s*{.*}$|;
    +
    +		# honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
    +		# and some funnies with ... Module ...
    +		return $1 if $text =~ m{^([a-z\d_]+)(\s+[A-Z,/& ][A-Z\d,/& ]*)?$};
    +		return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
    +
    +		return fragment_id_readable( $text, $generate );
    +	} else {
    +		return;
    +	}
    +}
    +
    +#
    +# make_URL_href - generate HTML href from URL
    +# Special treatment for CGI queries.
    +#
    +sub make_URL_href($;$) {
    +	my ($url) = shift;
    +	my $linktext = shift || $url;
    +	if ( $url !~ s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{$1}i ) {
    +		$url = "$linktext";
    +	}
    +	return $url;
    +}
    +
    +1;
    diff --git a/plugins/perl/lib/Xchat.pm b/plugins/perl/lib/Xchat.pm
    new file mode 100644
    index 00000000..74914882
    --- /dev/null
    +++ b/plugins/perl/lib/Xchat.pm
    @@ -0,0 +1,506 @@
    +BEGIN {
    +	$INC{'Xchat.pm'} = 'DUMMY';
    +}
    +
    +$SIG{__WARN__} = sub {
    +	my $message = shift @_;
    +	my ($package) = caller;
    +	
    +	# redirect Gtk/Glib errors and warnings back to STDERR
    +	my $message_levels =	qr/ERROR|CRITICAL|WARNING|MESSAGE|INFO|DEBUG/i;
    +	if( $message =~ /^(?:Gtk|GLib|Gdk)(?:-\w+)?-$message_levels/i ) {
    +		print STDERR $message;
    +	} else {
    +
    +		if( defined &Xchat::Internal::print ) {
    +			Xchat::print( $message );
    +		} else {
    +			warn $message;
    +		}
    +	}
    +};
    +
    +use File::Spec ();
    +use File::Basename ();
    +use File::Glob ();
    +use List::Util ();
    +use Symbol();
    +use Time::HiRes ();
    +use Carp ();
    +
    +package Xchat;
    +use base qw(Exporter);
    +use strict;
    +use warnings;
    +
    +sub PRI_HIGHEST ();
    +sub PRI_HIGH ();
    +sub PRI_NORM ();
    +sub PRI_LOW ();
    +sub PRI_LOWEST ();
    +
    +sub EAT_NONE ();
    +sub EAT_XCHAT ();
    +sub EAT_PLUIN ();
    +sub EAT_ALL ();
    +
    +sub KEEP ();
    +sub REMOVE ();
    +sub FD_READ ();
    +sub FD_WRITE ();
    +sub FD_EXCEPTION ();
    +sub FD_NOTSOCKET ();
    +
    +sub get_context;
    +sub Xchat::Internal::context_info;
    +sub Xchat::Internal::print;
    +
    +our %EXPORT_TAGS = (
    +	constants => [
    +		qw(PRI_HIGHEST PRI_HIGH PRI_NORM PRI_LOW PRI_LOWEST), # priorities
    +		qw(EAT_NONE EAT_XCHAT EAT_PLUGIN EAT_ALL), # callback return values
    +		qw(FD_READ FD_WRITE FD_EXCEPTION FD_NOTSOCKET), # fd flags
    +		qw(KEEP REMOVE), # timers
    +	],
    +	hooks => [
    +		qw(hook_server hook_command hook_print hook_timer hook_fd unhook),
    +	],
    +	util => [
    +		qw(register nickcmp strip_code send_modes), # misc
    +		qw(print prnt printf prntf command commandf emit_print), # output
    +		qw(find_context get_context set_context), # context
    +		qw(get_info get_prefs get_list context_info user_info), # input
    +	],
    +);
    +
    +$EXPORT_TAGS{all} = [ map { @{$_} } @EXPORT_TAGS{qw(constants hooks util)}];
    +our @EXPORT = @{$EXPORT_TAGS{constants}};
    +our @EXPORT_OK = @{$EXPORT_TAGS{all}};
    +
    +sub register {
    +	my $package = Xchat::Embed::find_pkg();
    +	my $pkg_info = Xchat::Embed::pkg_info( $package );
    +	my $filename = $pkg_info->{filename};
    +	my ($name, $version, $description, $callback) = @_;
    +	
    +	if( defined $pkg_info->{gui_entry} ) {
    +		Xchat::print( "Xchat::register called more than once in "
    +			. $pkg_info->{filename} );
    +		return ();
    +	}
    +	
    +	$description = "" unless defined $description;
    +	$pkg_info->{shutdown} = $callback;
    +	unless( $name && $name =~ /[[:print:]\w]/ ) {
    +		$name = "Not supplied";
    +	}
    +	unless( $version && $version =~ /\d+(?:\.\d+)?/ ) {
    +		$version = "NaN";
    +	}
    +	$pkg_info->{gui_entry} =
    +		Xchat::Internal::register( $name, $version, $description, $filename );
    +	# keep with old behavior
    +	return ();
    +}
    +
    +sub _process_hook_options {
    +	my ($options, $keys, $store) = @_;
    +
    +	unless( @$keys == @$store ) {
    +		die 'Number of keys must match the size of the store';
    +	}
    +
    +	my @results;
    +
    +	if( ref( $options ) eq 'HASH' ) {
    +		for my $index ( 0 .. @$keys - 1 ) {
    +			my $key = $keys->[$index];
    +			if( exists( $options->{ $key } ) && defined( $options->{ $key } ) ) {
    +				${$store->[$index]} = $options->{ $key };
    +			}
    +		}
    +	}
    +
    +}
    +
    +sub hook_server {
    +	return undef unless @_ >= 2;
    +	my $message = shift;
    +	my $callback = shift;
    +	my $options = shift;
    +	my $package = Xchat::Embed::find_pkg();
    +	
    +	$callback = Xchat::Embed::fix_callback( $package, $callback );
    +	
    +	my ($priority, $data) = ( Xchat::PRI_NORM, undef );
    +	_process_hook_options(
    +		$options,
    +		[qw(priority data)],
    +		[\($priority, $data)],
    +	);
    +	
    +	my $pkg_info = Xchat::Embed::pkg_info( $package );
    +	my $hook = Xchat::Internal::hook_server(
    +		$message, $priority, $callback, $data
    +	);
    +	push @{$pkg_info->{hooks}}, $hook if defined $hook;
    +	return $hook;
    +}
    +
    +sub hook_command {
    +	return undef unless @_ >= 2;
    +	my $command = shift;
    +	my $callback = shift;
    +	my $options = shift;
    +	my $package = Xchat::Embed::find_pkg();
    +
    +	$callback = Xchat::Embed::fix_callback( $package, $callback );
    +	
    +	my ($priority, $help_text, $data) = ( Xchat::PRI_NORM, undef, undef );
    +	_process_hook_options(
    +		$options,
    +		[qw(priority help_text data)],
    +		[\($priority, $help_text, $data)],
    +	);
    +	
    +	my $pkg_info = Xchat::Embed::pkg_info( $package );
    +	my $hook = Xchat::Internal::hook_command(
    +		$command, $priority, $callback, $help_text, $data
    +	);
    +	push @{$pkg_info->{hooks}}, $hook if defined $hook;
    +	return $hook;
    +}
    +
    +sub hook_print {
    +	return undef unless @_ >= 2;
    +	my $event = shift;
    +	my $callback = shift;
    +	my $options = shift;
    +	my $package = Xchat::Embed::find_pkg();
    +
    +	$callback = Xchat::Embed::fix_callback( $package, $callback );
    +	
    +	my ($priority, $run_after, $filter, $data) = ( Xchat::PRI_NORM, 0, 0, undef );
    +	_process_hook_options(
    +		$options,
    +		[qw(priority run_after_event filter data)],
    +		[\($priority, $run_after, $filter, $data)],
    +	);
    +	
    +	if( $run_after and $filter ) {
    +		Carp::carp( "Xchat::hook_print's run_after_event and filter options are mutually exclusive, you can only use of them at a time per hook" );
    +		return;
    +	}
    +
    +	if( $run_after ) {
    +		my $cb = $callback;
    +		$callback = sub {
    +			my @args = @_;
    +			hook_timer( 0, sub {
    +				$cb->( @args );
    +
    +				if( ref $run_after eq 'CODE' ) {
    +					$run_after->( @args );
    +				}
    +				return REMOVE;
    +			});
    +			return EAT_NONE;
    +		};
    +	}
    +
    +	if( $filter ) {
    +		my $cb = $callback;
    +		$callback = sub {
    +			my @args = @{$_[0]};
    +			my $last_arg = @args - 1;
    +
    +			my @new = $cb->( \@args, $_[1], $event );
    +
    +			# a filter can either return the new results or it can modify
    +			# @_ in place. 
    +			if( @new ) {
    +				emit_print( $event, @new[ 0 .. $last_arg ] );
    +				return EAT_ALL;
    +			} elsif(
    +				join( "\0", @{$_[0]} ) ne join( "\0", @args[ 0 .. $last_arg ] )
    +			) {
    +				emit_print( $event, @args[ 0 .. $last_arg ] );
    +				return EAT_ALL;
    +			}
    +
    +			return EAT_NONE;
    +		};
    +
    +	}
    +
    +	my $pkg_info = Xchat::Embed::pkg_info( $package );
    +	my $hook = Xchat::Internal::hook_print(
    +		$event, $priority, $callback, $data
    +	);
    +	push @{$pkg_info->{hooks}}, $hook if defined $hook;
    +	return $hook;
    +}
    +
    +sub hook_timer {
    +	return undef unless @_ >= 2;
    +	my ($timeout, $callback, $data) = @_;
    +	my $package = Xchat::Embed::find_pkg();
    +
    +	$callback = Xchat::Embed::fix_callback( $package, $callback );
    +
    +	if(
    +		ref( $data ) eq 'HASH' && exists( $data->{data} )
    +		&& defined( $data->{data} )
    +	) {
    +		$data = $data->{data};
    +	}
    +	
    +	my $pkg_info = Xchat::Embed::pkg_info( $package );
    +	my $hook = Xchat::Internal::hook_timer( $timeout, $callback, $data, $package );
    +	push @{$pkg_info->{hooks}}, $hook if defined $hook;
    +	return $hook;
    +}
    +
    +sub hook_fd {
    +	return undef unless @_ >= 2;
    +	my ($fd, $callback, $options) = @_;
    +	return undef unless defined $fd && defined $callback;
    +
    +	my $fileno = fileno $fd;
    +	return undef unless defined $fileno; # no underlying fd for this handle
    +	
    +	my ($package) = Xchat::Embed::find_pkg();
    +	$callback = Xchat::Embed::fix_callback( $package, $callback );
    +	
    +	my ($flags, $data) = (Xchat::FD_READ, undef);
    +	_process_hook_options(
    +		$options,
    +		[qw(flags data)],
    +		[\($flags, $data)],
    +	);
    +	
    +	my $cb = sub {
    +		my $userdata = shift;
    +		return $userdata->{CB}->(
    +			$userdata->{FD}, $userdata->{FLAGS}, $userdata->{DATA},
    +		);
    +	};
    +	
    +	my $pkg_info = Xchat::Embed::pkg_info( $package );
    +	my $hook = Xchat::Internal::hook_fd(
    +		$fileno, $cb, $flags, {
    +			DATA => $data, FD => $fd, CB => $callback, FLAGS => $flags,
    +		}
    +	);
    +	push @{$pkg_info->{hooks}}, $hook if defined $hook;
    +	return $hook;
    +}
    +
    +sub unhook {
    +	my $hook = shift @_;
    +	my $package = shift @_;
    +	($package) = caller unless $package;
    +	my $pkg_info = Xchat::Embed::pkg_info( $package );
    +
    +	if( defined( $hook )
    +		&& $hook =~ /^\d+$/
    +		&& grep { $_ == $hook } @{$pkg_info->{hooks}} ) {
    +		$pkg_info->{hooks} = [grep { $_ != $hook } @{$pkg_info->{hooks}}];
    +		return Xchat::Internal::unhook( $hook );
    +	}
    +	return ();
    +}
    +
    +sub _do_for_each {
    +	my ($cb, $channels, $servers) = @_;
    +
    +	# not specifying any channels or servers is not the same as specifying
    +	# undef for both
    +	# - not specifying either results in calling the callback inthe current ctx
    +	# - specifying undef for for both results in calling the callback in the
    +	#   front/currently selected tab
    +	if( @_ == 3 && !($channels || $servers) ) { 
    +		$channels = [ undef ];
    +		$servers = [ undef ];
    +	} elsif( !($channels || $servers) ) {
    +		$cb->();
    +		return 1;
    +	}
    +
    +	$channels = [ $channels ] unless ref( $channels ) eq 'ARRAY';
    +
    +	if( $servers ) {
    +		$servers = [ $servers ] unless ref( $servers ) eq 'ARRAY';
    +	} else {
    +		$servers = [ undef ];
    +	}
    +
    +	my $num_done = 0;
    +	my $old_ctx = Xchat::get_context();
    +	for my $server ( @$servers ) {
    +		for my $channel ( @$channels ) {
    +			if( Xchat::set_context( $channel, $server ) ) {
    +				$cb->();
    +				$num_done++
    +			}
    +		}
    +	}
    +	Xchat::set_context( $old_ctx );
    +	return $num_done;
    +}
    +
    +sub print {
    +	my $text = shift @_;
    +	return "" unless defined $text;
    +	if( ref( $text ) eq 'ARRAY' ) {
    +		if( $, ) {
    +			$text = join $, , @$text;
    +		} else {
    +			$text = join "", @$text;
    +		}
    +	}
    +	
    +	return _do_for_each(
    +		sub { Xchat::Internal::print( $text ); },
    +		@_
    +	);
    +}
    +
    +sub printf {
    +	my $format = shift;
    +	Xchat::print( sprintf( $format, @_ ) );
    +}
    +
    +# make Xchat::prnt() and Xchat::prntf() as aliases for Xchat::print() and 
    +# Xchat::printf(), mainly useful when these functions are exported
    +sub prnt {
    +	goto &Xchat::print;
    +}
    +
    +sub prntf {
    +	goto &Xchat::printf;
    +}
    +
    +sub command {
    +	my $command = shift;
    +	return "" unless defined $command;
    +	my @commands;
    +	
    +	if( ref( $command ) eq 'ARRAY' ) {
    +		@commands = @$command;
    +	} else {
    +		@commands = ($command);
    +	}
    +	
    +	return _do_for_each(
    +		sub { Xchat::Internal::command( $_ ) foreach @commands },
    +		@_
    +	);
    +}
    +
    +sub commandf {
    +	my $format = shift;
    +	Xchat::command( sprintf( $format, @_ ) );
    +}
    +
    +sub set_context {
    +	my $context;
    +	if( @_ == 2 ) {
    +		my ($channel, $server) = @_;
    +		$context = Xchat::find_context( $channel, $server );
    +	} elsif( @_ == 1 ) {
    +		if( defined $_[0] && $_[0] =~ /^\d+$/ ) {
    +			$context = $_[0];
    +		} else {
    +			$context = Xchat::find_context( $_[0] );
    +		}
    +	} elsif( @_ == 0 ) {
    +		$context = Xchat::find_context();
    +	}
    +	return $context ? Xchat::Internal::set_context( $context ) : 0;
    +}
    +
    +sub get_info {
    +	my $id = shift;
    +	my $info;
    +	
    +	if( defined( $id ) ) {
    +		if( grep { $id eq $_ } qw(state_cursor id) ) {
    +			$info = Xchat::get_prefs( $id );
    +		} else {
    +			$info = Xchat::Internal::get_info( $id );
    +		}
    +	}
    +	return $info;
    +}
    +
    +sub user_info {
    +	my $nick = Xchat::strip_code(shift @_ || Xchat::get_info( "nick" ));
    +	my $user;
    +	for (Xchat::get_list( "users" ) ) {
    +		if ( Xchat::nickcmp( $_->{nick}, $nick ) == 0 ) {
    +			$user = $_;
    +			last;
    +		}
    +	}
    +	return $user;
    +}
    +
    +sub context_info {
    +	my $ctx = shift @_ || Xchat::get_context;
    +	my $old_ctx = Xchat::get_context;
    +	my @fields = (
    +		qw(away channel charset host id inputbox libdirfs modes network),
    +		qw(nick nickserv server topic version win_ptr win_status),
    +		qw(xchatdir xchatdirfs state_cursor),
    +	);
    +
    +	if( Xchat::set_context( $ctx ) ) {
    +		my %info;
    +		for my $field ( @fields ) {
    +			$info{$field} = Xchat::get_info( $field );
    +		}
    +		
    +		my $ctx_info = Xchat::Internal::context_info;
    +		@info{keys %$ctx_info} = values %$ctx_info;
    +		
    +		Xchat::set_context( $old_ctx );
    +		return %info if wantarray;
    +		return \%info;
    +	} else {
    +		return undef;
    +	}
    +}
    +
    +sub get_list {
    +	unless( grep { $_[0] eq $_ } qw(channels dcc ignore notify users networks) ) {
    +		Carp::carp( "'$_[0]' does not appear to be a valid list name" );
    +	}
    +	if( $_[0] eq 'networks' ) {
    +		return Xchat::List::Network->get();
    +	} else {
    +		return Xchat::Internal::get_list( $_[0] );
    +	}
    +}
    +
    +sub strip_code {
    +	my $pattern = qr<
    +		\cB| #Bold
    +		\cC\d{0,2}(?:,\d{1,2})?| #Color
    +		\e\[(?:\d{1,2}(?:;\d{1,2})*)?m| # ANSI color code
    +		\cG| #Beep
    +		\cO| #Reset
    +		\cV| #Reverse
    +		\c_  #Underline
    +	>x;
    +		
    +	if( defined wantarray ) {
    +		my $msg = shift;
    +		$msg =~ s/$pattern//g;
    +		return $msg;
    +	} else {
    +		$_[0] =~ s/$pattern//g if defined $_[0];
    +	}
    +}
    +
    +1
    diff --git a/plugins/perl/lib/Xchat.pod b/plugins/perl/lib/Xchat.pod
    new file mode 100644
    index 00000000..a55a9bce
    --- /dev/null
    +++ b/plugins/perl/lib/Xchat.pod
    @@ -0,0 +1,1326 @@
    +=head1 X-Chat 2 Perl Interface
    +
    +=head2 Introduction
    +
    +This is the new Perl interface for X-Chat 2.  However, due to changes in
    +xchat's plugin code you will need xchat 2.0.8 or above to load this.  Scripts
    +written using the old interface will continue to work. If there are any
    +problems, questions, comments or suggestions please email them to the address
    +on the bottom of this page.
    +
    +=head2 Constants
    +
    +=head3 Priorities
    +
    +=over 3
    +
    +=item *
    +C 
    +
    +=item *
    +C 
    +
    +=item *
    +C 
    +
    +=item *
    +C 
    +
    +=item *
    +C 
    +
    +=back
    +
    +=head3 Return values
    +
    +=over 3
    +
    +=item *
    +C     - pass the event along
    +
    +=item *
    +C    - don't let xchat see this event
    +
    +=item *
    +C   - don't let other scripts and plugins see this event but xchat will still see it
    +
    +=item *
    +C      - don't let anything else see this event
    +
    +=back
    +
    +=head4 Timer and fd hooks
    +
    +=over 3
    +
    +=item *
    +C         - keep the timer going or hook watching the handle
    +
    +=item *
    +C       - remove the timer or hook watching the handle
    +
    +=back
    +
    +=head3 hook_fd flags
    +
    +=over 3
    +
    +=item *
    +C			- invoke the callback when the handle is ready for reading
    +
    +=item *
    +C		- invoke the callback when the handle is ready for writing
    +
    +=item *
    +C	- invoke the callback if an exception occurs
    +
    +=item *
    +C	- indicate that the handle being hooked is not a socket
    +
    +=back
    +
    +=head2 Functions
    +
    +=head3 C 
    +
    +=over 3
    +
    +=item *
    +C<$name>             -  The name of this script
    +
    +=item *
    +C<$version>          -  This script's version
    +
    +=item *
    +C<$description>   -  A description for this script
    +
    +=item *
    +C<$callback>      -  This is a function that will be called when the is script
    +                     unloaded. This can be either a reference to a
    +                     function or an anonymous sub reference.
    +
    +=back
    +
    +This is the first thing to call in every script.
    +
    +=head3 C 
    +
    +=head3 C 
    +
    +=head3 C 
    +
    +=head3 C 
    +
    +=head3 C
    +
    +These functions can be to intercept various events.
    +hook_server can be used to intercept any incoming message from the IRC server.
    +hook_command can be used to intercept any command, if the command doesn't currently exist then a new one is created.
    +hook_print can be used to intercept any of the events listed in Setttings-EAdvanced-EText Events
    +hook_timer can be used to create a new timer
    +
    +
    +=over 3
    +
    +=item *
    +C<$message>       -  server message to hook such as PRIVMSG
    +
    +=item *
    +C<$command>       -  command to intercept, without the leading /
    +
    +=item *
    +C<$event>      -  one of the events listed in Settings-EAdvanced-EText Events
    +
    +=item *
    +C<$timeout>       -  timeout in milliseconds
    +
    +=item *
    +C<$handle>     - the I/O handle you want to monitor with hook_fd. This must be something that has a fileno. See perldoc -f fileno or L
    +
    +=item *
    +C<$callback>   -  callback function, this is called whenever
    +                  the hooked event is trigged, the following are
    +                  the conditions that will trigger the different hooks.
    +                  This can be either a reference to a
    +                  function or an anonymous sub reference.
    +
    +=item *
    +\%options   -  a hash reference containing addional options for the hooks
    +
    +=back
    +
    +Valid keys for \%options:
    +
    +=begin html
    +
    +
    +
    +   
    +   
    +   
    +
    +   
    +      
    +
    +   
    +
    +   
    +      
    +   
    +
    +   
    +      
    +   
    +
    +
    data Additional data that is to be associated with the
    + hook. For timer hooks this value can be provided either as
    + Xchat::hook_timer( $timeout, $cb,{data=>$data})
    + or Xchat::hook_timer( $timeout, $cb, $data ).
    + However, this means that hook_timer cannot be provided
    + with a hash reference containing data as a key.
    + + example:
    + my $options = { data => [@arrayOfStuff] };
    + Xchat::hook_timer( $timeout, $cb, $options );
    +
    + In this example, the timer's data will be
    + [@arrayOfStuff] and not { data => [@arrayOfStuff] }
    +
    + This key is valid for all of the hook functions.
    +
    + Default is undef.
    +
    priority Sets the priority for the hook.
    + It can be set to one of the + Xchat::PRI_* constants.
    +
    + This key only applies to server, command + and print hooks.
    +
    + Default is Xchat::PRI_NORM. +
    help_text Text displayed for /help $command.
    +
    + This key only applies to command hooks.
    +
    + Default is "". +
    flags Specify the flags for a fd hook.
    +
    + See hook fd flags section for valid values.
    +
    + On Windows if the handle is a pipe you specify
    + Xchat::FD_NOTSOCKET in addition to any other flags you might be using.
    +
    + This key only applies to fd hooks.
    + Default is Xchat::FD_READ +
    + +=end html + +=head4 When callbacks are invoked + +Each of the hooks will be triggered at different times depending on the type +of hook. + +=begin html + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Hook Type When the callback will be invoked
    server hooks a $message message is + received from the server +
    command hooks the $command command is + executed, either by the user or from a script +
    print hooks X-Chat is about to print the message for the + $event event +
    timer hooks called every $timeout milliseconds + (1000 millisecond is 1 second)
    + the callback will be executed in the same context where + the hook_timer was called, if the context no longer exists + then it will execute in a random context +
    fd hooks depends on the flags that were passed to hook_fd
    + See hook_fd flags section. +
    + +=end html + + +The value return from these hook functions can be passed to C +to remove the hook. + +=head4 Callback Arguments + +All callback functions will receive their arguments in C<@_> like every +other Perl subroutine. + +=begin html + +

    +Server and command callbacks
    +
    +$_[0] - array reference containing the IRC message or command and +arguments broken into words
    +example:
    +/command arg1 arg2 arg3
    +$_[0][0] - command
    +$_[0][1] - arg1
    +$_[0][2] - arg2
    +$_[0][3] - arg3
    +
    +$_[1] - array reference containing the Nth word to the last word
    +example:
    +/command arg1 arg2 arg3
    +$_[1][0] - command arg1 arg2 arg3
    +$_[1][1] - arg1 arg2 arg3
    +$_[1][2] - arg2 arg3
    +$_[1][3] - arg3
    +
    +$_[2] - the data that was passed to the hook function
    +
    +Print callbacks
    +
    +$_[0] - array reference containing the values for the + text event see Settings->Advanced->Text Events
    +$_[1] - the data that was passed to the hook function
    +
    +Timer callbacks
    +
    +$_[0] - the data that was passed to the hook function
    +
    + +fd callbacks
    +
    +$_[0] - the handle that was passed to hook_fd
    +$_[1] - flags indicating why the callback was called
    +$_[2] - the data that was passed to the hook function
    +

    + +=end html + +=head4 Callback return values + +All server, command and print callbacks should return one of +the C constants. +Timer callbacks can return Xchat::REMOVE to remove +the timer or Xchat::KEEP to keep it going + +=head4 Miscellaneous Hook Related Information + +For server hooks, if C<$message> is "RAW LINE" then C<$cb> will be called for +every IRC message than X-Chat receives. + +For command hooks if C<$command> is "" then C<$cb> will be called for +messages entered by the user that is not a command. + +For print hooks besides those events listed in +Settings-EAdvanced-EText Events, these additional events can be used. + +=begin html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Event Description
    "Open Context" a new context is created
    "Close Context" a context has been close
    "Focus Tab" when a tab is brought to the front
    "Focus Window" when a top level window is focused or the + main tab window is focused by the window manager +
    "DCC Chat Text" when text from a DCC Chat arrives. + $_[0] will have these values
    +
    + $_[0][0] - Address
    + $_[0][1] - Port
    + $_[0][2] - Nick
    + $_[0][3] - Message
    +
    "Key Press" used for intercepting key presses
    + $_[0][0] - key value
    + $_[0][1] - state bitfield, 1 - shift, 4 - control, 8 - alt
    + $_[0][2] - string version of the key which might be empty for unprintable keys
    + $_[0][3] - length of the string in $_[0][2]
    +
    + +=end html + +=head3 C + +=over 3 + +=item * +C<$hook> - the hook that was previously returned by one of the C functions + +=back + + +This function is used to removed a hook previously added with one of +the C functions + +It returns the data that was passed to the C function when +the hook was added + + +=head3 C + +=over 3 + +=item * +C<$text> - the text to print + +=item * +C<\@lines> - array reference containing lines of text to be printed + all the elements will be joined together before printing + +=item * +C<$channel> - channel or tab with the given name where C<$text> + will be printed + +=item * +C<$server> - specifies that the text will be printed in a channel or tab + that is associated with C<$server> + +=back + +The first argument can either be a string or an array reference of strings. +Either or both of C<$channel> and C<$server> can be undef. + +If called as C, it will always return true. +If called with either the channel or the channel and the server +specified then it will return true if a context is found and +false otherwise. The text will not be printed if the context +is not found. The meaning of setting C<$channel> or C<$server> to +undef is the same as +L. + + +=head3 C + +=over 3 + +=item * +C<$format> - a format string, see "perldoc -f L" for further detail + +=item * +LIST - list of values for the format fields + +=back + +=head3 C + +=over 3 + +=item * +C<$command> - the command to execute, without the leading / + +=item * +C<\@commands> - array reference containing a list of commands to execute + +=item * +C<$channel> - channel or tab with the given name where C<$command> will be executed + +=item * +C<$server> - specifies that the command will be executed in a channel or tab that is associated with C<$server> + +=back + +The first argument can either be a string or an array reference of strings. +Either or both of C<$channel> and C<$server> can be undef. + +If called as C, it will always return true. +If called with either the channel or the channel and the server +specified then it will return true if a context is found and false +otherwise. The command will not be executed if the context is not found. +The meaning of setting C<$channel> or C<$server> to undef is the same +as find_context. + + +=head3 C + +=over 3 + +=item * +C<$format> - a format string, see "perldoc -f L" for further detail + +=item * +LIST - list of values for the format fields + +=back + +=head3 C + +=over 3 + +=item * +C<$channel> - name of a channel + +=item * +C<$server> - name of a server + +=back + +Either or both of C<$channel> and $server can be undef. Calling +C is the same as calling +C and +C is +the same as C. + +If C<$server> is undef, find any channel named $channel. +If C<$channel> is undef, find the front most window +or tab named C<$server>.If both $channel and +C<$server> are undef, find the currently focused tab or window. + +Return the context found for one of the above situations or undef if such +a context cannot be found. + + +=head3 C + +=over 3 + +=back + +Returns the current context. + +=head3 C + +=over 3 + +=item * +C<$context> - context value as returned from L,L or one + of the fields in the list of hashrefs returned by list_get + +=item * +C<$channel> - name of a channel you want to switch context to + +=item * +C<$server> - name of a server you want to switch context to + +=back + +See L for more details on C<$channel> and C<$server>. + +Returns true on success, false on failure + +=head3 C + +=over 3 + +=item * +C<$id> - one of the following case sensitive values + +=back + +=begin html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ID Return value
    away away reason or undef if you are not away
    channel current channel name
    charset character-set used in the current context
    event_text <Event Name> text event format string for <Event name>
    + Example: +
    + my $channel_msg_format = Xchat::get_info( "event_text Channel Message" ); +
    +
    host real hostname of the current server
    id connection id
    inputbox contents of the inputbox
    libdirfsthe system wide directory where xchat will look for plugins. + this string is in the same encoding as the local file system
    modes the current channels modes or undef if not known
    network current network name or undef
    nick current nick
    nickserv nickserv password for this network or undef
    server current server name
    + (what the server claims to be) undef if not connected +
    state_cursorcurrent inputbox cursor position in characters
    topic current channel topic
    version xchat version number
    win_statusstatus of the xchat window, possible values are "active", "hidden" + and "normal"
    win_ptr native window pointer, GtkWindow * on Unix, HWND on Win32.
    + On Unix if you have the Glib module installed you can use my $window = Glib::Object->new_from_pointer( Xchat::get_info( "win_ptr" ) ); to get a Gtk2::Window object.
    + Additionally when you have detached tabs, each of the windows will return a different win_ptr for the different Gtk2::Window objects.
    + See char_count.pl for a longer example of a script that uses this to show how many characters you currently have in your input box. +
    xchatdir xchat config directory encoded in UTF-8
    + examples:
    + /home/user/.xchat2
    + C:\Documents and Settings\user\Application Data\X-Chat 2 +
    xchatdirfs same as xchatdir except encoded in the locale file system encoding
    + +

    This function is used to retrieve certain information about the current +context.

    + +=end html + +=head3 C + +=over 3 + +=item * +C<$name> - name of a X-Chat setting (available through the /set command) + +=back + +This function provides a way to retrieve X-Chat's setting information. + +Returns C if there is no setting called called C<$name>. + + +=head3 C + +=over 3 + +=item * +C<$event> - name from the Event column in Settings-EAdvanced-EText Events + +=item * +LIST - this depends on the Description column on the bottom of Settings-EAdvanced-EText Events + +=back + +This functions is used to generate one of the events listed under +Settings-EAdvanced-EText Events + +Note: when using this function you MUST return Xchat::EAT_ALL otherwise you will end up with duplicate events. +One is the original and the second is the one you emit. + +Returns true on success, false on failure + +=head3 C + +=over 3 + +=item * +C<$target> - a single nick to set the mode on + +=item * +C<\@targets> - an array reference of the nicks to set the mode on + +=item * +C<$sign> - the mode sign, either '+' or '-' + +=item * +C<$mode> - the mode character such as 'o' and 'v', this can only be one character long + +=item * +C<$modes_per_line> - an optional argument maximum number of modes to send per at once, pass 0 use the current server's maximum (default) + +=back + +Send multiple mode changes for the current channel. It may send multiple MODE lines if the request doesn't fit on one. + +Example: + +=begin html +<
    + +use strict; +use warning; +use Xchat qw(:all); + +hook_command( "MODES", sub { + my (undef, $who, $sign, $mode) = @{$_[0]}; + + my @targets = split /,/, $who; + if( @targets > 1 ) { + send_modes( \@targets, $sign, $mode, 1 ); + } else { + send_modes( $who, $sign, $mode ); + } + + return EAT_XCHAT; +}); + + +
    + +=end html + +=head3 C + +=over 3 + +=item * +C<$nick1, $nick2> - the two nicks or channel names that are to be compared + +=back + +The comparsion is based on the current server. Either a RFC1459 compliant +string compare or plain ascii will be using depending on the server. The +comparison is case insensitive. + +Returns a number less than, equal to or greater than zero if +C<$nick1> is +found respectively, to be less than, to match, or be greater than +C<$nick2>. + + +=head3 C + +=over 3 + +=item * +C<$name> - name of the list, one of the following: +"channels", "dcc", "ignore", "notify", "users" + +=back + +This function will return a list of hash references. The hash references +will have different keys depend on the list. An empty list is returned +if there is no such list. + +=begin html + +

    "channels" - list of channels, querys and their server

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Description
    channel tab name
    chantypeschannel types supported by the server, typically "#&"
    context can be used with set_context
    flags Server Bits:
    + 0 - Connected
    + 1 - Connecting
    + 2 - Away
    + 3 - EndOfMotd(Login complete)
    + 4 - Has WHOX
    + 5 - Has IDMSG (FreeNode)
    +
    +

    The following correspond to the /chanopt command

    + 6 - Hide Join/Part Message (text_hidejoinpart)
    + 7 - unused (was for color paste)
    + 8 - Beep on message (alert_beep)
    + 9 - Blink Tray (alert_tray)
    + 10 - Blink Task Bar (alert_taskbar)
    +

    Example of checking if the current context has Hide Join/Part messages set:

    +
    + +if( Xchat::context_info->{flags} & (1 << 6) ) { + Xchat::print( "Hide Join/Part messages is enabled" ); +} + +
    + +
    id Unique server ID
    laglag in milliseconds
    maxmodes Maximum modes per line
    network network name to which this channel belongs
    nickprefixes Nickname prefixes e.g. "+@"
    nickmodes Nickname mode chars e.g. "vo"
    queuenumber of bytes in the send queue
    server server name to which this channel belongs
    type the type of this context
    + 1 - server
    + 2 - channel
    + 3 - dialog
    +
    users Number of users in this channel
    + +

    "dcc" - list of DCC file transfers

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Value
    address32 address of the remote user(ipv4 address)
    cps bytes per second(speed)
    destfile destination full pathname
    file file name
    nicknick of the person this DCC connection is connected to
    port TCP port number
    pos bytes sent/received
    poshigh bytes sent/received, high order 32 bits
    resume point at which this file was resumed
    + (zero if it was not resumed) +
    resumehigh point at which this file was resumed, high order 32 bits
    +
    size file size in bytes low order 32 bits
    sizehigh file size in bytes, high order 32 bits (when the files is > 4GB)
    status DCC Status:
    + 0 - queued
    + 1 - active
    + 2 - failed
    + 3 - done
    + 4 - connecting
    + 5 - aborted +
    type DCC Type:
    + 0 - send
    + 1 - receive
    + 2 - chatrecv
    + 3 - chatsend +
    + +

    "ignore" - current ignore list

    + + + + + + + + + + + + + + +
    Key Value
    mask ignore mask. e.g: *!*@*.aol.com
    flags Bit field of flags.
    + 0 - private
    + 1 - notice
    + 2 - channel
    + 3 - ctcp
    + 4 - invite
    + 5 - unignore
    + 6 - nosave
    + 7 - dcc
    +
    + +

    "notify" - list of people on notify

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Value
    networkscomma separated list of networks where you will be notfified about this user's online/offline status or undef if you will be notificed on every network you are connected to
    nick nickname
    flags 0 = is online
    on time when user came online
    off time when user went offline
    seen time when user was last verified still online
    + +

    the values indexed by on, off and seen can be passed to localtime +and gmtime, see perldoc -f localtime and perldoc -f gmtime for more +detail

    + +

    "users" - list of users in the current channel

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Value
    away away status(boolean)
    lasttalklast time a user was seen talking, this is the an epoch time(number of seconds since a certain date, that date depends on the OS)
    nick nick name
    hosthost name in the form: user@host or undef if not known
    prefix prefix character, .e.g: @ or +
    realnameReal name or undef
    selectedselected status in the user list, only works when retrieving the user list of the focused tab. You can use the /USELECT command to select the nicks
    + +

    "networks" - list of networks and the associated settings from network list

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Value
    autojoins An object with the following methods:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    MethodDescription
    channels()returns a list of this networks' autojoin channels in list context, a count of the number autojoin channels in scalar context
    keys()returns a list of the keys to go with the channels, the order is the same as the channels, if a channel doesn't have a key, '' will be returned in it's place
    pairs()a combination of channels() and keys(), returns a list of (channels, keys) pairs. This can be assigned to a hash for a mapping from channel to key.
    as_hash()return the pairs as a hash reference
    as_string()the original string that was used to construct this autojoin object, this can be used with the JOIN command to join all the channels in the autojoin list
    as_array()return an array reference of hash references consisting of the keys "channel" and "key"
    as_bool()returns true if the network has autojoins and false otherwise
    +
    connect_commands An array reference containing the connect commands for a network. An empty array if there aren't any
    encoding the encoding for the network
    flags + a hash reference corresponding to the checkboxes in the network edit window + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    allow_invalidtrue if "Accept invalid SSL certificate" is checked
    autoconnecttrue if "Auto connect to this network at startup" is checked
    cycletrue if "Connect to selected server only" is NOT checked
    use_globaltrue if "Use global user information" is checked
    use_proxytrue if "Bypass proxy server" is NOT checked
    use_ssltrue if "Use SSL for all the servers on this network" is checked
    +
    irc_nick1Corresponds with the "Nick name" field in the network edit window
    irc_nick2Corresponds with the "Second choice" field in the network edit window
    irc_real_nameCorresponds with the "Real name" field in the network edit window
    irc_user_nameCorresponds with the "User name" field in the network edit window
    networkName of the network
    nickserv_passwordCorresponds with the "Nickserv password" field in the network edit window
    selectedIndex into the list of servers in the "servers" key, this is used if the "cycle" flag is false
    server_passwordCorresponds with the "Server password" field in the network edit window
    serversAn array reference of hash references with a "host" and "port" key. If a port is not specified then 6667 will be used.
    + +=end html + +=head3 C + +=over 3 + +=item * +C<$nick> - the nick to look for, if this is not given your own nick will be + used as default + +=back + +This function is mainly intended to be used as a shortcut for when you need +to retrieve some information about only one user in a channel. Otherwise it +is better to use L. +If C<$nick> is found a hash reference containing the same keys as those in the +"users" list of L is returned otherwise undef is returned. +Since it relies on L this function can only be used in a +channel context. + +=head3 C + +=over 3 + +=item * +C<$context> - context returned from L, L and L, this is the context that you want infomation about. If this is omitted, it will default to current context. + +=back + +This function will return the information normally retrieved with L, except this is for the context that is passed in. The information will be returned in the form of a hash. The keys of the hash are the C<$id> you would normally supply to L as well as all the keys that are valid for the items in the "channels" list from L. Use of this function is more efficient than calling get_list( "channels" ) and searching through the result. + +=begin html + +

    Example:

    +
    +use strict; +use warnings; +use Xchat qw(:all); # imports all the functions documented on this page + +register( "User Count", "0.1", + "Print out the number of users on the current channel" ); + +hook_command( "UCOUNT", \&display_count ); + +sub display_count { + prnt "There are " . context_info()->{users} . " users in this channel."; + return EAT_XCHAT; +} +
    + +=end html + +=head3 C + +=over 3 + +=item * +C<$string> - string to remove codes from + +=back + +This function will remove bold, color, beep, reset, reverse and underline codes from C<$string>. It will also remove ANSI escape codes which might get used by certain terminal based clients. If it is called in void context C<$string> will be modified otherwise a modified copy of C<$string> is returned. + +=head2 Examples + +=head3 Asynchronous DNS resolution with hook_fd + +=begin html + +
    + +use strict; +use warnings; +use Xchat qw(:all); +use Net::DNS; + +hook_command( "BGDNS", sub { + my $host = $_[0][1]; + my $resolver = Net::DNS::Resolver->new; + my $sock = $resolver->bgsend( $host ); + + hook_fd( $sock, sub { + my $ready_sock = $_[0]; + my $packet = $resolver->bgread( $ready_sock ); + + if( $packet->authority && (my @answers = $packet->answer ) ) { + + if( @answers ) { + prnt "$host:"; + my $padding = " " x (length( $host ) + 2); + for my $answer ( @answers ) { + prnt $padding . $answer->rdatastr . ' ' . $answer->type; + } + } + } else { + prnt "Unable to resolve $host"; + } + + return REMOVE; + }, + { + flags => FD_READ, + }); + + return EAT_XCHAT; +}); + +
    + +=end html + +=head2 Contact Information + +Contact Lian Wan Situ at Eatmcmnky [at] yahoo.comE for questions, comments and +corrections about this page or the Perl plugin itself. You can also find me +in #xchat on FreeNode under the nick Khisanth. diff --git a/plugins/perl/lib/Xchat/Embed.pm b/plugins/perl/lib/Xchat/Embed.pm new file mode 100644 index 00000000..dffbaf5e --- /dev/null +++ b/plugins/perl/lib/Xchat/Embed.pm @@ -0,0 +1,253 @@ +package Xchat::Embed; +use strict; +use warnings; +# list of loaded scripts keyed by their package names +our %scripts; + +sub load { + my $file = expand_homedir( shift @_ ); + my $package = file2pkg( $file ); + + if( exists $scripts{$package} ) { + my $pkg_info = pkg_info( $package ); + my $filename = File::Basename::basename( $pkg_info->{filename} ); + Xchat::printf( + qq{'%s' already loaded from '%s'.\n}, + $filename, $pkg_info->{filename} + ); + Xchat::print( + 'If this is a different script then it rename and try '. + 'loading it again.' + ); + return 2; + } + + if( open my $source_handle, $file ) { + my $source = do {local $/; <$source_handle>}; + close $source_handle; + # we shouldn't care about things after __END__ + $source =~ s/^__END__.*//ms; + + if( + my @replacements = $source =~ + m/^\s*package ((?:[^\W:]+(?:::)?)+)\s*?;/mg + ) { + + if ( @replacements > 1 ) { + Xchat::print( + "Too many package defintions, only 1 is allowed\n" + ); + return 1; + } + + my $original_package = shift @replacements; + + # remove original package declaration + $source =~ s/^(package $original_package\s*;)/#$1/m; + + # fixes things up for code calling subs with fully qualified names + $source =~ s/${original_package}:://g; + } + + # this must come before the eval or the filename will not be found in + # Xchat::register + $scripts{$package}{filename} = $file; + $scripts{$package}{loaded_at} = Time::HiRes::time(); + + my $full_path = File::Spec->rel2abs( $file ); + $source =~ s/^/#line 1 "$full_path"\n\x7Bpackage $package;/; + + # make sure we add the closing } even if the last line is a comment + if( $source =~ /^#.*\Z/m ) { + $source =~ s/^(?=#.*\Z)/\x7D/m; + } else { + $source =~ s/\Z/\x7D/; + } + + _do_eval( $source ); + + unless( exists $scripts{$package}{gui_entry} ) { + $scripts{$package}{gui_entry} = + Xchat::Internal::register( + "", "unknown", "", $file + ); + } + + if( $@ ) { + # something went wrong + $@ =~ s/\(eval \d+\)/$file/g; + Xchat::print( "Error loading '$file':\n$@\n" ); + # make sure the script list doesn't contain false information + unload( $scripts{$package}{filename} ); + return 1; + } + } else { + Xchat::print( "Error opening '$file': $!\n" ); + return 2; + } + + return 0; +} + +sub _do_eval { + no strict; + no warnings; + eval $_[0]; +} + +sub unload { + my $file = shift @_; + my $package = file2pkg( $file ); + my $pkg_info = pkg_info( $package ); + + if( $pkg_info ) { + # take care of the shutdown callback + if( exists $pkg_info->{shutdown} ) { + # allow incorrectly written scripts to be unloaded + eval { + if( ref $pkg_info->{shutdown} eq 'CODE' ) { + $pkg_info->{shutdown}->(); + } elsif ( $pkg_info->{shutdown} ) { + no strict 'refs'; + &{$pkg_info->{shutdown}}; + } + }; + } + + if( exists $pkg_info->{hooks} ) { + for my $hook ( @{$pkg_info->{hooks}} ) { + Xchat::unhook( $hook, $package ); + } + } + + + if( exists $pkg_info->{gui_entry} ) { + plugingui_remove( $pkg_info->{gui_entry} ); + } + + Symbol::delete_package( $package ); + delete $scripts{$package}; + return Xchat::EAT_ALL; + } else { + Xchat::print( qq{"$file" is not loaded.\n} ); + return Xchat::EAT_NONE; + } +} + +sub unload_all { + for my $package ( keys %scripts ) { + unload( $scripts{$package}->{filename} ); + } + + return Xchat::EAT_ALL; +} + +sub reload { + my $file = shift @_; + my $package = file2pkg( $file ); + my $pkg_info = pkg_info( $package ); + my $fullpath = $file; + + if( $pkg_info ) { + $fullpath = $pkg_info->{filename}; + unload( $file ); + } + + load( $fullpath ); + return Xchat::EAT_ALL; +} + +sub reload_all { + my @dirs = Xchat::get_info( "xchatdirfs" ) || Xchat::get_info( "xchatdir" ); + push @dirs, File::Spec->catdir( $dirs[0], "plugins" ); + for my $dir ( @dirs ) { + my $auto_load_glob = File::Spec->catfile( $dir, "*.pl" ); + my @scripts = map { $_->{filename} } + sort { $a->{loaded_at} <=> $b->{loaded_at} } values %scripts; + push @scripts, File::Glob::bsd_glob( $auto_load_glob ); + + my %seen; + @scripts = grep { !$seen{ $_ }++ } @scripts; + + unload_all(); + for my $script ( @scripts ) { + if( !pkg_info( file2pkg( $script ) ) ) { + load( $script ); + } + } + } +} + +sub expand_homedir { + my $file = shift @_; + + if ( $^O eq "MSWin32" ) { + $file =~ s/^~/$ENV{USERPROFILE}/; + } else { + $file =~ s{^~}{ + (getpwuid($>))[7] || $ENV{HOME} || $ENV{LOGDIR} + }ex; + } + return $file; +} + +sub file2pkg { + my $string = File::Basename::basename( shift @_ ); + $string =~ s/\.pl$//i; + $string =~ s|([^A-Za-z0-9/])|'_'.unpack("H*",$1)|eg; + return "Xchat::Script::" . $string; +} + +sub pkg_info { + my $package = shift @_; + return $scripts{$package}; +} + +sub find_external_pkg { + my $level = 1; + + while( my @frame = caller( $level ) ) { + return @frame if $frame[0] !~ /^Xchat/; + $level++; + } + +} + +sub find_pkg { + my $level = 1; + + while( my ($package, $file, $line) = caller( $level ) ) { + return $package if $package =~ /^Xchat::Script::/; + $level++; + } + + my @frame = find_external_pkg(); + my $location; + + if( $frame[0] or $frame[1] ) { + $location = $frame[1] ? $frame[1] : "package $frame[0]"; + $location .= " line $frame[2]"; + } else { + $location = "unknown location"; + } + + die "Unable to determine which script this hook belongs to. at $location\n"; + +} + +sub fix_callback { + my ($package, $callback) = @_; + + unless( ref $callback ) { + # change the package to the correct one in case it was hardcoded + $callback =~ s/^.*:://; + $callback = qq[${package}::$callback]; + + no strict 'subs'; + $callback = \&{$callback}; + } + + return $callback; +} + +1 diff --git a/plugins/perl/lib/Xchat/List/Network.pm b/plugins/perl/lib/Xchat/List/Network.pm new file mode 100644 index 00000000..da2f52dd --- /dev/null +++ b/plugins/perl/lib/Xchat/List/Network.pm @@ -0,0 +1,32 @@ +package Xchat::List::Network; +use strict; +use warnings; +use Storable qw(dclone); +my $last_modified; +my @servers; + +sub get { + my $server_file = Xchat::get_info( "xchatdirfs" ) . "/servlist_.conf"; + + # recreate the list only if the server list file has changed + if( -f $server_file && + (!defined $last_modified || $last_modified != -M $server_file ) ) { + $last_modified = -M _; + + if( open my $fh, "<", $server_file ) { + local $/ = "\n\n"; + while( my $record = <$fh> ) { + chomp $record; + next if $record =~ /^v=/; # skip the version line + push @servers, Xchat::List::Network::Entry::parse( $record ); + } + } else { + warn "Unable to open '$server_file': $!"; + } + } + + my $clone = dclone( \@servers ); + return @$clone; +} + +1 diff --git a/plugins/perl/lib/Xchat/List/Network/AutoJoin.pm b/plugins/perl/lib/Xchat/List/Network/AutoJoin.pm new file mode 100644 index 00000000..16036a9d --- /dev/null +++ b/plugins/perl/lib/Xchat/List/Network/AutoJoin.pm @@ -0,0 +1,82 @@ +package Xchat::List::Network::AutoJoin; +use strict; +use warnings; + +use overload +# '%{}' => \&as_hash, +# '@{}' => \&as_array, + '""' => 'as_string', + '0+' => 'as_bool'; + +sub new { + my $class = shift; + my $line = shift; + + my @autojoins; + + if ( $line ) { + my ( $channels, $keys ) = split / /, $line, 2; + my @channels = split /,/, $channels; + my @keys = split /,/, ($keys || ''); + + for my $channel ( @channels ) { + my $key = shift @keys; + $key = '' unless defined $key; + + push @autojoins, { + channel => $channel, + key => $key, + }; + } + } + return bless \@autojoins, $class; +} + +sub channels { + my $self = shift; + + if( wantarray ) { + return map { $_->{channel} } @$self; + } else { + return scalar @$self; + } +} + +sub keys { + my $self = shift; + return map { $_->{key} } @$self ; + +} + +sub pairs { + my $self = shift; + + my @channels = $self->channels; + my @keys = $self->keys; + + my @pairs = map { $_ => shift @keys } @channels; +} + +sub as_hash { + my $self = shift; + return +{ $self->pairs }; +} + +sub as_string { + my $self = shift; + return join " ", + join( ",", $self->channels ), + join( ",", $self->keys ); +} + +sub as_array { + my $self = shift; + return [ map { \%$_ } @$self ]; +} + +sub as_bool { + my $self = shift; + return $self->channels ? 1 : ""; +} + +1 diff --git a/plugins/perl/lib/Xchat/List/Network/Entry.pm b/plugins/perl/lib/Xchat/List/Network/Entry.pm new file mode 100644 index 00000000..e40b48bd --- /dev/null +++ b/plugins/perl/lib/Xchat/List/Network/Entry.pm @@ -0,0 +1,105 @@ +package Xchat::List::Network::Entry; +use strict; +use warnings; + +my %key_for = ( + I => "irc_nick1", + i => "irc_nick2", + U => "irc_user_name", + R => "irc_real_name", + P => "server_password", + B => "nickserv_password", + N => "network", + D => "selected", + E => "encoding", +); +my $letter_key_re = join "|", keys %key_for; + +sub parse { + my $data = shift; + my $entry = { + irc_nick1 => undef, + irc_nick2 => undef, + irc_user_name => undef, + irc_real_name => undef, + server_password => undef, + + # the order of the channels need to be maintained + # list of { channel => .., key => ... } + autojoins => Xchat::List::Network::AutoJoin->new( '' ), + connect_commands => [], + flags => {}, + selected => undef, + encoding => undef, + servers => [], + nickserv_password => undef, + network => undef, + }; + + my @fields = split /\n/, $data; + chomp @fields; + + for my $field ( @fields ) { + SWITCH: for ( $field ) { + /^($letter_key_re)=(.*)/ && do { + $entry->{ $key_for{ $1 } } = $2; + last SWITCH; + }; + + /^J.(.*)/ && do { + $entry->{ autojoins } = + Xchat::List::Network::AutoJoin->new( $1 ); + }; + + /^F.(.*)/ && do { + $entry->{ flags } = parse_flags( $1 ); + }; + + /^S.(.+)/ && do { + push @{$entry->{servers}}, parse_server( $1 ); + }; + + /^C.(.+)/ && do { + push @{$entry->{connect_commands}}, $1; + }; + } + } + +# $entry->{ autojoins } = $entry->{ autojoin_channels }; + return $entry; +} + +sub parse_flags { + my $value = shift || 0; + my %flags; + + $flags{ "cycle" } = $value & 1 ? 1 : 0; + $flags{ "use_global" } = $value & 2 ? 1 : 0; + $flags{ "use_ssl" } = $value & 4 ? 1 : 0; + $flags{ "autoconnect" } = $value & 8 ? 1 : 0; + $flags{ "use_proxy" } = $value & 16 ? 1 : 0; + $flags{ "allow_invalid" } = $value & 32 ? 1 : 0; + + return \%flags; +} + +sub parse_server { + my $data = shift; + if( $data ) { + my ($host, $port) = split /\//, $data; + unless( $port ) { + my @parts = split /:/, $host; + + # if more than 2 then we are probably dealing with a IPv6 address + # if less than 2 then no port was specified + if( @parts == 2 ) { + $port = $parts[1]; + } + } + + $port ||= 6667; + return { host => $host, port => $port }; + } +} + +1 diff --git a/plugins/perl/perl.c b/plugins/perl/perl.c new file mode 100644 index 00000000..a29ce65a --- /dev/null +++ b/plugins/perl/perl.c @@ -0,0 +1,1522 @@ +/* X-Chat 2.0 PERL Plugin + * Copyright (C) 1998-2002 Peter Zelezny. + * + * 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 +#include +#include +#include +#include +#include +#include +#ifdef ENABLE_NLS +#include +#endif +#ifdef WIN32 +#include +#endif + +#undef PACKAGE +#include "../../config.h" /* for #define OLD_PERL */ +#include "xchat-plugin.h" + +static xchat_plugin *ph; /* plugin handle */ + +static int perl_load_file (char *script_name); + +#ifdef WIN32 +/* STRINGIFY is from perl's CORE/config.h */ +#ifndef PERL_REQUIRED_VERSION + #define PERL_REQUIRED_VERSION STRINGIFY(PERL_REVISION) "." STRINGIFY(PERL_VERSION) +#endif + +#ifndef PERL_DLL + #define PERL_DLL "perl" STRINGIFY(PERL_REVISION) STRINGIFY(PERL_VERSION) ".dll" +#endif + +static DWORD +child (char *str) +{ + MessageBoxA (0, str, "Perl DLL Error", + MB_OK | MB_ICONHAND | MB_SETFOREGROUND | MB_TASKMODAL); + return 0; +} + +static void +thread_mbox (char *str) +{ + DWORD tid; + + CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) child, + str, 0, &tid)); +} + +#endif + +/* leave this before XSUB.h, to avoid readdir() being redefined */ + +static void +perl_auto_load_from_path (const char *path) +{ + DIR *dir; + struct dirent *ent; + + dir = opendir (path); + if (dir) { + while ((ent = readdir (dir))) { + int len = strlen (ent->d_name); + if (len > 3 && strcasecmp (".pl", ent->d_name + len - 3) == 0) { + char *file = malloc (len + strlen (path) + 2); + sprintf (file, "%s/%s", path, ent->d_name); + perl_load_file (file); + free (file); + } + } + closedir (dir); + } +} + +static int +perl_auto_load (void *unused) +{ + const char *xdir; + char *sub_dir; +#ifdef WIN32 + int copied = 0; + char *slash = NULL; +#endif + + /* get the dir in local filesystem encoding (what opendir() expects!) */ + xdir = xchat_get_info (ph, "xchatdirfs"); + if (!xdir) /* xchatdirfs is new for 2.0.9, will fail on older */ + xdir = xchat_get_info (ph, "xchatdir"); + + /* autoload from ~/.xchat2/ or ${APPDATA}\X-Chat 2\ on win32 */ + perl_auto_load_from_path (xdir); + + sub_dir = malloc (strlen (xdir) + 9); + strcpy (sub_dir, xdir); + strcat (sub_dir, "/plugins"); + perl_auto_load_from_path (sub_dir); + free (sub_dir); + +#ifdef WIN32 + /* autoload from C:\program files\xchat\plugins\ */ + sub_dir = malloc (1025 + 9); + copied = GetModuleFileName( 0, sub_dir, 1024 ); + sub_dir[copied] = '\0'; + slash = strrchr( sub_dir, '\\' ); + if( slash != NULL ) { + *slash = '\0'; + } + perl_auto_load_from_path ( strncat (sub_dir, "\\plugins", 9)); + free (sub_dir); +#endif + return 0; +} + +#include +#define WIN32IOP_H +#include +#include + +typedef struct +{ + SV *callback; + SV *userdata; + xchat_hook *hook; /* required for timers */ + xchat_context *ctx; /* allow timers to remember their context */ + SV *package; /* need to track the package name when removing hooks + by returning REMOVE + */ + unsigned int depth; +} HookData; + +static PerlInterpreter *my_perl = NULL; +extern void boot_DynaLoader (pTHX_ CV * cv); + +/* + this is used for autoload and shutdown callbacks +*/ +static int +execute_perl (SV * function, char *args) +{ + + int count, ret_value = 1; + + dSP; + ENTER; + SAVETMPS; + + PUSHMARK (SP); + XPUSHs (sv_2mortal (newSVpv (args, 0))); + PUTBACK; + + count = call_sv (function, G_EVAL | G_SCALAR); + SPAGAIN; + if (SvTRUE (ERRSV)) { + xchat_printf(ph, "Perl error: %s\n", SvPV_nolen (ERRSV)); + if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ + } else if (count != 1) { + xchat_printf (ph, "Perl error: expected 1 value from %s, " + "got: %d\n", SvPV_nolen (function), count); + } else { + ret_value = POPi; + } + PUTBACK; + FREETMPS; + LEAVE; + + return ret_value; +} + +static char * +get_filename (char *word[], char *word_eol[]) +{ + int len; + char *file; + + len = strlen (word[2]); + + /* if called as /load "filename.pl" the only difference between word and + * word_eol will be the two quotes + */ + + if (strchr (word[2], ' ') != NULL + || (strlen (word_eol[2]) - strlen(word[2])) == 2 ) + { + file = word[2]; + } else { + file = word_eol[2]; + } + + len = strlen (file); + + if (len > 3 && strncasecmp (".pl", file + len - 3, 3) == 0) { + return file; + } + + return NULL; +} + +static SV * +list_item_to_sv ( xchat_list *list, const char *const *fields ) +{ + HV *hash = newHV(); + SV *field_value; + const char *field; + int field_index = 0; + const char *field_name; + int name_len; + + while (fields[field_index] != NULL) { + field_name = fields[field_index] + 1; + name_len = strlen (field_name); + + switch (fields[field_index][0]) { + case 's': + field = xchat_list_str (ph, list, field_name); + if (field != NULL) { + field_value = newSVpvn (field, strlen (field)); + } else { + field_value = &PL_sv_undef; + } + break; + case 'p': + field_value = newSViv (PTR2IV (xchat_list_str (ph, list, + field_name))); + break; + case 'i': + field_value = newSVuv (xchat_list_int (ph, list, field_name)); + break; + case 't': + field_value = newSVnv (xchat_list_time (ph, list, field_name)); + break; + default: + field_value = &PL_sv_undef; + } + hv_store (hash, field_name, name_len, field_value, 0); + field_index++; + } + return sv_2mortal (newRV_noinc ((SV *) hash)); +} + +static AV * +array2av (char *array[]) +{ + int count = 0; + SV *temp = NULL; + AV *av = newAV(); + sv_2mortal ((SV *)av); + + for ( + count = 1; + count < 32 && array[count] != NULL && array[count][0] != 0; + count++ + ) { + temp = newSVpv (array[count], 0); + SvUTF8_on (temp); + av_push (av, temp); + } + + return av; +} + +static int +fd_cb (int fd, int flags, void *userdata) +{ + HookData *data = (HookData *) userdata; + int retVal = 0; + int count = 0; + + dSP; + ENTER; + SAVETMPS; + + PUSHMARK (SP); + XPUSHs (data->userdata); + PUTBACK; + + count = call_sv (data->callback, G_EVAL); + SPAGAIN; + + if (SvTRUE (ERRSV)) { + xchat_printf (ph, "Error in fd callback %s", SvPV_nolen (ERRSV)); + if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ + retVal = XCHAT_EAT_ALL; + } else { + if (count != 1) { + xchat_print (ph, "Fd handler should only return 1 value."); + retVal = XCHAT_EAT_NONE; + } else { + retVal = POPi; + if (retVal == 0) { + /* if 0 is returned, the fd is going to get unhooked */ + PUSHMARK (SP); + XPUSHs (sv_2mortal (newSViv (PTR2IV (data->hook)))); + PUTBACK; + + call_pv ("Xchat::unhook", G_EVAL); + SPAGAIN; + + SvREFCNT_dec (data->callback); + + if (data->userdata) { + SvREFCNT_dec (data->userdata); + } + free (data); + } + } + + } + + PUTBACK; + FREETMPS; + LEAVE; + + return retVal; +} + +static int +timer_cb (void *userdata) +{ + HookData *data = (HookData *) userdata; + int retVal = 0; + int count = 0; + + dSP; + ENTER; + SAVETMPS; + + PUSHMARK (SP); + XPUSHs (data->userdata); + PUTBACK; + + if (data->ctx) { + xchat_set_context (ph, data->ctx); + } + count = call_sv (data->callback, G_EVAL); + SPAGAIN; + + if (SvTRUE (ERRSV)) { + xchat_printf (ph, "Error in timer callback %s", SvPV_nolen (ERRSV)); + if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ + retVal = XCHAT_EAT_ALL; + } else { + if (count != 1) { + xchat_print (ph, "Timer handler should only return 1 value."); + retVal = XCHAT_EAT_NONE; + } else { + retVal = POPi; + if (retVal == 0) { + /* if 0 is return the timer is going to get unhooked */ + PUSHMARK (SP); + XPUSHs (sv_2mortal (newSViv (PTR2IV (data->hook)))); + XPUSHs (sv_mortalcopy (data->package)); + PUTBACK; + + call_pv ("Xchat::unhook", G_EVAL); + SPAGAIN; + } + } + + } + + PUTBACK; + FREETMPS; + LEAVE; + + return retVal; +} + +static int +server_cb (char *word[], char *word_eol[], void *userdata) +{ + HookData *data = (HookData *) userdata; + int retVal = 0; + int count = 0; + + dSP; + ENTER; + SAVETMPS; + + if (data->depth) + return XCHAT_EAT_NONE; + + /* xchat_printf (ph, */ + /* "Recieved %d words in server callback", av_len (wd)); */ + PUSHMARK (SP); + XPUSHs (newRV_noinc ((SV *) array2av (word))); + XPUSHs (newRV_noinc ((SV *) array2av (word_eol))); + XPUSHs (data->userdata); + PUTBACK; + + data->depth++; + count = call_sv (data->callback, G_EVAL); + data->depth--; + SPAGAIN; + if (SvTRUE (ERRSV)) { + xchat_printf (ph, "Error in server callback %s", SvPV_nolen (ERRSV)); + if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ + retVal = XCHAT_EAT_NONE; + } else { + if (count != 1) { + xchat_print (ph, "Server handler should only return 1 value."); + retVal = XCHAT_EAT_NONE; + } else { + retVal = POPi; + } + + } + + PUTBACK; + FREETMPS; + LEAVE; + + return retVal; +} + +static int +command_cb (char *word[], char *word_eol[], void *userdata) +{ + HookData *data = (HookData *) userdata; + int retVal = 0; + int count = 0; + + dSP; + ENTER; + SAVETMPS; + + if (data->depth) + return XCHAT_EAT_NONE; + + /* xchat_printf (ph, "Recieved %d words in command callback", */ + /* av_len (wd)); */ + PUSHMARK (SP); + XPUSHs (newRV_noinc ((SV *) array2av (word))); + XPUSHs (newRV_noinc ((SV *) array2av (word_eol))); + XPUSHs (data->userdata); + PUTBACK; + + data->depth++; + count = call_sv (data->callback, G_EVAL); + data->depth--; + SPAGAIN; + if (SvTRUE (ERRSV)) { + xchat_printf (ph, "Error in command callback %s", SvPV_nolen (ERRSV)); + if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ + retVal = XCHAT_EAT_XCHAT; + } else { + if (count != 1) { + xchat_print (ph, "Command handler should only return 1 value."); + retVal = XCHAT_EAT_NONE; + } else { + retVal = POPi; + } + + } + + PUTBACK; + FREETMPS; + LEAVE; + + return retVal; +} + +static int +print_cb (char *word[], void *userdata) +{ + + HookData *data = (HookData *) userdata; + SV *temp = NULL; + int retVal = 0; + int count = 1; + int last_index = 31; + /* must be initialized after SAVETMPS */ + AV *wd = NULL; + + dSP; + ENTER; + SAVETMPS; + + if (data->depth) + return XCHAT_EAT_NONE; + + wd = newAV (); + sv_2mortal ((SV *) wd); + + /* need to scan backwards to find the index of the last element since some + events such as "DCC Timeout" can have NULL elements in between non NULL + elements */ + + while (last_index >= 0 + && (word[last_index] == NULL || word[last_index][0] == 0)) { + last_index--; + } + + for (count = 1; count <= last_index; count++) { + if (word[count] == NULL) { + av_push (wd, &PL_sv_undef); + } else if (word[count][0] == 0) { + av_push (wd, newSVpvn ("",0)); + } else { + temp = newSVpv (word[count], 0); + SvUTF8_on (temp); + av_push (wd, temp); + } + } + + /*xchat_printf (ph, "Recieved %d words in print callback", av_len (wd)+1); */ + PUSHMARK (SP); + XPUSHs (newRV_noinc ((SV *) wd)); + XPUSHs (data->userdata); + PUTBACK; + + data->depth++; + count = call_sv (data->callback, G_EVAL); + data->depth--; + SPAGAIN; + if (SvTRUE (ERRSV)) { + xchat_printf (ph, "Error in print callback %s", SvPV_nolen (ERRSV)); + if (!SvOK (POPs)) {} /* remove undef from the top of the stack */ + retVal = XCHAT_EAT_NONE; + } else { + if (count != 1) { + xchat_print (ph, "Print handler should only return 1 value."); + retVal = XCHAT_EAT_NONE; + } else { + retVal = POPi; + } + + } + + PUTBACK; + FREETMPS; + LEAVE; + + return retVal; +} + +/* custom IRC perl functions for scripting */ + +/* Xchat::Internal::register (scriptname, version, desc, shutdowncallback, filename) + * + */ + +static +XS (XS_Xchat_register) +{ + char *name, *version, *desc, *filename; + void *gui_entry; + dXSARGS; + if (items != 4) { + xchat_printf (ph, + "Usage: Xchat::Internal::register(scriptname, version, desc, filename)"); + } else { + name = SvPV_nolen (ST (0)); + version = SvPV_nolen (ST (1)); + desc = SvPV_nolen (ST (2)); + filename = SvPV_nolen (ST (3)); + + gui_entry = xchat_plugingui_add (ph, filename, name, + desc, version, NULL); + + XSRETURN_IV (PTR2IV (gui_entry)); + + } +} + + +/* Xchat::print(output) */ +static +XS (XS_Xchat_print) +{ + + char *text = NULL; + + dXSARGS; + if (items != 1) { + xchat_print (ph, "Usage: Xchat::Internal::print(text)"); + } else { + text = SvPV_nolen (ST (0)); + xchat_print (ph, text); + } + XSRETURN_EMPTY; +} + +static +XS (XS_Xchat_emit_print) +{ + char *event_name; + int RETVAL; + int count; + + dXSARGS; + if (items < 1) { + xchat_print (ph, "Usage: Xchat::emit_print(event_name, ...)"); + } else { + event_name = (char *) SvPV_nolen (ST (0)); + RETVAL = 0; + + /* we need to figure out the number of defined values passed in */ + for (count = 0; count < items; count++) { + if (!SvOK (ST (count))) { + break; + } + } + + switch (count) { + case 1: + RETVAL = xchat_emit_print (ph, event_name, NULL); + break; + case 2: + RETVAL = xchat_emit_print (ph, event_name, + SvPV_nolen (ST (1)), NULL); + break; + case 3: + RETVAL = xchat_emit_print (ph, event_name, + SvPV_nolen (ST (1)), + SvPV_nolen (ST (2)), NULL); + break; + case 4: + RETVAL = xchat_emit_print (ph, event_name, + SvPV_nolen (ST (1)), + SvPV_nolen (ST (2)), + SvPV_nolen (ST (3)), NULL); + break; + case 5: + RETVAL = xchat_emit_print (ph, event_name, + SvPV_nolen (ST (1)), + SvPV_nolen (ST (2)), + SvPV_nolen (ST (3)), + SvPV_nolen (ST (4)), NULL); + break; + + } + + XSRETURN_IV (RETVAL); + } +} + +static +XS (XS_Xchat_send_modes) +{ + AV *p_targets = NULL; + int modes_per_line = 0; + char sign; + char mode; + int i = 0; + const char **targets; + int target_count = 0; + SV **elem; + + dXSARGS; + if (items < 3 || items > 4) { + xchat_print (ph, + "Usage: Xchat::send_modes( targets, sign, mode, modes_per_line)" + ); + } else { + if (SvROK (ST (0))) { + p_targets = (AV*) SvRV (ST (0)); + target_count = av_len (p_targets) + 1; + targets = malloc (target_count * sizeof (char *)); + for (i = 0; i < target_count; i++ ) { + elem = av_fetch (p_targets, i, 0); + + if (elem != NULL) { + targets[i] = SvPV_nolen (*elem); + } else { + targets[i] = ""; + } + } + } else{ + targets = malloc (sizeof (char *)); + targets[0] = SvPV_nolen (ST (0)); + target_count = 1; + } + + if (target_count == 0) { + XSRETURN_EMPTY; + } + + sign = (SvPV_nolen (ST (1)))[0]; + mode = (SvPV_nolen (ST (2)))[0]; + + if (items == 4 ) { + modes_per_line = (int) SvIV (ST (3)); + } + + xchat_send_modes (ph, targets, target_count, modes_per_line, sign, mode); + free (targets); + } +} +static +XS (XS_Xchat_get_info) +{ + SV *temp = NULL; + dXSARGS; + if (items != 1) { + xchat_print (ph, "Usage: Xchat::get_info(id)"); + } else { + SV *id = ST (0); + const char *RETVAL; + + RETVAL = xchat_get_info (ph, SvPV_nolen (id)); + if (RETVAL == NULL) { + XSRETURN_UNDEF; + } + + if (!strncmp ("win_ptr", SvPV_nolen (id), 7) + || !strncmp ("gtkwin_ptr", SvPV_nolen (id), 10)) + { + XSRETURN_IV (PTR2IV (RETVAL)); + } else { + + if ( + !strncmp ("libdirfs", SvPV_nolen (id), 8) || + !strncmp ("xchatdirfs", SvPV_nolen (id), 10) + ) { + XSRETURN_PV (RETVAL); + } else { + temp = newSVpv (RETVAL, 0); + SvUTF8_on (temp); + PUSHMARK (SP); + XPUSHs (sv_2mortal (temp)); + PUTBACK; + } + } + } +} + +static +XS (XS_Xchat_context_info) +{ + const char *const *fields; + dXSARGS; + + if (items > 0 ) { + xchat_print (ph, "Usage: Xchat::Internal::context_info()"); + } + fields = xchat_list_fields (ph, "channels" ); + XPUSHs (list_item_to_sv (NULL, fields)); + XSRETURN (1); +} + +static +XS (XS_Xchat_get_prefs) +{ + const char *str; + int integer; + SV *temp = NULL; + dXSARGS; + if (items != 1) { + xchat_print (ph, "Usage: Xchat::get_prefs(name)"); + } else { + + + switch (xchat_get_prefs (ph, SvPV_nolen (ST (0)), &str, &integer)) { + case 0: + XSRETURN_UNDEF; + break; + case 1: + temp = newSVpv (str, 0); + SvUTF8_on (temp); + SP -= items; + sp = mark; + XPUSHs (sv_2mortal (temp)); + PUTBACK; + break; + case 2: + XSRETURN_IV (integer); + break; + case 3: + if (integer) { + XSRETURN_YES; + } else { + XSRETURN_NO; + } + } + } +} + +/* Xchat::Internal::hook_server(name, priority, callback, userdata) */ +static +XS (XS_Xchat_hook_server) +{ + + char *name; + int pri; + SV *callback; + SV *userdata; + xchat_hook *hook; + HookData *data; + + dXSARGS; + + if (items != 4) { + xchat_print (ph, + "Usage: Xchat::Internal::hook_server(name, priority, callback, userdata)"); + } else { + name = SvPV_nolen (ST (0)); + pri = (int) SvIV (ST (1)); + callback = ST (2); + userdata = ST (3); + data = NULL; + data = malloc (sizeof (HookData)); + if (data == NULL) { + XSRETURN_UNDEF; + } + + data->callback = sv_mortalcopy (callback); + SvREFCNT_inc (data->callback); + data->userdata = sv_mortalcopy (userdata); + SvREFCNT_inc (data->userdata); + data->depth = 0; + data->package = NULL; + hook = xchat_hook_server (ph, name, pri, server_cb, data); + + XSRETURN_IV (PTR2IV (hook)); + } +} + +/* Xchat::Internal::hook_command(name, priority, callback, help_text, userdata) */ +static +XS (XS_Xchat_hook_command) +{ + char *name; + int pri; + SV *callback; + char *help_text = NULL; + SV *userdata; + xchat_hook *hook; + HookData *data; + + dXSARGS; + + if (items != 5) { + xchat_print (ph, + "Usage: Xchat::Internal::hook_command(name, priority, callback, help_text, userdata)"); + } else { + name = SvPV_nolen (ST (0)); + pri = (int) SvIV (ST (1)); + callback = ST (2); + + /* leave the help text has NULL if the help text is undefined to avoid + * overriding the default help message for builtin commands */ + if (SvOK(ST (3))) { + help_text = SvPV_nolen (ST (3)); + } + + userdata = ST (4); + data = NULL; + + data = malloc (sizeof (HookData)); + if (data == NULL) { + XSRETURN_UNDEF; + } + + data->callback = sv_mortalcopy (callback); + SvREFCNT_inc (data->callback); + data->userdata = sv_mortalcopy (userdata); + SvREFCNT_inc (data->userdata); + data->depth = 0; + data->package = NULL; + hook = xchat_hook_command (ph, name, pri, command_cb, help_text, data); + + XSRETURN_IV (PTR2IV (hook)); + } + +} + +/* Xchat::Internal::hook_print(name, priority, callback, [userdata]) */ +static +XS (XS_Xchat_hook_print) +{ + + char *name; + int pri; + SV *callback; + SV *userdata; + xchat_hook *hook; + HookData *data; + dXSARGS; + if (items != 4) { + xchat_print (ph, + "Usage: Xchat::Internal::hook_print(name, priority, callback, userdata)"); + } else { + name = SvPV_nolen (ST (0)); + pri = (int) SvIV (ST (1)); + callback = ST (2); + data = NULL; + userdata = ST (3); + + data = malloc (sizeof (HookData)); + if (data == NULL) { + XSRETURN_UNDEF; + } + + data->callback = sv_mortalcopy (callback); + SvREFCNT_inc (data->callback); + data->userdata = sv_mortalcopy (userdata); + SvREFCNT_inc (data->userdata); + data->depth = 0; + data->package = NULL; + hook = xchat_hook_print (ph, name, pri, print_cb, data); + + XSRETURN_IV (PTR2IV (hook)); + } +} + +/* Xchat::Internal::hook_timer(timeout, callback, userdata) */ +static +XS (XS_Xchat_hook_timer) +{ + int timeout; + SV *callback; + SV *userdata; + xchat_hook *hook; + SV *package; + HookData *data; + + dXSARGS; + + if (items != 4) { + xchat_print (ph, + "Usage: Xchat::Internal::hook_timer(timeout, callback, userdata, package)"); + } else { + timeout = (int) SvIV (ST (0)); + callback = ST (1); + data = NULL; + userdata = ST (2); + package = ST (3); + + data = malloc (sizeof (HookData)); + if (data == NULL) { + XSRETURN_UNDEF; + } + + data->callback = sv_mortalcopy (callback); + SvREFCNT_inc (data->callback); + data->userdata = sv_mortalcopy (userdata); + SvREFCNT_inc (data->userdata); + data->ctx = xchat_get_context (ph); + data->package = sv_mortalcopy (package); + SvREFCNT_inc (data->package); + hook = xchat_hook_timer (ph, timeout, timer_cb, data); + data->hook = hook; + + XSRETURN_IV (PTR2IV (hook)); + } +} + +/* Xchat::Internal::hook_fd(fd, callback, flags, userdata) */ +static +XS (XS_Xchat_hook_fd) +{ + int fd; + SV *callback; + int flags; + SV *userdata; + xchat_hook *hook; + HookData *data; + + dXSARGS; + + if (items != 4) { + xchat_print (ph, + "Usage: Xchat::Internal::hook_fd(fd, callback, flags, userdata)"); + } else { + fd = (int) SvIV (ST (0)); + callback = ST (1); + flags = (int) SvIV (ST (2)); + userdata = ST (3); + data = NULL; + +#ifdef WIN32 + if ((flags & XCHAT_FD_NOTSOCKET) == 0) { + /* this _get_osfhandle if from win32iop.h in the perl distribution, + * not the one provided by Windows + */ + fd = _get_osfhandle(fd); + if (fd < 0) { + xchat_print(ph, "Invalid file descriptor"); + XSRETURN_UNDEF; + } + } +#endif + + data = malloc (sizeof (HookData)); + if (data == NULL) { + XSRETURN_UNDEF; + } + + data->callback = sv_mortalcopy (callback); + SvREFCNT_inc (data->callback); + data->userdata = sv_mortalcopy (userdata); + SvREFCNT_inc (data->userdata); + data->package = NULL; + hook = xchat_hook_fd (ph, fd, flags, fd_cb, data); + data->hook = hook; + + XSRETURN_IV (PTR2IV (hook)); + } +} + +static +XS (XS_Xchat_unhook) +{ + xchat_hook *hook; + HookData *userdata; + int retCount = 0; + dXSARGS; + if (items != 1) { + xchat_print (ph, "Usage: Xchat::unhook(hook)"); + } else { + hook = INT2PTR (xchat_hook *, SvUV (ST (0))); + userdata = (HookData *) xchat_unhook (ph, hook); + + if (userdata != NULL) { + if (userdata->callback != NULL) { + SvREFCNT_dec (userdata->callback); + } + + if (userdata->userdata != NULL) { + XPUSHs (sv_mortalcopy (userdata->userdata)); + SvREFCNT_dec (userdata->userdata); + retCount = 1; + } + + if (userdata->package != NULL) { + SvREFCNT_dec (userdata->package); + } + free (userdata); + } + XSRETURN (retCount); + } + XSRETURN_EMPTY; +} + +/* Xchat::Internal::command(command) */ +static +XS (XS_Xchat_command) +{ + char *cmd = NULL; + + dXSARGS; + if (items != 1) { + xchat_print (ph, "Usage: Xchat::Internal::command(command)"); + } else { + cmd = SvPV_nolen (ST (0)); + xchat_command (ph, cmd); + + } + XSRETURN_EMPTY; +} + +static +XS (XS_Xchat_find_context) +{ + char *server = NULL; + char *chan = NULL; + xchat_context *RETVAL; + + dXSARGS; + if (items > 2) + xchat_print (ph, "Usage: Xchat::find_context ([channel, [server]])"); + { + + switch (items) { + case 0: /* no server name and no channel name */ + /* nothing to do, server and chan are already NULL */ + break; + case 1: /* channel name only */ + /* change channel value only if it is true or 0 */ + /* otherwise leave it as null */ + if (SvTRUE (ST (0)) || SvNIOK (ST (0))) { + chan = SvPV_nolen (ST (0)); + /* xchat_printf( ph, "XSUB - find_context( %s, NULL )", chan ); */ + } + /* else { xchat_print( ph, "XSUB - find_context( NULL, NULL )" ); } */ + /* chan is already NULL */ + break; + case 2: /* server and channel */ + /* change channel value only if it is true or 0 */ + /* otherwise leave it as NULL */ + if (SvTRUE (ST (0)) || SvNIOK (ST (0))) { + chan = SvPV_nolen (ST (0)); + /* xchat_printf( ph, "XSUB - find_context( %s, NULL )", SvPV_nolen(ST(0) )); */ + } + + /* else { xchat_print( ph, "XSUB - 2 arg NULL chan" ); } */ + /* change server value only if it is true or 0 */ + /* otherwise leave it as NULL */ + if (SvTRUE (ST (1)) || SvNIOK (ST (1))) { + server = SvPV_nolen (ST (1)); + /* xchat_printf( ph, "XSUB - find_context( NULL, %s )", SvPV_nolen(ST(1) )); */ + } + /* else { xchat_print( ph, "XSUB - 2 arg NULL server" ); } */ + break; + } + + RETVAL = xchat_find_context (ph, server, chan); + if (RETVAL != NULL) { + /* xchat_print (ph, "XSUB - context found"); */ + XSRETURN_IV (PTR2IV (RETVAL)); + } else { + /* xchat_print (ph, "XSUB - context not found"); */ + XSRETURN_UNDEF; + } + } +} + +static +XS (XS_Xchat_get_context) +{ + dXSARGS; + if (items != 0) { + xchat_print (ph, "Usage: Xchat::get_context()"); + } else { + XSRETURN_IV (PTR2IV (xchat_get_context (ph))); + } +} + +static +XS (XS_Xchat_set_context) +{ + xchat_context *ctx; + dXSARGS; + if (items != 1) { + xchat_print (ph, "Usage: Xchat::set_context(ctx)"); + } else { + ctx = INT2PTR (xchat_context *, SvUV (ST (0))); + XSRETURN_IV ((IV) xchat_set_context (ph, ctx)); + } +} + +static +XS (XS_Xchat_nickcmp) +{ + dXSARGS; + if (items != 2) { + xchat_print (ph, "Usage: Xchat::nickcmp(s1, s2)"); + } else { + XSRETURN_IV ((IV) xchat_nickcmp (ph, SvPV_nolen (ST (0)), + SvPV_nolen (ST (1)))); + } +} + +static +XS (XS_Xchat_get_list) +{ + SV *name; + xchat_list *list; + const char *const *fields; + int count = 0; /* return value for scalar context */ + dXSARGS; + + if (items != 1) { + xchat_print (ph, "Usage: Xchat::get_list(name)"); + } else { + SP -= items; /*remove the argument list from the stack */ + + name = ST (0); + + list = xchat_list_get (ph, SvPV_nolen (name)); + + if (list == NULL) { + XSRETURN_EMPTY; + } + + if (GIMME_V == G_SCALAR) { + while (xchat_list_next (ph, list)) { + count++; + } + xchat_list_free (ph, list); + XSRETURN_IV ((IV) count); + } + + fields = xchat_list_fields (ph, SvPV_nolen (name)); + while (xchat_list_next (ph, list)) { + XPUSHs (list_item_to_sv (list, fields)); + } + xchat_list_free (ph, list); + + PUTBACK; + return; + } +} + +static +XS (XS_Xchat_Embed_plugingui_remove) +{ + void *gui_entry; + dXSARGS; + if (items != 1) { + xchat_print (ph, "Usage: Xchat::Embed::plugingui_remove(handle)"); + } else { + gui_entry = INT2PTR (void *, SvUV (ST (0))); + xchat_plugingui_remove (ph, gui_entry); + } + XSRETURN_EMPTY; +} + +/* xs_init is the second argument perl_parse. As the name hints, it + initializes XS subroutines (see the perlembed manpage) */ +static void +xs_init (pTHX) +{ + HV *stash; + SV *version; + /* This one allows dynamic loading of perl modules in perl + scripts by the 'use perlmod;' construction */ + newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); + /* load up all the custom IRC perl functions */ + newXS ("Xchat::Internal::register", XS_Xchat_register, __FILE__); + newXS ("Xchat::Internal::hook_server", XS_Xchat_hook_server, __FILE__); + newXS ("Xchat::Internal::hook_command", XS_Xchat_hook_command, __FILE__); + newXS ("Xchat::Internal::hook_print", XS_Xchat_hook_print, __FILE__); + newXS ("Xchat::Internal::hook_timer", XS_Xchat_hook_timer, __FILE__); + newXS ("Xchat::Internal::hook_fd", XS_Xchat_hook_fd, __FILE__); + newXS ("Xchat::Internal::unhook", XS_Xchat_unhook, __FILE__); + newXS ("Xchat::Internal::print", XS_Xchat_print, __FILE__); + newXS ("Xchat::Internal::command", XS_Xchat_command, __FILE__); + newXS ("Xchat::Internal::set_context", XS_Xchat_set_context, __FILE__); + newXS ("Xchat::Internal::get_info", XS_Xchat_get_info, __FILE__); + newXS ("Xchat::Internal::context_info", XS_Xchat_context_info, __FILE__); + newXS ("Xchat::Internal::get_list", XS_Xchat_get_list, __FILE__); + + newXS ("Xchat::find_context", XS_Xchat_find_context, __FILE__); + newXS ("Xchat::get_context", XS_Xchat_get_context, __FILE__); + newXS ("Xchat::get_prefs", XS_Xchat_get_prefs, __FILE__); + newXS ("Xchat::emit_print", XS_Xchat_emit_print, __FILE__); + newXS ("Xchat::send_modes", XS_Xchat_send_modes, __FILE__); + newXS ("Xchat::nickcmp", XS_Xchat_nickcmp, __FILE__); + + newXS ("Xchat::Embed::plugingui_remove", XS_Xchat_Embed_plugingui_remove, + __FILE__); + + stash = get_hv ("Xchat::", TRUE); + if (stash == NULL) { + exit (1); + } + + newCONSTSUB (stash, "PRI_HIGHEST", newSViv (XCHAT_PRI_HIGHEST)); + newCONSTSUB (stash, "PRI_HIGH", newSViv (XCHAT_PRI_HIGH)); + newCONSTSUB (stash, "PRI_NORM", newSViv (XCHAT_PRI_NORM)); + newCONSTSUB (stash, "PRI_LOW", newSViv (XCHAT_PRI_LOW)); + newCONSTSUB (stash, "PRI_LOWEST", newSViv (XCHAT_PRI_LOWEST)); + + newCONSTSUB (stash, "EAT_NONE", newSViv (XCHAT_EAT_NONE)); + newCONSTSUB (stash, "EAT_XCHAT", newSViv (XCHAT_EAT_XCHAT)); + newCONSTSUB (stash, "EAT_PLUGIN", newSViv (XCHAT_EAT_PLUGIN)); + newCONSTSUB (stash, "EAT_ALL", newSViv (XCHAT_EAT_ALL)); + newCONSTSUB (stash, "FD_READ", newSViv (XCHAT_FD_READ)); + newCONSTSUB (stash, "FD_WRITE", newSViv (XCHAT_FD_WRITE)); + newCONSTSUB (stash, "FD_EXCEPTION", newSViv (XCHAT_FD_EXCEPTION)); + newCONSTSUB (stash, "FD_NOTSOCKET", newSViv (XCHAT_FD_NOTSOCKET)); + newCONSTSUB (stash, "KEEP", newSViv (1)); + newCONSTSUB (stash, "REMOVE", newSViv (0)); + + version = get_sv( "Xchat::VERSION", 1 ); + sv_setpv( version, PACKAGE_VERSION ); +} + +static void +perl_init (void) +{ + int warn; + int arg_count; + char *perl_args[] = { "", "-e", "0", "-w" }; + char *env[] = { "" }; + static const char xchat_definitions[] = { + /* Redefine the $SIG{__WARN__} handler to have XChat + printing warnings in the main window. (TheHobbit) */ +#include "xchat.pm.h" + }; +#ifdef OLD_PERL + static const char irc_definitions[] = { +#include "irc.pm.h" + }; +#endif +#ifdef ENABLE_NLS + + /* Problem is, dynamicaly loaded modules check out the $] + var. It appears that in the embedded interpreter we get + 5,00503 as soon as the LC_NUMERIC locale calls for a comma + instead of a point in separating integer and decimal + parts. I realy can't understant why... The following + appears to be an awful workaround... But it'll do until I + (or someone else :)) found the "right way" to solve this + nasty problem. (TheHobbit ) */ + + setlocale (LC_NUMERIC, "C"); + +#endif + + warn = 0; + xchat_get_prefs (ph, "perl_warnings", NULL, &warn); + arg_count = warn ? 4 : 3; + + PERL_SYS_INIT3 (&arg_count, (char ***)&perl_args, (char ***)&env); + my_perl = perl_alloc (); + perl_construct (my_perl); + PL_exit_flags |= PERL_EXIT_DESTRUCT_END; + perl_parse (my_perl, xs_init, arg_count, perl_args, (char **)NULL); + + /* + Now initialising the perl interpreter by loading the + perl_definition array. + */ + + eval_pv (xchat_definitions, TRUE); +#ifdef OLD_PERL + eval_pv (irc_definitions, TRUE); +#endif + +} + + +static int +perl_load_file (char *filename) +{ +#ifdef WIN32 + static HMODULE lib = NULL; + + if (!lib) { + lib = LoadLibraryA (PERL_DLL); + if (!lib) { + if (GetLastError () == ERROR_BAD_EXE_FORMAT) + /* http://forum.xchat.org/viewtopic.php?t=3277 */ + thread_mbox ("Cannot use this " PERL_DLL "\n\n" + "32-bit ActivePerl is required."); + else { + /* a lot of people install this old version */ + lib = LoadLibraryA ("perl56.dll"); + if (lib) { + FreeLibrary (lib); + lib = NULL; + thread_mbox ("Cannot open " PERL_DLL "\n\n" + "You must have ActivePerl " PERL_REQUIRED_VERSION " installed in order to\n" + "run perl scripts.\n\n" + "I have found Perl 5.6, but that is too old."); + } else { + thread_mbox ("Cannot open " PERL_DLL "\n\n" + "You must have ActivePerl " PERL_REQUIRED_VERSION " installed in order to\n" + "run perl scripts.\n\n" + "http://www.activestate.com/ActivePerl/\n\n" + "Make sure perl's bin directory is in your PATH."); + } + } + /* failure */ + return FALSE; + } + + /* success */ + FreeLibrary (lib); + } +#endif + + if (my_perl == NULL) { + perl_init (); + } + + return execute_perl (sv_2mortal (newSVpv ("Xchat::Embed::load", 0)), + filename); + +} + +static void +perl_end (void) +{ + + if (my_perl != NULL) { + execute_perl (sv_2mortal (newSVpv ("Xchat::Embed::unload_all", 0)), ""); + PL_perl_destruct_level = 1; + perl_destruct (my_perl); + perl_free (my_perl); + PERL_SYS_TERM(); + my_perl = NULL; + } + +} + +static int +perl_command_unloadall (char *word[], char *word_eol[], void *userdata) +{ + if (my_perl != NULL) { + execute_perl (sv_2mortal (newSVpv ("Xchat::Embed::unload_all", 0)), ""); + return XCHAT_EAT_XCHAT; + } + + return XCHAT_EAT_XCHAT; +} + +static int +perl_command_reloadall (char *word[], char *word_eol[], void *userdata) +{ + if (my_perl != NULL) { + execute_perl (sv_2mortal (newSVpv ("Xchat::Embed::reload_all", 0)), ""); + + return XCHAT_EAT_XCHAT; + } else { + perl_auto_load( NULL ); + } + return XCHAT_EAT_XCHAT; +} + +static int +perl_command_load (char *word[], char *word_eol[], void *userdata) +{ + char *file = get_filename (word, word_eol); + + if (file != NULL ) + { + perl_load_file (file); + return XCHAT_EAT_XCHAT; + } + + return XCHAT_EAT_NONE; +} + +static int +perl_command_unload (char *word[], char *word_eol[], void *userdata) +{ + char *file = get_filename (word, word_eol); + + if (my_perl != NULL && file != NULL) { + execute_perl (sv_2mortal (newSVpv ("Xchat::Embed::unload", 0)), file); + return XCHAT_EAT_XCHAT; + } + + return XCHAT_EAT_NONE; +} + +static int +perl_command_reload (char *word[], char *word_eol[], void *userdata) +{ + char *file = get_filename (word, word_eol); + + if (my_perl != NULL && file != NULL) { + execute_perl (sv_2mortal (newSVpv ("Xchat::Embed::reload", 0)), file); + return XCHAT_EAT_XCHAT; + } + + return XCHAT_EAT_XCHAT; +} + +void +xchat_plugin_get_info (char **name, char **desc, char **version, + void **reserved) +{ + *name = "Perl"; + *desc = "Perl scripting interface"; + *version = PACKAGE_VERSION; + if (reserved) + *reserved = NULL; +} + + +/* Reinit safeguard */ + +static int initialized = 0; + +int +xchat_plugin_init (xchat_plugin * plugin_handle, char **plugin_name, + char **plugin_desc, char **plugin_version, char *arg) +{ + if (initialized != 0) { + xchat_print (plugin_handle, "Perl interface already loaded\n"); + return 0; + } + + ph = plugin_handle; + initialized = 1; + + *plugin_name = "Perl"; + *plugin_desc = "Perl scripting interface"; + *plugin_version = PACKAGE_VERSION; + + xchat_hook_command (ph, "load", XCHAT_PRI_NORM, perl_command_load, 0, 0); + xchat_hook_command (ph, "unload", XCHAT_PRI_NORM, perl_command_unload, 0, + 0); + xchat_hook_command (ph, "reload", XCHAT_PRI_NORM, perl_command_reload, 0, + 0); + xchat_hook_command (ph, "pl_reload", XCHAT_PRI_NORM, perl_command_reload, 0, + 0); + xchat_hook_command (ph, "unloadall", XCHAT_PRI_NORM, + perl_command_unloadall, 0, 0); + xchat_hook_command (ph, "reloadall", XCHAT_PRI_NORM, + perl_command_reloadall, 0, 0); + + /*perl_init (); */ + xchat_hook_timer (ph, 0, perl_auto_load, NULL ); + + xchat_print (ph, "Perl interface loaded\n"); + + return 1; +} + +int +xchat_plugin_deinit (xchat_plugin * plugin_handle) +{ + perl_end (); + + initialized = 0; + xchat_print (plugin_handle, "Perl interface unloaded\n"); + + return 1; +} diff --git a/plugins/perl/perl.def b/plugins/perl/perl.def new file mode 100644 index 00000000..a2ec6566 --- /dev/null +++ b/plugins/perl/perl.def @@ -0,0 +1,4 @@ +EXPORTS + xchat_plugin_init + xchat_plugin_deinit + xchat_plugin_get_info \ No newline at end of file diff --git a/plugins/perl/syntax_highlight b/plugins/perl/syntax_highlight new file mode 100644 index 00000000..96d57003 --- /dev/null +++ b/plugins/perl/syntax_highlight @@ -0,0 +1,69 @@ +#!/usr/bin/env perl +use 5.010; +use strict; +use warnings; +use Text::VimColor; +use HTML::TokeParser::Simple; +use HTML::Entities qw(decode_entities); +use Path::Class; + +my $html_file = shift; +my $reader = file( $html_file )->openr; +unlink $html_file; +my $writer = file( $html_file )->openw; + +my $parser = HTML::TokeParser::Simple->new( $reader ); + +while( my $token = $parser->get_token ) { + + my $class_name = $token->get_attr( "class" ); + + if( $token->is_start_tag( "div" ) + && ( $class_name && $class_name =~ qr/\bexample\b/ ) + ) { + my $start_tag = $token; + $start_tag->set_attr( class => $class_name . " synNormal" ); + my @content; + my $end_tag; + + EXAMPLE: + while( $token = $parser->get_token ) { + if( $token->is_end_tag( "div" ) ) { + $end_tag = $token; + last EXAMPLE; + } + + if( $token->is_text ) { + push @content, decode_entities( $token->as_is ); + } + } + + my $code = join "", @content; +# say $code; + my $vim = Text::VimColor->new( + string => $code, + filetype => "perl", + vim_options => [qw( -RXZ -i NONE -u NONE -N -n)], + ); + my $html = $vim->html; + $html =~ s/^\s+//; + $html =~ s/\s+$//; + + print $writer $start_tag->as_is; + + my $lines = $html =~ tr/\n/\n/; + + say $writer "
    "; + for my $line ( 0 .. $lines ) { + say $writer "
    ",1 + $line,"
    "; + } + say $writer "
    "; + + print $writer "
    ";
    +		say $writer $html;
    +		say $writer "
    "; + print $writer $end_tag->as_is; + } else { + print $writer $token->as_is; + } +} diff --git a/plugins/perl/xchat2-perl.html b/plugins/perl/xchat2-perl.html new file mode 100644 index 00000000..38dd3912 --- /dev/null +++ b/plugins/perl/xchat2-perl.html @@ -0,0 +1,1166 @@ + + + + +X-Chat 2 Perl Interface + + + + + + + + +
    + X-Chat 2 Perl Interface +
    + + + +
    +

    + + + +
    +
    + + +

    +

    +

    X-Chat 2 Perl Interface

    +

    +

    +

    Introduction

    +

    This is the new Perl interface for X-Chat 2. However, due to changes in +xchat's plugin code you will need xchat 2.0.8 or above to load this. Scripts +written using the old interface will continue to work. If there are any +problems, questions, comments or suggestions please email them to the address +on the bottom of this page.

    +

    +

    +

    Constants

    +

    +

    +

    Priorities

    +
      +
    • Xchat::PRI_HIGHEST +
    • +
    • Xchat::PRI_HIGH +
    • +
    • Xchat::PRI_NORM +
    • +
    • Xchat::PRI_LOW +
    • +
    • Xchat::PRI_LOWEST +
    • +
    +

    +

    +

    Return values

    +
      +
    • Xchat::EAT_NONE - pass the event along +
    • +
    • Xchat::EAT_XCHAT - don't let xchat see this event +
    • +
    • Xchat::EAT_PLUGIN - don't let other scripts and plugins see this event but xchat will still see it +
    • +
    • Xchat::EAT_ALL - don't let anything else see this event +
    • +
    +

    +

    +

    Timer and fd hooks

    +
      +
    • Xchat::KEEP - keep the timer going or hook watching the handle +
    • +
    • Xchat::REMOVE - remove the timer or hook watching the handle +
    • +
    +

    +

    +

    hook_fd flags

    +
      +
    • Xchat::FD_READ - invoke the callback when the handle is ready for reading +
    • +
    • Xchat::FD_WRITE - invoke the callback when the handle is ready for writing +
    • +
    • Xchat::FD_EXCEPTION - invoke the callback if an exception occurs +
    • +
    • Xchat::FD_NOTSOCKET - indicate that the handle being hooked is not a socket +
    • +
    +

    +

    +

    Functions

    +

    +

    +

    Xchat::register( $name, $version, [$description,[$callback]] )

    +
      +
    • $name - The name of this script +
    • +
    • $version - This script's version +
    • +
    • $description - A description for this script +
    • +
    • $callback - This is a function that will be called when the is script + unloaded. This can be either a reference to a + function or an anonymous sub reference. +
    • +
    +

    This is the first thing to call in every script.

    +

    +

    +

    Xchat::hook_server( $message, $callback, [\%options] )

    +

    +

    +

    Xchat::hook_command( $command, $callback, [\%options] )

    +

    +

    +

    Xchat::hook_print( $event,$callback, [\%options] )

    +

    +

    +

    Xchat::hook_timer( $timeout,$callback, [\%options | $data] )

    +

    +

    +

    Xchat::hook_fd( $handle, $callback, [ \%options ] )

    +

    These functions can be to intercept various events. +hook_server can be used to intercept any incoming message from the IRC server. +hook_command can be used to intercept any command, if the command doesn't currently exist then a new one is created. +hook_print can be used to intercept any of the events listed in Setttings->Advanced->Text Events +hook_timer can be used to create a new timer

    +
    +

    Valid keys for \%options:

    + + + + + + + +
    data Additional data that is to be associated with the
    + hook. For timer hooks this value can be provided either as
    + Xchat::hook_timer( $timeout, $cb,{data=>$data})
    + or Xchat::hook_timer( $timeout, $cb, $data ).
    + However, this means that hook_timer cannot be provided
    + with a hash reference containing data as a key.
    example:
    + my $options = { data => [@arrayOfStuff] };
    + Xchat::hook_timer( $timeout, $cb, $options );
    +
    + In this example, the timer's data will be
    + [@arrayOfStuff] and not { data => [@arrayOfStuff] }
    +
    + This key is valid for all of the hook functions.
    +
    + Default is undef.
    +
    priority Sets the priority for the hook.
    + It can be set to one of the + Xchat::PRI_* constants.
    +
    + This key only applies to server, command + and print hooks.
    +
    + Default is Xchat::PRI_NORM. +
    help_text Text displayed for /help $command.
    +
    + This key only applies to command hooks.
    +
    + Default is "". +
    flags Specify the flags for a fd hook.
    +
    + See hook fd flags section for valid values.
    +
    + On Windows if the handle is a pipe you specify
    + Xchat::FD_NOTSOCKET in addition to any other flags you might be using.
    +
    + This key only applies to fd hooks.
    + Default is Xchat::FD_READ +

    +

    +

    When callbacks are invoked

    +

    Each of the hooks will be triggered at different times depending on the type +of hook.

    + + + + + + + + + + + + + +
    Hook Type When the callback will be invoked
    server hooks a $message message is + received from the server +
    command hooks the $command command is + executed, either by the user or from a script +
    print hooks X-Chat is about to print the message for the + $event event +
    timer hooks called every $timeout milliseconds + (1000 millisecond is 1 second)
    + the callback will be executed in the same context where + the hook_timer was called, if the context no longer exists + then it will execute in a random context +
    fd hooks depends on the flags that were passed to hook_fd
    + See hook_fd flags section. +

    The value return from these hook functions can be passed to Xchat::unhook +to remove the hook.

    +

    +

    +

    Callback Arguments

    +

    All callback functions will receive their arguments in @_ like every +other Perl subroutine.

    +

    +Server and command callbacks
    +
    +$_[0] - array reference containing the IRC message or command and +arguments broken into words
    +example:
    +/command arg1 arg2 arg3
    +$_[0][0] - command
    +$_[0][1] - arg1
    +$_[0][2] - arg2
    +$_[0][3] - arg3
    +
    +$_[1] - array reference containing the Nth word to the last word
    +example:
    +/command arg1 arg2 arg3
    +$_[1][0] - command arg1 arg2 arg3
    +$_[1][1] - arg1 arg2 arg3
    +$_[1][2] - arg2 arg3
    +$_[1][3] - arg3
    +
    +$_[2] - the data that was passed to the hook function
    +
    +Print callbacks
    +
    +$_[0] - array reference containing the values for the + text event see Settings->Advanced->Text Events
    +$_[1] - the data that was passed to the hook function
    +
    +Timer callbacks
    +
    +$_[0] - the data that was passed to the hook function
    +
    fd callbacks
    +
    +$_[0] - the handle that was passed to hook_fd
    +$_[1] - flags indicating why the callback was called
    +$_[2] - the data that was passed to the hook function
    +

    +

    +

    Callback return values

    +

    All server, command and print callbacks should return one of +the Xchat::EAT_* constants. +Timer callbacks can return Xchat::REMOVE to remove +the timer or Xchat::KEEP to keep it going

    +

    +

    +

    Miscellaneous Hook Related Information

    +

    For server hooks, if $message is "RAW LINE" then $cb will be called for +every IRC message than X-Chat receives.

    +

    For command hooks if $command is "" then $cb will be called for +messages entered by the user that is not a command.

    +

    For print hooks besides those events listed in +Settings->Advanced->Text Events, these additional events can be used.

    + + + + + + + + + + + + + + + +
    Event Description
    "Open Context" a new context is created
    "Close Context" a context has been close
    "Focus Tab" when a tab is brought to the front
    "Focus Window" when a top level window is focused or the + main tab window is focused by the window manager +
    "DCC Chat Text" when text from a DCC Chat arrives. + $_[0] will have these values
    +
    + $_[0][0] - Address
    + $_[0][1] - Port
    + $_[0][2] - Nick
    + $_[0][3] - Message
    +
    "Key Press" used for intercepting key presses
    + $_[0][0] - key value
    + $_[0][1] - state bitfield, 1 - shift, 4 - control, 8 - alt
    + $_[0][2] - string version of the key which might be empty for unprintable keys
    + $_[0][3] - length of the string in $_[0][2]
    +

    +

    +

    Xchat::unhook( $hook )

    +
      +
    • $hook - the hook that was previously returned by one of the Xchat::hook_* functions +
    • +
    +

    This function is used to removed a hook previously added with one of +the Xchat::hook_* functions

    +

    It returns the data that was passed to the Xchat::hook_* function when +the hook was added

    +

    +

    +

    Xchat::print( $text | \@lines, [$channel,[$server]] )

    +
      +
    • $text - the text to print +
    • +
    • \@lines - array reference containing lines of text to be printed + all the elements will be joined together before printing +
    • +
    • $channel - channel or tab with the given name where $text + will be printed +
    • +
    • $server - specifies that the text will be printed in a channel or tab + that is associated with $server +
    • +
    +

    The first argument can either be a string or an array reference of strings. +Either or both of $channel and $server can be undef.

    +

    If called as Xchat::print( $text ), it will always return true. +If called with either the channel or the channel and the server +specified then it will return true if a context is found and +false otherwise. The text will not be printed if the context +is not found. The meaning of setting $channel or $server to +undef is the same as +find_context.

    +

    +

    +

    Xchat::printf( $format, LIST )

    + +

    +

    +

    Xchat::command( $command | \@commands, [$channel,[$server]] )

    +
      +
    • $command - the command to execute, without the leading / +
    • +
    • \@commands - array reference containing a list of commands to execute +
    • +
    • $channel - channel or tab with the given name where $command will be executed +
    • +
    • $server - specifies that the command will be executed in a channel or tab that is associated with $server +
    • +
    +

    The first argument can either be a string or an array reference of strings. +Either or both of $channel and $server can be undef.

    +

    If called as Xchat::command( $command ), it will always return true. +If called with either the channel or the channel and the server +specified then it will return true if a context is found and false +otherwise. The command will not be executed if the context is not found. +The meaning of setting $channel or $server to undef is the same +as find_context.

    +

    +

    +

    Xchat::commandf( $format, LIST )

    + +

    +

    +

    Xchat::find_context( [$channel, [$server]] )

    +
      +
    • $channel - name of a channel +
    • +
    • $server - name of a server +
    • +
    +

    Either or both of $channel and $server can be undef. Calling +Xchat::find_context() is the same as calling +Xchat::find_context( undef, undef) and +Xchat::find_context( $channel ) is +the same as Xchat::find_context( $channel, undef ).

    +

    If $server is undef, find any channel named $channel. +If $channel is undef, find the front most window +or tab named $server.If both $channel and +$server are undef, find the currently focused tab or window.

    +

    Return the context found for one of the above situations or undef if such +a context cannot be found.

    +

    +

    +

    Xchat::get_context()

    +

    Returns the current context.

    +

    +

    +

    Xchat::set_context( $context | $channel,[$server] )

    + +

    See find_context for more details on $channel and $server.

    +

    Returns true on success, false on failure

    +

    +

    +

    Xchat::get_info( $id )

    +
      +
    • $id - one of the following case sensitive values +
    • +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ID Return value
    away away reason or undef if you are not away
    channel current channel name
    charset character-set used in the current context
    event_text <Event Name> text event format string for <Event name>
    + Example: +
    +
    1
    +
    +
    my $channel_msg_format = Xchat::get_info( "event_text Channel Message" );
    +
    +
    +
    host real hostname of the current server
    id connection id
    inputbox contents of the inputbox
    libdirfsthe system wide directory where xchat will look for plugins. + this string is in the same encoding as the local file system
    modes the current channels modes or undef if not known
    network current network name or undef
    nick current nick
    nickserv nickserv password for this network or undef
    server current server name
    + (what the server claims to be) undef if not connected +
    state_cursorcurrent inputbox cursor position in characters
    topic current channel topic
    version xchat version number
    win_statusstatus of the xchat window, possible values are "active", "hidden" + and "normal"
    win_ptr native window pointer, GtkWindow * on Unix, HWND on Win32.
    + On Unix if you have the Glib module installed you can use my $window = Glib::Object->new_from_pointer( Xchat::get_info( "win_ptr" ) ); to get a Gtk2::Window object.
    + Additionally when you have detached tabs, each of the windows will return a different win_ptr for the different Gtk2::Window objects.
    + See char_count.pl for a longer example of a script that uses this to show how many characters you currently have in your input box. +
    xchatdir xchat config directory encoded in UTF-8
    + examples:
    + /home/user/.xchat2
    + C:\Documents and Settings\user\Application Data\X-Chat 2 +
    xchatdirfs same as xchatdir except encoded in the locale file system encoding

    This function is used to retrieve certain information about the current +context.

    +

    +

    Xchat::get_prefs( $name )

    +
      +
    • $name - name of a X-Chat setting (available through the /set command) +
    • +
    +

    This function provides a way to retrieve X-Chat's setting information.

    +

    Returns undef if there is no setting called called $name.

    +

    +

    +

    Xchat::emit_print( $event, LIST )

    +
      +
    • $event - name from the Event column in Settings->Advanced->Text Events +
    • +
    • LIST - this depends on the Description column on the bottom of Settings->Advanced->Text Events +
    • +
    +

    This functions is used to generate one of the events listed under +Settings->Advanced->Text Events

    +

    Note: when using this function you MUST return Xchat::EAT_ALL otherwise you will end up with duplicate events. +One is the original and the second is the one you emit.

    +

    Returns true on success, false on failure

    +

    +

    +

    Xchat::send_modes( $target | \@targets, $sign, $mode, [ $modes_per_line ] )

    +
      +
    • $target - a single nick to set the mode on +
    • +
    • \@targets - an array reference of the nicks to set the mode on +
    • +
    • $sign - the mode sign, either '+' or '-' +
    • +
    • $mode - the mode character such as 'o' and 'v', this can only be one character long +
    • +
    • $modes_per_line - an optional argument maximum number of modes to send per at once, pass 0 use the current server's maximum (default) +
    • +
    +

    Send multiple mode changes for the current channel. It may send multiple MODE lines if the request doesn't fit on one.

    +

    Example:

    +<
    +
    1
    +
    2
    +
    3
    +
    4
    +
    5
    +
    6
    +
    7
    +
    8
    +
    9
    +
    10
    +
    11
    +
    12
    +
    13
    +
    14
    +
    +
    use strict;
    +use warning;
    +use Xchat qw(:all);
    +
    +hook_command( "MODES", sub {
    +   my (undef, $who, $sign, $mode) = @{$_[0]};
    +   my @targets = split /,/, $who;
    +   if( @targets > 1 ) {
    +      send_modes( \@targets, $sign, $mode, 1 );
    +   } else {
    +      send_modes( $who, $sign, $mode );
    +   }
    +   return EAT_XCHAT;
    +});
    +
    +

    +

    +

    Xchat::nickcmp( $nick1, $nick2 )

    +
      +
    • $nick1, $nick2 - the two nicks or channel names that are to be compared +
    • +
    +

    The comparsion is based on the current server. Either a RFC1459 compliant +string compare or plain ascii will be using depending on the server. The +comparison is case insensitive.

    +

    Returns a number less than, equal to or greater than zero if +$nick1 is +found respectively, to be less than, to match, or be greater than +$nick2.

    +

    +

    +

    Xchat::get_list( $name )

    +
      +
    • $name - name of the list, one of the following: +"channels", "dcc", "ignore", "notify", "users" +
    • +
    +

    This function will return a list of hash references. The hash references +will have different keys depend on the list. An empty list is returned +if there is no such list.

    +

    "channels" - list of channels, querys and their server

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Description
    channel tab name
    chantypeschannel types supported by the server, typically "#&"
    context can be used with set_context
    flags Server Bits:
    + 0 - Connected
    + 1 - Connecting
    + 2 - Away
    + 3 - EndOfMotd(Login complete)
    + 4 - Has WHOX
    + 5 - Has IDMSG (FreeNode)
    +
    +

    The following correspond to the /chanopt command

    + 6 - Hide Join/Part Message (text_hidejoinpart)
    + 7 - unused (was for color paste)
    + 8 - Beep on message (alert_beep)
    + 9 - Blink Tray (alert_tray)
    + 10 - Blink Task Bar (alert_taskbar)
    +

    Example of checking if the current context has Hide Join/Part messages set:

    +
    +
    1
    +
    2
    +
    3
    +
    +
    if( Xchat::context_info->{flags} & (1 << 6) ) {
    +  Xchat::print( "Hide Join/Part messages is enabled" );
    +}
    +
    +
    id Unique server ID
    laglag in milliseconds
    maxmodes Maximum modes per line
    network network name to which this channel belongs
    nickprefixes Nickname prefixes e.g. "+@"
    nickmodes Nickname mode chars e.g. "vo"
    queuenumber of bytes in the send queue
    server server name to which this channel belongs
    type the type of this context
    + 1 - server
    + 2 - channel
    + 3 - dialog
    +
    users Number of users in this channel

    "dcc" - list of DCC file transfers

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Value
    address32 address of the remote user(ipv4 address)
    cps bytes per second(speed)
    destfile destination full pathname
    file file name
    nicknick of the person this DCC connection is connected to
    port TCP port number
    pos bytes sent/received
    poshigh bytes sent/received, high order 32 bits
    resume point at which this file was resumed
    + (zero if it was not resumed) +
    resumehigh point at which this file was resumed, high order 32 bits
    +
    size file size in bytes low order 32 bits
    sizehigh file size in bytes, high order 32 bits (when the files is > 4GB)
    status DCC Status:
    + 0 - queued
    + 1 - active
    + 2 - failed
    + 3 - done
    + 4 - connecting
    + 5 - aborted +
    type DCC Type:
    + 0 - send
    + 1 - receive
    + 2 - chatrecv
    + 3 - chatsend +

    "ignore" - current ignore list

    + + + + + + +
    Key Value
    mask ignore mask. e.g: *!*@*.aol.com
    flags Bit field of flags.
    + 0 - private
    + 1 - notice
    + 2 - channel
    + 3 - ctcp
    + 4 - invite
    + 5 - unignore
    + 6 - nosave
    + 7 - dcc
    +

    "notify" - list of people on notify

    + + + + + + + + + + + + + + + + + +
    Key Value
    networkscomma separated list of networks where you will be notfified about this user's online/offline status or undef if you will be notificed on every network you are connected to
    nick nickname
    flags 0 = is online
    on time when user came online
    off time when user went offline
    seen time when user was last verified still online

    the values indexed by on, off and seen can be passed to localtime +and gmtime, see perldoc -f localtime and perldoc -f gmtime for more +detail

    "users" - list of users in the current channel

    + + + + + + + + + + + + + + + + + + + + + +
    Key Value
    away away status(boolean)
    lasttalklast time a user was seen talking, this is the an epoch time(number of seconds since a certain date, that date depends on the OS)
    nick nick name
    hosthost name in the form: user@host or undef if not known
    prefix prefix character, .e.g: @ or +
    realnameReal name or undef
    selectedselected status in the user list, only works when retrieving the user list of the focused tab. You can use the /USELECT command to select the nicks

    "networks" - list of networks and the associated settings from network list

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key Value
    autojoins An object with the following methods:
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    MethodDescription
    channels()returns a list of this networks' autojoin channels in list context, a count of the number autojoin channels in scalar context
    keys()returns a list of the keys to go with the channels, the order is the same as the channels, if a channel doesn't have a key, '' will be returned in it's place
    pairs()a combination of channels() and keys(), returns a list of (channels, keys) pairs. This can be assigned to a hash for a mapping from channel to key.
    as_hash()return the pairs as a hash reference
    as_string()the original string that was used to construct this autojoin object, this can be used with the JOIN command to join all the channels in the autojoin list
    as_array()return an array reference of hash references consisting of the keys "channel" and "key"
    as_bool()returns true if the network has autojoins and false otherwise
    +
    connect_commands An array reference containing the connect commands for a network. An empty array if there aren't any
    encoding the encoding for the network
    flags + a hash reference corresponding to the checkboxes in the network edit window + + + + + + + + + + + + + + + + + + + + +
    allow_invalidtrue if "Accept invalid SSL certificate" is checked
    autoconnecttrue if "Auto connect to this network at startup" is checked
    cycletrue if "Connect to selected server only" is NOT checked
    use_globaltrue if "Use global user information" is checked
    use_proxytrue if "Bypass proxy server" is NOT checked
    use_ssltrue if "Use SSL for all the servers on this network" is checked
    +
    irc_nick1Corresponds with the "Nick name" field in the network edit window
    irc_nick2Corresponds with the "Second choice" field in the network edit window
    irc_real_nameCorresponds with the "Real name" field in the network edit window
    irc_user_nameCorresponds with the "User name" field in the network edit window
    networkName of the network
    nickserv_passwordCorresponds with the "Nickserv password" field in the network edit window
    selectedIndex into the list of servers in the "servers" key, this is used if the "cycle" flag is false
    server_passwordCorresponds with the "Server password" field in the network edit window
    serversAn array reference of hash references with a "host" and "port" key. If a port is not specified then 6667 will be used.

    +

    +

    Xchat::user_info( [$nick] )

    +
      +
    • $nick - the nick to look for, if this is not given your own nick will be + used as default +
    • +
    +

    This function is mainly intended to be used as a shortcut for when you need +to retrieve some information about only one user in a channel. Otherwise it +is better to use get_list. +If $nick is found a hash reference containing the same keys as those in the +"users" list of get_list is returned otherwise undef is returned. +Since it relies on get_list this function can only be used in a +channel context.

    +

    +

    +

    Xchat::context_info( [$context] )

    + +

    This function will return the information normally retrieved with get_info, except this is for the context that is passed in. The information will be returned in the form of a hash. The keys of the hash are the $id you would normally supply to get_info as well as all the keys that are valid for the items in the "channels" list from get_list. Use of this function is more efficient than calling get_list( "channels" ) and searching through the result.

    +

    Example:

    +
    +
    1
    +
    2
    +
    3
    +
    4
    +
    5
    +
    6
    +
    7
    +
    8
    +
    9
    +
    10
    +
    11
    +
    +
    use strict;
    +use warnings;
    +use Xchat qw(:all); # imports all the functions documented on this page
    +
    +register( "User Count", "0.1",
    +   "Print out the number of users on the current channel" );
    +hook_command( "UCOUNT", \&display_count );
    +sub display_count {
    +   prnt "There are " . context_info()->{users} . " users in this channel.";
    +   return EAT_XCHAT;
    +}
    +
    +

    +

    +

    Xchat::strip_code( $string )

    +
      +
    • $string - string to remove codes from +
    • +
    +

    This function will remove bold, color, beep, reset, reverse and underline codes from $string. It will also remove ANSI escape codes which might get used by certain terminal based clients. If it is called in void context $string will be modified otherwise a modified copy of $string is returned.

    +

    +

    +

    Examples

    +

    +

    +

    Asynchronous DNS resolution with hook_fd

    +
    +
    1
    +
    2
    +
    3
    +
    4
    +
    5
    +
    6
    +
    7
    +
    8
    +
    9
    +
    10
    +
    11
    +
    12
    +
    13
    +
    14
    +
    15
    +
    16
    +
    17
    +
    18
    +
    19
    +
    20
    +
    21
    +
    22
    +
    23
    +
    24
    +
    25
    +
    26
    +
    27
    +
    28
    +
    29
    +
    30
    +
    31
    +
    32
    +
    33
    +
    34
    +
    35
    +
    +
    use strict;
    +use warnings;
    +use Xchat qw(:all);
    +use Net::DNS;
    +   
    +hook_command( "BGDNS", sub {
    +   my $host = $_[0][1];
    +   my $resolver = Net::DNS::Resolver->new;
    +   my $sock = $resolver->bgsend( $host );
    +   
    +   hook_fd( $sock, sub {
    +      my $ready_sock = $_[0];
    +      my $packet = $resolver->bgread( $ready_sock );
    +      
    +      if( $packet->authority && (my @answers = $packet->answer ) ) {
    +         
    +         if( @answers ) {
    +            prnt "$host:";
    +            my $padding = " " x (length( $host ) + 2);
    +            for my $answer ( @answers ) {
    +               prnt $padding . $answer->rdatastr . ' ' . $answer->type;
    +            }
    +         }
    +      } else {
    +         prnt "Unable to resolve $host";
    +      }
    +      
    +      return REMOVE;
    +   },
    +   {
    +      flags => FD_READ,
    +   });
    +   
    +   return EAT_XCHAT;
    +});
    +
    +
    + +

    +

    +

    Contact Information

    +

    Contact Lian Wan Situ at <atmcmnky [at] yahoo.com> for questions, comments and +corrections about this page or the Perl plugin itself. You can also find me +in #xchat on FreeNode under the nick Khisanth.

    + + +
    + X-Chat 2 Perl Interface +
    + + + + diff --git a/plugins/perl/xchat2-perldocs.html b/plugins/perl/xchat2-perldocs.html new file mode 100644 index 00000000..10d8f314 --- /dev/null +++ b/plugins/perl/xchat2-perldocs.html @@ -0,0 +1,475 @@ +XChat - IRC (chat) client for UNIX + + + +

    This interface is deprecated

    + + + + + +
    +
    +

    Xchat Perl Docs

    + + +
    + + +
    + +Introduction +
    +
    + +
    +

    Good Hello!

    +

    The purpose of this page is to give people some quick documentation on the +things that they will encounter when they try to code scripts for X-Chat. +It is not meant to be a comprehensive programming tutorial, +by any means. If that's what you're looking for, then you can just keep on +looking.

    +

    If you're going to do any scripting with X-Chat at all, you will +need to know perl. It also won't hurt to have had experience writing tcl for +eggdrops or ircII scripts. Otherwise you're going to have to be very careful +to avoid creating conditions which could flood you offline or do other +not-so-optimal things. ;) Thankfully, it shouldn't take most intelligent +people more than a week (month on the outside) enough perl to do some nice +things in it. +Perl is a very flexible language.

    +

    You should probably also go read (or at least skim over and then carefully +bookmark this copy of the thing that defines how IRC works: RFC 1459. +Other documents that scripters might find useful would be this +nice list of server +numerics, and this list of changes +for Hybrid 6 which is something everyone on EFNet should read. In fact, I +strongly suggest saving copies of these documents to your local +hard drive, because you will be back to look at them again soon.

    +

    One last thing... While you may hear that RFC 1459 isn't being followed very +well, and this is partly true, do your absolute best to stick with RFC-compliant +behaviours anyway because otherwise there's a good chance that your script will +never interoperate properly with others, or at least just piss off a lot of other +people. Pay special attention to section 2.2 of the RFC.

    +
    + + +
    +Standard Disclaimer + +
    +This documentation is provided on an "as-is" basis and comes with no warranty of accuracy or usefulness, either expressed or implied. It is subject to change without any notice, and may contain omissions or errors which could cause your genitalia to shrivel and fall off, or spontaneously combust. If you have any further questions,
    please feel free to seek professional help.
    +
    + + +
    + + +
    + +About Handlers +
    +
    + +
    +There are [currently] four basic ways to make things call the subroutines you write for X-Chat and they are: +
    • message handlers - Triggered by messagse sent from the IRC server to your client
    • +
    • command handlers - triggered by / commands typed in by the user at the keyboard
    • +
    • timeout handlers - triggered by gtk+
    • +
    • print handlers - triggered just before xchat calls its built in print handlers for events
    +
    + + +
    + + +
    + +About Exit Codes +
    +
    + +
    +These are very important. Every time you set up a handler, it takes precedent over the built-in functions and commands of X-Chat. That is, whatever thing which triggered your subroutine will go to your code before it goes to X-Chat to be dealt with. In this way you can replace almost every built-in function that the client has with your own routines. The thing to remember is that if your code exits by hitting the end of your subroutine, or by a plain 'return' statement, processing of the event will go on to whatever other things have set up hooks for the event, and then (provided nothing else exits with a return value of 1) to X-Chat itself. There is only one problem with this, (which is solved by the brokering handler that I'll explain that later) and that is that you cannot really control what order the custom routines get called. Normally they will execute in order of which ones were installed first, but a single script has no real way of knowing this. Beware. +
    + + +
    + + +
    + +About @_ +
    +
    + +
    +If you've never heard of @_ before, then you've obviously not coded in perl. When a message handler triggers, the raw line from the IRC server is passed to the subroutine you specify in @_. When a command handler is triggered, only the arguments are passed to the routine through @_ and they are not broken into a list, but left as one long string. You'll have to parse those yourself with split. (I advise using s/\s+/ /g to collapse the blank space to single space first.) When a timer handler is triggered, I *think* absolutely nothing is passed in @_, but it's not like anything terrifically important could be passed along anyway. Be especially careful when setting up message handlers for mode changes, since the modes are not broken up into individual events like they are with eggdrop. The upside of this is that X-Chat has no mode hooks of it's own, so you don't have to worry about it too much. (This is not the case with the brokering handler, however.) +
    + + +
    + + +
    + +About Context +
    +
    + +
    +There are some really nice things about coding for X-Chat, and the biggest one is that it's fairly good about determining the proper context for things. If a server sends something that triggers a message handler, then you can be sure that unless you specify otherwise, that your IRC::print or IRC::command function call will go back to that server and that server alone. If you really really need to know what the current context is, use the IRC::get_info function as detailed below. +
    + +
    + + +
    + + +
    + +script initialization commands +
    +
    + + +
    + + +
    + +IRC::register(scriptname, version, shutdownroutine, unused); +
    +
    + +
    +

    This is the first function your script should call, example:

    +

    IRC::register ("my script", "1.0", "", "");

    +

    The "shutdownroutine" arg is a function that will be called when X-Chat shuts down, so you get a chance to save config files etc. You can omit this arg, it is optional. The "unused" arg is reserved for future use, for now just provide "". This function also returns X-Chat's version number.

    +
    + + +
    + + +
    + +Handler initialization commands +
    +
    + + +
    + + +
    + +IRC::add_message_handler(message, subroutine_name); +
    +
    + +
    +

    This function allows you to set up hooks to subroutines so that when a particular message arrives from the IRC server that you are connected to, it can be passed to a subroutine to be dealt with appropriately. The message argument is essentially the second solid token from the raw line sent by the IRC server, and X-Chat doesn't know that some numeric messages have associated text messages, so for now set up a handler for both if you want to be sure odd servers don't screw up your expectations. (Read: fear IRCNet.) The entire line sent by the IRC server will be passed to your subroutine in @_. For the completely uninitiated, messages are things like 'PRIVMSG', 'NOTICE', '372', etc.

    +
    + + +
    + + +
    + +IRC::add_command_handler(command, subroutine_name); +
    +
    + +
    +

    This function allows you to set up hooks for actual commands that the user can type into the text window. The arguments are passed to the subroutine via @_, and arrive as a single string. @_ will be null if no arguments are supplied. It's recommended that you be sure and collapse the excess whitespace with s/\s+/ /g before attempting to chop the line up with split. As mentioned earlier, exiting with an undefined return value will allow the command to be parsed by other handlers, while using a return value of 1 will signal the program that no further parsing needs to be done with this command.

    +
    + + +
    + + +
    + +IRC::add_timeout_handler(interval, subroutine_name); +
    +
    + +
    +

    This function allows you to set up hooks for subroutines to be called at a particular interval. The interval is measured in milliseconds, so don't use a particularly small value unless you wish to drive the CPU load through the roof. 1000ms = 1 second. No values will be passed to the routine via @_ and return values don't affect anything either.

    +
    + + +
    + + +
    + +IRC::add_print_handler(message, subroutine_name); +
    +
    + +
    +

    This function allows you to catch the system messages (those who generally start by three stars) and to execute a function each time an event appear. The events are those you can see in "Settings->Edit Events Texts". message is the name of the event (you can find it in the Edit Events box, "Events" column) , subroutine_name is the name of the function that will get messages. Be carrful: all the arguments are sent to function in $_[0] separated by spaces.

    +
    + + +
    + + +
    + +Output commands +
    +
    + + +
    + + +
    + +IRC::print(text); +
    +
    + +
    +This is a very simple routine. All it does is put the contents of the text string to the current window. The current window will be whichever window a command was typed into when called from a command handler, or in whichever window the message command is appropriate to if it is called from within a message handler. As with any perl program, newlines are not assumed, so don't forget to end the line with \n if you don't want things to look screwey. +
    + + +
    + + +
    + +IRC::print_with_channel( text, channelname, servername ); +
    +
    + +
    +This routine does the same thing as IRC::Print does, except it allows you to direct the output to a specific window. It returns 1 on success, 0 on fail. +
    + + +
    + + +
    + +IRC::command(text); +
    +
    + +
    +This routine allows you to execute commands in the current context. The text string containing the command will be parsed by everything that would normally parse a command, including your own command handlers, so be careful. Newlines are assumed, thankfully. +
    + + +
    + + +
    + +IRC::command_with_server(text, servername); +
    +
    + +
    +This routine allows you to specify the context of the server for which the command will be executed. It's not particularly useful unless you're managing a connection manually, yet the command still exists for it's usefulness in doing things like managing a bnc connection, etc. Newlines are assumed here as well. +
    + + +
    + + +
    + +IRC::send_raw(text); +
    +
    + +
    +This routine is very useful in that it allows you to send a string directly to the IRC server you are connected to. It is assumed that the server will be the one you first connected to if there is no clear context for the command, otherwise it will go to whatever server triggered the message handler or command handler window. You must specify newlines here always or you can be guaranteed that strange things will happen. The text message you specify should be a proper RAW IRC message, so don't play with it if you don't know how to do these. Additionally, while newlines are also not assumed here as with the IRC::print function, the RFC specifies that newlines are a CR+LF pair, even if most servers will accept a mere newline. It's best to play it safe and use \r\n instead of just \n. +
    + + +
    + + +
    + +Information retrieval commands +
    +
    + + +
    + + +
    + +IRC::get_info(integer); +
    +
    + +
    +This function returns a bit of selected information depending on what the value of the integer is. +Here's a list of the currently supported values: +
    • 0 - xchat version
    • +
    • 1 - your nickname
    • +
    • 2 - channel
    • +
    • 3 - server
    • +
    • 4 - xchatdir
    • +
    • 5 - away status
    • +
    • 6 - network name
    • +
    • 7 - server hostname
    • +
    • 8 - channel topic
    +

    If you are requesting information that isn't available in the current context, then it will return null.

    +

    Any numbers other than the above will return an error message.

    +
    + + +
    + + +
    + +IRC::get_prefs(var); +
    +
    + +
    +This command lets you read the preferences that are set in the xchat configuration file. Just look at the xchat.conf dir to see what variables are available to use with this command. Returns the value of the variable requested or "Unknown Variable" if the variable isn't available. +
    + + +
    + + +
    + +IRC::user_info( nickname ); +
    +
    + +
    +Returns a flat list of information on the nickname specified consisting of... nickname, nick host, and whether they have op or voice in the current context. +
    + + +
    + + +
    + +IRC::channel_list( ); +
    +
    + +
    +This command returns a flat list which contains the current channel, server, and nickname for all channels the client is currently in. You'll have to break the list up into groups of three yourself. No arguments are necessary, or used [currently]. +
    + + +
    + + +
    + +IRC::server_list( ); +
    +
    + +
    +This command returns a flat list of servers. (Note, it is incompatible with xchat 1.8 in that it also returns a list of servers you are NOT connected to as well.) +
    + + +
    + + +
    + +IRC::user_list(channel, server); +
    +
    + +
    +

    Works very much like the dcc_list command below, except that is returns information about the users on the channel provided as first argument. The second argument is the server and is optional.

    +

    NOTE: If a user has both op and voice, only the op flag will be set to 1 by this command in xchat2.

    +
    + + +
    + + +
    + +IRC::user_list_short(channel, server); +
    +
    + +
    +

    A simpler version of IRC::user_list that returns pairs of nick & user@host suitable for assigning to a hash.

    +

    NOTE: If a user has both op and voice, only the op flag will be set to 1 by this command in xchat2.

    +
    + + +
    + + +
    + +IRC::dcc_list( ); +
    +
    + +
    +This command does essentially the same thing as channel_list, giving you the details of each DCC connection currently in progress. I have no idea exactly what is returned because I haven't had a chance to poke at this one much, but suffice it to say that it's a flat list, and the first time you play with it the meaning of the returned values should be pretty obvious. +
    + + +
    + + +
    + +IRC::ignore_list( ); +
    +
    + +
    +This command returns a flat list of the contents of your ignore list. You'll have to play with it a little as I have not had a chance to yet. Works basically the same as the other list commands. +
    + + +
    + + +
    + +Unimplemented commands that were available in xchat 1.8.x +
    +
    + +
    +add_user_list , sub_user_list , clear_user_list, notify_list were available in xchat 1.8.x but are not implemented in xchat 2 at this time. +
    + +
    +
    +

    +This document originally written by Dagmar d'Surreal on March 26th, 1998 for xchat 1.4
    +Updated on July 30th, 1999 by Peter Zelezny
    +Updated on May 16th, 2003 by DaNumber8 to comply with the perl plugin for xchat2 version 2.0.3
    + diff --git a/plugins/perl/xcperl_build.bat b/plugins/perl/xcperl_build.bat new file mode 100644 index 00000000..6f569c47 --- /dev/null +++ b/plugins/perl/xcperl_build.bat @@ -0,0 +1,43 @@ +perl generate_header + +gcc -W -Os -DWIN32 -I "C:\MinGW\include" -I .. -I "C:\ActivePerl-5.8.9\perl\lib\CORE" -L "C:\ActivePerl-5.8.9\perl\bin" -c perl.c -o perl5.8.9.o + +dllwrap --def perl.def --dllname xcperl5.8.9.dll "C:\ActivePerl-5.8.9\perl\bin\perl58.dll" perl5.8.9.o + +strip xcperl5.8.9.dll + + + +gcc -W -Os -DWIN32 -I "C:\MinGW\include" -I .. -I "C:\Perl\lib\CORE" -L "C:\Perl\bin" -c perl.c -o perl5.10.0.o + +dllwrap --def perl.def --dllname xcperl5.10.0.dll "C:\Perl\bin\perl510.dll" perl5.10.0.o + +strip xcperl5.10.0.dll + + +gcc -W -Os -DWIN32 -I "C:\MinGW\include" -I .. -I "C:\ActivePerl-5.10.1\perl\lib\CORE" -L "C:\ActivePerl-5.10.1\perl\bin" -c perl.c -o perl5.10.1.o + +dllwrap --def perl.def --dllname xcperl5.10.1.dll "C:\ActivePerl-5.10.1\perl\bin\perl510.dll" perl5.10.1.o + +strip xcperl5.10.1.dll + + +gcc -W -Os -DWIN32 -I "C:\MinGW\include" -I .. -I "C:\ActivePerl-5.12.1\perl\lib\CORE" -L "C:\ActivePerl-5.12.1\perl\bin" -c perl.c -o perl5.12.1.o + +dllwrap --def perl.def --dllname xcperl5.12.1.dll "C:\ActivePerl-5.12.1\perl\bin\perl512.dll" perl5.12.1.o + +strip xcperl5.12.1.dll + +gcc -W -Os -DWIN32 -I "C:\MinGW\include" -I .. -I "C:\strawberry-perl-5.10.1.3\perl\lib\CORE" -L "C:\strawberry-perl-5.10.1.3\perl\bin" -c perl.c -o perl-strawberry5.10.1.o + +dllwrap --def perl.def --dllname xcperl-strawberry5.10.1.dll "C:\strawberry-perl-5.10.1.3\perl\bin\perl510.dll" perl5.10.1.o + +strip xcperl-strawberry5.10.1.dll + + +gcc -W -Os -DWIN32 -I "C:\MinGW\include" -I .. -I "C:\strawberry-perl-5.12.1.0-portable\perl\lib\CORE" -L "C:\strawberry-perl-5.12.1.0-portable\perl\bin" -c perl.c -o perl-strawberry5.12.1.o + +dllwrap --def perl.def --dllname xcperl-strawberry5.12.1.dll "C:\strawberry-perl-5.12.1.0-portable\perl\bin\perl512.dll" perl5.12.1.o + +strip xcperl-strawberry5.12.1.dll + -- cgit 1.4.1