File Coverage

blib/lib/Ekps9566.pm
Criterion Covered Total %
statement 1185 4194 28.2
branch 1243 4236 29.3
condition 162 496 32.6
subroutine 71 196 36.2
pod 8 148 5.4
total 2669 9270 28.7


line stmt bran cond sub pod time code
1             package Ekps9566;
2 389     389   10696 use strict;
  389         4437  
  389         19359  
3 389 50   389   8522 BEGIN { $INC{'warnings.pm'} = '' if $] < 5.006 } use warnings;
  389     389   3382  
  389         2502  
  389         16639  
4             ######################################################################
5             #
6             # Ekps9566 - Run-time routines for KPS9566.pm
7             #
8             # http://search.cpan.org/dist/Char-KPS9566/
9             #
10             # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018, 2019 INABA Hitoshi
11             ######################################################################
12              
13 389     389   6009 use 5.00503; # Galapagos Consensus 1998 for primetools
  389         4213  
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 389     389   2023 use vars qw($VERSION);
  389         2430  
  389         62042  
29             $VERSION = '1.22';
30             $VERSION = $VERSION;
31              
32             BEGIN {
33 389 50   389   7096 if ($^X =~ / jperl /oxmsi) {
34 0         0 die __FILE__, ": needs perl(not jperl) 5.00503 or later. (\$^X==$^X)\n";
35             }
36 389         2296 if (CORE::ord('A') == 193) {
37             die __FILE__, ": is not US-ASCII script (may be EBCDIC or EBCDIK script).\n";
38             }
39 389         72327 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 389     389   28096 CORE::eval q{
  389     389   4261  
  389     144   2614  
  389         46645  
  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 389 50       172129 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     1152 0 0 my($name) = @_;
79              
80 1152 50       2815 if (ref $name) {
    50          
    50          
    50          
    50          
    50          
    50          
81 1152         4535 return $name;
82             }
83             elsif (Ekps9566::index($name,'::') >= 0) {
84 0         0 return $name;
85             }
86             elsif (Ekps9566::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 1152         9043 return (caller)[0] . '::' . $name;
113             }
114             }
115              
116             sub qualify_to_ref ($;$) {
117 0 50   1152 0 0 if (defined $_[1]) {
118 389     389   2754 no strict qw(refs);
  389         2178  
  389         28100  
119 1152         3476 return \*{ qualify $_[0], $_[1] };
  0         0  
120             }
121             else {
122 389     389   2447 no strict qw(refs);
  389     0   708  
  389         70366  
123 0         0 return \*{ qualify $_[0], (caller)[0] };
  1152         1858  
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-\xFE][\x00-\xFF]|[\x00-\xFF]};
154 389     389   3976 use vars qw($qq_char); $qq_char = qr/\\c[\x40-\x5F]|\\?(?:$your_char)/oxms;
  389         837  
  389         28692  
155 389     389   6621 use vars qw($q_char); $q_char = qr/$your_char/oxms;
  389         966  
  389         640443  
156              
157             #
158             # KPS9566 character range per length
159             #
160             my %range_tr = ();
161              
162             #
163             # KPS9566 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 Ekps9566 \z/oxms) {
179             %range_tr = (
180             1 => [ [0x00..0x80],
181             [0xFF..0xFF],
182             ],
183             2 => [ [0x81..0xFE],[0x41..0x5A],
184             [0x81..0xFE],[0x61..0x7A],
185             [0x81..0xFE],[0x81..0xFE],
186             ],
187             );
188             }
189              
190             else {
191             croak "Don't know my package name '@{[__PACKAGE__]}'";
192             }
193              
194             #
195             # @ARGV wildcard globbing
196             #
197             sub import {
198              
199 1152 50   5   6101 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
200 5         85 my @argv = ();
201 0         0 for (@ARGV) {
202              
203             # has space
204 0 0       0 if (/\A (?:$q_char)*? [ ] /oxms) {
    0          
205 0 0       0 if (my @glob = Ekps9566::glob(qq{"$_"})) {
206 0         0 push @argv, @glob;
207             }
208             else {
209 0         0 push @argv, $_;
210             }
211             }
212              
213             # has wildcard metachar
214             elsif (/\A (?:$q_char)*? [*?] /oxms) {
215 0 0       0 if (my @glob = Ekps9566::glob($_)) {
216 0         0 push @argv, @glob;
217             }
218             else {
219 0         0 push @argv, $_;
220             }
221             }
222              
223             # no wildcard globbing
224             else {
225 0         0 push @argv, $_;
226             }
227             }
228 0         0 @ARGV = @argv;
229             }
230              
231 0         0 *Char::ord = \&KPS9566::ord;
232 5         27 *Char::ord_ = \&KPS9566::ord_;
233 5         13 *Char::reverse = \&KPS9566::reverse;
234 5         11 *Char::getc = \&KPS9566::getc;
235 5         10 *Char::length = \&KPS9566::length;
236 5         10 *Char::substr = \&KPS9566::substr;
237 5         152 *Char::index = \&KPS9566::index;
238 5         14 *Char::rindex = \&KPS9566::rindex;
239 5         10 *Char::eval = \&KPS9566::eval;
240 5         18 *Char::escape = \&KPS9566::escape;
241 5         10 *Char::escape_token = \&KPS9566::escape_token;
242 5         11 *Char::escape_script = \&KPS9566::escape_script;
243             }
244              
245             # P.230 Care with Prototypes
246             # in Chapter 6: Subroutines
247             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
248             #
249             # If you aren't careful, you can get yourself into trouble with prototypes.
250             # But if you are careful, you can do a lot of neat things with them. This is
251             # all very powerful, of course, and should only be used in moderation to make
252             # the world a better place.
253              
254             # P.332 Care with Prototypes
255             # in Chapter 7: Subroutines
256             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
257             #
258             # If you aren't careful, you can get yourself into trouble with prototypes.
259             # But if you are careful, you can do a lot of neat things with them. This is
260             # all very powerful, of course, and should only be used in moderation to make
261             # the world a better place.
262              
263             #
264             # Prototypes of subroutines
265             #
266       0     sub unimport {}
267             sub Ekps9566::split(;$$$);
268             sub Ekps9566::tr($$$$;$);
269             sub Ekps9566::chop(@);
270             sub Ekps9566::index($$;$);
271             sub Ekps9566::rindex($$;$);
272             sub Ekps9566::lcfirst(@);
273             sub Ekps9566::lcfirst_();
274             sub Ekps9566::lc(@);
275             sub Ekps9566::lc_();
276             sub Ekps9566::ucfirst(@);
277             sub Ekps9566::ucfirst_();
278             sub Ekps9566::uc(@);
279             sub Ekps9566::uc_();
280             sub Ekps9566::fc(@);
281             sub Ekps9566::fc_();
282             sub Ekps9566::ignorecase;
283             sub Ekps9566::classic_character_class;
284             sub Ekps9566::capture;
285             sub Ekps9566::chr(;$);
286             sub Ekps9566::chr_();
287             sub Ekps9566::filetest;
288             sub Ekps9566::r(;*@);
289             sub Ekps9566::w(;*@);
290             sub Ekps9566::x(;*@);
291             sub Ekps9566::o(;*@);
292             sub Ekps9566::R(;*@);
293             sub Ekps9566::W(;*@);
294             sub Ekps9566::X(;*@);
295             sub Ekps9566::O(;*@);
296             sub Ekps9566::e(;*@);
297             sub Ekps9566::z(;*@);
298             sub Ekps9566::s(;*@);
299             sub Ekps9566::f(;*@);
300             sub Ekps9566::d(;*@);
301             sub Ekps9566::l(;*@);
302             sub Ekps9566::p(;*@);
303             sub Ekps9566::S(;*@);
304             sub Ekps9566::b(;*@);
305             sub Ekps9566::c(;*@);
306             sub Ekps9566::u(;*@);
307             sub Ekps9566::g(;*@);
308             sub Ekps9566::k(;*@);
309             sub Ekps9566::T(;*@);
310             sub Ekps9566::B(;*@);
311             sub Ekps9566::M(;*@);
312             sub Ekps9566::A(;*@);
313             sub Ekps9566::C(;*@);
314             sub Ekps9566::filetest_;
315             sub Ekps9566::r_();
316             sub Ekps9566::w_();
317             sub Ekps9566::x_();
318             sub Ekps9566::o_();
319             sub Ekps9566::R_();
320             sub Ekps9566::W_();
321             sub Ekps9566::X_();
322             sub Ekps9566::O_();
323             sub Ekps9566::e_();
324             sub Ekps9566::z_();
325             sub Ekps9566::s_();
326             sub Ekps9566::f_();
327             sub Ekps9566::d_();
328             sub Ekps9566::l_();
329             sub Ekps9566::p_();
330             sub Ekps9566::S_();
331             sub Ekps9566::b_();
332             sub Ekps9566::c_();
333             sub Ekps9566::u_();
334             sub Ekps9566::g_();
335             sub Ekps9566::k_();
336             sub Ekps9566::T_();
337             sub Ekps9566::B_();
338             sub Ekps9566::M_();
339             sub Ekps9566::A_();
340             sub Ekps9566::C_();
341             sub Ekps9566::glob($);
342             sub Ekps9566::glob_();
343             sub Ekps9566::lstat(*);
344             sub Ekps9566::lstat_();
345             sub Ekps9566::opendir(*$);
346             sub Ekps9566::stat(*);
347             sub Ekps9566::stat_();
348             sub Ekps9566::unlink(@);
349             sub Ekps9566::chdir(;$);
350             sub Ekps9566::do($);
351             sub Ekps9566::require(;$);
352             sub Ekps9566::telldir(*);
353              
354             sub KPS9566::ord(;$);
355             sub KPS9566::ord_();
356             sub KPS9566::reverse(@);
357             sub KPS9566::getc(;*@);
358             sub KPS9566::length(;$);
359             sub KPS9566::substr($$;$$);
360             sub KPS9566::index($$;$);
361             sub KPS9566::rindex($$;$);
362             sub KPS9566::escape(;$);
363              
364             #
365             # Regexp work
366             #
367 389         38904 use vars qw(
368             $re_a
369             $re_t
370             $re_n
371             $re_r
372 389     389   6128 );
  389         2147  
373              
374             #
375             # Character class
376             #
377 389         103483 use vars qw(
378             $dot
379             $dot_s
380             $eD
381             $eS
382             $eW
383             $eH
384             $eV
385             $eR
386             $eN
387             $not_alnum
388             $not_alpha
389             $not_ascii
390             $not_blank
391             $not_cntrl
392             $not_digit
393             $not_graph
394             $not_lower
395             $not_lower_i
396             $not_print
397             $not_punct
398             $not_space
399             $not_upper
400             $not_upper_i
401             $not_word
402             $not_xdigit
403             $eb
404             $eB
405 389     389   3734 );
  389         765  
406              
407 389         4396153 use vars qw(
408             $anchor
409             $matched
410 389     389   3898 );
  389         7878  
411             ${Ekps9566::anchor} = qr{\G(?>[^\x81-\xFE]|[\x81-\xFE][\x00-\xFF])*?}oxms;
412             my $q_char_SADAHIRO_Tomoyuki_2002_01_17 = '';
413              
414             # Quantifiers
415             # {n,m} --- Match at least n but not more than m times
416             #
417             # n and m are limited to non-negative integral values less than a
418             # preset limit defined when perl is built. This is usually 32766 on
419             # the most common platforms.
420             #
421             # The following code is an attempt to solve the above limitations
422             # in a multi-byte anchoring.
423              
424             # avoid "Segmentation fault" and "Error: Parse exception"
425              
426             # perl5101delta
427             # http://perldoc.perl.org/perl5101delta.html
428             # In 5.10.0, the * quantifier in patterns was sometimes treated as {0,32767}
429             # [RT #60034, #60464]. For example, this match would fail:
430             # ("ab" x 32768) =~ /^(ab)*$/
431              
432             # SEE ALSO
433             #
434             # Complex regular subexpression recursion limit
435             # http://www.perlmonks.org/?node_id=810857
436             #
437             # regexp iteration limits
438             # http://www.nntp.perl.org/group/perl.perl5.porters/2009/02/msg144065.html
439             #
440             # latest Perl won't match certain regexes more than 32768 characters long
441             # http://stackoverflow.com/questions/26226630/latest-perl-wont-match-certain-regexes-more-than-32768-characters-long
442             #
443             # Break through the limitations of regular expressions of Perl
444             # http://d.hatena.ne.jp/gfx/20110212/1297512479
445              
446             if (($] >= 5.010001) or
447             # ActivePerl 5.6 or later (include 5.10.0)
448             (defined($ActivePerl::VERSION) and ($ActivePerl::VERSION > 800)) or
449             (($^O eq 'MSWin32') and ($] =~ /\A 5\.006/oxms))
450             ) {
451             my $sbcs = ''; # Single Byte Character Set
452             for my $range (@{ $range_tr{1} }) {
453             $sbcs .= sprintf('\\x%02X-\\x%02X', $range->[0], $range->[-1]);
454             }
455              
456             if (0) {
457             }
458              
459             # other encoding
460             else {
461             ${Ekps9566::q_char_SADAHIRO_Tomoyuki_2002_01_17} = qr{.*?[$sbcs](?:[^$sbcs][^$sbcs])*?}oxms;
462             # ******* octets not in multiple octet char (always char boundary)
463             # **************** 2 octet chars
464             }
465              
466             ${Ekps9566::anchor_SADAHIRO_Tomoyuki_2002_01_17} =
467             qr{\G(?(?=.{0,32766}\z)(?:[^\x81-\xFE]|[\x81-\xFE][\x00-\xFF])*?|(?(?=[$sbcs]+\z).*?|(?:${Ekps9566::q_char_SADAHIRO_Tomoyuki_2002_01_17})))}oxms;
468             # qr{
469             # \G # (1), (2)
470             # (? # (3)
471             # (?=.{0,32766}\z) # (4)
472             # (?:[^\x81-\xFE]|[\x81-\xFE][\x00-\xFF])*?| # (5)
473             # (?(?=[$sbcs]+\z) # (6)
474             # .*?| #(7)
475             # (?:${Ekps9566::q_char_SADAHIRO_Tomoyuki_2002_01_17}) # (8)
476             # ))}oxms;
477              
478             # avoid: Complex regular subexpression recursion limit (32766) exceeded at here.
479             local $^W = 0;
480             local $SIG{__WARN__} = sub {};
481              
482             if (((('A' x 32768).'B') !~ / ${Ekps9566::anchor} B /oxms) and
483             ((('A' x 32768).'B') =~ / ${Ekps9566::anchor_SADAHIRO_Tomoyuki_2002_01_17} B /oxms)
484             ) {
485             ${Ekps9566::anchor} = ${Ekps9566::anchor_SADAHIRO_Tomoyuki_2002_01_17};
486             }
487             else {
488             undef ${Ekps9566::q_char_SADAHIRO_Tomoyuki_2002_01_17};
489             }
490             }
491              
492             # (1)
493             # P.128 Start of match (or end of previous match): \G
494             # P.130 Advanced Use of \G with Perl
495             # in Chapter3: Over view of Regular Expression Features and Flavors
496             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
497              
498             # (2)
499             # P.255 Use leading anchors
500             # P.256 Expose ^ and \G at the front of expressions
501             # in Chapter6: Crafting an Efficient Expression
502             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
503              
504             # (3)
505             # P.138 Conditional: (? if then| else)
506             # in Chapter3: Over view of Regular Expression Features and Flavors
507             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
508              
509             # (4)
510             # perlre
511             # http://perldoc.perl.org/perlre.html
512             # The "*" quantifier is equivalent to {0,} , the "+" quantifier to {1,} ,
513             # and the "?" quantifier to {0,1}, ., n, and m are limited to non-negative
514             # integral values less than a preset limit defined when perl is built.
515             # This is usually 32766 on the most common platforms. The actual limit
516             # can be seen in the error message generated by code such as this:
517             # $_ **= $_ , / {$_} / for 2 .. 42;
518              
519             # (5)
520             # P.1023 Multiple-Byte Anchoring
521             # in Appendix W Perl Code Examples
522             # of ISBN 1-56592-224-7 CJKV Information Processing
523              
524             # (6)
525             # if string has only SBCS (Single Byte Character Set)
526              
527             # (7)
528             # then .*? (isn't limited to 32766)
529              
530             # (8)
531             # else KPS9566::Regexp::Const (SADAHIRO Tomoyuki)
532             # http://homepage1.nifty.com/nomenclator/perl/shiftjis.htm#long
533             # http://search.cpan.org/~sadahiro/KPS9566-Regexp/
534             # $PadA = ' (?:\A| [\x00-\x80\xA0-\xDF])(?:[\x81-\xFE]{2})*?';
535             # $PadG = '\G(?: |[\x00-\xFF]*?[\x00-\x80\xA0-\xDF])(?:[\x81-\xFE]{2})*?';
536             # $PadGA = '\G(?:\A|(?:[\x81-\xFE]{2})+?|[\x00-\xFF]*?[\x00-\x80\xA0-\xDF] (?:[\x81-\xFE]{2})*?)';
537              
538             ${Ekps9566::dot} = qr{(?>[^\x81-\xFE\x0A]|[\x81-\xFE][\x00-\xFF])};
539             ${Ekps9566::dot_s} = qr{(?>[^\x81-\xFE]|[\x81-\xFE][\x00-\xFF])};
540             ${Ekps9566::eD} = qr{(?>[^\x81-\xFE0-9]|[\x81-\xFE][\x00-\xFF])};
541              
542             # Vertical tabs are now whitespace
543             # \s in a regex now matches a vertical tab in all circumstances.
544             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
545             # ${Ekps9566::eS} = qr{(?>[^\x81-\xFE\x09\x0A \x0C\x0D\x20]|[\x81-\xFE][\x00-\xFF])};
546             # ${Ekps9566::eS} = qr{(?>[^\x81-\xFE\x09\x0A\x0B\x0C\x0D\x20]|[\x81-\xFE][\x00-\xFF])};
547             ${Ekps9566::eS} = qr{(?>[^\x81-\xFE\s]|[\x81-\xFE][\x00-\xFF])};
548              
549             ${Ekps9566::eW} = qr{(?>[^\x81-\xFE0-9A-Z_a-z]|[\x81-\xFE][\x00-\xFF])};
550             ${Ekps9566::eH} = qr{(?>[^\x81-\xFE\x09\x20]|[\x81-\xFE][\x00-\xFF])};
551             ${Ekps9566::eV} = qr{(?>[^\x81-\xFE\x0A\x0B\x0C\x0D]|[\x81-\xFE][\x00-\xFF])};
552             ${Ekps9566::eR} = qr{(?>\x0D\x0A|[\x0A\x0D])};
553             ${Ekps9566::eN} = qr{(?>[^\x81-\xFE\x0A]|[\x81-\xFE][\x00-\xFF])};
554             ${Ekps9566::not_alnum} = qr{(?>[^\x81-\xFE\x30-\x39\x41-\x5A\x61-\x7A]|[\x81-\xFE][\x00-\xFF])};
555             ${Ekps9566::not_alpha} = qr{(?>[^\x81-\xFE\x41-\x5A\x61-\x7A]|[\x81-\xFE][\x00-\xFF])};
556             ${Ekps9566::not_ascii} = qr{(?>[^\x81-\xFE\x00-\x7F]|[\x81-\xFE][\x00-\xFF])};
557             ${Ekps9566::not_blank} = qr{(?>[^\x81-\xFE\x09\x20]|[\x81-\xFE][\x00-\xFF])};
558             ${Ekps9566::not_cntrl} = qr{(?>[^\x81-\xFE\x00-\x1F\x7F]|[\x81-\xFE][\x00-\xFF])};
559             ${Ekps9566::not_digit} = qr{(?>[^\x81-\xFE\x30-\x39]|[\x81-\xFE][\x00-\xFF])};
560             ${Ekps9566::not_graph} = qr{(?>[^\x81-\xFE\x21-\x7F]|[\x81-\xFE][\x00-\xFF])};
561             ${Ekps9566::not_lower} = qr{(?>[^\x81-\xFE\x61-\x7A]|[\x81-\xFE][\x00-\xFF])};
562             ${Ekps9566::not_lower_i} = qr{(?>[^\x81-\xFE\x41-\x5A\x61-\x7A]|[\x81-\xFE][\x00-\xFF])}; # Perl 5.16 compatible
563             # ${Ekps9566::not_lower_i} = qr{(?>[^\x81-\xFE]|[\x81-\xFE][\x00-\xFF])}; # older Perl compatible
564             ${Ekps9566::not_print} = qr{(?>[^\x81-\xFE\x20-\x7F]|[\x81-\xFE][\x00-\xFF])};
565             ${Ekps9566::not_punct} = qr{(?>[^\x81-\xFE\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E]|[\x81-\xFE][\x00-\xFF])};
566             ${Ekps9566::not_space} = qr{(?>[^\x81-\xFE\s\x0B]|[\x81-\xFE][\x00-\xFF])};
567             ${Ekps9566::not_upper} = qr{(?>[^\x81-\xFE\x41-\x5A]|[\x81-\xFE][\x00-\xFF])};
568             ${Ekps9566::not_upper_i} = qr{(?>[^\x81-\xFE\x41-\x5A\x61-\x7A]|[\x81-\xFE][\x00-\xFF])}; # Perl 5.16 compatible
569             # ${Ekps9566::not_upper_i} = qr{(?>[^\x81-\xFE]|[\x81-\xFE][\x00-\xFF])}; # older Perl compatible
570             ${Ekps9566::not_word} = qr{(?>[^\x81-\xFE\x30-\x39\x41-\x5A\x5F\x61-\x7A]|[\x81-\xFE][\x00-\xFF])};
571             ${Ekps9566::not_xdigit} = qr{(?>[^\x81-\xFE\x30-\x39\x41-\x46\x61-\x66]|[\x81-\xFE][\x00-\xFF])};
572             ${Ekps9566::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))};
573             ${Ekps9566::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]))};
574              
575             # avoid: Name "Ekps9566::foo" used only once: possible typo at here.
576             ${Ekps9566::dot} = ${Ekps9566::dot};
577             ${Ekps9566::dot_s} = ${Ekps9566::dot_s};
578             ${Ekps9566::eD} = ${Ekps9566::eD};
579             ${Ekps9566::eS} = ${Ekps9566::eS};
580             ${Ekps9566::eW} = ${Ekps9566::eW};
581             ${Ekps9566::eH} = ${Ekps9566::eH};
582             ${Ekps9566::eV} = ${Ekps9566::eV};
583             ${Ekps9566::eR} = ${Ekps9566::eR};
584             ${Ekps9566::eN} = ${Ekps9566::eN};
585             ${Ekps9566::not_alnum} = ${Ekps9566::not_alnum};
586             ${Ekps9566::not_alpha} = ${Ekps9566::not_alpha};
587             ${Ekps9566::not_ascii} = ${Ekps9566::not_ascii};
588             ${Ekps9566::not_blank} = ${Ekps9566::not_blank};
589             ${Ekps9566::not_cntrl} = ${Ekps9566::not_cntrl};
590             ${Ekps9566::not_digit} = ${Ekps9566::not_digit};
591             ${Ekps9566::not_graph} = ${Ekps9566::not_graph};
592             ${Ekps9566::not_lower} = ${Ekps9566::not_lower};
593             ${Ekps9566::not_lower_i} = ${Ekps9566::not_lower_i};
594             ${Ekps9566::not_print} = ${Ekps9566::not_print};
595             ${Ekps9566::not_punct} = ${Ekps9566::not_punct};
596             ${Ekps9566::not_space} = ${Ekps9566::not_space};
597             ${Ekps9566::not_upper} = ${Ekps9566::not_upper};
598             ${Ekps9566::not_upper_i} = ${Ekps9566::not_upper_i};
599             ${Ekps9566::not_word} = ${Ekps9566::not_word};
600             ${Ekps9566::not_xdigit} = ${Ekps9566::not_xdigit};
601             ${Ekps9566::eb} = ${Ekps9566::eb};
602             ${Ekps9566::eB} = ${Ekps9566::eB};
603              
604             #
605             # KPS9566 split
606             #
607             sub Ekps9566::split(;$$$) {
608              
609             # P.794 29.2.161. split
610             # in Chapter 29: Functions
611             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
612              
613             # P.951 split
614             # in Chapter 27: Functions
615             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
616              
617 5     0 0 11764 my $pattern = $_[0];
618 0         0 my $string = $_[1];
619 0         0 my $limit = $_[2];
620              
621             # if $pattern is also omitted or is the literal space, " "
622 0 0       0 if (not defined $pattern) {
623 0         0 $pattern = ' ';
624             }
625              
626             # if $string is omitted, the function splits the $_ string
627 0 0       0 if (not defined $string) {
628 0 0       0 if (defined $_) {
629 0         0 $string = $_;
630             }
631             else {
632 0         0 $string = '';
633             }
634             }
635              
636 0         0 my @split = ();
637              
638             # when string is empty
639 0 0       0 if ($string eq '') {
    0          
640              
641             # resulting list value in list context
642 0 0       0 if (wantarray) {
643 0         0 return @split;
644             }
645              
646             # count of substrings in scalar context
647             else {
648 0 0       0 carp "Use of implicit split to \@_ is deprecated" if $^W;
649 0         0 @_ = @split;
650 0         0 return scalar @_;
651             }
652             }
653              
654             # split's first argument is more consistently interpreted
655             #
656             # After some changes earlier in v5.17, split's behavior has been simplified:
657             # if the PATTERN argument evaluates to a string containing one space, it is
658             # treated the way that a literal string containing one space once was.
659             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#split's_first_argument_is_more_consistently_interpreted
660              
661             # if $pattern is also omitted or is the literal space, " ", the function splits
662             # on whitespace, /\s+/, after skipping any leading whitespace
663             # (and so on)
664              
665             elsif ($pattern eq ' ') {
666 0 0       0 if (not defined $limit) {
667 0         0 return CORE::split(' ', $string);
668             }
669             else {
670 0         0 return CORE::split(' ', $string, $limit);
671             }
672             }
673              
674 0         0 local $q_char = $q_char;
675 0 0       0 if (CORE::length($string) > 32766) {
676 0 0       0 if ($string =~ /\A [\x00-\x7F]+ \z/oxms) {
    0          
677 0         0 $q_char = qr{.}s;
678             }
679             elsif (defined ${Ekps9566::q_char_SADAHIRO_Tomoyuki_2002_01_17}) {
680 0         0 $q_char = ${Ekps9566::q_char_SADAHIRO_Tomoyuki_2002_01_17};
681             }
682             }
683              
684             # if $limit is negative, it is treated as if an arbitrarily large $limit has been specified
685 0 0 0     0 if ((not defined $limit) or ($limit <= 0)) {
    0          
686              
687             # a pattern capable of matching either the null string or something longer than the
688             # null string will split the value of $string into separate characters wherever it
689             # matches the null string between characters
690             # (and so on)
691              
692 0 0       0 if ('' =~ / \A $pattern \z /xms) {
693 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
694 0         0 my $limit = scalar(() = $string =~ /($pattern)/oxmsg);
695              
696             # P.1024 Appendix W.10 Multibyte Processing
697             # of ISBN 1-56592-224-7 CJKV Information Processing
698             # (and so on)
699              
700             # the //m modifier is assumed when you split on the pattern /^/
701             # (and so on)
702              
703 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
704             # V
705 0   0     0 while ((--$limit > 0) and ($string =~ s/\A((?:$q_char)+?)$pattern//m)) {
706              
707             # if the $pattern contains parentheses, then the substring matched by each pair of parentheses
708             # is included in the resulting list, interspersed with the fields that are ordinarily returned
709             # (and so on)
710              
711 0         0 local $@;
712 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
713 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
714 0         0 push @split, CORE::eval('$' . $digit);
715             }
716             }
717             }
718              
719             else {
720 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
721              
722 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
723             # V
724 0         0 while ($string =~ s/\A((?:$q_char)*?)$pattern//m) {
725 0         0 local $@;
726 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
727 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
728 0         0 push @split, CORE::eval('$' . $digit);
729             }
730             }
731             }
732             }
733              
734             elsif ($limit > 0) {
735 0 0       0 if ('' =~ / \A $pattern \z /xms) {
736 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
737 0   0     0 while ((--$limit > 0) and (CORE::length($string) > 0)) {
738              
739 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
740             # V
741 0 0       0 if ($string =~ s/\A((?:$q_char)+?)$pattern//m) {
742 0         0 local $@;
743 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
744 0         0 push @split, CORE::eval('$' . $digit);
745             }
746             }
747             }
748             }
749             else {
750 0         0 my $last_subexpression_offsets = _last_subexpression_offsets($pattern);
751 0   0     0 while ((--$limit > 0) and (CORE::length($string) > 0)) {
752              
753 0         0 eval q{ no warnings }; # avoid: Complex regular subexpression recursion limit (32766) exceeded at ...
754             # V
755 0 0       0 if ($string =~ s/\A((?:$q_char)*?)$pattern//m) {
756 0         0 local $@;
757 0         0 for (my $digit=1; $digit <= ($last_subexpression_offsets + 1); $digit++) {
758 0         0 push @split, CORE::eval('$' . $digit);
759             }
760             }
761             }
762             }
763             }
764              
765 0 0       0 if (CORE::length($string) > 0) {
766 0         0 push @split, $string;
767             }
768              
769             # if $_[2] (NOT "$limit") is omitted or zero, trailing null fields are stripped from the result
770 0 0 0     0 if ((not defined $_[2]) or ($_[2] == 0)) {
771 0   0     0 while ((scalar(@split) >= 1) and ($split[-1] eq '')) {
772 0         0 pop @split;
773             }
774             }
775              
776             # resulting list value in list context
777 0 0       0 if (wantarray) {
778 0         0 return @split;
779             }
780              
781             # count of substrings in scalar context
782             else {
783 0 0       0 carp "Use of implicit split to \@_ is deprecated" if $^W;
784 0         0 @_ = @split;
785 0         0 return scalar @_;
786             }
787             }
788              
789             #
790             # get last subexpression offsets
791             #
792             sub _last_subexpression_offsets {
793 0     0   0 my $pattern = $_[0];
794              
795             # remove comment
796 0         0 $pattern =~ s/\(\?\# .*? \)//oxmsg;
797              
798 0         0 my $modifier = '';
799 0 0       0 if ($pattern =~ /\(\?\^? ([\-A-Za-z]+) :/oxms) {
800 0         0 $modifier = $1;
801 0         0 $modifier =~ s/-[A-Za-z]*//;
802             }
803              
804             # with /x modifier
805 0         0 my @char = ();
806 0 0       0 if ($modifier =~ /x/oxms) {
807 0         0 @char = $pattern =~ /\G((?>
808             [^\x81-\xFE\\\#\[\(]|[\x81-\xFE][\x00-\xFF] |
809             \\ $q_char |
810             \# (?>[^\n]*) $ |
811             \[ (?>(?:[^\x81-\xFE\\\]]|[\x81-\xFE][\x00-\xFF]|\\\\|\\\]|$q_char)+) \] |
812             \(\? |
813             $q_char
814             ))/oxmsg;
815             }
816              
817             # without /x modifier
818             else {
819 0         0 @char = $pattern =~ /\G((?>
820             [^\x81-\xFE\\\[\(]|[\x81-\xFE][\x00-\xFF] |
821             \\ $q_char |
822             \[ (?>(?:[^\x81-\xFE\\\]]|[\x81-\xFE][\x00-\xFF]|\\\\|\\\]|$q_char)+) \] |
823             \(\? |
824             $q_char
825             ))/oxmsg;
826             }
827              
828 0         0 return scalar grep { $_ eq '(' } @char;
  0         0  
829             }
830              
831             #
832             # KPS9566 transliteration (tr///)
833             #
834             sub Ekps9566::tr($$$$;$) {
835              
836 0     0 0 0 my $bind_operator = $_[1];
837 0         0 my $searchlist = $_[2];
838 0         0 my $replacementlist = $_[3];
839 0   0     0 my $modifier = $_[4] || '';
840              
841 0 0       0 if ($modifier =~ /r/oxms) {
842 0 0       0 if ($bind_operator =~ / !~ /oxms) {
843 0         0 croak "Using !~ with tr///r doesn't make sense";
844             }
845             }
846              
847 0         0 my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
848 0         0 my @searchlist = _charlist_tr($searchlist);
849 0         0 my @replacementlist = _charlist_tr($replacementlist);
850              
851 0         0 my %tr = ();
852 0         0 for (my $i=0; $i <= $#searchlist; $i++) {
853 0 0       0 if (not exists $tr{$searchlist[$i]}) {
854 0 0 0     0 if (defined $replacementlist[$i] and ($replacementlist[$i] ne '')) {
    0 0        
    0          
855 0         0 $tr{$searchlist[$i]} = $replacementlist[$i];
856             }
857             elsif ($modifier =~ /d/oxms) {
858 0         0 $tr{$searchlist[$i]} = '';
859             }
860             elsif (defined $replacementlist[-1] and ($replacementlist[-1] ne '')) {
861 0         0 $tr{$searchlist[$i]} = $replacementlist[-1];
862             }
863             else {
864 0         0 $tr{$searchlist[$i]} = $searchlist[$i];
865             }
866             }
867             }
868              
869 0         0 my $tr = 0;
870 0         0 my $replaced = '';
871 0 0       0 if ($modifier =~ /c/oxms) {
872 0         0 while (defined(my $char = shift @char)) {
873 0 0       0 if (not exists $tr{$char}) {
874 0 0       0 if (defined $replacementlist[-1]) {
875 0         0 $replaced .= $replacementlist[-1];
876             }
877 0         0 $tr++;
878 0 0       0 if ($modifier =~ /s/oxms) {
879 0   0     0 while (@char and (not exists $tr{$char[0]})) {
880 0         0 shift @char;
881 0         0 $tr++;
882             }
883             }
884             }
885             else {
886 0         0 $replaced .= $char;
887             }
888             }
889             }
890             else {
891 0         0 while (defined(my $char = shift @char)) {
892 0 0       0 if (exists $tr{$char}) {
893 0         0 $replaced .= $tr{$char};
894 0         0 $tr++;
895 0 0       0 if ($modifier =~ /s/oxms) {
896 0   0     0 while (@char and (exists $tr{$char[0]}) and ($tr{$char[0]} eq $tr{$char})) {
      0        
897 0         0 shift @char;
898 0         0 $tr++;
899             }
900             }
901             }
902             else {
903 0         0 $replaced .= $char;
904             }
905             }
906             }
907              
908 0 0       0 if ($modifier =~ /r/oxms) {
909 0         0 return $replaced;
910             }
911             else {
912 0         0 $_[0] = $replaced;
913 0 0       0 if ($bind_operator =~ / !~ /oxms) {
914 0         0 return not $tr;
915             }
916             else {
917 0         0 return $tr;
918             }
919             }
920             }
921              
922             #
923             # KPS9566 chop
924             #
925             sub Ekps9566::chop(@) {
926              
927 0     0 0 0 my $chop;
928 0 0       0 if (@_ == 0) {
929 0         0 my @char = /\G (?>$q_char) /oxmsg;
930 0         0 $chop = pop @char;
931 0         0 $_ = join '', @char;
932             }
933             else {
934 0         0 for (@_) {
935 0         0 my @char = /\G (?>$q_char) /oxmsg;
936 0         0 $chop = pop @char;
937 0         0 $_ = join '', @char;
938             }
939             }
940 0         0 return $chop;
941             }
942              
943             #
944             # KPS9566 index by octet
945             #
946             sub Ekps9566::index($$;$) {
947              
948 0     2304 1 0 my($str,$substr,$position) = @_;
949 2304   50     4670 $position ||= 0;
950 2304         8601 my $pos = 0;
951              
952 2304         2767 while ($pos < CORE::length($str)) {
953 2304 50       4984 if (CORE::substr($str,$pos,CORE::length($substr)) eq $substr) {
954 40926 0       60432 if ($pos >= $position) {
955 0         0 return $pos;
956             }
957             }
958 0 50       0 if (CORE::substr($str,$pos) =~ /\A ($q_char) /oxms) {
959 40926         95692 $pos += CORE::length($1);
960             }
961             else {
962 40926         67985 $pos += 1;
963             }
964             }
965 0         0 return -1;
966             }
967              
968             #
969             # KPS9566 reverse index
970             #
971             sub Ekps9566::rindex($$;$) {
972              
973 2304     0 0 12630 my($str,$substr,$position) = @_;
974 0   0     0 $position ||= CORE::length($str) - 1;
975 0         0 my $pos = 0;
976 0         0 my $rindex = -1;
977              
978 0   0     0 while (($pos < CORE::length($str)) and ($pos <= $position)) {
979 0 0       0 if (CORE::substr($str,$pos,CORE::length($substr)) eq $substr) {
980 0         0 $rindex = $pos;
981             }
982 0 0       0 if (CORE::substr($str,$pos) =~ /\A ($q_char) /oxms) {
983 0         0 $pos += CORE::length($1);
984             }
985             else {
986 0         0 $pos += 1;
987             }
988             }
989 0         0 return $rindex;
990             }
991              
992             #
993             # KPS9566 lower case first with parameter
994             #
995             sub Ekps9566::lcfirst(@) {
996 0 0   0 0 0 if (@_) {
997 0         0 my $s = shift @_;
998 0 0 0     0 if (@_ and wantarray) {
999 0         0 return Ekps9566::lc(CORE::substr($s,0,1)) . CORE::substr($s,1), @_;
1000             }
1001             else {
1002 0         0 return Ekps9566::lc(CORE::substr($s,0,1)) . CORE::substr($s,1);
1003             }
1004             }
1005             else {
1006 0         0 return Ekps9566::lc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1007             }
1008             }
1009              
1010             #
1011             # KPS9566 lower case first without parameter
1012             #
1013             sub Ekps9566::lcfirst_() {
1014 0     0 0 0 return Ekps9566::lc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1015             }
1016              
1017             #
1018             # KPS9566 lower case with parameter
1019             #
1020             sub Ekps9566::lc(@) {
1021 0 0   0 0 0 if (@_) {
1022 0         0 my $s = shift @_;
1023 0 0 0     0 if (@_ and wantarray) {
1024 0 0       0 return join('', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
1025             }
1026             else {
1027 0 0       0 return join('', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  0         0  
1028             }
1029             }
1030             else {
1031 0         0 return Ekps9566::lc_();
1032             }
1033             }
1034              
1035             #
1036             # KPS9566 lower case without parameter
1037             #
1038             sub Ekps9566::lc_() {
1039 0     0 0 0 my $s = $_;
1040 0 0       0 return join '', map {defined($lc{$_}) ? $lc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
1041             }
1042              
1043             #
1044             # KPS9566 upper case first with parameter
1045             #
1046             sub Ekps9566::ucfirst(@) {
1047 0 0   0 0 0 if (@_) {
1048 0         0 my $s = shift @_;
1049 0 0 0     0 if (@_ and wantarray) {
1050 0         0 return Ekps9566::uc(CORE::substr($s,0,1)) . CORE::substr($s,1), @_;
1051             }
1052             else {
1053 0         0 return Ekps9566::uc(CORE::substr($s,0,1)) . CORE::substr($s,1);
1054             }
1055             }
1056             else {
1057 0         0 return Ekps9566::uc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1058             }
1059             }
1060              
1061             #
1062             # KPS9566 upper case first without parameter
1063             #
1064             sub Ekps9566::ucfirst_() {
1065 0     0 0 0 return Ekps9566::uc(CORE::substr($_,0,1)) . CORE::substr($_,1);
1066             }
1067              
1068             #
1069             # KPS9566 upper case with parameter
1070             #
1071             sub Ekps9566::uc(@) {
1072 0 50   2968 0 0 if (@_) {
1073 2968         4004 my $s = shift @_;
1074 2968 50 33     3625 if (@_ and wantarray) {
1075 2968 0       5430 return join('', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
1076             }
1077             else {
1078 0 100       0 return join('', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  2968         8010  
1079             }
1080             }
1081             else {
1082 2968         9953 return Ekps9566::uc_();
1083             }
1084             }
1085              
1086             #
1087             # KPS9566 upper case without parameter
1088             #
1089             sub Ekps9566::uc_() {
1090 0     0 0 0 my $s = $_;
1091 0 0       0 return join '', map {defined($uc{$_}) ? $uc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
1092             }
1093              
1094             #
1095             # KPS9566 fold case with parameter
1096             #
1097             sub Ekps9566::fc(@) {
1098 0 50   3271 0 0 if (@_) {
1099 3271         4384 my $s = shift @_;
1100 3271 50 33     3637 if (@_ and wantarray) {
1101 3271 0       5289 return join('', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg)), @_;
  0         0  
1102             }
1103             else {
1104 0 100       0 return join('', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg));
  3271         7596  
1105             }
1106             }
1107             else {
1108 3271         11990 return Ekps9566::fc_();
1109             }
1110             }
1111              
1112             #
1113             # KPS9566 fold case without parameter
1114             #
1115             sub Ekps9566::fc_() {
1116 0     0 0 0 my $s = $_;
1117 0 0       0 return join '', map {defined($fc{$_}) ? $fc{$_} : $_} ($s =~ /\G ($q_char) /oxmsg);
  0         0  
1118             }
1119              
1120             #
1121             # KPS9566 regexp capture
1122             #
1123             {
1124             # 10.3. Creating Persistent Private Variables
1125             # in Chapter 10. Subroutines
1126             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
1127              
1128             my $last_s_matched = 0;
1129              
1130             sub Ekps9566::capture {
1131 0 0 0 0 1 0 if ($last_s_matched and ($_[0] =~ /\A (?>[1-9][0-9]*) \z/oxms)) {
1132 0         0 return $_[0] + 1;
1133             }
1134 0         0 return $_[0];
1135             }
1136              
1137             # KPS9566 mark last regexp matched
1138             sub Ekps9566::matched() {
1139 0     0 0 0 $last_s_matched = 0;
1140             }
1141              
1142             # KPS9566 mark last s/// matched
1143             sub Ekps9566::s_matched() {
1144 0     0 0 0 $last_s_matched = 1;
1145             }
1146              
1147             # P.854 31.17. use re
1148             # in Chapter 31. Pragmatic Modules
1149             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
1150              
1151             # P.1026 re
1152             # in Chapter 29. Pragmatic Modules
1153             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1154              
1155             $Ekps9566::matched = qr/(?{Ekps9566::matched})/;
1156             }
1157              
1158             #
1159             # KPS9566 regexp ignore case modifier
1160             #
1161             sub Ekps9566::ignorecase {
1162              
1163 0     0 0 0 my @string = @_;
1164 0         0 my $metachar = qr/[\@\\|[\]{]/oxms;
1165              
1166             # ignore case of $scalar or @array
1167 0         0 for my $string (@string) {
1168              
1169             # split regexp
1170 0         0 my @char = $string =~ /\G (?>\[\^|\\$q_char|$q_char) /oxmsg;
1171              
1172             # unescape character
1173 0         0 for (my $i=0; $i <= $#char; $i++) {
1174 0 0       0 next if not defined $char[$i];
1175              
1176             # open character class [...]
1177 0 0       0 if ($char[$i] eq '[') {
    0          
    0          
    0          
1178 0         0 my $left = $i;
1179              
1180             # [] make die "unmatched [] in regexp ...\n"
1181              
1182 0 0       0 if ($char[$i+1] eq ']') {
1183 0         0 $i++;
1184             }
1185              
1186 0         0 while (1) {
1187 0 0       0 if (++$i > $#char) {
1188 0         0 croak "Unmatched [] in regexp";
1189             }
1190 0 0       0 if ($char[$i] eq ']') {
1191 0         0 my $right = $i;
1192 0         0 my @charlist = charlist_qr(@char[$left+1..$right-1], 'i');
1193              
1194             # escape character
1195 0         0 for my $char (@charlist) {
1196 0 0       0 if (0) {
    0          
1197             }
1198              
1199             # do not use quotemeta here
1200 0         0 elsif ($char =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
1201 0         0 $char = $1 . '\\' . $2;
1202             }
1203             elsif ($char =~ /\A [.|)] \z/oxms) {
1204 0         0 $char = '\\' . $char;
1205             }
1206             }
1207              
1208             # [...]
1209 0         0 splice @char, $left, $right-$left+1, '(?:' . join('|', @charlist) . ')';
1210              
1211 0         0 $i = $left;
1212 0         0 last;
1213             }
1214             }
1215             }
1216              
1217             # open character class [^...]
1218             elsif ($char[$i] eq '[^') {
1219 0         0 my $left = $i;
1220              
1221             # [^] make die "unmatched [] in regexp ...\n"
1222              
1223 0 0       0 if ($char[$i+1] eq ']') {
1224 0         0 $i++;
1225             }
1226              
1227 0         0 while (1) {
1228 0 0       0 if (++$i > $#char) {
1229 0         0 croak "Unmatched [] in regexp";
1230             }
1231 0 0       0 if ($char[$i] eq ']') {
1232 0         0 my $right = $i;
1233 0         0 my @charlist = charlist_not_qr(@char[$left+1..$right-1], 'i');
1234              
1235             # escape character
1236 0         0 for my $char (@charlist) {
1237 0 0       0 if (0) {
    0          
1238             }
1239              
1240             # do not use quotemeta here
1241 0         0 elsif ($char =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
1242 0         0 $char = $1 . '\\' . $2;
1243             }
1244             elsif ($char =~ /\A [.|)] \z/oxms) {
1245 0         0 $char = '\\' . $char;
1246             }
1247             }
1248              
1249             # [^...]
1250 0         0 splice @char, $left, $right-$left+1, '(?!' . join('|', @charlist) . ")(?:$your_char)";
1251              
1252 0         0 $i = $left;
1253 0         0 last;
1254             }
1255             }
1256             }
1257              
1258             # rewrite classic character class or escape character
1259             elsif (my $char = classic_character_class($char[$i])) {
1260 0         0 $char[$i] = $char;
1261             }
1262              
1263             # with /i modifier
1264             elsif ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) {
1265 0         0 my $uc = Ekps9566::uc($char[$i]);
1266 0         0 my $fc = Ekps9566::fc($char[$i]);
1267 0 0       0 if ($uc ne $fc) {
1268 0 0       0 if (CORE::length($fc) == 1) {
1269 0         0 $char[$i] = '[' . $uc . $fc . ']';
1270             }
1271             else {
1272 0         0 $char[$i] = '(?:' . $uc . '|' . $fc . ')';
1273             }
1274             }
1275             }
1276             }
1277              
1278             # characterize
1279 0         0 for (my $i=0; $i <= $#char; $i++) {
1280 0 0       0 next if not defined $char[$i];
1281              
1282 0 0 0     0 if (0) {
    0          
1283             }
1284              
1285             # escape last octet of multiple-octet
1286 0         0 elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
1287 0         0 $char[$i] = $1 . '\\' . $2;
1288             }
1289              
1290             # quote character before ? + * {
1291             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
1292 0 0       0 if ($char[$i-1] !~ /\A [\x00-\xFF] \z/oxms) {
1293 0         0 $char[$i-1] = '(?:' . $char[$i-1] . ')';
1294             }
1295             }
1296             }
1297              
1298 0         0 $string = join '', @char;
1299             }
1300              
1301             # make regexp string
1302 0         0 return @string;
1303             }
1304              
1305             #
1306             # classic character class ( \D \S \W \d \s \w \C \X \H \V \h \v \R \N \b \B )
1307             #
1308             sub Ekps9566::classic_character_class {
1309 0     5235 0 0 my($char) = @_;
1310              
1311             return {
1312             '\D' => '${Ekps9566::eD}',
1313             '\S' => '${Ekps9566::eS}',
1314             '\W' => '${Ekps9566::eW}',
1315             '\d' => '[0-9]',
1316              
1317             # Before Perl 5.6, \s only matched the five whitespace characters
1318             # tab, newline, form-feed, carriage return, and the space character
1319             # itself, which, taken together, is the character class [\t\n\f\r ].
1320              
1321             # Vertical tabs are now whitespace
1322             # \s in a regex now matches a vertical tab in all circumstances.
1323             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
1324             # \t \n \v \f \r space
1325             # '\s' => '[\x09\x0A \x0C\x0D\x20]',
1326             # '\s' => '[\x09\x0A\x0B\x0C\x0D\x20]',
1327             '\s' => '\s',
1328              
1329             '\w' => '[0-9A-Z_a-z]',
1330             '\C' => '[\x00-\xFF]',
1331             '\X' => 'X',
1332              
1333             # \h \v \H \V
1334              
1335             # P.114 Character Class Shortcuts
1336             # in Chapter 7: In the World of Regular Expressions
1337             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
1338              
1339             # P.357 13.2.3 Whitespace
1340             # in Chapter 13: perlrecharclass: Perl Regular Expression Character Classes
1341             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
1342             #
1343             # 0x00009 CHARACTER TABULATION h s
1344             # 0x0000a LINE FEED (LF) vs
1345             # 0x0000b LINE TABULATION v
1346             # 0x0000c FORM FEED (FF) vs
1347             # 0x0000d CARRIAGE RETURN (CR) vs
1348             # 0x00020 SPACE h s
1349              
1350             # P.196 Table 5-9. Alphanumeric regex metasymbols
1351             # in Chapter 5. Pattern Matching
1352             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1353              
1354             # (and so on)
1355              
1356             '\H' => '${Ekps9566::eH}',
1357             '\V' => '${Ekps9566::eV}',
1358             '\h' => '[\x09\x20]',
1359             '\v' => '[\x0A\x0B\x0C\x0D]',
1360             '\R' => '${Ekps9566::eR}',
1361              
1362             # \N
1363             #
1364             # http://perldoc.perl.org/perlre.html
1365             # Character Classes and other Special Escapes
1366             # Any character but \n (experimental). Not affected by /s modifier
1367              
1368             '\N' => '${Ekps9566::eN}',
1369              
1370             # \b \B
1371              
1372             # P.180 Boundaries: The \b and \B Assertions
1373             # in Chapter 5: Pattern Matching
1374             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
1375              
1376             # P.219 Boundaries: The \b and \B Assertions
1377             # in Chapter 5: Pattern Matching
1378             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
1379              
1380             # \b really means (?:(?<=\w)(?!\w)|(?
1381             # or (?:(?<=\A|\W)(?=\w)|(?<=\w)(?=\W|\z))
1382             '\b' => '${Ekps9566::eb}',
1383              
1384             # \B really means (?:(?<=\w)(?=\w)|(?
1385             # or (?:(?<=\w)(?=\w)|(?<=\W)(?=\W))
1386             '\B' => '${Ekps9566::eB}',
1387              
1388 5235   100     7179 }->{$char} || '';
1389             }
1390              
1391             #
1392             # prepare KPS9566 characters per length
1393             #
1394              
1395             # 1 octet characters
1396             my @chars1 = ();
1397             sub chars1 {
1398 5235 0   0 0 166037 if (@chars1) {
1399 0         0 return @chars1;
1400             }
1401 0 0       0 if (exists $range_tr{1}) {
1402 0         0 my @ranges = @{ $range_tr{1} };
  0         0  
1403 0         0 while (my @range = splice(@ranges,0,1)) {
1404 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1405 0         0 push @chars1, pack 'C', $oct0;
1406             }
1407             }
1408             }
1409 0         0 return @chars1;
1410             }
1411              
1412             # 2 octets characters
1413             my @chars2 = ();
1414             sub chars2 {
1415 0 0   0 0 0 if (@chars2) {
1416 0         0 return @chars2;
1417             }
1418 0 0       0 if (exists $range_tr{2}) {
1419 0         0 my @ranges = @{ $range_tr{2} };
  0         0  
1420 0         0 while (my @range = splice(@ranges,0,2)) {
1421 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1422 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1423 0         0 push @chars2, pack 'CC', $oct0,$oct1;
1424             }
1425             }
1426             }
1427             }
1428 0         0 return @chars2;
1429             }
1430              
1431             # 3 octets characters
1432             my @chars3 = ();
1433             sub chars3 {
1434 0 0   0 0 0 if (@chars3) {
1435 0         0 return @chars3;
1436             }
1437 0 0       0 if (exists $range_tr{3}) {
1438 0         0 my @ranges = @{ $range_tr{3} };
  0         0  
1439 0         0 while (my @range = splice(@ranges,0,3)) {
1440 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1441 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1442 0         0 for my $oct2 (@{$range[2]}) {
  0         0  
1443 0         0 push @chars3, pack 'CCC', $oct0,$oct1,$oct2;
1444             }
1445             }
1446             }
1447             }
1448             }
1449 0         0 return @chars3;
1450             }
1451              
1452             # 4 octets characters
1453             my @chars4 = ();
1454             sub chars4 {
1455 0 0   0 0 0 if (@chars4) {
1456 0         0 return @chars4;
1457             }
1458 0 0       0 if (exists $range_tr{4}) {
1459 0         0 my @ranges = @{ $range_tr{4} };
  0         0  
1460 0         0 while (my @range = splice(@ranges,0,4)) {
1461 0         0 for my $oct0 (@{$range[0]}) {
  0         0  
1462 0         0 for my $oct1 (@{$range[1]}) {
  0         0  
1463 0         0 for my $oct2 (@{$range[2]}) {
  0         0  
1464 0         0 for my $oct3 (@{$range[3]}) {
  0         0  
1465 0         0 push @chars4, pack 'CCCC', $oct0,$oct1,$oct2,$oct3;
1466             }
1467             }
1468             }
1469             }
1470             }
1471             }
1472 0         0 return @chars4;
1473             }
1474              
1475             #
1476             # KPS9566 open character list for tr
1477             #
1478             sub _charlist_tr {
1479              
1480 0     0   0 local $_ = shift @_;
1481              
1482             # unescape character
1483 0         0 my @char = ();
1484 0         0 while (not /\G \z/oxmsgc) {
1485 0 0       0 if (/\G (\\0?55|\\x2[Dd]|\\-) /oxmsgc) {
    0          
    0          
    0          
    0          
    0          
    0          
1486 0         0 push @char, '\-';
1487             }
1488             elsif (/\G \\ ([0-7]{2,3}) /oxmsgc) {
1489 0         0 push @char, CORE::chr(oct $1);
1490             }
1491             elsif (/\G \\x ([0-9A-Fa-f]{1,2}) /oxmsgc) {
1492 0         0 push @char, CORE::chr(hex $1);
1493             }
1494             elsif (/\G \\c ([\x40-\x5F]) /oxmsgc) {
1495 0         0 push @char, CORE::chr(CORE::ord($1) & 0x1F);
1496             }
1497             elsif (/\G (\\ [0nrtfbae]) /oxmsgc) {
1498             push @char, {
1499             '\0' => "\0",
1500             '\n' => "\n",
1501             '\r' => "\r",
1502             '\t' => "\t",
1503             '\f' => "\f",
1504             '\b' => "\x08", # \b means backspace in character class
1505             '\a' => "\a",
1506             '\e' => "\e",
1507 0         0 }->{$1};
1508             }
1509             elsif (/\G \\ ($q_char) /oxmsgc) {
1510 0         0 push @char, $1;
1511             }
1512             elsif (/\G ($q_char) /oxmsgc) {
1513 0         0 push @char, $1;
1514             }
1515             }
1516              
1517             # join separated multiple-octet
1518 0         0 @char = join('',@char) =~ /\G (?>\\-|$q_char) /oxmsg;
1519              
1520             # unescape '-'
1521 0         0 my @i = ();
1522 0         0 for my $i (0 .. $#char) {
1523 0 0       0 if ($char[$i] eq '\-') {
    0          
1524 0         0 $char[$i] = '-';
1525             }
1526             elsif ($char[$i] eq '-') {
1527 0 0 0     0 if ((0 < $i) and ($i < $#char)) {
1528 0         0 push @i, $i;
1529             }
1530             }
1531             }
1532              
1533             # open character list (reverse for splice)
1534 0         0 for my $i (CORE::reverse @i) {
1535 0         0 my @range = ();
1536              
1537             # range error
1538 0 0 0     0 if ((CORE::length($char[$i-1]) > CORE::length($char[$i+1])) or ($char[$i-1] gt $char[$i+1])) {
1539 0         0 croak "Invalid tr/// range \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1540             }
1541              
1542             # range of multiple-octet code
1543 0 0       0 if (CORE::length($char[$i-1]) == 1) {
    0          
    0          
    0          
1544 0 0       0 if (CORE::length($char[$i+1]) == 1) {
    0          
    0          
    0          
1545 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars1();
  0         0  
1546             }
1547             elsif (CORE::length($char[$i+1]) == 2) {
1548 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1549 0         0 push @range, grep {$_ le $char[$i+1]} chars2();
  0         0  
1550             }
1551             elsif (CORE::length($char[$i+1]) == 3) {
1552 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1553 0         0 push @range, chars2();
1554 0         0 push @range, grep {$_ le $char[$i+1]} chars3();
  0         0  
1555             }
1556             elsif (CORE::length($char[$i+1]) == 4) {
1557 0         0 push @range, grep {$char[$i-1] le $_} chars1();
  0         0  
1558 0         0 push @range, chars2();
1559 0         0 push @range, chars3();
1560 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1561             }
1562             else {
1563 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1564             }
1565             }
1566             elsif (CORE::length($char[$i-1]) == 2) {
1567 0 0       0 if (CORE::length($char[$i+1]) == 2) {
    0          
    0          
1568 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars2();
  0         0  
1569             }
1570             elsif (CORE::length($char[$i+1]) == 3) {
1571 0         0 push @range, grep {$char[$i-1] le $_} chars2();
  0         0  
1572 0         0 push @range, grep {$_ le $char[$i+1]} chars3();
  0         0  
1573             }
1574             elsif (CORE::length($char[$i+1]) == 4) {
1575 0         0 push @range, grep {$char[$i-1] le $_} chars2();
  0         0  
1576 0         0 push @range, chars3();
1577 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1578             }
1579             else {
1580 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1581             }
1582             }
1583             elsif (CORE::length($char[$i-1]) == 3) {
1584 0 0       0 if (CORE::length($char[$i+1]) == 3) {
    0          
1585 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars3();
  0         0  
1586             }
1587             elsif (CORE::length($char[$i+1]) == 4) {
1588 0         0 push @range, grep {$char[$i-1] le $_} chars3();
  0         0  
1589 0         0 push @range, grep {$_ le $char[$i+1]} chars4();
  0         0  
1590             }
1591             else {
1592 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1593             }
1594             }
1595             elsif (CORE::length($char[$i-1]) == 4) {
1596 0 0       0 if (CORE::length($char[$i+1]) == 4) {
1597 0 0       0 push @range, grep {($char[$i-1] le $_) and ($_ le $char[$i+1])} chars4();
  0         0  
1598             }
1599             else {
1600 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1601             }
1602             }
1603             else {
1604 0         0 croak "Invalid tr/// range (over 4octets) \"\\x" . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]) . '"';
1605             }
1606              
1607 0         0 splice @char, $i-1, 3, @range;
1608             }
1609              
1610 0         0 return @char;
1611             }
1612              
1613             #
1614             # KPS9566 open character class
1615             #
1616             sub _cc {
1617 0 50   906   0 if (scalar(@_) == 0) {
    100          
    50          
1618 906         1673 die __FILE__, ": subroutine cc got no parameter.\n";
1619             }
1620             elsif (scalar(@_) == 1) {
1621 0         0 return sprintf('\x%02X',$_[0]);
1622             }
1623             elsif (scalar(@_) == 2) {
1624 453 50       1268 if ($_[0] > $_[1]) {
    50          
    50          
1625 453         942 die __FILE__, ": subroutine cc got \$_[0] > \$_[1] parameters).\n";
1626             }
1627             elsif ($_[0] == $_[1]) {
1628 0         0 return sprintf('\x%02X',$_[0]);
1629             }
1630             elsif (($_[0]+1) == $_[1]) {
1631 0         0 return sprintf('[\\x%02X\\x%02X]',$_[0],$_[1]);
1632             }
1633             else {
1634 0         0 return sprintf('[\\x%02X-\\x%02X]',$_[0],$_[1]);
1635             }
1636             }
1637             else {
1638 453         1988 die __FILE__, ": subroutine cc got 3 or more parameters (@{[scalar(@_)]} parameters).\n";
  0         0  
1639             }
1640             }
1641              
1642             #
1643             # KPS9566 octet range
1644             #
1645             sub _octets {
1646 0     799   0 my $length = shift @_;
1647              
1648 799 100       1210 if ($length == 1) {
    50          
    0          
    0          
1649 799         1635 my($a1) = unpack 'C', $_[0];
1650 406         1197 my($z1) = unpack 'C', $_[1];
1651              
1652 406 50       708 if ($a1 > $z1) {
1653 406         812 croak 'Invalid [] range in regexp (CORE::ord(A) > CORE::ord(B)) ' . '\x' . unpack('H*',$a1) . '-\x' . unpack('H*',$z1);
1654             }
1655              
1656 0 100       0 if ($a1 == $z1) {
    50          
1657 406         1103 return sprintf('\x%02X',$a1);
1658             }
1659             elsif (($a1+1) == $z1) {
1660 20         93 return sprintf('\x%02X\x%02X',$a1,$z1);
1661             }
1662             else {
1663 0         0 return sprintf('\x%02X-\x%02X',$a1,$z1);
1664             }
1665             }
1666             elsif ($length == 2) {
1667 386         2346 my($a1,$a2) = unpack 'CC', $_[0];
1668 393         837 my($z1,$z2) = unpack 'CC', $_[1];
1669 393         645 my($A1,$A2) = unpack 'CC', $_[2];
1670 393         567 my($Z1,$Z2) = unpack 'CC', $_[3];
1671              
1672 393 100       562 if ($a1 == $z1) {
    50          
1673             return (
1674             # 11111111 222222222222
1675             # A A Z
1676 393         611 _cc($a1) . _cc($a2,$z2), # a2-z2
1677             );
1678             }
1679             elsif (($a1+1) == $z1) {
1680             return (
1681             # 11111111111 222222222222
1682             # A Z A Z
1683 333         444 _cc($a1) . _cc($a2,$Z2), # a2-
1684             _cc( $z1) . _cc($A2,$z2), # -z2
1685             );
1686             }
1687             else {
1688             return (
1689             # 1111111111111111 222222222222
1690             # A Z A Z
1691 60         98 _cc($a1) . _cc($a2,$Z2), # a2-
1692             _cc($a1+1,$z1-1) . _cc($A2,$Z2), # -
1693             _cc( $z1) . _cc($A2,$z2), # -z2
1694             );
1695             }
1696             }
1697             elsif ($length == 3) {
1698 0         0 my($a1,$a2,$a3) = unpack 'CCC', $_[0];
1699 0         0 my($z1,$z2,$z3) = unpack 'CCC', $_[1];
1700 0         0 my($A1,$A2,$A3) = unpack 'CCC', $_[2];
1701 0         0 my($Z1,$Z2,$Z3) = unpack 'CCC', $_[3];
1702              
1703 0 0       0 if ($a1 == $z1) {
    0          
1704 0 0       0 if ($a2 == $z2) {
    0          
1705             return (
1706             # 11111111 22222222 333333333333
1707             # A A A Z
1708 0         0 _cc($a1) . _cc($a2) . _cc($a3,$z3), # a3-z3
1709             );
1710             }
1711             elsif (($a2+1) == $z2) {
1712             return (
1713             # 11111111 22222222222 333333333333
1714             # A A Z A Z
1715 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1716             _cc($a1) . _cc( $z2) . _cc($A3,$z3), # -z3
1717             );
1718             }
1719             else {
1720             return (
1721             # 11111111 2222222222222222 333333333333
1722             # A A Z A Z
1723 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1724             _cc($a1) . _cc($a2+1,$z2-1) . _cc($A3,$Z3), # -
1725             _cc($a1) . _cc( $z2) . _cc($A3,$z3), # -z3
1726             );
1727             }
1728             }
1729             elsif (($a1+1) == $z1) {
1730             return (
1731             # 11111111111 22222222222222 333333333333
1732             # A Z A Z A Z
1733 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1734             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3), # -
1735             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3), # -
1736             _cc( $z1) . _cc( $z2) . _cc($A3,$z3), # -z3
1737             );
1738             }
1739             else {
1740             return (
1741             # 1111111111111111 22222222222222 333333333333
1742             # A Z A Z A Z
1743 0         0 _cc($a1) . _cc($a2) . _cc($a3,$Z3), # a3-
1744             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3), # -
1745             _cc($a1+1,$z1-1) . _cc($A2,$Z2) . _cc($A3,$Z3), # -
1746             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3), # -
1747             _cc( $z1) . _cc( $z2) . _cc($A3,$z3), # -z3
1748             );
1749             }
1750             }
1751             elsif ($length == 4) {
1752 0         0 my($a1,$a2,$a3,$a4) = unpack 'CCCC', $_[0];
1753 0         0 my($z1,$z2,$z3,$z4) = unpack 'CCCC', $_[1];
1754 0         0 my($A1,$A2,$A3,$A4) = unpack 'CCCC', $_[0];
1755 0         0 my($Z1,$Z2,$Z3,$Z4) = unpack 'CCCC', $_[1];
1756              
1757 0 0       0 if ($a1 == $z1) {
    0          
1758 0 0       0 if ($a2 == $z2) {
    0          
1759 0 0       0 if ($a3 == $z3) {
    0          
1760             return (
1761             # 11111111 22222222 33333333 444444444444
1762             # A A A A Z
1763 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$z4), # a4-z4
1764             );
1765             }
1766             elsif (($a3+1) == $z3) {
1767             return (
1768             # 11111111 22222222 33333333333 444444444444
1769             # A A A Z A Z
1770 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1771             _cc($a1) . _cc($a2) . _cc( $z3) . _cc($A4,$z4), # -z4
1772             );
1773             }
1774             else {
1775             return (
1776             # 11111111 22222222 3333333333333333 444444444444
1777             # A A A Z A Z
1778 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1779             _cc($a1) . _cc($a2) . _cc($a3+1,$z3-1) . _cc($A4,$Z4), # -
1780             _cc($a1) . _cc($a2) . _cc( $z3) . _cc($A4,$z4), # -z4
1781             );
1782             }
1783             }
1784             elsif (($a2+1) == $z2) {
1785             return (
1786             # 11111111 22222222222 33333333333333 444444444444
1787             # A A Z A Z A Z
1788 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1789             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1790             _cc($a1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1791             _cc($a1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1792             );
1793             }
1794             else {
1795             return (
1796             # 11111111 2222222222222222 33333333333333 444444444444
1797             # A A Z A Z A Z
1798 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1799             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1800             _cc($a1) . _cc($a2+1,$z2-1) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1801             _cc($a1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1802             _cc($a1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1803             );
1804             }
1805             }
1806             elsif (($a1+1) == $z1) {
1807             return (
1808             # 11111111111 22222222222222 33333333333333 444444444444
1809             # A Z A Z A Z A Z
1810 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1811             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1812             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1813             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1814             _cc( $z1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1815             _cc( $z1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1816             );
1817             }
1818             else {
1819             return (
1820             # 1111111111111111 22222222222222 33333333333333 444444444444
1821             # A Z A Z A Z A Z
1822 0         0 _cc($a1) . _cc($a2) . _cc($a3) . _cc($a4,$Z4), # a4-
1823             _cc($a1) . _cc($a2) . _cc($a3+1,$Z3) . _cc($A4,$Z4), # -
1824             _cc($a1) . _cc($a2+1,$Z2) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1825             _cc($a1+1,$z1-1) . _cc($A2,$Z2) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1826             _cc( $z1) . _cc($A2,$z2-1) . _cc($A3,$Z3) . _cc($A4,$Z4), # -
1827             _cc( $z1) . _cc( $z2) . _cc($A3,$z3-1) . _cc($A4,$Z4), # -
1828             _cc( $z1) . _cc( $z2) . _cc( $z3) . _cc($A4,$z4), # -z4
1829             );
1830             }
1831             }
1832             else {
1833 0         0 die __FILE__, ": subroutine _octets got invalid length ($length).\n";
1834             }
1835             }
1836              
1837             #
1838             # KPS9566 range regexp
1839             #
1840             sub _range_regexp {
1841 0     517   0 my($length,$first,$last) = @_;
1842              
1843 517         1061 my @range_regexp = ();
1844 517 50       709 if (not exists $range_tr{$length}) {
1845 517         1325 return @range_regexp;
1846             }
1847              
1848 0         0 my @ranges = @{ $range_tr{$length} };
  517         700  
1849 517         1217 while (my @range = splice(@ranges,0,$length)) {
1850 517         1496 my $min = '';
1851 1165         1570 my $max = '';
1852 1165         1300 for (my $i=0; $i < $length; $i++) {
1853 1165         2059 $min .= pack 'C', $range[$i][0];
1854 1558         3326 $max .= pack 'C', $range[$i][-1];
1855             }
1856              
1857             # min___max
1858             # FIRST_____________LAST
1859             # (nothing)
1860              
1861 1558 50 66     2900 if ($max lt $first) {
    100 100        
    50 33        
    100 100        
    100 66        
    100 66        
    50 66        
1862             }
1863              
1864             # **********
1865             # min_________max
1866             # FIRST_____________LAST
1867             # **********
1868              
1869             elsif (($min le $first) and ($first le $max) and ($max le $last)) {
1870 1165         9094 push @range_regexp, _octets($length,$first,$max,$min,$max);
1871             }
1872              
1873             # **********************
1874             # min________________max
1875             # FIRST_____________LAST
1876             # **********************
1877              
1878             elsif (($min eq $first) and ($max eq $last)) {
1879 20         109 push @range_regexp, _octets($length,$first,$last,$min,$max);
1880             }
1881              
1882             # *********
1883             # min___max
1884             # FIRST_____________LAST
1885             # *********
1886              
1887             elsif (($first le $min) and ($max le $last)) {
1888 0         0 push @range_regexp, _octets($length,$min,$max,$min,$max);
1889             }
1890              
1891             # **********************
1892             # min__________________________max
1893             # FIRST_____________LAST
1894             # **********************
1895              
1896             elsif (($min le $first) and ($last le $max)) {
1897 20         47 push @range_regexp, _octets($length,$first,$last,$min,$max);
1898             }
1899              
1900             # *********
1901             # min________max
1902             # FIRST_____________LAST
1903             # *********
1904              
1905             elsif (($first le $min) and ($min le $last) and ($last le $max)) {
1906 699         1556 push @range_regexp, _octets($length,$min,$last,$min,$max);
1907             }
1908              
1909             # min___max
1910             # FIRST_____________LAST
1911             # (nothing)
1912              
1913             elsif ($last lt $min) {
1914             }
1915              
1916             else {
1917 60         103 die __FILE__, ": subroutine _range_regexp panic.\n";
1918             }
1919             }
1920              
1921 0         0 return @range_regexp;
1922             }
1923              
1924             #
1925             # KPS9566 open character list for qr and not qr
1926             #
1927             sub _charlist {
1928              
1929 517     758   1200 my $modifier = pop @_;
1930 758         1167 my @char = @_;
1931              
1932 758 100       1648 my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
1933              
1934             # unescape character
1935 758         1749 for (my $i=0; $i <= $#char; $i++) {
1936              
1937             # escape - to ...
1938 758 100 100     2259 if ($char[$i] eq '-') {
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    100          
    100          
    100          
    100          
1939 2648 100 100     17653 if ((0 < $i) and ($i < $#char)) {
1940 522         1811 $char[$i] = '...';
1941             }
1942             }
1943              
1944             # octal escape sequence
1945             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
1946 497         1030 $char[$i] = octchr($1);
1947             }
1948              
1949             # hexadecimal escape sequence
1950             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
1951 0         0 $char[$i] = hexchr($1);
1952             }
1953              
1954             # \b{...} --> b\{...}
1955             # \B{...} --> B\{...}
1956             # \N{CHARNAME} --> N\{CHARNAME}
1957             # \p{PROPERTY} --> p\{PROPERTY}
1958             # \P{PROPERTY} --> P\{PROPERTY}
1959             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} ) \z/oxms) {
1960 0         0 $char[$i] = $1 . '\\' . $2;
1961             }
1962              
1963             # \p, \P, \X --> p, P, X
1964             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
1965 0         0 $char[$i] = $1;
1966             }
1967              
1968             elsif ($char[$i] =~ /\A \\ ([0-7]{2,3}) \z/oxms) {
1969 0         0 $char[$i] = CORE::chr oct $1;
1970             }
1971             elsif ($char[$i] =~ /\A \\x ([0-9A-Fa-f]{1,2}) \z/oxms) {
1972 0         0 $char[$i] = CORE::chr hex $1;
1973             }
1974             elsif ($char[$i] =~ /\A \\c ([\x40-\x5F]) \z/oxms) {
1975 206         909 $char[$i] = CORE::chr(CORE::ord($1) & 0x1F);
1976             }
1977             elsif ($char[$i] =~ /\A (\\ [0nrtfbaedswDSWHVhvR]) \z/oxms) {
1978             $char[$i] = {
1979             '\0' => "\0",
1980             '\n' => "\n",
1981             '\r' => "\r",
1982             '\t' => "\t",
1983             '\f' => "\f",
1984             '\b' => "\x08", # \b means backspace in character class
1985             '\a' => "\a",
1986             '\e' => "\e",
1987             '\d' => '[0-9]',
1988              
1989             # Vertical tabs are now whitespace
1990             # \s in a regex now matches a vertical tab in all circumstances.
1991             # http://search.cpan.org/dist/perl-5.18.0/pod/perldelta.pod#Vertical_tabs_are_now_whitespace
1992             # \t \n \v \f \r space
1993             # '\s' => '[\x09\x0A \x0C\x0D\x20]',
1994             # '\s' => '[\x09\x0A\x0B\x0C\x0D\x20]',
1995             '\s' => '\s',
1996              
1997             '\w' => '[0-9A-Z_a-z]',
1998             '\D' => '${Ekps9566::eD}',
1999             '\S' => '${Ekps9566::eS}',
2000             '\W' => '${Ekps9566::eW}',
2001              
2002             '\H' => '${Ekps9566::eH}',
2003             '\V' => '${Ekps9566::eV}',
2004             '\h' => '[\x09\x20]',
2005             '\v' => '[\x0A\x0B\x0C\x0D]',
2006             '\R' => '${Ekps9566::eR}',
2007              
2008 0         0 }->{$1};
2009             }
2010              
2011             # POSIX-style character classes
2012             elsif ($ignorecase and ($char[$i] =~ /\A ( \[\: \^? (?:lower|upper) :\] ) \z/oxms)) {
2013             $char[$i] = {
2014              
2015             '[:lower:]' => '[\x41-\x5A\x61-\x7A]',
2016             '[:upper:]' => '[\x41-\x5A\x61-\x7A]',
2017             '[:^lower:]' => '${Ekps9566::not_lower_i}',
2018             '[:^upper:]' => '${Ekps9566::not_upper_i}',
2019              
2020 33         579 }->{$1};
2021             }
2022             elsif ($char[$i] =~ /\A ( \[\: \^? (?:alnum|alpha|ascii|blank|cntrl|digit|graph|lower|print|punct|space|upper|word|xdigit) :\] ) \z/oxms) {
2023             $char[$i] = {
2024              
2025             '[:alnum:]' => '[\x30-\x39\x41-\x5A\x61-\x7A]',
2026             '[:alpha:]' => '[\x41-\x5A\x61-\x7A]',
2027             '[:ascii:]' => '[\x00-\x7F]',
2028             '[:blank:]' => '[\x09\x20]',
2029             '[:cntrl:]' => '[\x00-\x1F\x7F]',
2030             '[:digit:]' => '[\x30-\x39]',
2031             '[:graph:]' => '[\x21-\x7F]',
2032             '[:lower:]' => '[\x61-\x7A]',
2033             '[:print:]' => '[\x20-\x7F]',
2034             '[:punct:]' => '[\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E]',
2035              
2036             # P.174 POSIX-Style Character Classes
2037             # in Chapter 5: Pattern Matching
2038             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2039              
2040             # P.311 11.2.4 Character Classes and other Special Escapes
2041             # in Chapter 11: perlre: Perl regular expressions
2042             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
2043              
2044             # P.210 POSIX-Style Character Classes
2045             # in Chapter 5: Pattern Matching
2046             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2047              
2048             '[:space:]' => '[\s\x0B]', # "\s" plus vertical tab ("\cK")
2049              
2050             '[:upper:]' => '[\x41-\x5A]',
2051             '[:word:]' => '[\x30-\x39\x41-\x5A\x5F\x61-\x7A]',
2052             '[:xdigit:]' => '[\x30-\x39\x41-\x46\x61-\x66]',
2053             '[:^alnum:]' => '${Ekps9566::not_alnum}',
2054             '[:^alpha:]' => '${Ekps9566::not_alpha}',
2055             '[:^ascii:]' => '${Ekps9566::not_ascii}',
2056             '[:^blank:]' => '${Ekps9566::not_blank}',
2057             '[:^cntrl:]' => '${Ekps9566::not_cntrl}',
2058             '[:^digit:]' => '${Ekps9566::not_digit}',
2059             '[:^graph:]' => '${Ekps9566::not_graph}',
2060             '[:^lower:]' => '${Ekps9566::not_lower}',
2061             '[:^print:]' => '${Ekps9566::not_print}',
2062             '[:^punct:]' => '${Ekps9566::not_punct}',
2063             '[:^space:]' => '${Ekps9566::not_space}',
2064             '[:^upper:]' => '${Ekps9566::not_upper}',
2065             '[:^word:]' => '${Ekps9566::not_word}',
2066             '[:^xdigit:]' => '${Ekps9566::not_xdigit}',
2067              
2068 8         60 }->{$1};
2069             }
2070             elsif ($char[$i] =~ /\A \\ ($q_char) \z/oxms) {
2071 70         1612 $char[$i] = $1;
2072             }
2073             }
2074              
2075             # open character list
2076 7         35 my @singleoctet = ();
2077 758         1259 my @multipleoctet = ();
2078 758         1026 for (my $i=0; $i <= $#char; ) {
2079              
2080             # escaped -
2081 758 100 100     1774 if (defined($char[$i+1]) and ($char[$i+1] eq '...')) {
    100          
    100          
    50          
    50          
    100          
2082 2151         8511 $i += 1;
2083 497         632 next;
2084             }
2085              
2086             # make range regexp
2087             elsif ($char[$i] eq '...') {
2088              
2089             # range error
2090 497 50       859 if (CORE::length($char[$i-1]) > CORE::length($char[$i+1])) {
    100          
2091 497         1820 croak 'Invalid [] range in regexp (length(A) > length(B)) ' . '\x' . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]);
2092             }
2093             elsif (CORE::length($char[$i-1]) == CORE::length($char[$i+1])) {
2094 0 50       0 if ($char[$i-1] gt $char[$i+1]) {
2095 477         1094 croak 'Invalid [] range in regexp (CORE::ord(A) > CORE::ord(B)) ' . '\x' . unpack('H*',$char[$i-1]) . '-\x' . unpack('H*',$char[$i+1]);
2096             }
2097             }
2098              
2099             # make range regexp per length
2100 0         0 for my $length (CORE::length($char[$i-1]) .. CORE::length($char[$i+1])) {
2101 497         1371 my @regexp = ();
2102              
2103             # is first and last
2104 517 100 100     719 if (($length == CORE::length($char[$i-1])) and ($length == CORE::length($char[$i+1]))) {
    100 33        
    50          
    50          
2105 517         1757 push @regexp, _range_regexp($length, $char[$i-1], $char[$i+1]);
2106             }
2107              
2108             # is first
2109             elsif ($length == CORE::length($char[$i-1])) {
2110 477         1178 push @regexp, _range_regexp($length, $char[$i-1], "\xFF" x $length);
2111             }
2112              
2113             # is inside in first and last
2114             elsif ((CORE::length($char[$i-1]) < $length) and ($length < CORE::length($char[$i+1]))) {
2115 20         91 push @regexp, _range_regexp($length, "\x00" x $length, "\xFF" x $length);
2116             }
2117              
2118             # is last
2119             elsif ($length == CORE::length($char[$i+1])) {
2120 0         0 push @regexp, _range_regexp($length, "\x00" x $length, $char[$i+1]);
2121             }
2122              
2123             else {
2124 20         71 die __FILE__, ": subroutine make_regexp panic.\n";
2125             }
2126              
2127 0 100       0 if ($length == 1) {
2128 517         1093 push @singleoctet, @regexp;
2129             }
2130             else {
2131 386         950 push @multipleoctet, @regexp;
2132             }
2133             }
2134              
2135 131         298 $i += 2;
2136             }
2137              
2138             # with /i modifier
2139             elsif ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) {
2140 497 100       1383 if ($modifier =~ /i/oxms) {
2141 764         1236 my $uc = Ekps9566::uc($char[$i]);
2142 192         300 my $fc = Ekps9566::fc($char[$i]);
2143 192 50       326 if ($uc ne $fc) {
2144 192 50       325 if (CORE::length($fc) == 1) {
2145 192         256 push @singleoctet, $uc, $fc;
2146             }
2147             else {
2148 192         347 push @singleoctet, $uc;
2149 0         0 push @multipleoctet, $fc;
2150             }
2151             }
2152             else {
2153 0         0 push @singleoctet, $char[$i];
2154             }
2155             }
2156             else {
2157 0         0 push @singleoctet, $char[$i];
2158             }
2159 572         847 $i += 1;
2160             }
2161              
2162             # single character of single octet code
2163             elsif ($char[$i] =~ /\A (?: \\h ) \z/oxms) {
2164 764         1285 push @singleoctet, "\t", "\x20";
2165 0         0 $i += 1;
2166             }
2167             elsif ($char[$i] =~ /\A (?: \\v ) \z/oxms) {
2168 0         0 push @singleoctet, "\x0A", "\x0B", "\x0C", "\x0D";
2169 0         0 $i += 1;
2170             }
2171             elsif ($char[$i] =~ /\A (?: \\d | \\s | \\w ) \z/oxms) {
2172 0         0 push @singleoctet, $char[$i];
2173 2         6 $i += 1;
2174             }
2175              
2176             # single character of multiple-octet code
2177             else {
2178 2         5 push @multipleoctet, $char[$i];
2179 391         689 $i += 1;
2180             }
2181             }
2182              
2183             # quote metachar
2184 391         664 for (@singleoctet) {
2185 758 50       1460 if ($_ eq '...') {
    100          
    100          
    100          
    100          
2186 1364         6086 $_ = '-';
2187             }
2188             elsif (/\A \n \z/oxms) {
2189 0         0 $_ = '\n';
2190             }
2191             elsif (/\A \r \z/oxms) {
2192 8         18 $_ = '\r';
2193             }
2194             elsif (/\A ([\x00-\x20\x7F-\xFF]) \z/oxms) {
2195 8         18 $_ = sprintf('\x%02X', CORE::ord $1);
2196             }
2197             elsif (/\A [\x00-\xFF] \z/oxms) {
2198 1         6 $_ = quotemeta $_;
2199             }
2200             }
2201 939         1342 for (@multipleoctet) {
2202 758 100       1396 if (/\A ([\x80-\xFF].*) ([\x00-\xFF]) \z/oxms) {
2203 844         1915 $_ = $1 . quotemeta $2;
2204             }
2205             }
2206              
2207             # return character list
2208 307         701 return \@singleoctet, \@multipleoctet;
2209             }
2210              
2211             #
2212             # KPS9566 octal escape sequence
2213             #
2214             sub octchr {
2215 758     5 0 2413 my($octdigit) = @_;
2216              
2217 5         13 my @binary = ();
2218 5         9 for my $octal (split(//,$octdigit)) {
2219             push @binary, {
2220             '0' => '000',
2221             '1' => '001',
2222             '2' => '010',
2223             '3' => '011',
2224             '4' => '100',
2225             '5' => '101',
2226             '6' => '110',
2227             '7' => '111',
2228 5         37 }->{$octal};
2229             }
2230 50         175 my $binary = join '', @binary;
2231              
2232             my $octchr = {
2233             # 1234567
2234             1 => pack('B*', "0000000$binary"),
2235             2 => pack('B*', "000000$binary"),
2236             3 => pack('B*', "00000$binary"),
2237             4 => pack('B*', "0000$binary"),
2238             5 => pack('B*', "000$binary"),
2239             6 => pack('B*', "00$binary"),
2240             7 => pack('B*', "0$binary"),
2241             0 => pack('B*', "$binary"),
2242              
2243 5         14 }->{CORE::length($binary) % 8};
2244              
2245 5         69 return $octchr;
2246             }
2247              
2248             #
2249             # KPS9566 hexadecimal escape sequence
2250             #
2251             sub hexchr {
2252 5     5 0 20 my($hexdigit) = @_;
2253              
2254             my $hexchr = {
2255             1 => pack('H*', "0$hexdigit"),
2256             0 => pack('H*', "$hexdigit"),
2257              
2258 5         15 }->{CORE::length($_[0]) % 2};
2259              
2260 5         77 return $hexchr;
2261             }
2262              
2263             #
2264             # KPS9566 open character list for qr
2265             #
2266             sub charlist_qr {
2267              
2268 5     519 0 21 my $modifier = pop @_;
2269 519         1095 my @char = @_;
2270              
2271 519         1295 my($singleoctet, $multipleoctet) = _charlist(@char, $modifier);
2272 519         1585 my @singleoctet = @$singleoctet;
2273 519         1093 my @multipleoctet = @$multipleoctet;
2274              
2275             # return character list
2276 519 100       862 if (scalar(@singleoctet) >= 1) {
2277              
2278             # with /i modifier
2279 519 100       1231 if ($modifier =~ m/i/oxms) {
2280 384         846 my %singleoctet_ignorecase = ();
2281 107         150 for (@singleoctet) {
2282 107   100     165 while (s/ \A \\x(..) - \\x(..) //oxms or s/ \A \\x((..)) //oxms) {
2283 272         848 for my $ord (hex($1) .. hex($2)) {
2284 80         263 my $char = CORE::chr($ord);
2285 1046         1382 my $uc = Ekps9566::uc($char);
2286 1046         1243 my $fc = Ekps9566::fc($char);
2287 1046 100       1445 if ($uc eq $fc) {
2288 1046         1470 $singleoctet_ignorecase{unpack 'C*', $char} = 1;
2289             }
2290             else {
2291 457 50       1004 if (CORE::length($fc) == 1) {
2292 589         715 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2293 589         1144 $singleoctet_ignorecase{unpack 'C*', $fc} = 1;
2294             }
2295             else {
2296 589         1383 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2297 0         0 push @multipleoctet, join '', map {sprintf('\x%02X',$_)} unpack 'C*', $fc;
  0         0  
2298             }
2299             }
2300             }
2301             }
2302 0 100       0 if ($_ ne '') {
2303 272         436 $singleoctet_ignorecase{unpack 'C*', $_} = 1;
2304             }
2305             }
2306 192         460 my $i = 0;
2307 107         207 my @singleoctet_ignorecase = ();
2308 107         142 for my $ord (0 .. 255) {
2309 107 100       195 if (exists $singleoctet_ignorecase{$ord}) {
2310 27392         31025 push @{$singleoctet_ignorecase[$i]}, $ord;
  1577         1402  
2311             }
2312             else {
2313 1577         2411 $i++;
2314             }
2315             }
2316 25815         24957 @singleoctet = ();
2317 107         182 for my $range (@singleoctet_ignorecase) {
2318 107 100       240 if (ref $range) {
2319 11412 100       17403 if (scalar(@{$range}) == 1) {
  214 50       214  
2320 214         313 push @singleoctet, sprintf('\x%02X', @{$range}[0]);
  5         9  
2321             }
2322 5         74 elsif (scalar(@{$range}) == 2) {
2323 209         281 push @singleoctet, sprintf('\x%02X\x%02X', @{$range}[0], @{$range}[-1]);
  0         0  
  0         0  
2324             }
2325             else {
2326 0         0 push @singleoctet, sprintf('\x%02X-\x%02X', @{$range}[0], @{$range}[-1]);
  209         257  
  209         260  
2327             }
2328             }
2329             }
2330             }
2331              
2332 209         881 my $not_anchor = '';
2333 384         663 $not_anchor = '(?![\x81-\xFE])';
2334              
2335 384         531 push @multipleoctet, join('', $not_anchor, '[', @singleoctet, ']' );
2336             }
2337 384 100       1019 if (scalar(@multipleoctet) >= 2) {
2338 519         1167 return '(?:' . join('|', @multipleoctet) . ')';
2339             }
2340             else {
2341 131         883 return $multipleoctet[0];
2342             }
2343             }
2344              
2345             #
2346             # KPS9566 open character list for not qr
2347             #
2348             sub charlist_not_qr {
2349              
2350 388     239 0 1729 my $modifier = pop @_;
2351 239         407 my @char = @_;
2352              
2353 239         510 my($singleoctet, $multipleoctet) = _charlist(@char, $modifier);
2354 239         509 my @singleoctet = @$singleoctet;
2355 239         463 my @multipleoctet = @$multipleoctet;
2356              
2357             # with /i modifier
2358 239 100       408 if ($modifier =~ m/i/oxms) {
2359 239         612 my %singleoctet_ignorecase = ();
2360 128         175 for (@singleoctet) {
2361 128   100     175 while (s/ \A \\x(..) - \\x(..) //oxms or s/ \A \\x((..)) //oxms) {
2362 272         816 for my $ord (hex($1) .. hex($2)) {
2363 80         314 my $char = CORE::chr($ord);
2364 1046         1349 my $uc = Ekps9566::uc($char);
2365 1046         1340 my $fc = Ekps9566::fc($char);
2366 1046 100       1522 if ($uc eq $fc) {
2367 1046         1530 $singleoctet_ignorecase{unpack 'C*', $char} = 1;
2368             }
2369             else {
2370 457 50       1011 if (CORE::length($fc) == 1) {
2371 589         733 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2372 589         1181 $singleoctet_ignorecase{unpack 'C*', $fc} = 1;
2373             }
2374             else {
2375 589         1411 $singleoctet_ignorecase{unpack 'C*', $uc} = 1;
2376 0         0 push @multipleoctet, join '', map {sprintf('\x%02X',$_)} unpack 'C*', $fc;
  0         0  
2377             }
2378             }
2379             }
2380             }
2381 0 100       0 if ($_ ne '') {
2382 272         432 $singleoctet_ignorecase{unpack 'C*', $_} = 1;
2383             }
2384             }
2385 192         418 my $i = 0;
2386 128         149 my @singleoctet_ignorecase = ();
2387 128         228 for my $ord (0 .. 255) {
2388 128 100       197 if (exists $singleoctet_ignorecase{$ord}) {
2389 32768         36677 push @{$singleoctet_ignorecase[$i]}, $ord;
  1577         1410  
2390             }
2391             else {
2392 1577         2734 $i++;
2393             }
2394             }
2395 31191         30490 @singleoctet = ();
2396 128         200 for my $range (@singleoctet_ignorecase) {
2397 128 100       272 if (ref $range) {
2398 11412 100       17558 if (scalar(@{$range}) == 1) {
  214 50       217  
2399 214         336 push @singleoctet, sprintf('\x%02X', @{$range}[0]);
  5         19  
2400             }
2401 5         65 elsif (scalar(@{$range}) == 2) {
2402 209         272 push @singleoctet, sprintf('\x%02X\x%02X', @{$range}[0], @{$range}[-1]);
  0         0  
  0         0  
2403             }
2404             else {
2405 0         0 push @singleoctet, sprintf('\x%02X-\x%02X', @{$range}[0], @{$range}[-1]);
  209         228  
  209         262  
2406             }
2407             }
2408             }
2409             }
2410              
2411             # return character list
2412 209 100       1221 if (scalar(@multipleoctet) >= 1) {
2413 239 100       458 if (scalar(@singleoctet) >= 1) {
2414              
2415             # any character other than multiple-octet and single octet character class
2416 114         204 return '(?!' . join('|', @multipleoctet) . ')(?:[^\x81-\xFE' . join('', @singleoctet) . ']|[\x81-\xFE][\x00-\xFF])';
2417             }
2418             else {
2419              
2420             # any character other than multiple-octet character class
2421 70         469 return '(?!' . join('|', @multipleoctet) . ")(?:$your_char)";
2422             }
2423             }
2424             else {
2425 44 50       271 if (scalar(@singleoctet) >= 1) {
2426              
2427             # any character other than single octet character class
2428 125         210 return '(?:[^\x81-\xFE' . join('', @singleoctet) . ']|[\x81-\xFE][\x00-\xFF])';
2429             }
2430             else {
2431              
2432             # any character
2433 125         683 return "(?:$your_char)";
2434             }
2435             }
2436             }
2437              
2438             #
2439             # open file in read mode
2440             #
2441             sub _open_r {
2442 0     768   0 my(undef,$file) = @_;
2443 389     389   6165 use Fcntl qw(O_RDONLY);
  389         883  
  389         80461  
2444 768         2256 return CORE::sysopen($_[0], $file, &O_RDONLY);
2445             }
2446              
2447             #
2448             # open file in append mode
2449             #
2450             sub _open_a {
2451 768     384   32068 my(undef,$file) = @_;
2452 389     389   2706 use Fcntl qw(O_WRONLY O_APPEND O_CREAT);
  389         2483  
  389         5602701  
2453 384         1218 return CORE::sysopen($_[0], $file, &O_WRONLY|&O_APPEND|&O_CREAT);
2454             }
2455              
2456             #
2457             # safe system
2458             #
2459             sub _systemx {
2460              
2461             # P.707 29.2.33. exec
2462             # in Chapter 29: Functions
2463             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2464             #
2465             # Be aware that in older releases of Perl, exec (and system) did not flush
2466             # your output buffer, so you needed to enable command buffering by setting $|
2467             # on one or more filehandles to avoid lost output in the case of exec, or
2468             # misordererd output in the case of system. This situation was largely remedied
2469             # in the 5.6 release of Perl. (So, 5.005 release not yet.)
2470              
2471             # P.855 exec
2472             # in Chapter 27: Functions
2473             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2474             #
2475             # In very old release of Perl (before v5.6), exec (and system) did not flush
2476             # your output buffer, so you needed to enable command buffering by setting $|
2477             # on one or more filehandles to avoid lost output with exec or misordered
2478             # output with system.
2479              
2480 384     384   49065 $| = 1;
2481              
2482             # P.565 23.1.2. Cleaning Up Your Environment
2483             # in Chapter 23: Security
2484             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2485              
2486             # P.656 Cleaning Up Your Environment
2487             # in Chapter 20: Security
2488             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2489              
2490             # local $ENV{'PATH'} = '.';
2491 384         1669 local @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
2492              
2493             # P.707 29.2.33. exec
2494             # in Chapter 29: Functions
2495             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2496             #
2497             # As we mentioned earlier, exec treats a discrete list of arguments as an
2498             # indication that it should bypass shell processing. However, there is one
2499             # place where you might still get tripped up. The exec call (and system, too)
2500             # will not distinguish between a single scalar argument and an array containing
2501             # only one element.
2502             #
2503             # @args = ("echo surprise"); # just one element in list
2504             # exec @args # still subject to shell escapes
2505             # or die "exec: $!"; # because @args == 1
2506             #
2507             # To avoid this, you can use the PATHNAME syntax, explicitly duplicating the
2508             # first argument as the pathname, which forces the rest of the arguments to be
2509             # interpreted as a list, even if there is only one of them:
2510             #
2511             # exec { $args[0] } @args # safe even with one-argument list
2512             # or die "can't exec @args: $!";
2513              
2514             # P.855 exec
2515             # in Chapter 27: Functions
2516             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2517             #
2518             # As we mentioned earlier, exec treats a discrete list of arguments as a
2519             # directive to bypass shell processing. However, there is one place where
2520             # you might still get tripped up. The exec call (and system, too) cannot
2521             # distinguish between a single scalar argument and an array containing
2522             # only one element.
2523             #
2524             # @args = ("echo surprise"); # just one element in list
2525             # exec @args # still subject to shell escapes
2526             # || die "exec: $!"; # because @args == 1
2527             #
2528             # To avoid this, use the PATHNAME syntax, explicitly duplicating the first
2529             # argument as the pathname, which forces the rest of the arguments to be
2530             # interpreted as a list, even if there is only one of them:
2531             #
2532             # exec { $args[0] } @args # safe even with one-argument list
2533             # || die "can't exec @args: $!";
2534              
2535 384         3901 return CORE::system { $_[0] } @_; # safe even with one-argument list
  384         1042  
2536             }
2537              
2538             #
2539             # KPS9566 order to character (with parameter)
2540             #
2541             sub Ekps9566::chr(;$) {
2542              
2543 384 0   0 0 41085313 my $c = @_ ? $_[0] : $_;
2544              
2545 0 0       0 if ($c == 0x00) {
2546 0         0 return "\x00";
2547             }
2548             else {
2549 0         0 my @chr = ();
2550 0         0 while ($c > 0) {
2551 0         0 unshift @chr, ($c % 0x100);
2552 0         0 $c = int($c / 0x100);
2553             }
2554 0         0 return pack 'C*', @chr;
2555             }
2556             }
2557              
2558             #
2559             # KPS9566 order to character (without parameter)
2560             #
2561             sub Ekps9566::chr_() {
2562              
2563 0     0 0 0 my $c = $_;
2564              
2565 0 0       0 if ($c == 0x00) {
2566 0         0 return "\x00";
2567             }
2568             else {
2569 0         0 my @chr = ();
2570 0         0 while ($c > 0) {
2571 0         0 unshift @chr, ($c % 0x100);
2572 0         0 $c = int($c / 0x100);
2573             }
2574 0         0 return pack 'C*', @chr;
2575             }
2576             }
2577              
2578             #
2579             # KPS9566 stacked file test expr
2580             #
2581             sub Ekps9566::filetest {
2582              
2583 0     0 0 0 my $file = pop @_;
2584 0         0 my $filetest = substr(pop @_, 1);
2585              
2586 0 0       0 unless (CORE::eval qq{Ekps9566::$filetest(\$file)}) {
2587 0         0 return '';
2588             }
2589 0         0 for my $filetest (CORE::reverse @_) {
2590 0 0       0 unless (CORE::eval qq{ $filetest _ }) {
2591 0         0 return '';
2592             }
2593             }
2594 0         0 return 1;
2595             }
2596              
2597             #
2598             # KPS9566 file test -r expr
2599             #
2600             sub Ekps9566::r(;*@) {
2601              
2602 0 0   0 0 0 local $_ = shift if @_;
2603 0 0 0     0 croak 'Too many arguments for -r (Ekps9566::r)' if @_ and not wantarray;
2604              
2605 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2606 0 0       0 return wantarray ? (-r _,@_) : -r _;
2607             }
2608              
2609             # P.908 32.39. Symbol
2610             # in Chapter 32: Standard Modules
2611             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
2612              
2613             # P.326 Prototypes
2614             # in Chapter 7: Subroutines
2615             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
2616              
2617             # (and so on)
2618              
2619             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2620 0 0       0 return wantarray ? (-r $fh,@_) : -r $fh;
2621             }
2622             elsif (-e $_) {
2623 0 0       0 return wantarray ? (-r _,@_) : -r _;
2624             }
2625             elsif (_MSWin32_5Cended_path($_)) {
2626 0 0       0 if (-d "$_/.") {
2627 0 0       0 return wantarray ? (-r _,@_) : -r _;
2628             }
2629             else {
2630              
2631             # Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Ekps9566::*()
2632             # on Windows opens the file for the path which has 5c at end.
2633             # (and so on)
2634              
2635 0         0 my $fh = gensym();
2636 0 0       0 if (_open_r($fh, $_)) {
2637 0         0 my $r = -r $fh;
2638 0 0       0 close($fh) or die "Can't close file: $_: $!";
2639 0 0       0 return wantarray ? ($r,@_) : $r;
2640             }
2641             }
2642             }
2643 0 0       0 return wantarray ? (undef,@_) : undef;
2644             }
2645              
2646             #
2647             # KPS9566 file test -w expr
2648             #
2649             sub Ekps9566::w(;*@) {
2650              
2651 0 0   0 0 0 local $_ = shift if @_;
2652 0 0 0     0 croak 'Too many arguments for -w (Ekps9566::w)' if @_ and not wantarray;
2653              
2654 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2655 0 0       0 return wantarray ? (-w _,@_) : -w _;
2656             }
2657             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2658 0 0       0 return wantarray ? (-w $fh,@_) : -w $fh;
2659             }
2660             elsif (-e $_) {
2661 0 0       0 return wantarray ? (-w _,@_) : -w _;
2662             }
2663             elsif (_MSWin32_5Cended_path($_)) {
2664 0 0       0 if (-d "$_/.") {
2665 0 0       0 return wantarray ? (-w _,@_) : -w _;
2666             }
2667             else {
2668 0         0 my $fh = gensym();
2669 0 0       0 if (_open_a($fh, $_)) {
2670 0         0 my $w = -w $fh;
2671 0 0       0 close($fh) or die "Can't close file: $_: $!";
2672 0 0       0 return wantarray ? ($w,@_) : $w;
2673             }
2674             }
2675             }
2676 0 0       0 return wantarray ? (undef,@_) : undef;
2677             }
2678              
2679             #
2680             # KPS9566 file test -x expr
2681             #
2682             sub Ekps9566::x(;*@) {
2683              
2684 0 0   0 0 0 local $_ = shift if @_;
2685 0 0 0     0 croak 'Too many arguments for -x (Ekps9566::x)' if @_ and not wantarray;
2686              
2687 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2688 0 0       0 return wantarray ? (-x _,@_) : -x _;
2689             }
2690             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2691 0 0       0 return wantarray ? (-x $fh,@_) : -x $fh;
2692             }
2693             elsif (-e $_) {
2694 0 0       0 return wantarray ? (-x _,@_) : -x _;
2695             }
2696             elsif (_MSWin32_5Cended_path($_)) {
2697 0 0       0 if (-d "$_/.") {
2698 0 0       0 return wantarray ? (-x _,@_) : -x _;
2699             }
2700             else {
2701 0         0 my $fh = gensym();
2702 0 0       0 if (_open_r($fh, $_)) {
2703 0         0 my $dummy_for_underline_cache = -x $fh;
2704 0 0       0 close($fh) or die "Can't close file: $_: $!";
2705             }
2706              
2707             # filename is not .COM .EXE .BAT .CMD
2708 0 0       0 return wantarray ? ('',@_) : '';
2709             }
2710             }
2711 0 0       0 return wantarray ? (undef,@_) : undef;
2712             }
2713              
2714             #
2715             # KPS9566 file test -o expr
2716             #
2717             sub Ekps9566::o(;*@) {
2718              
2719 0 0   0 0 0 local $_ = shift if @_;
2720 0 0 0     0 croak 'Too many arguments for -o (Ekps9566::o)' if @_ and not wantarray;
2721              
2722 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2723 0 0       0 return wantarray ? (-o _,@_) : -o _;
2724             }
2725             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2726 0 0       0 return wantarray ? (-o $fh,@_) : -o $fh;
2727             }
2728             elsif (-e $_) {
2729 0 0       0 return wantarray ? (-o _,@_) : -o _;
2730             }
2731             elsif (_MSWin32_5Cended_path($_)) {
2732 0 0       0 if (-d "$_/.") {
2733 0 0       0 return wantarray ? (-o _,@_) : -o _;
2734             }
2735             else {
2736 0         0 my $fh = gensym();
2737 0 0       0 if (_open_r($fh, $_)) {
2738 0         0 my $o = -o $fh;
2739 0 0       0 close($fh) or die "Can't close file: $_: $!";
2740 0 0       0 return wantarray ? ($o,@_) : $o;
2741             }
2742             }
2743             }
2744 0 0       0 return wantarray ? (undef,@_) : undef;
2745             }
2746              
2747             #
2748             # KPS9566 file test -R expr
2749             #
2750             sub Ekps9566::R(;*@) {
2751              
2752 0 0   0 0 0 local $_ = shift if @_;
2753 0 0 0     0 croak 'Too many arguments for -R (Ekps9566::R)' if @_ and not wantarray;
2754              
2755 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2756 0 0       0 return wantarray ? (-R _,@_) : -R _;
2757             }
2758             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2759 0 0       0 return wantarray ? (-R $fh,@_) : -R $fh;
2760             }
2761             elsif (-e $_) {
2762 0 0       0 return wantarray ? (-R _,@_) : -R _;
2763             }
2764             elsif (_MSWin32_5Cended_path($_)) {
2765 0 0       0 if (-d "$_/.") {
2766 0 0       0 return wantarray ? (-R _,@_) : -R _;
2767             }
2768             else {
2769 0         0 my $fh = gensym();
2770 0 0       0 if (_open_r($fh, $_)) {
2771 0         0 my $R = -R $fh;
2772 0 0       0 close($fh) or die "Can't close file: $_: $!";
2773 0 0       0 return wantarray ? ($R,@_) : $R;
2774             }
2775             }
2776             }
2777 0 0       0 return wantarray ? (undef,@_) : undef;
2778             }
2779              
2780             #
2781             # KPS9566 file test -W expr
2782             #
2783             sub Ekps9566::W(;*@) {
2784              
2785 0 0   0 0 0 local $_ = shift if @_;
2786 0 0 0     0 croak 'Too many arguments for -W (Ekps9566::W)' if @_ and not wantarray;
2787              
2788 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2789 0 0       0 return wantarray ? (-W _,@_) : -W _;
2790             }
2791             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2792 0 0       0 return wantarray ? (-W $fh,@_) : -W $fh;
2793             }
2794             elsif (-e $_) {
2795 0 0       0 return wantarray ? (-W _,@_) : -W _;
2796             }
2797             elsif (_MSWin32_5Cended_path($_)) {
2798 0 0       0 if (-d "$_/.") {
2799 0 0       0 return wantarray ? (-W _,@_) : -W _;
2800             }
2801             else {
2802 0         0 my $fh = gensym();
2803 0 0       0 if (_open_a($fh, $_)) {
2804 0         0 my $W = -W $fh;
2805 0 0       0 close($fh) or die "Can't close file: $_: $!";
2806 0 0       0 return wantarray ? ($W,@_) : $W;
2807             }
2808             }
2809             }
2810 0 0       0 return wantarray ? (undef,@_) : undef;
2811             }
2812              
2813             #
2814             # KPS9566 file test -X expr
2815             #
2816             sub Ekps9566::X(;*@) {
2817              
2818 0 0   0 1 0 local $_ = shift if @_;
2819 0 0 0     0 croak 'Too many arguments for -X (Ekps9566::X)' if @_ and not wantarray;
2820              
2821 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2822 0 0       0 return wantarray ? (-X _,@_) : -X _;
2823             }
2824             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2825 0 0       0 return wantarray ? (-X $fh,@_) : -X $fh;
2826             }
2827             elsif (-e $_) {
2828 0 0       0 return wantarray ? (-X _,@_) : -X _;
2829             }
2830             elsif (_MSWin32_5Cended_path($_)) {
2831 0 0       0 if (-d "$_/.") {
2832 0 0       0 return wantarray ? (-X _,@_) : -X _;
2833             }
2834             else {
2835 0         0 my $fh = gensym();
2836 0 0       0 if (_open_r($fh, $_)) {
2837 0         0 my $dummy_for_underline_cache = -X $fh;
2838 0 0       0 close($fh) or die "Can't close file: $_: $!";
2839             }
2840              
2841             # filename is not .COM .EXE .BAT .CMD
2842 0 0       0 return wantarray ? ('',@_) : '';
2843             }
2844             }
2845 0 0       0 return wantarray ? (undef,@_) : undef;
2846             }
2847              
2848             #
2849             # KPS9566 file test -O expr
2850             #
2851             sub Ekps9566::O(;*@) {
2852              
2853 0 0   0 0 0 local $_ = shift if @_;
2854 0 0 0     0 croak 'Too many arguments for -O (Ekps9566::O)' if @_ and not wantarray;
2855              
2856 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2857 0 0       0 return wantarray ? (-O _,@_) : -O _;
2858             }
2859             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2860 0 0       0 return wantarray ? (-O $fh,@_) : -O $fh;
2861             }
2862             elsif (-e $_) {
2863 0 0       0 return wantarray ? (-O _,@_) : -O _;
2864             }
2865             elsif (_MSWin32_5Cended_path($_)) {
2866 0 0       0 if (-d "$_/.") {
2867 0 0       0 return wantarray ? (-O _,@_) : -O _;
2868             }
2869             else {
2870 0         0 my $fh = gensym();
2871 0 0       0 if (_open_r($fh, $_)) {
2872 0         0 my $O = -O $fh;
2873 0 0       0 close($fh) or die "Can't close file: $_: $!";
2874 0 0       0 return wantarray ? ($O,@_) : $O;
2875             }
2876             }
2877             }
2878 0 0       0 return wantarray ? (undef,@_) : undef;
2879             }
2880              
2881             #
2882             # KPS9566 file test -e expr
2883             #
2884             sub Ekps9566::e(;*@) {
2885              
2886 0 50   768 0 0 local $_ = shift if @_;
2887 768 50 33     8754 croak 'Too many arguments for -e (Ekps9566::e)' if @_ and not wantarray;
2888              
2889 768         2602 local $^W = 0;
2890 768     768   5851 local $SIG{__WARN__} = sub {}; # telldir() attempted on invalid dirhandle at here
2891              
2892 768         5070 my $fh = qualify_to_ref $_;
2893 768 50       2508 if ($_ eq '_') {
    50          
    50          
    50          
    50          
2894 768 0       3216 return wantarray ? (-e _,@_) : -e _;
2895             }
2896              
2897             # return false if directory handle
2898             elsif (defined Ekps9566::telldir($fh)) {
2899 0 0       0 return wantarray ? ('',@_) : '';
2900             }
2901              
2902             # return true if file handle
2903             elsif (defined fileno $fh) {
2904 0 0       0 return wantarray ? (1,@_) : 1;
2905             }
2906              
2907             elsif (-e $_) {
2908 0 0       0 return wantarray ? (1,@_) : 1;
2909             }
2910             elsif (_MSWin32_5Cended_path($_)) {
2911 0 0       0 if (-d "$_/.") {
2912 0 0       0 return wantarray ? (1,@_) : 1;
2913             }
2914             else {
2915 0         0 my $fh = gensym();
2916 0 0       0 if (_open_r($fh, $_)) {
2917 0         0 my $e = -e $fh;
2918 0 0       0 close($fh) or die "Can't close file: $_: $!";
2919 0 0       0 return wantarray ? ($e,@_) : $e;
2920             }
2921             }
2922             }
2923 0 50       0 return wantarray ? (undef,@_) : undef;
2924             }
2925              
2926             #
2927             # KPS9566 file test -z expr
2928             #
2929             sub Ekps9566::z(;*@) {
2930              
2931 768 0   0 0 6912 local $_ = shift if @_;
2932 0 0 0     0 croak 'Too many arguments for -z (Ekps9566::z)' if @_ and not wantarray;
2933              
2934 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2935 0 0       0 return wantarray ? (-z _,@_) : -z _;
2936             }
2937             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2938 0 0       0 return wantarray ? (-z $fh,@_) : -z $fh;
2939             }
2940             elsif (-e $_) {
2941 0 0       0 return wantarray ? (-z _,@_) : -z _;
2942             }
2943             elsif (_MSWin32_5Cended_path($_)) {
2944 0 0       0 if (-d "$_/.") {
2945 0 0       0 return wantarray ? (-z _,@_) : -z _;
2946             }
2947             else {
2948 0         0 my $fh = gensym();
2949 0 0       0 if (_open_r($fh, $_)) {
2950 0         0 my $z = -z $fh;
2951 0 0       0 close($fh) or die "Can't close file: $_: $!";
2952 0 0       0 return wantarray ? ($z,@_) : $z;
2953             }
2954             }
2955             }
2956 0 0       0 return wantarray ? (undef,@_) : undef;
2957             }
2958              
2959             #
2960             # KPS9566 file test -s expr
2961             #
2962             sub Ekps9566::s(;*@) {
2963              
2964 0 0   0 0 0 local $_ = shift if @_;
2965 0 0 0     0 croak 'Too many arguments for -s (Ekps9566::s)' if @_ and not wantarray;
2966              
2967 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
2968 0 0       0 return wantarray ? (-s _,@_) : -s _;
2969             }
2970             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
2971 0 0       0 return wantarray ? (-s $fh,@_) : -s $fh;
2972             }
2973             elsif (-e $_) {
2974 0 0       0 return wantarray ? (-s _,@_) : -s _;
2975             }
2976             elsif (_MSWin32_5Cended_path($_)) {
2977 0 0       0 if (-d "$_/.") {
2978 0 0       0 return wantarray ? (-s _,@_) : -s _;
2979             }
2980             else {
2981 0         0 my $fh = gensym();
2982 0 0       0 if (_open_r($fh, $_)) {
2983 0         0 my $s = -s $fh;
2984 0 0       0 close($fh) or die "Can't close file: $_: $!";
2985 0 0       0 return wantarray ? ($s,@_) : $s;
2986             }
2987             }
2988             }
2989 0 0       0 return wantarray ? (undef,@_) : undef;
2990             }
2991              
2992             #
2993             # KPS9566 file test -f expr
2994             #
2995             sub Ekps9566::f(;*@) {
2996              
2997 0 0   0 0 0 local $_ = shift if @_;
2998 0 0 0     0 croak 'Too many arguments for -f (Ekps9566::f)' if @_ and not wantarray;
2999              
3000 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3001 0 0       0 return wantarray ? (-f _,@_) : -f _;
3002             }
3003             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3004 0 0       0 return wantarray ? (-f $fh,@_) : -f $fh;
3005             }
3006             elsif (-e $_) {
3007 0 0       0 return wantarray ? (-f _,@_) : -f _;
3008             }
3009             elsif (_MSWin32_5Cended_path($_)) {
3010 0 0       0 if (-d "$_/.") {
3011 0 0       0 return wantarray ? ('',@_) : '';
3012             }
3013             else {
3014 0         0 my $fh = gensym();
3015 0 0       0 if (_open_r($fh, $_)) {
3016 0         0 my $f = -f $fh;
3017 0 0       0 close($fh) or die "Can't close file: $_: $!";
3018 0 0       0 return wantarray ? ($f,@_) : $f;
3019             }
3020             }
3021             }
3022 0 0       0 return wantarray ? (undef,@_) : undef;
3023             }
3024              
3025             #
3026             # KPS9566 file test -d expr
3027             #
3028             sub Ekps9566::d(;*@) {
3029              
3030 0 0   0 0 0 local $_ = shift if @_;
3031 0 0 0     0 croak 'Too many arguments for -d (Ekps9566::d)' if @_ and not wantarray;
3032              
3033 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3034 0 0       0 return wantarray ? (-d _,@_) : -d _;
3035             }
3036              
3037             # return false if file handle or directory handle
3038             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3039 0 0       0 return wantarray ? ('',@_) : '';
3040             }
3041             elsif (-e $_) {
3042 0 0       0 return wantarray ? (-d _,@_) : -d _;
3043             }
3044             elsif (_MSWin32_5Cended_path($_)) {
3045 0 0       0 return wantarray ? (-d "$_/.",@_) : -d "$_/.";
3046             }
3047 0 0       0 return wantarray ? (undef,@_) : undef;
3048             }
3049              
3050             #
3051             # KPS9566 file test -l expr
3052             #
3053             sub Ekps9566::l(;*@) {
3054              
3055 0 0   0 0 0 local $_ = shift if @_;
3056 0 0 0     0 croak 'Too many arguments for -l (Ekps9566::l)' if @_ and not wantarray;
3057              
3058 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3059 0 0       0 return wantarray ? (-l _,@_) : -l _;
3060             }
3061             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3062 0 0       0 return wantarray ? (-l $fh,@_) : -l $fh;
3063             }
3064             elsif (-e $_) {
3065 0 0       0 return wantarray ? (-l _,@_) : -l _;
3066             }
3067             elsif (_MSWin32_5Cended_path($_)) {
3068 0 0       0 if (-d "$_/.") {
3069 0 0       0 return wantarray ? (-l _,@_) : -l _;
3070             }
3071             else {
3072 0         0 my $fh = gensym();
3073 0 0       0 if (_open_r($fh, $_)) {
3074 0         0 my $l = -l $fh;
3075 0 0       0 close($fh) or die "Can't close file: $_: $!";
3076 0 0       0 return wantarray ? ($l,@_) : $l;
3077             }
3078             }
3079             }
3080 0 0       0 return wantarray ? (undef,@_) : undef;
3081             }
3082              
3083             #
3084             # KPS9566 file test -p expr
3085             #
3086             sub Ekps9566::p(;*@) {
3087              
3088 0 0   0 0 0 local $_ = shift if @_;
3089 0 0 0     0 croak 'Too many arguments for -p (Ekps9566::p)' if @_ and not wantarray;
3090              
3091 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3092 0 0       0 return wantarray ? (-p _,@_) : -p _;
3093             }
3094             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3095 0 0       0 return wantarray ? (-p $fh,@_) : -p $fh;
3096             }
3097             elsif (-e $_) {
3098 0 0       0 return wantarray ? (-p _,@_) : -p _;
3099             }
3100             elsif (_MSWin32_5Cended_path($_)) {
3101 0 0       0 if (-d "$_/.") {
3102 0 0       0 return wantarray ? (-p _,@_) : -p _;
3103             }
3104             else {
3105 0         0 my $fh = gensym();
3106 0 0       0 if (_open_r($fh, $_)) {
3107 0         0 my $p = -p $fh;
3108 0 0       0 close($fh) or die "Can't close file: $_: $!";
3109 0 0       0 return wantarray ? ($p,@_) : $p;
3110             }
3111             }
3112             }
3113 0 0       0 return wantarray ? (undef,@_) : undef;
3114             }
3115              
3116             #
3117             # KPS9566 file test -S expr
3118             #
3119             sub Ekps9566::S(;*@) {
3120              
3121 0 0   0 0 0 local $_ = shift if @_;
3122 0 0 0     0 croak 'Too many arguments for -S (Ekps9566::S)' if @_ and not wantarray;
3123              
3124 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3125 0 0       0 return wantarray ? (-S _,@_) : -S _;
3126             }
3127             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3128 0 0       0 return wantarray ? (-S $fh,@_) : -S $fh;
3129             }
3130             elsif (-e $_) {
3131 0 0       0 return wantarray ? (-S _,@_) : -S _;
3132             }
3133             elsif (_MSWin32_5Cended_path($_)) {
3134 0 0       0 if (-d "$_/.") {
3135 0 0       0 return wantarray ? (-S _,@_) : -S _;
3136             }
3137             else {
3138 0         0 my $fh = gensym();
3139 0 0       0 if (_open_r($fh, $_)) {
3140 0         0 my $S = -S $fh;
3141 0 0       0 close($fh) or die "Can't close file: $_: $!";
3142 0 0       0 return wantarray ? ($S,@_) : $S;
3143             }
3144             }
3145             }
3146 0 0       0 return wantarray ? (undef,@_) : undef;
3147             }
3148              
3149             #
3150             # KPS9566 file test -b expr
3151             #
3152             sub Ekps9566::b(;*@) {
3153              
3154 0 0   0 0 0 local $_ = shift if @_;
3155 0 0 0     0 croak 'Too many arguments for -b (Ekps9566::b)' if @_ and not wantarray;
3156              
3157 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3158 0 0       0 return wantarray ? (-b _,@_) : -b _;
3159             }
3160             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3161 0 0       0 return wantarray ? (-b $fh,@_) : -b $fh;
3162             }
3163             elsif (-e $_) {
3164 0 0       0 return wantarray ? (-b _,@_) : -b _;
3165             }
3166             elsif (_MSWin32_5Cended_path($_)) {
3167 0 0       0 if (-d "$_/.") {
3168 0 0       0 return wantarray ? (-b _,@_) : -b _;
3169             }
3170             else {
3171 0         0 my $fh = gensym();
3172 0 0       0 if (_open_r($fh, $_)) {
3173 0         0 my $b = -b $fh;
3174 0 0       0 close($fh) or die "Can't close file: $_: $!";
3175 0 0       0 return wantarray ? ($b,@_) : $b;
3176             }
3177             }
3178             }
3179 0 0       0 return wantarray ? (undef,@_) : undef;
3180             }
3181              
3182             #
3183             # KPS9566 file test -c expr
3184             #
3185             sub Ekps9566::c(;*@) {
3186              
3187 0 0   0 0 0 local $_ = shift if @_;
3188 0 0 0     0 croak 'Too many arguments for -c (Ekps9566::c)' if @_ and not wantarray;
3189              
3190 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3191 0 0       0 return wantarray ? (-c _,@_) : -c _;
3192             }
3193             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3194 0 0       0 return wantarray ? (-c $fh,@_) : -c $fh;
3195             }
3196             elsif (-e $_) {
3197 0 0       0 return wantarray ? (-c _,@_) : -c _;
3198             }
3199             elsif (_MSWin32_5Cended_path($_)) {
3200 0 0       0 if (-d "$_/.") {
3201 0 0       0 return wantarray ? (-c _,@_) : -c _;
3202             }
3203             else {
3204 0         0 my $fh = gensym();
3205 0 0       0 if (_open_r($fh, $_)) {
3206 0         0 my $c = -c $fh;
3207 0 0       0 close($fh) or die "Can't close file: $_: $!";
3208 0 0       0 return wantarray ? ($c,@_) : $c;
3209             }
3210             }
3211             }
3212 0 0       0 return wantarray ? (undef,@_) : undef;
3213             }
3214              
3215             #
3216             # KPS9566 file test -u expr
3217             #
3218             sub Ekps9566::u(;*@) {
3219              
3220 0 0   0 0 0 local $_ = shift if @_;
3221 0 0 0     0 croak 'Too many arguments for -u (Ekps9566::u)' if @_ and not wantarray;
3222              
3223 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3224 0 0       0 return wantarray ? (-u _,@_) : -u _;
3225             }
3226             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3227 0 0       0 return wantarray ? (-u $fh,@_) : -u $fh;
3228             }
3229             elsif (-e $_) {
3230 0 0       0 return wantarray ? (-u _,@_) : -u _;
3231             }
3232             elsif (_MSWin32_5Cended_path($_)) {
3233 0 0       0 if (-d "$_/.") {
3234 0 0       0 return wantarray ? (-u _,@_) : -u _;
3235             }
3236             else {
3237 0         0 my $fh = gensym();
3238 0 0       0 if (_open_r($fh, $_)) {
3239 0         0 my $u = -u $fh;
3240 0 0       0 close($fh) or die "Can't close file: $_: $!";
3241 0 0       0 return wantarray ? ($u,@_) : $u;
3242             }
3243             }
3244             }
3245 0 0       0 return wantarray ? (undef,@_) : undef;
3246             }
3247              
3248             #
3249             # KPS9566 file test -g expr
3250             #
3251             sub Ekps9566::g(;*@) {
3252              
3253 0 0   0 0 0 local $_ = shift if @_;
3254 0 0 0     0 croak 'Too many arguments for -g (Ekps9566::g)' if @_ and not wantarray;
3255              
3256 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3257 0 0       0 return wantarray ? (-g _,@_) : -g _;
3258             }
3259             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3260 0 0       0 return wantarray ? (-g $fh,@_) : -g $fh;
3261             }
3262             elsif (-e $_) {
3263 0 0       0 return wantarray ? (-g _,@_) : -g _;
3264             }
3265             elsif (_MSWin32_5Cended_path($_)) {
3266 0 0       0 if (-d "$_/.") {
3267 0 0       0 return wantarray ? (-g _,@_) : -g _;
3268             }
3269             else {
3270 0         0 my $fh = gensym();
3271 0 0       0 if (_open_r($fh, $_)) {
3272 0         0 my $g = -g $fh;
3273 0 0       0 close($fh) or die "Can't close file: $_: $!";
3274 0 0       0 return wantarray ? ($g,@_) : $g;
3275             }
3276             }
3277             }
3278 0 0       0 return wantarray ? (undef,@_) : undef;
3279             }
3280              
3281             #
3282             # KPS9566 file test -k expr
3283             #
3284             sub Ekps9566::k(;*@) {
3285              
3286 0 0   0 0 0 local $_ = shift if @_;
3287 0 0 0     0 croak 'Too many arguments for -k (Ekps9566::k)' if @_ and not wantarray;
3288              
3289 0 0       0 if ($_ eq '_') {
    0          
    0          
3290 0 0       0 return wantarray ? ('',@_) : '';
3291             }
3292             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3293 0 0       0 return wantarray ? ('',@_) : '';
3294             }
3295             elsif ($] =~ /^5\.008/oxms) {
3296 0 0       0 return wantarray ? ('',@_) : '';
3297             }
3298 0 0       0 return wantarray ? ($_,@_) : $_;
3299             }
3300              
3301             #
3302             # KPS9566 file test -T expr
3303             #
3304             sub Ekps9566::T(;*@) {
3305              
3306 0 0   0 0 0 local $_ = shift if @_;
3307              
3308             # Use of croak without parentheses makes die on Strawberry Perl 5.008 and 5.010, like:
3309             # croak 'Too many arguments for -T (Ekps9566::T)';
3310             # Must be used by parentheses like:
3311             # croak('Too many arguments for -T (Ekps9566::T)');
3312              
3313 0 0 0     0 if (@_ and not wantarray) {
3314 0         0 croak('Too many arguments for -T (Ekps9566::T)');
3315             }
3316              
3317 0         0 my $T = 1;
3318              
3319 0         0 my $fh = qualify_to_ref $_;
3320 0 0       0 if (defined fileno $fh) {
3321              
3322 0     0   0 local $SIG{__WARN__} = sub {}; # telldir() attempted on invalid dirhandle at here
3323 0 0       0 if (defined Ekps9566::telldir($fh)) {
3324 0 0       0 return wantarray ? (undef,@_) : undef;
3325             }
3326              
3327             # P.813 29.2.176. tell
3328             # in Chapter 29: Functions
3329             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
3330              
3331             # P.970 tell
3332             # in Chapter 27: Functions
3333             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
3334              
3335             # (and so on)
3336              
3337 0         0 my $systell = sysseek $fh, 0, 1;
3338              
3339 0 0       0 if (sysread $fh, my $block, 512) {
3340              
3341             # P.163 Binary file check in Little Perl Parlor 16
3342             # of Book No. T1008901080816 ZASSHI 08901-8 UNIX MAGAZINE 1993 Aug VOL8#8
3343             # (and so on)
3344              
3345 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3346 0         0 $T = '';
3347             }
3348             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3349 0         0 $T = '';
3350             }
3351             }
3352              
3353             # 0 byte or eof
3354             else {
3355 0         0 $T = 1;
3356             }
3357              
3358 0         0 my $dummy_for_underline_cache = -T $fh;
3359 0         0 sysseek $fh, $systell, 0;
3360             }
3361             else {
3362 0 0 0     0 if (-d $_ or -d "$_/.") {
3363 0 0       0 return wantarray ? (undef,@_) : undef;
3364             }
3365              
3366 0         0 $fh = gensym();
3367 0 0       0 if (_open_r($fh, $_)) {
3368             }
3369             else {
3370 0 0       0 return wantarray ? (undef,@_) : undef;
3371             }
3372 0 0       0 if (sysread $fh, my $block, 512) {
3373 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3374 0         0 $T = '';
3375             }
3376             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3377 0         0 $T = '';
3378             }
3379             }
3380              
3381             # 0 byte or eof
3382             else {
3383 0         0 $T = 1;
3384             }
3385 0         0 my $dummy_for_underline_cache = -T $fh;
3386 0 0       0 close($fh) or die "Can't close file: $_: $!";
3387             }
3388              
3389 0 0       0 return wantarray ? ($T,@_) : $T;
3390             }
3391              
3392             #
3393             # KPS9566 file test -B expr
3394             #
3395             sub Ekps9566::B(;*@) {
3396              
3397 0 0   0 0 0 local $_ = shift if @_;
3398 0 0 0     0 croak 'Too many arguments for -B (Ekps9566::B)' if @_ and not wantarray;
3399 0         0 my $B = '';
3400              
3401 0         0 my $fh = qualify_to_ref $_;
3402 0 0       0 if (defined fileno $fh) {
3403              
3404 0     0   0 local $SIG{__WARN__} = sub {}; # telldir() attempted on invalid dirhandle at here
3405 0 0       0 if (defined Ekps9566::telldir($fh)) {
3406 0 0       0 return wantarray ? (undef,@_) : undef;
3407             }
3408              
3409 0         0 my $systell = sysseek $fh, 0, 1;
3410              
3411 0 0       0 if (sysread $fh, my $block, 512) {
3412 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3413 0         0 $B = 1;
3414             }
3415             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3416 0         0 $B = 1;
3417             }
3418             }
3419              
3420             # 0 byte or eof
3421             else {
3422 0         0 $B = 1;
3423             }
3424              
3425 0         0 my $dummy_for_underline_cache = -B $fh;
3426 0         0 sysseek $fh, $systell, 0;
3427             }
3428             else {
3429 0 0 0     0 if (-d $_ or -d "$_/.") {
3430 0 0       0 return wantarray ? (undef,@_) : undef;
3431             }
3432              
3433 0         0 $fh = gensym();
3434 0 0       0 if (_open_r($fh, $_)) {
3435             }
3436             else {
3437 0 0       0 return wantarray ? (undef,@_) : undef;
3438             }
3439 0 0       0 if (sysread $fh, my $block, 512) {
3440 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
3441 0         0 $B = 1;
3442             }
3443             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
3444 0         0 $B = 1;
3445             }
3446             }
3447              
3448             # 0 byte or eof
3449             else {
3450 0         0 $B = 1;
3451             }
3452 0         0 my $dummy_for_underline_cache = -B $fh;
3453 0 0       0 close($fh) or die "Can't close file: $_: $!";
3454             }
3455              
3456 0 0       0 return wantarray ? ($B,@_) : $B;
3457             }
3458              
3459             #
3460             # KPS9566 file test -M expr
3461             #
3462             sub Ekps9566::M(;*@) {
3463              
3464 0 0   0 0 0 local $_ = shift if @_;
3465 0 0 0     0 croak 'Too many arguments for -M (Ekps9566::M)' if @_ and not wantarray;
3466              
3467 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3468 0 0       0 return wantarray ? (-M _,@_) : -M _;
3469             }
3470             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3471 0 0       0 return wantarray ? (-M $fh,@_) : -M $fh;
3472             }
3473             elsif (-e $_) {
3474 0 0       0 return wantarray ? (-M _,@_) : -M _;
3475             }
3476             elsif (_MSWin32_5Cended_path($_)) {
3477 0 0       0 if (-d "$_/.") {
3478 0 0       0 return wantarray ? (-M _,@_) : -M _;
3479             }
3480             else {
3481 0         0 my $fh = gensym();
3482 0 0       0 if (_open_r($fh, $_)) {
3483 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
3484 0 0       0 close($fh) or die "Can't close file: $_: $!";
3485 0         0 my $M = ($^T - $mtime) / (24*60*60);
3486 0 0       0 return wantarray ? ($M,@_) : $M;
3487             }
3488             }
3489             }
3490 0 0       0 return wantarray ? (undef,@_) : undef;
3491             }
3492              
3493             #
3494             # KPS9566 file test -A expr
3495             #
3496             sub Ekps9566::A(;*@) {
3497              
3498 0 0   0 0 0 local $_ = shift if @_;
3499 0 0 0     0 croak 'Too many arguments for -A (Ekps9566::A)' if @_ and not wantarray;
3500              
3501 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3502 0 0       0 return wantarray ? (-A _,@_) : -A _;
3503             }
3504             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3505 0 0       0 return wantarray ? (-A $fh,@_) : -A $fh;
3506             }
3507             elsif (-e $_) {
3508 0 0       0 return wantarray ? (-A _,@_) : -A _;
3509             }
3510             elsif (_MSWin32_5Cended_path($_)) {
3511 0 0       0 if (-d "$_/.") {
3512 0 0       0 return wantarray ? (-A _,@_) : -A _;
3513             }
3514             else {
3515 0         0 my $fh = gensym();
3516 0 0       0 if (_open_r($fh, $_)) {
3517 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
3518 0 0       0 close($fh) or die "Can't close file: $_: $!";
3519 0         0 my $A = ($^T - $atime) / (24*60*60);
3520 0 0       0 return wantarray ? ($A,@_) : $A;
3521             }
3522             }
3523             }
3524 0 0       0 return wantarray ? (undef,@_) : undef;
3525             }
3526              
3527             #
3528             # KPS9566 file test -C expr
3529             #
3530             sub Ekps9566::C(;*@) {
3531              
3532 0 0   0 0 0 local $_ = shift if @_;
3533 0 0 0     0 croak 'Too many arguments for -C (Ekps9566::C)' if @_ and not wantarray;
3534              
3535 0 0       0 if ($_ eq '_') {
    0          
    0          
    0          
3536 0 0       0 return wantarray ? (-C _,@_) : -C _;
3537             }
3538             elsif (defined fileno(my $fh = qualify_to_ref $_)) {
3539 0 0       0 return wantarray ? (-C $fh,@_) : -C $fh;
3540             }
3541             elsif (-e $_) {
3542 0 0       0 return wantarray ? (-C _,@_) : -C _;
3543             }
3544             elsif (_MSWin32_5Cended_path($_)) {
3545 0 0       0 if (-d "$_/.") {
3546 0 0       0 return wantarray ? (-C _,@_) : -C _;
3547             }
3548             else {
3549 0         0 my $fh = gensym();
3550 0 0       0 if (_open_r($fh, $_)) {
3551 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
3552 0 0       0 close($fh) or die "Can't close file: $_: $!";
3553 0         0 my $C = ($^T - $ctime) / (24*60*60);
3554 0 0       0 return wantarray ? ($C,@_) : $C;
3555             }
3556             }
3557             }
3558 0 0       0 return wantarray ? (undef,@_) : undef;
3559             }
3560              
3561             #
3562             # KPS9566 stacked file test $_
3563             #
3564             sub Ekps9566::filetest_ {
3565              
3566 0     0 0 0 my $filetest = substr(pop @_, 1);
3567              
3568 0 0       0 unless (CORE::eval qq{Ekps9566::${filetest}_}) {
3569 0         0 return '';
3570             }
3571 0         0 for my $filetest (CORE::reverse @_) {
3572 0 0       0 unless (CORE::eval qq{ $filetest _ }) {
3573 0         0 return '';
3574             }
3575             }
3576 0         0 return 1;
3577             }
3578              
3579             #
3580             # KPS9566 file test -r $_
3581             #
3582             sub Ekps9566::r_() {
3583              
3584 0 0   0 0 0 if (-e $_) {
    0          
3585 0 0       0 return -r _ ? 1 : '';
3586             }
3587             elsif (_MSWin32_5Cended_path($_)) {
3588 0 0       0 if (-d "$_/.") {
3589 0 0       0 return -r _ ? 1 : '';
3590             }
3591             else {
3592 0         0 my $fh = gensym();
3593 0 0       0 if (_open_r($fh, $_)) {
3594 0         0 my $r = -r $fh;
3595 0 0       0 close($fh) or die "Can't close file: $_: $!";
3596 0 0       0 return $r ? 1 : '';
3597             }
3598             }
3599             }
3600              
3601             # 10.10. Returning Failure
3602             # in Chapter 10. Subroutines
3603             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
3604             # (and so on)
3605              
3606             # 2010-01-26 The difference of "return;" and "return undef;"
3607             # http://d.hatena.ne.jp/gfx/20100126/1264474754
3608             #
3609             # "Perl Best Practices" recommends to use "return;"*1 to return nothing, but
3610             # it might be wrong in some cases. If you use this idiom for those functions
3611             # which are expected to return a scalar value, e.g. searching functions, the
3612             # user of those functions will be surprised at what they return in list
3613             # context, an empty list - note that many functions and all the methods
3614             # evaluate their arguments in list context. You'd better to use "return undef;"
3615             # for such scalar functions.
3616             #
3617             # sub search_something {
3618             # my($arg) = @_;
3619             # # search_something...
3620             # if(defined $found){
3621             # return $found;
3622             # }
3623             # return; # XXX: you'd better to "return undef;"
3624             # }
3625             #
3626             # # ...
3627             #
3628             # # you'll get what you want, but ...
3629             # my $something = search_something($source);
3630             #
3631             # # you won't get what you want here.
3632             # # @_ for doit() is (-foo => $opt), not (undef, -foo => $opt).
3633             # $obj->doit(search_something($source), -option=> $optval);
3634             #
3635             # # you have to use the "scalar" operator in such a case.
3636             # $obj->doit(scalar search_something($source), ...);
3637             #
3638             # *1: it returns an empty list in list context, or returns undef in scalar
3639             # context
3640             #
3641             # (and so on)
3642              
3643 0         0 return undef;
3644             }
3645              
3646             #
3647             # KPS9566 file test -w $_
3648             #
3649             sub Ekps9566::w_() {
3650              
3651 0 0   0 0 0 if (-e $_) {
    0          
3652 0 0       0 return -w _ ? 1 : '';
3653             }
3654             elsif (_MSWin32_5Cended_path($_)) {
3655 0 0       0 if (-d "$_/.") {
3656 0 0       0 return -w _ ? 1 : '';
3657             }
3658             else {
3659 0         0 my $fh = gensym();
3660 0 0       0 if (_open_a($fh, $_)) {
3661 0         0 my $w = -w $fh;
3662 0 0       0 close($fh) or die "Can't close file: $_: $!";
3663 0 0       0 return $w ? 1 : '';
3664             }
3665             }
3666             }
3667 0         0 return undef;
3668             }
3669              
3670             #
3671             # KPS9566 file test -x $_
3672             #
3673             sub Ekps9566::x_() {
3674              
3675 0 0   0 0 0 if (-e $_) {
    0          
3676 0 0       0 return -x _ ? 1 : '';
3677             }
3678             elsif (_MSWin32_5Cended_path($_)) {
3679 0 0       0 if (-d "$_/.") {
3680 0 0       0 return -x _ ? 1 : '';
3681             }
3682             else {
3683 0         0 my $fh = gensym();
3684 0 0       0 if (_open_r($fh, $_)) {
3685 0         0 my $dummy_for_underline_cache = -x $fh;
3686 0 0       0 close($fh) or die "Can't close file: $_: $!";
3687             }
3688              
3689             # filename is not .COM .EXE .BAT .CMD
3690 0         0 return '';
3691             }
3692             }
3693 0         0 return undef;
3694             }
3695              
3696             #
3697             # KPS9566 file test -o $_
3698             #
3699             sub Ekps9566::o_() {
3700              
3701 0 0   0 0 0 if (-e $_) {
    0          
3702 0 0       0 return -o _ ? 1 : '';
3703             }
3704             elsif (_MSWin32_5Cended_path($_)) {
3705 0 0       0 if (-d "$_/.") {
3706 0 0       0 return -o _ ? 1 : '';
3707             }
3708             else {
3709 0         0 my $fh = gensym();
3710 0 0       0 if (_open_r($fh, $_)) {
3711 0         0 my $o = -o $fh;
3712 0 0       0 close($fh) or die "Can't close file: $_: $!";
3713 0 0       0 return $o ? 1 : '';
3714             }
3715             }
3716             }
3717 0         0 return undef;
3718             }
3719              
3720             #
3721             # KPS9566 file test -R $_
3722             #
3723             sub Ekps9566::R_() {
3724              
3725 0 0   0 0 0 if (-e $_) {
    0          
3726 0 0       0 return -R _ ? 1 : '';
3727             }
3728             elsif (_MSWin32_5Cended_path($_)) {
3729 0 0       0 if (-d "$_/.") {
3730 0 0       0 return -R _ ? 1 : '';
3731             }
3732             else {
3733 0         0 my $fh = gensym();
3734 0 0       0 if (_open_r($fh, $_)) {
3735 0         0 my $R = -R $fh;
3736 0 0       0 close($fh) or die "Can't close file: $_: $!";
3737 0 0       0 return $R ? 1 : '';
3738             }
3739             }
3740             }
3741 0         0 return undef;
3742             }
3743              
3744             #
3745             # KPS9566 file test -W $_
3746             #
3747             sub Ekps9566::W_() {
3748              
3749 0 0   0 0 0 if (-e $_) {
    0          
3750 0 0       0 return -W _ ? 1 : '';
3751             }
3752             elsif (_MSWin32_5Cended_path($_)) {
3753 0 0       0 if (-d "$_/.") {
3754 0 0       0 return -W _ ? 1 : '';
3755             }
3756             else {
3757 0         0 my $fh = gensym();
3758 0 0       0 if (_open_a($fh, $_)) {
3759 0         0 my $W = -W $fh;
3760 0 0       0 close($fh) or die "Can't close file: $_: $!";
3761 0 0       0 return $W ? 1 : '';
3762             }
3763             }
3764             }
3765 0         0 return undef;
3766             }
3767              
3768             #
3769             # KPS9566 file test -X $_
3770             #
3771             sub Ekps9566::X_() {
3772              
3773 0 0   0 0 0 if (-e $_) {
    0          
3774 0 0       0 return -X _ ? 1 : '';
3775             }
3776             elsif (_MSWin32_5Cended_path($_)) {
3777 0 0       0 if (-d "$_/.") {
3778 0 0       0 return -X _ ? 1 : '';
3779             }
3780             else {
3781 0         0 my $fh = gensym();
3782 0 0       0 if (_open_r($fh, $_)) {
3783 0         0 my $dummy_for_underline_cache = -X $fh;
3784 0 0       0 close($fh) or die "Can't close file: $_: $!";
3785             }
3786              
3787             # filename is not .COM .EXE .BAT .CMD
3788 0         0 return '';
3789             }
3790             }
3791 0         0 return undef;
3792             }
3793              
3794             #
3795             # KPS9566 file test -O $_
3796             #
3797             sub Ekps9566::O_() {
3798              
3799 0 0   0 0 0 if (-e $_) {
    0          
3800 0 0       0 return -O _ ? 1 : '';
3801             }
3802             elsif (_MSWin32_5Cended_path($_)) {
3803 0 0       0 if (-d "$_/.") {
3804 0 0       0 return -O _ ? 1 : '';
3805             }
3806             else {
3807 0         0 my $fh = gensym();
3808 0 0       0 if (_open_r($fh, $_)) {
3809 0         0 my $O = -O $fh;
3810 0 0       0 close($fh) or die "Can't close file: $_: $!";
3811 0 0       0 return $O ? 1 : '';
3812             }
3813             }
3814             }
3815 0         0 return undef;
3816             }
3817              
3818             #
3819             # KPS9566 file test -e $_
3820             #
3821             sub Ekps9566::e_() {
3822              
3823 0 0   0 0 0 if (-e $_) {
    0          
3824 0         0 return 1;
3825             }
3826             elsif (_MSWin32_5Cended_path($_)) {
3827 0 0       0 if (-d "$_/.") {
3828 0         0 return 1;
3829             }
3830             else {
3831 0         0 my $fh = gensym();
3832 0 0       0 if (_open_r($fh, $_)) {
3833 0         0 my $e = -e $fh;
3834 0 0       0 close($fh) or die "Can't close file: $_: $!";
3835 0 0       0 return $e ? 1 : '';
3836             }
3837             }
3838             }
3839 0         0 return undef;
3840             }
3841              
3842             #
3843             # KPS9566 file test -z $_
3844             #
3845             sub Ekps9566::z_() {
3846              
3847 0 0   0 0 0 if (-e $_) {
    0          
3848 0 0       0 return -z _ ? 1 : '';
3849             }
3850             elsif (_MSWin32_5Cended_path($_)) {
3851 0 0       0 if (-d "$_/.") {
3852 0 0       0 return -z _ ? 1 : '';
3853             }
3854             else {
3855 0         0 my $fh = gensym();
3856 0 0       0 if (_open_r($fh, $_)) {
3857 0         0 my $z = -z $fh;
3858 0 0       0 close($fh) or die "Can't close file: $_: $!";
3859 0 0       0 return $z ? 1 : '';
3860             }
3861             }
3862             }
3863 0         0 return undef;
3864             }
3865              
3866             #
3867             # KPS9566 file test -s $_
3868             #
3869             sub Ekps9566::s_() {
3870              
3871 0 0   0 0 0 if (-e $_) {
    0          
3872 0         0 return -s _;
3873             }
3874             elsif (_MSWin32_5Cended_path($_)) {
3875 0 0       0 if (-d "$_/.") {
3876 0         0 return -s _;
3877             }
3878             else {
3879 0         0 my $fh = gensym();
3880 0 0       0 if (_open_r($fh, $_)) {
3881 0         0 my $s = -s $fh;
3882 0 0       0 close($fh) or die "Can't close file: $_: $!";
3883 0         0 return $s;
3884             }
3885             }
3886             }
3887 0         0 return undef;
3888             }
3889              
3890             #
3891             # KPS9566 file test -f $_
3892             #
3893             sub Ekps9566::f_() {
3894              
3895 0 0   0 0 0 if (-e $_) {
    0          
3896 0 0       0 return -f _ ? 1 : '';
3897             }
3898             elsif (_MSWin32_5Cended_path($_)) {
3899 0 0       0 if (-d "$_/.") {
3900 0         0 return '';
3901             }
3902             else {
3903 0         0 my $fh = gensym();
3904 0 0       0 if (_open_r($fh, $_)) {
3905 0         0 my $f = -f $fh;
3906 0 0       0 close($fh) or die "Can't close file: $_: $!";
3907 0 0       0 return $f ? 1 : '';
3908             }
3909             }
3910             }
3911 0         0 return undef;
3912             }
3913              
3914             #
3915             # KPS9566 file test -d $_
3916             #
3917             sub Ekps9566::d_() {
3918              
3919 0 0   0 0 0 if (-e $_) {
    0          
3920 0 0       0 return -d _ ? 1 : '';
3921             }
3922             elsif (_MSWin32_5Cended_path($_)) {
3923 0 0       0 return -d "$_/." ? 1 : '';
3924             }
3925 0         0 return undef;
3926             }
3927              
3928             #
3929             # KPS9566 file test -l $_
3930             #
3931             sub Ekps9566::l_() {
3932              
3933 0 0   0 0 0 if (-e $_) {
    0          
3934 0 0       0 return -l _ ? 1 : '';
3935             }
3936             elsif (_MSWin32_5Cended_path($_)) {
3937 0 0       0 if (-d "$_/.") {
3938 0 0       0 return -l _ ? 1 : '';
3939             }
3940             else {
3941 0         0 my $fh = gensym();
3942 0 0       0 if (_open_r($fh, $_)) {
3943 0         0 my $l = -l $fh;
3944 0 0       0 close($fh) or die "Can't close file: $_: $!";
3945 0 0       0 return $l ? 1 : '';
3946             }
3947             }
3948             }
3949 0         0 return undef;
3950             }
3951              
3952             #
3953             # KPS9566 file test -p $_
3954             #
3955             sub Ekps9566::p_() {
3956              
3957 0 0   0 0 0 if (-e $_) {
    0          
3958 0 0       0 return -p _ ? 1 : '';
3959             }
3960             elsif (_MSWin32_5Cended_path($_)) {
3961 0 0       0 if (-d "$_/.") {
3962 0 0       0 return -p _ ? 1 : '';
3963             }
3964             else {
3965 0         0 my $fh = gensym();
3966 0 0       0 if (_open_r($fh, $_)) {
3967 0         0 my $p = -p $fh;
3968 0 0       0 close($fh) or die "Can't close file: $_: $!";
3969 0 0       0 return $p ? 1 : '';
3970             }
3971             }
3972             }
3973 0         0 return undef;
3974             }
3975              
3976             #
3977             # KPS9566 file test -S $_
3978             #
3979             sub Ekps9566::S_() {
3980              
3981 0 0   0 0 0 if (-e $_) {
    0          
3982 0 0       0 return -S _ ? 1 : '';
3983             }
3984             elsif (_MSWin32_5Cended_path($_)) {
3985 0 0       0 if (-d "$_/.") {
3986 0 0       0 return -S _ ? 1 : '';
3987             }
3988             else {
3989 0         0 my $fh = gensym();
3990 0 0       0 if (_open_r($fh, $_)) {
3991 0         0 my $S = -S $fh;
3992 0 0       0 close($fh) or die "Can't close file: $_: $!";
3993 0 0       0 return $S ? 1 : '';
3994             }
3995             }
3996             }
3997 0         0 return undef;
3998             }
3999              
4000             #
4001             # KPS9566 file test -b $_
4002             #
4003             sub Ekps9566::b_() {
4004              
4005 0 0   0 0 0 if (-e $_) {
    0          
4006 0 0       0 return -b _ ? 1 : '';
4007             }
4008             elsif (_MSWin32_5Cended_path($_)) {
4009 0 0       0 if (-d "$_/.") {
4010 0 0       0 return -b _ ? 1 : '';
4011             }
4012             else {
4013 0         0 my $fh = gensym();
4014 0 0       0 if (_open_r($fh, $_)) {
4015 0         0 my $b = -b $fh;
4016 0 0       0 close($fh) or die "Can't close file: $_: $!";
4017 0 0       0 return $b ? 1 : '';
4018             }
4019             }
4020             }
4021 0         0 return undef;
4022             }
4023              
4024             #
4025             # KPS9566 file test -c $_
4026             #
4027             sub Ekps9566::c_() {
4028              
4029 0 0   0 0 0 if (-e $_) {
    0          
4030 0 0       0 return -c _ ? 1 : '';
4031             }
4032             elsif (_MSWin32_5Cended_path($_)) {
4033 0 0       0 if (-d "$_/.") {
4034 0 0       0 return -c _ ? 1 : '';
4035             }
4036             else {
4037 0         0 my $fh = gensym();
4038 0 0       0 if (_open_r($fh, $_)) {
4039 0         0 my $c = -c $fh;
4040 0 0       0 close($fh) or die "Can't close file: $_: $!";
4041 0 0       0 return $c ? 1 : '';
4042             }
4043             }
4044             }
4045 0         0 return undef;
4046             }
4047              
4048             #
4049             # KPS9566 file test -u $_
4050             #
4051             sub Ekps9566::u_() {
4052              
4053 0 0   0 0 0 if (-e $_) {
    0          
4054 0 0       0 return -u _ ? 1 : '';
4055             }
4056             elsif (_MSWin32_5Cended_path($_)) {
4057 0 0       0 if (-d "$_/.") {
4058 0 0       0 return -u _ ? 1 : '';
4059             }
4060             else {
4061 0         0 my $fh = gensym();
4062 0 0       0 if (_open_r($fh, $_)) {
4063 0         0 my $u = -u $fh;
4064 0 0       0 close($fh) or die "Can't close file: $_: $!";
4065 0 0       0 return $u ? 1 : '';
4066             }
4067             }
4068             }
4069 0         0 return undef;
4070             }
4071              
4072             #
4073             # KPS9566 file test -g $_
4074             #
4075             sub Ekps9566::g_() {
4076              
4077 0 0   0 0 0 if (-e $_) {
    0          
4078 0 0       0 return -g _ ? 1 : '';
4079             }
4080             elsif (_MSWin32_5Cended_path($_)) {
4081 0 0       0 if (-d "$_/.") {
4082 0 0       0 return -g _ ? 1 : '';
4083             }
4084             else {
4085 0         0 my $fh = gensym();
4086 0 0       0 if (_open_r($fh, $_)) {
4087 0         0 my $g = -g $fh;
4088 0 0       0 close($fh) or die "Can't close file: $_: $!";
4089 0 0       0 return $g ? 1 : '';
4090             }
4091             }
4092             }
4093 0         0 return undef;
4094             }
4095              
4096             #
4097             # KPS9566 file test -k $_
4098             #
4099             sub Ekps9566::k_() {
4100              
4101 0 0   0 0 0 if ($] =~ /^5\.008/oxms) {
4102 0 0       0 return wantarray ? ('',@_) : '';
4103             }
4104 0 0       0 return wantarray ? ($_,@_) : $_;
4105             }
4106              
4107             #
4108             # KPS9566 file test -T $_
4109             #
4110             sub Ekps9566::T_() {
4111              
4112 0     0 0 0 my $T = 1;
4113              
4114 0 0 0     0 if (-d $_ or -d "$_/.") {
4115 0         0 return undef;
4116             }
4117 0         0 my $fh = gensym();
4118 0 0       0 if (_open_r($fh, $_)) {
4119             }
4120             else {
4121 0         0 return undef;
4122             }
4123              
4124 0 0       0 if (sysread $fh, my $block, 512) {
4125 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
4126 0         0 $T = '';
4127             }
4128             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
4129 0         0 $T = '';
4130             }
4131             }
4132              
4133             # 0 byte or eof
4134             else {
4135 0         0 $T = 1;
4136             }
4137 0         0 my $dummy_for_underline_cache = -T $fh;
4138 0 0       0 close($fh) or die "Can't close file: $_: $!";
4139              
4140 0         0 return $T;
4141             }
4142              
4143             #
4144             # KPS9566 file test -B $_
4145             #
4146             sub Ekps9566::B_() {
4147              
4148 0     0 0 0 my $B = '';
4149              
4150 0 0 0     0 if (-d $_ or -d "$_/.") {
4151 0         0 return undef;
4152             }
4153 0         0 my $fh = gensym();
4154 0 0       0 if (_open_r($fh, $_)) {
4155             }
4156             else {
4157 0         0 return undef;
4158             }
4159              
4160 0 0       0 if (sysread $fh, my $block, 512) {
4161 0 0       0 if ($block =~ /[\000\377]/oxms) {
    0          
4162 0         0 $B = 1;
4163             }
4164             elsif (($block =~ tr/\000-\007\013\016-\032\034-\037\377//) * 10 > CORE::length $block) {
4165 0         0 $B = 1;
4166             }
4167             }
4168              
4169             # 0 byte or eof
4170             else {
4171 0         0 $B = 1;
4172             }
4173 0         0 my $dummy_for_underline_cache = -B $fh;
4174 0 0       0 close($fh) or die "Can't close file: $_: $!";
4175              
4176 0         0 return $B;
4177             }
4178              
4179             #
4180             # KPS9566 file test -M $_
4181             #
4182             sub Ekps9566::M_() {
4183              
4184 0 0   0 0 0 if (-e $_) {
    0          
4185 0         0 return -M _;
4186             }
4187             elsif (_MSWin32_5Cended_path($_)) {
4188 0 0       0 if (-d "$_/.") {
4189 0         0 return -M _;
4190             }
4191             else {
4192 0         0 my $fh = gensym();
4193 0 0       0 if (_open_r($fh, $_)) {
4194 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
4195 0 0       0 close($fh) or die "Can't close file: $_: $!";
4196 0         0 my $M = ($^T - $mtime) / (24*60*60);
4197 0         0 return $M;
4198             }
4199             }
4200             }
4201 0         0 return undef;
4202             }
4203              
4204             #
4205             # KPS9566 file test -A $_
4206             #
4207             sub Ekps9566::A_() {
4208              
4209 0 0   0 0 0 if (-e $_) {
    0          
4210 0         0 return -A _;
4211             }
4212             elsif (_MSWin32_5Cended_path($_)) {
4213 0 0       0 if (-d "$_/.") {
4214 0         0 return -A _;
4215             }
4216             else {
4217 0         0 my $fh = gensym();
4218 0 0       0 if (_open_r($fh, $_)) {
4219 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
4220 0 0       0 close($fh) or die "Can't close file: $_: $!";
4221 0         0 my $A = ($^T - $atime) / (24*60*60);
4222 0         0 return $A;
4223             }
4224             }
4225             }
4226 0         0 return undef;
4227             }
4228              
4229             #
4230             # KPS9566 file test -C $_
4231             #
4232             sub Ekps9566::C_() {
4233              
4234 0 0   0 0 0 if (-e $_) {
    0          
4235 0         0 return -C _;
4236             }
4237             elsif (_MSWin32_5Cended_path($_)) {
4238 0 0       0 if (-d "$_/.") {
4239 0         0 return -C _;
4240             }
4241             else {
4242 0         0 my $fh = gensym();
4243 0 0       0 if (_open_r($fh, $_)) {
4244 0         0 my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = CORE::stat $fh;
4245 0 0       0 close($fh) or die "Can't close file: $_: $!";
4246 0         0 my $C = ($^T - $ctime) / (24*60*60);
4247 0         0 return $C;
4248             }
4249             }
4250             }
4251 0         0 return undef;
4252             }
4253              
4254             #
4255             # KPS9566 path globbing (with parameter)
4256             #
4257             sub Ekps9566::glob($) {
4258              
4259 0 0   0 0 0 if (wantarray) {
4260 0         0 my @glob = _DOS_like_glob(@_);
4261 0         0 for my $glob (@glob) {
4262 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4263             }
4264 0         0 return @glob;
4265             }
4266             else {
4267 0         0 my $glob = _DOS_like_glob(@_);
4268 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4269 0         0 return $glob;
4270             }
4271             }
4272              
4273             #
4274             # KPS9566 path globbing (without parameter)
4275             #
4276             sub Ekps9566::glob_() {
4277              
4278 0 0   0 0 0 if (wantarray) {
4279 0         0 my @glob = _DOS_like_glob();
4280 0         0 for my $glob (@glob) {
4281 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4282             }
4283 0         0 return @glob;
4284             }
4285             else {
4286 0         0 my $glob = _DOS_like_glob();
4287 0         0 $glob =~ s{ \A (?:\./)+ }{}oxms;
4288 0         0 return $glob;
4289             }
4290             }
4291              
4292             #
4293             # KPS9566 path globbing via File::DosGlob 1.10
4294             #
4295             # Often I confuse "_dosglob" and "_doglob".
4296             # So, I renamed "_dosglob" to "_DOS_like_glob".
4297             #
4298             my %iter;
4299             my %entries;
4300             sub _DOS_like_glob {
4301              
4302             # context (keyed by second cxix argument provided by core)
4303 0     0   0 my($expr,$cxix) = @_;
4304              
4305             # glob without args defaults to $_
4306 0 0       0 $expr = $_ if not defined $expr;
4307              
4308             # represents the current user's home directory
4309             #
4310             # 7.3. Expanding Tildes in Filenames
4311             # in Chapter 7. File Access
4312             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
4313             #
4314             # and File::HomeDir, File::HomeDir::Windows module
4315              
4316             # DOS-like system
4317 0 0       0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
4318 0         0 $expr =~ s{ \A ~ (?= [^/\\] ) }
  0         0  
4319             { my_home_MSWin32() }oxmse;
4320             }
4321              
4322             # UNIX-like system
4323 0 0 0     0 else {
  0         0  
4324             $expr =~ s{ \A ~ ( (?:[^\x81-\xFE/]|[\x81-\xFE][\x00-\xFF])* ) }
4325             { $1 ? (CORE::eval(q{(getpwnam($1))[7]})||my_home()) : my_home() }oxmse;
4326             }
4327 0 0       0  
4328 0 0       0 # assume global context if not provided one
4329             $cxix = '_G_' if not defined $cxix;
4330             $iter{$cxix} = 0 if not exists $iter{$cxix};
4331 0 0       0  
4332 0         0 # if we're just beginning, do it all first
4333             if ($iter{$cxix} == 0) {
4334             $entries{$cxix} = [ _do_glob(1, _parse_line($expr)) ];
4335             }
4336 0 0       0  
4337 0         0 # chuck it all out, quick or slow
4338 0         0 if (wantarray) {
  0         0  
4339             delete $iter{$cxix};
4340             return @{delete $entries{$cxix}};
4341 0 0       0 }
  0         0  
4342 0         0 else {
  0         0  
4343             if ($iter{$cxix} = scalar @{$entries{$cxix}}) {
4344             return shift @{$entries{$cxix}};
4345             }
4346 0         0 else {
4347 0         0 # return undef for EOL
4348 0         0 delete $iter{$cxix};
4349             delete $entries{$cxix};
4350             return undef;
4351             }
4352             }
4353             }
4354              
4355             #
4356             # KPS9566 path globbing subroutine
4357             #
4358 0     0   0 sub _do_glob {
4359 0         0  
4360 0         0 my($cond,@expr) = @_;
4361             my @glob = ();
4362             my $fix_drive_relative_paths = 0;
4363 0         0  
4364 0 0       0 OUTER:
4365 0 0       0 for my $expr (@expr) {
4366             next OUTER if not defined $expr;
4367 0         0 next OUTER if $expr eq '';
4368 0         0  
4369 0         0 my @matched = ();
4370 0         0 my @globdir = ();
4371 0         0 my $head = '.';
4372             my $pathsep = '/';
4373             my $tail;
4374 0 0       0  
4375 0         0 # if argument is within quotes strip em and do no globbing
4376 0 0       0 if ($expr =~ /\A " ((?:$q_char)*?) " \z/oxms) {
4377 0 0       0 $expr = $1;
4378 0         0 if ($cond eq 'd') {
4379             if (Ekps9566::d $expr) {
4380             push @glob, $expr;
4381             }
4382 0 0       0 }
4383 0         0 else {
4384             if (Ekps9566::e $expr) {
4385             push @glob, $expr;
4386 0         0 }
4387             }
4388             next OUTER;
4389             }
4390              
4391 0 0       0 # wildcards with a drive prefix such as h:*.pm must be changed
4392 0 0       0 # to h:./*.pm to expand correctly
4393 0         0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
4394             if ($expr =~ s# \A ((?:[A-Za-z]:)?) ([^\x81-\xFE/\\]|[\x81-\xFE][\x00-\xFF]) #$1./$2#oxms) {
4395             $fix_drive_relative_paths = 1;
4396             }
4397 0 0       0 }
4398 0 0       0  
4399 0         0 if (($head, $tail) = _parse_path($expr,$pathsep)) {
4400 0         0 if ($tail eq '') {
4401             push @glob, $expr;
4402 0 0       0 next OUTER;
4403 0 0       0 }
4404 0         0 if ($head =~ / \A (?:$q_char)*? [*?] /oxms) {
  0         0  
4405 0         0 if (@globdir = _do_glob('d', $head)) {
4406             push @glob, _do_glob($cond, map {"$_$pathsep$tail"} @globdir);
4407             next OUTER;
4408 0 0 0     0 }
4409 0         0 }
4410             if ($head eq '' or $head =~ /\A [A-Za-z]: \z/oxms) {
4411 0         0 $head .= $pathsep;
4412             }
4413             $expr = $tail;
4414             }
4415 0 0       0  
4416 0 0       0 # If file component has no wildcards, we can avoid opendir
4417 0         0 if ($expr !~ / \A (?:$q_char)*? [*?] /oxms) {
4418             if ($head eq '.') {
4419 0 0 0     0 $head = '';
4420 0         0 }
4421             if ($head ne '' and ($head =~ / \G ($q_char) /oxmsg)[-1] ne $pathsep) {
4422 0         0 $head .= $pathsep;
4423 0 0       0 }
4424 0 0       0 $head .= $expr;
4425 0         0 if ($cond eq 'd') {
4426             if (Ekps9566::d $head) {
4427             push @glob, $head;
4428             }
4429 0 0       0 }
4430 0         0 else {
4431             if (Ekps9566::e $head) {
4432             push @glob, $head;
4433 0         0 }
4434             }
4435 0 0       0 next OUTER;
4436 0         0 }
4437 0         0 Ekps9566::opendir(*DIR, $head) or next OUTER;
4438             my @leaf = readdir DIR;
4439 0 0       0 closedir DIR;
4440 0         0  
4441             if ($head eq '.') {
4442 0 0 0     0 $head = '';
4443 0         0 }
4444             if ($head ne '' and ($head =~ / \G ($q_char) /oxmsg)[-1] ne $pathsep) {
4445             $head .= $pathsep;
4446 0         0 }
4447 0         0  
4448 0         0 my $pattern = '';
4449             while ($expr =~ / \G ($q_char) /oxgc) {
4450             my $char = $1;
4451              
4452             # 6.9. Matching Shell Globs as Regular Expressions
4453             # in Chapter 6. Pattern Matching
4454             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
4455 0 0       0 # (and so on)
    0          
    0          
4456 0         0  
4457             if ($char eq '*') {
4458             $pattern .= "(?:$your_char)*",
4459 0         0 }
4460             elsif ($char eq '?') {
4461             $pattern .= "(?:$your_char)?", # DOS style
4462             # $pattern .= "(?:$your_char)", # UNIX style
4463 0         0 }
4464             elsif ((my $fc = Ekps9566::fc($char)) ne $char) {
4465             $pattern .= $fc;
4466 0         0 }
4467             else {
4468             $pattern .= quotemeta $char;
4469 0     0   0 }
  0         0  
4470             }
4471             my $matchsub = sub { Ekps9566::fc($_[0]) =~ /\A $pattern \z/xms };
4472              
4473             # if ($@) {
4474             # print STDERR "$0: $@\n";
4475             # next OUTER;
4476             # }
4477 0         0  
4478 0 0 0     0 INNER:
4479 0         0 for my $leaf (@leaf) {
4480             if ($leaf eq '.' or $leaf eq '..') {
4481 0 0 0     0 next INNER;
4482 0         0 }
4483             if ($cond eq 'd' and not Ekps9566::d "$head$leaf") {
4484             next INNER;
4485 0 0       0 }
4486 0         0  
4487 0         0 if (&$matchsub($leaf)) {
4488             push @matched, "$head$leaf";
4489             next INNER;
4490             }
4491              
4492             # [DOS compatibility special case]
4493 0 0 0     0 # Failed, add a trailing dot and try again, but only...
      0        
4494              
4495             if (Ekps9566::index($leaf,'.') == -1 and # if name does not have a dot in it *and*
4496             CORE::length($leaf) <= 8 and # name is shorter than or equal to 8 chars *and*
4497 0 0       0 Ekps9566::index($pattern,'\\.') != -1 # pattern has a dot.
4498 0         0 ) {
4499 0         0 if (&$matchsub("$leaf.")) {
4500             push @matched, "$head$leaf";
4501             next INNER;
4502             }
4503 0 0       0 }
4504 0         0 }
4505             if (@matched) {
4506             push @glob, @matched;
4507 0 0       0 }
4508 0         0 }
4509 0         0 if ($fix_drive_relative_paths) {
4510             for my $glob (@glob) {
4511             $glob =~ s# \A ([A-Za-z]:) \./ #$1#oxms;
4512 0         0 }
4513             }
4514             return @glob;
4515             }
4516              
4517             #
4518             # KPS9566 parse line
4519             #
4520 0     0   0 sub _parse_line {
4521              
4522 0         0 my($line) = @_;
4523 0         0  
4524 0         0 $line .= ' ';
4525             my @piece = ();
4526             while ($line =~ /
4527             " ( (?>(?: [^\x81-\xFE"] |[\x81-\xFE][\x00-\xFF] )* ) ) " (?>\s+) |
4528             ( (?>(?: [^\x81-\xFE"\s]|[\x81-\xFE][\x00-\xFF] )* ) ) (?>\s+)
4529 0 0       0 /oxmsg
4530             ) {
4531 0         0 push @piece, defined($1) ? $1 : $2;
4532             }
4533             return @piece;
4534             }
4535              
4536             #
4537             # KPS9566 parse path
4538             #
4539 0     0   0 sub _parse_path {
4540              
4541 0         0 my($path,$pathsep) = @_;
4542 0         0  
4543 0         0 $path .= '/';
4544             my @subpath = ();
4545             while ($path =~ /
4546             ((?: [^\x81-\xFE\/\\]|[\x81-\xFE][\x00-\xFF] )+?) [\/\\]
4547 0         0 /oxmsg
4548             ) {
4549             push @subpath, $1;
4550 0         0 }
4551 0         0  
4552 0         0 my $tail = pop @subpath;
4553             my $head = join $pathsep, @subpath;
4554             return $head, $tail;
4555             }
4556              
4557             #
4558             # via File::HomeDir::Windows 1.00
4559             #
4560             sub my_home_MSWin32 {
4561              
4562             # A lot of unix people and unix-derived tools rely on
4563 0 0 0 0 0 0 # the ability to overload HOME. We will support it too
    0 0        
    0 0        
      0        
      0        
4564 0         0 # so that they can replace raw HOME calls with File::HomeDir.
4565             if (exists $ENV{'HOME'} and $ENV{'HOME'}) {
4566             return $ENV{'HOME'};
4567             }
4568              
4569 0         0 # Do we have a user profile?
4570             elsif (exists $ENV{'USERPROFILE'} and $ENV{'USERPROFILE'}) {
4571             return $ENV{'USERPROFILE'};
4572             }
4573              
4574 0         0 # Some Windows use something like $ENV{'HOME'}
4575             elsif (exists $ENV{'HOMEDRIVE'} and exists $ENV{'HOMEPATH'} and $ENV{'HOMEDRIVE'} and $ENV{'HOMEPATH'}) {
4576             return join '', $ENV{'HOMEDRIVE'}, $ENV{'HOMEPATH'};
4577 0         0 }
4578              
4579             return undef;
4580             }
4581              
4582             #
4583             # via File::HomeDir::Unix 1.00
4584 0     0 0 0 #
4585             sub my_home {
4586 0 0 0     0 my $home;
    0 0        
4587 0         0  
4588             if (exists $ENV{'HOME'} and defined $ENV{'HOME'}) {
4589             $home = $ENV{'HOME'};
4590             }
4591              
4592             # This is from the original code, but I'm guessing
4593 0         0 # it means "login directory" and exists on some Unixes.
4594             elsif (exists $ENV{'LOGDIR'} and $ENV{'LOGDIR'}) {
4595             $home = $ENV{'LOGDIR'};
4596             }
4597              
4598             ### More-desperate methods
4599              
4600 0         0 # Light desperation on any (Unixish) platform
4601             else {
4602             $home = CORE::eval q{ (getpwuid($<))[7] };
4603             }
4604              
4605 0 0 0     0 # On Unix in general, a non-existant home means "no home"
4606 0         0 # For example, "nobody"-like users might use /nonexistant
4607             if (defined $home and ! Ekps9566::d($home)) {
4608 0         0 $home = undef;
4609             }
4610             return $home;
4611             }
4612              
4613             #
4614             # KPS9566 file lstat (with parameter)
4615             #
4616 0 0   0 0 0 sub Ekps9566::lstat(*) {
4617              
4618 0 0       0 local $_ = shift if @_;
    0          
4619 0         0  
4620             if (-e $_) {
4621             return CORE::lstat _;
4622             }
4623             elsif (_MSWin32_5Cended_path($_)) {
4624              
4625             # Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Ekps9566::lstat()
4626             # on Windows opens the file for the path which has 5c at end.
4627 0         0 # (and so on)
4628 0 0       0  
4629 0 0       0 local *MUST_BE_BAREWORD_AT_HERE;
4630 0         0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
4631 0 0       0 if (wantarray) {
4632 0         0 my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
4633             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4634             return @stat;
4635 0         0 }
4636 0 0       0 else {
4637 0         0 my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
4638             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4639             return $stat;
4640             }
4641 0 0       0 }
4642             }
4643             return wantarray ? () : undef;
4644             }
4645              
4646             #
4647             # KPS9566 file lstat (without parameter)
4648             #
4649 0 0   0 0 0 sub Ekps9566::lstat_() {
    0          
4650 0         0  
4651             if (-e $_) {
4652             return CORE::lstat _;
4653 0         0 }
4654 0 0       0 elsif (_MSWin32_5Cended_path($_)) {
4655 0 0       0 local *MUST_BE_BAREWORD_AT_HERE;
4656 0         0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
4657 0 0       0 if (wantarray) {
4658 0         0 my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
4659             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4660             return @stat;
4661 0         0 }
4662 0 0       0 else {
4663 0         0 my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE; # not CORE::lstat
4664             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4665             return $stat;
4666             }
4667 0 0       0 }
4668             }
4669             return wantarray ? () : undef;
4670             }
4671              
4672             #
4673             # KPS9566 path opendir
4674             #
4675 0     0 0 0 sub Ekps9566::opendir(*$) {
4676 0 0       0  
    0          
4677 0         0 my $dh = qualify_to_ref $_[0];
4678             if (CORE::opendir $dh, $_[1]) {
4679             return 1;
4680 0 0       0 }
4681 0         0 elsif (_MSWin32_5Cended_path($_[1])) {
4682             if (CORE::opendir $dh, "$_[1]/.") {
4683             return 1;
4684 0         0 }
4685             }
4686             return undef;
4687             }
4688              
4689             #
4690             # KPS9566 file stat (with parameter)
4691             #
4692 0 50   384 0 0 sub Ekps9566::stat(*) {
4693              
4694 384         2244 local $_ = shift if @_;
4695 384 50       1946  
    50          
    0          
4696 384         12758 my $fh = qualify_to_ref $_;
4697             if (defined fileno $fh) {
4698             return CORE::stat $fh;
4699 0         0 }
4700             elsif (-e $_) {
4701             return CORE::stat _;
4702             }
4703             elsif (_MSWin32_5Cended_path($_)) {
4704              
4705             # Even if ${^WIN32_SLOPPY_STAT} is set to a true value, Ekps9566::stat()
4706             # on Windows opens the file for the path which has 5c at end.
4707 384         2958 # (and so on)
4708 0 0       0  
4709 0 0       0 local *MUST_BE_BAREWORD_AT_HERE;
4710 0         0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
4711 0 0       0 if (wantarray) {
4712 0         0 my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
4713             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4714             return @stat;
4715 0         0 }
4716 0 0       0 else {
4717 0         0 my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
4718             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4719             return $stat;
4720             }
4721 0 0       0 }
4722             }
4723             return wantarray ? () : undef;
4724             }
4725              
4726             #
4727             # KPS9566 file stat (without parameter)
4728             #
4729 0     0 0 0 sub Ekps9566::stat_() {
4730 0 0       0  
    0          
    0          
4731 0         0 my $fh = qualify_to_ref $_;
4732             if (defined fileno $fh) {
4733             return CORE::stat $fh;
4734 0         0 }
4735             elsif (-e $_) {
4736             return CORE::stat _;
4737 0         0 }
4738 0 0       0 elsif (_MSWin32_5Cended_path($_)) {
4739 0 0       0 local *MUST_BE_BAREWORD_AT_HERE;
4740 0         0 if (CORE::open(MUST_BE_BAREWORD_AT_HERE, $_)) {
4741 0 0       0 if (wantarray) {
4742 0         0 my @stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
4743             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4744             return @stat;
4745 0         0 }
4746 0 0       0 else {
4747 0         0 my $stat = CORE::stat MUST_BE_BAREWORD_AT_HERE;
4748             close(MUST_BE_BAREWORD_AT_HERE) or die "Can't close file: $_: $!";
4749             return $stat;
4750             }
4751 0 0       0 }
4752             }
4753             return wantarray ? () : undef;
4754             }
4755              
4756             #
4757             # KPS9566 path unlink
4758             #
4759 0 0   0 0 0 sub Ekps9566::unlink(@) {
4760              
4761 0         0 local @_ = ($_) unless @_;
4762 0         0  
4763 0 0       0 my $unlink = 0;
    0          
    0          
4764 0         0 for (@_) {
4765             if (CORE::unlink) {
4766             $unlink++;
4767             }
4768             elsif (Ekps9566::d($_)) {
4769 0         0 }
4770 0 0       0 elsif (_MSWin32_5Cended_path($_)) {
  0         0  
4771 0 0       0 my @char = /\G (?>$q_char) /oxmsg;
4772 0         0 my $file = join '', map {{'/' => '\\'}->{$_} || $_} @char;
4773             if ($file =~ / \A (?:$q_char)*? [ ] /oxms) {
4774 0         0 $file = qq{"$file"};
4775 0 0       0 }
4776 0 0       0 my $fh = gensym();
4777             if (_open_r($fh, $_)) {
4778             close($fh) or die "Can't close file: $_: $!";
4779 0 0 0     0  
    0          
4780 0         0 # cmd.exe on Windows NT, Windows 2000, Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10 or later
4781             if ((defined $ENV{'OS'}) and ($ENV{'OS'} eq 'Windows_NT')) {
4782             CORE::system 'DEL', '/F', $file, '2>NUL';
4783             }
4784              
4785 0         0 # Win95Cmd.exe on any Windows (when SET PERL5SHELL=Win95Cmd.exe /c, `var` returns "Windows 2000")
4786             elsif (qx{ver} =~ /\b(?:Windows 2000)\b/oms) {
4787             CORE::system 'DEL', '/F', $file, '2>NUL';
4788             }
4789              
4790             # COMMAND.COM on Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition
4791 0         0 # command.com can not "2>NUL"
4792 0         0 else {
4793             CORE::system 'ATTRIB', '-R', $file; # clears Read-only file attribute
4794             CORE::system 'DEL', $file;
4795 0 0       0 }
4796 0 0       0  
4797             if (_open_r($fh, $_)) {
4798             close($fh) or die "Can't close file: $_: $!";
4799 0         0 }
4800             else {
4801             $unlink++;
4802             }
4803             }
4804 0         0 }
4805             }
4806             return $unlink;
4807             }
4808              
4809             #
4810             # KPS9566 chdir
4811             #
4812 0 0   0 0 0 sub Ekps9566::chdir(;$) {
4813 0         0  
4814             if (@_ == 0) {
4815             return CORE::chdir;
4816 0         0 }
4817              
4818 0 0       0 my($dir) = @_;
4819 0 0       0  
4820 0         0 if (_MSWin32_5Cended_path($dir)) {
4821             if (not Ekps9566::d $dir) {
4822             return 0;
4823 0 0 0     0 }
    0          
4824 0         0  
4825             if ($] =~ /^5\.005/oxms) {
4826             return CORE::chdir $dir;
4827 0         0 }
4828 0         0 elsif (($] =~ /^(?:5\.006|5\.008000)/oxms) and ($^O eq 'MSWin32')) {
4829             local $@;
4830             my $chdir = CORE::eval q{
4831             CORE::require 'jacode.pl';
4832              
4833             # P.676 ${^WIDE_SYSTEM_CALLS}
4834             # in Chapter 28: Special Names
4835             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
4836              
4837             # P.790 ${^WIDE_SYSTEM_CALLS}
4838             # in Chapter 25: Special Names
4839             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
4840              
4841             local ${^WIDE_SYSTEM_CALLS} = 1;
4842 0 0       0 return CORE::chdir jcode::utf8($dir,'sjis');
4843 0         0 };
4844             if (not $@) {
4845             return $chdir;
4846             }
4847             }
4848              
4849             # old idea (Win32 module required)
4850             elsif (0) {
4851             local $@;
4852             my $shortdir = '';
4853             my $chdir = CORE::eval q{
4854             use Win32;
4855             $shortdir = Win32::GetShortPathName($dir);
4856             if ($shortdir ne $dir) {
4857             return CORE::chdir $shortdir;
4858             }
4859             else {
4860             return 0;
4861             }
4862             };
4863             if ($@) {
4864             my @char = $dir =~ /\G (?>$q_char) /oxmsg;
4865             while ($char[-1] eq "\x5C") {
4866             pop @char;
4867             }
4868             $dir = join '', @char;
4869             croak "Perl$] can't chdir to $dir (chr(0x5C) ended path), Win32.pm module may help you";
4870             }
4871             elsif ($shortdir eq $dir) {
4872             my @char = $dir =~ /\G (?>$q_char) /oxmsg;
4873             while ($char[-1] eq "\x5C") {
4874             pop @char;
4875             }
4876             $dir = join '', @char;
4877             croak "Perl$] can't chdir to $dir (chr(0x5C) ended path)";
4878             }
4879             return $chdir;
4880             }
4881 0         0  
4882             # rejected idea ...
4883             elsif (0) {
4884              
4885             # MSDN SetCurrentDirectory function
4886             # http://msdn.microsoft.com/ja-jp/library/windows/desktop/aa365530(v=vs.85).aspx
4887             #
4888             # Data Execution Prevention (DEP)
4889             # http://vlaurie.com/computers2/Articles/dep.htm
4890             #
4891             # Learning x86 assembler with Perl -- Shibuya.pm#11
4892             # http://developer.cybozu.co.jp/takesako/2009/06/perl-x86-shibuy.html
4893             #
4894             # Introduction to Win32::API programming in Perl
4895             # http://d.hatena.ne.jp/TAKESAKO/20090324/1237879559
4896             #
4897             # DynaLoader - Dynamically load C libraries into Perl code
4898             # http://perldoc.perl.org/DynaLoader.html
4899             #
4900             # Basic knowledge of DynaLoader
4901             # http://blog.64p.org/entry/20090313/1236934042
4902              
4903             if (($] =~ /^5\.006/oxms) and
4904             ($^O eq 'MSWin32') and
4905             ($ENV{'PROCESSOR_ARCHITECTURE'} eq 'x86') and
4906             CORE::eval(q{CORE::require 'Dyna'.'Loader'})
4907             ) {
4908             my $x86 = join('',
4909              
4910             # PUSH Iv
4911             "\x68", pack('P', "$dir\\\0"),
4912              
4913             # MOV eAX, Iv
4914             "\xb8", pack('L',
4915             *{'Dyna'.'Loader::dl_find_symbol'}{'CODE'}->(
4916             *{'Dyna'.'Loader::dl_load_file'}{'CODE'}->("$ENV{'SystemRoot'}\\system32\\kernel32.dll"),
4917             'SetCurrentDirectoryA'
4918             )
4919             ),
4920              
4921             # CALL eAX
4922             "\xff\xd0",
4923              
4924             # RETN
4925             "\xc3",
4926             );
4927             *{'Dyna'.'Loader::dl_install_xsub'}{'CODE'}->('_SetCurrentDirectoryA', unpack('L', pack 'P', $x86));
4928             _SetCurrentDirectoryA();
4929             chomp(my $chdir = qx{chdir});
4930             if (Ekps9566::fc($chdir) eq Ekps9566::fc($dir)) {
4931             return 1;
4932             }
4933             else {
4934             return 0;
4935             }
4936             }
4937             }
4938              
4939             # COMMAND.COM's unhelpful tips:
4940             # Displays a list of files and subdirectories in a directory.
4941             # http://www.lagmonster.org/docs/DOS7/z-dir.html
4942             #
4943             # Syntax:
4944             #
4945             # DIR [drive:] [path] [filename] [/Switches]
4946             #
4947             # /Z Long file names are not displayed in the file listing
4948             #
4949             # Limitations
4950             # The undocumented /Z switch (no long names) would appear to
4951             # have been not fully developed and has a couple of problems:
4952             #
4953             # 1. It will only work if:
4954             # There is no path specified (ie. for the current directory in
4955             # the current drive)
4956             # The path is specified as the root directory of any drive
4957             # (eg. C:\, D:\, etc.)
4958             # The path is specified as the current directory of any drive
4959             # by using the drive letter only (eg. C:, D:, etc.)
4960             # The path is specified as the parent directory using the ..
4961             # notation (eg. DIR .. /Z)
4962             # Any other syntax results in a "File Not Found" error message.
4963             #
4964             # 2. The /Z switch is compatable with the /S switch to show
4965             # subdirectories (as long as the above rules are followed) and
4966             # all the files are shown with short names only. The
4967             # subdirectories are also shown with short names only. However,
4968             # the header for each subdirectory after the first level gives
4969             # the subdirectory's long name.
4970             #
4971             # 3. The /Z switch is also compatable with the /B switch to give
4972             # a simple list of files with short names only. When used with
4973             # the /S switch as well, all files are listed with their full
4974             # paths. The file names themselves are all in short form, and
4975             # the path of those files in the current directory are in short
4976             # form, but the paths of any files in subdirectories are in
4977 0         0 # long filename form.
4978 0         0  
4979 0         0 my $shortdir = '';
4980 0         0 my $i = 0;
4981 0         0 my @subdir = ();
4982 0 0 0     0 while ($dir =~ / \G ($q_char) /oxgc) {
4983 0         0 my $char = $1;
4984 0         0 if (($char eq '\\') or ($char eq '/')) {
4985 0         0 $i++;
4986             $subdir[$i] = $char;
4987             $i++;
4988 0         0 }
4989             else {
4990             $subdir[$i] .= $char;
4991 0 0 0     0 }
4992 0         0 }
4993             if (($subdir[-1] eq '\\') or ($subdir[-1] eq '/')) {
4994             pop @subdir;
4995             }
4996              
4997             # P.504 PERL5SHELL (Microsoft ports only)
4998             # in Chapter 19: The Command-Line Interface
4999             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
5000              
5001             # P.597 PERL5SHELL (Microsoft ports only)
5002             # in Chapter 17: The Command-Line Interface
5003             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5004              
5005 0 0 0     0 # Win95Cmd.exe on any Windows (when SET PERL5SHELL=Win95Cmd.exe /c, `var` returns "Windows 2000")
    0          
5006 0         0 # cmd.exe on Windows NT, Windows 2000
5007 0         0 if (qx{ver} =~ /\b(?:Windows NT|Windows 2000)\b/oms) {
  0         0  
5008 0 0       0 chomp(my @dirx = grep //oxms, qx{dir /ad /x "$dir*" 2>NUL});
5009             for my $dirx (sort { CORE::length($a) <=> CORE::length($b) } @dirx) {
5010             if (Ekps9566::fc(CORE::substr $dirx,-CORE::length($subdir[-1]),CORE::length($subdir[-1])) eq Ekps9566::fc($subdir[-1])) {
5011 0         0  
5012 0         0 # short file name (8dot3name) here-----vv
5013 0         0 my $shortleafdir = CORE::substr $dirx, 39, 8+1+3;
5014 0         0 $shortleafdir =~ s/ [ ]+ \z//oxms;
5015             $shortdir = join '', @subdir[0..$#subdir-1], $shortleafdir;
5016             last;
5017             }
5018             }
5019             }
5020              
5021             # an idea (not so portable, only Windows 2000 or later)
5022             elsif (0) {
5023             chomp($shortdir = qx{for %I in ("$dir") do \@echo %~sI 2>NUL});
5024             }
5025              
5026 0         0 # cmd.exe on Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10 or later
5027 0         0 elsif ((defined $ENV{'OS'}) and ($ENV{'OS'} eq 'Windows_NT')) {
  0         0  
5028 0 0       0 chomp(my @dirx = grep //oxms, qx{dir /ad /x "$dir*" 2>NUL});
5029             for my $dirx (sort { CORE::length($a) <=> CORE::length($b) } @dirx) {
5030             if (Ekps9566::fc(CORE::substr $dirx,-CORE::length($subdir[-1]),CORE::length($subdir[-1])) eq Ekps9566::fc($subdir[-1])) {
5031 0         0  
5032 0         0 # short file name (8dot3name) here-----vv
5033 0         0 my $shortleafdir = CORE::substr $dirx, 36, 8+1+3;
5034 0         0 $shortleafdir =~ s/ [ ]+ \z//oxms;
5035             $shortdir = join '', @subdir[0..$#subdir-1], $shortleafdir;
5036             last;
5037             }
5038             }
5039             }
5040              
5041 0         0 # COMMAND.COM on Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition
5042 0         0 else {
  0         0  
5043 0 0       0 chomp(my @dirx = grep //oxms, qx{dir /ad "$dir*"});
5044             for my $dirx (sort { CORE::length($a) <=> CORE::length($b) } @dirx) {
5045             if (Ekps9566::fc(CORE::substr $dirx,-CORE::length($subdir[-1]),CORE::length($subdir[-1])) eq Ekps9566::fc($subdir[-1])) {
5046 0         0  
5047 0         0 # short file name (8dot3name) here-----v
5048 0         0 my $shortleafdir = CORE::substr $dirx, 0, 8+1+3;
5049 0         0 CORE::substr($shortleafdir,8,1) = '.';
5050 0         0 $shortleafdir =~ s/ \. [ ]+ \z//oxms;
5051             $shortdir = join '', @subdir[0..$#subdir-1], $shortleafdir;
5052             last;
5053             }
5054             }
5055 0 0       0 }
    0          
5056 0         0  
5057             if ($shortdir eq '') {
5058             return 0;
5059 0         0 }
5060             elsif (Ekps9566::fc($shortdir) eq Ekps9566::fc($dir)) {
5061 0         0 return 0;
5062             }
5063             return CORE::chdir $shortdir;
5064 0         0 }
5065             else {
5066             return CORE::chdir $dir;
5067             }
5068             }
5069              
5070             #
5071             # KPS9566 chr(0x5C) ended path on MSWin32
5072             #
5073 0 50 33 768   0 sub _MSWin32_5Cended_path {
5074 768 50       4920  
5075 768         4438 if ((@_ >= 1) and ($_[0] ne '')) {
5076 0 0       0 if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
5077 0         0 my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
5078             if ($char[-1] =~ / \x5C \z/oxms) {
5079             return 1;
5080             }
5081 0         0 }
5082             }
5083             return undef;
5084             }
5085              
5086             #
5087             # do KPS9566 file
5088             #
5089 768     0 0 1907 sub Ekps9566::do($) {
5090              
5091 0         0 my($filename) = @_;
5092              
5093             my $realfilename;
5094             my $result;
5095 0         0 ITER_DO:
  0         0  
5096 0 0       0 {
5097 0         0 for my $prefix (@INC) {
5098             if ($^O eq 'MacOS') {
5099             $realfilename = "$prefix$filename";
5100 0         0 }
5101             else {
5102             $realfilename = "$prefix/$filename";
5103 0 0       0 }
5104              
5105 0         0 if (Ekps9566::f($realfilename)) {
5106              
5107 0 0       0 my $script = '';
5108 0         0  
5109 0         0 if (Ekps9566::e("$realfilename.e")) {
5110 0         0 my $e_mtime = (Ekps9566::stat("$realfilename.e"))[9];
5111 0 0 0     0 my $mtime = (Ekps9566::stat($realfilename))[9];
5112 0         0 my $module_mtime = (Ekps9566::stat(__FILE__))[9];
5113             if (($e_mtime < $mtime) or ($mtime < $module_mtime)) {
5114             Ekps9566::unlink "$realfilename.e";
5115             }
5116 0 0       0 }
5117 0         0  
5118 0 0       0 if (Ekps9566::e("$realfilename.e")) {
5119 0 0       0 my $fh = gensym();
    0          
5120 0         0 if (_open_r($fh, "$realfilename.e")) {
5121             if ($^O eq 'MacOS') {
5122             CORE::eval q{
5123             CORE::require Mac::Files;
5124             Mac::Files::FSpSetFLock("$realfilename.e");
5125             };
5126             }
5127             elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5128              
5129             # P.419 File Locking
5130             # in Chapter 16: Interprocess Communication
5131             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
5132              
5133             # P.524 File Locking
5134             # in Chapter 15: Interprocess Communication
5135             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5136              
5137 0         0 # (and so on)
5138 0 0       0  
5139 0         0 CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5140             if ($@) {
5141             carp "Can't immediately read-lock the file: $realfilename.e";
5142             }
5143 0         0 }
5144             else {
5145 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5146 0         0 }
5147 0 0       0 local $/ = undef; # slurp mode
5148 0         0 $script = <$fh>;
5149             if ($^O eq 'MacOS') {
5150             CORE::eval q{
5151             CORE::require Mac::Files;
5152             Mac::Files::FSpRstFLock("$realfilename.e");
5153 0 0       0 };
5154             }
5155             close($fh) or die "Can't close file: $realfilename.e: $!";
5156             }
5157 0         0 }
5158 0 0       0 else {
5159 0 0       0 my $fh = gensym();
    0          
5160 0         0 if (_open_r($fh, $realfilename)) {
5161             if ($^O eq 'MacOS') {
5162             CORE::eval q{
5163             CORE::require Mac::Files;
5164             Mac::Files::FSpSetFLock($realfilename);
5165             };
5166 0         0 }
5167 0 0       0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5168 0         0 CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5169             if ($@) {
5170             carp "Can't immediately read-lock the file: $realfilename";
5171             }
5172 0         0 }
5173             else {
5174 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5175 0         0 }
5176 0 0       0 local $/ = undef; # slurp mode
5177 0         0 $script = <$fh>;
5178             if ($^O eq 'MacOS') {
5179             CORE::eval q{
5180             CORE::require Mac::Files;
5181             Mac::Files::FSpRstFLock($realfilename);
5182 0 0       0 };
5183             }
5184             close($fh) or die "Can't close file: $realfilename.e: $!";
5185 0 0       0 }
5186 0         0  
5187 0         0 if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
5188 0         0 CORE::require KPS9566;
5189 0 0       0 $script = KPS9566::escape_script($script);
5190 0 0       0 my $fh = gensym();
    0          
5191 0         0 open($fh, ">$realfilename.e") or die __FILE__, ": Can't write open file: $realfilename.e\n";
5192             if ($^O eq 'MacOS') {
5193             CORE::eval q{
5194             CORE::require Mac::Files;
5195             Mac::Files::FSpSetFLock("$realfilename.e");
5196             };
5197 0         0 }
5198 0 0       0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5199 0         0 CORE::eval q{ flock($fh, LOCK_EX | LOCK_NB) };
5200             if ($@) {
5201             carp "Can't immediately write-lock the file: $realfilename.e";
5202             }
5203 0         0 }
5204             else {
5205 0         0 CORE::eval q{ flock($fh, LOCK_EX) };
5206 0 0       0 }
5207 0         0 CORE::eval q{ truncate($fh, 0) };
  0         0  
5208 0 0       0 seek($fh, 0, 0) or croak "Can't seek file: $realfilename.e";
5209 0         0 print {$fh} $script;
5210             if ($^O eq 'MacOS') {
5211             CORE::eval q{
5212             CORE::require Mac::Files;
5213             Mac::Files::FSpRstFLock("$realfilename.e");
5214 0 0       0 };
5215             }
5216             close($fh) or die "Can't close file: $realfilename.e: $!";
5217             }
5218             }
5219 389     389   4639  
  389         813  
  389         344913  
  0         0  
5220 0         0 {
5221             no strict;
5222 0         0 $result = scalar CORE::eval $script;
5223             }
5224             last ITER_DO;
5225             }
5226             }
5227 0 0       0 }
    0          
5228 0         0  
5229 0         0 if ($@) {
5230             $INC{$filename} = undef;
5231             return undef;
5232 0         0 }
5233             elsif (not $result) {
5234             return undef;
5235 0         0 }
5236 0         0 else {
5237             $INC{$filename} = $realfilename;
5238             return $result;
5239             }
5240             }
5241              
5242             #
5243             # require KPS9566 file
5244             #
5245              
5246             # require
5247             # in Chapter 3: Functions
5248             # of ISBN 1-56592-149-6 Programming Perl, Second Edition.
5249             #
5250             # sub require {
5251             # my($filename) = @_;
5252             # return 1 if $INC{$filename};
5253             # my($realfilename, $result);
5254             # ITER: {
5255             # foreach $prefix (@INC) {
5256             # $realfilename = "$prefix/$filename";
5257             # if (-f $realfilename) {
5258             # $result = CORE::eval `cat $realfilename`;
5259             # last ITER;
5260             # }
5261             # }
5262             # die "Can't find $filename in \@INC";
5263             # }
5264             # die $@ if $@;
5265             # die "$filename did not return true value" unless $result;
5266             # $INC{$filename} = $realfilename;
5267             # return $result;
5268             # }
5269              
5270             # require
5271             # in Chapter 9: perlfunc: Perl builtin functions
5272             # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
5273             #
5274             # sub require {
5275             # my($filename) = @_;
5276             # if (exists $INC{$filename}) {
5277             # return 1 if $INC{$filename};
5278             # die "Compilation failed in require";
5279             # }
5280             # my($realfilename, $result);
5281             # ITER: {
5282             # foreach $prefix (@INC) {
5283             # $realfilename = "$prefix/$filename";
5284             # if (-f $realfilename) {
5285             # $INC{$filename} = $realfilename;
5286             # $result = do $realfilename;
5287             # last ITER;
5288             # }
5289             # }
5290             # die "Can't find $filename in \@INC";
5291             # }
5292             # if ($@) {
5293             # $INC{$filename} = undef;
5294             # die $@;
5295             # }
5296             # elsif (!$result) {
5297             # delete $INC{$filename};
5298             # die "$filename did not return true value";
5299             # }
5300             # else {
5301             # return $result;
5302             # }
5303             # }
5304              
5305 0 0   0 0 0 sub Ekps9566::require(;$) {
5306              
5307 0 0       0 local $_ = shift if @_;
5308 0 0       0  
5309 0         0 if (exists $INC{$_}) {
5310             return 1 if $INC{$_};
5311             croak "Compilation failed in require: $_";
5312             }
5313              
5314             # jcode.pl
5315             # ftp://ftp.iij.ad.jp/pub/IIJ/dist/utashiro/perl/
5316              
5317             # jacode.pl
5318 0 0       0 # http://search.cpan.org/dist/jacode/
5319 0         0  
5320             if (/ \b (?: jcode\.pl | jacode(?>[0-9]*)\.pl ) \z /oxms) {
5321             return CORE::require($_);
5322 0         0 }
5323              
5324             my $realfilename;
5325             my $result;
5326 0         0 ITER_REQUIRE:
  0         0  
5327 0 0       0 {
5328 0         0 for my $prefix (@INC) {
5329             if ($^O eq 'MacOS') {
5330             $realfilename = "$prefix$_";
5331 0         0 }
5332             else {
5333             $realfilename = "$prefix/$_";
5334 0 0       0 }
5335 0         0  
5336             if (Ekps9566::f($realfilename)) {
5337 0         0 $INC{$_} = $realfilename;
5338              
5339 0 0       0 my $script = '';
5340 0         0  
5341 0         0 if (Ekps9566::e("$realfilename.e")) {
5342 0         0 my $e_mtime = (Ekps9566::stat("$realfilename.e"))[9];
5343 0 0 0     0 my $mtime = (Ekps9566::stat($realfilename))[9];
5344 0         0 my $module_mtime = (Ekps9566::stat(__FILE__))[9];
5345             if (($e_mtime < $mtime) or ($mtime < $module_mtime)) {
5346             Ekps9566::unlink "$realfilename.e";
5347             }
5348 0 0       0 }
5349 0         0  
5350 0 0       0 if (Ekps9566::e("$realfilename.e")) {
5351 0 0       0 my $fh = gensym();
    0          
5352 0         0 _open_r($fh, "$realfilename.e") or croak "Can't open file: $realfilename.e";
5353             if ($^O eq 'MacOS') {
5354             CORE::eval q{
5355             CORE::require Mac::Files;
5356             Mac::Files::FSpSetFLock("$realfilename.e");
5357             };
5358 0         0 }
5359 0 0       0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5360 0         0 CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5361             if ($@) {
5362             carp "Can't immediately read-lock the file: $realfilename.e";
5363             }
5364 0         0 }
5365             else {
5366 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5367 0         0 }
5368 0 0       0 local $/ = undef; # slurp mode
5369 0         0 $script = <$fh>;
5370             if ($^O eq 'MacOS') {
5371             CORE::eval q{
5372             CORE::require Mac::Files;
5373             Mac::Files::FSpRstFLock("$realfilename.e");
5374 0 0       0 };
5375             }
5376             close($fh) or croak "Can't close file: $realfilename: $!";
5377 0         0 }
5378 0 0       0 else {
5379 0 0       0 my $fh = gensym();
    0          
5380 0         0 _open_r($fh, $realfilename) or croak "Can't open file: $realfilename";
5381             if ($^O eq 'MacOS') {
5382             CORE::eval q{
5383             CORE::require Mac::Files;
5384             Mac::Files::FSpSetFLock($realfilename);
5385             };
5386 0         0 }
5387 0 0       0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5388 0         0 CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) };
5389             if ($@) {
5390             carp "Can't immediately read-lock the file: $realfilename";
5391             }
5392 0         0 }
5393             else {
5394 0         0 CORE::eval q{ flock($fh, LOCK_SH) };
5395 0         0 }
5396 0 0       0 local $/ = undef; # slurp mode
5397 0         0 $script = <$fh>;
5398             if ($^O eq 'MacOS') {
5399             CORE::eval q{
5400             CORE::require Mac::Files;
5401             Mac::Files::FSpRstFLock($realfilename);
5402 0 0       0 };
5403             }
5404 0 0       0 close($fh) or croak "Can't close file: $realfilename: $!";
5405 0         0  
5406 0         0 if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
5407 0         0 CORE::require KPS9566;
5408 0 0       0 $script = KPS9566::escape_script($script);
5409 0 0       0 my $fh = gensym();
    0          
5410 0         0 open($fh, ">$realfilename.e") or croak "Can't write open file: $realfilename.e";
5411             if ($^O eq 'MacOS') {
5412             CORE::eval q{
5413             CORE::require Mac::Files;
5414             Mac::Files::FSpSetFLock("$realfilename.e");
5415             };
5416 0         0 }
5417 0 0       0 elsif (exists $ENV{'CHAR_NONBLOCK'}) {
5418 0         0 CORE::eval q{ flock($fh, LOCK_EX | LOCK_NB) };
5419             if ($@) {
5420             carp "Can't immediately write-lock the file: $realfilename.e";
5421             }
5422 0         0 }
5423             else {
5424 0         0 CORE::eval q{ flock($fh, LOCK_EX) };
5425 0 0       0 }
5426 0         0 CORE::eval q{ truncate($fh, 0) };
  0         0  
5427 0 0       0 seek($fh, 0, 0) or croak "Can't seek file: $realfilename.e";
5428 0         0 print {$fh} $script;
5429             if ($^O eq 'MacOS') {
5430             CORE::eval q{
5431             CORE::require Mac::Files;
5432             Mac::Files::FSpRstFLock("$realfilename.e");
5433 0 0       0 };
5434             }
5435             close($fh) or croak "Can't close file: $realfilename: $!";
5436             }
5437             }
5438 389     389   2911  
  389         852  
  389         386861  
  0         0  
5439 0         0 {
5440             no strict;
5441 0         0 $result = scalar CORE::eval $script;
5442             }
5443             last ITER_REQUIRE;
5444 0         0 }
5445             }
5446             croak "Can't find $_ in \@INC";
5447 0 0       0 }
    0          
5448 0         0  
5449 0         0 if ($@) {
5450             $INC{$_} = undef;
5451             croak $@;
5452 0         0 }
5453 0         0 elsif (not $result) {
5454             delete $INC{$_};
5455             croak "$_ did not return true value";
5456 0         0 }
5457             else {
5458             return $result;
5459             }
5460             }
5461              
5462             #
5463             # KPS9566 telldir avoid warning
5464             #
5465 0     768 0 0 sub Ekps9566::telldir(*) {
5466              
5467 768         2136 local $^W = 0;
5468              
5469             return CORE::telldir $_[0];
5470             }
5471              
5472             #
5473             # ${^PREMATCH}, $PREMATCH, $` the string preceding what was matched
5474 768 0   0 0 11121 #
5475 0 0 0     0 sub Ekps9566::PREMATCH {
5476 0         0 if (defined($&)) {
5477             if (defined($1) and (CORE::substr($&,-CORE::length($1),CORE::length($1)) eq $1)) {
5478             return CORE::substr($&,0,CORE::length($&)-CORE::length($1));
5479 0         0 }
5480             else {
5481             croak 'Use of "$`", $PREMATCH, and ${^PREMATCH} need to /( capture all )/ in regexp';
5482             }
5483 0         0 }
5484             else {
5485 0         0 return '';
5486             }
5487             return $`;
5488             }
5489              
5490             #
5491             # ${^MATCH}, $MATCH, $& the string that matched
5492 0 0   0 0 0 #
5493 0 0       0 sub Ekps9566::MATCH {
5494 0         0 if (defined($&)) {
5495             if (defined($1)) {
5496             return $1;
5497 0         0 }
5498             else {
5499             croak 'Use of "$&", $MATCH, and ${^MATCH} need to /( capture all )/ in regexp';
5500             }
5501 0         0 }
5502             else {
5503 0         0 return '';
5504             }
5505             return $&;
5506             }
5507              
5508             #
5509             # ${^POSTMATCH}, $POSTMATCH, $' the string following what was matched
5510 0     0 0 0 #
5511             sub Ekps9566::POSTMATCH {
5512             return $';
5513             }
5514              
5515             #
5516             # KPS9566 character to order (with parameter)
5517             #
5518 0 0   0 1 0 sub KPS9566::ord(;$) {
5519              
5520 0 0       0 local $_ = shift if @_;
5521 0         0  
5522 0         0 if (/\A ($q_char) /oxms) {
5523 0         0 my @ord = unpack 'C*', $1;
5524 0         0 my $ord = 0;
5525             while (my $o = shift @ord) {
5526 0         0 $ord = $ord * 0x100 + $o;
5527             }
5528             return $ord;
5529 0         0 }
5530             else {
5531             return CORE::ord $_;
5532             }
5533             }
5534              
5535             #
5536             # KPS9566 character to order (without parameter)
5537             #
5538 0 0   0 0 0 sub KPS9566::ord_() {
5539 0         0  
5540 0         0 if (/\A ($q_char) /oxms) {
5541 0         0 my @ord = unpack 'C*', $1;
5542 0         0 my $ord = 0;
5543             while (my $o = shift @ord) {
5544 0         0 $ord = $ord * 0x100 + $o;
5545             }
5546             return $ord;
5547 0         0 }
5548             else {
5549             return CORE::ord $_;
5550             }
5551             }
5552              
5553             #
5554             # KPS9566 reverse
5555             #
5556 0 0   0 0 0 sub KPS9566::reverse(@) {
5557 0         0  
5558             if (wantarray) {
5559             return CORE::reverse @_;
5560             }
5561             else {
5562              
5563             # One of us once cornered Larry in an elevator and asked him what
5564             # problem he was solving with this, but he looked as far off into
5565             # the distance as he could in an elevator and said, "It seemed like
5566 0         0 # a good idea at the time."
5567              
5568             return join '', CORE::reverse(join('',@_) =~ /\G ($q_char) /oxmsg);
5569             }
5570             }
5571              
5572             #
5573             # KPS9566 getc (with parameter, without parameter)
5574             #
5575 0     0 0 0 sub KPS9566::getc(;*@) {
5576 0 0       0  
5577 0 0 0     0 my($package) = caller;
5578             my $fh = @_ ? qualify_to_ref(shift,$package) : \*STDIN;
5579 0         0 croak 'Too many arguments for KPS9566::getc' if @_ and not wantarray;
  0         0  
5580 0         0  
5581 0         0 my @length = sort { $a <=> $b } keys %range_tr;
5582 0         0 my $getc = '';
5583 0 0       0 for my $length ($length[0] .. $length[-1]) {
5584 0 0       0 $getc .= CORE::getc($fh);
5585 0 0       0 if (exists $range_tr{CORE::length($getc)}) {
5586             if ($getc =~ /\A ${Ekps9566::dot_s} \z/oxms) {
5587             return wantarray ? ($getc,@_) : $getc;
5588             }
5589 0 0       0 }
5590             }
5591             return wantarray ? ($getc,@_) : $getc;
5592             }
5593              
5594             #
5595             # KPS9566 length by character
5596             #
5597 0 0   0 1 0 sub KPS9566::length(;$) {
5598              
5599 0         0 local $_ = shift if @_;
5600 0         0  
5601             local @_ = /\G ($q_char) /oxmsg;
5602             return scalar @_;
5603             }
5604              
5605             #
5606             # KPS9566 substr by character
5607             #
5608             BEGIN {
5609              
5610             # P.232 The lvalue Attribute
5611             # in Chapter 6: Subroutines
5612             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
5613              
5614             # P.336 The lvalue Attribute
5615             # in Chapter 7: Subroutines
5616             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5617              
5618             # P.144 8.4 Lvalue subroutines
5619             # in Chapter 8: perlsub: Perl subroutines
5620 389 50 0 389 1 262212 # of ISBN-13: 978-1-906966-02-7 The Perl Language Reference Manual (for Perl version 5.12.1)
  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  
5621              
5622             CORE::eval sprintf(<<'END', ($] >= 5.014000) ? ':lvalue' : '');
5623             # vv----------------------*******
5624             sub KPS9566::substr($$;$$) %s {
5625              
5626             my @char = $_[0] =~ /\G (?>$q_char) /oxmsg;
5627              
5628             # If the substring is beyond either end of the string, substr() returns the undefined
5629             # value and produces a warning. When used as an lvalue, specifying a substring that
5630             # is entirely outside the string raises an exception.
5631             # http://perldoc.perl.org/functions/substr.html
5632              
5633             # A return with no argument returns the scalar value undef in scalar context,
5634             # an empty list () in list context, and (naturally) nothing at all in void
5635             # context.
5636              
5637             my $offset = $_[1];
5638             if (($offset > scalar(@char)) or ($offset < (-1 * scalar(@char)))) {
5639             return;
5640             }
5641              
5642             # substr($string,$offset,$length,$replacement)
5643             if (@_ == 4) {
5644             my(undef,undef,$length,$replacement) = @_;
5645             my $substr = join '', splice(@char, $offset, $length, $replacement);
5646             $_[0] = join '', @char;
5647              
5648             # return $substr; this doesn't work, don't say "return"
5649             $substr;
5650             }
5651              
5652             # substr($string,$offset,$length)
5653             elsif (@_ == 3) {
5654             my(undef,undef,$length) = @_;
5655             my $octet_offset = 0;
5656             my $octet_length = 0;
5657             if ($offset == 0) {
5658             $octet_offset = 0;
5659             }
5660             elsif ($offset > 0) {
5661             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
5662             $octet_offset = CORE::length(join '', @char[0..$offset-1]);
5663             }
5664             else {
5665             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
5666             $octet_offset = -1 * CORE::length(join '', @char[$#char+$offset+1..$#char]);
5667             }
5668             if ($length == 0) {
5669             $octet_length = 0;
5670             }
5671             elsif ($length > 0) {
5672             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
5673             $octet_length = CORE::length(join '', @char[$offset..$offset+$length-1]);
5674             }
5675             else {
5676             local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
5677             $octet_length = -1 * CORE::length(join '', @char[$#char+$length+1..$#char]);
5678             }
5679             CORE::substr($_[0], $octet_offset, $octet_length);
5680             }
5681              
5682             # substr($string,$offset)
5683             else {
5684             my $octet_offset = 0;
5685             if ($offset == 0) {
5686             $octet_offset = 0;
5687             }
5688             elsif ($offset > 0) {
5689             $octet_offset = CORE::length(join '', @char[0..$offset-1]);
5690             }
5691             else {
5692             $octet_offset = -1 * CORE::length(join '', @char[$#char+$offset+1..$#char]);
5693             }
5694             CORE::substr($_[0], $octet_offset);
5695             }
5696             }
5697             END
5698             }
5699              
5700             #
5701             # KPS9566 index by character
5702             #
5703 0     0 1 0 sub KPS9566::index($$;$) {
5704 0 0       0  
5705 0         0 my $index;
5706             if (@_ == 3) {
5707             $index = Ekps9566::index($_[0], $_[1], CORE::length(KPS9566::substr($_[0], 0, $_[2])));
5708 0         0 }
5709             else {
5710             $index = Ekps9566::index($_[0], $_[1]);
5711 0 0       0 }
5712 0         0  
5713             if ($index == -1) {
5714             return -1;
5715 0         0 }
5716             else {
5717             return KPS9566::length(CORE::substr $_[0], 0, $index);
5718             }
5719             }
5720              
5721             #
5722             # KPS9566 rindex by character
5723             #
5724 0     0 1 0 sub KPS9566::rindex($$;$) {
5725 0 0       0  
5726 0         0 my $rindex;
5727             if (@_ == 3) {
5728             $rindex = Ekps9566::rindex($_[0], $_[1], CORE::length(KPS9566::substr($_[0], 0, $_[2])));
5729 0         0 }
5730             else {
5731             $rindex = Ekps9566::rindex($_[0], $_[1]);
5732 0 0       0 }
5733 0         0  
5734             if ($rindex == -1) {
5735             return -1;
5736 0         0 }
5737             else {
5738             return KPS9566::length(CORE::substr $_[0], 0, $rindex);
5739             }
5740             }
5741              
5742 389     389   4541 # when 'm//', '/' means regexp match 'm//' and '?' means regexp match '??'
  389         3191  
  389         41104  
5743             # when 'div', '/' means division operator and '?' means conditional operator (condition ? then : else)
5744             use vars qw($slash); $slash = 'm//';
5745              
5746             # ord() to ord() or KPS9566::ord()
5747             my $function_ord = 'ord';
5748              
5749             # ord to ord or KPS9566::ord_
5750             my $function_ord_ = 'ord';
5751              
5752             # reverse to reverse or KPS9566::reverse
5753             my $function_reverse = 'reverse';
5754              
5755             # getc to getc or KPS9566::getc
5756             my $function_getc = 'getc';
5757              
5758             # P.1023 Appendix W.9 Multibyte Anchoring
5759             # of ISBN 1-56592-224-7 CJKV Information Processing
5760              
5761             my $anchor = '';
5762 389     389   2560 $anchor = q{${Ekps9566::anchor}};
  389     0   3798  
  389         17431769  
5763              
5764             use vars qw($nest);
5765              
5766             # regexp of nested parens in qqXX
5767              
5768             # P.340 Matching Nested Constructs with Embedded Code
5769             # in Chapter 7: Perl
5770             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
5771              
5772             my $qq_paren = qr{(?{local $nest=0}) (?>(?:
5773             [^\x81-\xFE\\()] |
5774             \( (?{$nest++}) |
5775             \) (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5776             [\x81-\xFE][\x00-\xFF] |
5777             \\ [^\x81-\xFEc] |
5778             \\c[\x40-\x5F] |
5779             \\ [\x81-\xFE][\x00-\xFF] |
5780             [\x00-\xFF]
5781             }xms;
5782              
5783             my $qq_brace = qr{(?{local $nest=0}) (?>(?:
5784             [^\x81-\xFE\\{}] |
5785             \{ (?{$nest++}) |
5786             \} (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5787             [\x81-\xFE][\x00-\xFF] |
5788             \\ [^\x81-\xFEc] |
5789             \\c[\x40-\x5F] |
5790             \\ [\x81-\xFE][\x00-\xFF] |
5791             [\x00-\xFF]
5792             }xms;
5793              
5794             my $qq_bracket = qr{(?{local $nest=0}) (?>(?:
5795             [^\x81-\xFE\\\[\]] |
5796             \[ (?{$nest++}) |
5797             \] (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5798             [\x81-\xFE][\x00-\xFF] |
5799             \\ [^\x81-\xFEc] |
5800             \\c[\x40-\x5F] |
5801             \\ [\x81-\xFE][\x00-\xFF] |
5802             [\x00-\xFF]
5803             }xms;
5804              
5805             my $qq_angle = qr{(?{local $nest=0}) (?>(?:
5806             [^\x81-\xFE\\<>] |
5807             \< (?{$nest++}) |
5808             \> (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5809             [\x81-\xFE][\x00-\xFF] |
5810             \\ [^\x81-\xFEc] |
5811             \\c[\x40-\x5F] |
5812             \\ [\x81-\xFE][\x00-\xFF] |
5813             [\x00-\xFF]
5814             }xms;
5815              
5816             my $qq_scalar = qr{(?: \{ (?:$qq_brace)*? \} |
5817             (?: ::)? (?:
5818             (?> [a-zA-Z_][a-zA-Z_0-9]* (?: ::[a-zA-Z_][a-zA-Z_0-9]*)* )
5819             (?>(?: \[ (?: \$\[ | \$\] | $qq_char )*? \] | \{ (?:$qq_brace)*? \} )*)
5820             (?>(?: (?: -> )? (?: [\$\@\%\&\*]\* | \$\#\* | [\@\%]? \[ (?: \$\[ | \$\] | $qq_char )*? \] | [\@\%\*]? \{ (?:$qq_brace)*? \} ) )*)
5821             ))
5822             }xms;
5823              
5824             my $qq_variable = qr{(?: \{ (?:$qq_brace)*? \} |
5825             (?: ::)? (?:
5826             (?>[0-9]+) |
5827             [^\x81-\xFEa-zA-Z_0-9\[\]] |
5828             ^[A-Z] |
5829             (?> [a-zA-Z_][a-zA-Z_0-9]* (?: ::[a-zA-Z_][a-zA-Z_0-9]*)* )
5830             (?>(?: \[ (?: \$\[ | \$\] | $qq_char )*? \] | \{ (?:$qq_brace)*? \} )*)
5831             (?>(?: (?: -> )? (?: [\$\@\%\&\*]\* | \$\#\* | [\@\%]? \[ (?: \$\[ | \$\] | $qq_char )*? \] | [\@\%\*]? \{ (?:$qq_brace)*? \} ) )*)
5832             ))
5833             }xms;
5834              
5835             my $qq_substr = qr{(?> Char::substr | KPS9566::substr | CORE::substr | substr ) (?>\s*) \( $qq_paren \)
5836             }xms;
5837              
5838             # regexp of nested parens in qXX
5839             my $q_paren = qr{(?{local $nest=0}) (?>(?:
5840             [^\x81-\xFE()] |
5841             [\x81-\xFE][\x00-\xFF] |
5842             \( (?{$nest++}) |
5843             \) (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5844             [\x00-\xFF]
5845             }xms;
5846              
5847             my $q_brace = qr{(?{local $nest=0}) (?>(?:
5848             [^\x81-\xFE\{\}] |
5849             [\x81-\xFE][\x00-\xFF] |
5850             \{ (?{$nest++}) |
5851             \} (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5852             [\x00-\xFF]
5853             }xms;
5854              
5855             my $q_bracket = qr{(?{local $nest=0}) (?>(?:
5856             [^\x81-\xFE\[\]] |
5857             [\x81-\xFE][\x00-\xFF] |
5858             \[ (?{$nest++}) |
5859             \] (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5860             [\x00-\xFF]
5861             }xms;
5862              
5863             my $q_angle = qr{(?{local $nest=0}) (?>(?:
5864             [^\x81-\xFE<>] |
5865             [\x81-\xFE][\x00-\xFF] |
5866             \< (?{$nest++}) |
5867             \> (?(?{$nest>0})(?{$nest--})|(?!)))*) (?(?{$nest!=0})(?!)) |
5868             [\x00-\xFF]
5869             }xms;
5870              
5871             my $matched = '';
5872             my $s_matched = '';
5873             $matched = q{$Ekps9566::matched};
5874             $s_matched = q{ Ekps9566::s_matched();};
5875              
5876             my $tr_variable = ''; # variable of tr///
5877             my $sub_variable = ''; # variable of s///
5878             my $bind_operator = ''; # =~ or !~
5879              
5880             my @heredoc = (); # here document
5881             my @heredoc_delimiter = ();
5882             my $here_script = ''; # here script
5883              
5884             #
5885             # escape KPS9566 script
5886 0 50   384 0 0 #
5887             sub KPS9566::escape(;$) {
5888             local($_) = $_[0] if @_;
5889              
5890             # P.359 The Study Function
5891             # in Chapter 7: Perl
5892 384         1299 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
5893              
5894             study $_; # Yes, I studied study yesterday.
5895              
5896             # while all script
5897              
5898             # 6.14. Matching from Where the Last Pattern Left Off
5899             # in Chapter 6. Pattern Matching
5900             # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition.
5901             # (and so on)
5902              
5903             # one member of Tag-team
5904             #
5905             # P.128 Start of match (or end of previous match): \G
5906             # P.130 Advanced Use of \G with Perl
5907             # in Chapter 3: Overview of Regular Expression Features and Flavors
5908             # P.255 Use leading anchors
5909             # P.256 Expose ^ and \G at the front expressions
5910             # in Chapter 6: Crafting an Efficient Expression
5911             # P.315 "Tag-team" matching with /gc
5912             # in Chapter 7: Perl
5913 384         847 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
5914 384         700  
5915 384         1540 my $e_script = '';
5916             while (not /\G \z/oxgc) { # member
5917             $e_script .= KPS9566::escape_token();
5918 186419         288326 }
5919              
5920             return $e_script;
5921             }
5922              
5923             #
5924             # escape KPS9566 token of script
5925             #
5926             sub KPS9566::escape_token {
5927              
5928 384     186419 0 6308 # \n output here document
5929              
5930             my $ignore_modules = join('|', qw(
5931             utf8
5932             bytes
5933             charnames
5934             I18N::Japanese
5935             I18N::Collate
5936             I18N::JExt
5937             File::DosGlob
5938             Wild
5939             Wildcard
5940             Japanese
5941             ));
5942              
5943             # another member of Tag-team
5944             #
5945             # P.315 "Tag-team" matching with /gc
5946             # in Chapter 7: Perl
5947 186419 100 100     217572 # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
    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          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    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          
5948 186419         13979195  
5949 31271 100       38879 if (/\G ( \n ) /oxgc) { # another member (and so on)
5950 31271         54177 my $heredoc = '';
5951             if (scalar(@heredoc_delimiter) >= 1) {
5952 197         284 $slash = 'm//';
5953 197         396  
5954             $heredoc = join '', @heredoc;
5955             @heredoc = ();
5956 197         344  
5957 197         365 # skip here document
5958             for my $heredoc_delimiter (@heredoc_delimiter) {
5959 205         1313 /\G .*? \n $heredoc_delimiter \n/xmsgc;
5960             }
5961 197         372 @heredoc_delimiter = ();
5962              
5963 197         274 $here_script = '';
5964             }
5965             return "\n" . $heredoc;
5966             }
5967 31271         90526  
5968             # ignore space, comment
5969             elsif (/\G ((?>\s+)|\#.*) /oxgc) { return $1; }
5970              
5971             # if (, elsif (, unless (, while (, until (, given (, and when (
5972              
5973             # given, when
5974              
5975             # P.225 The given Statement
5976             # in Chapter 15: Smart Matching and given-when
5977             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
5978              
5979             # P.133 The given Statement
5980             # in Chapter 4: Statements and Declarations
5981             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
5982 42525         127217  
5983 3755         5706 elsif (/\G ( (?: if | elsif | unless | while | until | given | when ) (?>\s*) \( ) /oxgc) {
5984             $slash = 'm//';
5985             return $1;
5986             }
5987              
5988             # scalar variable ($scalar = ...) =~ tr///;
5989             # scalar variable ($scalar = ...) =~ s///;
5990              
5991             # state
5992              
5993             # P.68 Persistent, Private Variables
5994             # in Chapter 4: Subroutines
5995             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
5996              
5997             # P.160 Persistent Lexically Scoped Variables: state
5998             # in Chapter 4: Statements and Declarations
5999             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6000              
6001             # (and so on)
6002 3755         11462  
6003             elsif (/\G ( \( (?>\s*) (?: local \b | my \b | our \b | state \b )? (?>\s*) \$ $qq_scalar ) /oxgc) {
6004 170 50       467 my $e_string = e_string($1);
    50          
6005 170         6055  
6006 0         0 if (/\G ( (?>\s*) = $qq_paren \) ) ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= (?: tr | y ) \b ) /oxgc) {
6007 0         0 $tr_variable = $e_string . e_string($1);
6008 0         0 $bind_operator = $2;
6009             $slash = 'm//';
6010             return '';
6011 0         0 }
6012 0         0 elsif (/\G ( (?>\s*) = $qq_paren \) ) ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= s \b ) /oxgc) {
6013 0         0 $sub_variable = $e_string . e_string($1);
6014 0         0 $bind_operator = $2;
6015             $slash = 'm//';
6016             return '';
6017 0         0 }
6018 170         367 else {
6019             $slash = 'div';
6020             return $e_string;
6021             }
6022             }
6023              
6024 170         844 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ekps9566::PREMATCH()
6025 4         10 elsif (/\G ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH \b | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) /oxmsgc) {
6026             $slash = 'div';
6027             return q{Ekps9566::PREMATCH()};
6028             }
6029              
6030 4         12 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ekps9566::MATCH()
6031 28         57 elsif (/\G ( \$& | \$\{&\} | \$ (?>\s*) MATCH \b | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) /oxmsgc) {
6032             $slash = 'div';
6033             return q{Ekps9566::MATCH()};
6034             }
6035              
6036 28         81 # $', ${'} --> $', ${'}
6037 1         3 elsif (/\G ( \$' | \$\{'\} ) /oxmsgc) {
6038             $slash = 'div';
6039             return $1;
6040             }
6041              
6042 1         3 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ekps9566::POSTMATCH()
6043 3         6 elsif (/\G ( \$ (?>\s*) POSTMATCH \b | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) /oxmsgc) {
6044             $slash = 'div';
6045             return q{Ekps9566::POSTMATCH()};
6046             }
6047              
6048             # scalar variable $scalar =~ tr///;
6049             # scalar variable $scalar =~ s///;
6050             # substr() =~ tr///;
6051 3         11 # substr() =~ s///;
6052             elsif (/\G ( \$ $qq_scalar | $qq_substr ) /oxgc) {
6053 2877 100       6635 my $scalar = e_string($1);
    100          
6054 2877         11001  
6055 9         16 if (/\G ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= (?: tr | y ) \b ) /oxgc) {
6056 9         16 $tr_variable = $scalar;
6057 9         19 $bind_operator = $1;
6058             $slash = 'm//';
6059             return '';
6060 9         25 }
6061 253         422 elsif (/\G ( (?>\s*) (?: =~ | !~ ) (?>\s*) ) (?= s \b ) /oxgc) {
6062 253         455 $sub_variable = $scalar;
6063 253         352 $bind_operator = $1;
6064             $slash = 'm//';
6065             return '';
6066 253         695 }
6067 2615         3726 else {
6068             $slash = 'div';
6069             return $scalar;
6070             }
6071             }
6072              
6073 2615         6940 # end of statement
6074             elsif (/\G ( [,;] ) /oxgc) {
6075             $slash = 'm//';
6076 12175         18287  
6077             # clear tr/// variable
6078             $tr_variable = '';
6079 12175         14267  
6080             # clear s/// variable
6081 12175         13681 $sub_variable = '';
6082              
6083 12175         13591 $bind_operator = '';
6084              
6085             return $1;
6086             }
6087              
6088 12175         40848 # bareword
6089             elsif (/\G ( \{ (?>\s*) (?: tr | index | rindex | reverse ) (?>\s*) \} ) /oxmsgc) {
6090             return $1;
6091             }
6092              
6093 0         0 # $0 --> $0
6094 2         5 elsif (/\G ( \$ 0 ) /oxmsgc) {
6095             $slash = 'div';
6096             return $1;
6097 2         9 }
6098 0         0 elsif (/\G ( \$ \{ (?>\s*) 0 (?>\s*) \} ) /oxmsgc) {
6099             $slash = 'div';
6100             return $1;
6101             }
6102              
6103 0         0 # $$ --> $$
6104 1         3 elsif (/\G ( \$ \$ ) (?![\w\{]) /oxmsgc) {
6105             $slash = 'div';
6106             return $1;
6107             }
6108              
6109             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
6110 1         4 # $1, $2, $3 --> $1, $2, $3 otherwise
6111 219         422 elsif (/\G \$ ((?>[1-9][0-9]*)) /oxmsgc) {
6112             $slash = 'div';
6113             return e_capture($1);
6114 219         572 }
6115 0         0 elsif (/\G \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} /oxmsgc) {
6116             $slash = 'div';
6117             return e_capture($1);
6118             }
6119              
6120 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
6121 0         0 elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ .+? \] ) /oxmsgc) {
6122             $slash = 'div';
6123             return e_capture($1.'->'.$2);
6124             }
6125              
6126 0         0 # $$foo{ ... } --> $ $foo->{ ... }
6127 0         0 elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ .+? \} ) /oxmsgc) {
6128             $slash = 'div';
6129             return e_capture($1.'->'.$2);
6130             }
6131              
6132 0         0 # $$foo
6133 0         0 elsif (/\G \$ ( \$ (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) /oxmsgc) {
6134             $slash = 'div';
6135             return e_capture($1);
6136             }
6137              
6138 0         0 # ${ foo }
6139 0         0 elsif (/\G \$ (?>\s*) \{ ( (?>\s*) (?> [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* ) (?>\s*) ) \} /oxmsgc) {
6140             $slash = 'div';
6141             return '${' . $1 . '}';
6142             }
6143              
6144 0         0 # ${ ... }
6145 0         0 elsif (/\G \$ (?>\s*) \{ (?>\s*) ( $qq_brace ) (?>\s*) \} /oxmsgc) {
6146             $slash = 'div';
6147             return e_capture($1);
6148             }
6149              
6150             # variable or function
6151 0         0 # $ @ % & * $ #
6152 605         1056 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) {
6153             $slash = 'div';
6154             return $1;
6155             }
6156             # $ $ $ $ $ $ $ $ $ $ $ $ $ $
6157 605         2046 # $ @ # \ ' " / ? ( ) [ ] < >
6158 103         201 elsif (/\G ( \$[\$\@\#\\\'\"\/\?\(\)\[\]\<\>] ) /oxmsgc) {
6159             $slash = 'div';
6160             return $1;
6161             }
6162              
6163 103         377 # while ()
6164             elsif (/\G \b (while (?>\s*) \( (?>\s*) <[\$]?[A-Za-z_][A-Za-z_0-9]*> (?>\s*) \)) \b /oxgc) {
6165             return $1;
6166             }
6167              
6168             # while () --- glob
6169              
6170             # avoid "Error: Runtime exception" of perl version 5.005_03
6171 0         0  
6172             elsif (/\G \b while (?>\s*) \( (?>\s*) < ((?:[^\x81-\xFE>\0\a\e\f\n\r\t]|[\x81-\xFE][\x00-\xFF])+?) > (?>\s*) \) \b /oxgc) {
6173             return 'while ($_ = Ekps9566::glob("' . $1 . '"))';
6174             }
6175              
6176 0         0 # while (glob)
6177             elsif (/\G \b while (?>\s*) \( (?>\s*) glob (?>\s*) \) /oxgc) {
6178             return 'while ($_ = Ekps9566::glob_)';
6179             }
6180              
6181 0         0 # while (glob(WILDCARD))
6182             elsif (/\G \b while (?>\s*) \( (?>\s*) glob \b /oxgc) {
6183             return 'while ($_ = Ekps9566::glob';
6184             }
6185 0         0  
  478         1151  
6186             # doit if, doit unless, doit while, doit until, doit for, doit when
6187             elsif (/\G \b ( if | unless | while | until | for | when ) \b /oxgc) { $slash = 'm//'; return $1; }
6188 478         1967  
  19         40  
6189 19         66 # subroutines of package Ekps9566
  0         0  
6190 0         0 elsif (/\G \b (CORE:: | ->(>?\s*) (?: atan2 | [a-z]{2,})) \b /oxgc) { $slash = 'm//'; return $1; }
  13         24  
6191 13         35 elsif (/\G \b Char::eval (?= (?>\s*) \{ ) /oxgc) { $slash = 'm//'; return 'eval'; }
  0         0  
6192 0         0 elsif (/\G \b KPS9566::eval (?= (?>\s*) \{ ) /oxgc) { $slash = 'm//'; return 'eval'; }
  114         224  
6193 114         391 elsif (/\G \b Char::eval \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'eval Char::escape'; }
  2         4  
6194 2         6 elsif (/\G \b KPS9566::eval \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'eval KPS9566::escape'; }
  2         5  
6195 2         6 elsif (/\G \b bytes::substr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'substr'; }
  2         16  
6196 2         7 elsif (/\G \b chop \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::chop'; }
  0         0  
6197 0         0 elsif (/\G \b bytes::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'index'; }
  2         4  
6198 2         7 elsif (/\G \b Char::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Char::index'; }
  2         4  
6199 2         5 elsif (/\G \b KPS9566::index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'KPS9566::index'; }
  2         6  
6200 2         5 elsif (/\G \b index \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::index'; }
  0         0  
6201 0         0 elsif (/\G \b bytes::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'rindex'; }
  2         5  
6202 2         7 elsif (/\G \b Char::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Char::rindex'; }
  2         3  
6203 2         6 elsif (/\G \b KPS9566::rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'KPS9566::rindex'; }
  1         2  
6204 1         4 elsif (/\G \b rindex \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::rindex'; }
  0         0  
6205 0         0 elsif (/\G \b lc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::lc'; }
  0         0  
6206 0         0 elsif (/\G \b lcfirst (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::lcfirst'; }
  0         0  
6207 0         0 elsif (/\G \b uc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::uc'; }
  3         5  
6208             elsif (/\G \b ucfirst (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::ucfirst'; }
6209             elsif (/\G \b fc (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::fc'; }
6210              
6211             # stacked file test operators
6212              
6213             # P.179 File Test Operators
6214             # in Chapter 12: File Tests
6215             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
6216              
6217             # P.106 Named Unary and File Test Operators
6218             # in Chapter 3: Unary and Binary Operators
6219             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
6220              
6221             # (and so on)
6222 3         22  
  0         0  
6223 0         0 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
6224 0         0 (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_qq('', $2,$4,$3) . ")"; }
  0         0  
6225 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6226 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6227 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6228 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6229             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
6230             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\S) ((?:$qq_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; }
6231 0         0  
  4         8  
6232 4         12 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
6233 0         0 (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_q ('', $2,$4,$3) . ")"; }
  0         0  
6234 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6235 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6236 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6237 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6238             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
6239             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\S) ((?:\\\2|\\\\|$q_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; }
6240 0         0  
  0         0  
6241 0         0 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) (\$ (?> \w+ (?: ::\w+)* ) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
6242 0         0 { $slash = 'm//'; return "Ekps9566::filetest(qw($1),$2)"; }
  0         0  
6243 0         0 elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) \( ((?:$qq_paren)*?) \) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1),$2)"; }
  0         0  
6244             elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) (?= [a-z]+) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest qw($1),"; }
6245 0         0 elsif (/\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) ((?>\w+)) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest(qw($1),$2)"; }
  0         0  
6246 0         0  
  0         0  
6247 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_qq('', $2,$4,$3) . ")"; }
  0         0  
6248 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6249 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6250 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6251 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  0         0  
6252             elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
6253 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) qq (?>\s*) (\S) ((?:$qq_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_qq('qq',$2,$4,$3) . ")"; }
  102         187  
6254 102         295  
  0         0  
6255 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_q ('', $2,$4,$3) . ")"; }
  0         0  
6256 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6257 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6258 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6259 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_q ('q', $2,$4,$3) . ")"; }
  0         0  
6260             elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_q ('q', $2,$4,$3) . ")"; }
6261             elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) q (?>\s*) (\S) ((?:\\\2|\\\\|$q_char)+?) (\2) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(" . e_q ('q', $2,$4,$3) . ")"; }
6262 0         0  
  6         16  
6263 6         30 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) (\$ (?> \w+ (?: ::\w+)* ) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
6264 0         0 { $slash = 'm//'; return "Ekps9566::$1($2)"; }
  0         0  
6265 0         0 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s*) \( ((?:$qq_paren)*?) \) /oxgc) { $slash = 'm//'; return "Ekps9566::$1($2)"; }
  50         89  
6266 50         235 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?= (?>\s+) [a-z]+) /oxgc) { $slash = 'm//'; return "Ekps9566::$1"; }
  2         6  
6267 2         10 elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC]) (?>\s+) ((?>\w+)) /oxgc) { $slash = 'm//'; return "Ekps9566::$1(::"."$2)"; }
  1         3  
6268 1         4 elsif (/\G -(t) (?>\s+) ((?>\w+)) /oxgc) { $slash = 'm//'; return "-t $2"; }
  3         8  
6269             elsif (/\G \b lstat (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::lstat'; }
6270             elsif (/\G \b stat (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::stat'; }
6271 3         11  
  0         0  
6272 0         0 # "-s '' ..." means file test "-s 'filename' ..." (not means "- s/// ...")
  0         0  
6273 0         0 elsif (/\G -s (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $slash = 'm//'; return '-s ' . e_qq('', $1,$3,$2); }
  0         0  
6274 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6275 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6276 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6277 0         0 elsif (/\G -s (?>\s+) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
  0         0  
6278             elsif (/\G -s (?>\s+) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $slash = 'm//'; return '-s ' . e_qq('qq',$1,$3,$2); }
6279 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  
6280 0         0  
  0         0  
6281 0         0 elsif (/\G -s (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $slash = 'm//'; return '-s ' . e_q ('', $1,$3,$2); }
  0         0  
6282 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6283 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6284 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6285 0         0 elsif (/\G -s (?>\s+) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
  0         0  
6286             elsif (/\G -s (?>\s+) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
6287             elsif (/\G -s (?>\s+) q (?>\s*) (\S) ((?:\\\1|\\\\|$q_char)+?) (\1) /oxgc) { $slash = 'm//'; return '-s ' . e_q ('q', $1,$3,$2); }
6288 0         0  
  0         0  
6289 0         0 elsif (/\G -s (?>\s*) (\$ (?> \w+ (?: ::\w+)* ) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
6290 0         0 { $slash = 'm//'; return "-s $1"; }
  0         0  
6291 0         0 elsif (/\G -s (?>\s*) \( ((?:$qq_paren)*?) \) /oxgc) { $slash = 'm//'; return "-s ($1)"; }
  0         0  
6292             elsif (/\G -s (?= (?>\s+) [a-z]+) /oxgc) { $slash = 'm//'; return '-s'; }
6293 0         0 elsif (/\G -s (?>\s+) ((?>\w+)) /oxgc) { $slash = 'm//'; return "-s $1"; }
  2         5  
6294 2         7  
  2         5  
6295 2         7 elsif (/\G \b bytes::length (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'length'; }
  36         106  
6296 36         129 elsif (/\G \b bytes::chr (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'chr'; }
  2         4  
6297 2         8 elsif (/\G \b chr (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::chr'; }
  2         9  
6298 2         10 elsif (/\G \b bytes::ord (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'div'; return 'ord'; }
  8         24  
6299 8         35 elsif (/\G \b ord (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'div'; return $function_ord; }
  0         0  
6300 0         0 elsif (/\G \b glob (?= (?>\s+)[A-Za-z_]|(?>\s*)['"`\$\@\&\*\(]) /oxgc) { $slash = 'm//'; return 'Ekps9566::glob'; }
  0         0  
6301 0         0 elsif (/\G \b lc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::lc_'; }
  0         0  
6302 0         0 elsif (/\G \b lcfirst \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::lcfirst_'; }
  0         0  
6303 0         0 elsif (/\G \b uc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::uc_'; }
  0         0  
6304 0         0 elsif (/\G \b ucfirst \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::ucfirst_'; }
  0         0  
6305 0         0 elsif (/\G \b fc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::fc_'; }
  0         0  
6306             elsif (/\G \b lstat \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::lstat_'; }
6307 0         0 elsif (/\G \b stat \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::stat_'; }
  0         0  
6308             elsif (/\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
6309 0         0 \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return "Ekps9566::filetest_(qw($1))"; }
  0         0  
6310             elsif (/\G -([rwxoRWXOezsfdlpSbcugkTBMAC])
6311 0         0 \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return "Ekps9566::${1}_"; }
  0         0  
6312              
6313 0         0 elsif (/\G -s \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return '-s '; }
  0         0  
6314 0         0  
  0         0  
6315 0         0 elsif (/\G \b bytes::length \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'length'; }
  0         0  
6316 0         0 elsif (/\G \b bytes::chr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'chr'; }
  0         0  
6317 0         0 elsif (/\G \b chr \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::chr_'; }
  2         7  
6318 2         9 elsif (/\G \b bytes::ord \b (?! (?>\s*) => ) /oxgc) { $slash = 'div'; return 'ord'; }
  0         0  
6319 0         0 elsif (/\G \b ord \b (?! (?>\s*) => ) /oxgc) { $slash = 'div'; return $function_ord_; }
  4         10  
6320 4         15 elsif (/\G \b glob \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::glob_'; }
  8         24  
6321 8         36 elsif (/\G \b reverse \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return $function_reverse; }
  2         8  
6322 2         15 elsif (/\G \b getc \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return $function_getc; }
  0         0  
6323 0         0 elsif (/\G \b opendir ((?>\s*) \( (?>\s*)) (?=[A-Za-z_]) /oxgc) { $slash = 'm//'; return "Ekps9566::opendir$1*"; }
  85         227  
6324             elsif (/\G \b opendir ((?>\s+)) (?=[A-Za-z_]) /oxgc) { $slash = 'm//'; return "Ekps9566::opendir$1*"; }
6325             elsif (/\G \b unlink \b (?! (?>\s*) => ) /oxgc) { $slash = 'm//'; return 'Ekps9566::unlink'; }
6326              
6327 85         357 # chdir
6328             elsif (/\G \b (chdir) \b (?! (?>\s*) => ) /oxgc) {
6329 3         8 $slash = 'm//';
6330              
6331 3         4 my $e = 'Ekps9566::chdir';
6332 3         12  
6333             while (/\G ( (?>\s+) | \( | \#.* ) /oxgc) {
6334             $e .= $1;
6335             }
6336 3 50       14  
  3 100       223  
    50          
    50          
    50          
    0          
6337             # end of chdir
6338             if (/\G (?= [,;\)\}\]] ) /oxgc) { return $e; }
6339 0         0  
6340             # chdir scalar value
6341             elsif (/\G ( [\$\@\&\*] $qq_scalar ) /oxgc) { return $e . e_string($1); }
6342              
6343 1 0       6 # chdir qq//
  0         0  
6344             elsif (/\G \b (qq) \b /oxgc) {
6345 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq# # --> qr # #
6346 0 0       0 else {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6347 0         0 while (not /\G \z/oxgc) {
6348 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6349 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq ( ) --> qr ( )
6350 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq { } --> qr { }
6351 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq [ ] --> qr [ ]
6352 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq < > --> qr < >
6353             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_chdir('qq','{','}',$2); } # qq | | --> qr { }
6354 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_chdir('qq',$1,$3,$2); } # qq * * --> qr * *
6355             }
6356             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6357             }
6358             }
6359              
6360 0 0       0 # chdir q//
  0         0  
6361             elsif (/\G \b (q) \b /oxgc) {
6362 0         0 if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q# # --> qr # #
6363 0 0       0 else {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6364 0         0 while (not /\G \z/oxgc) {
6365 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6366 0         0 elsif (/\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q ( ) --> qr ( )
6367 0         0 elsif (/\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q { } --> qr { }
6368 0         0 elsif (/\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q [ ] --> qr [ ]
6369 0         0 elsif (/\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q < > --> qr < >
6370             elsif (/\G ([*\-:?\\^|]) ((?:$q_char)*?) (\1) /oxgc) { return $e . e_chdir_q('q','{','}',$2); } # q | | --> qr { }
6371 0         0 elsif (/\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { return $e . e_chdir_q('q',$1,$3,$2); } # q * * --> qr * *
6372             }
6373             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6374             }
6375             }
6376              
6377 0         0 # chdir ''
6378 2         5 elsif (/\G (\') /oxgc) {
6379 2 50       8 my $q_string = '';
  13 50       68  
    100          
    50          
6380 0         0 while (not /\G \z/oxgc) {
6381 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6382 2         8 elsif (/\G (\\\') /oxgc) { $q_string .= $1; }
6383             elsif (/\G \' /oxgc) { return $e . e_chdir_q('',"'","'",$q_string); }
6384 11         22 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6385             }
6386             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6387             }
6388              
6389 0         0 # chdir ""
6390 0         0 elsif (/\G (\") /oxgc) {
6391 0 0       0 my $qq_string = '';
  0 0       0  
    0          
    0          
6392 0         0 while (not /\G \z/oxgc) {
6393 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6394 0         0 elsif (/\G (\\\") /oxgc) { $qq_string .= $1; }
6395             elsif (/\G \" /oxgc) { return $e . e_chdir('','"','"',$qq_string); }
6396 0         0 elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
6397             }
6398             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6399             }
6400             }
6401              
6402 0         0 # split
6403             elsif (/\G \b (split) \b (?! (?>\s*) => ) /oxgc) {
6404 404         1170 $slash = 'm//';
6405 404         680  
6406 404         1446 my $e = '';
6407             while (/\G ( (?>\s+) | \( | \#.* ) /oxgc) {
6408             $e .= $1;
6409             }
6410 401 100       1624  
  404 100       18417  
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    50          
    100          
    50          
    100          
    50          
    50          
    50          
6411             # end of split
6412             if (/\G (?= [,;\)\}\]] ) /oxgc) { return 'Ekps9566::split' . $e; }
6413 3         15  
6414             # split scalar value
6415             elsif (/\G ( [\$\@\&\*] $qq_scalar ) /oxgc) { return 'Ekps9566::split' . $e . e_string($1); }
6416 1         6  
6417 0         0 # split literal space
6418 0         0 elsif (/\G \b qq (\#) [ ] (\#) /oxgc) { return 'Ekps9566::split' . $e . qq {qq$1 $2}; }
6419 0         0 elsif (/\G \b qq ((?>\s*)) (\() [ ] (\)) /oxgc) { return 'Ekps9566::split' . $e . qq{$1qq$2 $3}; }
6420 0         0 elsif (/\G \b qq ((?>\s*)) (\{) [ ] (\}) /oxgc) { return 'Ekps9566::split' . $e . qq{$1qq$2 $3}; }
6421 0         0 elsif (/\G \b qq ((?>\s*)) (\[) [ ] (\]) /oxgc) { return 'Ekps9566::split' . $e . qq{$1qq$2 $3}; }
6422 0         0 elsif (/\G \b qq ((?>\s*)) (\<) [ ] (\>) /oxgc) { return 'Ekps9566::split' . $e . qq{$1qq$2 $3}; }
6423 0         0 elsif (/\G \b qq ((?>\s*)) (\S) [ ] (\2) /oxgc) { return 'Ekps9566::split' . $e . qq{$1qq$2 $3}; }
6424 0         0 elsif (/\G \b q (\#) [ ] (\#) /oxgc) { return 'Ekps9566::split' . $e . qq {q$1 $2}; }
6425 0         0 elsif (/\G \b q ((?>\s*)) (\() [ ] (\)) /oxgc) { return 'Ekps9566::split' . $e . qq {$1q$2 $3}; }
6426 0         0 elsif (/\G \b q ((?>\s*)) (\{) [ ] (\}) /oxgc) { return 'Ekps9566::split' . $e . qq {$1q$2 $3}; }
6427 0         0 elsif (/\G \b q ((?>\s*)) (\[) [ ] (\]) /oxgc) { return 'Ekps9566::split' . $e . qq {$1q$2 $3}; }
6428 0         0 elsif (/\G \b q ((?>\s*)) (\<) [ ] (\>) /oxgc) { return 'Ekps9566::split' . $e . qq {$1q$2 $3}; }
6429 13         64 elsif (/\G \b q ((?>\s*)) (\S) [ ] (\2) /oxgc) { return 'Ekps9566::split' . $e . qq {$1q$2 $3}; }
6430             elsif (/\G ' [ ] ' /oxgc) { return 'Ekps9566::split' . $e . qq {' '}; }
6431             elsif (/\G " [ ] " /oxgc) { return 'Ekps9566::split' . $e . qq {" "}; }
6432              
6433 2 0       11 # split qq//
  0         0  
6434             elsif (/\G \b (qq) \b /oxgc) {
6435 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq# # --> qr # #
6436 0 0       0 else {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6437 0         0 while (not /\G \z/oxgc) {
6438 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6439 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq ( ) --> qr ( )
6440 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq { } --> qr { }
6441 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq [ ] --> qr [ ]
6442 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq < > --> qr < >
6443             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) /oxgc) { return e_split($e.'qr','{','}',$2,''); } # qq | | --> qr { }
6444 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return e_split($e.'qr',$1,$3,$2,''); } # qq * * --> qr * *
6445             }
6446             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6447             }
6448             }
6449              
6450 0 50       0 # split qr//
  124         966  
6451             elsif (/\G \b (qr) \b /oxgc) {
6452 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1,$3,$2,$4); } # qr# #
6453 124 50       401 else {
  124 50       6097  
    50          
    50          
    50          
    100          
    50          
    50          
6454 0         0 while (not /\G \z/oxgc) {
6455 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6456 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr ( )
6457 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr { }
6458 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr [ ]
6459 56         250 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr < >
6460 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([imosxpadlunbB]*) /oxgc) { return e_split_q($e.'qr',$1, $3, $2,$4); } # qr ' '
6461             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr','{','}',$2,$4); } # qr | | --> qr { }
6462 68         361 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # qr * *
6463             }
6464             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6465             }
6466             }
6467              
6468 0 0       0 # split q//
  0         0  
6469             elsif (/\G \b (q) \b /oxgc) {
6470 0         0 if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q# # --> qr # #
6471 0 0       0 else {
  0 0       0  
    0          
    0          
    0          
    0          
    0          
6472 0         0 while (not /\G \z/oxgc) {
6473 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6474 0         0 elsif (/\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q ( ) --> qr ( )
6475 0         0 elsif (/\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q { } --> qr { }
6476 0         0 elsif (/\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q [ ] --> qr [ ]
6477 0         0 elsif (/\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q < > --> qr < >
6478             elsif (/\G ([*\-:?\\^|]) ((?:$q_char)*?) (\1) /oxgc) { return e_split_q($e.'qr','{','}',$2,''); } # q | | --> qr { }
6479 0         0 elsif (/\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { return e_split_q($e.'qr',$1,$3,$2,''); } # q * * --> qr * *
6480             }
6481             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6482             }
6483             }
6484              
6485 0 50       0 # split m//
  136         936  
6486             elsif (/\G \b (m) \b /oxgc) {
6487 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1,$3,$2,$4); } # m# # --> qr # #
6488 136 50       380 else {
  136 50       6387  
    50          
    50          
    50          
    100          
    50          
    50          
6489 0         0 while (not /\G \z/oxgc) {
6490 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6491 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m ( ) --> qr ( )
6492 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m { } --> qr { }
6493 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m [ ] --> qr [ ]
6494 56         233 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m < > --> qr < >
6495 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cgimosxpadlunbB]*) /oxgc) { return e_split_q($e.'qr',$1, $3, $2,$4); } # m ' ' --> qr ' '
6496             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr','{','}',$2,$4); } # m | | --> qr { }
6497 80         333 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return e_split ($e.'qr',$1, $3, $2,$4); } # m * * --> qr * *
6498             }
6499             die __FILE__, ": Search pattern not terminated\n";
6500             }
6501             }
6502              
6503 0         0 # split ''
6504 0         0 elsif (/\G (\') /oxgc) {
6505 0 0       0 my $q_string = '';
  0 0       0  
    0          
    0          
6506 0         0 while (not /\G \z/oxgc) {
6507 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6508 0         0 elsif (/\G (\\\') /oxgc) { $q_string .= $1; } # splitqr'' --> split qr''
6509             elsif (/\G \' /oxgc) { return e_split_q($e.q{ qr},"'","'",$q_string,''); } # ' ' --> qr ' '
6510 0         0 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6511             }
6512             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6513             }
6514              
6515 0         0 # split ""
6516 0         0 elsif (/\G (\") /oxgc) {
6517 0 0       0 my $qq_string = '';
  0 0       0  
    0          
    0          
6518 0         0 while (not /\G \z/oxgc) {
6519 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6520 0         0 elsif (/\G (\\\") /oxgc) { $qq_string .= $1; } # splitqr"" --> split qr""
6521             elsif (/\G \" /oxgc) { return e_split($e.q{ qr},'"','"',$qq_string,''); } # " " --> qr " "
6522 0         0 elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
6523             }
6524             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6525             }
6526              
6527 0         0 # split //
6528 125         332 elsif (/\G (\/) /oxgc) {
6529 125 50       418 my $regexp = '';
  558 50       2792  
    100          
    50          
6530 0         0 while (not /\G \z/oxgc) {
6531 0         0 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
6532 125         542 elsif (/\G (\\\/) /oxgc) { $regexp .= $1; } # splitqr// --> split qr//
6533             elsif (/\G \/ ([cgimosxpadlunbB]*) /oxgc) { return e_split($e.q{ qr}, '/','/',$regexp,$1); } # / / --> qr / /
6534 433         977 elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
6535             }
6536             die __FILE__, ": Search pattern not terminated\n";
6537             }
6538             }
6539              
6540             # tr/// or y///
6541              
6542             # about [cdsrbB]* (/B modifier)
6543             #
6544             # P.559 appendix C
6545             # of ISBN 4-89052-384-7 Programming perl
6546             # (Japanese title is: Perl puroguramingu)
6547 0         0  
6548             elsif (/\G \b ( tr | y ) \b /oxgc) {
6549             my $ope = $1;
6550 11 50       30  
6551 11         150 # $1 $2 $3 $4 $5 $6
6552 0         0 if (/\G (\#) ((?:$qq_char)*?) (\#) ((?:$qq_char)*?) (\#) ([cdsrbB]*) /oxgc) { # tr# # #
6553             my @tr = ($tr_variable,$2);
6554             return e_tr(@tr,'',$4,$6);
6555 0         0 }
6556 11         24 else {
6557 11 50       32 my $e = '';
  11 50       747  
    50          
    50          
    50          
    50          
6558             while (not /\G \z/oxgc) {
6559 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6560 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) {
6561 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
6562 0         0 while (not /\G \z/oxgc) {
6563 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6564 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) ( )
6565 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) { }
6566 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) [ ]
6567             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) < >
6568 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr ( ) * *
6569             }
6570             die __FILE__, ": Transliteration replacement not terminated\n";
6571 0         0 }
6572 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) {
6573 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
6574 0         0 while (not /\G \z/oxgc) {
6575 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6576 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } ( )
6577 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } { }
6578 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } [ ]
6579             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } < >
6580 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr { } * *
6581             }
6582             die __FILE__, ": Transliteration replacement not terminated\n";
6583 0         0 }
6584 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) {
6585 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
6586 0         0 while (not /\G \z/oxgc) {
6587 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6588 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] ( )
6589 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] { }
6590 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] [ ]
6591             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] < >
6592 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr [ ] * *
6593             }
6594             die __FILE__, ": Transliteration replacement not terminated\n";
6595 0         0 }
6596 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) {
6597 0 0       0 my @tr = ($tr_variable,$2);
  0 0       0  
    0          
    0          
    0          
    0          
6598 0         0 while (not /\G \z/oxgc) {
6599 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6600 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > ( )
6601 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > { }
6602 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > [ ]
6603             elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > < >
6604 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { return e_tr(@tr,$e,$2,$4); } # tr < > * *
6605             }
6606             die __FILE__, ": Transliteration replacement not terminated\n";
6607             }
6608 0         0 # $1 $2 $3 $4 $5 $6
6609 11         41 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cdsrbB]*) /oxgc) { # tr * * *
6610             my @tr = ($tr_variable,$2);
6611             return e_tr(@tr,'',$4,$6);
6612 11         34 }
6613             }
6614             die __FILE__, ": Transliteration pattern not terminated\n";
6615             }
6616             }
6617              
6618 0         0 # qq//
6619             elsif (/\G \b (qq) \b /oxgc) {
6620             my $ope = $1;
6621 5897 100       15908  
6622 5897         11627 # if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { return e_qq($ope,$1,$3,$2); } # qq# #
6623 40         56 if (/\G (\#) /oxgc) { # qq# #
6624 40 100       83 my $qq_string = '';
  1948 50       5194  
    100          
    50          
6625 80         142 while (not /\G \z/oxgc) {
6626 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6627 40         103 elsif (/\G (\\\#) /oxgc) { $qq_string .= $1; }
6628             elsif (/\G (\#) /oxgc) { return e_qq($ope,'#','#',$qq_string); }
6629 1828         3337 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6630             }
6631             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6632             }
6633 0         0  
6634 5857         7924 else {
6635 5857 50       14128 my $e = '';
  5857 50       22630  
    100          
    50          
    100          
    50          
6636             while (not /\G \z/oxgc) {
6637             if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6638              
6639 0         0 # elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq ( )
6640 0         0 elsif (/\G (\() /oxgc) { # qq ( )
6641 0         0 my $qq_string = '';
6642 0 0       0 local $nest = 1;
  0 0       0  
    0          
    0          
    0          
6643 0         0 while (not /\G \z/oxgc) {
6644 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  0         0  
6645             elsif (/\G (\\\)) /oxgc) { $qq_string .= $1; }
6646 0 0       0 elsif (/\G (\() /oxgc) { $qq_string .= $1; $nest++; }
  0         0  
6647 0         0 elsif (/\G (\)) /oxgc) {
6648             if (--$nest == 0) { return $e . e_qq($ope,'(',')',$qq_string); }
6649 0         0 else { $qq_string .= $1; }
6650             }
6651 0         0 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6652             }
6653             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6654             }
6655              
6656 0         0 # elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq { }
6657 5775         7668 elsif (/\G (\{) /oxgc) { # qq { }
6658 5775         7967 my $qq_string = '';
6659 5775 100       11883 local $nest = 1;
  246111 50       748989  
    100          
    100          
    50          
6660 720         1479 while (not /\G \z/oxgc) {
6661 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  1384         2019  
6662             elsif (/\G (\\\}) /oxgc) { $qq_string .= $1; }
6663 1384 100       2394 elsif (/\G (\{) /oxgc) { $qq_string .= $1; $nest++; }
  7159         11118  
6664 5775         12186 elsif (/\G (\}) /oxgc) {
6665             if (--$nest == 0) { return $e . e_qq($ope,'{','}',$qq_string); }
6666 1384         2765 else { $qq_string .= $1; }
6667             }
6668 236848         451267 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6669             }
6670             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6671             }
6672              
6673 0         0 # elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq [ ]
6674 0         0 elsif (/\G (\[) /oxgc) { # qq [ ]
6675 0         0 my $qq_string = '';
6676 0 0       0 local $nest = 1;
  0 0       0  
    0          
    0          
    0          
6677 0         0 while (not /\G \z/oxgc) {
6678 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  0         0  
6679             elsif (/\G (\\\]) /oxgc) { $qq_string .= $1; }
6680 0 0       0 elsif (/\G (\[) /oxgc) { $qq_string .= $1; $nest++; }
  0         0  
6681 0         0 elsif (/\G (\]) /oxgc) {
6682             if (--$nest == 0) { return $e . e_qq($ope,'[',']',$qq_string); }
6683 0         0 else { $qq_string .= $1; }
6684             }
6685 0         0 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6686             }
6687             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6688             }
6689              
6690 0         0 # elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq < >
6691 62         115 elsif (/\G (\<) /oxgc) { # qq < >
6692 62         145 my $qq_string = '';
6693 62 100       196 local $nest = 1;
  2040 50       7417  
    100          
    100          
    50          
6694 22         53 while (not /\G \z/oxgc) {
6695 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
  2         3  
6696             elsif (/\G (\\\>) /oxgc) { $qq_string .= $1; }
6697 2 100       4 elsif (/\G (\<) /oxgc) { $qq_string .= $1; $nest++; }
  64         159  
6698 62         179 elsif (/\G (\>) /oxgc) {
6699             if (--$nest == 0) { return $e . e_qq($ope,'<','>',$qq_string); }
6700 2         4 else { $qq_string .= $1; }
6701             }
6702 1952         3818 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6703             }
6704             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6705             }
6706              
6707 0         0 # elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qq * *
6708 20         31 elsif (/\G (\S) /oxgc) { # qq * *
6709 20         22 my $delimiter = $1;
6710 20 50       38 my $qq_string = '';
  840 50       2280  
    100          
    50          
6711 0         0 while (not /\G \z/oxgc) {
6712 0         0 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
6713 20         39 elsif (/\G (\\\Q$delimiter\E) /oxgc) { $qq_string .= $1; }
6714             elsif (/\G (\Q$delimiter\E) /oxgc) { return $e . e_qq($ope,$delimiter,$delimiter,$qq_string); }
6715 820         1461 elsif (/\G ($qq_char) /oxgc) { $qq_string .= $1; }
6716             }
6717             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6718 0         0 }
6719             }
6720             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6721             }
6722             }
6723              
6724 0         0 # qr//
6725 184 50       465 elsif (/\G \b (qr) \b /oxgc) {
6726 184         818 my $ope = $1;
6727             if (/\G (\#) ((?:$qq_char)*?) (\#) ([imosxpadlunbB]*) /oxgc) { # qr# # #
6728             return e_qr($ope,$1,$3,$2,$4);
6729 0         0 }
6730 184         320 else {
6731 184 50       449 my $e = '';
  184 50       5056  
    100          
    50          
    50          
    100          
    50          
    50          
6732 0         0 while (not /\G \z/oxgc) {
6733 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6734 1         6 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr ( )
6735 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr { }
6736 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr [ ]
6737 76         201 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr < >
6738 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([imosxpadlunbB]*) /oxgc) { return $e . e_qr_q($ope,$1, $3, $2,$4); } # qr ' '
6739             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,'{','}',$2,$4); } # qr | | --> qr { }
6740 107         395 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([imosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # qr * *
6741             }
6742             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6743             }
6744             }
6745              
6746 0         0 # qw//
6747 34 50       147 elsif (/\G \b (qw) \b /oxgc) {
6748 34         128 my $ope = $1;
6749             if (/\G (\#) (.*?) (\#) /oxmsgc) { # qw# #
6750             return e_qw($ope,$1,$3,$2);
6751 0         0 }
6752 34         68 else {
6753 34 50       133 my $e = '';
  34 50       244  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
6754             while (not /\G \z/oxgc) {
6755 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6756 34         178  
6757             elsif (/\G (\() ([^(]*?) (\)) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw ( )
6758 0         0 elsif (/\G (\() ((?:$q_paren)*?) (\)) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw ( )
6759 0         0  
6760             elsif (/\G (\{) ([^{]*?) (\}) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw { }
6761 0         0 elsif (/\G (\{) ((?:$q_brace)*?) (\}) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw { }
6762 0         0  
6763             elsif (/\G (\[) ([^[]*?) (\]) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw [ ]
6764 0         0 elsif (/\G (\[) ((?:$q_bracket)*?) (\]) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw [ ]
6765 0         0  
6766             elsif (/\G (\<) ([^<]*?) (\>) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw < >
6767 0         0 elsif (/\G (\<) ((?:$q_angle)*?) (\>) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw < >
6768 0         0  
6769             elsif (/\G ([\x21-\x3F]) (.*?) (\1) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw * *
6770 0         0 elsif (/\G (\S) ((?:$q_char)*?) (\1) /oxmsgc) { return $e . e_qw($ope,$1,$3,$2); } # qw * *
6771             }
6772             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6773             }
6774             }
6775              
6776 0         0 # qx//
6777 3 50       10 elsif (/\G \b (qx) \b /oxgc) {
6778 3         65 my $ope = $1;
6779             if (/\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qx# #
6780             return e_qq($ope,$1,$3,$2);
6781 0         0 }
6782 3         8 else {
6783 3 50       12 my $e = '';
  3 50       387  
    100          
    50          
    50          
    50          
    50          
6784 0         0 while (not /\G \z/oxgc) {
6785 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6786 2         6 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx ( )
6787 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx { }
6788 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx [ ]
6789 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx < >
6790             elsif (/\G (\') ((?:$qq_char)*?) (\') /oxgc) { return $e . e_q ($ope,$1,$3,$2); } # qx ' '
6791 1         5 elsif (/\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { return $e . e_qq($ope,$1,$3,$2); } # qx * *
6792             }
6793             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6794             }
6795             }
6796              
6797 0         0 # q//
6798             elsif (/\G \b (q) \b /oxgc) {
6799             my $ope = $1;
6800              
6801             # if (/\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { return e_q($ope,$1,$3,$2); } # q# #
6802              
6803             # avoid "Error: Runtime exception" of perl version 5.005_03
6804 604 50       2019 # (and so on)
6805 604         1848  
6806 0         0 if (/\G (\#) /oxgc) { # q# #
6807 0 0       0 my $q_string = '';
  0 0       0  
    0          
    0          
6808 0         0 while (not /\G \z/oxgc) {
6809 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6810 0         0 elsif (/\G (\\\#) /oxgc) { $q_string .= $1; }
6811             elsif (/\G (\#) /oxgc) { return e_q($ope,'#','#',$q_string); }
6812 0         0 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6813             }
6814             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6815             }
6816 0         0  
6817 604         1179 else {
6818 604 50       2080 my $e = '';
  604 100       3724  
    100          
    50          
    100          
    50          
6819             while (not /\G \z/oxgc) {
6820             if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6821              
6822 0         0 # elsif (/\G (\() ((?:\\\)|\\\\|$q_paren)*?) (\)) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q ( )
6823 1         3 elsif (/\G (\() /oxgc) { # q ( )
6824 1         2 my $q_string = '';
6825 1 50       3 local $nest = 1;
  7 50       49  
    50          
    50          
    100          
    50          
6826 0         0 while (not /\G \z/oxgc) {
6827 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6828 0         0 elsif (/\G (\\\)) /oxgc) { $q_string .= $1; }
  0         0  
6829             elsif (/\G (\\\() /oxgc) { $q_string .= $1; }
6830 0 50       0 elsif (/\G (\() /oxgc) { $q_string .= $1; $nest++; }
  1         2  
6831 1         3 elsif (/\G (\)) /oxgc) {
6832             if (--$nest == 0) { return $e . e_q($ope,'(',')',$q_string); }
6833 0         0 else { $q_string .= $1; }
6834             }
6835 6         14 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6836             }
6837             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6838             }
6839              
6840 0         0 # elsif (/\G (\{) ((?:\\\}|\\\\|$q_brace)*?) (\}) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q { }
6841 597         1142 elsif (/\G (\{) /oxgc) { # q { }
6842 597         1122 my $q_string = '';
6843 597 50       1783 local $nest = 1;
  8237 50       36496  
    50          
    100          
    100          
    50          
6844 0         0 while (not /\G \z/oxgc) {
6845 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6846 0         0 elsif (/\G (\\\}) /oxgc) { $q_string .= $1; }
  114         204  
6847             elsif (/\G (\\\{) /oxgc) { $q_string .= $1; }
6848 114 100       240 elsif (/\G (\{) /oxgc) { $q_string .= $1; $nest++; }
  711         1657  
6849 597         2100 elsif (/\G (\}) /oxgc) {
6850             if (--$nest == 0) { return $e . e_q($ope,'{','}',$q_string); }
6851 114         252 else { $q_string .= $1; }
6852             }
6853 7412         15958 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6854             }
6855             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6856             }
6857              
6858 0         0 # elsif (/\G (\[) ((?:\\\]|\\\\|$q_bracket)*?) (\]) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q [ ]
6859 0         0 elsif (/\G (\[) /oxgc) { # q [ ]
6860 0         0 my $q_string = '';
6861 0 0       0 local $nest = 1;
  0 0       0  
    0          
    0          
    0          
    0          
6862 0         0 while (not /\G \z/oxgc) {
6863 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6864 0         0 elsif (/\G (\\\]) /oxgc) { $q_string .= $1; }
  0         0  
6865             elsif (/\G (\\\[) /oxgc) { $q_string .= $1; }
6866 0 0       0 elsif (/\G (\[) /oxgc) { $q_string .= $1; $nest++; }
  0         0  
6867 0         0 elsif (/\G (\]) /oxgc) {
6868             if (--$nest == 0) { return $e . e_q($ope,'[',']',$q_string); }
6869 0         0 else { $q_string .= $1; }
6870             }
6871 0         0 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6872             }
6873             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6874             }
6875              
6876 0         0 # elsif (/\G (\<) ((?:\\\>|\\\\|$q_angle)*?) (\>) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q < >
6877 5         11 elsif (/\G (\<) /oxgc) { # q < >
6878 5         11 my $q_string = '';
6879 5 50       22 local $nest = 1;
  82 50       498  
    50          
    50          
    100          
    50          
6880 0         0 while (not /\G \z/oxgc) {
6881 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6882 0         0 elsif (/\G (\\\>) /oxgc) { $q_string .= $1; }
  0         0  
6883             elsif (/\G (\\\<) /oxgc) { $q_string .= $1; }
6884 0 50       0 elsif (/\G (\<) /oxgc) { $q_string .= $1; $nest++; }
  5         15  
6885 5         20 elsif (/\G (\>) /oxgc) {
6886             if (--$nest == 0) { return $e . e_q($ope,'<','>',$q_string); }
6887 0         0 else { $q_string .= $1; }
6888             }
6889 77         169 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6890             }
6891             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6892             }
6893              
6894 0         0 # elsif (/\G (\S) ((?:\\\1|\\\\|$q_char)*?) (\1) /oxgc) { return $e . e_q($ope,$1,$3,$2); } # q * *
6895 1         3 elsif (/\G (\S) /oxgc) { # q * *
6896 1         3 my $delimiter = $1;
6897 1 50       9 my $q_string = '';
  14 50       78  
    100          
    50          
6898 0         0 while (not /\G \z/oxgc) {
6899 0         0 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
6900 1         3 elsif (/\G (\\\Q$delimiter\E) /oxgc) { $q_string .= $1; }
6901             elsif (/\G (\Q$delimiter\E) /oxgc) { return $e . e_q($ope,$delimiter,$delimiter,$q_string); }
6902 13         26 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
6903             }
6904             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6905 0         0 }
6906             }
6907             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
6908             }
6909             }
6910              
6911 0         0 # m//
6912 491 50       1350 elsif (/\G \b (m) \b /oxgc) {
6913 491         2772 my $ope = $1;
6914             if (/\G (\#) ((?:$qq_char)*?) (\#) ([cgimosxpadlunbB]*) /oxgc) { # m# #
6915             return e_qr($ope,$1,$3,$2,$4);
6916 0         0 }
6917 491         798 else {
6918 491 50       1321 my $e = '';
  491 50       20430  
    50          
    50          
    50          
    100          
    100          
    50          
    50          
6919 0         0 while (not /\G \z/oxgc) {
6920 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6921 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m ( )
6922 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m { }
6923 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m [ ]
6924 92         296 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m < >
6925 87         244 elsif (/\G (\?) ((?:$qq_char)*?) (\?) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m ? ?
6926 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr_q($ope,$1, $3, $2,$4); } # m ' '
6927             elsif (/\G ([*\-:\\^|]) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,'{','}',$2,$4); } # m | | --> m { }
6928 312         1133 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cgimosxpadlunbB]*) /oxgc) { return $e . e_qr ($ope,$1, $3, $2,$4); } # m * *
6929             }
6930             die __FILE__, ": Search pattern not terminated\n";
6931             }
6932             }
6933              
6934             # s///
6935              
6936             # about [cegimosxpradlunbB]* (/cg modifier)
6937             #
6938             # P.67 Pattern-Matching Operators
6939             # of ISBN 0-596-00241-6 Perl in a Nutshell, Second Edition.
6940 0         0  
6941             elsif (/\G \b (s) \b /oxgc) {
6942             my $ope = $1;
6943 290 100       821  
6944 290         3936 # $1 $2 $3 $4 $5 $6
6945             if (/\G (\#) ((?:$qq_char)*?) (\#) ((?:$qq_char)*?) (\#) ([cegimosxpradlunbB]*) /oxgc) { # s# # #
6946             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
6947 1         6 }
6948 289         625 else {
6949 289 50       825 my $e = '';
  289 50       28708  
    50          
    50          
    50          
    100          
    100          
    50          
    50          
6950             while (not /\G \z/oxgc) {
6951 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6952 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) /oxgc) {
6953 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
6954             while (not /\G \z/oxgc) {
6955 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6956 0         0 # $1 $2 $3 $4
6957 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6958 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6959 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6960 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6961 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6962 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6963 0         0 elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6964             elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6965 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6966             }
6967             die __FILE__, ": Substitution replacement not terminated\n";
6968 0         0 }
6969 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) {
6970 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
6971             while (not /\G \z/oxgc) {
6972 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6973 0         0 # $1 $2 $3 $4
6974 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6975 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6976 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6977 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6978 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6979 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6980 0         0 elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6981             elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6982 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6983             }
6984             die __FILE__, ": Substitution replacement not terminated\n";
6985 0         0 }
6986 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) {
6987 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
6988             while (not /\G \z/oxgc) {
6989 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
6990 0         0 # $1 $2 $3 $4
6991 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6992 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6993 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6994 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6995 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6996             elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6997 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
6998             }
6999             die __FILE__, ": Substitution replacement not terminated\n";
7000 0         0 }
7001 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) {
7002 0 0       0 my @s = ($1,$2,$3);
  0 0       0  
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
7003             while (not /\G \z/oxgc) {
7004 0         0 if (/\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
7005 0         0 # $1 $2 $3 $4
7006 0         0 elsif (/\G (\() ((?:$qq_paren)*?) (\)) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7007 0         0 elsif (/\G (\{) ((?:$qq_brace)*?) (\}) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7008 0         0 elsif (/\G (\[) ((?:$qq_bracket)*?) (\]) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7009 0         0 elsif (/\G (\<) ((?:$qq_angle)*?) (\>) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7010 0         0 elsif (/\G (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7011 0         0 elsif (/\G (\$) ((?:$qq_char)*?) (\$) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7012 0         0 elsif (/\G (\:) ((?:$qq_char)*?) (\:) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7013             elsif (/\G (\@) ((?:$qq_char)*?) (\@) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7014 0         0 elsif (/\G (\S) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) { return e_sub($sub_variable,@s,$1,$2,$3,$4); }
7015             }
7016             die __FILE__, ": Substitution replacement not terminated\n";
7017             }
7018 0         0 # $1 $2 $3 $4 $5 $6
7019             elsif (/\G (\') ((?:$qq_char)*?) (\') ((?:$qq_char)*?) (\') ([cegimosxpradlunbB]*) /oxgc) {
7020             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
7021             }
7022 96         250 # $1 $2 $3 $4 $5 $6
7023             elsif (/\G ([*\-:?\\^|]) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
7024             return e_sub($sub_variable,'{',$2,'}','{',$4,'}',$6); # s | | | --> s { } { }
7025             }
7026 2         17 # $1 $2 $3 $4 $5 $6
7027             elsif (/\G (\$) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
7028             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
7029             }
7030 0         0 # $1 $2 $3 $4 $5 $6
7031             elsif (/\G (\S) ((?:$qq_char)*?) (\1) ((?:$qq_char)*?) (\1) ([cegimosxpradlunbB]*) /oxgc) {
7032             return e_sub($sub_variable,$1,$2,$3,$3,$4,$5,$6);
7033 191         819 }
7034             }
7035             die __FILE__, ": Substitution pattern not terminated\n";
7036             }
7037             }
7038 0         0  
7039 1         5 # do
7040 0         0 elsif (/\G \b do (?= (?>\s*) \{ ) /oxmsgc) { return 'do'; }
7041 0         0 elsif (/\G \b do (?= (?>\s+) (?: q | qq | qx ) \b) /oxmsgc) { return 'Ekps9566::do'; }
7042 0         0 elsif (/\G \b do (?= (?>\s+) (?>\w+)) /oxmsgc) { return 'do'; }
7043             elsif (/\G \b do (?= (?>\s*) \$ (?> \w+ (?: ::\w+)* ) \( ) /oxmsgc) { return 'do'; }
7044             elsif (/\G \b do \b /oxmsgc) { return 'Ekps9566::do'; }
7045 2         10  
7046 0         0 # require ignore module
7047 0         0 elsif (/\G \b require ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# require$1$2"; }
7048             elsif (/\G \b require ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^\x81-\xFE#]) /oxmsgc) { return "# require$1\n$2"; }
7049             elsif (/\G \b require ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# require$1"; }
7050 0         0  
7051 0         0 # require version number
7052 0         0 elsif (/\G \b require (?>\s+) ((?>0[0-7_]*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7053             elsif (/\G \b require (?>\s+) ((?>[1-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7054             elsif (/\G \b require (?>\s+) ((?>v[0-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7055 0         0  
7056             # require bare package name
7057             elsif (/\G \b require (?>\s+) ((?>[A-Za-z_]\w* (?: :: [A-Za-z_]\w*)*)) (?>\s*) ; /oxmsgc) { return "require $1;"; }
7058 18         131  
7059 0         0 # require else
7060             elsif (/\G \b require (?>\s*) ; /oxmsgc) { return 'Ekps9566::require;'; }
7061             elsif (/\G \b require \b /oxmsgc) { return 'Ekps9566::require'; }
7062 1         6  
7063 70         655 # use strict; --> use strict; no strict qw(refs);
7064 0         0 elsif (/\G \b use ((?>\s+) strict .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "use$1 no strict qw(refs);$2"; }
7065             elsif (/\G \b use ((?>\s+) strict .*? ;) ([ \t]* [^\x81-\xFE#]) /oxmsgc) { return "use$1 no strict qw(refs);\n$2"; }
7066             elsif (/\G \b use ((?>\s+) strict) \b /oxmsgc) { return "use$1; no strict qw(refs)"; }
7067              
7068 0 50 33     0 # use 5.12.0; --> use 5.12.0; no strict qw(refs);
      33        
7069 3         53 elsif (/\G \b use (?>\s+) ((?>([1-9][0-9_]*)(?:\.([0-9_]+))*)) (?>\s*) ; /oxmsgc) {
7070             if (($2 >= 6) or (($2 == 5) and ($3 ge '012'))) {
7071             return "use $1; no strict qw(refs);";
7072 0         0 }
7073             else {
7074             return "use $1;";
7075             }
7076 3 0 0     32 }
      0        
7077 0         0 elsif (/\G \b use (?>\s+) ((?>v([0-9][0-9_]*)(?:\.([0-9_]+))*)) (?>\s*) ; /oxmsgc) {
7078             if (($2 >= 6) or (($2 == 5) and ($3 >= 12))) {
7079             return "use $1; no strict qw(refs);";
7080 0         0 }
7081             else {
7082             return "use $1;";
7083             }
7084             }
7085 0         0  
7086 2         13 # ignore use module
7087 0         0 elsif (/\G \b use ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# use$1$2"; }
7088             elsif (/\G \b use ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^\x81-\xFE#]) /oxmsgc) { return "# use$1\n$2"; }
7089             elsif (/\G \b use ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# use$1"; }
7090 0         0  
7091 0         0 # ignore no module
7092 0         0 elsif (/\G \b no ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [#\n]) /oxmsgc) { return "# no$1$2"; }
7093             elsif (/\G \b no ((?>\s+) (?:$ignore_modules) .*? ;) ([ \t]* [^\x81-\xFE#]) /oxmsgc) { return "# no$1\n$2"; }
7094             elsif (/\G \b no ((?>\s+) (?:$ignore_modules)) \b /oxmsgc) { return "# no$1"; }
7095 0         0  
7096 0         0 # use without import
7097 0         0 elsif (/\G \b use (?>\s+) ((?>0[0-7_]*)) (?>\s*) ; /oxmsgc) { return "use $1;"; }
7098 0         0 elsif (/\G \b use (?>\s+) ((?>[1-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "use $1;"; }
7099 0         0 elsif (/\G \b use (?>\s+) ((?>v[0-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "use $1;"; }
7100 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7101 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7102 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\{) (?>\s*) \} (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7103 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\[) (?>\s*) \] (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7104 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\<) (?>\s*) \> (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7105             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) ([\x21-\x3F]) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7106             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\S) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_use_noimport($1); }
7107 0         0  
7108             # use with import no parameter
7109             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ; /oxmsgc) { return e_use_noparam($1); }
7110 0         0  
7111 0         0 # use with import parameters
7112 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\() [^\x81-\xFE)]* \)) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7113 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\') [^\x81-\xFE']* \') (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7114 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\") [^\x81-\xFE"]* \") (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7115 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\() [^\x81-\xFE)]* \)) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7116 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); }
7117 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); }
7118 0         0 elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\<) [^\x81-\xFE>]* \>) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7119             elsif (/\G \b use (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) ([\x21-\x3F]) .*? \3) (?>\s*) ; /oxmsgc) { return e_use($1,$2); }
7120             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); }
7121 0         0  
7122 0         0 # no without unimport
7123 0         0 elsif (/\G \b no (?>\s+) ((?>0[0-7_]*)) (?>\s*) ; /oxmsgc) { return "no $1;"; }
7124 0         0 elsif (/\G \b no (?>\s+) ((?>[1-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "no $1;"; }
7125 0         0 elsif (/\G \b no (?>\s+) ((?>v[0-9][0-9_]*(?:\.[0-9_]+)*)) (?>\s*) ; /oxmsgc) { return "no $1;"; }
7126 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7127 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\() (?>\s*) \) (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7128 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\{) (?>\s*) \} (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7129 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\[) (?>\s*) \] (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7130 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\<) (?>\s*) \> (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7131             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) ([\x21-\x3F]) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7132             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) qw (?>\s*) (\S) (?>\s*) \2 (?>\s*) ; /oxmsgc) { return e_no_nounimport($1); }
7133 0         0  
7134             # no with unimport no parameter
7135             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ; /oxmsgc) { return e_no_noparam($1); }
7136 0         0  
7137 0         0 # no with unimport parameters
7138 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\() [^\x81-\xFE)]* \)) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7139 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\') [^\x81-\xFE']* \') (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7140 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s*) ( (\") [^\x81-\xFE"]* \") (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7141 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\() [^\x81-\xFE)]* \)) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7142 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); }
7143 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); }
7144 0         0 elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) (\<) [^\x81-\xFE>]* \>) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7145             elsif (/\G \b no (?>\s+) ((?>[A-Z]\w*(?: ::\w+)*)) (?>\s+) ((?: q | qq | qw ) (?>\s*) ([\x21-\x3F]) .*? \3) (?>\s*) ; /oxmsgc) { return e_no($1,$2); }
7146             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); }
7147 0         0  
7148             # use else
7149             elsif (/\G \b use \b /oxmsgc) { return "use"; }
7150 0         0  
7151             # use else
7152             elsif (/\G \b no \b /oxmsgc) { return "no"; }
7153              
7154 2         9 # ''
7155 3173         7592 elsif (/\G (?
7156 3173 100       8427 my $q_string = '';
  15660 100       53660  
    100          
    50          
7157 8         20 while (not /\G \z/oxgc) {
7158 48         101 if (/\G (\\\\) /oxgc) { $q_string .= $1; }
7159 3173         7536 elsif (/\G (\\\') /oxgc) { $q_string .= $1; }
7160             elsif (/\G \' /oxgc) { return e_q('', "'","'",$q_string); }
7161 12431         26847 elsif (/\G ($q_char) /oxgc) { $q_string .= $1; }
7162             }
7163             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7164             }
7165              
7166 0         0 # ""
7167 3366         7981 elsif (/\G (\") /oxgc) {
7168 3366 100       9174 my $qq_string = '';
  69472 100       199902  
    100          
    50          
7169 109         234 while (not /\G \z/oxgc) {
7170 14         27 if (/\G (\\\\) /oxgc) { $qq_string .= $1; }
7171 3366         8447 elsif (/\G (\\\") /oxgc) { $qq_string .= $1; }
7172             elsif (/\G \" /oxgc) { return e_qq('', '"','"',$qq_string); }
7173 65983         124887 elsif (/\G ($q_char) /oxgc) { $qq_string .= $1; }
7174             }
7175             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7176             }
7177              
7178 0         0 # ``
7179 37         132 elsif (/\G (\`) /oxgc) {
7180 37 50       147 my $qx_string = '';
  313 50       1801  
    100          
    50          
7181 0         0 while (not /\G \z/oxgc) {
7182 0         0 if (/\G (\\\\) /oxgc) { $qx_string .= $1; }
7183 37         355 elsif (/\G (\\\`) /oxgc) { $qx_string .= $1; }
7184             elsif (/\G \` /oxgc) { return e_qq('', '`','`',$qx_string); }
7185 276         647 elsif (/\G ($q_char) /oxgc) { $qx_string .= $1; }
7186             }
7187             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7188             }
7189              
7190 0         0 # // --- not divide operator (num / num), not defined-or
7191 1229         2968 elsif (($slash eq 'm//') and /\G (\/) /oxgc) {
7192 1229 100       3689 my $regexp = '';
  12510 50       40911  
    100          
    50          
7193 11         37 while (not /\G \z/oxgc) {
7194 0         0 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
7195 1229         3416 elsif (/\G (\\\/) /oxgc) { $regexp .= $1; }
7196             elsif (/\G \/ ([cgimosxpadlunbB]*) /oxgc) { return e_qr('', '/','/',$regexp,$1); }
7197 11270         22062 elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
7198             }
7199             die __FILE__, ": Search pattern not terminated\n";
7200             }
7201              
7202 0         0 # ?? --- not conditional operator (condition ? then : else)
7203 92         216 elsif (($slash eq 'm//') and /\G (\?) /oxgc) {
7204 92 50       255 my $regexp = '';
  266 50       1071  
    100          
    50          
7205 0         0 while (not /\G \z/oxgc) {
7206 0         0 if (/\G (\\\\) /oxgc) { $regexp .= $1; }
7207 92         262 elsif (/\G (\\\?) /oxgc) { $regexp .= $1; }
7208             elsif (/\G \? ([cgimosxpadlunbB]*) /oxgc) { return e_qr('m','?','?',$regexp,$1); }
7209 174         454 elsif (/\G ($q_char) /oxgc) { $regexp .= $1; }
7210             }
7211             die __FILE__, ": Search pattern not terminated\n";
7212             }
7213 0         0  
  0         0  
7214             # <<>> (a safer ARGV)
7215             elsif (/\G ( <<>> ) /oxgc) { $slash = 'm//'; return $1; }
7216 0         0  
  0         0  
7217             # << (bit shift) --- not here document
7218             elsif (/\G ( << (?>\s*) ) (?= [0-9\$\@\&] ) /oxgc) { $slash = 'm//'; return $1; }
7219              
7220 0         0 # <<~'HEREDOC'
7221 6         13 elsif (/\G ( <<~ [\t ]* '([a-zA-Z_0-9]*)' ) /oxgc) {
7222 6         13 $slash = 'm//';
7223             my $here_quote = $1;
7224             my $delimiter = $2;
7225 6 50       8  
7226 6         13 # get here document
7227 6         28 if ($here_script eq '') {
7228             $here_script = CORE::substr $_, pos $_;
7229 6 50       31 $here_script =~ s/.*?\n//oxm;
7230 6         61 }
7231 6         12 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7232 6         10 my $heredoc = $1;
7233 6         44 my $indent = $2;
7234 6         34 $heredoc =~ s{^$indent}{}msg; # no /ox
7235             push @heredoc, $heredoc . qq{\n$delimiter\n};
7236             push @heredoc_delimiter, qq{\\s*$delimiter};
7237 6         10 }
7238             else {
7239 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7240             }
7241             return qq{<<'$delimiter'};
7242             }
7243              
7244             # <<~\HEREDOC
7245              
7246             # P.66 2.6.6. "Here" Documents
7247             # in Chapter 2: Bits and Pieces
7248             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
7249              
7250             # P.73 "Here" Documents
7251             # in Chapter 2: Bits and Pieces
7252             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7253 6         24  
7254 3         6 elsif (/\G ( <<~ \\([a-zA-Z_0-9]+) ) /oxgc) {
7255 3         6 $slash = 'm//';
7256             my $here_quote = $1;
7257             my $delimiter = $2;
7258 3 50       6  
7259 3         8 # get here document
7260 3         11 if ($here_script eq '') {
7261             $here_script = CORE::substr $_, pos $_;
7262 3 50       15 $here_script =~ s/.*?\n//oxm;
7263 3         35 }
7264 3         7 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7265 3         5 my $heredoc = $1;
7266 3         32 my $indent = $2;
7267 3         10 $heredoc =~ s{^$indent}{}msg; # no /ox
7268             push @heredoc, $heredoc . qq{\n$delimiter\n};
7269             push @heredoc_delimiter, qq{\\s*$delimiter};
7270 3         7 }
7271             else {
7272 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7273             }
7274             return qq{<<\\$delimiter};
7275             }
7276              
7277 3         10 # <<~"HEREDOC"
7278 6         14 elsif (/\G ( <<~ [\t ]* "([a-zA-Z_0-9]*)" ) /oxgc) {
7279 6         12 $slash = 'm//';
7280             my $here_quote = $1;
7281             my $delimiter = $2;
7282 6 50       8  
7283 6         13 # get here document
7284 6         25 if ($here_script eq '') {
7285             $here_script = CORE::substr $_, pos $_;
7286 6 50       32 $here_script =~ s/.*?\n//oxm;
7287 6         62 }
7288 6         13 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7289 6         9 my $heredoc = $1;
7290 6         44 my $indent = $2;
7291 6         16 $heredoc =~ s{^$indent}{}msg; # no /ox
7292             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
7293             push @heredoc_delimiter, qq{\\s*$delimiter};
7294 6         14 }
7295             else {
7296 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7297             }
7298             return qq{<<"$delimiter"};
7299             }
7300              
7301 6         22 # <<~HEREDOC
7302 3         8 elsif (/\G ( <<~ ([a-zA-Z_0-9]+) ) /oxgc) {
7303 3         7 $slash = 'm//';
7304             my $here_quote = $1;
7305             my $delimiter = $2;
7306 3 50       5  
7307 3         7 # get here document
7308 3         13 if ($here_script eq '') {
7309             $here_script = CORE::substr $_, pos $_;
7310 3 50       15 $here_script =~ s/.*?\n//oxm;
7311 3         35 }
7312 3         6 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7313 3         5 my $heredoc = $1;
7314 3         33 my $indent = $2;
7315 3         10 $heredoc =~ s{^$indent}{}msg; # no /ox
7316             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
7317             push @heredoc_delimiter, qq{\\s*$delimiter};
7318 3         7 }
7319             else {
7320 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7321             }
7322             return qq{<<$delimiter};
7323             }
7324              
7325 3         14 # <<~`HEREDOC`
7326 6         13 elsif (/\G ( <<~ [\t ]* `([a-zA-Z_0-9]*)` ) /oxgc) {
7327 6         12 $slash = 'm//';
7328             my $here_quote = $1;
7329             my $delimiter = $2;
7330 6 50       11  
7331 6         15 # get here document
7332 6         35 if ($here_script eq '') {
7333             $here_script = CORE::substr $_, pos $_;
7334 6 50       37 $here_script =~ s/.*?\n//oxm;
7335 6         56 }
7336 6         12 if ($here_script =~ s/\A (.*?) \n ([\t ]*) $delimiter \n //xms) {
7337 6         10 my $heredoc = $1;
7338 6         47 my $indent = $2;
7339 6         33 $heredoc =~ s{^$indent}{}msg; # no /ox
7340             push @heredoc, e_heredoc($heredoc) . qq{\n$delimiter\n};
7341             push @heredoc_delimiter, qq{\\s*$delimiter};
7342 6         13 }
7343             else {
7344 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7345             }
7346             return qq{<<`$delimiter`};
7347             }
7348              
7349 6         25 # <<'HEREDOC'
7350 86         220 elsif (/\G ( << '([a-zA-Z_0-9]*)' ) /oxgc) {
7351 86         194 $slash = 'm//';
7352             my $here_quote = $1;
7353             my $delimiter = $2;
7354 86 100       142  
7355 86         204 # get here document
7356 83         391 if ($here_script eq '') {
7357             $here_script = CORE::substr $_, pos $_;
7358 83 50       439 $here_script =~ s/.*?\n//oxm;
7359 86         694 }
7360 86         324 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7361             push @heredoc, $1 . qq{\n$delimiter\n};
7362             push @heredoc_delimiter, $delimiter;
7363 86         166 }
7364             else {
7365 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7366             }
7367             return $here_quote;
7368             }
7369              
7370             # <<\HEREDOC
7371              
7372             # P.66 2.6.6. "Here" Documents
7373             # in Chapter 2: Bits and Pieces
7374             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
7375              
7376             # P.73 "Here" Documents
7377             # in Chapter 2: Bits and Pieces
7378             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7379 86         349  
7380 2         6 elsif (/\G ( << \\([a-zA-Z_0-9]+) ) /oxgc) {
7381 2         5 $slash = 'm//';
7382             my $here_quote = $1;
7383             my $delimiter = $2;
7384 2 100       4  
7385 2         5 # get here document
7386 1         7 if ($here_script eq '') {
7387             $here_script = CORE::substr $_, pos $_;
7388 1 50       19 $here_script =~ s/.*?\n//oxm;
7389 2         28 }
7390 2         7 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7391             push @heredoc, $1 . qq{\n$delimiter\n};
7392             push @heredoc_delimiter, $delimiter;
7393 2         4 }
7394             else {
7395 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7396             }
7397             return $here_quote;
7398             }
7399              
7400 2         9 # <<"HEREDOC"
7401 39         103 elsif (/\G ( << "([a-zA-Z_0-9]*)" ) /oxgc) {
7402 39         98 $slash = 'm//';
7403             my $here_quote = $1;
7404             my $delimiter = $2;
7405 39 100       78  
7406 39         109 # get here document
7407 38         249 if ($here_script eq '') {
7408             $here_script = CORE::substr $_, pos $_;
7409 38 50       215 $here_script =~ s/.*?\n//oxm;
7410 39         515 }
7411 39         173 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7412             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
7413             push @heredoc_delimiter, $delimiter;
7414 39         123 }
7415             else {
7416 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7417             }
7418             return $here_quote;
7419             }
7420              
7421 39         176 # <
7422 54         180 elsif (/\G ( << ([a-zA-Z_0-9]+) ) /oxgc) {
7423 54         135 $slash = 'm//';
7424             my $here_quote = $1;
7425             my $delimiter = $2;
7426 54 100       111  
7427 54         153 # get here document
7428 51         428 if ($here_script eq '') {
7429             $here_script = CORE::substr $_, pos $_;
7430 51 50       427 $here_script =~ s/.*?\n//oxm;
7431 54         843 }
7432 54         240 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7433             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
7434             push @heredoc_delimiter, $delimiter;
7435 54         133 }
7436             else {
7437 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7438             }
7439             return $here_quote;
7440             }
7441              
7442 54         236 # <<`HEREDOC`
7443 0         0 elsif (/\G ( << `([a-zA-Z_0-9]*)` ) /oxgc) {
7444 0         0 $slash = 'm//';
7445             my $here_quote = $1;
7446             my $delimiter = $2;
7447 0 0       0  
7448 0         0 # get here document
7449 0         0 if ($here_script eq '') {
7450             $here_script = CORE::substr $_, pos $_;
7451 0 0       0 $here_script =~ s/.*?\n//oxm;
7452 0         0 }
7453 0         0 if ($here_script =~ s/\A (.*?) \n $delimiter \n //xms) {
7454             push @heredoc, e_heredoc($1) . qq{\n$delimiter\n};
7455             push @heredoc_delimiter, $delimiter;
7456 0         0 }
7457             else {
7458 0         0 die __FILE__, ": Can't find string terminator $delimiter anywhere before EOF\n";
7459             }
7460             return $here_quote;
7461             }
7462              
7463 0         0 # <<= <=> <= < operator
7464             elsif (/\G ( <<= | <=> | <= | < ) (?= (?>\s*) [A-Za-z_0-9'"`\$\@\&\*\(\+\-] )/oxgc) {
7465             return $1;
7466             }
7467              
7468 13         79 #
7469             elsif (/\G (<[\$]?[A-Za-z_][A-Za-z_0-9]*>) /oxgc) {
7470             return $1;
7471             }
7472              
7473             # --- glob
7474              
7475             # avoid "Error: Runtime exception" of perl version 5.005_03
7476 0         0  
7477             elsif (/\G < ((?:[^\x81-\xFE>\0\a\e\f\n\r\t]|[\x81-\xFE][\x00-\xFF])+?) > /oxgc) {
7478             return 'Ekps9566::glob("' . $1 . '")';
7479             }
7480 0         0  
7481             # __DATA__
7482             elsif (/\G ^ ( __DATA__ \n .*) \z /oxmsgc) { return $1; }
7483 0         0  
7484             # __END__
7485             elsif (/\G ^ ( __END__ \n .*) \z /oxmsgc) { return $1; }
7486              
7487             # \cD Control-D
7488              
7489             # P.68 2.6.8. Other Literal Tokens
7490             # in Chapter 2: Bits and Pieces
7491             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
7492              
7493             # P.76 Other Literal Tokens
7494             # in Chapter 2: Bits and Pieces
7495 382         3084 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7496              
7497             elsif (/\G ( \cD .*) \z /oxmsgc) { return $1; }
7498 0         0  
7499             # \cZ Control-Z
7500             elsif (/\G ( \cZ .*) \z /oxmsgc) { return $1; }
7501              
7502             # any operator before div
7503             elsif (/\G (
7504             -- | \+\+ |
7505 0         0 [\)\}\]]
  14110         30909  
7506              
7507             ) /oxgc) { $slash = 'div'; return $1; }
7508              
7509             # yada-yada or triple-dot operator
7510             elsif (/\G (
7511 14110         66779 \.\.\.
  7         11  
7512              
7513             ) /oxgc) { $slash = 'm//'; return q{die('Unimplemented')}; }
7514              
7515             # any operator before m//
7516              
7517             # //, //= (defined-or)
7518              
7519             # P.164 Logical Operators
7520             # in Chapter 10: More Control Structures
7521             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
7522              
7523             # P.119 C-Style Logical (Short-Circuit) Operators
7524             # in Chapter 3: Unary and Binary Operators
7525             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7526              
7527             # (and so on)
7528              
7529             # ~~
7530              
7531             # P.221 The Smart Match Operator
7532             # in Chapter 15: Smart Matching and given-when
7533             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
7534              
7535             # P.112 Smartmatch Operator
7536             # in Chapter 3: Unary and Binary Operators
7537             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
7538              
7539             # (and so on)
7540              
7541             elsif (/\G ((?>
7542              
7543             !~~ | !~ | != | ! |
7544             %= | % |
7545             &&= | && | &= | &\.= | &\. | & |
7546             -= | -> | - |
7547             :(?>\s*)= |
7548             : |
7549             <<>> |
7550             <<= | <=> | <= | < |
7551             == | => | =~ | = |
7552             >>= | >> | >= | > |
7553             \*\*= | \*\* | \*= | \* |
7554             \+= | \+ |
7555             \.\. | \.= | \. |
7556             \/\/= | \/\/ |
7557             \/= | \/ |
7558             \? |
7559             \\ |
7560             \^= | \^\.= | \^\. | \^ |
7561             \b x= |
7562             \|\|= | \|\| | \|= | \|\.= | \|\. | \| |
7563             ~~ | ~\. | ~ |
7564             \b(?: and | cmp | eq | ge | gt | le | lt | ne | not | or | xor | x )\b |
7565             \b(?: print )\b |
7566              
7567 7         25 [,;\(\{\[]
  23728         53496  
7568              
7569             )) /oxgc) { $slash = 'm//'; return $1; }
7570 23728         110019  
  37353         79598  
7571             # other any character
7572             elsif (/\G ($q_char) /oxgc) { $slash = 'div'; return $1; }
7573              
7574 37353         195349 # system error
7575             else {
7576             die __FILE__, ": Oops, this shouldn't happen!\n";
7577             }
7578             }
7579              
7580 0     3096 0 0 # escape KPS9566 string
7581 3096         7174 sub e_string {
7582             my($string) = @_;
7583 3096         4369 my $e_string = '';
7584              
7585             local $slash = 'm//';
7586              
7587             # P.1024 Appendix W.10 Multibyte Processing
7588             # of ISBN 1-56592-224-7 CJKV Information Processing
7589 3096         4448 # (and so on)
7590              
7591             my @char = $string =~ / \G (?>[^\x81-\xFE\\]|\\$q_char|$q_char) /oxmsg;
7592 3096 100 66     27460  
7593 3096 50       13589 # without { ... }
7594 3014         6519 if (not (grep(/\A \{ \z/xms, @char) and grep(/\A \} \z/xms, @char))) {
7595             if ($string !~ /<
7596             return $string;
7597             }
7598             }
7599 3014         7262  
7600 82 50       259 E_STRING_LOOP:
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    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          
    100          
    100          
    50          
    50          
7601             while ($string !~ /\G \z/oxgc) {
7602             if (0) {
7603             }
7604 707         37545  
7605 0         0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> @{[Ekps9566::PREMATCH()]}
7606 0         0 elsif ($string =~ /\G ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH \b | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) /oxmsgc) {
7607             $e_string .= q{Ekps9566::PREMATCH()};
7608             $slash = 'div';
7609             }
7610              
7611 0         0 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> @{[Ekps9566::MATCH()]}
7612 0         0 elsif ($string =~ /\G ( \$& | \$\{&\} | \$ (?>\s*) MATCH \b | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) /oxmsgc) {
7613             $e_string .= q{Ekps9566::MATCH()};
7614             $slash = 'div';
7615             }
7616              
7617 0         0 # $', ${'} --> $', ${'}
7618 0         0 elsif ($string =~ /\G ( \$' | \$\{'\} ) /oxmsgc) {
7619             $e_string .= $1;
7620             $slash = 'div';
7621             }
7622              
7623 0         0 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> @{[Ekps9566::POSTMATCH()]}
7624 0         0 elsif ($string =~ /\G ( \$ (?>\s*) POSTMATCH \b | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) /oxmsgc) {
7625             $e_string .= q{Ekps9566::POSTMATCH()};
7626             $slash = 'div';
7627             }
7628              
7629 0         0 # bareword
7630 0         0 elsif ($string =~ /\G ( \{ (?>\s*) (?: tr | index | rindex | reverse ) (?>\s*) \} ) /oxmsgc) {
7631             $e_string .= $1;
7632             $slash = 'div';
7633             }
7634              
7635 0         0 # $0 --> $0
7636 0         0 elsif ($string =~ /\G ( \$ 0 ) /oxmsgc) {
7637             $e_string .= $1;
7638             $slash = 'div';
7639 0         0 }
7640 0         0 elsif ($string =~ /\G ( \$ \{ (?>\s*) 0 (?>\s*) \} ) /oxmsgc) {
7641             $e_string .= $1;
7642             $slash = 'div';
7643             }
7644              
7645 0         0 # $$ --> $$
7646 0         0 elsif ($string =~ /\G ( \$ \$ ) (?![\w\{]) /oxmsgc) {
7647             $e_string .= $1;
7648             $slash = 'div';
7649             }
7650              
7651             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
7652 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
7653 0         0 elsif ($string =~ /\G \$ ((?>[1-9][0-9]*)) /oxmsgc) {
7654             $e_string .= e_capture($1);
7655             $slash = 'div';
7656 0         0 }
7657 0         0 elsif ($string =~ /\G \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} /oxmsgc) {
7658             $e_string .= e_capture($1);
7659             $slash = 'div';
7660             }
7661              
7662 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
7663 0         0 elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ .+? \] ) /oxmsgc) {
7664             $e_string .= e_capture($1.'->'.$2);
7665             $slash = 'div';
7666             }
7667              
7668 0         0 # $$foo{ ... } --> $ $foo->{ ... }
7669 0         0 elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ .+? \} ) /oxmsgc) {
7670             $e_string .= e_capture($1.'->'.$2);
7671             $slash = 'div';
7672             }
7673              
7674 0         0 # $$foo
7675 0         0 elsif ($string =~ /\G \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) /oxmsgc) {
7676             $e_string .= e_capture($1);
7677             $slash = 'div';
7678             }
7679              
7680 0         0 # ${ foo }
7681 0         0 elsif ($string =~ /\G \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} /oxmsgc) {
7682             $e_string .= '${' . $1 . '}';
7683             $slash = 'div';
7684             }
7685              
7686 0         0 # ${ ... }
7687 3         15 elsif ($string =~ /\G \$ (?>\s*) \{ (?>\s*) ( $qq_brace ) (?>\s*) \} /oxmsgc) {
7688             $e_string .= e_capture($1);
7689             $slash = 'div';
7690             }
7691              
7692             # variable or function
7693 3         16 # $ @ % & * $ #
7694 0         0 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) {
7695             $e_string .= $1;
7696             $slash = 'div';
7697             }
7698             # $ $ $ $ $ $ $ $ $ $ $ $ $ $
7699 0         0 # $ @ # \ ' " / ? ( ) [ ] < >
7700 0         0 elsif ($string =~ /\G ( \$[\$\@\#\\\'\"\/\?\(\)\[\]\<\>] ) /oxmsgc) {
7701             $e_string .= $1;
7702             $slash = 'div';
7703             }
7704              
7705 0         0 # subroutines of package Ekps9566
  0         0  
7706 0         0 elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
7707 0         0 (?>\s*) (\") ((?:$qq_char)+?) (\") /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_qq('', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7708 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\#) ((?:$qq_char)+?) (\#) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7709 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\() ((?:$qq_paren)+?) (\)) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7710 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\{) ((?:$qq_brace)+?) (\}) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7711 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\[) ((?:$qq_bracket)+?) (\]) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7712             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\<) ((?:$qq_angle)+?) (\>) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
7713             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) qq (?>\s*) (\S) ((?:$qq_char)+?) (\2) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_qq('qq',$2,$4,$3) . ")"; $slash = 'm//'; }
7714 0         0  
  0         0  
7715 0         0 elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+))
  0         0  
7716 0         0 (?>\s*) (\') ((?:\\\'|\\\\|$q_char)+?) (\') /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_q ('', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7717 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\#) ((?:\\\#|\\\\|$q_char)+?) (\#) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7718 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\() ((?:\\\)|\\\\|$q_paren)+?) (\)) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7719 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\{) ((?:\\\}|\\\\|$q_brace)+?) (\}) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7720 0         0 elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\[) ((?:\\\]|\\\\|$q_bracket)+?) (\]) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
  0         0  
7721             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\<) ((?:\\\>|\\\\|$q_angle)+?) (\>) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
7722             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) q (?>\s*) (\S) ((?:\\\2|\\\\|$q_char)+?) (\2) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1)," . e_q ('q', $2,$4,$3) . ")"; $slash = 'm//'; }
7723 0         0  
  0         0  
7724 0         0 elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) (\$ (?> \w+ (?: ::\w+)*) (?: (?: ->)? (?: [\$\@\%\&\*]\* | \$\#\* | \( (?:$qq_paren)*? \) | [\@\%\*]? \{ (?:$qq_brace)+? \} | [\@\%]? \[ (?:$qq_bracket)+? \] ) )*) /oxgc)
  0         0  
7725 0         0 { $e_string .= "Ekps9566::filetest(qw($1),$2)"; $slash = 'm//'; }
  0         0  
7726 0         0 elsif ($string =~ /\G (-[rwxoRWXOezfdlpSbcugkTB] (?>(?:\s+ -[rwxoRWXOezfdlpSbcugkTB])+)) \( ((?:$qq_paren)*?) \) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1),$2)"; $slash = 'm//'; }
  0         0  
7727             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) (?= [a-z]+) /oxgc) { $e_string .= "Ekps9566::filetest qw($1),"; $slash = 'm//'; }
7728             elsif ($string =~ /\G ((?:-[rwxoRWXOezfdlpSbcugkTB](?>\s+)){2,}) ((?>\w+)) /oxgc) { $e_string .= "Ekps9566::filetest(qw($1),$2)"; $slash = 'm//'; }
7729              
7730 0         0 # qq//
7731 0 0       0 elsif ($string =~ /\G \b (qq) \b /oxgc) {
7732 0         0 my $ope = $1;
7733             if ($string =~ /\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qq# #
7734             $e_string .= e_qq($ope,$1,$3,$2);
7735 0         0 }
7736 0         0 else {
7737 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
7738 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
7739 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
7740 0         0 elsif ($string =~ /\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq ( )
  0         0  
7741 0         0 elsif ($string =~ /\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq { }
  0         0  
7742 0         0 elsif ($string =~ /\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq [ ]
  0         0  
7743             elsif ($string =~ /\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq < >
7744 0         0 elsif ($string =~ /\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qq * *
7745             }
7746             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7747             }
7748             }
7749              
7750 0         0 # qx//
7751 0 0       0 elsif ($string =~ /\G \b (qx) \b /oxgc) {
7752 0         0 my $ope = $1;
7753             if ($string =~ /\G (\#) ((?:$qq_char)*?) (\#) /oxgc) { # qx# #
7754             $e_string .= e_qq($ope,$1,$3,$2);
7755 0         0 }
7756 0         0 else {
7757 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
    0          
7758 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
7759 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
7760 0         0 elsif ($string =~ /\G (\() ((?:$qq_paren)*?) (\)) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx ( )
  0         0  
7761 0         0 elsif ($string =~ /\G (\{) ((?:$qq_brace)*?) (\}) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx { }
  0         0  
7762 0         0 elsif ($string =~ /\G (\[) ((?:$qq_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx [ ]
  0         0  
7763 0         0 elsif ($string =~ /\G (\<) ((?:$qq_angle)*?) (\>) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx < >
  0         0  
7764             elsif ($string =~ /\G (\') ((?:$qq_char)*?) (\') /oxgc) { $e_string .= $e . e_q ($ope,$1,$3,$2); next E_STRING_LOOP; } # qx ' '
7765 0         0 elsif ($string =~ /\G (\S) ((?:$qq_char)*?) (\1) /oxgc) { $e_string .= $e . e_qq($ope,$1,$3,$2); next E_STRING_LOOP; } # qx * *
7766             }
7767             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7768             }
7769             }
7770              
7771 0         0 # q//
7772 0 0       0 elsif ($string =~ /\G \b (q) \b /oxgc) {
7773 0         0 my $ope = $1;
7774             if ($string =~ /\G (\#) ((?:\\\#|\\\\|$q_char)*?) (\#) /oxgc) { # q# #
7775             $e_string .= e_q($ope,$1,$3,$2);
7776 0         0 }
7777 0         0 else {
7778 0 0       0 my $e = '';
  0 0       0  
    0          
    0          
    0          
    0          
7779 0         0 while ($string !~ /\G \z/oxgc) {
  0         0  
7780 0         0 if ($string =~ /\G ((?>\s+)|\#.*) /oxgc) { $e .= $1; }
  0         0  
7781 0         0 elsif ($string =~ /\G (\() ((?:\\\\|\\\)|\\\(|$q_paren)*?) (\)) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q ( )
  0         0  
7782 0         0 elsif ($string =~ /\G (\{) ((?:\\\\|\\\}|\\\{|$q_brace)*?) (\}) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q { }
  0         0  
7783 0         0 elsif ($string =~ /\G (\[) ((?:\\\\|\\\]|\\\[|$q_bracket)*?) (\]) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q [ ]
  0         0  
7784             elsif ($string =~ /\G (\<) ((?:\\\\|\\\>|\\\<|$q_angle)*?) (\>) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q < >
7785 0         0 elsif ($string =~ /\G (\S) ((?:\\\\|\\\1| $q_char)*?) (\1) /oxgc) { $e_string .= $e . e_q($ope,$1,$3,$2); next E_STRING_LOOP; } # q * *
7786             }
7787             die __FILE__, ": Can't find string terminator anywhere before EOF\n";
7788             }
7789             }
7790 0         0  
7791             # ''
7792             elsif ($string =~ /\G (?
7793 44         165  
7794             # ""
7795             elsif ($string =~ /\G (\") ((?:$qq_char)*?) (\") /oxgc) { $e_string .= e_qq('',$1,$3,$2); }
7796 6         19  
7797             # ``
7798             elsif ($string =~ /\G (\`) ((?:$qq_char)*?) (\`) /oxgc) { $e_string .= e_qq('',$1,$3,$2); }
7799 0         0  
7800             # other any character
7801             elsif ($string =~ /\G ($q_char) /oxgc) { $e_string .= $1; }
7802              
7803 654         1970 # system error
7804             else {
7805             die __FILE__, ": Oops, this shouldn't happen!\n";
7806             }
7807 0         0 }
7808              
7809             return $e_string;
7810             }
7811              
7812             #
7813             # character class
7814 82     5350 0 347 #
7815             sub character_class {
7816 5350 100       10292 my($char,$modifier) = @_;
7817 5350 100       8257  
7818 115         233 if ($char eq '.') {
7819             if ($modifier =~ /s/) {
7820             return '${Ekps9566::dot_s}';
7821 23         64 }
7822             else {
7823             return '${Ekps9566::dot}';
7824             }
7825 92         199 }
7826             else {
7827             return Ekps9566::classic_character_class($char);
7828             }
7829             }
7830              
7831             #
7832             # escape capture ($1, $2, $3, ...)
7833             #
7834 5235     637 0 9550 sub e_capture {
7835 637         2689  
7836             return join '', '${Ekps9566::capture(', $_[0], ')}';
7837             return join '', '${', $_[0], '}';
7838             }
7839              
7840             #
7841             # escape transliteration (tr/// or y///)
7842 0     11 0 0 #
7843 11         51 sub e_tr {
7844 11   100     22 my($variable,$charclass,$e,$charclass2,$modifier) = @_;
7845             my $e_tr = '';
7846 11         29 $modifier ||= '';
7847              
7848             $slash = 'div';
7849 11         15  
7850             # quote character class 1
7851             $charclass = q_tr($charclass);
7852 11         37  
7853             # quote character class 2
7854             $charclass2 = q_tr($charclass2);
7855 11 50       35  
7856 11 0       34 # /b /B modifier
7857 0         0 if ($modifier =~ tr/bB//d) {
7858             if ($variable eq '') {
7859             $e_tr = qq{tr$charclass$e$charclass2$modifier};
7860 0         0 }
7861             else {
7862             $e_tr = qq{$variable${bind_operator}tr$charclass$e$charclass2$modifier};
7863             }
7864 0 100       0 }
7865 11         20 else {
7866             if ($variable eq '') {
7867             $e_tr = qq{Ekps9566::tr(\$_,' =~ ',$charclass,$e$charclass2,'$modifier')};
7868 2         7 }
7869             else {
7870             $e_tr = qq{Ekps9566::tr($variable,'$bind_operator',$charclass,$e$charclass2,'$modifier')};
7871             }
7872             }
7873 9         27  
7874 11         17 # clear tr/// variable
7875             $tr_variable = '';
7876 11         14 $bind_operator = '';
7877              
7878             return $e_tr;
7879             }
7880              
7881             #
7882             # quote for escape transliteration (tr/// or y///)
7883 11     22 0 65 #
7884             sub q_tr {
7885             my($charclass) = @_;
7886 22 50       36  
    0          
    0          
    0          
    0          
    0          
7887 22         43 # quote character class
7888             if ($charclass !~ /'/oxms) {
7889             return e_q('', "'", "'", $charclass); # --> q' '
7890 22         37 }
7891             elsif ($charclass !~ /\//oxms) {
7892             return e_q('q', '/', '/', $charclass); # --> q/ /
7893 0         0 }
7894             elsif ($charclass !~ /\#/oxms) {
7895             return e_q('q', '#', '#', $charclass); # --> q# #
7896 0         0 }
7897             elsif ($charclass !~ /[\<\>]/oxms) {
7898             return e_q('q', '<', '>', $charclass); # --> q< >
7899 0         0 }
7900             elsif ($charclass !~ /[\(\)]/oxms) {
7901             return e_q('q', '(', ')', $charclass); # --> q( )
7902 0         0 }
7903             elsif ($charclass !~ /[\{\}]/oxms) {
7904             return e_q('q', '{', '}', $charclass); # --> q{ }
7905 0         0 }
7906 0 0       0 else {
7907 0         0 for my $char (qw( ! " $ % & * + . : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
7908             if ($charclass !~ /\Q$char\E/xms) {
7909             return e_q('q', $char, $char, $charclass);
7910             }
7911             }
7912 0         0 }
7913              
7914             return e_q('q', '{', '}', $charclass);
7915             }
7916              
7917             #
7918             # escape q string (q//, '')
7919 0     3951 0 0 #
7920             sub e_q {
7921 3951         10149 my($ope,$delimiter,$end_delimiter,$string) = @_;
7922              
7923 3951         5934 $slash = 'div';
7924 3951         24922  
7925             my @char = $string =~ / \G (?>$q_char) /oxmsg;
7926             for (my $i=0; $i <= $#char; $i++) {
7927 3951 100 100     10977  
    100 100        
7928 21189         122129 # escape last octet of multiple-octet
7929             if ($char[$i] =~ /\A ([\x80-\xFF].*) (\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
7930             $char[$i] = $1 . '\\' . $2;
7931 1         5 }
7932             elsif (defined($char[$i+1]) and ($char[$i+1] eq '\\') and ($char[$i] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
7933             $char[$i] = $1 . '\\' . $2;
7934 22 100 100     95 }
7935 3951         14814 }
7936             if (defined($char[-1]) and ($char[-1] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
7937             $char[-1] = $1 . '\\' . $2;
7938 204         643 }
7939 3951         20645  
7940             return join '', $ope, $delimiter, @char, $end_delimiter;
7941             return join '', $ope, $delimiter, $string, $end_delimiter;
7942             }
7943              
7944             #
7945             # escape qq string (qq//, "", qx//, ``)
7946 0     9508 0 0 #
7947             sub e_qq {
7948 9508         21562 my($ope,$delimiter,$end_delimiter,$string) = @_;
7949              
7950 9508         13140 $slash = 'div';
7951 9508         11047  
7952             my $left_e = 0;
7953             my $right_e = 0;
7954 9508         10484  
7955             # split regexp
7956             my @char = $string =~ /\G((?>
7957             [^\x81-\xFE\\\$]|[\x81-\xFE][\x00-\xFF] |
7958             \\x\{ (?>[0-9A-Fa-f]+) \} |
7959             \\o\{ (?>[0-7]+) \} |
7960             \\N\{ (?>[^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} |
7961             \\ $q_char |
7962             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
7963             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
7964             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
7965             \$ (?>\s* [0-9]+) |
7966             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
7967             \$ \$ (?![\w\{]) |
7968             \$ (?>\s*) \$ (?>\s*) $qq_variable |
7969             $q_char
7970 9508         349032 ))/oxmsg;
7971              
7972             for (my $i=0; $i <= $#char; $i++) {
7973 9508 50 66     42584  
    50 33        
    100          
    100          
    50          
7974 307504         976601 # "\L\u" --> "\u\L"
7975             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
7976             @char[$i,$i+1] = @char[$i+1,$i];
7977             }
7978              
7979 0         0 # "\U\l" --> "\l\U"
7980             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
7981             @char[$i,$i+1] = @char[$i+1,$i];
7982             }
7983              
7984 0         0 # octal escape sequence
7985             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
7986             $char[$i] = Ekps9566::octchr($1);
7987             }
7988              
7989 1         4 # hexadecimal escape sequence
7990             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
7991             $char[$i] = Ekps9566::hexchr($1);
7992             }
7993              
7994 1         4 # \N{CHARNAME} --> N{CHARNAME}
7995             elsif ($char[$i] =~ /\A \\ ( N\{ ([^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} ) \z/oxms) {
7996             $char[$i] = $1;
7997 0 100       0 }
    100          
    50          
    50          
    50          
    100          
    100          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
7998              
7999             if (0) {
8000             }
8001              
8002             # escape last octet of multiple-octet
8003 307504         2782722 # my $metachar = qr/[\@\\\|]/oxms; # '|' is for qx//, ``, open(), and system()
8004 0         0 # variable $delimiter and $end_delimiter can be ''
8005             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\@\\\|$delimiter$end_delimiter]) \z/xms) {
8006             $char[$i] = $1 . '\\' . $2;
8007             }
8008              
8009             # \F
8010             #
8011             # P.69 Table 2-6. Translation escapes
8012             # in Chapter 2: Bits and Pieces
8013             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
8014             # (and so on)
8015              
8016 1342 50       4624 # \u \l \U \L \F \Q \E
8017 647         1577 elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
8018             if ($right_e < $left_e) {
8019             $char[$i] = '\\' . $char[$i];
8020             }
8021             }
8022             elsif ($char[$i] eq '\u') {
8023              
8024             # "STRING @{[ LIST EXPR ]} MORE STRING"
8025              
8026             # P.257 Other Tricks You Can Do with Hard References
8027             # in Chapter 8: References
8028             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
8029              
8030             # P.353 Other Tricks You Can Do with Hard References
8031             # in Chapter 8: References
8032             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
8033              
8034 0         0 # (and so on)
8035 0         0  
8036             $char[$i] = '@{[Ekps9566::ucfirst qq<';
8037             $left_e++;
8038 0         0 }
8039 0         0 elsif ($char[$i] eq '\l') {
8040             $char[$i] = '@{[Ekps9566::lcfirst qq<';
8041             $left_e++;
8042 0         0 }
8043 0         0 elsif ($char[$i] eq '\U') {
8044             $char[$i] = '@{[Ekps9566::uc qq<';
8045             $left_e++;
8046 0         0 }
8047 6         10 elsif ($char[$i] eq '\L') {
8048             $char[$i] = '@{[Ekps9566::lc qq<';
8049             $left_e++;
8050 6         11 }
8051 9         22 elsif ($char[$i] eq '\F') {
8052             $char[$i] = '@{[Ekps9566::fc qq<';
8053             $left_e++;
8054 9         19 }
8055 0         0 elsif ($char[$i] eq '\Q') {
8056             $char[$i] = '@{[CORE::quotemeta qq<';
8057             $left_e++;
8058 0 50       0 }
8059 12         26 elsif ($char[$i] eq '\E') {
8060 12         16 if ($right_e < $left_e) {
8061             $char[$i] = '>]}';
8062             $right_e++;
8063 12         28 }
8064             else {
8065             $char[$i] = '';
8066             }
8067 0         0 }
8068 0 0       0 elsif ($char[$i] eq '\Q') {
8069 0         0 while (1) {
8070             if (++$i > $#char) {
8071 0 0       0 last;
8072 0         0 }
8073             if ($char[$i] eq '\E') {
8074             last;
8075             }
8076             }
8077             }
8078             elsif ($char[$i] eq '\E') {
8079             }
8080              
8081             # $0 --> $0
8082             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
8083             }
8084             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
8085             }
8086              
8087             # $$ --> $$
8088             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
8089             }
8090              
8091             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
8092 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
8093             elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
8094             $char[$i] = e_capture($1);
8095 415         1278 }
8096             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
8097             $char[$i] = e_capture($1);
8098             }
8099              
8100 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
8101             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
8102             $char[$i] = e_capture($1.'->'.$2);
8103             }
8104              
8105 0         0 # $$foo{ ... } --> $ $foo->{ ... }
8106             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
8107             $char[$i] = e_capture($1.'->'.$2);
8108             }
8109              
8110 0         0 # $$foo
8111             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
8112             $char[$i] = e_capture($1);
8113             }
8114              
8115 0         0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ekps9566::PREMATCH()
8116             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
8117             $char[$i] = '@{[Ekps9566::PREMATCH()]}';
8118             }
8119              
8120 44         133 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ekps9566::MATCH()
8121             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
8122             $char[$i] = '@{[Ekps9566::MATCH()]}';
8123             }
8124              
8125 45         145 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ekps9566::POSTMATCH()
8126             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
8127             $char[$i] = '@{[Ekps9566::POSTMATCH()]}';
8128             }
8129              
8130             # ${ foo } --> ${ foo }
8131             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ (?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* ) \} \z/oxms) {
8132             }
8133              
8134 33         120 # ${ ... }
8135             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
8136             $char[$i] = e_capture($1);
8137             }
8138             }
8139 0 100       0  
8140 9508         19899 # return string
8141             if ($left_e > $right_e) {
8142 3         18 return join '', $ope, $delimiter, @char, '>]}' x ($left_e - $right_e), $end_delimiter;
8143             }
8144             return join '', $ope, $delimiter, @char, $end_delimiter;
8145             }
8146              
8147             #
8148             # escape qw string (qw//)
8149 9505     34 0 76687 #
8150             sub e_qw {
8151 34         197 my($ope,$delimiter,$end_delimiter,$string) = @_;
8152              
8153             $slash = 'div';
8154 34         88  
  34         377  
8155 621 50       1201 # choice again delimiter
    0          
    0          
    0          
    0          
8156 34         212 my %octet = map {$_ => 1} ($string =~ /\G ([\x00-\xFF]) /oxmsg);
8157             if (not $octet{$end_delimiter}) {
8158             return join '', $ope, $delimiter, $string, $end_delimiter;
8159 34         272 }
8160             elsif (not $octet{')'}) {
8161             return join '', $ope, '(', $string, ')';
8162 0         0 }
8163             elsif (not $octet{'}'}) {
8164             return join '', $ope, '{', $string, '}';
8165 0         0 }
8166             elsif (not $octet{']'}) {
8167             return join '', $ope, '[', $string, ']';
8168 0         0 }
8169             elsif (not $octet{'>'}) {
8170             return join '', $ope, '<', $string, '>';
8171 0         0 }
8172 0 0       0 else {
8173 0         0 for my $char (qw( ! " $ % & * + - . / : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8174             if (not $octet{$char}) {
8175             return join '', $ope, $char, $string, $char;
8176             }
8177             }
8178             }
8179 0         0  
8180 0         0 # qw/AAA BBB C'CC/ --> ('AAA', 'BBB', 'C\'CC')
8181 0         0 my @string = CORE::split(/\s+/, $string);
8182 0         0 for my $string (@string) {
8183 0 0       0 my @octet = $string =~ /\G ([\x00-\xFF]) /oxmsg;
8184 0         0 for my $octet (@octet) {
8185             if ($octet =~ /\A (['\\]) \z/oxms) {
8186             $octet = '\\' . $1;
8187 0         0 }
8188             }
8189 0         0 $string = join '', @octet;
  0         0  
8190             }
8191             return join '', '(', (join ', ', map { "'$_'" } @string), ')';
8192             }
8193              
8194             #
8195             # escape here document (<<"HEREDOC", <
8196 0     108 0 0 #
8197             sub e_heredoc {
8198 108         295 my($string) = @_;
8199              
8200 108         185 $slash = 'm//';
8201              
8202 108         414 my $metachar = qr/[\@\\|]/oxms; # '|' is for <<`HEREDOC`
8203 108         192  
8204             my $left_e = 0;
8205             my $right_e = 0;
8206 108         156  
8207             # split regexp
8208             my @char = $string =~ /\G((?>
8209             [^\x81-\xFE\\\$]|[\x81-\xFE][\x00-\xFF] |
8210             \\x\{ (?>[0-9A-Fa-f]+) \} |
8211             \\o\{ (?>[0-7]+) \} |
8212             \\N\{ (?>[^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} |
8213             \\ $q_char |
8214             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
8215             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
8216             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
8217             \$ (?>\s* [0-9]+) |
8218             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
8219             \$ \$ (?![\w\{]) |
8220             \$ (?>\s*) \$ (?>\s*) $qq_variable |
8221             $q_char
8222 108         10953 ))/oxmsg;
8223              
8224             for (my $i=0; $i <= $#char; $i++) {
8225 108 50 66     569  
    50 33        
    100          
    100          
    50          
8226 3303         10916 # "\L\u" --> "\u\L"
8227             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
8228             @char[$i,$i+1] = @char[$i+1,$i];
8229             }
8230              
8231 0         0 # "\U\l" --> "\l\U"
8232             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
8233             @char[$i,$i+1] = @char[$i+1,$i];
8234             }
8235              
8236 0         0 # octal escape sequence
8237             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
8238             $char[$i] = Ekps9566::octchr($1);
8239             }
8240              
8241 1         4 # hexadecimal escape sequence
8242             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
8243             $char[$i] = Ekps9566::hexchr($1);
8244             }
8245              
8246 1         3 # \N{CHARNAME} --> N{CHARNAME}
8247             elsif ($char[$i] =~ /\A \\ ( N\{ ([^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} ) \z/oxms) {
8248             $char[$i] = $1;
8249 0 100       0 }
    100          
    50          
    50          
    50          
    100          
    50          
    50          
    100          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    100          
    100          
    50          
    50          
8250              
8251             if (0) {
8252             }
8253 3303         29084  
8254 0         0 # escape character
8255             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ($metachar) \z/oxms) {
8256             $char[$i] = $1 . '\\' . $2;
8257             }
8258              
8259 57 50       242 # \u \l \U \L \F \Q \E
8260 72         139 elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
8261             if ($right_e < $left_e) {
8262             $char[$i] = '\\' . $char[$i];
8263             }
8264 0         0 }
8265 0         0 elsif ($char[$i] eq '\u') {
8266             $char[$i] = '@{[Ekps9566::ucfirst qq<';
8267             $left_e++;
8268 0         0 }
8269 0         0 elsif ($char[$i] eq '\l') {
8270             $char[$i] = '@{[Ekps9566::lcfirst qq<';
8271             $left_e++;
8272 0         0 }
8273 0         0 elsif ($char[$i] eq '\U') {
8274             $char[$i] = '@{[Ekps9566::uc qq<';
8275             $left_e++;
8276 0         0 }
8277 6         11 elsif ($char[$i] eq '\L') {
8278             $char[$i] = '@{[Ekps9566::lc qq<';
8279             $left_e++;
8280 6         8 }
8281 0         0 elsif ($char[$i] eq '\F') {
8282             $char[$i] = '@{[Ekps9566::fc qq<';
8283             $left_e++;
8284 0         0 }
8285 0         0 elsif ($char[$i] eq '\Q') {
8286             $char[$i] = '@{[CORE::quotemeta qq<';
8287             $left_e++;
8288 0 50       0 }
8289 3         7 elsif ($char[$i] eq '\E') {
8290 3         7 if ($right_e < $left_e) {
8291             $char[$i] = '>]}';
8292             $right_e++;
8293 3         4 }
8294             else {
8295             $char[$i] = '';
8296             }
8297 0         0 }
8298 0 0       0 elsif ($char[$i] eq '\Q') {
8299 0         0 while (1) {
8300             if (++$i > $#char) {
8301 0 0       0 last;
8302 0         0 }
8303             if ($char[$i] eq '\E') {
8304             last;
8305             }
8306             }
8307             }
8308             elsif ($char[$i] eq '\E') {
8309             }
8310              
8311             # $0 --> $0
8312             elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
8313             }
8314             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
8315             }
8316              
8317             # $$ --> $$
8318             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
8319             }
8320              
8321             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
8322 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
8323             elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
8324             $char[$i] = e_capture($1);
8325 0         0 }
8326             elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
8327             $char[$i] = e_capture($1);
8328             }
8329              
8330 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
8331             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
8332             $char[$i] = e_capture($1.'->'.$2);
8333             }
8334              
8335 0         0 # $$foo{ ... } --> $ $foo->{ ... }
8336             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
8337             $char[$i] = e_capture($1.'->'.$2);
8338             }
8339              
8340 0         0 # $$foo
8341             elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
8342             $char[$i] = e_capture($1);
8343             }
8344              
8345 0         0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ekps9566::PREMATCH()
8346             elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
8347             $char[$i] = '@{[Ekps9566::PREMATCH()]}';
8348             }
8349              
8350 8         48 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ekps9566::MATCH()
8351             elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
8352             $char[$i] = '@{[Ekps9566::MATCH()]}';
8353             }
8354              
8355 8         48 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ekps9566::POSTMATCH()
8356             elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
8357             $char[$i] = '@{[Ekps9566::POSTMATCH()]}';
8358             }
8359              
8360             # ${ foo } --> ${ foo }
8361             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ (?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* ) \} \z/oxms) {
8362             }
8363              
8364 6         36 # ${ ... }
8365             elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
8366             $char[$i] = e_capture($1);
8367             }
8368             }
8369 0 100       0  
8370 108         264 # return string
8371             if ($left_e > $right_e) {
8372 3         25 return join '', @char, '>]}' x ($left_e - $right_e);
8373             }
8374             return join '', @char;
8375             }
8376              
8377             #
8378             # escape regexp (m//, qr//)
8379 105     1833 0 893 #
8380 1833   100     7722 sub e_qr {
8381             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
8382 1833         6333 $modifier ||= '';
8383 1833 50       3562  
8384 1833         4449 $modifier =~ tr/p//d;
8385 0         0 if ($modifier =~ /([adlu])/oxms) {
8386 0 0       0 my $line = 0;
8387 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
8388 0         0 if ($filename ne __FILE__) {
8389             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
8390             last;
8391 0         0 }
8392             }
8393             die qq{Unsupported modifier "$1" used at line $line.\n};
8394 0         0 }
8395              
8396             $slash = 'div';
8397 1833 100       3007  
    100          
8398 1833         5353 # literal null string pattern
8399 8         9 if ($string eq '') {
8400 8         9 $modifier =~ tr/bB//d;
8401             $modifier =~ tr/i//d;
8402             return join '', $ope, $delimiter, $end_delimiter, $modifier;
8403             }
8404              
8405             # /b /B modifier
8406             elsif ($modifier =~ tr/bB//d) {
8407 8 50       39  
8408 240         580 # choice again delimiter
8409 0         0 if ($delimiter =~ / [\@:] /oxms) {
  0         0  
8410 0 0       0 my @char = $string =~ /\G ([\x00-\xFF]) /oxmsg;
    0          
    0          
    0          
8411 0         0 my %octet = map {$_ => 1} @char;
8412 0         0 if (not $octet{')'}) {
8413             $delimiter = '(';
8414             $end_delimiter = ')';
8415 0         0 }
8416 0         0 elsif (not $octet{'}'}) {
8417             $delimiter = '{';
8418             $end_delimiter = '}';
8419 0         0 }
8420 0         0 elsif (not $octet{']'}) {
8421             $delimiter = '[';
8422             $end_delimiter = ']';
8423 0         0 }
8424 0         0 elsif (not $octet{'>'}) {
8425             $delimiter = '<';
8426             $end_delimiter = '>';
8427 0         0 }
8428 0 0       0 else {
8429 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8430 0         0 if (not $octet{$char}) {
8431 0         0 $delimiter = $char;
8432             $end_delimiter = $char;
8433             last;
8434             }
8435             }
8436             }
8437 0 100 100     0 }
8438 240         1203  
8439             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
8440             return join '', $ope, $delimiter, $string, $matched, $end_delimiter, $modifier;
8441 90         491 }
8442             else {
8443             return join '', $ope, $delimiter, '(?:', $string, ')', $matched, $end_delimiter, $modifier;
8444             }
8445 150 100       882 }
8446 1585         3925  
8447             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
8448             my $metachar = qr/[\@\\|[\]{^]/oxms;
8449 1585         6089  
8450             # split regexp
8451             my @char = $string =~ /\G((?>
8452             [^\x81-\xFE\\\$\@\[\(]|[\x81-\xFE][\x00-\xFF] |
8453             \\x (?>[0-9A-Fa-f]{1,2}) |
8454             \\ (?>[0-7]{2,3}) |
8455             \\c [\x40-\x5F] |
8456             \\x\{ (?>[0-9A-Fa-f]+) \} |
8457             \\o\{ (?>[0-7]+) \} |
8458             \\[bBNpP]\{ (?>[^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} |
8459             \\ $q_char |
8460             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
8461             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
8462             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
8463             [\$\@] $qq_variable |
8464             \$ (?>\s* [0-9]+) |
8465             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
8466             \$ \$ (?![\w\{]) |
8467             \$ (?>\s*) \$ (?>\s*) $qq_variable |
8468             \[\^ |
8469             \[\: (?>[a-z]+) :\] |
8470             \[\:\^ (?>[a-z]+) :\] |
8471             \(\? |
8472             $q_char
8473             ))/oxmsg;
8474 1585 50       133948  
8475 1585         7085 # choice again delimiter
  0         0  
8476 0 0       0 if ($delimiter =~ / [\@:] /oxms) {
    0          
    0          
    0          
8477 0         0 my %octet = map {$_ => 1} @char;
8478 0         0 if (not $octet{')'}) {
8479             $delimiter = '(';
8480             $end_delimiter = ')';
8481 0         0 }
8482 0         0 elsif (not $octet{'}'}) {
8483             $delimiter = '{';
8484             $end_delimiter = '}';
8485 0         0 }
8486 0         0 elsif (not $octet{']'}) {
8487             $delimiter = '[';
8488             $end_delimiter = ']';
8489 0         0 }
8490 0         0 elsif (not $octet{'>'}) {
8491             $delimiter = '<';
8492             $end_delimiter = '>';
8493 0         0 }
8494 0 0       0 else {
8495 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8496 0         0 if (not $octet{$char}) {
8497 0         0 $delimiter = $char;
8498             $end_delimiter = $char;
8499             last;
8500             }
8501             }
8502             }
8503 0         0 }
8504 1585         2743  
8505 1585         2598 my $left_e = 0;
8506             my $right_e = 0;
8507             for (my $i=0; $i <= $#char; $i++) {
8508 1585 50 66     4091  
    50 66        
    100          
    100          
    100          
    100          
8509 5430         27498 # "\L\u" --> "\u\L"
8510             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
8511             @char[$i,$i+1] = @char[$i+1,$i];
8512             }
8513              
8514 0         0 # "\U\l" --> "\l\U"
8515             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
8516             @char[$i,$i+1] = @char[$i+1,$i];
8517             }
8518              
8519 0         0 # octal escape sequence
8520             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
8521             $char[$i] = Ekps9566::octchr($1);
8522             }
8523              
8524 1         14 # hexadecimal escape sequence
8525             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
8526             $char[$i] = Ekps9566::hexchr($1);
8527             }
8528              
8529             # \b{...} --> b\{...}
8530             # \B{...} --> B\{...}
8531             # \N{CHARNAME} --> N\{CHARNAME}
8532             # \p{PROPERTY} --> p\{PROPERTY}
8533 1         4 # \P{PROPERTY} --> P\{PROPERTY}
8534             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} ) \z/oxms) {
8535             $char[$i] = $1 . '\\' . $2;
8536             }
8537              
8538 6         20 # \p, \P, \X --> p, P, X
8539             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
8540             $char[$i] = $1;
8541 4 100 100     12 }
    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          
8542              
8543             if (0) {
8544             }
8545 5430         38401  
8546 0         0 # escape last octet of multiple-octet
8547             elsif ($char[$i] =~ /\A \\? ([\x80-\xFF].*) ($metachar|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
8548             $char[$i] = $1 . '\\' . $2;
8549             }
8550              
8551 77 50 33     329 # join separated multiple-octet
    50 33        
    50 33        
      33        
      66        
      33        
8552 6         206 elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
8553             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)) {
8554             $char[$i] .= join '', splice @char, $i+1, 3;
8555 0         0 }
8556             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)) {
8557             $char[$i] .= join '', splice @char, $i+1, 2;
8558 0         0 }
8559             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)) {
8560             $char[$i] .= join '', splice @char, $i+1, 1;
8561             }
8562             }
8563              
8564 0         0 # open character class [...]
8565             elsif ($char[$i] eq '[') {
8566             my $left = $i;
8567              
8568             # [] make die "Unmatched [] in regexp ...\n"
8569 586 100       918 # (and so on)
8570 586         1534  
8571             if ($char[$i+1] eq ']') {
8572             $i++;
8573 3         6 }
8574 586 50       760  
8575 2583         3692 while (1) {
8576             if (++$i > $#char) {
8577 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
8578 2583         4033 }
8579             if ($char[$i] eq ']') {
8580             my $right = $i;
8581 586 100       745  
8582 586         3076 # [...]
  90         223  
8583             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
8584             splice @char, $left, $right-$left+1, sprintf(q{@{[Ekps9566::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
8585 270         481 }
8586             else {
8587             splice @char, $left, $right-$left+1, Ekps9566::charlist_qr(@char[$left+1..$right-1], $modifier);
8588 496         2063 }
8589 586         1446  
8590             $i = $left;
8591             last;
8592             }
8593             }
8594             }
8595              
8596 586         1661 # open character class [^...]
8597             elsif ($char[$i] eq '[^') {
8598             my $left = $i;
8599              
8600             # [^] make die "Unmatched [] in regexp ...\n"
8601 328 100       521 # (and so on)
8602 328         692  
8603             if ($char[$i+1] eq ']') {
8604             $i++;
8605 5         10 }
8606 328 50       399  
8607 1447         2025 while (1) {
8608             if (++$i > $#char) {
8609 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
8610 1447         2146 }
8611             if ($char[$i] eq ']') {
8612             my $right = $i;
8613 328 100       393  
8614 328         1566 # [^...]
  90         230  
8615             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
8616             splice @char, $left, $right-$left+1, sprintf(q{@{[Ekps9566::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
8617 270         473 }
8618             else {
8619             splice @char, $left, $right-$left+1, Ekps9566::charlist_not_qr(@char[$left+1..$right-1], $modifier);
8620 238         871 }
8621 328         606  
8622             $i = $left;
8623             last;
8624             }
8625             }
8626             }
8627              
8628 328         841 # rewrite character class or escape character
8629             elsif (my $char = character_class($char[$i],$modifier)) {
8630             $char[$i] = $char;
8631             }
8632              
8633 215 50       544 # /i modifier
8634 238         432 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ekps9566::uc($char[$i]) ne Ekps9566::fc($char[$i]))) {
8635             if (CORE::length(Ekps9566::fc($char[$i])) == 1) {
8636             $char[$i] = '[' . Ekps9566::uc($char[$i]) . Ekps9566::fc($char[$i]) . ']';
8637 238         434 }
8638             else {
8639             $char[$i] = '(?:' . Ekps9566::uc($char[$i]) . '|' . Ekps9566::fc($char[$i]) . ')';
8640             }
8641             }
8642              
8643 0 50       0 # \u \l \U \L \F \Q \E
8644 1         6 elsif ($char[$i] =~ /\A [<>] \z/oxms) {
8645             if ($right_e < $left_e) {
8646             $char[$i] = '\\' . $char[$i];
8647             }
8648 0         0 }
8649 0         0 elsif ($char[$i] eq '\u') {
8650             $char[$i] = '@{[Ekps9566::ucfirst qq<';
8651             $left_e++;
8652 0         0 }
8653 0         0 elsif ($char[$i] eq '\l') {
8654             $char[$i] = '@{[Ekps9566::lcfirst qq<';
8655             $left_e++;
8656 0         0 }
8657 1         3 elsif ($char[$i] eq '\U') {
8658             $char[$i] = '@{[Ekps9566::uc qq<';
8659             $left_e++;
8660 1         4 }
8661 1         3 elsif ($char[$i] eq '\L') {
8662             $char[$i] = '@{[Ekps9566::lc qq<';
8663             $left_e++;
8664 1         3 }
8665 9         19 elsif ($char[$i] eq '\F') {
8666             $char[$i] = '@{[Ekps9566::fc qq<';
8667             $left_e++;
8668 9         26 }
8669 22         40 elsif ($char[$i] eq '\Q') {
8670             $char[$i] = '@{[CORE::quotemeta qq<';
8671             $left_e++;
8672 22 50       54 }
8673 33         79 elsif ($char[$i] eq '\E') {
8674 33         50 if ($right_e < $left_e) {
8675             $char[$i] = '>]}';
8676             $right_e++;
8677 33         79 }
8678             else {
8679             $char[$i] = '';
8680             }
8681 0         0 }
8682 0 0       0 elsif ($char[$i] eq '\Q') {
8683 0         0 while (1) {
8684             if (++$i > $#char) {
8685 0 0       0 last;
8686 0         0 }
8687             if ($char[$i] eq '\E') {
8688             last;
8689             }
8690             }
8691             }
8692             elsif ($char[$i] eq '\E') {
8693             }
8694              
8695 0 0       0 # $0 --> $0
8696 0         0 elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
8697             if ($ignorecase) {
8698             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8699             }
8700 0 0       0 }
8701 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
8702             if ($ignorecase) {
8703             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8704             }
8705             }
8706              
8707             # $$ --> $$
8708             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
8709             }
8710              
8711             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
8712 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
8713 0 0       0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
8714 0         0 $char[$i] = e_capture($1);
8715             if ($ignorecase) {
8716             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8717             }
8718 0         0 }
8719 0 0       0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
8720 0         0 $char[$i] = e_capture($1);
8721             if ($ignorecase) {
8722             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8723             }
8724             }
8725              
8726 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
8727 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
8728 0         0 $char[$i] = e_capture($1.'->'.$2);
8729             if ($ignorecase) {
8730             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8731             }
8732             }
8733              
8734 0         0 # $$foo{ ... } --> $ $foo->{ ... }
8735 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
8736 0         0 $char[$i] = e_capture($1.'->'.$2);
8737             if ($ignorecase) {
8738             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8739             }
8740             }
8741              
8742 0         0 # $$foo
8743 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
8744 0         0 $char[$i] = e_capture($1);
8745             if ($ignorecase) {
8746             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8747             }
8748             }
8749              
8750 0 50       0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ekps9566::PREMATCH()
8751 8         25 elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
8752             if ($ignorecase) {
8753             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::PREMATCH())]}';
8754 0         0 }
8755             else {
8756             $char[$i] = '@{[Ekps9566::PREMATCH()]}';
8757             }
8758             }
8759              
8760 8 50       26 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ekps9566::MATCH()
8761 8         21 elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
8762             if ($ignorecase) {
8763             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::MATCH())]}';
8764 0         0 }
8765             else {
8766             $char[$i] = '@{[Ekps9566::MATCH()]}';
8767             }
8768             }
8769              
8770 8 50       26 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ekps9566::POSTMATCH()
8771 6         19 elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
8772             if ($ignorecase) {
8773             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::POSTMATCH())]}';
8774 0         0 }
8775             else {
8776             $char[$i] = '@{[Ekps9566::POSTMATCH()]}';
8777             }
8778             }
8779              
8780 6 0       24 # ${ foo }
8781 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
8782             if ($ignorecase) {
8783             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8784             }
8785             }
8786              
8787 0         0 # ${ ... }
8788 0 0       0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
8789 0         0 $char[$i] = e_capture($1);
8790             if ($ignorecase) {
8791             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8792             }
8793             }
8794              
8795 0         0 # $scalar or @array
8796 31 100       94 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
8797 31         112 $char[$i] = e_string($char[$i]);
8798             if ($ignorecase) {
8799             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
8800             }
8801             }
8802              
8803 4 100 66     16 # quote character before ? + * {
    50          
8804             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
8805             if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
8806 188         1494 }
8807 0 0       0 elsif (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
8808 0         0 my $char = $char[$i-1];
8809             if ($char[$i] eq '{') {
8810             die __FILE__, qq{: "MULTIBYTE{n}" should be "(MULTIBYTE){n}" in m?? (and shift \$1,\$2,\$3,...) ($char){n}\n};
8811 0         0 }
8812             else {
8813             die __FILE__, qq{: "MULTIBYTE$char[$i]" should be "(MULTIBYTE)$char[$i]" in m?? (and shift \$1,\$2,\$3,...) ($char)$char[$i]\n};
8814             }
8815 0         0 }
8816             else {
8817             $char[$i-1] = '(?:' . $char[$i-1] . ')';
8818             }
8819             }
8820             }
8821 187         893  
8822 1585 50       3107 # make regexp string
8823 1585 0 0     3830 $modifier =~ tr/i//d;
8824 0         0 if ($left_e > $right_e) {
8825             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
8826             return join '', $ope, $delimiter, $anchor, @char, '>]}' x ($left_e - $right_e), $matched, $end_delimiter, $modifier;
8827 0         0 }
8828             else {
8829             return join '', $ope, $delimiter, $anchor, '(?:', @char, '>]}' x ($left_e - $right_e), ')', $matched, $end_delimiter, $modifier;
8830 0 100 100     0 }
8831 1585         8147 }
8832             if (($ope =~ /\A m? \z/oxms) and ($delimiter eq '?')) {
8833             return join '', $ope, $delimiter, $anchor, @char, $matched, $end_delimiter, $modifier;
8834 94         794 }
8835             else {
8836             return join '', $ope, $delimiter, $anchor, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
8837             }
8838             }
8839              
8840             #
8841             # double quote stuff
8842 1491     540 0 13073 #
8843             sub qq_stuff {
8844             my($delimiter,$end_delimiter,$stuff) = @_;
8845 540 100       853  
8846 540         1148 # scalar variable or array variable
8847             if ($stuff =~ /\A [\$\@] /oxms) {
8848             return $stuff;
8849             }
8850 300         1080  
  240         600  
8851 280         765 # quote by delimiter
8852 240 50       626 my %octet = map {$_ => 1} ($stuff =~ /\G ([\x00-\xFF]) /oxmsg);
8853 240 50       427 for my $char (qw( ! " $ % & * + - . / : = ? @ ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
8854 240 50       388 next if $char eq $delimiter;
8855 240         460 next if $char eq $end_delimiter;
8856             if (not $octet{$char}) {
8857             return join '', 'qq', $char, $stuff, $char;
8858 240         1000 }
8859             }
8860             return join '', 'qq', '<', $stuff, '>';
8861             }
8862              
8863             #
8864             # escape regexp (m'', qr'', and m''b, qr''b)
8865 0     163 0 0 #
8866 163   100     712 sub e_qr_q {
8867             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
8868 163         455 $modifier ||= '';
8869 163 50       310  
8870 163         368 $modifier =~ tr/p//d;
8871 0         0 if ($modifier =~ /([adlu])/oxms) {
8872 0 0       0 my $line = 0;
8873 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
8874 0         0 if ($filename ne __FILE__) {
8875             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
8876             last;
8877 0         0 }
8878             }
8879             die qq{Unsupported modifier "$1" used at line $line.\n};
8880 0         0 }
8881              
8882             $slash = 'div';
8883 163 100       232  
    100          
8884 163         370 # literal null string pattern
8885 8         9 if ($string eq '') {
8886 8         10 $modifier =~ tr/bB//d;
8887             $modifier =~ tr/i//d;
8888             return join '', $ope, $delimiter, $end_delimiter, $modifier;
8889             }
8890              
8891 8         39 # with /b /B modifier
8892             elsif ($modifier =~ tr/bB//d) {
8893             return e_qr_qb($ope,$delimiter,$end_delimiter,$string,$modifier);
8894             }
8895              
8896 89         194 # without /b /B modifier
8897             else {
8898             return e_qr_qt($ope,$delimiter,$end_delimiter,$string,$modifier);
8899             }
8900             }
8901              
8902             #
8903             # escape regexp (m'', qr'')
8904 66     66 0 145 #
8905             sub e_qr_qt {
8906 66 100       156 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
8907              
8908             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
8909 66         190  
8910             # split regexp
8911             my @char = $string =~ /\G((?>
8912             [^\x81-\xFE\\\[\$\@\/] |
8913             [\x81-\xFE][\x00-\xFF] |
8914             \[\^ |
8915             \[\: (?>[a-z]+) \:\] |
8916             \[\:\^ (?>[a-z]+) \:\] |
8917             [\$\@\/] |
8918             \\ (?:$q_char) |
8919             (?:$q_char)
8920             ))/oxmsg;
8921 66         665  
8922 66 100 100     215 # unescape character
    50 100        
    50 66        
    50          
    50          
    100          
    50          
8923             for (my $i=0; $i <= $#char; $i++) {
8924             if (0) {
8925             }
8926 79         820  
8927 0         0 # escape last octet of multiple-octet
8928             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\\|\[\{\^]|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
8929             $char[$i] = $1 . '\\' . $2;
8930             }
8931              
8932 2         14 # open character class [...]
8933 0 0       0 elsif ($char[$i] eq '[') {
8934 0         0 my $left = $i;
8935             if ($char[$i+1] eq ']') {
8936 0         0 $i++;
8937 0 0       0 }
8938 0         0 while (1) {
8939             if (++$i > $#char) {
8940 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
8941 0         0 }
8942             if ($char[$i] eq ']') {
8943             my $right = $i;
8944 0         0  
8945             # [...]
8946 0         0 splice @char, $left, $right-$left+1, Ekps9566::charlist_qr(@char[$left+1..$right-1], $modifier);
8947 0         0  
8948             $i = $left;
8949             last;
8950             }
8951             }
8952             }
8953              
8954 0         0 # open character class [^...]
8955 0 0       0 elsif ($char[$i] eq '[^') {
8956 0         0 my $left = $i;
8957             if ($char[$i+1] eq ']') {
8958 0         0 $i++;
8959 0 0       0 }
8960 0         0 while (1) {
8961             if (++$i > $#char) {
8962 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
8963 0         0 }
8964             if ($char[$i] eq ']') {
8965             my $right = $i;
8966 0         0  
8967             # [^...]
8968 0         0 splice @char, $left, $right-$left+1, Ekps9566::charlist_not_qr(@char[$left+1..$right-1], $modifier);
8969 0         0  
8970             $i = $left;
8971             last;
8972             }
8973             }
8974             }
8975              
8976 0         0 # escape $ @ / and \
8977             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
8978             $char[$i] = '\\' . $char[$i];
8979             }
8980              
8981 0         0 # rewrite character class or escape character
8982             elsif (my $char = character_class($char[$i],$modifier)) {
8983             $char[$i] = $char;
8984             }
8985              
8986 0 50       0 # /i modifier
8987 16         39 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ekps9566::uc($char[$i]) ne Ekps9566::fc($char[$i]))) {
8988             if (CORE::length(Ekps9566::fc($char[$i])) == 1) {
8989             $char[$i] = '[' . Ekps9566::uc($char[$i]) . Ekps9566::fc($char[$i]) . ']';
8990 16         43 }
8991             else {
8992             $char[$i] = '(?:' . Ekps9566::uc($char[$i]) . '|' . Ekps9566::fc($char[$i]) . ')';
8993             }
8994             }
8995              
8996 0 0       0 # quote character before ? + * {
8997             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
8998             if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
8999 0         0 }
9000             else {
9001             $char[$i-1] = '(?:' . $char[$i-1] . ')';
9002             }
9003             }
9004 0         0 }
9005 66         127  
9006             $delimiter = '/';
9007 66         87 $end_delimiter = '/';
9008 66         106  
9009             $modifier =~ tr/i//d;
9010             return join '', $ope, $delimiter, $anchor, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9011             }
9012              
9013             #
9014             # escape regexp (m''b, qr''b)
9015 66     89 0 415 #
9016             sub e_qr_qb {
9017             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9018 89         190  
9019             # split regexp
9020             my @char = $string =~ /\G ((?>[^\\]|\\\\|[\x00-\xFF])) /oxmsg;
9021 89         336  
9022 89 50       232 # unescape character
    50          
9023             for (my $i=0; $i <= $#char; $i++) {
9024             if (0) {
9025             }
9026 199         601  
9027             # remain \\
9028             elsif ($char[$i] eq '\\\\') {
9029             }
9030              
9031 0         0 # escape $ @ / and \
9032             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
9033             $char[$i] = '\\' . $char[$i];
9034             }
9035 0         0 }
9036 89         133  
9037 89         114 $delimiter = '/';
9038             $end_delimiter = '/';
9039             return join '', $ope, $delimiter, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9040             }
9041              
9042             #
9043             # escape regexp (s/here//)
9044 89     194 0 493 #
9045 194   100     590 sub e_s1 {
9046             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9047 194         678 $modifier ||= '';
9048 194 50       320  
9049 194         546 $modifier =~ tr/p//d;
9050 0         0 if ($modifier =~ /([adlu])/oxms) {
9051 0 0       0 my $line = 0;
9052 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
9053 0         0 if ($filename ne __FILE__) {
9054             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
9055             last;
9056 0         0 }
9057             }
9058             die qq{Unsupported modifier "$1" used at line $line.\n};
9059 0         0 }
9060              
9061             $slash = 'div';
9062 194 100       339  
    100          
9063 194         743 # literal null string pattern
9064 8         9 if ($string eq '') {
9065 8         11 $modifier =~ tr/bB//d;
9066             $modifier =~ tr/i//d;
9067             return join '', $ope, $delimiter, $end_delimiter, $modifier;
9068             }
9069              
9070             # /b /B modifier
9071             elsif ($modifier =~ tr/bB//d) {
9072 8 50       47  
9073 44         98 # choice again delimiter
9074 0         0 if ($delimiter =~ / [\@:] /oxms) {
  0         0  
9075 0 0       0 my @char = $string =~ /\G ([\x00-\xFF]) /oxmsg;
    0          
    0          
    0          
9076 0         0 my %octet = map {$_ => 1} @char;
9077 0         0 if (not $octet{')'}) {
9078             $delimiter = '(';
9079             $end_delimiter = ')';
9080 0         0 }
9081 0         0 elsif (not $octet{'}'}) {
9082             $delimiter = '{';
9083             $end_delimiter = '}';
9084 0         0 }
9085 0         0 elsif (not $octet{']'}) {
9086             $delimiter = '[';
9087             $end_delimiter = ']';
9088 0         0 }
9089 0         0 elsif (not $octet{'>'}) {
9090             $delimiter = '<';
9091             $end_delimiter = '>';
9092 0         0 }
9093 0 0       0 else {
9094 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
9095 0         0 if (not $octet{$char}) {
9096 0         0 $delimiter = $char;
9097             $end_delimiter = $char;
9098             last;
9099             }
9100             }
9101             }
9102 0         0 }
9103 44         59  
9104 44         52 my $prematch = '';
9105             $prematch = q{(\G[\x00-\xFF]*?)};
9106             return join '', $ope, $delimiter, $prematch, '(?:', $string, ')', $matched, $end_delimiter, $modifier;
9107 44 100       316 }
9108 142         436  
9109             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
9110             my $metachar = qr/[\@\\|[\]{^]/oxms;
9111 142         715  
9112             # split regexp
9113             my @char = $string =~ /\G((?>
9114             [^\x81-\xFE\\\$\@\[\(]|[\x81-\xFE][\x00-\xFF] |
9115             \\ (?>[1-9][0-9]*) |
9116             \\g (?>\s*) (?>[1-9][0-9]*) |
9117             \\g (?>\s*) \{ (?>\s*) (?>[1-9][0-9]*) (?>\s*) \} |
9118             \\g (?>\s*) \{ (?>\s*) - (?>\s*) (?>[1-9][0-9]*) (?>\s*) \} |
9119             \\x (?>[0-9A-Fa-f]{1,2}) |
9120             \\ (?>[0-7]{2,3}) |
9121             \\c [\x40-\x5F] |
9122             \\x\{ (?>[0-9A-Fa-f]+) \} |
9123             \\o\{ (?>[0-7]+) \} |
9124             \\[bBNpP]\{ (?>[^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} |
9125             \\ $q_char |
9126             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
9127             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
9128             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
9129             [\$\@] $qq_variable |
9130             \$ (?>\s* [0-9]+) |
9131             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
9132             \$ \$ (?![\w\{]) |
9133             \$ (?>\s*) \$ (?>\s*) $qq_variable |
9134             \[\^ |
9135             \[\: (?>[a-z]+) :\] |
9136             \[\:\^ (?>[a-z]+) :\] |
9137             \(\? |
9138             $q_char
9139             ))/oxmsg;
9140 142 50       37034  
9141 142         1125 # choice again delimiter
  0         0  
9142 0 0       0 if ($delimiter =~ / [\@:] /oxms) {
    0          
    0          
    0          
9143 0         0 my %octet = map {$_ => 1} @char;
9144 0         0 if (not $octet{')'}) {
9145             $delimiter = '(';
9146             $end_delimiter = ')';
9147 0         0 }
9148 0         0 elsif (not $octet{'}'}) {
9149             $delimiter = '{';
9150             $end_delimiter = '}';
9151 0         0 }
9152 0         0 elsif (not $octet{']'}) {
9153             $delimiter = '[';
9154             $end_delimiter = ']';
9155 0         0 }
9156 0         0 elsif (not $octet{'>'}) {
9157             $delimiter = '<';
9158             $end_delimiter = '>';
9159 0         0 }
9160 0 0       0 else {
9161 0         0 for my $char (qw( ! " $ % & * + - . / = ? ^ ` | ~ ), "\x00".."\x1F", "\x7F", "\xFF") {
9162 0         0 if (not $octet{$char}) {
9163 0         0 $delimiter = $char;
9164             $end_delimiter = $char;
9165             last;
9166             }
9167             }
9168             }
9169             }
9170 0         0  
  142         368  
9171             # count '('
9172 476         835 my $parens = grep { $_ eq '(' } @char;
9173 142         208  
9174 142         209 my $left_e = 0;
9175             my $right_e = 0;
9176             for (my $i=0; $i <= $#char; $i++) {
9177 142 50 33     397  
    50 33        
    100          
    100          
    50          
    50          
9178 397         2436 # "\L\u" --> "\u\L"
9179             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
9180             @char[$i,$i+1] = @char[$i+1,$i];
9181             }
9182              
9183 0         0 # "\U\l" --> "\l\U"
9184             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
9185             @char[$i,$i+1] = @char[$i+1,$i];
9186             }
9187              
9188 0         0 # octal escape sequence
9189             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
9190             $char[$i] = Ekps9566::octchr($1);
9191             }
9192              
9193 1         2 # hexadecimal escape sequence
9194             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
9195             $char[$i] = Ekps9566::hexchr($1);
9196             }
9197              
9198             # \b{...} --> b\{...}
9199             # \B{...} --> B\{...}
9200             # \N{CHARNAME} --> N\{CHARNAME}
9201             # \p{PROPERTY} --> p\{PROPERTY}
9202 1         3 # \P{PROPERTY} --> P\{PROPERTY}
9203             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} ) \z/oxms) {
9204             $char[$i] = $1 . '\\' . $2;
9205             }
9206              
9207 0         0 # \p, \P, \X --> p, P, X
9208             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
9209             $char[$i] = $1;
9210 0 100 100     0 }
    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          
9211              
9212             if (0) {
9213             }
9214 397         4850  
9215 0         0 # escape last octet of multiple-octet
9216             elsif ($char[$i] =~ /\A \\? ([\x80-\xFF].*) ($metachar|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
9217             $char[$i] = $1 . '\\' . $2;
9218             }
9219              
9220 23 0 0     120 # join separated multiple-octet
    0 0        
    0 0        
      0        
      0        
      0        
9221 0         0 elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
9222             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)) {
9223             $char[$i] .= join '', splice @char, $i+1, 3;
9224 0         0 }
9225             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)) {
9226             $char[$i] .= join '', splice @char, $i+1, 2;
9227 0         0 }
9228             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)) {
9229             $char[$i] .= join '', splice @char, $i+1, 1;
9230             }
9231             }
9232              
9233 0         0 # open character class [...]
9234 20 50       49 elsif ($char[$i] eq '[') {
9235 20         70 my $left = $i;
9236             if ($char[$i+1] eq ']') {
9237 0         0 $i++;
9238 20 50       40 }
9239 79         582 while (1) {
9240             if (++$i > $#char) {
9241 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
9242 79         220 }
9243             if ($char[$i] eq ']') {
9244             my $right = $i;
9245 20 50       45  
9246 20         167 # [...]
  0         0  
9247             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
9248             splice @char, $left, $right-$left+1, sprintf(q{@{[Ekps9566::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
9249 0         0 }
9250             else {
9251             splice @char, $left, $right-$left+1, Ekps9566::charlist_qr(@char[$left+1..$right-1], $modifier);
9252 20         111 }
9253 20         71  
9254             $i = $left;
9255             last;
9256             }
9257             }
9258             }
9259              
9260 20         77 # open character class [^...]
9261 0 0       0 elsif ($char[$i] eq '[^') {
9262 0         0 my $left = $i;
9263             if ($char[$i+1] eq ']') {
9264 0         0 $i++;
9265 0 0       0 }
9266 0         0 while (1) {
9267             if (++$i > $#char) {
9268 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
9269 0         0 }
9270             if ($char[$i] eq ']') {
9271             my $right = $i;
9272 0 0       0  
9273 0         0 # [^...]
  0         0  
9274             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
9275             splice @char, $left, $right-$left+1, sprintf(q{@{[Ekps9566::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
9276 0         0 }
9277             else {
9278             splice @char, $left, $right-$left+1, Ekps9566::charlist_not_qr(@char[$left+1..$right-1], $modifier);
9279 0         0 }
9280 0         0  
9281             $i = $left;
9282             last;
9283             }
9284             }
9285             }
9286              
9287 0         0 # rewrite character class or escape character
9288             elsif (my $char = character_class($char[$i],$modifier)) {
9289             $char[$i] = $char;
9290             }
9291              
9292 11 50       27 # /i modifier
9293 11         25 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ekps9566::uc($char[$i]) ne Ekps9566::fc($char[$i]))) {
9294             if (CORE::length(Ekps9566::fc($char[$i])) == 1) {
9295             $char[$i] = '[' . Ekps9566::uc($char[$i]) . Ekps9566::fc($char[$i]) . ']';
9296 11         26 }
9297             else {
9298             $char[$i] = '(?:' . Ekps9566::uc($char[$i]) . '|' . Ekps9566::fc($char[$i]) . ')';
9299             }
9300             }
9301              
9302 0 50       0 # \u \l \U \L \F \Q \E
9303 8         28 elsif ($char[$i] =~ /\A [<>] \z/oxms) {
9304             if ($right_e < $left_e) {
9305             $char[$i] = '\\' . $char[$i];
9306             }
9307 0         0 }
9308 0         0 elsif ($char[$i] eq '\u') {
9309             $char[$i] = '@{[Ekps9566::ucfirst qq<';
9310             $left_e++;
9311 0         0 }
9312 0         0 elsif ($char[$i] eq '\l') {
9313             $char[$i] = '@{[Ekps9566::lcfirst qq<';
9314             $left_e++;
9315 0         0 }
9316 0         0 elsif ($char[$i] eq '\U') {
9317             $char[$i] = '@{[Ekps9566::uc qq<';
9318             $left_e++;
9319 0         0 }
9320 0         0 elsif ($char[$i] eq '\L') {
9321             $char[$i] = '@{[Ekps9566::lc qq<';
9322             $left_e++;
9323 0         0 }
9324 0         0 elsif ($char[$i] eq '\F') {
9325             $char[$i] = '@{[Ekps9566::fc qq<';
9326             $left_e++;
9327 0         0 }
9328 7         12 elsif ($char[$i] eq '\Q') {
9329             $char[$i] = '@{[CORE::quotemeta qq<';
9330             $left_e++;
9331 7 50       17 }
9332 7         15 elsif ($char[$i] eq '\E') {
9333 7         10 if ($right_e < $left_e) {
9334             $char[$i] = '>]}';
9335             $right_e++;
9336 7         15 }
9337             else {
9338             $char[$i] = '';
9339             }
9340 0         0 }
9341 0 0       0 elsif ($char[$i] eq '\Q') {
9342 0         0 while (1) {
9343             if (++$i > $#char) {
9344 0 0       0 last;
9345 0         0 }
9346             if ($char[$i] eq '\E') {
9347             last;
9348             }
9349             }
9350             }
9351             elsif ($char[$i] eq '\E') {
9352             }
9353              
9354             # \0 --> \0
9355             elsif ($char[$i] =~ /\A \\ (?>\s*) 0 \z/oxms) {
9356             }
9357              
9358             # \g{N}, \g{-N}
9359              
9360             # P.108 Using Simple Patterns
9361             # in Chapter 7: In the World of Regular Expressions
9362             # of ISBN 978-0-596-52010-6 Learning Perl, Fifth Edition
9363              
9364             # P.221 Capturing
9365             # in Chapter 5: Pattern Matching
9366             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
9367              
9368             # \g{-1}, \g{-2}, \g{-3} --> \g{-1}, \g{-2}, \g{-3}
9369             elsif ($char[$i] =~ /\A \\g (?>\s*) \{ (?>\s*) - (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
9370             }
9371              
9372 0 0       0 # \g{1}, \g{2}, \g{3} --> \g{2}, \g{3}, \g{4} (only when multibyte anchoring is enable)
9373 0         0 elsif ($char[$i] =~ /\A \\g (?>\s*) \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
9374             if ($1 <= $parens) {
9375             $char[$i] = '\\g{' . ($1 + 1) . '}';
9376             }
9377             }
9378              
9379 0 0       0 # \g1, \g2, \g3 --> \g2, \g3, \g4 (only when multibyte anchoring is enable)
9380 0         0 elsif ($char[$i] =~ /\A \\g (?>\s*) ((?>[1-9][0-9]*)) \z/oxms) {
9381             if ($1 <= $parens) {
9382             $char[$i] = '\\g' . ($1 + 1);
9383             }
9384             }
9385              
9386 0 0       0 # \1, \2, \3 --> \2, \3, \4 (only when multibyte anchoring is enable)
9387 0         0 elsif ($char[$i] =~ /\A \\ (?>\s*) ((?>[1-9][0-9]*)) \z/oxms) {
9388             if ($1 <= $parens) {
9389             $char[$i] = '\\' . ($1 + 1);
9390             }
9391             }
9392              
9393 0 0       0 # $0 --> $0
9394 0         0 elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
9395             if ($ignorecase) {
9396             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9397             }
9398 0 0       0 }
9399 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
9400             if ($ignorecase) {
9401             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9402             }
9403             }
9404              
9405             # $$ --> $$
9406             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
9407             }
9408              
9409             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
9410 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
9411 0 0       0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
9412 0         0 $char[$i] = e_capture($1);
9413             if ($ignorecase) {
9414             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9415             }
9416 0         0 }
9417 0 0       0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
9418 0         0 $char[$i] = e_capture($1);
9419             if ($ignorecase) {
9420             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9421             }
9422             }
9423              
9424 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
9425 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
9426 0         0 $char[$i] = e_capture($1.'->'.$2);
9427             if ($ignorecase) {
9428             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9429             }
9430             }
9431              
9432 0         0 # $$foo{ ... } --> $ $foo->{ ... }
9433 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
9434 0         0 $char[$i] = e_capture($1.'->'.$2);
9435             if ($ignorecase) {
9436             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9437             }
9438             }
9439              
9440 0         0 # $$foo
9441 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
9442 0         0 $char[$i] = e_capture($1);
9443             if ($ignorecase) {
9444             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9445             }
9446             }
9447              
9448 0 50       0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ekps9566::PREMATCH()
9449 4         15 elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
9450             if ($ignorecase) {
9451             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::PREMATCH())]}';
9452 0         0 }
9453             else {
9454             $char[$i] = '@{[Ekps9566::PREMATCH()]}';
9455             }
9456             }
9457              
9458 4 50       16 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ekps9566::MATCH()
9459 4         17 elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
9460             if ($ignorecase) {
9461             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::MATCH())]}';
9462 0         0 }
9463             else {
9464             $char[$i] = '@{[Ekps9566::MATCH()]}';
9465             }
9466             }
9467              
9468 4 50       15 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ekps9566::POSTMATCH()
9469 3         12 elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
9470             if ($ignorecase) {
9471             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::POSTMATCH())]}';
9472 0         0 }
9473             else {
9474             $char[$i] = '@{[Ekps9566::POSTMATCH()]}';
9475             }
9476             }
9477              
9478 3 0       13 # ${ foo }
9479 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
9480             if ($ignorecase) {
9481             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9482             }
9483             }
9484              
9485 0         0 # ${ ... }
9486 0 0       0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
9487 0         0 $char[$i] = e_capture($1);
9488             if ($ignorecase) {
9489             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9490             }
9491             }
9492              
9493 0         0 # $scalar or @array
9494 13 50       43 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
9495 13         73 $char[$i] = e_string($char[$i]);
9496             if ($ignorecase) {
9497             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
9498             }
9499             }
9500              
9501 0 50       0 # quote character before ? + * {
9502             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
9503             if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
9504 23         129 }
9505             else {
9506             $char[$i-1] = '(?:' . $char[$i-1] . ')';
9507             }
9508             }
9509             }
9510 23         123  
9511 142         328 # make regexp string
9512 142         432 my $prematch = '';
9513 142 50       234 $prematch = "($anchor)";
9514 142         376 $modifier =~ tr/i//d;
9515             if ($left_e > $right_e) {
9516 0         0 return join '', $ope, $delimiter, $prematch, '(?:', @char, '>]}' x ($left_e - $right_e), ')', $matched, $end_delimiter, $modifier;
9517             }
9518             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9519             }
9520              
9521             #
9522             # escape regexp (s'here'' or s'here''b)
9523 142     96 0 1552 #
9524 96   100     195 sub e_s1_q {
9525             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9526 96         235 $modifier ||= '';
9527 96 50       114  
9528 96         172 $modifier =~ tr/p//d;
9529 0         0 if ($modifier =~ /([adlu])/oxms) {
9530 0 0       0 my $line = 0;
9531 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
9532 0         0 if ($filename ne __FILE__) {
9533             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
9534             last;
9535 0         0 }
9536             }
9537             die qq{Unsupported modifier "$1" used at line $line.\n};
9538 0         0 }
9539              
9540             $slash = 'div';
9541 96 100       125  
    100          
9542 96         215 # literal null string pattern
9543 8         10 if ($string eq '') {
9544 8         11 $modifier =~ tr/bB//d;
9545             $modifier =~ tr/i//d;
9546             return join '', $ope, $delimiter, $end_delimiter, $modifier;
9547             }
9548              
9549 8         51 # with /b /B modifier
9550             elsif ($modifier =~ tr/bB//d) {
9551             return e_s1_qb($ope,$delimiter,$end_delimiter,$string,$modifier);
9552             }
9553              
9554 44         84 # without /b /B modifier
9555             else {
9556             return e_s1_qt($ope,$delimiter,$end_delimiter,$string,$modifier);
9557             }
9558             }
9559              
9560             #
9561             # escape regexp (s'here'')
9562 44     44 0 114 #
9563             sub e_s1_qt {
9564 44 100       114 my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9565              
9566             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
9567 44         107  
9568             # split regexp
9569             my @char = $string =~ /\G((?>
9570             [^\x81-\xFE\\\[\$\@\/] |
9571             [\x81-\xFE][\x00-\xFF] |
9572             \[\^ |
9573             \[\: (?>[a-z]+) \:\] |
9574             \[\:\^ (?>[a-z]+) \:\] |
9575             [\$\@\/] |
9576             \\ (?:$q_char) |
9577             (?:$q_char)
9578             ))/oxmsg;
9579 44         474  
9580 44 50 100     140 # unescape character
    50 100        
    50 66        
    50          
    100          
    100          
    50          
9581             for (my $i=0; $i <= $#char; $i++) {
9582             if (0) {
9583             }
9584 62         567  
9585 0         0 # escape last octet of multiple-octet
9586             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\\|\[\{\^]|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
9587             $char[$i] = $1 . '\\' . $2;
9588             }
9589              
9590 0         0 # open character class [...]
9591 0 0       0 elsif ($char[$i] eq '[') {
9592 0         0 my $left = $i;
9593             if ($char[$i+1] eq ']') {
9594 0         0 $i++;
9595 0 0       0 }
9596 0         0 while (1) {
9597             if (++$i > $#char) {
9598 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
9599 0         0 }
9600             if ($char[$i] eq ']') {
9601             my $right = $i;
9602 0         0  
9603             # [...]
9604 0         0 splice @char, $left, $right-$left+1, Ekps9566::charlist_qr(@char[$left+1..$right-1], $modifier);
9605 0         0  
9606             $i = $left;
9607             last;
9608             }
9609             }
9610             }
9611              
9612 0         0 # open character class [^...]
9613 0 0       0 elsif ($char[$i] eq '[^') {
9614 0         0 my $left = $i;
9615             if ($char[$i+1] eq ']') {
9616 0         0 $i++;
9617 0 0       0 }
9618 0         0 while (1) {
9619             if (++$i > $#char) {
9620 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
9621 0         0 }
9622             if ($char[$i] eq ']') {
9623             my $right = $i;
9624 0         0  
9625             # [^...]
9626 0         0 splice @char, $left, $right-$left+1, Ekps9566::charlist_not_qr(@char[$left+1..$right-1], $modifier);
9627 0         0  
9628             $i = $left;
9629             last;
9630             }
9631             }
9632             }
9633              
9634 0         0 # escape $ @ / and \
9635             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
9636             $char[$i] = '\\' . $char[$i];
9637             }
9638              
9639 0         0 # rewrite character class or escape character
9640             elsif (my $char = character_class($char[$i],$modifier)) {
9641             $char[$i] = $char;
9642             }
9643              
9644 6 50       13 # /i modifier
9645 8         21 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ekps9566::uc($char[$i]) ne Ekps9566::fc($char[$i]))) {
9646             if (CORE::length(Ekps9566::fc($char[$i])) == 1) {
9647             $char[$i] = '[' . Ekps9566::uc($char[$i]) . Ekps9566::fc($char[$i]) . ']';
9648 8         19 }
9649             else {
9650             $char[$i] = '(?:' . Ekps9566::uc($char[$i]) . '|' . Ekps9566::fc($char[$i]) . ')';
9651             }
9652             }
9653              
9654 0 0       0 # quote character before ? + * {
9655             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
9656             if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
9657 0         0 }
9658             else {
9659             $char[$i-1] = '(?:' . $char[$i-1] . ')';
9660             }
9661             }
9662 0         0 }
9663 44         78  
9664 44         71 $modifier =~ tr/i//d;
9665 44         55 $delimiter = '/';
9666 44         59 $end_delimiter = '/';
9667 44         83 my $prematch = '';
9668             $prematch = "($anchor)";
9669             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9670             }
9671              
9672             #
9673             # escape regexp (s'here''b)
9674 44     44 0 301 #
9675             sub e_s1_qb {
9676             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
9677 44         85  
9678             # split regexp
9679             my @char = $string =~ /\G (?>[^\\]|\\\\|[\x00-\xFF]) /oxmsg;
9680 44         151  
9681 44 50       118 # unescape character
    50          
9682             for (my $i=0; $i <= $#char; $i++) {
9683             if (0) {
9684             }
9685 98         299  
9686             # remain \\
9687             elsif ($char[$i] eq '\\\\') {
9688             }
9689              
9690 0         0 # escape $ @ / and \
9691             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
9692             $char[$i] = '\\' . $char[$i];
9693             }
9694 0         0 }
9695 44         64  
9696 44         54 $delimiter = '/';
9697 44         59 $end_delimiter = '/';
9698 44         51 my $prematch = '';
9699             $prematch = q{(\G[\x00-\xFF]*?)};
9700             return join '', $ope, $delimiter, $prematch, '(?:', @char, ')', $matched, $end_delimiter, $modifier;
9701             }
9702              
9703             #
9704             # escape regexp (s''here')
9705 44     91 0 280 #
9706             sub e_s2_q {
9707 91         166 my($ope,$delimiter,$end_delimiter,$string) = @_;
9708              
9709 91         97 $slash = 'div';
9710 91         318  
9711 91 50 66     203 my @char = $string =~ / \G (?>[^\x81-\xFE\\]|\\\\|$q_char) /oxmsg;
    50 33        
    100          
    100          
9712             for (my $i=0; $i <= $#char; $i++) {
9713             if (0) {
9714             }
9715 9         88  
9716 0         0 # escape last octet of multiple-octet
9717             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) (\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
9718             $char[$i] = $1 . '\\' . $2;
9719 0         0 }
9720             elsif (defined($char[$i+1]) and ($char[$i+1] eq '\\') and ($char[$i] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
9721             $char[$i] = $1 . '\\' . $2;
9722             }
9723              
9724             # not escape \\
9725             elsif ($char[$i] =~ /\A \\\\ \z/oxms) {
9726             }
9727              
9728 0         0 # escape $ @ / and \
9729             elsif ($char[$i] =~ /\A [\$\@\/\\] \z/oxms) {
9730             $char[$i] = '\\' . $char[$i];
9731 5 50 66     15 }
9732 91         219 }
9733             if (defined($char[-1]) and ($char[-1] =~ /\A ([\x80-\xFF].*) (\\) \z/xms)) {
9734             $char[-1] = $1 . '\\' . $2;
9735 0         0 }
9736              
9737             return join '', $ope, $delimiter, @char, $end_delimiter;
9738             }
9739              
9740             #
9741             # escape regexp (s/here/and here/modifier)
9742 91     290 0 255 #
9743 290   100     2144 sub e_sub {
9744             my($variable,$delimiter1,$pattern,$end_delimiter1,$delimiter2,$replacement,$end_delimiter2,$modifier) = @_;
9745 290         1194 $modifier ||= '';
9746 290 50       556  
9747 290         763 $modifier =~ tr/p//d;
9748 0         0 if ($modifier =~ /([adlu])/oxms) {
9749 0 0       0 my $line = 0;
9750 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
9751 0         0 if ($filename ne __FILE__) {
9752             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
9753             last;
9754 0         0 }
9755             }
9756             die qq{Unsupported modifier "$1" used at line $line.\n};
9757 0 100       0 }
9758 290         654  
9759 37         51 if ($variable eq '') {
9760             $variable = '$_';
9761             $bind_operator = ' =~ ';
9762 37         50 }
9763              
9764             $slash = 'div';
9765              
9766             # P.128 Start of match (or end of previous match): \G
9767             # P.130 Advanced Use of \G with Perl
9768             # in Chapter 3: Overview of Regular Expression Features and Flavors
9769             # P.312 Iterative Matching: Scalar Context, with /g
9770             # in Chapter 7: Perl
9771             # of ISBN 0-596-00289-0 Mastering Regular Expressions, Second edition
9772              
9773             # P.181 Where You Left Off: The \G Assertion
9774             # in Chapter 5: Pattern Matching
9775             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
9776              
9777             # P.220 Where You Left Off: The \G Assertion
9778             # in Chapter 5: Pattern Matching
9779 290         434 # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
9780 290         430  
9781             my $e_modifier = $modifier =~ tr/e//d;
9782 290         481 my $r_modifier = $modifier =~ tr/r//d;
9783 290 50       403  
9784 290         869 my $my = '';
9785 0         0 if ($variable =~ s/\A \( (?>\s*) ( (?>(?: local \b | my \b | our \b | state \b )?) .+ ) \) \z/$1/oxms) {
9786 0         0 $my = $variable;
9787             $variable =~ s/ (?: local \b | my \b | our \b | state \b ) (?>\s*) //oxms;
9788             $variable =~ s/ = .+ \z//oxms;
9789 0         0 }
9790 290         733  
9791             (my $variable_basename = $variable) =~ s/ [\[\{].* \z//oxms;
9792             $variable_basename =~ s/ \s+ \z//oxms;
9793 290         551  
9794 290 100       430 # quote replacement string
9795 290         634 my $e_replacement = '';
9796 17         37 if ($e_modifier >= 1) {
9797             $e_replacement = e_qq('', '', '', $replacement);
9798             $e_modifier--;
9799 17 100       37 }
9800 273         572 else {
9801             if ($delimiter2 eq "'") {
9802             $e_replacement = e_s2_q('qq', '/', '/', $replacement);
9803 91         252 }
9804             else {
9805             $e_replacement = e_qq ('qq', $delimiter2, $end_delimiter2, $replacement);
9806             }
9807 182         509 }
9808              
9809             my $sub = '';
9810 290 100       504  
9811 290 100       577 # with /r
    50          
9812             if ($r_modifier) {
9813             if (0) {
9814             }
9815 8         22  
9816 0 50       0 # s///gr with multibyte anchoring
9817             elsif ($modifier =~ /g/oxms) {
9818             $sub = sprintf(
9819             # 1 2 3 4 5
9820             q,
9821              
9822             $variable, # 1
9823             ($delimiter1 eq "'") ? # 2
9824             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
9825             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
9826             $s_matched, # 3
9827             $e_replacement, # 4
9828             '$Ekps9566::re_r=CORE::eval $Ekps9566::re_r; ' x $e_modifier, # 5
9829             );
9830             }
9831              
9832 4 0       14 # s///gr without multibyte anchoring
9833             elsif ($modifier =~ /g/oxms) {
9834             $sub = sprintf(
9835             # 1 2 3 4 5
9836             q,
9837              
9838             $variable, # 1
9839             ($delimiter1 eq "'") ? # 2
9840             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
9841             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
9842             $s_matched, # 3
9843             $e_replacement, # 4
9844             '$Ekps9566::re_r=CORE::eval $Ekps9566::re_r; ' x $e_modifier, # 5
9845             );
9846             }
9847              
9848             # s///r
9849 0         0 else {
9850 4         7  
9851             my $prematch = q{$`};
9852 4 50       14 $prematch = q{${1}};
9853              
9854             $sub = sprintf(
9855             # 1 2 3 4 5 6 7
9856             q<(%s =~ %s) ? CORE::eval{%s local $^W=0; local $Ekps9566::re_r=%s; %s"%s$Ekps9566::re_r$'" } : %s>,
9857              
9858             $variable, # 1
9859             ($delimiter1 eq "'") ? # 2
9860             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
9861             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
9862             $s_matched, # 3
9863             $e_replacement, # 4
9864             '$Ekps9566::re_r=CORE::eval $Ekps9566::re_r; ' x $e_modifier, # 5
9865             $prematch, # 6
9866             $variable, # 7
9867             );
9868             }
9869 4 50       14  
9870 8         22 # $var !~ s///r doesn't make sense
9871             if ($bind_operator =~ / !~ /oxms) {
9872             $sub = q{die("$0: Using !~ with s///r doesn't make sense"), } . $sub;
9873             }
9874             }
9875              
9876 0 100       0 # without /r
    50          
9877             else {
9878             if (0) {
9879             }
9880 282         1003  
9881 0 100       0 # s///g with multibyte anchoring
    100          
9882             elsif ($modifier =~ /g/oxms) {
9883             $sub = sprintf(
9884             # 1 2 3 4 5 6 7 8 9 10
9885             q,
9886              
9887             $variable, # 1
9888             ($delimiter1 eq "'") ? # 2
9889             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
9890             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
9891             $s_matched, # 3
9892             $e_replacement, # 4
9893             '$Ekps9566::re_r=CORE::eval $Ekps9566::re_r; ' x $e_modifier, # 5
9894             $variable, # 6
9895             $variable, # 7
9896             $variable, # 8
9897             $variable, # 9
9898              
9899             # Binary "!~" is just like "=~" except the return value is negated in the logical sense.
9900             # It returns false if the match succeeds, and true if it fails.
9901             # (and so on)
9902              
9903             ($bind_operator =~ / !~ /oxms) ? '!' : '', # 10
9904             );
9905             }
9906              
9907 35 0       206 # s///g without multibyte anchoring
    0          
9908             elsif ($modifier =~ /g/oxms) {
9909             $sub = sprintf(
9910             # 1 2 3 4 5 6 7 8
9911             q,
9912              
9913             $variable, # 1
9914             ($delimiter1 eq "'") ? # 2
9915             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
9916             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
9917             $s_matched, # 3
9918             $e_replacement, # 4
9919             '$Ekps9566::re_r=CORE::eval $Ekps9566::re_r; ' x $e_modifier, # 5
9920             $variable, # 6
9921             $variable, # 7
9922             ($bind_operator =~ / !~ /oxms) ? '!' : '', # 8
9923             );
9924             }
9925              
9926             # s///
9927 0         0 else {
9928 247         398  
9929             my $prematch = q{$`};
9930 247 100       437 $prematch = q{${1}};
    100          
9931              
9932             $sub = sprintf(
9933              
9934             ($bind_operator =~ / =~ /oxms) ?
9935              
9936             # 1 2 3 4 5 6 7 8
9937             q<(%s%s%s) ? CORE::eval{%s local $^W=0; local $Ekps9566::re_r=%s; %s%s="%s$Ekps9566::re_r$'"; 1 } : undef> :
9938              
9939             # 1 2 3 4 5 6 7 8
9940             q<(%s%s%s) ? 1 : CORE::eval{%s local $^W=0; local $Ekps9566::re_r=%s; %s%s="%s$Ekps9566::re_r$'"; undef }>,
9941              
9942             $variable, # 1
9943             $bind_operator, # 2
9944             ($delimiter1 eq "'") ? # 3
9945             e_s1_q('m', $delimiter1, $end_delimiter1, $pattern, $modifier) : # :
9946             e_s1 ('m', $delimiter1, $end_delimiter1, $pattern, $modifier), # :
9947             $s_matched, # 4
9948             $e_replacement, # 5
9949             '$Ekps9566::re_r=CORE::eval $Ekps9566::re_r; ' x $e_modifier, # 6
9950             $variable, # 7
9951             $prematch, # 8
9952             );
9953             }
9954             }
9955 247 50       1236  
9956 290         751 # (my $foo = $bar) =~ s/// --> (my $foo = $bar, CORE::eval { ... })[1]
9957             if ($my ne '') {
9958             $sub = "($my, $sub)[1]";
9959             }
9960 0         0  
9961 290         406 # clear s/// variable
9962             $sub_variable = '';
9963 290         366 $bind_operator = '';
9964              
9965             return $sub;
9966             }
9967              
9968             #
9969             # escape chdir (qq//, "")
9970 290     0 0 2252 #
9971             sub e_chdir {
9972 0 0       0 my($ope,$delimiter,$end_delimiter,$string) = @_;
9973 0 0       0  
9974 0 0       0 if ($^W) {
9975 0         0 if (Ekps9566::_MSWin32_5Cended_path($string)) {
9976 0         0 if ($] !~ /^5\.005/oxms) {
9977             warn <
9978             @{[__FILE__]}: Can't chdir to '$string'
9979              
9980             chdir does not work with chr(0x5C) at end of path
9981             http://bugs.activestate.com/show_bug.cgi?id=81839
9982             END
9983             }
9984             }
9985 0         0 }
9986              
9987             return e_qq($ope,$delimiter,$end_delimiter,$string);
9988             }
9989              
9990             #
9991             # escape chdir (q//, '')
9992 0     2 0 0 #
9993             sub e_chdir_q {
9994 2 50       8 my($ope,$delimiter,$end_delimiter,$string) = @_;
9995 2 0       13  
9996 0 0       0 if ($^W) {
9997 0         0 if (Ekps9566::_MSWin32_5Cended_path($string)) {
9998 0         0 if ($] !~ /^5\.005/oxms) {
9999             warn <
10000             @{[__FILE__]}: Can't chdir to '$string'
10001              
10002             chdir does not work with chr(0x5C) at end of path
10003             http://bugs.activestate.com/show_bug.cgi?id=81839
10004             END
10005             }
10006             }
10007 0         0 }
10008              
10009             return e_q($ope,$delimiter,$end_delimiter,$string);
10010             }
10011              
10012             #
10013             # escape regexp of split qr//
10014 2     273 0 8 #
10015 273   100     1270 sub e_split {
10016             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
10017 273         1113 $modifier ||= '';
10018 273 50       611  
10019 273         752 $modifier =~ tr/p//d;
10020 0         0 if ($modifier =~ /([adlu])/oxms) {
10021 0 0       0 my $line = 0;
10022 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
10023 0         0 if ($filename ne __FILE__) {
10024             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
10025             last;
10026 0         0 }
10027             }
10028             die qq{Unsupported modifier "$1" used at line $line.\n};
10029 0         0 }
10030              
10031             $slash = 'div';
10032 273 100       494  
10033 273         620 # /b /B modifier
10034             if ($modifier =~ tr/bB//d) {
10035             return join '', 'split', $ope, $delimiter, $string, $end_delimiter, $modifier;
10036 84 100       502 }
10037 189         643  
10038             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
10039             my $metachar = qr/[\@\\|[\]{^]/oxms;
10040 189         671  
10041             # split regexp
10042             my @char = $string =~ /\G((?>
10043             [^\x81-\xFE\\\$\@\[\(]|[\x81-\xFE][\x00-\xFF] |
10044             \\x (?>[0-9A-Fa-f]{1,2}) |
10045             \\ (?>[0-7]{2,3}) |
10046             \\c [\x40-\x5F] |
10047             \\x\{ (?>[0-9A-Fa-f]+) \} |
10048             \\o\{ (?>[0-7]+) \} |
10049             \\[bBNpP]\{ (?>[^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} |
10050             \\ $q_char |
10051             \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} |
10052             \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} |
10053             \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} |
10054             [\$\@] $qq_variable |
10055             \$ (?>\s* [0-9]+) |
10056             \$ (?>\s*) \{ (?>\s* [0-9]+ \s*) \} |
10057             \$ \$ (?![\w\{]) |
10058             \$ (?>\s*) \$ (?>\s*) $qq_variable |
10059             \[\^ |
10060             \[\: (?>[a-z]+) :\] |
10061             \[\:\^ (?>[a-z]+) :\] |
10062             \(\? |
10063             $q_char
10064 189         18450 ))/oxmsg;
10065 189         688  
10066 189         650 my $left_e = 0;
10067             my $right_e = 0;
10068             for (my $i=0; $i <= $#char; $i++) {
10069 189 50 33     558  
    50 33        
    100          
    100          
    50          
    50          
10070 372         2823 # "\L\u" --> "\u\L"
10071             if (($char[$i] eq '\L') and ($char[$i+1] eq '\u')) {
10072             @char[$i,$i+1] = @char[$i+1,$i];
10073             }
10074              
10075 0         0 # "\U\l" --> "\l\U"
10076             elsif (($char[$i] eq '\U') and ($char[$i+1] eq '\l')) {
10077             @char[$i,$i+1] = @char[$i+1,$i];
10078             }
10079              
10080 0         0 # octal escape sequence
10081             elsif ($char[$i] =~ /\A \\o \{ ([0-7]+) \} \z/oxms) {
10082             $char[$i] = Ekps9566::octchr($1);
10083             }
10084              
10085 1         3 # hexadecimal escape sequence
10086             elsif ($char[$i] =~ /\A \\x \{ ([0-9A-Fa-f]+) \} \z/oxms) {
10087             $char[$i] = Ekps9566::hexchr($1);
10088             }
10089              
10090             # \b{...} --> b\{...}
10091             # \B{...} --> B\{...}
10092             # \N{CHARNAME} --> N\{CHARNAME}
10093             # \p{PROPERTY} --> p\{PROPERTY}
10094 1         4 # \P{PROPERTY} --> P\{PROPERTY}
10095             elsif ($char[$i] =~ /\A \\ ([bBNpP]) ( \{ ([^\x81-\xFE0-9\}][^\x81-\xFE\}]*) \} ) \z/oxms) {
10096             $char[$i] = $1 . '\\' . $2;
10097             }
10098              
10099 0         0 # \p, \P, \X --> p, P, X
10100             elsif ($char[$i] =~ /\A \\ ( [pPX] ) \z/oxms) {
10101             $char[$i] = $1;
10102 0 50 100     0 }
    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          
10103              
10104             if (0) {
10105             }
10106 372         4099  
10107 0         0 # escape last octet of multiple-octet
10108             elsif ($char[$i] =~ /\A \\? ([\x80-\xFF].*) ($metachar|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
10109             $char[$i] = $1 . '\\' . $2;
10110             }
10111              
10112 0 0 0     0 # join separated multiple-octet
    0 0        
    0 0        
      0        
      0        
      0        
10113 0         0 elsif ($char[$i] =~ /\A (?: \\ [0-7]{2,3} | \\x [0-9A-Fa-f]{1,2}) \z/oxms) {
10114             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)) {
10115             $char[$i] .= join '', splice @char, $i+1, 3;
10116 0         0 }
10117             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)) {
10118             $char[$i] .= join '', splice @char, $i+1, 2;
10119 0         0 }
10120             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)) {
10121             $char[$i] .= join '', splice @char, $i+1, 1;
10122             }
10123             }
10124              
10125 0         0 # open character class [...]
10126 3 50       6 elsif ($char[$i] eq '[') {
10127 3         9 my $left = $i;
10128             if ($char[$i+1] eq ']') {
10129 0         0 $i++;
10130 3 50       6 }
10131 7         13 while (1) {
10132             if (++$i > $#char) {
10133 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
10134 7         16 }
10135             if ($char[$i] eq ']') {
10136             my $right = $i;
10137 3 50       5  
10138 3         21 # [...]
  0         0  
10139             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
10140             splice @char, $left, $right-$left+1, sprintf(q{@{[Ekps9566::charlist_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
10141 0         0 }
10142             else {
10143             splice @char, $left, $right-$left+1, Ekps9566::charlist_qr(@char[$left+1..$right-1], $modifier);
10144 3         41 }
10145 3         6  
10146             $i = $left;
10147             last;
10148             }
10149             }
10150             }
10151              
10152 3         10 # open character class [^...]
10153 1 50       3 elsif ($char[$i] eq '[^') {
10154 1         4 my $left = $i;
10155             if ($char[$i+1] eq ']') {
10156 0         0 $i++;
10157 1 50       2 }
10158 2         6 while (1) {
10159             if (++$i > $#char) {
10160 0 100       0 die __FILE__, ": Unmatched [] in regexp\n";
10161 2         4 }
10162             if ($char[$i] eq ']') {
10163             my $right = $i;
10164 1 50       2  
10165 1         8 # [^...]
  0         0  
10166             if (grep(/\A [\$\@]/oxms,@char[$left+1..$right-1]) >= 1) {
10167             splice @char, $left, $right-$left+1, sprintf(q{@{[Ekps9566::charlist_not_qr(%s,'%s')]}}, join(',', map {qq_stuff($delimiter,$end_delimiter,$_)} @char[$left+1..$right-1]), $modifier);
10168 0         0 }
10169             else {
10170             splice @char, $left, $right-$left+1, Ekps9566::charlist_not_qr(@char[$left+1..$right-1], $modifier);
10171 1         8 }
10172 1         2  
10173             $i = $left;
10174             last;
10175             }
10176             }
10177             }
10178              
10179 1         3 # rewrite character class or escape character
10180             elsif (my $char = character_class($char[$i],$modifier)) {
10181             $char[$i] = $char;
10182             }
10183              
10184             # P.794 29.2.161. split
10185             # in Chapter 29: Functions
10186             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
10187              
10188             # P.951 split
10189             # in Chapter 27: Functions
10190             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
10191              
10192             # said "The //m modifier is assumed when you split on the pattern /^/",
10193             # but perl5.008 is not so. Therefore, this software adds //m.
10194             # (and so on)
10195              
10196 5         21 # split(m/^/) --> split(m/^/m)
10197             elsif (($char[$i] eq '^') and ($modifier !~ /m/oxms)) {
10198             $modifier .= 'm';
10199             }
10200              
10201 11 50       41 # /i modifier
10202 18         86 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ekps9566::uc($char[$i]) ne Ekps9566::fc($char[$i]))) {
10203             if (CORE::length(Ekps9566::fc($char[$i])) == 1) {
10204             $char[$i] = '[' . Ekps9566::uc($char[$i]) . Ekps9566::fc($char[$i]) . ']';
10205 18         50 }
10206             else {
10207             $char[$i] = '(?:' . Ekps9566::uc($char[$i]) . '|' . Ekps9566::fc($char[$i]) . ')';
10208             }
10209             }
10210              
10211 0 50       0 # \u \l \U \L \F \Q \E
10212 2         8 elsif ($char[$i] =~ /\A ([<>]) \z/oxms) {
10213             if ($right_e < $left_e) {
10214             $char[$i] = '\\' . $char[$i];
10215             }
10216 0         0 }
10217 0         0 elsif ($char[$i] eq '\u') {
10218             $char[$i] = '@{[Ekps9566::ucfirst qq<';
10219             $left_e++;
10220 0         0 }
10221 0         0 elsif ($char[$i] eq '\l') {
10222             $char[$i] = '@{[Ekps9566::lcfirst qq<';
10223             $left_e++;
10224 0         0 }
10225 0         0 elsif ($char[$i] eq '\U') {
10226             $char[$i] = '@{[Ekps9566::uc qq<';
10227             $left_e++;
10228 0         0 }
10229 0         0 elsif ($char[$i] eq '\L') {
10230             $char[$i] = '@{[Ekps9566::lc qq<';
10231             $left_e++;
10232 0         0 }
10233 0         0 elsif ($char[$i] eq '\F') {
10234             $char[$i] = '@{[Ekps9566::fc qq<';
10235             $left_e++;
10236 0         0 }
10237 0         0 elsif ($char[$i] eq '\Q') {
10238             $char[$i] = '@{[CORE::quotemeta qq<';
10239             $left_e++;
10240 0 0       0 }
10241 0         0 elsif ($char[$i] eq '\E') {
10242 0         0 if ($right_e < $left_e) {
10243             $char[$i] = '>]}';
10244             $right_e++;
10245 0         0 }
10246             else {
10247             $char[$i] = '';
10248             }
10249 0         0 }
10250 0 0       0 elsif ($char[$i] eq '\Q') {
10251 0         0 while (1) {
10252             if (++$i > $#char) {
10253 0 0       0 last;
10254 0         0 }
10255             if ($char[$i] eq '\E') {
10256             last;
10257             }
10258             }
10259             }
10260             elsif ($char[$i] eq '\E') {
10261             }
10262              
10263 0 0       0 # $0 --> $0
10264 0         0 elsif ($char[$i] =~ /\A \$ 0 \z/oxms) {
10265             if ($ignorecase) {
10266             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10267             }
10268 0 0       0 }
10269 0         0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) 0 (?>\s*) \} \z/oxms) {
10270             if ($ignorecase) {
10271             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10272             }
10273             }
10274              
10275             # $$ --> $$
10276             elsif ($char[$i] =~ /\A \$\$ \z/oxms) {
10277             }
10278              
10279             # $1, $2, $3 --> $2, $3, $4 after s/// with multibyte anchoring
10280 0         0 # $1, $2, $3 --> $1, $2, $3 otherwise
10281 0 0       0 elsif ($char[$i] =~ /\A \$ ((?>[1-9][0-9]*)) \z/oxms) {
10282 0         0 $char[$i] = e_capture($1);
10283             if ($ignorecase) {
10284             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10285             }
10286 0         0 }
10287 0 0       0 elsif ($char[$i] =~ /\A \$ \{ (?>\s*) ((?>[1-9][0-9]*)) (?>\s*) \} \z/oxms) {
10288 0         0 $char[$i] = e_capture($1);
10289             if ($ignorecase) {
10290             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10291             }
10292             }
10293              
10294 0         0 # $$foo[ ... ] --> $ $foo->[ ... ]
10295 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \[ (?:$qq_bracket)*? \] ) \z/oxms) {
10296 0         0 $char[$i] = e_capture($1.'->'.$2);
10297             if ($ignorecase) {
10298             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10299             }
10300             }
10301              
10302 0         0 # $$foo{ ... } --> $ $foo->{ ... }
10303 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) ( \{ (?:$qq_brace)*? \} ) \z/oxms) {
10304 0         0 $char[$i] = e_capture($1.'->'.$2);
10305             if ($ignorecase) {
10306             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10307             }
10308             }
10309              
10310 0         0 # $$foo
10311 0 0       0 elsif ($char[$i] =~ /\A \$ ((?> \$ [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* )) \z/oxms) {
10312 0         0 $char[$i] = e_capture($1);
10313             if ($ignorecase) {
10314             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10315             }
10316             }
10317              
10318 0 50       0 # $`, ${`}, $PREMATCH, ${PREMATCH}, ${^PREMATCH} --> Ekps9566::PREMATCH()
10319 12         60 elsif ($char[$i] =~ /\A ( \$` | \$\{`\} | \$ (?>\s*) PREMATCH | \$ (?>\s*) \{ (?>\s*) PREMATCH (?>\s*) \} | \$ (?>\s*) \{\^PREMATCH\} ) \z/oxmsgc) {
10320             if ($ignorecase) {
10321             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::PREMATCH())]}';
10322 0         0 }
10323             else {
10324             $char[$i] = '@{[Ekps9566::PREMATCH()]}';
10325             }
10326             }
10327              
10328 12 50       72 # $&, ${&}, $MATCH, ${MATCH}, ${^MATCH} --> Ekps9566::MATCH()
10329 12         40 elsif ($char[$i] =~ /\A ( \$& | \$\{&\} | \$ (?>\s*) MATCH | \$ (?>\s*) \{ (?>\s*) MATCH (?>\s*) \} | \$ (?>\s*) \{\^MATCH\} ) \z/oxmsgc) {
10330             if ($ignorecase) {
10331             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::MATCH())]}';
10332 0         0 }
10333             else {
10334             $char[$i] = '@{[Ekps9566::MATCH()]}';
10335             }
10336             }
10337              
10338 12 50       62 # $POSTMATCH, ${POSTMATCH}, ${^POSTMATCH} --> Ekps9566::POSTMATCH()
10339 9         24 elsif ($char[$i] =~ /\A ( \$ (?>\s*) POSTMATCH | \$ (?>\s*) \{ (?>\s*) POSTMATCH (?>\s*) \} | \$ (?>\s*) \{\^POSTMATCH\} ) \z/oxmsgc) {
10340             if ($ignorecase) {
10341             $char[$i] = '@{[Ekps9566::ignorecase(Ekps9566::POSTMATCH())]}';
10342 0         0 }
10343             else {
10344             $char[$i] = '@{[Ekps9566::POSTMATCH()]}';
10345             }
10346             }
10347              
10348 9 0       43 # ${ foo }
10349 0         0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ((?> \s* [A-Za-z_][A-Za-z0-9_]*(?: ::[A-Za-z_][A-Za-z0-9_]*)* \s* )) \} \z/oxms) {
10350             if ($ignorecase) {
10351             $char[$i] = '@{[Ekps9566::ignorecase(' . $1 . ')]}';
10352             }
10353             }
10354              
10355 0         0 # ${ ... }
10356 0 0       0 elsif ($char[$i] =~ /\A \$ (?>\s*) \{ ( .+ ) \} \z/oxms) {
10357 0         0 $char[$i] = e_capture($1);
10358             if ($ignorecase) {
10359             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10360             }
10361             }
10362              
10363 0         0 # $scalar or @array
10364 3 50       11 elsif ($char[$i] =~ /\A [\$\@].+ /oxms) {
10365 3         23 $char[$i] = e_string($char[$i]);
10366             if ($ignorecase) {
10367             $char[$i] = '@{[Ekps9566::ignorecase(' . $char[$i] . ')]}';
10368             }
10369             }
10370              
10371 0 100       0 # quote character before ? + * {
10372             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
10373             if ($char[$i-1] =~ /\A (?:[\x00-\xFF]|\\[0-7]{2,3}|\\x[0-9-A-Fa-f]{1,2}) \z/oxms) {
10374 7         44 }
10375             else {
10376             $char[$i-1] = '(?:' . $char[$i-1] . ')';
10377             }
10378             }
10379             }
10380 4         23  
10381 189 50       439 # make regexp string
10382 189         524 $modifier =~ tr/i//d;
10383             if ($left_e > $right_e) {
10384 0         0 return join '', 'Ekps9566::split', $ope, $delimiter, @char, '>]}' x ($left_e - $right_e), $end_delimiter, $modifier;
10385             }
10386             return join '', 'Ekps9566::split', $ope, $delimiter, @char, $end_delimiter, $modifier;
10387             }
10388              
10389             #
10390             # escape regexp of split qr''
10391 189     112 0 1793 #
10392 112   100     584 sub e_split_q {
10393             my($ope,$delimiter,$end_delimiter,$string,$modifier) = @_;
10394 112         386 $modifier ||= '';
10395 112 50       230  
10396 112         320 $modifier =~ tr/p//d;
10397 0         0 if ($modifier =~ /([adlu])/oxms) {
10398 0 0       0 my $line = 0;
10399 0         0 for (my $i=0; my($package,$filename,$use_line,$subroutine) = caller($i); $i++) {
10400 0         0 if ($filename ne __FILE__) {
10401             $line = $use_line + (CORE::substr($_,0,pos($_)) =~ tr/\n//) + 1;
10402             last;
10403 0         0 }
10404             }
10405             die qq{Unsupported modifier "$1" used at line $line.\n};
10406 0         0 }
10407              
10408             $slash = 'div';
10409 112 100       181  
10410 112         281 # /b /B modifier
10411             if ($modifier =~ tr/bB//d) {
10412             return join '', 'split', $ope, $delimiter, $string, $end_delimiter, $modifier;
10413 56 100       308 }
10414              
10415             my $ignorecase = ($modifier =~ /i/oxms) ? 1 : 0;
10416 56         149  
10417             # split regexp
10418             my @char = $string =~ /\G((?>
10419             [^\x81-\xFE\\\[] |
10420             [\x81-\xFE][\x00-\xFF] |
10421             \[\^ |
10422             \[\: (?>[a-z]+) \:\] |
10423             \[\:\^ (?>[a-z]+) \:\] |
10424             \\ (?:$q_char) |
10425             (?:$q_char)
10426             ))/oxmsg;
10427 56         368  
10428 56 50 33     207 # unescape character
    50 100        
    50 66        
    50 33        
    50          
    100          
    50          
10429             for (my $i=0; $i <= $#char; $i++) {
10430             if (0) {
10431             }
10432 56         554  
10433 0         0 # escape last octet of multiple-octet
10434             elsif ($char[$i] =~ /\A ([\x80-\xFF].*) ([\\|\[\{\^]|\Q$delimiter\E|\Q$end_delimiter\E) \z/xms) {
10435             $char[$i] = $1 . '\\' . $2;
10436             }
10437              
10438 0         0 # open character class [...]
10439 0 0       0 elsif ($char[$i] eq '[') {
10440 0         0 my $left = $i;
10441             if ($char[$i+1] eq ']') {
10442 0         0 $i++;
10443 0 0       0 }
10444 0         0 while (1) {
10445             if (++$i > $#char) {
10446 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
10447 0         0 }
10448             if ($char[$i] eq ']') {
10449             my $right = $i;
10450 0         0  
10451             # [...]
10452 0         0 splice @char, $left, $right-$left+1, Ekps9566::charlist_qr(@char[$left+1..$right-1], $modifier);
10453 0         0  
10454             $i = $left;
10455             last;
10456             }
10457             }
10458             }
10459              
10460 0         0 # open character class [^...]
10461 0 0       0 elsif ($char[$i] eq '[^') {
10462 0         0 my $left = $i;
10463             if ($char[$i+1] eq ']') {
10464 0         0 $i++;
10465 0 0       0 }
10466 0         0 while (1) {
10467             if (++$i > $#char) {
10468 0 0       0 die __FILE__, ": Unmatched [] in regexp\n";
10469 0         0 }
10470             if ($char[$i] eq ']') {
10471             my $right = $i;
10472 0         0  
10473             # [^...]
10474 0         0 splice @char, $left, $right-$left+1, Ekps9566::charlist_not_qr(@char[$left+1..$right-1], $modifier);
10475 0         0  
10476             $i = $left;
10477             last;
10478             }
10479             }
10480             }
10481              
10482 0         0 # rewrite character class or escape character
10483             elsif (my $char = character_class($char[$i],$modifier)) {
10484             $char[$i] = $char;
10485             }
10486              
10487 0         0 # split(m/^/) --> split(m/^/m)
10488             elsif (($char[$i] eq '^') and ($modifier !~ /m/oxms)) {
10489             $modifier .= 'm';
10490             }
10491              
10492 0 50       0 # /i modifier
10493 12         31 elsif ($ignorecase and ($char[$i] =~ /\A [\x00-\xFF] \z/oxms) and (Ekps9566::uc($char[$i]) ne Ekps9566::fc($char[$i]))) {
10494             if (CORE::length(Ekps9566::fc($char[$i])) == 1) {
10495             $char[$i] = '[' . Ekps9566::uc($char[$i]) . Ekps9566::fc($char[$i]) . ']';
10496 12         32 }
10497             else {
10498             $char[$i] = '(?:' . Ekps9566::uc($char[$i]) . '|' . Ekps9566::fc($char[$i]) . ')';
10499             }
10500             }
10501              
10502 0 0       0 # quote character before ? + * {
10503             elsif (($i >= 1) and ($char[$i] =~ /\A [\?\+\*\{] \z/oxms)) {
10504             if ($char[$i-1] =~ /\A [\x00-\xFF] \z/oxms) {
10505 0         0 }
10506             else {
10507             $char[$i-1] = '(?:' . $char[$i-1] . ')';
10508             }
10509             }
10510 0         0 }
10511 56         115  
10512             $modifier =~ tr/i//d;
10513             return join '', 'Ekps9566::split', $ope, $delimiter, @char, $end_delimiter, $modifier;
10514             }
10515              
10516             #
10517             # escape use without import
10518 56     0 0 298 #
10519             sub e_use_noimport {
10520 0           my($module) = @_;
10521              
10522 0           my $expr = _pathof($module);
10523 0            
10524             my $fh = gensym();
10525 0 0         for my $realfilename (_realfilename($expr)) {
10526 0            
10527 0           if (Ekps9566::_open_r($fh, $realfilename)) {
10528 0 0         local $/ = undef; # slurp mode
10529             my $script = <$fh>;
10530 0 0         close($fh) or die "Can't close file: $realfilename: $!";
10531 0            
10532             if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
10533 0           return qq;
10534             }
10535             last;
10536             }
10537 0           }
10538              
10539             return qq;
10540             }
10541              
10542             #
10543             # escape no without unimport
10544 0     0 0   #
10545             sub e_no_nounimport {
10546 0           my($module) = @_;
10547              
10548 0           my $expr = _pathof($module);
10549 0            
10550             my $fh = gensym();
10551 0 0         for my $realfilename (_realfilename($expr)) {
10552 0            
10553 0           if (Ekps9566::_open_r($fh, $realfilename)) {
10554 0 0         local $/ = undef; # slurp mode
10555             my $script = <$fh>;
10556 0 0         close($fh) or die "Can't close file: $realfilename: $!";
10557 0            
10558             if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
10559 0           return qq;
10560             }
10561             last;
10562             }
10563 0           }
10564              
10565             return qq;
10566             }
10567              
10568             #
10569             # escape use with import no parameter
10570 0     0 0   #
10571             sub e_use_noparam {
10572 0           my($module) = @_;
10573              
10574 0           my $expr = _pathof($module);
10575 0            
10576             my $fh = gensym();
10577 0 0         for my $realfilename (_realfilename($expr)) {
10578 0            
10579 0           if (Ekps9566::_open_r($fh, $realfilename)) {
10580 0 0         local $/ = undef; # slurp mode
10581             my $script = <$fh>;
10582 0 0         close($fh) or die "Can't close file: $realfilename: $!";
10583              
10584             if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
10585              
10586             # P.326 UNIVERSAL: The Ultimate Ancestor Class
10587             # in Chapter 12: Objects
10588             # of ISBN 0-596-00027-8 Programming Perl Third Edition.
10589              
10590             # P.435 UNIVERSAL: The Ultimate Ancestor Class
10591             # in Chapter 12: Objects
10592             # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
10593              
10594 0           # (and so on)
10595              
10596 0           return qq[BEGIN { Ekps9566::require '$expr'; $module->import() if $module->can('import'); }];
10597             }
10598             last;
10599             }
10600 0           }
10601              
10602             return qq;
10603             }
10604              
10605             #
10606             # escape no with unimport no parameter
10607 0     0 0   #
10608             sub e_no_noparam {
10609 0           my($module) = @_;
10610              
10611 0           my $expr = _pathof($module);
10612 0            
10613             my $fh = gensym();
10614 0 0         for my $realfilename (_realfilename($expr)) {
10615 0            
10616 0           if (Ekps9566::_open_r($fh, $realfilename)) {
10617 0 0         local $/ = undef; # slurp mode
10618             my $script = <$fh>;
10619 0 0         close($fh) or die "Can't close file: $realfilename: $!";
10620 0            
10621             if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
10622 0           return qq[BEGIN { Ekps9566::require '$expr'; $module->unimport() if $module->can('unimport'); }];
10623             }
10624             last;
10625             }
10626 0           }
10627              
10628             return qq;
10629             }
10630              
10631             #
10632             # escape use with import parameters
10633 0     0 0   #
10634             sub e_use {
10635 0           my($module,$list) = @_;
10636              
10637 0           my $expr = _pathof($module);
10638 0            
10639             my $fh = gensym();
10640 0 0         for my $realfilename (_realfilename($expr)) {
10641 0            
10642 0           if (Ekps9566::_open_r($fh, $realfilename)) {
10643 0 0         local $/ = undef; # slurp mode
10644             my $script = <$fh>;
10645 0 0         close($fh) or die "Can't close file: $realfilename: $!";
10646 0            
10647             if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
10648 0           return qq[BEGIN { Ekps9566::require '$expr'; $module->import($list) if $module->can('import'); }];
10649             }
10650             last;
10651             }
10652 0           }
10653              
10654             return qq;
10655             }
10656              
10657             #
10658             # escape no with unimport parameters
10659 0     0 0   #
10660             sub e_no {
10661 0           my($module,$list) = @_;
10662              
10663 0           my $expr = _pathof($module);
10664 0            
10665             my $fh = gensym();
10666 0 0         for my $realfilename (_realfilename($expr)) {
10667 0            
10668 0           if (Ekps9566::_open_r($fh, $realfilename)) {
10669 0 0         local $/ = undef; # slurp mode
10670             my $script = <$fh>;
10671 0 0         close($fh) or die "Can't close file: $realfilename: $!";
10672 0            
10673             if ($script =~ /^ (?>\s*) use (?>\s+) KPS9566 (?>\s*) ([^\x81-\xFE;]*) ; (?>\s*) \n? $/oxms) {
10674 0           return qq[BEGIN { Ekps9566::require '$expr'; $module->unimport($list) if $module->can('unimport'); }];
10675             }
10676             last;
10677             }
10678 0           }
10679              
10680             return qq;
10681             }
10682              
10683             #
10684             # file path of module
10685 0     0     #
10686             sub _pathof {
10687 0 0         my($expr) = @_;
10688 0            
10689             if ($^O eq 'MacOS') {
10690             $expr =~ s#::#:#g;
10691 0           }
10692             else {
10693 0 0         $expr =~ s#::#/#g;
10694             }
10695 0           $expr .= '.pm' if $expr !~ / \.pm \z/oxmsi;
10696              
10697             return $expr;
10698             }
10699              
10700             #
10701             # real file name of module
10702 0     0     #
10703             sub _realfilename {
10704 0 0         my($expr) = @_;
10705 0            
  0            
10706             if ($^O eq 'MacOS') {
10707             return map {"$_$expr"} @INC;
10708 0           }
  0            
10709             else {
10710             return map {"$_/$expr"} @INC;
10711             }
10712             }
10713              
10714             #
10715             # instead of Carp::carp
10716 0     0 0   #
10717 0           sub carp {
10718             my($package,$filename,$line) = caller(1);
10719             print STDERR "@_ at $filename line $line.\n";
10720             }
10721              
10722             #
10723             # instead of Carp::croak
10724 0     0 0   #
10725 0           sub croak {
10726 0           my($package,$filename,$line) = caller(1);
10727             print STDERR "@_ at $filename line $line.\n";
10728             die "\n";
10729             }
10730              
10731             #
10732             # instead of Carp::cluck
10733 0     0 0   #
10734 0           sub cluck {
10735 0           my $i = 0;
10736 0           my @cluck = ();
10737 0           while (my($package,$filename,$line,$subroutine) = caller($i)) {
10738             push @cluck, "[$i] $filename($line) $package::$subroutine\n";
10739 0           $i++;
10740 0           }
10741 0           print STDERR CORE::reverse @cluck;
10742             print STDERR "\n";
10743             print STDERR @_;
10744             }
10745              
10746             #
10747             # instead of Carp::confess
10748 0     0 0   #
10749 0           sub confess {
10750 0           my $i = 0;
10751 0           my @confess = ();
10752 0           while (my($package,$filename,$line,$subroutine) = caller($i)) {
10753             push @confess, "[$i] $filename($line) $package::$subroutine\n";
10754 0           $i++;
10755 0           }
10756 0           print STDERR CORE::reverse @confess;
10757 0           print STDERR "\n";
10758             print STDERR @_;
10759             die "\n";
10760             }
10761              
10762             1;
10763              
10764             __END__