#include "__while.h" #include "Exception.h" #include "Operand.h" #include namespace jet { __while::__while(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) { coreutils::MString result; bool booleanResult = false; bool exprMethod = false; coreutils::MString exprSaved; if(keywordDefined("value1")) { if(keywordDefined("expr")) throw coreutils::Exception("either value1 or expr can be specified but not both."); if(!keywordDefined("value2")) throw coreutils::Exception("value2 required if value1 specified."); if(!keywordDefined("type")) throw coreutils::Exception("type expected if value1 and value2 specified."); 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(keywordDefined("expr")) { if(keywordDefined("value2")) throw coreutils::Exception("value2 should not be specified with expr."); if(keywordDefined("type")) throw coreutils::Exception("type should not be specified with expr."); exprMethod = true; exprSaved = keywords["expr"]; booleanResult = Operand(keywords["expr"], global, parent->variables, keywords).boolean; } while(booleanResult) { processContainer(container); container.reset(); if(exprMethod) { keywords["expr"].reset(); keywords["expr"] = exprSaved; booleanResult = Operand(keywords["expr"], global, parent->variables, keywords).boolean; } else { booleanResult = false; 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; } } } }