decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::IfaceTerm Class Reference

Implement the command-line interface on top of a specific input stream. More...

#include <ifaceterm.hh>

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

Public Member Functions

 IfaceTerm (const string &prmpt, istream &is, ostream &os)
 Constructor.
 
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 bool isStreamFinished (void) const
 Return true if the current stream is finished.
 
- Public Member Functions inherited from ghidra::IfaceStatus
 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 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.
 
bool isInError (void) const
 Return true if the last command failed.
 
void evaluateError (void)
 Adjust which stream to process based on last error.
 

Private Member Functions

int4 doCompletion (string &line, int4 cursor)
 'Complete' the current command line More...
 
virtual void readLine (string &line)
 Read the next command line. More...
 

Private Attributes

istream * sptr
 The base input stream for the interface.
 
vector< istream * > inputstack
 Stack of nested input streams.
 

Additional Inherited Members

- Static Public Member Functions inherited from ghidra::IfaceStatus
static void wordsToString (string &res, const vector< string > &list)
 Concatenate tokens. More...
 
- Public Attributes inherited from ghidra::IfaceStatus
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 inherited from ghidra::IfaceStatus
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 inherited from ghidra::IfaceStatus
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

Implement the command-line interface on top of a specific input stream.

An initial input stream is provided as the base stream to parse for commands. Additional input streams can be stacked by invoking scripts. If the stream supports it, the stream parser recognizes special command-line editing and completion keys.

Member Function Documentation

◆ doCompletion()

int4 ghidra::IfaceTerm::doCompletion ( string &  line,
int4  cursor 
)
private

'Complete' the current command line

Respond to a TAB key press and try to 'complete' any existing tokens. The method is handed the current state of the command-line in a string, and it updates the command-line in place.

Parameters
lineis current command-line and will hold the final completion
cursoris the current position of the cursor
Returns
the (possibly new) position of the cursor, after completion

References ghidra::IfaceStatus::comlist, ghidra::IfaceStatus::expandCom(), ghidra::IfaceStatus::optr, and ghidra::IfaceStatus::wordsToString().

Referenced by readLine().

◆ popScript()

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

References inputstack, ghidra::IfaceStatus::popScript(), and sptr.

◆ pushScript()

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

References inputstack, ghidra::IfaceStatus::pushScript(), and sptr.

◆ readLine()

void ghidra::IfaceTerm::readLine ( string &  line)
privatevirtual

Read the next command line.

Parameters
lineis filled in with the next command to execute

Implements ghidra::IfaceStatus.

References doCompletion(), ghidra::IfaceStatus::getHistory(), ghidra::IfaceStatus::getHistorySize(), ghidra::IfaceStatus::optr, sptr, and ghidra::IfaceStatus::writePrompt().


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