From 5740e55a6f2d8b212fa77dcfb1cd59926a5d26a5 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Sun, 19 Mar 2017 19:50:34 -0700 Subject: [PATCH 1/4] Data can now come from STDIN or files on the cmdline This emulates the while(<>) syntax in perl, and makes self-plotting data files work again. These have been broken since that syntax was taken away in 4cfcf0fc35f5835a2ebd7a5e7dd9458da263995f --- bin/feedgnuplot | 70 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/bin/feedgnuplot b/bin/feedgnuplot index 6d4c5f5..e91777a 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -41,17 +41,10 @@ my $last_replot_time = [gettimeofday]; # whether the previous replot was timer based my $last_replot_is_from_timer = 1; - - -my $prev_timed_replot_time = [gettimeofday]; my $this_replot_is_from_timer; -my $stdin = IO::Handle->new(); -die "Couldn't open STDIN" unless $stdin->fdopen(fileno(STDIN),"r"); -my $selector = IO::Select->new( $stdin ); -mainThread(); @@ -122,7 +115,6 @@ sub interpretCommandline 'help', 'dump', 'exit', 'version', 'geometry=s') or exit 1; - # handle various cmdline-option errors if ( $options{help} ) { @@ -479,16 +471,66 @@ sub makeDomainNumeric } +my $prev_timed_replot_time = [gettimeofday]; +my $pipe_in; +my $selector; +my $line_number = 0; +my $is_stdin = !@ARGV; # read stdin only if no data files given on the cmdline +sub openNextFile +{ + my $fd; + if($is_stdin) + { + $fd = IO::Handle->new(); + $fd->fdopen(fileno(STDIN), "r") or die "Couldn't open STDIN"; + } + else + { + my $filename = shift @ARGV; + $fd = IO::File->new($filename, "r") or die "Couldn't open file '$filename'"; + } + + my $selector = IO::Select->new( $fd ); + return ($fd, $selector); +} sub getNextLine { + sub getline_internal + { + while(1) + { + my $line = $pipe_in->getline(); + if( !$is_stdin && !defined $line && $pipe_in->eof() && @ARGV) + { + # I got to the end of one file, so open the next one (which I'm + # sure exists) + ($pipe_in, $selector) = openNextFile(); + next; + } + return $line; + } + } + + + + + + if( !defined $pipe_in ) + { + ($pipe_in, $selector) = openNextFile(); + } + while(1) { $this_replot_is_from_timer = undef; # if we're not streaming, or we're doing triggered-only replotting, simply # do a blocking read - return $stdin->getline() - if (! $options{stream} || $options{stream} < 0); + if (! $options{stream} || $options{stream} < 0) + { + $line_number++; + return getline_internal(); + } my $now = [gettimeofday]; @@ -503,7 +545,8 @@ sub getNextLine if ($selector->can_read($time_remaining)) { - return $stdin->getline(); + $line_number++; + return getline_internal(); } } } @@ -773,7 +816,7 @@ sub mainThread } else { - $domain[0] = $.; + $domain[0] = $line_number; $domain0_numeric = makeDomainNumeric( $domain[0] ); } @@ -1082,6 +1125,9 @@ sub pushPoint } +mainThread(); + + =head1 NAME feedgnuplot - General purpose pipe-oriented plotting tool From 7c1f02ec7f7bc65aaa6834871e9a95d0f26a1004 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Sun, 19 Mar 2017 19:50:45 -0700 Subject: [PATCH 2/4] reworded manpage of --exit --- bin/feedgnuplot | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/bin/feedgnuplot b/bin/feedgnuplot index e91777a..5ea766c 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -1847,16 +1847,15 @@ is possible to send the output produced this way to gnuplot directly. C<--exit> -This controls the details of what happens when the input data is exhausted, or -when some part of the C pipeline is killed. This option does -different things depending on whether C<--stream> is active, so read this -closely. +This controls what happens when the input data is exhausted, or when some part +of the C pipeline is killed. This option does different things +depending on whether C<--stream> is active, so read this closely. With interactive gnuplot terminals (qt, x11, wxt), the plot windows live in a separate process from the main C process. It is thus possible for the main C process to exit, while leaving the plot windows up (a caveat is -that such decapitated windows aren't interactive). To be clear, there are 3 -possible states: +that such decapitated windows aren't interactive). There are 3 possible states +of the polotting pipeline: =over @@ -1871,35 +1870,35 @@ prompt available =back -The C<--exit> option controls the details of this behavior. The possibilities -are: +The possibilities are: =over -=item No C<--stream>, input pipe is exhausted (all data read in) +=item No C<--stream>, all data read in =over -=item default; no C<--exit> +=item no C<--exit> (default) Alive. Need to Ctrl-C to get back into the shell =item C<--exit> Half-alive. Non-interactive prompt up, and the shell accepts new commands. -Without C<--stream> the goal is to show a plot, so a Dead state is not useful -here. +Without C<--stream> the goal is to show a plot, so a Dead state would not be +useful. =back -=item C<--stream>, input pipe is exhausted (all data read in) or the -C process terminated +=item C<--stream>, all data read in or the C process terminated =over -=item default; no C<--exit> +=item no C<--exit> (default) -Alive. Need to Ctrl-C to get back into the shell +Alive. Need to Ctrl-C to get back into the shell. This means that when making +live plots, the first Ctrl-C kills the data feeding process, but leaves the +final plot up for inspection. A second Ctrl-C kills feedgnuplot as well. =item C<--exit> From 2ee401fcb4acc2115c336ee111b5bc691fd0b43d Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Fri, 31 Mar 2017 15:39:48 -0700 Subject: [PATCH 3/4] changelog update --- Changes | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Changes b/Changes index 68f8a1b..fa39fc2 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,10 @@ +feedgnuplot (1.42) unstable; urgency=medium + + * Data can now come from STDIN or files on the cmdline. + This fixes a regression. Self-plotting data files work again + + -- Dima Kogan Fri, 31 Mar 2017 15:38:47 -0700 + feedgnuplot (1.41) * Histograms: --xlen can coexist with --xmin/--xmax From ed9512924d7231f198696fca9d458c70866deb38 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Fri, 31 Mar 2017 15:40:39 -0700 Subject: [PATCH 4/4] version bump --- bin/feedgnuplot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/feedgnuplot b/bin/feedgnuplot index 5ea766c..8142905 100755 --- a/bin/feedgnuplot +++ b/bin/feedgnuplot @@ -15,7 +15,7 @@ use Text::ParseWords; # for shellwords use Pod::Usage; use Time::Piece; -my $VERSION = 1.41; +my $VERSION = 1.42; my %options; interpretCommandline();