File Coverage

blib/lib/Esjis.pm
Criterion Covered Total %
statement 1208 4331 27.8
branch 1263 4314 29.2
condition 160 511 31.3
subroutine 71 205 34.6
pod 8 149 5.3
total 2710 9510 28.5


line stmt bran cond sub pod time code
1             package Esjis;
2 392     392   11272 use strict;
  392         2099  
  392         19038  
3 392 50   392   10136 BEGIN { $INC{'warnings.pm'} = '' if $] < 5.006 } use warnings;
  392     392   4871  
  392         730  
  392         16899  
4             ######################################################################
5             #
6             # Esjis - Run-time routines for Sjis.pm
7             #
8             # http://search.cpan.org/dist/Char-Sjis/
9             #
10             # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018, 2019 INABA Hitoshi
11             ######################################################################
12              
13 392     392   8107 use 5.00503; # Galapagos Consensus 1998 for primetools
  392         1319  
14             # use 5.008001; # Lancaster Consensus 2013 for toolchains
15              
16             # 12.3. Delaying use Until Runtime
17             # in Chapter 12. Packages, Libraries, and Modules
18             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
19             # (and so on)
20              
21             # Version numbers should be boring
22             # http://www.dagolden.com/index.php/369/version-numbers-should-be-boring/
23             # For the impatient, the disinterested or those who just want to follow
24             # a recipe, my advice for all modules is this:
25             # our $VERSION = "0.001"; # or "0.001_001" for a dev release
26             # $VERSION = eval $VERSION; # No!! because '1.10' makes '1.1'
27              
28 392     392   3739 use vars qw($VERSION);
  392         3168  
  392         52367  
29             $VERSION = '1.22';
30             $VERSION = $VERSION;
31              
32             BEGIN {
33 392 50   392   5305 if ($^X =~ / jperl /oxmsi) {
34 0         0 die __FILE__, ": needs perl(not jperl) 5.00503 or later. (\$^X==$^X)\n";
35             }
36 392         628 if (CORE::ord('A') == 193) {
37             die __FILE__, ": is not US-ASCII script (may be EBCDIC or EBCDIK script).\n";
38             }
39 392         52859 if (CORE::ord('A') != 0x41) {
40             die __FILE__, ": is not US-ASCII script (must be US-ASCII script).\n";
41             }
42             }
43              
44             BEGIN {
45              
46             # instead of utf8.pm
47 392     392   32138 CORE::eval q{
  392     392   5476  
  392     116   765  
  392         47476  
  0         0  
  0         0  
  0         0  
  0         0  
48             no warnings qw(redefine);
49             *utf8::upgrade = sub { CORE::length $_[0] };
50             *utf8::downgrade = sub { 1 };
51             *utf8::encode = sub { };
52             *utf8::decode = sub { 1 };
53             *utf8::is_utf8 = sub { };
54             *utf8::valid = sub { 1 };
55             };
56 392 50       148988 if ($@) {
57 0         0 *utf8::upgrade = sub { CORE::length $_[0] };
  0         0  
58 0         0 *utf8::downgrade = sub { 1 };
  0         0  
59 0         0 *utf8::encode = sub { };
60 0         0 *utf8::decode = sub { 1 };
  0         0  
61 0         0 *utf8::is_utf8 = sub { };
62 0         0 *utf8::valid = sub { 1 };
  0         0  
63             }
64             }
65              
66             # instead of Symbol.pm
67 0         0 BEGIN {
68             sub gensym () {
69 0 0   0 0 0 if ($] < 5.006) {
70 0         0 return \do { local *_ };
  0         0  
71             }
72             else {
73 0         0 return undef;
74             }
75             }
76              
77             sub qualify ($$) {
78 0     1161 0 0 my($name) = @_;
79              
80 1161 50       2866 if (ref $name) {
    50          
    50          
    50          
    50          
    50          
    50          
81 1161         4424 return $name;
82             }
83             elsif (Esjis::index($name,'::') >= 0) {
84 0         0 return $name;
85             }
86             elsif (Esjis::index($name,"'") >= 0) {
87 0         0 return $name;
88             }
89              
90             # special character, "^xyz"
91             elsif ($name =~ /\A \^ [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]+ \z/x) {
92              
93             # RGS 2001-11-05 : translate leading ^X to control-char
94 0         0 $name =~ s{\A \^ ([ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_]) }{'qq(\c'.$1.')'}xee;
  0         0  
95 0         0 return 'main::' . $name;
96             }
97              
98             # Global names
99             elsif ($name =~ /\A (?: ARGV | ARGVOUT | ENV | INC | SIG | STDERR | STDIN | STDOUT ) \z/x) {
100 0         0 return 'main::' . $name;
101             }
102              
103             # or other
104             elsif ($name =~ /\A [^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz] \z/x) {
105 0         0 return 'main::' . $name;
106             }
107              
108             elsif (defined $_[1]) {
109 0         0 return $_[1] . '::' . $name;
110             }
111             else {
112 1161         8874 return (caller)[0] . '::' . $name;
113             }
114             }
115              
116             sub qualify_to_ref ($;$) {
117 0 50   1161 0 0 if (defined $_[1]) {
118 392     392   4161 no strict qw(refs);
  392         681  
  392         27244  
119 1161         3519 return \*{ qualify $_[0], $_[1] };
  0         0  
120             }
121             else {
122 392     392   2270 no strict qw(refs);
  392     0   727  
  392         72277  
123 0         0 return \*{ qualify $_[0], (caller)[0] };
  1161         1880  
124             }
125             }
126             }
127              
128             # P.714 29.2.39. flock
129             # in Chapter 29: Functions
130             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
131              
132             # P.863 flock
133             # in Chapter 27: Functions
134             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
135              
136             sub LOCK_SH() {1}
137             sub LOCK_EX() {2}
138             sub LOCK_UN() {8}
139             sub LOCK_NB() {4}
140              
141             # instead of Carp.pm
142             sub carp;
143             sub croak;
144             sub cluck;
145             sub confess;
146              
147             # 6.18. Matching Multiple-Byte Characters
148             # in Chapter 6. Pattern Matching
149             # of ISBN 978-1-56592-243-3 Perl Perl Cookbook.
150             # (and so on)
151              
152             # regexp of character
153             my $your_char = q{[\x81-\x9F\xE0-\xFC][\x00-\xFF]|[\x00-\xFF]};
154 392     392   2467 use vars qw($qq_char); $qq_char = qr/\\c[\x40-\x5F]|\\?(?:$your_char)/oxms;
  392         4073  
  392         29609  
155 392     392   3599 use vars qw($q_char); $q_char = qr/$your_char/oxms;
  392         827  
  392         636883  
156              
157             #
158             # ShiftJIS character range per length
159             #
160             my %range_tr = ();
161              
162             #
163             # ShiftJIS case conversion
164             #
165             my %lc = ();
166             @lc{qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)} =
167             qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);
168             my %uc = ();
169             @uc{qw(a b c d e f g h i j k l m n o p q r s t u v w x y z)} =
170             qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
171             my %fc = ();
172             @fc{qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)} =
173             qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);
174              
175             if (0) {
176             }
177              
178             elsif (__PACKAGE__ =~ / \b E s j i s \z/oxms) { # escape from build system
179             %range_tr = (
180             1 => [ [0x00..0x80],
181             [0xA0..0xDF],
182             [0xFD..0xFF],
183             ],
184             2 => [ [0x81..0x9F],[0x40..0x7E],
185             [0x81..0x9F],[0x80..0xFC],
186             [0xE0..0xFC],[0x40..0x7E],
187             [0xE0..0xFC],[0x80..0xFC],
188             ],
189             );
190             }
191              
192             else {
193             croak "Don't know my package name '@{[__PACKAGE__]}'";
194             }
195              
196             #
197             # @ARGV wildcard globbing
198             #
199             sub import {
200              
201 1161 50   5   6010 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
202 5         90 my @argv = ();
203 0         0 for (@ARGV) {
204              
205             # has space
206 0 0       0 if (/\A (?:$q_char)*? [ ] /oxms) {
    0          
207 0 0       0 if (my @glob = Esjis::glob(qq{"$_"})) {
208 0         0 push @argv, @glob;
209             }
210             else {
211 0         0 push @argv, $_;
212             }
213             }
214              
215             # has wildcard metachar
216             elsif (/\A (?:$q_char)*? [*?] /oxms) {
217 0 0       0 if (my @glob = Esjis::glob($_)) {
218 0         0 push @argv, @glob;
219             }
220             else {
221 0         0 push @argv, $_;
222             }
223             }
224              
225             # no wildcard globbing
226             else {
227 0         0 push @argv, $_;
228             }
229             }
230 0         0 @ARGV = @argv;
231             }
232              
233 0         0 *Char::ord = \&Sjis::ord;
234 5         23 *Char::ord_ = \&Sjis::ord_;
235 5         15 *Char::reverse = \&Sjis::reverse;
236 5         12 *Char::getc = \&Sjis::getc;
237 5         10 *Char::length = \&Sjis::length;
238 5         10 *Char::substr = \&Sjis::substr;
239 5         122 *Char::index = \&Sjis::index;
240 5         11 *Char::rindex = \&Sjis::rindex;
241 5         10 *Char::eval = \&Sjis::eval;
242 5         18 *Char::escape = \&Sjis::escape;
243 5         10 *Char::escape_token = \&Sjis::escape_token;
244 5         9 *Char::escape_script = \&Sjis::escape_script;
245             }
246              
247             # P.230 Care with Prototypes
248             # in Chapter 6: Subroutines
249             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
250             #
251             # If you aren't careful, you can get yourself into trouble with prototypes.
252             # But if you are careful, you can do a lot of neat things with them. This is
253             # all very powerful, of course, and should only be used in moderation to make
254             # the world a better place.
255              
256             # P.332 Care with Prototypes
257             # in Chapter 7: Subroutines
258             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
259             #
260             # If you aren't careful, you can get yourself into trouble with prototypes.
261             # But if you are careful, you can do a lot of neat things with them. This is
262             # all very powerful, of course, and should only be used in moderation to make
263             # the world a better place.
264              
265             #
266             # Prototypes of subroutines
267             #
268       0     sub unimport {}
269             sub Esjis::split(;$$$);
270             sub Esjis::tr($$$$;$);
271             sub Esjis::chop(@);
272             sub Esjis::index($$;$);
273             sub Esjis::rindex($$;$);
274             sub Esjis::lcfirst(@);
275             sub Esjis::lcfirst_();
276             sub Esjis::lc(@);
277             sub Esjis::lc_();
278             sub Esjis::ucfirst(@);
279             sub Esjis::ucfirst_();
280             sub Esjis::uc(@);
281             sub Esjis::uc_();
282             sub Esjis::fc(@);
283             sub Esjis::fc_();
284             sub Esjis::ignorecase;
285             sub Esjis::classic_character_class;
286             sub Esjis::capture;
287             sub Esjis::chr(;$);
288             sub Esjis::chr_();
289             sub Esjis::filetest;
290             sub Esjis::r(;*@);
291             sub Esjis::w(;*@);
292             sub Esjis::x(;*@);
293             sub Esjis::o(;*@);
294             sub Esjis::R(;*@);
295             sub Esjis::W(;*@);
296             sub Esjis::X(;*@);
297             sub Esjis::O(;*@);
298             sub Esjis::e(;*@);
299             sub Esjis::z(;*@);
300             sub Esjis::s(;*@);
301             sub Esjis::f(;*@);
302             sub Esjis::d(;*@);
303             sub Esjis::l(;*@);
304             sub Esjis::p(;*@);
305             sub Esjis::S(;*@);
306             sub Esjis::b(;*@);
307             sub Esjis::c(;*@);
308             sub Esjis::u(;*@);
309             sub Esjis::g(;*@);
310             sub Esjis::k(;*@);
311             sub Esjis::T(;*@);
312             sub Esjis::B(;*@);
313             sub Esjis::M(;*@);
314             sub Esjis::A(;*@);
315             sub Esjis::C(;*@);
316             sub Esjis::filetest_;
317             sub Esjis::r_();
318             sub Esjis::w_();
319             sub Esjis::x_();
320             sub Esjis::o_();
321             sub Esjis::R_();
322             sub Esjis::W_();
323             sub Esjis::X_();
324             sub Esjis::O_();
325             sub Esjis::e_();
326             sub Esjis::z_();
327             sub Esjis::s_();
328             sub Esjis::f_();
329             sub Esjis::d_();
330             sub Esjis::l_();
331             sub Esjis::p_();
332             sub Esjis::S_();
333             sub Esjis::b_();
334             sub Esjis::c_();
335             sub Esjis::u_();
336             sub Esjis::g_();
337             sub Esjis::k_();
338             sub Esjis::T_();
339             sub Esjis::B_();
340             sub Esjis::M_();
341             sub Esjis::A_();
342             sub Esjis::C_();
343             sub Esjis::glob($);
344             sub Esjis::glob_();
345             sub Esjis::lstat(*);
346             sub Esjis::lstat_();
347             sub Esjis::opendir(*$);
348             sub Esjis::stat(*);
349             sub Esjis::stat_();
350             sub Esjis::unlink(@);
351             sub Esjis::chdir(;$);
352             sub Esjis::do($);
353             sub Esjis::require(;$);
354             sub Esjis::telldir(*);
355              
356             sub Sjis::ord(;$);
357             sub Sjis::ord_();
358             sub Sjis::reverse(@);
359             sub Sjis::getc(;*@);
360             sub Sjis::length(;$);
361             sub Sjis::substr($$;$$);
362             sub Sjis::index($$;$);
363             sub Sjis::rindex($$;$);
364             sub Sjis::escape(;$);
365              
366             #
367             # Regexp work
368             #
369 392         41227 use vars qw(
370             $re_a
371             $re_t
372             $re_n
373             $re_r
374 392     392   5724 );
  392         888  
375              
376             #
377             # Character class
378             #
379 392         96540 use vars qw(
380             $dot
381             $dot_s
382             $eD
383             $eS
384             $eW
385             $eH
386             $eV
387             $eR
388             $eN
389             $not_alnum
390             $not_alpha
391             $not_ascii
392             $not_blank
393             $not_cntrl
394             $not_digit
395             $not_graph
396             $not_lower
397             $not_lower_i
398             $not_print
399             $not_punct
400             $not_space
401             $not_upper
402             $not_upper_i
403             $not_word
404             $not_xdigit
405             $eb
406             $eB
407 392     392   6310 );
  392         1994  
408              
409 392         4310323 use vars qw(
410             $anchor
411             $matched
412 392     392   5285 );
  392         6364  
413             ${Esjis::anchor} = qr{\G(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?}oxms;
414             my $q_char_SADAHIRO_Tomoyuki_2002_01_17 = '';
415              
416             # Quantifiers
417             # {n,m} --- Match at least n but not more than m times
418             #
419             # n and m are limited to non-negative integral values less than a
420             # preset limit defined when perl is built. This is usually 32766 on
421             # the most common platforms.
422             #
423             # The following code is an attempt to solve the above limitations
424             # in a multi-byte anchoring.
425              
426             # avoid "Segmentation fault" and "Error: Parse exception"
427              
428             # perl5101delta
429             # http://perldoc.perl.org/perl5101delta.html
430             # In 5.10.0, the * quantifier in patterns was sometimes treated as {0,32767}
431             # [RT #60034, #60464]. For example, this match would fail:
432             # ("ab" x 32768) =~ /^(ab)*$/
433              
434             # SEE ALSO
435             #
436             # Complex regular subexpression recursion limit
437             # http://www.perlmonks.org/?node_id=810857
438             #
439             # regexp iteration limits
440             # http://www.nntp.perl.org/group/perl.perl5.porters/2009/02/msg144065.html
441             #
442             # latest Perl won't match certain regexes more than 32768 characters long
443             # http://stackoverflow.com/questions/26226630/latest-perl-wont-match-certain-regexes-more-than-32768-characters-long
444             #
445             # Break through the limitations of regular expressions of Perl
446             # http://d.hatena.ne.jp/gfx/20110212/1297512479
447              
448             if (($] >= 5.010001) or
449             # ActivePerl 5.6 or later (include 5.10.0)
450             (defined($ActivePerl::VERSION) and ($ActivePerl::VERSION > 800)) or
451             (($^O eq 'MSWin32') and ($] =~ /\A 5\.006/oxms))
452             ) {
453             my $sbcs = ''; # Single Byte Character Set
454             for my $range (@{ $range_tr{1} }) {
455             $sbcs .= sprintf('\\x%02X-\\x%02X', $range->[0], $range->[-1]);
456             }
457              
458             if (0) {
459             }
460              
461             # other encoding
462             else {
463             ${Esjis::q_char_SADAHIRO_Tomoyuki_2002_01_17} = qr{.*?[$sbcs](?:[^$sbcs][^$sbcs])*?}oxms;
464             # ******* octets not in multiple octet char (always char boundary)
465             # **************** 2 octet chars
466             }
467              
468             ${Esjis::anchor_SADAHIRO_Tomoyuki_2002_01_17} =
469             qr{\G(?(?=.{0,32766}\z)(?:[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?|(?(?=[$sbcs]+\z).*?|(?:${Esjis::q_char_SADAHIRO_Tomoyuki_2002_01_17})))}oxms;
470             # qr{
471             # \G # (1), (2)
472             # (? # (3)
473             # (?=.{0,32766}\z) # (4)
474             # (?:[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?| # (5)
475             # (?(?=[$sbcs]+\z) # (6)
476             # .*?| #(7)
477             # (?:${Esjis::q_char_SADAHIRO_Tomoyuki_2002_01_17}) # (8)
478             # ))}oxms;
479              
480             # avoid: Complex regular subexpression recursion limit (32766) exceeded at here.
481             local $^W = 0;
482             local $SIG{__WARN__} = sub {};
483              
484             if (((('A' x 32768).'B') !~ / ${Esjis::anchor} B /oxms) and
485             ((('A' x 32768).'B') =~ / ${Esjis::anchor_SADAHIRO_Tomoyuki_2002_01_17} B /oxms)
486             ) {
487             ${Esjis::anchor} = ${Esjis::anchor_SADAHIRO_Tomoyuki_2002_01_17};
488             }
489             else {
490             undef ${Esjis::q_char_SADAHIRO_Tomoyuki_2002_01_17};
491             }
492             }
493              
494             # (1)
495             # P.128 Start of match (or end of previous match): \G
496             # P.130 Advanced Use of \G with Perl
497             # in Chapter3: Over view of Regular Expression Features and Flavors
498             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
499              
500             # (2)
501             # P.255 Use leading anchors
502             # P.256 Expose ^ and \G at the front of expressions
503             # in Chapter6: Crafting an Efficient Expression
504             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
505              
506             # (3)
507             # P.138 Conditional: (? if then| else)
508             # in Chapter3: Over view of Regular Expression Features and Flavors
509             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
510              
511             # (4)
512             # perlre
513             # http://perldoc.perl.org/perlre.html
514             # The "*" quantifier is equivalent to {0,} , the "+" quantifier to {1,} ,
515             # and the "?" quantifier to {0,1}, ., n, and m are limited to non-negative
516             # integral values less than a preset limit defined when perl is built.
517             # This is usually 32766 on the most common platforms. The actual limit
518             # can be seen in the error message generated by code such as this:
519             # $_ **= $_ , / {$_} / for 2 .. 42;
520              
521             # (5)
522             # P.1023 Multiple-Byte Anchoring
523             # in Appendix W Perl Code Examples
524             # of ISBN 1-56592-224-7 CJKV Information Processing
525              
526             # (6)
527             # if string has only SBCS (Single Byte Character Set)
528              
529             # (7)
530             # then .*? (isn't limited to 32766)
531              
532             # (8)
533             # else ShiftJIS::Regexp::Const (SADAHIRO Tomoyuki)
534             # http://homepage1.nifty.com/nomenclator/perl/shiftjis.htm#long
535             # http://search.cpan.org/~sadahiro/ShiftJIS-Regexp/
536             # $PadA = ' (?:\A| [\x00-\x80\xA0-\xDF])(?:[\x81-\x9F\xE0-\xFC]{2})*?';
537             # $PadG = '\G(?: |[\x00-\xFF]*?[\x00-\x80\xA0-\xDF])(?:[\x81-\x9F\xE0-\xFC]{2})*?';
538             # $PadGA = '\G(?:\A|(?:[\x81-\x9F\xE0-\xFC]{2})+?|[\x00-\xFF]*?[\x00-\x80\xA0-\xDF] (?:[\x81-\x9F\xE0-\xFC]{2})*?)';
539              
540             ${Esjis::dot} = qr{(?>[^\x81-\x9F\xE0-\xFC\x0A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
541             ${Esjis::dot_s} = qr{(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
542             ${Esjis::eD} = qr{(?>[^\x81-\x9F\xE0-\xFC0-9]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
543              
544             # Vertical tabs are now whitespace
545             # \s in a regex now matches a vertical tab in all circumstances.
546             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
547             # ${Esjis::eS} = qr{(?>[^\x81-\x9F\xE0-\xFC\x09\x0A \x0C\x0D\x20]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
548             # ${Esjis::eS} = qr{(?>[^\x81-\x9F\xE0-\xFC\x09\x0A\x0B\x0C\x0D\x20]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
549             ${Esjis::eS} = qr{(?>[^\x81-\x9F\xE0-\xFC\s]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
550              
551             ${Esjis::eW} = qr{(?>[^\x81-\x9F\xE0-\xFC0-9A-Z_a-z]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
552             ${Esjis::eH} = qr{(?>[^\x81-\x9F\xE0-\xFC\x09\x20]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
553             ${Esjis::eV} = qr{(?>[^\x81-\x9F\xE0-\xFC\x0A\x0B\x0C\x0D]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
554             ${Esjis::eR} = qr{(?>\x0D\x0A|[\x0A\x0D])};
555             ${Esjis::eN} = qr{(?>[^\x81-\x9F\xE0-\xFC\x0A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
556             ${Esjis::not_alnum} = qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
557             ${Esjis::not_alpha} = qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
558             ${Esjis::not_ascii} = qr{(?>[^\x81-\x9F\xE0-\xFC\x00-\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
559             ${Esjis::not_blank} = qr{(?>[^\x81-\x9F\xE0-\xFC\x09\x20]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
560             ${Esjis::not_cntrl} = qr{(?>[^\x81-\x9F\xE0-\xFC\x00-\x1F\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
561             ${Esjis::not_digit} = qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
562             ${Esjis::not_graph} = qr{(?>[^\x81-\x9F\xE0-\xFC\x21-\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
563             ${Esjis::not_lower} = qr{(?>[^\x81-\x9F\xE0-\xFC\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
564             ${Esjis::not_lower_i} = qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])}; # Perl 5.16 compatible
565             # ${Esjis::not_lower_i} = qr{(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])}; # older Perl compatible
566             ${Esjis::not_print} = qr{(?>[^\x81-\x9F\xE0-\xFC\x20-\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
567             ${Esjis::not_punct} = qr{(?>[^\x81-\x9F\xE0-\xFC\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
568             ${Esjis::not_space} = qr{(?>[^\x81-\x9F\xE0-\xFC\s\x0B]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
569             ${Esjis::not_upper} = qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
570             ${Esjis::not_upper_i} = qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])}; # Perl 5.16 compatible
571             # ${Esjis::not_upper_i} = qr{(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])}; # older Perl compatible
572             ${Esjis::not_word} = qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39\x41-\x5A\x5F\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
573             ${Esjis::not_xdigit} = qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39\x41-\x46\x61-\x66]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
574             ${Esjis::eb} = qr{(?:\A(?=[0-9A-Z_a-z])|(?<=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF])(?=[0-9A-Z_a-z])|(?<=[0-9A-Z_a-z])(?=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF]|\z))};
575             ${Esjis::eB} = qr{(?:(?<=[0-9A-Z_a-z])(?=[0-9A-Z_a-z])|(?<=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF])(?=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF]))};
576              
577             # avoid: Name "Esjis::foo" used only once: possible typo at here.
578             ${Esjis::dot} = ${Esjis::dot};
579             ${Esjis::dot_s} = ${Esjis::dot_s};
580             ${Esjis::eD} = ${Esjis::eD};
581             ${Esjis::eS} = ${Esjis::eS};
582             ${Esjis::eW} = ${Esjis::eW};
583             ${Esjis::eH} = ${Esjis::eH};
584             ${Esjis::eV} = ${Esjis::eV};
585             ${Esjis::eR} = ${Esjis::eR};
586             ${Esjis::eN} = ${Esjis::eN};
587             ${Esjis::not_alnum} = ${Esjis::not_alnum};
588             ${Esjis::not_alpha} = ${Esjis::not_alpha};
589             ${Esjis::not_ascii} = ${Esjis::not_ascii};
590             ${Esjis::not_blank} = ${Esjis::not_blank};
591             ${Esjis::not_cntrl} = ${Esjis::not_cntrl};
592             ${Esjis::not_digit} = ${Esjis::not_digit};
593             ${Esjis::not_graph} = ${Esjis::not_graph};
594             ${Esjis::not_lower} = ${Esjis::not_lower};
595             ${Esjis::not_lower_i} = ${Esjis::not_lower_i};
596             ${Esjis::not_print} = ${Esjis::not_print};
597             ${Esjis::not_punct} = ${Esjis::not_punct};
598             ${Esjis::not_space} = ${Esjis::not_space};
599             ${Esjis::not_upper} = ${Esjis::not_upper};
600             ${Esjis::not_upper_i} = ${Esjis::not_upper_i};
601             ${Esjis::not_word} = ${Esjis::not_word};
602             ${Esjis::not_xdigit} = ${Esjis::not_xdigit};
603             ${Esjis::eb} = ${Esjis::eb};
604             ${Esjis::eB} = ${Esjis::eB};
605              
606             #
607             # ShiftJIS split
608             #
609             sub Esjis::split(;$$$) {
610              
611             # P.794 29.2.161. split
612             # in Chapter 29: Functions
613             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
614              
615             # P.951 split
616             # in Chapter 27: Functions
617             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
618              
619 5     0 0 11425 my $pattern = $_[0];
620 0         0 my $string = $_[1];
621 0         0 my $limit = $_[2];
622              
623             # if $pattern is also omitted or is the literal space, " "
624 0 0       0 if (not defined $pattern) {
625 0         0 $pattern = ' ';
626             }
627              
628             # if $string is omitted, the function splits the $_ string
629 0 0       0 if (not defined $string) {
630 0 0       0 if (defined $_) {
631 0         0 $string = $_;
632             }
633             else {
634 0         0 $string = '';
635             }
636             }
637              
638 0         0 my @split = ();
639              
640             # when string is empty
641 0 0       0 if ($string eq '') {
    0          
642              
643             # resulting list value in list context
644 0 0       0 if (wantarray) {
645 0         0 return @split;
646             }
647              
648             # count of substrings in scalar context
649             else {
650 0 0       0 carp "Use of implicit split to \@_ is deprecated" if $^W;
651 0         0 @_ = @split;
652 0         0 return scalar @_;
653             }
654             }
655              
656             # split's first argument is more consistently interpreted
657             #
658             # After some changes earlier in v5.17, split's behavior has been simplified:
659             # if the PATTERN argument evaluates to a string containing one space, it is
660             # treated the way that a literal string containing one space once was.
661             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#split's_first_argument_is_more_consistently_interpreted
662              
663             # if $pattern is also omitted or is the literal space, " ", the function splits
664             # on whitespace, /\s+/, after skipping any leading whitespace
665             # (and so on)
666              
667             elsif ($pattern eq ' ') {
668 0 0       0 if (not defined $limit) {
669 0         0 return CORE::split(' ', $string);
670             }
671             else {
672 0         0 return CORE::split(' ', $string, $limit);
673             }
674             }
675              
676 0         0 local $q_char = $q_char;
677 0 0       0 if (CORE::length($string) > 32766) {
678 0 0       0 if ($string =~ /\A [\x00-\x7F]+ \z/oxms) {
    0          
679 0         0 $q_char = qr{.}s;
680             }
681             elsif (defined ${Esjis::q_char_SADAHIRO_Tomoyuki_2002_01_17}) {
682 0         0 $q_char = ${Esjis::q_char_SADAHIRO_Tomoyuki_2002_01_17};
683             }
684             }
685              
686             # if $limit is negative, it is treated as if an arbitrarily large $limit has been specified
687 0 0 0     0 if ((not defined $limit) or ($limit <= 0)) {
    0          
688              
689             # a pattern capable of matching either the null string or something longer than the
690             # null string will split the value of $string into separate characters wherever it
691             # matches the null string between characters
692             # (and so on)
693              
694 0 0       0 if ('' =~ / \A $pattern \z /xms) {
695 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
696 0         0 my $limit = scalar(() = $string =~ /($pattern)/oxmsg);
697              
698             # P.1024 Appendix W.10 Multibyte Processing
699             # of ISBN 1-56592-224-7 CJKV Information Processing
700             # (and so on)
701              
702             # the //m modifier is assumed when you split on the pattern /^/
703             # (and so on)
704              
705 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
706             # V
707 0   0     0 while ((--$limit > 0) and ($string =~ s/\A((?:$q_char)+?)$pattern//m)) {
708              
709             # if the $pattern contains parentheses, then the substring matched by each pair of parentheses
710             # is included in the resulting list, interspersed with the fields that are ordinarily returned
711             # (and so on)
712              
713 0         0 local $@;
714 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
715 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
716 0         0 push @split, CORE::eval('$' . $digit);
717             }
718             }
719             }
720              
721             else {
722 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
723              
724 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
725             # V
726 0         0 while ($string =~ s/\A((?:$q_char)*?)$pattern//m) {
727 0         0 local $@;
728 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
729 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
730 0         0 push @split, CORE::eval('$' . $digit);
731             }
732             }
733             }
734             }
735              
736             elsif ($limit > 0) {
737 0 0       0 if ('' =~ / \A $pattern \z /xms) {
738 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
739 0   0     0 while ((--$limit > 0) and (CORE::length($string) > 0)) {
740              
741 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
742             # V
743 0 0       0 if ($string =~ s/\A((?:$q_char)+?)$pattern//m) {
744 0         0 local $@;
745 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
746 0         0 push @split, CORE::eval('$' . $digit);
747             }
748             }
749             }
750             }
751             else {
752 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
753 0   0     0 while ((--$limit > 0) and (CORE::length($string) > 0)) {
754              
755 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
756             # V
757 0 0       0 if ($string =~ s/\A((?:$q_char)*?)$pattern//m) {
758 0         0 local $@;
759 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
760 0         0 push @split, CORE::eval('$' . $digit);
761             }
762             }
763             }
764             }
765             }
766              
767 0 0       0 if (CORE::length($string) > 0) {
768 0         0 push @split, $string;
769             }
770              
771             # if $_[2] (NOT "$limit") is omitted or zero, trailing null fields are stripped from the result
772 0 0 0     0 if ((not defined $_[2]) or ($_[2] == 0)) {
773 0   0     0 while ((scalar(@split) >= 1) and ($split[-1] eq '')) {
774 0         0 pop @split;
775             }
776             }
777              
778             # resulting list value in list context
779 0 0       0 if (wantarray) {
780 0         0 return @split;
781             }
782              
783             # count of substrings in scalar context
784             else {
785 0 0       0 carp "Use of implicit split to \@_ is deprecated" if $^W;
786 0         0 @_ = @split;
787 0         0 return scalar @_;
788             }
789             }
790              
791             #
792             # get last subexpression offsets
793             #
794             sub _last_subexpression_offsets {
795 0     0   0 my $pattern = $_[0];
796              
797             # remove comment
798 0         0 $pattern =~ s/\(\?\# .*? \)//oxmsg;
799              
800 0         0 my $modifier = '';
801 0 0       0 if ($pattern =~ /\(\?\^? ([\-A-Za-z]+) :/oxms) {
802 0         0 $modifier = $1;
803 0         0 $modifier =~ s/-[A-Za-z]*//;
804             }
805              
806             # with /x modifier
807 0         0 my @char = ();
808 0 0       0 if ($modifier =~ /x/oxms) {
809 0         0 @char = $pattern =~ /\G((?>
810             [^\x81-\x9F\xE0-\xFC\\\#\[\(]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] |
811             \\ $q_char |
812             \# (?>[^\n]*) $ |
813             \[ (?>(?:[^\x81-\x9F\xE0-\xFC\\\]]|[\x81-\x9F\xE0-\xFC][\x00-\xFF]|\\\\|\\\]|$q_char)+) \] |
814             \(\? |
815             $q_char
816             ))/oxmsg;
817             }
818              
819             # without /x modifier
820             else {
821 0         0 @char = $pattern =~ /\G((?>
822             [^\x81-\x9F\xE0-\xFC\\\[\(]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] |
823             \\ $q_char |
824             \[ (?>(?:[^\x81-\x9F\xE0-\xFC\\\]]|[\x81-\x9F\xE0-\xFC][\x00-\xFF]|\\\\|\\\]|$q_char)+) \] |
825             \(\? |
826             $q_char
827             ))/oxmsg;
828             }
829              
830 0         0 return scalar grep { $_ eq '(' } @char;
  0         0  
831             }
832              
833             #
834             # ShiftJIS transliteration (tr///)
835             #
836             sub Esjis::tr($$$$;$) {
837              
838 0     0 0 0 my $bind_operator = $_[1];
839 0         0 my $searchlist = $_[2];
840 0         0 my $replacementlist = $_[3];
841 0   0     0 my $modifier = $_[4] || '';
842              
843 0 0       0 if ($modifier =~ /r/oxms) {
844 0 0       0 if ($bind_operator =~ / !~ /oxms) {
845 0         0 croak "Using !~ with tr///r doesn't make sense";
846             }
847             }
848              
849 0         0 my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
850 0         0 my @searchlist = _charlist_tr($searchlist);
851 0         0 my @replacementlist = _charlist_tr($replacementlist);
852              
853 0         0 my %tr = ();
854 0         0 for (my $i=0; $i <= $#searchlist; $i++) {
855 0 0       0 if (not exists $tr{$searchlist[$i]}) {
856 0 0 0     0 if (defined $replacementlist[$i] and ($replacementlist[$i] ne '')) {
    0 0        
    0          
857 0         0 $tr{$searchlist[$i]} = $replacementlist[$i];
858             }
859             elsif ($modifier =~ /d/oxms) {
860 0         0 $tr{$searchlist[$i]} = '';
861             }
862             elsif (defined $replacementlist[-1] and ($replacementlist[-1] ne '')) {
863 0         0 $tr{$searchlist[$i]} = $replacementlist[-1];
864             }
865             else {
866 0         0 $tr{$searchlist[$i]} = $searchlist[$i];
867             }
868             }
869             }
870              
871 0         0 my $tr = 0;
872 0         0 my $replaced = '';
873 0 0       0 if ($modifier =~ /c/oxms) {
874 0         0 while (defined(my $char = shift @char)) {
875 0 0       0 if (not exists $tr{$char}) {
876 0 0       0 if (defined $replacementlist[-1]) {
877 0         0 $replaced .= $replacementlist[-1];
878             }
879 0         0 $tr++;
880 0 0       0 if ($modifier =~ /s/oxms) {
881 0   0     0 while (@char and (not exists $tr{$char[0]})) {
882 0         0 shift @char;
883 0         0 $tr++;
884             }
885             }
886             }
887             else {
888 0         0 $replaced .= $char;
889             }
890             }
891             }
892             else {
893 0         0 while (defined(my $char = shift @char)) {
894 0 0       0 if (exists $tr{$char}) {
895 0         0 $replaced .= $tr{$char};
896 0         0 $tr++;
897 0 0       0 if ($modifier =~ /s/oxms) {
898 0   0     0 while (@char and (exists $tr{$char[0]}) and ($tr{$char[0]} eq $tr{$char})) {
      0        
899 0         0 shift @char;
900 0         0 $tr++;
901             }
902             }
903             }
904             else {
905 0         0 $replaced .= $char;
906             }
907             }
908             }
909              
910 0 0       0 if ($modifier =~ /r/oxms) {
911 0         0 return $replaced;
912             }
913             else {
914 0         0 $_[0] = $replaced;
915 0 0       0 if ($bind_operator =~ / !~ /oxms) {
916 0         0 return not $tr;
917             }
918             else {
919 0         0 return $tr;
920             }
921             }
922             }
923              
924             #
925             # ShiftJIS chop
926             #
927             sub Esjis::chop(@) {
928              
929 0     0 0 0 my $chop;
930 0 0       0 if (@_ == 0) {
931 0         0 my @char = /\G (?>$q_char) /oxmsg;
932 0         0 $chop = pop @char;
933 0         0 $_ = join '', @char;
934             }
935             else {
936 0         0 for (@_) {
937 0         0 my @char = /\G (?>$q_char) /oxmsg;
938 0         0 $chop = pop @char;
939 0         0 $_ = join '', @char;
940             }
941             }
942 0         0 return $chop;
943             }
944              
945             #
946             # ShiftJIS index by octet
947             #
948             sub Esjis::index($$;$) {
949              
950 0     2322 1 0 my($str,$substr,$position) = @_;
951 2322   50     4682 $position ||= 0;
952 2322         8365 my $pos = 0;
953              
954 2322         2810 while ($pos < CORE::length($str)) {
955 2322 50       4981 if (CORE::substr($str,$pos,CORE::length($substr)) eq $substr) {
956 41154 0       61340 if ($pos >= $position) {
957 0         0 return $pos;
958             }
959             }
960 0 50       0 if (CORE::substr($str,$pos) =~ /\A ($q_char) /oxms) {
961 41154         92939 $pos += CORE::length($1);
962             }
963             else {
964 41154         67572 $pos += 1;
965             }
966             }
967 0         0 return -1;
968             }
969              
970             #
971             # ShiftJIS reverse index
972             #
973             sub Esjis::rindex($$;$) {
974              
975 2322     0 0 13441 my($str,$substr,$position) = @_;
976 0   0     0 $position ||= CORE::length($str) - 1;
977 0         0 my $pos = 0;
978 0         0 my $rindex = -1;
979              
980 0   0     0 while (($pos < CORE::length($str)) and ($pos <= $position)) {
981 0 0       0 if (CORE::substr($str,$pos,CORE::length($substr)) eq $substr) {
982 0         0 $rindex = $pos;
983             }
984 0 0       0 if (CORE::substr($str,$pos) =~ /\A ($q_char) /oxms) {
985 0         0 $pos += CORE::length($1);
986             }
987             else {
988 0         0 $pos += 1;
989             }
990             }
991 0         0 return $rindex;
992             }
993              
994             #
995             # ShiftJIS lower case first with parameter
996             #
997             sub Esjis::lcfirst(@) {
998 0 0   0 0 0 if (@_) {
999 0         0 my $s = shift @_;
1000 0 0 0     0 if (@_ and wantarray) {
1001 0         0 return Esjis::lc(CORE::substr($s,0,1)) . CORE::substr($s,1), @_;
1002             }
1003             else {
1004 0         0 return Esjis::lc(CORE::substr($s,0,1)) . CORE::substr($s,1);
1005             }
1006             }
1007             else {
1008 0         0 return Esjis::lc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1009             }
1010             }
1011              
1012             #
1013             # ShiftJIS lower case first without parameter
1014             #
1015             sub Esjis::lcfirst_() {
1016 0     0 0 0 return Esjis::lc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1017             }
1018              
1019             #
1020             # ShiftJIS lower case with parameter
1021             #
1022             sub Esjis::lc(@) {
1023 0 0   0 0 0 if (@_) {
1024 0         0 my $s = shift @_;
1025 0 0 0     0 if (@_ and wantarray) {
1026 0 0       0 return join('', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
1027             }
1028             else {
1029 0 0       0 return join('', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  0         0  
1030             }
1031             }
1032             else {
1033 0         0 return Esjis::lc_();
1034             }
1035             }
1036              
1037             #
1038             # ShiftJIS lower case without parameter
1039             #
1040             sub Esjis::lc_() {
1041 0     0 0 0 my $s = $_;
1042 0 0       0 return join '', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
1043             }
1044              
1045             #
1046             # ShiftJIS upper case first with parameter
1047             #
1048             sub Esjis::ucfirst(@) {
1049 0 0   0 0 0 if (@_) {
1050 0         0 my $s = shift @_;
1051 0 0 0     0 if (@_ and wantarray) {
1052 0         0 return Esjis::uc(CORE::substr($s,0,1)) . CORE::substr($s,1), @_;
1053             }
1054             else {
1055 0         0 return Esjis::uc(CORE::substr($s,0,1)) . CORE::substr($s,1);
1056             }
1057             }
1058             else {
1059 0         0 return Esjis::uc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1060             }
1061             }
1062              
1063             #
1064             # ShiftJIS upper case first without parameter
1065             #
1066             sub Esjis::ucfirst_() {
1067 0     0 0 0 return Esjis::uc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1068             }
1069              
1070             #
1071             # ShiftJIS upper case with parameter
1072             #
1073             sub Esjis::uc(@) {
1074 0 50   3628 0 0 if (@_) {
1075 3628         4882 my $s = shift @_;
1076 3628 50 33     4113 if (@_ and wantarray) {
1077 3628 0       5803 return join('', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
1078             }
1079             else {
1080 0 100       0 return join('', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  3628         9048  
1081             }
1082             }
1083             else {
1084 3628         11053 return Esjis::uc_();
1085             }
1086             }
1087              
1088             #
1089             # ShiftJIS upper case without parameter
1090             #
1091             sub Esjis::uc_() {
1092 0     0 0 0 my $s = $_;
1093 0 0       0 return join '', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
1094             }
1095              
1096             #
1097             # ShiftJIS fold case with parameter
1098             #
1099             sub Esjis::fc(@) {
1100 0 50   3931 0 0 if (@_) {
1101 3931         5043 my $s = shift @_;
1102 3931 50 33     4315 if (@_ and wantarray) {
1103 3931 0       6020 return join('', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
1104             }
1105             else {
1106 0 100       0 return join('', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  3931         9132  
1107             }
1108             }
1109             else {
1110 3931         12993 return Esjis::fc_();
1111             }
1112             }
1113              
1114             #
1115             # ShiftJIS fold case without parameter
1116             #
1117             sub Esjis::fc_() {
1118 0     0 0 0 my $s = $_;
1119 0 0       0 return join '', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
1120             }
1121              
1122             #
1123             # ShiftJIS regexp capture
1124             #
1125             {
1126             # 10.3. Creating Persistent Private Variables
1127             # in Chapter 10. Subroutines
1128             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
1129              
1130             my $last_s_matched = 0;
1131              
1132             sub Esjis::capture {
1133 0 0 0 0 1 0 if ($last_s_matched and ($_[0] =~ /\A (?>[1-9][0-9]*) \z/oxms)) {
1134 0         0 return $_[0] + 1;
1135             }
1136 0         0 return $_[0];
1137             }
1138              
1139             # ShiftJIS mark last regexp matched
1140             sub Esjis::matched() {
1141 0     0 0 0 $last_s_matched = 0;
1142             }
1143              
1144             # ShiftJIS mark last s/// matched
1145             sub Esjis::s_matched() {
1146 0     0 0 0 $last_s_matched = 1;
1147             }
1148              
1149             # P.854 31.17. use re
1150             # in Chapter 31. Pragmatic Modules
1151             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
1152              
1153             # P.1026 re
1154             # in Chapter 29. Pragmatic Modules
1155             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1156              
1157             $Esjis::matched = qr/(?{Esjis::matched})/;
1158             }
1159              
1160             #
1161             # ShiftJIS regexp ignore case modifier
1162             #
1163             sub Esjis::ignorecase {
1164              
1165 0     0 0 0 my @string = @_;
1166 0         0 my $metachar = qr/[\@\\|[\]{]/oxms;
1167              
1168             # ignore case of $scalar or @array
1169 0         0 for my $string (@string) {
1170              
1171             # split regexp
1172 0         0 my @char = $string =~ /\G (?>\[\^|\\$q_char|$q_char) /oxmsg;
1173              
1174             # unescape character
1175 0         0 for (my $i=0; $i <= $#char; $i++) {
1176 0 0       0 next if not defined $char[$i];
1177              
1178             # open character class [...]
1179 0 0       0 if ($char[$i] eq '[') {
    0          
    0          
    0          
1180 0         0 my $left = $i;
1181              
1182             # [] make die "unmatched [] in regexp ...\n"
1183              
1184 0 0       0 if ($char[$i+1] eq ']') {
1185 0         0 $i++;
1186             }
1187              
1188 0         0 while (1) {
1189 0 0       0 if (++$i > $#char) {
1190 0         0 croak "Unmatched [] in regexp";
1191             }
1192 0 0       0 if ($char[$i] eq ']') {
1193 0         0 my $right = $i;
1194 0         0 my @charlist = charlist_qr(@char[$left+1..$right-1], 'i');
1195              
1196             # escape character
1197 0         0 for my $char (@charlist) {
1198 0 0       0 if (0) {
    0          
1199             }
1200              
1201             # do not use quotemeta here
1202 0         0 elsif ($char =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
1203 0         0 $char = $1 . '\\' . $2;
1204             }
1205             elsif ($char =~ /\A [.|)] \z/oxms) {
1206 0         0 $char = '\\' . $char;
1207             }
1208             }
1209              
1210             # [...]
1211 0         0 splice @char, $left, $right-$left+1, '(?:' . join('|', @charlist) . ')';
1212              
1213 0         0 $i = $left;
1214 0         0 last;
1215             }
1216             }
1217             }
1218              
1219             # open character class [^...]
1220             elsif ($char[$i] eq '[^') {
1221 0         0 my $left = $i;
1222              
1223             # [^] make die "unmatched [] in regexp ...\n"
1224              
1225 0 0       0 if ($char[$i+1] eq ']') {
1226 0         0 $i++;
1227             }
1228              
1229 0         0 while (1) {
1230 0 0       0 if (++$i > $#char) {
1231 0         0 croak "Unmatched [] in regexp";
1232             }
1233 0 0       0 if ($char[$i] eq ']') {
1234 0         0 my $right = $i;
1235 0         0 my @charlist = charlist_not_qr(@char[$left+1..$right-1], 'i');
1236              
1237             # escape character
1238 0         0 for my $char (@charlist) {
1239 0 0       0 if (0) {
    0          
1240             }
1241              
1242             # do not use quotemeta here
1243 0         0 elsif ($char =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
1244 0         0 $char = $1 . '\\' . $2;
1245             }
1246             elsif ($char =~ /\A [.|)] \z/oxms) {
1247 0         0 $char = '\\' . $char;
1248             }
1249             }
1250              
1251             # [^...]
1252 0         0 splice @char, $left, $right-$left+1, '(?!' . join('|', @charlist) . ")(?:$your_char)";
1253              
1254 0         0 $i = $left;
1255 0         0 last;
1256             }
1257             }
1258             }
1259              
1260             # rewrite classic character class or escape character
1261             elsif (my $char = classic_character_class($char[$i])) {
1262 0         0 $char[$i] = $char;
1263             }
1264              
1265             # with /i modifier
1266             elsif ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) {
1267 0         0 my $uc = Esjis::uc($char[$i]);
1268 0         0 my $fc = Esjis::fc($char[$i]);
1269 0 0       0 if ($uc ne $fc) {
1270 0 0       0 if (CORE::length($fc) == 1) {
1271 0         0 $char[$i] = '[' . $uc . $fc . ']';
1272             }
1273             else {
1274 0         0 $char[$i] = '(?:' . $uc . '|' . $fc . ')';
1275             }
1276             }
1277             }
1278             }
1279              
1280             # characterize
1281 0         0 for (my $i=0; $i <= $#char; $i++) {
1282 0 0       0 next if not defined $char[$i];
1283              
1284 0 0 0     0 if (0) {
    0          
1285             }
1286              
1287             # escape last octet of multiple-octet
1288 0         0 elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
1289 0         0 $char[$i] = $1 . '\\' . $2;
1290             }
1291              
1292             # quote character before ? + * {
1293             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
1294 0 0       0 if ($char[$i-1] !~ /\A [\x00-\xFF] \z/oxms) {
1295 0         0 $char[$i-1] = '(?:' . $char[$i-1] . ')';
1296             }
1297             }
1298             }
1299              
1300 0         0 $string = join '', @char;
1301             }
1302              
1303             # make regexp string
1304 0         0 return @string;
1305             }
1306              
1307             #
1308             # classic character class ( \D \S \W \d \s \w \C \X \H \V \h \v \R \N \b \B )
1309             #
1310             sub Esjis::classic_character_class {
1311 0     5243 0 0 my($char) = @_;
1312              
1313             return {
1314             '\D' => '${Esjis::eD}',
1315             '\S' => '${Esjis::eS}',
1316             '\W' => '${Esjis::eW}',
1317             '\d' => '[0-9]',
1318              
1319             # Before Perl 5.6, \s only matched the five whitespace characters
1320             # tab, newline, form-feed, carriage return, and the space character
1321             # itself, which, taken together, is the character class [\t\n\f\r ].
1322              
1323             # Vertical tabs are now whitespace
1324             # \s in a regex now matches a vertical tab in all circumstances.
1325             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
1326             # \t \n \v \f \r space
1327             # '\s' => '[\x09\x0A \x0C\x0D\x20]',
1328             # '\s' => '[\x09\x0A\x0B\x0C\x0D\x20]',
1329             '\s' => '\s',
1330              
1331             '\w' => '[0-9A-Z_a-z]',
1332             '\C' => '[\x00-\xFF]',
1333             '\X' => 'X',
1334              
1335             # \h \v \H \V
1336              
1337             # P.114 Character Class Shortcuts
1338             # in Chapter 7: In the World of Regular Expressions
1339             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
1340              
1341             # P.357 13.2.3 Whitespace
1342             # in Chapter 13: perlrecharclass: Perl Regular Expression Character Classes
1343             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
1344             #
1345             # 0x00009 CHARACTER TABULATION h s
1346             # 0x0000a LINE FEED (LF) vs
1347             # 0x0000b LINE TABULATION v
1348             # 0x0000c FORM FEED (FF) vs
1349             # 0x0000d CARRIAGE RETURN (CR) vs
1350             # 0x00020 SPACE h s
1351              
1352             # P.196 Table 5-9. Alphanumeric regex metasymbols
1353             # in Chapter 5. Pattern Matching
1354             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1355              
1356             # (and so on)
1357              
1358             '\H' => '${Esjis::eH}',
1359             '\V' => '${Esjis::eV}',
1360             '\h' => '[\x09\x20]',
1361             '\v' => '[\x0A\x0B\x0C\x0D]',
1362             '\R' => '${Esjis::eR}',
1363              
1364             # \N
1365             #
1366             # http://perldoc.perl.org/perlre.html
1367             # Character Classes and other Special Escapes
1368             # Any character but \n (experimental). Not affected by /s modifier
1369              
1370             '\N' => '${Esjis::eN}',
1371              
1372             # \b \B
1373              
1374             # P.180 Boundaries: The \b and \B Assertions
1375             # in Chapter 5: Pattern Matching
1376             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
1377              
1378             # P.219 Boundaries: The \b and \B Assertions
1379             # in Chapter 5: Pattern Matching
1380             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1381              
1382             # \b really means (?:(?<=\w)(?!\w)|(?
1383             # or (?:(?<=\A|\W)(?=\w)|(?<=\w)(?=\W|\z))
1384             '\b' => '${Esjis::eb}',
1385              
1386             # \B really means (?:(?<=\w)(?=\w)|(?
1387             # or (?:(?<=\w)(?=\w)|(?<=\W)(?=\W))
1388             '\B' => '${Esjis::eB}',
1389              
1390 5243   100     7067 }->{$char} || '';
1391             }
1392              
1393             #
1394             # prepare ShiftJIS characters per length
1395             #
1396              
1397             # 1 octet characters
1398             my @chars1 = ();
1399             sub chars1 {
1400 5243 0   0 0 165364 if (@chars1) {
1401 0         0 return @chars1;
1402             }
1403 0 0       0 if (exists $range_tr{1}) {
1404 0         0 my @ranges = @{ $range_tr{1} };
  0         0  
1405 0         0 while (my @range = splice(@ranges,0,1)) {
1406 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1407 0         0 push @chars1, pack 'C', $oct0;
1408             }
1409             }
1410             }
1411 0         0 return @chars1;
1412             }
1413              
1414             # 2 octets characters
1415             my @chars2 = ();
1416             sub chars2 {
1417 0 0   0 0 0 if (@chars2) {
1418 0         0 return @chars2;
1419             }
1420 0 0       0 if (exists $range_tr{2}) {
1421 0         0 my @ranges = @{ $range_tr{2} };
  0         0  
1422 0         0 while (my @range = splice(@ranges,0,2)) {
1423 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1424 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1425 0         0 push @chars2, pack 'CC', $oct0,$oct1;
1426             }
1427             }
1428             }
1429             }
1430 0         0 return @chars2;
1431             }
1432              
1433             # 3 octets characters
1434             my @chars3 = ();
1435             sub chars3 {
1436 0 0   0 0 0 if (@chars3) {
1437 0         0 return @chars3;
1438             }
1439 0 0       0 if (exists $range_tr{3}) {
1440 0         0 my @ranges = @{ $range_tr{3} };
  0         0  
1441 0         0 while (my @range = splice(@ranges,0,3)) {
1442 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1443 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1444 0         0 for my $oct2 (@{$range[2]}) {
  0         0  
1445 0         0 push @chars3, pack 'CCC', $oct0,$oct1,$oct2;
1446             }
1447             }
1448             }
1449             }
1450             }
1451 0         0 return @chars3;
1452             }
1453              
1454             # 4 octets characters
1455             my @chars4 = ();
1456             sub chars4 {
1457 0 0   0 0 0 if (@chars4) {
1458 0         0 return @chars4;
1459             }
1460 0 0       0 if (exists $range_tr{4}) {
1461 0         0 my @ranges = @{ $range_tr{4} };
  0         0  
1462 0         0 while (my @range = splice(@ranges,0,4)) {
1463 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1464 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1465 0         0 for my $oct2 (@{$range[2]}) {
  0         0  
1466 0         0 for my $oct3 (@{$range[3]}) {
  0         0  
1467 0         0 push @chars4, pack 'CCCC', $oct0,$oct1,$oct2,$oct3;
1468             }
1469             }
1470             }
1471             }
1472             }
1473             }
1474 0         0 return @chars4;
1475             }
1476              
1477             #
1478             # ShiftJIS open character list for tr
1479             #
1480             sub _charlist_tr {
1481              
1482 0     0   0 local $_ = shift @_;
1483              
1484             # unescape character
1485 0         0 my @char = ();
1486 0         0 while (not /\G \z/oxmsgc) {
1487 0 0       0 if (/\G (\\0?55|\\x2[Dd]|\\-) /oxmsgc) {
    0          
    0          
    0          
    0          
    0          
    0          
1488 0         0 push @char, '\-';
1489             }
1490             elsif (/\G \\ ([0-7]{2,3}) /oxmsgc) {
1491 0         0 push @char, CORE::chr(oct $1);
1492             }
1493             elsif (/\G \\x ([0-9A-Fa-f]{1,2}) /oxmsgc) {
1494 0         0 push @char, CORE::chr(hex $1);
1495             }
1496             elsif (/\G \\c ([\x40-\x5F]) /oxmsgc) {
1497 0         0 push @char, CORE::chr(CORE::ord($1) & 0x1F);
1498             }
1499             elsif (/\G (\\ [0nrtfbae]) /oxmsgc) {
1500             push @char, {
1501             '\0' => "\0",
1502             '\n' => "\n",
1503             '\r' => "\r",
1504             '\t' => "\t",
1505             '\f' => "\f",
1506             '\b' => "\x08", # \b means backspace in character class
1507             '\a' => "\a",
1508             '\e' => "\e",
1509 0         0 }->{$1};
1510             }
1511             elsif (/\G \\ ($q_char) /oxmsgc) {
1512 0         0 push @char, $1;
1513             }
1514             elsif (/\G ($q_char) /oxmsgc) {
1515 0         0 push @char, $1;
1516             }
1517             }
1518              
1519             # join separated multiple-octet
1520 0         0 @char = join('',@char) =~ /\G (?>\\-|$q_char) /oxmsg;
1521              
1522             # unescape '-'
1523 0         0 my @i = ();
1524 0         0 for my $i (0 .. $#char) {
1525 0 0       0 if ($char[$i] eq '\-') {
    0          
1526 0         0 $char[$i] = '-';
1527             }
1528             elsif ($char[$i] eq '-') {
1529 0 0 0     0 if ((0 < $i) and ($i < $#char)) {
1530 0         0 push @i, $i;
1531             }
1532             }
1533             }
1534              
1535             # open character list (reverse for splice)
1536 0         0 for my $i (CORE::reverse @i) {
1537 0         0 my @range = ();
1538              
1539             # range error
1540 0 0 0     0 if ((CORE::length($char[$i-1]) > CORE::length($char[$i+1])) or ($char[$i-1] gt $char[$i+1])) {
1541 0         0 croak "Invalid tr/// range \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1542             }
1543              
1544             # range of multiple-octet code
1545 0 0       0 if (CORE::length($char[$i-1]) == 1) {
    0          
    0          
    0          
1546 0 0       0 if (CORE::length($char[$i+1]) == 1) {
    0          
    0          
    0          
1547 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars1();
  0         0  
1548             }
1549             elsif (CORE::length($char[$i+1]) == 2) {
1550 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1551 0         0 push @range, grep {$_ le $char[$i+1]} chars2();
  0         0  
1552             }
1553             elsif (CORE::length($char[$i+1]) == 3) {
1554 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1555 0         0 push @range, chars2();
1556 0         0 push @range, grep {$_ le $char[$i+1]} chars3();
  0         0  
1557             }
1558             elsif (CORE::length($char[$i+1]) == 4) {
1559 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1560 0         0 push @range, chars2();
1561 0         0 push @range, chars3();
1562 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1563             }
1564             else {
1565 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1566             }
1567             }
1568             elsif (CORE::length($char[$i-1]) == 2) {
1569 0 0       0 if (CORE::length($char[$i+1]) == 2) {
    0          
    0          
1570 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars2();
  0         0  
1571             }
1572             elsif (CORE::length($char[$i+1]) == 3) {
1573 0         0 push @range, grep {$char[$i-1] le $_} chars2();
  0         0  
1574 0         0 push @range, grep {$_ le $char[$i+1]} chars3();
  0         0  
1575             }
1576             elsif (CORE::length($char[$i+1]) == 4) {
1577 0         0 push @range, grep {$char[$i-1] le $_} chars2();
  0         0  
1578 0         0 push @range, chars3();
1579 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1580             }
1581             else {
1582 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1583             }
1584             }
1585             elsif (CORE::length($char[$i-1]) == 3) {
1586 0 0       0 if (CORE::length($char[$i+1]) == 3) {
    0          
1587 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars3();
  0         0  
1588             }
1589             elsif (CORE::length($char[$i+1]) == 4) {
1590 0         0 push @range, grep {$char[$i-1] le $_} chars3();
  0         0  
1591 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1592             }
1593             else {
1594 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1595             }
1596             }
1597             elsif (CORE::length($char[$i-1]) == 4) {
1598 0 0       0 if (CORE::length($char[$i+1]) == 4) {
1599 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars4();
  0         0  
1600             }
1601             else {
1602 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1603             }
1604             }
1605             else {
1606 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1607             }
1608              
1609 0         0 splice @char, $i-1, 3, @range;
1610             }
1611              
1612 0         0 return @char;
1613             }
1614              
1615             #
1616             # ShiftJIS open character class
1617             #
1618             sub _cc {
1619 0 50   604   0 if (scalar(@_) == 0) {
    100          
    50          
1620 604         1122 die __FILE__, ": subroutine cc got no parameter.\n";
1621             }
1622             elsif (scalar(@_) == 1) {
1623 0         0 return sprintf('\x%02X',$_[0]);
1624             }
1625             elsif (scalar(@_) == 2) {
1626 302 50       895 if ($_[0] > $_[1]) {
    50          
    50          
1627 302         701 die __FILE__, ": subroutine cc got \$_[0] > \$_[1] parameters).\n";
1628             }
1629             elsif ($_[0] == $_[1]) {
1630 0         0 return sprintf('\x%02X',$_[0]);
1631             }
1632             elsif (($_[0]+1) == $_[1]) {
1633 0         0 return sprintf('[\\x%02X\\x%02X]',$_[0],$_[1]);
1634             }
1635             else {
1636 0         0 return sprintf('[\\x%02X-\\x%02X]',$_[0],$_[1]);
1637             }
1638             }
1639             else {
1640 302         1354 die __FILE__, ": subroutine cc got 3 or more parameters (@{[scalar(@_)]} parameters).\n";
  0         0  
1641             }
1642             }
1643              
1644             #
1645             # ShiftJIS octet range
1646             #
1647             sub _octets {
1648 0     688   0 my $length = shift @_;
1649              
1650 688 100       1020 if ($length == 1) {
    50          
    0          
    0          
1651 688         1428 my($a1) = unpack 'C', $_[0];
1652 426         1079 my($z1) = unpack 'C', $_[1];
1653              
1654 426 50       741 if ($a1 > $z1) {
1655 426         773 croak 'Invalid [] range in regexp (CORE::ord(A) > CORE::ord(B)) ' . '\x' . unpack('H*',$a1) . '-\x' . unpack('H*',$z1);
1656             }
1657              
1658 0 50       0 if ($a1 == $z1) {
    50          
1659 426         963 return sprintf('\x%02X',$a1);
1660             }
1661             elsif (($a1+1) == $z1) {
1662 0         0 return sprintf('\x%02X\x%02X',$a1,$z1);
1663             }
1664             else {
1665 0         0 return sprintf('\x%02X-\x%02X',$a1,$z1);
1666             }
1667             }
1668             elsif ($length == 2) {
1669 426         2697 my($a1,$a2) = unpack 'CC', $_[0];
1670 262         553 my($z1,$z2) = unpack 'CC', $_[1];
1671 262         414 my($A1,$A2) = unpack 'CC', $_[2];
1672 262         363 my($Z1,$Z2) = unpack 'CC', $_[3];
1673              
1674 262 100       381 if ($a1 == $z1) {
    50          
1675             return (
1676             # 11111111 222222222222
1677             # A A Z
1678 262         403 _cc($a1) . _cc($a2,$z2), # a2-z2
1679             );
1680             }
1681             elsif (($a1+1) == $z1) {
1682             return (
1683             # 11111111111 222222222222
1684             # A Z A Z
1685 222         337 _cc($a1) . _cc($a2,$Z2), # a2-
1686             _cc( $z1) . _cc($A2,$z2), # -z2
1687             );
1688             }
1689             else {
1690             return (
1691             # 1111111111111111 222222222222
1692             # A Z A Z
1693 40         62 _cc($a1) . _cc($a2,$Z2), # a2-
1694             _cc($a1+1,$z1-1) . _cc($A2,$Z2), # -
1695             _cc( $z1) . _cc($A2,$z2), # -z2
1696             );
1697             }
1698             }
1699             elsif ($length == 3) {
1700 0         0 my($a1,$a2,$a3) = unpack 'CCC', $_[0];
1701 0         0 my($z1,$z2,$z3) = unpack 'CCC', $_[1];
1702 0         0 my($A1,$A2,$A3) = unpack 'CCC', $_[2];
1703 0         0 my($Z1,$Z2,$Z3) = unpack 'CCC', $_[3];
1704              
1705 0 0       0 if ($a1 == $z1) {
    0          
1706 0 0       0 if ($a2 == $z2) {
    0          
1707             return (
1708             # 11111111 22222222 333333333333
1709             # A A A Z
1710 0         0 _cc($a1) . _cc($a2) . _cc($a3,$z3), # a3-z3
1711             );
1712             }
1713             elsif (($a2+1) == $z2) {
1714             return (
1715             # 11111111 22222222222 333333333333
1716             # A A Z A Z
1717 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1718             _cc($a1) . _cc( $z2) . _cc($A3,$z3), # -z3
1719             );
1720             }
1721             else {
1722             return (
1723             # 11111111 2222222222222222 333333333333
1724             # A A Z A Z
1725 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1726             _cc($a1) . _cc($a2+1,$z2-1) . _cc($A3,$Z3), # -
1727             _cc($a1) . _cc( $z2) . _cc($A3,$z3), # -z3
1728             );
1729             }
1730             }
1731             elsif (($a1+1) == $z1) {
1732             return (
1733             # 11111111111 22222222222222 333333333333
1734             # A Z A Z A Z
1735 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1736             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3), # -
1737             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3), # -
1738             _cc( $z1) . _cc( $z2) . _cc($A3,$z3), # -z3
1739             );
1740             }
1741             else {
1742             return (
1743             # 1111111111111111 22222222222222 333333333333
1744             # A Z A Z A Z
1745 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1746             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3), # -
1747             _cc($a1+1,$z1-1) . _cc($A2,$Z2) . _cc($A3,$Z3), # -
1748             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3), # -
1749             _cc( $z1) . _cc( $z2) . _cc($A3,$z3), # -z3
1750             );
1751             }
1752             }
1753             elsif ($length == 4) {
1754 0         0 my($a1,$a2,$a3,$a4) = unpack 'CCCC', $_[0];
1755 0         0 my($z1,$z2,$z3,$z4) = unpack 'CCCC', $_[1];
1756 0         0 my($A1,$A2,$A3,$A4) = unpack 'CCCC', $_[0];
1757 0         0 my($Z1,$Z2,$Z3,$Z4) = unpack 'CCCC', $_[1];
1758              
1759 0 0       0 if ($a1 == $z1) {
    0          
1760 0 0       0 if ($a2 == $z2) {
    0          
1761 0 0       0 if ($a3 == $z3) {
    0          
1762             return (
1763             # 11111111 22222222 33333333 444444444444
1764             # A A A A Z
1765 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$z4), # a4-z4
1766             );
1767             }
1768             elsif (($a3+1) == $z3) {
1769             return (
1770             # 11111111 22222222 33333333333 444444444444
1771             # A A A Z A Z
1772 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1773             _cc($a1) . _cc($a2) . _cc( $z3) . _cc($A4,$z4), # -z4
1774             );
1775             }
1776             else {
1777             return (
1778             # 11111111 22222222 3333333333333333 444444444444
1779             # A A A Z A Z
1780 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1781             _cc($a1) . _cc($a2) . _cc($a3+1,$z3-1) . _cc($A4,$Z4), # -
1782             _cc($a1) . _cc($a2) . _cc( $z3) . _cc($A4,$z4), # -z4
1783             );
1784             }
1785             }
1786             elsif (($a2+1) == $z2) {
1787             return (
1788             # 11111111 22222222222 33333333333333 444444444444
1789             # A A Z A Z A Z
1790 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1791             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1792             _cc($a1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1793             _cc($a1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1794             );
1795             }
1796             else {
1797             return (
1798             # 11111111 2222222222222222 33333333333333 444444444444
1799             # A A Z A Z A Z
1800 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1801             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1802             _cc($a1) . _cc($a2+1,$z2-1) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1803             _cc($a1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1804             _cc($a1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1805             );
1806             }
1807             }
1808             elsif (($a1+1) == $z1) {
1809             return (
1810             # 11111111111 22222222222222 33333333333333 444444444444
1811             # A Z A Z A Z A Z
1812 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1813             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1814             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1815             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1816             _cc( $z1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1817             _cc( $z1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1818             );
1819             }
1820             else {
1821             return (
1822             # 1111111111111111 22222222222222 33333333333333 444444444444
1823             # A Z A Z A Z A Z
1824 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1825             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1826             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1827             _cc($a1+1,$z1-1) . _cc($A2,$Z2) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1828             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1829             _cc( $z1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1830             _cc( $z1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1831             );
1832             }
1833             }
1834             else {
1835 0         0 die __FILE__, ": subroutine _octets got invalid length ($length).\n";
1836             }
1837             }
1838              
1839             #
1840             # ShiftJIS range regexp
1841             #
1842             sub _range_regexp {
1843 0     517   0 my($length,$first,$last) = @_;
1844              
1845 517         1099 my @range_regexp = ();
1846 517 50       725 if (not exists $range_tr{$length}) {
1847 517         1181 return @range_regexp;
1848             }
1849              
1850 0         0 my @ranges = @{ $range_tr{$length} };
  517         669  
1851 517         1178 while (my @range = splice(@ranges,0,$length)) {
1852 517         1463 my $min = '';
1853 1682         2193 my $max = '';
1854 1682         1688 for (my $i=0; $i < $length; $i++) {
1855 1682         2709 $min .= pack 'C', $range[$i][0];
1856 2206         4049 $max .= pack 'C', $range[$i][-1];
1857             }
1858              
1859             # min___max
1860             # FIRST_____________LAST
1861             # (nothing)
1862              
1863 2206 50 66     3908 if ($max lt $first) {
    100 100        
    50 33        
    100 100        
    100 66        
    100 66        
    50 66        
1864             }
1865              
1866             # **********
1867             # min_________max
1868             # FIRST_____________LAST
1869             # **********
1870              
1871             elsif (($min le $first) and ($first le $max) and ($max le $last)) {
1872 1682         12561 push @range_regexp, _octets($length,$first,$max,$min,$max);
1873             }
1874              
1875             # **********************
1876             # min________________max
1877             # FIRST_____________LAST
1878             # **********************
1879              
1880             elsif (($min eq $first) and ($max eq $last)) {
1881 20         79 push @range_regexp, _octets($length,$first,$last,$min,$max);
1882             }
1883              
1884             # *********
1885             # min___max
1886             # FIRST_____________LAST
1887             # *********
1888              
1889             elsif (($first le $min) and ($max le $last)) {
1890 0         0 push @range_regexp, _octets($length,$min,$max,$min,$max);
1891             }
1892              
1893             # **********************
1894             # min__________________________max
1895             # FIRST_____________LAST
1896             # **********************
1897              
1898             elsif (($min le $first) and ($last le $max)) {
1899 40         55 push @range_regexp, _octets($length,$first,$last,$min,$max);
1900             }
1901              
1902             # *********
1903             # min________max
1904             # FIRST_____________LAST
1905             # *********
1906              
1907             elsif (($first le $min) and ($min le $last) and ($last le $max)) {
1908 588         1257 push @range_regexp, _octets($length,$min,$last,$min,$max);
1909             }
1910              
1911             # min___max
1912             # FIRST_____________LAST
1913             # (nothing)
1914              
1915             elsif ($last lt $min) {
1916             }
1917              
1918             else {
1919 40         60 die __FILE__, ": subroutine _range_regexp panic.\n";
1920             }
1921             }
1922              
1923 0         0 return @range_regexp;
1924             }
1925              
1926             #
1927             # ShiftJIS open character list for qr and not qr
1928             #
1929             sub _charlist {
1930              
1931 517     758   1118 my $modifier = pop @_;
1932 758         1123 my @char = @_;
1933              
1934 758 100       1572 my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
1935              
1936             # unescape character
1937 758         1639 for (my $i=0; $i <= $#char; $i++) {
1938              
1939             # escape - to ...
1940 758 100 100     2246 if ($char[$i] eq '-') {
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    100          
    100          
    100          
    100          
1941 2648 100 100     16460 if ((0 < $i) and ($i < $#char)) {
1942 522         1808 $char[$i] = '...';
1943             }
1944             }
1945              
1946             # octal escape sequence
1947             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
1948 497         1057 $char[$i] = octchr($1);
1949             }
1950              
1951             # hexadecimal escape sequence
1952             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
1953 0         0 $char[$i] = hexchr($1);
1954             }
1955              
1956             # \b{...} --> b\{...}
1957             # \B{...} --> B\{...}
1958             # \N{CHARNAME} --> N\{CHARNAME}
1959             # \p{PROPERTY} --> p\{PROPERTY}
1960             # \P{PROPERTY} --> P\{PROPERTY}
1961             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} ) \z/oxms) {
1962 0         0 $char[$i] = $1 . '\\' . $2;
1963             }
1964              
1965             # \p, \P, \X --> p, P, X
1966             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
1967 0         0 $char[$i] = $1;
1968             }
1969              
1970             elsif ($char[$i] =~ /\A \\ ([0-7]{2,3}) \z/oxms) {
1971 0         0 $char[$i] = CORE::chr oct $1;
1972             }
1973             elsif ($char[$i] =~ /\A \\x ([0-9A-Fa-f]{1,2}) \z/oxms) {
1974 0         0 $char[$i] = CORE::chr hex $1;
1975             }
1976             elsif ($char[$i] =~ /\A \\c ([\x40-\x5F]) \z/oxms) {
1977 206         842 $char[$i] = CORE::chr(CORE::ord($1) & 0x1F);
1978             }
1979             elsif ($char[$i] =~ /\A (\\ [0nrtfbaedswDSWHVhvR]) \z/oxms) {
1980             $char[$i] = {
1981             '\0' => "\0",
1982             '\n' => "\n",
1983             '\r' => "\r",
1984             '\t' => "\t",
1985             '\f' => "\f",
1986             '\b' => "\x08", # \b means backspace in character class
1987             '\a' => "\a",
1988             '\e' => "\e",
1989             '\d' => '[0-9]',
1990              
1991             # Vertical tabs are now whitespace
1992             # \s in a regex now matches a vertical tab in all circumstances.
1993             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
1994             # \t \n \v \f \r space
1995             # '\s' => '[\x09\x0A \x0C\x0D\x20]',
1996             # '\s' => '[\x09\x0A\x0B\x0C\x0D\x20]',
1997             '\s' => '\s',
1998              
1999             '\w' => '[0-9A-Z_a-z]',
2000             '\D' => '${Esjis::eD}',
2001             '\S' => '${Esjis::eS}',
2002             '\W' => '${Esjis::eW}',
2003              
2004             '\H' => '${Esjis::eH}',
2005             '\V' => '${Esjis::eV}',
2006             '\h' => '[\x09\x20]',
2007             '\v' => '[\x0A\x0B\x0C\x0D]',
2008             '\R' => '${Esjis::eR}',
2009              
2010 0         0 }->{$1};
2011             }
2012              
2013             # POSIX-style character classes
2014             elsif ($ignorecase and ($char[$i] =~ /\A ( \[\: \^? (?:lower|upper) :\] ) \z/oxms)) {
2015             $char[$i] = {
2016              
2017             '[:lower:]' => '[\x41-\x5A\x61-\x7A]',
2018             '[:upper:]' => '[\x41-\x5A\x61-\x7A]',
2019             '[:^lower:]' => '${Esjis::not_lower_i}',
2020             '[:^upper:]' => '${Esjis::not_upper_i}',
2021              
2022 33         521 }->{$1};
2023             }
2024             elsif ($char[$i] =~ /\A ( \[\: \^? (?:alnum|alpha|ascii|blank|cntrl|digit|graph|lower|print|punct|space|upper|word|xdigit) :\] ) \z/oxms) {
2025             $char[$i] = {
2026              
2027             '[:alnum:]' => '[\x30-\x39\x41-\x5A\x61-\x7A]',
2028             '[:alpha:]' => '[\x41-\x5A\x61-\x7A]',
2029             '[:ascii:]' => '[\x00-\x7F]',
2030             '[:blank:]' => '[\x09\x20]',
2031             '[:cntrl:]' => '[\x00-\x1F\x7F]',
2032             '[:digit:]' => '[\x30-\x39]',
2033             '[:graph:]' => '[\x21-\x7F]',
2034             '[:lower:]' => '[\x61-\x7A]',
2035             '[:print:]' => '[\x20-\x7F]',
2036             '[:punct:]' => '[\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E]',
2037              
2038             # P.174 POSIX-Style Character Classes
2039             # in Chapter 5: Pattern Matching
2040             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2041              
2042             # P.311 11.2.4 Character Classes and other Special Escapes
2043             # in Chapter 11: perlre: Perl regular expressions
2044             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
2045              
2046             # P.210 POSIX-Style Character Classes
2047             # in Chapter 5: Pattern Matching
2048             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2049              
2050             '[:space:]' => '[\s\x0B]', # "\s" plus vertical tab ("\cK")
2051              
2052             '[:upper:]' => '[\x41-\x5A]',
2053             '[:word:]' => '[\x30-\x39\x41-\x5A\x5F\x61-\x7A]',
2054             '[:xdigit:]' => '[\x30-\x39\x41-\x46\x61-\x66]',
2055             '[:^alnum:]' => '${Esjis::not_alnum}',
2056             '[:^alpha:]' => '${Esjis::not_alpha}',
2057             '[:^ascii:]' => '${Esjis::not_ascii}',
2058             '[:^blank:]' => '${Esjis::not_blank}',
2059             '[:^cntrl:]' => '${Esjis::not_cntrl}',
2060             '[:^digit:]' => '${Esjis::not_digit}',
2061             '[:^graph:]' => '${Esjis::not_graph}',
2062             '[:^lower:]' => '${Esjis::not_lower}',
2063             '[:^print:]' => '${Esjis::not_print}',
2064             '[:^punct:]' => '${Esjis::not_punct}',
2065             '[:^space:]' => '${Esjis::not_space}',
2066             '[:^upper:]' => '${Esjis::not_upper}',
2067             '[:^word:]' => '${Esjis::not_word}',
2068             '[:^xdigit:]' => '${Esjis::not_xdigit}',
2069              
2070 8         64 }->{$1};
2071             }
2072             elsif ($char[$i] =~ /\A \\ ($q_char) \z/oxms) {
2073 70         1465 $char[$i] = $1;
2074             }
2075             }
2076              
2077             # open character list
2078 7         41 my @singleoctet = ();
2079 758         1275 my @multipleoctet = ();
2080 758         1048 for (my $i=0; $i <= $#char; ) {
2081              
2082             # escaped -
2083 758 100 100     1644 if (defined($char[$i+1]) and ($char[$i+1] eq '...')) {
    100          
    100          
    50          
    50          
    100          
2084 2151         8429 $i += 1;
2085 497         603 next;
2086             }
2087              
2088             # make range regexp
2089             elsif ($char[$i] eq '...') {
2090              
2091             # range error
2092 497 50       910 if (CORE::length($char[$i-1]) > CORE::length($char[$i+1])) {
    100          
2093 497         1732 croak 'Invalid [] range in regexp (length(A) > length(B)) ' . '\x' . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]);
2094             }
2095             elsif (CORE::length($char[$i-1]) == CORE::length($char[$i+1])) {
2096 0 50       0 if ($char[$i-1] gt $char[$i+1]) {
2097 477         1120 croak 'Invalid [] range in regexp (CORE::ord(A) > CORE::ord(B)) ' . '\x' . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]);
2098             }
2099             }
2100              
2101             # make range regexp per length
2102 0         0 for my $length (CORE::length($char[$i-1]) .. CORE::length($char[$i+1])) {
2103 497         1273 my @regexp = ();
2104              
2105             # is first and last
2106 517 100 100     709 if (($length == CORE::length($char[$i-1])) and ($length == CORE::length($char[$i+1]))) {
    100 33        
    50          
    50          
2107 517         1736 push @regexp, _range_regexp($length, $char[$i-1], $char[$i+1]);
2108             }
2109              
2110             # is first
2111             elsif ($length == CORE::length($char[$i-1])) {
2112 477         1240 push @regexp, _range_regexp($length, $char[$i-1], "\xFF" x $length);
2113             }
2114              
2115             # is inside in first and last
2116             elsif ((CORE::length($char[$i-1]) < $length) and ($length < CORE::length($char[$i+1]))) {
2117 20         69 push @regexp, _range_regexp($length, "\x00" x $length, "\xFF" x $length);
2118             }
2119              
2120             # is last
2121             elsif ($length == CORE::length($char[$i+1])) {
2122 0         0 push @regexp, _range_regexp($length, "\x00" x $length, $char[$i+1]);
2123             }
2124              
2125             else {
2126 20         63 die __FILE__, ": subroutine make_regexp panic.\n";
2127             }
2128              
2129 0 100       0 if ($length == 1) {
2130 517         1000 push @singleoctet, @regexp;
2131             }
2132             else {
2133 386         936 push @multipleoctet, @regexp;
2134             }
2135             }
2136              
2137 131         405 $i += 2;
2138             }
2139              
2140             # with /i modifier
2141             elsif ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) {
2142 497 100       1394 if ($modifier =~ /i/oxms) {
2143 764         1172 my $uc = Esjis::uc($char[$i]);
2144 192         293 my $fc = Esjis::fc($char[$i]);
2145 192 50       293 if ($uc ne $fc) {
2146 192 50       285 if (CORE::length($fc) == 1) {
2147 192         242 push @singleoctet, $uc, $fc;
2148             }
2149             else {
2150 192         314 push @singleoctet, $uc;
2151 0         0 push @multipleoctet, $fc;
2152             }
2153             }
2154             else {
2155 0         0 push @singleoctet, $char[$i];
2156             }
2157             }
2158             else {
2159 0         0 push @singleoctet, $char[$i];
2160             }
2161 572         842 $i += 1;
2162             }
2163              
2164             # single character of single octet code
2165             elsif ($char[$i] =~ /\A (?: \\h ) \z/oxms) {
2166 764         1259 push @singleoctet, "\t", "\x20";
2167 0         0 $i += 1;
2168             }
2169             elsif ($char[$i] =~ /\A (?: \\v ) \z/oxms) {
2170 0         0 push @singleoctet, "\x0A", "\x0B", "\x0C", "\x0D";
2171 0         0 $i += 1;
2172             }
2173             elsif ($char[$i] =~ /\A (?: \\d | \\s | \\w ) \z/oxms) {
2174 0         0 push @singleoctet, $char[$i];
2175 2         5 $i += 1;
2176             }
2177              
2178             # single character of multiple-octet code
2179             else {
2180 2         6 push @multipleoctet, $char[$i];
2181 391         661 $i += 1;
2182             }
2183             }
2184              
2185             # quote metachar
2186 391         630 for (@singleoctet) {
2187 758 50       1433 if ($_ eq '...') {
    100          
    100          
    100          
    100          
2188 1384         5527 $_ = '-';
2189             }
2190             elsif (/\A \n \z/oxms) {
2191 0         0 $_ = '\n';
2192             }
2193             elsif (/\A \r \z/oxms) {
2194 8         18 $_ = '\r';
2195             }
2196             elsif (/\A ([\x00-\x20\x7F-\xFF]) \z/oxms) {
2197 8         29 $_ = sprintf('\x%02X', CORE::ord $1);
2198             }
2199             elsif (/\A [\x00-\xFF] \z/oxms) {
2200 1         6 $_ = quotemeta $_;
2201             }
2202             }
2203 939         1354 for (@multipleoctet) {
2204 758 100       1329 if (/\A ([\x80-\xFF].*) ([\x00-\xFF]) \z/oxms) {
2205 693         1652 $_ = $1 . quotemeta $2;
2206             }
2207             }
2208              
2209             # return character list
2210 307         699 return \@singleoctet, \@multipleoctet;
2211             }
2212              
2213             #
2214             # ShiftJIS octal escape sequence
2215             #
2216             sub octchr {
2217 758     5 0 2481 my($octdigit) = @_;
2218              
2219 5         15 my @binary = ();
2220 5         7 for my $octal (split(//,$octdigit)) {
2221             push @binary, {
2222             '0' => '000',
2223             '1' => '001',
2224             '2' => '010',
2225             '3' => '011',
2226             '4' => '100',
2227             '5' => '101',
2228             '6' => '110',
2229             '7' => '111',
2230 5         22 }->{$octal};
2231             }
2232 50         169 my $binary = join '', @binary;
2233              
2234             my $octchr = {
2235             # 1234567
2236             1 => pack('B*', "0000000$binary"),
2237             2 => pack('B*', "000000$binary"),
2238             3 => pack('B*', "00000$binary"),
2239             4 => pack('B*', "0000$binary"),
2240             5 => pack('B*', "000$binary"),
2241             6 => pack('B*', "00$binary"),
2242             7 => pack('B*', "0$binary"),
2243             0 => pack('B*', "$binary"),
2244              
2245 5         14 }->{CORE::length($binary) % 8};
2246              
2247 5         81 return $octchr;
2248             }
2249              
2250             #
2251             # ShiftJIS hexadecimal escape sequence
2252             #
2253             sub hexchr {
2254 5     5 0 24 my($hexdigit) = @_;
2255              
2256             my $hexchr = {
2257             1 => pack('H*', "0$hexdigit"),
2258             0 => pack('H*', "$hexdigit"),
2259              
2260 5         13 }->{CORE::length($_[0]) % 2};
2261              
2262 5         39 return $hexchr;
2263             }
2264              
2265             #
2266             # ShiftJIS open character list for qr
2267             #
2268             sub charlist_qr {
2269              
2270 5     519 0 19 my $modifier = pop @_;
2271 519         979 my @char = @_;
2272              
2273 519         1327 my($singleoctet, $multipleoctet) = _charlist(@char, $modifier);
2274 519         1478 my @singleoctet = @$singleoctet;
2275 519         1118 my @multipleoctet = @$multipleoctet;
2276              
2277             # return character list
2278 519 100       881 if (scalar(@singleoctet) >= 1) {
2279              
2280             # with /i modifier
2281 519 100       1214 if ($modifier =~ m/i/oxms) {
2282 384         879 my %singleoctet_ignorecase = ();
2283 107         134 for (@singleoctet) {
2284 107   66     166 while (s/ \A \\x(..) - \\x(..) //oxms or s/ \A \\x((..)) //oxms) {
2285 277         822 for my $ord (hex($1) .. hex($2)) {
2286 85         289 my $char = CORE::chr($ord);
2287 1376         1737 my $uc = Esjis::uc($char);
2288 1376         1614 my $fc = Esjis::fc($char);
2289 1376 100       1898 if ($uc eq $fc) {
2290 1376         1859 $singleoctet_ignorecase{unpack 'C*', $char} = 1;
2291             }
2292             else {
2293 787 50       1707 if (CORE::length($fc) == 1) {
2294 589         703 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2295 589         1090 $singleoctet_ignorecase{unpack 'C*', $fc} = 1;
2296             }
2297             else {
2298 589         1342 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2299 0         0 push @multipleoctet, join '', map {sprintf('\x%02X',$_)} unpack 'C*', $fc;
  0         0  
2300             }
2301             }
2302             }
2303             }
2304 0 100       0 if ($_ ne '') {
2305 277         435 $singleoctet_ignorecase{unpack 'C*', $_} = 1;
2306             }
2307             }
2308 192         455 my $i = 0;
2309 107         211 my @singleoctet_ignorecase = ();
2310 107         136 for my $ord (0 .. 255) {
2311 107 100       165 if (exists $singleoctet_ignorecase{$ord}) {
2312 27392         29806 push @{$singleoctet_ignorecase[$i]}, $ord;
  1907         1662  
2313             }
2314             else {
2315 1907         2801 $i++;
2316             }
2317             }
2318 25485         24070 @singleoctet = ();
2319 107         140 for my $range (@singleoctet_ignorecase) {
2320 107 100       243 if (ref $range) {
2321 11082 50       16087 if (scalar(@{$range}) == 1) {
  219 50       208  
2322 219         321 push @singleoctet, sprintf('\x%02X', @{$range}[0]);
  0         0  
2323             }
2324 0         0 elsif (scalar(@{$range}) == 2) {
2325 219         276 push @singleoctet, sprintf('\x%02X\x%02X', @{$range}[0], @{$range}[-1]);
  0         0  
  0         0  
2326             }
2327             else {
2328 0         0 push @singleoctet, sprintf('\x%02X-\x%02X', @{$range}[0], @{$range}[-1]);
  219         241  
  219         248  
2329             }
2330             }
2331             }
2332             }
2333              
2334 219         1014 my $not_anchor = '';
2335 384         572 $not_anchor = '(?![\x81-\x9F\xE0-\xFC])';
2336              
2337 384         505 push @multipleoctet, join('', $not_anchor, '[', @singleoctet, ']' );
2338             }
2339 384 100       965 if (scalar(@multipleoctet) >= 2) {
2340 519         1130 return '(?:' . join('|', @multipleoctet) . ')';
2341             }
2342             else {
2343 131         803 return $multipleoctet[0];
2344             }
2345             }
2346              
2347             #
2348             # ShiftJIS open character list for not qr
2349             #
2350             sub charlist_not_qr {
2351              
2352 388     239 0 1960 my $modifier = pop @_;
2353 239         442 my @char = @_;
2354              
2355 239         531 my($singleoctet, $multipleoctet) = _charlist(@char, $modifier);
2356 239         512 my @singleoctet = @$singleoctet;
2357 239         467 my @multipleoctet = @$multipleoctet;
2358              
2359             # with /i modifier
2360 239 100       353 if ($modifier =~ m/i/oxms) {
2361 239         562 my %singleoctet_ignorecase = ();
2362 128         174 for (@singleoctet) {
2363 128   66     165 while (s/ \A \\x(..) - \\x(..) //oxms or s/ \A \\x((..)) //oxms) {
2364 277         783 for my $ord (hex($1) .. hex($2)) {
2365 85         295 my $char = CORE::chr($ord);
2366 1376         1643 my $uc = Esjis::uc($char);
2367 1376         1651 my $fc = Esjis::fc($char);
2368 1376 100       1847 if ($uc eq $fc) {
2369 1376         1804 $singleoctet_ignorecase{unpack 'C*', $char} = 1;
2370             }
2371             else {
2372 787 50       1608 if (CORE::length($fc) == 1) {
2373 589         704 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2374 589         1036 $singleoctet_ignorecase{unpack 'C*', $fc} = 1;
2375             }
2376             else {
2377 589         1348 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2378 0         0 push @multipleoctet, join '', map {sprintf('\x%02X',$_)} unpack 'C*', $fc;
  0         0  
2379             }
2380             }
2381             }
2382             }
2383 0 100       0 if ($_ ne '') {
2384 277         429 $singleoctet_ignorecase{unpack 'C*', $_} = 1;
2385             }
2386             }
2387 192         402 my $i = 0;
2388 128         153 my @singleoctet_ignorecase = ();
2389 128         219 for my $ord (0 .. 255) {
2390 128 100       196 if (exists $singleoctet_ignorecase{$ord}) {
2391 32768         35465 push @{$singleoctet_ignorecase[$i]}, $ord;
  1907         1611  
2392             }
2393             else {
2394 1907         2712 $i++;
2395             }
2396             }
2397 30861         29038 @singleoctet = ();
2398 128         183 for my $range (@singleoctet_ignorecase) {
2399 128 100       259 if (ref $range) {
2400 11082 50       16196 if (scalar(@{$range}) == 1) {
  219 50       202  
2401 219         300 push @singleoctet, sprintf('\x%02X', @{$range}[0]);
  0         0  
2402             }
2403 0         0 elsif (scalar(@{$range}) == 2) {
2404 219         278 push @singleoctet, sprintf('\x%02X\x%02X', @{$range}[0], @{$range}[-1]);
  0         0  
  0         0  
2405             }
2406             else {
2407 0         0 push @singleoctet, sprintf('\x%02X-\x%02X', @{$range}[0], @{$range}[-1]);
  219         259  
  219         238  
2408             }
2409             }
2410             }
2411             }
2412              
2413             # return character list
2414 219 100       1043 if (scalar(@multipleoctet) >= 1) {
2415 239 100       489 if (scalar(@singleoctet) >= 1) {
2416              
2417             # any character other than multiple-octet and single octet character class
2418 114         177 return '(?!' . join('|', @multipleoctet) . ')(?:[^\x81-\x9F\xE0-\xFC' . join('', @singleoctet) . ']|[\x81-\x9F\xE0-\xFC][\x00-\xFF])';
2419             }
2420             else {
2421              
2422             # any character other than multiple-octet character class
2423 70         451 return '(?!' . join('|', @multipleoctet) . ")(?:$your_char)";
2424             }
2425             }
2426             else {
2427 44 50       257 if (scalar(@singleoctet) >= 1) {
2428              
2429             # any character other than single octet character class
2430 125         214 return '(?:[^\x81-\x9F\xE0-\xFC' . join('', @singleoctet) . ']|[\x81-\x9F\xE0-\xFC][\x00-\xFF])';
2431             }
2432             else {
2433              
2434             # any character
2435 125         706 return "(?:$your_char)";
2436             }
2437             }
2438             }
2439              
2440             #
2441             # open file in read mode
2442             #
2443             sub _open_r {
2444 0     774   0 my(undef,$file) = @_;
2445 392     392   5804 use Fcntl qw(O_RDONLY);
  392         847  
  392         63001  
2446 774         2251 return CORE::sysopen($_[0], $file, &O_RDONLY);
2447             }
2448              
2449             #
2450             # open file in append mode
2451             #
2452             sub _open_a {
2453 774     387   33071 my(undef,$file) = @_;
2454 392     392   6137 use Fcntl qw(O_WRONLY O_APPEND O_CREAT);
  392         2394  
  392         6430842  
2455 387         1185 return CORE::sysopen($_[0], $file, &O_WRONLY|&O_APPEND|&O_CREAT);
2456             }
2457              
2458             #
2459             # safe system
2460             #
2461             sub _systemx {
2462              
2463             # P.707 29.2.33. exec
2464             # in Chapter 29: Functions
2465             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2466             #
2467             # Be aware that in older releases of Perl, exec (and system) did not flush
2468             # your output buffer, so you needed to enable command buffering by setting $|
2469             # on one or more filehandles to avoid lost output in the case of exec, or
2470             # misordererd output in the case of system. This situation was largely remedied
2471             # in the 5.6 release of Perl. (So, 5.005 release not yet.)
2472              
2473             # P.855 exec
2474             # in Chapter 27: Functions
2475             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2476             #
2477             # In very old release of Perl (before v5.6), exec (and system) did not flush
2478             # your output buffer, so you needed to enable command buffering by setting $|
2479             # on one or more filehandles to avoid lost output with exec or misordered
2480             # output with system.
2481              
2482 387     387   63511 $| = 1;
2483              
2484             # P.565 23.1.2. Cleaning Up Your Environment
2485             # in Chapter 23: Security
2486             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2487              
2488             # P.656 Cleaning Up Your Environment
2489             # in Chapter 20: Security
2490             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2491              
2492             # local $ENV{'PATH'} = '.';
2493 387         1760 local @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
2494              
2495             # P.707 29.2.33. exec
2496             # in Chapter 29: Functions
2497             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2498             #
2499             # As we mentioned earlier, exec treats a discrete list of arguments as an
2500             # indication that it should bypass shell processing. However, there is one
2501             # place where you might still get tripped up. The exec call (and system, too)
2502             # will not distinguish between a single scalar argument and an array containing
2503             # only one element.
2504             #
2505             # @args = ("echo surprise"); # just one element in list
2506             # exec @args # still subject to shell escapes
2507             # or die "exec: $!"; # because @args == 1
2508             #
2509             # To avoid this, you can use the PATHNAME syntax, explicitly duplicating the
2510             # first argument as the pathname, which forces the rest of the arguments to be
2511             # interpreted as a list, even if there is only one of them:
2512             #
2513             # exec { $args[0] } @args # safe even with one-argument list
2514             # or die "can't exec @args: $!";
2515              
2516             # P.855 exec
2517             # in Chapter 27: Functions
2518             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2519             #
2520             # As we mentioned earlier, exec treats a discrete list of arguments as a
2521             # directive to bypass shell processing. However, there is one place where
2522             # you might still get tripped up. The exec call (and system, too) cannot
2523             # distinguish between a single scalar argument and an array containing
2524             # only one element.
2525             #
2526             # @args = ("echo surprise"); # just one element in list
2527             # exec @args # still subject to shell escapes
2528             # || die "exec: $!"; # because @args == 1
2529             #
2530             # To avoid this, use the PATHNAME syntax, explicitly duplicating the first
2531             # argument as the pathname, which forces the rest of the arguments to be
2532             # interpreted as a list, even if there is only one of them:
2533             #
2534             # exec { $args[0] } @args # safe even with one-argument list
2535             # || die "can't exec @args: $!";
2536              
2537 387         3883 return CORE::system { $_[0] } @_; # safe even with one-argument list
  387         808  
2538             }
2539              
2540             #
2541             # ShiftJIS order to character (with parameter)
2542             #
2543             sub Esjis::chr(;$) {
2544              
2545 387 0   0 0 41900367 my $c = @_ ? $_[0] : $_;
2546              
2547 0 0       0 if ($c == 0x00) {
2548 0         0 return "\x00";
2549             }
2550             else {
2551 0         0 my @chr = ();
2552 0         0 while ($c > 0) {
2553 0         0 unshift @chr, ($c % 0x100);
2554 0         0 $c = int($c / 0x100);
2555             }
2556 0         0 return pack 'C*', @chr;
2557             }
2558             }
2559              
2560             #
2561             # ShiftJIS order to character (without parameter)
2562             #
2563             sub Esjis::chr_() {
2564              
2565 0     0 0 0 my $c = $_;
2566              
2567 0 0       0 if ($c == 0x00) {
2568 0         0 return "\x00";
2569             }
2570             else {
2571 0         0 my @chr = ();
2572 0         0 while ($c > 0) {
2573 0         0 unshift @chr, ($c % 0x100);
2574 0         0 $c = int($c / 0x100);
2575             }
2576 0         0 return pack 'C*', @chr;
2577             }
2578             }
2579              
2580             #
2581             # ShiftJIS stacked file test expr
2582             #
2583             sub Esjis::filetest {
2584              
2585 0     0 0 0 my $file = pop @_;
2586 0         0 my $filetest = substr(pop @_, 1);
2587              
2588 0 0       0 unless (CORE::eval qq{Esjis::$filetest(\$file)}) {
2589 0         0 return '';
2590             }
2591 0         0 for my $filetest (CORE::reverse @_) {
2592 0 0       0 unless (CORE::eval qq{ $filetest _ }) {
2593 0         0 return '';
2594             }
2595             }
2596 0         0 return 1;
2597             }
2598              
2599             #
2600             # ShiftJIS file test -r expr
2601             #
2602             sub Esjis::r(;*@) {
2603              
2604 0 0   0 0 0 local $_ = shift if @_;
2605 0 0 0     0 croak 'Too many arguments for -r (Esjis::r)' if @_ and not wantarray;
2606              
2607 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2608 0 0       0 return wantarray ? (-r _,@_) : -r _;
2609             }
2610              
2611             # P.908 32.39. Symbol
2612             # in Chapter 32: Standard Modules
2613             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2614              
2615             # P.326 Prototypes
2616             # in Chapter 7: Subroutines
2617             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2618              
2619             # (and so on)
2620              
2621             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2622 0 0       0 return wantarray ? (-r $fh,@_) : -r $fh;
2623             }
2624             elsif (-e $_) {
2625 0 0       0 return wantarray ? (-r _,@_) : -r _;
2626             }
2627             elsif (_MSWin32_5Cended_path($_)) {
2628 0 0       0 if (-d "$_/.") {
2629 0 0       0 return wantarray ? (-r _,@_) : -r _;
2630             }
2631             else {
2632              
2633             # Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Esjis::*()
2634             # on Windows opens the file for the path which has 5c at end.
2635             # (and so on)
2636              
2637 0         0 my $fh = gensym();
2638 0 0       0 if (_open_r($fh, $_)) {
2639 0         0 my $r = -r $fh;
2640 0 0       0 close($fh) or die "Can't close file: $_: $!";
2641 0 0       0 return wantarray ? ($r,@_) : $r;
2642             }
2643             }
2644             }
2645 0 0       0 return wantarray ? (undef,@_) : undef;
2646             }
2647              
2648             #
2649             # ShiftJIS file test -w expr
2650             #
2651             sub Esjis::w(;*@) {
2652              
2653 0 0   0 0 0 local $_ = shift if @_;
2654 0 0 0     0 croak 'Too many arguments for -w (Esjis::w)' if @_ and not wantarray;
2655              
2656 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2657 0 0       0 return wantarray ? (-w _,@_) : -w _;
2658             }
2659             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2660 0 0       0 return wantarray ? (-w $fh,@_) : -w $fh;
2661             }
2662             elsif (-e $_) {
2663 0 0       0 return wantarray ? (-w _,@_) : -w _;
2664             }
2665             elsif (_MSWin32_5Cended_path($_)) {
2666 0 0       0 if (-d "$_/.") {
2667 0 0       0 return wantarray ? (-w _,@_) : -w _;
2668             }
2669             else {
2670 0         0 my $fh = gensym();
2671 0 0       0 if (_open_a($fh, $_)) {
2672 0         0 my $w = -w $fh;
2673 0 0       0 close($fh) or die "Can't close file: $_: $!";
2674 0 0       0 return wantarray ? ($w,@_) : $w;
2675             }
2676             }
2677             }
2678 0 0       0 return wantarray ? (undef,@_) : undef;
2679             }
2680              
2681             #
2682             # ShiftJIS file test -x expr
2683             #
2684             sub Esjis::x(;*@) {
2685              
2686 0 0   0 0 0 local $_ = shift if @_;
2687 0 0 0     0 croak 'Too many arguments for -x (Esjis::x)' if @_ and not wantarray;
2688              
2689 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2690 0 0       0 return wantarray ? (-x _,@_) : -x _;
2691             }
2692             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2693 0 0       0 return wantarray ? (-x $fh,@_) : -x $fh;
2694             }
2695             elsif (-e $_) {
2696 0 0       0 return wantarray ? (-x _,@_) : -x _;
2697             }
2698             elsif (_MSWin32_5Cended_path($_)) {
2699 0 0       0 if (-d "$_/.") {
2700 0 0       0 return wantarray ? (-x _,@_) : -x _;
2701             }
2702             else {
2703 0         0 my $fh = gensym();
2704 0 0       0 if (_open_r($fh, $_)) {
2705 0         0 my $dummy_for_underline_cache = -x $fh;
2706 0 0       0 close($fh) or die "Can't close file: $_: $!";
2707             }
2708              
2709             # filename is not .COM .EXE .BAT .CMD
2710 0 0       0 return wantarray ? ('',@_) : '';
2711             }
2712             }
2713 0 0       0 return wantarray ? (undef,@_) : undef;
2714             }
2715              
2716             #
2717             # ShiftJIS file test -o expr
2718             #
2719             sub Esjis::o(;*@) {
2720              
2721 0 0   0 0 0 local $_ = shift if @_;
2722 0 0 0     0 croak 'Too many arguments for -o (Esjis::o)' if @_ and not wantarray;
2723              
2724 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2725 0 0       0 return wantarray ? (-o _,@_) : -o _;
2726             }
2727             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2728 0 0       0 return wantarray ? (-o $fh,@_) : -o $fh;
2729             }
2730             elsif (-e $_) {
2731 0 0       0 return wantarray ? (-o _,@_) : -o _;
2732             }
2733             elsif (_MSWin32_5Cended_path($_)) {
2734 0 0       0 if (-d "$_/.") {
2735 0 0       0 return wantarray ? (-o _,@_) : -o _;
2736             }
2737             else {
2738 0         0 my $fh = gensym();
2739 0 0       0 if (_open_r($fh, $_)) {
2740 0         0 my $o = -o $fh;
2741 0 0       0 close($fh) or die "Can't close file: $_: $!";
2742 0 0       0 return wantarray ? ($o,@_) : $o;
2743             }
2744             }
2745             }
2746 0 0       0 return wantarray ? (undef,@_) : undef;
2747             }
2748              
2749             #
2750             # ShiftJIS file test -R expr
2751             #
2752             sub Esjis::R(;*@) {
2753              
2754 0 0   0 0 0 local $_ = shift if @_;
2755 0 0 0     0 croak 'Too many arguments for -R (Esjis::R)' if @_ and not wantarray;
2756              
2757 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2758 0 0       0 return wantarray ? (-R _,@_) : -R _;
2759             }
2760             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2761 0 0       0 return wantarray ? (-R $fh,@_) : -R $fh;
2762             }
2763             elsif (-e $_) {
2764 0 0       0 return wantarray ? (-R _,@_) : -R _;
2765             }
2766             elsif (_MSWin32_5Cended_path($_)) {
2767 0 0       0 if (-d "$_/.") {
2768 0 0       0 return wantarray ? (-R _,@_) : -R _;
2769             }
2770             else {
2771 0         0 my $fh = gensym();
2772 0 0       0 if (_open_r($fh, $_)) {
2773 0         0 my $R = -R $fh;
2774 0 0       0 close($fh) or die "Can't close file: $_: $!";
2775 0 0       0 return wantarray ? ($R,@_) : $R;
2776             }
2777             }
2778             }
2779 0 0       0 return wantarray ? (undef,@_) : undef;
2780             }
2781              
2782             #
2783             # ShiftJIS file test -W expr
2784             #
2785             sub Esjis::W(;*@) {
2786              
2787 0 0   0 0 0 local $_ = shift if @_;
2788 0 0 0     0 croak 'Too many arguments for -W (Esjis::W)' if @_ and not wantarray;
2789              
2790 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2791 0 0       0 return wantarray ? (-W _,@_) : -W _;
2792             }
2793             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2794 0 0       0 return wantarray ? (-W $fh,@_) : -W $fh;
2795             }
2796             elsif (-e $_) {
2797 0 0       0 return wantarray ? (-W _,@_) : -W _;
2798             }
2799             elsif (_MSWin32_5Cended_path($_)) {
2800 0 0       0 if (-d "$_/.") {
2801 0 0       0 return wantarray ? (-W _,@_) : -W _;
2802             }
2803             else {
2804 0         0 my $fh = gensym();
2805 0 0       0 if (_open_a($fh, $_)) {
2806 0         0 my $W = -W $fh;
2807 0 0       0 close($fh) or die "Can't close file: $_: $!";
2808 0 0       0 return wantarray ? ($W,@_) : $W;
2809             }
2810             }
2811             }
2812 0 0       0 return wantarray ? (undef,@_) : undef;
2813             }
2814              
2815             #
2816             # ShiftJIS file test -X expr
2817             #
2818             sub Esjis::X(;*@) {
2819              
2820 0 0   0 1 0 local $_ = shift if @_;
2821 0 0 0     0 croak 'Too many arguments for -X (Esjis::X)' if @_ and not wantarray;
2822              
2823 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2824 0 0       0 return wantarray ? (-X _,@_) : -X _;
2825             }
2826             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2827 0 0       0 return wantarray ? (-X $fh,@_) : -X $fh;
2828             }
2829             elsif (-e $_) {
2830 0 0       0 return wantarray ? (-X _,@_) : -X _;
2831             }
2832             elsif (_MSWin32_5Cended_path($_)) {
2833 0 0       0 if (-d "$_/.") {
2834 0 0       0 return wantarray ? (-X _,@_) : -X _;
2835             }
2836             else {
2837 0         0 my $fh = gensym();
2838 0 0       0 if (_open_r($fh, $_)) {
2839 0         0 my $dummy_for_underline_cache = -X $fh;
2840 0 0       0 close($fh) or die "Can't close file: $_: $!";
2841             }
2842              
2843             # filename is not .COM .EXE .BAT .CMD
2844 0 0       0 return wantarray ? ('',@_) : '';
2845             }
2846             }
2847 0 0       0 return wantarray ? (undef,@_) : undef;
2848             }
2849              
2850             #
2851             # ShiftJIS file test -O expr
2852             #
2853             sub Esjis::O(;*@) {
2854              
2855 0 0   0 0 0 local $_ = shift if @_;
2856 0 0 0     0 croak 'Too many arguments for -O (Esjis::O)' if @_ and not wantarray;
2857              
2858 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2859 0 0       0 return wantarray ? (-O _,@_) : -O _;
2860             }
2861             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2862 0 0       0 return wantarray ? (-O $fh,@_) : -O $fh;
2863             }
2864             elsif (-e $_) {
2865 0 0       0 return wantarray ? (-O _,@_) : -O _;
2866             }
2867             elsif (_MSWin32_5Cended_path($_)) {
2868 0 0       0 if (-d "$_/.") {
2869 0 0       0 return wantarray ? (-O _,@_) : -O _;
2870             }
2871             else {
2872 0         0 my $fh = gensym();
2873 0 0       0 if (_open_r($fh, $_)) {
2874 0         0 my $O = -O $fh;
2875 0 0       0 close($fh) or die "Can't close file: $_: $!";
2876 0 0       0 return wantarray ? ($O,@_) : $O;
2877             }
2878             }
2879             }
2880 0 0       0 return wantarray ? (undef,@_) : undef;
2881             }
2882              
2883             #
2884             # ShiftJIS file test -e expr
2885             #
2886             sub Esjis::e(;*@) {
2887              
2888 0 50   774 0 0 local $_ = shift if @_;
2889 774 50 33     3655 croak 'Too many arguments for -e (Esjis::e)' if @_ and not wantarray;
2890              
2891 774         2482 local $^W = 0;
2892 774     774   2401 local $SIG{__WARN__} = sub {}; # telldir() attempted on invalid dirhandle at here
2893              
2894 774         4843 my $fh = qualify_to_ref $_;
2895 774 50       2477 if ($_ eq '_') {
    50          
    50          
    50          
    50          
2896 774 0       3309 return wantarray ? (-e _,@_) : -e _;
2897             }
2898              
2899             # return false if directory handle
2900             elsif (defined Esjis::telldir($fh)) {
2901 0 0       0 return wantarray ? ('',@_) : '';
2902             }
2903              
2904             # return true if file handle
2905             elsif (defined fileno $fh) {
2906 0 0       0 return wantarray ? (1,@_) : 1;
2907             }
2908              
2909             elsif (-e $_) {
2910 0 0       0 return wantarray ? (1,@_) : 1;
2911             }
2912             elsif (_MSWin32_5Cended_path($_)) {
2913 0 0       0 if (-d "$_/.") {
2914 0 0       0 return wantarray ? (1,@_) : 1;
2915             }
2916             else {
2917 0         0 my $fh = gensym();
2918 0 0       0 if (_open_r($fh, $_)) {
2919 0         0 my $e = -e $fh;
2920 0 0       0 close($fh) or die "Can't close file: $_: $!";
2921 0 0       0 return wantarray ? ($e,@_) : $e;
2922             }
2923             }
2924             }
2925 0 50       0 return wantarray ? (undef,@_) : undef;
2926             }
2927              
2928             #
2929             # ShiftJIS file test -z expr
2930             #
2931             sub Esjis::z(;*@) {
2932              
2933 774 0   0 0 7042 local $_ = shift if @_;
2934 0 0 0     0 croak 'Too many arguments for -z (Esjis::z)' if @_ and not wantarray;
2935              
2936 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2937 0 0       0 return wantarray ? (-z _,@_) : -z _;
2938             }
2939             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2940 0 0       0 return wantarray ? (-z $fh,@_) : -z $fh;
2941             }
2942             elsif (-e $_) {
2943 0 0       0 return wantarray ? (-z _,@_) : -z _;
2944             }
2945             elsif (_MSWin32_5Cended_path($_)) {
2946 0 0       0 if (-d "$_/.") {
2947 0 0       0 return wantarray ? (-z _,@_) : -z _;
2948             }
2949             else {
2950 0         0 my $fh = gensym();
2951 0 0       0 if (_open_r($fh, $_)) {
2952 0         0 my $z = -z $fh;
2953 0 0       0 close($fh) or die "Can't close file: $_: $!";
2954 0 0       0 return wantarray ? ($z,@_) : $z;
2955             }
2956             }
2957             }
2958 0 0       0 return wantarray ? (undef,@_) : undef;
2959             }
2960              
2961             #
2962             # ShiftJIS file test -s expr
2963             #
2964             sub Esjis::s(;*@) {
2965              
2966 0 0   0 0 0 local $_ = shift if @_;
2967 0 0 0     0 croak 'Too many arguments for -s (Esjis::s)' if @_ and not wantarray;
2968              
2969 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2970 0 0       0 return wantarray ? (-s _,@_) : -s _;
2971             }
2972             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2973 0 0       0 return wantarray ? (-s $fh,@_) : -s $fh;
2974             }
2975             elsif (-e $_) {
2976 0 0       0 return wantarray ? (-s _,@_) : -s _;
2977             }
2978             elsif (_MSWin32_5Cended_path($_)) {
2979 0 0       0 if (-d "$_/.") {
2980 0 0       0 return wantarray ? (-s _,@_) : -s _;
2981             }
2982             else {
2983 0         0 my $fh = gensym();
2984 0 0       0 if (_open_r($fh, $_)) {
2985 0         0 my $s = -s $fh;
2986 0 0       0 close($fh) or die "Can't close file: $_: $!";
2987 0 0       0 return wantarray ? ($s,@_) : $s;
2988             }
2989             }
2990             }
2991 0 0       0 return wantarray ? (undef,@_) : undef;
2992             }
2993              
2994             #
2995             # ShiftJIS file test -f expr
2996             #
2997             sub Esjis::f(;*@) {
2998              
2999 0 0   0 0 0 local $_ = shift if @_;
3000 0 0 0     0 croak 'Too many arguments for -f (Esjis::f)' if @_ and not wantarray;
3001              
3002 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3003 0 0       0 return wantarray ? (-f _,@_) : -f _;
3004             }
3005             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3006 0 0       0 return wantarray ? (-f $fh,@_) : -f $fh;
3007             }
3008             elsif (-e $_) {
3009 0 0       0 return wantarray ? (-f _,@_) : -f _;
3010             }
3011             elsif (_MSWin32_5Cended_path($_)) {
3012 0 0       0 if (-d "$_/.") {
3013 0 0       0 return wantarray ? ('',@_) : '';
3014             }
3015             else {
3016 0         0 my $fh = gensym();
3017 0 0       0 if (_open_r($fh, $_)) {
3018 0         0 my $f = -f $fh;
3019 0 0       0 close($fh) or die "Can't close file: $_: $!";
3020 0 0       0 return wantarray ? ($f,@_) : $f;
3021             }
3022             }
3023             }
3024 0 0       0 return wantarray ? (undef,@_) : undef;
3025             }
3026              
3027             #
3028             # ShiftJIS file test -d expr
3029             #
3030             sub Esjis::d(;*@) {
3031              
3032 0 0   0 0 0 local $_ = shift if @_;
3033 0 0 0     0 croak 'Too many arguments for -d (Esjis::d)' if @_ and not wantarray;
3034              
3035 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3036 0 0       0 return wantarray ? (-d _,@_) : -d _;
3037             }
3038              
3039             # return false if file handle or directory handle
3040             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3041 0 0       0 return wantarray ? ('',@_) : '';
3042             }
3043             elsif (-e $_) {
3044 0 0       0 return wantarray ? (-d _,@_) : -d _;
3045             }
3046             elsif (_MSWin32_5Cended_path($_)) {
3047 0 0       0 return wantarray ? (-d "$_/.",@_) : -d "$_/.";
3048             }
3049 0 0       0 return wantarray ? (undef,@_) : undef;
3050             }
3051              
3052             #
3053             # ShiftJIS file test -l expr
3054             #
3055             sub Esjis::l(;*@) {
3056              
3057 0 0   0 0 0 local $_ = shift if @_;
3058 0 0 0     0 croak 'Too many arguments for -l (Esjis::l)' if @_ and not wantarray;
3059              
3060 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3061 0 0       0 return wantarray ? (-l _,@_) : -l _;
3062             }
3063             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3064 0 0       0 return wantarray ? (-l $fh,@_) : -l $fh;
3065             }
3066             elsif (-e $_) {
3067 0 0       0 return wantarray ? (-l _,@_) : -l _;
3068             }
3069             elsif (_MSWin32_5Cended_path($_)) {
3070 0 0       0 if (-d "$_/.") {
3071 0 0       0 return wantarray ? (-l _,@_) : -l _;
3072             }
3073             else {
3074 0         0 my $fh = gensym();
3075 0 0       0 if (_open_r($fh, $_)) {
3076 0         0 my $l = -l $fh;
3077 0 0       0 close($fh) or die "Can't close file: $_: $!";
3078 0 0       0 return wantarray ? ($l,@_) : $l;
3079             }
3080             }
3081             }
3082 0 0       0 return wantarray ? (undef,@_) : undef;
3083             }
3084              
3085             #
3086             # ShiftJIS file test -p expr
3087             #
3088             sub Esjis::p(;*@) {
3089              
3090 0 0   0 0 0 local $_ = shift if @_;
3091 0 0 0     0 croak 'Too many arguments for -p (Esjis::p)' if @_ and not wantarray;
3092              
3093 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3094 0 0       0 return wantarray ? (-p _,@_) : -p _;
3095             }
3096             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3097 0 0       0 return wantarray ? (-p $fh,@_) : -p $fh;
3098             }
3099             elsif (-e $_) {
3100 0 0       0 return wantarray ? (-p _,@_) : -p _;
3101             }
3102             elsif (_MSWin32_5Cended_path($_)) {
3103 0 0       0 if (-d "$_/.") {
3104 0 0       0 return wantarray ? (-p _,@_) : -p _;
3105             }
3106             else {
3107 0         0 my $fh = gensym();
3108 0 0       0 if (_open_r($fh, $_)) {
3109 0         0 my $p = -p $fh;
3110 0 0       0 close($fh) or die "Can't close file: $_: $!";
3111 0 0       0 return wantarray ? ($p,@_) : $p;
3112             }
3113             }
3114             }
3115 0 0       0 return wantarray ? (undef,@_) : undef;
3116             }
3117              
3118             #
3119             # ShiftJIS file test -S expr
3120             #
3121             sub Esjis::S(;*@) {
3122              
3123 0 0   0 0 0 local $_ = shift if @_;
3124 0 0 0     0 croak 'Too many arguments for -S (Esjis::S)' if @_ and not wantarray;
3125              
3126 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3127 0 0       0 return wantarray ? (-S _,@_) : -S _;
3128             }
3129             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3130 0 0       0 return wantarray ? (-S $fh,@_) : -S $fh;
3131             }
3132             elsif (-e $_) {
3133 0 0       0 return wantarray ? (-S _,@_) : -S _;
3134             }
3135             elsif (_MSWin32_5Cended_path($_)) {
3136 0 0       0 if (-d "$_/.") {
3137 0 0       0 return wantarray ? (-S _,@_) : -S _;
3138             }
3139             else {
3140 0         0 my $fh = gensym();
3141 0 0       0 if (_open_r($fh, $_)) {
3142 0         0 my $S = -S $fh;
3143 0 0       0 close($fh) or die "Can't close file: $_: $!";
3144 0 0       0 return wantarray ? ($S,@_) : $S;
3145             }
3146             }
3147             }
3148 0 0       0 return wantarray ? (undef,@_) : undef;
3149             }
3150              
3151             #
3152             # ShiftJIS file test -b expr
3153             #
3154             sub Esjis::b(;*@) {
3155              
3156 0 0   0 0 0 local $_ = shift if @_;
3157 0 0 0     0 croak 'Too many arguments for -b (Esjis::b)' if @_ and not wantarray;
3158              
3159 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3160 0 0       0 return wantarray ? (-b _,@_) : -b _;
3161             }
3162             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3163 0 0       0 return wantarray ? (-b $fh,@_) : -b $fh;
3164             }
3165             elsif (-e $_) {
3166 0 0       0 return wantarray ? (-b _,@_) : -b _;
3167             }
3168             elsif (_MSWin32_5Cended_path($_)) {
3169 0 0       0 if (-d "$_/.") {
3170 0 0       0 return wantarray ? (-b _,@_) : -b _;
3171             }
3172             else {
3173 0         0 my $fh = gensym();
3174 0 0       0 if (_open_r($fh, $_)) {
3175 0         0 my $b = -b $fh;
3176 0 0       0 close($fh) or die "Can't close file: $_: $!";
3177 0 0       0 return wantarray ? ($b,@_) : $b;
3178             }
3179             }
3180             }
3181 0 0       0 return wantarray ? (undef,@_) : undef;
3182             }
3183              
3184             #
3185             # ShiftJIS file test -c expr
3186             #
3187             sub Esjis::c(;*@) {
3188              
3189 0 0   0 0 0 local $_ = shift if @_;
3190 0 0 0     0 croak 'Too many arguments for -c (Esjis::c)' if @_ and not wantarray;
3191              
3192 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3193 0 0       0 return wantarray ? (-c _,@_) : -c _;
3194             }
3195             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3196 0 0       0 return wantarray ? (-c $fh,@_) : -c $fh;
3197             }
3198             elsif (-e $_) {
3199 0 0       0 return wantarray ? (-c _,@_) : -c _;
3200             }
3201             elsif (_MSWin32_5Cended_path($_)) {
3202 0 0       0 if (-d "$_/.") {
3203 0 0       0 return wantarray ? (-c _,@_) : -c _;
3204             }
3205             else {
3206 0         0 my $fh = gensym();
3207 0 0       0 if (_open_r($fh, $_)) {
3208 0         0 my $c = -c $fh;
3209 0 0       0 close($fh) or die "Can't close file: $_: $!";
3210 0 0       0 return wantarray ? ($c,@_) : $c;
3211             }
3212             }
3213             }
3214 0 0       0 return wantarray ? (undef,@_) : undef;
3215             }
3216              
3217             #
3218             # ShiftJIS file test -u expr
3219             #
3220             sub Esjis::u(;*@) {
3221              
3222 0 0   0 0 0 local $_ = shift if @_;
3223 0 0 0     0 croak 'Too many arguments for -u (Esjis::u)' if @_ and not wantarray;
3224              
3225 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3226 0 0       0 return wantarray ? (-u _,@_) : -u _;
3227             }
3228             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3229 0 0       0 return wantarray ? (-u $fh,@_) : -u $fh;
3230             }
3231             elsif (-e $_) {
3232 0 0       0 return wantarray ? (-u _,@_) : -u _;
3233             }
3234             elsif (_MSWin32_5Cended_path($_)) {
3235 0 0       0 if (-d "$_/.") {
3236 0 0       0 return wantarray ? (-u _,@_) : -u _;
3237             }
3238             else {
3239 0         0 my $fh = gensym();
3240 0 0       0 if (_open_r($fh, $_)) {
3241 0         0 my $u = -u $fh;
3242 0 0       0 close($fh) or die "Can't close file: $_: $!";
3243 0 0       0 return wantarray ? ($u,@_) : $u;
3244             }
3245             }
3246             }
3247 0 0       0 return wantarray ? (undef,@_) : undef;
3248             }
3249              
3250             #
3251             # ShiftJIS file test -g expr
3252             #
3253             sub Esjis::g(;*@) {
3254              
3255 0 0   0 0 0 local $_ = shift if @_;
3256 0 0 0     0 croak 'Too many arguments for -g (Esjis::g)' if @_ and not wantarray;
3257              
3258 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3259 0 0       0 return wantarray ? (-g _,@_) : -g _;
3260             }
3261             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3262 0 0       0 return wantarray ? (-g $fh,@_) : -g $fh;
3263             }
3264             elsif (-e $_) {
3265 0 0       0 return wantarray ? (-g _,@_) : -g _;
3266             }
3267             elsif (_MSWin32_5Cended_path($_)) {
3268 0 0       0 if (-d "$_/.") {
3269 0 0       0 return wantarray ? (-g _,@_) : -g _;
3270             }
3271             else {
3272 0         0 my $fh = gensym();
3273 0 0       0 if (_open_r($fh, $_)) {
3274 0         0 my $g = -g $fh;
3275 0 0       0 close($fh) or die "Can't close file: $_: $!";
3276 0 0       0 return wantarray ? ($g,@_) : $g;
3277             }
3278             }
3279             }
3280 0 0       0 return wantarray ? (undef,@_) : undef;
3281             }
3282              
3283             #
3284             # ShiftJIS file test -k expr
3285             #
3286             sub Esjis::k(;*@) {
3287              
3288 0 0   0 0 0 local $_ = shift if @_;
3289 0 0 0     0 croak 'Too many arguments for -k (Esjis::k)' if @_ and not wantarray;
3290              
3291 0 0       0 if ($_ eq '_') {
    0          
    0          
3292 0 0       0 return wantarray ? ('',@_) : '';
3293             }
3294             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3295 0 0       0 return wantarray ? ('',@_) : '';
3296             }
3297             elsif ($] =~ /^5\.008/oxms) {
3298 0 0       0 return wantarray ? ('',@_) : '';
3299             }
3300 0 0       0 return wantarray ? ($_,@_) : $_;
3301             }
3302              
3303             #
3304             # ShiftJIS file test -T expr
3305             #
3306             sub Esjis::T(;*@) {
3307              
3308 0 0   0 0 0 local $_ = shift if @_;
3309              
3310             # Use of croak without parentheses makes die on Strawberry Perl 5.008 and 5.010, like:
3311             # croak 'Too many arguments for -T (Esjis::T)';
3312             # Must be used by parentheses like:
3313             # croak('Too many arguments for -T (Esjis::T)');
3314              
3315 0 0 0     0 if (@_ and not wantarray) {
3316 0         0 croak('Too many arguments for -T (Esjis::T)');
3317             }
3318              
3319 0         0 my $T = 1;
3320              
3321 0         0 my $fh = qualify_to_ref $_;
3322 0 0       0 if (defined fileno $fh) {
3323              
3324 0     0   0 local $SIG{__WARN__} = sub {}; # telldir() attempted on invalid dirhandle at here
3325 0 0       0 if (defined Esjis::telldir($fh)) {
3326 0 0       0 return wantarray ? (undef,@_) : undef;
3327             }
3328              
3329             # P.813 29.2.176. tell
3330             # in Chapter 29: Functions
3331             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
3332              
3333             # P.970 tell
3334             # in Chapter 27: Functions
3335             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
3336              
3337             # (and so on)
3338              
3339 0         0 my $systell = sysseek $fh, 0, 1;
3340              
3341 0 0       0 if (sysread $fh, my $block, 512) {
3342              
3343             # P.163 Binary file check in Little Perl Parlor 16
3344             # of Book No. T1008901080816 ZASSHI 08901-8 UNIX MAGAZINE 1993 Aug VOL8#8
3345             # (and so on)
3346              
3347 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3348 0         0 $T = '';
3349             }
3350             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3351 0         0 $T = '';
3352             }
3353             }
3354              
3355             # 0 byte or eof
3356             else {
3357 0         0 $T = 1;
3358             }
3359              
3360 0         0 my $dummy_for_underline_cache = -T $fh;
3361 0         0 sysseek $fh, $systell, 0;
3362             }
3363             else {
3364 0 0 0     0 if (-d $_ or -d "$_/.") {
3365 0 0       0 return wantarray ? (undef,@_) : undef;
3366             }
3367              
3368 0         0 $fh = gensym();
3369 0 0       0 if (_open_r($fh, $_)) {
3370             }
3371             else {
3372 0 0       0 return wantarray ? (undef,@_) : undef;
3373             }
3374 0 0       0 if (sysread $fh, my $block, 512) {
3375 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3376 0         0 $T = '';
3377             }
3378             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3379 0         0 $T = '';
3380             }
3381             }
3382              
3383             # 0 byte or eof
3384             else {
3385 0         0 $T = 1;
3386             }
3387 0         0 my $dummy_for_underline_cache = -T $fh;
3388 0 0       0 close($fh) or die "Can't close file: $_: $!";
3389             }
3390              
3391 0 0       0 return wantarray ? ($T,@_) : $T;
3392             }
3393              
3394             #
3395             # ShiftJIS file test -B expr
3396             #
3397             sub Esjis::B(;*@) {
3398              
3399 0 0   0 0 0 local $_ = shift if @_;
3400 0 0 0     0 croak 'Too many arguments for -B (Esjis::B)' if @_ and not wantarray;
3401 0         0 my $B = '';
3402              
3403 0         0 my $fh = qualify_to_ref $_;
3404 0 0       0 if (defined fileno $fh) {
3405              
3406 0     0   0 local $SIG{__WARN__} = sub {}; # telldir() attempted on invalid dirhandle at here
3407 0 0       0 if (defined Esjis::telldir($fh)) {
3408 0 0       0 return wantarray ? (undef,@_) : undef;
3409             }
3410              
3411 0         0 my $systell = sysseek $fh, 0, 1;
3412              
3413 0 0       0 if (sysread $fh, my $block, 512) {
3414 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3415 0         0 $B = 1;
3416             }
3417             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3418 0         0 $B = 1;
3419             }
3420             }
3421              
3422             # 0 byte or eof
3423             else {
3424 0         0 $B = 1;
3425             }
3426              
3427 0         0 my $dummy_for_underline_cache = -B $fh;
3428 0         0 sysseek $fh, $systell, 0;
3429             }
3430             else {
3431 0 0 0     0 if (-d $_ or -d "$_/.") {
3432 0 0       0 return wantarray ? (undef,@_) : undef;
3433             }
3434              
3435 0         0 $fh = gensym();
3436 0 0       0 if (_open_r($fh, $_)) {
3437             }
3438             else {
3439 0 0       0 return wantarray ? (undef,@_) : undef;
3440             }
3441 0 0       0 if (sysread $fh, my $block, 512) {
3442 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3443 0         0 $B = 1;
3444             }
3445             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3446 0         0 $B = 1;
3447             }
3448             }
3449              
3450             # 0 byte or eof
3451             else {
3452 0         0 $B = 1;
3453             }
3454 0         0 my $dummy_for_underline_cache = -B $fh;
3455 0 0       0 close($fh) or die "Can't close file: $_: $!";
3456             }
3457              
3458 0 0       0 return wantarray ? ($B,@_) : $B;
3459             }
3460              
3461             #
3462             # ShiftJIS file test -M expr
3463             #
3464             sub Esjis::M(;*@) {
3465              
3466 0 0   0 0 0 local $_ = shift if @_;
3467 0 0 0     0 croak 'Too many arguments for -M (Esjis::M)' if @_ and not wantarray;
3468              
3469 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3470 0 0       0 return wantarray ? (-M _,@_) : -M _;
3471             }
3472             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3473 0 0       0 return wantarray ? (-M $fh,@_) : -M $fh;
3474             }
3475             elsif (-e $_) {
3476 0 0       0 return wantarray ? (-M _,@_) : -M _;
3477             }
3478             elsif (_MSWin32_5Cended_path($_)) {
3479 0 0       0 if (-d "$_/.") {
3480 0 0       0 return wantarray ? (-M _,@_) : -M _;
3481             }
3482             else {
3483 0         0 my $fh = gensym();
3484 0 0       0 if (_open_r($fh, $_)) {
3485 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
3486 0 0       0 close($fh) or die "Can't close file: $_: $!";
3487 0         0 my $M = ($^T - $mtime) / (24*60*60);
3488 0 0       0 return wantarray ? ($M,@_) : $M;
3489             }
3490             }
3491             }
3492 0 0       0 return wantarray ? (undef,@_) : undef;
3493             }
3494              
3495             #
3496             # ShiftJIS file test -A expr
3497             #
3498             sub Esjis::A(;*@) {
3499              
3500 0 0   0 0 0 local $_ = shift if @_;
3501 0 0 0     0 croak 'Too many arguments for -A (Esjis::A)' if @_ and not wantarray;
3502              
3503 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3504 0 0       0 return wantarray ? (-A _,@_) : -A _;
3505             }
3506             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3507 0 0       0 return wantarray ? (-A $fh,@_) : -A $fh;
3508             }
3509             elsif (-e $_) {
3510 0 0       0 return wantarray ? (-A _,@_) : -A _;
3511             }
3512             elsif (_MSWin32_5Cended_path($_)) {
3513 0 0       0 if (-d "$_/.") {
3514 0 0       0 return wantarray ? (-A _,@_) : -A _;
3515             }
3516             else {
3517 0         0 my $fh = gensym();
3518 0 0       0 if (_open_r($fh, $_)) {
3519 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
3520 0 0       0 close($fh) or die "Can't close file: $_: $!";
3521 0         0 my $A = ($^T - $atime) / (24*60*60);
3522 0 0       0 return wantarray ? ($A,@_) : $A;
3523             }
3524             }
3525             }
3526 0 0       0 return wantarray ? (undef,@_) : undef;
3527             }
3528              
3529             #
3530             # ShiftJIS file test -C expr
3531             #
3532             sub Esjis::C(;*@) {
3533              
3534 0 0   0 0 0 local $_ = shift if @_;
3535 0 0 0     0 croak 'Too many arguments for -C (Esjis::C)' if @_ and not wantarray;
3536              
3537 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3538 0 0       0 return wantarray ? (-C _,@_) : -C _;
3539             }
3540             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3541 0 0       0 return wantarray ? (-C $fh,@_) : -C $fh;
3542             }
3543             elsif (-e $_) {
3544 0 0       0 return wantarray ? (-C _,@_) : -C _;
3545             }
3546             elsif (_MSWin32_5Cended_path($_)) {
3547 0 0       0 if (-d "$_/.") {
3548 0 0       0 return wantarray ? (-C _,@_) : -C _;
3549             }
3550             else {
3551 0         0 my $fh = gensym();
3552 0 0       0 if (_open_r($fh, $_)) {
3553 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
3554 0 0       0 close($fh) or die "Can't close file: $_: $!";
3555 0         0 my $C = ($^T - $ctime) / (24*60*60);
3556 0 0       0 return wantarray ? ($C,@_) : $C;
3557             }
3558             }
3559             }
3560 0 0       0 return wantarray ? (undef,@_) : undef;
3561             }
3562              
3563             #
3564             # ShiftJIS stacked file test $_
3565             #
3566             sub Esjis::filetest_ {
3567              
3568 0     0 0 0 my $filetest = substr(pop @_, 1);
3569              
3570 0 0       0 unless (CORE::eval qq{Esjis::${filetest}_}) {
3571 0         0 return '';
3572             }
3573 0         0 for my $filetest (CORE::reverse @_) {
3574 0 0       0 unless (CORE::eval qq{ $filetest _ }) {
3575 0         0 return '';
3576             }
3577             }
3578 0         0 return 1;
3579             }
3580              
3581             #
3582             # ShiftJIS file test -r $_
3583             #
3584             sub Esjis::r_() {
3585              
3586 0 0   0 0 0 if (-e $_) {
    0          
3587 0 0       0 return -r _ ? 1 : '';
3588             }
3589             elsif (_MSWin32_5Cended_path($_)) {
3590 0 0       0 if (-d "$_/.") {
3591 0 0       0 return -r _ ? 1 : '';
3592             }
3593             else {
3594 0         0 my $fh = gensym();
3595 0 0       0 if (_open_r($fh, $_)) {
3596 0         0 my $r = -r $fh;
3597 0 0       0 close($fh) or die "Can't close file: $_: $!";
3598 0 0       0 return $r ? 1 : '';
3599             }
3600             }
3601             }
3602              
3603             # 10.10. Returning Failure
3604             # in Chapter 10. Subroutines
3605             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
3606             # (and so on)
3607              
3608             # 2010-01-26 The difference of "return;" and "return undef;"
3609             # http://d.hatena.ne.jp/gfx/20100126/1264474754
3610             #
3611             # "Perl Best Practices" recommends to use "return;"*1 to return nothing, but
3612             # it might be wrong in some cases. If you use this idiom for those functions
3613             # which are expected to return a scalar value, e.g. searching functions, the
3614             # user of those functions will be surprised at what they return in list
3615             # context, an empty list - note that many functions and all the methods
3616             # evaluate their arguments in list context. You'd better to use "return undef;"
3617             # for such scalar functions.
3618             #
3619             # sub search_something {
3620             # my($arg) = @_;
3621             # # search_something...
3622             # if(defined $found){
3623             # return $found;
3624             # }
3625             # return; # XXX: you'd better to "return undef;"
3626             # }
3627             #
3628             # # ...
3629             #
3630             # # you'll get what you want, but ...
3631             # my $something = search_something($source);
3632             #
3633             # # you won't get what you want here.
3634             # # @_ for doit() is (-foo => $opt), not (undef, -foo => $opt).
3635             # $obj->doit(search_something($source), -option=> $optval);
3636             #
3637             # # you have to use the "scalar" operator in such a case.
3638             # $obj->doit(scalar search_something($source), ...);
3639             #
3640             # *1: it returns an empty list in list context, or returns undef in scalar
3641             # context
3642             #
3643             # (and so on)
3644              
3645 0         0 return undef;
3646             }
3647              
3648             #
3649             # ShiftJIS file test -w $_
3650             #
3651             sub Esjis::w_() {
3652              
3653 0 0   0 0 0 if (-e $_) {
    0          
3654 0 0       0 return -w _ ? 1 : '';
3655             }
3656             elsif (_MSWin32_5Cended_path($_)) {
3657 0 0       0 if (-d "$_/.") {
3658 0 0       0 return -w _ ? 1 : '';
3659             }
3660             else {
3661 0         0 my $fh = gensym();
3662 0 0       0 if (_open_a($fh, $_)) {
3663 0         0 my $w = -w $fh;
3664 0 0       0 close($fh) or die "Can't close file: $_: $!";
3665 0 0       0 return $w ? 1 : '';
3666             }
3667             }
3668             }
3669 0         0 return undef;
3670             }
3671              
3672             #
3673             # ShiftJIS file test -x $_
3674             #
3675             sub Esjis::x_() {
3676              
3677 0 0   0 0 0 if (-e $_) {
    0          
3678 0 0       0 return -x _ ? 1 : '';
3679             }
3680             elsif (_MSWin32_5Cended_path($_)) {
3681 0 0       0 if (-d "$_/.") {
3682 0 0       0 return -x _ ? 1 : '';
3683             }
3684             else {
3685 0         0 my $fh = gensym();
3686 0 0       0 if (_open_r($fh, $_)) {
3687 0         0 my $dummy_for_underline_cache = -x $fh;
3688 0 0       0 close($fh) or die "Can't close file: $_: $!";
3689             }
3690              
3691             # filename is not .COM .EXE .BAT .CMD
3692 0         0 return '';
3693             }
3694             }
3695 0         0 return undef;
3696             }
3697              
3698             #
3699             # ShiftJIS file test -o $_
3700             #
3701             sub Esjis::o_() {
3702              
3703 0 0   0 0 0 if (-e $_) {
    0          
3704 0 0       0 return -o _ ? 1 : '';
3705             }
3706             elsif (_MSWin32_5Cended_path($_)) {
3707 0 0       0 if (-d "$_/.") {
3708 0 0       0 return -o _ ? 1 : '';
3709             }
3710             else {
3711 0         0 my $fh = gensym();
3712 0 0       0 if (_open_r($fh, $_)) {
3713 0         0 my $o = -o $fh;
3714 0 0       0 close($fh) or die "Can't close file: $_: $!";
3715 0 0       0 return $o ? 1 : '';
3716             }
3717             }
3718             }
3719 0         0 return undef;
3720             }
3721              
3722             #
3723             # ShiftJIS file test -R $_
3724             #
3725             sub Esjis::R_() {
3726              
3727 0 0   0 0 0 if (-e $_) {
    0          
3728 0 0       0 return -R _ ? 1 : '';
3729             }
3730             elsif (_MSWin32_5Cended_path($_)) {
3731 0 0       0 if (-d "$_/.") {
3732 0 0       0 return -R _ ? 1 : '';
3733             }
3734             else {
3735 0         0 my $fh = gensym();
3736 0 0       0 if (_open_r($fh, $_)) {
3737 0         0 my $R = -R $fh;
3738 0 0       0 close($fh) or die "Can't close file: $_: $!";
3739 0 0       0 return $R ? 1 : '';
3740             }
3741             }
3742             }
3743 0         0 return undef;
3744             }
3745              
3746             #
3747             # ShiftJIS file test -W $_
3748             #
3749             sub Esjis::W_() {
3750              
3751 0 0   0 0 0 if (-e $_) {
    0          
3752 0 0       0 return -W _ ? 1 : '';
3753             }
3754             elsif (_MSWin32_5Cended_path($_)) {
3755 0 0       0 if (-d "$_/.") {
3756 0 0       0 return -W _ ? 1 : '';
3757             }
3758             else {
3759 0         0 my $fh = gensym();
3760 0 0       0 if (_open_a($fh, $_)) {
3761 0         0 my $W = -W $fh;
3762 0 0       0 close($fh) or die "Can't close file: $_: $!";
3763 0 0       0 return $W ? 1 : '';
3764             }
3765             }
3766             }
3767 0         0 return undef;
3768             }
3769              
3770             #
3771             # ShiftJIS file test -X $_
3772             #
3773             sub Esjis::X_() {
3774              
3775 0 0   0 0 0 if (-e $_) {
    0          
3776 0 0       0 return -X _ ? 1 : '';
3777             }
3778             elsif (_MSWin32_5Cended_path($_)) {
3779 0 0       0 if (-d "$_/.") {
3780 0 0       0 return -X _ ? 1 : '';
3781             }
3782             else {
3783 0         0 my $fh = gensym();
3784 0 0       0 if (_open_r($fh, $_)) {
3785 0         0 my $dummy_for_underline_cache = -X $fh;
3786 0 0       0 close($fh) or die "Can't close file: $_: $!";
3787             }
3788              
3789             # filename is not .COM .EXE .BAT .CMD
3790 0         0 return '';
3791             }
3792             }
3793 0         0 return undef;
3794             }
3795              
3796             #
3797             # ShiftJIS file test -O $_
3798             #
3799             sub Esjis::O_() {
3800              
3801 0 0   0 0 0 if (-e $_) {
    0          
3802 0 0       0 return -O _ ? 1 : '';
3803             }
3804             elsif (_MSWin32_5Cended_path($_)) {
3805 0 0       0 if (-d "$_/.") {
3806 0 0       0 return -O _ ? 1 : '';
3807             }
3808             else {
3809 0         0 my $fh = gensym();
3810 0 0       0 if (_open_r($fh, $_)) {
3811 0         0 my $O = -O $fh;
3812 0 0       0 close($fh) or die "Can't close file: $_: $!";
3813 0 0       0 return $O ? 1 : '';
3814             }
3815             }
3816             }
3817 0         0 return undef;
3818             }
3819              
3820             #
3821             # ShiftJIS file test -e $_
3822             #
3823             sub Esjis::e_() {
3824              
3825 0 0   0 0 0 if (-e $_) {
    0          
3826 0         0 return 1;
3827             }
3828             elsif (_MSWin32_5Cended_path($_)) {
3829 0 0       0 if (-d "$_/.") {
3830 0         0 return 1;
3831             }
3832             else {
3833 0         0 my $fh = gensym();
3834 0 0       0 if (_open_r($fh, $_)) {
3835 0         0 my $e = -e $fh;
3836 0 0       0 close($fh) or die "Can't close file: $_: $!";
3837 0 0       0 return $e ? 1 : '';
3838             }
3839             }
3840             }
3841 0         0 return undef;
3842             }
3843              
3844             #
3845             # ShiftJIS file test -z $_
3846             #
3847             sub Esjis::z_() {
3848              
3849 0 0   0 0 0 if (-e $_) {
    0          
3850 0 0       0 return -z _ ? 1 : '';
3851             }
3852             elsif (_MSWin32_5Cended_path($_)) {
3853 0 0       0 if (-d "$_/.") {
3854 0 0       0 return -z _ ? 1 : '';
3855             }
3856             else {
3857 0         0 my $fh = gensym();
3858 0 0       0 if (_open_r($fh, $_)) {
3859 0         0 my $z = -z $fh;
3860 0 0       0 close($fh) or die "Can't close file: $_: $!";
3861 0 0       0 return $z ? 1 : '';
3862             }
3863             }
3864             }
3865 0         0 return undef;
3866             }
3867              
3868             #
3869             # ShiftJIS file test -s $_
3870             #
3871             sub Esjis::s_() {
3872              
3873 0 0   0 0 0 if (-e $_) {
    0          
3874 0         0 return -s _;
3875             }
3876             elsif (_MSWin32_5Cended_path($_)) {
3877 0 0       0 if (-d "$_/.") {
3878 0         0 return -s _;
3879             }
3880             else {
3881 0         0 my $fh = gensym();
3882 0 0       0 if (_open_r($fh, $_)) {
3883 0         0 my $s = -s $fh;
3884 0 0       0 close($fh) or die "Can't close file: $_: $!";
3885 0         0 return $s;
3886             }
3887             }
3888             }
3889 0         0 return undef;
3890             }
3891              
3892             #
3893             # ShiftJIS file test -f $_
3894             #
3895             sub Esjis::f_() {
3896              
3897 0 0   0 0 0 if (-e $_) {
    0          
3898 0 0       0 return -f _ ? 1 : '';
3899             }
3900             elsif (_MSWin32_5Cended_path($_)) {
3901 0 0       0 if (-d "$_/.") {
3902 0         0 return '';
3903             }
3904             else {
3905 0         0 my $fh = gensym();
3906 0 0       0 if (_open_r($fh, $_)) {
3907 0         0 my $f = -f $fh;
3908 0 0       0 close($fh) or die "Can't close file: $_: $!";
3909 0 0       0 return $f ? 1 : '';
3910             }
3911             }
3912             }
3913 0         0 return undef;
3914             }
3915              
3916             #
3917             # ShiftJIS file test -d $_
3918             #
3919             sub Esjis::d_() {
3920              
3921 0 0   0 0 0 if (-e $_) {
    0          
3922 0 0       0 return -d _ ? 1 : '';
3923             }
3924             elsif (_MSWin32_5Cended_path($_)) {
3925 0 0       0 return -d "$_/." ? 1 : '';
3926             }
3927 0         0 return undef;
3928             }
3929              
3930             #
3931             # ShiftJIS file test -l $_
3932             #
3933             sub Esjis::l_() {
3934              
3935 0 0   0 0 0 if (-e $_) {
    0          
3936 0 0       0 return -l _ ? 1 : '';
3937             }
3938             elsif (_MSWin32_5Cended_path($_)) {
3939 0 0       0 if (-d "$_/.") {
3940 0 0       0 return -l _ ? 1 : '';
3941             }
3942             else {
3943 0         0 my $fh = gensym();
3944 0 0       0 if (_open_r($fh, $_)) {
3945 0         0 my $l = -l $fh;
3946 0 0       0 close($fh) or die "Can't close file: $_: $!";
3947 0 0       0 return $l ? 1 : '';
3948             }
3949             }
3950             }
3951 0         0 return undef;
3952             }
3953              
3954             #
3955             # ShiftJIS file test -p $_
3956             #
3957             sub Esjis::p_() {
3958              
3959 0 0   0 0 0 if (-e $_) {
    0          
3960 0 0       0 return -p _ ? 1 : '';
3961             }
3962             elsif (_MSWin32_5Cended_path($_)) {
3963 0 0       0 if (-d "$_/.") {
3964 0 0       0 return -p _ ? 1 : '';
3965             }
3966             else {
3967 0         0 my $fh = gensym();
3968 0 0       0 if (_open_r($fh, $_)) {
3969 0         0 my $p = -p $fh;
3970 0 0       0 close($fh) or die "Can't close file: $_: $!";
3971 0 0       0 return $p ? 1 : '';
3972             }
3973             }
3974             }
3975 0         0 return undef;
3976             }
3977              
3978             #
3979             # ShiftJIS file test -S $_
3980             #
3981             sub Esjis::S_() {
3982              
3983 0 0   0 0 0 if (-e $_) {
    0          
3984 0 0       0 return -S _ ? 1 : '';
3985             }
3986             elsif (_MSWin32_5Cended_path($_)) {
3987 0 0       0 if (-d "$_/.") {
3988 0 0       0 return -S _ ? 1 : '';
3989             }
3990             else {
3991 0         0 my $fh = gensym();
3992 0 0       0 if (_open_r($fh, $_)) {
3993 0         0 my $S = -S $fh;
3994 0 0       0 close($fh) or die "Can't close file: $_: $!";
3995 0 0       0 return $S ? 1 : '';
3996             }
3997             }
3998             }
3999 0         0 return undef;
4000             }
4001              
4002             #
4003             # ShiftJIS file test -b $_
4004             #
4005             sub Esjis::b_() {
4006              
4007 0 0   0 0 0 if (-e $_) {
    0          
4008 0 0       0 return -b _ ? 1 : '';
4009             }
4010             elsif (_MSWin32_5Cended_path($_)) {
4011 0 0       0 if (-d "$_/.") {
4012 0 0       0 return -b _ ? 1 : '';
4013             }
4014             else {
4015 0         0 my $fh = gensym();
4016 0 0       0 if (_open_r($fh, $_)) {
4017 0         0 my $b = -b $fh;
4018 0 0       0 close($fh) or die "Can't close file: $_: $!";
4019 0 0       0 return $b ? 1 : '';
4020             }
4021             }
4022             }
4023 0         0 return undef;
4024             }
4025              
4026             #
4027             # ShiftJIS file test -c $_
4028             #
4029             sub Esjis::c_() {
4030              
4031 0 0   0 0 0 if (-e $_) {
    0          
4032 0 0       0 return -c _ ? 1 : '';
4033             }
4034             elsif (_MSWin32_5Cended_path($_)) {
4035 0 0       0 if (-d "$_/.") {
4036 0 0       0 return -c _ ? 1 : '';
4037             }
4038             else {
4039 0         0 my $fh = gensym();
4040 0 0       0 if (_open_r($fh, $_)) {
4041 0         0 my $c = -c $fh;
4042 0 0       0 close($fh) or die "Can't close file: $_: $!";
4043 0 0       0 return $c ? 1 : '';
4044             }
4045             }
4046             }
4047 0         0 return undef;
4048             }
4049              
4050             #
4051             # ShiftJIS file test -u $_
4052             #
4053             sub Esjis::u_() {
4054              
4055 0 0   0 0 0 if (-e $_) {
    0          
4056 0 0       0 return -u _ ? 1 : '';
4057             }
4058             elsif (_MSWin32_5Cended_path($_)) {
4059 0 0       0 if (-d "$_/.") {
4060 0 0       0 return -u _ ? 1 : '';
4061             }
4062             else {
4063 0         0 my $fh = gensym();
4064 0 0       0 if (_open_r($fh, $_)) {
4065 0         0 my $u = -u $fh;
4066 0 0       0 close($fh) or die "Can't close file: $_: $!";
4067 0 0       0 return $u ? 1 : '';
4068             }
4069             }
4070             }
4071 0         0 return undef;
4072             }
4073              
4074             #
4075             # ShiftJIS file test -g $_
4076             #
4077             sub Esjis::g_() {
4078              
4079 0 0   0 0 0 if (-e $_) {
    0          
4080 0 0       0 return -g _ ? 1 : '';
4081             }
4082             elsif (_MSWin32_5Cended_path($_)) {
4083 0 0       0 if (-d "$_/.") {
4084 0 0       0 return -g _ ? 1 : '';
4085             }
4086             else {
4087 0         0 my $fh = gensym();
4088 0 0       0 if (_open_r($fh, $_)) {
4089 0         0 my $g = -g $fh;
4090 0 0       0 close($fh) or die "Can't close file: $_: $!";
4091 0 0       0 return $g ? 1 : '';
4092             }
4093             }
4094             }
4095 0         0 return undef;
4096             }
4097              
4098             #
4099             # ShiftJIS file test -k $_
4100             #
4101             sub Esjis::k_() {
4102              
4103 0 0   0 0 0 if ($] =~ /^5\.008/oxms) {
4104 0 0       0 return wantarray ? ('',@_) : '';
4105             }
4106 0 0       0 return wantarray ? ($_,@_) : $_;
4107             }
4108              
4109             #
4110             # ShiftJIS file test -T $_
4111             #
4112             sub Esjis::T_() {
4113              
4114 0     0 0 0 my $T = 1;
4115              
4116 0 0 0     0 if (-d $_ or -d "$_/.") {
4117 0         0 return undef;
4118             }
4119 0         0 my $fh = gensym();
4120 0 0       0 if (_open_r($fh, $_)) {
4121             }
4122             else {
4123 0         0 return undef;
4124             }
4125              
4126 0 0       0 if (sysread $fh, my $block, 512) {
4127 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
4128 0         0 $T = '';
4129             }
4130             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
4131 0         0 $T = '';
4132             }
4133             }
4134              
4135             # 0 byte or eof
4136             else {
4137 0         0 $T = 1;
4138             }
4139 0         0 my $dummy_for_underline_cache = -T $fh;
4140 0 0       0 close($fh) or die "Can't close file: $_: $!";
4141              
4142 0         0 return $T;
4143             }
4144              
4145             #
4146             # ShiftJIS file test -B $_
4147             #
4148             sub Esjis::B_() {
4149              
4150 0     0 0 0 my $B = '';
4151              
4152 0 0 0     0 if (-d $_ or -d "$_/.") {
4153 0         0 return undef;
4154             }
4155 0         0 my $fh = gensym();
4156 0 0       0 if (_open_r($fh, $_)) {
4157             }
4158             else {
4159 0         0 return undef;
4160             }
4161              
4162 0 0       0 if (sysread $fh, my $block, 512) {
4163 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
4164 0         0 $B = 1;
4165             }
4166             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
4167 0         0 $B = 1;
4168             }
4169             }
4170              
4171             # 0 byte or eof
4172             else {
4173 0         0 $B = 1;
4174             }
4175 0         0 my $dummy_for_underline_cache = -B $fh;
4176 0 0       0 close($fh) or die "Can't close file: $_: $!";
4177              
4178 0         0 return $B;
4179             }
4180              
4181             #
4182             # ShiftJIS file test -M $_
4183             #
4184             sub Esjis::M_() {
4185              
4186 0 0   0 0 0 if (-e $_) {
    0          
4187 0         0 return -M _;
4188             }
4189             elsif (_MSWin32_5Cended_path($_)) {
4190 0 0       0 if (-d "$_/.") {
4191 0         0 return -M _;
4192             }
4193             else {
4194 0         0 my $fh = gensym();
4195 0 0       0 if (_open_r($fh, $_)) {
4196 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
4197 0 0       0 close($fh) or die "Can't close file: $_: $!";
4198 0         0 my $M = ($^T - $mtime) / (24*60*60);
4199 0         0 return $M;
4200             }
4201             }
4202             }
4203 0         0 return undef;
4204             }
4205              
4206             #
4207             # ShiftJIS file test -A $_
4208             #
4209             sub Esjis::A_() {
4210              
4211 0 0   0 0 0 if (-e $_) {
    0          
4212 0         0 return -A _;
4213             }
4214             elsif (_MSWin32_5Cended_path($_)) {
4215 0 0       0 if (-d "$_/.") {
4216 0         0 return -A _;
4217             }
4218             else {
4219 0         0 my $fh = gensym();
4220 0 0       0 if (_open_r($fh, $_)) {
4221 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
4222 0 0       0 close($fh) or die "Can't close file: $_: $!";
4223 0         0 my $A = ($^T - $atime) / (24*60*60);
4224 0         0 return $A;
4225             }
4226             }
4227             }
4228 0         0 return undef;
4229             }
4230              
4231             #
4232             # ShiftJIS file test -C $_
4233             #
4234             sub Esjis::C_() {
4235              
4236 0 0   0 0 0 if (-e $_) {
    0          
4237 0         0 return -C _;
4238             }
4239             elsif (_MSWin32_5Cended_path($_)) {
4240 0 0       0 if (-d "$_/.") {
4241 0         0 return -C _;
4242             }
4243             else {
4244 0         0 my $fh = gensym();
4245 0 0       0 if (_open_r($fh, $_)) {
4246 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
4247 0 0       0 close($fh) or die "Can't close file: $_: $!";
4248 0         0 my $C = ($^T - $ctime) / (24*60*60);
4249 0         0 return $C;
4250             }
4251             }
4252             }
4253 0         0 return undef;
4254             }
4255              
4256             #
4257             # ShiftJIS path globbing (with parameter)
4258             #
4259             sub Esjis::glob($) {
4260              
4261 0 0   0 0 0 if (wantarray) {
4262 0         0 my @glob = _DOS_like_glob(@_);
4263 0         0 for my $glob (@glob) {
4264 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4265             }
4266 0         0 return @glob;
4267             }
4268             else {
4269 0         0 my $glob = _DOS_like_glob(@_);
4270 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4271 0         0 return $glob;
4272             }
4273             }
4274              
4275             #
4276             # ShiftJIS path globbing (without parameter)
4277             #
4278             sub Esjis::glob_() {
4279              
4280 0 0   0 0 0 if (wantarray) {
4281 0         0 my @glob = _DOS_like_glob();
4282 0         0 for my $glob (@glob) {
4283 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4284             }
4285 0         0 return @glob;
4286             }
4287             else {
4288 0         0 my $glob = _DOS_like_glob();
4289 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4290 0         0 return $glob;
4291             }
4292             }
4293              
4294             #
4295             # ShiftJIS path globbing via File::DosGlob 1.10
4296             #
4297             # Often I confuse "_dosglob" and "_doglob".
4298             # So, I renamed "_dosglob" to "_DOS_like_glob".
4299             #
4300             my %iter;
4301             my %entries;
4302             sub _DOS_like_glob {
4303              
4304             # context (keyed by second cxix argument provided by core)
4305 0     0   0 my($expr,$cxix) = @_;
4306              
4307             # glob without args defaults to $_
4308 0 0       0 $expr = $_ if not defined $expr;
4309              
4310             # represents the current user's home directory
4311             #
4312             # 7.3. Expanding Tildes in Filenames
4313             # in Chapter 7. File Access
4314             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
4315             #
4316             # and File::HomeDir, File::HomeDir::Windows module
4317              
4318             # DOS-like system
4319 0 0       0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
    0          
4320 0         0 $expr =~ s{ \A ~ (?= [^/\\] ) }
  0         0  
4321             { my_home_MSWin32() }oxmse;
4322             }
4323              
4324             # Mac OS system
4325 0 0       0 elsif ($^O eq 'MacOS') {
4326 0         0 if ($expr =~ / \A ~ /oxms) {
  0         0  
4327             $expr =~ s{ \A ~ (?= [^/:] ) }
4328             { my_home_MacOS() }oxmse;
4329             }
4330             }
4331              
4332 0 0 0     0 # UNIX-like system
  0         0  
4333             else {
4334             $expr =~ s{ \A ~ ( (?:[^\x81-\x9F\xE0-\xFC/]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])* ) }
4335             { $1 ? (CORE::eval(q{(getpwnam($1))[7]})||my_home()) : my_home() }oxmse;
4336 0 0       0 }
4337 0 0       0  
4338             # assume global context if not provided one
4339             $cxix = '_G_' if not defined $cxix;
4340 0 0       0 $iter{$cxix} = 0 if not exists $iter{$cxix};
4341 0 0       0  
4342             # if we're just beginning, do it all first
4343             if ($iter{$cxix} == 0) {
4344 0         0 if ($^O eq 'MacOS') {
4345              
4346             # first, take care of updirs and trailing colons
4347 0         0 my @expr = _canonpath_MacOS(_parse_line($expr));
4348              
4349 0 0       0 # expand volume names
  0         0  
4350             @expr = _expand_volume_MacOS(@expr);
4351              
4352 0         0 $entries{$cxix} = (@expr) ? [ map { _unescape_MacOS($_) } _do_glob_MacOS(1,@expr) ] : [()];
4353             }
4354             else {
4355             $entries{$cxix} = [ _do_glob(1, _parse_line($expr)) ];
4356             }
4357 0 0       0 }
4358 0         0  
4359 0         0 # chuck it all out, quick or slow
  0         0  
4360             if (wantarray) {
4361             delete $iter{$cxix};
4362 0 0       0 return @{delete $entries{$cxix}};
  0         0  
4363 0         0 }
  0         0  
4364             else {
4365             if ($iter{$cxix} = scalar @{$entries{$cxix}}) {
4366             return shift @{$entries{$cxix}};
4367 0         0 }
4368 0         0 else {
4369 0         0 # return undef for EOL
4370             delete $iter{$cxix};
4371             delete $entries{$cxix};
4372             return undef;
4373             }
4374             }
4375             }
4376              
4377             #
4378             # ShiftJIS path globbing subroutine
4379 0     0   0 #
4380 0         0 sub _do_glob {
4381 0         0  
4382             my($cond,@expr) = @_;
4383             my @glob = ();
4384 0         0 my $fix_drive_relative_paths = 0;
4385 0 0       0  
4386 0 0       0 OUTER:
4387             for my $expr (@expr) {
4388 0         0 next OUTER if not defined $expr;
4389 0         0 next OUTER if $expr eq '';
4390 0         0  
4391 0         0 my @matched = ();
4392 0         0 my @globdir = ();
4393             my $head = '.';
4394             my $pathsep = '/';
4395 0 0       0 my $tail;
4396 0         0  
4397 0 0       0 # if argument is within quotes strip em and do no globbing
4398 0 0       0 if ($expr =~ /\A " ((?:$q_char)*?) " \z/oxms) {
4399 0         0 $expr = $1;
4400             if ($cond eq 'd') {
4401             if (Esjis::d $expr) {
4402             push @glob, $expr;
4403 0 0       0 }
4404 0         0 }
4405             else {
4406             if (Esjis::e $expr) {
4407 0         0 push @glob, $expr;
4408             }
4409             }
4410             next OUTER;
4411             }
4412 0 0       0  
4413 0 0       0 # wildcards with a drive prefix such as h:*.pm must be changed
4414 0         0 # to h:./*.pm to expand correctly
4415             if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
4416             if ($expr =~ s# \A ((?:[A-Za-z]:)?) ([^\x81-\x9F\xE0-\xFC/\\]|[\x81-\x9F\xE0-\xFC][\x00-\xFF]) #$1./$2#oxms) {
4417             $fix_drive_relative_paths = 1;
4418 0 0       0 }
4419 0 0       0 }
4420 0         0  
4421 0         0 if (($head, $tail) = _parse_path($expr,$pathsep)) {
4422             if ($tail eq '') {
4423 0 0       0 push @glob, $expr;
4424 0 0       0 next OUTER;
4425 0         0 }
  0         0  
4426 0         0 if ($head =~ / \A (?:$q_char)*? [*?] /oxms) {
4427             if (@globdir = _do_glob('d', $head)) {
4428             push @glob, _do_glob($cond, map {"$_$pathsep$tail"} @globdir);
4429 0 0 0     0 next OUTER;
4430 0         0 }
4431             }
4432 0         0 if ($head eq '' or $head =~ /\A [A-Za-z]: \z/oxms) {
4433             $head .= $pathsep;
4434             }
4435             $expr = $tail;
4436 0 0       0 }
4437 0 0       0  
4438 0         0 # If file component has no wildcards, we can avoid opendir
4439             if ($expr !~ / \A (?:$q_char)*? [*?] /oxms) {
4440 0 0 0     0 if ($head eq '.') {
4441 0         0 $head = '';
4442             }
4443 0         0 if ($head ne '' and ($head =~ / \G ($q_char) /oxmsg)[-1] ne $pathsep) {
4444 0 0       0 $head .= $pathsep;
4445 0 0       0 }
4446 0         0 $head .= $expr;
4447             if ($cond eq 'd') {
4448             if (Esjis::d $head) {
4449             push @glob, $head;
4450 0 0       0 }
4451 0         0 }
4452             else {
4453             if (Esjis::e $head) {
4454 0         0 push @glob, $head;
4455             }
4456 0 0       0 }
4457 0         0 next OUTER;
4458 0         0 }
4459             Esjis::opendir(*DIR, $head) or next OUTER;
4460 0 0       0 my @leaf = readdir DIR;
4461 0         0 closedir DIR;
4462              
4463 0 0 0     0 if ($head eq '.') {
4464 0         0 $head = '';
4465             }
4466             if ($head ne '' and ($head =~ / \G ($q_char) /oxmsg)[-1] ne $pathsep) {
4467 0         0 $head .= $pathsep;
4468 0         0 }
4469 0         0  
4470             my $pattern = '';
4471             while ($expr =~ / \G ($q_char) /oxgc) {
4472             my $char = $1;
4473              
4474             # 6.9. Matching Shell Globs as Regular Expressions
4475             # in Chapter 6. Pattern Matching
4476 0 0       0 # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
    0          
    0          
4477 0         0 # (and so on)
4478              
4479             if ($char eq '*') {
4480 0         0 $pattern .= "(?:$your_char)*",
4481             }
4482             elsif ($char eq '?') {
4483             $pattern .= "(?:$your_char)?", # DOS style
4484 0         0 # $pattern .= "(?:$your_char)", # UNIX style
4485             }
4486             elsif ((my $fc = Esjis::fc($char)) ne $char) {
4487 0         0 $pattern .= $fc;
4488             }
4489             else {
4490 0     0   0 $pattern .= quotemeta $char;
  0         0  
4491             }
4492             }
4493             my $matchsub = sub { Esjis::fc($_[0]) =~ /\A $pattern \z/xms };
4494              
4495             # if ($@) {
4496             # print STDERR "$0: $@\n";
4497             # next OUTER;
4498 0         0 # }
4499 0 0 0     0  
4500 0         0 INNER:
4501             for my $leaf (@leaf) {
4502 0 0 0     0 if ($leaf eq '.' or $leaf eq '..') {
4503 0         0 next INNER;
4504             }
4505             if ($cond eq 'd' and not Esjis::d "$head$leaf") {
4506 0 0       0 next INNER;
4507 0         0 }
4508 0         0  
4509             if (&$matchsub($leaf)) {
4510             push @matched, "$head$leaf";
4511             next INNER;
4512             }
4513              
4514 0 0 0     0 # [DOS compatibility special case]
      0        
4515             # Failed, add a trailing dot and try again, but only...
4516              
4517             if (Esjis::index($leaf,'.') == -1 and # if name does not have a dot in it *and*
4518 0 0       0 CORE::length($leaf) <= 8 and # name is shorter than or equal to 8 chars *and*
4519 0         0 Esjis::index($pattern,'\\.') != -1 # pattern has a dot.
4520 0         0 ) {
4521             if (&$matchsub("$leaf.")) {
4522             push @matched, "$head$leaf";
4523             next INNER;
4524 0 0       0 }
4525 0         0 }
4526             }
4527             if (@matched) {
4528 0 0       0 push @glob, @matched;
4529 0         0 }
4530 0         0 }
4531             if ($fix_drive_relative_paths) {
4532             for my $glob (@glob) {
4533 0         0 $glob =~ s# \A ([A-Za-z]:) \./ #$1#oxms;
4534             }
4535             }
4536             return @glob;
4537             }
4538              
4539             #
4540             # ShiftJIS parse line
4541 0     0   0 #
4542             sub _parse_line {
4543 0         0  
4544 0         0 my($line) = @_;
4545 0         0  
4546             $line .= ' ';
4547             my @piece = ();
4548             while ($line =~ /
4549             " ( (?>(?: [^\x81-\x9F\xE0-\xFC"] |[\x81-\x9F\xE0-\xFC][\x00-\xFF] )* ) ) " (?>\s+) |
4550 0 0       0 ( (?>(?: [^\x81-\x9F\xE0-\xFC"\s]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] )* ) ) (?>\s+)
4551             /oxmsg
4552 0         0 ) {
4553             push @piece, defined($1) ? $1 : $2;
4554             }
4555             return @piece;
4556             }
4557              
4558             #
4559             # ShiftJIS parse path
4560 0     0   0 #
4561             sub _parse_path {
4562 0         0  
4563 0         0 my($path,$pathsep) = @_;
4564 0         0  
4565             $path .= '/';
4566             my @subpath = ();
4567             while ($path =~ /
4568 0         0 ((?: [^\x81-\x9F\xE0-\xFC\/\\]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] )+?) [\/\\]
4569             /oxmsg
4570             ) {
4571 0         0 push @subpath, $1;
4572 0         0 }
4573 0         0  
4574             my $tail = pop @subpath;
4575             my $head = join $pathsep, @subpath;
4576             return $head, $tail;
4577             }
4578              
4579             #
4580             # ShiftJIS path globbing on Mac OS
4581 0     0   0 #
4582 0         0 sub _do_glob_MacOS {
4583              
4584             my($cond,@expr) = @_;
4585 0         0 my @glob = ();
4586 0 0       0  
4587 0 0       0 OUTER_MACOS:
4588             for my $expr (@expr) {
4589 0         0 next OUTER_MACOS if not defined $expr;
4590 0         0 next OUTER_MACOS if $expr eq '';
4591 0         0  
4592 0         0 my @matched = ();
4593 0         0 my @globdir = ();
4594 0         0 my $head = ':';
4595             my $unesc_head = $head;
4596             my $pathsep = ':';
4597 0 0       0 my $tail;
4598 0         0  
4599             # if $expr is within quotes strip em and do no globbing
4600             if ($expr =~ /\A " ((?:$q_char)*?) " \z/oxms) {
4601 0         0 $expr = $1;
4602              
4603 0 0       0 # $expr may contain escaped metachars '\*', '\?', and '\'
4604 0 0       0 $expr = _unescape_MacOS($expr);
4605 0         0  
4606             if ($cond eq 'd') {
4607             if (Esjis::d $expr) {
4608             push @glob, $expr;
4609 0 0       0 }
4610 0         0 }
4611             else {
4612             if (Esjis::e $expr) {
4613 0         0 push @glob, $expr;
4614             }
4615             }
4616             next OUTER_MACOS;
4617 0 0       0 }
4618 0 0       0  
4619 0         0 # note: $1 is not greedy
4620 0         0 if (($head,$pathsep,$tail) = $expr =~ /\A ((?:$q_char)*?) (:+) ((?:[^\x81-\x9F\xE0-\xFC:]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?) \z/oxms) {
4621             if ($tail eq '') {
4622 0 0       0 push @glob, $expr;
4623 0 0       0 next OUTER_MACOS;
4624 0         0 }
  0         0  
4625 0         0 if (_hasmeta_MacOS($head)) {
4626             if (@globdir = _do_glob_MacOS('d', $head)) {
4627             push @glob, _do_glob_MacOS($cond, map {"$_$pathsep$tail"} @globdir);
4628 0         0 next OUTER_MACOS;
4629             }
4630             }
4631 0         0 $head .= $pathsep;
4632              
4633 0         0 # unescape $head for file operations
4634             $unesc_head = _unescape_MacOS($head);
4635              
4636             $expr = $tail;
4637 0 0       0 }
4638 0 0       0  
4639 0         0 # If file component has no wildcards, we can avoid opendir
4640             if (not _hasmeta_MacOS($expr)) {
4641 0         0 if ($head eq ':') {
4642             $unesc_head = $head = '';
4643             }
4644 0         0 $head .= $expr;
4645              
4646 0 0       0 # unescape $head and $expr for file operations
4647 0 0       0 $unesc_head .= _unescape_MacOS($expr);
4648 0         0  
4649             if ($cond eq 'd') {
4650             if (Esjis::d $unesc_head) {
4651             push @glob, $head;
4652 0 0       0 }
4653 0         0 }
4654             else {
4655             if (Esjis::e $unesc_head) {
4656 0         0 push @glob, $head;
4657             }
4658 0 0       0 }
4659 0         0 next OUTER_MACOS;
4660 0         0 }
4661             Esjis::opendir(*DIR, $head) or next OUTER_MACOS;
4662 0         0 my @leaf = readdir DIR;
4663 0     0   0 closedir DIR;
  0         0  
4664              
4665             my $pattern = _quotemeta_MacOS($expr);
4666             my $matchsub = sub { Esjis::fc($_[0]) =~ /\A $pattern \z/xms };
4667              
4668             # if ($@) {
4669             # print STDERR "$0: $@\n";
4670             # next OUTER_MACOS;
4671 0         0 # }
4672 0 0 0     0  
4673 0         0 INNER_MACOS:
4674             for my $leaf (@leaf) {
4675 0 0 0     0 if ($leaf eq '.' or $leaf eq '..') {
4676 0         0 next INNER_MACOS;
4677             }
4678             if ($cond eq 'd' and not Esjis::d qq{$unesc_head$leaf}) {
4679 0 0       0 next INNER_MACOS;
4680 0 0 0     0 }
4681              
4682             if (&$matchsub($leaf)) {
4683 0         0 if (($unesc_head eq ':') and (Esjis::f qq{$unesc_head$leaf})) {
4684             }
4685             else {
4686             $leaf = $unesc_head . $leaf;
4687             }
4688              
4689 0         0 # On Mac OS, the two glob metachars '*' and '?' and the escape
4690 0         0 # char '\' are valid characters for file and directory names.
4691             # We have to escape and treat them specially.
4692             push @matched, _escape_MacOS($leaf);
4693 0 0       0 next INNER_MACOS;
4694 0         0 }
4695             }
4696             if (@matched) {
4697 0         0 push @glob, @matched;
4698             }
4699             }
4700             return @glob;
4701             }
4702              
4703             #
4704             # _expand_volume_MacOS() will only be used on Mac OS (OS9 or older):
4705             # Takes an array of original patterns as argument and returns an array of
4706             # possibly modified patterns. Each original pattern is processed like
4707             # that:
4708             # + If there's a volume name in the pattern, we push a separate pattern
4709             # for each mounted volume that matches (with '*', '?', and '\' escaped).
4710             # + If there's no volume name in the original pattern, it is pushed
4711             # unchanged.
4712             # Note that the returned array of patterns may be empty.
4713 0     0   0 #
4714 0 0       0 sub _expand_volume_MacOS {
4715              
4716 0         0 CORE::eval q{ CORE::require MacPerl; };
4717 0         0 croak "Can't require MacPerl;" if $@;
4718 0         0  
4719             my @volume_glob = @_;
4720             my @expand_volume = ();
4721 0 0       0 for my $volume_glob (@volume_glob) {
4722 0         0  
4723 0         0 # volume name in pattern
4724             if ($volume_glob =~ /\A ((?:[^\x81-\x9F\xE0-\xFC:]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])+:) (.*) \z/oxms) {
4725 0         0 my $pattern = _quotemeta_MacOS($1);
  0         0  
4726 0 0       0 my $tail = $2;
4727              
4728             for my $volume (map { MacPerl::MakePath($_) } MacPerl::Volumes()) {
4729             if ($volume =~ /\A $pattern \z/xmsi) {
4730              
4731 0         0 # On Mac OS, the two glob metachars '*' and '?' and the
4732             # escape char '\' are valid characters for volume names.
4733             # We have to escape and treat them specially.
4734             push @expand_volume, _escape_MacOS($volume) . $tail;
4735             }
4736             }
4737             }
4738 0         0  
4739             # no volume name in pattern
4740             else {
4741 0         0 push @expand_volume, $volume_glob;
4742             }
4743             }
4744             return @expand_volume;
4745             }
4746              
4747             #
4748             # _canonpath_MacOS() will only be used on Mac OS (OS9 or older):
4749             # Resolves any updirs in the pattern. Removes a single trailing colon
4750 0     0   0 # from the pattern, unless it's a volume name pattern like "*HD:"
4751             #
4752 0         0 sub _canonpath_MacOS {
4753             my(@expr) = @_;
4754              
4755 0         0 for my $expr (@expr) {
4756              
4757             # resolve any updirs, e.g. "*HD:t?p::a*" -> "*HD:a*"
4758 0         0 1 while ($expr =~ s/\A ((?:[^\x81-\x9F\xE0-\xFC:]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?) : (?:[^\x81-\x9F\xE0-\xFC:]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])+ :: ((?:$q_char)*?) \z/$1:$2/oxms);
4759              
4760 0         0 # remove a single trailing colon, e.g. ":*:" -> ":*"
4761             $expr =~ s/ : ((?:[^\x81-\x9F\xE0-\xFC:]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])+) : \z/:$1/oxms;
4762             }
4763             return @expr;
4764             }
4765              
4766             #
4767             # _escape_MacOS() will only be used on Mac OS (OS9 or older):
4768 0     0   0 # Escape metachars '*', '?', and '\' of arguments.
4769             #
4770             sub _escape_MacOS {
4771 0         0 my($expr) = @_;
4772 0         0  
4773 0         0 # escape regex metachars but not '\' and glob chars '*', '?'
4774 0 0       0 my $escape = '';
4775 0         0 while ($expr =~ / \G ($q_char) /oxmsgc) {
4776             my $char = $1;
4777             if ($char =~ /\A [*?\\] \z/oxms) {
4778 0         0 $escape .= '\\' . $char;
4779             }
4780             else {
4781 0         0 $escape .= $char;
4782             }
4783             }
4784             return $escape;
4785             }
4786              
4787             #
4788             # _unescape_MacOS() will only be used on Mac OS (OS9 or older):
4789             # Unescapes a list of arguments which may contain escaped
4790 0     0   0 # metachars '*', '?', and '\'.
4791             #
4792 0         0 sub _unescape_MacOS {
4793 0         0 my($expr) = @_;
4794 0         0  
4795 0 0       0 my $unescape = '';
4796 0         0 while ($expr =~ / \G (\\[*?\\] | $q_char) /oxmsgc) {
4797             my $char = $1;
4798             if ($char =~ /\A \\([*?\\]) \z/oxms) {
4799 0         0 $unescape .= $1;
4800             }
4801             else {
4802 0         0 $unescape .= $char;
4803             }
4804             }
4805             return $unescape;
4806             }
4807              
4808             #
4809 0     0   0 # _hasmeta_MacOS() will only be used on Mac OS (OS9 or older):
4810             #
4811             sub _hasmeta_MacOS {
4812             my($expr) = @_;
4813              
4814 0         0 # if a '*' or '?' is preceded by an odd count of '\', temporary delete
4815 0         0 # it (and its preceding backslashes), i.e. don't treat '\*' and '\?' as
4816 0 0       0 # wildcards
    0          
4817 0         0 while ($expr =~ / \G (\\[*?\\] | $q_char) /oxgc) {
4818             my $char = $1;
4819             if ($char eq '*') {
4820 0         0 return 1;
4821             }
4822             elsif ($char eq '?') {
4823 0         0 return 1;
4824             }
4825             }
4826             return 0;
4827             }
4828              
4829             #
4830 0     0   0 # _quotemeta_MacOS() will only be used on Mac OS (OS9 or older):
4831             #
4832             sub _quotemeta_MacOS {
4833 0         0 my($expr) = @_;
4834 0         0  
4835 0         0 # escape regex metachars but not '\' and glob chars '*', '?'
4836 0 0       0 my $quotemeta = '';
    0          
    0          
    0          
4837 0         0 while ($expr =~ / \G (\\[*?\\] | $q_char) /oxgc) {
4838             my $char = $1;
4839             if ($char =~ /\A \\[*?\\] \z/oxms) {
4840 0         0 $quotemeta .= $char;
4841             }
4842             elsif ($char eq '*') {
4843 0         0 $quotemeta .= "(?:$your_char)*",
4844             }
4845             elsif ($char eq '?') {
4846             $quotemeta .= "(?:$your_char)?", # DOS style
4847 0         0 # $quotemeta .= "(?:$your_char)", # UNIX style
4848             }
4849             elsif ((my $fc = Esjis::fc($char)) ne $char) {
4850 0         0 $quotemeta .= $fc;
4851             }
4852             else {
4853 0         0 $quotemeta .= quotemeta $char;
4854             }
4855             }
4856             return $quotemeta;
4857             }
4858              
4859             #
4860             # via File::HomeDir::Windows 1.00
4861             #
4862             sub my_home_MSWin32 {
4863              
4864 0 0 0 0 0 0 # A lot of unix people and unix-derived tools rely on
    0 0        
    0 0        
      0        
      0        
4865 0         0 # the ability to overload HOME. We will support it too
4866             # so that they can replace raw HOME calls with File::HomeDir.
4867             if (exists $ENV{'HOME'} and $ENV{'HOME'}) {
4868             return $ENV{'HOME'};
4869             }
4870 0         0  
4871             # Do we have a user profile?
4872             elsif (exists $ENV{'USERPROFILE'} and $ENV{'USERPROFILE'}) {
4873             return $ENV{'USERPROFILE'};
4874             }
4875 0         0  
4876             # Some Windows use something like $ENV{'HOME'}
4877             elsif (exists $ENV{'HOMEDRIVE'} and exists $ENV{'HOMEPATH'} and $ENV{'HOMEDRIVE'} and $ENV{'HOMEPATH'}) {
4878 0         0 return join '', $ENV{'HOMEDRIVE'}, $ENV{'HOMEPATH'};
4879             }
4880              
4881             return undef;
4882             }
4883              
4884             #
4885             # via File::HomeDir::MacOS9 1.00
4886             #
4887 0 0   0 0 0 sub my_home_MacOS {
4888 0         0  
4889             # Try for $ENV{'HOME'} if we have it
4890             if (defined $ENV{'HOME'}) {
4891             return $ENV{'HOME'};
4892             }
4893              
4894             ### DESPERATION SETS IN
4895 0         0  
  0         0  
4896 0         0 # We could use the desktop
4897             SCOPE: {
4898 0         0 local $@;
4899 0         0 CORE::eval {
4900 0         0 # Find the desktop via Mac::Files
4901             local $SIG{'__DIE__'} = '';
4902             CORE::require Mac::Files;
4903             my $home = Mac::Files::FindFolder(
4904 0 0 0     0 Mac::Files::kOnSystemDisk(),
4905             Mac::Files::kDesktopFolderType(),
4906             );
4907             return $home if $home and Esjis::d($home);
4908             };
4909             }
4910              
4911 0         0 # Desperation on any platform
  0         0  
4912 0         0 SCOPE: {
4913 0 0 0     0 # On some platforms getpwuid dies if called at all
4914             local $SIG{'__DIE__'} = '';
4915             my $home = CORE::eval q{ (getpwuid($<))[7] };
4916 0         0 return $home if $home and Esjis::d($home);
4917             }
4918              
4919             croak "Could not locate current user's home directory";
4920             }
4921              
4922             #
4923 0     0 0 0 # via File::HomeDir::Unix 1.00
4924             #
4925 0 0 0     0 sub my_home {
    0 0        
4926 0         0 my $home;
4927              
4928             if (exists $ENV{'HOME'} and defined $ENV{'HOME'}) {
4929             $home = $ENV{'HOME'};
4930             }
4931              
4932 0         0 # This is from the original code, but I'm guessing
4933             # it means "login directory" and exists on some Unixes.
4934             elsif (exists $ENV{'LOGDIR'} and $ENV{'LOGDIR'}) {
4935             $home = $ENV{'LOGDIR'};
4936             }
4937              
4938             ### More-desperate methods
4939 0         0  
4940             # Light desperation on any (Unixish) platform
4941             else {
4942             $home = CORE::eval q{ (getpwuid($<))[7] };
4943             }
4944 0 0 0     0  
4945 0         0 # On Unix in general, a non-existant home means "no home"
4946             # For example, "nobody"-like users might use /nonexistant
4947 0         0 if (defined $home and ! Esjis::d($home)) {
4948             $home = undef;
4949             }
4950             return $home;
4951             }
4952              
4953             #
4954             # ShiftJIS file lstat (with parameter)
4955 0 0   0 0 0 #
4956             sub Esjis::lstat(*) {
4957 0 0       0  
    0          
4958 0         0 local $_ = shift if @_;
4959              
4960             if (-e $_) {
4961             return CORE::lstat _;
4962             }
4963             elsif (_MSWin32_5Cended_path($_)) {
4964              
4965             # Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Esjis::lstat()
4966 0         0 # on Windows opens the file for the path which has 5c at end.
4967 0 0       0 # (and so on)
4968 0 0       0  
4969 0         0 local *MUST_BE_BAREWORD_AT_HERE;
4970 0 0       0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
4971 0         0 if (wantarray) {
4972             my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
4973             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4974 0         0 return @stat;
4975 0 0       0 }
4976 0         0 else {
4977             my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
4978             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4979             return $stat;
4980 0 0       0 }
4981             }
4982             }
4983             return wantarray ? () : undef;
4984             }
4985              
4986             #
4987             # ShiftJIS file lstat (without parameter)
4988 0 0   0 0 0 #
    0          
4989 0         0 sub Esjis::lstat_() {
4990              
4991             if (-e $_) {
4992 0         0 return CORE::lstat _;
4993 0 0       0 }
4994 0 0       0 elsif (_MSWin32_5Cended_path($_)) {
4995 0         0 local *MUST_BE_BAREWORD_AT_HERE;
4996 0 0       0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
4997 0         0 if (wantarray) {
4998             my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
4999             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
5000 0         0 return @stat;
5001 0 0       0 }
5002 0         0 else {
5003             my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
5004             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
5005             return $stat;
5006 0 0       0 }
5007             }
5008             }
5009             return wantarray ? () : undef;
5010             }
5011              
5012             #
5013             # ShiftJIS path opendir
5014 0     0 0 0 #
5015 0 0       0 sub Esjis::opendir(*$) {
    0          
5016 0         0  
5017             my $dh = qualify_to_ref $_[0];
5018             if (CORE::opendir $dh, $_[1]) {
5019 0 0       0 return 1;
5020 0         0 }
5021             elsif (_MSWin32_5Cended_path($_[1])) {
5022             if (CORE::opendir $dh, "$_[1]/.") {
5023 0         0 return 1;
5024             }
5025             }
5026             return undef;
5027             }
5028              
5029             #
5030             # ShiftJIS file stat (with parameter)
5031 0 50   387 0 0 #
5032             sub Esjis::stat(*) {
5033 387         2247  
5034 387 50       2109 local $_ = shift if @_;
    50          
    0          
5035 387         12551  
5036             my $fh = qualify_to_ref $_;
5037             if (defined fileno $fh) {
5038 0         0 return CORE::stat $fh;
5039             }
5040             elsif (-e $_) {
5041             return CORE::stat _;
5042             }
5043             elsif (_MSWin32_5Cended_path($_)) {
5044              
5045             # Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Esjis::stat()
5046 387         3363 # on Windows opens the file for the path which has 5c at end.
5047 0 0       0 # (and so on)
5048 0 0       0  
5049 0         0 local *MUST_BE_BAREWORD_AT_HERE;
5050 0 0       0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
5051 0         0 if (wantarray) {
5052             my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
5053             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
5054 0         0 return @stat;
5055 0 0       0 }
5056 0         0 else {
5057             my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
5058             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
5059             return $stat;
5060 0 0       0 }
5061             }
5062             }
5063             return wantarray ? () : undef;
5064             }
5065              
5066             #
5067             # ShiftJIS file stat (without parameter)
5068 0     0 0 0 #
5069 0 0       0 sub Esjis::stat_() {
    0          
    0          
5070 0         0  
5071             my $fh = qualify_to_ref $_;
5072             if (defined fileno $fh) {
5073 0         0 return CORE::stat $fh;
5074             }
5075             elsif (-e $_) {
5076 0         0 return CORE::stat _;
5077 0 0       0 }
5078 0 0       0 elsif (_MSWin32_5Cended_path($_)) {
5079 0         0 local *MUST_BE_BAREWORD_AT_HERE;
5080 0 0       0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
5081 0         0 if (wantarray) {
5082             my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
5083             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
5084 0         0 return @stat;
5085 0 0       0 }
5086 0         0 else {
5087             my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
5088             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
5089             return $stat;
5090 0 0       0 }
5091             }
5092             }
5093             return wantarray ? () : undef;
5094             }
5095              
5096             #
5097             # ShiftJIS path unlink
5098 0 0   0 0 0 #
5099             sub Esjis::unlink(@) {
5100 0         0  
5101 0         0 local @_ = ($_) unless @_;
5102 0 0       0  
    0          
    0          
5103 0         0 my $unlink = 0;
5104             for (@_) {
5105             if (CORE::unlink) {
5106             $unlink++;
5107             }
5108 0         0 elsif (Esjis::d($_)) {
5109 0 0       0 }
  0         0  
5110 0 0       0 elsif (_MSWin32_5Cended_path($_)) {
5111 0         0 my @char = /\G (?>$q_char) /oxmsg;
5112             my $file = join '', map {{'/' => '\\'}->{$_} || $_} @char;
5113 0         0 if ($file =~ / \A (?:$q_char)*? [ ] /oxms) {
5114 0 0       0 $file = qq{"$file"};
5115 0 0       0 }
5116             my $fh = gensym();
5117             if (_open_r($fh, $_)) {
5118 0 0 0     0 close($fh) or die "Can't close file: $_: $!";
    0          
5119 0         0  
5120             # cmd.exe on Windows NT, Windows 2000, Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10 or later
5121             if ((defined $ENV{'OS'}) and ($ENV{'OS'} eq 'Windows_NT')) {
5122             CORE::system 'DEL', '/F', $file, '2>NUL';
5123             }
5124 0         0  
5125             # Win95Cmd.exe on any Windows (when SET PERL5SHELL=Win95Cmd.exe /c, `var` returns "Windows 2000")
5126             elsif (qx{ver} =~ /\b(?:Windows 2000)\b/oms) {
5127             CORE::system 'DEL', '/F', $file, '2>NUL';
5128             }
5129              
5130 0         0 # COMMAND.COM on Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition
5131 0         0 # command.com can not "2>NUL"
5132             else {
5133             CORE::system 'ATTRIB', '-R', $file; # clears Read-only file attribute
5134 0 0       0 CORE::system 'DEL', $file;
5135 0 0       0 }
5136              
5137             if (_open_r($fh, $_)) {
5138 0         0 close($fh) or die "Can't close file: $_: $!";
5139             }
5140             else {
5141             $unlink++;
5142             }
5143 0         0 }
5144             }
5145             }
5146             return $unlink;
5147             }
5148              
5149             #
5150             # ShiftJIS chdir
5151 0 0   0 0 0 #
5152 0         0 sub Esjis::chdir(;$) {
5153              
5154             if (@_ == 0) {
5155 0         0 return CORE::chdir;
5156             }
5157 0 0       0  
5158 0 0       0 my($dir) = @_;
5159 0         0  
5160             if (_MSWin32_5Cended_path($dir)) {
5161             if (not Esjis::d $dir) {
5162 0 0 0     0 return 0;
    0          
5163 0         0 }
5164              
5165             if ($] =~ /^5\.005/oxms) {
5166 0         0 return CORE::chdir $dir;
5167 0         0 }
5168             elsif (($] =~ /^(?:5\.006|5\.008000)/oxms) and ($^O eq 'MSWin32')) {
5169             local $@;
5170             my $chdir = CORE::eval q{
5171             CORE::require 'jacode.pl';
5172              
5173             # P.676 ${^WIDE_SYSTEM_CALLS}
5174             # in Chapter 28: Special Names
5175             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
5176              
5177             # P.790 ${^WIDE_SYSTEM_CALLS}
5178             # in Chapter 25: Special Names
5179             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5180              
5181 0 0       0 local ${^WIDE_SYSTEM_CALLS} = 1;
5182 0         0 return CORE::chdir jcode::utf8($dir,'sjis');
5183             };
5184             if (not $@) {
5185             return $chdir;
5186             }
5187             }
5188              
5189             # old idea (Win32 module required)
5190             elsif (0) {
5191             local $@;
5192             my $shortdir = '';
5193             my $chdir = CORE::eval q{
5194             use Win32;
5195             $shortdir = Win32::GetShortPathName($dir);
5196             if ($shortdir ne $dir) {
5197             return CORE::chdir $shortdir;
5198             }
5199             else {
5200             return 0;
5201             }
5202             };
5203             if ($@) {
5204             my @char = $dir =~ /\G (?>$q_char) /oxmsg;
5205             while ($char[-1] eq "\x5C") {
5206             pop @char;
5207             }
5208             $dir = join '', @char;
5209             croak "Perl$] can't chdir to $dir (chr(0x5C) ended path), Win32.pm module may help you";
5210             }
5211             elsif ($shortdir eq $dir) {
5212             my @char = $dir =~ /\G (?>$q_char) /oxmsg;
5213             while ($char[-1] eq "\x5C") {
5214             pop @char;
5215             }
5216             $dir = join '', @char;
5217             croak "Perl$] can't chdir to $dir (chr(0x5C) ended path)";
5218             }
5219             return $chdir;
5220 0         0 }
5221              
5222             # rejected idea ...
5223             elsif (0) {
5224              
5225             # MSDN SetCurrentDirectory function
5226             # http://msdn.microsoft.com/ja-jp/library/windows/desktop/aa365530(v=vs.85).aspx
5227             #
5228             # Data Execution Prevention (DEP)
5229             # http://vlaurie.com/computers2/Articles/dep.htm
5230             #
5231             # Learning x86 assembler with Perl -- Shibuya.pm#11
5232             # http://developer.cybozu.co.jp/takesako/2009/06/perl-x86-shibuy.html
5233             #
5234             # Introduction to Win32::API programming in Perl
5235             # http://d.hatena.ne.jp/TAKESAKO/20090324/1237879559
5236             #
5237             # DynaLoader - Dynamically load C libraries into Perl code
5238             # http://perldoc.perl.org/DynaLoader.html
5239             #
5240             # Basic knowledge of DynaLoader
5241             # http://blog.64p.org/entry/20090313/1236934042
5242              
5243             if (($] =~ /^5\.006/oxms) and
5244             ($^O eq 'MSWin32') and
5245             ($ENV{'PROCESSOR_ARCHITECTURE'} eq 'x86') and
5246             CORE::eval(q{CORE::require 'Dyna'.'Loader'})
5247             ) {
5248             my $x86 = join('',
5249              
5250             # PUSH Iv
5251             "\x68", pack('P', "$dir\\\0"),
5252              
5253             # MOV eAX, Iv
5254             "\xb8", pack('L',
5255             *{'Dyna'.'Loader::dl_find_symbol'}{'CODE'}->(
5256             *{'Dyna'.'Loader::dl_load_file'}{'CODE'}->("$ENV{'SystemRoot'}\\system32\\kernel32.dll"),
5257             'SetCurrentDirectoryA'
5258             )
5259             ),
5260              
5261             # CALL eAX
5262             "\xff\xd0",
5263              
5264             # RETN
5265             "\xc3",
5266             );
5267             *{'Dyna'.'Loader::dl_install_xsub'}{'CODE'}->('_SetCurrentDirectoryA', unpack('L', pack 'P', $x86));
5268             _SetCurrentDirectoryA();
5269             chomp(my $chdir = qx{chdir});
5270             if (Esjis::fc($chdir) eq Esjis::fc($dir)) {
5271             return 1;
5272             }
5273             else {
5274             return 0;
5275             }
5276             }
5277             }
5278              
5279             # COMMAND.COM's unhelpful tips:
5280             # Displays a list of files and subdirectories in a directory.
5281             # http://www.lagmonster.org/docs/DOS7/z-dir.html
5282             #
5283             # Syntax:
5284             #
5285             # DIR [drive:] [path] [filename] [/Switches]
5286             #
5287             # /Z Long file names are not displayed in the file listing
5288             #
5289             # Limitations
5290             # The undocumented /Z switch (no long names) would appear to
5291             # have been not fully developed and has a couple of problems:
5292             #
5293             # 1. It will only work if:
5294             # There is no path specified (ie. for the current directory in
5295             # the current drive)
5296             # The path is specified as the root directory of any drive
5297             # (eg. C:\, D:\, etc.)
5298             # The path is specified as the current directory of any drive
5299             # by using the drive letter only (eg. C:, D:, etc.)
5300             # The path is specified as the parent directory using the ..
5301             # notation (eg. DIR .. /Z)
5302             # Any other syntax results in a "File Not Found" error message.
5303             #
5304             # 2. The /Z switch is compatable with the /S switch to show
5305             # subdirectories (as long as the above rules are followed) and
5306             # all the files are shown with short names only. The
5307             # subdirectories are also shown with short names only. However,
5308             # the header for each subdirectory after the first level gives
5309             # the subdirectory's long name.
5310             #
5311             # 3. The /Z switch is also compatable with the /B switch to give
5312             # a simple list of files with short names only. When used with
5313             # the /S switch as well, all files are listed with their full
5314             # paths. The file names themselves are all in short form, and
5315             # the path of those files in the current directory are in short
5316 0         0 # form, but the paths of any files in subdirectories are in
5317 0         0 # long filename form.
5318 0         0  
5319 0         0 my $shortdir = '';
5320 0         0 my $i = 0;
5321 0 0 0     0 my @subdir = ();
5322 0         0 while ($dir =~ / \G ($q_char) /oxgc) {
5323 0         0 my $char = $1;
5324 0         0 if (($char eq '\\') or ($char eq '/')) {
5325             $i++;
5326             $subdir[$i] = $char;
5327 0         0 $i++;
5328             }
5329             else {
5330 0 0 0     0 $subdir[$i] .= $char;
5331 0         0 }
5332             }
5333             if (($subdir[-1] eq '\\') or ($subdir[-1] eq '/')) {
5334             pop @subdir;
5335             }
5336              
5337             # P.504 PERL5SHELL (Microsoft ports only)
5338             # in Chapter 19: The Command-Line Interface
5339             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
5340              
5341             # P.597 PERL5SHELL (Microsoft ports only)
5342             # in Chapter 17: The Command-Line Interface
5343             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5344 0 0 0     0  
    0          
5345 0         0 # Win95Cmd.exe on any Windows (when SET PERL5SHELL=Win95Cmd.exe /c, `var` returns "Windows 2000")
5346 0         0 # cmd.exe on Windows NT, Windows 2000
  0         0  
5347 0 0       0 if (qx{ver} =~ /\b(?:Windows NT|Windows 2000)\b/oms) {
5348             chomp(my @dirx = grep //oxms, qx{dir /ad /x "$dir*" 2>NUL});
5349             for my $dirx (sort { CORE::length($a) <=> CORE::length($b) } @dirx) {
5350 0         0 if (Esjis::fc(CORE::substr $dirx,-CORE::length($subdir[-1]),CORE::length($subdir[-1])) eq Esjis::fc($subdir[-1])) {
5351 0         0  
5352 0         0 # short file name (8dot3name) here-----vv
5353 0         0 my $shortleafdir = CORE::substr $dirx, 39, 8+1+3;
5354             $shortleafdir =~ s/ [ ]+ \z//oxms;
5355             $shortdir = join '', @subdir[0..$#subdir-1], $shortleafdir;
5356             last;
5357             }
5358             }
5359             }
5360              
5361             # an idea (not so portable, only Windows 2000 or later)
5362             elsif (0) {
5363             chomp($shortdir = qx{for %I in ("$dir") do \@echo %~sI 2>NUL});
5364             }
5365 0         0  
5366 0         0 # cmd.exe on Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10 or later
  0         0  
5367 0 0       0 elsif ((defined $ENV{'OS'}) and ($ENV{'OS'} eq 'Windows_NT')) {
5368             chomp(my @dirx = grep //oxms, qx{dir /ad /x "$dir*" 2>NUL});
5369             for my $dirx (sort { CORE::length($a) <=> CORE::length($b) } @dirx) {
5370 0         0 if (Esjis::fc(CORE::substr $dirx,-CORE::length($subdir[-1]),CORE::length($subdir[-1])) eq Esjis::fc($subdir[-1])) {
5371 0         0  
5372 0         0 # short file name (8dot3name) here-----vv
5373 0         0 my $shortleafdir = CORE::substr $dirx, 36, 8+1+3;
5374             $shortleafdir =~ s/ [ ]+ \z//oxms;
5375             $shortdir = join '', @subdir[0..$#subdir-1], $shortleafdir;
5376             last;
5377             }
5378             }
5379             }
5380 0         0  
5381 0         0 # COMMAND.COM on Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition
  0         0  
5382 0 0       0 else {
5383             chomp(my @dirx = grep //oxms, qx{dir /ad "$dir*"});
5384             for my $dirx (sort { CORE::length($a) <=> CORE::length($b) } @dirx) {
5385 0         0 if (Esjis::fc(CORE::substr $dirx,-CORE::length($subdir[-1]),CORE::length($subdir[-1])) eq Esjis::fc($subdir[-1])) {
5386 0         0  
5387 0         0 # short file name (8dot3name) here-----v
5388 0         0 my $shortleafdir = CORE::substr $dirx, 0, 8+1+3;
5389 0         0 CORE::substr($shortleafdir,8,1) = '.';
5390             $shortleafdir =~ s/ \. [ ]+ \z//oxms;
5391             $shortdir = join '', @subdir[0..$#subdir-1], $shortleafdir;
5392             last;
5393             }
5394 0 0       0 }
    0          
5395 0         0 }
5396              
5397             if ($shortdir eq '') {
5398 0         0 return 0;
5399             }
5400 0         0 elsif (Esjis::fc($shortdir) eq Esjis::fc($dir)) {
5401             return 0;
5402             }
5403 0         0 return CORE::chdir $shortdir;
5404             }
5405             else {
5406             return CORE::chdir $dir;
5407             }
5408             }
5409              
5410             #
5411             # ShiftJIS chr(0x5C) ended path on MSWin32
5412 0 50 33 774   0 #
5413 774 50       5182 sub _MSWin32_5Cended_path {
5414 774         4400  
5415 0 0       0 if ((@_ >= 1) and ($_[0] ne '')) {
5416 0         0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
5417             my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
5418             if ($char[-1] =~ / \x5C \z/oxms) {
5419             return 1;
5420 0         0 }
5421             }
5422             }
5423             return undef;
5424             }
5425              
5426             #
5427             # do ShiftJIS file
5428 774     0 0 2026 #
5429             sub Esjis::do($) {
5430 0         0  
5431             my($filename) = @_;
5432              
5433             my $realfilename;
5434 0         0 my $result;
  0         0  
5435 0 0       0 ITER_DO:
5436 0         0 {
5437             for my $prefix (@INC) {
5438             if ($^O eq 'MacOS') {
5439 0         0 $realfilename = "$prefix$filename";
5440             }
5441             else {
5442 0 0       0 $realfilename = "$prefix/$filename";
5443             }
5444 0         0  
5445             if (Esjis::f($realfilename)) {
5446 0 0       0  
5447 0         0 my $script = '';
5448 0         0  
5449 0         0 if (Esjis::e("$realfilename.e")) {
5450 0 0 0     0 my $e_mtime = (Esjis::stat("$realfilename.e"))[9];
5451 0         0 my $mtime = (Esjis::stat($realfilename))[9];
5452             my $module_mtime = (Esjis::stat(__FILE__))[9];
5453             if (($e_mtime < $mtime) or ($mtime < $module_mtime)) {
5454             Esjis::unlink "$realfilename.e";
5455 0 0       0 }
5456 0         0 }
5457 0 0       0  
5458 0 0       0 if (Esjis::e("$realfilename.e")) {
    0          
5459 0         0 my $fh = gensym();
5460             if (_open_r($fh, "$realfilename.e")) {
5461             if ($^O eq 'MacOS') {
5462             CORE::eval q{
5463             CORE::require Mac::Files;
5464             Mac::Files::FSpSetFLock("$realfilename.e");
5465             };
5466             }
5467             elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5468              
5469             # P.419 File Locking
5470             # in Chapter 16: Interprocess Communication
5471             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
5472              
5473             # P.524 File Locking
5474             # in Chapter 15: Interprocess Communication
5475             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5476 0         0  
5477 0 0       0 # (and so on)
5478 0         0  
5479             CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5480             if ($@) {
5481             carp "Can't immediately read-lock the file: $realfilename.e";
5482 0         0 }
5483             }
5484 0         0 else {
5485 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5486 0 0       0 }
5487 0         0 local $/ = undef; # slurp mode
5488             $script = <$fh>;
5489             if ($^O eq 'MacOS') {
5490             CORE::eval q{
5491             CORE::require Mac::Files;
5492 0 0       0 Mac::Files::FSpRstFLock("$realfilename.e");
5493             };
5494             }
5495             close($fh) or die "Can't close file: $realfilename.e: $!";
5496 0         0 }
5497 0 0       0 }
5498 0 0       0 else {
    0          
5499 0         0 my $fh = gensym();
5500             if (_open_r($fh, $realfilename)) {
5501             if ($^O eq 'MacOS') {
5502             CORE::eval q{
5503             CORE::require Mac::Files;
5504             Mac::Files::FSpSetFLock($realfilename);
5505 0         0 };
5506 0 0       0 }
5507 0         0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5508             CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5509             if ($@) {
5510             carp "Can't immediately read-lock the file: $realfilename";
5511 0         0 }
5512             }
5513 0         0 else {
5514 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5515 0 0       0 }
5516 0         0 local $/ = undef; # slurp mode
5517             $script = <$fh>;
5518             if ($^O eq 'MacOS') {
5519             CORE::eval q{
5520             CORE::require Mac::Files;
5521 0 0       0 Mac::Files::FSpRstFLock($realfilename);
5522             };
5523             }
5524 0 0       0 close($fh) or die "Can't close file: $realfilename.e: $!";
5525 0         0 }
5526 0         0  
5527 0         0 if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
5528 0 0       0 CORE::require Sjis;
5529 0 0       0 $script = Sjis::escape_script($script);
    0          
5530 0         0 my $fh = gensym();
5531             open($fh, ">$realfilename.e") or die __FILE__, ": Can't write open file: $realfilename.e\n";
5532             if ($^O eq 'MacOS') {
5533             CORE::eval q{
5534             CORE::require Mac::Files;
5535             Mac::Files::FSpSetFLock("$realfilename.e");
5536 0         0 };
5537 0 0       0 }
5538 0         0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5539             CORE::eval q{ flock($fh, LOCK_EX | LOCK_NB) };
5540             if ($@) {
5541             carp "Can't immediately write-lock the file: $realfilename.e";
5542 0         0 }
5543             }
5544 0         0 else {
5545 0 0       0 CORE::eval q{ flock($fh, LOCK_EX) };
5546 0         0 }
  0         0  
5547 0 0       0 CORE::eval q{ truncate($fh, 0) };
5548 0         0 seek($fh, 0, 0) or croak "Can't seek file: $realfilename.e";
5549             print {$fh} $script;
5550             if ($^O eq 'MacOS') {
5551             CORE::eval q{
5552             CORE::require Mac::Files;
5553 0 0       0 Mac::Files::FSpRstFLock("$realfilename.e");
5554             };
5555             }
5556             close($fh) or die "Can't close file: $realfilename.e: $!";
5557             }
5558 392     392   6233 }
  392         2857  
  392         338350  
  0         0  
5559 0         0  
5560             {
5561 0         0 no strict;
5562             $result = scalar CORE::eval $script;
5563             }
5564             last ITER_DO;
5565             }
5566 0 0       0 }
    0          
5567 0         0 }
5568 0         0  
5569             if ($@) {
5570             $INC{$filename} = undef;
5571 0         0 return undef;
5572             }
5573             elsif (not $result) {
5574 0         0 return undef;
5575 0         0 }
5576             else {
5577             $INC{$filename} = $realfilename;
5578             return $result;
5579             }
5580             }
5581              
5582             #
5583             # require ShiftJIS file
5584             #
5585              
5586             # require
5587             # in Chapter 3: Functions
5588             # of ISBN 1-56592-149-6 Programming Perl, Second Edition.
5589             #
5590             # sub require {
5591             # my($filename) = @_;
5592             # return 1 if $INC{$filename};
5593             # my($realfilename, $result);
5594             # ITER: {
5595             # foreach $prefix (@INC) {
5596             # $realfilename = "$prefix/$filename";
5597             # if (-f $realfilename) {
5598             # $result = CORE::eval `cat $realfilename`;
5599             # last ITER;
5600             # }
5601             # }
5602             # die "Can't find $filename in \@INC";
5603             # }
5604             # die $@ if $@;
5605             # die "$filename did not return true value" unless $result;
5606             # $INC{$filename} = $realfilename;
5607             # return $result;
5608             # }
5609              
5610             # require
5611             # in Chapter 9: perlfunc: Perl builtin functions
5612             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
5613             #
5614             # sub require {
5615             # my($filename) = @_;
5616             # if (exists $INC{$filename}) {
5617             # return 1 if $INC{$filename};
5618             # die "Compilation failed in require";
5619             # }
5620             # my($realfilename, $result);
5621             # ITER: {
5622             # foreach $prefix (@INC) {
5623             # $realfilename = "$prefix/$filename";
5624             # if (-f $realfilename) {
5625             # $INC{$filename} = $realfilename;
5626             # $result = do $realfilename;
5627             # last ITER;
5628             # }
5629             # }
5630             # die "Can't find $filename in \@INC";
5631             # }
5632             # if ($@) {
5633             # $INC{$filename} = undef;
5634             # die $@;
5635             # }
5636             # elsif (!$result) {
5637             # delete $INC{$filename};
5638             # die "$filename did not return true value";
5639             # }
5640             # else {
5641             # return $result;
5642             # }
5643             # }
5644 0 0   0 0 0  
5645             sub Esjis::require(;$) {
5646 0 0       0  
5647 0 0       0 local $_ = shift if @_;
5648 0         0  
5649             if (exists $INC{$_}) {
5650             return 1 if $INC{$_};
5651             croak "Compilation failed in require: $_";
5652             }
5653              
5654             # jcode.pl
5655             # ftp://ftp.iij.ad.jp/pub/IIJ/dist/utashiro/perl/
5656              
5657 0 0       0 # jacode.pl
5658 0         0 # http://search.cpan.org/dist/jacode/
5659              
5660             if (/ \b (?: jcode\.pl | jacode(?>[0-9]*)\.pl ) \z /oxms) {
5661 0         0 return CORE::require($_);
5662             }
5663              
5664             my $realfilename;
5665 0         0 my $result;
  0         0  
5666 0 0       0 ITER_REQUIRE:
5667 0         0 {
5668             for my $prefix (@INC) {
5669             if ($^O eq 'MacOS') {
5670 0         0 $realfilename = "$prefix$_";
5671             }
5672             else {
5673 0 0       0 $realfilename = "$prefix/$_";
5674 0         0 }
5675              
5676 0         0 if (Esjis::f($realfilename)) {
5677             $INC{$_} = $realfilename;
5678 0 0       0  
5679 0         0 my $script = '';
5680 0         0  
5681 0         0 if (Esjis::e("$realfilename.e")) {
5682 0 0 0     0 my $e_mtime = (Esjis::stat("$realfilename.e"))[9];
5683 0         0 my $mtime = (Esjis::stat($realfilename))[9];
5684             my $module_mtime = (Esjis::stat(__FILE__))[9];
5685             if (($e_mtime < $mtime) or ($mtime < $module_mtime)) {
5686             Esjis::unlink "$realfilename.e";
5687 0 0       0 }
5688 0         0 }
5689 0 0       0  
5690 0 0       0 if (Esjis::e("$realfilename.e")) {
    0          
5691 0         0 my $fh = gensym();
5692             _open_r($fh, "$realfilename.e") or croak "Can't open file: $realfilename.e";
5693             if ($^O eq 'MacOS') {
5694             CORE::eval q{
5695             CORE::require Mac::Files;
5696             Mac::Files::FSpSetFLock("$realfilename.e");
5697 0         0 };
5698 0 0       0 }
5699 0         0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5700             CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5701             if ($@) {
5702             carp "Can't immediately read-lock the file: $realfilename.e";
5703 0         0 }
5704             }
5705 0         0 else {
5706 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5707 0 0       0 }
5708 0         0 local $/ = undef; # slurp mode
5709             $script = <$fh>;
5710             if ($^O eq 'MacOS') {
5711             CORE::eval q{
5712             CORE::require Mac::Files;
5713 0 0       0 Mac::Files::FSpRstFLock("$realfilename.e");
5714             };
5715             }
5716 0         0 close($fh) or croak "Can't close file: $realfilename: $!";
5717 0 0       0 }
5718 0 0       0 else {
    0          
5719 0         0 my $fh = gensym();
5720             _open_r($fh, $realfilename) or croak "Can't open file: $realfilename";
5721             if ($^O eq 'MacOS') {
5722             CORE::eval q{
5723             CORE::require Mac::Files;
5724             Mac::Files::FSpSetFLock($realfilename);
5725 0         0 };
5726 0 0       0 }
5727 0         0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5728             CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5729             if ($@) {
5730             carp "Can't immediately read-lock the file: $realfilename";
5731 0         0 }
5732             }
5733 0         0 else {
5734 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5735 0 0       0 }
5736 0         0 local $/ = undef; # slurp mode
5737             $script = <$fh>;
5738             if ($^O eq 'MacOS') {
5739             CORE::eval q{
5740             CORE::require Mac::Files;
5741 0 0       0 Mac::Files::FSpRstFLock($realfilename);
5742             };
5743 0 0       0 }
5744 0         0 close($fh) or croak "Can't close file: $realfilename: $!";
5745 0         0  
5746 0         0 if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
5747 0 0       0 CORE::require Sjis;
5748 0 0       0 $script = Sjis::escape_script($script);
    0          
5749 0         0 my $fh = gensym();
5750             open($fh, ">$realfilename.e") or croak "Can't write open file: $realfilename.e";
5751             if ($^O eq 'MacOS') {
5752             CORE::eval q{
5753             CORE::require Mac::Files;
5754             Mac::Files::FSpSetFLock("$realfilename.e");
5755 0         0 };
5756 0 0       0 }
5757 0         0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5758             CORE::eval q{ flock($fh, LOCK_EX | LOCK_NB) };
5759             if ($@) {
5760             carp "Can't immediately write-lock the file: $realfilename.e";
5761 0         0 }
5762             }
5763 0         0 else {
5764 0 0       0 CORE::eval q{ flock($fh, LOCK_EX) };
5765 0         0 }
  0         0  
5766 0 0       0 CORE::eval q{ truncate($fh, 0) };
5767 0         0 seek($fh, 0, 0) or croak "Can't seek file: $realfilename.e";
5768             print {$fh} $script;
5769             if ($^O eq 'MacOS') {
5770             CORE::eval q{
5771             CORE::require Mac::Files;
5772 0 0       0 Mac::Files::FSpRstFLock("$realfilename.e");
5773             };
5774             }
5775             close($fh) or croak "Can't close file: $realfilename: $!";
5776             }
5777 392     392   2913 }
  392         4116  
  392         371130  
  0         0  
5778 0         0  
5779             {
5780 0         0 no strict;
5781             $result = scalar CORE::eval $script;
5782             }
5783 0         0 last ITER_REQUIRE;
5784             }
5785             }
5786 0 0       0 croak "Can't find $_ in \@INC";
    0          
5787 0         0 }
5788 0         0  
5789             if ($@) {
5790             $INC{$_} = undef;
5791 0         0 croak $@;
5792 0         0 }
5793             elsif (not $result) {
5794             delete $INC{$_};
5795 0         0 croak "$_ did not return true value";
5796             }
5797             else {
5798             return $result;
5799             }
5800             }
5801              
5802             #
5803             # ShiftJIS telldir avoid warning
5804 0     774 0 0 #
5805             sub Esjis::telldir(*) {
5806 774         2294  
5807             local $^W = 0;
5808              
5809             return CORE::telldir $_[0];
5810             }
5811              
5812             #
5813 774 0   0 0 11783 # ${^PREMATCH}, $PREMATCH, $` the string preceding what was matched
5814 0 0 0     0 #
5815 0         0 sub Esjis::PREMATCH {
5816             if (defined($&)) {
5817             if (defined($1) and (CORE::substr($&,-CORE::length($1),CORE::length($1)) eq $1)) {
5818 0         0 return CORE::substr($&,0,CORE::length($&)-CORE::length($1));
5819             }
5820             else {
5821             croak 'Use of "$`", $PREMATCH, and ${^PREMATCH} need to /( capture all )/ in regexp';
5822 0         0 }
5823             }
5824 0         0 else {
5825             return '';
5826             }
5827             return $`;
5828             }
5829              
5830             #
5831 0 0   0 0 0 # ${^MATCH}, $MATCH, $& the string that matched
5832 0 0       0 #
5833 0         0 sub Esjis::MATCH {
5834             if (defined($&)) {
5835             if (defined($1)) {
5836 0         0 return $1;
5837             }
5838             else {
5839             croak 'Use of "$&", $MATCH, and ${^MATCH} need to /( capture all )/ in regexp';
5840 0         0 }
5841             }
5842 0         0 else {
5843             return '';
5844             }
5845             return $&;
5846             }
5847              
5848             #
5849 0     0 0 0 # ${^POSTMATCH}, $POSTMATCH, $' the string following what was matched
5850             #
5851             sub Esjis::POSTMATCH {
5852             return $';
5853             }
5854              
5855             #
5856             # ShiftJIS character to order (with parameter)
5857 0 0   0 1 0 #
5858             sub Sjis::ord(;$) {
5859 0 0       0  
5860 0         0 local $_ = shift if @_;
5861 0         0  
5862 0         0 if (/\A ($q_char) /oxms) {
5863 0         0 my @ord = unpack 'C*', $1;
5864             my $ord = 0;
5865 0         0 while (my $o = shift @ord) {
5866             $ord = $ord * 0x100 + $o;
5867             }
5868 0         0 return $ord;
5869             }
5870             else {
5871             return CORE::ord $_;
5872             }
5873             }
5874              
5875             #
5876             # ShiftJIS character to order (without parameter)
5877 0 0   0 0 0 #
5878 0         0 sub Sjis::ord_() {
5879 0         0  
5880 0         0 if (/\A ($q_char) /oxms) {
5881 0         0 my @ord = unpack 'C*', $1;
5882             my $ord = 0;
5883 0         0 while (my $o = shift @ord) {
5884             $ord = $ord * 0x100 + $o;
5885             }
5886 0         0 return $ord;
5887             }
5888             else {
5889             return CORE::ord $_;
5890             }
5891             }
5892              
5893             #
5894             # ShiftJIS reverse
5895 0 0   0 0 0 #
5896 0         0 sub Sjis::reverse(@) {
5897              
5898             if (wantarray) {
5899             return CORE::reverse @_;
5900             }
5901             else {
5902              
5903             # One of us once cornered Larry in an elevator and asked him what
5904             # problem he was solving with this, but he looked as far off into
5905 0         0 # the distance as he could in an elevator and said, "It seemed like
5906             # a good idea at the time."
5907              
5908             return join '', CORE::reverse(join('',@_) =~ /\G ($q_char) /oxmsg);
5909             }
5910             }
5911              
5912             #
5913             # ShiftJIS getc (with parameter, without parameter)
5914 0     0 0 0 #
5915 0 0       0 sub Sjis::getc(;*@) {
5916 0 0 0     0  
5917             my($package) = caller;
5918 0         0 my $fh = @_ ? qualify_to_ref(shift,$package) : \*STDIN;
  0         0  
5919 0         0 croak 'Too many arguments for Sjis::getc' if @_ and not wantarray;
5920 0         0  
5921 0         0 my @length = sort { $a <=> $b } keys %range_tr;
5922 0 0       0 my $getc = '';
5923 0 0       0 for my $length ($length[0] .. $length[-1]) {
5924 0 0       0 $getc .= CORE::getc($fh);
5925             if (exists $range_tr{CORE::length($getc)}) {
5926             if ($getc =~ /\A ${Esjis::dot_s} \z/oxms) {
5927             return wantarray ? ($getc,@_) : $getc;
5928 0 0       0 }
5929             }
5930             }
5931             return wantarray ? ($getc,@_) : $getc;
5932             }
5933              
5934             #
5935             # ShiftJIS length by character
5936 0 0   0 1 0 #
5937             sub Sjis::length(;$) {
5938 0         0  
5939 0         0 local $_ = shift if @_;
5940              
5941             local @_ = /\G ($q_char) /oxmsg;
5942             return scalar @_;
5943             }
5944              
5945             #
5946             # ShiftJIS substr by character
5947             #
5948             BEGIN {
5949              
5950             # P.232 The lvalue Attribute
5951             # in Chapter 6: Subroutines
5952             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
5953              
5954             # P.336 The lvalue Attribute
5955             # in Chapter 7: Subroutines
5956             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5957              
5958             # P.144 8.4 Lvalue subroutines
5959 392 50 0 392 1 256333 # in Chapter 8: perlsub: Perl subroutines
  0 0   0   0  
  0 0   0   0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
5960             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
5961              
5962             CORE::eval sprintf(<<'END', ($] >= 5.014000) ? ':lvalue' : '');
5963             # vv----------------------*******
5964             sub Sjis::substr($$;$$) %s {
5965              
5966             my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
5967              
5968             # If the substring is beyond either end of the string, substr() returns the undefined
5969             # value and produces a warning. When used as an lvalue, specifying a substring that
5970             # is entirely outside the string raises an exception.
5971             # http://perldoc.perl.org/functions/substr.html
5972              
5973             # A return with no argument returns the scalar value undef in scalar context,
5974             # an empty list () in list context, and (naturally) nothing at all in void
5975             # context.
5976              
5977             my $offset = $_[1];
5978             if (($offset > scalar(@char)) or ($offset < (-1 * scalar(@char)))) {
5979             return;
5980             }
5981              
5982             # substr($string,$offset,$length,$replacement)
5983             if (@_ == 4) {
5984             my(undef,undef,$length,$replacement) = @_;
5985             my $substr = join '', splice(@char, $offset, $length, $replacement);
5986             $_[0] = join '', @char;
5987              
5988             # return $substr; this doesn't work, don't say "return"
5989             $substr;
5990             }
5991              
5992             # substr($string,$offset,$length)
5993             elsif (@_ == 3) {
5994             my(undef,undef,$length) = @_;
5995             my $octet_offset = 0;
5996             my $octet_length = 0;
5997             if ($offset == 0) {
5998             $octet_offset = 0;
5999             }
6000             elsif ($offset > 0) {
6001             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
6002             $octet_offset = CORE::length(join '', @char[0..$offset-1]);
6003             }
6004             else {
6005             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
6006             $octet_offset = -1 * CORE::length(join '', @char[$#char+$offset+1..$#char]);
6007             }
6008             if ($length == 0) {
6009             $octet_length = 0;
6010             }
6011             elsif ($length > 0) {
6012             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
6013             $octet_length = CORE::length(join '', @char[$offset..$offset+$length-1]);
6014             }
6015             else {
6016             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
6017             $octet_length = -1 * CORE::length(join '', @char[$#char+$length+1..$#char]);
6018             }
6019             CORE::substr($_[0], $octet_offset, $octet_length);
6020             }
6021              
6022             # substr($string,$offset)
6023             else {
6024             my $octet_offset = 0;
6025             if ($offset == 0) {
6026             $octet_offset = 0;
6027             }
6028             elsif ($offset > 0) {
6029             $octet_offset = CORE::length(join '', @char[0..$offset-1]);
6030             }
6031             else {
6032             $octet_offset = -1 * CORE::length(join '', @char[$#char+$offset+1..$#char]);
6033             }
6034             CORE::substr($_[0], $octet_offset);
6035             }
6036             }
6037             END
6038             }
6039              
6040             #
6041             # ShiftJIS index by character
6042 0     0 1 0 #
6043 0 0       0 sub Sjis::index($$;$) {
6044 0         0  
6045             my $index;
6046             if (@_ == 3) {
6047 0         0 $index = Esjis::index($_[0], $_[1], CORE::length(Sjis::substr($_[0], 0, $_[2])));
6048             }
6049             else {
6050 0 0       0 $index = Esjis::index($_[0], $_[1]);
6051 0         0 }
6052              
6053             if ($index == -1) {
6054 0         0 return -1;
6055             }
6056             else {
6057             return Sjis::length(CORE::substr $_[0], 0, $index);
6058             }
6059             }
6060              
6061             #
6062             # ShiftJIS rindex by character
6063 0     0 1 0 #
6064 0 0       0 sub Sjis::rindex($$;$) {
6065 0         0  
6066             my $rindex;
6067             if (@_ == 3) {
6068 0         0 $rindex = Esjis::rindex($_[0], $_[1], CORE::length(Sjis::substr($_[0], 0, $_[2])));
6069             }
6070             else {
6071 0 0       0 $rindex = Esjis::rindex($_[0], $_[1]);
6072 0         0 }
6073              
6074             if ($rindex == -1) {
6075 0         0 return -1;
6076             }
6077             else {
6078             return Sjis::length(CORE::substr $_[0], 0, $rindex);
6079             }
6080             }
6081 392     392   5252  
  392         16242  
  392         42076  
6082             # when 'm//', '/' means regexp match 'm//' and '?' means regexp match '??'
6083             # when 'div', '/' means division operator and '?' means conditional operator (condition ? then : else)
6084             use vars qw($slash); $slash = 'm//';
6085              
6086             # ord() to ord() or Sjis::ord()
6087             my $function_ord = 'ord';
6088              
6089             # ord to ord or Sjis::ord_
6090             my $function_ord_ = 'ord';
6091              
6092             # reverse to reverse or Sjis::reverse
6093             my $function_reverse = 'reverse';
6094              
6095             # getc to getc or Sjis::getc
6096             my $function_getc = 'getc';
6097              
6098             # P.1023 Appendix W.9 Multibyte Anchoring
6099             # of ISBN 1-56592-224-7 CJKV Information Processing
6100              
6101 392     392   4230 my $anchor = '';
  392     0   957  
  392         17725524  
6102             $anchor = q{${Esjis::anchor}};
6103              
6104             use vars qw($nest);
6105              
6106             # regexp of nested parens in qqXX
6107              
6108             # P.340 Matching Nested Constructs with Embedded Code
6109             # in Chapter 7: Perl
6110             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
6111              
6112             my $qq_paren = qr{(?{local $nest=0}) (?>(?:
6113             [^\x81-\x9F\xE0-\xFC\\()] |
6114             \( (?{$nest++}) |
6115             \) (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6116             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6117             \\ [^\x81-\x9F\xE0-\xFCc] |
6118             \\c[\x40-\x5F] |
6119             \\ [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6120             [\x00-\xFF]
6121             }xms;
6122              
6123             my $qq_brace = qr{(?{local $nest=0}) (?>(?:
6124             [^\x81-\x9F\xE0-\xFC\\{}] |
6125             \{ (?{$nest++}) |
6126             \} (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6127             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6128             \\ [^\x81-\x9F\xE0-\xFCc] |
6129             \\c[\x40-\x5F] |
6130             \\ [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6131             [\x00-\xFF]
6132             }xms;
6133              
6134             my $qq_bracket = qr{(?{local $nest=0}) (?>(?:
6135             [^\x81-\x9F\xE0-\xFC\\\[\]] |
6136             \[ (?{$nest++}) |
6137             \] (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6138             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6139             \\ [^\x81-\x9F\xE0-\xFCc] |
6140             \\c[\x40-\x5F] |
6141             \\ [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6142             [\x00-\xFF]
6143             }xms;
6144              
6145             my $qq_angle = qr{(?{local $nest=0}) (?>(?:
6146             [^\x81-\x9F\xE0-\xFC\\<>] |
6147             \< (?{$nest++}) |
6148             \> (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6149             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6150             \\ [^\x81-\x9F\xE0-\xFCc] |
6151             \\c[\x40-\x5F] |
6152             \\ [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6153             [\x00-\xFF]
6154             }xms;
6155              
6156             my $qq_scalar = qr{(?: \{ (?:$qq_brace)*? \} |
6157             (?: ::)? (?:
6158             (?> [a-zA-Z_][a-zA-Z_0-9]* (?: ::[a-zA-Z_][a-zA-Z_0-9]*)* )
6159             (?>(?: \[ (?: \$\[ | \$\] | $qq_char )*? \] | \{ (?:$qq_brace)*? \} )*)
6160             (?>(?: (?: -> )? (?: [\$\@\%\&\*]\* | \$\#\* | [\@\%]? \[ (?: \$\[ | \$\] | $qq_char )*? \] | [\@\%\*]? \{ (?:$qq_brace)*? \} ) )*)
6161             ))
6162             }xms;
6163              
6164             my $qq_variable = qr{(?: \{ (?:$qq_brace)*? \} |
6165             (?: ::)? (?:
6166             (?>[0-9]+) |
6167             [^\x81-\x9F\xE0-\xFCa-zA-Z_0-9\[\]] |
6168             ^[A-Z] |
6169             (?> [a-zA-Z_][a-zA-Z_0-9]* (?: ::[a-zA-Z_][a-zA-Z_0-9]*)* )
6170             (?>(?: \[ (?: \$\[ | \$\] | $qq_char )*? \] | \{ (?:$qq_brace)*? \} )*)
6171             (?>(?: (?: -> )? (?: [\$\@\%\&\*]\* | \$\#\* | [\@\%]? \[ (?: \$\[ | \$\] | $qq_char )*? \] | [\@\%\*]? \{ (?:$qq_brace)*? \} ) )*)
6172             ))
6173             }xms;
6174              
6175             my $qq_substr = qr{(?> Char::substr | Sjis::substr | CORE::substr | substr ) (?>\s*) \( $qq_paren \)
6176             }xms;
6177              
6178             # regexp of nested parens in qXX
6179             my $q_paren = qr{(?{local $nest=0}) (?>(?:
6180             [^\x81-\x9F\xE0-\xFC()] |
6181             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6182             \( (?{$nest++}) |
6183             \) (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6184             [\x00-\xFF]
6185             }xms;
6186              
6187             my $q_brace = qr{(?{local $nest=0}) (?>(?:
6188             [^\x81-\x9F\xE0-\xFC\{\}] |
6189             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6190             \{ (?{$nest++}) |
6191             \} (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6192             [\x00-\xFF]
6193             }xms;
6194              
6195             my $q_bracket = qr{(?{local $nest=0}) (?>(?:
6196             [^\x81-\x9F\xE0-\xFC\[\]] |
6197             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6198             \[ (?{$nest++}) |
6199             \] (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6200             [\x00-\xFF]
6201             }xms;
6202              
6203             my $q_angle = qr{(?{local $nest=0}) (?>(?:
6204             [^\x81-\x9F\xE0-\xFC<>] |
6205             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
6206             \< (?{$nest++}) |
6207             \> (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
6208             [\x00-\xFF]
6209             }xms;
6210              
6211             my $matched = '';
6212             my $s_matched = '';
6213             $matched = q{$Esjis::matched};
6214             $s_matched = q{ Esjis::s_matched();};
6215              
6216             my $tr_variable = ''; # variable of tr///
6217             my $sub_variable = ''; # variable of s///
6218             my $bind_operator = ''; # =~ or !~
6219              
6220             my @heredoc = (); # here document
6221             my @heredoc_delimiter = ();
6222             my $here_script = ''; # here script
6223              
6224             #
6225 0 50   387 0 0 # escape ShiftJIS script
6226             #
6227             sub Sjis::escape(;$) {
6228             local($_) = $_[0] if @_;
6229              
6230             # P.359 The Study Function
6231 387         1449 # in Chapter 7: Perl
6232             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
6233              
6234             study $_; # Yes, I studied study yesterday.
6235              
6236             # while all script
6237              
6238             # 6.14. Matching from Where the Last Pattern Left Off
6239             # in Chapter 6. Pattern Matching
6240             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
6241             # (and so on)
6242              
6243             # one member of Tag-team
6244             #
6245             # P.128 Start of match (or end of previous match): \G
6246             # P.130 Advanced Use of \G with Perl
6247             # in Chapter 3: Overview of Regular Expression Features and Flavors
6248             # P.255 Use leading anchors
6249             # P.256 Expose ^ and \G at the front expressions
6250             # in Chapter 6: Crafting an Efficient Expression
6251             # P.315 "Tag-team" matching with /gc
6252 387         804 # in Chapter 7: Perl
6253 387         732 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
6254 387         1555  
6255             my $e_script = '';
6256             while (not /\G \z/oxgc) { # member
6257 187637         284771 $e_script .= Sjis::escape_token();
6258             }
6259              
6260             return $e_script;
6261             }
6262              
6263             #
6264             # escape ShiftJIS token of script
6265             #
6266             sub Sjis::escape_token {
6267 387     187637 0 7140  
6268             # \n output here document
6269              
6270             my $ignore_modules = join('|', qw(
6271             utf8
6272             bytes
6273             charnames
6274             I18N::Japanese
6275             I18N::Collate
6276             I18N::JExt
6277             File::DosGlob
6278             Wild
6279             Wildcard
6280             Japanese
6281             ));
6282              
6283             # another member of Tag-team
6284             #
6285             # P.315 "Tag-team" matching with /gc
6286 187637 100 100     214478 # in Chapter 7: Perl
    100 100        
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
    100          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    100          
    50          
    100          
    100          
    100          
    100          
    50          
    100          
    100          
    100          
    50          
    100          
    100          
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    100          
    100          
    100          
    50          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    100          
    100          
    50          
    50          
    100          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    100          
    100          
    100          
    50          
6287 187637         14099466 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
6288 31572 100       38352  
6289 31572         54275 if (/\G ( \n ) /oxgc) { # another member (and so on)
6290             my $heredoc = '';
6291 197         301 if (scalar(@heredoc_delimiter) >= 1) {
6292 197         407 $slash = 'm//';
6293              
6294             $heredoc = join '', @heredoc;
6295 197         377 @heredoc = ();
6296 197         394  
6297             # skip here document
6298 205         1310 for my $heredoc_delimiter (@heredoc_delimiter) {
6299             /\G .*? \n $heredoc_delimiter \n/xmsgc;
6300 197         355 }
6301             @heredoc_delimiter = ();
6302 197         294  
6303             $here_script = '';
6304             }
6305             return "\n" . $heredoc;
6306 31572         90293 }
6307              
6308             # ignore space, comment
6309             elsif (/\G ((?>\s+)|\#.*) /oxgc) { return $1; }
6310              
6311             # if (, elsif (, unless (, while (, until (, given (, and when (
6312              
6313             # given, when
6314              
6315             # P.225 The given Statement
6316             # in Chapter 15: Smart Matching and given-when
6317             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
6318              
6319             # P.133 The given Statement
6320             # in Chapter 4: Statements and Declarations
6321 42871         126973 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6322 3797         5774  
6323             elsif (/\G ( (?: if | elsif | unless | while | until | given | when ) (?>\s*) \( ) /oxgc) {
6324             $slash = 'm//';
6325             return $1;
6326             }
6327              
6328             # scalar variable ($scalar = ...) =~ tr///;
6329             # scalar variable ($scalar = ...) =~ s///;
6330              
6331             # state
6332              
6333             # P.68 Persistent, Private Variables
6334             # in Chapter 4: Subroutines
6335             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
6336              
6337             # P.160 Persistent Lexically Scoped Variables: state
6338             # in Chapter 4: Statements and Declarations
6339             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6340              
6341 3797         11455 # (and so on)
6342              
6343 170 50       471 elsif (/\G ( \( (?>\s*) (?: local \b | my \b | our \b | state \b )? (?>\s*) \$ $qq_scalar ) /oxgc) {
    50          
6344 170         6260 my $e_string = e_string($1);
6345 0         0  
6346 0         0 if (/\G ( (?>\s*) = $qq_paren \) ) ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= (?: tr | y ) \b ) /oxgc) {
6347 0         0 $tr_variable = $e_string . e_string($1);
6348             $bind_operator = $2;
6349             $slash = 'm//';
6350 0         0 return '';
6351 0         0 }
6352 0         0 elsif (/\G ( (?>\s*) = $qq_paren \) ) ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= s \b ) /oxgc) {
6353 0         0 $sub_variable = $e_string . e_string($1);
6354             $bind_operator = $2;
6355             $slash = 'm//';
6356 0         0 return '';
6357 170         344 }
6358             else {
6359             $slash = 'div';
6360             return $e_string;
6361             }
6362             }
6363 170         619  
6364 4         8 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Esjis::PREMATCH()
6365             elsif (/\G ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH \b | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) /oxmsgc) {
6366             $slash = 'div';
6367             return q{Esjis::PREMATCH()};
6368             }
6369 4         15  
6370 28         55 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Esjis::MATCH()
6371             elsif (/\G ( \$& | \$\{&\} | \$ (?>\s*) MATCH \b | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) /oxmsgc) {
6372             $slash = 'div';
6373             return q{Esjis::MATCH()};
6374             }
6375 28         85  
6376 1         3 # $', ${'} --> $', ${'}
6377             elsif (/\G ( \$' | \$\{'\} ) /oxmsgc) {
6378             $slash = 'div';
6379             return $1;
6380             }
6381 1         7  
6382 3         25 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Esjis::POSTMATCH()
6383             elsif (/\G ( \$ (?>\s*) POSTMATCH \b | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) /oxmsgc) {
6384             $slash = 'div';
6385             return q{Esjis::POSTMATCH()};
6386             }
6387              
6388             # scalar variable $scalar =~ tr///;
6389             # scalar variable $scalar =~ s///;
6390 3         12 # substr() =~ tr///;
6391             # substr() =~ s///;
6392 2895 100       6588 elsif (/\G ( \$ $qq_scalar | $qq_substr ) /oxgc) {
    100          
6393 2895         11877 my $scalar = e_string($1);
6394 9         15  
6395 9         16 if (/\G ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= (?: tr | y ) \b ) /oxgc) {
6396 9         12 $tr_variable = $scalar;
6397             $bind_operator = $1;
6398             $slash = 'm//';
6399 9         26 return '';
6400 254         424 }
6401 254         451 elsif (/\G ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= s \b ) /oxgc) {
6402 254         339 $sub_variable = $scalar;
6403             $bind_operator = $1;
6404             $slash = 'm//';
6405 254         688 return '';
6406 2632         3841 }
6407             else {
6408             $slash = 'div';
6409             return $scalar;
6410             }
6411             }
6412 2632         7201  
6413             # end of statement
6414             elsif (/\G ( [,;] ) /oxgc) {
6415 12289         17870 $slash = 'm//';
6416              
6417             # clear tr/// variable
6418 12289         14020 $tr_variable = '';
6419              
6420 12289         13441 # clear s/// variable
6421             $sub_variable = '';
6422 12289         13187  
6423             $bind_operator = '';
6424              
6425             return $1;
6426             }
6427 12289         40652  
6428             # bareword
6429             elsif (/\G ( \{ (?>\s*) (?: tr | index | rindex | reverse ) (?>\s*) \} ) /oxmsgc) {
6430             return $1;
6431             }
6432 0         0  
6433 2         4 # $0 --> $0
6434             elsif (/\G ( \$ 0 ) /oxmsgc) {
6435             $slash = 'div';
6436 2         6 return $1;
6437 0         0 }
6438             elsif (/\G ( \$ \{ (?>\s*) 0 (?>\s*) \} ) /oxmsgc) {
6439             $slash = 'div';
6440             return $1;
6441             }
6442 0         0  
6443 1         2 # $$ --> $$
6444             elsif (/\G ( \$ \$ ) (?![\w\{]) /oxmsgc) {
6445             $slash = 'div';
6446             return $1;
6447             }
6448              
6449 1         4 # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
6450 219         375 # $1, $2, $3 --> $1, $2, $3 otherwise
6451             elsif (/\G \$ ((?>[1-9][0-9]*)) /oxmsgc) {
6452             $slash = 'div';
6453 219         548 return e_capture($1);
6454 0         0 }
6455             elsif (/\G \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} /oxmsgc) {
6456             $slash = 'div';
6457             return e_capture($1);
6458             }
6459 0         0  
6460 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
6461             elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ .+? \] ) /oxmsgc) {
6462             $slash = 'div';
6463             return e_capture($1.'->'.$2);
6464             }
6465 0         0  
6466 0         0 # $$foo{ ... } --> $ $foo->{ ... }
6467             elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ .+? \} ) /oxmsgc) {
6468             $slash = 'div';
6469             return e_capture($1.'->'.$2);
6470             }
6471 0         0  
6472 0         0 # $$foo
6473             elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) /oxmsgc) {
6474             $slash = 'div';
6475             return e_capture($1);
6476             }
6477 0         0  
6478 0         0 # ${ foo }
6479             elsif (/\G \$ (?>\s*) \{ ( (?>\s*) (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* ) (?>\s*) ) \} /oxmsgc) {
6480             $slash = 'div';
6481             return '${' . $1 . '}';
6482             }
6483 0         0  
6484 0         0 # ${ ... }
6485             elsif (/\G \$ (?>\s*) \{ (?>\s*) ( $qq_brace ) (?>\s*) \} /oxmsgc) {
6486             $slash = 'div';
6487             return e_capture($1);
6488             }
6489              
6490 0         0 # variable or function
6491 605         921 # $ @ % & * $ #
6492             elsif (/\G ( (?: [\$\@\%\&\*] | \$\# | -> | \b sub \b) (?>\s*) (?: split | chop | index | rindex | lc | uc | fc | chr | ord | reverse | getc | tr | y | q | qq | qx | qw | m | s | qr | glob | lstat | opendir | stat | unlink | chdir ) ) \b /oxmsgc) {
6493             $slash = 'div';
6494             return $1;
6495             }
6496 605         1976 # $ $ $ $ $ $ $ $ $ $ $ $ $ $
6497 103         218 # $ @ # \ ' " / ? ( ) [ ] < >
6498             elsif (/\G ( \$[\$\@\#\\\'\"\/\?\(\)\[\]\<\>] ) /oxmsgc) {
6499             $slash = 'div';
6500             return $1;
6501             }
6502 103         378  
6503             # while ()
6504             elsif (/\G \b (while (?>\s*) \( (?>\s*) <[\$]?[A-Za-z_][A-Za-z_0-9]*> (?>\s*) \)) \b /oxgc) {
6505             return $1;
6506             }
6507              
6508             # while () --- glob
6509              
6510 0         0 # avoid "Error: Runtime exception" of perl version 5.005_03
6511              
6512             elsif (/\G \b while (?>\s*) \( (?>\s*) < ((?:[^\x81-\x9F\xE0-\xFC>\0\a\e\f\n\r\t]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])+?) > (?>\s*) \) \b /oxgc) {
6513             return 'while ($_ = Esjis::glob("' . $1 . '"))';
6514             }
6515 0         0  
6516             # while (glob)
6517             elsif (/\G \b while (?>\s*) \( (?>\s*) glob (?>\s*) \) /oxgc) {
6518             return 'while ($_ = Esjis::glob_)';
6519             }
6520 0         0  
6521             # while (glob(WILDCARD))
6522             elsif (/\G \b while (?>\s*) \( (?>\s*) glob \b /oxgc) {
6523             return 'while ($_ = Esjis::glob';
6524 0         0 }
  484         1221  
6525              
6526             # doit if, doit unless, doit while, doit until, doit for, doit when
6527 484         1848 elsif (/\G \b ( if | unless | while | until | for | when ) \b /oxgc) { $slash = 'm//'; return $1; }
  19         37  
6528 19         74  
  0         0  
6529 0         0 # subroutines of package Esjis
  13         20  
6530 13         33 elsif (/\G \b (CORE:: | ->(>?\s*) (?: atan2 | [a-z]{2,})) \b /oxgc) { $slash = 'm//'; return $1; }
  0         0  
6531 0         0 elsif (/\G \b Char::eval (?= (?>\s*) \{ ) /oxgc) { $slash = 'm//'; return 'eval'; }
  114         200  
6532 114         325 elsif (/\G \b Sjis::eval (?= (?>\s*) \{ ) /oxgc) { $slash = 'm//'; return 'eval'; }
  2         4  
6533 2         8 elsif (/\G \b Char::eval \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'eval Char::escape'; }
  2         4  
6534 2         7 elsif (/\G \b Sjis::eval \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'eval Sjis::escape'; }
  2         4  
6535 2         7 elsif (/\G \b bytes::substr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'substr'; }
  0         0  
6536 0         0 elsif (/\G \b chop \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::chop'; }
  2         4  
6537 2         26 elsif (/\G \b bytes::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'index'; }
  2         4  
6538 2         6 elsif (/\G \b Char::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Char::index'; }
  2         5  
6539 2         7 elsif (/\G \b Sjis::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Sjis::index'; }
  0         0  
6540 0         0 elsif (/\G \b index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::index'; }
  2         13  
6541 2         10 elsif (/\G \b bytes::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'rindex'; }
  2         3  
6542 2         6 elsif (/\G \b Char::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Char::rindex'; }
  1         2  
6543 1         4 elsif (/\G \b Sjis::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Sjis::rindex'; }
  0         0  
6544 0         0 elsif (/\G \b rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::rindex'; }
  0         0  
6545 0         0 elsif (/\G \b lc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::lc'; }
  0         0  
6546 0         0 elsif (/\G \b lcfirst (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::lcfirst'; }
  3         5  
6547             elsif (/\G \b uc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::uc'; }
6548             elsif (/\G \b ucfirst (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::ucfirst'; }
6549             elsif (/\G \b fc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::fc'; }
6550              
6551             # stacked file test operators
6552              
6553             # P.179 File Test Operators
6554             # in Chapter 12: File Tests
6555             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
6556              
6557             # P.106 Named Unary and File Test Operators
6558             # in Chapter 3: Unary and Binary Operators
6559             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6560              
6561 3         10 # (and so on)
  0         0  
6562 0         0  
  0         0  
6563 0         0 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
6564 0         0 (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_qq('', $2,$4,$3) . ")"; }
  0         0  
6565 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6566 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6567 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  1         4  
6568             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
6569             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
6570 1         6 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\S) ((?:$qq_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  5         12  
6571 5         32  
  0         0  
6572 0         0 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
6573 0         0 (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_q ('', $2,$4,$3) . ")"; }
  0         0  
6574 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6575 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6576 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  1         5  
6577             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
6578             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
6579 1         6 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\S) ((?:\\\2|\\\\|$q_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6580 0         0  
  0         0  
6581 0         0 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) (\$ (?> \w+ (?: ::\w+)* ) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
6582 0         0 { $slash = 'm//'; return "Esjis::filetest(qw($1),$2)"; }
  0         0  
6583             elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) \( ((?:$qq_paren)*?) \) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1),$2)"; }
6584 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) (?= [a-z]+) /oxgc) { $slash = 'm//'; return "Esjis::filetest qw($1),"; }
  0         0  
6585 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) ((?>\w+)) /oxgc) { $slash = 'm//'; return "Esjis::filetest(qw($1),$2)"; }
  0         0  
6586 0         0  
  0         0  
6587 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_qq('', $2,$4,$3) . ")"; }
  0         0  
6588 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6589 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6590 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  2         5  
6591             elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
6592 2         9 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  103         165  
6593 103         311 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\S) ((?:$qq_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6594 0         0  
  0         0  
6595 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_q ('', $2,$4,$3) . ")"; }
  0         0  
6596 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6597 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6598 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  2         5  
6599             elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_q ('q', $2,$4,$3) . ")"; }
6600             elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_q ('q', $2,$4,$3) . ")"; }
6601 2         13 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\S) ((?:\\\2|\\\\|$q_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Esjis::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  6         14  
6602 6         32  
  0         0  
6603 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) (\$ (?> \w+ (?: ::\w+)* ) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
6604 0         0 { $slash = 'm//'; return "Esjis::$1($2)"; }
  50         84  
6605 50         238 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) \( ((?:$qq_paren)*?) \) /oxgc) { $slash = 'm//'; return "Esjis::$1($2)"; }
  2         6  
6606 2         11 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?= (?>\s+) [a-z]+) /oxgc) { $slash = 'm//'; return "Esjis::$1"; }
  1         3  
6607 1         4 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) ((?>\w+)) /oxgc) { $slash = 'm//'; return "Esjis::$1(::"."$2)"; }
  3         9  
6608             elsif (/\G -(t) (?>\s+) ((?>\w+)) /oxgc) { $slash = 'm//'; return "-t $2"; }
6609             elsif (/\G \b lstat (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::lstat'; }
6610 3         10 elsif (/\G \b stat (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::stat'; }
  0         0  
6611 0         0  
  0         0  
6612 0         0 # "-s '' ..." means file test "-s 'filename' ..." (not means "- s/// ...")
  0         0  
6613 0         0 elsif (/\G -s (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $slash = 'm//'; return '-s ' . e_qq('', $1,$3,$2); }
  0         0  
6614 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6615 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6616 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6617             elsif (/\G -s (?>\s+) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
6618 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6619 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\S) ((?:$qq_char)+?) (\1) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6620 0         0  
  0         0  
6621 0         0 elsif (/\G -s (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $slash = 'm//'; return '-s ' . e_q ('', $1,$3,$2); }
  0         0  
6622 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6623 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6624 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6625             elsif (/\G -s (?>\s+) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
6626             elsif (/\G -s (?>\s+) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
6627 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\S) ((?:\\\1|\\\\|$q_char)+?) (\1) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6628 0         0  
  0         0  
6629 0         0 elsif (/\G -s (?>\s*) (\$ (?> \w+ (?: ::\w+)* ) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
6630 0         0 { $slash = 'm//'; return "-s $1"; }
  0         0  
6631             elsif (/\G -s (?>\s*) \( ((?:$qq_paren)*?) \) /oxgc) { $slash = 'm//'; return "-s ($1)"; }
6632 0         0 elsif (/\G -s (?= (?>\s+) [a-z]+) /oxgc) { $slash = 'm//'; return '-s'; }
  2         6  
6633 2         7 elsif (/\G -s (?>\s+) ((?>\w+)) /oxgc) { $slash = 'm//'; return "-s $1"; }
  2         5  
6634 2         7  
  36         95  
6635 36         136 elsif (/\G \b bytes::length (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'length'; }
  2         4  
6636 2         8 elsif (/\G \b bytes::chr (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'chr'; }
  2         7  
6637 2         9 elsif (/\G \b chr (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::chr'; }
  8         22  
6638 8         46 elsif (/\G \b bytes::ord (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'div'; return 'ord'; }
  0         0  
6639 0         0 elsif (/\G \b ord (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'div'; return $function_ord; }
  0         0  
6640 0         0 elsif (/\G \b glob (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Esjis::glob'; }
  0         0  
6641 0         0 elsif (/\G \b lc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::lc_'; }
  0         0  
6642 0         0 elsif (/\G \b lcfirst \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::lcfirst_'; }
  0         0  
6643 0         0 elsif (/\G \b uc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::uc_'; }
  0         0  
6644 0         0 elsif (/\G \b ucfirst \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::ucfirst_'; }
  0         0  
6645             elsif (/\G \b fc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::fc_'; }
6646 0         0 elsif (/\G \b lstat \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::lstat_'; }
  0         0  
6647             elsif (/\G \b stat \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::stat_'; }
6648 0         0 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
6649             \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return "Esjis::filetest_(qw($1))"; }
6650 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC])
  0         0  
6651             \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return "Esjis::${1}_"; }
6652 0         0  
  0         0  
6653 0         0 elsif (/\G -s \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return '-s '; }
  0         0  
6654 0         0  
  0         0  
6655 0         0 elsif (/\G \b bytes::length \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'length'; }
  0         0  
6656 0         0 elsif (/\G \b bytes::chr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'chr'; }
  2         8  
6657 2         8 elsif (/\G \b chr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::chr_'; }
  0         0  
6658 0         0 elsif (/\G \b bytes::ord \b (?! (?>\s*) => ) /oxgc) { $slash = 'div'; return 'ord'; }
  4         9  
6659 4         17 elsif (/\G \b ord \b (?! (?>\s*) => ) /oxgc) { $slash = 'div'; return $function_ord_; }
  8         25  
6660 8         35 elsif (/\G \b glob \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::glob_'; }
  2         9  
6661 2         15 elsif (/\G \b reverse \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return $function_reverse; }
  0         0  
6662 0         0 elsif (/\G \b getc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return $function_getc; }
  87         228  
6663             elsif (/\G \b opendir ((?>\s*) \( (?>\s*)) (?=[A-Za-z_]) /oxgc) { $slash = 'm//'; return "Esjis::opendir$1*"; }
6664             elsif (/\G \b opendir ((?>\s+)) (?=[A-Za-z_]) /oxgc) { $slash = 'm//'; return "Esjis::opendir$1*"; }
6665             elsif (/\G \b unlink \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Esjis::unlink'; }
6666 87         360  
6667             # chdir
6668 3         6 elsif (/\G \b (chdir) \b (?! (?>\s*) => ) /oxgc) {
6669             $slash = 'm//';
6670 3         4  
6671 3         11 my $e = 'Esjis::chdir';
6672              
6673             while (/\G ( (?>\s+) | \( | \#.* ) /oxgc) {
6674             $e .= $1;
6675 3 50       11 }
  3 100       236  
    50          
    50          
    50          
    0          
6676              
6677             # end of chdir
6678 0         0 if (/\G (?= [,;\)\}\]] ) /oxgc) { return $e; }
6679              
6680             # chdir scalar value
6681             elsif (/\G ( [\$\@\&\*] $qq_scalar ) /oxgc) { return $e . e_string($1); }
6682 1 0       3  
  0         0  
6683             # chdir qq//
6684 0         0 elsif (/\G \b (qq) \b /oxgc) {
6685 0 0       0 if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq# # --> qr # #
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6686 0         0 else {
6687 0         0 while (not /\G \z/oxgc) {
6688 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6689 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq ( ) --> qr ( )
6690 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq { } --> qr { }
6691 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq [ ] --> qr [ ]
6692             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq < > --> qr < >
6693 0         0 elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_chdir('qq','{','}',$2); } # qq | | --> qr { }
6694             elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq * * --> qr * *
6695             }
6696             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6697             }
6698             }
6699 0 0       0  
  0         0  
6700             # chdir q//
6701 0         0 elsif (/\G \b (q) \b /oxgc) {
6702 0 0       0 if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q# # --> qr # #
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6703 0         0 else {
6704 0         0 while (not /\G \z/oxgc) {
6705 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6706 0         0 elsif (/\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q ( ) --> qr ( )
6707 0         0 elsif (/\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q { } --> qr { }
6708 0         0 elsif (/\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q [ ] --> qr [ ]
6709             elsif (/\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q < > --> qr < >
6710 0         0 elsif (/\G ([*\-:?\\^|]) ((?:$q_char)*?) (\1) /oxgc) { return $e . e_chdir_q('q','{','}',$2); } # q | | --> qr { }
6711             elsif (/\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q * * --> qr * *
6712             }
6713             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6714             }
6715             }
6716 0         0  
6717 2         5 # chdir ''
6718 2 50       7 elsif (/\G (\') /oxgc) {
  13 50       58  
    100          
    50          
6719 0         0 my $q_string = '';
6720 0         0 while (not /\G \z/oxgc) {
6721 2         12 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6722             elsif (/\G (\\\') /oxgc) { $q_string .= $1; }
6723 11         23 elsif (/\G \' /oxgc) { return $e . e_chdir_q('',"'","'",$q_string); }
6724             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6725             }
6726             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6727             }
6728 0         0  
6729 0         0 # chdir ""
6730 0 0       0 elsif (/\G (\") /oxgc) {
  0 0       0  
    0          
    0          
6731 0         0 my $qq_string = '';
6732 0         0 while (not /\G \z/oxgc) {
6733 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6734             elsif (/\G (\\\") /oxgc) { $qq_string .= $1; }
6735 0         0 elsif (/\G \" /oxgc) { return $e . e_chdir('','"','"',$qq_string); }
6736             elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
6737             }
6738             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6739             }
6740             }
6741 0         0  
6742             # split
6743 404         895 elsif (/\G \b (split) \b (?! (?>\s*) => ) /oxgc) {
6744 404         626 $slash = 'm//';
6745 404         1398  
6746             my $e = '';
6747             while (/\G ( (?>\s+) | \( | \#.* ) /oxgc) {
6748             $e .= $1;
6749 401 100       1515 }
  404 100       17438  
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    100          
    50          
    100          
    50          
    50          
    50          
6750              
6751             # end of split
6752 3         14 if (/\G (?= [,;\)\}\]] ) /oxgc) { return 'Esjis::split' . $e; }
6753              
6754             # split scalar value
6755 1         4 elsif (/\G ( [\$\@\&\*] $qq_scalar ) /oxgc) { return 'Esjis::split' . $e . e_string($1); }
6756 0         0  
6757 0         0 # split literal space
6758 0         0 elsif (/\G \b qq (\#) [ ] (\#) /oxgc) { return 'Esjis::split' . $e . qq {qq$1 $2}; }
6759 0         0 elsif (/\G \b qq ((?>\s*)) (\() [ ] (\)) /oxgc) { return 'Esjis::split' . $e . qq{$1qq$2 $3}; }
6760 0         0 elsif (/\G \b qq ((?>\s*)) (\{) [ ] (\}) /oxgc) { return 'Esjis::split' . $e . qq{$1qq$2 $3}; }
6761 0         0 elsif (/\G \b qq ((?>\s*)) (\[) [ ] (\]) /oxgc) { return 'Esjis::split' . $e . qq{$1qq$2 $3}; }
6762 0         0 elsif (/\G \b qq ((?>\s*)) (\<) [ ] (\>) /oxgc) { return 'Esjis::split' . $e . qq{$1qq$2 $3}; }
6763 0         0 elsif (/\G \b qq ((?>\s*)) (\S) [ ] (\2) /oxgc) { return 'Esjis::split' . $e . qq{$1qq$2 $3}; }
6764 0         0 elsif (/\G \b q (\#) [ ] (\#) /oxgc) { return 'Esjis::split' . $e . qq {q$1 $2}; }
6765 0         0 elsif (/\G \b q ((?>\s*)) (\() [ ] (\)) /oxgc) { return 'Esjis::split' . $e . qq {$1q$2 $3}; }
6766 0         0 elsif (/\G \b q ((?>\s*)) (\{) [ ] (\}) /oxgc) { return 'Esjis::split' . $e . qq {$1q$2 $3}; }
6767 0         0 elsif (/\G \b q ((?>\s*)) (\[) [ ] (\]) /oxgc) { return 'Esjis::split' . $e . qq {$1q$2 $3}; }
6768 13         63 elsif (/\G \b q ((?>\s*)) (\<) [ ] (\>) /oxgc) { return 'Esjis::split' . $e . qq {$1q$2 $3}; }
6769             elsif (/\G \b q ((?>\s*)) (\S) [ ] (\2) /oxgc) { return 'Esjis::split' . $e . qq {$1q$2 $3}; }
6770             elsif (/\G ' [ ] ' /oxgc) { return 'Esjis::split' . $e . qq {' '}; }
6771             elsif (/\G " [ ] " /oxgc) { return 'Esjis::split' . $e . qq {" "}; }
6772 2 0       11  
  0         0  
6773             # split qq//
6774 0         0 elsif (/\G \b (qq) \b /oxgc) {
6775 0 0       0 if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq# # --> qr # #
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6776 0         0 else {
6777 0         0 while (not /\G \z/oxgc) {
6778 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6779 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq ( ) --> qr ( )
6780 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq { } --> qr { }
6781 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq [ ] --> qr [ ]
6782             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq < > --> qr < >
6783 0         0 elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) /oxgc) { return e_split($e.'qr','{','}',$2,''); } # qq | | --> qr { }
6784             elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq * * --> qr * *
6785             }
6786             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6787             }
6788             }
6789 0 50       0  
  124         914  
6790             # split qr//
6791 0         0 elsif (/\G \b (qr) \b /oxgc) {
6792 124 50       394 if (/\G (\#) ((?:$qq_char)*?) (\#) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1,$3,$2,$4); } # qr# #
  124 50       6288  
    50          
    50          
    50          
    100          
    50          
    50          
6793 0         0 else {
6794 0         0 while (not /\G \z/oxgc) {
6795 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6796 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr ( )
6797 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr { }
6798 56         294 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr [ ]
6799 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr < >
6800             elsif (/\G (\') ((?:$qq_char)*?) (\') ([imosxpadlunbB]*) /oxgc) { return e_split_q($e.'qr',$1, $3, $2,$4); } # qr ' '
6801 68         352 elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr','{','}',$2,$4); } # qr | | --> qr { }
6802             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr * *
6803             }
6804             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6805             }
6806             }
6807 0 0       0  
  0         0  
6808             # split q//
6809 0         0 elsif (/\G \b (q) \b /oxgc) {
6810 0 0       0 if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q# # --> qr # #
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6811 0         0 else {
6812 0         0 while (not /\G \z/oxgc) {
6813 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6814 0         0 elsif (/\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q ( ) --> qr ( )
6815 0         0 elsif (/\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q { } --> qr { }
6816 0         0 elsif (/\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q [ ] --> qr [ ]
6817             elsif (/\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q < > --> qr < >
6818 0         0 elsif (/\G ([*\-:?\\^|]) ((?:$q_char)*?) (\1) /oxgc) { return e_split_q($e.'qr','{','}',$2,''); } # q | | --> qr { }
6819             elsif (/\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q * * --> qr * *
6820             }
6821             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6822             }
6823             }
6824 0 50       0  
  136         944  
6825             # split m//
6826 0         0 elsif (/\G \b (m) \b /oxgc) {
6827 136 50       361 if (/\G (\#) ((?:$qq_char)*?) (\#) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1,$3,$2,$4); } # m# # --> qr # #
  136 50       6572  
    50          
    50          
    50          
    100          
    50          
    50          
6828 0         0 else {
6829 0         0 while (not /\G \z/oxgc) {
6830 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6831 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m ( ) --> qr ( )
6832 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m { } --> qr { }
6833 56         250 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m [ ] --> qr [ ]
6834 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m < > --> qr < >
6835             elsif (/\G (\') ((?:$qq_char)*?) (\') ([cgimosxpadlunbB]*) /oxgc) { return e_split_q($e.'qr',$1, $3, $2,$4); } # m ' ' --> qr ' '
6836 80         372 elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr','{','}',$2,$4); } # m | | --> qr { }
6837             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m * * --> qr * *
6838             }
6839             die __FILE__, ": Search pattern not terminated\n";
6840             }
6841             }
6842 0         0  
6843 0         0 # split ''
6844 0 0       0 elsif (/\G (\') /oxgc) {
  0 0       0  
    0          
    0          
6845 0         0 my $q_string = '';
6846 0         0 while (not /\G \z/oxgc) {
6847 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6848             elsif (/\G (\\\') /oxgc) { $q_string .= $1; } # splitqr'' --> split qr''
6849 0         0 elsif (/\G \' /oxgc) { return e_split_q($e.q{ qr},"'","'",$q_string,''); } # ' ' --> qr ' '
6850             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6851             }
6852             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6853             }
6854 0         0  
6855 0         0 # split ""
6856 0 0       0 elsif (/\G (\") /oxgc) {
  0 0       0  
    0          
    0          
6857 0         0 my $qq_string = '';
6858 0         0 while (not /\G \z/oxgc) {
6859 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6860             elsif (/\G (\\\") /oxgc) { $qq_string .= $1; } # splitqr"" --> split qr""
6861 0         0 elsif (/\G \" /oxgc) { return e_split($e.q{ qr},'"','"',$qq_string,''); } # " " --> qr " "
6862             elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
6863             }
6864             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6865             }
6866 0         0  
6867 125         240 # split //
6868 125 50       353 elsif (/\G (\/) /oxgc) {
  558 50       2715  
    100          
    50          
6869 0         0 my $regexp = '';
6870 0         0 while (not /\G \z/oxgc) {
6871 125         485 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
6872             elsif (/\G (\\\/) /oxgc) { $regexp .= $1; } # splitqr// --> split qr//
6873 433         904 elsif (/\G \/ ([cgimosxpadlunbB]*) /oxgc) { return e_split($e.q{ qr}, '/','/',$regexp,$1); } # / / --> qr / /
6874             elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
6875             }
6876             die __FILE__, ": Search pattern not terminated\n";
6877             }
6878             }
6879              
6880             # tr/// or y///
6881              
6882             # about [cdsrbB]* (/B modifier)
6883             #
6884             # P.559 appendix C
6885             # of ISBN 4-89052-384-7 Programming perl
6886 0         0 # (Japanese title is: Perl puroguramingu)
6887              
6888             elsif (/\G \b ( tr | y ) \b /oxgc) {
6889 11 50       30 my $ope = $1;
6890 11         167  
6891 0         0 # $1 $2 $3 $4 $5 $6
6892             if (/\G (\#) ((?:$qq_char)*?) (\#) ((?:$qq_char)*?) (\#) ([cdsrbB]*) /oxgc) { # tr# # #
6893             my @tr = ($tr_variable,$2);
6894 0         0 return e_tr(@tr,'',$4,$6);
6895 11         22 }
6896 11 50       33 else {
  11 50       769  
    50          
    50          
    50          
    50          
6897             my $e = '';
6898 0         0 while (not /\G \z/oxgc) {
6899 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6900 0 0       0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
6901 0         0 my @tr = ($tr_variable,$2);
6902 0         0 while (not /\G \z/oxgc) {
6903 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6904 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) ( )
6905 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) { }
6906             elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) [ ]
6907 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) < >
6908             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) * *
6909             }
6910 0         0 die __FILE__, ": Transliteration replacement not terminated\n";
6911 0         0 }
6912 0 0       0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
6913 0         0 my @tr = ($tr_variable,$2);
6914 0         0 while (not /\G \z/oxgc) {
6915 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6916 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } ( )
6917 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } { }
6918             elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } [ ]
6919 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } < >
6920             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } * *
6921             }
6922 0         0 die __FILE__, ": Transliteration replacement not terminated\n";
6923 0         0 }
6924 0 0       0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
6925 0         0 my @tr = ($tr_variable,$2);
6926 0         0 while (not /\G \z/oxgc) {
6927 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6928 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] ( )
6929 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] { }
6930             elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] [ ]
6931 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] < >
6932             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] * *
6933             }
6934 0         0 die __FILE__, ": Transliteration replacement not terminated\n";
6935 0         0 }
6936 0 0       0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
6937 0         0 my @tr = ($tr_variable,$2);
6938 0         0 while (not /\G \z/oxgc) {
6939 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6940 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > ( )
6941 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > { }
6942             elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > [ ]
6943 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > < >
6944             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > * *
6945             }
6946             die __FILE__, ": Transliteration replacement not terminated\n";
6947 0         0 }
6948 11         70 # $1 $2 $3 $4 $5 $6
6949             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { # tr * * *
6950             my @tr = ($tr_variable,$2);
6951 11         36 return e_tr(@tr,'',$4,$6);
6952             }
6953             }
6954             die __FILE__, ": Transliteration pattern not terminated\n";
6955             }
6956             }
6957 0         0  
6958             # qq//
6959             elsif (/\G \b (qq) \b /oxgc) {
6960 5900 100       15777 my $ope = $1;
6961 5900         11117  
6962 40         52 # if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return e_qq($ope,$1,$3,$2); } # qq# #
6963 40 100       80 if (/\G (\#) /oxgc) { # qq# #
  1948 50       5169  
    100          
    50          
6964 80         151 my $qq_string = '';
6965 0         0 while (not /\G \z/oxgc) {
6966 40         92 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6967             elsif (/\G (\\\#) /oxgc) { $qq_string .= $1; }
6968 1828         3504 elsif (/\G (\#) /oxgc) { return e_qq($ope,'#','#',$qq_string); }
6969             elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6970             }
6971             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6972 0         0 }
6973 5860         7639  
6974 5860 50       13621 else {
  5860 50       21860  
    100          
    50          
    100          
    50          
6975             my $e = '';
6976             while (not /\G \z/oxgc) {
6977             if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6978 0         0  
6979 0         0 # elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq ( )
6980 0         0 elsif (/\G (\() /oxgc) { # qq ( )
6981 0 0       0 my $qq_string = '';
  0 0       0  
    0          
    0          
    0          
6982 0         0 local $nest = 1;
6983 0         0 while (not /\G \z/oxgc) {
  0         0  
6984             if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6985 0 0       0 elsif (/\G (\\\)) /oxgc) { $qq_string .= $1; }
  0         0  
6986 0         0 elsif (/\G (\() /oxgc) { $qq_string .= $1; $nest++; }
6987             elsif (/\G (\)) /oxgc) {
6988 0         0 if (--$nest == 0) { return $e . e_qq($ope,'(',')',$qq_string); }
6989             else { $qq_string .= $1; }
6990 0         0 }
6991             elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6992             }
6993             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6994             }
6995 0         0  
6996 5778         7613 # elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq { }
6997 5778         7902 elsif (/\G (\{) /oxgc) { # qq { }
6998 5778 100       11771 my $qq_string = '';
  246074 50       743944  
    100          
    100          
    50          
6999 720         1606 local $nest = 1;
7000 0         0 while (not /\G \z/oxgc) {
  1384         2049  
7001             if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
7002 1384 100       2372 elsif (/\G (\\\}) /oxgc) { $qq_string .= $1; }
  7162         11023  
7003 5778         12085 elsif (/\G (\{) /oxgc) { $qq_string .= $1; $nest++; }
7004             elsif (/\G (\}) /oxgc) {
7005 1384         2763 if (--$nest == 0) { return $e . e_qq($ope,'{','}',$qq_string); }
7006             else { $qq_string .= $1; }
7007 236808         444741 }
7008             elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
7009             }
7010             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7011             }
7012 0         0  
7013 0         0 # elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq [ ]
7014 0         0 elsif (/\G (\[) /oxgc) { # qq [ ]
7015 0 0       0 my $qq_string = '';
  0 0       0  
    0          
    0          
    0          
7016 0         0 local $nest = 1;
7017 0         0 while (not /\G \z/oxgc) {
  0         0  
7018             if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
7019 0 0       0 elsif (/\G (\\\]) /oxgc) { $qq_string .= $1; }
  0         0  
7020 0         0 elsif (/\G (\[) /oxgc) { $qq_string .= $1; $nest++; }
7021             elsif (/\G (\]) /oxgc) {
7022 0         0 if (--$nest == 0) { return $e . e_qq($ope,'[',']',$qq_string); }
7023             else { $qq_string .= $1; }
7024 0         0 }
7025             elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
7026             }
7027             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7028             }
7029 0         0  
7030 62         103 # elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq < >
7031 62         105 elsif (/\G (\<) /oxgc) { # qq < >
7032 62 100       180 my $qq_string = '';
  2040 50       7446  
    100          
    100          
    50          
7033 22         53 local $nest = 1;
7034 0         0 while (not /\G \z/oxgc) {
  2         3  
7035             if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
7036 2 100       5 elsif (/\G (\\\>) /oxgc) { $qq_string .= $1; }
  64         145  
7037 62         167 elsif (/\G (\<) /oxgc) { $qq_string .= $1; $nest++; }
7038             elsif (/\G (\>) /oxgc) {
7039 2         5 if (--$nest == 0) { return $e . e_qq($ope,'<','>',$qq_string); }
7040             else { $qq_string .= $1; }
7041 1952         3885 }
7042             elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
7043             }
7044             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7045             }
7046 0         0  
7047 20         37 # elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq * *
7048 20         21 elsif (/\G (\S) /oxgc) { # qq * *
7049 20 50       40 my $delimiter = $1;
  840 50       2346  
    100          
    50          
7050 0         0 my $qq_string = '';
7051 0         0 while (not /\G \z/oxgc) {
7052 20         42 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
7053             elsif (/\G (\\\Q$delimiter\E) /oxgc) { $qq_string .= $1; }
7054 820         1456 elsif (/\G (\Q$delimiter\E) /oxgc) { return $e . e_qq($ope,$delimiter,$delimiter,$qq_string); }
7055             elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
7056             }
7057 0         0 die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7058             }
7059             }
7060             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7061             }
7062             }
7063 0         0  
7064 184 50       485 # qr//
7065 184         768 elsif (/\G \b (qr) \b /oxgc) {
7066             my $ope = $1;
7067             if (/\G (\#) ((?:$qq_char)*?) (\#) ([imosxpadlunbB]*) /oxgc) { # qr# # #
7068 0         0 return e_qr($ope,$1,$3,$2,$4);
7069 184         249 }
7070 184 50       466 else {
  184 50       4759  
    100          
    50          
    50          
    100          
    50          
    50          
7071 0         0 my $e = '';
7072 0         0 while (not /\G \z/oxgc) {
7073 1         6 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7074 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr ( )
7075 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr { }
7076 76         231 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr [ ]
7077 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr < >
7078             elsif (/\G (\') ((?:$qq_char)*?) (\') ([imosxpadlunbB]*) /oxgc) { return $e . e_qr_q($ope,$1, $3, $2,$4); } # qr ' '
7079 107         311 elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,'{','}',$2,$4); } # qr | | --> qr { }
7080             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr * *
7081             }
7082             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7083             }
7084             }
7085 0         0  
7086 34 50       105 # qw//
7087 34         112 elsif (/\G \b (qw) \b /oxgc) {
7088             my $ope = $1;
7089             if (/\G (\#) (.*?) (\#) /oxmsgc) { # qw# #
7090 0         0 return e_qw($ope,$1,$3,$2);
7091 34         65 }
7092 34 50       116 else {
  34 50       249  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
7093             my $e = '';
7094 0         0 while (not /\G \z/oxgc) {
7095 34         184 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7096              
7097 0         0 elsif (/\G (\() ([^(]*?) (\)) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw ( )
7098 0         0 elsif (/\G (\() ((?:$q_paren)*?) (\)) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw ( )
7099              
7100 0         0 elsif (/\G (\{) ([^{]*?) (\}) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw { }
7101 0         0 elsif (/\G (\{) ((?:$q_brace)*?) (\}) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw { }
7102              
7103 0         0 elsif (/\G (\[) ([^[]*?) (\]) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw [ ]
7104 0         0 elsif (/\G (\[) ((?:$q_bracket)*?) (\]) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw [ ]
7105              
7106 0         0 elsif (/\G (\<) ([^<]*?) (\>) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw < >
7107 0         0 elsif (/\G (\<) ((?:$q_angle)*?) (\>) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw < >
7108              
7109 0         0 elsif (/\G ([\x21-\x3F]) (.*?) (\1) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw * *
7110             elsif (/\G (\S) ((?:$q_char)*?) (\1) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw * *
7111             }
7112             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7113             }
7114             }
7115 0         0  
7116 3 50       10 # qx//
7117 3         76 elsif (/\G \b (qx) \b /oxgc) {
7118             my $ope = $1;
7119             if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qx# #
7120 0         0 return e_qq($ope,$1,$3,$2);
7121 3         8 }
7122 3 50       11 else {
  3 50       439  
    100          
    50          
    50          
    50          
    50          
7123 0         0 my $e = '';
7124 0         0 while (not /\G \z/oxgc) {
7125 2         6 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7126 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx ( )
7127 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx { }
7128 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx [ ]
7129             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx < >
7130 1         6 elsif (/\G (\') ((?:$qq_char)*?) (\') /oxgc) { return $e . e_q ($ope,$1,$3,$2); } # qx ' '
7131             elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx * *
7132             }
7133             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7134             }
7135             }
7136 0         0  
7137             # q//
7138             elsif (/\G \b (q) \b /oxgc) {
7139             my $ope = $1;
7140              
7141             # if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return e_q($ope,$1,$3,$2); } # q# #
7142              
7143 607 50       2095 # avoid "Error: Runtime exception" of perl version 5.005_03
7144 607         1903 # (and so on)
7145 0         0  
7146 0 0       0 if (/\G (\#) /oxgc) { # q# #
  0 0       0  
    0          
    0          
7147 0         0 my $q_string = '';
7148 0         0 while (not /\G \z/oxgc) {
7149 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
7150             elsif (/\G (\\\#) /oxgc) { $q_string .= $1; }
7151 0         0 elsif (/\G (\#) /oxgc) { return e_q($ope,'#','#',$q_string); }
7152             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7153             }
7154             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7155 0         0 }
7156 607         1232  
7157 607 50       2145 else {
  607 100       3785  
    100          
    50          
    100          
    50          
7158             my $e = '';
7159             while (not /\G \z/oxgc) {
7160             if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7161 0         0  
7162 1         2 # elsif (/\G (\() ((?:\\\)|\\\\|$q_paren)*?) (\)) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q ( )
7163 1         2 elsif (/\G (\() /oxgc) { # q ( )
7164 1 50       4 my $q_string = '';
  7 50       50  
    50          
    50          
    100          
    50          
7165 0         0 local $nest = 1;
7166 0         0 while (not /\G \z/oxgc) {
7167 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
  0         0  
7168             elsif (/\G (\\\)) /oxgc) { $q_string .= $1; }
7169 0 50       0 elsif (/\G (\\\() /oxgc) { $q_string .= $1; }
  1         3  
7170 1         2 elsif (/\G (\() /oxgc) { $q_string .= $1; $nest++; }
7171             elsif (/\G (\)) /oxgc) {
7172 0         0 if (--$nest == 0) { return $e . e_q($ope,'(',')',$q_string); }
7173             else { $q_string .= $1; }
7174 6         15 }
7175             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7176             }
7177             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7178             }
7179 0         0  
7180 600         1155 # elsif (/\G (\{) ((?:\\\}|\\\\|$q_brace)*?) (\}) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q { }
7181 600         1155 elsif (/\G (\{) /oxgc) { # q { }
7182 600 50       1849 my $q_string = '';
  8204 50       38540  
    50          
    100          
    100          
    50          
7183 0         0 local $nest = 1;
7184 0         0 while (not /\G \z/oxgc) {
7185 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
  114         201  
7186             elsif (/\G (\\\}) /oxgc) { $q_string .= $1; }
7187 114 100       228 elsif (/\G (\\\{) /oxgc) { $q_string .= $1; }
  714         1677  
7188 600         2064 elsif (/\G (\{) /oxgc) { $q_string .= $1; $nest++; }
7189             elsif (/\G (\}) /oxgc) {
7190 114         250 if (--$nest == 0) { return $e . e_q($ope,'{','}',$q_string); }
7191             else { $q_string .= $1; }
7192 7376         16249 }
7193             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7194             }
7195             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7196             }
7197 0         0  
7198 0         0 # elsif (/\G (\[) ((?:\\\]|\\\\|$q_bracket)*?) (\]) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q [ ]
7199 0         0 elsif (/\G (\[) /oxgc) { # q [ ]
7200 0 0       0 my $q_string = '';
  0 0       0  
    0          
    0          
    0          
    0          
7201 0         0 local $nest = 1;
7202 0         0 while (not /\G \z/oxgc) {
7203 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
  0         0  
7204             elsif (/\G (\\\]) /oxgc) { $q_string .= $1; }
7205 0 0       0 elsif (/\G (\\\[) /oxgc) { $q_string .= $1; }
  0         0  
7206 0         0 elsif (/\G (\[) /oxgc) { $q_string .= $1; $nest++; }
7207             elsif (/\G (\]) /oxgc) {
7208 0         0 if (--$nest == 0) { return $e . e_q($ope,'[',']',$q_string); }
7209             else { $q_string .= $1; }
7210 0         0 }
7211             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7212             }
7213             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7214             }
7215 0         0  
7216 5         12 # elsif (/\G (\<) ((?:\\\>|\\\\|$q_angle)*?) (\>) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q < >
7217 5         13 elsif (/\G (\<) /oxgc) { # q < >
7218 5 50       19 my $q_string = '';
  82 50       816  
    50          
    50          
    100          
    50          
7219 0         0 local $nest = 1;
7220 0         0 while (not /\G \z/oxgc) {
7221 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
  0         0  
7222             elsif (/\G (\\\>) /oxgc) { $q_string .= $1; }
7223 0 50       0 elsif (/\G (\\\<) /oxgc) { $q_string .= $1; }
  5         18  
7224 5         20 elsif (/\G (\<) /oxgc) { $q_string .= $1; $nest++; }
7225             elsif (/\G (\>) /oxgc) {
7226 0         0 if (--$nest == 0) { return $e . e_q($ope,'<','>',$q_string); }
7227             else { $q_string .= $1; }
7228 77         174 }
7229             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7230             }
7231             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7232             }
7233 0         0  
7234 1         3 # elsif (/\G (\S) ((?:\\\1|\\\\|$q_char)*?) (\1) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q * *
7235 1         3 elsif (/\G (\S) /oxgc) { # q * *
7236 1 50       10 my $delimiter = $1;
  14 50       83  
    100          
    50          
7237 0         0 my $q_string = '';
7238 0         0 while (not /\G \z/oxgc) {
7239 1         4 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
7240             elsif (/\G (\\\Q$delimiter\E) /oxgc) { $q_string .= $1; }
7241 13         55 elsif (/\G (\Q$delimiter\E) /oxgc) { return $e . e_q($ope,$delimiter,$delimiter,$q_string); }
7242             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7243             }
7244 0         0 die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7245             }
7246             }
7247             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7248             }
7249             }
7250 0         0  
7251 491 50       1438 # m//
7252 491         2815 elsif (/\G \b (m) \b /oxgc) {
7253             my $ope = $1;
7254             if (/\G (\#) ((?:$qq_char)*?) (\#) ([cgimosxpadlunbB]*) /oxgc) { # m# #
7255 0         0 return e_qr($ope,$1,$3,$2,$4);
7256 491         730 }
7257 491 50       1417 else {
  491 50       20636  
    50          
    50          
    50          
    100          
    100          
    50          
    50          
7258 0         0 my $e = '';
7259 0         0 while (not /\G \z/oxgc) {
7260 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7261 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m ( )
7262 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m { }
7263 92         262 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m [ ]
7264 87         300 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m < >
7265 0         0 elsif (/\G (\?) ((?:$qq_char)*?) (\?) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m ? ?
7266             elsif (/\G (\') ((?:$qq_char)*?) (\') ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr_q($ope,$1, $3, $2,$4); } # m ' '
7267 312         1052 elsif (/\G ([*\-:\\^|]) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,'{','}',$2,$4); } # m | | --> m { }
7268             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m * *
7269             }
7270             die __FILE__, ": Search pattern not terminated\n";
7271             }
7272             }
7273              
7274             # s///
7275              
7276             # about [cegimosxpradlunbB]* (/cg modifier)
7277             #
7278             # P.67 Pattern-Matching Operators
7279 0         0 # of ISBN 0-596-00241-6 Perl in a Nutshell, Second Edition.
7280              
7281             elsif (/\G \b (s) \b /oxgc) {
7282 291 100       873 my $ope = $1;
7283 291         4086  
7284             # $1 $2 $3 $4 $5 $6
7285             if (/\G (\#) ((?:$qq_char)*?) (\#) ((?:$qq_char)*?) (\#) ([cegimosxpradlunbB]*) /oxgc) { # s# # #
7286 1         5 return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
7287 290         515 }
7288 290 50       841 else {
  290 50       28456  
    50          
    50          
    50          
    100          
    100          
    50          
    50          
7289             my $e = '';
7290 0         0 while (not /\G \z/oxgc) {
7291 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7292 0 0       0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
7293             my @s = ($1,$2,$3);
7294 0         0 while (not /\G \z/oxgc) {
7295 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7296 0         0 # $1 $2 $3 $4
7297 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7298 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7299 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7300 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7301 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7302 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7303             elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7304 0         0 elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7305             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7306             }
7307 0         0 die __FILE__, ": Substitution replacement not terminated\n";
7308 0         0 }
7309 0 0       0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
7310             my @s = ($1,$2,$3);
7311 0         0 while (not /\G \z/oxgc) {
7312 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7313 0         0 # $1 $2 $3 $4
7314 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7315 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7316 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7317 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7318 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7319 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7320             elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7321 0         0 elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7322             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7323             }
7324 0         0 die __FILE__, ": Substitution replacement not terminated\n";
7325 0         0 }
7326 0 0       0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
7327             my @s = ($1,$2,$3);
7328 0         0 while (not /\G \z/oxgc) {
7329 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7330 0         0 # $1 $2 $3 $4
7331 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7332 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7333 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7334 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7335             elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7336 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7337             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7338             }
7339 0         0 die __FILE__, ": Substitution replacement not terminated\n";
7340 0         0 }
7341 0 0       0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
7342             my @s = ($1,$2,$3);
7343 0         0 while (not /\G \z/oxgc) {
7344 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7345 0         0 # $1 $2 $3 $4
7346 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7347 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7348 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7349 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7350 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7351 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7352             elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7353 0         0 elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7354             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7355             }
7356             die __FILE__, ": Substitution replacement not terminated\n";
7357 0         0 }
7358             # $1 $2 $3 $4 $5 $6
7359             elsif (/\G (\') ((?:$qq_char)*?) (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) {
7360             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
7361 96         270 }
7362             # $1 $2 $3 $4 $5 $6
7363             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
7364             return e_sub($sub_variable,'{',$2,'}','{',$4,'}',$6); # s | | | --> s { } { }
7365 2         14 }
7366             # $1 $2 $3 $4 $5 $6
7367             elsif (/\G (\$) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
7368             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
7369 0         0 }
7370             # $1 $2 $3 $4 $5 $6
7371             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
7372 192         873 return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
7373             }
7374             }
7375             die __FILE__, ": Substitution pattern not terminated\n";
7376             }
7377 0         0 }
7378 1         7  
7379 0         0 # do
7380 0         0 elsif (/\G \b do (?= (?>\s*) \{ ) /oxmsgc) { return 'do'; }
7381 0         0 elsif (/\G \b do (?= (?>\s+) (?: q | qq | qx ) \b) /oxmsgc) { return 'Esjis::do'; }
7382             elsif (/\G \b do (?= (?>\s+) (?>\w+)) /oxmsgc) { return 'do'; }
7383             elsif (/\G \b do (?= (?>\s*) \$ (?> \w+ (?: ::\w+)* ) \( ) /oxmsgc) { return 'do'; }
7384 2         10 elsif (/\G \b do \b /oxmsgc) { return 'Esjis::do'; }
7385 0         0  
7386 0         0 # require ignore module
7387             elsif (/\G \b require ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# require$1$2"; }
7388             elsif (/\G \b require ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^\x81-\x9F\xE0-\xFC#]) /oxmsgc) { return "# require$1\n$2"; }
7389 0         0 elsif (/\G \b require ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# require$1"; }
7390 0         0  
7391 0         0 # require version number
7392             elsif (/\G \b require (?>\s+) ((?>0[0-7_]*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7393             elsif (/\G \b require (?>\s+) ((?>[1-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7394 0         0 elsif (/\G \b require (?>\s+) ((?>v[0-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7395              
7396             # require bare package name
7397 18         122 elsif (/\G \b require (?>\s+) ((?>[A-Za-z_]\w* (?: :: [A-Za-z_]\w*)*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7398 0         0  
7399             # require else
7400             elsif (/\G \b require (?>\s*) ; /oxmsgc) { return 'Esjis::require;'; }
7401 1         6 elsif (/\G \b require \b /oxmsgc) { return 'Esjis::require'; }
7402 70         588  
7403 0         0 # use strict; --> use strict; no strict qw(refs);
7404             elsif (/\G \b use ((?>\s+) strict .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "use$1 no strict qw(refs);$2"; }
7405             elsif (/\G \b use ((?>\s+) strict .*? ;) ([ \t]* [^\x81-\x9F\xE0-\xFC#]) /oxmsgc) { return "use$1 no strict qw(refs);\n$2"; }
7406             elsif (/\G \b use ((?>\s+) strict) \b /oxmsgc) { return "use$1; no strict qw(refs)"; }
7407 0 50 33     0  
      33        
7408 3         58 # use 5.12.0; --> use 5.12.0; no strict qw(refs);
7409             elsif (/\G \b use (?>\s+) ((?>([1-9][0-9_]*)(?:\.([0-9_]+))*)) (?>\s*) ; /oxmsgc) {
7410             if (($2 >= 6) or (($2 == 5) and ($3 ge '012'))) {
7411 0         0 return "use $1; no strict qw(refs);";
7412             }
7413             else {
7414             return "use $1;";
7415 3 0 0     20 }
      0        
7416 0         0 }
7417             elsif (/\G \b use (?>\s+) ((?>v([0-9][0-9_]*)(?:\.([0-9_]+))*)) (?>\s*) ; /oxmsgc) {
7418             if (($2 >= 6) or (($2 == 5) and ($3 >= 12))) {
7419 0         0 return "use $1; no strict qw(refs);";
7420             }
7421             else {
7422             return "use $1;";
7423             }
7424 0         0 }
7425 2         17  
7426 0         0 # ignore use module
7427             elsif (/\G \b use ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# use$1$2"; }
7428             elsif (/\G \b use ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^\x81-\x9F\xE0-\xFC#]) /oxmsgc) { return "# use$1\n$2"; }
7429 0         0 elsif (/\G \b use ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# use$1"; }
7430 0         0  
7431 0         0 # ignore no module
7432             elsif (/\G \b no ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# no$1$2"; }
7433             elsif (/\G \b no ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^\x81-\x9F\xE0-\xFC#]) /oxmsgc) { return "# no$1\n$2"; }
7434 0         0 elsif (/\G \b no ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# no$1"; }
7435 0         0  
7436 0         0 # use without import
7437 0         0 elsif (/\G \b use (?>\s+) ((?>0[0-7_]*)) (?>\s*) ; /oxmsgc) { return "use $1;"; }
7438 0         0 elsif (/\G \b use (?>\s+) ((?>[1-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "use $1;"; }
7439 0         0 elsif (/\G \b use (?>\s+) ((?>v[0-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "use $1;"; }
7440 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7441 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7442 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\{) (?>\s*) \} (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7443 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\[) (?>\s*) \] (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7444             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\<) (?>\s*) \> (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7445             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) ([\x21-\x3F]) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7446 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\S) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7447              
7448             # use with import no parameter
7449 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ; /oxmsgc) { return e_use_noparam($1); }
7450 0         0  
7451 0         0 # use with import parameters
7452 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\() [^\x81-\x9F\xE0-\xFC)]* \)) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7453 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\') [^\x81-\x9F\xE0-\xFC']* \') (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7454 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\") [^\x81-\x9F\xE0-\xFC"]* \") (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7455 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\() [^\x81-\x9F\xE0-\xFC)]* \)) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7456 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\{) (?:$q_char)*? \}) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7457 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\[) (?:$q_char)*? \]) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7458             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\<) [^\x81-\x9F\xE0-\xFC>]* \>) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7459             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) ([\x21-\x3F]) .*? \3) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7460 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\S) (?:$q_char)*? \3) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7461 0         0  
7462 0         0 # no without unimport
7463 0         0 elsif (/\G \b no (?>\s+) ((?>0[0-7_]*)) (?>\s*) ; /oxmsgc) { return "no $1;"; }
7464 0         0 elsif (/\G \b no (?>\s+) ((?>[1-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "no $1;"; }
7465 0         0 elsif (/\G \b no (?>\s+) ((?>v[0-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "no $1;"; }
7466 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7467 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7468 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\{) (?>\s*) \} (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7469 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\[) (?>\s*) \] (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7470             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\<) (?>\s*) \> (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7471             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) ([\x21-\x3F]) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7472 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\S) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7473              
7474             # no with unimport no parameter
7475 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ; /oxmsgc) { return e_no_noparam($1); }
7476 0         0  
7477 0         0 # no with unimport parameters
7478 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\() [^\x81-\x9F\xE0-\xFC)]* \)) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7479 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\') [^\x81-\x9F\xE0-\xFC']* \') (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7480 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\") [^\x81-\x9F\xE0-\xFC"]* \") (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7481 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\() [^\x81-\x9F\xE0-\xFC)]* \)) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7482 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\{) (?:$q_char)*? \}) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7483 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\[) (?:$q_char)*? \]) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7484             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\<) [^\x81-\x9F\xE0-\xFC>]* \>) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7485             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) ([\x21-\x3F]) .*? \3) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7486 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\S) (?:$q_char)*? \3) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7487              
7488             # use else
7489 0         0 elsif (/\G \b use \b /oxmsgc) { return "use"; }
7490              
7491             # use else
7492             elsif (/\G \b no \b /oxmsgc) { return "no"; }
7493 2         10  
7494 3199         7252 # ''
7495 3199 100       8387 elsif (/\G (?
  15823 100       54219  
    100          
    50          
7496 8         22 my $q_string = '';
7497 48         81 while (not /\G \z/oxgc) {
7498 3199         7568 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
7499             elsif (/\G (\\\') /oxgc) { $q_string .= $1; }
7500 12568         26497 elsif (/\G \' /oxgc) { return e_q('', "'","'",$q_string); }
7501             elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7502             }
7503             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7504             }
7505 0         0  
7506 3444         7865 # ""
7507 3444 100       9085 elsif (/\G (\") /oxgc) {
  72144 100       199558  
    100          
    50          
7508 109         242 my $qq_string = '';
7509 14         34 while (not /\G \z/oxgc) {
7510 3444         8474 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
7511             elsif (/\G (\\\") /oxgc) { $qq_string .= $1; }
7512 68577         128321 elsif (/\G \" /oxgc) { return e_qq('', '"','"',$qq_string); }
7513             elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
7514             }
7515             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7516             }
7517 0         0  
7518 37         116 # ``
7519 37 50       151 elsif (/\G (\`) /oxgc) {
  313 50       2020  
    100          
    50          
7520 0         0 my $qx_string = '';
7521 0         0 while (not /\G \z/oxgc) {
7522 37         441 if (/\G (\\\\) /oxgc) { $qx_string .= $1; }
7523             elsif (/\G (\\\`) /oxgc) { $qx_string .= $1; }
7524 276         597 elsif (/\G \` /oxgc) { return e_qq('', '`','`',$qx_string); }
7525             elsif (/\G ($q_char) /oxgc) { $qx_string .= $1; }
7526             }
7527             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7528             }
7529 0         0  
7530 1231         3128 # // --- not divide operator (num / num), not defined-or
7531 1231 100       3287 elsif (($slash eq 'm//') and /\G (\/) /oxgc) {
  12525 50       40491  
    100          
    50          
7532 11         35 my $regexp = '';
7533 0         0 while (not /\G \z/oxgc) {
7534 1231         3386 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
7535             elsif (/\G (\\\/) /oxgc) { $regexp .= $1; }
7536 11283         21754 elsif (/\G \/ ([cgimosxpadlunbB]*) /oxgc) { return e_qr('', '/','/',$regexp,$1); }
7537             elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
7538             }
7539             die __FILE__, ": Search pattern not terminated\n";
7540             }
7541 0         0  
7542 92         201 # ?? --- not conditional operator (condition ? then : else)
7543 92 50       282 elsif (($slash eq 'm//') and /\G (\?) /oxgc) {
  266 50       985  
    100          
    50          
7544 0         0 my $regexp = '';
7545 0         0 while (not /\G \z/oxgc) {
7546 92         222 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
7547             elsif (/\G (\\\?) /oxgc) { $regexp .= $1; }
7548 174         407 elsif (/\G \? ([cgimosxpadlunbB]*) /oxgc) { return e_qr('m','?','?',$regexp,$1); }
7549             elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
7550             }
7551             die __FILE__, ": Search pattern not terminated\n";
7552 0         0 }
  0         0  
7553              
7554             # <<>> (a safer ARGV)
7555 0         0 elsif (/\G ( <<>> ) /oxgc) { $slash = 'm//'; return $1; }
  0         0  
7556              
7557             # << (bit shift) --- not here document
7558             elsif (/\G ( << (?>\s*) ) (?= [0-9\$\@\&] ) /oxgc) { $slash = 'm//'; return $1; }
7559 0         0  
7560 6         14 # <<~'HEREDOC'
7561 6         12 elsif (/\G ( <<~ [\t ]* '([a-zA-Z_0-9]*)' ) /oxgc) {
7562             $slash = 'm//';
7563             my $here_quote = $1;
7564 6 50       10 my $delimiter = $2;
7565 6         14  
7566 6         41 # get here document
7567             if ($here_script eq '') {
7568 6 50       36 $here_script = CORE::substr $_, pos $_;
7569 6         59 $here_script =~ s/.*?\n//oxm;
7570 6         13 }
7571 6         13 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7572 6         48 my $heredoc = $1;
7573 6         22 my $indent = $2;
7574             $heredoc =~ s{^$indent}{}msg; # no /ox
7575             push @heredoc, $heredoc . qq{\n$delimiter\n};
7576 6         13 push @heredoc_delimiter, qq{\\s*$delimiter};
7577             }
7578 0         0 else {
7579             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7580             }
7581             return qq{<<'$delimiter'};
7582             }
7583              
7584             # <<~\HEREDOC
7585              
7586             # P.66 2.6.6. "Here" Documents
7587             # in Chapter 2: Bits and Pieces
7588             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
7589              
7590             # P.73 "Here" Documents
7591             # in Chapter 2: Bits and Pieces
7592 6         24 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7593 3         8  
7594 3         6 elsif (/\G ( <<~ \\([a-zA-Z_0-9]+) ) /oxgc) {
7595             $slash = 'm//';
7596             my $here_quote = $1;
7597 3 50       8 my $delimiter = $2;
7598 3         9  
7599 3         16 # get here document
7600             if ($here_script eq '') {
7601 3 50       17 $here_script = CORE::substr $_, pos $_;
7602 3         38 $here_script =~ s/.*?\n//oxm;
7603 3         7 }
7604 3         6 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7605 3         36 my $heredoc = $1;
7606 3         13 my $indent = $2;
7607             $heredoc =~ s{^$indent}{}msg; # no /ox
7608             push @heredoc, $heredoc . qq{\n$delimiter\n};
7609 3         7 push @heredoc_delimiter, qq{\\s*$delimiter};
7610             }
7611 0         0 else {
7612             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7613             }
7614             return qq{<<\\$delimiter};
7615             }
7616 3         14  
7617 6         18 # <<~"HEREDOC"
7618 6         16 elsif (/\G ( <<~ [\t ]* "([a-zA-Z_0-9]*)" ) /oxgc) {
7619             $slash = 'm//';
7620             my $here_quote = $1;
7621 6 50       14 my $delimiter = $2;
7622 6         16  
7623 6         59 # get here document
7624             if ($here_script eq '') {
7625 6 50       41 $here_script = CORE::substr $_, pos $_;
7626 6         74 $here_script =~ s/.*?\n//oxm;
7627 6         17 }
7628 6         12 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7629 6         75 my $heredoc = $1;
7630 6         21 my $indent = $2;
7631             $heredoc =~ s{^$indent}{}msg; # no /ox
7632             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
7633 6         19 push @heredoc_delimiter, qq{\\s*$delimiter};
7634             }
7635 0         0 else {
7636             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7637             }
7638             return qq{<<"$delimiter"};
7639             }
7640 6         30  
7641 3         10 # <<~HEREDOC
7642 3         9 elsif (/\G ( <<~ ([a-zA-Z_0-9]+) ) /oxgc) {
7643             $slash = 'm//';
7644             my $here_quote = $1;
7645 3 50       7 my $delimiter = $2;
7646 3         12  
7647 3         19 # get here document
7648             if ($here_script eq '') {
7649 3 50       22 $here_script = CORE::substr $_, pos $_;
7650 3         74 $here_script =~ s/.*?\n//oxm;
7651 3         10 }
7652 3         6 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7653 3         48 my $heredoc = $1;
7654 3         14 my $indent = $2;
7655             $heredoc =~ s{^$indent}{}msg; # no /ox
7656             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
7657 3         11 push @heredoc_delimiter, qq{\\s*$delimiter};
7658             }
7659 0         0 else {
7660             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7661             }
7662             return qq{<<$delimiter};
7663             }
7664 3         15  
7665 6         18 # <<~`HEREDOC`
7666 6         17 elsif (/\G ( <<~ [\t ]* `([a-zA-Z_0-9]*)` ) /oxgc) {
7667             $slash = 'm//';
7668             my $here_quote = $1;
7669 6 50       13 my $delimiter = $2;
7670 6         16  
7671 6         34 # get here document
7672             if ($here_script eq '') {
7673 6 50       50 $here_script = CORE::substr $_, pos $_;
7674 6         72 $here_script =~ s/.*?\n//oxm;
7675 6         15 }
7676 6         13 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7677 6         58 my $heredoc = $1;
7678 6         39 my $indent = $2;
7679             $heredoc =~ s{^$indent}{}msg; # no /ox
7680             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
7681 6         16 push @heredoc_delimiter, qq{\\s*$delimiter};
7682             }
7683 0         0 else {
7684             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7685             }
7686             return qq{<<`$delimiter`};
7687             }
7688 6         29  
7689 86         202 # <<'HEREDOC'
7690 86         200 elsif (/\G ( << '([a-zA-Z_0-9]*)' ) /oxgc) {
7691             $slash = 'm//';
7692             my $here_quote = $1;
7693 86 100       167 my $delimiter = $2;
7694 86         201  
7695 83         473 # get here document
7696             if ($here_script eq '') {
7697 83 50       471 $here_script = CORE::substr $_, pos $_;
7698 86         715 $here_script =~ s/.*?\n//oxm;
7699 86         308 }
7700             if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7701             push @heredoc, $1 . qq{\n$delimiter\n};
7702 86         163 push @heredoc_delimiter, $delimiter;
7703             }
7704 0         0 else {
7705             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7706             }
7707             return $here_quote;
7708             }
7709              
7710             # <<\HEREDOC
7711              
7712             # P.66 2.6.6. "Here" Documents
7713             # in Chapter 2: Bits and Pieces
7714             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
7715              
7716             # P.73 "Here" Documents
7717             # in Chapter 2: Bits and Pieces
7718 86         358 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7719 2         7  
7720 2         4 elsif (/\G ( << \\([a-zA-Z_0-9]+) ) /oxgc) {
7721             $slash = 'm//';
7722             my $here_quote = $1;
7723 2 100       4 my $delimiter = $2;
7724 2         5  
7725 1         7 # get here document
7726             if ($here_script eq '') {
7727 1 50       6 $here_script = CORE::substr $_, pos $_;
7728 2         38 $here_script =~ s/.*?\n//oxm;
7729 2         9 }
7730             if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7731             push @heredoc, $1 . qq{\n$delimiter\n};
7732 2         4 push @heredoc_delimiter, $delimiter;
7733             }
7734 0         0 else {
7735             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7736             }
7737             return $here_quote;
7738             }
7739 2         9  
7740 39         101 # <<"HEREDOC"
7741 39         99 elsif (/\G ( << "([a-zA-Z_0-9]*)" ) /oxgc) {
7742             $slash = 'm//';
7743             my $here_quote = $1;
7744 39 100       76 my $delimiter = $2;
7745 39         100  
7746 38         278 # get here document
7747             if ($here_script eq '') {
7748 38 50       305 $here_script = CORE::substr $_, pos $_;
7749 39         521 $here_script =~ s/.*?\n//oxm;
7750 39         156 }
7751             if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7752             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
7753 39         104 push @heredoc_delimiter, $delimiter;
7754             }
7755 0         0 else {
7756             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7757             }
7758             return $here_quote;
7759             }
7760 39         178  
7761 54         146 # <
7762 54         127 elsif (/\G ( << ([a-zA-Z_0-9]+) ) /oxgc) {
7763             $slash = 'm//';
7764             my $here_quote = $1;
7765 54 100       110 my $delimiter = $2;
7766 54         141  
7767 51         335 # get here document
7768             if ($here_script eq '') {
7769 51 50       368 $here_script = CORE::substr $_, pos $_;
7770 54         773 $here_script =~ s/.*?\n//oxm;
7771 54         196 }
7772             if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7773             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
7774 54         122 push @heredoc_delimiter, $delimiter;
7775             }
7776 0         0 else {
7777             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7778             }
7779             return $here_quote;
7780             }
7781 54         245  
7782 0         0 # <<`HEREDOC`
7783 0         0 elsif (/\G ( << `([a-zA-Z_0-9]*)` ) /oxgc) {
7784             $slash = 'm//';
7785             my $here_quote = $1;
7786 0 0       0 my $delimiter = $2;
7787 0         0  
7788 0         0 # get here document
7789             if ($here_script eq '') {
7790 0 0       0 $here_script = CORE::substr $_, pos $_;
7791 0         0 $here_script =~ s/.*?\n//oxm;
7792 0         0 }
7793             if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7794             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
7795 0         0 push @heredoc_delimiter, $delimiter;
7796             }
7797 0         0 else {
7798             die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7799             }
7800             return $here_quote;
7801             }
7802 0         0  
7803             # <<= <=> <= < operator
7804             elsif (/\G ( <<= | <=> | <= | < ) (?= (?>\s*) [A-Za-z_0-9'"`\$\@\&\*\(\+\-] )/oxgc) {
7805             return $1;
7806             }
7807 13         91  
7808             #
7809             elsif (/\G (<[\$]?[A-Za-z_][A-Za-z_0-9]*>) /oxgc) {
7810             return $1;
7811             }
7812              
7813             # --- glob
7814              
7815 0         0 # avoid "Error: Runtime exception" of perl version 5.005_03
7816              
7817             elsif (/\G < ((?:[^\x81-\x9F\xE0-\xFC>\0\a\e\f\n\r\t]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])+?) > /oxgc) {
7818             return 'Esjis::glob("' . $1 . '")';
7819 0         0 }
7820              
7821             # __DATA__
7822 0         0 elsif (/\G ^ ( __DATA__ \n .*) \z /oxmsgc) { return $1; }
7823              
7824             # __END__
7825             elsif (/\G ^ ( __END__ \n .*) \z /oxmsgc) { return $1; }
7826              
7827             # \cD Control-D
7828              
7829             # P.68 2.6.8. Other Literal Tokens
7830             # in Chapter 2: Bits and Pieces
7831             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
7832              
7833             # P.76 Other Literal Tokens
7834 385         3069 # in Chapter 2: Bits and Pieces
7835             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7836              
7837 0         0 elsif (/\G ( \cD .*) \z /oxmsgc) { return $1; }
7838              
7839             # \cZ Control-Z
7840             elsif (/\G ( \cZ .*) \z /oxmsgc) { return $1; }
7841              
7842             # any operator before div
7843             elsif (/\G (
7844 0         0 -- | \+\+ |
  14225         31086  
7845             [\)\}\]]
7846              
7847             ) /oxgc) { $slash = 'div'; return $1; }
7848              
7849             # yada-yada or triple-dot operator
7850 14225         67414 elsif (/\G (
  7         19  
7851             \.\.\.
7852              
7853             ) /oxgc) { $slash = 'm//'; return q{die('Unimplemented')}; }
7854              
7855             # any operator before m//
7856              
7857             # //, //= (defined-or)
7858              
7859             # P.164 Logical Operators
7860             # in Chapter 10: More Control Structures
7861             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
7862              
7863             # P.119 C-Style Logical (Short-Circuit) Operators
7864             # in Chapter 3: Unary and Binary Operators
7865             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7866              
7867             # (and so on)
7868              
7869             # ~~
7870              
7871             # P.221 The Smart Match Operator
7872             # in Chapter 15: Smart Matching and given-when
7873             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
7874              
7875             # P.112 Smartmatch Operator
7876             # in Chapter 3: Unary and Binary Operators
7877             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7878              
7879             # (and so on)
7880              
7881             elsif (/\G ((?>
7882              
7883             !~~ | !~ | != | ! |
7884             %= | % |
7885             &&= | && | &= | &\.= | &\. | & |
7886             -= | -> | - |
7887             :(?>\s*)= |
7888             : |
7889             <<>> |
7890             <<= | <=> | <= | < |
7891             == | => | =~ | = |
7892             >>= | >> | >= | > |
7893             \*\*= | \*\* | \*= | \* |
7894             \+= | \+ |
7895             \.\. | \.= | \. |
7896             \/\/= | \/\/ |
7897             \/= | \/ |
7898             \? |
7899             \\ |
7900             \^= | \^\.= | \^\. | \^ |
7901             \b x= |
7902             \|\|= | \|\| | \|= | \|\.= | \|\. | \| |
7903             ~~ | ~\. | ~ |
7904             \b(?: and | cmp | eq | ge | gt | le | lt | ne | not | or | xor | x )\b |
7905             \b(?: print )\b |
7906 7         32  
  23936         49375  
7907             [,;\(\{\[]
7908              
7909 23936         112551 )) /oxgc) { $slash = 'm//'; return $1; }
  37295         75041  
7910              
7911             # other any character
7912             elsif (/\G ($q_char) /oxgc) { $slash = 'div'; return $1; }
7913 37295         192273  
7914             # system error
7915             else {
7916             die __FILE__, ": Oops, this shouldn't happen!\n";
7917             }
7918             }
7919 0     3114 0 0  
7920 3114         7413 # escape ShiftJIS string
7921             sub e_string {
7922 3114         4365 my($string) = @_;
7923             my $e_string = '';
7924              
7925             local $slash = 'm//';
7926              
7927             # P.1024 Appendix W.10 Multibyte Processing
7928 3114         4468 # of ISBN 1-56592-224-7 CJKV Information Processing
7929             # (and so on)
7930              
7931 3114 100 66     28435 my @char = $string =~ / \G (?>[^\x81-\x9F\xE0-\xFC\\]|\\$q_char|$q_char) /oxmsg;
7932 3114 50       13779  
7933 3023         6638 # without { ... }
7934             if (not (grep(/\A \{ \z/xms, @char) and grep(/\A \} \z/xms, @char))) {
7935             if ($string !~ /<
7936             return $string;
7937             }
7938 3023         7288 }
7939 91 50       276  
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    100          
    50          
    100          
    100          
    100          
    50          
    50          
7940             E_STRING_LOOP:
7941             while ($string !~ /\G \z/oxgc) {
7942             if (0) {
7943 794         39759 }
7944 0         0  
7945 0         0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> @{[Esjis::PREMATCH()]}
7946             elsif ($string =~ /\G ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH \b | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) /oxmsgc) {
7947             $e_string .= q{Esjis::PREMATCH()};
7948             $slash = 'div';
7949             }
7950 0         0  
7951 0         0 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> @{[Esjis::MATCH()]}
7952             elsif ($string =~ /\G ( \$& | \$\{&\} | \$ (?>\s*) MATCH \b | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) /oxmsgc) {
7953             $e_string .= q{Esjis::MATCH()};
7954             $slash = 'div';
7955             }
7956 0         0  
7957 0         0 # $', ${'} --> $', ${'}
7958             elsif ($string =~ /\G ( \$' | \$\{'\} ) /oxmsgc) {
7959             $e_string .= $1;
7960             $slash = 'div';
7961             }
7962 0         0  
7963 0         0 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> @{[Esjis::POSTMATCH()]}
7964             elsif ($string =~ /\G ( \$ (?>\s*) POSTMATCH \b | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) /oxmsgc) {
7965             $e_string .= q{Esjis::POSTMATCH()};
7966             $slash = 'div';
7967             }
7968 0         0  
7969 0         0 # bareword
7970             elsif ($string =~ /\G ( \{ (?>\s*) (?: tr | index | rindex | reverse ) (?>\s*) \} ) /oxmsgc) {
7971             $e_string .= $1;
7972             $slash = 'div';
7973             }
7974 0         0  
7975 0         0 # $0 --> $0
7976             elsif ($string =~ /\G ( \$ 0 ) /oxmsgc) {
7977             $e_string .= $1;
7978 0         0 $slash = 'div';
7979 0         0 }
7980             elsif ($string =~ /\G ( \$ \{ (?>\s*) 0 (?>\s*) \} ) /oxmsgc) {
7981             $e_string .= $1;
7982             $slash = 'div';
7983             }
7984 0         0  
7985 0         0 # $$ --> $$
7986             elsif ($string =~ /\G ( \$ \$ ) (?![\w\{]) /oxmsgc) {
7987             $e_string .= $1;
7988             $slash = 'div';
7989             }
7990              
7991 0         0 # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
7992 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
7993             elsif ($string =~ /\G \$ ((?>[1-9][0-9]*)) /oxmsgc) {
7994             $e_string .= e_capture($1);
7995 0         0 $slash = 'div';
7996 0         0 }
7997             elsif ($string =~ /\G \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} /oxmsgc) {
7998             $e_string .= e_capture($1);
7999             $slash = 'div';
8000             }
8001 0         0  
8002 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
8003             elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ .+? \] ) /oxmsgc) {
8004             $e_string .= e_capture($1.'->'.$2);
8005             $slash = 'div';
8006             }
8007 0         0  
8008 0         0 # $$foo{ ... } --> $ $foo->{ ... }
8009             elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ .+? \} ) /oxmsgc) {
8010             $e_string .= e_capture($1.'->'.$2);
8011             $slash = 'div';
8012             }
8013 0         0  
8014 0         0 # $$foo
8015             elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) /oxmsgc) {
8016             $e_string .= e_capture($1);
8017             $slash = 'div';
8018             }
8019 0         0  
8020 0         0 # ${ foo }
8021             elsif ($string =~ /\G \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} /oxmsgc) {
8022             $e_string .= '${' . $1 . '}';
8023             $slash = 'div';
8024             }
8025 0         0  
8026 3         11 # ${ ... }
8027             elsif ($string =~ /\G \$ (?>\s*) \{ (?>\s*) ( $qq_brace ) (?>\s*) \} /oxmsgc) {
8028             $e_string .= e_capture($1);
8029             $slash = 'div';
8030             }
8031              
8032 3         15 # variable or function
8033 0         0 # $ @ % & * $ #
8034             elsif ($string =~ /\G ( (?: [\$\@\%\&\*] | \$\# | -> | \b sub \b) (?>\s*) (?: split | chop | index | rindex | lc | uc | fc | chr | ord | reverse | getc | tr | y | q | qq | qx | qw | m | s | qr | glob | lstat | opendir | stat | unlink | chdir ) ) \b /oxmsgc) {
8035             $e_string .= $1;
8036             $slash = 'div';
8037             }
8038 0         0 # $ $ $ $ $ $ $ $ $ $ $ $ $ $
8039 0         0 # $ @ # \ ' " / ? ( ) [ ] < >
8040             elsif ($string =~ /\G ( \$[\$\@\#\\\'\"\/\?\(\)\[\]\<\>] ) /oxmsgc) {
8041             $e_string .= $1;
8042             $slash = 'div';
8043             }
8044 0         0  
  0         0  
8045 0         0 # subroutines of package Esjis
  0         0  
8046 0         0 elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
8047 0         0 (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_qq('', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
8048 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
8049 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
8050 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  1         6  
8051             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
8052             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
8053 1         5 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\S) ((?:$qq_char)+?) (\2) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  1         6  
8054 1         26  
  0         0  
8055 0         0 elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
8056 0         0 (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_q ('', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
8057 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
8058 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
8059 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  1         7  
8060             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
8061             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
8062 1         3 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\S) ((?:\\\2|\\\\|$q_char)+?) (\2) /oxgc) { $e_string .= "Esjis::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
8063 0         0  
  0         0  
8064 0         0 elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) (\$ (?> \w+ (?: ::\w+)*) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
8065 0         0 { $e_string .= "Esjis::filetest(qw($1),$2)"; $slash = 'm//'; }
  0         0  
8066             elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) \( ((?:$qq_paren)*?) \) /oxgc) { $e_string .= "Esjis::filetest(qw($1),$2)"; $slash = 'm//'; }
8067             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) (?= [a-z]+) /oxgc) { $e_string .= "Esjis::filetest qw($1),"; $slash = 'm//'; }
8068             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) ((?>\w+)) /oxgc) { $e_string .= "Esjis::filetest(qw($1),$2)"; $slash = 'm//'; }
8069 0         0  
8070 2 50       4 # qq//
8071 2         34 elsif ($string =~ /\G \b (qq) \b /oxgc) {
8072             my $ope = $1;
8073             if ($string =~ /\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qq# #
8074 0         0 $e_string .= e_qq($ope,$1,$3,$2);
8075 2         4 }
8076 2 50       7 else {
  2 50       247  
    50          
    50          
    50          
    50          
8077 0         0 my $e = '';
  0         0  
8078 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
8079 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
8080 0         0 elsif ($string =~ /\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq ( )
  0         0  
8081 0         0 elsif ($string =~ /\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq { }
  2         7  
8082             elsif ($string =~ /\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq [ ]
8083 2         12 elsif ($string =~ /\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq < >
8084             elsif ($string =~ /\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq * *
8085             }
8086             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
8087             }
8088             }
8089 0         0  
8090 0 0       0 # qx//
8091 0         0 elsif ($string =~ /\G \b (qx) \b /oxgc) {
8092             my $ope = $1;
8093             if ($string =~ /\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qx# #
8094 0         0 $e_string .= e_qq($ope,$1,$3,$2);
8095 0         0 }
8096 0 0       0 else {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
8097 0         0 my $e = '';
  0         0  
8098 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
8099 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
8100 0         0 elsif ($string =~ /\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx ( )
  0         0  
8101 0         0 elsif ($string =~ /\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx { }
  0         0  
8102 0         0 elsif ($string =~ /\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx [ ]
  0         0  
8103             elsif ($string =~ /\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx < >
8104 0         0 elsif ($string =~ /\G (\') ((?:$qq_char)*?) (\') /oxgc) { $e_string .= $e . e_q ($ope,$1,$3,$2); next E_STRING_LOOP; } # qx ' '
8105             elsif ($string =~ /\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx * *
8106             }
8107             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
8108             }
8109             }
8110 0         0  
8111 2 50       4 # q//
8112 2         41 elsif ($string =~ /\G \b (q) \b /oxgc) {
8113             my $ope = $1;
8114             if ($string =~ /\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { # q# #
8115 0         0 $e_string .= e_q($ope,$1,$3,$2);
8116 2         4 }
8117 2 50       6 else {
  2 50       196  
    50          
    50          
    50          
    50          
8118 0         0 my $e = '';
  0         0  
8119 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
8120 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
8121 0         0 elsif ($string =~ /\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q ( )
  0         0  
8122 0         0 elsif ($string =~ /\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q { }
  2         8  
8123             elsif ($string =~ /\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q [ ]
8124 2         11 elsif ($string =~ /\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q < >
8125             elsif ($string =~ /\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q * *
8126             }
8127             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
8128             }
8129 0         0 }
8130              
8131             # ''
8132 45         165 elsif ($string =~ /\G (?
8133              
8134             # ""
8135 6         21 elsif ($string =~ /\G (\") ((?:$qq_char)*?) (\") /oxgc) { $e_string .= e_qq('',$1,$3,$2); }
8136              
8137             # ``
8138 0         0 elsif ($string =~ /\G (\`) ((?:$qq_char)*?) (\`) /oxgc) { $e_string .= e_qq('',$1,$3,$2); }
8139              
8140             # other any character
8141             elsif ($string =~ /\G ($q_char) /oxgc) { $e_string .= $1; }
8142 733         2085  
8143             # system error
8144             else {
8145             die __FILE__, ": Oops, this shouldn't happen!\n";
8146 0         0 }
8147             }
8148              
8149             return $e_string;
8150             }
8151              
8152             #
8153 91     5358 0 338 # character class
8154             #
8155 5358 100       9916 sub character_class {
8156 5358 100       8156 my($char,$modifier) = @_;
8157 115         302  
8158             if ($char eq '.') {
8159             if ($modifier =~ /s/) {
8160 23         65 return '${Esjis::dot_s}';
8161             }
8162             else {
8163             return '${Esjis::dot}';
8164 92         201 }
8165             }
8166             else {
8167             return Esjis::classic_character_class($char);
8168             }
8169             }
8170              
8171             #
8172             # escape capture ($1, $2, $3, ...)
8173 5243     637 0 9167 #
8174 637         2627 sub e_capture {
8175              
8176             return join '', '${Esjis::capture(', $_[0], ')}';
8177             return join '', '${', $_[0], '}';
8178             }
8179              
8180             #
8181 0     11 0 0 # escape transliteration (tr/// or y///)
8182 11         76 #
8183 11   100     22 sub e_tr {
8184             my($variable,$charclass,$e,$charclass2,$modifier) = @_;
8185 11         33 my $e_tr = '';
8186             $modifier ||= '';
8187              
8188 11         18 $slash = 'div';
8189              
8190             # quote character class 1
8191 11         26 $charclass = q_tr($charclass);
8192              
8193             # quote character class 2
8194 11 50       41 $charclass2 = q_tr($charclass2);
8195 11 0       34  
8196 0         0 # /b /B modifier
8197             if ($modifier =~ tr/bB//d) {
8198             if ($variable eq '') {
8199 0         0 $e_tr = qq{tr$charclass$e$charclass2$modifier};
8200             }
8201             else {
8202             $e_tr = qq{$variable${bind_operator}tr$charclass$e$charclass2$modifier};
8203 0 100       0 }
8204 11         22 }
8205             else {
8206             if ($variable eq '') {
8207 2         8 $e_tr = qq{Esjis::tr(\$_,' =~ ',$charclass,$e$charclass2,'$modifier')};
8208             }
8209             else {
8210             $e_tr = qq{Esjis::tr($variable,'$bind_operator',$charclass,$e$charclass2,'$modifier')};
8211             }
8212 9         27 }
8213 11         15  
8214             # clear tr/// variable
8215 11         24 $tr_variable = '';
8216             $bind_operator = '';
8217              
8218             return $e_tr;
8219             }
8220              
8221             #
8222 11     22 0 61 # quote for escape transliteration (tr/// or y///)
8223             #
8224             sub q_tr {
8225 22 50       36 my($charclass) = @_;
    0          
    0          
    0          
    0          
    0          
8226 22         46  
8227             # quote character class
8228             if ($charclass !~ /'/oxms) {
8229 22         32 return e_q('', "'", "'", $charclass); # --> q' '
8230             }
8231             elsif ($charclass !~ /\//oxms) {
8232 0         0 return e_q('q', '/', '/', $charclass); # --> q/ /
8233             }
8234             elsif ($charclass !~ /\#/oxms) {
8235 0         0 return e_q('q', '#', '#', $charclass); # --> q# #
8236             }
8237             elsif ($charclass !~ /[\<\>]/oxms) {
8238 0         0 return e_q('q', '<', '>', $charclass); # --> q< >
8239             }
8240             elsif ($charclass !~ /[\(\)]/oxms) {
8241 0         0 return e_q('q', '(', ')', $charclass); # --> q( )
8242             }
8243             elsif ($charclass !~ /[\{\}]/oxms) {
8244 0         0 return e_q('q', '{', '}', $charclass); # --> q{ }
8245 0 0       0 }
8246 0         0 else {
8247             for my $char (qw( ! " $ % & * + . : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8248             if ($charclass !~ /\Q$char\E/xms) {
8249             return e_q('q', $char, $char, $charclass);
8250             }
8251 0         0 }
8252             }
8253              
8254             return e_q('q', '{', '}', $charclass);
8255             }
8256              
8257             #
8258 0     3990 0 0 # escape q string (q//, '')
8259             #
8260 3990         29304 sub e_q {
8261             my($ope,$delimiter,$end_delimiter,$string) = @_;
8262 3990         5728  
8263 3990         34552 $slash = 'div';
8264              
8265             my @char = $string =~ / \G (?>$q_char) /oxmsg;
8266 3990 100 100     10914 for (my $i=0; $i <= $#char; $i++) {
    100 100        
8267 21330         127149  
8268             # escape last octet of multiple-octet
8269             if ($char[$i] =~ /\A ([\x80-\xFF].*) (\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
8270 1         6 $char[$i] = $1 . '\\' . $2;
8271             }
8272             elsif (defined($char[$i+1]) and ($char[$i+1] eq '\\') and ($char[$i] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
8273 22 100 100     91 $char[$i] = $1 . '\\' . $2;
8274 3990         19537 }
8275             }
8276             if (defined($char[-1]) and ($char[-1] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
8277 204         662 $char[-1] = $1 . '\\' . $2;
8278 3990         21078 }
8279              
8280             return join '', $ope, $delimiter, @char, $end_delimiter;
8281             return join '', $ope, $delimiter, $string, $end_delimiter;
8282             }
8283              
8284             #
8285 0     9596 0 0 # escape qq string (qq//, "", qx//, ``)
8286             #
8287 9596         21715 sub e_qq {
8288             my($ope,$delimiter,$end_delimiter,$string) = @_;
8289 9596         12785  
8290 9596         11268 $slash = 'div';
8291              
8292             my $left_e = 0;
8293 9596         10446 my $right_e = 0;
8294              
8295             # split regexp
8296             my @char = $string =~ /\G((?>
8297             [^\x81-\x9F\xE0-\xFC\\\$]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] |
8298             \\x\{ (?>[0-9A-Fa-f]+) \} |
8299             \\o\{ (?>[0-7]+) \} |
8300             \\N\{ (?>[^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} |
8301             \\ $q_char |
8302             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
8303             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
8304             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
8305             \$ (?>\s* [0-9]+) |
8306             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
8307             \$ \$ (?![\w\{]) |
8308             \$ (?>\s*) \$ (?>\s*) $qq_variable |
8309 9596         372263 $q_char
8310             ))/oxmsg;
8311              
8312 9596 50 66     29704 for (my $i=0; $i <= $#char; $i++) {
    50 33        
    100          
    100          
    50          
8313 309965         963121  
8314             # "\L\u" --> "\u\L"
8315             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
8316             @char[$i,$i+1] = @char[$i+1,$i];
8317             }
8318 0         0  
8319             # "\U\l" --> "\l\U"
8320             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
8321             @char[$i,$i+1] = @char[$i+1,$i];
8322             }
8323 0         0  
8324             # octal escape sequence
8325             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
8326             $char[$i] = Esjis::octchr($1);
8327             }
8328 1         4  
8329             # hexadecimal escape sequence
8330             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
8331             $char[$i] = Esjis::hexchr($1);
8332             }
8333 1         4  
8334             # \N{CHARNAME} --> N{CHARNAME}
8335             elsif ($char[$i] =~ /\A \\ ( N\{ ([^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} ) \z/oxms) {
8336 0 100       0 $char[$i] = $1;
    100          
    50          
    50          
    50          
    100          
    100          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
8337             }
8338              
8339             if (0) {
8340             }
8341              
8342 309965         2829692 # escape last octet of multiple-octet
8343 0         0 # my $metachar = qr/[\@\\\|]/oxms; # '|' is for qx//, ``, open(), and system()
8344             # variable $delimiter and $end_delimiter can be ''
8345             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\@\\\|$delimiter$end_delimiter]) \z/xms) {
8346             $char[$i] = $1 . '\\' . $2;
8347             }
8348              
8349             # \F
8350             #
8351             # P.69 Table 2-6. Translation escapes
8352             # in Chapter 2: Bits and Pieces
8353             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
8354             # (and so on)
8355 1342 50       4465  
8356 650         1560 # \u \l \U \L \F \Q \E
8357             elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
8358             if ($right_e < $left_e) {
8359             $char[$i] = '\\' . $char[$i];
8360             }
8361             }
8362             elsif ($char[$i] eq '\u') {
8363              
8364             # "STRING @{[ LIST EXPR ]} MORE STRING"
8365              
8366             # P.257 Other Tricks You Can Do with Hard References
8367             # in Chapter 8: References
8368             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
8369              
8370             # P.353 Other Tricks You Can Do with Hard References
8371             # in Chapter 8: References
8372             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
8373 0         0  
8374 0         0 # (and so on)
8375              
8376             $char[$i] = '@{[Esjis::ucfirst qq<';
8377 0         0 $left_e++;
8378 0         0 }
8379             elsif ($char[$i] eq '\l') {
8380             $char[$i] = '@{[Esjis::lcfirst qq<';
8381 0         0 $left_e++;
8382 0         0 }
8383             elsif ($char[$i] eq '\U') {
8384             $char[$i] = '@{[Esjis::uc qq<';
8385 0         0 $left_e++;
8386 6         10 }
8387             elsif ($char[$i] eq '\L') {
8388             $char[$i] = '@{[Esjis::lc qq<';
8389 6         11 $left_e++;
8390 9         16 }
8391             elsif ($char[$i] eq '\F') {
8392             $char[$i] = '@{[Esjis::fc qq<';
8393 9         42 $left_e++;
8394 0         0 }
8395             elsif ($char[$i] eq '\Q') {
8396             $char[$i] = '@{[CORE::quotemeta qq<';
8397 0 50       0 $left_e++;
8398 12         19 }
8399 12         16 elsif ($char[$i] eq '\E') {
8400             if ($right_e < $left_e) {
8401             $char[$i] = '>]}';
8402 12         24 $right_e++;
8403             }
8404             else {
8405             $char[$i] = '';
8406 0         0 }
8407 0 0       0 }
8408 0         0 elsif ($char[$i] eq '\Q') {
8409             while (1) {
8410 0 0       0 if (++$i > $#char) {
8411 0         0 last;
8412             }
8413             if ($char[$i] eq '\E') {
8414             last;
8415             }
8416             }
8417             }
8418             elsif ($char[$i] eq '\E') {
8419             }
8420              
8421             # $0 --> $0
8422             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
8423             }
8424             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
8425             }
8426              
8427             # $$ --> $$
8428             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
8429             }
8430              
8431 0         0 # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
8432             # $1, $2, $3 --> $1, $2, $3 otherwise
8433             elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
8434 415         1298 $char[$i] = e_capture($1);
8435             }
8436             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
8437             $char[$i] = e_capture($1);
8438             }
8439 0         0  
8440             # $$foo[ ... ] --> $ $foo->[ ... ]
8441             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
8442             $char[$i] = e_capture($1.'->'.$2);
8443             }
8444 0         0  
8445             # $$foo{ ... } --> $ $foo->{ ... }
8446             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
8447             $char[$i] = e_capture($1.'->'.$2);
8448             }
8449 0         0  
8450             # $$foo
8451             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
8452             $char[$i] = e_capture($1);
8453             }
8454 0         0  
8455             # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Esjis::PREMATCH()
8456             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
8457             $char[$i] = '@{[Esjis::PREMATCH()]}';
8458             }
8459 44         144  
8460             # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Esjis::MATCH()
8461             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
8462             $char[$i] = '@{[Esjis::MATCH()]}';
8463             }
8464 45         178  
8465             # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Esjis::POSTMATCH()
8466             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
8467             $char[$i] = '@{[Esjis::POSTMATCH()]}';
8468             }
8469              
8470             # ${ foo } --> ${ foo }
8471             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ (?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* ) \} \z/oxms) {
8472             }
8473 33         106  
8474             # ${ ... }
8475             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
8476             $char[$i] = e_capture($1);
8477             }
8478 0 100       0 }
8479 9596         19413  
8480             # return string
8481 3         18 if ($left_e > $right_e) {
8482             return join '', $ope, $delimiter, @char, '>]}' x ($left_e - $right_e), $end_delimiter;
8483             }
8484             return join '', $ope, $delimiter, @char, $end_delimiter;
8485             }
8486              
8487             #
8488 9593     34 0 77149 # escape qw string (qw//)
8489             #
8490 34         193 sub e_qw {
8491             my($ope,$delimiter,$end_delimiter,$string) = @_;
8492              
8493 34         76 $slash = 'div';
  34         352  
8494 621 50       1062  
    0          
    0          
    0          
    0          
8495 34         189 # choice again delimiter
8496             my %octet = map {$_ => 1} ($string =~ /\G ([\x00-\xFF]) /oxmsg);
8497             if (not $octet{$end_delimiter}) {
8498 34         256 return join '', $ope, $delimiter, $string, $end_delimiter;
8499             }
8500             elsif (not $octet{')'}) {
8501 0         0 return join '', $ope, '(', $string, ')';
8502             }
8503             elsif (not $octet{'}'}) {
8504 0         0 return join '', $ope, '{', $string, '}';
8505             }
8506             elsif (not $octet{']'}) {
8507 0         0 return join '', $ope, '[', $string, ']';
8508             }
8509             elsif (not $octet{'>'}) {
8510 0         0 return join '', $ope, '<', $string, '>';
8511 0 0       0 }
8512 0         0 else {
8513             for my $char (qw( ! " $ % & * + - . / : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8514             if (not $octet{$char}) {
8515             return join '', $ope, $char, $string, $char;
8516             }
8517             }
8518 0         0 }
8519 0         0  
8520 0         0 # qw/AAA BBB C'CC/ --> ('AAA', 'BBB', 'C\'CC')
8521 0         0 my @string = CORE::split(/\s+/, $string);
8522 0 0       0 for my $string (@string) {
8523 0         0 my @octet = $string =~ /\G ([\x00-\xFF]) /oxmsg;
8524             for my $octet (@octet) {
8525             if ($octet =~ /\A (['\\]) \z/oxms) {
8526 0         0 $octet = '\\' . $1;
8527             }
8528 0         0 }
  0         0  
8529             $string = join '', @octet;
8530             }
8531             return join '', '(', (join ', ', map { "'$_'" } @string), ')';
8532             }
8533              
8534             #
8535 0     108 0 0 # escape here document (<<"HEREDOC", <
8536             #
8537 108         311 sub e_heredoc {
8538             my($string) = @_;
8539 108         180  
8540             $slash = 'm//';
8541 108         452  
8542 108         188 my $metachar = qr/[\@\\|]/oxms; # '|' is for <<`HEREDOC`
8543              
8544             my $left_e = 0;
8545 108         148 my $right_e = 0;
8546              
8547             # split regexp
8548             my @char = $string =~ /\G((?>
8549             [^\x81-\x9F\xE0-\xFC\\\$]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] |
8550             \\x\{ (?>[0-9A-Fa-f]+) \} |
8551             \\o\{ (?>[0-7]+) \} |
8552             \\N\{ (?>[^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} |
8553             \\ $q_char |
8554             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
8555             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
8556             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
8557             \$ (?>\s* [0-9]+) |
8558             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
8559             \$ \$ (?![\w\{]) |
8560             \$ (?>\s*) \$ (?>\s*) $qq_variable |
8561 108         11123 $q_char
8562             ))/oxmsg;
8563              
8564 108 50 66     540 for (my $i=0; $i <= $#char; $i++) {
    50 33        
    100          
    100          
    50          
8565 3225         10580  
8566             # "\L\u" --> "\u\L"
8567             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
8568             @char[$i,$i+1] = @char[$i+1,$i];
8569             }
8570 0         0  
8571             # "\U\l" --> "\l\U"
8572             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
8573             @char[$i,$i+1] = @char[$i+1,$i];
8574             }
8575 0         0  
8576             # octal escape sequence
8577             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
8578             $char[$i] = Esjis::octchr($1);
8579             }
8580 1         3  
8581             # hexadecimal escape sequence
8582             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
8583             $char[$i] = Esjis::hexchr($1);
8584             }
8585 1         4  
8586             # \N{CHARNAME} --> N{CHARNAME}
8587             elsif ($char[$i] =~ /\A \\ ( N\{ ([^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} ) \z/oxms) {
8588 0 100       0 $char[$i] = $1;
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
8589             }
8590              
8591             if (0) {
8592 3225         30056 }
8593 0         0  
8594             # escape character
8595             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
8596             $char[$i] = $1 . '\\' . $2;
8597             }
8598 57 50       233  
8599 72         132 # \u \l \U \L \F \Q \E
8600             elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
8601             if ($right_e < $left_e) {
8602             $char[$i] = '\\' . $char[$i];
8603 0         0 }
8604 0         0 }
8605             elsif ($char[$i] eq '\u') {
8606             $char[$i] = '@{[Esjis::ucfirst qq<';
8607 0         0 $left_e++;
8608 0         0 }
8609             elsif ($char[$i] eq '\l') {
8610             $char[$i] = '@{[Esjis::lcfirst qq<';
8611 0         0 $left_e++;
8612 0         0 }
8613             elsif ($char[$i] eq '\U') {
8614             $char[$i] = '@{[Esjis::uc qq<';
8615 0         0 $left_e++;
8616 6         10 }
8617             elsif ($char[$i] eq '\L') {
8618             $char[$i] = '@{[Esjis::lc qq<';
8619 6         12 $left_e++;
8620 0         0 }
8621             elsif ($char[$i] eq '\F') {
8622             $char[$i] = '@{[Esjis::fc qq<';
8623 0         0 $left_e++;
8624 0         0 }
8625             elsif ($char[$i] eq '\Q') {
8626             $char[$i] = '@{[CORE::quotemeta qq<';
8627 0 50       0 $left_e++;
8628 3         6 }
8629 3         4 elsif ($char[$i] eq '\E') {
8630             if ($right_e < $left_e) {
8631             $char[$i] = '>]}';
8632 3         7 $right_e++;
8633             }
8634             else {
8635             $char[$i] = '';
8636 0         0 }
8637 0 0       0 }
8638 0         0 elsif ($char[$i] eq '\Q') {
8639             while (1) {
8640 0 0       0 if (++$i > $#char) {
8641 0         0 last;
8642             }
8643             if ($char[$i] eq '\E') {
8644             last;
8645             }
8646             }
8647             }
8648             elsif ($char[$i] eq '\E') {
8649             }
8650              
8651             # $0 --> $0
8652             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
8653             }
8654             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
8655             }
8656              
8657             # $$ --> $$
8658             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
8659             }
8660              
8661 0         0 # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
8662             # $1, $2, $3 --> $1, $2, $3 otherwise
8663             elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
8664 0         0 $char[$i] = e_capture($1);
8665             }
8666             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
8667             $char[$i] = e_capture($1);
8668             }
8669 0         0  
8670             # $$foo[ ... ] --> $ $foo->[ ... ]
8671             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
8672             $char[$i] = e_capture($1.'->'.$2);
8673             }
8674 0         0  
8675             # $$foo{ ... } --> $ $foo->{ ... }
8676             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
8677             $char[$i] = e_capture($1.'->'.$2);
8678             }
8679 0         0  
8680             # $$foo
8681             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
8682             $char[$i] = e_capture($1);
8683             }
8684 0         0  
8685             # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Esjis::PREMATCH()
8686             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
8687             $char[$i] = '@{[Esjis::PREMATCH()]}';
8688             }
8689 8         45  
8690             # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Esjis::MATCH()
8691             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
8692             $char[$i] = '@{[Esjis::MATCH()]}';
8693             }
8694 8         48  
8695             # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Esjis::POSTMATCH()
8696             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
8697             $char[$i] = '@{[Esjis::POSTMATCH()]}';
8698             }
8699              
8700             # ${ foo } --> ${ foo }
8701             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ (?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* ) \} \z/oxms) {
8702             }
8703 6         35  
8704             # ${ ... }
8705             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
8706             $char[$i] = e_capture($1);
8707             }
8708 0 100       0 }
8709 108         249  
8710             # return string
8711 3         22 if ($left_e > $right_e) {
8712             return join '', @char, '>]}' x ($left_e - $right_e);
8713             }
8714             return join '', @char;
8715             }
8716              
8717             #
8718 105     1835 0 830 # escape regexp (m//, qr//)
8719 1835   100     7459 #
8720             sub e_qr {
8721 1835         6041 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
8722 1835 50       3326 $modifier ||= '';
8723 1835         4344  
8724 0         0 $modifier =~ tr/p//d;
8725 0 0       0 if ($modifier =~ /([adlu])/oxms) {
8726 0         0 my $line = 0;
8727 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
8728             if ($filename ne __FILE__) {
8729             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
8730 0         0 last;
8731             }
8732             }
8733 0         0 die qq{Unsupported modifier "$1" used at line $line.\n};
8734             }
8735              
8736 1835 100       2735 $slash = 'div';
    100          
8737 1835         5447  
8738 8         8 # literal null string pattern
8739 8         10 if ($string eq '') {
8740             $modifier =~ tr/bB//d;
8741             $modifier =~ tr/i//d;
8742             return join '', $ope, $delimiter, $end_delimiter, $modifier;
8743             }
8744              
8745             # /b /B modifier
8746 8 50       40 elsif ($modifier =~ tr/bB//d) {
8747 240         504  
8748 0         0 # choice again delimiter
  0         0  
8749 0 0       0 if ($delimiter =~ / [\@:] /oxms) {
    0          
    0          
    0          
8750 0         0 my @char = $string =~ /\G ([\x00-\xFF]) /oxmsg;
8751 0         0 my %octet = map {$_ => 1} @char;
8752             if (not $octet{')'}) {
8753             $delimiter = '(';
8754 0         0 $end_delimiter = ')';
8755 0         0 }
8756             elsif (not $octet{'}'}) {
8757             $delimiter = '{';
8758 0         0 $end_delimiter = '}';
8759 0         0 }
8760             elsif (not $octet{']'}) {
8761             $delimiter = '[';
8762 0         0 $end_delimiter = ']';
8763 0         0 }
8764             elsif (not $octet{'>'}) {
8765             $delimiter = '<';
8766 0         0 $end_delimiter = '>';
8767 0 0       0 }
8768 0         0 else {
8769 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8770 0         0 if (not $octet{$char}) {
8771             $delimiter = $char;
8772             $end_delimiter = $char;
8773             last;
8774             }
8775             }
8776 0 100 100     0 }
8777 240         1103 }
8778              
8779             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
8780 90         466 return join '', $ope, $delimiter, $string, $matched, $end_delimiter, $modifier;
8781             }
8782             else {
8783             return join '', $ope, $delimiter, '(?:', $string, ')', $matched, $end_delimiter, $modifier;
8784 150 100       873 }
8785 1587         3631 }
8786              
8787             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
8788 1587         5759 my $metachar = qr/[\@\\|[\]{^]/oxms;
8789              
8790             # split regexp
8791             my @char = $string =~ /\G((?>
8792             [^\x81-\x9F\xE0-\xFC\\\$\@\[\(]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] |
8793             \\x (?>[0-9A-Fa-f]{1,2}) |
8794             \\ (?>[0-7]{2,3}) |
8795             \\c [\x40-\x5F] |
8796             \\x\{ (?>[0-9A-Fa-f]+) \} |
8797             \\o\{ (?>[0-7]+) \} |
8798             \\[bBNpP]\{ (?>[^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} |
8799             \\ $q_char |
8800             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
8801             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
8802             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
8803             [\$\@] $qq_variable |
8804             \$ (?>\s* [0-9]+) |
8805             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
8806             \$ \$ (?![\w\{]) |
8807             \$ (?>\s*) \$ (?>\s*) $qq_variable |
8808             \[\^ |
8809             \[\: (?>[a-z]+) :\] |
8810             \[\:\^ (?>[a-z]+) :\] |
8811             \(\? |
8812             $q_char
8813 1587 50       135433 ))/oxmsg;
8814 1587         6708  
  0         0  
8815 0 0       0 # choice again delimiter
    0          
    0          
    0          
8816 0         0 if ($delimiter =~ / [\@:] /oxms) {
8817 0         0 my %octet = map {$_ => 1} @char;
8818             if (not $octet{')'}) {
8819             $delimiter = '(';
8820 0         0 $end_delimiter = ')';
8821 0         0 }
8822             elsif (not $octet{'}'}) {
8823             $delimiter = '{';
8824 0         0 $end_delimiter = '}';
8825 0         0 }
8826             elsif (not $octet{']'}) {
8827             $delimiter = '[';
8828 0         0 $end_delimiter = ']';
8829 0         0 }
8830             elsif (not $octet{'>'}) {
8831             $delimiter = '<';
8832 0         0 $end_delimiter = '>';
8833 0 0       0 }
8834 0         0 else {
8835 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8836 0         0 if (not $octet{$char}) {
8837             $delimiter = $char;
8838             $end_delimiter = $char;
8839             last;
8840             }
8841             }
8842 0         0 }
8843 1587         2473 }
8844 1587         2240  
8845             my $left_e = 0;
8846             my $right_e = 0;
8847 1587 50 66     3928 for (my $i=0; $i <= $#char; $i++) {
    50 66        
    100          
    100          
    100          
    100          
8848 5437         27002  
8849             # "\L\u" --> "\u\L"
8850             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
8851             @char[$i,$i+1] = @char[$i+1,$i];
8852             }
8853 0         0  
8854             # "\U\l" --> "\l\U"
8855             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
8856             @char[$i,$i+1] = @char[$i+1,$i];
8857             }
8858 0         0  
8859             # octal escape sequence
8860             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
8861             $char[$i] = Esjis::octchr($1);
8862             }
8863 1         4  
8864             # hexadecimal escape sequence
8865             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
8866             $char[$i] = Esjis::hexchr($1);
8867             }
8868              
8869             # \b{...} --> b\{...}
8870             # \B{...} --> B\{...}
8871             # \N{CHARNAME} --> N\{CHARNAME}
8872 1         4 # \p{PROPERTY} --> p\{PROPERTY}
8873             # \P{PROPERTY} --> P\{PROPERTY}
8874             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} ) \z/oxms) {
8875             $char[$i] = $1 . '\\' . $2;
8876             }
8877 6         19  
8878             # \p, \P, \X --> p, P, X
8879             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
8880 4 100 100     12 $char[$i] = $1;
    100 100        
    100 100        
    100          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
8881             }
8882              
8883             if (0) {
8884 5437         36681 }
8885 0         0  
8886             # escape last octet of multiple-octet
8887             elsif ($char[$i] =~ /\A \\? ([\x80-\xFF].*) ($metachar|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
8888             $char[$i] = $1 . '\\' . $2;
8889             }
8890 77 50 33     344  
    50 33        
    50 33        
      33        
      66        
      33        
8891 6         169 # join separated multiple-octet
8892             elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
8893             if ( ($i+3 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+3]) == 3) and (CORE::eval(sprintf '"%s%s%s%s"', @char[$i..$i+3]) =~ /\A $q_char \z/oxms)) {
8894 0         0 $char[$i] .= join '', splice @char, $i+1, 3;
8895             }
8896             elsif (($i+2 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+2]) == 2) and (CORE::eval(sprintf '"%s%s%s"', @char[$i..$i+2]) =~ /\A $q_char \z/oxms)) {
8897 0         0 $char[$i] .= join '', splice @char, $i+1, 2;
8898             }
8899             elsif (($i+1 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, $char[$i+1 ]) == 1) and (CORE::eval(sprintf '"%s%s"', @char[$i..$i+1]) =~ /\A $q_char \z/oxms)) {
8900             $char[$i] .= join '', splice @char, $i+1, 1;
8901             }
8902             }
8903 0         0  
8904             # open character class [...]
8905             elsif ($char[$i] eq '[') {
8906             my $left = $i;
8907              
8908 586 100       853 # [] make die "Unmatched [] in regexp ...\n"
8909 586         1444 # (and so on)
8910              
8911             if ($char[$i+1] eq ']') {
8912 3         4 $i++;
8913 586 50       729 }
8914 2583         3510  
8915             while (1) {
8916 0 100       0 if (++$i > $#char) {
8917 2583         3997 die __FILE__, ": Unmatched [] in regexp\n";
8918             }
8919             if ($char[$i] eq ']') {
8920 586 100       738 my $right = $i;
8921 586         3249  
  90         197  
8922             # [...]
8923             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
8924 270         440 splice @char, $left, $right-$left+1, sprintf(q{@{[Esjis::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
8925             }
8926             else {
8927 496         2307 splice @char, $left, $right-$left+1, Esjis::charlist_qr(@char[$left+1..$right-1], $modifier);
8928 586         1050 }
8929              
8930             $i = $left;
8931             last;
8932             }
8933             }
8934             }
8935 586         1542  
8936             # open character class [^...]
8937             elsif ($char[$i] eq '[^') {
8938             my $left = $i;
8939              
8940 328 100       465 # [^] make die "Unmatched [] in regexp ...\n"
8941 328         697 # (and so on)
8942              
8943             if ($char[$i+1] eq ']') {
8944 5         24 $i++;
8945 328 50       365 }
8946 1447         2003  
8947             while (1) {
8948 0 100       0 if (++$i > $#char) {
8949 1447         2306 die __FILE__, ": Unmatched [] in regexp\n";
8950             }
8951             if ($char[$i] eq ']') {
8952 328 100       356 my $right = $i;
8953 328         1550  
  90         208  
8954             # [^...]
8955             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
8956 270         533 splice @char, $left, $right-$left+1, sprintf(q{@{[Esjis::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
8957             }
8958             else {
8959 238         943 splice @char, $left, $right-$left+1, Esjis::charlist_not_qr(@char[$left+1..$right-1], $modifier);
8960 328         562 }
8961              
8962             $i = $left;
8963             last;
8964             }
8965             }
8966             }
8967 328         872  
8968             # rewrite character class or escape character
8969             elsif (my $char = character_class($char[$i],$modifier)) {
8970             $char[$i] = $char;
8971             }
8972 215 50       648  
8973 238         411 # /i modifier
8974             elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Esjis::uc($char[$i]) ne Esjis::fc($char[$i]))) {
8975             if (CORE::length(Esjis::fc($char[$i])) == 1) {
8976 238         442 $char[$i] = '[' . Esjis::uc($char[$i]) . Esjis::fc($char[$i]) . ']';
8977             }
8978             else {
8979             $char[$i] = '(?:' . Esjis::uc($char[$i]) . '|' . Esjis::fc($char[$i]) . ')';
8980             }
8981             }
8982 0 50       0  
8983 1         6 # \u \l \U \L \F \Q \E
8984             elsif ($char[$i] =~ /\A [<>] \z/oxms) {
8985             if ($right_e < $left_e) {
8986             $char[$i] = '\\' . $char[$i];
8987 0         0 }
8988 0         0 }
8989             elsif ($char[$i] eq '\u') {
8990             $char[$i] = '@{[Esjis::ucfirst qq<';
8991 0         0 $left_e++;
8992 0         0 }
8993             elsif ($char[$i] eq '\l') {
8994             $char[$i] = '@{[Esjis::lcfirst qq<';
8995 0         0 $left_e++;
8996 1         3 }
8997             elsif ($char[$i] eq '\U') {
8998             $char[$i] = '@{[Esjis::uc qq<';
8999 1         3 $left_e++;
9000 1         111 }
9001             elsif ($char[$i] eq '\L') {
9002             $char[$i] = '@{[Esjis::lc qq<';
9003 1         6 $left_e++;
9004 9         16 }
9005             elsif ($char[$i] eq '\F') {
9006             $char[$i] = '@{[Esjis::fc qq<';
9007 9         20 $left_e++;
9008 22         42 }
9009             elsif ($char[$i] eq '\Q') {
9010             $char[$i] = '@{[CORE::quotemeta qq<';
9011 22 50       91 $left_e++;
9012 33         75 }
9013 33         45 elsif ($char[$i] eq '\E') {
9014             if ($right_e < $left_e) {
9015             $char[$i] = '>]}';
9016 33         247 $right_e++;
9017             }
9018             else {
9019             $char[$i] = '';
9020 0         0 }
9021 0 0       0 }
9022 0         0 elsif ($char[$i] eq '\Q') {
9023             while (1) {
9024 0 0       0 if (++$i > $#char) {
9025 0         0 last;
9026             }
9027             if ($char[$i] eq '\E') {
9028             last;
9029             }
9030             }
9031             }
9032             elsif ($char[$i] eq '\E') {
9033             }
9034 0 0       0  
9035 0         0 # $0 --> $0
9036             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
9037             if ($ignorecase) {
9038             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9039 0 0       0 }
9040 0         0 }
9041             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
9042             if ($ignorecase) {
9043             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9044             }
9045             }
9046              
9047             # $$ --> $$
9048             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
9049             }
9050              
9051 0         0 # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
9052 0 0       0 # $1, $2, $3 --> $1, $2, $3 otherwise
9053 0         0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
9054             $char[$i] = e_capture($1);
9055             if ($ignorecase) {
9056             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9057 0         0 }
9058 0 0       0 }
9059 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
9060             $char[$i] = e_capture($1);
9061             if ($ignorecase) {
9062             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9063             }
9064             }
9065 0         0  
9066 0 0       0 # $$foo[ ... ] --> $ $foo->[ ... ]
9067 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
9068             $char[$i] = e_capture($1.'->'.$2);
9069             if ($ignorecase) {
9070             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9071             }
9072             }
9073 0         0  
9074 0 0       0 # $$foo{ ... } --> $ $foo->{ ... }
9075 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
9076             $char[$i] = e_capture($1.'->'.$2);
9077             if ($ignorecase) {
9078             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9079             }
9080             }
9081 0         0  
9082 0 0       0 # $$foo
9083 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
9084             $char[$i] = e_capture($1);
9085             if ($ignorecase) {
9086             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9087             }
9088             }
9089 0 50       0  
9090 8         23 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Esjis::PREMATCH()
9091             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
9092             if ($ignorecase) {
9093 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::PREMATCH())]}';
9094             }
9095             else {
9096             $char[$i] = '@{[Esjis::PREMATCH()]}';
9097             }
9098             }
9099 8 50       27  
9100 8         38 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Esjis::MATCH()
9101             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
9102             if ($ignorecase) {
9103 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::MATCH())]}';
9104             }
9105             else {
9106             $char[$i] = '@{[Esjis::MATCH()]}';
9107             }
9108             }
9109 8 50       28  
9110 6         19 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Esjis::POSTMATCH()
9111             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
9112             if ($ignorecase) {
9113 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::POSTMATCH())]}';
9114             }
9115             else {
9116             $char[$i] = '@{[Esjis::POSTMATCH()]}';
9117             }
9118             }
9119 6 0       17  
9120 0         0 # ${ foo }
9121             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
9122             if ($ignorecase) {
9123             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9124             }
9125             }
9126 0         0  
9127 0 0       0 # ${ ... }
9128 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
9129             $char[$i] = e_capture($1);
9130             if ($ignorecase) {
9131             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9132             }
9133             }
9134 0         0  
9135 31 100       95 # $scalar or @array
9136 31         106 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
9137             $char[$i] = e_string($char[$i]);
9138             if ($ignorecase) {
9139             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9140             }
9141             }
9142 4 100 66     15  
    50          
9143             # quote character before ? + * {
9144             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
9145 188         1460 if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
9146 0 0       0 }
9147 0         0 elsif (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
9148             my $char = $char[$i-1];
9149             if ($char[$i] eq '{') {
9150 0         0 die __FILE__, qq{: "MULTIBYTE{n}" should be "(MULTIBYTE){n}" in m?? (and shift \$1,\$2,\$3,...) ($char){n}\n};
9151             }
9152             else {
9153             die __FILE__, qq{: "MULTIBYTE$char[$i]" should be "(MULTIBYTE)$char[$i]" in m?? (and shift \$1,\$2,\$3,...) ($char)$char[$i]\n};
9154 0         0 }
9155             }
9156             else {
9157             $char[$i-1] = '(?:' . $char[$i-1] . ')';
9158             }
9159             }
9160 187         763 }
9161 1587 50       2937  
9162 1587 0 0     3750 # make regexp string
9163 0         0 $modifier =~ tr/i//d;
9164             if ($left_e > $right_e) {
9165             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
9166 0         0 return join '', $ope, $delimiter, $anchor, @char, '>]}' x ($left_e - $right_e), $matched, $end_delimiter, $modifier;
9167             }
9168             else {
9169 0 100 100     0 return join '', $ope, $delimiter, $anchor, '(?:', @char, '>]}' x ($left_e - $right_e), ')', $matched, $end_delimiter, $modifier;
9170 1587         7895 }
9171             }
9172             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
9173 94         723 return join '', $ope, $delimiter, $anchor, @char, $matched, $end_delimiter, $modifier;
9174             }
9175             else {
9176             return join '', $ope, $delimiter, $anchor, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9177             }
9178             }
9179              
9180             #
9181 1493     540 0 13094 # double quote stuff
9182             #
9183             sub qq_stuff {
9184 540 100       770 my($delimiter,$end_delimiter,$stuff) = @_;
9185 540         1090  
9186             # scalar variable or array variable
9187             if ($stuff =~ /\A [\$\@] /oxms) {
9188             return $stuff;
9189 300         1015 }
  240         574  
9190 280         740  
9191 240 50       553 # quote by delimiter
9192 240 50       423 my %octet = map {$_ => 1} ($stuff =~ /\G ([\x00-\xFF]) /oxmsg);
9193 240 50       385 for my $char (qw( ! " $ % & * + - . / : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
9194 240         395 next if $char eq $delimiter;
9195             next if $char eq $end_delimiter;
9196             if (not $octet{$char}) {
9197 240         931 return join '', 'qq', $char, $stuff, $char;
9198             }
9199             }
9200             return join '', 'qq', '<', $stuff, '>';
9201             }
9202              
9203             #
9204 0     163 0 0 # escape regexp (m'', qr'', and m''b, qr''b)
9205 163   100     903 #
9206             sub e_qr_q {
9207 163         508 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9208 163 50       430 $modifier ||= '';
9209 163         479  
9210 0         0 $modifier =~ tr/p//d;
9211 0 0       0 if ($modifier =~ /([adlu])/oxms) {
9212 0         0 my $line = 0;
9213 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
9214             if ($filename ne __FILE__) {
9215             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
9216 0         0 last;
9217             }
9218             }
9219 0         0 die qq{Unsupported modifier "$1" used at line $line.\n};
9220             }
9221              
9222 163 100       233 $slash = 'div';
    100          
9223 163         458  
9224 8         9 # literal null string pattern
9225 8         8 if ($string eq '') {
9226             $modifier =~ tr/bB//d;
9227             $modifier =~ tr/i//d;
9228             return join '', $ope, $delimiter, $end_delimiter, $modifier;
9229             }
9230 8         37  
9231             # with /b /B modifier
9232             elsif ($modifier =~ tr/bB//d) {
9233             return e_qr_qb($ope,$delimiter,$end_delimiter,$string,$modifier);
9234             }
9235 89         214  
9236             # without /b /B modifier
9237             else {
9238             return e_qr_qt($ope,$delimiter,$end_delimiter,$string,$modifier);
9239             }
9240             }
9241              
9242             #
9243 66     66 0 187 # escape regexp (m'', qr'')
9244             #
9245 66 100       216 sub e_qr_qt {
9246             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9247              
9248 66         201 my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
9249              
9250             # split regexp
9251             my @char = $string =~ /\G((?>
9252             [^\x81-\x9F\xE0-\xFC\\\[\$\@\/] |
9253             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
9254             \[\^ |
9255             \[\: (?>[a-z]+) \:\] |
9256             \[\:\^ (?>[a-z]+) \:\] |
9257             [\$\@\/] |
9258             \\ (?:$q_char) |
9259             (?:$q_char)
9260 66         709 ))/oxmsg;
9261 66 100 100     250  
    50 100        
    50 66        
    50          
    50          
    100          
    50          
9262             # unescape character
9263             for (my $i=0; $i <= $#char; $i++) {
9264             if (0) {
9265 79         918 }
9266 0         0  
9267             # escape last octet of multiple-octet
9268             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\\|\[\{\^]|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
9269             $char[$i] = $1 . '\\' . $2;
9270             }
9271 2         12  
9272 0 0       0 # open character class [...]
9273 0         0 elsif ($char[$i] eq '[') {
9274             my $left = $i;
9275 0         0 if ($char[$i+1] eq ']') {
9276 0 0       0 $i++;
9277 0         0 }
9278             while (1) {
9279 0 0       0 if (++$i > $#char) {
9280 0         0 die __FILE__, ": Unmatched [] in regexp\n";
9281             }
9282             if ($char[$i] eq ']') {
9283 0         0 my $right = $i;
9284              
9285 0         0 # [...]
9286 0         0 splice @char, $left, $right-$left+1, Esjis::charlist_qr(@char[$left+1..$right-1], $modifier);
9287              
9288             $i = $left;
9289             last;
9290             }
9291             }
9292             }
9293 0         0  
9294 0 0       0 # open character class [^...]
9295 0         0 elsif ($char[$i] eq '[^') {
9296             my $left = $i;
9297 0         0 if ($char[$i+1] eq ']') {
9298 0 0       0 $i++;
9299 0         0 }
9300             while (1) {
9301 0 0       0 if (++$i > $#char) {
9302 0         0 die __FILE__, ": Unmatched [] in regexp\n";
9303             }
9304             if ($char[$i] eq ']') {
9305 0         0 my $right = $i;
9306              
9307 0         0 # [^...]
9308 0         0 splice @char, $left, $right-$left+1, Esjis::charlist_not_qr(@char[$left+1..$right-1], $modifier);
9309              
9310             $i = $left;
9311             last;
9312             }
9313             }
9314             }
9315 0         0  
9316             # escape $ @ / and \
9317             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
9318             $char[$i] = '\\' . $char[$i];
9319             }
9320 0         0  
9321             # rewrite character class or escape character
9322             elsif (my $char = character_class($char[$i],$modifier)) {
9323             $char[$i] = $char;
9324             }
9325 0 50       0  
9326 16         68 # /i modifier
9327             elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Esjis::uc($char[$i]) ne Esjis::fc($char[$i]))) {
9328             if (CORE::length(Esjis::fc($char[$i])) == 1) {
9329 16         43 $char[$i] = '[' . Esjis::uc($char[$i]) . Esjis::fc($char[$i]) . ']';
9330             }
9331             else {
9332             $char[$i] = '(?:' . Esjis::uc($char[$i]) . '|' . Esjis::fc($char[$i]) . ')';
9333             }
9334             }
9335 0 0       0  
9336             # quote character before ? + * {
9337             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
9338 0         0 if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
9339             }
9340             else {
9341             $char[$i-1] = '(?:' . $char[$i-1] . ')';
9342             }
9343 0         0 }
9344 66         190 }
9345              
9346 66         108 $delimiter = '/';
9347 66         105 $end_delimiter = '/';
9348              
9349             $modifier =~ tr/i//d;
9350             return join '', $ope, $delimiter, $anchor, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9351             }
9352              
9353             #
9354 66     89 0 472 # escape regexp (m''b, qr''b)
9355             #
9356             sub e_qr_qb {
9357 89         215 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9358              
9359             # split regexp
9360 89         366 my @char = $string =~ /\G ((?>[^\\]|\\\\|[\x00-\xFF])) /oxmsg;
9361 89 50       270  
    50          
9362             # unescape character
9363             for (my $i=0; $i <= $#char; $i++) {
9364             if (0) {
9365 199         677 }
9366              
9367             # remain \\
9368             elsif ($char[$i] eq '\\\\') {
9369             }
9370 0         0  
9371             # escape $ @ / and \
9372             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
9373             $char[$i] = '\\' . $char[$i];
9374 0         0 }
9375 89         136 }
9376 89         120  
9377             $delimiter = '/';
9378             $end_delimiter = '/';
9379             return join '', $ope, $delimiter, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9380             }
9381              
9382             #
9383 89     195 0 542 # escape regexp (s/here//)
9384 195   100     638 #
9385             sub e_s1 {
9386 195         716 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9387 195 50       325 $modifier ||= '';
9388 195         569  
9389 0         0 $modifier =~ tr/p//d;
9390 0 0       0 if ($modifier =~ /([adlu])/oxms) {
9391 0         0 my $line = 0;
9392 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
9393             if ($filename ne __FILE__) {
9394             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
9395 0         0 last;
9396             }
9397             }
9398 0         0 die qq{Unsupported modifier "$1" used at line $line.\n};
9399             }
9400              
9401 195 100       344 $slash = 'div';
    100          
9402 195         674  
9403 8         10 # literal null string pattern
9404 8         10 if ($string eq '') {
9405             $modifier =~ tr/bB//d;
9406             $modifier =~ tr/i//d;
9407             return join '', $ope, $delimiter, $end_delimiter, $modifier;
9408             }
9409              
9410             # /b /B modifier
9411 8 50       54 elsif ($modifier =~ tr/bB//d) {
9412 44         97  
9413 0         0 # choice again delimiter
  0         0  
9414 0 0       0 if ($delimiter =~ / [\@:] /oxms) {
    0          
    0          
    0          
9415 0         0 my @char = $string =~ /\G ([\x00-\xFF]) /oxmsg;
9416 0         0 my %octet = map {$_ => 1} @char;
9417             if (not $octet{')'}) {
9418             $delimiter = '(';
9419 0         0 $end_delimiter = ')';
9420 0         0 }
9421             elsif (not $octet{'}'}) {
9422             $delimiter = '{';
9423 0         0 $end_delimiter = '}';
9424 0         0 }
9425             elsif (not $octet{']'}) {
9426             $delimiter = '[';
9427 0         0 $end_delimiter = ']';
9428 0         0 }
9429             elsif (not $octet{'>'}) {
9430             $delimiter = '<';
9431 0         0 $end_delimiter = '>';
9432 0 0       0 }
9433 0         0 else {
9434 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
9435 0         0 if (not $octet{$char}) {
9436             $delimiter = $char;
9437             $end_delimiter = $char;
9438             last;
9439             }
9440             }
9441 0         0 }
9442 44         54 }
9443 44         53  
9444             my $prematch = '';
9445             $prematch = q{(\G[\x00-\xFF]*?)};
9446 44 100       268 return join '', $ope, $delimiter, $prematch, '(?:', $string, ')', $matched, $end_delimiter, $modifier;
9447 143         426 }
9448              
9449             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
9450 143         626 my $metachar = qr/[\@\\|[\]{^]/oxms;
9451              
9452             # split regexp
9453             my @char = $string =~ /\G((?>
9454             [^\x81-\x9F\xE0-\xFC\\\$\@\[\(]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] |
9455             \\ (?>[1-9][0-9]*) |
9456             \\g (?>\s*) (?>[1-9][0-9]*) |
9457             \\g (?>\s*) \{ (?>\s*) (?>[1-9][0-9]*) (?>\s*) \} |
9458             \\g (?>\s*) \{ (?>\s*) - (?>\s*) (?>[1-9][0-9]*) (?>\s*) \} |
9459             \\x (?>[0-9A-Fa-f]{1,2}) |
9460             \\ (?>[0-7]{2,3}) |
9461             \\c [\x40-\x5F] |
9462             \\x\{ (?>[0-9A-Fa-f]+) \} |
9463             \\o\{ (?>[0-7]+) \} |
9464             \\[bBNpP]\{ (?>[^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} |
9465             \\ $q_char |
9466             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
9467             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
9468             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
9469             [\$\@] $qq_variable |
9470             \$ (?>\s* [0-9]+) |
9471             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
9472             \$ \$ (?![\w\{]) |
9473             \$ (?>\s*) \$ (?>\s*) $qq_variable |
9474             \[\^ |
9475             \[\: (?>[a-z]+) :\] |
9476             \[\:\^ (?>[a-z]+) :\] |
9477             \(\? |
9478             $q_char
9479 143 50       38732 ))/oxmsg;
9480 143         1208  
  0         0  
9481 0 0       0 # choice again delimiter
    0          
    0          
    0          
9482 0         0 if ($delimiter =~ / [\@:] /oxms) {
9483 0         0 my %octet = map {$_ => 1} @char;
9484             if (not $octet{')'}) {
9485             $delimiter = '(';
9486 0         0 $end_delimiter = ')';
9487 0         0 }
9488             elsif (not $octet{'}'}) {
9489             $delimiter = '{';
9490 0         0 $end_delimiter = '}';
9491 0         0 }
9492             elsif (not $octet{']'}) {
9493             $delimiter = '[';
9494 0         0 $end_delimiter = ']';
9495 0         0 }
9496             elsif (not $octet{'>'}) {
9497             $delimiter = '<';
9498 0         0 $end_delimiter = '>';
9499 0 0       0 }
9500 0         0 else {
9501 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
9502 0         0 if (not $octet{$char}) {
9503             $delimiter = $char;
9504             $end_delimiter = $char;
9505             last;
9506             }
9507             }
9508             }
9509 0         0 }
  143         396  
9510              
9511 477         1550 # count '('
9512 143         372 my $parens = grep { $_ eq '(' } @char;
9513 143         206  
9514             my $left_e = 0;
9515             my $right_e = 0;
9516 143 50 33     519 for (my $i=0; $i <= $#char; $i++) {
    50 33        
    100          
    100          
    50          
    50          
9517 398         2501  
9518             # "\L\u" --> "\u\L"
9519             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
9520             @char[$i,$i+1] = @char[$i+1,$i];
9521             }
9522 0         0  
9523             # "\U\l" --> "\l\U"
9524             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
9525             @char[$i,$i+1] = @char[$i+1,$i];
9526             }
9527 0         0  
9528             # octal escape sequence
9529             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
9530             $char[$i] = Esjis::octchr($1);
9531             }
9532 1         13  
9533             # hexadecimal escape sequence
9534             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
9535             $char[$i] = Esjis::hexchr($1);
9536             }
9537              
9538             # \b{...} --> b\{...}
9539             # \B{...} --> B\{...}
9540             # \N{CHARNAME} --> N\{CHARNAME}
9541 1         3 # \p{PROPERTY} --> p\{PROPERTY}
9542             # \P{PROPERTY} --> P\{PROPERTY}
9543             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} ) \z/oxms) {
9544             $char[$i] = $1 . '\\' . $2;
9545             }
9546 0         0  
9547             # \p, \P, \X --> p, P, X
9548             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
9549 0 100 100     0 $char[$i] = $1;
    50 100        
    100 100        
    50          
    100          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
9550             }
9551              
9552             if (0) {
9553 398         5189 }
9554 0         0  
9555             # escape last octet of multiple-octet
9556             elsif ($char[$i] =~ /\A \\? ([\x80-\xFF].*) ($metachar|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
9557             $char[$i] = $1 . '\\' . $2;
9558             }
9559 23 0 0     118  
    0 0        
    0 0        
      0        
      0        
      0        
9560 0         0 # join separated multiple-octet
9561             elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
9562             if ( ($i+3 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+3]) == 3) and (CORE::eval(sprintf '"%s%s%s%s"', @char[$i..$i+3]) =~ /\A $q_char \z/oxms)) {
9563 0         0 $char[$i] .= join '', splice @char, $i+1, 3;
9564             }
9565             elsif (($i+2 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+2]) == 2) and (CORE::eval(sprintf '"%s%s%s"', @char[$i..$i+2]) =~ /\A $q_char \z/oxms)) {
9566 0         0 $char[$i] .= join '', splice @char, $i+1, 2;
9567             }
9568             elsif (($i+1 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, $char[$i+1 ]) == 1) and (CORE::eval(sprintf '"%s%s"', @char[$i..$i+1]) =~ /\A $q_char \z/oxms)) {
9569             $char[$i] .= join '', splice @char, $i+1, 1;
9570             }
9571             }
9572 0         0  
9573 20 50       44 # open character class [...]
9574 20         62 elsif ($char[$i] eq '[') {
9575             my $left = $i;
9576 0         0 if ($char[$i+1] eq ']') {
9577 20 50       31 $i++;
9578 79         131 }
9579             while (1) {
9580 0 100       0 if (++$i > $#char) {
9581 79         292 die __FILE__, ": Unmatched [] in regexp\n";
9582             }
9583             if ($char[$i] eq ']') {
9584 20 50       40 my $right = $i;
9585 20         144  
  0         0  
9586             # [...]
9587             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
9588 0         0 splice @char, $left, $right-$left+1, sprintf(q{@{[Esjis::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
9589             }
9590             else {
9591 20         101 splice @char, $left, $right-$left+1, Esjis::charlist_qr(@char[$left+1..$right-1], $modifier);
9592 20         44 }
9593              
9594             $i = $left;
9595             last;
9596             }
9597             }
9598             }
9599 20         63  
9600 0 0       0 # open character class [^...]
9601 0         0 elsif ($char[$i] eq '[^') {
9602             my $left = $i;
9603 0         0 if ($char[$i+1] eq ']') {
9604 0 0       0 $i++;
9605 0         0 }
9606             while (1) {
9607 0 0       0 if (++$i > $#char) {
9608 0         0 die __FILE__, ": Unmatched [] in regexp\n";
9609             }
9610             if ($char[$i] eq ']') {
9611 0 0       0 my $right = $i;
9612 0         0  
  0         0  
9613             # [^...]
9614             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
9615 0         0 splice @char, $left, $right-$left+1, sprintf(q{@{[Esjis::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
9616             }
9617             else {
9618 0         0 splice @char, $left, $right-$left+1, Esjis::charlist_not_qr(@char[$left+1..$right-1], $modifier);
9619 0         0 }
9620              
9621             $i = $left;
9622             last;
9623             }
9624             }
9625             }
9626 0         0  
9627             # rewrite character class or escape character
9628             elsif (my $char = character_class($char[$i],$modifier)) {
9629             $char[$i] = $char;
9630             }
9631 11 50       27  
9632 11         22 # /i modifier
9633             elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Esjis::uc($char[$i]) ne Esjis::fc($char[$i]))) {
9634             if (CORE::length(Esjis::fc($char[$i])) == 1) {
9635 11         24 $char[$i] = '[' . Esjis::uc($char[$i]) . Esjis::fc($char[$i]) . ']';
9636             }
9637             else {
9638             $char[$i] = '(?:' . Esjis::uc($char[$i]) . '|' . Esjis::fc($char[$i]) . ')';
9639             }
9640             }
9641 0 50       0  
9642 8         28 # \u \l \U \L \F \Q \E
9643             elsif ($char[$i] =~ /\A [<>] \z/oxms) {
9644             if ($right_e < $left_e) {
9645             $char[$i] = '\\' . $char[$i];
9646 0         0 }
9647 0         0 }
9648             elsif ($char[$i] eq '\u') {
9649             $char[$i] = '@{[Esjis::ucfirst qq<';
9650 0         0 $left_e++;
9651 0         0 }
9652             elsif ($char[$i] eq '\l') {
9653             $char[$i] = '@{[Esjis::lcfirst qq<';
9654 0         0 $left_e++;
9655 0         0 }
9656             elsif ($char[$i] eq '\U') {
9657             $char[$i] = '@{[Esjis::uc qq<';
9658 0         0 $left_e++;
9659 0         0 }
9660             elsif ($char[$i] eq '\L') {
9661             $char[$i] = '@{[Esjis::lc qq<';
9662 0         0 $left_e++;
9663 0         0 }
9664             elsif ($char[$i] eq '\F') {
9665             $char[$i] = '@{[Esjis::fc qq<';
9666 0         0 $left_e++;
9667 7         14 }
9668             elsif ($char[$i] eq '\Q') {
9669             $char[$i] = '@{[CORE::quotemeta qq<';
9670 7 50       17 $left_e++;
9671 7         16 }
9672 7         9 elsif ($char[$i] eq '\E') {
9673             if ($right_e < $left_e) {
9674             $char[$i] = '>]}';
9675 7         17 $right_e++;
9676             }
9677             else {
9678             $char[$i] = '';
9679 0         0 }
9680 0 0       0 }
9681 0         0 elsif ($char[$i] eq '\Q') {
9682             while (1) {
9683 0 0       0 if (++$i > $#char) {
9684 0         0 last;
9685             }
9686             if ($char[$i] eq '\E') {
9687             last;
9688             }
9689             }
9690             }
9691             elsif ($char[$i] eq '\E') {
9692             }
9693              
9694             # \0 --> \0
9695             elsif ($char[$i] =~ /\A \\ (?>\s*) 0 \z/oxms) {
9696             }
9697              
9698             # \g{N}, \g{-N}
9699              
9700             # P.108 Using Simple Patterns
9701             # in Chapter 7: In the World of Regular Expressions
9702             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
9703              
9704             # P.221 Capturing
9705             # in Chapter 5: Pattern Matching
9706             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
9707              
9708             # \g{-1}, \g{-2}, \g{-3} --> \g{-1}, \g{-2}, \g{-3}
9709             elsif ($char[$i] =~ /\A \\g (?>\s*) \{ (?>\s*) - (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
9710             }
9711 0 0       0  
9712 0         0 # \g{1}, \g{2}, \g{3} --> \g{2}, \g{3}, \g{4} (only when multibyte anchoring is enable)
9713             elsif ($char[$i] =~ /\A \\g (?>\s*) \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
9714             if ($1 <= $parens) {
9715             $char[$i] = '\\g{' . ($1 + 1) . '}';
9716             }
9717             }
9718 0 0       0  
9719 0         0 # \g1, \g2, \g3 --> \g2, \g3, \g4 (only when multibyte anchoring is enable)
9720             elsif ($char[$i] =~ /\A \\g (?>\s*) ((?>[1-9][0-9]*)) \z/oxms) {
9721             if ($1 <= $parens) {
9722             $char[$i] = '\\g' . ($1 + 1);
9723             }
9724             }
9725 0 0       0  
9726 0         0 # \1, \2, \3 --> \2, \3, \4 (only when multibyte anchoring is enable)
9727             elsif ($char[$i] =~ /\A \\ (?>\s*) ((?>[1-9][0-9]*)) \z/oxms) {
9728             if ($1 <= $parens) {
9729             $char[$i] = '\\' . ($1 + 1);
9730             }
9731             }
9732 0 0       0  
9733 0         0 # $0 --> $0
9734             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
9735             if ($ignorecase) {
9736             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9737 0 0       0 }
9738 0         0 }
9739             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
9740             if ($ignorecase) {
9741             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9742             }
9743             }
9744              
9745             # $$ --> $$
9746             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
9747             }
9748              
9749 0         0 # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
9750 0 0       0 # $1, $2, $3 --> $1, $2, $3 otherwise
9751 0         0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
9752             $char[$i] = e_capture($1);
9753             if ($ignorecase) {
9754             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9755 0         0 }
9756 0 0       0 }
9757 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
9758             $char[$i] = e_capture($1);
9759             if ($ignorecase) {
9760             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9761             }
9762             }
9763 0         0  
9764 0 0       0 # $$foo[ ... ] --> $ $foo->[ ... ]
9765 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
9766             $char[$i] = e_capture($1.'->'.$2);
9767             if ($ignorecase) {
9768             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9769             }
9770             }
9771 0         0  
9772 0 0       0 # $$foo{ ... } --> $ $foo->{ ... }
9773 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
9774             $char[$i] = e_capture($1.'->'.$2);
9775             if ($ignorecase) {
9776             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9777             }
9778             }
9779 0         0  
9780 0 0       0 # $$foo
9781 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
9782             $char[$i] = e_capture($1);
9783             if ($ignorecase) {
9784             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9785             }
9786             }
9787 0 50       0  
9788 4         14 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Esjis::PREMATCH()
9789             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
9790             if ($ignorecase) {
9791 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::PREMATCH())]}';
9792             }
9793             else {
9794             $char[$i] = '@{[Esjis::PREMATCH()]}';
9795             }
9796             }
9797 4 50       16  
9798 4         13 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Esjis::MATCH()
9799             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
9800             if ($ignorecase) {
9801 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::MATCH())]}';
9802             }
9803             else {
9804             $char[$i] = '@{[Esjis::MATCH()]}';
9805             }
9806             }
9807 4 50       16  
9808 3         11 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Esjis::POSTMATCH()
9809             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
9810             if ($ignorecase) {
9811 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::POSTMATCH())]}';
9812             }
9813             else {
9814             $char[$i] = '@{[Esjis::POSTMATCH()]}';
9815             }
9816             }
9817 3 0       11  
9818 0         0 # ${ foo }
9819             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
9820             if ($ignorecase) {
9821             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9822             }
9823             }
9824 0         0  
9825 0 0       0 # ${ ... }
9826 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
9827             $char[$i] = e_capture($1);
9828             if ($ignorecase) {
9829             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9830             }
9831             }
9832 0         0  
9833 13 50       42 # $scalar or @array
9834 13         60 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
9835             $char[$i] = e_string($char[$i]);
9836             if ($ignorecase) {
9837             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
9838             }
9839             }
9840 0 50       0  
9841             # quote character before ? + * {
9842             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
9843 23         178 if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
9844             }
9845             else {
9846             $char[$i-1] = '(?:' . $char[$i-1] . ')';
9847             }
9848             }
9849 23         131 }
9850 143         344  
9851 143         399 # make regexp string
9852 143 50       1213 my $prematch = '';
9853 143         442 $prematch = "($anchor)";
9854             $modifier =~ tr/i//d;
9855 0         0 if ($left_e > $right_e) {
9856             return join '', $ope, $delimiter, $prematch, '(?:', @char, '>]}' x ($left_e - $right_e), ')', $matched, $end_delimiter, $modifier;
9857             }
9858             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9859             }
9860              
9861             #
9862 143     96 0 1716 # escape regexp (s'here'' or s'here''b)
9863 96   100     207 #
9864             sub e_s1_q {
9865 96         209 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9866 96 50       145 $modifier ||= '';
9867 96         187  
9868 0         0 $modifier =~ tr/p//d;
9869 0 0       0 if ($modifier =~ /([adlu])/oxms) {
9870 0         0 my $line = 0;
9871 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
9872             if ($filename ne __FILE__) {
9873             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
9874 0         0 last;
9875             }
9876             }
9877 0         0 die qq{Unsupported modifier "$1" used at line $line.\n};
9878             }
9879              
9880 96 100       116 $slash = 'div';
    100          
9881 96         216  
9882 8         9 # literal null string pattern
9883 8         11 if ($string eq '') {
9884             $modifier =~ tr/bB//d;
9885             $modifier =~ tr/i//d;
9886             return join '', $ope, $delimiter, $end_delimiter, $modifier;
9887             }
9888 8         51  
9889             # with /b /B modifier
9890             elsif ($modifier =~ tr/bB//d) {
9891             return e_s1_qb($ope,$delimiter,$end_delimiter,$string,$modifier);
9892             }
9893 44         90  
9894             # without /b /B modifier
9895             else {
9896             return e_s1_qt($ope,$delimiter,$end_delimiter,$string,$modifier);
9897             }
9898             }
9899              
9900             #
9901 44     44 0 112 # escape regexp (s'here'')
9902             #
9903 44 100       95 sub e_s1_qt {
9904             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9905              
9906 44         88 my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
9907              
9908             # split regexp
9909             my @char = $string =~ /\G((?>
9910             [^\x81-\x9F\xE0-\xFC\\\[\$\@\/] |
9911             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
9912             \[\^ |
9913             \[\: (?>[a-z]+) \:\] |
9914             \[\:\^ (?>[a-z]+) \:\] |
9915             [\$\@\/] |
9916             \\ (?:$q_char) |
9917             (?:$q_char)
9918 44         503 ))/oxmsg;
9919 44 50 100     135  
    50 100        
    50 66        
    50          
    100          
    100          
    50          
9920             # unescape character
9921             for (my $i=0; $i <= $#char; $i++) {
9922             if (0) {
9923 62         614 }
9924 0         0  
9925             # escape last octet of multiple-octet
9926             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\\|\[\{\^]|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
9927             $char[$i] = $1 . '\\' . $2;
9928             }
9929 0         0  
9930 0 0       0 # open character class [...]
9931 0         0 elsif ($char[$i] eq '[') {
9932             my $left = $i;
9933 0         0 if ($char[$i+1] eq ']') {
9934 0 0       0 $i++;
9935 0         0 }
9936             while (1) {
9937 0 0       0 if (++$i > $#char) {
9938 0         0 die __FILE__, ": Unmatched [] in regexp\n";
9939             }
9940             if ($char[$i] eq ']') {
9941 0         0 my $right = $i;
9942              
9943 0         0 # [...]
9944 0         0 splice @char, $left, $right-$left+1, Esjis::charlist_qr(@char[$left+1..$right-1], $modifier);
9945              
9946             $i = $left;
9947             last;
9948             }
9949             }
9950             }
9951 0         0  
9952 0 0       0 # open character class [^...]
9953 0         0 elsif ($char[$i] eq '[^') {
9954             my $left = $i;
9955 0         0 if ($char[$i+1] eq ']') {
9956 0 0       0 $i++;
9957 0         0 }
9958             while (1) {
9959 0 0       0 if (++$i > $#char) {
9960 0         0 die __FILE__, ": Unmatched [] in regexp\n";
9961             }
9962             if ($char[$i] eq ']') {
9963 0         0 my $right = $i;
9964              
9965 0         0 # [^...]
9966 0         0 splice @char, $left, $right-$left+1, Esjis::charlist_not_qr(@char[$left+1..$right-1], $modifier);
9967              
9968             $i = $left;
9969             last;
9970             }
9971             }
9972             }
9973 0         0  
9974             # escape $ @ / and \
9975             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
9976             $char[$i] = '\\' . $char[$i];
9977             }
9978 0         0  
9979             # rewrite character class or escape character
9980             elsif (my $char = character_class($char[$i],$modifier)) {
9981             $char[$i] = $char;
9982             }
9983 6 50       14  
9984 8         22 # /i modifier
9985             elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Esjis::uc($char[$i]) ne Esjis::fc($char[$i]))) {
9986             if (CORE::length(Esjis::fc($char[$i])) == 1) {
9987 8         21 $char[$i] = '[' . Esjis::uc($char[$i]) . Esjis::fc($char[$i]) . ']';
9988             }
9989             else {
9990             $char[$i] = '(?:' . Esjis::uc($char[$i]) . '|' . Esjis::fc($char[$i]) . ')';
9991             }
9992             }
9993 0 0       0  
9994             # quote character before ? + * {
9995             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
9996 0         0 if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
9997             }
9998             else {
9999             $char[$i-1] = '(?:' . $char[$i-1] . ')';
10000             }
10001 0         0 }
10002 44         81 }
10003 44         69  
10004 44         57 $modifier =~ tr/i//d;
10005 44         56 $delimiter = '/';
10006 44         88 $end_delimiter = '/';
10007             my $prematch = '';
10008             $prematch = "($anchor)";
10009             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
10010             }
10011              
10012             #
10013 44     44 0 334 # escape regexp (s'here''b)
10014             #
10015             sub e_s1_qb {
10016 44         96 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
10017              
10018             # split regexp
10019 44         152 my @char = $string =~ /\G (?>[^\\]|\\\\|[\x00-\xFF]) /oxmsg;
10020 44 50       110  
    50          
10021             # unescape character
10022             for (my $i=0; $i <= $#char; $i++) {
10023             if (0) {
10024 98         299 }
10025              
10026             # remain \\
10027             elsif ($char[$i] eq '\\\\') {
10028             }
10029 0         0  
10030             # escape $ @ / and \
10031             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
10032             $char[$i] = '\\' . $char[$i];
10033 0         0 }
10034 44         62 }
10035 44         60  
10036 44         49 $delimiter = '/';
10037 44         46 $end_delimiter = '/';
10038             my $prematch = '';
10039             $prematch = q{(\G[\x00-\xFF]*?)};
10040             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
10041             }
10042              
10043             #
10044 44     91 0 290 # escape regexp (s''here')
10045             #
10046 91         170 sub e_s2_q {
10047             my($ope,$delimiter,$end_delimiter,$string) = @_;
10048 91         106  
10049 91         336 $slash = 'div';
10050 91 50 66     220  
    50 33        
    100          
    100          
10051             my @char = $string =~ / \G (?>[^\x81-\x9F\xE0-\xFC\\]|\\\\|$q_char) /oxmsg;
10052             for (my $i=0; $i <= $#char; $i++) {
10053             if (0) {
10054 9         109 }
10055 0         0  
10056             # escape last octet of multiple-octet
10057             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) (\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
10058 0         0 $char[$i] = $1 . '\\' . $2;
10059             }
10060             elsif (defined($char[$i+1]) and ($char[$i+1] eq '\\') and ($char[$i] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
10061             $char[$i] = $1 . '\\' . $2;
10062             }
10063              
10064             # not escape \\
10065             elsif ($char[$i] =~ /\A \\\\ \z/oxms) {
10066             }
10067 0         0  
10068             # escape $ @ / and \
10069             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
10070 5 50 66     20 $char[$i] = '\\' . $char[$i];
10071 91         221 }
10072             }
10073             if (defined($char[-1]) and ($char[-1] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
10074 0         0 $char[-1] = $1 . '\\' . $2;
10075             }
10076              
10077             return join '', $ope, $delimiter, @char, $end_delimiter;
10078             }
10079              
10080             #
10081 91     291 0 248 # escape regexp (s/here/and here/modifier)
10082 291   100     2319 #
10083             sub e_sub {
10084 291         1121 my($variable,$delimiter1,$pattern,$end_delimiter1,$delimiter2,$replacement,$end_delimiter2,$modifier) = @_;
10085 291 50       585 $modifier ||= '';
10086 291         942  
10087 0         0 $modifier =~ tr/p//d;
10088 0 0       0 if ($modifier =~ /([adlu])/oxms) {
10089 0         0 my $line = 0;
10090 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
10091             if ($filename ne __FILE__) {
10092             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
10093 0         0 last;
10094             }
10095             }
10096 0 100       0 die qq{Unsupported modifier "$1" used at line $line.\n};
10097 291         790 }
10098 37         67  
10099             if ($variable eq '') {
10100             $variable = '$_';
10101 37         74 $bind_operator = ' =~ ';
10102             }
10103              
10104             $slash = 'div';
10105              
10106             # P.128 Start of match (or end of previous match): \G
10107             # P.130 Advanced Use of \G with Perl
10108             # in Chapter 3: Overview of Regular Expression Features and Flavors
10109             # P.312 Iterative Matching: Scalar Context, with /g
10110             # in Chapter 7: Perl
10111             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
10112              
10113             # P.181 Where You Left Off: The \G Assertion
10114             # in Chapter 5: Pattern Matching
10115             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
10116              
10117             # P.220 Where You Left Off: The \G Assertion
10118 291         480 # in Chapter 5: Pattern Matching
10119 291         447 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
10120              
10121 291         501 my $e_modifier = $modifier =~ tr/e//d;
10122 291 50       400 my $r_modifier = $modifier =~ tr/r//d;
10123 291         921  
10124 0         0 my $my = '';
10125 0         0 if ($variable =~ s/\A \( (?>\s*) ( (?>(?: local \b | my \b | our \b | state \b )?) .+ ) \) \z/$1/oxms) {
10126             $my = $variable;
10127             $variable =~ s/ (?: local \b | my \b | our \b | state \b ) (?>\s*) //oxms;
10128 0         0 $variable =~ s/ = .+ \z//oxms;
10129 291         751 }
10130              
10131             (my $variable_basename = $variable) =~ s/ [\[\{].* \z//oxms;
10132 291         590 $variable_basename =~ s/ \s+ \z//oxms;
10133 291 100       407  
10134 291         691 # quote replacement string
10135 17         54 my $e_replacement = '';
10136             if ($e_modifier >= 1) {
10137             $e_replacement = e_qq('', '', '', $replacement);
10138 17 100       28 $e_modifier--;
10139 274         554 }
10140             else {
10141             if ($delimiter2 eq "'") {
10142 91         272 $e_replacement = e_s2_q('qq', '/', '/', $replacement);
10143             }
10144             else {
10145             $e_replacement = e_qq ('qq', $delimiter2, $end_delimiter2, $replacement);
10146 183         501 }
10147             }
10148              
10149 291 100       536 my $sub = '';
10150 291 100       611  
    50          
10151             # with /r
10152             if ($r_modifier) {
10153             if (0) {
10154 8         28 }
10155 0 50       0  
10156             # s///gr with multibyte anchoring
10157             elsif ($modifier =~ /g/oxms) {
10158             $sub = sprintf(
10159             # 1 2 3 4 5
10160             q,
10161              
10162             $variable, # 1
10163             ($delimiter1 eq "'") ? # 2
10164             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
10165             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
10166             $s_matched, # 3
10167             $e_replacement, # 4
10168             '$Esjis::re_r=CORE::eval $Esjis::re_r; ' x $e_modifier, # 5
10169             );
10170             }
10171 4 0       24  
10172             # s///gr without multibyte anchoring
10173             elsif ($modifier =~ /g/oxms) {
10174             $sub = sprintf(
10175             # 1 2 3 4 5
10176             q,
10177              
10178             $variable, # 1
10179             ($delimiter1 eq "'") ? # 2
10180             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
10181             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
10182             $s_matched, # 3
10183             $e_replacement, # 4
10184             '$Esjis::re_r=CORE::eval $Esjis::re_r; ' x $e_modifier, # 5
10185             );
10186             }
10187              
10188 0         0 # s///r
10189 4         7 else {
10190              
10191 4 50       6 my $prematch = q{$`};
10192             $prematch = q{${1}};
10193              
10194             $sub = sprintf(
10195             # 1 2 3 4 5 6 7
10196             q<(%s =~ %s) ? CORE::eval{%s local $^W=0; local $Esjis::re_r=%s; %s"%s$Esjis::re_r$'" } : %s>,
10197              
10198             $variable, # 1
10199             ($delimiter1 eq "'") ? # 2
10200             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
10201             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
10202             $s_matched, # 3
10203             $e_replacement, # 4
10204             '$Esjis::re_r=CORE::eval $Esjis::re_r; ' x $e_modifier, # 5
10205             $prematch, # 6
10206             $variable, # 7
10207             );
10208 4 50       20 }
10209 8         27  
10210             # $var !~ s///r doesn't make sense
10211             if ($bind_operator =~ / !~ /oxms) {
10212             $sub = q{die("$0: Using !~ with s///r doesn't make sense"), } . $sub;
10213             }
10214             }
10215 0 100       0  
    50          
10216             # without /r
10217             else {
10218             if (0) {
10219 283         790 }
10220 0 100       0  
    100          
10221             # s///g with multibyte anchoring
10222             elsif ($modifier =~ /g/oxms) {
10223             $sub = sprintf(
10224             # 1 2 3 4 5 6 7 8 9 10
10225             q,
10226              
10227             $variable, # 1
10228             ($delimiter1 eq "'") ? # 2
10229             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
10230             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
10231             $s_matched, # 3
10232             $e_replacement, # 4
10233             '$Esjis::re_r=CORE::eval $Esjis::re_r; ' x $e_modifier, # 5
10234             $variable, # 6
10235             $variable, # 7
10236             $variable, # 8
10237             $variable, # 9
10238              
10239             # Binary "!~" is just like "=~" except the return value is negated in the logical sense.
10240             # It returns false if the match succeeds, and true if it fails.
10241             # (and so on)
10242              
10243             ($bind_operator =~ / !~ /oxms) ? '!' : '', # 10
10244             );
10245             }
10246 36 0       231  
    0          
10247             # s///g without multibyte anchoring
10248             elsif ($modifier =~ /g/oxms) {
10249             $sub = sprintf(
10250             # 1 2 3 4 5 6 7 8
10251             q,
10252              
10253             $variable, # 1
10254             ($delimiter1 eq "'") ? # 2
10255             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
10256             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
10257             $s_matched, # 3
10258             $e_replacement, # 4
10259             '$Esjis::re_r=CORE::eval $Esjis::re_r; ' x $e_modifier, # 5
10260             $variable, # 6
10261             $variable, # 7
10262             ($bind_operator =~ / !~ /oxms) ? '!' : '', # 8
10263             );
10264             }
10265              
10266 0         0 # s///
10267 247         359 else {
10268              
10269 247 100       352 my $prematch = q{$`};
    100          
10270             $prematch = q{${1}};
10271              
10272             $sub = sprintf(
10273              
10274             ($bind_operator =~ / =~ /oxms) ?
10275              
10276             # 1 2 3 4 5 6 7 8
10277             q<(%s%s%s) ? CORE::eval{%s local $^W=0; local $Esjis::re_r=%s; %s%s="%s$Esjis::re_r$'"; 1 } : undef> :
10278              
10279             # 1 2 3 4 5 6 7 8
10280             q<(%s%s%s) ? 1 : CORE::eval{%s local $^W=0; local $Esjis::re_r=%s; %s%s="%s$Esjis::re_r$'"; undef }>,
10281              
10282             $variable, # 1
10283             $bind_operator, # 2
10284             ($delimiter1 eq "'") ? # 3
10285             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
10286             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
10287             $s_matched, # 4
10288             $e_replacement, # 5
10289             '$Esjis::re_r=CORE::eval $Esjis::re_r; ' x $e_modifier, # 6
10290             $variable, # 7
10291             $prematch, # 8
10292             );
10293             }
10294 247 50       1315 }
10295 291         769  
10296             # (my $foo = $bar) =~ s/// --> (my $foo = $bar, CORE::eval { ... })[1]
10297             if ($my ne '') {
10298             $sub = "($my, $sub)[1]";
10299 0         0 }
10300 291         423  
10301             # clear s/// variable
10302 291         377 $sub_variable = '';
10303             $bind_operator = '';
10304              
10305             return $sub;
10306             }
10307              
10308             #
10309 291     0 0 2147 # escape chdir (qq//, "")
10310             #
10311 0 0       0 sub e_chdir {
10312 0 0       0 my($ope,$delimiter,$end_delimiter,$string) = @_;
10313 0 0       0  
10314 0         0 if ($^W) {
10315 0         0 if (Esjis::_MSWin32_5Cended_path($string)) {
10316             if ($] !~ /^5\.005/oxms) {
10317             warn <
10318             @{[__FILE__]}: Can't chdir to '$string'
10319              
10320             chdir does not work with chr(0x5C) at end of path
10321             http://bugs.activestate.com/show_bug.cgi?id=81839
10322             END
10323             }
10324 0         0 }
10325             }
10326              
10327             return e_qq($ope,$delimiter,$end_delimiter,$string);
10328             }
10329              
10330             #
10331 0     2 0 0 # escape chdir (q//, '')
10332             #
10333 2 50       6 sub e_chdir_q {
10334 2 0       6 my($ope,$delimiter,$end_delimiter,$string) = @_;
10335 0 0       0  
10336 0         0 if ($^W) {
10337 0         0 if (Esjis::_MSWin32_5Cended_path($string)) {
10338             if ($] !~ /^5\.005/oxms) {
10339             warn <
10340             @{[__FILE__]}: Can't chdir to '$string'
10341              
10342             chdir does not work with chr(0x5C) at end of path
10343             http://bugs.activestate.com/show_bug.cgi?id=81839
10344             END
10345             }
10346 0         0 }
10347             }
10348              
10349             return e_q($ope,$delimiter,$end_delimiter,$string);
10350             }
10351              
10352             #
10353 2     273 0 7 # escape regexp of split qr//
10354 273   100     1243 #
10355             sub e_split {
10356 273         1024 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
10357 273 50       554 $modifier ||= '';
10358 273         729  
10359 0         0 $modifier =~ tr/p//d;
10360 0 0       0 if ($modifier =~ /([adlu])/oxms) {
10361 0         0 my $line = 0;
10362 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
10363             if ($filename ne __FILE__) {
10364             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
10365 0         0 last;
10366             }
10367             }
10368 0         0 die qq{Unsupported modifier "$1" used at line $line.\n};
10369             }
10370              
10371 273 100       417 $slash = 'div';
10372 273         586  
10373             # /b /B modifier
10374             if ($modifier =~ tr/bB//d) {
10375 84 100       402 return join '', 'split', $ope, $delimiter, $string, $end_delimiter, $modifier;
10376 189         568 }
10377              
10378             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
10379 189         653 my $metachar = qr/[\@\\|[\]{^]/oxms;
10380              
10381             # split regexp
10382             my @char = $string =~ /\G((?>
10383             [^\x81-\x9F\xE0-\xFC\\\$\@\[\(]|[\x81-\x9F\xE0-\xFC][\x00-\xFF] |
10384             \\x (?>[0-9A-Fa-f]{1,2}) |
10385             \\ (?>[0-7]{2,3}) |
10386             \\c [\x40-\x5F] |
10387             \\x\{ (?>[0-9A-Fa-f]+) \} |
10388             \\o\{ (?>[0-7]+) \} |
10389             \\[bBNpP]\{ (?>[^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} |
10390             \\ $q_char |
10391             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
10392             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
10393             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
10394             [\$\@] $qq_variable |
10395             \$ (?>\s* [0-9]+) |
10396             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
10397             \$ \$ (?![\w\{]) |
10398             \$ (?>\s*) \$ (?>\s*) $qq_variable |
10399             \[\^ |
10400             \[\: (?>[a-z]+) :\] |
10401             \[\:\^ (?>[a-z]+) :\] |
10402             \(\? |
10403 189         16771 $q_char
10404 189         557 ))/oxmsg;
10405 189         273  
10406             my $left_e = 0;
10407             my $right_e = 0;
10408 189 50 33     527 for (my $i=0; $i <= $#char; $i++) {
    50 33        
    100          
    100          
    50          
    50          
10409 372         2135  
10410             # "\L\u" --> "\u\L"
10411             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
10412             @char[$i,$i+1] = @char[$i+1,$i];
10413             }
10414 0         0  
10415             # "\U\l" --> "\l\U"
10416             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
10417             @char[$i,$i+1] = @char[$i+1,$i];
10418             }
10419 0         0  
10420             # octal escape sequence
10421             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
10422             $char[$i] = Esjis::octchr($1);
10423             }
10424 1         4  
10425             # hexadecimal escape sequence
10426             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
10427             $char[$i] = Esjis::hexchr($1);
10428             }
10429              
10430             # \b{...} --> b\{...}
10431             # \B{...} --> B\{...}
10432             # \N{CHARNAME} --> N\{CHARNAME}
10433 1         3 # \p{PROPERTY} --> p\{PROPERTY}
10434             # \P{PROPERTY} --> P\{PROPERTY}
10435             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\x9F\xE0-\xFC0-9\}][^\x81-\x9F\xE0-\xFC\}]*) \} ) \z/oxms) {
10436             $char[$i] = $1 . '\\' . $2;
10437             }
10438 0         0  
10439             # \p, \P, \X --> p, P, X
10440             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
10441 0 50 100     0 $char[$i] = $1;
    50 100        
    100 66        
    100 100        
    100          
    100          
    100          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
    100          
    100          
10442             }
10443              
10444             if (0) {
10445 372         4380 }
10446 0         0  
10447             # escape last octet of multiple-octet
10448             elsif ($char[$i] =~ /\A \\? ([\x80-\xFF].*) ($metachar|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
10449             $char[$i] = $1 . '\\' . $2;
10450             }
10451 0 0 0     0  
    0 0        
    0 0        
      0        
      0        
      0        
10452 0         0 # join separated multiple-octet
10453             elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
10454             if ( ($i+3 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+3]) == 3) and (CORE::eval(sprintf '"%s%s%s%s"', @char[$i..$i+3]) =~ /\A $q_char \z/oxms)) {
10455 0         0 $char[$i] .= join '', splice @char, $i+1, 3;
10456             }
10457             elsif (($i+2 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, @char[$i+1..$i+2]) == 2) and (CORE::eval(sprintf '"%s%s%s"', @char[$i..$i+2]) =~ /\A $q_char \z/oxms)) {
10458 0         0 $char[$i] .= join '', splice @char, $i+1, 2;
10459             }
10460             elsif (($i+1 <= $#char) and (grep(/\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms, $char[$i+1 ]) == 1) and (CORE::eval(sprintf '"%s%s"', @char[$i..$i+1]) =~ /\A $q_char \z/oxms)) {
10461             $char[$i] .= join '', splice @char, $i+1, 1;
10462             }
10463             }
10464 0         0  
10465 3 50       6 # open character class [...]
10466 3         10 elsif ($char[$i] eq '[') {
10467             my $left = $i;
10468 0         0 if ($char[$i+1] eq ']') {
10469 3 50       6 $i++;
10470 7         13 }
10471             while (1) {
10472 0 100       0 if (++$i > $#char) {
10473 7         27 die __FILE__, ": Unmatched [] in regexp\n";
10474             }
10475             if ($char[$i] eq ']') {
10476 3 50       5 my $right = $i;
10477 3         22  
  0         0  
10478             # [...]
10479             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
10480 0         0 splice @char, $left, $right-$left+1, sprintf(q{@{[Esjis::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
10481             }
10482             else {
10483 3         15 splice @char, $left, $right-$left+1, Esjis::charlist_qr(@char[$left+1..$right-1], $modifier);
10484 3         5 }
10485              
10486             $i = $left;
10487             last;
10488             }
10489             }
10490             }
10491 3         7  
10492 1 50       2 # open character class [^...]
10493 1         4 elsif ($char[$i] eq '[^') {
10494             my $left = $i;
10495 0         0 if ($char[$i+1] eq ']') {
10496 1 50       2 $i++;
10497 2         5 }
10498             while (1) {
10499 0 100       0 if (++$i > $#char) {
10500 2         5 die __FILE__, ": Unmatched [] in regexp\n";
10501             }
10502             if ($char[$i] eq ']') {
10503 1 50       2 my $right = $i;
10504 1         7  
  0         0  
10505             # [^...]
10506             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
10507 0         0 splice @char, $left, $right-$left+1, sprintf(q{@{[Esjis::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
10508             }
10509             else {
10510 1         7 splice @char, $left, $right-$left+1, Esjis::charlist_not_qr(@char[$left+1..$right-1], $modifier);
10511 1         2 }
10512              
10513             $i = $left;
10514             last;
10515             }
10516             }
10517             }
10518 1         4  
10519             # rewrite character class or escape character
10520             elsif (my $char = character_class($char[$i],$modifier)) {
10521             $char[$i] = $char;
10522             }
10523              
10524             # P.794 29.2.161. split
10525             # in Chapter 29: Functions
10526             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
10527              
10528             # P.951 split
10529             # in Chapter 27: Functions
10530             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
10531              
10532             # said "The //m modifier is assumed when you split on the pattern /^/",
10533             # but perl5.008 is not so. Therefore, this software adds //m.
10534             # (and so on)
10535 5         20  
10536             # split(m/^/) --> split(m/^/m)
10537             elsif (($char[$i] eq '^') and ($modifier !~ /m/oxms)) {
10538             $modifier .= 'm';
10539             }
10540 11 50       39  
10541 18         43 # /i modifier
10542             elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Esjis::uc($char[$i]) ne Esjis::fc($char[$i]))) {
10543             if (CORE::length(Esjis::fc($char[$i])) == 1) {
10544 18         49 $char[$i] = '[' . Esjis::uc($char[$i]) . Esjis::fc($char[$i]) . ']';
10545             }
10546             else {
10547             $char[$i] = '(?:' . Esjis::uc($char[$i]) . '|' . Esjis::fc($char[$i]) . ')';
10548             }
10549             }
10550 0 50       0  
10551 2         20 # \u \l \U \L \F \Q \E
10552             elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
10553             if ($right_e < $left_e) {
10554             $char[$i] = '\\' . $char[$i];
10555 0         0 }
10556 0         0 }
10557             elsif ($char[$i] eq '\u') {
10558             $char[$i] = '@{[Esjis::ucfirst qq<';
10559 0         0 $left_e++;
10560 0         0 }
10561             elsif ($char[$i] eq '\l') {
10562             $char[$i] = '@{[Esjis::lcfirst qq<';
10563 0         0 $left_e++;
10564 0         0 }
10565             elsif ($char[$i] eq '\U') {
10566             $char[$i] = '@{[Esjis::uc qq<';
10567 0         0 $left_e++;
10568 0         0 }
10569             elsif ($char[$i] eq '\L') {
10570             $char[$i] = '@{[Esjis::lc qq<';
10571 0         0 $left_e++;
10572 0         0 }
10573             elsif ($char[$i] eq '\F') {
10574             $char[$i] = '@{[Esjis::fc qq<';
10575 0         0 $left_e++;
10576 0         0 }
10577             elsif ($char[$i] eq '\Q') {
10578             $char[$i] = '@{[CORE::quotemeta qq<';
10579 0 0       0 $left_e++;
10580 0         0 }
10581 0         0 elsif ($char[$i] eq '\E') {
10582             if ($right_e < $left_e) {
10583             $char[$i] = '>]}';
10584 0         0 $right_e++;
10585             }
10586             else {
10587             $char[$i] = '';
10588 0         0 }
10589 0 0       0 }
10590 0         0 elsif ($char[$i] eq '\Q') {
10591             while (1) {
10592 0 0       0 if (++$i > $#char) {
10593 0         0 last;
10594             }
10595             if ($char[$i] eq '\E') {
10596             last;
10597             }
10598             }
10599             }
10600             elsif ($char[$i] eq '\E') {
10601             }
10602 0 0       0  
10603 0         0 # $0 --> $0
10604             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
10605             if ($ignorecase) {
10606             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10607 0 0       0 }
10608 0         0 }
10609             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
10610             if ($ignorecase) {
10611             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10612             }
10613             }
10614              
10615             # $$ --> $$
10616             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
10617             }
10618              
10619 0         0 # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
10620 0 0       0 # $1, $2, $3 --> $1, $2, $3 otherwise
10621 0         0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
10622             $char[$i] = e_capture($1);
10623             if ($ignorecase) {
10624             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10625 0         0 }
10626 0 0       0 }
10627 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
10628             $char[$i] = e_capture($1);
10629             if ($ignorecase) {
10630             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10631             }
10632             }
10633 0         0  
10634 0 0       0 # $$foo[ ... ] --> $ $foo->[ ... ]
10635 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
10636             $char[$i] = e_capture($1.'->'.$2);
10637             if ($ignorecase) {
10638             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10639             }
10640             }
10641 0         0  
10642 0 0       0 # $$foo{ ... } --> $ $foo->{ ... }
10643 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
10644             $char[$i] = e_capture($1.'->'.$2);
10645             if ($ignorecase) {
10646             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10647             }
10648             }
10649 0         0  
10650 0 0       0 # $$foo
10651 0         0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
10652             $char[$i] = e_capture($1);
10653             if ($ignorecase) {
10654             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10655             }
10656             }
10657 0 50       0  
10658 12         45 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Esjis::PREMATCH()
10659             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
10660             if ($ignorecase) {
10661 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::PREMATCH())]}';
10662             }
10663             else {
10664             $char[$i] = '@{[Esjis::PREMATCH()]}';
10665             }
10666             }
10667 12 50       57  
10668 12         33 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Esjis::MATCH()
10669             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
10670             if ($ignorecase) {
10671 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::MATCH())]}';
10672             }
10673             else {
10674             $char[$i] = '@{[Esjis::MATCH()]}';
10675             }
10676             }
10677 12 50       58  
10678 9         30 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Esjis::POSTMATCH()
10679             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
10680             if ($ignorecase) {
10681 0         0 $char[$i] = '@{[Esjis::ignorecase(Esjis::POSTMATCH())]}';
10682             }
10683             else {
10684             $char[$i] = '@{[Esjis::POSTMATCH()]}';
10685             }
10686             }
10687 9 0       45  
10688 0         0 # ${ foo }
10689             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
10690             if ($ignorecase) {
10691             $char[$i] = '@{[Esjis::ignorecase(' . $1 . ')]}';
10692             }
10693             }
10694 0         0  
10695 0 0       0 # ${ ... }
10696 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
10697             $char[$i] = e_capture($1);
10698             if ($ignorecase) {
10699             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10700             }
10701             }
10702 0         0  
10703 3 50       9 # $scalar or @array
10704 3         15 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
10705             $char[$i] = e_string($char[$i]);
10706             if ($ignorecase) {
10707             $char[$i] = '@{[Esjis::ignorecase(' . $char[$i] . ')]}';
10708             }
10709             }
10710 0 100       0  
10711             # quote character before ? + * {
10712             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
10713 7         40 if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
10714             }
10715             else {
10716             $char[$i-1] = '(?:' . $char[$i-1] . ')';
10717             }
10718             }
10719 4         20 }
10720 189 50       393  
10721 189         437 # make regexp string
10722             $modifier =~ tr/i//d;
10723 0         0 if ($left_e > $right_e) {
10724             return join '', 'Esjis::split', $ope, $delimiter, @char, '>]}' x ($left_e - $right_e), $end_delimiter, $modifier;
10725             }
10726             return join '', 'Esjis::split', $ope, $delimiter, @char, $end_delimiter, $modifier;
10727             }
10728              
10729             #
10730 189     112 0 1628 # escape regexp of split qr''
10731 112   100     614 #
10732             sub e_split_q {
10733 112         354 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
10734 112 50       260 $modifier ||= '';
10735 112         368  
10736 0         0 $modifier =~ tr/p//d;
10737 0 0       0 if ($modifier =~ /([adlu])/oxms) {
10738 0         0 my $line = 0;
10739 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
10740             if ($filename ne __FILE__) {
10741             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
10742 0         0 last;
10743             }
10744             }
10745 0         0 die qq{Unsupported modifier "$1" used at line $line.\n};
10746             }
10747              
10748 112 100       206 $slash = 'div';
10749 112         239  
10750             # /b /B modifier
10751             if ($modifier =~ tr/bB//d) {
10752 56 100       298 return join '', 'split', $ope, $delimiter, $string, $end_delimiter, $modifier;
10753             }
10754              
10755 56         142 my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
10756              
10757             # split regexp
10758             my @char = $string =~ /\G((?>
10759             [^\x81-\x9F\xE0-\xFC\\\[] |
10760             [\x81-\x9F\xE0-\xFC][\x00-\xFF] |
10761             \[\^ |
10762             \[\: (?>[a-z]+) \:\] |
10763             \[\:\^ (?>[a-z]+) \:\] |
10764             \\ (?:$q_char) |
10765             (?:$q_char)
10766 56         319 ))/oxmsg;
10767 56 50 33     185  
    50 100        
    50 66        
    50 33        
    50          
    100          
    50          
10768             # unescape character
10769             for (my $i=0; $i <= $#char; $i++) {
10770             if (0) {
10771 56         553 }
10772 0         0  
10773             # escape last octet of multiple-octet
10774             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\\|\[\{\^]|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
10775             $char[$i] = $1 . '\\' . $2;
10776             }
10777 0         0  
10778 0 0       0 # open character class [...]
10779 0         0 elsif ($char[$i] eq '[') {
10780             my $left = $i;
10781 0         0 if ($char[$i+1] eq ']') {
10782 0 0       0 $i++;
10783 0         0 }
10784             while (1) {
10785 0 0       0 if (++$i > $#char) {
10786 0         0 die __FILE__, ": Unmatched [] in regexp\n";
10787             }
10788             if ($char[$i] eq ']') {
10789 0         0 my $right = $i;
10790              
10791 0         0 # [...]
10792 0         0 splice @char, $left, $right-$left+1, Esjis::charlist_qr(@char[$left+1..$right-1], $modifier);
10793              
10794             $i = $left;
10795             last;
10796             }
10797             }
10798             }
10799 0         0  
10800 0 0       0 # open character class [^...]
10801 0         0 elsif ($char[$i] eq '[^') {
10802             my $left = $i;
10803 0         0 if ($char[$i+1] eq ']') {
10804 0 0       0 $i++;
10805 0         0 }
10806             while (1) {
10807 0 0       0 if (++$i > $#char) {
10808 0         0 die __FILE__, ": Unmatched [] in regexp\n";
10809             }
10810             if ($char[$i] eq ']') {
10811 0         0 my $right = $i;
10812              
10813 0         0 # [^...]
10814 0         0 splice @char, $left, $right-$left+1, Esjis::charlist_not_qr(@char[$left+1..$right-1], $modifier);
10815              
10816             $i = $left;
10817             last;
10818             }
10819             }
10820             }
10821 0         0  
10822             # rewrite character class or escape character
10823             elsif (my $char = character_class($char[$i],$modifier)) {
10824             $char[$i] = $char;
10825             }
10826 0         0  
10827             # split(m/^/) --> split(m/^/m)
10828             elsif (($char[$i] eq '^') and ($modifier !~ /m/oxms)) {
10829             $modifier .= 'm';
10830             }
10831 0 50       0  
10832 12         34 # /i modifier
10833             elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Esjis::uc($char[$i]) ne Esjis::fc($char[$i]))) {
10834             if (CORE::length(Esjis::fc($char[$i])) == 1) {
10835 12         31 $char[$i] = '[' . Esjis::uc($char[$i]) . Esjis::fc($char[$i]) . ']';
10836             }
10837             else {
10838             $char[$i] = '(?:' . Esjis::uc($char[$i]) . '|' . Esjis::fc($char[$i]) . ')';
10839             }
10840             }
10841 0 0       0  
10842             # quote character before ? + * {
10843             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
10844 0         0 if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
10845             }
10846             else {
10847             $char[$i-1] = '(?:' . $char[$i-1] . ')';
10848             }
10849 0         0 }
10850 56         117 }
10851              
10852             $modifier =~ tr/i//d;
10853             return join '', 'Esjis::split', $ope, $delimiter, @char, $end_delimiter, $modifier;
10854             }
10855              
10856             #
10857 56     0 0 314 # escape use without import
10858             #
10859 0           sub e_use_noimport {
10860             my($module) = @_;
10861 0            
10862 0           my $expr = _pathof($module);
10863              
10864 0 0         my $fh = gensym();
10865 0           for my $realfilename (_realfilename($expr)) {
10866 0            
10867 0 0         if (Esjis::_open_r($fh, $realfilename)) {
10868             local $/ = undef; # slurp mode
10869 0 0         my $script = <$fh>;
10870 0           close($fh) or die "Can't close file: $realfilename: $!";
10871              
10872 0           if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
10873             return qq;
10874             }
10875             last;
10876 0           }
10877             }
10878              
10879             return qq;
10880             }
10881              
10882             #
10883 0     0 0   # escape no without unimport
10884             #
10885 0           sub e_no_nounimport {
10886             my($module) = @_;
10887 0            
10888 0           my $expr = _pathof($module);
10889              
10890 0 0         my $fh = gensym();
10891 0           for my $realfilename (_realfilename($expr)) {
10892 0            
10893 0 0         if (Esjis::_open_r($fh, $realfilename)) {
10894             local $/ = undef; # slurp mode
10895 0 0         my $script = <$fh>;
10896 0           close($fh) or die "Can't close file: $realfilename: $!";
10897              
10898 0           if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
10899             return qq;
10900             }
10901             last;
10902 0           }
10903             }
10904              
10905             return qq;
10906             }
10907              
10908             #
10909 0     0 0   # escape use with import no parameter
10910             #
10911 0           sub e_use_noparam {
10912             my($module) = @_;
10913 0            
10914 0           my $expr = _pathof($module);
10915              
10916 0 0         my $fh = gensym();
10917 0           for my $realfilename (_realfilename($expr)) {
10918 0            
10919 0 0         if (Esjis::_open_r($fh, $realfilename)) {
10920             local $/ = undef; # slurp mode
10921 0 0         my $script = <$fh>;
10922             close($fh) or die "Can't close file: $realfilename: $!";
10923              
10924             if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
10925              
10926             # P.326 UNIVERSAL: The Ultimate Ancestor Class
10927             # in Chapter 12: Objects
10928             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
10929              
10930             # P.435 UNIVERSAL: The Ultimate Ancestor Class
10931             # in Chapter 12: Objects
10932             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
10933 0            
10934             # (and so on)
10935 0            
10936             return qq[BEGIN { Esjis::require '$expr'; $module->import() if $module->can('import'); }];
10937             }
10938             last;
10939 0           }
10940             }
10941              
10942             return qq;
10943             }
10944              
10945             #
10946 0     0 0   # escape no with unimport no parameter
10947             #
10948 0           sub e_no_noparam {
10949             my($module) = @_;
10950 0            
10951 0           my $expr = _pathof($module);
10952              
10953 0 0         my $fh = gensym();
10954 0           for my $realfilename (_realfilename($expr)) {
10955 0            
10956 0 0         if (Esjis::_open_r($fh, $realfilename)) {
10957             local $/ = undef; # slurp mode
10958 0 0         my $script = <$fh>;
10959 0           close($fh) or die "Can't close file: $realfilename: $!";
10960              
10961 0           if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
10962             return qq[BEGIN { Esjis::require '$expr'; $module->unimport() if $module->can('unimport'); }];
10963             }
10964             last;
10965 0           }
10966             }
10967              
10968             return qq;
10969             }
10970              
10971             #
10972 0     0 0   # escape use with import parameters
10973             #
10974 0           sub e_use {
10975             my($module,$list) = @_;
10976 0            
10977 0           my $expr = _pathof($module);
10978              
10979 0 0         my $fh = gensym();
10980 0           for my $realfilename (_realfilename($expr)) {
10981 0            
10982 0 0         if (Esjis::_open_r($fh, $realfilename)) {
10983             local $/ = undef; # slurp mode
10984 0 0         my $script = <$fh>;
10985 0           close($fh) or die "Can't close file: $realfilename: $!";
10986              
10987 0           if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
10988             return qq[BEGIN { Esjis::require '$expr'; $module->import($list) if $module->can('import'); }];
10989             }
10990             last;
10991 0           }
10992             }
10993              
10994             return qq;
10995             }
10996              
10997             #
10998 0     0 0   # escape no with unimport parameters
10999             #
11000 0           sub e_no {
11001             my($module,$list) = @_;
11002 0            
11003 0           my $expr = _pathof($module);
11004              
11005 0 0         my $fh = gensym();
11006 0           for my $realfilename (_realfilename($expr)) {
11007 0            
11008 0 0         if (Esjis::_open_r($fh, $realfilename)) {
11009             local $/ = undef; # slurp mode
11010 0 0         my $script = <$fh>;
11011 0           close($fh) or die "Can't close file: $realfilename: $!";
11012              
11013 0           if ($script =~ /^ (?>\s*) use (?>\s+) Sjis (?>\s*) ([^\x81-\x9F\xE0-\xFC;]*) ; (?>\s*) \n? $/oxms) {
11014             return qq[BEGIN { Esjis::require '$expr'; $module->unimport($list) if $module->can('unimport'); }];
11015             }
11016             last;
11017 0           }
11018             }
11019              
11020             return qq;
11021             }
11022              
11023             #
11024 0     0     # file path of module
11025             #
11026 0 0         sub _pathof {
11027 0           my($expr) = @_;
11028              
11029             if ($^O eq 'MacOS') {
11030 0           $expr =~ s#::#:#g;
11031             }
11032 0 0         else {
11033             $expr =~ s#::#/#g;
11034 0           }
11035             $expr .= '.pm' if $expr !~ / \.pm \z/oxmsi;
11036              
11037             return $expr;
11038             }
11039              
11040             #
11041 0     0     # real file name of module
11042             #
11043 0 0         sub _realfilename {
11044 0           my($expr) = @_;
  0            
11045              
11046             if ($^O eq 'MacOS') {
11047 0           return map {"$_$expr"} @INC;
  0            
11048             }
11049             else {
11050             return map {"$_/$expr"} @INC;
11051             }
11052             }
11053              
11054             #
11055 0     0 0   # instead of Carp::carp
11056 0           #
11057             sub carp {
11058             my($package,$filename,$line) = caller(1);
11059             print STDERR "@_ at $filename line $line.\n";
11060             }
11061              
11062             #
11063 0     0 0   # instead of Carp::croak
11064 0           #
11065 0           sub croak {
11066             my($package,$filename,$line) = caller(1);
11067             print STDERR "@_ at $filename line $line.\n";
11068             die "\n";
11069             }
11070              
11071             #
11072 0     0 0   # instead of Carp::cluck
11073 0           #
11074 0           sub cluck {
11075 0           my $i = 0;
11076 0           my @cluck = ();
11077             while (my($package,$filename,$line,$subroutine) = caller($i)) {
11078 0           push @cluck, "[$i] $filename($line) $package::$subroutine\n";
11079 0           $i++;
11080 0           }
11081             print STDERR CORE::reverse @cluck;
11082             print STDERR "\n";
11083             print STDERR @_;
11084             }
11085              
11086             #
11087 0     0 0   # instead of Carp::confess
11088 0           #
11089 0           sub confess {
11090 0           my $i = 0;
11091 0           my @confess = ();
11092             while (my($package,$filename,$line,$subroutine) = caller($i)) {
11093 0           push @confess, "[$i] $filename($line) $package::$subroutine\n";
11094 0           $i++;
11095 0           }
11096 0           print STDERR CORE::reverse @confess;
11097             print STDERR "\n";
11098             print STDERR @_;
11099             die "\n";
11100             }
11101              
11102             1;
11103              
11104             __END__