From d7dd1b4dd279f6686de88682ac0761ccd9ecb72c Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 11 Nov 2024 09:51:24 -0800 Subject: [PATCH] Upgraded whiledir tag to use resolution keyword method. --- __whiledir.cpp | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/__whiledir.cpp b/__whiledir.cpp index 0f4cc3d..db6ff55 100644 --- a/__whiledir.cpp +++ b/__whiledir.cpp @@ -11,29 +11,43 @@ namespace jet { __whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) { if(!variableDefined("path")) throw coreutils::Exception("whiledir tag must specify a path."); + resolveKeyword("path"); + resolveKeyword("sort"); 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) { - if(variableDefined("fullpath")) - global.variables[variables["fullpath"]] = entry.path(); - if(variableDefined("filename")) - global.variables[variables["filename"]] = entry.path().filename(); - if(variableDefined("filenamenoextension")) - global.variables[variables["filenamenoextension"]] = entry.path().stem(); + if(variableDefined("fullpath")) { + resolveKeyword("fullpath"); + global.variables[variables["fullpath"]] = entry.path(); + } + if(variableDefined("filename")) { + resolveKeyword("filename"); + global.variables[variables["filename"]] = entry.path().filename(); + } + if(variableDefined("filenamenoextension")) { + resolveKeyword("filenamenoextension"); + global.variables[variables["filenamenoextension"]] = entry.path().stem(); + } processContainer(container); container.reset(); } } else { for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) { - if(variableDefined("fullpath")) - global.variables[variables["fullpath"]] = entry.path(); - if(variableDefined("filename")) - global.variables[variables["filename"]] = entry.path().filename(); - if(variableDefined("filenamenoextension")) - global.variables[variables["filenamenoextension"]] = entry.path().stem(); + if(variableDefined("fullpath")) { + resolveKeyword("fullpath"); + global.variables[variables["fullpath"]] = entry.path(); + } + if(variableDefined("filename")) { + resolveKeyword("filename"); + global.variables[variables["filename"]] = entry.path().filename(); + } + if(variableDefined("filenamenoextension")) { + resolveKeyword("filenamenoextension"); + global.variables[variables["filenamenoextension"]] = entry.path().stem(); + } processContainer(container); container.reset(); }