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