|
15 | 15 | #include <tl/expected.hpp> |
16 | 16 |
|
17 | 17 | #include <algorithm> |
| 18 | +#include <cctype> |
18 | 19 | #include <deque> |
19 | 20 | #include <filesystem> |
20 | 21 | #include <fstream> |
@@ -139,19 +140,46 @@ namespace cps::search { |
139 | 140 | return std::vector<fs::path>{name}; |
140 | 141 | } |
141 | 142 |
|
| 143 | + // If the given name is not all lower, we need to search that as well. |
| 144 | + std::vector<std::string> names{std::string{name}}; |
| 145 | + std::string lc{name}; |
| 146 | + std::transform(lc.begin(), lc.end(), lc.begin(), [](const unsigned char ch) { return std::tolower(ch); }); |
| 147 | + if (name != lc) { |
| 148 | + names.push_back(lc); |
| 149 | + } |
| 150 | + |
142 | 151 | // TODO: Need something like pkgconf's --personality option |
143 | 152 | // TODO: we likely either need to return all possible files, or load |
144 | 153 | // a file |
145 | 154 | // TODO: what to do about finding multiple versions of the same |
146 | 155 | // dependency? |
| 156 | + |
| 157 | + // Each prefix must be searched for (assuming Name is the term): |
| 158 | + // |
| 159 | + // - Name/*.cps |
| 160 | + // - name/*.cps |
| 161 | + // - Name.cps |
| 162 | + // - name.cps |
| 163 | + // |
| 164 | + // TODO: should we allow symlinks? |
147 | 165 | auto && paths = search_paths(env); |
148 | 166 | std::vector<fs::path> found{}; |
149 | | - for (auto && path : paths) { |
150 | | - if (fs::is_directory(path)) { |
151 | | - // TODO: <name-like> |
152 | | - const fs::path file = path / fmt::format("{}.cps", name); |
153 | | - if (fs::is_regular_file(file)) { |
154 | | - found.push_back(file); |
| 167 | + for (auto && cname : names) { |
| 168 | + for (auto && path : paths) { |
| 169 | + if (fs::is_directory(path)) { |
| 170 | + const fs::path namelike = path / cname; |
| 171 | + if (fs::is_directory(namelike)) { |
| 172 | + for (auto && trial : fs::directory_iterator(namelike)) { |
| 173 | + auto && tpath = trial.path(); |
| 174 | + if (fs::is_regular_file(tpath) && tpath.extension() == ".cps") { |
| 175 | + found.push_back(tpath); |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | + const fs::path file = path / fmt::format("{}.cps", cname); |
| 180 | + if (fs::is_regular_file(file)) { |
| 181 | + found.push_back(file); |
| 182 | + } |
155 | 183 | } |
156 | 184 | } |
157 | 185 | } |
|
0 commit comments