codekingpro commited on
Commit
41d2134
·
verified ·
1 Parent(s): 3f07f06

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. git/usr/bin/core_perl/corelist +577 -0
  2. git/usr/bin/core_perl/cpan +352 -0
  3. git/usr/bin/core_perl/enc2xs +1484 -0
  4. git/usr/bin/core_perl/encguess +149 -0
  5. git/usr/bin/core_perl/h2ph +977 -0
  6. git/usr/bin/core_perl/h2xs +2207 -0
  7. git/usr/bin/core_perl/instmodsh +196 -0
  8. git/usr/bin/core_perl/json_pp +240 -0
  9. git/usr/bin/core_perl/libnetcfg +722 -0
  10. git/usr/bin/core_perl/perlbug +1537 -0
  11. git/usr/bin/core_perl/perlivp +392 -0
  12. git/usr/bin/core_perl/perlthanks +1537 -0
  13. git/usr/bin/core_perl/piconv +322 -0
  14. git/usr/bin/core_perl/pl2pm +378 -0
  15. git/usr/bin/core_perl/pod2html +202 -0
  16. git/usr/bin/core_perl/pod2man +519 -0
  17. git/usr/bin/core_perl/pod2text +367 -0
  18. git/usr/bin/core_perl/pod2usage +161 -0
  19. git/usr/bin/core_perl/podchecker +148 -0
  20. git/usr/bin/core_perl/prove +410 -0
  21. git/usr/bin/core_perl/ptar +151 -0
  22. git/usr/bin/core_perl/ptardiff +121 -0
  23. git/usr/etc/profile.d/gawk.csh +11 -0
  24. git/usr/etc/profile.d/gawk.sh +31 -0
  25. git/usr/lib/awk/grcat.exe +0 -0
  26. git/usr/lib/awk/pwcat.exe +0 -0
  27. git/usr/lib/coreutils/libstdbuf.dll +0 -0
  28. git/usr/lib/gawk/filefuncs.dll +0 -0
  29. git/usr/lib/gawk/fnmatch.dll +0 -0
  30. git/usr/lib/gawk/fork.dll +0 -0
  31. git/usr/lib/gawk/inplace.dll +0 -0
  32. git/usr/lib/gawk/intdiv.dll +0 -0
  33. git/usr/lib/gawk/ordchr.dll +0 -0
  34. git/usr/lib/gawk/readdir.dll +0 -0
  35. git/usr/lib/gawk/readfile.dll +0 -0
  36. git/usr/lib/gawk/revoutput.dll +0 -0
  37. git/usr/lib/gawk/revtwoway.dll +0 -0
  38. git/usr/lib/gawk/rwarray.dll +0 -0
  39. git/usr/lib/gawk/time.dll +0 -0
  40. git/usr/lib/gnupg/gpg-check-pattern.exe +0 -0
  41. git/usr/lib/gnupg/gpg-preset-passphrase.exe +0 -0
  42. git/usr/lib/gnupg/gpg-wks-client +2 -0
  43. git/usr/lib/openssl/engines-3/capi.dll +0 -0
  44. git/usr/lib/openssl/engines-3/loader_attic.dll +0 -0
  45. git/usr/lib/openssl/engines-3/padlock.dll +0 -0
  46. git/usr/lib/p11-kit/p11-kit-extract-trust +24 -0
  47. git/usr/lib/perl5/core_perl/B.pm +1432 -0
  48. git/usr/lib/perl5/core_perl/B/Concise.pm +1929 -0
  49. git/usr/lib/perl5/core_perl/B/Showlex.pm +217 -0
  50. git/usr/lib/perl5/core_perl/B/Terse.pm +104 -0
git/usr/bin/core_perl/corelist ADDED
@@ -0,0 +1,577 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!/usr/bin/perl
5
+
6
+ =head1 NAME
7
+
8
+ corelist - a commandline frontend to Module::CoreList
9
+
10
+ =head1 DESCRIPTION
11
+
12
+ See L<Module::CoreList> for one.
13
+
14
+ =head1 SYNOPSIS
15
+
16
+ corelist -v
17
+ corelist [-a|-d] <ModuleName> | /<ModuleRegex>/ [<ModuleVersion>] ...
18
+ corelist [-v <PerlVersion>] [ <ModuleName> | /<ModuleRegex>/ ] ...
19
+ corelist [-r <PerlVersion>] ...
20
+ corelist --utils [-d] <UtilityName> [<UtilityName>] ...
21
+ corelist --utils -v <PerlVersion>
22
+ corelist --feature <FeatureName> [<FeatureName>] ...
23
+ corelist --diff PerlVersion PerlVersion
24
+ corelist --upstream <ModuleName>
25
+
26
+ =head1 OPTIONS
27
+
28
+ =over
29
+
30
+ =item -a
31
+
32
+ lists all versions of the given module (or the matching modules, in case you
33
+ used a module regexp) in the perls Module::CoreList knows about.
34
+
35
+ corelist -a Unicode
36
+
37
+ Unicode was first released with perl v5.6.2
38
+ v5.6.2 3.0.1
39
+ v5.8.0 3.2.0
40
+ v5.8.1 4.0.0
41
+ v5.8.2 4.0.0
42
+ v5.8.3 4.0.0
43
+ v5.8.4 4.0.1
44
+ v5.8.5 4.0.1
45
+ v5.8.6 4.0.1
46
+ v5.8.7 4.1.0
47
+ v5.8.8 4.1.0
48
+ v5.8.9 5.1.0
49
+ v5.9.0 4.0.0
50
+ v5.9.1 4.0.0
51
+ v5.9.2 4.0.1
52
+ v5.9.3 4.1.0
53
+ v5.9.4 4.1.0
54
+ v5.9.5 5.0.0
55
+ v5.10.0 5.0.0
56
+ v5.10.1 5.1.0
57
+ v5.11.0 5.1.0
58
+ v5.11.1 5.1.0
59
+ v5.11.2 5.1.0
60
+ v5.11.3 5.2.0
61
+ v5.11.4 5.2.0
62
+ v5.11.5 5.2.0
63
+ v5.12.0 5.2.0
64
+ v5.12.1 5.2.0
65
+ v5.12.2 5.2.0
66
+ v5.12.3 5.2.0
67
+ v5.12.4 5.2.0
68
+ v5.13.0 5.2.0
69
+ v5.13.1 5.2.0
70
+ v5.13.2 5.2.0
71
+ v5.13.3 5.2.0
72
+ v5.13.4 5.2.0
73
+ v5.13.5 5.2.0
74
+ v5.13.6 5.2.0
75
+ v5.13.7 6.0.0
76
+ v5.13.8 6.0.0
77
+ v5.13.9 6.0.0
78
+ v5.13.10 6.0.0
79
+ v5.13.11 6.0.0
80
+ v5.14.0 6.0.0
81
+ v5.14.1 6.0.0
82
+ v5.15.0 6.0.0
83
+
84
+ =item -d
85
+
86
+ finds the first perl version where a module has been released by
87
+ date, and not by version number (as is the default).
88
+
89
+ =item --diff
90
+
91
+ Given two versions of perl, this prints a human-readable table of all module
92
+ changes between the two. The output format may change in the future, and is
93
+ meant for I<humans>, not programs. For programs, use the L<Module::CoreList>
94
+ API.
95
+
96
+ =item -? or -help
97
+
98
+ help! help! help! to see more help, try --man.
99
+
100
+ =item -man
101
+
102
+ all of the help
103
+
104
+ =item -v
105
+
106
+ lists all of the perl release versions we got the CoreList for.
107
+
108
+ If you pass a version argument (value of C<$]>, like C<5.00503> or C<5.008008>),
109
+ you get a list of all the modules and their respective versions.
110
+ (If you have the C<version> module, you can also use new-style version numbers,
111
+ like C<5.8.8>.)
112
+
113
+ In module filtering context, it can be used as Perl version filter.
114
+
115
+ =item -r
116
+
117
+ lists all of the perl releases and when they were released
118
+
119
+ If you pass a perl version you get the release date for that version only.
120
+
121
+ =item --utils
122
+
123
+ lists the first version of perl each named utility program was released with
124
+
125
+ May be used with -d to modify the first release criteria.
126
+
127
+ If used with -v <version> then all utilities released with that version of perl
128
+ are listed, and any utility programs named on the command line are ignored.
129
+
130
+ =item --feature, -f
131
+
132
+ lists the first version bundle of each named feature given
133
+
134
+ =item --upstream, -u
135
+
136
+ Shows if the given module is primarily maintained in perl core or on CPAN
137
+ and bug tracker URL.
138
+
139
+ =back
140
+
141
+ As a special case, if you specify the module name C<Unicode>, you'll get
142
+ the version number of the Unicode Character Database bundled with the
143
+ requested perl versions.
144
+
145
+ =cut
146
+
147
+ BEGIN { pop @INC if $INC[-1] eq '.' }
148
+ use Module::CoreList;
149
+ use Getopt::Long qw(:config no_ignore_case);
150
+ use Pod::Usage;
151
+ use strict;
152
+ use warnings;
153
+ use List::Util qw/maxstr/;
154
+
155
+ my %Opts;
156
+
157
+ GetOptions(
158
+ \%Opts,
159
+ qw[ help|?! man! r|release:s v|version:s a! d diff|D utils feature|f u|upstream ]
160
+ );
161
+
162
+ pod2usage(1) if $Opts{help};
163
+ pod2usage(-verbose=>2) if $Opts{man};
164
+
165
+ if(exists $Opts{r} ){
166
+ if ( !$Opts{r} ) {
167
+ print "\nModule::CoreList has release info for the following perl versions:\n";
168
+ my $versions = { };
169
+ my $max_ver_len = max_mod_len(\%Module::CoreList::released);
170
+ for my $ver ( grep !/0[01]0$/, sort keys %Module::CoreList::released ) {
171
+ printf "%-${max_ver_len}s %s\n", format_perl_version($ver), $Module::CoreList::released{$ver};
172
+ }
173
+ print "\n";
174
+ exit 0;
175
+ }
176
+
177
+ my $num_r = numify_version( $Opts{r} );
178
+ my $version_hash = Module::CoreList->find_version($num_r);
179
+
180
+ if( !$version_hash ) {
181
+ print "\nModule::CoreList has no info on perl $Opts{r}\n\n";
182
+ exit 1;
183
+ }
184
+
185
+ printf "Perl %s was released on %s\n\n", format_perl_version($num_r), $Module::CoreList::released{$num_r};
186
+ exit 0;
187
+ }
188
+
189
+ if(exists $Opts{v} ){
190
+ if( !$Opts{v} ) {
191
+ print "\nModule::CoreList has info on the following perl versions:\n";
192
+ print format_perl_version($_)."\n" for grep !/0[01]0$/, sort keys %Module::CoreList::version;
193
+ print "\n";
194
+ exit 0;
195
+ }
196
+
197
+ my $num_v = numify_version( $Opts{v} );
198
+
199
+ if ($Opts{utils}) {
200
+ utilities_in_version($num_v);
201
+ exit 0;
202
+ }
203
+
204
+ my $version_hash = Module::CoreList->find_version($num_v);
205
+
206
+ if( !$version_hash ) {
207
+ print "\nModule::CoreList has no info on perl $Opts{v}\n\n";
208
+ exit 1;
209
+ }
210
+
211
+ if ( !@ARGV ) {
212
+ print "\nThe following modules were in perl $Opts{v} CORE\n";
213
+ my $max_mod_len = max_mod_len($version_hash);
214
+ for my $mod ( sort keys %$version_hash ) {
215
+ printf "%-${max_mod_len}s %s\n", $mod, $version_hash->{$mod} || "";
216
+ }
217
+ print "\n";
218
+ exit 0;
219
+ }
220
+ }
221
+
222
+ if ($Opts{diff}) {
223
+ if(@ARGV != 2) {
224
+ die "\nprovide exactly two perl core versions to diff with --diff\n";
225
+ }
226
+
227
+ my ($old_ver, $new_ver) = @ARGV;
228
+
229
+ my $old = numify_version($old_ver);
230
+ if ( !Module::CoreList->find_version($old) ) {
231
+ print "\nModule::CoreList has no info on perl $old_ver\n\n";
232
+ exit 1;
233
+ }
234
+ my $new = numify_version($new_ver);
235
+ if ( !Module::CoreList->find_version($new) ) {
236
+ print "\nModule::CoreList has no info on perl $new_ver\n\n";
237
+ exit 1;
238
+ }
239
+
240
+ my %diff = Module::CoreList::changes_between($old, $new);
241
+
242
+ for my $lib (sort keys %diff) {
243
+ my $diff = $diff{$lib};
244
+
245
+ my $was = ! exists $diff->{left} ? '(absent)'
246
+ : ! defined $diff->{left} ? '(undef)'
247
+ : $diff->{left};
248
+
249
+ my $now = ! exists $diff->{right} ? '(absent)'
250
+ : ! defined $diff->{right} ? '(undef)'
251
+ : $diff->{right};
252
+
253
+ printf "%-35s %10s %10s\n", $lib, $was, $now;
254
+ }
255
+ exit(0);
256
+ }
257
+
258
+ if ($Opts{utils}) {
259
+ die "\n--utils only available with perl v5.19.1 or greater\n"
260
+ if $] < 5.019001;
261
+
262
+ die "\nprovide at least one utility name to --utils\n"
263
+ unless @ARGV;
264
+
265
+ warn "\n-a has no effect when --utils is used\n" if $Opts{a};
266
+ warn "\n--diff has no effect when --utils is used\n" if $Opts{diff};
267
+ warn "\n--upstream, or -u, has no effect when --utils is used\n" if $Opts{u};
268
+
269
+ my $when = maxstr(values %Module::CoreList::released);
270
+ print "\n","Data for $when\n";
271
+
272
+ utility_version($_) for @ARGV;
273
+
274
+ exit(0);
275
+ }
276
+
277
+ if ($Opts{feature}) {
278
+ die "\n--feature is only available with perl v5.16.0 or greater\n"
279
+ if $] < 5.016;
280
+
281
+ die "\nprovide at least one feature name to --feature\n"
282
+ unless @ARGV;
283
+
284
+ no warnings 'once';
285
+ require feature;
286
+
287
+ my %feature2version;
288
+ my @bundles = map { $_->[0] }
289
+ sort { $b->[1] <=> $a->[1] }
290
+ map { [$_, numify_version($_)] }
291
+ grep { not /[^0-9.]/ }
292
+ keys %feature::feature_bundle;
293
+
294
+ for my $version (@bundles) {
295
+ $feature2version{$_} = $version =~ /^\d\.\d+$/ ? "$version.0" : $version
296
+ for @{ $feature::feature_bundle{$version} };
297
+ }
298
+
299
+ # allow internal feature names, just in case someone gives us __SUB__
300
+ # instead of current_sub.
301
+ while (my ($name, $internal) = each %feature::feature) {
302
+ $internal =~ s/^feature_//;
303
+ $feature2version{$internal} = $feature2version{$name}
304
+ if $feature2version{$name};
305
+ }
306
+
307
+ my $when = maxstr(values %Module::CoreList::released);
308
+ print "\n","Data for $when\n";
309
+
310
+ for my $feature (@ARGV) {
311
+ print "feature \"$feature\" ",
312
+ exists $feature2version{$feature}
313
+ ? "was first released with the perl "
314
+ . format_perl_version(numify_version($feature2version{$feature}))
315
+ . " feature bundle\n"
316
+ : "doesn't exist (or so I think)\n";
317
+ }
318
+ exit(0);
319
+ }
320
+
321
+ if ( !@ARGV ) {
322
+ pod2usage(0);
323
+ }
324
+
325
+ while (@ARGV) {
326
+ my ($mod, $ver);
327
+ if ($ARGV[0] =~ /=/) {
328
+ ($mod, $ver) = split /=/, shift @ARGV;
329
+ } else {
330
+ $mod = shift @ARGV;
331
+ $ver = (@ARGV && $ARGV[0] =~ /^\d/) ? shift @ARGV : "";
332
+ }
333
+
334
+ if ($mod !~ m|^/(.*)/([imosx]*)$|) { # not a regex
335
+ module_version($mod,$ver);
336
+ } else {
337
+ my $re;
338
+ eval { $re = $2 ? qr/(?$2)($1)/ : qr/$1/; }; # trap exceptions while building regex
339
+ if ($@) {
340
+ # regex errors are usually like 'Quantifier follow nothing in regex; marked by ...'
341
+ # then we drop text after ';' to shorten message
342
+ my $errmsg = $@ =~ /(.*);/ ? $1 : $@;
343
+ warn "\n$mod is a bad regex: $errmsg\n";
344
+ next;
345
+ }
346
+ my @mod = Module::CoreList->find_modules($re);
347
+ if (@mod) {
348
+ module_version($_, $ver) for @mod;
349
+ } else {
350
+ $ver |= '';
351
+ print "\n$mod $ver has no match in CORE (or so I think)\n";
352
+ }
353
+
354
+ }
355
+ }
356
+
357
+ exit();
358
+
359
+ sub module_version {
360
+ my($mod,$ver) = @_;
361
+
362
+ if ( $Opts{v} ) {
363
+ my $numeric_v = numify_version($Opts{v});
364
+ my $version_hash = Module::CoreList->find_version($numeric_v);
365
+ if ($version_hash) {
366
+ print $mod, " ", $version_hash->{$mod} || 'undef', "\n";
367
+ return;
368
+ }
369
+ else { die "Shouldn't happen" }
370
+ }
371
+
372
+ my $ret = $Opts{d}
373
+ ? Module::CoreList->first_release_by_date(@_)
374
+ : Module::CoreList->first_release(@_);
375
+ my $msg = $mod;
376
+ $msg .= " $ver" if $ver;
377
+
378
+ my $rem = $Opts{d}
379
+ ? Module::CoreList->removed_from_by_date($mod)
380
+ : Module::CoreList->removed_from($mod);
381
+
382
+ my $when = maxstr(values %Module::CoreList::released);
383
+ print "\n","Data for $when\n";
384
+
385
+ if( defined $ret ) {
386
+ my $deprecated = Module::CoreList->deprecated_in($mod);
387
+ $msg .= " was ";
388
+ $msg .= "first " unless $ver;
389
+ $msg .= "released with perl " . format_perl_version($ret);
390
+ $msg .= ( $rem ? ',' : ' and' ) . " deprecated (will be CPAN-only) in " . format_perl_version($deprecated) if $deprecated;
391
+ $msg .= " and removed from " . format_perl_version($rem) if $rem;
392
+ } else {
393
+ $msg .= " was not in CORE (or so I think)";
394
+ }
395
+
396
+ print $msg,"\n";
397
+
398
+ if( defined $ret and exists $Opts{u} ) {
399
+ my $upstream = $Module::CoreList::upstream{$mod};
400
+ $upstream = 'undef' unless $upstream;
401
+ print "upstream: $upstream\n";
402
+ if ( $upstream ne 'blead' ) {
403
+ my $bugtracker = $Module::CoreList::bug_tracker{$mod};
404
+ $bugtracker = 'unknown' unless $bugtracker;
405
+ print "bug tracker: $bugtracker\n";
406
+ }
407
+ }
408
+
409
+ if(defined $ret and exists $Opts{a} and $Opts{a}){
410
+ display_a($mod);
411
+ }
412
+ }
413
+
414
+ sub utility_version {
415
+ my ($utility) = @_;
416
+
417
+ require Module::CoreList::Utils;
418
+
419
+ my $released = $Opts{d}
420
+ ? Module::CoreList::Utils->first_release_by_date($utility)
421
+ : Module::CoreList::Utils->first_release($utility);
422
+
423
+ my $removed = $Opts{d}
424
+ ? Module::CoreList::Utils->removed_from_by_date($utility)
425
+ : Module::CoreList::Utils->removed_from($utility);
426
+
427
+ if ($released) {
428
+ print "$utility was first released with perl ", format_perl_version($released);
429
+ print " and later removed in ", format_perl_version($removed)
430
+ if $removed;
431
+ print "\n";
432
+ } else {
433
+ print "$utility was not in CORE (or so I think)\n";
434
+ }
435
+ }
436
+
437
+ sub utilities_in_version {
438
+ my ($version) = @_;
439
+
440
+ require Module::CoreList::Utils;
441
+
442
+ my @utilities = Module::CoreList::Utils->utilities($version);
443
+
444
+ if (not @utilities) {
445
+ print "\nModule::CoreList::Utils has no info on perl $version\n\n";
446
+ exit 1;
447
+ }
448
+
449
+ print "\nThe following utilities were in perl ",
450
+ format_perl_version($version), " CORE\n";
451
+ print "$_\n" for sort { lc($a) cmp lc($b) } @utilities;
452
+ print "\n";
453
+ }
454
+
455
+
456
+ sub max_mod_len {
457
+ my $versions = shift;
458
+ my $max = 0;
459
+ for my $mod (keys %$versions) {
460
+ $max = max($max, length $mod);
461
+ }
462
+
463
+ return $max;
464
+ }
465
+
466
+ sub max {
467
+ my($this, $that) = @_;
468
+ return $this if $this > $that;
469
+ return $that;
470
+ }
471
+
472
+ sub display_a {
473
+ my $mod = shift;
474
+
475
+ for my $v (grep !/0[01]0$/, sort keys %Module::CoreList::version ) {
476
+ next unless exists $Module::CoreList::version{$v}{$mod};
477
+
478
+ my $mod_v = $Module::CoreList::version{$v}{$mod} || 'undef';
479
+ printf " %-10s %-10s\n", format_perl_version($v), $mod_v;
480
+ }
481
+ print "\n";
482
+ }
483
+
484
+
485
+ {
486
+ my $have_version_pm;
487
+ sub have_version_pm {
488
+ return $have_version_pm if defined $have_version_pm;
489
+ return $have_version_pm = eval { require version; 1 };
490
+ }
491
+ }
492
+
493
+
494
+ sub format_perl_version {
495
+ my $v = shift;
496
+ return $v if $v < 5.006 or !have_version_pm;
497
+ return version->new($v)->normal;
498
+ }
499
+
500
+
501
+ sub numify_version {
502
+ my $ver = shift;
503
+ if ($ver =~ /\..+\./) {
504
+ have_version_pm()
505
+ or die "You need to install version.pm to use dotted version numbers\n";
506
+ $ver = version->new($ver)->numify;
507
+ }
508
+ $ver += 0;
509
+ return $ver;
510
+ }
511
+
512
+ =head1 EXAMPLES
513
+
514
+ $ corelist File::Spec
515
+
516
+ File::Spec was first released with perl 5.005
517
+
518
+ $ corelist File::Spec 0.83
519
+
520
+ File::Spec 0.83 was released with perl 5.007003
521
+
522
+ $ corelist File::Spec 0.89
523
+
524
+ File::Spec 0.89 was not in CORE (or so I think)
525
+
526
+ $ corelist File::Spec::Aliens
527
+
528
+ File::Spec::Aliens was not in CORE (or so I think)
529
+
530
+ $ corelist /IPC::Open/
531
+
532
+ IPC::Open2 was first released with perl 5
533
+
534
+ IPC::Open3 was first released with perl 5
535
+
536
+ $ corelist /MANIFEST/i
537
+
538
+ ExtUtils::Manifest was first released with perl 5.001
539
+
540
+ $ corelist /Template/
541
+
542
+ /Template/ has no match in CORE (or so I think)
543
+
544
+ $ corelist -v 5.8.8 B
545
+
546
+ B 1.09_01
547
+
548
+ $ corelist -v 5.8.8 /^B::/
549
+
550
+ B::Asmdata 1.01
551
+ B::Assembler 0.07
552
+ B::Bblock 1.02_01
553
+ B::Bytecode 1.01_01
554
+ B::C 1.04_01
555
+ B::CC 1.00_01
556
+ B::Concise 0.66
557
+ B::Debug 1.02_01
558
+ B::Deparse 0.71
559
+ B::Disassembler 1.05
560
+ B::Lint 1.03
561
+ B::O 1.00
562
+ B::Showlex 1.02
563
+ B::Stackobj 1.00
564
+ B::Stash 1.00
565
+ B::Terse 1.03_01
566
+ B::Xref 1.01
567
+
568
+ =head1 COPYRIGHT
569
+
570
+ Copyright (c) 2002-2007 by D.H. aka PodMaster
571
+
572
+ Currently maintained by the perl 5 porters E<lt>perl5-porters@perl.orgE<gt>.
573
+
574
+ This program is distributed under the same terms as perl itself.
575
+ See http://perl.org/ or http://cpan.org/ for more info on that.
576
+
577
+ =cut
git/usr/bin/core_perl/cpan ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!/usr/local/bin/perl
5
+
6
+ BEGIN { pop @INC if $INC[-1] eq '.' }
7
+ use strict;
8
+ use vars qw($VERSION);
9
+
10
+ use App::Cpan;
11
+ use CPAN::Version;
12
+ my $minver = '1.64';
13
+ if ( CPAN::Version->vlt($App::Cpan::VERSION, $minver) ) {
14
+ warn "WARNING: your version of App::Cpan is $App::Cpan::VERSION while we would expect at least $minver";
15
+ }
16
+ $VERSION = '1.64';
17
+
18
+ my $rc = App::Cpan->run( @ARGV );
19
+
20
+ # will this work under Strawberry Perl?
21
+ exit( $rc || 0 );
22
+
23
+ =head1 NAME
24
+
25
+ cpan - easily interact with CPAN from the command line
26
+
27
+ =head1 SYNOPSIS
28
+
29
+ # with arguments and no switches, installs specified modules
30
+ cpan module_name [ module_name ... ]
31
+
32
+ # with switches, installs modules with extra behavior
33
+ cpan [-cfFimtTw] module_name [ module_name ... ]
34
+
35
+ # use local::lib
36
+ cpan -I module_name [ module_name ... ]
37
+
38
+ # one time mirror override for faster mirrors
39
+ cpan -p ...
40
+
41
+ # with just the dot, install from the distribution in the
42
+ # current directory
43
+ cpan .
44
+
45
+ # without arguments, starts CPAN.pm shell
46
+ cpan
47
+
48
+ # without arguments, but some switches
49
+ cpan [-ahpruvACDLOPX]
50
+
51
+ =head1 DESCRIPTION
52
+
53
+ This script provides a command interface (not a shell) to CPAN. At the
54
+ moment it uses CPAN.pm to do the work, but it is not a one-shot command
55
+ runner for CPAN.pm.
56
+
57
+ =head2 Options
58
+
59
+ =over 4
60
+
61
+ =item -a
62
+
63
+ Creates a CPAN.pm autobundle with CPAN::Shell->autobundle.
64
+
65
+ =item -A module [ module ... ]
66
+
67
+ Shows the primary maintainers for the specified modules.
68
+
69
+ =item -c module
70
+
71
+ Runs a `make clean` in the specified module's directories.
72
+
73
+ =item -C module [ module ... ]
74
+
75
+ Show the F<Changes> files for the specified modules
76
+
77
+ =item -D module [ module ... ]
78
+
79
+ Show the module details. This prints one line for each out-of-date module
80
+ (meaning, modules locally installed but have newer versions on CPAN).
81
+ Each line has three columns: module name, local version, and CPAN
82
+ version.
83
+
84
+ =item -f
85
+
86
+ Force the specified action, when it normally would have failed. Use this
87
+ to install a module even if its tests fail. When you use this option,
88
+ -i is not optional for installing a module when you need to force it:
89
+
90
+ % cpan -f -i Module::Foo
91
+
92
+ =item -F
93
+
94
+ Turn off CPAN.pm's attempts to lock anything. You should be careful with
95
+ this since you might end up with multiple scripts trying to muck in the
96
+ same directory. This isn't so much of a concern if you're loading a special
97
+ config with C<-j>, and that config sets up its own work directories.
98
+
99
+ =item -g module [ module ... ]
100
+
101
+ Downloads to the current directory the latest distribution of the module.
102
+
103
+ =item -G module [ module ... ]
104
+
105
+ UNIMPLEMENTED
106
+
107
+ Download to the current directory the latest distribution of the
108
+ modules, unpack each distribution, and create a git repository for each
109
+ distribution.
110
+
111
+ If you want this feature, check out Yanick Champoux's C<Git::CPAN::Patch>
112
+ distribution.
113
+
114
+ =item -h
115
+
116
+ Print a help message and exit. When you specify C<-h>, it ignores all
117
+ of the other options and arguments.
118
+
119
+ =item -i module [ module ... ]
120
+
121
+ Install the specified modules. With no other switches, this switch
122
+ is implied.
123
+
124
+ =item -I
125
+
126
+ Load C<local::lib> (think like C<-I> for loading lib paths). Too bad
127
+ C<-l> was already taken.
128
+
129
+ =item -j Config.pm
130
+
131
+ Load the file that has the CPAN configuration data. This should have the
132
+ same format as the standard F<CPAN/Config.pm> file, which defines
133
+ C<$CPAN::Config> as an anonymous hash.
134
+
135
+ =item -J
136
+
137
+ Dump the configuration in the same format that CPAN.pm uses. This is useful
138
+ for checking the configuration as well as using the dump as a starting point
139
+ for a new, custom configuration.
140
+
141
+ =item -l
142
+
143
+ List all installed modules with their versions
144
+
145
+ =item -L author [ author ... ]
146
+
147
+ List the modules by the specified authors.
148
+
149
+ =item -m
150
+
151
+ Make the specified modules.
152
+
153
+ =item -M mirror1,mirror2,...
154
+
155
+ A comma-separated list of mirrors to use for just this run. The C<-P>
156
+ option can find them for you automatically.
157
+
158
+ =item -n
159
+
160
+ Do a dry run, but don't actually install anything. (unimplemented)
161
+
162
+ =item -O
163
+
164
+ Show the out-of-date modules.
165
+
166
+ =item -p
167
+
168
+ Ping the configured mirrors and print a report
169
+
170
+ =item -P
171
+
172
+ Find the best mirrors you could be using and use them for the current
173
+ session.
174
+
175
+ =item -r
176
+
177
+ Recompiles dynamically loaded modules with CPAN::Shell->recompile.
178
+
179
+ =item -s
180
+
181
+ Drop in the CPAN.pm shell. This command does this automatically if you don't
182
+ specify any arguments.
183
+
184
+ =item -t module [ module ... ]
185
+
186
+ Run a `make test` on the specified modules.
187
+
188
+ =item -T
189
+
190
+ Do not test modules. Simply install them.
191
+
192
+ =item -u
193
+
194
+ Upgrade all installed modules. Blindly doing this can really break things,
195
+ so keep a backup.
196
+
197
+ =item -v
198
+
199
+ Print the script version and CPAN.pm version then exit.
200
+
201
+ =item -V
202
+
203
+ Print detailed information about the cpan client.
204
+
205
+ =item -w
206
+
207
+ UNIMPLEMENTED
208
+
209
+ Turn on cpan warnings. This checks various things, like directory permissions,
210
+ and tells you about problems you might have.
211
+
212
+ =item -x module [ module ... ]
213
+
214
+ Find close matches to the named modules that you think you might have
215
+ mistyped. This requires the optional installation of Text::Levenshtein or
216
+ Text::Levenshtein::Damerau.
217
+
218
+ =item -X
219
+
220
+ Dump all the namespaces to standard output.
221
+
222
+ =back
223
+
224
+ =head2 Examples
225
+
226
+ # print a help message
227
+ cpan -h
228
+
229
+ # print the version numbers
230
+ cpan -v
231
+
232
+ # create an autobundle
233
+ cpan -a
234
+
235
+ # recompile modules
236
+ cpan -r
237
+
238
+ # upgrade all installed modules
239
+ cpan -u
240
+
241
+ # install modules ( sole -i is optional )
242
+ cpan -i Netscape::Booksmarks Business::ISBN
243
+
244
+ # force install modules ( must use -i )
245
+ cpan -fi CGI::Minimal URI
246
+
247
+ # install modules but without testing them
248
+ cpan -Ti CGI::Minimal URI
249
+
250
+ =head2 Environment variables
251
+
252
+ There are several components in CPAN.pm that use environment variables.
253
+ The build tools, L<ExtUtils::MakeMaker> and L<Module::Build> use some,
254
+ while others matter to the levels above them. Some of these are specified
255
+ by the Perl Toolchain Gang:
256
+
257
+ Lancaster Consensus: L<https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/lancaster-consensus.md>
258
+
259
+ Oslo Consensus: L<https://github.com/Perl-Toolchain-Gang/toolchain-site/blob/master/oslo-consensus.md>
260
+
261
+ =over 4
262
+
263
+ =item NONINTERACTIVE_TESTING
264
+
265
+ Assume no one is paying attention and skips prompts for distributions
266
+ that do that correctly. C<cpan(1)> sets this to C<1> unless it already
267
+ has a value (even if that value is false).
268
+
269
+ =item PERL_MM_USE_DEFAULT
270
+
271
+ Use the default answer for a prompted questions. C<cpan(1)> sets this
272
+ to C<1> unless it already has a value (even if that value is false).
273
+
274
+ =item CPAN_OPTS
275
+
276
+ As with C<PERL5OPT>, a string of additional C<cpan(1)> options to
277
+ add to those you specify on the command line.
278
+
279
+ =item CPANSCRIPT_LOGLEVEL
280
+
281
+ The log level to use, with either the embedded, minimal logger or
282
+ L<Log::Log4perl> if it is installed. Possible values are the same as
283
+ the C<Log::Log4perl> levels: C<TRACE>, C<DEBUG>, C<INFO>, C<WARN>,
284
+ C<ERROR>, and C<FATAL>. The default is C<INFO>.
285
+
286
+ =item GIT_COMMAND
287
+
288
+ The path to the C<git> binary to use for the Git features. The default
289
+ is C</usr/local/bin/git>.
290
+
291
+ =back
292
+
293
+ =head1 EXIT VALUES
294
+
295
+ The script exits with zero if it thinks that everything worked, or a
296
+ positive number if it thinks that something failed. Note, however, that
297
+ in some cases it has to divine a failure by the output of things it does
298
+ not control. For now, the exit codes are vague:
299
+
300
+ 1 An unknown error
301
+
302
+ 2 The was an external problem
303
+
304
+ 4 There was an internal problem with the script
305
+
306
+ 8 A module failed to install
307
+
308
+ =head1 TO DO
309
+
310
+ * one shot configuration values from the command line
311
+
312
+ =head1 BUGS
313
+
314
+ * none noted
315
+
316
+ =head1 SEE ALSO
317
+
318
+ Most behaviour, including environment variables and configuration,
319
+ comes directly from CPAN.pm.
320
+
321
+ =head1 SOURCE AVAILABILITY
322
+
323
+ This code is in Github in the CPAN.pm repository:
324
+
325
+ https://github.com/andk/cpanpm
326
+
327
+ The source used to be tracked separately in another GitHub repo,
328
+ but the canonical source is now in the above repo.
329
+
330
+ =head1 CREDITS
331
+
332
+ Japheth Cleaver added the bits to allow a forced install (-f).
333
+
334
+ Jim Brandt suggest and provided the initial implementation for the
335
+ up-to-date and Changes features.
336
+
337
+ Adam Kennedy pointed out that exit() causes problems on Windows
338
+ where this script ends up with a .bat extension
339
+
340
+ =head1 AUTHOR
341
+
342
+ brian d foy, C<< <bdfoy@cpan.org> >>
343
+
344
+ =head1 COPYRIGHT
345
+
346
+ Copyright (c) 2001-2015, brian d foy, All Rights Reserved.
347
+
348
+ You may redistribute this under the same terms as Perl itself.
349
+
350
+ =cut
351
+
352
+ 1;
git/usr/bin/core_perl/enc2xs ADDED
@@ -0,0 +1,1484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!./perl
5
+ BEGIN {
6
+ # @INC poking no longer needed w/ new MakeMaker and Makefile.PL's
7
+ # with $ENV{PERL_CORE} set
8
+ # In case we need it in future...
9
+ require Config; Config->import();
10
+ pop @INC if $INC[-1] eq '.';
11
+ }
12
+ use strict;
13
+ use warnings;
14
+ use Getopt::Std;
15
+ use Config;
16
+ my @orig_ARGV = @ARGV;
17
+ our $VERSION = do { my @r = (q$Revision: 2.25 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
18
+
19
+ # These may get re-ordered.
20
+ # RAW is a do_now as inserted by &enter
21
+ # AGG is an aggregated do_now, as built up by &process
22
+
23
+ use constant {
24
+ RAW_NEXT => 0,
25
+ RAW_IN_LEN => 1,
26
+ RAW_OUT_BYTES => 2,
27
+ RAW_FALLBACK => 3,
28
+
29
+ AGG_MIN_IN => 0,
30
+ AGG_MAX_IN => 1,
31
+ AGG_OUT_BYTES => 2,
32
+ AGG_NEXT => 3,
33
+ AGG_IN_LEN => 4,
34
+ AGG_OUT_LEN => 5,
35
+ AGG_FALLBACK => 6,
36
+ };
37
+
38
+ # (See the algorithm in encengine.c - we're building structures for it)
39
+
40
+ # There are two sorts of structures.
41
+ # "do_now" (an array, two variants of what needs storing) is whatever we need
42
+ # to do now we've read an input byte.
43
+ # It's housed in a "do_next" (which is how we got to it), and in turn points
44
+ # to a "do_next" which contains all the "do_now"s for the next input byte.
45
+
46
+ # There will be a "do_next" which is the start state.
47
+ # For a single byte encoding it's the only "do_next" - each "do_now" points
48
+ # back to it, and each "do_now" will cause bytes. There is no state.
49
+
50
+ # For a multi-byte encoding where all characters in the input are the same
51
+ # length, then there will be a tree of "do_now"->"do_next"->"do_now"
52
+ # branching out from the start state, one step for each input byte.
53
+ # The leaf "do_now"s will all be at the same distance from the start state,
54
+ # only the leaf "do_now"s cause output bytes, and they in turn point back to
55
+ # the start state.
56
+
57
+ # For an encoding where there are variable length input byte sequences, you
58
+ # will encounter a leaf "do_now" sooner for the shorter input sequences, but
59
+ # as before the leaves will point back to the start state.
60
+
61
+ # The system will cope with escape encodings (imagine them as a mostly
62
+ # self-contained tree for each escape state, and cross links between trees
63
+ # at the state-switching characters) but so far no input format defines these.
64
+
65
+ # The system will also cope with having output "leaves" in the middle of
66
+ # the bifurcating branches, not just at the extremities, but again no
67
+ # input format does this yet.
68
+
69
+ # There are two variants of the "do_now" structure. The first, smaller variant
70
+ # is generated by &enter as the input file is read. There is one structure
71
+ # for each input byte. Say we are mapping a single byte encoding to a
72
+ # single byte encoding, with "ABCD" going "abcd". There will be
73
+ # 4 "do_now"s, {"A" => [...,"a",...], "B" => [...,"b",...], "C"=>..., "D"=>...}
74
+
75
+ # &process then walks the tree, building aggregate "do_now" structures for
76
+ # adjacent bytes where possible. The aggregate is for a contiguous range of
77
+ # bytes which each produce the same length of output, each move to the
78
+ # same next state, and each have the same fallback flag.
79
+ # So our 4 RAW "do_now"s above become replaced by a single structure
80
+ # containing:
81
+ # ["A", "D", "abcd", 1, ...]
82
+ # ie, for an input byte $_ in "A".."D", output 1 byte, found as
83
+ # substr ("abcd", (ord $_ - ord "A") * 1, 1)
84
+ # which maps very nicely into pointer arithmetic in C for encengine.c
85
+
86
+ sub encode_U
87
+ {
88
+ # UTF-8 encode long hand - only covers part of perl's range
89
+ ## my $uv = shift;
90
+ # chr() works in native space so convert value from table
91
+ # into that space before using chr().
92
+ my $ch = chr(utf8::unicode_to_native($_[0]));
93
+ # Now get core perl to encode that the way it likes.
94
+ utf8::encode($ch);
95
+ return $ch;
96
+ }
97
+
98
+ sub encode_S
99
+ {
100
+ # encode single byte
101
+ ## my ($ch,$page) = @_; return chr($ch);
102
+ return chr $_[0];
103
+ }
104
+
105
+ sub encode_D
106
+ {
107
+ # encode double byte MS byte first
108
+ ## my ($ch,$page) = @_; return chr($page).chr($ch);
109
+ return chr ($_[1]) . chr $_[0];
110
+ }
111
+
112
+ sub encode_M
113
+ {
114
+ # encode Multi-byte - single for 0..255 otherwise double
115
+ ## my ($ch,$page) = @_;
116
+ ## return &encode_D if $page;
117
+ ## return &encode_S;
118
+ return chr ($_[1]) . chr $_[0] if $_[1];
119
+ return chr $_[0];
120
+ }
121
+
122
+ my %encode_types = (U => \&encode_U,
123
+ S => \&encode_S,
124
+ D => \&encode_D,
125
+ M => \&encode_M,
126
+ );
127
+
128
+ # Win32 does not expand globs on command line
129
+ if ($^O eq 'MSWin32' and !$ENV{PERL_CORE}) {
130
+ eval "\@ARGV = map(glob(\$_),\@ARGV)";
131
+ @ARGV = @orig_ARGV unless @ARGV;
132
+ }
133
+
134
+ my %opt;
135
+ # I think these are:
136
+ # -Q to disable the duplicate codepoint test
137
+ # -S make mapping errors fatal
138
+ # -q to remove comments written to output files
139
+ # -O to enable the (brute force) substring optimiser
140
+ # -o <output> to specify the output file name (else it's the first arg)
141
+ # -f <inlist> to give a file with a list of input files (else use the args)
142
+ # -n <name> to name the encoding (else use the basename of the input file.
143
+ #Getopt::Long::Configure("bundling");
144
+ #GetOptions(\%opt, qw(C M=s S Q q O o=s f=s n=s v));
145
+ getopts('CM:SQqOo:f:n:v',\%opt);
146
+
147
+ $opt{M} and make_makefile_pl($opt{M}, @ARGV);
148
+ $opt{C} and make_configlocal_pm($opt{C}, @ARGV);
149
+ $opt{v} ||= $ENV{ENC2XS_VERBOSE};
150
+ $opt{q} ||= $ENV{ENC2XS_NO_COMMENTS};
151
+
152
+ sub verbose {
153
+ print STDERR @_ if $opt{v};
154
+ }
155
+ sub verbosef {
156
+ printf STDERR @_ if $opt{v};
157
+ }
158
+
159
+
160
+ # ($cpp, $static, $sized) = compiler_info($declaration)
161
+ #
162
+ # return some information about the compiler and compile options we're using:
163
+ #
164
+ # $declaration - true if we're doing a declaration rather than a definition.
165
+ #
166
+ # $cpp - we're using C++
167
+ # $static - ok to declare the arrays as static
168
+ # $sized - the array declarations should be sized
169
+
170
+ sub compiler_info {
171
+ my ($declaration) = @_;
172
+
173
+ my $ccflags = $Config{ccflags};
174
+ if (defined $Config{ccwarnflags}) {
175
+ $ccflags .= " " . $Config{ccwarnflags};
176
+ }
177
+ my $compat = $ccflags =~ /\Q-Wc++-compat/;
178
+ my $pedantic = $ccflags =~ /-pedantic/;
179
+
180
+ my $cpp = ($Config{d_cplusplus} || '') eq 'define';
181
+
182
+ # The encpage_t tables contain recursive and mutually recursive
183
+ # references. To allow them to compile under C++ and some restrictive
184
+ # cc options, it may be necessary to make the tables non-static/const
185
+ # (thus moving them from the text to the data segment) and/or not
186
+ # include the size in the declaration.
187
+
188
+ my $static = !(
189
+ $cpp
190
+ || ($compat && $pedantic)
191
+ || ($^O eq 'MacOS' && $declaration)
192
+ );
193
+
194
+ # -Wc++-compat on its own warns if the array declaration is sized.
195
+ # The easiest way to avoid this warning is simply not to include
196
+ # the size in the declaration.
197
+ # With -pedantic as well, the issue doesn't arise because $static
198
+ # above becomes false.
199
+ my $sized = $declaration && !($compat && !$pedantic);
200
+
201
+ return ($cpp, $static, $sized);
202
+ }
203
+
204
+
205
+ # This really should go first, else the die here causes empty (non-erroneous)
206
+ # output files to be written.
207
+ my @encfiles;
208
+ if (exists $opt{f}) {
209
+ # -F is followed by name of file containing list of filenames
210
+ my $flist = $opt{f};
211
+ open(FLIST,$flist) || die "Cannot open $flist:$!";
212
+ chomp(@encfiles = <FLIST>);
213
+ close(FLIST);
214
+ } else {
215
+ @encfiles = @ARGV;
216
+ }
217
+
218
+ my $cname = $opt{o} ? $opt{o} : shift(@ARGV);
219
+ unless ($cname) { # Debugging a Win32 nmake error-only; works via cmdline.
220
+ print "\nARGV:";
221
+ print "$_ " for @ARGV;
222
+ print "\nopt:";
223
+ print " $_ => ",defined $opt{$_}?$opt{$_}:"undef","\n" for keys %opt;
224
+ }
225
+ chmod(0666,$cname) if -f $cname && !-w $cname;
226
+ open(C,">", $cname) || die "Cannot open $cname:$!";
227
+
228
+ my $dname = $cname;
229
+ my $hname = $cname;
230
+
231
+ my ($doC,$doEnc,$doUcm,$doPet);
232
+
233
+ if ($cname =~ /\.(c|xs)$/i) # VMS may have upcased filenames with DECC$ARGV_PARSE_STYLE defined
234
+ {
235
+ $doC = 1;
236
+ $dname =~ s/(\.[^\.]*)?$/.exh/;
237
+ chmod(0666,$dname) if -f $cname && !-w $dname;
238
+ open(D,">", $dname) || die "Cannot open $dname:$!";
239
+ $hname =~ s/(\.[^\.]*)?$/.h/;
240
+ chmod(0666,$hname) if -f $cname && !-w $hname;
241
+ open(H,">", $hname) || die "Cannot open $hname:$!";
242
+
243
+ foreach my $fh (\*C,\*D,\*H)
244
+ {
245
+ print $fh <<"END" unless $opt{'q'};
246
+ /*
247
+ !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
248
+ This file was autogenerated by:
249
+ $^X $0 @orig_ARGV
250
+ enc2xs VERSION $VERSION
251
+ */
252
+ END
253
+ }
254
+
255
+ if ($cname =~ /\.c$/i && $Config{ccname} eq "gcc")
256
+ {
257
+ print C qq(#pragma GCC diagnostic ignored "-Wc++-compat"\n);
258
+ }
259
+
260
+ if ($cname =~ /\.xs$/i)
261
+ {
262
+ print C "#define PERL_NO_GET_CONTEXT\n";
263
+ print C "#include <EXTERN.h>\n";
264
+ print C "#include <perl.h>\n";
265
+ print C "#include <XSUB.h>\n";
266
+ }
267
+ print C "#include \"encode.h\"\n\n";
268
+
269
+ }
270
+ elsif ($cname =~ /\.enc$/i)
271
+ {
272
+ $doEnc = 1;
273
+ }
274
+ elsif ($cname =~ /\.ucm$/i)
275
+ {
276
+ $doUcm = 1;
277
+ }
278
+ elsif ($cname =~ /\.pet$/i)
279
+ {
280
+ $doPet = 1;
281
+ }
282
+
283
+ my %encoding;
284
+ my %strings;
285
+ my $string_acc;
286
+ my %strings_in_acc;
287
+
288
+ my $saved = 0;
289
+ my $subsave = 0;
290
+ my $strings = 0;
291
+
292
+ sub cmp_name
293
+ {
294
+ if ($a =~ /^.*-(\d+)/)
295
+ {
296
+ my $an = $1;
297
+ if ($b =~ /^.*-(\d+)/)
298
+ {
299
+ my $r = $an <=> $1;
300
+ return $r if $r;
301
+ }
302
+ }
303
+ return $a cmp $b;
304
+ }
305
+
306
+
307
+ foreach my $enc (sort cmp_name @encfiles)
308
+ {
309
+ my ($name,$sfx) = $enc =~ /^.*?([\w-]+)\.(enc|ucm)$/;
310
+ $name = $opt{'n'} if exists $opt{'n'};
311
+ if (open(E,$enc))
312
+ {
313
+ if ($sfx eq 'enc')
314
+ {
315
+ compile_enc(\*E,lc($name));
316
+ }
317
+ else
318
+ {
319
+ compile_ucm(\*E,lc($name));
320
+ }
321
+ }
322
+ else
323
+ {
324
+ warn "Cannot open $enc for $name:$!";
325
+ }
326
+ }
327
+
328
+ if ($doC)
329
+ {
330
+ verbose "Writing compiled form\n";
331
+ foreach my $name (sort cmp_name keys %encoding)
332
+ {
333
+ my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}};
334
+ process($name.'_utf8',$e2u);
335
+ addstrings(\*C,$e2u);
336
+
337
+ process('utf8_'.$name,$u2e);
338
+ addstrings(\*C,$u2e);
339
+ }
340
+ outbigstring(\*C,"enctable");
341
+ foreach my $name (sort cmp_name keys %encoding)
342
+ {
343
+ my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}};
344
+ outtable(\*C,$e2u, "enctable");
345
+ outtable(\*C,$u2e, "enctable");
346
+
347
+ # push(@{$encoding{$name}},outstring(\*C,$e2u->{Cname}.'_def',$erep));
348
+ }
349
+ my ($cpp) = compiler_info(0);
350
+ my $ext = $cpp ? 'extern "C"' : "extern";
351
+ my $exta = $cpp ? 'extern "C"' : "static";
352
+ my $extb = $cpp ? 'extern "C"' : "";
353
+ foreach my $enc (sort cmp_name keys %encoding)
354
+ {
355
+ # my ($e2u,$u2e,$rep,$min_el,$max_el,$rsym) = @{$encoding{$enc}};
356
+ my ($e2u,$u2e,$rep,$min_el,$max_el) = @{$encoding{$enc}};
357
+ #my @info = ($e2u->{Cname},$u2e->{Cname},$rsym,length($rep),$min_el,$max_el);
358
+ my $replen = 0;
359
+ $replen++ while($rep =~ /\G\\x[0-9A-Fa-f]/g);
360
+ my $sym = "${enc}_encoding";
361
+ $sym =~ s/\W+/_/g;
362
+ my @info = ($e2u->{Cname},$u2e->{Cname},"${sym}_rep_character",$replen,
363
+ $min_el,$max_el);
364
+ print C "${exta} const U8 ${sym}_rep_character[] = \"$rep\";\n";
365
+ print C "${exta} const char ${sym}_enc_name[] = \"$enc\";\n\n";
366
+ print C "${extb} const encode_t $sym = \n";
367
+ # This is to make null encoding work -- dankogai
368
+ for (my $i = (scalar @info) - 1; $i >= 0; --$i){
369
+ $info[$i] ||= 1;
370
+ }
371
+ # end of null tweak -- dankogai
372
+ print C " {",join(',',@info,"{${sym}_enc_name,(const char *)0}"),"};\n\n";
373
+ }
374
+
375
+ foreach my $enc (sort cmp_name keys %encoding)
376
+ {
377
+ my $sym = "${enc}_encoding";
378
+ $sym =~ s/\W+/_/g;
379
+ print H "${ext} encode_t $sym;\n";
380
+ print D " Encode_XSEncoding(aTHX_ &$sym);\n";
381
+ }
382
+
383
+ if ($cname =~ /(\w+)\.xs$/)
384
+ {
385
+ my $mod = $1;
386
+ print C <<'END';
387
+
388
+ static void
389
+ Encode_XSEncoding(pTHX_ encode_t *enc)
390
+ {
391
+ dSP;
392
+ HV *stash = gv_stashpv("Encode::XS", TRUE);
393
+ SV *iv = newSViv(PTR2IV(enc));
394
+ SV *sv = sv_bless(newRV_noinc(iv),stash);
395
+ int i = 0;
396
+ /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's
397
+ constness, in the hope that perl won't mess with it. */
398
+ assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0);
399
+ SvFLAGS(iv) |= SVp_POK;
400
+ SvPVX(iv) = (char*) enc->name[0];
401
+ PUSHMARK(sp);
402
+ XPUSHs(sv);
403
+ while (enc->name[i])
404
+ {
405
+ const char *name = enc->name[i++];
406
+ XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
407
+ }
408
+ PUTBACK;
409
+ call_pv("Encode::define_encoding",G_DISCARD);
410
+ SvREFCNT_dec(sv);
411
+ }
412
+
413
+ END
414
+
415
+ print C "\nMODULE = Encode::$mod\tPACKAGE = Encode::$mod\n\n";
416
+ print C "BOOT:\n{\n";
417
+ print C "#include \"$dname\"\n";
418
+ print C "}\n";
419
+ }
420
+ # Close in void context is bad, m'kay
421
+ close(D) or warn "Error closing '$dname': $!";
422
+ close(H) or warn "Error closing '$hname': $!";
423
+
424
+ my $perc_saved = $saved/($strings + $saved) * 100;
425
+ my $perc_subsaved = $subsave/($strings + $subsave) * 100;
426
+ verbosef "%d bytes in string tables\n",$strings;
427
+ verbosef "%d bytes (%.3g%%) saved spotting duplicates\n",
428
+ $saved, $perc_saved if $saved;
429
+ verbosef "%d bytes (%.3g%%) saved using substrings\n",
430
+ $subsave, $perc_subsaved if $subsave;
431
+ }
432
+ elsif ($doEnc)
433
+ {
434
+ foreach my $name (sort cmp_name keys %encoding)
435
+ {
436
+ my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}};
437
+ output_enc(\*C,$name,$e2u);
438
+ }
439
+ }
440
+ elsif ($doUcm)
441
+ {
442
+ foreach my $name (sort cmp_name keys %encoding)
443
+ {
444
+ my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}};
445
+ output_ucm(\*C,$name,$u2e,$erep,$min_el,$max_el);
446
+ }
447
+ }
448
+
449
+ # writing half meg files and then not checking to see if you just filled the
450
+ # disk is bad, m'kay
451
+ close(C) or die "Error closing '$cname': $!";
452
+
453
+ # End of the main program.
454
+
455
+ sub compile_ucm
456
+ {
457
+ my ($fh,$name) = @_;
458
+ my $e2u = {};
459
+ my $u2e = {};
460
+ my $cs;
461
+ my %attr;
462
+ while (<$fh>)
463
+ {
464
+ s/#.*$//;
465
+ last if /^\s*CHARMAP\s*$/i;
466
+ if (/^\s*<(\w+)>\s+"?([^"]*)"?\s*$/i) # " # Grrr
467
+ {
468
+ $attr{$1} = $2;
469
+ }
470
+ }
471
+ if (!defined($cs = $attr{'code_set_name'}))
472
+ {
473
+ warn "No <code_set_name> in $name\n";
474
+ }
475
+ else
476
+ {
477
+ $name = $cs unless exists $opt{'n'};
478
+ }
479
+ my $erep;
480
+ my $urep;
481
+ my $max_el;
482
+ my $min_el;
483
+ if (exists $attr{'subchar'})
484
+ {
485
+ #my @byte;
486
+ #$attr{'subchar'} =~ /^\s*/cg;
487
+ #push(@byte,$1) while $attr{'subchar'} =~ /\G\\x([0-9a-f]+)/icg;
488
+ #$erep = join('',map(chr(hex($_)),@byte));
489
+ $erep = $attr{'subchar'};
490
+ $erep =~ s/^\s+//; $erep =~ s/\s+$//;
491
+ }
492
+ print "Reading $name ($cs)\n"
493
+ unless defined $ENV{MAKEFLAGS}
494
+ and $ENV{MAKEFLAGS} =~ /\b(s|silent|quiet)\b/;
495
+ my $nfb = 0;
496
+ my $hfb = 0;
497
+ while (<$fh>)
498
+ {
499
+ s/#.*$//;
500
+ last if /^\s*END\s+CHARMAP\s*$/i;
501
+ next if /^\s*$/;
502
+ my (@uni, @byte) = ();
503
+ my ($uni, $byte, $fb) = m/^(\S+)\s+(\S+)\s+(\S+)\s+/o
504
+ or die "Bad line: $_";
505
+ while ($uni =~ m/\G<([U0-9a-fA-F\+]+)>/g){
506
+ push @uni, map { substr($_, 1) } split(/\+/, $1);
507
+ }
508
+ while ($byte =~ m/\G\\x([0-9a-fA-F]+)/g){
509
+ push @byte, $1;
510
+ }
511
+ if (@uni)
512
+ {
513
+ my $uch = join('', map { encode_U(hex($_)) } @uni );
514
+ my $ech = join('',map(chr(hex($_)),@byte));
515
+ my $el = length($ech);
516
+ $max_el = $el if (!defined($max_el) || $el > $max_el);
517
+ $min_el = $el if (!defined($min_el) || $el < $min_el);
518
+ if (length($fb))
519
+ {
520
+ $fb = substr($fb,1);
521
+ $hfb++;
522
+ }
523
+ else
524
+ {
525
+ $nfb++;
526
+ $fb = '0';
527
+ }
528
+ # $fb is fallback flag
529
+ # 0 - round trip safe
530
+ # 1 - fallback for unicode -> enc
531
+ # 2 - skip sub-char mapping
532
+ # 3 - fallback enc -> unicode
533
+ enter($u2e,$uch,$ech,$u2e,$fb+0) if ($fb =~ /[01]/);
534
+ enter($e2u,$ech,$uch,$e2u,$fb+0) if ($fb =~ /[03]/);
535
+ }
536
+ else
537
+ {
538
+ warn $_;
539
+ }
540
+ }
541
+ if ($nfb && $hfb)
542
+ {
543
+ die "$nfb entries without fallback, $hfb entries with\n";
544
+ }
545
+ $encoding{$name} = [$e2u,$u2e,$erep,$min_el,$max_el];
546
+ }
547
+
548
+
549
+
550
+ sub compile_enc
551
+ {
552
+ my ($fh,$name) = @_;
553
+ my $e2u = {};
554
+ my $u2e = {};
555
+
556
+ my $type;
557
+ while ($type = <$fh>)
558
+ {
559
+ last if $type !~ /^\s*#/;
560
+ }
561
+ chomp($type);
562
+ return if $type eq 'E';
563
+ # Do the hash lookup once, rather than once per function call. 4% speedup.
564
+ my $type_func = $encode_types{$type};
565
+ my ($def,$sym,$pages) = split(/\s+/,scalar(<$fh>));
566
+ warn "$type encoded $name\n";
567
+ my $rep = '';
568
+ # Save a defined test by setting these to defined values.
569
+ my $min_el = ~0; # A very big integer
570
+ my $max_el = 0; # Anything must be longer than 0
571
+ {
572
+ my $v = hex($def);
573
+ $rep = &$type_func($v & 0xFF, ($v >> 8) & 0xffe);
574
+ }
575
+ my $errors;
576
+ my $seen;
577
+ # use -Q to silence the seen test. Makefile.PL uses this by default.
578
+ $seen = {} unless $opt{Q};
579
+ do
580
+ {
581
+ my $line = <$fh>;
582
+ chomp($line);
583
+ my $page = hex($line);
584
+ my $ch = 0;
585
+ my $i = 16;
586
+ do
587
+ {
588
+ # So why is it 1% faster to leave the my here?
589
+ my $line = <$fh>;
590
+ $line =~ s/\r\n$/\n/;
591
+ die "$.:${line}Line should be exactly 65 characters long including
592
+ newline (".length($line).")" unless length ($line) == 65;
593
+ # Split line into groups of 4 hex digits, convert groups to ints
594
+ # This takes 65.35
595
+ # map {hex $_} $line =~ /(....)/g
596
+ # This takes 63.75 (2.5% less time)
597
+ # unpack "n*", pack "H*", $line
598
+ # There's an implicit loop in map. Loops are bad, m'kay. Ops are bad, m'kay
599
+ # Doing it as while ($line =~ /(....)/g) took 74.63
600
+ foreach my $val (unpack "n*", pack "H*", $line)
601
+ {
602
+ next if $val == 0xFFFD;
603
+ my $ech = &$type_func($ch,$page);
604
+ if ($val || (!$ch && !$page))
605
+ {
606
+ my $el = length($ech);
607
+ $max_el = $el if $el > $max_el;
608
+ $min_el = $el if $el < $min_el;
609
+ my $uch = encode_U($val);
610
+ if ($seen) {
611
+ # We're doing the test.
612
+ # We don't need to read this quickly, so storing it as a scalar,
613
+ # rather than 3 (anon array, plus the 2 scalars it holds) saves
614
+ # RAM and may make us faster on low RAM systems. [see __END__]
615
+ if (exists $seen->{$uch})
616
+ {
617
+ warn sprintf("U%04X is %02X%02X and %04X\n",
618
+ $val,$page,$ch,$seen->{$uch});
619
+ $errors++;
620
+ }
621
+ else
622
+ {
623
+ $seen->{$uch} = $page << 8 | $ch;
624
+ }
625
+ }
626
+ # Passing 2 extra args each time is 3.6% slower!
627
+ # Even with having to add $fallback ||= 0 later
628
+ enter_fb0($e2u,$ech,$uch);
629
+ enter_fb0($u2e,$uch,$ech);
630
+ }
631
+ else
632
+ {
633
+ # No character at this position
634
+ # enter($e2u,$ech,undef,$e2u);
635
+ }
636
+ $ch++;
637
+ }
638
+ } while --$i;
639
+ } while --$pages;
640
+ die "\$min_el=$min_el, \$max_el=$max_el - seems we read no lines"
641
+ if $min_el > $max_el;
642
+ die "$errors mapping conflicts\n" if ($errors && $opt{'S'});
643
+ $encoding{$name} = [$e2u,$u2e,$rep,$min_el,$max_el];
644
+ }
645
+
646
+ # my ($a,$s,$d,$t,$fb) = @_;
647
+ sub enter {
648
+ my ($current,$inbytes,$outbytes,$next,$fallback) = @_;
649
+ # state we shift to after this (multibyte) input character defaults to same
650
+ # as current state.
651
+ $next ||= $current;
652
+ # Making sure it is defined seems to be faster than {no warnings;} in
653
+ # &process, or passing it in as 0 explicitly.
654
+ # XXX $fallback ||= 0;
655
+
656
+ # Start at the beginning and work forwards through the string to zero.
657
+ # effectively we are removing 1 character from the front each time
658
+ # but we don't actually edit the string. [this alone seems to be 14% speedup]
659
+ # Hence -$pos is the length of the remaining string.
660
+ my $pos = -length $inbytes;
661
+ while (1) {
662
+ my $byte = substr $inbytes, $pos, 1;
663
+ # RAW_NEXT => 0,
664
+ # RAW_IN_LEN => 1,
665
+ # RAW_OUT_BYTES => 2,
666
+ # RAW_FALLBACK => 3,
667
+ # to unicode an array would seem to be better, because the pages are dense.
668
+ # from unicode can be very sparse, favouring a hash.
669
+ # hash using the bytes (all length 1) as keys rather than ord value,
670
+ # as it's easier to sort these in &process.
671
+
672
+ # It's faster to always add $fallback even if it's undef, rather than
673
+ # choosing between 3 and 4 element array. (hence why we set it defined
674
+ # above)
675
+ my $do_now = $current->{Raw}{$byte} ||= [{},-$pos,'',$fallback];
676
+ # When $pos was -1 we were at the last input character.
677
+ unless (++$pos) {
678
+ $do_now->[RAW_OUT_BYTES] = $outbytes;
679
+ $do_now->[RAW_NEXT] = $next;
680
+ return;
681
+ }
682
+ # Tail recursion. The intermediate state may not have a name yet.
683
+ $current = $do_now->[RAW_NEXT];
684
+ }
685
+ }
686
+
687
+ # This is purely for optimisation. It's just &enter hard coded for $fallback
688
+ # of 0, using only a 3 entry array ref to save memory for every entry.
689
+ sub enter_fb0 {
690
+ my ($current,$inbytes,$outbytes,$next) = @_;
691
+ $next ||= $current;
692
+
693
+ my $pos = -length $inbytes;
694
+ while (1) {
695
+ my $byte = substr $inbytes, $pos, 1;
696
+ my $do_now = $current->{Raw}{$byte} ||= [{},-$pos,''];
697
+ unless (++$pos) {
698
+ $do_now->[RAW_OUT_BYTES] = $outbytes;
699
+ $do_now->[RAW_NEXT] = $next;
700
+ return;
701
+ }
702
+ $current = $do_now->[RAW_NEXT];
703
+ }
704
+ }
705
+
706
+ sub process
707
+ {
708
+ my ($name,$a) = @_;
709
+ $name =~ s/\W+/_/g;
710
+ $a->{Cname} = $name;
711
+ my $raw = $a->{Raw};
712
+ my ($l, $agg_max_in, $agg_next, $agg_in_len, $agg_out_len, $agg_fallback);
713
+ my @ent;
714
+ $agg_max_in = 0;
715
+ foreach my $key (sort keys %$raw) {
716
+ # RAW_NEXT => 0,
717
+ # RAW_IN_LEN => 1,
718
+ # RAW_OUT_BYTES => 2,
719
+ # RAW_FALLBACK => 3,
720
+ my ($next, $in_len, $out_bytes, $fallback) = @{$raw->{$key}};
721
+ # Now we are converting from raw to aggregate, switch from 1 byte strings
722
+ # to numbers
723
+ my $b = ord $key;
724
+ $fallback ||= 0;
725
+ if ($l &&
726
+ # If this == fails, we're going to reset $agg_max_in below anyway.
727
+ $b == ++$agg_max_in &&
728
+ # References in numeric context give the pointer as an int.
729
+ $agg_next == $next &&
730
+ $agg_in_len == $in_len &&
731
+ $agg_out_len == length $out_bytes &&
732
+ $agg_fallback == $fallback
733
+ # && length($l->[AGG_OUT_BYTES]) < 16
734
+ ) {
735
+ # my $i = ord($b)-ord($l->[AGG_MIN_IN]);
736
+ # we can aggregate this byte onto the end.
737
+ $l->[AGG_MAX_IN] = $b;
738
+ $l->[AGG_OUT_BYTES] .= $out_bytes;
739
+ } else {
740
+ # AGG_MIN_IN => 0,
741
+ # AGG_MAX_IN => 1,
742
+ # AGG_OUT_BYTES => 2,
743
+ # AGG_NEXT => 3,
744
+ # AGG_IN_LEN => 4,
745
+ # AGG_OUT_LEN => 5,
746
+ # AGG_FALLBACK => 6,
747
+ # Reset the last thing we saw, plus set 5 lexicals to save some derefs.
748
+ # (only gains .6% on euc-jp -- is it worth it?)
749
+ push @ent, $l = [$b, $agg_max_in = $b, $out_bytes, $agg_next = $next,
750
+ $agg_in_len = $in_len, $agg_out_len = length $out_bytes,
751
+ $agg_fallback = $fallback];
752
+ }
753
+ if (exists $next->{Cname}) {
754
+ $next->{'Forward'} = 1 if $next != $a;
755
+ } else {
756
+ process(sprintf("%s_%02x",$name,$b),$next);
757
+ }
758
+ }
759
+ # encengine.c rules say that last entry must be for 255
760
+ if ($agg_max_in < 255) {
761
+ push @ent, [1+$agg_max_in, 255,undef,$a,0,0];
762
+ }
763
+ $a->{'Entries'} = \@ent;
764
+ }
765
+
766
+
767
+ sub addstrings
768
+ {
769
+ my ($fh,$a) = @_;
770
+ my $name = $a->{'Cname'};
771
+ # String tables
772
+ foreach my $b (@{$a->{'Entries'}})
773
+ {
774
+ next unless $b->[AGG_OUT_LEN];
775
+ $strings{$b->[AGG_OUT_BYTES]} = undef;
776
+ }
777
+ if ($a->{'Forward'})
778
+ {
779
+ my ($cpp, $static, $sized) = compiler_info(1);
780
+ my $count = $sized ? scalar(@{$a->{'Entries'}}) : '';
781
+ if ($static) {
782
+ # we cannot ask Config for d_plusplus since we can override CC=g++-6 on the cmdline
783
+ print $fh "#ifdef __cplusplus\n"; # -fpermissive since g++-6
784
+ print $fh "extern encpage_t $name\[$count];\n";
785
+ print $fh "#else\n";
786
+ print $fh "static const encpage_t $name\[$count];\n";
787
+ print $fh "#endif\n";
788
+ } else {
789
+ print $fh "extern encpage_t $name\[$count];\n";
790
+ }
791
+ }
792
+ $a->{'DoneStrings'} = 1;
793
+ foreach my $b (@{$a->{'Entries'}})
794
+ {
795
+ my ($s,$e,$out,$t,$end,$l) = @$b;
796
+ addstrings($fh,$t) unless $t->{'DoneStrings'};
797
+ }
798
+ }
799
+
800
+ sub outbigstring
801
+ {
802
+ my ($fh,$name) = @_;
803
+
804
+ $string_acc = '';
805
+
806
+ # Make the big string in the string accumulator. Longest first, on the hope
807
+ # that this makes it more likely that we find the short strings later on.
808
+ # Not sure if it helps sorting strings of the same length lexically.
809
+ foreach my $s (sort {length $b <=> length $a || $a cmp $b} keys %strings) {
810
+ my $index = index $string_acc, $s;
811
+ if ($index >= 0) {
812
+ $saved += length($s);
813
+ $strings_in_acc{$s} = $index;
814
+ } else {
815
+ OPTIMISER: {
816
+ if ($opt{'O'}) {
817
+ my $sublength = length $s;
818
+ while (--$sublength > 0) {
819
+ # progressively lop characters off the end, to see if the start of
820
+ # the new string overlaps the end of the accumulator.
821
+ if (substr ($string_acc, -$sublength)
822
+ eq substr ($s, 0, $sublength)) {
823
+ $subsave += $sublength;
824
+ $strings_in_acc{$s} = length ($string_acc) - $sublength;
825
+ # append the last bit on the end.
826
+ $string_acc .= substr ($s, $sublength);
827
+ last OPTIMISER;
828
+ }
829
+ # or if the end of the new string overlaps the start of the
830
+ # accumulator
831
+ next unless substr ($string_acc, 0, $sublength)
832
+ eq substr ($s, -$sublength);
833
+ # well, the last $sublength characters of the accumulator match.
834
+ # so as we're prepending to the accumulator, need to shift all our
835
+ # existing offsets forwards
836
+ $_ += $sublength foreach values %strings_in_acc;
837
+ $subsave += $sublength;
838
+ $strings_in_acc{$s} = 0;
839
+ # append the first bit on the start.
840
+ $string_acc = substr ($s, 0, -$sublength) . $string_acc;
841
+ last OPTIMISER;
842
+ }
843
+ }
844
+ # Optimiser (if it ran) found nothing, so just going have to tack the
845
+ # whole thing on the end.
846
+ $strings_in_acc{$s} = length $string_acc;
847
+ $string_acc .= $s;
848
+ };
849
+ }
850
+ }
851
+
852
+ $strings = length $string_acc;
853
+ my ($cpp) = compiler_info(0);
854
+ my $var = $cpp ? '' : 'static';
855
+ my $definition = "\n$var const U8 $name\[$strings] = { " .
856
+ join(',',unpack "C*",$string_acc);
857
+ # We have a single long line. Split it at convenient commas.
858
+ print $fh $1, "\n" while $definition =~ /\G(.{74,77},)/gcs;
859
+ print $fh substr ($definition, pos $definition), " };\n";
860
+ }
861
+
862
+ sub findstring {
863
+ my ($name,$s) = @_;
864
+ my $offset = $strings_in_acc{$s};
865
+ die "Can't find string " . join (',',unpack "C*",$s) . " in accumulator"
866
+ unless defined $offset;
867
+ "$name + $offset";
868
+ }
869
+
870
+ sub outtable
871
+ {
872
+ my ($fh,$a,$bigname) = @_;
873
+ my $name = $a->{'Cname'};
874
+ $a->{'Done'} = 1;
875
+ foreach my $b (@{$a->{'Entries'}})
876
+ {
877
+ my ($s,$e,$out,$t,$end,$l) = @$b;
878
+ outtable($fh,$t,$bigname) unless $t->{'Done'};
879
+ }
880
+ my ($cpp, $static) = compiler_info(0);
881
+ my $count = scalar(@{$a->{'Entries'}});
882
+ if ($static) {
883
+ print $fh "#ifdef __cplusplus\n"; # -fpermissive since g++-6
884
+ print $fh "encpage_t $name\[$count] = {\n";
885
+ print $fh "#else\n";
886
+ print $fh "static const encpage_t $name\[$count] = {\n";
887
+ print $fh "#endif\n";
888
+ } else {
889
+ print $fh "\nencpage_t $name\[$count] = {\n";
890
+ }
891
+ foreach my $b (@{$a->{'Entries'}})
892
+ {
893
+ my ($sc,$ec,$out,$t,$end,$l,$fb) = @$b;
894
+ # $end |= 0x80 if $fb; # what the heck was on your mind, Nick? -- Dan
895
+ print $fh "{";
896
+ if ($l)
897
+ {
898
+ printf $fh findstring($bigname,$out);
899
+ }
900
+ else
901
+ {
902
+ print $fh "0";
903
+ }
904
+ print $fh ",",$t->{Cname};
905
+ printf $fh ",0x%02x,0x%02x,$l,$end},\n",$sc,$ec;
906
+ }
907
+ print $fh "};\n";
908
+ }
909
+
910
+ sub output_enc
911
+ {
912
+ my ($fh,$name,$a) = @_;
913
+ die "Changed - fix me for new structure";
914
+ foreach my $b (sort keys %$a)
915
+ {
916
+ my ($s,$e,$out,$t,$end,$l,$fb) = @{$a->{$b}};
917
+ }
918
+ }
919
+
920
+ sub decode_U
921
+ {
922
+ my $s = shift;
923
+ }
924
+
925
+ my @uname;
926
+ sub char_names{} # cf. https://rt.cpan.org/Ticket/Display.html?id=132471
927
+
928
+ sub output_ucm_page
929
+ {
930
+ my ($cmap,$a,$t,$pre) = @_;
931
+ # warn sprintf("Page %x\n",$pre);
932
+ my $raw = $t->{Raw};
933
+ foreach my $key (sort keys %$raw) {
934
+ # RAW_NEXT => 0,
935
+ # RAW_IN_LEN => 1,
936
+ # RAW_OUT_BYTES => 2,
937
+ # RAW_FALLBACK => 3,
938
+ my ($next, $in_len, $out_bytes, $fallback) = @{$raw->{$key}};
939
+ my $u = ord $key;
940
+ $fallback ||= 0;
941
+
942
+ if ($next != $a && $next != $t) {
943
+ output_ucm_page($cmap,$a,$next,(($pre|($u &0x3F)) << 6)&0xFFFF);
944
+ } elsif (length $out_bytes) {
945
+ if ($pre) {
946
+ $u = $pre|($u &0x3f);
947
+ }
948
+ my $s = sprintf "<U%04X> ",$u;
949
+ #foreach my $c (split(//,$out_bytes)) {
950
+ # $s .= sprintf "\\x%02X",ord($c);
951
+ #}
952
+ # 9.5% faster changing that loop to this:
953
+ $s .= sprintf +("\\x%02X" x length $out_bytes), unpack "C*", $out_bytes;
954
+ $s .= sprintf " |%d # %s\n",($fallback ? 1 : 0),$uname[$u];
955
+ push(@$cmap,$s);
956
+ } else {
957
+ warn join(',',$u, @{$raw->{$key}},$a,$t);
958
+ }
959
+ }
960
+ }
961
+
962
+ sub output_ucm
963
+ {
964
+ my ($fh,$name,$h,$rep,$min_el,$max_el) = @_;
965
+ print $fh "# $0 @orig_ARGV\n" unless $opt{'q'};
966
+ print $fh "<code_set_name> \"$name\"\n";
967
+ char_names();
968
+ if (defined $min_el)
969
+ {
970
+ print $fh "<mb_cur_min> $min_el\n";
971
+ }
972
+ if (defined $max_el)
973
+ {
974
+ print $fh "<mb_cur_max> $max_el\n";
975
+ }
976
+ if (defined $rep)
977
+ {
978
+ print $fh "<subchar> ";
979
+ foreach my $c (split(//,$rep))
980
+ {
981
+ printf $fh "\\x%02X",ord($c);
982
+ }
983
+ print $fh "\n";
984
+ }
985
+ my @cmap;
986
+ output_ucm_page(\@cmap,$h,$h,0);
987
+ print $fh "#\nCHARMAP\n";
988
+ foreach my $line (sort { substr($a,8) cmp substr($b,8) } @cmap)
989
+ {
990
+ print $fh $line;
991
+ }
992
+ print $fh "END CHARMAP\n";
993
+ }
994
+
995
+ use vars qw(
996
+ $_Enc2xs
997
+ $_Version
998
+ $_Inc
999
+ $_E2X
1000
+ $_Name
1001
+ $_TableFiles
1002
+ $_Now
1003
+ );
1004
+
1005
+ sub find_e2x{
1006
+ eval { require File::Find; };
1007
+ my (@inc, %e2x_dir);
1008
+ for my $inc (@INC){
1009
+ push @inc, $inc unless $inc eq '.'; #skip current dir
1010
+ }
1011
+ File::Find::find(
1012
+ sub {
1013
+ my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
1014
+ $atime,$mtime,$ctime,$blksize,$blocks)
1015
+ = lstat($_) or return;
1016
+ -f _ or return;
1017
+ if (/^.*\.e2x$/o){
1018
+ no warnings 'once';
1019
+ $e2x_dir{$File::Find::dir} ||= $mtime;
1020
+ }
1021
+ return;
1022
+ }, @inc);
1023
+ warn join("\n", keys %e2x_dir), "\n";
1024
+ for my $d (sort {$e2x_dir{$a} <=> $e2x_dir{$b}} keys %e2x_dir){
1025
+ $_E2X = $d;
1026
+ # warn "$_E2X => ", scalar localtime($e2x_dir{$d});
1027
+ return $_E2X;
1028
+ }
1029
+ }
1030
+
1031
+ sub make_makefile_pl
1032
+ {
1033
+ eval { require Encode } or die "You need to install Encode to use enc2xs -M\nerror: $@\n";
1034
+ # our used for variable expansion
1035
+ $_Enc2xs = $0;
1036
+ $_Version = $VERSION;
1037
+ $_E2X = find_e2x();
1038
+ $_Name = shift;
1039
+ $_TableFiles = join(",", map {qq('$_')} @_);
1040
+ $_Now = scalar localtime();
1041
+
1042
+ eval { require File::Spec; };
1043
+ _print_expand(File::Spec->catfile($_E2X,"Makefile_PL.e2x"),"Makefile.PL");
1044
+ _print_expand(File::Spec->catfile($_E2X,"_PM.e2x"), "$_Name.pm");
1045
+ _print_expand(File::Spec->catfile($_E2X,"_T.e2x"), "t/$_Name.t");
1046
+ _print_expand(File::Spec->catfile($_E2X,"README.e2x"), "README");
1047
+ _print_expand(File::Spec->catfile($_E2X,"Changes.e2x"), "Changes");
1048
+ exit;
1049
+ }
1050
+
1051
+ use vars qw(
1052
+ $_ModLines
1053
+ $_LocalVer
1054
+ );
1055
+
1056
+ sub make_configlocal_pm {
1057
+ eval { require Encode } or die "Unable to require Encode: $@\n";
1058
+ eval { require File::Spec; };
1059
+
1060
+ # our used for variable expantion
1061
+ my %in_core = map { $_ => 1 } (
1062
+ 'ascii', 'iso-8859-1', 'utf8',
1063
+ 'ascii-ctrl', 'null', 'utf-8-strict'
1064
+ );
1065
+ my %LocalMod = ();
1066
+ # check @enc;
1067
+ use File::Find ();
1068
+ my $wanted = sub{
1069
+ -f $_ or return;
1070
+ $File::Find::name =~ /\A\./ and return;
1071
+ $File::Find::name =~ /\.pm\z/ or return;
1072
+ $File::Find::name =~ m/\bEncode\b/ or return;
1073
+ my $mod = $File::Find::name;
1074
+ $mod =~ s/.*\bEncode\b/Encode/o;
1075
+ $mod =~ s/\.pm\z//o;
1076
+ $mod =~ s,/,::,og;
1077
+ eval qq{ require $mod; } or return;
1078
+ warn qq{ require $mod;\n};
1079
+ for my $enc ( Encode->encodings() ) {
1080
+ no warnings;
1081
+ $in_core{$enc} and next;
1082
+ $Encode::Config::ExtModule{$enc} and next;
1083
+ $LocalMod{$enc} ||= $mod;
1084
+ }
1085
+ };
1086
+ File::Find::find({wanted => $wanted}, @INC);
1087
+ $_ModLines = "";
1088
+ for my $enc ( sort keys %LocalMod ) {
1089
+ $_ModLines .=
1090
+ qq(\$Encode::ExtModule{'$enc'} = "$LocalMod{$enc}";\n);
1091
+ }
1092
+ warn $_ModLines if $_ModLines;
1093
+ $_LocalVer = _mkversion();
1094
+ $_E2X = find_e2x();
1095
+ $_Inc = $INC{"Encode.pm"};
1096
+ $_Inc =~ s/\.pm$//o;
1097
+ _print_expand( File::Spec->catfile( $_E2X, "ConfigLocal_PM.e2x" ),
1098
+ File::Spec->catfile( $_Inc, "ConfigLocal.pm" ), 1 );
1099
+ exit;
1100
+ }
1101
+
1102
+ sub _mkversion{
1103
+ # v-string is now depreciated; use time() instead;
1104
+ #my ($ss,$mm,$hh,$dd,$mo,$yyyy) = localtime();
1105
+ #$yyyy += 1900, $mo +=1;
1106
+ #return sprintf("v%04d.%04d.%04d", $yyyy, $mo*100+$dd, $hh*100+$mm);
1107
+ return time();
1108
+ }
1109
+
1110
+ sub _print_expand{
1111
+ eval { require File::Basename } or die "File::Basename needed. Are you on miniperl?;\nerror: $@\n";
1112
+ File::Basename->import();
1113
+ my ($src, $dst, $clobber) = @_;
1114
+ if (!$clobber and -e $dst){
1115
+ warn "$dst exists. skipping\n";
1116
+ return;
1117
+ }
1118
+ warn "Generating $dst...\n";
1119
+ open my $in, $src or die "$src : $!";
1120
+ if ((my $d = dirname($dst)) ne '.'){
1121
+ -d $d or mkdir $d, 0755 or die "mkdir $d : $!";
1122
+ }
1123
+ open my $out, ">", $dst or die "$!";
1124
+ my $asis = 0;
1125
+ while (<$in>){
1126
+ if (/^#### END_OF_HEADER/){
1127
+ $asis = 1; next;
1128
+ }
1129
+ s/(\$_[A-Z][A-Za-z0-9]+)_/$1/gee unless $asis;
1130
+ print $out $_;
1131
+ }
1132
+ }
1133
+ __END__
1134
+
1135
+ =head1 NAME
1136
+
1137
+ enc2xs -- Perl Encode Module Generator
1138
+
1139
+ =head1 SYNOPSIS
1140
+
1141
+ enc2xs -[options]
1142
+ enc2xs -M ModName mapfiles...
1143
+ enc2xs -C
1144
+
1145
+ =head1 DESCRIPTION
1146
+
1147
+ F<enc2xs> builds a Perl extension for use by Encode from either
1148
+ Unicode Character Mapping files (.ucm) or Tcl Encoding Files (.enc).
1149
+ Besides being used internally during the build process of the Encode
1150
+ module, you can use F<enc2xs> to add your own encoding to perl.
1151
+ No knowledge of XS is necessary.
1152
+
1153
+ =head1 Quick Guide
1154
+
1155
+ If you want to know as little about Perl as possible but need to
1156
+ add a new encoding, just read this chapter and forget the rest.
1157
+
1158
+ =over 4
1159
+
1160
+ =item 0.Z<>
1161
+
1162
+ Have a .ucm file ready. You can get it from somewhere or you can write
1163
+ your own from scratch or you can grab one from the Encode distribution
1164
+ and customize it. For the UCM format, see the next Chapter. In the
1165
+ example below, I'll call my theoretical encoding myascii, defined
1166
+ in I<my.ucm>. C<$> is a shell prompt.
1167
+
1168
+ $ ls -F
1169
+ my.ucm
1170
+
1171
+ =item 1.Z<>
1172
+
1173
+ Issue a command as follows;
1174
+
1175
+ $ enc2xs -M My my.ucm
1176
+ generating Makefile.PL
1177
+ generating My.pm
1178
+ generating README
1179
+ generating Changes
1180
+
1181
+ Now take a look at your current directory. It should look like this.
1182
+
1183
+ $ ls -F
1184
+ Makefile.PL My.pm my.ucm t/
1185
+
1186
+ The following files were created.
1187
+
1188
+ Makefile.PL - MakeMaker script
1189
+ My.pm - Encode submodule
1190
+ t/My.t - test file
1191
+
1192
+ =over 4
1193
+
1194
+ =item 1.1.Z<>
1195
+
1196
+ If you want *.ucm installed together with the modules, do as follows;
1197
+
1198
+ $ mkdir Encode
1199
+ $ mv *.ucm Encode
1200
+ $ enc2xs -M My Encode/*ucm
1201
+
1202
+ =back
1203
+
1204
+ =item 2.Z<>
1205
+
1206
+ Edit the files generated. You don't have to if you have no time AND no
1207
+ intention to give it to someone else. But it is a good idea to edit
1208
+ the pod and to add more tests.
1209
+
1210
+ =item 3.Z<>
1211
+
1212
+ Now issue a command all Perl Mongers love:
1213
+
1214
+ $ perl Makefile.PL
1215
+ Writing Makefile for Encode::My
1216
+
1217
+ =item 4.Z<>
1218
+
1219
+ Now all you have to do is make.
1220
+
1221
+ $ make
1222
+ cp My.pm blib/lib/Encode/My.pm
1223
+ /usr/local/bin/perl /usr/local/bin/enc2xs -Q -O \
1224
+ -o encode_t.c -f encode_t.fnm
1225
+ Reading myascii (myascii)
1226
+ Writing compiled form
1227
+ 128 bytes in string tables
1228
+ 384 bytes (75%) saved spotting duplicates
1229
+ 1 bytes (0.775%) saved using substrings
1230
+ ....
1231
+ chmod 644 blib/arch/auto/Encode/My/My.bs
1232
+ $
1233
+
1234
+ The time it takes varies depending on how fast your machine is and
1235
+ how large your encoding is. Unless you are working on something big
1236
+ like euc-tw, it won't take too long.
1237
+
1238
+ =item 5.Z<>
1239
+
1240
+ You can "make install" already but you should test first.
1241
+
1242
+ $ make test
1243
+ PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib \
1244
+ -e 'use Test::Harness qw(&runtests $verbose); \
1245
+ $verbose=0; runtests @ARGV;' t/*.t
1246
+ t/My....ok
1247
+ All tests successful.
1248
+ Files=1, Tests=2, 0 wallclock secs
1249
+ ( 0.09 cusr + 0.01 csys = 0.09 CPU)
1250
+
1251
+ =item 6.Z<>
1252
+
1253
+ If you are content with the test result, just "make install"
1254
+
1255
+ =item 7.Z<>
1256
+
1257
+ If you want to add your encoding to Encode's demand-loading list
1258
+ (so you don't have to "use Encode::YourEncoding"), run
1259
+
1260
+ enc2xs -C
1261
+
1262
+ to update Encode::ConfigLocal, a module that controls local settings.
1263
+ After that, "use Encode;" is enough to load your encodings on demand.
1264
+
1265
+ =back
1266
+
1267
+ =head1 The Unicode Character Map
1268
+
1269
+ Encode uses the Unicode Character Map (UCM) format for source character
1270
+ mappings. This format is used by IBM's ICU package and was adopted
1271
+ by Nick Ing-Simmons for use with the Encode module. Since UCM is
1272
+ more flexible than Tcl's Encoding Map and far more user-friendly,
1273
+ this is the recommended format for Encode now.
1274
+
1275
+ A UCM file looks like this.
1276
+
1277
+ #
1278
+ # Comments
1279
+ #
1280
+ <code_set_name> "US-ascii" # Required
1281
+ <code_set_alias> "ascii" # Optional
1282
+ <mb_cur_min> 1 # Required; usually 1
1283
+ <mb_cur_max> 1 # Max. # of bytes/char
1284
+ <subchar> \x3F # Substitution char
1285
+ #
1286
+ CHARMAP
1287
+ <U0000> \x00 |0 # <control>
1288
+ <U0001> \x01 |0 # <control>
1289
+ <U0002> \x02 |0 # <control>
1290
+ ....
1291
+ <U007C> \x7C |0 # VERTICAL LINE
1292
+ <U007D> \x7D |0 # RIGHT CURLY BRACKET
1293
+ <U007E> \x7E |0 # TILDE
1294
+ <U007F> \x7F |0 # <control>
1295
+ END CHARMAP
1296
+
1297
+ =over 4
1298
+
1299
+ =item *
1300
+
1301
+ Anything that follows C<#> is treated as a comment.
1302
+
1303
+ =item *
1304
+
1305
+ The header section continues until a line containing the word
1306
+ CHARMAP. This section has a form of I<E<lt>keywordE<gt> value>, one
1307
+ pair per line. Strings used as values must be quoted. Barewords are
1308
+ treated as numbers. I<\xXX> represents a byte.
1309
+
1310
+ Most of the keywords are self-explanatory. I<subchar> means
1311
+ substitution character, not subcharacter. When you decode a Unicode
1312
+ sequence to this encoding but no matching character is found, the byte
1313
+ sequence defined here will be used. For most cases, the value here is
1314
+ \x3F; in ASCII, this is a question mark.
1315
+
1316
+ =item *
1317
+
1318
+ CHARMAP starts the character map section. Each line has a form as
1319
+ follows:
1320
+
1321
+ <UXXXX> \xXX.. |0 # comment
1322
+ ^ ^ ^
1323
+ | | +- Fallback flag
1324
+ | +-------- Encoded byte sequence
1325
+ +-------------- Unicode Character ID in hex
1326
+
1327
+ The format is roughly the same as a header section except for the
1328
+ fallback flag: | followed by 0..3. The meaning of the possible
1329
+ values is as follows:
1330
+
1331
+ =over 4
1332
+
1333
+ =item |0
1334
+
1335
+ Round trip safe. A character decoded to Unicode encodes back to the
1336
+ same byte sequence. Most characters have this flag.
1337
+
1338
+ =item |1
1339
+
1340
+ Fallback for unicode -> encoding. When seen, enc2xs adds this
1341
+ character for the encode map only.
1342
+
1343
+ =item |2
1344
+
1345
+ Skip sub-char mapping should there be no code point.
1346
+
1347
+ =item |3
1348
+
1349
+ Fallback for encoding -> unicode. When seen, enc2xs adds this
1350
+ character for the decode map only.
1351
+
1352
+ =back
1353
+
1354
+ =item *
1355
+
1356
+ And finally, END OF CHARMAP ends the section.
1357
+
1358
+ =back
1359
+
1360
+ When you are manually creating a UCM file, you should copy ascii.ucm
1361
+ or an existing encoding which is close to yours, rather than write
1362
+ your own from scratch.
1363
+
1364
+ When you do so, make sure you leave at least B<U0000> to B<U0020> as
1365
+ is, unless your environment is EBCDIC.
1366
+
1367
+ B<CAVEAT>: not all features in UCM are implemented. For example,
1368
+ icu:state is not used. Because of that, you need to write a perl
1369
+ module if you want to support algorithmical encodings, notably
1370
+ the ISO-2022 series. Such modules include L<Encode::JP::2022_JP>,
1371
+ L<Encode::KR::2022_KR>, and L<Encode::TW::HZ>.
1372
+
1373
+ =head2 Coping with duplicate mappings
1374
+
1375
+ When you create a map, you SHOULD make your mappings round-trip safe.
1376
+ That is, C<encode('your-encoding', decode('your-encoding', $data)) eq
1377
+ $data> stands for all characters that are marked as C<|0>. Here is
1378
+ how to make sure:
1379
+
1380
+ =over 4
1381
+
1382
+ =item *
1383
+
1384
+ Sort your map in Unicode order.
1385
+
1386
+ =item *
1387
+
1388
+ When you have a duplicate entry, mark either one with '|1' or '|3'.
1389
+
1390
+ =item *
1391
+
1392
+ And make sure the '|1' or '|3' entry FOLLOWS the '|0' entry.
1393
+
1394
+ =back
1395
+
1396
+ Here is an example from big5-eten.
1397
+
1398
+ <U2550> \xF9\xF9 |0
1399
+ <U2550> \xA2\xA4 |3
1400
+
1401
+ Internally Encoding -> Unicode and Unicode -> Encoding Map looks like
1402
+ this;
1403
+
1404
+ E to U U to E
1405
+ --------------------------------------
1406
+ \xF9\xF9 => U2550 U2550 => \xF9\xF9
1407
+ \xA2\xA4 => U2550
1408
+
1409
+ So it is round-trip safe for \xF9\xF9. But if the line above is upside
1410
+ down, here is what happens.
1411
+
1412
+ E to U U to E
1413
+ --------------------------------------
1414
+ \xA2\xA4 => U2550 U2550 => \xF9\xF9
1415
+ (\xF9\xF9 => U2550 is now overwritten!)
1416
+
1417
+ The Encode package comes with F<ucmlint>, a crude but sufficient
1418
+ utility to check the integrity of a UCM file. Check under the
1419
+ Encode/bin directory for this.
1420
+
1421
+ When in doubt, you can use F<ucmsort>, yet another utility under
1422
+ Encode/bin directory.
1423
+
1424
+ =head1 Bookmarks
1425
+
1426
+ =over 4
1427
+
1428
+ =item *
1429
+
1430
+ ICU Home Page
1431
+ L<http://www.icu-project.org/>
1432
+
1433
+ =item *
1434
+
1435
+ ICU Character Mapping Tables
1436
+ L<http://site.icu-project.org/charts/charset>
1437
+
1438
+ =item *
1439
+
1440
+ ICU:Conversion Data
1441
+ L<http://www.icu-project.org/userguide/conversion-data.html>
1442
+
1443
+ =back
1444
+
1445
+ =head1 SEE ALSO
1446
+
1447
+ L<Encode>,
1448
+ L<perlmod>,
1449
+ L<perlpod>
1450
+
1451
+ =cut
1452
+
1453
+ # -Q to disable the duplicate codepoint test
1454
+ # -S make mapping errors fatal
1455
+ # -q to remove comments written to output files
1456
+ # -O to enable the (brute force) substring optimiser
1457
+ # -o <output> to specify the output file name (else it's the first arg)
1458
+ # -f <inlist> to give a file with a list of input files (else use the args)
1459
+ # -n <name> to name the encoding (else use the basename of the input file.
1460
+
1461
+ With %seen holding array refs:
1462
+
1463
+ 865.66 real 28.80 user 8.79 sys
1464
+ 7904 maximum resident set size
1465
+ 1356 average shared memory size
1466
+ 18566 average unshared data size
1467
+ 229 average unshared stack size
1468
+ 46080 page reclaims
1469
+ 33373 page faults
1470
+
1471
+ With %seen holding simple scalars:
1472
+
1473
+ 342.16 real 27.11 user 3.54 sys
1474
+ 8388 maximum resident set size
1475
+ 1394 average shared memory size
1476
+ 14969 average unshared data size
1477
+ 236 average unshared stack size
1478
+ 28159 page reclaims
1479
+ 9839 page faults
1480
+
1481
+ Yes, 5 minutes is faster than 15. Above is for CP936 in CN. Only difference is
1482
+ how %seen is storing things its seen. So it is pathalogically bad on a 16M
1483
+ RAM machine, but it's going to help even on modern machines.
1484
+ Swapping is bad, m'kay :-)
git/usr/bin/core_perl/encguess ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!./perl
5
+ use 5.008001;
6
+ BEGIN { pop @INC if $INC[-1] eq '.' }
7
+ use strict;
8
+ use warnings;
9
+ use Encode;
10
+ use Getopt::Std;
11
+ use Carp;
12
+ use Encode::Guess;
13
+ $Getopt::Std::STANDARD_HELP_VERSION = 1;
14
+
15
+ my %opt;
16
+ getopts( "huSs:", \%opt );
17
+ my @suspect_list;
18
+ list_valid_suspects() and exit if $opt{S};
19
+ @suspect_list = split /:,/, $opt{s} if $opt{s};
20
+ HELP_MESSAGE() if $opt{h};
21
+ HELP_MESSAGE() unless @ARGV;
22
+ do_guess($_) for @ARGV;
23
+
24
+ sub read_file {
25
+ my $filename = shift;
26
+ local $/;
27
+ open my $fh, '<:raw', $filename or croak "$filename:$!";
28
+ my $content = <$fh>;
29
+ close $fh;
30
+ return $content;
31
+ }
32
+
33
+ sub do_guess {
34
+ my $filename = shift;
35
+ my $data = read_file($filename);
36
+ my $enc = guess_encoding( $data, @suspect_list );
37
+ if ( !ref($enc) && $opt{u} ) {
38
+ return 1;
39
+ }
40
+ print "$filename\t";
41
+ if ( ref($enc) ) {
42
+ print $enc->mime_name();
43
+ }
44
+ else {
45
+ print "unknown";
46
+ }
47
+ print "\n";
48
+ return 1;
49
+ }
50
+
51
+ sub list_valid_suspects {
52
+ print join( "\n", Encode->encodings(":all") );
53
+ print "\n";
54
+ return 1;
55
+ }
56
+
57
+ sub HELP_MESSAGE {
58
+ exec 'pod2usage', $0 or die "pod2usage: $!"
59
+ }
60
+ __END__
61
+ =head1 NAME
62
+
63
+ encguess - guess character encodings of files
64
+
65
+ =head1 VERSION
66
+
67
+ $Id: encguess,v 0.4 2023/11/10 01:10:50 dankogai Exp $
68
+
69
+ =head1 SYNOPSIS
70
+
71
+ encguess [switches] filename...
72
+
73
+ =head2 SWITCHES
74
+
75
+ =over 2
76
+
77
+ =item -h
78
+
79
+ show this message and exit.
80
+
81
+ =item -s
82
+
83
+ specify a list of "suspect encoding types" to test,
84
+ separated by either C<:> or C<,>
85
+
86
+ =item -S
87
+
88
+ output a list of all acceptable encoding types that can be used with
89
+ the -s param
90
+
91
+ =item -u
92
+
93
+ suppress display of unidentified types
94
+
95
+ =back
96
+
97
+ =head2 EXAMPLES:
98
+
99
+ =over 2
100
+
101
+ =item *
102
+
103
+ Guess encoding of a file named C<test.txt>, using only the default
104
+ suspect types.
105
+
106
+ encguess test.txt
107
+
108
+ =item *
109
+
110
+ Guess the encoding type of a file named C<test.txt>, using the suspect
111
+ types C<euc-jp,shiftjis,7bit-jis>.
112
+
113
+ encguess -s euc-jp,shiftjis,7bit-jis test.txt
114
+ encguess -s euc-jp:shiftjis:7bit-jis test.txt
115
+
116
+ =item *
117
+
118
+ Guess the encoding type of several files, do not display results for
119
+ unidentified files.
120
+
121
+ encguess -us euc-jp,shiftjis,7bit-jis test*.txt
122
+
123
+ =back
124
+
125
+ =head1 DESCRIPTION
126
+
127
+ The encoding identification is done by checking one encoding type at a
128
+ time until all but the right type are eliminated. The set of encoding
129
+ types to try is defined by the -s parameter and defaults to ascii,
130
+ utf8 and UTF-16/32 with BOM. This can be overridden by passing one or
131
+ more encoding types via the -s parameter. If you need to pass in
132
+ multiple suspect encoding types, use a quoted string with the a space
133
+ separating each value.
134
+
135
+ =head1 SEE ALSO
136
+
137
+ L<Encode::Guess>, L<Encode::Detect>
138
+
139
+ =head1 LICENSE AND COPYRIGHT
140
+
141
+ Copyright 2015 Michael LaGrasta and Dan Kogai.
142
+
143
+ This program is free software; you can redistribute it and/or modify it
144
+ under the terms of the Artistic License (2.0). You may obtain a
145
+ copy of the full license at:
146
+
147
+ L<http://www.perlfoundation.org/artistic_license_2_0>
148
+
149
+ =cut
git/usr/bin/core_perl/h2ph ADDED
@@ -0,0 +1,977 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ BEGIN { pop @INC if $INC[-1] eq '.' }
6
+
7
+ use strict;
8
+
9
+ use Config;
10
+ use File::Path qw(mkpath);
11
+ use Getopt::Std;
12
+
13
+ # Make sure read permissions for all are set:
14
+ if (defined umask && (umask() & 0444)) {
15
+ umask (umask() & ~0444);
16
+ }
17
+
18
+ getopts('Dd:rlhaQe');
19
+ use vars qw($opt_D $opt_d $opt_r $opt_l $opt_h $opt_a $opt_Q $opt_e);
20
+ die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a);
21
+ my @inc_dirs = inc_dirs() if $opt_a;
22
+
23
+ my $Exit = 0;
24
+
25
+ my $Dest_dir = $opt_d || $Config{installsitearch};
26
+ die "Destination directory $Dest_dir doesn't exist or isn't a directory\n"
27
+ unless -d $Dest_dir;
28
+
29
+ my @isatype = qw(
30
+ char uchar u_char
31
+ short ushort u_short
32
+ int uint u_int
33
+ long ulong u_long
34
+ FILE key_t caddr_t
35
+ float double size_t
36
+ );
37
+
38
+ my %isatype;
39
+ @isatype{@isatype} = (1) x @isatype;
40
+ my $inif = 0;
41
+ my %Is_converted;
42
+ my %bad_file = ();
43
+
44
+ @ARGV = ('-') unless @ARGV;
45
+
46
+ build_preamble_if_necessary();
47
+
48
+ sub reindent($) {
49
+ my($text) = shift;
50
+ $text =~ s/\n/\n /g;
51
+ $text =~ s/ /\t/g;
52
+ $text;
53
+ }
54
+
55
+ my ($t, $tab, %curargs, $new, $eval_index, $dir, $name, $args, $outfile);
56
+ my ($incl, $incl_type, $incl_quote, $next);
57
+ while (defined (my $file = next_file())) {
58
+ if (-l $file and -d $file) {
59
+ link_if_possible($file) if ($opt_l);
60
+ next;
61
+ }
62
+
63
+ # Recover from header files with unbalanced cpp directives
64
+ $t = '';
65
+ $tab = 0;
66
+
67
+ # $eval_index goes into '#line' directives, to help locate syntax errors:
68
+ $eval_index = 1;
69
+
70
+ if ($file eq '-') {
71
+ open(IN, "-");
72
+ open(OUT, ">-");
73
+ } else {
74
+ ($outfile = $file) =~ s/\.h$/.ph/ || next;
75
+ print "$file -> $outfile\n" unless $opt_Q;
76
+ if ($file =~ m|^(.*)/|) {
77
+ $dir = $1;
78
+ mkpath "$Dest_dir/$dir";
79
+ }
80
+
81
+ if ($opt_a) { # automagic mode: locate header file in @inc_dirs
82
+ foreach (@inc_dirs) {
83
+ chdir $_;
84
+ last if -f $file;
85
+ }
86
+ }
87
+
88
+ open(IN, "<", "$file") || (($Exit = 1),(warn "Can't open $file: $!\n"),next);
89
+ open(OUT, ">", "$Dest_dir/$outfile") || die "Can't create $outfile: $!\n";
90
+ }
91
+
92
+ print OUT
93
+ "require '_h2ph_pre.ph';\n\n",
94
+ "no warnings qw(redefine misc);\n\n";
95
+
96
+ while (defined (local $_ = next_line($file))) {
97
+ if (s/^\s*\#\s*//) {
98
+ if (s/^define\s+(\w+)//) {
99
+ $name = $1;
100
+ $new = '';
101
+ s/\s+$//;
102
+ s/\(\w+\s*\(\*\)\s*\(\w*\)\)\s*(-?\d+)/$1/; # (int (*)(foo_t))0
103
+ if (s/^\(([\w,\s]*)\)//) {
104
+ $args = $1;
105
+ my $proto = '() ';
106
+ if ($args ne '') {
107
+ $proto = '';
108
+ foreach my $arg (split(/,\s*/,$args)) {
109
+ $arg =~ s/^\s*([^\s].*[^\s])\s*$/$1/;
110
+ $curargs{$arg} = 1;
111
+ }
112
+ $args =~ s/\b(\w)/\$$1/g;
113
+ $args = "my($args) = \@_;\n$t ";
114
+ }
115
+ s/^\s+//;
116
+ expr();
117
+ $new =~ s/(["\\])/\\$1/g; #"]);
118
+ EMIT($proto);
119
+ } else {
120
+ s/^\s+//;
121
+ expr();
122
+
123
+ $new = 1 if $new eq '';
124
+
125
+ # Shunt around such directives as '#define FOO FOO':
126
+ next if $new =~ /^\s*&\Q$name\E\s*\z/;
127
+
128
+ $new = reindent($new);
129
+ $args = reindent($args);
130
+ $new =~ s/(['\\])/\\$1/g; #']);
131
+
132
+ print OUT $t, 'eval ';
133
+ if ($opt_h) {
134
+ print OUT "\"\\n#line $eval_index $outfile\\n\" . ";
135
+ $eval_index++;
136
+ }
137
+ print OUT "'sub $name () {$new;}' unless defined(&$name);\n";
138
+ }
139
+ } elsif (/^(include|import|include_next)\s*([<\"])(.*)[>\"]/) {
140
+ $incl_type = $1;
141
+ $incl_quote = $2;
142
+ $incl = $3;
143
+ if (($incl_type eq 'include_next') ||
144
+ ($opt_e && exists($bad_file{$incl}))) {
145
+ $incl =~ s/\.h$/.ph/;
146
+ print OUT ($t,
147
+ "eval {\n");
148
+ $tab += 4;
149
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
150
+ print OUT ($t, "my(\@REM);\n");
151
+ if ($incl_type eq 'include_next') {
152
+ print OUT ($t,
153
+ "my(\%INCD) = map { \$INC{\$_} => 1 } ",
154
+ "(grep { \$_ eq \"$incl\" } ",
155
+ "keys(\%INC));\n");
156
+ print OUT ($t,
157
+ "\@REM = map { \"\$_/$incl\" } ",
158
+ "(grep { not exists(\$INCD{\"\$_/$incl\"})",
159
+ " and -f \"\$_/$incl\" } \@INC);\n");
160
+ } else {
161
+ print OUT ($t,
162
+ "\@REM = map { \"\$_/$incl\" } ",
163
+ "(grep {-r \"\$_/$incl\" } \@INC);\n");
164
+ }
165
+ print OUT ($t,
166
+ "require \"\$REM[0]\" if \@REM;\n");
167
+ $tab -= 4;
168
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
169
+ print OUT ($t,
170
+ "};\n");
171
+ print OUT ($t,
172
+ "warn(\$\@) if \$\@;\n");
173
+ } else {
174
+ $incl =~ s/\.h$/.ph/;
175
+ # copy the prefix in the quote syntax (#include "x.h") case
176
+ if ($incl !~ m|/| && $incl_quote eq q{"} && $file =~ m|^(.*)/|) {
177
+ $incl = "$1/$incl";
178
+ }
179
+ print OUT $t,"require '$incl';\n";
180
+ }
181
+ } elsif (/^ifdef\s+(\w+)/) {
182
+ print OUT $t,"if(defined(&$1)) {\n";
183
+ $tab += 4;
184
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
185
+ } elsif (/^ifndef\s+(\w+)/) {
186
+ print OUT $t,"unless(defined(&$1)) {\n";
187
+ $tab += 4;
188
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
189
+ } elsif (s/^if\s+//) {
190
+ $new = '';
191
+ $inif = 1;
192
+ expr();
193
+ $inif = 0;
194
+ print OUT $t,"if($new) {\n";
195
+ $tab += 4;
196
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
197
+ } elsif (s/^elif\s+//) {
198
+ $new = '';
199
+ $inif = 1;
200
+ expr();
201
+ $inif = 0;
202
+ $tab -= 4;
203
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
204
+ print OUT $t,"}\n elsif($new) {\n";
205
+ $tab += 4;
206
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
207
+ } elsif (/^else/) {
208
+ $tab -= 4;
209
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
210
+ print OUT $t,"} else {\n";
211
+ $tab += 4;
212
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
213
+ } elsif (/^endif/) {
214
+ $tab -= 4;
215
+ $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
216
+ print OUT $t,"}\n";
217
+ } elsif(/^undef\s+(\w+)/) {
218
+ print OUT $t, "undef(&$1) if defined(&$1);\n";
219
+ } elsif(/^error\s+(".*")/) {
220
+ print OUT $t, "die($1);\n";
221
+ } elsif(/^error\s+(.*)/) {
222
+ print OUT $t, "die(\"", quotemeta($1), "\");\n";
223
+ } elsif(/^warning\s+(.*)/) {
224
+ print OUT $t, "warn(\"", quotemeta($1), "\");\n";
225
+ } elsif(/^ident\s+(.*)/) {
226
+ print OUT $t, "# $1\n";
227
+ }
228
+ } elsif (/^\s*(typedef\s*)?enum\s*(\s+[a-zA-Z_]\w*\s*)?/) { # { for vi
229
+ until(/\{[^}]*\}.*;/ || /;/) {
230
+ last unless defined ($next = next_line($file));
231
+ chomp $next;
232
+ # drop "#define FOO FOO" in enums
233
+ $next =~ s/^\s*#\s*define\s+(\w+)\s+\1\s*$//;
234
+ # #defines in enums (aliases)
235
+ $next =~ s/^\s*#\s*define\s+(\w+)\s+(\w+)\s*$/$1 = $2,/;
236
+ $_ .= $next;
237
+ print OUT "# $next\n" if $opt_D;
238
+ }
239
+ s/#\s*if.*?#\s*endif//g; # drop #ifdefs
240
+ s@/\*.*?\*/@@g;
241
+ s/\s+/ /g;
242
+ next unless /^\s?(typedef\s?)?enum\s?([a-zA-Z_]\w*)?\s?\{(.*)\}\s?([a-zA-Z_]\w*)?\s?;/;
243
+ (my $enum_subs = $3) =~ s/\s//g;
244
+ my @enum_subs = split(/,/, $enum_subs);
245
+ my $enum_val = -1;
246
+ foreach my $enum (@enum_subs) {
247
+ my ($enum_name, $enum_value) = $enum =~ /^([a-zA-Z_]\w*)(=.+)?$/;
248
+ $enum_name or next;
249
+ $enum_value =~ s/^=//;
250
+ $enum_val = (length($enum_value) ? $enum_value : $enum_val + 1);
251
+ if ($opt_h) {
252
+ print OUT ($t,
253
+ "eval(\"\\n#line $eval_index $outfile\\n",
254
+ "sub $enum_name () \{ $enum_val; \}\") ",
255
+ "unless defined(\&$enum_name);\n");
256
+ ++ $eval_index;
257
+ } else {
258
+ print OUT ($t,
259
+ "eval(\"sub $enum_name () \{ $enum_val; \}\") ",
260
+ "unless defined(\&$enum_name);\n");
261
+ }
262
+ }
263
+ } elsif (/^(?:__extension__\s+)?(?:extern|static)\s+(?:__)?inline(?:__)?\s+/
264
+ and !/;\s*$/ and !/{\s*}\s*$/)
265
+ { # { for vi
266
+ # This is a hack to parse the inline functions in the glibc headers.
267
+ # Warning: massive kludge ahead. We suppose inline functions
268
+ # are mainly constructed like macros.
269
+ while (1) {
270
+ last unless defined ($next = next_line($file));
271
+ chomp $next;
272
+ undef $_, last if $next =~ /__THROW\s*;/
273
+ or $next =~ /^(__extension__|extern|static)\b/;
274
+ $_ .= " $next";
275
+ print OUT "# $next\n" if $opt_D;
276
+ last if $next =~ /^}|^{.*}\s*$/;
277
+ }
278
+ next if not defined; # because it's only a prototype
279
+ s/\b(__extension__|extern|static|(?:__)?inline(?:__)?)\b//g;
280
+ # violently drop #ifdefs
281
+ s/#\s*if.*?#\s*endif//g
282
+ and print OUT "# some #ifdef were dropped here -- fill in the blanks\n";
283
+ if (s/^(?:\w|\s|\*)*\s(\w+)\s*//) {
284
+ $name = $1;
285
+ } else {
286
+ warn "name not found"; next; # shouldn't occur...
287
+ }
288
+ my @args;
289
+ if (s/^\(([^()]*)\)\s*(\w+\s*)*//) {
290
+ for my $arg (split /,/, $1) {
291
+ if ($arg =~ /(\w+)\s*$/) {
292
+ $curargs{$1} = 1;
293
+ push @args, $1;
294
+ }
295
+ }
296
+ }
297
+ $args = (
298
+ @args
299
+ ? "my(" . (join ',', map "\$$_", @args) . ") = \@_;\n$t "
300
+ : ""
301
+ );
302
+ my $proto = @args ? '' : '() ';
303
+ $new = '';
304
+ s/\breturn\b//g; # "return" doesn't occur in macros usually...
305
+ expr();
306
+ # try to find and perlify local C variables
307
+ our @local_variables = (); # needs to be a our(): (?{...}) bug workaround
308
+ {
309
+ use re "eval";
310
+ my $typelist = join '|', keys %isatype;
311
+ $new =~ s['
312
+ (?:(?:__)?const(?:__)?\s+)?
313
+ (?:(?:un)?signed\s+)?
314
+ (?:long\s+)?
315
+ (?:$typelist)\s+
316
+ (\w+)
317
+ (?{ push @local_variables, $1 })
318
+ ']
319
+ [my \$$1]gx;
320
+ $new =~ s['
321
+ (?:(?:__)?const(?:__)?\s+)?
322
+ (?:(?:un)?signed\s+)?
323
+ (?:long\s+)?
324
+ (?:$typelist)\s+
325
+ ' \s+ &(\w+) \s* ;
326
+ (?{ push @local_variables, $1 })
327
+ ]
328
+ [my \$$1;]gx;
329
+ }
330
+ $new =~ s/&$_\b/\$$_/g for @local_variables;
331
+ $new =~ s/(["\\])/\\$1/g; #"]);
332
+ # now that's almost like a macro (we hope)
333
+ EMIT($proto);
334
+ }
335
+ }
336
+ $Is_converted{$file} = 1;
337
+ if ($opt_e && exists($bad_file{$file})) {
338
+ unlink($Dest_dir . '/' . $outfile);
339
+ $next = '';
340
+ } else {
341
+ print OUT "1;\n";
342
+ queue_includes_from($file) if $opt_a;
343
+ }
344
+ }
345
+
346
+ if ($opt_e && (scalar(keys %bad_file) > 0)) {
347
+ warn "Was unable to convert the following files:\n";
348
+ warn "\t" . join("\n\t",sort(keys %bad_file)) . "\n";
349
+ }
350
+
351
+ exit $Exit;
352
+
353
+ sub EMIT {
354
+ my $proto = shift;
355
+
356
+ $new = reindent($new);
357
+ $args = reindent($args);
358
+ $new =~ s/(['\\])/\\$1/g; #']);
359
+ if ($opt_h) {
360
+ print OUT $t,
361
+ "eval \"\\n#line $eval_index $outfile\\n\" . 'sub $name $proto\{\n$t ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
362
+ $eval_index++;
363
+ } else {
364
+ print OUT $t,
365
+ "eval 'sub $name $proto\{\n$t ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
366
+ }
367
+ %curargs = ();
368
+ return;
369
+ }
370
+
371
+ sub expr {
372
+ if (/\b__asm__\b/) { # freak out
373
+ $new = '"(assembly code)"';
374
+ return
375
+ }
376
+ my $joined_args;
377
+ if(keys(%curargs)) {
378
+ $joined_args = join('|', keys(%curargs));
379
+ }
380
+ while ($_ ne '') {
381
+ s/^\&\&// && do { $new .= " &&"; next;}; # handle && operator
382
+ s/^\&([\(a-z\)]+)/$1/i; # hack for things that take the address of
383
+ s/^(\s+)// && do {$new .= ' '; next;};
384
+ s/^0X([0-9A-F]+)[UL]*//i
385
+ && do {my $hex = $1;
386
+ $hex =~ s/^0+//;
387
+ if (length $hex > 8 && !$Config{use64bitint}) {
388
+ # Croak if nv_preserves_uv_bits < 64 ?
389
+ $new .= hex(substr($hex, -8)) +
390
+ 2**32 * hex(substr($hex, 0, -8));
391
+ # The above will produce "erroneous" code
392
+ # if the hex constant was e.g. inside UINT64_C
393
+ # macro, but then again, h2ph is an approximation.
394
+ } else {
395
+ $new .= lc("0x$hex");
396
+ }
397
+ next;};
398
+ s/^(-?\d+\.\d+E[-+]?\d+)[FL]?//i && do {$new .= $1; next;};
399
+ s/^(\d+)\s*[LU]*//i && do {$new .= $1; next;};
400
+ s/^("(\\"|[^"])*")// && do {$new .= $1; next;};
401
+ s/^'((\\"|[^"])*)'// && do {
402
+ if ($curargs{$1}) {
403
+ $new .= "ord('\$$1')";
404
+ } else {
405
+ $new .= "ord('$1')";
406
+ }
407
+ next;
408
+ };
409
+ # replace "sizeof(foo)" with "{foo}"
410
+ # also, remove * (C dereference operator) to avoid perl syntax
411
+ # problems. Where the %sizeof array comes from is anyone's
412
+ # guess (c2ph?), but this at least avoids fatal syntax errors.
413
+ # Behavior is undefined if sizeof() delimiters are unbalanced.
414
+ # This code was modified to able to handle constructs like this:
415
+ # sizeof(*(p)), which appear in the HP-UX 10.01 header files.
416
+ s/^sizeof\s*\(// && do {
417
+ $new .= '$sizeof';
418
+ my $lvl = 1; # already saw one open paren
419
+ # tack { on the front, and skip it in the loop
420
+ $_ = "{" . "$_";
421
+ my $index = 1;
422
+ # find balanced closing paren
423
+ while ($index <= length($_) && $lvl > 0) {
424
+ $lvl++ if substr($_, $index, 1) eq "(";
425
+ $lvl-- if substr($_, $index, 1) eq ")";
426
+ $index++;
427
+ }
428
+ # tack } on the end, replacing )
429
+ substr($_, $index - 1, 1) = "}";
430
+ # remove pesky * operators within the sizeof argument
431
+ substr($_, 0, $index - 1) =~ s/\*//g;
432
+ next;
433
+ };
434
+ # Eliminate typedefs
435
+ /\(([\w\s]+)[\*\s]*\)\s*[\w\(]/ && do {
436
+ my $doit = 1;
437
+ foreach (split /\s+/, $1) { # Make sure all the words are types,
438
+ unless($isatype{$_} or $_ eq 'struct' or $_ eq 'union'){
439
+ $doit = 0;
440
+ last;
441
+ }
442
+ }
443
+ if( $doit ){
444
+ s/\([\w\s]+[\*\s]*\)// && next; # then eliminate them.
445
+ }
446
+ };
447
+ # struct/union member, including arrays:
448
+ s/^([_A-Z]\w*(\[[^\]]+\])?((\.|->)[_A-Z]\w*(\[[^\]]+\])?)+)//i && do {
449
+ my $id = $1;
450
+ $id =~ s/(\.|(->))([^\.\-]*)/->\{$3\}/g;
451
+ $id =~ s/\b([^\$])($joined_args)/$1\$$2/g if length($joined_args);
452
+ while($id =~ /\[\s*([^\$\&\d\]]+)\]/) {
453
+ my($index) = $1;
454
+ $index =~ s/\s//g;
455
+ if(exists($curargs{$index})) {
456
+ $index = "\$$index";
457
+ } else {
458
+ $index = "&$index";
459
+ }
460
+ $id =~ s/\[\s*([^\$\&\d\]]+)\]/[$index]/;
461
+ }
462
+ $new .= " (\$$id)";
463
+ };
464
+ s/^([_a-zA-Z]\w*)// && do {
465
+ my $id = $1;
466
+ if ($id eq 'struct' || $id eq 'union') {
467
+ s/^\s+(\w+)//;
468
+ $id .= ' ' . $1;
469
+ $isatype{$id} = 1;
470
+ } elsif ($id =~ /^((un)?signed)|(long)|(short)$/) {
471
+ while (s/^\s+(\w+)//) { $id .= ' ' . $1; }
472
+ $isatype{$id} = 1;
473
+ }
474
+ if ($curargs{$id}) {
475
+ $new .= "\$$id";
476
+ $new .= '->' if /^[\[\{]/;
477
+ } elsif ($id eq 'defined') {
478
+ $new .= 'defined';
479
+ } elsif (/^\s*\(/) {
480
+ s/^\s*\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i; # cheat
481
+ $new .= " &$id";
482
+ } elsif ($isatype{$id}) {
483
+ if ($new =~ /\{\s*$/) {
484
+ $new .= "'$id'";
485
+ } elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) {
486
+ $new =~ s/\(\s*$//;
487
+ s/^[\s*]*\)//;
488
+ } else {
489
+ $new .= q(').$id.q(');
490
+ }
491
+ } else {
492
+ if ($inif) {
493
+ if ($new =~ /defined\s*$/) {
494
+ $new .= '(&' . $id . ')';
495
+ } elsif ($new =~ /defined\s*\($/) {
496
+ $new .= '&' . $id;
497
+ } else {
498
+ $new .= '(defined(&' . $id . ') ? &' . $id . ' : undef)';
499
+ }
500
+ } elsif (/^\[/) {
501
+ $new .= " \$$id";
502
+ } else {
503
+ $new .= ' &' . $id;
504
+ }
505
+ }
506
+ next;
507
+ };
508
+ s/^(.)// && do { if ($1 ne '#') { $new .= $1; } next;};
509
+ }
510
+ }
511
+
512
+
513
+ sub next_line
514
+ {
515
+ my $file = shift;
516
+ my ($in, $out);
517
+ my $pre_sub_tri_graphs = 1;
518
+
519
+ READ: while (not eof IN) {
520
+ $in .= <IN>;
521
+ chomp $in;
522
+ next unless length $in;
523
+
524
+ while (length $in) {
525
+ if ($pre_sub_tri_graphs) {
526
+ # Preprocess all tri-graphs
527
+ # including things stuck in quoted string constants.
528
+ $in =~ s/\?\?=/#/g; # | ??=| #|
529
+ $in =~ s/\?\?\!/|/g; # | ??!| ||
530
+ $in =~ s/\?\?'/^/g; # | ??'| ^|
531
+ $in =~ s/\?\?\(/[/g; # | ??(| [|
532
+ $in =~ s/\?\?\)/]/g; # | ??)| ]|
533
+ $in =~ s/\?\?\-/~/g; # | ??-| ~|
534
+ $in =~ s/\?\?\//\\/g; # | ??/| \|
535
+ $in =~ s/\?\?</{/g; # | ??<| {|
536
+ $in =~ s/\?\?>/}/g; # | ??>| }|
537
+ }
538
+ if ($in =~ /^\#ifdef __LANGUAGE_PASCAL__/) {
539
+ # Tru64 disassembler.h evilness: mixed C and Pascal.
540
+ while (<IN>) {
541
+ last if /^\#endif/;
542
+ }
543
+ $in = "";
544
+ next READ;
545
+ }
546
+ if ($in =~ /^extern inline / && # Inlined assembler.
547
+ $^O eq 'linux' && $file =~ m!(?:^|/)asm/[^/]+\.h$!) {
548
+ while (<IN>) {
549
+ last if /^}/;
550
+ }
551
+ $in = "";
552
+ next READ;
553
+ }
554
+ if ($in =~ s/\\$//) { # \-newline
555
+ $out .= ' ';
556
+ next READ;
557
+ } elsif ($in =~ s/^([^"'\\\/]+)//) { # Passthrough
558
+ $out .= $1;
559
+ } elsif ($in =~ s/^(\\.)//) { # \...
560
+ $out .= $1;
561
+ } elsif ($in =~ /^'/) { # '...
562
+ if ($in =~ s/^('(\\.|[^'\\])*')//) {
563
+ $out .= $1;
564
+ } else {
565
+ next READ;
566
+ }
567
+ } elsif ($in =~ /^"/) { # "...
568
+ if ($in =~ s/^("(\\.|[^"\\])*")//) {
569
+ $out .= $1;
570
+ } else {
571
+ next READ;
572
+ }
573
+ } elsif ($in =~ s/^\/\/.*//) { # //...
574
+ # fall through
575
+ } elsif ($in =~ m/^\/\*/) { # /*...
576
+ # C comment removal adapted from perlfaq6:
577
+ if ($in =~ s/^\/\*[^*]*\*+([^\/*][^*]*\*+)*\///) {
578
+ $out .= ' ';
579
+ } else { # Incomplete /* */
580
+ next READ;
581
+ }
582
+ } elsif ($in =~ s/^(\/)//) { # /...
583
+ $out .= $1;
584
+ } elsif ($in =~ s/^([^\'\"\\\/]+)//) {
585
+ $out .= $1;
586
+ } elsif ($^O eq 'linux' &&
587
+ $file =~ m!(?:^|/)linux/byteorder/pdp_endian\.h$! &&
588
+ $in =~ s!\'T KNOW!!) {
589
+ $out =~ s!I DON$!I_DO_NOT_KNOW!;
590
+ } else {
591
+ if ($opt_e) {
592
+ warn "Cannot parse $file:\n$in\n";
593
+ $bad_file{$file} = 1;
594
+ $in = '';
595
+ $out = undef;
596
+ last READ;
597
+ } else {
598
+ die "Cannot parse:\n$in\n";
599
+ }
600
+ }
601
+ }
602
+
603
+ last READ if $out =~ /\S/;
604
+ }
605
+
606
+ return $out;
607
+ }
608
+
609
+
610
+ # Handle recursive subdirectories without getting a grotesquely big stack.
611
+ # Could this be implemented using File::Find?
612
+ sub next_file
613
+ {
614
+ my $file;
615
+
616
+ while (@ARGV) {
617
+ $file = shift @ARGV;
618
+
619
+ if ($file eq '-' or -f $file or -l $file) {
620
+ return $file;
621
+ } elsif (-d $file) {
622
+ if ($opt_r) {
623
+ expand_glob($file);
624
+ } else {
625
+ print STDERR "Skipping directory '$file'\n";
626
+ }
627
+ } elsif ($opt_a) {
628
+ return $file;
629
+ } else {
630
+ print STDERR "Skipping '$file': not a file or directory\n";
631
+ }
632
+ }
633
+
634
+ return undef;
635
+ }
636
+
637
+
638
+ # Put all the files in $directory into @ARGV for processing.
639
+ sub expand_glob
640
+ {
641
+ my ($directory) = @_;
642
+
643
+ $directory =~ s:/$::;
644
+
645
+ opendir DIR, $directory;
646
+ foreach (readdir DIR) {
647
+ next if ($_ eq '.' or $_ eq '..');
648
+
649
+ # expand_glob() is going to be called until $ARGV[0] isn't a
650
+ # directory; so push directories, and unshift everything else.
651
+ if (-d "$directory/$_") { push @ARGV, "$directory/$_" }
652
+ else { unshift @ARGV, "$directory/$_" }
653
+ }
654
+ closedir DIR;
655
+ }
656
+
657
+
658
+ # Given $file, a symbolic link to a directory in the C include directory,
659
+ # make an equivalent symbolic link in $Dest_dir, if we can figure out how.
660
+ # Otherwise, just duplicate the file or directory.
661
+ sub link_if_possible
662
+ {
663
+ my ($dirlink) = @_;
664
+ my $target = eval 'readlink($dirlink)';
665
+
666
+ if ($target =~ m:^\.\./: or $target =~ m:^/:) {
667
+ # The target of a parent or absolute link could leave the $Dest_dir
668
+ # hierarchy, so let's put all of the contents of $dirlink (actually,
669
+ # the contents of $target) into @ARGV; as a side effect down the
670
+ # line, $dirlink will get created as an _actual_ directory.
671
+ expand_glob($dirlink);
672
+ } else {
673
+ if (-l "$Dest_dir/$dirlink") {
674
+ unlink "$Dest_dir/$dirlink" or
675
+ print STDERR "Could not remove link $Dest_dir/$dirlink: $!\n";
676
+ }
677
+
678
+ if (eval 'symlink($target, "$Dest_dir/$dirlink")') {
679
+ print "Linking $target -> $Dest_dir/$dirlink\n";
680
+
681
+ # Make sure that the link _links_ to something:
682
+ if (! -e "$Dest_dir/$target") {
683
+ mkpath("$Dest_dir/$target", 0755) or
684
+ print STDERR "Could not create $Dest_dir/$target/\n";
685
+ }
686
+ } else {
687
+ print STDERR "Could not symlink $target -> $Dest_dir/$dirlink: $!\n";
688
+ }
689
+ }
690
+ }
691
+
692
+
693
+ # Push all #included files in $file onto our stack, except for STDIN
694
+ # and files we've already processed.
695
+ sub queue_includes_from
696
+ {
697
+ my ($file) = @_;
698
+ my $line;
699
+
700
+ return if ($file eq "-");
701
+
702
+ open HEADER, "<", $file or return;
703
+ while (defined($line = <HEADER>)) {
704
+ while (/\\$/) { # Handle continuation lines
705
+ chop $line;
706
+ $line .= <HEADER>;
707
+ }
708
+
709
+ if ($line =~ /^#\s*include\s+([<"])(.*?)[>"]/) {
710
+ my ($delimiter, $new_file) = ($1, $2);
711
+ # copy the prefix in the quote syntax (#include "x.h") case
712
+ if ($delimiter eq q{"} && $file =~ m|^(.*)/|) {
713
+ $new_file = "$1/$new_file";
714
+ }
715
+ push(@ARGV, $new_file) unless $Is_converted{$new_file};
716
+ }
717
+ }
718
+ close HEADER;
719
+ }
720
+
721
+
722
+ # Determine include directories; $Config{usrinc} should be enough for (all
723
+ # non-GCC?) C compilers, but gcc uses additional include directories.
724
+ sub inc_dirs
725
+ {
726
+ my $from_gcc = `LC_ALL=C $Config{cc} -v -E - < /dev/null 2>&1 | awk '/^#include/, /^End of search list/' | grep '^ '`;
727
+ length($from_gcc) ? (split(' ', $from_gcc), $Config{usrinc}) : ($Config{usrinc});
728
+ }
729
+
730
+
731
+ # Create "_h2ph_pre.ph", if it doesn't exist or was built by a different
732
+ # version of h2ph.
733
+ sub build_preamble_if_necessary
734
+ {
735
+ # Increment $VERSION every time this function is modified:
736
+ my $VERSION = 5;
737
+ my $preamble = "$Dest_dir/_h2ph_pre.ph";
738
+
739
+ # Can we skip building the preamble file?
740
+ if (-r $preamble) {
741
+ # Extract version number from first line of preamble:
742
+ open PREAMBLE, "<", $preamble or die "Cannot open $preamble: $!";
743
+ my $line = <PREAMBLE>;
744
+ $line =~ /(\b\d+\b)/;
745
+ close PREAMBLE or die "Cannot close $preamble: $!";
746
+
747
+ # Don't build preamble if a compatible preamble exists:
748
+ return if $1 == $VERSION;
749
+ }
750
+
751
+ my (%define) = _extract_cc_defines();
752
+
753
+ open PREAMBLE, ">", $preamble or die "Cannot open $preamble: $!";
754
+ print PREAMBLE "# This file was created by h2ph version $VERSION\n";
755
+ # Prevent non-portable hex constants from warning.
756
+ #
757
+ # We still produce an overflow warning if we can't represent
758
+ # a hex constant as an integer.
759
+ print PREAMBLE "no warnings qw(portable);\n";
760
+
761
+ foreach (sort keys %define) {
762
+ if ($opt_D) {
763
+ print PREAMBLE "# $_=$define{$_}\n";
764
+ }
765
+ if ($define{$_} =~ /^\((.*)\)$/) {
766
+ # parenthesized value: d=(v)
767
+ $define{$_} = $1;
768
+ }
769
+ if (/^(\w+)\((\w)\)$/) {
770
+ my($macro, $arg) = ($1, $2);
771
+ my $def = $define{$_};
772
+ $def =~ s/$arg/\$\{$arg\}/g;
773
+ print PREAMBLE <<DEFINE;
774
+ sub $macro(\$) { my (\$$arg) = \@_; \"$def\" }
775
+
776
+ DEFINE
777
+ } elsif
778
+ ($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/) {
779
+ # float:
780
+ print PREAMBLE "sub $_() { $1 }\n\n";
781
+ } elsif ($define{$_} =~ /^([+-]?\d+)U?L{0,2}$/i) {
782
+ # integer:
783
+ print PREAMBLE "sub $_() { $1 }\n\n";
784
+ } elsif ($define{$_} =~ /^([+-]?0x[\da-f]+)U?L{0,2}$/i) {
785
+ # hex integer
786
+ # Special cased, since perl warns on hex integers
787
+ # that can't be represented in a UV.
788
+ #
789
+ # This way we get the warning at time of use, so the user
790
+ # only gets the warning if they happen to use this
791
+ # platform-specific definition.
792
+ my $code = $1;
793
+ $code = "hex('$code')" if length $code > 10;
794
+ print PREAMBLE "sub $_() { $code }\n\n";
795
+ } elsif ($define{$_} =~ /^\w+$/) {
796
+ my $def = $define{$_};
797
+ if ($isatype{$def}) {
798
+ print PREAMBLE "sub $_() { \"$def\" }\n\n";
799
+ } else {
800
+ print PREAMBLE "sub $_() { &$def }\n\n";
801
+ }
802
+ } else {
803
+ print PREAMBLE "sub $_() { \"\Q$define{$_}\E\" }\n\n";
804
+ }
805
+ }
806
+ print PREAMBLE "\n1;\n"; # avoid 'did not return a true value' when empty
807
+ close PREAMBLE or die "Cannot close $preamble: $!";
808
+ }
809
+
810
+
811
+ # %Config contains information on macros that are pre-defined by the
812
+ # system's compiler. We need this information to make the .ph files
813
+ # function with perl as the .h files do with cc.
814
+ sub _extract_cc_defines
815
+ {
816
+ my %define;
817
+ my $allsymbols = join " ",
818
+ @Config{'ccsymbols', 'cppsymbols', 'cppccsymbols'};
819
+
820
+ # Split compiler pre-definitions into 'key=value' pairs:
821
+ while ($allsymbols =~ /([^\s]+)=((\\\s|[^\s])+)/g) {
822
+ $define{$1} = $2;
823
+ if ($opt_D) {
824
+ print STDERR "$_: $1 -> $2\n";
825
+ }
826
+ }
827
+
828
+ return %define;
829
+ }
830
+
831
+
832
+ 1;
833
+
834
+ ##############################################################################
835
+ __END__
836
+
837
+ =head1 NAME
838
+
839
+ h2ph - convert .h C header files to .ph Perl header files
840
+
841
+ =head1 SYNOPSIS
842
+
843
+ B<h2ph [-d destination directory] [-r | -a] [-l] [-h] [-e] [-D] [-Q]
844
+ [headerfiles]>
845
+
846
+ =head1 DESCRIPTION
847
+
848
+ I<h2ph>
849
+ converts any C header files specified to the corresponding Perl header file
850
+ format.
851
+ It is most easily run while in /usr/include:
852
+
853
+ cd /usr/include; h2ph * sys/*
854
+
855
+ or
856
+
857
+ cd /usr/include; h2ph * sys/* arpa/* netinet/*
858
+
859
+ or
860
+
861
+ cd /usr/include; h2ph -r -l .
862
+
863
+ The output files are placed in the hierarchy rooted at Perl's
864
+ architecture dependent library directory. You can specify a different
865
+ hierarchy with a B<-d> switch.
866
+
867
+ If run with no arguments, filters standard input to standard output.
868
+
869
+ =head1 OPTIONS
870
+
871
+ =over 4
872
+
873
+ =item -d destination_dir
874
+
875
+ Put the resulting B<.ph> files beneath B<destination_dir>, instead of
876
+ beneath the default Perl library location (C<$Config{'installsitearch'}>).
877
+
878
+ =item -r
879
+
880
+ Run recursively; if any of B<headerfiles> are directories, then run I<h2ph>
881
+ on all files in those directories (and their subdirectories, etc.). B<-r>
882
+ and B<-a> are mutually exclusive.
883
+
884
+ =item -a
885
+
886
+ Run automagically; convert B<headerfiles>, as well as any B<.h> files
887
+ which they include. This option will search for B<.h> files in all
888
+ directories which your C compiler ordinarily uses. B<-a> and B<-r> are
889
+ mutually exclusive.
890
+
891
+ =item -l
892
+
893
+ Symbolic links will be replicated in the destination directory. If B<-l>
894
+ is not specified, then links are skipped over.
895
+
896
+ =item -h
897
+
898
+ Put 'hints' in the .ph files which will help in locating problems with
899
+ I<h2ph>. In those cases when you B<require> a B<.ph> file containing syntax
900
+ errors, instead of the cryptic
901
+
902
+ [ some error condition ] at (eval mmm) line nnn
903
+
904
+ you will see the slightly more helpful
905
+
906
+ [ some error condition ] at filename.ph line nnn
907
+
908
+ However, the B<.ph> files almost double in size when built using B<-h>.
909
+
910
+ =item -e
911
+
912
+ If an error is encountered during conversion, output file will be removed and
913
+ a warning emitted instead of terminating the conversion immediately.
914
+
915
+ =item -D
916
+
917
+ Include the code from the B<.h> file as a comment in the B<.ph> file.
918
+ This is primarily used for debugging I<h2ph>.
919
+
920
+ =item -Q
921
+
922
+ 'Quiet' mode; don't print out the names of the files being converted.
923
+
924
+ =back
925
+
926
+ =head1 ENVIRONMENT
927
+
928
+ No environment variables are used.
929
+
930
+ =head1 FILES
931
+
932
+ /usr/include/*.h
933
+ /usr/include/sys/*.h
934
+
935
+ etc.
936
+
937
+ =head1 AUTHOR
938
+
939
+ Larry Wall
940
+
941
+ =head1 SEE ALSO
942
+
943
+ perl(1)
944
+
945
+ =head1 DIAGNOSTICS
946
+
947
+ The usual warnings if it can't read or write the files involved.
948
+
949
+ =head1 BUGS
950
+
951
+ Doesn't construct the %sizeof array for you.
952
+
953
+ It doesn't handle all C constructs, but it does attempt to isolate
954
+ definitions inside evals so that you can get at the definitions
955
+ that it can translate.
956
+
957
+ It's only intended as a rough tool.
958
+ You may need to dicker with the files produced.
959
+
960
+ You have to run this program by hand; it's not run as part of the Perl
961
+ installation.
962
+
963
+ Doesn't handle complicated expressions built piecemeal, a la:
964
+
965
+ enum {
966
+ FIRST_VALUE,
967
+ SECOND_VALUE,
968
+ #ifdef ABC
969
+ THIRD_VALUE
970
+ #endif
971
+ };
972
+
973
+ Doesn't necessarily locate all of your C compiler's internally-defined
974
+ symbols.
975
+
976
+ =cut
977
+
git/usr/bin/core_perl/h2xs ADDED
@@ -0,0 +1,2207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ BEGIN { pop @INC if $INC[-1] eq '.' }
6
+
7
+ use warnings;
8
+
9
+ =head1 NAME
10
+
11
+ h2xs - convert .h C header files to Perl extensions
12
+
13
+ =head1 SYNOPSIS
14
+
15
+ B<h2xs> [B<OPTIONS> ...] [headerfile ... [extra_libraries]]
16
+
17
+ B<h2xs> B<-h>|B<-?>|B<--help>
18
+
19
+ =head1 DESCRIPTION
20
+
21
+ I<h2xs> builds a Perl extension from C header files. The extension
22
+ will include functions which can be used to retrieve the value of any
23
+ #define statement which was in the C header files.
24
+
25
+ The I<module_name> will be used for the name of the extension. If
26
+ module_name is not supplied then the name of the first header file
27
+ will be used, with the first character capitalized.
28
+
29
+ If the extension might need extra libraries, they should be included
30
+ here. The extension Makefile.PL will take care of checking whether
31
+ the libraries actually exist and how they should be loaded. The extra
32
+ libraries should be specified in the form -lm -lposix, etc, just as on
33
+ the cc command line. By default, the Makefile.PL will search through
34
+ the library path determined by Configure. That path can be augmented
35
+ by including arguments of the form B<-L/another/library/path> in the
36
+ extra-libraries argument.
37
+
38
+ In spite of its name, I<h2xs> may also be used to create a skeleton pure
39
+ Perl module. See the B<-X> option.
40
+
41
+ =head1 OPTIONS
42
+
43
+ =over 5
44
+
45
+ =item B<-A>, B<--omit-autoload>
46
+
47
+ Omit all autoload facilities. This is the same as B<-c> but also
48
+ removes the S<C<use AutoLoader>> statement from the .pm file.
49
+
50
+ =item B<-B>, B<--beta-version>
51
+
52
+ Use an alpha/beta style version number. Causes version number to
53
+ be "0.00_01" unless B<-v> is specified.
54
+
55
+ =item B<-C>, B<--omit-changes>
56
+
57
+ Omits creation of the F<Changes> file, and adds a HISTORY section to
58
+ the POD template.
59
+
60
+ =item B<-F>, B<--cpp-flags>=I<addflags>
61
+
62
+ Additional flags to specify to C preprocessor when scanning header for
63
+ function declarations. Writes these options in the generated F<Makefile.PL>
64
+ too.
65
+
66
+ =item B<-M>, B<--func-mask>=I<regular expression>
67
+
68
+ selects functions/macros to process.
69
+
70
+ =item B<-O>, B<--overwrite-ok>
71
+
72
+ Allows a pre-existing extension directory to be overwritten.
73
+
74
+ =item B<-P>, B<--omit-pod>
75
+
76
+ Omit the autogenerated stub POD section.
77
+
78
+ =item B<-X>, B<--omit-XS>
79
+
80
+ Omit the XS portion. Used to generate a skeleton pure Perl module.
81
+ C<-c> and C<-f> are implicitly enabled.
82
+
83
+ =item B<-a>, B<--gen-accessors>
84
+
85
+ Generate an accessor method for each element of structs and unions. The
86
+ generated methods are named after the element name; will return the current
87
+ value of the element if called without additional arguments; and will set
88
+ the element to the supplied value (and return the new value) if called with
89
+ an additional argument. Embedded structures and unions are returned as a
90
+ pointer rather than the complete structure, to facilitate chained calls.
91
+
92
+ These methods all apply to the Ptr type for the structure; additionally
93
+ two methods are constructed for the structure type itself, C<_to_ptr>
94
+ which returns a Ptr type pointing to the same structure, and a C<new>
95
+ method to construct and return a new structure, initialised to zeroes.
96
+
97
+ =item B<-b>, B<--compat-version>=I<version>
98
+
99
+ Generates a .pm file which is backwards compatible with the specified
100
+ perl version.
101
+
102
+ For versions < 5.6.0, the changes are.
103
+ - no use of 'our' (uses 'use vars' instead)
104
+ - no 'use warnings'
105
+
106
+ Specifying a compatibility version higher than the version of perl you
107
+ are using to run h2xs will have no effect. If unspecified h2xs will default
108
+ to compatibility with the version of perl you are using to run h2xs.
109
+
110
+ =item B<-c>, B<--omit-constant>
111
+
112
+ Omit C<constant()> from the .xs file and corresponding specialised
113
+ C<AUTOLOAD> from the .pm file.
114
+
115
+ =item B<-d>, B<--debugging>
116
+
117
+ Turn on debugging messages.
118
+
119
+ =item B<-e>, B<--omit-enums>=[I<regular expression>]
120
+
121
+ If I<regular expression> is not given, skip all constants that are defined in
122
+ a C enumeration. Otherwise skip only those constants that are defined in an
123
+ enum whose name matches I<regular expression>.
124
+
125
+ Since I<regular expression> is optional, make sure that this switch is followed
126
+ by at least one other switch if you omit I<regular expression> and have some
127
+ pending arguments such as header-file names. This is ok:
128
+
129
+ h2xs -e -n Module::Foo foo.h
130
+
131
+ This is not ok:
132
+
133
+ h2xs -n Module::Foo -e foo.h
134
+
135
+ In the latter, foo.h is taken as I<regular expression>.
136
+
137
+ =item B<-f>, B<--force>
138
+
139
+ Allows an extension to be created for a header even if that header is
140
+ not found in standard include directories.
141
+
142
+ =item B<-g>, B<--global>
143
+
144
+ Include code for safely storing static data in the .xs file.
145
+ Extensions that do no make use of static data can ignore this option.
146
+
147
+ =item B<-h>, B<-?>, B<--help>
148
+
149
+ Print the usage, help and version for this h2xs and exit.
150
+
151
+ =item B<-k>, B<--omit-const-func>
152
+
153
+ For function arguments declared as C<const>, omit the const attribute in the
154
+ generated XS code.
155
+
156
+ =item B<-m>, B<--gen-tied-var>
157
+
158
+ B<Experimental>: for each variable declared in the header file(s), declare
159
+ a perl variable of the same name magically tied to the C variable.
160
+
161
+ =item B<-n>, B<--name>=I<module_name>
162
+
163
+ Specifies a name to be used for the extension, e.g., S<-n RPC::DCE>
164
+
165
+ =item B<-o>, B<--opaque-re>=I<regular expression>
166
+
167
+ Use "opaque" data type for the C types matched by the regular
168
+ expression, even if these types are C<typedef>-equivalent to types
169
+ from typemaps. Should not be used without B<-x>.
170
+
171
+ This may be useful since, say, types which are C<typedef>-equivalent
172
+ to integers may represent OS-related handles, and one may want to work
173
+ with these handles in OO-way, as in C<$handle-E<gt>do_something()>.
174
+ Use C<-o .> if you want to handle all the C<typedef>ed types as opaque
175
+ types.
176
+
177
+ The type-to-match is whitewashed (except for commas, which have no
178
+ whitespace before them, and multiple C<*> which have no whitespace
179
+ between them).
180
+
181
+ =item B<-p>, B<--remove-prefix>=I<prefix>
182
+
183
+ Specify a prefix which should be removed from the Perl function names,
184
+ e.g., S<-p sec_rgy_> This sets up the XS B<PREFIX> keyword and removes
185
+ the prefix from functions that are autoloaded via the C<constant()>
186
+ mechanism.
187
+
188
+ =item B<-s>, B<--const-subs>=I<sub1,sub2>
189
+
190
+ Create a perl subroutine for the specified macros rather than autoload
191
+ with the constant() subroutine. These macros are assumed to have a
192
+ return type of B<char *>, e.g.,
193
+ S<-s sec_rgy_wildcard_name,sec_rgy_wildcard_sid>.
194
+
195
+ =item B<-t>, B<--default-type>=I<type>
196
+
197
+ Specify the internal type that the constant() mechanism uses for macros.
198
+ The default is IV (signed integer). Currently all macros found during the
199
+ header scanning process will be assumed to have this type. Future versions
200
+ of C<h2xs> may gain the ability to make educated guesses.
201
+
202
+ =item B<--use-new-tests>
203
+
204
+ When B<--compat-version> (B<-b>) is present the generated tests will use
205
+ C<Test::More> rather than C<Test> which is the default for versions before
206
+ 5.6.2. C<Test::More> will be added to PREREQ_PM in the generated
207
+ C<Makefile.PL>.
208
+
209
+ =item B<--use-old-tests>
210
+
211
+ Will force the generation of test code that uses the older C<Test> module.
212
+
213
+ =item B<--skip-exporter>
214
+
215
+ Do not use C<Exporter> and/or export any symbol.
216
+
217
+ =item B<--skip-ppport>
218
+
219
+ Do not use C<Devel::PPPort>: no portability to older version.
220
+
221
+ =item B<--skip-autoloader>
222
+
223
+ Do not use the module C<AutoLoader>; but keep the constant() function
224
+ and C<sub AUTOLOAD> for constants.
225
+
226
+ =item B<--skip-strict>
227
+
228
+ Do not use the pragma C<strict>.
229
+
230
+ =item B<--skip-warnings>
231
+
232
+ Do not use the pragma C<warnings>.
233
+
234
+ =item B<-v>, B<--version>=I<version>
235
+
236
+ Specify a version number for this extension. This version number is added
237
+ to the templates. The default is 0.01, or 0.00_01 if C<-B> is specified.
238
+ The version specified should be numeric.
239
+
240
+ =item B<-x>, B<--autogen-xsubs>
241
+
242
+ Automatically generate XSUBs basing on function declarations in the
243
+ header file. The package C<C::Scan> should be installed. If this
244
+ option is specified, the name of the header file may look like
245
+ C<NAME1,NAME2>. In this case NAME1 is used instead of the specified
246
+ string, but XSUBs are emitted only for the declarations included from
247
+ file NAME2.
248
+
249
+ Note that some types of arguments/return-values for functions may
250
+ result in XSUB-declarations/typemap-entries which need
251
+ hand-editing. Such may be objects which cannot be converted from/to a
252
+ pointer (like C<long long>), pointers to functions, or arrays. See
253
+ also the section on L</LIMITATIONS of B<-x>>.
254
+
255
+ =back
256
+
257
+ =head1 EXAMPLES
258
+
259
+
260
+ # Default behavior, extension is Rusers
261
+ h2xs rpcsvc/rusers
262
+
263
+ # Same, but extension is RUSERS
264
+ h2xs -n RUSERS rpcsvc/rusers
265
+
266
+ # Extension is rpcsvc::rusers. Still finds <rpcsvc/rusers.h>
267
+ h2xs rpcsvc::rusers
268
+
269
+ # Extension is ONC::RPC. Still finds <rpcsvc/rusers.h>
270
+ h2xs -n ONC::RPC rpcsvc/rusers
271
+
272
+ # Without constant() or AUTOLOAD
273
+ h2xs -c rpcsvc/rusers
274
+
275
+ # Creates templates for an extension named RPC
276
+ h2xs -cfn RPC
277
+
278
+ # Extension is ONC::RPC.
279
+ h2xs -cfn ONC::RPC
280
+
281
+ # Extension is a pure Perl module with no XS code.
282
+ h2xs -X My::Module
283
+
284
+ # Extension is Lib::Foo which works at least with Perl5.005_03.
285
+ # Constants are created for all #defines and enums h2xs can find
286
+ # in foo.h.
287
+ h2xs -b 5.5.3 -n Lib::Foo foo.h
288
+
289
+ # Extension is Lib::Foo which works at least with Perl5.005_03.
290
+ # Constants are created for all #defines but only for enums
291
+ # whose names do not start with 'bar_'.
292
+ h2xs -b 5.5.3 -e '^bar_' -n Lib::Foo foo.h
293
+
294
+ # Makefile.PL will look for library -lrpc in
295
+ # additional directory /opt/net/lib
296
+ h2xs rpcsvc/rusers -L/opt/net/lib -lrpc
297
+
298
+ # Extension is DCE::rgynbase
299
+ # prefix "sec_rgy_" is dropped from perl function names
300
+ h2xs -n DCE::rgynbase -p sec_rgy_ dce/rgynbase
301
+
302
+ # Extension is DCE::rgynbase
303
+ # prefix "sec_rgy_" is dropped from perl function names
304
+ # subroutines are created for sec_rgy_wildcard_name and
305
+ # sec_rgy_wildcard_sid
306
+ h2xs -n DCE::rgynbase -p sec_rgy_ \
307
+ -s sec_rgy_wildcard_name,sec_rgy_wildcard_sid dce/rgynbase
308
+
309
+ # Make XS without defines in perl.h, but with function declarations
310
+ # visible from perl.h. Name of the extension is perl1.
311
+ # When scanning perl.h, define -DEXT=extern -DdEXT= -DINIT(x)=
312
+ # Extra backslashes below because the string is passed to shell.
313
+ # Note that a directory with perl header files would
314
+ # be added automatically to include path.
315
+ h2xs -xAn perl1 -F "-DEXT=extern -DdEXT= -DINIT\(x\)=" perl.h
316
+
317
+ # Same with function declaration in proto.h as visible from perl.h.
318
+ h2xs -xAn perl2 perl.h,proto.h
319
+
320
+ # Same but select only functions which match /^av_/
321
+ h2xs -M '^av_' -xAn perl2 perl.h,proto.h
322
+
323
+ # Same but treat SV* etc as "opaque" types
324
+ h2xs -o '^[S]V \*$' -M '^av_' -xAn perl2 perl.h,proto.h
325
+
326
+ =head2 Extension based on F<.h> and F<.c> files
327
+
328
+ Suppose that you have some C files implementing some functionality,
329
+ and the corresponding header files. How to create an extension which
330
+ makes this functionality accessible in Perl? The example below
331
+ assumes that the header files are F<interface_simple.h> and
332
+ I<interface_hairy.h>, and you want the perl module be named as
333
+ C<Ext::Ension>. If you need some preprocessor directives and/or
334
+ linking with external libraries, see the flags C<-F>, C<-L> and C<-l>
335
+ in L<"OPTIONS">.
336
+
337
+ =over
338
+
339
+ =item Find the directory name
340
+
341
+ Start with a dummy run of h2xs:
342
+
343
+ h2xs -Afn Ext::Ension
344
+
345
+ The only purpose of this step is to create the needed directories, and
346
+ let you know the names of these directories. From the output you can
347
+ see that the directory for the extension is F<Ext/Ension>.
348
+
349
+ =item Copy C files
350
+
351
+ Copy your header files and C files to this directory F<Ext/Ension>.
352
+
353
+ =item Create the extension
354
+
355
+ Run h2xs, overwriting older autogenerated files:
356
+
357
+ h2xs -Oxan Ext::Ension interface_simple.h interface_hairy.h
358
+
359
+ h2xs looks for header files I<after> changing to the extension
360
+ directory, so it will find your header files OK.
361
+
362
+ =item Archive and test
363
+
364
+ As usual, run
365
+
366
+ cd Ext/Ension
367
+ perl Makefile.PL
368
+ make dist
369
+ make
370
+ make test
371
+
372
+ =item Hints
373
+
374
+ It is important to do C<make dist> as early as possible. This way you
375
+ can easily merge(1) your changes to autogenerated files if you decide
376
+ to edit your C<.h> files and rerun h2xs.
377
+
378
+ Do not forget to edit the documentation in the generated F<.pm> file.
379
+
380
+ Consider the autogenerated files as skeletons only, you may invent
381
+ better interfaces than what h2xs could guess.
382
+
383
+ Consider this section as a guideline only, some other options of h2xs
384
+ may better suit your needs.
385
+
386
+ =back
387
+
388
+ =head1 ENVIRONMENT
389
+
390
+ No environment variables are used.
391
+
392
+ =head1 AUTHOR
393
+
394
+ Larry Wall and others
395
+
396
+ =head1 SEE ALSO
397
+
398
+ L<perl>, L<perlxstut>, L<ExtUtils::MakeMaker>, and L<AutoLoader>.
399
+
400
+ =head1 DIAGNOSTICS
401
+
402
+ The usual warnings if it cannot read or write the files involved.
403
+
404
+ =head1 LIMITATIONS of B<-x>
405
+
406
+ F<h2xs> would not distinguish whether an argument to a C function
407
+ which is of the form, say, C<int *>, is an input, output, or
408
+ input/output parameter. In particular, argument declarations of the
409
+ form
410
+
411
+ int
412
+ foo(n)
413
+ int *n
414
+
415
+ should be better rewritten as
416
+
417
+ int
418
+ foo(n)
419
+ int &n
420
+
421
+ if C<n> is an input parameter.
422
+
423
+ Additionally, F<h2xs> has no facilities to intuit that a function
424
+
425
+ int
426
+ foo(addr,l)
427
+ char *addr
428
+ int l
429
+
430
+ takes a pair of address and length of data at this address, so it is better
431
+ to rewrite this function as
432
+
433
+ int
434
+ foo(sv)
435
+ SV *addr
436
+ PREINIT:
437
+ STRLEN len;
438
+ char *s;
439
+ CODE:
440
+ s = SvPV(sv,len);
441
+ RETVAL = foo(s, len);
442
+ OUTPUT:
443
+ RETVAL
444
+
445
+ or alternately
446
+
447
+ static int
448
+ my_foo(SV *sv)
449
+ {
450
+ STRLEN len;
451
+ char *s = SvPV(sv,len);
452
+
453
+ return foo(s, len);
454
+ }
455
+
456
+ MODULE = foo PACKAGE = foo PREFIX = my_
457
+
458
+ int
459
+ foo(sv)
460
+ SV *sv
461
+
462
+ See L<perlxs> and L<perlxstut> for additional details.
463
+
464
+ =cut
465
+
466
+ # ' # Grr
467
+ use strict;
468
+
469
+
470
+ my( $H2XS_VERSION ) = ' $Revision: 1.23 $ ' =~ /\$Revision:\s+([^\s]+)/;
471
+ my $TEMPLATE_VERSION = '0.01';
472
+ my @ARGS = @ARGV;
473
+ my $compat_version = $];
474
+
475
+ use Getopt::Long;
476
+ use Config;
477
+ use Text::Wrap;
478
+ $Text::Wrap::huge = 'overflow';
479
+ $Text::Wrap::columns = 80;
480
+ use ExtUtils::Constant qw (WriteConstants WriteMakefileSnippet autoload);
481
+ use File::Compare;
482
+ use File::Path;
483
+
484
+ sub usage {
485
+ warn "@_\n" if @_;
486
+ die <<EOFUSAGE;
487
+ h2xs [OPTIONS ... ] [headerfile [extra_libraries]]
488
+ version: $H2XS_VERSION
489
+ OPTIONS:
490
+ -A, --omit-autoload Omit all autoloading facilities (implies -c).
491
+ -B, --beta-version Use beta \$VERSION of 0.00_01 (ignored if -v).
492
+ -C, --omit-changes Omit creating the Changes file, add HISTORY heading
493
+ to stub POD.
494
+ -F, --cpp-flags Additional flags for C preprocessor/compile.
495
+ -M, --func-mask Mask to select C functions/macros
496
+ (default is select all).
497
+ -O, --overwrite-ok Allow overwriting of a pre-existing extension directory.
498
+ -P, --omit-pod Omit the stub POD section.
499
+ -X, --omit-XS Omit the XS portion (implies both -c and -f).
500
+ -a, --gen-accessors Generate get/set accessors for struct and union members
501
+ (used with -x).
502
+ -b, --compat-version Specify a perl version to be backwards compatible with.
503
+ -c, --omit-constant Omit the constant() function and specialised AUTOLOAD
504
+ from the XS file.
505
+ -d, --debugging Turn on debugging messages.
506
+ -e, --omit-enums Omit constants from enums in the constant() function.
507
+ If a pattern is given, only the matching enums are
508
+ ignored.
509
+ -f, --force Force creation of the extension even if the C header
510
+ does not exist.
511
+ -g, --global Include code for safely storing static data in the .xs file.
512
+ -h, -?, --help Display this help message.
513
+ -k, --omit-const-func Omit 'const' attribute on function arguments
514
+ (used with -x).
515
+ -m, --gen-tied-var Generate tied variables for access to declared
516
+ variables.
517
+ -n, --name Specify a name to use for the extension (recommended).
518
+ -o, --opaque-re Regular expression for \"opaque\" types.
519
+ -p, --remove-prefix Specify a prefix which should be removed from the
520
+ Perl function names.
521
+ -s, --const-subs Create subroutines for specified macros.
522
+ -t, --default-type Default type for autoloaded constants (default is IV).
523
+ --use-new-tests Use Test::More in backward compatible modules.
524
+ --use-old-tests Use the module Test rather than Test::More.
525
+ --skip-exporter Do not export symbols.
526
+ --skip-ppport Do not use portability layer.
527
+ --skip-autoloader Do not use the module C<AutoLoader>.
528
+ --skip-strict Do not use the pragma C<strict>.
529
+ --skip-warnings Do not use the pragma C<warnings>.
530
+ -v, --version Specify a version number for this extension.
531
+ -x, --autogen-xsubs Autogenerate XSUBs using C::Scan.
532
+ --use-xsloader Use XSLoader in backward compatible modules (ignored
533
+ when used with -X).
534
+
535
+ extra_libraries
536
+ are any libraries that might be needed for loading the
537
+ extension, e.g. -lm would try to link in the math library.
538
+ EOFUSAGE
539
+ }
540
+
541
+ my ($opt_A,
542
+ $opt_B,
543
+ $opt_C,
544
+ $opt_F,
545
+ $opt_M,
546
+ $opt_O,
547
+ $opt_P,
548
+ $opt_X,
549
+ $opt_a,
550
+ $opt_c,
551
+ $opt_d,
552
+ $opt_e,
553
+ $opt_f,
554
+ $opt_g,
555
+ $opt_h,
556
+ $opt_k,
557
+ $opt_m,
558
+ $opt_n,
559
+ $opt_o,
560
+ $opt_p,
561
+ $opt_s,
562
+ $opt_v,
563
+ $opt_x,
564
+ $opt_b,
565
+ $opt_t,
566
+ $new_test,
567
+ $old_test,
568
+ $skip_exporter,
569
+ $skip_ppport,
570
+ $skip_autoloader,
571
+ $skip_strict,
572
+ $skip_warnings,
573
+ $use_xsloader
574
+ );
575
+
576
+ Getopt::Long::Configure('bundling');
577
+ Getopt::Long::Configure('pass_through');
578
+
579
+ my %options = (
580
+ 'omit-autoload|A' => \$opt_A,
581
+ 'beta-version|B' => \$opt_B,
582
+ 'omit-changes|C' => \$opt_C,
583
+ 'cpp-flags|F=s' => \$opt_F,
584
+ 'func-mask|M=s' => \$opt_M,
585
+ 'overwrite_ok|O' => \$opt_O,
586
+ 'omit-pod|P' => \$opt_P,
587
+ 'omit-XS|X' => \$opt_X,
588
+ 'gen-accessors|a' => \$opt_a,
589
+ 'compat-version|b=s' => \$opt_b,
590
+ 'omit-constant|c' => \$opt_c,
591
+ 'debugging|d' => \$opt_d,
592
+ 'omit-enums|e:s' => \$opt_e,
593
+ 'force|f' => \$opt_f,
594
+ 'global|g' => \$opt_g,
595
+ 'help|h|?' => \$opt_h,
596
+ 'omit-const-func|k' => \$opt_k,
597
+ 'gen-tied-var|m' => \$opt_m,
598
+ 'name|n=s' => \$opt_n,
599
+ 'opaque-re|o=s' => \$opt_o,
600
+ 'remove-prefix|p=s' => \$opt_p,
601
+ 'const-subs|s=s' => \$opt_s,
602
+ 'default-type|t=s' => \$opt_t,
603
+ 'version|v=s' => \$opt_v,
604
+ 'autogen-xsubs|x' => \$opt_x,
605
+ 'use-new-tests' => \$new_test,
606
+ 'use-old-tests' => \$old_test,
607
+ 'skip-exporter' => \$skip_exporter,
608
+ 'skip-ppport' => \$skip_ppport,
609
+ 'skip-autoloader' => \$skip_autoloader,
610
+ 'skip-warnings' => \$skip_warnings,
611
+ 'skip-strict' => \$skip_strict,
612
+ 'use-xsloader' => \$use_xsloader,
613
+ );
614
+
615
+ GetOptions(%options) || usage;
616
+
617
+ usage if $opt_h;
618
+
619
+ if( $opt_b ){
620
+ usage "You cannot use -b and -m at the same time.\n" if ($opt_b && $opt_m);
621
+ $opt_b =~ /^v?(\d+)\.(\d+)\.(\d+)/ ||
622
+ usage "You must provide the backwards compatibility version in X.Y.Z form. "
623
+ . "(i.e. 5.5.0)\n";
624
+ my ($maj,$min,$sub) = ($1,$2,$3);
625
+ if ($maj < 5 || ($maj == 5 && $min < 6)) {
626
+ $compat_version =
627
+ $sub ? sprintf("%d.%03d%02d",$maj,$min,$sub) :
628
+ sprintf("%d.%03d", $maj,$min);
629
+ } else {
630
+ $compat_version = sprintf("%d.%03d%03d",$maj,$min,$sub);
631
+ }
632
+ } else {
633
+ my ($maj,$min,$sub) = $compat_version =~ /(\d+)\.(\d\d\d)(\d*)/;
634
+ $sub ||= 0;
635
+ warn sprintf <<'EOF', $maj,$min,$sub;
636
+ Defaulting to backwards compatibility with perl %d.%d.%d
637
+ If you intend this module to be compatible with earlier perl versions, please
638
+ specify a minimum perl version with the -b option.
639
+
640
+ EOF
641
+ }
642
+
643
+ if( $opt_B ){
644
+ $TEMPLATE_VERSION = '0.00_01';
645
+ }
646
+
647
+ if( $opt_v ){
648
+ $TEMPLATE_VERSION = $opt_v;
649
+
650
+ # check if it is numeric
651
+ my $temp_version = $TEMPLATE_VERSION;
652
+ my $beta_version = $temp_version =~ s/(\d)_(\d\d)/$1$2/;
653
+ my $notnum;
654
+ {
655
+ local $SIG{__WARN__} = sub { $notnum = 1 };
656
+ use warnings 'numeric';
657
+ $temp_version = 0+$temp_version;
658
+ }
659
+
660
+ if ($notnum) {
661
+ my $module = $opt_n || 'Your::Module';
662
+ warn <<"EOF";
663
+ You have specified a non-numeric version. Unless you supply an
664
+ appropriate VERSION class method, users may not be able to specify a
665
+ minimum required version with C<use $module versionnum>.
666
+
667
+ EOF
668
+ }
669
+ else {
670
+ $opt_B = $beta_version;
671
+ }
672
+ }
673
+
674
+ # -A implies -c.
675
+ $skip_autoloader = $opt_c = 1 if $opt_A;
676
+
677
+ # -X implies -c and -f
678
+ $opt_c = $opt_f = 1 if $opt_X;
679
+
680
+ $opt_t ||= 'IV';
681
+
682
+ my %const_xsub;
683
+ %const_xsub = map { $_,1 } split(/,+/, $opt_s) if $opt_s;
684
+
685
+ my $extralibs = '';
686
+
687
+ my @path_h;
688
+
689
+ while (my $arg = shift) {
690
+ if ($arg =~ /^-l/i) {
691
+ $extralibs .= "$arg ";
692
+ next;
693
+ }
694
+ last if $extralibs;
695
+ push(@path_h, $arg);
696
+ }
697
+
698
+ usage "Must supply header file or module name\n"
699
+ unless (@path_h or $opt_n);
700
+
701
+ my $fmask;
702
+ my $tmask;
703
+
704
+ $fmask = qr{$opt_M} if defined $opt_M;
705
+ $tmask = qr{$opt_o} if defined $opt_o;
706
+ my $tmask_all = $tmask && $opt_o eq '.';
707
+
708
+ if ($opt_x) {
709
+ eval {require C::Scan; 1}
710
+ or die <<EOD;
711
+ C::Scan required if you use -x option.
712
+ To install C::Scan, execute
713
+ perl -MCPAN -e "install C::Scan"
714
+ EOD
715
+ unless ($tmask_all) {
716
+ $C::Scan::VERSION >= 0.70
717
+ or die <<EOD;
718
+ C::Scan v. 0.70 or later required unless you use -o . option.
719
+ You have version $C::Scan::VERSION installed as $INC{'C/Scan.pm'}.
720
+ To install C::Scan, execute
721
+ perl -MCPAN -e "install C::Scan"
722
+ EOD
723
+ }
724
+ if (($opt_m || $opt_a) && $C::Scan::VERSION < 0.73) {
725
+ die <<EOD;
726
+ C::Scan v. 0.73 or later required to use -m or -a options.
727
+ You have version $C::Scan::VERSION installed as $INC{'C/Scan.pm'}.
728
+ To install C::Scan, execute
729
+ perl -MCPAN -e "install C::Scan"
730
+ EOD
731
+ }
732
+ }
733
+ elsif ($opt_o or $opt_F) {
734
+ warn <<EOD if $opt_o;
735
+ Option -o does not make sense without -x.
736
+ EOD
737
+ warn <<EOD if $opt_F and $opt_X ;
738
+ Option -F does not make sense with -X.
739
+ EOD
740
+ }
741
+
742
+ my @path_h_ini = @path_h;
743
+ my ($name, %fullpath, %prefix, %seen_define, %prefixless, %const_names);
744
+
745
+ my $module = $opt_n;
746
+
747
+ if( @path_h ){
748
+ use File::Spec;
749
+ my @paths;
750
+ my $pre_sub_tri_graphs = 1;
751
+ if ($^O eq 'VMS') { # Consider overrides of default location
752
+ # XXXX This is not equivalent to what the older version did:
753
+ # it was looking at $hadsys header-file per header-file...
754
+ my($hadsys) = grep s!^sys/!!i , @path_h;
755
+ @paths = qw( Sys$Library VAXC$Include );
756
+ push @paths, ($hadsys ? 'GNU_CC_Include[vms]' : 'GNU_CC_Include[000000]');
757
+ push @paths, qw( DECC$Library_Include DECC$System_Include );
758
+ }
759
+ else {
760
+ @paths = (File::Spec->curdir(), $Config{usrinc},
761
+ (split / +/, $Config{locincpth} // ""), '/usr/include');
762
+ }
763
+ foreach my $path_h (@path_h) {
764
+ $name ||= $path_h;
765
+ $module ||= do {
766
+ $name =~ s/\.h$//;
767
+ if ( $name !~ /::/ ) {
768
+ $name =~ s#^.*/##;
769
+ $name = "\u$name";
770
+ }
771
+ $name;
772
+ };
773
+
774
+ if( $path_h =~ s#::#/#g && $opt_n ){
775
+ warn "Nesting of headerfile ignored with -n\n";
776
+ }
777
+ $path_h .= ".h" unless $path_h =~ /\.h$/;
778
+ my $fullpath = $path_h;
779
+ $path_h =~ s/,.*$// if $opt_x;
780
+ $fullpath{$path_h} = $fullpath;
781
+
782
+ # Minor trickery: we can't chdir() before we processed the headers
783
+ # (so know the name of the extension), but the header may be in the
784
+ # extension directory...
785
+ my $tmp_path_h = $path_h;
786
+ my $rel_path_h = $path_h;
787
+ my @dirs = @paths;
788
+ if (not -f $path_h) {
789
+ my $found;
790
+ for my $dir (@paths) {
791
+ $found++, last
792
+ if -f ($path_h = File::Spec->catfile($dir, $tmp_path_h));
793
+ }
794
+ if ($found) {
795
+ $rel_path_h = $path_h;
796
+ $fullpath{$path_h} = $fullpath;
797
+ } else {
798
+ (my $epath = $module) =~ s,::,/,g;
799
+ $epath = File::Spec->catdir('ext', $epath) if -d 'ext';
800
+ $rel_path_h = File::Spec->catfile($epath, $tmp_path_h);
801
+ $path_h = $tmp_path_h; # Used during -x
802
+ push @dirs, $epath;
803
+ }
804
+ }
805
+
806
+ if (!$opt_c) {
807
+ die "Can't find $tmp_path_h in @dirs\n"
808
+ if ( ! $opt_f && ! -f "$rel_path_h" );
809
+ # Scan the header file (we should deal with nested header files)
810
+ # Record the names of simple #define constants into const_names
811
+ # Function prototypes are processed below.
812
+ open(CH, "<", "$rel_path_h") || die "Can't open $rel_path_h: $!\n";
813
+ defines:
814
+ while (<CH>) {
815
+ if ($pre_sub_tri_graphs) {
816
+ # Preprocess all tri-graphs
817
+ # including things stuck in quoted string constants.
818
+ s/\?\?=/#/g; # | ??=| #|
819
+ s/\?\?\!/|/g; # | ??!| ||
820
+ s/\?\?'/^/g; # | ??'| ^|
821
+ s/\?\?\(/[/g; # | ??(| [|
822
+ s/\?\?\)/]/g; # | ??)| ]|
823
+ s/\?\?\-/~/g; # | ??-| ~|
824
+ s/\?\?\//\\/g; # | ??/| \|
825
+ s/\?\?</{/g; # | ??<| {|
826
+ s/\?\?>/}/g; # | ??>| }|
827
+ }
828
+ if (/^[ \t]*#[ \t]*define\s+([\$\w]+)\b(?!\()\s*(?=[^"\s])(.*)/) {
829
+ my $def = $1;
830
+ my $rest = $2;
831
+ $rest =~ s!/\*.*?(\*/|\n)|//.*!!g; # Remove comments
832
+ $rest =~ s/^\s+//;
833
+ $rest =~ s/\s+$//;
834
+ if ($rest eq '') {
835
+ print("Skip empty $def\n") if $opt_d;
836
+ next defines;
837
+ }
838
+ # Cannot do: (-1) and ((LHANDLE)3) are OK:
839
+ #print("Skip non-wordy $def => $rest\n"),
840
+ # next defines if $rest =~ /[^\w\$]/;
841
+ if ($rest =~ /"/) {
842
+ print("Skip stringy $def => $rest\n") if $opt_d;
843
+ next defines;
844
+ }
845
+ print "Matched $_ ($def)\n" if $opt_d;
846
+ $seen_define{$def} = $rest;
847
+ $_ = $def;
848
+ next if /^_.*_h_*$/i; # special case, but for what?
849
+ if (defined $opt_p) {
850
+ if (!/^$opt_p(\d)/) {
851
+ ++$prefix{$_} if s/^$opt_p//;
852
+ }
853
+ else {
854
+ warn "can't remove $opt_p prefix from '$_'!\n";
855
+ }
856
+ }
857
+ $prefixless{$def} = $_;
858
+ if (!$fmask or /$fmask/) {
859
+ print "... Passes mask of -M.\n" if $opt_d and $fmask;
860
+ $const_names{$_}++;
861
+ }
862
+ }
863
+ }
864
+ if (defined $opt_e and !$opt_e) {
865
+ close(CH);
866
+ }
867
+ else {
868
+ # Work from miniperl too - on "normal" systems
869
+ my $SEEK_SET = eval 'use Fcntl qw/SEEK_SET/; SEEK_SET' || 0;
870
+ seek CH, 0, $SEEK_SET;
871
+ my $src = do { local $/; <CH> };
872
+ close CH;
873
+ no warnings 'uninitialized';
874
+
875
+ # Remove C and C++ comments
876
+ $src =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
877
+ $src =~ s#//.*$##gm;
878
+
879
+ while ($src =~ /\benum\s*([\w_]*)\s*\{\s([^}]+)\}/gsc) {
880
+ my ($enum_name, $enum_body) = ($1, $2);
881
+ # skip enums matching $opt_e
882
+ next if $opt_e && $enum_name =~ /$opt_e/;
883
+ my $val = 0;
884
+ for my $item (split /,/, $enum_body) {
885
+ next if $item =~ /\A\s*\Z/;
886
+ my ($key, $declared_val) = $item =~ /(\w+)\s*(?:=\s*(.*))?/;
887
+ $val = defined($declared_val) && length($declared_val) ? $declared_val : 1 + $val;
888
+ $seen_define{$key} = $val;
889
+ $const_names{$key} = { name => $key, macro => 1 };
890
+ }
891
+ } # while (...)
892
+ } # if (!defined $opt_e or $opt_e)
893
+ }
894
+ }
895
+ }
896
+
897
+ # Save current directory so that C::Scan can use it
898
+ my $cwd = File::Spec->rel2abs( File::Spec->curdir );
899
+
900
+ # As Ilya suggested, use a name that contains - and then it can't clash with
901
+ # the names of any packages. A directory 'fallback' will clash with any
902
+ # new pragmata down the fallback:: tree, but that seems unlikely.
903
+ my $constscfname = 'const-c.inc';
904
+ my $constsxsfname = 'const-xs.inc';
905
+ my $fallbackdirname = 'fallback';
906
+
907
+ my $ext = chdir 'ext' ? 'ext/' : '';
908
+
909
+ my @modparts = split(/::/,$module);
910
+ my $modpname = join('-', @modparts);
911
+ my $modfname = pop @modparts;
912
+ my $modpmdir = join '/', 'lib', @modparts;
913
+ my $modpmname = join '/', $modpmdir, $modfname.'.pm';
914
+
915
+ if ($opt_O) {
916
+ warn "Overwriting existing $ext$modpname!!!\n" if -e $modpname;
917
+ }
918
+ else {
919
+ die "Won't overwrite existing $ext$modpname\n" if -e $modpname;
920
+ }
921
+ -d "$modpname" || mkpath([$modpname], 0, 0775);
922
+ chdir($modpname) || die "Can't chdir $ext$modpname: $!\n";
923
+
924
+ my %types_seen;
925
+ my %std_types;
926
+ my $fdecls = [];
927
+ my $fdecls_parsed = [];
928
+ my $typedef_rex;
929
+ my %typedefs_pre;
930
+ my %known_fnames;
931
+ my %structs;
932
+
933
+ my @fnames;
934
+ my @fnames_no_prefix;
935
+ my %vdecl_hash;
936
+ my @vdecls;
937
+
938
+ if( ! $opt_X ){ # use XS, unless it was disabled
939
+ unless ($skip_ppport) {
940
+ require Devel::PPPort;
941
+ warn "Writing $ext$modpname/ppport.h\n";
942
+ Devel::PPPort::WriteFile('ppport.h')
943
+ || die "Can't create $ext$modpname/ppport.h: $!\n";
944
+ }
945
+ open(XS, ">", "$modfname.xs") || die "Can't create $ext$modpname/$modfname.xs: $!\n";
946
+ if ($opt_x) {
947
+ warn "Scanning typemaps...\n";
948
+ get_typemap();
949
+ my @td;
950
+ my @good_td;
951
+ my $addflags = $opt_F || '';
952
+
953
+ foreach my $filename (@path_h) {
954
+ my $c;
955
+ my $filter;
956
+
957
+ if ($fullpath{$filename} =~ /,/) {
958
+ $filename = $`;
959
+ $filter = $';
960
+ }
961
+ warn "Scanning $filename for functions...\n";
962
+ my @styles = $Config{gccversion} ? qw(C++ C9X GNU) : qw(C++ C9X);
963
+ $c = C::Scan->new('filename' => $filename, 'filename_filter' => $filter,
964
+ 'add_cppflags' => $addflags, 'c_styles' => \@styles);
965
+ $c->set('includeDirs' => ["$Config::Config{archlib}/CORE", $cwd]);
966
+
967
+ $c->get('keywords')->{'__restrict'} = 1;
968
+
969
+ push @$fdecls_parsed, @{ $c->get('parsed_fdecls') };
970
+ push(@$fdecls, @{$c->get('fdecls')});
971
+
972
+ push @td, @{$c->get('typedefs_maybe')};
973
+ if ($opt_a) {
974
+ my $structs = $c->get('typedef_structs');
975
+ @structs{keys %$structs} = values %$structs;
976
+ }
977
+
978
+ if ($opt_m) {
979
+ %vdecl_hash = %{ $c->get('vdecl_hash') };
980
+ @vdecls = sort keys %vdecl_hash;
981
+ for (local $_ = 0; $_ < @vdecls; ++$_) {
982
+ my $var = $vdecls[$_];
983
+ my($type, $post) = @{ $vdecl_hash{$var} };
984
+ if (defined $post) {
985
+ warn "Can't handle variable '$type $var $post', skipping.\n";
986
+ splice @vdecls, $_, 1;
987
+ redo;
988
+ }
989
+ $type = normalize_type($type);
990
+ $vdecl_hash{$var} = $type;
991
+ }
992
+ }
993
+
994
+ unless ($tmask_all) {
995
+ warn "Scanning $filename for typedefs...\n";
996
+ my $td = $c->get('typedef_hash');
997
+ # eval {require 'dumpvar.pl'; ::dumpValue($td)} or warn $@ if $opt_d;
998
+ my @f_good_td = grep $td->{$_}[1] eq '', keys %$td;
999
+ push @good_td, @f_good_td;
1000
+ @typedefs_pre{@f_good_td} = map $_->[0], @$td{@f_good_td};
1001
+ }
1002
+ }
1003
+ { local $" = '|';
1004
+ $typedef_rex = qr(\b(?<!struct )(?<!enum )(?:@good_td)\b) if @good_td;
1005
+ }
1006
+ %known_fnames = map @$_[1,3], @$fdecls_parsed; # [1,3] is NAME, FULLTEXT
1007
+ if ($fmask) {
1008
+ my @good;
1009
+ for my $i (0..$#$fdecls_parsed) {
1010
+ next unless $fdecls_parsed->[$i][1] =~ /$fmask/; # [1] is NAME
1011
+ push @good, $i;
1012
+ print "... Function $fdecls_parsed->[$i][1] passes -M mask.\n"
1013
+ if $opt_d;
1014
+ }
1015
+ $fdecls = [@$fdecls[@good]];
1016
+ $fdecls_parsed = [@$fdecls_parsed[@good]];
1017
+ }
1018
+ @fnames = sort map $_->[1], @$fdecls_parsed; # 1 is NAME
1019
+ # Sort declarations:
1020
+ {
1021
+ my %h = map( ($_->[1], $_), @$fdecls_parsed);
1022
+ $fdecls_parsed = [ @h{@fnames} ];
1023
+ }
1024
+ @fnames_no_prefix = @fnames;
1025
+ @fnames_no_prefix
1026
+ = sort map { ++$prefix{$_} if s/^$opt_p(?!\d)//; $_ } @fnames_no_prefix
1027
+ if defined $opt_p;
1028
+ # Remove macros which expand to typedefs
1029
+ print "Typedefs are @td.\n" if $opt_d;
1030
+ my %td = map {($_, $_)} @td;
1031
+ # Add some other possible but meaningless values for macros
1032
+ for my $k (qw(char double float int long short unsigned signed void)) {
1033
+ $td{"$_$k"} = "$_$k" for ('', 'signed ', 'unsigned ');
1034
+ }
1035
+ # eval {require 'dumpvar.pl'; ::dumpValue( [\@td, \%td] ); 1} or warn $@;
1036
+ my $n = 0;
1037
+ my %bad_macs;
1038
+ while (keys %td > $n) {
1039
+ $n = keys %td;
1040
+ my ($k, $v);
1041
+ while (($k, $v) = each %seen_define) {
1042
+ # print("found '$k'=>'$v'\n"),
1043
+ $bad_macs{$k} = $td{$k} = $td{$v} if exists $td{$v};
1044
+ }
1045
+ }
1046
+ # Now %bad_macs contains names of bad macros
1047
+ for my $k (keys %bad_macs) {
1048
+ delete $const_names{$prefixless{$k}};
1049
+ print "Ignoring macro $k which expands to a typedef name '$bad_macs{$k}'\n" if $opt_d;
1050
+ }
1051
+ }
1052
+ }
1053
+ my (@const_specs, @const_names);
1054
+
1055
+ for (sort(keys(%const_names))) {
1056
+ my $v = $const_names{$_};
1057
+
1058
+ push(@const_specs, ref($v) ? $v : $_);
1059
+ push(@const_names, $_);
1060
+ }
1061
+
1062
+ -d $modpmdir || mkpath([$modpmdir], 0, 0775);
1063
+ open(PM, ">", "$modpmname") || die "Can't create $ext$modpname/$modpmname: $!\n";
1064
+
1065
+ $" = "\n\t";
1066
+ warn "Writing $ext$modpname/$modpmname\n";
1067
+
1068
+ print PM <<"END";
1069
+ package $module;
1070
+
1071
+ use $compat_version;
1072
+ END
1073
+
1074
+ print PM <<"END" unless $skip_strict;
1075
+ use strict;
1076
+ END
1077
+
1078
+ print PM "use warnings;\n" unless $skip_warnings or $compat_version < 5.006;
1079
+
1080
+ unless( $opt_X || $opt_c || $opt_A ){
1081
+ # we'll have an AUTOLOAD(), and it will have $AUTOLOAD and
1082
+ # will want Carp.
1083
+ print PM <<'END';
1084
+ use Carp;
1085
+ END
1086
+ }
1087
+
1088
+ print PM <<'END' unless $skip_exporter;
1089
+
1090
+ require Exporter;
1091
+ END
1092
+
1093
+ my $use_Dyna = (not $opt_X and $compat_version < 5.006 and not $use_xsloader);
1094
+ print PM <<"END" if $use_Dyna; # use DynaLoader, unless XS was disabled
1095
+ require DynaLoader;
1096
+ END
1097
+
1098
+
1099
+ # Are we using AutoLoader or not?
1100
+ unless ($skip_autoloader) { # no autoloader whatsoever.
1101
+ unless ($opt_c) { # we're doing the AUTOLOAD
1102
+ print PM "use AutoLoader;\n";
1103
+ }
1104
+ else {
1105
+ print PM "use AutoLoader qw(AUTOLOAD);\n"
1106
+ }
1107
+ }
1108
+
1109
+ if ( $compat_version < 5.006 ) {
1110
+ my $vars = '$VERSION @ISA';
1111
+ $vars .= ' @EXPORT @EXPORT_OK %EXPORT_TAGS' unless $skip_exporter;
1112
+ $vars .= ' $AUTOLOAD' unless $opt_X || $opt_c || $opt_A;
1113
+ $vars .= ' $XS_VERSION' if $opt_B && !$opt_X;
1114
+ print PM "use vars qw($vars);";
1115
+ }
1116
+
1117
+ # Determine @ISA.
1118
+ my @modISA;
1119
+ push @modISA, 'Exporter' unless $skip_exporter;
1120
+ push @modISA, 'DynaLoader' if $use_Dyna; # no XS
1121
+ my $myISA = "our \@ISA = qw(@modISA);";
1122
+ $myISA =~ s/^our // if $compat_version < 5.006;
1123
+
1124
+ print PM "\n$myISA\n\n";
1125
+
1126
+ my @exported_names = (@const_names, @fnames_no_prefix, map '$'.$_, @vdecls);
1127
+
1128
+ my $tmp='';
1129
+ $tmp .= <<"END" unless $skip_exporter;
1130
+ # Items to export into callers namespace by default. Note: do not export
1131
+ # names by default without a very good reason. Use EXPORT_OK instead.
1132
+ # Do not simply export all your public functions/methods/constants.
1133
+
1134
+ # This allows declaration use $module ':all';
1135
+ # If you do not need this, moving things directly into \@EXPORT or \@EXPORT_OK
1136
+ # will save memory.
1137
+ our %EXPORT_TAGS = ( 'all' => [ qw(
1138
+ @exported_names
1139
+ ) ] );
1140
+
1141
+ our \@EXPORT_OK = ( \@{ \$EXPORT_TAGS{'all'} } );
1142
+
1143
+ our \@EXPORT = qw(
1144
+ @const_names
1145
+ );
1146
+
1147
+ END
1148
+
1149
+ $tmp .= "our \$VERSION = '$TEMPLATE_VERSION';\n";
1150
+ if ($opt_B) {
1151
+ $tmp .= "our \$XS_VERSION = \$VERSION;\n" unless $opt_X;
1152
+ $tmp .= "\$VERSION = eval \$VERSION; # see L<perlmodstyle>\n";
1153
+ }
1154
+ $tmp .= "\n";
1155
+
1156
+ $tmp =~ s/^our //mg if $compat_version < 5.006;
1157
+ print PM $tmp;
1158
+
1159
+ if (@vdecls) {
1160
+ printf PM "our(@{[ join ', ', map '$'.$_, @vdecls ]});\n\n";
1161
+ }
1162
+
1163
+
1164
+ print PM autoload ($module, $compat_version) unless $opt_c or $opt_X;
1165
+
1166
+ if( ! $opt_X ){ # print bootstrap, unless XS is disabled
1167
+ if ($use_Dyna) {
1168
+ $tmp = <<"END";
1169
+ bootstrap $module \$VERSION;
1170
+ END
1171
+ } else {
1172
+ $tmp = <<"END";
1173
+ require XSLoader;
1174
+ XSLoader::load('$module', \$VERSION);
1175
+ END
1176
+ }
1177
+ $tmp =~ s:\$VERSION:\$XS_VERSION:g if $opt_B;
1178
+ print PM $tmp;
1179
+ }
1180
+
1181
+ # tying the variables can happen only after bootstrap
1182
+ if (@vdecls) {
1183
+ printf PM <<END;
1184
+ {
1185
+ @{[ join "\n", map " _tievar_$_(\$$_);", @vdecls ]}
1186
+ }
1187
+
1188
+ END
1189
+ }
1190
+
1191
+ my $after;
1192
+ if( $opt_P ){ # if POD is disabled
1193
+ $after = '__END__';
1194
+ }
1195
+ else {
1196
+ $after = '=cut';
1197
+ }
1198
+
1199
+ print PM <<"END";
1200
+
1201
+ # Preloaded methods go here.
1202
+ END
1203
+
1204
+ print PM <<"END" unless $opt_A;
1205
+
1206
+ # Autoload methods go after $after, and are processed by the autosplit program.
1207
+ END
1208
+
1209
+ print PM <<"END";
1210
+
1211
+ 1;
1212
+ __END__
1213
+ END
1214
+
1215
+ my ($email,$author,$licence);
1216
+
1217
+ eval {
1218
+ my $username;
1219
+ ($username,$author) = (getpwuid($>))[0,6];
1220
+ if (defined $username && defined $author) {
1221
+ $author =~ s/,.*$//; # in case of sub fields
1222
+ my $domain = $Config{'mydomain'};
1223
+ $domain =~ s/^\.//;
1224
+ $email = "$username\@$domain";
1225
+ }
1226
+ };
1227
+
1228
+ $author =~ s/'/\\'/g if defined $author;
1229
+ $author ||= "A. U. Thor";
1230
+ $email ||= 'a.u.thor@a.galaxy.far.far.away';
1231
+
1232
+ $licence = sprintf << "DEFAULT", $^V;
1233
+ Copyright (C) ${\(1900 + (localtime) [5])} by $author
1234
+
1235
+ This library is free software; you can redistribute it and/or modify
1236
+ it under the same terms as Perl itself, either Perl version %vd or,
1237
+ at your option, any later version of Perl 5 you may have available.
1238
+ DEFAULT
1239
+
1240
+ my $revhist = '';
1241
+ $revhist = <<EOT if $opt_C;
1242
+ #
1243
+ #=head1 HISTORY
1244
+ #
1245
+ #=over 8
1246
+ #
1247
+ #=item $TEMPLATE_VERSION
1248
+ #
1249
+ #Original version; created by h2xs $H2XS_VERSION with options
1250
+ #
1251
+ # @ARGS
1252
+ #
1253
+ #=back
1254
+ #
1255
+ EOT
1256
+
1257
+ my $exp_doc = $skip_exporter ? '' : <<EOD;
1258
+ #
1259
+ #=head2 EXPORT
1260
+ #
1261
+ #None by default.
1262
+ #
1263
+ EOD
1264
+
1265
+ if (@const_names and not $opt_P) {
1266
+ $exp_doc .= <<EOD unless $skip_exporter;
1267
+ #=head2 Exportable constants
1268
+ #
1269
+ # @{[join "\n ", @const_names]}
1270
+ #
1271
+ EOD
1272
+ }
1273
+
1274
+ if (defined $fdecls and @$fdecls and not $opt_P) {
1275
+ $exp_doc .= <<EOD unless $skip_exporter;
1276
+ #=head2 Exportable functions
1277
+ #
1278
+ EOD
1279
+
1280
+ # $exp_doc .= <<EOD if $opt_p;
1281
+ #When accessing these functions from Perl, prefix C<$opt_p> should be removed.
1282
+ #
1283
+ #EOD
1284
+ $exp_doc .= <<EOD unless $skip_exporter;
1285
+ # @{[join "\n ", @known_fnames{@fnames}]}
1286
+ #
1287
+ EOD
1288
+ }
1289
+
1290
+ my $meth_doc = '';
1291
+
1292
+ if ($opt_x && $opt_a) {
1293
+ my($name, $struct);
1294
+ $meth_doc .= accessor_docs($name, $struct)
1295
+ while ($name, $struct) = each %structs;
1296
+ }
1297
+
1298
+ # Prefix the default licence with hash symbols.
1299
+ # Is this just cargo cult - it seems that the first thing that happens to this
1300
+ # block is that all the hashes are then s///g out.
1301
+ my $licence_hash = $licence;
1302
+ $licence_hash =~ s/^/#/gm;
1303
+
1304
+ my $pod;
1305
+ $pod = <<"END" unless $opt_P;
1306
+ ## Below is stub documentation for your module. You'd better edit it!
1307
+ #
1308
+ #=head1 NAME
1309
+ #
1310
+ #$module - Perl extension for blah blah blah
1311
+ #
1312
+ #=head1 SYNOPSIS
1313
+ #
1314
+ # use $module;
1315
+ # blah blah blah
1316
+ #
1317
+ #=head1 DESCRIPTION
1318
+ #
1319
+ #Stub documentation for $module, created by h2xs. It looks like the
1320
+ #author of the extension was negligent enough to leave the stub
1321
+ #unedited.
1322
+ #
1323
+ #Blah blah blah.
1324
+ $exp_doc$meth_doc$revhist
1325
+ #
1326
+ #=head1 SEE ALSO
1327
+ #
1328
+ #Mention other useful documentation such as the documentation of
1329
+ #related modules or operating system documentation (such as man pages
1330
+ #in UNIX), or any relevant external documentation such as RFCs or
1331
+ #standards.
1332
+ #
1333
+ #If you have a mailing list set up for your module, mention it here.
1334
+ #
1335
+ #If you have a web site set up for your module, mention it here.
1336
+ #
1337
+ #=head1 AUTHOR
1338
+ #
1339
+ #$author, E<lt>${email}E<gt>
1340
+ #
1341
+ #=head1 COPYRIGHT AND LICENSE
1342
+ #
1343
+ $licence_hash
1344
+ #
1345
+ #=cut
1346
+ END
1347
+
1348
+ $pod =~ s/^\#//gm unless $opt_P;
1349
+ print PM $pod unless $opt_P;
1350
+
1351
+ close PM;
1352
+
1353
+
1354
+ if( ! $opt_X ){ # print XS, unless it is disabled
1355
+ warn "Writing $ext$modpname/$modfname.xs\n";
1356
+
1357
+ print XS <<"END";
1358
+ #define PERL_NO_GET_CONTEXT
1359
+ #include "EXTERN.h"
1360
+ #include "perl.h"
1361
+ #include "XSUB.h"
1362
+
1363
+ END
1364
+
1365
+ print XS <<"END" unless $skip_ppport;
1366
+ #include "ppport.h"
1367
+
1368
+ END
1369
+
1370
+ if( @path_h ){
1371
+ foreach my $path_h (@path_h_ini) {
1372
+ my($h) = $path_h;
1373
+ $h =~ s#^/usr/include/##;
1374
+ if ($^O eq 'VMS') { $h =~ s#.*vms\]#sys/# or $h =~ s#.*[:>\]]##; }
1375
+ print XS qq{#include <$h>\n};
1376
+ }
1377
+ print XS "\n";
1378
+ }
1379
+
1380
+ print XS <<"END" if $opt_g;
1381
+
1382
+ /* Global Data */
1383
+
1384
+ #define MY_CXT_KEY "${module}::_guts" XS_VERSION
1385
+
1386
+ typedef struct {
1387
+ /* Put Global Data in here */
1388
+ int dummy; /* you can access this elsewhere as MY_CXT.dummy */
1389
+ } my_cxt_t;
1390
+
1391
+ START_MY_CXT
1392
+
1393
+ END
1394
+
1395
+ my %pointer_typedefs;
1396
+ my %struct_typedefs;
1397
+
1398
+ sub td_is_pointer {
1399
+ my $type = shift;
1400
+ my $out = $pointer_typedefs{$type};
1401
+ return $out if defined $out;
1402
+ my $otype = $type;
1403
+ $out = ($type =~ /\*$/);
1404
+ # This converts only the guys which do not have trailing part in the typedef
1405
+ if (not $out
1406
+ and $typedef_rex and $type =~ s/($typedef_rex)/$typedefs_pre{$1}/go) {
1407
+ $type = normalize_type($type);
1408
+ print "Is-Pointer: Type mutation via typedefs: $otype ==> $type\n"
1409
+ if $opt_d;
1410
+ $out = td_is_pointer($type);
1411
+ }
1412
+ return ($pointer_typedefs{$otype} = $out);
1413
+ }
1414
+
1415
+ sub td_is_struct {
1416
+ my $type = shift;
1417
+ my $out = $struct_typedefs{$type};
1418
+ return $out if defined $out;
1419
+ my $otype = $type;
1420
+ $out = ($type =~ /^(struct|union)\b/) && !td_is_pointer($type);
1421
+ # This converts only the guys which do not have trailing part in the typedef
1422
+ if (not $out
1423
+ and $typedef_rex and $type =~ s/($typedef_rex)/$typedefs_pre{$1}/go) {
1424
+ $type = normalize_type($type);
1425
+ print "Is-Struct: Type mutation via typedefs: $otype ==> $type\n"
1426
+ if $opt_d;
1427
+ $out = td_is_struct($type);
1428
+ }
1429
+ return ($struct_typedefs{$otype} = $out);
1430
+ }
1431
+
1432
+ print_tievar_subs(\*XS, $_, $vdecl_hash{$_}) for @vdecls;
1433
+
1434
+ if( ! $opt_c ) {
1435
+ # We write the "sample" files used when this module is built by perl without
1436
+ # ExtUtils::Constant.
1437
+ # h2xs will later check that these are the same as those generated by the
1438
+ # code embedded into Makefile.PL
1439
+ unless (-d $fallbackdirname) {
1440
+ mkdir "$fallbackdirname" or die "Cannot mkdir $fallbackdirname: $!\n";
1441
+ }
1442
+ warn "Writing $ext$modpname/$fallbackdirname/$constscfname\n";
1443
+ warn "Writing $ext$modpname/$fallbackdirname/$constsxsfname\n";
1444
+ my $cfallback = File::Spec->catfile($fallbackdirname, $constscfname);
1445
+ my $xsfallback = File::Spec->catfile($fallbackdirname, $constsxsfname);
1446
+ WriteConstants ( C_FILE => $cfallback,
1447
+ XS_FILE => $xsfallback,
1448
+ DEFAULT_TYPE => $opt_t,
1449
+ NAME => $module,
1450
+ NAMES => \@const_specs,
1451
+ );
1452
+ print XS "#include \"$constscfname\"\n";
1453
+ }
1454
+
1455
+
1456
+ my $prefix = defined $opt_p ? "PREFIX = $opt_p" : '';
1457
+
1458
+ # Now switch from C to XS by issuing the first MODULE declaration:
1459
+ print XS <<"END";
1460
+
1461
+ MODULE = $module PACKAGE = $module $prefix
1462
+
1463
+ END
1464
+
1465
+ # If a constant() function was #included then output a corresponding
1466
+ # XS declaration:
1467
+ print XS "INCLUDE: $constsxsfname\n" unless $opt_c;
1468
+
1469
+ print XS <<"END" if $opt_g;
1470
+
1471
+ BOOT:
1472
+ {
1473
+ MY_CXT_INIT;
1474
+ /* If any of the fields in the my_cxt_t struct need
1475
+ to be initialised, do it here.
1476
+ */
1477
+ }
1478
+
1479
+ END
1480
+
1481
+ foreach (sort keys %const_xsub) {
1482
+ print XS <<"END";
1483
+ char *
1484
+ $_()
1485
+
1486
+ CODE:
1487
+ #ifdef $_
1488
+ RETVAL = $_;
1489
+ #else
1490
+ croak("Your vendor has not defined the $module macro $_");
1491
+ #endif
1492
+
1493
+ OUTPUT:
1494
+ RETVAL
1495
+
1496
+ END
1497
+ }
1498
+
1499
+ my %seen_decl;
1500
+ my %typemap;
1501
+
1502
+ sub print_decl {
1503
+ my $fh = shift;
1504
+ my $decl = shift;
1505
+ my ($type, $name, $args) = @$decl;
1506
+ return if $seen_decl{$name}++; # Need to do the same for docs as well?
1507
+
1508
+ my @argnames = map {$_->[1]} @$args;
1509
+ my @argtypes = map { normalize_type( $_->[0], 1 ) } @$args;
1510
+ if ($opt_k) {
1511
+ s/^\s*const\b\s*// for @argtypes;
1512
+ }
1513
+ my @argarrays = map { $_->[4] || '' } @$args;
1514
+ my $numargs = @$args;
1515
+ if ($numargs and $argtypes[-1] eq '...') {
1516
+ $numargs--;
1517
+ $argnames[-1] = '...';
1518
+ }
1519
+ local $" = ', ';
1520
+ $type = normalize_type($type, 1);
1521
+
1522
+ print $fh <<"EOP";
1523
+
1524
+ $type
1525
+ $name(@argnames)
1526
+ EOP
1527
+
1528
+ for my $arg (0 .. $numargs - 1) {
1529
+ print $fh <<"EOP";
1530
+ $argtypes[$arg] $argnames[$arg]$argarrays[$arg]
1531
+ EOP
1532
+ }
1533
+ }
1534
+
1535
+ sub print_tievar_subs {
1536
+ my($fh, $name, $type) = @_;
1537
+ print $fh <<END;
1538
+ I32
1539
+ _get_$name(IV index, SV *sv) {
1540
+ dSP;
1541
+ PUSHMARK(SP);
1542
+ XPUSHs(sv);
1543
+ PUTBACK;
1544
+ (void)call_pv("$module\::_get_$name", G_DISCARD);
1545
+ return (I32)0;
1546
+ }
1547
+
1548
+ I32
1549
+ _set_$name(IV index, SV *sv) {
1550
+ dSP;
1551
+ PUSHMARK(SP);
1552
+ XPUSHs(sv);
1553
+ PUTBACK;
1554
+ (void)call_pv("$module\::_set_$name", G_DISCARD);
1555
+ return (I32)0;
1556
+ }
1557
+
1558
+ END
1559
+ }
1560
+
1561
+ sub print_tievar_xsubs {
1562
+ my($fh, $name, $type) = @_;
1563
+ print $fh <<END;
1564
+ void
1565
+ _tievar_$name(sv)
1566
+ SV* sv
1567
+ PREINIT:
1568
+ struct ufuncs uf;
1569
+ CODE:
1570
+ uf.uf_val = &_get_$name;
1571
+ uf.uf_set = &_set_$name;
1572
+ uf.uf_index = (IV)&_get_$name;
1573
+ sv_magic(sv, 0, 'U', (char*)&uf, sizeof(uf));
1574
+
1575
+ void
1576
+ _get_$name(THIS)
1577
+ $type THIS = NO_INIT
1578
+ CODE:
1579
+ THIS = $name;
1580
+ OUTPUT:
1581
+ SETMAGIC: DISABLE
1582
+ THIS
1583
+
1584
+ void
1585
+ _set_$name(THIS)
1586
+ $type THIS
1587
+ CODE:
1588
+ $name = THIS;
1589
+
1590
+ END
1591
+ }
1592
+
1593
+ sub print_accessors {
1594
+ my($fh, $name, $struct) = @_;
1595
+ return unless defined $struct && $name !~ /\s|_ANON/;
1596
+ $name = normalize_type($name);
1597
+ my $ptrname = normalize_type("$name *");
1598
+ print $fh <<"EOF";
1599
+
1600
+ MODULE = $module PACKAGE = ${name} $prefix
1601
+
1602
+ $name *
1603
+ _to_ptr(THIS)
1604
+ $name THIS = NO_INIT
1605
+ PROTOTYPE: \$
1606
+ CODE:
1607
+ if (sv_derived_from(ST(0), "$name")) {
1608
+ STRLEN len;
1609
+ char *s = SvPV((SV*)SvRV(ST(0)), len);
1610
+ if (len != sizeof(THIS))
1611
+ croak("Size \%d of packed data != expected \%d",
1612
+ len, sizeof(THIS));
1613
+ RETVAL = ($name *)s;
1614
+ }
1615
+ else
1616
+ croak("THIS is not of type $name");
1617
+ OUTPUT:
1618
+ RETVAL
1619
+
1620
+ $name
1621
+ new(CLASS)
1622
+ char *CLASS = NO_INIT
1623
+ PROTOTYPE: \$
1624
+ CODE:
1625
+ Zero((void*)&RETVAL, sizeof(RETVAL), char);
1626
+ OUTPUT:
1627
+ RETVAL
1628
+
1629
+ MODULE = $module PACKAGE = ${name}Ptr $prefix
1630
+
1631
+ EOF
1632
+ my @items = @$struct;
1633
+ while (@items) {
1634
+ my $item = shift @items;
1635
+ if ($item->[0] =~ /_ANON/) {
1636
+ if (defined $item->[2]) {
1637
+ push @items, map [
1638
+ @$_[0, 1], "$item->[2]_$_->[2]", "$item->[2].$_->[2]",
1639
+ ], @{ $structs{$item->[0]} };
1640
+ } else {
1641
+ push @items, @{ $structs{$item->[0]} };
1642
+ }
1643
+ } else {
1644
+ my $type = normalize_type($item->[0]);
1645
+ my $ttype = $structs{$type} ? normalize_type("$type *") : $type;
1646
+ print $fh <<"EOF";
1647
+ $ttype
1648
+ $item->[2](THIS, __value = NO_INIT)
1649
+ $ptrname THIS
1650
+ $type __value
1651
+ PROTOTYPE: \$;\$
1652
+ CODE:
1653
+ if (items > 1)
1654
+ THIS->$item->[-1] = __value;
1655
+ RETVAL = @{[
1656
+ $type eq $ttype ? "THIS->$item->[-1]" : "&(THIS->$item->[-1])"
1657
+ ]};
1658
+ OUTPUT:
1659
+ RETVAL
1660
+
1661
+ EOF
1662
+ }
1663
+ }
1664
+ }
1665
+
1666
+ sub accessor_docs {
1667
+ my($name, $struct) = @_;
1668
+ return unless defined $struct && $name !~ /\s|_ANON/;
1669
+ $name = normalize_type($name);
1670
+ my $ptrname = $name . 'Ptr';
1671
+ my @items = @$struct;
1672
+ my @list;
1673
+ while (@items) {
1674
+ my $item = shift @items;
1675
+ if ($item->[0] =~ /_ANON/) {
1676
+ if (defined $item->[2]) {
1677
+ push @items, map [
1678
+ @$_[0, 1], "$item->[2]_$_->[2]", "$item->[2].$_->[2]",
1679
+ ], @{ $structs{$item->[0]} };
1680
+ } else {
1681
+ push @items, @{ $structs{$item->[0]} };
1682
+ }
1683
+ } else {
1684
+ push @list, $item->[2];
1685
+ }
1686
+ }
1687
+ my $methods = (join '(...)>, C<', @list) . '(...)';
1688
+
1689
+ my $pod = <<"EOF";
1690
+ #
1691
+ #=head2 Object and class methods for C<$name>/C<$ptrname>
1692
+ #
1693
+ #The principal Perl representation of a C object of type C<$name> is an
1694
+ #object of class C<$ptrname> which is a reference to an integer
1695
+ #representation of a C pointer. To create such an object, one may use
1696
+ #a combination
1697
+ #
1698
+ # my \$buffer = $name->new();
1699
+ # my \$obj = \$buffer->_to_ptr();
1700
+ #
1701
+ #This exercises the following two methods, and an additional class
1702
+ #C<$name>, the internal representation of which is a reference to a
1703
+ #packed string with the C structure. Keep in mind that \$buffer should
1704
+ #better survive longer than \$obj.
1705
+ #
1706
+ #=over
1707
+ #
1708
+ #=item C<\$object_of_type_$name-E<gt>_to_ptr()>
1709
+ #
1710
+ #Converts an object of type C<$name> to an object of type C<$ptrname>.
1711
+ #
1712
+ #=item C<$name-E<gt>new()>
1713
+ #
1714
+ #Creates an empty object of type C<$name>. The corresponding packed
1715
+ #string is zeroed out.
1716
+ #
1717
+ #=item C<$methods>
1718
+ #
1719
+ #return the current value of the corresponding element if called
1720
+ #without additional arguments. Set the element to the supplied value
1721
+ #(and return the new value) if called with an additional argument.
1722
+ #
1723
+ #Applicable to objects of type C<$ptrname>.
1724
+ #
1725
+ #=back
1726
+ #
1727
+ EOF
1728
+ $pod =~ s/^\#//gm;
1729
+ return $pod;
1730
+ }
1731
+
1732
+ # Should be called before any actual call to normalize_type().
1733
+ sub get_typemap {
1734
+ # We do not want to read ./typemap by obvios reasons.
1735
+ my @tm = qw(../../../typemap ../../typemap ../typemap);
1736
+ my $stdtypemap = "$Config::Config{privlib}/ExtUtils/typemap";
1737
+ unshift @tm, $stdtypemap;
1738
+ my $proto_re = "[" . quotemeta('\$%&*@;') . "]" ;
1739
+
1740
+ # Start with useful default values
1741
+ $typemap{float} = 'T_NV';
1742
+
1743
+ foreach my $typemap (@tm) {
1744
+ next unless -e $typemap ;
1745
+ # skip directories, binary files etc.
1746
+ warn " Scanning $typemap\n";
1747
+ warn("Warning: ignoring non-text typemap file '$typemap'\n"), next
1748
+ unless -T $typemap ;
1749
+ open(TYPEMAP, "<", $typemap)
1750
+ or warn ("Warning: could not open typemap file '$typemap': $!\n"), next;
1751
+ my $mode = 'Typemap';
1752
+ while (<TYPEMAP>) {
1753
+ next if /^\s*\#/;
1754
+ if (/^INPUT\s*$/) { $mode = 'Input'; next; }
1755
+ elsif (/^OUTPUT\s*$/) { $mode = 'Output'; next; }
1756
+ elsif (/^TYPEMAP\s*$/) { $mode = 'Typemap'; next; }
1757
+ elsif ($mode eq 'Typemap') {
1758
+ next if /^\s*($|\#)/ ;
1759
+ my ($type, $image);
1760
+ if ( ($type, $image) =
1761
+ /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/o
1762
+ # This may reference undefined functions:
1763
+ and not ($image eq 'T_PACKED' and $typemap eq $stdtypemap)) {
1764
+ $typemap{normalize_type($type)} = $image;
1765
+ }
1766
+ }
1767
+ }
1768
+ close(TYPEMAP) or die "Cannot close $typemap: $!";
1769
+ }
1770
+ %std_types = %types_seen;
1771
+ %types_seen = ();
1772
+ }
1773
+
1774
+
1775
+ sub normalize_type { # Second arg: do not strip const's before \*
1776
+ my $type = shift;
1777
+ my $do_keep_deep_const = shift;
1778
+ # If $do_keep_deep_const this is heuristic only
1779
+ my $keep_deep_const = ($do_keep_deep_const ? '\b(?![^(,)]*\*)' : '');
1780
+ my $ignore_mods
1781
+ = "(?:\\b(?:(?:__const__|const)$keep_deep_const|static|inline|__inline__)\\b\\s*)*";
1782
+ if ($do_keep_deep_const) { # Keep different compiled /RExen/o separately!
1783
+ $type =~ s/$ignore_mods//go;
1784
+ }
1785
+ else {
1786
+ $type =~ s/$ignore_mods//go;
1787
+ }
1788
+ $type =~ s/([^\s\w])/ $1 /g;
1789
+ $type =~ s/\s+$//;
1790
+ $type =~ s/^\s+//;
1791
+ $type =~ s/\s+/ /g;
1792
+ $type =~ s/\* (?=\*)/*/g;
1793
+ $type =~ s/\. \. \./.../g;
1794
+ $type =~ s/ ,/,/g;
1795
+ $types_seen{$type}++
1796
+ unless $type eq '...' or $type eq 'void' or $std_types{$type};
1797
+ $type;
1798
+ }
1799
+
1800
+ my $need_opaque;
1801
+
1802
+ sub assign_typemap_entry {
1803
+ my $type = shift;
1804
+ my $otype = $type;
1805
+ my $entry;
1806
+ if ($tmask and $type =~ /$tmask/) {
1807
+ print "Type $type matches -o mask\n" if $opt_d;
1808
+ $entry = (td_is_struct($type) ? "T_OPAQUE_STRUCT" : "T_PTROBJ");
1809
+ }
1810
+ elsif ($typedef_rex and $type =~ s/($typedef_rex)/$typedefs_pre{$1}/go) {
1811
+ $type = normalize_type $type;
1812
+ print "Type mutation via typedefs: $otype ==> $type\n" if $opt_d;
1813
+ $entry = assign_typemap_entry($type);
1814
+ }
1815
+ # XXX good do better if our UV happens to be long long
1816
+ return "T_NV" if $type =~ /^(unsigned\s+)?long\s+(long|double)\z/;
1817
+ $entry ||= $typemap{$otype}
1818
+ || (td_is_struct($type) ? "T_OPAQUE_STRUCT" : "T_PTROBJ");
1819
+ $typemap{$otype} = $entry;
1820
+ $need_opaque = 1 if $entry eq "T_OPAQUE_STRUCT";
1821
+ return $entry;
1822
+ }
1823
+
1824
+ for (@vdecls) {
1825
+ print_tievar_xsubs(\*XS, $_, $vdecl_hash{$_});
1826
+ }
1827
+
1828
+ if ($opt_x) {
1829
+ for my $decl (@$fdecls_parsed) { print_decl(\*XS, $decl) }
1830
+ if ($opt_a) {
1831
+ while (my($name, $struct) = each %structs) {
1832
+ print_accessors(\*XS, $name, $struct);
1833
+ }
1834
+ }
1835
+ }
1836
+
1837
+ close XS;
1838
+
1839
+ if (%types_seen) {
1840
+ my $type;
1841
+ warn "Writing $ext$modpname/typemap\n";
1842
+ open TM, ">", "typemap" or die "Cannot open typemap file for write: $!";
1843
+
1844
+ for $type (sort keys %types_seen) {
1845
+ my $entry = assign_typemap_entry $type;
1846
+ print TM $type, "\t" x (5 - int((length $type)/8)), "\t$entry\n"
1847
+ }
1848
+
1849
+ print TM <<'EOP' if $need_opaque; # Older Perls do not have correct entry
1850
+ #############################################################################
1851
+ INPUT
1852
+ T_OPAQUE_STRUCT
1853
+ if (sv_derived_from($arg, \"${ntype}\")) {
1854
+ STRLEN len;
1855
+ char *s = SvPV((SV*)SvRV($arg), len);
1856
+
1857
+ if (len != sizeof($var))
1858
+ croak(\"Size %d of packed data != expected %d\",
1859
+ len, sizeof($var));
1860
+ $var = *($type *)s;
1861
+ }
1862
+ else
1863
+ croak(\"$var is not of type ${ntype}\")
1864
+ #############################################################################
1865
+ OUTPUT
1866
+ T_OPAQUE_STRUCT
1867
+ sv_setref_pvn($arg, \"${ntype}\", (char *)&$var, sizeof($var));
1868
+ EOP
1869
+
1870
+ close TM or die "Cannot close typemap file for write: $!";
1871
+ }
1872
+
1873
+ } # if( ! $opt_X )
1874
+
1875
+ warn "Writing $ext$modpname/Makefile.PL\n";
1876
+ open(PL, ">", "Makefile.PL") || die "Can't create $ext$modpname/Makefile.PL: $!\n";
1877
+
1878
+ my $prereq_pm = '';
1879
+
1880
+ if ( $compat_version < 5.006002 and $new_test )
1881
+ {
1882
+ $prereq_pm .= q%'Test::More' => 0, %;
1883
+ }
1884
+ elsif ( $compat_version < 5.006002 )
1885
+ {
1886
+ $prereq_pm .= q%'Test' => 0, %;
1887
+ }
1888
+
1889
+ if (!$opt_X and $use_xsloader)
1890
+ {
1891
+ $prereq_pm .= q%'XSLoader' => 0, %;
1892
+ }
1893
+
1894
+ print PL <<"END";
1895
+ use $compat_version;
1896
+ use ExtUtils::MakeMaker;
1897
+ # See lib/ExtUtils/MakeMaker.pm for details of how to influence
1898
+ # the contents of the Makefile that is written.
1899
+ WriteMakefile(
1900
+ NAME => '$module',
1901
+ VERSION_FROM => '$modpmname', # finds \$VERSION, requires EU::MM from perl >= 5.5
1902
+ PREREQ_PM => {$prereq_pm}, # e.g., Module::Name => 1.1
1903
+ ABSTRACT_FROM => '$modpmname', # retrieve abstract from module
1904
+ AUTHOR => '$author <$email>',
1905
+ #LICENSE => 'perl',
1906
+ #Value must be from legacy list of licenses here
1907
+ #https://metacpan.org/pod/Module::Build::API
1908
+ END
1909
+ if (!$opt_X) { # print C stuff, unless XS is disabled
1910
+ $opt_F = '' unless defined $opt_F;
1911
+ my $I = (((glob '*.h') || (glob '*.hh')) ? '-I.' : '');
1912
+ my $Ihelp = ($I ? '-I. ' : '');
1913
+ my $Icomment = ($I ? '' : <<EOC);
1914
+ # Insert -I. if you add *.h files later:
1915
+ EOC
1916
+
1917
+ print PL <<END;
1918
+ LIBS => ['$extralibs'], # e.g., '-lm'
1919
+ DEFINE => '$opt_F', # e.g., '-DHAVE_SOMETHING'
1920
+ $Icomment INC => '$I', # e.g., '${Ihelp}-I/usr/include/other'
1921
+ END
1922
+
1923
+ my $C = grep {$_ ne "$modfname.c"}
1924
+ (glob '*.c'), (glob '*.cc'), (glob '*.C');
1925
+ my $Cpre = ($C ? '' : '# ');
1926
+ my $Ccomment = ($C ? '' : <<EOC);
1927
+ # Un-comment this if you add C files to link with later:
1928
+ EOC
1929
+
1930
+ print PL <<END;
1931
+ $Ccomment ${Cpre}OBJECT => '\$(O_FILES)', # link all the C files too
1932
+ END
1933
+ } # ' # Grr
1934
+ print PL ");\n";
1935
+ if (!$opt_c) {
1936
+ my $generate_code =
1937
+ WriteMakefileSnippet ( C_FILE => $constscfname,
1938
+ XS_FILE => $constsxsfname,
1939
+ DEFAULT_TYPE => $opt_t,
1940
+ NAME => $module,
1941
+ NAMES => \@const_specs,
1942
+ );
1943
+ print PL <<"END";
1944
+ if (eval {require ExtUtils::Constant; 1}) {
1945
+ # If you edit these definitions to change the constants used by this module,
1946
+ # you will need to use the generated $constscfname and $constsxsfname
1947
+ # files to replace their "fallback" counterparts before distributing your
1948
+ # changes.
1949
+ $generate_code
1950
+ }
1951
+ else {
1952
+ use File::Copy;
1953
+ use File::Spec;
1954
+ foreach my \$file ('$constscfname', '$constsxsfname') {
1955
+ my \$fallback = File::Spec->catfile('$fallbackdirname', \$file);
1956
+ copy (\$fallback, \$file) or die "Can't copy \$fallback to \$file: \$!";
1957
+ }
1958
+ }
1959
+ END
1960
+
1961
+ eval $generate_code;
1962
+ if ($@) {
1963
+ warn <<"EOM";
1964
+ Attempting to test constant code in $ext$modpname/Makefile.PL:
1965
+ $generate_code
1966
+ __END__
1967
+ gave unexpected error $@
1968
+ Please report the circumstances of this bug in h2xs version $H2XS_VERSION
1969
+ using the issue tracker at https://github.com/Perl/perl5/issues.
1970
+ EOM
1971
+ } else {
1972
+ my $fail;
1973
+
1974
+ foreach my $file ($constscfname, $constsxsfname) {
1975
+ my $fallback = File::Spec->catfile($fallbackdirname, $file);
1976
+ if (compare($file, $fallback)) {
1977
+ warn << "EOM";
1978
+ Files "$ext$modpname/$fallbackdirname/$file" and "$ext$modpname/$file" differ.
1979
+ EOM
1980
+ $fail++;
1981
+ }
1982
+ }
1983
+ if ($fail) {
1984
+ warn fill ('','', <<"EOM") . "\n";
1985
+ It appears that the code in $ext$modpname/Makefile.PL does not autogenerate
1986
+ the files $ext$modpname/$constscfname and $ext$modpname/$constsxsfname
1987
+ correctly.
1988
+
1989
+ Please report the circumstances of this bug in h2xs version $H2XS_VERSION
1990
+ using the issue tracker at https://github.com/Perl/perl5/issues.
1991
+ EOM
1992
+ } else {
1993
+ unlink $constscfname, $constsxsfname;
1994
+ }
1995
+ }
1996
+ }
1997
+ close(PL) || die "Can't close $ext$modpname/Makefile.PL: $!\n";
1998
+
1999
+ # Create a simple README since this is a CPAN requirement
2000
+ # and it doesn't hurt to have one
2001
+ warn "Writing $ext$modpname/README\n";
2002
+ open(RM, ">", "README") || die "Can't create $ext$modpname/README:$!\n";
2003
+ my $thisyear = (gmtime)[5] + 1900;
2004
+ my $rmhead = "$modpname version $TEMPLATE_VERSION";
2005
+ my $rmheadeq = "=" x length($rmhead);
2006
+
2007
+ my $rm_prereq;
2008
+
2009
+ if ( $compat_version < 5.006002 and $new_test )
2010
+ {
2011
+ $rm_prereq = 'Test::More';
2012
+ }
2013
+ elsif ( $compat_version < 5.006002 )
2014
+ {
2015
+ $rm_prereq = 'Test';
2016
+ }
2017
+ else
2018
+ {
2019
+ $rm_prereq = 'blah blah blah';
2020
+ }
2021
+
2022
+ print RM <<_RMEND_;
2023
+ $rmhead
2024
+ $rmheadeq
2025
+
2026
+ The README is used to introduce the module and provide instructions on
2027
+ how to install the module, any machine dependencies it may have (for
2028
+ example C compilers and installed libraries) and any other information
2029
+ that should be provided before the module is installed.
2030
+
2031
+ A README file is required for CPAN modules since CPAN extracts the
2032
+ README file from a module distribution so that people browsing the
2033
+ archive can use it get an idea of the modules uses. It is usually a
2034
+ good idea to provide version information here so that people can
2035
+ decide whether fixes for the module are worth downloading.
2036
+
2037
+ INSTALLATION
2038
+
2039
+ To install this module type the following:
2040
+
2041
+ perl Makefile.PL
2042
+ make
2043
+ make test
2044
+ make install
2045
+
2046
+ DEPENDENCIES
2047
+
2048
+ This module requires these other modules and libraries:
2049
+
2050
+ $rm_prereq
2051
+
2052
+ COPYRIGHT AND LICENCE
2053
+
2054
+ Put the correct copyright and licence information here.
2055
+
2056
+ $licence
2057
+
2058
+ _RMEND_
2059
+ close(RM) || die "Can't close $ext$modpname/README: $!\n";
2060
+
2061
+ my $testdir = "t";
2062
+ my $testfile = "$testdir/$modpname.t";
2063
+ unless (-d "$testdir") {
2064
+ mkdir "$testdir" or die "Cannot mkdir $testdir: $!\n";
2065
+ }
2066
+ warn "Writing $ext$modpname/$testfile\n";
2067
+ my $tests = @const_names ? 2 : 1;
2068
+
2069
+ open EX, ">", "$testfile" or die "Can't create $ext$modpname/$testfile: $!\n";
2070
+
2071
+ print EX <<_END_;
2072
+ # Before 'make install' is performed this script should be runnable with
2073
+ # 'make test'. After 'make install' it should work as 'perl $modpname.t'
2074
+
2075
+ #########################
2076
+
2077
+ # change 'tests => $tests' to 'tests => last_test_to_print';
2078
+
2079
+ use strict;
2080
+ use warnings;
2081
+
2082
+ _END_
2083
+
2084
+ my $test_mod = 'Test::More';
2085
+
2086
+ if ( $old_test or ($compat_version < 5.006002 and not $new_test ))
2087
+ {
2088
+ my $test_mod = 'Test';
2089
+
2090
+ print EX <<_END_;
2091
+ use Test;
2092
+ BEGIN { plan tests => $tests };
2093
+ use $module;
2094
+ ok(1); # If we made it this far, we're ok.
2095
+
2096
+ _END_
2097
+
2098
+ if (@const_names) {
2099
+ my $const_names = join " ", @const_names;
2100
+ print EX <<'_END_';
2101
+
2102
+ my $fail;
2103
+ foreach my $constname (qw(
2104
+ _END_
2105
+
2106
+ print EX wrap ("\t", "\t", $const_names);
2107
+ print EX (")) {\n");
2108
+
2109
+ print EX <<_END_;
2110
+ next if (eval "my \\\$a = \$constname; 1");
2111
+ if (\$\@ =~ /^Your vendor has not defined $module macro \$constname/) {
2112
+ print "# pass: \$\@";
2113
+ } else {
2114
+ print "# fail: \$\@";
2115
+ \$fail = 1;
2116
+ }
2117
+ }
2118
+ if (\$fail) {
2119
+ print "not ok 2\\n";
2120
+ } else {
2121
+ print "ok 2\\n";
2122
+ }
2123
+
2124
+ _END_
2125
+ }
2126
+ }
2127
+ else
2128
+ {
2129
+ print EX <<_END_;
2130
+ use Test::More tests => $tests;
2131
+ BEGIN { use_ok('$module') };
2132
+
2133
+ _END_
2134
+
2135
+ if (@const_names) {
2136
+ my $const_names = join " ", @const_names;
2137
+ print EX <<'_END_';
2138
+
2139
+ my $fail = 0;
2140
+ foreach my $constname (qw(
2141
+ _END_
2142
+
2143
+ print EX wrap ("\t", "\t", $const_names);
2144
+ print EX (")) {\n");
2145
+
2146
+ print EX <<_END_;
2147
+ next if (eval "my \\\$a = \$constname; 1");
2148
+ if (\$\@ =~ /^Your vendor has not defined $module macro \$constname/) {
2149
+ print "# pass: \$\@";
2150
+ } else {
2151
+ print "# fail: \$\@";
2152
+ \$fail = 1;
2153
+ }
2154
+
2155
+ }
2156
+
2157
+ ok( \$fail == 0 , 'Constants' );
2158
+ _END_
2159
+ }
2160
+ }
2161
+
2162
+ print EX <<_END_;
2163
+ #########################
2164
+
2165
+ # Insert your test code below, the $test_mod module is use()ed here so read
2166
+ # its man page ( perldoc $test_mod ) for help writing this test script.
2167
+
2168
+ _END_
2169
+
2170
+ close(EX) || die "Can't close $ext$modpname/$testfile: $!\n";
2171
+
2172
+ unless ($opt_C) {
2173
+ warn "Writing $ext$modpname/Changes\n";
2174
+ $" = ' ';
2175
+ open(EX, ">", "Changes") || die "Can't create $ext$modpname/Changes: $!\n";
2176
+ @ARGS = map {/[\s\"\'\`\$*?^|&<>\[\]\{\}\(\)]/ ? "'$_'" : $_} @ARGS;
2177
+ print EX <<EOP;
2178
+ Revision history for Perl extension $module.
2179
+
2180
+ $TEMPLATE_VERSION @{[scalar localtime]}
2181
+ \t- original version; created by h2xs $H2XS_VERSION with options
2182
+ \t\t@ARGS
2183
+
2184
+ EOP
2185
+ close(EX) || die "Can't close $ext$modpname/Changes: $!\n";
2186
+ }
2187
+
2188
+ warn "Writing $ext$modpname/MANIFEST\n";
2189
+ open(MANI, '>', 'MANIFEST') or die "Can't create MANIFEST: $!";
2190
+ my @files = grep { -f } (<*>, <t/*>, <$fallbackdirname/*>, <$modpmdir/*>);
2191
+ if (!@files) {
2192
+ eval {opendir(D,'.');};
2193
+ unless ($@) { @files = readdir(D); closedir(D); }
2194
+ }
2195
+ if (!@files) { @files = map {chomp && $_} `ls`; }
2196
+ if ($^O eq 'VMS') {
2197
+ foreach (@files) {
2198
+ # Clip trailing '.' for portability -- non-VMS OSs don't expect it
2199
+ s%\.$%%;
2200
+ # Fix up for case-sensitive file systems
2201
+ s/$modfname/$modfname/i && next;
2202
+ $_ = "\U$_" if $_ eq 'manifest' or $_ eq 'changes';
2203
+ $_ = 'Makefile.PL' if $_ eq 'makefile.pl';
2204
+ }
2205
+ }
2206
+ print MANI join("\n",@files), "\n";
2207
+ close MANI;
git/usr/bin/core_perl/instmodsh ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!/usr/bin/perl -w
5
+
6
+ BEGIN { pop @INC if $INC[-1] eq '.' }
7
+ use strict;
8
+ use IO::File;
9
+ use ExtUtils::Packlist;
10
+ use ExtUtils::Installed;
11
+
12
+ use vars qw($Inst @Modules);
13
+
14
+
15
+ =head1 NAME
16
+
17
+ instmodsh - A shell to examine installed modules
18
+
19
+ =head1 SYNOPSIS
20
+
21
+ instmodsh
22
+
23
+ =head1 DESCRIPTION
24
+
25
+ A little interface to ExtUtils::Installed to examine installed modules,
26
+ validate your packlists and even create a tarball from an installed module.
27
+
28
+ =head1 SEE ALSO
29
+
30
+ ExtUtils::Installed
31
+
32
+ =cut
33
+
34
+
35
+ my $Module_Help = <<EOF;
36
+ Available commands are:
37
+ f [all|prog|doc] - List installed files of a given type
38
+ d [all|prog|doc] - List the directories used by a module
39
+ v - Validate the .packlist - check for missing files
40
+ t <tarfile> - Create a tar archive of the module
41
+ h - Display module help
42
+ q - Quit the module
43
+ EOF
44
+
45
+ my %Module_Commands = (
46
+ f => \&list_installed,
47
+ d => \&list_directories,
48
+ v => \&validate_packlist,
49
+ t => \&create_archive,
50
+ h => \&module_help,
51
+ );
52
+
53
+ sub do_module($) {
54
+ my ($module) = @_;
55
+
56
+ print($Module_Help);
57
+ MODULE_CMD: while (1) {
58
+ print("$module cmd? ");
59
+
60
+ my $reply = <STDIN>; chomp($reply);
61
+ my($cmd) = $reply =~ /^(\w)\b/;
62
+
63
+ last if $cmd eq 'q';
64
+
65
+ if( $Module_Commands{$cmd} ) {
66
+ $Module_Commands{$cmd}->($reply, $module);
67
+ }
68
+ elsif( $cmd eq 'q' ) {
69
+ last MODULE_CMD;
70
+ }
71
+ else {
72
+ module_help();
73
+ }
74
+ }
75
+ }
76
+
77
+
78
+ sub list_installed {
79
+ my($reply, $module) = @_;
80
+
81
+ my $class = (split(' ', $reply))[1];
82
+ $class = 'all' unless $class;
83
+
84
+ my @files;
85
+ if (eval { @files = $Inst->files($module, $class); }) {
86
+ print("$class files in $module are:\n ",
87
+ join("\n ", @files), "\n");
88
+ }
89
+ else {
90
+ print($@);
91
+ }
92
+ };
93
+
94
+
95
+ sub list_directories {
96
+ my($reply, $module) = @_;
97
+
98
+ my $class = (split(' ', $reply))[1];
99
+ $class = 'all' unless $class;
100
+
101
+ my @dirs;
102
+ if (eval { @dirs = $Inst->directories($module, $class); }) {
103
+ print("$class directories in $module are:\n ",
104
+ join("\n ", @dirs), "\n");
105
+ }
106
+ else {
107
+ print($@);
108
+ }
109
+ }
110
+
111
+
112
+ sub create_archive {
113
+ my($reply, $module) = @_;
114
+
115
+ my $file = (split(' ', $reply))[1];
116
+
117
+ if( !(defined $file and length $file) ) {
118
+ print "No tar file specified\n";
119
+ }
120
+ elsif( eval { require Archive::Tar } ) {
121
+ Archive::Tar->create_archive($file, 0, $Inst->files($module));
122
+ }
123
+ else {
124
+ my($first, @rest) = $Inst->files($module);
125
+ system('tar', 'cvf', $file, $first);
126
+ for my $f (@rest) {
127
+ system('tar', 'rvf', $file, $f);
128
+ }
129
+ print "Can't use tar\n" if $?;
130
+ }
131
+ }
132
+
133
+
134
+ sub validate_packlist {
135
+ my($reply, $module) = @_;
136
+
137
+ if (my @missing = $Inst->validate($module)) {
138
+ print("Files missing from $module are:\n ",
139
+ join("\n ", @missing), "\n");
140
+ }
141
+ else {
142
+ print("$module has no missing files\n");
143
+ }
144
+ }
145
+
146
+ sub module_help {
147
+ print $Module_Help;
148
+ }
149
+
150
+
151
+
152
+ ##############################################################################
153
+
154
+ sub toplevel()
155
+ {
156
+ my $help = <<EOF;
157
+ Available commands are:
158
+ l - List all installed modules
159
+ m <module> - Select a module
160
+ q - Quit the program
161
+ EOF
162
+ print($help);
163
+ while (1)
164
+ {
165
+ print("cmd? ");
166
+ my $reply = <STDIN>; chomp($reply);
167
+ CASE:
168
+ {
169
+ $reply eq 'l' and do
170
+ {
171
+ print("Installed modules are:\n ", join("\n ", @Modules), "\n");
172
+ last CASE;
173
+ };
174
+ $reply =~ /^m\s+/ and do
175
+ {
176
+ do_module((split(' ', $reply))[1]);
177
+ last CASE;
178
+ };
179
+ $reply eq 'q' and do
180
+ {
181
+ exit(0);
182
+ };
183
+ # Default
184
+ print($help);
185
+ }
186
+ }
187
+ }
188
+
189
+
190
+ ###############################################################################
191
+
192
+ $Inst = ExtUtils::Installed->new();
193
+ @Modules = $Inst->modules();
194
+ toplevel();
195
+
196
+ ###############################################################################
git/usr/bin/core_perl/json_pp ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!/usr/bin/perl
5
+
6
+ BEGIN { pop @INC if $INC[-1] eq '.' }
7
+ use strict;
8
+ use Getopt::Long;
9
+ use Encode ();
10
+
11
+ use JSON::PP ();
12
+
13
+ # imported from JSON-XS/bin/json_xs
14
+
15
+ my %allow_json_opt = map { $_ => 1 } qw(
16
+ ascii latin1 utf8 pretty indent space_before space_after relaxed canonical allow_nonref
17
+ allow_singlequote allow_barekey allow_bignum loose escape_slash indent_length
18
+ );
19
+
20
+
21
+ GetOptions(
22
+ 'v' => \( my $opt_verbose ),
23
+ 'f=s' => \( my $opt_from = 'json' ),
24
+ 't=s' => \( my $opt_to = 'json' ),
25
+ 'json_opt=s' => \( my $json_opt = 'pretty' ),
26
+ 'V' => \( my $version ),
27
+ ) or die "Usage: $0 [-V] [-f from_format] [-t to_format] [-json_opt options_to_json1[,options_to_json2[,...]]]\n";
28
+
29
+
30
+ if ( $version ) {
31
+ print "$JSON::PP::VERSION\n";
32
+ exit;
33
+ }
34
+
35
+
36
+ $json_opt = '' if $json_opt eq '-';
37
+
38
+ my %json_opt;
39
+ for my $opt (split /,/, $json_opt) {
40
+ my ($key, $value) = split /=/, $opt, 2;
41
+ $value = 1 unless defined $value;
42
+ die "'$_' is not a valid json option" unless $allow_json_opt{$key};
43
+ $json_opt{$key} = $value;
44
+ }
45
+
46
+ my %F = (
47
+ 'json' => sub {
48
+ my $json = JSON::PP->new;
49
+ my $enc =
50
+ /^\x00\x00\x00/s ? "utf-32be"
51
+ : /^\x00.\x00/s ? "utf-16be"
52
+ : /^.\x00\x00\x00/s ? "utf-32le"
53
+ : /^.\x00.\x00/s ? "utf-16le"
54
+ : "utf-8";
55
+ for my $key (keys %json_opt) {
56
+ next if $key eq 'utf8';
57
+ $json->$key($json_opt{$key});
58
+ }
59
+ $json->decode( Encode::decode($enc, $_) );
60
+ },
61
+ 'eval' => sub {
62
+ my $v = eval "no strict;\n#line 1 \"input\"\n$_";
63
+ die "$@" if $@;
64
+ return $v;
65
+ },
66
+ );
67
+
68
+
69
+ my %T = (
70
+ 'null' => sub { "" },
71
+ 'json' => sub {
72
+ my $json = JSON::PP->new->utf8;
73
+ for my $key (keys %json_opt) {
74
+ $json->$key($json_opt{$key});
75
+ }
76
+ $json->canonical if $json_opt{pretty};
77
+ $json->encode( $_ );
78
+ },
79
+ 'dumper' => sub {
80
+ require Data::Dumper;
81
+ local $Data::Dumper::Terse = 1;
82
+ local $Data::Dumper::Indent = 1;
83
+ local $Data::Dumper::Useqq = 1;
84
+ local $Data::Dumper::Quotekeys = 0;
85
+ local $Data::Dumper::Sortkeys = 1;
86
+ Data::Dumper::Dumper($_)
87
+ },
88
+ );
89
+
90
+
91
+
92
+ $F{$opt_from}
93
+ or die "$opt_from: not a valid fromformat\n";
94
+
95
+ $T{$opt_to}
96
+ or die "$opt_from: not a valid toformat\n";
97
+
98
+ {
99
+ local $/;
100
+ binmode STDIN;
101
+ $_ = <STDIN>;
102
+ }
103
+
104
+ $_ = $F{$opt_from}->();
105
+ $_ = $T{$opt_to}->();
106
+
107
+ print $_;
108
+
109
+
110
+ __END__
111
+
112
+ =pod
113
+
114
+ =encoding utf8
115
+
116
+ =head1 NAME
117
+
118
+ json_pp - JSON::PP command utility
119
+
120
+ =head1 SYNOPSIS
121
+
122
+ json_pp [-v] [-f from_format] [-t to_format] [-json_opt options_to_json1[,options_to_json2[,...]]]
123
+
124
+ =head1 DESCRIPTION
125
+
126
+ json_pp converts between some input and output formats (one of them is JSON).
127
+ This program was copied from L<json_xs> and modified.
128
+
129
+ The default input format is json and the default output format is json with pretty option.
130
+
131
+ =head1 OPTIONS
132
+
133
+ =head2 -f
134
+
135
+ -f from_format
136
+
137
+ Reads a data in the given format from STDIN.
138
+
139
+ Format types:
140
+
141
+ =over
142
+
143
+ =item json
144
+
145
+ as JSON
146
+
147
+ =item eval
148
+
149
+ as Perl code
150
+
151
+ =back
152
+
153
+ =head2 -t
154
+
155
+ Writes a data in the given format to STDOUT.
156
+
157
+ =over
158
+
159
+ =item null
160
+
161
+ no action.
162
+
163
+ =item json
164
+
165
+ as JSON
166
+
167
+ =item dumper
168
+
169
+ as Data::Dumper
170
+
171
+ =back
172
+
173
+ =head2 -json_opt
174
+
175
+ options to JSON::PP
176
+
177
+ Acceptable options are:
178
+
179
+ ascii latin1 utf8 pretty indent space_before space_after relaxed canonical allow_nonref
180
+ allow_singlequote allow_barekey allow_bignum loose escape_slash indent_length
181
+
182
+ Multiple options must be separated by commas:
183
+
184
+ Right: -json_opt pretty,canonical
185
+
186
+ Wrong: -json_opt pretty -json_opt canonical
187
+
188
+ =head2 -v
189
+
190
+ Verbose option, but currently no action in fact.
191
+
192
+ =head2 -V
193
+
194
+ Prints version and exits.
195
+
196
+
197
+ =head1 EXAMPLES
198
+
199
+ $ perl -e'print q|{"foo":"あい","bar":1234567890000000000000000}|' |\
200
+ json_pp -f json -t dumper -json_opt pretty,utf8,allow_bignum
201
+
202
+ $VAR1 = {
203
+ 'bar' => bless( {
204
+ 'value' => [
205
+ '0000000',
206
+ '0000000',
207
+ '5678900',
208
+ '1234'
209
+ ],
210
+ 'sign' => '+'
211
+ }, 'Math::BigInt' ),
212
+ 'foo' => "\x{3042}\x{3044}"
213
+ };
214
+
215
+ $ perl -e'print q|{"foo":"あい","bar":1234567890000000000000000}|' |\
216
+ json_pp -f json -t dumper -json_opt pretty
217
+
218
+ $VAR1 = {
219
+ 'bar' => '1234567890000000000000000',
220
+ 'foo' => "\x{e3}\x{81}\x{82}\x{e3}\x{81}\x{84}"
221
+ };
222
+
223
+ =head1 SEE ALSO
224
+
225
+ L<JSON::PP>, L<json_xs>
226
+
227
+ =head1 AUTHOR
228
+
229
+ Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
230
+
231
+
232
+ =head1 COPYRIGHT AND LICENSE
233
+
234
+ Copyright 2010 by Makamaka Hannyaharamitu
235
+
236
+ This library is free software; you can redistribute it and/or modify
237
+ it under the same terms as Perl itself.
238
+
239
+ =cut
240
+
git/usr/bin/core_perl/libnetcfg ADDED
@@ -0,0 +1,722 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ =head1 NAME
6
+
7
+ libnetcfg - configure libnet
8
+
9
+ =head1 DESCRIPTION
10
+
11
+ The libnetcfg utility can be used to configure the libnet.
12
+ Starting from perl 5.8 libnet is part of the standard Perl
13
+ distribution, but the libnetcfg can be used for any libnet
14
+ installation.
15
+
16
+ =head1 USAGE
17
+
18
+ Without arguments libnetcfg displays the current configuration.
19
+
20
+ $ libnetcfg
21
+ # old config ./libnet.cfg
22
+ daytime_hosts ntp1.none.such
23
+ ftp_int_passive 0
24
+ ftp_testhost ftp.funet.fi
25
+ inet_domain none.such
26
+ nntp_hosts nntp.none.such
27
+ ph_hosts
28
+ pop3_hosts pop.none.such
29
+ smtp_hosts smtp.none.such
30
+ snpp_hosts
31
+ test_exist 1
32
+ test_hosts 1
33
+ time_hosts ntp.none.such
34
+ # libnetcfg -h for help
35
+ $
36
+
37
+ It tells where the old configuration file was found (if found).
38
+
39
+ The C<-h> option will show a usage message.
40
+
41
+ To change the configuration you will need to use either the C<-c> or
42
+ the C<-d> options.
43
+
44
+ The default name of the old configuration file is by default
45
+ "libnet.cfg", unless otherwise specified using the -i option,
46
+ C<-i oldfile>, and it is searched first from the current directory,
47
+ and then from your module path.
48
+
49
+ The default name of the new configuration file is "libnet.cfg", and by
50
+ default it is written to the current directory, unless otherwise
51
+ specified using the -o option, C<-o newfile>.
52
+
53
+ =head1 SEE ALSO
54
+
55
+ L<Net::Config>, L<libnetFAQ>
56
+
57
+ =head1 AUTHORS
58
+
59
+ Graham Barr, the original Configure script of libnet.
60
+
61
+ Jarkko Hietaniemi, conversion into libnetcfg for inclusion into Perl 5.8.
62
+
63
+ =cut
64
+
65
+ # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $
66
+
67
+ BEGIN { pop @INC if $INC[-1] eq '.' }
68
+ use strict;
69
+ use IO::File;
70
+ use Getopt::Std;
71
+ use ExtUtils::MakeMaker qw(prompt);
72
+ use File::Spec;
73
+
74
+ use vars qw($opt_d $opt_c $opt_h $opt_o $opt_i);
75
+
76
+ ##
77
+ ##
78
+ ##
79
+
80
+ my %cfg = ();
81
+ my @cfg = ();
82
+
83
+ my($libnet_cfg_in,$libnet_cfg_out,$msg,$ans,$def,$have_old);
84
+
85
+ ##
86
+ ##
87
+ ##
88
+
89
+ sub valid_host
90
+ {
91
+ my $h = shift;
92
+
93
+ defined($h) && (($cfg{'test_exist'} == 0) || gethostbyname($h));
94
+ }
95
+
96
+ ##
97
+ ##
98
+ ##
99
+
100
+ sub test_hostnames (\@)
101
+ {
102
+ my $hlist = shift;
103
+ my @h = ();
104
+ my $host;
105
+ my $err = 0;
106
+
107
+ foreach $host (@$hlist)
108
+ {
109
+ if(valid_host($host))
110
+ {
111
+ push(@h, $host);
112
+ next;
113
+ }
114
+ warn "Bad hostname: '$host'\n";
115
+ $err++;
116
+ }
117
+ @$hlist = @h;
118
+ $err ? join(" ",@h) : undef;
119
+ }
120
+
121
+ ##
122
+ ##
123
+ ##
124
+
125
+ sub Prompt
126
+ {
127
+ my($prompt,$def) = @_;
128
+
129
+ $def = "" unless defined $def;
130
+
131
+ chomp($prompt);
132
+
133
+ if($opt_d)
134
+ {
135
+ print $prompt,," [",$def,"]\n";
136
+ return $def;
137
+ }
138
+ prompt($prompt,$def);
139
+ }
140
+
141
+ ##
142
+ ##
143
+ ##
144
+
145
+ sub get_host_list
146
+ {
147
+ my($prompt,$def) = @_;
148
+
149
+ $def = join(" ",@$def) if ref($def);
150
+
151
+ my @hosts;
152
+
153
+ do
154
+ {
155
+ my $ans = Prompt($prompt,$def);
156
+
157
+ $ans =~ s/(\A\s+|\s+\Z)//g;
158
+
159
+ @hosts = split(/\s+/, $ans);
160
+ }
161
+ while(@hosts && defined($def = test_hostnames(@hosts)));
162
+
163
+ \@hosts;
164
+ }
165
+
166
+ ##
167
+ ##
168
+ ##
169
+
170
+ sub get_hostname
171
+ {
172
+ my($prompt,$def) = @_;
173
+
174
+ my $host;
175
+
176
+ while(1)
177
+ {
178
+ my $ans = Prompt($prompt,$def);
179
+ $host = ($ans =~ /(\S*)/)[0];
180
+ last
181
+ if(!length($host) || valid_host($host));
182
+
183
+ $def =""
184
+ if $def eq $host;
185
+
186
+ print <<"EDQ";
187
+
188
+ *** ERROR:
189
+ Hostname '$host' does not seem to exist, please enter again
190
+ or a single space to clear any default
191
+
192
+ EDQ
193
+ }
194
+
195
+ length $host
196
+ ? $host
197
+ : undef;
198
+ }
199
+
200
+ ##
201
+ ##
202
+ ##
203
+
204
+ sub get_bool ($$)
205
+ {
206
+ my($prompt,$def) = @_;
207
+
208
+ chomp($prompt);
209
+
210
+ my $val = Prompt($prompt,$def ? "yes" : "no");
211
+
212
+ $val =~ /^y/i ? 1 : 0;
213
+ }
214
+
215
+ ##
216
+ ##
217
+ ##
218
+
219
+ sub get_netmask ($$)
220
+ {
221
+ my($prompt,$def) = @_;
222
+
223
+ chomp($prompt);
224
+
225
+ my %list;
226
+ @list{@$def} = ();
227
+
228
+ MASK:
229
+ while(1) {
230
+ my $bad = 0;
231
+ my $ans = Prompt($prompt) or last;
232
+
233
+ if($ans eq '*') {
234
+ %list = ();
235
+ next;
236
+ }
237
+
238
+ if($ans eq '=') {
239
+ print "\n",( %list ? join("\n", sort keys %list) : 'none'),"\n\n";
240
+ next;
241
+ }
242
+
243
+ unless ($ans =~ m{^\s*(?:(-?\s*)(\d+(?:\.\d+){0,3})/(\d+))}) {
244
+ warn "Bad netmask '$ans'\n";
245
+ next;
246
+ }
247
+
248
+ my($remove,$bits,@ip) = ($1,$3,split(/\./, $2),0,0,0);
249
+ if ( $ip[0] < 1 || $bits < 1 || $bits > 32) {
250
+ warn "Bad netmask '$ans'\n";
251
+ next MASK;
252
+ }
253
+ foreach my $byte (@ip) {
254
+ if ( $byte > 255 ) {
255
+ warn "Bad netmask '$ans'\n";
256
+ next MASK;
257
+ }
258
+ }
259
+
260
+ my $mask = sprintf("%d.%d.%d.%d/%d",@ip[0..3],$bits);
261
+
262
+ if ($remove) {
263
+ delete $list{$mask};
264
+ }
265
+ else {
266
+ $list{$mask} = 1;
267
+ }
268
+
269
+ }
270
+
271
+ [ keys %list ];
272
+ }
273
+
274
+ ##
275
+ ##
276
+ ##
277
+
278
+ sub default_hostname
279
+ {
280
+ my $host;
281
+ my @host;
282
+
283
+ foreach $host (@_)
284
+ {
285
+ if(defined($host) && valid_host($host))
286
+ {
287
+ return $host
288
+ unless wantarray;
289
+ push(@host,$host);
290
+ }
291
+ }
292
+
293
+ return wantarray ? @host : undef;
294
+ }
295
+
296
+ ##
297
+ ##
298
+ ##
299
+
300
+ getopts('dcho:i:');
301
+
302
+ $libnet_cfg_in = "libnet.cfg"
303
+ unless(defined($libnet_cfg_in = $opt_i));
304
+
305
+ $libnet_cfg_out = "libnet.cfg"
306
+ unless(defined($libnet_cfg_out = $opt_o));
307
+
308
+ my %oldcfg = ();
309
+
310
+ $Net::Config::CONFIGURE = 1; # Suppress load of user overrides
311
+ if( -f $libnet_cfg_in )
312
+ {
313
+ %oldcfg = ( %{ local @INC = '.'; do $libnet_cfg_in } );
314
+ }
315
+ elsif (eval { require Net::Config })
316
+ {
317
+ $have_old = 1;
318
+ %oldcfg = %Net::Config::NetConfig;
319
+ }
320
+
321
+ map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg;
322
+
323
+ #---------------------------------------------------------------------------
324
+
325
+ if ($opt_h) {
326
+ print <<EOU;
327
+ $0: Usage: $0 [-c] [-d] [-i oldconfigile] [-o newconfigfile] [-h]
328
+ Without options, the old configuration is shown.
329
+
330
+ -c change the configuration
331
+ -d use defaults from the old config (implies -c, non-interactive)
332
+ -i use a specific file as the old config file
333
+ -o use a specific file as the new config file
334
+ -h show this help
335
+
336
+ The default name of the old configuration file is by default
337
+ "libnet.cfg", unless otherwise specified using the -i option,
338
+ C<-i oldfile>, and it is searched first from the current directory,
339
+ and then from your module path.
340
+
341
+ The default name of the new configuration file is "libnet.cfg", and by
342
+ default it is written to the current directory, unless otherwise
343
+ specified using the -o option.
344
+
345
+ EOU
346
+ exit(0);
347
+ }
348
+
349
+ #---------------------------------------------------------------------------
350
+
351
+ {
352
+ my $oldcfgfile;
353
+ my @inc;
354
+ push @inc, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
355
+ push @inc, $ENV{PERLLIB} if exists $ENV{PERLLIB};
356
+ push @inc, @INC;
357
+ for (@inc) {
358
+ my $trycfgfile = File::Spec->catfile($_, $libnet_cfg_in);
359
+ if (-f $trycfgfile && -r $trycfgfile) {
360
+ $oldcfgfile = $trycfgfile;
361
+ last;
362
+ }
363
+ }
364
+ print "# old config $oldcfgfile\n" if defined $oldcfgfile;
365
+ for (sort keys %oldcfg) {
366
+ printf "%-20s %s\n", $_,
367
+ ref $oldcfg{$_} ? @{$oldcfg{$_}} : $oldcfg{$_};
368
+ }
369
+ unless ($opt_c || $opt_d) {
370
+ print "# $0 -h for help\n";
371
+ exit(0);
372
+ }
373
+ }
374
+
375
+ #---------------------------------------------------------------------------
376
+
377
+ $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'};
378
+ $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'};
379
+
380
+ #---------------------------------------------------------------------------
381
+
382
+ if($have_old && !$opt_d)
383
+ {
384
+ $msg = <<EDQ;
385
+
386
+ Ah, I see you already have installed libnet before.
387
+
388
+ Do you want to modify/update your configuration (y|n) ?
389
+ EDQ
390
+
391
+ $opt_d = 1
392
+ unless get_bool($msg,0);
393
+ }
394
+
395
+ #---------------------------------------------------------------------------
396
+
397
+ $msg = <<EDQ;
398
+
399
+ This script will prompt you to enter hostnames that can be used as
400
+ defaults for some of the modules in the libnet distribution.
401
+
402
+ To ensure that you do not enter an invalid hostname, I can perform a
403
+ lookup on each hostname you enter. If your internet connection is via
404
+ a dialup line then you may not want me to perform these lookups, as
405
+ it will require you to be on-line.
406
+
407
+ Do you want me to perform hostname lookups (y|n) ?
408
+ EDQ
409
+
410
+ $cfg{'test_exist'} = get_bool($msg, $oldcfg{'test_exist'});
411
+
412
+ print <<EDQ unless $cfg{'test_exist'};
413
+
414
+ *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
415
+
416
+ OK I will not check if the hostnames you give are valid
417
+ so be very cafeful
418
+
419
+ *** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***
420
+ EDQ
421
+
422
+
423
+ #---------------------------------------------------------------------------
424
+
425
+ print <<EDQ;
426
+
427
+ The following questions all require a list of host names, separated
428
+ with spaces. If you do not have a host available for any of the
429
+ services, then enter a single space, followed by <CR>. To accept the
430
+ default, hit <CR>
431
+
432
+ EDQ
433
+
434
+ $msg = 'Enter a list of available NNTP hosts :';
435
+
436
+ $def = $oldcfg{'nntp_hosts'} ||
437
+ [ default_hostname($ENV{NNTPSERVER},$ENV{NEWSHOST},'news') ];
438
+
439
+ $cfg{'nntp_hosts'} = get_host_list($msg,$def);
440
+
441
+ #---------------------------------------------------------------------------
442
+
443
+ $msg = 'Enter a list of available SMTP hosts :';
444
+
445
+ $def = $oldcfg{'smtp_hosts'} ||
446
+ [ default_hostname(split(/:/,$ENV{SMTPHOSTS} || ""), 'mailhost') ];
447
+
448
+ $cfg{'smtp_hosts'} = get_host_list($msg,$def);
449
+
450
+ #---------------------------------------------------------------------------
451
+
452
+ $msg = 'Enter a list of available POP3 hosts :';
453
+
454
+ $def = $oldcfg{'pop3_hosts'} || [];
455
+
456
+ $cfg{'pop3_hosts'} = get_host_list($msg,$def);
457
+
458
+ #---------------------------------------------------------------------------
459
+
460
+ $msg = 'Enter a list of available SNPP hosts :';
461
+
462
+ $def = $oldcfg{'snpp_hosts'} || [];
463
+
464
+ $cfg{'snpp_hosts'} = get_host_list($msg,$def);
465
+
466
+ #---------------------------------------------------------------------------
467
+
468
+ $msg = 'Enter a list of available PH Hosts :' ;
469
+
470
+ $def = $oldcfg{'ph_hosts'} ||
471
+ [ default_hostname('dirserv') ];
472
+
473
+ $cfg{'ph_hosts'} = get_host_list($msg,$def);
474
+
475
+ #---------------------------------------------------------------------------
476
+
477
+ $msg = 'Enter a list of available TIME Hosts :' ;
478
+
479
+ $def = $oldcfg{'time_hosts'} || [];
480
+
481
+ $cfg{'time_hosts'} = get_host_list($msg,$def);
482
+
483
+ #---------------------------------------------------------------------------
484
+
485
+ $msg = 'Enter a list of available DAYTIME Hosts :' ;
486
+
487
+ $def = $oldcfg{'daytime_hosts'} || $oldcfg{'time_hosts'};
488
+
489
+ $cfg{'daytime_hosts'} = get_host_list($msg,$def);
490
+
491
+ #---------------------------------------------------------------------------
492
+
493
+ $msg = <<EDQ;
494
+
495
+ Do you have a firewall/ftp proxy between your machine and the internet
496
+
497
+ If you use a SOCKS firewall answer no
498
+
499
+ (y|n) ?
500
+ EDQ
501
+
502
+ if(get_bool($msg,0)) {
503
+
504
+ $msg = <<'EDQ';
505
+ What series of FTP commands do you need to send to your
506
+ firewall to connect to an external host.
507
+
508
+ user/pass => external user & password
509
+ fwuser/fwpass => firewall user & password
510
+
511
+ 0) None
512
+ 1) -----------------------
513
+ USER user@remote.host
514
+ PASS pass
515
+ 2) -----------------------
516
+ USER fwuser
517
+ PASS fwpass
518
+ USER user@remote.host
519
+ PASS pass
520
+ 3) -----------------------
521
+ USER fwuser
522
+ PASS fwpass
523
+ SITE remote.site
524
+ USER user
525
+ PASS pass
526
+ 4) -----------------------
527
+ USER fwuser
528
+ PASS fwpass
529
+ OPEN remote.site
530
+ USER user
531
+ PASS pass
532
+ 5) -----------------------
533
+ USER user@fwuser@remote.site
534
+ PASS pass@fwpass
535
+ 6) -----------------------
536
+ USER fwuser@remote.site
537
+ PASS fwpass
538
+ USER user
539
+ PASS pass
540
+ 7) -----------------------
541
+ USER user@remote.host
542
+ PASS pass
543
+ AUTH fwuser
544
+ RESP fwpass
545
+
546
+ Choice:
547
+ EDQ
548
+ $def = exists $oldcfg{'ftp_firewall_type'} ? $oldcfg{'ftp_firewall_type'} : 1;
549
+ $ans = Prompt($msg,$def);
550
+ $cfg{'ftp_firewall_type'} = 0+$ans;
551
+ $def = $oldcfg{'ftp_firewall'} || $ENV{FTP_FIREWALL};
552
+
553
+ $cfg{'ftp_firewall'} = get_hostname("FTP proxy hostname :", $def);
554
+ }
555
+ else {
556
+ delete $cfg{'ftp_firewall'};
557
+ }
558
+
559
+
560
+ #---------------------------------------------------------------------------
561
+
562
+ if (defined $cfg{'ftp_firewall'})
563
+ {
564
+ print <<EDQ;
565
+
566
+ By default Net::FTP assumes that it only needs to use a firewall if it
567
+ cannot resolve the name of the host given. This only works if your DNS
568
+ system is setup to only resolve internal hostnames. If this is not the
569
+ case and your DNS will resolve external hostnames, then another method
570
+ is needed. Net::Config can do this if you provide the netmasks that
571
+ describe your internal network. Each netmask should be entered in the
572
+ form x.x.x.x/y, for example 127.0.0.0/8 or 214.8.16.32/24
573
+
574
+ EDQ
575
+ $def = [];
576
+ if(ref($oldcfg{'local_netmask'}))
577
+ {
578
+ $def = $oldcfg{'local_netmask'};
579
+ print "Your current netmasks are :\n\n\t",
580
+ join("\n\t",@{$def}),"\n\n";
581
+ }
582
+
583
+ print "
584
+ Enter one netmask at each prompt, prefix with a - to remove a netmask
585
+ from the list, enter a '*' to clear the whole list, an '=' to show the
586
+ current list and an empty line to continue with Configure.
587
+
588
+ ";
589
+
590
+ my $mask = get_netmask("netmask :",$def);
591
+ $cfg{'local_netmask'} = $mask if ref($mask) && @$mask;
592
+ }
593
+
594
+ #---------------------------------------------------------------------------
595
+
596
+ ###$msg =<<EDQ;
597
+ ###
598
+ ###SOCKS is a commonly used firewall protocol. If you use SOCKS firewalls
599
+ ###then enter a list of hostames
600
+ ###
601
+ ###Enter a list of available SOCKS hosts :
602
+ ###EDQ
603
+ ###
604
+ ###$def = $cfg{'socks_hosts'} ||
605
+ ### [ default_hostname($ENV{SOCKS5_SERVER},
606
+ ### $ENV{SOCKS_SERVER},
607
+ ### $ENV{SOCKS4_SERVER}) ];
608
+ ###
609
+ ###$cfg{'socks_hosts'} = get_host_list($msg,$def);
610
+
611
+ #---------------------------------------------------------------------------
612
+
613
+ print <<EDQ;
614
+
615
+ Normally when FTP needs a data connection the client tells the server
616
+ a port to connect to, and the server initiates a connection to the client.
617
+
618
+ Some setups, in particular firewall setups, can/do not work using this
619
+ protocol. In these situations the client must make the connection to the
620
+ server, this is called a passive transfer.
621
+ EDQ
622
+
623
+ if (defined $cfg{'ftp_firewall'}) {
624
+ $msg = "\nShould all FTP connections via a firewall/proxy be passive (y|n) ?";
625
+
626
+ $def = $oldcfg{'ftp_ext_passive'} || 0;
627
+
628
+ $cfg{'ftp_ext_passive'} = get_bool($msg,$def);
629
+
630
+ $msg = "\nShould all other FTP connections be passive (y|n) ?";
631
+
632
+ }
633
+ else {
634
+ $msg = "\nShould all FTP connections be passive (y|n) ?";
635
+ }
636
+
637
+ $def = $oldcfg{'ftp_int_passive'} || 0;
638
+
639
+ $cfg{'ftp_int_passive'} = get_bool($msg,$def);
640
+
641
+
642
+ #---------------------------------------------------------------------------
643
+
644
+ $def = $oldcfg{'inet_domain'} || $ENV{LOCALDOMAIN};
645
+
646
+ $ans = Prompt("\nWhat is your local internet domain name :",$def);
647
+
648
+ $cfg{'inet_domain'} = ($ans =~ /(\S+)/)[0];
649
+
650
+ #---------------------------------------------------------------------------
651
+
652
+ $msg = <<EDQ;
653
+
654
+ If you specified some default hosts above, it is possible for me to
655
+ do some basic tests when you run 'make test'
656
+
657
+ This will cause 'make test' to be quite a bit slower and, if your
658
+ internet connection is via dialup, will require you to be on-line
659
+ unless the hosts are local.
660
+
661
+ Do you want me to run these tests (y|n) ?
662
+ EDQ
663
+
664
+ $cfg{'test_hosts'} = get_bool($msg,$oldcfg{'test_hosts'});
665
+
666
+ #---------------------------------------------------------------------------
667
+
668
+ $msg = <<EDQ;
669
+
670
+ To allow Net::FTP to be tested I will need a hostname. This host
671
+ should allow anonymous access and have a /pub directory
672
+
673
+ What host can I use :
674
+ EDQ
675
+
676
+ $cfg{'ftp_testhost'} = get_hostname($msg,$oldcfg{'ftp_testhost'})
677
+ if $cfg{'test_hosts'};
678
+
679
+
680
+ print "\n";
681
+
682
+ #---------------------------------------------------------------------------
683
+
684
+ my $fh = IO::File->new($libnet_cfg_out, "w") or
685
+ die "Cannot create '$libnet_cfg_out': $!";
686
+
687
+ print "Writing $libnet_cfg_out\n";
688
+
689
+ print $fh "{\n";
690
+
691
+ my $key;
692
+ foreach $key (keys %cfg) {
693
+ my $val = $cfg{$key};
694
+ if(!defined($val)) {
695
+ $val = "undef";
696
+ }
697
+ elsif(ref($val)) {
698
+ $val = '[' . join(",",
699
+ map {
700
+ my $v = "undef";
701
+ if(defined $_) {
702
+ ($v = $_) =~ s/'/\'/sog;
703
+ $v = "'" . $v . "'";
704
+ }
705
+ $v;
706
+ } @$val ) . ']';
707
+ }
708
+ else {
709
+ $val =~ s/'/\'/sog;
710
+ $val = "'" . $val . "'" if $val =~ /\D/;
711
+ }
712
+ print $fh "\t'",$key,"' => ",$val,",\n";
713
+ }
714
+
715
+ print $fh "}\n";
716
+
717
+ $fh->close;
718
+
719
+ ############################################################################
720
+ ############################################################################
721
+
722
+ exit 0;
git/usr/bin/core_perl/perlbug ADDED
@@ -0,0 +1,1537 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ my $config_tag1 = '5.42.2 - Thu Apr 2 19:54:57 UTC 2026';
6
+
7
+ my $patchlevel_date = 1774202317;
8
+ my @patches = Config::local_patches();
9
+ my $patch_tags = join "", map /(\S+)/ ? "+$1 " : (), @patches;
10
+
11
+ BEGIN { pop @INC if $INC[-1] eq '.' }
12
+ use warnings;
13
+ use strict;
14
+ use Config;
15
+ use File::Spec; # keep perlbug Perl 5.005 compatible
16
+ use Getopt::Std;
17
+ use File::Basename 'basename';
18
+
19
+ $Getopt::Std::STANDARD_HELP_VERSION = 1;
20
+
21
+ sub paraprint;
22
+
23
+ BEGIN {
24
+ eval { require Mail::Send;};
25
+ $::HaveSend = ($@ eq "");
26
+ eval { require Mail::Util; } ;
27
+ $::HaveUtil = (!$ENV{PERL_BUILD_PACKAGING} and $@ eq "");
28
+ # use secure tempfiles wherever possible
29
+ eval { require File::Temp; };
30
+ $::HaveTemp = ($@ eq "");
31
+ eval { require Module::CoreList; };
32
+ $::HaveCoreList = ($@ eq "");
33
+ eval { require Text::Wrap; };
34
+ $::HaveWrap = ($@ eq "");
35
+ };
36
+
37
+ our $VERSION = "1.43";
38
+
39
+ #TODO:
40
+ # make sure failure (transmission-wise) of Mail::Send is accounted for.
41
+ # (This may work now. Unsure of the original author's issue -JESSE 2008-06-08)
42
+ # - Test -b option
43
+
44
+ my( $file, $usefile, $cc, $address, $thanksaddress,
45
+ $filename, $messageid, $domain, $subject, $from, $verbose, $ed, $outfile,
46
+ $fh, $me, $body, $andcc, %REP, $ok, $thanks, $progname,
47
+ $Is_MSWin32, $Is_Linux, $Is_VMS, $Is_OpenBSD,
48
+ $report_about_module, $category, $severity,
49
+ %opt, $have_attachment, $attachments, $has_patch, $mime_boundary
50
+ );
51
+
52
+ my $running_noninteractively = !-t STDIN;
53
+
54
+ my $perl_version = $^V ? sprintf("%vd", $^V) : $];
55
+
56
+ my $config_tag2 = "$perl_version - $Config{cf_time}";
57
+
58
+ Init();
59
+
60
+ if ($opt{h}) { Help(); exit; }
61
+ if ($opt{d}) { Dump(*STDOUT); exit; }
62
+ if ($running_noninteractively && !$opt{t} && !($ok and not $opt{n})) {
63
+ paraprint <<"EOF";
64
+ Please use $progname interactively. If you want to
65
+ include a file, you can use the -f switch.
66
+ EOF
67
+ die "\n";
68
+ }
69
+
70
+ Query();
71
+ Edit() unless $usefile || ($ok and not $opt{n});
72
+ NowWhat();
73
+ if ($address) {
74
+ Send();
75
+ if ($thanks) {
76
+ print "\nThank you for taking the time to send a thank-you message!\n\n";
77
+
78
+ paraprint <<EOF
79
+ Please note that mailing lists are moderated, your message may take a while to
80
+ show up.
81
+ EOF
82
+ } else {
83
+ print "\nThank you for taking the time to file a bug report!\n\n";
84
+
85
+ paraprint <<EOF
86
+ Please note that mailing lists are moderated, your message may take a while to
87
+ show up. Please consider submitting your report directly to the issue tracker
88
+ at https://github.com/Perl/perl5/issues
89
+ EOF
90
+ }
91
+
92
+ } else {
93
+ save_message_to_disk($outfile);
94
+ }
95
+
96
+ exit;
97
+
98
+ sub ask_for_alternatives { # (category|severity)
99
+ my $name = shift;
100
+ my %alts = (
101
+ 'category' => {
102
+ 'default' => 'core',
103
+ 'ok' => 'install',
104
+ # Inevitably some of these will end up in RT whatever we do:
105
+ 'thanks' => 'thanks',
106
+ 'opts' => [qw(core docs install library utilities)], # patch, notabug
107
+ },
108
+ 'severity' => {
109
+ 'default' => 'low',
110
+ 'ok' => 'none',
111
+ 'thanks' => 'none',
112
+ 'opts' => [qw(critical high medium low wishlist none)], # zero
113
+ },
114
+ );
115
+ die "Invalid alternative ($name) requested\n" unless grep(/^$name$/, keys %alts);
116
+ my $alt = "";
117
+ my $what = $ok || $thanks;
118
+ if ($what) {
119
+ $alt = $alts{$name}{$what};
120
+ } else {
121
+ my @alts = @{$alts{$name}{'opts'}};
122
+ print "\n\n";
123
+ paraprint <<EOF;
124
+ Please pick a $name from the following list:
125
+
126
+ @alts
127
+ EOF
128
+ my $err = 0;
129
+ do {
130
+ if ($err++ > 5) {
131
+ die "Invalid $name: aborting.\n";
132
+ }
133
+ $alt = _prompt('', "\u$name", $alts{$name}{'default'});
134
+ $alt ||= $alts{$name}{'default'};
135
+ } while !((($alt) = grep(/^$alt/i, @alts)));
136
+ }
137
+ lc $alt;
138
+ }
139
+
140
+ sub HELP_MESSAGE { Help(); exit; }
141
+ sub VERSION_MESSAGE { print "perlbug version $VERSION\n"; }
142
+
143
+ sub Init {
144
+ # -------- Setup --------
145
+
146
+ $Is_MSWin32 = $^O eq 'MSWin32';
147
+ $Is_VMS = $^O eq 'VMS';
148
+ $Is_Linux = lc($^O) eq 'linux';
149
+ $Is_OpenBSD = lc($^O) eq 'openbsd';
150
+
151
+ # Thanks address
152
+ $thanksaddress = 'perl-thanks@perl.org';
153
+
154
+ # Defaults if getopts fails.
155
+ $outfile = (basename($0) =~ /^perlthanks/i) ? "perlthanks.rep" : "perlbug.rep";
156
+ $cc = $::Config{'perladmin'} || $::Config{'cf_email'} || $::Config{'cf_by'} || '';
157
+
158
+ HELP_MESSAGE() unless getopts("Adhva:s:b:f:F:r:e:SCc:to:n:T:p:", \%opt);
159
+
160
+ # This comment is needed to notify metaconfig that we are
161
+ # using the $perladmin, $cf_by, and $cf_time definitions.
162
+ # -------- Configuration ---------
163
+
164
+ if (basename ($0) =~ /^perlthanks/i) {
165
+ # invoked as perlthanks
166
+ $opt{T} = 1;
167
+ $opt{C} = 1; # don't send a copy to the local admin
168
+ }
169
+
170
+ if ($opt{T}) {
171
+ $thanks = 'thanks';
172
+ }
173
+
174
+ $progname = $thanks ? 'perlthanks' : 'perlbug';
175
+ # Target address
176
+ $address = $opt{a} || ($thanks ? $thanksaddress : "");
177
+
178
+ # Users address, used in message and in From and Reply-To headers
179
+ $from = $opt{r} || "";
180
+
181
+ # Include verbose configuration information
182
+ $verbose = $opt{v} || 0;
183
+
184
+ # Subject of bug-report message
185
+ $subject = $opt{s} || "";
186
+
187
+ # Send a file
188
+ $usefile = ($opt{f} || 0);
189
+
190
+ # File to send as report
191
+ $file = $opt{f} || "";
192
+
193
+ # We have one or more attachments
194
+ $have_attachment = ($opt{p} || 0);
195
+ $mime_boundary = ('-' x 12) . "$VERSION.perlbug" if $have_attachment;
196
+
197
+ # Comma-separated list of attachments
198
+ $attachments = $opt{p} || "";
199
+ $has_patch = 0; # TBD based on file type
200
+
201
+ for my $attachment (split /\s*,\s*/, $attachments) {
202
+ unless (-f $attachment && -r $attachment) {
203
+ die "The attachment $attachment is not a readable file: $!\n";
204
+ }
205
+ $has_patch = 1 if $attachment =~ m/\.(patch|diff)$/;
206
+ }
207
+
208
+ # File to output to
209
+ $outfile = $opt{F} || "$progname.rep";
210
+
211
+ # Body of report
212
+ $body = $opt{b} || "";
213
+
214
+ # Editor
215
+ $ed = $opt{e} || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
216
+ || ($Is_VMS && "edit/tpu")
217
+ || ($Is_MSWin32 && "notepad")
218
+ || "vi";
219
+
220
+ # Not OK - provide build failure template by finessing OK report
221
+ if ($opt{n}) {
222
+ if (substr($opt{n}, 0, 2) eq 'ok' ) {
223
+ $opt{o} = substr($opt{n}, 1);
224
+ } else {
225
+ Help();
226
+ exit();
227
+ }
228
+ }
229
+
230
+ # OK - send "OK" report for build on this system
231
+ $ok = '';
232
+ if ($opt{o}) {
233
+ if ($opt{o} eq 'k' or $opt{o} eq 'kay') {
234
+ my $age = time - $patchlevel_date;
235
+ if ($opt{o} eq 'k' and $age > 60 * 24 * 60 * 60 ) {
236
+ my $date = localtime $patchlevel_date;
237
+ print <<"EOF";
238
+ "perlbug -ok" and "perlbug -nok" do not report on Perl versions which
239
+ are more than 60 days old. This Perl version was constructed on
240
+ $date. If you really want to report this, use
241
+ "perlbug -okay" or "perlbug -nokay".
242
+ EOF
243
+ exit();
244
+ }
245
+ # force these options
246
+ unless ($opt{n}) {
247
+ $opt{S} = 1; # don't prompt for send
248
+ $opt{b} = 1; # we have a body
249
+ $body = "Perl reported to build OK on this system.\n";
250
+ }
251
+ $opt{C} = 1; # don't send a copy to the local admin
252
+ $opt{s} = 1; # we have a subject line
253
+ $subject = ($opt{n} ? 'Not ' : '')
254
+ . "OK: perl $perl_version ${patch_tags}on"
255
+ ." $::Config{'archname'} $::Config{'osvers'} $subject";
256
+ $ok = 'ok';
257
+ } else {
258
+ Help();
259
+ exit();
260
+ }
261
+ }
262
+
263
+ # Possible administrator addresses, in order of confidence
264
+ # (Note that cf_email is not mentioned to metaconfig, since
265
+ # we don't really want it. We'll just take it if we have to.)
266
+ #
267
+ # This has to be after the $ok stuff above because of the way
268
+ # that $opt{C} is forced.
269
+ $cc = $opt{C} ? "" : (
270
+ $opt{c} || $::Config{'perladmin'}
271
+ || $::Config{'cf_email'} || $::Config{'cf_by'}
272
+ );
273
+
274
+ if ($::HaveUtil) {
275
+ $domain = Mail::Util::maildomain();
276
+ } elsif ($Is_MSWin32) {
277
+ $domain = $ENV{'USERDOMAIN'};
278
+ } else {
279
+ require Sys::Hostname;
280
+ $domain = Sys::Hostname::hostname();
281
+ }
282
+
283
+ # Message-Id - rjsf
284
+ $messageid = "<$::Config{'version'}_${$}_".time."\@$domain>";
285
+
286
+ # My username
287
+ $me = $Is_MSWin32 ? $ENV{'USERNAME'}
288
+ : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
289
+ : eval { getpwuid($<) }; # May be missing
290
+
291
+ $from = $::Config{'cf_email'}
292
+ if !$from && $::Config{'cf_email'} && $::Config{'cf_by'} && $me &&
293
+ ($me eq $::Config{'cf_by'});
294
+ } # sub Init
295
+
296
+ sub Query {
297
+ # Explain what perlbug is
298
+ unless ($ok) {
299
+ if ($thanks) {
300
+ paraprint <<'EOF';
301
+ This program provides an easy way to send a thank-you message back to the
302
+ authors and maintainers of perl.
303
+
304
+ If you wish to generate a bug report, please run it without the -T flag
305
+ (or run the program perlbug rather than perlthanks)
306
+ EOF
307
+ } else {
308
+ paraprint <<"EOF";
309
+ This program provides an easy way to generate a bug report for the core
310
+ perl distribution (along with tests or patches). To send a thank-you
311
+ note to $thanksaddress instead of a bug report, please run 'perlthanks'.
312
+
313
+ The GitHub issue tracker at https://github.com/Perl/perl5/issues is the
314
+ best place to submit your report so it can be tracked and resolved.
315
+
316
+ Please do not use $0 to report bugs in perl modules from CPAN.
317
+
318
+ Suggestions for how to find help using Perl can be found at
319
+ https://perldoc.perl.org/perlcommunity.html
320
+ EOF
321
+ }
322
+ }
323
+
324
+ # Prompt for subject of message, if needed
325
+
326
+ if ($subject && TrivialSubject($subject)) {
327
+ $subject = '';
328
+ }
329
+
330
+ unless ($subject) {
331
+ print
332
+ "First of all, please provide a subject for the report.\n";
333
+ if ( not $thanks) {
334
+ paraprint <<EOF;
335
+ This should be a concise description of your bug or problem
336
+ which will help the volunteers working to improve perl to categorize
337
+ and resolve the issue. Be as specific and descriptive as
338
+ you can. A subject like "perl bug" or "perl problem" will make it
339
+ much less likely that your issue gets the attention it deserves.
340
+ EOF
341
+ }
342
+
343
+ my $err = 0;
344
+ do {
345
+ $subject = _prompt('','Subject');
346
+ if ($err++ == 5) {
347
+ if ($thanks) {
348
+ $subject = 'Thanks for Perl';
349
+ } else {
350
+ die "Aborting.\n";
351
+ }
352
+ }
353
+ } while (TrivialSubject($subject));
354
+ }
355
+ $subject = '[PATCH] ' . $subject
356
+ if $has_patch && ($subject !~ m/^\[PATCH/i);
357
+
358
+ # Prompt for return address, if needed
359
+ unless ($opt{r}) {
360
+ # Try and guess return address
361
+ my $guess;
362
+
363
+ $guess = $ENV{'REPLY-TO'} || $ENV{'REPLYTO'} || $ENV{'EMAIL'}
364
+ || $from || '';
365
+
366
+ unless ($guess) {
367
+ # move $domain to where we can use it elsewhere
368
+ if ($domain) {
369
+ if ($Is_VMS && !$::Config{'d_socket'}) {
370
+ $guess = "$domain\:\:$me";
371
+ } else {
372
+ $guess = "$me\@$domain" if $domain;
373
+ }
374
+ }
375
+ }
376
+
377
+ if ($guess) {
378
+ unless ($ok) {
379
+ paraprint <<EOF;
380
+ Perl's developers may need your email address to contact you for
381
+ further information about your issue or to inform you when it is
382
+ resolved. If the default shown is not your email address, please
383
+ correct it.
384
+ EOF
385
+ }
386
+ } else {
387
+ paraprint <<EOF;
388
+ Please enter your full internet email address so that Perl's
389
+ developers can contact you with questions about your issue or to
390
+ inform you that it has been resolved.
391
+ EOF
392
+ }
393
+
394
+ if ($ok && $guess) {
395
+ # use it
396
+ $from = $guess;
397
+ } else {
398
+ # verify it
399
+ $from = _prompt('','Your address',$guess);
400
+ $from = $guess if $from eq '';
401
+ }
402
+ }
403
+
404
+ if ($from eq $cc or $me eq $cc) {
405
+ # Try not to copy ourselves
406
+ $cc = "yourself";
407
+ }
408
+
409
+ # Prompt for administrator address, unless an override was given
410
+ if( $address and !$opt{C} and !$opt{c} ) {
411
+ my $description = <<EOF;
412
+ $0 can send a copy of this report to your local perl
413
+ administrator. If the address below is wrong, please correct it,
414
+ or enter 'none' or 'yourself' to not send a copy.
415
+ EOF
416
+ my $entry = _prompt($description, "Local perl administrator", $cc);
417
+
418
+ if ($entry ne "") {
419
+ $cc = $entry;
420
+ $cc = '' if $me eq $cc;
421
+ }
422
+ }
423
+
424
+ $cc = '' if $cc =~ /^(none|yourself|me|myself|ourselves)$/i;
425
+ if ($cc) {
426
+ $andcc = " and $cc"
427
+ } else {
428
+ $andcc = ''
429
+ }
430
+
431
+ # Prompt for editor, if no override is given
432
+ editor:
433
+ unless ($opt{e} || $opt{f} || $opt{b}) {
434
+
435
+ my $description;
436
+
437
+ chomp (my $common_end = <<"EOF");
438
+ You will probably want to use a text editor to enter the body of
439
+ your report. If "$ed" is the editor you want to use, then just press
440
+ Enter, otherwise type in the name of the editor you would like to
441
+ use.
442
+
443
+ If you have already composed the body of your report, you may enter
444
+ "file", and $0 will prompt you to enter the name of the file
445
+ containing your report.
446
+ EOF
447
+
448
+ if ($thanks) {
449
+ $description = <<"EOF";
450
+ It's now time to compose your thank-you message.
451
+
452
+ Some information about your local perl configuration will automatically
453
+ be included at the end of your message, because we're curious about
454
+ the different ways that people build and use perl. If you'd rather
455
+ not share this information, you're welcome to delete it.
456
+
457
+ $common_end
458
+ EOF
459
+ } else {
460
+ $description = <<"EOF";
461
+ It's now time to compose your bug report. Try to make the report
462
+ concise but descriptive. Please include any detail which you think
463
+ might be relevant or might help the volunteers working to improve
464
+ perl. If you are reporting something that does not work as you think
465
+ it should, please try to include examples of the actual result and of
466
+ what you expected.
467
+
468
+ Some information about your local perl configuration will automatically
469
+ be included at the end of your report. If you are using an unusual
470
+ version of perl, it would be useful if you could confirm that you
471
+ can replicate the problem on a standard build of perl as well.
472
+
473
+ $common_end
474
+ EOF
475
+ }
476
+
477
+ my $entry = _prompt($description, "Editor", $ed);
478
+ $usefile = 0;
479
+ if ($entry eq "file") {
480
+ $usefile = 1;
481
+ } elsif ($entry ne "") {
482
+ $ed = $entry;
483
+ }
484
+ }
485
+ if ($::HaveCoreList && !$ok && !$thanks) {
486
+ my $description = <<EOF;
487
+ If your bug is about a Perl module rather than a core language
488
+ feature, please enter its name here. If it's not, just hit Enter
489
+ to skip this question.
490
+ EOF
491
+
492
+ my $entry = '';
493
+ while ($entry eq '') {
494
+ $entry = _prompt($description, 'Module');
495
+ my $first_release = Module::CoreList->first_release($entry);
496
+ if ($entry and not $first_release) {
497
+ paraprint <<EOF;
498
+ $entry is not a "core" Perl module. Please check that you entered
499
+ its name correctly. If it is correct, quit this program, try searching
500
+ for $entry on https://rt.cpan.org, and report your issue there.
501
+ EOF
502
+
503
+ $entry = '';
504
+ } elsif (my $bug_tracker = $Module::CoreList::bug_tracker{$entry}) {
505
+ paraprint <<"EOF";
506
+ $entry included with core Perl is copied directly from the CPAN distribution.
507
+ Please report bugs in $entry directly to its maintainers using $bug_tracker
508
+ EOF
509
+ $entry = '';
510
+ } elsif ($entry) {
511
+ $category ||= 'library';
512
+ $report_about_module = $entry;
513
+ last;
514
+ } else {
515
+ last;
516
+ }
517
+ }
518
+ }
519
+
520
+ # Prompt for category of bug
521
+ $category ||= ask_for_alternatives('category');
522
+
523
+ # Prompt for severity of bug
524
+ $severity ||= ask_for_alternatives('severity');
525
+
526
+ # Generate scratch file to edit report in
527
+ $filename = filename();
528
+
529
+ # Prompt for file to read report from, if needed
530
+ if ($usefile and !$file) {
531
+ filename:
532
+ my $description = <<EOF;
533
+ What is the name of the file that contains your report?
534
+ EOF
535
+ my $entry = _prompt($description, "Filename");
536
+
537
+ if ($entry eq "") {
538
+ paraprint <<EOF;
539
+ It seems you didn't enter a filename. Please choose to use a text
540
+ editor or enter a filename.
541
+ EOF
542
+ goto editor;
543
+ }
544
+
545
+ unless (-f $entry and -r $entry) {
546
+ paraprint <<EOF;
547
+ '$entry' doesn't seem to be a readable file. You may have mistyped
548
+ its name or may not have permission to read it.
549
+
550
+ If you don't want to use a file as the content of your report, just
551
+ hit Enter and you'll be able to select a text editor instead.
552
+ EOF
553
+ goto filename;
554
+ }
555
+ $file = $entry;
556
+ }
557
+
558
+ # Generate report
559
+ open(REP, '>:raw', $filename) or die "Unable to create report file '$filename': $!\n";
560
+ binmode(REP, ':raw :crlf') if $Is_MSWin32;
561
+
562
+ my $reptype = !$ok ? ($thanks ? 'thank-you' : 'bug')
563
+ : $opt{n} ? "build failure" : "success";
564
+
565
+ print REP <<EOF;
566
+ This is a $reptype report for perl from $from,
567
+ generated with the help of perlbug $VERSION running under perl $perl_version.
568
+
569
+ EOF
570
+
571
+ if ($report_about_module) {
572
+ print REP "Module: $report_about_module\n\n";
573
+ }
574
+
575
+ if ($body) {
576
+ print REP $body;
577
+ } elsif ($usefile) {
578
+ open(F, '<:raw', $file)
579
+ or die "Unable to read report file from '$file': $!\n";
580
+ binmode(F, ':raw :crlf') if $Is_MSWin32;
581
+ while (<F>) {
582
+ print REP $_
583
+ }
584
+ close(F) or die "Error closing '$file': $!";
585
+ } else {
586
+ if ($thanks) {
587
+ print REP <<'EOF';
588
+
589
+ -----------------------------------------------------------------
590
+ [Please enter your thank-you message here]
591
+
592
+
593
+
594
+ [You're welcome to delete anything below this line]
595
+ -----------------------------------------------------------------
596
+ EOF
597
+ } else {
598
+ print REP <<'EOF';
599
+
600
+ -----------------------------------------------------------------
601
+ <!--[Please describe your issue here]-->
602
+
603
+ **Description**
604
+ <!-- A clear and concise description of what the bug is. -->
605
+
606
+
607
+
608
+ **Steps to Reproduce**
609
+ <!-- A one-liner or script to reproduce the issue. -->
610
+
611
+
612
+
613
+ **Expected behavior**
614
+ <!-- A clear and concise description of what you expected to happen. -->
615
+
616
+
617
+
618
+ <!--[Please do not change anything below this line]-->
619
+ <!------------------------------------------------------------------- -->
620
+ EOF
621
+ }
622
+ }
623
+ Dump(*REP);
624
+ close(REP) or die "Error closing report file: $!";
625
+
626
+ # Set up an initial report fingerprint so we can compare it later
627
+ _fingerprint_lines_in_report();
628
+
629
+ } # sub Query
630
+
631
+ sub Dump {
632
+ local(*OUT) = @_;
633
+
634
+ # these won't have been set if run with -d
635
+ $category ||= 'core';
636
+ $severity ||= 'low';
637
+
638
+ print OUT <<EFF;
639
+
640
+
641
+ ---
642
+ **Flags**
643
+ - category=$category
644
+ - severity=$severity
645
+ EFF
646
+
647
+ if ($has_patch) {
648
+ print OUT <<EFF;
649
+ - Type=Patch
650
+ - PatchStatus=HasPatch
651
+ EFF
652
+ }
653
+
654
+ if ($report_about_module ) {
655
+ print OUT <<EFF;
656
+ - module=$report_about_module
657
+ EFF
658
+ }
659
+ print OUT <<EFF;
660
+ ---
661
+ **Perl configuration**
662
+ ```
663
+ EFF
664
+ print OUT "This perlbug was built using Perl $config_tag1\n",
665
+ "It is being executed now by Perl $config_tag2.\n\n"
666
+ if $config_tag2 ne $config_tag1;
667
+
668
+ print OUT <<EOF;
669
+ Site configuration information for perl $perl_version:
670
+
671
+ EOF
672
+ if ($::Config{cf_by} and $::Config{cf_time}) {
673
+ print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
674
+ }
675
+ print OUT Config::myconfig;
676
+
677
+ if (@patches) {
678
+ print OUT join "\n ", "Locally applied patches:", @patches;
679
+ print OUT "\n";
680
+ };
681
+
682
+ print OUT <<EOF;
683
+
684
+ ---
685
+ \@INC for perl $perl_version:
686
+ EOF
687
+ for my $i (@INC) {
688
+ print OUT " $i\n";
689
+ }
690
+
691
+ print OUT <<EOF;
692
+
693
+ ---
694
+ Environment for perl $perl_version:
695
+ EOF
696
+ my @env =
697
+ qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
698
+ push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
699
+ push @env, grep /^(?:PERL|LC_|LANG|CYGWIN|MSYS)/, keys %ENV;
700
+ my %env;
701
+ @env{@env} = @env;
702
+ for my $env (sort keys %env) {
703
+ print OUT " $env",
704
+ exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
705
+ "\n";
706
+ }
707
+ if ($verbose) {
708
+ print OUT "\nComplete configuration data for perl $perl_version:\n\n";
709
+ my $value;
710
+ foreach (sort keys %::Config) {
711
+ $value = $::Config{$_};
712
+ $value = '' unless defined $value;
713
+ $value =~ s/'/\\'/g;
714
+ print OUT "$_='$value'\n";
715
+ }
716
+ }
717
+ print OUT "```\n";
718
+ } # sub Dump
719
+
720
+ sub Edit {
721
+ # Edit the report
722
+ if ($usefile || $body) {
723
+ my $description = "Please make sure that the name of the editor you want to use is correct.";
724
+ my $entry = _prompt($description, 'Editor', $ed);
725
+ $ed = $entry unless $entry eq '';
726
+ }
727
+
728
+ _edit_file($ed) unless $running_noninteractively;
729
+ }
730
+
731
+ sub _edit_file {
732
+ my $editor = shift;
733
+
734
+ my $report_written = 0;
735
+
736
+ while ( !$report_written ) {
737
+ my $exit_status = system("$editor $filename");
738
+ if ($exit_status) {
739
+ my $desc = <<EOF;
740
+ The editor you chose ('$editor') could not be run!
741
+
742
+ If you mistyped its name, please enter it now, otherwise just press Enter.
743
+ EOF
744
+ my $entry = _prompt( $desc, 'Editor', $editor );
745
+ if ( $entry ne "" ) {
746
+ $editor = $entry;
747
+ next;
748
+ } else {
749
+ paraprint <<EOF;
750
+ You can edit your report after saving it to a file.
751
+ EOF
752
+ return;
753
+ }
754
+ }
755
+ return if ( $ok and not $opt{n} ) || $body;
756
+
757
+ # Check that we have a report that has some, eh, report in it.
758
+
759
+ unless ( _fingerprint_lines_in_report() ) {
760
+ my $description = <<EOF;
761
+ It looks like you didn't enter a report. You may [r]etry your edit
762
+ or [c]ancel this report.
763
+ EOF
764
+ my $action = _prompt( $description, "Action (Retry/Cancel) " );
765
+ if ( $action =~ /^[re]/i ) { # <R>etry <E>dit
766
+ next;
767
+ } elsif ( $action =~ /^[cq]/i ) { # <C>ancel, <Q>uit
768
+ Cancel(); # cancel exits
769
+ }
770
+ }
771
+ # Ok. the user did what they needed to;
772
+ return;
773
+
774
+ }
775
+ }
776
+
777
+
778
+ sub Cancel {
779
+ 1 while unlink($filename); # remove all versions under VMS
780
+ print "\nQuitting without generating a report.\n";
781
+ exit(0);
782
+ }
783
+
784
+ sub NowWhat {
785
+ # Report is done, prompt for further action
786
+ if( !$opt{S} ) {
787
+ while(1) {
788
+ my $send_to = $address || 'the Perl developers';
789
+ my $menu = <<EOF;
790
+
791
+
792
+ You have finished composing your report. At this point, you have
793
+ a few options. You can:
794
+
795
+ * Save the report to a [f]ile
796
+ * [Se]nd the report to $send_to$andcc
797
+ * [D]isplay the report on the screen
798
+ * [R]e-edit the report
799
+ * Display or change the report's [su]bject
800
+ * [Q]uit without generating the report
801
+
802
+ EOF
803
+ retry:
804
+ print $menu;
805
+ my $action = _prompt('', "Action (Save/Send/Display/Edit/Subject/Quit)",
806
+ $opt{t} ? 'q' : '');
807
+ print "\n";
808
+ if ($action =~ /^(f|sa)/i) { # <F>ile/<Sa>ve
809
+ if ( SaveMessage() ) { exit }
810
+ } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
811
+ # Display the message
812
+ print _read_report($filename);
813
+ if ($have_attachment) {
814
+ print "\n\n---\nAttachment(s):\n";
815
+ for my $att (split /\s*,\s*/, $attachments) { print " $att\n"; }
816
+ }
817
+ } elsif ($action =~ /^su/i) { # <Su>bject
818
+ my $reply = _prompt( "Subject: $subject", "If the above subject is fine, press Enter. Otherwise, type a replacement now\nSubject");
819
+ if ($reply ne '') {
820
+ unless (TrivialSubject($reply)) {
821
+ $subject = $reply;
822
+ print "Subject: $subject\n";
823
+ }
824
+ }
825
+ } elsif ($action =~ /^se/i) { # <S>end
826
+ # Send the message
827
+ if (not $thanks) {
828
+ print <<EOF
829
+ To ensure your issue can be best tracked and resolved,
830
+ you should submit it to the GitHub issue tracker at
831
+ https://github.com/Perl/perl5/issues
832
+ EOF
833
+ }
834
+ my $reply = _prompt( "Are you certain you want to send this report to $send_to$andcc?", 'Please type "yes" if you are','no');
835
+ if ($reply =~ /^yes$/) {
836
+ $address ||= 'perl5-porters@perl.org';
837
+ last;
838
+ } else {
839
+ paraprint <<EOF;
840
+ You didn't type "yes", so your report has not been sent.
841
+ EOF
842
+ }
843
+ } elsif ($action =~ /^[er]/i) { # <E>dit, <R>e-edit
844
+ # edit the message
845
+ Edit();
846
+ } elsif ($action =~ /^[qc]/i) { # <C>ancel, <Q>uit
847
+ Cancel();
848
+ } elsif ($action =~ /^s/i) {
849
+ paraprint <<EOF;
850
+ The command you entered was ambiguous. Please type "send", "save" or "subject".
851
+ EOF
852
+ }
853
+ }
854
+ }
855
+ } # sub NowWhat
856
+
857
+ sub TrivialSubject {
858
+ my $subject = shift;
859
+ if ($subject =~
860
+ /^(y(es)?|no?|help|perl( (bug|problem))?|bug|problem)$/i ||
861
+ length($subject) < 4 ||
862
+ ($subject !~ /\s/ && ! $opt{t})) { # non-whitespace is accepted in test mode
863
+ print "\nThe subject you entered wasn't very descriptive. Please try again.\n\n";
864
+ return 1;
865
+ } else {
866
+ return 0;
867
+ }
868
+ }
869
+
870
+ sub SaveMessage {
871
+ my $file = _prompt( '', "Name of file to save report in", $outfile );
872
+ save_message_to_disk($file) || return undef;
873
+ return 1;
874
+ }
875
+
876
+ sub Send {
877
+
878
+ # Message has been accepted for transmission -- Send the message
879
+
880
+ # on linux certain "mail" implementations won't accept the subject
881
+ # as "~s subject" and thus the Subject header will be corrupted
882
+ # so don't use Mail::Send to be safe
883
+ eval {
884
+ if ( $::HaveSend && !$Is_Linux && !$Is_OpenBSD ) {
885
+ _send_message_mailsend();
886
+ } elsif ($Is_VMS) {
887
+ _send_message_vms();
888
+ } else {
889
+ _send_message_sendmail();
890
+ }
891
+ };
892
+
893
+ if ( my $error = $@ ) {
894
+ paraprint <<EOF;
895
+ $0 has detected an error while trying to send your message: $error.
896
+
897
+ Your message may not have been sent. You will now have a chance to save a copy to disk.
898
+ EOF
899
+ SaveMessage();
900
+ return;
901
+ }
902
+
903
+ 1 while unlink($filename); # remove all versions under VMS
904
+ } # sub Send
905
+
906
+ sub Help {
907
+ print <<EOF;
908
+
909
+ This program is designed to help you generate bug reports
910
+ (and thank-you notes) about perl5 and the modules which ship with it.
911
+
912
+ In most cases, you can just run "$0" interactively from a command
913
+ line without any special arguments and follow the prompts.
914
+
915
+ Advanced usage:
916
+
917
+ $0 [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
918
+ [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
919
+ [-p patchfile ]
920
+ $0 [-v] [-r returnaddress] [-ok | -okay | -nok | -nokay]
921
+
922
+
923
+ Options:
924
+
925
+ -v Include Verbose configuration data in the report
926
+ -f File containing the body of the report. Use this to
927
+ quickly send a prepared report.
928
+ -p File containing a patch or other text attachment. Separate
929
+ multiple files with commas.
930
+ -F File to output the resulting report to. Defaults to
931
+ '$outfile'.
932
+ -S Save or send the report without asking for confirmation.
933
+ -a Send the report to this address, instead of saving to a file.
934
+ -c Address to send copy of report to. Defaults to '$cc'.
935
+ -C Don't send copy to administrator.
936
+ -s Subject to include with the report. You will be prompted
937
+ if you don't supply one on the command line.
938
+ -b Body of the report. If not included on the command line, or
939
+ in a file with -f, you will get a chance to edit the report.
940
+ -r Your return address. The program will ask you to confirm
941
+ this if you don't give it here.
942
+ -e Editor to use.
943
+ -t Test mode.
944
+ -T Thank-you mode. The target address defaults to '$thanksaddress'.
945
+ -d Data mode. This prints out your configuration data, without mailing
946
+ anything. You can use this with -v to get more complete data.
947
+ -ok Report successful build on this system to perl porters
948
+ (use alone or with -v). Only use -ok if *everything* was ok:
949
+ if there were *any* problems at all, use -nok.
950
+ -okay As -ok but allow report from old builds.
951
+ -nok Report unsuccessful build on this system to perl porters
952
+ (use alone or with -v). You must describe what went wrong
953
+ in the body of the report which you will be asked to edit.
954
+ -nokay As -nok but allow report from old builds.
955
+ -h Print this help message.
956
+
957
+ EOF
958
+ }
959
+
960
+ sub filename {
961
+ if ($::HaveTemp) {
962
+ # Good. Use a secure temp file
963
+ my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1);
964
+ close($fh);
965
+ return $filename;
966
+ } else {
967
+ # Bah. Fall back to doing things less securely.
968
+ my $dir = File::Spec->tmpdir();
969
+ $filename = "bugrep0$$";
970
+ $filename++ while -e File::Spec->catfile($dir, $filename);
971
+ $filename = File::Spec->catfile($dir, $filename);
972
+ }
973
+ }
974
+
975
+ sub paraprint {
976
+ my @paragraphs = split /\n{2,}/, "@_";
977
+ for (@paragraphs) { # implicit local $_
978
+ s/(\S)\s*\n/$1 /g;
979
+ write;
980
+ print "\n";
981
+ }
982
+ }
983
+
984
+ sub _prompt {
985
+ my ($explanation, $prompt, $default) = (@_);
986
+ if ($explanation) {
987
+ print "\n\n";
988
+ paraprint $explanation;
989
+ }
990
+ print $prompt. ($default ? " [$default]" :''). ": ";
991
+ my $result = scalar(<>);
992
+ return $default if !defined $result; # got eof
993
+ chomp($result);
994
+ $result =~ s/^\s*(.*?)\s*$/$1/s;
995
+ if ($default && $result eq '') {
996
+ return $default;
997
+ } else {
998
+ return $result;
999
+ }
1000
+ }
1001
+
1002
+ sub _build_header {
1003
+ my %attr = (@_);
1004
+
1005
+ my $head = '';
1006
+ for my $header (keys %attr) {
1007
+ $head .= "$header: ".$attr{$header}."\n";
1008
+ }
1009
+ return $head;
1010
+ }
1011
+
1012
+ sub _message_headers {
1013
+ my %headers = ( To => $address || 'perl5-porters@perl.org', Subject => $subject );
1014
+ $headers{'Cc'} = $cc if ($cc);
1015
+ $headers{'Message-Id'} = $messageid if ($messageid);
1016
+ $headers{'Reply-To'} = $from if ($from);
1017
+ $headers{'From'} = $from if ($from);
1018
+ if ($have_attachment) {
1019
+ $headers{'MIME-Version'} = '1.0';
1020
+ $headers{'Content-Type'} = qq{multipart/mixed; boundary=\"$mime_boundary\"};
1021
+ }
1022
+ return \%headers;
1023
+ }
1024
+
1025
+ sub _add_body_start {
1026
+ my $body_start = <<"BODY_START";
1027
+ This is a multi-part message in MIME format.
1028
+ --$mime_boundary
1029
+ Content-Type: text/plain; format=fixed
1030
+ Content-Transfer-Encoding: 8bit
1031
+
1032
+ BODY_START
1033
+ return $body_start;
1034
+ }
1035
+
1036
+ sub _add_attachments {
1037
+ my $attach = '';
1038
+ for my $attachment (split /\s*,\s*/, $attachments) {
1039
+ my $attach_file = basename($attachment);
1040
+ $attach .= <<"ATTACHMENT";
1041
+
1042
+ --$mime_boundary
1043
+ Content-Type: text/x-patch; name="$attach_file"
1044
+ Content-Transfer-Encoding: 8bit
1045
+ Content-Disposition: attachment; filename="$attach_file"
1046
+
1047
+ ATTACHMENT
1048
+
1049
+ open my $attach_fh, '<:raw', $attachment
1050
+ or die "Couldn't open attachment '$attachment': $!\n";
1051
+ while (<$attach_fh>) { $attach .= $_; }
1052
+ close($attach_fh) or die "Error closing attachment '$attachment': $!";
1053
+ }
1054
+
1055
+ $attach .= "\n--$mime_boundary--\n";
1056
+ return $attach;
1057
+ }
1058
+
1059
+ sub _read_report {
1060
+ my $fname = shift;
1061
+ my $content;
1062
+ open( REP, "<:raw", $fname ) or die "Couldn't open file '$fname': $!\n";
1063
+ binmode(REP, ':raw :crlf') if $Is_MSWin32;
1064
+ # wrap long lines to make sure the report gets delivered
1065
+ local $Text::Wrap::columns = 900;
1066
+ local $Text::Wrap::huge = 'overflow';
1067
+ while (<REP>) {
1068
+ if ($::HaveWrap && /\S/) { # wrap() would remove empty lines
1069
+ $content .= Text::Wrap::wrap(undef, undef, $_);
1070
+ } else {
1071
+ $content .= $_;
1072
+ }
1073
+ }
1074
+ close(REP) or die "Error closing report file '$fname': $!";
1075
+ return $content;
1076
+ }
1077
+
1078
+ sub build_complete_message {
1079
+ my $content = _build_header(%{_message_headers()}) . "\n\n";
1080
+ $content .= _add_body_start() if $have_attachment;
1081
+ $content .= _read_report($filename);
1082
+ $content .= _add_attachments() if $have_attachment;
1083
+ return $content;
1084
+ }
1085
+
1086
+ sub save_message_to_disk {
1087
+ my $file = shift;
1088
+
1089
+ if (-e $file) {
1090
+ my $response = _prompt( '', "Overwrite existing '$file'", 'n' );
1091
+ return undef unless $response =~ / yes | y /xi;
1092
+ }
1093
+ open OUTFILE, '>:raw', $file or do { warn "Couldn't open '$file': $!\n"; return undef};
1094
+ binmode(OUTFILE, ':raw :crlf') if $Is_MSWin32;
1095
+
1096
+ print OUTFILE build_complete_message();
1097
+ close(OUTFILE) or do { warn "Error closing $file: $!"; return undef };
1098
+ print "\nReport saved to '$file'. Please submit it to https://github.com/Perl/perl5/issues\n";
1099
+ return 1;
1100
+ }
1101
+
1102
+ sub _send_message_vms {
1103
+
1104
+ my $mail_from = $from;
1105
+ my $rcpt_to_to = $address;
1106
+ my $rcpt_to_cc = $cc;
1107
+
1108
+ map { $_ =~ s/^[^<]*<//;
1109
+ $_ =~ s/>[^>]*//; } ($mail_from, $rcpt_to_to, $rcpt_to_cc);
1110
+
1111
+ if ( open my $sff_fh, '|-:raw', 'MCR TCPIP$SYSTEM:TCPIP$SMTP_SFF.EXE SYS$INPUT:' ) {
1112
+ print $sff_fh "MAIL FROM:<$mail_from>\n";
1113
+ print $sff_fh "RCPT TO:<$rcpt_to_to>\n";
1114
+ print $sff_fh "RCPT TO:<$rcpt_to_cc>\n" if $rcpt_to_cc;
1115
+ print $sff_fh "DATA\n";
1116
+ print $sff_fh build_complete_message();
1117
+ my $success = close $sff_fh;
1118
+ if ($success ) {
1119
+ print "\nMessage sent\n";
1120
+ return;
1121
+ }
1122
+ }
1123
+ die "Mail transport failed (leaving bug report in $filename): $^E\n";
1124
+ }
1125
+
1126
+ sub _send_message_mailsend {
1127
+ my $msg = Mail::Send->new();
1128
+ my %headers = %{_message_headers()};
1129
+ for my $key ( keys %headers) {
1130
+ $msg->add($key => $headers{$key});
1131
+ }
1132
+
1133
+ $fh = $msg->open;
1134
+ binmode($fh, ':raw');
1135
+ print $fh _add_body_start() if $have_attachment;
1136
+ print $fh _read_report($filename);
1137
+ print $fh _add_attachments() if $have_attachment;
1138
+ $fh->close or die "Error sending mail: $!";
1139
+
1140
+ print "\nMessage sent.\n";
1141
+ }
1142
+
1143
+ sub _probe_for_sendmail {
1144
+ my $sendmail = "";
1145
+ for (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail)) {
1146
+ $sendmail = $_, last if -e $_;
1147
+ }
1148
+ if ( $^O eq 'os2' and $sendmail eq "" ) {
1149
+ my $path = $ENV{PATH};
1150
+ $path =~ s:\\:/:;
1151
+ my @path = split /$Config{'path_sep'}/, $path;
1152
+ for (@path) {
1153
+ $sendmail = "$_/sendmail", last if -e "$_/sendmail";
1154
+ $sendmail = "$_/sendmail.exe", last if -e "$_/sendmail.exe";
1155
+ }
1156
+ }
1157
+ return $sendmail;
1158
+ }
1159
+
1160
+ sub _send_message_sendmail {
1161
+ my $sendmail = _probe_for_sendmail();
1162
+ unless ($sendmail) {
1163
+ my $message_start = !$Is_Linux && !$Is_OpenBSD ? <<'EOT' : <<'EOT';
1164
+ It appears that there is no program which looks like "sendmail" on
1165
+ your system and that the Mail::Send library from CPAN isn't available.
1166
+ EOT
1167
+ It appears that there is no program which looks like "sendmail" on
1168
+ your system.
1169
+ EOT
1170
+ paraprint(<<"EOF"), die "\n";
1171
+ $message_start
1172
+ Because of this, there's no easy way to automatically send your
1173
+ report.
1174
+
1175
+ A copy of your report has been saved in '$filename' for you to
1176
+ send to '$address' with your normal mail client.
1177
+ EOF
1178
+ }
1179
+
1180
+ open( SENDMAIL, "|-:raw", $sendmail, "-t", "-oi", "-f", $from )
1181
+ || die "'|$sendmail -t -oi -f $from' failed: $!";
1182
+ print SENDMAIL build_complete_message();
1183
+ if ( close(SENDMAIL) ) {
1184
+ print "\nMessage sent\n";
1185
+ } else {
1186
+ warn "\nSendmail returned status '", $? >> 8, "'\n";
1187
+ }
1188
+ }
1189
+
1190
+
1191
+
1192
+ # a strange way to check whether any significant editing
1193
+ # has been done: check whether any new non-empty lines
1194
+ # have been added.
1195
+
1196
+ sub _fingerprint_lines_in_report {
1197
+ my $new_lines = 0;
1198
+ # read in the report template once so that
1199
+ # we can track whether the user does any editing.
1200
+ # yes, *all* whitespace is ignored.
1201
+
1202
+ open(REP, '<:raw', $filename) or die "Unable to open report file '$filename': $!\n";
1203
+ binmode(REP, ':raw :crlf') if $Is_MSWin32;
1204
+ while (my $line = <REP>) {
1205
+ $line =~ s/\s+//g;
1206
+ $new_lines++ if (!$REP{$line});
1207
+
1208
+ }
1209
+ close(REP) or die "Error closing report file '$filename': $!";
1210
+ # returns the number of lines with content that wasn't there when last we looked
1211
+ return $new_lines;
1212
+ }
1213
+
1214
+
1215
+
1216
+ format STDOUT =
1217
+ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
1218
+ $_
1219
+ .
1220
+
1221
+ __END__
1222
+
1223
+ =head1 NAME
1224
+
1225
+ perlbug - how to submit bug reports on Perl
1226
+
1227
+ =head1 SYNOPSIS
1228
+
1229
+ B<perlbug>
1230
+
1231
+ B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
1232
+ S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
1233
+ S<[ B<-r> I<returnaddress> ]>
1234
+ S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
1235
+ S<[ B<-S> ]> S<[ B<-t> ]> S<[ B<-d> ]> S<[ B<-h> ]> S<[ B<-T> ]>
1236
+
1237
+ B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]>
1238
+ S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
1239
+
1240
+ B<perlthanks>
1241
+
1242
+ =head1 DESCRIPTION
1243
+
1244
+
1245
+ This program is designed to help you generate bug reports
1246
+ (and thank-you notes) about perl5 and the modules which ship with it.
1247
+
1248
+ In most cases, you can just run it interactively from a command
1249
+ line without any special arguments and follow the prompts.
1250
+
1251
+ If you have found a bug with a non-standard port (one that was not
1252
+ part of the I<standard distribution>), a binary distribution, or a
1253
+ non-core module (such as Tk, DBI, etc), then please see the
1254
+ documentation that came with that distribution to determine the
1255
+ correct place to report bugs.
1256
+
1257
+ Bug reports should be submitted to the GitHub issue tracker at
1258
+ L<https://github.com/Perl/perl5/issues>. The B<perlbug@perl.org>
1259
+ address no longer automatically opens tickets. You can use this tool
1260
+ to compose your report and save it to a file which you can then submit
1261
+ to the issue tracker.
1262
+
1263
+ In extreme cases, B<perlbug> may not work well enough on your system
1264
+ to guide you through composing a bug report. In those cases, you
1265
+ may be able to use B<perlbug -d> or B<perl -V> to get system
1266
+ configuration information to include in your issue report.
1267
+
1268
+
1269
+ When reporting a bug, please run through this checklist:
1270
+
1271
+ =over 4
1272
+
1273
+ =item What version of Perl you are running?
1274
+
1275
+ Type C<perl -v> at the command line to find out.
1276
+
1277
+ =item Are you running the latest released version of perl?
1278
+
1279
+ Look at L<http://www.perl.org/> to find out. If you are not using the
1280
+ latest released version, please try to replicate your bug on the
1281
+ latest stable release.
1282
+
1283
+ Note that reports about bugs in old versions of Perl, especially
1284
+ those which indicate you haven't also tested the current stable
1285
+ release of Perl, are likely to receive less attention from the
1286
+ volunteers who build and maintain Perl than reports about bugs in
1287
+ the current release.
1288
+
1289
+ =item Are you sure what you have is a bug?
1290
+
1291
+ A significant number of the bug reports we get turn out to be
1292
+ documented features in Perl. Make sure the issue you've run into
1293
+ isn't intentional by glancing through the documentation that comes
1294
+ with the Perl distribution.
1295
+
1296
+ Given the sheer volume of Perl documentation, this isn't a trivial
1297
+ undertaking, but if you can point to documentation that suggests
1298
+ the behaviour you're seeing is I<wrong>, your issue is likely to
1299
+ receive more attention. You may want to start with B<perldoc>
1300
+ L<perltrap> for pointers to common traps that new (and experienced)
1301
+ Perl programmers run into.
1302
+
1303
+ If you're unsure of the meaning of an error message you've run
1304
+ across, B<perldoc> L<perldiag> for an explanation. If the message
1305
+ isn't in perldiag, it probably isn't generated by Perl. You may
1306
+ have luck consulting your operating system documentation instead.
1307
+
1308
+ If you are on a non-UNIX platform B<perldoc> L<perlport>, as some
1309
+ features may be unimplemented or work differently.
1310
+
1311
+ You may be able to figure out what's going wrong using the Perl
1312
+ debugger. For information about how to use the debugger B<perldoc>
1313
+ L<perldebug>.
1314
+
1315
+ =item Do you have a proper test case?
1316
+
1317
+ The easier it is to reproduce your bug, the more likely it will be
1318
+ fixed -- if nobody can duplicate your problem, it probably won't be
1319
+ addressed.
1320
+
1321
+ A good test case has most of these attributes: short, simple code;
1322
+ few dependencies on external commands, modules, or libraries; no
1323
+ platform-dependent code (unless it's a platform-specific bug);
1324
+ clear, simple documentation.
1325
+
1326
+ A good test case is almost always a good candidate to be included in
1327
+ Perl's test suite. If you have the time, consider writing your test case so
1328
+ that it can be easily included into the standard test suite.
1329
+
1330
+ =item Have you included all relevant information?
1331
+
1332
+ Be sure to include the B<exact> error messages, if any.
1333
+ "Perl gave an error" is not an exact error message.
1334
+
1335
+ If you get a core dump (or equivalent), you may use a debugger
1336
+ (B<dbx>, B<gdb>, etc) to produce a stack trace to include in the bug
1337
+ report.
1338
+
1339
+ NOTE: unless your Perl has been compiled with debug info
1340
+ (often B<-g>), the stack trace is likely to be somewhat hard to use
1341
+ because it will most probably contain only the function names and not
1342
+ their arguments. If possible, recompile your Perl with debug info and
1343
+ reproduce the crash and the stack trace.
1344
+
1345
+ =item Can you describe the bug in plain English?
1346
+
1347
+ The easier it is to understand a reproducible bug, the more likely
1348
+ it will be fixed. Any insight you can provide into the problem
1349
+ will help a great deal. In other words, try to analyze the problem
1350
+ (to the extent you can) and report your discoveries.
1351
+
1352
+ =item Can you fix the bug yourself?
1353
+
1354
+ If so, that's great news; bug reports with patches are likely to
1355
+ receive significantly more attention and interest than those without
1356
+ patches. Please submit your patch via the GitHub Pull Request workflow
1357
+ as described in B<perldoc> L<perlhack>. You may also send patches to
1358
+ B<perl5-porters@perl.org>. When sending a patch, create it using
1359
+ C<git format-patch> if possible, though a unified diff created with
1360
+ C<diff -pu> will do nearly as well.
1361
+
1362
+ Your patch may be returned with requests for changes, or requests for more
1363
+ detailed explanations about your fix.
1364
+
1365
+ Here are a few hints for creating high-quality patches:
1366
+
1367
+ Make sure the patch is not reversed (the first argument to diff is
1368
+ typically the original file, the second argument your changed file).
1369
+ Make sure you test your patch by applying it with C<git am> or the
1370
+ C<patch> program before you send it on its way. Try to follow the
1371
+ same style as the code you are trying to patch. Make sure your patch
1372
+ really does work (C<make test>, if the thing you're patching is covered
1373
+ by Perl's test suite).
1374
+
1375
+ =item Can you use C<perlbug> to submit a thank-you note?
1376
+
1377
+ Yes, you can do this by either using the C<-T> option, or by invoking
1378
+ the program as C<perlthanks>. Thank-you notes are good. It makes people
1379
+ smile.
1380
+
1381
+ =back
1382
+
1383
+ Please make your issue title informative. "a bug" is not informative.
1384
+ Neither is "perl crashes" nor is "HELP!!!". These don't help. A compact
1385
+ description of what's wrong is fine.
1386
+
1387
+ Having done your bit, please be prepared to wait, to be told the
1388
+ bug is in your code, or possibly to get no reply at all. The
1389
+ volunteers who maintain Perl are busy folks, so if your problem is
1390
+ an obvious bug in your own code, is difficult to understand or is
1391
+ a duplicate of an existing report, you may not receive a personal
1392
+ reply.
1393
+
1394
+ If it is important to you that your bug be fixed, do monitor the
1395
+ issue tracker (you will be subscribed to notifications for issues you
1396
+ submit or comment on) and the commit logs to development
1397
+ versions of Perl, and encourage the maintainers with kind words or
1398
+ offers of frosty beverages. (Please do be kind to the maintainers.
1399
+ Harassing or flaming them is likely to have the opposite effect of the
1400
+ one you want.)
1401
+
1402
+ Feel free to update the ticket about your bug on
1403
+ L<https://github.com/Perl/perl5/issues>
1404
+ if a new version of Perl is released and your bug is still present.
1405
+
1406
+ =head1 OPTIONS
1407
+
1408
+ =over 8
1409
+
1410
+ =item B<-a>
1411
+
1412
+ Address to send the report to instead of saving to a file.
1413
+
1414
+ =item B<-b>
1415
+
1416
+ Body of the report. If not included on the command line, or
1417
+ in a file with B<-f>, you will get a chance to edit the report.
1418
+
1419
+ =item B<-C>
1420
+
1421
+ Don't send copy to administrator when sending report by mail.
1422
+
1423
+ =item B<-c>
1424
+
1425
+ Address to send copy of report to when sending report by mail.
1426
+ Defaults to the address of the
1427
+ local perl administrator (recorded when perl was built).
1428
+
1429
+ =item B<-d>
1430
+
1431
+ Data mode (the default if you redirect or pipe output). This prints out
1432
+ your configuration data, without saving or mailing anything. You can use
1433
+ this with B<-v> to get more complete data.
1434
+
1435
+ =item B<-e>
1436
+
1437
+ Editor to use.
1438
+
1439
+ =item B<-f>
1440
+
1441
+ File containing the body of the report. Use this to quickly send a
1442
+ prepared report.
1443
+
1444
+ =item B<-F>
1445
+
1446
+ File to output the results to. Defaults to B<perlbug.rep>.
1447
+
1448
+ =item B<-h>
1449
+
1450
+ Prints a brief summary of the options.
1451
+
1452
+ =item B<-ok>
1453
+
1454
+ Report successful build on this system to perl porters. Forces B<-S>
1455
+ and B<-C>. Forces and supplies values for B<-s> and B<-b>. Only
1456
+ prompts for a return address if it cannot guess it (for use with
1457
+ B<make>). Honors return address specified with B<-r>. You can use this
1458
+ with B<-v> to get more complete data. Only makes a report if this
1459
+ system is less than 60 days old.
1460
+
1461
+ =item B<-okay>
1462
+
1463
+ As B<-ok> except it will report on older systems.
1464
+
1465
+ =item B<-nok>
1466
+
1467
+ Report unsuccessful build on this system. Forces B<-C>. Forces and
1468
+ supplies a value for B<-s>, then requires you to edit the report
1469
+ and say what went wrong. Alternatively, a prepared report may be
1470
+ supplied using B<-f>. Only prompts for a return address if it
1471
+ cannot guess it (for use with B<make>). Honors return address
1472
+ specified with B<-r>. You can use this with B<-v> to get more
1473
+ complete data. Only makes a report if this system is less than 60
1474
+ days old.
1475
+
1476
+ =item B<-nokay>
1477
+
1478
+ As B<-nok> except it will report on older systems.
1479
+
1480
+ =item B<-p>
1481
+
1482
+ The names of one or more patch files or other text attachments to be
1483
+ included with the report. Multiple files must be separated with commas.
1484
+
1485
+ =item B<-r>
1486
+
1487
+ Your return address. The program will ask you to confirm its default
1488
+ if you don't use this option.
1489
+
1490
+ =item B<-S>
1491
+
1492
+ Save or send the report without asking for confirmation.
1493
+
1494
+ =item B<-s>
1495
+
1496
+ Subject to include with the report. You will be prompted if you don't
1497
+ supply one on the command line.
1498
+
1499
+ =item B<-t>
1500
+
1501
+ Test mode. Makes it possible to command perlbug from a pipe or file, for
1502
+ testing purposes.
1503
+
1504
+ =item B<-T>
1505
+
1506
+ Send a thank-you note instead of a bug report.
1507
+
1508
+ =item B<-v>
1509
+
1510
+ Include verbose configuration data in the report.
1511
+
1512
+ =back
1513
+
1514
+ =head1 AUTHORS
1515
+
1516
+ Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently
1517
+ I<doc>tored by Gurusamy Sarathy (E<lt>gsar@activestate.comE<gt>),
1518
+ Tom Christiansen (E<lt>tchrist@perl.comE<gt>), Nathan Torkington
1519
+ (E<lt>gnat@frii.comE<gt>), Charles F. Randall (E<lt>cfr@pobox.comE<gt>),
1520
+ Mike Guy (E<lt>mjtg@cam.ac.ukE<gt>), Dominic Dunlop
1521
+ (E<lt>domo@computer.orgE<gt>), Hugo van der Sanden (E<lt>hv@crypt.orgE<gt>),
1522
+ Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), Chris Nandor
1523
+ (E<lt>pudge@pobox.comE<gt>), Jon Orwant (E<lt>orwant@media.mit.eduE<gt>,
1524
+ Richard Foley (E<lt>richard.foley@rfi.netE<gt>), Jesse Vincent
1525
+ (E<lt>jesse@bestpractical.comE<gt>), and Craig A. Berry (E<lt>craigberry@mac.comE<gt>).
1526
+
1527
+ =head1 SEE ALSO
1528
+
1529
+ perl(1), perldebug(1), perldiag(1), perlport(1), perltrap(1),
1530
+ diff(1), patch(1), dbx(1), gdb(1)
1531
+
1532
+ =head1 BUGS
1533
+
1534
+ None known (guess what must have been used to report them?)
1535
+
1536
+ =cut
1537
+
git/usr/bin/core_perl/perlivp ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ # perlivp v5.42.2
6
+
7
+ BEGIN { pop @INC if $INC[-1] eq '.' }
8
+
9
+ sub usage {
10
+ warn "@_\n" if @_;
11
+ print << " EOUSAGE";
12
+ Usage:
13
+
14
+ $0 [-p] [-v] | [-h]
15
+
16
+ -p Print a preface before each test telling what it will test.
17
+ -v Verbose mode in which extra information about test results
18
+ is printed. Test failures always print out some extra information
19
+ regardless of whether or not this switch is set.
20
+ -h Prints this help message.
21
+ EOUSAGE
22
+ exit;
23
+ }
24
+
25
+ use vars qw(%opt); # allow testing with older versions (do not use our)
26
+
27
+ @opt{ qw/? H h P p V v/ } = qw(0 0 0 0 0 0 0);
28
+
29
+ while ($ARGV[0] =~ /^-/) {
30
+ $ARGV[0] =~ s/^-//;
31
+ for my $flag (split(//,$ARGV[0])) {
32
+ usage() if '?' =~ /\Q$flag/;
33
+ usage() if 'h' =~ /\Q$flag/;
34
+ usage() if 'H' =~ /\Q$flag/;
35
+ usage("unknown flag: '$flag'") unless 'HhPpVv' =~ /\Q$flag/;
36
+ warn "$0: '$flag' flag already set\n" if $opt{$flag}++;
37
+ }
38
+ shift;
39
+ }
40
+
41
+ $opt{p}++ if $opt{P};
42
+ $opt{v}++ if $opt{V};
43
+
44
+ my $pass__total = 0;
45
+ my $error_total = 0;
46
+ my $tests_total = 0;
47
+
48
+ my $perlpath = '/usr/bin/perl';
49
+ my $useithreads = 'define';
50
+
51
+ print "## Checking Perl binary via variable '\$perlpath' = $perlpath.\n" if $opt{'p'};
52
+
53
+ my $label = 'Executable perl binary';
54
+
55
+ if (-x $perlpath) {
56
+ print "## Perl binary '$perlpath' appears executable.\n" if $opt{'v'};
57
+ print "ok 1 $label\n";
58
+ $pass__total++;
59
+ }
60
+ else {
61
+ print "# Perl binary '$perlpath' does not appear executable.\n";
62
+ print "not ok 1 $label\n";
63
+ $error_total++;
64
+ }
65
+ $tests_total++;
66
+
67
+
68
+ print "## Checking Perl version via variable '\$]'.\n" if $opt{'p'};
69
+
70
+ my $ivp_VERSION = "5.042002";
71
+
72
+
73
+ $label = 'Perl version correct';
74
+ if ($ivp_VERSION eq $]) {
75
+ print "## Perl version '$]' appears installed as expected.\n" if $opt{'v'};
76
+ print "ok 2 $label\n";
77
+ $pass__total++;
78
+ }
79
+ else {
80
+ print "# Perl version '$]' installed, expected $ivp_VERSION.\n";
81
+ print "not ok 2 $label\n";
82
+ $error_total++;
83
+ }
84
+ $tests_total++;
85
+
86
+ # We have the right perl and version, so now reset @INC so we ignore
87
+ # PERL5LIB and '.'
88
+ {
89
+ local $ENV{PERL5LIB};
90
+ my $perl_V = qx($perlpath -V);
91
+ $perl_V =~ s{.*\@INC:\n}{}ms;
92
+ @INC = grep { length && $_ ne '.' } split ' ', $perl_V;
93
+ }
94
+
95
+ print "## Checking roots of the Perl library directory tree via variable '\@INC'.\n" if $opt{'p'};
96
+
97
+ my $INC_total = 0;
98
+ my $INC_there = 0;
99
+ foreach (@INC) {
100
+ next if $_ eq '.'; # skip -d test here
101
+ if (-d $_) {
102
+ print "## Perl \@INC directory '$_' exists.\n" if $opt{'v'};
103
+ $INC_there++;
104
+ }
105
+ else {
106
+ print "# Perl \@INC directory '$_' does not appear to exist.\n";
107
+ }
108
+ $INC_total++;
109
+ }
110
+
111
+ $label = '@INC directories exist';
112
+ if ($INC_total == $INC_there) {
113
+ print "ok 3 $label\n";
114
+ $pass__total++;
115
+ }
116
+ else {
117
+ print "not ok 3 $label\n";
118
+ $error_total++;
119
+ }
120
+ $tests_total++;
121
+
122
+
123
+ print "## Checking installations of modules necessary for ivp.\n" if $opt{'p'};
124
+
125
+ my $needed_total = 0;
126
+ my $needed_there = 0;
127
+ foreach (qw(Config.pm ExtUtils/Installed.pm)) {
128
+ $@ = undef;
129
+ $needed_total++;
130
+ eval "require \"$_\";";
131
+ if (!$@) {
132
+ print "## Module '$_' appears to be installed.\n" if $opt{'v'};
133
+ $needed_there++;
134
+ }
135
+ else {
136
+ print "# Needed module '$_' does not appear to be properly installed.\n";
137
+ }
138
+ $@ = undef;
139
+ }
140
+ $label = 'Modules needed for rest of perlivp exist';
141
+ if ($needed_total == $needed_there) {
142
+ print "ok 4 $label\n";
143
+ $pass__total++;
144
+ }
145
+ else {
146
+ print "not ok 4 $label\n";
147
+ $error_total++;
148
+ }
149
+ $tests_total++;
150
+
151
+
152
+ print "## Checking installations of extensions built with perl.\n" if $opt{'p'};
153
+
154
+ use Config;
155
+
156
+ my $extensions_total = 0;
157
+ my $extensions_there = 0;
158
+ if (defined($Config{'extensions'})) {
159
+ my @extensions = split(/\s+/,$Config{'extensions'});
160
+ foreach (@extensions) {
161
+ next if ($_ eq '');
162
+ if ( $useithreads !~ /define/i ) {
163
+ next if ($_ eq 'threads');
164
+ next if ($_ eq 'threads/shared');
165
+ }
166
+ # that's a distribution name, not a module name
167
+ next if $_ eq 'IO/Compress';
168
+ next if $_ eq 'Devel/DProf';
169
+ next if $_ eq 'libnet';
170
+ next if $_ eq 'Locale/Codes';
171
+ next if $_ eq 'podlators';
172
+ next if $_ eq 'perlfaq';
173
+ # test modules
174
+ next if $_ eq 'XS/APItest';
175
+ next if $_ eq 'XS/Typemap';
176
+ # VMS$ perl -e "eval ""require \""Devel/DProf.pm\"";"" print $@"
177
+ # \NT> perl -e "eval \"require './Devel/DProf.pm'\"; print $@"
178
+ # DProf: run perl with -d to use DProf.
179
+ # Compilation failed in require at (eval 1) line 1.
180
+ eval " require \"$_.pm\"; ";
181
+ if (!$@) {
182
+ print "## Module '$_' appears to be installed.\n" if $opt{'v'};
183
+ $extensions_there++;
184
+ }
185
+ else {
186
+ print "# Required module '$_' does not appear to be properly installed.\n";
187
+ $@ = undef;
188
+ }
189
+ $extensions_total++;
190
+ }
191
+
192
+ # A silly name for a module (that hopefully won't ever exist).
193
+ # Note that this test serves more as a check of the validity of the
194
+ # actual required module tests above.
195
+ my $unnecessary = 'bLuRfle';
196
+
197
+ if (!grep(/$unnecessary/, @extensions)) {
198
+ $@ = undef;
199
+ eval " require \"$unnecessary.pm\"; ";
200
+ if ($@) {
201
+ print "## Unnecessary module '$unnecessary' does not appear to be installed.\n" if $opt{'v'};
202
+ }
203
+ else {
204
+ print "# Unnecessary module '$unnecessary' appears to be installed.\n";
205
+ $extensions_there++;
206
+ }
207
+ }
208
+ $@ = undef;
209
+ }
210
+ $label = 'All (and only) expected extensions installed';
211
+ if ($extensions_total == $extensions_there) {
212
+ print "ok 5 $label\n";
213
+ $pass__total++;
214
+ }
215
+ else {
216
+ print "not ok 5 $label\n";
217
+ $error_total++;
218
+ }
219
+ $tests_total++;
220
+
221
+
222
+ print "## Checking installations of later additional extensions.\n" if $opt{'p'};
223
+
224
+ use ExtUtils::Installed;
225
+
226
+ my $installed_total = 0;
227
+ my $installed_there = 0;
228
+ my $version_check = 0;
229
+ my $installed = ExtUtils::Installed -> new();
230
+ my @modules = $installed -> modules();
231
+ my @missing = ();
232
+ my $version = undef;
233
+ for (@modules) {
234
+ $installed_total++;
235
+ # Consider it there if it contains one or more files,
236
+ # and has zero missing files,
237
+ # and has a defined version
238
+ $version = undef;
239
+ $version = $installed -> version($_);
240
+ if ($version) {
241
+ print "## $_; $version\n" if $opt{'v'};
242
+ $version_check++;
243
+ }
244
+ else {
245
+ print "# $_; NO VERSION\n" if $opt{'v'};
246
+ }
247
+ $version = undef;
248
+ @missing = ();
249
+ @missing = $installed -> validate($_);
250
+
251
+ # .bs files are optional
252
+ @missing = grep { ! /\.bs$/ } @missing;
253
+ # man files are often compressed
254
+ @missing = grep { ! ( -s "$_.gz" || -s "$_.bz2" ) } @missing;
255
+
256
+ if ($#missing >= 0) {
257
+ print "# file",+($#missing == 0) ? '' : 's'," missing from installation:\n";
258
+ print '# ',join(' ',@missing),"\n";
259
+ }
260
+ elsif ($#missing == -1) {
261
+ $installed_there++;
262
+ }
263
+ @missing = ();
264
+ }
265
+ $label = 'Module files correctly installed';
266
+ if (($installed_total == $installed_there) &&
267
+ ($installed_total == $version_check)) {
268
+ print "ok 6 $label\n";
269
+ $pass__total++;
270
+ }
271
+ else {
272
+ print "not ok 6 $label\n";
273
+ $error_total++;
274
+ }
275
+ $tests_total++;
276
+
277
+ # Final report (rather than feed ousrselves to Test::Harness::runtests()
278
+ # we simply format some output on our own to keep things simple and
279
+ # easier to "fix" - at least for now.
280
+
281
+ if ($error_total == 0 && $tests_total) {
282
+ print "All tests successful.\n";
283
+ } elsif ($tests_total==0){
284
+ die "FAILED--no tests were run for some reason.\n";
285
+ } else {
286
+ my $rate = 0.0;
287
+ if ($tests_total > 0) { $rate = sprintf "%.2f", 100.0 * ($pass__total / $tests_total); }
288
+ printf " %d/%d subtests failed, %.2f%% okay.\n",
289
+ $error_total, $tests_total, $rate;
290
+ }
291
+
292
+ =head1 NAME
293
+
294
+ perlivp - Perl Installation Verification Procedure
295
+
296
+ =head1 SYNOPSIS
297
+
298
+ B<perlivp> [B<-p>] [B<-v>] [B<-h>]
299
+
300
+ =head1 DESCRIPTION
301
+
302
+ The B<perlivp> program is set up at Perl source code build time to test the
303
+ Perl version it was built under. It can be used after running:
304
+
305
+ make install
306
+
307
+ (or your platform's equivalent procedure) to verify that B<perl> and its
308
+ libraries have been installed correctly. A correct installation is verified
309
+ by output that looks like:
310
+
311
+ ok 1
312
+ ok 2
313
+
314
+ etc.
315
+
316
+ =head1 OPTIONS
317
+
318
+ =over 5
319
+
320
+ =item B<-h> help
321
+
322
+ Prints out a brief help message.
323
+
324
+ =item B<-p> print preface
325
+
326
+ Gives a description of each test prior to performing it.
327
+
328
+ =item B<-v> verbose
329
+
330
+ Gives more detailed information about each test, after it has been performed.
331
+ Note that any failed tests ought to print out some extra information whether
332
+ or not -v is thrown.
333
+
334
+ =back
335
+
336
+ =head1 DIAGNOSTICS
337
+
338
+ =over 4
339
+
340
+ =item * print "# Perl binary '$perlpath' does not appear executable.\n";
341
+
342
+ Likely to occur for a perl binary that was not properly installed.
343
+ Correct by conducting a proper installation.
344
+
345
+ =item * print "# Perl version '$]' installed, expected $ivp_VERSION.\n";
346
+
347
+ Likely to occur for a perl that was not properly installed.
348
+ Correct by conducting a proper installation.
349
+
350
+ =item * print "# Perl \@INC directory '$_' does not appear to exist.\n";
351
+
352
+ Likely to occur for a perl library tree that was not properly installed.
353
+ Correct by conducting a proper installation.
354
+
355
+ =item * print "# Needed module '$_' does not appear to be properly installed.\n";
356
+
357
+ One of the two modules that is used by perlivp was not present in the
358
+ installation. This is a serious error since it adversely affects perlivp's
359
+ ability to function. You may be able to correct this by performing a
360
+ proper perl installation.
361
+
362
+ =item * print "# Required module '$_' does not appear to be properly installed.\n";
363
+
364
+ An attempt to C<eval "require $module"> failed, even though the list of
365
+ extensions indicated that it should succeed. Correct by conducting a proper
366
+ installation.
367
+
368
+ =item * print "# Unnecessary module 'bLuRfle' appears to be installed.\n";
369
+
370
+ This test not coming out ok could indicate that you have in fact installed
371
+ a bLuRfle.pm module or that the C<eval " require \"$module_name.pm\"; ">
372
+ test may give misleading results with your installation of perl. If yours
373
+ is the latter case then please let the author know.
374
+
375
+ =item * print "# file",+($#missing == 0) ? '' : 's'," missing from installation:\n";
376
+
377
+ One or more files turned up missing according to a run of
378
+ C<ExtUtils::Installed -E<gt> validate()> over your installation.
379
+ Correct by conducting a proper installation.
380
+
381
+ =back
382
+
383
+ For further information on how to conduct a proper installation consult the
384
+ INSTALL file that comes with the perl source and the README file for your
385
+ platform.
386
+
387
+ =head1 AUTHOR
388
+
389
+ Peter Prymmer
390
+
391
+ =cut
392
+
git/usr/bin/core_perl/perlthanks ADDED
@@ -0,0 +1,1537 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ my $config_tag1 = '5.42.2 - Thu Apr 2 19:54:57 UTC 2026';
6
+
7
+ my $patchlevel_date = 1774202317;
8
+ my @patches = Config::local_patches();
9
+ my $patch_tags = join "", map /(\S+)/ ? "+$1 " : (), @patches;
10
+
11
+ BEGIN { pop @INC if $INC[-1] eq '.' }
12
+ use warnings;
13
+ use strict;
14
+ use Config;
15
+ use File::Spec; # keep perlbug Perl 5.005 compatible
16
+ use Getopt::Std;
17
+ use File::Basename 'basename';
18
+
19
+ $Getopt::Std::STANDARD_HELP_VERSION = 1;
20
+
21
+ sub paraprint;
22
+
23
+ BEGIN {
24
+ eval { require Mail::Send;};
25
+ $::HaveSend = ($@ eq "");
26
+ eval { require Mail::Util; } ;
27
+ $::HaveUtil = (!$ENV{PERL_BUILD_PACKAGING} and $@ eq "");
28
+ # use secure tempfiles wherever possible
29
+ eval { require File::Temp; };
30
+ $::HaveTemp = ($@ eq "");
31
+ eval { require Module::CoreList; };
32
+ $::HaveCoreList = ($@ eq "");
33
+ eval { require Text::Wrap; };
34
+ $::HaveWrap = ($@ eq "");
35
+ };
36
+
37
+ our $VERSION = "1.43";
38
+
39
+ #TODO:
40
+ # make sure failure (transmission-wise) of Mail::Send is accounted for.
41
+ # (This may work now. Unsure of the original author's issue -JESSE 2008-06-08)
42
+ # - Test -b option
43
+
44
+ my( $file, $usefile, $cc, $address, $thanksaddress,
45
+ $filename, $messageid, $domain, $subject, $from, $verbose, $ed, $outfile,
46
+ $fh, $me, $body, $andcc, %REP, $ok, $thanks, $progname,
47
+ $Is_MSWin32, $Is_Linux, $Is_VMS, $Is_OpenBSD,
48
+ $report_about_module, $category, $severity,
49
+ %opt, $have_attachment, $attachments, $has_patch, $mime_boundary
50
+ );
51
+
52
+ my $running_noninteractively = !-t STDIN;
53
+
54
+ my $perl_version = $^V ? sprintf("%vd", $^V) : $];
55
+
56
+ my $config_tag2 = "$perl_version - $Config{cf_time}";
57
+
58
+ Init();
59
+
60
+ if ($opt{h}) { Help(); exit; }
61
+ if ($opt{d}) { Dump(*STDOUT); exit; }
62
+ if ($running_noninteractively && !$opt{t} && !($ok and not $opt{n})) {
63
+ paraprint <<"EOF";
64
+ Please use $progname interactively. If you want to
65
+ include a file, you can use the -f switch.
66
+ EOF
67
+ die "\n";
68
+ }
69
+
70
+ Query();
71
+ Edit() unless $usefile || ($ok and not $opt{n});
72
+ NowWhat();
73
+ if ($address) {
74
+ Send();
75
+ if ($thanks) {
76
+ print "\nThank you for taking the time to send a thank-you message!\n\n";
77
+
78
+ paraprint <<EOF
79
+ Please note that mailing lists are moderated, your message may take a while to
80
+ show up.
81
+ EOF
82
+ } else {
83
+ print "\nThank you for taking the time to file a bug report!\n\n";
84
+
85
+ paraprint <<EOF
86
+ Please note that mailing lists are moderated, your message may take a while to
87
+ show up. Please consider submitting your report directly to the issue tracker
88
+ at https://github.com/Perl/perl5/issues
89
+ EOF
90
+ }
91
+
92
+ } else {
93
+ save_message_to_disk($outfile);
94
+ }
95
+
96
+ exit;
97
+
98
+ sub ask_for_alternatives { # (category|severity)
99
+ my $name = shift;
100
+ my %alts = (
101
+ 'category' => {
102
+ 'default' => 'core',
103
+ 'ok' => 'install',
104
+ # Inevitably some of these will end up in RT whatever we do:
105
+ 'thanks' => 'thanks',
106
+ 'opts' => [qw(core docs install library utilities)], # patch, notabug
107
+ },
108
+ 'severity' => {
109
+ 'default' => 'low',
110
+ 'ok' => 'none',
111
+ 'thanks' => 'none',
112
+ 'opts' => [qw(critical high medium low wishlist none)], # zero
113
+ },
114
+ );
115
+ die "Invalid alternative ($name) requested\n" unless grep(/^$name$/, keys %alts);
116
+ my $alt = "";
117
+ my $what = $ok || $thanks;
118
+ if ($what) {
119
+ $alt = $alts{$name}{$what};
120
+ } else {
121
+ my @alts = @{$alts{$name}{'opts'}};
122
+ print "\n\n";
123
+ paraprint <<EOF;
124
+ Please pick a $name from the following list:
125
+
126
+ @alts
127
+ EOF
128
+ my $err = 0;
129
+ do {
130
+ if ($err++ > 5) {
131
+ die "Invalid $name: aborting.\n";
132
+ }
133
+ $alt = _prompt('', "\u$name", $alts{$name}{'default'});
134
+ $alt ||= $alts{$name}{'default'};
135
+ } while !((($alt) = grep(/^$alt/i, @alts)));
136
+ }
137
+ lc $alt;
138
+ }
139
+
140
+ sub HELP_MESSAGE { Help(); exit; }
141
+ sub VERSION_MESSAGE { print "perlbug version $VERSION\n"; }
142
+
143
+ sub Init {
144
+ # -------- Setup --------
145
+
146
+ $Is_MSWin32 = $^O eq 'MSWin32';
147
+ $Is_VMS = $^O eq 'VMS';
148
+ $Is_Linux = lc($^O) eq 'linux';
149
+ $Is_OpenBSD = lc($^O) eq 'openbsd';
150
+
151
+ # Thanks address
152
+ $thanksaddress = 'perl-thanks@perl.org';
153
+
154
+ # Defaults if getopts fails.
155
+ $outfile = (basename($0) =~ /^perlthanks/i) ? "perlthanks.rep" : "perlbug.rep";
156
+ $cc = $::Config{'perladmin'} || $::Config{'cf_email'} || $::Config{'cf_by'} || '';
157
+
158
+ HELP_MESSAGE() unless getopts("Adhva:s:b:f:F:r:e:SCc:to:n:T:p:", \%opt);
159
+
160
+ # This comment is needed to notify metaconfig that we are
161
+ # using the $perladmin, $cf_by, and $cf_time definitions.
162
+ # -------- Configuration ---------
163
+
164
+ if (basename ($0) =~ /^perlthanks/i) {
165
+ # invoked as perlthanks
166
+ $opt{T} = 1;
167
+ $opt{C} = 1; # don't send a copy to the local admin
168
+ }
169
+
170
+ if ($opt{T}) {
171
+ $thanks = 'thanks';
172
+ }
173
+
174
+ $progname = $thanks ? 'perlthanks' : 'perlbug';
175
+ # Target address
176
+ $address = $opt{a} || ($thanks ? $thanksaddress : "");
177
+
178
+ # Users address, used in message and in From and Reply-To headers
179
+ $from = $opt{r} || "";
180
+
181
+ # Include verbose configuration information
182
+ $verbose = $opt{v} || 0;
183
+
184
+ # Subject of bug-report message
185
+ $subject = $opt{s} || "";
186
+
187
+ # Send a file
188
+ $usefile = ($opt{f} || 0);
189
+
190
+ # File to send as report
191
+ $file = $opt{f} || "";
192
+
193
+ # We have one or more attachments
194
+ $have_attachment = ($opt{p} || 0);
195
+ $mime_boundary = ('-' x 12) . "$VERSION.perlbug" if $have_attachment;
196
+
197
+ # Comma-separated list of attachments
198
+ $attachments = $opt{p} || "";
199
+ $has_patch = 0; # TBD based on file type
200
+
201
+ for my $attachment (split /\s*,\s*/, $attachments) {
202
+ unless (-f $attachment && -r $attachment) {
203
+ die "The attachment $attachment is not a readable file: $!\n";
204
+ }
205
+ $has_patch = 1 if $attachment =~ m/\.(patch|diff)$/;
206
+ }
207
+
208
+ # File to output to
209
+ $outfile = $opt{F} || "$progname.rep";
210
+
211
+ # Body of report
212
+ $body = $opt{b} || "";
213
+
214
+ # Editor
215
+ $ed = $opt{e} || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
216
+ || ($Is_VMS && "edit/tpu")
217
+ || ($Is_MSWin32 && "notepad")
218
+ || "vi";
219
+
220
+ # Not OK - provide build failure template by finessing OK report
221
+ if ($opt{n}) {
222
+ if (substr($opt{n}, 0, 2) eq 'ok' ) {
223
+ $opt{o} = substr($opt{n}, 1);
224
+ } else {
225
+ Help();
226
+ exit();
227
+ }
228
+ }
229
+
230
+ # OK - send "OK" report for build on this system
231
+ $ok = '';
232
+ if ($opt{o}) {
233
+ if ($opt{o} eq 'k' or $opt{o} eq 'kay') {
234
+ my $age = time - $patchlevel_date;
235
+ if ($opt{o} eq 'k' and $age > 60 * 24 * 60 * 60 ) {
236
+ my $date = localtime $patchlevel_date;
237
+ print <<"EOF";
238
+ "perlbug -ok" and "perlbug -nok" do not report on Perl versions which
239
+ are more than 60 days old. This Perl version was constructed on
240
+ $date. If you really want to report this, use
241
+ "perlbug -okay" or "perlbug -nokay".
242
+ EOF
243
+ exit();
244
+ }
245
+ # force these options
246
+ unless ($opt{n}) {
247
+ $opt{S} = 1; # don't prompt for send
248
+ $opt{b} = 1; # we have a body
249
+ $body = "Perl reported to build OK on this system.\n";
250
+ }
251
+ $opt{C} = 1; # don't send a copy to the local admin
252
+ $opt{s} = 1; # we have a subject line
253
+ $subject = ($opt{n} ? 'Not ' : '')
254
+ . "OK: perl $perl_version ${patch_tags}on"
255
+ ." $::Config{'archname'} $::Config{'osvers'} $subject";
256
+ $ok = 'ok';
257
+ } else {
258
+ Help();
259
+ exit();
260
+ }
261
+ }
262
+
263
+ # Possible administrator addresses, in order of confidence
264
+ # (Note that cf_email is not mentioned to metaconfig, since
265
+ # we don't really want it. We'll just take it if we have to.)
266
+ #
267
+ # This has to be after the $ok stuff above because of the way
268
+ # that $opt{C} is forced.
269
+ $cc = $opt{C} ? "" : (
270
+ $opt{c} || $::Config{'perladmin'}
271
+ || $::Config{'cf_email'} || $::Config{'cf_by'}
272
+ );
273
+
274
+ if ($::HaveUtil) {
275
+ $domain = Mail::Util::maildomain();
276
+ } elsif ($Is_MSWin32) {
277
+ $domain = $ENV{'USERDOMAIN'};
278
+ } else {
279
+ require Sys::Hostname;
280
+ $domain = Sys::Hostname::hostname();
281
+ }
282
+
283
+ # Message-Id - rjsf
284
+ $messageid = "<$::Config{'version'}_${$}_".time."\@$domain>";
285
+
286
+ # My username
287
+ $me = $Is_MSWin32 ? $ENV{'USERNAME'}
288
+ : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
289
+ : eval { getpwuid($<) }; # May be missing
290
+
291
+ $from = $::Config{'cf_email'}
292
+ if !$from && $::Config{'cf_email'} && $::Config{'cf_by'} && $me &&
293
+ ($me eq $::Config{'cf_by'});
294
+ } # sub Init
295
+
296
+ sub Query {
297
+ # Explain what perlbug is
298
+ unless ($ok) {
299
+ if ($thanks) {
300
+ paraprint <<'EOF';
301
+ This program provides an easy way to send a thank-you message back to the
302
+ authors and maintainers of perl.
303
+
304
+ If you wish to generate a bug report, please run it without the -T flag
305
+ (or run the program perlbug rather than perlthanks)
306
+ EOF
307
+ } else {
308
+ paraprint <<"EOF";
309
+ This program provides an easy way to generate a bug report for the core
310
+ perl distribution (along with tests or patches). To send a thank-you
311
+ note to $thanksaddress instead of a bug report, please run 'perlthanks'.
312
+
313
+ The GitHub issue tracker at https://github.com/Perl/perl5/issues is the
314
+ best place to submit your report so it can be tracked and resolved.
315
+
316
+ Please do not use $0 to report bugs in perl modules from CPAN.
317
+
318
+ Suggestions for how to find help using Perl can be found at
319
+ https://perldoc.perl.org/perlcommunity.html
320
+ EOF
321
+ }
322
+ }
323
+
324
+ # Prompt for subject of message, if needed
325
+
326
+ if ($subject && TrivialSubject($subject)) {
327
+ $subject = '';
328
+ }
329
+
330
+ unless ($subject) {
331
+ print
332
+ "First of all, please provide a subject for the report.\n";
333
+ if ( not $thanks) {
334
+ paraprint <<EOF;
335
+ This should be a concise description of your bug or problem
336
+ which will help the volunteers working to improve perl to categorize
337
+ and resolve the issue. Be as specific and descriptive as
338
+ you can. A subject like "perl bug" or "perl problem" will make it
339
+ much less likely that your issue gets the attention it deserves.
340
+ EOF
341
+ }
342
+
343
+ my $err = 0;
344
+ do {
345
+ $subject = _prompt('','Subject');
346
+ if ($err++ == 5) {
347
+ if ($thanks) {
348
+ $subject = 'Thanks for Perl';
349
+ } else {
350
+ die "Aborting.\n";
351
+ }
352
+ }
353
+ } while (TrivialSubject($subject));
354
+ }
355
+ $subject = '[PATCH] ' . $subject
356
+ if $has_patch && ($subject !~ m/^\[PATCH/i);
357
+
358
+ # Prompt for return address, if needed
359
+ unless ($opt{r}) {
360
+ # Try and guess return address
361
+ my $guess;
362
+
363
+ $guess = $ENV{'REPLY-TO'} || $ENV{'REPLYTO'} || $ENV{'EMAIL'}
364
+ || $from || '';
365
+
366
+ unless ($guess) {
367
+ # move $domain to where we can use it elsewhere
368
+ if ($domain) {
369
+ if ($Is_VMS && !$::Config{'d_socket'}) {
370
+ $guess = "$domain\:\:$me";
371
+ } else {
372
+ $guess = "$me\@$domain" if $domain;
373
+ }
374
+ }
375
+ }
376
+
377
+ if ($guess) {
378
+ unless ($ok) {
379
+ paraprint <<EOF;
380
+ Perl's developers may need your email address to contact you for
381
+ further information about your issue or to inform you when it is
382
+ resolved. If the default shown is not your email address, please
383
+ correct it.
384
+ EOF
385
+ }
386
+ } else {
387
+ paraprint <<EOF;
388
+ Please enter your full internet email address so that Perl's
389
+ developers can contact you with questions about your issue or to
390
+ inform you that it has been resolved.
391
+ EOF
392
+ }
393
+
394
+ if ($ok && $guess) {
395
+ # use it
396
+ $from = $guess;
397
+ } else {
398
+ # verify it
399
+ $from = _prompt('','Your address',$guess);
400
+ $from = $guess if $from eq '';
401
+ }
402
+ }
403
+
404
+ if ($from eq $cc or $me eq $cc) {
405
+ # Try not to copy ourselves
406
+ $cc = "yourself";
407
+ }
408
+
409
+ # Prompt for administrator address, unless an override was given
410
+ if( $address and !$opt{C} and !$opt{c} ) {
411
+ my $description = <<EOF;
412
+ $0 can send a copy of this report to your local perl
413
+ administrator. If the address below is wrong, please correct it,
414
+ or enter 'none' or 'yourself' to not send a copy.
415
+ EOF
416
+ my $entry = _prompt($description, "Local perl administrator", $cc);
417
+
418
+ if ($entry ne "") {
419
+ $cc = $entry;
420
+ $cc = '' if $me eq $cc;
421
+ }
422
+ }
423
+
424
+ $cc = '' if $cc =~ /^(none|yourself|me|myself|ourselves)$/i;
425
+ if ($cc) {
426
+ $andcc = " and $cc"
427
+ } else {
428
+ $andcc = ''
429
+ }
430
+
431
+ # Prompt for editor, if no override is given
432
+ editor:
433
+ unless ($opt{e} || $opt{f} || $opt{b}) {
434
+
435
+ my $description;
436
+
437
+ chomp (my $common_end = <<"EOF");
438
+ You will probably want to use a text editor to enter the body of
439
+ your report. If "$ed" is the editor you want to use, then just press
440
+ Enter, otherwise type in the name of the editor you would like to
441
+ use.
442
+
443
+ If you have already composed the body of your report, you may enter
444
+ "file", and $0 will prompt you to enter the name of the file
445
+ containing your report.
446
+ EOF
447
+
448
+ if ($thanks) {
449
+ $description = <<"EOF";
450
+ It's now time to compose your thank-you message.
451
+
452
+ Some information about your local perl configuration will automatically
453
+ be included at the end of your message, because we're curious about
454
+ the different ways that people build and use perl. If you'd rather
455
+ not share this information, you're welcome to delete it.
456
+
457
+ $common_end
458
+ EOF
459
+ } else {
460
+ $description = <<"EOF";
461
+ It's now time to compose your bug report. Try to make the report
462
+ concise but descriptive. Please include any detail which you think
463
+ might be relevant or might help the volunteers working to improve
464
+ perl. If you are reporting something that does not work as you think
465
+ it should, please try to include examples of the actual result and of
466
+ what you expected.
467
+
468
+ Some information about your local perl configuration will automatically
469
+ be included at the end of your report. If you are using an unusual
470
+ version of perl, it would be useful if you could confirm that you
471
+ can replicate the problem on a standard build of perl as well.
472
+
473
+ $common_end
474
+ EOF
475
+ }
476
+
477
+ my $entry = _prompt($description, "Editor", $ed);
478
+ $usefile = 0;
479
+ if ($entry eq "file") {
480
+ $usefile = 1;
481
+ } elsif ($entry ne "") {
482
+ $ed = $entry;
483
+ }
484
+ }
485
+ if ($::HaveCoreList && !$ok && !$thanks) {
486
+ my $description = <<EOF;
487
+ If your bug is about a Perl module rather than a core language
488
+ feature, please enter its name here. If it's not, just hit Enter
489
+ to skip this question.
490
+ EOF
491
+
492
+ my $entry = '';
493
+ while ($entry eq '') {
494
+ $entry = _prompt($description, 'Module');
495
+ my $first_release = Module::CoreList->first_release($entry);
496
+ if ($entry and not $first_release) {
497
+ paraprint <<EOF;
498
+ $entry is not a "core" Perl module. Please check that you entered
499
+ its name correctly. If it is correct, quit this program, try searching
500
+ for $entry on https://rt.cpan.org, and report your issue there.
501
+ EOF
502
+
503
+ $entry = '';
504
+ } elsif (my $bug_tracker = $Module::CoreList::bug_tracker{$entry}) {
505
+ paraprint <<"EOF";
506
+ $entry included with core Perl is copied directly from the CPAN distribution.
507
+ Please report bugs in $entry directly to its maintainers using $bug_tracker
508
+ EOF
509
+ $entry = '';
510
+ } elsif ($entry) {
511
+ $category ||= 'library';
512
+ $report_about_module = $entry;
513
+ last;
514
+ } else {
515
+ last;
516
+ }
517
+ }
518
+ }
519
+
520
+ # Prompt for category of bug
521
+ $category ||= ask_for_alternatives('category');
522
+
523
+ # Prompt for severity of bug
524
+ $severity ||= ask_for_alternatives('severity');
525
+
526
+ # Generate scratch file to edit report in
527
+ $filename = filename();
528
+
529
+ # Prompt for file to read report from, if needed
530
+ if ($usefile and !$file) {
531
+ filename:
532
+ my $description = <<EOF;
533
+ What is the name of the file that contains your report?
534
+ EOF
535
+ my $entry = _prompt($description, "Filename");
536
+
537
+ if ($entry eq "") {
538
+ paraprint <<EOF;
539
+ It seems you didn't enter a filename. Please choose to use a text
540
+ editor or enter a filename.
541
+ EOF
542
+ goto editor;
543
+ }
544
+
545
+ unless (-f $entry and -r $entry) {
546
+ paraprint <<EOF;
547
+ '$entry' doesn't seem to be a readable file. You may have mistyped
548
+ its name or may not have permission to read it.
549
+
550
+ If you don't want to use a file as the content of your report, just
551
+ hit Enter and you'll be able to select a text editor instead.
552
+ EOF
553
+ goto filename;
554
+ }
555
+ $file = $entry;
556
+ }
557
+
558
+ # Generate report
559
+ open(REP, '>:raw', $filename) or die "Unable to create report file '$filename': $!\n";
560
+ binmode(REP, ':raw :crlf') if $Is_MSWin32;
561
+
562
+ my $reptype = !$ok ? ($thanks ? 'thank-you' : 'bug')
563
+ : $opt{n} ? "build failure" : "success";
564
+
565
+ print REP <<EOF;
566
+ This is a $reptype report for perl from $from,
567
+ generated with the help of perlbug $VERSION running under perl $perl_version.
568
+
569
+ EOF
570
+
571
+ if ($report_about_module) {
572
+ print REP "Module: $report_about_module\n\n";
573
+ }
574
+
575
+ if ($body) {
576
+ print REP $body;
577
+ } elsif ($usefile) {
578
+ open(F, '<:raw', $file)
579
+ or die "Unable to read report file from '$file': $!\n";
580
+ binmode(F, ':raw :crlf') if $Is_MSWin32;
581
+ while (<F>) {
582
+ print REP $_
583
+ }
584
+ close(F) or die "Error closing '$file': $!";
585
+ } else {
586
+ if ($thanks) {
587
+ print REP <<'EOF';
588
+
589
+ -----------------------------------------------------------------
590
+ [Please enter your thank-you message here]
591
+
592
+
593
+
594
+ [You're welcome to delete anything below this line]
595
+ -----------------------------------------------------------------
596
+ EOF
597
+ } else {
598
+ print REP <<'EOF';
599
+
600
+ -----------------------------------------------------------------
601
+ <!--[Please describe your issue here]-->
602
+
603
+ **Description**
604
+ <!-- A clear and concise description of what the bug is. -->
605
+
606
+
607
+
608
+ **Steps to Reproduce**
609
+ <!-- A one-liner or script to reproduce the issue. -->
610
+
611
+
612
+
613
+ **Expected behavior**
614
+ <!-- A clear and concise description of what you expected to happen. -->
615
+
616
+
617
+
618
+ <!--[Please do not change anything below this line]-->
619
+ <!------------------------------------------------------------------- -->
620
+ EOF
621
+ }
622
+ }
623
+ Dump(*REP);
624
+ close(REP) or die "Error closing report file: $!";
625
+
626
+ # Set up an initial report fingerprint so we can compare it later
627
+ _fingerprint_lines_in_report();
628
+
629
+ } # sub Query
630
+
631
+ sub Dump {
632
+ local(*OUT) = @_;
633
+
634
+ # these won't have been set if run with -d
635
+ $category ||= 'core';
636
+ $severity ||= 'low';
637
+
638
+ print OUT <<EFF;
639
+
640
+
641
+ ---
642
+ **Flags**
643
+ - category=$category
644
+ - severity=$severity
645
+ EFF
646
+
647
+ if ($has_patch) {
648
+ print OUT <<EFF;
649
+ - Type=Patch
650
+ - PatchStatus=HasPatch
651
+ EFF
652
+ }
653
+
654
+ if ($report_about_module ) {
655
+ print OUT <<EFF;
656
+ - module=$report_about_module
657
+ EFF
658
+ }
659
+ print OUT <<EFF;
660
+ ---
661
+ **Perl configuration**
662
+ ```
663
+ EFF
664
+ print OUT "This perlbug was built using Perl $config_tag1\n",
665
+ "It is being executed now by Perl $config_tag2.\n\n"
666
+ if $config_tag2 ne $config_tag1;
667
+
668
+ print OUT <<EOF;
669
+ Site configuration information for perl $perl_version:
670
+
671
+ EOF
672
+ if ($::Config{cf_by} and $::Config{cf_time}) {
673
+ print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
674
+ }
675
+ print OUT Config::myconfig;
676
+
677
+ if (@patches) {
678
+ print OUT join "\n ", "Locally applied patches:", @patches;
679
+ print OUT "\n";
680
+ };
681
+
682
+ print OUT <<EOF;
683
+
684
+ ---
685
+ \@INC for perl $perl_version:
686
+ EOF
687
+ for my $i (@INC) {
688
+ print OUT " $i\n";
689
+ }
690
+
691
+ print OUT <<EOF;
692
+
693
+ ---
694
+ Environment for perl $perl_version:
695
+ EOF
696
+ my @env =
697
+ qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
698
+ push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
699
+ push @env, grep /^(?:PERL|LC_|LANG|CYGWIN|MSYS)/, keys %ENV;
700
+ my %env;
701
+ @env{@env} = @env;
702
+ for my $env (sort keys %env) {
703
+ print OUT " $env",
704
+ exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
705
+ "\n";
706
+ }
707
+ if ($verbose) {
708
+ print OUT "\nComplete configuration data for perl $perl_version:\n\n";
709
+ my $value;
710
+ foreach (sort keys %::Config) {
711
+ $value = $::Config{$_};
712
+ $value = '' unless defined $value;
713
+ $value =~ s/'/\\'/g;
714
+ print OUT "$_='$value'\n";
715
+ }
716
+ }
717
+ print OUT "```\n";
718
+ } # sub Dump
719
+
720
+ sub Edit {
721
+ # Edit the report
722
+ if ($usefile || $body) {
723
+ my $description = "Please make sure that the name of the editor you want to use is correct.";
724
+ my $entry = _prompt($description, 'Editor', $ed);
725
+ $ed = $entry unless $entry eq '';
726
+ }
727
+
728
+ _edit_file($ed) unless $running_noninteractively;
729
+ }
730
+
731
+ sub _edit_file {
732
+ my $editor = shift;
733
+
734
+ my $report_written = 0;
735
+
736
+ while ( !$report_written ) {
737
+ my $exit_status = system("$editor $filename");
738
+ if ($exit_status) {
739
+ my $desc = <<EOF;
740
+ The editor you chose ('$editor') could not be run!
741
+
742
+ If you mistyped its name, please enter it now, otherwise just press Enter.
743
+ EOF
744
+ my $entry = _prompt( $desc, 'Editor', $editor );
745
+ if ( $entry ne "" ) {
746
+ $editor = $entry;
747
+ next;
748
+ } else {
749
+ paraprint <<EOF;
750
+ You can edit your report after saving it to a file.
751
+ EOF
752
+ return;
753
+ }
754
+ }
755
+ return if ( $ok and not $opt{n} ) || $body;
756
+
757
+ # Check that we have a report that has some, eh, report in it.
758
+
759
+ unless ( _fingerprint_lines_in_report() ) {
760
+ my $description = <<EOF;
761
+ It looks like you didn't enter a report. You may [r]etry your edit
762
+ or [c]ancel this report.
763
+ EOF
764
+ my $action = _prompt( $description, "Action (Retry/Cancel) " );
765
+ if ( $action =~ /^[re]/i ) { # <R>etry <E>dit
766
+ next;
767
+ } elsif ( $action =~ /^[cq]/i ) { # <C>ancel, <Q>uit
768
+ Cancel(); # cancel exits
769
+ }
770
+ }
771
+ # Ok. the user did what they needed to;
772
+ return;
773
+
774
+ }
775
+ }
776
+
777
+
778
+ sub Cancel {
779
+ 1 while unlink($filename); # remove all versions under VMS
780
+ print "\nQuitting without generating a report.\n";
781
+ exit(0);
782
+ }
783
+
784
+ sub NowWhat {
785
+ # Report is done, prompt for further action
786
+ if( !$opt{S} ) {
787
+ while(1) {
788
+ my $send_to = $address || 'the Perl developers';
789
+ my $menu = <<EOF;
790
+
791
+
792
+ You have finished composing your report. At this point, you have
793
+ a few options. You can:
794
+
795
+ * Save the report to a [f]ile
796
+ * [Se]nd the report to $send_to$andcc
797
+ * [D]isplay the report on the screen
798
+ * [R]e-edit the report
799
+ * Display or change the report's [su]bject
800
+ * [Q]uit without generating the report
801
+
802
+ EOF
803
+ retry:
804
+ print $menu;
805
+ my $action = _prompt('', "Action (Save/Send/Display/Edit/Subject/Quit)",
806
+ $opt{t} ? 'q' : '');
807
+ print "\n";
808
+ if ($action =~ /^(f|sa)/i) { # <F>ile/<Sa>ve
809
+ if ( SaveMessage() ) { exit }
810
+ } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
811
+ # Display the message
812
+ print _read_report($filename);
813
+ if ($have_attachment) {
814
+ print "\n\n---\nAttachment(s):\n";
815
+ for my $att (split /\s*,\s*/, $attachments) { print " $att\n"; }
816
+ }
817
+ } elsif ($action =~ /^su/i) { # <Su>bject
818
+ my $reply = _prompt( "Subject: $subject", "If the above subject is fine, press Enter. Otherwise, type a replacement now\nSubject");
819
+ if ($reply ne '') {
820
+ unless (TrivialSubject($reply)) {
821
+ $subject = $reply;
822
+ print "Subject: $subject\n";
823
+ }
824
+ }
825
+ } elsif ($action =~ /^se/i) { # <S>end
826
+ # Send the message
827
+ if (not $thanks) {
828
+ print <<EOF
829
+ To ensure your issue can be best tracked and resolved,
830
+ you should submit it to the GitHub issue tracker at
831
+ https://github.com/Perl/perl5/issues
832
+ EOF
833
+ }
834
+ my $reply = _prompt( "Are you certain you want to send this report to $send_to$andcc?", 'Please type "yes" if you are','no');
835
+ if ($reply =~ /^yes$/) {
836
+ $address ||= 'perl5-porters@perl.org';
837
+ last;
838
+ } else {
839
+ paraprint <<EOF;
840
+ You didn't type "yes", so your report has not been sent.
841
+ EOF
842
+ }
843
+ } elsif ($action =~ /^[er]/i) { # <E>dit, <R>e-edit
844
+ # edit the message
845
+ Edit();
846
+ } elsif ($action =~ /^[qc]/i) { # <C>ancel, <Q>uit
847
+ Cancel();
848
+ } elsif ($action =~ /^s/i) {
849
+ paraprint <<EOF;
850
+ The command you entered was ambiguous. Please type "send", "save" or "subject".
851
+ EOF
852
+ }
853
+ }
854
+ }
855
+ } # sub NowWhat
856
+
857
+ sub TrivialSubject {
858
+ my $subject = shift;
859
+ if ($subject =~
860
+ /^(y(es)?|no?|help|perl( (bug|problem))?|bug|problem)$/i ||
861
+ length($subject) < 4 ||
862
+ ($subject !~ /\s/ && ! $opt{t})) { # non-whitespace is accepted in test mode
863
+ print "\nThe subject you entered wasn't very descriptive. Please try again.\n\n";
864
+ return 1;
865
+ } else {
866
+ return 0;
867
+ }
868
+ }
869
+
870
+ sub SaveMessage {
871
+ my $file = _prompt( '', "Name of file to save report in", $outfile );
872
+ save_message_to_disk($file) || return undef;
873
+ return 1;
874
+ }
875
+
876
+ sub Send {
877
+
878
+ # Message has been accepted for transmission -- Send the message
879
+
880
+ # on linux certain "mail" implementations won't accept the subject
881
+ # as "~s subject" and thus the Subject header will be corrupted
882
+ # so don't use Mail::Send to be safe
883
+ eval {
884
+ if ( $::HaveSend && !$Is_Linux && !$Is_OpenBSD ) {
885
+ _send_message_mailsend();
886
+ } elsif ($Is_VMS) {
887
+ _send_message_vms();
888
+ } else {
889
+ _send_message_sendmail();
890
+ }
891
+ };
892
+
893
+ if ( my $error = $@ ) {
894
+ paraprint <<EOF;
895
+ $0 has detected an error while trying to send your message: $error.
896
+
897
+ Your message may not have been sent. You will now have a chance to save a copy to disk.
898
+ EOF
899
+ SaveMessage();
900
+ return;
901
+ }
902
+
903
+ 1 while unlink($filename); # remove all versions under VMS
904
+ } # sub Send
905
+
906
+ sub Help {
907
+ print <<EOF;
908
+
909
+ This program is designed to help you generate bug reports
910
+ (and thank-you notes) about perl5 and the modules which ship with it.
911
+
912
+ In most cases, you can just run "$0" interactively from a command
913
+ line without any special arguments and follow the prompts.
914
+
915
+ Advanced usage:
916
+
917
+ $0 [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
918
+ [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
919
+ [-p patchfile ]
920
+ $0 [-v] [-r returnaddress] [-ok | -okay | -nok | -nokay]
921
+
922
+
923
+ Options:
924
+
925
+ -v Include Verbose configuration data in the report
926
+ -f File containing the body of the report. Use this to
927
+ quickly send a prepared report.
928
+ -p File containing a patch or other text attachment. Separate
929
+ multiple files with commas.
930
+ -F File to output the resulting report to. Defaults to
931
+ '$outfile'.
932
+ -S Save or send the report without asking for confirmation.
933
+ -a Send the report to this address, instead of saving to a file.
934
+ -c Address to send copy of report to. Defaults to '$cc'.
935
+ -C Don't send copy to administrator.
936
+ -s Subject to include with the report. You will be prompted
937
+ if you don't supply one on the command line.
938
+ -b Body of the report. If not included on the command line, or
939
+ in a file with -f, you will get a chance to edit the report.
940
+ -r Your return address. The program will ask you to confirm
941
+ this if you don't give it here.
942
+ -e Editor to use.
943
+ -t Test mode.
944
+ -T Thank-you mode. The target address defaults to '$thanksaddress'.
945
+ -d Data mode. This prints out your configuration data, without mailing
946
+ anything. You can use this with -v to get more complete data.
947
+ -ok Report successful build on this system to perl porters
948
+ (use alone or with -v). Only use -ok if *everything* was ok:
949
+ if there were *any* problems at all, use -nok.
950
+ -okay As -ok but allow report from old builds.
951
+ -nok Report unsuccessful build on this system to perl porters
952
+ (use alone or with -v). You must describe what went wrong
953
+ in the body of the report which you will be asked to edit.
954
+ -nokay As -nok but allow report from old builds.
955
+ -h Print this help message.
956
+
957
+ EOF
958
+ }
959
+
960
+ sub filename {
961
+ if ($::HaveTemp) {
962
+ # Good. Use a secure temp file
963
+ my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1);
964
+ close($fh);
965
+ return $filename;
966
+ } else {
967
+ # Bah. Fall back to doing things less securely.
968
+ my $dir = File::Spec->tmpdir();
969
+ $filename = "bugrep0$$";
970
+ $filename++ while -e File::Spec->catfile($dir, $filename);
971
+ $filename = File::Spec->catfile($dir, $filename);
972
+ }
973
+ }
974
+
975
+ sub paraprint {
976
+ my @paragraphs = split /\n{2,}/, "@_";
977
+ for (@paragraphs) { # implicit local $_
978
+ s/(\S)\s*\n/$1 /g;
979
+ write;
980
+ print "\n";
981
+ }
982
+ }
983
+
984
+ sub _prompt {
985
+ my ($explanation, $prompt, $default) = (@_);
986
+ if ($explanation) {
987
+ print "\n\n";
988
+ paraprint $explanation;
989
+ }
990
+ print $prompt. ($default ? " [$default]" :''). ": ";
991
+ my $result = scalar(<>);
992
+ return $default if !defined $result; # got eof
993
+ chomp($result);
994
+ $result =~ s/^\s*(.*?)\s*$/$1/s;
995
+ if ($default && $result eq '') {
996
+ return $default;
997
+ } else {
998
+ return $result;
999
+ }
1000
+ }
1001
+
1002
+ sub _build_header {
1003
+ my %attr = (@_);
1004
+
1005
+ my $head = '';
1006
+ for my $header (keys %attr) {
1007
+ $head .= "$header: ".$attr{$header}."\n";
1008
+ }
1009
+ return $head;
1010
+ }
1011
+
1012
+ sub _message_headers {
1013
+ my %headers = ( To => $address || 'perl5-porters@perl.org', Subject => $subject );
1014
+ $headers{'Cc'} = $cc if ($cc);
1015
+ $headers{'Message-Id'} = $messageid if ($messageid);
1016
+ $headers{'Reply-To'} = $from if ($from);
1017
+ $headers{'From'} = $from if ($from);
1018
+ if ($have_attachment) {
1019
+ $headers{'MIME-Version'} = '1.0';
1020
+ $headers{'Content-Type'} = qq{multipart/mixed; boundary=\"$mime_boundary\"};
1021
+ }
1022
+ return \%headers;
1023
+ }
1024
+
1025
+ sub _add_body_start {
1026
+ my $body_start = <<"BODY_START";
1027
+ This is a multi-part message in MIME format.
1028
+ --$mime_boundary
1029
+ Content-Type: text/plain; format=fixed
1030
+ Content-Transfer-Encoding: 8bit
1031
+
1032
+ BODY_START
1033
+ return $body_start;
1034
+ }
1035
+
1036
+ sub _add_attachments {
1037
+ my $attach = '';
1038
+ for my $attachment (split /\s*,\s*/, $attachments) {
1039
+ my $attach_file = basename($attachment);
1040
+ $attach .= <<"ATTACHMENT";
1041
+
1042
+ --$mime_boundary
1043
+ Content-Type: text/x-patch; name="$attach_file"
1044
+ Content-Transfer-Encoding: 8bit
1045
+ Content-Disposition: attachment; filename="$attach_file"
1046
+
1047
+ ATTACHMENT
1048
+
1049
+ open my $attach_fh, '<:raw', $attachment
1050
+ or die "Couldn't open attachment '$attachment': $!\n";
1051
+ while (<$attach_fh>) { $attach .= $_; }
1052
+ close($attach_fh) or die "Error closing attachment '$attachment': $!";
1053
+ }
1054
+
1055
+ $attach .= "\n--$mime_boundary--\n";
1056
+ return $attach;
1057
+ }
1058
+
1059
+ sub _read_report {
1060
+ my $fname = shift;
1061
+ my $content;
1062
+ open( REP, "<:raw", $fname ) or die "Couldn't open file '$fname': $!\n";
1063
+ binmode(REP, ':raw :crlf') if $Is_MSWin32;
1064
+ # wrap long lines to make sure the report gets delivered
1065
+ local $Text::Wrap::columns = 900;
1066
+ local $Text::Wrap::huge = 'overflow';
1067
+ while (<REP>) {
1068
+ if ($::HaveWrap && /\S/) { # wrap() would remove empty lines
1069
+ $content .= Text::Wrap::wrap(undef, undef, $_);
1070
+ } else {
1071
+ $content .= $_;
1072
+ }
1073
+ }
1074
+ close(REP) or die "Error closing report file '$fname': $!";
1075
+ return $content;
1076
+ }
1077
+
1078
+ sub build_complete_message {
1079
+ my $content = _build_header(%{_message_headers()}) . "\n\n";
1080
+ $content .= _add_body_start() if $have_attachment;
1081
+ $content .= _read_report($filename);
1082
+ $content .= _add_attachments() if $have_attachment;
1083
+ return $content;
1084
+ }
1085
+
1086
+ sub save_message_to_disk {
1087
+ my $file = shift;
1088
+
1089
+ if (-e $file) {
1090
+ my $response = _prompt( '', "Overwrite existing '$file'", 'n' );
1091
+ return undef unless $response =~ / yes | y /xi;
1092
+ }
1093
+ open OUTFILE, '>:raw', $file or do { warn "Couldn't open '$file': $!\n"; return undef};
1094
+ binmode(OUTFILE, ':raw :crlf') if $Is_MSWin32;
1095
+
1096
+ print OUTFILE build_complete_message();
1097
+ close(OUTFILE) or do { warn "Error closing $file: $!"; return undef };
1098
+ print "\nReport saved to '$file'. Please submit it to https://github.com/Perl/perl5/issues\n";
1099
+ return 1;
1100
+ }
1101
+
1102
+ sub _send_message_vms {
1103
+
1104
+ my $mail_from = $from;
1105
+ my $rcpt_to_to = $address;
1106
+ my $rcpt_to_cc = $cc;
1107
+
1108
+ map { $_ =~ s/^[^<]*<//;
1109
+ $_ =~ s/>[^>]*//; } ($mail_from, $rcpt_to_to, $rcpt_to_cc);
1110
+
1111
+ if ( open my $sff_fh, '|-:raw', 'MCR TCPIP$SYSTEM:TCPIP$SMTP_SFF.EXE SYS$INPUT:' ) {
1112
+ print $sff_fh "MAIL FROM:<$mail_from>\n";
1113
+ print $sff_fh "RCPT TO:<$rcpt_to_to>\n";
1114
+ print $sff_fh "RCPT TO:<$rcpt_to_cc>\n" if $rcpt_to_cc;
1115
+ print $sff_fh "DATA\n";
1116
+ print $sff_fh build_complete_message();
1117
+ my $success = close $sff_fh;
1118
+ if ($success ) {
1119
+ print "\nMessage sent\n";
1120
+ return;
1121
+ }
1122
+ }
1123
+ die "Mail transport failed (leaving bug report in $filename): $^E\n";
1124
+ }
1125
+
1126
+ sub _send_message_mailsend {
1127
+ my $msg = Mail::Send->new();
1128
+ my %headers = %{_message_headers()};
1129
+ for my $key ( keys %headers) {
1130
+ $msg->add($key => $headers{$key});
1131
+ }
1132
+
1133
+ $fh = $msg->open;
1134
+ binmode($fh, ':raw');
1135
+ print $fh _add_body_start() if $have_attachment;
1136
+ print $fh _read_report($filename);
1137
+ print $fh _add_attachments() if $have_attachment;
1138
+ $fh->close or die "Error sending mail: $!";
1139
+
1140
+ print "\nMessage sent.\n";
1141
+ }
1142
+
1143
+ sub _probe_for_sendmail {
1144
+ my $sendmail = "";
1145
+ for (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail)) {
1146
+ $sendmail = $_, last if -e $_;
1147
+ }
1148
+ if ( $^O eq 'os2' and $sendmail eq "" ) {
1149
+ my $path = $ENV{PATH};
1150
+ $path =~ s:\\:/:;
1151
+ my @path = split /$Config{'path_sep'}/, $path;
1152
+ for (@path) {
1153
+ $sendmail = "$_/sendmail", last if -e "$_/sendmail";
1154
+ $sendmail = "$_/sendmail.exe", last if -e "$_/sendmail.exe";
1155
+ }
1156
+ }
1157
+ return $sendmail;
1158
+ }
1159
+
1160
+ sub _send_message_sendmail {
1161
+ my $sendmail = _probe_for_sendmail();
1162
+ unless ($sendmail) {
1163
+ my $message_start = !$Is_Linux && !$Is_OpenBSD ? <<'EOT' : <<'EOT';
1164
+ It appears that there is no program which looks like "sendmail" on
1165
+ your system and that the Mail::Send library from CPAN isn't available.
1166
+ EOT
1167
+ It appears that there is no program which looks like "sendmail" on
1168
+ your system.
1169
+ EOT
1170
+ paraprint(<<"EOF"), die "\n";
1171
+ $message_start
1172
+ Because of this, there's no easy way to automatically send your
1173
+ report.
1174
+
1175
+ A copy of your report has been saved in '$filename' for you to
1176
+ send to '$address' with your normal mail client.
1177
+ EOF
1178
+ }
1179
+
1180
+ open( SENDMAIL, "|-:raw", $sendmail, "-t", "-oi", "-f", $from )
1181
+ || die "'|$sendmail -t -oi -f $from' failed: $!";
1182
+ print SENDMAIL build_complete_message();
1183
+ if ( close(SENDMAIL) ) {
1184
+ print "\nMessage sent\n";
1185
+ } else {
1186
+ warn "\nSendmail returned status '", $? >> 8, "'\n";
1187
+ }
1188
+ }
1189
+
1190
+
1191
+
1192
+ # a strange way to check whether any significant editing
1193
+ # has been done: check whether any new non-empty lines
1194
+ # have been added.
1195
+
1196
+ sub _fingerprint_lines_in_report {
1197
+ my $new_lines = 0;
1198
+ # read in the report template once so that
1199
+ # we can track whether the user does any editing.
1200
+ # yes, *all* whitespace is ignored.
1201
+
1202
+ open(REP, '<:raw', $filename) or die "Unable to open report file '$filename': $!\n";
1203
+ binmode(REP, ':raw :crlf') if $Is_MSWin32;
1204
+ while (my $line = <REP>) {
1205
+ $line =~ s/\s+//g;
1206
+ $new_lines++ if (!$REP{$line});
1207
+
1208
+ }
1209
+ close(REP) or die "Error closing report file '$filename': $!";
1210
+ # returns the number of lines with content that wasn't there when last we looked
1211
+ return $new_lines;
1212
+ }
1213
+
1214
+
1215
+
1216
+ format STDOUT =
1217
+ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
1218
+ $_
1219
+ .
1220
+
1221
+ __END__
1222
+
1223
+ =head1 NAME
1224
+
1225
+ perlbug - how to submit bug reports on Perl
1226
+
1227
+ =head1 SYNOPSIS
1228
+
1229
+ B<perlbug>
1230
+
1231
+ B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
1232
+ S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
1233
+ S<[ B<-r> I<returnaddress> ]>
1234
+ S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
1235
+ S<[ B<-S> ]> S<[ B<-t> ]> S<[ B<-d> ]> S<[ B<-h> ]> S<[ B<-T> ]>
1236
+
1237
+ B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]>
1238
+ S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
1239
+
1240
+ B<perlthanks>
1241
+
1242
+ =head1 DESCRIPTION
1243
+
1244
+
1245
+ This program is designed to help you generate bug reports
1246
+ (and thank-you notes) about perl5 and the modules which ship with it.
1247
+
1248
+ In most cases, you can just run it interactively from a command
1249
+ line without any special arguments and follow the prompts.
1250
+
1251
+ If you have found a bug with a non-standard port (one that was not
1252
+ part of the I<standard distribution>), a binary distribution, or a
1253
+ non-core module (such as Tk, DBI, etc), then please see the
1254
+ documentation that came with that distribution to determine the
1255
+ correct place to report bugs.
1256
+
1257
+ Bug reports should be submitted to the GitHub issue tracker at
1258
+ L<https://github.com/Perl/perl5/issues>. The B<perlbug@perl.org>
1259
+ address no longer automatically opens tickets. You can use this tool
1260
+ to compose your report and save it to a file which you can then submit
1261
+ to the issue tracker.
1262
+
1263
+ In extreme cases, B<perlbug> may not work well enough on your system
1264
+ to guide you through composing a bug report. In those cases, you
1265
+ may be able to use B<perlbug -d> or B<perl -V> to get system
1266
+ configuration information to include in your issue report.
1267
+
1268
+
1269
+ When reporting a bug, please run through this checklist:
1270
+
1271
+ =over 4
1272
+
1273
+ =item What version of Perl you are running?
1274
+
1275
+ Type C<perl -v> at the command line to find out.
1276
+
1277
+ =item Are you running the latest released version of perl?
1278
+
1279
+ Look at L<http://www.perl.org/> to find out. If you are not using the
1280
+ latest released version, please try to replicate your bug on the
1281
+ latest stable release.
1282
+
1283
+ Note that reports about bugs in old versions of Perl, especially
1284
+ those which indicate you haven't also tested the current stable
1285
+ release of Perl, are likely to receive less attention from the
1286
+ volunteers who build and maintain Perl than reports about bugs in
1287
+ the current release.
1288
+
1289
+ =item Are you sure what you have is a bug?
1290
+
1291
+ A significant number of the bug reports we get turn out to be
1292
+ documented features in Perl. Make sure the issue you've run into
1293
+ isn't intentional by glancing through the documentation that comes
1294
+ with the Perl distribution.
1295
+
1296
+ Given the sheer volume of Perl documentation, this isn't a trivial
1297
+ undertaking, but if you can point to documentation that suggests
1298
+ the behaviour you're seeing is I<wrong>, your issue is likely to
1299
+ receive more attention. You may want to start with B<perldoc>
1300
+ L<perltrap> for pointers to common traps that new (and experienced)
1301
+ Perl programmers run into.
1302
+
1303
+ If you're unsure of the meaning of an error message you've run
1304
+ across, B<perldoc> L<perldiag> for an explanation. If the message
1305
+ isn't in perldiag, it probably isn't generated by Perl. You may
1306
+ have luck consulting your operating system documentation instead.
1307
+
1308
+ If you are on a non-UNIX platform B<perldoc> L<perlport>, as some
1309
+ features may be unimplemented or work differently.
1310
+
1311
+ You may be able to figure out what's going wrong using the Perl
1312
+ debugger. For information about how to use the debugger B<perldoc>
1313
+ L<perldebug>.
1314
+
1315
+ =item Do you have a proper test case?
1316
+
1317
+ The easier it is to reproduce your bug, the more likely it will be
1318
+ fixed -- if nobody can duplicate your problem, it probably won't be
1319
+ addressed.
1320
+
1321
+ A good test case has most of these attributes: short, simple code;
1322
+ few dependencies on external commands, modules, or libraries; no
1323
+ platform-dependent code (unless it's a platform-specific bug);
1324
+ clear, simple documentation.
1325
+
1326
+ A good test case is almost always a good candidate to be included in
1327
+ Perl's test suite. If you have the time, consider writing your test case so
1328
+ that it can be easily included into the standard test suite.
1329
+
1330
+ =item Have you included all relevant information?
1331
+
1332
+ Be sure to include the B<exact> error messages, if any.
1333
+ "Perl gave an error" is not an exact error message.
1334
+
1335
+ If you get a core dump (or equivalent), you may use a debugger
1336
+ (B<dbx>, B<gdb>, etc) to produce a stack trace to include in the bug
1337
+ report.
1338
+
1339
+ NOTE: unless your Perl has been compiled with debug info
1340
+ (often B<-g>), the stack trace is likely to be somewhat hard to use
1341
+ because it will most probably contain only the function names and not
1342
+ their arguments. If possible, recompile your Perl with debug info and
1343
+ reproduce the crash and the stack trace.
1344
+
1345
+ =item Can you describe the bug in plain English?
1346
+
1347
+ The easier it is to understand a reproducible bug, the more likely
1348
+ it will be fixed. Any insight you can provide into the problem
1349
+ will help a great deal. In other words, try to analyze the problem
1350
+ (to the extent you can) and report your discoveries.
1351
+
1352
+ =item Can you fix the bug yourself?
1353
+
1354
+ If so, that's great news; bug reports with patches are likely to
1355
+ receive significantly more attention and interest than those without
1356
+ patches. Please submit your patch via the GitHub Pull Request workflow
1357
+ as described in B<perldoc> L<perlhack>. You may also send patches to
1358
+ B<perl5-porters@perl.org>. When sending a patch, create it using
1359
+ C<git format-patch> if possible, though a unified diff created with
1360
+ C<diff -pu> will do nearly as well.
1361
+
1362
+ Your patch may be returned with requests for changes, or requests for more
1363
+ detailed explanations about your fix.
1364
+
1365
+ Here are a few hints for creating high-quality patches:
1366
+
1367
+ Make sure the patch is not reversed (the first argument to diff is
1368
+ typically the original file, the second argument your changed file).
1369
+ Make sure you test your patch by applying it with C<git am> or the
1370
+ C<patch> program before you send it on its way. Try to follow the
1371
+ same style as the code you are trying to patch. Make sure your patch
1372
+ really does work (C<make test>, if the thing you're patching is covered
1373
+ by Perl's test suite).
1374
+
1375
+ =item Can you use C<perlbug> to submit a thank-you note?
1376
+
1377
+ Yes, you can do this by either using the C<-T> option, or by invoking
1378
+ the program as C<perlthanks>. Thank-you notes are good. It makes people
1379
+ smile.
1380
+
1381
+ =back
1382
+
1383
+ Please make your issue title informative. "a bug" is not informative.
1384
+ Neither is "perl crashes" nor is "HELP!!!". These don't help. A compact
1385
+ description of what's wrong is fine.
1386
+
1387
+ Having done your bit, please be prepared to wait, to be told the
1388
+ bug is in your code, or possibly to get no reply at all. The
1389
+ volunteers who maintain Perl are busy folks, so if your problem is
1390
+ an obvious bug in your own code, is difficult to understand or is
1391
+ a duplicate of an existing report, you may not receive a personal
1392
+ reply.
1393
+
1394
+ If it is important to you that your bug be fixed, do monitor the
1395
+ issue tracker (you will be subscribed to notifications for issues you
1396
+ submit or comment on) and the commit logs to development
1397
+ versions of Perl, and encourage the maintainers with kind words or
1398
+ offers of frosty beverages. (Please do be kind to the maintainers.
1399
+ Harassing or flaming them is likely to have the opposite effect of the
1400
+ one you want.)
1401
+
1402
+ Feel free to update the ticket about your bug on
1403
+ L<https://github.com/Perl/perl5/issues>
1404
+ if a new version of Perl is released and your bug is still present.
1405
+
1406
+ =head1 OPTIONS
1407
+
1408
+ =over 8
1409
+
1410
+ =item B<-a>
1411
+
1412
+ Address to send the report to instead of saving to a file.
1413
+
1414
+ =item B<-b>
1415
+
1416
+ Body of the report. If not included on the command line, or
1417
+ in a file with B<-f>, you will get a chance to edit the report.
1418
+
1419
+ =item B<-C>
1420
+
1421
+ Don't send copy to administrator when sending report by mail.
1422
+
1423
+ =item B<-c>
1424
+
1425
+ Address to send copy of report to when sending report by mail.
1426
+ Defaults to the address of the
1427
+ local perl administrator (recorded when perl was built).
1428
+
1429
+ =item B<-d>
1430
+
1431
+ Data mode (the default if you redirect or pipe output). This prints out
1432
+ your configuration data, without saving or mailing anything. You can use
1433
+ this with B<-v> to get more complete data.
1434
+
1435
+ =item B<-e>
1436
+
1437
+ Editor to use.
1438
+
1439
+ =item B<-f>
1440
+
1441
+ File containing the body of the report. Use this to quickly send a
1442
+ prepared report.
1443
+
1444
+ =item B<-F>
1445
+
1446
+ File to output the results to. Defaults to B<perlbug.rep>.
1447
+
1448
+ =item B<-h>
1449
+
1450
+ Prints a brief summary of the options.
1451
+
1452
+ =item B<-ok>
1453
+
1454
+ Report successful build on this system to perl porters. Forces B<-S>
1455
+ and B<-C>. Forces and supplies values for B<-s> and B<-b>. Only
1456
+ prompts for a return address if it cannot guess it (for use with
1457
+ B<make>). Honors return address specified with B<-r>. You can use this
1458
+ with B<-v> to get more complete data. Only makes a report if this
1459
+ system is less than 60 days old.
1460
+
1461
+ =item B<-okay>
1462
+
1463
+ As B<-ok> except it will report on older systems.
1464
+
1465
+ =item B<-nok>
1466
+
1467
+ Report unsuccessful build on this system. Forces B<-C>. Forces and
1468
+ supplies a value for B<-s>, then requires you to edit the report
1469
+ and say what went wrong. Alternatively, a prepared report may be
1470
+ supplied using B<-f>. Only prompts for a return address if it
1471
+ cannot guess it (for use with B<make>). Honors return address
1472
+ specified with B<-r>. You can use this with B<-v> to get more
1473
+ complete data. Only makes a report if this system is less than 60
1474
+ days old.
1475
+
1476
+ =item B<-nokay>
1477
+
1478
+ As B<-nok> except it will report on older systems.
1479
+
1480
+ =item B<-p>
1481
+
1482
+ The names of one or more patch files or other text attachments to be
1483
+ included with the report. Multiple files must be separated with commas.
1484
+
1485
+ =item B<-r>
1486
+
1487
+ Your return address. The program will ask you to confirm its default
1488
+ if you don't use this option.
1489
+
1490
+ =item B<-S>
1491
+
1492
+ Save or send the report without asking for confirmation.
1493
+
1494
+ =item B<-s>
1495
+
1496
+ Subject to include with the report. You will be prompted if you don't
1497
+ supply one on the command line.
1498
+
1499
+ =item B<-t>
1500
+
1501
+ Test mode. Makes it possible to command perlbug from a pipe or file, for
1502
+ testing purposes.
1503
+
1504
+ =item B<-T>
1505
+
1506
+ Send a thank-you note instead of a bug report.
1507
+
1508
+ =item B<-v>
1509
+
1510
+ Include verbose configuration data in the report.
1511
+
1512
+ =back
1513
+
1514
+ =head1 AUTHORS
1515
+
1516
+ Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently
1517
+ I<doc>tored by Gurusamy Sarathy (E<lt>gsar@activestate.comE<gt>),
1518
+ Tom Christiansen (E<lt>tchrist@perl.comE<gt>), Nathan Torkington
1519
+ (E<lt>gnat@frii.comE<gt>), Charles F. Randall (E<lt>cfr@pobox.comE<gt>),
1520
+ Mike Guy (E<lt>mjtg@cam.ac.ukE<gt>), Dominic Dunlop
1521
+ (E<lt>domo@computer.orgE<gt>), Hugo van der Sanden (E<lt>hv@crypt.orgE<gt>),
1522
+ Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), Chris Nandor
1523
+ (E<lt>pudge@pobox.comE<gt>), Jon Orwant (E<lt>orwant@media.mit.eduE<gt>,
1524
+ Richard Foley (E<lt>richard.foley@rfi.netE<gt>), Jesse Vincent
1525
+ (E<lt>jesse@bestpractical.comE<gt>), and Craig A. Berry (E<lt>craigberry@mac.comE<gt>).
1526
+
1527
+ =head1 SEE ALSO
1528
+
1529
+ perl(1), perldebug(1), perldiag(1), perlport(1), perltrap(1),
1530
+ diff(1), patch(1), dbx(1), gdb(1)
1531
+
1532
+ =head1 BUGS
1533
+
1534
+ None known (guess what must have been used to report them?)
1535
+
1536
+ =cut
1537
+
git/usr/bin/core_perl/piconv ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!./perl
5
+ # $Id: piconv,v 2.8 2016/08/04 03:15:58 dankogai Exp $
6
+ #
7
+ BEGIN { pop @INC if $INC[-1] eq '.' }
8
+ use 5.8.0;
9
+ use strict;
10
+ use Encode ;
11
+ use Encode::Alias;
12
+ my %Scheme = map {$_ => 1} qw(from_to decode_encode perlio);
13
+
14
+ use File::Basename;
15
+ my $name = basename($0);
16
+
17
+ use Getopt::Long qw(:config no_ignore_case);
18
+
19
+ my %Opt;
20
+
21
+ help()
22
+ unless
23
+ GetOptions(\%Opt,
24
+ 'from|f=s',
25
+ 'to|t=s',
26
+ 'list|l',
27
+ 'string|s=s',
28
+ 'check|C=i',
29
+ 'c',
30
+ 'perlqq|p',
31
+ 'htmlcref',
32
+ 'xmlcref',
33
+ 'debug|D',
34
+ 'scheme|S=s',
35
+ 'resolve|r=s',
36
+ 'help',
37
+ );
38
+
39
+ $Opt{help} and help();
40
+ $Opt{list} and list_encodings();
41
+ my $locale = $ENV{LC_CTYPE} || $ENV{LC_ALL} || $ENV{LANG};
42
+ defined $Opt{resolve} and resolve_encoding($Opt{resolve});
43
+ $Opt{from} || $Opt{to} || help();
44
+ my $from = $Opt{from} || $locale or help("from_encoding unspecified");
45
+ my $to = $Opt{to} || $locale or help("to_encoding unspecified");
46
+ $Opt{string} and Encode::from_to($Opt{string}, $from, $to) and print $Opt{string} and exit;
47
+ my $scheme = do {
48
+ if (defined $Opt{scheme}) {
49
+ if (!exists $Scheme{$Opt{scheme}}) {
50
+ warn "Unknown scheme '$Opt{scheme}', fallback to 'from_to'.\n";
51
+ 'from_to';
52
+ } else {
53
+ $Opt{scheme};
54
+ }
55
+ } else {
56
+ 'from_to';
57
+ }
58
+ };
59
+
60
+ $Opt{check} ||= $Opt{c};
61
+ $Opt{perlqq} and $Opt{check} = Encode::PERLQQ;
62
+ $Opt{htmlcref} and $Opt{check} = Encode::HTMLCREF;
63
+ $Opt{xmlcref} and $Opt{check} = Encode::XMLCREF;
64
+
65
+ my $efrom = Encode->getEncoding($from) || die "Unknown encoding '$from'";
66
+ my $eto = Encode->getEncoding($to) || die "Unknown encoding '$to'";
67
+
68
+ my $cfrom = $efrom->name;
69
+ my $cto = $eto->name;
70
+
71
+ if ($Opt{debug}){
72
+ print <<"EOT";
73
+ Scheme: $scheme
74
+ From: $from => $cfrom
75
+ To: $to => $cto
76
+ EOT
77
+ }
78
+
79
+ my %use_bom =
80
+ map { $_ => 1 } qw/UTF-16 UTF-16BE UTF-16LE UTF-32 UTF-32BE UTF-32LE/;
81
+
82
+ # we do not use <> (or ARGV) for the sake of binmode()
83
+ @ARGV or push @ARGV, \*STDIN;
84
+
85
+ unless ( $scheme eq 'perlio' ) {
86
+ binmode STDOUT;
87
+ my $need2slurp = $use_bom{ $eto } || $use_bom{ $efrom };
88
+ for my $argv (@ARGV) {
89
+ my $ifh = ref $argv ? $argv : undef;
90
+ $ifh or open $ifh, "<", $argv or warn "Can't open $argv: $!" and next;
91
+ $ifh or open $ifh, "<", $argv or next;
92
+ binmode $ifh;
93
+ if ( $scheme eq 'from_to' ) { # default
94
+ if ($need2slurp){
95
+ local $/;
96
+ $_ = <$ifh>;
97
+ Encode::from_to( $_, $from, $to, $Opt{check} );
98
+ print;
99
+ }else{
100
+ while (<$ifh>) {
101
+ Encode::from_to( $_, $from, $to, $Opt{check} );
102
+ print;
103
+ }
104
+ }
105
+ }
106
+ elsif ( $scheme eq 'decode_encode' ) { # step-by-step
107
+ if ($need2slurp){
108
+ local $/;
109
+ $_ = <$ifh>;
110
+ my $decoded = decode( $from, $_, $Opt{check} );
111
+ my $encoded = encode( $to, $decoded );
112
+ print $encoded;
113
+ }else{
114
+ while (<$ifh>) {
115
+ my $decoded = decode( $from, $_, $Opt{check} );
116
+ my $encoded = encode( $to, $decoded );
117
+ print $encoded;
118
+ }
119
+ }
120
+ }
121
+ else { # won't reach
122
+ die "$name: unknown scheme: $scheme";
123
+ }
124
+ }
125
+ }
126
+ else {
127
+
128
+ # NI-S favorite
129
+ binmode STDOUT => "raw:encoding($to)";
130
+ for my $argv (@ARGV) {
131
+ my $ifh = ref $argv ? $argv : undef;
132
+ $ifh or open $ifh, "<", $argv or warn "Can't open $argv: $!" and next;
133
+ $ifh or open $ifh, "<", $argv or next;
134
+ binmode $ifh => "raw:encoding($from)";
135
+ print while (<$ifh>);
136
+ }
137
+ }
138
+
139
+ sub list_encodings {
140
+ print join( "\n", Encode->encodings(":all") ), "\n";
141
+ exit 0;
142
+ }
143
+
144
+ sub resolve_encoding {
145
+ if ( my $alias = Encode::resolve_alias( $_[0] ) ) {
146
+ print $alias, "\n";
147
+ exit 0;
148
+ }
149
+ else {
150
+ warn "$name: $_[0] is not known to Encode\n";
151
+ exit 1;
152
+ }
153
+ }
154
+
155
+ sub help {
156
+ my $message = shift;
157
+ $message and print STDERR "$name error: $message\n";
158
+ print STDERR <<"EOT";
159
+ $name [-f from_encoding] [-t to_encoding]
160
+ [-p|--perlqq|--htmlcref|--xmlcref] [-C N|-c] [-D] [-S scheme]
161
+ [-s string|file...]
162
+ $name -l
163
+ $name -r encoding_alias
164
+ $name -h
165
+ Common options:
166
+ -l,--list
167
+ lists all available encodings
168
+ -r,--resolve encoding_alias
169
+ resolve encoding to its (Encode) canonical name
170
+ -f,--from from_encoding
171
+ when omitted, the current locale will be used
172
+ -t,--to to_encoding
173
+ when omitted, the current locale will be used
174
+ -s,--string string
175
+ "string" will be the input instead of STDIN or files
176
+ The following are mainly of interest to Encode hackers:
177
+ -C N | -c check the validity of the input
178
+ -D,--debug show debug information
179
+ -S,--scheme scheme use the scheme for conversion
180
+ Those are handy when you can only see ASCII characters:
181
+ -p,--perlqq transliterate characters missing in encoding to \\x{HHHH}
182
+ where HHHH is the hexadecimal Unicode code point
183
+ --htmlcref transliterate characters missing in encoding to &#NNN;
184
+ where NNN is the decimal Unicode code point
185
+ --xmlcref transliterate characters missing in encoding to &#xHHHH;
186
+ where HHHH is the hexadecimal Unicode code point
187
+
188
+ EOT
189
+ exit;
190
+ }
191
+
192
+ __END__
193
+
194
+ =head1 NAME
195
+
196
+ piconv -- iconv(1), reinvented in perl
197
+
198
+ =head1 SYNOPSIS
199
+
200
+ piconv [-f from_encoding] [-t to_encoding]
201
+ [-p|--perlqq|--htmlcref|--xmlcref] [-C N|-c] [-D] [-S scheme]
202
+ [-s string|file...]
203
+ piconv -l
204
+ piconv -r encoding_alias
205
+ piconv -h
206
+
207
+ =head1 DESCRIPTION
208
+
209
+ B<piconv> is perl version of B<iconv>, a character encoding converter
210
+ widely available for various Unixen today. This script was primarily
211
+ a technology demonstrator for Perl 5.8.0, but you can use piconv in the
212
+ place of iconv for virtually any case.
213
+
214
+ piconv converts the character encoding of either STDIN or files
215
+ specified in the argument and prints out to STDOUT.
216
+
217
+ Here is the list of options. Some options can be in short format (-f)
218
+ or long (--from) one.
219
+
220
+ =over 4
221
+
222
+ =item -f,--from I<from_encoding>
223
+
224
+ Specifies the encoding you are converting from. Unlike B<iconv>,
225
+ this option can be omitted. In such cases, the current locale is used.
226
+
227
+ =item -t,--to I<to_encoding>
228
+
229
+ Specifies the encoding you are converting to. Unlike B<iconv>,
230
+ this option can be omitted. In such cases, the current locale is used.
231
+
232
+ Therefore, when both -f and -t are omitted, B<piconv> just acts
233
+ like B<cat>.
234
+
235
+ =item -s,--string I<string>
236
+
237
+ uses I<string> instead of file for the source of text.
238
+
239
+ =item -l,--list
240
+
241
+ Lists all available encodings, one per line, in case-insensitive
242
+ order. Note that only the canonical names are listed; many aliases
243
+ exist. For example, the names are case-insensitive, and many standard
244
+ and common aliases work, such as "latin1" for "ISO-8859-1", or "ibm850"
245
+ instead of "cp850", or "winlatin1" for "cp1252". See L<Encode::Supported>
246
+ for a full discussion.
247
+
248
+ =item -r,--resolve I<encoding_alias>
249
+
250
+ Resolve I<encoding_alias> to Encode canonical encoding name.
251
+
252
+ =item -C,--check I<N>
253
+
254
+ Check the validity of the stream if I<N> = 1. When I<N> = -1, something
255
+ interesting happens when it encounters an invalid character.
256
+
257
+ =item -c
258
+
259
+ Same as C<-C 1>.
260
+
261
+ =item -p,--perlqq
262
+
263
+ Transliterate characters missing in encoding to \x{HHHH} where HHHH is the
264
+ hexadecimal Unicode code point.
265
+
266
+ =item --htmlcref
267
+
268
+ Transliterate characters missing in encoding to &#NNN; where NNN is the
269
+ decimal Unicode code point.
270
+
271
+ =item --xmlcref
272
+
273
+ Transliterate characters missing in encoding to &#xHHHH; where HHHH is the
274
+ hexadecimal Unicode code point.
275
+
276
+ =item -h,--help
277
+
278
+ Show usage.
279
+
280
+ =item -D,--debug
281
+
282
+ Invokes debugging mode. Primarily for Encode hackers.
283
+
284
+ =item -S,--scheme I<scheme>
285
+
286
+ Selects which scheme is to be used for conversion. Available schemes
287
+ are as follows:
288
+
289
+ =over 4
290
+
291
+ =item from_to
292
+
293
+ Uses Encode::from_to for conversion. This is the default.
294
+
295
+ =item decode_encode
296
+
297
+ Input strings are decode()d then encode()d. A straight two-step
298
+ implementation.
299
+
300
+ =item perlio
301
+
302
+ The new perlIO layer is used. NI-S' favorite.
303
+
304
+ You should use this option if you are using UTF-16 and others which
305
+ linefeed is not $/.
306
+
307
+ =back
308
+
309
+ Like the I<-D> option, this is also for Encode hackers.
310
+
311
+ =back
312
+
313
+ =head1 SEE ALSO
314
+
315
+ L<iconv(1)>
316
+ L<locale(3)>
317
+ L<Encode>
318
+ L<Encode::Supported>
319
+ L<Encode::Alias>
320
+ L<PerlIO>
321
+
322
+ =cut
git/usr/bin/core_perl/pl2pm ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ =head1 NAME
6
+
7
+ pl2pm - Rough tool to translate Perl4 .pl files to Perl5 .pm modules.
8
+
9
+ =head1 SYNOPSIS
10
+
11
+ B<pl2pm> F<files>
12
+
13
+ =head1 DESCRIPTION
14
+
15
+ B<pl2pm> is a tool to aid in the conversion of Perl4-style .pl
16
+ library files to Perl5-style library modules. Usually, your old .pl
17
+ file will still work fine and you should only use this tool if you
18
+ plan to update your library to use some of the newer Perl 5 features,
19
+ such as AutoLoading.
20
+
21
+ =head1 LIMITATIONS
22
+
23
+ It's just a first step, but it's usually a good first step.
24
+
25
+ =head1 AUTHOR
26
+
27
+ Larry Wall <larry@wall.org>
28
+
29
+ =cut
30
+
31
+ use strict;
32
+ use warnings;
33
+
34
+ my %keyword = ();
35
+
36
+ while (<DATA>) {
37
+ chomp;
38
+ $keyword{$_} = 1;
39
+ }
40
+
41
+ local $/;
42
+
43
+ while (<>) {
44
+ my $newname = $ARGV;
45
+ $newname =~ s/\.pl$/.pm/ || next;
46
+ $newname =~ s#(.*/)?(\w+)#$1\u$2#;
47
+ if (-f $newname) {
48
+ warn "Won't overwrite existing $newname\n";
49
+ next;
50
+ }
51
+ my $oldpack = $2;
52
+ my $newpack = "\u$2";
53
+ my @export = ();
54
+
55
+ s/\bstd(in|out|err)\b/\U$&/g;
56
+ s/(sub\s+)(\w+)(\s*\{[ \t]*\n)\s*package\s+$oldpack\s*;[ \t]*\n+/${1}main'$2$3/ig;
57
+ if (/sub\s+\w+'/) {
58
+ @export = m/sub\s+\w+'(\w+)/g;
59
+ s/(sub\s+)main'(\w+)/$1$2/g;
60
+ }
61
+ else {
62
+ @export = m/sub\s+([A-Za-z]\w*)/g;
63
+ }
64
+ my @export_ok = grep($keyword{$_}, @export);
65
+ @export = grep(!$keyword{$_}, @export);
66
+
67
+ my %export = ();
68
+ @export{@export} = (1) x @export;
69
+
70
+ s/(^\s*);#/$1#/g;
71
+ s/(#.*)require ['"]$oldpack\.pl['"]/$1use $newpack/;
72
+ s/(package\s*)($oldpack)\s*;[ \t]*\n+//ig;
73
+ s/([\$\@%&*])'(\w+)/&xlate($1,"",$2,$newpack,$oldpack,\%export)/eg;
74
+ s/([\$\@%&*]?)(\w+)'(\w+)/&xlate($1,$2,$3,$newpack,$oldpack,\%export)/eg;
75
+ if (!/\$\[\s*\)?\s*=\s*[^0\s]/) {
76
+ s/^\s*(local\s*\()?\s*\$\[\s*\)?\s*=\s*0\s*;[ \t]*\n//g;
77
+ s/\$\[\s*\+\s*//g;
78
+ s/\s*\+\s*\$\[//g;
79
+ s/\$\[/0/g;
80
+ }
81
+ s/open\s+(\w+)/open($1)/g;
82
+
83
+ my $export_ok = '';
84
+ my $carp ='';
85
+
86
+
87
+ if (s/\bdie\b/croak/g) {
88
+ $carp = "use Carp;\n";
89
+ s/croak "([^"]*)\\n"/croak "$1"/g;
90
+ }
91
+
92
+ if (@export_ok) {
93
+ $export_ok = "\@EXPORT_OK = qw(@export_ok);\n";
94
+ }
95
+
96
+ if ( open(PM, ">", $newname) ) {
97
+ print PM <<"END";
98
+ package $newpack;
99
+ use 5.006;
100
+ require Exporter;
101
+ $carp
102
+ \@ISA = qw(Exporter);
103
+ \@EXPORT = qw(@export);
104
+ $export_ok
105
+ $_
106
+ END
107
+ }
108
+ else {
109
+ warn "Can't create $newname: $!\n";
110
+ }
111
+ }
112
+
113
+ sub xlate {
114
+ my ($prefix, $pack, $ident,$newpack,$oldpack,$export) = @_;
115
+
116
+ my $xlated ;
117
+ if ($prefix eq '' && $ident =~ /^(t|s|m|d|ing|ll|ed|ve|re)$/) {
118
+ $xlated = "${pack}'$ident";
119
+ }
120
+ elsif ($pack eq '' || $pack eq 'main') {
121
+ if ($export->{$ident}) {
122
+ $xlated = "$prefix$ident";
123
+ }
124
+ else {
125
+ $xlated = "$prefix${pack}::$ident";
126
+ }
127
+ }
128
+ elsif ($pack eq $oldpack) {
129
+ $xlated = "$prefix${newpack}::$ident";
130
+ }
131
+ else {
132
+ $xlated = "$prefix${pack}::$ident";
133
+ }
134
+
135
+ return $xlated;
136
+ }
137
+ __END__
138
+ AUTOLOAD
139
+ BEGIN
140
+ CHECK
141
+ CORE
142
+ DESTROY
143
+ END
144
+ INIT
145
+ UNITCHECK
146
+ abs
147
+ accept
148
+ alarm
149
+ and
150
+ atan2
151
+ bind
152
+ binmode
153
+ bless
154
+ caller
155
+ chdir
156
+ chmod
157
+ chomp
158
+ chop
159
+ chown
160
+ chr
161
+ chroot
162
+ close
163
+ closedir
164
+ cmp
165
+ connect
166
+ continue
167
+ cos
168
+ crypt
169
+ dbmclose
170
+ dbmopen
171
+ defined
172
+ delete
173
+ die
174
+ do
175
+ dump
176
+ each
177
+ else
178
+ elsif
179
+ endgrent
180
+ endhostent
181
+ endnetent
182
+ endprotoent
183
+ endpwent
184
+ endservent
185
+ eof
186
+ eq
187
+ eval
188
+ exec
189
+ exists
190
+ exit
191
+ exp
192
+ fcntl
193
+ fileno
194
+ flock
195
+ for
196
+ foreach
197
+ fork
198
+ format
199
+ formline
200
+ ge
201
+ getc
202
+ getgrent
203
+ getgrgid
204
+ getgrnam
205
+ gethostbyaddr
206
+ gethostbyname
207
+ gethostent
208
+ getlogin
209
+ getnetbyaddr
210
+ getnetbyname
211
+ getnetent
212
+ getpeername
213
+ getpgrp
214
+ getppid
215
+ getpriority
216
+ getprotobyname
217
+ getprotobynumber
218
+ getprotoent
219
+ getpwent
220
+ getpwnam
221
+ getpwuid
222
+ getservbyname
223
+ getservbyport
224
+ getservent
225
+ getsockname
226
+ getsockopt
227
+ glob
228
+ gmtime
229
+ goto
230
+ grep
231
+ gt
232
+ hex
233
+ if
234
+ index
235
+ int
236
+ ioctl
237
+ join
238
+ keys
239
+ kill
240
+ last
241
+ lc
242
+ lcfirst
243
+ le
244
+ length
245
+ link
246
+ listen
247
+ local
248
+ localtime
249
+ lock
250
+ log
251
+ lstat
252
+ lt
253
+ m
254
+ map
255
+ mkdir
256
+ msgctl
257
+ msgget
258
+ msgrcv
259
+ msgsnd
260
+ my
261
+ ne
262
+ next
263
+ no
264
+ not
265
+ oct
266
+ open
267
+ opendir
268
+ or
269
+ ord
270
+ our
271
+ pack
272
+ package
273
+ pipe
274
+ pop
275
+ pos
276
+ print
277
+ printf
278
+ prototype
279
+ push
280
+ q
281
+ qq
282
+ qr
283
+ quotemeta
284
+ qw
285
+ qx
286
+ rand
287
+ read
288
+ readdir
289
+ readline
290
+ readlink
291
+ readpipe
292
+ recv
293
+ redo
294
+ ref
295
+ rename
296
+ require
297
+ reset
298
+ return
299
+ reverse
300
+ rewinddir
301
+ rindex
302
+ rmdir
303
+ s
304
+ scalar
305
+ seek
306
+ seekdir
307
+ select
308
+ semctl
309
+ semget
310
+ semop
311
+ send
312
+ setgrent
313
+ sethostent
314
+ setnetent
315
+ setpgrp
316
+ setpriority
317
+ setprotoent
318
+ setpwent
319
+ setservent
320
+ setsockopt
321
+ shift
322
+ shmctl
323
+ shmget
324
+ shmread
325
+ shmwrite
326
+ shutdown
327
+ sin
328
+ sleep
329
+ socket
330
+ socketpair
331
+ sort
332
+ splice
333
+ split
334
+ sprintf
335
+ sqrt
336
+ srand
337
+ stat
338
+ study
339
+ sub
340
+ substr
341
+ symlink
342
+ syscall
343
+ sysopen
344
+ sysread
345
+ sysseek
346
+ system
347
+ syswrite
348
+ tell
349
+ telldir
350
+ tie
351
+ tied
352
+ time
353
+ times
354
+ tr
355
+ truncate
356
+ uc
357
+ ucfirst
358
+ umask
359
+ undef
360
+ unless
361
+ unlink
362
+ unpack
363
+ unshift
364
+ untie
365
+ until
366
+ use
367
+ utime
368
+ values
369
+ vec
370
+ wait
371
+ waitpid
372
+ wantarray
373
+ warn
374
+ while
375
+ write
376
+ x
377
+ xor
378
+ y
git/usr/bin/core_perl/pod2html ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ =pod
5
+
6
+ =head1 NAME
7
+
8
+ pod2html - convert .pod files to .html files
9
+
10
+ =head1 SYNOPSIS
11
+
12
+ pod2html --help --htmldir=<name> --htmlroot=<URL>
13
+ --infile=<name> --outfile=<name>
14
+ --podpath=<name>:...:<name> --podroot=<name>
15
+ --cachedir=<name> --flush --recurse --norecurse
16
+ --quiet --noquiet --verbose --noverbose
17
+ --index --noindex --backlink --nobacklink
18
+ --header --noheader --poderrors --nopoderrors
19
+ --css=<URL> --title=<name>
20
+
21
+ =head1 DESCRIPTION
22
+
23
+ Converts files from pod format (see L<perlpod>) to HTML format.
24
+
25
+ =head1 ARGUMENTS
26
+
27
+ pod2html takes the following arguments:
28
+
29
+ =over 4
30
+
31
+ =item backlink
32
+
33
+ --backlink
34
+ --nobacklink
35
+
36
+ Turn =head1 directives into links pointing to the top of the HTML file.
37
+ --nobacklink (which is the default behavior) does not create these backlinks.
38
+
39
+ =item cachedir
40
+
41
+ --cachedir=name
42
+
43
+ Specify which directory is used for storing cache. Default directory is the
44
+ current working directory.
45
+
46
+ =item css
47
+
48
+ --css=URL
49
+
50
+ Specify the URL of cascading style sheet to link from resulting HTML file.
51
+ Default is none style sheet.
52
+
53
+ =item flush
54
+
55
+ --flush
56
+
57
+ Flush the cache.
58
+
59
+ =item header
60
+
61
+ --header
62
+ --noheader
63
+
64
+ Create header and footer blocks containing the text of the "NAME" section.
65
+ --noheader -- which is the default behavior -- does not create header or footer
66
+ blocks.
67
+
68
+ =item help
69
+
70
+ --help
71
+
72
+ Displays the usage message.
73
+
74
+ =item htmldir
75
+
76
+ --htmldir=name
77
+
78
+ Sets the directory to which all cross references in the resulting HTML file
79
+ will be relative. Not passing this causes all links to be absolute since this
80
+ is the value that tells Pod::Html the root of the documentation tree.
81
+
82
+ Do not use this and --htmlroot in the same call to pod2html; they are mutually
83
+ exclusive.
84
+
85
+ =item htmlroot
86
+
87
+ --htmlroot=URL
88
+
89
+ Sets the base URL for the HTML files. When cross-references are made, the
90
+ HTML root is prepended to the URL.
91
+
92
+ Do not use this if relative links are desired: use --htmldir instead.
93
+
94
+ Do not pass both this and --htmldir to pod2html; they are mutually exclusive.
95
+
96
+ =item index
97
+
98
+ --index
99
+
100
+ Generate an index at the top of the HTML file (default behaviour).
101
+
102
+ =over 4
103
+
104
+ =item noindex
105
+
106
+ --noindex
107
+
108
+ Do not generate an index at the top of the HTML file.
109
+
110
+ =back
111
+
112
+ =item infile
113
+
114
+ --infile=name
115
+
116
+ Specify the pod file to convert. Input is taken from STDIN if no
117
+ infile is specified.
118
+
119
+ =item outfile
120
+
121
+ --outfile=name
122
+
123
+ Specify the HTML file to create. Output goes to STDOUT if no outfile
124
+ is specified.
125
+
126
+ =item poderrors
127
+
128
+ --poderrors
129
+ --nopoderrors
130
+
131
+ Include a "POD ERRORS" section in the outfile if there were any POD errors in
132
+ the infile (default behaviour). --nopoderrors does not create this "POD
133
+ ERRORS" section.
134
+
135
+ =item podpath
136
+
137
+ --podpath=name:...:name
138
+
139
+ Specify which subdirectories of the podroot contain pod files whose
140
+ HTML converted forms can be linked-to in cross-references.
141
+
142
+ =item podroot
143
+
144
+ --podroot=name
145
+
146
+ Specify the base directory for finding library pods.
147
+
148
+ =item quiet
149
+
150
+ --quiet
151
+ --noquiet
152
+
153
+ Don't display mostly harmless warning messages. --noquiet -- which is the
154
+ default behavior -- I<does> display these mostly harmless warning messages (but
155
+ this is not the same as "verbose" mode).
156
+
157
+ =item recurse
158
+
159
+ --recurse
160
+ --norecurse
161
+
162
+ Recurse into subdirectories specified in podpath (default behaviour).
163
+ --norecurse does not recurse into these subdirectories.
164
+
165
+ =item title
166
+
167
+ --title=title
168
+
169
+ Specify the title of the resulting HTML file.
170
+
171
+ =item verbose
172
+
173
+ --verbose
174
+ --noverbose
175
+
176
+ Display progress messages. --noverbose -- which is the default behavior --
177
+ does not display these progress messages.
178
+
179
+ =back
180
+
181
+ =head1 AUTHOR
182
+
183
+ Tom Christiansen, E<lt>tchrist@perl.comE<gt>.
184
+
185
+ =head1 BUGS
186
+
187
+ See L<Pod::Html> for a list of known bugs in the translator.
188
+
189
+ =head1 SEE ALSO
190
+
191
+ L<perlpod>, L<Pod::Html>
192
+
193
+ =head1 COPYRIGHT
194
+
195
+ This program is distributed under the Artistic License.
196
+
197
+ =cut
198
+
199
+ BEGIN { pop @INC if $INC[-1] eq '.' }
200
+ use Pod::Html;
201
+
202
+ pod2html @ARGV;
git/usr/bin/core_perl/pod2man ADDED
@@ -0,0 +1,519 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ # Convert POD data to formatted *roff input.
6
+ #
7
+ # The driver script for Pod::Man.
8
+ #
9
+ # SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
10
+
11
+ use 5.012;
12
+ use warnings;
13
+
14
+ use Getopt::Long qw(GetOptions);
15
+ use Pod::Man ();
16
+ use Pod::Usage qw(pod2usage);
17
+
18
+ # Format a single POD file.
19
+ #
20
+ # $parser - Pod::Man object to use
21
+ # $input - Input file, - or undef for standard input
22
+ # $output - Output file, - or undef for standard output
23
+ # $verbose - Whether to print each file to standard output when converted
24
+ #
25
+ # Returns: 0 on no errors, 1 if there was an error
26
+ sub format_file {
27
+ my ($parser, $input, $output, $verbose) = @_;
28
+ my $to_stdout = !defined($output) || $output eq q{-};
29
+ if ($verbose && !$to_stdout) {
30
+ print " $output\n" or warn "$0: cannot write to stdout: $!\n";
31
+ }
32
+ $parser->parse_from_file($input, $output);
33
+ if ($parser->{CONTENTLESS}) {
34
+ if (defined($input) && $input ne q{-}) {
35
+ warn "$0: unable to format $input\n";
36
+ } else {
37
+ warn "$0: unable to format standard input\n";
38
+ }
39
+ if (!$to_stdout && !-s $output) {
40
+ unlink($output);
41
+ }
42
+ return 1;
43
+ }
44
+ return 0;
45
+ }
46
+
47
+ # Clean up $0 for error reporting.
48
+ $0 =~ s{ .*/ }{}xms;
49
+
50
+ # Insert -- into @ARGV before any single dash argument to hide it from
51
+ # Getopt::Long; we want to interpret it as meaning stdin.
52
+ my $stdin;
53
+ local @ARGV = map { $_ eq q{-} && !$stdin++ ? (q{--}, $_) : $_ } @ARGV;
54
+
55
+ # Parse our options, trying to retain backward compatibility with pod2man but
56
+ # allowing short forms as well. --lax is currently ignored.
57
+ my %options;
58
+ Getopt::Long::config('bundling_override');
59
+ GetOptions(
60
+ \%options,
61
+ 'center|c=s',
62
+ 'date|d=s',
63
+ 'encoding|e=s',
64
+ 'errors=s',
65
+ 'fixed=s',
66
+ 'fixedbold=s',
67
+ 'fixeditalic=s',
68
+ 'fixedbolditalic=s',
69
+ 'guesswork=s',
70
+ 'help|h',
71
+ 'lax|l',
72
+ 'language=s',
73
+ 'lquote=s',
74
+ 'name|n=s',
75
+ 'nourls',
76
+ 'official|o',
77
+ 'quotes|q=s',
78
+ 'release|r=s',
79
+ 'rquote=s',
80
+ 'section|s=s',
81
+ 'stderr',
82
+ 'verbose|v',
83
+ 'utf8|u',
84
+ ) or exit 1;
85
+ if ($options{help}) {
86
+ pod2usage(0);
87
+ }
88
+
89
+ # Official sets --center, but don't override things explicitly set.
90
+ if ($options{official} && !defined($options{center})) {
91
+ $options{center} = 'Perl Programmers Reference Guide';
92
+ }
93
+
94
+ # Delete flags that are only used in pod2man, not in Pod::Man. lax is accepted
95
+ # only for backward compatibility and does nothing.
96
+ my $verbose = $options{verbose};
97
+ delete @options{qw(verbose lax official)};
98
+
99
+ # If neither stderr nor errors is set, default to errors = die rather than the
100
+ # Pod::Man default of pod.
101
+ if (!defined($options{stderr}) && !defined($options{errors})) {
102
+ $options{errors} = 'die';
103
+ }
104
+
105
+ # If given no arguments, read from stdin and write to stdout.
106
+ if (!@ARGV) {
107
+ push(@ARGV, q{-});
108
+ }
109
+
110
+ # Initialize and run the formatter, pulling a pair of input and output off at
111
+ # a time. For each file, we check whether the document was completely empty
112
+ # and, if so, will remove the created file and exit with a non-zero exit
113
+ # status.
114
+ my $parser = Pod::Man->new(%options);
115
+ my $status = 0;
116
+ while (@ARGV) {
117
+ my ($input, $output) = splice(@ARGV, 0, 2);
118
+ my $result = format_file($parser, $input, $output, $verbose);
119
+ $status ||= $result;
120
+ }
121
+ exit($status);
122
+
123
+ __END__
124
+
125
+ =for stopwords
126
+ en em --stderr stderr --utf8 UTF-8 overdo markup MT-LEVEL Allbery Solaris URL
127
+ troff troff-specific formatters uppercased Christiansen --nourls UTC prepend
128
+ lquote rquote unrepresentable mandoc manref EBCDIC
129
+
130
+ =head1 NAME
131
+
132
+ pod2man - Convert POD data to formatted *roff input
133
+
134
+ =head1 SYNOPSIS
135
+
136
+ pod2man [B<--center>=I<string>] [B<--date>=I<string>]
137
+ [B<--encoding>=I<encoding>] [B<--errors>=I<style>] [B<--fixed>=I<font>]
138
+ [B<--fixedbold>=I<font>] [B<--fixeditalic>=I<font>]
139
+ [B<--fixedbolditalic>=I<font>] [B<--guesswork>=I<rule>[,I<rule>...]]
140
+ [B<--name>=I<name>] [B<--nourls>] [B<--official>]
141
+ [B<--release>=I<version>] [B<--section>=I<manext>]
142
+ [B<--quotes>=I<quotes>] [B<--lquote>=I<quote>] [B<--rquote>=I<quote>]
143
+ [B<--stderr>] [B<--utf8>] [B<--verbose>] [I<input> [I<output>] ...]
144
+
145
+ pod2man B<--help>
146
+
147
+ =head1 DESCRIPTION
148
+
149
+ B<pod2man> is a wrapper script around the L<Pod::Man> module, using it to
150
+ generate *roff input from POD source. The resulting *roff code is suitable
151
+ for display on a terminal using L<nroff(1)>, normally via L<man(1)>, or
152
+ printing using L<troff(1)>.
153
+
154
+ By default (on non-EBCDIC systems), B<pod2man> outputs UTF-8 manual pages.
155
+ Its output should work with the B<man> program on systems that use B<groff>
156
+ (most Linux distributions) or B<mandoc> (most BSD variants), but may result in
157
+ mangled output on older UNIX systems. To choose a different, possibly more
158
+ backward-compatible output mangling on such systems, use C<--encoding=roff>
159
+ (the default in earlier Pod::Man versions). See the B<--encoding> option and
160
+ L<Pod::Man/ENCODING> for more details.
161
+
162
+ I<input> is the file to read for POD source (the POD can be embedded in code).
163
+ If I<input> isn't given, it defaults to C<STDIN>. I<output>, if given, is the
164
+ file to which to write the formatted output. If I<output> isn't given, the
165
+ formatted output is written to C<STDOUT>. Several POD files can be processed
166
+ in the same B<pod2man> invocation (saving module load and compile times) by
167
+ providing multiple pairs of I<input> and I<output> files on the command line.
168
+
169
+ B<--section>, B<--release>, B<--center>, B<--date>, and B<--official> can be
170
+ used to set the headers and footers to use. If not given, Pod::Man will
171
+ assume various defaults. See below for details.
172
+
173
+ For specific details and caveats about the translation from POD to *roff, see
174
+ L<Pod::Man/CAVEATS>.
175
+
176
+ =head1 OPTIONS
177
+
178
+ Each option is annotated with the version of podlators in which that option
179
+ was added with its current meaning.
180
+
181
+ =over 4
182
+
183
+ =item B<-c> I<string>, B<--center>=I<string>
184
+
185
+ [1.00] Sets the centered page header for the C<.TH> macro to I<string>. The
186
+ default is C<User Contributed Perl Documentation>, but also see B<--official>
187
+ below.
188
+
189
+ =item B<-d> I<string>, B<--date>=I<string>
190
+
191
+ [4.00] Set the left-hand footer string for the C<.TH> macro to I<string>. By
192
+ default, the first of POD_MAN_DATE, SOURCE_DATE_EPOCH, the modification date
193
+ of the input file, or the current date (if input comes from C<STDIN>) will be
194
+ used, and the date will be in UTC. See L<Pod::Man/CLASS METHODS> for more
195
+ details.
196
+
197
+ =item B<-e> I<encoding>, B<--encoding>=I<encoding>
198
+
199
+ [5.00] Specifies the encoding of the output. I<encoding> must be an encoding
200
+ recognized by the L<Encode> module (see L<Encode::Supported>). The default on
201
+ non-EBCDIC systems is UTF-8.
202
+
203
+ If the output contains characters that cannot be represented in this encoding,
204
+ that is an error that will be reported as configured by the B<--errors>
205
+ option. If error handling is other than C<die>, the unrepresentable character
206
+ will be replaced with the Encode substitution character (normally C<?>).
207
+
208
+ If the C<encoding> option is set to the special value C<groff> (the default on
209
+ EBCDIC systems), or if the Encode module is not available and the encoding is
210
+ set to anything other than C<roff> (see below), Pod::Man will translate all
211
+ non-ASCII characters to C<\[uNNNN]> Unicode escapes. These are not
212
+ traditionally part of the *roff language, but are supported by B<groff> and
213
+ B<mandoc> and thus by the majority of manual page processors in use today.
214
+
215
+ If I<encoding> is set to the special value C<roff>, B<pod2man> will do its
216
+ historic transformation of (some) ISO 8859-1 characters into *roff escapes
217
+ that may be adequate in troff and may be readable (if ugly) in nroff. This
218
+ was the default behavior of versions of B<pod2man> before 5.00. With this
219
+ encoding, all other non-ASCII characters will be replaced with C<X>. It may
220
+ be required for very old troff and nroff implementations that do not support
221
+ UTF-8, but its representation of any non-ASCII character is very poor and
222
+ often specific to European languages. Its use is discouraged.
223
+
224
+ WARNING: The input encoding of the POD source is independent from the output
225
+ encoding, and setting this option does not affect the interpretation of the
226
+ POD input. Unless your POD source is US-ASCII, its encoding should be
227
+ declared with the C<=encoding> command in the source. If this is not done,
228
+ Pod::Simple will will attempt to guess the encoding and may be successful if
229
+ it's Latin-1 or UTF-8, but it will produce warnings. See L<perlpod(1)> for
230
+ more information.
231
+
232
+ =item B<--errors>=I<style>
233
+
234
+ [2.5.0] Set the error handling style. C<die> says to throw an exception on
235
+ any POD formatting error. C<stderr> says to report errors on standard error,
236
+ but not to throw an exception. C<pod> says to include a POD ERRORS section in
237
+ the resulting documentation summarizing the errors. C<none> ignores POD
238
+ errors entirely, as much as possible.
239
+
240
+ The default is C<die>.
241
+
242
+ =item B<--fixed>=I<font>
243
+
244
+ [1.0] The fixed-width font to use for verbatim text and code. Defaults to
245
+ C<CW>. Some systems may want C<CR> instead. Only matters for B<troff>
246
+ output.
247
+
248
+ =item B<--fixedbold>=I<font>
249
+
250
+ [1.0] Bold version of the fixed-width font. Defaults to C<CB>. Only matters
251
+ for B<troff> output.
252
+
253
+ =item B<--fixeditalic>=I<font>
254
+
255
+ [1.0] Italic version of the fixed-width font (something of a misnomer, since
256
+ most fixed-width fonts only have an oblique version, not an italic version).
257
+ Defaults to C<CI>. Only matters for B<troff> output.
258
+
259
+ =item B<--fixedbolditalic>=I<font>
260
+
261
+ [1.0] Bold italic (in theory, probably oblique in practice) version of the
262
+ fixed-width font. Pod::Man doesn't assume you have this, and defaults to
263
+ C<CB>. Some systems (such as Solaris) have this font available as C<CX>.
264
+ Only matters for B<troff> output.
265
+
266
+ =item B<--guesswork>=I<rule>[,I<rule>...]
267
+
268
+ [5.00] By default, B<pod2man> applies some default formatting rules based on
269
+ guesswork and regular expressions that are intended to make writing Perl
270
+ documentation easier and require less explicit markup. These rules may not
271
+ always be appropriate, particularly for documentation that isn't about Perl.
272
+ This option allows turning all or some of it off.
273
+
274
+ The special rule C<all> enables all guesswork. This is also the default for
275
+ backward compatibility reasons. The special rule C<none> disables all
276
+ guesswork. Otherwise, the value of this option should be a comma-separated
277
+ list of one or more of the following keywords:
278
+
279
+ =over 4
280
+
281
+ =item functions
282
+
283
+ Convert function references like C<foo()> to bold even if they have no markup.
284
+ The function name accepts valid Perl characters for function names (including
285
+ C<:>), and the trailing parentheses must be present and empty.
286
+
287
+ =item manref
288
+
289
+ Make the first part (before the parentheses) of man page references like
290
+ C<foo(1)> bold even if they have no markup. The section must be a single
291
+ number optionally followed by lowercase letters.
292
+
293
+ =item quoting
294
+
295
+ If no guesswork is enabled, any text enclosed in CZ<><> is surrounded by
296
+ double quotes in nroff (terminal) output unless the contents are already
297
+ quoted. When this guesswork is enabled, quote marks will also be suppressed
298
+ for Perl variables, function names, function calls, numbers, and hex
299
+ constants.
300
+
301
+ =item variables
302
+
303
+ Convert Perl variable names to a fixed-width font even if they have no markup.
304
+ This transformation will only be apparent in troff output, or some other
305
+ output format (unlike nroff terminal output) that supports fixed-width fonts.
306
+
307
+ =back
308
+
309
+ Any unknown guesswork name is silently ignored (for potential future
310
+ compatibility), so be careful about spelling.
311
+
312
+ =item B<-h>, B<--help>
313
+
314
+ [1.00] Print out usage information.
315
+
316
+ =item B<-l>, B<--lax>
317
+
318
+ [1.00] No longer used. B<pod2man> used to check its input for validity as a
319
+ manual page, but this should now be done by L<podchecker(1)> instead.
320
+ Accepted for backward compatibility; this option no longer does anything.
321
+
322
+ =item B<--language>=I<language>
323
+
324
+ [5.00] Add commands telling B<groff> that the input file is in the given
325
+ language. The value of this setting must be a language abbreviation for which
326
+ B<groff> provides supplemental configuration, such as C<ja> (for Japanese) or
327
+ C<zh> (for Chinese).
328
+
329
+ This adds:
330
+
331
+ .mso <language>.tmac
332
+ .hla <language>
333
+
334
+ to the start of the file, which configure correct line breaking for the
335
+ specified language. Without these commands, groff may not know how to add
336
+ proper line breaks for Chinese and Japanese text if the man page is installed
337
+ into the normal man page directory, such as F</usr/share/man>.
338
+
339
+ On many systems, this will be done automatically if the man page is installed
340
+ into a language-specific man page directory, such as F</usr/share/man/zh_CN>.
341
+ In that case, this option is not required.
342
+
343
+ Unfortunately, the commands added with this option are specific to B<groff>
344
+ and will not work with other B<troff> and B<nroff> implementations.
345
+
346
+ =item B<--lquote>=I<quote>
347
+
348
+ =item B<--rquote>=I<quote>
349
+
350
+ [4.08] Sets the quote marks used to surround CE<lt>> text. B<--lquote> sets
351
+ the left quote mark and B<--rquote> sets the right quote mark. Either may
352
+ also be set to the special value C<none>, in which case no quote mark is added
353
+ on that side of CE<lt>> text (but the font is still changed for troff output).
354
+
355
+ Also see the B<--quotes> option, which can be used to set both quotes at once.
356
+ If both B<--quotes> and one of the other options is set, B<--lquote> or
357
+ B<--rquote> overrides B<--quotes>.
358
+
359
+ =item B<-n> I<name>, B<--name>=I<name>
360
+
361
+ [4.08] Set the name of the manual page for the C<.TH> macro to I<name>.
362
+ Without this option, the manual name is set to the uppercased base name of the
363
+ file being converted unless the manual section is 3, in which case the path is
364
+ parsed to see if it is a Perl module path. If it is, a path like
365
+ C<.../lib/Pod/Man.pm> is converted into a name like C<Pod::Man>. This option,
366
+ if given, overrides any automatic determination of the name.
367
+
368
+ Although one does not have to follow this convention, be aware that the
369
+ convention for UNIX manual pages is for the title to be in all-uppercase, even
370
+ if the command isn't. (Perl modules traditionally use mixed case for the
371
+ manual page title, however.)
372
+
373
+ This option is probably not useful when converting multiple POD files at once.
374
+
375
+ When converting POD source from standard input, the name will be set to
376
+ C<STDIN> if this option is not provided. Providing this option is strongly
377
+ recommended to set a meaningful manual page name.
378
+
379
+ =item B<--nourls>
380
+
381
+ [2.5.0] Normally, LZ<><> formatting codes with a URL but anchor text are
382
+ formatted to show both the anchor text and the URL. In other words:
383
+
384
+ =for ProhibitVerbatimMarkup allow next
385
+
386
+ L<foo|http://example.com/>
387
+
388
+ is formatted as:
389
+
390
+ foo <http://example.com/>
391
+
392
+ This flag, if given, suppresses the URL when anchor text is given, so this
393
+ example would be formatted as just C<foo>. This can produce less
394
+ cluttered output in cases where the URLs are not particularly important.
395
+
396
+ =item B<-o>, B<--official>
397
+
398
+ [1.00] Set the default header to indicate that this page is part of the
399
+ standard Perl release, if B<--center> is not also given.
400
+
401
+ =item B<-q> I<quotes>, B<--quotes>=I<quotes>
402
+
403
+ [4.00] Sets the quote marks used to surround CE<lt>> text to I<quotes>. If
404
+ I<quotes> is a single character, it is used as both the left and right quote.
405
+ Otherwise, it is split in half, and the first half of the string is used as
406
+ the left quote and the second is used as the right quote.
407
+
408
+ I<quotes> may also be set to the special value C<none>, in which case no quote
409
+ marks are added around CE<lt>> text (but the font is still changed for troff
410
+ output).
411
+
412
+ Also see the B<--lquote> and B<--rquote> options, which can be used to set the
413
+ left and right quotes independently. If both B<--quotes> and one of the other
414
+ options is set, B<--lquote> or B<--rquote> overrides B<--quotes>.
415
+
416
+ =item B<-r> I<version>, B<--release>=I<version>
417
+
418
+ [1.00] Set the centered footer for the C<.TH> macro to I<version>. By
419
+ default, this is set to the version of Perl you run B<pod2man> under. Setting
420
+ this to the empty string will cause some *roff implementations to use the
421
+ system default value.
422
+
423
+ Note that some system C<an> macro sets assume that the centered footer will be
424
+ a modification date and will prepend something like C<Last modified: >. If
425
+ this is the case for your target system, you may want to set B<--release> to
426
+ the last modified date and B<--date> to the version number.
427
+
428
+ =item B<-s> I<string>, B<--section>=I<string>
429
+
430
+ [1.00] Set the section for the C<.TH> macro. The standard section numbering
431
+ convention is to use 1 for user commands, 2 for system calls, 3 for functions,
432
+ 4 for devices, 5 for file formats, 6 for games, 7 for miscellaneous
433
+ information, and 8 for administrator commands. There is a lot of variation
434
+ here, however; some systems (like Solaris) use 4 for file formats, 5 for
435
+ miscellaneous information, and 7 for devices. Still others use 1m instead of
436
+ 8, or some mix of both. About the only section numbers that are reliably
437
+ consistent are 1, 2, and 3.
438
+
439
+ By default, section 1 will be used unless the file ends in C<.pm>, in which
440
+ case section 3 will be selected.
441
+
442
+ =item B<--stderr>
443
+
444
+ [2.1.3] By default, B<pod2man> dies if any errors are detected in the POD
445
+ input. If B<--stderr> is given and no B<--errors> flag is present, errors are
446
+ sent to standard error, but B<pod2man> does not abort. This is equivalent to
447
+ C<--errors=stderr> and is supported for backward compatibility.
448
+
449
+ =item B<-u>, B<--utf8>
450
+
451
+ [2.1.0] This option used to tell B<pod2man> to produce UTF-8 output. Since
452
+ this is now the default as of version 5.00, it is ignored and does nothing.
453
+
454
+ =item B<-v>, B<--verbose>
455
+
456
+ [1.11] Print out the name of each output file as it is being generated.
457
+
458
+ =back
459
+
460
+ =head1 EXIT STATUS
461
+
462
+ As long as all documents processed result in some output, even if that output
463
+ includes errata (a C<POD ERRORS> section generated with C<--errors=pod>),
464
+ B<pod2man> will exit with status 0. If any of the documents being processed
465
+ do not result in an output document, B<pod2man> will exit with status 1. If
466
+ there are syntax errors in a POD document being processed and the error
467
+ handling style is set to the default of C<die>, B<pod2man> will abort
468
+ immediately with exit status 255.
469
+
470
+ =head1 DIAGNOSTICS
471
+
472
+ If B<pod2man> fails with errors, see L<Pod::Man> and L<Pod::Simple> for
473
+ information about what those errors might mean.
474
+
475
+ =head1 EXAMPLES
476
+
477
+ pod2man program > program.1
478
+ pod2man SomeModule.pm /usr/perl/man/man3/SomeModule.3
479
+ pod2man --section=7 note.pod > note.7
480
+
481
+ If you would like to print out a lot of man page continuously, you probably
482
+ want to set the C and D registers to set contiguous page numbering and
483
+ even/odd paging, at least on some versions of man(7).
484
+
485
+ troff -man -rC1 -rD1 perl.1 perldata.1 perlsyn.1 ...
486
+
487
+ To get index entries on C<STDERR>, turn on the F register, as in:
488
+
489
+ troff -man -rF1 perl.1
490
+
491
+ The indexing merely outputs messages via C<.tm> for each major page, section,
492
+ subsection, item, and any C<XE<lt>E<gt>> directives.
493
+
494
+ =head1 AUTHOR
495
+
496
+ Russ Allbery <rra@cpan.org>, based on the original B<pod2man> by Larry Wall
497
+ and Tom Christiansen.
498
+
499
+ =head1 COPYRIGHT AND LICENSE
500
+
501
+ Copyright 1999-2001, 2004, 2006, 2008, 2010, 2012-2019, 2022-2024 Russ Allbery
502
+ <rra@cpan.org>
503
+
504
+ This program is free software; you may redistribute it and/or modify it
505
+ under the same terms as Perl itself.
506
+
507
+ =head1 SEE ALSO
508
+
509
+ L<Pod::Man>, L<Pod::Simple>, L<man(1)>, L<nroff(1)>, L<perlpod(1)>,
510
+ L<podchecker(1)>, L<perlpodstyle(1)>, L<troff(1)>
511
+
512
+ The man page documenting the C<an> macro set is usually either L<man(7)> or
513
+ L<man(5)> depending on the system.
514
+
515
+ The current version of this script is always available from its web site at
516
+ L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
517
+ Perl core distribution as of 5.6.0.
518
+
519
+ =cut
git/usr/bin/core_perl/pod2text ADDED
@@ -0,0 +1,367 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+
5
+ # Convert POD data to formatted ASCII text.
6
+ #
7
+ # The driver script for Pod::Text, Pod::Text::Termcap, and Pod::Text::Color,
8
+ # invoked by perldoc -t among other things.
9
+ #
10
+ # SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
11
+
12
+ use 5.012;
13
+ use warnings;
14
+
15
+ use Getopt::Long qw(GetOptions);
16
+ use Pod::Text ();
17
+ use Pod::Usage qw(pod2usage);
18
+
19
+ # Clean up $0 for error reporting.
20
+ $0 =~ s%.*/%%;
21
+
22
+ # Take an initial pass through our options, looking for one of the form
23
+ # -<number>. We turn that into -w <number> for compatibility with the
24
+ # original pod2text script.
25
+ for (my $i = 0; $i < @ARGV; $i++) {
26
+ last if $ARGV[$i] =~ /^--$/;
27
+ if ($ARGV[$i] =~ /^-(\d+)$/) {
28
+ splice (@ARGV, $i++, 1, '-w', $1);
29
+ }
30
+ }
31
+
32
+ # Insert -- into @ARGV before any single dash argument to hide it from
33
+ # Getopt::Long; we want to interpret it as meaning stdin (which Pod::Simple
34
+ # does correctly).
35
+ my $stdin;
36
+ @ARGV = map { $_ eq '-' && !$stdin++ ? ('--', $_) : $_ } @ARGV;
37
+
38
+ # Parse our options. Use the same names as Pod::Text for simplicity.
39
+ my %options;
40
+ Getopt::Long::config ('bundling');
41
+ GetOptions (\%options, 'alt|a', 'code', 'color|c', 'encoding|e=s', 'errors=s',
42
+ 'guesswork=s', 'help|h', 'indent|i=i', 'loose|l',
43
+ 'margin|left-margin|m=i', 'nourls', 'overstrike|o', 'quotes|q=s',
44
+ 'sentence|s', 'stderr', 'termcap|t', 'utf8|u', 'width|w=i')
45
+ or exit 1;
46
+ pod2usage (0) if $options{help};
47
+
48
+ # Figure out what formatter we're going to use. -c overrides -t.
49
+ my $formatter = 'Pod::Text';
50
+ if ($options{color}) {
51
+ $formatter = 'Pod::Text::Color';
52
+ eval { require Term::ANSIColor };
53
+ if ($@) { die "-c (--color) requires Term::ANSIColor be installed\n" }
54
+ require Pod::Text::Color;
55
+ } elsif ($options{termcap}) {
56
+ $formatter = 'Pod::Text::Termcap';
57
+ require Pod::Text::Termcap;
58
+ } elsif ($options{overstrike}) {
59
+ $formatter = 'Pod::Text::Overstrike';
60
+ require Pod::Text::Overstrike;
61
+ }
62
+ delete @options{'color', 'termcap', 'overstrike'};
63
+
64
+ # If neither stderr nor errors is set, default to errors = die.
65
+ if (!defined $options{stderr} && !defined $options{errors}) {
66
+ $options{errors} = 'die';
67
+ }
68
+
69
+ # Initialize and run the formatter.
70
+ my $parser = $formatter->new (%options);
71
+ my $status = 0;
72
+ do {
73
+ my ($input, $output) = splice (@ARGV, 0, 2);
74
+ $parser->parse_from_file ($input, $output);
75
+ if ($parser->{CONTENTLESS}) {
76
+ $status = 1;
77
+ if (defined $input) {
78
+ warn "$0: unable to format $input\n";
79
+ } else {
80
+ warn "$0: unable to format standard input\n";
81
+ }
82
+ if (defined ($output) and $output ne '-') {
83
+ unlink $output unless (-s $output);
84
+ }
85
+ }
86
+ } while (@ARGV);
87
+ exit $status;
88
+
89
+ __END__
90
+
91
+ =for stopwords
92
+ -aclostu --alt --stderr Allbery --overstrike overstrike --termcap --utf8
93
+ UTF-8 subclasses --nourls EBCDIC unrepresentable
94
+
95
+ =head1 NAME
96
+
97
+ pod2text - Convert POD data to formatted ASCII text
98
+
99
+ =head1 SYNOPSIS
100
+
101
+ pod2text [B<-aclostu>] [B<--code>] S<[B<-e> I<encoding>]>
102
+ [B<--errors>=I<style>] [B<--guesswork>=I<rule>[,I<rule>...]]
103
+ S<[B<-i> I<indent>]> S<[B<-q> I<quotes>]>
104
+ [B<--nourls>] [B<--stderr>] S<[B<-w> I<width>]> [I<input> [I<output> ...]]
105
+
106
+ pod2text B<-h>
107
+
108
+ =head1 DESCRIPTION
109
+
110
+ B<pod2text> is a wrapper script around the L<Pod::Text> and its subclasses.
111
+ It uses them to generate formatted text from POD source. It can optionally
112
+ use either termcap sequences or ANSI color escape sequences to format the
113
+ text.
114
+
115
+ I<input> is the file to read for POD source (the POD can be embedded in code).
116
+ If I<input> isn't given, it defaults to C<STDIN>. I<output>, if given, is the
117
+ file to which to write the formatted output. If I<output> isn't given, the
118
+ formatted output is written to C<STDOUT>. Several POD files can be processed
119
+ in the same B<pod2text> invocation (saving module load and compile times) by
120
+ providing multiple pairs of I<input> and I<output> files on the command line.
121
+
122
+ By default, the output encoding is the same as the encoding of the input file,
123
+ or UTF-8 if that encoding is not set (except on EBCDIC systems). See the
124
+ B<-e> option to explicitly set the output encoding and L<Pod::Text/Encoding>
125
+ for more discussion.
126
+
127
+ =head1 OPTIONS
128
+
129
+ Each option is annotated with the version of podlators in which that option
130
+ was added with its current meaning.
131
+
132
+ =over 4
133
+
134
+ =item B<-a>, B<--alt>
135
+
136
+ [1.00] Use an alternate output format that, among other things, uses a
137
+ different heading style and marks C<=item> entries with a colon in the left
138
+ margin.
139
+
140
+ =item B<--code>
141
+
142
+ [1.11] Include any non-POD text from the input file in the output as well.
143
+ Useful for viewing code documented with POD blocks with the POD rendered and
144
+ the code left intact.
145
+
146
+ =item B<-c>, B<--color>
147
+
148
+ [1.00] Format the output with ANSI color escape sequences. Using this option
149
+ requires that Term::ANSIColor be installed on your system.
150
+
151
+ =item B<-e> I<encoding>, B<--encoding>=I<encoding>
152
+
153
+ [5.00] Specifies the encoding of the output. I<encoding> must be an encoding
154
+ recognized by the L<Encode> module (see L<Encode::Supported>). If the output
155
+ contains characters that cannot be represented in this encoding, that is an
156
+ error that will be reported as configured by the C<errors> option. If error
157
+ handling is other than C<die>, the unrepresentable character will be replaced
158
+ with the Encode substitution character (normally C<?>).
159
+
160
+ WARNING: The input encoding of the POD source is independent from the output
161
+ encoding, and setting this option does not affect the interpretation of the
162
+ POD input. Unless your POD source is US-ASCII, its encoding should be
163
+ declared with the C<=encoding> command in the source, as near to the top of
164
+ the file as possible. If this is not done, Pod::Simple will will attempt to
165
+ guess the encoding and may be successful if it's Latin-1 or UTF-8, but it will
166
+ produce warnings. See L<perlpod(1)> for more information.
167
+
168
+ =item B<--errors>=I<style>
169
+
170
+ [2.5.0] Set the error handling style. C<die> says to throw an exception on
171
+ any POD formatting error. C<stderr> says to report errors on standard error,
172
+ but not to throw an exception. C<pod> says to include a POD ERRORS section in
173
+ the resulting documentation summarizing the errors. C<none> ignores POD
174
+ errors entirely, as much as possible.
175
+
176
+ The default is C<die>.
177
+
178
+ =item B<--guesswork>=I<rule>[,I<rule>...]
179
+
180
+ [5.01] By default, B<pod2text> applies some default formatting rules based on
181
+ guesswork and regular expressions that are intended to make writing Perl
182
+ documentation easier and require less explicit markup. These rules may not
183
+ always be appropriate, particularly for documentation that isn't about Perl.
184
+ This option allows turning all or some of it off.
185
+
186
+ The special rule C<all> enables all guesswork. This is also the default for
187
+ backward compatibility reasons. The special rule C<none> disables all
188
+ guesswork. Otherwise, the value of this option should be a comma-separated
189
+ list of one or more of the following keywords:
190
+
191
+ =over 4
192
+
193
+ =item quoting
194
+
195
+ If no guesswork is enabled, any text enclosed in CZ<><> is surrounded by
196
+ double quotes in nroff (terminal) output unless the contents are already
197
+ quoted. When this guesswork is enabled, quote marks will also be suppressed
198
+ for Perl variables, function names, function calls, numbers, and hex
199
+ constants.
200
+
201
+ =back
202
+
203
+ Any unknown guesswork name is silently ignored (for potential future
204
+ compatibility), so be careful about spelling.
205
+
206
+ =item B<-i> I<indent>, B<--indent=>I<indent>
207
+
208
+ [1.00] Set the number of spaces to indent regular text, and the default
209
+ indentation for C<=over> blocks. Defaults to 4 spaces if this option isn't
210
+ given.
211
+
212
+ =item B<-h>, B<--help>
213
+
214
+ [1.00] Print out usage information and exit.
215
+
216
+ =item B<-l>, B<--loose>
217
+
218
+ [1.00] Print a blank line after a C<=head1> heading. Normally, no blank line
219
+ is printed after C<=head1>, although one is still printed after C<=head2>,
220
+ because this is the expected formatting for manual pages; if you're formatting
221
+ arbitrary text documents, using this option is recommended.
222
+
223
+ =item B<-m> I<width>, B<--left-margin>=I<width>, B<--margin>=I<width>
224
+
225
+ [1.24] The width of the left margin in spaces. Defaults to 0. This is the
226
+ margin for all text, including headings, not the amount by which regular text
227
+ is indented; for the latter, see B<-i> option.
228
+
229
+ =item B<--nourls>
230
+
231
+ [2.5.0] Normally, LZ<><> formatting codes with a URL but anchor text are
232
+ formatted to show both the anchor text and the URL. In other words:
233
+
234
+ L<foo|http://example.com/>
235
+
236
+ is formatted as:
237
+
238
+ foo <http://example.com/>
239
+
240
+ This flag, if given, suppresses the URL when anchor text is given, so this
241
+ example would be formatted as just C<foo>. This can produce less cluttered
242
+ output in cases where the URLs are not particularly important.
243
+
244
+ =item B<-o>, B<--overstrike>
245
+
246
+ [1.06] Format the output with overstrike printing. Bold text is rendered as
247
+ character, backspace, character. Italics and file names are rendered as
248
+ underscore, backspace, character. Many pagers, such as B<less>, know how to
249
+ convert this to bold or underlined text.
250
+
251
+ =item B<-q> I<quotes>, B<--quotes>=I<quotes>
252
+
253
+ [4.00] Sets the quote marks used to surround CE<lt>> text to I<quotes>. If
254
+ I<quotes> is a single character, it is used as both the left and right quote.
255
+ Otherwise, it is split in half, and the first half of the string is used as
256
+ the left quote and the second is used as the right quote.
257
+
258
+ I<quotes> may also be set to the special value C<none>, in which case no quote
259
+ marks are added around CE<lt>> text.
260
+
261
+ =item B<-s>, B<--sentence>
262
+
263
+ [1.00] Assume each sentence ends with two spaces and try to preserve that
264
+ spacing. Without this option, all consecutive whitespace in non-verbatim
265
+ paragraphs is compressed into a single space.
266
+
267
+ =item B<--stderr>
268
+
269
+ [2.1.3] By default, B<pod2text> dies if any errors are detected in the POD
270
+ input. If B<--stderr> is given and no B<--errors> flag is present, errors are
271
+ sent to standard error, but B<pod2text> does not abort. This is equivalent to
272
+ C<--errors=stderr> and is supported for backward compatibility.
273
+
274
+ =item B<-t>, B<--termcap>
275
+
276
+ [1.00] Try to determine the width of the screen and the bold and underline
277
+ sequences for the terminal from termcap, and use that information in
278
+ formatting the output. Output will be wrapped at two columns less than the
279
+ width of your terminal device. Using this option requires that your system
280
+ have a termcap file somewhere where Term::Cap can find it and requires that
281
+ your system support termios. With this option, the output of B<pod2text> will
282
+ contain terminal control sequences for your current terminal type.
283
+
284
+ =item B<-u>, B<--utf8>
285
+
286
+ [2.2.0] Set the output encoding to UTF-8. This is equivalent to
287
+ C<--encoding=UTF-8> and is supported for backward compatibility.
288
+
289
+ =item B<-w>, B<--width=>I<width>, B<->I<width>
290
+
291
+ [1.00] The column at which to wrap text on the right-hand side. Defaults to
292
+ 76, unless B<-t> is given, in which case it's two columns less than the width
293
+ of your terminal device.
294
+
295
+ =back
296
+
297
+ =head1 EXIT STATUS
298
+
299
+ As long as all documents processed result in some output, even if that output
300
+ includes errata (a C<POD ERRORS> section generated with C<--errors=pod>),
301
+ B<pod2text> will exit with status 0. If any of the documents being processed
302
+ do not result in an output document, B<pod2text> will exit with status 1. If
303
+ there are syntax errors in a POD document being processed and the error
304
+ handling style is set to the default of C<die>, B<pod2text> will abort
305
+ immediately with exit status 255.
306
+
307
+ =head1 DIAGNOSTICS
308
+
309
+ If B<pod2text> fails with errors, see L<Pod::Text> and L<Pod::Simple> for
310
+ information about what those errors might mean. Internally, it can also
311
+ produce the following diagnostics:
312
+
313
+ =over 4
314
+
315
+ =item -c (--color) requires Term::ANSIColor be installed
316
+
317
+ (F) B<-c> or B<--color> were given, but Term::ANSIColor could not be loaded.
318
+
319
+ =item Unknown option: %s
320
+
321
+ (F) An unknown command line option was given.
322
+
323
+ =back
324
+
325
+ In addition, other L<Getopt::Long> error messages may result from invalid
326
+ command-line options.
327
+
328
+ =head1 ENVIRONMENT
329
+
330
+ =over 4
331
+
332
+ =item COLUMNS
333
+
334
+ If B<-t> is given, B<pod2text> will take the current width of your screen from
335
+ this environment variable, if available. It overrides terminal width
336
+ information in TERMCAP.
337
+
338
+ =item TERMCAP
339
+
340
+ If B<-t> is given, B<pod2text> will use the contents of this environment
341
+ variable if available to determine the correct formatting sequences for your
342
+ current terminal device.
343
+
344
+ =back
345
+
346
+ =head1 AUTHOR
347
+
348
+ Russ Allbery <rra@cpan.org>.
349
+
350
+ =head1 COPYRIGHT AND LICENSE
351
+
352
+ Copyright 1999-2001, 2004, 2006, 2008, 2010, 2012-2019, 2022, 2024 Russ
353
+ Allbery <rra@cpan.org>
354
+
355
+ This program is free software; you may redistribute it and/or modify it
356
+ under the same terms as Perl itself.
357
+
358
+ =head1 SEE ALSO
359
+
360
+ L<Encode::Supported>, L<Pod::Text>, L<Pod::Text::Color>,
361
+ L<Pod::Text::Overstrike>, L<Pod::Text::Termcap>, L<Pod::Simple>, L<perlpod(1)>
362
+
363
+ The current version of this script is always available from its web site at
364
+ L<https://www.eyrie.org/~eagle/software/podlators/>. It is also part of the
365
+ Perl core distribution as of 5.6.0.
366
+
367
+ =cut
git/usr/bin/core_perl/pod2usage ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec perl -S $0 "$@"'
3
+ if 0;
4
+
5
+ #############################################################################
6
+ # pod2usage -- command to print usage messages from embedded pod docs
7
+ #
8
+ # Copyright (c) 1996-2000 by Bradford Appleton. All rights reserved.
9
+ # Copyright (c) 2001-2016 by Marek Rouchal.
10
+ # This file is part of "Pod-Usage". Pod-Usage is free software;
11
+ # you can redistribute it and/or modify it under the same terms
12
+ # as Perl itself.
13
+ #############################################################################
14
+
15
+ use strict;
16
+ #use diagnostics;
17
+
18
+ =head1 NAME
19
+
20
+ pod2usage - print usage messages from embedded pod docs in files
21
+
22
+ =head1 SYNOPSIS
23
+
24
+ =over 12
25
+
26
+ =item B<pod2usage>
27
+
28
+ [B<-help>]
29
+ [B<-man>]
30
+ [B<-exit>S< >I<exitval>]
31
+ [B<-output>S< >I<outfile>]
32
+ [B<-verbose> I<level>]
33
+ [B<-pathlist> I<dirlist>]
34
+ [B<-formatter> I<module>]
35
+ [B<-utf8>]
36
+ I<file>
37
+
38
+ =back
39
+
40
+ =head1 OPTIONS AND ARGUMENTS
41
+
42
+ =over 8
43
+
44
+ =item B<-help>
45
+
46
+ Prints a brief help message and exit.
47
+
48
+ =item B<-man>
49
+
50
+ Prints this command's manual page and exit.
51
+
52
+ =item B<-exit> I<exitval>
53
+
54
+ The exit status value to return.
55
+
56
+ =item B<-output> I<outfile>
57
+
58
+ The output file to print to. If the special names "-" or ">&1" or ">&STDOUT"
59
+ are used then standard output is used. If ">&2" or ">&STDERR" is used then
60
+ standard error is used.
61
+
62
+ =item B<-verbose> I<level>
63
+
64
+ The desired level of verbosity to use:
65
+
66
+ 1 : print SYNOPSIS only
67
+ 2 : print SYNOPSIS sections and any OPTIONS/ARGUMENTS sections
68
+ 3 : print the entire manpage (similar to running pod2text)
69
+
70
+ =item B<-pathlist> I<dirlist>
71
+
72
+ Specifies one or more directories to search for the input file if it
73
+ was not supplied with an absolute path. Each directory path in the given
74
+ list should be separated by a ':' on Unix (';' on MSWin32 and DOS).
75
+
76
+ =item B<-formatter> I<module>
77
+
78
+ Which text formatter to use. Default is L<Pod::Text>. An alternative would
79
+ be e.g. L<Pod::Text::Termcap>.
80
+
81
+ =item B<-utf8>
82
+
83
+ This option assumes that the formatter (see above) understands the option
84
+ "utf8". It turns on generation of utf8 output.
85
+
86
+ =item I<file>
87
+
88
+ The pathname of a file containing pod documentation to be output in
89
+ usage message format. If omitted, standard input is read - but the
90
+ output is then formatted with L<Pod::Text> only - unless a specific
91
+ formatter has been specified with B<-formatter>.
92
+
93
+ =back
94
+
95
+ =head1 DESCRIPTION
96
+
97
+ B<pod2usage> will read the given input file looking for pod
98
+ documentation and will print the corresponding usage message.
99
+ If no input file is specified then standard input is read.
100
+
101
+ B<pod2usage> invokes the B<pod2usage()> function in the B<Pod::Usage>
102
+ module. Please see L<Pod::Usage/pod2usage()>.
103
+
104
+ =head1 SEE ALSO
105
+
106
+ L<Pod::Usage>, L<pod2text>, L<Pod::Text>, L<Pod::Text::Termcap>,
107
+ L<perldoc>
108
+
109
+ =head1 AUTHOR
110
+
111
+ Please report bugs using L<http://rt.cpan.org>.
112
+
113
+ Brad Appleton E<lt>bradapp@enteract.comE<gt>
114
+
115
+ Based on code for B<pod2text(1)> written by
116
+ Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
117
+
118
+ =cut
119
+
120
+ use Getopt::Long;
121
+
122
+ ## Define options
123
+ my %options = ();
124
+ my @opt_specs = (
125
+ 'help',
126
+ 'man',
127
+ 'exit=i',
128
+ 'output=s',
129
+ 'pathlist=s',
130
+ 'formatter=s',
131
+ 'verbose=i',
132
+ 'utf8!'
133
+ );
134
+
135
+ ## Parse options
136
+ GetOptions(\%options, @opt_specs) || pod2usage(2);
137
+ $Pod::Usage::Formatter = $options{formatter} if $options{formatter};
138
+ require Pod::Usage;
139
+ Pod::Usage->import();
140
+ pod2usage(1) if ($options{help});
141
+ pod2usage(VERBOSE => 2) if ($options{man});
142
+
143
+ ## Dont default to STDIN if connected to a terminal
144
+ pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
145
+
146
+ if (@ARGV > 1) {
147
+ print STDERR "pod2usage: Too many filenames given\n\n";
148
+ pod2usage(2);
149
+ }
150
+
151
+ my %usage = ();
152
+ $usage{-input} = shift(@ARGV) || \*STDIN;
153
+ $usage{-exitval} = $options{'exit'} if (defined $options{'exit'});
154
+ $usage{-output} = $options{'output'} if (defined $options{'output'});
155
+ $usage{-verbose} = $options{'verbose'} if (defined $options{'verbose'});
156
+ $usage{-pathlist} = $options{'pathlist'} if (defined $options{'pathlist'});
157
+ $usage{-utf8} = $options{'utf8'} if (defined $options{'utf8'});
158
+
159
+ pod2usage(\%usage);
160
+
161
+
git/usr/bin/core_perl/podchecker ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec perl -S $0 "$@"'
3
+ if 0;
4
+ #############################################################################
5
+ # podchecker -- command to invoke the podchecker function in Pod::Checker
6
+ #
7
+ # Copyright (c) 1998-2000 by Bradford Appleton. All rights reserved.
8
+ # This is free software; you can redistribute it and/or modify it under the
9
+ # same terms as Perl itself.
10
+ #############################################################################
11
+
12
+ use strict;
13
+ #use diagnostics;
14
+
15
+ =head1 NAME
16
+
17
+ podchecker - check the syntax of POD format documentation files
18
+
19
+ =head1 SYNOPSIS
20
+
21
+ B<podchecker> [B<-help>] [B<-man>] [B<-(no)warnings>] [I<file>S< >...]
22
+
23
+ =head1 OPTIONS AND ARGUMENTS
24
+
25
+ =over 8
26
+
27
+ =item B<-help>
28
+
29
+ Print a brief help message and exit.
30
+
31
+ =item B<-man>
32
+
33
+ Print the manual page and exit.
34
+
35
+ =item B<-quiet>
36
+
37
+ Do not print a success message.
38
+
39
+ =item B<-warnings> B<-nowarnings>
40
+
41
+ Turn on/off printing of warnings. Repeating B<-warnings> increases the
42
+ warning level, i.e. more warnings are printed. Currently increasing to
43
+ level two causes flagging of unescaped "E<lt>,E<gt>" characters.
44
+
45
+ =item I<file>
46
+
47
+ The pathname of a POD file to syntax-check (defaults to standard input).
48
+
49
+ =back
50
+
51
+ =head1 DESCRIPTION
52
+
53
+ B<podchecker> will read the given input files looking for POD
54
+ syntax errors in the POD documentation and will print any errors
55
+ it find to STDERR. At the end, it will print a status message
56
+ indicating the number of errors found.
57
+
58
+ Directories are ignored, an appropriate warning message is printed.
59
+
60
+ B<podchecker> invokes the B<podchecker()> function exported by B<Pod::Checker>
61
+ Please see L<Pod::Checker/podchecker()> for more details.
62
+
63
+ =head1 RETURN VALUE
64
+
65
+ B<podchecker> returns a 0 (zero) exit status if all specified
66
+ POD files are ok.
67
+
68
+ =head1 ERRORS
69
+
70
+ B<podchecker> returns the exit status 1 if at least one of
71
+ the given POD files has syntax errors.
72
+
73
+ The status 2 indicates that at least one of the specified
74
+ files does not contain I<any> POD commands.
75
+
76
+ Status 1 overrides status 2. If you want unambiguous
77
+ results, call B<podchecker> with one single argument only.
78
+
79
+ =head1 SEE ALSO
80
+
81
+ L<Pod::Simple> and L<Pod::Checker>
82
+
83
+ =head1 AUTHORS
84
+
85
+ Please report bugs using L<http://rt.cpan.org>.
86
+
87
+ Brad Appleton E<lt>bradapp@enteract.comE<gt>,
88
+ Marek Rouchal E<lt>marekr@cpan.orgE<gt>
89
+
90
+ Based on code for B<Pod::Text::pod2text(1)> written by
91
+ Tom Christiansen E<lt>tchrist@mox.perl.comE<gt>
92
+
93
+ =cut
94
+
95
+
96
+ use Pod::Checker;
97
+ use Pod::Usage;
98
+ use Getopt::Long;
99
+
100
+ ## Define options
101
+ my %options;
102
+
103
+ ## Parse options
104
+ GetOptions(\%options, qw(help man quiet warnings+ nowarnings)) || pod2usage(2);
105
+ pod2usage(1) if ($options{help});
106
+ pod2usage(-verbose => 2) if ($options{man});
107
+
108
+ if($options{nowarnings}) {
109
+ $options{warnings} = 0;
110
+ }
111
+ elsif(!defined $options{warnings}) {
112
+ $options{warnings} = 1; # default is warnings on
113
+ }
114
+
115
+ ## Dont default to STDIN if connected to a terminal
116
+ pod2usage(2) if ((@ARGV == 0) && (-t STDIN));
117
+
118
+ ## Invoke podchecker()
119
+ my $status = 0;
120
+ @ARGV = qw(-) unless(@ARGV);
121
+ for my $podfile (@ARGV) {
122
+ if($podfile eq '-') {
123
+ $podfile = '<&STDIN';
124
+ }
125
+ elsif(-d $podfile) {
126
+ warn "podchecker: Warning: Ignoring directory '$podfile'\n";
127
+ next;
128
+ }
129
+ my $errors =
130
+ podchecker($podfile, undef, '-warnings' => $options{warnings});
131
+ if($errors > 0) {
132
+ # errors occurred
133
+ $status = 1;
134
+ printf STDERR ("%s has %d pod syntax %s.\n",
135
+ $podfile, $errors,
136
+ ($errors == 1) ? 'error' : 'errors');
137
+ }
138
+ elsif($errors < 0) {
139
+ # no pod found
140
+ $status = 2 unless($status);
141
+ print STDERR "$podfile does not contain any pod commands.\n";
142
+ }
143
+ else {
144
+ print "$podfile pod syntax OK.\n" unless $options{quiet};
145
+ }
146
+ }
147
+ exit $status;
148
+
git/usr/bin/core_perl/prove ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!/usr/bin/perl -w
5
+
6
+ BEGIN { pop @INC if $INC[-1] eq '.' }
7
+ use strict;
8
+ use warnings;
9
+ use App::Prove;
10
+
11
+ my $app = App::Prove->new;
12
+ $app->process_args(@ARGV);
13
+ exit( $app->run ? 0 : 1 );
14
+
15
+ __END__
16
+
17
+ =head1 NAME
18
+
19
+ prove - Run tests through a TAP harness.
20
+
21
+ =head1 USAGE
22
+
23
+ prove [options] [files or directories]
24
+
25
+ =head1 OPTIONS
26
+
27
+ Boolean options:
28
+
29
+ -v, --verbose Print all test lines. Also sets TEST_VERBOSE
30
+ -l, --lib Add 'lib' to the path for your tests (-Ilib).
31
+ -b, --blib Add 'blib/lib' and 'blib/arch' to the path for
32
+ your tests
33
+ -s, --shuffle Run the tests in random order.
34
+ -c, --color Colored test output (default).
35
+ --nocolor Do not color test output.
36
+ --count Show the X/Y test count when not verbose
37
+ (default)
38
+ --nocount Disable the X/Y test count.
39
+ -D --dry Dry run. Show test that would have run.
40
+ -f, --failures Show failed tests.
41
+ -o, --comments Show comments.
42
+ --ignore-exit Ignore exit status from test scripts.
43
+ -m, --merge Merge test scripts' STDERR with their STDOUT.
44
+ -r, --recurse Recursively descend into directories.
45
+ --reverse Run the tests in reverse order.
46
+ -q, --quiet Suppress some test output while running tests.
47
+ -Q, --QUIET Only print summary results.
48
+ -p, --parse Show full list of TAP parse errors, if any.
49
+ --directives Only show results with TODO or SKIP directives.
50
+ --timer Print elapsed time after each test.
51
+ --trap Trap Ctrl-C and print summary on interrupt.
52
+ --normalize Normalize TAP output in verbose output
53
+ -T Enable tainting checks.
54
+ -t Enable tainting warnings.
55
+ -W Enable fatal warnings.
56
+ -w Enable warnings.
57
+ -h, --help Display this help
58
+ -?, Display this help
59
+ -V, --version Display the version
60
+ -H, --man Longer manpage for prove
61
+ --norc Don't process default .proverc
62
+
63
+ Options that take arguments:
64
+
65
+ -I Library paths to include.
66
+ -P Load plugin (searches App::Prove::Plugin::*.)
67
+ -M Load a module.
68
+ -e, --exec Interpreter to run the tests ('' for compiled
69
+ tests.)
70
+ --ext Set the extension for tests (default '.t')
71
+ --harness Define test harness to use. See TAP::Harness.
72
+ --formatter Result formatter to use. See FORMATTERS.
73
+ --source Load and/or configure a SourceHandler. See
74
+ SOURCE HANDLERS.
75
+ -a, --archive out.tgz Store the resulting TAP in an archive file.
76
+ -j, --jobs N Run N test jobs in parallel (try 9.)
77
+ --state=opts Control prove's persistent state.
78
+ --statefile=file Use `file` instead of `.prove` for state
79
+ --rc=rcfile Process options from rcfile
80
+ --rules Rules for parallel vs sequential processing.
81
+
82
+ =head1 NOTES
83
+
84
+ =head2 .proverc
85
+
86
+ If F<~/.proverc> or F<./.proverc> exist they will be read and any
87
+ options they contain processed before the command line options. Options
88
+ in F<.proverc> are specified in the same way as command line options:
89
+
90
+ # .proverc
91
+ --state=hot,fast,save
92
+ -j9
93
+
94
+ Additional option files may be specified with the C<--rc> option.
95
+ Default option file processing is disabled by the C<--norc> option.
96
+
97
+ Under Windows and VMS the option file is named F<_proverc> rather than
98
+ F<.proverc> and is sought only in the current directory.
99
+
100
+ =head2 Reading from C<STDIN>
101
+
102
+ If you have a list of tests (or URLs, or anything else you want to test) in a
103
+ file, you can add them to your tests by using a '-':
104
+
105
+ prove - < my_list_of_things_to_test.txt
106
+
107
+ See the C<README> in the C<examples> directory of this distribution.
108
+
109
+ =head2 Default Test Directory
110
+
111
+ If no files or directories are supplied, C<prove> looks for all files
112
+ matching the pattern C<t/*.t>.
113
+
114
+ =head2 Colored Test Output
115
+
116
+ Colored test output using L<TAP::Formatter::Color> is the default, but
117
+ if output is not to a terminal, color is disabled. You can override this by
118
+ adding the C<--color> switch.
119
+
120
+ Color support requires L<Term::ANSIColor> and, on windows platforms, also
121
+ L<Win32::Console::ANSI>. If the necessary module(s) are not installed
122
+ colored output will not be available.
123
+
124
+ =head2 Exit Code
125
+
126
+ If the tests fail C<prove> will exit with non-zero status.
127
+
128
+ =head2 Arguments to Tests
129
+
130
+ It is possible to supply arguments to tests. To do so separate them from
131
+ prove's own arguments with the arisdottle, '::'. For example
132
+
133
+ prove -v t/mytest.t :: --url http://example.com
134
+
135
+ would run F<t/mytest.t> with the options '--url http://example.com'.
136
+ When running multiple tests they will each receive the same arguments.
137
+
138
+ =head2 C<--exec>
139
+
140
+ Normally you can just pass a list of Perl tests and the harness will know how
141
+ to execute them. However, if your tests are not written in Perl or if you
142
+ want all tests invoked exactly the same way, use the C<-e>, or C<--exec>
143
+ switch:
144
+
145
+ prove --exec '/usr/bin/ruby -w' t/
146
+ prove --exec '/usr/bin/perl -Tw -mstrict -Ilib' t/
147
+ prove --exec '/path/to/my/customer/exec'
148
+
149
+ =head2 C<--merge>
150
+
151
+ If you need to make sure your diagnostics are displayed in the correct
152
+ order relative to test results you can use the C<--merge> option to
153
+ merge the test scripts' STDERR into their STDOUT.
154
+
155
+ This guarantees that STDOUT (where the test results appear) and STDERR
156
+ (where the diagnostics appear) will stay in sync. The harness will
157
+ display any diagnostics your tests emit on STDERR.
158
+
159
+ Caveat: this is a bit of a kludge. In particular note that if anything
160
+ that appears on STDERR looks like a test result the test harness will
161
+ get confused. Use this option only if you understand the consequences
162
+ and can live with the risk.
163
+
164
+ =head2 C<--trap>
165
+
166
+ The C<--trap> option will attempt to trap SIGINT (Ctrl-C) during a test
167
+ run and display the test summary even if the run is interrupted
168
+
169
+ =head2 C<--state>
170
+
171
+ You can ask C<prove> to remember the state of previous test runs and
172
+ select and/or order the tests to be run based on that saved state.
173
+
174
+ The C<--state> switch requires an argument which must be a comma
175
+ separated list of one or more of the following options.
176
+
177
+ =over
178
+
179
+ =item C<last>
180
+
181
+ Run the same tests as the last time the state was saved. This makes it
182
+ possible, for example, to recreate the ordering of a shuffled test.
183
+
184
+ # Run all tests in random order
185
+ $ prove -b --state=save --shuffle
186
+
187
+ # Run them again in the same order
188
+ $ prove -b --state=last
189
+
190
+ =item C<failed>
191
+
192
+ Run only the tests that failed on the last run.
193
+
194
+ # Run all tests
195
+ $ prove -b --state=save
196
+
197
+ # Run failures
198
+ $ prove -b --state=failed
199
+
200
+ If you also specify the C<save> option newly passing tests will be
201
+ excluded from subsequent runs.
202
+
203
+ # Repeat until no more failures
204
+ $ prove -b --state=failed,save
205
+
206
+ =item C<passed>
207
+
208
+ Run only the passed tests from last time. Useful to make sure that no
209
+ new problems have been introduced.
210
+
211
+ =item C<all>
212
+
213
+ Run all tests in normal order. Multiple options may be specified, so to
214
+ run all tests with the failures from last time first:
215
+
216
+ $ prove -b --state=failed,all,save
217
+
218
+ =item C<hot>
219
+
220
+ Run the tests that most recently failed first. The last failure time of
221
+ each test is stored. The C<hot> option causes tests to be run in most-recent-
222
+ failure order.
223
+
224
+ $ prove -b --state=hot,save
225
+
226
+ Tests that have never failed will not be selected. To run all tests with
227
+ the most recently failed first use
228
+
229
+ $ prove -b --state=hot,all,save
230
+
231
+ This combination of options may also be specified thus
232
+
233
+ $ prove -b --state=adrian
234
+
235
+ =item C<todo>
236
+
237
+ Run any tests with todos.
238
+
239
+ =item C<slow>
240
+
241
+ Run the tests in slowest to fastest order. This is useful in conjunction
242
+ with the C<-j> parallel testing switch to ensure that your slowest tests
243
+ start running first.
244
+
245
+ $ prove -b --state=slow -j9
246
+
247
+ =item C<fast>
248
+
249
+ Run test tests in fastest to slowest order.
250
+
251
+ =item C<new>
252
+
253
+ Run the tests in newest to oldest order based on the modification times
254
+ of the test scripts.
255
+
256
+ =item C<old>
257
+
258
+ Run the tests in oldest to newest order.
259
+
260
+ =item C<fresh>
261
+
262
+ Run those test scripts that have been modified since the last test run.
263
+
264
+ =item C<save>
265
+
266
+ Save the state on exit. The state is stored in a file called F<.prove>
267
+ (F<_prove> on Windows and VMS) in the current directory.
268
+
269
+ =back
270
+
271
+ The C<--state> switch may be used more than once.
272
+
273
+ $ prove -b --state=hot --state=all,save
274
+
275
+ =head2 --rules
276
+
277
+ The C<--rules> option is used to control which tests are run sequentially and
278
+ which are run in parallel, if the C<--jobs> option is specified. The option may
279
+ be specified multiple times, and the order matters.
280
+
281
+ The most practical use is likely to specify that some tests are not
282
+ "parallel-ready". Since mentioning a file with --rules doesn't cause it to
283
+ be selected to run as a test, you can "set and forget" some rules preferences in
284
+ your .proverc file. Then you'll be able to take maximum advantage of the
285
+ performance benefits of parallel testing, while some exceptions are still run
286
+ in parallel.
287
+
288
+ =head3 --rules examples
289
+
290
+ # All tests are allowed to run in parallel, except those starting with "p"
291
+ --rules='seq=t/p*.t' --rules='par=**'
292
+
293
+ # All tests must run in sequence except those starting with "p", which should be run parallel
294
+ --rules='par=t/p*.t'
295
+
296
+ =head3 --rules resolution
297
+
298
+ =over 4
299
+
300
+ =item * By default, all tests are eligible to be run in parallel. Specifying any of your own rules removes this one.
301
+
302
+ =item * "First match wins". The first rule that matches a test will be the one that applies.
303
+
304
+ =item * Any test which does not match a rule will be run in sequence at the end of the run.
305
+
306
+ =item * The existence of a rule does not imply selecting a test. You must still specify the tests to run.
307
+
308
+ =item * Specifying a rule to allow tests to run in parallel does not make them run in parallel. You still need specify the number of parallel C<jobs> in your Harness object.
309
+
310
+ =back
311
+
312
+ =head3 --rules Glob-style pattern matching
313
+
314
+ We implement our own glob-style pattern matching for --rules. Here are the
315
+ supported patterns:
316
+
317
+ ** is any number of characters, including /, within a pathname
318
+ * is zero or more characters within a filename/directory name
319
+ ? is exactly one character within a filename/directory name
320
+ {foo,bar,baz} is any of foo, bar or baz.
321
+ \ is an escape character
322
+
323
+ =head3 More advanced specifications for parallel vs sequence run rules
324
+
325
+ If you need more advanced management of what runs in parallel vs in sequence, see
326
+ the associated 'rules' documentation in L<TAP::Harness> and L<TAP::Parser::Scheduler>.
327
+ If what's possible directly through C<prove> is not sufficient, you can write your own
328
+ harness to access these features directly.
329
+
330
+ =head2 @INC
331
+
332
+ prove introduces a separation between "options passed to the perl which
333
+ runs prove" and "options passed to the perl which runs tests"; this
334
+ distinction is by design. Thus the perl which is running a test starts
335
+ with the default C<@INC>. Additional library directories can be added
336
+ via the C<PERL5LIB> environment variable, via -Ifoo in C<PERL5OPT> or
337
+ via the C<-Ilib> option to F<prove>.
338
+
339
+ =head2 Taint Mode
340
+
341
+ Normally when a Perl program is run in taint mode the contents of the
342
+ C<PERL5LIB> environment variable do not appear in C<@INC>.
343
+
344
+ Because C<PERL5LIB> is often used during testing to add build
345
+ directories to C<@INC> prove passes the names of any directories found
346
+ in C<PERL5LIB> as -I switches. The net effect of this is that
347
+ C<PERL5LIB> is honoured even when prove is run in taint mode.
348
+
349
+
350
+ =head1 FORMATTERS
351
+
352
+ You can load a custom L<TAP::Parser::Formatter>:
353
+
354
+ prove --formatter MyFormatter
355
+
356
+ =head1 SOURCE HANDLERS
357
+
358
+ You can load custom L<TAP::Parser::SourceHandler>s, to change the way the
359
+ parser interprets particular I<sources> of TAP.
360
+
361
+ prove --source MyHandler --source YetAnother t
362
+
363
+ If you want to provide config to the source you can use:
364
+
365
+ prove --source MyCustom \
366
+ --source Perl --perl-option 'foo=bar baz' --perl-option avg=0.278 \
367
+ --source File --file-option extensions=.txt --file-option extensions=.tmp t
368
+ --source pgTAP --pgtap-option pset=format=html --pgtap-option pset=border=2
369
+
370
+ Each C<--$source-option> option must specify a key/value pair separated by an
371
+ C<=>. If an option can take multiple values, just specify it multiple times,
372
+ as with the C<extensions=> examples above. If the option should be a hash
373
+ reference, specify the value as a second pair separated by a C<=>, as in the
374
+ C<pset=> examples above (escape C<=> with a backslash).
375
+
376
+ All C<--sources> are combined into a hash, and passed to L<TAP::Harness/new>'s
377
+ C<sources> parameter.
378
+
379
+ See L<TAP::Parser::IteratorFactory> for more details on how configuration is
380
+ passed to I<SourceHandlers>.
381
+
382
+ =head1 PLUGINS
383
+
384
+ Plugins can be loaded using the C<< -PI<plugin> >> syntax, eg:
385
+
386
+ prove -PMyPlugin
387
+
388
+ This will search for a module named C<App::Prove::Plugin::MyPlugin>, or failing
389
+ that, C<MyPlugin>. If the plugin can't be found, C<prove> will complain & exit.
390
+
391
+ You can pass arguments to your plugin by appending C<=arg1,arg2,etc> to the
392
+ plugin name:
393
+
394
+ prove -PMyPlugin=fou,du,fafa
395
+
396
+ Please check individual plugin documentation for more details.
397
+
398
+ =head2 Available Plugins
399
+
400
+ For an up-to-date list of plugins available, please check CPAN:
401
+
402
+ L<https://metacpan.org/search?q=App%3A%3AProve+Plugin>
403
+
404
+ =head2 Writing Plugins
405
+
406
+ Please see L<App::Prove/PLUGINS>.
407
+
408
+ =cut
409
+
410
+ # vim:ts=4:sw=4:et:sta
git/usr/bin/core_perl/ptar ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!/usr/bin/perl
5
+ use strict;
6
+ use warnings;
7
+
8
+ BEGIN { pop @INC if $INC[-1] eq '.' }
9
+ use File::Find;
10
+ use Getopt::Std;
11
+ use Archive::Tar;
12
+ use Data::Dumper;
13
+
14
+ # Allow (and ignore) --format=ustar, for compatibility with GNU tar
15
+ for (my $i = 0; $i < @ARGV; ++$i) {
16
+ last if $ARGV[$i] eq '--';
17
+ splice @ARGV, $i--, 1 if $ARGV[$i] eq '--format=ustar';
18
+ splice @ARGV, $i--, 2 if $i < $#ARGV
19
+ && $ARGV[$i] eq '--format' && $ARGV[$i + 1] eq 'ustar';
20
+ }
21
+
22
+ # Allow historic support for dashless bundled options
23
+ # tar cvf file.tar
24
+ # is valid (GNU) tar style
25
+ @ARGV && $ARGV[0] =~ m/^[DdcvzthxIC]+[fT]?$/ and
26
+ unshift @ARGV, map { "-$_" } split m// => shift @ARGV;
27
+ my $opts = {};
28
+ getopts('Ddcvzthxf:ICT:', $opts) or die usage();
29
+
30
+ ### show the help message ###
31
+ die usage() if $opts->{h};
32
+
33
+ ### enable debugging (undocumented feature)
34
+ local $Archive::Tar::DEBUG = 1 if $opts->{d};
35
+
36
+ ### enable insecure extracting.
37
+ local $Archive::Tar::INSECURE_EXTRACT_MODE = 1 if $opts->{I};
38
+
39
+ ### sanity checks ###
40
+ unless ( 1 == grep { defined $opts->{$_} } qw[x t c] ) {
41
+ die "You need exactly one of 'x', 't' or 'c' options: " . usage();
42
+ }
43
+
44
+ my $compress = $opts->{z} ? 1 : 0;
45
+ my $verbose = $opts->{v} ? 1 : 0;
46
+ my $file = $opts->{f} ? $opts->{f} : 'default.tar';
47
+ my $tar = Archive::Tar->new();
48
+
49
+ if( $opts->{c} ) {
50
+ my @files;
51
+ my @src = @ARGV;
52
+ if( $opts->{T} ) {
53
+ if( $opts->{T} eq "-" ) {
54
+ chomp( @src = <STDIN> );
55
+ } elsif( open my $fh, "<", $opts->{T} ) {
56
+ chomp( @src = <$fh> );
57
+ } else {
58
+ die "$0: $opts->{T}: $!\n";
59
+ }
60
+ }
61
+
62
+ find( sub { push @files, $File::Find::name;
63
+ print $File::Find::name.$/ if $verbose }, @src );
64
+
65
+ if ($file eq '-') {
66
+ use IO::Handle;
67
+ $file = IO::Handle->new();
68
+ $file->fdopen(fileno(STDOUT),"w");
69
+ }
70
+
71
+ my $tar = Archive::Tar->new;
72
+ $tar->add_files(@files);
73
+ if( $opts->{C} ) {
74
+ for my $f ($tar->get_files) {
75
+ $f->mode($f->mode & ~022); # chmod go-w
76
+ }
77
+ }
78
+ $tar->write($file, $compress);
79
+ } else {
80
+ if ($file eq '-') {
81
+ use IO::Handle;
82
+ $file = IO::Handle->new();
83
+ $file->fdopen(fileno(STDIN),"r");
84
+ }
85
+
86
+ ### print the files we're finding?
87
+ my $print = $verbose || $opts->{'t'} || 0;
88
+
89
+ my $iter = Archive::Tar->iter( $file );
90
+
91
+ while( my $f = $iter->() ) {
92
+ print $f->full_path . $/ if $print;
93
+
94
+ ### data dumper output
95
+ print Dumper( $f ) if $opts->{'D'};
96
+
97
+ ### extract it
98
+ $f->extract if $opts->{'x'};
99
+ }
100
+ }
101
+
102
+ ### pod & usage in one
103
+ sub usage {
104
+ my $usage .= << '=cut';
105
+ =pod
106
+
107
+ =head1 NAME
108
+
109
+ ptar - a tar-like program written in perl
110
+
111
+ =head1 DESCRIPTION
112
+
113
+ ptar is a small, tar look-alike program that uses the perl module
114
+ Archive::Tar to extract, create and list tar archives.
115
+
116
+ =head1 SYNOPSIS
117
+
118
+ ptar -c [-v] [-z] [-C] [-f ARCHIVE_FILE | -] FILE FILE ...
119
+ ptar -c [-v] [-z] [-C] [-T index | -] [-f ARCHIVE_FILE | -]
120
+ ptar -x [-v] [-z] [-f ARCHIVE_FILE | -]
121
+ ptar -t [-z] [-f ARCHIVE_FILE | -]
122
+ ptar -h
123
+
124
+ =head1 OPTIONS
125
+
126
+ c Create ARCHIVE_FILE or STDOUT (-) from FILE
127
+ x Extract from ARCHIVE_FILE or STDIN (-)
128
+ t List the contents of ARCHIVE_FILE or STDIN (-)
129
+ f Name of the ARCHIVE_FILE to use. Default is './default.tar'
130
+ z Read/Write zlib compressed ARCHIVE_FILE (not always available)
131
+ v Print filenames as they are added or extracted from ARCHIVE_FILE
132
+ h Prints this help message
133
+ C CPAN mode - drop 022 from permissions
134
+ T get names to create from file
135
+
136
+ =head1 SEE ALSO
137
+
138
+ L<tar(1)>, L<Archive::Tar>.
139
+
140
+ =cut
141
+
142
+ ### strip the pod directives
143
+ $usage =~ s/=pod\n//g;
144
+ $usage =~ s/=head1 //g;
145
+
146
+ ### add some newlines
147
+ $usage .= $/.$/;
148
+
149
+ return $usage;
150
+ }
151
+
git/usr/bin/core_perl/ptardiff ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3
+ if 0; # ^ Run only under a shell
4
+ #!/usr/bin/perl
5
+
6
+ BEGIN { pop @INC if $INC[-1] eq '.' }
7
+ use strict;
8
+ use warnings;
9
+ use Archive::Tar;
10
+ use Getopt::Std;
11
+
12
+ my $opts = {};
13
+ getopts('h:', $opts) or die usage();
14
+
15
+ die usages() if $opts->{h};
16
+
17
+ ### need Text::Diff -- give a polite error (not a standard prereq)
18
+ unless ( eval { require Text::Diff; Text::Diff->import; 1 } ) {
19
+ die "\n\t This tool requires the 'Text::Diff' module to be installed\n";
20
+ }
21
+
22
+ my $arch = shift or die usage();
23
+ my $tar = Archive::Tar->new( $arch ) or die "Couldn't read '$arch': $!";
24
+
25
+
26
+ foreach my $file ( $tar->get_files ) {
27
+ next unless $file->is_file;
28
+ my $prefix = $file->prefix;
29
+ my $name = $file->name;
30
+ if (defined $prefix) {
31
+ $name = File::Spec->catfile($prefix, $name);
32
+ }
33
+
34
+ diff( \($file->get_content), $name,
35
+ { FILENAME_A => $name,
36
+ MTIME_A => $file->mtime,
37
+ OUTPUT => \*STDOUT
38
+ }
39
+ );
40
+ }
41
+
42
+
43
+
44
+
45
+ sub usage {
46
+ return q[
47
+
48
+ Usage: ptardiff ARCHIVE_FILE
49
+ ptardiff -h
50
+
51
+ ptardiff is a small program that diffs an extracted archive
52
+ against an unextracted one, using the perl module Archive::Tar.
53
+
54
+ This effectively lets you view changes made to an archives contents.
55
+
56
+ Provide the progam with an ARCHIVE_FILE and it will look up all
57
+ the files with in the archive, scan the current working directory
58
+ for a file with the name and diff it against the contents of the
59
+ archive.
60
+
61
+
62
+ Options:
63
+ h Prints this help message
64
+
65
+
66
+ Sample Usage:
67
+
68
+ $ tar -xzf Acme-Buffy-1.3.tar.gz
69
+ $ vi Acme-Buffy-1.3/README
70
+
71
+ [...]
72
+
73
+ $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch
74
+
75
+
76
+ See Also:
77
+ tar(1)
78
+ ptar
79
+ Archive::Tar
80
+
81
+ ] . $/;
82
+ }
83
+
84
+
85
+
86
+ =head1 NAME
87
+
88
+ ptardiff - program that diffs an extracted archive against an unextracted one
89
+
90
+ =head1 DESCRIPTION
91
+
92
+ ptardiff is a small program that diffs an extracted archive
93
+ against an unextracted one, using the perl module Archive::Tar.
94
+
95
+ This effectively lets you view changes made to an archives contents.
96
+
97
+ Provide the progam with an ARCHIVE_FILE and it will look up all
98
+ the files with in the archive, scan the current working directory
99
+ for a file with the name and diff it against the contents of the
100
+ archive.
101
+
102
+ =head1 SYNOPSIS
103
+
104
+ ptardiff ARCHIVE_FILE
105
+ ptardiff -h
106
+
107
+ $ tar -xzf Acme-Buffy-1.3.tar.gz
108
+ $ vi Acme-Buffy-1.3/README
109
+ [...]
110
+ $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch
111
+
112
+
113
+ =head1 OPTIONS
114
+
115
+ h Prints this help message
116
+
117
+ =head1 SEE ALSO
118
+
119
+ tar(1), L<Archive::Tar>.
120
+
121
+ =cut
git/usr/etc/profile.d/gawk.csh ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ alias gawkpath_default 'unsetenv AWKPATH; setenv AWKPATH `gawk -v x=AWKPATH "BEGIN {print ENVIRON[x]}"`'
2
+
3
+ alias gawkpath_prepend 'if (! $?AWKPATH) setenv AWKPATH ""; if ($AWKPATH == "") then; unsetenv AWKPATH; setenv AWKPATH `gawk -v x=AWKPATH "BEGIN {print ENVIRON[x]}"`; endif; setenv AWKPATH "\!*"":$AWKPATH"'
4
+
5
+ alias gawkpath_append 'if (! $?AWKPATH) setenv AWKPATH ""; if ($AWKPATH == "") then; unsetenv AWKPATH; setenv AWKPATH `gawk -v x=AWKPATH "BEGIN {print ENVIRON[x]}"`; endif; setenv AWKPATH "$AWKPATH"":\!*"'
6
+
7
+ alias gawklibpath_default 'unsetenv AWKLIBPATH; setenv AWKLIBPATH `gawk -v x=AWKLIBPATH "BEGIN {print ENVIRON[x]}"`'
8
+
9
+ alias gawklibpath_prepend 'if (! $?AWKLIBPATH) setenv AWKLIBPATH ""; if ($AWKLIBPATH == "") then; unsetenv AWKLIBPATH; setenv AWKLIBPATH `gawk -v x=AWKLIBPATH "BEGIN {print ENVIRON[x]}"`; endif; setenv AWKLIBPATH "\!*"":$AWKLIBPATH"'
10
+
11
+ alias gawklibpath_append 'if (! $?AWKLIBPATH) setenv AWKLIBPATH ""; if ($AWKLIBPATH == "") then; unsetenv AWKLIBPATH; setenv AWKLIBPATH `gawk -v x=AWKLIBPATH "BEGIN {print ENVIRON[x]}"`; endif; setenv AWKLIBPATH "$AWKLIBPATH"":\!*"'
git/usr/etc/profile.d/gawk.sh ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gawkpath_default () {
2
+ unset AWKPATH
3
+ export AWKPATH=`gawk 'BEGIN {print ENVIRON["AWKPATH"]}'`
4
+ }
5
+
6
+ gawkpath_prepend () {
7
+ [ -z "$AWKPATH" ] && AWKPATH=`gawk 'BEGIN {print ENVIRON["AWKPATH"]}'`
8
+ export AWKPATH="$*:$AWKPATH"
9
+ }
10
+
11
+ gawkpath_append () {
12
+ [ -z "$AWKPATH" ] && AWKPATH=`gawk 'BEGIN {print ENVIRON["AWKPATH"]}'`
13
+ export AWKPATH="$AWKPATH:$*"
14
+ }
15
+
16
+ gawklibpath_default () {
17
+ unset AWKLIBPATH
18
+ export AWKLIBPATH=`gawk 'BEGIN {print ENVIRON["AWKLIBPATH"]}'`
19
+ }
20
+
21
+ gawklibpath_prepend () {
22
+ [ -z "$AWKLIBPATH" ] && \
23
+ AWKLIBPATH=`gawk 'BEGIN {print ENVIRON["AWKLIBPATH"]}'`
24
+ export AWKLIBPATH="$*:$AWKLIBPATH"
25
+ }
26
+
27
+ gawklibpath_append () {
28
+ [ -z "$AWKLIBPATH" ] && \
29
+ AWKLIBPATH=`gawk 'BEGIN {print ENVIRON["AWKLIBPATH"]}'`
30
+ export AWKLIBPATH="$AWKLIBPATH:$*"
31
+ }
git/usr/lib/awk/grcat.exe ADDED
Binary file (10 kB). View file
 
git/usr/lib/awk/pwcat.exe ADDED
Binary file (10 kB). View file
 
git/usr/lib/coreutils/libstdbuf.dll ADDED
Binary file (9.68 kB). View file
 
git/usr/lib/gawk/filefuncs.dll ADDED
Binary file (27.1 kB). View file
 
git/usr/lib/gawk/fnmatch.dll ADDED
Binary file (10.7 kB). View file
 
git/usr/lib/gawk/fork.dll ADDED
Binary file (10.4 kB). View file
 
git/usr/lib/gawk/inplace.dll ADDED
Binary file (14.2 kB). View file
 
git/usr/lib/gawk/intdiv.dll ADDED
Binary file (12.6 kB). View file
 
git/usr/lib/gawk/ordchr.dll ADDED
Binary file (10.3 kB). View file
 
git/usr/lib/gawk/readdir.dll ADDED
Binary file (10.8 kB). View file
 
git/usr/lib/gawk/readfile.dll ADDED
Binary file (10.8 kB). View file
 
git/usr/lib/gawk/revoutput.dll ADDED
Binary file (9.6 kB). View file
 
git/usr/lib/gawk/revtwoway.dll ADDED
Binary file (10 kB). View file
 
git/usr/lib/gawk/rwarray.dll ADDED
Binary file (18.2 kB). View file
 
git/usr/lib/gawk/time.dll ADDED
Binary file (10.9 kB). View file
 
git/usr/lib/gnupg/gpg-check-pattern.exe ADDED
Binary file (88.6 kB). View file
 
git/usr/lib/gnupg/gpg-preset-passphrase.exe ADDED
Binary file (66.7 kB). View file
 
git/usr/lib/gnupg/gpg-wks-client ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/bin/sh
2
+ exec "/usr/bin/gpg-wks-client" "$@"
git/usr/lib/openssl/engines-3/capi.dll ADDED
Binary file (7.79 kB). View file
 
git/usr/lib/openssl/engines-3/loader_attic.dll ADDED
Binary file (48 kB). View file
 
git/usr/lib/openssl/engines-3/padlock.dll ADDED
Binary file (7.79 kB). View file
 
git/usr/lib/p11-kit/p11-kit-extract-trust ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ #set -vx
4
+
5
+ # At this time, while this script is trivial, we ignore any parameters given.
6
+ # However, for backwards compatibility reasons, future versions of this script must
7
+ # support the syntax "update-ca-trust extract" trigger the generation of output
8
+ # files in $DEST.
9
+
10
+ DEST=/etc/pki/ca-trust/extracted
11
+
12
+ # OpenSSL PEM bundle that includes trust flags
13
+ # (BEGIN TRUSTED CERTIFICATE)
14
+ /usr/bin/p11-kit extract --format=openssl-bundle --filter=certificates --overwrite --comment $DEST/openssl/ca-bundle.trust.crt
15
+ /usr/bin/p11-kit extract --format=pem-bundle --filter=ca-anchors --overwrite --comment --purpose server-auth $DEST/pem/tls-ca-bundle.pem
16
+ /usr/bin/p11-kit extract --format=pem-bundle --filter=ca-anchors --overwrite --comment --purpose email $DEST/pem/email-ca-bundle.pem
17
+ /usr/bin/p11-kit extract --format=pem-bundle --filter=ca-anchors --overwrite --comment --purpose code-signing $DEST/pem/objsign-ca-bundle.pem
18
+ /usr/bin/p11-kit extract --format=java-cacerts --filter=ca-anchors --overwrite --purpose server-auth $DEST/java/cacerts
19
+
20
+ # The usual symbolic links are not present to keep these file in sync in MSYS2, so copying is necessary
21
+ mkdir -p /usr/ssl/certs
22
+ cp -f $DEST/pem/tls-ca-bundle.pem /usr/ssl/certs/ca-bundle.crt
23
+ cp -f $DEST/pem/tls-ca-bundle.pem /usr/ssl/cert.pem
24
+ cp -f $DEST/openssl/ca-bundle.trust.crt /usr/ssl/certs/ca-bundle.trust.crt
git/usr/lib/perl5/core_perl/B.pm ADDED
@@ -0,0 +1,1432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # B.pm
2
+ #
3
+ # Copyright (c) 1996, 1997, 1998 Malcolm Beattie
4
+ #
5
+ # You may distribute under the terms of either the GNU General Public
6
+ # License or the Artistic License, as specified in the README file.
7
+ #
8
+ package B;
9
+
10
+ @B::ISA = qw(Exporter);
11
+
12
+ # If B is loaded without imports, we do not want to unnecessarily pollute the stash with Exporter.
13
+ sub import {
14
+ return unless scalar @_ > 1; # Called as a method call.
15
+ require Exporter;
16
+ B->export_to_level(1, @_);
17
+ }
18
+
19
+ # walkoptree_slow comes from B.pm (you are there),
20
+ # walkoptree comes from B.xs
21
+
22
+ BEGIN {
23
+ $B::VERSION = '1.89';
24
+ @B::EXPORT_OK = ();
25
+
26
+ # Our BOOT code needs $VERSION set, and will append to @EXPORT_OK.
27
+ # Want our constants loaded before the compiler meets OPf_KIDS below, as
28
+ # the combination of having the constant stay a Proxy Constant Subroutine
29
+ # and its value being inlined saves a little over .5K
30
+
31
+ require XSLoader;
32
+ XSLoader::load();
33
+ }
34
+
35
+ push @B::EXPORT_OK, (qw(minus_c ppname save_BEGINs
36
+ class peekop cast_I32 cstring cchar hash threadsv_names
37
+ main_root main_start main_cv svref_2object opnumber
38
+ sub_generation amagic_generation perlstring
39
+ walkoptree_slow walkoptree walkoptree_exec walksymtable
40
+ parents comppadlist sv_undef compile_stats timing_info
41
+ begin_av init_av check_av end_av regex_padav dowarn
42
+ defstash curstash warnhook diehook inc_gv @optype
43
+ @specialsv_name unitcheck_av safename));
44
+
45
+ @B::SV::ISA = 'B::OBJECT';
46
+ @B::NULL::ISA = 'B::SV';
47
+ @B::PV::ISA = 'B::SV';
48
+ @B::IV::ISA = 'B::SV';
49
+ @B::NV::ISA = 'B::SV';
50
+ # RV is eliminated with 5.11.0, but effectively is a specialisation of IV now.
51
+ @B::RV::ISA = 'B::IV';
52
+ @B::PVIV::ISA = qw(B::PV B::IV);
53
+ @B::PVNV::ISA = qw(B::PVIV B::NV);
54
+ @B::PVMG::ISA = 'B::PVNV';
55
+ @B::REGEXP::ISA = 'B::PVMG';
56
+ @B::INVLIST::ISA = 'B::PV';
57
+ @B::PVLV::ISA = 'B::GV';
58
+ @B::BM::ISA = 'B::GV';
59
+ @B::AV::ISA = 'B::PVMG';
60
+ @B::GV::ISA = 'B::PVMG';
61
+ @B::HV::ISA = 'B::PVMG';
62
+ @B::CV::ISA = 'B::PVMG';
63
+ @B::IO::ISA = 'B::PVMG';
64
+ @B::FM::ISA = 'B::CV';
65
+ @B::OBJ::ISA = 'B::PVMG';
66
+
67
+ @B::OP::ISA = 'B::OBJECT';
68
+ @B::UNOP::ISA = 'B::OP';
69
+ @B::UNOP_AUX::ISA = 'B::UNOP';
70
+ @B::BINOP::ISA = 'B::UNOP';
71
+ @B::LOGOP::ISA = 'B::UNOP';
72
+ @B::LISTOP::ISA = 'B::BINOP';
73
+ @B::SVOP::ISA = 'B::OP';
74
+ @B::PADOP::ISA = 'B::OP';
75
+ @B::PVOP::ISA = 'B::OP';
76
+ @B::LOOP::ISA = 'B::LISTOP';
77
+ @B::PMOP::ISA = 'B::LISTOP';
78
+ @B::COP::ISA = 'B::OP';
79
+ @B::METHOP::ISA = 'B::OP';
80
+
81
+ @B::SPECIAL::ISA = 'B::OBJECT';
82
+
83
+ our @optype = qw(OP UNOP BINOP LOGOP LISTOP PMOP SVOP PADOP PVOP LOOP COP
84
+ METHOP UNOP_AUX);
85
+ # bytecode.pl contained the following comment:
86
+ # Nullsv *must* come first in the following so that the condition
87
+ # ($$sv == 0) can continue to be used to test (sv == Nullsv).
88
+ our @specialsv_name = qw(Nullsv &PL_sv_undef &PL_sv_yes &PL_sv_no
89
+ (SV*)pWARN_ALL (SV*)pWARN_NONE (SV*)pWARN_STD
90
+ &PL_sv_zero);
91
+
92
+ # Back-compat
93
+ {
94
+ no warnings 'once';
95
+ *CVf_METHOD = \&CVf_NOWARN_AMBIGUOUS;
96
+ }
97
+
98
+ {
99
+ # Stop "-w" from complaining about the lack of a real B::OBJECT class
100
+ package B::OBJECT;
101
+ }
102
+
103
+ sub B::GV::SAFENAME {
104
+ safename(shift()->NAME);
105
+ }
106
+
107
+ sub safename {
108
+ my $name = shift;
109
+
110
+ # The regex below corresponds to the isCONTROLVAR macro
111
+ # from toke.c
112
+
113
+ $name =~ s/^\c?/^?/
114
+ or $name =~ s/^([\cA-\cZ\c\\c[\c]\c_\c^])/
115
+ "^" . chr( utf8::unicode_to_native( 64 ^ ord($1) ))/e;
116
+
117
+ # When we say unicode_to_native we really mean ascii_to_native,
118
+ # which matters iff this is a non-ASCII platform (EBCDIC). '\c?' would
119
+ # not have to be special cased, except for non-ASCII.
120
+
121
+ return $name;
122
+ }
123
+
124
+ sub B::IV::int_value {
125
+ my ($self) = @_;
126
+ return (($self->FLAGS() & SVf_IVisUV()) ? $self->UVX : $self->IV);
127
+ }
128
+
129
+ sub B::NULL::as_string() {""}
130
+ *B::IV::as_string = *B::IV::as_string = \*B::IV::int_value;
131
+ *B::PV::as_string = *B::PV::as_string = \*B::PV::PV;
132
+
133
+ # The input typemap checking makes no distinction between different SV types,
134
+ # so the XS body will generate the same C code, despite the different XS
135
+ # "types". So there is no change in behaviour from doing "newXS" like this,
136
+ # compared with the old approach of having a (near) duplicate XS body.
137
+ # We should fix the typemap checking.
138
+
139
+ # Since perl 5.12.0
140
+ *B::IV::RV = *B::IV::RV = \*B::PV::RV;
141
+
142
+ my $debug;
143
+ my $op_count = 0;
144
+ my @parents = ();
145
+
146
+ sub debug {
147
+ my ($class, $value) = @_;
148
+ $debug = $value;
149
+ walkoptree_debug($value);
150
+ }
151
+
152
+ sub class {
153
+ my $obj = shift;
154
+ my $name = ref $obj;
155
+ $name =~ s/^.*:://;
156
+ return $name;
157
+ }
158
+
159
+ sub parents { \@parents }
160
+
161
+ # For debugging
162
+ sub peekop {
163
+ my $op = shift;
164
+ return sprintf("%s (0x%x) %s", class($op), $$op, $op->name);
165
+ }
166
+
167
+ sub walkoptree_slow {
168
+ my($op, $method, $level) = @_;
169
+ $op_count++; # just for statistics
170
+ $level ||= 0;
171
+ warn(sprintf("walkoptree: %d. %s\n", $level, peekop($op))) if $debug;
172
+ $op->$method($level) if $op->can($method);
173
+ if ($$op && ($op->flags & OPf_KIDS)) {
174
+ my $kid;
175
+ unshift(@parents, $op);
176
+ for ($kid = $op->first; $$kid; $kid = $kid->sibling) {
177
+ walkoptree_slow($kid, $method, $level + 1);
178
+ }
179
+ shift @parents;
180
+ }
181
+ if (class($op) eq 'PMOP'
182
+ && ref($op->pmreplroot)
183
+ && ${$op->pmreplroot}
184
+ && $op->pmreplroot->isa( 'B::OP' ))
185
+ {
186
+ unshift(@parents, $op);
187
+ walkoptree_slow($op->pmreplroot, $method, $level + 1);
188
+ shift @parents;
189
+ }
190
+ }
191
+
192
+ sub compile_stats {
193
+ return "Total number of OPs processed: $op_count\n";
194
+ }
195
+
196
+ sub timing_info {
197
+ my ($sec, $min, $hr) = localtime;
198
+ my ($user, $sys) = times;
199
+ sprintf("%02d:%02d:%02d user=$user sys=$sys",
200
+ $hr, $min, $sec, $user, $sys);
201
+ }
202
+
203
+ my %symtable;
204
+
205
+ sub clearsym {
206
+ %symtable = ();
207
+ }
208
+
209
+ sub savesym {
210
+ my ($obj, $value) = @_;
211
+ # warn(sprintf("savesym: sym_%x => %s\n", $$obj, $value)); # debug
212
+ $symtable{sprintf("sym_%x", $$obj)} = $value;
213
+ }
214
+
215
+ sub objsym {
216
+ my $obj = shift;
217
+ return $symtable{sprintf("sym_%x", $$obj)};
218
+ }
219
+
220
+ sub walkoptree_exec {
221
+ my ($op, $method, $level) = @_;
222
+ $level ||= 0;
223
+ my ($sym, $ppname);
224
+ my $prefix = " " x $level;
225
+ for (; $$op; $op = $op->next) {
226
+ $sym = objsym($op);
227
+ if (defined($sym)) {
228
+ print $prefix, "goto $sym\n";
229
+ return;
230
+ }
231
+ savesym($op, sprintf("%s (0x%lx)", class($op), $$op));
232
+ $op->$method($level);
233
+ $ppname = $op->name;
234
+ if ($ppname =~
235
+ /^(d?or(assign)?|and(assign)?|mapwhile|grepwhile|entertry|range|cond_expr)$/)
236
+ {
237
+ print $prefix, uc($1), " => {\n";
238
+ walkoptree_exec($op->other, $method, $level + 1);
239
+ print $prefix, "}\n";
240
+ } elsif ($ppname eq "match" || $ppname eq "subst") {
241
+ my $pmreplstart = $op->pmreplstart;
242
+ if ($$pmreplstart) {
243
+ print $prefix, "PMREPLSTART => {\n";
244
+ walkoptree_exec($pmreplstart, $method, $level + 1);
245
+ print $prefix, "}\n";
246
+ }
247
+ } elsif ($ppname eq "substcont") {
248
+ print $prefix, "SUBSTCONT => {\n";
249
+ walkoptree_exec($op->other->pmreplstart, $method, $level + 1);
250
+ print $prefix, "}\n";
251
+ $op = $op->other;
252
+ } elsif ($ppname eq "enterloop") {
253
+ print $prefix, "REDO => {\n";
254
+ walkoptree_exec($op->redoop, $method, $level + 1);
255
+ print $prefix, "}\n", $prefix, "NEXT => {\n";
256
+ walkoptree_exec($op->nextop, $method, $level + 1);
257
+ print $prefix, "}\n", $prefix, "LAST => {\n";
258
+ walkoptree_exec($op->lastop, $method, $level + 1);
259
+ print $prefix, "}\n";
260
+ } elsif ($ppname eq "subst") {
261
+ my $replstart = $op->pmreplstart;
262
+ if ($$replstart) {
263
+ print $prefix, "SUBST => {\n";
264
+ walkoptree_exec($replstart, $method, $level + 1);
265
+ print $prefix, "}\n";
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ sub walksymtable {
272
+ my ($symref, $method, $recurse, $prefix) = @_;
273
+ my $sym;
274
+ my $fullname;
275
+ no strict 'refs';
276
+ $prefix = '' unless defined $prefix;
277
+ foreach my $sym ( sort keys %$symref ) {
278
+ my $dummy = $symref->{$sym}; # Copying the glob and incrementing
279
+ # the GPs refcnt clears cached methods
280
+ $fullname = "*main::".$prefix.$sym;
281
+ if ($sym =~ /::$/) {
282
+ $sym = $prefix . $sym;
283
+ if (svref_2object(\*$sym)->NAME ne "main::" && $sym ne "<none>::" && &$recurse($sym)) {
284
+ walksymtable(\%$fullname, $method, $recurse, $sym);
285
+ }
286
+ } else {
287
+ svref_2object(\*$fullname)->$method();
288
+ }
289
+ }
290
+ }
291
+
292
+ 1;
293
+
294
+ __END__
295
+
296
+ =head1 NAME
297
+
298
+ B - The Perl Compiler Backend
299
+
300
+ =head1 SYNOPSIS
301
+
302
+ use B;
303
+
304
+ =head1 DESCRIPTION
305
+
306
+ The C<B> module supplies classes which allow a Perl program to delve
307
+ into its own innards. It is the module used to implement the
308
+ "backends" of the Perl compiler. Usage of the compiler does not
309
+ require knowledge of this module: see the L<O> module for the
310
+ user-visible part. The C<B> module is of use to those who want to
311
+ write new compiler backends. This documentation assumes that the
312
+ reader knows a fair amount about perl's internals including such
313
+ things as SVs, OPs and the internal symbol table and syntax tree
314
+ of a program.
315
+
316
+ =head1 OVERVIEW
317
+
318
+ The C<B> module contains a set of utility functions for querying the
319
+ current state of the Perl interpreter; typically these functions
320
+ return objects from the B::SV and B::OP classes, or their derived
321
+ classes. These classes in turn define methods for querying the
322
+ resulting objects about their own internal state.
323
+
324
+ =head1 Utility Functions
325
+
326
+ The C<B> module exports a variety of functions: some are simple
327
+ utility functions, others provide a Perl program with a way to
328
+ get an initial "handle" on an internal object.
329
+
330
+ =head2 Functions Returning C<B::SV>, C<B::AV>, C<B::HV>, and C<B::CV> objects
331
+
332
+ For descriptions of the class hierarchy of these objects and the
333
+ methods that can be called on them, see below, L<"OVERVIEW OF
334
+ CLASSES"> and L<"SV-RELATED CLASSES">.
335
+
336
+ =over 4
337
+
338
+ =item sv_undef
339
+
340
+ Returns the SV object corresponding to the C variable C<sv_undef>.
341
+
342
+ =item sv_yes
343
+
344
+ Returns the SV object corresponding to the C variable C<sv_yes>.
345
+
346
+ =item sv_no
347
+
348
+ Returns the SV object corresponding to the C variable C<sv_no>.
349
+
350
+ =item svref_2object(SVREF)
351
+
352
+ Takes a reference to any Perl value, and turns the referred-to value
353
+ into an object in the appropriate B::OP-derived or B::SV-derived
354
+ class. Apart from functions such as C<main_root>, this is the primary
355
+ way to get an initial "handle" on an internal perl data structure
356
+ which can then be followed with the other access methods.
357
+
358
+ The returned object will only be valid as long as the underlying OPs
359
+ and SVs continue to exist. Do not attempt to use the object after the
360
+ underlying structures are freed.
361
+
362
+ =item amagic_generation
363
+
364
+ Returns the SV object corresponding to the C variable C<amagic_generation>.
365
+ As of Perl 5.18, this is just an alias to C<PL_na>, so its value is
366
+ meaningless.
367
+
368
+ =item init_av
369
+
370
+ Returns the AV object (i.e. in class B::AV) representing INIT blocks.
371
+
372
+ =item check_av
373
+
374
+ Returns the AV object (i.e. in class B::AV) representing CHECK blocks.
375
+
376
+ =item unitcheck_av
377
+
378
+ Returns the AV object (i.e. in class B::AV) representing UNITCHECK blocks.
379
+
380
+ =item begin_av
381
+
382
+ Returns the AV object (i.e. in class B::AV) representing BEGIN blocks.
383
+
384
+ =item end_av
385
+
386
+ Returns the AV object (i.e. in class B::AV) representing END blocks.
387
+
388
+ =item comppadlist
389
+
390
+ Returns the PADLIST object (i.e. in class B::PADLIST) of the global
391
+ comppadlist. In Perl 5.16 and earlier it returns an AV object (class
392
+ B::AV).
393
+
394
+ =item regex_padav
395
+
396
+ Only when perl was compiled with ithreads.
397
+
398
+ =item main_cv
399
+
400
+ Return the (faked) CV corresponding to the main part of the Perl
401
+ program.
402
+
403
+ =back
404
+
405
+ =head2 Functions for Examining the Symbol Table
406
+
407
+ =over 4
408
+
409
+ =item walksymtable(SYMREF, METHOD, RECURSE, PREFIX)
410
+
411
+ Walk the symbol table starting at SYMREF and call METHOD on each
412
+ symbol (a B::GV object) visited. When the walk reaches package
413
+ symbols (such as "Foo::") it invokes RECURSE, passing in the symbol
414
+ name, and only recurses into the package if that sub returns true.
415
+
416
+ PREFIX is the name of the SYMREF you're walking.
417
+
418
+ For example:
419
+
420
+ # Walk CGI's symbol table calling print_subs on each symbol.
421
+ # Recurse only into CGI::Util::
422
+ walksymtable(\%CGI::, 'print_subs',
423
+ sub { $_[0] eq 'CGI::Util::' }, 'CGI::');
424
+
425
+ print_subs() is a B::GV method you have declared. Also see L<"B::GV
426
+ Methods">, below.
427
+
428
+ =back
429
+
430
+ =head2 Functions Returning C<B::OP> objects or for walking op trees
431
+
432
+ For descriptions of the class hierarchy of these objects and the
433
+ methods that can be called on them, see below, L<"OVERVIEW OF
434
+ CLASSES"> and L<"OP-RELATED CLASSES">.
435
+
436
+ =over 4
437
+
438
+ =item main_root
439
+
440
+ Returns the root op (i.e. an object in the appropriate B::OP-derived
441
+ class) of the main part of the Perl program.
442
+
443
+ =item main_start
444
+
445
+ Returns the starting op of the main part of the Perl program.
446
+
447
+ =item walkoptree(OP, METHOD)
448
+
449
+ Does a tree-walk of the syntax tree based at OP and calls METHOD on
450
+ each op it visits. Each node is visited before its children. If
451
+ C<walkoptree_debug> (see below) has been called to turn debugging on then
452
+ the method C<walkoptree_debug> is called on each op before METHOD is
453
+ called.
454
+
455
+ =item walkoptree_debug(DEBUG)
456
+
457
+ Returns the current debugging flag for C<walkoptree>. If the optional
458
+ DEBUG argument is non-zero, it sets the debugging flag to that. See
459
+ the description of C<walkoptree> above for what the debugging flag
460
+ does.
461
+
462
+ =back
463
+
464
+ =head2 Miscellaneous Utility Functions
465
+
466
+ =over 4
467
+
468
+ =item ppname(OPNUM)
469
+
470
+ Return the PP function name (e.g. "pp_add") of op number OPNUM.
471
+
472
+ =item hash(STR)
473
+
474
+ Returns a string in the form "0x..." representing the value of the
475
+ internal hash function used by perl on string STR.
476
+
477
+ =item cast_I32(I)
478
+
479
+ Casts I to the internal I32 type used by that perl.
480
+
481
+ =item minus_c
482
+
483
+ Does the equivalent of the C<-c> command-line option. Obviously, this
484
+ is only useful in a BEGIN block or else the flag is set too late.
485
+
486
+ =item cstring(STR)
487
+
488
+ Returns a double-quote-surrounded escaped version of STR which can
489
+ be used as a string in C source code.
490
+
491
+ =item perlstring(STR)
492
+
493
+ Returns a double-quote-surrounded escaped version of STR which can
494
+ be used as a string in Perl source code.
495
+
496
+ =item safename(STR)
497
+
498
+ This function returns the string with the first character modified if it
499
+ is a control character. It converts it to ^X format first, so that "\cG"
500
+ becomes "^G". This is used internally by L<B::GV::SAFENAME|/SAFENAME>, but
501
+ you can call it directly.
502
+
503
+ =item class(OBJ)
504
+
505
+ Returns the class of an object without the part of the classname
506
+ preceding the first C<"::">. This is used to turn C<"B::UNOP"> into
507
+ C<"UNOP"> for example.
508
+
509
+ =item threadsv_names
510
+
511
+ This used to provide support for the old 5.005 threading module. It now
512
+ does nothing.
513
+
514
+ =back
515
+
516
+ =head2 Exported utility variables
517
+
518
+ =over 4
519
+
520
+ =item @optype
521
+
522
+ my $op_type = $optype[$op_type_num];
523
+
524
+ A simple mapping of the op type number to its type (like 'COP' or 'BINOP').
525
+
526
+ =item @specialsv_name
527
+
528
+ my $sv_name = $specialsv_name[$sv_index];
529
+
530
+ Certain SV types are considered 'special'. They're represented by
531
+ B::SPECIAL and are referred to by a number from the specialsv_list.
532
+ This array maps that number back to the name of the SV (like 'Nullsv'
533
+ or '&PL_sv_undef').
534
+
535
+ =back
536
+
537
+
538
+ =head1 OVERVIEW OF CLASSES
539
+
540
+ The C structures used by Perl's internals to hold SV and OP
541
+ information (PVIV, AV, HV, ..., OP, SVOP, UNOP, ...) are modelled on a
542
+ class hierarchy and the C<B> module gives access to them via a true
543
+ object hierarchy. Structure fields which point to other objects
544
+ (whether types of SV or types of OP) are represented by the C<B>
545
+ module as Perl objects of the appropriate class.
546
+
547
+ The bulk of the C<B> module is the methods for accessing fields of
548
+ these structures.
549
+
550
+ Note that all access is read-only. You cannot modify the internals by
551
+ using this module. Also, note that the B::OP and B::SV objects created
552
+ by this module are only valid for as long as the underlying objects
553
+ exist; their creation doesn't increase the reference counts of the
554
+ underlying objects. Trying to access the fields of a freed object will
555
+ give incomprehensible results, or worse.
556
+
557
+ =head2 SV-RELATED CLASSES
558
+
559
+ B::IV, B::NV, B::PV, B::PVIV, B::PVNV, B::PVMG,
560
+ B::PVLV, B::AV, B::HV, B::CV, B::GV, B::FM, B::IO. These classes
561
+ correspond in the obvious way to the underlying C structures of similar names.
562
+ The inheritance hierarchy mimics the underlying C "inheritance":
563
+
564
+ B::SV
565
+ |
566
+ +------------+------------+
567
+ | | |
568
+ B::PV B::IV B::NV
569
+ / \ / /
570
+ / \ / /
571
+ B::INVLIST B::PVIV /
572
+ \ /
573
+ \ /
574
+ \ /
575
+ B::PVNV
576
+ |
577
+ |
578
+ B::PVMG
579
+ |
580
+ +-------+-------+---+---+-------+-------+
581
+ | | | | | |
582
+ B::AV B::GV B::HV B::CV B::IO B::REGEXP
583
+ | |
584
+ | |
585
+ B::PVLV B::FM
586
+
587
+
588
+ Access methods correspond to the underlying C macros for field access,
589
+ usually with the leading "class indication" prefix removed (Sv, Av,
590
+ Hv, ...). The leading prefix is only left in cases where its removal
591
+ would cause a clash in method name. For example, C<GvREFCNT> stays
592
+ as-is since its abbreviation would clash with the "superclass" method
593
+ C<REFCNT> (corresponding to the C function C<SvREFCNT>).
594
+
595
+ =head2 B::SV Methods
596
+
597
+ =over 4
598
+
599
+ =item REFCNT
600
+
601
+ =item FLAGS
602
+
603
+ =item IsBOOL
604
+
605
+ Returns true if the SV is a boolean (true or false).
606
+ You can then use C<TRUE> to check if the value is true or false.
607
+
608
+ my $something = ( 1 == 1 ) # boolean true
609
+ || ( 1 == 0 ) # boolean false
610
+ || 42 # IV true
611
+ || 0; # IV false
612
+ my $sv = B::svref_2object(\$something);
613
+
614
+ say q[Not a boolean value]
615
+ if ! $sv->IsBOOL;
616
+
617
+ say q[This is a boolean with value: true]
618
+ if $sv->IsBOOL && $sv->TRUE_nomg;
619
+
620
+ say q[This is a boolean with value: false]
621
+ if $sv->IsBOOL && ! $sv->TRUE_nomg;
622
+
623
+ =item object_2svref
624
+
625
+ Returns a reference to the regular scalar corresponding to this
626
+ B::SV object. In other words, this method is the inverse operation
627
+ to the svref_2object() subroutine. This scalar and other data it points
628
+ at should be considered read-only: modifying them is neither safe nor
629
+ guaranteed to have a sensible effect.
630
+
631
+ =item TRUE
632
+
633
+ Returns a boolean indicating hether Perl would evaluate the SV as true or
634
+ false.
635
+
636
+ B<Warning> this call performs 'get' magic. If you only want to check the
637
+ nature of this SV use C<TRUE_nomg> helper.
638
+
639
+ This is an alias for C<SvTRUE($sv)>.
640
+
641
+ =item TRUE_nomg
642
+
643
+ Check if the value is true (do not perform 'get' magic).
644
+ Returns a boolean indicating whether Perl would evaluate the SV as true or
645
+ false.
646
+
647
+ This is an alias for C<SvTRUE_nomg($sv)>.
648
+
649
+ =back
650
+
651
+ =head2 B::IV Methods
652
+
653
+ =over 4
654
+
655
+ =item IV
656
+
657
+ Returns the value of the IV, I<interpreted as
658
+ a signed integer>. This will be misleading
659
+ if C<FLAGS & SVf_IVisUV>. Perhaps you want the
660
+ C<int_value> method instead?
661
+
662
+ =item IVX
663
+
664
+ =item UVX
665
+
666
+ =item int_value
667
+
668
+ This method returns the value of the IV as an integer.
669
+ It differs from C<IV> in that it returns the correct
670
+ value regardless of whether it's stored signed or
671
+ unsigned.
672
+
673
+ =item needs64bits
674
+
675
+ =item packiv
676
+
677
+ =back
678
+
679
+ =head2 B::NV Methods
680
+
681
+ =over 4
682
+
683
+ =item NV
684
+
685
+ =item NVX
686
+
687
+ =item COP_SEQ_RANGE_LOW
688
+
689
+ =item COP_SEQ_RANGE_HIGH
690
+
691
+ These last two are only valid for pad name SVs. They only existed in the
692
+ B::NV class before Perl 5.22. In 5.22 they were moved to the B::PADNAME
693
+ class.
694
+
695
+ =back
696
+
697
+ =head2 B::RV Methods
698
+
699
+ =over 4
700
+
701
+ =item RV
702
+
703
+ =back
704
+
705
+ =head2 B::PV Methods
706
+
707
+ =over 4
708
+
709
+ =item PV
710
+
711
+ This method is the one you usually want. It constructs a
712
+ string using the length and offset information in the struct:
713
+ for ordinary scalars it will return the string that you'd see
714
+ from Perl, even if it contains null characters.
715
+
716
+ =item RV
717
+
718
+ Same as B::RV::RV, except that it will die() if the PV isn't
719
+ a reference.
720
+
721
+ =item PVX
722
+
723
+ This method is less often useful. It assumes that the string
724
+ stored in the struct is null-terminated, and disregards the
725
+ length information.
726
+
727
+ It is the appropriate method to use if you need to get the name
728
+ of a lexical variable from a padname array. Lexical variable names
729
+ are always stored with a null terminator, and the length field
730
+ (CUR) is overloaded for other purposes and can't be relied on here.
731
+
732
+ =item CUR
733
+
734
+ This method returns the internal length field, which consists of the number
735
+ of internal bytes, not necessarily the number of logical characters.
736
+
737
+ =item LEN
738
+
739
+ This method returns the number of bytes allocated (via malloc) for storing
740
+ the string. This is 0 if the scalar does not "own" the string.
741
+
742
+ =back
743
+
744
+ =head2 B::PVMG Methods
745
+
746
+ =over 4
747
+
748
+ =item MAGIC
749
+
750
+ =item SvSTASH
751
+
752
+ =back
753
+
754
+ =head2 B::MAGIC Methods
755
+
756
+ =over 4
757
+
758
+ =item MOREMAGIC
759
+
760
+ =item precomp
761
+
762
+ Only valid on r-magic, returns the string that generated the regexp.
763
+
764
+ =item PRIVATE
765
+
766
+ =item TYPE
767
+
768
+ =item FLAGS
769
+
770
+ =item OBJ
771
+
772
+ Will die() if called on r-magic.
773
+
774
+ =item PTR
775
+
776
+ =item REGEX
777
+
778
+ Only valid on r-magic, returns the integer value of the REGEX stored
779
+ in the MAGIC.
780
+
781
+ =back
782
+
783
+ =head2 B::INVLIST Methods
784
+
785
+ =over 4
786
+
787
+ =item prev_index
788
+
789
+ Returns the cache result of previous invlist_search() (internal usage)
790
+
791
+ =item is_offset
792
+
793
+ Returns a boolean value (0 or 1) to know if the invlist is using an offset.
794
+ When false the list begins with the code point U+0000.
795
+ When true the list begins with the following elements.
796
+
797
+ =item array_len
798
+
799
+ Returns an integer with the size of the array used to define the invlist.
800
+
801
+ =item get_invlist_array
802
+
803
+ This method returns a list of integers representing the array used by the
804
+ invlist.
805
+ Note: this cannot be used while in middle of iterating on an invlist and croaks.
806
+
807
+ =back
808
+
809
+ =head2 B::PVLV Methods
810
+
811
+ =over 4
812
+
813
+ =item TARGOFF
814
+
815
+ =item TARGLEN
816
+
817
+ =item TYPE
818
+
819
+ =item TARG
820
+
821
+ =back
822
+
823
+ =head2 B::BM Methods
824
+
825
+ =over 4
826
+
827
+ =item USEFUL
828
+
829
+ =item PREVIOUS
830
+
831
+ =item RARE
832
+
833
+ =item TABLE
834
+
835
+ =back
836
+
837
+ =head2 B::REGEXP Methods
838
+
839
+ =over 4
840
+
841
+ =item REGEX
842
+
843
+ =item precomp
844
+
845
+ =item qr_anoncv
846
+
847
+ =item compflags
848
+
849
+ The last two were added in Perl 5.22.
850
+
851
+ =back
852
+
853
+ =head2 B::GV Methods
854
+
855
+ =over 4
856
+
857
+ =item is_empty
858
+
859
+ This method returns TRUE if the GP field of the GV is NULL.
860
+
861
+ =item NAME
862
+
863
+ =item SAFENAME
864
+
865
+ This method returns the name of the glob, but if the first
866
+ character of the name is a control character, then it converts
867
+ it to ^X first, so that *^G would return "^G" rather than "\cG".
868
+
869
+ It's useful if you want to print out the name of a variable.
870
+ If you restrict yourself to globs which exist at compile-time
871
+ then the result ought to be unambiguous, because code like
872
+ C<${"^G"} = 1> is compiled as two ops - a constant string and
873
+ a dereference (rv2gv) - so that the glob is created at runtime.
874
+
875
+ If you're working with globs at runtime, and need to disambiguate
876
+ *^G from *{"^G"}, then you should use the raw NAME method.
877
+
878
+ =item STASH
879
+
880
+ =item SV
881
+
882
+ =item IO
883
+
884
+ =item FORM
885
+
886
+ =item AV
887
+
888
+ =item HV
889
+
890
+ =item EGV
891
+
892
+ =item CV
893
+
894
+ =item CVGEN
895
+
896
+ =item LINE
897
+
898
+ =item FILE
899
+
900
+ =item FILEGV
901
+
902
+ =item GvREFCNT
903
+
904
+ =item FLAGS
905
+
906
+ =item GPFLAGS
907
+
908
+ This last one is present only in perl 5.22.0 and higher.
909
+
910
+ =back
911
+
912
+ =head2 B::IO Methods
913
+
914
+ B::IO objects derive from IO objects and you will get more information from
915
+ the IO object itself.
916
+
917
+ For example:
918
+
919
+ $gvio = B::svref_2object(\*main::stdin)->IO;
920
+ $IO = $gvio->object_2svref();
921
+ $fd = $IO->fileno();
922
+
923
+ =over 4
924
+
925
+ =item LINES
926
+
927
+ =item PAGE
928
+
929
+ =item PAGE_LEN
930
+
931
+ =item LINES_LEFT
932
+
933
+ =item TOP_NAME
934
+
935
+ =item TOP_GV
936
+
937
+ =item FMT_NAME
938
+
939
+ =item FMT_GV
940
+
941
+ =item BOTTOM_NAME
942
+
943
+ =item BOTTOM_GV
944
+
945
+ =item SUBPROCESS
946
+
947
+ =item IoTYPE
948
+
949
+ A character symbolizing the type of IO Handle.
950
+
951
+ - STDIN/OUT
952
+ I STDIN/OUT/ERR
953
+ < read-only
954
+ > write-only
955
+ a append
956
+ + read and write
957
+ s socket
958
+ | pipe
959
+ I IMPLICIT
960
+ # NUMERIC
961
+ space closed handle
962
+ \0 closed internal handle
963
+
964
+ =item IoFLAGS
965
+
966
+ =item IsSTD
967
+
968
+ Takes one argument ( 'stdin' | 'stdout' | 'stderr' ) and returns true
969
+ if the IoIFP of the object is equal to the handle whose name was
970
+ passed as argument; i.e., $io->IsSTD('stderr') is true if
971
+ IoIFP($io) == PerlIO_stderr().
972
+
973
+ =back
974
+
975
+ =head2 B::AV Methods
976
+
977
+ =over 4
978
+
979
+ =item FILL
980
+
981
+ =item MAX
982
+
983
+ =item ARRAY
984
+
985
+ =item ARRAYelt
986
+
987
+ Like C<ARRAY>, but takes an index as an argument to get only one element,
988
+ rather than a list of all of them.
989
+
990
+ =back
991
+
992
+ =head2 B::CV Methods
993
+
994
+ =over 4
995
+
996
+ =item STASH
997
+
998
+ =item START
999
+
1000
+ =item ROOT
1001
+
1002
+ =item GV
1003
+
1004
+ =item FILE
1005
+
1006
+ =item DEPTH
1007
+
1008
+ =item PADLIST
1009
+
1010
+ Returns a B::PADLIST object.
1011
+
1012
+ =item OUTSIDE
1013
+
1014
+ =item OUTSIDE_SEQ
1015
+
1016
+ =item XSUB
1017
+
1018
+ =item XSUBANY
1019
+
1020
+ For constant subroutines, returns the constant SV returned by the subroutine.
1021
+
1022
+ =item CvFLAGS
1023
+
1024
+ =item const_sv
1025
+
1026
+ =item NAME_HEK
1027
+
1028
+ Returns the name of a lexical sub, otherwise C<undef>.
1029
+
1030
+ =back
1031
+
1032
+ =head2 B::HV Methods
1033
+
1034
+ =over 4
1035
+
1036
+ =item FILL
1037
+
1038
+ =item MAX
1039
+
1040
+ =item KEYS
1041
+
1042
+ =item RITER
1043
+
1044
+ =item NAME
1045
+
1046
+ =item ARRAY
1047
+
1048
+ =back
1049
+
1050
+ =head2 OP-RELATED CLASSES
1051
+
1052
+ C<B::OP>, C<B::UNOP>, C<B::UNOP_AUX>, C<B::BINOP>, C<B::LOGOP>,
1053
+ C<B::LISTOP>, C<B::PMOP>, C<B::SVOP>, C<B::PADOP>, C<B::PVOP>, C<B::LOOP>,
1054
+ C<B::COP>, C<B::METHOP>.
1055
+
1056
+ These classes correspond in the obvious way to the underlying C
1057
+ structures of similar names. The inheritance hierarchy mimics the
1058
+ underlying C "inheritance":
1059
+
1060
+ B::OP
1061
+ |
1062
+ +----------+---------+--------+-------+---------+
1063
+ | | | | | |
1064
+ B::UNOP B::SVOP B::PADOP B::COP B::PVOP B::METHOP
1065
+ |
1066
+ +---+---+---------+
1067
+ | | |
1068
+ B::BINOP B::LOGOP B::UNOP_AUX
1069
+ |
1070
+ |
1071
+ B::LISTOP
1072
+ |
1073
+ +---+---+
1074
+ | |
1075
+ B::LOOP B::PMOP
1076
+
1077
+ Access methods correspond to the underlying C structure field names,
1078
+ with the leading "class indication" prefix (C<"op_">) removed.
1079
+
1080
+ =head2 B::OP Methods
1081
+
1082
+ These methods get the values of similarly named fields within the OP
1083
+ data structure. See top of C<op.h> for more info.
1084
+
1085
+ =over 4
1086
+
1087
+ =item next
1088
+
1089
+ =item sibling
1090
+
1091
+ =item parent
1092
+
1093
+ Returns the OP's parent. If it has no parent, or if your perl wasn't built
1094
+ with C<-DPERL_OP_PARENT>, returns NULL.
1095
+
1096
+ Note that the global variable C<$B::OP::does_parent> is undefined on older
1097
+ perls that don't support the C<parent> method, is defined but false on
1098
+ perls that support the method but were built without C<-DPERL_OP_PARENT>,
1099
+ and is true otherwise.
1100
+
1101
+ =item name
1102
+
1103
+ This returns the op name as a string (e.g. "add", "rv2av").
1104
+
1105
+ =item ppaddr
1106
+
1107
+ This returns the function name as a string (e.g. "PL_ppaddr[OP_ADD]",
1108
+ "PL_ppaddr[OP_RV2AV]").
1109
+
1110
+ =item desc
1111
+
1112
+ This returns the op description from the global C PL_op_desc array
1113
+ (e.g. "addition" "array deref").
1114
+
1115
+ =item targ
1116
+
1117
+ =item type
1118
+
1119
+ =item opt
1120
+
1121
+ =item flags
1122
+
1123
+ =item private
1124
+
1125
+ =item spare
1126
+
1127
+ =back
1128
+
1129
+ =head2 B::UNOP Method
1130
+
1131
+ =over 4
1132
+
1133
+ =item first
1134
+
1135
+ =back
1136
+
1137
+ =head2 B::UNOP_AUX Methods (since 5.22)
1138
+
1139
+ =over 4
1140
+
1141
+ =item aux_list(cv)
1142
+
1143
+ This returns a list of the elements of the op's aux data structure,
1144
+ or a null list if there is no aux. What will be returned depends on the
1145
+ object's type, but will typically be a collection of C<B::IV>, C<B::GV>,
1146
+ etc. objects. C<cv> is the C<B::CV> object representing the sub that the
1147
+ op is contained within.
1148
+
1149
+ =item string(cv)
1150
+
1151
+ This returns a textual representation of the object (likely to b useful
1152
+ for deparsing and debugging), or an empty string if the op type doesn't
1153
+ support this. C<cv> is the C<B::CV> object representing the sub that the
1154
+ op is contained within.
1155
+
1156
+ =back
1157
+
1158
+ =head2 B::BINOP Method
1159
+
1160
+ =over 4
1161
+
1162
+ =item last
1163
+
1164
+ =back
1165
+
1166
+ =head2 B::LOGOP Method
1167
+
1168
+ =over 4
1169
+
1170
+ =item other
1171
+
1172
+ =back
1173
+
1174
+ =head2 B::LISTOP Method
1175
+
1176
+ =over 4
1177
+
1178
+ =item children
1179
+
1180
+ =back
1181
+
1182
+ =head2 B::PMOP Methods
1183
+
1184
+ =over 4
1185
+
1186
+ =item pmreplroot
1187
+
1188
+ =item pmreplstart
1189
+
1190
+ =item pmflags
1191
+
1192
+ =item precomp
1193
+
1194
+ =item pmoffset
1195
+
1196
+ Only when perl was compiled with ithreads.
1197
+
1198
+ =item code_list
1199
+
1200
+ Since perl 5.17.1
1201
+
1202
+ =item pmregexp
1203
+
1204
+ Added in perl 5.22, this method returns the B::REGEXP associated with the
1205
+ op. While PMOPs do not actually have C<pmregexp> fields under threaded
1206
+ builds, this method returns the regexp under threads nonetheless, for
1207
+ convenience.
1208
+
1209
+ =back
1210
+
1211
+ =head2 B::SVOP Methods
1212
+
1213
+ =over 4
1214
+
1215
+ =item sv
1216
+
1217
+ =item gv
1218
+
1219
+ =back
1220
+
1221
+ =head2 B::PADOP Method
1222
+
1223
+ =over 4
1224
+
1225
+ =item padix
1226
+
1227
+ =back
1228
+
1229
+ =head2 B::PVOP Method
1230
+
1231
+ =over 4
1232
+
1233
+ =item pv
1234
+
1235
+ =back
1236
+
1237
+ =head2 B::LOOP Methods
1238
+
1239
+ =over 4
1240
+
1241
+ =item redoop
1242
+
1243
+ =item nextop
1244
+
1245
+ =item lastop
1246
+
1247
+ =back
1248
+
1249
+ =head2 B::COP Methods
1250
+
1251
+ The C<B::COP> class is used for "nextstate" and "dbstate" ops. As of Perl
1252
+ 5.22, it is also used for "null" ops that started out as COPs.
1253
+
1254
+ =over 4
1255
+
1256
+ =item label
1257
+
1258
+ =item stash
1259
+
1260
+ =item stashpv
1261
+
1262
+ =item stashoff (threaded only)
1263
+
1264
+ =item file
1265
+
1266
+ =item cop_seq
1267
+
1268
+ =item line
1269
+
1270
+ =item warnings
1271
+
1272
+ =item io
1273
+
1274
+ =item hints
1275
+
1276
+ =item hints_hash
1277
+
1278
+ =back
1279
+
1280
+ =head2 B::METHOP Methods (Since Perl 5.22)
1281
+
1282
+ =over 4
1283
+
1284
+ =item first
1285
+
1286
+ =item meth_sv
1287
+
1288
+ =back
1289
+
1290
+ =head2 PAD-RELATED CLASSES
1291
+
1292
+ Perl 5.18 introduced a new class, B::PADLIST, returned by B::CV's
1293
+ C<PADLIST> method.
1294
+
1295
+ Perl 5.22 introduced the B::PADNAMELIST and B::PADNAME classes.
1296
+
1297
+ =head2 B::PADLIST Methods
1298
+
1299
+ =over 4
1300
+
1301
+ =item MAX
1302
+
1303
+ =item ARRAY
1304
+
1305
+ A list of pads. The first one is a B::PADNAMELIST containing the names.
1306
+ The rest are currently B::AV objects, but that could
1307
+ change in future versions.
1308
+
1309
+ =item ARRAYelt
1310
+
1311
+ Like C<ARRAY>, but takes an index as an argument to get only one element,
1312
+ rather than a list of all of them.
1313
+
1314
+ =item NAMES
1315
+
1316
+ This method, introduced in 5.22, returns the B::PADNAMELIST. It is
1317
+ equivalent to C<ARRAYelt> with a 0 argument.
1318
+
1319
+ =item REFCNT
1320
+
1321
+ =item id
1322
+
1323
+ This method, introduced in 5.22, returns an ID shared by clones of the same
1324
+ padlist.
1325
+
1326
+ =item outid
1327
+
1328
+ This method, also added in 5.22, returns the ID of the outer padlist.
1329
+
1330
+ =back
1331
+
1332
+ =head2 B::PADNAMELIST Methods
1333
+
1334
+ =over 4
1335
+
1336
+ =item MAX
1337
+
1338
+ =item ARRAY
1339
+
1340
+ =item ARRAYelt
1341
+
1342
+ These two methods return the pad names, using B::SPECIAL objects for null
1343
+ pointers and B::PADNAME objects otherwise.
1344
+
1345
+ =item REFCNT
1346
+
1347
+ =back
1348
+
1349
+ =head2 B::PADNAME Methods
1350
+
1351
+ =over 4
1352
+
1353
+ =item PV
1354
+
1355
+ =item PVX
1356
+
1357
+ =item LEN
1358
+
1359
+ =item REFCNT
1360
+
1361
+ =item GEN
1362
+
1363
+ =item FLAGS
1364
+
1365
+ For backward-compatibility, if the PADNAMEt_OUTER flag is set, the FLAGS
1366
+ method adds the SVf_FAKE flag, too.
1367
+
1368
+ =item TYPE
1369
+
1370
+ A B::HV object representing the stash for a typed lexical.
1371
+
1372
+ =item SvSTASH
1373
+
1374
+ A backward-compatibility alias for TYPE.
1375
+
1376
+ =item OURSTASH
1377
+
1378
+ A B::HV object representing the stash for 'our' variables.
1379
+
1380
+ =item PROTOCV
1381
+
1382
+ The prototype CV for a 'my' sub.
1383
+
1384
+ =item COP_SEQ_RANGE_LOW
1385
+
1386
+ =item COP_SEQ_RANGE_HIGH
1387
+
1388
+ Sequence numbers representing the scope within which a lexical is visible.
1389
+ Meaningless if PADNAMEt_OUTER is set.
1390
+
1391
+ =item PARENT_PAD_INDEX
1392
+
1393
+ Only meaningful if PADNAMEt_OUTER is set.
1394
+
1395
+ =item PARENT_FAKELEX_FLAGS
1396
+
1397
+ Only meaningful if PADNAMEt_OUTER is set.
1398
+
1399
+ =item IsUndef
1400
+
1401
+ Returns a boolean value to check if the padname is PL_padname_undef.
1402
+
1403
+ =back
1404
+
1405
+ =head2 $B::overlay
1406
+
1407
+ Although the optree is read-only, there is an overlay facility that allows
1408
+ you to override what values the various B::*OP methods return for a
1409
+ particular op. C<$B::overlay> should be set to reference a two-deep hash:
1410
+ indexed by OP address, then method name. Whenever a an op method is
1411
+ called, the value in the hash is returned if it exists. This facility is
1412
+ used by B::Deparse to "undo" some optimisations. For example:
1413
+
1414
+
1415
+ local $B::overlay = {};
1416
+ ...
1417
+ if ($op->name eq "foo") {
1418
+ $B::overlay->{$$op} = {
1419
+ name => 'bar',
1420
+ next => $op->next->next,
1421
+ };
1422
+ }
1423
+ ...
1424
+ $op->name # returns "bar"
1425
+ $op->next # returns the next op but one
1426
+
1427
+
1428
+ =head1 AUTHOR
1429
+
1430
+ Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
1431
+
1432
+ =cut
git/usr/lib/perl5/core_perl/B/Concise.pm ADDED
@@ -0,0 +1,1929 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package B::Concise;
2
+ # Copyright (C) 2000-2003 Stephen McCamant. All rights reserved.
3
+ # This program is free software; you can redistribute and/or modify it
4
+ # under the same terms as Perl itself.
5
+
6
+ # Note: we need to keep track of how many use declarations/BEGIN
7
+ # blocks this module uses, so we can avoid printing them when user
8
+ # asks for the BEGIN blocks in her program. Update the comments and
9
+ # the count in concise_specials if you add or delete one. The
10
+ # -MO=Concise counts as use #1.
11
+
12
+ use strict; # use #2
13
+ use warnings; # uses #3 and #4, since warnings uses Carp
14
+
15
+ use Exporter 'import'; # use #5
16
+
17
+ our $VERSION = "1.007";
18
+ our @EXPORT_OK = qw( set_style set_style_standard add_callback
19
+ concise_subref concise_cv concise_main
20
+ add_style walk_output compile reset_sequence );
21
+ our %EXPORT_TAGS =
22
+ ( io => [qw( walk_output compile reset_sequence )],
23
+ style => [qw( add_style set_style_standard )],
24
+ cb => [qw( add_callback )],
25
+ mech => [qw( concise_subref concise_cv concise_main )], );
26
+
27
+ # use #6
28
+ use B qw(class ppname main_start main_root main_cv cstring svref_2object
29
+ SVf_IOK SVf_NOK SVf_POK SVf_IVisUV SVf_FAKE OPf_KIDS OPf_SPECIAL
30
+ OPf_STACKED
31
+ OPpSPLIT_ASSIGN OPpSPLIT_LEX
32
+ CVf_ANON CVf_LEXICAL CVf_NAMED
33
+ PAD_FAKELEX_ANON PAD_FAKELEX_MULTI SVf_ROK);
34
+
35
+ my %style =
36
+ ("terse" =>
37
+ ["(?(#label =>\n)?)(*( )*)#class (#addr) #name (?([#targ])?) "
38
+ . "#svclass~(?((#svaddr))?)~#svval~(?(label \"#coplabel\")?)\n",
39
+ "(*( )*)goto #class (#addr)\n",
40
+ "#class pp_#name"],
41
+ "concise" =>
42
+ ["#hyphseq2 (*( (x( ;)x))*)<#classsym> #exname#arg(?([#targarglife])?)"
43
+ . "~#flags(?(/#private)?)(?(:#hints)?)(x(;~->#next)x)\n"
44
+ , " (*( )*) goto #seq\n",
45
+ "(?(<#seq>)?)#exname#arg(?([#targarglife])?)"],
46
+ "linenoise" =>
47
+ ["(x(;(*( )*))x)#noise#arg(?([#targarg])?)(x( ;\n)x)",
48
+ "gt_#seq ",
49
+ "(?(#seq)?)#noise#arg(?([#targarg])?)"],
50
+ "debug" =>
51
+ ["#class (#addr)\n\top_next\t\t#nextaddr\n\t(?(op_other\t#otheraddr\n\t)?)"
52
+ . "op_sibling\t#sibaddr\n\t"
53
+ . "op_ppaddr\tPL_ppaddr[OP_#NAME]\n\top_type\t\t#typenum\n"
54
+ . "\top_flags\t#flagval\n\top_private\t#privval\t#hintsval\n"
55
+ . "(?(\top_first\t#firstaddr\n)?)(?(\top_last\t\t#lastaddr\n)?)"
56
+ . "(?(\top_sv\t\t#svaddr\n)?)",
57
+ " GOTO #addr\n",
58
+ "#addr"],
59
+ "env" => [$ENV{B_CONCISE_FORMAT}, $ENV{B_CONCISE_GOTO_FORMAT},
60
+ $ENV{B_CONCISE_TREE_FORMAT}],
61
+ );
62
+
63
+ # Renderings, ie how Concise prints, is controlled by these vars
64
+ # primary:
65
+ our $stylename; # selects current style from %style
66
+ my $order = "basic"; # how optree is walked & printed: basic, exec, tree
67
+
68
+ # rendering mechanics:
69
+ # these 'formats' are the line-rendering templates
70
+ # they're updated from %style when $stylename changes
71
+ my ($format, $gotofmt, $treefmt);
72
+
73
+ # lesser players:
74
+ my $base = 36; # how <sequence#> is displayed
75
+ my $big_endian = 1; # more <sequence#> display
76
+ my $tree_style = 0; # tree-order details
77
+ my $banner = 1; # print banner before optree is traversed
78
+ my $do_main = 0; # force printing of main routine
79
+ my $show_src; # show source code
80
+
81
+ # another factor: can affect all styles!
82
+ our @callbacks; # allow external management
83
+
84
+ set_style_standard("concise");
85
+
86
+ my $curcv;
87
+ my $cop_seq_base;
88
+
89
+ sub set_style {
90
+ ($format, $gotofmt, $treefmt) = @_;
91
+ #warn "set_style: deprecated, use set_style_standard instead\n"; # someday
92
+ die "expecting 3 style-format args\n" unless @_ == 3;
93
+ }
94
+
95
+ sub add_style {
96
+ my ($newstyle,@args) = @_;
97
+ die "style '$newstyle' already exists, choose a new name\n"
98
+ if exists $style{$newstyle};
99
+ die "expecting 3 style-format args\n" unless @args == 3;
100
+ $style{$newstyle} = [@args];
101
+ $stylename = $newstyle; # update rendering state
102
+ }
103
+
104
+ sub set_style_standard {
105
+ ($stylename) = @_; # update rendering state
106
+ die "err: style '$stylename' unknown\n" unless exists $style{$stylename};
107
+ set_style(@{$style{$stylename}});
108
+ }
109
+
110
+ sub add_callback {
111
+ push @callbacks, @_;
112
+ }
113
+
114
+ # output handle, used with all Concise-output printing
115
+ our $walkHandle; # public for your convenience
116
+ BEGIN { $walkHandle = \*STDOUT }
117
+
118
+ sub walk_output { # updates $walkHandle
119
+ my $handle = shift;
120
+ return $walkHandle unless $handle; # allow use as accessor
121
+
122
+ if (ref $handle eq 'SCALAR') {
123
+ require Config;
124
+ die "no perlio in this build, can't call walk_output (\\\$scalar)\n"
125
+ unless $Config::Config{useperlio};
126
+ # in 5.8+, open(FILEHANDLE,MODE,REFERENCE) writes to string
127
+ open my $tmp, '>', $handle; # but cant re-set existing STDOUT
128
+ $walkHandle = $tmp; # so use my $tmp as intermediate var
129
+ return $walkHandle;
130
+ }
131
+ my $iotype = ref $handle;
132
+ die "expecting argument/object that can print\n"
133
+ unless $iotype eq 'GLOB' or $iotype and $handle->can('print');
134
+ $walkHandle = $handle;
135
+ }
136
+
137
+ sub concise_subref {
138
+ my($order, $coderef, $name) = @_;
139
+ my $codeobj = svref_2object($coderef);
140
+
141
+ return concise_stashref(@_)
142
+ unless ref($codeobj) =~ '^B::(?:CV|FM)\z';
143
+ concise_cv_obj($order, $codeobj, $name);
144
+ }
145
+
146
+ sub concise_stashref {
147
+ my($order, $h) = @_;
148
+ my $name = svref_2object($h)->NAME;
149
+ foreach my $k (sort keys %$h) {
150
+ next unless defined $h->{$k};
151
+ my $coderef = ref $h->{$k} eq 'CODE' ? $h->{$k}
152
+ : ref\$h->{$k} eq 'GLOB' ? *{$h->{$k}}{CODE} || next
153
+ : next;
154
+ reset_sequence();
155
+ print "FUNC: *", $name, "::", $k, "\n";
156
+ my $codeobj = svref_2object($coderef);
157
+ next unless ref $codeobj eq 'B::CV';
158
+ eval { concise_cv_obj($order, $codeobj, $k) };
159
+ warn "err $@ on $codeobj" if $@;
160
+ }
161
+ }
162
+
163
+ # This should have been called concise_subref, but it was exported
164
+ # under this name in versions before 0.56
165
+ *concise_cv = \&concise_subref;
166
+
167
+ sub concise_cv_obj {
168
+ my ($order, $cv, $name) = @_;
169
+ # name is either a string, or a CODE ref (copy of $cv arg??)
170
+
171
+ $curcv = $cv;
172
+
173
+ if (ref($cv->XSUBANY) =~ /B::(\w+)/) {
174
+ print $walkHandle "$name is a constant sub, optimized to a $1\n";
175
+ return;
176
+ }
177
+ if ($cv->XSUB) {
178
+ print $walkHandle "$name is XS code\n";
179
+ return;
180
+ }
181
+ if (class($cv->START) eq "NULL") {
182
+ no strict 'refs';
183
+ if (ref $name eq 'CODE') {
184
+ print $walkHandle "coderef $name has no START\n";
185
+ }
186
+ elsif (exists &$name) {
187
+ print $walkHandle "$name exists in stash, but has no START\n";
188
+ }
189
+ else {
190
+ print $walkHandle "$name not in symbol table\n";
191
+ }
192
+ return;
193
+ }
194
+ sequence($cv->START);
195
+ if ($order eq "exec") {
196
+ walk_exec($cv->START);
197
+ }
198
+ elsif ($order eq "basic") {
199
+ # walk_topdown($cv->ROOT, sub { $_[0]->concise($_[1]) }, 0);
200
+ my $root = $cv->ROOT;
201
+ unless (ref $root eq 'B::NULL') {
202
+ walk_topdown($root, sub { $_[0]->concise($_[1]) }, 0);
203
+ } else {
204
+ print $walkHandle "B::NULL encountered doing ROOT on $cv. avoiding disaster\n";
205
+ }
206
+ } else {
207
+ print $walkHandle tree($cv->ROOT, 0);
208
+ }
209
+ }
210
+
211
+ sub concise_main {
212
+ my($order) = @_;
213
+ sequence(main_start);
214
+ $curcv = main_cv;
215
+ if ($order eq "exec") {
216
+ return if class(main_start) eq "NULL";
217
+ walk_exec(main_start);
218
+ } elsif ($order eq "tree") {
219
+ return if class(main_root) eq "NULL";
220
+ print $walkHandle tree(main_root, 0);
221
+ } elsif ($order eq "basic") {
222
+ return if class(main_root) eq "NULL";
223
+ walk_topdown(main_root,
224
+ sub { $_[0]->concise($_[1]) }, 0);
225
+ }
226
+ }
227
+
228
+ sub concise_specials {
229
+ my($name, $order, @cv_s) = @_;
230
+ my $i = 1;
231
+ if ($name eq "BEGIN") {
232
+ splice(@cv_s, 0, 8); # skip 7 BEGIN blocks in this file. NOW 8 ??
233
+ } elsif ($name eq "CHECK") {
234
+ pop @cv_s; # skip the CHECK block that calls us
235
+ }
236
+ for my $cv (@cv_s) {
237
+ print $walkHandle "$name $i:\n";
238
+ $i++;
239
+ concise_cv_obj($order, $cv, $name);
240
+ }
241
+ }
242
+
243
+ my $start_sym = "\e(0"; # "\cN" sometimes also works
244
+ my $end_sym = "\e(B"; # "\cO" respectively
245
+
246
+ my @tree_decorations =
247
+ ([" ", "--", "+-", "|-", "| ", "`-", "-", 1],
248
+ [" ", "-", "+", "+", "|", "`", "", 0],
249
+ [" ", map("$start_sym$_$end_sym", "qq", "wq", "tq", "x ", "mq", "q"), 1],
250
+ [" ", map("$start_sym$_$end_sym", "q", "w", "t", "x", "m"), "", 0],
251
+ );
252
+
253
+ my @render_packs; # collect -stash=<packages>
254
+
255
+ sub compileOpts {
256
+ # set rendering state from options and args
257
+ my (@options,@args);
258
+ if (@_) {
259
+ @options = grep(/^-/, @_);
260
+ @args = grep(!/^-/, @_);
261
+ }
262
+ for my $o (@options) {
263
+ # mode/order
264
+ if ($o eq "-basic") {
265
+ $order = "basic";
266
+ } elsif ($o eq "-exec") {
267
+ $order = "exec";
268
+ } elsif ($o eq "-tree") {
269
+ $order = "tree";
270
+ }
271
+ # tree-specific
272
+ elsif ($o eq "-compact") {
273
+ $tree_style |= 1;
274
+ } elsif ($o eq "-loose") {
275
+ $tree_style &= ~1;
276
+ } elsif ($o eq "-vt") {
277
+ $tree_style |= 2;
278
+ } elsif ($o eq "-ascii") {
279
+ $tree_style &= ~2;
280
+ }
281
+ # sequence numbering
282
+ elsif ($o =~ /^-base(\d+)$/) {
283
+ $base = $1;
284
+ } elsif ($o eq "-bigendian") {
285
+ $big_endian = 1;
286
+ } elsif ($o eq "-littleendian") {
287
+ $big_endian = 0;
288
+ }
289
+ # miscellaneous, presentation
290
+ elsif ($o eq "-nobanner") {
291
+ $banner = 0;
292
+ } elsif ($o eq "-banner") {
293
+ $banner = 1;
294
+ }
295
+ elsif ($o eq "-main") {
296
+ $do_main = 1;
297
+ } elsif ($o eq "-nomain") {
298
+ $do_main = 0;
299
+ } elsif ($o eq "-src") {
300
+ $show_src = 1;
301
+ }
302
+ elsif ($o =~ /^-stash=(.*)/) {
303
+ my $pkg = $1;
304
+ no strict 'refs';
305
+ if (! %{$pkg.'::'}) {
306
+ eval "require $pkg";
307
+ } else {
308
+ require Config;
309
+ if (!$Config::Config{usedl}
310
+ && keys %{$pkg.'::'} == 1
311
+ && $pkg->can('bootstrap')) {
312
+ # It is something that we're statically linked to, but hasn't
313
+ # yet been used.
314
+ eval "require $pkg";
315
+ }
316
+ }
317
+ push @render_packs, $pkg;
318
+ }
319
+ # line-style options
320
+ elsif (exists $style{substr($o, 1)}) {
321
+ $stylename = substr($o, 1);
322
+ set_style_standard($stylename);
323
+ } else {
324
+ warn "Option $o unrecognized";
325
+ }
326
+ }
327
+ return (@args);
328
+ }
329
+
330
+ sub compile {
331
+ my (@args) = compileOpts(@_);
332
+ return sub {
333
+ my @newargs = compileOpts(@_); # accept new rendering options
334
+ warn "disregarding non-options: @newargs\n" if @newargs;
335
+
336
+ for my $objname (@args) {
337
+ next unless $objname; # skip null args to avoid noisy responses
338
+
339
+ if ($objname eq "BEGIN") {
340
+ concise_specials("BEGIN", $order,
341
+ B::begin_av->isa("B::AV") ?
342
+ B::begin_av->ARRAY : ());
343
+ } elsif ($objname eq "INIT") {
344
+ concise_specials("INIT", $order,
345
+ B::init_av->isa("B::AV") ?
346
+ B::init_av->ARRAY : ());
347
+ } elsif ($objname eq "CHECK") {
348
+ concise_specials("CHECK", $order,
349
+ B::check_av->isa("B::AV") ?
350
+ B::check_av->ARRAY : ());
351
+ } elsif ($objname eq "UNITCHECK") {
352
+ concise_specials("UNITCHECK", $order,
353
+ B::unitcheck_av->isa("B::AV") ?
354
+ B::unitcheck_av->ARRAY : ());
355
+ } elsif ($objname eq "END") {
356
+ concise_specials("END", $order,
357
+ B::end_av->isa("B::AV") ?
358
+ B::end_av->ARRAY : ());
359
+ }
360
+ else {
361
+ # convert function names to subrefs
362
+ if (ref $objname) {
363
+ print $walkHandle "B::Concise::compile($objname)\n"
364
+ if $banner;
365
+ concise_subref($order, ($objname)x2);
366
+ next;
367
+ } else {
368
+ $objname = "main::" . $objname unless $objname =~ /::/;
369
+ no strict 'refs';
370
+ my $glob = \*$objname;
371
+ unless (*$glob{CODE} || *$glob{FORMAT}) {
372
+ print $walkHandle "$objname:\n" if $banner;
373
+ print $walkHandle "err: unknown function ($objname)\n";
374
+ return;
375
+ }
376
+ if (my $objref = *$glob{CODE}) {
377
+ print $walkHandle "$objname:\n" if $banner;
378
+ concise_subref($order, $objref, $objname);
379
+ }
380
+ if (my $objref = *$glob{FORMAT}) {
381
+ print $walkHandle "$objname (FORMAT):\n"
382
+ if $banner;
383
+ concise_subref($order, $objref, $objname);
384
+ }
385
+ }
386
+ }
387
+ }
388
+ for my $pkg (@render_packs) {
389
+ no strict 'refs';
390
+ concise_stashref($order, \%{$pkg.'::'});
391
+ }
392
+
393
+ if (!@args or $do_main or @render_packs) {
394
+ print $walkHandle "main program:\n" if $do_main;
395
+ concise_main($order);
396
+ }
397
+ return @args; # something
398
+ }
399
+ }
400
+
401
+ my %labels;
402
+ my $lastnext; # remembers op-chain, used to insert gotos
403
+
404
+ my %opclass = ('OP' => "0", 'UNOP' => "1", 'BINOP' => "2", 'LOGOP' => "|",
405
+ 'LISTOP' => "@", 'PMOP' => "/", 'SVOP' => "\$", 'GVOP' => "*",
406
+ 'PVOP' => '"', 'LOOP' => "{", 'COP' => ";", 'PADOP' => "#",
407
+ 'METHOP' => '.', UNOP_AUX => '+');
408
+
409
+ no warnings 'qw'; # "Possible attempt to put comments..."; use #7
410
+ my @linenoise =
411
+ qw'# () sc ( @? 1 $* gv *{ m$ m@ m% m? p/ *$ $ $# & a& pt \\ s\\ rf bl
412
+ ` *? <> ?? ?/ r/ c/ // qr s/ /c y/ = @= C sC Cp sp df un BM po +1 +I
413
+ -1 -I 1+ I+ 1- I- ** * i* / i/ %$ i% x + i+ - i- . " << >> < i<
414
+ > i> <= i, >= i. == i= != i! <? i? s< s> s, s. s= s! s? b& b^ b| -0 -i
415
+ ! ~ a2 si cs rd sr e^ lg sq in %x %o ab le ss ve ix ri sf FL od ch cy
416
+ uf lf uc lc qm @ [f [ @[ eh vl ky dl ex % ${ @{ uk pk st jn ) )[ a@
417
+ a% sl +] -] [- [+ so rv GS GW MS MW .. f. .f && || ^^ ?: &= |= -> s{ s}
418
+ v} ca wa di rs ;; ; ;d }{ { } {} f{ it {l l} rt }l }n }r dm }g }e ^o
419
+ ^c ^| ^# um bm t~ u~ ~d DB db ^s se ^g ^r {w }w pf pr ^O ^K ^R ^W ^d ^v
420
+ ^e ^t ^k t. fc ic fl .s .p .b .c .l .a .h g1 s1 g2 s2 ?. l? -R -W -X -r
421
+ -w -x -e -o -O -z -s -M -A -C -S -c -b -f -d -p -l -u -g -k -t -T -B cd
422
+ co cr u. cm ut r. l@ s@ r@ mD uD oD rD tD sD wD cD f$ w$ p$ sh e$ k$ g3
423
+ g4 s4 g5 s5 T@ C@ L@ G@ A@ S@ Hg Hc Hr Hw Mg Mc Ms Mr Sg Sc So rq do {e
424
+ e} {t t} g6 G6 6e g7 G7 7e g8 G8 8e g9 G9 9e 6s 7s 8s 9s 6E 7E 8E 9E Pn
425
+ Pu GP SP EP Gn Gg GG SG EG g0 c$ lk t$ ;s n> // /= CO';
426
+
427
+ my $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
428
+
429
+ sub op_flags { # common flags (see BASOP.op_flags in op.h)
430
+ my($x) = @_;
431
+ my(@v);
432
+ push @v, "v" if ($x & 3) == 1;
433
+ push @v, "s" if ($x & 3) == 2;
434
+ push @v, "l" if ($x & 3) == 3;
435
+ push @v, "K" if $x & 4;
436
+ push @v, "P" if $x & 8;
437
+ push @v, "R" if $x & 16;
438
+ push @v, "M" if $x & 32;
439
+ push @v, "S" if $x & 64;
440
+ push @v, "*" if $x & 128;
441
+ return join("", @v);
442
+ }
443
+
444
+ sub base_n {
445
+ my $x = shift;
446
+ return "-" . base_n(-$x) if $x < 0;
447
+ my $str = "";
448
+ do { $str .= substr($chars, $x % $base, 1) } while $x = int($x / $base);
449
+ $str = reverse $str if $big_endian;
450
+ return $str;
451
+ }
452
+
453
+ my %sequence_num;
454
+ my $seq_max = 1;
455
+
456
+ sub reset_sequence {
457
+ # reset the sequence
458
+ %sequence_num = ();
459
+ $seq_max = 1;
460
+ $lastnext = 0;
461
+ }
462
+
463
+ sub seq {
464
+ my($op) = @_;
465
+ return "-" if not exists $sequence_num{$$op};
466
+ return base_n($sequence_num{$$op});
467
+ }
468
+
469
+ sub walk_topdown {
470
+ my($op, $sub, $level) = @_;
471
+ $sub->($op, $level);
472
+ if ($op->flags & OPf_KIDS) {
473
+ for (my $kid = $op->first; $$kid; $kid = $kid->sibling) {
474
+ walk_topdown($kid, $sub, $level + 1);
475
+ }
476
+ }
477
+ if (class($op) eq "PMOP") {
478
+ my $maybe_root = $op->code_list;
479
+ if ( ref($maybe_root) and $maybe_root->isa("B::OP")
480
+ and not $op->flags & OPf_KIDS) {
481
+ walk_topdown($maybe_root, $sub, $level + 1);
482
+ }
483
+ $maybe_root = $op->pmreplroot;
484
+ if (ref($maybe_root) and $maybe_root->isa("B::OP")) {
485
+ # It really is the root of the replacement, not something
486
+ # else stored here for lack of space elsewhere
487
+ walk_topdown($maybe_root, $sub, $level + 1);
488
+ }
489
+ }
490
+ }
491
+
492
+ sub walklines {
493
+ my($ar, $level) = @_;
494
+ for my $l (@$ar) {
495
+ if (ref($l) eq "ARRAY") {
496
+ walklines($l, $level + 1);
497
+ } else {
498
+ $l->concise($level);
499
+ }
500
+ }
501
+ }
502
+
503
+ sub walk_exec {
504
+ my($top, $level) = @_;
505
+ my %opsseen;
506
+ my @lines;
507
+ my @todo = ([$top, \@lines]);
508
+ while (@todo and my($op, $targ) = @{shift @todo}) {
509
+ for (; $$op; $op = $op->next) {
510
+ last if $opsseen{$$op}++;
511
+ push @$targ, $op;
512
+ my $name = $op->name;
513
+ if (class($op) eq "LOGOP") {
514
+ my $ar = [];
515
+ push @$targ, $ar;
516
+ push @todo, [$op->other, $ar];
517
+ } elsif ($name eq "subst" and $ {$op->pmreplstart}) {
518
+ my $ar = [];
519
+ push @$targ, $ar;
520
+ push @todo, [$op->pmreplstart, $ar];
521
+ } elsif ($name =~ /^enter(loop|iter)$/) {
522
+ $labels{${$op->nextop}} = "NEXT";
523
+ $labels{${$op->lastop}} = "LAST";
524
+ $labels{${$op->redoop}} = "REDO";
525
+ }
526
+ }
527
+ }
528
+ walklines(\@lines, 0);
529
+ }
530
+
531
+ # The structure of this routine is purposely modeled after op.c's peep()
532
+ sub sequence {
533
+ my($op) = @_;
534
+ my $oldop = 0;
535
+ return if class($op) eq "NULL" or exists $sequence_num{$$op};
536
+ for (; $$op; $op = $op->next) {
537
+ last if exists $sequence_num{$$op};
538
+ my $name = $op->name;
539
+ $sequence_num{$$op} = $seq_max++;
540
+ if (class($op) eq "LOGOP") {
541
+ sequence($op->other);
542
+ } elsif (class($op) eq "LOOP") {
543
+ sequence($op->redoop);
544
+ sequence( $op->nextop);
545
+ sequence($op->lastop);
546
+ } elsif ($name eq "subst" and $ {$op->pmreplstart}) {
547
+ sequence($op->pmreplstart);
548
+ }
549
+ $oldop = $op;
550
+ }
551
+ }
552
+
553
+ sub fmt_line { # generate text-line for op.
554
+ my($hr, $op, $text, $level) = @_;
555
+
556
+ $_->($hr, $op, \$text, \$level, $stylename) for @callbacks;
557
+
558
+ return '' if $hr->{SKIP}; # suppress line if a callback said so
559
+ return '' if $hr->{goto} and $hr->{goto} eq '-'; # no goto nowhere
560
+
561
+ # spec: (?(text1#varText2)?)
562
+ $text =~ s/\(\?\(([^\#]*?)\#(\w+)([^\#]*?)\)\?\)/
563
+ $hr->{$2} ? $1.$hr->{$2}.$3 : ""/eg;
564
+
565
+ # spec: (x(exec_text;basic_text)x)
566
+ $text =~ s/\(x\((.*?);(.*?)\)x\)/$order eq "exec" ? $1 : $2/egs;
567
+
568
+ # spec: (*(text)*)
569
+ $text =~ s/\(\*\(([^;]*?)\)\*\)/$1 x $level/egs;
570
+
571
+ # spec: (*(text1;text2)*)
572
+ $text =~ s/\(\*\((.*?);(.*?)\)\*\)/$1 x ($level - 1) . $2 x ($level>0)/egs;
573
+
574
+ # convert #Var to tag=>val form: Var\t#var
575
+ $text =~ s/\#([A-Z][a-z]+)(\d+)?/\t\u$1\t\L#$1$2/gs;
576
+
577
+ # spec: #varN
578
+ $text =~ s/\#([a-zA-Z]+)(\d+)/sprintf("%-$2s", $hr->{$1})/eg;
579
+
580
+ $text =~ s/\#([a-zA-Z]+)/$hr->{$1}/eg; # populate #var's
581
+ $text =~ s/[ \t]*~+[ \t]*/ /g; # squeeze tildes
582
+
583
+ $text = "# $hr->{src}\n$text" if $show_src and $hr->{src};
584
+
585
+ chomp $text;
586
+ return "$text\n" if $text ne "" and $order ne "tree";
587
+ return $text; # suppress empty lines
588
+ }
589
+
590
+
591
+
592
+ # use require rather than use here to avoid disturbing tests that dump
593
+ # BEGIN blocks
594
+ require B::Op_private;
595
+
596
+
597
+
598
+ our %hints; # used to display each COP's op_hints values
599
+
600
+ # strict refs, subs, vars
601
+ @hints{0x2,0x200,0x400,0x20,0x40,0x80} = ('$', '&', '*', 'x$', 'x&', 'x*');
602
+ # integers, locale, bytes
603
+ @hints{0x1,0x4,0x8,0x10} = ('i', 'l', 'b');
604
+ # block scope, localise %^H, $^OPEN (in), $^OPEN (out)
605
+ @hints{0x100,0x20000,0x40000,0x80000} = ('{','%','<','>');
606
+ # overload new integer, float, binary, string, re
607
+ @hints{0x1000,0x2000,0x4000,0x8000,0x10000} = ('I', 'F', 'B', 'S', 'R');
608
+ # taint and eval
609
+ @hints{0x100000,0x200000} = ('T', 'E');
610
+ # filetest access, use utf8, unicode_strings feature
611
+ @hints{0x400000,0x800000,0x800} = ('X', 'U', 'us');
612
+
613
+ # pick up the feature hints constants.
614
+ # Note that we're relying on non-API parts of feature.pm,
615
+ # but its less naughty than just blindly copying those constants into
616
+ # this src file.
617
+ #
618
+ require feature;
619
+
620
+ sub hints_flags {
621
+ my($x) = @_;
622
+ my @s;
623
+ for my $flag (sort {$b <=> $a} keys %hints) {
624
+ if ($hints{$flag} and $x & $flag and $x >= $flag) {
625
+ $x -= $flag;
626
+ push @s, $hints{$flag};
627
+ }
628
+ }
629
+ if ($x & $feature::hint_mask) {
630
+ push @s, "fea=" . (($x & $feature::hint_mask) >> $feature::hint_shift);
631
+ $x &= ~$feature::hint_mask;
632
+ }
633
+ push @s, sprintf "0x%x", $x if $x;
634
+ return join(",", @s);
635
+ }
636
+
637
+
638
+ # return a string like 'LVINTRO,1' for the op $name with op_private
639
+ # value $x
640
+
641
+ sub private_flags {
642
+ my($name, $x) = @_;
643
+ my $entry = $B::Op_private::bits{$name};
644
+ return $x ? "$x" : '' unless $entry;
645
+
646
+ my @flags;
647
+ my $bit;
648
+ for ($bit = 7; $bit >= 0; $bit--) {
649
+ next unless exists $entry->{$bit};
650
+ my $e = $entry->{$bit};
651
+ if (ref($e) eq 'HASH') {
652
+ # bit field
653
+
654
+ my ($bitmin, $bitmax, $bitmask, $enum, $label) =
655
+ @{$e}{qw(bitmin bitmax bitmask enum label)};
656
+ $bit = $bitmin;
657
+ next if defined $label && $label eq '-'; # display as raw number
658
+
659
+ my $val = $x & $bitmask;
660
+ $x &= ~$bitmask;
661
+ $val >>= $bitmin;
662
+
663
+ if (defined $enum) {
664
+ # try to convert numeric $val into symbolic
665
+ my @enum = @$enum;
666
+ while (@enum) {
667
+ my $ix = shift @enum;
668
+ my $name = shift @enum;
669
+ my $label = shift @enum;
670
+ if ($val == $ix) {
671
+ $val = $label;
672
+ last;
673
+ }
674
+ }
675
+ }
676
+ next if $val eq '0'; # don't display anonymous zero values
677
+ push @flags, defined $label ? "$label=$val" : $val;
678
+
679
+ }
680
+ else {
681
+ # flag bit
682
+ my $label = $B::Op_private::labels{$e};
683
+ next if defined $label && $label eq '-'; # display as raw number
684
+ if ($x & (1<<$bit)) {
685
+ $x -= (1<<$bit);
686
+ push @flags, $label;
687
+ }
688
+ }
689
+ }
690
+
691
+ push @flags, $x if $x; # display unknown bits numerically
692
+ return join ",", @flags;
693
+ }
694
+
695
+ sub concise_sv {
696
+ my($sv, $hr, $preferpv) = @_;
697
+ $hr->{svclass} = class($sv);
698
+ $hr->{svclass} = "UV"
699
+ if $hr->{svclass} eq "IV" and $sv->FLAGS & SVf_IVisUV;
700
+ Carp::cluck("bad concise_sv: $sv") unless $sv and $$sv;
701
+ $hr->{svaddr} = sprintf("%#x", $$sv);
702
+ if ($hr->{svclass} eq "GV" && $sv->isGV_with_GP()) {
703
+ my $gv = $sv;
704
+ my $stash = $gv->STASH;
705
+ if (class($stash) eq "SPECIAL") {
706
+ $stash = "<none>";
707
+ }
708
+ else {
709
+ $stash = $stash->NAME;
710
+ }
711
+ if ($stash eq "main") {
712
+ $stash = "";
713
+ } else {
714
+ $stash = $stash . "::";
715
+ }
716
+ $hr->{svval} = "*$stash" . $gv->SAFENAME;
717
+ return "*$stash" . $gv->SAFENAME;
718
+ } else {
719
+ while (class($sv) eq "IV" && $sv->FLAGS & SVf_ROK) {
720
+ $hr->{svval} .= "\\";
721
+ $sv = $sv->RV;
722
+ }
723
+ if (class($sv) eq "SPECIAL") {
724
+ $hr->{svval} .= ["Null", "sv_undef", "sv_yes", "sv_no",
725
+ '', '', '', "sv_zero"]->[$$sv];
726
+ } elsif ($preferpv
727
+ && ($sv->FLAGS & SVf_POK)) {
728
+ $hr->{svval} .= cstring($sv->PV);
729
+ } elsif ($sv->FLAGS & SVf_NOK) {
730
+ $hr->{svval} .= $sv->NV;
731
+ } elsif ($sv->FLAGS & SVf_IOK) {
732
+ $hr->{svval} .= $sv->int_value;
733
+ } elsif ($sv->FLAGS & SVf_POK) {
734
+ $hr->{svval} .= cstring($sv->PV);
735
+ } elsif (class($sv) eq "HV") {
736
+ $hr->{svval} .= 'HASH';
737
+ } elsif (class($sv) eq "AV") {
738
+ $hr->{svval} .= 'ARRAY';
739
+ } elsif (class($sv) eq "CV") {
740
+ if ($sv->CvFLAGS & CVf_ANON) {
741
+ $hr->{svval} .= 'CODE';
742
+ } elsif ($sv->CvFLAGS & CVf_NAMED) {
743
+ $hr->{svval} .= "&";
744
+ unless ($sv->CvFLAGS & CVf_LEXICAL) {
745
+ my $stash = $sv->STASH;
746
+ unless (class($stash) eq "SPECIAL") {
747
+ $hr->{svval} .= $stash->NAME . "::";
748
+ }
749
+ }
750
+ $hr->{svval} .= $sv->NAME_HEK;
751
+ } else {
752
+ $hr->{svval} .= "&";
753
+ $sv = $sv->GV;
754
+ my $stash = $sv->STASH;
755
+ unless (class($stash) eq "SPECIAL") {
756
+ $hr->{svval} .= $stash->NAME . "::";
757
+ }
758
+ $hr->{svval} .= $sv->SAFENAME;
759
+ }
760
+ }
761
+
762
+ $hr->{svval} = 'undef' unless defined $hr->{svval};
763
+ my $out = $hr->{svclass};
764
+ return $out .= " $hr->{svval}" ;
765
+ }
766
+ }
767
+
768
+ my %srclines;
769
+
770
+ sub fill_srclines {
771
+ my $fullnm = shift;
772
+ if ($fullnm eq '-e') {
773
+ $srclines{$fullnm} = [ $fullnm, "-src not supported for -e" ];
774
+ return;
775
+ }
776
+ open (my $fh, '<', $fullnm)
777
+ or warn "# $fullnm: $!, (chdirs not supported by this feature yet)\n"
778
+ and return;
779
+ my @l = <$fh>;
780
+ chomp @l;
781
+ unshift @l, $fullnm; # like @{_<$fullnm} in debug, array starts at 1
782
+ $srclines{$fullnm} = \@l;
783
+ }
784
+
785
+ # Given a pad target, return the pad var's name and cop range /
786
+ # fakeness, or failing that, its target number.
787
+ # e.g.
788
+ # ('$i', '$i:5,7')
789
+ # or
790
+ # ('$i', '$i:fake:a')
791
+ # or
792
+ # ('t5', 't5')
793
+
794
+ sub padname {
795
+ my ($targ) = @_;
796
+
797
+ my ($targarg, $targarglife);
798
+ my $padname = (($curcv->PADLIST->ARRAY)[0]->ARRAY)[$targ];
799
+ if (defined $padname and class($padname) ne "SPECIAL" and
800
+ $padname->LEN)
801
+ {
802
+ $targarg = $padname->PVX;
803
+ if ($padname->FLAGS & SVf_FAKE) {
804
+ # These changes relate to the jumbo closure fix.
805
+ # See changes 19939 and 20005
806
+ my $fake = '';
807
+ $fake .= 'a'
808
+ if $padname->PARENT_FAKELEX_FLAGS & PAD_FAKELEX_ANON;
809
+ $fake .= 'm'
810
+ if $padname->PARENT_FAKELEX_FLAGS & PAD_FAKELEX_MULTI;
811
+ $fake .= ':' . $padname->PARENT_PAD_INDEX
812
+ if $curcv->CvFLAGS & CVf_ANON;
813
+ $targarglife = "$targarg:FAKE:$fake";
814
+ }
815
+ else {
816
+ my $intro = $padname->COP_SEQ_RANGE_LOW - $cop_seq_base;
817
+ my $finish = int($padname->COP_SEQ_RANGE_HIGH) - $cop_seq_base;
818
+ $finish = "end" if $finish == 999999999 - $cop_seq_base;
819
+ $targarglife = "$targarg:$intro,$finish";
820
+ }
821
+ } else {
822
+ $targarglife = $targarg = "t" . $targ;
823
+ }
824
+ return $targarg, $targarglife;
825
+ }
826
+
827
+
828
+
829
+ sub concise_op {
830
+ my ($op, $level, $format) = @_;
831
+ my %h;
832
+ $h{exname} = $h{name} = $op->name;
833
+ $h{NAME} = uc $h{name};
834
+ $h{class} = class($op);
835
+ $h{extarg} = $h{targ} = $op->targ;
836
+ $h{extarg} = "" unless $h{extarg};
837
+ $h{privval} = $op->private;
838
+ # for null ops, targ holds the old type
839
+ my $origname = $h{name} eq "null" && $h{targ}
840
+ ? substr(ppname($h{targ}), 3)
841
+ : $h{name};
842
+ $h{private} = private_flags($origname, $op->private);
843
+ if ($op->folded) {
844
+ $h{private} &&= "$h{private},";
845
+ $h{private} .= "FOLD";
846
+ }
847
+
848
+ if ($h{name} ne $origname) { # a null op
849
+ $h{exname} = "ex-$origname";
850
+ $h{extarg} = "";
851
+ } elsif ($h{private} =~ /\bREFC\b/) {
852
+ # targ holds a reference count
853
+ my $refs = "ref" . ($h{targ} != 1 ? "s" : "");
854
+ $h{targarglife} = $h{targarg} = "$h{targ} $refs";
855
+ } elsif ($h{targ} && $h{name} ne 'iter') {
856
+ # for my ($q, $r, $s) () {} syntax hijacks the targ of the iter op,
857
+ # (which is the ->next of the enteriter) hence the special cases above
858
+ # and just below:
859
+ my $count = $h{name} eq 'padrange'
860
+ ? ($op->private & $B::Op_private::defines{'OPpPADRANGE_COUNTMASK'})
861
+ : $h{name} eq 'enteriter'
862
+ ? $op->next->targ + 1
863
+ : 1;
864
+ my (@targarg, @targarglife);
865
+ for my $i (0..$count-1) {
866
+ my ($targarg, $targarglife) = padname($h{targ} + $i);
867
+ push @targarg, $targarg;
868
+ push @targarglife, $targarglife;
869
+ }
870
+ $h{targarg} = join '; ', @targarg;
871
+ $h{targarglife} = join '; ', @targarglife;
872
+ }
873
+
874
+ $h{arg} = "";
875
+ $h{svclass} = $h{svaddr} = $h{svval} = "";
876
+ if ($h{class} eq "PMOP") {
877
+ my $extra = '';
878
+ my $precomp = $op->precomp;
879
+ if (defined $precomp) {
880
+ $precomp = cstring($precomp); # Escape literal control sequences
881
+ $precomp = "/$precomp/";
882
+ } else {
883
+ $precomp = "";
884
+ }
885
+ if ($op->name eq 'subst') {
886
+ if (class($op->pmreplstart) ne "NULL") {
887
+ undef $lastnext;
888
+ $extra = " replstart->" . seq($op->pmreplstart);
889
+ }
890
+ }
891
+ elsif ($op->name eq 'split') {
892
+ if ( ($op->private & OPpSPLIT_ASSIGN) # @array = split
893
+ && (not $op->flags & OPf_STACKED)) # @{expr} = split
894
+ {
895
+ # with C<@array = split(/pat/, str);>,
896
+ # array is stored in /pat/'s pmreplroot; either
897
+ # as an integer index into the pad (for a lexical array)
898
+ # or as GV for a package array (which will be a pad index
899
+ # on threaded builds)
900
+
901
+ if ($op->private & $B::Op_private::defines{'OPpSPLIT_LEX'}) {
902
+ my $off = $op->pmreplroot; # union with op_pmtargetoff
903
+ my ($name, $full) = padname($off);
904
+ $extra = " => $full";
905
+ }
906
+ else {
907
+ # union with op_pmtargetoff, op_pmtargetgv
908
+ my $gv = $op->pmreplroot;
909
+ if (!ref($gv)) {
910
+ # the value is actually a pad offset
911
+ $gv = (($curcv->PADLIST->ARRAY)[1]->ARRAY)[$gv]->NAME;
912
+ }
913
+ else {
914
+ # unthreaded: its a GV
915
+ $gv = $gv->NAME;
916
+ }
917
+ $extra = " => \@$gv";
918
+ }
919
+ }
920
+ }
921
+ $h{arg} = "($precomp$extra)";
922
+ } elsif ($h{class} eq "PVOP" and $h{name} !~ '^transr?\z') {
923
+ $h{arg} = '("' . $op->pv . '")';
924
+ $h{svval} = '"' . $op->pv . '"';
925
+ } elsif ($h{class} eq "COP") {
926
+ my $label = $op->label;
927
+ $h{coplabel} = $label;
928
+ $label = $label ? "$label: " : "";
929
+ my $loc = $op->file;
930
+ my $pathnm = $loc;
931
+ $loc =~ s[.*/][];
932
+ my $ln = $op->line;
933
+ $loc .= ":$ln";
934
+ my($stash, $cseq) = ($op->stash->NAME, $op->cop_seq - $cop_seq_base);
935
+ $h{arg} = "($label$stash $cseq $loc)";
936
+ if ($show_src) {
937
+ fill_srclines($pathnm) unless exists $srclines{$pathnm};
938
+ my $line = $srclines{$pathnm}[$ln] // "-src unavailable under -e";
939
+ $h{src} = "$ln: $line";
940
+ }
941
+ } elsif ($h{class} eq "LOOP") {
942
+ $h{arg} = "(next->" . seq($op->nextop) . " last->" . seq($op->lastop)
943
+ . " redo->" . seq($op->redoop) . ")";
944
+ } elsif ($h{class} eq "LOGOP") {
945
+ undef $lastnext;
946
+ $h{arg} = "(other->" . seq($op->other) . ")";
947
+ $h{otheraddr} = sprintf("%#x", $ {$op->other});
948
+ if ($h{name} eq "argdefelem") {
949
+ # targ used for element index
950
+ $h{targarglife} = $h{targarg} = "";
951
+ $h{arg} .= "[" . $op->targ . "]";
952
+ }
953
+ }
954
+ elsif ($h{class} eq "SVOP" or $h{class} eq "PADOP") {
955
+ unless ($h{name} eq 'aelemfast' and $op->flags & OPf_SPECIAL) {
956
+ my $idx = ($h{class} eq "SVOP") ? $op->targ : $op->padix;
957
+ if ($h{class} eq "PADOP" or !${$op->sv}) {
958
+ my $sv = (($curcv->PADLIST->ARRAY)[1]->ARRAY)[$idx];
959
+ $h{arg} = "[" . concise_sv($sv, \%h, 0) . "]";
960
+ $h{targarglife} = $h{targarg} = "";
961
+ } else {
962
+ $h{arg} = "(" . concise_sv($op->sv, \%h, 0) . ")";
963
+ }
964
+ }
965
+ }
966
+ elsif ($h{class} eq "METHOP") {
967
+ my $prefix = '';
968
+ if ($h{name} eq 'method_redir' or $h{name} eq 'method_redir_super') {
969
+ my $rclass_sv = $op->rclass;
970
+ $rclass_sv = (($curcv->PADLIST->ARRAY)[1]->ARRAY)[$rclass_sv]
971
+ unless ref $rclass_sv;
972
+ $prefix .= 'PACKAGE "'.$rclass_sv->PV.'", ';
973
+ }
974
+ if ($h{name} ne "method") {
975
+ if (${$op->meth_sv}) {
976
+ $h{arg} = "($prefix" . concise_sv($op->meth_sv, \%h, 1) . ")";
977
+ } else {
978
+ my $sv = (($curcv->PADLIST->ARRAY)[1]->ARRAY)[$op->targ];
979
+ $h{arg} = "[$prefix" . concise_sv($sv, \%h, 1) . "]";
980
+ $h{targarglife} = $h{targarg} = "";
981
+ }
982
+ }
983
+ }
984
+ elsif ($h{class} eq "UNOP_AUX") {
985
+ $h{arg} = "(" . $op->string($curcv) . ")";
986
+ }
987
+
988
+ $h{seq} = $h{hyphseq} = seq($op);
989
+ $h{seq} = "" if $h{seq} eq "-";
990
+ $h{opt} = $op->opt;
991
+ $h{label} = $labels{$$op};
992
+ $h{next} = $op->next;
993
+ $h{next} = (class($h{next}) eq "NULL") ? "(end)" : seq($h{next});
994
+ $h{nextaddr} = sprintf("%#x", $ {$op->next});
995
+ $h{sibaddr} = sprintf("%#x", $ {$op->sibling});
996
+ $h{firstaddr} = sprintf("%#x", $ {$op->first}) if $op->can("first");
997
+ $h{lastaddr} = sprintf("%#x", $ {$op->last}) if $op->can("last");
998
+
999
+ $h{classsym} = $opclass{$h{class}};
1000
+ $h{flagval} = $op->flags;
1001
+ $h{flags} = op_flags($op->flags);
1002
+ if ($op->can("hints")) {
1003
+ $h{hintsval} = $op->hints;
1004
+ $h{hints} = hints_flags($h{hintsval});
1005
+ } else {
1006
+ $h{hintsval} = $h{hints} = '';
1007
+ }
1008
+ $h{addr} = sprintf("%#x", $$op);
1009
+ $h{typenum} = $op->type;
1010
+ $h{noise} = $linenoise[$op->type];
1011
+
1012
+ return fmt_line(\%h, $op, $format, $level);
1013
+ }
1014
+
1015
+ sub B::OP::concise {
1016
+ my($op, $level) = @_;
1017
+ if ($order eq "exec" and $lastnext and $$lastnext != $$op) {
1018
+ # insert a 'goto' line
1019
+ my $synth = {"seq" => seq($lastnext), "class" => class($lastnext),
1020
+ "addr" => sprintf("%#x", $$lastnext),
1021
+ "goto" => seq($lastnext), # simplify goto '-' removal
1022
+ };
1023
+ print $walkHandle fmt_line($synth, $op, $gotofmt, $level+1);
1024
+ }
1025
+ $lastnext = $op->next;
1026
+ print $walkHandle concise_op($op, $level, $format);
1027
+ }
1028
+
1029
+ # B::OP::terse (see Terse.pm) now just calls this
1030
+ sub b_terse {
1031
+ my($op, $level) = @_;
1032
+
1033
+ # This isn't necessarily right, but there's no easy way to get
1034
+ # from an OP to the right CV. This is a limitation of the
1035
+ # ->terse() interface style, and there isn't much to do about
1036
+ # it. In particular, we can die in concise_op if the main pad
1037
+ # isn't long enough, or has the wrong kind of entries, compared to
1038
+ # the pad a sub was compiled with. The fix for that would be to
1039
+ # make a backwards compatible "terse" format that never even
1040
+ # looked at the pad, just like the old B::Terse. I don't think
1041
+ # that's worth the effort, though.
1042
+ $curcv = main_cv unless $curcv;
1043
+
1044
+ if ($order eq "exec" and $lastnext and $$lastnext != $$op) {
1045
+ # insert a 'goto'
1046
+ my $h = {"seq" => seq($lastnext), "class" => class($lastnext),
1047
+ "addr" => sprintf("%#x", $$lastnext)};
1048
+ print # $walkHandle
1049
+ fmt_line($h, $op, $style{"terse"}[1], $level+1);
1050
+ }
1051
+ $lastnext = $op->next;
1052
+ print # $walkHandle
1053
+ concise_op($op, $level, $style{"terse"}[0]);
1054
+ }
1055
+
1056
+ sub tree {
1057
+ my $op = shift;
1058
+ my $level = shift;
1059
+ my $style = $tree_decorations[$tree_style];
1060
+ my($space, $single, $kids, $kid, $nokid, $last, $lead, $size) = @$style;
1061
+ my $name = concise_op($op, $level, $treefmt);
1062
+ if (not $op->flags & OPf_KIDS) {
1063
+ return $name . "\n";
1064
+ }
1065
+ my @lines;
1066
+ for (my $kid = $op->first; $$kid; $kid = $kid->sibling) {
1067
+ push @lines, tree($kid, $level+1);
1068
+ }
1069
+ my $i;
1070
+ for ($i = $#lines; substr($lines[$i], 0, 1) eq " "; $i--) {
1071
+ $lines[$i] = $space . $lines[$i];
1072
+ }
1073
+ if ($i > 0) {
1074
+ $lines[$i] = $last . $lines[$i];
1075
+ while ($i-- > 1) {
1076
+ if (substr($lines[$i], 0, 1) eq " ") {
1077
+ $lines[$i] = $nokid . $lines[$i];
1078
+ } else {
1079
+ $lines[$i] = $kid . $lines[$i];
1080
+ }
1081
+ }
1082
+ $lines[$i] = $kids . $lines[$i];
1083
+ } else {
1084
+ $lines[0] = $single . $lines[0];
1085
+ }
1086
+ return("$name$lead" . shift @lines,
1087
+ map(" " x (length($name)+$size) . $_, @lines));
1088
+ }
1089
+
1090
+ # *** Warning: fragile kludge ahead ***
1091
+ # Because the B::* modules run in the same interpreter as the code
1092
+ # they're compiling, their presence tends to distort the view we have of
1093
+ # the code we're looking at. In particular, perl gives sequence numbers
1094
+ # to COPs. If the program we're looking at were run on its own, this
1095
+ # would start at 1. Because all of B::Concise and all the modules it
1096
+ # uses are compiled first, though, by the time we get to the user's
1097
+ # program the sequence number is already pretty high, which could be
1098
+ # distracting if you're trying to tell OPs apart. Therefore we'd like to
1099
+ # subtract an offset from all the sequence numbers we display, to
1100
+ # restore the simpler view of the world. The trick is to know what that
1101
+ # offset will be, when we're still compiling B::Concise! If we
1102
+ # hardcoded a value, it would have to change every time B::Concise or
1103
+ # other modules we use do. To help a little, what we do here is compile
1104
+ # a little code at the end of the module, and compute the base sequence
1105
+ # number for the user's program as being a small offset later, so all we
1106
+ # have to worry about are changes in the offset.
1107
+
1108
+ # When you say "perl -MO=Concise -e '$a'", the output should look like:
1109
+
1110
+ # 4 <@> leave[t1] vKP/REFC ->(end)
1111
+ # 1 <0> enter ->2
1112
+ #^ smallest OP sequence number should be 1
1113
+ # 2 <;> nextstate(main 1 -e:1) v ->3
1114
+ # ^ smallest COP sequence number should be 1
1115
+ # - <1> ex-rv2sv vK/1 ->4
1116
+ # 3 <$> gvsv(*a) s ->4
1117
+
1118
+ # If the second of the marked numbers there isn't 1, it means you need
1119
+ # to update the corresponding magic number in the next line.
1120
+ # Remember, this needs to stay the last things in the module.
1121
+
1122
+ my $cop_seq_mnum = 12;
1123
+ $cop_seq_base = svref_2object(eval 'sub{0;}')->START->cop_seq + $cop_seq_mnum;
1124
+
1125
+ 1;
1126
+
1127
+ __END__
1128
+
1129
+ =head1 NAME
1130
+
1131
+ B::Concise - Walk Perl syntax tree, printing concise info about ops
1132
+
1133
+ =head1 SYNOPSIS
1134
+
1135
+ perl -MO=Concise[,OPTIONS] foo.pl
1136
+
1137
+ use B::Concise qw(set_style add_callback);
1138
+
1139
+ =head1 DESCRIPTION
1140
+
1141
+ This compiler backend prints the internal OPs of a Perl program's syntax
1142
+ tree in one of several space-efficient text formats suitable for debugging
1143
+ the inner workings of perl or other compiler backends. It can print OPs in
1144
+ the order they appear in the OP tree, in the order they will execute, or
1145
+ in a text approximation to their tree structure, and the format of the
1146
+ information displayed is customizable. Its function is similar to that of
1147
+ perl's B<-Dx> debugging flag or the B<B::Terse> module, but it is more
1148
+ sophisticated and flexible.
1149
+
1150
+ =head1 EXAMPLE
1151
+
1152
+ Here's two outputs (or 'renderings'), using the -exec and -basic
1153
+ (i.e. default) formatting conventions on the same code snippet.
1154
+
1155
+ % perl -MO=Concise,-exec -e '$a = $b + 42'
1156
+ 1 <0> enter
1157
+ 2 <;> nextstate(main 1 -e:1) v
1158
+ 3 <#> gvsv[*b] s
1159
+ 4 <$> const[IV 42] s
1160
+ * 5 <2> add[t3] sK/2
1161
+ 6 <#> gvsv[*a] s
1162
+ 7 <2> sassign vKS/2
1163
+ 8 <@> leave[1 ref] vKP/REFC
1164
+
1165
+ In this -exec rendering, each opcode is executed in the order shown.
1166
+ The add opcode, marked with '*', is discussed in more detail.
1167
+
1168
+ The 1st column is the op's sequence number, starting at 1, and is
1169
+ displayed in base 36 by default. Here they're purely linear; the
1170
+ sequences are very helpful when looking at code with loops and
1171
+ branches.
1172
+
1173
+ The symbol between angle brackets indicates the op's type, for
1174
+ example; <2> is a BINOP, <@> a LISTOP, and <#> is a PADOP, which is
1175
+ used in threaded perls. (see L</"OP class abbreviations">).
1176
+
1177
+ The opname, as in B<'add[t1]'>, may be followed by op-specific
1178
+ information in parentheses or brackets (ex B<'[t1]'>).
1179
+
1180
+ The op-flags (ex B<'sK/2'>) are described in (L</"OP flags
1181
+ abbreviations">).
1182
+
1183
+ % perl -MO=Concise -e '$a = $b + 42'
1184
+ 8 <@> leave[1 ref] vKP/REFC ->(end)
1185
+ 1 <0> enter ->2
1186
+ 2 <;> nextstate(main 1 -e:1) v ->3
1187
+ 7 <2> sassign vKS/2 ->8
1188
+ * 5 <2> add[t1] sK/2 ->6
1189
+ - <1> ex-rv2sv sK/1 ->4
1190
+ 3 <$> gvsv(*b) s ->4
1191
+ 4 <$> const(IV 42) s ->5
1192
+ - <1> ex-rv2sv sKRM*/1 ->7
1193
+ 6 <$> gvsv(*a) s ->7
1194
+
1195
+ The default rendering is top-down, so they're not in execution order.
1196
+ This form reflects the way the stack is used to parse and evaluate
1197
+ expressions; the add operates on the two terms below it in the tree.
1198
+
1199
+ Nullops appear as C<ex-opname>, where I<opname> is an op that has been
1200
+ optimized away by perl. They're displayed with a sequence-number of
1201
+ '-', because they are not executed (they don't appear in previous
1202
+ example), they're printed here because they reflect the parse.
1203
+
1204
+ The arrow points to the sequence number of the next op; they're not
1205
+ displayed in -exec mode, for obvious reasons.
1206
+
1207
+ Note that because this rendering was done on a non-threaded perl, the
1208
+ PADOPs in the previous examples are now SVOPs, and some (but not all)
1209
+ of the square brackets have been replaced by round ones. This is a
1210
+ subtle feature to provide some visual distinction between renderings
1211
+ on threaded and un-threaded perls.
1212
+
1213
+
1214
+ =head1 OPTIONS
1215
+
1216
+ Arguments that don't start with a hyphen are taken to be the names of
1217
+ subroutines or formats to render; if no
1218
+ such functions are specified, the main
1219
+ body of the program (outside any subroutines, and not including use'd
1220
+ or require'd files) is rendered. Passing C<BEGIN>, C<UNITCHECK>,
1221
+ C<CHECK>, C<INIT>, or C<END> will cause all of the corresponding
1222
+ special blocks to be printed. Arguments must follow options.
1223
+
1224
+ Options affect how things are rendered (ie printed). They're presented
1225
+ here by their visual effect, 1st being strongest. They're grouped
1226
+ according to how they interrelate; within each group the options are
1227
+ mutually exclusive (unless otherwise stated).
1228
+
1229
+ =head2 Options for Opcode Ordering
1230
+
1231
+ These options control the 'vertical display' of opcodes. The display
1232
+ 'order' is also called 'mode' elsewhere in this document.
1233
+
1234
+ =over 4
1235
+
1236
+ =item B<-basic>
1237
+
1238
+ Print OPs in the order they appear in the OP tree (a preorder
1239
+ traversal, starting at the root). The indentation of each OP shows its
1240
+ level in the tree, and the '->' at the end of the line indicates the
1241
+ next opcode in execution order. This mode is the default, so the flag
1242
+ is included simply for completeness.
1243
+
1244
+ =item B<-exec>
1245
+
1246
+ Print OPs in the order they would normally execute (for the majority
1247
+ of constructs this is a postorder traversal of the tree, ending at the
1248
+ root). In most cases the OP that usually follows a given OP will
1249
+ appear directly below it; alternate paths are shown by indentation. In
1250
+ cases like loops when control jumps out of a linear path, a 'goto'
1251
+ line is generated.
1252
+
1253
+ =item B<-tree>
1254
+
1255
+ Print OPs in a text approximation of a tree, with the root of the tree
1256
+ at the left and 'left-to-right' order of children transformed into
1257
+ 'top-to-bottom'. Because this mode grows both to the right and down,
1258
+ it isn't suitable for large programs (unless you have a very wide
1259
+ terminal).
1260
+
1261
+ =back
1262
+
1263
+ =head2 Options for Line-Style
1264
+
1265
+ These options select the line-style (or just style) used to render
1266
+ each opcode, and dictates what info is actually printed into each line.
1267
+
1268
+ =over 4
1269
+
1270
+ =item B<-concise>
1271
+
1272
+ Use the author's favorite set of formatting conventions. This is the
1273
+ default, of course.
1274
+
1275
+ =item B<-terse>
1276
+
1277
+ Use formatting conventions that emulate the output of B<B::Terse>. The
1278
+ basic mode is almost indistinguishable from the real B<B::Terse>, and the
1279
+ exec mode looks very similar, but is in a more logical order and lacks
1280
+ curly brackets. B<B::Terse> doesn't have a tree mode, so the tree mode
1281
+ is only vaguely reminiscent of B<B::Terse>.
1282
+
1283
+ =item B<-linenoise>
1284
+
1285
+ Use formatting conventions in which the name of each OP, rather than being
1286
+ written out in full, is represented by a one- or two-character abbreviation.
1287
+ This is mainly a joke.
1288
+
1289
+ =item B<-debug>
1290
+
1291
+ Use formatting conventions reminiscent of CPAN module B<B::Debug>; these aren't
1292
+ very concise at all.
1293
+
1294
+ =item B<-env>
1295
+
1296
+ Use formatting conventions read from the environment variables
1297
+ C<B_CONCISE_FORMAT>, C<B_CONCISE_GOTO_FORMAT>, and C<B_CONCISE_TREE_FORMAT>.
1298
+
1299
+ =back
1300
+
1301
+ =head2 Options for tree-specific formatting
1302
+
1303
+ =over 4
1304
+
1305
+ =item B<-compact>
1306
+
1307
+ Use a tree format in which the minimum amount of space is used for the
1308
+ lines connecting nodes (one character in most cases). This squeezes out
1309
+ a few precious columns of screen real estate.
1310
+
1311
+ =item B<-loose>
1312
+
1313
+ Use a tree format that uses longer edges to separate OP nodes. This format
1314
+ tends to look better than the compact one, especially in ASCII, and is
1315
+ the default.
1316
+
1317
+ =item B<-vt>
1318
+
1319
+ Use tree connecting characters drawn from the VT100 line-drawing set.
1320
+ This looks better if your terminal supports it.
1321
+
1322
+ =item B<-ascii>
1323
+
1324
+ Draw the tree with standard ASCII characters like C<+> and C<|>. These don't
1325
+ look as clean as the VT100 characters, but they'll work with almost any
1326
+ terminal (or the horizontal scrolling mode of less(1)) and are suitable
1327
+ for text documentation or email. This is the default.
1328
+
1329
+ =back
1330
+
1331
+ These are pairwise exclusive, i.e. compact or loose, vt or ascii.
1332
+
1333
+ =head2 Options controlling sequence numbering
1334
+
1335
+ =over 4
1336
+
1337
+ =item B<-base>I<n>
1338
+
1339
+ Print OP sequence numbers in base I<n>. If I<n> is greater than 10, the
1340
+ digit for 11 will be 'a', and so on. If I<n> is greater than 36, the digit
1341
+ for 37 will be 'A', and so on until 62. Values greater than 62 are not
1342
+ currently supported. The default is 36.
1343
+
1344
+ =item B<-bigendian>
1345
+
1346
+ Print sequence numbers with the most significant digit first. This is the
1347
+ usual convention for Arabic numerals, and the default.
1348
+
1349
+ =item B<-littleendian>
1350
+
1351
+ Print sequence numbers with the least significant digit first. This is
1352
+ obviously mutually exclusive with bigendian.
1353
+
1354
+ =back
1355
+
1356
+ =head2 Other options
1357
+
1358
+ =over 4
1359
+
1360
+ =item B<-src>
1361
+
1362
+ With this option, the rendering of each statement (starting with the
1363
+ nextstate OP) will be preceded by the 1st line of source code that
1364
+ generates it. For example:
1365
+
1366
+ 1 <0> enter
1367
+ # 1: my $i;
1368
+ 2 <;> nextstate(main 1 junk.pl:1) v:{
1369
+ 3 <0> padsv[$i:1,10] vM/LVINTRO
1370
+ # 3: for $i (0..9) {
1371
+ 4 <;> nextstate(main 3 junk.pl:3) v:{
1372
+ 5 <0> pushmark s
1373
+ 6 <$> const[IV 0] s
1374
+ 7 <$> const[IV 9] s
1375
+ 8 <{> enteriter(next->j last->m redo->9)[$i:1,10] lKS
1376
+ k <0> iter s
1377
+ l <|> and(other->9) vK/1
1378
+ # 4: print "line ";
1379
+ 9 <;> nextstate(main 2 junk.pl:4) v
1380
+ a <0> pushmark s
1381
+ b <$> const[PV "line "] s
1382
+ c <@> print vK
1383
+ # 5: print "$i\n";
1384
+ ...
1385
+
1386
+ =item B<-stash="somepackage">
1387
+
1388
+ With this, "somepackage" will be required, then the stash is
1389
+ inspected, and each function is rendered.
1390
+
1391
+ =back
1392
+
1393
+ The following options are pairwise exclusive.
1394
+
1395
+ =over 4
1396
+
1397
+ =item B<-main>
1398
+
1399
+ Include the main program in the output, even if subroutines were also
1400
+ specified. This rendering is normally suppressed when a subroutine
1401
+ name or reference is given.
1402
+
1403
+ =item B<-nomain>
1404
+
1405
+ This restores the default behavior after you've changed it with '-main'
1406
+ (it's not normally needed). If no subroutine name/ref is given, main is
1407
+ rendered, regardless of this flag.
1408
+
1409
+ =item B<-nobanner>
1410
+
1411
+ Renderings usually include a banner line identifying the function name
1412
+ or stringified subref. This suppresses the printing of the banner.
1413
+
1414
+ TBC: Remove the stringified coderef; while it provides a 'cookie' for
1415
+ each function rendered, the cookies used should be 1,2,3.. not a
1416
+ random hex-address. It also complicates string comparison of two
1417
+ different trees.
1418
+
1419
+ =item B<-banner>
1420
+
1421
+ restores default banner behavior.
1422
+
1423
+ =item B<-banneris> => subref
1424
+
1425
+ TBC: a hookpoint (and an option to set it) for a user-supplied
1426
+ function to produce a banner appropriate for users needs. It's not
1427
+ ideal, because the rendering-state variables, which are a natural
1428
+ candidate for use in concise.t, are unavailable to the user.
1429
+
1430
+ =back
1431
+
1432
+ =head2 Option Stickiness
1433
+
1434
+ If you invoke Concise more than once in a program, you should know that
1435
+ the options are 'sticky'. This means that the options you provide in
1436
+ the first call will be remembered for the 2nd call, unless you
1437
+ re-specify or change them.
1438
+
1439
+ =head1 ABBREVIATIONS
1440
+
1441
+ The concise style uses symbols to convey maximum info with minimal
1442
+ clutter (like hex addresses). With just a little practice, you can
1443
+ start to see the flowers, not just the branches, in the trees.
1444
+
1445
+ =head2 OP class abbreviations
1446
+
1447
+ These symbols appear before the op-name, and indicate the
1448
+ B:: namespace that represents the ops in your Perl code.
1449
+
1450
+ 0 OP (aka BASEOP) An OP with no children
1451
+ 1 UNOP An OP with one child
1452
+ + UNOP_AUX A UNOP with auxillary fields
1453
+ 2 BINOP An OP with two children
1454
+ | LOGOP A control branch OP
1455
+ @ LISTOP An OP that could have lots of children
1456
+ / PMOP An OP with a regular expression
1457
+ $ SVOP An OP with an SV
1458
+ " PVOP An OP with a string
1459
+ { LOOP An OP that holds pointers for a loop
1460
+ ; COP An OP that marks the start of a statement
1461
+ # PADOP An OP with a GV on the pad
1462
+ . METHOP An OP with method call info
1463
+
1464
+ =head2 OP flags abbreviations
1465
+
1466
+ OP flags are either public or private. The public flags alter the
1467
+ behavior of each opcode in consistent ways, and are represented by 0
1468
+ or more single characters.
1469
+
1470
+ v OPf_WANT_VOID Want nothing (void context)
1471
+ s OPf_WANT_SCALAR Want single value (scalar context)
1472
+ l OPf_WANT_LIST Want list of any length (list context)
1473
+ Want is unknown
1474
+ K OPf_KIDS There is a firstborn child.
1475
+ P OPf_PARENS This operator was parenthesized.
1476
+ (Or block needs explicit scope entry.)
1477
+ R OPf_REF Certified reference.
1478
+ (Return container, not containee).
1479
+ M OPf_MOD Will modify (lvalue).
1480
+ S OPf_STACKED Some arg is arriving on the stack.
1481
+ * OPf_SPECIAL Do something weird for this op (see op.h)
1482
+
1483
+ Private flags, if any are set for an opcode, are displayed after a '/'
1484
+
1485
+ 8 <@> leave[1 ref] vKP/REFC ->(end)
1486
+ 7 <2> sassign vKS/2 ->8
1487
+
1488
+ They're opcode specific, and occur less often than the public ones, so
1489
+ they're represented by short mnemonics instead of single-chars; see
1490
+ B::Op_private and F<regen/op_private> for more details.
1491
+
1492
+ Note that a number after a '/' often indicates the number of arguments.
1493
+ In the I<sassign> example above, the OP takes 2 arguments. These values
1494
+ are sometimes used at runtime: in particular, the MAXARG macro makes use
1495
+ of them.
1496
+
1497
+ =head1 FORMATTING SPECIFICATIONS
1498
+
1499
+ For each line-style ('concise', 'terse', 'linenoise', etc.) there are
1500
+ 3 format-specs which control how OPs are rendered.
1501
+
1502
+ The first is the 'default' format, which is used in both basic and exec
1503
+ modes to print all opcodes. The 2nd, goto-format, is used in exec
1504
+ mode when branches are encountered. They're not real opcodes, and are
1505
+ inserted to look like a closing curly brace. The tree-format is tree
1506
+ specific.
1507
+
1508
+ When a line is rendered, the correct format-spec is copied and scanned
1509
+ for the following items; data is substituted in, and other
1510
+ manipulations like basic indenting are done, for each opcode rendered.
1511
+
1512
+ There are 3 kinds of items that may be populated; special patterns,
1513
+ #vars, and literal text, which is copied verbatim. (Yes, it's a set
1514
+ of s///g steps.)
1515
+
1516
+ =head2 Special Patterns
1517
+
1518
+ These items are the primitives used to perform indenting, and to
1519
+ select text from amongst alternatives.
1520
+
1521
+ =over 4
1522
+
1523
+ =item B<(x(>I<exec_text>B<;>I<basic_text>B<)x)>
1524
+
1525
+ Generates I<exec_text> in exec mode, or I<basic_text> in basic mode.
1526
+
1527
+ =item B<(*(>I<text>B<)*)>
1528
+
1529
+ Generates one copy of I<text> for each indentation level.
1530
+
1531
+ =item B<(*(>I<text1>B<;>I<text2>B<)*)>
1532
+
1533
+ Generates one fewer copies of I<text1> than the indentation level, followed
1534
+ by one copy of I<text2> if the indentation level is more than 0.
1535
+
1536
+ =item B<(?(>I<text1>B<#>I<var>I<Text2>B<)?)>
1537
+
1538
+ If the value of I<var> is true (not empty or zero), generates the
1539
+ value of I<var> surrounded by I<text1> and I<Text2>, otherwise
1540
+ nothing.
1541
+
1542
+ =item B<~>
1543
+
1544
+ Any number of tildes and surrounding whitespace will be collapsed to
1545
+ a single space.
1546
+
1547
+ =back
1548
+
1549
+ =head2 # Variables
1550
+
1551
+ These #vars represent opcode properties that you may want as part of
1552
+ your rendering. The '#' is intended as a private sigil; a #var's
1553
+ value is interpolated into the style-line, much like "read $this".
1554
+
1555
+ These vars take 3 forms:
1556
+
1557
+ =over 4
1558
+
1559
+ =item B<#>I<var>
1560
+
1561
+ A property named 'var' is assumed to exist for the opcodes, and is
1562
+ interpolated into the rendering.
1563
+
1564
+ =item B<#>I<var>I<N>
1565
+
1566
+ Generates the value of I<var>, left justified to fill I<N> spaces.
1567
+ Note that this means while you can have properties 'foo' and 'foo2',
1568
+ you cannot render 'foo2', but you could with 'foo2a'. You would be
1569
+ wise not to rely on this behavior going forward ;-)
1570
+
1571
+ =item B<#>I<Var>
1572
+
1573
+ This ucfirst form of #var generates a tag-value form of itself for
1574
+ display; it converts '#Var' into a 'Var => #var' style, which is then
1575
+ handled as described above. (Imp-note: #Vars cannot be used for
1576
+ conditional-fills, because the => #var transform is done after the check
1577
+ for #Var's value).
1578
+
1579
+ =back
1580
+
1581
+ The following variables are 'defined' by B::Concise; when they are
1582
+ used in a style, their respective values are plugged into the
1583
+ rendering of each opcode.
1584
+
1585
+ Only some of these are used by the standard styles, the others are
1586
+ provided for you to delve into optree mechanics, should you wish to
1587
+ add a new style (see L</add_style> below) that uses them. You can
1588
+ also add new ones using L</add_callback>.
1589
+
1590
+ =over 4
1591
+
1592
+ =item B<#addr>
1593
+
1594
+ The address of the OP, in hexadecimal.
1595
+
1596
+ =item B<#arg>
1597
+
1598
+ The OP-specific information of the OP (such as the SV for an SVOP, the
1599
+ non-local exit pointers for a LOOP, etc.) enclosed in parentheses.
1600
+
1601
+ =item B<#class>
1602
+
1603
+ The B-determined class of the OP, in all caps.
1604
+
1605
+ =item B<#classsym>
1606
+
1607
+ A single symbol abbreviating the class of the OP.
1608
+
1609
+ =item B<#coplabel>
1610
+
1611
+ The label of the statement or block the OP is the start of, if any.
1612
+
1613
+ =item B<#exname>
1614
+
1615
+ The name of the OP, or 'ex-foo' if the OP is a null that used to be a foo.
1616
+
1617
+ =item B<#extarg>
1618
+
1619
+ The target of the OP, or nothing for a nulled OP.
1620
+
1621
+ =item B<#firstaddr>
1622
+
1623
+ The address of the OP's first child, in hexadecimal.
1624
+
1625
+ =item B<#flags>
1626
+
1627
+ The OP's flags, abbreviated as a series of symbols.
1628
+
1629
+ =item B<#flagval>
1630
+
1631
+ The numeric value of the OP's flags.
1632
+
1633
+ =item B<#hints>
1634
+
1635
+ The COP's hint flags, rendered with abbreviated names if possible. An empty
1636
+ string if this is not a COP. Here are the symbols used:
1637
+
1638
+ $ strict refs
1639
+ & strict subs
1640
+ * strict vars
1641
+ x$ explicit use/no strict refs
1642
+ x& explicit use/no strict subs
1643
+ x* explicit use/no strict vars
1644
+ i integers
1645
+ l locale
1646
+ b bytes
1647
+ { block scope
1648
+ % localise %^H
1649
+ < open in
1650
+ > open out
1651
+ I overload int
1652
+ F overload float
1653
+ B overload binary
1654
+ S overload string
1655
+ R overload re
1656
+ T taint
1657
+ E eval
1658
+ X filetest access
1659
+ U utf-8
1660
+
1661
+ us use feature 'unicode_strings'
1662
+ fea=NNN feature bundle number
1663
+
1664
+ =item B<#hintsval>
1665
+
1666
+ The numeric value of the COP's hint flags, or an empty string if this is not
1667
+ a COP.
1668
+
1669
+ =item B<#hyphseq>
1670
+
1671
+ The sequence number of the OP, or a hyphen if it doesn't have one.
1672
+
1673
+ =item B<#label>
1674
+
1675
+ 'NEXT', 'LAST', or 'REDO' if the OP is a target of one of those in exec
1676
+ mode, or empty otherwise.
1677
+
1678
+ =item B<#lastaddr>
1679
+
1680
+ The address of the OP's last child, in hexadecimal.
1681
+
1682
+ =item B<#name>
1683
+
1684
+ The OP's name.
1685
+
1686
+ =item B<#NAME>
1687
+
1688
+ The OP's name, in all caps.
1689
+
1690
+ =item B<#next>
1691
+
1692
+ The sequence number of the OP's next OP.
1693
+
1694
+ =item B<#nextaddr>
1695
+
1696
+ The address of the OP's next OP, in hexadecimal.
1697
+
1698
+ =item B<#noise>
1699
+
1700
+ A one- or two-character abbreviation for the OP's name.
1701
+
1702
+ =item B<#private>
1703
+
1704
+ The OP's private flags, rendered with abbreviated names if possible.
1705
+
1706
+ =item B<#privval>
1707
+
1708
+ The numeric value of the OP's private flags.
1709
+
1710
+ =item B<#seq>
1711
+
1712
+ The sequence number of the OP. Note that this is a sequence number
1713
+ generated by B::Concise.
1714
+
1715
+ =item B<#opt>
1716
+
1717
+ Whether or not the op has been optimized by the peephole optimizer.
1718
+
1719
+ =item B<#sibaddr>
1720
+
1721
+ The address of the OP's next youngest sibling, in hexadecimal.
1722
+
1723
+ =item B<#svaddr>
1724
+
1725
+ The address of the OP's SV, if it has an SV, in hexadecimal.
1726
+
1727
+ =item B<#svclass>
1728
+
1729
+ The class of the OP's SV, if it has one, in all caps (e.g., 'IV').
1730
+
1731
+ =item B<#svval>
1732
+
1733
+ The value of the OP's SV, if it has one, in a short human-readable format.
1734
+
1735
+ =item B<#targ>
1736
+
1737
+ The numeric value of the OP's targ.
1738
+
1739
+ =item B<#targarg>
1740
+
1741
+ The name of the variable the OP's targ refers to, if any, otherwise the
1742
+ letter t followed by the OP's targ in decimal.
1743
+
1744
+ =item B<#targarglife>
1745
+
1746
+ Same as B<#targarg>, but followed by the COP sequence numbers that delimit
1747
+ the variable's lifetime (or 'end' for a variable in an open scope) for a
1748
+ variable.
1749
+
1750
+ =item B<#typenum>
1751
+
1752
+ The numeric value of the OP's type, in decimal.
1753
+
1754
+ =back
1755
+
1756
+ =head1 One-Liner Command tips
1757
+
1758
+ =over 4
1759
+
1760
+ =item perl -MO=Concise,bar foo.pl
1761
+
1762
+ Renders only bar() from foo.pl. To see main, drop the ',bar'. To see
1763
+ both, add ',-main'
1764
+
1765
+ =item perl -MDigest::MD5=md5 -MO=Concise,md5 -e1
1766
+
1767
+ Identifies md5 as an XS function. The export is needed so that BC can
1768
+ find it in main.
1769
+
1770
+ =item perl -MPOSIX -MO=Concise,_POSIX_ARG_MAX -e1
1771
+
1772
+ Identifies _POSIX_ARG_MAX as a constant sub, optimized to an IV.
1773
+ Although POSIX isn't entirely consistent across platforms, this is
1774
+ likely to be present in virtually all of them.
1775
+
1776
+ =item perl -MPOSIX -MO=Concise,a -e 'print _POSIX_SAVED_IDS'
1777
+
1778
+ This renders a print statement, which includes a call to the function.
1779
+ It's identical to rendering a file with a use call and that single
1780
+ statement, except for the filename which appears in the nextstate ops.
1781
+
1782
+ =item perl -MPOSIX -MO=Concise,a -e 'sub a{_POSIX_SAVED_IDS}'
1783
+
1784
+ This is B<very> similar to previous, only the first two ops differ. This
1785
+ subroutine rendering is more representative, insofar as a single main
1786
+ program will have many subs.
1787
+
1788
+ =item perl -MB::Concise -e 'B::Concise::compile("-exec","-src", \%B::Concise::)->()'
1789
+
1790
+ This renders all functions in the B::Concise package with the source
1791
+ lines. It eschews the O framework so that the stashref can be passed
1792
+ directly to B::Concise::compile(). See -stash option for a more
1793
+ convenient way to render a package.
1794
+
1795
+ =back
1796
+
1797
+ =head1 Using B::Concise outside of the O framework
1798
+
1799
+ The common (and original) usage of B::Concise was for command-line
1800
+ renderings of simple code, as given in EXAMPLE. But you can also use
1801
+ B<B::Concise> from your code, and call compile() directly, and
1802
+ repeatedly. By doing so, you can avoid the compile-time only
1803
+ operation of O.pm, and even use the debugger to step through
1804
+ B::Concise::compile() itself.
1805
+
1806
+ Once you're doing this, you may alter Concise output by adding new
1807
+ rendering styles, and by optionally adding callback routines which
1808
+ populate new variables, if such were referenced from those (just
1809
+ added) styles.
1810
+
1811
+ =head2 Example: Altering Concise Renderings
1812
+
1813
+ use B::Concise qw(set_style add_callback);
1814
+ add_style($yourStyleName => $defaultfmt, $gotofmt, $treefmt);
1815
+ add_callback
1816
+ ( sub {
1817
+ my ($h, $op, $format, $level, $stylename) = @_;
1818
+ $h->{variable} = some_func($op);
1819
+ });
1820
+ $walker = B::Concise::compile(@options,@subnames,@subrefs);
1821
+ $walker->();
1822
+
1823
+ =head2 set_style()
1824
+
1825
+ B<set_style> accepts 3 arguments, and updates the three format-specs
1826
+ comprising a line-style (basic-exec, goto, tree). It has one minor
1827
+ drawback though; it doesn't register the style under a new name. This
1828
+ can become an issue if you render more than once and switch styles.
1829
+ Thus you may prefer to use add_style() and/or set_style_standard()
1830
+ instead.
1831
+
1832
+ =head2 set_style_standard($name)
1833
+
1834
+ This restores one of the standard line-styles: C<terse>, C<concise>,
1835
+ C<linenoise>, C<debug>, C<env>, into effect. It also accepts style
1836
+ names previously defined with add_style().
1837
+
1838
+ =head2 add_style ()
1839
+
1840
+ This subroutine accepts a new style name and three style arguments as
1841
+ above, and creates, registers, and selects the newly named style. It is
1842
+ an error to re-add a style; call set_style_standard() to switch between
1843
+ several styles.
1844
+
1845
+ =head2 add_callback ()
1846
+
1847
+ If your newly minted styles refer to any new #variables, you'll need
1848
+ to define a callback subroutine that will populate (or modify) those
1849
+ variables. They are then available for use in the style you've
1850
+ chosen.
1851
+
1852
+ The callbacks are called for each opcode visited by Concise, in the
1853
+ same order as they are added. Each subroutine is passed five
1854
+ parameters.
1855
+
1856
+ 1. A hashref, containing the variable names and values which are
1857
+ populated into the report-line for the op
1858
+ 2. the op, as a B<B::OP> object
1859
+ 3. a reference to the format string
1860
+ 4. the formatting (indent) level
1861
+ 5. the selected stylename
1862
+
1863
+ To define your own variables, simply add them to the hash, or change
1864
+ existing values if you need to. The level and format are passed in as
1865
+ references to scalars, but it is unlikely that they will need to be
1866
+ changed or even used.
1867
+
1868
+ =head2 Running B::Concise::compile()
1869
+
1870
+ B<compile> accepts options as described above in L</OPTIONS>, and
1871
+ arguments, which are either coderefs, or subroutine names.
1872
+
1873
+ It constructs and returns a $treewalker coderef, which when invoked,
1874
+ traverses, or walks, and renders the optrees of the given arguments to
1875
+ STDOUT. You can reuse this, and can change the rendering style used
1876
+ each time; thereafter the coderef renders in the new style.
1877
+
1878
+ B<walk_output> lets you change the print destination from STDOUT to
1879
+ another open filehandle, or into a string passed as a ref (unless
1880
+ you've built perl with -Uuseperlio).
1881
+
1882
+ my $walker = B::Concise::compile('-terse','aFuncName', \&aSubRef); # 1
1883
+ walk_output(\my $buf);
1884
+ $walker->(); # 1 renders -terse
1885
+ set_style_standard('concise'); # 2
1886
+ $walker->(); # 2 renders -concise
1887
+ $walker->(@new); # 3 renders whatever
1888
+ print "3 different renderings: terse, concise, and @new: $buf\n";
1889
+
1890
+ When $walker is called, it traverses the subroutines supplied when it
1891
+ was created, and renders them using the current style. You can change
1892
+ the style afterwards in several different ways:
1893
+
1894
+ 1. call C<compile>, altering style or mode/order
1895
+ 2. call C<set_style_standard>
1896
+ 3. call $walker, passing @new options
1897
+
1898
+ Passing new options to the $walker is the easiest way to change
1899
+ amongst any pre-defined styles (the ones you add are automatically
1900
+ recognized as options), and is the only way to alter rendering order
1901
+ without calling compile again. Note however that rendering state is
1902
+ still shared amongst multiple $walker objects, so they must still be
1903
+ used in a coordinated manner.
1904
+
1905
+ =head2 B::Concise::reset_sequence()
1906
+
1907
+ This function (not exported) lets you reset the sequence numbers (note
1908
+ that they're numbered arbitrarily, their goal being to be human
1909
+ readable). Its purpose is mostly to support testing, i.e. to compare
1910
+ the concise output from two identical anonymous subroutines (but
1911
+ different instances). Without the reset, B::Concise, seeing that
1912
+ they're separate optrees, generates different sequence numbers in
1913
+ the output.
1914
+
1915
+ =head2 Errors
1916
+
1917
+ Errors in rendering (non-existent function-name, non-existent coderef)
1918
+ are written to the STDOUT, or wherever you've set it via
1919
+ walk_output().
1920
+
1921
+ Errors using the various *style* calls, and bad args to walk_output(),
1922
+ result in die(). Use an eval if you wish to catch these errors and
1923
+ continue processing.
1924
+
1925
+ =head1 AUTHOR
1926
+
1927
+ Stephen McCamant, E<lt>smcc@CSUA.Berkeley.EDUE<gt>.
1928
+
1929
+ =cut
git/usr/lib/perl5/core_perl/B/Showlex.pm ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package B::Showlex;
2
+
3
+ our $VERSION = '1.05';
4
+
5
+ use strict;
6
+ use B qw(svref_2object comppadlist class);
7
+ use B::Terse ();
8
+ use B::Concise ();
9
+
10
+ #
11
+ # Invoke as
12
+ # perl -MO=Showlex,foo bar.pl
13
+ # to see the names of lexical variables used by &foo
14
+ # or as
15
+ # perl -MO=Showlex bar.pl
16
+ # to see the names of file scope lexicals used by bar.pl
17
+ #
18
+
19
+
20
+ # borrowed from B::Concise
21
+ our $walkHandle = \*STDOUT;
22
+
23
+ sub walk_output { # updates $walkHandle
24
+ $walkHandle = B::Concise::walk_output(@_);
25
+ #print "got $walkHandle";
26
+ #print $walkHandle "using it";
27
+ $walkHandle;
28
+ }
29
+
30
+ sub shownamearray {
31
+ my ($name, $av) = @_;
32
+ my @els = $av->ARRAY;
33
+ my $count = @els;
34
+ my $i;
35
+ print $walkHandle "$name has $count entries\n";
36
+ for ($i = 0; $i < $count; $i++) {
37
+ my $sv = $els[$i];
38
+ if (class($sv) ne "SPECIAL") {
39
+ printf $walkHandle "$i: (0x%lx) %s\n",
40
+ $$sv, $sv->PVX // "undef" || "const";
41
+ } else {
42
+ printf $walkHandle "$i: %s\n", $sv->terse;
43
+ #printf $walkHandle "$i: %s\n", B::Concise::concise_sv($sv);
44
+ }
45
+ }
46
+ }
47
+
48
+ sub showvaluearray {
49
+ my ($name, $av) = @_;
50
+ my @els = $av->ARRAY;
51
+ my $count = @els;
52
+ my $i;
53
+ print $walkHandle "$name has $count entries\n";
54
+ for ($i = 0; $i < $count; $i++) {
55
+ printf $walkHandle "$i: %s\n", $els[$i]->terse;
56
+ #print $walkHandle "$i: %s\n", B::Concise::concise_sv($els[$i]);
57
+ }
58
+ }
59
+
60
+ sub showlex {
61
+ my ($objname, $namesav, $valsav) = @_;
62
+ shownamearray("Pad of lexical names for $objname", $namesav);
63
+ showvaluearray("Pad of lexical values for $objname", $valsav);
64
+ }
65
+
66
+ my ($newlex, $nosp1); # rendering state vars
67
+
68
+ sub padname_terse {
69
+ my $name = shift;
70
+ return $name->terse if class($name) eq 'SPECIAL';
71
+ my $str = $name->PVX;
72
+ return sprintf "(0x%lx) %s",
73
+ $$name,
74
+ length $str ? qq'"$str"' : defined $str ? "const" : 'undef';
75
+ }
76
+
77
+ sub newlex { # drop-in for showlex
78
+ my ($objname, $names, $vals) = @_;
79
+ my @names = $names->ARRAY;
80
+ my @vals = $vals->ARRAY;
81
+ my $count = @names;
82
+ print $walkHandle "$objname Pad has $count entries\n";
83
+ printf $walkHandle "0: %s\n", padname_terse($names[0]) unless $nosp1;
84
+ for (my $i = 1; $i < $count; $i++) {
85
+ printf $walkHandle "$i: %s = %s\n", padname_terse($names[$i]),
86
+ $vals[$i]->terse,
87
+ unless $nosp1
88
+ and class($names[$i]) eq 'SPECIAL' || !$names[$i]->LEN;
89
+ }
90
+ }
91
+
92
+ sub showlex_obj {
93
+ my ($objname, $obj) = @_;
94
+ $objname =~ s/^&main::/&/;
95
+ showlex($objname, svref_2object($obj)->PADLIST->ARRAY) if !$newlex;
96
+ newlex ($objname, svref_2object($obj)->PADLIST->ARRAY) if $newlex;
97
+ }
98
+
99
+ sub showlex_main {
100
+ showlex("comppadlist", comppadlist->ARRAY) if !$newlex;
101
+ newlex ("main", comppadlist->ARRAY) if $newlex;
102
+ }
103
+
104
+ sub compile {
105
+ my @options = grep(/^-/, @_);
106
+ my @args = grep(!/^-/, @_);
107
+ for my $o (@options) {
108
+ $newlex = 1 if $o eq "-newlex";
109
+ $nosp1 = 1 if $o eq "-nosp";
110
+ }
111
+
112
+ return \&showlex_main unless @args;
113
+ return sub {
114
+ my $objref;
115
+ foreach my $objname (@args) {
116
+ next unless $objname; # skip nulls w/o carping
117
+
118
+ if (ref $objname) {
119
+ print $walkHandle "B::Showlex::compile($objname)\n";
120
+ $objref = $objname;
121
+ } else {
122
+ $objname = "main::$objname" unless $objname =~ /::/;
123
+ print $walkHandle "$objname:\n";
124
+ no strict 'refs';
125
+ die "err: unknown function ($objname)\n"
126
+ unless *{$objname}{CODE};
127
+ $objref = \&$objname;
128
+ }
129
+ showlex_obj($objname, $objref);
130
+ }
131
+ }
132
+ }
133
+
134
+ 1;
135
+
136
+ __END__
137
+
138
+ =head1 NAME
139
+
140
+ B::Showlex - Show lexical variables used in functions or files
141
+
142
+ =head1 SYNOPSIS
143
+
144
+ perl -MO=Showlex[,-OPTIONS][,SUBROUTINE] foo.pl
145
+
146
+ =head1 DESCRIPTION
147
+
148
+ When a comma-separated list of subroutine names is given as options, Showlex
149
+ prints the lexical variables used in those subroutines. Otherwise, it prints
150
+ the file-scope lexicals in the file.
151
+
152
+ =head1 EXAMPLES
153
+
154
+ Traditional form:
155
+
156
+ $ perl -MO=Showlex -e 'my ($i,$j,$k)=(1,"foo")'
157
+ Pad of lexical names for comppadlist has 4 entries
158
+ 0: (0x8caea4) undef
159
+ 1: (0x9db0fb0) $i
160
+ 2: (0x9db0f38) $j
161
+ 3: (0x9db0f50) $k
162
+ Pad of lexical values for comppadlist has 5 entries
163
+ 0: SPECIAL #1 &PL_sv_undef
164
+ 1: NULL (0x9da4234)
165
+ 2: NULL (0x9db0f2c)
166
+ 3: NULL (0x9db0f44)
167
+ 4: NULL (0x9da4264)
168
+ -e syntax OK
169
+
170
+ New-style form:
171
+
172
+ $ perl -MO=Showlex,-newlex -e 'my ($i,$j,$k)=(1,"foo")'
173
+ main Pad has 4 entries
174
+ 0: (0x8caea4) undef
175
+ 1: (0xa0c4fb8) "$i" = NULL (0xa0b8234)
176
+ 2: (0xa0c4f40) "$j" = NULL (0xa0c4f34)
177
+ 3: (0xa0c4f58) "$k" = NULL (0xa0c4f4c)
178
+ -e syntax OK
179
+
180
+ New form, no specials, outside O framework:
181
+
182
+ $ perl -MB::Showlex -e \
183
+ 'my ($i,$j,$k)=(1,"foo"); B::Showlex::compile(-newlex,-nosp)->()'
184
+ main Pad has 4 entries
185
+ 1: (0x998ffb0) "$i" = IV (0x9983234) 1
186
+ 2: (0x998ff68) "$j" = PV (0x998ff5c) "foo"
187
+ 3: (0x998ff80) "$k" = NULL (0x998ff74)
188
+
189
+ Note that this example shows the values of the lexicals, whereas the other
190
+ examples did not (as they're compile-time only).
191
+
192
+ =head2 OPTIONS
193
+
194
+ The C<-newlex> option produces a more readable C<< name => value >> format,
195
+ and is shown in the second example above.
196
+
197
+ The C<-nosp> option eliminates reporting of SPECIALs, such as C<0: SPECIAL
198
+ #1 &PL_sv_undef> above. Reporting of SPECIALs can sometimes overwhelm
199
+ your declared lexicals.
200
+
201
+ =head1 SEE ALSO
202
+
203
+ L<B::Showlex> can also be used outside of the O framework, as in the third
204
+ example. See L<B::Concise> for a fuller explanation of reasons.
205
+
206
+ =head1 TODO
207
+
208
+ Some of the reported info, such as hex addresses, is not particularly
209
+ valuable. Other information would be more useful for the typical
210
+ programmer, such as line-numbers, pad-slot reuses, etc.. Given this,
211
+ -newlex is not a particularly good flag-name.
212
+
213
+ =head1 AUTHOR
214
+
215
+ Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
216
+
217
+ =cut
git/usr/lib/perl5/core_perl/B/Terse.pm ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package B::Terse;
2
+
3
+ our $VERSION = '1.09';
4
+
5
+ use strict;
6
+ use B qw(class @specialsv_name);
7
+ use B::Concise qw(concise_subref set_style_standard);
8
+ use Carp;
9
+
10
+ sub terse {
11
+ my ($order, $subref) = @_;
12
+ set_style_standard("terse");
13
+ if ($order eq "exec") {
14
+ concise_subref('exec', $subref);
15
+ } else {
16
+ concise_subref('basic', $subref);
17
+ }
18
+ }
19
+
20
+ sub compile {
21
+ my @args = @_;
22
+ my $order = @args ? shift(@args) : "";
23
+ $order = "-exec" if $order eq "exec";
24
+ unshift @args, $order if $order ne "";
25
+ B::Concise::compile("-terse", @args);
26
+ }
27
+
28
+ sub indent {
29
+ my ($level) = @_ ? shift : 0;
30
+ return " " x $level;
31
+ }
32
+
33
+
34
+ sub B::SV::terse {
35
+ my($sv, $level) = (@_, 0);
36
+ my %info;
37
+ B::Concise::concise_sv($sv, \%info);
38
+ my $s = indent($level)
39
+ . B::Concise::fmt_line(\%info, $sv,
40
+ "#svclass~(?((#svaddr))?)~#svval", 0);
41
+ chomp $s;
42
+ print "$s\n" unless defined wantarray;
43
+ $s;
44
+ }
45
+
46
+ sub B::NULL::terse {
47
+ my ($sv, $level) = (@_, 0);
48
+ my $s = indent($level) . sprintf "%s (0x%lx)", class($sv), $$sv;
49
+ print "$s\n" unless defined wantarray;
50
+ $s;
51
+ }
52
+
53
+ sub B::SPECIAL::terse {
54
+ my ($sv, $level) = (@_, 0);
55
+ my $s = indent($level)
56
+ . sprintf( "%s #%d %s", class($sv), $$sv, $specialsv_name[$$sv]);
57
+ print "$s\n" unless defined wantarray;
58
+ $s;
59
+ }
60
+
61
+ 1;
62
+
63
+ __END__
64
+
65
+ =head1 NAME
66
+
67
+ B::Terse - Walk Perl syntax tree, printing terse info about ops
68
+
69
+ =head1 SYNOPSIS
70
+
71
+ perl -MO=Terse[,OPTIONS] foo.pl
72
+
73
+ =head1 DESCRIPTION
74
+
75
+ This module prints the contents of the parse tree, but without as much
76
+ information as CPAN module B::Debug. For comparison, C<print "Hello, world.">
77
+ produced 96 lines of output from B::Debug, but only 6 from B::Terse.
78
+
79
+ This module is useful for people who are writing their own back end,
80
+ or who are learning about the Perl internals. It's not useful to the
81
+ average programmer.
82
+
83
+ This version of B::Terse is really just a wrapper that calls L<B::Concise>
84
+ with the B<-terse> option. It is provided for compatibility with old scripts
85
+ (and habits) but using B::Concise directly is now recommended instead.
86
+
87
+ For compatibility with the old B::Terse, this module also adds a
88
+ method named C<terse> to B::OP and B::SV objects. The B::SV method is
89
+ largely compatible with the old one, though authors of new software
90
+ might be advised to choose a more user-friendly output format. The
91
+ B::OP C<terse> method, however, doesn't work well. Since B::Terse was
92
+ first written, much more information in OPs has migrated to the
93
+ scratchpad datastructure, but the C<terse> interface doesn't have any
94
+ way of getting to the correct pad. As a kludge, the new version will
95
+ always use the pad for the main program, but for OPs in subroutines
96
+ this will give the wrong answer or crash.
97
+
98
+ =head1 AUTHOR
99
+
100
+ The original version of B::Terse was written by Malcolm Beattie,
101
+ E<lt>mbeattie@sable.ox.ac.ukE<gt>. This wrapper was written by Stephen
102
+ McCamant, E<lt>smcc@MIT.EDUE<gt>.
103
+
104
+ =cut