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>
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 ¤tLine, 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.
|
CompiledScript & | script_ |
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
Member Function Documentation
swap pattern and hold
swap pattern and hold buffers
Definition at line 2204 of file muSED.h.
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.
bool execute |
( |
std::string const & |
currentLine, |
|
|
size_t |
lineNumber, |
|
|
bool |
isLast, |
|
|
std::list< std::string > & |
tmp, |
|
|
ActivationMap * |
activationMap | |
|
) |
| | |
append hold to pattern
Definition at line 2237 of file muSED.h.
copy hold to pattern
Definition at line 2231 of file muSED.h.
append pattern to hold
Definition at line 2222 of file muSED.h.
copy pattern to hold
Definition at line 2216 of file muSED.h.
std::string* holdBuffer |
( |
|
) |
|
returns a pointer to the buffer that is not the pattern buffer.
Definition at line 2193 of file muSED.h.
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.
return true if this script's context is valid.
Definition at line 2177 of file muSED.h.
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.
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.
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.
Member Data Documentation
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.
"pattern" and "hold" in sed lingo
Definition at line 2141 of file muSED.h.
True only if the current line number is the last in the input stream.
Definition at line 2127 of file muSED.h.
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.
null unless we are in the execute function. NOT OWNED BY THIS CLASS
Definition at line 2122 of file muSED.h.
defines which buffer is pattern and which is hold
Definition at line 2143 of file muSED.h.
The script is running and not yet been 'q' commanded.
Definition at line 2119 of file muSED.h.
The documentation for this struct was generated from the following files: