23 #if defined (HAVE_CONFIG_H) 42 #include "builtin-defun-decls.h" 86 DEFUN (__version_info__, args, ,
107 vinfo.
assign (
"Name", args(0));
108 vinfo.
assign (
"Version", args(1));
109 vinfo.
assign (
"Release", args(2));
110 vinfo.
assign (
"Date", args(3));
155 error (
"quit: not supported in embedded mode");
159 if (args.length () > 0)
160 exit_status = args(0).nint_value ();
167 throw octave::exit_exception (exit_status);
214 int nargin = args.length ();
221 bool add_mode = (
nargin == 2)
222 ? args(1).xbool_value (
"atexit: FLAG argument must be a logical value")
247 static int safe_source_file (
const std::string& file_name,
250 bool require_file =
true,
257 catch (
const interrupt_exception&)
267 if (! stack_trace.empty ())
268 std::cerr << stack_trace;
278 static void execute_pkg_add (
const std::string& dir)
286 lp.execute_pkg_add (dir);
288 catch (
const interrupt_exception&)
298 static void initialize_version_info (
void)
305 args(0) =
"GNU Octave";
310 static void xerbla_abort (
void)
312 error (
"Fortran procedure terminated by call to XERBLA");
315 static void initialize_xerbla_error_handler (
void)
325 F77_FUNC (xerbla, XERBLA) (
"octave", 13 F77_CHAR_ARG_LEN (6));
327 typedef void (*xerbla_handler_ptr) (void);
329 typedef void (*octave_set_xerbla_handler_ptr) (xerbla_handler_ptr);
331 dynamic_library libs (
"");
336 =
reinterpret_cast<octave_set_xerbla_handler_ptr
> 337 (libs.search (
"octave_set_xerbla_handler"));
344 OCTAVE_NORETURN
static void 345 lo_error_handler (
const char *fmt, ...)
348 va_start (args, fmt);
355 OCTAVE_NORETURN
static void 356 lo_error_with_id_handler (
const char *
id,
const char *fmt, ...)
359 va_start (args, fmt);
366 static void initialize_error_handlers (
void)
379 : m_app_context (app_context),
381 m_help_system (*
this),
382 m_dynamic_loader (*
this),
388 m_stream_list (*
this),
390 m_url_handle_manager (),
391 m_cdef_manager (*
this),
393 m_interactive (
false),
394 m_read_site_files (true),
395 m_read_init_files (m_app_context != nullptr),
397 m_inhibit_startup_message (
false),
398 m_load_path_initialized (
false),
399 m_history_initialized (
false),
400 m_initialized (
false)
408 throw std::runtime_error
409 (
"only one Octave interpreter may be active");
414 setlocale (LC_NUMERIC,
"C");
415 setlocale (LC_TIME,
"C");
416 sys::env::putenv (
"LC_NUMERIC",
"C");
417 sys::env::putenv (
"LC_TIME",
"C");
435 initialize_xerbla_error_handler ();
437 initialize_error_handlers ();
444 bool line_editing =
false;
445 bool traditional =
false;
450 const cmdline_options&
options = m_app_context->options ();
457 m_app_context->intern_argv (args);
458 intern_nargin (args.
numel () - 1);
460 bool is_octave_program = m_app_context->is_octave_program ();
462 std::list<std::string> command_line_path =
options.command_line_path ();
464 for (
const auto& pth : command_line_path)
465 m_load_path.set_command_line_path (pth);
468 if (! exec_path.empty ())
469 m_environment.exec_path (exec_path);
472 if (! image_path.empty ())
473 m_environment.image_path (image_path);
475 if (
options.no_window_system ())
476 display_info::no_window_system ();
485 m_interactive = (! is_octave_program && stdin_is_tty
489 if (
options.forced_interactive ())
490 m_interactive =
true;
492 line_editing =
options.line_editing ();
493 if ((! m_interactive ||
options.forced_interactive ())
494 && !
options.forced_line_editing ())
495 line_editing =
false;
497 traditional =
options.traditional ();
504 (tree_evaluator::ECHO_SCRIPTS | tree_evaluator::ECHO_FUNCTIONS
505 | tree_evaluator::ECHO_ALL);
508 if (! docstrings_file.empty ())
509 Fbuilt_in_docstrings_file (*
this,
octave_value (docstrings_file));
512 if (! doc_cache_file.empty ())
516 if (! info_file.empty ())
520 if (! info_program.empty ())
530 if (! texi_macros_file.empty ())
531 Ftexi_macros_file (*
this,
octave_value (texi_macros_file));
538 command_editor::force_default_editor ();
543 initialize_version_info ();
549 maximum_braindamage ();
554 OCTAVE_THREAD_LOCAL interpreter *interpreter::instance =
nullptr;
556 interpreter::~interpreter (
void)
564 symbol_scope scope = m_symbol_table.current_scope ();
568 scope.assign (
".nargin.", nargs);
569 scope.mark_hidden (
".nargin.");
577 if (! m_history_initialized)
583 const cmdline_options&
options = m_app_context->options ();
585 read_history_file =
options.read_history_file ();
587 if (! read_history_file)
588 command_history::ignore_entries ();
594 command_history::ignore_entries ();
596 m_history_initialized =
true;
603 void interpreter::initialize_load_path (
bool set_initial_path)
605 if (! m_load_path_initialized)
611 const cmdline_options&
options = m_app_context->options ();
613 set_initial_path =
options.set_initial_path ();
625 unwind_protect
frame;
628 m_load_path.get_add_hook ());
630 m_load_path.set_add_hook (execute_pkg_add);
632 m_load_path.initialize (set_initial_path);
634 m_load_path_initialized =
true;
645 display_startup_message ();
659 initialize_load_path ();
661 m_initialized =
true;
667 int interpreter::execute (
void)
675 execute_startup_files ();
681 const cmdline_options&
options = m_app_context->options ();
683 if (m_app_context->have_eval_option_code ())
685 int status = execute_eval_option_code ();
688 exit_status = status;
698 if (m_app_context->have_script_file ())
700 int status = execute_command_line_file ();
703 exit_status = status;
709 if (
options.forced_interactive ())
710 command_editor::blink_matching_paren (
false);
715 command_editor::reset_current_command_number (1);
719 catch (
const exit_exception& ex)
721 return ex.exit_status ();
725 void interpreter::display_startup_message (
void)
const 727 bool inhibit_startup_message =
false;
731 const cmdline_options&
options = m_app_context->options ();
733 inhibit_startup_message =
options.inhibit_startup_message ();
736 if (m_interactive && ! inhibit_startup_message)
744 int interpreter::execute_startup_files (
void)
const 746 bool read_site_files = m_read_site_files;
747 bool read_init_files = m_read_init_files;
749 bool inhibit_startup_message = m_inhibit_startup_message;
753 const cmdline_options&
options = m_app_context->options ();
755 read_site_files =
options.read_site_files ();
756 read_init_files =
options.read_init_files ();
758 inhibit_startup_message =
options.inhibit_startup_message ();
763 bool require_file =
false;
780 exit_status = status;
786 exit_status = status;
795 bool home_rc_already_executed =
false;
797 std::string initfile = sys::env::getenv (
"OCTAVE_INITFILE");
799 if (initfile.empty ())
800 initfile =
".octaverc";
802 std::string home_dir = sys::env::get_home_directory ();
808 if (! home_rc.empty ())
814 exit_status = status;
818 sys::file_stat fs_home_rc (home_rc);
827 home_rc_already_executed =
same_file (home_rc, local_rc);
831 if (! home_rc_already_executed)
833 if (local_rc.empty ())
840 exit_status = status;
845 std::cout << std::endl;
852 int interpreter::execute_eval_option_code (
void)
854 const cmdline_options&
options = m_app_context->options ();
858 unwind_protect
frame;
874 m_interactive =
false;
876 int parse_status = 0;
880 eval_string (code_to_eval,
false, parse_status, 0);
882 catch (
const interrupt_exception&)
884 recover_from_exception ();
890 recover_from_exception ();
898 int interpreter::execute_command_line_file (
void)
900 const cmdline_options&
options = m_app_context->options ();
902 unwind_protect
frame;
925 &application::program_invocation_name,
926 application::program_invocation_name ());
929 &application::program_name,
930 application::program_name ());
932 m_interactive =
false;
939 m_app_context->intern_argv (script_args);
940 intern_nargin (script_args.
numel () - 1);
944 m_app_context->set_program_names (
fname);
948 bool require_file =
true;
953 int interpreter::main_loop (
void)
972 lexer *lxr = (application::interactive () ?
new lexer ()
973 : new lexer (stdin));
975 parser parser (*lxr);
986 if (m_symbol_table.at_top_level ())
987 tree_evaluator::reset_debug_state ();
993 if (parser.m_stmt_list)
995 parser.m_stmt_list->accept (m_evaluator);
999 if (! application::interactive ())
1001 bool quit = (tree_return_command::returning
1002 || tree_break_command::breaking);
1004 if (tree_return_command::returning)
1005 tree_return_command::returning = 0;
1007 if (tree_break_command::breaking)
1008 tree_break_command::breaking--;
1017 command_editor::increment_current_command_number ();
1019 else if (parser.m_lexer.m_end_of_input)
1026 catch (
const interrupt_exception&)
1028 recover_from_exception ();
1031 if (application::interactive ())
1034 catch (
const index_exception&
e)
1036 recover_from_exception ();
1038 std::cerr <<
"error: unhandled index exception: " 1039 <<
e.message () <<
" -- trying to return to prompt" 1046 if (! stack_trace.empty ())
1047 std::cerr << stack_trace;
1049 if (application::interactive ())
1050 recover_from_exception ();
1058 catch (
const std::bad_alloc&)
1060 recover_from_exception ();
1062 std::cerr <<
"error: out of memory -- trying to return to prompt" 1066 #if defined (DBSTOP_NANINF) 1067 if (Vdebug_on_naninf)
1069 if (setjump (naninf_jump) != 0)
1070 debug_or_throw_exception (
true);
1078 if (application::interactive ())
1090 #define OCTAVE_IGNORE_EXCEPTION(E) \ 1093 recover_from_exception (); \ 1095 std::cerr << "error: ignoring " #E " while preparing to exit" \ 1099 #define OCTAVE_SAFE_CALL(F, ARGS) \ 1104 unwind_protect frame; \ 1106 frame.protect_var (Vdebug_on_error); \ 1107 frame.protect_var (Vdebug_on_warning); \ 1109 Vdebug_on_error = false; \ 1110 Vdebug_on_warning = false; \ 1114 OCTAVE_IGNORE_EXCEPTION (const exit_exception&) \ 1115 OCTAVE_IGNORE_EXCEPTION (const interrupt_exception&) \ 1116 OCTAVE_IGNORE_EXCEPTION (const execution_exception&) \ 1117 OCTAVE_IGNORE_EXCEPTION (const std::bad_alloc&) \ 1121 void interpreter::cleanup (
void)
1131 while (! atexit_functions.empty ())
1135 atexit_functions.pop_front ();
1153 if (! command_history::ignoring_entries ())
1158 m_gtk_manager.unload_all_toolkits ();
1165 m_symbol_table.cleanup ();
1186 tree_evaluator& interpreter::get_evaluator (
void)
1191 stream_list& interpreter::get_stream_list (
void)
1193 return m_stream_list;
1196 url_handle_manager& interpreter::get_url_handle_manager (
void)
1198 return m_url_handle_manager;
1202 interpreter::get_current_scope (
void)
1204 return m_symbol_table.current_scope ();
1208 interpreter::require_current_scope (
const std::string& who)
1210 symbol_scope scope = get_current_scope ();
1213 error (
"%s: symbol table scope missing", who.c_str ());
1218 call_stack& interpreter::get_call_stack (
void)
1220 return m_evaluator.get_call_stack ();
1223 profiler& interpreter::get_profiler (
void)
1225 return m_evaluator.get_profiler ();
1230 call_stack&
cs = get_call_stack ();
1235 error (
"mlock: invalid use outside a function");
1244 if (
val.is_defined ())
1259 if (
val.is_defined ())
1270 void interpreter::recover_from_exception (
void)
1282 std::list<std::string> interpreter::atexit_functions;
1286 atexit_functions.push_front (
fname);
1293 for (
auto it = atexit_functions.begin ();
1294 it != atexit_functions.end (); it++)
1298 atexit_functions.erase (it);
1309 void interpreter::maximum_braindamage (
void)
1314 m_evaluator.PS4 (
"");
1323 Fhistory_timestamp_format_string (
octave_value (
"%%-- %D %I:%M %p --%%"));
static void close_all_figures(void)
OCTINTERP_API octave_value_list feval(const std::string &name, const octave_value_list &args=octave_value_list(), int nargout=0)
void warning_with_id(const char *id, const char *fmt,...)
volatile sig_atomic_t octave_signal_caught
is already an absolute the name is checked against the file system instead of Octave s loadpath In this if otherwise an empty string is returned If the first argument is a cell array of 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
bool same_file(const std::string &f, const std::string &g)
std::string octave_startup_message(bool html)
void octave_set_default_fpucw(void)
void assign(const std::string &k, const Cell &val)
static void recover_from_exception(void)
void octave_prepare_hdf5(void)
OCTINTERP_API void initialize_default_warning_state(void)
void octave_set_xerbla_handler(xerbla_handler_fptr fcn)
OCTINTERP_API void print_usage(void)
identity matrix If supplied two scalar respectively For allows like xample val
std::string xstring_value(const char *fmt,...) const
interrupt_handler catch_interrupts(void)
bool islocked(void) const
#define OCTAVE_SAFE_CALL(F, ARGS)
void octave_restore_signal_mask(void)
static void process_events(bool disable=false)
static string_vector make_absolute(const string_vector &sv)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
static octave_link * disconnect_link(bool delete_instance=true)
static llvm::LLVMContext & context
void sysdep_cleanup(void)
void respond_to_pending_signals(void)
void octave_ieee_init(void)
void initialize_history(bool read_history_file)
void cleanup_tmp_files(void)
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="")
void set_liboctave_warning_with_id_handler(liboctave_warning_with_id_handler f)
static void initialize(void)
std::string local_site_defaults_file(void)
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
void set_liboctave_error_with_id_handler(OCTAVE_NORETURN liboctave_error_with_id_handler f)
std::string concat(const std::string &dir, const std::string &file)
void verror_with_cfn(const char *fmt, va_list args)
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
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)
void octave_throw_execution_exception(void)
OCTINTERP_API octave_value_list eval_string(const std::string &, bool silent, int &parse_status, int nargout)
#define OCTAVE_RELEASE_DATE
void octave_history_write_timestamp(void)
OCTINTERP_API bool mislocked(const std::string &)
sig_atomic_t octave_exception_state
void set_liboctave_warning_handler(liboctave_warning_handler f)
void octave_save_signal_mask(void)
void(* octave_signal_hook)(void)
void reset_error_handler(void)
sig_atomic_t octave_interrupt_state
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
OCTINTERP_API void munlock(const std::string &)
std::string release(void)
load_path & __get_load_path__(const std::string &who)
octave_idx_type numel(void) const
F77_RET_T F77_FUNC(xerbla, XERBLA)
bool octave_interpreter_ready
OCTAVE_EXPORT octave_value_list F__version_info__(const octave_value_list &args, int)
octave_function * current(void) const
octave_idx_type nfields(void) const
void warning(const char *fmt,...)
void set_liboctave_error_handler(OCTAVE_NORETURN liboctave_error_handler f)
octave::unwind_protect frame
static bool confirm_shutdown(void)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
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 void add_atexit_function(const std::string &fname)
void octave_finalize_hdf5(void)
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
void add_method(T *obj, void(T::*method)(void))
std::string site_defaults_file(void)
interpreter(application *app_context=nullptr)
static bool remove_atexit_function(const std::string &fname)
void resize(const dim_vector &dv, bool fill=false)
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
void(* octave_interrupt_hook)(void)
void(* octave_bad_alloc_hook)(void)
Vector representing the dimensions (size) of an Array.
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
void install_signal_handlers(void)
OCTINTERP_API void mlock(void)