Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / bin / perlbug
CommitLineData
920dae64
AT
1#!/import/archperf/ws/devtools/4/amd64/bin/perl
2 eval 'exec /import/archperf/ws/devtools/4/amd64/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5my $config_tag1 = 'v5.8.8 - Tue Jun 19 16:03:32 PDT 2007';
6
7my $patchlevel_date = 1138723930;
8my $patch_tags = '';
9my @patches = (
10 ''
11);
12
13use Config;
14use File::Spec; # keep perlbug Perl 5.005 compatible
15use Getopt::Std;
16use strict;
17
18sub paraprint;
19
20BEGIN {
21 eval "use Mail::Send;";
22 $::HaveSend = ($@ eq "");
23 eval "use Mail::Util;";
24 $::HaveUtil = ($@ eq "");
25 # use secure tempfiles wherever possible
26 eval "require File::Temp;";
27 $::HaveTemp = ($@ eq "");
28};
29
30my $Version = "1.35";
31
32# Changed in 1.06 to skip Mail::Send and Mail::Util if not available.
33# Changed in 1.07 to see more sendmail execs, and added pipe output.
34# Changed in 1.08 to use correct address for sendmail.
35# Changed in 1.09 to close the REP file before calling it up in the editor.
36# Also removed some old comments duplicated elsewhere.
37# Changed in 1.10 to run under VMS without Mail::Send; also fixed
38# temp filename generation.
39# Changed in 1.11 to clean up some text and removed Mail::Send deactivator.
40# Changed in 1.12 to check for editor errors, make save/send distinction
41# clearer and add $ENV{REPLYTO}.
42# Changed in 1.13 to hopefully make it more difficult to accidentally
43# send mail
44# Changed in 1.14 to make the prompts a little more clear on providing
45# helpful information. Also let file read fail gracefully.
46# Changed in 1.15 to add warnings to stop people using perlbug for non-bugs.
47# Also report selected environment variables.
48# Changed in 1.16 to include @INC, and allow user to re-edit if no changes.
49# Changed in 1.17 Win32 support added. GSAR 97-04-12
50# Changed in 1.18 add '-ok' option for reporting build success. CFR 97-06-18
51# Changed in 1.19 '-ok' default not '-v'
52# add local patch information
53# warn on '-ok' if this is an old system; add '-okay'
54# Changed in 1.20 Added patchlevel.h reading and version/config checks
55# Changed in 1.21 Added '-nok' for reporting build failure DFD 98-05-05
56# Changed in 1.22 Heavy reformatting & minor bugfixes HVDS 98-05-10
57# Changed in 1.23 Restore -ok(ay): say 'success'; don't prompt
58# Changed in 1.24 Added '-F<file>' to save report HVDS 98-07-01
59# Changed in 1.25 Warn on failure to open save file. HVDS 98-07-12
60# Changed in 1.26 Don't require -t STDIN for -ok. HVDS 98-07-15
61# Changed in 1.27 Added Mac OS and File::Spec support CNANDOR 99-07-27
62# Changed in 1.28 Additional questions for Perlbugtron RFOLEY 20.03.2000
63# Changed in 1.29 Perlbug(tron): auto(-ok), short prompts RFOLEY 05-05-2000
64# Changed in 1.30 Added warnings on failure to open files MSTEVENS 13-07-2000
65# Changed in 1.31 Add checks on close().Fix my $var unless. TJENNESS 26-07-2000
66# Changed in 1.32 Use File::Spec->tmpdir TJENNESS 20-08-2000
67# Changed in 1.33 Don't require -t STDOUT for -ok.
68# Changed in 1.34 Added Message-Id RFOLEY 18-06-2002
69# Changed in 1.35 Use File::Temp (patch from Solar Designer) NWCLARK 28-02-2004
70
71# TODO: - Allow the user to re-name the file on mail failure, and
72# make sure failure (transmission-wise) of Mail::Send is
73# accounted for.
74# - Test -b option
75
76my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename, $messageid, $domain,
77 $subject, $from, $verbose, $ed, $outfile, $Is_MacOS, $category, $severity,
78 $fh, $me, $Is_MSWin32, $Is_Linux, $Is_VMS, $msg, $body, $andcc, %REP, $ok,
79 $Is_OpenBSD);
80
81my $perl_version = $^V ? sprintf("v%vd", $^V) : $];
82
83my $config_tag2 = "$perl_version - $Config{cf_time}";
84
85Init();
86
87if ($::opt_h) { Help(); exit; }
88if ($::opt_d) { Dump(*STDOUT); exit; }
89if (!-t STDIN && !($ok and not $::opt_n)) {
90 paraprint <<EOF;
91Please use perlbug interactively. If you want to
92include a file, you can use the -f switch.
93EOF
94 die "\n";
95}
96
97Query();
98Edit() unless $usefile || ($ok and not $::opt_n);
99NowWhat();
100Send();
101
102exit;
103
104sub ask_for_alternatives { # (category|severity)
105 my $name = shift;
106 my %alts = (
107 'category' => {
108 'default' => 'core',
109 'ok' => 'install',
110 'opts' => [qw(core docs install library utilities)], # patch, notabug
111 },
112 'severity' => {
113 'default' => 'low',
114 'ok' => 'none',
115 'opts' => [qw(critical high medium low wishlist none)], # zero
116 },
117 );
118 die "Invalid alternative($name) requested\n" unless grep(/^$name$/, keys %alts);
119 my $alt = "";
120 if ($ok) {
121 $alt = $alts{$name}{'ok'};
122 } else {
123 my @alts = @{$alts{$name}{'opts'}};
124 paraprint <<EOF;
125Please pick a \u$name from the following:
126
127 @alts
128
129EOF
130 my $err = 0;
131 do {
132 if ($err++ > 5) {
133 die "Invalid $name: aborting.\n";
134 }
135 print "Please enter a \u$name [$alts{$name}{'default'}]: ";
136 $alt = <>;
137 chomp $alt;
138 if ($alt =~ /^\s*$/) {
139 $alt = $alts{$name}{'default'};
140 }
141 } while !((($alt) = grep(/^$alt/i, @alts)));
142 }
143 lc $alt;
144}
145
146sub Init {
147 # -------- Setup --------
148
149 $Is_MSWin32 = $^O eq 'MSWin32';
150 $Is_VMS = $^O eq 'VMS';
151 $Is_Linux = lc($^O) eq 'linux';
152 $Is_OpenBSD = lc($^O) eq 'openbsd';
153 $Is_MacOS = $^O eq 'MacOS';
154
155 @ARGV = split m/\s+/,
156 MacPerl::Ask('Provide command-line args here (-h for help):')
157 if $Is_MacOS && $MacPerl::Version =~ /App/;
158
159 if (!getopts("Adhva:s:b:f:F:r:e:SCc:to:n:")) { Help(); exit; };
160
161 # This comment is needed to notify metaconfig that we are
162 # using the $perladmin, $cf_by, and $cf_time definitions.
163
164 # -------- Configuration ---------
165
166 # perlbug address
167 $perlbug = 'perlbug@perl.org';
168
169 # Test address
170 $testaddress = 'perlbug-test@perl.org';
171
172 # Target address
173 $address = $::opt_a || ($::opt_t ? $testaddress : $perlbug);
174
175 # Users address, used in message and in Reply-To header
176 $from = $::opt_r || "";
177
178 # Include verbose configuration information
179 $verbose = $::opt_v || 0;
180
181 # Subject of bug-report message
182 $subject = $::opt_s || "";
183
184 # Send a file
185 $usefile = ($::opt_f || 0);
186
187 # File to send as report
188 $file = $::opt_f || "";
189
190 # File to output to
191 $outfile = $::opt_F || "";
192
193 # Body of report
194 $body = $::opt_b || "";
195
196 # Editor
197 $ed = $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
198 || ($Is_VMS && "edit/tpu")
199 || ($Is_MSWin32 && "notepad")
200 || ($Is_MacOS && '')
201 || "vi";
202
203 # Not OK - provide build failure template by finessing OK report
204 if ($::opt_n) {
205 if (substr($::opt_n, 0, 2) eq 'ok' ) {
206 $::opt_o = substr($::opt_n, 1);
207 } else {
208 Help();
209 exit();
210 }
211 }
212
213 # OK - send "OK" report for build on this system
214 $ok = 0;
215 if ($::opt_o) {
216 if ($::opt_o eq 'k' or $::opt_o eq 'kay') {
217 my $age = time - $patchlevel_date;
218 if ($::opt_o eq 'k' and $age > 60 * 24 * 60 * 60 ) {
219 my $date = localtime $patchlevel_date;
220 print <<"EOF";
221"perlbug -ok" and "perlbug -nok" do not report on Perl versions which
222are more than 60 days old. This Perl version was constructed on
223$date. If you really want to report this, use
224"perlbug -okay" or "perlbug -nokay".
225EOF
226 exit();
227 }
228 # force these options
229 unless ($::opt_n) {
230 $::opt_S = 1; # don't prompt for send
231 $::opt_b = 1; # we have a body
232 $body = "Perl reported to build OK on this system.\n";
233 }
234 $::opt_C = 1; # don't send a copy to the local admin
235 $::opt_s = 1; # we have a subject line
236 $subject = ($::opt_n ? 'Not ' : '')
237 . "OK: perl $perl_version ${patch_tags}on"
238 ." $::Config{'archname'} $::Config{'osvers'} $subject";
239 $ok = 1;
240 } else {
241 Help();
242 exit();
243 }
244 }
245
246 # Possible administrator addresses, in order of confidence
247 # (Note that cf_email is not mentioned to metaconfig, since
248 # we don't really want it. We'll just take it if we have to.)
249 #
250 # This has to be after the $ok stuff above because of the way
251 # that $::opt_C is forced.
252 $cc = $::opt_C ? "" : (
253 $::opt_c || $::Config{'perladmin'}
254 || $::Config{'cf_email'} || $::Config{'cf_by'}
255 );
256
257 if ($::HaveUtil) {
258 $domain = Mail::Util::maildomain();
259 } elsif ($Is_MSWin32) {
260 $domain = $ENV{'USERDOMAIN'};
261 } else {
262 require Sys::Hostname;
263 $domain = Sys::Hostname::hostname();
264 }
265
266 # Message-Id - rjsf
267 $messageid = "<$::Config{'version'}_${$}_".time."\@$domain>";
268
269 # My username
270 $me = $Is_MSWin32 ? $ENV{'USERNAME'}
271 : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
272 : $Is_MacOS ? $ENV{'USER'}
273 : eval { getpwuid($<) }; # May be missing
274
275 $from = $::Config{'cf_email'}
276 if !$from && $::Config{'cf_email'} && $::Config{'cf_by'} && $me &&
277 ($me eq $::Config{'cf_by'});
278} # sub Init
279
280sub Query {
281 # Explain what perlbug is
282 unless ($ok) {
283 paraprint <<EOF;
284This program provides an easy way to create a message reporting a bug
285in perl, and e-mail it to $address. It is *NOT* intended for
286sending test messages or simply verifying that perl works, *NOR* is it
287intended for reporting bugs in third-party perl modules. It is *ONLY*
288a means of reporting verifiable problems with the core perl distribution,
289and any solutions to such problems, to the people who maintain perl.
290
291If you're just looking for help with perl, try posting to the Usenet
292newsgroup comp.lang.perl.misc. If you're looking for help with using
293perl with CGI, try posting to comp.infosystems.www.programming.cgi.
294EOF
295 }
296
297 # Prompt for subject of message, if needed
298
299 if (TrivialSubject($subject)) {
300 $subject = '';
301 }
302
303 unless ($subject) {
304 paraprint <<EOF;
305First of all, please provide a subject for the
306message. It should be a concise description of
307the bug or problem. "perl bug" or "perl problem"
308is not a concise description.
309EOF
310
311 my $err = 0;
312 do {
313 print "Subject: ";
314 $subject = <>;
315 chomp $subject;
316 if ($err++ == 5) {
317 die "Aborting.\n";
318 }
319 } while (TrivialSubject($subject));
320 }
321
322 # Prompt for return address, if needed
323 unless ($from) {
324 # Try and guess return address
325 my $guess;
326
327 $guess = $ENV{'REPLY-TO'} || $ENV{'REPLYTO'} || '';
328 if ($Is_MacOS) {
329 require Mac::InternetConfig;
330 $guess = $Mac::InternetConfig::InternetConfig{
331 Mac::InternetConfig::kICEmail()
332 };
333 }
334
335 unless ($guess) {
336 # move $domain to where we can use it elsewhere
337 if ($domain) {
338 if ($Is_VMS && !$::Config{'d_socket'}) {
339 $guess = "$domain\:\:$me";
340 } else {
341 $guess = "$me\@$domain" if $domain;
342 }
343 }
344 }
345
346 if ($guess) {
347 unless ($ok) {
348 paraprint <<EOF;
349Your e-mail address will be useful if you need to be contacted. If the
350default shown is not your full internet e-mail address, please correct it.
351EOF
352 }
353 } else {
354 paraprint <<EOF;
355So that you may be contacted if necessary, please enter
356your full internet e-mail address here.
357EOF
358 }
359
360 if ($ok && $guess) {
361 # use it
362 $from = $guess;
363 } else {
364 # verify it
365 print "Your address [$guess]: ";
366 $from = <>;
367 chomp $from;
368 $from = $guess if $from eq '';
369 }
370 }
371
372 if ($from eq $cc or $me eq $cc) {
373 # Try not to copy ourselves
374 $cc = "yourself";
375 }
376
377 # Prompt for administrator address, unless an override was given
378 if( !$::opt_C and !$::opt_c ) {
379 paraprint <<EOF;
380A copy of this report can be sent to your local
381perl administrator. If the address is wrong, please
382correct it, or enter 'none' or 'yourself' to not send
383a copy.
384EOF
385 print "Local perl administrator [$cc]: ";
386 my $entry = scalar <>;
387 chomp $entry;
388
389 if ($entry ne "") {
390 $cc = $entry;
391 $cc = '' if $me eq $cc;
392 }
393 }
394
395 $cc = '' if $cc =~ /^(none|yourself|me|myself|ourselves)$/i;
396 $andcc = " and $cc" if $cc;
397
398 # Prompt for editor, if no override is given
399editor:
400 unless ($::opt_e || $::opt_f || $::opt_b) {
401 paraprint <<EOF;
402Now you need to supply the bug report. Try to make
403the report concise but descriptive. Include any
404relevant detail. If you are reporting something
405that does not work as you think it should, please
406try to include example of both the actual
407result, and what you expected.
408
409Some information about your local
410perl configuration will automatically be included
411at the end of the report. If you are using any
412unusual version of perl, please try and confirm
413exactly which versions are relevant.
414
415You will probably want to use an editor to enter
416the report. If "$ed" is the editor you want
417to use, then just press Enter, otherwise type in
418the name of the editor you would like to use.
419
420If you would like to use a prepared file, type
421"file", and you will be asked for the filename.
422EOF
423 print "Editor [$ed]: ";
424 my $entry =scalar <>;
425 chomp $entry;
426
427 $usefile = 0;
428 if ($entry eq "file") {
429 $usefile = 1;
430 } elsif ($entry ne "") {
431 $ed = $entry;
432 }
433 }
434
435 # Prompt for category of bug
436 $category ||= ask_for_alternatives('category');
437
438 # Prompt for severity of bug
439 $severity ||= ask_for_alternatives('severity');
440
441 # Generate scratch file to edit report in
442 $filename = filename();
443
444 # Prompt for file to read report from, if needed
445 if ($usefile and !$file) {
446filename:
447 paraprint <<EOF;
448What is the name of the file that contains your report?
449EOF
450 print "Filename: ";
451 my $entry = scalar <>;
452 chomp $entry;
453
454 if ($entry eq "") {
455 paraprint <<EOF;
456No filename? I'll let you go back and choose an editor again.
457EOF
458 goto editor;
459 }
460
461 unless (-f $entry and -r $entry) {
462 paraprint <<EOF;
463I'm sorry, but I can't read from `$entry'. Maybe you mistyped the name of
464the file? If you don't want to send a file, just enter a blank line and you
465can get back to the editor selection.
466EOF
467 goto filename;
468 }
469 $file = $entry;
470 }
471
472 # Generate report
473 open(REP,">$filename") or die "Unable to create report file `$filename': $!\n";
474 my $reptype = !$ok ? "bug" : $::opt_n ? "build failure" : "success";
475
476 print REP <<EOF;
477This is a $reptype report for perl from $from,
478generated with the help of perlbug $Version running under perl $perl_version.
479
480EOF
481
482 if ($body) {
483 print REP $body;
484 } elsif ($usefile) {
485 open(F, "<$file")
486 or die "Unable to read report file from `$file': $!\n";
487 while (<F>) {
488 print REP $_
489 }
490 close(F) or die "Error closing `$file': $!";
491 } else {
492 print REP <<EOF;
493
494-----------------------------------------------------------------
495[Please enter your report here]
496
497
498
499[Please do not change anything below this line]
500-----------------------------------------------------------------
501EOF
502 }
503 Dump(*REP);
504 close(REP) or die "Error closing report file: $!";
505
506 # read in the report template once so that
507 # we can track whether the user does any editing.
508 # yes, *all* whitespace is ignored.
509 open(REP, "<$filename") or die "Unable to open report file `$filename': $!\n";
510 while (<REP>) {
511 s/\s+//g;
512 $REP{$_}++;
513 }
514 close(REP) or die "Error closing report file `$filename': $!";
515} # sub Query
516
517sub Dump {
518 local(*OUT) = @_;
519
520 print OUT <<EFF;
521---
522Flags:
523 category=$category
524 severity=$severity
525EFF
526 if ($::opt_A) {
527 print OUT <<EFF;
528 ack=no
529EFF
530 }
531 print OUT <<EFF;
532---
533EFF
534 print OUT "This perlbug was built using Perl $config_tag1\n",
535 "It is being executed now by Perl $config_tag2.\n\n"
536 if $config_tag2 ne $config_tag1;
537
538 print OUT <<EOF;
539Site configuration information for perl $perl_version:
540
541EOF
542 if ($::Config{cf_by} and $::Config{cf_time}) {
543 print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
544 }
545 print OUT Config::myconfig;
546
547 if (@patches) {
548 print OUT join "\n ", "Locally applied patches:", @patches;
549 print OUT "\n";
550 };
551
552 print OUT <<EOF;
553
554---
555\@INC for perl $perl_version:
556EOF
557 for my $i (@INC) {
558 print OUT " $i\n";
559 }
560
561 print OUT <<EOF;
562
563---
564Environment for perl $perl_version:
565EOF
566 my @env =
567 qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
568 push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
569 push @env, grep /^(?:PERL|LC_|LANG|CYGWIN)/, keys %ENV;
570 my %env;
571 @env{@env} = @env;
572 for my $env (sort keys %env) {
573 print OUT " $env",
574 exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
575 "\n";
576 }
577 if ($verbose) {
578 print OUT "\nComplete configuration data for perl $perl_version:\n\n";
579 my $value;
580 foreach (sort keys %::Config) {
581 $value = $::Config{$_};
582 $value =~ s/'/\\'/g;
583 print OUT "$_='$value'\n";
584 }
585 }
586} # sub Dump
587
588sub Edit {
589 # Edit the report
590 if ($usefile || $body) {
591 paraprint <<EOF;
592Please make sure that the name of the editor you want to use is correct.
593EOF
594 print "Editor [$ed]: ";
595 my $entry =scalar <>;
596 chomp $entry;
597 $ed = $entry unless $entry eq '';
598 }
599
600tryagain:
601 my $sts;
602 $sts = system("$ed $filename") unless $Is_MacOS;
603 if ($Is_MacOS) {
604 require ExtUtils::MakeMaker;
605 ExtUtils::MM_MacOS::launch_file($filename);
606 paraprint <<EOF;
607Press Enter when done.
608EOF
609 scalar <>;
610 }
611 if ($sts) {
612 paraprint <<EOF;
613The editor you chose (`$ed') could apparently not be run!
614Did you mistype the name of your editor? If so, please
615correct it here, otherwise just press Enter.
616EOF
617 print "Editor [$ed]: ";
618 my $entry =scalar <>;
619 chomp $entry;
620
621 if ($entry ne "") {
622 $ed = $entry;
623 goto tryagain;
624 } else {
625 paraprint <<EOF;
626You may want to save your report to a file, so you can edit and mail it
627yourself.
628EOF
629 }
630 }
631
632 return if ($ok and not $::opt_n) || $body;
633 # Check that we have a report that has some, eh, report in it.
634 my $unseen = 0;
635
636 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
637 # a strange way to check whether any significant editing
638 # have been done: check whether any new non-empty lines
639 # have been added. Yes, the below code ignores *any* space
640 # in *any* line.
641 while (<REP>) {
642 s/\s+//g;
643 $unseen++ if $_ ne '' and not exists $REP{$_};
644 }
645
646 while ($unseen == 0) {
647 paraprint <<EOF;
648I am sorry but it looks like you did not report anything.
649EOF
650 print "Action (Retry Edit/Cancel) ";
651 my ($action) = scalar(<>);
652 if ($action =~ /^[re]/i) { # <R>etry <E>dit
653 goto tryagain;
654 } elsif ($action =~ /^[cq]/i) { # <C>ancel, <Q>uit
655 Cancel();
656 }
657 }
658} # sub Edit
659
660sub Cancel {
661 1 while unlink($filename); # remove all versions under VMS
662 print "\nCancelling.\n";
663 exit(0);
664}
665
666sub NowWhat {
667 # Report is done, prompt for further action
668 if( !$::opt_S ) {
669 while(1) {
670 paraprint <<EOF;
671Now that you have completed your report, would you like to send
672the message to $address$andcc, display the message on
673the screen, re-edit it, display/change the subject,
674or cancel without sending anything?
675You may also save the message as a file to mail at another time.
676EOF
677 retry:
678 print "Action (Send/Display/Edit/Subject/Save to File): ";
679 my $action = scalar <>;
680 chomp $action;
681
682 if ($action =~ /^(f|sa)/i) { # <F>ile/<Sa>ve
683 my $file_save = $outfile || "perlbug.rep";
684 print "\n\nName of file to save message in [$file_save]: ";
685 my $file = scalar <>;
686 chomp $file;
687 $file = $file_save if $file eq "";
688
689 unless (open(FILE, ">$file")) {
690 print "\nError opening $file: $!\n\n";
691 goto retry;
692 }
693 open(REP, "<$filename") or die "Couldn't open file `$filename': $!\n";
694 print FILE "To: $address\nSubject: $subject\n";
695 print FILE "Cc: $cc\n" if $cc;
696 print FILE "Reply-To: $from\n" if $from;
697 print FILE "Message-Id: $messageid\n" if $messageid;
698 print FILE "\n";
699 while (<REP>) { print FILE }
700 close(REP) or die "Error closing report file `$filename': $!";
701 close(FILE) or die "Error closing $file: $!";
702
703 print "\nMessage saved in `$file'.\n";
704 exit;
705 } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
706 # Display the message
707 open(REP, "<$filename") or die "Couldn't open file `$filename': $!\n";
708 while (<REP>) { print $_ }
709 close(REP) or die "Error closing report file `$filename': $!";
710 } elsif ($action =~ /^su/i) { # <Su>bject
711 print "Subject: $subject\n";
712 print "If the above subject is fine, just press Enter.\n";
713 print "If not, type in the new subject.\n";
714 print "Subject: ";
715 my $reply = scalar <STDIN>;
716 chomp $reply;
717 if ($reply ne '') {
718 unless (TrivialSubject($reply)) {
719 $subject = $reply;
720 print "Subject: $subject\n";
721 }
722 }
723 } elsif ($action =~ /^se/i) { # <S>end
724 # Send the message
725 print "Are you certain you want to send this message?\n"
726 . 'Please type "yes" if you are: ';
727 my $reply = scalar <STDIN>;
728 chomp $reply;
729 if ($reply eq "yes") {
730 last;
731 } else {
732 paraprint <<EOF;
733That wasn't a clear "yes", so I won't send your message. If you are sure
734your message should be sent, type in "yes" (without the quotes) at the
735confirmation prompt.
736EOF
737 }
738 } elsif ($action =~ /^[er]/i) { # <E>dit, <R>e-edit
739 # edit the message
740 Edit();
741 } elsif ($action =~ /^[qc]/i) { # <C>ancel, <Q>uit
742 Cancel();
743 } elsif ($action =~ /^s/i) {
744 paraprint <<EOF;
745I'm sorry, but I didn't understand that. Please type "send" or "save".
746EOF
747 }
748 }
749 }
750} # sub NowWhat
751
752sub TrivialSubject {
753 my $subject = shift;
754 if ($subject =~
755 /^(y(es)?|no?|help|perl( (bug|problem))?|bug|problem)$/i ||
756 length($subject) < 4 ||
757 $subject !~ /\s/) {
758 print "\nThat doesn't look like a good subject. Please be more verbose.\n\n";
759 return 1;
760 } else {
761 return 0;
762 }
763}
764
765sub Send {
766 # Message has been accepted for transmission -- Send the message
767 if ($outfile) {
768 open SENDMAIL, ">$outfile" or die "Couldn't open '$outfile': $!\n";
769 goto sendout;
770 }
771
772 # on linux certain mail implementations won't accept the subject
773 # as "~s subject" and thus the Subject header will be corrupted
774 # so don't use Mail::Send to be safe
775 if ($::HaveSend && !$Is_Linux && !$Is_OpenBSD) {
776 $msg = new Mail::Send Subject => $subject, To => $address;
777 $msg->cc($cc) if $cc;
778 $msg->add("Reply-To",$from) if $from;
779
780 $fh = $msg->open;
781 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
782 while (<REP>) { print $fh $_ }
783 close(REP) or die "Error closing $filename: $!";
784 $fh->close;
785
786 print "\nMessage sent.\n";
787 } elsif ($Is_VMS) {
788 if ( ($address =~ /@/ and $address !~ /^\w+%"/) or
789 ($cc =~ /@/ and $cc !~ /^\w+%"/) ) {
790 my $prefix;
791 foreach (qw[ IN MX SMTP UCX PONY WINS ], '') {
792 $prefix = "$_%", last if $ENV{"MAIL\$PROTOCOL_$_"};
793 }
794 $address = qq[${prefix}"$address"] unless $address =~ /^\w+%"/;
795 $cc = qq[${prefix}"$cc"] unless !$cc || $cc =~ /^\w+%"/;
796 }
797 $subject =~ s/"/""/g; $address =~ s/"/""/g; $cc =~ s/"/""/g;
798 my $sts = system(qq[mail/Subject="$subject" $filename. "$address","$cc"]);
799 if ($sts) {
800 die <<EOF;
801Can't spawn off mail
802 (leaving bug report in $filename): $sts
803EOF
804 }
805 } else {
806 my $sendmail = "";
807 for (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail)) {
808 $sendmail = $_, last if -e $_;
809 }
810 if ($^O eq 'os2' and $sendmail eq "") {
811 my $path = $ENV{PATH};
812 $path =~ s:\\:/: ;
813 my @path = split /$Config{'path_sep'}/, $path;
814 for (@path) {
815 $sendmail = "$_/sendmail", last if -e "$_/sendmail";
816 $sendmail = "$_/sendmail.exe", last if -e "$_/sendmail.exe";
817 }
818 }
819
820 paraprint(<<"EOF"), die "\n" if $sendmail eq "";
821I am terribly sorry, but I cannot find sendmail, or a close equivalent, and
822the perl package Mail::Send has not been installed, so I can't send your bug
823report. We apologize for the inconvenience.
824
825So you may attempt to find some way of sending your message, it has
826been left in the file `$filename'.
827EOF
828 open(SENDMAIL, "|$sendmail -t -oi") || die "'|$sendmail -t -oi' failed: $!";
829sendout:
830 print SENDMAIL "To: $address\n";
831 print SENDMAIL "Subject: $subject\n";
832 print SENDMAIL "Cc: $cc\n" if $cc;
833 print SENDMAIL "Reply-To: $from\n" if $from;
834 print SENDMAIL "Message-Id: $messageid\n" if $messageid;
835 print SENDMAIL "\n\n";
836 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
837 while (<REP>) { print SENDMAIL $_ }
838 close(REP) or die "Error closing $filename: $!";
839
840 if (close(SENDMAIL)) {
841 printf "\nMessage %s.\n", $outfile ? "saved" : "sent";
842 } else {
843 warn "\nSendmail returned status '", $? >> 8, "'\n";
844 }
845 }
846 1 while unlink($filename); # remove all versions under VMS
847} # sub Send
848
849sub Help {
850 print <<EOF;
851
852A program to help generate bug reports about perl5, and mail them.
853It is designed to be used interactively. Normally no arguments will
854be needed.
855
856Usage:
857$0 [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
858 [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
859$0 [-v] [-r returnaddress] [-A] [-ok | -okay | -nok | -nokay]
860
861Simplest usage: run "$0", and follow the prompts.
862
863Options:
864
865 -v Include Verbose configuration data in the report
866 -f File containing the body of the report. Use this to
867 quickly send a prepared message.
868 -F File to output the resulting mail message to, instead of mailing.
869 -S Send without asking for confirmation.
870 -a Address to send the report to. Defaults to `$address'.
871 -c Address to send copy of report to. Defaults to `$cc'.
872 -C Don't send copy to administrator.
873 -s Subject to include with the message. You will be prompted
874 if you don't supply one on the command line.
875 -b Body of the report. If not included on the command line, or
876 in a file with -f, you will get a chance to edit the message.
877 -r Your return address. The program will ask you to confirm
878 this if you don't give it here.
879 -e Editor to use.
880 -t Test mode. The target address defaults to `$testaddress'.
881 -d Data mode. This prints out your configuration data, without mailing
882 anything. You can use this with -v to get more complete data.
883 -A Don't send a bug received acknowledgement to the return address.
884 -ok Report successful build on this system to perl porters
885 (use alone or with -v). Only use -ok if *everything* was ok:
886 if there were *any* problems at all, use -nok.
887 -okay As -ok but allow report from old builds.
888 -nok Report unsuccessful build on this system to perl porters
889 (use alone or with -v). You must describe what went wrong
890 in the body of the report which you will be asked to edit.
891 -nokay As -nok but allow report from old builds.
892 -h Print this help message.
893
894EOF
895}
896
897sub filename {
898 if ($::HaveTemp) {
899 # Good. Use a secure temp file
900 my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1);
901 close($fh);
902 return $filename;
903 } else {
904 # Bah. Fall back to doing things less securely.
905 my $dir = File::Spec->tmpdir();
906 $filename = "bugrep0$$";
907 $filename++ while -e File::Spec->catfile($dir, $filename);
908 $filename = File::Spec->catfile($dir, $filename);
909 }
910}
911
912sub paraprint {
913 my @paragraphs = split /\n{2,}/, "@_";
914 print "\n\n";
915 for (@paragraphs) { # implicit local $_
916 s/(\S)\s*\n/$1 /g;
917 write;
918 print "\n";
919 }
920}
921
922format STDOUT =
923^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
924$_
925.
926
927__END__
928
929=head1 NAME
930
931perlbug - how to submit bug reports on Perl
932
933=head1 SYNOPSIS
934
935B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
936S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
937S<[ B<-r> I<returnaddress> ]>
938S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
939S<[ B<-S> ]> S<[ B<-t> ]> S<[ B<-d> ]> S<[ B<-A> ]> S<[ B<-h> ]>
940
941B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]>
942 S<[ B<-A> ]> S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
943
944=head1 DESCRIPTION
945
946A program to help generate bug reports about perl or the modules that
947come with it, and mail them.
948
949If you have found a bug with a non-standard port (one that was not part
950of the I<standard distribution>), a binary distribution, or a
951non-standard module (such as Tk, CGI, etc), then please see the
952documentation that came with that distribution to determine the correct
953place to report bugs.
954
955C<perlbug> is designed to be used interactively. Normally no arguments
956will be needed. Simply run it, and follow the prompts.
957
958If you are unable to run B<perlbug> (most likely because you don't have
959a working setup to send mail that perlbug recognizes), you may have to
960compose your own report, and email it to B<perlbug@perl.org>. You might
961find the B<-d> option useful to get summary information in that case.
962
963In any case, when reporting a bug, please make sure you have run through
964this checklist:
965
966=over 4
967
968=item What version of Perl you are running?
969
970Type C<perl -v> at the command line to find out.
971
972=item Are you running the latest released version of perl?
973
974Look at http://www.perl.com/ to find out. If it is not the latest
975released version, get that one and see whether your bug has been
976fixed. Note that bug reports about old versions of Perl, especially
977those prior to the 5.0 release, are likely to fall upon deaf ears.
978You are on your own if you continue to use perl1 .. perl4.
979
980=item Are you sure what you have is a bug?
981
982A significant number of the bug reports we get turn out to be documented
983features in Perl. Make sure the behavior you are witnessing doesn't fall
984under that category, by glancing through the documentation that comes
985with Perl (we'll admit this is no mean task, given the sheer volume of
986it all, but at least have a look at the sections that I<seem> relevant).
987
988Be aware of the familiar traps that perl programmers of various hues
989fall into. See L<perltrap>.
990
991Check in L<perldiag> to see what any Perl error message(s) mean.
992If message isn't in perldiag, it probably isn't generated by Perl.
993Consult your operating system documentation instead.
994
995If you are on a non-UNIX platform check also L<perlport>, as some
996features may be unimplemented or work differently.
997
998Try to study the problem under the Perl debugger, if necessary.
999See L<perldebug>.
1000
1001=item Do you have a proper test case?
1002
1003The easier it is to reproduce your bug, the more likely it will be
1004fixed, because if no one can duplicate the problem, no one can fix it.
1005A good test case has most of these attributes: fewest possible number
1006of lines; few dependencies on external commands, modules, or
1007libraries; runs on most platforms unimpeded; and is self-documenting.
1008
1009A good test case is almost always a good candidate to be on the perl
1010test suite. If you have the time, consider making your test case so
1011that it will readily fit into the standard test suite.
1012
1013Remember also to include the B<exact> error messages, if any.
1014"Perl complained something" is not an exact error message.
1015
1016If you get a core dump (or equivalent), you may use a debugger
1017(B<dbx>, B<gdb>, etc) to produce a stack trace to include in the bug
1018report. NOTE: unless your Perl has been compiled with debug info
1019(often B<-g>), the stack trace is likely to be somewhat hard to use
1020because it will most probably contain only the function names and not
1021their arguments. If possible, recompile your Perl with debug info and
1022reproduce the dump and the stack trace.
1023
1024=item Can you describe the bug in plain English?
1025
1026The easier it is to understand a reproducible bug, the more likely it
1027will be fixed. Anything you can provide by way of insight into the
1028problem helps a great deal. In other words, try to analyze the
1029problem (to the extent you can) and report your discoveries.
1030
1031=item Can you fix the bug yourself?
1032
1033A bug report which I<includes a patch to fix it> will almost
1034definitely be fixed. Use the C<diff> program to generate your patches
1035(C<diff> is being maintained by the GNU folks as part of the B<diffutils>
1036package, so you should be able to get it from any of the GNU software
1037repositories). If you do submit a patch, the cool-dude counter at
1038perlbug@perl.org will register you as a savior of the world. Your
1039patch may be returned with requests for changes, or requests for more
1040detailed explanations about your fix.
1041
1042Here are some clues for creating quality patches: Use the B<-c> or
1043B<-u> switches to the diff program (to create a so-called context or
1044unified diff). Make sure the patch is not reversed (the first
1045argument to diff is typically the original file, the second argument
1046your changed file). Make sure you test your patch by applying it with
1047the C<patch> program before you send it on its way. Try to follow the
1048same style as the code you are trying to patch. Make sure your patch
1049really does work (C<make test>, if the thing you're patching supports
1050it).
1051
1052=item Can you use C<perlbug> to submit the report?
1053
1054B<perlbug> will, amongst other things, ensure your report includes
1055crucial information about your version of perl. If C<perlbug> is unable
1056to mail your report after you have typed it in, you may have to compose
1057the message yourself, add the output produced by C<perlbug -d> and email
1058it to B<perlbug@perl.org>. If, for some reason, you cannot run
1059C<perlbug> at all on your system, be sure to include the entire output
1060produced by running C<perl -V> (note the uppercase V).
1061
1062Whether you use C<perlbug> or send the email manually, please make
1063your Subject line informative. "a bug" not informative. Neither is
1064"perl crashes" nor "HELP!!!". These don't help.
1065A compact description of what's wrong is fine.
1066
1067=back
1068
1069Having done your bit, please be prepared to wait, to be told the bug
1070is in your code, or even to get no reply at all. The Perl maintainers
1071are busy folks, so if your problem is a small one or if it is difficult
1072to understand or already known, they may not respond with a personal reply.
1073If it is important to you that your bug be fixed, do monitor the
1074C<Changes> file in any development releases since the time you submitted
1075the bug, and encourage the maintainers with kind words (but never any
1076flames!). Feel free to resend your bug report if the next released
1077version of perl comes out and your bug is still present.
1078
1079=head1 OPTIONS
1080
1081=over 8
1082
1083=item B<-a>
1084
1085Address to send the report to. Defaults to B<perlbug@perl.org>.
1086
1087=item B<-A>
1088
1089Don't send a bug received acknowledgement to the reply address.
1090Generally it is only a sensible to use this option if you are a
1091perl maintainer actively watching perl porters for your message to
1092arrive.
1093
1094=item B<-b>
1095
1096Body of the report. If not included on the command line, or
1097in a file with B<-f>, you will get a chance to edit the message.
1098
1099=item B<-C>
1100
1101Don't send copy to administrator.
1102
1103=item B<-c>
1104
1105Address to send copy of report to. Defaults to the address of the
1106local perl administrator (recorded when perl was built).
1107
1108=item B<-d>
1109
1110Data mode (the default if you redirect or pipe output). This prints out
1111your configuration data, without mailing anything. You can use this
1112with B<-v> to get more complete data.
1113
1114=item B<-e>
1115
1116Editor to use.
1117
1118=item B<-f>
1119
1120File containing the body of the report. Use this to quickly send a
1121prepared message.
1122
1123=item B<-F>
1124
1125File to output the results to instead of sending as an email. Useful
1126particularly when running perlbug on a machine with no direct internet
1127connection.
1128
1129=item B<-h>
1130
1131Prints a brief summary of the options.
1132
1133=item B<-ok>
1134
1135Report successful build on this system to perl porters. Forces B<-S>
1136and B<-C>. Forces and supplies values for B<-s> and B<-b>. Only
1137prompts for a return address if it cannot guess it (for use with
1138B<make>). Honors return address specified with B<-r>. You can use this
1139with B<-v> to get more complete data. Only makes a report if this
1140system is less than 60 days old.
1141
1142=item B<-okay>
1143
1144As B<-ok> except it will report on older systems.
1145
1146=item B<-nok>
1147
1148Report unsuccessful build on this system. Forces B<-C>. Forces and
1149supplies a value for B<-s>, then requires you to edit the report
1150and say what went wrong. Alternatively, a prepared report may be
1151supplied using B<-f>. Only prompts for a return address if it
1152cannot guess it (for use with B<make>). Honors return address
1153specified with B<-r>. You can use this with B<-v> to get more
1154complete data. Only makes a report if this system is less than 60
1155days old.
1156
1157=item B<-nokay>
1158
1159As B<-nok> except it will report on older systems.
1160
1161=item B<-r>
1162
1163Your return address. The program will ask you to confirm its default
1164if you don't use this option.
1165
1166=item B<-S>
1167
1168Send without asking for confirmation.
1169
1170=item B<-s>
1171
1172Subject to include with the message. You will be prompted if you don't
1173supply one on the command line.
1174
1175=item B<-t>
1176
1177Test mode. The target address defaults to B<perlbug-test@perl.org>.
1178
1179=item B<-v>
1180
1181Include verbose configuration data in the report.
1182
1183=back
1184
1185=head1 AUTHORS
1186
1187Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently I<doc>tored
1188by Gurusamy Sarathy (E<lt>gsar@activestate.comE<gt>), Tom Christiansen
1189(E<lt>tchrist@perl.comE<gt>), Nathan Torkington (E<lt>gnat@frii.comE<gt>),
1190Charles F. Randall (E<lt>cfr@pobox.comE<gt>), Mike Guy
1191(E<lt>mjtg@cam.a.ukE<gt>), Dominic Dunlop (E<lt>domo@computer.orgE<gt>),
1192Hugo van der Sanden (E<lt>hv@crypt.org<gt>),
1193Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), Chris Nandor
1194(E<lt>pudge@pobox.comE<gt>), Jon Orwant (E<lt>orwant@media.mit.eduE<gt>,
1195and Richard Foley (E<lt>richard@rfi.netE<gt>).
1196
1197=head1 SEE ALSO
1198
1199perl(1), perldebug(1), perldiag(1), perlport(1), perltrap(1),
1200diff(1), patch(1), dbx(1), gdb(1)
1201
1202=head1 BUGS
1203
1204None known (guess what must have been used to report them?)
1205
1206=cut
1207