ScriptRuntimeContext Struct Reference

The runtime data needed to execute a muSED script on a stream of input lines. It contains the script and the activation state of the lines within the script, as well as the pattern and hold buffers, the only two variables defined by the sed language. More...

#include <muSED.h>

Collaboration diagram for ScriptRuntimeContext:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void bufferSwap ()
 swap pattern and hold
std::string const & error () const
 Return a non-empty string if there has been a compile error in this script.
bool execute (std::string const &currentLine, size_t lineNumber, bool isLast, std::list< std::string > &tmp, ActivationMap *activationMap)
void Get ()
 append hold to pattern
void get ()
 copy hold to pattern
void Hold ()
 append pattern to hold
void hold ()
 copy pattern to hold
std::string * holdBuffer ()
 returns a pointer to the buffer that is not the pattern buffer.
int maxWhileIterations () const
bool ok () const
 return true if this script's context is valid.
std::string * patternBuffer ()
 Return a pointer to this runtime context's current pattern buffer.
void print (bool firstLineOnly)
 Print part or all of the pattern buffer to the output. Each newline delimited fragment goes into a separate string in the output sequence.
bool running () const
 ScriptRuntimeContext (CompiledScript &s)
void setMaxWhileIterations (int count)
 Set the maximum number of times that a while loop is allowed to iterate over the same line of input text. The default is 1 million but that is probably too large if you are applying a script from inside a text editor based on user command.
void start ()
void stop ()

Public Attributes

std::map< Statement *, bool > activationMap_
 A mapping between statements and their activation state. A statement is active unless it's filters turn it off. Only 2 filter statements can ever be off. One filter statements are on until they are off, and then stay off only for the execution of one line.
std::string buffer1_
std::string buffer2_
 "pattern" and "hold" in sed lingo
bool isLast_
 True only if the current line number is the last in the input stream.
size_t lineNumber_
 Current line number within the input stream.
int maxWhileIterations_
 Maximum number of times a while command should loop on the same line.
std::list< std::string > * output_
 null unless we are in the execute function. NOT OWNED BY THIS CLASS
std::string * pattern_
 defines which buffer is pattern and which is hold
bool running_
 The script is running and not yet been 'q' commanded.
CompiledScriptscript_

Detailed Description

The runtime data needed to execute a muSED script on a stream of input lines. It contains the script and the activation state of the lines within the script, as well as the pattern and hold buffers, the only two variables defined by the sed language.

The ScriptRuntimeContext also defines functions needed to manipulate the program variables so as to produce useful output.

The SED script language makes heavy use of the pattern buffer, which refers to the most recently read line of text from the input stream being processed by the script. The hold buffer is a temporary string available to the script for keeping track of data previously read. The hold buffer can be as simple as an earlier line or it can be sum of all previous lines, or it can also contain a collection of "variables" which refer to part of the previous lines read. The user has the option of formatting the "hold" buffer in any helpful way to a specific script.

The while command is somewhat dangerous in that it allows multiple transformations on the same input command line. It is dangerous because it allows you create an infinite loop. To avoid this, there is a maximum while loop iteration count. This can be set using the setMaxWhileIterations() function. The default is 1 million. This is a large number but won't allow a script to run forever. Remember that this number applies to each line of input. If you really need more than a million loops you are probably doing something wrong. Text editors using muSED will likely set a much lower number.

Definition at line 2090 of file muSED.h.


Constructor & Destructor Documentation

Definition at line 2150 of file muSED.h.


Member Function Documentation

void bufferSwap (  ) 

swap pattern and hold

swap pattern and hold buffers

Definition at line 2204 of file muSED.h.

Here is the caller graph for this function:

std::string const& error (  )  const

Return a non-empty string if there has been a compile error in this script.

Definition at line 2180 of file muSED.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool execute ( std::string const &  currentLine,
size_t  lineNumber,
bool  isLast,
std::list< std::string > &  tmp,
ActivationMap activationMap 
)

Definition at line 2266 of file muSED.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void Get (  ) 

append hold to pattern

Definition at line 2237 of file muSED.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void get (  ) 

copy hold to pattern

Definition at line 2231 of file muSED.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void Hold (  ) 

append pattern to hold

Definition at line 2222 of file muSED.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void hold (  ) 

copy pattern to hold

Definition at line 2216 of file muSED.h.

Here is the call graph for this function:

Here is the caller graph for this function:

std::string* holdBuffer (  ) 

returns a pointer to the buffer that is not the pattern buffer.

Definition at line 2193 of file muSED.h.

Here is the caller graph for this function:

int maxWhileIterations (  )  const
Returns:
the maximum number of times a while statement is allowed to process a single line. The default is 1 million.

Definition at line 2244 of file muSED.h.

Here is the caller graph for this function:

bool ok (  )  const

return true if this script's context is valid.

Definition at line 2177 of file muSED.h.

Here is the call graph for this function:

Here is the caller graph for this function:

std::string* patternBuffer (  ) 

Return a pointer to this runtime context's current pattern buffer.

Note:
that the pattern and the hold buffer switch back and forth based on the number of the 'x' commands that have been executed in this script.

Definition at line 2184 of file muSED.h.

Here is the caller graph for this function:

void print ( bool  firstLineOnly  ) 

Print part or all of the pattern buffer to the output. Each newline delimited fragment goes into a separate string in the output sequence.

Parameters:
[in] firstLineOnly Means to print only the first newline delimited string to the output.

Definition at line 173 of file muSED.cxx.

Here is the call graph for this function:

Here is the caller graph for this function:

bool running (  )  const

Definition at line 2171 of file muSED.h.

Here is the caller graph for this function:

void setMaxWhileIterations ( int  count  ) 

Set the maximum number of times that a while loop is allowed to iterate over the same line of input text. The default is 1 million but that is probably too large if you are applying a script from inside a text editor based on user command.

Definition at line 2249 of file muSED.h.

Here is the caller graph for this function:

void start (  ) 

Definition at line 2166 of file muSED.h.

Here is the caller graph for this function:

void stop (  ) 

Definition at line 2161 of file muSED.h.

Here is the caller graph for this function:


Member Data Documentation

std::map<Statement*, bool> activationMap_

A mapping between statements and their activation state. A statement is active unless it's filters turn it off. Only 2 filter statements can ever be off. One filter statements are on until they are off, and then stay off only for the execution of one line.

Definition at line 2131 of file muSED.h.

std::string buffer1_

Definition at line 2141 of file muSED.h.

std::string buffer2_

"pattern" and "hold" in sed lingo

Definition at line 2141 of file muSED.h.

bool isLast_

True only if the current line number is the last in the input stream.

Definition at line 2127 of file muSED.h.

size_t lineNumber_

Current line number within the input stream.

Definition at line 2125 of file muSED.h.

Maximum number of times a while command should loop on the same line.

Definition at line 2146 of file muSED.h.

std::list<std::string>* output_

null unless we are in the execute function. NOT OWNED BY THIS CLASS

Definition at line 2122 of file muSED.h.

std::string* pattern_

defines which buffer is pattern and which is hold

Definition at line 2143 of file muSED.h.

bool running_

The script is running and not yet been 'q' commanded.

Definition at line 2119 of file muSED.h.

Definition at line 2117 of file muSED.h.


The documentation for this struct was generated from the following files:
Generated on Wed Feb 29 22:59:08 2012 for CXXUtilities by  doxygen 1.6.3