Mercurial > hg > octave-nkf
changeset 19843:408361a8c72f
Don't register gnuplot toolkit if gnuplot is not available (bug #35391)
* __init_gnuplot__.cc (F__have_gnuplot__, have_gnuplot_binary): New functions
to test for existence of gnuplot external program. (PKG_ADD): Don't register
gnuplot toolkit unless gnuplot binary is available. (F__init_gnuplot): Error
if gnuplot binary is not available.
* graphics.cc (gtk_manager::do_get_toolkit): Provide better error message if
no graphics toolkits are available.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Sat, 31 Jan 2015 02:42:15 -0500 |
parents | ebd27d8c63fd |
children | 0165d9607624 |
files | libinterp/corefcn/graphics.cc libinterp/dldfcn/__init_gnuplot__.cc |
diffstat | 2 files changed, 65 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc +++ b/libinterp/corefcn/graphics.cc @@ -10651,32 +10651,37 @@ { graphics_toolkit retval; - const_loaded_toolkits_iterator pl = loaded_toolkits.find (dtk); - - if (pl == loaded_toolkits.end ()) - { - const_available_toolkits_iterator pa = available_toolkits.find (dtk); - - if (pa != available_toolkits.end ()) - { - octave_value_list args; - args(0) = dtk; - feval ("graphics_toolkit", args); - - if (! error_state) - pl = loaded_toolkits.find (dtk); - - if (error_state || pl == loaded_toolkits.end ()) - error ("failed to load %s graphics toolkit", dtk.c_str ()); + if (! dtk.empty ()) + { + const_loaded_toolkits_iterator pl = loaded_toolkits.find (dtk); + + if (pl == loaded_toolkits.end ()) + { + const_available_toolkits_iterator pa = available_toolkits.find (dtk); + + if (pa != available_toolkits.end ()) + { + octave_value_list args; + args(0) = dtk; + feval ("graphics_toolkit", args); + + if (! error_state) + pl = loaded_toolkits.find (dtk); + + if (error_state || pl == loaded_toolkits.end ()) + error ("failed to load %s graphics toolkit", dtk.c_str ()); + else + retval = pl->second; + } else - retval = pl->second; + error ("default graphics toolkit '%s' is not available!", + dtk.c_str ()); } else - error ("default graphics toolkit '%s' is not available!", - dtk.c_str ()); - } - else - retval = pl->second; + retval = pl->second; + } + else + error ("no graphics toolkits are available!"); return retval; }
--- a/libinterp/dldfcn/__init_gnuplot__.cc +++ b/libinterp/dldfcn/__init_gnuplot__.cc @@ -36,11 +36,14 @@ #include "builtins.h" #include "defun-dld.h" #include "error.h" +#include "file-stat.h" #include "graphics.h" +#include "oct-env.h" #include "parse.h" +#include "utils.h" #include "variables.h" -// PKG_ADD: register_graphics_toolkit ("gnuplot"); +// PKG_ADD: if (__have_gnuplot__ ()) register_graphics_toolkit ("gnuplot"); endif static bool toolkit_loaded = false; @@ -166,13 +169,31 @@ } }; -// Initialize the fltk graphics toolkit. +static bool +have_gnuplot_binary (void) +{ + octave_value_list tmp = feval ("gnuplot_binary", octave_value_list ()); + std::string gnuplot_binary = tmp(0).string_value (); + + std::string path = octave_env::getenv ("PATH"); + + string_vector args (gnuplot_binary); + std::string gnuplot_path = search_path_for_file (path, args); + + file_stat fs (gnuplot_path); + + return fs.exists (); +} + +// Initialize the gnuplot graphics toolkit. DEFUN_DLD (__init_gnuplot__, , , "") { octave_value retval; - if (! toolkit_loaded) + if (! have_gnuplot_binary ()) + error ("__init_gnuplot__: the gnuplot program is not available, see 'gnuplot_binary'"); + else if (! toolkit_loaded) { mlock (); @@ -185,3 +206,16 @@ return retval; } +DEFUN_DLD (__have_gnuplot__, , , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {@var{gnuplot_available} =} __have_gnuplot__ ()\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ + octave_value retval; + + retval = have_gnuplot_binary (); + + return retval; +} +