GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
interpreter.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstdio>
31 #include <clocale>
32 
33 #include <iostream>
34 #include <set>
35 #include <string>
36 #include <thread>
37 
38 #include "cmd-edit.h"
39 #include "cmd-hist.h"
40 #include "file-ops.h"
41 #include "file-stat.h"
42 #include "file-ops.h"
43 #include "fpucw-wrappers.h"
44 #include "lo-blas-proto.h"
45 #include "lo-error.h"
46 #include "lo-sysdep.h"
47 #include "oct-env.h"
48 #include "quit.h"
49 #include "str-vec.h"
50 #include "signal-wrappers.h"
51 #include "unistd-wrappers.h"
52 
53 #include "builtin-defun-decls.h"
54 #include "defaults.h"
55 #include "Cell.h"
56 #include "defun.h"
57 #include "display.h"
58 #include "error.h"
59 #include "event-manager.h"
60 #include "graphics.h"
61 #include "help.h"
62 #include "input.h"
63 #include "interpreter-private.h"
64 #include "interpreter.h"
65 #include "load-path.h"
66 #include "load-save.h"
67 #include "octave.h"
68 #include "oct-hist.h"
69 #include "oct-map.h"
70 #include "oct-mutex.h"
71 #include "ovl.h"
72 #include "ov.h"
73 #include "ov-classdef.h"
74 #include "parse.h"
75 #include "pt-classdef.h"
76 #include "pt-eval.h"
77 #include "pt-jump.h"
78 #include "pt-stmt.h"
79 #include "settings.h"
80 #include "sighandlers.h"
81 #include "sysdep.h"
82 #include "unwind-prot.h"
83 #include "utils.h"
84 #include "variables.h"
85 #include "version.h"
86 
87 // TRUE means the quit() call is allowed.
88 bool quit_allowed = true;
89 
90 // TRUE means we are ready to interpret commands, but not everything
91 // is ready for interactive use.
93 
94 // TRUE means we've processed all the init code and we are good to go.
95 std::atomic<bool> octave_initialized{false};
96 
98 
99 DEFUN (__version_info__, args, ,
100  doc: /* -*- texinfo -*-
101 @deftypefn {} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})
102 Undocumented internal function.
103 @end deftypefn */)
104 {
105  static octave_map vinfo;
106 
107  int nargin = args.length ();
108 
109  if (nargin != 0 && nargin != 4)
110  print_usage ();
111 
112  octave_value retval;
113 
114  if (nargin == 0)
115  retval = vinfo;
116  else if (nargin == 4)
117  {
118  if (vinfo.nfields () == 0)
119  {
120  vinfo.assign ("Name", args(0));
121  vinfo.assign ("Version", args(1));
122  vinfo.assign ("Release", args(2));
123  vinfo.assign ("Date", args(3));
124  }
125  else
126  {
127  octave_idx_type n = vinfo.numel () + 1;
128 
129  vinfo.resize (dim_vector (n, 1));
130 
131  octave_value idx (n);
132 
133  vinfo.assign (idx, "Name", Cell (octave_value (args(0))));
134  vinfo.assign (idx, "Version", Cell (octave_value (args(1))));
135  vinfo.assign (idx, "Release", Cell (octave_value (args(2))));
136  vinfo.assign (idx, "Date", Cell (octave_value (args(3))));
137  }
138  }
139 
140  return retval;
141 }
142 
143 DEFMETHOD (quit, interp, args, ,
144  doc: /* -*- texinfo -*-
145 @deftypefn {} {} quit
146 @deftypefnx {} {} quit cancel
147 @deftypefnx {} {} quit force
148 @deftypefnx {} {} quit ("cancel")
149 @deftypefnx {} {} quit ("force")
150 @deftypefnx {} {} quit (@var{status})
151 @deftypefnx {} {} quit (@var{status}, "force")
152 @deftypefnx {} {} exit (@dots{})
153 Quit the current Octave session.
154 
155 If the optional integer value @var{status} is supplied, pass that value to
156 the operating system as Octave's exit status. The default value is zero.
157 
158 When exiting, Octave will attempt to run the m-file @file{finish.m} if it
159 exists. User commands to save the workspace or clean up temporary files
160 may be placed in that file. Alternatively, another m-file may be scheduled
161 to run using @code{atexit}. If an error occurs while executing the
162 @file{finish.m} file, Octave does not exit and control is returned to
163 the command prompt.
164 
165 If the optional argument @qcode{"cancel"} is provided, Octave does not
166 exit and control is returned to the command prompt. This feature allows
167 the @code{finish.m} file to cancel the quit process.
168 
169 If the user preference to request confirmation before exiting, Octave
170 will display a dialog and give the user an option to cancel the exit
171 process.
172 
173 If the optional argument @qcode{"force"} is provided, no confirmation is
174 requested, and the execution of the @file{finish.m} file is skipped.
175 
176 Programming Note: @code{exit} is an alias for @code{quit} and can be used
177 interchangeably.
178 @seealso{atexit}
179 @end deftypefn */)
180 {
181  int numel = args.length ();
182 
183  if (numel > 2)
184  print_usage ();
185 
186  int exit_status = 0;
187 
188  bool force = false;
189  bool cancel = false;
190 
191  if (numel == 2)
192  {
193  exit_status = args(0).xnint_value ("quit: STATUS must be an integer");
194  std::string frc
195  = args(1).xstring_value ("quit: second argument must be a string");
196 
197  if (frc == "force")
198  force = true;
199  else
200  error (R"(quit: second argument must be string "force")");
201  }
202  else if (numel == 1)
203  {
204  if (args(0).is_string ())
205  {
206  const char *msg
207  = R"(quit: option must be string "cancel" or "force")";
208 
209  std::string opt = args(0).xstring_value (msg);
210 
211  if (opt == "cancel")
212  cancel = true;
213  else if (opt == "force")
214  force = true;
215  else
216  error ("%s", msg);
217  }
218  else
219  exit_status = args(0).xnint_value ("quit: STATUS must be an integer");
220  }
221 
222  if (cancel)
223  {
224  // No effect if "quit cancel" appears outside of finish script.
225 
226  if (interp.executing_finish_script ())
227  interp.cancel_quit (true);
228 
229  return ovl ();
230  }
231 
232  interp.quit (exit_status, force);
233 
234  return ovl ();
235 }
236 
237 DEFALIAS (exit, quit);
238 
239 DEFMETHOD (atexit, interp, args, nargout,
240  doc: /* -*- texinfo -*-
241 @deftypefn {} {} atexit (@var{fcn})
242 @deftypefnx {} {} atexit (@var{fcn}, true)
243 @deftypefnx {} {} atexit (@var{fcn}, false)
244 @deftypefnx {} {@var{status} =} atexit (@var{fcn}, false)
245 Register a function to be called when Octave exits.
246 
247 For example,
248 
249 @example
250 @group
251 function last_words ()
252  disp ("Bye bye");
253 endfunction
254 atexit ("last_words");
255 @end group
256 @end example
257 
258 @noindent
259 will print the message @qcode{"Bye bye"} when Octave exits.
260 
261 The additional argument @var{flag} will register or unregister @var{fcn}
262 from the list of functions to be called when Octave exits. If @var{flag} is
263 true, the function is registered, and if @var{flag} is false, it is
264 unregistered. For example, after registering the function @code{last_words}
265 above,
266 
267 @example
268 atexit ("last_words", false);
269 @end example
270 
271 @noindent
272 will remove the function from the list and Octave will not call
273 @code{last_words} when it exits.
274 
275 The optional output @var{status} is only available when unregistering a
276 function. The value is true if the unregistering was successful and false
277 otherwise.
278 
279 Programming Note: @code{atexit} only removes the first occurrence of a function
280 from the list; if a function was placed in the list multiple times with
281 @code{atexit}, it must also be removed from the list multiple times.
282 @seealso{quit}
283 @end deftypefn */)
284 {
285  int nargin = args.length ();
286 
287  if (nargin < 1 || nargin > 2)
288  print_usage ();
289 
290  std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string");
291 
292  bool add_mode = (nargin == 2)
293  ? args(1).xbool_value ("atexit: FLAG argument must be a logical value")
294  : true;
295 
296  octave_value_list retval;
297 
298  if (add_mode)
299  interp.add_atexit_fcn (arg);
300  else
301  {
302  bool found = interp.remove_atexit_fcn (arg);
303 
304  if (nargout > 0)
305  retval = ovl (found);
306  }
307 
308  return retval;
309 }
310 
311 DEFMETHOD (__traditional__, interp, , ,
312  doc: /* -*- texinfo -*-
313 @deftypefn {} {@var{tf} =} __traditional__ ()
314 Return true if Octave was invoked with the @w{@env{--traditional}}@ option.
315 @end deftypefn */)
316 {
317  return ovl (interp.traditional ());
318 }
319 
321 {
322  cleanup ();
323 }
324 
325 void
326 temporary_file_list::insert (const std::string& file)
327 {
328  m_files.insert (file);
329 }
330 
331 void
333 {
334  while (! m_files.empty ())
335  {
336  auto it = m_files.begin ();
337 
338  octave_unlink_wrapper (it->c_str ());
339 
340  m_files.erase (it);
341  }
342 }
343 
344 // The time we last time we changed directories.
345 sys::time Vlast_chdir_time = 0.0;
346 
347 static void
348 initialize_version_info ()
349 {
350  octave_value_list args (4);
351 
352  args(0) = "GNU Octave";
353  args(1) = OCTAVE_VERSION;
354  args(2) = config::release ();
355  args(3) = OCTAVE_RELEASE_DATE;
356 
357  F__version_info__ (args);
358 }
359 
360 static void
361 xerbla_abort ()
362 {
363  error ("Fortran procedure terminated by call to XERBLA");
364 }
365 
366 static void
367 initialize_xerbla_error_handler ()
368 {
369  // The idea here is to force xerbla to be referenced so that we will
370  // link to our own version instead of the one provided by the BLAS
371  // library. But numeric_limits<double>::NaN () should never be -1, so
372  // we should never actually call xerbla. FIXME (again!): If this
373  // becomes a constant expression the test might be optimized away and
374  // then the reference to the function might also disappear.
375 
376  if (numeric_limits<double>::NaN () == -1)
377  F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6));
378 
379  typedef void (*xerbla_handler_ptr) ();
380 
381  typedef void (*octave_set_xerbla_handler_ptr) (xerbla_handler_ptr);
382 
383  dynamic_library libs ("");
384 
385  if (libs)
386  {
387  octave_set_xerbla_handler_ptr octave_set_xerbla_handler
388  = reinterpret_cast<octave_set_xerbla_handler_ptr>
389  (libs.search ("octave_set_xerbla_handler"));
390 
392  octave_set_xerbla_handler (xerbla_abort);
393  }
394 }
395 
396 OCTAVE_NORETURN static void
397 lo_error_handler (const char *fmt, ...)
398 {
399  va_list args;
400  va_start (args, fmt);
401  verror_with_cfn (fmt, args);
402  va_end (args);
403 
404  throw execution_exception ();
405 }
406 
407 OCTAVE_NORETURN static void
408 lo_error_with_id_handler (const char *id, const char *fmt, ...)
409 {
410  va_list args;
411  va_start (args, fmt);
412  verror_with_id_cfn (id, fmt, args);
413  va_end (args);
414 
415  throw execution_exception ();
416 }
417 
418 static void
419 initialize_error_handlers ()
420 {
421  set_liboctave_error_handler (lo_error_handler);
422  set_liboctave_error_with_id_handler (lo_error_with_id_handler);
425 }
426 
427 // Create an interpreter object and perform initialization up to the
428 // point of setting reading command history and setting the load
429 // path.
430 
432  : m_app_context (app_context),
433  m_tmp_files (),
434  m_atexit_fcns (),
435  m_display_info (),
436  m_environment (),
437  m_settings (),
438  m_error_system (*this),
439  m_evaluator (*this),
440  m_help_system (*this),
441  m_input_system (*this),
442  m_output_system (*this),
443  m_history_system (*this),
444  m_dynamic_loader (*this),
445  m_load_path (*this),
446  m_load_save_system (*this),
447  m_type_info (),
448  m_symbol_table (*this),
449  m_stream_list (*this),
450  m_child_list (),
451  m_url_handle_manager (),
452  m_cdef_manager (*this),
453  m_gtk_manager (*this),
454  m_event_manager (*this),
455  m_gh_manager (nullptr),
456  m_interactive (false),
457  m_read_site_files (true),
458  m_read_init_files (m_app_context != nullptr),
459  m_verbose (false),
460  m_traditional (false),
461  m_inhibit_startup_message (false),
462  m_load_path_initialized (false),
463  m_history_initialized (false),
464  m_interrupt_all_in_process_group (true),
465  m_cancel_quit (false),
466  m_executing_finish_script (false),
467  m_executing_atexit (false),
468  m_initialized (false)
469 {
470  // FIXME: When thread_local storage is used by default, this message
471  // should change to say something like
472  //
473  // only one Octave interpreter may be active in any given thread
474 
475  if (s_instance)
476  throw std::runtime_error
477  ("only one Octave interpreter may be active");
478 
479  s_instance = this;
480 
481 #if defined (OCTAVE_HAVE_WINDOWS_UTF8_LOCALE)
482  // Force a UTF-8 locale on Windows if possible
483  std::setlocale (LC_ALL, ".UTF8");
484 #else
485  std::setlocale (LC_ALL, "");
486 #endif
487  // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting
488  std::setlocale (LC_NUMERIC, "C");
489  std::setlocale (LC_TIME, "C");
490  sys::env::putenv ("LC_NUMERIC", "C");
491  sys::env::putenv ("LC_TIME", "C");
492 
493  // Initialize the default floating point unit control state.
495 
496  thread::init ();
497 
498  octave_ieee_init ();
499 
500  initialize_xerbla_error_handler ();
501 
502  initialize_error_handlers ();
503 
504  if (m_app_context)
505  {
507  octave_unblock_signal_by_name ("SIGTSTP");
508  }
509  else
510  quit_allowed = false;
511 
512  if (! m_app_context)
513  m_display_info.initialize ();
514 
515  bool line_editing = false;
516 
517  if (m_app_context)
518  {
519  // Embedded interpreters don't execute command line options.
520  const cmdline_options& options = m_app_context->options ();
521 
522  // Make all command-line arguments available to startup files,
523  // including PKG_ADD files.
524 
525  string_vector args = options.all_args ();
526 
527  m_app_context->intern_argv (args);
528  intern_nargin (args.numel () - 1);
529 
530  bool is_octave_program = m_app_context->is_octave_program ();
531 
532  std::list<std::string> command_line_path = options.command_line_path ();
533 
534  for (const auto& pth : command_line_path)
535  m_load_path.set_command_line_path (pth);
536 
537  std::string exec_path = options.exec_path ();
538  if (! exec_path.empty ())
539  m_environment.exec_path (exec_path);
540 
541  std::string image_path = options.image_path ();
542  if (! image_path.empty ())
543  m_environment.image_path (image_path);
544 
545  if (! options.no_window_system ())
546  m_display_info.initialize ();
547 
548  // Is input coming from a terminal? If so, we are probably
549  // interactive.
550 
551  // If stdin is not a tty, then we are reading commands from a
552  // pipe or a redirected file.
553  bool stdin_is_tty = octave_isatty_wrapper (fileno (stdin));
554 
555  m_interactive = (! is_octave_program && stdin_is_tty
556  && octave_isatty_wrapper (fileno (stdout)));
557 
558  // Don't force interactive if we're already interactive (bug #60696).
559  bool forced_interactive = options.forced_interactive ();
560  if (m_interactive)
561  {
562  m_app_context->forced_interactive (false);
563  forced_interactive = false;
564  }
565 
566  // Check if the user forced an interactive session.
567  if (forced_interactive)
568  m_interactive = true;
569 
570  line_editing = options.line_editing ();
571  if ((! m_interactive || forced_interactive)
572  && ! options.forced_line_editing ())
573  line_editing = false;
574 
575  m_traditional = options.traditional ();
576 
577  // FIXME: if possible, perform the following actions directly
578  // instead of using the interpreter-level functions.
579 
580  if (options.echo_commands ())
581  m_evaluator.echo
584 
585  std::string docstrings_file = options.docstrings_file ();
586  if (! docstrings_file.empty ())
587  Fbuilt_in_docstrings_file (*this, ovl (docstrings_file));
588 
589  std::string doc_cache_file = options.doc_cache_file ();
590  if (! doc_cache_file.empty ())
591  Fdoc_cache_file (*this, ovl (doc_cache_file));
592 
593  std::string info_file = options.info_file ();
594  if (! info_file.empty ())
595  Finfo_file (*this, ovl (info_file));
596 
597  std::string info_program = options.info_program ();
598  if (! info_program.empty ())
599  Finfo_program (*this, ovl (info_program));
600 
601  std::string texi_macros_file = options.texi_macros_file ();
602  if (! texi_macros_file.empty ())
603  Ftexi_macros_file (*this, ovl (texi_macros_file));
604  }
605 
606  // FIXME: we defer creation of the gh_manager object because it
607  // creates a root_figure object that requires the display_info
608  // object, but that is currently only accessible through the global
609  // interpreter object and that is not available until after the
610  // interpreter::instance pointer is set (above). It would be better
611  // if m_gh_manager could be an object value instead of a pointer and
612  // created as part of the interpreter initialization. To do that,
613  // we should either make the display_info object independent of the
614  // interpreter object (does it really need to cache any
615  // information?) or defer creation of the root_figure object until
616  // it is actually needed.
617  m_gh_manager = new gh_manager (*this);
618 
619  m_input_system.initialize (line_editing);
620 
621  // These can come after command line args since none of them set any
622  // defaults that might be changed by command line options.
623 
624  initialize_version_info ();
625 
626  // This should be done before initializing the load path because
627  // some PKG_ADD files might need --traditional behavior.
628 
629  if (m_traditional)
630  maximum_braindamage ();
631 
633 }
634 
635 OCTAVE_THREAD_LOCAL interpreter *interpreter::s_instance = nullptr;
636 
638 {
639  if (! m_app_context)
640  shutdown ();
641 
642  delete m_gh_manager;
643 }
644 
645 void
647 {
648  m_evaluator.set_auto_fcn_var (stack_frame::NARGIN, nargs);
649 }
650 
651 // Read the history file unless a command-line option inhibits that.
652 
653 void
654 interpreter::initialize_history (bool read_history_file)
655 {
656  if (! m_history_initialized)
657  {
658  // Allow command-line option to override.
659 
660  if (m_app_context)
661  {
662  const cmdline_options& options = m_app_context->options ();
663 
664  read_history_file = options.read_history_file ();
665 
666  if (! read_history_file)
668  }
669 
670  m_history_system.initialize (read_history_file);
671 
672  if (! m_app_context)
674 
675  m_history_initialized = true;
676  }
677 }
678 
679 // Set the initial path to the system default unless command-line
680 // option says to leave it empty.
681 
682 void
683 interpreter::initialize_load_path (bool set_initial_path)
684 {
685  if (! m_load_path_initialized)
686  {
687  // Allow command-line option to override.
688 
689  if (m_app_context)
690  {
691  const cmdline_options& options = m_app_context->options ();
692 
693  set_initial_path = options.set_initial_path ();
694  }
695 
696  // Temporarily set the execute_pkg_add function to one that
697  // catches exceptions. This is better than wrapping
698  // load_path::initialize in a try-catch block because it will
699  // not stop executing PKG_ADD files at the first exception.
700  // It's also better than changing the default execute_pkg_add
701  // function to use safe_source file because that will normally
702  // be evaluated from the normal interpreter loop where exceptions
703  // are already handled.
704 
705  unwind_action restore_add_hook (&load_path::set_add_hook, &m_load_path,
706  m_load_path.get_add_hook ());
707 
708  m_load_path.set_add_hook ([=] (const std::string& dir)
709  { this->execute_pkg_add (dir); });
710 
711  m_load_path.initialize (set_initial_path);
712 
713  m_load_path_initialized = true;
714  }
715 }
716 
717 // This may be called separately from execute
718 
719 void
721 {
722  if (m_initialized)
723  return;
724 
725  if (m_app_context)
726  {
727  const cmdline_options& options = m_app_context->options ();
728 
729  if (options.experimental_terminal_widget ())
730  {
731  if (! options.gui ())
732  display_startup_message ();
733  }
734  else
735  display_startup_message ();
736  }
737  else
738  display_startup_message ();
739 
740  // Wait to read the history file until the interpreter reads input
741  // files and begins evaluating commands.
742 
744 
745  // Initializing the load path may execute PKG_ADD files, so can't be
746  // done until the interpreter is ready to execute commands.
747 
748  // Deferring it to the execute step also allows the path to be
749  // initialized between creating and execute the interpreter, for
750  // example, to set a custom path for an embedded interpreter.
751 
753 
755 
756  can_interrupt = true;
757 
759  octave_interrupt_hook = nullptr;
760 
761  catch_interrupts ();
762 
763  // FIXME: could we eliminate this variable or make it not be global?
764  // Global used to communicate with signal handler.
765  octave_initialized = true;
766 
767  m_initialized = true;
768 }
769 
770 // Note: this function is currently only used with the new
771 // experimental terminal widget.
772 
773 void
775 {
776  m_evaluator.get_line_and_eval ();
777 }
778 
779 // Note: the following class is currently only used with the new
780 // experimental terminal widget.
781 
782 class cli_input_reader
783 {
784 public:
785 
786  cli_input_reader (interpreter& interp)
787  : m_interpreter (interp), m_thread () { }
788 
789  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (cli_input_reader)
790 
791  ~cli_input_reader ()
792  {
793  // FIXME: Would it be better to ensure that
794  // interpreter::get_line_and_eval exits and then call
795  // m_thread.join () here?
796 
797  m_thread.detach ();
798  }
799 
800  void start ()
801  {
802  m_thread = std::thread (&interpreter::get_line_and_eval, &m_interpreter);
803  }
804 
805 private:
806 
807  interpreter& m_interpreter;
808 
809  std::thread m_thread;
810 };
811 
812 void
813 interpreter::parse_and_execute (const std::string& input,
814  bool& incomplete_parse)
815 {
816  m_evaluator.parse_and_execute (input, incomplete_parse);
817 }
818 
819 // FIXME: this function is intended to be executed only once. Should
820 // we enforce that restriction?
821 
822 int
824 {
825  int exit_status = 0;
826 
827  try
828  {
829  initialize ();
830 
831  execute_startup_files ();
832 
833  if (m_app_context)
834  {
835  const cmdline_options& options = m_app_context->options ();
836 
837  if (m_app_context->have_eval_option_code ())
838  {
839  int status = execute_eval_option_code ();
840 
841  if (status )
842  exit_status = status;
843 
844  if (! options.persist ())
845  {
846  shutdown ();
847 
848  return exit_status;
849  }
850  }
851 
852  // If there is an extra argument, see if it names a file to
853  // read. Additional arguments are taken as command line options
854  // for the script.
855 
856  if (m_app_context->have_script_file ())
857  {
858  int status = execute_command_line_file ();
859 
860  if (status)
861  exit_status = status;
862 
863  if (! options.persist ())
864  {
865  shutdown ();
866 
867  return exit_status;
868  }
869  }
870 
871  if (options.forced_interactive ())
873 
874  if (options.server ())
875  exit_status = server_loop ();
876  else if (options.experimental_terminal_widget ())
877  {
878  if (options.gui ())
879  {
880  m_event_manager.start_gui (true);
881 
882  exit_status = server_loop ();
883  }
884  else
885  {
886  // Use an object so that the thread started for the
887  // reader will be cleaned up no matter how we exit
888  // this function.
889 
890  cli_input_reader reader (*this);
891 
892  reader.start ();
893 
894  exit_status = server_loop ();
895  }
896  }
897  else
898  exit_status = main_loop ();
899 
900  shutdown ();
901  }
902  }
903  catch (const exit_exception& xe)
904  {
905  exit_status = xe.exit_status ();
906 
907  shutdown ();
908  }
909 
910  return exit_status;
911 }
912 
913 // Call a function with exceptions handled to avoid problems with
914 // errors while shutting down.
915 
916 #define OCTAVE_IGNORE_EXCEPTION(E) \
917  catch (E) \
918  { \
919  recover_from_exception (); \
920  \
921  std::cerr << "error: ignoring " #E " while preparing to exit" \
922  << std::endl; \
923  }
924 
925 #define OCTAVE_SAFE_CALL(F, ARGS) \
926  do \
927  { \
928  try \
929  { \
930  unwind_action restore_debug_on_error \
931  (&error_system::set_debug_on_error, &m_error_system, \
932  m_error_system.debug_on_error ()); \
933  \
934  unwind_action restore_debug_on_warning \
935  (&error_system::set_debug_on_warning, &m_error_system, \
936  m_error_system.debug_on_warning ()); \
937  \
938  m_error_system.debug_on_error (false); \
939  m_error_system.debug_on_warning (false); \
940  \
941  F ARGS; \
942  } \
943  OCTAVE_IGNORE_EXCEPTION (const exit_exception&) \
944  OCTAVE_IGNORE_EXCEPTION (const interrupt_exception&) \
945  OCTAVE_IGNORE_EXCEPTION (const execution_exception&) \
946  OCTAVE_IGNORE_EXCEPTION (const std::bad_alloc&) \
947  } \
948  while (0)
949 
950 void
951 interpreter::shutdown ()
952 {
953  // Attempt to prevent more than one call to shutdown.
954 
955  if (! m_initialized)
956  return;
957 
958  m_initialized = false;
959 
960  OCTAVE_SAFE_CALL (feval, ("close", ovl ("all"), 0));
961 
962  // Any atexit functions added after this function call won't be
963  // executed. Each atexit function is executed with
964  // OCTAVE_SAFE_CALL, so we don't need that here.
965 
966  execute_atexit_fcns ();
967 
968  // Clear all functions and variables while the event manager is
969  // still processing events and notify the event manager. This way,
970  // the workspace model will be cleared before the GUI exits.
971 
972  // FIXME: This approach seems a bit fragile since there could be
973  // other places in the GUI that have references to interpreter
974  // objects. How can we reliably ensure that they are all removed
975  // before the interpreter exits? Maybe the best solution is to
976  // always start the GUI from the interpreter and close it when the
977  // interpreter exits? However, the workspace model is owned by the
978  // base_qobject object not the workspace viewer or the main window,
979  // so simply closing the GUI window(s) is not sufficient. See also
980  // bug #61994.
981 
982  // Note that we don't force symbols to be cleared, so we will
983  // respect mlock at this point. Later, we'll force all variables
984  // and functions to be cleared.
985 
987  OCTAVE_SAFE_CALL (m_event_manager.clear_workspace, ());
988 
989  // If we are attached to a GUI, queue and event to close it (only
990  // works with the new terminal widget), process pending events and
991  // disable the link.
992 
993  OCTAVE_SAFE_CALL (m_event_manager.close_gui, ());
994  OCTAVE_SAFE_CALL (m_event_manager.process_events, (true));
995  OCTAVE_SAFE_CALL (m_event_manager.disable, ());
996 
997  OCTAVE_SAFE_CALL (m_input_system.clear_input_event_hooks, ());
998 
999  // We may still have some figures. Close them.
1000 
1001  OCTAVE_SAFE_CALL (feval, ("close", ovl ("all"), 0));
1002 
1003  // What is supposed to happen if a figure has a closerequestfcn or
1004  // deletefcn callback registered that creates other figures or
1005  // variables? What if those variables are classdef objects with
1006  // destructors that can create figures? The possibilities are
1007  // endless. At some point, we have to give up and force execution
1008  // to end.
1009 
1010  // Note that we again don't force symbols to be cleared, so we
1011  // continue to respect mlock here. Later, we'll force all variables
1012  // and functions to be cleared.
1013 
1015 
1016  // Do this explicitly so that destructors for mex file objects
1017  // are called, so that functions registered with mexAtExit are
1018  // called.
1019 
1020  OCTAVE_SAFE_CALL (m_symbol_table.clear_mex_functions, ());
1021 
1023 
1024  OCTAVE_SAFE_CALL (m_history_system.write_timestamp, ());
1025 
1028 
1029  OCTAVE_SAFE_CALL (m_gtk_manager.unload_all_toolkits, ());
1030 
1031  // Now that the graphics toolkits have been unloaded, force all
1032  // symbols to be cleared.
1033 
1034  OCTAVE_SAFE_CALL (clear_all, (true));
1035 
1036  // FIXME: May still need something like this to ensure that
1037  // destructors for class objects will run properly. Should that be
1038  // done earlier? Before or after atexit functions are executed?
1039  // What will happen if the destructor for an obect attempts to
1040  // display a figure?
1041 
1042  OCTAVE_SAFE_CALL (m_symbol_table.cleanup, ());
1043 
1045 
1047 
1048  // Don't call singleton_cleanup_list::cleanup until we have the
1049  // problems with registering/unregistering types worked out. For
1050  // example, uncomment the following line, then use the make_int
1051  // function from the examples directory to create an integer
1052  // object and then exit Octave. Octave should crash with a
1053  // segfault when cleaning up the typinfo singleton. We need some
1054  // way to force new octave_value_X types that are created in
1055  // .oct files to be unregistered when the .oct file shared library
1056  // is unloaded.
1057  //
1058  // OCTAVE_SAFE_CALL (singleton_cleanup_list::cleanup, ());
1059 }
1060 
1061 void
1062 interpreter::execute_atexit_fcns ()
1063 {
1064  // Prevent atexit functions from adding new functions to the list.
1065  m_executing_atexit = true;
1066 
1067  while (! m_atexit_fcns.empty ())
1068  {
1069  std::string fcn = m_atexit_fcns.front ();
1070 
1071  m_atexit_fcns.pop_front ();
1072 
1073  OCTAVE_SAFE_CALL (feval, (fcn, octave_value_list (), 0));
1074 
1076  }
1077 }
1078 
1079 void
1080 interpreter::display_startup_message () const
1081 {
1082  bool inhibit_startup_message = false;
1083 
1084  if (m_app_context)
1085  {
1086  const cmdline_options& options = m_app_context->options ();
1087 
1089  }
1090 
1091  if (m_interactive && ! inhibit_startup_message)
1092  std::cout << octave_startup_message () << "\n" << std::endl;
1093 }
1094 
1095 // Initialize by reading startup files. Return nonzero if an exception
1096 // occurs when reading any of them, but don't exit early because of an
1097 // exception.
1098 
1099 int
1100 interpreter::execute_startup_files ()
1101 {
1102  bool read_site_files = m_read_site_files;
1103  bool read_init_files = m_read_init_files;
1104  bool verbose = m_verbose;
1105  bool inhibit_startup_message = m_inhibit_startup_message;
1106 
1107  if (m_app_context)
1108  {
1109  const cmdline_options& options = m_app_context->options ();
1110 
1111  read_site_files = options.read_site_files ();
1112  read_init_files = options.read_init_files ();
1113  verbose = options.verbose_flag ();
1115  }
1116 
1118 
1119  bool require_file = false;
1120 
1121  std::string context;
1122 
1123  int exit_status = 0;
1124 
1125  if (read_site_files)
1126  {
1127  // Execute commands from the site-wide configuration file.
1128  // First from the file $(prefix)/lib/octave/site/m/octaverc
1129  // (if it exists), then from the file
1130  // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
1131 
1132  int status = safe_source_file (config::local_site_defaults_file (),
1133  context, verbose, require_file);
1134 
1135  if (status)
1136  exit_status = status;
1137 
1138  status = safe_source_file (config::site_defaults_file (),
1139  context, verbose, require_file);
1140 
1141  if (status)
1142  exit_status = status;
1143  }
1144 
1145  if (read_init_files)
1146  {
1147  // Try to execute commands from the Matlab compatible startup.m file
1148  // if it exists anywhere in the load path when starting Octave.
1149  std::string ff_startup_m = file_in_path ("startup.m", "");
1150 
1151  if (! ff_startup_m.empty ())
1152  {
1153  int parse_status = 0;
1154 
1155  try
1156  {
1157  eval_string (std::string ("startup"), false, parse_status, 0);
1158  }
1159  catch (const interrupt_exception&)
1160  {
1162  }
1163  catch (const execution_exception& ee)
1164  {
1165  handle_exception (ee);
1166  }
1167  }
1168 
1169  // Try to execute commands from $CONFIG/octave/octaverc, where
1170  // $CONFIG is the platform-dependent location for user local
1171  // configuration files.
1172 
1173  std::string user_config_dir = sys::env::get_user_config_directory ();
1174 
1175  std::string cfg_dir = user_config_dir + sys::file_ops::dir_sep_str ()
1176  + "octave";
1177 
1178  std::string cfg_rc = sys::env::make_absolute ("octaverc", cfg_dir);
1179 
1180  if (! cfg_rc.empty ())
1181  {
1182  int status = safe_source_file (cfg_rc, context, verbose,
1183  require_file);
1184 
1185  if (status)
1186  exit_status = status;
1187  }
1188 
1189  // Try to execute commands from $HOME/$OCTAVE_INITFILE and
1190  // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
1191  // .octaverc is assumed.
1192 
1193  bool home_rc_already_executed = false;
1194 
1195  std::string initfile = sys::env::getenv ("OCTAVE_INITFILE");
1196 
1197  if (initfile.empty ())
1198  initfile = ".octaverc";
1199 
1200  std::string home_dir = sys::env::get_home_directory ();
1201 
1202  std::string home_rc = sys::env::make_absolute (initfile, home_dir);
1203 
1204  std::string local_rc;
1205 
1206  if (! home_rc.empty ())
1207  {
1208  int status = safe_source_file (home_rc, context, verbose,
1209  require_file);
1210 
1211  if (status)
1212  exit_status = status;
1213 
1214  // Names alone are not enough.
1215 
1216  if (sys::file_exists (home_rc))
1217  {
1218  // We want to check for curr_dir after executing home_rc
1219  // because doing that may change the working directory.
1220 
1221  local_rc = sys::env::make_absolute (initfile);
1222 
1223  home_rc_already_executed = sys::same_file (home_rc, local_rc);
1224  }
1225  }
1226 
1227  if (! home_rc_already_executed)
1228  {
1229  if (local_rc.empty ())
1230  local_rc = sys::env::make_absolute (initfile);
1231 
1232  int status = safe_source_file (local_rc, context, verbose,
1233  require_file);
1234 
1235  if (status)
1236  exit_status = status;
1237  }
1238  }
1239 
1240  if (m_interactive && verbose)
1241  std::cout << std::endl;
1242 
1243  return exit_status;
1244 }
1245 
1246 // Execute any code specified with --eval 'CODE'
1247 
1248 int
1249 interpreter::execute_eval_option_code ()
1250 {
1251  if (! m_app_context)
1252  return 0;
1253 
1254  const cmdline_options& options = m_app_context->options ();
1255 
1256  std::string code_to_eval = options.code_to_eval ();
1257 
1258  unwind_protect_var<bool> upv (m_interactive, false);
1259 
1260  int parse_status = 0;
1261 
1262  try
1263  {
1264  eval_string (code_to_eval, false, parse_status, 0);
1265  }
1266  catch (const interrupt_exception&)
1267  {
1269 
1270  return 1;
1271  }
1272  catch (const execution_exception& ee)
1273  {
1274  handle_exception (ee);
1275 
1276  return 1;
1277  }
1278 
1279  return parse_status;
1280 }
1281 
1282 int
1283 interpreter::execute_command_line_file ()
1284 {
1285  if (! m_app_context)
1286  return 0;
1287 
1288  const cmdline_options& options = m_app_context->options ();
1289 
1290  string_vector args = options.all_args ();
1291 
1292  void (interpreter::*interactive_fptr) (bool) = &interpreter::interactive;
1293  unwind_action restore_interactive (interactive_fptr, this, m_interactive);
1294 
1295  unwind_action restore_argv (&application::intern_argv, m_app_context, args);
1296 
1297  unwind_action restore_nargin (&interpreter::intern_nargin, this,
1298  args.numel () - 1);
1299 
1300  void (application::*program_invocation_name_fptr) (const std::string&)
1302  unwind_action restore_program_invocation_name
1303  (program_invocation_name_fptr, m_app_context,
1305 
1306  void (application::*program_name_fptr) (const std::string&)
1308  unwind_action restore_program_name
1309  (program_name_fptr, m_app_context, application::program_name ());
1310 
1311  m_interactive = false;
1312 
1313  // If we are running an executable script (#! /bin/octave) then
1314  // we should only see the args passed to the script.
1315 
1316  string_vector script_args = options.remaining_args ();
1317 
1318  m_app_context->intern_argv (script_args);
1319  intern_nargin (script_args.numel () - 1);
1320 
1321  std::string fname = script_args[0];
1322 
1323  m_app_context->set_program_names (fname);
1324 
1325  std::string context;
1326  bool verbose = false;
1327  bool require_file = true;
1328 
1329  return safe_source_file (fname, context, verbose, require_file);
1330 }
1331 
1332 int
1333 interpreter::main_loop ()
1334 {
1336 
1337  return m_evaluator.repl ();
1338 }
1339 
1340 int
1341 interpreter::server_loop ()
1342 {
1343  return m_evaluator.server_loop ();
1344 }
1345 
1348 {
1349  return m_evaluator;
1350 }
1351 
1352 stream_list&
1354 {
1355  return m_stream_list;
1356 }
1357 
1360 {
1361  return m_url_handle_manager;
1362 }
1363 
1366 {
1367  return m_evaluator.get_top_scope ();
1368 }
1369 
1372 {
1373  return m_evaluator.get_current_scope ();
1374 }
1375 
1377 interpreter::require_current_scope (const std::string& who) const
1378 {
1379  symbol_scope scope = get_current_scope ();
1380 
1381  if (! scope)
1382  error ("%s: symbol table scope missing", who.c_str ());
1383 
1384  return scope;
1385 }
1386 
1387 profiler&
1389 {
1390  return m_evaluator.get_profiler ();
1391 }
1392 
1393 int
1394 interpreter::chdir (const std::string& dir)
1395 {
1396  std::string xdir = sys::file_ops::tilde_expand (dir);
1397 
1398  int cd_ok = sys::env::chdir (xdir);
1399 
1400  if (! cd_ok)
1401  error ("%s: %s", dir.c_str (), std::strerror (errno));
1402 
1403  Vlast_chdir_time.stamp ();
1404 
1405  // FIXME: should these actions be handled as a list of functions
1406  // to call so users can add their own chdir handlers?
1407 
1408  m_load_path.read_dir_config (".");
1409  m_load_path.update ();
1410  // Updating the last prompt time stamp avoids skipping a fcn-info refresh
1411  // so that functions in the new current directory can shadow functions
1412  // further back in the load path order.
1413  Vlast_prompt_time.stamp ();
1414 
1415  m_event_manager.directory_changed (sys::env::get_current_directory ());
1416 
1417  return cd_ok;
1418 }
1419 
1420 void
1421 interpreter::mlock (bool skip_first) const
1422 {
1423  m_evaluator.mlock (skip_first);
1424 }
1425 
1426 void
1427 interpreter::munlock (bool skip_first) const
1428 {
1429  m_evaluator.munlock (skip_first);
1430 }
1431 
1432 bool
1433 interpreter::mislocked (bool skip_first) const
1434 {
1435  return m_evaluator.mislocked (skip_first);
1436 }
1437 
1438 void
1439 interpreter::munlock (const char *nm)
1440 {
1441  if (! nm)
1442  error ("munlock: invalid value for NAME");
1443 
1444  munlock (std::string (nm));
1445 }
1446 
1447 void
1448 interpreter::munlock (const std::string& nm)
1449 {
1450  octave_value val = m_symbol_table.find_function (nm);
1451 
1452  if (val.is_defined ())
1453  {
1454  octave_function *fcn = val.function_value ();
1455 
1456  if (fcn)
1457  fcn->unlock ();
1458  }
1459 }
1460 
1461 bool
1462 interpreter::mislocked (const char *nm)
1463 {
1464  if (! nm)
1465  error ("mislocked: invalid value for NAME");
1466 
1467  return mislocked (std::string (nm));
1468 }
1469 
1470 bool
1471 interpreter::mislocked (const std::string& nm)
1472 {
1473  bool retval = false;
1474 
1475  octave_value val = m_symbol_table.find_function (nm);
1476 
1477  if (val.is_defined ())
1478  {
1479  octave_function *fcn = val.function_value ();
1480 
1481  if (fcn)
1482  retval = fcn->islocked ();
1483  }
1484 
1485  return retval;
1486 }
1487 
1488 std::string
1489 interpreter::mfilename (const std::string& opt) const
1490 {
1491  return m_evaluator.mfilename (opt);
1492 }
1493 
1495 interpreter::eval_string (const std::string& eval_str,
1496  bool silent, int& parse_status,
1497  int nargout)
1498 {
1499  return m_evaluator.eval_string (eval_str, silent, parse_status, nargout);
1500 }
1501 
1503 interpreter::eval_string (const std::string& eval_str,
1504  bool silent, int& parse_status)
1505 {
1506  return m_evaluator.eval_string (eval_str, silent, parse_status);
1507 }
1508 
1511  bool silent, int& parse_status,
1512  int nargout)
1513 {
1514  return m_evaluator.eval_string (arg, silent, parse_status, nargout);
1515 }
1516 
1518 interpreter::eval (const std::string& try_code,
1519  int nargout)
1520 {
1521  return m_evaluator.eval (try_code, nargout);
1522 }
1523 
1525 interpreter::eval (const std::string& try_code,
1526  const std::string& catch_code,
1527  int nargout)
1528 {
1529  return m_evaluator.eval (try_code, catch_code, nargout);
1530 }
1531 
1533 interpreter::evalin (const std::string& context,
1534  const std::string& try_code,
1535  int nargout)
1536 {
1537  return m_evaluator.evalin (context, try_code, nargout);
1538 }
1539 
1541 interpreter::evalin (const std::string& context,
1542  const std::string& try_code,
1543  const std::string& catch_code,
1544  int nargout)
1545 {
1546  return m_evaluator.evalin (context, try_code, catch_code, nargout);
1547 }
1548 
1549 //! Evaluate an Octave function (built-in or interpreted) and return
1550 //! the list of result values.
1551 //!
1552 //! @param name The name of the function to call.
1553 //! @param args The arguments to the function.
1554 //! @param nargout The number of output arguments expected.
1555 //! @return A list of output values. The length of the list is not
1556 //! necessarily the same as @c nargout.
1557 
1559 interpreter::feval (const char *name,
1560  const octave_value_list& args,
1561  int nargout)
1562 {
1563  return feval (std::string (name), args, nargout);
1564 }
1565 
1567 interpreter::feval (const std::string& name,
1568  const octave_value_list& args,
1569  int nargout)
1570 {
1571  octave_value fcn = m_symbol_table.find_function (name, args);
1572 
1573  if (fcn.is_undefined ())
1574  error ("feval: function '%s' not found", name.c_str ());
1575 
1576  octave_function *of = fcn.function_value ();
1577 
1578  return of->call (m_evaluator, nargout, args);
1579 }
1580 
1583  const octave_value_list& args,
1584  int nargout)
1585 {
1586  if (fcn)
1587  return fcn->call (m_evaluator, nargout, args);
1588 
1589  return octave_value_list ();
1590 }
1591 
1594  const octave_value_list& args,
1595  int nargout)
1596 {
1597  // FIXME: do we really want to silently return an empty ovl if
1598  // the function object is undefined? It's essentially what the
1599  // version above that accepts a pointer to an octave_function
1600  // object does and some code was apparently written to rely on it
1601  // (for example, __ode15__).
1602 
1603  if (val.is_undefined ())
1604  return ovl ();
1605 
1606  if (val.is_function ())
1607  {
1608  return feval (val.function_value (), args, nargout);
1609  }
1610  else if (val.is_function_handle () || val.is_inline_function ())
1611  {
1612  // This covers function handles, inline functions, and anonymous
1613  // functions.
1614 
1615  std::list<octave_value_list> arg_list;
1616  arg_list.push_back (args);
1617 
1618  // FIXME: could we make octave_value::subsref a const method?
1619  // It would be difficult because there are instances of
1620  // incrementing the reference count inside subsref methods,
1621  // which means they can't be const with the current way of
1622  // handling reference counting.
1623 
1624  octave_value xval = val;
1625  return xval.subsref ("(", arg_list, nargout);
1626  }
1627  else if (val.is_string ())
1628  {
1629  return feval (val.string_value (), args, nargout);
1630  }
1631  else
1632  error ("feval: first argument must be a string, inline function, or a function handle");
1633 
1634  return ovl ();
1635 }
1636 
1637 //! Evaluate an Octave function (built-in or interpreted) and return
1638 //! the list of result values.
1639 //!
1640 //! @param args The first element of @c args is the function to call.
1641 //! It may be the name of the function as a string, a function
1642 //! handle, or an inline function. The remaining arguments are
1643 //! passed to the function.
1644 //! @param nargout The number of output arguments expected.
1645 //! @return A list of output values. The length of the list is not
1646 //! necessarily the same as @c nargout.
1647 
1650  int nargout)
1651 {
1652  if (args.length () == 0)
1653  error ("feval: first argument must be a string, inline function, or a function handle");
1654 
1655  octave_value f_arg = args(0);
1656 
1657  octave_value_list tmp_args = args.slice (1, args.length () - 1, true);
1658 
1659  return feval (f_arg, tmp_args, nargout);
1660 }
1661 
1663 interpreter::make_function_handle (const std::string& name)
1664 {
1665  return m_evaluator.make_fcn_handle (name);
1666 }
1667 
1668 void
1669 interpreter::install_variable (const std::string& name,
1670  const octave_value& value, bool global)
1671 {
1672  m_evaluator.install_variable (name, value, global);
1673 }
1674 
1676 interpreter::global_varval (const std::string& name) const
1677 {
1678  return m_evaluator.global_varval (name);
1679 }
1680 
1681 void
1682 interpreter::global_assign (const std::string& name,
1683  const octave_value& val)
1684 {
1685  m_evaluator.global_assign (name, val);
1686 }
1687 
1689 interpreter::top_level_varval (const std::string& name) const
1690 {
1691  return m_evaluator.top_level_varval (name);
1692 }
1693 
1694 void
1695 interpreter::top_level_assign (const std::string& name,
1696  const octave_value& val)
1697 {
1698  m_evaluator.top_level_assign (name, val);
1699 }
1700 
1701 bool
1702 interpreter::is_variable (const std::string& name) const
1703 {
1704  return m_evaluator.is_variable (name);
1705 }
1706 
1707 bool
1708 interpreter::is_local_variable (const std::string& name) const
1709 {
1710  return m_evaluator.is_local_variable (name);
1711 }
1712 
1714 interpreter::varval (const std::string& name) const
1715 {
1716  return m_evaluator.varval (name);
1717 }
1718 
1719 void
1720 interpreter::assign (const std::string& name,
1721  const octave_value& val)
1722 {
1723  m_evaluator.assign (name, val);
1724 }
1725 
1726 void
1727 interpreter::assignin (const std::string& context,
1728  const std::string& name,
1729  const octave_value& val)
1730 {
1731  m_evaluator.assignin (context, name, val);
1732 }
1733 
1734 void
1735 interpreter::source_file (const std::string& file_name,
1736  const std::string& context, bool verbose,
1737  bool require_file)
1738 {
1739  m_evaluator.source_file (file_name, context, verbose, require_file);
1740 }
1741 
1742 bool
1744 {
1745  return m_evaluator.at_top_level ();
1746 }
1747 
1748 bool
1749 interpreter::isglobal (const std::string& name) const
1750 {
1751  return m_evaluator.is_global (name);
1752 }
1753 
1755 interpreter::find (const std::string& name)
1756 {
1757  return m_evaluator.find (name);
1758 }
1759 
1760 void
1762 {
1763  m_evaluator.clear_all (force);
1764 }
1765 
1766 void
1768 {
1769  m_evaluator.clear_objects ();
1770 }
1771 
1772 void
1773 interpreter::clear_variable (const std::string& name)
1774 {
1775  m_evaluator.clear_variable (name);
1776 }
1777 
1778 void
1779 interpreter::clear_variable_pattern (const std::string& pattern)
1780 {
1781  m_evaluator.clear_variable_pattern (pattern);
1782 }
1783 
1784 void
1785 interpreter::clear_variable_regexp (const std::string& pattern)
1786 {
1787  m_evaluator.clear_variable_regexp (pattern);
1788 }
1789 
1790 void
1792 {
1793  m_evaluator.clear_variables ();
1794 }
1795 
1796 void
1797 interpreter::clear_global_variable (const std::string& name)
1798 {
1799  m_evaluator.clear_global_variable (name);
1800 }
1801 
1802 void
1804 {
1805  m_evaluator.clear_global_variable_pattern (pattern);
1806 }
1807 
1808 void
1809 interpreter::clear_global_variable_regexp (const std::string& pattern)
1810 {
1811  m_evaluator.clear_global_variable_regexp (pattern);
1812 }
1813 
1814 void
1816 {
1817  m_evaluator.clear_global_variables ();
1818 }
1819 
1820 void
1822 {
1823  m_symbol_table.clear_functions (force);
1824 }
1825 
1826 void
1827 interpreter::clear_function (const std::string& name)
1828 {
1829  m_symbol_table.clear_function (name);
1830 }
1831 
1832 void
1833 interpreter::clear_symbol (const std::string& name)
1834 {
1835  m_evaluator.clear_symbol (name);
1836 }
1837 
1838 void
1839 interpreter::clear_function_pattern (const std::string& pat)
1840 {
1841  m_symbol_table.clear_function_pattern (pat);
1842 }
1843 
1844 void
1845 interpreter::clear_function_regexp (const std::string& pat)
1846 {
1847  m_symbol_table.clear_function_regexp (pat);
1848 }
1849 
1850 void
1851 interpreter::clear_symbol_pattern (const std::string& pat)
1852 {
1853  return m_evaluator.clear_symbol_pattern (pat);
1854 }
1855 
1856 void
1857 interpreter::clear_symbol_regexp (const std::string& pat)
1858 {
1859  return m_evaluator.clear_symbol_regexp (pat);
1860 }
1861 
1862 std::list<std::string>
1864 {
1865  return m_evaluator.global_variable_names ();
1866 }
1867 
1868 std::list<std::string>
1870 {
1871  return m_evaluator.top_level_variable_names ();
1872 }
1873 
1874 std::list<std::string>
1876 {
1877  return m_evaluator.variable_names ();
1878 }
1879 
1880 std::list<std::string>
1882 {
1883  return m_symbol_table.user_function_names ();
1884 }
1885 
1886 std::list<std::string>
1888 {
1889  return m_evaluator.autoloaded_functions ();
1890 }
1891 
1892 // May be used to send an interrupt signal to the the interpreter from
1893 // another thread (for example, the GUI).
1894 
1895 void
1897 {
1898  static int sigint = 0;
1899  static bool first = true;
1900 
1901  if (first)
1902  {
1903  octave_get_sig_number ("SIGINT", &sigint);
1904  first = false;
1905  }
1906 
1907  // Send SIGINT to Octave and (optionally) all other processes in its
1908  // process group. The signal handler for SIGINT will set a global
1909  // variable indicating an interrupt has happened. That variable is
1910  // checked in many places in the Octave interpreter and eventually
1911  // results in an interrupt_exception being thrown. Finally, that
1912  // exception is caught and returns control to one of the
1913  // read-eval-print loops or to the server loop. We use a signal
1914  // instead of just setting the global variables here so that we will
1915  // probably send interrupt signals to any subprocesses as well as
1916  // interrupt execution of the interpreter.
1917 
1918  pid_t pid
1919  = m_interrupt_all_in_process_group ? 0 : octave_getpid_wrapper ();
1920 
1921  octave_kill_wrapper (pid, sigint);
1922 }
1923 
1924 void
1926 {
1927  // FIXME: To be reliable, these tree_evaluator functions must be
1928  // made thread safe.
1929 
1930  m_evaluator.break_on_next_statement (true);
1931  m_evaluator.reset_debug_state ();
1932 }
1933 
1934 void
1936 {
1937  // FIXME: To be reliable, these tree_evaluator functions must be
1938  // made thread safe.
1939 
1940  if (m_evaluator.in_debug_repl ())
1941  m_evaluator.dbquit (true);
1942  else
1943  interrupt ();
1944 }
1945 
1946 void
1948 {
1949  // FIXME: To be reliable, these tree_evaluator functions must be
1950  // made thread safe.
1951 
1952  // FIXME: Should there be any feeback about not doing anything if
1953  // not in debug mode?
1954 
1955  if (m_evaluator.in_debug_repl ())
1956  m_evaluator.dbcont ();
1957 }
1958 
1960 interpreter::PS1 (const octave_value_list& args, int nargout)
1961 {
1962  return m_input_system.PS1 (args, nargout);
1963 }
1964 
1965 std::string
1967 {
1968  return m_input_system.PS1 ();
1969 }
1970 
1971 std::string
1972 interpreter::PS1 (const std::string& s)
1973 {
1974  return m_input_system.PS1 (s);
1975 }
1976 
1977 void
1978 interpreter::set_PS1 (const std::string& s)
1979 {
1980  m_input_system.set_PS1 (s);
1981 }
1982 
1984 interpreter::PS2 (const octave_value_list& args, int nargout)
1985 {
1986  return m_input_system.PS2 (args, nargout);
1987 }
1988 
1989 std::string
1991 {
1992  return m_input_system.PS2 ();
1993 }
1994 
1995 std::string
1996 interpreter::PS2 (const std::string& s)
1997 {
1998  return m_input_system.PS2 (s);
1999 }
2000 
2001 void
2002 interpreter::set_PS2 (const std::string& s)
2003 {
2004  m_input_system.set_PS2 (s);
2005 }
2006 
2008 interpreter::PS4 (const octave_value_list& args, int nargout)
2009 {
2010  return m_evaluator.PS4 (args, nargout);
2011 }
2012 
2013 std::string
2015 {
2016  return m_evaluator.PS4 ();
2017 }
2018 
2019 std::string
2020 interpreter::PS4 (const std::string& s)
2021 {
2022  return m_evaluator.PS4 (s);
2023 }
2024 
2025 void
2026 interpreter::set_PS4 (const std::string& s)
2027 {
2028  m_evaluator.set_PS4 (s);
2029 }
2030 
2031 // Provided for convenience. Will be removed once we eliminate the
2032 // old terminal widget.
2033 bool
2035 {
2036  if (! m_app_context)
2037  return false;
2038 
2039  // Embedded interpreters don't execute command line options.
2040  const cmdline_options& options = m_app_context->options ();
2041 
2042  return options.experimental_terminal_widget ();
2043 }
2044 
2045 void
2047 {
2048  m_evaluator.add_debug_watch_expression (expr);
2049 }
2050 
2051 void
2053 {
2054  m_evaluator.remove_debug_watch_expression (expr);
2055 }
2056 
2057 void
2059 {
2060  m_evaluator.clear_debug_watch_expressions ();
2061 }
2062 
2063 std::set<std::string>
2065 {
2066  return m_evaluator.debug_watch_expressions ();
2067 }
2068 
2069 void
2071 {
2072  m_error_system.save_exception (ee);
2073 
2074  // FIXME: use a separate stream instead of std::cerr directly so that
2075  // error messages can be redirected more easily? Pass the message
2076  // to an event manager function?
2077  m_error_system.display_exception (ee);
2078 
2080 }
2081 
2082 void
2084 {
2086  m_event_manager.interpreter_interrupted ();
2087 
2088  can_interrupt = true;
2090  octave_signal_caught = false;
2092  catch_interrupts ();
2093 }
2094 
2095 void
2096 interpreter::mark_for_deletion (const std::string& file)
2097 {
2098  m_tmp_files.insert (file);
2099 }
2100 
2101 void
2103 {
2104  m_tmp_files.cleanup ();
2105 }
2106 
2107 void
2108 interpreter::quit (int exit_status, bool force, bool confirm)
2109 {
2110  if (! force)
2111  {
2112  try
2113  {
2114  bool cancel = false;
2115 
2116  if (symbol_exist ("finish.m", "file"))
2117  {
2118  unwind_protect_var<bool> upv1 (m_executing_finish_script, true);
2119  unwind_protect_var<bool> upv2 (m_cancel_quit);
2120 
2121  evalin ("base", "finish", 0);
2122 
2123  cancel = m_cancel_quit;
2124  }
2125 
2126  if (cancel)
2127  return;
2128 
2129  // Check for confirmation.
2130 
2131  if (confirm && ! m_event_manager.confirm_shutdown ())
2132  return;
2133  }
2134  catch (const execution_exception&)
2135  {
2136  // Catch execution_exceptions so we don't throw an
2137  // exit_exception if there is an in finish.m. But throw it
2138  // again so that will be handled as any other
2139  // execution_exception by the evaluator. This way, errors
2140  // will be ignored properly and we won't exit if quit is
2141  // called recursively from finish.m.
2142 
2143  throw;
2144  }
2145  }
2146 
2147  throw exit_exception (exit_status);
2148 }
2149 
2150 void
2151 interpreter::add_atexit_fcn (const std::string& fname)
2152 {
2153  if (m_executing_atexit)
2154  return;
2155 
2156  m_atexit_fcns.push_front (fname);
2157 }
2158 
2159 bool
2160 interpreter::remove_atexit_fcn (const std::string& fname)
2161 {
2162  bool found = false;
2163 
2164  for (auto it = m_atexit_fcns.begin ();
2165  it != m_atexit_fcns.end (); it++)
2166  {
2167  if (*it == fname)
2168  {
2169  m_atexit_fcns.erase (it);
2170  found = true;
2171  break;
2172  }
2173  }
2174 
2175  return found;
2176 }
2177 
2178 // What internal options get configured by --traditional.
2179 
2180 void
2181 interpreter::maximum_braindamage ()
2182 {
2183  PS1 (">> ");
2184  PS2 ("");
2185  PS4 ("");
2186 
2187  m_load_save_system.crash_dumps_octave_core (false);
2188  m_load_save_system.save_default_options ("-mat-binary");
2189 
2190  m_history_system.timestamp_format_string ("%%-- %D %I:%M %p --%%");
2191 
2192  m_error_system.beep_on_error (true);
2193 
2194  Fconfirm_recursive_rmdir (ovl (false));
2195  Foptimize_diagonal_matrix (ovl (false));
2197  Foptimize_range (ovl (false));
2198  Ffixed_point_format (ovl (true));
2199  Fprint_empty_dimensions (ovl (false));
2202 
2203  m_error_system.disable_warning ("Octave:abbreviated-property-match");
2204  m_error_system.disable_warning ("Octave:colon-nonscalar-argument");
2205  m_error_system.disable_warning ("Octave:data-file-in-path");
2206  m_error_system.disable_warning ("Octave:empty-index");
2207  m_error_system.disable_warning ("Octave:function-name-clash");
2208  m_error_system.disable_warning ("Octave:possible-matlab-short-circuit-operator");
2209 }
2210 
2211 void
2212 interpreter::execute_pkg_add (const std::string& dir)
2213 {
2214  try
2215  {
2216  m_load_path.execute_pkg_add (dir);
2217  }
2218  catch (const interrupt_exception&)
2219  {
2221  }
2222  catch (const execution_exception& ee)
2223  {
2224  handle_exception (ee);
2225  }
2226 }
2227 
2228 // Execute commands from a file and catch potential exceptions in a consistent
2229 // way. This function should be called anywhere we might parse and execute
2230 // commands from a file before we have entered the main loop in
2231 // toplev.cc.
2232 
2233 int
2234 interpreter::safe_source_file (const std::string& file_name,
2235  const std::string& context,
2236  bool verbose, bool require_file)
2237 {
2238  try
2239  {
2240  source_file (file_name, context, verbose, require_file);
2241  }
2242  catch (const interrupt_exception&)
2243  {
2245 
2246  return 1;
2247  }
2248  catch (const execution_exception& ee)
2249  {
2250  handle_exception (ee);
2251 
2252  return 1;
2253  }
2254 
2255  return 0;
2256 }
2257 
2258 OCTAVE_END_NAMESPACE(octave)
#define NaN
Definition: Faddeeva.cc:261
octave_value_list Fprint_empty_dimensions(const octave_value_list &=octave_value_list(), int=0)
Definition: pr-output.cc:4184
octave_value_list Fstruct_levels_to_print(const octave_value_list &=octave_value_list(), int=0)
Definition: ov-struct.cc:2268
octave_value_list Finfo_file(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Foptimize_diagonal_matrix(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Ffixed_point_format(const octave_value_list &=octave_value_list(), int=0)
Definition: pr-output.cc:4153
octave_value_list Foptimize_permutation_matrix(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fprint_struct_array_contents(const octave_value_list &=octave_value_list(), int=0)
Definition: ov-struct.cc:2292
octave_value_list Fdoc_cache_file(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Finfo_program(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fconfirm_recursive_rmdir(const octave_value_list &=octave_value_list(), int=0)
octave_value_list F__version_info__(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Ftexi_macros_file(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
octave_value_list Foptimize_range(const octave_value_list &=octave_value_list(), int=0)
octave_value_list Fbuilt_in_docstrings_file(octave::interpreter &, const octave_value_list &=octave_value_list(), int=0)
Definition: Cell.h:43
void set_program_names(const std::string &pname)
Definition: octave.cc:302
void forced_interactive(bool arg)
Definition: octave.h:295
void intern_argv(const string_vector &args)
Definition: octave.cc:312
bool have_eval_option_code() const
Definition: octave.h:263
cmdline_options options() const
Definition: octave.h:261
static std::string program_name()
Definition: octave.h:308
bool is_octave_program() const
Definition: octave.h:267
bool have_script_file() const
Definition: octave.h:265
static std::string program_invocation_name()
Definition: octave.h:303
bool line_editing() const
Definition: octave.h:65
bool forced_interactive() const
Definition: octave.h:60
bool experimental_terminal_widget() const
Definition: octave.h:58
std::string texi_macros_file() const
Definition: octave.h:85
bool inhibit_startup_message() const
Definition: octave.h:63
std::string doc_cache_file() const
Definition: octave.h:80
std::string image_path() const
Definition: octave.h:82
bool read_site_files() const
Definition: octave.h:71
string_vector remaining_args() const
Definition: octave.h:87
bool persist() const
Definition: octave.h:68
std::string info_program() const
Definition: octave.h:84
bool server() const
Definition: octave.h:72
bool read_history_file() const
Definition: octave.h:69
std::string exec_path() const
Definition: octave.h:81
bool no_window_system() const
Definition: octave.h:67
std::list< std::string > command_line_path() const
Definition: octave.h:77
std::string code_to_eval() const
Definition: octave.h:76
string_vector all_args() const
Definition: octave.h:86
std::string info_file() const
Definition: octave.h:83
bool verbose_flag() const
Definition: octave.h:75
std::string docstrings_file() const
Definition: octave.h:79
bool echo_commands() const
Definition: octave.h:56
bool gui() const
Definition: octave.h:62
bool traditional() const
Definition: octave.h:74
bool read_init_files() const
Definition: octave.h:70
bool set_initial_path() const
Definition: octave.h:73
bool forced_line_editing() const
Definition: octave.h:61
static void blink_matching_paren(bool flag)
Definition: cmd-edit.cc:1308
static void restore_terminal_state()
Definition: cmd-edit.cc:1301
static void add_event_hook(event_hook_fcn f)
Definition: cmd-edit.cc:1558
static bool ignoring_entries()
Definition: cmd-hist.cc:611
static void clean_up_and_save(const std::string &="", int=-1)
Definition: cmd-hist.cc:769
static void ignore_entries(bool=true)
Definition: cmd-hist.cc:604
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
void initialize()
Definition: display.cc:42
octave_value image_path(const octave_value_list &args, int nargout)
Definition: environment.cc:102
octave_value exec_path(const octave_value_list &args, int nargout)
Definition: environment.cc:81
octave_value beep_on_error(const octave_value_list &args, int nargout)
Definition: error.cc:307
void disable_warning(const std::string &id)
Definition: error.cc:841
void save_exception(const execution_exception &ee)
Definition: error.cc:912
void display_exception(const execution_exception &ee) const
Definition: error.cc:924
bool confirm_shutdown()
void process_events(bool disable=false)
void interpreter_interrupted()
void directory_changed(const std::string &dir)
void start_gui(bool gui_app=false)
void clear_workspace()
void unload_all_toolkits()
Definition: gtk-manager.h:103
void write_timestamp()
Definition: oct-hist.cc:281
octave_value timestamp_format_string(const octave_value_list &args, int nargout)
Definition: oct-hist.cc:307
void initialize(bool read_history_file=false)
Definition: oct-hist.cc:269
void initialize(bool line_editing)
void clear_input_event_hooks()
void set_PS2(const std::string &s)
Definition: input.h:91
void set_PS1(const std::string &s)
Definition: input.h:78
octave_value PS2(const octave_value_list &args, int nargout)
octave_value PS1(const octave_value_list &args, int nargout)
octave_value global_varval(const std::string &name) const
octave_value varval(const std::string &name) const
void clear_variable(const std::string &name)
octave_value make_function_handle(const std::string &name)
void assignin(const std::string &context, const std::string &varname, const octave_value &val=octave_value())
bool isglobal(const std::string &name) const
void quit(int exit_status, bool force=false, bool confirm=true)
void clear_global_variables()
std::list< std::string > autoloaded_functions() const
void global_assign(const std::string &name, const octave_value &val=octave_value())
void install_variable(const std::string &name, const octave_value &value, bool global)
void verbose(bool flag)
Definition: interpreter.h:185
void add_debug_watch_expression(const std::string &expr)
bool at_top_level() const
void read_site_files(bool flag)
Definition: interpreter.h:175
void add_atexit_fcn(const std::string &fname)
bool remove_atexit_fcn(const std::string &fname)
void initialize()
Definition: interpreter.cc:720
void clear_objects()
octave_value find(const std::string &name)
void mlock(bool skip_first=false) const
profiler & get_profiler()
void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
std::list< std::string > variable_names()
void top_level_assign(const std::string &name, const octave_value &val=octave_value())
std::set< std::string > debug_watch_expressions() const
octave_value_list eval(const std::string &try_code, int nargout)
std::string PS2() const
void interrupt()
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
std::string PS1() const
void clear_symbol_regexp(const std::string &pat)
void handle_exception(const execution_exception &ee)
bool experimental_terminal_widget() const
symbol_scope get_current_scope() const
void clear_symbol_pattern(const std::string &pat)
void clear_global_variable_regexp(const std::string &pattern)
void clear_global_variable(const std::string &name)
void set_PS1(const std::string &s)
int chdir(const std::string &dir)
std::list< std::string > user_function_names()
void clear_global_variable_pattern(const std::string &pattern)
void clear_function_regexp(const std::string &pat)
octave_value top_level_varval(const std::string &name) const
symbol_scope get_top_scope() const
void intern_nargin(octave_idx_type nargs)
Definition: interpreter.cc:646
void clear_variables()
void parse_and_execute(const std::string &input, bool &incomplete_parse)
Definition: interpreter.cc:813
bool is_variable(const std::string &name) const
interpreter(application *app_context=nullptr)
Definition: interpreter.cc:431
void clear_variable_regexp(const std::string &pattern)
bool interactive() const
Definition: interpreter.h:165
std::string PS4() const
bool mislocked(bool skip_first=false) const
tree_evaluator & get_evaluator()
void assign(const std::string &name, const octave_value &val=octave_value())
void initialize_history(bool read_history_file=false)
Definition: interpreter.cc:654
void clear_symbol(const std::string &name)
std::list< std::string > global_variable_names()
octave_value_list evalin(const std::string &context, const std::string &try_code, int nargout)
void cleanup_tmp_files()
std::string mfilename(const std::string &opt="") const
void initialize_load_path(bool set_initial_path=true)
Definition: interpreter.cc:683
void clear_debug_watch_expressions()
void inhibit_startup_message(bool flag)
Definition: interpreter.h:200
void clear_variable_pattern(const std::string &pattern)
void clear_function_pattern(const std::string &pat)
void read_init_files(bool flag)
Definition: interpreter.h:180
bool is_local_variable(const std::string &name) const
std::list< std::string > top_level_variable_names()
void munlock(bool skip_first=false) const
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
void get_line_and_eval()
Definition: interpreter.cc:774
url_handle_manager & get_url_handle_manager()
symbol_scope require_current_scope(const std::string &who) const
void clear_function(const std::string &name)
void remove_debug_watch_expression(const std::string &expr)
void recover_from_exception()
void clear_all(bool force=false)
void mark_for_deletion(const std::string &file)
void set_PS2(const std::string &s)
stream_list & get_stream_list()
void set_PS4(const std::string &s)
void clear_functions(bool force=false)
void set_add_hook(const std::function< void(const std::string &)> &f)
Definition: load-path.h:182
void initialize(bool set_initial_path=false)
Definition: load-path.cc:260
void read_dir_config(const std::string &dir) const
Definition: load-path.cc:1162
void execute_pkg_add(const std::string &dir)
Definition: load-path.cc:960
std::function< void(const std::string &)> get_add_hook()
Definition: load-path.h:172
void update()
Definition: load-path.cc:417
void set_command_line_path(const std::string &p)
Definition: load-path.h:197
octave_value save_default_options(const octave_value_list &args, int nargout)
Definition: load-save.cc:300
octave_value crash_dumps_octave_core(const octave_value_list &args, int nargout)
Definition: load-save.cc:276
bool islocked() const
Definition: ov-fcn.h:186
void unlock()
Definition: ov-fcn.h:180
virtual octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition: ov-fcn.cc:56
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:574
octave_idx_type nfields() const
Definition: oct-map.h:323
octave_idx_type length() const
Definition: oct-map.h:369
octave_idx_type numel() const
Definition: oct-map.h:368
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:344
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
Definition: ovl.h:131
octave_idx_type length() const
Definition: ovl.h:113
bool is_function_handle() const
Definition: ov.h:768
bool is_undefined() const
Definition: ov.h:595
bool is_inline_function() const
Definition: ov.h:774
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov.h:476
bool is_string() const
Definition: ov.h:637
bool is_defined() const
Definition: ov.h:592
bool is_function() const
Definition: ov.h:777
octave_function * function_value(bool silent=false) const
std::string string_value(bool force=false) const
Definition: ov.h:974
octave_idx_type numel() const
Definition: str-vec.h:100
void clear_function(const std::string &name)
Definition: symtab.cc:446
void clear_function_pattern(const std::string &pat)
Definition: symtab.cc:452
void clear_functions(bool force=false)
Definition: symtab.cc:437
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope::invalid())
Definition: symtab.cc:254
void clear_mex_functions()
Definition: symtab.cc:515
void cleanup()
Definition: symtab.cc:722
std::list< std::string > user_function_names()
Definition: symtab.cc:603
void clear_function_regexp(const std::string &pat)
Definition: symtab.cc:468
void insert(const std::string &file)
Definition: interpreter.cc:326
static void init()
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
Definition: pt-eval.cc:1022
std::set< std::string > debug_watch_expressions() const
Definition: pt-eval.h:693
bool is_global(const std::string &name) const
Definition: pt-eval.cc:1927
bool mislocked(bool skip_first=false) const
Definition: pt-eval.cc:2754
void clear_all(bool force=false)
Definition: pt-eval.cc:2871
void reset_debug_state()
Definition: pt-eval.cc:1378
void dbcont()
Definition: pt-eval.cc:5065
void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
Definition: pt-eval.cc:2042
symbol_scope get_current_scope() const
Definition: pt-eval.cc:2714
octave_value echo(const octave_value_list &args, int nargout)
Definition: pt-eval.cc:4930
void set_PS4(const std::string &s)
Definition: pt-eval.h:709
void clear_global_variables()
Definition: pt-eval.cc:2865
void clear_global_variable(const std::string &name)
Definition: pt-eval.cc:2847
bool break_on_next_statement() const
Definition: pt-eval.h:804
void munlock(bool skip_first=false) const
Definition: pt-eval.cc:2737
bool at_top_level() const
Definition: pt-eval.cc:538
octave_value find(const std::string &name)
Definition: pt-eval.cc:2777
std::list< std::string > variable_names() const
Definition: pt-eval.cc:2932
bool is_local_variable(const std::string &name) const
Definition: pt-eval.cc:1869
bool in_debug_repl() const
Definition: pt-eval.cc:5058
symbol_scope get_top_scope() const
Definition: pt-eval.cc:2708
void clear_symbol_pattern(const std::string &pattern)
Definition: pt-eval.cc:2896
void clear_symbol(const std::string &name)
Definition: pt-eval.cc:2884
void remove_debug_watch_expression(const std::string &expr)
Definition: pt-eval.h:679
void dbquit(bool all=false)
Definition: pt-eval.cc:5072
void clear_objects()
Definition: pt-eval.cc:2802
int server_loop()
Definition: pt-eval.cc:880
void clear_variable(const std::string &name)
Definition: pt-eval.cc:2811
bool is_variable(const std::string &name) const
Definition: pt-eval.cc:1860
void add_debug_watch_expression(const std::string &expr)
Definition: pt-eval.h:672
std::list< std::string > global_variable_names() const
Definition: pt-eval.cc:2920
void clear_global_variable_pattern(const std::string &pattern)
Definition: pt-eval.cc:2853
void assign(const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:1997
void assignin(const std::string &context, const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:2006
octave_value top_level_varval(const std::string &name) const
Definition: pt-eval.cc:1984
void clear_symbol_regexp(const std::string &pattern)
Definition: pt-eval.cc:2908
@ ECHO_FUNCTIONS
Definition: pt-eval.h:75
void get_line_and_eval()
Definition: pt-eval.cc:645
std::list< std::string > autoloaded_functions() const
Definition: pt-eval.cc:4670
void eval(std::shared_ptr< tree_statement_list > &stmt_list, bool interactive)
Definition: pt-eval.cc:989
octave_value_list evalin(const std::string &context, const std::string &try_code, int nargout)
Definition: pt-eval.cc:1176
octave_value global_varval(const std::string &name) const
Definition: pt-eval.cc:1965
void top_level_assign(const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:1990
void install_variable(const std::string &name, const octave_value &value, bool global)
Definition: pt-eval.cc:1954
void set_auto_fcn_var(stack_frame::auto_var_type avt, const octave_value &val=octave_value())
Definition: pt-eval.cc:2194
void clear_global_variable_regexp(const std::string &pattern)
Definition: pt-eval.cc:2859
void parse_and_execute(const std::string &input, bool &incomplete_parse)
Definition: pt-eval.cc:580
void clear_debug_watch_expressions()
Definition: pt-eval.h:686
std::list< std::string > top_level_variable_names() const
Definition: pt-eval.cc:2926
void global_assign(const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:1977
octave_value make_fcn_handle(const std::string &nm)
Definition: pt-eval.cc:1603
void mlock(bool skip_first=false) const
Definition: pt-eval.cc:2720
octave_value varval(const symbol_record &sym) const
Definition: pt-eval.cc:1936
octave_value PS4(const octave_value_list &args, int nargout)
Definition: pt-eval.cc:5176
std::string mfilename(const std::string &opt="") const
Definition: pt-eval.cc:544
void clear_variable_regexp(const std::string &pattern)
Definition: pt-eval.cc:2829
void clear_variable_pattern(const std::string &pattern)
Definition: pt-eval.cc:2820
void clear_variables()
Definition: pt-eval.cc:2838
profiler & get_profiler()
Definition: pt-eval.h:424
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string site_defaults_file()
std::string local_site_defaults_file()
std::string release()
void print_usage(void)
Definition: defun-int.h:72
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:111
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
Definition: defun.h:160
void warning(const char *fmt,...)
Definition: error.cc:1063
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:1078
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
Definition: error.cc:1042
void verror_with_cfn(const char *fmt, va_list args)
Definition: error.cc:1012
void() error(const char *fmt,...)
Definition: error.cc:988
std::string dir_sep_str()
void octave_set_default_fpucw(void)
octave::sys::time Vlast_prompt_time
Definition: input.cc:83
#define OCTAVE_SAFE_CALL(F, ARGS)
Definition: interpreter.cc:925
bool octave_interpreter_ready
Definition: interpreter.cc:92
std::atomic< bool > octave_initialized
Definition: interpreter.cc:95
bool quit_allowed
Definition: interpreter.cc:88
sys::time Vlast_chdir_time
void set_liboctave_error_handler(OCTAVE_NORETURN liboctave_error_handler f)
Definition: lo-error.c:67
void set_liboctave_warning_handler(liboctave_warning_handler f)
Definition: lo-error.c:86
void set_liboctave_error_with_id_handler(OCTAVE_NORETURN liboctave_error_with_id_handler f)
Definition: lo-error.c:76
void set_liboctave_warning_with_id_handler(liboctave_warning_with_id_handler f)
Definition: lo-error.c:95
void octave_ieee_init()
Definition: lo-ieee.cc:124
bool file_exists(const std::string &filename, bool is_dir)
Definition: lo-sysdep.cc:341
int chdir(const std::string &path_arg)
Definition: lo-sysdep.cc:107
bool same_file(const std::string &file1, const std::string &file2)
Definition: lo-sysdep.cc:437
#define OCTAVE_VERSION
Definition: main.cc:63
octave_idx_type n
Definition: mx-inlines.cc:761
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:289
int release_unreferenced_dynamic_libraries()
Definition: oct-shlib.cc:72
T::size_type numel(const T &str)
Definition: oct-string.cc:74
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:219
void flush_stdout()
std::atomic< sig_atomic_t > octave_interrupt_state
Definition: quit.cc:39
void(* octave_interrupt_hook)()
Definition: quit.cc:44
void(* octave_signal_hook)()
Definition: quit.cc:43
volatile std::atomic< bool > octave_signal_caught
Definition: quit.cc:41
void respond_to_pending_signals()
Definition: sighandlers.cc:111
std::atomic< bool > can_interrupt
Definition: sighandlers.cc:69
interrupt_handler catch_interrupts()
Definition: sighandlers.cc:327
void install_signal_handlers()
Definition: sighandlers.cc:366
void octave_save_signal_mask(void)
void octave_unblock_signal_by_name(const char *signame)
bool octave_get_sig_number(const char *signame, int *signum)
int octave_kill_wrapper(pid_t pid, int signum)
void octave_restore_signal_mask(void)
void sysdep_cleanup()
pid_t octave_getpid_wrapper(void)
int octave_unlink_wrapper(const char *nm)
int octave_isatty_wrapper(int fd)
std::string file_in_path(const std::string &, const std::string &)
int symbol_exist(const std::string &name, const std::string &type="any")
std::string octave_startup_message(bool html)
Definition: version.cc:118
#define OCTAVE_RELEASE_DATE
Definition: version.h:51
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DEF(s_arg
void octave_set_xerbla_handler(xerbla_handler_fptr fcn)
Definition: xerbla.cc:52