Mercurial > octave
diff libinterp/dldfcn/__osmesa_print__.cc @ 19884:e814e202cd84
Account for whitespace and other anomalies in print function pipe/file string.
* graphics.cc (Fdrawnow): Use two positions from standard string finds to
address all whitespace and improper syntax in "file" variable, the first
"|" character and the first non "| " character.
* __osmesa_print__.cc (F__osmesa_print__): Ditto.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Sat, 28 Feb 2015 03:44:00 -0600 |
parents | 6b7aee95c54c |
children | d9f6260cf20a |
line wrap: on
line diff
--- a/libinterp/dldfcn/__osmesa_print__.cc Mon Mar 02 14:51:23 2015 +0100 +++ b/libinterp/dldfcn/__osmesa_print__.cc Sat Feb 28 03:44:00 2015 -0600 @@ -105,7 +105,7 @@ { if (! (args(1).is_string () && args(2).is_string ())) { - error ("__osmesa_print__: FILE and TERM has to be strings"); + error ("__osmesa_print__: FILE and TERM must be strings"); return retval; } @@ -119,7 +119,7 @@ graphics_object fobj = gh_manager::get_object (h); if (! (fobj && fobj.isa ("figure"))) { - error ("__osmesa_print__: H has to be a valid figure handle"); + error ("__osmesa_print__: H must be a valid figure handle"); return retval; } @@ -182,16 +182,23 @@ if (! error_state) { - if (! file.empty () && file[0] == '|') + size_t pos_p = file.find_first_of ("|"); + size_t pos_c = file.find_first_not_of ("| "); + + if (pos_p == std::string::npos && pos_c == std::string::npos) + error ("__osmesa_print__: empty output ''"); + else if (pos_c == std::string::npos) + error ("__osmesa_print__: empty pipe '|'"); + else if (pos_p != std::string::npos && pos_p < pos_c) { // create process and pipe gl2ps output to it - std::string cmd = file.substr (1); + std::string cmd = file.substr (pos_c); gl2ps_print (fobj, cmd, term); } else { // write gl2ps output directly to file - FILE *filep = gnulib::fopen (file.c_str (), "w"); + FILE *filep = gnulib::fopen (file.substr (pos_c).c_str (), "w"); if (filep) {