![]() |
appkit
1.5.1
RoadNarrows Robotics Application Kit
|
CommandLine class. More...
#include <CommandLine.h>
Public Member Functions | |
| CommandLine (const std::string strName="cl", const std::string strPrompt="> ", bool bUseRlLib=true, bool bIgnoreCase=false) | |
| Default initialization constructor. More... | |
| virtual | ~CommandLine () |
| Destructor. | |
| bool | isDefined () const |
| bool | ok () const |
| Test if command-line interface is ok to continue. More... | |
| void | quit () |
| Mark command-line interface to quit. | |
| bool | getBtEnable () const |
| Test if backtracing is enabled. More... | |
| void | setBtEnable (bool bEnable) |
| Enable/disable backtracing. More... | |
| virtual int | addCommand (const CmdDesc &desc) |
| Add a command to the command line interface. More... | |
| virtual int | addCommand (const CmdDesc &desc, CmdExec1Func fnExec) |
| Add a command to the command line interface. More... | |
| virtual int | addCommand (const CmdDesc &desc, CmdExec2Func fnExec) |
| Add a command to the command line interface. More... | |
| virtual int | addCommand (const CmdDesc &desc, CmdExec3Func fnExec) |
| Add a command to the command line interface. More... | |
| virtual int | addCommand (const std::string strSyntax) |
| Add a command to the command line interface. More... | |
| virtual int | addCommand (const std::string strSyntax, CmdExec1Func fnExec) |
| Add a command to the command line interface. More... | |
| virtual int | addCommand (const std::string strSyntax, CmdExec2Func fnExec) |
| Add a command to the command line interface. More... | |
| virtual int | addCommand (const std::string strSyntax, CmdExec3Func fnExec) |
| Add a command to the command line interface. More... | |
| virtual int | removeCommand (const int uid) |
| Remove command from command line interface. More... | |
| virtual int | removeCommand (const std::string &strName) |
| Remove command from command line interface. More... | |
| virtual int | removeAllCommands () |
| Remove all commands from command line interface. More... | |
| virtual int | compile () |
| Compile all added commands. More... | |
| int | addDataSection (const std::string &ns, void *pData, DataSect::DeallocFunc fn=NULL) |
| Add a data section to the command-line interface. More... | |
| int | removeDataSection (const std::string &ns) |
| Remove a data section from the command-line interface. More... | |
| void * | getDataSection (const std::string &ns) |
| Get the section data under the specified namespace. More... | |
| bool | isReservedDataSection (const std::string &ns) const |
| Test if the namespace is a command-line interface reserved name. More... | |
| virtual int | readCommand (int &uid, int &iform, str::StringVec &argv) |
| Read an input line from stdin and match to the best compiled command. More... | |
| virtual int | readCommand (CmdExtArgVec &argv) |
| Read an input line from stdin and match to the best compiled command. More... | |
| virtual int | readCommand (FILE *fp, int &uid, int &iform, str::StringVec &argv) |
| Read an input line from file fp and match to the best compiled command. More... | |
| virtual int | readCommand (FILE *fp, CmdExtArgVec &argv) |
| Read an input line from file fp and match to the best compiled command. More... | |
| bool | kbhit () |
| bool | kbhit (FILE *fp) |
| virtual int | execute (const str::StringVec &argv) |
| Execute a comamnd with the given arguments. More... | |
| virtual int | execute (const CmdExtArgVec &argv) |
| Execute a comamnd with the given arguments. More... | |
| virtual void | addToHistory (const str::StringVec &argv) |
| Add command to history. More... | |
| virtual void | addToHistory (const CmdExtArgVec &argv) |
| Add command to history. More... | |
| void | pushPrompt (const std::string &strPrompt) |
| Push prompt string onto stack of prompts. More... | |
| void | popPrompt () |
| Pop prompt string from stack of prompts. More... | |
| const std::string & | getPrompt () const |
| Get the current prompt string. More... | |
| size_t | getLineNum () const |
| Get the line number of the last read line. More... | |
| void | setLineNum (const size_t uLineNum) |
| Set the current line number. More... | |
| void | resetLineNum () |
| Reset the line number to zero. | |
| int | numOfArgs (int uid, int iform) const |
| Get the total number of arguments. More... | |
| int | numOfArgs (const CmdExtArg &arg) const |
| Get the total number of arguments of matched command. More... | |
| int | numOfRequiredArgs (int uid, int iform) const |
| Get the total number of required arguments. More... | |
| int | numOfRequiredArgs (const CmdExtArg &arg) const |
| Get the total number of required arguments of matched command. More... | |
| int | numOfOptionalArgs (int uid, int iform) const |
| Get the total number of optional arguments. More... | |
| int | numOfOptionalArgs (const CmdExtArg &arg) const |
| Get the total number of arguments of matched command. More... | |
| const std::string & | getArgName (const CmdExtArg &arg) const |
| Get the argument name. More... | |
| CmdArgDef::ArgType | getArgDefType (const CmdExtArg &arg) const |
| Get the argument type. More... | |
| virtual ssize_t | tokenizeInput (const std::string &strInput, TokenVec &tokens) |
| Lexically analyze input string to generate a series of tokens. More... | |
| virtual ssize_t | tokenizeInput (const std::string &strInput, str::StringVec &tokens) |
| Lexically analyze input string to generate a series of string tokens. More... | |
| const std::string & | getName () const |
| Get command line interface's name. More... | |
| bool | hasCmd (const int uid) const |
| Test if command exists. More... | |
| bool | hasCmd (const std::string &strName) const |
| Test if command exists. More... | |
| const CmdDef & | at (const int uid) const |
| Get the command definition with the unique id. More... | |
| const CmdDef & | at (const std::string &strName) const |
| Get command definition with the argv0 name. More... | |
| const CmdDef & | operator[] (const int uid) const |
| Index operator. More... | |
| const CmdDef & | operator[] (const std::string &strName) const |
| Index operator. More... | |
| int | numOfCmds () const |
| Get the total number of added commands. More... | |
| CmdDefCIter | begin () const |
| Return a constant iterator pointing to the first element of the list of command definitions. More... | |
| CmdDefCIter | end () const |
| Return a constant iterator referring to the past-the-end element of the list of command definitions. More... | |
| const std::string & | getErrorStr () const |
| Get the most recent error. More... | |
| std::ostream & | backtrace (std::ostream &os, const bool bAll=false) const |
| Insert trace and error log backtrace into output stream. More... | |
Static Public Member Functions | |
| static std::string | c14n (const TokenVec &tokens) |
| Canonicalization of a string. More... | |
Protected Member Functions | |
| CmdDef & | cmdAt (const int uid) |
| Get modifiable command definition with the given unique id. More... | |
| CmdDef & | cmdAt (const std::string &strName) |
| Get modifiable command definition with the given argv0 name. More... | |
| virtual ssize_t | tokenizeSyntax (const std::string &strSyntax, TokenVec &tokens) |
| Lexically analyze extened usage syntax string to generate a series of tokens. More... | |
| virtual ssize_t | lexSyntaxWord (const std::string &strSyntax, ssize_t cursor, TokenVec &tokens) |
| Syntax word lexical analyzer. More... | |
| virtual ssize_t | lexSyntaxParenExpr (const std::string &strSyntax, ssize_t cursor, TokenVec &tokens) |
| Syntax parenthetical expression lexical analyzer. More... | |
| virtual ssize_t | lexWord (const std::string &strInput, ssize_t cursor, TokenVec &tokens) |
| Word lexical analyzer. More... | |
| virtual ssize_t | lexQuotedString (const std::string &strInput, ssize_t cursor, TokenVec &tokens) |
| Quoted string lexical analyzer. More... | |
| virtual void | logLexToken (const std::string &strSource, const size_t start, const ssize_t cursor, TokenVec &tokens, const bool bLoc=false) |
| Log lexigraphical token. More... | |
| void | pushToken (const std::string &strSource, const size_t start, const ssize_t cursor, TokenVec &tokens) |
| Push token to the end of the generated tokens. More... | |
| virtual int | compile (CmdDef &cmddef) |
| Compile a command. More... | |
| int | finalize () |
| Finalize command compilation. More... | |
| virtual int | parseSyntax (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens) |
| Parse command syntax. More... | |
| bool | parseArgv0 (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos) |
| Parse argument 0 (command name) syntax. More... | |
| bool | parseRequiredArgList (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos) |
| Parse required argument list syntax. More... | |
| bool | parseOptionalArgList (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos) |
| Parse optional argument list syntax. More... | |
| bool | parseArg (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos) |
| Parse argument syntax. More... | |
| bool | parseXorListArg (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos) |
| Parse mutually exclusive argument values syntax. More... | |
| bool | parseVariableArg (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos) |
| Parse variable argument syntax. More... | |
| bool | parseLiteralArg (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos) |
| Parse literal, fixed-valued argument syntax. More... | |
| bool | parseXorList (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos, str::StringVec &literals) |
| Parse mutually exclusive list. More... | |
| bool | parseIdentifier (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos, std::string &strIdent) |
| Parse identifier. More... | |
| bool | parseVarMod (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos, CmdArgDef::ArgType &eType, CmdArgDef::RangeVec &ranges, RegEx &re) |
| Parse variable modifier. More... | |
| bool | parseVarType (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos, CmdArgDef::ArgType &eType) |
| Parse variable type. More... | |
| bool | parseVarRangeExpr (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos, CmdArgDef::RangeVec &ranges) |
| Parse variable range expression. More... | |
| bool | parseVarRegExpr (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos, RegEx &re) |
| Parse variable regular expression. More... | |
| bool | parseLiteralValue (CmdDef &cmddef, CmdFormDef &form, const TokenVec &tokens, size_t &pos, std::string &strValue) |
| Parse literal value. More... | |
| bool | tokEq (const std::string strCmp, const TokenVec &tokens, size_t &pos) |
| Test if token at position is equal to string. More... | |
| bool | peekEq (const std::string strCmp, const Token &token) const |
| Peek if token is equal to string. More... | |
| bool | tokIdentifier (const TokenVec &tokens, size_t &pos) |
| Test if string has valid identifier syntax. More... | |
| int | processInput (const std::string &strLine, CmdExtArgVec &argv) |
| Process a line of input. More... | |
| int | match (const TokenVec &tokens, CmdExtArgVec &argv) |
| Match the input tokens to the compiled commands to find the best fit. More... | |
| int | matchCommand (const CmdDef &cmddef, const TokenVec &tokens, CmdExtArgVec &argv, double &fFitness) |
| Match best command form against input line argument list. More... | |
| int | matchCommandForm (const CmdFormDef &form, const TokenVec &tokens, CmdExtArgVec &argv, double &fFitness) |
| Match command form against input line argument list. More... | |
| int | checkReadResult () |
| Check read input result. More... | |
| void | toVec (const CmdExtArgVec &v1, str::StringVec &v2) |
| Convert extended argument vector to string argument vector. More... | |
| virtual int | rlBuildReadLineGenerator () |
| Perform any necessary pre-processing to prepare for command line TAB completion. More... | |
| virtual const std::string | rlGenerator (const std::string &strText, int nIndex, const std::string &strContext, int nStart, int nEnd, unsigned &uFlags) |
| TAB completion generator. More... | |
| void | rlArgDefs (const std::string &strSubtext, std::vector< CmdArgDef * > &argdefs) |
| Build list of all command argument definitions that match completed subtext. More... | |
| void | rlTabList (const std::string &strText, std::vector< CmdArgDef * > &argdefs, str::StringVec &tabList, unsigned &uFlags) |
| Build TAB completion list and set appropriate readline modifiers. More... | |
| bool | rlPartialMatch (const std::string &strText, const std::string strLiteral, const size_t uLen) |
| Match partial text agains literal string. More... | |
Static Protected Member Functions | |
| static const std::string | rlGeneratorWrapper (void *pAppArg, const std::string &strText, int nIndex, const std::string &strContext, int nStart, int nEnd, unsigned &uFlags) |
| Static TAB completion generator wrapper. More... | |
Protected Attributes | |
| std::string | m_strName |
| name of this command line | |
| bool | m_bIgnoreCase |
| do [not] ignore case on commands | |
| int | m_nUidCnt |
| unique id counter | |
| bool | m_bIsCompiled |
| has [not] been successfully compiled | |
| CmdDefMap | m_cmdDefs |
| map of added command definitions | |
| CmdExecMap | m_cmdExecs |
| map of added command executions | |
| PromptStack | m_prompts |
| stack of prompt strings | |
| ReadLine | m_readline |
| readline interface | |
| LogBook | m_log |
| trace and error log | |
| DataSectMap | m_dataSects |
| data sections | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const CommandLine &cl) |
| Insert object into output stream. More... | |
CommandLine class.
Definition at line 444 of file CommandLine.h.
| CommandLine::CommandLine | ( | const std::string | strName = "cl", |
| const std::string | strPrompt = "> ", |
||
| bool | bUseRlLib = true, |
||
| bool | bIgnoreCase = false |
||
| ) |
Default initialization constructor.
| strName | Name of command set and entry into readline's conditional parsing of the ~/.inputrc file. |
| strPrompt | Command line primary prompt string. Prompting occurs only in interactive mode. |
| bUseRlLib | Use the readline library. Note that readline must be available and in interactive mode. Otherwise a simple command-line interface will be used. |
| bIgnoreCase | Ignore case on comands and arguments. |
Definition at line 383 of file CommandLine.cxx.
References addDataSection(), rnr::cmd::DataSectNsCore, rnr::cmd::DataSectCore::dealloc(), m_bIsCompiled, m_nUidCnt, and pushPrompt().
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
Definition at line 414 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), LOGERROR_STREAM, rnr::cmd::CmdDesc::longdesc, m_cmdDefs, m_log, rnr::cmd::NoUid, rnr::cmd::CmdDesc::synopsis, and rnr::cmd::CmdDesc::syntax.
Referenced by addCommand(), rnr::cmd::addons::execBtEnable(), rnr::cmd::addons::execQuit(), execTAdd(), loadCommands(), and rnr::cmd::addons::printCmdHelp().
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
Definition at line 435 of file CommandLine.cxx.
References addCommand(), m_cmdExecs, and rnr::cmd::NoUid.
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
Definition at line 448 of file CommandLine.cxx.
References addCommand(), m_cmdExecs, and rnr::cmd::NoUid.
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
Definition at line 461 of file CommandLine.cxx.
References addCommand(), cmdAt(), rnr::eoe(), getErrorStr(), rnr::cmd::CmdDef::getUid(), LOGERROR_STREAM, m_bIsCompiled, m_cmdDefs, m_cmdExecs, m_log, m_nUidCnt, rnr::cmd::CmdDef::m_strSyntax, rnr::cmd::NoUid, rnr::cmd::CmdDef::pushForm(), rnr::cmd::CmdDef::setUid(), and rnr::str::split().
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
|
virtual |
Add a command to the command line interface.
The command syntax may specify multiple command forms, each separated by a newline '\n' character. The command named in each form must be the identical.
This is a light-weight function. A call to compile() is necessary to finalized command syntax processing.
| desc | Command description (see CmdDesc). |
| strSyntax | One or more extended usage syntax separated by newline characters. |
| fnExec | Command execution function of variant 1, 2, or 3. |
| int CommandLine::addDataSection | ( | const std::string & | ns, |
| void * | pData, | ||
| DataSect::DeallocFunc | fn = NULL |
||
| ) |
Add a data section to the command-line interface.
When the section is removed or the interface is deleted, the section data is automatically deleted if a deallocation function is specified. Otherwise, the user has responsibility to delete any data.
| ns | Namespace of data section. |
| pData | Pointer to data. |
| fn | Deallocator function. |
Definition at line 790 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::EBadVal, LOGERROR_STREAM, and m_dataSects.
Referenced by CommandLine().
|
virtual |
Add command to history.
Simple string argument version.
| argv | Command in argv vector. |
Definition at line 1039 of file CommandLine.cxx.
References rnr::str::c14n(), and m_readline.
Referenced by run().
|
virtual |
Add command to history.
Extended argument version.
| argv | Command in argv vector. |
Definition at line 1044 of file CommandLine.cxx.
References rnr::str::c14n(), m_readline, and toVec().
| const CmdDef & CommandLine::at | ( | const int | uid | ) | const |
Get the command definition with the unique id.
| uid | Command unique id. |
Definition at line 1889 of file CommandLine.cxx.
References m_cmdDefs, and rnr::cmd::nocmddef.
Referenced by checkCmd(), rnr::cmd::addons::execHelp(), execTDump(), execTRemove(), getArgDefType(), getArgName(), hasCmd(), numOfArgs(), numOfOptionalArgs(), and numOfRequiredArgs().
| const CmdDef& rnr::cmd::CommandLine::at | ( | const std::string & | strName | ) | const |
Get command definition with the argv0 name.
| strName | Command name. |
| ostream & CommandLine::backtrace | ( | std::ostream & | os, |
| const bool | bAll = false |
||
| ) | const |
Insert trace and error log backtrace into output stream.
| os | Output stream. |
| bAll | If true, backtrace all of log. Otherwise backtrace to last major execution mark. |
Definition at line 1952 of file CommandLine.cxx.
References rnr::cmd::isdquote(), lexQuotedString(), lexWord(), m_log, rnr::LogBook::NEWEST, rnr::LogBook::printLog(), rnr::LogBook::printToMark(), and tokenizeInput().
Referenced by execTBt(), loadCommands(), and readCommand().
|
inline |
Return a constant iterator pointing to the first element of the list of command definitions.
Definition at line 1119 of file CommandLine.h.
Referenced by rnr::cmd::addons::execHelp().
|
static |
Canonicalization of a string.
| tokens | Tokens to canonicalize. |
Definition at line 3174 of file CommandLine.cxx.
References rnr::io::deltaindent(), getPrompt(), rnr::cmd::ReadLine::haveRlLib(), rnr::io::indent(), m_bIgnoreCase, m_cmdDefs, m_cmdExecs, m_dataSects, m_readline, m_strName, numOfCmds(), operator<<(), rnr::str::prettify(), rnr::io::setindent(), and rnr::cmd::ReadLine::useRlLib().
Referenced by match().
|
protected |
Check read input result.
Definition at line 1506 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::EEoF, rnr::eoe(), rnr::cmd::ERead, rnr::cmd::ReadLine::getErrorStr(), rnr::cmd::ReadLine::isEoF(), rnr::cmd::ReadLine::isFError(), m_log, and m_readline.
Referenced by processInput().
|
protected |
Get modifiable command definition with the given unique id.
Protected version of at().
| uid | Command unique id. |
Definition at line 1918 of file CommandLine.cxx.
References m_cmdDefs, and rnr::cmd::nocmddef.
Referenced by addCommand(), execute(), match(), and removeCommand().
|
protected |
Get modifiable command definition with the given argv0 name.
Protected version of at().
| strName | Command name. |
|
virtual |
Compile all added commands.
Compiling essentially parses the command extended usage syntax and sets the internal data for:
Definition at line 627 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::bookmark(), rnr::LogBook::clear(), rnr::cmd::EError, rnr::eoe(), finalize(), getErrorStr(), LOGERROR_STREAM, m_bIsCompiled, m_cmdDefs, m_log, m_nUidCnt, m_readline, numOfCmds(), rnr::cmd::ReadLine::registerAltGenerator(), rlBuildReadLineGenerator(), and rlGeneratorWrapper().
Referenced by execTAdd(), execTCompile(), and loadCommands().
|
protectedvirtual |
Compile a command.
| cmddef | Command definition. |
Definition at line 701 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::bookmark(), rnr::LogBook::clear(), rnr::cmd::EBadSyntax, rnr::eoe(), rnr::cmd::CmdDef::formAt(), getErrorStr(), rnr::cmd::CmdFormDef::getIndex(), rnr::cmd::CmdDef::getName(), rnr::cmd::CmdFormDef::getSyntax(), rnr::cmd::CmdDef::getUid(), LOGERROR_STREAM, m_log, rnr::cmd::CmdDef::m_nUid, rnr::cmd::CmdDef::numOfForms(), parseSyntax(), rnr::cmd::CmdDef::reset(), and tokenizeSyntax().
|
inline |
Return a constant iterator referring to the past-the-end element of the list of command definitions.
Definition at line 1130 of file CommandLine.h.
References rnr::str::c14n(), and rnr::cmd::CmdExec::operator<<.
Referenced by rnr::cmd::addons::execHelp().
|
virtual |
Execute a comamnd with the given arguments.
| argv | The list of string arguments. |
Definition at line 984 of file CommandLine.cxx.
References cmdAt(), rnr::cmd::EBadSyntax, rnr::cmd::EUnknownCmd, rnr::cmd::CmdDef::getUid(), m_cmdExecs, and rnr::cmd::NoUid.
Referenced by run().
|
virtual |
Execute a comamnd with the given arguments.
| argv | The list of extended arguments. |
Definition at line 1018 of file CommandLine.cxx.
References rnr::cmd::EBadSyntax, rnr::cmd::EUnknownCmd, and m_cmdExecs.
|
protected |
Finalize command compilation.
Definition at line 757 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::EAmbigCmd, rnr::eoe(), getErrorStr(), rnr::cmd::CmdDef::getName(), rnr::cmd::CmdDef::getUid(), LOGERROR_STREAM, m_cmdDefs, and m_log.
Referenced by compile().
| CmdArgDef::ArgType CommandLine::getArgDefType | ( | const CmdExtArg & | arg | ) | const |
Get the argument type.
The extended argument contains matched command context.
| arg | Extended argument. |
Definition at line 1580 of file CommandLine.cxx.
References rnr::cmd::CmdExtArg::argIndex(), at(), rnr::cmd::CmdExtArg::formIndex(), rnr::cmd::CmdArgDef::getType(), and rnr::cmd::CmdExtArg::uid().
| const string & CommandLine::getArgName | ( | const CmdExtArg & | arg | ) | const |
Get the argument name.
The extended argument contains matched command context.
| arg | Extended argument. |
Definition at line 1572 of file CommandLine.cxx.
References rnr::cmd::CmdExtArg::argIndex(), at(), rnr::cmd::CmdExtArg::formIndex(), rnr::cmd::CmdArgDef::getName(), and rnr::cmd::CmdExtArg::uid().
|
inline |
Test if backtracing is enabled.
Definition at line 499 of file CommandLine.h.
References rnr::cmd::DataSectNsCore.
Referenced by readCommand().
| void * CommandLine::getDataSection | ( | const std::string & | ns | ) |
Get the section data under the specified namespace.
| ns | Namespace of data section to retrieve. |
Definition at line 830 of file CommandLine.cxx.
References m_dataSects.
| const string & CommandLine::getErrorStr | ( | ) | const |
Get the most recent error.
Definition at line 1947 of file CommandLine.cxx.
References rnr::LogBook::lastText(), and m_log.
Referenced by addCommand(), compile(), execTAdd(), execTCompile(), execTPrint(), execTRemove(), finalize(), lexSyntaxParenExpr(), lexSyntaxWord(), parseArg(), parseArgv0(), parseIdentifier(), parseLiteralValue(), parseSyntax(), parseVarMod(), parseVarRangeExpr(), parseVarRegExpr(), parseVarType(), parseXorList(), readCommand(), removeCommand(), tokEq(), and tokIdentifier().
|
inline |
Get the line number of the last read line.
Definition at line 853 of file CommandLine.h.
Referenced by pushToken(), and readCommand().
|
inline |
Get command line interface's name.
Definition at line 1040 of file CommandLine.h.
Referenced by execTPrint(), and readCommand().
| const string & CommandLine::getPrompt | ( | ) | const |
Get the current prompt string.
Definition at line 1071 of file CommandLine.cxx.
References m_prompts, and rnr::cmd::noprompt.
Referenced by c14n(), execTPrint(), and popPrompt().
| bool CommandLine::hasCmd | ( | const int | uid | ) | const |
Test if command exists.
| uid | Command unique id. |
Definition at line 1879 of file CommandLine.cxx.
References at(), and m_cmdDefs.
Referenced by execTAdd().
| bool rnr::cmd::CommandLine::hasCmd | ( | const std::string & | strName | ) | const |
Test if command exists.
| strName | Command name. |
| bool CommandLine::isReservedDataSection | ( | const std::string & | ns | ) | const |
Test if the namespace is a command-line interface reserved name.
| ns | Namespace. |
Definition at line 837 of file CommandLine.cxx.
References rnr::cmd::DataSectNsCore, rnr::cmd::DataSectNsNet, and rnr::cmd::DataSectNsOS.
Referenced by removeDataSection().
|
protectedvirtual |
Quoted string lexical analyzer.
The unescaped double quotes are not included in the token. Escape sequences interpreted.
On success, the generated <interp-char-seq> token is placed at the end of the vector.
| [in] | strInput | Input string to analyze. |
| [in] | cursor | Character position along input string. |
| [in,out] | tokens | Vector of generated tokens. |
Definition at line 2256 of file CommandLine.cxx.
References rnr::cmd::EBadSyntax, rnr::eoe(), rnr::cmd::isdquote(), logLexToken(), m_log, pushToken(), and rnr::cmd::tohex().
Referenced by backtrace().
|
protectedvirtual |
Syntax parenthetical expression lexical analyzer.
A syntax parenthetical expression isdefined as any contiguous sequence block of character delineated by a balanced pair of parentheses. A backslash escaped parenthesis does to factor into the paentheses countiog.
On success,the generated tokens '(', <paren-tok>, and ')' are placed at the end of the vector.
| [in] | strSyntax | Syntax string to analyze. |
| [in] | cursor | Character position along syntax string. |
| [in,out] | tokens | Vector of generated tokens. |
Definition at line 2137 of file CommandLine.cxx.
References rnr::cmd::EBadSyntax, rnr::eoe(), getErrorStr(), rnr::cmd::iscparen(), rnr::cmd::isoparen(), LOGERROR_STREAM, logLexToken(), m_log, and pushToken().
Referenced by tokenizeSyntax().
|
protectedvirtual |
Syntax word lexical analyzer.
A syntax word is defined as any contiguous sequence of non-whitespace, non-syntax-special symbol characters.
On success, the generated <word> token is placed at the end of the vector.
| [in] | strSyntax | Syntax string to analyze. |
| [in] | cursor | Character position along syntax string. |
| [in,out] | tokens | Vector of generated tokens. |
Definition at line 2104 of file CommandLine.cxx.
References rnr::cmd::EBadSyntax, rnr::eoe(), getErrorStr(), rnr::cmd::isspecial(), LOGERROR_STREAM, logLexToken(), m_log, and pushToken().
Referenced by tokenizeSyntax().
|
protectedvirtual |
Word lexical analyzer.
A word is defined as any contiguous sequence of non-whitespace characters.
On success, the generated <word> token is placed at the end of the vector.
| [in] | strInput | Input string to analyze. |
| [in] | cursor | Character position along input string. |
| [in,out] | tokens | Vector of generated tokens. |
Definition at line 2227 of file CommandLine.cxx.
References rnr::cmd::EBadSyntax, rnr::eoe(), logLexToken(), m_log, and pushToken().
Referenced by backtrace().
|
protectedvirtual |
Log lexigraphical token.
| strSource | Source string of tokens. | |
| start | Start token character position in source. | |
| cursor | Cursor position in source. | |
| [in,out] | tokens | Vector of lexical tokens. |
| bLoc | If true, then include line number and token characater positions. |
Definition at line 2370 of file CommandLine.cxx.
References rnr::eoe(), m_log, and pushToken().
Referenced by lexQuotedString(), lexSyntaxParenExpr(), lexSyntaxWord(), and lexWord().
|
protected |
Match the input tokens to the compiled commands to find the best fit.
| [in] | tokens | Vector of input tokens. |
| [out] | argv | Vector of extended arguments, with argv[0] being the command name argument. |
Definition at line 1128 of file CommandLine.cxx.
References rnr::cmd::AOk, c14n(), cmdAt(), rnr::cmd::EAmbigCmd, rnr::cmd::EArgv0, rnr::cmd::EError, rnr::eoe(), rnr::cmd::EUnknownCmd, rnr::cmd::CmdDef::formAt(), rnr::cmd::CmdFormDef::getSyntax(), m_cmdDefs, m_log, matchCommand(), rnr::cmd::NoIndex, and rnr::cmd::NoUid.
Referenced by processInput().
|
protected |
Match best command form against input line argument list.
| [in] | cmddef | Compiled command definition. |
| [in] | tokens | Vector of arguments. |
| [out] | argv | Vector of extended arguments, with argv[0] being the command name argument. |
| [out] | fFitness | Fitness of match [0.0 - 1.0]. |
Definition at line 1242 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::CmdFormDef::at(), rnr::cmd::CmdDef::at(), rnr::cmd::EArgv0, rnr::cmd::EBadSyntax, rnr::cmd::EError, rnr::eoe(), rnr::cmd::CmdDef::getName(), rnr::cmd::CmdFormDef::getSyntax(), m_log, rnr::cmd::CmdArgDef::match(), matchCommandForm(), rnr::cmd::NoIndex, and rnr::cmd::CmdDef::numOfForms().
Referenced by match().
|
protected |
Match command form against input line argument list.
| [in] | form | Compiled command form definition. |
| [in] | tokens | Vector of arguments. |
| [out] | argv | Vector of extended arguments, with argv[0] being the command name argument. |
| [out] | fFitness | Fitness of match [0.0 - 1.0]. |
Definition at line 1329 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::CmdArgDef::ArgTypeBoolean, rnr::cmd::CmdArgDef::ArgTypeFile, rnr::cmd::CmdArgDef::ArgTypeFpn, rnr::cmd::CmdArgDef::ArgTypeIdentifier, rnr::cmd::CmdArgDef::ArgTypeInteger, rnr::cmd::CmdArgDef::ArgTypeLiteral, rnr::cmd::CmdArgDef::ArgTypeMultiWord, rnr::cmd::CmdArgDef::ArgTypeRegEx, rnr::cmd::CmdArgDef::ArgTypeUndef, rnr::cmd::CmdArgDef::ArgTypeWord, rnr::cmd::CmdFormDef::at(), rnr::cmd::CmdArgDef::constructLiteralList(), rnr::cmd::CmdArgDef::constructRangeList(), rnr::cmd::CmdArgDef::convert(), rnr::cmd::EBadSyntax, rnr::cmd::EError, rnr::eoe(), rnr::cmd::CmdFormDef::getIndex(), rnr::cmd::CmdArgDef::getIndex(), rnr::cmd::CmdFormDef::getParentCmdUid(), rnr::cmd::CmdArgDef::getRanges(), rnr::cmd::CmdArgDef::getRegEx(), rnr::cmd::CmdArgDef::getType(), rnr::cmd::CmdArgDef::isOptional(), rnr::cmd::CmdArgDef::lookupArgSymbol(), m_bIgnoreCase, m_cmdDefs, m_log, rnr::cmd::CmdArgDef::match(), rnr::cmd::CmdFormDef::numOfArgs(), and rnr::cmd::CmdFormDef::numOfRequiredArgs().
Referenced by matchCommand().
| int CommandLine::numOfArgs | ( | int | uid, |
| int | iform | ||
| ) | const |
Get the total number of arguments.
The first argument (argv0) is the command.
| uid | Matched command unique id. |
| iform | Matched command form index. |
Definition at line 1542 of file CommandLine.cxx.
References rnr::cmd::CmdDef::at(), at(), and rnr::cmd::CmdFormDef::numOfArgs().
Referenced by numOfArgs().
| int CommandLine::numOfArgs | ( | const CmdExtArg & | arg | ) | const |
Get the total number of arguments of matched command.
The extended argument contains matched command context.
| arg | Extended argument. |
Definition at line 1547 of file CommandLine.cxx.
References at(), rnr::cmd::CmdExtArg::formIndex(), numOfArgs(), and rnr::cmd::CmdExtArg::uid().
|
inline |
Get the total number of added commands.
Definition at line 1108 of file CommandLine.h.
Referenced by c14n(), compile(), execTCompile(), execTPrint(), and readCommand().
| int CommandLine::numOfOptionalArgs | ( | int | uid, |
| int | iform | ||
| ) | const |
Get the total number of optional arguments.
Optional arguments start at argument index numOfRequiredArgs().
| uid | Matched command unique id. |
| iform | Matched command form index. |
Definition at line 1562 of file CommandLine.cxx.
References rnr::cmd::CmdDef::at(), at(), and rnr::cmd::CmdFormDef::numOfOptionalArgs().
Referenced by numOfOptionalArgs().
| int CommandLine::numOfOptionalArgs | ( | const CmdExtArg & | arg | ) | const |
Get the total number of arguments of matched command.
The extended argument contains matched command context.
| arg | Extended argument. |
Definition at line 1567 of file CommandLine.cxx.
References at(), rnr::cmd::CmdExtArg::formIndex(), numOfOptionalArgs(), and rnr::cmd::CmdExtArg::uid().
| int CommandLine::numOfRequiredArgs | ( | int | uid, |
| int | iform | ||
| ) | const |
Get the total number of required arguments.
The required number includes the command argv0.
Required arguments start at argument index 0.
| uid | Matched command unique id. |
| iform | Matched command form index. |
Definition at line 1552 of file CommandLine.cxx.
References rnr::cmd::CmdDef::at(), at(), and rnr::cmd::CmdFormDef::numOfRequiredArgs().
Referenced by checkCmd(), and numOfRequiredArgs().
| int CommandLine::numOfRequiredArgs | ( | const CmdExtArg & | arg | ) | const |
Get the total number of required arguments of matched command.
The extended argument contains matched command context.
The required number includes the command argv0.
Required arguments start at argument index 0.
| arg | Extended argument. |
Definition at line 1557 of file CommandLine.cxx.
References at(), rnr::cmd::CmdExtArg::formIndex(), numOfRequiredArgs(), and rnr::cmd::CmdExtArg::uid().
|
inline |
Test if command-line interface is ok to continue.
Definition at line 481 of file CommandLine.h.
References rnr::cmd::DataSectNsCore.
Referenced by run().
| const CmdDef& rnr::cmd::CommandLine::operator[] | ( | const int | uid | ) | const |
Index operator.
Get the command definition with the unique id.
| uid | Command unique id. |
| const CmdDef& rnr::cmd::CommandLine::operator[] | ( | const std::string & | strName | ) | const |
Index operator.
Get the command definition with the unique id.
| strName | Command name. |
|
protected |
Parse argument syntax.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
Definition at line 2605 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), LOGERROR_STREAM, m_log, rnr::str::okstr(), parseLiteralArg(), parseVariableArg(), parseXorListArg(), and peekEq().
Referenced by parseOptionalArgList(), and parseRequiredArgList().
|
protected |
Parse argument 0 (command name) syntax.
Argv0 is a special argument that defines the command name. Only literal and variable arguments types are valid.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
Definition at line 2470 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::ArgTypeLiteral, rnr::eoe(), rnr::cmd::CmdArgDef::FlagCommand, getErrorStr(), rnr::cmd::CmdFormDef::getIndex(), rnr::cmd::CmdDef::getName(), rnr::cmd::CmdArgDef::getName(), rnr::cmd::CmdArgDef::getType(), rnr::cmd::CmdFormDef::lastArg(), rnr::cmd::CmdArgDef::literalAt(), LOGERROR_STREAM, m_log, rnr::cmd::CmdFormDef::m_nArgcReq, rnr::str::okstr(), rnr::cmd::CmdArgDef::orFlags(), parseLiteralArg(), parseVariableArg(), peekEq(), and rnr::cmd::CmdDef::setName().
Referenced by parseSyntax().
|
protected |
Parse identifier.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from syntax usage. |
| [in,out] | pos | The parse cursor position. |
| [out] | strIdent | Identity string. |
Definition at line 2810 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), LOGERROR_STREAM, m_log, rnr::str::okstr(), and tokIdentifier().
Referenced by parseVariableArg().
|
protected |
Parse literal, fixed-valued argument syntax.
A CmdArgDef object is added to the CmdDef
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
Definition at line 2729 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::addLiteralValue(), rnr::cmd::CmdArgDef::ArgTypeLiteral, rnr::cmd::CmdFormDef::lastArg(), rnr::cmd::CmdFormDef::numOfArgs(), rnr::str::okstr(), parseLiteralValue(), rnr::cmd::CmdFormDef::pushArg(), rnr::cmd::CmdArgDef::setName(), and rnr::cmd::CmdArgDef::setType().
Referenced by parseArg(), and parseArgv0().
|
protected |
Parse literal value.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from syntax usage. |
| [in,out] | pos | The parse cursor position. |
| [out] | strValue | Value string. |
Definition at line 3079 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), LOGERROR_STREAM, m_log, and rnr::str::okstr().
Referenced by parseLiteralArg(), and parseXorList().
|
protected |
Parse optional argument list syntax.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
Definition at line 2569 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::FlagOptional, rnr::cmd::CmdFormDef::lastArg(), rnr::cmd::CmdFormDef::m_nArgcOpt, rnr::str::okstr(), rnr::cmd::CmdArgDef::orFlags(), parseArg(), peekEq(), and tokEq().
Referenced by parseSyntax().
|
protected |
Parse required argument list syntax.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
Definition at line 2540 of file CommandLine.cxx.
References rnr::cmd::CmdFormDef::m_nArgcReq, rnr::str::okstr(), parseArg(), and peekEq().
Referenced by parseSyntax().
|
protectedvirtual |
Parse command syntax.
The parsed, generated internal data are used for readline tab completion, input - command pattern matching, and first-level validation.
The parseSyntax() function [in]directly calls the CommandLine::parse family of member functions. Each function takes, at a minimum, four parameters:
| Parameter | Description |
|---|---|
| cmddef | Definition of an added command. It may be modified. |
| form | Definition of a command form. It may be modified. |
| tokens | Lexical tokens generated from the extended usage syntax. |
| pos | The parse cursor position. On input, it specifies |
| ^ | the starting position in the tokens vector. On a |
| ^ | succesful parse, the cursor position is advanced |
| ^ | to the first token after the relevant syntax block. |
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
Definition at line 2398 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::EBadSyntax, rnr::eoe(), getErrorStr(), rnr::cmd::CmdFormDef::getIndex(), rnr::cmd::CmdDef::getName(), rnr::cmd::CmdFormDef::getSyntax(), rnr::cmd::CmdDef::getUid(), LOGDIAG2_STREAM, LOGERROR_STREAM, m_log, rnr::cmd::CmdFormDef::numOfArgs(), rnr::str::okstr(), parseArgv0(), parseOptionalArgList(), and parseRequiredArgList().
Referenced by compile().
|
protected |
Parse variable argument syntax.
A CmdArgDef object is added to the CmdDef
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
Definition at line 2680 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::ArgTypeWord, rnr::cmd::CmdFormDef::lastArg(), rnr::str::okstr(), parseIdentifier(), parseVarMod(), peekEq(), rnr::cmd::CmdFormDef::pushArg(), rnr::cmd::CmdArgDef::setName(), rnr::cmd::CmdArgDef::setRanges(), rnr::cmd::CmdArgDef::setRegEx(), rnr::cmd::CmdArgDef::setType(), and tokEq().
Referenced by parseArg(), and parseArgv0().
|
protected |
Parse variable modifier.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
| [out] | eType | Type enum. |
| [out] | ranges | Vector of ranges. |
| [out] | re | Regular expression. |
Definition at line 2840 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::ArgTypeFpn, rnr::cmd::CmdArgDef::ArgTypeInteger, rnr::cmd::CmdArgDef::ArgTypeRegEx, rnr::eoe(), getErrorStr(), LOGERROR_STREAM, rnr::cmd::CmdArgDef::lookupArgSymbol(), m_log, rnr::str::okstr(), parseVarRangeExpr(), parseVarRegExpr(), parseVarType(), peekEq(), and tokEq().
Referenced by parseVariableArg().
|
protected |
Parse variable range expression.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
| [out] | ranges | Vector of ranges. |
Definition at line 2929 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), LOGERROR_STREAM, m_log, rnr::cmd::CmdArgDef::range::max, rnr::cmd::CmdArgDef::range::min, rnr::str::okstr(), rnr::str::split(), and rnr::str::todouble().
Referenced by parseVarMod().
|
protected |
Parse variable regular expression.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
| [out] | re | Regular expression. |
Definition at line 3032 of file CommandLine.cxx.
References rnr::eoe(), rnr::RegEx::getErrorStr(), getErrorStr(), rnr::RegEx::getRegEx(), rnr::RegEx::isValid(), LOGERROR_STREAM, m_bIgnoreCase, m_log, rnr::str::okstr(), rnr::RegEx::ReFlagICase, and rnr::RegEx::setFlags().
Referenced by parseVarMod().
|
protected |
Parse variable type.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
| [out] | eType | Type enum. |
Definition at line 2887 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::ArgTypeUndef, rnr::eoe(), getErrorStr(), LOGERROR_STREAM, rnr::cmd::CmdArgDef::lookupArgType(), m_log, and rnr::str::okstr().
Referenced by parseVarMod().
|
protected |
Parse mutually exclusive list.
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from syntax usage. |
| [in,out] | pos | The parse cursor position. |
| [out] | literals | Vector of literals. |
Definition at line 2761 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), LOGERROR_STREAM, m_log, rnr::str::okstr(), parseLiteralValue(), peekEq(), and tokEq().
Referenced by parseXorListArg().
|
protected |
Parse mutually exclusive argument values syntax.
A CmdArgDef object is added to the CmdDef
| [in,out] | cmddef | Command definition. |
| [in,out] | form | Command form definition. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The parse cursor position. |
Definition at line 2641 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::addLiteralValue(), rnr::cmd::CmdArgDef::ArgTypeLiteral, rnr::cmd::CmdArgDef::FlagXorList, rnr::cmd::CmdFormDef::lastArg(), rnr::cmd::CmdFormDef::numOfArgs(), rnr::str::okstr(), rnr::cmd::CmdArgDef::orFlags(), parseXorList(), rnr::cmd::CmdFormDef::pushArg(), rnr::cmd::CmdArgDef::setName(), rnr::cmd::CmdArgDef::setType(), and tokEq().
Referenced by parseArg().
|
inlineprotected |
Peek if token is equal to string.
The position cursor is not advance nor any error message logged.
| [in] | strCmp | String to compare token against. |
| [in] | token | Lexical token. |
Definition at line 1789 of file CommandLine.h.
References rnr::cmd::Token::value().
Referenced by parseArg(), parseArgv0(), parseOptionalArgList(), parseRequiredArgList(), parseVariableArg(), parseVarMod(), and parseXorList().
| void CommandLine::popPrompt | ( | ) |
Pop prompt string from stack of prompts.
The new top prompt string will be used for user prompting.
Definition at line 1058 of file CommandLine.cxx.
References getPrompt(), m_prompts, m_readline, rnr::cmd::noprompt, and rnr::cmd::ReadLine::setPrompt().
Referenced by execCliTest().
|
protected |
Process a line of input.
The line is tokenized and matched to the command with the best fit.
| [in] | strLine | Line of input. |
| [out] | argv | Vector of extended arguments, with argv[0] being the command name argument. |
Definition at line 1083 of file CommandLine.cxx.
References checkReadResult(), rnr::cmd::EBadSyntax, match(), and tokenizeInput().
Referenced by readCommand().
| void CommandLine::pushPrompt | ( | const std::string & | strPrompt | ) |
Push prompt string onto stack of prompts.
If in interactive mode, the user will be prompted with the prompt string found at the top of the prompt stack. If the stack or prompt string is empty, no prompt will be displayed. Any prompt is written to standard output (stdout).
| strPrompt | Prompt string. |
Definition at line 1052 of file CommandLine.cxx.
References m_prompts, m_readline, and rnr::cmd::ReadLine::setPrompt().
Referenced by CommandLine(), and execTPush().
|
protected |
Push token to the end of the generated tokens.
| strSource | Source string of tokens. | |
| start | Start token character position in source. | |
| cursor | Cursor position in source. | |
| [in,out] | tokens | Vector of lexical tokens. |
Definition at line 2383 of file CommandLine.cxx.
References getLineNum().
Referenced by lexQuotedString(), lexSyntaxParenExpr(), lexSyntaxWord(), lexWord(), logLexToken(), and tokenizeSyntax().
|
inlinevirtual |
Read an input line from stdin and match to the best compiled command.
Simple string argument version.
On success, no arguments indicate an empty input line. Otherwise, the command name argv[0] is guaranteed to be present in the vector.
| [out] | uid | Matched command unique id. |
| [out] | iform | Matched command form index. |
| [out] | argv | Vector of arguments, with argv[0] being the command name. |
Definition at line 683 of file CommandLine.h.
Referenced by readCommand(), and run().
|
inlinevirtual |
Read an input line from stdin and match to the best compiled command.
Extended argument version.
Each extended argument contains matched command context of:
On success, no arguments indicate an empty input line. Otherwise, the command name argv[0] is guaranteed to be present in the vector.
Extended arguments gives access to the compiled, matched command definition data such as number of required, optional, and total arguments, plus argument specific info such as name, type, etc.
| [out] | uid | Matched command unique id. |
| [out] | argv | Vector of extended arguments, with argv[0] being the command name argument. |
Definition at line 713 of file CommandLine.h.
References rnr::cmd::CmdExec::execute().
|
virtual |
Read an input line from file fp and match to the best compiled command.
Simple string argument version.
On success, no arguments indicate an empty input line. Otherwise, the command name argv[0] is guaranteed to be present in the vector.
| fp | Input file pointer. | |
| [out] | uid | Matched command unique id. |
| [out] | iform | Matched command form index. |
| [out] | argv | Vector of arguments, with argv[0] being the command name. |
Definition at line 848 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::NoIndex, rnr::cmd::NoUid, readCommand(), and toVec().
|
virtual |
Read an input line from file fp and match to the best compiled command.
Extended argument version.
Each extended argument contains matched command context of:
On success, no arguments indicate an empty input line. Otherwise, the command name argv[0] is guaranteed to be present in the vector.
Extended arguments gives access to the compiled, matched command definition data such as number of required, optional, and total arguments, plus argument specific info such as name, type, etc.
| fp | Input file pointer. | |
| [out] | argv | Vector of extended arguments, with argv[0] being the command name argument. |
Definition at line 869 of file CommandLine.cxx.
References rnr::cmd::AOk, backtrace(), rnr::bookmark(), rnr::LogBook::clear(), rnr::cmd::ENoExec, rnr::eoe(), getBtEnable(), getErrorStr(), getLineNum(), getName(), rnr::cmd::ReadLine::ireadLine(), LOGDIAG3_STREAM, LOGERROR_STREAM, m_cmdDefs, m_log, m_readline, numOfCmds(), processInput(), and rnr::cmd::ReadLine::rlreadLine().
|
virtual |
Remove all commands from command line interface.
Definition at line 619 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::eoe(), m_bIsCompiled, m_cmdDefs, and m_log.
|
virtual |
Remove command from command line interface.
No re-comiple is necessary.
| uid | Command unique id. |
Definition at line 569 of file CommandLine.cxx.
References rnr::cmd::AOk, cmdAt(), rnr::cmd::EBadVal, rnr::eoe(), getErrorStr(), rnr::cmd::CmdDef::getUid(), LOGERROR_STREAM, m_bIsCompiled, m_cmdDefs, m_cmdExecs, m_log, and rnr::cmd::NoUid.
Referenced by execTRemove().
|
virtual |
Remove command from command line interface.
No re-comiple is necessary.
| strName | Command name. |
| int CommandLine::removeDataSection | ( | const std::string & | ns | ) |
Remove a data section from the command-line interface.
If a deallocation function was specified, the section data is also deleted. Otherwise, the data remains intact.
| ns | Namespace of data section to remove. |
Definition at line 809 of file CommandLine.cxx.
References rnr::cmd::AOk, rnr::cmd::EBadVal, rnr::cmd::ENoExec, isReservedDataSection(), LOGERROR_STREAM, and m_dataSects.
|
protected |
Build list of all command argument definitions that match completed subtext.
| [in] | strSubtext | Complete subtext string. |
| [out] | argdefs | List of matched argument definitions. |
Definition at line 1654 of file CommandLine.cxx.
References rnr::cmd::CmdFormDef::argAt(), rnr::cmd::CmdArgDef::getParentCmdUid(), rnr::cmd::CmdArgDef::getParentFormIndex(), m_bIgnoreCase, m_cmdDefs, rnr::cmd::CmdArgDef::match(), rnr::cmd::CmdFormDef::numOfArgs(), and tokenizeInput().
Referenced by rlGenerator().
|
protectedvirtual |
Perform any necessary pre-processing to prepare for command line TAB completion.
Definition at line 1592 of file CommandLine.cxx.
References rnr::cmd::AOk.
Referenced by compile().
|
protectedvirtual |
TAB completion generator.
See ReadLine::AltAppGenFunc for description of a ReadLine generator.
| strText | Partial text string to complete. | |
| nIndex | Match candidate index starting from 0. | |
| strContext | Generator context (i.e. input buffer). | |
| nStart | Starting index in context of text. | |
| nEnd | Ending index in context of the position immediately after the end of text. If nStart equals nEnd, then empty text. | |
| [out] | uFlags | TAB completion modifier flags. |
Definition at line 1616 of file CommandLine.cxx.
References rlArgDefs(), rnr::cmd::RlTabEnd, and rlTabList().
|
staticprotected |
Static TAB completion generator wrapper.
See ReadLine::AltAppGenFunc for description of a ReadLine generator.
| pAppArg | Pointer to this CommandLine object. | |
| strText | Partial text string to complete. | |
| nIndex | Match candidate index starting from 0. | |
| strContext | Generator context (i.e. input buffer). | |
| nStart | Starting index in context of text. | |
| nEnd | Ending index in context of the position immediately after the end of text. If nStart equals nEnd, then empty text. | |
| [out] | uFlags | TAB completion modifier flags. |
Definition at line 1597 of file CommandLine.cxx.
References rnr::cmd::emptystring.
Referenced by compile().
|
protected |
Match partial text agains literal string.
Ignore case is taken into account when strings are compared.
| [in] | strText | Partial text string to complete. |
| [in] | strLiteral | Literal text string to compare. |
| [in] | uLen | Number of characters to match. |
Definition at line 1860 of file CommandLine.cxx.
References rnr::str::lowercase(), and m_bIgnoreCase.
Referenced by rlTabList().
|
protected |
Build TAB completion list and set appropriate readline modifiers.
| [in] | strText | Partial text string to complete. |
| [in] | argdefs | List of matched argument definitions. |
| [out] | tabList | List of TAB completion matches. |
| [out] | uFlags | TAB completion modifier flags. |
Definition at line 1716 of file CommandLine.cxx.
References rnr::cmd::CmdArgDef::ArgTypeBoolean, rnr::cmd::CmdArgDef::ArgTypeFile, rnr::cmd::CmdArgDef::ArgTypeFpn, rnr::cmd::CmdArgDef::ArgTypeIdentifier, rnr::cmd::CmdArgDef::ArgTypeInteger, rnr::cmd::CmdArgDef::ArgTypeLiteral, rnr::cmd::CmdArgDef::ArgTypeMultiWord, rnr::cmd::CmdArgDef::ArgTypeRegEx, rnr::cmd::CmdArgDef::ArgTypeUndef, rnr::cmd::CmdArgDef::ArgTypeWord, rnr::str::FalseHood, rnr::cmd::ReadLine::FlagTabNoDefault, rnr::cmd::ReadLine::FlagTabNoFilename, rnr::cmd::ReadLine::FlagTabNoSpace, rnr::str::gcss(), rlPartialMatch(), and rnr::str::TruthHood.
Referenced by rlGenerator().
|
inline |
Enable/disable backtracing.
| bEnable | Enable(true) or Disable(false). |
Definition at line 510 of file CommandLine.h.
References rnr::cmd::DataSectNsCore.
Referenced by rnr::cmd::addons::execBtEnable().
|
inline |
Set the current line number.
| Line | number. |
Definition at line 863 of file CommandLine.h.
|
virtual |
Lexically analyze input string to generate a series of tokens.
Tokens are separated by whitespace.
Each tokens is either:
| [in] | strInput | Input string to analyze. |
| [out] | tokens | Generated tokens. |
Referenced by backtrace(), processInput(), and rlArgDefs().
|
virtual |
Lexically analyze input string to generate a series of string tokens.
See tokenize()
| [in] | strInput | Input string to analyze. |
| [out] | tokens | Generated string tokens. |
|
protectedvirtual |
Lexically analyze extened usage syntax string to generate a series of tokens.
Tokens are separated by either whitespace, parenthetical blocks, or syntax special characters.
| [in] | strSyntax | Syntax string to analyze. |
| [out] | tokens | Generated tokens. |
Definition at line 2042 of file CommandLine.cxx.
References rnr::cmd::isoparen(), rnr::cmd::isspecial(), lexSyntaxParenExpr(), lexSyntaxWord(), and pushToken().
Referenced by compile().
|
protected |
Test if token at position is equal to string.
If equal, the position cursor is advanced on position. If not equal, an error message will be logged.
| [in] | strCmp | String to compare token against. |
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The position in the token vector. Advanced 1 position if equal. |
Definition at line 3109 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), LOGERROR_STREAM, m_log, and rnr::str::okstr().
Referenced by parseOptionalArgList(), parseVariableArg(), parseVarMod(), parseXorList(), and parseXorListArg().
|
protected |
Test if string has valid identifier syntax.
| [in] | tokens | Lexical tokens generated from the syntax usage. |
| [in,out] | pos | The position in the token vector. Advanced 1 position if valid identifier. |
Definition at line 3146 of file CommandLine.cxx.
References rnr::eoe(), getErrorStr(), rnr::cmd::isIdentifier(), LOGERROR_STREAM, m_log, and rnr::str::okstr().
Referenced by parseIdentifier().
|
protected |
Convert extended argument vector to string argument vector.
| [in] | v1 | Extended argument vector. |
| [out] | v2 | String argument vector. |
Definition at line 1529 of file CommandLine.cxx.
Referenced by addToHistory(), and readCommand().
|
friend |
Insert object into output stream.
| os | Output stream. |
| cl | Object to insert. |