wxMaxima
Loading...
Searching...
No Matches
Data Structures | Functions
CommandLine.h File Reference

Turns wxMaxima's command line into settings, without needing a GUI. More...

#include <wx/cmdline.h>
#include <wx/string.h>
#include <optional>
#include <vector>
Include dependency graph for CommandLine.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  wxm::cmdline::Settings
 What the user asked for on the command line. More...
 

Functions

const wxCmdLineEntryDesc * wxm::cmdline::ParserDescription ()
 The wxCmdLineParser description, made from wxm::cmdline::Options.
 
std::vector< wxString > wxm::cmdline::DiffAliasArguments (const std::vector< wxString > &args)
 The arguments wxMaxima acts on, if it was started under this name.
 
void wxm::cmdline::SetArguments (wxCmdLineParser &parser, const std::vector< wxString > &args)
 Hands an argument vector (program first) to the parser, unmodified.
 
int wxm::cmdline::Parse (wxCmdLineParser &parser, const std::vector< wxString > &args, bool showUsage=true)
 Parses the arguments (program first) with wxMaxima's options.
 
wxString wxm::cmdline::CanonicalFileArgument (const wxString &arg)
 A file name from the command line, made absolute.
 
Settings wxm::cmdline::Interpret (const wxCmdLineParser &parser)
 Reads the settings out of a parser that has already run Parse()
 

Detailed Description

Turns wxMaxima's command line into settings, without needing a GUI.

main.cpp used to read each option straight out of its wxCmdLineParser in the middle of starting the application, which made the parsing impossible to test or fuzz on its own. Everything between "here are the arguments" and "here is what the user asked for" now lives here and needs nothing but wxBase, which is what test_CommandLine and the libFuzzer target fuzz_cmdline (test/fuzz/) build it with. main.cpp only acts on the result.

The options themselves are defined in CommandLineOptions.h.

Function Documentation

◆ CanonicalFileArgument()

wxString wxm::cmdline::CanonicalFileArgument ( const wxString &  arg)

A file name from the command line, made absolute.

A "#uuid" suffix, which addresses a cell inside a worksheet, is split off before the path is made absolute and appended again afterwards.

◆ DiffAliasArguments()

std::vector< wxString > wxm::cmdline::DiffAliasArguments ( const std::vector< wxString > &  args)

The arguments wxMaxima acts on, if it was started under this name.

The first entry is the program itself. If that is called wxmxdiff and no –diff/-d was given, a -d is inserted right behind it, so "wxmxdiff a b" compares a and b. Otherwise the arguments are returned unchanged. A "-d" after "--" is a file name, not the switch, and so is one that is the value of an option ("--ini -d").

This used to re-join the arguments into one string and have wxCmdLineParser split that again. That string's first word was the program, which wxCmdLineParser takes as a parameter (it supplies the program name itself), so wxmxdiff compared the wxMaxima executable with the files; and an argument containing a quote was mangled on the way. Passing the vector through keeps every argument exactly as it was.

◆ Interpret()

Settings wxm::cmdline::Interpret ( const wxCmdLineParser &  parser)

Reads the settings out of a parser that has already run Parse()

Only meaningful if Parse() returned 0; on an error main.cpp still looks at –single_process and –single_thread before it exits, so this doesn't refuse to run then.

◆ Parse()

int wxm::cmdline::Parse ( wxCmdLineParser &  parser,
const std::vector< wxString > &  args,
bool  showUsage = true 
)

Parses the arguments (program first) with wxMaxima's options.

Parameters
parserA parser that has no description yet: this sets it.
argsThe arguments, the program name first.
showUsagePrint the usage text along with an error message.
Returns
What wxCmdLineParser::Parse() returns: 0 on success, -1 if help was requested, a positive number on an error, which has been printed.

The same as SetDesc(), SetArguments() and Parse(), except for one argument wxCmdLineParser can't cope with: an option starting with "--" and a character that can't be part of an option name, such as "--+" or "--=x". wxWidgets (3.2 up to at least 3.3) looks up the option's name, finds it empty, and asks the empty name for its last character – a failed assertion, followed by a read in front of the string. Found by fuzz_cmdline. Such an argument is harmless where it is a value (after "--", or after an option that takes one), so whether it is in the place of an option is asked of wxCmdLineParser itself: the arguments are parsed once with it replaced by an option name of our own, and if the parser complains about that name, the argument is reported as an unknown option instead of being handed to the real parse.

◆ ParserDescription()

const wxCmdLineEntryDesc * wxm::cmdline::ParserDescription ( )

The wxCmdLineParser description, made from wxm::cmdline::Options.

Points to a static, wxCMD_LINE_NONE-terminated array that lives as long as the program.