晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /lib64/perl5/vendor_perl/IO/ |
Upload File : |
# Documentation at the __END__
package IO::Pty;
use strict;
use Carp;
use IO::Tty qw(TIOCSCTTY TCSETCTTY TIOCNOTTY);
use IO::File;
require POSIX;
use vars qw(@ISA $VERSION);
$VERSION = '1.12'; # keep same as in Tty.pm
@ISA = qw(IO::Handle);
eval { local $^W = 0; undef local $SIG{__DIE__}; require IO::Stty };
push @ISA, "IO::Stty" if (not $@); # if IO::Stty is installed
sub new {
my ($class) = $_[0] || "IO::Pty";
$class = ref($class) if ref($class);
@_ <= 1 or croak 'usage: new $class';
my ($ptyfd, $ttyfd, $ttyname) = pty_allocate();
croak "Cannot open a pty" if not defined $ptyfd;
my $pty = $class->SUPER::new_from_fd($ptyfd, "r+");
croak "Cannot create a new $class from fd $ptyfd: $!" if not $pty;
$pty->autoflush(1);
bless $pty => $class;
my $slave = IO::Tty->new_from_fd($ttyfd, "r+");
croak "Cannot create a new IO::Tty from fd $ttyfd: $!" if not $slave;
$slave->autoflush(1);
${*$pty}{'io_pty_slave'} = $slave;
${*$pty}{'io_pty_ttyname'} = $ttyname;
${*$slave}{'io_tty_ttyname'} = $ttyname;
return $pty;
}
sub ttyname {
@_ == 1 or croak 'usage: $pty->ttyname();';
my $pty = shift;
${*$pty}{'io_pty_ttyname'};
}
sub close_slave {
@_ == 1 or croak 'usage: $pty->close_slave();';
my $master = shift;
if (exists ${*$master}{'io_pty_slave'}) {
close ${*$master}{'io_pty_slave'};
delete ${*$master}{'io_pty_slave'};
}
}
sub slave {
@_ == 1 or croak 'usage: $pty->slave();';
my $master = shift;
if (exists ${*$master}{'io_pty_slave'}) {
return ${*$master}{'io_pty_slave'};
}
my $tty = ${*$master}{'io_pty_ttyname'};
my $slave = new IO::Tty;
$slave->open($tty, O_RDWR | O_NOCTTY) ||
croak "Cannot open slave $tty: $!";
return $slave;
}
sub make_slave_controlling_terminal {
@_ == 1 or croak 'usage: $pty->make_slave_controlling_terminal();';
my $self = shift;
local(*DEVTTY);
# loose controlling terminal explicitly
if (defined TIOCNOTTY) {
if (open (\*DEVTTY, "/dev/tty")) {
ioctl( \*DEVTTY, TIOCNOTTY, 0 );
close \*DEVTTY;
}
}
# Create a new 'session', lose controlling terminal.
if (not POSIX::setsid()) {
warn "setsid() failed, strange behavior may result: $!\r\n" if $^W;
}
if (open(\*DEVTTY, "/dev/tty")) {
warn "Could not disconnect from controlling terminal?!\n" if $^W;
close \*DEVTTY;
}
# now open slave, this should set it as controlling tty on some systems
my $ttyname = ${*$self}{'io_pty_ttyname'};
my $slv = new IO::Tty;
$slv->open($ttyname, O_RDWR)
or croak "Cannot open slave $ttyname: $!";
if (not exists ${*$self}{'io_pty_slave'}) {
${*$self}{'io_pty_slave'} = $slv;
} else {
$slv->close;
}
# Acquire a controlling terminal if this doesn't happen automatically
if (not open(\*DEVTTY, "/dev/tty")) {
if (defined TIOCSCTTY) {
if (not defined ioctl( ${*$self}{'io_pty_slave'}, TIOCSCTTY, 0 )) {
warn "warning: TIOCSCTTY failed, slave might not be set as controlling terminal: $!" if $^W;
}
} elsif (defined TCSETCTTY) {
if (not defined ioctl( ${*$self}{'io_pty_slave'}, TCSETCTTY, 0 )) {
warn "warning: TCSETCTTY failed, slave might not be set as controlling terminal: $!" if $^W;
}
} else {
warn "warning: You have neither TIOCSCTTY nor TCSETCTTY on your system\n" if $^W;
return 0;
}
}
if (not open(\*DEVTTY, "/dev/tty")) {
warn "Error: could not connect pty as controlling terminal!\n";
return undef;
} else {
close \*DEVTTY;
}
return 1;
}
*clone_winsize_from = \&IO::Tty::clone_winsize_from;
*get_winsize = \&IO::Tty::get_winsize;
*set_winsize = \&IO::Tty::set_winsize;
*set_raw = \&IO::Tty::set_raw;
1;
__END__
=head1 NAME
IO::Pty - Pseudo TTY object class
=head1 VERSION
1.12
=head1 SYNOPSIS
use IO::Pty;
$pty = new IO::Pty;
$slave = $pty->slave;
foreach $val (1..10) {
print $pty "$val\n";
$_ = <$slave>;
print "$_";
}
close($slave);
=head1 DESCRIPTION
C<IO::Pty> provides an interface to allow the creation of a pseudo tty.
C<IO::Pty> inherits from C<IO::Handle> and so provide all the methods
defined by the C<IO::Handle> package.
Please note that pty creation is very system-dependend. If you have
problems, see L<IO::Tty> for help.
=head1 CONSTRUCTOR
=over 3
=item new
The C<new> constructor takes no arguments and returns a new file
object which is the master side of the pseudo tty.
=back
=head1 METHODS
=over 4
=item ttyname()
Returns the name of the slave pseudo tty. On UNIX machines this will
be the pathname of the device. Use this name for informational
purpose only, to get a slave filehandle, use slave().
=item slave()
The C<slave> method will return the slave filehandle of the given
master pty, opening it anew if necessary. If IO::Stty is installed,
you can then call C<$slave-E<gt>stty()> to modify the terminal settings.
=item close_slave()
The slave filehandle will be closed and destroyed. This is necessary
in the parent after forking to get rid of the open filehandle,
otherwise the parent will not notice if the child exits. Subsequent
calls of C<slave()> will return a newly opened slave filehandle.
=item make_slave_controlling_terminal()
This will set the slave filehandle as the controlling terminal of the
current process, which will become a session leader, so this should
only be called by a child process after a fork(), e.g. in the callback
to C<sync_exec()> (see L<Proc::SyncExec>). See the C<try> script
(also C<test.pl>) for an example how to correctly spawn a subprocess.
=item set_raw()
Will set the pty to raw. Note that this is a one-way operation, you
need IO::Stty to set the terminal settings to anything else.
On some systems, the master pty is not a tty. This method checks for
that and returns success anyway on such systems. Note that this
method must be called on the slave, and probably should be called on
the master, just to be sure, i.e.
$pty->slave->set_raw();
$pty->set_raw();
=item clone_winsize_from(\*FH)
Gets the terminal size from filehandle FH (which must be a terminal)
and transfers it to the pty. Returns true on success and undef on
failure. Note that this must be called upon the I<slave>, i.e.
$pty->slave->clone_winsize_from(\*STDIN);
On some systems, the master pty also isatty. I actually have no
idea if setting terminal sizes there is passed through to the slave,
so if this method is called for a master that is not a tty, it
silently returns OK.
See the C<try> script for example code how to propagate SIGWINCH.
=item get_winsize()
Returns the terminal size, in a 4-element list.
($row, $col, $xpixel, $ypixel) = $tty->get_winsize()
=item set_winsize($row, $col, $xpixel, $ypixel)
Sets the terminal size. If not specified, C<$xpixel> and C<$ypixel> are set to
0. As with C<clone_winsize_from>, this must be called upon the I<slave>.
=back
=head1 SEE ALSO
L<IO::Tty>, L<IO::Tty::Constant>, L<IO::Handle>, L<Expect>, L<Proc::SyncExec>
=head1 MAILING LISTS
As this module is mainly used by Expect, support for it is available
via the two Expect mailing lists, expectperl-announce and
expectperl-discuss, at
http://lists.sourceforge.net/lists/listinfo/expectperl-announce
and
http://lists.sourceforge.net/lists/listinfo/expectperl-discuss
=head1 AUTHORS
Originally by Graham Barr E<lt>F<gbarr@pobox.com>E<gt>, based on the
Ptty module by Nick Ing-Simmons E<lt>F<nik@tiuk.ti.com>E<gt>.
Now maintained and heavily rewritten by Roland Giersig
E<lt>F<RGiersig@cpan.org>E<gt>.
Contains copyrighted stuff from openssh v3.0p1, authored by
Tatu Ylonen <ylo@cs.hut.fi>, Markus Friedl and Todd C. Miller
<Todd.Miller@courtesan.com>.
=head1 COPYRIGHT
Now all code is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
Nevertheless the above AUTHORS retain their copyrights to the various
parts and want to receive credit if their source code is used.
See the source for details.
=head1 DISCLAIMER
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
In other words: Use at your own risk. Provided as is. Your mileage
may vary. Read the source, Luke!
And finally, just to be sure:
Any Use of This Product, in Any Manner Whatsoever, Will Increase the
Amount of Disorder in the Universe. Although No Liability Is Implied
Herein, the Consumer Is Warned That This Process Will Ultimately Lead
to the Heat Death of the Universe.
=cut