decompiler  1.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ghidra::IfaceStatus Class Referenceabstract

A generic console mode interface and command executor. More...

#include <interface.hh>

Inheritance diagram for ghidra::IfaceStatus:
ghidra::ConsoleCommands ghidra::IfaceTerm

Public Member Functions

 IfaceStatus (const string &prmpt, ostream &os, int4 mxhist=10)
 Constructor. More...
 
virtual ~IfaceStatus (void)
 Destructor.
 
void setErrorIsDone (bool val)
 Set if processing should terminate on an error.
 
void pushScript (const string &filename, const string &newprompt)
 Push a new file on the script stack. More...
 
virtual void pushScript (istream *iptr, const string &newprompt)
 Provide a new input stream to execute, with an associated command prompt. More...
 
virtual void popScript (void)
 Return to processing the parent stream. More...
 
virtual void reset (void)
 Pop any existing script streams and return to processing from the base stream.
 
int4 getNumInputStreamSize (void) const
 Get depth of script nesting.
 
void writePrompt (void)
 Write the current command prompt to the current output 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...
 
IfaceDatagetData (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...
 
int4 getHistorySize (void) const
 Get the number of command lines in history.
 
virtual bool isStreamFinished (void) const =0
 Return true if the current stream is finished.
 
bool isInError (void) const
 Return true if the last command failed.
 
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.
 

Private Member Functions

void restrictCom (vector< IfaceCommand *>::const_iterator &first, vector< IfaceCommand *>::const_iterator &last, vector< string > &input)
 Restrict range of possible commands given a list of command line tokens. More...
 
virtual void readLine (string &line)=0
 Read the next command line. More...
 
void saveHistory (const string &line)
 Store the given command line into history. More...
 

Private Attributes

vector< string > promptstack
 Stack of command prompts corresponding to script nesting level.
 
vector< uint4 > flagstack
 Stack of flag state corresponding to script nesting level.
 
string prompt
 The current command prompt.
 
int4 maxhistory
 Maximum number of command lines to store in history.
 
int4 curhistory
 Most recent history.
 
vector< string > history
 History of commands executed through this interface.
 
bool sorted
 Set to true if commands are sorted.
 
bool errorisdone
 Set to true if any error terminates the process.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ IfaceStatus()

ghidra::IfaceStatus::IfaceStatus ( const string &  prmpt,
ostream &  os,
int4  mxhist = 10 
)

Constructor.

Parameters
prmptis the base command line prompt
osis the base stream to write output to
mxhistis the maximum number of lines to store in history

Member Function Documentation

◆ expandCom()

int4 ghidra::IfaceStatus::expandCom ( vector< string > &  expand,
istream &  s,
vector< IfaceCommand *>::const_iterator &  first,
vector< IfaceCommand *>::const_iterator &  last 
)
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.

Parameters
expandwill hold the list of expanded tokens
sis the input stream tokens are read from
firstwill hold the beginning of the matching range of commands
lastwill hold the end of the matching range of commands
Returns
the number of matching commands

Referenced by ghidra::IfaceTerm::doCompletion().

◆ getData()

IfaceData * ghidra::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.

Parameters
nmis the name of the module
Returns
the IfaceData object or null

Referenced by ghidra::IfcExecuteTestCommand::execute(), and ghidra::FunctionTestCollection::FunctionTestCollection().

◆ getHistory()

void ghidra::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.

Parameters
linewill hold the selected command line from history
iis the number of steps back to go

Referenced by ghidra::IfaceTerm::readLine().

◆ popScript()

void ghidra::IfaceStatus::popScript ( void  )
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 ghidra::IfaceTerm.

Referenced by ghidra::IfcExecuteTestCommand::execute(), and ghidra::IfaceTerm::popScript().

◆ pushScript() [1/2]

void ghidra::IfaceStatus::pushScript ( const string &  filename,
const string &  newprompt 
)

Push a new file on the script stack.

Attempt to open the file, and if we succeed put the open stream onto the script stack.

Parameters
filenameis the name of the script file
newpromptis the command line prompt to associate with the file

Referenced by ghidra::IfcSource::execute(), and ghidra::IfaceTerm::pushScript().

◆ pushScript() [2/2]

void ghidra::IfaceStatus::pushScript ( istream *  iptr,
const string &  newprompt 
)
virtual

Provide a new input stream to execute, with an associated command prompt.

The new stream is added to a stack and becomes the primary source for parsing new commands. Once commands from the stream are exhausted, parsing will resume in the previous stream.

Parameters
iptris the new input stream
newpromptis the command line prompt to associate with the new stream

Reimplemented in ghidra::IfaceTerm.

◆ readLine()

virtual void ghidra::IfaceStatus::readLine ( string &  line)
privatepure virtual

Read the next command line.

Parameters
lineis filled in with the next command to execute

Implemented in ghidra::ConsoleCommands, and ghidra::IfaceTerm.

◆ registerCom()

void ghidra::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.

Parameters
fptris the IfaceCommand object
nm1is the first token representing the command
nm2is the second token (or null)
nm3is the third token (or null)
nm4is the fourth token (or null)
nm5is the fifth token (or null)

References ghidra::IfaceCommand::addWord(), ghidra::IfaceCommand::createData(), ghidra::IfaceCommand::getModule(), and ghidra::IfaceCommand::setData().

Referenced by ghidra::IfaceDecompCapability::registerCommands().

◆ restrictCom()

void ghidra::IfaceStatus::restrictCom ( vector< IfaceCommand *>::const_iterator &  first,
vector< IfaceCommand *>::const_iterator &  last,
vector< string > &  input 
)
private

Restrict range of possible commands given a list of command line tokens.

Given a set of tokens partially describing a command, provide the most narrow range of IfaceCommand objects that could be referred to.

Parameters
firstwill hold an iterator to the first command in the range
lastwill hold an iterator (one after) the last command in the range
inputis the list of command tokens to match on

References ghidra::IfaceCommand::addWord(), ghidra::IfaceCommand::addWords(), ghidra::compare_ifacecommand(), and ghidra::IfaceCommand::removeWord().

◆ runCommand()

bool ghidra::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.

Returns
true if a command successfully executes

References ghidra::compare_ifacecommand().

Referenced by ghidra::IfcExecuteTestCommand::execute().

◆ saveHistory()

void ghidra::IfaceStatus::saveHistory ( const string &  line)
private

Store the given command line into history.

The line is saved in a circular history buffer

Parameters
lineis the command line to save

◆ wordsToString()

void ghidra::IfaceStatus::wordsToString ( string &  res,
const vector< string > &  list 
)
static

Concatenate tokens.

Concatenate a list of tokens into a single string, separated by a space character.

Referenced by ghidra::IfaceCommand::commandString(), and ghidra::IfaceTerm::doCompletion().


The documentation for this class was generated from the following files: