Moved keywords from local variables to keywords map.
This commit is contained in:
parent
907f449ecc
commit
9622b5cf8c
24
Tag.cpp
24
Tag.cpp
@ -53,19 +53,19 @@ namespace jet {
|
|||||||
if(!finished) {
|
if(!finished) {
|
||||||
coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
||||||
if(in.ifNext("=\"")) {
|
if(in.ifNext("=\"")) {
|
||||||
if(variables.count(keywordName) == 0)
|
if(keywords.count(keywordName) == 0)
|
||||||
variables[keywordName] = in.getTokenExclude("\"");
|
keywords[keywordName] = in.getTokenExclude("\"");
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("keyword name must be unique for tag.");
|
throw coreutils::Exception("keyword name must be unique for tag.");
|
||||||
}
|
}
|
||||||
if(!in.ifNext("\"")) {}
|
if(!in.ifNext("\"")) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(variableDefined("filterblanklines")) {
|
if(keywordDefined("filterblanklines")) {
|
||||||
filterBlankLines = variables["filterblanklines"] == "true" ? true: false;
|
filterBlankLines = keywords["filterblanklines"] == "true" ? true: false;
|
||||||
}
|
}
|
||||||
if(variableDefined("trimlines")) {
|
if(keywordDefined("trimlines")) {
|
||||||
trimLines = variables["trimlines"] == "true" ? true: false;
|
trimLines = keywords["trimlines"] == "true" ? true: false;
|
||||||
}
|
}
|
||||||
if(hasContainer) {
|
if(hasContainer) {
|
||||||
bool hasSplitTag = splitTagName == "" ? false: true;
|
bool hasSplitTag = splitTagName == "" ? false: true;
|
||||||
@ -89,10 +89,10 @@ namespace jet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setZString(in.parsed());
|
setZString(in.parsed());
|
||||||
if(variableDefined("eval")) {
|
if(keywordDefined("eval")) {
|
||||||
if(variables["eval"] == "yes") {
|
if(keywords["eval"] == "yes") {
|
||||||
evaluate = true;
|
evaluate = true;
|
||||||
} else if(variables["eval"] == "no") {
|
} else if(keywords["eval"] == "no") {
|
||||||
evaluate = false;
|
evaluate = false;
|
||||||
} else
|
} else
|
||||||
throw coreutils::Exception("keyword 'eval' must be 'yes' or 'no'.");
|
throw coreutils::Exception("keyword 'eval' must be 'yes' or 'no'.");
|
||||||
@ -111,7 +111,7 @@ namespace jet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Tag::resolveKeyword(coreutils::ZString keyword) {
|
void Tag::resolveKeyword(coreutils::ZString keyword) {
|
||||||
variables[keyword] = KeywordValue(variables[keyword], global, parent->local->variables);
|
keywords[keyword] = KeywordValue(keywords[keyword], global, parent->local->variables);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tag::processContainer(coreutils::ZString &container) {
|
void Tag::processContainer(coreutils::ZString &container) {
|
||||||
@ -335,8 +335,8 @@ namespace jet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tag::variableDefined(coreutils::ZString keyword) {
|
bool Tag::keywordDefined(coreutils::ZString keyword) {
|
||||||
return variables.find(keyword) != variables.end();
|
return keywords.find(keyword) != keywords.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tag::ifNested(coreutils::ZString &in) {
|
bool Tag::ifNested(coreutils::ZString &in) {
|
||||||
|
3
Tag.h
3
Tag.h
@ -16,6 +16,7 @@ namespace jet {
|
|||||||
|
|
||||||
void resolveKeyword(coreutils::ZString keyword);
|
void resolveKeyword(coreutils::ZString keyword);
|
||||||
std::map<coreutils::MString, coreutils::MString> variables;
|
std::map<coreutils::MString, coreutils::MString> variables;
|
||||||
|
std::map<coreutils::MString, coreutils::MString> keywords;
|
||||||
coreutils::ZString name;
|
coreutils::ZString name;
|
||||||
coreutils::ZString container;
|
coreutils::ZString container;
|
||||||
coreutils::ZString container2;
|
coreutils::ZString container2;
|
||||||
@ -25,7 +26,7 @@ namespace jet {
|
|||||||
protected:
|
protected:
|
||||||
bool hasContainer = false;
|
bool hasContainer = false;
|
||||||
bool hasContainer2 = false;
|
bool hasContainer2 = false;
|
||||||
bool variableDefined(coreutils::ZString variable);
|
bool keywordDefined(coreutils::ZString variable);
|
||||||
void parseContainer(coreutils::ZString &in, coreutils::MString &out);
|
void parseContainer(coreutils::ZString &in, coreutils::MString &out);
|
||||||
void processContainer(coreutils::ZString &container);
|
void processContainer(coreutils::ZString &container);
|
||||||
void copyContainer(coreutils::ZString &in, coreutils::MString &out);
|
void copyContainer(coreutils::ZString &in, coreutils::MString &out);
|
||||||
|
28
__call.cpp
28
__call.cpp
@ -12,18 +12,18 @@ namespace jet {
|
|||||||
__call::__call(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__call::__call(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
if(hasContainer)
|
if(hasContainer)
|
||||||
throw coreutils::Exception("call tag cannot have a container.");
|
throw coreutils::Exception("call tag cannot have a container.");
|
||||||
if(!variableDefined("pgm"))
|
if(!keywordDefined("pgm"))
|
||||||
throw coreutils::Exception("pgm keyword must be specified.");
|
throw coreutils::Exception("pgm keyword must be specified.");
|
||||||
resolveKeyword("pgm");
|
resolveKeyword("pgm");
|
||||||
for(ix = 0; ix <= 50; ++ix)
|
for(ix = 0; ix <= 50; ++ix)
|
||||||
argv[ix] = NULL;
|
argv[ix] = NULL;
|
||||||
argv[0] = variables["pgm"].c_str(); // TODO: Need to peel off the program name only and pass as argv[0].
|
argv[0] = keywords["pgm"].c_str(); // TODO: Need to peel off the program name only and pass as argv[0].
|
||||||
for(ix = 1; ix <= 50; ++ix) {
|
for(ix = 1; ix <= 50; ++ix) {
|
||||||
coreutils::MString arg("arg");
|
coreutils::MString arg("arg");
|
||||||
arg << ix;
|
arg << ix;
|
||||||
if(variableDefined(arg)) {
|
if(keywordDefined(arg)) {
|
||||||
resolveKeyword(arg);
|
resolveKeyword(arg);
|
||||||
argv[ix] = variables[arg].c_str();
|
argv[ix] = keywords[arg].c_str();
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ namespace jet {
|
|||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
close(fdo[0]);
|
close(fdo[0]);
|
||||||
dup2(fdo[1], 1);
|
dup2(fdo[1], 1);
|
||||||
if(variableDefined("input")) {
|
if(keywordDefined("input")) {
|
||||||
resolveKeyword("input");
|
resolveKeyword("input");
|
||||||
coreutils::ZString input(variables["input"]);
|
coreutils::ZString input(variables["input"]);
|
||||||
pipe(fdi);
|
pipe(fdi);
|
||||||
@ -50,23 +50,23 @@ namespace jet {
|
|||||||
exit(errno);
|
exit(errno);
|
||||||
}
|
}
|
||||||
close(fdo[1]);
|
close(fdo[1]);
|
||||||
if(variableDefined("name")) {
|
if(keywordDefined("name")) {
|
||||||
resolveKeyword("name");
|
resolveKeyword("name");
|
||||||
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
|
||||||
global.variables[variables["name"]].read(fdo[0]);
|
global.variables[keywords["name"]].read(fdo[0]);
|
||||||
else if(variables["scope"] == "local")
|
else if(keywords["scope"] == "local")
|
||||||
this->local->variables[variables["name"]].read(fdo[0]);
|
this->local->variables[keywords["name"]].read(fdo[0]);
|
||||||
else if(variables["scope"] == "parent")
|
else if(keywords["scope"] == "parent")
|
||||||
this->local->parent->local->variables[variables["name"]].read(fdo[0]);
|
this->local->parent->local->variables[keywords["name"]].read(fdo[0]);
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("scope value is not valid.");
|
throw coreutils::Exception("scope value is not valid.");
|
||||||
|
|
||||||
} else
|
} else
|
||||||
out.read(fdo[0]);
|
out.read(fdo[0]);
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
if(variableDefined("error")) {
|
if(keywordDefined("error")) {
|
||||||
resolveKeyword("error");
|
resolveKeyword("error");
|
||||||
global.variables[variables["error"]] = (status >> 8 & 255);
|
global.variables[keywords["error"]] = (status >> 8 & 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
__cookie.cpp
22
__cookie.cpp
@ -8,31 +8,31 @@ namespace jet {
|
|||||||
|
|
||||||
__cookie::__cookie(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__cookie::__cookie(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
output = false;
|
output = false;
|
||||||
if(!variableDefined("name"))
|
if(!keywordDefined("name"))
|
||||||
throw coreutils::Exception("header tag must have name defined.");
|
throw coreutils::Exception("header tag must have name defined.");
|
||||||
if(!variableDefined("expr") && variableDefined("value") && hasContainer)
|
if(!keywordDefined("expr") && keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("header tag cannot have both value and a container.");
|
throw coreutils::Exception("header tag cannot have both value and a container.");
|
||||||
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
|
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("header tag cannot have both expr and a container.");
|
throw coreutils::Exception("header tag cannot have both expr and a container.");
|
||||||
if(variableDefined("expr") && variableDefined("value") && !hasContainer)
|
if(keywordDefined("expr") && keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("header tag cannot have both expr and value.");
|
throw coreutils::Exception("header tag cannot have both expr and value.");
|
||||||
if(!variableDefined("expr") && !variableDefined("value") && !hasContainer)
|
if(!keywordDefined("expr") && !keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("header tag must have a value, expr or a container.");
|
throw coreutils::Exception("header tag must have a value, expr or a container.");
|
||||||
resolveKeyword("name");
|
resolveKeyword("name");
|
||||||
if(variableDefined("expr")) {
|
if(keywordDefined("expr")) {
|
||||||
if(variableDefined("eval"))
|
if(keywordDefined("eval"))
|
||||||
throw coreutils::Exception("Cannot use eval with expr.");
|
throw coreutils::Exception("Cannot use eval with expr.");
|
||||||
global.headers[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
global.headers[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||||
} else if(hasContainer) {
|
} else if(hasContainer) {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
if(evaluate) {
|
if(evaluate) {
|
||||||
global.headers[variables["name"]] = out;
|
global.headers[keywords["name"]] = out;
|
||||||
} else {
|
} else {
|
||||||
global.headers[variables["name"]] = container;
|
global.headers[keywords["name"]] = container;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolveKeyword("value");
|
resolveKeyword("value");
|
||||||
global.headers[variables["Set-Cookie"]] = variables["value"];
|
global.headers[keywords["Set-Cookie"]] = keywords["value"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__dump::__dump(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__dump::__dump(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
if(!variableDefined("file"))
|
if(!keywordDefined("file"))
|
||||||
throw coreutils::Exception("file must be sppecified for dump tag.");
|
throw coreutils::Exception("file must be sppecified for dump tag.");
|
||||||
|
|
||||||
std::ofstream outFile(variables["file"].str());
|
std::ofstream outFile(keywords["file"].str());
|
||||||
|
|
||||||
outFile << "*** CGI VARIABLES ***" << std::endl;
|
outFile << "*** CGI VARIABLES ***" << std::endl;
|
||||||
|
|
||||||
|
28
__for.cpp
28
__for.cpp
@ -6,30 +6,30 @@ namespace jet {
|
|||||||
|
|
||||||
__for::__for(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
__for::__for(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
||||||
double counter = 0.0f;
|
double counter = 0.0f;
|
||||||
bool nameDefined = variableDefined("name");
|
bool nameDefined = keywordDefined("name");
|
||||||
if(variableDefined("start")) {
|
if(keywordDefined("start")) {
|
||||||
resolveKeyword("start");
|
resolveKeyword("start");
|
||||||
counter = variables["start"].asDouble();
|
counter = keywords["start"].asDouble();
|
||||||
variables["start"].reset();
|
keywords["start"].reset();
|
||||||
}
|
}
|
||||||
if(variableDefined("end"))
|
if(keywordDefined("end"))
|
||||||
resolveKeyword("end");
|
resolveKeyword("end");
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("for tag requires end keyword.");
|
throw coreutils::Exception("for tag requires end keyword.");
|
||||||
if(variableDefined("step"))
|
if(keywordDefined("step"))
|
||||||
resolveKeyword("step");
|
resolveKeyword("step");
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("for tag requires step keyword.");
|
throw coreutils::Exception("for tag requires step keyword.");
|
||||||
for(double ix = counter; ix <= variables["end"].asDouble(); ix += variables["step"].asDouble()) {
|
for(double ix = counter; ix <= variables["end"].asDouble(); ix += variables["step"].asDouble()) {
|
||||||
variables["end"].reset();
|
keywords["end"].reset();
|
||||||
variables["step"].reset();
|
keywords["step"].reset();
|
||||||
if(nameDefined) {
|
if(nameDefined) {
|
||||||
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
|
||||||
global.variables[variables["name"]] = ix;
|
global.variables[keywords["name"]] = ix;
|
||||||
else if(variables["scope"] == "local")
|
else if(keywords["scope"] == "local")
|
||||||
this->local->variables[variables["name"]] = ix;
|
this->local->variables[keywords["name"]] = ix;
|
||||||
else if(variables["scope"] == "parent")
|
else if(keywords["scope"] == "parent")
|
||||||
parent->local->variables[variables["name"]] = ix;
|
parent->local->variables[keywords["name"]] = ix;
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("scope value is not valid.");
|
throw coreutils::Exception("scope value is not valid.");
|
||||||
}
|
}
|
||||||
|
22
__header.cpp
22
__header.cpp
@ -7,31 +7,31 @@ namespace jet {
|
|||||||
|
|
||||||
__header::__header(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__header::__header(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
output = false;
|
output = false;
|
||||||
if(!variableDefined("name"))
|
if(!keywordDefined("name"))
|
||||||
throw coreutils::Exception("header tag must have name defined.");
|
throw coreutils::Exception("header tag must have name defined.");
|
||||||
if(!variableDefined("expr") && variableDefined("value") && hasContainer)
|
if(!keywordDefined("expr") && keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("header tag cannot have both value and a container.");
|
throw coreutils::Exception("header tag cannot have both value and a container.");
|
||||||
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
|
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("header tag cannot have both expr and a container.");
|
throw coreutils::Exception("header tag cannot have both expr and a container.");
|
||||||
if(variableDefined("expr") && variableDefined("value") && !hasContainer)
|
if(keywordDefined("expr") && keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("header tag cannot have both expr and value.");
|
throw coreutils::Exception("header tag cannot have both expr and value.");
|
||||||
if(!variableDefined("expr") && !variableDefined("value") && !hasContainer)
|
if(!keywordDefined("expr") && !keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("header tag must have a value, expr or a container.");
|
throw coreutils::Exception("header tag must have a value, expr or a container.");
|
||||||
resolveKeyword("name");
|
resolveKeyword("name");
|
||||||
if(variableDefined("expr")) {
|
if(keywordDefined("expr")) {
|
||||||
if(variableDefined("eval"))
|
if(keywordDefined("eval"))
|
||||||
throw coreutils::Exception("Cannot use eval with expr.");
|
throw coreutils::Exception("Cannot use eval with expr.");
|
||||||
global.headers[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
global.headers[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||||
} else if(hasContainer) {
|
} else if(hasContainer) {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
if(evaluate) {
|
if(evaluate) {
|
||||||
global.headers[variables["name"]] = out;
|
global.headers[keywords["name"]] = out;
|
||||||
} else {
|
} else {
|
||||||
global.headers[variables["name"]] = container;
|
global.headers[keywords["name"]] = container;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolveKeyword("value");
|
resolveKeyword("value");
|
||||||
global.headers[variables["name"]] = variables["value"];
|
global.headers[keywords["name"]] = keywords["value"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
30
__if.cpp
30
__if.cpp
@ -8,33 +8,33 @@ namespace jet {
|
|||||||
__if::__if(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this, "else") {
|
__if::__if(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this, "else") {
|
||||||
coreutils::MString result;
|
coreutils::MString result;
|
||||||
bool booleanResult = false;
|
bool booleanResult = false;
|
||||||
if(variableDefined("value1")) {
|
if(keywordDefined("value1")) {
|
||||||
resolveKeyword("value1");
|
resolveKeyword("value1");
|
||||||
if(variableDefined("expr"))
|
if(keywordDefined("expr"))
|
||||||
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
|
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
|
||||||
if(variableDefined("value2")) {
|
if(keywordDefined("value2")) {
|
||||||
if(!variableDefined("type"))
|
if(!keywordDefined("type"))
|
||||||
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
||||||
} else
|
} else
|
||||||
throw coreutils::Exception("value2 required if value1 specified.");
|
throw coreutils::Exception("value2 required if value1 specified.");
|
||||||
resolveKeyword("value2");
|
resolveKeyword("value2");
|
||||||
resolveKeyword("type");
|
resolveKeyword("type");
|
||||||
int rc = variables["value1"].compare(variables["value2"]);
|
int rc = keywords["value1"].compare(keywords["value2"]);
|
||||||
if(((variables["type"] == "eq") && (rc == 0)) ||
|
if(((keywords["type"] == "eq") && (rc == 0)) ||
|
||||||
((variables["type"] == "ne") && (rc != 0)) ||
|
((keywords["type"] == "ne") && (rc != 0)) ||
|
||||||
((variables["type"] == "lt") && (rc == -1)) ||
|
((keywords["type"] == "lt") && (rc == -1)) ||
|
||||||
((variables["type"] == "le") && (rc != 1)) ||
|
((keywords["type"] == "le") && (rc != 1)) ||
|
||||||
((variables["type"] == "gt") && (rc == 1)) ||
|
((keywords["type"] == "gt") && (rc == 1)) ||
|
||||||
((variables["type"] == "ge") && (rc != -1)))
|
((keywords["type"] == "ge") && (rc != -1)))
|
||||||
booleanResult = true;
|
booleanResult = true;
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
|
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
|
||||||
} else if(variableDefined("expr")) {
|
} else if(keywordDefined("expr")) {
|
||||||
if(variableDefined("value2"))
|
if(keywordDefined("value2"))
|
||||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
throw coreutils::Exception("value2 should not be specified with expr.");
|
||||||
if(variableDefined("type"))
|
if(keywordDefined("type"))
|
||||||
throw coreutils::Exception("type should not be specified with expr.");
|
throw coreutils::Exception("type should not be specified with expr.");
|
||||||
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
|
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||||
}
|
}
|
||||||
if(booleanResult)
|
if(booleanResult)
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
|
@ -11,10 +11,10 @@ namespace jet {
|
|||||||
output = false;
|
output = false;
|
||||||
if(!hasContainer)
|
if(!hasContainer)
|
||||||
throw coreutils::Exception("ifrow tag must have a container.");
|
throw coreutils::Exception("ifrow tag must have a container.");
|
||||||
if(!global.sessionExists(variables["sessionid"]))
|
if(!global.sessionExists(keywords["sessionid"]))
|
||||||
throw coreutils::Exception("sessionid does not exist.");
|
throw coreutils::Exception("sessionid does not exist.");
|
||||||
resolveKeyword("sessionid");
|
resolveKeyword("sessionid");
|
||||||
if(global.getSession(variables["sessionid"])->hasRow())
|
if(global.getSession(keywords["sessionid"])->hasRow())
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
else
|
else
|
||||||
processContainer(container2);
|
processContainer(container2);
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__include::__include(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__include::__include(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
if(!variableDefined("file"))
|
if(!keywordDefined("file"))
|
||||||
throw coreutils::Exception("file keyword must be specified.");
|
throw coreutils::Exception("file keyword must be specified.");
|
||||||
if(hasContainer)
|
if(hasContainer)
|
||||||
throw coreutils::Exception("include tag should not have a container.");
|
throw coreutils::Exception("include tag should not have a container.");
|
||||||
hasContainer = true;
|
hasContainer = true;
|
||||||
resolveKeyword("file");
|
resolveKeyword("file");
|
||||||
coreutils::File file(variables["file"]);
|
coreutils::File file(keywords["file"]);
|
||||||
file.read();
|
file.read();
|
||||||
container = file.asZString();
|
container = file.asZString();
|
||||||
try {
|
try {
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__jet::__jet(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
__jet::__jet(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
||||||
if(variableDefined("cgi"))
|
if(keywordDefined("cgi"))
|
||||||
resolveKeyword("cgi");
|
resolveKeyword("cgi");
|
||||||
if(variables["cgi"] == "true") {
|
if(keywords["cgi"] == "true") {
|
||||||
coreutils::ZString requestMethod(getenv("REQUEST_METHOD"));
|
coreutils::ZString requestMethod(getenv("REQUEST_METHOD"));
|
||||||
if(requestMethod == "POST") {
|
if(requestMethod == "POST") {
|
||||||
coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));
|
coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));
|
||||||
|
12
__mysql.cpp
12
__mysql.cpp
@ -6,13 +6,13 @@ namespace jet {
|
|||||||
|
|
||||||
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
||||||
|
|
||||||
if(!variableDefined("host"))
|
if(!keywordDefined("host"))
|
||||||
throw coreutils::Exception("host must be specified for mysql tag.");
|
throw coreutils::Exception("host must be specified for mysql tag.");
|
||||||
if(!variableDefined("database"))
|
if(!keywordDefined("database"))
|
||||||
throw coreutils::Exception("database must be specified for mysql tag.");
|
throw coreutils::Exception("database must be specified for mysql tag.");
|
||||||
if(!variableDefined("user"))
|
if(!keywordDefined("user"))
|
||||||
throw coreutils::Exception("user must be specified for mysql tag.");
|
throw coreutils::Exception("user must be specified for mysql tag.");
|
||||||
if(!variableDefined("password"))
|
if(!keywordDefined("password"))
|
||||||
throw coreutils::Exception("password must be specified for mysql tag.");
|
throw coreutils::Exception("password must be specified for mysql tag.");
|
||||||
|
|
||||||
resolveKeyword("host");
|
resolveKeyword("host");
|
||||||
@ -21,12 +21,12 @@ namespace jet {
|
|||||||
resolveKeyword("password");
|
resolveKeyword("password");
|
||||||
resolveKeyword("sessionid");
|
resolveKeyword("sessionid");
|
||||||
|
|
||||||
sessionId = variables["sessionid"];
|
sessionId = keywords["sessionid"];
|
||||||
|
|
||||||
global.addSession(sessionId, this);
|
global.addSession(sessionId, this);
|
||||||
|
|
||||||
mysql = mysql_init(NULL);
|
mysql = mysql_init(NULL);
|
||||||
mysql = mysql_real_connect(mysql, variables["host"].c_str(), variables["user"].c_str(), variables["password"].c_str(), variables["database"].c_str(), 0, NULL, 0);
|
mysql = mysql_real_connect(mysql, keywords["host"].c_str(), keywords["user"].c_str(), keywords["password"].c_str(), keywords["database"].c_str(), 0, NULL, 0);
|
||||||
|
|
||||||
if(!mysql)
|
if(!mysql)
|
||||||
throw coreutils::Exception("database and host parameters are not valid.");
|
throw coreutils::Exception("database and host parameters are not valid.");
|
||||||
|
@ -7,18 +7,18 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__read::__read(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
__read::__read(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
||||||
if(!variableDefined("file"))
|
if(!keywordDefined("file"))
|
||||||
throw coreutils::Exception("file keyword must be specified.");
|
throw coreutils::Exception("file keyword must be specified.");
|
||||||
if(!variableDefined("name"))
|
if(!keywordDefined("name"))
|
||||||
throw coreutils::Exception("name keyword must be specified.");
|
throw coreutils::Exception("name keyword must be specified.");
|
||||||
if(hasContainer)
|
if(hasContainer)
|
||||||
throw coreutils::Exception("read tag does not have a container.");
|
throw coreutils::Exception("read tag does not have a container.");
|
||||||
resolveKeyword("file");
|
resolveKeyword("file");
|
||||||
resolveKeyword("name");
|
resolveKeyword("name");
|
||||||
fd = open(variables["file"].c_str(), O_RDONLY);
|
fd = open(keywords["file"].c_str(), O_RDONLY);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
throw coreutils::Exception("file name is not found.");
|
throw coreutils::Exception("file name is not found.");
|
||||||
global.variables[variables["name"]].read(fd);
|
global.variables[keywords["name"]].read(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
62
__set.cpp
62
__set.cpp
@ -8,53 +8,53 @@ namespace jet {
|
|||||||
|
|
||||||
__set::__set(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__set::__set(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
output = false;
|
output = false;
|
||||||
if(!variableDefined("name"))
|
if(!keywordDefined("name"))
|
||||||
throw coreutils::Exception("set tag must have name defined.");
|
throw coreutils::Exception("set tag must have name defined.");
|
||||||
if(!variableDefined("expr") && variableDefined("value") && hasContainer)
|
if(!keywordDefined("expr") && keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("set tag cannot have both value and a container.");
|
throw coreutils::Exception("set tag cannot have both value and a container.");
|
||||||
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
|
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("set tag cannot have both expr and a container.");
|
throw coreutils::Exception("set tag cannot have both expr and a container.");
|
||||||
if(variableDefined("expr") && variableDefined("value") && !hasContainer)
|
if(keywordDefined("expr") && keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("set tag cannot have both expr and value.");
|
throw coreutils::Exception("set tag cannot have both expr and value.");
|
||||||
if(!variableDefined("expr") && !variableDefined("value") && !hasContainer)
|
if(!keywordDefined("expr") && !keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("set tag must have a value, expr or a container.");
|
throw coreutils::Exception("set tag must have a value, expr or a container.");
|
||||||
if(variableDefined("expr") && variableDefined("eval"))
|
if(keywordDefined("expr") && keywordDefined("eval"))
|
||||||
throw coreutils::Exception("Cannot use eval with expr.");
|
throw coreutils::Exception("Cannot use eval with expr.");
|
||||||
|
|
||||||
resolveKeyword("name");
|
resolveKeyword("name");
|
||||||
|
|
||||||
if(variableDefined("expr")) {
|
if(keywordDefined("expr")) {
|
||||||
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
|
||||||
global.variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
global.variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||||
else if(variables["scope"] == "local")
|
else if(keywords["scope"] == "local")
|
||||||
local->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
local->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||||
else if(variables["scope"] == "parent")
|
else if(keywords["scope"] == "parent")
|
||||||
local->parent->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
local->parent->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||||
} else if(hasContainer) {
|
} else if(hasContainer) {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
if(evaluate) {
|
if(evaluate) {
|
||||||
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
|
||||||
global.variables[variables["name"]] = out;
|
global.variables[keywords["name"]] = out;
|
||||||
else if(variables["scope"] == "local")
|
else if(keywords["scope"] == "local")
|
||||||
local->variables[variables["name"]] = out;
|
local->variables[keywords["name"]] = out;
|
||||||
else if(variables["scope"] == "parent")
|
else if(keywords["scope"] == "parent")
|
||||||
local->parent->variables[variables["name"]] = out;
|
local->parent->variables[keywords["name"]] = out;
|
||||||
} else {
|
} else {
|
||||||
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
|
||||||
global.variables[variables["name"]] = container;
|
global.variables[keywords["name"]] = container;
|
||||||
else if(variables["scope"] == "local")
|
else if(keywords["scope"] == "local")
|
||||||
local->variables[variables["name"]] = container;
|
local->variables[keywords["name"]] = container;
|
||||||
else if(variables["scope"] == "parent")
|
else if(keywords["scope"] == "parent")
|
||||||
local->parent->variables[variables["name"]] = container;
|
local->parent->variables[keywords["name"]] = container;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolveKeyword("value");
|
resolveKeyword("value");
|
||||||
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
|
||||||
global.variables[variables["name"]] = variables["value"];
|
global.variables[keywords["name"]] = keywords["value"];
|
||||||
else if(variables["scope"] == "local")
|
else if(keywords["scope"] == "local")
|
||||||
local->variables[variables["name"]] = variables["value"];
|
local->variables[keywords["name"]] = keywords["value"];
|
||||||
else if(variables["scope"] == "parent")
|
else if(keywords["scope"] == "parent")
|
||||||
local->parent->variables[variables["name"]] = variables["value"];
|
local->parent->variables[keywords["name"]] = keywords["value"];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ namespace jet {
|
|||||||
output = false;
|
output = false;
|
||||||
if(!hasContainer)
|
if(!hasContainer)
|
||||||
throw coreutils::Exception("sql tag must have a container.");
|
throw coreutils::Exception("sql tag must have a container.");
|
||||||
if(!global.sessionExists(variables["sessionid"]))
|
if(!global.sessionExists(keywords["sessionid"]))
|
||||||
throw coreutils::Exception("sessionid does not exist.");
|
throw coreutils::Exception("sessionid does not exist.");
|
||||||
resolveKeyword("sessionid");
|
resolveKeyword("sessionid");
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
global.getSession(variables["sessionid"])->query(out);
|
global.getSession(keywords["sessionid"])->query(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ namespace jet {
|
|||||||
|
|
||||||
__stream::__stream(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
__stream::__stream(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
||||||
output = false;
|
output = false;
|
||||||
if(!variableDefined("name"))
|
if(!keywordDefined("name"))
|
||||||
throw coreutils::Exception("stream tag must have a file name to stream.");
|
throw coreutils::Exception("stream tag must have a file name to stream.");
|
||||||
global.outputHeaders();
|
global.outputHeaders();
|
||||||
int len;
|
int len;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int fd = open(variables["name"].c_str(), O_RDONLY);
|
int fd = open(keywords["name"].c_str(), O_RDONLY);
|
||||||
do {
|
do {
|
||||||
len = read(fd, &buffer, 1024);
|
len = read(fd, &buffer, 1024);
|
||||||
std::cout << buffer;
|
std::cout << buffer;
|
||||||
|
12
__system.cpp
12
__system.cpp
@ -11,16 +11,16 @@ namespace jet {
|
|||||||
__system::__system(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__system::__system(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
if(hasContainer)
|
if(hasContainer)
|
||||||
throw coreutils::Exception("system tag cannot have a container.");
|
throw coreutils::Exception("system tag cannot have a container.");
|
||||||
if(!variableDefined(coreutils::ZString("cmd")))
|
if(!keywordDefined(coreutils::ZString("cmd")))
|
||||||
throw coreutils::Exception("cmd keyword must be specified.");
|
throw coreutils::Exception("cmd keyword must be specified.");
|
||||||
pipe(fdo);
|
pipe(fdo);
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
close(fdo[0]);
|
close(fdo[0]);
|
||||||
dup2(fdo[1], 1);
|
dup2(fdo[1], 1);
|
||||||
if(variableDefined("input")) {
|
if(keywordDefined("input")) {
|
||||||
resolveKeyword("input");
|
resolveKeyword("input");
|
||||||
coreutils::ZString input(variables["input"]);
|
coreutils::ZString input(keywords["input"]);
|
||||||
pipe(fdi);
|
pipe(fdi);
|
||||||
if(fork() == 0) {
|
if(fork() == 0) {
|
||||||
close(fdi[0]);
|
close(fdi[0]);
|
||||||
@ -31,13 +31,13 @@ namespace jet {
|
|||||||
close(fdi[1]);
|
close(fdi[1]);
|
||||||
dup2(fdi[0], 0);
|
dup2(fdi[0], 0);
|
||||||
}
|
}
|
||||||
system(variables["cmd"].c_str());
|
system(keywords["cmd"].c_str());
|
||||||
close(fdo[1]);
|
close(fdo[1]);
|
||||||
exit(errno);
|
exit(errno);
|
||||||
}
|
}
|
||||||
close(fdo[1]);
|
close(fdo[1]);
|
||||||
if(variableDefined("name"))
|
if(keywordDefined("name"))
|
||||||
global.variables[variables["name"]].read(fdo[0]);
|
global.variables[keywords["name"]].read(fdo[0]);
|
||||||
else
|
else
|
||||||
out.read(fdo[0]);
|
out.read(fdo[0]);
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
|
@ -6,11 +6,11 @@ namespace jet {
|
|||||||
__tag::__tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, this, this) {
|
__tag::__tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, this, this) {
|
||||||
evaluate = false;
|
evaluate = false;
|
||||||
output = false;
|
output = false;
|
||||||
if(!variableDefined("name"))
|
if(!keywordDefined("name"))
|
||||||
throw coreutils::Exception("tag must have a name.");
|
throw coreutils::Exception("tag must have a name.");
|
||||||
if(!hasContainer)
|
if(!hasContainer)
|
||||||
throw coreutils::Exception("tag requires a container to process.");
|
throw coreutils::Exception("tag requires a container to process.");
|
||||||
global.tags[variables["name"]] = container; // TODO: process container for further tag definitions.
|
global.tags[keywords["name"]] = container; // TODO: process container for further tag definitions.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
50
__until.cpp
50
__until.cpp
@ -12,51 +12,51 @@ namespace jet {
|
|||||||
bool exprMethod = false;
|
bool exprMethod = false;
|
||||||
coreutils::MString exprSaved;
|
coreutils::MString exprSaved;
|
||||||
|
|
||||||
if(variableDefined("value1")) {
|
if(keywordDefined("value1")) {
|
||||||
|
|
||||||
if(variableDefined("expr"))
|
if(keywordDefined("expr"))
|
||||||
throw coreutils::Exception("either value1 or expr can be specified but not both.");
|
throw coreutils::Exception("either value1 or expr can be specified but not both.");
|
||||||
if(!variableDefined("value2"))
|
if(!keywordDefined("value2"))
|
||||||
throw coreutils::Exception("value2 required if value1 specified.");
|
throw coreutils::Exception("value2 required if value1 specified.");
|
||||||
if(!variableDefined("type"))
|
if(!keywordDefined("type"))
|
||||||
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
||||||
|
|
||||||
int rc = variables["value1"].compare(variables["value2"]);
|
int rc = keywords["value1"].compare(keywords["value2"]);
|
||||||
if(((variables["type"] == "eq") && (rc == 0)) ||
|
if(((keywords["type"] == "eq") && (rc == 0)) ||
|
||||||
((variables["type"] == "ne") && (rc != 0)) ||
|
((keywords["type"] == "ne") && (rc != 0)) ||
|
||||||
((variables["type"] == "lt") && (rc == -1)) ||
|
((keywords["type"] == "lt") && (rc == -1)) ||
|
||||||
((variables["type"] == "le") && (rc != 1)) ||
|
((keywords["type"] == "le") && (rc != 1)) ||
|
||||||
((variables["type"] == "gt") && (rc == 1)) ||
|
((keywords["type"] == "gt") && (rc == 1)) ||
|
||||||
((variables["type"] == "ge") && (rc != -1)))
|
((keywords["type"] == "ge") && (rc != -1)))
|
||||||
booleanResult = true;
|
booleanResult = true;
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
|
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
|
||||||
}
|
}
|
||||||
else if(variableDefined("expr")) {
|
else if(keywordDefined("expr")) {
|
||||||
if(variableDefined("value2"))
|
if(keywordDefined("value2"))
|
||||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
throw coreutils::Exception("value2 should not be specified with expr.");
|
||||||
if(variableDefined("type"))
|
if(keywordDefined("type"))
|
||||||
throw coreutils::Exception("type should not be specified with expr.");
|
throw coreutils::Exception("type should not be specified with expr.");
|
||||||
exprMethod = true;
|
exprMethod = true;
|
||||||
exprSaved = variables["expr"];
|
exprSaved = keywords["expr"];
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
if(exprMethod) {
|
if(exprMethod) {
|
||||||
variables["expr"].reset();
|
keywords["expr"].reset();
|
||||||
variables["expr"] = exprSaved;
|
keywords["expr"] = exprSaved;
|
||||||
resolveKeyword("expr");
|
resolveKeyword("expr");
|
||||||
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
|
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||||
} else {
|
} else {
|
||||||
booleanResult = false;
|
booleanResult = false;
|
||||||
int rc = variables["value1"].compare(variables["value2"]);
|
int rc = keywords["value1"].compare(keywords["value2"]);
|
||||||
if(((variables["type"] == "eq") && (rc == 0)) ||
|
if(((keywords["type"] == "eq") && (rc == 0)) ||
|
||||||
((variables["type"] == "ne") && (rc != 0)) ||
|
((keywords["type"] == "ne") && (rc != 0)) ||
|
||||||
((variables["type"] == "lt") && (rc == -1)) ||
|
((keywords["type"] == "lt") && (rc == -1)) ||
|
||||||
((variables["type"] == "le") && (rc != 1)) ||
|
((keywords["type"] == "le") && (rc != 1)) ||
|
||||||
((variables["type"] == "gt") && (rc == 1)) ||
|
((keywords["type"] == "gt") && (rc == 1)) ||
|
||||||
((variables["type"] == "ge") && (rc != -1)))
|
((keywords["type"] == "ge") && (rc != -1)))
|
||||||
booleanResult = true;
|
booleanResult = true;
|
||||||
}
|
}
|
||||||
} while(booleanResult);
|
} while(booleanResult);
|
||||||
|
52
__while.cpp
52
__while.cpp
@ -12,51 +12,51 @@ namespace jet {
|
|||||||
bool exprMethod = false;
|
bool exprMethod = false;
|
||||||
coreutils::MString exprSaved;
|
coreutils::MString exprSaved;
|
||||||
|
|
||||||
if(variableDefined("value1")) {
|
if(keywordDefined("value1")) {
|
||||||
|
|
||||||
if(variableDefined("expr"))
|
if(keywordDefined("expr"))
|
||||||
throw coreutils::Exception("either value1 or expr can be specified but not both.");
|
throw coreutils::Exception("either value1 or expr can be specified but not both.");
|
||||||
if(!variableDefined("value2"))
|
if(!keywordDefined("value2"))
|
||||||
throw coreutils::Exception("value2 required if value1 specified.");
|
throw coreutils::Exception("value2 required if value1 specified.");
|
||||||
if(!variableDefined("type"))
|
if(!keywordDefined("type"))
|
||||||
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
||||||
|
|
||||||
int rc = variables["value1"].compare(variables["value2"]);
|
int rc = keywords["value1"].compare(keywords["value2"]);
|
||||||
if(((variables["type"] == "eq") && (rc == 0)) ||
|
if(((keywords["type"] == "eq") && (rc == 0)) ||
|
||||||
((variables["type"] == "ne") && (rc != 0)) ||
|
((keywords["type"] == "ne") && (rc != 0)) ||
|
||||||
((variables["type"] == "lt") && (rc == -1)) ||
|
((keywords["type"] == "lt") && (rc == -1)) ||
|
||||||
((variables["type"] == "le") && (rc != 1)) ||
|
((keywords["type"] == "le") && (rc != 1)) ||
|
||||||
((variables["type"] == "gt") && (rc == 1)) ||
|
((keywords["type"] == "gt") && (rc == 1)) ||
|
||||||
((variables["type"] == "ge") && (rc != -1)))
|
((keywords["type"] == "ge") && (rc != -1)))
|
||||||
booleanResult = true;
|
booleanResult = true;
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
|
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
|
||||||
}
|
}
|
||||||
else if(variableDefined("expr")) {
|
else if(keywordDefined("expr")) {
|
||||||
if(variableDefined("value2"))
|
if(keywordDefined("value2"))
|
||||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
throw coreutils::Exception("value2 should not be specified with expr.");
|
||||||
if(variableDefined("type"))
|
if(keywordDefined("type"))
|
||||||
throw coreutils::Exception("type should not be specified with expr.");
|
throw coreutils::Exception("type should not be specified with expr.");
|
||||||
exprMethod = true;
|
exprMethod = true;
|
||||||
exprSaved = variables["expr"];
|
exprSaved = keywords["expr"];
|
||||||
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
|
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||||
}
|
}
|
||||||
while(booleanResult) {
|
while(booleanResult) {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
if(exprMethod) {
|
if(exprMethod) {
|
||||||
variables["expr"].reset();
|
keywords["expr"].reset();
|
||||||
variables["expr"] = exprSaved;
|
keywords["expr"] = exprSaved;
|
||||||
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
|
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||||
} else {
|
} else {
|
||||||
booleanResult = false;
|
booleanResult = false;
|
||||||
int rc = variables["value1"].compare(variables["value2"]);
|
int rc = keywords["value1"].compare(keywords["value2"]);
|
||||||
if(((variables["type"] == "eq") && (rc == 0)) ||
|
if(((keywords["type"] == "eq") && (rc == 0)) ||
|
||||||
((variables["type"] == "ne") && (rc != 0)) ||
|
((keywords["type"] == "ne") && (rc != 0)) ||
|
||||||
((variables["type"] == "lt") && (rc == -1)) ||
|
((keywords["type"] == "lt") && (rc == -1)) ||
|
||||||
((variables["type"] == "le") && (rc != 1)) ||
|
((keywords["type"] == "le") && (rc != 1)) ||
|
||||||
((variables["type"] == "gt") && (rc == 1)) ||
|
((keywords["type"] == "gt") && (rc == 1)) ||
|
||||||
((variables["type"] == "ge") && (rc != -1)))
|
((keywords["type"] == "ge") && (rc != -1)))
|
||||||
booleanResult = true;
|
booleanResult = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,44 +9,44 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
|
||||||
if(!variableDefined("path"))
|
if(!keywordDefined("path"))
|
||||||
throw coreutils::Exception("whiledir tag must specify a path.");
|
throw coreutils::Exception("whiledir tag must specify a path.");
|
||||||
resolveKeyword("path");
|
resolveKeyword("path");
|
||||||
resolveKeyword("sort");
|
resolveKeyword("sort");
|
||||||
if(variableDefined("sort") && (variables["sort"] == "true")) {
|
if(keywordDefined("sort") && (keywords["sort"] == "true")) {
|
||||||
std::vector<std::filesystem::directory_entry> entries;
|
std::vector<std::filesystem::directory_entry> entries;
|
||||||
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
|
||||||
entries.push_back(entry);
|
entries.push_back(entry);
|
||||||
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
|
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
|
||||||
for(const auto &entry : entries) {
|
for(const auto &entry : entries) {
|
||||||
if(variableDefined("fullpath")) {
|
if(keywordDefined("fullpath")) {
|
||||||
resolveKeyword("fullpath");
|
resolveKeyword("fullpath");
|
||||||
global.variables[variables["fullpath"]] = entry.path();
|
global.variables[keywords["fullpath"]] = entry.path();
|
||||||
}
|
}
|
||||||
if(variableDefined("filename")) {
|
if(keywordDefined("filename")) {
|
||||||
resolveKeyword("filename");
|
resolveKeyword("filename");
|
||||||
global.variables[variables["filename"]] = entry.path().filename();
|
global.variables[keywords["filename"]] = entry.path().filename();
|
||||||
}
|
}
|
||||||
if(variableDefined("filenamenoextension")) {
|
if(keywordDefined("filenamenoextension")) {
|
||||||
resolveKeyword("filenamenoextension");
|
resolveKeyword("filenamenoextension");
|
||||||
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
global.variables[keywords["filenamenoextension"]] = entry.path().stem();
|
||||||
}
|
}
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
|
||||||
if(variableDefined("fullpath")) {
|
if(keywordDefined("fullpath")) {
|
||||||
resolveKeyword("fullpath");
|
resolveKeyword("fullpath");
|
||||||
global.variables[variables["fullpath"]] = entry.path();
|
global.variables[keywords["fullpath"]] = entry.path();
|
||||||
}
|
}
|
||||||
if(variableDefined("filename")) {
|
if(keywordDefined("filename")) {
|
||||||
resolveKeyword("filename");
|
resolveKeyword("filename");
|
||||||
global.variables[variables["filename"]] = entry.path().filename();
|
global.variables[keywords["filename"]] = entry.path().filename();
|
||||||
}
|
}
|
||||||
if(variableDefined("filenamenoextension")) {
|
if(keywordDefined("filenamenoextension")) {
|
||||||
resolveKeyword("filenamenoextension");
|
resolveKeyword("filenamenoextension");
|
||||||
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
global.variables[keywords["filenamenoextension"]] = entry.path().stem();
|
||||||
}
|
}
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
|
@ -7,12 +7,12 @@ namespace jet {
|
|||||||
|
|
||||||
__whilerow::__whilerow(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
__whilerow::__whilerow(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) {
|
||||||
|
|
||||||
int count = variables["count"].asInteger();
|
int count = keywords["count"].asInteger();
|
||||||
|
|
||||||
while ((count != 0) && global.getSession(variables["sessionid"])->hasRow()) {
|
while ((count != 0) && global.getSession(keywords["sessionid"])->hasRow()) {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
global.getSession(variables["sessionid"])->nextRow();
|
global.getSession(keywords["sessionid"])->nextRow();
|
||||||
--count;
|
--count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
__write.cpp
26
__write.cpp
@ -12,35 +12,35 @@ namespace jet {
|
|||||||
int mode = 0;
|
int mode = 0;
|
||||||
int len;
|
int len;
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
if(!variableDefined("file"))
|
if(!keywordDefined("file"))
|
||||||
throw coreutils::Exception("write tag must have file defined.");
|
throw coreutils::Exception("write tag must have file defined.");
|
||||||
resolveKeyword("file");
|
resolveKeyword("file");
|
||||||
if(!variableDefined("expr") && variableDefined("value") && hasContainer)
|
if(!keywordDefined("expr") && keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("write tag cannot have both value and a container.");
|
throw coreutils::Exception("write tag cannot have both value and a container.");
|
||||||
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
|
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
|
||||||
throw coreutils::Exception("write tag cannot have both expr and a container.");
|
throw coreutils::Exception("write tag cannot have both expr and a container.");
|
||||||
if(variableDefined("expr") && variableDefined("value") && !hasContainer)
|
if(keywordDefined("expr") && keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("write tag cannot have both expr and value.");
|
throw coreutils::Exception("write tag cannot have both expr and value.");
|
||||||
if(!variableDefined("expr") && !variableDefined("value") && !hasContainer)
|
if(!keywordDefined("expr") && !keywordDefined("value") && !hasContainer)
|
||||||
throw coreutils::Exception("write tag must have a value, expr or a container.");
|
throw coreutils::Exception("write tag must have a value, expr or a container.");
|
||||||
if(!variableDefined("mode"))
|
if(!keywordDefined("mode"))
|
||||||
throw coreutils::Exception("write tag must have a mode keyword.");
|
throw coreutils::Exception("write tag must have a mode keyword.");
|
||||||
resolveKeyword("mode");
|
resolveKeyword("mode");
|
||||||
if(variables["mode"] == "append")
|
if(keywords["mode"] == "append")
|
||||||
mode = O_APPEND;
|
mode = O_APPEND;
|
||||||
else if(variables["mode"] == "overwrite")
|
else if(keywords["mode"] == "overwrite")
|
||||||
mode = O_TRUNC;
|
mode = O_TRUNC;
|
||||||
else
|
else
|
||||||
throw coreutils::Exception("mode keyword must be 'overwrite' or 'append'.");
|
throw coreutils::Exception("mode keyword must be 'overwrite' or 'append'.");
|
||||||
int fd = open(variables["file"].c_str(), mode, 0644); // TODO: Need to add O_CREAT and AUTH flags.
|
int fd = open(keywords["file"].c_str(), mode, 0644); // TODO: Need to add O_CREAT and AUTH flags.
|
||||||
if(hasContainer && !evaluate)
|
if(hasContainer && !evaluate)
|
||||||
len = write(fd, container.getData(), container.getLength());
|
len = write(fd, container.getData(), container.getLength());
|
||||||
else if(hasContainer && evaluate)
|
else if(hasContainer && evaluate)
|
||||||
len = write(fd, out.getData(), out.getLength());
|
len = write(fd, out.getData(), out.getLength());
|
||||||
else if(!hasContainer && variableDefined("value"))
|
else if(!hasContainer && keywordDefined("value"))
|
||||||
len = write(fd, variables["value"].getData(), variables["value"].getLength());
|
len = write(fd, variables["value"].getData(), keywords["value"].getLength());
|
||||||
else if(!hasContainer && variableDefined("expr"))
|
else if(!hasContainer && keywordDefined("expr"))
|
||||||
len = write(fd, variables["expr"].getData(), variables["expr"].getLength());
|
len = write(fd, keywords["expr"].getData(), keywords["expr"].getLength());
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user