Mercurial > octave
changeset 29152:556f20454064
make all command line option info available in scripting language
* octave.h, octave.cc (Fcmdline_options): New function.
(cmdline_options::as_octave_value): New function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 03 Dec 2020 12:28:59 -0500 |
parents | 6aa1440e415a |
children | 02ee34a30351 |
files | libinterp/octave.cc libinterp/octave.h |
diffstat | 2 files changed, 61 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave.cc Sat Dec 05 13:29:48 2020 -0500 +++ b/libinterp/octave.cc Thu Dec 03 12:28:59 2020 -0500 @@ -236,6 +236,43 @@ argc-octave_optind_wrapper ()); } + octave_value cmdline_options::as_octave_value (void) const + { + octave_scalar_map m; + + m.assign ("sys_argc", sys_argc ()); + m.assign ("sys_argv", string_vector (sys_argv ())); + m.assign ("debug_jit", debug_jit ()); + m.assign ("echo_commands", echo_commands ()); + m.assign ("forced_interactive", forced_interactive ()); + m.assign ("forced_line_editing", forced_line_editing ()); + m.assign ("gui", gui ()); + m.assign ("inhibit_startup_message", inhibit_startup_message ()); + m.assign ("jit_compiler", jit_compiler ()); + m.assign ("line_editing", line_editing ()); + m.assign ("no_window_system", no_window_system ()); + m.assign ("persist", persist ()); + m.assign ("read_history_file", read_history_file ()); + m.assign ("read_init_files", read_init_files ()); + m.assign ("read_site_files", read_site_files ()); + m.assign ("set_initial_path", set_initial_path ()); + m.assign ("traditional", traditional ()); + m.assign ("verbose_flag", verbose_flag ()); + m.assign ("code_to_eval", code_to_eval ()); + m.assign ("command_line_path", string_vector (command_line_path ())); + m.assign ("docstrings_file", docstrings_file ()); + m.assign ("doc_cache_file", doc_cache_file ()); + m.assign ("exec_path", exec_path ()); + m.assign ("image_path", image_path ()); + m.assign ("info_file", info_file ()); + m.assign ("info_program", info_program ()); + m.assign ("texi_macros_file", texi_macros_file ()); + m.assign ("all_args", all_args ()); + m.assign ("remaining_args", remaining_args ()); + + return m; + } + application *application::instance = nullptr; application::application (int argc, char **argv) @@ -436,6 +473,26 @@ %!error argv (1) */ +DEFUN (cmdline_options, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} argv () +Return a structure containing info about the command line arguments +passed to Octave. +@end deftypefn */) +{ + if (args.length () != 0) + print_usage (); + + octave::application *app = octave::application::app (); + + if (! app) + error ("invalid application context!"); + + octave::cmdline_options opts = app->options (); + + return ovl (opts.as_octave_value ()); +} + DEFUN (program_invocation_name, args, , doc: /* -*- texinfo -*- @deftypefn {} {} program_invocation_name ()
--- a/libinterp/octave.h Sat Dec 05 13:29:48 2020 -0500 +++ b/libinterp/octave.h Thu Dec 03 12:28:59 2020 -0500 @@ -33,6 +33,8 @@ #include "str-vec.h" +class octave_value; + namespace octave { // Command line arguments. See also options-usage.h. @@ -112,6 +114,8 @@ void all_args (const string_vector& arg) { m_all_args = arg; } void remaining_args (const string_vector& arg) { m_remaining_args = arg; } + octave_value as_octave_value (void) const; + private: // TRUE means enable debug tracing for the JIT compiler.