aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Moisseev <moiseev@mezonplus.ru>2018-03-17 19:01:06 +0300
committerAlexander Moisseev <moiseev@mezonplus.ru>2018-03-17 19:01:06 +0300
commit2f60c72b00c026b4b34160bc599a121a3c2662a0 (patch)
tree9bfc1d4474469e150963c7bba2d0511d5a24d5de
parent233c5ae2ad31a4ab9755fd52492cc796c329bfd7 (diff)
downloadrspamd-2f60c72b00c026b4b34160bc599a121a3c2662a0.tar.gz
rspamd-2f60c72b00c026b4b34160bc599a121a3c2662a0.zip
[Minor] Import subroutines from IO::Interactive Perl module
-rwxr-xr-xutils/rspamd_stats.pl42
1 files changed, 42 insertions, 0 deletions
diff --git a/utils/rspamd_stats.pl b/utils/rspamd_stats.pl
index 50191959c..102654dba 100755
--- a/utils/rspamd_stats.pl
+++ b/utils/rspamd_stats.pl
@@ -723,6 +723,48 @@ sub syslog2iso {
$month_map{$month} + 1, @t;
}
+### Imported from IO::Interactive 1.022 Perl module
+sub is_interactive {
+ my ($out_handle) = (@_, select); # Default to default output handle
+
+ # Not interactive if output is not to terminal...
+ return 0 if not -t $out_handle;
+
+ # If *ARGV is opened, we're interactive if...
+ if ( tied(*ARGV) or defined(fileno(ARGV)) ) { # this is what 'Scalar::Util::openhandle *ARGV' boils down to
+
+ # ...it's currently opened to the magic '-' file
+ return -t *STDIN if defined $ARGV && $ARGV eq '-';
+
+ # ...it's at end-of-file and the next file is the magic '-' file
+ return @ARGV>0 && $ARGV[0] eq '-' && -t *STDIN if eof *ARGV;
+
+ # ...it's directly attached to the terminal
+ return -t *ARGV;
+ }
+
+ # If *ARGV isn't opened, it will be interactive if *STDIN is attached
+ # to a terminal.
+ else {
+ return -t *STDIN;
+ }
+}
+
+### Imported from IO::Interactive 1.022 Perl module
+local (*DEV_NULL, *DEV_NULL2);
+my $dev_null;
+BEGIN {
+ pipe *DEV_NULL, *DEV_NULL2
+ or die "Internal error: can't create null filehandle";
+ $dev_null = \*DEV_NULL;
+}
+
+### Imported from IO::Interactive 1.022 Perl module
+sub interactive {
+ my ($out_handle) = (@_, \*STDOUT); # Default to STDOUT
+ return &is_interactive ? $out_handle : $dev_null;
+}
+
__END__
=head1 NAME