comparison libinterp/corefcn/sysdep.cc @ 20617:ba2b07c13913

use new string_value method to handle value extraction errors * __dispatch__.cc, balance.cc, colloc.cc, conv2.cc, data.cc, debug.cc, graphics.cc, input.cc, matrix_type.cc, oct-hist.cc, schur.cc, spparms.cc, symtab.cc, sysdep.cc, toplev.cc, utils.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Fri, 09 Oct 2015 10:06:39 -0400
parents f90c8372b7ba
children
comparison
equal deleted inserted replaced
20616:fd0efcdb3718 20617:ba2b07c13913
193 { 193 {
194 octave_value retval; 194 octave_value retval;
195 195
196 if (args.length () == 1) 196 if (args.length () == 1)
197 { 197 {
198 std::string file = args(0).string_value (); 198 std::string file = args(0).string_value ("__open_with_system_app__: argument must be a file name");
199 199
200 if (! error_state)
201 {
202 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) 200 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
203 HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0, 201 HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0,
204 SW_SHOWNORMAL); 202 SW_SHOWNORMAL);
205 203
206 // ShellExecute returns a value greater than 32 if successful. 204 // ShellExecute returns a value greater than 32 if successful.
207 retval = (reinterpret_cast<ptrdiff_t> (status) > 32); 205 retval = (reinterpret_cast<ptrdiff_t> (status) > 32);
208 #else 206 #else
209 octave_value_list tmp 207 octave_value_list tmp
210 = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null", 208 = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null",
211 false, "async"), 209 false, "async"),
212 1); 210 1);
213 211
214 retval = (tmp(0).double_value () == 0); 212 retval = (tmp(0).double_value () == 0);
215 #endif 213 #endif
216 }
217 else
218 error ("__open_with_system_app__: argument must be a file name");
219 } 214 }
220 else 215 else
221 print_usage (); 216 print_usage ();
222 217
223 return retval; 218 return retval;
648 643
649 int nargin = args.length (); 644 int nargin = args.length ();
650 645
651 if (nargin == 2 || nargin == 1) 646 if (nargin == 2 || nargin == 1)
652 { 647 {
653 if (args(0).is_string ()) 648 std::string var = args(0).string_value ("setenv: VAR must be a string");
654 { 649
655 std::string var = args(0).string_value (); 650 std::string val = (nargin == 2
656 651 ? args(1).string_value ("setenv: VALUE must be a string")
657 std::string val = (nargin == 2 652 : std::string ());
658 ? args(1).string_value () : std::string ()); 653
659 654 octave_env::putenv (var, val);
660 if (! error_state)
661 octave_env::putenv (var, val);
662 else
663 error ("setenv: VALUE must be a string");
664 }
665 else
666 error ("setenv: VAR must be a string");
667 } 655 }
668 else 656 else
669 print_usage (); 657 print_usage ();
670 658
671 return retval; 659 return retval;