Moved keywords from local variables to keywords map.

This commit is contained in:
brad Arant 2025-01-02 16:43:53 -08:00
parent 907f449ecc
commit 9622b5cf8c
23 changed files with 221 additions and 220 deletions

24
Tag.cpp
View File

@ -53,19 +53,19 @@ namespace jet {
if(!finished) {
coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
if(in.ifNext("=\"")) {
if(variables.count(keywordName) == 0)
variables[keywordName] = in.getTokenExclude("\"");
if(keywords.count(keywordName) == 0)
keywords[keywordName] = in.getTokenExclude("\"");
else
throw coreutils::Exception("keyword name must be unique for tag.");
}
if(!in.ifNext("\"")) {}
}
}
if(variableDefined("filterblanklines")) {
filterBlankLines = variables["filterblanklines"] == "true" ? true: false;
if(keywordDefined("filterblanklines")) {
filterBlankLines = keywords["filterblanklines"] == "true" ? true: false;
}
if(variableDefined("trimlines")) {
trimLines = variables["trimlines"] == "true" ? true: false;
if(keywordDefined("trimlines")) {
trimLines = keywords["trimlines"] == "true" ? true: false;
}
if(hasContainer) {
bool hasSplitTag = splitTagName == "" ? false: true;
@ -89,10 +89,10 @@ namespace jet {
}
}
setZString(in.parsed());
if(variableDefined("eval")) {
if(variables["eval"] == "yes") {
if(keywordDefined("eval")) {
if(keywords["eval"] == "yes") {
evaluate = true;
} else if(variables["eval"] == "no") {
} else if(keywords["eval"] == "no") {
evaluate = false;
} else
throw coreutils::Exception("keyword 'eval' must be 'yes' or 'no'.");
@ -111,7 +111,7 @@ namespace jet {
}
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) {
@ -335,8 +335,8 @@ namespace jet {
}
}
bool Tag::variableDefined(coreutils::ZString keyword) {
return variables.find(keyword) != variables.end();
bool Tag::keywordDefined(coreutils::ZString keyword) {
return keywords.find(keyword) != keywords.end();
}
bool Tag::ifNested(coreutils::ZString &in) {

3
Tag.h
View File

@ -16,6 +16,7 @@ namespace jet {
void resolveKeyword(coreutils::ZString keyword);
std::map<coreutils::MString, coreutils::MString> variables;
std::map<coreutils::MString, coreutils::MString> keywords;
coreutils::ZString name;
coreutils::ZString container;
coreutils::ZString container2;
@ -25,7 +26,7 @@ namespace jet {
protected:
bool hasContainer = false;
bool hasContainer2 = false;
bool variableDefined(coreutils::ZString variable);
bool keywordDefined(coreutils::ZString variable);
void parseContainer(coreutils::ZString &in, coreutils::MString &out);
void processContainer(coreutils::ZString &container);
void copyContainer(coreutils::ZString &in, coreutils::MString &out);

View File

@ -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) {
if(hasContainer)
throw coreutils::Exception("call tag cannot have a container.");
if(!variableDefined("pgm"))
if(!keywordDefined("pgm"))
throw coreutils::Exception("pgm keyword must be specified.");
resolveKeyword("pgm");
for(ix = 0; ix <= 50; ++ix)
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) {
coreutils::MString arg("arg");
arg << ix;
if(variableDefined(arg)) {
if(keywordDefined(arg)) {
resolveKeyword(arg);
argv[ix] = variables[arg].c_str();
argv[ix] = keywords[arg].c_str();
} else
break;
}
@ -32,7 +32,7 @@ namespace jet {
if(pid == 0) {
close(fdo[0]);
dup2(fdo[1], 1);
if(variableDefined("input")) {
if(keywordDefined("input")) {
resolveKeyword("input");
coreutils::ZString input(variables["input"]);
pipe(fdi);
@ -50,23 +50,23 @@ namespace jet {
exit(errno);
}
close(fdo[1]);
if(variableDefined("name")) {
if(keywordDefined("name")) {
resolveKeyword("name");
if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]].read(fdo[0]);
else if(variables["scope"] == "local")
this->local->variables[variables["name"]].read(fdo[0]);
else if(variables["scope"] == "parent")
this->local->parent->local->variables[variables["name"]].read(fdo[0]);
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]].read(fdo[0]);
else if(keywords["scope"] == "local")
this->local->variables[keywords["name"]].read(fdo[0]);
else if(keywords["scope"] == "parent")
this->local->parent->local->variables[keywords["name"]].read(fdo[0]);
else
throw coreutils::Exception("scope value is not valid.");
} else
out.read(fdo[0]);
waitpid(pid, &status, 0);
if(variableDefined("error")) {
if(keywordDefined("error")) {
resolveKeyword("error");
global.variables[variables["error"]] = (status >> 8 & 255);
global.variables[keywords["error"]] = (status >> 8 & 255);
}
}

View File

@ -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) {
output = false;
if(!variableDefined("name"))
if(!keywordDefined("name"))
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.");
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
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.");
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.");
resolveKeyword("name");
if(variableDefined("expr")) {
if(variableDefined("eval"))
if(keywordDefined("expr")) {
if(keywordDefined("eval"))
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) {
processContainer(container);
if(evaluate) {
global.headers[variables["name"]] = out;
global.headers[keywords["name"]] = out;
} else {
global.headers[variables["name"]] = container;
global.headers[keywords["name"]] = container;
}
} else {
resolveKeyword("value");
global.headers[variables["Set-Cookie"]] = variables["value"];
global.headers[keywords["Set-Cookie"]] = keywords["value"];
}
}
}

View File

@ -6,10 +6,10 @@
namespace jet {
__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.");
std::ofstream outFile(variables["file"].str());
std::ofstream outFile(keywords["file"].str());
outFile << "*** CGI VARIABLES ***" << std::endl;

View File

@ -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) {
double counter = 0.0f;
bool nameDefined = variableDefined("name");
if(variableDefined("start")) {
bool nameDefined = keywordDefined("name");
if(keywordDefined("start")) {
resolveKeyword("start");
counter = variables["start"].asDouble();
variables["start"].reset();
counter = keywords["start"].asDouble();
keywords["start"].reset();
}
if(variableDefined("end"))
if(keywordDefined("end"))
resolveKeyword("end");
else
throw coreutils::Exception("for tag requires end keyword.");
if(variableDefined("step"))
if(keywordDefined("step"))
resolveKeyword("step");
else
throw coreutils::Exception("for tag requires step keyword.");
for(double ix = counter; ix <= variables["end"].asDouble(); ix += variables["step"].asDouble()) {
variables["end"].reset();
variables["step"].reset();
keywords["end"].reset();
keywords["step"].reset();
if(nameDefined) {
if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = ix;
else if(variables["scope"] == "local")
this->local->variables[variables["name"]] = ix;
else if(variables["scope"] == "parent")
parent->local->variables[variables["name"]] = ix;
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = ix;
else if(keywords["scope"] == "local")
this->local->variables[keywords["name"]] = ix;
else if(keywords["scope"] == "parent")
parent->local->variables[keywords["name"]] = ix;
else
throw coreutils::Exception("scope value is not valid.");
}

View File

@ -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) {
output = false;
if(!variableDefined("name"))
if(!keywordDefined("name"))
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.");
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
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.");
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.");
resolveKeyword("name");
if(variableDefined("expr")) {
if(variableDefined("eval"))
if(keywordDefined("expr")) {
if(keywordDefined("eval"))
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) {
processContainer(container);
if(evaluate) {
global.headers[variables["name"]] = out;
global.headers[keywords["name"]] = out;
} else {
global.headers[variables["name"]] = container;
global.headers[keywords["name"]] = container;
}
} else {
resolveKeyword("value");
global.headers[variables["name"]] = variables["value"];
global.headers[keywords["name"]] = keywords["value"];
}
}
}

View File

@ -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") {
coreutils::MString result;
bool booleanResult = false;
if(variableDefined("value1")) {
if(keywordDefined("value1")) {
resolveKeyword("value1");
if(variableDefined("expr"))
if(keywordDefined("expr"))
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
if(variableDefined("value2")) {
if(!variableDefined("type"))
if(keywordDefined("value2")) {
if(!keywordDefined("type"))
throw coreutils::Exception("type expected if value1 and value2 specified.");
} else
throw coreutils::Exception("value2 required if value1 specified.");
resolveKeyword("value2");
resolveKeyword("type");
int rc = variables["value1"].compare(variables["value2"]);
if(((variables["type"] == "eq") && (rc == 0)) ||
((variables["type"] == "ne") && (rc != 0)) ||
((variables["type"] == "lt") && (rc == -1)) ||
((variables["type"] == "le") && (rc != 1)) ||
((variables["type"] == "gt") && (rc == 1)) ||
((variables["type"] == "ge") && (rc != -1)))
int rc = keywords["value1"].compare(keywords["value2"]);
if(((keywords["type"] == "eq") && (rc == 0)) ||
((keywords["type"] == "ne") && (rc != 0)) ||
((keywords["type"] == "lt") && (rc == -1)) ||
((keywords["type"] == "le") && (rc != 1)) ||
((keywords["type"] == "gt") && (rc == 1)) ||
((keywords["type"] == "ge") && (rc != -1)))
booleanResult = true;
else
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
} else if(variableDefined("expr")) {
if(variableDefined("value2"))
} else if(keywordDefined("expr")) {
if(keywordDefined("value2"))
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.");
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
}
if(booleanResult)
processContainer(container);

View File

@ -11,10 +11,10 @@ namespace jet {
output = false;
if(!hasContainer)
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.");
resolveKeyword("sessionid");
if(global.getSession(variables["sessionid"])->hasRow())
if(global.getSession(keywords["sessionid"])->hasRow())
processContainer(container);
else
processContainer(container2);

View File

@ -5,13 +5,13 @@
namespace jet {
__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.");
if(hasContainer)
throw coreutils::Exception("include tag should not have a container.");
hasContainer = true;
resolveKeyword("file");
coreutils::File file(variables["file"]);
coreutils::File file(keywords["file"]);
file.read();
container = file.asZString();
try {

View File

@ -6,9 +6,9 @@
namespace jet {
__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");
if(variables["cgi"] == "true") {
if(keywords["cgi"] == "true") {
coreutils::ZString requestMethod(getenv("REQUEST_METHOD"));
if(requestMethod == "POST") {
coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));

View File

@ -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) {
if(!variableDefined("host"))
if(!keywordDefined("host"))
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.");
if(!variableDefined("user"))
if(!keywordDefined("user"))
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.");
resolveKeyword("host");
@ -21,12 +21,12 @@ namespace jet {
resolveKeyword("password");
resolveKeyword("sessionid");
sessionId = variables["sessionid"];
sessionId = keywords["sessionid"];
global.addSession(sessionId, this);
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)
throw coreutils::Exception("database and host parameters are not valid.");

View File

@ -7,18 +7,18 @@
namespace jet {
__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.");
if(!variableDefined("name"))
if(!keywordDefined("name"))
throw coreutils::Exception("name keyword must be specified.");
if(hasContainer)
throw coreutils::Exception("read tag does not have a container.");
resolveKeyword("file");
resolveKeyword("name");
fd = open(variables["file"].c_str(), O_RDONLY);
fd = open(keywords["file"].c_str(), O_RDONLY);
if(fd < 0)
throw coreutils::Exception("file name is not found.");
global.variables[variables["name"]].read(fd);
global.variables[keywords["name"]].read(fd);
close(fd);
}

View File

@ -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) {
output = false;
if(!variableDefined("name"))
if(!keywordDefined("name"))
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.");
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
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.");
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.");
if(variableDefined("expr") && variableDefined("eval"))
if(keywordDefined("expr") && keywordDefined("eval"))
throw coreutils::Exception("Cannot use eval with expr.");
resolveKeyword("name");
if(variableDefined("expr")) {
if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
else if(variables["scope"] == "local")
local->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
else if(variables["scope"] == "parent")
local->parent->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
if(keywordDefined("expr")) {
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
} else if(hasContainer) {
processContainer(container);
if(evaluate) {
if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = out;
else if(variables["scope"] == "local")
local->variables[variables["name"]] = out;
else if(variables["scope"] == "parent")
local->parent->variables[variables["name"]] = out;
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = out;
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = out;
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = out;
} else {
if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = container;
else if(variables["scope"] == "local")
local->variables[variables["name"]] = container;
else if(variables["scope"] == "parent")
local->parent->variables[variables["name"]] = container;
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = container;
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = container;
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = container;
}
} else {
resolveKeyword("value");
if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = variables["value"];
else if(variables["scope"] == "local")
local->variables[variables["name"]] = variables["value"];
else if(variables["scope"] == "parent")
local->parent->variables[variables["name"]] = variables["value"];
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = keywords["value"];
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = keywords["value"];
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = keywords["value"];
}
}

View File

@ -13,11 +13,11 @@ namespace jet {
output = false;
if(!hasContainer)
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.");
resolveKeyword("sessionid");
processContainer(container);
global.getSession(variables["sessionid"])->query(out);
global.getSession(keywords["sessionid"])->query(out);
}
}

View File

@ -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) {
output = false;
if(!variableDefined("name"))
if(!keywordDefined("name"))
throw coreutils::Exception("stream tag must have a file name to stream.");
global.outputHeaders();
int len;
char buffer[1024];
int fd = open(variables["name"].c_str(), O_RDONLY);
int fd = open(keywords["name"].c_str(), O_RDONLY);
do {
len = read(fd, &buffer, 1024);
std::cout << buffer;

View File

@ -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) {
if(hasContainer)
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.");
pipe(fdo);
pid = fork();
if(pid == 0) {
close(fdo[0]);
dup2(fdo[1], 1);
if(variableDefined("input")) {
if(keywordDefined("input")) {
resolveKeyword("input");
coreutils::ZString input(variables["input"]);
coreutils::ZString input(keywords["input"]);
pipe(fdi);
if(fork() == 0) {
close(fdi[0]);
@ -31,13 +31,13 @@ namespace jet {
close(fdi[1]);
dup2(fdi[0], 0);
}
system(variables["cmd"].c_str());
system(keywords["cmd"].c_str());
close(fdo[1]);
exit(errno);
}
close(fdo[1]);
if(variableDefined("name"))
global.variables[variables["name"]].read(fdo[0]);
if(keywordDefined("name"))
global.variables[keywords["name"]].read(fdo[0]);
else
out.read(fdo[0]);
waitpid(pid, &status, 0);

View File

@ -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) {
evaluate = false;
output = false;
if(!variableDefined("name"))
if(!keywordDefined("name"))
throw coreutils::Exception("tag must have a name.");
if(!hasContainer)
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.
}
}

View File

@ -12,51 +12,51 @@ namespace jet {
bool exprMethod = false;
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.");
if(!variableDefined("value2"))
if(!keywordDefined("value2"))
throw coreutils::Exception("value2 required if value1 specified.");
if(!variableDefined("type"))
if(!keywordDefined("type"))
throw coreutils::Exception("type expected if value1 and value2 specified.");
int rc = variables["value1"].compare(variables["value2"]);
if(((variables["type"] == "eq") && (rc == 0)) ||
((variables["type"] == "ne") && (rc != 0)) ||
((variables["type"] == "lt") && (rc == -1)) ||
((variables["type"] == "le") && (rc != 1)) ||
((variables["type"] == "gt") && (rc == 1)) ||
((variables["type"] == "ge") && (rc != -1)))
int rc = keywords["value1"].compare(keywords["value2"]);
if(((keywords["type"] == "eq") && (rc == 0)) ||
((keywords["type"] == "ne") && (rc != 0)) ||
((keywords["type"] == "lt") && (rc == -1)) ||
((keywords["type"] == "le") && (rc != 1)) ||
((keywords["type"] == "gt") && (rc == 1)) ||
((keywords["type"] == "ge") && (rc != -1)))
booleanResult = true;
else
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
}
else if(variableDefined("expr")) {
if(variableDefined("value2"))
else if(keywordDefined("expr")) {
if(keywordDefined("value2"))
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.");
exprMethod = true;
exprSaved = variables["expr"];
exprSaved = keywords["expr"];
}
do {
processContainer(container);
container.reset();
if(exprMethod) {
variables["expr"].reset();
variables["expr"] = exprSaved;
keywords["expr"].reset();
keywords["expr"] = exprSaved;
resolveKeyword("expr");
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
} else {
booleanResult = false;
int rc = variables["value1"].compare(variables["value2"]);
if(((variables["type"] == "eq") && (rc == 0)) ||
((variables["type"] == "ne") && (rc != 0)) ||
((variables["type"] == "lt") && (rc == -1)) ||
((variables["type"] == "le") && (rc != 1)) ||
((variables["type"] == "gt") && (rc == 1)) ||
((variables["type"] == "ge") && (rc != -1)))
int rc = keywords["value1"].compare(keywords["value2"]);
if(((keywords["type"] == "eq") && (rc == 0)) ||
((keywords["type"] == "ne") && (rc != 0)) ||
((keywords["type"] == "lt") && (rc == -1)) ||
((keywords["type"] == "le") && (rc != 1)) ||
((keywords["type"] == "gt") && (rc == 1)) ||
((keywords["type"] == "ge") && (rc != -1)))
booleanResult = true;
}
} while(booleanResult);

View File

@ -12,51 +12,51 @@ namespace jet {
bool exprMethod = false;
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.");
if(!variableDefined("value2"))
if(!keywordDefined("value2"))
throw coreutils::Exception("value2 required if value1 specified.");
if(!variableDefined("type"))
if(!keywordDefined("type"))
throw coreutils::Exception("type expected if value1 and value2 specified.");
int rc = variables["value1"].compare(variables["value2"]);
if(((variables["type"] == "eq") && (rc == 0)) ||
((variables["type"] == "ne") && (rc != 0)) ||
((variables["type"] == "lt") && (rc == -1)) ||
((variables["type"] == "le") && (rc != 1)) ||
((variables["type"] == "gt") && (rc == 1)) ||
((variables["type"] == "ge") && (rc != -1)))
int rc = keywords["value1"].compare(keywords["value2"]);
if(((keywords["type"] == "eq") && (rc == 0)) ||
((keywords["type"] == "ne") && (rc != 0)) ||
((keywords["type"] == "lt") && (rc == -1)) ||
((keywords["type"] == "le") && (rc != 1)) ||
((keywords["type"] == "gt") && (rc == 1)) ||
((keywords["type"] == "ge") && (rc != -1)))
booleanResult = true;
else
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
}
else if(variableDefined("expr")) {
if(variableDefined("value2"))
else if(keywordDefined("expr")) {
if(keywordDefined("value2"))
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.");
exprMethod = true;
exprSaved = variables["expr"];
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
exprSaved = keywords["expr"];
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
}
while(booleanResult) {
processContainer(container);
container.reset();
if(exprMethod) {
variables["expr"].reset();
variables["expr"] = exprSaved;
booleanResult = Operand(variables["expr"], global, parent->variables).boolean;
keywords["expr"].reset();
keywords["expr"] = exprSaved;
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
} else {
booleanResult = false;
int rc = variables["value1"].compare(variables["value2"]);
if(((variables["type"] == "eq") && (rc == 0)) ||
((variables["type"] == "ne") && (rc != 0)) ||
((variables["type"] == "lt") && (rc == -1)) ||
((variables["type"] == "le") && (rc != 1)) ||
((variables["type"] == "gt") && (rc == 1)) ||
((variables["type"] == "ge") && (rc != -1)))
int rc = keywords["value1"].compare(keywords["value2"]);
if(((keywords["type"] == "eq") && (rc == 0)) ||
((keywords["type"] == "ne") && (rc != 0)) ||
((keywords["type"] == "lt") && (rc == -1)) ||
((keywords["type"] == "le") && (rc != 1)) ||
((keywords["type"] == "gt") && (rc == 1)) ||
((keywords["type"] == "ge") && (rc != -1)))
booleanResult = true;
}
}

View File

@ -9,44 +9,44 @@
namespace jet {
__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.");
resolveKeyword("path");
resolveKeyword("sort");
if(variableDefined("sort") && (variables["sort"] == "true")) {
if(keywordDefined("sort") && (keywords["sort"] == "true")) {
std::vector<std::filesystem::directory_entry> entries;
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
entries.push_back(entry);
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
for(const auto &entry : entries) {
if(variableDefined("fullpath")) {
if(keywordDefined("fullpath")) {
resolveKeyword("fullpath");
global.variables[variables["fullpath"]] = entry.path();
global.variables[keywords["fullpath"]] = entry.path();
}
if(variableDefined("filename")) {
if(keywordDefined("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");
global.variables[variables["filenamenoextension"]] = entry.path().stem();
global.variables[keywords["filenamenoextension"]] = entry.path().stem();
}
processContainer(container);
container.reset();
}
} else {
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
if(variableDefined("fullpath")) {
if(keywordDefined("fullpath")) {
resolveKeyword("fullpath");
global.variables[variables["fullpath"]] = entry.path();
global.variables[keywords["fullpath"]] = entry.path();
}
if(variableDefined("filename")) {
if(keywordDefined("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");
global.variables[variables["filenamenoextension"]] = entry.path().stem();
global.variables[keywords["filenamenoextension"]] = entry.path().stem();
}
processContainer(container);
container.reset();

View File

@ -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) {
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);
container.reset();
global.getSession(variables["sessionid"])->nextRow();
global.getSession(keywords["sessionid"])->nextRow();
--count;
}

View File

@ -12,35 +12,35 @@ namespace jet {
int mode = 0;
int len;
processContainer(container);
if(!variableDefined("file"))
if(!keywordDefined("file"))
throw coreutils::Exception("write tag must have file defined.");
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.");
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
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.");
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.");
if(!variableDefined("mode"))
if(!keywordDefined("mode"))
throw coreutils::Exception("write tag must have a mode keyword.");
resolveKeyword("mode");
if(variables["mode"] == "append")
if(keywords["mode"] == "append")
mode = O_APPEND;
else if(variables["mode"] == "overwrite")
else if(keywords["mode"] == "overwrite")
mode = O_TRUNC;
else
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)
len = write(fd, container.getData(), container.getLength());
else if(hasContainer && evaluate)
len = write(fd, out.getData(), out.getLength());
else if(!hasContainer && variableDefined("value"))
len = write(fd, variables["value"].getData(), variables["value"].getLength());
else if(!hasContainer && variableDefined("expr"))
len = write(fd, variables["expr"].getData(), variables["expr"].getLength());
else if(!hasContainer && keywordDefined("value"))
len = write(fd, variables["value"].getData(), keywords["value"].getLength());
else if(!hasContainer && keywordDefined("expr"))
len = write(fd, keywords["expr"].getData(), keywords["expr"].getLength());
close(fd);
}