$ospackage='Psh::OS::Win';
die "Could not find OS specific package $ospackage: $@" if $@
;
$ospackage='Psh::OS::Unix';
die "Could not find OS specific package $ospackage: $@" if $@
;
my $name="${ospackage}::$AUTOLOAD";
$name="Psh::OS::fb_$AUTOLOAD" unless ref *{$name}{CODE
} eq 'CODE';
unless (ref *{$name}{CODE
} eq 'CODE') {
Carp
::croak
("Function `$AUTOLOAD' in Psh::OS does not exist.");
# The following code is here because it is most probably
# portable across at least a large number of platforms
# If you need to override them, then modify the symbol
# recursive glob function used for **/anything glob
opendir( DIR
, $dir) || return ();
my @result= map { catdir
($dir,$_) }
grep { /^$pattern$/ } @files;
foreach my $tmp (@files) {
my $tmpdir= catdir
($dir,$tmp);
next if ! -d
$tmpdir || !no_upwards
($tmp);
push @result, _recursive_glob
($pattern, $tmpdir);
$text=~s/(?<!\\)([^a-zA-Z0-9\*\?])/\\$1/g;
# The Perl builtin glob STILL uses csh, furthermore it is
# not possible to supply a base directory... so I guess this
my( $pattern, $dir, $already_absed) = @_;
return () unless $pattern;
$dir=Psh
::Util
::abs_path
($dir) unless $already_absed;
my $home= $ENV{HOME
}||get_home_dir
();
$pattern=~ s
|^\
~/|$home/|;
$pattern=~ s
|^\
~([^/]+)|&get_home_dir
($1)|e
;
return $pattern if $pattern !~ /[*?]/;
# Special recursion handling for **/anything globs
if( $pattern=~ m
:^([^\
*]+/)?\*\*/(.*)$: ) {
my $tlen= length($dir)+1;
$dir= catdir
($dir,$prefix);
$pattern=_escape
($pattern);
$pattern='[^\.]'.$pattern if( substr($pattern,0,2) eq '.*');
@result= map { substr($_,$tlen) } _recursive_glob
($pattern,$dir);
} elsif( $pattern=~ m
:/:) {
# Too difficult to simulate, so use slow variant
$pattern=_escape
($pattern);
@result= eval { CORE
::glob($pattern); };
# The fast variant for simple matches
$pattern=_escape
($pattern);
$pattern='[^\.]'.$pattern if( substr($pattern,0,2) eq '.*');
opendir( DIR
, $dir) || return ();
@result= grep { /^$pattern$/ } readdir(DIR
);
# string signal_name( int )
# Looks up the name of a signal
my @numbers= split ',',$Config::Config
{sig_num
};
@numbers= split ' ',$Config::Config
{sig_num
} if( @numbers==1);
# Strange incompatibility between perl versions
my @names= split ' ',$Config::Config
{sig_name
};
for( my $i=0; $i<$#numbers; $i++)
return $names[$i] if( $numbers[$i]==$signalnum);
# string signal_description( int signal_number | string signal_name )
# returns a descriptive name for the POSIX signals
sub fb_signal_description
{
my $signal_name= signal_name
(shift);
my $desc= Psh
::Locale
::get_text
('sig_description')->{$signal_name};
if( defined($desc) and $desc) {
return "SIG$signal_name - $desc";
return "signal $signal_name";
# Return a name for a temp file
sub fb_get_window_size
{}
sub fb_remove_signal_handlers
{1}
sub fb_setup_signal_handlers
{1}
sub fb_setup_sigsegv_handler
{1}
sub fb_setup_readline_handler
{1}
sub fb_abs_path
{ undef }
# Exit psh - you won't believe it, but exit needs special treatment on
Psh
::Util
::print_debug_class
('i',"[Psh::OS::exit_psh() called]\n");
$ENV{SHELL
} = $Psh::old_shell
if $Psh::old_shell
;
CORE
::exit($_[0]) if $_[0];
return eval { Cwd
::getcwd
(); } || '';
my $type= shift || Psh
::OS
::LOCK_SH
();
while ($count-- and !$status) {
$status= flock($file, $type| Psh
::OS
::LOCK_NB
());
flock($file, Psh
::OS
::LOCK_UN
()| Psh
::OS
::LOCK_NB
());
sub fb_reinstall_resize_handler
{ 1; }
sub fb_install_resize_handler
{
eval '$Psh::term->get_screen_size()';
eval 'use Term::ReadKey;';
sub fb_check_terminal_size
{
} elsif ($handler_type==3) {
($rows,$cols)= $Psh::term
->get_screen_size();
} elsif ($handler_type==1) {
($cols,$rows)= Term
::Size
::chars
();
} elsif ($handler_type==2) {
($cols,$rows)= Term
::ReadKey
::GetTerminalSize
(*STDOUT
);
if($cols && $rows && ($cols > 0) && ($rows > 0)) {
$Psh::term
->Attribs->{screen_width
}=$cols-1;
# We add the necessary functions directly because:
# 1) Changes to File::Spec might be fatal to psh's file location mechanisms
# 2) File::Spec loads unwanted modules
# 3) We don't need it anyway as we need platform-specific OS modules
# Normally I wouldn't do it - but this is a shell and memory
# consumption and startup time is worth something for everyday work...
return grep(!/^\.{1,2}\Z(?!\n)/s, @_);
Psh::OS - Wrapper class for OS dependant stuff
Markus Peter, warp@spin.de
# The following is for Emacs - I hope it won't annoy anyone
# but this could solve the problems with different tab widths etc