From 9622b5cf8c9840d90d93553aa3df8cda838c9d89 Mon Sep 17 00:00:00 2001 From: brad Arant Date: Thu, 2 Jan 2025 16:43:53 -0800 Subject: [PATCH] Moved keywords from local variables to keywords map. --- Tag.cpp | 24 +++++++++---------- Tag.h | 3 ++- __call.cpp | 28 +++++++++++------------ __cookie.cpp | 22 +++++++++--------- __dump.cpp | 4 ++-- __for.cpp | 28 +++++++++++------------ __header.cpp | 22 +++++++++--------- __if.cpp | 30 ++++++++++++------------ __ifrow.cpp | 4 ++-- __include.cpp | 4 ++-- __jet.cpp | 4 ++-- __mysql.cpp | 12 +++++----- __read.cpp | 8 +++---- __set.cpp | 62 +++++++++++++++++++++++++------------------------- __sql.cpp | 4 ++-- __stream.cpp | 4 ++-- __system.cpp | 12 +++++----- __tag.cpp | 4 ++-- __until.cpp | 50 ++++++++++++++++++++-------------------- __while.cpp | 52 +++++++++++++++++++++--------------------- __whiledir.cpp | 28 +++++++++++------------ __whilerow.cpp | 6 ++--- __write.cpp | 26 ++++++++++----------- 23 files changed, 221 insertions(+), 220 deletions(-) diff --git a/Tag.cpp b/Tag.cpp index 37705d6..444cc7d 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -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) { diff --git a/Tag.h b/Tag.h index ab992a4..a546c79 100644 --- a/Tag.h +++ b/Tag.h @@ -16,6 +16,7 @@ namespace jet { void resolveKeyword(coreutils::ZString keyword); std::map variables; + std::map 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); diff --git a/__call.cpp b/__call.cpp index ecf8784..cc2fa39 100644 --- a/__call.cpp +++ b/__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) { 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); } } diff --git a/__cookie.cpp b/__cookie.cpp index 0cf32b7..a51665f 100644 --- a/__cookie.cpp +++ b/__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) { 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"]; } } } diff --git a/__dump.cpp b/__dump.cpp index 25c8476..aa633c0 100644 --- a/__dump.cpp +++ b/__dump.cpp @@ -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; diff --git a/__for.cpp b/__for.cpp index 1ff9319..7277b23 100644 --- a/__for.cpp +++ b/__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) { 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."); } diff --git a/__header.cpp b/__header.cpp index 965e481..e583d21 100644 --- a/__header.cpp +++ b/__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) { 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"]; } } } diff --git a/__if.cpp b/__if.cpp index 716c351..b8f4f02 100644 --- a/__if.cpp +++ b/__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") { 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); diff --git a/__ifrow.cpp b/__ifrow.cpp index d31c7cc..159d9a1 100644 --- a/__ifrow.cpp +++ b/__ifrow.cpp @@ -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); diff --git a/__include.cpp b/__include.cpp index 5609931..e5ac7eb 100644 --- a/__include.cpp +++ b/__include.cpp @@ -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 { diff --git a/__jet.cpp b/__jet.cpp index 722f3f8..8d14bb0 100644 --- a/__jet.cpp +++ b/__jet.cpp @@ -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")); diff --git a/__mysql.cpp b/__mysql.cpp index 4c44db4..db7b71f 100644 --- a/__mysql.cpp +++ b/__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) { - 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."); diff --git a/__read.cpp b/__read.cpp index e62a3f6..fb03b6e 100644 --- a/__read.cpp +++ b/__read.cpp @@ -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); } diff --git a/__set.cpp b/__set.cpp index a23dfff..df9d7cb 100644 --- a/__set.cpp +++ b/__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) { 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"]; } } diff --git a/__sql.cpp b/__sql.cpp index 7db6ee4..2488aea 100644 --- a/__sql.cpp +++ b/__sql.cpp @@ -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); } } diff --git a/__stream.cpp b/__stream.cpp index 6d5c055..9263ead 100644 --- a/__stream.cpp +++ b/__stream.cpp @@ -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; diff --git a/__system.cpp b/__system.cpp index 416b73a..08ae1f2 100644 --- a/__system.cpp +++ b/__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) { 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); diff --git a/__tag.cpp b/__tag.cpp index b75fae0..68c66a2 100644 --- a/__tag.cpp +++ b/__tag.cpp @@ -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. } } diff --git a/__until.cpp b/__until.cpp index d8c325d..79ba915 100644 --- a/__until.cpp +++ b/__until.cpp @@ -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); diff --git a/__while.cpp b/__while.cpp index ac6603f..4f17fe0 100644 --- a/__while.cpp +++ b/__while.cpp @@ -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; } } diff --git a/__whiledir.cpp b/__whiledir.cpp index 8d063f4..0aa2302 100644 --- a/__whiledir.cpp +++ b/__whiledir.cpp @@ -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 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(); diff --git a/__whilerow.cpp b/__whilerow.cpp index ab84c32..5e2caef 100644 --- a/__whilerow.cpp +++ b/__whilerow.cpp @@ -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; } diff --git a/__write.cpp b/__write.cpp index 4581506..937ba75 100644 --- a/__write.cpp +++ b/__write.cpp @@ -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); }