Ghidra Decompiler Analysis Engine
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
IfaceStatus Class Referenceabstract

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

#include <interface.hh>

Inheritance diagram for IfaceStatus:
Inheritance graph
[legend]

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...
 
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...
 
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.
 

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()

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 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

◆ getData()

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.

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

◆ getHistory()

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.

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

◆ popScript()

void 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 IfaceTerm.

◆ pushScript()

void IfaceStatus::pushScript ( const string &  filename,
const string &  newprompt 
)
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.

Parameters
filenameis the name of the file containing the script
newpromptis the command line prompt

Reimplemented in IfaceTerm.

◆ registerCom()

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.

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)

◆ runCommand()

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.

Returns
true if a command successfully executes

◆ wordsToString()

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


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