Ghidra Decompiler Analysis Engine
|
A generic console mode interface and command executor. More...
#include <interface.hh>
Public Member Functions | |
IfaceStatus (const string &prmpt, ostream &os, int4 mxhist=10) | |
Constructor. More... | |
virtual | ~IfaceStatus (void) |
Destructor. | |
virtual void | pushScript (const string &filename, const string &newprompt) |
Provide a new script file to execute, with an associated command prompt. More... | |
virtual void | popScript (void) |
Return to processing the parent stream. More... | |
void | reset (void) |
Pop any existing script streams and return to processing from the base stream. | |
void | registerCom (IfaceCommand *fptr, const char *nm1, const char *nm2=(const char *) 0, const char *nm3=(const char *) 0, const char *nm4=(const char *) 0, const char *nm5=(const char *) 0) |
Register a command with this interface. More... | |
IfaceData * | getData (const string &nm) const |
Get data associated with a IfaceCommand module. More... | |
bool | runCommand (void) |
Run the next command. More... | |
void | getHistory (string &line, int4 i) const |
Get the i-th command line from history. More... | |
virtual bool | isStreamFinished (void) const =0 |
Return true if the current stream is finished. | |
void | evaluateError (void) |
Adjust which stream to process based on last error. | |
Static Public Member Functions | |
static void | wordsToString (string &res, const vector< string > &list) |
Concatenate tokens. More... | |
Public Attributes | |
bool | done |
Set to true (by a command) to indicate processing is finished. | |
ostream * | optr |
Where to put command line output. | |
ostream * | fileoptr |
Where to put bulk output. | |
Protected Member Functions | |
int4 | expandCom (vector< string > &expand, istream &s, vector< IfaceCommand * >::const_iterator &first, vector< IfaceCommand * >::const_iterator &last) |
Expand tokens from the given input stream to a full command. More... | |
Protected Attributes | |
bool | inerror |
Set to true if last command did not succeed. | |
vector< IfaceCommand * > | comlist |
List of registered commands. | |
map< string, IfaceData * > | datamap |
Data associated with particular modules. | |
A generic console mode interface and command executor.
Input is provided one command line at a time by providing calling readLine(). Output goes to a provided ostream, optr. Output to a separate bulk stream can be enabled by setting fileoptr.
A derived IfaceCommand is attached to a command string via registerCom() i.e. stat.registerCom(new IfcQuit(),"quit"); stat.registerCom(new IfcOpenfileAppend(),"openfile","append"); stat.mainloop(); Command line processing is started with mainloop(), which prints a command prompt, allows command line editing, including command completion and history, and executes the corresponding IfaceComman::execute() callback. Command words only have to match enough to disambiguate it from other commands. A Custom history size and command prompt can be passed to the constructor. Applications should inherit from base class IfaceStatus in order to
IfaceStatus::IfaceStatus | ( | const string & | prmpt, |
ostream & | os, | ||
int4 | mxhist = 10 |
||
) |
prmpt | is the base command line prompt |
os | is the base stream to write output to |
mxhist | is the maximum number of lines to store in history |
|
protected |
Expand tokens from the given input stream to a full command.
A range of possible commands is returned. Processing of the stream stops as soon as at least one complete command is recognized. Tokens partially matching a command are expanded to the full command and passed back.
expand | will hold the list of expanded tokens |
s | is the input stream tokens are read from |
first | will hold the beginning of the matching range of commands |
last | will hold the end of the matching range of commands |
IfaceData * IfaceStatus::getData | ( | const string & | nm | ) | const |
Get data associated with a IfaceCommand module.
Commands (IfaceCommand) are associated with a particular module that has a formal name and a data object associated with it. This method retrieves the module specific data object by name.
nm | is the name of the module |
void IfaceStatus::getHistory | ( | string & | line, |
int4 | i | ||
) | const |
Get the i-th command line from history.
A command line is selected by specifying how many steps in time to go back through the list of successful command lines.
line | will hold the selected command line from history |
i | is the number of steps back to go |
|
virtual |
Return to processing the parent stream.
The current input stream, as established by a script, is popped from the stack, along with its command prompt, and processing continues with the previous stream.
Reimplemented in IfaceTerm.
|
virtual |
Provide a new script file to execute, with an associated command prompt.
The script provides a subsidiary input stream to the current stream. Once commands from the script are complete, processing will resume on this stream.
filename | is the name of the file containing the script |
newprompt | is the command line prompt |
Reimplemented in IfaceTerm.
void IfaceStatus::registerCom | ( | IfaceCommand * | fptr, |
const char * | nm1, | ||
const char * | nm2 = (const char *)0 , |
||
const char * | nm3 = (const char *)0 , |
||
const char * | nm4 = (const char *)0 , |
||
const char * | nm5 = (const char *)0 |
||
) |
Register a command with this interface.
A command object is associated with one or more tokens on the command line. A string containing up to 5 tokens can be associated with the command.
fptr | is the IfaceCommand object |
nm1 | is the first token representing the command |
nm2 | is the second token (or null) |
nm3 | is the third token (or null) |
nm4 | is the fourth token (or null) |
nm5 | is the fifth token (or null) |
bool IfaceStatus::runCommand | ( | void | ) |
Run the next command.
A single command line is read (via readLine) and executed. If the command is successfully executed, the command line is committed to history and true is returned.
|
static |
Concatenate tokens.
Concatenate a list of tokens into a single string, separated by a space character.