From 5e44f777fb934743441767bb13ce0ff329e1b036 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Thu, 14 Jan 2010 14:45:24 -0800 Subject: [PATCH] Allow to specify a limit on the number of curves. --- feedGnuplot.pl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/feedGnuplot.pl b/feedGnuplot.pl index 4a1aea7..da9979f 100755 --- a/feedGnuplot.pl +++ b/feedGnuplot.pl @@ -85,6 +85,11 @@ As an example, if line 3 of the input is "0 9 1 20" --hardcopy xxx If not streaming, output to a file specified here. Format inferred from filename + --maxcurves xxx The maximum allowed number of curves. This is 10 by default, + but can be reset with this option. This exists purely to + prevent perl from allocating all of the system's memory when + reading bogus data + --dump Instead of printing to gnuplot, print to STDOUT. For debugging. OEF @@ -99,7 +104,9 @@ my %options = ( "stream" => 0, "ymin" => "", "ymax" => "", "y2min" => "", - "y2max" => ""); + "y2max" => "", + "maxcurves" => 10); + GetOptions(\%options, "stream!", "domain!", @@ -120,6 +127,7 @@ GetOptions(\%options, "y2max=f", "y2=i@", "hardcopy=s", + "maxcurves=i", "help", "dump") or die($usage); @@ -413,6 +421,13 @@ sub newCurve() { my ($title, $opts, $newpoint, $idx) = @_; + if(scalar @curves >= $options{maxcurves}) + { + say STDERR "Tried to exceed the --maxcurves setting."; + say STDERR "Invoke with a higher --maxcurves limit if you really want to do this."; + return; + } + # if this curve index doesn't exist, create curve up-to this index if(defined $idx) {