| 203 | } |
| 204 | |
| 205 | path findInSystemPath(const path& p) { |
| 206 | |
| 207 | path result; |
| 208 | // Ensure that this is just a name and not a path |
| 209 | if (p.parent_path().empty()) { |
| 210 | std::istringstream pathstream(getenv("PATH")); |
| 211 | LOG_FREE(Debug, "PathHelpers", "findInSystemPath, searching for '" << p << "' in PATH'"); |
| 212 | |
| 213 | std::string pathstring; |
| 214 | while (std::getline(pathstream, pathstring, pathDelimiter())) { |
| 215 | LOG_FREE(Trace, "PathHelpers", "findInSystemPath, searching for '" << p << "' in '" << pathstring << "'"); |
| 216 | |
| 217 | auto maybepath = toPath(pathstring) / p; |
| 218 | if (openstudio::filesystem::exists(maybepath) && !openstudio::filesystem::is_directory(maybepath)) { |
| 219 | LOG_FREE(Debug, "PathHelpers", "findInSystemPath, found '" << p << "' in PATH: '" << pathstring); |
| 220 | result = maybepath; |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | if (result.empty()) { |
| 225 | LOG_FREE(Debug, "PathHelpers", "findInSystemPath, p wasn't found in PATH, leaving as is"); |
| 226 | result = p; |
| 227 | } |
| 228 | |
| 229 | } else { |
| 230 | LOG_FREE(Debug, "PathHelpers", "findInSystemPath, p isn't just a name, leaving as is"); |
| 231 | result = p; |
| 232 | } |
| 233 | |
| 234 | return result; |
| 235 | } |
| 236 | |
| 237 | path completeAndNormalize(const path& p) { |
| 238 | |