forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsedScript.cxx
More file actions
97 lines (86 loc) · 2.65 KB
/
sedScript.cxx
File metadata and controls
97 lines (86 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Filename: sedScript.cxx
// Created by: drose (24Oct00)
//
////////////////////////////////////////////////////////////////////
#include "sedScript.h"
#include "sedCommand.h"
#include "sedContext.h"
////////////////////////////////////////////////////////////////////
// Function: SedScript::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
SedScript::
SedScript() {
_quit = false;
}
////////////////////////////////////////////////////////////////////
// Function: SedScript::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
SedScript::
~SedScript() {
Commands::iterator ci;
for (ci = _commands.begin(); ci != _commands.end(); ++ci) {
delete (*ci);
}
}
////////////////////////////////////////////////////////////////////
// Function: SedScript::add_line
// Access: Public
// Description: Adds the indicated script line to the script.
// Returns true if it is a valid line, false if there is
// an error.
////////////////////////////////////////////////////////////////////
bool SedScript::
add_line(const string &line) {
size_t p = 0;
SedCommand *command = new SedCommand;
if (!command->parse_command(line, p)) {
// That's an invalid command.
delete command;
return false;
}
_commands.push_back(command);
while (p < line.length()) {
// There's more to the line.
if (line[p] != ';') {
// But it's an error.
cerr << "Invalid character at: " << line.substr(p) << "\n";
return false;
}
p++;
command = new SedCommand;
if (!command->parse_command(line, p)) {
// That's an invalid command.
delete command;
return false;
}
_commands.push_back(command);
}
// Everything parsed ok.
return true;
}
////////////////////////////////////////////////////////////////////
// Function: SedScript::run
// Access: Public
// Description: Runs the script, modifying the context as
// appropriate. Returns true if the process should
// continue with the next line, or false if we have quit
// and we should terminate.
////////////////////////////////////////////////////////////////////
bool SedScript::
run(SedContext &context) {
context._deleted = false;
_next_command = _commands.begin();
while (!_quit && _next_command != _commands.end()) {
SedCommand *command = (*_next_command);
++_next_command;
command->run(*this, context);
}
if (!context._deleted) {
context._out << context._pattern_space << "\n";
}
return !_quit;
}