Upgraded whiledir tag to use resolution keyword method.
This commit is contained in:
parent
93da0f16b3
commit
d7dd1b4dd2
@ -11,29 +11,43 @@ namespace jet {
|
|||||||
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||||
if(!variableDefined("path"))
|
if(!variableDefined("path"))
|
||||||
throw coreutils::Exception("whiledir tag must specify a path.");
|
throw coreutils::Exception("whiledir tag must specify a path.");
|
||||||
|
resolveKeyword("path");
|
||||||
|
resolveKeyword("sort");
|
||||||
if(variableDefined("sort") && (variables["sort"] == "true")) {
|
if(variableDefined("sort") && (variables["sort"] == "true")) {
|
||||||
std::vector<std::filesystem::directory_entry> entries;
|
std::vector<std::filesystem::directory_entry> entries;
|
||||||
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
|
||||||
entries.push_back(entry);
|
entries.push_back(entry);
|
||||||
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
|
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
|
||||||
for(const auto &entry : entries) {
|
for(const auto &entry : entries) {
|
||||||
if(variableDefined("fullpath"))
|
if(variableDefined("fullpath")) {
|
||||||
|
resolveKeyword("fullpath");
|
||||||
global.variables[variables["fullpath"]] = entry.path();
|
global.variables[variables["fullpath"]] = entry.path();
|
||||||
if(variableDefined("filename"))
|
}
|
||||||
|
if(variableDefined("filename")) {
|
||||||
|
resolveKeyword("filename");
|
||||||
global.variables[variables["filename"]] = entry.path().filename();
|
global.variables[variables["filename"]] = entry.path().filename();
|
||||||
if(variableDefined("filenamenoextension"))
|
}
|
||||||
|
if(variableDefined("filenamenoextension")) {
|
||||||
|
resolveKeyword("filenamenoextension");
|
||||||
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
||||||
|
}
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
|
||||||
if(variableDefined("fullpath"))
|
if(variableDefined("fullpath")) {
|
||||||
|
resolveKeyword("fullpath");
|
||||||
global.variables[variables["fullpath"]] = entry.path();
|
global.variables[variables["fullpath"]] = entry.path();
|
||||||
if(variableDefined("filename"))
|
}
|
||||||
|
if(variableDefined("filename")) {
|
||||||
|
resolveKeyword("filename");
|
||||||
global.variables[variables["filename"]] = entry.path().filename();
|
global.variables[variables["filename"]] = entry.path().filename();
|
||||||
if(variableDefined("filenamenoextension"))
|
}
|
||||||
|
if(variableDefined("filenamenoextension")) {
|
||||||
|
resolveKeyword("filenamenoextension");
|
||||||
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
||||||
|
}
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user