normalize time for strftime() (without the isdst effects of
[p5sagit/p5-mst-13.2.git] / utils / perlbug.PL
index 68ff290..3404d2b 100644 (file)
@@ -2,6 +2,8 @@
 
 use Config;
 use File::Basename qw(&basename &dirname);
+use Cwd;
+use File::Spec::Functions;
 
 # List explicitly here the variables you want Configure to
 # generate.  Metaconfig only looks for shell variables, so you
@@ -13,6 +15,7 @@ use File::Basename qw(&basename &dirname);
 
 # This forces PL files to create target in same directory as PL file.
 # This is so that make depend always knows where to find PL derivatives.
+$origdir = cwd;
 chdir dirname($0);
 $file = basename($0, '.PL');
 $file .= '.com' if $^O eq 'VMS';
@@ -21,7 +24,8 @@ open OUT, ">$file" or die "Can't create $file: $!";
 
 # extract patchlevel.h information
 
-open PATCH_LEVEL, "<../patchlevel.h" or die "Can't open patchlevel.h: $!";
+open PATCH_LEVEL, "<" . catfile(updir, "patchlevel.h")
+    or die "Can't open patchlevel.h: $!";
 
 my $patchlevel_date = (stat PATCH_LEVEL)[9];
 
@@ -72,6 +76,7 @@ my \@patches = (
 print OUT <<'!NO!SUBS!';
 
 use Config;
+use File::Spec::Functions;
 use Getopt::Std;
 use strict;
 
@@ -84,7 +89,7 @@ BEGIN {
     $::HaveUtil = ($@ eq "");
 };
 
-my $Version = "1.22";
+my $Version = "1.27";
 
 # Changed in 1.06 to skip Mail::Send and Mail::Util if not available.
 # Changed in 1.07 to see more sendmail execs, and added pipe output.
@@ -111,6 +116,11 @@ my $Version = "1.22";
 # Changed in 1.20 Added patchlevel.h reading and version/config checks
 # Changed in 1.21 Added '-nok' for reporting build failure DFD 98-05-05
 # Changed in 1.22 Heavy reformatting & minor bugfixes HVDS 98-05-10
+# Changed in 1.23 Restore -ok(ay): say 'success'; don't prompt
+# Changed in 1.24 Added '-F<file>' to save report HVDS 98-07-01
+# Changed in 1.25 Warn on failure to open save file. HVDS 98-07-12
+# Changed in 1.26 Don't require -t STDIN for -ok. HVDS 98-07-15
+# Changed in 1.27 Added Mac OS and File::Spec support CNANDOR 99-07-27
 
 # TODO: - Allow the user to re-name the file on mail failure, and
 #       make sure failure (transmission-wise) of Mail::Send is
@@ -118,7 +128,7 @@ my $Version = "1.22";
 #       - Test -b option
 
 my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename,
-    $subject, $from, $verbose, $ed,
+    $subject, $from, $verbose, $ed, $outfile, $Is_MacOS,
     $fh, $me, $Is_MSWin32, $Is_VMS, $msg, $body, $andcc, %REP, $ok);
 
 my $config_tag2 = "$] - $Config{cf_time}";
@@ -127,17 +137,17 @@ Init();
 
 if ($::opt_h) { Help(); exit; }
 if ($::opt_d) { Dump(*STDOUT); exit; }
-if (!-t STDIN) {
+if (!-t STDIN && !($ok and not $::opt_n)) {
     paraprint <<EOF;
 Please use perlbug interactively. If you want to
 include a file, you can use the -f switch.
 EOF
     die "\n";
 }
-if (!-t STDOUT) { Dump(*STDOUT); exit; }
+if (!-t STDOUT && !$outfile) { Dump(*STDOUT); exit; }
 
 Query();
-Edit() unless $usefile;
+Edit() unless $usefile || ($ok and not $::opt_n);
 NowWhat();
 Send();
 
@@ -148,8 +158,13 @@ sub Init {
 
     $Is_MSWin32 = $^O eq 'MSWin32';
     $Is_VMS = $^O eq 'VMS';
+    $Is_MacOS = $^O eq 'MacOS';
 
-    getopts("dhva:s:b:f:r:e:SCc:to:n:");
+    @ARGV = split m/\s+/,
+        MacPerl::Ask('Provide command-line args here (-h for help):')
+        if $Is_MacOS && $MacPerl::Version =~ /App/;
+
+    if (!getopts("dhva:s:b:f:F:r:e:SCc:to:n:")) { Help(); exit; };
 
     # This comment is needed to notify metaconfig that we are
     # using the $perladmin, $cf_by, and $cf_time definitions.
@@ -180,6 +195,9 @@ sub Init {
     # File to send as report
     $file = $::opt_f || "";
 
+    # File to output to
+    $outfile = $::opt_F || "";
+
     # Body of report
     $body = $::opt_b || "";
 
@@ -187,6 +205,7 @@ sub Init {
     $ed = $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
        || ($Is_VMS && "edit/tpu")
        || ($Is_MSWin32 && "notepad")
+       || ($Is_MacOS && '')
        || "vi";
 
     # Not OK - provide build failure template by finessing OK report
@@ -246,7 +265,12 @@ EOF
     # My username
     $me = $Is_MSWin32 ? $ENV{'USERNAME'}
            : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
+           : $Is_MacOS ? $ENV{'USER'}
            : eval { getpwuid($<) };    # May be missing
+
+    $from = $::Config{'cf_email'}
+       if !$from && $::Config{'cf_email'} && $::Config{'cf_by'} && $me &&
+               ($me eq $::Config{'cf_by'});
 } # sub Init
 
 sub Query {
@@ -294,6 +318,13 @@ EOF
        my $guess;
 
        $guess = $ENV{'REPLY-TO'} || $ENV{'REPLYTO'} || '';
+        if ($Is_MacOS) {
+            require Mac::InternetConfig;
+            $guess = $Mac::InternetConfig::InternetConfig{
+                Mac::InternetConfig::kICEmail()
+            };
+        }
+
        unless ($guess) {
            my $domain;
            if ($::HaveUtil) {
@@ -435,7 +466,7 @@ EOF
 
     # Generate report
     open(REP,">$filename");
-    my $reptype = $ok ? "build failure" : "bug";
+    my $reptype = !$ok ? "bug" : $::opt_n ? "build failure" : "success";
 
     print REP <<EOF;
 This is a $reptype report for perl from $from,
@@ -482,8 +513,8 @@ sub Dump {
     local(*OUT) = @_;
 
     print REP "\n---\n";
-    print REP "This perlbug was built using Perl $config_tag1\n",
-           "It is being executed now by  Perl $config_tag2.\n\n"
+    print REP "This perlbug was built using Perl $config_tag2\n",
+           "It is being executed now by  Perl $config_tag1.\n\n"
        if $config_tag2 ne $config_tag1;
 
     print OUT <<EOF;
@@ -514,10 +545,13 @@ EOF
 ---
 Environment for perl $]:
 EOF
-    for my $env (sort
-       (qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR),
-       grep /^(?:PERL|LC_)/, keys %ENV)
-    ) {
+    my @env =
+        qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
+    push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
+    push @env, grep /^(?:PERL|LC_|LANG)/, keys %ENV;
+    my %env;
+    @env{@env} = @env;
+    for my $env (sort keys %env) {
        print OUT "    $env",
                exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
                "\n";
@@ -546,7 +580,15 @@ EOF
     }
 
 tryagain:
-    my $sts = system("$ed $filename");
+    my $sts = system("$ed $filename") unless $Is_MacOS;
+    if ($Is_MacOS) {
+        require ExtUtils::MakeMaker;
+        ExtUtils::MM_MacOS::launch_file($filename);
+        paraprint <<EOF;
+Press Enter when done.
+EOF
+        scalar <>;
+    }
     if ($sts) {
        paraprint <<EOF;
 The editor you chose (`$ed') could apparently not be run!
@@ -612,6 +654,7 @@ the message to $address$andcc, display the message on
 the screen, re-edit it, or cancel without sending anything?
 You may also save the message as a file to mail at another time.
 EOF
+      retry:
            print "Action (Send/Display/Edit/Cancel/Save to File): ";
            my $action = scalar <>;
            chop $action;
@@ -622,7 +665,10 @@ EOF
                chop $file;
                $file = "perlbug.rep" if $file eq "";
 
-               open(FILE, ">$file");
+               unless (open(FILE, ">$file")) {
+                   print "\nError opening $file: $!\n\n";
+                   goto retry;
+               }
                open(REP, "<$filename");
                print FILE "To: $address\nSubject: $subject\n";
                print FILE "Cc: $cc\n" if $cc;
@@ -670,6 +716,10 @@ EOF
 
 sub Send {
     # Message has been accepted for transmission -- Send the message
+    if ($outfile) {
+       open SENDMAIL, ">$outfile" or die "Couldn't open '$outfile': $!\n";
+       goto sendout;
+    }
     if ($::HaveSend) {
        $msg = new Mail::Send Subject => $subject, To => $address;
        $msg->cc($cc) if $cc;
@@ -724,6 +774,7 @@ So you may attempt to find some way of sending your message, it has
 been left in the file `$filename'.
 EOF
        open(SENDMAIL, "|$sendmail -t") || die "'|$sendmail -t' failed: $!";
+sendout:
        print SENDMAIL "To: $address\n";
        print SENDMAIL "Subject: $subject\n";
        print SENDMAIL "Cc: $cc\n" if $cc;
@@ -734,7 +785,7 @@ EOF
        close(REP);
 
        if (close(SENDMAIL)) {
-           print "\nMessage sent.\n";
+           printf "\nMessage %s.\n", $outfile ? "saved" : "sent";
        } else {
            warn "\nSendmail returned status '", $? >> 8, "'\n";
        }
@@ -750,7 +801,7 @@ It is designed to be used interactively. Normally no arguments will
 be needed.
 
 Usage:
-$0  [-v] [-a address] [-s subject] [-b body | -f file ]
+$0  [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
     [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
 $0  [-v] [-r returnaddress] [-ok | -okay | -nok | -nokay]
 
@@ -761,6 +812,7 @@ Options:
   -v    Include Verbose configuration data in the report
   -f    File containing the body of the report. Use this to
         quickly send a prepared message.
+  -F    File to output the resulting mail message to, instead of mailing.
   -S    Send without asking for confirmation.
   -a    Address to send the report to. Defaults to `$address'.
   -c    Address to send copy of report to. Defaults to `$cc'.
@@ -773,7 +825,7 @@ Options:
         this if you don't give it here.
   -e    Editor to use.
   -t    Test mode. The target address defaults to `$testaddress'.
-  -d   Data mode (the default if you redirect or pipe output.)
+  -d    Data mode (the default if you redirect or pipe output.)
         This prints out your configuration data, without mailing
         anything. You can use this with -v to get more complete data.
   -ok   Report successful build on this system to perl porters
@@ -792,11 +844,12 @@ EOF
 sub filename {
     my $dir = $Is_VMS ? 'sys$scratch:'
        : ($Is_MSWin32 && $ENV{'TEMP'}) ? $ENV{'TEMP'}
-       : '/tmp/';
+        : $Is_MacOS ? $ENV{'TMPDIR'}
+       : '/tmp';
     $filename = "bugrep0$$";
-    $dir .= "\\" if $Is_MSWin32 and $dir !~ m|[\\/]$|;
-    $filename++ while -e "$dir$filename";
-    $filename = "$dir$filename";
+#    $dir .= "\\" if $Is_MSWin32 and $dir !~ m|[\\/]$|;
+    $filename++ while -e catfile($dir, $filename);
+    $filename = catfile($dir, $filename);
 }
 
 sub paraprint {
@@ -823,7 +876,8 @@ perlbug - how to submit bug reports on Perl
 =head1 SYNOPSIS
 
 B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
-S<[ B<-b> I<body> | B<-f> I<file> ]> S<[ B<-r> I<returnaddress> ]>
+S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
+S<[ B<-r> I<returnaddress> ]>
 S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
 S<[ B<-S> ]> S<[ B<-t> ]>  S<[ B<-d> ]>  S<[ B<-h> ]>
 
@@ -854,7 +908,7 @@ this checklist:
 
 =over 4
 
-=item What version of perl you are running?
+=item What version of Perl you are running?
 
 Type C<perl -v> at the command line to find out.
 
@@ -862,22 +916,29 @@ Type C<perl -v> at the command line to find out.
 
 Look at http://www.perl.com/ to find out.  If it is not the latest
 released version, get that one and see whether your bug has been
-fixed.  Note that bug reports about old versions of perl, especially
+fixed.  Note that bug reports about old versions of Perl, especially
 those prior to the 5.0 release, are likely to fall upon deaf ears.
 You are on your own if you continue to use perl1 .. perl4.
 
 =item Are you sure what you have is a bug?
 
 A significant number of the bug reports we get turn out to be documented
-features in perl.  Make sure the behavior you are witnessing doesn't fall
+features in Perl.  Make sure the behavior you are witnessing doesn't fall
 under that category, by glancing through the documentation that comes
-with perl (we'll admit this is no mean task, given the sheer volume of
+with Perl (we'll admit this is no mean task, given the sheer volume of
 it all, but at least have a look at the sections that I<seem> relevant).
 
 Be aware of the familiar traps that perl programmers of various hues
 fall into.  See L<perltrap>.
 
-Try to study the problem under the perl debugger, if necessary.
+Check in L<perldiag> to see what any Perl error message(s) mean.
+If message isn't in perldiag, it probably isn't generated by Perl.
+Consult your operating system documentation instead.
+
+If you are on a non-UNIX platform check also L<perlport>, as some
+features may be unimplemented or work differently.
+
+Try to study the problem under the Perl debugger, if necessary.
 See L<perldebug>.
 
 =item Do you have a proper test case?
@@ -892,12 +953,23 @@ A good test case is almost always a good candidate to be on the perl
 test suite.  If you have the time, consider making your test case so
 that it will readily fit into the standard test suite.
 
+Remember also to include the B<exact> error messages, if any.
+"Perl complained something" is not an exact error message.
+
+If you get a core dump (or equivalent), you may use a debugger
+(B<dbx>, B<gdb>, etc) to produce a stack trace to include in the bug
+report.  NOTE: unless your Perl has been compiled with debug info
+(often B<-g>), the stack trace is likely to be somewhat hard to use
+because it will most probably contain only the function names and not
+their arguments.  If possible, recompile your Perl with debug info and
+reproduce the dump and the stack trace.
+
 =item Can you describe the bug in plain English?
 
 The easier it is to understand a reproducible bug, the more likely it
 will be fixed.  Anything you can provide by way of insight into the
-problem helps a great deal.  In other words, try to analyse the
-problem to the extent you feel qualified and report your discoveries.
+problem helps a great deal.  In other words, try to analyze the
+problem (to the extent you can) and report your discoveries.
 
 =item Can you fix the bug yourself?
 
@@ -930,10 +1002,15 @@ it to B<perlbug@perl.com>.  If, for some reason, you cannot run
 C<perlbug> at all on your system, be sure to include the entire output
 produced by running C<perl -V> (note the uppercase V).
 
+Whether you use C<perlbug> or send the email manually, please make
+your Subject line informative.  "a bug" not informative.  Neither is
+"perl crashes" nor "HELP!!!".  These don't help.
+A compact description of what's wrong is fine.
+
 =back
 
 Having done your bit, please be prepared to wait, to be told the bug
-is in your code, or even to get no reply at all.  The perl maintainers
+is in your code, or even to get no reply at all.  The Perl maintainers
 are busy folks, so if your problem is a small one or if it is difficult
 to understand or already known, they may not respond with a personal reply.
 If it is important to you that your bug be fixed, do monitor the
@@ -979,6 +1056,12 @@ Editor to use.
 File containing the body of the report.  Use this to quickly send a
 prepared message.
 
+=item B<-F>
+
+File to output the results to instead of sending as an email. Useful
+particularly when running perlbug on a machine with no direct internet
+connection.
+
 =item B<-h>
 
 Prints a brief summary of the options.
@@ -1041,12 +1124,15 @@ Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently I<doc>tored
 by Gurusamy Sarathy (E<lt>gsar@umich.eduE<gt>), Tom Christiansen
 (E<lt>tchrist@perl.comE<gt>), Nathan Torkington (E<lt>gnat@frii.comE<gt>),
 Charles F. Randall (E<lt>cfr@pobox.comE<gt>), Mike Guy
-(E<lt>mjtg@cam.a.ukE<gt>), Dominic Dunlop (E<lt>domo@computer.orgE<gt>)
-and Hugo van der Sanden (E<lt>hv@crypt0.demon.co.ukE<gt>).
+(E<lt>mjtg@cam.a.ukE<gt>), Dominic Dunlop (E<lt>domo@computer.orgE<gt>),
+Hugo van der Sanden (E<lt>hv@crypt0.demon.co.ukE<gt>),
+Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), hris Nandor
+(E<lt>pudge@pobox.comE<gt>), and Jon Orwant (E<lt>orwant@media.mit.eduE<gt>).
 
 =head1 SEE ALSO
 
-perl(1), perldebug(1), perltrap(1), diff(1), patch(1)
+perl(1), perldebug(1), perldiag(1), perlport(1), perltrap(1),
+diff(1), patch(1), dbx(1), gdb(1)
 
 =head1 BUGS
 
@@ -1059,4 +1145,4 @@ None known (guess what must have been used to report them?)
 close OUT or die "Can't close $file: $!";
 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
-
+chdir $origdir;