GNU Octave  6.2.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-2021 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 
32 #include <set>
33 #include <string>
34 #include <iostream>
35 
36 #include "cmd-edit.h"
37 #include "cmd-hist.h"
38 #include "file-ops.h"
39 #include "file-stat.h"
40 #include "file-ops.h"
41 #include "fpucw-wrappers.h"
42 #include "lo-blas-proto.h"
43 #include "lo-error.h"
44 #include "oct-env.h"
45 #include "str-vec.h"
46 #include "signal-wrappers.h"
47 #include "unistd-wrappers.h"
48 
49 #include "builtin-defun-decls.h"
50 #include "defaults.h"
51 #include "Cell.h"
52 #include "defun.h"
53 #include "display.h"
54 #include "error.h"
55 #include "event-manager.h"
56 #include "file-io.h"
57 #include "graphics.h"
58 #include "help.h"
59 #include "input.h"
60 #include "interpreter-private.h"
61 #include "interpreter.h"
62 #include "load-path.h"
63 #include "load-save.h"
64 #include "octave.h"
65 #include "oct-hist.h"
66 #include "oct-map.h"
67 #include "oct-mutex.h"
68 #include "ovl.h"
69 #include "ov.h"
70 #include "ov-classdef.h"
71 #include "parse.h"
72 #include "pt-classdef.h"
73 #include "pt-eval.h"
74 #include "pt-jump.h"
75 #include "pt-stmt.h"
76 #include "settings.h"
77 #include "sighandlers.h"
78 #include "sysdep.h"
79 #include "unwind-prot.h"
80 #include "utils.h"
81 #include "variables.h"
82 #include "version.h"
83 
84 // TRUE means the quit() call is allowed.
85 bool quit_allowed = true;
86 
87 // TRUE means we are ready to interpret commands, but not everything
88 // is ready for interactive use.
90 
91 // TRUE means we've processed all the init code and we are good to go.
92 bool octave_initialized = false;
93 
94 DEFUN (__version_info__, args, ,
95  doc: /* -*- texinfo -*-
96 @deftypefn {} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})
97 Undocumented internal function.
98 @end deftypefn */)
99 {
100  static octave_map vinfo;
101 
102  int nargin = args.length ();
103 
104  if (nargin != 0 && nargin != 4)
105  print_usage ();
106 
108 
109  if (nargin == 0)
110  retval = vinfo;
111  else if (nargin == 4)
112  {
113  if (vinfo.nfields () == 0)
114  {
115  vinfo.assign ("Name", args(0));
116  vinfo.assign ("Version", args(1));
117  vinfo.assign ("Release", args(2));
118  vinfo.assign ("Date", args(3));
119  }
120  else
121  {
122  octave_idx_type n = vinfo.numel () + 1;
123 
124  vinfo.resize (dim_vector (n, 1));
125 
126  octave_value idx (n);
127 
128  vinfo.assign (idx, "Name", Cell (octave_value (args(0))));
129  vinfo.assign (idx, "Version", Cell (octave_value (args(1))));
130  vinfo.assign (idx, "Release", Cell (octave_value (args(2))));
131  vinfo.assign (idx, "Date", Cell (octave_value (args(3))));
132  }
133  }
134 
135  return retval;
136 }
137 
138 DEFMETHOD (quit, interp, args, ,
139  doc: /* -*- texinfo -*-
140 @deftypefn {} {} quit
141 @deftypefnx {} {} quit cancel
142 @deftypefnx {} {} quit force
143 @deftypefnx {} {} quit ("cancel")
144 @deftypefnx {} {} quit ("force")
145 @deftypefnx {} {} quit (@var{status})
146 @deftypefnx {} {} quit (@var{status}, "force")
147 Quit the current Octave session.
148 
149 The @code{exit} function is an alias for @code{quit}.
150 
151 If the optional integer value @var{status} is supplied, pass that value to
152 the operating system as Octave's exit status. The default value is zero.
153 
154 When exiting, Octave will attempt to run the m-file @file{finish.m} if it
155 exists. User commands to save the workspace or clean up temporary files
156 may be placed in that file. Alternatively, another m-file may be scheduled
157 to run using @code{atexit}. If an error occurs while executing the
158 @file{finish.m} file, Octave does not exit and control is returned to
159 the command prompt.
160 
161 If the optional argument @qcode{"cancel"} is provided, Octave does not
162 exit and control is returned to the command prompt. This feature allows
163 the @code{finish.m} file to cancel the quit process.
164 
165 If the user preference to request confirmation before exiting, Octave
166 will display a dialog and give the user an option to cancel the exit
167 process.
168 
169 If the optional argument @qcode{"force"} is provided, no confirmation is
170 requested, and the execution of the @file{finish.m} file is skipped.
171 @seealso{atexit}
172 @end deftypefn */)
173 {
174  int numel = args.length ();
175 
176  if (numel > 2)
177  print_usage ();
178 
179  int exit_status = 0;
180 
181  bool force = false;
182  bool cancel = false;
183 
184  if (numel == 2)
185  {
186  exit_status = args(0).xnint_value ("quit: STATUS must be an integer");
187  std::string frc
188  = args(1).xstring_value ("quit: second argument must be a string");
189 
190  if (frc == "force")
191  force = true;
192  else
193  error (R"(quit: second argument must be string "force")");
194  }
195  else if (numel == 1)
196  {
197  if (args(0).is_string ())
198  {
199  const char *msg
200  = R"(quit: option must be string "cancel" or "force")";
201 
202  std::string opt = args(0).xstring_value (msg);
203 
204  if (opt == "cancel")
205  cancel = true;
206  else if (opt == "force")
207  force = true;
208  else
209  error ("%s", msg);
210  }
211  else
212  exit_status = args(0).xnint_value ("quit: STATUS must be an integer");
213  }
214 
215  if (cancel)
216  {
217  // No effect if "quit cancel" appears outside of finish script.
218 
219  if (interp.executing_finish_script ())
220  interp.cancel_quit (true);
221 
222  return ovl ();
223  }
224 
225  interp.quit (exit_status, force);
226 
227  return ovl ();
228 }
229 
230 DEFALIAS (exit, quit);
231 
232 DEFMETHOD (atexit, interp, args, nargout,
233  doc: /* -*- texinfo -*-
234 @deftypefn {} {} atexit (@var{fcn})
235 @deftypefnx {} {} atexit (@var{fcn}, @var{flag})
236 Register a function to be called when Octave exits.
237 
238 For example,
239 
240 @example
241 @group
242 function last_words ()
243  disp ("Bye bye");
244 endfunction
245 atexit ("last_words");
246 @end group
247 @end example
248 
249 @noindent
250 will print the message @qcode{"Bye bye"} when Octave exits.
251 
252 The additional argument @var{flag} will register or unregister @var{fcn}
253 from the list of functions to be called when Octave exits. If @var{flag} is
254 true, the function is registered, and if @var{flag} is false, it is
255 unregistered. For example, after registering the function @code{last_words}
256 above,
257 
258 @example
259 atexit ("last_words", false);
260 @end example
261 
262 @noindent
263 will remove the function from the list and Octave will not call
264 @code{last_words} when it exits.
265 
266 Note that @code{atexit} only removes the first occurrence of a function
267 from the list, so if a function was placed in the list multiple times with
268 @code{atexit}, it must also be removed from the list multiple times.
269 @seealso{quit}
270 @end deftypefn */)
271 {
272  int nargin = args.length ();
273 
274  if (nargin < 1 || nargin > 2)
275  print_usage ();
276 
277  std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string");
278 
279  bool add_mode = (nargin == 2)
280  ? args(1).xbool_value ("atexit: FLAG argument must be a logical value")
281  : true;
282 
284 
285  if (add_mode)
286  interp.add_atexit_fcn (arg);
287  else
288  {
289  bool found = interp.remove_atexit_fcn (arg);
290 
291  if (nargout > 0)
292  retval = ovl (found);
293  }
294 
295  return retval;
296 }
297 
298 namespace octave
299 {
301  {
302  cleanup ();
303  }
304 
305  void temporary_file_list::insert (const std::string& file)
306  {
307  m_files.insert (file);
308  }
309 
311  {
312  while (! m_files.empty ())
313  {
314  auto it = m_files.begin ();
315 
316  octave_unlink_wrapper (it->c_str ());
317 
318  m_files.erase (it);
319  }
320  }
321 
322  // The time we last time we changed directories.
324 
325  // Execute commands from a file and catch potential exceptions in a consistent
326  // way. This function should be called anywhere we might parse and execute
327  // commands from a file before we have entered the main loop in
328  // toplev.cc.
329 
330  static int safe_source_file (const std::string& file_name,
331  const std::string& context = "",
332  bool verbose = false,
333  bool require_file = true)
334  {
335  interpreter& interp = __get_interpreter__ ("safe_source_file");
336 
337  try
338  {
339  source_file (file_name, context, verbose, require_file);
340  }
341  catch (const interrupt_exception&)
342  {
343  interp.recover_from_exception ();
344 
345  return 1;
346  }
347  catch (const execution_exception& e)
348  {
349  interp.handle_exception (e);
350 
351  return 1;
352  }
353 
354  return 0;
355  }
356 
357  static void initialize_version_info (void)
358  {
359  octave_value_list args;
360 
361  args(3) = OCTAVE_RELEASE_DATE;
362  args(2) = config::release ();
363  args(1) = OCTAVE_VERSION;
364  args(0) = "GNU Octave";
365 
366  F__version_info__ (args, 0);
367  }
368 
369  static void xerbla_abort (void)
370  {
371  error ("Fortran procedure terminated by call to XERBLA");
372  }
373 
375  {
376  // The idea here is to force xerbla to be referenced so that we will
377  // link to our own version instead of the one provided by the BLAS
378  // library. But numeric_limits<double>::NaN () should never be -1, so
379  // we should never actually call xerbla. FIXME (again!): If this
380  // becomes a constant expression the test might be optimized away and
381  // then the reference to the function might also disappear.
382 
383  if (numeric_limits<double>::NaN () == -1)
384  F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6));
385 
386  typedef void (*xerbla_handler_ptr) (void);
387 
388  typedef void (*octave_set_xerbla_handler_ptr) (xerbla_handler_ptr);
389 
390  dynamic_library libs ("");
391 
392  if (libs)
393  {
394  octave_set_xerbla_handler_ptr octave_set_xerbla_handler
395  = reinterpret_cast<octave_set_xerbla_handler_ptr>
396  (libs.search ("octave_set_xerbla_handler"));
397 
400  }
401  }
402 
403  OCTAVE_NORETURN static void
404  lo_error_handler (const char *fmt, ...)
405  {
406  va_list args;
407  va_start (args, fmt);
408  verror_with_cfn (fmt, args);
409  va_end (args);
410 
411  throw execution_exception ();
412  }
413 
414  OCTAVE_NORETURN static void
415  lo_error_with_id_handler (const char *id, const char *fmt, ...)
416  {
417  va_list args;
418  va_start (args, fmt);
419  verror_with_id_cfn (id, fmt, args);
420  va_end (args);
421 
422  throw execution_exception ();
423  }
424 
425  static void initialize_error_handlers (void)
426  {
431  }
432 
433  // Create an interpreter object and perform initialization up to the
434  // point of setting reading command history and setting the load
435  // path.
436 
438  : m_app_context (app_context),
439  m_tmp_files (),
440  m_atexit_fcns (),
441  m_display_info (),
442  m_environment (),
443  m_settings (),
444  m_error_system (*this),
445  m_help_system (*this),
446  m_input_system (*this),
447  m_output_system (*this),
448  m_history_system (*this),
449  m_dynamic_loader (*this),
450  m_load_path (*this),
451  m_load_save_system (*this),
452  m_type_info (),
453  m_symbol_table (*this),
454  m_evaluator (*this),
455  m_stream_list (*this),
456  m_child_list (),
457  m_url_handle_manager (),
458  m_cdef_manager (*this),
459  m_gtk_manager (),
460  m_event_manager (*this),
461  m_gh_manager (nullptr),
462  m_interactive (false),
463  m_read_site_files (true),
464  m_read_init_files (m_app_context != nullptr),
465  m_verbose (false),
466  m_inhibit_startup_message (false),
467  m_load_path_initialized (false),
468  m_history_initialized (false),
469  m_in_top_level_repl (false),
470  m_cancel_quit (false),
471  m_executing_finish_script (false),
472  m_executing_atexit (false),
473  m_initialized (false)
474  {
475  // FIXME: When thread_local storage is used by default, this message
476  // should change to say something like
477  //
478  // only one Octave interpreter may be active in any given thread
479 
480  if (instance)
481  throw std::runtime_error
482  ("only one Octave interpreter may be active");
483 
484  instance = this;
485 
486  // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting
487  setlocale (LC_ALL, "");
488  setlocale (LC_NUMERIC, "C");
489  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 
501 
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)
514 
515  bool line_editing = false;
516  bool traditional = false;
517 
518  if (m_app_context)
519  {
520  // Embedded interpreters don't execute command line options.
521  const cmdline_options& options = m_app_context->options ();
522 
523  // Make all command-line arguments available to startup files,
524  // including PKG_ADD files.
525 
526  string_vector args = options.all_args ();
527 
528  m_app_context->intern_argv (args);
529  intern_nargin (args.numel () - 1);
530 
531  bool is_octave_program = m_app_context->is_octave_program ();
532 
533  std::list<std::string> command_line_path = options.command_line_path ();
534 
535  for (const auto& pth : command_line_path)
537 
538  std::string exec_path = options.exec_path ();
539  if (! exec_path.empty ())
540  m_environment.exec_path (exec_path);
541 
542  std::string image_path = options.image_path ();
543  if (! image_path.empty ())
544  m_environment.image_path (image_path);
545 
546  if (! options.no_window_system ())
548 
549  // Is input coming from a terminal? If so, we are probably
550  // interactive.
551 
552  // If stdin is not a tty, then we are reading commands from a
553  // pipe or a redirected file.
554  bool stdin_is_tty = octave_isatty_wrapper (fileno (stdin));
555 
556  m_interactive = (! is_octave_program && stdin_is_tty
557  && octave_isatty_wrapper (fileno (stdout)));
558 
559  // Check if the user forced an interactive session.
560  if (options.forced_interactive ())
561  m_interactive = true;
562 
563  line_editing = options.line_editing ();
564  if ((! m_interactive || options.forced_interactive ())
565  && ! options.forced_line_editing ())
566  line_editing = false;
567 
568  traditional = options.traditional ();
569 
570  // FIXME: if possible, perform the following actions directly
571  // instead of using the interpreter-level functions.
572 
573  if (options.echo_commands ())
577 
578  std::string docstrings_file = options.docstrings_file ();
579  if (! docstrings_file.empty ())
580  Fbuilt_in_docstrings_file (*this, octave_value (docstrings_file));
581 
582  std::string doc_cache_file = options.doc_cache_file ();
583  if (! doc_cache_file.empty ())
584  Fdoc_cache_file (*this, octave_value (doc_cache_file));
585 
586  std::string info_file = options.info_file ();
587  if (! info_file.empty ())
588  Finfo_file (*this, octave_value (info_file));
589 
590  std::string info_program = options.info_program ();
591  if (! info_program.empty ())
592  Finfo_program (*this, octave_value (info_program));
593 
594  if (options.debug_jit ())
595  Fdebug_jit (octave_value (true));
596 
597  if (options.jit_compiler ())
598  Fjit_enable (octave_value (true));
599 
600  std::string texi_macros_file = options.texi_macros_file ();
601  if (! texi_macros_file.empty ())
602  Ftexi_macros_file (*this, octave_value (texi_macros_file));
603  }
604 
605  // FIXME: we defer creation of the gh_manager object because it
606  // creates a root_figure object that requires the display_info
607  // object, but that is currently only accessible through the global
608  // interpreter object and that is not available until after the
609  // interpreter::instance pointer is set (above). It would be better
610  // if m_gh_manager could be an object value instead of a pointer and
611  // created as part of the interpreter initialization. To do that,
612  // we should either make the display_info object independent of the
613  // interpreter object (does it really need to cache any
614  // information?) or defer creation of the root_figure object until
615  // it is actually needed.
616  m_gh_manager = new gh_manager (*this);
617 
618  m_input_system.initialize (line_editing);
619 
620  // These can come after command line args since none of them set any
621  // defaults that might be changed by command line options.
622 
624 
625  // This should be done before initializing the load path because
626  // some PKG_ADD files might need --traditional behavior.
627 
628  if (traditional)
630 
632  }
633 
634  OCTAVE_THREAD_LOCAL interpreter *interpreter::instance = nullptr;
635 
637  {
638  delete m_gh_manager;
639  }
640 
642  {
644  }
645 
646  // Read the history file unless a command-line option inhibits that.
647 
648  void interpreter::initialize_history (bool read_history_file)
649  {
650  if (! m_history_initialized)
651  {
652  // Allow command-line option to override.
653 
654  if (m_app_context)
655  {
656  const cmdline_options& options = m_app_context->options ();
657 
658  read_history_file = options.read_history_file ();
659 
660  if (! read_history_file)
662  }
663 
664  m_history_system.initialize (read_history_file);
665 
666  if (! m_app_context)
668 
669  m_history_initialized = true;
670  }
671  }
672 
673  // Set the initial path to the system default unless command-line
674  // option says to leave it empty.
675 
676  void interpreter::initialize_load_path (bool set_initial_path)
677  {
679  {
680  // Allow command-line option to override.
681 
682  if (m_app_context)
683  {
684  const cmdline_options& options = m_app_context->options ();
685 
686  set_initial_path = options.set_initial_path ();
687  }
688 
689  // Temporarily set the execute_pkg_add function to one that
690  // catches exceptions. This is better than wrapping
691  // load_path::initialize in a try-catch block because it will
692  // not stop executing PKG_ADD files at the first exception.
693  // It's also better than changing the default execute_pkg_add
694  // function to use safe_source file because that will normally
695  // be evaluated from the normal interpreter loop where exceptions
696  // are already handled.
697 
698  unwind_protect frame;
699 
702 
703  m_load_path.set_add_hook ([this] (const std::string& dir)
704  { this->execute_pkg_add (dir); });
705 
706  m_load_path.initialize (set_initial_path);
707 
709  }
710  }
711 
712  // This may be called separately from execute
713 
715  {
716  if (m_initialized)
717  return;
718 
720 
721  // Wait to read the history file until the interpreter reads input
722  // files and begins evaluating commands.
723 
725 
726  // Initializing the load path may execute PKG_ADD files, so can't be
727  // done until the interpreter is ready to execute commands.
728 
729  // Deferring it to the execute step also allows the path to be
730  // initialized between creating and execute the interpreter, for
731  // example, to set a custom path for an embedded interpreter.
732 
734 
736 
737  can_interrupt = true;
738 
740  octave_interrupt_hook = nullptr;
741 
742  catch_interrupts ();
743 
744  // FIXME: could we eliminate this variable or make it not be global?
745  // Global used to communicate with signal handler.
746  octave_initialized = true;
747 
748  m_initialized = true;
749  }
750 
751  // FIXME: this function is intended to be executed only once. Should
752  // we enforce that restriction?
753 
755  {
756  int exit_status = 0;
757 
758  try
759  {
760  initialize ();
761 
763 
764  if (m_app_context)
765  {
766  const cmdline_options& options = m_app_context->options ();
767 
769  {
770  int status = execute_eval_option_code ();
771 
772  if (status )
773  exit_status = status;
774 
775  if (! options.persist ())
776  return exit_status;
777  }
778 
779  // If there is an extra argument, see if it names a file to
780  // read. Additional arguments are taken as command line options
781  // for the script.
782 
784  {
785  int status = execute_command_line_file ();
786 
787  if (status)
788  exit_status = status;
789 
790  if (! options.persist ())
791  return exit_status;
792  }
793 
794  if (options.forced_interactive ())
796 
797  exit_status = main_loop ();
798  }
799  }
800  catch (const exit_exception& ex)
801  {
802  return ex.exit_status ();
803  }
804 
805  return exit_status;
806  }
807 
808  // Call a function with exceptions handled to avoid problems with
809  // errors while shutting down.
810 
811 #define OCTAVE_IGNORE_EXCEPTION(E) \
812  catch (E) \
813  { \
814  recover_from_exception (); \
815  \
816  std::cerr << "error: ignoring " #E " while preparing to exit" \
817  << std::endl; \
818  }
819 
820 #define OCTAVE_SAFE_CALL(F, ARGS) \
821  do \
822  { \
823  try \
824  { \
825  unwind_protect frame; \
826  \
827  frame.add_method (m_error_system, \
828  &error_system::set_debug_on_error, \
829  m_error_system.debug_on_error ()); \
830  frame.add_method (m_error_system, \
831  &error_system::set_debug_on_warning, \
832  m_error_system.debug_on_warning ()); \
833  \
834  m_error_system.debug_on_error (false); \
835  m_error_system.debug_on_warning (false); \
836  \
837  F ARGS; \
838  } \
839  OCTAVE_IGNORE_EXCEPTION (const exit_exception&) \
840  OCTAVE_IGNORE_EXCEPTION (const interrupt_exception&) \
841  OCTAVE_IGNORE_EXCEPTION (const execution_exception&) \
842  OCTAVE_IGNORE_EXCEPTION (const std::bad_alloc&) \
843  } \
844  while (0)
845 
847  {
848  OCTAVE_SAFE_CALL (feval, ("close", ovl ("all"), 0));
849 
850  // If we are attached to a GUI, process pending events and
851  // disable the link.
852 
855 
857 
858  // Any atexit functions added after this function call won't be
859  // executed. Each atexit function is executed with
860  // OCTAVE_SAFE_CALL, so we don't need that here.
861 
863 
864  // Clear all functions and variables.
865 
866  // Note that we don't force symbols to be cleared, so we will
867  // respect mlock at this point. Later, we'll force all variables
868  // and functions to be cleared.
869 
871 
872  // We may still have some figures. Close them.
873 
874  OCTAVE_SAFE_CALL (feval, ("close", ovl ("all"), 0));
875 
876  // What is supposed to happen if a figure has a closerequestfcn or
877  // deletefcn callback registered that creates other figures or
878  // variables? What if those variables are classdef objects with
879  // destructors that can create figures? The possibilities are
880  // endless. At some point, we have to give up and force execution
881  // to end.
882 
883  // Note that we again don't force symbols to be cleared, so we
884  // continue to respect mlock here. Later, we'll force all variables
885  // and functions to be cleared.
886 
888 
889  // Do this explicitly so that destructors for mex file objects
890  // are called, so that functions registered with mexAtExit are
891  // called.
892 
894 
896 
898 
901 
903 
904  // Now that the graphics toolkits have been unloaded, force all
905  // symbols to be cleared.
906 
907  OCTAVE_SAFE_CALL (clear_all, (true));
908 
909  // FIXME: May still need something like this to ensure that
910  // destructors for class objects will run properly. Should that be
911  // done earlier? Before or after atexit functions are executed?
912  // What will happen if the destructor for an obect attempts to
913  // display a figure?
914 
916 
918 
920 
921  // Don't call singleton_cleanup_list::cleanup until we have the
922  // problems with registering/unregistering types worked out. For
923  // example, uncomment the following line, then use the make_int
924  // function from the examples directory to create an integer
925  // object and then exit Octave. Octave should crash with a
926  // segfault when cleaning up the typinfo singleton. We need some
927  // way to force new octave_value_X types that are created in
928  // .oct files to be unregistered when the .oct file shared library
929  // is unloaded.
930  //
931  // OCTAVE_SAFE_CALL (singleton_cleanup_list::cleanup, ());
932  }
933 
935  {
936  // Prevent atexit functions from adding new functions to the list.
937  m_executing_atexit = true;
938 
939  while (! m_atexit_fcns.empty ())
940  {
941  std::string fcn = m_atexit_fcns.front ();
942 
943  m_atexit_fcns.pop_front ();
944 
945  OCTAVE_SAFE_CALL (feval, (fcn, octave_value_list (), 0));
946 
948  }
949  }
950 
952  {
953  bool inhibit_startup_message = false;
954 
955  if (m_app_context)
956  {
957  const cmdline_options& options = m_app_context->options ();
958 
960  }
961 
963  std::cout << octave_startup_message () << "\n" << std::endl;
964  }
965 
966  // Initialize by reading startup files. Return non-zero if an exception
967  // occurs when reading any of them, but don't exit early because of an
968  // exception.
969 
971  {
974  bool verbose = m_verbose;
976 
977  if (m_app_context)
978  {
979  const cmdline_options& options = m_app_context->options ();
980 
981  read_site_files = options.read_site_files ();
982  read_init_files = options.read_init_files ();
983  verbose = options.verbose_flag ();
985  }
986 
988 
989  bool require_file = false;
990 
991  std::string context;
992 
993  int exit_status = 0;
994 
995  if (read_site_files)
996  {
997  // Execute commands from the site-wide configuration file.
998  // First from the file $(prefix)/lib/octave/site/m/octaverc
999  // (if it exists), then from the file
1000  // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
1001 
1003  context, verbose, require_file);
1004 
1005  if (status)
1006  exit_status = status;
1007 
1009  context, verbose, require_file);
1010 
1011  if (status)
1012  exit_status = status;
1013  }
1014 
1015  if (read_init_files)
1016  {
1017  // Try to execute commands from the Matlab compatible startup.m file
1018  // if it exists anywhere in the load path when starting Octave.
1019  std::string ff_startup_m = file_in_path ("startup.m", "");
1020 
1021  if (! ff_startup_m.empty ())
1022  {
1023  int parse_status = 0;
1024 
1025  try
1026  {
1027  eval_string (std::string ("startup"), false, parse_status, 0);
1028  }
1029  catch (const interrupt_exception&)
1030  {
1032  }
1033  catch (const execution_exception& e)
1034  {
1035  handle_exception (e);
1036  }
1037  }
1038 
1039  // Try to execute commands from $CONFIG/octave/octaverc, where
1040  // $CONFIG is the platform-dependent location for user local
1041  // configuration files.
1042 
1043  std::string user_config_dir = sys::env::get_user_config_directory ();
1044 
1045  std::string cfg_dir = user_config_dir + sys::file_ops::dir_sep_str ()
1046  + "octave";
1047 
1048  std::string cfg_rc = sys::env::make_absolute ("octaverc", cfg_dir);
1049 
1050  if (! cfg_rc.empty ())
1051  {
1052  int status = safe_source_file (cfg_rc, context, verbose,
1053  require_file);
1054 
1055  if (status)
1056  exit_status = status;
1057  }
1058 
1059  // Try to execute commands from $HOME/$OCTAVE_INITFILE and
1060  // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
1061  // .octaverc is assumed.
1062 
1063  bool home_rc_already_executed = false;
1064 
1065  std::string initfile = sys::env::getenv ("OCTAVE_INITFILE");
1066 
1067  if (initfile.empty ())
1068  initfile = ".octaverc";
1069 
1070  std::string home_dir = sys::env::get_home_directory ();
1071 
1072  std::string home_rc = sys::env::make_absolute (initfile, home_dir);
1073 
1074  std::string local_rc;
1075 
1076  if (! home_rc.empty ())
1077  {
1078  int status = safe_source_file (home_rc, context, verbose,
1079  require_file);
1080 
1081  if (status)
1082  exit_status = status;
1083 
1084  // Names alone are not enough.
1085 
1086  sys::file_stat fs_home_rc (home_rc);
1087 
1088  if (fs_home_rc)
1089  {
1090  // We want to check for curr_dir after executing home_rc
1091  // because doing that may change the working directory.
1092 
1093  local_rc = sys::env::make_absolute (initfile);
1094 
1095  home_rc_already_executed = same_file (home_rc, local_rc);
1096  }
1097  }
1098 
1099  if (! home_rc_already_executed)
1100  {
1101  if (local_rc.empty ())
1102  local_rc = sys::env::make_absolute (initfile);
1103 
1104  int status = safe_source_file (local_rc, context, verbose,
1105  require_file);
1106 
1107  if (status)
1108  exit_status = status;
1109  }
1110  }
1111 
1112  if (m_interactive && verbose)
1113  std::cout << std::endl;
1114 
1115  return exit_status;
1116  }
1117 
1118  // Execute any code specified with --eval 'CODE'
1119 
1121  {
1122  if (! m_app_context)
1123  return 0;
1124 
1125  const cmdline_options& options = m_app_context->options ();
1126 
1127  std::string code_to_eval = options.code_to_eval ();
1128 
1130 
1131  int parse_status = 0;
1132 
1133  try
1134  {
1135  eval_string (code_to_eval, false, parse_status, 0);
1136  }
1137  catch (const interrupt_exception&)
1138  {
1140 
1141  return 1;
1142  }
1143  catch (const execution_exception& e)
1144  {
1145  handle_exception (e);
1146 
1147  return 1;
1148  }
1149 
1150  return parse_status;
1151  }
1152 
1154  {
1155  if (! m_app_context)
1156  return 0;
1157 
1158  const cmdline_options& options = m_app_context->options ();
1159 
1160  unwind_protect frame;
1161 
1163 
1164  string_vector args = options.all_args ();
1165 
1167 
1168  frame.add_method (this, &interpreter::intern_nargin, args.numel () - 1);
1169 
1170  frame.add_method (m_app_context,
1173 
1174  frame.add_method (m_app_context,
1177 
1178  m_interactive = false;
1179 
1180  // If we are running an executable script (#! /bin/octave) then
1181  // we should only see the args passed to the script.
1182 
1183  string_vector script_args = options.remaining_args ();
1184 
1185  m_app_context->intern_argv (script_args);
1186  intern_nargin (script_args.numel () - 1);
1187 
1188  std::string fname = script_args[0];
1189 
1191 
1192  std::string context;
1193  bool verbose = false;
1194  bool require_file = true;
1195 
1196  return safe_source_file (fname, context, verbose, require_file);
1197  }
1198 
1200  {
1201  // The big loop. Read, Eval, Print, Loop. Normally user
1202  // interaction at the command line in a terminal session, but we may
1203  // also end up here when reading from a pipe or when stdin is
1204  // connected to a file by the magic of input redirection.
1205 
1206  int exit_status = 0;
1207 
1208  // FIXME: should this choice be a command-line option? Note that we
1209  // intend that the push parser interface only be used for
1210  // interactive sessions.
1211 
1212 #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
1213  static bool use_command_line_push_parser = true;
1214 #else
1215  static bool use_command_line_push_parser = false;
1216 #endif
1217 
1218  // The following logic is written as it is to allow easy transition
1219  // to setting USE_COMMAND_LINE_PUSH_PARSER at run time and to
1220  // simplify the logic of the main loop below by using the same
1221  // base_parser::run interface for both push and pull parsers.
1222 
1223  std::shared_ptr<base_parser> repl_parser;
1224 
1225  if (m_interactive)
1226  {
1227  if (use_command_line_push_parser)
1228  {
1229  push_parser *pp = new push_parser (*this, new input_reader (*this));
1230  repl_parser = std::shared_ptr<base_parser> (pp);
1231  }
1232  else
1233  {
1234  parser *pp = new parser (new lexer (*this));
1235  repl_parser = std::shared_ptr<base_parser> (pp);
1236  }
1237  }
1238  else
1239  {
1240  parser *pp = new parser (new lexer (stdin, *this));
1241  repl_parser = std::shared_ptr<base_parser> (pp);
1242  }
1243 
1244  do
1245  {
1246  try
1247  {
1249 
1250  repl_parser->reset ();
1251 
1252  if (m_evaluator.at_top_level ())
1253  {
1256  }
1257 
1258  exit_status = repl_parser->run ();
1259 
1260  if (exit_status == 0)
1261  {
1262  std::shared_ptr<tree_statement_list>
1263  stmt_list = repl_parser->statement_list ();
1264 
1265  if (stmt_list)
1266  {
1268 
1269  m_evaluator.eval (stmt_list, m_interactive);
1270  }
1271  else if (repl_parser->at_end_of_input ())
1272  {
1273  exit_status = EOF;
1274  break;
1275  }
1276  }
1277  }
1278  catch (const interrupt_exception&)
1279  {
1281 
1282  // Required newline when the user does Ctrl+C at the prompt.
1283  if (m_interactive)
1284  octave_stdout << "\n";
1285  }
1286  catch (const index_exception& e)
1287  {
1289 
1290  std::cerr << "error: unhandled index exception: "
1291  << e.message () << " -- trying to return to prompt"
1292  << std::endl;
1293  }
1294  catch (const execution_exception& ee)
1295  {
1297  m_error_system.display_exception (ee, std::cerr);
1298 
1299  if (m_interactive)
1301  else
1302  {
1303  // We should exit with a nonzero status.
1304  exit_status = 1;
1305  break;
1306  }
1307  }
1308  catch (const std::bad_alloc&)
1309  {
1311 
1312  std::cerr << "error: out of memory -- trying to return to prompt"
1313  << std::endl;
1314  }
1315  }
1316  while (exit_status == 0);
1317 
1318  if (exit_status == EOF)
1319  {
1320  if (m_interactive)
1321  octave_stdout << "\n";
1322 
1323  exit_status = 0;
1324  }
1325 
1326  return exit_status;
1327  }
1328 
1330  {
1331  return m_evaluator;
1332  }
1333 
1335  {
1336  return m_stream_list;
1337  }
1338 
1340  {
1341  return m_url_handle_manager;
1342  }
1343 
1344  symbol_scope
1346  {
1347  return m_evaluator.get_top_scope ();
1348  }
1349 
1350  symbol_scope
1352  {
1353  return m_evaluator.get_current_scope ();
1354  }
1355 
1356  symbol_scope
1357  interpreter::require_current_scope (const std::string& who) const
1358  {
1359  symbol_scope scope = get_current_scope ();
1360 
1361  if (! scope)
1362  error ("%s: symbol table scope missing", who.c_str ());
1363 
1364  return scope;
1365  }
1366 
1368  {
1369  return m_evaluator.get_profiler ();
1370  }
1371 
1372  int interpreter::chdir (const std::string& dir)
1373  {
1374  std::string xdir = sys::file_ops::tilde_expand (dir);
1375 
1376  int cd_ok = sys::env::chdir (xdir);
1377 
1378  if (! cd_ok)
1379  error ("%s: %s", dir.c_str (), std::strerror (errno));
1380 
1382 
1383  // FIXME: should these actions be handled as a list of functions
1384  // to call so users can add their own chdir handlers?
1385 
1386  m_load_path.update ();
1387 
1389 
1390  return cd_ok;
1391  }
1392 
1393  void interpreter::mlock (bool skip_first) const
1394  {
1395  m_evaluator.mlock (skip_first);
1396  }
1397 
1398  void interpreter::munlock (bool skip_first) const
1399  {
1400  m_evaluator.munlock (skip_first);
1401  }
1402 
1403  bool interpreter::mislocked (bool skip_first) const
1404  {
1405  return m_evaluator.mislocked (skip_first);
1406  }
1407 
1408  void interpreter::munlock (const char *nm)
1409  {
1410  if (! nm)
1411  error ("munlock: invalid value for NAME");
1412 
1413  munlock (std::string (nm));
1414  }
1415 
1416  void interpreter::munlock (const std::string& nm)
1417  {
1419 
1420  if (val.is_defined ())
1421  {
1422  octave_function *fcn = val.function_value ();
1423 
1424  if (fcn)
1425  fcn->unlock ();
1426  }
1427  }
1428 
1429  bool interpreter::mislocked (const char *nm)
1430  {
1431  if (! nm)
1432  error ("mislocked: invalid value for NAME");
1433 
1434  return mislocked (std::string (nm));
1435  }
1436 
1437  bool interpreter::mislocked (const std::string& nm)
1438  {
1439  bool retval = false;
1440 
1442 
1443  if (val.is_defined ())
1444  {
1445  octave_function *fcn = val.function_value ();
1446 
1447  if (fcn)
1448  retval = fcn->islocked ();
1449  }
1450 
1451  return retval;
1452  }
1453 
1454  std::string interpreter::mfilename (const std::string& opt) const
1455  {
1456  return m_evaluator.mfilename (opt);
1457  }
1458 
1459  octave_value_list interpreter::eval_string (const std::string& eval_str,
1460  bool silent, int& parse_status,
1461  int nargout)
1462  {
1463  return m_evaluator.eval_string (eval_str, silent, parse_status, nargout);
1464  }
1465 
1466  octave_value interpreter::eval_string (const std::string& eval_str,
1467  bool silent, int& parse_status)
1468  {
1469  return m_evaluator.eval_string (eval_str, silent, parse_status);
1470  }
1471 
1473  bool silent, int& parse_status,
1474  int nargout)
1475  {
1476  return m_evaluator.eval_string (arg, silent, parse_status, nargout);
1477  }
1478 
1479  octave_value_list interpreter::eval (const std::string& try_code,
1480  int nargout)
1481  {
1482  return m_evaluator.eval (try_code, nargout);
1483  }
1484 
1485  octave_value_list interpreter::eval (const std::string& try_code,
1486  const std::string& catch_code,
1487  int nargout)
1488  {
1489  return m_evaluator.eval (try_code, catch_code, nargout);
1490  }
1491 
1493  const std::string& try_code,
1494  int nargout)
1495  {
1496  return m_evaluator.evalin (context, try_code, nargout);
1497  }
1498 
1500  const std::string& try_code,
1501  const std::string& catch_code,
1502  int nargout)
1503  {
1504  return m_evaluator.evalin (context, try_code, catch_code, nargout);
1505  }
1506 
1507  //! Evaluate an Octave function (built-in or interpreted) and return
1508  //! the list of result values.
1509  //!
1510  //! @param name The name of the function to call.
1511  //! @param args The arguments to the function.
1512  //! @param nargout The number of output arguments expected.
1513  //! @return A list of output values. The length of the list is not
1514  //! necessarily the same as @c nargout.
1515 
1517  const octave_value_list& args,
1518  int nargout)
1519  {
1520  return feval (std::string (name), args, nargout);
1521  }
1522 
1524  const octave_value_list& args,
1525  int nargout)
1526  {
1528 
1529  if (fcn.is_undefined ())
1530  error ("feval: function '%s' not found", name.c_str ());
1531 
1532  octave_function *of = fcn.function_value ();
1533 
1534  return of->call (m_evaluator, nargout, args);
1535  }
1536 
1538  const octave_value_list& args,
1539  int nargout)
1540  {
1541  if (fcn)
1542  return fcn->call (m_evaluator, nargout, args);
1543 
1544  return octave_value_list ();
1545  }
1546 
1548  const octave_value_list& args,
1549  int nargout)
1550  {
1551  // FIXME: do we really want to silently return an empty ovl if
1552  // the function object is undefined? It's essentially what the
1553  // version above that accepts a pointer to an octave_function
1554  // object does and some code was apparently written to rely on it
1555  // (for example, __ode15__).
1556 
1557  if (val.is_undefined ())
1558  return ovl ();
1559 
1560  if (val.is_function ())
1561  {
1562  return feval (val.function_value (), args, nargout);
1563  }
1564  else if (val.is_function_handle () || val.is_inline_function ())
1565  {
1566  // This covers function handles, inline functions, and anonymous
1567  // functions.
1568 
1569  std::list<octave_value_list> arg_list;
1570  arg_list.push_back (args);
1571 
1572  // FIXME: could we make octave_value::subsref a const method?
1573  // It would be difficult because there are instances of
1574  // incrementing the reference count inside subsref methods,
1575  // which means they can't be const with the current way of
1576  // handling reference counting.
1577 
1578  octave_value xval = val;
1579  return xval.subsref ("(", arg_list, nargout);
1580  }
1581  else if (val.is_string ())
1582  {
1583  return feval (val.string_value (), args, nargout);
1584  }
1585  else
1586  error ("feval: first argument must be a string, inline function, or a function handle");
1587 
1588  return ovl ();
1589  }
1590 
1591  //! Evaluate an Octave function (built-in or interpreted) and return
1592  //! the list of result values.
1593  //!
1594  //! @param args The first element of @c args is the function to call.
1595  //! It may be the name of the function as a string, a function
1596  //! handle, or an inline function. The remaining arguments are
1597  //! passed to the function.
1598  //! @param nargout The number of output arguments expected.
1599  //! @return A list of output values. The length of the list is not
1600  //! necessarily the same as @c nargout.
1601 
1603  int nargout)
1604  {
1605  if (args.length () == 0)
1606  error ("feval: first argument must be a string, inline function, or a function handle");
1607 
1608  octave_value f_arg = args(0);
1609 
1610  octave_value_list tmp_args = args.slice (1, args.length () - 1, true);
1611 
1612  return feval (f_arg, tmp_args, nargout);
1613  }
1614 
1616  {
1617  return m_evaluator.make_fcn_handle (name);
1618  }
1619 
1620  void interpreter::install_variable (const std::string& name,
1621  const octave_value& value, bool global)
1622  {
1623  m_evaluator.install_variable (name, value, global);
1624  }
1625 
1626  octave_value interpreter::global_varval (const std::string& name) const
1627  {
1628  return m_evaluator.global_varval (name);
1629  }
1630 
1631  void interpreter::global_assign (const std::string& name,
1632  const octave_value& val)
1633  {
1635  }
1636 
1638  {
1640  }
1641 
1642  void interpreter::top_level_assign (const std::string& name,
1643  const octave_value& val)
1644  {
1646  }
1647 
1648  bool interpreter::is_variable (const std::string& name) const
1649  {
1650  return m_evaluator.is_variable (name);
1651  }
1652 
1653  bool interpreter::is_local_variable (const std::string& name) const
1654  {
1656  }
1657 
1658  octave_value interpreter::varval (const std::string& name) const
1659  {
1660  return m_evaluator.varval (name);
1661  }
1662 
1663  void interpreter::assign (const std::string& name,
1664  const octave_value& val)
1665  {
1666  m_evaluator.assign (name, val);
1667  }
1668 
1669  void interpreter::assignin (const std::string& context,
1670  const std::string& name,
1671  const octave_value& val)
1672  {
1673  m_evaluator.assignin (context, name, val);
1674  }
1675 
1676  void interpreter::source_file (const std::string& file_name,
1677  const std::string& context, bool verbose,
1678  bool require_file)
1679  {
1680  m_evaluator.source_file (file_name, context, verbose, require_file);
1681  }
1682 
1683  bool interpreter::at_top_level (void) const
1684  {
1685  return m_evaluator.at_top_level ();
1686  }
1687 
1688  bool interpreter::isglobal (const std::string& name) const
1689  {
1690  return m_evaluator.is_global (name);
1691  }
1692 
1693  octave_value interpreter::find (const std::string& name)
1694  {
1695  return m_evaluator.find (name);
1696  }
1697 
1698  void interpreter::clear_all (bool force)
1699  {
1700  m_evaluator.clear_all (force);
1701  }
1702 
1704  {
1706  }
1707 
1708  void interpreter::clear_variable (const std::string& name)
1709  {
1711  }
1712 
1713  void interpreter::clear_variable_pattern (const std::string& pattern)
1714  {
1716  }
1717 
1718  void interpreter::clear_variable_regexp (const std::string& pattern)
1719  {
1721  }
1722 
1724  {
1726  }
1727 
1728  void interpreter::clear_global_variable (const std::string& name)
1729  {
1731  }
1732 
1733  void interpreter::clear_global_variable_pattern (const std::string& pattern)
1734  {
1736  }
1737 
1738  void interpreter::clear_global_variable_regexp (const std::string& pattern)
1739  {
1741  }
1742 
1744  {
1746  }
1747 
1749  {
1751  }
1752 
1753  void interpreter::clear_function (const std::string& name)
1754  {
1756  }
1757 
1758  void interpreter::clear_symbol (const std::string& name)
1759  {
1761  }
1762 
1763  void interpreter::clear_function_pattern (const std::string& pat)
1764  {
1766  }
1767 
1768  void interpreter::clear_function_regexp (const std::string& pat)
1769  {
1771  }
1772 
1773  void interpreter::clear_symbol_pattern (const std::string& pat)
1774  {
1775  return m_evaluator.clear_symbol_pattern (pat);
1776  }
1777 
1778  void interpreter::clear_symbol_regexp (const std::string& pat)
1779  {
1780  return m_evaluator.clear_symbol_regexp (pat);
1781  }
1782 
1783  std::list<std::string> interpreter::global_variable_names (void)
1784  {
1786  }
1787 
1788  std::list<std::string> interpreter::top_level_variable_names (void)
1789  {
1791  }
1792 
1793  std::list<std::string> interpreter::variable_names (void)
1794  {
1795  return m_evaluator.variable_names ();
1796  }
1797 
1798  std::list<std::string> interpreter::user_function_names (void)
1799  {
1801  }
1802 
1803  std::list<std::string> interpreter::autoloaded_functions (void) const
1804  {
1806  }
1807 
1809  {
1811 
1812  // FIXME: use a separate stream instead of std::cerr directly so that
1813  // error messages can be redirected more easily? Pass the message
1814  // to an event manager function?
1815  m_error_system.display_exception (e, std::cerr);
1816 
1818  }
1819 
1821  {
1822  can_interrupt = true;
1826  catch_interrupts ();
1827  }
1828 
1829  void interpreter::mark_for_deletion (const std::string& file)
1830  {
1831  m_tmp_files.insert (file);
1832  }
1833 
1835  {
1836  m_tmp_files.cleanup ();
1837  }
1838 
1839  void interpreter::quit (int exit_status, bool force, bool confirm)
1840  {
1841  if (! force)
1842  {
1843  try
1844  {
1845  bool cancel = false;
1846 
1847  if (symbol_exist ("finish.m", "file"))
1848  {
1851 
1852  evalin ("base", "finish", 0);
1853 
1854  cancel = m_cancel_quit;
1855  }
1856 
1857  if (cancel)
1858  return;
1859 
1860  // Check for confirmation.
1861 
1862  if (confirm && ! m_event_manager.confirm_shutdown ())
1863  return;
1864  }
1865  catch (const execution_exception&)
1866  {
1867  // Catch execution_exceptions so we don't throw an
1868  // exit_exception if there is an in finish.m. But throw it
1869  // again so that will be handled as any other
1870  // execution_exception by the evaluator. This way, errors
1871  // will be ignored properly and we won't exit if quit is
1872  // called recursively from finish.m.
1873 
1874  throw;
1875  }
1876  }
1877 
1878  throw exit_exception (exit_status);
1879  }
1880 
1881  void interpreter::add_atexit_fcn (const std::string& fname)
1882  {
1883  if (m_executing_atexit)
1884  return;
1885 
1886  m_atexit_fcns.push_front (fname);
1887  }
1888 
1889  bool interpreter::remove_atexit_fcn (const std::string& fname)
1890  {
1891  bool found = false;
1892 
1893  for (auto it = m_atexit_fcns.begin ();
1894  it != m_atexit_fcns.end (); it++)
1895  {
1896  if (*it == fname)
1897  {
1898  m_atexit_fcns.erase (it);
1899  found = true;
1900  break;
1901  }
1902  }
1903 
1904  return found;
1905  }
1906 
1907  void interpreter::add_atexit_function (const std::string& fname)
1908  {
1909  interpreter& interp
1910  = __get_interpreter__ ("interpreter::add_atexit_function");
1911 
1912  interp.add_atexit_fcn (fname);
1913  }
1914 
1915  bool interpreter::remove_atexit_function (const std::string& fname)
1916  {
1917  interpreter& interp
1918  = __get_interpreter__ ("interpreter::remove_atexit_function");
1919 
1920  return interp.remove_atexit_fcn (fname);
1921  }
1922 
1923  // What internal options get configured by --traditional.
1924 
1926  {
1927  m_input_system.PS1 (">> ");
1928  m_input_system.PS2 ("");
1929 
1930  m_evaluator.PS4 ("");
1931 
1933  m_load_save_system.save_default_options ("-mat-binary");
1934 
1935  m_history_system.timestamp_format_string ("%%-- %D %I:%M %p --%%");
1936 
1939 
1942  Fdisable_range (octave_value (true));
1946 
1947  disable_warning ("Octave:abbreviated-property-match");
1948  disable_warning ("Octave:colon-nonscalar-argument");
1949  disable_warning ("Octave:data-file-in-path");
1950  disable_warning ("Octave:function-name-clash");
1951  disable_warning ("Octave:possible-matlab-short-circuit-operator");
1952  }
1953 
1954  void interpreter::execute_pkg_add (const std::string& dir)
1955  {
1956  try
1957  {
1959  }
1960  catch (const interrupt_exception&)
1961  {
1963  }
1964  catch (const execution_exception& e)
1965  {
1966  handle_exception (e);
1967  }
1968  }
1969 }
#define NaN
Definition: Faddeeva.cc:248
Definition: Cell.h:43
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
void add_method(T *obj, void(T::*method)(Params...), Args &&... args)
bool have_script_file(void) const
Definition: octave.h:261
bool is_octave_program(void) const
Definition: octave.h:263
void intern_argv(const string_vector &args)
Definition: octave.cc:264
void set_program_names(const std::string &pname)
Definition: octave.cc:254
static std::string program_name(void)
Definition: octave.h:293
bool have_eval_option_code(void) const
Definition: octave.h:259
static std::string program_invocation_name(void)
Definition: octave.h:288
cmdline_options options(void) const
Definition: octave.h:257
bool read_site_files(void) const
Definition: octave.h:69
std::string info_program(void) const
Definition: octave.h:80
std::list< std::string > command_line_path(void) const
Definition: octave.h:74
bool line_editing(void) const
Definition: octave.h:63
bool traditional(void) const
Definition: octave.h:71
bool inhibit_startup_message(void) const
Definition: octave.h:61
std::string image_path(void) const
Definition: octave.h:78
bool persist(void) const
Definition: octave.h:66
bool forced_line_editing(void) const
Definition: octave.h:59
std::string doc_cache_file(void) const
Definition: octave.h:76
std::string texi_macros_file(void) const
Definition: octave.h:81
bool forced_interactive(void) const
Definition: octave.h:58
std::string docstrings_file(void) const
Definition: octave.h:75
bool read_init_files(void) const
Definition: octave.h:68
string_vector remaining_args(void) const
Definition: octave.h:83
bool debug_jit(void) const
Definition: octave.h:55
bool read_history_file(void) const
Definition: octave.h:67
bool no_window_system(void) const
Definition: octave.h:65
std::string code_to_eval(void) const
Definition: octave.h:73
std::string info_file(void) const
Definition: octave.h:79
bool jit_compiler(void) const
Definition: octave.h:62
std::string exec_path(void) const
Definition: octave.h:77
bool echo_commands(void) const
Definition: octave.h:56
bool set_initial_path(void) const
Definition: octave.h:70
bool verbose_flag(void) const
Definition: octave.h:72
string_vector all_args(void) const
Definition: octave.h:82
static void blink_matching_paren(bool flag)
Definition: cmd-edit.cc:1302
static void restore_terminal_state(void)
Definition: cmd-edit.cc:1295
static void increment_current_command_number(void)
Definition: cmd-edit.cc:1288
static void ignore_entries(bool=true)
Definition: cmd-hist.cc:592
static bool ignoring_entries(void)
Definition: cmd-hist.cc:599
static void clean_up_and_save(const std::string &="", int=-1)
Definition: cmd-hist.cc:757
void initialize(void)
Definition: display.cc:42
octave_value exec_path(const octave_value_list &args, int nargout)
Definition: environment.cc:81
octave_value image_path(const octave_value_list &args, int nargout)
Definition: environment.cc:101
void save_exception(const execution_exception &e)
Definition: error.cc:899
void display_exception(const execution_exception &e, std::ostream &os) const
Definition: error.cc:910
octave_value beep_on_error(const octave_value_list &args, int nargout)
Definition: error.cc:306
void directory_changed(const std::string &dir)
bool confirm_shutdown(void)
void process_events(bool disable=false)
void unload_all_toolkits(void)
Definition: gtk-manager.h:99
void write_timestamp(void)
Definition: oct-hist.cc:286
octave_value timestamp_format_string(const octave_value_list &args, int nargout)
Definition: oct-hist.cc:312
void initialize(bool read_history_file=false)
Definition: oct-hist.cc:275
octave_value PS1(const octave_value_list &args, int nargout)
void initialize(bool line_editing)
octave_value PS2(const octave_value_list &args, int nargout)
void clear_input_event_hooks(void)
bool is_variable(const std::string &name) const
history_system m_history_system
Definition: interpreter.h:520
void clear_symbol(const std::string &name)
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 execute_pkg_add(const std::string &dir)
void maximum_braindamage(void)
void assign(const std::string &name, const octave_value &val=octave_value())
void global_assign(const std::string &name, const octave_value &val=octave_value())
bool m_inhibit_startup_message
Definition: interpreter.h:557
environment m_environment
Definition: interpreter.h:508
octave_value_list evalin(const std::string &context, const std::string &try_code, int nargout)
octave_value varval(const std::string &name) const
octave_value global_varval(const std::string &name) const
event_manager m_event_manager
Definition: interpreter.h:544
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
void initialize_load_path(bool set_initial_path=true)
Definition: interpreter.cc:676
int execute_command_line_file(void)
void clear_variables(void)
std::list< std::string > user_function_names(void)
void cleanup_tmp_files(void)
std::list< std::string > variable_names(void)
void inhibit_startup_message(bool flag)
Definition: interpreter.h:183
std::list< std::string > top_level_variable_names(void)
std::list< std::string > m_atexit_fcns
Definition: interpreter.h:504
void top_level_assign(const std::string &name, const octave_value &val=octave_value())
void clear_symbol_regexp(const std::string &pat)
symbol_scope require_current_scope(const std::string &who) const
void clear_function(const std::string &name)
bool is_local_variable(const std::string &name) const
void read_site_files(bool flag)
Definition: interpreter.h:168
bool remove_atexit_fcn(const std::string &fname)
void clear_function_pattern(const std::string &pat)
void clear_global_variable(const std::string &name)
std::list< std::string > autoloaded_functions(void) const
gtk_manager m_gtk_manager
Definition: interpreter.h:542
void clear_global_variable_pattern(const std::string &pattern)
void clear_global_variables(void)
void clear_functions(bool force=false)
void clear_variable_pattern(const std::string &pattern)
bool isglobal(const std::string &name) const
display_info m_display_info
Definition: interpreter.h:506
load_save_system m_load_save_system
Definition: interpreter.h:526
bool mislocked(bool skip_first=false) const
void recover_from_exception(void)
void intern_nargin(octave_idx_type nargs)
Definition: interpreter.cc:641
void clear_variable(const std::string &name)
url_handle_manager & get_url_handle_manager(void)
static bool remove_atexit_function(const std::string &fname)
application * m_app_context
Definition: interpreter.h:500
void clear_global_variable_regexp(const std::string &pattern)
gh_manager * m_gh_manager
Definition: interpreter.h:546
int execute_startup_files(void)
Definition: interpreter.cc:970
interpreter(application *app_context=nullptr)
Definition: interpreter.cc:437
bool m_executing_finish_script
Definition: interpreter.h:568
stream_list m_stream_list
Definition: interpreter.h:534
octave_value make_function_handle(const std::string &name)
stream_list & get_stream_list(void)
void read_init_files(bool flag)
Definition: interpreter.h:173
octave_value top_level_varval(const std::string &name) const
void handle_exception(const execution_exception &e)
input_system m_input_system
Definition: interpreter.h:516
void assignin(const std::string &context, const std::string &varname, const octave_value &val=octave_value())
tree_evaluator m_evaluator
Definition: interpreter.h:532
load_path m_load_path
Definition: interpreter.h:524
symbol_table m_symbol_table
Definition: interpreter.h:530
void clear_function_regexp(const std::string &pat)
void clear_objects(void)
bool at_top_level(void) const
void display_startup_message(void) const
Definition: interpreter.cc:951
bool interactive(void) const
Definition: interpreter.h:158
static OCTAVE_THREAD_LOCAL interpreter * instance
Definition: interpreter.h:486
void clear_all(bool force=false)
symbol_scope get_top_scope(void) const
static void add_atexit_function(const std::string &fname)
temporary_file_list m_tmp_files
Definition: interpreter.h:502
void initialize_history(bool read_history_file=false)
Definition: interpreter.cc:648
void mark_for_deletion(const std::string &file)
int chdir(const std::string &dir)
symbol_scope get_current_scope(void) const
void verbose(bool flag)
Definition: interpreter.h:178
profiler & get_profiler(void)
int execute_eval_option_code(void)
void mlock(bool skip_first=false) const
void munlock(bool skip_first=false) const
void quit(int exit_status, bool force=false, bool confirm=true)
std::string mfilename(const std::string &opt="") const
void clear_variable_regexp(const std::string &pattern)
error_system m_error_system
Definition: interpreter.h:512
octave_value_list eval(const std::string &try_code, int nargout)
url_handle_manager m_url_handle_manager
Definition: interpreter.h:538
void install_variable(const std::string &name, const octave_value &value, bool global)
void add_atexit_fcn(const std::string &fname)
void clear_symbol_pattern(const std::string &pat)
void execute_atexit_fcns(void)
Definition: interpreter.cc:934
std::list< std::string > global_variable_names(void)
void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
tree_evaluator & get_evaluator(void)
void initialize(void)
Definition: interpreter.cc:714
octave_value find(const std::string &name)
void initialize(bool set_initial_path=false)
Definition: load-path.cc:238
std::function< void(const std::string &)> get_add_hook(void)
Definition: load-path.h:174
void update(void) const
Definition: load-path.cc:395
void set_add_hook(const std::function< void(const std::string &)> &f)
Definition: load-path.h:184
void set_command_line_path(const std::string &p)
Definition: load-path.h:197
void execute_pkg_add(const std::string &dir)
Definition: load-path.cc:949
octave_value crash_dumps_octave_core(const octave_value_list &args, int nargout)
Definition: load-save.cc:281
octave_value save_default_options(const octave_value_list &args, int nargout)
Definition: load-save.cc:305
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
Definition: symtab.cc:249
void clear_function(const std::string &name)
Definition: symtab.cc:434
std::list< std::string > user_function_names(void)
Definition: symtab.cc:581
void clear_function_pattern(const std::string &pat)
Definition: symtab.cc:439
void cleanup(void)
Definition: symtab.cc:693
void clear_functions(bool force=false)
Definition: symtab.cc:426
void clear_function_regexp(const std::string &pat)
Definition: symtab.cc:454
void clear_mex_functions(void)
Definition: symtab.cc:498
static std::string getenv(const std::string &name)
Definition: oct-env.cc:271
static std::string get_home_directory(void)
Definition: oct-env.cc:147
static void putenv(const std::string &name, const std::string &value)
Definition: oct-env.cc:278
static std::string get_user_config_directory(void)
Definition: oct-env.cc:161
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
Definition: oct-env.cc:133
static std::string get_current_directory(void)
Definition: oct-env.cc:140
static bool chdir(const std::string &newdir)
Definition: oct-env.cc:292
void stamp(void)
Definition: oct-time.cc:109
std::set< std::string > m_files
Definition: interpreter.h:108
void insert(const std::string &file)
Definition: interpreter.cc:305
static void init(void)
symbol_scope get_top_scope(void) const
Definition: pt-eval.cc:2040
void clear_symbol_pattern(const std::string &pattern)
Definition: pt-eval.cc:2211
bool at_top_level(void) const
Definition: pt-eval.cc:394
void clear_global_variables(void)
Definition: pt-eval.cc:2183
void clear_objects(void)
Definition: pt-eval.cc:2127
void set_auto_fcn_var(stack_frame::auto_var_type avt, const octave_value &val=octave_value())
Definition: pt-eval.cc:1587
bool mislocked(bool skip_first=false) const
Definition: pt-eval.cc:2082
octave_value global_varval(const std::string &name) const
Definition: pt-eval.cc:1358
octave_value varval(const symbol_record &sym) const
Definition: pt-eval.cc:1330
std::list< std::string > autoloaded_functions(void) const
Definition: pt-eval.cc:3700
bool is_variable(const std::string &name) const
Definition: pt-eval.cc:1255
std::list< std::string > global_variable_names(void) const
Definition: pt-eval.cc:2233
bool is_global(const std::string &name) const
Definition: pt-eval.cc:1321
octave_value make_fcn_handle(const std::string &nm)
Definition: pt-eval.cc:1011
int dbstep_flag(void) const
Definition: pt-eval.h:710
void clear_variables(void)
Definition: pt-eval.cc:2159
void install_variable(const std::string &name, const octave_value &value, bool global)
Definition: pt-eval.cc:1347
void clear_symbol_regexp(const std::string &pattern)
Definition: pt-eval.cc:2222
void clear_global_variable_pattern(const std::string &pattern)
Definition: pt-eval.cc:2173
void clear_global_variable_regexp(const std::string &pattern)
Definition: pt-eval.cc:2178
std::string mfilename(const std::string &opt="") const
Definition: pt-eval.cc:432
void mlock(bool skip_first=false) const
Definition: pt-eval.cc:2050
octave_value top_level_varval(const std::string &name) const
Definition: pt-eval.cc:1377
std::list< std::string > variable_names(void) const
Definition: pt-eval.cc:2243
void assignin(const std::string &context, const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:1399
octave_value_list evalin(const std::string &context, const std::string &try_code, int nargout)
Definition: pt-eval.cc:617
void top_level_assign(const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:1383
void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
Definition: pt-eval.cc:1435
void clear_variable(const std::string &name)
Definition: pt-eval.cc:2135
void clear_variable_pattern(const std::string &pattern)
Definition: pt-eval.cc:2143
void clear_all(bool force=false)
Definition: pt-eval.cc:2188
octave_value find(const std::string &name)
Definition: pt-eval.cc:2103
void assign(const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:1390
void clear_global_variable(const std::string &name)
Definition: pt-eval.cc:2167
octave_value PS4(const octave_value_list &args, int nargout)
Definition: pt-eval.cc:4221
void eval(std::shared_ptr< tree_statement_list > &stmt_list, bool interactive)
Definition: pt-eval.cc:399
void clear_symbol(const std::string &name)
Definition: pt-eval.cc:2200
void reset_debug_state(void)
Definition: pt-eval.cc:778
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
Definition: pt-eval.cc:468
void munlock(bool skip_first=false) const
Definition: pt-eval.cc:2066
void global_assign(const std::string &name, const octave_value &val=octave_value())
Definition: pt-eval.cc:1370
void clear_variable_regexp(const std::string &pattern)
Definition: pt-eval.cc:2151
bool is_local_variable(const std::string &name) const
Definition: pt-eval.cc:1264
std::list< std::string > top_level_variable_names(void) const
Definition: pt-eval.cc:2238
octave_value echo(const octave_value_list &args, int nargout)
Definition: pt-eval.cc:3949
symbol_scope get_current_scope(void) const
Definition: pt-eval.cc:2045
profiler & get_profiler(void)
Definition: pt-eval.h:374
void unlock(void)
Definition: ov-fcn.h:183
bool islocked(void) const
Definition: ov-fcn.h:189
virtual octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
Definition: ov-fcn.cc:50
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:576
octave_idx_type nfields(void) const
Definition: oct-map.h:344
octave_idx_type numel(void) const
Definition: oct-map.h:389
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:365
octave_idx_type length(void) const
Definition: oct-map.h:390
octave_idx_type length(void) const
Definition: ovl.h:113
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
Definition: ovl.h:131
bool is_function(void) const
Definition: ov.h:730
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov.h:449
bool is_string(void) const
Definition: ov.h:593
bool is_defined(void) const
Definition: ov.h:551
bool is_function_handle(void) const
Definition: ov.h:721
octave_function * function_value(bool silent=false) const
std::string string_value(bool force=false) const
Definition: ov.h:927
bool is_undefined(void) const
Definition: ov.h:554
bool is_inline_function(void) const
Definition: ov.h:727
octave_idx_type numel(void) const
Definition: str-vec.h:100
OCTINTERP_API void print_usage(void)
Definition: defun.cc:53
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:138
#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:214
OCTAVE_EXPORT octave_value_list Fconfirm_recursive_rmdir(const octave_value_list &args, int nargout)
Definition: dirfns.cc:679
void warning(const char *fmt,...)
Definition: error.cc:1050
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:1065
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
Definition: error.cc:1022
void verror_with_cfn(const char *fmt, va_list args)
Definition: error.cc:992
void error(const char *fmt,...)
Definition: error.cc:968
void disable_warning(const std::string &id)
Definition: error.cc:1803
void octave_set_default_fpucw(void)
QString name
#define OCTAVE_SAFE_CALL(F, ARGS)
Definition: interpreter.cc:820
bool octave_initialized
Definition: interpreter.cc:92
OCTAVE_EXPORT octave_value_list F__version_info__(const octave_value_list &args, int)
Definition: interpreter.cc:98
bool octave_interpreter_ready
Definition: interpreter.cc:89
bool quit_allowed
Definition: interpreter.cc:85
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(void)
Definition: lo-ieee.cc:134
#define OCTAVE_VERSION
Definition: main.in.cc:52
octave_idx_type n
Definition: mx-inlines.cc:753
std::string local_site_defaults_file(void)
Definition: defaults.cc:434
std::string site_defaults_file(void)
Definition: defaults.cc:442
std::string release(void)
Definition: defaults.cc:143
std::string dir_sep_str(void)
Definition: file-ops.cc:243
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:286
void respond_to_pending_signals(void)
Definition: sighandlers.cc:106
static void initialize_xerbla_error_handler(void)
Definition: interpreter.cc:374
void flush_stdout(void)
Definition: pager.cc:260
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:80
interpreter & __get_interpreter__(const std::string &who)
void sysdep_cleanup(void)
Definition: sysdep.cc:451
static void xerbla_abort(void)
Definition: interpreter.cc:369
static OCTAVE_NORETURN void lo_error_with_id_handler(const char *id, const char *fmt,...)
Definition: interpreter.cc:415
static void initialize_error_handlers(void)
Definition: interpreter.cc:425
std::string file_in_path(const std::string &name, const std::string &suffix)
Definition: utils.cc:541
static void initialize_version_info(void)
Definition: interpreter.cc:357
sys::time Vlast_chdir_time
Definition: interpreter.cc:323
static OCTAVE_NORETURN void lo_error_handler(const char *fmt,...)
Definition: interpreter.cc:404
bool can_interrupt
Definition: sighandlers.cc:68
interrupt_handler catch_interrupts(void)
Definition: sighandlers.cc:322
void source_file(const std::string &file_name, const std::string &context, bool verbose, bool require_file)
Definition: oct-parse.cc:9526
void install_signal_handlers(void)
Definition: sighandlers.cc:361
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:138
static int safe_source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
Definition: interpreter.cc:330
T::size_type numel(const T &str)
Definition: oct-string.cc:71
OCTAVE_EXPORT octave_value_list Fstruct_levels_to_print(const octave_value_list &args, int nargout)
Definition: ov-struct.cc:2161
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
OCTAVE_EXPORT octave_value_list Fdisable_diagonal_matrix(const octave_value_list &args, int nargout)
Definition: ov.cc:3325
OCTAVE_EXPORT octave_value_list Fdisable_permutation_matrix(const octave_value_list &args, int nargout)
Definition: ov.cc:3295
OCTAVE_EXPORT octave_value_list Fdisable_range(const octave_value_list &args, int nargout)
Definition: ov.cc:3369
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
#define octave_stdout
Definition: pager.h:313
OCTAVE_EXPORT octave_value_list Ffixed_point_format(const octave_value_list &args, int nargout)
Definition: pr-output.cc:4096
OCTAVE_EXPORT octave_value_list Fprint_empty_dimensions(const octave_value_list &args, int nargout)
Definition: pr-output.cc:4126
OCTAVE_EXPORT octave_value_list Fjit_enable(const octave_value_list &args, int nargout)
Definition: pt-jit.cc:2899
OCTAVE_EXPORT octave_value_list Fdebug_jit(const octave_value_list &args, int nargout)
Definition: pt-jit.cc:2876
volatile sig_atomic_t octave_signal_caught
Definition: quit.cc:47
sig_atomic_t octave_interrupt_state
Definition: quit.cc:38
void(* octave_interrupt_hook)(void)
Definition: quit.cc:50
void(* octave_signal_hook)(void)
Definition: quit.cc:49
void octave_save_signal_mask(void)
void octave_unblock_signal_by_name(const char *signame)
void octave_restore_signal_mask(void)
int octave_unlink_wrapper(const char *nm)
int octave_isatty_wrapper(int fd)
static int symbol_exist(octave::interpreter &interp, const std::string &name, const std::string &type="any")
Definition: variables.cc:200
std::string octave_startup_message(bool html)
Definition: version.cc:122
#define OCTAVE_RELEASE_DATE
Definition: version.in.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