#include "__dump.h" #include "Exception.h" #include #include #include namespace jet { __dump::__dump(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) { if(!keywordDefined("file")) throw coreutils::Exception("file must be sppecified for dump tag."); std::ofstream outFile(keywords["file"].str()); if(global.cgi) { outFile << "*** CGI VARIABLES ***" << std::endl; // for (auto i = global.cgiVariables.begin(); i != global.cgiVariables.end(); i++) // outFile << i->first << "=[" << i->second << "]" << std::endl; } outFile << "*** GLOBAL VARIABLES ***" << std::endl; for (auto i = global.variables.begin(); i != global.variables.end(); i++) outFile << i->first << "=[" << i->second << "]" << std::endl; outFile << "*** LOCAL VARIABLES ***" << std::endl; for (auto i = local->variables.begin(); i != local->variables.end(); i++) outFile << i->first << "=[" << i->second << "]" << std::endl; outFile << "*** KEYWORD VALUES ***" << std::endl; for (auto i = parent->keywords.begin(); i != parent->keywords.end(); i++) outFile << i->first << "=[" << i->second << "]" << std::endl; outFile << "*** COOKIES ***" << std::endl; for (auto i = global.cookies.data.begin(); i != global.cookies.data.end(); i++) outFile << i->first << "=[" << i->second << "]" << std::endl; // Custom definitions now have real scoping - one // defined directly inside another custom tag's own invocation is // only visible for the rest of that invocation (see Tag.h's // isCustomTagBoundary/localTags doc comment). Render the actual // tree currently in effect at this point in the script: global at // the root, then each enclosing custom-tag invocation nested one // level deeper, outermost first - if there's no active local scope // (this isn't running inside any custom tag's expansion), // that's just the root with nothing nested under it. outFile << "*** DEFINED TAGS ***" << std::endl; outFile << "(global)" << std::endl; for (auto i = global.tags.begin(); i != global.tags.end(); i++) outFile << " " << i->first << std::endl; std::vector scopeChain; for (Tag *scope = this; scope; scope = scope->parent) if (scope->isCustomTagBoundary) scopeChain.push_back(scope); int depth = 1; for (auto it = scopeChain.rbegin(); it != scopeChain.rend(); ++it) { Tag *boundary = *it; coreutils::MString indent; for (int d = 0; d < depth; d++) indent << " "; outFile << indent << "(inside " << boundary->name << ")" << std::endl; for (auto i = boundary->localTags.begin(); i != boundary->localTags.end(); i++) outFile << indent << " " << i->first << std::endl; depth++; } outFile.close(); } }