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