GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
interpreter.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <string>
28 #include <iostream>
29 
30 #include "cmd-edit.h"
31 #include "file-ops.h"
32 #include "file-stat.h"
33 #include "fpucw-wrappers.h"
34 #include "lo-blas-proto.h"
35 #include "lo-error.h"
36 #include "oct-env.h"
37 #include "str-vec.h"
38 #include "signal-wrappers.h"
39 #include "unistd-wrappers.h"
40 
41 #include "builtins.h"
42 #include "defaults.h"
43 #include "Cell.h"
44 #include "defun.h"
45 #include "display.h"
46 #include "error.h"
47 #include "file-io.h"
48 #include "graphics.h"
49 #include "interpreter.h"
50 #include "load-path.h"
51 #include "load-save.h"
52 #include "octave-link.h"
53 #include "octave.h"
54 #include "oct-hist.h"
55 #include "oct-map.h"
56 #include "oct-mutex.h"
57 #include "ops.h"
58 #include "ovl.h"
59 #include "ov.h"
60 #include "ov-classdef.h"
61 #include "parse.h"
62 #include "pt-eval.h"
63 #include "pt-jump.h"
64 #include "pt-stmt.h"
65 #include "sighandlers.h"
66 #include "sysdep.h"
67 #include "unwind-prot.h"
68 #include "utils.h"
69 #include "variables.h"
70 #include <version.h>
71 
72 void (*octave_exit) (int) = ::exit;
73 
74 // TRUE means the quit() call is allowed.
75 bool quit_allowed = true;
76 
77 // TRUE means we are ready to interpret commands, but not everything
78 // is ready for interactive use.
80 
81 // TRUE means we've processed all the init code and we are good to go.
82 bool octave_initialized = false;
83 
84 DEFUN (__version_info__, args, ,
85  doc: /* -*- texinfo -*-
86 @deftypefn {} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})
87 Undocumented internal function.
88 @end deftypefn */)
89 {
90  static octave_map vinfo;
91 
92  int nargin = args.length ();
93 
94  if (nargin != 0 && nargin != 4)
95  print_usage ();
96 
98 
99  if (nargin == 0)
100  retval = vinfo;
101  else if (nargin == 4)
102  {
103  if (vinfo.nfields () == 0)
104  {
105  vinfo.assign ("Name", args(0));
106  vinfo.assign ("Version", args(1));
107  vinfo.assign ("Release", args(2));
108  vinfo.assign ("Date", args(3));
109  }
110  else
111  {
112  octave_idx_type n = vinfo.numel () + 1;
113 
114  vinfo.resize (dim_vector (n, 1));
115 
116  octave_value idx (n);
117 
118  vinfo.assign (idx, "Name", Cell (octave_value (args(0))));
119  vinfo.assign (idx, "Version", Cell (octave_value (args(1))));
120  vinfo.assign (idx, "Release", Cell (octave_value (args(2))));
121  vinfo.assign (idx, "Date", Cell (octave_value (args(3))));
122  }
123  }
124 
125  return retval;
126 }
127 
128 static void
130 {
132 
134  args(2) = OCTAVE_RELEASE;
135  args(1) = OCTAVE_VERSION;
136  args(0) = "GNU Octave";
137 
138  F__version_info__ (args, 0);
139 }
140 
141 OCTAVE_NORETURN static void
142 lo_error_handler (const char *fmt, ...)
143 {
144  va_list args;
145  va_start (args, fmt);
146  verror_with_cfn (fmt, args);
147  va_end (args);
148 
150 }
151 
152 OCTAVE_NORETURN static void
153 lo_error_with_id_handler (const char *id, const char *fmt, ...)
154 {
155  va_list args;
156  va_start (args, fmt);
157  verror_with_id_cfn (id, fmt, args);
158  va_end (args);
159 
161 }
162 
163 static void
165 {
170 }
171 
172 // What internal options get configured by --traditional.
173 
174 static void
176 {
177  FPS1 (octave_value (">> "));
178  FPS2 (octave_value (""));
179  FPS4 (octave_value (""));
180  Fbeep_on_error (octave_value (true));
185  Fdisable_range (octave_value (true));
187  Fhistory_timestamp_format_string (octave_value ("%%-- %D %I:%M %p --%%"));
190  Fsave_default_options (octave_value ("-mat-binary"));
192 
193  disable_warning ("Octave:abbreviated-property-match");
194  disable_warning ("Octave:data-file-in-path");
195  disable_warning ("Octave:function-name-clash");
196  disable_warning ("Octave:possible-matlab-short-circuit-operator");
197 }
198 
199 void
201 {
202  octave::can_interrupt = true;
209 }
210 
211 // Fix up things before exiting.
212 
213 static std::list<std::string> octave_atexit_functions;
214 
215 DEFUN (quit, args, ,
216  doc: /* -*- texinfo -*-
217 @deftypefn {} {} exit
218 @deftypefnx {} {} exit (@var{status})
219 @deftypefnx {} {} quit
220 @deftypefnx {} {} quit (@var{status})
221 Exit the current Octave session.
222 
223 If the optional integer value @var{status} is supplied, pass that value to
224 the operating system as Octave's exit status. The default value is zero.
225 
226 When exiting, Octave will attempt to run the m-file @file{finish.m} if it
227 exists. User commands to save the workspace or clean up temporary files
228 may be placed in that file. Alternatively, another m-file may be scheduled
229 to run using @code{atexit}.
230 @seealso{atexit}
231 @end deftypefn */)
232 {
233  // Confirm OK to shutdown. Note: A dynamic function installation similar
234  // to overriding polymorphism for which the GUI can install its own "quit"
235  // yet call this base "quit" could be nice. No link would be needed here.
237  return ovl ();
238 
239  if (! quit_allowed)
240  error ("quit: not supported in embedded mode");
241 
242  int exit_status = 0;
243 
244  if (args.length () > 0)
245  exit_status = args(0).nint_value ();
246 
247  // Instead of simply calling exit, we thrown an exception so that no
248  // matter where the call to quit occurs, we will run the
249  // unwind_protect stack, clear the OCTAVE_LOCAL_BUFFER allocations,
250  // etc. before exiting.
251 
252  clean_up_and_exit (exit_status);
253 
254  return ovl ();
255 }
256 
257 DEFALIAS (exit, quit);
258 
259 void
261 {
262  octave_atexit_functions.push_front (fname);
263 }
264 
265 bool
267 {
268  bool found = false;
269 
270  for (std::list<std::string>::iterator p = octave_atexit_functions.begin ();
271  p != octave_atexit_functions.end (); p++)
272  {
273  if (*p == fname)
274  {
275  octave_atexit_functions.erase (p);
276  found = true;
277  break;
278  }
279  }
280 
281  return found;
282 }
283 
284 DEFUN (atexit, args, nargout,
285  doc: /* -*- texinfo -*-
286 @deftypefn {} {} atexit (@var{fcn})
287 @deftypefnx {} {} atexit (@var{fcn}, @var{flag})
288 Register a function to be called when Octave exits.
289 
290 For example,
291 
292 @example
293 @group
294 function last_words ()
295  disp ("Bye bye");
296 endfunction
297 atexit ("last_words");
298 @end group
299 @end example
300 
301 @noindent
302 will print the message @qcode{"Bye bye"} when Octave exits.
303 
304 The additional argument @var{flag} will register or unregister @var{fcn}
305 from the list of functions to be called when Octave exits. If @var{flag} is
306 true, the function is registered, and if @var{flag} is false, it is
307 unregistered. For example, after registering the function @code{last_words}
308 above,
309 
310 @example
311 atexit ("last_words", false);
312 @end example
313 
314 @noindent
315 will remove the function from the list and Octave will not call
316 @code{last_words} when it exits.
317 
318 Note that @code{atexit} only removes the first occurrence of a function
319 from the list, so if a function was placed in the list multiple times with
320 @code{atexit}, it must also be removed from the list multiple times.
321 @seealso{quit}
322 @end deftypefn */)
323 {
324  int nargin = args.length ();
325 
326  if (nargin < 1 || nargin > 2)
327  print_usage ();
328 
329  std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string");
330 
331  bool add_mode = (nargin == 2)
332  ? args(1).xbool_value ("atexit: FLAG argument must be a logical value")
333  : true;
334 
336 
337  if (add_mode)
339  else
340  {
341  bool found = octave_remove_atexit_function (arg);
342 
343  if (nargout > 0)
344  retval = ovl (found);
345  }
346 
347  return retval;
348 }
349 
350 // Execute commands from a file and catch potential exceptions in a consistent
351 // way. This function should be called anywhere we might parse and execute
352 // commands from a file before we have entered the main loop in
353 // toplev.cc.
354 
355 static void
356 safe_source_file (const std::string& file_name,
357  const std::string& context = "",
358  bool verbose = false, bool require_file = true,
359  const std::string& warn_for = "")
360 {
361  try
362  {
363  source_file (file_name, context, verbose, require_file, warn_for);
364  }
365  catch (const octave::index_exception& e)
366  {
368 
369  std::cerr << "error: index exception in " << file_name << ": "
370  << e.message () << std::endl;
371  }
372  catch (const octave::exit_exception& ex)
373  {
375 
376  clean_up_and_exit (ex.exit_status (), ex.safe_to_return ());
377  }
378  catch (const octave::interrupt_exception&)
379  {
381  }
382  catch (const octave::execution_exception&)
383  {
385 
386  std::cerr << "error: execution exception in " << file_name << std::endl;
387  }
388 }
389 
390 static void
391 execute_pkg_add (const std::string& dir)
392 {
393  std::string file_name = octave::sys::file_ops::concat (dir, "PKG_ADD");
394 
395  try
396  {
398  }
399  catch (const octave::index_exception& e)
400  {
402 
403  std::cerr << "error: index exception in " << file_name << ": "
404  << e.message () << std::endl;
405  }
406  catch (const octave::exit_exception& ex)
407  {
409 
410  clean_up_and_exit (ex.exit_status (), ex.safe_to_return ());
411  }
412  catch (const octave::interrupt_exception&)
413  {
415  }
416  catch (const octave::execution_exception&)
417  {
419 
420  std::cerr << "error: execution exception in " << file_name << std::endl;
421  }
422 }
423 
424 static void
425 initialize_load_path (bool set_initial_path)
426 {
427  // Temporarily set the execute_pkg_add function to one that catches
428  // exceptions. This is better than wrapping load_path::initialize in
429  // a try-catch block because it will not stop executing PKG_ADD files
430  // at the first exception. It's also better than changing the default
431  // execute_pkg_add function to use safe_source file because that will
432  // normally be evaluated from the normal intepreter loop where
433  // exceptions are already handled.
434 
436 
438 
439  load_path::set_add_hook (execute_pkg_add);
440 
441  load_path::initialize (set_initial_path);
442 }
443 
444 // Initialize by reading startup files.
445 
446 static void
447 execute_startup_files (bool read_site_files, bool read_init_files,
448  bool verbose_flag, bool inhibit_startup_message)
449 {
451 
453 
454  bool verbose = (verbose_flag && ! inhibit_startup_message);
455 
456  bool require_file = false;
457 
458  if (read_site_files)
459  {
460  // Execute commands from the site-wide configuration file.
461  // First from the file $(prefix)/lib/octave/site/m/octaverc
462  // (if it exists), then from the file
463  // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
464 
465  safe_source_file (Vlocal_site_defaults_file, context, verbose,
466  require_file);
467 
468  safe_source_file (Vsite_defaults_file, context, verbose, require_file);
469  }
470 
471  if (read_init_files)
472  {
473  // Try to execute commands from $HOME/$OCTAVE_INITFILE and
474  // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
475  // .octaverc is assumed.
476 
477  bool home_rc_already_executed = false;
478 
479  std::string initfile = octave::sys::env::getenv ("OCTAVE_INITFILE");
480 
481  if (initfile.empty ())
482  initfile = ".octaverc";
483 
485 
486  std::string home_rc = octave::sys::env::make_absolute (initfile, home_dir);
487 
488  std::string local_rc;
489 
490  if (! home_rc.empty ())
491  {
492  safe_source_file (home_rc, context, verbose, require_file);
493 
494  // Names alone are not enough.
495 
496  octave::sys::file_stat fs_home_rc (home_rc);
497 
498  if (fs_home_rc)
499  {
500  // We want to check for curr_dir after executing home_rc
501  // because doing that may change the working directory.
502 
503  local_rc = octave::sys::env::make_absolute (initfile);
504 
505  home_rc_already_executed = same_file (home_rc, local_rc);
506  }
507  }
508 
509  if (! home_rc_already_executed)
510  {
511  if (local_rc.empty ())
512  local_rc = octave::sys::env::make_absolute (initfile);
513 
514  safe_source_file (local_rc, context, verbose, require_file);
515  }
516  }
517 }
518 
519 namespace octave
520 {
521  tree_evaluator *current_evaluator = 0;
522 
523  interpreter::interpreter (application *app_context, bool embedded)
524  : m_app_context (app_context), m_evaluator (new tree_evaluator (this)),
525  m_embedded (embedded), m_interactive (false),
526  m_quitting_gracefully (false)
527  {
528  current_evaluator = m_evaluator;
529 
530  cmdline_options options = m_app_context->options ();
531 
532  // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting
533  setlocale (LC_NUMERIC, "C");
534  setlocale (LC_TIME, "C");
535  octave::sys::env::putenv ("LC_NUMERIC", "C");
536  octave::sys::env::putenv ("LC_TIME", "C");
537 
538  // Initialize the default floating point unit control state.
540 
541  string_vector all_args = options.all_args ();
542 
544 
546 
547  // Initialize default warning state before --traditional option
548  // that may reset them.
549 
551 
552  if (options.traditional ())
554 
555  octave_ieee_init ();
556 
557  // The idea here is to force xerbla to be referenced so that we will link to
558  // our own version instead of the one provided by the BLAS library. But
559  // octave::numeric_limits<double>::NaN () should never be -1, so we
560  // should never actually call xerbla. FIXME (again!): If this
561  // becomes a constant expression the test might be optimized away and
562  // then the reference to the function might also disappear.
563 
565  F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6));
566 
568 
569  if (! m_embedded)
571  else
572  quit_allowed = false;
573 
575 
576  install_types ();
577 
578  install_ops ();
579 
580  install_builtins ();
581 
582  install_classdef ();
583 
584  std::list<std::string> command_line_path = options.command_line_path ();
585 
586  for (std::list<std::string>::const_iterator it = command_line_path.begin ();
587  it != command_line_path.end (); it++)
589 
590  std::string exec_path = options.exec_path ();
591  if (! exec_path.empty ())
592  set_exec_path (exec_path);
593 
594  std::string image_path = options.image_path ();
595  if (! image_path.empty ())
596  set_image_path (image_path);
597 
598  if (options.no_window_system ())
600 
601  // Is input coming from a terminal? If so, we are probably interactive.
602 
603  // If stdin is not a tty, then we are reading commands from a pipe or
604  // a redirected file.
605  bool stdin_is_tty = octave_isatty_wrapper (fileno (stdin));
606 
607  m_interactive = (! m_embedded
608  && ! m_app_context->is_octave_program ()
609  && stdin_is_tty
610  && octave_isatty_wrapper (fileno (stdout)));
611 
612  // Check if the user forced an interactive session.
613  if (options.forced_interactive ())
614  m_interactive = true;
615 
616  bool line_editing = options.line_editing ();
617  if ((! m_interactive || options.forced_interactive ())
618  && ! options.forced_line_editing ())
619  line_editing = false;
620 
621  // Force default line editor if we don't want readline editing.
622  if (! line_editing)
624 
625  // These can come after command line args since none of them set any
626  // defaults that might be changed by command line options.
627 
628  if (line_editing)
630 
631  octave_interpreter_ready = true;
632 
634 
635  // Make all command-line arguments available to startup files,
636  // including PKG_ADD files.
637 
638  app_context->intern_argv (options.all_args ());
639 
640  initialize_load_path (options.set_initial_path ());
641 
642  initialize_history (options.read_history_file ());
643  }
644 
645  interpreter::~interpreter (void)
646  {
647  current_evaluator = 0;
648 
649  delete m_evaluator;
650  }
651 
652  int interpreter::execute (void)
653  {
654  cmdline_options options = m_app_context->options ();
655 
656  if (m_interactive && ! options.inhibit_startup_message ())
657  std::cout << octave_startup_message () << "\n" << std::endl;
658 
660 
661  execute_startup_files (options.read_site_files (),
662  options.read_init_files (),
663  options.verbose_flag (),
664  options.inhibit_startup_message ());
665 
666  if (m_interactive && ! options.inhibit_startup_message ()
668  std::cout << std::endl;
669 
670  // Execute any code specified with --eval 'CODE'
671  std::string code_to_eval = options.code_to_eval ();
672 
673  if (! code_to_eval.empty ())
674  {
675  int parse_status = 0;
676 
677  try
678  {
679  parse_status = execute_eval_option_code (code_to_eval);
680  }
681  catch (const octave::execution_exception&)
682  {
684 
685  parse_status = 1;
686  }
687 
688  if (! options.persist ())
689  {
690  m_quitting_gracefully = true;
691 
692  clean_up_and_exit (parse_status);
693  }
694  }
695 
696  // If there is an extra argument, see if it names a file to read.
697  // Additional arguments are taken as command line options for the script.
698 
699  if (m_app_context->have_script_file ())
700  {
701  // If we are running an executable script (#! /bin/octave) then
702  // we should only see the args passed to the script.
703 
704  int exit_status = 0;
705 
706  try
707  {
708  string_vector script_args = options.remaining_args ();
709 
710  m_app_context->intern_argv (script_args);
711 
712  execute_command_line_file (script_args[0]);
713  }
714  catch (const octave::execution_exception&)
715  {
717 
718  exit_status = 1;
719  }
720 
721  // Restore full set of args.
722  m_app_context->intern_argv (options.all_args ());
723 
724  if (! options.persist ())
725  {
726  m_quitting_gracefully = true;
727 
728  clean_up_and_exit (exit_status);
729  }
730  }
731 
732  // Avoid counting commands executed from startup or script files.
733 
735 
736  // Force input to be echoed if not really interactive,
737  // but the user has forced interactive behavior.
738 
739  if (options.forced_interactive ())
740  {
742 
743  // FIXME: is this the right thing to do?
745  }
746 
747  if (m_embedded)
748  {
749  // FIXME: Do we need to do any cleanup here before returning?
750  // If we don't, what will happen to Octave functions that have been
751  // registered to execute with atexit, for example?
752 
753  return 1;
754  }
755 
756  int retval = main_loop ();
757 
758  m_quitting_gracefully = true;
759 
760  clean_up_and_exit (retval, true);
761 
762  return retval;
763  }
764 
765  int interpreter::execute_eval_option_code (const std::string& code)
766  {
768 
770 
771  octave::can_interrupt = true;
772 
776 
778 
779  octave_initialized = true;
780 
781  frame.add_method (this, &interpreter::interactive, m_interactive);
782 
783  m_interactive = false;
784 
785  int parse_status = 0;
786 
787  try
788  {
789  eval_string (code, false, parse_status, 0);
790  }
791  catch (const octave::exit_exception& ex)
792  {
794 
795  clean_up_and_exit (ex.exit_status (), ex.safe_to_return ());
796  }
797  catch (const octave::interrupt_exception&)
798  {
800  }
801  catch (const octave::execution_exception&)
802  {
804 
805  parse_status = 1;
806  }
807 
808  return parse_status;
809  }
810 
811  void interpreter::execute_command_line_file (const std::string& fname)
812  {
814 
816 
817  octave::can_interrupt = true;
818 
822 
824 
825  octave_initialized = true;
826 
827  frame.add_method (this, &interpreter::interactive, m_interactive);
828 
829  frame.add_method (m_app_context,
830  &application::program_invocation_name,
831  application::program_invocation_name ());
832 
833  frame.add_method (m_app_context,
834  &application::program_name,
835  application::program_name ());
836 
837  m_interactive = false;
838 
839  m_app_context->set_program_names (fname);
840 
842  bool verbose = false;
843  bool require_file = true;
844 
845  safe_source_file (fname, context, verbose, require_file, "octave");
846  }
847 
848  int interpreter::main_loop (void)
849  {
851 
852  octave::can_interrupt = true;
853 
857 
859 
860  octave_initialized = true;
861 
862  // The big loop.
863 
864  octave::lexer *lxr = (octave::application::interactive ()
865  ? new octave::lexer ()
866  : new octave::lexer (stdin));
867 
868  octave::parser parser (*lxr);
869 
870  int retval = 0;
871  do
872  {
873  try
874  {
876 
877  parser.reset ();
878 
881 
882  retval = parser.run ();
883 
884  if (retval == 0)
885  {
886  if (parser.stmt_list)
887  {
888  parser.stmt_list->accept (*current_evaluator);
889 
890  octave_quit ();
891 
892  if (! octave::application::interactive ())
893  {
894  bool quit = (tree_return_command::returning
896 
899 
902 
903  if (quit)
904  break;
905  }
906 
909  else
911  }
912  else if (parser.lexer.end_of_input)
913  break;
914  }
915  }
916  catch (const octave::exit_exception& ex)
917  {
919 
920  clean_up_and_exit (ex.exit_status (), ex.safe_to_return ());
921  }
922  catch (const octave::interrupt_exception&)
923  {
925 
926  // Required newline when the user does Ctrl+C at the prompt.
927  if (octave::application::interactive ())
928  octave_stdout << "\n";
929  }
930  catch (const octave::index_exception& e)
931  {
933 
934  std::cerr << "error: unhandled index exception: "
935  << e.message () << " -- trying to return to prompt"
936  << std::endl;
937  }
938  catch (const octave::execution_exception& e)
939  {
940  std::string stack_trace = e.info ();
941 
942  if (! stack_trace.empty ())
943  std::cerr << stack_trace;
944 
945  if (octave::application::interactive ())
947  else
948  {
949  // We should exit with a nonzero status.
950  retval = 1;
951  break;
952  }
953  }
954  catch (const std::bad_alloc&)
955  {
957 
958  std::cerr << "error: out of memory -- trying to return to prompt"
959  << std::endl;
960  }
961 
962 #if defined (DBSTOP_NANINF)
963  if (Vdebug_on_naninf)
964  {
965  if (setjump (naninf_jump) != 0)
966  debug_or_throw_exception (true); // true = stack trace
967  }
968 #endif
969  }
970  while (retval == 0);
971 
972  if (octave::application::interactive ())
973  octave_stdout << "\n";
974 
975  if (retval == EOF)
976  retval = 0;
977 
978  return retval;
979  }
980 
981  void interpreter::clean_up_and_exit (int status, bool safe_to_return)
982  {
983  static bool deja_vu = false;
984 
986 
987  while (! octave_atexit_functions.empty ())
988  {
989  std::string fcn = octave_atexit_functions.front ();
990 
991  octave_atexit_functions.pop_front ();
992 
994 
995  OCTAVE_SAFE_CALL (feval, (fcn, octave_value_list (), 0));
996 
998  }
999 
1000  if (! deja_vu)
1001  {
1002  deja_vu = true;
1003 
1004  // Process pending events and disasble octave_link event
1005  // processing with this call.
1006 
1008 
1009  // Do this explicitly so that destructors for mex file objects
1010  // are called, so that functions registered with mexAtExit are
1011  // called.
1013 
1015 
1016  // FIXME: is this needed? Can it cause any trouble?
1017  OCTAVE_SAFE_CALL (raw_mode, (0));
1018 
1020 
1023 
1025 
1027 
1029 
1031 
1033 
1035 
1037 
1039 
1040  if (! m_quitting_gracefully && octave::application::interactive ())
1041  {
1042  octave_stdout << "\n";
1043 
1044  // Yes, we want this to be separate from the call to
1045  // flush_octave_stdout above.
1046 
1048  }
1049 
1050  // Don't call singleton_cleanup_list::cleanup until we have the
1051  // problems with registering/unregistering types worked out. For
1052  // example, uncomment the following line, then use the make_int
1053  // function from the examples directory to create an integer
1054  // object and then exit Octave. Octave should crash with a
1055  // segfault when cleaning up the typinfo singleton. We need some
1056  // way to force new octave_value_X types that are created in
1057  // .oct files to be unregistered when the .oct file shared library
1058  // is unloaded.
1059  //
1060  // OCTAVE_SAFE_CALL (singleton_cleanup_list::cleanup, ());
1061 
1063  }
1064 
1065  if (octave_link::exit (status))
1066  {
1067  if (safe_to_return)
1068  return;
1069  else
1070  {
1071  // What should we do here? We might be called from some
1072  // location other than the end of octave::interpreter::execute
1073  // so it might not be safe to return.
1074 
1075  // We have nothing else to do at this point, and the
1076  // octave_link::exit function is supposed to take care of
1077  // exiting for us. Hang here forever so we never return.
1078 
1079  while (true)
1080  {
1081  octave_sleep (1);
1082  }
1083  }
1084  }
1085  else
1086  {
1087  if (octave_exit)
1088  (*octave_exit) (status);
1089  }
1090  }
1091 }
static void close_all_figures(void)
Definition: graphics.h:13959
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:803
volatile sig_atomic_t octave_signal_caught
Definition: cquit.c:66
static void unload_all_toolkits(void)
Definition: graphics.h:2294
void flush_octave_stdout(void)
Definition: pager.cc:454
void set_exec_path(const std::string &path_arg)
Definition: defaults.cc:250
OCTINTERP_API void octave_sleep(double seconds)
std::string Vsite_defaults_file
Definition: defaults.cc:93
bool octave_initialized
Definition: interpreter.cc:82
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
static void initialize_version_info(void)
Definition: interpreter.cc:129
Definition: Cell.h:37
void install_classdef(void)
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:1
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:130
static void putenv(const std::string &name, const std::string &value)
Definition: oct-env.cc:242
void(* octave_interrupt_hook)(void)=0
Definition: quit.cc:35
static bool at_top_level(void)
Definition: symtab.h:1300
static hook_fcn_ptr get_add_hook(void)
Definition: load-path.h:263
fname
Definition: load-save.cc:754
std::string octave_startup_message(bool html)
Definition: version.cc:118
void octave_set_default_fpucw(void)
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:347
void raw_mode(bool on, bool wait)
Definition: sysdep.cc:367
void octave_prepare_hdf5(void)
Definition: load-save.cc:1240
#define OCTAVE_RELEASE
Definition: defaults.h:190
OCTINTERP_API void initialize_default_warning_state(void)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API octave_value_list Fdisable_diagonal_matrix(const octave_value_list &=octave_value_list(), int=0)
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
OCTINTERP_API octave_value_list FPS1(const octave_value_list &=octave_value_list(), int=0)
interrupt_handler catch_interrupts(void)
Definition: sighandlers.cc:559
OCTINTERP_API octave_value_list Fconfirm_recursive_rmdir(const octave_value_list &=octave_value_list(), int=0)
void octave_restore_signal_mask(void)
static OCTAVE_NORETURN void lo_error_handler(const char *fmt,...)
Definition: interpreter.cc:142
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
OCTINTERP_API octave_value_list FPS4(const octave_value_list &=octave_value_list(), int=0)
void error(const char *fmt,...)
Definition: error.cc:570
static void reset_debug_state(void)
Definition: pt-eval.cc:123
void install_types(void)
Definition: ov.cc:2909
void(* octave_bad_alloc_hook)(void)=0
Definition: quit.cc:36
static std::list< std::string > octave_atexit_functions
Definition: interpreter.cc:213
static void set_command_line_path(const std::string &p)
Definition: load-path.h:272
static void restore_terminal_state(void)
Definition: cmd-edit.cc:1286
void set_image_path(const std::string &path)
Definition: defaults.cc:289
OCTINTERP_API octave_value_list Fpage_screen_output(const octave_value_list &=octave_value_list(), int=0)
octave_idx_type numel(void) const
Definition: oct-map.h:371
static void init(void)
void sysdep_cleanup(void)
Definition: sysdep.cc:346
static OCTAVE_API void clear(void)
Definition: oct-locbuf.cc:132
void add_method(T *obj, void(T::*method)(void))
static void clean_up_and_save(const std::string &="", int=-1)
Definition: cmd-hist.cc:768
OCTINTERP_API octave_value_list Fbeep_on_error(const octave_value_list &=octave_value_list(), int=0)
i e
Definition: data.cc:2724
static void increment_current_command_number(void)
Definition: cmd-edit.cc:1279
bool can_interrupt
Definition: sighandlers.cc:67
octave_value arg
Definition: pr-output.cc:3440
octave_function * fcn
Definition: ov-class.cc:1743
static void reset_current_command_number(int n)
Definition: cmd-edit.cc:1272
static std::string getenv(const std::string &name)
Definition: oct-env.cc:235
void octave_ieee_init(void)
Definition: lo-ieee.cc:221
OCTINTERP_API octave_value_list Fdisable_range(const octave_value_list &=octave_value_list(), int=0)
virtual std::string message(void) const
void initialize_history(bool read_history_file)
Definition: oct-hist.cc:532
void cleanup_tmp_files(void)
Definition: file-io.cc:125
void set_liboctave_warning_with_id_handler(liboctave_warning_with_id_handler f)
Definition: lo-error.c:92
This class gets nodes and searchs inside of 'info files'.
Definition: parser.h:52
OCTAVE_EXPORT octave_value_list search each directory of the loadpath for element of the cell array and return the first that matches If the second optional argument return a cell array containing the list of all files that have the same name in the path If no files are found
Definition: utils.cc:302
#define OCTAVE_RELEASE_DATE
Definition: version.h:47
JNIEnv void * args
Definition: ov-java.cc:67
OCTINTERP_API octave_value_list Fdisable_permutation_matrix(const octave_value_list &=octave_value_list(), int=0)
tree_evaluator * current_evaluator
#define DEFALIAS(alias, name)
Definition: defun.h:65
static int breaking
Definition: pt-jump.h:50
void install_ops(void)
Definition: ops.cc:135
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
Definition: oct-env.cc:129
bool verbose
Definition: load-save.cc:654
void set_liboctave_error_with_id_handler(OCTAVE_NORETURN liboctave_error_with_id_handler f)
Definition: lo-error.c:73
void verror_with_cfn(const char *fmt, va_list args)
Definition: error.cc:594
OCTINTERP_API octave_value_list Fhistory_timestamp_format_string(const octave_value_list &=octave_value_list(), int=0)
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
Definition: error.cc:624
static void initialize_error_handlers()
Definition: interpreter.cc:164
OCTINTERP_API void disable_warning(const std::string &id)
int octave_isatty_wrapper(int fd)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
void octave_throw_execution_exception(void)
Definition: quit.cc:69
void add_fcn(void(*fcn)(void))
OCTINTERP_API octave_value_list Fcrash_dumps_octave_core(const octave_value_list &=octave_value_list(), int=0)
void close_files(void)
Definition: file-io.cc:107
#define lexer
Definition: oct-parse.cc:152
static std::string get_home_directory(void)
Definition: oct-env.cc:143
octave_idx_type nfields(void) const
Definition: oct-map.h:326
void initialize_command_input(void)
Definition: input.cc:552
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
void octave_history_write_timestamp(void)
Definition: oct-hist.cc:543
void(* octave_exit)(int)
Definition: interpreter.cc:72
OCTINTERP_API octave_value_list Fecho_executing_commands(const octave_value_list &=octave_value_list(), int=0)
#define OCTAVE_SAFE_CALL(F, ARGS)
Definition: interpreter.h:67
static void execute_pkg_add(const std::string &dir)
Definition: load-path.cc:2233
int nargin
Definition: graphics.cc:10115
OCTINTERP_API bool octave_remove_atexit_function(const std::string &fname)
OCTAVE_API void clean_up_and_exit(int exit_status, bool safe_to_return)
Definition: quit.cc:52
sig_atomic_t octave_exception_state
Definition: cquit.c:60
void install_builtins(void)
Definition: builtins.cc:1818
void signal_handler(void)
Definition: sighandlers.cc:321
static void cleanup(void)
Definition: symtab.cc:1625
static void initialize(bool set_initial_path=false)
Definition: load-path.h:53
OCTINTERP_API octave_value_list Fsave_default_options(const octave_value_list &=octave_value_list(), int=0)
is false
Definition: cellfun.cc:398
void set_liboctave_warning_handler(liboctave_warning_handler f)
Definition: lo-error.c:83
octave_value retval
Definition: data.cc:6294
F77_RET_T F77_FUNC(xstopx, XSTOPX) const
Definition: f77-fcn.c:53
void octave_save_signal_mask(void)
std::string Vlocal_site_defaults_file
Definition: defaults.cc:92
void reset_error_handler(void)
Definition: error.cc:124
sig_atomic_t octave_interrupt_state
Definition: cquit.c:58
do not permute tem code
Definition: balance.cc:90
returns the type of the matrix and caches it for future use Called with more than one the function will not attempt to guess the type if it is still unknown This is useful for debugging purposes The possible matrix types depend on whether the matrix is full or and can be one of the following able sis tem and mark type as unknown tem as the structure of the matrix explicitly gives this(Sparse matrices only) tem code
Definition: matrix_type.cc:120
OCTINTERP_API octave_value_list Fprint_empty_dimensions(const octave_value_list &=octave_value_list(), int=0)
Definition: pr-output.cc:4065
static void force_default_editor(void)
Definition: cmd-edit.cc:1089
sig_atomic_t octave_interrupt_immediately
Definition: cquit.c:56
#define OCTAVE_VERSION
Definition: main.cc:49
feval(ar{f}, 1) esult
Definition: oct-parse.cc:8829
static std::string concat(const std::string &, const std::string &)
Definition: file-ops.cc:375
bool octave_interpreter_ready
Definition: interpreter.cc:79
OCTAVE_EXPORT octave_value_list F__version_info__(const octave_value_list &args, int)
Definition: interpreter.cc:88
void warning(const char *fmt,...)
Definition: error.cc:788
void set_liboctave_error_handler(OCTAVE_NORETURN liboctave_error_handler f)
Definition: lo-error.c:64
octave::unwind_protect frame
Definition: graphics.cc:11584
void recover_from_exception(void)
Definition: interpreter.cc:200
void(* octave_signal_hook)(void)=0
Definition: quit.cc:34
static void maximum_braindamage(void)
Definition: interpreter.cc:175
#define octave_stdout
Definition: pager.h:146
static int returning
Definition: pt-jump.h:106
static OCTAVE_NORETURN void lo_error_with_id_handler(const char *id, const char *fmt,...)
Definition: interpreter.cc:153
static void no_window_system(void)
Definition: display.h:85
void remove_input_event_hook_functions(void)
Definition: input.cc:130
void octave_finalize_hdf5(void)
Definition: load-save.cc:1248
p
Definition: lu.cc:138
static void blink_matching_paren(bool flag)
Definition: cmd-edit.cc:1293
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
Definition: variables.cc:1859
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol NaN(Not a Number).NaN is the result of operations which do not produce a well defined 0 result.Common operations which produce a NaN are arithmetic with infinity ex($\infty-\infty $)
static bool ignoring_entries(void)
Definition: cmd-hist.cc:600
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:547
OCTINTERP_API octave_value_list Ffixed_point_format(const octave_value_list &=octave_value_list(), int=0)
void initialize_file_io(void)
Definition: file-io.cc:90
OCTINTERP_API octave_value_list eval_string(const std::string &, bool silent, int &parse_status, int nargout)
interpreter(application *app_context=0, bool embedded=false)
void clear_mex_functions(void)
Definition: variables.cc:73
OCTINTERP_API octave_value_list FPS2(const octave_value_list &=octave_value_list(), int=0)
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
OCTINTERP_API void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true, const std::string &warn_for="")
bool octave_completion_matches_called
Definition: input.cc:102
bool quit_allowed
Definition: interpreter.cc:75
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
bool reading_startup_message_printed
Definition: oct-parse.cc:142
void set_default_prompts(void)
Definition: input.cc:136
void install_signal_handlers(void)
Definition: sighandlers.cc:604
static void set_add_hook(hook_fcn_ptr f)
Definition: load-path.h:266
OCTINTERP_API octave_value_list Fstruct_levels_to_print(const octave_value_list &=octave_value_list(), int=0)
Definition: ov-struct.cc:2104
OCTINTERP_API void octave_add_atexit_function(const std::string &fname)