adjust searchdict.t for EBCDIC (still needs documenting)
[p5sagit/p5-mst-13.2.git] / utils / perlbug.PL
index 0a53240..589e7e6 100644 (file)
@@ -86,7 +86,7 @@ BEGIN {
     $::HaveUtil = ($@ eq "");
 };
 
-my $Version = "1.23";
+my $Version = "1.26";
 
 # 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.
@@ -114,6 +114,9 @@ my $Version = "1.23";
 # 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
 
 # TODO: - Allow the user to re-name the file on mail failure, and
 #       make sure failure (transmission-wise) of Mail::Send is
@@ -121,7 +124,7 @@ my $Version = "1.23";
 #       - Test -b option
 
 my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename,
-    $subject, $from, $verbose, $ed,
+    $subject, $from, $verbose, $ed, $outfile,
     $fh, $me, $Is_MSWin32, $Is_VMS, $msg, $body, $andcc, %REP, $ok);
 
 my $config_tag2 = "$] - $Config{cf_time}";
@@ -130,14 +133,14 @@ 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 || ($ok and not $::opt_n);
@@ -152,7 +155,7 @@ sub Init {
     $Is_MSWin32 = $^O eq 'MSWin32';
     $Is_VMS = $^O eq 'VMS';
 
-    getopts("dhva:s:b:f:r:e:SCc:to:n:");
+    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.
@@ -183,6 +186,9 @@ sub Init {
     # File to send as report
     $file = $::opt_f || "";
 
+    # File to output to
+    $outfile = $::opt_F || "";
+
     # Body of report
     $body = $::opt_b || "";
 
@@ -250,6 +256,10 @@ EOF
     $me = $Is_MSWin32 ? $ENV{'USERNAME'}
            : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
            : 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 {
@@ -615,6 +625,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;
@@ -625,7 +636,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;
@@ -673,6 +687,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;
@@ -727,6 +745,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;
@@ -737,7 +756,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";
        }
@@ -753,7 +772,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]
 
@@ -764,6 +783,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'.
@@ -826,7 +846,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> ]>
 
@@ -982,6 +1003,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.