26 #if defined (HAVE_CONFIG_H)
49 #include "builtin-defun-decls.h"
94 DEFUN (__version_info__, args, ,
102 int nargin = args.
length ();
104 if (nargin != 0 && nargin != 4)
111 else if (nargin == 4)
115 vinfo.
assign (
"Name", args(0));
116 vinfo.
assign (
"Version", args(1));
117 vinfo.
assign (
"Release", args(2));
118 vinfo.
assign (
"Date", args(3));
174 int numel = args.length ();
186 exit_status = args(0).xnint_value (
"quit: STATUS must be an integer");
188 = args(1).xstring_value (
"quit: second argument must be a string");
193 error (R
"(quit: second argument must be string "force")");
197 if (args(0).is_string ())
200 = R
"(quit: option must be string "cancel" or "force")";
202 std::string opt = args(0).xstring_value (msg);
206 else if (opt ==
"force")
212 exit_status = args(0).xnint_value (
"quit: STATUS must be an integer");
219 if (interp.executing_finish_script ())
220 interp.cancel_quit (
true);
225 interp.quit (exit_status, force);
232 DEFMETHOD (atexit, interp, args, nargout,
272 int nargin = args.length ();
274 if (nargin < 1 || nargin > 2)
277 std::string arg = args(0).xstring_value (
"atexit: FCN argument must be a string");
279 bool add_mode = (nargin == 2)
280 ? args(1).xbool_value (
"atexit: FLAG argument must be a logical value")
286 interp.add_atexit_fcn (arg);
289 bool found = interp.remove_atexit_fcn (arg);
331 const std::string&
context =
"",
332 bool verbose =
false,
333 bool require_file =
true)
341 catch (
const interrupt_exception&)
364 args(0) =
"GNU Octave";
371 error (
"Fortran procedure terminated by call to XERBLA");
384 F77_FUNC (xerbla, XERBLA) (
"octave", 13 F77_CHAR_ARG_LEN (6));
386 typedef void (*xerbla_handler_ptr) (void);
388 typedef void (*octave_set_xerbla_handler_ptr) (xerbla_handler_ptr);
395 =
reinterpret_cast<octave_set_xerbla_handler_ptr
>
396 (libs.search (
"octave_set_xerbla_handler"));
403 OCTAVE_NORETURN
static void
407 va_start (args, fmt);
414 OCTAVE_NORETURN
static void
418 va_start (args, fmt);
438 : m_app_context (app_context),
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),
451 m_load_save_system (*this),
453 m_symbol_table (*this),
455 m_stream_list (*this),
457 m_url_handle_manager (),
458 m_cdef_manager (*this),
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),
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)
481 throw std::runtime_error
482 (
"only one Octave interpreter may be active");
487 setlocale (LC_ALL,
"");
488 setlocale (LC_NUMERIC,
"C");
489 setlocale (LC_TIME,
"C");
515 bool line_editing =
false;
516 bool traditional =
false;
535 for (
const auto& pth : command_line_path)
538 std::string exec_path = options.
exec_path ();
539 if (! exec_path.empty ())
542 std::string image_path = options.
image_path ();
543 if (! image_path.empty ())
566 line_editing =
false;
579 if (! docstrings_file.empty ())
580 Fbuilt_in_docstrings_file (*
this,
octave_value (docstrings_file));
583 if (! doc_cache_file.empty ())
586 std::string info_file = options.
info_file ();
587 if (! info_file.empty ())
591 if (! info_program.empty ())
601 if (! texi_macros_file.empty ())
602 Ftexi_macros_file (*
this,
octave_value (texi_macros_file));
660 if (! read_history_file)
773 exit_status = status;
788 exit_status = status;
800 catch (
const exit_exception& ex)
802 return ex.exit_status ();
811 #define OCTAVE_IGNORE_EXCEPTION(E) \
814 recover_from_exception (); \
816 std::cerr << "error: ignoring " #E " while preparing to exit" \
820 #define OCTAVE_SAFE_CALL(F, ARGS) \
825 unwind_protect frame; \
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 ()); \
834 m_error_system.debug_on_error (false); \
835 m_error_system.debug_on_warning (false); \
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&) \
989 bool require_file =
false;
1006 exit_status = status;
1012 exit_status = status;
1019 std::string ff_startup_m =
file_in_path (
"startup.m",
"");
1021 if (! ff_startup_m.empty ())
1023 int parse_status = 0;
1027 eval_string (std::string (
"startup"),
false, parse_status, 0);
1029 catch (
const interrupt_exception&)
1050 if (! cfg_rc.empty ())
1056 exit_status = status;
1063 bool home_rc_already_executed =
false;
1067 if (initfile.empty ())
1068 initfile =
".octaverc";
1074 std::string local_rc;
1076 if (! home_rc.empty ())
1082 exit_status = status;
1095 home_rc_already_executed =
same_file (home_rc, local_rc);
1099 if (! home_rc_already_executed)
1101 if (local_rc.empty ())
1108 exit_status = status;
1113 std::cout << std::endl;
1131 int parse_status = 0;
1135 eval_string (code_to_eval,
false, parse_status, 0);
1137 catch (
const interrupt_exception&)
1150 return parse_status;
1188 std::string fname = script_args[0];
1194 bool require_file =
true;
1206 int exit_status = 0;
1212 #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
1213 static bool use_command_line_push_parser =
true;
1215 static bool use_command_line_push_parser =
false;
1223 std::shared_ptr<base_parser> repl_parser;
1227 if (use_command_line_push_parser)
1230 repl_parser = std::shared_ptr<base_parser> (pp);
1235 repl_parser = std::shared_ptr<base_parser> (pp);
1241 repl_parser = std::shared_ptr<base_parser> (pp);
1250 repl_parser->reset ();
1258 exit_status = repl_parser->run ();
1260 if (exit_status == 0)
1262 std::shared_ptr<tree_statement_list>
1263 stmt_list = repl_parser->statement_list ();
1271 else if (repl_parser->at_end_of_input ())
1278 catch (
const interrupt_exception&)
1290 std::cerr <<
"error: unhandled index exception: "
1291 << e.message () <<
" -- trying to return to prompt"
1308 catch (
const std::bad_alloc&)
1312 std::cerr <<
"error: out of memory -- trying to return to prompt"
1316 while (exit_status == 0);
1318 if (exit_status == EOF)
1362 error (
"%s: symbol table scope missing", who.c_str ());
1379 error (
"%s: %s", dir.c_str (), std::strerror (errno));
1411 error (
"munlock: invalid value for NAME");
1432 error (
"mislocked: invalid value for NAME");
1460 bool silent,
int& parse_status,
1467 bool silent,
int& parse_status)
1473 bool silent,
int& parse_status,
1486 const std::string& catch_code,
1493 const std::string& try_code,
1500 const std::string& try_code,
1501 const std::string& catch_code,
1520 return feval (std::string (
name), args, nargout);
1530 error (
"feval: function '%s' not found",
name.c_str ());
1569 std::list<octave_value_list> arg_list;
1570 arg_list.push_back (args);
1579 return xval.
subsref (
"(", arg_list, nargout);
1586 error (
"feval: first argument must be a string, inline function, or a function handle");
1606 error (
"feval: first argument must be a string, inline function, or a function handle");
1612 return feval (f_arg, tmp_args, nargout);
1670 const std::string&
name,
1677 const std::string&
context,
bool verbose,
1845 bool cancel =
false;
1852 evalin (
"base",
"finish", 0);
1878 throw exit_exception (exit_status);
1960 catch (
const interrupt_exception&)
Vector representing the dimensions (size) of an Array.
void add_method(T *obj, void(T::*method)(Params...), Args &&... args)
bool have_script_file(void) const
bool is_octave_program(void) const
void intern_argv(const string_vector &args)
void set_program_names(const std::string &pname)
static std::string program_name(void)
bool have_eval_option_code(void) const
static std::string program_invocation_name(void)
cmdline_options options(void) const
bool read_site_files(void) const
std::string info_program(void) const
std::list< std::string > command_line_path(void) const
bool line_editing(void) const
bool traditional(void) const
bool inhibit_startup_message(void) const
std::string image_path(void) const
bool forced_line_editing(void) const
std::string doc_cache_file(void) const
std::string texi_macros_file(void) const
bool forced_interactive(void) const
std::string docstrings_file(void) const
bool read_init_files(void) const
string_vector remaining_args(void) const
bool debug_jit(void) const
bool read_history_file(void) const
bool no_window_system(void) const
std::string code_to_eval(void) const
std::string info_file(void) const
bool jit_compiler(void) const
std::string exec_path(void) const
bool echo_commands(void) const
bool set_initial_path(void) const
bool verbose_flag(void) const
string_vector all_args(void) const
static void blink_matching_paren(bool flag)
static void restore_terminal_state(void)
static void increment_current_command_number(void)
static void ignore_entries(bool=true)
static bool ignoring_entries(void)
static void clean_up_and_save(const std::string &="", int=-1)
octave_value exec_path(const octave_value_list &args, int nargout)
octave_value image_path(const octave_value_list &args, int nargout)
void save_exception(const execution_exception &e)
void display_exception(const execution_exception &e, std::ostream &os) const
octave_value beep_on_error(const octave_value_list &args, int nargout)
void directory_changed(const std::string &dir)
bool confirm_shutdown(void)
void process_events(bool disable=false)
void unload_all_toolkits(void)
void write_timestamp(void)
octave_value timestamp_format_string(const octave_value_list &args, int nargout)
void initialize(bool read_history_file=false)
bool is_variable(const std::string &name) const
history_system m_history_system
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
environment m_environment
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
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)
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)
std::list< std::string > top_level_variable_names(void)
std::list< std::string > m_atexit_fcns
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)
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
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
load_save_system m_load_save_system
bool mislocked(bool skip_first=false) const
void recover_from_exception(void)
void intern_nargin(octave_idx_type nargs)
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
void clear_global_variable_regexp(const std::string &pattern)
bool m_history_initialized
gh_manager * m_gh_manager
int execute_startup_files(void)
interpreter(application *app_context=nullptr)
bool m_executing_finish_script
stream_list m_stream_list
octave_value make_function_handle(const std::string &name)
stream_list & get_stream_list(void)
void read_init_files(bool flag)
octave_value top_level_varval(const std::string &name) const
void handle_exception(const execution_exception &e)
input_system m_input_system
void assignin(const std::string &context, const std::string &varname, const octave_value &val=octave_value())
tree_evaluator m_evaluator
symbol_table m_symbol_table
void clear_function_regexp(const std::string &pat)
bool at_top_level(void) const
void display_startup_message(void) const
bool interactive(void) const
static OCTAVE_THREAD_LOCAL interpreter * instance
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
void initialize_history(bool read_history_file=false)
bool m_load_path_initialized
void mark_for_deletion(const std::string &file)
int chdir(const std::string &dir)
symbol_scope get_current_scope(void) const
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
octave_value_list eval(const std::string &try_code, int nargout)
url_handle_manager m_url_handle_manager
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)
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)
octave_value find(const std::string &name)
void initialize(bool set_initial_path=false)
std::function< void(const std::string &)> get_add_hook(void)
void set_add_hook(const std::function< void(const std::string &)> &f)
void set_command_line_path(const std::string &p)
void execute_pkg_add(const std::string &dir)
octave_value crash_dumps_octave_core(const octave_value_list &args, int nargout)
octave_value save_default_options(const octave_value_list &args, int nargout)
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
void clear_function(const std::string &name)
std::list< std::string > user_function_names(void)
void clear_function_pattern(const std::string &pat)
void clear_functions(bool force=false)
void clear_function_regexp(const std::string &pat)
void clear_mex_functions(void)
static std::string getenv(const std::string &name)
static std::string get_home_directory(void)
static void putenv(const std::string &name, const std::string &value)
static std::string get_user_config_directory(void)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
static std::string get_current_directory(void)
static bool chdir(const std::string &newdir)
~temporary_file_list(void)
std::set< std::string > m_files
void insert(const std::string &file)
symbol_scope get_top_scope(void) const
void clear_symbol_pattern(const std::string &pattern)
bool at_top_level(void) const
void clear_global_variables(void)
void set_auto_fcn_var(stack_frame::auto_var_type avt, const octave_value &val=octave_value())
bool mislocked(bool skip_first=false) const
octave_value global_varval(const std::string &name) const
octave_value varval(const symbol_record &sym) const
std::list< std::string > autoloaded_functions(void) const
bool is_variable(const std::string &name) const
std::list< std::string > global_variable_names(void) const
bool is_global(const std::string &name) const
octave_value make_fcn_handle(const std::string &nm)
int dbstep_flag(void) const
void clear_variables(void)
void install_variable(const std::string &name, const octave_value &value, bool global)
void clear_symbol_regexp(const std::string &pattern)
void clear_global_variable_pattern(const std::string &pattern)
void clear_global_variable_regexp(const std::string &pattern)
std::string mfilename(const std::string &opt="") const
void mlock(bool skip_first=false) const
octave_value top_level_varval(const std::string &name) const
std::list< std::string > variable_names(void) const
void assignin(const std::string &context, const std::string &name, const octave_value &val=octave_value())
octave_value_list evalin(const std::string &context, const std::string &try_code, int nargout)
void top_level_assign(const std::string &name, const octave_value &val=octave_value())
void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
void clear_variable(const std::string &name)
void clear_variable_pattern(const std::string &pattern)
void clear_all(bool force=false)
octave_value find(const std::string &name)
void assign(const std::string &name, const octave_value &val=octave_value())
void clear_global_variable(const std::string &name)
octave_value PS4(const octave_value_list &args, int nargout)
void eval(std::shared_ptr< tree_statement_list > &stmt_list, bool interactive)
void clear_symbol(const std::string &name)
void reset_debug_state(void)
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
void munlock(bool skip_first=false) const
void global_assign(const std::string &name, const octave_value &val=octave_value())
void clear_variable_regexp(const std::string &pattern)
bool is_local_variable(const std::string &name) const
std::list< std::string > top_level_variable_names(void) const
octave_value echo(const octave_value_list &args, int nargout)
symbol_scope get_current_scope(void) const
profiler & get_profiler(void)
bool islocked(void) const
virtual octave_value_list call(octave::tree_evaluator &tw, int nargout=0, const octave_value_list &args=octave_value_list())
void resize(const dim_vector &dv, bool fill=false)
octave_idx_type nfields(void) const
octave_idx_type numel(void) const
void assign(const std::string &k, const Cell &val)
octave_idx_type length(void) const
octave_idx_type length(void) const
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
bool is_function(void) const
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
bool is_string(void) const
bool is_defined(void) const
bool is_function_handle(void) const
octave_function * function_value(bool silent=false) const
std::string string_value(bool force=false) const
bool is_undefined(void) const
bool is_inline_function(void) const
octave_idx_type numel(void) const
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
OCTAVE_EXPORT octave_value_list Fconfirm_recursive_rmdir(const octave_value_list &args, int nargout)
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
void verror_with_cfn(const char *fmt, va_list args)
void error(const char *fmt,...)
void disable_warning(const std::string &id)
void octave_set_default_fpucw(void)
#define OCTAVE_SAFE_CALL(F, ARGS)
OCTAVE_EXPORT octave_value_list F__version_info__(const octave_value_list &args, int)
bool octave_interpreter_ready
void set_liboctave_error_handler(OCTAVE_NORETURN liboctave_error_handler f)
void set_liboctave_warning_handler(liboctave_warning_handler f)
void set_liboctave_error_with_id_handler(OCTAVE_NORETURN liboctave_error_with_id_handler f)
void set_liboctave_warning_with_id_handler(liboctave_warning_with_id_handler f)
void octave_ieee_init(void)
std::string local_site_defaults_file(void)
std::string site_defaults_file(void)
std::string release(void)
std::string dir_sep_str(void)
std::string tilde_expand(const std::string &name)
void respond_to_pending_signals(void)
static void initialize_xerbla_error_handler(void)
static llvm::LLVMContext & context
interpreter & __get_interpreter__(const std::string &who)
void sysdep_cleanup(void)
static void xerbla_abort(void)
static OCTAVE_NORETURN void lo_error_with_id_handler(const char *id, const char *fmt,...)
static void initialize_error_handlers(void)
std::string file_in_path(const std::string &name, const std::string &suffix)
static void initialize_version_info(void)
sys::time Vlast_chdir_time
static OCTAVE_NORETURN void lo_error_handler(const char *fmt,...)
interrupt_handler catch_interrupts(void)
void source_file(const std::string &file_name, const std::string &context, bool verbose, bool require_file)
void install_signal_handlers(void)
bool same_file(const std::string &f, const std::string &g)
static int safe_source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
T::size_type numel(const T &str)
OCTAVE_EXPORT octave_value_list Fstruct_levels_to_print(const octave_value_list &args, int nargout)
octave_value::octave_value(const Array< char > &chm, char type) return retval
OCTAVE_EXPORT octave_value_list Fdisable_diagonal_matrix(const octave_value_list &args, int nargout)
OCTAVE_EXPORT octave_value_list Fdisable_permutation_matrix(const octave_value_list &args, int nargout)
OCTAVE_EXPORT octave_value_list Fdisable_range(const octave_value_list &args, int nargout)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
OCTAVE_EXPORT octave_value_list Ffixed_point_format(const octave_value_list &args, int nargout)
OCTAVE_EXPORT octave_value_list Fprint_empty_dimensions(const octave_value_list &args, int nargout)
OCTAVE_EXPORT octave_value_list Fjit_enable(const octave_value_list &args, int nargout)
OCTAVE_EXPORT octave_value_list Fdebug_jit(const octave_value_list &args, int nargout)
volatile sig_atomic_t octave_signal_caught
sig_atomic_t octave_interrupt_state
void(* octave_interrupt_hook)(void)
void(* octave_signal_hook)(void)
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")
std::string octave_startup_message(bool html)
#define OCTAVE_RELEASE_DATE
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DEF(s_arg
void octave_set_xerbla_handler(xerbla_handler_fptr fcn)