What is cmdline_options() used for and do we need it?

Reviewing the documentation for 7.1 release and the function cmdline_options is not documented. I can see with grep that there are a few places where it is used in the code, but I don’t know if these are legacy and could be removed or not.

The function also produces some strange output. Starting Octave with

octave -q --quiet

and then executing

x = cmdline_options
x.argv

shows long strings with what I assume are null bytes. It doesn’t look right to my eye.

The output looks OK, no long strings, but no member called x.argv.

$ octave -q --quiet
octave:1> x = cmdline_options 
x =

  scalar structure containing the fields:

    sys_argc = 3
    sys_argv =

/usr/local/libexec/octave/8.0.0/exec/x86_64-pc-linux-gnu/octave-gui
-q
--quiet

    echo_commands = 0
    forced_interactive = 0
    forced_line_editing = 0
    gui = 0
    inhibit_startup_message = 1
    line_editing = 1
    no_window_system = 0
    persist = 0
    read_history_file = 1
    read_init_files = 1
    read_site_files = 1
    server = 0
    set_initial_path = 1
    traditional = 0
    verbose_flag = 0
    code_to_eval = 
    command_line_path = 
    docstrings_file = 
    doc_cache_file = 
    exec_path = 
    image_path = 
    info_file = 
    info_program = 
    texi_macros_file = 
    all_args =

/usr/local/libexec/octave/8.0.0/exec/x86_64-pc-linux-gnu/octave-gui
-q
--quiet

    remaining_args = 

octave:2> x.argv
error: structure has no member 'argv'

Oops, my mistake. The field is sys_argv. The test code should be

x = cmdline_options ();
x.sys_argv
 octave -q --quiet
octave:1> x = cmdline_options ();
octave:2> x.sys_argv
ans =

/usr/local/libexec/octave/7.0.1/exec/x86_64-pc-linux-gnu/octave-gui
-q
--quiet

octave:3> ver
----------------------------------------------------------------------
GNU Octave Version: 7.0.1 (hg id: 363fb10055df)
GNU Octave License: GNU General Public License
Operating System: Linux 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Tue Nov 16 14:42:35 UTC 2021 x86_64
----------------------------------------------------------------------
no packages installed.
octave:4> 

I guess that could be used for something…

@dasergatskov: Do you see a lot of null bytes onscreen? I neglected to mention that I was using the CLI version of Octave rather than the GUI and something about the sys_argv displays horribly on my screen.

No. What you see is my cli (gnome terminal) cut and paste.

Also:

octave:3> length(x.sys_argv)
ans = 67

Are you running installed octave or ./run-octave from the build tree?

Same observation as @dasergatskov for OpenSUSE 15.3. in the respective installed (CLI, GUI) Octave development versions (7.0.1, 8.0.0). For the uninstalled ones (./run-octave) the output is longer, but no visible NULL characters either.

This seems to be related to my .octaverc startup file.

What happens if you add a .octaverc file to the directory where you start octave which has this single line?

more on;

I get the following:

For me there is no change in the behavior. The pager is on (checked with help eig for getting long output).

What does

PAGER

return?

I get

ans = less

EDIT: If I switch to more there are no longer nulls printed, although there are large blank sections.

My output is:

$ ./octave-cli-stable -q --quiet
>> PAGER
ans = less
>> x = cmdline_options ()
x =

  scalar structure containing the fields:

    sys_argc = 3
    sys_argv =

./octave-cli-stable
-q
--quiet

    echo_commands = 0
    forced_interactive = 0
    forced_line_editing = 0
    gui = 0
    inhibit_startup_message = 1
    line_editing = 1
    no_window_system = 0
    persist = 0
    read_history_file = 1
    read_init_files = 1
    read_site_files = 1
    server = 0
    set_initial_path = 1
    traditional = 0
    verbose_flag = 0
    code_to_eval = 
    command_line_path = 
    docstrings_file = 
    doc_cache_file = 
    exec_path = 
    image_path = 
    info_file = 
    info_program = 
    texi_macros_file = 
    all_args =

./octave-cli-stable
-q
--quiet

    remaining_args =

I have an .octaverc (I setup default fonts for the plots there).
Some unprintable chars in your .octaverc? Do you use some fancy
editor that leaves some UTF BOM there?
Do you the problem if you login as another user?

I get lot of NULLs if I set PAGER to “more” (on Ubuntu 20.10, less 551; more from util-linux 2.36.1).
I do not see difference on CentOS (less 530; more from more from util-linux 2.32.1)

P.S. And now I cannot reproduce it anymore…

And now I can reproduce by doing this:

octave:1> PAGER
ans = less
octave:2> PAGER = more
error: value on right hand side of assignment is undefined
octave:3> PAGER = "more"
PAGER = more
octave:4> x = cmdline_options ()
x =

  scalar structure containing the fields:

    sys_argc = 8
    sys_argv =

/home/uu1/src/octave/clang_opt/src/.libs/octave-gui^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

command 2 seems to be essential. But only on Ubuntu.

I have a better idea about what is going on now. The issue is that the sys_argv field is a charMatrix and the fill value is 0 rather than 32 (ASCII space).

For some pagers, in my case less, the pager renders char(0) as ^@. Other pagers, like more apparently substitute space for this case.

Additional things which made this hard to debug are that the pager has to be turned on more on AND the window has to be small enough that Octave chooses to redirect output through the pager rather than just displaying it onscreen. This is why I had issues with cmdline_options which displays an entire screenful of information, but not with

x = cmdline_options ();
x.sys_argv

which displayed only a few lines.

To switch between pagers you need to use PAGER as a function rather than a variable.

PAGER ("more");   # switch to more pager
PAGER
ans = more
PAGER ("less");   # switch to less pager
PAGER
ans = less

I know, but without this error I do not get @s.

octave:1> PAGER
ans = less
octave:2> PAGER("more")
octave:3> x = cmdline_options ()
x =

  scalar structure containing the fields:

    sys_argc = 8
    sys_argv =

/home/uu1/src/octave/clang_opt/src/.libs/octave-gui
--no-init-path
--path=/home/uu1/src/octave/clang_opt/../scripts:/home/uu1/src/octave/clang_opt/../scripts/deprecated:/home/uu1/src/octave/clang_opt/../scripts/testfun:/home/uu1/src/octave/clang_opt/../scripts/audio:/home/uu1/src/octave/clang_opt/../scripts/gui:/home/uu1/src/octave/clang_opt/../scripts/signal:/home/uu1/src/octave/clang_opt/../scripts/help:/home/uu1/src/

I see now that all I need is to turn pager on:

octave:1> more
octave:2> x = cmdline_options ()
x =

  scalar structure containing the fields:

    sys_argc = 8
    sys_argv =

/home/uu1/src/octave/clang_opt/src/.libs/octave-gui^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@

and that seems to reproducible on all platforms.

Also setting pager to more does not seem to work:
On Ubuntu 20.10 (and same on Fedora):

octave:1> PAGER("more")
octave:2> more on
octave:3> x = cmdline_options ()
more: invalid option -- 'X'
Try 'more --help' for more information.

On CentOS:

octave:1> PAGER("more")
octave:2> more on
octave:3> x = cmdline_options ()
more: unknown option -e
Try 'more --help' for more information.
octave:4>