Sjis
view release on metacpan or search on metacpan
lib/Esjis.pm view on Meta::CPAN
my $quotemeta = '';
while ($expr =~ / \G (\\[*?\\] | $q_char) /oxgc) {
my $char = $1;
if ($char =~ /\A \\[*?\\] \z/oxms) {
$quotemeta .= $char;
}
elsif ($char eq '*') {
$quotemeta .= "(?:$your_char)*",
}
elsif ($char eq '?') {
$quotemeta .= "(?:$your_char)?", # DOS style
# $quotemeta .= "(?:$your_char)", # UNIX style
}
elsif ((my $fc = Esjis::fc($char)) ne $char) {
$quotemeta .= $fc;
}
else {
$quotemeta .= quotemeta $char;
}
}
return $quotemeta;
}
#
# via File::HomeDir::Windows 1.00
#
sub my_home_MSWin32 {
# A lot of unix people and unix-derived tools rely on
# the ability to overload HOME. We will support it too
# so that they can replace raw HOME calls with File::HomeDir.
if (exists $ENV{'HOME'} and $ENV{'HOME'}) {
return $ENV{'HOME'};
}
# Do we have a user profile?
elsif (exists $ENV{'USERPROFILE'} and $ENV{'USERPROFILE'}) {
return $ENV{'USERPROFILE'};
}
# Some Windows use something like $ENV{'HOME'}
elsif (exists $ENV{'HOMEDRIVE'} and exists $ENV{'HOMEPATH'} and $ENV{'HOMEDRIVE'} and $ENV{'HOMEPATH'}) {
return join '', $ENV{'HOMEDRIVE'}, $ENV{'HOMEPATH'};
}
return undef;
}
#
# via File::HomeDir::MacOS9 1.00
#
sub my_home_MacOS {
# Try for $ENV{'HOME'} if we have it
if (defined $ENV{'HOME'}) {
return $ENV{'HOME'};
}
### DESPERATION SETS IN
# We could use the desktop
SCOPE: {
local $@;
CORE::eval {
# Find the desktop via Mac::Files
local $SIG{'__DIE__'} = '';
CORE::require Mac::Files;
my $home = Mac::Files::FindFolder(
Mac::Files::kOnSystemDisk(),
Mac::Files::kDesktopFolderType(),
);
return $home if $home and Esjis::d($home);
};
}
# Desperation on any platform
SCOPE: {
# On some platforms getpwuid dies if called at all
local $SIG{'__DIE__'} = '';
my $home = CORE::eval q{ (getpwuid($<))[7] };
return $home if $home and Esjis::d($home);
}
croak "Could not locate current user's home directory";
}
#
# via File::HomeDir::Unix 1.00
#
sub my_home {
my $home;
if (exists $ENV{'HOME'} and defined $ENV{'HOME'}) {
$home = $ENV{'HOME'};
}
# This is from the original code, but I'm guessing
# it means "login directory" and exists on some Unixes.
elsif (exists $ENV{'LOGDIR'} and $ENV{'LOGDIR'}) {
$home = $ENV{'LOGDIR'};
}
### More-desperate methods
# Light desperation on any (Unixish) platform
else {
$home = CORE::eval q{ (getpwuid($<))[7] };
}
# On Unix in general, a non-existant home means "no home"
# For example, "nobody"-like users might use /nonexistant
if (defined $home and ! Esjis::d($home)) {
$home = undef;
}
return $home;
}
#
# ShiftJIS file lstat (with parameter)
#
sub Esjis::lstat(*) {
local $_ = shift if @_;
if (-e $_) {
lib/Esjis.pm view on Meta::CPAN
return CORE::chdir $dir;
}
elsif (($] =~ /^(?:5\.006|5\.008000)/oxms) and ($^O eq 'MSWin32')) {
local $@;
my $chdir = CORE::eval q{
CORE::require 'jacode.pl';
# P.676 ${^WIDE_SYSTEM_CALLS}
# in Chapter 28: Special Names
# of ISBN 0-596-00027-8 Programming Perl Third Edition.
# P.790 ${^WIDE_SYSTEM_CALLS}
# in Chapter 25: Special Names
# of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
local ${^WIDE_SYSTEM_CALLS} = 1;
return CORE::chdir jcode::utf8($dir,'sjis');
};
if (not $@) {
return $chdir;
}
}
# old idea (Win32 module required)
elsif (0) {
local $@;
my $shortdir = '';
my $chdir = CORE::eval q{
use Win32;
$shortdir = Win32::GetShortPathName($dir);
if ($shortdir ne $dir) {
return CORE::chdir $shortdir;
}
else {
return 0;
}
};
if ($@) {
my @char = $dir =~ /\G (?>$q_char) /oxmsg;
while ($char[-1] eq "\x5C") {
pop @char;
}
$dir = join '', @char;
croak "Perl$] can't chdir to $dir (chr(0x5C) ended path), Win32.pm module may help you";
}
elsif ($shortdir eq $dir) {
my @char = $dir =~ /\G (?>$q_char) /oxmsg;
while ($char[-1] eq "\x5C") {
pop @char;
}
$dir = join '', @char;
croak "Perl$] can't chdir to $dir (chr(0x5C) ended path)";
}
return $chdir;
}
# rejected idea ...
elsif (0) {
# MSDN SetCurrentDirectory function
# http://msdn.microsoft.com/ja-jp/library/windows/desktop/aa365530(v=vs.85).aspx
#
# Data Execution Prevention (DEP)
# http://vlaurie.com/computers2/Articles/dep.htm
#
# Learning x86 assembler with Perl -- Shibuya.pm#11
# http://developer.cybozu.co.jp/takesako/2009/06/perl-x86-shibuy.html
#
# Introduction to Win32::API programming in Perl
# http://d.hatena.ne.jp/TAKESAKO/20090324/1237879559
#
# DynaLoader - Dynamically load C libraries into Perl code
# http://perldoc.perl.org/DynaLoader.html
#
# Basic knowledge of DynaLoader
# http://blog.64p.org/entry/20090313/1236934042
if (($] =~ /^5\.006/oxms) and
($^O eq 'MSWin32') and
($ENV{'PROCESSOR_ARCHITECTURE'} eq 'x86') and
CORE::eval(q{CORE::require 'Dyna'.'Loader'})
) {
my $x86 = join('',
# PUSH Iv
"\x68", pack('P', "$dir\\\0"),
# MOV eAX, Iv
"\xb8", pack('L',
*{'Dyna'.'Loader::dl_find_symbol'}{'CODE'}->(
*{'Dyna'.'Loader::dl_load_file'}{'CODE'}->("$ENV{'SystemRoot'}\\system32\\kernel32.dll"),
'SetCurrentDirectoryA'
)
),
# CALL eAX
"\xff\xd0",
# RETN
"\xc3",
);
*{'Dyna'.'Loader::dl_install_xsub'}{'CODE'}->('_SetCurrentDirectoryA', unpack('L', pack 'P', $x86));
_SetCurrentDirectoryA();
chomp(my $chdir = qx{chdir});
if (Esjis::fc($chdir) eq Esjis::fc($dir)) {
return 1;
}
else {
return 0;
}
}
}
# COMMAND.COM's unhelpful tips:
# Displays a list of files and subdirectories in a directory.
# http://www.lagmonster.org/docs/DOS7/z-dir.html
#
# Syntax:
#
# DIR [drive:] [path] [filename] [/Switches]
#
( run in 3.129 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )