3 use constant
{ OUTPUT_TERM
=>1, OUTPUT_IMAGE
=>2, OUTPUT_DEFAULT
=>3, };
6 use Fcntl qw
/F_GETFL F_SETFL F_GETFD F_SETFD FD_CLOEXEC/;
7 no if ($] >= 5.018), 'warnings' => 'experimental::smartmatch';
10 $OptOutput = OUTPUT_TERM
;
11 @gnuplot_commands = ();
14 'i' => sub { $OptOutput = OUTPUT_IMAGE
; },
15 'd' => sub { $OptOutput = OUTPUT_DEFAULT
; },
16 'e=s@' => \
@gnuplot_commands,
19 do '/usr/lib/tool/perl5/tabdata/common.pl' or die "$@";
21 pipe $conf_script_rfh, $conf_script_wfh or die "$0: pipe: $!\n";
22 pipe $plot_script_rfh, $plot_script_wfh or die "$0: pipe: $!\n";
23 fcntl($conf_script_rfh, F_SETFD
, fcntl($conf_script_rfh, F_GETFD
, 0) & ~FD_CLOEXEC
);
24 fcntl($plot_script_rfh, F_SETFD
, fcntl($plot_script_rfh, F_GETFD
, 0) & ~FD_CLOEXEC
);
26 process_header
(sys_read_line
());
28 select $conf_script_wfh;
31 set xlabel "$Header[0]"
34 set key on bmargin left horizontal
35 set xtics out nomirror
36 set x2tics out nomirror
37 set ytics out nomirror
38 set y2tics out nomirror
42 if($OptOutput eq OUTPUT_TERM
)
44 my ($term_cols, $term_rows) = Term
::Size
::chars
*STDOUT
{IO
};
45 if(not $term_cols) { ($term_cols, $term_rows) = Term
::Size
::chars
*STDERR
{IO
}; }
49 set terminal dumb size $term_cols,$term_rows ansi256
53 elsif($OptOutput eq OUTPUT_IMAGE
)
58 set output "/dev/stdout"
63 close $conf_script_wfh;
64 select $plot_script_wfh;
68 for my $colnum (2..$#Header+1)
70 my $col = $Header[$colnum-1];
71 print "\"/dev/stdin\" using 1:$colnum with linespoints title \"$col\" axes x1y1, ";
75 close $plot_script_wfh;
78 exec 'gnuplot', '--persist', map {('-e', $_)} 'load "/dev/fd/'.fileno($conf_script_rfh).'"', @gnuplot_commands, 'load "/dev/fd/'.fileno($plot_script_rfh).'"';
79 ($errno, $errstr) = (int $!, $!);
80 warn "gnuplot: $errstr\n";