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) {
|
||||
if(!variableDefined("path"))
|
||||
throw coreutils::Exception("whiledir tag must specify a path.");
|
||||
resolveKeyword("path");
|
||||
resolveKeyword("sort");
|
||||
if(variableDefined("sort") && (variables["sort"] == "true")) {
|
||||
std::vector<std::filesystem::directory_entry> 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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user