| 1 | package Windows1258; | ||||||||||||||||||||||||||||
| 2 | 212 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 212 | ▶ | BEGIN { $INC{'warnings.pm'} = '' if $] < 5.006 } use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 4 | ###################################################################### | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # Windows1258 - Source code filter to escape Windows-1258 script | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # http://search.cpan.org/dist/Char-Windows1258/ | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018, 2019 INABA Hitoshi <ina@cpan.org> | ||||||||||||||||||||||||||||
| 11 | ###################################################################### | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 212 | ▶ | use 5.00503; # Galapagos Consensus 1998 for primetools | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 = CORE::eval $VERSION; # No!! because '1.10' makes '1.1' | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 212 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 212 | $VERSION = '1.22'; | |||||||||||||||||||||||||||
| 30 | 212 | $VERSION = $VERSION; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 212 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 33 | 212 | ▶ | if ($^X =~ / jperl /oxmsi) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | die __FILE__, ": needs perl(not jperl) 5.00503 or later. (\$^X==$^X)\n"; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 212 | if (CORE::ord('A') == 193) { | |||||||||||||||||||||||||||
| 37 | die __FILE__, ": is not US-ASCII script (may be EBCDIC or EBCDIK script).\n"; | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 212 | if (CORE::ord('A') != 0x41) { | |||||||||||||||||||||||||||
| 40 | die __FILE__, ": is not US-ASCII script (must be US-ASCII script).\n"; | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 212 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 212 | (my $dirname = __FILE__) =~ s{^(.+)/[^/]*$}{$1}; | |||||||||||||||||||||||||||
| 46 | 212 | unshift @INC, $dirname; | |||||||||||||||||||||||||||
| 47 | 212 | CORE::require Ewindows1258; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # instead of Symbol.pm | ||||||||||||||||||||||||||||
| 51 | BEGIN { | ||||||||||||||||||||||||||||
| 52 | 636 | ▶ | sub gensym () { | ||||||||||||||||||||||||||
|
Subroutine
gensym: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 636 | ▶ | if ($] < 5.006) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | return \do { local *_ }; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 636 | return undef; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # P.714 29.2.39. flock | ||||||||||||||||||||||||||||
| 63 | # in Chapter 29: Functions | ||||||||||||||||||||||||||||
| 64 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # P.863 flock | ||||||||||||||||||||||||||||
| 67 | # in Chapter 27: Functions | ||||||||||||||||||||||||||||
| 68 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # P.228 Inlining Constant Functions | ||||||||||||||||||||||||||||
| 71 | # in Chapter 6: Subroutines | ||||||||||||||||||||||||||||
| 72 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # P.331 Inlining Constant Functions | ||||||||||||||||||||||||||||
| 75 | # in Chapter 7: Subroutines | ||||||||||||||||||||||||||||
| 76 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub LOCK_SH() {1} | ||||||||||||||||||||||||||||
| 79 | sub LOCK_EX() {2} | ||||||||||||||||||||||||||||
| 80 | sub LOCK_UN() {8} | ||||||||||||||||||||||||||||
| 81 | sub LOCK_NB() {4} | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub unimport {} | ||||||||||||||||||||||||||
|
Subroutine
unimport: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | sub Windows1258::escape_script; | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # 6.18. Matching Multiple-Byte Characters | ||||||||||||||||||||||||||||
| 87 | # in Chapter 6. Pattern Matching | ||||||||||||||||||||||||||||
| 88 | # of ISBN 978-1-56592-243-3 Perl Perl Cookbook. | ||||||||||||||||||||||||||||
| 89 | # (and so on) | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # regexp of character | ||||||||||||||||||||||||||||
| 92 | 212 | my $qq_char = qr/(?> \\c[\x40-\x5F] | \\? (?:[\x00-\xFF] | [\x00-\xFF]) )/oxms; | |||||||||||||||||||||||||||
| 93 | 212 | my $q_char = qr/(?> [\x00-\xFF] | [\x00-\xFF] )/oxms; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # when this script is main program | ||||||||||||||||||||||||||||
| 96 | 212 | ▶ | if ($0 eq __FILE__) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # show usage | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | unless (@ARGV) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | die <<END; | |||||||||||||||||||||||||||
| 101 | $0: usage | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | perl $0 Windows-1258_script.pl > Escaped_script.pl.e | ||||||||||||||||||||||||||||
| 104 | END | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | print Windows1258::escape_script($ARGV[0]); | |||||||||||||||||||||||||||
| 108 | 0 | exit 0; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 212 | my($package,$filename,$line,$subroutine,$hasargs,$wantarray,$evaltext,$is_require,$hints,$bitmask) = caller 0; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # called any package not main | ||||||||||||||||||||||||||||
| 114 | 212 | ▶ | if ($package ne 'main') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | die <<END; | |||||||||||||||||||||||||||
| 116 | 0 | @{[__FILE__]}: escape by manually command '$^X @{[__FILE__]} "$filename" > "@{[__PACKAGE__]}::$filename"' | |||||||||||||||||||||||||||
| 117 | 0 | and rewrite "use $package;" to "use @{[__PACKAGE__]}::$package;" of script "$0". | |||||||||||||||||||||||||||
| 118 | END | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # P.302 Module Privacy and the Exporter | ||||||||||||||||||||||||||||
| 122 | # in Chapter 11: Modules | ||||||||||||||||||||||||||||
| 123 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 124 | # | ||||||||||||||||||||||||||||
| 125 | # A module can do anything it jolly well pleases when it's used, since use just | ||||||||||||||||||||||||||||
| 126 | # calls the ordinary import method for the module, and you can define that | ||||||||||||||||||||||||||||
| 127 | # method to do anything you like. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # P.406 Module Privacy and the Exporter | ||||||||||||||||||||||||||||
| 130 | # in Chapter 11: Modules | ||||||||||||||||||||||||||||
| 131 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||
| 133 | # A module can do anything it jolly well pleases when it's used, since use just | ||||||||||||||||||||||||||||
| 134 | # calls the ordinary import method for the module, and you can define that | ||||||||||||||||||||||||||||
| 135 | # method to do anything you like. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 212 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=18 SCAR=41.9
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 212 | ▶ | if (-e("$filename.e")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if (exists $ENV{'CHAR_DEBUG'}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 141 | 0 | unlink "$filename.e"; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | elsif (-z("$filename.e")) { | ||||||||||||||||||||||||||||
| 144 | 0 | unlink "$filename.e"; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | else { | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | #---------------------------------------------------- | ||||||||||||||||||||||||||||
| 149 | # older > | ||||||||||||||||||||||||||||
| 150 | # newer >>>>> | ||||||||||||||||||||||||||||
| 151 | #---------------------------------------------------- | ||||||||||||||||||||||||||||
| 152 | # Filter > | ||||||||||||||||||||||||||||
| 153 | # Source >>>>> | ||||||||||||||||||||||||||||
| 154 | # Escape >>> needs re-escape (Source was changed) | ||||||||||||||||||||||||||||
| 155 | # | ||||||||||||||||||||||||||||
| 156 | # Filter >>> | ||||||||||||||||||||||||||||
| 157 | # Source >>>>> | ||||||||||||||||||||||||||||
| 158 | # Escape > needs re-escape (Source was changed) | ||||||||||||||||||||||||||||
| 159 | # | ||||||||||||||||||||||||||||
| 160 | # Filter >>>>> | ||||||||||||||||||||||||||||
| 161 | # Source >>> | ||||||||||||||||||||||||||||
| 162 | # Escape > needs re-escape (Source was changed) | ||||||||||||||||||||||||||||
| 163 | # | ||||||||||||||||||||||||||||
| 164 | # Filter >>>>> | ||||||||||||||||||||||||||||
| 165 | # Source > | ||||||||||||||||||||||||||||
| 166 | # Escape >>> needs re-escape (Filter was changed) | ||||||||||||||||||||||||||||
| 167 | # | ||||||||||||||||||||||||||||
| 168 | # Filter > | ||||||||||||||||||||||||||||
| 169 | # Source >>> | ||||||||||||||||||||||||||||
| 170 | # Escape >>>>> executable without re-escape | ||||||||||||||||||||||||||||
| 171 | # | ||||||||||||||||||||||||||||
| 172 | # Filter >>> | ||||||||||||||||||||||||||||
| 173 | # Source > | ||||||||||||||||||||||||||||
| 174 | # Escape >>>>> executable without re-escape | ||||||||||||||||||||||||||||
| 175 | #---------------------------------------------------- | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | my $mtime_filter = (stat(__FILE__ ))[9]; | |||||||||||||||||||||||||||
| 178 | 0 | my $mtime_source = (stat($filename ))[9]; | |||||||||||||||||||||||||||
| 179 | 0 | my $mtime_escape = (stat("$filename.e"))[9]; | |||||||||||||||||||||||||||
| 180 | 0 | ▶ | if (($mtime_escape < $mtime_source) or ($mtime_escape < $mtime_filter)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mtime_escape < $mtime_source or $mtime_escape < $mtime_filter
MC/DC0%0/2
$mtime_escape < $mtime_source or $mtime_escape < $mtime_filter
$mtime_escape < $mtime_source
$mtime_escape < $mtime_filter
Truth table0%0/3
A or B
A= $mtime_escape < $mtime_sourceB= $mtime_escape < $mtime_filter
| |||||||||||||||||||||||||||||
| 181 | 0 | unlink "$filename.e"; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 212 | ▶ | if (not -e("$filename.e")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 212 | my $fh = gensym(); | |||||||||||||||||||||||||||
| 188 | 212 | ▶ | Ewindows1258::_open_a($fh, "$filename.e") or die __FILE__, ": Can't write open file: $filename.e\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # 7.19. Flushing Output | ||||||||||||||||||||||||||||
| 191 | # in Chapter 7. File Access | ||||||||||||||||||||||||||||
| 192 | # of ISBN 0-596-00313-7 Perl Cookbook, 2nd Edition. | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 212 | select((select($fh), $|=1)[0]); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 212 | ▶ | if (0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | elsif (exists $ENV{'CHAR_NONBLOCK'}) { | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # P.419 File Locking | ||||||||||||||||||||||||||||
| 201 | # in Chapter 16: Interprocess Communication | ||||||||||||||||||||||||||||
| 202 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # P.524 File Locking | ||||||||||||||||||||||||||||
| 205 | # in Chapter 15: Interprocess Communication | ||||||||||||||||||||||||||||
| 206 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # P.571 Handling Race Conditions | ||||||||||||||||||||||||||||
| 209 | # in Chapter 23: Security | ||||||||||||||||||||||||||||
| 210 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | # P.663 Handling Race Conditions | ||||||||||||||||||||||||||||
| 213 | # in Chapter 20: Security | ||||||||||||||||||||||||||||
| 214 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | # (and so on) | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | CORE::eval q{ flock($fh, LOCK_EX | LOCK_NB) }; | |||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | die __FILE__, ": Can't immediately write-lock the file: $filename.e\n"; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||
| 224 | 212 | CORE::eval q{ flock($fh, LOCK_EX) }; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 212 | CORE::eval q{ truncate($fh, 0) }; | |||||||||||||||||||||||||||
| 228 | 212 | ▶ | seek($fh, 0, 0) or die __FILE__, ": Can't seek file: $filename.e\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 212 | my $e_script = Windows1258::escape_script($filename); | |||||||||||||||||||||||||||
| 231 | 212 | print {$fh} $e_script; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 212 | my $mode = (stat($filename))[2] & 0777; | |||||||||||||||||||||||||||
| 234 | 212 | chmod $mode, "$filename.e"; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 212 | ▶ | close($fh) or die "Can't close file: $filename.e: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 212 | my $fh = gensym(); | |||||||||||||||||||||||||||
| 240 | 212 | ▶ | Ewindows1258::_open_r($fh, "$filename.e") or die __FILE__, ": Can't read open file: $filename.e\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 212 | ▶ | if (0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | elsif (exists $ENV{'CHAR_NONBLOCK'}) { | ||||||||||||||||||||||||||||
| 245 | 0 | CORE::eval q{ flock($fh, LOCK_SH | LOCK_NB) }; | |||||||||||||||||||||||||||
| 246 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 0 | die __FILE__, ": Can't immediately read-lock the file: $filename.e\n"; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | else { | ||||||||||||||||||||||||||||
| 251 | 212 | CORE::eval q{ flock($fh, LOCK_SH) }; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 212 | my @switch = (); | |||||||||||||||||||||||||||
| 255 | 212 | ▶ | if ($^W) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | push @switch, '-w'; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | 212 | ▶ | if (defined $^I) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | push @switch, '-i' . $^I; | |||||||||||||||||||||||||||
| 260 | 0 | undef $^I; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | # P.707 29.2.33. exec | ||||||||||||||||||||||||||||
| 264 | # in Chapter 29: Functions | ||||||||||||||||||||||||||||
| 265 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 266 | # | ||||||||||||||||||||||||||||
| 267 | # If there is more than one argument in LIST, or if LIST is an array with more | ||||||||||||||||||||||||||||
| 268 | # than one value, the system shell will never be used. This also bypasses any | ||||||||||||||||||||||||||||
| 269 | # shell processing of the command. The presence or absence of metacharacters in | ||||||||||||||||||||||||||||
| 270 | # the arguments doesn't affect this list-triggered behavior, which makes it the | ||||||||||||||||||||||||||||
| 271 | # preferred from in security-conscious programs that do not with to expose | ||||||||||||||||||||||||||||
| 272 | # themselves to potential shell escapes. | ||||||||||||||||||||||||||||
| 273 | # Environment variable PERL5SHELL(Microsoft ports only) will never be used, too. | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | # P.855 exec | ||||||||||||||||||||||||||||
| 276 | # in Chapter 27: Functions | ||||||||||||||||||||||||||||
| 277 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 278 | # | ||||||||||||||||||||||||||||
| 279 | # If there is more than one argument in LIST, or if LIST is an array with more | ||||||||||||||||||||||||||||
| 280 | # than one value, the system shell will never be used. This also bypasses any | ||||||||||||||||||||||||||||
| 281 | # shell processing of the command. The presence or absence of metacharacters in | ||||||||||||||||||||||||||||
| 282 | # the arguments doesn't affect this list-triggered behavior, which makes it the | ||||||||||||||||||||||||||||
| 283 | # preferred from in security-conscious programs that do not wish to expose | ||||||||||||||||||||||||||||
| 284 | # themselves to injection attacks via shell escapes. | ||||||||||||||||||||||||||||
| 285 | # Environment variable PERL5SHELL(Microsoft ports only) will never be used, too. | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | # P.489 #! and Quoting on Non-Unix Systems | ||||||||||||||||||||||||||||
| 288 | # in Chapter 19: The Command-Line Interface | ||||||||||||||||||||||||||||
| 289 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | # P.578 #! and Quoting on Non-Unix Systems | ||||||||||||||||||||||||||||
| 292 | # in Chapter 17: The Command-Line Interface | ||||||||||||||||||||||||||||
| 293 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 212 | my $system = 0; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | # DOS-like system | ||||||||||||||||||||||||||||
| 298 | 212 | ▶ | if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | $system = Ewindows1258::_systemx( | ||||||||||||||||||||||||||||
| 300 | _escapeshellcmd_MSWin32($^X), | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # -I switch can not treat space included path | ||||||||||||||||||||||||||||
| 303 | # (map { '-I' . _escapeshellcmd_MSWin32($_) } @INC), | ||||||||||||||||||||||||||||
| 304 | 0 | (map { '-I' . $_ } @INC), | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | @switch, | ||||||||||||||||||||||||||||
| 307 | '--', | ||||||||||||||||||||||||||||
| 308 | 0 | map { _escapeshellcmd_MSWin32($_) } "$filename.e", @ARGV | |||||||||||||||||||||||||||
| 309 | ); | ||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | # UNIX-like system | ||||||||||||||||||||||||||||
| 313 | else { | ||||||||||||||||||||||||||||
| 314 | $system = Ewindows1258::_systemx( | ||||||||||||||||||||||||||||
| 315 | _escapeshellcmd($^X), | ||||||||||||||||||||||||||||
| 316 | 1908 | (map { '-I' . _escapeshellcmd($_) } @INC), | |||||||||||||||||||||||||||
| 317 | @switch, | ||||||||||||||||||||||||||||
| 318 | '--', | ||||||||||||||||||||||||||||
| 319 | 212 | map { _escapeshellcmd($_) } "$filename.e", @ARGV | |||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # exit with actual exit value | ||||||||||||||||||||||||||||
| 324 | 212 | exit($system >> 8); | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # escape shell command line on DOS-like system | ||||||||||||||||||||||||||||
| 328 | 0 | ▶ | sub _escapeshellcmd_MSWin32 { | ||||||||||||||||||||||||||
|
Subroutine
_escapeshellcmd_MSWin32: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 329 | 0 | my($word) = @_; | |||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ($word =~ / [ ] /oxms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 0 | return qq{"$word"}; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | else { | ||||||||||||||||||||||||||||
| 334 | 0 | return $word; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # escape shell command line on UNIX-like system | ||||||||||||||||||||||||||||
| 339 | 2332 | ▶ | sub _escapeshellcmd { | ||||||||||||||||||||||||||
|
Subroutine
_escapeshellcmd: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 340 | 2332 | my($word) = @_; | |||||||||||||||||||||||||||
| 341 | 2332 | return $word; | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | # P.619 Source Filters | ||||||||||||||||||||||||||||
| 345 | # in Chapter 24: Common Practices | ||||||||||||||||||||||||||||
| 346 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | # P.718 Source Filters | ||||||||||||||||||||||||||||
| 349 | # in Chapter 21: Common Practices | ||||||||||||||||||||||||||||
| 350 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | # escape Windows-1258 script | ||||||||||||||||||||||||||||
| 353 | 212 | ▶ | sub Windows1258::escape_script { | ||||||||||||||||||||||||||
|
Subroutine
escape_script: called CC=19 SCAR=41.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 354 | 212 | my($script) = @_; | |||||||||||||||||||||||||||
| 355 | 212 | my $e_script = ''; | |||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | # read Windows-1258 script | ||||||||||||||||||||||||||||
| 358 | 212 | my $fh = gensym(); | |||||||||||||||||||||||||||
| 359 | 212 | ▶ | Ewindows1258::_open_r($fh, $script) or die __FILE__, ": Can't open file: $script\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | 212 | local $/ = undef; # slurp mode | |||||||||||||||||||||||||||
| 361 | 212 | $_ = <$fh>; | |||||||||||||||||||||||||||
| 362 | 212 | ▶ | close($fh) or die "Can't close file: $script: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 212 | ▶ | if (/^ use Ewindows1258(?:(?>\s+)(?>[0-9\.]*))?(?>\s*); $/oxms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | 0 | return $_; | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | else { | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | # #! shebang line | ||||||||||||||||||||||||||||
| 370 | 212 | ▶ | if (s/\A(#!.+?\n)//oms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 0 | my $head = $1; | |||||||||||||||||||||||||||
| 372 | 0 | $head =~ s/\bjperl\b/perl/gi; | |||||||||||||||||||||||||||
| 373 | 0 | $e_script .= $head; | |||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | # DOS-like system header | ||||||||||||||||||||||||||||
| 377 | 212 | ▶ | if (s/\A(\@rem(?>\s*)=(?>\s*)'.*?'(?>\s*);\s*\n)//oms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | my $head = $1; | |||||||||||||||||||||||||||
| 379 | 0 | $head =~ s/\bjperl\b/perl/gi; | |||||||||||||||||||||||||||
| 380 | 0 | $e_script .= $head; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | # P.618 Generating Perl in Other Languages | ||||||||||||||||||||||||||||
| 384 | # in Chapter 24: Common Practices | ||||||||||||||||||||||||||||
| 385 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | # P.717 Generating Perl in Other Languages | ||||||||||||||||||||||||||||
| 388 | # in Chapter 21: Common Practices | ||||||||||||||||||||||||||||
| 389 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 212 | ▶ | if (s/(.*^#(?>\s*)line(?>\s+)(?>[0-9]+)(?:(?>\s+)"(?:$q_char)+?")?\s*\n)//oms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 0 | my $head = $1; | |||||||||||||||||||||||||||
| 393 | 0 | $head =~ s/\bjperl\b/perl/gi; | |||||||||||||||||||||||||||
| 394 | 0 | $e_script .= $head; | |||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | # P.210 5.10.3.3. Match-time code evaluation | ||||||||||||||||||||||||||||
| 398 | # in Chapter 5: Pattern Matching | ||||||||||||||||||||||||||||
| 399 | # of ISBN 0-596-00027-8 Programming Perl Third Edition. | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | # P.255 Match-time code evaluation | ||||||||||||||||||||||||||||
| 402 | # in Chapter 5: Pattern Matching | ||||||||||||||||||||||||||||
| 403 | # of ISBN 978-0-596-00492-7 Programming Perl 4th Edition. | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | # '...' quote to avoid "Octal number in vector unsupported" on perl 5.6 | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 212 | $e_script .= sprintf("use Ewindows1258 '%s.0'; # 'quote' for perl5.6\n", $Windows1258::VERSION); # require run-time routines version | |||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | # use Windows1258 version qw(ord reverse getc); | ||||||||||||||||||||||||||||
| 410 | 212 | ▶ | if (s/^ (?>\s*) use (?>\s+) (?: Char | Windows1258 ) (?>\s*) ([^;]*) ; \s* \n? $//oxms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | # require version | ||||||||||||||||||||||||||||
| 413 | 212 | my $list = $1; | |||||||||||||||||||||||||||
| 414 | 212 | ▶ | if ($list =~ s/\A ((?>[0-9]+)\.(?>[0-9]+)) \.0 (?>\s*) //oxms) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 415 | 0 | my $version = $1; | |||||||||||||||||||||||||||
| 416 | 0 | ▶ | if ($version ne $Windows1258::VERSION) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 417 | 0 | my @file = grep -e, map {qq{$_/Windows1258.pm}} @INC; | |||||||||||||||||||||||||||
| 418 | 0 | my %file = map { $_ => 1 } @file; | |||||||||||||||||||||||||||
| 419 | 0 | ▶ | if (scalar(keys %file) >= 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | 0 | my $file = join "\n", sort keys %file; | |||||||||||||||||||||||||||
| 421 | 0 | warn <<END; | |||||||||||||||||||||||||||
| 422 | **************************************************** | ||||||||||||||||||||||||||||
| 423 | C A U T I O N | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | CONFLICT Windows1258.pm FILE | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | $file | ||||||||||||||||||||||||||||
| 428 | **************************************************** | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | END | ||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | 0 | die "Script $0 expects Windows1258.pm $version, but @{[__FILE__]} is version $Windows1258::VERSION\n"; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | 0 | $e_script .= qq{die "Script \$0 expects Ewindows1258.pm $version, but \\\$Ewindows1258::VERSION is \$Ewindows1258::VERSION" if \$Ewindows1258::VERSION ne '$version';\n}; | |||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | elsif ($list =~ s/\A ((?>[0-9]+)(?>\.[0-9]*)) (?>\s*) //oxms) { | ||||||||||||||||||||||||||||
| 437 | 0 | my $version = $1; | |||||||||||||||||||||||||||
| 438 | 0 | ▶ | if ($version > $Windows1258::VERSION) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 0 | die "Script $0 required Windows1258.pm $version, but @{[__FILE__]} is only version $Windows1258::VERSION\n"; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | # demand ord, reverse, and getc | ||||||||||||||||||||||||||||
| 444 | 212 | ▶ | if ($list !~ /\A (?>\s*) \z/oxms) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 3 | local $@; | |||||||||||||||||||||||||||
| 446 | 3 | my @list = CORE::eval $list; | |||||||||||||||||||||||||||
| 447 | 3 | for (@list) { | |||||||||||||||||||||||||||
| 448 | 3 | ▶ | $Ewindows1258::function_ord = 'Windows1258::ord' if /\A ord \z/oxms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 449 | 3 | ▶ | $Ewindows1258::function_ord_ = 'Windows1258::ord_' if /\A ord \z/oxms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | 3 | ▶ | $Ewindows1258::function_reverse = 'Windows1258::reverse' if /\A reverse \z/oxms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 451 | 3 | ▶ | $Ewindows1258::function_getc = 'Windows1258::getc' if /\A getc \z/oxms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | # avoid: used only once: possible typo at ... | ||||||||||||||||||||||||||||
| 454 | 3 | $Ewindows1258::function_ord = $Ewindows1258::function_ord; | |||||||||||||||||||||||||||
| 455 | 3 | $Ewindows1258::function_ord_ = $Ewindows1258::function_ord_; | |||||||||||||||||||||||||||
| 456 | 3 | $Ewindows1258::function_reverse = $Ewindows1258::function_reverse; | |||||||||||||||||||||||||||
| 457 | 3 | $Ewindows1258::function_getc = $Ewindows1258::function_getc; | |||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 212 | $e_script .= Windows1258::escape(); | |||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 212 | return $e_script; | |||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 212 | 1; | |||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | __END__ | ||||||||||||||||||||||||||||