25 #if defined (HAVE_CONFIG_H) 55 cmdline_options::cmdline_options (
void)
57 m_all_args.resize (1);
61 cmdline_options::cmdline_options (
int argc,
char **
argv)
85 m_read_history_file =
false;
89 m_no_window_system =
true;
93 m_verbose_flag =
true;
102 m_read_init_files =
false;
103 m_read_site_files =
false;
111 m_forced_interactive =
true;
120 m_inhibit_startup_message =
true;
124 m_echo_commands =
true;
144 if (m_code_to_eval.empty ())
181 m_jit_compiler =
true;
185 m_forced_line_editing = m_line_editing =
true;
193 m_read_init_files =
false;
197 m_set_initial_path =
false;
201 m_line_editing =
false;
205 m_read_site_files = 0;
218 m_traditional =
true;
238 application::application (
int argc,
char **
argv)
244 application::application (
const cmdline_options& opts)
253 m_program_invocation_name =
pname;
257 m_program_name = (pos != std::string::npos) ?
pname.substr (pos+1) :
pname;
270 m_argv.resize (nargs);
273 m_argv[
i] = args[
i+1];
277 void application::interactive (
bool arg)
279 interpreter *interp = (instance ? instance->m_interpreter :
nullptr);
282 interp->interactive (
arg);
285 bool application::forced_interactive (
void)
287 return instance ? instance->m_options.forced_interactive () :
false;
290 bool application::interactive (
void)
292 interpreter *interp = (instance ? instance->m_interpreter :
nullptr);
294 return interp ? interp->interactive () :
false;
297 application::~application (
void)
301 delete m_interpreter;
306 bool application::interpreter_initialized (
void)
308 return m_interpreter ? m_interpreter->initialized () :
false;
311 interpreter& application::create_interpreter (
void)
314 m_interpreter =
new interpreter (
this);
316 return *m_interpreter;
319 void application::initialize_interpreter (
void)
322 m_interpreter->initialize ();
325 int application::execute_interpreter (
void)
327 return m_interpreter ? m_interpreter->execute () : -1;
330 void application::delete_interpreter (
void)
332 delete m_interpreter;
334 m_interpreter =
nullptr;
337 void application::init (
void)
340 throw std::runtime_error
341 (
"only one Octave application object may be active");
347 set_program_names (all_args[0]);
351 std::string code_to_eval = m_options.code_to_eval ();
353 m_have_script_file = ! remaining_args.
empty ();
355 m_have_eval_option_code = ! code_to_eval.empty ();
357 if (m_have_eval_option_code && m_have_script_file)
359 std::cerr << R
"(error: --eval "CODE" and script file are mutually exclusive options)" << std::endl; 364 if (m_options.gui ())
366 if (m_options.no_window_system ())
368 std::cerr <<
"error: --gui and --no-window-system are mutually exclusive options" << std::endl;
371 if (! m_options.line_editing ())
373 std::cerr <<
"error: --gui and --no-line-editing are mutually exclusive options" << std::endl;
379 m_is_octave_program = ((m_have_script_file || m_have_eval_option_code)
380 && ! m_options.persist ()
381 && ! m_options.traditional ());
387 int cli_application::execute (
void)
389 interpreter& interp = create_interpreter ();
391 int status = interp.execute ();
393 delete_interpreter ();
407 std::cerr <<
"warning: ignoring command line options for embedded octave\n";
410 return embedded_interpreter.
execute ();
414 std::cerr <<
"warning: octave_main should only be used to create an embedded interpreter";
416 static octave::cli_application app (
argc,
argv);
417 return app.execute ();
421 DEFUN (isguirunning, args, ,
434 return ovl (octave::application::is_gui_running ());
473 DEFUN (program_invocation_name, args, ,
488 return ovl (octave::application::program_invocation_name ());
496 DEFUN (program_name, args, ,
507 return ovl (octave::application::program_name ());
#define LINE_EDITING_OPTION
static std::string dir_sep_chars
static void octave_print_version_and_exit(void)
would return a cell array of strings with the elements for an example of how to create an executable Octave script nd deftypefn *return ovl(Cell(octave::application::argv()))
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define IMAGE_PATH_OPTION
#define NO_SITE_FILE_OPTION
int octave_main(int argc, char **argv, int embedded)
#define TRADITIONAL_OPTION
#define NO_LINE_EDITING_OPTION
#define TEXI_MACROS_FILE_OPTION
static void octave_print_terse_usage_and_exit(void)
#define panic_impossible()
char * octave_optarg_wrapper(void)
int octave_getopt_long_wrapper(int argc, char **argv, const char *shortopts, const struct octave_getopt_options *longopts, int *longind)
static const char * short_opts
struct octave_getopt_options long_opts[]
#define DOC_CACHE_FILE_OPTION
#define BUILT_IN_DOCSTRINGS_FILE_OPTION
static void octave_print_verbose_usage_and_exit(void)
int octave_optind_wrapper(void)
#define NO_INIT_PATH_OPTION
#define NO_INIT_FILE_OPTION
octave_idx_type numel(void) const
Number of elements in the 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
#define JIT_COMPILER_OPTION
octave_idx_type length(void) const
Number of elements in the array.