diff --git a/Tag.cpp b/Tag.cpp index 7e126ad..923a588 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -17,6 +17,7 @@ #include "__jet.h" #include "__while.h" #include "__header.h" +#include "__whiledir.h" #include namespace jet { @@ -155,6 +156,9 @@ namespace jet { } else if(ifTagName(in, "header")) { __header _header(in, out, global); continue; + } else if(ifTagName(in, "whiledir")) { + __whiledir _whiledir(in, out, global); + continue; } else { out.write(in.charAt(0)); in.nextChar(); diff --git a/__while.cpp b/__while.cpp index 022bca4..cb3ce71 100644 --- a/__while.cpp +++ b/__while.cpp @@ -25,7 +25,7 @@ namespace jet { } while(true) { - parseContainer(container); + processContainer(container); } } diff --git a/__whiledir.cpp b/__whiledir.cpp new file mode 100644 index 0000000..d930dc2 --- /dev/null +++ b/__whiledir.cpp @@ -0,0 +1,36 @@ +#include "__whiledir.h" +#include "Exception.h" +#include "__mysql.h" +#include +#include +#include +#include + +namespace jet { + + __whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { + if(!variableDefined("path")) + throw coreutils::Exception("whiledir tag must specify a path."); + if(!variableDefined("name")) + throw coreutils::Exception("whiledir tag requires a name tag."); + if(variableDefined("sort") && (variables["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) { + variables[variables["name"]] = entry.path(); + processContainer(container); + container.reset(); + } + } else { + for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) { + variables[variables["name"]] = entry.path(); + processContainer(container); + container.reset(); + } + } + + } + +} diff --git a/__whiledir.h b/__whiledir.h new file mode 100644 index 0000000..cccf50a --- /dev/null +++ b/__whiledir.h @@ -0,0 +1,19 @@ +#ifndef ____whiledir_h__ +#define ____whiledir_h__ + +#include "Tag.h" +#include "ZString.h" +#include "MString.h" + +namespace jet { + + class __whiledir : public Tag { + + public: + __whiledir(coreutils::ZString &in, coreutils::MString &parent, Global &global); + + }; + +} + +#endif diff --git a/jet-2.0 b/jet-2.0 index f90e007..459a7e1 100755 Binary files a/jet-2.0 and b/jet-2.0 differ diff --git a/testjet.jet b/testjet.jet index 7b77dc0..dfcb31b 100755 --- a/testjet.jet +++ b/testjet.jet @@ -55,5 +55,8 @@ $[ls] $[filex] + + #[file] +